@womp/spark-agent 6.5.0 → 8.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.
Files changed (40) hide show
  1. package/CHANGELOG.md +86 -0
  2. package/README.md +7 -4
  3. package/dist/agent.d.ts +3 -6
  4. package/dist/agent.js +41 -23
  5. package/dist/capabilities/geometry.d.ts +17 -5
  6. package/dist/capabilities/geometry.js +11 -12
  7. package/dist/compaction.d.ts +41 -8
  8. package/dist/compaction.js +241 -77
  9. package/dist/context-window.d.ts +23 -0
  10. package/dist/context-window.js +141 -0
  11. package/dist/generated/geometry-declarations.d.ts +1 -1
  12. package/dist/generated/geometry-declarations.js +1 -1
  13. package/dist/geometry/backendRegistry.d.ts +1 -0
  14. package/dist/geometry/common.d.ts +5 -2
  15. package/dist/geometry/common.js +18 -3
  16. package/dist/geometry/compiler.js +2 -2
  17. package/dist/geometry/diagnostics.d.ts +2 -7
  18. package/dist/geometry/diagnostics.js +3 -51
  19. package/dist/geometry/graph.d.ts +1 -1
  20. package/dist/geometry/graph.js +1 -0
  21. package/dist/geometry/index.d.ts +0 -1
  22. package/dist/geometry/index.js +0 -3
  23. package/dist/geometry/lift.js +105 -113
  24. package/dist/geometry/lower.js +29 -49
  25. package/dist/geometry/schemas/flowir-dialect.json +117 -117
  26. package/dist/geometry/writeParamData.js +4 -4
  27. package/dist/geometry.d.ts +2 -5
  28. package/dist/geometry.js +7 -11
  29. package/dist/index.d.ts +2 -2
  30. package/dist/index.js +2 -1
  31. package/dist/intent-bench.js +1 -1
  32. package/dist/sdk-geometry-host.d.ts +1 -1
  33. package/dist/sdk-geometry-host.js +253 -251
  34. package/dist/ui.d.ts +7 -0
  35. package/dist/ui.js +1 -0
  36. package/dist/womp-scene-api.d.ts +9 -1
  37. package/dist/womp-scene-api.js +41 -32
  38. package/package.json +2 -2
  39. package/dist/context-budget.d.ts +0 -65
  40. package/dist/context-budget.js +0 -364
@@ -1,4 +1,4 @@
1
- import { astNameToTitle, defaultScalar, valueBackendName, isArrayPortType, } from "./common.js";
1
+ import { astNameToTitle, backendTypeId, defaultScalar, valueBackendName, isArrayPortType, } from "./common.js";
2
2
  class GraphBuilder {
3
3
  nextId = 0;
4
4
  nodes = {};
@@ -28,10 +28,7 @@ class GraphBuilder {
28
28
  }
29
29
  }
30
30
  function resolveBackendSchema(nodeType, flowirRegistry, backendRegistry) {
31
- const typeId = flowirRegistry.getNodeTypeId(nodeType);
32
- if (typeId === null)
33
- return null;
34
- return backendRegistry.getSchema(typeId);
31
+ return backendRegistry.getSchema(backendTypeId(flowirRegistry, nodeType));
35
32
  }
36
33
  function toLiteral(value) {
37
34
  if (value.kind === "int")
@@ -45,10 +42,7 @@ function toLiteral(value) {
45
42
  return null;
46
43
  }
47
44
  function isVecPortType(type) {
48
- return (type === "Vec3" ||
49
- type === "Vec" ||
50
- type === "Vec3[]" ||
51
- type === "VecArray");
45
+ return type === "Vec" || type === "VecArray";
52
46
  }
53
47
  function isZeroVec(v) {
54
48
  if (!v || typeof v !== "object")
@@ -56,11 +50,9 @@ function isZeroVec(v) {
56
50
  const vec = v;
57
51
  return vec.x === 0 && vec.y === 0 && vec.z === 0;
58
52
  }
59
- function isDefaultValue(value, port, dialectPort) {
53
+ function isDefaultValue(value, port) {
60
54
  if (port.enumValues?.length)
61
55
  return false;
62
- if (dialectPort?.enum)
63
- return false;
64
56
  if (defaultScalar(port) === null)
65
57
  return false;
66
58
  if (value === 0)
@@ -91,9 +83,9 @@ function encodeLiteralForPort(literal, port) {
91
83
  }
92
84
  return isArray ? [scalar] : scalar;
93
85
  }
94
- function trySetInput(bid, portIndex, literal, port, dialectPort, graph) {
86
+ function trySetInput(bid, portIndex, literal, port, graph) {
95
87
  const encoded = encodeLiteralForPort(literal, port);
96
- if (!isDefaultValue(encoded, port, dialectPort)) {
88
+ if (!isDefaultValue(encoded, port)) {
97
89
  graph.setInput(bid, portIndex, encoded);
98
90
  }
99
91
  }
@@ -101,27 +93,19 @@ function encodeValue(value, port, dialectPort, flowirRegistry) {
101
93
  const literal = toLiteral(value);
102
94
  if (literal)
103
95
  return encodeLiteralForPort(literal, port);
104
- if (value.kind === "ident") {
105
- if (dialectPort?.enum) {
106
- const idx = flowirRegistry
107
- .getEnumValues(dialectPort.enum)
108
- .indexOf(value.name);
109
- if (idx >= 0)
110
- return idx;
111
- }
112
- if (port.enumValues?.length) {
113
- const idx = port.enumValues.indexOf(value.name);
114
- if (idx >= 0)
115
- return idx;
116
- }
117
- }
118
- return null;
96
+ if (value.kind !== "ident" || !flowirRegistry.isEnum(dialectPort.type))
97
+ return null;
98
+ const index = flowirRegistry
99
+ .getEnumValues(dialectPort.type)
100
+ .indexOf(value.name);
101
+ return index >= 0 ? index : null;
119
102
  }
120
103
  function valueNodeSchema(typeName, backendRegistry) {
121
104
  const backendName = valueBackendName(typeName);
122
- if (!backendName)
123
- return null;
124
- return backendRegistry.getSchemaByName(backendName);
105
+ const schema = backendName ? backendRegistry.getSchemaByName(backendName) : null;
106
+ if (!schema)
107
+ throw new Error(`Geometry has no value node for ${typeName}.`);
108
+ return schema;
125
109
  }
126
110
  function lowerFloatExpr(expr, ctx) {
127
111
  if (expr.kind === "float_lit")
@@ -157,7 +141,7 @@ function lowerFloatExpr(expr, ctx) {
157
141
  if (left.kind === "literal") {
158
142
  const port = mathFloat.inputs[1];
159
143
  if (port)
160
- trySetInput(bid, 1, { kind: "float", value: left.value }, port, null, ctx.graph);
144
+ trySetInput(bid, 1, { kind: "float", value: left.value }, port, ctx.graph);
161
145
  }
162
146
  else {
163
147
  ctx.graph.connect(left.backendNodeId, left.portIndex, bid, 1);
@@ -165,7 +149,7 @@ function lowerFloatExpr(expr, ctx) {
165
149
  if (right.kind === "literal") {
166
150
  const port = mathFloat.inputs[2];
167
151
  if (port)
168
- trySetInput(bid, 2, { kind: "float", value: right.value }, port, null, ctx.graph);
152
+ trySetInput(bid, 2, { kind: "float", value: right.value }, port, ctx.graph);
169
153
  }
170
154
  else {
171
155
  ctx.graph.connect(right.backendNodeId, right.portIndex, bid, 2);
@@ -187,7 +171,7 @@ function lowerVec3Ctor(ctor, targetBid, targetPortIndex, targetPort, ctx) {
187
171
  if (result.kind === "literal") {
188
172
  const port = combineXyz.inputs[idx];
189
173
  if (port)
190
- trySetInput(combineBid, idx, { kind: "float", value: result.value }, port, null, ctx.graph);
174
+ trySetInput(combineBid, idx, { kind: "float", value: result.value }, port, ctx.graph);
191
175
  }
192
176
  else {
193
177
  ctx.graph.connect(result.backendNodeId, result.portIndex, combineBid, idx);
@@ -198,22 +182,19 @@ function lowerVec3Ctor(ctor, targetBid, targetPortIndex, targetPort, ctx) {
198
182
  }
199
183
  function lowerConst(stmt, ctx) {
200
184
  const schema = valueNodeSchema(stmt.typeName, ctx.backendRegistry);
201
- if (!schema)
202
- return;
203
185
  const lit = toLiteral(stmt.value);
204
186
  if (!lit)
205
187
  return;
206
188
  const bid = ctx.graph.addNode(schema.typeId);
207
189
  const backendPort = schema.inputs[0];
208
190
  if (backendPort)
209
- trySetInput(bid, 0, lit, backendPort, null, ctx.graph);
191
+ trySetInput(bid, 0, lit, backendPort, ctx.graph);
210
192
  ctx.paramNodes.set(stmt.name, bid);
211
193
  ctx.nodeIds[`const:${stmt.name}`] = bid;
194
+ ctx.graphExt.nodes[bid] = { flowirSymbol: stmt.name };
212
195
  }
213
196
  function lowerParam(stmt, ctx) {
214
197
  const schema = valueNodeSchema(stmt.typeName, ctx.backendRegistry);
215
- if (!schema)
216
- return;
217
198
  const lit = toLiteral(stmt.value);
218
199
  if (!lit)
219
200
  return;
@@ -222,17 +203,18 @@ function lowerParam(stmt, ctx) {
222
203
  return;
223
204
  const gipBid = ctx.graph.addNode(gipSchema.typeId);
224
205
  ctx.nodeIds[`param-input:${stmt.name}`] = gipBid;
225
- ctx.nodeNames.set(gipBid, astNameToTitle(stmt.name));
206
+ ctx.graphExt.nodes[gipBid] = { name: astNameToTitle(stmt.name) };
226
207
  ctx.graph.setInput(gipBid, 0, stmt.range.min);
227
208
  ctx.graph.setInput(gipBid, 1, stmt.range.max);
228
209
  ctx.graph.setInput(gipBid, 2, stmt.range.step);
229
210
  const bid = ctx.graph.addNode(schema.typeId);
230
211
  const backendPort = schema.inputs[0];
231
212
  if (backendPort)
232
- trySetInput(bid, 0, lit, backendPort, null, ctx.graph);
213
+ trySetInput(bid, 0, lit, backendPort, ctx.graph);
233
214
  ctx.graph.connect(gipBid, 0, bid, 0);
234
215
  ctx.paramNodes.set(stmt.name, bid);
235
216
  ctx.nodeIds[`param:${stmt.name}`] = bid;
217
+ ctx.graphExt.nodes[bid] = { flowirSymbol: stmt.name };
236
218
  }
237
219
  function lowerNodeStmt(stmt, ctx, pending) {
238
220
  const schema = resolveBackendSchema(stmt.nodeType, ctx.flowirRegistry, ctx.backendRegistry);
@@ -241,6 +223,7 @@ function lowerNodeStmt(stmt, ctx, pending) {
241
223
  const bid = ctx.graph.addNode(schema.typeId);
242
224
  ctx.backendIds.set(stmt.id, bid);
243
225
  ctx.nodeIds[`node:${stmt.id}`] = bid;
226
+ ctx.graphExt.nodes[bid] = { flowirSymbol: stmt.id };
244
227
  ctx.nodeTypes.set(stmt.id, stmt.nodeType);
245
228
  ctx.nodeSchemas.set(stmt.id, schema);
246
229
  for (const input of stmt.inputs) {
@@ -272,7 +255,7 @@ function lowerNodeStmt(stmt, ctx, pending) {
272
255
  if (input.value.kind === "vec3ctor") {
273
256
  const lowered = lowerVec3Ctor(input.value, bid, resolved.index, backendPort, ctx);
274
257
  if (lowered !== null &&
275
- !isDefaultValue(lowered, backendPort, resolved.port)) {
258
+ !isDefaultValue(lowered, backendPort)) {
276
259
  ctx.graph.setInput(bid, resolved.index, lowered);
277
260
  }
278
261
  continue;
@@ -280,7 +263,7 @@ function lowerNodeStmt(stmt, ctx, pending) {
280
263
  const encoded = encodeValue(input.value, backendPort, resolved.port, ctx.flowirRegistry);
281
264
  if (encoded === null)
282
265
  continue;
283
- if (isDefaultValue(encoded, backendPort, resolved.port))
266
+ if (isDefaultValue(encoded, backendPort))
284
267
  continue;
285
268
  ctx.graph.setInput(bid, resolved.index, encoded);
286
269
  }
@@ -337,7 +320,7 @@ export function lower(program, flowirRegistry, backendRegistry) {
337
320
  backendIds: new Map(),
338
321
  nodeTypes: new Map(),
339
322
  nodeSchemas: new Map(),
340
- nodeNames: new Map(),
323
+ graphExt: { nodes: {} },
341
324
  nodeIds: {},
342
325
  };
343
326
  const pending = [];
@@ -358,8 +341,5 @@ export function lower(program, flowirRegistry, backendRegistry) {
358
341
  }
359
342
  }
360
343
  resolvePendingConnections(pending, ctx);
361
- const graphExt = {
362
- nodes: Object.fromEntries([...ctx.nodeNames.entries()].map(([bid, name]) => [bid, { name }])),
363
- };
364
- return { graph: graph.toPayload(), graphExt, nodeIds: ctx.nodeIds };
344
+ return { graph: graph.toPayload(), graphExt: ctx.graphExt, nodeIds: ctx.nodeIds };
365
345
  }