@womp/spark-agent 1.0.0 → 2.0.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/README.md +37 -19
- package/dist/agent.js +1 -1
- package/dist/capabilities/scene-draft.d.ts +2 -404
- package/dist/capabilities/scene.d.ts +1 -1
- package/dist/capabilities/scene.js +13 -4
- package/dist/cli.js +19 -2
- package/dist/client.js +15 -15
- package/dist/context.d.ts +1 -1
- package/dist/context.js +6 -4
- package/dist/coordinates.d.ts +23 -0
- package/dist/coordinates.js +132 -0
- package/dist/generated/scene-declarations.d.ts +1 -1
- package/dist/generated/scene-declarations.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/kakapo.d.ts +4 -5
- package/dist/kakapo.js +2 -6
- package/dist/pricing.js +9 -29
- package/dist/runtime.d.ts +16 -36
- package/dist/runtime.js +132 -139
- package/dist/scene-environment.d.ts +25 -0
- package/dist/scene-environment.js +76 -0
- package/dist/scene-metadata.d.ts +6 -0
- package/dist/scene-metadata.js +65 -0
- package/dist/scene-operations.d.ts +47 -0
- package/dist/scene-operations.js +126 -0
- package/dist/sdk-scene-host.d.ts +309 -0
- package/dist/sdk-scene-host.js +201 -0
- package/dist/sdk-scene-screenshot.d.ts +7 -0
- package/dist/sdk-scene-screenshot.js +17 -0
- package/dist/server/demo-scene-materials.d.ts +3 -0
- package/dist/server/demo-scene-materials.js +18 -0
- package/dist/server/express.js +2 -4
- package/dist/server/fixtures/materials/matte-blue.json +14 -0
- package/dist/server/fixtures/materials/polished-copper.json +14 -0
- package/dist/server/index.d.ts +2 -1
- package/dist/server/index.js +2 -1
- package/dist/server/service.d.ts +4 -0
- package/dist/server/service.js +26 -2
- package/dist/server/sqlite-store.d.ts +29 -0
- package/dist/server/sqlite-store.js +200 -0
- package/dist/server/standalone.d.ts +5 -1
- package/dist/server/standalone.js +78 -21
- package/dist/server/store.js +3 -1
- package/dist/types.d.ts +1 -1
- package/dist/womp-scene-api.d.ts +283 -0
- package/dist/womp-scene-api.js +974 -0
- package/package.json +7 -9
- package/dist/kakapo-capability.d.ts +0 -45
- package/dist/kakapo-capability.js +0 -169
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@womp/spark-agent",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.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",
|
|
@@ -59,11 +59,12 @@
|
|
|
59
59
|
"files": [
|
|
60
60
|
"dist/**/*.js",
|
|
61
61
|
"dist/**/*.d.ts",
|
|
62
|
+
"dist/server/fixtures/**/*.json",
|
|
62
63
|
"README.md"
|
|
63
64
|
],
|
|
64
65
|
"sideEffects": false,
|
|
65
66
|
"engines": {
|
|
66
|
-
"node": ">=22"
|
|
67
|
+
"node": ">=22.13"
|
|
67
68
|
},
|
|
68
69
|
"repository": {
|
|
69
70
|
"type": "git",
|
|
@@ -75,7 +76,7 @@
|
|
|
75
76
|
"license": "MIT",
|
|
76
77
|
"scripts": {
|
|
77
78
|
"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",
|
|
79
|
+
"build": "yarn clean && node scripts/generate-skill-declarations.mjs && tsc -p tsconfig.json && node scripts/copy-fixtures.mjs",
|
|
79
80
|
"typecheck": "tsc --noEmit -p tsconfig.json && tsc --noEmit -p web/tsconfig.json",
|
|
80
81
|
"lint": "yarn typecheck",
|
|
81
82
|
"dev": "yarn build && concurrently --kill-others \"yarn dev:server\" \"yarn dev:web\"",
|
|
@@ -84,16 +85,15 @@
|
|
|
84
85
|
"dev:web": "vite --config web/vite.config.ts",
|
|
85
86
|
"start": "node dist/cli.js",
|
|
86
87
|
"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')
|
|
88
|
-
"test:live": "tsx --tsconfig tsconfig.json test/
|
|
88
|
+
"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')])\"",
|
|
89
|
+
"test:live": "tsx --tsconfig tsconfig.json test/womp-scene-api.live.ts",
|
|
89
90
|
"prepack": "yarn build"
|
|
90
91
|
},
|
|
91
92
|
"dependencies": {
|
|
92
93
|
"@ai-sdk/anthropic": "4.0.50",
|
|
93
94
|
"@ai-sdk/openai": "4.0.63",
|
|
94
95
|
"@jitl/quickjs-wasmfile-release-sync": "0.32.0",
|
|
95
|
-
"@womp/kakapo-sdk": "0.
|
|
96
|
-
"@womp/scene-api": "0.2.0",
|
|
96
|
+
"@womp/kakapo-sdk": "0.3.0",
|
|
97
97
|
"ai": "7.0.95",
|
|
98
98
|
"eventsource-parser": "^3.0.6",
|
|
99
99
|
"express": "^5.2.1",
|
|
@@ -109,8 +109,6 @@
|
|
|
109
109
|
"@vitejs/plugin-react": "^6.0.4",
|
|
110
110
|
"concurrently": "^9.2.1",
|
|
111
111
|
"lucide-react": "^1.26.0",
|
|
112
|
-
"prettier": "^3.8.1",
|
|
113
|
-
"pretty-quick": "^4.2.2",
|
|
114
112
|
"react": "^19.2.8",
|
|
115
113
|
"react-dom": "^19.2.8",
|
|
116
114
|
"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
|
-
}
|