@ouispec/agent-worker 0.4.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.
- package/README.md +27 -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/index.d.ts +5 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- 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 +418 -82
- package/dist/orchestrator.js.map +1 -1
- package/dist/runtime/turn-runner.d.ts +21 -2
- package/dist/runtime/turn-runner.d.ts.map +1 -1
- package/dist/runtime/turn-runner.js +77 -8
- package/dist/runtime/turn-runner.js.map +1 -1
- package/dist/runtime/types.d.ts +63 -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 +155 -0
- package/dist/stop/turn-stop.js.map +1 -0
- package/dist/tools/types.d.ts +7 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/tools/types.js.map +1 -1
- package/dist/types.d.ts +60 -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
package/dist/tools/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { TurnStopState } from '../stop/turn-stop.js';
|
|
1
2
|
import type { ActionRequestApproval, AgentApiSurface } from '@ouispec/agent-core';
|
|
2
3
|
import type { EffectOrKind } from '@ouispec/bindings';
|
|
3
4
|
import type { UISlot } from '../ui/ui-sequence.js';
|
|
@@ -75,6 +76,12 @@ export interface ToolExecutionContext {
|
|
|
75
76
|
* the grant from the user's own click.
|
|
76
77
|
*/
|
|
77
78
|
approval?: ActionRequestApproval;
|
|
79
|
+
/**
|
|
80
|
+
* Whether the turn has been asked to stop (ADR-0252). A tool that waits on
|
|
81
|
+
* something it sent reads it when `abortSignal` aborts, to say what became
|
|
82
|
+
* of the call: not run, or sent with its outcome unknown.
|
|
83
|
+
*/
|
|
84
|
+
stop?: TurnStopState;
|
|
78
85
|
[key: string]: unknown;
|
|
79
86
|
}
|
|
80
87
|
export interface ToolExecutionResult {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/tools/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAClF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,KAAK,EAAE,MAAM,EAAE,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AO,CAAC;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;CAC/C;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":"AA4GA;;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/types.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { TurnStopReason, TurnStoppedMarker } from '@ouispec/agent-core';
|
|
2
|
+
import type { TurnStopClient, TurnStopWatch } from './stop/turn-stop.js';
|
|
1
3
|
import type { LanguageModel, ProviderOptions } from './model.js';
|
|
2
4
|
import type { RealtimeEmitAdapter } from './emit/types.js';
|
|
3
5
|
import type { ToolRegistry } from './tools/types.js';
|
|
@@ -61,6 +63,14 @@ export interface AgentWorkerConfig {
|
|
|
61
63
|
channel: UIActionChannel;
|
|
62
64
|
/** How long a UI tool waits for the client's answer. Default 20 s. */
|
|
63
65
|
resultTimeoutMs?: number;
|
|
66
|
+
/**
|
|
67
|
+
* The longest a UI tool waits, in the call, for the outcome of work its
|
|
68
|
+
* action started (a GPU job, an export). Work that ends within it is
|
|
69
|
+
* reported done; work that does not is reported still running, and the
|
|
70
|
+
* turn ends: its outcome is in the page state the next turn reads.
|
|
71
|
+
* Default 20 s (`DEFAULT_JOB_WAIT_MS`).
|
|
72
|
+
*/
|
|
73
|
+
jobWaitMs?: number;
|
|
64
74
|
/** Largest page-state payload given to the model, in characters. Default 12000 (`DEFAULT_PAGE_STATE_CHARS`). */
|
|
65
75
|
maxObservationChars?: number;
|
|
66
76
|
/** Largest index of the page's actions given to the model, in characters. Default 60000 (`DEFAULT_INDEX_CHARS`). */
|
|
@@ -76,8 +86,22 @@ export interface AgentWorkerConfig {
|
|
|
76
86
|
*
|
|
77
87
|
* It is awaited. If it rejects, the rejection is logged and the turn still
|
|
78
88
|
* completes: a turn that answered is not turned into a failure by its record.
|
|
89
|
+
*
|
|
90
|
+
* A stopped turn calls it too, with what it had produced and `stopped`
|
|
91
|
+
* (ADR-0252 §2.4): stored first, announced after, on both paths.
|
|
92
|
+
*/
|
|
93
|
+
beforeTurnComplete?: (turn: Pick<AgentTurnResult, 'rounds' | 'usage' | 'newMessages' | 'stopped'>) => Promise<void>;
|
|
94
|
+
/**
|
|
95
|
+
* Where the turn hears that it was asked to stop (ADR-0252 §2.1): the
|
|
96
|
+
* person's Stop, or a newer message superseding it. Without one, or without
|
|
97
|
+
* `stopWatch` on the turn's input, a turn cannot be stopped.
|
|
79
98
|
*/
|
|
80
|
-
|
|
99
|
+
stops?: TurnStopClient;
|
|
100
|
+
/**
|
|
101
|
+
* How long after a stop an answer already on its way is still waited for,
|
|
102
|
+
* before its call is stored as sent with its outcome unknown. Default 2 s.
|
|
103
|
+
*/
|
|
104
|
+
stopGraceMs?: number;
|
|
81
105
|
}
|
|
82
106
|
export interface SystemPromptContext {
|
|
83
107
|
userId: string;
|
|
@@ -103,6 +127,18 @@ export interface AgentTurnInput {
|
|
|
103
127
|
* message text.
|
|
104
128
|
*/
|
|
105
129
|
approval?: ApprovalContinuation;
|
|
130
|
+
/**
|
|
131
|
+
* The turn's watch for a stop, when the caller opened it before this call:
|
|
132
|
+
* the turn runner does, before it reads history, so a stop asked for while
|
|
133
|
+
* the turn waited is heard first. Without it, one is opened from
|
|
134
|
+
* `config.stops`.
|
|
135
|
+
*/
|
|
136
|
+
stopWatch?: TurnStopWatch;
|
|
137
|
+
/**
|
|
138
|
+
* How long this process has left, in ms, when the host knows (a Lambda's
|
|
139
|
+
* remaining time). A stopped turn stores and announces within it.
|
|
140
|
+
*/
|
|
141
|
+
remainingMs?: () => number;
|
|
106
142
|
}
|
|
107
143
|
/**
|
|
108
144
|
* Rich history message — supports full conversation state including tool calls and results.
|
|
@@ -115,6 +151,12 @@ export type TurnHistoryMessage = {
|
|
|
115
151
|
role: 'assistant';
|
|
116
152
|
content: string | null;
|
|
117
153
|
tool_calls?: ToolCallRef[];
|
|
154
|
+
/**
|
|
155
|
+
* Set on the last assistant message of a turn that was stopped
|
|
156
|
+
* (`TurnMessage.stopped`, as the host stored it). The model is told so
|
|
157
|
+
* after the message's text.
|
|
158
|
+
*/
|
|
159
|
+
stopped?: TurnStoppedMarker | null;
|
|
118
160
|
} | {
|
|
119
161
|
role: 'tool';
|
|
120
162
|
content: string;
|
|
@@ -161,8 +203,16 @@ export interface AgentTurnResult {
|
|
|
161
203
|
*/
|
|
162
204
|
settledApprovals?: string[];
|
|
163
205
|
maxRoundsReached: boolean;
|
|
164
|
-
/**
|
|
165
|
-
|
|
206
|
+
/**
|
|
207
|
+
* Why the turn ended: which bound or condition terminated the loop, or
|
|
208
|
+
* that it was stopped (`user_stop`, `superseded`: ADR-0252).
|
|
209
|
+
*/
|
|
210
|
+
stopReason: 'present_options' | 'awaiting_approval' | 'step_count' | 'token_budget' | 'deadline' | 'complete' | 'error' | TurnStopReason;
|
|
211
|
+
/**
|
|
212
|
+
* Set when the turn was stopped: `newMessages` is what it had produced, each
|
|
213
|
+
* call with exactly one result, the last assistant message marked.
|
|
214
|
+
*/
|
|
215
|
+
stopped?: TurnStoppedMarker;
|
|
166
216
|
}
|
|
167
217
|
export interface TurnMessage {
|
|
168
218
|
role: 'assistant' | 'tool';
|
|
@@ -174,5 +224,12 @@ export interface TurnMessage {
|
|
|
174
224
|
}>;
|
|
175
225
|
toolCallId?: string;
|
|
176
226
|
name?: string;
|
|
227
|
+
/**
|
|
228
|
+
* On the last assistant message of a stopped turn (ADR-0252 §2.3). The host
|
|
229
|
+
* stores it with the message and hands it back in history
|
|
230
|
+
* (`TurnHistoryMessage.stopped`). A message that has only the marker carries
|
|
231
|
+
* the marker's line as its `content`, so it is never empty.
|
|
232
|
+
*/
|
|
233
|
+
stopped?: TurnStoppedMarker;
|
|
177
234
|
}
|
|
178
235
|
//# s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AAS,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE;QACL,6EAA6E;QAC7E,YAAY,EAAE,MAAM,CAAC;QACrB,gBAAgB,EAAE,MAAM,CAAC;QACzB,WAAW,EAAE,MAAM,CAAC;QACpB;;;;;WAKG;QACH,gBAAgB,EAAE,MAAM,CAAC;QACzB,uGAAuG;QACvG,eAAe,EAAE,MAAM,CAAC;QACxB,8EAA8E;QAC9E,gBAAgB,EAAE,MAAM,CAAC;KAC1B,CAAC;IACF,WAAW,EAAE,WAAW,EAAE,CAAC;IAC3B;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,MAAM,EAAE,CAAC;IAC5B,gBAAgB,EAAE,OAAO,CAAC;IAC1B;;;OAGG;IACH,UAAU,EACN,iBAAiB,GACjB,mBAAmB,GACnB,YAAY,GACZ,cAAc,GACd,UAAU,GACV,UAAU,GACV,OAAO,GACP,cAAc,CAAC;IACnB;;;OAGG;IACH,OAAO,CAAC,EAAE,iBAAiB,CAAC;CAC7B;AAED,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,WAAW,GAAG,MAAM,CAAC;IAC3B,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;IACvB,SAAS,CAAC,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAAE,CAAC,CAAC;IACpF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd;;;;;OAKG;IACH,OAAO,CAAC,EAAE,iBAAiB,CAAC;CAC7B"}
|
package/dist/ui/knowledge.d.ts
CHANGED
|
@@ -10,10 +10,24 @@
|
|
|
10
10
|
* The worker renders it into the system prompt after the host's own prompt, for
|
|
11
11
|
* every host: a persona or a `systemPrompt` callback never sees it as context
|
|
12
12
|
* and never has to render it.
|
|
13
|
+
*
|
|
14
|
+
* It is bounded, as the page's index is (ADR-0245): in session 24611234 the
|
|
15
|
+
* video editor's knowledge was 117,000 characters, most of it a page detail
|
|
16
|
+
* that repeats what the index already lists, in every model call of every
|
|
17
|
+
* turn. What fits in `KNOWLEDGE_PROMPT_CHARS` is sent; the rest of an entry,
|
|
18
|
+
* and a workflow's steps, are read with `ui_guide` when they are needed, and
|
|
19
|
+
* the prompt says what is not shown and how to read it.
|
|
13
20
|
*/
|
|
14
21
|
import type { ResolvedKnowledge } from '@ouispec/bindings';
|
|
22
|
+
import type { RegisteredTool } from '../tools/types.js';
|
|
15
23
|
/** The context key a UI client uses for its knowledge. */
|
|
16
24
|
export declare const CLIENT_KNOWLEDGE_KEY = "uiKnowledge";
|
|
25
|
+
/** The tool that reads the rest of the knowledge. */
|
|
26
|
+
export declare const KNOWLEDGE_TOOL = "ui_guide";
|
|
27
|
+
/** The knowledge the system prompt carries at most, in characters. One constant. */
|
|
28
|
+
export declare const KNOWLEDGE_PROMPT_CHARS = 12000;
|
|
29
|
+
/** What one `ui_guide` answer gives at most. */
|
|
30
|
+
export declare const KNOWLEDGE_PAGE_CHARS = 12000;
|
|
17
31
|
/** What a UI client sends: the knowledge for the page the user is on. */
|
|
18
32
|
export type ClientKnowledge = ResolvedKnowledge;
|
|
19
33
|
/**
|
|
@@ -23,8 +37,20 @@ export type ClientKnowledge = ResolvedKnowledge;
|
|
|
23
37
|
* become "this client knows nothing".
|
|
24
38
|
*/
|
|
25
39
|
export declare function readClientKnowledge(context: Record<string, unknown> | null | undefined): ClientKnowledge | null;
|
|
26
|
-
/**
|
|
27
|
-
|
|
40
|
+
/**
|
|
41
|
+
* The knowledge as a prompt section, within `maxChars`: every entry whole when
|
|
42
|
+
* all of it fits, and every workflow with its steps. Over that, small entries
|
|
43
|
+
* stay whole, a large one is cut at a line with a note saying how much is left
|
|
44
|
+
* and how to read it, and the workflows are listed by name to be read one at a
|
|
45
|
+
* time.
|
|
46
|
+
*/
|
|
47
|
+
export declare function renderClientKnowledge(knowledge: ClientKnowledge, maxChars?: number): string;
|
|
48
|
+
/**
|
|
49
|
+
* Reads what the prompt leaves out of the client's knowledge: the rest of an
|
|
50
|
+
* entry, a page at a time, or a workflow in full. It reads only what the turn's
|
|
51
|
+
* client sent, so it changes nothing and needs no approval.
|
|
52
|
+
*/
|
|
53
|
+
export declare function knowledgeTool(knowledge: ClientKnowledge): RegisteredTool;
|
|
28
54
|
/** The host's system prompt, followed by the knowledge the turn's client sent, if any. */
|
|
29
55
|
export declare function withClientKnowledge(systemPrompt: string, context: Record<string, unknown> | null | undefined): string;
|
|
30
56
|
//# sourceMappingURL=knowledge.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"knowledge.d.ts","sourceRoot":"","sources":["../../src/ui/knowledge.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"knowledge.d.ts","sourceRoot":"","sources":["../../src/ui/knowledge.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC3D,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAExD,0DAA0D;AAC1D,eAAO,MAAM,oBAAoB,gBAAgB,CAAC;AAClD,qDAAqD;AACrD,eAAO,MAAM,cAAc,aAAa,CAAC;AACzC,oFAAoF;AACpF,eAAO,MAAM,sBAAsB,QAAS,CAAC;AAG7C,gDAAgD;AAChD,eAAO,MAAM,oBAAoB,QAAS,CAAC;AAE3C,yEAAyE;AACzE,MAAM,MAAM,eAAe,GAAG,iBAAiB,CAAC;AAEhD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,eAAe,GAAG,IAAI,CAe/G;AAcD;;;;;;GAMG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,eAAe,EAAE,QAAQ,SAAyB,GAAG,MAAM,CAqC3G;AAED;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,SAAS,EAAE,eAAe,GAAG,cAAc,CAmDxE;AAED,0FAA0F;AAC1F,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAIrH"}
|
package/dist/ui/knowledge.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
/** The context key a UI client uses for its knowledge. */
|
|
2
2
|
export const CLIENT_KNOWLEDGE_KEY = 'uiKnowledge';
|
|
3
|
+
/** The tool that reads the rest of the knowledge. */
|
|
4
|
+
export const KNOWLEDGE_TOOL = 'ui_guide';
|
|
5
|
+
/** The knowledge the system prompt carries at most, in characters. One constant. */
|
|
6
|
+
export const KNOWLEDGE_PROMPT_CHARS = 12_000;
|
|
7
|
+
/** An entry this size or smaller is never cut: a map, a frame, a neighbouring page's summary. */
|
|
8
|
+
const WHOLE_ENTRY_CHARS = 1_500;
|
|
9
|
+
/** What one `ui_guide` answer gives at most. */
|
|
10
|
+
export const KNOWLEDGE_PAGE_CHARS = 12_000;
|
|
3
11
|
/**
|
|
4
12
|
* Read and validate the knowledge from a turn's context. Returns null when the
|
|
5
13
|
* turn carries none (a client with no UI), and throws when it carries knowledge
|
|
@@ -28,19 +36,115 @@ export function readClientKnowledge(context) {
|
|
|
28
36
|
});
|
|
29
37
|
return { entries, workflows };
|
|
30
38
|
}
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
/** A workflow in full: its trigger and numbered steps. */
|
|
40
|
+
function workflowText(w) {
|
|
41
|
+
return `Trigger: ${w.trigger}\nSteps:\n${w.steps.map((step, i) => `${i + 1}. ${step}`).join('\n')}`;
|
|
42
|
+
}
|
|
43
|
+
/** `text` cut at a line end at most `max` characters in, never mid-line when a line end is near. */
|
|
44
|
+
function cutAt(text, max) {
|
|
45
|
+
if (text.length <= max)
|
|
46
|
+
return text;
|
|
47
|
+
const end = text.lastIndexOf('\n', max);
|
|
48
|
+
return text.slice(0, end > max / 2 ? end : max);
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The knowledge as a prompt section, within `maxChars`: every entry whole when
|
|
52
|
+
* all of it fits, and every workflow with its steps. Over that, small entries
|
|
53
|
+
* stay whole, a large one is cut at a line with a note saying how much is left
|
|
54
|
+
* and how to read it, and the workflows are listed by name to be read one at a
|
|
55
|
+
* time.
|
|
56
|
+
*/
|
|
57
|
+
export function renderClientKnowledge(knowledge, maxChars = KNOWLEDGE_PROMPT_CHARS) {
|
|
58
|
+
const entryHead = '## Platform Knowledge (Context-Aware)\n\n';
|
|
59
|
+
const workflowHead = '## Active Workflows\n\n';
|
|
60
|
+
const whole = (e) => `### ${e.title}\n${e.content}`;
|
|
61
|
+
const wholeWorkflows = knowledge.workflows.map((w) => `### ${w.name}\n${workflowText(w)}`).join('\n\n');
|
|
62
|
+
const sections = (entries, workflows) => [entries.length ? entryHead + entries.join('\n\n') : '', workflows ? workflowHead + workflows : '']
|
|
63
|
+
.filter(Boolean)
|
|
64
|
+
.join('\n\n');
|
|
65
|
+
const all = sections(knowledge.entries.map(whole), wholeWorkflows);
|
|
66
|
+
if (all.length <= maxChars)
|
|
67
|
+
return all;
|
|
68
|
+
// The workflows by name: each read whole with the tool.
|
|
69
|
+
const named = knowledge.workflows.length
|
|
70
|
+
? `Each is read in full, with its steps, by \`${KNOWLEDGE_TOOL}\` with \`workflow\` set to its name.\n` +
|
|
71
|
+
knowledge.workflows.map((w) => `- ${w.name}`).join('\n')
|
|
72
|
+
: '';
|
|
73
|
+
const workflowsSize = named ? workflowHead.length + named.length + 2 : 0;
|
|
74
|
+
// The small entries whole; the large ones share what is left, each cut at a line.
|
|
75
|
+
const small = knowledge.entries.filter((e) => whole(e).length <= WHOLE_ENTRY_CHARS);
|
|
76
|
+
const large = knowledge.entries.filter((e) => whole(e).length > WHOLE_ENTRY_CHARS);
|
|
77
|
+
const fixed = entryHead.length + small.reduce((n, e) => n + whole(e).length + 2, 0);
|
|
78
|
+
const share = Math.max(0, Math.floor((maxChars - workflowsSize - fixed) / Math.max(large.length, 1)) - 200);
|
|
79
|
+
const rendered = knowledge.entries.map((e) => {
|
|
80
|
+
if (!large.includes(e))
|
|
81
|
+
return whole(e);
|
|
82
|
+
const shown = cutAt(e.content, share);
|
|
83
|
+
const rest = e.content.length - shown.length;
|
|
84
|
+
return (`### ${e.title}\n${shown}` +
|
|
85
|
+
(rest > 0
|
|
86
|
+
? `\n(${rest} more characters of "${e.title}" are not shown: \`${KNOWLEDGE_TOOL}\` with \`entry\` set to this title and \`from: ${shown.length}\` reads them.)`
|
|
87
|
+
: ''));
|
|
88
|
+
});
|
|
89
|
+
return sections(rendered, named);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Reads what the prompt leaves out of the client's knowledge: the rest of an
|
|
93
|
+
* entry, a page at a time, or a workflow in full. It reads only what the turn's
|
|
94
|
+
* client sent, so it changes nothing and needs no approval.
|
|
95
|
+
*/
|
|
96
|
+
export function knowledgeTool(knowledge) {
|
|
97
|
+
const titles = knowledge.entries.map((e) => e.title);
|
|
98
|
+
const names = knowledge.workflows.map((w) => w.name);
|
|
99
|
+
const listed = (items) => items.slice(0, 40).map((t) => `"${t}"`).join(', ') + (items.length > 40 ? ', …' : '');
|
|
100
|
+
return {
|
|
101
|
+
name: KNOWLEDGE_TOOL,
|
|
102
|
+
kind: 'ui',
|
|
103
|
+
effect: 'view',
|
|
104
|
+
description: 'Reads the part of what the app knows about this page that your instructions do not show: the rest of a ' +
|
|
105
|
+
'knowledge entry (`entry`, its title, and `from`, where to continue), or one workflow with its steps (`workflow`, its name). ' +
|
|
106
|
+
'Your instructions say what is not shown and give the title or name.',
|
|
107
|
+
inputSchema: {
|
|
108
|
+
type: 'object',
|
|
109
|
+
additionalProperties: false,
|
|
110
|
+
properties: {
|
|
111
|
+
entry: { type: 'string', description: 'A knowledge entry’s title, as your instructions give it.' },
|
|
112
|
+
workflow: { type: 'string', description: 'A workflow’s name, as your instructions list it.' },
|
|
113
|
+
from: { type: 'integer', minimum: 0, description: 'Where in the entry to begin. Default 0.' },
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
async execute(input) {
|
|
117
|
+
const workflow = typeof input.workflow === 'string' ? input.workflow.trim() : '';
|
|
118
|
+
const entry = typeof input.entry === 'string' ? input.entry.trim() : '';
|
|
119
|
+
if (workflow) {
|
|
120
|
+
const found = knowledge.workflows.find((w) => w.name === workflow) ??
|
|
121
|
+
knowledge.workflows.find((w) => w.name.toLowerCase() === workflow.toLowerCase());
|
|
122
|
+
if (!found)
|
|
123
|
+
return { success: false, error: `No workflow is named "${workflow}". Workflows: ${listed(names)}.` };
|
|
124
|
+
return { success: true, data: { workflow: found.name, text: workflowText(found) } };
|
|
125
|
+
}
|
|
126
|
+
if (entry) {
|
|
127
|
+
const found = knowledge.entries.find((e) => e.title === entry) ??
|
|
128
|
+
knowledge.entries.find((e) => e.title.toLowerCase() === entry.toLowerCase());
|
|
129
|
+
if (!found)
|
|
130
|
+
return { success: false, error: `No knowledge entry has the title "${entry}". Entries: ${listed(titles)}.` };
|
|
131
|
+
const from = typeof input.from === 'number' && input.from > 0 ? Math.min(input.from, found.content.length) : 0;
|
|
132
|
+
const text = cutAt(found.content.slice(from), KNOWLEDGE_PAGE_CHARS);
|
|
133
|
+
const next = from + text.length;
|
|
134
|
+
return {
|
|
135
|
+
success: true,
|
|
136
|
+
data: {
|
|
137
|
+
entry: found.title,
|
|
138
|
+
from,
|
|
139
|
+
total: found.content.length,
|
|
140
|
+
text,
|
|
141
|
+
...(next < found.content.length ? { next } : {}),
|
|
142
|
+
},
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
return { success: false, error: 'Give an `entry` title or a `workflow` name.' };
|
|
146
|
+
},
|
|
147
|
+
};
|
|
44
148
|
}
|
|
45
149
|
/** The host's system prompt, followed by the knowledge the turn's client sent, if any. */
|
|
46
150
|
export function withClientKnowledge(systemPrompt, context) {
|
package/dist/ui/knowledge.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"knowledge.js","sourceRoot":"","sources":["../../src/ui/knowledge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"knowledge.js","sourceRoot":"","sources":["../../src/ui/knowledge.ts"],"names":[],"mappings":"AAuBA,0DAA0D;AAC1D,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAAC;AAClD,qDAAqD;AACrD,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,CAAC;AACzC,oFAAoF;AACpF,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC;AAC7C,iGAAiG;AACjG,MAAM,iBAAiB,GAAG,KAAK,CAAC;AAChC,gDAAgD;AAChD,MAAM,CAAC,MAAM,oBAAoB,GAAG,MAAM,CAAC;AAK3C;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,OAAmD;IACrF,MAAM,GAAG,GAAG,OAAO,EAAE,CAAC,oBAAoB,CAAC,CAAC;IAC5C,IAAI,GAAG,KAAK,SAAS,IAAI,GAAG,KAAK,IAAI;QAAE,OAAO,IAAI,CAAC;IACnD,MAAM,KAAK,GAAG,WAAW,oBAAoB,EAAE,CAAC;IAChD,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,MAAM,IAAI,KAAK,CAAC,eAAe,KAAK,oBAAoB,CAAC,CAAC;IACvF,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,GAA8B,CAAC;IAC9D,I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state`, up to the page-state
|
|
5
|
+
* budget), so the model sees what its action did. Kept on every answer, a turn
|
|
6
|
+
* of many actions resends every earlier page with every step: in session
|
|
7
|
+
* 24611234 a turn of 24 editor actions peaked at 205,000 prompt tokens, about
|
|
8
|
+
* 5,000 for each answer kept. An earlier page is not what the page is now, and
|
|
9
|
+
* the newest answer holds that.
|
|
10
|
+
*
|
|
11
|
+
* So before each step, every earlier answer keeps what it did (its result, the
|
|
12
|
+
* rows it changed, what the page offers since, any error) and its `state` is
|
|
13
|
+
* replaced with one line that says where the page's state is.
|
|
14
|
+
*/
|
|
15
|
+
import type { ModelMessage } from 'ai';
|
|
16
|
+
export declare const SUPERSEDED_STATE = "Not repeated: a later answer in this conversation carries the page\u2019s state, which is what the page is now.";
|
|
17
|
+
/**
|
|
18
|
+
* `messages` with the page's state kept on the newest answer that carries one
|
|
19
|
+
* and replaced on every earlier one, or null when there is nothing to replace.
|
|
20
|
+
*/
|
|
21
|
+
export declare function withNewestPageStateOnly(messages: readonly ModelMessage[]): {
|
|
22
|
+
messages: ModelMessage[];
|
|
23
|
+
replaced: number;
|
|
24
|
+
} | null;
|
|
25
|
+
//# sourceMappingURL=newest-page-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"newest-page-state.d.ts","sourceRoot":"","sources":["../../src/ui/newest-page-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,IAAI,CAAC;AAEvC,eAAO,MAAM,gBAAgB,oHACiF,CAAC;AAgD/G;;;GAGG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,SAAS,YAAY,EAAE,GAAG;IAAE,QAAQ,EAAE,YAAY,EAAE,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAkChI"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
export const SUPERSEDED_STATE = 'Not repeated: a later answer in this conversation carries the page’s state, which is what the page is now.';
|
|
2
|
+
/** The JSON text of an answer, when it is a UI answer that carries the page's state. */
|
|
3
|
+
function stateful(text) {
|
|
4
|
+
if (!text.includes('"state"'))
|
|
5
|
+
return null;
|
|
6
|
+
try {
|
|
7
|
+
const value = JSON.parse(text);
|
|
8
|
+
return value && typeof value === 'object' && !Array.isArray(value) && 'state' in value
|
|
9
|
+
? value
|
|
10
|
+
: null;
|
|
11
|
+
}
|
|
12
|
+
catch {
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
/** The answer's text, wherever its output keeps it. */
|
|
17
|
+
function textOf(output) {
|
|
18
|
+
if (output.type === 'text')
|
|
19
|
+
return output.value;
|
|
20
|
+
if (output.type === 'json')
|
|
21
|
+
return JSON.stringify(output.value);
|
|
22
|
+
if (output.type === 'content') {
|
|
23
|
+
const part = output.value.find((p) => p.type === 'text');
|
|
24
|
+
return part?.text ?? null;
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
function withText(output, text) {
|
|
29
|
+
if (output.type === 'text')
|
|
30
|
+
return { ...output, value: text };
|
|
31
|
+
if (output.type === 'json')
|
|
32
|
+
return { ...output, value: JSON.parse(text) };
|
|
33
|
+
if (output.type === 'content') {
|
|
34
|
+
let done = false;
|
|
35
|
+
return {
|
|
36
|
+
...output,
|
|
37
|
+
value: output.value.map((p) => {
|
|
38
|
+
if (done || p.type !== 'text')
|
|
39
|
+
return p;
|
|
40
|
+
done = true;
|
|
41
|
+
return { ...p, text };
|
|
42
|
+
}),
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
return output;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* `messages` with the page's state kept on the newest answer that carries one
|
|
49
|
+
* and replaced on every earlier one, or null when there is nothing to replace.
|
|
50
|
+
*/
|
|
51
|
+
export function withNewestPageStateOnly(messages) {
|
|
52
|
+
// The newest answer with a state, found from the end.
|
|
53
|
+
let newest = null;
|
|
54
|
+
for (let i = messages.length - 1; i >= 0 && newest === null; i--) {
|
|
55
|
+
const m = messages[i];
|
|
56
|
+
if (m.role !== 'tool')
|
|
57
|
+
continue;
|
|
58
|
+
for (let j = m.content.length - 1; j >= 0; j--) {
|
|
59
|
+
const part = m.content[j];
|
|
60
|
+
if (part.type !== 'tool-result')
|
|
61
|
+
continue;
|
|
62
|
+
const text = textOf(part.output);
|
|
63
|
+
if (text !== null && stateful(text)) {
|
|
64
|
+
newest = part.toolCallId;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
if (newest === null)
|
|
70
|
+
return null;
|
|
71
|
+
let replaced = 0;
|
|
72
|
+
const out = messages.map((m) => {
|
|
73
|
+
if (m.role !== 'tool')
|
|
74
|
+
return m;
|
|
75
|
+
let changed = false;
|
|
76
|
+
const content = m.content.map((part) => {
|
|
77
|
+
if (part.type !== 'tool-result' || part.toolCallId === newest)
|
|
78
|
+
return part;
|
|
79
|
+
const text = textOf(part.output);
|
|
80
|
+
const answer = text === null ? null : stateful(text);
|
|
81
|
+
if (!answer || answer.state === SUPERSEDED_STATE)
|
|
82
|
+
return part;
|
|
83
|
+
changed = true;
|
|
84
|
+
replaced++;
|
|
85
|
+
return { ...part, output: withText(part.output, JSON.stringify({ ...answer, state: SUPERSEDED_STATE })) };
|
|
86
|
+
});
|
|
87
|
+
return changed ? { ...m, content } : m;
|
|
88
|
+
});
|
|
89
|
+
return replaced ? { messages: out, replaced } : null;
|
|
90
|
+
}
|
|
91
|
+
//# sourceMappingURL=newest-page-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"newest-page-state.js","sourceRoot":"","sources":["../../src/ui/newest-page-state.ts"],"names":[],"mappings":"AAgBA,MAAM,CAAC,MAAM,gBAAgB,GAC3B,4GAA4G,CAAC;AAO/G,wFAAwF;AACxF,SAAS,QAAQ,CAAC,IAAY;IAC5B,IAAI,CAAC,IAAI,CA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C;AACvD,CAAC"}
|
package/dist/ui/ui-tools.d.ts
CHANGED
|
@@ -55,6 +55,12 @@ export interface UIToolDependencies {
|
|
|
55
55
|
* reported as running, never as done. Unbounded when not given.
|
|
56
56
|
*/
|
|
57
57
|
waitDeadline?: () => number;
|
|
58
|
+
/**
|
|
59
|
+
* The longest a call waits for the outcome of work its action started, in ms;
|
|
60
|
+
* `DEFAULT_JOB_WAIT_MS` when not given. Never longer than the action's own
|
|
61
|
+
* limit or `waitDeadline`.
|
|
62
|
+
*/
|
|
63
|
+
jobWaitMs?: number;
|
|
58
64
|
/**
|
|
59
65
|
* The turn's UI action queue, shared by every set of UI tools built during the
|
|
60
66
|
* turn, so the actions run one at a time in the order they were called. A new
|
|
@@ -85,8 +91,18 @@ export declare const MAX_RESEND_AFTER_MS = 8000;
|
|
|
85
91
|
* `reanswerAfterMs`, 8 s), so the repeat recovers an answer that was lost.
|
|
86
92
|
*/
|
|
87
93
|
export declare const RECEIVED_RESEND_AFTER_MS = 10000;
|
|
88
|
-
/**
|
|
89
|
-
|
|
94
|
+
/**
|
|
95
|
+
* The longest a UI tool waits, in the call, for the outcome of work an action
|
|
96
|
+
* started (a GPU job, an export): `UIToolDependencies.jobWaitMs` by default.
|
|
97
|
+
*
|
|
98
|
+
* Work that ends within it is reported done in the call. Work that does not is
|
|
99
|
+
* reported still running, and the turn goes on and ends: its outcome reaches
|
|
100
|
+
* the conversation through the page state, where the app's job tracker lists
|
|
101
|
+
* it, in the next turn. The call never waits on the action's own limit (its
|
|
102
|
+
* `maxDurationMs`), which can be many minutes for a job queued behind a live
|
|
103
|
+
* conversation: a turn held open that long could not be stopped or answered.
|
|
104
|
+
*/
|
|
105
|
+
export declare const DEFAULT_JOB_WAIT_MS = 20000;
|
|
90
106
|
/** The most actions one `ui_describe` call describes. */
|
|
91
107
|
export declare const MAX_DESCRIBED_ACTIONS = 8;
|
|
92
108
|
/**
|
|
@@ -103,6 +119,8 @@ export declare function buildUITools(page: readonly PageSurface[], deps: UIToolD
|
|
|
103
119
|
/** Thrown when an action's definition cannot be had: the model is told why. */
|
|
104
120
|
export declare class DefinitionUnavailable extends Error {
|
|
105
121
|
}
|
|
122
|
+
/** The call's wait for a started action's outcome. */
|
|
123
|
+
export declare function jobWaitOf(deps: Pick<UIToolDependencies, 'jobWaitMs'>): number;
|
|
106
124
|
/** What of the page's state the client left out to fit its answer, and how to read each part (oui-spec §7.3.9). */
|
|
107
125
|
export declare function fitNotes(cuts: NonNullable<OUIFit['observations']>): string[];
|
|
108
126
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ui-tools.d.ts","sourceRoot":"","sources":["../../src/ui/ui-tools.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ui-tools.d.ts","sourceRoot":"","sources":["../../src/ui/ui-tools.ts"],"names":[],"mappings":"AAmBA,OAAO,EAQL,KAAK,eAAe,EACpB,KAAK,MAAM,EACZ,MAAM,eAAe,CAAC;AACvB,OAAO,KAAK,EAAE,cAAc,EAA6C,MAAM,mBAAmB,CAAC;AACnG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AAGpD,OAAO,EASL,KAAK,eAAe,EAEpB,KAAK,WAAW,EACjB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAoB,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAErE,uHAAuH;AACvH,eAAO,MAAM,WAAW,UAAqB,CAAC;AAC9C,4CAA4C;AAC5C,eAAO,MAAM,gBAAgB,eAA0B,CAAC;AACxD,oDAAoD;AACpD,eAAO,MAAM,YAAY,WAAsB,CAAC;AAEhD;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IACxB,wDAAwD;IACxD,KAAK,IAAI,MAAM,GAAG,IAAI,CAAC;IACvB,IAAI,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,IAAI,IAAI,IAAI,CAAC;IACb;;;;OAIG;IACH,YAAY,IAAI;QAAE,KA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