@womp/spark-agent 17.2.0 → 17.3.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,16 @@ 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.3.0 — 2026-11-09
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- `createStandaloneSparkAgentApp({ webImages: true })` offers web search and `womp.web.fetchImage`
|
|
12
|
+
in the standalone server, so local runs and benches can use web references as Crow chat runs do.
|
|
13
|
+
Images are fetched only from public hosts (every redirect is checked, private, loopback and
|
|
14
|
+
link-local addresses are refused), as JPEG, PNG, WebP or GIF up to 20 MB. Standalone has no image
|
|
15
|
+
encoder, so a photo longer than 2048 px on a side is refused with a hint to fetch a thumbnail.
|
|
16
|
+
|
|
7
17
|
## 17.2.0 — 2026-11-04
|
|
8
18
|
|
|
9
19
|
### Changed
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { WebHost } from "../capabilities/web.js";
|
|
2
|
+
import type { SparkArtifactStore } from "./artifacts.js";
|
|
3
|
+
/**
|
|
4
|
+
* Standalone's womp.web.fetchImage: downloads a public image into the run's
|
|
5
|
+
* artifacts. Every hop must resolve to a public address, so a URL planted in a
|
|
6
|
+
* searched page cannot reach Kakapo, this server or the local network.
|
|
7
|
+
*/
|
|
8
|
+
export declare function createStandaloneWebHost(artifacts: SparkArtifactStore, ownerId: string): WebHost;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import { promises as dns } from "node:dns";
|
|
2
|
+
import net from "node:net";
|
|
3
|
+
const MAX_BYTES = 20 * 1024 * 1024;
|
|
4
|
+
const MAX_REDIRECTS = 3;
|
|
5
|
+
const TIMEOUT_MS = 20_000;
|
|
6
|
+
/** Standalone has no image encoder to shrink large photos, as production's host does, so it refuses them. */
|
|
7
|
+
const MAX_EDGE = 2048;
|
|
8
|
+
const IMAGE_TYPES = new Set(["image/jpeg", "image/png", "image/webp", "image/gif"]);
|
|
9
|
+
/** Private, loopback, link-local and reserved IPv4/IPv6 ranges a fetched URL must not reach. */
|
|
10
|
+
function isPrivateAddress(address) {
|
|
11
|
+
const mapped = address.toLowerCase().match(/^::ffff:(\d+\.\d+\.\d+\.\d+)$/u);
|
|
12
|
+
if (mapped)
|
|
13
|
+
return isPrivateAddress(mapped[1]);
|
|
14
|
+
if (net.isIPv4(address)) {
|
|
15
|
+
const [a, b] = address.split(".").map(Number);
|
|
16
|
+
return a === 0 || a === 10 || a === 127 || a >= 224 || (a === 100 && b >= 64 && b < 128)
|
|
17
|
+
|| (a === 169 && b === 254) || (a === 172 && b >= 16 && b < 32) || (a === 192 && b === 168)
|
|
18
|
+
|| (a === 198 && (b === 18 || b === 19));
|
|
19
|
+
}
|
|
20
|
+
const v6 = address.toLowerCase();
|
|
21
|
+
return v6 === "::" || v6 === "::1" || v6.startsWith("fc") || v6.startsWith("fd") || v6.startsWith("fe8")
|
|
22
|
+
|| v6.startsWith("fe9") || v6.startsWith("fea") || v6.startsWith("feb") || v6.startsWith("ff");
|
|
23
|
+
}
|
|
24
|
+
async function assertPublicUrl(url) {
|
|
25
|
+
if (url.protocol !== "http:" && url.protocol !== "https:")
|
|
26
|
+
throw new Error("Only http(s) image URLs can be fetched.");
|
|
27
|
+
const host = url.hostname.replace(/^\[|\]$/gu, "");
|
|
28
|
+
const addresses = net.isIP(host) ? [host] : (await dns.lookup(host, { all: true })).map(({ address }) => address);
|
|
29
|
+
if (addresses.length === 0 || addresses.some(isPrivateAddress))
|
|
30
|
+
throw new Error("That image URL is not on a public host.");
|
|
31
|
+
}
|
|
32
|
+
/** Width and height from a PNG, JPEG, GIF or WebP header; 0 when unknown. */
|
|
33
|
+
function imageSize(data) {
|
|
34
|
+
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
|
35
|
+
if (data.length > 24 && view.getUint32(0) === 0x89504e47)
|
|
36
|
+
return { width: view.getUint32(16), height: view.getUint32(20) };
|
|
37
|
+
if (data.length > 10 && data[0] === 0x47 && data[1] === 0x49)
|
|
38
|
+
return { width: view.getUint16(6, true), height: view.getUint16(8, true) };
|
|
39
|
+
if (data.length > 30 && view.getUint32(0) === 0x52494646 && view.getUint32(8) === 0x57454250) {
|
|
40
|
+
const chunk = String.fromCharCode(...data.slice(12, 16));
|
|
41
|
+
if (chunk === "VP8X")
|
|
42
|
+
return { width: 1 + (data[24] | (data[25] << 8) | (data[26] << 16)), height: 1 + (data[27] | (data[28] << 8) | (data[29] << 16)) };
|
|
43
|
+
if (chunk === "VP8 ")
|
|
44
|
+
return { width: view.getUint16(26, true) & 0x3fff, height: view.getUint16(28, true) & 0x3fff };
|
|
45
|
+
if (chunk === "VP8L") {
|
|
46
|
+
const bits = view.getUint32(21, true);
|
|
47
|
+
return { width: (bits & 0x3fff) + 1, height: ((bits >> 14) & 0x3fff) + 1 };
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (data[0] === 0xff && data[1] === 0xd8) {
|
|
51
|
+
for (let i = 2; i + 9 < data.length;) {
|
|
52
|
+
if (data[i] !== 0xff) {
|
|
53
|
+
i++;
|
|
54
|
+
continue;
|
|
55
|
+
}
|
|
56
|
+
const marker = data[i + 1];
|
|
57
|
+
if (marker >= 0xc0 && marker <= 0xcf && marker !== 0xc4 && marker !== 0xc8 && marker !== 0xcc)
|
|
58
|
+
return { width: view.getUint16(i + 7), height: view.getUint16(i + 5) };
|
|
59
|
+
i += 2 + view.getUint16(i + 2);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return { width: 0, height: 0 };
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Standalone's womp.web.fetchImage: downloads a public image into the run's
|
|
66
|
+
* artifacts. Every hop must resolve to a public address, so a URL planted in a
|
|
67
|
+
* searched page cannot reach Kakapo, this server or the local network.
|
|
68
|
+
*/
|
|
69
|
+
export function createStandaloneWebHost(artifacts, ownerId) {
|
|
70
|
+
return {
|
|
71
|
+
async fetchImage(rawUrl, context) {
|
|
72
|
+
let url = new URL(rawUrl);
|
|
73
|
+
let response;
|
|
74
|
+
for (let hop = 0; hop <= MAX_REDIRECTS; hop++) {
|
|
75
|
+
await assertPublicUrl(url);
|
|
76
|
+
response = await fetch(url, { redirect: "manual", signal: AbortSignal.any([context.signal, AbortSignal.timeout(TIMEOUT_MS)]),
|
|
77
|
+
headers: { "user-agent": "SparkStandalone/1.0", accept: "image/*" } });
|
|
78
|
+
const location = response.headers.get("location");
|
|
79
|
+
if (response.status < 300 || response.status >= 400 || !location)
|
|
80
|
+
break;
|
|
81
|
+
url = new URL(location, url);
|
|
82
|
+
response = undefined;
|
|
83
|
+
}
|
|
84
|
+
if (!response)
|
|
85
|
+
throw new Error("Too many redirects.");
|
|
86
|
+
if (!response.ok)
|
|
87
|
+
throw new Error(`The image URL returned HTTP ${response.status}.`);
|
|
88
|
+
const mediaType = (response.headers.get("content-type") ?? "").split(";")[0].trim().toLowerCase();
|
|
89
|
+
if (!IMAGE_TYPES.has(mediaType))
|
|
90
|
+
throw new Error(`Not an image (${mediaType || "unknown type"}); pass a direct image URL, not a page.`);
|
|
91
|
+
const chunks = [];
|
|
92
|
+
let size = 0;
|
|
93
|
+
for await (const chunk of response.body) {
|
|
94
|
+
size += chunk.length;
|
|
95
|
+
if (size > MAX_BYTES)
|
|
96
|
+
throw new Error("The image is larger than 20 MB.");
|
|
97
|
+
chunks.push(chunk);
|
|
98
|
+
}
|
|
99
|
+
const data = new Uint8Array(size);
|
|
100
|
+
let offset = 0;
|
|
101
|
+
for (const chunk of chunks) {
|
|
102
|
+
data.set(chunk, offset);
|
|
103
|
+
offset += chunk.length;
|
|
104
|
+
}
|
|
105
|
+
// The artifact store keeps the real media type; ExecutionScreenshot names only JPEG.
|
|
106
|
+
const size2d = imageSize(data);
|
|
107
|
+
if (Math.max(size2d.width, size2d.height) > MAX_EDGE)
|
|
108
|
+
throw new Error(`The image is ${size2d.width}x${size2d.height}; fetch a version at most ${MAX_EDGE} px on its longest side, such as a thumbnail URL (Wikimedia: /thumb/<path>/1280px-<file>).`);
|
|
109
|
+
const image = { data, mediaType, ...size2d };
|
|
110
|
+
return artifacts.write(ownerId, image);
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
@@ -13,6 +13,8 @@ export type StandaloneSparkAgentOptions = {
|
|
|
13
13
|
/** Stable host-verified identity for the scene behind kakapoUrl. */
|
|
14
14
|
sceneIdentity?: string;
|
|
15
15
|
logger?: Pick<Console, "info" | "warn">;
|
|
16
|
+
/** Offer web search and womp.web.fetchImage, with images fetched from public hosts only. */
|
|
17
|
+
webImages?: boolean;
|
|
16
18
|
/** Observe successful renderer captures, including captures not attached to a reply. */
|
|
17
19
|
onScreenshot?: (runId: string) => void;
|
|
18
20
|
};
|
|
@@ -16,6 +16,8 @@ import { createSdkSceneHealthHost } from "../sdk-scene-health-host.js";
|
|
|
16
16
|
import { geometryReference } from "../geometry.js";
|
|
17
17
|
import { hasSceneResourcePressure, } from "../scene-health.js";
|
|
18
18
|
import { QuickJSJavaScriptExecutor } from "../quickjs-executor.js";
|
|
19
|
+
import { createWebCapability } from "../capabilities/web.js";
|
|
20
|
+
import { createStandaloneWebHost } from "./standalone-web.js";
|
|
19
21
|
import { sparkModelOptions } from "../model-options.js";
|
|
20
22
|
import { createSparkRunExecutor } from "./executor.js";
|
|
21
23
|
import { createSparkGoalEvaluator } from "./goal-evaluator.js";
|
|
@@ -154,6 +156,9 @@ export async function createStandaloneSparkAgentApp(options) {
|
|
|
154
156
|
...(options.developmentProfile === "demo-account"
|
|
155
157
|
? { account: createAccountCapability(createDemoAccountHost()) }
|
|
156
158
|
: {}),
|
|
159
|
+
...(options.webImages
|
|
160
|
+
? { web: createWebCapability(createStandaloneWebHost(artifactStore, context.ownerId)) }
|
|
161
|
+
: {}),
|
|
157
162
|
};
|
|
158
163
|
const capabilities = composeCapabilities(capabilityBindings);
|
|
159
164
|
const catalog = `${Object.keys(capabilityBindings).join(",")}\n${capabilities.skills.map(({ name }) => name).join(",")}`;
|