@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.
- package/.env.example +4 -0
- package/README.md +295 -49
- package/dist/agent-tools.d.ts +30 -0
- package/dist/agent-tools.js +189 -0
- package/dist/agent.d.ts +34 -7
- package/dist/agent.js +223 -158
- package/dist/browser.d.ts +2 -0
- package/dist/browser.js +2 -0
- package/dist/capabilities/account.d.ts +216 -0
- package/dist/capabilities/account.js +63 -0
- package/dist/capabilities/asset-imports.d.ts +55 -0
- package/dist/capabilities/asset-imports.js +117 -0
- package/dist/capabilities/assets.d.ts +29 -0
- package/dist/capabilities/assets.js +48 -0
- package/dist/capabilities/flow.d.ts +29 -0
- package/dist/capabilities/flow.js +52 -0
- package/dist/capabilities/geometry.d.ts +48 -0
- package/dist/capabilities/geometry.js +51 -0
- package/dist/capabilities/knowledge.d.ts +11 -0
- package/dist/capabilities/knowledge.js +23 -0
- package/dist/capabilities/openscad-instructions.d.ts +1 -0
- package/dist/capabilities/openscad-instructions.js +81 -0
- package/dist/capabilities/openscad.d.ts +54 -0
- package/dist/capabilities/openscad.js +34 -0
- package/dist/capabilities/operations.d.ts +104 -0
- package/dist/capabilities/operations.js +145 -0
- package/dist/capabilities/scene-draft.d.ts +404 -0
- package/dist/capabilities/scene-draft.js +1 -0
- package/dist/capabilities/scene.d.ts +28 -0
- package/dist/capabilities/scene.js +51 -0
- package/dist/capabilities.d.ts +67 -0
- package/dist/capabilities.js +25 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +24 -0
- package/dist/client.d.ts +43 -0
- package/dist/client.js +159 -0
- package/dist/context.d.ts +15 -0
- package/dist/context.js +264 -0
- package/dist/execution-lifetime.d.ts +32 -0
- package/dist/execution-lifetime.js +113 -0
- package/dist/executor.d.ts +6 -1
- package/dist/generated/account-declarations.d.ts +1 -0
- package/dist/generated/account-declarations.js +3 -0
- package/dist/generated/asset-import-declarations.d.ts +1 -0
- package/dist/generated/asset-import-declarations.js +3 -0
- package/dist/generated/assets-declarations.d.ts +1 -0
- package/dist/generated/assets-declarations.js +3 -0
- package/dist/generated/flow-declarations.d.ts +1 -0
- package/dist/generated/flow-declarations.js +3 -0
- package/dist/generated/geometry-declarations.d.ts +1 -0
- package/dist/generated/geometry-declarations.js +3 -0
- package/dist/generated/kakapo-declarations.d.ts +1 -0
- package/dist/generated/kakapo-declarations.js +3 -0
- package/dist/generated/knowledge-declarations.d.ts +1 -0
- package/dist/generated/knowledge-declarations.js +3 -0
- package/dist/generated/openscad-declarations.d.ts +1 -0
- package/dist/generated/openscad-declarations.js +3 -0
- package/dist/generated/operations-declarations.d.ts +1 -0
- package/dist/generated/operations-declarations.js +3 -0
- package/dist/generated/scene-declarations.d.ts +1 -0
- package/dist/generated/scene-declarations.js +3 -0
- package/dist/index.d.ts +7 -6
- package/dist/index.js +5 -3
- package/dist/kakapo-capability-api.d.ts +18 -0
- package/dist/kakapo-capability-api.js +1 -0
- package/dist/kakapo-capability.d.ts +6 -0
- package/dist/kakapo-capability.js +50 -0
- package/dist/kakapo-scene-skill.d.ts +1 -0
- package/dist/kakapo-scene-skill.js +54 -0
- package/dist/kakapo.d.ts +5 -0
- package/dist/kakapo.js +3 -0
- package/dist/local-transport.d.ts +11 -0
- package/dist/local-transport.js +15 -0
- package/dist/model-history.d.ts +5 -0
- package/dist/model-history.js +34 -0
- package/dist/model-options.d.ts +4 -0
- package/dist/model-options.js +25 -0
- package/dist/models.d.ts +3 -15
- package/dist/models.js +2 -16
- package/dist/native-executor.d.ts +5 -0
- package/dist/native-executor.js +92 -0
- package/dist/pricing.d.ts +3 -0
- package/dist/pricing.js +70 -0
- package/dist/prompt.d.ts +1 -1
- package/dist/prompt.js +19 -209
- package/dist/quickjs-executor.d.ts +13 -0
- package/dist/quickjs-executor.js +309 -0
- package/dist/runtime.d.ts +16 -5
- package/dist/runtime.js +61 -10
- package/dist/server/artifacts.d.ts +17 -0
- package/dist/server/artifacts.js +36 -0
- package/dist/server/demo-account.d.ts +3 -0
- package/dist/server/demo-account.js +38 -0
- package/dist/server/executor.d.ts +17 -0
- package/dist/server/executor.js +35 -0
- package/dist/server/express.d.ts +13 -0
- package/dist/server/express.js +159 -0
- package/dist/server/index.d.ts +8 -0
- package/dist/server/index.js +5 -0
- package/dist/server/service.d.ts +41 -0
- package/dist/server/service.js +402 -0
- package/dist/server/standalone.d.ts +9 -0
- package/dist/server/standalone.js +85 -0
- package/dist/server/store.d.ts +16 -0
- package/dist/server/store.js +70 -0
- package/dist/server/types.d.ts +53 -0
- package/dist/server/types.js +1 -0
- package/dist/types.d.ts +3 -27
- package/dist/ui.d.ts +224 -0
- package/dist/ui.js +71 -0
- package/dist/womp-scene-api.d.ts +195 -3
- package/dist/womp-scene-api.js +102 -73
- package/package.json +66 -10
package/dist/agent.js
CHANGED
|
@@ -1,168 +1,233 @@
|
|
|
1
|
-
import { stepCountIs, streamText,
|
|
2
|
-
import {
|
|
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
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
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
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
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
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
}
|
package/dist/browser.js
ADDED
|
@@ -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>;
|