|
1 | 1 | import { parseArgs } from "@std/cli/parse-args";
|
2 |
| -import { castNewRecipe, CharmManager } from "@commontools/charm"; |
| 2 | +import { |
| 3 | + castNewRecipe, |
| 4 | + CharmManager, |
| 5 | + compileAndRunRecipe, |
| 6 | +} from "@commontools/charm"; |
3 | 7 | import { getEntityId, setBobbyServerUrl, storage } from "@commontools/runner";
|
4 | 8 | import { createSession, Identity } from "@commontools/identity";
|
5 |
| -import { formatJsonImportPrompt, LLMClient, setLLMUrl } from "@commontools/llm"; |
| 9 | +import { LLMClient, setLLMUrl } from "@commontools/llm"; |
6 | 10 | import { processWorkflow } from "@commontools/charm";
|
7 | 11 | import { type CharmResult, CommandType, type Step } from "./interfaces.ts";
|
8 | 12 | import { scenarios } from "./scenarios.ts";
|
9 | 13 | import { toolshedUrl } from "./env.ts";
|
10 | 14 | import { llmVerifyCharm } from "./judge.ts";
|
| 15 | +import { |
| 16 | + createJsonSchema, |
| 17 | + derive, |
| 18 | + NAME, |
| 19 | + recipe, |
| 20 | + UI, |
| 21 | +} from "@commontools/builder"; |
| 22 | +import { h } from "@commontools/html"; |
11 | 23 | import { ensureReportDir, generateReport } from "./report.ts";
|
12 | 24 | import {
|
13 | 25 | addErrorListeners,
|
@@ -128,14 +140,48 @@ async function processCommand(
|
128 | 140 | throw new Error("Missing data for JSON import.");
|
129 | 141 | }
|
130 | 142 |
|
131 |
| - const jsonPrompt = formatJsonImportPrompt(prompt, step.data); |
132 |
| - const form = await processWorkflow( |
133 |
| - jsonPrompt, |
| 143 | + // FIXME(ja): we should move this to a common charm method so that |
| 144 | + // jumble and seeder can share |
| 145 | + const schema = step.dataSchema ?? createJsonSchema(step.data); |
| 146 | + const schemaString = JSON.stringify(schema, null, 2); |
| 147 | + const result = Object.keys(schema.properties ?? {}).map((key) => |
| 148 | + ` ${key}: data.${key},\n` |
| 149 | + ).join("\n"); |
| 150 | + |
| 151 | + const dataRecipeSrc = `import { h } from "@commontools/html"; |
| 152 | + import { recipe, UI, NAME, derive, type JSONSchema } from "@commontools/builder"; |
| 153 | +
|
| 154 | + const schema = ${schemaString}; |
| 155 | +
|
| 156 | + export default recipe(schema, schema, (data) => ({ |
| 157 | + [NAME]: "Data Import", |
| 158 | + [UI]: <div><h2>schema</h2><pre>${ |
| 159 | + schemaString.replaceAll("{", "{") |
| 160 | + .replaceAll("}", "}") |
| 161 | + .replaceAll("\n", "<br/>") |
| 162 | + }</pre></div>, |
| 163 | + ${result} |
| 164 | + }));`; |
| 165 | + |
| 166 | + const dataCharm = await compileAndRunRecipe( |
134 | 167 | charmManager,
|
135 |
| - { |
136 |
| - cache, |
137 |
| - }, |
| 168 | + dataRecipeSrc, |
| 169 | + "data import", |
| 170 | + step.data, |
138 | 171 | );
|
| 172 | + |
| 173 | + const form = await processWorkflow(prompt, charmManager, { |
| 174 | + existingCharm: dataCharm, |
| 175 | + cache, |
| 176 | + prefill: { |
| 177 | + classification: { |
| 178 | + workflowType: "imagine", |
| 179 | + confidence: 1.0, |
| 180 | + reasoning: "hard coded", |
| 181 | + }, |
| 182 | + }, |
| 183 | + }); |
| 184 | + |
139 | 185 | const newCharm = form.generation?.charm;
|
140 | 186 | const id = getEntityId(newCharm);
|
141 | 187 | if (id) {
|
|
0 commit comments