@womp/spark-agent 10.0.0 → 10.1.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/CHANGELOG.md +19 -0
- package/dist/agent.js +8 -1
- package/dist/compaction.js +11 -7
- package/dist/ui.d.ts +16 -0
- package/dist/ui.js +5 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,25 @@ 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.0 — 2026-10-13
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Timings on the `step-metrics` data part, from the AI SDK's step performance, all optional in
|
|
12
|
+
`sparkDataPartSchemas`: `timeToFirstOutputMs` (until the model's first output chunk),
|
|
13
|
+
`stepTimeMs` (the model's response and the step's tool calls, after the request was prepared),
|
|
14
|
+
`toolExecutionMs` (the step's tool calls, summed) and `toolCallMs` (each tool call, by tool call
|
|
15
|
+
id).
|
|
16
|
+
- `durationMs` on `SparkCompaction` (the `compaction` data part, optional): how long the summary
|
|
17
|
+
request took.
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- `step-metrics` timings, `responseTimeMs` included, are whole milliseconds.
|
|
22
|
+
|
|
23
|
+
### Migration
|
|
24
|
+
|
|
25
|
+
- None. The fields are optional; readers on older versions accept stored parts that carry them and ignore the fields.
|
|
7
26
|
## 10.0.0 — 2026-10-13
|
|
8
27
|
|
|
9
28
|
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:
|
|
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
|
},
|
package/dist/compaction.js
CHANGED
|
@@ -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
|
|
189
|
-
if (
|
|
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
|
|
269
|
-
if (
|
|
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
|