@womp/spark-agent 10.0.0 → 10.1.1

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/CHANGELOG.md CHANGED
@@ -4,6 +4,38 @@ Notable changes to `@womp/spark-agent`, newest first. Versions follow
4
4
  [Semantic Versioning](https://semver.org/). Add an entry with each version bump; describe what
5
5
  changed for hosts and users, and how to migrate across breaking changes.
6
6
 
7
+ ## 10.1.1 — 2026-10-13
8
+
9
+ ### Fixed
10
+
11
+ - `womp.flowRuns.wait(runId, seconds)` waits through the host's `waitForService`, outside the
12
+ 60-second JavaScript budget. Before, `wait(runId, 60)` (the skill's own example) always ended
13
+ the call with "JavaScript exceeded 60 seconds." instead of returning the run's status. On a host
14
+ without `waitForService`, the wait is cut to 45 seconds.
15
+
16
+ ### Migration
17
+
18
+ - None.
19
+
20
+ ## 10.1.0 — 2026-10-13
21
+
22
+ ### Added
23
+
24
+ - Timings on the `step-metrics` data part, from the AI SDK's step performance, all optional in
25
+ `sparkDataPartSchemas`: `timeToFirstOutputMs` (until the model's first output chunk),
26
+ `stepTimeMs` (the model's response and the step's tool calls, after the request was prepared),
27
+ `toolExecutionMs` (the step's tool calls, summed) and `toolCallMs` (each tool call, by tool call
28
+ id).
29
+ - `durationMs` on `SparkCompaction` (the `compaction` data part, optional): how long the summary
30
+ request took.
31
+
32
+ ### Changed
33
+
34
+ - `step-metrics` timings, `responseTimeMs` included, are whole milliseconds.
35
+
36
+ ### Migration
37
+
38
+ - None. The fields are optional; readers on older versions accept stored parts that carry them and ignore the fields.
7
39
  ## 10.0.0 — 2026-10-13
8
40
 
9
41
  The agent sets and changes a goal itself, from what the user says in chat, instead of proposing one
package/dist/agent.js CHANGED
@@ -210,13 +210,20 @@ export function runSparkAgent(options) {
210
210
  },
211
211
  onStepEnd: async (step) => {
212
212
  stepCount++;
213
+ // The SDK times with performance.now(); whole milliseconds are enough to store.
214
+ const timing = step.performance;
215
+ const toolCallMs = Object.fromEntries(Object.entries(timing.toolExecutionMs).map(([id, ms]) => [id, Math.round(ms)]));
213
216
  writer.write({
214
217
  type: "data-step-metrics",
215
218
  id: `step-${step.stepNumber}`,
216
219
  data: {
217
220
  step: step.stepNumber,
218
221
  toolNames: step.toolCalls.map(({ toolName }) => toolName),
219
- responseTimeMs: step.performance.responseTimeMs,
222
+ responseTimeMs: Math.round(timing.responseTimeMs),
223
+ timeToFirstOutputMs: timing.timeToFirstOutputMs === undefined ? undefined : Math.round(timing.timeToFirstOutputMs),
224
+ stepTimeMs: Math.round(timing.stepTimeMs),
225
+ toolExecutionMs: Object.values(toolCallMs).reduce((sum, ms) => sum + ms, 0),
226
+ toolCallMs,
220
227
  cost: calculateStepCost(options.modelId, step.usage),
221
228
  usage: step.usage,
222
229
  },
@@ -2,6 +2,8 @@ import { z } from "zod";
2
2
  import { WOMP_FLOW_RUNS_DECLARATIONS } from "../generated/flow-runs-declarations.js";
3
3
  export const FLOW_RUN_WAIT_MAX_SECONDS = 60;
4
4
  export const FLOW_RUN_WAIT_DEFAULT_SECONDS = 30;
5
+ /** A wait inside the 60 s JavaScript budget, on a host without waitForService, with room for the rest of the call. */
6
+ const FLOW_RUN_WAIT_INLINE_MAX_SECONDS = 45;
5
7
  const runId = z
6
8
  .string()
7
9
  .regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i, "Use a runId returned by run().");
@@ -61,7 +63,14 @@ While a run is live on this project (not a copy run), womp.scene.access is refus
61
63
  return start();
62
64
  },
63
65
  status: async (id) => host.status(runId.parse(id), context),
64
- wait: async (id, seconds) => host.wait(runId.parse(id), waitSeconds.parse(seconds), context),
66
+ wait: async (id, seconds) => {
67
+ const parsed = runId.parse(id);
68
+ const bound = waitSeconds.parse(seconds);
69
+ // wait(id, 60) would spend the whole 60 s JavaScript budget; a service wait is outside it.
70
+ if (context.waitForService)
71
+ return context.waitForService("Waiting for the flow run", () => host.wait(parsed, bound, context));
72
+ return host.wait(parsed, Math.min(bound, FLOW_RUN_WAIT_INLINE_MAX_SECONDS), context);
73
+ },
65
74
  cancel: async (id) => host.cancel(runId.parse(id), context),
66
75
  deleteCopy: async (id) => {
67
76
  context.signal.throwIfAborted();
@@ -185,8 +185,8 @@ export async function compactSparkHistory(options) {
185
185
  const end = Math.min(messages.length - kept, lastIndex(messages, ({ role }) => role === "user"));
186
186
  if (end <= 0)
187
187
  return { messages };
188
- const summary = await summarize(messages.slice(0, end), options);
189
- if (summary === undefined)
188
+ const summarized = await summarize(messages.slice(0, end), options);
189
+ if (summarized === undefined)
190
190
  return { messages };
191
191
  const keptSkills = readSkills(history.slice(firstKept));
192
192
  const skills = [
@@ -194,12 +194,13 @@ export async function compactSparkHistory(options) {
194
194
  ].filter((name) => !keptSkills.has(name));
195
195
  const compaction = {
196
196
  firstKeptMessageId: history[firstKept].id,
197
- summary,
197
+ summary: summarized.summary,
198
198
  skills,
199
199
  modelId: options.modelId,
200
200
  tokensBefore: estimate(messages, options),
201
201
  tokensAfter: 0,
202
202
  createdAt: new Date().toISOString(),
203
+ durationMs: summarized.durationMs,
203
204
  };
204
205
  const compacted = await options.convert(compaction);
205
206
  compaction.tokensAfter = estimate(compacted, options);
@@ -265,10 +266,10 @@ export function createStepCompaction(options) {
265
266
  // Only the steps it replaces: a kept step it also told of would read as done
266
267
  // twice. They end the request of the first kept step, which the provider has
267
268
  // cached.
268
- const summary = await summarize(messages.slice(0, firstKept), options);
269
- if (summary === undefined)
269
+ const summarized = await summarize(messages.slice(0, firstKept), options);
270
+ if (summarized === undefined)
270
271
  return messages;
271
- const next = compaction(summary);
272
+ const next = { ...compaction(summarized.summary), durationMs: summarized.durationMs };
272
273
  const sent = await compacted(next);
273
274
  next.tokensAfter = estimate(sent, options);
274
275
  previous = next;
@@ -303,6 +304,7 @@ function keptTail(messages, compacted) {
303
304
  }
304
305
  return kept;
305
306
  }
307
+ /** The summary of `messages`, and how long its request took; undefined when it failed. */
306
308
  async function summarize(messages, options) {
307
309
  options.onCompacting?.();
308
310
  const definitions = Object.fromEntries(Object.entries(options.tools).map(([name, tool]) => {
@@ -310,6 +312,7 @@ async function summarize(messages, options) {
310
312
  return [name, definition];
311
313
  }));
312
314
  let summary;
315
+ const started = performance.now();
313
316
  try {
314
317
  const result = await generateText({
315
318
  model: options.model,
@@ -329,8 +332,9 @@ async function summarize(messages, options) {
329
332
  if (options.signal?.aborted)
330
333
  throw error;
331
334
  }
335
+ const durationMs = Math.round(performance.now() - started);
332
336
  options.signal?.throwIfAborted();
333
- return summary;
337
+ return summary === undefined ? undefined : { summary, durationMs };
334
338
  }
335
339
  function threshold(options) {
336
340
  return Math.min(options.limits?.thresholdTokens ?? COMPACTION_THRESHOLD_TOKENS, options.contextWindow === undefined ? Infinity : options.contextWindow - (options.maxOutputTokens ?? 0));
package/dist/ui.d.ts CHANGED
@@ -59,7 +59,16 @@ export type SparkStepCost = z.infer<typeof sparkStepCostSchema>;
59
59
  export type SparkStepMetricsData = {
60
60
  step: number;
61
61
  toolNames: string[];
62
+ /** Time waiting for the model's response. */
62
63
  responseTimeMs: number;
64
+ /** Time until the model's first output chunk; absent when the step did not stream one. */
65
+ timeToFirstOutputMs?: number;
66
+ /** The whole step: the model's response and the tools it called, after the request was prepared. */
67
+ stepTimeMs?: number;
68
+ /** Time running the step's tool calls, summed. */
69
+ toolExecutionMs?: number;
70
+ /** Time running each tool call, by tool call id. */
71
+ toolCallMs?: Record<string, number>;
63
72
  cost?: SparkStepCost;
64
73
  usage?: unknown;
65
74
  };
@@ -121,6 +130,8 @@ export type SparkCompaction = {
121
130
  tokensBefore: number;
122
131
  tokensAfter: number;
123
132
  createdAt: string;
133
+ /** How long the summary request took. */
134
+ durationMs?: number;
124
135
  };
125
136
  export type ExecuteJavaScriptInput = {
126
137
  purpose: string;
@@ -373,6 +384,10 @@ export declare const sparkDataPartSchemas: {
373
384
  step: z.ZodNumber;
374
385
  toolNames: z.ZodArray<z.ZodString>;
375
386
  responseTimeMs: z.ZodNumber;
387
+ timeToFirstOutputMs: z.ZodOptional<z.ZodNumber>;
388
+ stepTimeMs: z.ZodOptional<z.ZodNumber>;
389
+ toolExecutionMs: z.ZodOptional<z.ZodNumber>;
390
+ toolCallMs: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNumber>>;
376
391
  cost: z.ZodOptional<z.ZodObject<{
377
392
  modelId: z.ZodString;
378
393
  pricingDate: z.ZodString;
@@ -404,6 +419,7 @@ export declare const sparkDataPartSchemas: {
404
419
  tokensBefore: z.ZodNumber;
405
420
  tokensAfter: z.ZodNumber;
406
421
  createdAt: z.ZodString;
422
+ durationMs: z.ZodOptional<z.ZodNumber>;
407
423
  }, z.core.$strip>;
408
424
  /**
409
425
  * A finished flow run, as an event. Hosts attach it to a user message, render
package/dist/ui.js CHANGED
@@ -103,6 +103,10 @@ export const sparkDataPartSchemas = {
103
103
  step: z.number().int().nonnegative(),
104
104
  toolNames: z.array(z.string()),
105
105
  responseTimeMs: z.number().nonnegative(),
106
+ timeToFirstOutputMs: z.number().nonnegative().optional(),
107
+ stepTimeMs: z.number().nonnegative().optional(),
108
+ toolExecutionMs: z.number().nonnegative().optional(),
109
+ toolCallMs: z.record(z.string(), z.number().nonnegative()).optional(),
106
110
  cost: sparkStepCostSchema.optional(),
107
111
  usage: z.unknown().optional(),
108
112
  }),
@@ -121,6 +125,7 @@ export const sparkDataPartSchemas = {
121
125
  tokensBefore: z.number().int().nonnegative(),
122
126
  tokensAfter: z.number().int().nonnegative(),
123
127
  createdAt: z.string().datetime(),
128
+ durationMs: z.number().nonnegative().optional(),
124
129
  }),
125
130
  /**
126
131
  * A finished flow run, as an event. Hosts attach it to a user message, render
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@womp/spark-agent",
3
- "version": "10.0.0",
3
+ "version": "10.1.1",
4
4
  "description": "Portable skills-based AI agent with local and durable chat transports for Womp",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",