@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
package/dist/agent.js CHANGED
@@ -1,168 +1,233 @@
1
- import { stepCountIs, streamText, tool } from "ai";
2
- import { z } from "zod";
3
- import { resolveReasoningEffort } from "./models.js";
1
+ import { createUIMessageStream, stepCountIs, streamText, } from "ai";
2
+ import { createSparkTools } from "./agent-tools.js";
4
3
  import { SPARK_AGENT_PROMPT } from "./prompt.js";
5
- export async function runSparkAgent(options) {
6
- const { input, model, modelId, provider, runtime } = options;
7
- const onEvent = (event) => runtime.emit(event);
8
- try {
9
- await runtime.connect();
10
- const reasoningEffort = resolveReasoningEffort(modelId, input.reasoningEffort);
11
- const content = [{
12
- type: "text",
13
- text: [
14
- ...input.context.slice(-8).map(({ role, content: text }) => `${role === "user" ? "Previous user" : "Previous Spark"}: ${text.slice(0, 2_000)}`),
15
- `Current request: ${input.prompt}`,
16
- ].join("\n"),
17
- }];
18
- for (const image of input.images) {
19
- content.push({
20
- type: "file",
21
- data: { type: "data", data: image.data },
22
- mediaType: image.mediaType,
23
- filename: image.name,
24
- ...(provider === "openai"
25
- ? { providerOptions: { openai: { imageDetail: "high" } } }
26
- : {}),
27
- });
28
- }
29
- const pendingScreenshots = [];
30
- const runAbort = new AbortController();
31
- const stopOnDisconnect = (value, message) => {
32
- if (runtime.connected)
33
- return value;
34
- const error = new Error(message);
35
- runAbort.abort(error);
36
- throw error;
37
- };
38
- const executeJavaScript = tool({
39
- description: "Execute one atomic JavaScript transaction against Spark's Womp-style scene API. Scene functions and enums are globals; there is no kakapo object.",
40
- inputSchema: z.object({
41
- purpose: z.string().min(1).max(240),
42
- code: z.string().min(1).max(60_000),
43
- }),
44
- execute: async ({ code, purpose }) => {
45
- const output = await runtime.execute(code, purpose);
46
- return stopOnDisconnect(output, output.error ?? "Kakapo disconnected while committing the scene transaction.");
47
- },
48
- toModelOutput: ({ output }) => ({
49
- type: "content",
50
- value: [{
51
- type: "text",
52
- text: JSON.stringify({
53
- ok: output.ok,
54
- purpose: output.purpose,
55
- value: output.value,
56
- logs: output.logs,
57
- sdkCalls: output.sdkCalls,
58
- error: output.error,
59
- rolledBack: output.rolledBack,
60
- }),
61
- }],
62
- }),
4
+ import { calculateStepCost } from "./pricing.js";
5
+ import { prepareSparkContext, SparkContextLimitError } from "./context.js";
6
+ function errorMessage(error) {
7
+ return error instanceof Error ? error.message : String(error);
8
+ }
9
+ export function runSparkAgent(options) {
10
+ const maxSteps = options.maxSteps ?? 100;
11
+ if (Number.isInteger(maxSteps) === false || maxSteps < 1) {
12
+ throw new Error("maxSteps must be a positive integer.");
13
+ }
14
+ const startedAt = Date.now();
15
+ const controller = new AbortController();
16
+ const onAbort = () => controller.abort(options.signal?.reason);
17
+ options.signal?.addEventListener("abort", onAbort, { once: true });
18
+ if (options.signal?.aborted)
19
+ onAbort();
20
+ let resolveResult;
21
+ let rejectResult;
22
+ const result = new Promise((resolve, reject) => {
23
+ resolveResult = resolve;
24
+ rejectResult = reject;
25
+ });
26
+ // Hosts may drain the stream before awaiting the result.
27
+ void result.catch(() => undefined);
28
+ let completedResult;
29
+ let savedSteps = 0;
30
+ const checkpoints = new Map();
31
+ const checkpoint = (step) => {
32
+ let entry = checkpoints.get(step);
33
+ if (entry !== undefined)
34
+ return entry;
35
+ let resolve;
36
+ let reject;
37
+ const promise = new Promise((ok, fail) => {
38
+ resolve = ok;
39
+ reject = fail;
63
40
  });
64
- const screenshot = tool({
65
- description: "Capture Kakapo's native renderer. Omit targetId to frame the whole visible scene; child targets are framed through their owning top-level Area. Inspect the image before finishing.",
66
- inputSchema: z.object({
67
- targetId: z.number().int().optional(),
68
- view: z.enum(["front", "back", "left", "right", "top", "bottom", "isometric"]).default("isometric"),
41
+ void promise.catch(() => undefined);
42
+ entry = { promise, resolve, reject };
43
+ checkpoints.set(step, entry);
44
+ return entry;
45
+ };
46
+ controller.signal.addEventListener("abort", () => {
47
+ for (const entry of checkpoints.values())
48
+ entry.reject(controller.signal.reason);
49
+ }, { once: true });
50
+ const metadata = (status, usage) => ({
51
+ createdAt: new Date(startedAt).toISOString(),
52
+ runId: options.runId,
53
+ runStatus: status,
54
+ modelId: options.modelId,
55
+ ...(status === "running"
56
+ ? {}
57
+ : {
58
+ completedAt: new Date().toISOString(),
59
+ durationMs: Date.now() - startedAt,
69
60
  }),
70
- execute: async ({ targetId, view }, { toolCallId }) => {
71
- const image = await runtime.screenshot({ targetId, view });
72
- pendingScreenshots.push({ callId: toolCallId, screenshot: image });
73
- return stopOnDisconnect(image, "Kakapo disconnected while capturing the screenshot.");
61
+ ...(usage === undefined ? {} : { usage }),
62
+ });
63
+ const stream = createUIMessageStream({
64
+ generateId: () => options.messageId,
65
+ onError: errorMessage,
66
+ onStepEnd: options.persistence?.saveMessage === undefined
67
+ ? undefined
68
+ : async ({ responseMessage }) => {
69
+ const barrier = checkpoint(savedSteps++);
70
+ try {
71
+ await options.persistence?.saveMessage?.(responseMessage);
72
+ barrier.resolve();
73
+ }
74
+ catch (error) {
75
+ barrier.reject(error);
76
+ controller.abort(error);
77
+ throw error;
78
+ }
74
79
  },
75
- toModelOutput: ({ output }) => ({
76
- type: "content",
77
- value: [
78
- {
79
- type: "text",
80
- text: JSON.stringify({
81
- view: output.view,
82
- targetId: output.targetId,
83
- width: output.width,
84
- height: output.height,
85
- }),
80
+ onEnd: async ({ responseMessage }) => {
81
+ try {
82
+ await options.persistence?.saveMessage?.(responseMessage);
83
+ if (completedResult !== undefined)
84
+ resolveResult(completedResult);
85
+ }
86
+ catch (error) {
87
+ rejectResult(error);
88
+ throw error;
89
+ }
90
+ },
91
+ execute: async ({ writer }) => {
92
+ let generationError;
93
+ let stepCount = 0;
94
+ let readUsage;
95
+ try {
96
+ controller.signal.throwIfAborted();
97
+ const tools = createSparkTools({
98
+ ...options,
99
+ controller,
100
+ write: (chunk) => writer.write(chunk),
101
+ });
102
+ const readSystem = () => [
103
+ options.instructions ?? SPARK_AGENT_PROMPT,
104
+ options.context,
105
+ "Available skills (read before using their APIs):",
106
+ ...options.capabilities.skills.map(({ name, version, description }) => `- ${name} (${version}): ${description}`),
107
+ ]
108
+ .filter(Boolean)
109
+ .join("\n\n");
110
+ const generation = streamText({
111
+ model: options.model,
112
+ system: readSystem(),
113
+ messages: options.messages,
114
+ tools,
115
+ toolChoice: "auto",
116
+ abortSignal: controller.signal,
117
+ stopWhen: stepCountIs(maxSteps),
118
+ maxOutputTokens: options.maxOutputTokens,
119
+ providerOptions: options.providerOptions,
120
+ prepareStep: async ({ messages }) => {
121
+ controller.signal.throwIfAborted();
122
+ const prepared = options.prepareMessages === undefined
123
+ ? messages
124
+ : await options.prepareMessages(messages);
125
+ controller.signal.throwIfAborted();
126
+ const system = readSystem();
127
+ return {
128
+ system,
129
+ messages: prepareSparkContext(prepared, system, {
130
+ maxInputTokens: options.maxInputTokens ?? 64_000,
131
+ }),
132
+ };
86
133
  },
87
- {
88
- type: "file",
89
- data: { type: "data", data: output.data },
90
- mediaType: output.mediaType,
91
- filename: `spark-${output.view}.jpg`,
92
- ...(provider === "openai"
93
- ? { providerOptions: { openai: { imageDetail: "high" } } }
94
- : {}),
134
+ onError: ({ error }) => {
135
+ generationError = error;
136
+ },
137
+ onStepEnd: async (step) => {
138
+ stepCount++;
139
+ writer.write({
140
+ type: "data-step-metrics",
141
+ id: `step-${step.stepNumber}`,
142
+ data: {
143
+ step: step.stepNumber,
144
+ toolNames: step.toolCalls.map(({ toolName }) => toolName),
145
+ responseTimeMs: step.performance.responseTimeMs,
146
+ cost: calculateStepCost(options.modelId, step.usage),
147
+ },
148
+ });
149
+ if (options.persistence?.saveMessage !== undefined) {
150
+ // AI SDK forwards finish-step before invoking this callback.
151
+ // Join the corresponding UI checkpoint explicitly: observing
152
+ // stream events alone must never authorize the next model call.
153
+ controller.signal.throwIfAborted();
154
+ await checkpoint(step.stepNumber).promise;
155
+ checkpoints.delete(step.stepNumber);
156
+ controller.signal.throwIfAborted();
157
+ }
95
158
  },
96
- ],
97
- }),
98
- });
99
- const result = streamText({
100
- model,
101
- system: SPARK_AGENT_PROMPT,
102
- messages: [{ role: "user", content }],
103
- tools: { executeJavaScript, screenshot },
104
- toolChoice: "auto",
105
- abortSignal: runAbort.signal,
106
- stopWhen: stepCountIs(256),
107
- maxOutputTokens: 48_000,
108
- onChunk: ({ chunk }) => {
109
- if (chunk.type === "text-delta")
110
- onEvent({ type: "text-delta", text: chunk.text });
111
- },
112
- onStepEnd: (step) => {
113
- onEvent({
114
- type: "step",
115
- step: step.stepNumber,
116
- toolNames: step.toolCalls.map(({ toolName }) => toolName),
117
- reasoningSummary: step.reasoningText,
118
- responseTimeMs: step.performance.responseTimeMs,
119
159
  });
120
- for (const pending of pendingScreenshots.splice(0)) {
121
- onEvent({
122
- type: "tool-call",
123
- callId: pending.callId,
124
- toolName: "screenshot",
125
- label: "Capture native screenshot",
126
- input: { targetId: pending.screenshot.targetId, view: pending.screenshot.view },
127
- });
128
- onEvent({
129
- type: "screenshot",
130
- callId: pending.callId,
131
- data: pending.screenshot.data,
132
- mediaType: pending.screenshot.mediaType,
133
- view: pending.screenshot.view,
134
- targetId: pending.screenshot.targetId,
135
- });
136
- }
137
- },
138
- providerOptions: provider === "anthropic"
139
- ? {
140
- anthropic: {
141
- effort: reasoningEffort,
142
- thinking: { type: "adaptive", display: "summarized" },
143
- disableParallelToolUse: true,
160
+ readUsage = () => generation.totalUsage;
161
+ writer.merge(generation
162
+ .toUIMessageStream({
163
+ generateMessageId: () => options.messageId,
164
+ onError: (error) => {
165
+ // Record the error before its UI chunk reaches the filter below;
166
+ // streamText's onError callback may run later on another stream branch.
167
+ generationError = error;
168
+ return errorMessage(error);
144
169
  },
145
- }
146
- : {
147
- openai: {
148
- reasoningEffort,
149
- reasoningSummary: "auto",
150
- parallelToolCalls: false,
151
- store: false,
170
+ sendReasoning: true,
171
+ messageMetadata: ({ part }) => {
172
+ if (part.type === "start")
173
+ return metadata("running");
174
+ if (part.type === "finish") {
175
+ const completed = part.finishReason === "stop";
176
+ return metadata(completed ? "completed" : "incomplete", part.totalUsage);
177
+ }
178
+ return undefined;
152
179
  },
153
- },
154
- });
155
- const [text, steps, usage] = await Promise.all([
156
- result.text,
157
- result.steps,
158
- result.totalUsage,
159
- ]);
160
- onEvent({ type: "result", text, steps: steps.length, usage });
161
- }
162
- catch (error) {
163
- onEvent({ type: "error", message: error instanceof Error ? error.message : String(error) });
164
- }
165
- finally {
166
- runtime.disconnect();
167
- }
180
+ })
181
+ .pipeThrough(new TransformStream({
182
+ transform(chunk, streamController) {
183
+ // A context limit is a controlled terminal outcome. An SDK error
184
+ // chunk would make chat consumers stop before its final checkpoint.
185
+ if (chunk.type === "error" && generationError instanceof SparkContextLimitError)
186
+ return;
187
+ streamController.enqueue(chunk);
188
+ },
189
+ })));
190
+ const [text, usage, finishReason] = await Promise.all([
191
+ generation.text,
192
+ generation.totalUsage,
193
+ generation.finishReason,
194
+ ]);
195
+ controller.signal.throwIfAborted();
196
+ if (generationError !== undefined)
197
+ throw generationError;
198
+ const status = finishReason === "stop" ? "completed" : "incomplete";
199
+ completedResult = { text, steps: stepCount, usage, status, finishReason };
200
+ }
201
+ catch (error) {
202
+ const failure = generationError ?? error;
203
+ if (failure instanceof SparkContextLimitError && !options.signal?.aborted) {
204
+ const usage = await Promise.resolve(readUsage?.()).catch(() => undefined);
205
+ writer.write({
206
+ type: "message-metadata",
207
+ messageMetadata: { ...metadata("incomplete", usage), error: failure.message },
208
+ });
209
+ completedResult = {
210
+ text: failure.message,
211
+ steps: stepCount,
212
+ usage,
213
+ status: "incomplete",
214
+ finishReason: "context-limit",
215
+ };
216
+ return;
217
+ }
218
+ const status = options.signal?.aborted ? "cancelled" : "failed";
219
+ writer.write({
220
+ type: "message-metadata",
221
+ messageMetadata: { ...metadata(status), error: errorMessage(failure) },
222
+ });
223
+ rejectResult(failure);
224
+ throw failure;
225
+ }
226
+ finally {
227
+ options.signal?.removeEventListener("abort", onAbort);
228
+ controller.abort(new Error("Agent run ended."));
229
+ }
230
+ },
231
+ });
232
+ return { stream, result };
168
233
  }
@@ -0,0 +1,2 @@
1
+ export { NativeJavaScriptExecutor } from "./native-executor.js";
2
+ export { LocalSparkChatTransport, type LocalSparkRequest } from "./local-transport.js";
@@ -0,0 +1,2 @@
1
+ export { NativeJavaScriptExecutor } from "./native-executor.js";
2
+ export { LocalSparkChatTransport } from "./local-transport.js";
@@ -0,0 +1,216 @@
1
+ import type { SparkCapability, SparkInvocationContext } from "../capabilities.js";
2
+ export type AccountSection = "profile" | "teams" | "credits" | "subscription" | "billing" | "orders" | "cart" | "projects" | "notifications" | "workflows";
3
+ export type AccountRead = {
4
+ sections: AccountSection[];
5
+ from?: number;
6
+ count?: number;
7
+ };
8
+ export type AccountScope = {
9
+ userId: string;
10
+ teamId: string | null;
11
+ };
12
+ export type AccountResult<T> = {
13
+ status: "available";
14
+ scope: AccountScope;
15
+ data: T;
16
+ } | {
17
+ status: "unavailable";
18
+ reason: string;
19
+ };
20
+ export type AccountPage<T> = {
21
+ items: T[];
22
+ from: number;
23
+ nextFrom: number | null;
24
+ totalCount?: number;
25
+ };
26
+ export type AccountAddress = {
27
+ name: string;
28
+ city: string;
29
+ country: string;
30
+ line1: string;
31
+ line2?: string | null;
32
+ postalCode: string;
33
+ state?: string | null;
34
+ phoneNumber?: string | null;
35
+ };
36
+ export type AccountProfile = {
37
+ userId: string;
38
+ name: string;
39
+ email?: string | null;
40
+ biography?: string | null;
41
+ picture?: string | null;
42
+ isPro?: boolean;
43
+ subStatus?: string | null;
44
+ verified?: boolean;
45
+ tier?: number;
46
+ roles?: string;
47
+ permissions?: string;
48
+ projectCount?: number;
49
+ publicProjectCount?: number;
50
+ followerCount?: number;
51
+ followeeCount?: number;
52
+ totalLikeCount?: number;
53
+ point?: number;
54
+ thisWeekPoint?: number;
55
+ createdAt?: string;
56
+ lastEditedAt?: string;
57
+ addresses?: AccountAddress[];
58
+ badges?: {
59
+ id: string;
60
+ description: string;
61
+ symbol: string;
62
+ }[];
63
+ };
64
+ export type AccountTeam = {
65
+ teamId: string;
66
+ name: string;
67
+ roles: string;
68
+ accepted: boolean;
69
+ memberCount?: number;
70
+ seats?: number;
71
+ };
72
+ export type AccountCreditBalance = {
73
+ unit: "aip" | "3dpd";
74
+ scope: AccountScope;
75
+ available: number;
76
+ subscription: number;
77
+ periodical: number;
78
+ canUseSubscriptionCredit: boolean;
79
+ buckets: {
80
+ net: number;
81
+ originalNet: number;
82
+ activeSubscriptionId: string | null;
83
+ periodicalFrom: string | null;
84
+ transactionId: string | null;
85
+ transactionFrom: string | null;
86
+ }[];
87
+ };
88
+ export type AccountSubscription = {
89
+ id: number;
90
+ status: string;
91
+ period: string;
92
+ createdAt: string;
93
+ trialEndAt?: string | null;
94
+ endAt?: string | null;
95
+ cancelAt?: string | null;
96
+ canceledAt?: string | null;
97
+ endedAt?: string | null;
98
+ price?: number;
99
+ };
100
+ export type AccountBilling = {
101
+ balance: number;
102
+ history: AccountPage<{
103
+ invoiceId: string;
104
+ amountPaid: number;
105
+ paymentDate: string;
106
+ paymentStatus: string;
107
+ description: string | null;
108
+ via: string;
109
+ }>;
110
+ upcoming: {
111
+ amountDue: number;
112
+ total: number;
113
+ dueDate: string;
114
+ lines: {
115
+ amount: number;
116
+ description: string | null;
117
+ }[];
118
+ } | null;
119
+ paymentMethods: {
120
+ type: string;
121
+ brand?: string;
122
+ last4?: string;
123
+ default: boolean;
124
+ status?: string;
125
+ }[];
126
+ };
127
+ export type AccountOrderItem = {
128
+ id: number;
129
+ title: string;
130
+ projectId: number | null;
131
+ projectTitle?: string | null;
132
+ quantity: number;
133
+ status: number;
134
+ materialName?: string | null;
135
+ color?: string | null;
136
+ surface?: string | null;
137
+ previewUrl?: string | null;
138
+ pricings?: {
139
+ selected: boolean;
140
+ salePrice: number;
141
+ discount?: number;
142
+ needPro?: boolean;
143
+ }[] | null;
144
+ };
145
+ export type AccountOrder = {
146
+ id: number;
147
+ status: number;
148
+ statusName: string;
149
+ totalCost: number;
150
+ shippingCost: number;
151
+ shippingService?: string | null;
152
+ createdAt: string;
153
+ deliveredAt?: string | null;
154
+ clientShippingStartedAt?: string | null;
155
+ clientShippingDays?: number | null;
156
+ orderItems: AccountOrderItem[];
157
+ addrTo?: AccountAddress | null;
158
+ shipments?: {
159
+ carrier?: string;
160
+ trackingNumber: string;
161
+ trackingStatus: string;
162
+ }[];
163
+ };
164
+ export type AccountProject = {
165
+ id: number;
166
+ title: string;
167
+ userId?: string;
168
+ teamId?: string | null;
169
+ public: boolean;
170
+ createdAt?: string;
171
+ updatedAt?: string;
172
+ thumbnailUrl?: string | null;
173
+ labels?: string[];
174
+ };
175
+ export type AccountNotification = {
176
+ id: number;
177
+ type: string;
178
+ read: boolean;
179
+ seen: boolean;
180
+ createdAt: string;
181
+ details: Record<string, unknown>;
182
+ };
183
+ export type AccountWorkflow = {
184
+ id: number;
185
+ name: string;
186
+ type: string;
187
+ description?: string | null;
188
+ capabilities?: string[];
189
+ };
190
+ export type AccountSnapshot = {
191
+ provenance: {
192
+ kind: "live";
193
+ observedAt: string;
194
+ } | {
195
+ kind: "fixture";
196
+ profile: "demo-account";
197
+ fictional: true;
198
+ };
199
+ profile?: AccountResult<AccountProfile>;
200
+ teams?: AccountResult<AccountTeam[]>;
201
+ credits?: AccountResult<AccountCreditBalance[]>;
202
+ subscription?: AccountResult<AccountSubscription | null>;
203
+ billing?: AccountResult<AccountBilling>;
204
+ orders?: AccountResult<AccountPage<AccountOrder>>;
205
+ cart?: AccountResult<AccountPage<AccountOrderItem>>;
206
+ projects?: AccountResult<AccountPage<AccountProject>>;
207
+ notifications?: AccountResult<AccountPage<AccountNotification>>;
208
+ workflows?: AccountResult<AccountPage<AccountWorkflow>>;
209
+ };
210
+ export type WompAccountApi = {
211
+ read(options: AccountRead): Promise<AccountSnapshot>;
212
+ };
213
+ export interface AccountHost {
214
+ read(options: Required<AccountRead>, context: SparkInvocationContext): Promise<AccountSnapshot>;
215
+ }
216
+ export declare function createAccountCapability(host: AccountHost): SparkCapability<WompAccountApi>;