smithers-orchestrator 0.16.9 → 0.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "smithers-orchestrator",
3
- "version": "0.16.9",
3
+ "version": "0.18.0",
4
4
  "description": "Public Smithers facade and workflow authoring convenience package",
5
5
  "type": "module",
6
6
  "sideEffects": false,
@@ -15,6 +15,16 @@
15
15
  "import": "./src/tools.js",
16
16
  "default": "./src/tools.js"
17
17
  },
18
+ "./gateway-client": {
19
+ "types": "./src/gateway-client.d.ts",
20
+ "import": "./src/gateway-client.js",
21
+ "default": "./src/gateway-client.js"
22
+ },
23
+ "./gateway-react": {
24
+ "types": "./src/gateway-react.d.ts",
25
+ "import": "./src/gateway-react.js",
26
+ "default": "./src/gateway-react.js"
27
+ },
18
28
  "./*": {
19
29
  "types": "./src/index.d.ts",
20
30
  "import": "./src/*.js",
@@ -33,28 +43,37 @@
33
43
  "smithers": "./src/bin/smithers.js"
34
44
  },
35
45
  "dependencies": {
46
+ "@modelcontextprotocol/sdk": "^1.29.0",
47
+ "@mariozechner/pi-tui": "^0.70.2",
48
+ "@sinclair/typebox": "^0.34.49",
36
49
  "@mdx-js/esbuild": "^3.1.1",
37
50
  "ai": "^6.0.168",
38
51
  "diff": "^9.0.0",
52
+ "drizzle-orm": "^0.45.2",
53
+ "effect": "^3.21.1",
54
+ "incur": "^0.4.1",
55
+ "react": "^19.2.5",
39
56
  "zod": "^4.3.6",
40
- "@smithers-orchestrator/components": "0.16.9",
41
- "@smithers-orchestrator/agents": "0.16.9",
42
- "@smithers-orchestrator/driver": "0.16.9",
43
- "@smithers-orchestrator/cli": "0.16.9",
44
- "@smithers-orchestrator/db": "0.16.9",
45
- "@smithers-orchestrator/graph": "0.16.9",
46
- "@smithers-orchestrator/errors": "0.16.9",
47
- "@smithers-orchestrator/observability": "0.16.9",
48
- "@smithers-orchestrator/engine": "0.16.9",
49
- "@smithers-orchestrator/react-reconciler": "0.16.9",
50
- "@smithers-orchestrator/openapi": "0.16.9",
51
- "@smithers-orchestrator/scheduler": "0.16.9",
52
- "@smithers-orchestrator/scorers": "0.16.9",
53
- "@smithers-orchestrator/memory": "0.16.9",
54
- "@smithers-orchestrator/server": "0.16.9",
55
- "@smithers-orchestrator/sandbox": "0.16.9",
56
- "@smithers-orchestrator/time-travel": "0.16.9",
57
- "@smithers-orchestrator/vcs": "0.16.9"
57
+ "@smithers-orchestrator/agents": "0.18.0",
58
+ "@smithers-orchestrator/driver": "0.18.0",
59
+ "@smithers-orchestrator/components": "0.18.0",
60
+ "@smithers-orchestrator/db": "0.18.0",
61
+ "@smithers-orchestrator/engine": "0.18.0",
62
+ "@smithers-orchestrator/gateway-client": "0.18.0",
63
+ "@smithers-orchestrator/errors": "0.18.0",
64
+ "@smithers-orchestrator/gateway-react": "0.18.0",
65
+ "@smithers-orchestrator/graph": "0.18.0",
66
+ "@smithers-orchestrator/openapi": "0.18.0",
67
+ "@smithers-orchestrator/react-reconciler": "0.18.0",
68
+ "@smithers-orchestrator/sandbox": "0.18.0",
69
+ "@smithers-orchestrator/observability": "0.18.0",
70
+ "@smithers-orchestrator/scorers": "0.18.0",
71
+ "@smithers-orchestrator/scheduler": "0.18.0",
72
+ "@smithers-orchestrator/server": "0.18.0",
73
+ "@smithers-orchestrator/time-travel": "0.18.0",
74
+ "@smithers-orchestrator/cli": "0.18.0",
75
+ "@smithers-orchestrator/vcs": "0.18.0",
76
+ "@smithers-orchestrator/memory": "0.18.0"
58
77
  },
59
78
  "devDependencies": {
60
79
  "@types/bun": "latest",
@@ -0,0 +1,19 @@
1
+ import type { z } from "zod";
2
+ import type { CreateSmithersApi } from "../CreateSmithersApi";
3
+
4
+ type Equal<A, B> =
5
+ (<T>() => T extends A ? 1 : 2) extends
6
+ (<T>() => T extends B ? 1 : 2)
7
+ ? true
8
+ : false;
9
+ type Assert<T extends true> = T;
10
+
11
+ type Api = CreateSmithersApi<{
12
+ input: z.ZodObject<{ prompt: z.ZodString }>;
13
+ }>;
14
+ type Ctx = Parameters<Parameters<Api["smithers"]>[0]>[0];
15
+
16
+ type _PromptIsString = Assert<Equal<Ctx["input"]["prompt"], string>>;
17
+
18
+ // @ts-expect-error input.foo is not declared by the workflow input schema.
19
+ type _MissingFoo = Ctx["input"]["foo"];
package/src/create.js CHANGED
@@ -12,7 +12,7 @@ import React from "react";
12
12
  import { createSmithersContext, SmithersContext as GlobalSmithersContext } from "@smithers-orchestrator/react-reconciler/context";
13
13
  import { Approval as BaseApproval, Workflow as BaseWorkflow, Task as BaseTask, Sequence as BaseSequence, Parallel as BaseParallel, MergeQueue as BaseMergeQueue, Branch as BaseBranch, Loop as BaseLoop, Ralph as BaseRalph, ContinueAsNew as BaseContinueAsNew, continueAsNew as baseContinueAsNew, Worktree as BaseWorktree, Sandbox as BaseSandbox, Signal as BaseSignal, Timer as BaseTimer, } from "@smithers-orchestrator/components";
14
14
  import { zodToTable } from "@smithers-orchestrator/db/zodToTable";
15
- import { zodToCreateTableSQL } from "@smithers-orchestrator/db/zodToCreateTableSQL";
15
+ import { zodToCreateTableSQL, syncZodTableSchema } from "@smithers-orchestrator/db/zodToCreateTableSQL";
16
16
  import { camelToSnake } from "@smithers-orchestrator/db/utils/camelToSnake";
17
17
  import { resolve } from "node:path";
18
18
  import { SmithersError } from "@smithers-orchestrator/errors/SmithersError";
@@ -49,6 +49,41 @@ function computeSchemaSig(schemas, dbPath) {
49
49
  }
50
50
  return parts.join("\n");
51
51
  }
52
+ /**
53
+ * Duplicate schema objects need distinct output refs so Task `output={outputs.foo}`
54
+ * can still resolve the intended table by identity.
55
+ * @param {Record<string, any>} schemas
56
+ */
57
+ function prepareOutputSchemas(schemas) {
58
+ const counts = new Map();
59
+ for (const [name, zodSchema] of Object.entries(schemas)) {
60
+ if (name === "input")
61
+ continue;
62
+ counts.set(zodSchema, (counts.get(zodSchema) ?? 0) + 1);
63
+ }
64
+ const outputs = {
65
+ ...schemas,
66
+ };
67
+ const zodToKeyName = new Map();
68
+ const ambiguousZodSchemas = new Set();
69
+ for (const [name, zodSchema] of Object.entries(schemas)) {
70
+ if (name === "input")
71
+ continue;
72
+ if ((counts.get(zodSchema) ?? 0) > 1) {
73
+ ambiguousZodSchemas.add(zodSchema);
74
+ const aliasSchema = zodSchema.clone();
75
+ outputs[name] = aliasSchema;
76
+ zodToKeyName.set(aliasSchema, name);
77
+ continue;
78
+ }
79
+ zodToKeyName.set(zodSchema, name);
80
+ }
81
+ return {
82
+ outputs,
83
+ zodToKeyName,
84
+ ambiguousZodSchemas,
85
+ };
86
+ }
52
87
  /**
53
88
  * @param {Record<string, string>} [base]
54
89
  * @param {Record<string, string>} [override]
@@ -216,10 +251,11 @@ export function createSmithers(schemas, opts) {
216
251
  catch { }
217
252
  };
218
253
  process.on("exit", closeDb);
219
- // 3. Auto-create tables using CREATE TABLE IF NOT EXISTS
254
+ // 3. Auto-create tables, and ALTER any existing tables to add columns the
255
+ // current schema introduced (CREATE TABLE IF NOT EXISTS would silently
256
+ // skip the columns and a later upsert would fail with "no column named X").
220
257
  if (schemas.input) {
221
- const inputDdl = zodToCreateTableSQL("input", schemas.input, { isInput: true });
222
- sqlite.run(inputDdl);
258
+ syncZodTableSchema(sqlite, "input", schemas.input, { isInput: true });
223
259
  }
224
260
  else {
225
261
  sqlite.exec(`CREATE TABLE IF NOT EXISTS "input" (run_id TEXT PRIMARY KEY, payload TEXT)`);
@@ -238,8 +274,7 @@ export function createSmithers(schemas, opts) {
238
274
  if (name === "input")
239
275
  continue;
240
276
  const tableName = camelToSnake(name);
241
- const ddl = zodToCreateTableSQL(tableName, zodSchema);
242
- sqlite.run(ddl);
277
+ syncZodTableSchema(sqlite, tableName, zodSchema);
243
278
  }
244
279
  // 4. Create Drizzle instance with all tables in the schema
245
280
  const drizzleSchema = { input: inputTable };
@@ -254,13 +289,8 @@ export function createSmithers(schemas, opts) {
254
289
  continue;
255
290
  schemaRegistry.set(name, { table: tables[name], zodSchema });
256
291
  }
257
- // 6. Build reverse lookup: ZodObject reference → schema key name
258
- const zodToKeyName = new Map();
259
- for (const [name, zodSchema] of Object.entries(schemas)) {
260
- if (name === "input")
261
- continue;
262
- zodToKeyName.set(zodSchema, name);
263
- }
292
+ // 6. Build output refs and reverse lookup: ZodObject reference → schema key name
293
+ const { outputs, zodToKeyName, ambiguousZodSchemas } = prepareOutputSchemas(schemas);
264
294
  // 7. Context + hooks
265
295
  const { SmithersContext: RuntimeSmithersContext, useCtx, } = createSmithersContext();
266
296
  const ctxRef = { current: null };
@@ -302,6 +332,7 @@ export function createSmithers(schemas, opts) {
302
332
  opts: {},
303
333
  schemaRegistry,
304
334
  zodToKeyName,
335
+ ambiguousZodSchemas,
305
336
  };
306
337
  return React.createElement(BaseSandbox, {
307
338
  ...props,
@@ -342,6 +373,7 @@ export function createSmithers(schemas, opts) {
342
373
  opts: workflowOpts,
343
374
  schemaRegistry,
344
375
  zodToKeyName,
376
+ ambiguousZodSchemas,
345
377
  };
346
378
  }
347
379
  /**
@@ -370,7 +402,7 @@ export function createSmithers(schemas, opts) {
370
402
  smithers: boundSmithers,
371
403
  db,
372
404
  tables: tables,
373
- outputs: schemas,
405
+ outputs,
374
406
  };
375
407
  if (process.env.SMITHERS_HOT === "1") {
376
408
  const sig = computeSchemaSig(schemas, absDbPath);
@@ -12,7 +12,7 @@ import { Database } from "bun:sqlite";
12
12
  import { drizzle } from "drizzle-orm/bun-sqlite";
13
13
  import { sqliteTable, text } from "drizzle-orm/sqlite-core";
14
14
  import { zodToTable } from "@smithers-orchestrator/db/zodToTable";
15
- import { zodToCreateTableSQL } from "@smithers-orchestrator/db/zodToCreateTableSQL";
15
+ import { syncZodTableSchema } from "@smithers-orchestrator/db/zodToCreateTableSQL";
16
16
  import { camelToSnake } from "@smithers-orchestrator/db/utils/camelToSnake";
17
17
  import { SmithersError } from "@smithers-orchestrator/errors/SmithersError";
18
18
  import { mkdtempSync } from "node:fs";
@@ -64,6 +64,33 @@ export function hostNodeToReact(node, agents) {
64
64
  const children = node.children.map((child) => hostNodeToReact(child, agents));
65
65
  return React.createElement(node.tag, rawProps, ...children);
66
66
  }
67
+ /**
68
+ * @param {Record<string, any>} schemas
69
+ */
70
+ function prepareOutputSchemas(schemas) {
71
+ const counts = new Map();
72
+ for (const [name, zodSchema] of Object.entries(schemas)) {
73
+ if (name === "input")
74
+ continue;
75
+ counts.set(zodSchema, (counts.get(zodSchema) ?? 0) + 1);
76
+ }
77
+ const zodToKeyName = new Map();
78
+ const ambiguousZodSchemas = new Set();
79
+ for (const [name, zodSchema] of Object.entries(schemas)) {
80
+ if (name === "input")
81
+ continue;
82
+ if ((counts.get(zodSchema) ?? 0) > 1) {
83
+ ambiguousZodSchemas.add(zodSchema);
84
+ zodToKeyName.set(zodSchema.clone(), name);
85
+ continue;
86
+ }
87
+ zodToKeyName.set(zodSchema, name);
88
+ }
89
+ return {
90
+ zodToKeyName,
91
+ ambiguousZodSchemas,
92
+ };
93
+ }
67
94
  /**
68
95
  * Create a SmithersWorkflow from an external build function.
69
96
  *
@@ -113,7 +140,7 @@ export function createExternalSmithers(config) {
113
140
  continue;
114
141
  const tableName = camelToSnake(name);
115
142
  tables[name] = zodToTable(tableName, zodSchema);
116
- sqlite.run(zodToCreateTableSQL(tableName, zodSchema));
143
+ syncZodTableSchema(sqlite, tableName, zodSchema);
117
144
  }
118
145
  const drizzleSchema = { input: inputTable };
119
146
  for (const [key, table] of Object.entries(tables)) {
@@ -126,12 +153,7 @@ export function createExternalSmithers(config) {
126
153
  continue;
127
154
  schemaRegistry.set(name, { table: tables[name], zodSchema });
128
155
  }
129
- const zodToKeyName = new Map();
130
- for (const [name, zodSchema] of Object.entries(schemas)) {
131
- if (name === "input")
132
- continue;
133
- zodToKeyName.set(zodSchema, name);
134
- }
156
+ const { zodToKeyName, ambiguousZodSchemas } = prepareOutputSchemas(schemas);
135
157
  return {
136
158
  db,
137
159
  build: (ctx) => {
@@ -142,6 +164,7 @@ export function createExternalSmithers(config) {
142
164
  opts: {},
143
165
  schemaRegistry,
144
166
  zodToKeyName,
167
+ ambiguousZodSchemas,
145
168
  tables,
146
169
  cleanup: closeDb,
147
170
  };
@@ -0,0 +1 @@
1
+ export * from "@smithers-orchestrator/gateway-client";
@@ -0,0 +1 @@
1
+ export * from "@smithers-orchestrator/gateway-client";
@@ -0,0 +1 @@
1
+ export * from "@smithers-orchestrator/gateway-react";
@@ -0,0 +1 @@
1
+ export * from "@smithers-orchestrator/gateway-react";
package/src/index.d.ts CHANGED
@@ -72,7 +72,7 @@ export { ensureSmithersTables } from '@smithers-orchestrator/db/ensure';
72
72
  export { markdownComponents } from '@smithers-orchestrator/components/markdownComponents';
73
73
  export { renderMdx } from '@smithers-orchestrator/components/renderMdx';
74
74
  export { zodToTable } from '@smithers-orchestrator/db/zodToTable';
75
- export { zodToCreateTableSQL } from '@smithers-orchestrator/db/zodToCreateTableSQL';
75
+ export { syncZodTableSchema, zodSchemaColumns, zodToCreateTableSQL } from '@smithers-orchestrator/db/zodToCreateTableSQL';
76
76
  export { camelToSnake } from '@smithers-orchestrator/db/utils/camelToSnake';
77
77
  export { unwrapZodType } from '@smithers-orchestrator/db/unwrapZodType';
78
78
  export { zodSchemaToJsonExample } from '@smithers-orchestrator/components/zod-to-example';
package/src/index.js CHANGED
@@ -212,7 +212,7 @@ export { mdxPlugin } from "./mdx-plugin.js";
212
212
  export { markdownComponents } from "@smithers-orchestrator/components/markdownComponents";
213
213
  export { renderMdx } from "@smithers-orchestrator/components/renderMdx";
214
214
  export { zodToTable } from "@smithers-orchestrator/db/zodToTable";
215
- export { zodToCreateTableSQL } from "@smithers-orchestrator/db/zodToCreateTableSQL";
215
+ export { syncZodTableSchema, zodSchemaColumns, zodToCreateTableSQL } from "@smithers-orchestrator/db/zodToCreateTableSQL";
216
216
  export { camelToSnake } from "@smithers-orchestrator/db/utils/camelToSnake";
217
217
  export { unwrapZodType } from "@smithers-orchestrator/db/unwrapZodType";
218
218
  export { zodSchemaToJsonExample } from "@smithers-orchestrator/components/zod-to-example";
@@ -1 +0,0 @@
1
- export * from "./pi-plugin/extension.js";
@@ -1,7 +0,0 @@
1
- export type SmithersPiRunContext = {
2
- runId: string;
3
- workflowName: string;
4
- status: string;
5
- nodeStates: Array<{ nodeId: string; state: string }>;
6
- errors: string[];
7
- };