@sctg/cline-shared 3.84.0-beta.20260524130712
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 +47 -0
- package/dist/agent.d.ts +388 -0
- package/dist/agents/index.d.ts +1 -0
- package/dist/agents/types.d.ts +967 -0
- package/dist/automation/index.d.ts +3 -0
- package/dist/automation/index.js +65 -0
- package/dist/automation/schemas.d.ts +89 -0
- package/dist/automation/types.d.ts +151 -0
- package/dist/connectors/events.d.ts +93 -0
- package/dist/connectors/options.d.ts +174 -0
- package/dist/cron/cron-spec-types.d.ts +94 -0
- package/dist/cron/index.d.ts +1 -0
- package/dist/db/index.d.ts +2 -0
- package/dist/db/index.js +80 -0
- package/dist/db/sqlite-db.d.ts +24 -0
- package/dist/dispose.d.ts +13 -0
- package/dist/extensions/context.d.ts +76 -0
- package/dist/extensions/contribution-registry.d.ts +195 -0
- package/dist/extensions/plugin.d.ts +1 -0
- package/dist/hooks/contracts.d.ts +9 -0
- package/dist/hooks/events.d.ts +194 -0
- package/dist/hub.d.ts +470 -0
- package/dist/index.browser.d.ts +61 -0
- package/dist/index.browser.js +76 -0
- package/dist/index.d.ts +69 -0
- package/dist/index.js +163 -0
- package/dist/llms/ai-sdk-format.d.ts +55 -0
- package/dist/llms/gateway.d.ts +145 -0
- package/dist/llms/messages.d.ts +149 -0
- package/dist/llms/model-info.d.ts +120 -0
- package/dist/llms/reasoning-effort.d.ts +21 -0
- package/dist/llms/requests.d.ts +2 -0
- package/dist/llms/tokens.d.ts +7 -0
- package/dist/llms/tools.d.ts +86 -0
- package/dist/logging/logger.d.ts +37 -0
- package/dist/parse/error.d.ts +2 -0
- package/dist/parse/headers/utils.d.ts +1 -0
- package/dist/parse/json.d.ts +3 -0
- package/dist/parse/shell.d.ts +2 -0
- package/dist/parse/string.d.ts +4 -0
- package/dist/parse/time.d.ts +9 -0
- package/dist/parse/zod.d.ts +12 -0
- package/dist/prompt/cline.d.ts +24 -0
- package/dist/prompt/format.d.ts +11 -0
- package/dist/prompt/system.d.ts +2 -0
- package/dist/remote-config/artifact-store.d.ts +13 -0
- package/dist/remote-config/blob-storage.d.ts +47 -0
- package/dist/remote-config/bundle.d.ts +136 -0
- package/dist/remote-config/constants.d.ts +5 -0
- package/dist/remote-config/index.d.ts +9 -0
- package/dist/remote-config/index.js +76 -0
- package/dist/remote-config/materializer.d.ts +4 -0
- package/dist/remote-config/paths.d.ts +10 -0
- package/dist/remote-config/runtime.d.ts +20 -0
- package/dist/remote-config/schema.d.ts +408 -0
- package/dist/remote-config/telemetry.d.ts +9 -0
- package/dist/rpc/index.d.ts +5 -0
- package/dist/rpc/runtime.d.ts +322 -0
- package/dist/rpc/team-progress.d.ts +53 -0
- package/dist/runtime/build-env.d.ts +13 -0
- package/dist/runtime/cline-environment.d.ts +17 -0
- package/dist/runtime/hub-daemon-env.d.ts +2 -0
- package/dist/services/telemetry-config.d.ts +6 -0
- package/dist/services/telemetry.d.ts +133 -0
- package/dist/session/hook-context.d.ts +12 -0
- package/dist/session/index.d.ts +1 -0
- package/dist/session/records.d.ts +31 -0
- package/dist/session/runtime-config.d.ts +26 -0
- package/dist/session/runtime-env.d.ts +8 -0
- package/dist/session/workspace.d.ts +28 -0
- package/dist/storage/index.d.ts +2 -0
- package/dist/storage/index.js +1 -0
- package/dist/storage/path-resolution.d.ts +11 -0
- package/dist/storage/paths.d.ts +86 -0
- package/dist/team/index.d.ts +2 -0
- package/dist/team/schema.d.ts +411 -0
- package/dist/team/types.d.ts +196 -0
- package/dist/tools/create.d.ts +22 -0
- package/dist/types/auth.d.ts +20 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/vcr.d.ts +14 -0
- package/dist/vcr.d.ts +41 -0
- package/package.json +63 -0
|
@@ -0,0 +1,967 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agent Types and Zod Schemas
|
|
3
|
+
*
|
|
4
|
+
* Canonical type definitions for agent configuration, events, hooks,
|
|
5
|
+
* extensions, and results.
|
|
6
|
+
*
|
|
7
|
+
* ProviderConfig is left as `unknown` here so that shared stays
|
|
8
|
+
* dependency-free of @cline/llms. Consuming packages narrow it
|
|
9
|
+
* via re-exports. ModelInfo lives in shared (../llms/model-info)
|
|
10
|
+
* and is used directly.
|
|
11
|
+
*/
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
import type { AgentRuntimeHooks, AgentTool } from "../agent";
|
|
14
|
+
import type { ExtensionContext } from "../extensions/context";
|
|
15
|
+
import type { AgentExtensionApi, AgentExtensionHooks, AgentExtensionRegistry as AgentExtensionRegistryGeneric, ContributionRegistryExtension, PluginManifest, PluginSetupContext } from "../extensions/contribution-registry";
|
|
16
|
+
import type { HookControl } from "../hooks/contracts";
|
|
17
|
+
import type { Message, MessageWithMetadata } from "../llms/messages";
|
|
18
|
+
import type { ModelInfo } from "../llms/model-info";
|
|
19
|
+
import type { ToolApprovalRequest, ToolApprovalResult, ToolCallRecord, ToolPolicy } from "../llms/tools";
|
|
20
|
+
import type { BasicLogger } from "../logging/logger";
|
|
21
|
+
import type { ITelemetryService } from "../services/telemetry";
|
|
22
|
+
import type { WorkspaceInfo } from "../session/workspace";
|
|
23
|
+
/**
|
|
24
|
+
* Events emitted during agent execution
|
|
25
|
+
*/
|
|
26
|
+
export type AgentEvent = AgentContentStartEvent | AgentContentUpdateEvent | AgentContentEndEvent | AgentIterationStartEvent | AgentIterationEndEvent | AgentNoticeEvent | AgentUsageEvent | AgentDoneEvent | AgentErrorEvent;
|
|
27
|
+
export type AgentContentType = "text" | "reasoning" | "tool";
|
|
28
|
+
export interface AgentEventMetadata {
|
|
29
|
+
/** Current ID */
|
|
30
|
+
agentId?: string;
|
|
31
|
+
/** Task ID */
|
|
32
|
+
conversationId?: string;
|
|
33
|
+
/** ID of the agent that created this agent */
|
|
34
|
+
parentAgentId?: string | null;
|
|
35
|
+
}
|
|
36
|
+
export interface AgentContentStartEvent extends AgentEventMetadata {
|
|
37
|
+
type: "content_start";
|
|
38
|
+
contentType: AgentContentType;
|
|
39
|
+
/** The text chunk received from the model */
|
|
40
|
+
text?: string;
|
|
41
|
+
/** Accumulated text so far in this turn */
|
|
42
|
+
accumulated?: string;
|
|
43
|
+
/** The reasoning/thinking text from the model */
|
|
44
|
+
reasoning?: string;
|
|
45
|
+
/** Whether this is redacted reasoning */
|
|
46
|
+
redacted?: boolean;
|
|
47
|
+
/** Name of the tool being called */
|
|
48
|
+
toolName?: string;
|
|
49
|
+
/** Unique identifier for this tool call */
|
|
50
|
+
toolCallId?: string;
|
|
51
|
+
/** Input being passed to the tool */
|
|
52
|
+
input?: unknown;
|
|
53
|
+
}
|
|
54
|
+
export interface AgentContentUpdateEvent extends AgentEventMetadata {
|
|
55
|
+
type: "content_update";
|
|
56
|
+
contentType: "tool";
|
|
57
|
+
/** Name of the tool emitting progress */
|
|
58
|
+
toolName?: string;
|
|
59
|
+
/** Unique identifier for this tool call */
|
|
60
|
+
toolCallId?: string;
|
|
61
|
+
/** Partial result emitted by the tool */
|
|
62
|
+
update: unknown;
|
|
63
|
+
}
|
|
64
|
+
export interface AgentContentEndEvent extends AgentEventMetadata {
|
|
65
|
+
type: "content_end";
|
|
66
|
+
contentType: AgentContentType;
|
|
67
|
+
/** Final text generated for this turn */
|
|
68
|
+
text?: string;
|
|
69
|
+
/** Final reasoning/thinking text generated for this turn */
|
|
70
|
+
reasoning?: string;
|
|
71
|
+
/** Name of the tool that completed */
|
|
72
|
+
toolName?: string;
|
|
73
|
+
/** Unique identifier for this tool call */
|
|
74
|
+
toolCallId?: string;
|
|
75
|
+
/** Output from the tool */
|
|
76
|
+
output?: unknown;
|
|
77
|
+
/** Error message if the tool failed */
|
|
78
|
+
error?: string;
|
|
79
|
+
/** Time taken in milliseconds for tool content */
|
|
80
|
+
durationMs?: number;
|
|
81
|
+
}
|
|
82
|
+
export interface AgentIterationStartEvent extends AgentEventMetadata {
|
|
83
|
+
type: "iteration_start";
|
|
84
|
+
/** The iteration number (1-based) */
|
|
85
|
+
iteration: number;
|
|
86
|
+
}
|
|
87
|
+
export interface AgentIterationEndEvent extends AgentEventMetadata {
|
|
88
|
+
type: "iteration_end";
|
|
89
|
+
/** The iteration number that just completed */
|
|
90
|
+
iteration: number;
|
|
91
|
+
/** Whether this iteration had any tool calls */
|
|
92
|
+
hadToolCalls: boolean;
|
|
93
|
+
/** Number of tool calls in this iteration */
|
|
94
|
+
toolCallCount: number;
|
|
95
|
+
}
|
|
96
|
+
export interface AgentUsageEvent extends AgentEventMetadata {
|
|
97
|
+
type: "usage";
|
|
98
|
+
/** Number of input tokens for this turn */
|
|
99
|
+
inputTokens: number;
|
|
100
|
+
/** Number of output tokens for this turn */
|
|
101
|
+
outputTokens: number;
|
|
102
|
+
/** Tokens read from cache */
|
|
103
|
+
cacheReadTokens?: number;
|
|
104
|
+
/** Tokens written to cache */
|
|
105
|
+
cacheWriteTokens?: number;
|
|
106
|
+
/** Cost for this turn */
|
|
107
|
+
cost?: number;
|
|
108
|
+
/** Accumulated totals */
|
|
109
|
+
totalInputTokens: number;
|
|
110
|
+
totalCacheReadTokens?: number;
|
|
111
|
+
totalCacheWriteTokens?: number;
|
|
112
|
+
totalOutputTokens: number;
|
|
113
|
+
totalCost?: number;
|
|
114
|
+
}
|
|
115
|
+
export interface AgentNoticeEvent extends AgentEventMetadata {
|
|
116
|
+
type: "notice";
|
|
117
|
+
noticeType: "recovery" | "stop" | "status";
|
|
118
|
+
message: string;
|
|
119
|
+
displayRole?: "system" | "status";
|
|
120
|
+
reason?: "api_error" | "invalid_tool_call" | "completion_without_submit" | "tool_execution_failed" | "mistake_limit" | "auto_compaction";
|
|
121
|
+
metadata?: Record<string, unknown>;
|
|
122
|
+
}
|
|
123
|
+
export interface AgentDoneEvent extends AgentEventMetadata {
|
|
124
|
+
type: "done";
|
|
125
|
+
/** The reason the agent stopped */
|
|
126
|
+
reason: AgentFinishReason;
|
|
127
|
+
/** Final text output */
|
|
128
|
+
text: string;
|
|
129
|
+
/** Total number of iterations */
|
|
130
|
+
iterations: number;
|
|
131
|
+
/** Aggregated usage information */
|
|
132
|
+
usage?: LegacyAgentUsage;
|
|
133
|
+
}
|
|
134
|
+
export interface AgentErrorEvent extends AgentEventMetadata {
|
|
135
|
+
type: "error";
|
|
136
|
+
/** The error that occurred */
|
|
137
|
+
error: Error;
|
|
138
|
+
/** Whether the error is recoverable */
|
|
139
|
+
recoverable: boolean;
|
|
140
|
+
/** Current iteration when error occurred */
|
|
141
|
+
iteration: number;
|
|
142
|
+
}
|
|
143
|
+
export interface ConsecutiveMistakeLimitContext {
|
|
144
|
+
iteration: number;
|
|
145
|
+
consecutiveMistakes: number;
|
|
146
|
+
maxConsecutiveMistakes: number;
|
|
147
|
+
reason: "api_error" | "invalid_tool_call" | "tool_execution_failed";
|
|
148
|
+
details?: string;
|
|
149
|
+
}
|
|
150
|
+
export type ConsecutiveMistakeLimitDecision = {
|
|
151
|
+
action: "continue";
|
|
152
|
+
/**
|
|
153
|
+
* Optional guidance appended as a user message before continuing.
|
|
154
|
+
*/
|
|
155
|
+
guidance?: string;
|
|
156
|
+
} | {
|
|
157
|
+
action: "stop";
|
|
158
|
+
/**
|
|
159
|
+
* Optional reason surfaced when stopping due to the limit.
|
|
160
|
+
*/
|
|
161
|
+
reason?: string;
|
|
162
|
+
};
|
|
163
|
+
export interface LoopDetectionConfig {
|
|
164
|
+
softThreshold: number;
|
|
165
|
+
hardThreshold: number;
|
|
166
|
+
}
|
|
167
|
+
export interface AgentExecutionConfig {
|
|
168
|
+
/**
|
|
169
|
+
* Maximum consecutive internal mistakes before escalation.
|
|
170
|
+
* Mistakes include API turn failures, invalid/missing tool-call arguments,
|
|
171
|
+
* and iterations where every executed tool call fails.
|
|
172
|
+
* @default 6
|
|
173
|
+
*/
|
|
174
|
+
maxConsecutiveMistakes?: number;
|
|
175
|
+
/**
|
|
176
|
+
* After this many consecutive iterations with tool calls,
|
|
177
|
+
* inject a reminder text block asking the agent to answer if it has enough info.
|
|
178
|
+
* Set to `0` or omit to disable.
|
|
179
|
+
* @default 0
|
|
180
|
+
*/
|
|
181
|
+
reminderAfterIterations?: number;
|
|
182
|
+
/**
|
|
183
|
+
* Custom reminder text to inject after `reminderAfterIterations`.
|
|
184
|
+
* @default "REMINDER: If you have gathered enough information to answer the user's question, please provide your final answer now without using any more tools."
|
|
185
|
+
*/
|
|
186
|
+
reminderText?: string;
|
|
187
|
+
/**
|
|
188
|
+
* Repeated tool call loop detection. When enabled, the agent detects
|
|
189
|
+
* consecutive identical tool calls and intervenes:
|
|
190
|
+
* - At `softThreshold`: injects a recovery notice urging a different approach.
|
|
191
|
+
* - At `hardThreshold`: triggers the consecutive-mistake-limit decision path.
|
|
192
|
+
*
|
|
193
|
+
* Set to `false` to explicitly disable. Omit or leave `undefined` for no detection.
|
|
194
|
+
* The CLI enables this by default with `{ softThreshold: 3, hardThreshold: 5 }`.
|
|
195
|
+
*/
|
|
196
|
+
loopDetection?: false | Partial<LoopDetectionConfig>;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Hook error handling behavior.
|
|
200
|
+
* - "ignore": swallow hook errors and continue agent execution
|
|
201
|
+
* - "throw": fail agent execution when a hook throws
|
|
202
|
+
*/
|
|
203
|
+
export type HookErrorMode = "ignore" | "throw";
|
|
204
|
+
/**
|
|
205
|
+
* Common controls supported by lifecycle hooks.
|
|
206
|
+
*/
|
|
207
|
+
export type AgentHookControl = Omit<HookControl, "appendMessages"> & {
|
|
208
|
+
/**
|
|
209
|
+
* Optional messages appended to history.
|
|
210
|
+
* Primarily used by before-agent-start hook stages.
|
|
211
|
+
*/
|
|
212
|
+
appendMessages?: Message[];
|
|
213
|
+
/**
|
|
214
|
+
* Optional replacement message history.
|
|
215
|
+
* Primarily used by before-agent-start hooks and host-owned context pipelines.
|
|
216
|
+
*/
|
|
217
|
+
replaceMessages?: Message[];
|
|
218
|
+
};
|
|
219
|
+
export interface AgentHookRunStartContext {
|
|
220
|
+
/**
|
|
221
|
+
* ID of the agent
|
|
222
|
+
*/
|
|
223
|
+
agentId: string;
|
|
224
|
+
/**
|
|
225
|
+
* Session ID
|
|
226
|
+
*/
|
|
227
|
+
conversationId: string;
|
|
228
|
+
/**
|
|
229
|
+
* ID of the agent that spawned the agent that is executing this run
|
|
230
|
+
*/
|
|
231
|
+
parentAgentId: string | null;
|
|
232
|
+
/**
|
|
233
|
+
* The prompt submitted by user
|
|
234
|
+
*/
|
|
235
|
+
userMessage: string;
|
|
236
|
+
}
|
|
237
|
+
export interface AgentHookScheduleContext {
|
|
238
|
+
scheduleId: string;
|
|
239
|
+
executionId?: string;
|
|
240
|
+
trigger: "scheduled" | "manual";
|
|
241
|
+
triggeredAt?: string;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Workspace location fields shared by session-scoped and run-scoped contexts.
|
|
245
|
+
*
|
|
246
|
+
* These fields are always sourced from the host session config — never from
|
|
247
|
+
* `process.cwd()`. Plugins and hooks must use these values when they need to
|
|
248
|
+
* resolve paths relative to the session's working directory or project root,
|
|
249
|
+
* because the `--cwd` CLI flag sets the session cwd without calling
|
|
250
|
+
* `process.chdir()`, so `process.cwd()` may return the wrong path.
|
|
251
|
+
*/
|
|
252
|
+
export interface SessionWorkspaceEnv {
|
|
253
|
+
/**
|
|
254
|
+
* The session's active working directory as configured by the host (e.g.
|
|
255
|
+
* via `--cwd`). Always accurate — never use `process.cwd()` in plugins or
|
|
256
|
+
* hooks; use this field instead.
|
|
257
|
+
*/
|
|
258
|
+
cwd?: string;
|
|
259
|
+
/**
|
|
260
|
+
* The workspace / project root when it differs from `cwd`. Global plugins
|
|
261
|
+
* installed outside the project should use this rather than
|
|
262
|
+
* `import.meta.url` tricks or `process.cwd()`.
|
|
263
|
+
*/
|
|
264
|
+
workspaceRoot?: string;
|
|
265
|
+
/**
|
|
266
|
+
* Structured workspace and git metadata for the session.
|
|
267
|
+
*
|
|
268
|
+
* Contains the same information as the `{{CLINE_METADATA}}` block in the
|
|
269
|
+
* system prompt but in structured form: `rootPath`, `hint`,
|
|
270
|
+
* `associatedRemoteUrls`, `latestGitCommitHash`, `latestGitBranchName`.
|
|
271
|
+
*
|
|
272
|
+
* Plugins and hooks can use this for branch-aware logic, commit
|
|
273
|
+
* attribution, or tooling integrations without running their own `git`
|
|
274
|
+
* calls. Populated once per session at session-start time.
|
|
275
|
+
*/
|
|
276
|
+
workspaceInfo?: WorkspaceInfo;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Fired exactly once for the lifetime of an agent conversation, before the
|
|
280
|
+
* first run starts. This is the right place for session-scoped setup.
|
|
281
|
+
*/
|
|
282
|
+
export interface AgentHookSessionStartContext extends SessionWorkspaceEnv {
|
|
283
|
+
agentId: string;
|
|
284
|
+
conversationId: string;
|
|
285
|
+
parentAgentId: string | null;
|
|
286
|
+
schedule?: AgentHookScheduleContext;
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Fired once per `run()` / `continue()` invocation after user input has been
|
|
290
|
+
* accepted and before the loop enters its first iteration.
|
|
291
|
+
*/
|
|
292
|
+
export interface AgentHookRunEndContext {
|
|
293
|
+
agentId: string;
|
|
294
|
+
conversationId: string;
|
|
295
|
+
parentAgentId: string | null;
|
|
296
|
+
result: AgentResult;
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Fired at the top of every loop iteration, before any turn-level prompt or
|
|
300
|
+
* model preparation occurs.
|
|
301
|
+
*/
|
|
302
|
+
export interface AgentHookIterationStartContext {
|
|
303
|
+
agentId: string;
|
|
304
|
+
conversationId: string;
|
|
305
|
+
parentAgentId: string | null;
|
|
306
|
+
iteration: number;
|
|
307
|
+
}
|
|
308
|
+
export interface AgentHookIterationEndContext {
|
|
309
|
+
agentId: string;
|
|
310
|
+
conversationId: string;
|
|
311
|
+
parentAgentId: string | null;
|
|
312
|
+
iteration: number;
|
|
313
|
+
hadToolCalls: boolean;
|
|
314
|
+
toolCallCount: number;
|
|
315
|
+
}
|
|
316
|
+
export interface AgentHookTurnStartContext {
|
|
317
|
+
agentId: string;
|
|
318
|
+
conversationId: string;
|
|
319
|
+
parentAgentId: string | null;
|
|
320
|
+
iteration: number;
|
|
321
|
+
messages: Message[];
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Fired immediately before the model call for an iteration.
|
|
325
|
+
*
|
|
326
|
+
* Compared with `onIterationStart`, this hook runs later: after turn-start
|
|
327
|
+
* processing and with the exact message list that will be sent to the model.
|
|
328
|
+
* It can still influence the upcoming turn by replacing the system prompt,
|
|
329
|
+
* appending messages, or cancelling the run.
|
|
330
|
+
*/
|
|
331
|
+
export interface AgentHookBeforeAgentStartContext {
|
|
332
|
+
agentId: string;
|
|
333
|
+
conversationId: string;
|
|
334
|
+
parentAgentId: string | null;
|
|
335
|
+
iteration: number;
|
|
336
|
+
systemPrompt: string;
|
|
337
|
+
messages: Message[];
|
|
338
|
+
}
|
|
339
|
+
export interface AgentHookTurnEndContext {
|
|
340
|
+
agentId: string;
|
|
341
|
+
conversationId: string;
|
|
342
|
+
parentAgentId: string | null;
|
|
343
|
+
iteration: number;
|
|
344
|
+
turn: ProcessedTurn;
|
|
345
|
+
}
|
|
346
|
+
export interface AgentHookToolCallStartContext {
|
|
347
|
+
agentId: string;
|
|
348
|
+
conversationId: string;
|
|
349
|
+
parentAgentId: string | null;
|
|
350
|
+
iteration: number;
|
|
351
|
+
call: PendingToolCall;
|
|
352
|
+
}
|
|
353
|
+
export interface AgentHookToolCallEndContext {
|
|
354
|
+
agentId: string;
|
|
355
|
+
conversationId: string;
|
|
356
|
+
parentAgentId: string | null;
|
|
357
|
+
iteration: number;
|
|
358
|
+
record: ToolCallRecord;
|
|
359
|
+
}
|
|
360
|
+
export interface AgentHookErrorContext {
|
|
361
|
+
agentId: string;
|
|
362
|
+
conversationId: string;
|
|
363
|
+
parentAgentId: string | null;
|
|
364
|
+
iteration: number;
|
|
365
|
+
error: Error;
|
|
366
|
+
}
|
|
367
|
+
export interface AgentHookStopErrorContext {
|
|
368
|
+
agentId: string;
|
|
369
|
+
conversationId: string;
|
|
370
|
+
parentAgentId: string | null;
|
|
371
|
+
iteration: number;
|
|
372
|
+
error: Error;
|
|
373
|
+
}
|
|
374
|
+
export interface AgentHookSessionShutdownContext {
|
|
375
|
+
agentId: string;
|
|
376
|
+
conversationId: string;
|
|
377
|
+
/** Stable core session id for the root session, when provided by the host. */
|
|
378
|
+
sessionId?: string;
|
|
379
|
+
parentAgentId: string | null;
|
|
380
|
+
/**
|
|
381
|
+
* Optional reason for shutdown (e.g. "ctrl_d", "process_exit")
|
|
382
|
+
*/
|
|
383
|
+
reason?: string;
|
|
384
|
+
}
|
|
385
|
+
export interface AgentExtensionRuntimeEventContext {
|
|
386
|
+
agentId: string;
|
|
387
|
+
conversationId: string;
|
|
388
|
+
parentAgentId: string | null;
|
|
389
|
+
event: AgentEvent;
|
|
390
|
+
}
|
|
391
|
+
export interface AgentExtensionSessionStartContext extends SessionWorkspaceEnv {
|
|
392
|
+
agentId: string;
|
|
393
|
+
conversationId: string;
|
|
394
|
+
parentAgentId: string | null;
|
|
395
|
+
schedule?: AgentHookScheduleContext;
|
|
396
|
+
}
|
|
397
|
+
export interface AgentExtensionSessionShutdownContext {
|
|
398
|
+
agentId: string;
|
|
399
|
+
conversationId: string;
|
|
400
|
+
/** Stable core session id for the root session, when provided by the host. */
|
|
401
|
+
sessionId?: string;
|
|
402
|
+
parentAgentId: string | null;
|
|
403
|
+
reason?: string;
|
|
404
|
+
}
|
|
405
|
+
export interface AgentExtensionContext extends PluginSetupContext {
|
|
406
|
+
}
|
|
407
|
+
export interface AgentExtension extends ContributionRegistryExtension<AgentTool, Message[]> {
|
|
408
|
+
name: string;
|
|
409
|
+
manifest: PluginManifest;
|
|
410
|
+
hooks?: AgentExtensionHooks;
|
|
411
|
+
setup?: (api: AgentExtensionApi<AgentTool, Message[]>, ctx: AgentExtensionContext) => void | Promise<void>;
|
|
412
|
+
}
|
|
413
|
+
export type AgentLoopExtensionRegistry = AgentExtensionRegistryGeneric<AgentTool, Message>;
|
|
414
|
+
/**
|
|
415
|
+
* Lifecycle hooks for observing or influencing agent execution.
|
|
416
|
+
*/
|
|
417
|
+
export type AgentHooks = Partial<AgentRuntimeHooks>;
|
|
418
|
+
/**
|
|
419
|
+
* Reasons why the agent stopped executing
|
|
420
|
+
*/
|
|
421
|
+
export type AgentFinishReason = "completed" | "max_iterations" | "aborted" | "mistake_limit" | "error";
|
|
422
|
+
export declare const AgentFinishReasonSchema: z.ZodEnum<{
|
|
423
|
+
error: "error";
|
|
424
|
+
completed: "completed";
|
|
425
|
+
aborted: "aborted";
|
|
426
|
+
mistake_limit: "mistake_limit";
|
|
427
|
+
max_iterations: "max_iterations";
|
|
428
|
+
}>;
|
|
429
|
+
/**
|
|
430
|
+
* Aggregated token usage and cost information (legacy, host-facing shape).
|
|
431
|
+
*
|
|
432
|
+
* Renamed from `AgentUsage` to make room for the runtime's stricter
|
|
433
|
+
* `AgentUsage` (see `../agent.ts`). Retained because
|
|
434
|
+
* the host-facing `AgentResult`/`AgentUsageEvent` surface and the
|
|
435
|
+
* `AgentUsageSchema` Zod schema use this more-permissive shape (all
|
|
436
|
+
* cache/cost fields optional). The facade adapter converts between the
|
|
437
|
+
* two shapes at runtime.
|
|
438
|
+
*/
|
|
439
|
+
export interface LegacyAgentUsage {
|
|
440
|
+
/** Total input tokens across all iterations */
|
|
441
|
+
inputTokens: number;
|
|
442
|
+
/** Total output tokens across all iterations */
|
|
443
|
+
outputTokens: number;
|
|
444
|
+
/** Total tokens read from cache */
|
|
445
|
+
cacheReadTokens?: number;
|
|
446
|
+
/** Total tokens written to cache */
|
|
447
|
+
cacheWriteTokens?: number;
|
|
448
|
+
/** Total cost in dollars */
|
|
449
|
+
totalCost?: number;
|
|
450
|
+
}
|
|
451
|
+
export declare const AgentUsageSchema: z.ZodObject<{
|
|
452
|
+
inputTokens: z.ZodNumber;
|
|
453
|
+
outputTokens: z.ZodNumber;
|
|
454
|
+
cacheReadTokens: z.ZodOptional<z.ZodNumber>;
|
|
455
|
+
cacheWriteTokens: z.ZodOptional<z.ZodNumber>;
|
|
456
|
+
totalCost: z.ZodOptional<z.ZodNumber>;
|
|
457
|
+
}, z.core.$strip>;
|
|
458
|
+
export interface AgentPrepareTurnContext {
|
|
459
|
+
agentId: string;
|
|
460
|
+
conversationId: string;
|
|
461
|
+
parentAgentId: string | null;
|
|
462
|
+
iteration: number;
|
|
463
|
+
messages: MessageWithMetadata[];
|
|
464
|
+
apiMessages: MessageWithMetadata[];
|
|
465
|
+
abortSignal: AbortSignal;
|
|
466
|
+
systemPrompt: string;
|
|
467
|
+
tools: AgentTool[];
|
|
468
|
+
model: {
|
|
469
|
+
id: string;
|
|
470
|
+
provider: string;
|
|
471
|
+
info?: ModelInfo;
|
|
472
|
+
};
|
|
473
|
+
emitStatusNotice?: (message: string, metadata?: Record<string, unknown>) => void;
|
|
474
|
+
}
|
|
475
|
+
export interface AgentPrepareTurnResult {
|
|
476
|
+
messages?: MessageWithMetadata[];
|
|
477
|
+
systemPrompt?: string;
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Result returned from Agent.run()
|
|
481
|
+
*/
|
|
482
|
+
export interface AgentResult {
|
|
483
|
+
/** Final text output from the agent */
|
|
484
|
+
text: string;
|
|
485
|
+
/** Aggregated token usage and cost */
|
|
486
|
+
usage: LegacyAgentUsage;
|
|
487
|
+
/** Full conversation history */
|
|
488
|
+
messages: MessageWithMetadata[];
|
|
489
|
+
/** All tool calls made during execution */
|
|
490
|
+
toolCalls: ToolCallRecord[];
|
|
491
|
+
/** Number of loop iterations */
|
|
492
|
+
iterations: number;
|
|
493
|
+
/** Why the agent stopped */
|
|
494
|
+
finishReason: AgentFinishReason;
|
|
495
|
+
/** Model information used */
|
|
496
|
+
model: {
|
|
497
|
+
id: string;
|
|
498
|
+
provider: string;
|
|
499
|
+
info?: ModelInfo;
|
|
500
|
+
};
|
|
501
|
+
/** Start time of the run */
|
|
502
|
+
startedAt: Date;
|
|
503
|
+
/** End time of the run */
|
|
504
|
+
endedAt: Date;
|
|
505
|
+
/** Total duration in milliseconds */
|
|
506
|
+
durationMs: number;
|
|
507
|
+
}
|
|
508
|
+
export declare const AgentResultSchema: z.ZodObject<{
|
|
509
|
+
text: z.ZodString;
|
|
510
|
+
usage: z.ZodObject<{
|
|
511
|
+
inputTokens: z.ZodNumber;
|
|
512
|
+
outputTokens: z.ZodNumber;
|
|
513
|
+
cacheReadTokens: z.ZodOptional<z.ZodNumber>;
|
|
514
|
+
cacheWriteTokens: z.ZodOptional<z.ZodNumber>;
|
|
515
|
+
totalCost: z.ZodOptional<z.ZodNumber>;
|
|
516
|
+
}, z.core.$strip>;
|
|
517
|
+
messages: z.ZodArray<z.ZodCustom<MessageWithMetadata, MessageWithMetadata>>;
|
|
518
|
+
toolCalls: z.ZodArray<z.ZodObject<{
|
|
519
|
+
id: z.ZodString;
|
|
520
|
+
name: z.ZodString;
|
|
521
|
+
input: z.ZodUnknown;
|
|
522
|
+
output: z.ZodUnknown;
|
|
523
|
+
error: z.ZodOptional<z.ZodString>;
|
|
524
|
+
durationMs: z.ZodNumber;
|
|
525
|
+
startedAt: z.ZodDate;
|
|
526
|
+
endedAt: z.ZodDate;
|
|
527
|
+
}, z.core.$strip>>;
|
|
528
|
+
iterations: z.ZodNumber;
|
|
529
|
+
finishReason: z.ZodEnum<{
|
|
530
|
+
error: "error";
|
|
531
|
+
completed: "completed";
|
|
532
|
+
aborted: "aborted";
|
|
533
|
+
mistake_limit: "mistake_limit";
|
|
534
|
+
max_iterations: "max_iterations";
|
|
535
|
+
}>;
|
|
536
|
+
model: z.ZodObject<{
|
|
537
|
+
id: z.ZodString;
|
|
538
|
+
provider: z.ZodString;
|
|
539
|
+
info: z.ZodOptional<z.ZodObject<{
|
|
540
|
+
id: z.ZodString;
|
|
541
|
+
name: z.ZodOptional<z.ZodString>;
|
|
542
|
+
description: z.ZodOptional<z.ZodString>;
|
|
543
|
+
maxTokens: z.ZodOptional<z.ZodNumber>;
|
|
544
|
+
contextWindow: z.ZodOptional<z.ZodNumber>;
|
|
545
|
+
maxInputTokens: z.ZodOptional<z.ZodNumber>;
|
|
546
|
+
capabilities: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
547
|
+
images: "images";
|
|
548
|
+
tools: "tools";
|
|
549
|
+
streaming: "streaming";
|
|
550
|
+
"prompt-cache": "prompt-cache";
|
|
551
|
+
reasoning: "reasoning";
|
|
552
|
+
"reasoning-effort": "reasoning-effort";
|
|
553
|
+
"computer-use": "computer-use";
|
|
554
|
+
"global-endpoint": "global-endpoint";
|
|
555
|
+
structured_output: "structured_output";
|
|
556
|
+
temperature: "temperature";
|
|
557
|
+
files: "files";
|
|
558
|
+
}>>>;
|
|
559
|
+
apiFormat: z.ZodOptional<z.ZodEnum<{
|
|
560
|
+
default: "default";
|
|
561
|
+
"openai-responses": "openai-responses";
|
|
562
|
+
r1: "r1";
|
|
563
|
+
}>>;
|
|
564
|
+
systemRole: z.ZodOptional<z.ZodEnum<{
|
|
565
|
+
system: "system";
|
|
566
|
+
developer: "developer";
|
|
567
|
+
}>>;
|
|
568
|
+
temperature: z.ZodOptional<z.ZodNumber>;
|
|
569
|
+
pricing: z.ZodOptional<z.ZodObject<{
|
|
570
|
+
input: z.ZodOptional<z.ZodNumber>;
|
|
571
|
+
output: z.ZodOptional<z.ZodNumber>;
|
|
572
|
+
cacheWrite: z.ZodOptional<z.ZodNumber>;
|
|
573
|
+
cacheRead: z.ZodOptional<z.ZodNumber>;
|
|
574
|
+
}, z.core.$strip>>;
|
|
575
|
+
thinkingConfig: z.ZodOptional<z.ZodObject<{
|
|
576
|
+
maxBudget: z.ZodOptional<z.ZodNumber>;
|
|
577
|
+
outputPrice: z.ZodOptional<z.ZodNumber>;
|
|
578
|
+
thinkingLevel: z.ZodOptional<z.ZodEnum<{
|
|
579
|
+
low: "low";
|
|
580
|
+
high: "high";
|
|
581
|
+
}>>;
|
|
582
|
+
}, z.core.$strip>>;
|
|
583
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
584
|
+
active: "active";
|
|
585
|
+
preview: "preview";
|
|
586
|
+
deprecated: "deprecated";
|
|
587
|
+
legacy: "legacy";
|
|
588
|
+
}>>;
|
|
589
|
+
deprecationNotice: z.ZodOptional<z.ZodString>;
|
|
590
|
+
replacedBy: z.ZodOptional<z.ZodString>;
|
|
591
|
+
releaseDate: z.ZodOptional<z.ZodString>;
|
|
592
|
+
deprecationDate: z.ZodOptional<z.ZodString>;
|
|
593
|
+
family: z.ZodOptional<z.ZodString>;
|
|
594
|
+
metadata: z.ZodOptional<z.ZodObject<{
|
|
595
|
+
reasoningDefaultOn: z.ZodOptional<z.ZodBoolean>;
|
|
596
|
+
}, z.core.$catchall<z.ZodUnknown>>>;
|
|
597
|
+
}, z.core.$strip>>;
|
|
598
|
+
}, z.core.$strip>;
|
|
599
|
+
startedAt: z.ZodDate;
|
|
600
|
+
endedAt: z.ZodDate;
|
|
601
|
+
durationMs: z.ZodNumber;
|
|
602
|
+
}, z.core.$strip>;
|
|
603
|
+
/**
|
|
604
|
+
* Reasoning effort level for capable models
|
|
605
|
+
*/
|
|
606
|
+
export type ReasoningEffort = "low" | "medium" | "high" | "xhigh";
|
|
607
|
+
export declare const ReasoningEffortSchema: z.ZodEnum<{
|
|
608
|
+
low: "low";
|
|
609
|
+
high: "high";
|
|
610
|
+
medium: "medium";
|
|
611
|
+
xhigh: "xhigh";
|
|
612
|
+
}>;
|
|
613
|
+
/**
|
|
614
|
+
* Configuration for creating an Agent
|
|
615
|
+
*/
|
|
616
|
+
export interface AgentConfig {
|
|
617
|
+
/**
|
|
618
|
+
* Core/hub runtime session identifier.
|
|
619
|
+
*
|
|
620
|
+
* The host-owned lifecycle id for this task/session. Core uses it for
|
|
621
|
+
* persistence, event routing, abort/stop operations, and approval delivery.
|
|
622
|
+
* This is intentionally separate from `conversationId`, which identifies the
|
|
623
|
+
* model transcript managed by the agent runtime.
|
|
624
|
+
*/
|
|
625
|
+
sessionId?: string;
|
|
626
|
+
/** Provider ID (e.g., "anthropic", "openai", "gemini") */
|
|
627
|
+
providerId: string;
|
|
628
|
+
/** Model ID to use */
|
|
629
|
+
modelId: string;
|
|
630
|
+
/** API key for the provider */
|
|
631
|
+
apiKey?: string;
|
|
632
|
+
/** Custom base URL for the API */
|
|
633
|
+
baseUrl?: string;
|
|
634
|
+
/** Additional headers for API requests */
|
|
635
|
+
headers?: Record<string, string>;
|
|
636
|
+
/** Optional provider model catalog overrides */
|
|
637
|
+
knownModels?: Record<string, ModelInfo>;
|
|
638
|
+
/** Optional pre-resolved provider configuration (includes provider-specific fields like aws/gcp). */
|
|
639
|
+
providerConfig?: unknown;
|
|
640
|
+
/**
|
|
641
|
+
* Optional preloaded conversation history for resume flows.
|
|
642
|
+
* When provided, start by calling continue() to preserve history.
|
|
643
|
+
*/
|
|
644
|
+
initialMessages?: Message[];
|
|
645
|
+
/** System prompt for the agent */
|
|
646
|
+
systemPrompt: string;
|
|
647
|
+
/** Tools available to the agent */
|
|
648
|
+
tools: AgentTool[];
|
|
649
|
+
/**
|
|
650
|
+
* Maximum number of loop iterations
|
|
651
|
+
* If undefined, no iteration cap is enforced.
|
|
652
|
+
*/
|
|
653
|
+
maxIterations?: number;
|
|
654
|
+
/**
|
|
655
|
+
* Maximum number of tool calls to execute concurrently in a single iteration.
|
|
656
|
+
* @default 8
|
|
657
|
+
*/
|
|
658
|
+
maxParallelToolCalls?: number;
|
|
659
|
+
/**
|
|
660
|
+
* Maximum output tokens per API call
|
|
661
|
+
*/
|
|
662
|
+
maxTokensPerTurn?: number;
|
|
663
|
+
/**
|
|
664
|
+
* Timeout for each API call in milliseconds
|
|
665
|
+
* @default 180000 (3 minutes)
|
|
666
|
+
*/
|
|
667
|
+
apiTimeoutMs?: number;
|
|
668
|
+
/**
|
|
669
|
+
* Optional runtime file-content loader used when user files are attached.
|
|
670
|
+
* When omitted, attached files will be represented as loader errors.
|
|
671
|
+
*/
|
|
672
|
+
userFileContentLoader?: (path: string) => Promise<string>;
|
|
673
|
+
/**
|
|
674
|
+
* Optional metadata merged into every tool execution context.
|
|
675
|
+
* Hosts can use this to thread runtime-specific identifiers such as session IDs.
|
|
676
|
+
*/
|
|
677
|
+
toolContextMetadata?: Record<string, unknown>;
|
|
678
|
+
/** Execution guardrails and recovery settings. */
|
|
679
|
+
execution?: AgentExecutionConfig;
|
|
680
|
+
/**
|
|
681
|
+
* Reasoning effort level
|
|
682
|
+
*/
|
|
683
|
+
reasoningEffort?: ReasoningEffort;
|
|
684
|
+
/**
|
|
685
|
+
* Maximum tokens for thinking/reasoning
|
|
686
|
+
*/
|
|
687
|
+
thinkingBudgetTokens?: number;
|
|
688
|
+
/**
|
|
689
|
+
* Enable default thinking/reasoning behavior for supported models.
|
|
690
|
+
*/
|
|
691
|
+
thinking?: boolean;
|
|
692
|
+
/**
|
|
693
|
+
* Callback for agent events (streaming, progress, etc.)
|
|
694
|
+
*/
|
|
695
|
+
onEvent?: (event: AgentEvent) => void;
|
|
696
|
+
/**
|
|
697
|
+
* Lifecycle hooks for observing or influencing agent execution.
|
|
698
|
+
*/
|
|
699
|
+
hooks?: AgentHooks;
|
|
700
|
+
/**
|
|
701
|
+
* Optional parent agent ID for spawned/delegated runs.
|
|
702
|
+
* Root agents should leave this undefined.
|
|
703
|
+
*/
|
|
704
|
+
parentAgentId?: string;
|
|
705
|
+
/**
|
|
706
|
+
* Extension modules that can intercept lifecycle events and register tools/commands.
|
|
707
|
+
*/
|
|
708
|
+
extensions?: AgentExtension[];
|
|
709
|
+
/**
|
|
710
|
+
* How hook errors should be handled.
|
|
711
|
+
* @default "ignore"
|
|
712
|
+
*/
|
|
713
|
+
hookErrorMode?: HookErrorMode;
|
|
714
|
+
/**
|
|
715
|
+
* Optional schedule metadata for runs initiated by scheduler services.
|
|
716
|
+
* Used by session_start lifecycle hooks.
|
|
717
|
+
*/
|
|
718
|
+
schedule?: AgentHookScheduleContext;
|
|
719
|
+
/**
|
|
720
|
+
* Per-tool execution policy. Tool names not listed here default to enabled + autoApprove.
|
|
721
|
+
*/
|
|
722
|
+
toolPolicies?: Record<string, ToolPolicy>;
|
|
723
|
+
/**
|
|
724
|
+
* Optional callback to request client approval when a tool policy disables auto-approval.
|
|
725
|
+
*/
|
|
726
|
+
requestToolApproval?: (request: ToolApprovalRequest) => Promise<ToolApprovalResult> | ToolApprovalResult;
|
|
727
|
+
/**
|
|
728
|
+
* Optional callback invoked when consecutive mistakes reach maxConsecutiveMistakes.
|
|
729
|
+
*/
|
|
730
|
+
onConsecutiveMistakeLimitReached?: (context: ConsecutiveMistakeLimitContext) => Promise<ConsecutiveMistakeLimitDecision> | ConsecutiveMistakeLimitDecision;
|
|
731
|
+
/**
|
|
732
|
+
* Optional logger for tracing agent loop lifecycle and recoverable failures.
|
|
733
|
+
*/
|
|
734
|
+
logger?: BasicLogger;
|
|
735
|
+
/**
|
|
736
|
+
* Optional callback that can rewrite the turn input before each model call.
|
|
737
|
+
* This is the primary seam for host-owned context pipelines.
|
|
738
|
+
*/
|
|
739
|
+
prepareTurn?: (context: AgentPrepareTurnContext) => Promise<AgentPrepareTurnResult | undefined> | AgentPrepareTurnResult | undefined;
|
|
740
|
+
/**
|
|
741
|
+
* Optional Telemetry service for emitting structured events about agent execution to configured telemetry backends.
|
|
742
|
+
*/
|
|
743
|
+
telemetry?: ITelemetryService;
|
|
744
|
+
/**
|
|
745
|
+
* Ambient runtime context: user identity, client surface, workspace, logger,
|
|
746
|
+
* and telemetry. Threaded through to ProviderConfig so handlers can access it.
|
|
747
|
+
*/
|
|
748
|
+
extensionContext?: ExtensionContext;
|
|
749
|
+
/**
|
|
750
|
+
* First-class runtime completion policy. Tool-based completion is resolved
|
|
751
|
+
* from the final agent tool list, so built-in and plugin tools can opt in
|
|
752
|
+
* with `lifecycle.completesRun`.
|
|
753
|
+
*
|
|
754
|
+
* `completionGuard` runs when the model returns no tool calls.
|
|
755
|
+
* If it returns a non-empty string, that string is injected as a
|
|
756
|
+
* system-level nudge and the loop continues instead of completing.
|
|
757
|
+
* Use this to prevent premature exit when the agent has unfinished
|
|
758
|
+
* obligations (e.g. in-progress team tasks).
|
|
759
|
+
*/
|
|
760
|
+
completionPolicy?: {
|
|
761
|
+
requireCompletionTool?: boolean;
|
|
762
|
+
completionGuard?: () => string | undefined;
|
|
763
|
+
};
|
|
764
|
+
/**
|
|
765
|
+
* Optional callback invoked at the top of each agent loop iteration
|
|
766
|
+
* (after the first). If it returns a non-empty string, that string is
|
|
767
|
+
* injected as a user message into the conversation before the next API
|
|
768
|
+
* call. This allows the host to feed user input into a running loop
|
|
769
|
+
* without waiting for the current run to finish.
|
|
770
|
+
*/
|
|
771
|
+
consumePendingUserMessage?: () => string | undefined;
|
|
772
|
+
/**
|
|
773
|
+
* Abort signal for cancellation
|
|
774
|
+
*/
|
|
775
|
+
abortSignal?: AbortSignal;
|
|
776
|
+
}
|
|
777
|
+
export declare const AgentConfigSchema: z.ZodObject<{
|
|
778
|
+
sessionId: z.ZodOptional<z.ZodString>;
|
|
779
|
+
providerId: z.ZodString;
|
|
780
|
+
modelId: z.ZodString;
|
|
781
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
782
|
+
baseUrl: z.ZodOptional<z.ZodString>;
|
|
783
|
+
headers: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
784
|
+
knownModels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
785
|
+
id: z.ZodString;
|
|
786
|
+
name: z.ZodOptional<z.ZodString>;
|
|
787
|
+
description: z.ZodOptional<z.ZodString>;
|
|
788
|
+
maxTokens: z.ZodOptional<z.ZodNumber>;
|
|
789
|
+
contextWindow: z.ZodOptional<z.ZodNumber>;
|
|
790
|
+
maxInputTokens: z.ZodOptional<z.ZodNumber>;
|
|
791
|
+
capabilities: z.ZodOptional<z.ZodArray<z.ZodEnum<{
|
|
792
|
+
images: "images";
|
|
793
|
+
tools: "tools";
|
|
794
|
+
streaming: "streaming";
|
|
795
|
+
"prompt-cache": "prompt-cache";
|
|
796
|
+
reasoning: "reasoning";
|
|
797
|
+
"reasoning-effort": "reasoning-effort";
|
|
798
|
+
"computer-use": "computer-use";
|
|
799
|
+
"global-endpoint": "global-endpoint";
|
|
800
|
+
structured_output: "structured_output";
|
|
801
|
+
temperature: "temperature";
|
|
802
|
+
files: "files";
|
|
803
|
+
}>>>;
|
|
804
|
+
apiFormat: z.ZodOptional<z.ZodEnum<{
|
|
805
|
+
default: "default";
|
|
806
|
+
"openai-responses": "openai-responses";
|
|
807
|
+
r1: "r1";
|
|
808
|
+
}>>;
|
|
809
|
+
systemRole: z.ZodOptional<z.ZodEnum<{
|
|
810
|
+
system: "system";
|
|
811
|
+
developer: "developer";
|
|
812
|
+
}>>;
|
|
813
|
+
temperature: z.ZodOptional<z.ZodNumber>;
|
|
814
|
+
pricing: z.ZodOptional<z.ZodObject<{
|
|
815
|
+
input: z.ZodOptional<z.ZodNumber>;
|
|
816
|
+
output: z.ZodOptional<z.ZodNumber>;
|
|
817
|
+
cacheWrite: z.ZodOptional<z.ZodNumber>;
|
|
818
|
+
cacheRead: z.ZodOptional<z.ZodNumber>;
|
|
819
|
+
}, z.core.$strip>>;
|
|
820
|
+
thinkingConfig: z.ZodOptional<z.ZodObject<{
|
|
821
|
+
maxBudget: z.ZodOptional<z.ZodNumber>;
|
|
822
|
+
outputPrice: z.ZodOptional<z.ZodNumber>;
|
|
823
|
+
thinkingLevel: z.ZodOptional<z.ZodEnum<{
|
|
824
|
+
low: "low";
|
|
825
|
+
high: "high";
|
|
826
|
+
}>>;
|
|
827
|
+
}, z.core.$strip>>;
|
|
828
|
+
status: z.ZodOptional<z.ZodEnum<{
|
|
829
|
+
active: "active";
|
|
830
|
+
preview: "preview";
|
|
831
|
+
deprecated: "deprecated";
|
|
832
|
+
legacy: "legacy";
|
|
833
|
+
}>>;
|
|
834
|
+
deprecationNotice: z.ZodOptional<z.ZodString>;
|
|
835
|
+
replacedBy: z.ZodOptional<z.ZodString>;
|
|
836
|
+
releaseDate: z.ZodOptional<z.ZodString>;
|
|
837
|
+
deprecationDate: z.ZodOptional<z.ZodString>;
|
|
838
|
+
family: z.ZodOptional<z.ZodString>;
|
|
839
|
+
metadata: z.ZodOptional<z.ZodObject<{
|
|
840
|
+
reasoningDefaultOn: z.ZodOptional<z.ZodBoolean>;
|
|
841
|
+
}, z.core.$catchall<z.ZodUnknown>>>;
|
|
842
|
+
}, z.core.$strip>>>;
|
|
843
|
+
providerConfig: z.ZodOptional<z.ZodUnknown>;
|
|
844
|
+
initialMessages: z.ZodOptional<z.ZodArray<z.ZodCustom<Message, Message>>>;
|
|
845
|
+
systemPrompt: z.ZodString;
|
|
846
|
+
tools: z.ZodArray<z.ZodCustom<AgentTool<unknown, unknown>, AgentTool<unknown, unknown>>>;
|
|
847
|
+
maxIterations: z.ZodOptional<z.ZodNumber>;
|
|
848
|
+
maxParallelToolCalls: z.ZodDefault<z.ZodNumber>;
|
|
849
|
+
maxTokensPerTurn: z.ZodOptional<z.ZodNumber>;
|
|
850
|
+
apiTimeoutMs: z.ZodDefault<z.ZodNumber>;
|
|
851
|
+
userFileContentLoader: z.ZodOptional<z.ZodFunction<z.core.$ZodTuple<readonly [z.ZodString], z.core.$ZodFunctionOut>, z.ZodPromise<z.ZodString>>>;
|
|
852
|
+
toolContextMetadata: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
853
|
+
execution: z.ZodOptional<z.ZodObject<{
|
|
854
|
+
maxConsecutiveMistakes: z.ZodOptional<z.ZodNumber>;
|
|
855
|
+
reminderAfterIterations: z.ZodOptional<z.ZodNumber>;
|
|
856
|
+
reminderText: z.ZodOptional<z.ZodString>;
|
|
857
|
+
loopDetection: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<false>, z.ZodObject<{
|
|
858
|
+
softThreshold: z.ZodOptional<z.ZodNumber>;
|
|
859
|
+
hardThreshold: z.ZodOptional<z.ZodNumber>;
|
|
860
|
+
}, z.core.$strip>]>>;
|
|
861
|
+
}, z.core.$strip>>;
|
|
862
|
+
reasoningEffort: z.ZodOptional<z.ZodEnum<{
|
|
863
|
+
low: "low";
|
|
864
|
+
high: "high";
|
|
865
|
+
medium: "medium";
|
|
866
|
+
xhigh: "xhigh";
|
|
867
|
+
}>>;
|
|
868
|
+
thinkingBudgetTokens: z.ZodOptional<z.ZodNumber>;
|
|
869
|
+
thinking: z.ZodOptional<z.ZodBoolean>;
|
|
870
|
+
onEvent: z.ZodOptional<z.ZodFunction<z.core.$ZodTuple<readonly [z.ZodCustom<AgentEvent, AgentEvent>], z.core.$ZodFunctionOut>, z.ZodVoid>>;
|
|
871
|
+
hooks: z.ZodOptional<z.ZodCustom<Partial<AgentRuntimeHooks>, Partial<AgentRuntimeHooks>>>;
|
|
872
|
+
parentAgentId: z.ZodOptional<z.ZodString>;
|
|
873
|
+
extensions: z.ZodOptional<z.ZodArray<z.ZodCustom<AgentExtension, AgentExtension>>>;
|
|
874
|
+
hookErrorMode: z.ZodDefault<z.ZodEnum<{
|
|
875
|
+
ignore: "ignore";
|
|
876
|
+
throw: "throw";
|
|
877
|
+
}>>;
|
|
878
|
+
toolPolicies: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
879
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
880
|
+
autoApprove: z.ZodOptional<z.ZodBoolean>;
|
|
881
|
+
}, z.core.$strip>>>;
|
|
882
|
+
requestToolApproval: z.ZodOptional<z.ZodFunction<z.core.$ZodTuple<readonly [z.ZodObject<{
|
|
883
|
+
sessionId: z.ZodString;
|
|
884
|
+
agentId: z.ZodString;
|
|
885
|
+
conversationId: z.ZodString;
|
|
886
|
+
iteration: z.ZodNumber;
|
|
887
|
+
toolCallId: z.ZodString;
|
|
888
|
+
toolName: z.ZodString;
|
|
889
|
+
input: z.ZodUnknown;
|
|
890
|
+
policy: z.ZodDefault<z.ZodObject<{
|
|
891
|
+
enabled: z.ZodOptional<z.ZodBoolean>;
|
|
892
|
+
autoApprove: z.ZodOptional<z.ZodBoolean>;
|
|
893
|
+
}, z.core.$strip>>;
|
|
894
|
+
}, z.core.$strip>], z.core.$ZodFunctionOut>, z.ZodUnion<readonly [z.ZodObject<{
|
|
895
|
+
approved: z.ZodBoolean;
|
|
896
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
897
|
+
}, z.core.$strip>, z.ZodPromise<z.ZodObject<{
|
|
898
|
+
approved: z.ZodBoolean;
|
|
899
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
900
|
+
}, z.core.$strip>>]>>>;
|
|
901
|
+
onConsecutiveMistakeLimitReached: z.ZodOptional<z.ZodFunction<z.core.$ZodTuple<readonly [z.ZodObject<{
|
|
902
|
+
iteration: z.ZodNumber;
|
|
903
|
+
consecutiveMistakes: z.ZodNumber;
|
|
904
|
+
maxConsecutiveMistakes: z.ZodNumber;
|
|
905
|
+
reason: z.ZodEnum<{
|
|
906
|
+
api_error: "api_error";
|
|
907
|
+
invalid_tool_call: "invalid_tool_call";
|
|
908
|
+
tool_execution_failed: "tool_execution_failed";
|
|
909
|
+
}>;
|
|
910
|
+
details: z.ZodOptional<z.ZodString>;
|
|
911
|
+
}, z.core.$strip>], z.core.$ZodFunctionOut>, z.ZodUnion<readonly [z.ZodObject<{
|
|
912
|
+
action: z.ZodLiteral<"continue">;
|
|
913
|
+
guidance: z.ZodOptional<z.ZodString>;
|
|
914
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
915
|
+
action: z.ZodLiteral<"stop">;
|
|
916
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
917
|
+
}, z.core.$strip>, z.ZodPromise<z.ZodUnion<readonly [z.ZodObject<{
|
|
918
|
+
action: z.ZodLiteral<"continue">;
|
|
919
|
+
guidance: z.ZodOptional<z.ZodString>;
|
|
920
|
+
}, z.core.$strip>, z.ZodObject<{
|
|
921
|
+
action: z.ZodLiteral<"stop">;
|
|
922
|
+
reason: z.ZodOptional<z.ZodString>;
|
|
923
|
+
}, z.core.$strip>]>>]>>>;
|
|
924
|
+
logger: z.ZodOptional<z.ZodCustom<BasicLogger, BasicLogger>>;
|
|
925
|
+
extensionContext: z.ZodOptional<z.ZodCustom<ExtensionContext, ExtensionContext>>;
|
|
926
|
+
abortSignal: z.ZodOptional<z.ZodCustom<AbortSignal, AbortSignal>>;
|
|
927
|
+
}, z.core.$strip>;
|
|
928
|
+
/**
|
|
929
|
+
* Pending tool call from the model
|
|
930
|
+
*/
|
|
931
|
+
export interface PendingToolCall {
|
|
932
|
+
id: string;
|
|
933
|
+
name: string;
|
|
934
|
+
input: unknown;
|
|
935
|
+
signature?: string;
|
|
936
|
+
review?: boolean;
|
|
937
|
+
}
|
|
938
|
+
/**
|
|
939
|
+
* Processed response from one turn of the loop
|
|
940
|
+
*/
|
|
941
|
+
export interface ProcessedTurn {
|
|
942
|
+
/** Text output from the model */
|
|
943
|
+
text: string;
|
|
944
|
+
/** Reasoning/thinking content */
|
|
945
|
+
reasoning?: string;
|
|
946
|
+
/** Tool calls requested by the model */
|
|
947
|
+
toolCalls: PendingToolCall[];
|
|
948
|
+
/** Model-emitted tool calls that were invalid or missing required fields */
|
|
949
|
+
invalidToolCalls: Array<{
|
|
950
|
+
id: string;
|
|
951
|
+
name?: string;
|
|
952
|
+
input?: unknown;
|
|
953
|
+
reason: "missing_name" | "missing_arguments" | "invalid_arguments";
|
|
954
|
+
}>;
|
|
955
|
+
/** Token usage for this turn */
|
|
956
|
+
usage: {
|
|
957
|
+
inputTokens: number;
|
|
958
|
+
outputTokens: number;
|
|
959
|
+
cacheReadTokens?: number;
|
|
960
|
+
cacheWriteTokens?: number;
|
|
961
|
+
cost?: number;
|
|
962
|
+
};
|
|
963
|
+
/** Whether the response was truncated */
|
|
964
|
+
truncated: boolean;
|
|
965
|
+
/** Response ID from the API */
|
|
966
|
+
responseId?: string;
|
|
967
|
+
}
|