@womp/spark-agent 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (113) hide show
  1. package/.env.example +4 -0
  2. package/README.md +295 -49
  3. package/dist/agent-tools.d.ts +30 -0
  4. package/dist/agent-tools.js +189 -0
  5. package/dist/agent.d.ts +34 -7
  6. package/dist/agent.js +223 -158
  7. package/dist/browser.d.ts +2 -0
  8. package/dist/browser.js +2 -0
  9. package/dist/capabilities/account.d.ts +216 -0
  10. package/dist/capabilities/account.js +63 -0
  11. package/dist/capabilities/asset-imports.d.ts +55 -0
  12. package/dist/capabilities/asset-imports.js +117 -0
  13. package/dist/capabilities/assets.d.ts +29 -0
  14. package/dist/capabilities/assets.js +48 -0
  15. package/dist/capabilities/flow.d.ts +29 -0
  16. package/dist/capabilities/flow.js +52 -0
  17. package/dist/capabilities/geometry.d.ts +48 -0
  18. package/dist/capabilities/geometry.js +51 -0
  19. package/dist/capabilities/knowledge.d.ts +11 -0
  20. package/dist/capabilities/knowledge.js +23 -0
  21. package/dist/capabilities/openscad-instructions.d.ts +1 -0
  22. package/dist/capabilities/openscad-instructions.js +81 -0
  23. package/dist/capabilities/openscad.d.ts +54 -0
  24. package/dist/capabilities/openscad.js +34 -0
  25. package/dist/capabilities/operations.d.ts +104 -0
  26. package/dist/capabilities/operations.js +145 -0
  27. package/dist/capabilities/scene-draft.d.ts +404 -0
  28. package/dist/capabilities/scene-draft.js +1 -0
  29. package/dist/capabilities/scene.d.ts +28 -0
  30. package/dist/capabilities/scene.js +51 -0
  31. package/dist/capabilities.d.ts +67 -0
  32. package/dist/capabilities.js +25 -0
  33. package/dist/cli.d.ts +2 -0
  34. package/dist/cli.js +24 -0
  35. package/dist/client.d.ts +43 -0
  36. package/dist/client.js +159 -0
  37. package/dist/context.d.ts +15 -0
  38. package/dist/context.js +264 -0
  39. package/dist/execution-lifetime.d.ts +32 -0
  40. package/dist/execution-lifetime.js +113 -0
  41. package/dist/executor.d.ts +6 -1
  42. package/dist/generated/account-declarations.d.ts +1 -0
  43. package/dist/generated/account-declarations.js +3 -0
  44. package/dist/generated/asset-import-declarations.d.ts +1 -0
  45. package/dist/generated/asset-import-declarations.js +3 -0
  46. package/dist/generated/assets-declarations.d.ts +1 -0
  47. package/dist/generated/assets-declarations.js +3 -0
  48. package/dist/generated/flow-declarations.d.ts +1 -0
  49. package/dist/generated/flow-declarations.js +3 -0
  50. package/dist/generated/geometry-declarations.d.ts +1 -0
  51. package/dist/generated/geometry-declarations.js +3 -0
  52. package/dist/generated/kakapo-declarations.d.ts +1 -0
  53. package/dist/generated/kakapo-declarations.js +3 -0
  54. package/dist/generated/knowledge-declarations.d.ts +1 -0
  55. package/dist/generated/knowledge-declarations.js +3 -0
  56. package/dist/generated/openscad-declarations.d.ts +1 -0
  57. package/dist/generated/openscad-declarations.js +3 -0
  58. package/dist/generated/operations-declarations.d.ts +1 -0
  59. package/dist/generated/operations-declarations.js +3 -0
  60. package/dist/generated/scene-declarations.d.ts +1 -0
  61. package/dist/generated/scene-declarations.js +3 -0
  62. package/dist/index.d.ts +7 -6
  63. package/dist/index.js +5 -3
  64. package/dist/kakapo-capability-api.d.ts +18 -0
  65. package/dist/kakapo-capability-api.js +1 -0
  66. package/dist/kakapo-capability.d.ts +6 -0
  67. package/dist/kakapo-capability.js +50 -0
  68. package/dist/kakapo-scene-skill.d.ts +1 -0
  69. package/dist/kakapo-scene-skill.js +54 -0
  70. package/dist/kakapo.d.ts +5 -0
  71. package/dist/kakapo.js +3 -0
  72. package/dist/local-transport.d.ts +11 -0
  73. package/dist/local-transport.js +15 -0
  74. package/dist/model-history.d.ts +5 -0
  75. package/dist/model-history.js +34 -0
  76. package/dist/model-options.d.ts +4 -0
  77. package/dist/model-options.js +25 -0
  78. package/dist/models.d.ts +3 -15
  79. package/dist/models.js +2 -16
  80. package/dist/native-executor.d.ts +5 -0
  81. package/dist/native-executor.js +92 -0
  82. package/dist/pricing.d.ts +3 -0
  83. package/dist/pricing.js +70 -0
  84. package/dist/prompt.d.ts +1 -1
  85. package/dist/prompt.js +19 -209
  86. package/dist/quickjs-executor.d.ts +13 -0
  87. package/dist/quickjs-executor.js +309 -0
  88. package/dist/runtime.d.ts +16 -5
  89. package/dist/runtime.js +61 -10
  90. package/dist/server/artifacts.d.ts +17 -0
  91. package/dist/server/artifacts.js +36 -0
  92. package/dist/server/demo-account.d.ts +3 -0
  93. package/dist/server/demo-account.js +38 -0
  94. package/dist/server/executor.d.ts +17 -0
  95. package/dist/server/executor.js +35 -0
  96. package/dist/server/express.d.ts +13 -0
  97. package/dist/server/express.js +159 -0
  98. package/dist/server/index.d.ts +8 -0
  99. package/dist/server/index.js +5 -0
  100. package/dist/server/service.d.ts +41 -0
  101. package/dist/server/service.js +402 -0
  102. package/dist/server/standalone.d.ts +9 -0
  103. package/dist/server/standalone.js +85 -0
  104. package/dist/server/store.d.ts +16 -0
  105. package/dist/server/store.js +70 -0
  106. package/dist/server/types.d.ts +53 -0
  107. package/dist/server/types.js +1 -0
  108. package/dist/types.d.ts +3 -27
  109. package/dist/ui.d.ts +224 -0
  110. package/dist/ui.js +71 -0
  111. package/dist/womp-scene-api.d.ts +195 -3
  112. package/dist/womp-scene-api.js +102 -73
  113. package/package.json +66 -10
@@ -0,0 +1,54 @@
1
+ import type { SparkCapability, SparkInvocationContext } from "../capabilities.js";
2
+ export type OpenScadTarget = {
3
+ kind: "part" | "container";
4
+ objectId: number;
5
+ parentId: number;
6
+ title: string;
7
+ source: string | null;
8
+ params: Record<string, unknown>;
9
+ revision: string;
10
+ };
11
+ export type OpenScadSource = {
12
+ source: string;
13
+ title: string;
14
+ params?: Record<string, unknown>;
15
+ expectedRevision: string;
16
+ };
17
+ export type OpenScadCreate = OpenScadSource & {
18
+ parentId: number;
19
+ };
20
+ export type OpenScadUpdate = OpenScadSource & {
21
+ objectId: number;
22
+ };
23
+ export type OpenScadValidation = {
24
+ status: "valid" | "invalid" | "unavailable";
25
+ error?: string;
26
+ warnings: string[];
27
+ };
28
+ export type OpenScadPrintability = {
29
+ status: "passed" | "failed" | "unavailable";
30
+ objectIds: number[];
31
+ maxThinPercentage: number;
32
+ thinPercentage?: number;
33
+ reason?: string;
34
+ };
35
+ export type OpenScadWriteResult = {
36
+ status: "applied" | "rejected";
37
+ objectId?: number;
38
+ revision: string;
39
+ validation: OpenScadValidation;
40
+ printability?: OpenScadPrintability;
41
+ repairAttempts: number;
42
+ repairLimit: number;
43
+ };
44
+ export type WompOpenScadApi = {
45
+ read(objectId: number): Promise<OpenScadTarget>;
46
+ create(options: OpenScadCreate): Promise<OpenScadWriteResult>;
47
+ update(options: OpenScadUpdate): Promise<OpenScadWriteResult>;
48
+ };
49
+ export interface OpenScadHost {
50
+ read(objectId: number, context: SparkInvocationContext): Promise<OpenScadTarget>;
51
+ create(options: OpenScadCreate, context: SparkInvocationContext): Promise<OpenScadWriteResult>;
52
+ update(options: OpenScadUpdate, context: SparkInvocationContext): Promise<OpenScadWriteResult>;
53
+ }
54
+ export declare function createOpenScadCapability(host: OpenScadHost): SparkCapability<WompOpenScadApi>;
@@ -0,0 +1,34 @@
1
+ import { z } from "zod";
2
+ import { WOMP_OPENSCAD_DECLARATIONS } from "../generated/openscad-declarations.js";
3
+ import { OPENSCAD_INSTRUCTIONS } from "./openscad-instructions.js";
4
+ const nodeId = z.number().int().nonnegative();
5
+ const source = z.object({
6
+ source: z.string().trim().min(1),
7
+ title: z.string().trim().min(1),
8
+ params: z.record(z.string(), z.json()).optional(),
9
+ expectedRevision: z.string().min(1),
10
+ });
11
+ const create = source.extend({ parentId: nodeId }).strict();
12
+ const update = source.extend({ objectId: nodeId.positive() }).strict();
13
+ export function createOpenScadCapability(host) {
14
+ return {
15
+ skills: [
16
+ {
17
+ name: "parametric-parts",
18
+ version: "3",
19
+ description: "Create and edit adjustable mechanical, measured, and hard-surface OpenSCAD parts; compile them and check wall thickness.",
20
+ instructions: OPENSCAD_INSTRUCTIONS,
21
+ declarations: WOMP_OPENSCAD_DECLARATIONS,
22
+ examples: [
23
+ "const part = await womp.openscad.read(objectId); print(part);",
24
+ "const part = await womp.openscad.read(objectId); print(await womp.openscad.update({ objectId: part.objectId, source: part.source, title: part.title, params: { width: 30 }, expectedRevision: part.revision }));",
25
+ ],
26
+ },
27
+ ],
28
+ createApi: (context) => ({
29
+ read: (objectId) => host.read(nodeId.parse(objectId), context),
30
+ create: (options) => host.create(create.parse(options), context),
31
+ update: (options) => host.update(update.parse(options), context),
32
+ }),
33
+ };
34
+ }
@@ -0,0 +1,104 @@
1
+ import type { ArtifactRef, SparkCapability, SparkInvocationContext } from "../capabilities.js";
2
+ export type OperationType = "text-to-image" | "image-to-image" | "text-to-mesh" | "image-to-mesh" | "upscale-image" | "remove-image-background";
3
+ export type OperationModel = {
4
+ id: string;
5
+ name: string;
6
+ description?: string;
7
+ requiresSubscription: boolean;
8
+ operations: OperationType[];
9
+ };
10
+ export type OperationCatalog = {
11
+ models: OperationModel[];
12
+ defaults: {
13
+ image?: string;
14
+ editing?: string;
15
+ mesh?: string;
16
+ };
17
+ confirmationRequired: boolean;
18
+ };
19
+ export type OperationRequest = {
20
+ key: string;
21
+ } & ({
22
+ type: "text-to-image";
23
+ prompt: string;
24
+ pipeline?: string;
25
+ params?: Record<string, unknown>;
26
+ } | {
27
+ type: "image-to-image";
28
+ inputs: ArtifactRef[];
29
+ prompt?: string;
30
+ pipeline?: string;
31
+ params?: Record<string, unknown>;
32
+ } | {
33
+ type: "text-to-mesh";
34
+ prompt: string;
35
+ pipeline?: string;
36
+ workflow?: string;
37
+ imageParams?: Record<string, unknown>;
38
+ params?: Record<string, unknown>;
39
+ } | {
40
+ type: "image-to-mesh";
41
+ inputs: ArtifactRef[];
42
+ prompt?: string;
43
+ pipeline?: string;
44
+ workflow?: string;
45
+ imageParams?: Record<string, unknown>;
46
+ params?: Record<string, unknown>;
47
+ } | {
48
+ type: "upscale-image";
49
+ inputs: ArtifactRef[];
50
+ scale?: number;
51
+ modelName?: string;
52
+ } | {
53
+ type: "remove-image-background";
54
+ inputs: ArtifactRef[];
55
+ });
56
+ export type OperationJob = {
57
+ messageId: number;
58
+ operationId?: number;
59
+ type: OperationType;
60
+ status: "submitted" | "not_ready" | "queued" | "running" | "waiting_for_capacity" | "completed" | "cancelled" | "failed";
61
+ outputs: ArtifactRef[];
62
+ error?: string;
63
+ };
64
+ export type OperationStartResult = {
65
+ status: "started";
66
+ job: OperationJob;
67
+ } | {
68
+ status: "cancelled";
69
+ reason: string;
70
+ } | {
71
+ status: "unknown";
72
+ key: string;
73
+ reason: string;
74
+ };
75
+ export type OperationWaitOptions = {
76
+ timeoutMs?: number;
77
+ };
78
+ export type OperationWaitResult = {
79
+ job: OperationJob;
80
+ timedOut: boolean;
81
+ };
82
+ export type OperationListOptions = {
83
+ from?: number;
84
+ count?: number;
85
+ };
86
+ export type OperationPage = {
87
+ jobs: OperationJob[];
88
+ nextFrom: number | null;
89
+ };
90
+ export type WompOperationsApi = {
91
+ catalog(): Promise<OperationCatalog>;
92
+ list(options?: OperationListOptions): Promise<OperationPage>;
93
+ start(request: OperationRequest): Promise<OperationStartResult>;
94
+ read(messageId: number): Promise<OperationJob>;
95
+ wait(messageId: number, options?: OperationWaitOptions): Promise<OperationWaitResult>;
96
+ };
97
+ export interface OperationsHost {
98
+ catalog(context: SparkInvocationContext): Promise<OperationCatalog>;
99
+ list(options: Required<OperationListOptions>, context: SparkInvocationContext): Promise<OperationPage>;
100
+ start(request: OperationRequest, context: SparkInvocationContext): Promise<OperationStartResult>;
101
+ read(messageId: number, context: SparkInvocationContext): Promise<OperationJob>;
102
+ wait(messageId: number, options: Required<OperationWaitOptions>, context: SparkInvocationContext): Promise<OperationWaitResult>;
103
+ }
104
+ export declare function createOperationsCapability(host: OperationsHost): SparkCapability<WompOperationsApi>;
@@ -0,0 +1,145 @@
1
+ import { z } from "zod";
2
+ import { WOMP_OPERATIONS_DECLARATIONS } from "../generated/operations-declarations.js";
3
+ const key = z.string().trim().min(1).max(120);
4
+ const model = z.string().trim().min(1).max(120).optional();
5
+ const prompt = z.string().max(20_000);
6
+ const params = z.record(z.string(), z.json()).optional();
7
+ const input = z
8
+ .object({
9
+ id: z.string().min(1),
10
+ mediaType: z.string().startsWith("image/"),
11
+ name: z.string().optional(),
12
+ })
13
+ .strict();
14
+ const inputs = z.array(input).min(1).max(16);
15
+ const requestSchema = z.discriminatedUnion("type", [
16
+ z
17
+ .object({
18
+ key,
19
+ type: z.literal("text-to-image"),
20
+ prompt: prompt.trim().min(1),
21
+ pipeline: model,
22
+ params,
23
+ })
24
+ .strict(),
25
+ z
26
+ .object({
27
+ key,
28
+ type: z.literal("image-to-image"),
29
+ inputs,
30
+ prompt: prompt.optional(),
31
+ pipeline: model,
32
+ params,
33
+ })
34
+ .strict(),
35
+ z
36
+ .object({
37
+ key,
38
+ type: z.literal("text-to-mesh"),
39
+ prompt: prompt.trim().min(1),
40
+ pipeline: model,
41
+ workflow: model,
42
+ imageParams: params,
43
+ params,
44
+ })
45
+ .strict(),
46
+ z
47
+ .object({
48
+ key,
49
+ type: z.literal("image-to-mesh"),
50
+ inputs,
51
+ prompt: prompt.optional(),
52
+ pipeline: model,
53
+ workflow: model,
54
+ imageParams: params,
55
+ params,
56
+ })
57
+ .strict(),
58
+ z
59
+ .object({
60
+ key,
61
+ type: z.literal("upscale-image"),
62
+ inputs: inputs.max(1),
63
+ scale: z.number().positive().max(8).optional(),
64
+ modelName: model,
65
+ })
66
+ .strict(),
67
+ z.object({ key, type: z.literal("remove-image-background"), inputs: inputs.max(1) }).strict(),
68
+ ]);
69
+ const messageIdSchema = z.number().int().positive();
70
+ const listSchema = z
71
+ .object({
72
+ from: z.number().int().nonnegative().default(0),
73
+ count: z.number().int().min(1).max(50).default(20),
74
+ })
75
+ .strict();
76
+ const waitSchema = z
77
+ .object({ timeoutMs: z.number().int().min(1).max(30_000).default(15_000) })
78
+ .strict();
79
+ export function createOperationsCapability(host) {
80
+ return {
81
+ skills: [
82
+ {
83
+ name: "generation",
84
+ version: "4",
85
+ description: "Generate or edit images and meshes, inspect jobs, and wait for their outputs.",
86
+ instructions: `Read operations.catalog() for the currently available models and selected defaults.
87
+ Use generation for inline chat results. If the user is working in their Flow graph and flow-graphs is available,
88
+ add the generation to that graph instead unless they request an inline result. When they want repeated variations,
89
+ offer a reusable Flow workflow if available; accepting that offer means editing the graph, not submitting another inline job.
90
+ Use start() for image/mesh generation, image editing, upscaling, or background removal. Model IDs must
91
+ come from the catalog and support the requested operation. An unavailable or restricted explicit choice
92
+ is an error; do not silently substitute another model. Omit model IDs to use the user's defaults.
93
+ For text-to-mesh, imageParams configures the image step and params configures the mesh step. For
94
+ image-to-mesh, an optional prompt requests an image-editing step first. Advanced params are JSON
95
+ values passed to the existing service; use documented options and do not invent provider settings.
96
+ Author the full text-to-mesh image prompt yourself, preserving the user's requested subject and details.
97
+ For a standalone object, describe a clear three-quarter view with a plain background and even lighting
98
+ unless the user requests otherwise. Do not rely on another model to expand or rewrite this prompt.
99
+ Inputs are image references returned by the available assets API or a previous completed operation.
100
+ Do not fabricate references, replace a missing input with another image, or pass arbitrary URLs.
101
+ Assign a short, distinct key to each intended job. Reuse that key when checking the same submission;
102
+ never choose a new key merely to retry a timeout or unknown outcome. A key cannot identify two
103
+ different requests. Host receipts and saved message IDs record submitted effects.
104
+ start() may wait for the user's existing cost confirmation. Dismissal is cancelled and must not be
105
+ automatically retried. A returned job is submitted work, not a completed generation. Use read() or
106
+ bounded wait() to inspect it. Use list() to discover existing jobs in this conversation. Follow nextFrom
107
+ even when a page has no jobs, since pagination scans conversation messages. A wait timeout leaves the
108
+ existing job running; do not submit a replacement. Make at most one bounded wait (timeoutMs <= 30000)
109
+ per execute_javascript call, print its result, and return. If more waiting is needed, use another tool
110
+ step. Do not loop over waits inside one script or exceed the limit; service waits consume execution time.
111
+ Only returned outputs exist. Emit images/files to inspect or show them; generating a mesh does not
112
+ import it into the scene. Use the assets skill for importing. Stopping the agent ends its wait and
113
+ prevents further submissions; it does not claim to cancel a job already accepted by the service.`,
114
+ declarations: WOMP_OPERATIONS_DECLARATIONS,
115
+ examples: [
116
+ "print(await womp.operations.catalog());",
117
+ 'const result = await womp.operations.start({ key: "blue-chair-preview", type: "text-to-image", prompt: "A blue chair on a plain background" }); print(result);',
118
+ 'const result = await womp.operations.wait(123, { timeoutMs: 15000 }); print(result); for (const output of result.job.outputs) { if (output.mediaType.startsWith("image/")) await emitImage(output); }',
119
+ ],
120
+ },
121
+ ],
122
+ createApi: (context) => ({
123
+ catalog: () => {
124
+ context.signal.throwIfAborted();
125
+ return host.catalog(context);
126
+ },
127
+ list: (options) => {
128
+ context.signal.throwIfAborted();
129
+ return host.list(listSchema.parse(options ?? {}), context);
130
+ },
131
+ start: (request) => {
132
+ context.signal.throwIfAborted();
133
+ return host.start(requestSchema.parse(request), context);
134
+ },
135
+ read: (messageId) => {
136
+ context.signal.throwIfAborted();
137
+ return host.read(messageIdSchema.parse(messageId), context);
138
+ },
139
+ wait: (messageId, options) => {
140
+ context.signal.throwIfAborted();
141
+ return host.wait(messageIdSchema.parse(messageId), waitSchema.parse(options ?? {}), context);
142
+ },
143
+ }),
144
+ };
145
+ }