@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,85 @@
1
+ import { createAnthropic } from "@ai-sdk/anthropic";
2
+ import { createOpenAI } from "@ai-sdk/openai";
3
+ import express from "express";
4
+ import { getSparkModel, SPARK_MODELS } from "../models.js";
5
+ import { KakapoRuntime } from "../runtime.js";
6
+ import { composeCapabilities, createAccountCapability } from "../capabilities.js";
7
+ import { createDemoAccountHost } from "./demo-account.js";
8
+ import { createKakapoSceneCapability } from "../kakapo-capability.js";
9
+ import { QuickJSJavaScriptExecutor } from "../quickjs-executor.js";
10
+ import { sparkModelOptions } from "../model-options.js";
11
+ import { MemorySparkArtifactStore } from "./artifacts.js";
12
+ import { createSparkRunExecutor } from "./executor.js";
13
+ import { createSparkAgentRouter } from "./express.js";
14
+ import { SparkAgentService } from "./service.js";
15
+ import { MemorySparkAgentStore } from "./store.js";
16
+ export function createStandaloneSparkAgentApp(options) {
17
+ const apiBasePath = options.apiBasePath ?? "/agent";
18
+ const store = new MemorySparkAgentStore();
19
+ const artifactStore = new MemorySparkArtifactStore(`${apiBasePath}/artifacts`);
20
+ const executeRun = createSparkRunExecutor({
21
+ createHost: async (context) => {
22
+ const runtime = new KakapoRuntime(options.kakapoUrl);
23
+ try {
24
+ await runtime.connect();
25
+ return {
26
+ executor: new QuickJSJavaScriptExecutor(),
27
+ capabilities: composeCapabilities({
28
+ scene: createKakapoSceneCapability(runtime, (image) => artifactStore.write(context.ownerId, image)),
29
+ ...(options.developmentProfile === "demo-account"
30
+ ? { account: createAccountCapability(createDemoAccountHost()) }
31
+ : {}),
32
+ }),
33
+ artifacts: {
34
+ resolve: async (ref) => {
35
+ const stored = await artifactStore.get(context.ownerId, ref.id);
36
+ if (stored === undefined)
37
+ throw new Error(`Artifact unavailable: ${ref.id}`);
38
+ const { data, ownerId: _ownerId, ...artifact } = stored;
39
+ return { artifact, data };
40
+ },
41
+ },
42
+ dispose: () => runtime.disconnect(),
43
+ };
44
+ }
45
+ catch (error) {
46
+ runtime.disconnect();
47
+ throw error;
48
+ }
49
+ },
50
+ resolveModel: (settings) => {
51
+ const selected = getSparkModel(settings.modelId);
52
+ if (SPARK_MODELS.some(({ id }) => id === settings.modelId) === false) {
53
+ throw new Error(`Unsupported Spark model: ${settings.modelId}`);
54
+ }
55
+ if (selected.provider === "anthropic") {
56
+ if (options.anthropicApiKey?.trim() === "" || options.anthropicApiKey === undefined) {
57
+ throw new Error("ANTHROPIC_API_KEY is required for this model.");
58
+ }
59
+ return {
60
+ model: createAnthropic({ apiKey: options.anthropicApiKey })(selected.id),
61
+ modelId: selected.id,
62
+ providerOptions: sparkModelOptions(selected.id, selected.provider, settings.reasoningEffort),
63
+ maxOutputTokens: 48_000,
64
+ };
65
+ }
66
+ if (options.openAiApiKey?.trim() === "" || options.openAiApiKey === undefined) {
67
+ throw new Error("OPENAI_API_KEY is required for this model.");
68
+ }
69
+ return {
70
+ model: createOpenAI({ apiKey: options.openAiApiKey }).responses(selected.id),
71
+ modelId: selected.id,
72
+ providerOptions: sparkModelOptions(selected.id, selected.provider, settings.reasoningEffort),
73
+ maxOutputTokens: 48_000,
74
+ };
75
+ },
76
+ });
77
+ const service = new SparkAgentService({ store, executeRun });
78
+ const app = express();
79
+ app.disable("x-powered-by");
80
+ app.get("/health", (_request, response) => {
81
+ response.json({ status: "ok" });
82
+ });
83
+ app.use(apiBasePath, createSparkAgentRouter({ service, artifactStore }));
84
+ return app;
85
+ }
@@ -0,0 +1,16 @@
1
+ import type { SparkAgentStore, SparkConversation, SparkConversationSummary, SparkRun } from "./types.js";
2
+ import type { StoredSparkChunk } from "../ui.js";
3
+ export declare class MemorySparkAgentStore implements SparkAgentStore {
4
+ private readonly conversations;
5
+ private readonly runs;
6
+ private readonly chunks;
7
+ createConversation(conversation: SparkConversation): Promise<void>;
8
+ getConversation(id: string): Promise<SparkConversation | undefined>;
9
+ listConversations(ownerId: string): Promise<SparkConversationSummary[]>;
10
+ saveConversation(conversation: SparkConversation): Promise<void>;
11
+ createRun(run: SparkRun): Promise<void>;
12
+ getRun(id: string): Promise<SparkRun | undefined>;
13
+ saveRun(run: SparkRun): Promise<void>;
14
+ appendRunChunk(runId: string, conversationId: string, chunk: StoredSparkChunk["chunk"]): Promise<StoredSparkChunk>;
15
+ listRunChunks(runId: string, afterSequence: number): Promise<StoredSparkChunk[]>;
16
+ }
@@ -0,0 +1,70 @@
1
+ function copy(value) {
2
+ return structuredClone(value);
3
+ }
4
+ export class MemorySparkAgentStore {
5
+ conversations = new Map();
6
+ runs = new Map();
7
+ chunks = new Map();
8
+ async createConversation(conversation) {
9
+ if (this.conversations.has(conversation.id)) {
10
+ throw new Error(`Conversation ${conversation.id} already exists.`);
11
+ }
12
+ this.conversations.set(conversation.id, copy(conversation));
13
+ }
14
+ async getConversation(id) {
15
+ const conversation = this.conversations.get(id);
16
+ return conversation === undefined ? undefined : copy(conversation);
17
+ }
18
+ async listConversations(ownerId) {
19
+ return [...this.conversations.values()]
20
+ .filter((conversation) => conversation.ownerId === ownerId)
21
+ .sort((left, right) => right.updatedAt.localeCompare(left.updatedAt))
22
+ .map(({ messages, ...conversation }) => ({
23
+ ...copy(conversation),
24
+ messageCount: messages.length,
25
+ }));
26
+ }
27
+ async saveConversation(conversation) {
28
+ if (this.conversations.has(conversation.id) === false) {
29
+ throw new Error(`Conversation ${conversation.id} does not exist.`);
30
+ }
31
+ this.conversations.set(conversation.id, copy(conversation));
32
+ }
33
+ async createRun(run) {
34
+ if (this.runs.has(run.id))
35
+ throw new Error(`Run ${run.id} already exists.`);
36
+ this.runs.set(run.id, copy(run));
37
+ this.chunks.set(run.id, []);
38
+ }
39
+ async getRun(id) {
40
+ const run = this.runs.get(id);
41
+ return run === undefined ? undefined : copy(run);
42
+ }
43
+ async saveRun(run) {
44
+ if (this.runs.has(run.id) === false)
45
+ throw new Error(`Run ${run.id} does not exist.`);
46
+ this.runs.set(run.id, copy(run));
47
+ }
48
+ async appendRunChunk(runId, conversationId, chunk) {
49
+ const chunks = this.chunks.get(runId);
50
+ if (chunks === undefined)
51
+ throw new Error(`Run ${runId} does not exist.`);
52
+ const stored = {
53
+ sequence: chunks.length + 1,
54
+ conversationId,
55
+ runId,
56
+ createdAt: new Date().toISOString(),
57
+ chunk: copy(chunk),
58
+ };
59
+ chunks.push(stored);
60
+ return copy(stored);
61
+ }
62
+ async listRunChunks(runId, afterSequence) {
63
+ const chunks = this.chunks.get(runId);
64
+ if (chunks === undefined)
65
+ throw new Error(`Run ${runId} does not exist.`);
66
+ return chunks
67
+ .filter(({ sequence }) => sequence > afterSequence)
68
+ .map(copy);
69
+ }
70
+ }
@@ -0,0 +1,53 @@
1
+ import type { SparkAgentRun } from "../agent.js";
2
+ import type { ReasoningEffort } from "../models.js";
3
+ import type { SparkRunStatus, SparkUIMessage, StoredSparkChunk } from "../ui.js";
4
+ export type SparkConversation = {
5
+ id: string;
6
+ ownerId: string;
7
+ title: string;
8
+ messages: SparkUIMessage[];
9
+ activeRunId?: string;
10
+ createdAt: string;
11
+ updatedAt: string;
12
+ };
13
+ export type SparkConversationSummary = Omit<SparkConversation, "messages"> & {
14
+ messageCount: number;
15
+ };
16
+ export type SparkRunSettings = {
17
+ modelId: string;
18
+ reasoningEffort: ReasoningEffort;
19
+ };
20
+ export type SparkRun = {
21
+ id: string;
22
+ conversationId: string;
23
+ inputMessageId: string;
24
+ assistantMessageId: string;
25
+ status: SparkRunStatus;
26
+ settings: SparkRunSettings;
27
+ error?: string;
28
+ createdAt: string;
29
+ updatedAt: string;
30
+ startedAt?: string;
31
+ completedAt?: string;
32
+ };
33
+ export type SparkRunExecutionContext = {
34
+ ownerId: string;
35
+ conversationId: string;
36
+ runId: string;
37
+ assistantMessageId: string;
38
+ uiMessages: SparkUIMessage[];
39
+ settings: SparkRunSettings;
40
+ signal: AbortSignal;
41
+ };
42
+ export type SparkRunExecutor = (context: SparkRunExecutionContext) => SparkAgentRun | Promise<SparkAgentRun>;
43
+ export interface SparkAgentStore {
44
+ createConversation(conversation: SparkConversation): Promise<void>;
45
+ getConversation(id: string): Promise<SparkConversation | undefined>;
46
+ listConversations(ownerId: string): Promise<SparkConversationSummary[]>;
47
+ saveConversation(conversation: SparkConversation): Promise<void>;
48
+ createRun(run: SparkRun): Promise<void>;
49
+ getRun(id: string): Promise<SparkRun | undefined>;
50
+ saveRun(run: SparkRun): Promise<void>;
51
+ appendRunChunk(runId: string, conversationId: string, chunk: StoredSparkChunk["chunk"]): Promise<StoredSparkChunk>;
52
+ listRunChunks(runId: string, afterSequence: number): Promise<StoredSparkChunk[]>;
53
+ }
@@ -0,0 +1 @@
1
+ export {};
package/dist/types.d.ts CHANGED
@@ -32,7 +32,7 @@ export type ExecutionResult = {
32
32
  error?: string;
33
33
  rolledBack?: boolean;
34
34
  };
35
- export type RunEvent = {
35
+ export type SparkRuntimeEvent = {
36
36
  type: "sdk-call";
37
37
  callId: string;
38
38
  method: string;
@@ -62,35 +62,11 @@ export type RunEvent = {
62
62
  sdkCalls: string[];
63
63
  error?: string;
64
64
  rolledBack?: boolean;
65
- } | {
66
- type: "step";
67
- step: number;
68
- toolNames: string[];
69
- reasoningSummary?: string;
70
- responseTimeMs: number;
71
- } | {
72
- type: "text-delta";
73
- text: string;
74
- } | {
75
- type: "screenshot";
76
- callId: string;
77
- data: Uint8Array;
78
- mediaType: string;
79
- view: string;
80
- targetId: number;
81
- } | {
82
- type: "result";
83
- text: string;
84
- steps: number;
85
- usage: unknown;
86
- } | {
87
- type: "error";
88
- message: string;
89
65
  };
90
- export type RunEventSink = (event: RunEvent) => void;
66
+ export type SparkRuntimeEventSink = (event: SparkRuntimeEvent) => void;
91
67
  export interface SparkRuntime {
92
68
  readonly connected: boolean;
93
- emit(event: RunEvent): void;
69
+ setEventSink(eventSink: SparkRuntimeEventSink): void;
94
70
  connect(): Promise<void>;
95
71
  disconnect(): void;
96
72
  execute(code: string, purpose: string): Promise<ExecutionResult>;
package/dist/ui.d.ts ADDED
@@ -0,0 +1,224 @@
1
+ import type { InferUIMessageChunk, UIMessage } from "ai";
2
+ import { z } from "zod";
3
+ import type { ExecutionReceipt, SparkSkill } from "./capabilities.js";
4
+ export { DEFAULT_MODEL_ID, getSparkModel, REASONING_EFFORT_LABELS, resolveReasoningEffort, SPARK_MODELS, } from "./models.js";
5
+ export type { ModelProvider, ReasoningEffort, SparkModel } from "./models.js";
6
+ export declare const SPARK_RUN_STATUSES: readonly ["queued", "running", "requires_action", "completed", "failed", "cancelled", "incomplete"];
7
+ export type SparkRunStatus = (typeof SPARK_RUN_STATUSES)[number];
8
+ export type SparkArtifact = {
9
+ id: string;
10
+ url: string;
11
+ mediaType: string;
12
+ name?: string;
13
+ width?: number;
14
+ height?: number;
15
+ metadata?: Record<string, unknown>;
16
+ };
17
+ export type SparkMessageMetadata = {
18
+ createdAt: string;
19
+ completedAt?: string;
20
+ durationMs?: number;
21
+ runId?: string;
22
+ runStatus?: SparkRunStatus;
23
+ modelId?: string;
24
+ usage?: unknown;
25
+ error?: string;
26
+ };
27
+ export type SparkConsoleData = {
28
+ stream: "stdout" | "stderr";
29
+ text: string;
30
+ };
31
+ export type SparkRunStatusData = {
32
+ runId: string;
33
+ status: SparkRunStatus;
34
+ error?: string;
35
+ label?: string;
36
+ };
37
+ export declare const sparkStepCostSchema: z.ZodObject<{
38
+ modelId: z.ZodString;
39
+ pricingDate: z.ZodString;
40
+ source: z.ZodOptional<z.ZodString>;
41
+ totalUsd: z.ZodNullable<z.ZodNumber>;
42
+ reason: z.ZodOptional<z.ZodString>;
43
+ lines: z.ZodArray<z.ZodObject<{
44
+ label: z.ZodString;
45
+ tokens: z.ZodNumber;
46
+ usdPerMillion: z.ZodNumber;
47
+ usd: z.ZodNumber;
48
+ }, z.core.$strip>>;
49
+ }, z.core.$strip>;
50
+ export type SparkStepCost = z.infer<typeof sparkStepCostSchema>;
51
+ export type SparkStepMetricsData = {
52
+ step: number;
53
+ toolNames: string[];
54
+ responseTimeMs: number;
55
+ cost?: SparkStepCost;
56
+ };
57
+ export declare const sparkExecutionReceiptSchema: z.ZodObject<{
58
+ id: z.ZodString;
59
+ capability: z.ZodString;
60
+ operation: z.ZodString;
61
+ status: z.ZodEnum<{
62
+ unknown: "unknown";
63
+ committed: "committed";
64
+ rolled_back: "rolled_back";
65
+ submitted: "submitted";
66
+ }>;
67
+ target: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
68
+ details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
69
+ }, z.core.$strip>;
70
+ export type SparkDataParts = {
71
+ console: SparkConsoleData;
72
+ artifact: SparkArtifact;
73
+ "run-status": SparkRunStatusData;
74
+ "step-metrics": SparkStepMetricsData;
75
+ "execution-receipt": {
76
+ toolCallId: string;
77
+ receipt: ExecutionReceipt;
78
+ };
79
+ };
80
+ export type ExecuteJavaScriptInput = {
81
+ purpose: string;
82
+ code: string;
83
+ };
84
+ export type ExecuteJavaScriptOutput = {
85
+ version: 2;
86
+ ok: boolean;
87
+ purpose: string;
88
+ value: unknown;
89
+ logs: string[];
90
+ receipts: ExecutionReceipt[];
91
+ artifacts: {
92
+ kind: "image" | "file";
93
+ artifact: SparkArtifact;
94
+ }[];
95
+ error?: string;
96
+ };
97
+ export type ScreenshotInput = {
98
+ targetId?: number;
99
+ view?: "front" | "back" | "left" | "right" | "top" | "bottom" | "isometric";
100
+ };
101
+ export type ScreenshotOutput = SparkArtifact & {
102
+ targetId: number;
103
+ view: string;
104
+ };
105
+ export type SparkUITools = {
106
+ execute_javascript: {
107
+ input: ExecuteJavaScriptInput;
108
+ output: ExecuteJavaScriptOutput;
109
+ };
110
+ read_skill: {
111
+ input: {
112
+ name: string;
113
+ };
114
+ output: ({
115
+ ok: true;
116
+ } & SparkSkill) | {
117
+ ok: false;
118
+ error: string;
119
+ available: string[];
120
+ };
121
+ };
122
+ };
123
+ export type SparkUIMessage = UIMessage<SparkMessageMetadata, SparkDataParts, SparkUITools>;
124
+ export type SparkUIMessageChunk = InferUIMessageChunk<SparkUIMessage>;
125
+ export type StoredSparkChunk = {
126
+ sequence: number;
127
+ conversationId: string;
128
+ runId: string;
129
+ createdAt: string;
130
+ chunk: SparkUIMessageChunk;
131
+ };
132
+ export declare const sparkArtifactSchema: z.ZodObject<{
133
+ id: z.ZodString;
134
+ url: z.ZodString;
135
+ mediaType: z.ZodString;
136
+ name: z.ZodOptional<z.ZodString>;
137
+ width: z.ZodOptional<z.ZodNumber>;
138
+ height: z.ZodOptional<z.ZodNumber>;
139
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
140
+ }, z.core.$strip>;
141
+ export declare const sparkMessageMetadataSchema: z.ZodObject<{
142
+ createdAt: z.ZodString;
143
+ completedAt: z.ZodOptional<z.ZodString>;
144
+ durationMs: z.ZodOptional<z.ZodNumber>;
145
+ runId: z.ZodOptional<z.ZodString>;
146
+ runStatus: z.ZodOptional<z.ZodEnum<{
147
+ queued: "queued";
148
+ running: "running";
149
+ requires_action: "requires_action";
150
+ completed: "completed";
151
+ failed: "failed";
152
+ cancelled: "cancelled";
153
+ incomplete: "incomplete";
154
+ }>>;
155
+ modelId: z.ZodOptional<z.ZodString>;
156
+ usage: z.ZodOptional<z.ZodUnknown>;
157
+ error: z.ZodOptional<z.ZodString>;
158
+ }, z.core.$strip>;
159
+ export declare const sparkDataPartSchemas: {
160
+ readonly "execution-receipt": z.ZodObject<{
161
+ toolCallId: z.ZodString;
162
+ receipt: z.ZodObject<{
163
+ id: z.ZodString;
164
+ capability: z.ZodString;
165
+ operation: z.ZodString;
166
+ status: z.ZodEnum<{
167
+ unknown: "unknown";
168
+ committed: "committed";
169
+ rolled_back: "rolled_back";
170
+ submitted: "submitted";
171
+ }>;
172
+ target: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnion<readonly [z.ZodString, z.ZodNumber]>>>;
173
+ details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
174
+ }, z.core.$strip>;
175
+ }, z.core.$strip>;
176
+ readonly console: z.ZodObject<{
177
+ stream: z.ZodEnum<{
178
+ stdout: "stdout";
179
+ stderr: "stderr";
180
+ }>;
181
+ text: z.ZodString;
182
+ }, z.core.$strip>;
183
+ readonly artifact: z.ZodObject<{
184
+ id: z.ZodString;
185
+ url: z.ZodString;
186
+ mediaType: z.ZodString;
187
+ name: z.ZodOptional<z.ZodString>;
188
+ width: z.ZodOptional<z.ZodNumber>;
189
+ height: z.ZodOptional<z.ZodNumber>;
190
+ metadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
191
+ }, z.core.$strip>;
192
+ readonly "run-status": z.ZodObject<{
193
+ runId: z.ZodString;
194
+ status: z.ZodEnum<{
195
+ queued: "queued";
196
+ running: "running";
197
+ requires_action: "requires_action";
198
+ completed: "completed";
199
+ failed: "failed";
200
+ cancelled: "cancelled";
201
+ incomplete: "incomplete";
202
+ }>;
203
+ error: z.ZodOptional<z.ZodString>;
204
+ label: z.ZodOptional<z.ZodString>;
205
+ }, z.core.$strip>;
206
+ readonly "step-metrics": z.ZodObject<{
207
+ step: z.ZodNumber;
208
+ toolNames: z.ZodArray<z.ZodString>;
209
+ responseTimeMs: z.ZodNumber;
210
+ cost: z.ZodOptional<z.ZodObject<{
211
+ modelId: z.ZodString;
212
+ pricingDate: z.ZodString;
213
+ source: z.ZodOptional<z.ZodString>;
214
+ totalUsd: z.ZodNullable<z.ZodNumber>;
215
+ reason: z.ZodOptional<z.ZodString>;
216
+ lines: z.ZodArray<z.ZodObject<{
217
+ label: z.ZodString;
218
+ tokens: z.ZodNumber;
219
+ usdPerMillion: z.ZodNumber;
220
+ usd: z.ZodNumber;
221
+ }, z.core.$strip>>;
222
+ }, z.core.$strip>>;
223
+ }, z.core.$strip>;
224
+ };
package/dist/ui.js ADDED
@@ -0,0 +1,71 @@
1
+ import { z } from "zod";
2
+ export { DEFAULT_MODEL_ID, getSparkModel, REASONING_EFFORT_LABELS, resolveReasoningEffort, SPARK_MODELS, } from "./models.js";
3
+ export const SPARK_RUN_STATUSES = [
4
+ "queued",
5
+ "running",
6
+ "requires_action",
7
+ "completed",
8
+ "failed",
9
+ "cancelled",
10
+ "incomplete",
11
+ ];
12
+ export const sparkStepCostSchema = z.object({
13
+ modelId: z.string(),
14
+ pricingDate: z.string(),
15
+ source: z.string().url().optional(),
16
+ totalUsd: z.number().nonnegative().nullable(),
17
+ reason: z.string().optional(),
18
+ lines: z.array(z.object({
19
+ label: z.string(),
20
+ tokens: z.number().int().nonnegative(),
21
+ usdPerMillion: z.number().nonnegative(),
22
+ usd: z.number().nonnegative(),
23
+ })),
24
+ });
25
+ export const sparkExecutionReceiptSchema = z.object({
26
+ id: z.string(),
27
+ capability: z.string(),
28
+ operation: z.string(),
29
+ status: z.enum(["committed", "rolled_back", "unknown", "submitted"]),
30
+ target: z.record(z.string(), z.union([z.string(), z.number()])).optional(),
31
+ details: z.record(z.string(), z.unknown()).optional(),
32
+ });
33
+ export const sparkArtifactSchema = z.object({
34
+ id: z.string().min(1),
35
+ url: z.string().min(1),
36
+ mediaType: z.string().min(1),
37
+ name: z.string().optional(),
38
+ width: z.number().int().positive().optional(),
39
+ height: z.number().int().positive().optional(),
40
+ metadata: z.record(z.string(), z.unknown()).optional(),
41
+ });
42
+ export const sparkMessageMetadataSchema = z.object({
43
+ createdAt: z.string().datetime(),
44
+ completedAt: z.string().datetime().optional(),
45
+ durationMs: z.number().nonnegative().optional(),
46
+ runId: z.string().optional(),
47
+ runStatus: z.enum(SPARK_RUN_STATUSES).optional(),
48
+ modelId: z.string().optional(),
49
+ usage: z.unknown().optional(),
50
+ error: z.string().optional(),
51
+ });
52
+ export const sparkDataPartSchemas = {
53
+ "execution-receipt": z.object({ toolCallId: z.string(), receipt: sparkExecutionReceiptSchema }),
54
+ console: z.object({
55
+ stream: z.enum(["stdout", "stderr"]),
56
+ text: z.string(),
57
+ }),
58
+ artifact: sparkArtifactSchema,
59
+ "run-status": z.object({
60
+ runId: z.string().min(1),
61
+ status: z.enum(SPARK_RUN_STATUSES),
62
+ error: z.string().optional(),
63
+ label: z.string().optional(),
64
+ }),
65
+ "step-metrics": z.object({
66
+ step: z.number().int().nonnegative(),
67
+ toolNames: z.array(z.string()),
68
+ responseTimeMs: z.number().nonnegative(),
69
+ cost: sparkStepCostSchema.optional(),
70
+ }),
71
+ };