Skip to content

Commit 2d3e51c

Browse files
authored
fix(llm-dialog): when re-creating schema via source cell, follow cell path (commontoolsinc#2094)
1 parent a5af518 commit 2d3e51c

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

packages/runner/src/builtins/llm-dialog.ts

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,23 @@ function normalizeInputSchema(schemaLike: unknown): JSONSchema {
9393
function getCellSchema(
9494
cell: Cell<unknown>,
9595
): JSONSchema | undefined {
96-
return cell.schema ??
97-
// If cell has a source cell, any resultRef has a schema attached
98-
cell.getSourceCell<{ resultRef: Cell<unknown> }>({
99-
type: "object",
100-
properties: { resultRef: { asCell: true } },
101-
})?.get()?.resultRef?.schema ??
102-
// Otherwise, derive a simple object schema from the current value
103-
buildMinimalSchemaFromValue(cell);
96+
if (cell.schema) return cell.schema;
97+
98+
const sourceCell = cell.getSourceCell<{ resultRef: Cell<unknown> }>({
99+
type: "object",
100+
properties: { resultRef: { asCell: true } },
101+
});
102+
const sourceCellSchema = sourceCell?.key("resultRef").get()?.schema;
103+
if (sourceCellSchema !== undefined) {
104+
const cfc = new ContextualFlowControl();
105+
return cfc.schemaAtPath(
106+
sourceCellSchema,
107+
cell.getAsNormalizedFullLink().path,
108+
cell.schema,
109+
);
110+
}
111+
112+
return buildMinimalSchemaFromValue(cell);
104113
}
105114

106115
function buildMinimalSchemaFromValue(charm: Cell<any>): JSONSchema | undefined {

packages/runner/src/cfc.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,7 @@ export class ContextualFlowControl {
505505
*/
506506
schemaAtPath(
507507
schema: JSONSchema,
508-
path: string[],
508+
path: readonly string[],
509509
rootSchema?: JSONSchema,
510510
extraClassifications?: Set<string>,
511511
): JSONSchema {

0 commit comments

Comments
 (0)