@ouispec/agent-worker 0.4.0 → 0.8.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/README.md +57 -2
- package/dist/approvals/client.d.ts +8 -1
- package/dist/approvals/client.d.ts.map +1 -1
- package/dist/approvals/client.js +10 -0
- package/dist/approvals/client.js.map +1 -1
- package/dist/approvals/continuation.d.ts +13 -1
- package/dist/approvals/continuation.d.ts.map +1 -1
- package/dist/approvals/continuation.js +35 -0
- package/dist/approvals/continuation.js.map +1 -1
- package/dist/approvals/preview.d.ts +2 -2
- package/dist/approvals/preview.d.ts.map +1 -1
- package/dist/approvals/preview.js +20 -3
- package/dist/approvals/preview.js.map +1 -1
- package/dist/attachments/content.d.ts +68 -0
- package/dist/attachments/content.d.ts.map +1 -0
- package/dist/attachments/content.js +318 -0
- package/dist/attachments/content.js.map +1 -0
- package/dist/attachments/guard.d.ts +69 -0
- package/dist/attachments/guard.d.ts.map +1 -0
- package/dist/attachments/guard.js +86 -0
- package/dist/attachments/guard.js.map +1 -0
- package/dist/attachments/limits.d.ts +46 -0
- package/dist/attachments/limits.d.ts.map +1 -0
- package/dist/attachments/limits.js +64 -0
- package/dist/attachments/limits.js.map +1 -0
- package/dist/attachments/store.d.ts +85 -0
- package/dist/attachments/store.d.ts.map +1 -0
- package/dist/attachments/store.js +2 -0
- package/dist/attachments/store.js.map +1 -0
- package/dist/attachments/tools.d.ts +12 -0
- package/dist/attachments/tools.d.ts.map +1 -0
- package/dist/attachments/tools.js +216 -0
- package/dist/attachments/tools.js.map +1 -0
- package/dist/authz/tool-policy.d.ts +6 -0
- package/dist/authz/tool-policy.d.ts.map +1 -1
- package/dist/authz/tool-policy.js.map +1 -1
- package/dist/index.d.ts +12 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -1
- package/dist/index.js.map +1 -1
- package/dist/lambda/handler.d.ts +2 -2
- package/dist/lambda/handler.d.ts.map +1 -1
- package/dist/lambda/handler.js +3 -2
- package/dist/lambda/handler.js.map +1 -1
- package/dist/orchestrator.d.ts.map +1 -1
- package/dist/orchestrator.js +613 -101
- package/dist/orchestrator.js.map +1 -1
- package/dist/prompt/clock.d.ts +0 -17
- package/dist/prompt/clock.d.ts.map +1 -1
- package/dist/prompt/clock.js +19 -2
- package/dist/prompt/clock.js.map +1 -1
- package/dist/prompt/user-text.d.ts +19 -0
- package/dist/prompt/user-text.d.ts.map +1 -0
- package/dist/prompt/user-text.js +20 -0
- package/dist/prompt/user-text.js.map +1 -0
- package/dist/runtime/turn-runner.d.ts +29 -2
- package/dist/runtime/turn-runner.d.ts.map +1 -1
- package/dist/runtime/turn-runner.js +118 -9
- package/dist/runtime/turn-runner.js.map +1 -1
- package/dist/runtime/types.d.ts +84 -6
- package/dist/runtime/types.d.ts.map +1 -1
- package/dist/stop/partial.d.ts +49 -0
- package/dist/stop/partial.d.ts.map +1 -0
- package/dist/stop/partial.js +73 -0
- package/dist/stop/partial.js.map +1 -0
- package/dist/stop/results.d.ts +20 -0
- package/dist/stop/results.d.ts.map +1 -0
- package/dist/stop/results.js +46 -0
- package/dist/stop/results.js.map +1 -0
- package/dist/stop/turn-stop.d.ts +114 -0
- package/dist/stop/turn-stop.d.ts.map +1 -0
- package/dist/stop/turn-stop.js +159 -0
- package/dist/stop/turn-stop.js.map +1 -0
- package/dist/tools/input-validation.d.ts.map +1 -1
- package/dist/tools/input-validation.js +3 -0
- package/dist/tools/input-validation.js.map +1 -1
- package/dist/tools/types.d.ts +19 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js.map +1 -1
- package/dist/turn-policy.d.ts +14 -0
- package/dist/turn-policy.d.ts.map +1 -1
- package/dist/turn-policy.js.map +1 -1
- package/dist/types.d.ts +84 -3
- package/dist/types.d.ts.map +1 -1
- package/dist/ui/knowledge.d.ts +28 -2
- package/dist/ui/knowledge.d.ts.map +1 -1
- package/dist/ui/knowledge.js +117 -13
- package/dist/ui/knowledge.js.map +1 -1
- package/dist/ui/newest-page-state.d.ts +25 -0
- package/dist/ui/newest-page-state.d.ts.map +1 -0
- package/dist/ui/newest-page-state.js +91 -0
- package/dist/ui/newest-page-state.js.map +1 -0
- package/dist/ui/ui-tools.d.ts +20 -2
- package/dist/ui/ui-tools.d.ts.map +1 -1
- package/dist/ui/ui-tools.js +65 -6
- package/dist/ui/ui-tools.js.map +1 -1
- package/package.json +6 -6
|
@@ -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 { TurnStoppedReason, 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: TurnStoppedReason;
|
|
17
|
+
/** When it was asked for, or the deadline passed: epoch ms. */
|
|
18
|
+
readonly at: number;
|
|
19
|
+
readonly cause: "stopped";
|
|
20
|
+
constructor(reason: TurnStoppedReason,
|
|
21
|
+
/** When it was asked for, or the deadline passed: 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(): TurnStoppedReason | 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,OAAO,KAAK,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAG7E;;;;GAIG;AACH,qBAAa,WAAY,SAAQ,KAAK;IAGlC,QAAQ,CAAC,MAAM,EAAE,iBAAiB;IAClC,+DAA+D;IAC/D,QAAQ,CAAC,EAAE,EAAE,MAAM;IAJrB,QAAQ,CAAC,KAAK,EAAG,SAAS,CAAU;gBAEzB,MAAM,EAAE,iBAAiB;IAClC,+DAA+D;IACtD,EAAE,EAAE,MAAM;CAWtB;AAED,qGAAqG;AACrG,wBAAgB,MAAM,CAAC,MA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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,159 @@
|
|
|
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, or the deadline passed: epoch ms. */
|
|
13
|
+
at) {
|
|
14
|
+
super(reason === 'superseded'
|
|
15
|
+
? 'The turn was superseded by a newer message'
|
|
16
|
+
: reason === 'deadline'
|
|
17
|
+
? 'The turn ran out of time'
|
|
18
|
+
: 'The turn was stopped by the person');
|
|
19
|
+
this.reason = reason;
|
|
20
|
+
this.at = at;
|
|
21
|
+
this.name = 'TurnStopped';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/** The stop a signal was aborted with, or null when it was not aborted, or was for another cause. */
|
|
25
|
+
export function stopOf(signal) {
|
|
26
|
+
return signal?.aborted && signal.reason instanceof TurnStopped ? signal.reason : null;
|
|
27
|
+
}
|
|
28
|
+
/** How long after a stop an answer already on its way is still waited for (ADR-0252 §2.2). */
|
|
29
|
+
export const DEFAULT_STOP_GRACE_MS = 2_000;
|
|
30
|
+
const FIRST_BACKOFF_MS = 250;
|
|
31
|
+
/** The longest a turn waits for the answer to its first question before it starts anyway. */
|
|
32
|
+
export const FIRST_CHECK_LIMIT_MS = 1_500;
|
|
33
|
+
/** A "not yet" sooner than this was not a held request. */
|
|
34
|
+
const UNHELD_ANSWER_MS = 50;
|
|
35
|
+
/**
|
|
36
|
+
* The stop record over the realtime server's internal HTTP API:
|
|
37
|
+
* `GET {url}/internal/turns/{turnId}/stop?userId=&waitMs=` (200 with the
|
|
38
|
+
* record, 204 when none was asked for in `waitMs`).
|
|
39
|
+
*
|
|
40
|
+
* It fails open. A failure (the server restarting, a 5xx) is retried with a
|
|
41
|
+
* growing pause, and the turn runs on meanwhile: a turn must never fail
|
|
42
|
+
* because it could not ask whether to stop. A 404 is not a failure to retry:
|
|
43
|
+
* it is a server that keeps no stops, said once, and the watch ends.
|
|
44
|
+
*/
|
|
45
|
+
export function createHttpTurnStopClient(config) {
|
|
46
|
+
const { url, apiKey } = config;
|
|
47
|
+
requireRealtime(url, apiKey);
|
|
48
|
+
const maxPollMs = config.maxPollMs ?? 25_000;
|
|
49
|
+
const maxBackoffMs = config.maxBackoffMs ?? 5_000;
|
|
50
|
+
return {
|
|
51
|
+
async watch(turnId, userId, signal, onChecked) {
|
|
52
|
+
let backoff = FIRST_BACKOFF_MS;
|
|
53
|
+
let attempt = 0;
|
|
54
|
+
let checked = false;
|
|
55
|
+
const firstAnswered = () => {
|
|
56
|
+
if (checked)
|
|
57
|
+
return;
|
|
58
|
+
checked = true;
|
|
59
|
+
onChecked?.();
|
|
60
|
+
};
|
|
61
|
+
while (!signal.aborted) {
|
|
62
|
+
attempt++;
|
|
63
|
+
const asked = Date.now();
|
|
64
|
+
// The first question does not wait: is there a stop already?
|
|
65
|
+
const waitMs = checked ? maxPollMs : 0;
|
|
66
|
+
try {
|
|
67
|
+
const query = new URLSearchParams({ userId, waitMs: String(waitMs) });
|
|
68
|
+
const res = await fetch(`${url}/internal/turns/${encodeURIComponent(turnId)}/stop?${query}`, {
|
|
69
|
+
headers: { 'X-Api-Key': apiKey },
|
|
70
|
+
signal: AbortSignal.any([signal, AbortSignal.timeout(waitMs + 5_000)]),
|
|
71
|
+
});
|
|
72
|
+
if (res.status === 200)
|
|
73
|
+
return (await res.json());
|
|
74
|
+
if (res.status === 204) {
|
|
75
|
+
backoff = FIRST_BACKOFF_MS;
|
|
76
|
+
// A server that answers "not yet" at once to a question that asked it to wait is not
|
|
77
|
+
// holding the request open: asked again without a pause, this would spin.
|
|
78
|
+
if (waitMs > 0 && Date.now() - asked < UNHELD_ANSWER_MS)
|
|
79
|
+
await pause(FIRST_BACKOFF_MS, signal);
|
|
80
|
+
firstAnswered();
|
|
81
|
+
continue;
|
|
82
|
+
}
|
|
83
|
+
if (res.status === 404) {
|
|
84
|
+
// A realtime server from before stops were kept: there is nothing to wait for.
|
|
85
|
+
firstAnswered();
|
|
86
|
+
config.onUnsupported?.();
|
|
87
|
+
return null;
|
|
88
|
+
}
|
|
89
|
+
throw new Error(`HTTP ${res.status}`);
|
|
90
|
+
}
|
|
91
|
+
catch (err) {
|
|
92
|
+
firstAnswered();
|
|
93
|
+
if (signal.aborted)
|
|
94
|
+
return null;
|
|
95
|
+
config.onError?.(err, attempt);
|
|
96
|
+
await pause(backoff, signal);
|
|
97
|
+
backoff = Math.min(backoff * 2, maxBackoffMs);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
return null;
|
|
101
|
+
},
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
function pause(ms, signal) {
|
|
105
|
+
return new Promise((resolve) => {
|
|
106
|
+
const timer = setTimeout(done, ms);
|
|
107
|
+
function done() {
|
|
108
|
+
clearTimeout(timer);
|
|
109
|
+
signal.removeEventListener('abort', done);
|
|
110
|
+
resolve();
|
|
111
|
+
}
|
|
112
|
+
signal.addEventListener('abort', done, { once: true });
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
export function watchTurnStop(client, turnId, userId) {
|
|
116
|
+
const controller = new AbortController();
|
|
117
|
+
let heard = null;
|
|
118
|
+
let closed = false;
|
|
119
|
+
let listener = null;
|
|
120
|
+
let markChecked;
|
|
121
|
+
const firstCheck = new Promise((resolve) => {
|
|
122
|
+
markChecked = resolve;
|
|
123
|
+
});
|
|
124
|
+
if (client) {
|
|
125
|
+
const limit = setTimeout(markChecked, FIRST_CHECK_LIMIT_MS);
|
|
126
|
+
void firstCheck.then(() => clearTimeout(limit));
|
|
127
|
+
void client.watch(turnId, userId, controller.signal, markChecked).then((record) => {
|
|
128
|
+
if (record && !closed) {
|
|
129
|
+
heard = record;
|
|
130
|
+
listener?.(record);
|
|
131
|
+
}
|
|
132
|
+
markChecked();
|
|
133
|
+
}, () => {
|
|
134
|
+
// `watch` does not reject; a client that does is treated as hearing nothing.
|
|
135
|
+
markChecked();
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
else {
|
|
139
|
+
markChecked();
|
|
140
|
+
}
|
|
141
|
+
return {
|
|
142
|
+
current: () => (closed ? null : heard),
|
|
143
|
+
checked: () => firstCheck,
|
|
144
|
+
onStop(next) {
|
|
145
|
+
if (closed)
|
|
146
|
+
return;
|
|
147
|
+
listener = next;
|
|
148
|
+
if (heard)
|
|
149
|
+
next(heard);
|
|
150
|
+
},
|
|
151
|
+
close() {
|
|
152
|
+
closed = true;
|
|
153
|
+
listener = null;
|
|
154
|
+
controller.abort();
|
|
155
|
+
markChecked();
|
|
156
|
+
},
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
//# sourceMappingURL=turn-stop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"turn-stop.js","sourceRoot":"","sources":["../../src/stop/turn-stop.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D;;;;GAIG;AACH,MAAM,OAAO,WAAY,SAAQ,KAAK;IAGzB;IAEA;IAJF,KAAK,GAAG,SAAkB,CAAC;IACpC,YACW,MAAyB;IAClC,+DAA+D;IACtD,EAAU;QAEnB,KAAK,CACH,MAAM,KAAK,YAAY;YACrB,CAAC,CAAC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;YACnB,WAAW,EAAE,CAAC;QAChB,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-validation.d.ts","sourceRoot":"","sources":["../../src/tools/input-validation.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"input-validation.d.ts","sourceRoot":"","sources":["../../src/tools/input-validation.ts"],"names":[],"mappings":"AAgCA,MAAM,MAAM,mBAAmB,GAC3B;IACE,EAAE,EAAE,IAAI,CAAC;IACT,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B;;;;OAIG;IACH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;CACpB,GACD;IAAE,EAAE,EAAE,KAAK,CAAC;IAAC,MAAM,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AAEpC,MAAM,MAAM,kBAAkB,GAAG,CAAC,KAAK,EAAE,OAAO,KAAK,mBAAmB,CAAC;AA+DzE;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,GAC/C,kBAAkB,CAiCpB"}
|
|
@@ -11,6 +11,7 @@
|
|
|
11
11
|
* properties says so with `additionalProperties: false`, as the schema loader and the
|
|
12
12
|
* entity tool generator now do.
|
|
13
13
|
*/
|
|
14
|
+
import { ATTACHMENT_ID_PATTERN, OUI_ATTACHMENT_FORMAT } from 'oui-spec/spec';
|
|
14
15
|
import { Ajv } from 'ajv';
|
|
15
16
|
import formatsPlugin from 'ajv-formats';
|
|
16
17
|
// ajv-formats is CommonJS; under ESM interop its function is on `default`.
|
|
@@ -26,6 +27,8 @@ const addFormats = formatsPlugin.default ??
|
|
|
26
27
|
const NON_VALIDATION_KEYS = ['sideEffects', '$schema', '$id'];
|
|
27
28
|
const ajv = new Ajv({ allErrors: true, strict: false, useDefaults: false, coerceTypes: false });
|
|
28
29
|
addFormats(ajv);
|
|
30
|
+
// An input that takes a file the person attached is given the file's id (OUI spec §7.3.11).
|
|
31
|
+
ajv.addFormat(OUI_ATTACHMENT_FORMAT, ATTACHMENT_ID_PATTERN);
|
|
29
32
|
function describeError(error) {
|
|
30
33
|
const at = error.instancePath || '(input)';
|
|
31
34
|
const params = error.params;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"input-validation.js","sourceRoot":"","sources":["../../src/tools/input-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,GAAG,EAA2C,MAAM,KAAK,CAAC;AACnE,OAAO,aAAa,MAAM,aAAa,CAAC;AAGxC,2EAA2E;AAC3E,MAAM,UAAU,GACb,aAAwD,CAAC,OAAO;IAChE,aAA0C,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,mBAAmB,GAAG,CAAC,aAAa,EAAE,SAAS,EAAE,KAAK,CAAU,CAAC;AAiBvE,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,EAAE,SAAS,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC,CAAC;AAChG,UAAU,CAAC,GAAG,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"input-validation.js","sourceRoot":"","sources":["../../src/tools/input-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AACH,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAC7E,OAAO,EAAE,GAAG,EAA2C,MAAM,KAAK,CAAC;AACnE,OAAO,aAAa,MAAM,aAAa,CAAC;AAGxC,2EAA2E;AAC3E,MAAM,UAAU,GACb,aAAwD,CAAC,OAAO;IAChE,aAA0C,CAAC;AAE9C;;;;;;GAMG;AACH,MAAM,mBAAmB,GAAG,CAAC,aAAa,EAAE,SAAS,EAAE,KAAK,CAAU,CAAC;AAiBvE,MAAM,GAAG,GAAG,IAAI,GAAG,CAA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core';
|
|
2
3
|
import type { EffectOrKind } from '@ouispec/bindings';
|
|
3
4
|
import type { UISlot } from '../ui/ui-sequence.js';
|
|
@@ -18,6 +19,12 @@ export interface RegisteredTool {
|
|
|
18
19
|
* side-effect quota. Default `backend`.
|
|
19
20
|
*/
|
|
20
21
|
kind?: 'ui' | 'backend';
|
|
22
|
+
/**
|
|
23
|
+
* The SDK's class for a tool it owns (ADR-0252 §2.12): `attachment` for the
|
|
24
|
+
* attachment tools. A host's tool policy may admit a class as well as a name,
|
|
25
|
+
* so a tool the SDK adds later in that class needs no change in the host.
|
|
26
|
+
*/
|
|
27
|
+
toolClass?: 'attachment';
|
|
21
28
|
/**
|
|
22
29
|
* What calling the tool changes (ADR-0226 §2.6). A tool that declares none is
|
|
23
30
|
* treated as a write. Approvals key on this and `destructive` (ADR-0228).
|
|
@@ -75,6 +82,12 @@ export interface ToolExecutionContext {
|
|
|
75
82
|
* the grant from the user's own click.
|
|
76
83
|
*/
|
|
77
84
|
approval?: ActionRequestApproval;
|
|
85
|
+
/**
|
|
86
|
+
* Whether the turn has been asked to stop (ADR-0252). A tool that waits on
|
|
87
|
+
* something it sent reads it when `abortSignal` aborts, to say what became
|
|
88
|
+
* of the call: not run, or sent with its outcome unknown.
|
|
89
|
+
*/
|
|
90
|
+
stop?: TurnStopState;
|
|
78
91
|
[key: string]: unknown;
|
|
79
92
|
}
|
|
80
93
|
export interface ToolExecutionResult {
|
|
@@ -90,6 +103,12 @@ export interface ToolExecutionResult {
|
|
|
90
103
|
mediaType: string;
|
|
91
104
|
base64: string;
|
|
92
105
|
};
|
|
106
|
+
/**
|
|
107
|
+
* Text the model is given beside the result's text, as a text part of the
|
|
108
|
+
* tool result: a file's text, which is the model's for this call only. Like
|
|
109
|
+
* `image`, it is in no event, record or stored message: `data` says what it is.
|
|
110
|
+
*/
|
|
111
|
+
modelText?: string;
|
|
93
112
|
}
|
|
94
113
|
export interface ToolRegistry {
|
|
95
114
|
tools: RegisteredTool[];
|
|
@@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IACjB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,KAAK,CAAC,EAAE;QAAE,SAAS,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9C;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,cAAc,EAAE,CAAC;IACxB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,GAAG,EAAE,oBAAoB,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAAC;CAChH;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,cAAc,EAAE,GAAG,YAAY,CAiBxE"}
|
package/dist/tools/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAwHA;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAuB;IACxD,MAAM,OAAO,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;IAErD,OAAO;QACL,KAAK;QACL,KAAK,CAAC,OAAO,CAAC,IAAY,EAAE,KAA8B,EAAE,GAAyB;YACnF,MAAM,IAAI,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;YAC/B,IAAI,CAAC,IAAI,EAAE,CAAC;gBACV,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,iBAAiB,IAAI,EAAE,EAAE,CAAC;YAC5D,CAAC;YACD,IAAI,CAAC;gBACH,OAAO,MAAM,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;YACxC,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACb,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;YACrF,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/turn-policy.d.ts
CHANGED
|
@@ -9,6 +9,18 @@
|
|
|
9
9
|
* 1. classifyTurn — called once at turn start to classify the user's intent
|
|
10
10
|
* 2. prepareStep — called before each LLM step to control tool selection
|
|
11
11
|
*/
|
|
12
|
+
/**
|
|
13
|
+
* A tool the model can be given at a step, as a policy sees it: its name, what
|
|
14
|
+
* kind of tool it is, and its class when it has one (the SDK's attachment
|
|
15
|
+
* tools are `attachment`). A policy that picks a step's active tools by name
|
|
16
|
+
* can keep a whole class, such as the attachment tools, by this.
|
|
17
|
+
*/
|
|
18
|
+
export interface StepTool {
|
|
19
|
+
name: string;
|
|
20
|
+
/** `ui`: a page action, or a UI tool (`ui_act`, `ui_describe`, `ui_read`). `backend`: the host's or the SDK's own. `builtin`: the worker's. */
|
|
21
|
+
kind: 'ui' | 'backend' | 'builtin';
|
|
22
|
+
toolClass?: string;
|
|
23
|
+
}
|
|
12
24
|
export interface TurnPolicy {
|
|
13
25
|
/**
|
|
14
26
|
* Classify the current turn to determine orchestration behavior.
|
|
@@ -31,6 +43,8 @@ export interface TurnPolicy {
|
|
|
31
43
|
}>;
|
|
32
44
|
turnClass: string;
|
|
33
45
|
allToolNames: string[];
|
|
46
|
+
/** The same tools with their kind and class, in the same order. */
|
|
47
|
+
allTools: StepTool[];
|
|
34
48
|
}): Promise<{
|
|
35
49
|
toolChoice?: 'auto' | 'none' | 'required' | {
|
|
36
50
|
type: 'tool';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turn-policy.d.ts","sourceRoot":"","sources":["../src/turn-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,UAAU;IACzB;;;;OAIG;IACH,YAAY,CACV,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,GACjD,MAAM,CAAC;IAEV;;;OAGG;IACH,WAAW,CAAC,GAAG,EAAE;QACf,KAAK,EAAE,KAAK,CAAC;YAAE,SAAS,CAAC,EAAE,KAAK,CAAC;gBAAE,QAAQ,EAAE,MAAM,CAAA;aAAE,CAAC,CAAA;SAAE,CAAC,CAAC;QAC1D,SAAS,EAAE,MAAM,CAAC;QAClB,YAAY,EAAE,MAAM,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"turn-policy.d.ts","sourceRoot":"","sources":["../src/turn-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH;;;;;GAKG;AACH,MAAM,WAAW,QAAQ;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,+IAA+I;IAC/I,IAAI,EAAE,IAAI,GAAG,SAAS,GAAG,SAAS,CAAC;IACnC,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,UAAU;IACzB;;;;OAIG;IACH,YAAY,CACV,OAAO,EAAE,MAAM,EACf,OAAO,CAAC,EAAE,KAAK,CAAC;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,GACjD,MAAM,CAAC;IAEV;;;OAGG;IACH,WAAW,CAAC,GAAG,EAAE;QACf,KAAK,EAAE,KAAK,CAAC;YAAE,SAAS,CAAC,EAAE,KAAK,CAAC;gBAAE,QAAQ,EAAE,MAAM,CAAA;aAAE,CAAC,CAAA;SAAE,CAAC,CAAC;QAC1D,SAAS,EAAE,MAAM,CAAC;QAClB,YAAY,EAAE,MAAM,EAAE,CAAC;QACvB,mEAAmE;QACnE,QAAQ,EAAE,QAAQ,EAAE,CAAC;KACtB,GAAG,OAAO,CAAC;QACV,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,UAAU,GAAG;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,QAAQ,EAAE,MAAM,CAAA;SAAE,CAAC;QAC/E,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;QACvB;;;;;WAKG;QACH,IAAI,CAAC,EAAE,MAAM,CAAC;KACf,CAAC,CAAC;IAEH;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,CAAC,GAAG,EAAE;QACvB,SAAS,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,MAAM,CAAC;QAChB,IAAI,EAAE;YAAE,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;SAAE,CAAC;QAC9E,UAAU,EAAE,MAAM,CAAC;KACpB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACrB;AAED;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,EAAE,UAG/B,CAAC"}
|
package/dist/turn-policy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"turn-policy.js","sourceRoot":"","sources":["../src/turn-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;
|
|
1
|
+
{"version":3,"file":"turn-policy.js","sourceRoot":"","sources":["../src/turn-policy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AA6DH;;;;GAIG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAe;IAC3C,YAAY,EAAE,GAAG,EAAE,CAAC,QAAQ;IAC5B,WAAW,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC;CAC9B,CAAC"}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import type { AttachmentRef, TurnStoppedReason, TurnStoppedMarker } from '@ouispec/agent-core';
|
|
2
|
+
import type { AttachmentWorkerConfig } from './attachments/store.js';
|
|
3
|
+
import type { AttachmentUsage } from './attachments/guard.js';
|
|
4
|
+
import type { TurnStopClient, TurnStopWatch } from './stop/turn-stop.js';
|
|
1
5
|
import type { LanguageModel, ProviderOptions } from './model.js';
|
|
2
6
|
import type { RealtimeEmitAdapter } from './emit/types.js';
|
|
3
7
|
import type { ToolRegistry } from './tools/types.js';
|
|
@@ -61,6 +65,14 @@ export interface AgentWorkerConfig {
|
|
|
61
65
|
channel: UIActionChannel;
|
|
62
66
|
/** How long a UI tool waits for the client's answer. Default 20 s. */
|
|
63
67
|
resultTimeoutMs?: number;
|
|
68
|
+
/**
|
|
69
|
+
* The longest a UI tool waits, in the call, for the outcome of work its
|
|
70
|
+
* action started (a GPU job, an export). Work that ends within it is
|
|
71
|
+
* reported done; work that does not is reported still running, and the
|
|
72
|
+
* turn ends: its outcome is in the page state the next turn reads.
|
|
73
|
+
* Default 20 s (`DEFAULT_JOB_WAIT_MS`).
|
|
74
|
+
*/
|
|
75
|
+
jobWaitMs?: number;
|
|
64
76
|
/** Largest page-state payload given to the model, in characters. Default 12000 (`DEFAULT_PAGE_STATE_CHARS`). */
|
|
65
77
|
maxObservationChars?: number;
|
|
66
78
|
/** Largest index of the page's actions given to the model, in characters. Default 60000 (`DEFAULT_INDEX_CHARS`). */
|
|
@@ -76,8 +88,28 @@ export interface AgentWorkerConfig {
|
|
|
76
88
|
*
|
|
77
89
|
* It is awaited. If it rejects, the rejection is logged and the turn still
|
|
78
90
|
* completes: a turn that answered is not turned into a failure by its record.
|
|
91
|
+
*
|
|
92
|
+
* A stopped turn calls it too, with what it had produced and `stopped`
|
|
93
|
+
* (ADR-0252 §2.4): stored first, announced after, on both paths.
|
|
94
|
+
*/
|
|
95
|
+
beforeTurnComplete?: (turn: Pick<AgentTurnResult, 'rounds' | 'usage' | 'newMessages' | 'stopped'>) => Promise<void>;
|
|
96
|
+
/**
|
|
97
|
+
* Where the turn hears that it was asked to stop (ADR-0252 §2.1): the
|
|
98
|
+
* person's Stop, or a newer message superseding it. Without one, or without
|
|
99
|
+
* `stopWatch` on the turn's input, a turn cannot be stopped.
|
|
100
|
+
*/
|
|
101
|
+
stops?: TurnStopClient;
|
|
102
|
+
/**
|
|
103
|
+
* How long after a stop an answer already on its way is still waited for,
|
|
104
|
+
* before its call is stored as sent with its outcome unknown. Default 2 s.
|
|
79
105
|
*/
|
|
80
|
-
|
|
106
|
+
stopGraceMs?: number;
|
|
107
|
+
/**
|
|
108
|
+
* The host's file area (ADR-0252 §3). With it, a turn's files are given to
|
|
109
|
+
* the model with its message, and the attachment tools reach the
|
|
110
|
+
* conversation's files. Without it a turn's attachments are left out.
|
|
111
|
+
*/
|
|
112
|
+
attachments?: AttachmentWorkerConfig;
|
|
81
113
|
}
|
|
82
114
|
export interface SystemPromptContext {
|
|
83
115
|
userId: string;
|
|
@@ -103,6 +135,23 @@ export interface AgentTurnInput {
|
|
|
103
135
|
* message text.
|
|
104
136
|
*/
|
|
105
137
|
approval?: ApprovalContinuation;
|
|
138
|
+
/**
|
|
139
|
+
* The turn's watch for a stop, when the caller opened it before this call:
|
|
140
|
+
* the turn runner does, before it reads history, so a stop asked for while
|
|
141
|
+
* the turn waited is heard first. Without it, one is opened from
|
|
142
|
+
* `config.stops`.
|
|
143
|
+
*/
|
|
144
|
+
stopWatch?: TurnStopWatch;
|
|
145
|
+
/**
|
|
146
|
+
* How long this process has left, in ms, when the host knows (a Lambda's
|
|
147
|
+
* remaining time). A stopped turn stores and announces within it.
|
|
148
|
+
*/
|
|
149
|
+
remainingMs?: () => number;
|
|
150
|
+
/**
|
|
151
|
+
* The files attached to the turn's message, by reference (ADR-0252 §2.8):
|
|
152
|
+
* given to the model with it, through `config.attachments`.
|
|
153
|
+
*/
|
|
154
|
+
attachments?: AttachmentRef[];
|
|
106
155
|
}
|
|
107
156
|
/**
|
|
108
157
|
* Rich history message — supports full conversation state including tool calls and results.
|
|
@@ -111,10 +160,18 @@ export interface AgentTurnInput {
|
|
|
111
160
|
export type TurnHistoryMessage = {
|
|
112
161
|
role: 'user';
|
|
113
162
|
content: string;
|
|
163
|
+
/** The files the person attached to this message: the model reads their reference lines. */
|
|
164
|
+
attachments?: AttachmentRef[] | null;
|
|
114
165
|
} | {
|
|
115
166
|
role: 'assistant';
|
|
116
167
|
content: string | null;
|
|
117
168
|
tool_calls?: ToolCallRef[];
|
|
169
|
+
/**
|
|
170
|
+
* Set on the last assistant message of a turn that was stopped
|
|
171
|
+
* (`TurnMessage.stopped`, as the host stored it). The model is told so
|
|
172
|
+
* after the message's text.
|
|
173
|
+
*/
|
|
174
|
+
stopped?: TurnStoppedMarker | null;
|
|
118
175
|
} | {
|
|
119
176
|
role: 'tool';
|
|
120
177
|
content: string;
|
|
@@ -161,8 +218,25 @@ export interface AgentTurnResult {
|
|
|
161
218
|
*/
|
|
162
219
|
settledApprovals?: string[];
|
|
163
220
|
maxRoundsReached: boolean;
|
|
164
|
-
/**
|
|
165
|
-
|
|
221
|
+
/**
|
|
222
|
+
* Why the turn ended: which bound or condition terminated the loop, or
|
|
223
|
+
* that it was stopped (`user_stop`, `superseded`: ADR-0252).
|
|
224
|
+
*/
|
|
225
|
+
stopReason: 'present_options' | 'awaiting_approval' | 'step_count' | 'token_budget' | 'deadline' | 'complete' | 'error' | TurnStoppedReason;
|
|
226
|
+
/**
|
|
227
|
+
* Set when the turn was stopped: `newMessages` is what it had produced, each
|
|
228
|
+
* call with exactly one result, the last assistant message marked.
|
|
229
|
+
*/
|
|
230
|
+
stopped?: TurnStoppedMarker;
|
|
231
|
+
/**
|
|
232
|
+
* `false` when the turn was stopped and what it had produced could not be
|
|
233
|
+
* stored (`beforeTurnComplete` failed or ran out of time). A turn that ran
|
|
234
|
+
* out of time and stored nothing is recorded as such, not as stopped
|
|
235
|
+
* (ADR-0252 §6.4).
|
|
236
|
+
*/
|
|
237
|
+
stored?: false;
|
|
238
|
+
/** What the turn gave the model of its files, when the host has a file area (ADR-0252 §2.11). */
|
|
239
|
+
attachments?: AttachmentUsage;
|
|
166
240
|
}
|
|
167
241
|
export interface TurnMessage {
|
|
168
242
|
role: 'assistant' | 'tool';
|
|
@@ -174,5 +248,12 @@ export interface TurnMessage {
|
|
|
174
248
|
}>;
|
|
175
249
|
toolCallId?: string;
|
|
176
250
|
name?: string;
|
|
251
|
+
/**
|
|
252
|
+
* On the last assistant message of a stopped turn (ADR-0252 §2.3). The host
|
|
253
|
+
* stores it with the message and hands it back in history
|
|
254
|
+
* (`TurnHistoryMessage.stopped`). A message that has only the marker carries
|
|
255
|
+
* the marker's line as its `content`, so it is never empty.
|
|
256
|
+
*/
|
|
257
|
+
stopped?: TurnStoppedMarker;
|
|
177
258
|
}
|
|
178
259
|
//# sourceMappingURL=types.d.ts.map
|