@womp/spark-agent 15.7.0 → 17.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/CHANGELOG.md CHANGED
@@ -4,6 +4,71 @@ Notable changes to `@womp/spark-agent`, newest first. Versions follow
4
4
  [Semantic Versioning](https://semver.org/). Add an entry with each version bump; describe what
5
5
  changed for hosts and users, and how to migrate across breaking changes.
6
6
 
7
+ ## 17.0.0 — 2026-11-03
8
+
9
+ Web search is the model's own: a run with the `web` fact gives an Anthropic (Messages API) or
10
+ OpenAI (Responses API) model its provider's web search tool, and the new `web-search` skill. The
11
+ model reads the results itself instead of a summary from a second model.
12
+
13
+ ### Breaking
14
+
15
+ - `womp.web.search`, `WebHost.search` and `WebSearchResult` are removed. `WebHost` is
16
+ `{ fetchImage }`. Hosts drop their search implementation; the search is billed with the model
17
+ call that ran it (Anthropic `usage.server_tool_use.web_search_requests`, OpenAI
18
+ `web_search_call` output items).
19
+
20
+ ### Changed
21
+
22
+ - `SparkSkill.nativeTool` names a provider tool a skill is about. The run lists such a skill, and
23
+ sends its tool, only when its model can run it: OpenAI Chat Completions, Gemini, OpenRouter and
24
+ gateway models get neither the `web-search` skill nor the tool.
25
+ - The `web` skill (version 2) covers `womp.web.fetchImage` alone.
26
+ - A stored search (`tool-web_search` part) is replayed in later turns as a text note of what was
27
+ searched and the pages found, so a conversation reads the same after a change of model and the
28
+ pages' contents are not resent every turn.
29
+
30
+ ## 16.0.0 — 2026-11-02
31
+
32
+ Spark now owns every capability: its skills, prompt rules, which capabilities a run offers and how
33
+ they behave. Hosts supply services and run facts, so a bench given the same facts runs exactly what
34
+ production runs.
35
+
36
+ ### Breaking
37
+
38
+ - `createSparkCapabilities({ hosts, facts })` is the only way to build a run's capabilities.
39
+ `facts` are crow's capability gates (`scene`, `health`, `geometry`, `openScad`, `flow`,
40
+ `flowRuns`, `operations`, `knowledge`, `account`, `web`) plus `projectBound`; `hosts` are the
41
+ service interfaces (`assets`, `imports`, `textureImports`, `operations`, `account`, `flow` with
42
+ `flowNodeCatalog`, `flowRuns`, `geometry`, `scene` with its `health`, `materials`, `openscad`,
43
+ `print`, `knowledge`, `web`, `project`). The composition order is unchanged. An enabled
44
+ capability without its host throws instead of being left out.
45
+ - `composeCapabilities`, `SparkCapability` and every `create*Capability` are no longer exported,
46
+ and `SparkCapabilities` cannot be built by hand. Scene scripts use
47
+ `createSceneScriptCapabilities(sceneHost)`.
48
+ - `runSparkAgent`'s `instructions` option is replaced by `unattended: true`, which adds the rules
49
+ for a run nobody attends after the agent prompt. `SPARK_AGENT_PROMPT` is no longer exported, and
50
+ `sparkSystemPrompt(skills, instructions, modelId)` is now `sparkSystemPrompt(skills, { modelId,
51
+ unattended })`.
52
+
53
+ ### Moved from crow-backend
54
+
55
+ - The `web` skill (`womp.web.search`, `womp.web.fetchImage`) and its argument checks; crow keeps
56
+ the billed search and the image download behind `WebHost`.
57
+ - The `project-choice` skill (version 2, which also names print estimates among the tools that
58
+ ask for a project) and the project gate: with `hosts.project`, scene, screenshot, health, Geometry
59
+ Nodes, materials, OpenSCAD, print estimate and Flow calls, and imports into the scene, call
60
+ `ensureProject` first. Crow keeps choosing and binding the project behind `ProjectHost`.
61
+ - `finishImport` caps a wait over 30 s at 30 s and says to wait again, instead of rejecting it.
62
+ - The unattended (Flow node) rules, previously crow's `HEADLESS_INSTRUCTIONS`, word for word.
63
+
64
+ ### Migration
65
+
66
+ Replace `composeCapabilities({ ... })` with `createSparkCapabilities({ hosts, facts })`, delete
67
+ host-written skills and wrappers listed above, and pass `unattended: true` instead of a headless
68
+ system prompt. Crow's `action-recovery` skill is dropped: crow never resumed an interrupted run, so
69
+ it always answered `operation: null`. The first turn after deploy misses the provider prompt cache
70
+ once, because the skills directory changes.
71
+
7
72
  ## 15.7.0 — 2026-11-02
8
73
 
9
74
  Spark looks up the export steps with the help lookup when a user wants a file format, instead of
package/README.md CHANGED
@@ -22,7 +22,7 @@ npm install @womp/spark-agent
22
22
 
23
23
  - `@womp/spark-agent` — browser-safe model loop, two tools, persistence hooks, and shared contracts
24
24
  - `@womp/spark-agent/browser` — native JavaScript executor and local chat transport
25
- - `@womp/spark-agent/capabilities` — capability composition and skill contracts
25
+ - `@womp/spark-agent/capabilities` — `createSparkCapabilities` and the host service interfaces
26
26
  - `@womp/spark-agent/kakapo` — direct Kakapo runtime and scene capability
27
27
  - `@womp/spark-agent/quickjs` — optional isolated JavaScript executor
28
28
  - `@womp/spark-agent/ui` — browser-safe UI message types, schemas, and model catalog
@@ -36,22 +36,29 @@ Kakapo, Express, or React at runtime.
36
36
  ## Running in a host application
37
37
 
38
38
  `runSparkAgent` accepts a configured model, the stored conversation (`history`, compacted once it
39
- is long) or model messages, an executor, a capability composition, and an artifact resolver. It exposes exactly `read_skill` and `execute_javascript` to the model.
39
+ is long) or model messages, an executor, the run's capabilities, and an artifact resolver. It exposes exactly `read_skill` and `execute_javascript` to the model.
40
40
  Skills carry instructions, declarations, and JavaScript examples. Kakapo skill declarations are
41
41
  generated from its typed API at build time and packaged as JavaScript strings.
42
42
 
43
43
  ### System prompt and editor selection
44
44
 
45
- Every host sends `sparkSystemPrompt(skills)`: the shared agent prompt and the skills directory,
46
- with nothing host-specific, so it stays identical across a conversation. Hosts attach the editor
45
+ Every run sends `sparkSystemPrompt(skills)`: the shared agent prompt and the skills directory,
46
+ with nothing host-specific, so it stays identical across a conversation. A run nobody attends, such
47
+ as a Flow node's, passes `unattended: true` and gets the unattended rules after the agent prompt.
48
+ Hosts attach the editor
47
49
  selection to the user message it was sent with as a `data-selection` part (`{ nodeIds }`). It is
48
50
  not rendered as chat text; the model reads it as a short note on that message.
49
51
 
50
52
  ### Capabilities
51
53
 
52
- Compose only supported capabilities with `composeCapabilities({ scene, account, ... })`. Each
53
- capability supplies its skills and `createApi(context)`; the returned API is bound under `womp`.
54
- Every invocation receives a cancellation signal and an awaited `recordReceipt` hook. Capabilities
54
+ Spark defines every skill. A host builds a run's capabilities with
55
+ `createSparkCapabilities({ hosts, facts })`: `hosts` implements the service interfaces (`SceneHost`,
56
+ `AccountHost`, `FlowHost`, ...), and `facts` says what the run's user and conversation allow
57
+ (`scene`, `operations`, `flow`, `projectBound`, ...). Spark decides from the facts which skills the
58
+ run offers and in which order, and binds each API under `womp`; an enabled capability without its
59
+ host throws. With `hosts.project`, a conversation with no project offers `project-choice` and every
60
+ project tool asks for a project first. Hosts cannot add skills or build a capability set by hand.
61
+ Every invocation receives a cancellation signal and an awaited `recordReceipt` hook. Host services
55
62
  own their transactions and must check cancellation at their commit boundary.
56
63
 
57
64
  For a real user interaction, call `context.waitForUser(label, async signal => ...)` outside mutation
@@ -63,7 +70,7 @@ Shared SDK scene adapters apply each edit directly to the scene and save it; not
63
70
  or replayed. An edit that fails after it began throws `SceneOperationError`, whose `operation`
64
71
  reports whether the edit was committed, rolled back or left uncertain.
65
72
 
66
- `createPrintCapability(createSdkPrintHost({ editor, price }))` offers `womp.printing.estimate`:
73
+ `hosts.print: createSdkPrintHost({ editor, price })` backs `womp.printing.estimate`:
67
74
  the engine measures the parts (`set_3dp_context`) and the host's `price` prices the measurement for
68
75
  the run's user, as swan's print estimate does. A host that serializes the engine's print context with
69
76
  other wall-thickness checks passes its own `requestPrintContext`.
package/dist/agent.d.ts CHANGED
@@ -29,7 +29,8 @@ export type SparkAgentOptions = {
29
29
  runId: string;
30
30
  messageId: string;
31
31
  signal?: AbortSignal;
32
- instructions?: string;
32
+ /** No person attends the run (a Flow node's): the agent never asks, offers or waits. */
33
+ unattended?: boolean;
33
34
  maxSteps?: number;
34
35
  maxOutputTokens?: number;
35
36
  executionTimeoutMs?: number;
package/dist/agent.js CHANGED
@@ -1,6 +1,7 @@
1
1
  import { sparkErrorDiagnostics } from "./error-diagnostics.js";
2
2
  import { createUIMessageStream, InvalidToolInputError, NoSuchToolError, stepCountIs, streamText, ToolCallRepairError, } from "ai";
3
3
  import { createSparkTools } from "./agent-tools.js";
4
+ import { withNativeTools } from "./native-tools.js";
4
5
  import { sparkSystemPrompt } from "./prompt.js";
5
6
  import { calculateStepCost } from "./pricing.js";
6
7
  import { contextWindowFor } from "./context-window.js";
@@ -136,19 +137,27 @@ export function runSparkAgent(options) {
136
137
  let stepCount = 0;
137
138
  try {
138
139
  controller.signal.throwIfAborted();
139
- const tools = createSparkTools({
140
- ...options,
141
- controller,
142
- write: (chunk) => writer.write(chunk),
143
- });
144
- const readSystem = () => sparkSystemPrompt(options.capabilities.skills, options.instructions, options.modelId);
140
+ // A skill about a provider tool is offered, with its tool, only when
141
+ // this run's model can run it.
142
+ const native = withNativeTools(options.model, options.capabilities);
143
+ const { capabilities } = native;
144
+ const tools = {
145
+ ...createSparkTools({
146
+ ...options,
147
+ capabilities,
148
+ controller,
149
+ write: (chunk) => writer.write(chunk),
150
+ }),
151
+ ...native.tools,
152
+ };
153
+ const readSystem = () => sparkSystemPrompt(capabilities.skills, { modelId: options.modelId, unattended: options.unattended });
145
154
  let messages = options.messages ?? [];
146
155
  // Compaction before each later step; only for a stored conversation,
147
156
  // where the compaction can be recorded.
148
157
  let compactStep;
149
158
  if (options.history !== undefined) {
150
159
  const history = options.history;
151
- const skills = options.capabilities.skills;
160
+ const skills = capabilities.skills;
152
161
  let compactions = 0;
153
162
  const summaryOptions = {
154
163
  model: options.model,
@@ -14,8 +14,11 @@ const requestSchema = z
14
14
  destination: z.enum(["scene", "library"]),
15
15
  })
16
16
  .strict();
17
+ /** The longest one finishImport waits; a longer request waits this long and says so. */
18
+ const MAX_IMPORT_WAIT_MS = 30_000;
19
+ const CAPPED_IMPORT_WAIT = `This call waited ${MAX_IMPORT_WAIT_MS} ms, the longest a single wait allows. Call finishImport again with the same key to keep waiting.`;
17
20
  const waitSchema = z
18
- .object({ timeoutMs: z.number().int().min(1).max(30_000).default(15_000) })
21
+ .object({ timeoutMs: z.number().int().min(1).default(15_000) })
19
22
  .strict();
20
23
  const imageRequestSchema = requestSchema.extend({
21
24
  kind: z.enum(["image-plane", "sticker"]),
@@ -112,9 +115,16 @@ or meshes. Image imports can fail or have an unknown outcome; do not blindly upl
112
115
  context.signal.throwIfAborted();
113
116
  return host.readImport(keySchema.parse(key), context);
114
117
  },
115
- finishImport: (key, options) => {
118
+ finishImport: async (key, options) => {
116
119
  context.signal.throwIfAborted();
117
- return host.finishImport(keySchema.parse(key), waitSchema.parse(options ?? {}), context);
120
+ const importKey = keySchema.parse(key);
121
+ const { timeoutMs } = waitSchema.parse(options ?? {});
122
+ // A slow import is when the model asks for a longer wait; capping it
123
+ // rather than rejecting the call saves the step a rejection costs.
124
+ if (timeoutMs <= MAX_IMPORT_WAIT_MS)
125
+ return host.finishImport(importKey, { timeoutMs }, context);
126
+ const result = await host.finishImport(importKey, { timeoutMs: MAX_IMPORT_WAIT_MS }, context);
127
+ return { ...result, reason: [result.reason, CAPPED_IMPORT_WAIT].filter(Boolean).join(" ") };
118
128
  },
119
129
  }),
120
130
  };
@@ -0,0 +1,35 @@
1
+ import type { SparkCapability, SparkInvocationContext } from "../capabilities.js";
2
+ import type { AssetImportsHost } from "./asset-imports.js";
3
+ import type { FlowHost } from "./flow.js";
4
+ import type { GeometryHost } from "./geometry.js";
5
+ import type { MaterialsHost } from "./materials.js";
6
+ import type { OpenScadHost } from "./openscad.js";
7
+ import type { PrintHost } from "./print.js";
8
+ import type { SceneHost } from "./scene.js";
9
+ /** The step a project tool names when it asks for the conversation's project. */
10
+ export type ProjectTool = "scene" | "screenshot" | "geometry" | "openscad" | "flow" | "asset-import";
11
+ /**
12
+ * A conversation that may have no project yet. The first project tool call of
13
+ * such a conversation asks the user to choose one.
14
+ */
15
+ export interface ProjectHost {
16
+ /** Resolves once the conversation has a project; rejects with the sentence the call answers otherwise. */
17
+ ensureProject(context: SparkInvocationContext, tool: ProjectTool): Promise<void>;
18
+ /** The new project's name the user will be offered. */
19
+ suggestTitle(title: string): void;
20
+ }
21
+ export type WompProjectApi = {
22
+ /** Records the name offered for a new project. */
23
+ suggestTitle(title: string): Promise<void>;
24
+ };
25
+ /** Offered only while the conversation has no project. */
26
+ export declare function createProjectChoiceCapability(host: ProjectHost): SparkCapability<WompProjectApi>;
27
+ export declare function gateSceneHost(host: SceneHost, project: ProjectHost): SceneHost;
28
+ export declare function gateGeometryHost(host: GeometryHost, project: ProjectHost): GeometryHost;
29
+ export declare function gateMaterialsHost(host: MaterialsHost, project: ProjectHost): MaterialsHost;
30
+ export declare function gatePrintHost(host: PrintHost, project: ProjectHost): PrintHost;
31
+ export declare function gateOpenScadHost(host: OpenScadHost, project: ProjectHost): OpenScadHost;
32
+ /** A Flow call asks for the project before the host could refuse it for having no Flow graph. */
33
+ export declare function gateFlowHost(host: FlowHost, project: ProjectHost): FlowHost;
34
+ /** An import into the scene asks for the project; a library import needs none. */
35
+ export declare function gateAssetImportsHost(host: AssetImportsHost, project: ProjectHost): AssetImportsHost;
@@ -0,0 +1,142 @@
1
+ import { z } from "zod";
2
+ import { WOMP_PROJECT_DECLARATIONS } from "../generated/project-declarations.js";
3
+ const title = z.string().trim().min(1, "A project name is required.").max(100);
4
+ /** Offered only while the conversation has no project. */
5
+ export function createProjectChoiceCapability(host) {
6
+ return {
7
+ skills: [
8
+ {
9
+ name: "project-choice",
10
+ version: "2",
11
+ description: "This conversation has no project yet; suggest the name of the new project the user may create.",
12
+ instructions: `The scene, screenshot, Geometry Nodes, parametric part, print estimate and Flow tools, and imports into the scene, ask the user to choose a project the first time one of them is called.
13
+ Call womp.project.suggestTitle once, before that first call, with a short name (at most 100 characters) for a new project that fits the request; the user sees it as the suggested name and can change it.
14
+ If the user chooses no project, that call fails with a sentence saying so; tell the user and carry on without the scene.`,
15
+ declarations: WOMP_PROJECT_DECLARATIONS,
16
+ examples: ['await womp.project.suggestTitle("Desk lamp");'],
17
+ },
18
+ ],
19
+ createApi: () => ({
20
+ suggestTitle: async (value) => host.suggestTitle(title.parse(value)),
21
+ }),
22
+ };
23
+ }
24
+ // Each gated method asks for the project first, naming its step. Written out per
25
+ // method rather than proxied: a proxy would silently pass through a method the
26
+ // host interface grows later.
27
+ export function gateSceneHost(host, project) {
28
+ const health = host.health;
29
+ return {
30
+ ...(health === undefined
31
+ ? {}
32
+ : {
33
+ async health(objectIds, context) {
34
+ await project.ensureProject(context, "scene");
35
+ return health(objectIds, context);
36
+ },
37
+ }),
38
+ async access(callback, context) {
39
+ await project.ensureProject(context, "scene");
40
+ return host.access(callback, context);
41
+ },
42
+ async screenshot(options, context) {
43
+ await project.ensureProject(context, "screenshot");
44
+ return host.screenshot(options, context);
45
+ },
46
+ };
47
+ }
48
+ export function gateGeometryHost(host, project) {
49
+ return {
50
+ async read(objectId, context) {
51
+ await project.ensureProject(context, "geometry");
52
+ return host.read(objectId, context);
53
+ },
54
+ async write(options, context) {
55
+ await project.ensureProject(context, "geometry");
56
+ return host.write(options, context);
57
+ },
58
+ };
59
+ }
60
+ export function gateMaterialsHost(host, project) {
61
+ return {
62
+ async catalog(options, context) {
63
+ await project.ensureProject(context, "scene");
64
+ return host.catalog(options, context);
65
+ },
66
+ async read(materialId, context) {
67
+ await project.ensureProject(context, "scene");
68
+ return host.read(materialId, context);
69
+ },
70
+ async write(options, context) {
71
+ await project.ensureProject(context, "scene");
72
+ return host.write(options, context);
73
+ },
74
+ async readProgram(materialId, layerIndex, context) {
75
+ await project.ensureProject(context, "scene");
76
+ return host.readProgram(materialId, layerIndex, context);
77
+ },
78
+ async writeProgram(options, context) {
79
+ await project.ensureProject(context, "scene");
80
+ return host.writeProgram(options, context);
81
+ },
82
+ async status(context) {
83
+ await project.ensureProject(context, "scene");
84
+ return host.status(context);
85
+ },
86
+ };
87
+ }
88
+ export function gatePrintHost(host, project) {
89
+ return {
90
+ async estimate(request, context) {
91
+ await project.ensureProject(context, "scene");
92
+ return host.estimate(request, context);
93
+ },
94
+ };
95
+ }
96
+ export function gateOpenScadHost(host, project) {
97
+ return {
98
+ async read(objectId, context) {
99
+ await project.ensureProject(context, "openscad");
100
+ return host.read(objectId, context);
101
+ },
102
+ async create(options, context) {
103
+ await project.ensureProject(context, "openscad");
104
+ return host.create(options, context);
105
+ },
106
+ async update(options, context) {
107
+ await project.ensureProject(context, "openscad");
108
+ return host.update(options, context);
109
+ },
110
+ };
111
+ }
112
+ /** A Flow call asks for the project before the host could refuse it for having no Flow graph. */
113
+ export function gateFlowHost(host, project) {
114
+ return {
115
+ async read(context) {
116
+ await project.ensureProject(context, "flow");
117
+ return host.read(context);
118
+ },
119
+ async write(options, context) {
120
+ await project.ensureProject(context, "flow");
121
+ return host.write(options, context);
122
+ },
123
+ };
124
+ }
125
+ /** An import into the scene asks for the project; a library import needs none. */
126
+ export function gateAssetImportsHost(host, project) {
127
+ return {
128
+ async importMesh(request, context) {
129
+ if (request.destination === "scene")
130
+ await project.ensureProject(context, "asset-import");
131
+ return host.importMesh(request, context);
132
+ },
133
+ async importImage(request, context) {
134
+ if (request.destination === "scene")
135
+ await project.ensureProject(context, "asset-import");
136
+ return host.importImage(request, context);
137
+ },
138
+ retryMeshImport: (request, context) => host.retryMeshImport(request, context),
139
+ readImport: (key, context) => host.readImport(key, context),
140
+ finishImport: (key, options, context) => host.finishImport(key, options, context),
141
+ };
142
+ }
@@ -0,0 +1,10 @@
1
+ import type { ArtifactRef, SparkCapability, SparkInvocationContext } from "../capabilities.js";
2
+ export type WompWebApi = {
3
+ /** Downloads an image from a public http(s) URL into this conversation; emitImage(ref) shows it to you. */
4
+ fetchImage(url: string): Promise<ArtifactRef>;
5
+ };
6
+ /** The host stores fetched images as conversation artifacts. */
7
+ export interface WebHost {
8
+ fetchImage(url: string, context: SparkInvocationContext): Promise<ArtifactRef>;
9
+ }
10
+ export declare function createWebCapability(host: WebHost): SparkCapability<WompWebApi>;
@@ -0,0 +1,39 @@
1
+ import { z } from "zod";
2
+ import { WOMP_WEB_DECLARATIONS } from "../generated/web-declarations.js";
3
+ /**
4
+ * Searching is the model's own provider tool (../native-tools.ts), not a
5
+ * `womp` API: the run offers this skill only when its model can run it.
6
+ */
7
+ const WEB_SEARCH_SKILL = {
8
+ name: "web-search",
9
+ version: "1",
10
+ description: "Search the web for facts you do not know or that change.",
11
+ instructions: `Your web_search tool searches the web and shows you the results. It is a tool of its own: call it directly, not from execute_javascript.
12
+ Search when the request depends on facts you do not know or that change: what a real place, building, product, person or object looks like, current information, specifications. Say which pages your answer comes from.
13
+ Results are web pages, not images.
14
+ Prefer one well-aimed search over many; every search is billed.`,
15
+ declarations: "",
16
+ examples: [],
17
+ nativeTool: "web_search",
18
+ };
19
+ export function createWebCapability(host) {
20
+ return {
21
+ skills: [
22
+ {
23
+ name: "web",
24
+ version: "2",
25
+ description: "Fetch images from the web to look at or use as references.",
26
+ instructions: `Use womp.web.fetchImage with a direct image URL to bring an image into this conversation; it returns an artifact reference: await emitImage(ref) to look at it, and pass it to a generation as a reference image.
27
+ Only public http(s) URLs of an image work: a web page's URL is refused.`,
28
+ declarations: WOMP_WEB_DECLARATIONS,
29
+ examples: [
30
+ 'const photo = await womp.web.fetchImage("https://example.com/photo.jpg");\nawait emitImage(photo);',
31
+ ],
32
+ },
33
+ WEB_SEARCH_SKILL,
34
+ ],
35
+ createApi: (context) => ({
36
+ fetchImage: (url) => host.fetchImage(z.string().trim().min(1, "An image URL is required.").parse(url), context),
37
+ }),
38
+ };
39
+ }
@@ -35,7 +35,15 @@ export type SparkSkill = {
35
35
  instructions: string;
36
36
  declarations: string;
37
37
  examples: string[];
38
+ /**
39
+ * The model provider's own tool this skill is about. The run offers the
40
+ * skill, and the tool, only when its model can run that tool
41
+ * (../native-tools.ts).
42
+ */
43
+ nativeTool?: SparkNativeToolName;
38
44
  };
45
+ /** A tool the model's provider runs itself, rather than a `womp` API. */
46
+ export type SparkNativeToolName = "web_search";
39
47
  export type ExecutionReceipt = {
40
48
  id: string;
41
49
  capability: string;
@@ -59,10 +67,15 @@ export type SparkCapability<TApi extends object = object> = {
59
67
  skills: readonly SparkSkill[];
60
68
  createApi(context: SparkInvocationContext): TApi;
61
69
  };
70
+ declare const composed: unique symbol;
71
+ /**
72
+ * A run's skills and `womp.*` globals. Only Spark composes one
73
+ * (`createSparkCapabilities`), so every skill a run can read is defined here.
74
+ */
62
75
  export type SparkCapabilities = {
63
- /** Hosts may use a getter to refresh the catalog when their available services change. */
64
- skills: readonly SparkSkill[];
76
+ readonly skills: readonly SparkSkill[];
65
77
  createApi(context: SparkInvocationContext): JavaScriptGlobals;
78
+ readonly [composed]: true;
66
79
  };
67
80
  /** The enabled bindings are also the only source of discoverable skills. */
68
81
  export declare function composeCapabilities(capabilities: Record<string, SparkCapability>): SparkCapabilities;
@@ -0,0 +1 @@
1
+ export declare const WOMP_PROJECT_DECLARATIONS = "declare const womp: { project: { suggestTitle: ((title: string) => Promise<void>); } };\ndeclare function print(...values: unknown[]): void;\ndeclare function emitImage(ref: { id: string; mediaType: string; name?: string }, options?: { inspect?: boolean }): Promise<void>;\ndeclare function emitFile(ref: { id: string; mediaType: string; name?: string }): Promise<void>;\n";
@@ -0,0 +1,3 @@
1
+ // Generated by scripts/generate-skill-declarations.mjs.
2
+ // prettier-ignore
3
+ export const WOMP_PROJECT_DECLARATIONS = "declare const womp: { project: { suggestTitle: ((title: string) => Promise<void>); } };\ndeclare function print(...values: unknown[]): void;\ndeclare function emitImage(ref: { id: string; mediaType: string; name?: string }, options?: { inspect?: boolean }): Promise<void>;\ndeclare function emitFile(ref: { id: string; mediaType: string; name?: string }): Promise<void>;\n";
@@ -0,0 +1 @@
1
+ export declare const WOMP_WEB_DECLARATIONS = "declare const womp: { web: { fetchImage: ((url: string) => Promise<{ id: string; mediaType: string; name?: string; }>); } };\ndeclare function print(...values: unknown[]): void;\ndeclare function emitImage(ref: { id: string; mediaType: string; name?: string }, options?: { inspect?: boolean }): Promise<void>;\ndeclare function emitFile(ref: { id: string; mediaType: string; name?: string }): Promise<void>;\n";
@@ -0,0 +1,3 @@
1
+ // Generated by scripts/generate-skill-declarations.mjs.
2
+ // prettier-ignore
3
+ export const WOMP_WEB_DECLARATIONS = "declare const womp: { web: { fetchImage: ((url: string) => Promise<{ id: string; mediaType: string; name?: string; }>); } };\ndeclare function print(...values: unknown[]): void;\ndeclare function emitImage(ref: { id: string; mediaType: string; name?: string }, options?: { inspect?: boolean }): Promise<void>;\ndeclare function emitFile(ref: { id: string; mediaType: string; name?: string }): Promise<void>;\n";
package/dist/index.d.ts CHANGED
@@ -3,11 +3,11 @@ export { createSparkTools, type SparkPersistence, type SparkToolCall } from "./a
3
3
  export { convertSparkMessages } from "./model-history.js";
4
4
  export { applyCompaction, latestCompaction, type SparkCompactionLimits } from "./compaction.js";
5
5
  export * from "./context-window.js";
6
- export * from "./capabilities.js";
6
+ export * from "./public-capabilities.js";
7
7
  export { createSdkSceneEditor, createSdkSceneHost, type SdkSceneEditor, type SdkSceneEditorOptions, type SdkSceneEditIdentity, type SdkSceneServices, } from "./sdk-scene-host.js";
8
8
  export type { SceneOperation } from "./scene-operations.js";
9
9
  export type { JavaScriptExecutor, JavaScriptGlobals, JavaScriptUserWait } from "./executor.js";
10
10
  export { DEFAULT_MODEL_ID, getSparkModel, REASONING_EFFORT_LABELS, resolveReasoningEffort, SPARK_MODELS, } from "./models.js";
11
11
  export type { ModelProvider, ReasoningEffort, SparkModel } from "./models.js";
12
- export { SPARK_AGENT_PROMPT, sparkSystemPrompt } from "./prompt.js";
12
+ export { sparkSystemPrompt } from "./prompt.js";
13
13
  export type { ExecutionResult, ExecutionScreenshot, SparkRuntimeEvent, SparkRuntimeEventSink, SparkContextMessage, SparkImage, SparkRunInput, SparkRuntime, } from "./types.js";
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ export { createSparkTools } from "./agent-tools.js";
3
3
  export { convertSparkMessages } from "./model-history.js";
4
4
  export { applyCompaction, latestCompaction } from "./compaction.js";
5
5
  export * from "./context-window.js";
6
- export * from "./capabilities.js";
6
+ export * from "./public-capabilities.js";
7
7
  export { createSdkSceneEditor, createSdkSceneHost, } from "./sdk-scene-host.js";
8
8
  export { DEFAULT_MODEL_ID, getSparkModel, REASONING_EFFORT_LABELS, resolveReasoningEffort, SPARK_MODELS, } from "./models.js";
9
- export { SPARK_AGENT_PROMPT, sparkSystemPrompt } from "./prompt.js";
9
+ export { sparkSystemPrompt } from "./prompt.js";
@@ -23,6 +23,39 @@ async function liveInput(tools, part) {
23
23
  const validated = await asSchema(tool.inputSchema).validate?.(input);
24
24
  return validated?.success ? { ...part, input: validated.value } : part;
25
25
  }
26
+ /** The most result pages a stored web search is replayed with. */
27
+ const REPLAYED_SEARCH_RESULTS = 10;
28
+ /**
29
+ * A stored provider web search (../native-tools.ts), as the text an earlier
30
+ * turn's search is replayed as: what was searched and the pages it found.
31
+ * Provider-run tool parts are replayed to their own provider only, so the
32
+ * conversation still reads the same after a change of model, and the pages'
33
+ * contents (Anthropic's encrypted results) are not sent again every turn.
34
+ */
35
+ function webSearchText(part) {
36
+ if (part.type !== "tool-web_search")
37
+ return part;
38
+ const action = record(record(part.output).action);
39
+ const query = [part.input?.query, action.query, ...(Array.isArray(action.queries) ? action.queries : [])].find((value) => typeof value === "string" && value.trim() !== "");
40
+ // Anthropic answers with its results, OpenAI with the sources it read.
41
+ const found = Array.isArray(part.output) ? part.output : record(part.output).sources;
42
+ const pages = (Array.isArray(found) ? found : [])
43
+ .map((item) => {
44
+ const { url, title } = record(item);
45
+ if (typeof url !== "string")
46
+ return undefined;
47
+ return typeof title === "string" && title.trim() !== "" ? `${title} (${url})` : url;
48
+ })
49
+ .filter((page) => page !== undefined)
50
+ .slice(0, REPLAYED_SEARCH_RESULTS);
51
+ const searched = query === undefined ? "Searched the web" : `Searched the web for ${JSON.stringify(query)}`;
52
+ const outcome = part.state === "output-error"
53
+ ? `; the search failed: ${part.errorText}`
54
+ : pages.length > 0
55
+ ? `; found: ${pages.join("; ")}`
56
+ : "";
57
+ return { type: "text", text: `[${searched}${outcome}]` };
58
+ }
26
59
  /**
27
60
  * The stored conversation as model messages. UI artifact previews already
28
61
  * represented by a tool result are not model output. The messages before the
@@ -54,7 +87,7 @@ export async function convertSparkMessages(messages, tools, options = {}) {
54
87
  ...message,
55
88
  parts: await Promise.all(message.parts
56
89
  .filter((part) => part.type !== "file" || (!previews.has(part.url) && part.providerMetadata?.spark?.inspect !== false))
57
- .map((part) => liveInput(tools, part))),
90
+ .map((part) => liveInput(tools, webSearchText(part)))),
58
91
  };
59
92
  }));
60
93
  return convertToModelMessages(history, {
@@ -0,0 +1,26 @@
1
+ import type { LanguageModel, Tool } from "ai";
2
+ import type { SparkCapabilities } from "./capabilities.js";
3
+ /** Most searches one Anthropic response may run: each is a billed call. */
4
+ export declare const MAX_WEB_SEARCHES_PER_RESPONSE = 5;
5
+ /** Provider tools by the name the model calls them. */
6
+ type NativeTools = Record<string, Tool>;
7
+ /**
8
+ * The provider tools the run's model can run itself, by name. A provider is
9
+ * named by its AI SDK client (`model.provider`): Anthropic's Messages API and
10
+ * OpenAI's Responses API have a web search tool; OpenAI's Chat Completions,
11
+ * Gemini (which cannot pair its search with function tools) and OpenRouter
12
+ * have none here, and a model given as a gateway id is not known.
13
+ */
14
+ export declare function nativeToolsFor(model: LanguageModel): NativeTools;
15
+ /**
16
+ * The run's capabilities as its model can use them, and the provider tools
17
+ * they bring: a skill about a provider tool (`SparkSkill.nativeTool`) is
18
+ * listed, and its tool offered, only when the model can run that tool, so no
19
+ * skill names a tool the model was not given. Skills are still read when
20
+ * asked for, as the host's capabilities state them then.
21
+ */
22
+ export declare function withNativeTools(model: LanguageModel, given: SparkCapabilities): {
23
+ capabilities: SparkCapabilities;
24
+ tools: NativeTools;
25
+ };
26
+ export {};
@@ -0,0 +1,43 @@
1
+ import { anthropic } from "@ai-sdk/anthropic";
2
+ import { openai } from "@ai-sdk/openai";
3
+ /** Most searches one Anthropic response may run: each is a billed call. */
4
+ export const MAX_WEB_SEARCHES_PER_RESPONSE = 5;
5
+ /**
6
+ * The provider tools the run's model can run itself, by name. A provider is
7
+ * named by its AI SDK client (`model.provider`): Anthropic's Messages API and
8
+ * OpenAI's Responses API have a web search tool; OpenAI's Chat Completions,
9
+ * Gemini (which cannot pair its search with function tools) and OpenRouter
10
+ * have none here, and a model given as a gateway id is not known.
11
+ */
12
+ export function nativeToolsFor(model) {
13
+ const provider = typeof model === "string" ? "" : model.provider;
14
+ if (provider.startsWith("anthropic.")) {
15
+ return { web_search: anthropic.tools.webSearch_20250305({ maxUses: MAX_WEB_SEARCHES_PER_RESPONSE }) };
16
+ }
17
+ if (provider === "openai.responses")
18
+ return { web_search: openai.tools.webSearch({}) };
19
+ return {};
20
+ }
21
+ /**
22
+ * The run's capabilities as its model can use them, and the provider tools
23
+ * they bring: a skill about a provider tool (`SparkSkill.nativeTool`) is
24
+ * listed, and its tool offered, only when the model can run that tool, so no
25
+ * skill names a tool the model was not given. Skills are still read when
26
+ * asked for, as the host's capabilities state them then.
27
+ */
28
+ export function withNativeTools(model, given) {
29
+ const available = nativeToolsFor(model);
30
+ const capabilities = {
31
+ get skills() {
32
+ return given.skills.filter(({ nativeTool }) => nativeTool === undefined || available[nativeTool] !== undefined);
33
+ },
34
+ createApi: (context) => given.createApi(context),
35
+ };
36
+ const tools = {};
37
+ for (const { nativeTool } of capabilities.skills) {
38
+ const tool = nativeTool === undefined ? undefined : available[nativeTool];
39
+ if (nativeTool !== undefined && tool !== undefined)
40
+ tools[nativeTool] = tool;
41
+ }
42
+ return { capabilities, tools };
43
+ }
package/dist/prompt.d.ts CHANGED
@@ -6,4 +6,7 @@ export declare const SPARK_AGENT_PROMPT = "You are Spark, Womp's unified assista
6
6
  * conversation that run on one model, or the provider's prompt cache misses; caches
7
7
  * are per model, so naming the model costs no hits. Per-turn state travels in messages.
8
8
  */
9
- export declare function sparkSystemPrompt(skills: readonly Pick<SparkSkill, "name" | "version" | "description">[], instructions?: string, modelId?: string): string;
9
+ export declare function sparkSystemPrompt(skills: readonly Pick<SparkSkill, "name" | "version" | "description">[], options?: {
10
+ modelId?: string;
11
+ unattended?: boolean;
12
+ }): string;
package/dist/prompt.js CHANGED
@@ -128,6 +128,28 @@ scenes and text in every skill.
128
128
  - When the subject is or looks like a child, refuse any sexual or sexualizing request.
129
129
  - Refuse in one short sentence, such as "I can't help with sexual content." Do not explain, discuss
130
130
  consent, lore or biology, or offer an alternative to the sexual request.`;
131
+ /**
132
+ * Added after the agent prompt for a run nobody attends, such as a Flow node's.
133
+ * A question there reports requires_action and the node cancels the run, so this
134
+ * overrides by name each part of the agent prompt that asks, offers, previews or waits.
135
+ */
136
+ const UNATTENDED_PROMPT = `Unattended run
137
+
138
+ This request comes from a Flow node, not a person. Nobody can read a question or answer it, so
139
+ the rules below override everything above that asks, offers, previews or waits:
140
+
141
+ - Never ask the user anything, never offer choices or menus, and never wait for a reply.
142
+ - Where a question would have helped, choose the most sensible default yourself, carry on, and
143
+ state the assumption in one short line of your final answer.
144
+ - Do not stop at a preview. Carry the request all the way through to the result it asks for:
145
+ if the goal asks for a 3D model, make the model, not just an image of it.
146
+ - An attached image is the reference for the goal. Use it as the goal describes; do not ask
147
+ what to make of it.
148
+ - If something the goal needs is not available, do what you can and report the limitation in
149
+ the final answer instead of asking anyone to enable it.
150
+ - Your final message is what the Flow passes on to its next node. Make it the result itself:
151
+ the answer, or a concise description of what you made and where it is, not a question,
152
+ a plan, or a list of options.`;
131
153
  /**
132
154
  * Which chat model runs, among Spark's. Users name these models ("make it using astra");
133
155
  * without them the agent took such a name for a generation model it did not have.
@@ -148,10 +170,11 @@ them is about the chat model, not a creation method: carry out the rest of the r
148
170
  * conversation that run on one model, or the provider's prompt cache misses; caches
149
171
  * are per model, so naming the model costs no hits. Per-turn state travels in messages.
150
172
  */
151
- export function sparkSystemPrompt(skills, instructions = SPARK_AGENT_PROMPT, modelId) {
173
+ export function sparkSystemPrompt(skills, options = {}) {
152
174
  return [
153
- instructions,
154
- chatModelPrompt(modelId),
175
+ SPARK_AGENT_PROMPT,
176
+ ...(options.unattended ? [UNATTENDED_PROMPT] : []),
177
+ chatModelPrompt(options.modelId),
155
178
  "Available skills (read before using their APIs):",
156
179
  ...skills.map(({ name, version, description }) => `- ${name} (${version}): ${description}`),
157
180
  ].join("\n\n");
@@ -0,0 +1,21 @@
1
+ export { createSparkCapabilities, createSceneScriptCapabilities, type SparkHosts, type SparkRunFacts, } from "./spark-capabilities.js";
2
+ export type { ArtifactRef, ExecutionReceipt, SparkArtifactResolver, SparkCapabilities, SparkInvocationContext, SparkSkill, } from "./capabilities.js";
3
+ export type { WompSceneApi, SceneHost, SceneHealthHost, SceneSnapshot, SceneScreenshotOptions, } from "./capabilities/scene.js";
4
+ export type { WompSceneDraft } from "./capabilities/scene-draft.js";
5
+ export type { AssetImportsHost, MeshImportRequest, ImageImportRequest, AssetImportResult, MeshImportRetryRequest, AssetImportWaitOptions, WompAssetImportsApi, } from "./capabilities/asset-imports.js";
6
+ export type { AssetsHost, AssetListOptions, ConversationAsset, AssetPage, WompAssetsApi, } from "./capabilities/assets.js";
7
+ export type { OperationsHost, OperationType, OperationModel, OperationCatalog, OperationRequest, OperationJob, OperationStartResult, OperationGenerationResult, OperationWaitOptions, OperationWaitResult, OperationListOptions, OperationPage, WompOperationsApi, } from "./capabilities/operations.js";
8
+ export type { AccountHost, AccountRead, AccountSection, AccountScope, AccountResult, AccountSnapshot, AccountPage, AccountProfile, AccountTeam, AccountCreditBalance, AccountSubscription, AccountBilling, AccountOrderItem, AccountOrder, AccountProject, AccountNotification, AccountWorkflow, WompAccountApi, } from "./capabilities/account.js";
9
+ export type { KnowledgeAnswer, KnowledgeHost, WompKnowledgeApi } from "./capabilities/knowledge.js";
10
+ export type { PrintEstimate, PrintEstimateRequest, PrintEstimateUnavailableReason, PrintHost, PrintPrice, WompPrintApi, } from "./capabilities/print.js";
11
+ export type { FlowHost, FlowSnapshot, FlowWrite, FlowWriteResult, WompFlowApi } from "./capabilities/flow.js";
12
+ export { FLOW_RUN_WAIT_DEFAULT_SECONDS, FLOW_RUN_WAIT_MAX_SECONDS } from "./capabilities/flow-runs.js";
13
+ export type { FlowRunCancelled, FlowRunCopyDeleted, FlowRunDescription, FlowRunInput, FlowRunLive, FlowRunOutputNode, FlowRunFailedNode, FlowRunStarted, FlowRunStatus, FlowRunsHost, WompFlowRunsApi, } from "./capabilities/flow-runs.js";
14
+ export type { GeometryHost, GeometryTarget, GeometryInstance, GeometryParamValue, GeometryWrite, GeometryWriteResult, WompGeometryApi, } from "./capabilities/geometry.js";
15
+ export type { WompOpenScadApi, OpenScadHost, OpenScadTarget, OpenScadSource, OpenScadCreate, OpenScadUpdate, OpenScadValidation, OpenScadPrintability, OpenScadWriteResult, } from "./capabilities/openscad.js";
16
+ export type * from "./materials/types.js";
17
+ export type { MaterialInspectionOptions, MaterialInspectionResult, MaterialInspectionHost, MaterialStatus, MaterialsHost, WompMaterialsApi, } from "./capabilities/materials.js";
18
+ export type { TextureImportRequest, TextureImportResult, TextureImportsHost, WompTextureImportsApi, } from "./capabilities/texture-imports.js";
19
+ export { createTextureImportsHost, type TextureImportHostOptions } from "./texture-import-host.js";
20
+ export type { WebHost, WompWebApi } from "./capabilities/web.js";
21
+ export type { ProjectHost, ProjectTool, WompProjectApi } from "./capabilities/project.js";
@@ -0,0 +1,6 @@
1
+ // The capability surface hosts see. Spark defines every skill and decides which
2
+ // a run offers (`createSparkCapabilities`); hosts implement the service
3
+ // interfaces below and never compose skills of their own.
4
+ export { createSparkCapabilities, createSceneScriptCapabilities, } from "./spark-capabilities.js";
5
+ export { FLOW_RUN_WAIT_DEFAULT_SECONDS, FLOW_RUN_WAIT_MAX_SECONDS } from "./capabilities/flow-runs.js";
6
+ export { createTextureImportsHost } from "./texture-import-host.js";
@@ -11,7 +11,7 @@ export type SparkRunExecutorOptions = {
11
11
  /** When a run's conversation is compacted; see `SparkAgentOptions.compaction`. */
12
12
  compaction?: SparkAgentOptions["compaction"];
13
13
  resolveModel(settings: SparkRunSettings): ResolvedSparkModel | Promise<ResolvedSparkModel>;
14
- createHost(context: SparkRunExecutionContext): Promise<Pick<SparkAgentOptions, "capabilities" | "executor" | "artifacts" | "persistence"> & {
14
+ createHost(context: SparkRunExecutionContext): Promise<Pick<SparkAgentOptions, "capabilities" | "executor" | "artifacts" | "persistence" | "unattended"> & {
15
15
  dispose(): void;
16
16
  }>;
17
17
  };
@@ -0,0 +1,87 @@
1
+ import { type SparkCapabilities } from "./capabilities.js";
2
+ import type { AccountHost } from "./capabilities/account.js";
3
+ import type { AssetImportsHost } from "./capabilities/asset-imports.js";
4
+ import { type AssetsHost } from "./capabilities/assets.js";
5
+ import { type FlowHost } from "./capabilities/flow.js";
6
+ import { type FlowRunsHost } from "./capabilities/flow-runs.js";
7
+ import { type GeometryHost } from "./capabilities/geometry.js";
8
+ import { type KnowledgeHost } from "./capabilities/knowledge.js";
9
+ import { type MaterialsHost } from "./capabilities/materials.js";
10
+ import { type OpenScadHost } from "./capabilities/openscad.js";
11
+ import { type OperationsHost } from "./capabilities/operations.js";
12
+ import { type PrintHost } from "./capabilities/print.js";
13
+ import { type ProjectHost } from "./capabilities/project.js";
14
+ import { type SceneHost } from "./capabilities/scene.js";
15
+ import type { TextureImportsHost } from "./capabilities/texture-imports.js";
16
+ import { type WebHost } from "./capabilities/web.js";
17
+ /**
18
+ * What the run's user and conversation allow. Each capability is offered only
19
+ * when its fact is true; absent is false.
20
+ */
21
+ export type SparkRunFacts = {
22
+ /** Scene editing is on: `scene-editing` writes and `womp.materials`. */
23
+ scene?: boolean;
24
+ /** A scene can be read (scene editing, Geometry Nodes or parametric parts is on): `womp.scene` and print estimates. */
25
+ health?: boolean;
26
+ /** Geometry Nodes is on. */
27
+ geometry?: boolean;
28
+ /** Parametric parts (OpenSCAD) is on. */
29
+ openScad?: boolean;
30
+ /** Flow editing is on. Calls fail while no Flow canvas is open; the skill is offered either way. */
31
+ flow?: boolean;
32
+ /** The agent may start runs of the conversation's flow. */
33
+ flowRuns?: boolean;
34
+ /** Image and 3D generation. */
35
+ operations?: boolean;
36
+ /** Womp help documentation. */
37
+ knowledge?: boolean;
38
+ /** The user's account, credits, orders and projects. */
39
+ account?: boolean;
40
+ /** Web images, and web search where the run's model can search (./native-tools.ts). */
41
+ web?: boolean;
42
+ /**
43
+ * False while the conversation has no project. With `hosts.project`, every
44
+ * project tool asks for one first, and `project-choice` is offered.
45
+ */
46
+ projectBound?: boolean;
47
+ };
48
+ /**
49
+ * The host services behind each capability. A host is required for every
50
+ * capability its fact enables; `assets` is offered whenever its host is given.
51
+ */
52
+ export type SparkHosts = {
53
+ assets?: AssetsHost;
54
+ /** The `asset-import` half of `womp.assets`. */
55
+ imports?: AssetImportsHost;
56
+ /** The texture half of `womp.assets`. */
57
+ textureImports?: TextureImportsHost;
58
+ operations?: OperationsHost;
59
+ account?: AccountHost;
60
+ flow?: FlowHost;
61
+ /** The Flow node catalog the host's editor accepts, appended to `flow-graphs`. */
62
+ flowNodeCatalog?: string;
63
+ flowRuns?: FlowRunsHost;
64
+ geometry?: GeometryHost;
65
+ /** Its `health` is how the model reads scene health (`womp.scene.health`). */
66
+ scene?: SceneHost;
67
+ materials?: MaterialsHost;
68
+ openscad?: OpenScadHost;
69
+ print?: PrintHost;
70
+ knowledge?: KnowledgeHost;
71
+ web?: WebHost;
72
+ /** The conversation's project gate. Absent, project tools run ungated. */
73
+ project?: ProjectHost;
74
+ };
75
+ /**
76
+ * Spark's capability set for one run: which skills it offers, in which order,
77
+ * and how each behaves, from the run's facts. Hosts supply only services.
78
+ */
79
+ export declare function createSparkCapabilities({ hosts, facts, }: {
80
+ hosts: SparkHosts;
81
+ facts: SparkRunFacts;
82
+ }): SparkCapabilities;
83
+ /**
84
+ * Scene scripts: JavaScript an outside model wrote against `womp.scene` alone,
85
+ * described by the same `scene-editing` skill a run reads.
86
+ */
87
+ export declare function createSceneScriptCapabilities(scene: SceneHost): SparkCapabilities;
@@ -0,0 +1,67 @@
1
+ import { composeCapabilities } from "./capabilities.js";
2
+ import { createAssetsCapability } from "./capabilities/assets.js";
3
+ import { createAccountCapability } from "./capabilities/account.js";
4
+ import { createFlowCapability } from "./capabilities/flow.js";
5
+ import { createFlowRunsCapability } from "./capabilities/flow-runs.js";
6
+ import { createGeometryCapability } from "./capabilities/geometry.js";
7
+ import { createKnowledgeCapability } from "./capabilities/knowledge.js";
8
+ import { createMaterialsCapability } from "./capabilities/materials.js";
9
+ import { createOpenScadCapability } from "./capabilities/openscad.js";
10
+ import { createOperationsCapability } from "./capabilities/operations.js";
11
+ import { createPrintCapability } from "./capabilities/print.js";
12
+ import { createProjectChoiceCapability, gateAssetImportsHost, gateFlowHost, gateGeometryHost, gateMaterialsHost, gateOpenScadHost, gatePrintHost, gateSceneHost, } from "./capabilities/project.js";
13
+ import { createSceneCapability } from "./capabilities/scene.js";
14
+ import { createWebCapability } from "./capabilities/web.js";
15
+ import { geometryReference } from "./geometry.js";
16
+ function required(host, capability) {
17
+ if (host === undefined)
18
+ throw new Error(`The ${capability} capability is enabled but its host was not given.`);
19
+ return host;
20
+ }
21
+ /**
22
+ * Spark's capability set for one run: which skills it offers, in which order,
23
+ * and how each behaves, from the run's facts. Hosts supply only services.
24
+ */
25
+ export function createSparkCapabilities({ hosts, facts, }) {
26
+ const project = hosts.project;
27
+ const gated = (host, gate) => host === undefined || project === undefined ? host : gate(host, project);
28
+ const scene = gated(hosts.scene, gateSceneHost);
29
+ const imports = gated(hosts.imports, gateAssetImportsHost);
30
+ // The key each capability is composed under is the `womp.*` global its skill
31
+ // names, and the composition order is the skill order in the system prompt.
32
+ const bindings = {
33
+ ...(hosts.assets ? { assets: createAssetsCapability(hosts.assets, imports, hosts.textureImports) } : {}),
34
+ ...(facts.operations ? { operations: createOperationsCapability(required(hosts.operations, "operations")) } : {}),
35
+ ...(facts.account ? { account: createAccountCapability(required(hosts.account, "account")) } : {}),
36
+ ...(facts.flow
37
+ ? {
38
+ flow: createFlowCapability(gated(required(hosts.flow, "flow"), gateFlowHost), required(hosts.flowNodeCatalog, "flow")),
39
+ }
40
+ : {}),
41
+ ...(facts.flowRuns ? { flowRuns: createFlowRunsCapability(required(hosts.flowRuns, "flowRuns")) } : {}),
42
+ ...(facts.geometry
43
+ ? { geometry: createGeometryCapability(gated(required(hosts.geometry, "geometry"), gateGeometryHost), geometryReference()) }
44
+ : {}),
45
+ ...(facts.health ? { scene: createSceneCapability(required(scene, "scene")) } : {}),
46
+ ...(facts.scene
47
+ ? {
48
+ materials: createMaterialsCapability(gated(required(hosts.materials, "materials"), gateMaterialsHost), required(scene, "materials")),
49
+ }
50
+ : {}),
51
+ ...(facts.openScad
52
+ ? { openscad: createOpenScadCapability(gated(required(hosts.openscad, "openscad"), gateOpenScadHost)) }
53
+ : {}),
54
+ ...(facts.health ? { printing: createPrintCapability(gated(required(hosts.print, "printing"), gatePrintHost)) } : {}),
55
+ ...(facts.knowledge ? { knowledge: createKnowledgeCapability(required(hosts.knowledge, "knowledge")) } : {}),
56
+ ...(facts.web ? { web: createWebCapability(required(hosts.web, "web")) } : {}),
57
+ ...(project !== undefined && facts.projectBound === false ? { project: createProjectChoiceCapability(project) } : {}),
58
+ };
59
+ return composeCapabilities(bindings);
60
+ }
61
+ /**
62
+ * Scene scripts: JavaScript an outside model wrote against `womp.scene` alone,
63
+ * described by the same `scene-editing` skill a run reads.
64
+ */
65
+ export function createSceneScriptCapabilities(scene) {
66
+ return composeCapabilities({ scene: createSceneCapability(scene) });
67
+ }
package/dist/ui.d.ts CHANGED
@@ -172,6 +172,16 @@ export type SparkUITools = {
172
172
  input: SparkGoalRequest;
173
173
  output: SparkGoalResult;
174
174
  };
175
+ /**
176
+ * The model provider's own search (../native-tools.ts), which the provider
177
+ * runs: its input and results are in the provider's shape.
178
+ */
179
+ web_search: {
180
+ input: {
181
+ query?: string;
182
+ };
183
+ output: unknown;
184
+ };
175
185
  };
176
186
  export type SkillReadResult = ({
177
187
  ok: true;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@womp/spark-agent",
3
- "version": "15.7.0",
3
+ "version": "17.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",
@@ -18,9 +18,9 @@
18
18
  "default": "./dist/browser.js"
19
19
  },
20
20
  "./capabilities": {
21
- "types": "./dist/capabilities.d.ts",
22
- "import": "./dist/capabilities.js",
23
- "default": "./dist/capabilities.js"
21
+ "types": "./dist/public-capabilities.d.ts",
22
+ "import": "./dist/public-capabilities.js",
23
+ "default": "./dist/public-capabilities.js"
24
24
  },
25
25
  "./kakapo": {
26
26
  "types": "./dist/kakapo.d.ts",