@womp/spark-agent 2.0.0 → 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 (53) hide show
  1. package/README.md +5 -0
  2. package/dist/capabilities/health.d.ts +9 -0
  3. package/dist/capabilities/health.js +27 -0
  4. package/dist/capabilities.d.ts +3 -1
  5. package/dist/capabilities.js +1 -0
  6. package/dist/cli.js +1 -0
  7. package/dist/generated/health-declarations.d.ts +1 -0
  8. package/dist/generated/health-declarations.js +3 -0
  9. package/dist/geometry/backendRegistry.d.ts +37 -0
  10. package/dist/geometry/backendRegistry.js +61 -0
  11. package/dist/geometry/common.d.ts +26 -0
  12. package/dist/geometry/common.js +78 -0
  13. package/dist/geometry/compiler.d.ts +35 -0
  14. package/dist/geometry/compiler.js +115 -0
  15. package/dist/geometry/graph.d.ts +39 -0
  16. package/dist/geometry/graph.js +32 -0
  17. package/dist/geometry/index.d.ts +9 -0
  18. package/dist/geometry/index.js +12 -0
  19. package/dist/geometry/lift.d.ts +7 -0
  20. package/dist/geometry/lift.js +376 -0
  21. package/dist/geometry/lower.d.ts +9 -0
  22. package/dist/geometry/lower.js +363 -0
  23. package/dist/geometry/parameters.d.ts +23 -0
  24. package/dist/geometry/parameters.js +46 -0
  25. package/dist/geometry/schemas/backend-schema.json +3394 -0
  26. package/dist/geometry/schemas/flowir-dialect.json +976 -0
  27. package/dist/geometry/writeParamData.d.ts +18 -0
  28. package/dist/geometry/writeParamData.js +47 -0
  29. package/dist/geometry.d.ts +10 -0
  30. package/dist/geometry.js +19 -0
  31. package/dist/kakapo.d.ts +6 -1
  32. package/dist/kakapo.js +5 -0
  33. package/dist/openscad.d.ts +85 -0
  34. package/dist/openscad.js +223 -0
  35. package/dist/repair-state.d.ts +50 -0
  36. package/dist/repair-state.js +96 -0
  37. package/dist/scene-health.d.ts +49 -0
  38. package/dist/scene-health.js +176 -0
  39. package/dist/sdk-geometry-host.d.ts +12 -0
  40. package/dist/sdk-geometry-host.js +306 -0
  41. package/dist/sdk-openscad-host.d.ts +14 -0
  42. package/dist/sdk-openscad-host.js +296 -0
  43. package/dist/sdk-openscad-renderer.d.ts +11 -0
  44. package/dist/sdk-openscad-renderer.js +71 -0
  45. package/dist/sdk-scene-health-host.d.ts +4 -0
  46. package/dist/sdk-scene-health-host.js +13 -0
  47. package/dist/sdk-scene-host.d.ts +5 -2
  48. package/dist/sdk-scene-host.js +6 -5
  49. package/dist/server/sqlite-store.d.ts +2 -0
  50. package/dist/server/sqlite-store.js +55 -31
  51. package/dist/server/standalone.d.ts +9 -0
  52. package/dist/server/standalone.js +91 -15
  53. package/package.json +17 -3
@@ -1,21 +1,49 @@
1
1
  import { createAnthropic } from "@ai-sdk/anthropic";
2
2
  import { createOpenAI } from "@ai-sdk/openai";
3
- import { createHash } from "node:crypto";
4
3
  import express from "express";
5
4
  import { getSparkModel, SPARK_MODELS } from "../models.js";
6
- import { KakapoAPI } from "@womp/kakapo-sdk";
5
+ import { KakapoAPI, KakapoRpcError } from "@womp/kakapo-sdk";
7
6
  import { captureSdkSceneScreenshot } from "../sdk-scene-screenshot.js";
8
- import { composeCapabilities, createAccountCapability, createSceneCapability, } from "../capabilities.js";
7
+ import { composeCapabilities, createAccountCapability, createGeometryCapability, createOpenScadCapability, createSceneCapability, createSceneHealthCapability, } from "../capabilities.js";
9
8
  import { loadDemoSceneMaterials } from "./demo-scene-materials.js";
10
9
  import { createDemoAccountHost } from "./demo-account.js";
11
- import { createSdkSceneHost } from "../sdk-scene-host.js";
10
+ import { createSdkSceneEditor, createSdkSceneHost, } from "../sdk-scene-host.js";
11
+ import { createSdkGeometryHost } from "../sdk-geometry-host.js";
12
+ import { createSdkOpenScadHost } from "../sdk-openscad-host.js";
13
+ import { createSdkSceneHealthHost } from "../sdk-scene-health-host.js";
14
+ import { geometryReference } from "../geometry.js";
15
+ import { getSdkSceneAreaIds, hasSceneResourcePressure, readStableSdkSceneHealth, } from "../scene-health.js";
12
16
  import { QuickJSJavaScriptExecutor } from "../quickjs-executor.js";
13
17
  import { sparkModelOptions } from "../model-options.js";
14
18
  import { createSparkRunExecutor } from "./executor.js";
15
19
  import { createSparkAgentRouter } from "./express.js";
16
20
  import { SparkAgentService } from "./service.js";
17
21
  import { SqliteSparkStore } from "./sqlite-store.js";
22
+ export async function checkStandaloneServices(api) {
23
+ const [fonts, openScad] = await Promise.allSettled([
24
+ api.listFonts(),
25
+ api.validateOpenScad("// Spark capability check"),
26
+ ]);
27
+ const openScadStatus = openScad.status === "fulfilled"
28
+ ? "available"
29
+ : openScad.reason instanceof KakapoRpcError &&
30
+ openScad.reason.rpcCode === -32601
31
+ ? "unsupported"
32
+ : "unverified";
33
+ return {
34
+ fonts: fonts.status === "fulfilled" ? fonts.value : [],
35
+ fontsAvailable: fonts.status === "fulfilled",
36
+ openScadStatus,
37
+ };
38
+ }
18
39
  export async function createStandaloneSparkAgentApp(options) {
40
+ const logger = options.logger ?? console;
41
+ const configuredSceneIdentity = options.sceneIdentity?.trim() || undefined;
42
+ const sceneIdentity = configuredSceneIdentity ?? `session:${crypto.randomUUID()}`;
43
+ if (configuredSceneIdentity === undefined) {
44
+ logger.warn("Spark scene identity is unavailable; interrupted scene mutations will not be resumed across server restarts.");
45
+ }
46
+ let loggedCatalog;
19
47
  const apiBasePath = options.apiBasePath ?? "/agent";
20
48
  const store = new SqliteSparkStore(options.storagePath ?? ".spark/spark.sqlite", `${apiBasePath}/artifacts`);
21
49
  try {
@@ -36,16 +64,16 @@ export async function createStandaloneSparkAgentApp(options) {
36
64
  context.signal.throwIfAborted();
37
65
  await api.connect();
38
66
  context.signal.throwIfAborted();
67
+ const support = await checkStandaloneServices(api);
39
68
  const services = {
40
- fonts: await api.listFonts(),
69
+ fonts: support.fonts,
41
70
  ...(options.developmentProfile === "demo-account"
42
71
  ? await loadDemoSceneMaterials()
43
72
  : {}),
44
73
  };
45
- const sceneHost = createSdkSceneHost({
46
- targetKey: `${context.ownerId}:${createHash("sha256")
47
- .update(options.kakapoUrl)
48
- .digest("hex")}`,
74
+ const targetKey = `${context.ownerId}:${sceneIdentity}`;
75
+ const editorOptions = {
76
+ targetKey,
49
77
  operations: store,
50
78
  saveToRenderer: true,
51
79
  withConnection: async (invocation, action) => {
@@ -58,6 +86,23 @@ export async function createStandaloneSparkAgentApp(options) {
58
86
  if (!api.isConnected)
59
87
  throw new Error("The Kakapo connection is unavailable");
60
88
  },
89
+ };
90
+ const editor = createSdkSceneEditor(editorOptions);
91
+ const repairs = store.repairStateStore(`${targetKey}:${context.runId}`);
92
+ let latestHealth;
93
+ const onHealth = (health) => {
94
+ latestHealth = health;
95
+ };
96
+ const canGrow = () => latestHealth === undefined ||
97
+ hasSceneResourcePressure(latestHealth) === false;
98
+ const sceneHost = createSdkSceneHost({
99
+ ...editorOptions,
100
+ editor,
101
+ onSceneCommitted: async (_operation, api) => {
102
+ const sceneHealth = await readStableSdkSceneHealth(api, getSdkSceneAreaIds(api), context.signal);
103
+ onHealth(sceneHealth);
104
+ return { sceneHealth };
105
+ },
61
106
  services: async () => services,
62
107
  screenshot: async (settings, invocation) => {
63
108
  invocation.signal.throwIfAborted();
@@ -66,14 +111,45 @@ export async function createStandaloneSparkAgentApp(options) {
66
111
  return artifactStore.write(context.ownerId, image);
67
112
  },
68
113
  });
114
+ const capabilityBindings = {
115
+ scene: createSceneCapability(sceneHost),
116
+ health: createSceneHealthCapability(createSdkSceneHealthHost(editor, onHealth)),
117
+ geometry: createGeometryCapability(createSdkGeometryHost({
118
+ editor,
119
+ repairs,
120
+ canGrow,
121
+ onHealth,
122
+ }), geometryReference()),
123
+ ...(support.openScadStatus !== "unsupported"
124
+ ? {
125
+ openscad: createOpenScadCapability(createSdkOpenScadHost({ editor, repairs, canGrow, onHealth })),
126
+ }
127
+ : {}),
128
+ ...(options.developmentProfile === "demo-account"
129
+ ? { account: createAccountCapability(createDemoAccountHost()) }
130
+ : {}),
131
+ };
132
+ const capabilities = composeCapabilities(capabilityBindings);
133
+ const catalog = `${Object.keys(capabilityBindings).join(",")}\n${capabilities.skills.map(({ name }) => name).join(",")}`;
134
+ if (catalog !== loggedCatalog) {
135
+ logger.info(`Spark capabilities enabled: ${Object.keys(capabilityBindings).join(", ")}`);
136
+ logger.info(`Spark skills enabled: ${capabilities.skills
137
+ .map(({ name }) => name)
138
+ .join(", ")}`);
139
+ loggedCatalog = catalog;
140
+ }
141
+ if (support.fontsAvailable === false) {
142
+ logger.warn("Spark font discovery is unavailable; the scene binding will use an empty font catalog.");
143
+ }
144
+ if (support.openScadStatus === "unsupported") {
145
+ logger.warn("Spark OpenSCAD validation is unavailable; the parametric-parts skill is disabled.");
146
+ }
147
+ if (support.openScadStatus === "unverified") {
148
+ logger.warn("Spark OpenSCAD validation could not be verified; the parametric-parts skill remains enabled and will report service errors when used.");
149
+ }
69
150
  return {
70
151
  executor: new QuickJSJavaScriptExecutor(),
71
- capabilities: composeCapabilities({
72
- scene: createSceneCapability(sceneHost),
73
- ...(options.developmentProfile === "demo-account"
74
- ? { account: createAccountCapability(createDemoAccountHost()) }
75
- : {}),
76
- }),
152
+ capabilities,
77
153
  artifacts: {
78
154
  resolve: async (ref) => {
79
155
  const stored = await artifactStore.get(context.ownerId, ref.id);
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@womp/spark-agent",
3
- "version": "2.0.0",
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",
@@ -60,6 +70,7 @@
60
70
  "dist/**/*.js",
61
71
  "dist/**/*.d.ts",
62
72
  "dist/server/fixtures/**/*.json",
73
+ "dist/geometry/schemas/**/*.json",
63
74
  "README.md"
64
75
  ],
65
76
  "sideEffects": false,
@@ -85,7 +96,7 @@
85
96
  "dev:web": "vite --config web/vite.config.ts",
86
97
  "start": "node dist/cli.js",
87
98
  "web:build": "yarn build && tsc --noEmit -p web/tsconfig.json && vite build --config web/vite.config.ts",
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')])\"",
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')])\"",
89
100
  "test:live": "tsx --tsconfig tsconfig.json test/womp-scene-api.live.ts",
90
101
  "prepack": "yarn build"
91
102
  },
@@ -93,16 +104,19 @@
93
104
  "@ai-sdk/anthropic": "4.0.50",
94
105
  "@ai-sdk/openai": "4.0.63",
95
106
  "@jitl/quickjs-wasmfile-release-sync": "0.32.0",
107
+ "@womp/flowir": "0.3.0",
96
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",