From dd531b27ad98dc47f3c6d259cfa34e872d880b89 Mon Sep 17 00:00:00 2001 From: Bernhard Seefeld Date: Mon, 17 Nov 2025 16:11:29 -0800 Subject: [PATCH] fix(llm-dialog): when re-creating schema via source cell, follow cell path --- packages/runner/src/builtins/llm-dialog.ts | 25 +++++++++++++++------- packages/runner/src/cfc.ts | 2 +- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/packages/runner/src/builtins/llm-dialog.ts b/packages/runner/src/builtins/llm-dialog.ts index 1c9ac5dd13..4b80c9153d 100644 --- a/packages/runner/src/builtins/llm-dialog.ts +++ b/packages/runner/src/builtins/llm-dialog.ts @@ -93,14 +93,23 @@ function normalizeInputSchema(schemaLike: unknown): JSONSchema { function getCellSchema( cell: Cell, ): JSONSchema | undefined { - return cell.schema ?? - // If cell has a source cell, any resultRef has a schema attached - cell.getSourceCell<{ resultRef: Cell }>({ - type: "object", - properties: { resultRef: { asCell: true } }, - })?.get()?.resultRef?.schema ?? - // Otherwise, derive a simple object schema from the current value - buildMinimalSchemaFromValue(cell); + if (cell.schema) return cell.schema; + + const sourceCell = cell.getSourceCell<{ resultRef: Cell }>({ + type: "object", + properties: { resultRef: { asCell: true } }, + }); + const sourceCellSchema = sourceCell?.key("resultRef").get()?.schema; + if (sourceCellSchema !== undefined) { + const cfc = new ContextualFlowControl(); + return cfc.schemaAtPath( + sourceCellSchema, + cell.getAsNormalizedFullLink().path, + cell.schema, + ); + } + + return buildMinimalSchemaFromValue(cell); } function buildMinimalSchemaFromValue(charm: Cell): JSONSchema | undefined { diff --git a/packages/runner/src/cfc.ts b/packages/runner/src/cfc.ts index da66d7c3e9..3c200986d1 100644 --- a/packages/runner/src/cfc.ts +++ b/packages/runner/src/cfc.ts @@ -505,7 +505,7 @@ export class ContextualFlowControl { */ schemaAtPath( schema: JSONSchema, - path: string[], + path: readonly string[], rootSchema?: JSONSchema, extraClassifications?: Set, ): JSONSchema {