@womp/spark-agent 16.0.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 +23 -0
- package/dist/agent.js +16 -7
- package/dist/capabilities/web.d.ts +1 -11
- package/dist/capabilities/web.js +21 -7
- package/dist/capabilities.d.ts +8 -0
- package/dist/generated/web-declarations.d.ts +1 -1
- package/dist/generated/web-declarations.js +1 -1
- package/dist/model-history.js +34 -1
- package/dist/native-tools.d.ts +26 -0
- package/dist/native-tools.js +43 -0
- package/dist/public-capabilities.d.ts +1 -1
- package/dist/spark-capabilities.d.ts +1 -1
- package/dist/ui.d.ts +10 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,29 @@ 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
|
+
|
|
7
30
|
## 16.0.0 — 2026-11-02
|
|
8
31
|
|
|
9
32
|
Spark now owns every capability: its skills, prompt rules, which capabilities a run offers and how
|
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
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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 =
|
|
160
|
+
const skills = capabilities.skills;
|
|
152
161
|
let compactions = 0;
|
|
153
162
|
const summaryOptions = {
|
|
154
163
|
model: options.model,
|
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
import type { ArtifactRef, SparkCapability, SparkInvocationContext } from "../capabilities.js";
|
|
2
|
-
export type WebSearchResult = {
|
|
3
|
-
answer: string;
|
|
4
|
-
sources: {
|
|
5
|
-
title: string;
|
|
6
|
-
url: string;
|
|
7
|
-
}[];
|
|
8
|
-
};
|
|
9
2
|
export type WompWebApi = {
|
|
10
|
-
/** Searches the web and answers from what it found, with the pages it used. */
|
|
11
|
-
search(query: string): Promise<WebSearchResult>;
|
|
12
3
|
/** Downloads an image from a public http(s) URL into this conversation; emitImage(ref) shows it to you. */
|
|
13
4
|
fetchImage(url: string): Promise<ArtifactRef>;
|
|
14
5
|
};
|
|
15
|
-
/** The host
|
|
6
|
+
/** The host stores fetched images as conversation artifacts. */
|
|
16
7
|
export interface WebHost {
|
|
17
|
-
search(query: string, context: SparkInvocationContext): Promise<WebSearchResult>;
|
|
18
8
|
fetchImage(url: string, context: SparkInvocationContext): Promise<ArtifactRef>;
|
|
19
9
|
}
|
|
20
10
|
export declare function createWebCapability(host: WebHost): SparkCapability<WompWebApi>;
|
package/dist/capabilities/web.js
CHANGED
|
@@ -1,24 +1,38 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
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
|
+
};
|
|
3
19
|
export function createWebCapability(host) {
|
|
4
20
|
return {
|
|
5
21
|
skills: [
|
|
6
22
|
{
|
|
7
23
|
name: "web",
|
|
8
|
-
version: "
|
|
9
|
-
description: "
|
|
10
|
-
instructions: `Use womp.web.
|
|
11
|
-
|
|
12
|
-
Only public http(s) URLs work. Prefer one well-aimed search over many; every search is a billed model call.`,
|
|
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.`,
|
|
13
28
|
declarations: WOMP_WEB_DECLARATIONS,
|
|
14
29
|
examples: [
|
|
15
|
-
'const found = await womp.web.search("What does 1 Main St, Springfield, IL look like? Describe the building.");\nprint(found.answer, found.sources);',
|
|
16
30
|
'const photo = await womp.web.fetchImage("https://example.com/photo.jpg");\nawait emitImage(photo);',
|
|
17
31
|
],
|
|
18
32
|
},
|
|
33
|
+
WEB_SEARCH_SKILL,
|
|
19
34
|
],
|
|
20
35
|
createApi: (context) => ({
|
|
21
|
-
search: (query) => host.search(z.string().trim().min(1, "A search query is required.").parse(query), context),
|
|
22
36
|
fetchImage: (url) => host.fetchImage(z.string().trim().min(1, "An image URL is required.").parse(url), context),
|
|
23
37
|
}),
|
|
24
38
|
};
|
package/dist/capabilities.d.ts
CHANGED
|
@@ -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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const WOMP_WEB_DECLARATIONS = "declare const womp: { web: {
|
|
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";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
// Generated by scripts/generate-skill-declarations.mjs.
|
|
2
2
|
// prettier-ignore
|
|
3
|
-
export const WOMP_WEB_DECLARATIONS = "declare const womp: { web: {
|
|
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/model-history.js
CHANGED
|
@@ -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
|
+
}
|
|
@@ -17,5 +17,5 @@ export type * from "./materials/types.js";
|
|
|
17
17
|
export type { MaterialInspectionOptions, MaterialInspectionResult, MaterialInspectionHost, MaterialStatus, MaterialsHost, WompMaterialsApi, } from "./capabilities/materials.js";
|
|
18
18
|
export type { TextureImportRequest, TextureImportResult, TextureImportsHost, WompTextureImportsApi, } from "./capabilities/texture-imports.js";
|
|
19
19
|
export { createTextureImportsHost, type TextureImportHostOptions } from "./texture-import-host.js";
|
|
20
|
-
export type { WebHost,
|
|
20
|
+
export type { WebHost, WompWebApi } from "./capabilities/web.js";
|
|
21
21
|
export type { ProjectHost, ProjectTool, WompProjectApi } from "./capabilities/project.js";
|
|
@@ -37,7 +37,7 @@ export type SparkRunFacts = {
|
|
|
37
37
|
knowledge?: boolean;
|
|
38
38
|
/** The user's account, credits, orders and projects. */
|
|
39
39
|
account?: boolean;
|
|
40
|
-
/** Web
|
|
40
|
+
/** Web images, and web search where the run's model can search (./native-tools.ts). */
|
|
41
41
|
web?: boolean;
|
|
42
42
|
/**
|
|
43
43
|
* False while the conversation has no project. With `hosts.project`, every
|
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;
|