@womp/spark-agent 1.0.1 → 2.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/README.md +37 -19
- package/dist/capabilities/scene-draft.d.ts +2 -404
- package/dist/capabilities/scene.d.ts +1 -1
- package/dist/capabilities/scene.js +13 -4
- package/dist/cli.js +19 -2
- package/dist/client.js +15 -15
- package/dist/coordinates.d.ts +23 -0
- package/dist/coordinates.js +132 -0
- package/dist/generated/scene-declarations.d.ts +1 -1
- package/dist/generated/scene-declarations.js +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/kakapo.d.ts +4 -5
- package/dist/kakapo.js +2 -6
- package/dist/pricing.js +9 -29
- package/dist/runtime.d.ts +16 -36
- package/dist/runtime.js +132 -139
- package/dist/scene-environment.d.ts +25 -0
- package/dist/scene-environment.js +76 -0
- package/dist/scene-metadata.d.ts +6 -0
- package/dist/scene-metadata.js +65 -0
- package/dist/scene-operations.d.ts +47 -0
- package/dist/scene-operations.js +126 -0
- package/dist/sdk-scene-host.d.ts +309 -0
- package/dist/sdk-scene-host.js +201 -0
- package/dist/sdk-scene-screenshot.d.ts +7 -0
- package/dist/sdk-scene-screenshot.js +17 -0
- package/dist/server/demo-scene-materials.d.ts +3 -0
- package/dist/server/demo-scene-materials.js +18 -0
- package/dist/server/express.js +2 -4
- package/dist/server/fixtures/materials/matte-blue.json +14 -0
- package/dist/server/fixtures/materials/polished-copper.json +14 -0
- package/dist/server/index.d.ts +2 -1
- package/dist/server/index.js +2 -1
- package/dist/server/service.d.ts +4 -0
- package/dist/server/service.js +26 -2
- package/dist/server/sqlite-store.d.ts +29 -0
- package/dist/server/sqlite-store.js +200 -0
- package/dist/server/standalone.d.ts +5 -1
- package/dist/server/standalone.js +78 -21
- package/dist/server/store.js +3 -1
- package/dist/types.d.ts +1 -1
- package/dist/womp-scene-api.d.ts +283 -0
- package/dist/womp-scene-api.js +974 -0
- package/package.json +7 -9
- package/dist/kakapo-capability.d.ts +0 -45
- package/dist/kakapo-capability.js +0 -169
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import type { FontFamily, KakapoAPI, SceneEdit, MaterialResource } from "@womp/kakapo-sdk";
|
|
2
|
+
import type { ArtifactRef, SparkInvocationContext } from "./capabilities.js";
|
|
3
|
+
import type { SceneHost, SceneScreenshotOptions } from "./capabilities/scene.js";
|
|
4
|
+
import { type SceneOperation, type SceneOperationStore } from "./scene-operations.js";
|
|
5
|
+
import type { SceneHdr } from "./scene-environment.js";
|
|
6
|
+
export type SdkSceneServices = {
|
|
7
|
+
fonts: FontFamily[];
|
|
8
|
+
hdrs?: readonly SceneHdr[];
|
|
9
|
+
superMaterialNames?: readonly string[];
|
|
10
|
+
loadSuperMaterial?(name: string): Promise<{
|
|
11
|
+
resource: MaterialResource;
|
|
12
|
+
name: string;
|
|
13
|
+
tier: number;
|
|
14
|
+
libraryId: number;
|
|
15
|
+
}>;
|
|
16
|
+
enableCurveV3?: boolean;
|
|
17
|
+
};
|
|
18
|
+
export type SdkSceneEditorOptions = {
|
|
19
|
+
targetKey: string;
|
|
20
|
+
projectId?: number;
|
|
21
|
+
operations: SceneOperationStore;
|
|
22
|
+
saveToRenderer?: boolean;
|
|
23
|
+
withConnection<T>(context: SparkInvocationContext, action: (api: KakapoAPI, beginSettlement: () => void,
|
|
24
|
+
/** Supply this when the host adds a stricter connection lifetime. */
|
|
25
|
+
context?: SparkInvocationContext) => Promise<T>): Promise<T>;
|
|
26
|
+
assertEditable(context: SparkInvocationContext): void | Promise<void>;
|
|
27
|
+
/** Acquire host coordination only after the draft is durably prepared. */
|
|
28
|
+
prepareCommit?(operation: SceneOperation, context: SparkInvocationContext): Promise<() => void | Promise<void>>;
|
|
29
|
+
/** Must adopt each operation ID at most once, including during recovery. */
|
|
30
|
+
onCommitted?(operation: SceneOperation, api: KakapoAPI, context: SparkInvocationContext, identity: SdkSceneEditIdentity): Promise<Record<string, unknown> | void>;
|
|
31
|
+
};
|
|
32
|
+
export type SdkSceneEditIdentity = {
|
|
33
|
+
capability: string;
|
|
34
|
+
operation: string;
|
|
35
|
+
target?: Record<string, unknown> | (() => Record<string, unknown>);
|
|
36
|
+
};
|
|
37
|
+
export type SdkSceneEditor = {
|
|
38
|
+
read<T>(context: SparkInvocationContext, action: (api: KakapoAPI) => T | Promise<T>): Promise<T>;
|
|
39
|
+
edit<T>(identity: SdkSceneEditIdentity, callback: (api: KakapoAPI, draft: SceneEdit) => T | Promise<T>, expectedRevision: string, context: SparkInvocationContext, afterCommitted?: (operation: SceneOperation, api: KakapoAPI) => Promise<Record<string, unknown> | void>): Promise<{
|
|
40
|
+
value: T;
|
|
41
|
+
operation: SceneOperation;
|
|
42
|
+
}>;
|
|
43
|
+
};
|
|
44
|
+
export declare function createSdkSceneDraft(api: KakapoAPI, scene: SceneEdit, services: SdkSceneServices): {
|
|
45
|
+
listSuperMaterials: () => string[];
|
|
46
|
+
_getParentId: (childId: number) => number;
|
|
47
|
+
_getScaleProductUpTo: (nodeId: number, includeNodeSelfUnion?: boolean) => number;
|
|
48
|
+
NodeType: {
|
|
49
|
+
readonly Primitive: 0;
|
|
50
|
+
readonly Union: 1;
|
|
51
|
+
readonly Light: 2;
|
|
52
|
+
readonly Curve: 3;
|
|
53
|
+
readonly Group: 4;
|
|
54
|
+
readonly Text: 5;
|
|
55
|
+
readonly Field: 6;
|
|
56
|
+
readonly SVG: 7;
|
|
57
|
+
readonly Mesh: 8;
|
|
58
|
+
readonly Decal: 9;
|
|
59
|
+
readonly OpenSCAD: 10;
|
|
60
|
+
readonly Socket: 11;
|
|
61
|
+
} & Record<number, string>;
|
|
62
|
+
PrimitiveType: {
|
|
63
|
+
readonly Sphere: 0;
|
|
64
|
+
readonly Cylinder: 1;
|
|
65
|
+
readonly Cube: 2;
|
|
66
|
+
readonly Cone: 3;
|
|
67
|
+
readonly Torus: 4;
|
|
68
|
+
readonly Pyramid: 9;
|
|
69
|
+
} & Record<number, string>;
|
|
70
|
+
OperationType: {
|
|
71
|
+
readonly Subtract: 0;
|
|
72
|
+
readonly Union: 1;
|
|
73
|
+
readonly Stain: 2;
|
|
74
|
+
readonly Intersect: 3;
|
|
75
|
+
} & Record<number, string>;
|
|
76
|
+
LightType: {
|
|
77
|
+
readonly Rect: 0;
|
|
78
|
+
readonly Sphere: 1;
|
|
79
|
+
readonly Distant: 2;
|
|
80
|
+
} & Record<number, string>;
|
|
81
|
+
nodeCreate: (type: number, parentId?: number) => number;
|
|
82
|
+
nodeDelete: (id: number) => void;
|
|
83
|
+
nodeClone: (id: number) => number;
|
|
84
|
+
nodeList: () => number[];
|
|
85
|
+
nodeChildren: (parentId: number) => number[];
|
|
86
|
+
nodeSetParent: (id: number, parentId: number, index?: number) => void;
|
|
87
|
+
nodeGetType: (id: number) => number;
|
|
88
|
+
nodeGetName: (id: number) => string;
|
|
89
|
+
nodeSetName: (id: number, name: string) => void;
|
|
90
|
+
nodeGetParentId: (id: number) => number;
|
|
91
|
+
nodeGetPos: (id: number) => import("@womp/kakapo-sdk").Vec3;
|
|
92
|
+
nodeGetLock: (id: number) => boolean;
|
|
93
|
+
nodeSetLock: (id: number, locked: boolean) => void;
|
|
94
|
+
nodeSetPos: (id: number, position: import("@womp/kakapo-sdk").Vec3) => void;
|
|
95
|
+
nodeGetRot: (id: number) => import("@womp/kakapo-sdk").Vec3;
|
|
96
|
+
nodeSetRot: (id: number, rotation: import("@womp/kakapo-sdk").Vec3) => void;
|
|
97
|
+
nodeGetSize: (id: number) => import("@womp/kakapo-sdk").Vec2 | import("@womp/kakapo-sdk").Vec3;
|
|
98
|
+
nodeSetSize: (id: number, sizeValue: import("@womp/kakapo-sdk").Vec2 | import("@womp/kakapo-sdk").Vec3) => void;
|
|
99
|
+
nodeGetHide: (id: number) => boolean;
|
|
100
|
+
nodeSetHide: (id: number, hidden: boolean) => void;
|
|
101
|
+
nodeGetOp: (id: number) => number;
|
|
102
|
+
nodeSetOp: (id: number, operation: number) => void;
|
|
103
|
+
nodeGetBlend: (id: number) => number;
|
|
104
|
+
nodeSetBlend: (id: number, blend: number) => void;
|
|
105
|
+
nodeGetRound: (id: number) => number;
|
|
106
|
+
nodeSetRound: (id: number, round: number) => void;
|
|
107
|
+
nodeGetColor: (id: number) => {
|
|
108
|
+
r: number;
|
|
109
|
+
g: number;
|
|
110
|
+
b: number;
|
|
111
|
+
};
|
|
112
|
+
nodeSetColor: (id: number, color: {
|
|
113
|
+
r: number;
|
|
114
|
+
g: number;
|
|
115
|
+
b: number;
|
|
116
|
+
} | import("@womp/kakapo-sdk").Vec3) => void;
|
|
117
|
+
nodeGetMaterialId: (id: number) => number | null;
|
|
118
|
+
nodeSetMaterialId: (id: number, materialId: number) => void;
|
|
119
|
+
nodeGetResolution: (id: number) => number;
|
|
120
|
+
nodeSetResolution: (id: number, resolution: number) => void;
|
|
121
|
+
nodeGetLightType: (id: number) => number;
|
|
122
|
+
nodeSetLightType: (id: number, lightType: number) => void;
|
|
123
|
+
nodeGetPower: (id: number) => number;
|
|
124
|
+
nodeSetPower: (id: number, power: number) => void;
|
|
125
|
+
nodeGetText: (id: number) => string;
|
|
126
|
+
nodeSetText: (id: number, text: string) => void;
|
|
127
|
+
nodeGetFont: (id: number) => string;
|
|
128
|
+
nodeSetFont: (id: number, font: string) => void;
|
|
129
|
+
nodeGetWeight: (id: number) => number;
|
|
130
|
+
nodeSetWeight: (id: number, weight: number) => void;
|
|
131
|
+
nodeGetItalic: (id: number) => boolean;
|
|
132
|
+
nodeSetItalic: (id: number, italic: boolean) => void;
|
|
133
|
+
nodeGetAlign: (id: number) => number;
|
|
134
|
+
nodeSetAlign: (id: number, align: number) => void;
|
|
135
|
+
nodeGetWrap: (id: number) => number;
|
|
136
|
+
nodeSetWrap: (id: number, wrap: number) => void;
|
|
137
|
+
nodeGetWidth: (id: number) => number;
|
|
138
|
+
nodeSetWidth: (id: number, width: number) => void;
|
|
139
|
+
nodeGetSpacing: (id: number) => number;
|
|
140
|
+
nodeSetSpacing: (id: number, spacing: number) => void;
|
|
141
|
+
nodeGetLineHeight: (id: number) => number;
|
|
142
|
+
nodeSetLineHeight: (id: number, lineHeight: number) => void;
|
|
143
|
+
nodeGetDensity: (id: number) => number;
|
|
144
|
+
nodeSetDensity: (id: number, density: number) => void;
|
|
145
|
+
nodeGetRoundness: (id: number) => number;
|
|
146
|
+
nodeSetRoundness: (id: number, roundness: number) => void;
|
|
147
|
+
nodeGetSmoothing: (id: number) => number;
|
|
148
|
+
nodeSetSmoothing: (id: number, smoothing: number) => void;
|
|
149
|
+
nodeGetPrimType: (id: number) => number;
|
|
150
|
+
nodeSetPrimType: (id: number, primitive: number) => void;
|
|
151
|
+
nodeGetMirror: (id: number, slot: number) => {
|
|
152
|
+
axis: import("./coordinates.js").MirrorAxis | "custom" | "disabled";
|
|
153
|
+
planePosition: number;
|
|
154
|
+
goop: number;
|
|
155
|
+
};
|
|
156
|
+
nodeSetMirror: (id: number, slot: number, axis: import("./coordinates.js").MirrorAxis | "disabled", planePosition?: number, goop?: number) => void;
|
|
157
|
+
nodeGetThickness: (id: number) => number;
|
|
158
|
+
nodeSetThickness: (id: number, thickness: number) => void;
|
|
159
|
+
curveGetClosed: (curveId: number) => boolean;
|
|
160
|
+
curveSetClosed: (curveId: number, closed: boolean) => void;
|
|
161
|
+
curvePointGetHandleIn: (curveId: number, pointIndex: number) => import("@womp/kakapo-sdk").Vec3;
|
|
162
|
+
curvePointGetHandleOut: (curveId: number, pointIndex: number) => import("@womp/kakapo-sdk").Vec3;
|
|
163
|
+
curvePointSetHandleIn: (curveId: number, pointIndex: number, value: import("@womp/kakapo-sdk").Vec3) => void;
|
|
164
|
+
curvePointSetHandleOut: (curveId: number, pointIndex: number, value: import("@womp/kakapo-sdk").Vec3) => void;
|
|
165
|
+
curvePointCount: (curveId: number) => number;
|
|
166
|
+
curvePointAdd: (curveId: number, point?: {
|
|
167
|
+
name?: string;
|
|
168
|
+
pos?: import("@womp/kakapo-sdk").Vec3;
|
|
169
|
+
rot?: import("@womp/kakapo-sdk").Vec3;
|
|
170
|
+
size?: import("@womp/kakapo-sdk").Vec3;
|
|
171
|
+
fixed?: boolean;
|
|
172
|
+
round?: number;
|
|
173
|
+
materialId?: number;
|
|
174
|
+
}) => number;
|
|
175
|
+
curvePointInsert: (curveId: number, pointIndex: number, point?: {
|
|
176
|
+
name?: string;
|
|
177
|
+
pos?: import("@womp/kakapo-sdk").Vec3;
|
|
178
|
+
rot?: import("@womp/kakapo-sdk").Vec3;
|
|
179
|
+
size?: import("@womp/kakapo-sdk").Vec3;
|
|
180
|
+
fixed?: boolean;
|
|
181
|
+
round?: number;
|
|
182
|
+
materialId?: number;
|
|
183
|
+
}) => number;
|
|
184
|
+
curvePointRemove: (curveId: number, pointIndex: number) => void;
|
|
185
|
+
curvePointGetName: (curveId: number, pointIndex: number) => string;
|
|
186
|
+
curvePointSetName: (curveId: number, pointIndex: number, name: string) => void;
|
|
187
|
+
curvePointGetPos: (curveId: number, pointIndex: number) => import("@womp/kakapo-sdk").Vec3;
|
|
188
|
+
curvePointSetPos: (curveId: number, pointIndex: number, position: import("@womp/kakapo-sdk").Vec3) => void;
|
|
189
|
+
curvePointGetRot: (curveId: number, pointIndex: number) => import("@womp/kakapo-sdk").Vec3;
|
|
190
|
+
curvePointSetRot: (curveId: number, pointIndex: number, rotation: import("@womp/kakapo-sdk").Vec3) => void;
|
|
191
|
+
curvePointGetSize: (curveId: number, pointIndex: number) => import("@womp/kakapo-sdk").Vec3;
|
|
192
|
+
curvePointSetSize: (curveId: number, pointIndex: number, sizeValue: import("@womp/kakapo-sdk").Vec3) => void;
|
|
193
|
+
curvePointGetFixed: (curveId: number, pointIndex: number) => boolean;
|
|
194
|
+
curvePointSetFixed: (curveId: number, pointIndex: number, fixed: boolean) => void;
|
|
195
|
+
curvePointGetRound: (curveId: number, pointIndex: number) => number;
|
|
196
|
+
curvePointSetRound: (curveId: number, pointIndex: number, round: number) => void;
|
|
197
|
+
curvePointGetMaterialId: (curveId: number, pointIndex: number) => number | null;
|
|
198
|
+
curvePointSetMaterialId: (curveId: number, pointIndex: number, materialId: number) => void;
|
|
199
|
+
materialImport: (name: string) => Promise<number>;
|
|
200
|
+
materialCreate: () => number;
|
|
201
|
+
materialDelete: (id: number) => void;
|
|
202
|
+
materialList: () => number[];
|
|
203
|
+
materialGetName: (id: number) => string;
|
|
204
|
+
materialSetName: (id: number, name: string) => void;
|
|
205
|
+
materialGetTier: (id: number) => number;
|
|
206
|
+
materialSetTier: (id: number, tier: number) => void;
|
|
207
|
+
materialGetColor: (id: number) => {
|
|
208
|
+
r: number;
|
|
209
|
+
g: number;
|
|
210
|
+
b: number;
|
|
211
|
+
};
|
|
212
|
+
materialSetColor: (id: number, color: {
|
|
213
|
+
r: number;
|
|
214
|
+
g: number;
|
|
215
|
+
b: number;
|
|
216
|
+
}) => void;
|
|
217
|
+
materialGetSecondaryColor: (id: number) => {
|
|
218
|
+
r: number;
|
|
219
|
+
g: number;
|
|
220
|
+
b: number;
|
|
221
|
+
};
|
|
222
|
+
materialSetSecondaryColor: (id: number, color: {
|
|
223
|
+
r: number;
|
|
224
|
+
g: number;
|
|
225
|
+
b: number;
|
|
226
|
+
}) => void;
|
|
227
|
+
materialGetSubsurfaceColor: (id: number) => {
|
|
228
|
+
r: number;
|
|
229
|
+
g: number;
|
|
230
|
+
b: number;
|
|
231
|
+
};
|
|
232
|
+
materialSetSubsurfaceColor: (id: number, color: {
|
|
233
|
+
r: number;
|
|
234
|
+
g: number;
|
|
235
|
+
b: number;
|
|
236
|
+
}) => void;
|
|
237
|
+
materialGetRoughness: (id: number) => number;
|
|
238
|
+
materialSetRoughness: (id: number, value: number) => void;
|
|
239
|
+
materialGetMetalness: (id: number) => number;
|
|
240
|
+
materialSetMetalness: (id: number, value: number) => void;
|
|
241
|
+
materialGetTransmittance: (id: number) => number;
|
|
242
|
+
materialSetTransmittance: (id: number, value: number) => void;
|
|
243
|
+
materialGetTranslucency: (id: number) => number;
|
|
244
|
+
materialSetTranslucency: (id: number, value: number) => void;
|
|
245
|
+
materialGetIor: (id: number) => number;
|
|
246
|
+
materialSetIor: (id: number, value: number) => void;
|
|
247
|
+
materialGetSheen: (id: number) => number;
|
|
248
|
+
materialSetSheen: (id: number, value: number) => void;
|
|
249
|
+
materialGetSheenRoughness: (id: number) => number;
|
|
250
|
+
materialSetSheenRoughness: (id: number, value: number) => void;
|
|
251
|
+
materialGetSpecularTint: (id: number) => number;
|
|
252
|
+
materialSetSpecularTint: (id: number, value: number) => void;
|
|
253
|
+
materialGetAbsorption: (id: number) => number;
|
|
254
|
+
materialSetAbsorption: (id: number, value: number) => void;
|
|
255
|
+
materialGetEmission: (id: number) => number;
|
|
256
|
+
materialSetEmission: (id: number, value: number) => void;
|
|
257
|
+
materialGetIridescence: (id: number) => number;
|
|
258
|
+
materialSetIridescence: (id: number, value: number) => void;
|
|
259
|
+
materialGetTranslucencyWeight: (id: number) => number;
|
|
260
|
+
materialSetTranslucencyWeight: (id: number, value: number) => void;
|
|
261
|
+
materialGetDispersion: (id: number) => number;
|
|
262
|
+
materialSetDispersion: (id: number, value: number) => void;
|
|
263
|
+
materialGetSurfaceOpacity: (id: number) => number;
|
|
264
|
+
materialSetSurfaceOpacity: (id: number, value: number) => void;
|
|
265
|
+
listFontFamilies: () => {
|
|
266
|
+
name: string;
|
|
267
|
+
variants: {
|
|
268
|
+
weight: string;
|
|
269
|
+
italic: boolean;
|
|
270
|
+
}[];
|
|
271
|
+
}[];
|
|
272
|
+
print: (...values: unknown[]) => void;
|
|
273
|
+
nodeGetAABB: (id: number) => Promise<{
|
|
274
|
+
min: import("@womp/kakapo-sdk").Vec3;
|
|
275
|
+
max: import("@womp/kakapo-sdk").Vec3;
|
|
276
|
+
}>;
|
|
277
|
+
nodeResize: (id: number, dimensions: Partial<import("@womp/kakapo-sdk").Vec3>) => Promise<void>;
|
|
278
|
+
aabbCenter: (box: {
|
|
279
|
+
min: import("@womp/kakapo-sdk").Vec3;
|
|
280
|
+
max: import("@womp/kakapo-sdk").Vec3;
|
|
281
|
+
}) => import("@womp/kakapo-sdk").Vec3;
|
|
282
|
+
aabbRadius: (box: {
|
|
283
|
+
min: import("@womp/kakapo-sdk").Vec3;
|
|
284
|
+
max: import("@womp/kakapo-sdk").Vec3;
|
|
285
|
+
}) => number;
|
|
286
|
+
lookAt: (origin: import("@womp/kakapo-sdk").Vec3, target: import("@womp/kakapo-sdk").Vec3) => import("@womp/kakapo-sdk").Vec3;
|
|
287
|
+
scenePropertiesRead: () => {
|
|
288
|
+
hdr_name: string | undefined;
|
|
289
|
+
hdr_multiplier: number | undefined;
|
|
290
|
+
hdr_orientation: import("@womp/kakapo-sdk").Vec2 | undefined;
|
|
291
|
+
backdrop_color1: import("@womp/kakapo-sdk").Vec3 | undefined;
|
|
292
|
+
backdrop_color2: import("@womp/kakapo-sdk").Vec3 | undefined;
|
|
293
|
+
backdrop_grad_offset: import("@womp/kakapo-sdk").Vec2 | undefined;
|
|
294
|
+
};
|
|
295
|
+
listHDRs: () => string[];
|
|
296
|
+
setHdrName: (name: string) => void;
|
|
297
|
+
setHdrMultiplier: (multiplier: number) => void;
|
|
298
|
+
setHdrOrientation: (orientation: import("@womp/kakapo-sdk").Vec2) => void;
|
|
299
|
+
setBackgroundColor: (color: {
|
|
300
|
+
r: number;
|
|
301
|
+
g: number;
|
|
302
|
+
b: number;
|
|
303
|
+
}) => void;
|
|
304
|
+
};
|
|
305
|
+
export declare function createSdkSceneEditor(options: SdkSceneEditorOptions): SdkSceneEditor;
|
|
306
|
+
export declare function createSdkSceneHost(options: SdkSceneEditorOptions & {
|
|
307
|
+
services(api: KakapoAPI, context: SparkInvocationContext): Promise<SdkSceneServices>;
|
|
308
|
+
screenshot(options: SceneScreenshotOptions, context: SparkInvocationContext): Promise<ArtifactRef>;
|
|
309
|
+
}): SceneHost;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import { createWompSceneApi, sceneNodeType } from "./womp-scene-api.js";
|
|
2
|
+
import { sceneUnitMultiplier } from "./coordinates.js";
|
|
3
|
+
import { executeSceneOperation, } from "./scene-operations.js";
|
|
4
|
+
import { readMaterialMetadata, writeMaterialMetadata, } from "./scene-metadata.js";
|
|
5
|
+
export function createSdkSceneDraft(api, scene, services) {
|
|
6
|
+
let defaultMaterialId = scene
|
|
7
|
+
.listMaterials()
|
|
8
|
+
.find(({ id }) => readMaterialMetadata(scene, id).sparkDefault === true)?.id;
|
|
9
|
+
return createWompSceneApi({
|
|
10
|
+
...services,
|
|
11
|
+
scene,
|
|
12
|
+
engine: api,
|
|
13
|
+
rootId: 0,
|
|
14
|
+
importLibraryMaterial: async (name) => {
|
|
15
|
+
if (!services.loadSuperMaterial)
|
|
16
|
+
throw new Error("The material library is unavailable in this host");
|
|
17
|
+
const loaded = await services.loadSuperMaterial(name);
|
|
18
|
+
const material = scene.importMaterial(loaded.resource);
|
|
19
|
+
writeMaterialMetadata(scene, material.id, {
|
|
20
|
+
name: loaded.name,
|
|
21
|
+
tier: loaded.tier,
|
|
22
|
+
libraryId: loaded.libraryId,
|
|
23
|
+
saved: true,
|
|
24
|
+
});
|
|
25
|
+
return material.id;
|
|
26
|
+
},
|
|
27
|
+
getDefaultMaterialId: () => {
|
|
28
|
+
if (defaultMaterialId !== undefined &&
|
|
29
|
+
scene.listMaterials().some(({ id }) => id === defaultMaterialId) &&
|
|
30
|
+
readMaterialMetadata(scene, defaultMaterialId).sparkDefault === true)
|
|
31
|
+
return defaultMaterialId;
|
|
32
|
+
const material = scene.createMaterial({
|
|
33
|
+
color: { x: 189 / 255, y: 189 / 255, z: 189 / 255 },
|
|
34
|
+
roughness: 0.22,
|
|
35
|
+
});
|
|
36
|
+
defaultMaterialId = material.id;
|
|
37
|
+
writeMaterialMetadata(scene, material.id, {
|
|
38
|
+
name: "Default Material",
|
|
39
|
+
tier: 0,
|
|
40
|
+
sparkDefault: true,
|
|
41
|
+
});
|
|
42
|
+
return material.id;
|
|
43
|
+
},
|
|
44
|
+
requireNode: (id) => {
|
|
45
|
+
scene.getNode(id);
|
|
46
|
+
},
|
|
47
|
+
requireMaterial: (id) => {
|
|
48
|
+
scene.getMaterial(id);
|
|
49
|
+
},
|
|
50
|
+
listMaterialIds: () => scene.listMaterials().map(({ id }) => id),
|
|
51
|
+
trackNode: () => { },
|
|
52
|
+
trackMaterial: () => { },
|
|
53
|
+
untrackMaterial: () => { },
|
|
54
|
+
call: (_method, _args, action) => action(),
|
|
55
|
+
callAsync: (_method, _args, action) => action(),
|
|
56
|
+
print: () => { },
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
export function createSdkSceneEditor(options) {
|
|
60
|
+
const ordinals = new WeakMap();
|
|
61
|
+
return {
|
|
62
|
+
read: (context, action) => options.withConnection(context, async (api, _beginSettlement, activeContext = context) => {
|
|
63
|
+
activeContext.signal.throwIfAborted();
|
|
64
|
+
await api.refreshScene();
|
|
65
|
+
activeContext.signal.throwIfAborted();
|
|
66
|
+
return action(api);
|
|
67
|
+
}),
|
|
68
|
+
edit: (identity, callback, expectedRevision, context, afterCommitted) => {
|
|
69
|
+
const operationKey = `${identity.capability}.${identity.operation}`;
|
|
70
|
+
const contextOrdinals = ordinals.get(context) ?? new Map();
|
|
71
|
+
ordinals.set(context, contextOrdinals);
|
|
72
|
+
const ordinal = contextOrdinals.get(operationKey) ?? 0;
|
|
73
|
+
contextOrdinals.set(operationKey, ordinal + 1);
|
|
74
|
+
const id = `${context.runId}:${context.toolCallId}:${operationKey}:${ordinal}`;
|
|
75
|
+
return options.withConnection(context, async (api, beginSettlement, activeContext = context) => {
|
|
76
|
+
const receipt = () => ({
|
|
77
|
+
id,
|
|
78
|
+
capability: identity.capability,
|
|
79
|
+
operation: identity.operation,
|
|
80
|
+
target: {
|
|
81
|
+
targetKey: options.targetKey,
|
|
82
|
+
...(options.projectId === undefined
|
|
83
|
+
? {}
|
|
84
|
+
: { projectId: options.projectId }),
|
|
85
|
+
...(typeof identity.target === "function"
|
|
86
|
+
? identity.target()
|
|
87
|
+
: identity.target),
|
|
88
|
+
},
|
|
89
|
+
});
|
|
90
|
+
let releaseCommit;
|
|
91
|
+
try {
|
|
92
|
+
let result;
|
|
93
|
+
try {
|
|
94
|
+
result = await executeSceneOperation({
|
|
95
|
+
api,
|
|
96
|
+
store: options.operations,
|
|
97
|
+
saveToRenderer: options.saveToRenderer,
|
|
98
|
+
operation: {
|
|
99
|
+
id,
|
|
100
|
+
targetKey: options.targetKey,
|
|
101
|
+
expectedRevision,
|
|
102
|
+
},
|
|
103
|
+
assertEditable: async () => {
|
|
104
|
+
activeContext.signal.throwIfAborted();
|
|
105
|
+
await options.assertEditable(activeContext);
|
|
106
|
+
},
|
|
107
|
+
edit: (draft) => callback(api, draft),
|
|
108
|
+
prepareCommit: async (operation) => {
|
|
109
|
+
await activeContext.recordReceipt({
|
|
110
|
+
...receipt(),
|
|
111
|
+
status: "unknown",
|
|
112
|
+
});
|
|
113
|
+
releaseCommit = await options.prepareCommit?.(operation, activeContext);
|
|
114
|
+
beginSettlement();
|
|
115
|
+
},
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
const operation = await options.operations.getSceneOperation(options.targetKey, id);
|
|
120
|
+
if (operation)
|
|
121
|
+
await activeContext.recordReceipt({
|
|
122
|
+
...receipt(),
|
|
123
|
+
status: operation.status === "committed"
|
|
124
|
+
? "committed"
|
|
125
|
+
: operation.status === "rolled_back"
|
|
126
|
+
? "rolled_back"
|
|
127
|
+
: "unknown",
|
|
128
|
+
});
|
|
129
|
+
throw error;
|
|
130
|
+
}
|
|
131
|
+
let details;
|
|
132
|
+
if (result.operation.changed) {
|
|
133
|
+
const adopted = await options.onCommitted?.(result.operation, api, activeContext, identity);
|
|
134
|
+
const finalized = await afterCommitted?.(result.operation, api);
|
|
135
|
+
details = { ...adopted, ...finalized };
|
|
136
|
+
}
|
|
137
|
+
await activeContext.recordReceipt({
|
|
138
|
+
...receipt(),
|
|
139
|
+
status: "committed",
|
|
140
|
+
...(details && Object.keys(details).length ? { details } : {}),
|
|
141
|
+
});
|
|
142
|
+
if (result.operation.changed) {
|
|
143
|
+
if (result.operation.save?.status === "failed")
|
|
144
|
+
throw new Error(`The scene edit was applied, but the save failed: ${result.operation.save.error} Do not repeat the edit.`);
|
|
145
|
+
if (result.operation.save?.status === "unknown")
|
|
146
|
+
throw new Error("The scene edit was applied, but its save outcome is unknown. Inspect persistence before continuing; do not repeat the edit.");
|
|
147
|
+
}
|
|
148
|
+
return result;
|
|
149
|
+
}
|
|
150
|
+
finally {
|
|
151
|
+
await releaseCommit?.();
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
},
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
export function createSdkSceneHost(options) {
|
|
158
|
+
const editor = createSdkSceneEditor(options);
|
|
159
|
+
return {
|
|
160
|
+
read: (context) => editor.read(context, async (api) => {
|
|
161
|
+
const scene = api.getScene();
|
|
162
|
+
const revision = await api.getSceneRevision();
|
|
163
|
+
return {
|
|
164
|
+
revision,
|
|
165
|
+
projectId: options.projectId,
|
|
166
|
+
unitMultiplier: sceneUnitMultiplier(scene.properties.unit_multiplier),
|
|
167
|
+
nodes: Object.values(scene.nodes).map(({ id, name, kind, parentId }) => ({
|
|
168
|
+
id,
|
|
169
|
+
name,
|
|
170
|
+
type: sceneNodeType(kind),
|
|
171
|
+
parentId: parentId ?? 0,
|
|
172
|
+
})),
|
|
173
|
+
};
|
|
174
|
+
}),
|
|
175
|
+
edit: (callback, expectedRevision, context) => editor
|
|
176
|
+
.edit({ capability: "scene", operation: "edit" }, async (api, draft) => {
|
|
177
|
+
const services = await options.services(api, context);
|
|
178
|
+
let active = true;
|
|
179
|
+
const scopedDraft = new Proxy(draft, {
|
|
180
|
+
get(target, key) {
|
|
181
|
+
const value = Reflect.get(target, key);
|
|
182
|
+
if (typeof value !== "function")
|
|
183
|
+
return value;
|
|
184
|
+
return (...args) => {
|
|
185
|
+
if (!active)
|
|
186
|
+
throw new Error("The scene draft has expired");
|
|
187
|
+
return Reflect.apply(value, target, args);
|
|
188
|
+
};
|
|
189
|
+
},
|
|
190
|
+
});
|
|
191
|
+
try {
|
|
192
|
+
return await callback(createSdkSceneDraft(api, scopedDraft, services));
|
|
193
|
+
}
|
|
194
|
+
finally {
|
|
195
|
+
active = false;
|
|
196
|
+
}
|
|
197
|
+
}, expectedRevision, context)
|
|
198
|
+
.then(({ value }) => value),
|
|
199
|
+
screenshot: options.screenshot,
|
|
200
|
+
};
|
|
201
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { KakapoAPI, ScreenshotView } from "@womp/kakapo-sdk";
|
|
2
|
+
import type { ExecutionScreenshot } from "./types.js";
|
|
3
|
+
/** Native capture policy shared by SDK-backed hosts; camera permissions belong to the host. */
|
|
4
|
+
export declare function captureSdkSceneScreenshot(api: KakapoAPI, input: {
|
|
5
|
+
targetId?: number;
|
|
6
|
+
view?: ScreenshotView;
|
|
7
|
+
}): Promise<ExecutionScreenshot>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Native capture policy shared by SDK-backed hosts; camera permissions belong to the host. */
|
|
2
|
+
export async function captureSdkSceneScreenshot(api, input) {
|
|
3
|
+
const view = input.view ?? (input.targetId === undefined ? "current" : "isometric");
|
|
4
|
+
let targetId = input.targetId;
|
|
5
|
+
if (view !== "current") {
|
|
6
|
+
await api.refreshScene();
|
|
7
|
+
if (targetId !== undefined) {
|
|
8
|
+
let target = api.getNode(targetId);
|
|
9
|
+
while (target.parentId !== null && target.parentId !== 0) {
|
|
10
|
+
target = api.getNode(target.parentId);
|
|
11
|
+
}
|
|
12
|
+
if (target.kind === "union" || target.kind === "group")
|
|
13
|
+
targetId = target.id;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return api.captureScreenshot({ targetId, view, timeoutMs: 30_000 });
|
|
17
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { readFile } from "node:fs/promises";
|
|
2
|
+
/** Actual local material resources, explicitly labeled as development assets. */
|
|
3
|
+
export async function loadDemoSceneMaterials() {
|
|
4
|
+
const materials = new Map();
|
|
5
|
+
for (const filename of ["matte-blue.json", "polished-copper.json"]) {
|
|
6
|
+
const material = JSON.parse(await readFile(new URL(`./fixtures/materials/${filename}`, import.meta.url), "utf8"));
|
|
7
|
+
materials.set(material.name.toLowerCase(), material);
|
|
8
|
+
}
|
|
9
|
+
return {
|
|
10
|
+
superMaterialNames: [...materials.values()].map(({ name }) => name),
|
|
11
|
+
loadSuperMaterial: async (name) => {
|
|
12
|
+
const material = materials.get(name.trim().toLowerCase());
|
|
13
|
+
if (!material)
|
|
14
|
+
throw new Error(`Unknown development material: ${name}. Use listSuperMaterials() to see the local fixture catalog.`);
|
|
15
|
+
return { ...structuredClone(material), tier: 0, libraryId: -1 };
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
}
|
package/dist/server/express.js
CHANGED
|
@@ -44,12 +44,10 @@ export function createSparkAgentRouter(options) {
|
|
|
44
44
|
});
|
|
45
45
|
router.post("/conversations", async (request, response) => {
|
|
46
46
|
const ownerId = await resolveOwnerId(request);
|
|
47
|
-
const body = z
|
|
48
|
-
.object({
|
|
47
|
+
const body = z.object({
|
|
49
48
|
id: z.string().min(1).optional(),
|
|
50
49
|
title: z.string().max(200).optional(),
|
|
51
|
-
})
|
|
52
|
-
.parse(request.body ?? {});
|
|
50
|
+
}).parse(request.body ?? {});
|
|
53
51
|
const conversation = await options.service.createConversation(ownerId, body);
|
|
54
52
|
response.status(201).json({ conversation });
|
|
55
53
|
});
|
package/dist/server/index.d.ts
CHANGED
|
@@ -4,5 +4,6 @@ export { createSparkRunExecutor, type ResolvedSparkModel, type SparkRunExecutorO
|
|
|
4
4
|
export { SparkAgentService, SparkServiceError } from "./service.js";
|
|
5
5
|
export type { SubmitSparkMessageInput } from "./service.js";
|
|
6
6
|
export { MemorySparkAgentStore } from "./store.js";
|
|
7
|
-
export {
|
|
7
|
+
export { SqliteSparkStore } from "./sqlite-store.js";
|
|
8
|
+
export { createStandaloneSparkAgentApp, type StandaloneSparkAgentOptions, type StandaloneSparkAgentApp, } from "./standalone.js";
|
|
8
9
|
export type { SparkAgentStore, SparkConversation, SparkConversationSummary, SparkRun, SparkRunExecutionContext, SparkRunExecutor, SparkRunSettings, } from "./types.js";
|
package/dist/server/index.js
CHANGED
|
@@ -2,4 +2,5 @@ export { MemorySparkArtifactStore } from "./artifacts.js";
|
|
|
2
2
|
export { createSparkRunExecutor, } from "./executor.js";
|
|
3
3
|
export { SparkAgentService, SparkServiceError } from "./service.js";
|
|
4
4
|
export { MemorySparkAgentStore } from "./store.js";
|
|
5
|
-
export {
|
|
5
|
+
export { SqliteSparkStore } from "./sqlite-store.js";
|
|
6
|
+
export { createStandaloneSparkAgentApp, } from "./standalone.js";
|
package/dist/server/service.d.ts
CHANGED
|
@@ -17,6 +17,7 @@ export declare class SparkAgentService {
|
|
|
17
17
|
private readonly executeRun;
|
|
18
18
|
private readonly controllers;
|
|
19
19
|
private readonly listeners;
|
|
20
|
+
private readonly executions;
|
|
20
21
|
constructor(options: {
|
|
21
22
|
store: SparkAgentStore;
|
|
22
23
|
executeRun: SparkRunExecutor;
|
|
@@ -29,6 +30,9 @@ export declare class SparkAgentService {
|
|
|
29
30
|
getConversation(ownerId: string, id: string): Promise<SparkConversation>;
|
|
30
31
|
getRun(ownerId: string, id: string): Promise<SparkRun>;
|
|
31
32
|
getActiveRun(ownerId: string, conversationId: string): Promise<SparkRun | undefined>;
|
|
33
|
+
/** The host must establish exclusive ownership before recovering abandoned runs. */
|
|
34
|
+
recoverInterruptedRun(runId: string): Promise<void>;
|
|
35
|
+
close(): Promise<void>;
|
|
32
36
|
submitMessage(input: SubmitSparkMessageInput): Promise<SparkRun>;
|
|
33
37
|
cancelRun(ownerId: string, runId: string): Promise<SparkRun>;
|
|
34
38
|
streamRun(ownerId: string, runId: string, afterSequence: number, signal: AbortSignal): AsyncGenerator<StoredSparkChunk>;
|