@swarm-agent/sdk 0.1.51 → 0.1.53
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 +26 -10
- package/dist/activity.d.ts +33 -0
- package/dist/activity.js +83 -0
- package/dist/agents.d.ts +432 -17
- package/dist/agents.js +529 -37
- package/dist/auth.d.ts +21 -5
- package/dist/auth.js +33 -4
- package/dist/client.d.ts +11 -0
- package/dist/client.js +14 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/job-automations.d.ts +343 -0
- package/dist/job-automations.js +74 -0
- package/dist/limits.d.ts +16 -0
- package/dist/limits.js +12 -0
- package/dist/projects.d.ts +11 -1
- package/dist/projects.js +30 -0
- package/dist/sessions.js +9 -1
- package/dist/types.d.ts +158 -0
- package/dist/workers.js +2 -0
- package/package.json +3 -3
package/dist/agents.d.ts
CHANGED
|
@@ -1,14 +1,128 @@
|
|
|
1
|
+
import type { PendingPermissionRecord } from './permissions.js';
|
|
1
2
|
import type { SwarmTransport } from './transport.js';
|
|
3
|
+
/** What a wait returned for. */
|
|
4
|
+
export type SessionWaitReason = 'assistant_message' | 'tool_call' | 'run_ended' | 'session_ended' | 'confirmation';
|
|
5
|
+
/** One answer from `agents.wait`: why it returned and the session's state now. */
|
|
6
|
+
export interface SessionWait {
|
|
7
|
+
sessionId: string;
|
|
8
|
+
/** Pass back as `after` to wait for what comes next. */
|
|
9
|
+
cursor: number;
|
|
10
|
+
/** Empty when the wait ended without anything to act on (see `timedOut`). */
|
|
11
|
+
reasons: SessionWaitReason[];
|
|
12
|
+
timedOut: boolean;
|
|
13
|
+
/** More events follow the cursor: wait again at once. */
|
|
14
|
+
more: boolean;
|
|
15
|
+
/** The cursor was ahead of the session; `cursor` is where it is now. */
|
|
16
|
+
staleCursor: boolean;
|
|
17
|
+
/** The conversation was ended (`endSession`): it takes no more messages. */
|
|
18
|
+
ended: boolean;
|
|
19
|
+
run?: {
|
|
20
|
+
run_id: string;
|
|
21
|
+
status: string;
|
|
22
|
+
active: boolean;
|
|
23
|
+
};
|
|
24
|
+
/** Tool calls waiting for an answer, as `GET .../permissions?status=pending` returns them. */
|
|
25
|
+
pendingCalls: PendingPermissionRecord[];
|
|
26
|
+
/** Confirmed calls waiting for the person's approval (at most one); reason `confirmation` wakes a wait. */
|
|
27
|
+
pendingConfirmations: PendingConfirmation[];
|
|
28
|
+
/** The session's end user and labels, from the stored session (gateway conversations). */
|
|
29
|
+
endUser?: string;
|
|
30
|
+
labels?: Record<string, string>;
|
|
31
|
+
}
|
|
32
|
+
/** One of an agent's conversations, as `agents.listSessions` returns it. */
|
|
33
|
+
export interface AgentSession {
|
|
34
|
+
id: string;
|
|
35
|
+
title: string;
|
|
36
|
+
created_at: number;
|
|
37
|
+
updated_at: number;
|
|
38
|
+
message_count: number;
|
|
39
|
+
last_message_at: number;
|
|
40
|
+
state: 'active' | 'ended';
|
|
41
|
+
ended?: {
|
|
42
|
+
at: number;
|
|
43
|
+
by: string;
|
|
44
|
+
reason?: string;
|
|
45
|
+
};
|
|
46
|
+
takeover?: Takeover;
|
|
47
|
+
run_active: boolean;
|
|
48
|
+
/** Set on gateway conversations, from the stored session. */
|
|
49
|
+
end_user?: string;
|
|
50
|
+
labels?: Record<string, string>;
|
|
51
|
+
}
|
|
52
|
+
export interface ListAgentSessionsParams {
|
|
53
|
+
/** Owner only: the agent to list. A gateway token always lists its own agent. */
|
|
54
|
+
agent?: string;
|
|
55
|
+
state?: 'active' | 'ended' | 'all';
|
|
56
|
+
/** Unix milliseconds. */
|
|
57
|
+
updatedAfter?: number;
|
|
58
|
+
updatedBefore?: number;
|
|
59
|
+
/** `nextCursor` from the previous page. */
|
|
60
|
+
cursor?: string;
|
|
61
|
+
/** 1 to 200 (default 50). */
|
|
62
|
+
limit?: number;
|
|
63
|
+
}
|
|
64
|
+
export type AgentEventKind = 'session.created' | 'message.user' | 'message.assistant' | 'tool.called' | 'tool.answered' | 'tool.failed' | 'session.ended' | 'run.failed' | 'takeover.started' | 'takeover.ended' | 'confirmation.requested' | 'confirmation.decided';
|
|
65
|
+
/**
|
|
66
|
+
* One entry in an agent's event feed. Message text and tool arguments,
|
|
67
|
+
* results and reasons are cut to 2000 characters, with `data.truncated` set.
|
|
68
|
+
*/
|
|
69
|
+
export interface AgentEvent {
|
|
70
|
+
/** Feed position; pass the last `next_after` back as `after`. */
|
|
71
|
+
seq: number;
|
|
72
|
+
id: string;
|
|
73
|
+
at: number;
|
|
74
|
+
kind: AgentEventKind;
|
|
75
|
+
session_id: string;
|
|
76
|
+
/** The conversation's end user and labels (gateway conversations), from the stored session. */
|
|
77
|
+
end_user?: string;
|
|
78
|
+
labels?: Record<string, string>;
|
|
79
|
+
data?: Record<string, unknown>;
|
|
80
|
+
}
|
|
81
|
+
export interface AgentEventPage {
|
|
82
|
+
events: AgentEvent[];
|
|
83
|
+
next_after: number;
|
|
84
|
+
latest_seq: number;
|
|
85
|
+
oldest_seq: number;
|
|
86
|
+
/** Entries after your cursor were already dropped (or the cursor is ahead): resync from `next_after`. */
|
|
87
|
+
gap: boolean;
|
|
88
|
+
}
|
|
89
|
+
export interface AgentEventsParams {
|
|
90
|
+
/** Owner only: the agent to follow. A gateway or operator token always follows its own agent. */
|
|
91
|
+
agent?: string;
|
|
92
|
+
after?: number;
|
|
93
|
+
/** 1 to 500 (default 100). */
|
|
94
|
+
limit?: number;
|
|
95
|
+
/** Kind prefixes, e.g. `['message', 'tool.failed']`. */
|
|
96
|
+
kinds?: string[];
|
|
97
|
+
/** Wait up to this many seconds (max 30) for an entry when there is none. */
|
|
98
|
+
waitSeconds?: number;
|
|
99
|
+
signal?: AbortSignal;
|
|
100
|
+
}
|
|
101
|
+
/** Yielded by `watchEvents` when entries were missed (dropped by feed retention). */
|
|
102
|
+
export interface AgentEventGap {
|
|
103
|
+
kind: 'gap';
|
|
104
|
+
from: number;
|
|
105
|
+
to: number;
|
|
106
|
+
}
|
|
2
107
|
/** A typed tool the application answers. Swarm validates and waits; it never executes it. */
|
|
3
108
|
export interface ClientToolDefinition {
|
|
4
109
|
name: string;
|
|
5
110
|
description: string;
|
|
6
111
|
/** JSON Schema for the arguments; must be `type: "object"` with only local `$ref`s. */
|
|
7
112
|
input_schema: Record<string, unknown>;
|
|
8
|
-
/** `write` marks a tool with external effects
|
|
113
|
+
/** `write` marks a tool with external effects. Write tools are confirmed by default (see `confirm`). */
|
|
9
114
|
effect?: 'read' | 'write';
|
|
10
115
|
/** How long a call waits for an answer before the model gets "client tool timed out" (max 300000). */
|
|
11
116
|
timeout_ms?: number;
|
|
117
|
+
/**
|
|
118
|
+
* Each call waits for the person to approve it before your handler runs it.
|
|
119
|
+
* Default: true for write tools, false for read tools. The model must add a
|
|
120
|
+
* one-sentence `summary` argument for the approval card; your handler never
|
|
121
|
+
* receives it.
|
|
122
|
+
*/
|
|
123
|
+
confirm?: boolean;
|
|
124
|
+
/** How long a call waits for the person's decision before the model is told nobody answered (default 900000 = 15 min, max 1 day). */
|
|
125
|
+
confirm_timeout_ms?: number;
|
|
12
126
|
}
|
|
13
127
|
/**
|
|
14
128
|
* An agent whose only capabilities are the client tools listed. It has no
|
|
@@ -23,12 +137,16 @@ export interface SealedAgentDefinition {
|
|
|
23
137
|
provider?: string;
|
|
24
138
|
model?: string;
|
|
25
139
|
thinking?: string;
|
|
26
|
-
/**
|
|
140
|
+
/**
|
|
141
|
+
* Bounds one message's cost. Unset fields use the sealed defaults (4 model calls, 1024 output tokens, last 40 messages, 60 s).
|
|
142
|
+
* `retention_days` (1 to 3650; unset keeps them) deletes ended or idle conversations that many days after their last activity.
|
|
143
|
+
*/
|
|
27
144
|
limits?: {
|
|
28
145
|
max_steps?: number;
|
|
29
146
|
max_output_tokens?: number;
|
|
30
147
|
max_history_messages?: number;
|
|
31
148
|
run_timeout_ms?: number;
|
|
149
|
+
retention_days?: number;
|
|
32
150
|
};
|
|
33
151
|
}
|
|
34
152
|
/** The account's spend today and its daily cap, as the daemon enforces it. */
|
|
@@ -40,6 +158,7 @@ export interface SpendToday {
|
|
|
40
158
|
}
|
|
41
159
|
/** A pending client tool call your application must answer. */
|
|
42
160
|
export interface ClientToolCall {
|
|
161
|
+
kind: 'call';
|
|
43
162
|
/** Pass to `answer`/`fail`. */
|
|
44
163
|
id: string;
|
|
45
164
|
sessionId: string;
|
|
@@ -48,7 +167,97 @@ export interface ClientToolCall {
|
|
|
48
167
|
/** Already validated by Swarm against the tool's input_schema. */
|
|
49
168
|
arguments: Record<string, unknown>;
|
|
50
169
|
createdAt: number;
|
|
170
|
+
/**
|
|
171
|
+
* The session's end user, as your gateway set it at create time. It comes
|
|
172
|
+
* from the stored session, never from the model: decide whose data the call
|
|
173
|
+
* may see from this, not from `arguments`.
|
|
174
|
+
*/
|
|
175
|
+
endUser?: string;
|
|
176
|
+
labels?: Record<string, string>;
|
|
177
|
+
}
|
|
178
|
+
/** A gateway token's limits; omitted fields keep the daemon defaults (or, on update, their current value). */
|
|
179
|
+
export interface GatewayTokenLimits {
|
|
180
|
+
/** Messages (model runs) the token may start per minute (default 120). */
|
|
181
|
+
messagesPerMinute?: number;
|
|
182
|
+
/** New conversations per hour (default 300). */
|
|
183
|
+
sessionsPerHour?: number;
|
|
184
|
+
/** Model runs at once across the agent's conversations (default 4, 1-64). */
|
|
185
|
+
maxConcurrentRuns?: number;
|
|
186
|
+
/** Messages per minute for one end user's conversations (default 20). */
|
|
187
|
+
endUserMessagesPerMinute?: number;
|
|
188
|
+
/** New conversations per hour for one end user (default 30). */
|
|
189
|
+
endUserSessionsPerHour?: number;
|
|
190
|
+
/** Model tokens one end user may use per UTC day (default: no cap). */
|
|
191
|
+
endUserMaxTokensPerDay?: number;
|
|
192
|
+
}
|
|
193
|
+
/** One end user's model usage for a UTC day, from the provider receipts of their sessions. */
|
|
194
|
+
export interface EndUserUsage {
|
|
195
|
+
endUser: string;
|
|
196
|
+
/** False when nothing was recorded for them that day. */
|
|
197
|
+
recorded: boolean;
|
|
198
|
+
usage: {
|
|
199
|
+
total_tokens: number;
|
|
200
|
+
input_tokens: number;
|
|
201
|
+
output_tokens: number;
|
|
202
|
+
receipt_count: number;
|
|
203
|
+
} & Record<string, unknown>;
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* `code` on a 429 from a gateway token: `token_*` is the token's own limit,
|
|
207
|
+
* `end_user_*` one end user's. Retry after `Retry-After` seconds.
|
|
208
|
+
*/
|
|
209
|
+
export type GatewayLimitCode = 'token_messages_rate_limited' | 'token_sessions_rate_limited' | 'token_concurrent_runs_limited' | 'end_user_messages_rate_limited' | 'end_user_sessions_rate_limited' | 'end_user_daily_tokens_exceeded' | 'rate_limit_capacity_reached';
|
|
210
|
+
/**
|
|
211
|
+
* A call to a confirmed client tool, waiting for the person's approval. Show
|
|
212
|
+
* `summary` and `arguments` on a card, then call `confirm` or `reject`.
|
|
213
|
+
* Nothing has run yet; after approval the same call reaches your handler with
|
|
214
|
+
* exactly these `arguments`.
|
|
215
|
+
*/
|
|
216
|
+
export interface PendingConfirmation {
|
|
217
|
+
kind: 'confirmation';
|
|
218
|
+
/** Pass to `confirm`/`reject`/`decideConfirmation`. */
|
|
219
|
+
id: string;
|
|
220
|
+
sessionId: string;
|
|
221
|
+
runId: string;
|
|
222
|
+
tool: string;
|
|
223
|
+
/** The model's one-sentence description of what approving will do. */
|
|
224
|
+
summary: string;
|
|
225
|
+
/** What your handler will receive on approval (validated against the tool's schema). */
|
|
226
|
+
arguments: Record<string, unknown>;
|
|
227
|
+
/** `sha256:<hex>` of the arguments; an approval must send it back. */
|
|
228
|
+
argumentsHash: string;
|
|
229
|
+
createdAt: number;
|
|
230
|
+
/** After this (unix ms) the model is told nobody answered. */
|
|
231
|
+
expiresAt: number;
|
|
232
|
+
/** The session's end user and labels, from the stored session (as on `ClientToolCall`). */
|
|
233
|
+
endUser?: string;
|
|
234
|
+
labels?: Record<string, string>;
|
|
51
235
|
}
|
|
236
|
+
/** A confirmation as the daemon stores it, in any state. */
|
|
237
|
+
export interface ClientToolConfirmationRecord {
|
|
238
|
+
id: string;
|
|
239
|
+
kind: 'confirmation';
|
|
240
|
+
status: 'pending' | 'approved' | 'rejected' | 'expired';
|
|
241
|
+
tool: string;
|
|
242
|
+
summary: string;
|
|
243
|
+
arguments: Record<string, unknown>;
|
|
244
|
+
arguments_hash: string;
|
|
245
|
+
run_id: string;
|
|
246
|
+
call_id: string;
|
|
247
|
+
created_at: number;
|
|
248
|
+
expires_at: number;
|
|
249
|
+
decided_at?: number;
|
|
250
|
+
note?: string;
|
|
251
|
+
execution_call_id: string;
|
|
252
|
+
execution_permission_id?: string;
|
|
253
|
+
execution_deadline?: number;
|
|
254
|
+
delivered?: boolean;
|
|
255
|
+
delivered_at?: number;
|
|
256
|
+
outcome_message_id?: string;
|
|
257
|
+
continuation_run_id?: string;
|
|
258
|
+
}
|
|
259
|
+
/** Called once for each confirmation `serve` sees: show the approval card from here. */
|
|
260
|
+
export type ConfirmationHandler = (confirmation: PendingConfirmation) => Promise<void> | void;
|
|
52
261
|
/** Throw from a handler to send this message to the model; other errors send "tool failed". */
|
|
53
262
|
export declare class ClientToolError extends Error {
|
|
54
263
|
constructor(message: string);
|
|
@@ -58,57 +267,263 @@ export type ClientToolHandler = (args: Record<string, unknown>, call: ClientTool
|
|
|
58
267
|
export interface ConverseResult {
|
|
59
268
|
reply: string;
|
|
60
269
|
messages: Array<Record<string, any>>;
|
|
270
|
+
/**
|
|
271
|
+
* Set when the turn ended waiting for the person to approve a confirmed
|
|
272
|
+
* tool call: show it, then call `confirm` or `reject` (each returns the
|
|
273
|
+
* agent's next reply). `reply` holds whatever the agent said before asking.
|
|
274
|
+
*/
|
|
275
|
+
confirmation?: PendingConfirmation;
|
|
61
276
|
}
|
|
277
|
+
/** Options of `serve`. */
|
|
278
|
+
export interface ServeOptions {
|
|
279
|
+
signal?: AbortSignal;
|
|
280
|
+
/** Poll interval, only against a daemon that predates waiting. */
|
|
281
|
+
intervalMs?: number;
|
|
282
|
+
/** Fail calls (and hide confirmations) of sessions that belong to anyone else. */
|
|
283
|
+
endUser?: string;
|
|
284
|
+
onConfirm?: ConfirmationHandler;
|
|
285
|
+
}
|
|
286
|
+
/** Options of `converse`, `confirm` and `reject`. */
|
|
287
|
+
export interface TurnOptions {
|
|
288
|
+
timeoutMs?: number;
|
|
289
|
+
/** Poll interval, only against a daemon that predates waiting. */
|
|
290
|
+
pollIntervalMs?: number;
|
|
291
|
+
/** Refuse a session that belongs to anyone else before sending anything. */
|
|
292
|
+
endUser?: string;
|
|
293
|
+
onConfirm?: ConfirmationHandler;
|
|
294
|
+
}
|
|
295
|
+
/** Who holds a conversation, as stored in its metadata under `takeover`. */
|
|
296
|
+
export type Takeover = {
|
|
297
|
+
state: 'human';
|
|
298
|
+
by: string;
|
|
299
|
+
since: number;
|
|
300
|
+
} | {
|
|
301
|
+
state: 'agent';
|
|
302
|
+
ended_at: number;
|
|
303
|
+
};
|
|
62
304
|
/**
|
|
63
305
|
* Sealed agents and client tools (`/v2/agents`, `/v2/custom-tools`). Defining
|
|
64
306
|
* them needs the owner or an `admin` token: keep this in a trusted backend.
|
|
65
307
|
*/
|
|
66
308
|
export declare class SwarmAgentsNamespace {
|
|
67
309
|
private readonly transport;
|
|
310
|
+
private olderDaemonNoted;
|
|
68
311
|
constructor(transport: SwarmTransport);
|
|
312
|
+
/** Records, once, that this daemon predates waiting and the SDK polls instead. */
|
|
313
|
+
private noteOlderDaemon;
|
|
69
314
|
defineClientTool(definition: ClientToolDefinition): Promise<Record<string, unknown>>;
|
|
70
315
|
defineSealedAgent(definition: SealedAgentDefinition): Promise<Record<string, unknown>>;
|
|
71
316
|
/**
|
|
72
317
|
* Mints the token a gateway holds to serve one sealed agent. It can only
|
|
73
318
|
* create and use that agent's sessions and answer its client tool calls;
|
|
74
319
|
* it stops working if the agent is given any built-in tool. Owner only.
|
|
320
|
+
* Like every key it works while used and stops after 90 days unused;
|
|
321
|
+
* expiresInSeconds adds an optional fixed end date (at most 365 days).
|
|
75
322
|
*/
|
|
76
323
|
createGatewayToken(agentName: string, options?: {
|
|
77
324
|
name?: string;
|
|
78
325
|
expiresInSeconds?: number;
|
|
79
|
-
|
|
80
|
-
sessionsPerHour?: number;
|
|
81
|
-
}): Promise<{
|
|
326
|
+
} & GatewayTokenLimits): Promise<{
|
|
82
327
|
token: string;
|
|
83
328
|
record: Record<string, unknown>;
|
|
84
329
|
}>;
|
|
330
|
+
/**
|
|
331
|
+
* Changes a gateway token's limits in place (owner only); fields you omit
|
|
332
|
+
* keep their value, 0 restores the default. Applies from its next request.
|
|
333
|
+
*/
|
|
334
|
+
updateGatewayTokenLimits(tokenId: string, limits: GatewayTokenLimits): Promise<Record<string, unknown>>;
|
|
335
|
+
/**
|
|
336
|
+
* Creates a conversation with a sealed agent for one end user (gateway
|
|
337
|
+
* token). `endUser` is stored with the session once and cannot change; the
|
|
338
|
+
* model never sees it. Pass the same `clientRequestId` to retry safely.
|
|
339
|
+
*/
|
|
340
|
+
startConversation(agentName: string, options?: {
|
|
341
|
+
endUser?: string;
|
|
342
|
+
labels?: Record<string, string>;
|
|
343
|
+
title?: string;
|
|
344
|
+
clientRequestId?: string;
|
|
345
|
+
workspacePath?: string;
|
|
346
|
+
workspaceId?: string;
|
|
347
|
+
}): Promise<{
|
|
348
|
+
sessionId: string;
|
|
349
|
+
endUser?: string;
|
|
350
|
+
labels?: Record<string, string>;
|
|
351
|
+
}>;
|
|
352
|
+
/**
|
|
353
|
+
* One UTC day's model usage of the agent's conversations, by end user (a
|
|
354
|
+
* gateway token reads its own agent; the owner passes `agentName`).
|
|
355
|
+
*/
|
|
356
|
+
endUserUsage(options?: {
|
|
357
|
+
endUser?: string;
|
|
358
|
+
date?: string;
|
|
359
|
+
limit?: number;
|
|
360
|
+
agentName?: string;
|
|
361
|
+
}): Promise<{
|
|
362
|
+
date: string;
|
|
363
|
+
endUsers: EndUserUsage[];
|
|
364
|
+
truncated: boolean;
|
|
365
|
+
}>;
|
|
85
366
|
/** Today's spend against the daily cap. A gateway token may read it. */
|
|
367
|
+
/**
|
|
368
|
+
* Mints the human-takeover token for one sealed agent: it can read that
|
|
369
|
+
* agent's conversations, take one over (the agent stops replying), reply as a
|
|
370
|
+
* person and hand it back. It cannot post as the visitor, start runs or answer
|
|
371
|
+
* tool calls. Owner only. Like every key it works while used and stops after
|
|
372
|
+
* 90 days unused; expiresInSeconds adds an optional fixed end date.
|
|
373
|
+
*/
|
|
374
|
+
createOperatorToken(agentName: string, options?: {
|
|
375
|
+
name?: string;
|
|
376
|
+
expiresInSeconds?: number;
|
|
377
|
+
}): Promise<{
|
|
378
|
+
token: string;
|
|
379
|
+
record: Record<string, unknown>;
|
|
380
|
+
}>;
|
|
381
|
+
/** Who holds a conversation: `{ state: 'human', by, since }`, `{ state: 'agent', ended_at }`, or undefined. */
|
|
382
|
+
takeoverState(sessionId: string): Promise<Takeover | undefined>;
|
|
383
|
+
/** A person takes the conversation: the agent's run in flight stops and visitor messages start no runs. */
|
|
384
|
+
takeOver(sessionId: string, options?: {
|
|
385
|
+
clientRequestId?: string;
|
|
386
|
+
}): Promise<Takeover>;
|
|
387
|
+
/** Hands the conversation back to the agent; the next visitor message runs it again. */
|
|
388
|
+
handBack(sessionId: string, options?: {
|
|
389
|
+
clientRequestId?: string;
|
|
390
|
+
}): Promise<Takeover>;
|
|
391
|
+
/** Replies as a person during a takeover (an assistant message with source "operator"). */
|
|
392
|
+
replyAsOperator(sessionId: string, content: string, options?: {
|
|
393
|
+
clientRequestId?: string;
|
|
394
|
+
}): Promise<Record<string, unknown>>;
|
|
395
|
+
private setTakeover;
|
|
86
396
|
spendToday(): Promise<SpendToday>;
|
|
87
397
|
removeAgent(name: string): Promise<void>;
|
|
88
398
|
removeClientTool(name: string): Promise<void>;
|
|
89
|
-
/**
|
|
90
|
-
|
|
399
|
+
/**
|
|
400
|
+
* Waits on one conversation (`GET /v3/sessions/{id}/wait`). Without `after`
|
|
401
|
+
* it answers at once with the current state and cursor. With `after` it
|
|
402
|
+
* returns as soon as there is a new assistant message, a pending tool call,
|
|
403
|
+
* a confirmation waiting for the person, the end of a run or of the
|
|
404
|
+
* session, or after `waitSeconds` (default 25, max 30). A gateway token may
|
|
405
|
+
* wait only on its agent's sessions.
|
|
406
|
+
*/
|
|
407
|
+
wait(sessionId: string, options?: {
|
|
408
|
+
after?: number;
|
|
409
|
+
waitSeconds?: number;
|
|
410
|
+
signal?: AbortSignal;
|
|
411
|
+
}): Promise<SessionWait>;
|
|
412
|
+
/**
|
|
413
|
+
* What waits on your application in a session, limited to the tool names you
|
|
414
|
+
* answer: client tool calls to run (`kind: 'call'`) and confirmed calls
|
|
415
|
+
* waiting for the person's approval (`kind: 'confirmation'`). Both carry the
|
|
416
|
+
* session's `endUser` and `labels`.
|
|
417
|
+
*/
|
|
418
|
+
pendingCalls(sessionId: string, tools: Iterable<string>): Promise<Array<ClientToolCall | PendingConfirmation>>;
|
|
419
|
+
/** The calls and confirmations a wait reported, for the tools you answer. */
|
|
420
|
+
private waitItems;
|
|
421
|
+
/** pendingCalls for daemons that predate waiting (see noteOlderDaemon). */
|
|
422
|
+
private polledItems;
|
|
423
|
+
/**
|
|
424
|
+
* Lists the agent's conversations, most recently updated first
|
|
425
|
+
* (`GET /v3/sessions:agent`). A gateway or operator token lists its own
|
|
426
|
+
* agent; the owner passes `agent`. Page with `nextCursor`.
|
|
427
|
+
*/
|
|
428
|
+
listSessions(params?: ListAgentSessionsParams): Promise<{
|
|
429
|
+
sessions: AgentSession[];
|
|
430
|
+
nextCursor?: string;
|
|
431
|
+
}>;
|
|
432
|
+
/**
|
|
433
|
+
* Ends a conversation: it accepts no more messages, its run in flight and
|
|
434
|
+
* pending tool calls stop. Ending an ended conversation changes nothing.
|
|
435
|
+
*/
|
|
436
|
+
endSession(sessionId: string, options?: {
|
|
437
|
+
reason?: string;
|
|
438
|
+
clientRequestId?: string;
|
|
439
|
+
}): Promise<{
|
|
440
|
+
ended: {
|
|
441
|
+
at: number;
|
|
442
|
+
by: string;
|
|
443
|
+
reason?: string;
|
|
444
|
+
};
|
|
445
|
+
alreadyEnded: boolean;
|
|
446
|
+
stoppedRunId?: string;
|
|
447
|
+
}>;
|
|
448
|
+
/**
|
|
449
|
+
* Hard deletes a conversation and its messages. The daemon refuses (409)
|
|
450
|
+
* while a run or tool call is in flight: end the session first.
|
|
451
|
+
*/
|
|
452
|
+
deleteSession(sessionId: string): Promise<void>;
|
|
453
|
+
/** Reads the agent's event feed after a cursor (`GET /v3/sessions:agent-events`), oldest first. */
|
|
454
|
+
events(params?: AgentEventsParams): Promise<AgentEventPage>;
|
|
455
|
+
/**
|
|
456
|
+
* Follows the agent's event feed until `signal` aborts, waiting on the
|
|
457
|
+
* daemon between entries (no polling). Yields a gap record when entries
|
|
458
|
+
* after the cursor were already dropped by the feed's retention.
|
|
459
|
+
*/
|
|
460
|
+
watchEvents(params?: Omit<AgentEventsParams, 'waitSeconds' | 'limit'>): AsyncGenerator<AgentEvent | AgentEventGap>;
|
|
461
|
+
/** Confirmed tool calls in a session waiting for the person's approval (at most one). */
|
|
462
|
+
confirmations(sessionId: string): Promise<PendingConfirmation[]>;
|
|
463
|
+
/**
|
|
464
|
+
* Records the person's decision on a confirmation and returns its new state.
|
|
465
|
+
* Approving needs the hash of the arguments the person was shown; the call
|
|
466
|
+
* then waits for your handler like any other. `confirm` and `reject` do this
|
|
467
|
+
* and also wait for the agent's reply.
|
|
468
|
+
*/
|
|
469
|
+
decideConfirmation(sessionId: string, confirmationId: string, decision: {
|
|
470
|
+
decision: 'approve' | 'reject';
|
|
471
|
+
argumentsHash?: string;
|
|
472
|
+
note?: string;
|
|
473
|
+
}): Promise<ClientToolConfirmationRecord>;
|
|
474
|
+
/**
|
|
475
|
+
* The person approved: runs the confirmed call through `handlers` (with
|
|
476
|
+
* exactly the confirmation's arguments) and returns the agent's reply. With
|
|
477
|
+
* `endUser`, it refuses a session that belongs to anyone else before
|
|
478
|
+
* recording the approval.
|
|
479
|
+
*/
|
|
480
|
+
confirm(sessionId: string, confirmation: PendingConfirmation, handlers: Record<string, ClientToolHandler>, options?: TurnOptions): Promise<ConverseResult>;
|
|
481
|
+
/**
|
|
482
|
+
* The person declined: the model is told "the person declined: <note>".
|
|
483
|
+
* Returns the agent's reply. `endUser` works as on `confirm`.
|
|
484
|
+
*/
|
|
485
|
+
reject(sessionId: string, confirmation: PendingConfirmation, handlers: Record<string, ClientToolHandler>, options?: TurnOptions & {
|
|
486
|
+
note?: string;
|
|
487
|
+
}): Promise<ConverseResult>;
|
|
91
488
|
/** Returns `result` (any JSON value) to the model as the tool's output. */
|
|
92
489
|
answer(sessionId: string, callId: string, result: unknown): Promise<void>;
|
|
93
490
|
/** Returns `reason` to the model as the tool's error. */
|
|
94
491
|
fail(sessionId: string, callId: string, reason: string): Promise<void>;
|
|
95
492
|
/**
|
|
96
493
|
* Answers one session's client tool calls with `handlers` until `signal`
|
|
97
|
-
* aborts
|
|
98
|
-
*
|
|
494
|
+
* aborts or the conversation has ended, waiting on the daemon between steps
|
|
495
|
+
* (`intervalMs` applies only to daemons that predate waiting). Each call is
|
|
496
|
+
* answered at most once; a handler error fails the call with "tool failed"
|
|
497
|
+
* unless it is a ClientToolError. With `endUser`, a call whose session
|
|
498
|
+
* belongs to anyone else is failed unanswered, and such a confirmation is
|
|
499
|
+
* not passed to `onConfirm`. Confirmations are never answered here:
|
|
500
|
+
* `onConfirm` is called once for each (show the approval card), and
|
|
501
|
+
* `confirm` or `reject` records the person's decision.
|
|
99
502
|
*/
|
|
100
|
-
serve(sessionId: string, handlers: Record<string, ClientToolHandler>, options?:
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
503
|
+
serve(sessionId: string, handlers: Record<string, ClientToolHandler>, options?: ServeOptions): Promise<void>;
|
|
504
|
+
/** Answers each new call once and shows each new confirmation once. */
|
|
505
|
+
private handleItems;
|
|
506
|
+
/** serve for daemons that predate waiting (see noteOlderDaemon). */
|
|
507
|
+
private servePolling;
|
|
104
508
|
/**
|
|
105
509
|
* Sends one user message to a sealed agent's session, answers its client
|
|
106
510
|
* tool calls with `handlers` while it runs, and returns once the run has
|
|
107
511
|
* finished. This is the whole loop a gateway needs per visitor message.
|
|
512
|
+
* It waits on the daemon between steps; `pollIntervalMs` applies only to
|
|
513
|
+
* daemons that predate waiting. With `endUser`, it refuses a session that
|
|
514
|
+
* belongs to anyone else before sending, and answers only that end user's
|
|
515
|
+
* calls. When the agent asks the person to approve a confirmed tool call,
|
|
516
|
+
* the result carries `confirmation`: pass it to `confirm` or `reject`.
|
|
108
517
|
*/
|
|
109
|
-
converse(sessionId: string, message: string, handlers: Record<string, ClientToolHandler>, options?:
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
518
|
+
converse(sessionId: string, message: string, handlers: Record<string, ClientToolHandler>, options?: TurnOptions): Promise<ConverseResult>;
|
|
519
|
+
/**
|
|
520
|
+
* Starts a turn with `start`, answers client tool calls while it runs, and
|
|
521
|
+
* returns once the agent has replied or has asked for a confirmation. With
|
|
522
|
+
* `endUser`, it refuses a session that belongs to anyone else before
|
|
523
|
+
* `start` runs.
|
|
524
|
+
*/
|
|
525
|
+
private followTurn;
|
|
526
|
+
/** followTurn for daemons that predate waiting (see noteOlderDaemon). */
|
|
527
|
+
private followTurnPolling;
|
|
113
528
|
private resolve;
|
|
114
529
|
}
|