Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { RunnableConfig } from '@langchain/core/runnables'
import { convertSchemaToText } from '../../utils/convertSchemaToText'
import { yamlSchemaDeparser } from '@liam-hq/schema'
import { Result } from 'neverthrow'
import { WorkflowTerminationError } from '../../utils/errorHandling'
import { getConfigurable } from '../../utils/getConfigurable'
import { removeReasoningFromMessages } from '../../utils/messageCleanup'
Expand All @@ -14,16 +15,15 @@ export async function designSchemaNode(
state: DbAgentState,
config: RunnableConfig,
): Promise<DbAgentState> {
const configurableResult = getConfigurable(config)
if (configurableResult.isErr()) {
throw new WorkflowTerminationError(
configurableResult.error,
'designSchemaNode',
)
}
const { repositories } = configurableResult.value
const combinedResult = Result.combine([
getConfigurable(config),
yamlSchemaDeparser(state.schemaData),
])

const schemaText = convertSchemaToText(state.schemaData)
if (combinedResult.isErr()) {
throw new WorkflowTerminationError(combinedResult.error, 'designSchemaNode')
}
const [{ repositories }, schemaText] = combinedResult.value

// Remove reasoning field from AIMessages to avoid API issues
// This prevents the "reasoning without required following item" error
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { RunnableConfig } from '@langchain/core/runnables'
import { convertSchemaToText } from '../../utils/convertSchemaToText'
import { yamlSchemaDeparser } from '@liam-hq/schema'
import { Result } from 'neverthrow'
import { WorkflowTerminationError } from '../../utils/errorHandling'
import { getConfigurable } from '../../utils/getConfigurable'
import { invokePmAnalysisAgent } from '../invokePmAnalysisAgent'
Expand All @@ -13,20 +14,24 @@ export async function analyzeRequirementsNode(
state: PmAgentState,
config: RunnableConfig,
): Promise<Partial<PmAgentState>> {
const configurableResult = getConfigurable(config)
if (configurableResult.isErr()) {
const combinedResult = Result.combine([
getConfigurable(config),
yamlSchemaDeparser(state.schemaData),
])

if (combinedResult.isErr()) {
throw new WorkflowTerminationError(
configurableResult.error,
combinedResult.error,
'analyzeRequirementsNode',
)
}

const schemaText = convertSchemaToText(state.schemaData)
const [configurable, schemaText] = combinedResult.value

const analysisResult = await invokePmAnalysisAgent(
{ schemaText },
state.messages,
configurableResult.value,
configurable,
)

if (analysisResult.isErr()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
} from '@langchain/core/messages'
import { ChatOpenAI } from '@langchain/openai'
import { fromAsyncThrowable } from '@liam-hq/neverthrow'
import { convertSchemaToText } from '../../utils/convertSchemaToText'
import { yamlSchemaDeparser } from '@liam-hq/schema'
import { removeReasoningFromMessages } from '../../utils/messageCleanup'
import { streamLLMResponse } from '../../utils/streamingLlmUtils'
import { saveTestcaseTool } from '../tools/saveTestcaseTool'
Expand Down Expand Up @@ -36,7 +36,11 @@ export async function generateTestcaseNode(
): Promise<{ messages: BaseMessage[] }> {
const { currentTestcase, schemaData, goal, messages } = state

const schemaContext = convertSchemaToText(schemaData)
const schemaContextResult = yamlSchemaDeparser(schemaData)
if (schemaContextResult.isErr()) {
throw schemaContextResult.error
}
const schemaContext = schemaContextResult.value

const contextMessage = await humanPromptTemplateForTestcaseGeneration.format({
schemaContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { HumanMessage, SystemMessage } from '@langchain/core/messages'
import { Command, END } from '@langchain/langgraph'
import { ChatOpenAI } from '@langchain/openai'
import { fromPromise } from '@liam-hq/neverthrow'
import { yamlSchemaDeparser } from '@liam-hq/schema'
import * as v from 'valibot'
import { convertSchemaToText } from '../../utils/convertSchemaToText'
import { toJsonSchema } from '../../utils/jsonSchema'
import type { testcaseAnnotation } from './testcaseAnnotation'

Expand Down Expand Up @@ -47,7 +47,11 @@ export async function validateSchemaRequirementsNode(
): Promise<Command> {
const { currentTestcase, schemaData, goal } = state

const schemaContext = convertSchemaToText(schemaData)
const schemaContextResult = yamlSchemaDeparser(schemaData)
if (schemaContextResult.isErr()) {
throw schemaContextResult.error
}
const schemaContext = schemaContextResult.value

const contextMessage = `
# Database Schema Context
Expand Down

This file was deleted.

1 change: 1 addition & 0 deletions frontend/packages/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"neverthrow": "8.2.0",
"pg-query-emscripten": "5.1.0",
"valibot": "1.1.0",
"yaml": "2.8.1",
"zod": "3.25.76"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ import {
isReplaceTableCommentOperation,
isReplaceTableNameOperation,
} from '../../operation/schema/table.js'
import type { OperationDeparser } from '../type.js'
import type { LegacyOperationDeparser } from '../type.js'
import {
generateAddCheckConstraintStatement,
generateAddColumnStatement,
Expand Down Expand Up @@ -605,7 +605,12 @@ function generateAlterConstraintUpdateFromOperation(
)
}

export const postgresqlOperationDeparser: OperationDeparser = (
/**
* PostgreSQL operation deparser
* @deprecated This implementation uses LegacyOperationDeparser type.
* TODO: Migrate to new OperationDeparser type (Result<string, Error>) for better error handling.
*/
export const postgresqlOperationDeparser: LegacyOperationDeparser = (
operation: Operation,
// biome-ignore lint/complexity/noExcessiveCognitiveComplexity: TODO: Refactor to reduce complexity
) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import type {
Schema,
Table,
} from '../../schema/index.js'
import type { SchemaDeparser } from '../type.js'
import type { LegacySchemaDeparser } from '../type.js'
import {
generateAddConstraintStatement,
generateCreateEnumStatement,
Expand All @@ -14,7 +14,14 @@ import {
generateCreateTableStatement,
} from './utils.js'

export const postgresqlSchemaDeparser: SchemaDeparser = (schema: Schema) => {
/**
* PostgreSQL schema deparser
* @deprecated This implementation uses LegacySchemaDeparser type.
* TODO: Migrate to new SchemaDeparser type (Result<string, Error>) for better error handling.
*/
export const postgresqlSchemaDeparser: LegacySchemaDeparser = (
schema: Schema,
) => {
const ddlStatements: string[] = []
const errors: { message: string }[] = []

Expand Down
23 changes: 20 additions & 3 deletions frontend/packages/schema/src/deparser/type.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
import type { Result } from 'neverthrow'
import type { Operation } from '../operation/schema/index.js'
import type { Schema } from '../schema/index.js'

// Legacy types - TODO: Migrate all implementations to use the new types
type DeparserError = {
message: string
}

type DeparserResult = {
type LegacyDeparserResult = {
value: string
errors: DeparserError[]
}

export type SchemaDeparser = (schema: Schema) => DeparserResult
export type OperationDeparser = (operation: Operation) => DeparserResult
/**
* @deprecated Use SchemaDeparser instead. This type is kept for backward compatibility.
* TODO: Migrate existing implementations to use the new SchemaDeparser type.
*/
export type LegacySchemaDeparser = (schema: Schema) => LegacyDeparserResult

/**
* @deprecated Use OperationDeparser instead. This type is kept for backward compatibility.
* TODO: Migrate existing implementations to use the new OperationDeparser type.
*/
export type LegacyOperationDeparser = (
operation: Operation,
) => LegacyDeparserResult

// New types using neverthrow
export type SchemaDeparser = (schema: Schema) => Result<string, Error>
export type OperationDeparser = (operation: Operation) => Result<string, Error>
1 change: 1 addition & 0 deletions frontend/packages/schema/src/deparser/yaml/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { yamlSchemaDeparser } from './schemaDeparser.js'
Loading
Loading