@womp/spark-agent 9.5.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 CHANGED
@@ -4,6 +4,73 @@ 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.
26
+ ## 10.0.0 — 2026-10-13
27
+
28
+ The agent sets and changes a goal itself, from what the user says in chat, instead of proposing one
29
+ and waiting for the user to confirm it.
30
+
31
+ ### Added
32
+
33
+ - The `goal({ action, title?, conditions?, tries?, credits? })` tool, offered whenever the service
34
+ has `evaluateGoal`:
35
+ - `set` starts a goal at once with the calling run as its first try, with 5 tries, and 2,000
36
+ credits where the host has `readGoalCredits`, unless the call gives others. A goal the
37
+ conversation already has ends: as done if it was complete, replaced otherwise.
38
+ - `change` gives the goal new conditions, tries or credits. A condition whose words did not change
39
+ keeps what the checks found for it, in the goal and in `goal.tries`. If every measurable
40
+ condition is then already verified, the goal is complete at once.
41
+ - `continue` has a goal that stopped go on, with `GOAL_MORE_TRIES` (3) more tries if it had used
42
+ its tries.
43
+ - `remove` ends the goal, and the run goes on as an ordinary turn.
44
+ A goal that is set, changed or continued goes on with the calling run as its next try, unless it
45
+ is complete or still at a limit. Only a turn the user started may call the tool to effect, not a
46
+ try the service started, and not for a Wompify goal.
47
+ - The tool's result (`SparkGoalResult`) carries the goal's limits and `ended`
48
+ (`SparkGoalSummary`): the title, outcome, tries, credits and checks of the goal the call ended.
49
+ It stays in the conversation as the `tool-goal` part's output, for hosts to show past goals.
50
+ - `SparkAgentServiceOptions.onGoalChange`, called when a `goal` call changes what its run works
51
+ for or ends a goal, before the agent goes on. A change it refuses is undone.
52
+ - `SparkRunExecutionContext.handleGoal` and `SparkAgentOptions.handleGoal` (`SparkGoalHandler`)
53
+ carry the tool to the agent.
54
+
55
+ ### Removed
56
+
57
+ - The `propose_goal` tool, `SparkAgentServiceOptions.confirmGoal` and `onGoalStart`,
58
+ `SparkGoalOffer`, `sparkGoalDecisionSchema`, `sparkGoalProposalSchema` and their types, and the
59
+ wait in `requires_action` for the user's answer.
60
+ - The `data-goal-proposal` part and `sparkGoalProposalPartSchema`. A conversation that holds one no
61
+ longer validates.
62
+ - `GOAL_CONFIRMATION_DEFAULTS`.
63
+ - The standalone server's `POST /goal-proposals/:toolCallId`.
64
+
65
+ ### Migration
66
+
67
+ - Remove `confirmGoal` and the confirmation UI. Show a goal from the conversation's goal state, and
68
+ past goals from the `ended` of the `tool-goal` parts.
69
+ - A host that counted a goal's spending from `onGoalStart` does it from `onGoalChange`, which also
70
+ says when a run stops working for a goal.
71
+ - A host that offered `propose_goal` to some runs only passes or drops `handleGoal` the same way.
72
+ - A host that stores tool calls by name must accept `goal`.
73
+
7
74
  ## 9.5.0 — 2026-10-13
8
75
 
9
76
  ### Added
package/README.md CHANGED
@@ -149,17 +149,17 @@ Conversation settings contain `modelId` and `reasoningEffort`; save them with
149
149
  `transport.saveConversationSettings(id, settings)`. The goal endpoint accepts `set`, `pause`,
150
150
  `resume`, `clear`, and `update_budget` commands.
151
151
 
152
- A goal starts from an ordinary message, when the agent proposes one. A host that sets
153
- `SparkAgentServiceOptions.confirmGoal` (with `evaluateGoal`) gives the agent the `propose_goal`
154
- tool: it calls it before building when the request sets constraints a result can be measured
155
- against, with a title and the conditions, each marked `measurable` or left to the user's review.
156
- The run then waits in `requires_action` while `confirmGoal` shows the proposal, which the
157
- assistant message stores as a `data-goal-proposal` part, and resolves the user's answer: `{ kind: "goal", maxTurns,
158
- creditBudget }`, `{ kind: "once" }`, or `{ kind: "unanswered" }` when the host stops waiting. A
159
- confirmed goal starts with that run as its first try; the service evaluates each measurable
160
- condition after every try and records the result on `goal.conditions`. Any other answer leaves an
161
- ordinary turn. The part then carries the `outcome`: `started`, `declined`, `unanswered`, or `active`
162
- when a goal was already running. `onGoalStart` tells a host that counts a goal's spending when one starts.
152
+ A goal starts from an ordinary message, when the agent sets one, and changes when the user asks in
153
+ chat. A service with `evaluateGoal` gives the agent the `goal` tool. With `set` it starts a goal
154
+ before building, when the request sets constraints a result can be measured against, from a title
155
+ and the conditions, each marked `measurable` or left to the user's review. The goal starts at once,
156
+ with that run as its first try and with 5 tries and 2,000 credits unless the call gives others; the
157
+ service evaluates each measurable condition after every try and records the result on
158
+ `goal.conditions`. `change` gives the goal new conditions or limits, `continue` has a stopped goal
159
+ go on, and `remove` ends it; after a change the goal goes on in that turn. A `set` over an existing
160
+ goal ends that one, and the call's result keeps its summary as `ended`. `onGoalChange` tells a host
161
+ that counts a goal's spending when a run starts or stops working for one. A host leaves
162
+ `handleGoal` out of the run it executes to withhold the tool.
163
163
 
164
164
  The SSE response contains ordered persistence envelopes around standard AI SDK chunks:
165
165
 
@@ -43,7 +43,7 @@ export declare function runAgent(options: RunOptions): Promise<{
43
43
  } | undefined;
44
44
  conversationId: string | null;
45
45
  runId: string | null;
46
- status: "completed" | "queued" | "running" | "requires_action" | "failed" | "cancelled" | "incomplete";
46
+ status: "running" | "completed" | "queued" | "requires_action" | "failed" | "cancelled" | "incomplete";
47
47
  finalAnswer: string;
48
48
  durationMs: number | null;
49
49
  steps: number;
@@ -1,21 +1,15 @@
1
1
  import { type Tool } from "ai";
2
2
  import type { ExecutionReceipt, SparkArtifactResolver, SparkCapabilities } from "./capabilities.js";
3
3
  import type { JavaScriptExecutor } from "./executor.js";
4
- import { type SparkGoalOutcome, type SparkGoalProposal } from "./goals.js";
4
+ import { type SparkGoalRequest, type SparkGoalResult } from "./goals.js";
5
5
  import type { SparkUIMessage, SparkUIMessageChunk, SparkUITools } from "./ui.js";
6
6
  export type SparkToolCall = {
7
7
  id: string;
8
- name: "read_skill" | "execute_javascript" | "propose_goal";
8
+ name: "read_skill" | "execute_javascript" | "goal";
9
9
  input: unknown;
10
10
  };
11
- /**
12
- * Shows the user a goal the model proposed and waits for their answer, starting
13
- * the goal for this run when they confirm it.
14
- */
15
- export type SparkGoalOffer = (proposal: SparkGoalProposal, call: {
16
- toolCallId: string;
17
- signal: AbortSignal;
18
- }) => Promise<SparkGoalOutcome>;
11
+ /** Carries out a `goal` call for the run that made it. */
12
+ export type SparkGoalHandler = (request: SparkGoalRequest) => Promise<SparkGoalResult>;
19
13
  export interface SparkPersistence {
20
14
  beforeToolCall(call: SparkToolCall): Promise<void>;
21
15
  recordReceipt(callId: string, receipt: ExecutionReceipt): Promise<void>;
@@ -31,8 +25,8 @@ export type SparkToolOptions = {
31
25
  controller: AbortController;
32
26
  persistence?: SparkPersistence;
33
27
  executionTimeoutMs?: number;
34
- /** Present when the host can ask the user: the model then has `propose_goal`. */
35
- proposeGoal?: SparkGoalOffer;
28
+ /** Present when the host runs goals: the model then has `goal`. */
29
+ handleGoal?: SparkGoalHandler;
36
30
  write(chunk: SparkUIMessageChunk): void;
37
31
  };
38
32
  type SparkTool<Name extends keyof SparkUITools> = Tool<SparkUITools[Name]["input"], SparkUITools[Name]["output"]>;
@@ -40,7 +34,7 @@ type SparkCoreTools = {
40
34
  [Name in "read_skill" | "execute_javascript"]: SparkTool<Name>;
41
35
  };
42
36
  export type SparkTools = SparkCoreTools | (SparkCoreTools & {
43
- propose_goal: SparkTool<"propose_goal">;
37
+ goal: SparkTool<"goal">;
44
38
  });
45
39
  export declare function createSparkTools(options: SparkToolOptions): SparkTools;
46
40
  export {};
@@ -3,7 +3,7 @@ import { z } from "zod";
3
3
  import { boundedResultText, canonicalJsonValue } from "./bounded-output.js";
4
4
  import { completedInputString } from "./tool-input-label.js";
5
5
  import { UserWait } from "./execution-lifetime.js";
6
- import { sparkGoalProposalSchema } from "./goals.js";
6
+ import { GOAL_DEFAULT_CAPS, GOAL_MORE_TRIES, sparkGoalRequestSchema } from "./goals.js";
7
7
  function errorMessage(error) {
8
8
  return error instanceof Error ? error.message : String(error);
9
9
  }
@@ -22,13 +22,30 @@ const artifactRefSchema = z.object({
22
22
  mediaType: z.string().min(1),
23
23
  name: z.string().optional(),
24
24
  });
25
- /** What the model is told a proposal came to, and so what to do next. */
26
- const GOAL_OUTCOMES = {
27
- started: "The user confirmed the goal. Build it now, and verify every measurable condition with tool results before you finish. An independent check follows each try and sends back what is still unmet.",
28
- declined: "The user chose a single try. Carry out the request as usual and do not propose a goal for it again.",
29
- unanswered: "The user has not answered. Build nothing: say that you are waiting for their answer, and stop.",
30
- active: "A goal is already running in this conversation. Keep working toward it.",
31
- };
25
+ /** What the model is told a `goal` call did, and so what to do next. */
26
+ function goalResultText({ goal, tries, credits }) {
27
+ const limits = [
28
+ tries === undefined ? undefined : `${tries} ${tries === 1 ? "try" : "tries"}`,
29
+ credits === undefined ? undefined : `${credits.toLocaleString("en-US")} credits`,
30
+ ].filter(Boolean).join(" and ");
31
+ const upTo = limits ? `, up to ${limits}` : "";
32
+ switch (goal) {
33
+ case "started":
34
+ return `The goal is set and running${upTo}. Tell the user in one line that you set a goal from their message, its limits, and that they can tell you to stop or change anything. Then build it, and verify every measurable condition with tool results before you finish. An independent check follows each try and sends back what is still unmet.`;
35
+ case "running":
36
+ return `The goal is running${upTo}, with this turn as its next try. Confirm to the user in one line what changed, then keep working toward it.`;
37
+ case "done":
38
+ return "With this change every measurable condition is already verified, so the goal is done. Tell the user in one line.";
39
+ case "limited":
40
+ return `The goal is at its limit${upTo}, so it is not running. Tell the user in one line, and that it goes on when they ask for more.`;
41
+ case "removed":
42
+ return "The goal is removed. Tell the user in one line, and carry out their request as an ordinary turn.";
43
+ case "refused":
44
+ return "The goal cannot be set or changed in this turn: only the user's own message can do that, and not for a goal Wompify runs. Keep working toward the current goal.";
45
+ case "missing":
46
+ return "This conversation has no goal to change.";
47
+ }
48
+ }
32
49
  export function createSparkTools(options) {
33
50
  const { controller, persistence } = options;
34
51
  const executionTimeoutMs = options.executionTimeoutMs ?? 60_000;
@@ -84,35 +101,19 @@ export function createSparkTools(options) {
84
101
  onInputAvailable: ({ toolCallId }) => { inputs.delete(toolCallId); },
85
102
  };
86
103
  };
87
- const { proposeGoal } = options;
104
+ const { handleGoal } = options;
88
105
  return {
89
- ...(proposeGoal === undefined ? {} : {
90
- propose_goal: tool({
91
- description: "Offer to run the user's request as a goal: work that repeats until an independent check verifies its conditions. Call it once, before building or generating anything, when the request sets a constraint the finished result passes or fails by measurement: a size, a count, a limit, a fit to something real, a clearance, an angle, a weight, a price, or a physical requirement such as being one piece, resting on the ground or parts not intersecting. Do not call it for a question, a small direct edit, a request that only describes what to make, or while a goal is running. It shows the user the conditions and waits for their answer.",
92
- inputSchema: sparkGoalProposalSchema.extend({
93
- title: sparkGoalProposalSchema.shape.title.describe("Two to four words in sentence case naming what is being made."),
94
- conditions: sparkGoalProposalSchema.shape.conditions.describe("Only constraints the user stated or directly implied, never your own, each marked measurable. The description of what to make is not a list of constraints: leave out its parts and features, and any instruction about how to work, what to check or what to render. State each as a fact about the finished result in a few words of the user's language, with its number and unit: \"Height is 120 mm\", not \"Make it 120 mm tall\". Split compound constraints. If the user asked for a look, style, feel or quality that takes judgement, add it as one condition that is not measurable, left to their review."),
95
- }),
96
- execute: (input, { toolCallId }) => execute({ id: toolCallId, name: "propose_goal", input }, async () => {
97
- const status = (status, label) => options.write({ type: "data-run-status", data: { runId: options.runId, status, label } });
98
- // The message keeps the proposal, and then what became of it, under one id.
99
- const store = (outcome) => options.write({
100
- type: "data-goal-proposal", id: `goal-proposal-${toolCallId}`,
101
- data: { ...input, toolCallId, ...(outcome ? { outcome } : {}) },
102
- });
103
- store();
104
- status("requires_action", "Waiting for your answer");
105
- try {
106
- const goal = await proposeGoal(input, { toolCallId, signal: controller.signal });
107
- store(goal);
108
- return { goal };
109
- }
110
- finally {
111
- if (!controller.signal.aborted)
112
- status("running", "Continuing after user input");
113
- }
106
+ ...(handleGoal === undefined ? {} : {
107
+ goal: tool({
108
+ description: "Manage the conversation's goal: work that repeats, without the user, until an independent check verifies its conditions. Call it only for what the user's own message asks. set: start a goal for the request, once, before building or generating anything, when the request sets a constraint the finished result passes or fails by measurement: a size, a count, a limit, a fit to something real, a clearance, an angle, a weight, a price, or a physical requirement such as being one piece, resting on the ground or parts not intersecting. Do not set one for a question, a small direct edit, or a request that only describes what to make. The goal starts at once, with this turn as its first try, and ends a goal already there, so use it for a new request and not to adjust the current one. change: the user asked to add, drop or alter a condition, or for other limits. continue: the user asked to keep going with a goal that stopped. remove: the user wants the request done without a goal.",
109
+ inputSchema: sparkGoalRequestSchema.extend({
110
+ title: sparkGoalRequestSchema.shape.title.describe("For set: two to four words in sentence case naming what is being made."),
111
+ conditions: sparkGoalRequestSchema.shape.conditions.describe("For set, and for change when the conditions change: the full list. Only constraints the user stated or directly implied, never your own, each marked measurable. The description of what to make is not a list of constraints: leave out its parts and features, and any instruction about how to work, what to check or what to render. State each as a fact about the finished result in a few words of the user's language, with its number and unit: \"Height is 120 mm\", not \"Make it 120 mm tall\". Split compound constraints. If the user asked for a look, style, feel or quality that takes judgement, add it as one condition that is not measurable, left to their review. Keep a condition's words as they are when it does not change."),
112
+ tries: sparkGoalRequestSchema.shape.tries.describe(`For set or change: the most tries the goal may take, when the user gave a number. A new goal otherwise gets ${GOAL_DEFAULT_CAPS.tries}, and continue adds ${GOAL_MORE_TRIES} to one that used its tries.`),
113
+ credits: sparkGoalRequestSchema.shape.credits.describe(`For set or change: the most credits the goal may spend, when the user gave a number. A new goal otherwise gets ${GOAL_DEFAULT_CAPS.credits.toLocaleString("en-US")}.`),
114
114
  }),
115
- toModelOutput: ({ output }) => ({ type: "text", value: GOAL_OUTCOMES[output.goal] }),
115
+ execute: (input, { toolCallId }) => execute({ id: toolCallId, name: "goal", input }, () => handleGoal(input)),
116
+ toModelOutput: ({ output }) => ({ type: "text", value: goalResultText(output) }),
116
117
  }),
117
118
  }),
118
119
  read_skill: tool({
package/dist/agent.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { streamText, type LanguageModel, type ModelMessage } from "ai";
2
- import { type SparkGoalOffer, type SparkPersistence } from "./agent-tools.js";
2
+ import { type SparkGoalHandler, type SparkPersistence } from "./agent-tools.js";
3
3
  import type { SparkArtifactResolver, SparkCapabilities } from "./capabilities.js";
4
4
  import type { JavaScriptExecutor } from "./executor.js";
5
5
  import { type SparkCompactionLimits } from "./compaction.js";
@@ -34,8 +34,8 @@ export type SparkAgentOptions = {
34
34
  maxOutputTokens?: number;
35
35
  executionTimeoutMs?: number;
36
36
  persistence?: SparkPersistence;
37
- /** Gives the model `propose_goal`; absent, it has no way to offer a goal. */
38
- proposeGoal?: SparkGoalOffer;
37
+ /** Gives the model `goal`; absent, it has no way to set or change a goal. */
38
+ handleGoal?: SparkGoalHandler;
39
39
  prepareMessages?(messages: ModelMessage[]): Promise<ModelMessage[]>;
40
40
  /** The model's context window, which caps when `history` is compacted. Absent: `contextWindowFor(modelId)`. */
41
41
  contextWindow?: number;
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
  },
package/dist/client.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import type { ChatRequestOptions, ChatTransport, UIMessageChunk } from "ai";
2
2
  import type { SparkRunSettings } from "./server/types.js";
3
3
  import type { SparkGoal, SparkGoalCommand } from "./goals.js";
4
- export type { SparkGoal, SparkGoalCommand, SparkGoalCondition, SparkGoalDecision, SparkGoalProposal, SparkGoalTry } from "./goals.js";
4
+ export type { SparkGoal, SparkGoalCommand, SparkGoalCondition, SparkGoalTry } from "./goals.js";
5
5
  import type { SparkConversation, SparkConversationSummary, SparkRun } from "./server/types.js";
6
6
  import type { SparkUIMessage } from "./ui.js";
7
7
  export type { SparkConversation, SparkConversationSummary, SparkRun, SparkRunSettings, } from "./server/types.js";
@@ -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/goals.d.ts CHANGED
@@ -22,56 +22,63 @@ export type SparkGoalTry = {
22
22
  /** In the order of the goal's conditions; a condition left to the user has no result. */
23
23
  conditions: Pick<SparkGoalCondition, "met" | "reason">[];
24
24
  };
25
- /** The goal the agent proposes for a request, for the user to confirm before it starts. */
26
- export declare const sparkGoalProposalSchema: z.ZodObject<{
27
- title: z.ZodString;
28
- conditions: z.ZodArray<z.ZodObject<{
29
- text: z.ZodString;
30
- measurable: z.ZodBoolean;
31
- }, z.core.$strip>>;
32
- }, z.core.$strip>;
33
- export type SparkGoalProposal = z.infer<typeof sparkGoalProposalSchema>;
34
- /**
35
- * How the user answered a proposed goal: run it with these caps, try the request
36
- * once, or nothing in the time the host waits.
37
- */
38
- export declare const sparkGoalDecisionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
39
- creditBudget: z.ZodOptional<z.ZodNumber>;
40
- maxTurns: z.ZodOptional<z.ZodNumber>;
41
- kind: z.ZodLiteral<"goal">;
42
- }, z.core.$strip>, z.ZodObject<{
43
- kind: z.ZodLiteral<"once">;
44
- }, z.core.$strip>, z.ZodObject<{
45
- kind: z.ZodLiteral<"unanswered">;
46
- }, z.core.$strip>], "kind">;
47
- export type SparkGoalDecision = z.infer<typeof sparkGoalDecisionSchema>;
48
- /** What became of a proposal, as the agent is told: `active` when a goal was already running. */
49
- export declare const SPARK_GOAL_OUTCOMES: readonly ["started", "declined", "unanswered", "active"];
50
- export type SparkGoalOutcome = (typeof SPARK_GOAL_OUTCOMES)[number];
25
+ /** The caps of a goal the agent sets, unless the user asked for others. */
26
+ export declare const GOAL_DEFAULT_CAPS: {
27
+ readonly tries: 5;
28
+ readonly credits: 2000;
29
+ };
30
+ /** The tries a goal that used its tries gets when the user has it keep going. */
31
+ export declare const GOAL_MORE_TRIES = 3;
51
32
  /**
52
- * A proposal as its message stores it: the `propose_goal` call that made it, and
53
- * its outcome once there is one. Without an outcome it is waiting for the user
54
- * while its run is, and was left unanswered once that run has ended.
33
+ * What the agent asks with the `goal` tool, for the user. `set` starts a goal
34
+ * from `title` and `conditions`, at once, with the asking run as its first try;
35
+ * a goal the conversation already has ends. `change` gives the goal new
36
+ * `conditions`, `tries` or `credits`. `continue` has a goal that stopped go on.
37
+ * `remove` ends the goal. After a change the goal goes on, with the asking run
38
+ * as its next try.
55
39
  */
56
- export declare const sparkGoalProposalPartSchema: z.ZodObject<{
57
- title: z.ZodString;
58
- conditions: z.ZodArray<z.ZodObject<{
40
+ export declare const sparkGoalRequestSchema: z.ZodObject<{
41
+ action: z.ZodEnum<{
42
+ set: "set";
43
+ remove: "remove";
44
+ change: "change";
45
+ continue: "continue";
46
+ }>;
47
+ title: z.ZodOptional<z.ZodString>;
48
+ conditions: z.ZodOptional<z.ZodArray<z.ZodObject<{
59
49
  text: z.ZodString;
60
50
  measurable: z.ZodBoolean;
61
- }, z.core.$strip>>;
62
- toolCallId: z.ZodString;
63
- outcome: z.ZodOptional<z.ZodEnum<{
64
- active: "active";
65
- unanswered: "unanswered";
66
- started: "started";
67
- declined: "declined";
68
- }>>;
51
+ }, z.core.$strip>>>;
52
+ tries: z.ZodOptional<z.ZodNumber>;
53
+ credits: z.ZodOptional<z.ZodNumber>;
69
54
  }, z.core.$strip>;
70
- export type SparkGoalProposalPart = z.infer<typeof sparkGoalProposalPartSchema>;
71
- /** The caps a goal confirmation offers before the user changes them. */
72
- export declare const GOAL_CONFIRMATION_DEFAULTS: {
73
- readonly tries: 5;
74
- readonly credits: 2000;
55
+ export type SparkGoalRequest = z.infer<typeof sparkGoalRequestSchema>;
56
+ /**
57
+ * What a `goal` call did. `started`: a goal is set and running. `running`: the
58
+ * goal goes on with the change. `done`: with the change every measurable
59
+ * condition is already verified. `limited`: the goal is at its tries or credit
60
+ * limit and does not run. `removed`: the goal is gone. `refused`: nothing
61
+ * changed, since only a turn the user started may change a goal, and not one
62
+ * Wompify runs. `missing`: there is no goal to change.
63
+ */
64
+ export type SparkGoalOutcome = "started" | "running" | "done" | "limited" | "removed" | "refused" | "missing";
65
+ /** A goal that ended, as the chat keeps it once the conversation has moved on. */
66
+ export type SparkGoalSummary = {
67
+ title: string;
68
+ outcome: "done" | "replaced" | "removed";
69
+ /** The tries it finished. */
70
+ tries: number;
71
+ credits?: number;
72
+ /** Of its `measured` conditions, how many its last check found met. */
73
+ passed: number;
74
+ measured: number;
75
+ };
76
+ /** A `goal` call's result: the goal's limits where it has a goal, and the goal the call ended. */
77
+ export type SparkGoalResult = {
78
+ goal: SparkGoalOutcome;
79
+ tries?: number;
80
+ credits?: number;
81
+ ended?: SparkGoalSummary;
75
82
  };
76
83
  export type SparkGoal = {
77
84
  id: string;
package/dist/goals.js CHANGED
@@ -15,33 +15,25 @@ const goalCaps = {
15
15
  creditBudget: z.number().int().positive().max(1_000_000_000).optional(),
16
16
  maxTurns: z.number().int().min(1).max(100).optional(),
17
17
  };
18
- /** The goal the agent proposes for a request, for the user to confirm before it starts. */
19
- export const sparkGoalProposalSchema = z.object({
20
- title: z.string().trim().min(1).max(80),
21
- conditions: z.array(sparkGoalConditionSchema).min(1).max(MAX_GOAL_CONDITIONS),
22
- });
23
- /**
24
- * How the user answered a proposed goal: run it with these caps, try the request
25
- * once, or nothing in the time the host waits.
26
- */
27
- export const sparkGoalDecisionSchema = z.discriminatedUnion("kind", [
28
- z.object({ kind: z.literal("goal"), ...goalCaps }),
29
- z.object({ kind: z.literal("once") }),
30
- z.object({ kind: z.literal("unanswered") }),
31
- ]);
32
- /** What became of a proposal, as the agent is told: `active` when a goal was already running. */
33
- export const SPARK_GOAL_OUTCOMES = ["started", "declined", "unanswered", "active"];
18
+ /** The caps of a goal the agent sets, unless the user asked for others. */
19
+ export const GOAL_DEFAULT_CAPS = { tries: 5, credits: 2_000 };
20
+ /** The tries a goal that used its tries gets when the user has it keep going. */
21
+ export const GOAL_MORE_TRIES = 3;
34
22
  /**
35
- * A proposal as its message stores it: the `propose_goal` call that made it, and
36
- * its outcome once there is one. Without an outcome it is waiting for the user
37
- * while its run is, and was left unanswered once that run has ended.
23
+ * What the agent asks with the `goal` tool, for the user. `set` starts a goal
24
+ * from `title` and `conditions`, at once, with the asking run as its first try;
25
+ * a goal the conversation already has ends. `change` gives the goal new
26
+ * `conditions`, `tries` or `credits`. `continue` has a goal that stopped go on.
27
+ * `remove` ends the goal. After a change the goal goes on, with the asking run
28
+ * as its next try.
38
29
  */
39
- export const sparkGoalProposalPartSchema = sparkGoalProposalSchema.extend({
40
- toolCallId: z.string().min(1),
41
- outcome: z.enum(SPARK_GOAL_OUTCOMES).optional(),
30
+ export const sparkGoalRequestSchema = z.object({
31
+ action: z.enum(["set", "change", "continue", "remove"]),
32
+ title: z.string().trim().min(1).max(80).optional(),
33
+ conditions: z.array(sparkGoalConditionSchema).min(1).max(MAX_GOAL_CONDITIONS).optional(),
34
+ tries: goalCaps.maxTurns,
35
+ credits: goalCaps.creditBudget,
42
36
  });
43
- /** The caps a goal confirmation offers before the user changes them. */
44
- export const GOAL_CONFIRMATION_DEFAULTS = { tries: 5, credits: 2_000 };
45
37
  export const sparkGoalCommandSchema = z.discriminatedUnion("action", [
46
38
  z.object({
47
39
  action: z.literal("set"),