@dudousxd/nestjs-agent-core 0.38.1 → 0.40.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/dist/ag-ui/index.cjs +78 -0
- package/dist/ag-ui/index.cjs.map +1 -1
- package/dist/ag-ui/index.d.cts +12 -2
- package/dist/ag-ui/index.d.ts +12 -2
- package/dist/ag-ui/index.js +77 -0
- package/dist/ag-ui/index.js.map +1 -1
- package/dist/genui/builtins.cjs +2 -0
- package/dist/genui/builtins.cjs.map +1 -1
- package/dist/genui/builtins.js +2 -0
- package/dist/genui/builtins.js.map +1 -1
- package/dist/genui/index.cjs +120 -38
- package/dist/genui/index.cjs.map +1 -1
- package/dist/genui/index.d.cts +2 -2
- package/dist/genui/index.d.ts +2 -2
- package/dist/genui/index.js +116 -37
- package/dist/genui/index.js.map +1 -1
- package/dist/guardrails/index.d.cts +3 -3
- package/dist/guardrails/index.d.ts +3 -3
- package/dist/index.cjs +2524 -148
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +321 -95
- package/dist/index.d.ts +321 -95
- package/dist/index.js +2482 -144
- package/dist/index.js.map +1 -1
- package/dist/{processors-CAVevaYJ.d.cts → processors-B7nfbU6E.d.cts} +3 -1
- package/dist/{processors-C-FP4nDy.d.ts → processors-BR3nICcp.d.ts} +3 -1
- package/dist/{stream-events-rpd3d6gh.d.cts → stream-events-DAmes2Of.d.ts} +704 -86
- package/dist/{stream-events-rpd3d6gh.d.ts → stream-events-M0jc7lSW.d.cts} +704 -86
- package/package.json +1 -1
- package/dist/tool-Dp8HA_f4.d.cts +0 -119
- package/dist/tool-hhssZ_HW.d.ts +0 -119
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import { a as Catalog } from './catalog-CrzetM3_.cjs';
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Typed answers for a question set: a question that asks for a number, a date, an email or a
|
|
@@ -69,6 +70,419 @@ declare function readElicitationInput(raw: unknown): ElicitationInput | undefine
|
|
|
69
70
|
*/
|
|
70
71
|
declare function readElicitationQuestions(input: unknown): ElicitationQuestion[];
|
|
71
72
|
|
|
73
|
+
/**
|
|
74
|
+
* How a person-facing surface talks about a tool WITHOUT ever naming it. Declared on the server,
|
|
75
|
+
* beside the tool's input schema, because whoever changes the input is the one who has to re-word
|
|
76
|
+
* the sentence that mentions it — and a client that shipped its own name-to-sentence map would go
|
|
77
|
+
* stale the moment a tool was renamed. A tool name is an identifier, never copy.
|
|
78
|
+
*
|
|
79
|
+
* `running` / `done` (and `confirm.title`, `confirm.detail`, `result.text`) are templates:
|
|
80
|
+
* `{dotted.path}` placeholders are filled from the call's INPUT (or, for `result`, its OUTPUT), so one
|
|
81
|
+
* declaration covers every call the tool will ever receive and replays identically from history.
|
|
82
|
+
* A placeholder with nothing behind it collapses along with the space before it.
|
|
83
|
+
*/
|
|
84
|
+
interface ToolPresentation {
|
|
85
|
+
/** Noun phrase, for counts and headings: "Database query", "Knowledge base". */
|
|
86
|
+
label: string;
|
|
87
|
+
/** Present progressive, while the call is in flight: "Reading {bucket}". */
|
|
88
|
+
running: string;
|
|
89
|
+
/** Settled, once the output is in: "Read {bucket}". */
|
|
90
|
+
done: string;
|
|
91
|
+
/** A key into the client's own glyph map (`database`, `search`, …). Unknown keys fall back to a generic glyph there. */
|
|
92
|
+
icon?: string;
|
|
93
|
+
/** One line naming what the tool reaches, for when the activity line is opened. */
|
|
94
|
+
detail?: string;
|
|
95
|
+
/** `destructive` earns the warning treatment on an approval prompt. */
|
|
96
|
+
tone?: ToolPresentationTone;
|
|
97
|
+
/** What a person is being asked to allow when an `action` call parks for approval. */
|
|
98
|
+
confirm?: ToolConfirmation;
|
|
99
|
+
/** How the call's OUTPUT reads as content. */
|
|
100
|
+
result?: ToolResultView;
|
|
101
|
+
}
|
|
102
|
+
type ToolPresentationTone = 'neutral' | 'destructive';
|
|
103
|
+
interface ToolConfirmation {
|
|
104
|
+
/** "Delete {count} files?" */
|
|
105
|
+
title: string;
|
|
106
|
+
/** The button: "Delete". */
|
|
107
|
+
verb: string;
|
|
108
|
+
/** A sentence under the title, when the title alone does not say what changes. */
|
|
109
|
+
detail?: string;
|
|
110
|
+
}
|
|
111
|
+
/** A value read out of a tool's output by dotted path, with the words to put next to it. */
|
|
112
|
+
interface ToolResultField {
|
|
113
|
+
path: string;
|
|
114
|
+
label: string;
|
|
115
|
+
unit?: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* How a tool's output reads as content. Every variant names dotted paths into the output rather
|
|
119
|
+
* than shapes, so a renderer never has to recognise which tool it is drawing: it receives
|
|
120
|
+
* `{ view, output }` and draws it.
|
|
121
|
+
*/
|
|
122
|
+
type ToolResultView =
|
|
123
|
+
/** A row of labelled readings — one result, several facets. */
|
|
124
|
+
{
|
|
125
|
+
kind: 'metrics';
|
|
126
|
+
fields: ToolResultField[];
|
|
127
|
+
}
|
|
128
|
+
/** `rows` is a path to an array; each column's `path` is read WITHIN a row. */
|
|
129
|
+
| {
|
|
130
|
+
kind: 'table';
|
|
131
|
+
columns: ToolResultField[];
|
|
132
|
+
rows: string;
|
|
133
|
+
empty?: string;
|
|
134
|
+
}
|
|
135
|
+
/** `lines` is a path to an array of strings, drawn as a log tail. */
|
|
136
|
+
| {
|
|
137
|
+
kind: 'log';
|
|
138
|
+
lines: string;
|
|
139
|
+
}
|
|
140
|
+
/** One sentence, templated over the output. */
|
|
141
|
+
| {
|
|
142
|
+
kind: 'note';
|
|
143
|
+
text: string;
|
|
144
|
+
}
|
|
145
|
+
/** The output is drawn somewhere else on the screen already (a pushed component, a side panel). */
|
|
146
|
+
| {
|
|
147
|
+
kind: 'elsewhere';
|
|
148
|
+
};
|
|
149
|
+
/**
|
|
150
|
+
* `GET <base>/tools?agent=*` (and `useToolCatalog({ agent: ALL_AGENTS })`): every tool the actor
|
|
151
|
+
* reaches through ANY agent, each once — for a surface that shows several agents' conversations.
|
|
152
|
+
*/
|
|
153
|
+
declare const ALL_AGENTS = "*";
|
|
154
|
+
/**
|
|
155
|
+
* One tool as `GET <base>/tools` reports it: the tools THIS actor may be offered by the chosen agent,
|
|
156
|
+
* with how each is spoken about. `presentation` is absent for a tool that declared none — a client
|
|
157
|
+
* then narrates it generically rather than falling back to its name.
|
|
158
|
+
*/
|
|
159
|
+
interface ToolCatalogEntry {
|
|
160
|
+
/** The wire name tool parts carry (`tool-<name>`) — the key a client looks a call up by. */
|
|
161
|
+
name: string;
|
|
162
|
+
kind: ToolKind;
|
|
163
|
+
presentation?: ToolPresentation;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/** The approver that means "the person the run is acting for" — the thread's own actor. */
|
|
167
|
+
declare const REQUESTER_APPROVER = "requester";
|
|
168
|
+
/** The tool a requirement is asked about. `spec` is absent where this process cannot resolve it. */
|
|
169
|
+
interface ApprovalToolRef {
|
|
170
|
+
name: string;
|
|
171
|
+
kind: ToolKind;
|
|
172
|
+
spec?: ToolSpec;
|
|
173
|
+
}
|
|
174
|
+
/** Where the call is being made. */
|
|
175
|
+
interface ApprovalThreadRef {
|
|
176
|
+
threadId: string;
|
|
177
|
+
runId: string;
|
|
178
|
+
agentName?: string;
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* What an action tool call needs before it runs.
|
|
182
|
+
*
|
|
183
|
+
* - `required: false` → the call runs without asking anyone (it is still recorded as an action).
|
|
184
|
+
* - `approver` → who may decide: {@link REQUESTER_APPROVER} (the thread's own actor — the default)
|
|
185
|
+
* or any other string, which the default {@link ApprovalPolicy.canDecide} reads as a ROLE the
|
|
186
|
+
* decider must hold. Streamed on `approval-requested` and persisted on the call.
|
|
187
|
+
* - `ttlMs` → how long the request stays open. When it lapses the call settles `expired` and the
|
|
188
|
+
* model is told nobody approved it. Absent → it waits indefinitely.
|
|
189
|
+
*/
|
|
190
|
+
interface ApprovalRequirement {
|
|
191
|
+
required: boolean;
|
|
192
|
+
approver: string;
|
|
193
|
+
ttlMs?: number;
|
|
194
|
+
}
|
|
195
|
+
/** A decision about to be taken on a call, as {@link ApprovalPolicy.canDecide} sees it. */
|
|
196
|
+
interface ApprovalDecisionRef {
|
|
197
|
+
toolCallId: string;
|
|
198
|
+
/** The approver recorded on the call when it was put to a person. */
|
|
199
|
+
approver: string;
|
|
200
|
+
/** The actorRef the run is acting for — the owner of the call's thread. */
|
|
201
|
+
requesterRef: string;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Who has to approve an action tool call, and for how long the request stays open.
|
|
205
|
+
*
|
|
206
|
+
* Consulted by the LOOP once per `action` call, inside the call's `persist:toolcall` checkpoint — so
|
|
207
|
+
* a durable run reads the answer back on every replay instead of re-deciding it against a policy
|
|
208
|
+
* that may have changed while it was parked. Only `action` calls are asked about: a policy cannot
|
|
209
|
+
* put a `read` behind an approval, and an `ask` (a question set) is always the requester's.
|
|
210
|
+
*/
|
|
211
|
+
interface ApprovalPolicy {
|
|
212
|
+
requirementFor(tool: ApprovalToolRef, actor: Actor, thread: ApprovalThreadRef): ApprovalRequirement | Promise<ApprovalRequirement>;
|
|
213
|
+
/**
|
|
214
|
+
* May `actor` settle this call? Checked by the approve/reject routes before a decision is
|
|
215
|
+
* signalled. Absent → {@link defaultCanDecide}: the requester approver means the thread's own
|
|
216
|
+
* actor, anything else is a role the actor must hold. Plug an authz Gate here for abilities.
|
|
217
|
+
*/
|
|
218
|
+
canDecide?(actor: Actor, decision: ApprovalDecisionRef): boolean | Promise<boolean>;
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* The behaviour the lib always had: every `action` call waits on the person who asked, with no
|
|
222
|
+
* expiry.
|
|
223
|
+
*/
|
|
224
|
+
declare class DefaultApprovalPolicy implements ApprovalPolicy {
|
|
225
|
+
requirementFor(tool: ApprovalToolRef): ApprovalRequirement;
|
|
226
|
+
}
|
|
227
|
+
/** The default decider rule — see {@link ApprovalPolicy.canDecide}. */
|
|
228
|
+
declare function defaultCanDecide(actor: Actor, decision: ApprovalDecisionRef): boolean;
|
|
229
|
+
/** Resolve whether `actor` may decide, through the policy's own rule when it has one. */
|
|
230
|
+
declare function mayDecideApproval(policy: ApprovalPolicy | undefined, actor: Actor, decision: ApprovalDecisionRef): Promise<boolean>;
|
|
231
|
+
/** The columns a store keeps for one call's approval, however it names them. */
|
|
232
|
+
interface ToolCallApprovalColumns {
|
|
233
|
+
proposalId?: string | null;
|
|
234
|
+
confirmation?: ToolConfirmation | null | undefined;
|
|
235
|
+
toolCallId: string;
|
|
236
|
+
status: ToolCallStatus;
|
|
237
|
+
approver: string | null | undefined;
|
|
238
|
+
expiresAt: string | Date | null | undefined;
|
|
239
|
+
remember: boolean | null | undefined;
|
|
240
|
+
executedByRef: string | null | undefined;
|
|
241
|
+
decidedVia: string | null | undefined;
|
|
242
|
+
error: string | null | undefined;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* Read a tool-call row back as the {@link ToolCallApproval} a thread carries, or `null` for a call
|
|
246
|
+
* no policy put to anyone (no approver recorded). Shared by every store so they agree on the
|
|
247
|
+
* status mapping: a call that ran — or ran and failed — after a decision was APPROVED.
|
|
248
|
+
*/
|
|
249
|
+
declare function toolCallApprovalFromRow(row: ToolCallApprovalColumns): ToolCallApproval | null;
|
|
250
|
+
|
|
251
|
+
type ClaimedActionApproval = {
|
|
252
|
+
mode: 'auto';
|
|
253
|
+
} | {
|
|
254
|
+
mode: 'remembered';
|
|
255
|
+
approver: string;
|
|
256
|
+
} | {
|
|
257
|
+
mode: 'ask';
|
|
258
|
+
approver: string;
|
|
259
|
+
ttlMs?: number;
|
|
260
|
+
expiresAt?: string;
|
|
261
|
+
};
|
|
262
|
+
interface ResolveActionProposalApprovalInput {
|
|
263
|
+
actor: Actor;
|
|
264
|
+
thread: ApprovalThreadRef;
|
|
265
|
+
tool: ApprovalToolRef;
|
|
266
|
+
store: {
|
|
267
|
+
rememberedApprovals?(threadId: string): Promise<string[]>;
|
|
268
|
+
};
|
|
269
|
+
policy?: ApprovalPolicy;
|
|
270
|
+
clock?: () => number;
|
|
271
|
+
}
|
|
272
|
+
/** Journal this result on the trusted producer before choosing strict proposal preparation. */
|
|
273
|
+
declare function resolveActionProposalApproval(input: ResolveActionProposalApprovalInput): Promise<ClaimedActionApproval>;
|
|
274
|
+
|
|
275
|
+
/** Renderer support only. Component definitions and authorization remain server-owned. */
|
|
276
|
+
interface UiCapabilities {
|
|
277
|
+
components: Array<{
|
|
278
|
+
name: string;
|
|
279
|
+
version: number;
|
|
280
|
+
}>;
|
|
281
|
+
}
|
|
282
|
+
declare function validateUiCapabilities(value: unknown): UiCapabilities;
|
|
283
|
+
declare function negotiateCatalog(catalog: Catalog, capabilities?: UiCapabilities): Catalog;
|
|
284
|
+
type PreparedUiEmission = {
|
|
285
|
+
kind: 'ui';
|
|
286
|
+
component: string;
|
|
287
|
+
props: Record<string, unknown>;
|
|
288
|
+
version: number;
|
|
289
|
+
fallbackText: string;
|
|
290
|
+
componentVersions?: Record<string, number>;
|
|
291
|
+
} | {
|
|
292
|
+
kind: 'text';
|
|
293
|
+
text: string;
|
|
294
|
+
};
|
|
295
|
+
/** Validate against current trusted definitions before drawing or generating complete text. */
|
|
296
|
+
declare function prepareUiEmission(catalog: Catalog, capabilities: UiCapabilities | undefined, component: string, props: Record<string, unknown>, version?: number): Promise<PreparedUiEmission>;
|
|
297
|
+
|
|
298
|
+
interface ActionProposalScope {
|
|
299
|
+
/** Explicit null or string; scope strings have at most 255 UTF-16 code units. */
|
|
300
|
+
tenantRef: string | null;
|
|
301
|
+
actorRef: string;
|
|
302
|
+
threadId: string;
|
|
303
|
+
}
|
|
304
|
+
/** Persisted JSON execution descriptor; identity is resolved fresh from proposal scope. */
|
|
305
|
+
interface ActionProposalExecutionContext {
|
|
306
|
+
agentName?: string;
|
|
307
|
+
persona?: string;
|
|
308
|
+
requestId: string;
|
|
309
|
+
uiCapabilities?: UiCapabilities;
|
|
310
|
+
pageContext?: PageContext;
|
|
311
|
+
}
|
|
312
|
+
interface CreateActionProposal extends ActionProposalScope {
|
|
313
|
+
/** Globally unique deterministic identifier, at most 255 UTF-16 code units. */
|
|
314
|
+
id: string;
|
|
315
|
+
originRunId: string;
|
|
316
|
+
originMessageId: string;
|
|
317
|
+
originToolCallId: string;
|
|
318
|
+
toolName: string;
|
|
319
|
+
/** JSON-serializable immutable snapshot. */
|
|
320
|
+
input: unknown;
|
|
321
|
+
/** Original JSON before schema parsing; absence on legacy rows falls back to input. Null is present. */
|
|
322
|
+
preparationInput?: unknown;
|
|
323
|
+
/** Original execution address, never requester roles or transport/host handles. */
|
|
324
|
+
executionContext?: ActionProposalExecutionContext;
|
|
325
|
+
confirmation: ToolConfirmation;
|
|
326
|
+
approver: string;
|
|
327
|
+
/** Milliseconds since epoch; null means no expiry. */
|
|
328
|
+
expiresAt: number | null;
|
|
329
|
+
/** Stable across claims and crash recovery; tools must honor this key. */
|
|
330
|
+
idempotencyKey: string;
|
|
331
|
+
/** Explicit tool-authored replacement identity; never inferred from model text. */
|
|
332
|
+
replacementKey?: string;
|
|
333
|
+
}
|
|
334
|
+
type ActionProposalDecision = 'pending' | 'approved' | 'rejected' | 'expired' | 'superseded';
|
|
335
|
+
interface ActionProposalDecisionCommand {
|
|
336
|
+
decision: 'approved' | 'rejected' | 'expired';
|
|
337
|
+
actorRef: string;
|
|
338
|
+
via: string;
|
|
339
|
+
reason?: string;
|
|
340
|
+
remember?: boolean;
|
|
341
|
+
}
|
|
342
|
+
interface ActionProposalDecisionAudit extends Omit<ActionProposalDecisionCommand, 'decision'> {
|
|
343
|
+
at: number;
|
|
344
|
+
replacementProposalId?: string;
|
|
345
|
+
}
|
|
346
|
+
interface ActionProposalLease {
|
|
347
|
+
token: string;
|
|
348
|
+
generation: number;
|
|
349
|
+
workerId: string;
|
|
350
|
+
expiresAt: number;
|
|
351
|
+
}
|
|
352
|
+
interface ActionProposalExecution {
|
|
353
|
+
status: 'queued' | 'executing' | 'succeeded' | 'failed';
|
|
354
|
+
generation: number;
|
|
355
|
+
lease: ActionProposalLease | null;
|
|
356
|
+
result?: unknown;
|
|
357
|
+
error?: string;
|
|
358
|
+
}
|
|
359
|
+
interface ActionProposal extends CreateActionProposal {
|
|
360
|
+
decision: ActionProposalDecision;
|
|
361
|
+
decisionAudit: ActionProposalDecisionAudit | null;
|
|
362
|
+
/** Embedded durable execution work: created atomically with approval, absent before it. */
|
|
363
|
+
execution: ActionProposalExecution | null;
|
|
364
|
+
supersededBy?: string;
|
|
365
|
+
outcome?: ActionProposalOutcome;
|
|
366
|
+
outcomeDelivery?: ActionProposalOutcomeDelivery;
|
|
367
|
+
createdAt: number;
|
|
368
|
+
updatedAt: number;
|
|
369
|
+
}
|
|
370
|
+
interface CreateActionProposalResult {
|
|
371
|
+
status: 'created' | 'unchanged' | 'conflict';
|
|
372
|
+
proposal?: ActionProposal;
|
|
373
|
+
}
|
|
374
|
+
interface ActionProposalMutationResult {
|
|
375
|
+
status: 'applied' | 'unchanged' | 'conflict' | 'not_found' | 'expired';
|
|
376
|
+
/** Snapshot observed after the operation; concurrent operations may advance it. */
|
|
377
|
+
proposal?: ActionProposal;
|
|
378
|
+
}
|
|
379
|
+
interface ClaimActionProposal {
|
|
380
|
+
workerId: string;
|
|
381
|
+
leaseMs: number;
|
|
382
|
+
}
|
|
383
|
+
interface ExtendActionProposalLease {
|
|
384
|
+
token: string;
|
|
385
|
+
generation: number;
|
|
386
|
+
leaseMs: number;
|
|
387
|
+
}
|
|
388
|
+
type SettleActionProposal = {
|
|
389
|
+
token: string;
|
|
390
|
+
generation: number;
|
|
391
|
+
ui?: AgentUiComponent[];
|
|
392
|
+
text?: string;
|
|
393
|
+
} & ({
|
|
394
|
+
status: 'succeeded';
|
|
395
|
+
result?: unknown;
|
|
396
|
+
error?: never;
|
|
397
|
+
} | {
|
|
398
|
+
status: 'failed';
|
|
399
|
+
error: string;
|
|
400
|
+
result?: never;
|
|
401
|
+
});
|
|
402
|
+
interface ListActionProposals {
|
|
403
|
+
/** Default 100; integer 1..1000. Ties order by UTF-16 lexical logical id. */
|
|
404
|
+
limit?: number;
|
|
405
|
+
decision?: ActionProposalDecision;
|
|
406
|
+
/** Exclusive cursor in the same creation-time / exact logical-id order. */
|
|
407
|
+
after?: {
|
|
408
|
+
createdAt: number;
|
|
409
|
+
id: string;
|
|
410
|
+
};
|
|
411
|
+
}
|
|
412
|
+
interface ActionProposalStoreOptions {
|
|
413
|
+
/** Server-configured trusted clock, never a timestamp from a request. */
|
|
414
|
+
clock?: () => number;
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Independent capability; AgentStore implementations are not required to implement it.
|
|
418
|
+
* All identifiers are looked up within the complete scope. Creation must compare the original
|
|
419
|
+
* immutable payload on replay and reject mismatches without disclosing a differently scoped row.
|
|
420
|
+
* Decisions are first-wins CAS; approving atomically queues durable execution work. At now >=
|
|
421
|
+
* expiresAt a pending proposal expires and cannot be approved or rejected. An explicit expiry
|
|
422
|
+
* before that instant conflicts. Duplicate matching decisions are unchanged without replacing
|
|
423
|
+
* audit data. Lease claims and recovery are atomic and fenced by token AND generation. Settlement
|
|
424
|
+
* and renewal require a matching, unexpired lease; leaseMs must be a positive safe integer.
|
|
425
|
+
* Execution recovery preserves the idempotency key (delivery is at least once, not exactly once).
|
|
426
|
+
*/
|
|
427
|
+
interface ActionProposalStore {
|
|
428
|
+
createActionProposal(input: CreateActionProposal): Promise<CreateActionProposalResult>;
|
|
429
|
+
getActionProposal(scope: ActionProposalScope, id: string): Promise<ActionProposal | null>;
|
|
430
|
+
listActionProposals(scope: ActionProposalScope, query?: ListActionProposals): Promise<ActionProposal[]>;
|
|
431
|
+
decideActionProposal(scope: ActionProposalScope, id: string, command: ActionProposalDecisionCommand): Promise<ActionProposalMutationResult>;
|
|
432
|
+
claimActionProposal(scope: ActionProposalScope, id: string, command: ClaimActionProposal): Promise<ActionProposalMutationResult>;
|
|
433
|
+
extendActionProposalLease(scope: ActionProposalScope, id: string, command: ExtendActionProposalLease): Promise<ActionProposalMutationResult>;
|
|
434
|
+
settleActionProposal(scope: ActionProposalScope, id: string, command: SettleActionProposal): Promise<ActionProposalMutationResult>;
|
|
435
|
+
}
|
|
436
|
+
interface ActionProposalSupersessionStore {
|
|
437
|
+
createReplacingActionProposal(input: CreateActionProposal): Promise<CreateActionProposalResult>;
|
|
438
|
+
supersedeActionProposal(scope: ActionProposalScope, id: string, command: {
|
|
439
|
+
replacementProposalId: string;
|
|
440
|
+
actorRef: string;
|
|
441
|
+
via: string;
|
|
442
|
+
}): Promise<ActionProposalMutationResult>;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
interface ActionProposalOutcome extends ActionProposalScope {
|
|
446
|
+
id: string;
|
|
447
|
+
proposalId: string;
|
|
448
|
+
outcomeVersion: 1;
|
|
449
|
+
originRunId: string;
|
|
450
|
+
originToolCallId: string;
|
|
451
|
+
toolName: string;
|
|
452
|
+
decision: ActionProposalDecision;
|
|
453
|
+
executionStatus?: 'succeeded' | 'failed';
|
|
454
|
+
result?: unknown;
|
|
455
|
+
error?: string;
|
|
456
|
+
ui: AgentUiComponent[];
|
|
457
|
+
text?: string;
|
|
458
|
+
createdAt: number;
|
|
459
|
+
}
|
|
460
|
+
interface ActionProposalOutcomeDelivery {
|
|
461
|
+
status: 'pending' | 'admitted' | 'discarded';
|
|
462
|
+
generation: number;
|
|
463
|
+
lease: ActionProposalLease | null;
|
|
464
|
+
messageId?: string;
|
|
465
|
+
}
|
|
466
|
+
interface ActionProposalOutcomeLease {
|
|
467
|
+
outcomeId: string;
|
|
468
|
+
token: string;
|
|
469
|
+
generation: number;
|
|
470
|
+
}
|
|
471
|
+
interface ActionProposalOutcomeStore {
|
|
472
|
+
getThreadActionProposalScope(threadId: string): Promise<ActionProposalScope | null>;
|
|
473
|
+
claimNextActionProposalOutcome(command: {
|
|
474
|
+
workerId: string;
|
|
475
|
+
leaseMs: number;
|
|
476
|
+
}): Promise<{
|
|
477
|
+
outcome: ActionProposalOutcome;
|
|
478
|
+
lease: ActionProposalOutcomeLease;
|
|
479
|
+
} | null>;
|
|
480
|
+
admitActionProposalOutcome(command: ActionProposalOutcomeLease): Promise<{
|
|
481
|
+
status: 'applied' | 'unchanged' | 'busy' | 'conflict' | 'not_found' | 'discarded';
|
|
482
|
+
messageId?: string;
|
|
483
|
+
}>;
|
|
484
|
+
}
|
|
485
|
+
|
|
72
486
|
/**
|
|
73
487
|
* What a store knows about a tool call, read back when its message carries no result for it — see
|
|
74
488
|
* {@link import('./spi/agent-store.js').AgentStore.toolCallOutcomes}.
|
|
@@ -115,13 +529,18 @@ interface CreateThreadInput {
|
|
|
115
529
|
* included).
|
|
116
530
|
*/
|
|
117
531
|
id?: string;
|
|
532
|
+
/** The persona the thread's turns run under when a send names none. See {@link ThreadSummary.persona}. */
|
|
533
|
+
persona?: string;
|
|
118
534
|
}
|
|
119
535
|
interface AppendMessageInput {
|
|
536
|
+
actionProposalOutcome?: ActionProposalOutcome;
|
|
120
537
|
threadId: string;
|
|
121
538
|
role: StoredMessage['role'];
|
|
122
539
|
content: string;
|
|
123
540
|
/** Which agent produced this message (assistant messages) — provenance. */
|
|
124
541
|
agentName?: string;
|
|
542
|
+
/** The persona the turn ran under. See {@link StoredMessage.persona}. */
|
|
543
|
+
persona?: string;
|
|
125
544
|
toolCalls?: ToolCallRequest[];
|
|
126
545
|
toolResults?: ToolResult[];
|
|
127
546
|
/** Files the user attached to this message (image/PDF). Persisted verbatim. */
|
|
@@ -144,6 +563,9 @@ interface AppendMessageInput {
|
|
|
144
563
|
ui?: AgentUiComponent[];
|
|
145
564
|
}
|
|
146
565
|
interface RecordToolCallInput {
|
|
566
|
+
proposalId?: string;
|
|
567
|
+
/** Resolved confirmation from the action preflight; overrides presentation templates. */
|
|
568
|
+
confirmation?: ToolConfirmation;
|
|
147
569
|
toolCallId: string;
|
|
148
570
|
messageId: string;
|
|
149
571
|
toolName: string;
|
|
@@ -191,6 +613,8 @@ interface UpdateThreadInput {
|
|
|
191
613
|
defaultAgent?: string | null;
|
|
192
614
|
/** `null` unpins the thread's model (turns run on the provider default). */
|
|
193
615
|
model?: string | null;
|
|
616
|
+
/** `null` clears the thread's persona (sends fall back to the agent's default persona). */
|
|
617
|
+
persona?: string | null;
|
|
194
618
|
}
|
|
195
619
|
interface RecordUsageInput {
|
|
196
620
|
threadId: string;
|
|
@@ -490,8 +914,11 @@ interface QueuedMessage {
|
|
|
490
914
|
content: string;
|
|
491
915
|
attachments?: MessageAttachment[];
|
|
492
916
|
agentName?: string;
|
|
917
|
+
/** The persona the send resolved (explicit, the thread's, or the agent's default) — what it starts under. */
|
|
918
|
+
persona?: string;
|
|
493
919
|
model?: string;
|
|
494
920
|
pageContext?: PageContext;
|
|
921
|
+
uiCapabilities?: UiCapabilities;
|
|
495
922
|
/**
|
|
496
923
|
* Queued by an interrupt (`POST chat { mode: 'interrupt' }`): the running turn was cancelled to
|
|
497
924
|
* make room for it, so the cancel starts it instead of pausing the queue.
|
|
@@ -506,6 +933,7 @@ interface QueuedMessageView {
|
|
|
506
933
|
content: string;
|
|
507
934
|
attachments?: MessageAttachment[];
|
|
508
935
|
agentName?: string;
|
|
936
|
+
persona?: string;
|
|
509
937
|
model?: string;
|
|
510
938
|
interrupt?: boolean;
|
|
511
939
|
createdAt: string;
|
|
@@ -526,8 +954,10 @@ interface EnqueueMessageInput {
|
|
|
526
954
|
content: string;
|
|
527
955
|
attachments?: MessageAttachment[];
|
|
528
956
|
agentName?: string;
|
|
957
|
+
persona?: string;
|
|
529
958
|
model?: string;
|
|
530
959
|
pageContext?: PageContext;
|
|
960
|
+
uiCapabilities?: UiCapabilities;
|
|
531
961
|
interrupt?: boolean;
|
|
532
962
|
/** `'tail'` (default) runs it after everything already waiting; `'head'` runs it next. */
|
|
533
963
|
at?: 'tail' | 'head';
|
|
@@ -693,96 +1123,145 @@ interface AgentHistoryWindow {
|
|
|
693
1123
|
}
|
|
694
1124
|
|
|
695
1125
|
/**
|
|
696
|
-
*
|
|
697
|
-
*
|
|
698
|
-
*
|
|
699
|
-
* stale the moment a tool was renamed. A tool name is an identifier, never copy.
|
|
700
|
-
*
|
|
701
|
-
* `running` / `done` (and `confirm.title`, `confirm.detail`, `result.text`) are templates:
|
|
702
|
-
* `{dotted.path}` placeholders are filled from the call's INPUT (or, for `result`, its OUTPUT), so one
|
|
703
|
-
* declaration covers every call the tool will ever receive and replays identically from history.
|
|
704
|
-
* A placeholder with nothing behind it collapses along with the space before it.
|
|
1126
|
+
* Per-invocation context handed to a tool handler. Host-supplied bits are optional. Identity lives
|
|
1127
|
+
* on {@link AiToolCtx.actor} — read `ctx.actor.id` / `ctx.actor.tenantRef` (single source of truth;
|
|
1128
|
+
* no denormalized copies).
|
|
705
1129
|
*/
|
|
706
|
-
interface
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
/**
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
/**
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
1130
|
+
interface AiToolCtx {
|
|
1131
|
+
uiCapabilities?: UiCapabilities;
|
|
1132
|
+
actor: Actor;
|
|
1133
|
+
threadId: string;
|
|
1134
|
+
runId: string;
|
|
1135
|
+
requestId: string;
|
|
1136
|
+
/**
|
|
1137
|
+
* The id of the tool call this invocation serves. Absent where a tool is invoked outside a turn
|
|
1138
|
+
* (the MCP server, a direct `registry.invoke`).
|
|
1139
|
+
*/
|
|
1140
|
+
toolCallId?: string;
|
|
1141
|
+
/**
|
|
1142
|
+
* `<runId>:<toolCallId>` — the same value for every execution of THIS call, and for no other.
|
|
1143
|
+
*
|
|
1144
|
+
* A tool's side effect and the checkpoint that records it are two writes. Under the durable
|
|
1145
|
+
* runner a worker that dies between them leaves a call the journal does not know ran, and the
|
|
1146
|
+
* runtime's recovery runs it again; an in-step transient retry (a deadlock, a lock-wait timeout)
|
|
1147
|
+
* re-invokes it too. The library cannot make your write atomic with its journal — so it hands you
|
|
1148
|
+
* the key that makes the second attempt recognisable: pass it to whatever you call as its
|
|
1149
|
+
* idempotency key (a payment provider's `Idempotency-Key`, a unique column on the row you insert,
|
|
1150
|
+
* a workflow's `id`), and a re-execution lands on the first one's result instead of doing it
|
|
1151
|
+
* twice. Stable across replays and across pods: the run id is the run's own, and the call id
|
|
1152
|
+
* comes out of the journaled model step.
|
|
1153
|
+
*
|
|
1154
|
+
* Absent where a tool is invoked outside a turn (the MCP server, a direct `registry.invoke`).
|
|
1155
|
+
*/
|
|
1156
|
+
idempotencyKey?: string;
|
|
1157
|
+
/** The name of the agent running this turn — provenance a tool can scope on (e.g. capability sets). */
|
|
1158
|
+
agentName?: string;
|
|
1159
|
+
/** The persona of {@link agentName} the turn runs under, when it runs under one. */
|
|
1160
|
+
persona?: string;
|
|
1161
|
+
pageContext?: PageContext;
|
|
1162
|
+
/** Optional host handle (e.g. an ORM EntityManager) the app threads through options. */
|
|
1163
|
+
host?: unknown;
|
|
1164
|
+
/**
|
|
1165
|
+
* Push a component into the assistant message: streamed live as a `ui` frame and persisted on
|
|
1166
|
+
* the message, so a reload shows it where the live stream did. Resolves to the component's id.
|
|
1167
|
+
*
|
|
1168
|
+
* `id` defaults to `<toolCallId>:ui:<n>` (the n-th push without an `id` in this invocation), so a retried or
|
|
1169
|
+
* re-executed call REPLACES what it pushed before instead of adding a second copy; pass your own
|
|
1170
|
+
* `id` to update one component across pushes (streaming rows into a table). `props` must be
|
|
1171
|
+
* JSON; it is snapshotted when pushed.
|
|
1172
|
+
*
|
|
1173
|
+
* Replay-safe under the durable runner: the pushed components ride the tool step's journaled
|
|
1174
|
+
* result, so a replay neither streams nor persists them again.
|
|
1175
|
+
*
|
|
1176
|
+
* Always present. On a surface with no conversation to push into (the MCP server, a direct
|
|
1177
|
+
* `registry.invoke` without one) it is a no-op that still resolves to an id, so a tool calls
|
|
1178
|
+
* `ctx.emitUi(…)` unconditionally.
|
|
1179
|
+
*/
|
|
1180
|
+
emitUi(component: string, props: Record<string, unknown>, options?: EmitUiOptions): Promise<{
|
|
1181
|
+
id: string;
|
|
1182
|
+
}>;
|
|
738
1183
|
}
|
|
739
|
-
/**
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
* `{ view, output }` and draws it.
|
|
743
|
-
*/
|
|
744
|
-
type ToolResultView =
|
|
745
|
-
/** A row of labelled readings — one result, several facets. */
|
|
746
|
-
{
|
|
747
|
-
kind: 'metrics';
|
|
748
|
-
fields: ToolResultField[];
|
|
1184
|
+
/** When the action state is being checked. */
|
|
1185
|
+
interface ToolPreflightOptions {
|
|
1186
|
+
phase: 'prepare' | 'execute';
|
|
749
1187
|
}
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
1188
|
+
type ToolPreflightResult<O = unknown> = {
|
|
1189
|
+
status: 'ready';
|
|
1190
|
+
confirmation?: ToolConfirmation;
|
|
1191
|
+
} | {
|
|
1192
|
+
status: 'denied';
|
|
1193
|
+
reason: string;
|
|
1194
|
+
} | {
|
|
1195
|
+
status: 'completed';
|
|
1196
|
+
output: O;
|
|
1197
|
+
};
|
|
1198
|
+
/** A tool implementation. `I` is the input parsed by its registered Standard Schema. */
|
|
1199
|
+
interface ToolHandler<I = unknown, O = unknown> {
|
|
1200
|
+
execute(input: I, ctx: AiToolCtx): Promise<O>;
|
|
1201
|
+
/** Read-only action check. Runs after authorization and validation, before approval and again
|
|
1202
|
+
* immediately before execution. Confirmation strings are resolved, never templates. */
|
|
1203
|
+
preflight?(input: I, ctx: AiToolCtx, options: ToolPreflightOptions): ToolPreflightResult<O> | Promise<ToolPreflightResult<O>>;
|
|
1204
|
+
/**
|
|
1205
|
+
* Whether this tool exists in this deployment at all — evaluated per turn, BEFORE the roles
|
|
1206
|
+
* policy, so a `false` here means the model is never shown the tool rather than being shown one
|
|
1207
|
+
* it will be refused. Omit → always enabled.
|
|
1208
|
+
*
|
|
1209
|
+
* This is the seam for a feature flag or a licensing tier: the handler is an ordinary provider,
|
|
1210
|
+
* so it can read injected config (`this.config.featureX`) that a decorator, evaluated at import
|
|
1211
|
+
* time, cannot. Answering "does this capability exist here?"; `roles`/`RolesPolicy` answers the
|
|
1212
|
+
* separate question "may THIS actor use it?", and both still run.
|
|
1213
|
+
*
|
|
1214
|
+
* Prefer this over conditionally registering the provider: registration happens while the
|
|
1215
|
+
* `@Module` metadata is built, which in most apps is before configuration is loaded.
|
|
1216
|
+
*/
|
|
1217
|
+
isEnabled?(): boolean | Promise<boolean>;
|
|
1218
|
+
/**
|
|
1219
|
+
* Whether THIS actor may use the tool, decided per turn. Omit → the role gate alone decides.
|
|
1220
|
+
*
|
|
1221
|
+
* The three existing gates all answer the question somewhere else: `roles` is static data,
|
|
1222
|
+
* `RolesPolicy` is one app-wide rule for every tool, and an agent's `tools` allow-list is fixed
|
|
1223
|
+
* when the agent is declared. This one lives on the tool and runs with DI, so it can ask the
|
|
1224
|
+
* questions only the tool knows to ask — is this user's org on the plan that includes it, does
|
|
1225
|
+
* this actor own the base being queried, is the per-user override in the DB set today.
|
|
1226
|
+
*
|
|
1227
|
+
* Runs AFTER {@link isEnabled} and the `RolesPolicy`, and all of them must pass. Applied both
|
|
1228
|
+
* when the turn's tool list is built (a denied actor is never shown it) and again on invoke.
|
|
1229
|
+
*/
|
|
1230
|
+
canUse?(actor: Actor): boolean | Promise<boolean>;
|
|
1231
|
+
/**
|
|
1232
|
+
* What the model is told about this tool for THIS turn — a description and/or input schema that
|
|
1233
|
+
* depend on who is asking (a per-tenant component catalog, a per-plan list of options). Called
|
|
1234
|
+
* when the turn's tool list is built, after every gate has passed; whatever it returns replaces
|
|
1235
|
+
* the registered spec's `description` / `inputSchema` in the definition the model sees. Omit, or
|
|
1236
|
+
* return `undefined`, to use the registered spec as is.
|
|
1237
|
+
*
|
|
1238
|
+
* It shapes what the model is SHOWN only: the registry still validates a call against the
|
|
1239
|
+
* registered `inputSchema`, so a tool whose accepted input varies per turn registers a permissive
|
|
1240
|
+
* schema and validates in `execute`.
|
|
1241
|
+
*/
|
|
1242
|
+
describe?(scope: ToolDescribeScope): ToolDescription | undefined | Promise<ToolDescription | undefined>;
|
|
756
1243
|
}
|
|
757
|
-
/**
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
1244
|
+
/** Who a turn's tool list is being built for — what {@link ToolHandler.describe} can vary on. */
|
|
1245
|
+
interface ToolDescribeScope {
|
|
1246
|
+
uiCapabilities?: UiCapabilities;
|
|
1247
|
+
actor: Actor;
|
|
1248
|
+
/** Absent where the list is built outside a conversation (the MCP server's `tools/list`). */
|
|
1249
|
+
threadId?: string;
|
|
1250
|
+
agentName?: string;
|
|
761
1251
|
}
|
|
762
|
-
/**
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
1252
|
+
/** A per-turn override of a tool's model-facing definition ({@link ToolHandler.describe}). */
|
|
1253
|
+
interface ToolDescription {
|
|
1254
|
+
/** False removes this tool from the current model-facing catalog. */
|
|
1255
|
+
available?: boolean;
|
|
1256
|
+
description?: string;
|
|
1257
|
+
inputSchema?: StandardSchemaV1;
|
|
766
1258
|
}
|
|
767
|
-
/**
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
* reaches through ANY agent, each once — for a surface that shows several agents' conversations.
|
|
774
|
-
*/
|
|
775
|
-
declare const ALL_AGENTS = "*";
|
|
776
|
-
/**
|
|
777
|
-
* One tool as `GET <base>/tools` reports it: the tools THIS actor may be offered by the chosen agent,
|
|
778
|
-
* with how each is spoken about. `presentation` is absent for a tool that declared none — a client
|
|
779
|
-
* then narrates it generically rather than falling back to its name.
|
|
780
|
-
*/
|
|
781
|
-
interface ToolCatalogEntry {
|
|
782
|
-
/** The wire name tool parts carry (`tool-<name>`) — the key a client looks a call up by. */
|
|
783
|
-
name: string;
|
|
784
|
-
kind: ToolKind;
|
|
785
|
-
presentation?: ToolPresentation;
|
|
1259
|
+
/** Metadata recorded with a pushed UI component. */
|
|
1260
|
+
interface EmitUiOptions {
|
|
1261
|
+
id?: string;
|
|
1262
|
+
version?: number;
|
|
1263
|
+
fallbackText?: string;
|
|
1264
|
+
componentVersions?: Record<string, number>;
|
|
786
1265
|
}
|
|
787
1266
|
|
|
788
1267
|
/**
|
|
@@ -901,6 +1380,8 @@ interface DetachedDelivery {
|
|
|
901
1380
|
* remedy is the read-back that lets them delete it.
|
|
902
1381
|
*/
|
|
903
1382
|
interface ToolSpec {
|
|
1383
|
+
/** Explicit domain identity for pending-only replacement; evaluated on approved normalized input. */
|
|
1384
|
+
replacementKey?: string | ((input: unknown, ctx: AiToolCtx) => string | undefined | Promise<string | undefined>);
|
|
904
1385
|
name: string;
|
|
905
1386
|
kind: ToolKind;
|
|
906
1387
|
description: string;
|
|
@@ -970,6 +1451,19 @@ interface ToolDefinition {
|
|
|
970
1451
|
}
|
|
971
1452
|
/** A tool call the model asked for during a turn. */
|
|
972
1453
|
interface ToolCallRequest {
|
|
1454
|
+
actionApproval?: ClaimedActionApproval;
|
|
1455
|
+
prepared?: {
|
|
1456
|
+
preparationInput: unknown;
|
|
1457
|
+
input: unknown;
|
|
1458
|
+
preflight: ToolPreflightResult;
|
|
1459
|
+
replacementKey?: string;
|
|
1460
|
+
};
|
|
1461
|
+
/** Trusted action preparation from the dispatched model worker, journaled with its turn.
|
|
1462
|
+
* Model-provider supplied values are overwritten by the worker. Absent on legacy turns. */
|
|
1463
|
+
preflight?: ToolPreflightResult | {
|
|
1464
|
+
status: 'failed';
|
|
1465
|
+
error: string;
|
|
1466
|
+
};
|
|
973
1467
|
id: string;
|
|
974
1468
|
name: string;
|
|
975
1469
|
input: unknown;
|
|
@@ -1139,6 +1633,71 @@ interface PromptContext {
|
|
|
1139
1633
|
/** The selected agent's name. */
|
|
1140
1634
|
agentName: string;
|
|
1141
1635
|
pageContext?: PageContext;
|
|
1636
|
+
uiCapabilities?: UiCapabilities;
|
|
1637
|
+
/**
|
|
1638
|
+
* The persona this turn runs under, when it runs under one — so an agent's own `@SystemPrompt`
|
|
1639
|
+
* (or a contributor) can vary by persona without the persona carrying a prompt of its own.
|
|
1640
|
+
*/
|
|
1641
|
+
persona?: PersonaRef;
|
|
1642
|
+
/**
|
|
1643
|
+
* The agent's own resolved base prompt. Set only while a persona's {@link Persona.systemPrompt} is
|
|
1644
|
+
* being resolved, so a persona builder can wrap the base rather than discard it.
|
|
1645
|
+
*/
|
|
1646
|
+
basePrompt?: string;
|
|
1647
|
+
}
|
|
1648
|
+
/**
|
|
1649
|
+
* A named variant of ONE agent: its own prompt and, optionally, a narrower tool allow-list. The
|
|
1650
|
+
* caller picks one per send (`POST <base>/chat { persona }`); everything else — the agent's model,
|
|
1651
|
+
* its access rules, its handoffs, its history — stays the agent's. A variant that needs any of those
|
|
1652
|
+
* to differ is a different `@Agent`, not a persona.
|
|
1653
|
+
*/
|
|
1654
|
+
interface Persona {
|
|
1655
|
+
/** Unique within its agent — what a send names and what a message records. */
|
|
1656
|
+
id: string;
|
|
1657
|
+
/** What a picker shows. */
|
|
1658
|
+
label: string;
|
|
1659
|
+
/** One line about what the persona is for, for a picker. */
|
|
1660
|
+
description?: string;
|
|
1661
|
+
/**
|
|
1662
|
+
* The persona's prompt. A flat string STANDS IN FOR the agent's base prompt; a
|
|
1663
|
+
* {@link PromptBuilder} is handed that base as `ctx.basePrompt`, so it can wrap it instead. The
|
|
1664
|
+
* cross-agent contributors still follow either way. Omit → the agent's base prompt, unchanged
|
|
1665
|
+
* (which can itself read `ctx.persona`).
|
|
1666
|
+
*/
|
|
1667
|
+
systemPrompt?: string | PromptBuilder;
|
|
1668
|
+
/**
|
|
1669
|
+
* Only these tool names are offered — and only these may be invoked — under this persona. Layered
|
|
1670
|
+
* AFTER the agent's own allow-list, `enabled`, the roles policy and `canUse`: it narrows, never
|
|
1671
|
+
* widens. Omit → whatever the agent offers.
|
|
1672
|
+
*/
|
|
1673
|
+
allowedTools?: string[];
|
|
1674
|
+
/**
|
|
1675
|
+
* Agent names this persona answers for: a send, a queued message or a thread that names one of
|
|
1676
|
+
* them runs as THIS agent under THIS persona. For an app that turns separate agents into personas
|
|
1677
|
+
* of one — the threads, messages and in-flight runs that recorded the old agent name keep
|
|
1678
|
+
* resolving, with no data migration.
|
|
1679
|
+
*/
|
|
1680
|
+
aliases?: string[];
|
|
1681
|
+
}
|
|
1682
|
+
/** What a prompt builder and a tool see of the turn's persona. */
|
|
1683
|
+
interface PersonaRef {
|
|
1684
|
+
id: string;
|
|
1685
|
+
label: string;
|
|
1686
|
+
}
|
|
1687
|
+
/**
|
|
1688
|
+
* A persona as a turn RESOLVED it, journaled in the `persona:resolve` checkpoint — so every replay
|
|
1689
|
+
* of the run uses this, and not whatever the persona's configuration says by the time it resumes.
|
|
1690
|
+
*/
|
|
1691
|
+
interface TurnPersona extends PersonaRef {
|
|
1692
|
+
allowedTools?: string[];
|
|
1693
|
+
/** The persona's prompt, resolved (with the base prompt it wraps). Absent → the base prompt. */
|
|
1694
|
+
prompt?: string;
|
|
1695
|
+
}
|
|
1696
|
+
/** One persona as `GET <base>/agents` lists it — what a persona picker renders. */
|
|
1697
|
+
interface PersonaCatalogEntry {
|
|
1698
|
+
id: string;
|
|
1699
|
+
label: string;
|
|
1700
|
+
description?: string;
|
|
1142
1701
|
}
|
|
1143
1702
|
/**
|
|
1144
1703
|
* An agent's base system prompt. Return a string (optionally async) built from the turn's context —
|
|
@@ -1162,10 +1721,18 @@ interface AgentRunInput {
|
|
|
1162
1721
|
/** Files attached to the latest user message (image/PDF). Persisted with it and sent to the model. */
|
|
1163
1722
|
attachments?: MessageAttachment[];
|
|
1164
1723
|
pageContext?: PageContext;
|
|
1724
|
+
uiCapabilities?: UiCapabilities;
|
|
1165
1725
|
/** YYYY-MM-DD stamped by the runner so quota/day stays deterministic under durable replay. */
|
|
1166
1726
|
day?: string;
|
|
1167
1727
|
/** Which named agent runs this turn. Omitted → the default/single agent. */
|
|
1168
1728
|
agentName?: string;
|
|
1729
|
+
/**
|
|
1730
|
+
* The persona of {@link agentName} this turn runs under (a {@link Persona.id}). Resolved by the
|
|
1731
|
+
* service from the send, the thread and the agent's default BEFORE the run starts, so it is part
|
|
1732
|
+
* of the run's own input; the loop resolves its definition once, in the `persona:resolve`
|
|
1733
|
+
* checkpoint. Omitted → no persona, and no checkpoint spent on one.
|
|
1734
|
+
*/
|
|
1735
|
+
persona?: string;
|
|
1169
1736
|
/**
|
|
1170
1737
|
* How many agent→agent delegations deep this run already is (0 for a top-level turn). The runner
|
|
1171
1738
|
* increments it for each child run; the loop refuses to delegate past its depth ceiling.
|
|
@@ -1273,6 +1840,10 @@ interface AgentDefinition {
|
|
|
1273
1840
|
* Whether this agent is offered the built-in `ask` tool. Undefined → the module-wide setting.
|
|
1274
1841
|
*/
|
|
1275
1842
|
ask?: boolean;
|
|
1843
|
+
/** Named variants of this agent — see {@link Persona}. Undefined → none. */
|
|
1844
|
+
personas?: Persona[];
|
|
1845
|
+
/** The persona a send runs under when neither it nor its thread names one. Undefined → none. */
|
|
1846
|
+
defaultPersona?: string;
|
|
1276
1847
|
}
|
|
1277
1848
|
/**
|
|
1278
1849
|
* The read-model the `GET agents` endpoint returns to a client — the safe public subset of an
|
|
@@ -1288,6 +1859,10 @@ interface AgentCatalogEntry {
|
|
|
1288
1859
|
* so before a chat starts. `GET <base>/models?agent=` reports the same lock as `locked`.
|
|
1289
1860
|
*/
|
|
1290
1861
|
lockedModel?: string;
|
|
1862
|
+
/** The agent's personas, for a persona picker. Omitted when it declares none. */
|
|
1863
|
+
personas?: PersonaCatalogEntry[];
|
|
1864
|
+
/** The persona a send runs under when it names none. Omitted when the agent has no default. */
|
|
1865
|
+
defaultPersona?: string;
|
|
1291
1866
|
}
|
|
1292
1867
|
interface ThreadSummary {
|
|
1293
1868
|
id: string;
|
|
@@ -1314,13 +1889,22 @@ interface ThreadSummary {
|
|
|
1314
1889
|
* it; the REST read-model normalizes that to `null`.
|
|
1315
1890
|
*/
|
|
1316
1891
|
model?: string | null;
|
|
1892
|
+
/**
|
|
1893
|
+
* The persona this thread's turns run under when a send names none — the last one a send on it
|
|
1894
|
+
* named, or `PATCH <base>/threads/:id { persona }`. `null` → the agent's default. Undefined for a
|
|
1895
|
+
* store that does not persist it; the REST read-model normalizes that to `null`.
|
|
1896
|
+
*/
|
|
1897
|
+
persona?: string | null;
|
|
1317
1898
|
}
|
|
1318
1899
|
interface StoredMessage {
|
|
1900
|
+
actionProposalOutcome?: ActionProposalOutcome;
|
|
1319
1901
|
id: string;
|
|
1320
1902
|
role: MessageRole;
|
|
1321
1903
|
content: string;
|
|
1322
1904
|
/** Which agent produced this message (assistant messages) — provenance for replay / UI / telescope. */
|
|
1323
1905
|
agentName?: string;
|
|
1906
|
+
/** The persona the turn that wrote this message ran under; absent when it ran under none. */
|
|
1907
|
+
persona?: string;
|
|
1324
1908
|
toolCalls?: ToolCallRequest[];
|
|
1325
1909
|
toolResults?: ToolResult[];
|
|
1326
1910
|
/** Files the user attached to this message (image/PDF). Persisted with the message, replayed as-is. */
|
|
@@ -1379,6 +1963,14 @@ interface MessageFeedback {
|
|
|
1379
1963
|
type ToolCallApprovalStatus = 'pending' | 'approved' | 'rejected' | 'expired';
|
|
1380
1964
|
/** The persisted approval metadata of one action tool call. See {@link StoredMessage.approvals}. */
|
|
1381
1965
|
interface ToolCallApproval {
|
|
1966
|
+
target?: {
|
|
1967
|
+
kind: 'proposal';
|
|
1968
|
+
proposalId: string;
|
|
1969
|
+
threadId?: string;
|
|
1970
|
+
};
|
|
1971
|
+
proposalId?: string;
|
|
1972
|
+
/** Resolved confirmation from the action preflight; overrides presentation templates. */
|
|
1973
|
+
confirmation?: ToolConfirmation;
|
|
1382
1974
|
toolCallId: string;
|
|
1383
1975
|
/** Who may decide: `'requester'` (the thread's own actor) or a role name. */
|
|
1384
1976
|
approver: string;
|
|
@@ -1403,7 +1995,7 @@ interface ThreadDetail extends ThreadSummary {
|
|
|
1403
1995
|
*/
|
|
1404
1996
|
queue?: ChatQueueState;
|
|
1405
1997
|
}
|
|
1406
|
-
type ToolCallStatus = 'auto_executed' | 'pending_approval' | 'executed' | 'rejected' | 'failed'
|
|
1998
|
+
type ToolCallStatus = 'proposed' | 'auto_executed' | 'pending_approval' | 'executed' | 'rejected' | 'failed'
|
|
1407
1999
|
/** An approval request lapsed before anyone decided; the tool never ran. */
|
|
1408
2000
|
| 'expired';
|
|
1409
2001
|
/**
|
|
@@ -1411,6 +2003,9 @@ type ToolCallStatus = 'auto_executed' | 'pending_approval' | 'executed' | 'rejec
|
|
|
1411
2003
|
* re-resolves the model/sink/registry from its own DI via AGENT_DEPS_FACTORY.forAgent(agentName).
|
|
1412
2004
|
*/
|
|
1413
2005
|
interface LlmStepEnvelope {
|
|
2006
|
+
actionApprovalMode?: 'blocking' | 'independent';
|
|
2007
|
+
/** Full invocation identity for action preparation at the worker. Optional for old envelopes. */
|
|
2008
|
+
preflightContext?: ToolStepCtx;
|
|
1414
2009
|
/** Undefined = default agent (same semantics as {@link AgentRunInput.agentName}). */
|
|
1415
2010
|
agentName?: string;
|
|
1416
2011
|
system: string;
|
|
@@ -1431,6 +2026,11 @@ interface LlmStepEnvelope {
|
|
|
1431
2026
|
bufferOutput?: boolean;
|
|
1432
2027
|
/** The turn's selected model ({@link AgentRunInput.model}), for the worker's provider call. */
|
|
1433
2028
|
model?: string;
|
|
2029
|
+
/**
|
|
2030
|
+
* The allow-list of the persona the turn resolved (`persona:resolve`), which the serving worker
|
|
2031
|
+
* intersects with the agent's own. Absent → no persona narrowing, as before personas existed.
|
|
2032
|
+
*/
|
|
2033
|
+
personaAllowedTools?: string[];
|
|
1434
2034
|
}
|
|
1435
2035
|
/**
|
|
1436
2036
|
* The serializable subset of `AiToolCtx` — everything except `host` (re-attached handler-side
|
|
@@ -1442,13 +2042,21 @@ interface ToolStepCtx {
|
|
|
1442
2042
|
runId: string;
|
|
1443
2043
|
requestId: string;
|
|
1444
2044
|
agentName?: string;
|
|
2045
|
+
/** The persona the turn runs under ({@link AiToolCtx.persona}). */
|
|
2046
|
+
persona?: string;
|
|
1445
2047
|
pageContext?: PageContext;
|
|
2048
|
+
uiCapabilities?: UiCapabilities;
|
|
1446
2049
|
}
|
|
1447
2050
|
/** Serializable input for a dispatched tool-execution step. */
|
|
1448
2051
|
interface ToolStepEnvelope {
|
|
1449
2052
|
toolName: string;
|
|
1450
2053
|
input: unknown;
|
|
1451
2054
|
ctx: ToolStepCtx;
|
|
2055
|
+
/**
|
|
2056
|
+
* The only tool names this call may invoke — the turn's persona allow-list (intersected with the
|
|
2057
|
+
* agent's). Checked by `ToolRegistry.invoke` on the worker. Absent → no such check.
|
|
2058
|
+
*/
|
|
2059
|
+
allowedTools?: string[];
|
|
1452
2060
|
/** Applied INSIDE the handler (`withToolTimeout`) — never as a durable step `timeoutMs`. */
|
|
1453
2061
|
timeoutMs?: number;
|
|
1454
2062
|
/**
|
|
@@ -1730,6 +2338,10 @@ interface AgentUiComponent {
|
|
|
1730
2338
|
props: Record<string, unknown>;
|
|
1731
2339
|
/** Schema version of `props`, so a client can keep rendering components persisted by an older server. */
|
|
1732
2340
|
version?: number;
|
|
2341
|
+
/** Validated readable fallback retained for clients without this renderer. */
|
|
2342
|
+
fallbackText?: string;
|
|
2343
|
+
/** Trusted schema versions for every component in a persisted tree. */
|
|
2344
|
+
componentVersions?: Record<string, number>;
|
|
1733
2345
|
/**
|
|
1734
2346
|
* The tool call that pushed the component (`ctx.emitUi`), when one did. Lets a client place it
|
|
1735
2347
|
* with that call — a reloaded message puts it right after the call's tool part, where the live
|
|
@@ -1742,6 +2354,12 @@ interface AgentUiComponent {
|
|
|
1742
2354
|
* settled through the tool-call approve/reject routes, by its `toolCallId`.
|
|
1743
2355
|
*/
|
|
1744
2356
|
interface AgentApprovalRequest {
|
|
2357
|
+
target?: {
|
|
2358
|
+
kind: 'proposal';
|
|
2359
|
+
proposalId: string;
|
|
2360
|
+
};
|
|
2361
|
+
/** Resolved confirmation from the action preflight; overrides presentation templates. */
|
|
2362
|
+
confirmation?: ToolConfirmation;
|
|
1745
2363
|
/** The tool call awaiting the decision — the `id` of a call already announced on this stream. */
|
|
1746
2364
|
id: string;
|
|
1747
2365
|
/**
|
|
@@ -1957,4 +2575,4 @@ type AgentStreamErrorCode = 'quota_exceeded' | 'output_rejected' | 'structured_o
|
|
|
1957
2575
|
/** A model call ended without producing anything. */
|
|
1958
2576
|
| 'model_no_output' | 'run_failed';
|
|
1959
2577
|
|
|
1960
|
-
export { type
|
|
2578
|
+
export { type ToolCallStatus as $, type AgentStreamEvent as A, type ToolTransientRetrySetting as B, type AgentIntake as C, type DetachedDelivery as D, type Decision as E, type ElicitationRequest as F, type ToolStepEnvelope as G, type HumanReply as H, type ClaimActionProposal as I, type ActionProposal as J, type ActionProposalStore as K, type LlmStepEnvelope as L, type ModelMessage as M, type ActionProposalStoreOptions as N, type CreateActionProposal as O, type PreparedUiEmission as P, type QuotaState as Q, type CreateActionProposalResult as R, type ActionProposalScope as S, type ToolSpec as T, type UiCapabilities as U, type ListActionProposals as V, type ActionProposalDecisionCommand as W, type ExtendActionProposalLease as X, type SettleActionProposal as Y, type ActionProposalOutcome as Z, type ActionProposalOutcomeLease as _, type Actor as a, type MessageFeedbackValue as a$, type ChatQueueStore as a0, type ActionProposalOutcomeStore as a1, type CreateThreadInput as a2, type ThreadSummary as a3, type ThreadDetail as a4, type ToolCallApprovalState as a5, type UpdateThreadInput as a6, type RecordRunStartInput as a7, type EnqueueMessageInput as a8, type QueuedMessage as a9, type AgentHistoryWindow as aA, type AgentStreamErrorCode as aB, type ApprovalDecisionRef as aC, type ApprovalRequirement as aD, type ApprovalThreadRef as aE, type ApprovalToolRef as aF, type AskToolInput as aG, type ChatQueueState as aH, type ClaimedActionApproval as aI, DEFAULT_INTAKE_PREAMBLE as aJ, DEFAULT_TOOL_TRANSIENT_RETRY_ATTEMPTS as aK, DEFAULT_TOOL_TRANSIENT_RETRY_BACKOFF_MS as aL, DefaultApprovalPolicy as aM, ELICITATION_INPUT_TYPES as aN, type ElicitationInput as aO, type ElicitationInputType as aP, type ElicitationOption as aQ, type ElicitationOutcome as aR, type ElicitationQuestion as aS, type ElicitationReply as aT, type ElicitationResult as aU, type EmitUiOptions as aV, type HistoryPolicyContext as aW, type HistorySelection as aX, type HistorySummary as aY, type InvokeWithTransientRetryOptions as aZ, MAX_ASK_QUESTIONS as a_, type QueuedMessagePatch as aa, type QueuePause as ab, type AppendMessageInput as ac, type StoredMessage as ad, type ToolResult as ae, type MessageFeedback as af, type RecordToolCallInput as ag, type ToolCallOutcome as ah, type UpdateToolCallInput as ai, type RecordUsageInput as aj, type ToolConfirmation as ak, type ActionProposalDecision as al, type ActionProposalSupersessionStore as am, ALL_AGENTS as an, ASK_TOOL_DESCRIPTION as ao, ASK_TOOL_NAME as ap, type ActionProposalDecisionAudit as aq, type ActionProposalExecution as ar, type ActionProposalExecutionContext as as, type ActionProposalLease as at, type ActionProposalOutcomeDelivery as au, type AgentApprovalRequest as av, type AgentApprovalSettlement as aw, type AgentAttachmentConfig as ax, type AgentCatalogEntry as ay, type AgentClientConfig as az, type ToolHandler as b, type MessageRole as b0, type PersonaRef as b1, type PromptContext as b2, type QueuePauseReason as b3, type QueuedMessageView as b4, type QuotaView as b5, REQUESTER_APPROVER as b6, RUN_ENDED_BEFORE_TOOL_CALL as b7, type RecordRunEndInput as b8, type ResolveActionProposalApprovalInput as b9, isChatQueueStore as bA, isTransientToolError as bB, isTypedQuestion as bC, mayDecideApproval as bD, normalizeElicitationReply as bE, questionOptions as bF, queuedMessageView as bG, readElicitationInput as bH, readElicitationQuestions as bI, releaseThreadRun as bJ, renderElicitationAnswers as bK, resolveActionProposalApproval as bL, resolveElicitation as bM, resolveToolTransientRetryNumbers as bN, settleDanglingToolCalls as bO, settleElicitation as bP, toolCallApprovalFromRow as bQ, validateElicitationAnswer as bR, validateElicitationValue as bS, type ThreadTurnPage as ba, type ThreadTurnQuery as bb, type ThreadTurnReader as bc, type ToolCallApproval as bd, type ToolCallApprovalColumns as be, type ToolCallApprovalStatus as bf, type ToolCatalogEntry as bg, type ToolDescription as bh, type ToolKind as bi, type ToolPreflightOptions as bj, type ToolPresentationTone as bk, type ToolResultField as bl, type ToolResultView as bm, type ToolStepCtx as bn, type ToolTransientRetryNumbers as bo, type ToolTransientRetryOptions as bp, type TurnPersona as bq, UNFINISHED_TOOL_CALL as br, type UsagePurpose as bs, askInputSchema as bt, askToolDefinition as bu, danglingToolCallIds as bv, decodeStreamEvent as bw, defaultCanDecide as bx, encodeStreamEvent as by, invokeWithTransientRetry as bz, type ToolPresentation as c, type ToolDefinition as d, type ToolCallRequest as e, type MessageUsage as f, type AgentUiComponent as g, type AiToolCtx as h, type AgentRunInput as i, type MessageAttachment as j, type ActionProposalMutationResult as k, type AgentDefinition as l, type Persona as m, negotiateCatalog as n, type PersonaCatalogEntry as o, prepareUiEmission as p, type HistoryPolicy as q, type PageContext as r, type AgentStore as s, type AgentDelegation as t, type ToolDescribeScope as u, validateUiCapabilities as v, type ToolPreflightResult as w, type ApprovalPolicy as x, type PromptBuilder as y, type PromptContributor as z };
|