@womp/spark-agent 1.0.1 → 2.1.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.
Files changed (89) hide show
  1. package/README.md +42 -19
  2. package/dist/capabilities/health.d.ts +9 -0
  3. package/dist/capabilities/health.js +27 -0
  4. package/dist/capabilities/scene-draft.d.ts +2 -404
  5. package/dist/capabilities/scene.d.ts +1 -1
  6. package/dist/capabilities/scene.js +13 -4
  7. package/dist/capabilities.d.ts +3 -1
  8. package/dist/capabilities.js +1 -0
  9. package/dist/cli.js +20 -2
  10. package/dist/client.js +15 -15
  11. package/dist/coordinates.d.ts +23 -0
  12. package/dist/coordinates.js +132 -0
  13. package/dist/generated/health-declarations.d.ts +1 -0
  14. package/dist/generated/health-declarations.js +3 -0
  15. package/dist/generated/scene-declarations.d.ts +1 -1
  16. package/dist/generated/scene-declarations.js +1 -1
  17. package/dist/geometry/backendRegistry.d.ts +37 -0
  18. package/dist/geometry/backendRegistry.js +61 -0
  19. package/dist/geometry/common.d.ts +26 -0
  20. package/dist/geometry/common.js +78 -0
  21. package/dist/geometry/compiler.d.ts +35 -0
  22. package/dist/geometry/compiler.js +115 -0
  23. package/dist/geometry/graph.d.ts +39 -0
  24. package/dist/geometry/graph.js +32 -0
  25. package/dist/geometry/index.d.ts +9 -0
  26. package/dist/geometry/index.js +12 -0
  27. package/dist/geometry/lift.d.ts +7 -0
  28. package/dist/geometry/lift.js +376 -0
  29. package/dist/geometry/lower.d.ts +9 -0
  30. package/dist/geometry/lower.js +363 -0
  31. package/dist/geometry/parameters.d.ts +23 -0
  32. package/dist/geometry/parameters.js +46 -0
  33. package/dist/geometry/schemas/backend-schema.json +3394 -0
  34. package/dist/geometry/schemas/flowir-dialect.json +976 -0
  35. package/dist/geometry/writeParamData.d.ts +18 -0
  36. package/dist/geometry/writeParamData.js +47 -0
  37. package/dist/geometry.d.ts +10 -0
  38. package/dist/geometry.js +19 -0
  39. package/dist/index.d.ts +2 -0
  40. package/dist/index.js +2 -0
  41. package/dist/kakapo.d.ts +9 -5
  42. package/dist/kakapo.js +7 -6
  43. package/dist/openscad.d.ts +85 -0
  44. package/dist/openscad.js +223 -0
  45. package/dist/pricing.js +9 -29
  46. package/dist/repair-state.d.ts +50 -0
  47. package/dist/repair-state.js +96 -0
  48. package/dist/runtime.d.ts +16 -36
  49. package/dist/runtime.js +132 -139
  50. package/dist/scene-environment.d.ts +25 -0
  51. package/dist/scene-environment.js +76 -0
  52. package/dist/scene-health.d.ts +49 -0
  53. package/dist/scene-health.js +176 -0
  54. package/dist/scene-metadata.d.ts +6 -0
  55. package/dist/scene-metadata.js +65 -0
  56. package/dist/scene-operations.d.ts +47 -0
  57. package/dist/scene-operations.js +126 -0
  58. package/dist/sdk-geometry-host.d.ts +12 -0
  59. package/dist/sdk-geometry-host.js +306 -0
  60. package/dist/sdk-openscad-host.d.ts +14 -0
  61. package/dist/sdk-openscad-host.js +296 -0
  62. package/dist/sdk-openscad-renderer.d.ts +11 -0
  63. package/dist/sdk-openscad-renderer.js +71 -0
  64. package/dist/sdk-scene-health-host.d.ts +4 -0
  65. package/dist/sdk-scene-health-host.js +13 -0
  66. package/dist/sdk-scene-host.d.ts +312 -0
  67. package/dist/sdk-scene-host.js +202 -0
  68. package/dist/sdk-scene-screenshot.d.ts +7 -0
  69. package/dist/sdk-scene-screenshot.js +17 -0
  70. package/dist/server/demo-scene-materials.d.ts +3 -0
  71. package/dist/server/demo-scene-materials.js +18 -0
  72. package/dist/server/express.js +2 -4
  73. package/dist/server/fixtures/materials/matte-blue.json +14 -0
  74. package/dist/server/fixtures/materials/polished-copper.json +14 -0
  75. package/dist/server/index.d.ts +2 -1
  76. package/dist/server/index.js +2 -1
  77. package/dist/server/service.d.ts +4 -0
  78. package/dist/server/service.js +26 -2
  79. package/dist/server/sqlite-store.d.ts +31 -0
  80. package/dist/server/sqlite-store.js +224 -0
  81. package/dist/server/standalone.d.ts +14 -1
  82. package/dist/server/standalone.js +160 -27
  83. package/dist/server/store.js +3 -1
  84. package/dist/types.d.ts +1 -1
  85. package/dist/womp-scene-api.d.ts +283 -0
  86. package/dist/womp-scene-api.js +974 -0
  87. package/package.json +22 -10
  88. package/dist/kakapo-capability.d.ts +0 -45
  89. package/dist/kakapo-capability.js +0 -169
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@womp/spark-agent",
3
- "version": "1.0.1",
3
+ "version": "2.1.0",
4
4
  "description": "Portable skills-based AI agent with local and durable chat transports for Womp",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
7
7
  "types": "./dist/index.d.ts",
8
8
  "bin": {
9
- "spark-agent": "./dist/cli.js"
9
+ "spark-agent": "dist/cli.js"
10
10
  },
11
11
  "exports": {
12
12
  "./browser": {
@@ -24,6 +24,16 @@
24
24
  "import": "./dist/kakapo.js",
25
25
  "default": "./dist/kakapo.js"
26
26
  },
27
+ "./geometry": {
28
+ "types": "./dist/geometry.d.ts",
29
+ "import": "./dist/geometry.js",
30
+ "default": "./dist/geometry.js"
31
+ },
32
+ "./openscad": {
33
+ "types": "./dist/openscad.d.ts",
34
+ "import": "./dist/openscad.js",
35
+ "default": "./dist/openscad.js"
36
+ },
27
37
  "./quickjs": {
28
38
  "types": "./dist/quickjs-executor.d.ts",
29
39
  "import": "./dist/quickjs-executor.js",
@@ -59,11 +69,13 @@
59
69
  "files": [
60
70
  "dist/**/*.js",
61
71
  "dist/**/*.d.ts",
72
+ "dist/server/fixtures/**/*.json",
73
+ "dist/geometry/schemas/**/*.json",
62
74
  "README.md"
63
75
  ],
64
76
  "sideEffects": false,
65
77
  "engines": {
66
- "node": ">=22"
78
+ "node": ">=22.13"
67
79
  },
68
80
  "repository": {
69
81
  "type": "git",
@@ -75,7 +87,7 @@
75
87
  "license": "MIT",
76
88
  "scripts": {
77
89
  "clean": "node -e \"require('node:fs').rmSync('dist',{recursive:true,force:true})\"",
78
- "build": "yarn clean && node scripts/generate-skill-declarations.mjs && tsc -p tsconfig.json",
90
+ "build": "yarn clean && node scripts/generate-skill-declarations.mjs && tsc -p tsconfig.json && node scripts/copy-fixtures.mjs",
79
91
  "typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p web/tsconfig.json",
80
92
  "lint": "yarn typecheck",
81
93
  "dev": "yarn build && concurrently --kill-others \"yarn dev:server\" \"yarn dev:web\"",
@@ -84,33 +96,33 @@
84
96
  "dev:web": "vite --config web/vite.config.ts",
85
97
  "start": "node dist/cli.js",
86
98
  "web:build": "yarn build && tsc --noEmit -p web/tsconfig.json && vite build --config web/vite.config.ts",
87
- "test": "yarn build && tsx --tsconfig tsconfig.json --test test/**/*.test.ts && node --input-type=module -e \"await Promise.all([import('@womp/spark-agent'), import('@womp/spark-agent/ui'), import('@womp/spark-agent/client'), import('@womp/spark-agent/server'), import('@womp/spark-agent/express'), import('@womp/spark-agent/kakapo')])\"",
88
- "test:live": "tsx --tsconfig tsconfig.json test/kakapo-runtime.live.ts",
99
+ "test": "yarn build && tsx --tsconfig tsconfig.json --test test/**/*.test.ts && node --input-type=module -e \"await Promise.all([import('@womp/spark-agent'), import('@womp/spark-agent/ui'), import('@womp/spark-agent/client'), import('@womp/spark-agent/server'), import('@womp/spark-agent/express'), import('@womp/spark-agent/kakapo'), import('@womp/spark-agent/geometry'), import('@womp/spark-agent/openscad')])\"",
100
+ "test:live": "tsx --tsconfig tsconfig.json test/womp-scene-api.live.ts",
89
101
  "prepack": "yarn build"
90
102
  },
91
103
  "dependencies": {
92
104
  "@ai-sdk/anthropic": "4.0.50",
93
105
  "@ai-sdk/openai": "4.0.63",
94
106
  "@jitl/quickjs-wasmfile-release-sync": "0.32.0",
95
- "@womp/kakapo-sdk": "0.2.0",
96
- "@womp/scene-api": "0.2.0",
107
+ "@womp/flowir": "0.3.0",
108
+ "@womp/kakapo-sdk": "0.3.0",
97
109
  "ai": "7.0.95",
98
110
  "eventsource-parser": "^3.0.6",
99
111
  "express": "^5.2.1",
112
+ "lodash": "4.18.1",
100
113
  "quickjs-emscripten-core": "0.32.0",
101
114
  "zod": "4.5.4"
102
115
  },
103
116
  "devDependencies": {
104
117
  "@ai-sdk/react": "^4.0.77",
105
118
  "@types/express": "^5.0.5",
119
+ "@types/lodash": "4.17.24",
106
120
  "@types/node": "^24.0.0",
107
121
  "@types/react": "^19.2.17",
108
122
  "@types/react-dom": "^19.2.3",
109
123
  "@vitejs/plugin-react": "^6.0.4",
110
124
  "concurrently": "^9.2.1",
111
125
  "lucide-react": "^1.26.0",
112
- "prettier": "^3.8.1",
113
- "pretty-quick": "^4.2.2",
114
126
  "react": "^19.2.8",
115
127
  "react-dom": "^19.2.8",
116
128
  "react-markdown": "^10.1.0",
@@ -1,45 +0,0 @@
1
- import type { KakapoAPI } from "@womp/kakapo-sdk";
2
- import type { ExecutionScreenshot } from "./types.js";
3
- import type { ArtifactRef, SparkInvocationContext } from "./capabilities.js";
4
- import type { SceneHost } from "./capabilities/scene.js";
5
- export type KakapoSceneHostOptions = {
6
- /** Persists a captured screenshot and returns the reference the model emits. */
7
- saveImage(image: ExecutionScreenshot, context: SparkInvocationContext): Promise<ArtifactRef>;
8
- /**
9
- * Reported verbatim in `read().projectId`. A headless Kakapo session has no
10
- * project of its own, so a host that is standing in for one supplies it and
11
- * anything else reports 0.
12
- */
13
- projectId?: number;
14
- /**
15
- * UI units per millimetre (mm=1, cm=0.1, in=0.0393701...), reported in
16
- * `read().unitMultiplier` and applied by `@womp/scene-api` to every position
17
- * and dimension. Defaults to 1 -- millimetres -- which is what the scene
18
- * skill's own instructions state; a host that supplies anything else is also
19
- * declaring it has re-denominated the prompt to match.
20
- */
21
- unitMultiplier?: number;
22
- };
23
- /**
24
- * The library-side `SceneHost`: `@womp/scene-api` over a Kakapo engine session,
25
- * with the same three methods swan-frontend's `createBrowserSceneHost` has.
26
- *
27
- * WHY BOTH `read` AND `edit` RUN INSIDE A TRANSACTION. `KakapoAPI.editScene`
28
- * calls `refreshScene()` before it hands out a draft (kakapo-sdk api.ts:197-231)
29
- * and serializes on `transactionTail`, so entering one is what makes a revision
30
- * mean "the engine's current scene" rather than "whatever the client last
31
- * cached". A `read()` that skipped it would hash a stale cache and then have
32
- * its own revision rejected by the very next `edit()`. The empty draft a read
33
- * opens sends no patch, because `editScene` only patches when the JSON diff is
34
- * non-empty. This is also the parity the browser host has, where `read` goes
35
- * through the same `sceneMutations.run` queue every mutation does.
36
- *
37
- * WHY THE STALENESS CHECK IS INSIDE THE TRANSACTION AND NOT AT ENTRY. It is
38
- * checked against the freshly refreshed draft, immediately before the callback's
39
- * first write, so it compares the expectation against the document the write
40
- * will actually land on, and a mismatch rolls the transaction back rather than
41
- * leaving a partial edit behind. swan-frontend does the same thing through
42
- * `sceneAccess`'s `beforeWrite` hook, and the message is its message verbatim --
43
- * it is what the MODEL reads and reacts to.
44
- */
45
- export declare function createKakapoSceneHost(engine: KakapoAPI, options: KakapoSceneHostOptions): SceneHost;
@@ -1,169 +0,0 @@
1
- // The Kakapo-backed `SceneHost`: `@womp/scene-api` over one Kakapo engine
2
- // session, and the ONLY optimistic-concurrency guard this package publishes.
3
- //
4
- // It had a sibling until this task: a `scene-editing` v1 capability over
5
- // `KakapoRuntime.inspect()`/`.edit()`, with its own revision check that hashed
6
- // OUTSIDE any transaction and its own receipt ladder that disagreed with this
7
- // one. Two guards, one skill version apart, one of them tested, is the exact
8
- // duplication this migration exists to remove -- so v1 is gone rather than
9
- // routed through here, along with `kakapo-capability-api.ts`,
10
- // `kakapo-scene-skill.ts` and the `KAKAPO_DECLARATIONS` the generator built from
11
- // them. `server/standalone.ts` serves v2 through this host.
12
- import { z } from "zod";
13
- import { createSceneApi, kakapoSceneRevision } from "@womp/scene-api";
14
- import { asSceneDraft, composeKakapoSceneSeams } from "./runtime.js";
15
- const screenshotSchema = z.object({
16
- targetId: z.number().int().optional(),
17
- view: z.enum(["front", "back", "left", "right", "top", "bottom", "isometric"]).optional(),
18
- });
19
- /**
20
- * The library-side `SceneHost`: `@womp/scene-api` over a Kakapo engine session,
21
- * with the same three methods swan-frontend's `createBrowserSceneHost` has.
22
- *
23
- * WHY BOTH `read` AND `edit` RUN INSIDE A TRANSACTION. `KakapoAPI.editScene`
24
- * calls `refreshScene()` before it hands out a draft (kakapo-sdk api.ts:197-231)
25
- * and serializes on `transactionTail`, so entering one is what makes a revision
26
- * mean "the engine's current scene" rather than "whatever the client last
27
- * cached". A `read()` that skipped it would hash a stale cache and then have
28
- * its own revision rejected by the very next `edit()`. The empty draft a read
29
- * opens sends no patch, because `editScene` only patches when the JSON diff is
30
- * non-empty. This is also the parity the browser host has, where `read` goes
31
- * through the same `sceneMutations.run` queue every mutation does.
32
- *
33
- * WHY THE STALENESS CHECK IS INSIDE THE TRANSACTION AND NOT AT ENTRY. It is
34
- * checked against the freshly refreshed draft, immediately before the callback's
35
- * first write, so it compares the expectation against the document the write
36
- * will actually land on, and a mismatch rolls the transaction back rather than
37
- * leaving a partial edit behind. swan-frontend does the same thing through
38
- * `sceneAccess`'s `beforeWrite` hook, and the message is its message verbatim --
39
- * it is what the MODEL reads and reacts to.
40
- */
41
- export function createKakapoSceneHost(engine, options) {
42
- const unitMultiplier = options.unitMultiplier ?? 1;
43
- const projectId = options.projectId ?? 0;
44
- let pending;
45
- // Lazily, and only once: `createKakapoSceneStore` needs a `SceneEdit`, which
46
- // only `editScene()` can hand out, and this factory is synchronous.
47
- //
48
- // A REJECTION IS NOT CACHED. Priming touches the network twice (`listFonts`
49
- // and the empty `editScene`), so a transient failure there must not poison the
50
- // host for the rest of the run -- the next call retries. The `catch` clears
51
- // `pending` and rethrows; it never swallows.
52
- const seamsOf = () => {
53
- pending ??= composeKakapoSceneSeams(engine).catch((error) => {
54
- pending = undefined;
55
- throw error;
56
- });
57
- return pending;
58
- };
59
- const sceneApi = (seams, print = () => undefined) => createSceneApi({
60
- store: seams.store,
61
- transaction: seams.transaction,
62
- // Kakapo has no library-material concept, so `pending` stays absent --
63
- // the "backing with no queue" case `MaterialCatalog` documents.
64
- catalog: { listSuperMaterialNames: () => [] },
65
- print,
66
- unitMultiplier,
67
- // `enableCurveV3` is deliberately not an option: Kakapo has no V1/V2
68
- // curve concept at all, so the package default of `true` is the only
69
- // correct value here (adapters/kakapo-store.ts's O3).
70
- });
71
- /** `transaction.run` reports failure rather than throwing it. */
72
- const runOrThrow = async (seams, body) => {
73
- const failure = await seams.transaction.run(body);
74
- if (failure !== null)
75
- throw failure;
76
- };
77
- return {
78
- async read(context) {
79
- context.signal.throwIfAborted();
80
- const seams = await seamsOf();
81
- let snapshot;
82
- await runOrThrow(seams, async () => {
83
- context.signal.throwIfAborted();
84
- const api = sceneApi(seams);
85
- snapshot = {
86
- revision: kakapoSceneRevision(seams.scene()),
87
- projectId,
88
- unitMultiplier,
89
- nodes: api.nodeList().map((id) => ({
90
- id,
91
- name: api.nodeGetName(id),
92
- type: api.nodeGetType(id),
93
- parentId: api.nodeGetParentId(id),
94
- })),
95
- };
96
- });
97
- if (snapshot === undefined) {
98
- throw new Error("read(): the scene transaction resolved without producing a snapshot.");
99
- }
100
- return snapshot;
101
- },
102
- async edit(callback, expectedRevision, context) {
103
- context.signal.throwIfAborted();
104
- if (typeof callback !== "function")
105
- throw new Error("scene.edit requires a callback.");
106
- const seams = await seamsOf();
107
- const receipt = {
108
- id: crypto.randomUUID(),
109
- capability: "scene",
110
- operation: "edit",
111
- details: { expectedRevision },
112
- };
113
- let entered = false;
114
- let changed = false;
115
- let value;
116
- const failure = await seams.transaction.run(async () => {
117
- context.signal.throwIfAborted();
118
- if (kakapoSceneRevision(seams.scene()) !== expectedRevision) {
119
- throw new Error("The scene changed. Read it again before editing.");
120
- }
121
- entered = true;
122
- value = await callback(asSceneDraft(sceneApi(seams)));
123
- context.signal.throwIfAborted();
124
- changed = kakapoSceneRevision(seams.scene()) !== expectedRevision;
125
- });
126
- if (failure !== null) {
127
- await context.recordReceipt({
128
- ...receipt,
129
- status: entered ? "unknown" : "rolled_back",
130
- });
131
- throw failure;
132
- }
133
- await context.recordReceipt({
134
- ...receipt,
135
- status: changed ? "committed" : "rolled_back",
136
- });
137
- return value;
138
- },
139
- async screenshot(settings, context) {
140
- context.signal.throwIfAborted();
141
- const input = screenshotSchema.parse(settings);
142
- let targetId;
143
- if (input.targetId !== undefined) {
144
- let target = engine.getNode(input.targetId);
145
- while (target.parentId !== null && target.parentId !== 0) {
146
- target = engine.getNode(target.parentId);
147
- }
148
- targetId = target.kind === "union" || target.kind === "group" ? target.id : input.targetId;
149
- }
150
- const view = input.view ?? "isometric";
151
- // Never composed into a scene transaction: a capture is a renderer read,
152
- // and the renderer refuses one behind a dirty draft.
153
- const image = await engine.captureScreenshot({
154
- targetId,
155
- view,
156
- timeoutMs: 30_000,
157
- });
158
- context.signal.throwIfAborted();
159
- return options.saveImage({
160
- data: image.data,
161
- mediaType: image.mediaType,
162
- width: image.width,
163
- height: image.height,
164
- view,
165
- targetId: image.targetId,
166
- }, context);
167
- },
168
- };
169
- }