@womp/spark-agent 0.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.
- package/README.md +87 -0
- package/dist/agent.d.ts +11 -0
- package/dist/agent.js +168 -0
- package/dist/coordinates.d.ts +22 -0
- package/dist/coordinates.js +123 -0
- package/dist/executor.d.ts +4 -0
- package/dist/executor.js +1 -0
- package/dist/index.d.ts +9 -0
- package/dist/index.js +5 -0
- package/dist/models.d.ts +44 -0
- package/dist/models.js +61 -0
- package/dist/prompt.d.ts +1 -0
- package/dist/prompt.js +209 -0
- package/dist/runtime.d.ts +29 -0
- package/dist/runtime.js +215 -0
- package/dist/types.d.ts +101 -0
- package/dist/types.js +1 -0
- package/dist/womp-scene-api.d.ts +54 -0
- package/dist/womp-scene-api.js +815 -0
- package/package.json +63 -0
package/README.md
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# @womp/spark-agent
|
|
2
|
+
|
|
3
|
+
Local browser workspace for controlling Kakapo with model-authored JavaScript.
|
|
4
|
+
|
|
5
|
+
The agent runs in the tab, calls OpenAI through the AI SDK, and connects directly to Kakapo through
|
|
6
|
+
`@womp/kakapo-sdk`. Scene access is restricted to a private build root. Top-level `createNode()` calls are
|
|
7
|
+
automatically parented to that root, and the native screenshot tool frames the build for visual
|
|
8
|
+
inspection.
|
|
9
|
+
|
|
10
|
+
## Run
|
|
11
|
+
|
|
12
|
+
Install the reusable core from npm:
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
yarn add @womp/spark-agent @womp/kakapo-sdk
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The package entrypoint exports only the environment-neutral agent core. It does not import React,
|
|
19
|
+
Vite, browser storage, or the browser JavaScript executor.
|
|
20
|
+
|
|
21
|
+
## Browser test application
|
|
22
|
+
|
|
23
|
+
Requirements:
|
|
24
|
+
|
|
25
|
+
- Node.js 20 or newer
|
|
26
|
+
- `D:/Womp/kakapo/kakapo_app.exe` listening on `ws://127.0.0.1:5502`
|
|
27
|
+
- `VITE_OPENAI_API_KEY` or `VITE_ANTHROPIC_API_KEY` in the repository root `.env`, or a key entered in Runtime settings
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
yarn install
|
|
31
|
+
yarn dev
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Open `http://127.0.0.1:5173`.
|
|
35
|
+
|
|
36
|
+
## Browser workspace
|
|
37
|
+
|
|
38
|
+
The workspace provides:
|
|
39
|
+
|
|
40
|
+
- local threads with search, fork, and delete actions;
|
|
41
|
+
- model and reasoning controls;
|
|
42
|
+
- pasted and uploaded reference images;
|
|
43
|
+
- streamed assistant messages and reasoning summaries;
|
|
44
|
+
- formatted JavaScript execution and result traces;
|
|
45
|
+
- native Kakapo screenshots inline with the execution timeline.
|
|
46
|
+
|
|
47
|
+
Threads and images are stored in IndexedDB. Model and runtime preferences use browser storage. An API
|
|
48
|
+
key entered in Runtime settings is kept in session storage and is not stored with threads.
|
|
49
|
+
|
|
50
|
+
## Core package
|
|
51
|
+
|
|
52
|
+
The environment-neutral agent is under `src/`. It accepts a language model, a scene runtime, a
|
|
53
|
+
JavaScript executor, byte-based images, and an event sink. The browser supplies those dependencies in
|
|
54
|
+
`web/src/api.ts`; a server can supply its own credentials, isolated executor, and durable event sink
|
|
55
|
+
without importing React or browser storage.
|
|
56
|
+
|
|
57
|
+
## Agent execution
|
|
58
|
+
|
|
59
|
+
The model has two tools:
|
|
60
|
+
|
|
61
|
+
- `executeJavaScript` runs code against the scoped `@womp/kakapo-sdk` facade;
|
|
62
|
+
- `screenshot` moves Kakapo's native camera, frames a target bounding box, and returns the rendered
|
|
63
|
+
image to the model.
|
|
64
|
+
|
|
65
|
+
Node, material, transform, inspection, and refresh operations are SDK calls made from JavaScript.
|
|
66
|
+
The private build root is runtime state and is not exposed as a generated-code variable.
|
|
67
|
+
|
|
68
|
+
## Validation
|
|
69
|
+
|
|
70
|
+
```bash
|
|
71
|
+
yarn build
|
|
72
|
+
yarn typecheck
|
|
73
|
+
yarn lint
|
|
74
|
+
yarn test
|
|
75
|
+
yarn web:build
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Layout
|
|
79
|
+
|
|
80
|
+
- `src/agent.ts` — environment-neutral model loop and tool orchestration
|
|
81
|
+
- `src/runtime.ts` — Kakapo scene runtime and atomic JavaScript transactions
|
|
82
|
+
- `src/womp-scene-api.ts` — Womp-compatible scene API
|
|
83
|
+
- `src/prompt.ts` — JavaScript agent instructions and SDK reference
|
|
84
|
+
- `src/coordinates.ts` — Womp basis, units, rotations, and goop conversion
|
|
85
|
+
- `web/src/api.ts` — browser model, image, runtime, and event adapters
|
|
86
|
+
- `web/src/browser-executor.ts` — local generated-JavaScript executor
|
|
87
|
+
- `web/src/App.tsx` — local chat, persistence, traces, screenshots, and streaming UI
|
package/dist/agent.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type LanguageModel } from "ai";
|
|
2
|
+
import { type ModelProvider } from "./models.js";
|
|
3
|
+
import type { SparkRunInput, SparkRuntime } from "./types.js";
|
|
4
|
+
export type SparkAgentOptions = {
|
|
5
|
+
input: SparkRunInput;
|
|
6
|
+
model: LanguageModel;
|
|
7
|
+
modelId: string;
|
|
8
|
+
provider: ModelProvider;
|
|
9
|
+
runtime: SparkRuntime;
|
|
10
|
+
};
|
|
11
|
+
export declare function runSparkAgent(options: SparkAgentOptions): Promise<void>;
|
package/dist/agent.js
ADDED
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { stepCountIs, streamText, tool } from "ai";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { resolveReasoningEffort } from "./models.js";
|
|
4
|
+
import { SPARK_AGENT_PROMPT } from "./prompt.js";
|
|
5
|
+
export async function runSparkAgent(options) {
|
|
6
|
+
const { input, model, modelId, provider, runtime } = options;
|
|
7
|
+
const onEvent = (event) => runtime.emit(event);
|
|
8
|
+
try {
|
|
9
|
+
await runtime.connect();
|
|
10
|
+
const reasoningEffort = resolveReasoningEffort(modelId, input.reasoningEffort);
|
|
11
|
+
const content = [{
|
|
12
|
+
type: "text",
|
|
13
|
+
text: [
|
|
14
|
+
...input.context.slice(-8).map(({ role, content: text }) => `${role === "user" ? "Previous user" : "Previous Spark"}: ${text.slice(0, 2_000)}`),
|
|
15
|
+
`Current request: ${input.prompt}`,
|
|
16
|
+
].join("\n"),
|
|
17
|
+
}];
|
|
18
|
+
for (const image of input.images) {
|
|
19
|
+
content.push({
|
|
20
|
+
type: "file",
|
|
21
|
+
data: { type: "data", data: image.data },
|
|
22
|
+
mediaType: image.mediaType,
|
|
23
|
+
filename: image.name,
|
|
24
|
+
...(provider === "openai"
|
|
25
|
+
? { providerOptions: { openai: { imageDetail: "high" } } }
|
|
26
|
+
: {}),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
const pendingScreenshots = [];
|
|
30
|
+
const runAbort = new AbortController();
|
|
31
|
+
const stopOnDisconnect = (value, message) => {
|
|
32
|
+
if (runtime.connected)
|
|
33
|
+
return value;
|
|
34
|
+
const error = new Error(message);
|
|
35
|
+
runAbort.abort(error);
|
|
36
|
+
throw error;
|
|
37
|
+
};
|
|
38
|
+
const executeJavaScript = tool({
|
|
39
|
+
description: "Execute one atomic JavaScript transaction against Spark's Womp-style scene API. Scene functions and enums are globals; there is no kakapo object.",
|
|
40
|
+
inputSchema: z.object({
|
|
41
|
+
purpose: z.string().min(1).max(240),
|
|
42
|
+
code: z.string().min(1).max(60_000),
|
|
43
|
+
}),
|
|
44
|
+
execute: async ({ code, purpose }) => {
|
|
45
|
+
const output = await runtime.execute(code, purpose);
|
|
46
|
+
return stopOnDisconnect(output, output.error ?? "Kakapo disconnected while committing the scene transaction.");
|
|
47
|
+
},
|
|
48
|
+
toModelOutput: ({ output }) => ({
|
|
49
|
+
type: "content",
|
|
50
|
+
value: [{
|
|
51
|
+
type: "text",
|
|
52
|
+
text: JSON.stringify({
|
|
53
|
+
ok: output.ok,
|
|
54
|
+
purpose: output.purpose,
|
|
55
|
+
value: output.value,
|
|
56
|
+
logs: output.logs,
|
|
57
|
+
sdkCalls: output.sdkCalls,
|
|
58
|
+
error: output.error,
|
|
59
|
+
rolledBack: output.rolledBack,
|
|
60
|
+
}),
|
|
61
|
+
}],
|
|
62
|
+
}),
|
|
63
|
+
});
|
|
64
|
+
const screenshot = tool({
|
|
65
|
+
description: "Capture Kakapo's native renderer. Omit targetId to frame the whole visible scene; child targets are framed through their owning top-level Area. Inspect the image before finishing.",
|
|
66
|
+
inputSchema: z.object({
|
|
67
|
+
targetId: z.number().int().optional(),
|
|
68
|
+
view: z.enum(["front", "back", "left", "right", "top", "bottom", "isometric"]).default("isometric"),
|
|
69
|
+
}),
|
|
70
|
+
execute: async ({ targetId, view }, { toolCallId }) => {
|
|
71
|
+
const image = await runtime.screenshot({ targetId, view });
|
|
72
|
+
pendingScreenshots.push({ callId: toolCallId, screenshot: image });
|
|
73
|
+
return stopOnDisconnect(image, "Kakapo disconnected while capturing the screenshot.");
|
|
74
|
+
},
|
|
75
|
+
toModelOutput: ({ output }) => ({
|
|
76
|
+
type: "content",
|
|
77
|
+
value: [
|
|
78
|
+
{
|
|
79
|
+
type: "text",
|
|
80
|
+
text: JSON.stringify({
|
|
81
|
+
view: output.view,
|
|
82
|
+
targetId: output.targetId,
|
|
83
|
+
width: output.width,
|
|
84
|
+
height: output.height,
|
|
85
|
+
}),
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
type: "file",
|
|
89
|
+
data: { type: "data", data: output.data },
|
|
90
|
+
mediaType: output.mediaType,
|
|
91
|
+
filename: `spark-${output.view}.jpg`,
|
|
92
|
+
...(provider === "openai"
|
|
93
|
+
? { providerOptions: { openai: { imageDetail: "high" } } }
|
|
94
|
+
: {}),
|
|
95
|
+
},
|
|
96
|
+
],
|
|
97
|
+
}),
|
|
98
|
+
});
|
|
99
|
+
const result = streamText({
|
|
100
|
+
model,
|
|
101
|
+
system: SPARK_AGENT_PROMPT,
|
|
102
|
+
messages: [{ role: "user", content }],
|
|
103
|
+
tools: { executeJavaScript, screenshot },
|
|
104
|
+
toolChoice: "auto",
|
|
105
|
+
abortSignal: runAbort.signal,
|
|
106
|
+
stopWhen: stepCountIs(256),
|
|
107
|
+
maxOutputTokens: 48_000,
|
|
108
|
+
onChunk: ({ chunk }) => {
|
|
109
|
+
if (chunk.type === "text-delta")
|
|
110
|
+
onEvent({ type: "text-delta", text: chunk.text });
|
|
111
|
+
},
|
|
112
|
+
onStepEnd: (step) => {
|
|
113
|
+
onEvent({
|
|
114
|
+
type: "step",
|
|
115
|
+
step: step.stepNumber,
|
|
116
|
+
toolNames: step.toolCalls.map(({ toolName }) => toolName),
|
|
117
|
+
reasoningSummary: step.reasoningText,
|
|
118
|
+
responseTimeMs: step.performance.responseTimeMs,
|
|
119
|
+
});
|
|
120
|
+
for (const pending of pendingScreenshots.splice(0)) {
|
|
121
|
+
onEvent({
|
|
122
|
+
type: "tool-call",
|
|
123
|
+
callId: pending.callId,
|
|
124
|
+
toolName: "screenshot",
|
|
125
|
+
label: "Capture native screenshot",
|
|
126
|
+
input: { targetId: pending.screenshot.targetId, view: pending.screenshot.view },
|
|
127
|
+
});
|
|
128
|
+
onEvent({
|
|
129
|
+
type: "screenshot",
|
|
130
|
+
callId: pending.callId,
|
|
131
|
+
data: pending.screenshot.data,
|
|
132
|
+
mediaType: pending.screenshot.mediaType,
|
|
133
|
+
view: pending.screenshot.view,
|
|
134
|
+
targetId: pending.screenshot.targetId,
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
},
|
|
138
|
+
providerOptions: provider === "anthropic"
|
|
139
|
+
? {
|
|
140
|
+
anthropic: {
|
|
141
|
+
effort: reasoningEffort,
|
|
142
|
+
thinking: { type: "adaptive", display: "summarized" },
|
|
143
|
+
disableParallelToolUse: true,
|
|
144
|
+
},
|
|
145
|
+
}
|
|
146
|
+
: {
|
|
147
|
+
openai: {
|
|
148
|
+
reasoningEffort,
|
|
149
|
+
reasoningSummary: "auto",
|
|
150
|
+
parallelToolCalls: false,
|
|
151
|
+
store: false,
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
});
|
|
155
|
+
const [text, steps, usage] = await Promise.all([
|
|
156
|
+
result.text,
|
|
157
|
+
result.steps,
|
|
158
|
+
result.totalUsage,
|
|
159
|
+
]);
|
|
160
|
+
onEvent({ type: "result", text, steps: steps.length, usage });
|
|
161
|
+
}
|
|
162
|
+
catch (error) {
|
|
163
|
+
onEvent({ type: "error", message: error instanceof Error ? error.message : String(error) });
|
|
164
|
+
}
|
|
165
|
+
finally {
|
|
166
|
+
runtime.disconnect();
|
|
167
|
+
}
|
|
168
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Transform, Vec3 } from "@womp/kakapo-sdk";
|
|
2
|
+
export declare const INTERNAL_UNITS_PER_MM: number;
|
|
3
|
+
export declare const WOMP_BLEND_MULTIPLIER = 55;
|
|
4
|
+
export declare const MAX_ENGINE_BLEND = 500;
|
|
5
|
+
export declare const MAX_GOOP_MM: number;
|
|
6
|
+
export declare const MAX_MIRROR_GOOP_MM = 1000;
|
|
7
|
+
export declare function toEnginePosition(value: Vec3): Vec3;
|
|
8
|
+
export declare function fromEnginePosition(value: Vec3): Vec3;
|
|
9
|
+
export declare function toEngineDimensions(value: Vec3): Vec3;
|
|
10
|
+
export declare function fromEngineDimensions(value: Vec3): Vec3;
|
|
11
|
+
export declare function convertRotationBasis(value: Vec3): Vec3;
|
|
12
|
+
export declare function toEngineTransform(input: {
|
|
13
|
+
position?: Vec3;
|
|
14
|
+
rotation?: Vec3;
|
|
15
|
+
dimensions?: Vec3;
|
|
16
|
+
}): Partial<Transform>;
|
|
17
|
+
export declare function toEngineBlend(goopMm: number): number;
|
|
18
|
+
export declare function fromEngineBlend(blend: number): number;
|
|
19
|
+
export declare function toEngineMirrorGoop(goopMm: number): number;
|
|
20
|
+
export type MirrorAxis = "x" | "y" | "z";
|
|
21
|
+
export declare function toEngineMirrorRotation(axis: MirrorAxis): Vec3;
|
|
22
|
+
export declare function fromEngineMirrorRotation(rotation: Vec3): MirrorAxis | undefined;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
export const INTERNAL_UNITS_PER_MM = 1 / 25;
|
|
2
|
+
export const WOMP_BLEND_MULTIPLIER = 55;
|
|
3
|
+
export const MAX_ENGINE_BLEND = 500;
|
|
4
|
+
export const MAX_GOOP_MM = MAX_ENGINE_BLEND / WOMP_BLEND_MULTIPLIER;
|
|
5
|
+
export const MAX_MIRROR_GOOP_MM = 1000;
|
|
6
|
+
const BASIS = [
|
|
7
|
+
[0, 0, -1],
|
|
8
|
+
[0, 1, 0],
|
|
9
|
+
[-1, 0, 0],
|
|
10
|
+
];
|
|
11
|
+
function clean(value) {
|
|
12
|
+
const rounded = Math.round(value * 1e9) / 1e9;
|
|
13
|
+
return Math.abs(rounded) < 1e-10 ? 0 : rounded;
|
|
14
|
+
}
|
|
15
|
+
export function toEnginePosition(value) {
|
|
16
|
+
return {
|
|
17
|
+
x: clean(-value.z * INTERNAL_UNITS_PER_MM),
|
|
18
|
+
y: clean(value.y * INTERNAL_UNITS_PER_MM),
|
|
19
|
+
z: clean(-value.x * INTERNAL_UNITS_PER_MM),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export function fromEnginePosition(value) {
|
|
23
|
+
return {
|
|
24
|
+
x: clean(-value.z / INTERNAL_UNITS_PER_MM),
|
|
25
|
+
y: clean(value.y / INTERNAL_UNITS_PER_MM),
|
|
26
|
+
z: clean(-value.x / INTERNAL_UNITS_PER_MM),
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
export function toEngineDimensions(value) {
|
|
30
|
+
return {
|
|
31
|
+
x: value.z * INTERNAL_UNITS_PER_MM,
|
|
32
|
+
y: value.y * INTERNAL_UNITS_PER_MM,
|
|
33
|
+
z: value.x * INTERNAL_UNITS_PER_MM,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
export function fromEngineDimensions(value) {
|
|
37
|
+
return {
|
|
38
|
+
x: value.z / INTERNAL_UNITS_PER_MM,
|
|
39
|
+
y: value.y / INTERNAL_UNITS_PER_MM,
|
|
40
|
+
z: value.x / INTERNAL_UNITS_PER_MM,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export function convertRotationBasis(value) {
|
|
44
|
+
// Womp and Kakapo compose and extract Euler angles in XZY order.
|
|
45
|
+
const x = value.x * Math.PI / 180;
|
|
46
|
+
const y = value.y * Math.PI / 180;
|
|
47
|
+
const z = value.z * Math.PI / 180;
|
|
48
|
+
const a = Math.cos(x);
|
|
49
|
+
const b = Math.sin(x);
|
|
50
|
+
const c = Math.cos(y);
|
|
51
|
+
const d = Math.sin(y);
|
|
52
|
+
const e = Math.cos(z);
|
|
53
|
+
const f = Math.sin(z);
|
|
54
|
+
const source = [
|
|
55
|
+
[c * e, -f, d * e],
|
|
56
|
+
[a * c * f + b * d, a * e, a * d * f - b * c],
|
|
57
|
+
[b * c * f - a * d, b * e, b * d * f + a * c],
|
|
58
|
+
];
|
|
59
|
+
const multiply = (left, right) => {
|
|
60
|
+
const cell = (row, column) => left[row][0] * right[0][column] +
|
|
61
|
+
left[row][1] * right[1][column] +
|
|
62
|
+
left[row][2] * right[2][column];
|
|
63
|
+
return [
|
|
64
|
+
[cell(0, 0), cell(0, 1), cell(0, 2)],
|
|
65
|
+
[cell(1, 0), cell(1, 1), cell(1, 2)],
|
|
66
|
+
[cell(2, 0), cell(2, 1), cell(2, 2)],
|
|
67
|
+
];
|
|
68
|
+
};
|
|
69
|
+
const converted = multiply(multiply(BASIS, source), BASIS);
|
|
70
|
+
const convertedZ = Math.asin(Math.min(1, Math.max(-1, -converted[0][1])));
|
|
71
|
+
const nearGimbalLock = Math.abs(converted[0][1]) >= 0.9999999;
|
|
72
|
+
const convertedX = nearGimbalLock
|
|
73
|
+
? Math.atan2(-converted[1][2], converted[2][2])
|
|
74
|
+
: Math.atan2(converted[2][1], converted[1][1]);
|
|
75
|
+
const convertedY = nearGimbalLock
|
|
76
|
+
? 0
|
|
77
|
+
: Math.atan2(converted[0][2], converted[0][0]);
|
|
78
|
+
return {
|
|
79
|
+
x: clean(convertedX * 180 / Math.PI),
|
|
80
|
+
y: clean(convertedY * 180 / Math.PI),
|
|
81
|
+
z: clean(convertedZ * 180 / Math.PI),
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
export function toEngineTransform(input) {
|
|
85
|
+
return {
|
|
86
|
+
...(input.position ? { position: toEnginePosition(input.position) } : {}),
|
|
87
|
+
...(input.rotation ? { rotation: convertRotationBasis(input.rotation) } : {}),
|
|
88
|
+
...(input.dimensions ? { scale: toEngineDimensions(input.dimensions) } : {}),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
export function toEngineBlend(goopMm) {
|
|
92
|
+
return Math.min(MAX_ENGINE_BLEND, Math.max(0, goopMm * WOMP_BLEND_MULTIPLIER));
|
|
93
|
+
}
|
|
94
|
+
export function fromEngineBlend(blend) {
|
|
95
|
+
return blend / WOMP_BLEND_MULTIPLIER;
|
|
96
|
+
}
|
|
97
|
+
export function toEngineMirrorGoop(goopMm) {
|
|
98
|
+
return Math.min(MAX_MIRROR_GOOP_MM, Math.max(0, goopMm)) * WOMP_BLEND_MULTIPLIER;
|
|
99
|
+
}
|
|
100
|
+
export function toEngineMirrorRotation(axis) {
|
|
101
|
+
if (axis === "x")
|
|
102
|
+
return { x: 0, y: 90, z: 0 };
|
|
103
|
+
if (axis === "y")
|
|
104
|
+
return { x: 0, y: 0, z: 90 };
|
|
105
|
+
return { x: 0, y: 180, z: 0 };
|
|
106
|
+
}
|
|
107
|
+
export function fromEngineMirrorRotation(rotation) {
|
|
108
|
+
const x = rotation.x * Math.PI / 180;
|
|
109
|
+
const y = rotation.y * Math.PI / 180;
|
|
110
|
+
const z = rotation.z * Math.PI / 180;
|
|
111
|
+
const engineNormal = {
|
|
112
|
+
x: Math.cos(y) * Math.cos(z),
|
|
113
|
+
y: Math.cos(x) * Math.sin(z) + Math.sin(x) * Math.cos(z) * Math.sin(y),
|
|
114
|
+
z: Math.sin(x) * Math.sin(z) - Math.cos(x) * Math.cos(z) * Math.sin(y),
|
|
115
|
+
};
|
|
116
|
+
const publicNormal = {
|
|
117
|
+
x: -engineNormal.z,
|
|
118
|
+
y: engineNormal.y,
|
|
119
|
+
z: -engineNormal.x,
|
|
120
|
+
};
|
|
121
|
+
return Object.keys(publicNormal)
|
|
122
|
+
.find((axis) => Math.abs(publicNormal[axis]) > 1 - 1e-6);
|
|
123
|
+
}
|
package/dist/executor.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { runSparkAgent, type SparkAgentOptions } from "./agent.js";
|
|
2
|
+
export type { JavaScriptExecutor, JavaScriptGlobals } from "./executor.js";
|
|
3
|
+
export { DEFAULT_MODEL_ID, getSparkModel, REASONING_EFFORT_LABELS, resolveReasoningEffort, SPARK_MODELS, } from "./models.js";
|
|
4
|
+
export type { ModelProvider, ReasoningEffort, SparkModel } from "./models.js";
|
|
5
|
+
export { SPARK_AGENT_PROMPT } from "./prompt.js";
|
|
6
|
+
export { KakapoRuntime } from "./runtime.js";
|
|
7
|
+
export type { ExecutionResult, ExecutionScreenshot, RunEvent, RunEventSink, SparkContextMessage, SparkImage, SparkRunInput, SparkRuntime, } from "./types.js";
|
|
8
|
+
export { NodeType, OperationType, PrimitiveTypeValue, createWompSceneApi, } from "./womp-scene-api.js";
|
|
9
|
+
export type { WompSceneApi, WompSceneApiContext } from "./womp-scene-api.js";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { runSparkAgent } from "./agent.js";
|
|
2
|
+
export { DEFAULT_MODEL_ID, getSparkModel, REASONING_EFFORT_LABELS, resolveReasoningEffort, SPARK_MODELS, } from "./models.js";
|
|
3
|
+
export { SPARK_AGENT_PROMPT } from "./prompt.js";
|
|
4
|
+
export { KakapoRuntime } from "./runtime.js";
|
|
5
|
+
export { NodeType, OperationType, PrimitiveTypeValue, createWompSceneApi, } from "./womp-scene-api.js";
|
package/dist/models.d.ts
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
export type ModelProvider = "openai" | "anthropic";
|
|
2
|
+
export type ReasoningEffort = "low" | "medium" | "high" | "xhigh" | "max";
|
|
3
|
+
export declare const REASONING_EFFORT_LABELS: Record<ReasoningEffort, string>;
|
|
4
|
+
export type SparkModel = {
|
|
5
|
+
id: string;
|
|
6
|
+
label: string;
|
|
7
|
+
note: string;
|
|
8
|
+
provider: ModelProvider;
|
|
9
|
+
reasoningEfforts: readonly ReasoningEffort[];
|
|
10
|
+
};
|
|
11
|
+
export declare const SPARK_MODELS: readonly [{
|
|
12
|
+
readonly id: "gpt-5.6-sol";
|
|
13
|
+
readonly label: "GPT-5.6 Sol";
|
|
14
|
+
readonly note: "Best OpenAI quality";
|
|
15
|
+
readonly provider: "openai";
|
|
16
|
+
readonly reasoningEfforts: readonly ["low", "medium", "high", "xhigh", "max"];
|
|
17
|
+
}, {
|
|
18
|
+
readonly id: "gpt-5.6-terra";
|
|
19
|
+
readonly label: "GPT-5.6 Terra";
|
|
20
|
+
readonly note: "Balanced OpenAI model";
|
|
21
|
+
readonly provider: "openai";
|
|
22
|
+
readonly reasoningEfforts: readonly ["low", "medium", "high", "xhigh", "max"];
|
|
23
|
+
}, {
|
|
24
|
+
readonly id: "gpt-5.6-luna";
|
|
25
|
+
readonly label: "GPT-5.6 Luna";
|
|
26
|
+
readonly note: "Fast OpenAI model";
|
|
27
|
+
readonly provider: "openai";
|
|
28
|
+
readonly reasoningEfforts: readonly ["low", "medium", "high", "xhigh", "max"];
|
|
29
|
+
}, {
|
|
30
|
+
readonly id: "claude-opus-5";
|
|
31
|
+
readonly label: "Opus 5";
|
|
32
|
+
readonly note: "Best Anthropic quality";
|
|
33
|
+
readonly provider: "anthropic";
|
|
34
|
+
readonly reasoningEfforts: readonly ["low", "medium", "high", "xhigh", "max"];
|
|
35
|
+
}, {
|
|
36
|
+
readonly id: "claude-fable-5";
|
|
37
|
+
readonly label: "Fable 5";
|
|
38
|
+
readonly note: "Fast Anthropic model";
|
|
39
|
+
readonly provider: "anthropic";
|
|
40
|
+
readonly reasoningEfforts: readonly ["low", "medium", "high", "xhigh", "max"];
|
|
41
|
+
}];
|
|
42
|
+
export declare const DEFAULT_MODEL_ID: "gpt-5.6-sol";
|
|
43
|
+
export declare function getSparkModel(id: string): SparkModel;
|
|
44
|
+
export declare function resolveReasoningEffort(modelId: string, effort: string): ReasoningEffort;
|
package/dist/models.js
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
export const REASONING_EFFORT_LABELS = {
|
|
2
|
+
low: "Low",
|
|
3
|
+
medium: "Medium",
|
|
4
|
+
high: "High",
|
|
5
|
+
xhigh: "XHigh",
|
|
6
|
+
max: "Max",
|
|
7
|
+
};
|
|
8
|
+
const EXTENDED_REASONING_EFFORTS = [
|
|
9
|
+
"low",
|
|
10
|
+
"medium",
|
|
11
|
+
"high",
|
|
12
|
+
"xhigh",
|
|
13
|
+
"max",
|
|
14
|
+
];
|
|
15
|
+
export const SPARK_MODELS = [
|
|
16
|
+
{
|
|
17
|
+
id: "gpt-5.6-sol",
|
|
18
|
+
label: "GPT-5.6 Sol",
|
|
19
|
+
note: "Best OpenAI quality",
|
|
20
|
+
provider: "openai",
|
|
21
|
+
reasoningEfforts: EXTENDED_REASONING_EFFORTS,
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
id: "gpt-5.6-terra",
|
|
25
|
+
label: "GPT-5.6 Terra",
|
|
26
|
+
note: "Balanced OpenAI model",
|
|
27
|
+
provider: "openai",
|
|
28
|
+
reasoningEfforts: EXTENDED_REASONING_EFFORTS,
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
id: "gpt-5.6-luna",
|
|
32
|
+
label: "GPT-5.6 Luna",
|
|
33
|
+
note: "Fast OpenAI model",
|
|
34
|
+
provider: "openai",
|
|
35
|
+
reasoningEfforts: EXTENDED_REASONING_EFFORTS,
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
id: "claude-opus-5",
|
|
39
|
+
label: "Opus 5",
|
|
40
|
+
note: "Best Anthropic quality",
|
|
41
|
+
provider: "anthropic",
|
|
42
|
+
reasoningEfforts: EXTENDED_REASONING_EFFORTS,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
id: "claude-fable-5",
|
|
46
|
+
label: "Fable 5",
|
|
47
|
+
note: "Fast Anthropic model",
|
|
48
|
+
provider: "anthropic",
|
|
49
|
+
reasoningEfforts: EXTENDED_REASONING_EFFORTS,
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
export const DEFAULT_MODEL_ID = SPARK_MODELS[0].id;
|
|
53
|
+
export function getSparkModel(id) {
|
|
54
|
+
return SPARK_MODELS.find((model) => model.id === id) ?? SPARK_MODELS[0];
|
|
55
|
+
}
|
|
56
|
+
export function resolveReasoningEffort(modelId, effort) {
|
|
57
|
+
const supportedEfforts = getSparkModel(modelId).reasoningEfforts;
|
|
58
|
+
return supportedEfforts.includes(effort)
|
|
59
|
+
? effort
|
|
60
|
+
: "medium";
|
|
61
|
+
}
|
package/dist/prompt.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SPARK_AGENT_PROMPT: string;
|