@ouispec/agent-worker 0.3.0 → 0.7.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 (56) hide show
  1. package/README.md +27 -2
  2. package/dist/approvals/client.d.ts +20 -1
  3. package/dist/approvals/client.d.ts.map +1 -1
  4. package/dist/approvals/client.js +25 -0
  5. package/dist/approvals/client.js.map +1 -1
  6. package/dist/approvals/continuation.d.ts +47 -1
  7. package/dist/approvals/continuation.d.ts.map +1 -1
  8. package/dist/approvals/continuation.js +97 -1
  9. package/dist/approvals/continuation.js.map +1 -1
  10. package/dist/index.d.ts +5 -1
  11. package/dist/index.d.ts.map +1 -1
  12. package/dist/index.js +5 -0
  13. package/dist/index.js.map +1 -1
  14. package/dist/lambda/handler.d.ts +2 -2
  15. package/dist/lambda/handler.d.ts.map +1 -1
  16. package/dist/lambda/handler.js +3 -2
  17. package/dist/lambda/handler.js.map +1 -1
  18. package/dist/orchestrator.d.ts.map +1 -1
  19. package/dist/orchestrator.js +504 -84
  20. package/dist/orchestrator.js.map +1 -1
  21. package/dist/runtime/turn-runner.d.ts +21 -2
  22. package/dist/runtime/turn-runner.d.ts.map +1 -1
  23. package/dist/runtime/turn-runner.js +106 -12
  24. package/dist/runtime/turn-runner.js.map +1 -1
  25. package/dist/runtime/types.d.ts +63 -6
  26. package/dist/runtime/types.d.ts.map +1 -1
  27. package/dist/stop/partial.d.ts +49 -0
  28. package/dist/stop/partial.d.ts.map +1 -0
  29. package/dist/stop/partial.js +73 -0
  30. package/dist/stop/partial.js.map +1 -0
  31. package/dist/stop/results.d.ts +20 -0
  32. package/dist/stop/results.d.ts.map +1 -0
  33. package/dist/stop/results.js +46 -0
  34. package/dist/stop/results.js.map +1 -0
  35. package/dist/stop/turn-stop.d.ts +114 -0
  36. package/dist/stop/turn-stop.d.ts.map +1 -0
  37. package/dist/stop/turn-stop.js +155 -0
  38. package/dist/stop/turn-stop.js.map +1 -0
  39. package/dist/tools/types.d.ts +7 -0
  40. package/dist/tools/types.d.ts.map +1 -1
  41. package/dist/tools/types.js.map +1 -1
  42. package/dist/types.d.ts +79 -2
  43. package/dist/types.d.ts.map +1 -1
  44. package/dist/ui/knowledge.d.ts +28 -2
  45. package/dist/ui/knowledge.d.ts.map +1 -1
  46. package/dist/ui/knowledge.js +117 -13
  47. package/dist/ui/knowledge.js.map +1 -1
  48. package/dist/ui/newest-page-state.d.ts +25 -0
  49. package/dist/ui/newest-page-state.d.ts.map +1 -0
  50. package/dist/ui/newest-page-state.js +91 -0
  51. package/dist/ui/newest-page-state.js.map +1 -0
  52. package/dist/ui/ui-tools.d.ts +20 -2
  53. package/dist/ui/ui-tools.d.ts.map +1 -1
  54. package/dist/ui/ui-tools.js +65 -6
  55. package/dist/ui/ui-tools.js.map +1 -1
  56. package/package.json +6 -6
@@ -16,7 +16,8 @@ import type { ToolPolicy } from '../authz/tool-policy.js';
16
16
  import type { UIActionChannel } from '../ui/channel.js';
17
17
  import type { LanguageModel, ProviderOptions } from '../model.js';
18
18
  import type { ApprovalStoreClient } from '../approvals/client.js';
19
- import type { ApprovalContinuation } from '@ouispec/agent-core';
19
+ import type { ApprovalContinuation, TurnStopReason, TurnStoppedMarker } from '@ouispec/agent-core';
20
+ import type { TurnStopClient } from '../stop/turn-stop.js';
20
21
  /**
21
22
  * Database handle — opaque to the SDK. The integrator's callbacks receive
22
23
  * whatever they return from `getDb` so they can use it directly.
@@ -41,6 +42,24 @@ export interface AgentTurnPayload {
41
42
  * token to redeem, or that they declined (ADR-0228 §2.2.5).
42
43
  */
43
44
  approval?: ApprovalContinuation;
45
+ /**
46
+ * The turns of this conversation that this turn supersedes (ADR-0252 §2.5):
47
+ * the host asked each to stop when this turn's message arrived. The host's
48
+ * `getHistory` is given them, to wait until each is stored before it reads.
49
+ */
50
+ supersedes?: string[];
51
+ }
52
+ /** What `getHistory` is told of the turn it reads for. */
53
+ export interface HistoryRequest {
54
+ turnId: string;
55
+ /** The turns this one supersedes, which must be stored (or given up on) before history is read. */
56
+ supersedes: readonly string[];
57
+ /**
58
+ * Aborts when this turn is itself asked to stop while it waits: a wait for
59
+ * earlier turns should end then, since the turn will store only that it was
60
+ * stopped and reads no history.
61
+ */
62
+ signal: AbortSignal;
44
63
  }
45
64
  /**
46
65
  * Configuration for the agent runtime, whichever adapter hosts it.
@@ -151,6 +170,14 @@ export interface AgentRuntimeConfig<TDb = IntegratorDb> {
151
170
  channel?: UIActionChannel;
152
171
  /** How long a UI tool waits for the client's answer. Default 20 s. */
153
172
  resultTimeoutMs?: number;
173
+ /**
174
+ * The longest a UI tool waits, in the call, for the outcome of work its
175
+ * action started (a GPU job, an export). Work that ends within it is
176
+ * reported done; work that does not is reported still running, and the
177
+ * turn ends: its outcome is in the page state the next turn reads.
178
+ * Default 20 s (`DEFAULT_JOB_WAIT_MS`).
179
+ */
180
+ jobWaitMs?: number;
154
181
  /** Largest page-state payload given to the model, in characters. Default 12000 (`DEFAULT_PAGE_STATE_CHARS`). */
155
182
  maxObservationChars?: number;
156
183
  /** Longest the page's index is in the model's context, in characters, before its furthest surfaces are listed by action id only. Default 60000 (`DEFAULT_INDEX_CHARS`, ADR-0245). */
@@ -163,6 +190,15 @@ export interface AgentRuntimeConfig<TDb = IntegratorDb> {
163
190
  approvals?: {
164
191
  store?: ApprovalStoreClient;
165
192
  };
193
+ /**
194
+ * Stopping a turn (ADR-0252). The stop request is kept by the realtime
195
+ * server, and the turn asks for it there unless `client` says otherwise.
196
+ */
197
+ stops?: {
198
+ client?: TurnStopClient;
199
+ /** How long after a stop an answer already on its way is still waited for. Default 2 s. */
200
+ graceMs?: number;
201
+ };
166
202
  /**
167
203
  * Returns a database client/handle. Called once per invocation.
168
204
  * The returned value is passed to `getHistory` and `persistMessages`.
@@ -176,10 +212,17 @@ export interface AgentRuntimeConfig<TDb = IntegratorDb> {
176
212
  *
177
213
  * The SDK handles appending the current user message — don't include it.
178
214
  */
179
- getHistory: (conversationId: string, db: TDb) => Promise<TurnHistoryMessage[]>;
215
+ getHistory: (conversationId: string, db: TDb, turn: HistoryRequest) => Promise<TurnHistoryMessage[]>;
180
216
  /**
181
- * Persists the new messages generated during this turn.
182
- * Called after the turn completes successfully.
217
+ * Persists the new messages generated during this turn. Called once, before
218
+ * the client is told the turn ended, whether it ended by itself or was
219
+ * stopped (`stopped` is then set, and the last assistant message carries the
220
+ * same marker: ADR-0252 §2.3).
221
+ *
222
+ * A host that lets a newer turn give up on this one (ADR-0252 §2.5) answers
223
+ * `{ stored: false }` when it found the turn already given up on and stored
224
+ * nothing. The turn is still announced, and nothing that depends on its
225
+ * messages being stored (an expired approval's confirmation) is done.
183
226
  */
184
227
  persistMessages: (input: {
185
228
  turnId: string;
@@ -190,11 +233,20 @@ export interface AgentRuntimeConfig<TDb = IntegratorDb> {
190
233
  completionTokens: number;
191
234
  totalTokens: number;
192
235
  };
236
+ stopped?: TurnStoppedMarker;
193
237
  db: TDb;
194
- }) => Promise<void>;
238
+ }) => Promise<void | {
239
+ stored: false;
240
+ }>;
195
241
  /**
196
242
  * Optional: record turn start in your database. Receives the db handle.
197
243
  * Default: no-op (the SDK still emits `agent:turn_started` to realtime).
244
+ *
245
+ * A host that keeps a row per turn claims it here. Answering
246
+ * `{ run: false, reason }` says the turn must not run: its row shows it
247
+ * already ended or was given up on, which is what a queue's redelivery of
248
+ * an old turn finds (ADR-0252 §2.5). The turn then does nothing: no model
249
+ * call, no UI action, no event to the client.
198
250
  */
199
251
  recordTurnStart?: (input: {
200
252
  turnId: string;
@@ -203,7 +255,10 @@ export interface AgentRuntimeConfig<TDb = IntegratorDb> {
203
255
  accountId: string;
204
256
  model: string;
205
257
  db: TDb;
206
- }) => Promise<void>;
258
+ }) => Promise<void | {
259
+ run: false;
260
+ reason: string;
261
+ }>;
207
262
  /**
208
263
  * Optional: record turn completion. Default: no-op.
209
264
  */
@@ -216,6 +271,8 @@ export interface AgentRuntimeConfig<TDb = IntegratorDb> {
216
271
  completionTokens: number;
217
272
  totalTokens: number;
218
273
  };
274
+ /** Set when the turn was stopped rather than ending by itself (ADR-0252). */
275
+ stopReason?: TurnStopReason;
219
276
  db: TDb;
220
277
  }) => Promise<void>;
221
278
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/runtime/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACxD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AACnE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAC1D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAClE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAEhE;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC;AAEnC;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,CAAC;IACf,cAAc,EAAE,MAAM,CAAC;IACvB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;IACnB,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC;IACzC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAA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ker on its last assistant message.
4
+ *
5
+ * It is built from what the worker itself recorded as the turn ran: the text
6
+ * it streamed, the steps it saw end, and the calls its tools were asked to
7
+ * run. Nothing here reads the model stream's own results, which do not
8
+ * survive an abort, so it is the same whatever way the abort surfaces.
9
+ */
10
+ import { type TurnStoppedMarker } from '@ouispec/agent-core';
11
+ import type { TurnMessage } from '../types.js';
12
+ /** A step the turn saw end: its text, and the calls the model made in it. */
13
+ export interface RecordedStep {
14
+ text: string;
15
+ toolCalls: ReadonlyArray<{
16
+ toolCallId: string;
17
+ toolName: string;
18
+ input: unknown;
19
+ }>;
20
+ }
21
+ /** A call a tool of the turn was asked to run, in the order the calls arrived. */
22
+ export interface RecordedCall {
23
+ toolCallId: string;
24
+ /** The tool as the model called it (`ui_act` for a page action). */
25
+ toolName: string;
26
+ input: unknown;
27
+ /** Its result as the model would read it; null while it has not settled. */
28
+ text: string | null;
29
+ }
30
+ /**
31
+ * The stopped turn's messages, each call with exactly one result:
32
+ * - a call that settled keeps the result it gave, which for a call the stop
33
+ * cut short already says so (not run, or sent with its outcome unknown);
34
+ * - a call still unsettled when the grace ended is stored as running when the
35
+ * turn was stopped, its outcome unknown.
36
+ *
37
+ * The last assistant message carries the marker. A turn that produced no
38
+ * text and no call still stores one assistant message, whose text is the
39
+ * marker's line: a model provider refuses an empty text block, and the
40
+ * conversation never holds two user messages with nothing between them.
41
+ */
42
+ export declare function stoppedTurnMessages(recorded: {
43
+ steps: readonly RecordedStep[];
44
+ calls: readonly RecordedCall[];
45
+ /** Every piece of reply text the turn streamed, in order. */
46
+ streamedText: string;
47
+ marker: TurnStoppedMarker;
48
+ }): TurnMessage[];
49
+ //# sourceMappingURL=partial.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"partial.d.ts","sourceRoot":"","sources":["../../src/stop/partial.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,EAAmB,KAAK,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAC9E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG/C,6EAA6E;AAC7E,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,aAAa,CAAC;QAAE,UAAU,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC;CACpF;AAED,kFAAkF;AAClF,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,MAAM,CAAC;IACnB,oEAAoE;IACpE,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,OAAO,CAAC;IACf,4EAA4E;IAC5E,IAAI,EAAE,MAAM,GAAG,IAAI,CAAC;CACrB;AAKD;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE;IAC5C,KAAK,EAAE,SAAS,YAAY,EAAE,CAAC;IAC/B,KAAK,EAAE,SAAS,YAAY,EAAE,CAAC;IAC/B,6DAA6D;IAC7D,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,EAAE,iBAAiB,CAAC;CAC3B,GAAG,WAAW,EAAE,CAgDhB"}
@@ -0,0 +1,73 @@
1
+ /**
2
+ * What a stopped turn stores (ADR-0252 §2.3): the steps it finished, the step
3
+ * it was in, and a marker on its last assistant message.
4
+ *
5
+ * It is built from what the worker itself recorded as the turn ran: the text
6
+ * it streamed, the steps it saw end, and the calls its tools were asked to
7
+ * run. Nothing here reads the model stream's own results, which do not
8
+ * survive an abort, so it is the same whatever way the abort surfaces.
9
+ */
10
+ import { turnStoppedNote } from '@ouispec/agent-core';
11
+ import { resultText, stoppedWhileRunning } from './results.js';
12
+ const asArguments = (input) => input && typeof input === 'object' && !Array.isArray(input) ? input : {};
13
+ /**
14
+ * The stopped turn's messages, each call with exactly one result:
15
+ * - a call that settled keeps the result it gave, which for a call the stop
16
+ * cut short already says so (not run, or sent with its outcome unknown);
17
+ * - a call still unsettled when the grace ended is stored as running when the
18
+ * turn was stopped, its outcome unknown.
19
+ *
20
+ * The last assistant message carries the marker. A turn that produced no
21
+ * text and no call still stores one assistant message, whose text is the
22
+ * marker's line: a model provider refuses an empty text block, and the
23
+ * conversation never holds two user messages with nothing between them.
24
+ */
25
+ export function stoppedTurnMessages(recorded) {
26
+ const { steps, calls, streamedText, marker } = recorded;
27
+ const byId = new Map(calls.map((call) => [call.toolCallId, call]));
28
+ const messages = [];
29
+ const push = (text, stepCalls) => {
30
+ // Whitespace alone is no text: a provider refuses that block too.
31
+ const content = text.trim() ? text : null;
32
+ if (content === null && stepCalls.length === 0)
33
+ return;
34
+ messages.push({
35
+ role: 'assistant',
36
+ content,
37
+ ...(stepCalls.length > 0
38
+ ? { toolCalls: stepCalls.map((c) => ({ id: c.toolCallId, name: c.toolName, arguments: asArguments(c.input) })) }
39
+ : {}),
40
+ });
41
+ for (const call of stepCalls) {
42
+ messages.push({
43
+ role: 'tool',
44
+ content: byId.get(call.toolCallId)?.text ?? resultText(stoppedWhileRunning(call.toolName)),
45
+ toolCallId: call.toolCallId,
46
+ name: call.toolName,
47
+ });
48
+ }
49
+ };
50
+ const finished = new Set();
51
+ let finishedText = 0;
52
+ for (const step of steps) {
53
+ push(step.text, step.toolCalls);
54
+ finishedText += step.text.length;
55
+ for (const call of step.toolCalls)
56
+ finished.add(call.toolCallId);
57
+ }
58
+ // The step the turn was in: the text streamed since the last step ended, and
59
+ // the calls no finished step holds.
60
+ push(streamedText.length > finishedText ? streamedText.slice(finishedText) : '', calls.filter((call) => !finished.has(call.toolCallId)));
61
+ let last;
62
+ for (let i = messages.length - 1; i >= 0 && !last; i--)
63
+ if (messages[i].role === 'assistant')
64
+ last = messages[i];
65
+ if (!last) {
66
+ messages.push({ role: 'assistant', content: turnStoppedNote(marker), stopped: marker });
67
+ }
68
+ else {
69
+ last.stopped = marker;
70
+ }
71
+ return messages;
72
+ }
73
+ //# sourceMappingURL=partial.js.map
@@ -0,0 +1 @@
1
+ {"version":3,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CAAC;IAClC,KAAK,IAAI,CAAC,GAAG,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,EAAE;QAAE,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,WAAW;YAAE,IAAI,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC;IACjH,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,QAAQ,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,WAAW,EAAE,OAAO,EAAE,eAAe,CAAC,MAAM,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC;IAC1F,CAAC;SAAM,CAAC;QACN,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;IACxB,CAAC;IACD,OAAO,QAAQ,CAAC;AAClB,CAAC"}
@@ -0,0 +1,20 @@
1
+ /**
2
+ * What a call's result says when its turn was stopped before the call ended
3
+ * (ADR-0252 §2.2). Every call the model made keeps exactly one result, so the
4
+ * stored conversation is one a model accepts, and a later turn reads what
5
+ * became of each call instead of guessing.
6
+ */
7
+ import type { ToolExecutionResult } from '../tools/types.js';
8
+ /** The call never left the worker: nothing ran. */
9
+ export declare function stoppedNotRun(what: string): ToolExecutionResult;
10
+ /** The request went out, tabs answered that they got it, and none took it: it did not run. */
11
+ export declare function stoppedNotTaken(what: string): ToolExecutionResult;
12
+ /** The call was sent to the page and no answer came back before the turn ended. */
13
+ export declare function stoppedOutcomeUnknown(what: string): ToolExecutionResult;
14
+ /** A tool was running when the turn was stopped, and did not finish in time to say what it did. */
15
+ export declare function stoppedWhileRunning(what: string): ToolExecutionResult;
16
+ /** A read of the page that the stop cut short: nothing was changed, and nothing was learned. */
17
+ export declare function stoppedBeforeAnswer(what: string): ToolExecutionResult;
18
+ /** The text of a result, as a stored tool message carries it. */
19
+ export declare function resultText(result: ToolExecutionResult): string;
20
+ //# sourceMappingURL=results.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"results.d.ts","sourceRoot":"","sources":["../../src/stop/results.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAE7D,mDAAmD;AACnD,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,CAM/D;AAED,8FAA8F;AAC9F,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,CAMjE;AAED,mFAAmF;AACnF,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,CAQvE;AAED,mGAAmG;AACnG,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,CAMrE;AAED,gGAAgG;AAChG,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,mBAAmB,CAMrE;AAED,iEAAiE;AACjE,wBAAgB,UAAU,CAAC,MAAM,EAAE,mBAAmB,GAAG,MAAM,CAE9D"}
@@ -0,0 +1,46 @@
1
+ /** The call never left the worker: nothing ran. */
2
+ export function stoppedNotRun(what) {
3
+ return {
4
+ success: false,
5
+ error: `Not run: the turn was stopped before "${what}" was sent. Nothing was changed by it.`,
6
+ data: { stopped: true, notRun: true },
7
+ };
8
+ }
9
+ /** The request went out, tabs answered that they got it, and none took it: it did not run. */
10
+ export function stoppedNotTaken(what) {
11
+ return {
12
+ success: false,
13
+ error: `Not run: "${what}" was sent, and no open page took it before the turn was stopped. Nothing was changed by it.`,
14
+ data: { stopped: true, notRun: true },
15
+ };
16
+ }
17
+ /** The call was sent to the page and no answer came back before the turn ended. */
18
+ export function stoppedOutcomeUnknown(what) {
19
+ return {
20
+ success: false,
21
+ error: `"${what}" was sent to the page, and the turn was stopped before its answer arrived. It may have run: ` +
22
+ 'its outcome is unknown. Read what the page shows before doing anything that depends on it.',
23
+ data: { stopped: true, sent: true, outcome: 'unknown' },
24
+ };
25
+ }
26
+ /** A tool was running when the turn was stopped, and did not finish in time to say what it did. */
27
+ export function stoppedWhileRunning(what) {
28
+ return {
29
+ success: false,
30
+ error: `"${what}" was running when the turn was stopped. It did not finish in time to report: its outcome is unknown.`,
31
+ data: { stopped: true, sent: true, outcome: 'unknown' },
32
+ };
33
+ }
34
+ /** A read of the page that the stop cut short: nothing was changed, and nothing was learned. */
35
+ export function stoppedBeforeAnswer(what) {
36
+ return {
37
+ success: false,
38
+ error: `The turn was stopped before ${what} was answered. Nothing was changed.`,
39
+ data: { stopped: true, notRun: true },
40
+ };
41
+ }
42
+ /** The text of a result, as a stored tool message carries it. */
43
+ export function resultText(result) {
44
+ return JSON.stringify({ success: false, error: result.error, ...result.data });
45
+ }
46
+ //# sourceMappingURL=results.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"results.js","sourceRoot":"","sources":["../../src/stop/results.ts"],"names":[],"mappings":"AAQA,mDAAmD;AACnD,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,OAAO;QACL,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,yCAAyC,IAAI,wCAAwC;QAC5F,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE;KACtC,CAAC;AACJ,CAAC;AAED,8FAA8F;AAC9F,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,OAAO;QACL,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,aAAa,IAAI,8FAA8F;QACtH,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE;KACtC,CAAC;AACJ,CAAC;AAED,mFAAmF;AACnF,MAAM,UAAU,qBAAqB,CAAC,IAAY;IAChD,OAAO;QACL,OAAO,EAAE,KAAK;QACd,KAAK,EACH,IAAI,IAAI,+FAA+F;YACvG,4FAA4F;QAC9F,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE;KACxD,CAAC;AACJ,CAAC;AAED,mGAAmG;AACnG,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,OAAO;QACL,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,IAAI,IAAI,uGAAuG;QACtH,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE;KACxD,CAAC;AACJ,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,OAAO;QACL,OAAO,EAAE,KAAK;QACd,KAAK,EAAE,+BAA+B,IAAI,qCAAqC;QAC/E,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE;KACtC,CAAC;AACJ,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,UAAU,CAAC,MAA2B;IACpD,OAAO,IAAI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,GAAI,MAAM,CAAC,IAAgC,EAAE,CAAC,CAAC;AAC9G,CAAC"}
@@ -0,0 +1,114 @@
1
+ /**
2
+ * Hearing that a turn has been asked to stop (ADR-0252 §2.1).
3
+ *
4
+ * The worker has no socket. The realtime server keeps a stop request (the
5
+ * person's Stop, or the host's when a newer message supersedes the turn), and
6
+ * the worker asks for it for as long as the turn runs, as it asks for UI
7
+ * answers and approvals.
8
+ */
9
+ import type { TurnStopReason, TurnStopRecord } from '@ouispec/agent-core';
10
+ /**
11
+ * Why a turn's work was aborted, as its abort signal's reason. The stop path
12
+ * is written against this type, so another cause that should also keep what
13
+ * the turn produced (its deadline) is one more value of `cause`.
14
+ */
15
+ export declare class TurnStopped extends Error {
16
+ readonly reason: TurnStopReason;
17
+ /** When it was asked for, epoch ms. */
18
+ readonly at: number;
19
+ readonly cause: "stopped";
20
+ constructor(reason: TurnStopReason,
21
+ /** When it was asked for, epoch ms. */
22
+ at: number);
23
+ }
24
+ /** The stop a signal was aborted with, or null when it was not aborted, or was for another cause. */
25
+ export declare function stopOf(signal: AbortSignal | undefined): TurnStopped | null;
26
+ /**
27
+ * What a tool is told of a stop: set on its context for the whole turn, and
28
+ * answering null until the turn is asked to stop. A tool that was waiting on
29
+ * something it sent uses `graceSignal`, never the turn's aborted signal, for
30
+ * the one last look it takes.
31
+ */
32
+ export interface TurnStopState {
33
+ /** Why the turn was stopped, or null while it has not been. */
34
+ reason(): TurnStopReason | null;
35
+ /** Aborts when the grace after a stop is over. A fresh signal: the turn's own is already aborted. */
36
+ graceSignal(): AbortSignal;
37
+ /** How long after a stop an answer already on its way is still waited for. */
38
+ graceMs: number;
39
+ }
40
+ /** How long after a stop an answer already on its way is still waited for (ADR-0252 §2.2). */
41
+ export declare const DEFAULT_STOP_GRACE_MS = 2000;
42
+ export interface TurnStopClient {
43
+ /**
44
+ * The stop asked for on `turnId` by `userId`, waiting for one until `signal`
45
+ * aborts. Resolves null when the signal aborts first. Never rejects: a
46
+ * failure to ask is retried, since the request is kept and is heard late
47
+ * rather than lost.
48
+ *
49
+ * The first question is asked without waiting, and `onChecked` is called
50
+ * once it is answered, whatever the answer, or has failed: from then a stop
51
+ * that was asked for before the watch began has been heard.
52
+ */
53
+ watch(turnId: string, userId: string, signal: AbortSignal, onChecked?: () => void): Promise<TurnStopRecord | null>;
54
+ }
55
+ export interface HttpTurnStopClientConfig {
56
+ /** The realtime server's base URL. */
57
+ url: string;
58
+ /** Its internal key. */
59
+ apiKey: string;
60
+ /** Longest single wait the realtime server is asked to hold open. Default 25 s. */
61
+ maxPollMs?: number;
62
+ /** The longest pause between attempts while the server cannot be reached. Default 5 s. */
63
+ maxBackoffMs?: number;
64
+ /** Where a failed attempt is reported. */
65
+ onError?: (error: unknown, attempt: number) => void;
66
+ /**
67
+ * Called once when the server answers that it has no such route (404): a
68
+ * realtime server from before stops were kept. The watch then ends, since
69
+ * asking again cannot help; the turn runs on and cannot be stopped.
70
+ */
71
+ onUnsupported?: () => void;
72
+ }
73
+ /** The longest a turn waits for the answer to its first question before it starts anyway. */
74
+ export declare const FIRST_CHECK_LIMIT_MS = 1500;
75
+ /**
76
+ * The stop record over the realtime server's internal HTTP API:
77
+ * `GET {url}/internal/turns/{turnId}/stop?userId=&waitMs=` (200 with the
78
+ * record, 204 when none was asked for in `waitMs`).
79
+ *
80
+ * It fails open. A failure (the server restarting, a 5xx) is retried with a
81
+ * growing pause, and the turn runs on meanwhile: a turn must never fail
82
+ * because it could not ask whether to stop. A 404 is not a failure to retry:
83
+ * it is a server that keeps no stops, said once, and the watch ends.
84
+ */
85
+ export declare function createHttpTurnStopClient(config: HttpTurnStopClientConfig): TurnStopClient;
86
+ /**
87
+ * One turn's watch for a stop: open from before the turn reads its history
88
+ * until the turn ends, so a stop asked for while the turn waited in a queue
89
+ * is the first thing it hears.
90
+ */
91
+ export interface TurnStopWatch {
92
+ /** The stop, once one has been heard; null until then. */
93
+ current(): TurnStopRecord | null;
94
+ /**
95
+ * Resolves once the watch has asked its first question and has the answer:
96
+ * a stop asked for before the turn started (while it waited in a queue) has
97
+ * been heard by then. It also resolves if the question failed, or took
98
+ * longer than `FIRST_CHECK_LIMIT_MS`: a turn is never held up, or failed,
99
+ * by not being able to ask.
100
+ */
101
+ checked(): Promise<void>;
102
+ /**
103
+ * Calls `listener` when a stop is heard, at once if one already was. At most
104
+ * once, and never after `close`.
105
+ */
106
+ onStop(listener: (record: TurnStopRecord) => void): void;
107
+ /**
108
+ * Stop watching, and ignore a stop that is heard from now on: the turn has
109
+ * begun its own end, and a stop that lands now is not one (ADR-0252 §2.4).
110
+ */
111
+ close(): void;
112
+ }
113
+ export declare function watchTurnStop(client: TurnStopClient | undefined, turnId: string, userId: string): TurnStopWatch;
114
+ //# sourceMappingURL=turn-stop.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"turn-stop.d.ts","sourceRoot":"","sources":["../../src/stop/turn-stop.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,O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aAAa,CAAC,EAAE,MAAM,IAAI,CAAC;CAC5B;AAGD,6FAA6F;AAC7F,eAAO,MAAM,oBAAoB,OAAQ,CAAC;AAI1C;;;;;;;;;GASG;AACH,wBAAgB,wBAAwB,CAAC,MAAM,EAAE,wBAAwB,GAAG,cAAc,CAsDzF;AAcD;;;;GAIG;AACH,MAAM,WAAW,aAAa;IAC5B,0DAA0D;IAC1D,OAAO,IAAI,cAAc,GAAG,IAAI,CAAC;IACjC;;;;;;OAMG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACzB;;;OAGG;IACH,MAAM,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,IAAI,GAAG,IAAI,CAAC;IACzD;;;OAGG;IACH,KAAK,IAAI,IAAI,CAAC;CACf;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,cAAc,GAAG,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,aAAa,CA6C/G"}
@@ -0,0 +1,155 @@
1
+ import { requireRealtime } from '../emit/http-adapter.js';
2
+ /**
3
+ * Why a turn's work was aborted, as its abort signal's reason. The stop path
4
+ * is written against this type, so another cause that should also keep what
5
+ * the turn produced (its deadline) is one more value of `cause`.
6
+ */
7
+ export class TurnStopped extends Error {
8
+ reason;
9
+ at;
10
+ cause = 'stopped';
11
+ constructor(reason,
12
+ /** When it was asked for, epoch ms. */
13
+ at) {
14
+ super(reason === 'superseded' ? 'The turn was superseded by a newer message' : 'The turn was stopped by the person');
15
+ this.reason = reason;
16
+ this.at = at;
17
+ this.name = 'TurnStopped';
18
+ }
19
+ }
20
+ /** The stop a signal was aborted with, or null when it was not aborted, or was for another cause. */
21
+ export function stopOf(signal) {
22
+ return signal?.aborted && signal.reason instanceof TurnStopped ? signal.reason : null;
23
+ }
24
+ /** How long after a stop an answer already on its way is still waited for (ADR-0252 §2.2). */
25
+ export const DEFAULT_STOP_GRACE_MS = 2_000;
26
+ const FIRST_BACKOFF_MS = 250;
27
+ /** The longest a turn waits for the answer to its first question before it starts anyway. */
28
+ export const FIRST_CHECK_LIMIT_MS = 1_500;
29
+ /** A "not yet" sooner than this was not a held request. */
30
+ const UNHELD_ANSWER_MS = 50;
31
+ /**
32
+ * The stop record over the realtime server's internal HTTP API:
33
+ * `GET {url}/internal/turns/{turnId}/stop?userId=&waitMs=` (200 with the
34
+ * record, 204 when none was asked for in `waitMs`).
35
+ *
36
+ * It fails open. A failure (the server restarting, a 5xx) is retried with a
37
+ * growing pause, and the turn runs on meanwhile: a turn must never fail
38
+ * because it could not ask whether to stop. A 404 is not a failure to retry:
39
+ * it is a server that keeps no stops, said once, and the watch ends.
40
+ */
41
+ export function createHttpTurnStopClient(config) {
42
+ const { url, apiKey } = config;
43
+ requireRealtime(url, apiKey);
44
+ const maxPollMs = config.maxPollMs ?? 25_000;
45
+ const maxBackoffMs = config.maxBackoffMs ?? 5_000;
46
+ return {
47
+ async watch(turnId, userId, signal, onChecked) {
48
+ let backoff = FIRST_BACKOFF_MS;
49
+ let attempt = 0;
50
+ let checked = false;
51
+ const firstAnswered = () => {
52
+ if (checked)
53
+ return;
54
+ checked = true;
55
+ onChecked?.();
56
+ };
57
+ while (!signal.aborted) {
58
+ attempt++;
59
+ const asked = Date.now();
60
+ // The first question does not wait: is there a stop already?
61
+ const waitMs = checked ? maxPollMs : 0;
62
+ try {
63
+ const query = new URLSearchParams({ userId, waitMs: String(waitMs) });
64
+ const res = await fetch(`${url}/internal/turns/${encodeURIComponent(turnId)}/stop?${query}`, {
65
+ headers: { 'X-Api-Key': apiKey },
66
+ signal: AbortSignal.any([signal, AbortSignal.timeout(waitMs + 5_000)]),
67
+ });
68
+ if (res.status === 200)
69
+ return (await res.json());
70
+ if (res.status === 204) {
71
+ backoff = FIRST_BACKOFF_MS;
72
+ // A server that answers "not yet" at once to a question that asked it to wait is not
73
+ // holding the request open: asked again without a pause, this would spin.
74
+ if (waitMs > 0 && Date.now() - asked < UNHELD_ANSWER_MS)
75
+ await pause(FIRST_BACKOFF_MS, signal);
76
+ firstAnswered();
77
+ continue;
78
+ }
79
+ if (res.status === 404) {
80
+ // A realtime server from before stops were kept: there is nothing to wait for.
81
+ firstAnswered();
82
+ config.onUnsupported?.();
83
+ return null;
84
+ }
85
+ throw new Error(`HTTP ${res.status}`);
86
+ }
87
+ catch (err) {
88
+ firstAnswered();
89
+ if (signal.aborted)
90
+ return null;
91
+ config.onError?.(err, attempt);
92
+ await pause(backoff, signal);
93
+ backoff = Math.min(backoff * 2, maxBackoffMs);
94
+ }
95
+ }
96
+ return null;
97
+ },
98
+ };
99
+ }
100
+ function pause(ms, signal) {
101
+ return new Promise((resolve) => {
102
+ const timer = setTimeout(done, ms);
103
+ function done() {
104
+ clearTimeout(timer);
105
+ signal.removeEventListener('abort', done);
106
+ resolve();
107
+ }
108
+ signal.addEventListener('abort', done, { once: true });
109
+ });
110
+ }
111
+ export function watchTurnStop(client, turnId, userId) {
112
+ const controller = new AbortController();
113
+ let heard = null;
114
+ let closed = false;
115
+ let listener = null;
116
+ let markChecked;
117
+ const firstCheck = new Promise((resolve) => {
118
+ markChecked = resolve;
119
+ });
120
+ if (client) {
121
+ const limit = setTimeout(markChecked, FIRST_CHECK_LIMIT_MS);
122
+ void firstCheck.then(() => clearTimeout(limit));
123
+ void client.watch(turnId, userId, controller.signal, markChecked).then((record) => {
124
+ if (record && !closed) {
125
+ heard = record;
126
+ listener?.(record);
127
+ }
128
+ markChecked();
129
+ }, () => {
130
+ // `watch` does not reject; a client that does is treated as hearing nothing.
131
+ markChecked();
132
+ });
133
+ }
134
+ else {
135
+ markChecked();
136
+ }
137
+ return {
138
+ current: () => (closed ? null : heard),
139
+ checked: () => firstCheck,
140
+ onStop(next) {
141
+ if (closed)
142
+ return;
143
+ listener = next;
144
+ if (heard)
145
+ next(heard);
146
+ },
147
+ close() {
148
+ closed = true;
149
+ listener = null;
150
+ controller.abort();
151
+ markChecked();
152
+ },
153
+ };
154
+ }
155
+ //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