@womp/spark-agent 2.0.0 → 2.2.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 +5 -0
- package/dist/capabilities/health.d.ts +9 -0
- package/dist/capabilities/health.js +27 -0
- package/dist/capabilities.d.ts +3 -1
- package/dist/capabilities.js +1 -0
- package/dist/cli.js +1 -0
- package/dist/generated/health-declarations.d.ts +1 -0
- package/dist/generated/health-declarations.js +3 -0
- package/dist/geometry/backendRegistry.d.ts +37 -0
- package/dist/geometry/backendRegistry.js +61 -0
- package/dist/geometry/common.d.ts +26 -0
- package/dist/geometry/common.js +78 -0
- package/dist/geometry/compiler.d.ts +35 -0
- package/dist/geometry/compiler.js +115 -0
- package/dist/geometry/graph.d.ts +39 -0
- package/dist/geometry/graph.js +32 -0
- package/dist/geometry/index.d.ts +9 -0
- package/dist/geometry/index.js +12 -0
- package/dist/geometry/lift.d.ts +7 -0
- package/dist/geometry/lift.js +376 -0
- package/dist/geometry/lower.d.ts +9 -0
- package/dist/geometry/lower.js +363 -0
- package/dist/geometry/parameters.d.ts +23 -0
- package/dist/geometry/parameters.js +46 -0
- package/dist/geometry/schemas/backend-schema.json +3394 -0
- package/dist/geometry/schemas/flowir-dialect.json +979 -0
- package/dist/geometry/writeParamData.d.ts +18 -0
- package/dist/geometry/writeParamData.js +47 -0
- package/dist/geometry.d.ts +10 -0
- package/dist/geometry.js +19 -0
- package/dist/kakapo.d.ts +6 -1
- package/dist/kakapo.js +5 -0
- package/dist/openscad.d.ts +85 -0
- package/dist/openscad.js +223 -0
- package/dist/repair-state.d.ts +50 -0
- package/dist/repair-state.js +96 -0
- package/dist/scene-health.d.ts +49 -0
- package/dist/scene-health.js +176 -0
- package/dist/sdk-geometry-host.d.ts +12 -0
- package/dist/sdk-geometry-host.js +306 -0
- package/dist/sdk-openscad-host.d.ts +14 -0
- package/dist/sdk-openscad-host.js +296 -0
- package/dist/sdk-openscad-renderer.d.ts +11 -0
- package/dist/sdk-openscad-renderer.js +71 -0
- package/dist/sdk-scene-health-host.d.ts +4 -0
- package/dist/sdk-scene-health-host.js +13 -0
- package/dist/sdk-scene-host.d.ts +5 -2
- package/dist/sdk-scene-host.js +6 -5
- package/dist/server/fixtures/materials/matte-blue.json +1 -1
- package/dist/server/fixtures/materials/polished-copper.json +1 -1
- package/dist/server/sqlite-store.d.ts +2 -0
- package/dist/server/sqlite-store.js +26 -2
- package/dist/server/standalone.d.ts +9 -0
- package/dist/server/standalone.js +91 -15
- package/package.json +17 -3
package/README.md
CHANGED
|
@@ -204,6 +204,7 @@ Configure the process with:
|
|
|
204
204
|
- `KAKAPO_URL` (defaults to `ws://127.0.0.1:5502`)
|
|
205
205
|
- `PORT` (defaults to `8787`)
|
|
206
206
|
- `SPARK_STORAGE_PATH` (defaults to `.spark/spark.sqlite`)
|
|
207
|
+
- `SPARK_SCENE_IDENTITY` (optional stable identity for the scene behind `KAKAPO_URL`)
|
|
207
208
|
|
|
208
209
|
The CLI automatically loads `.env` from its working directory when the file exists. Copy
|
|
209
210
|
`.env.example` to `.env`, then add the provider key you intend to use. Existing process environment
|
|
@@ -224,6 +225,10 @@ preserves recorded output and marks abandoned queued/running runs incomplete wit
|
|
|
224
225
|
scene edits. Pending approvals remain pending. Full operation reconciliation and run continuation
|
|
225
226
|
are still being integrated. Node 22 reports an experimental warning for its built-in SQLite module.
|
|
226
227
|
|
|
228
|
+
Set `SPARK_SCENE_IDENTITY` only when the host can verify that the value names the same durable
|
|
229
|
+
scene across renderer reconnects. Without it, Spark uses a process-scoped identity and does not
|
|
230
|
+
authorize interrupted scene mutations to continue after a server restart.
|
|
231
|
+
|
|
227
232
|
`createStandaloneSparkAgentApp(options)` is asynchronous. Await it before listening, and call
|
|
228
233
|
`await app.dispose()` on shutdown to settle active runs and release storage ownership.
|
|
229
234
|
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { SparkCapability, SparkInvocationContext } from "../capabilities.js";
|
|
2
|
+
import type { SceneHealth } from "../scene-health.js";
|
|
3
|
+
export type WompHealthApi = {
|
|
4
|
+
read(objectIds: number[]): Promise<SceneHealth>;
|
|
5
|
+
};
|
|
6
|
+
export interface SceneHealthHost {
|
|
7
|
+
read(objectIds: number[], context: SparkInvocationContext): Promise<SceneHealth>;
|
|
8
|
+
}
|
|
9
|
+
export declare function createSceneHealthCapability(host: SceneHealthHost): SparkCapability<WompHealthApi>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { WOMP_HEALTH_DECLARATIONS } from "../generated/health-declarations.js";
|
|
3
|
+
export function createSceneHealthCapability(host) {
|
|
4
|
+
return {
|
|
5
|
+
skills: [
|
|
6
|
+
{
|
|
7
|
+
name: "scene-health",
|
|
8
|
+
version: "1",
|
|
9
|
+
description: "Required before scene checks or procedural edits: engine limits, empty Areas, fresh geometry feedback, and bounded repairs.",
|
|
10
|
+
instructions: `Before checking or editing a model, call womp.health.read([]) for current scene health. A health read is a snapshot and does not prove that the latest edit finished evaluating. Inspect scene edit receipts before claiming success.
|
|
11
|
+
For confirmed primitive or depth overflow, repair the same target while preserving design, dimensions, active parameter overrides, and unrelated objects. At most two geometry repairs are allowed per target in one logical run. Unverified feedback must not trigger blind regeneration or a claim that the model passed. Empty Areas may be pending, intentionally empty, mesh-only, or failed. Overflow flags take precedence over possibly stale counts. max_total_depth is a scene hierarchy limit, not measured Boolean depth.`,
|
|
12
|
+
declarations: WOMP_HEALTH_DECLARATIONS,
|
|
13
|
+
examples: ["print(await womp.health.read([]));"],
|
|
14
|
+
},
|
|
15
|
+
],
|
|
16
|
+
createApi: (context) => ({
|
|
17
|
+
read: (objectIds) => {
|
|
18
|
+
const parsed = z
|
|
19
|
+
.array(z.number().int().positive())
|
|
20
|
+
.safeParse(objectIds);
|
|
21
|
+
if (parsed.success === false)
|
|
22
|
+
return Promise.reject(parsed.error);
|
|
23
|
+
return host.read(parsed.data, context);
|
|
24
|
+
},
|
|
25
|
+
}),
|
|
26
|
+
};
|
|
27
|
+
}
|
package/dist/capabilities.d.ts
CHANGED
|
@@ -11,9 +11,11 @@ export type { AssetImportsHost, MeshImportRequest, ImageImportRequest, AssetImpo
|
|
|
11
11
|
export type { AssetsHost, AssetListOptions, ConversationAsset, AssetPage, WompAssetsApi, } from "./capabilities/assets.js";
|
|
12
12
|
export type { OperationsHost, OperationType, OperationModel, OperationCatalog, OperationRequest, OperationJob, OperationStartResult, OperationWaitOptions, OperationWaitResult, OperationListOptions, OperationPage, WompOperationsApi, } from "./capabilities/operations.js";
|
|
13
13
|
export type { AccountHost, AccountRead, AccountSection, AccountScope, AccountResult, AccountSnapshot, AccountPage, AccountProfile, AccountTeam, AccountCreditBalance, AccountSubscription, AccountBilling, AccountOrderItem, AccountOrder, AccountProject, AccountNotification, AccountWorkflow, WompAccountApi, } from "./capabilities/account.js";
|
|
14
|
-
export type { KnowledgeAnswer, KnowledgeHost, WompKnowledgeApi } from "./capabilities/knowledge.js";
|
|
14
|
+
export type { KnowledgeAnswer, KnowledgeHost, WompKnowledgeApi, } from "./capabilities/knowledge.js";
|
|
15
15
|
export { createOpenScadCapability } from "./capabilities/openscad.js";
|
|
16
16
|
export { createGeometryCapability } from "./capabilities/geometry.js";
|
|
17
|
+
export { createSceneHealthCapability } from "./capabilities/health.js";
|
|
18
|
+
export type { SceneHealthHost, WompHealthApi } from "./capabilities/health.js";
|
|
17
19
|
export { createFlowCapability } from "./capabilities/flow.js";
|
|
18
20
|
export type { FlowHost, FlowSnapshot, FlowWrite, FlowWriteResult, WompFlowApi, } from "./capabilities/flow.js";
|
|
19
21
|
export type { GeometryHost, GeometryTarget, GeometryInstance, GeometryParamValue, GeometryWrite, GeometryWriteResult, WompGeometryApi, } from "./capabilities/geometry.js";
|
package/dist/capabilities.js
CHANGED
|
@@ -5,6 +5,7 @@ export { createOperationsCapability } from "./capabilities/operations.js";
|
|
|
5
5
|
export { createAssetsCapability } from "./capabilities/assets.js";
|
|
6
6
|
export { createOpenScadCapability } from "./capabilities/openscad.js";
|
|
7
7
|
export { createGeometryCapability } from "./capabilities/geometry.js";
|
|
8
|
+
export { createSceneHealthCapability } from "./capabilities/health.js";
|
|
8
9
|
export { createFlowCapability } from "./capabilities/flow.js";
|
|
9
10
|
/** The enabled bindings are also the only source of discoverable skills. */
|
|
10
11
|
export function composeCapabilities(capabilities) {
|
package/dist/cli.js
CHANGED
|
@@ -19,6 +19,7 @@ const app = await createStandaloneSparkAgentApp({
|
|
|
19
19
|
kakapoUrl: process.env.KAKAPO_URL ?? "ws://127.0.0.1:5502",
|
|
20
20
|
developmentProfile: values.profile,
|
|
21
21
|
storagePath: process.env.SPARK_STORAGE_PATH,
|
|
22
|
+
sceneIdentity: process.env.SPARK_SCENE_IDENTITY,
|
|
22
23
|
});
|
|
23
24
|
const server = app.listen(port, "127.0.0.1", () => {
|
|
24
25
|
process.stdout.write(`Spark Agent server listening on http://127.0.0.1:${port}\n`);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const WOMP_HEALTH_DECLARATIONS = "declare const womp: { health: {\n\"read\": ((objectIds: Array<number>) => Promise<{\n\"status\": \"within_limits\" | \"overflow\" | \"unverified\";\n\"freshness\": \"unverified\" | \"snapshot\" | \"post_ack_event\";\n\"revisionVerified\": false;\n\"affectedAreaIds\": Array<string>;\n\"emptyAreaIds\"?: undefined | Array<string>;\n\"thermometer\"?: undefined | {\n\"objects\": {\n[key: string]: {\n\"num_prims\": number;\n\"flag_prim_overflow\": number;\n\"flag_depth_overflow\": number;\n\"flag_vox_overflow\": number;\n\"voxels\": number;\n};\n};\n\"max_num_prims\": number;\n\"max_total_depth\": number;\n\"max_per_object\": number;\n\"total\": number;\n\"max_total\": number;\n\"assets_budget_used\": number;\n\"assets_budget_total\": number;\n\"mesh_instances_used\"?: undefined | number;\n\"mesh_instances_total\"?: undefined | number;\n\"decal_instances_used\"?: undefined | number;\n\"decal_instances_total\"?: undefined | number;\n\"field_instances_used\"?: undefined | number;\n\"field_instances_total\"?: undefined | number;\n};\n\"reason\"?: undefined | string;\n}>);\n} };\ndeclare function print(...values: unknown[]): void;\ndeclare function emitImage(ref: { id: string; mediaType: string; name?: string }): Promise<void>;\ndeclare function emitFile(ref: { id: string; mediaType: string; name?: string }): Promise<void>;\n";
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
// Generated by scripts/generate-skill-declarations.mjs.
|
|
2
|
+
// prettier-ignore
|
|
3
|
+
export const WOMP_HEALTH_DECLARATIONS = "declare const womp: { health: {\n\"read\": ((objectIds: Array<number>) => Promise<{\n\"status\": \"within_limits\" | \"overflow\" | \"unverified\";\n\"freshness\": \"unverified\" | \"snapshot\" | \"post_ack_event\";\n\"revisionVerified\": false;\n\"affectedAreaIds\": Array<string>;\n\"emptyAreaIds\"?: undefined | Array<string>;\n\"thermometer\"?: undefined | {\n\"objects\": {\n[key: string]: {\n\"num_prims\": number;\n\"flag_prim_overflow\": number;\n\"flag_depth_overflow\": number;\n\"flag_vox_overflow\": number;\n\"voxels\": number;\n};\n};\n\"max_num_prims\": number;\n\"max_total_depth\": number;\n\"max_per_object\": number;\n\"total\": number;\n\"max_total\": number;\n\"assets_budget_used\": number;\n\"assets_budget_total\": number;\n\"mesh_instances_used\"?: undefined | number;\n\"mesh_instances_total\"?: undefined | number;\n\"decal_instances_used\"?: undefined | number;\n\"decal_instances_total\"?: undefined | number;\n\"field_instances_used\"?: undefined | number;\n\"field_instances_total\"?: undefined | number;\n};\n\"reason\"?: undefined | string;\n}>);\n} };\ndeclare function print(...values: unknown[]): void;\ndeclare function emitImage(ref: { id: string; mediaType: string; name?: string }): Promise<void>;\ndeclare function emitFile(ref: { id: string; mediaType: string; name?: string }): Promise<void>;\n";
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export type BackendPort = {
|
|
2
|
+
name: string;
|
|
3
|
+
type: string;
|
|
4
|
+
enumValues?: string[];
|
|
5
|
+
};
|
|
6
|
+
export type BackendNodeSchema = {
|
|
7
|
+
typeId: number;
|
|
8
|
+
name: string;
|
|
9
|
+
inputs: BackendPort[];
|
|
10
|
+
outputs: BackendPort[];
|
|
11
|
+
};
|
|
12
|
+
export type BackendValue = number | boolean | string | {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
z: number;
|
|
16
|
+
} | number[] | boolean[] | string[] | Array<{
|
|
17
|
+
x: number;
|
|
18
|
+
y: number;
|
|
19
|
+
z: number;
|
|
20
|
+
}>;
|
|
21
|
+
export declare class BackendRegistry {
|
|
22
|
+
private readonly schemas;
|
|
23
|
+
private readonly typeIdsByName;
|
|
24
|
+
private constructor();
|
|
25
|
+
static fromJsonObject(obj: unknown): BackendRegistry;
|
|
26
|
+
static fromBundledJson(): BackendRegistry;
|
|
27
|
+
getSchema(typeId: number): BackendNodeSchema | null;
|
|
28
|
+
getSchemaByName(name: string): BackendNodeSchema | null;
|
|
29
|
+
}
|
|
30
|
+
export type GraphExt = {
|
|
31
|
+
nodes: Record<string, {
|
|
32
|
+
name?: string;
|
|
33
|
+
position?: number[];
|
|
34
|
+
[key: string]: unknown;
|
|
35
|
+
}>;
|
|
36
|
+
[key: string]: unknown;
|
|
37
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import geoNodeDescRaw from "./schemas/backend-schema.json" with { type: "json" };
|
|
2
|
+
function parsePort(raw) {
|
|
3
|
+
if (typeof raw.title !== "string" || typeof raw.type !== "string")
|
|
4
|
+
return null;
|
|
5
|
+
const name = raw.title.trim();
|
|
6
|
+
const type = raw.type.trim();
|
|
7
|
+
if (!name || !type)
|
|
8
|
+
return null;
|
|
9
|
+
const enumValues = Array.isArray(raw.values)
|
|
10
|
+
? raw.values.filter((v) => typeof v === "string")
|
|
11
|
+
: undefined;
|
|
12
|
+
return { name, type, enumValues };
|
|
13
|
+
}
|
|
14
|
+
function parseNodeSchema(typeId, raw) {
|
|
15
|
+
if (typeof raw.name !== "string")
|
|
16
|
+
return null;
|
|
17
|
+
const name = raw.name.trim();
|
|
18
|
+
if (!name)
|
|
19
|
+
return null;
|
|
20
|
+
const rawInputs = Array.isArray(raw.inputs) ? raw.inputs : [];
|
|
21
|
+
const rawOutputs = Array.isArray(raw.outputs) ? raw.outputs : [];
|
|
22
|
+
const inputs = rawInputs
|
|
23
|
+
.map((p) => parsePort(p))
|
|
24
|
+
.filter((p) => p !== null);
|
|
25
|
+
const outputs = rawOutputs
|
|
26
|
+
.map((p) => parsePort(p))
|
|
27
|
+
.filter((p) => p !== null);
|
|
28
|
+
return { typeId, name, inputs, outputs };
|
|
29
|
+
}
|
|
30
|
+
export class BackendRegistry {
|
|
31
|
+
schemas = new Map();
|
|
32
|
+
typeIdsByName = new Map();
|
|
33
|
+
constructor() { }
|
|
34
|
+
static fromJsonObject(obj) {
|
|
35
|
+
const registry = new BackendRegistry();
|
|
36
|
+
const raw = (obj ?? {});
|
|
37
|
+
for (const [typeIdStr, rawSchema] of Object.entries(raw)) {
|
|
38
|
+
const typeId = Number(typeIdStr);
|
|
39
|
+
if (!Number.isFinite(typeId))
|
|
40
|
+
continue;
|
|
41
|
+
const parsed = parseNodeSchema(Math.trunc(typeId), rawSchema);
|
|
42
|
+
if (!parsed)
|
|
43
|
+
continue;
|
|
44
|
+
registry.schemas.set(parsed.typeId, parsed);
|
|
45
|
+
registry.typeIdsByName.set(parsed.name, parsed.typeId);
|
|
46
|
+
}
|
|
47
|
+
return registry;
|
|
48
|
+
}
|
|
49
|
+
static fromBundledJson() {
|
|
50
|
+
return BackendRegistry.fromJsonObject(geoNodeDescRaw);
|
|
51
|
+
}
|
|
52
|
+
getSchema(typeId) {
|
|
53
|
+
return this.schemas.get(typeId) ?? null;
|
|
54
|
+
}
|
|
55
|
+
getSchemaByName(name) {
|
|
56
|
+
const typeId = this.typeIdsByName.get(name);
|
|
57
|
+
if (typeId === undefined)
|
|
58
|
+
return null;
|
|
59
|
+
return this.schemas.get(typeId) ?? null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { BackendPort, BackendRegistry, BackendValue } from "./backendRegistry.js";
|
|
2
|
+
/** Scalar backend storage is zero-initialized. Empty arrays have node-specific semantics. */
|
|
3
|
+
export declare function defaultScalar(port: BackendPort): BackendValue | null;
|
|
4
|
+
export type Edge = {
|
|
5
|
+
fromBid: string;
|
|
6
|
+
fromPort: number;
|
|
7
|
+
toBid: string;
|
|
8
|
+
toPort: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Backend node name → FlowIR scalar type (used by lift / writeParamData).
|
|
12
|
+
* Inverted form used by lower via {@link valueBackendName}.
|
|
13
|
+
*/
|
|
14
|
+
export declare const VALUE_BACKEND_NAMES: Record<string, string>;
|
|
15
|
+
/** FlowIR scalar type → backend node name (inverse of VALUE_BACKEND_NAMES). */
|
|
16
|
+
export declare function valueBackendName(typeName: string): string | undefined;
|
|
17
|
+
export declare function titleToAstName(title: string): string;
|
|
18
|
+
export declare function astNameToTitle(s: string): string;
|
|
19
|
+
export declare function isArrayPortType(type: string): boolean;
|
|
20
|
+
export declare function parseConnection(key: string): Edge | null;
|
|
21
|
+
export declare function buildIncomingMap(connections: Record<string, 0>): Map<string, Edge[]>;
|
|
22
|
+
/** Resolve the GIP and value-node type IDs from the backend registry. */
|
|
23
|
+
export declare function resolveParamTypeIds(backendRegistry: BackendRegistry): {
|
|
24
|
+
gipTypeId: number | null;
|
|
25
|
+
valueTypeIds: Map<number, string>;
|
|
26
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/** Scalar backend storage is zero-initialized. Empty arrays have node-specific semantics. */
|
|
2
|
+
export function defaultScalar(port) {
|
|
3
|
+
if (port.enumValues?.length || port.type === "Float" || port.type === "Int")
|
|
4
|
+
return 0;
|
|
5
|
+
if (port.type === "Bool")
|
|
6
|
+
return false;
|
|
7
|
+
if (port.type === "Vec" || port.type === "Vec3")
|
|
8
|
+
return { x: 0, y: 0, z: 0 };
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Backend node name → FlowIR scalar type (used by lift / writeParamData).
|
|
13
|
+
* Inverted form used by lower via {@link valueBackendName}.
|
|
14
|
+
*/
|
|
15
|
+
export const VALUE_BACKEND_NAMES = {
|
|
16
|
+
ValueFloat: "Float",
|
|
17
|
+
ValueInt: "Int",
|
|
18
|
+
ValueVec: "Vec3",
|
|
19
|
+
};
|
|
20
|
+
/** FlowIR scalar type → backend node name (inverse of VALUE_BACKEND_NAMES). */
|
|
21
|
+
export function valueBackendName(typeName) {
|
|
22
|
+
for (const [backend, type] of Object.entries(VALUE_BACKEND_NAMES)) {
|
|
23
|
+
if (type === typeName)
|
|
24
|
+
return backend;
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
export function titleToAstName(title) {
|
|
29
|
+
return title
|
|
30
|
+
.trim()
|
|
31
|
+
.replace(/\s+(.)/g, (_, c) => "_" + c.toLowerCase())
|
|
32
|
+
.replace(/^(.)/, (m) => m.toLowerCase());
|
|
33
|
+
}
|
|
34
|
+
export function astNameToTitle(s) {
|
|
35
|
+
return s
|
|
36
|
+
.replace(/_./g, (m) => " " + m[1].toUpperCase())
|
|
37
|
+
.replace(/^./, (m) => m.toUpperCase());
|
|
38
|
+
}
|
|
39
|
+
export function isArrayPortType(type) {
|
|
40
|
+
return type.endsWith("[]") || type.endsWith("Array");
|
|
41
|
+
}
|
|
42
|
+
export function parseConnection(key) {
|
|
43
|
+
const m = key.match(/^(\d+):(\d+)-(\d+):(\d+)$/);
|
|
44
|
+
if (!m)
|
|
45
|
+
return null;
|
|
46
|
+
return {
|
|
47
|
+
fromBid: m[1],
|
|
48
|
+
fromPort: Number(m[2]),
|
|
49
|
+
toBid: m[3],
|
|
50
|
+
toPort: Number(m[4]),
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
export function buildIncomingMap(connections) {
|
|
54
|
+
const incoming = new Map();
|
|
55
|
+
for (const key of Object.keys(connections)) {
|
|
56
|
+
const edge = parseConnection(key);
|
|
57
|
+
if (!edge)
|
|
58
|
+
continue;
|
|
59
|
+
let list = incoming.get(edge.toBid);
|
|
60
|
+
if (!list) {
|
|
61
|
+
list = [];
|
|
62
|
+
incoming.set(edge.toBid, list);
|
|
63
|
+
}
|
|
64
|
+
list.push(edge);
|
|
65
|
+
}
|
|
66
|
+
return incoming;
|
|
67
|
+
}
|
|
68
|
+
/** Resolve the GIP and value-node type IDs from the backend registry. */
|
|
69
|
+
export function resolveParamTypeIds(backendRegistry) {
|
|
70
|
+
const gipTypeId = backendRegistry.getSchemaByName("GroupInputParam")?.typeId ?? null;
|
|
71
|
+
const valueTypeIds = new Map();
|
|
72
|
+
for (const [backendName, typeName] of Object.entries(VALUE_BACKEND_NAMES)) {
|
|
73
|
+
const schema = backendRegistry.getSchemaByName(backendName);
|
|
74
|
+
if (schema)
|
|
75
|
+
valueTypeIds.set(schema.typeId, typeName);
|
|
76
|
+
}
|
|
77
|
+
return { gipTypeId, valueTypeIds };
|
|
78
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as flowir from "@womp/flowir";
|
|
2
|
+
import { BackendRegistry, type GraphExt } from "./backendRegistry.js";
|
|
3
|
+
import { type GeometryGraph, type StatementNodes } from "./graph.js";
|
|
4
|
+
export declare const backendRegistry: BackendRegistry;
|
|
5
|
+
export declare const flowirRegistry: flowir.Registry;
|
|
6
|
+
export declare function compileGeometry(source: string): {
|
|
7
|
+
program: flowir.AstProgram;
|
|
8
|
+
graph: GeometryGraph;
|
|
9
|
+
graphExt: GraphExt;
|
|
10
|
+
nodeIds: StatementNodes;
|
|
11
|
+
};
|
|
12
|
+
/** Refuse full replacement unless the editable representation retains the stored graph. */
|
|
13
|
+
export declare function readEditableGeometry(rawGraph: unknown, graphExt: GraphExt): {
|
|
14
|
+
program: flowir.AstProgram;
|
|
15
|
+
nodeIds: StatementNodes;
|
|
16
|
+
graph: {
|
|
17
|
+
nodes: Record<string, {
|
|
18
|
+
type_id: number;
|
|
19
|
+
}>;
|
|
20
|
+
connections: Record<string, 0>;
|
|
21
|
+
data: Record<string, {
|
|
22
|
+
inputs: Record<string, string | number | boolean | string[] | number[] | boolean[] | {
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
z: number;
|
|
26
|
+
} | {
|
|
27
|
+
x: number;
|
|
28
|
+
y: number;
|
|
29
|
+
z: number;
|
|
30
|
+
}[]>;
|
|
31
|
+
}>;
|
|
32
|
+
};
|
|
33
|
+
source: string;
|
|
34
|
+
};
|
|
35
|
+
export declare function migrateGraphExt(previous: GraphExt, oldIds: StatementNodes, compiled: ReturnType<typeof compileGeometry>): GraphExt;
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import * as flowir from "@womp/flowir";
|
|
2
|
+
import isEqual from "lodash/isEqual.js";
|
|
3
|
+
import { BackendRegistry } from "./backendRegistry.js";
|
|
4
|
+
import { defaultScalar, parseConnection } from "./common.js";
|
|
5
|
+
import { geometryGraphSchema, } from "./graph.js";
|
|
6
|
+
import { createGeoNodesRegistry } from "./index.js";
|
|
7
|
+
import { lift } from "./lift.js";
|
|
8
|
+
import { lower } from "./lower.js";
|
|
9
|
+
export const backendRegistry = BackendRegistry.fromBundledJson();
|
|
10
|
+
export const flowirRegistry = createGeoNodesRegistry();
|
|
11
|
+
export function compileGeometry(source) {
|
|
12
|
+
const parsed = flowir.parseIRText(source);
|
|
13
|
+
if (!parsed.ok)
|
|
14
|
+
throw new Error(parsed.diagnostics
|
|
15
|
+
.map((item) => `Line ${item.line}: ${item.message} ${item.hint}`)
|
|
16
|
+
.join("\n"));
|
|
17
|
+
const result = flowir.compileFromProgram(parsed.program, source, flowirRegistry);
|
|
18
|
+
if (!result.ok)
|
|
19
|
+
throw new Error(flowir.formatDiagnostics(result));
|
|
20
|
+
const compiled = lower(parsed.program, flowirRegistry, backendRegistry);
|
|
21
|
+
for (const statement of parsed.program.statements) {
|
|
22
|
+
const name = statement.kind === "node"
|
|
23
|
+
? statement.id
|
|
24
|
+
: statement.kind === "out"
|
|
25
|
+
? statement.outputName
|
|
26
|
+
: statement.name;
|
|
27
|
+
if (compiled.nodeIds[`${statement.kind}:${name}`] === undefined)
|
|
28
|
+
throw new Error(`The backend cannot lower ${statement.kind} ${name}. Use a supported node or literal input instead.`);
|
|
29
|
+
}
|
|
30
|
+
return { ...compiled, program: parsed.program };
|
|
31
|
+
}
|
|
32
|
+
function comparableGraph(graph, nodeIds) {
|
|
33
|
+
const roles = new Map(Object.entries(nodeIds).map(([role, id]) => [id, role]));
|
|
34
|
+
if (roles.size !== Object.keys(graph.nodes).length)
|
|
35
|
+
throw new Error("This graph contains nodes that FlowIR cannot preserve.");
|
|
36
|
+
const nodes = {};
|
|
37
|
+
for (const [id, node] of Object.entries(graph.nodes)) {
|
|
38
|
+
const role = roles.get(id);
|
|
39
|
+
if (!role)
|
|
40
|
+
throw new Error(`FlowIR cannot preserve node ${id}.`);
|
|
41
|
+
const schema = backendRegistry.getSchema(node.type_id);
|
|
42
|
+
const inputs = {};
|
|
43
|
+
for (const [portId, value] of Object.entries(graph.data[id]?.inputs ?? {})) {
|
|
44
|
+
const port = schema?.inputs[Number(portId)];
|
|
45
|
+
if (!port ||
|
|
46
|
+
schema?.name === "GroupInputParam" ||
|
|
47
|
+
!isEqual(value, defaultScalar(port)))
|
|
48
|
+
inputs[portId] = value;
|
|
49
|
+
}
|
|
50
|
+
nodes[role] = { typeId: node.type_id, inputs };
|
|
51
|
+
}
|
|
52
|
+
for (const id of Object.keys(graph.data)) {
|
|
53
|
+
if (!graph.nodes[id])
|
|
54
|
+
throw new Error(`Graph data refers to missing node ${id}.`);
|
|
55
|
+
}
|
|
56
|
+
const edges = Object.keys(graph.connections)
|
|
57
|
+
.map((key) => {
|
|
58
|
+
const edge = parseConnection(key);
|
|
59
|
+
if (!edge || !roles.has(edge.fromBid) || !roles.has(edge.toBid))
|
|
60
|
+
throw new Error(`FlowIR cannot preserve connection ${key}.`);
|
|
61
|
+
return `${roles.get(edge.fromBid)}:${edge.fromPort}-${roles.get(edge.toBid)}:${edge.toPort}`;
|
|
62
|
+
})
|
|
63
|
+
.sort();
|
|
64
|
+
return { nodes, edges };
|
|
65
|
+
}
|
|
66
|
+
/** Refuse full replacement unless the editable representation retains the stored graph. */
|
|
67
|
+
export function readEditableGeometry(rawGraph, graphExt) {
|
|
68
|
+
const graph = geometryGraphSchema.parse(rawGraph);
|
|
69
|
+
const lifted = lift(graph, graphExt, flowirRegistry, backendRegistry);
|
|
70
|
+
const source = flowir.programToIRText(lifted.program);
|
|
71
|
+
const rebuilt = compileGeometry(source);
|
|
72
|
+
if (!isEqual(comparableGraph(graph, lifted.nodeIds), comparableGraph(rebuilt.graph, rebuilt.nodeIds)))
|
|
73
|
+
throw new Error("This graph contains inputs or connections that FlowIR cannot preserve. Edit it in the graph editor instead of replacing it.");
|
|
74
|
+
return { graph, source, ...lifted };
|
|
75
|
+
}
|
|
76
|
+
export function migrateGraphExt(previous, oldIds, compiled) {
|
|
77
|
+
const nodes = {};
|
|
78
|
+
for (const [role, id] of Object.entries(compiled.nodeIds)) {
|
|
79
|
+
const oldId = oldIds[role];
|
|
80
|
+
nodes[id] = {
|
|
81
|
+
...compiled.graphExt.nodes[id],
|
|
82
|
+
...(oldId === undefined ? {} : previous.nodes[oldId]),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
// New nodes get a readable layout without invoking another open graph's UI callback.
|
|
86
|
+
const existingX = Object.values(nodes).flatMap((node) => node.position?.slice(0, 1) ?? []);
|
|
87
|
+
const startX = existingX.length ? Math.max(...existingX) + 350 : 0;
|
|
88
|
+
const depths = new Map();
|
|
89
|
+
for (const id of Object.keys(compiled.graph.nodes))
|
|
90
|
+
depths.set(id, 0);
|
|
91
|
+
const edges = Object.keys(compiled.graph.connections).map(parseConnection);
|
|
92
|
+
for (let pass = 0; pass < depths.size; pass++) {
|
|
93
|
+
let changed = false;
|
|
94
|
+
for (const edge of edges) {
|
|
95
|
+
if (!edge)
|
|
96
|
+
continue;
|
|
97
|
+
const depth = (depths.get(edge.fromBid) ?? 0) + 1;
|
|
98
|
+
if (depth > (depths.get(edge.toBid) ?? 0)) {
|
|
99
|
+
depths.set(edge.toBid, depth);
|
|
100
|
+
changed = true;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
if (!changed)
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
const rows = new Map();
|
|
107
|
+
for (const [id, depth] of depths) {
|
|
108
|
+
if (nodes[id]?.position)
|
|
109
|
+
continue;
|
|
110
|
+
const row = rows.get(depth) ?? 0;
|
|
111
|
+
nodes[id] = { ...nodes[id], position: [startX + depth * 350, row * 500] };
|
|
112
|
+
rows.set(depth, row + 1);
|
|
113
|
+
}
|
|
114
|
+
return { ...previous, nodes };
|
|
115
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const graphDataSchema: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
3
|
+
inputs: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodNumber, z.ZodBoolean, z.ZodString, z.ZodObject<{
|
|
4
|
+
x: z.ZodNumber;
|
|
5
|
+
y: z.ZodNumber;
|
|
6
|
+
z: z.ZodNumber;
|
|
7
|
+
}, z.core.$strict>, z.ZodArray<z.ZodNumber>, z.ZodArray<z.ZodBoolean>, z.ZodArray<z.ZodString>, z.ZodArray<z.ZodObject<{
|
|
8
|
+
x: z.ZodNumber;
|
|
9
|
+
y: z.ZodNumber;
|
|
10
|
+
z: z.ZodNumber;
|
|
11
|
+
}, z.core.$strict>>]>>;
|
|
12
|
+
}, z.core.$strict>>;
|
|
13
|
+
export declare const geometryGraphSchema: z.ZodObject<{
|
|
14
|
+
nodes: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
15
|
+
type_id: z.ZodNumber;
|
|
16
|
+
}, z.core.$strict>>;
|
|
17
|
+
connections: z.ZodRecord<z.ZodString, z.ZodLiteral<0>>;
|
|
18
|
+
data: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
19
|
+
inputs: z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodNumber, z.ZodBoolean, z.ZodString, z.ZodObject<{
|
|
20
|
+
x: z.ZodNumber;
|
|
21
|
+
y: z.ZodNumber;
|
|
22
|
+
z: z.ZodNumber;
|
|
23
|
+
}, z.core.$strict>, z.ZodArray<z.ZodNumber>, z.ZodArray<z.ZodBoolean>, z.ZodArray<z.ZodString>, z.ZodArray<z.ZodObject<{
|
|
24
|
+
x: z.ZodNumber;
|
|
25
|
+
y: z.ZodNumber;
|
|
26
|
+
z: z.ZodNumber;
|
|
27
|
+
}, z.core.$strict>>]>>;
|
|
28
|
+
}, z.core.$strict>>;
|
|
29
|
+
}, z.core.$strict>;
|
|
30
|
+
export declare const graphExtSchema: z.ZodObject<{
|
|
31
|
+
nodes: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
32
|
+
name: z.ZodOptional<z.ZodString>;
|
|
33
|
+
position: z.ZodOptional<z.ZodArray<z.ZodNumber>>;
|
|
34
|
+
}, z.core.$catchall<z.ZodJSONSchema>>>>;
|
|
35
|
+
}, z.core.$catchall<z.ZodJSONSchema>>;
|
|
36
|
+
export type GeometryGraph = z.infer<typeof geometryGraphSchema>;
|
|
37
|
+
export type GraphData = z.infer<typeof graphDataSchema>;
|
|
38
|
+
/** FlowIR statement roles map to backend IDs only for the current conversion. */
|
|
39
|
+
export type StatementNodes = Record<string, string>;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
const vec3 = z.object({ x: z.number(), y: z.number(), z: z.number() }).strict();
|
|
3
|
+
const value = z.union([
|
|
4
|
+
z.number(),
|
|
5
|
+
z.boolean(),
|
|
6
|
+
z.string(),
|
|
7
|
+
vec3,
|
|
8
|
+
z.array(z.number()),
|
|
9
|
+
z.array(z.boolean()),
|
|
10
|
+
z.array(z.string()),
|
|
11
|
+
z.array(vec3),
|
|
12
|
+
]);
|
|
13
|
+
export const graphDataSchema = z.record(z.string().regex(/^\d+$/), z.object({ inputs: z.record(z.string().regex(/^\d+$/), value) }).strict());
|
|
14
|
+
export const geometryGraphSchema = z
|
|
15
|
+
.object({
|
|
16
|
+
nodes: z.record(z.string().regex(/^\d+$/), z.object({ type_id: z.number().int().nonnegative() }).strict()),
|
|
17
|
+
connections: z.record(z.string().regex(/^\d+:\d+-\d+:\d+$/), z.literal(0)),
|
|
18
|
+
data: graphDataSchema,
|
|
19
|
+
})
|
|
20
|
+
.strict();
|
|
21
|
+
export const graphExtSchema = z
|
|
22
|
+
.object({
|
|
23
|
+
nodes: z
|
|
24
|
+
.record(z.string(), z
|
|
25
|
+
.object({
|
|
26
|
+
name: z.string().optional(),
|
|
27
|
+
position: z.array(z.number()).length(2).optional(),
|
|
28
|
+
})
|
|
29
|
+
.catchall(z.json()))
|
|
30
|
+
.default({}),
|
|
31
|
+
})
|
|
32
|
+
.catchall(z.json());
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import * as flowir from "@womp/flowir";
|
|
2
|
+
export { BackendRegistry } from "./backendRegistry.js";
|
|
3
|
+
export type { BackendValue, BackendNodeSchema, BackendPort, GraphExt, } from "./backendRegistry.js";
|
|
4
|
+
export { lower } from "./lower.js";
|
|
5
|
+
export type { LowerResult } from "./lower.js";
|
|
6
|
+
export { lift } from "./lift.js";
|
|
7
|
+
export { writeParamData } from "./writeParamData.js";
|
|
8
|
+
export declare function loadGeoNodesDialect(): flowir.DialectSchema;
|
|
9
|
+
export declare function createGeoNodesRegistry(): flowir.Registry;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as flowir from "@womp/flowir";
|
|
2
|
+
import dialectJson from "./schemas/flowir-dialect.json" with { type: "json" };
|
|
3
|
+
export { BackendRegistry } from "./backendRegistry.js";
|
|
4
|
+
export { lower } from "./lower.js";
|
|
5
|
+
export { lift } from "./lift.js";
|
|
6
|
+
export { writeParamData } from "./writeParamData.js";
|
|
7
|
+
export function loadGeoNodesDialect() {
|
|
8
|
+
return dialectJson;
|
|
9
|
+
}
|
|
10
|
+
export function createGeoNodesRegistry() {
|
|
11
|
+
return flowir.Registry.fromJsonObject(dialectJson);
|
|
12
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as flowir from "@womp/flowir";
|
|
2
|
+
import type { GeometryGraph, StatementNodes } from "./graph.js";
|
|
3
|
+
import type { BackendRegistry, GraphExt } from "./backendRegistry.js";
|
|
4
|
+
export declare function lift(graph: GeometryGraph, graphExt: GraphExt, flowirRegistry: flowir.Registry, backendRegistry: BackendRegistry): {
|
|
5
|
+
program: flowir.AstProgram;
|
|
6
|
+
nodeIds: StatementNodes;
|
|
7
|
+
};
|