@dudko.dev/agent 0.0.30 → 0.0.32
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 +274 -9
- package/dist/cli.js +126 -56
- package/dist/index.cjs +94 -41
- package/dist/index.d.cts +421 -16
- package/dist/index.d.ts +421 -16
- package/dist/index.js +94 -41
- package/dist/subagent-worker.js +120 -0
- package/package.json +12 -12
package/dist/index.d.cts
CHANGED
|
@@ -1,23 +1,104 @@
|
|
|
1
1
|
import { OAuthClientProvider } from '@modelcontextprotocol/sdk/client/auth.js';
|
|
2
2
|
import { FetchLike } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
3
|
-
import { ToolSet } from 'ai';
|
|
3
|
+
import { ToolSet, LanguageModel, Tool, SystemModelMessage, ModelMessage } from 'ai';
|
|
4
4
|
import { OAuthClientMetadata, OAuthClientInformationMixed, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
5
5
|
|
|
6
6
|
type ProviderType = 'openai' | 'anthropic' | 'openai-compatible' | 'google' | 'xai' | 'azure' | 'amazon-bedrock' | 'google-vertex' | 'deepseek' | 'gateway' | 'cloudflare';
|
|
7
7
|
type LogLevel = 'none' | 'error' | 'warn' | 'info' | 'debug';
|
|
8
|
-
type ToolSelectionStrategy = 'all' | 'plan-narrowed';
|
|
8
|
+
type ToolSelectionStrategy = 'all' | 'plan-narrowed' | 'search' | 'auto';
|
|
9
|
+
type AgentStage = 'planner' | 'executor' | 'replanner' | 'synthesizer';
|
|
10
|
+
type ThinkingLevel = 'provider-default' | 'none' | 'minimal' | 'low' | 'medium' | 'high' | 'xhigh';
|
|
11
|
+
interface IThinkingConfig {
|
|
12
|
+
level?: ThinkingLevel;
|
|
13
|
+
budgetTokens?: number;
|
|
14
|
+
includeThoughts?: boolean;
|
|
15
|
+
}
|
|
16
|
+
type ThinkingSetting = boolean | ThinkingLevel | IThinkingConfig;
|
|
17
|
+
interface ITokenLimits {
|
|
18
|
+
maxInputTokens?: number;
|
|
19
|
+
maxOutputTokens?: number;
|
|
20
|
+
maxReasoningTokens?: number;
|
|
21
|
+
maxTotalTokens?: number;
|
|
22
|
+
perCall?: {
|
|
23
|
+
planner?: number;
|
|
24
|
+
executor?: number;
|
|
25
|
+
replanner?: number;
|
|
26
|
+
synthesizer?: number;
|
|
27
|
+
compaction?: number;
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
type TokenLimitKind = 'input' | 'output' | 'reasoning' | 'total';
|
|
31
|
+
type BudgetKind = TokenLimitKind | 'tool-calls';
|
|
32
|
+
interface ILimitBreach {
|
|
33
|
+
kind: TokenLimitKind;
|
|
34
|
+
tokens: number;
|
|
35
|
+
cap: number;
|
|
36
|
+
}
|
|
37
|
+
interface ICompactionConfig {
|
|
38
|
+
auto?: boolean;
|
|
39
|
+
contextWindowTokens?: number;
|
|
40
|
+
thresholdTokens?: number;
|
|
41
|
+
keepRecentTurns?: number;
|
|
42
|
+
keepRecentSteps?: number;
|
|
43
|
+
summaryMaxTokens?: number;
|
|
44
|
+
maxToolOutputChars?: number;
|
|
45
|
+
clearToolResultsAfterTokens?: number;
|
|
46
|
+
keepToolResults?: number;
|
|
47
|
+
}
|
|
48
|
+
interface ISkill {
|
|
49
|
+
name: string;
|
|
50
|
+
description: string;
|
|
51
|
+
content: string;
|
|
52
|
+
files?: {
|
|
53
|
+
path: string;
|
|
54
|
+
content: string;
|
|
55
|
+
}[];
|
|
56
|
+
}
|
|
57
|
+
type ToolApprovalMode = 'autopilot' | 'ask-writes' | 'ask-all' | 'read-only';
|
|
58
|
+
type ToolPermission = 'allow' | 'ask' | 'deny';
|
|
59
|
+
interface IToolApprovalRequest {
|
|
60
|
+
id: string;
|
|
61
|
+
toolName: string;
|
|
62
|
+
input: unknown;
|
|
63
|
+
readOnly: boolean;
|
|
64
|
+
step?: IPlanStep;
|
|
65
|
+
runId?: string;
|
|
66
|
+
}
|
|
67
|
+
type ToolApprovalDecision = boolean | {
|
|
68
|
+
approved: boolean;
|
|
69
|
+
reason?: string;
|
|
70
|
+
remember?: boolean;
|
|
71
|
+
};
|
|
72
|
+
interface IToolApprovalConfig {
|
|
73
|
+
mode?: ToolApprovalMode;
|
|
74
|
+
rules?: Record<string, ToolPermission>;
|
|
75
|
+
onRequest?: (req: IToolApprovalRequest) => ToolApprovalDecision | Promise<ToolApprovalDecision>;
|
|
76
|
+
timeoutMs?: number;
|
|
77
|
+
}
|
|
78
|
+
type PromptCachingSetting = boolean | {
|
|
79
|
+
ttl?: '5m' | '1h';
|
|
80
|
+
key?: string;
|
|
81
|
+
};
|
|
82
|
+
interface IToolCatalogEntry {
|
|
83
|
+
name: string;
|
|
84
|
+
description: string;
|
|
85
|
+
server?: string;
|
|
86
|
+
readOnly?: boolean;
|
|
87
|
+
}
|
|
9
88
|
interface IMcpHttpServerConfig {
|
|
10
89
|
url: string;
|
|
11
90
|
headers?: Record<string, string>;
|
|
12
91
|
getHeaders?: () => Promise<Record<string, string>> | Record<string, string>;
|
|
13
92
|
authProvider?: OAuthClientProvider;
|
|
14
93
|
fetch?: FetchLike;
|
|
94
|
+
connectTimeoutMs?: number;
|
|
15
95
|
}
|
|
16
96
|
interface IMcpStdioServerConfig {
|
|
17
97
|
command: string;
|
|
18
98
|
args?: string[];
|
|
19
99
|
env?: Record<string, string>;
|
|
20
100
|
cwd?: string;
|
|
101
|
+
connectTimeoutMs?: number;
|
|
21
102
|
}
|
|
22
103
|
type IMcpServerConfig = IMcpHttpServerConfig | IMcpStdioServerConfig;
|
|
23
104
|
interface IAgentStageOverride {
|
|
@@ -49,6 +130,17 @@ interface IAgentConfig {
|
|
|
49
130
|
maxRevisions?: number;
|
|
50
131
|
replanAfter?: ReplanTrigger;
|
|
51
132
|
maxTotalTokens?: number;
|
|
133
|
+
limits?: ITokenLimits;
|
|
134
|
+
maxToolCalls?: number;
|
|
135
|
+
maxPlanSteps?: number;
|
|
136
|
+
thinking?: ThinkingSetting;
|
|
137
|
+
stageThinking?: Partial<Record<AgentStage, ThinkingSetting>>;
|
|
138
|
+
compaction?: ICompactionConfig;
|
|
139
|
+
skills?: ISkill[];
|
|
140
|
+
toolApproval?: IToolApprovalConfig;
|
|
141
|
+
toolSearchThreshold?: number;
|
|
142
|
+
mcpConnectTimeoutMs?: number;
|
|
143
|
+
promptCaching?: PromptCachingSetting;
|
|
52
144
|
llmTimeoutMs?: number;
|
|
53
145
|
llmMaxRetries?: number;
|
|
54
146
|
maxConcurrentRuns?: number;
|
|
@@ -70,6 +162,9 @@ interface IUsage {
|
|
|
70
162
|
inputTokens: number;
|
|
71
163
|
outputTokens: number;
|
|
72
164
|
totalTokens: number;
|
|
165
|
+
reasoningTokens?: number;
|
|
166
|
+
cachedInputTokens?: number;
|
|
167
|
+
cacheWriteTokens?: number;
|
|
73
168
|
}
|
|
74
169
|
interface IPlanStep {
|
|
75
170
|
id: string;
|
|
@@ -81,6 +176,7 @@ interface IPlanStep {
|
|
|
81
176
|
interface IPlan {
|
|
82
177
|
thought: string;
|
|
83
178
|
steps: IPlanStep[];
|
|
179
|
+
skills?: string[];
|
|
84
180
|
}
|
|
85
181
|
interface IStepResult {
|
|
86
182
|
step: IPlanStep;
|
|
@@ -96,6 +192,7 @@ interface IStepResult {
|
|
|
96
192
|
}
|
|
97
193
|
type ReplanTrigger = 'failure' | 'always' | ((result: IStepResult) => boolean | Promise<boolean>);
|
|
98
194
|
type ReplanCause = 'last-step' | 'clean-step' | 'llm-decision';
|
|
195
|
+
type UsagePhase = 'plan' | 'execute' | 'replan' | 'synthesize' | 'compact' | 'subagent';
|
|
99
196
|
type AgentEventBody = {
|
|
100
197
|
type: 'plan.thought-delta';
|
|
101
198
|
delta: string;
|
|
@@ -118,6 +215,10 @@ type AgentEventBody = {
|
|
|
118
215
|
type: 'step.text-delta';
|
|
119
216
|
step: IPlanStep;
|
|
120
217
|
delta: string;
|
|
218
|
+
} | {
|
|
219
|
+
type: 'step.reasoning-delta';
|
|
220
|
+
step: IPlanStep;
|
|
221
|
+
delta: string;
|
|
121
222
|
} | {
|
|
122
223
|
type: 'step.tool-call';
|
|
123
224
|
step: IPlanStep;
|
|
@@ -141,6 +242,9 @@ type AgentEventBody = {
|
|
|
141
242
|
} | {
|
|
142
243
|
type: 'final.text-delta';
|
|
143
244
|
delta: string;
|
|
245
|
+
} | {
|
|
246
|
+
type: 'final.reasoning-delta';
|
|
247
|
+
delta: string;
|
|
144
248
|
} | {
|
|
145
249
|
type: 'final';
|
|
146
250
|
text: string;
|
|
@@ -150,7 +254,7 @@ type AgentEventBody = {
|
|
|
150
254
|
message: string;
|
|
151
255
|
} | {
|
|
152
256
|
type: 'usage';
|
|
153
|
-
phase:
|
|
257
|
+
phase: UsagePhase;
|
|
154
258
|
usage: IUsage;
|
|
155
259
|
} | {
|
|
156
260
|
type: 'retry';
|
|
@@ -159,8 +263,58 @@ type AgentEventBody = {
|
|
|
159
263
|
error: string;
|
|
160
264
|
} | {
|
|
161
265
|
type: 'budget.exceeded';
|
|
266
|
+
kind: BudgetKind;
|
|
162
267
|
tokens: number;
|
|
163
268
|
cap: number;
|
|
269
|
+
} | {
|
|
270
|
+
type: 'context.compacted';
|
|
271
|
+
scope: 'history' | 'trace' | 'tool-results';
|
|
272
|
+
beforeTokens: number;
|
|
273
|
+
afterTokens: number;
|
|
274
|
+
} | {
|
|
275
|
+
type: 'skill.activated';
|
|
276
|
+
name: string;
|
|
277
|
+
by: 'plan' | 'tool';
|
|
278
|
+
} | {
|
|
279
|
+
type: 'tools.discovered';
|
|
280
|
+
step: IPlanStep;
|
|
281
|
+
query: string;
|
|
282
|
+
names: string[];
|
|
283
|
+
} | {
|
|
284
|
+
type: 'tool.approval-requested';
|
|
285
|
+
id: string;
|
|
286
|
+
name: string;
|
|
287
|
+
input: unknown;
|
|
288
|
+
readOnly: boolean;
|
|
289
|
+
step?: IPlanStep;
|
|
290
|
+
} | {
|
|
291
|
+
type: 'tool.approval-resolved';
|
|
292
|
+
id: string;
|
|
293
|
+
name: string;
|
|
294
|
+
approved: boolean;
|
|
295
|
+
reason?: string;
|
|
296
|
+
automatic: boolean;
|
|
297
|
+
} | {
|
|
298
|
+
type: 'subagent.start';
|
|
299
|
+
id: string;
|
|
300
|
+
name: string;
|
|
301
|
+
task: string;
|
|
302
|
+
} | {
|
|
303
|
+
type: 'subagent.event';
|
|
304
|
+
id: string;
|
|
305
|
+
name: string;
|
|
306
|
+
event: AgentEvent;
|
|
307
|
+
} | {
|
|
308
|
+
type: 'subagent.complete';
|
|
309
|
+
id: string;
|
|
310
|
+
name: string;
|
|
311
|
+
text: string;
|
|
312
|
+
usage: IUsage;
|
|
313
|
+
} | {
|
|
314
|
+
type: 'subagent.error';
|
|
315
|
+
id: string;
|
|
316
|
+
name: string;
|
|
317
|
+
error: string;
|
|
164
318
|
} | {
|
|
165
319
|
type: 'revisions.exceeded';
|
|
166
320
|
cap: number;
|
|
@@ -192,6 +346,7 @@ interface IAgentRunResult {
|
|
|
192
346
|
trace: IStepResult[];
|
|
193
347
|
iterations: number;
|
|
194
348
|
usage: IUsage;
|
|
349
|
+
compactedHistory?: IConversationTurn[];
|
|
195
350
|
}
|
|
196
351
|
interface IRunSnapshot {
|
|
197
352
|
runId: string;
|
|
@@ -208,6 +363,10 @@ interface IRunSnapshot {
|
|
|
208
363
|
text?: string;
|
|
209
364
|
error?: string;
|
|
210
365
|
completedAt?: number;
|
|
366
|
+
traceSummary?: string;
|
|
367
|
+
traceSummaryUpTo?: number;
|
|
368
|
+
activeSkills?: string[];
|
|
369
|
+
toolCallCount?: number;
|
|
211
370
|
}
|
|
212
371
|
interface IPersistence {
|
|
213
372
|
onRunStart?: (snapshot: IRunSnapshot) => void | Promise<void>;
|
|
@@ -216,10 +375,98 @@ interface IPersistence {
|
|
|
216
375
|
loadRun?: (runId: string) => IRunSnapshot | null | Promise<IRunSnapshot | null>;
|
|
217
376
|
}
|
|
218
377
|
|
|
378
|
+
interface ICloseOptions {
|
|
379
|
+
waitForRuns?: boolean;
|
|
380
|
+
timeoutMs?: number;
|
|
381
|
+
}
|
|
382
|
+
interface ICompactOptions {
|
|
383
|
+
history: IConversationTurn[];
|
|
384
|
+
signal?: AbortSignal;
|
|
385
|
+
force?: boolean;
|
|
386
|
+
}
|
|
387
|
+
interface ICompactResult {
|
|
388
|
+
history: IConversationTurn[];
|
|
389
|
+
summary?: string;
|
|
390
|
+
beforeTokens: number;
|
|
391
|
+
afterTokens: number;
|
|
392
|
+
compacted: boolean;
|
|
393
|
+
}
|
|
394
|
+
interface IAgent {
|
|
395
|
+
run: (options: IAgentRunOptions) => Promise<IAgentRunResult>;
|
|
396
|
+
listTools: () => IToolCatalogEntry[];
|
|
397
|
+
listSkills: () => {
|
|
398
|
+
name: string;
|
|
399
|
+
description: string;
|
|
400
|
+
}[];
|
|
401
|
+
compact: (options: ICompactOptions) => Promise<ICompactResult>;
|
|
402
|
+
setToolApprovalMode: (mode: ToolApprovalMode) => void;
|
|
403
|
+
getToolApprovalMode: () => ToolApprovalMode;
|
|
404
|
+
reconnect: () => Promise<void>;
|
|
405
|
+
close: (options?: ICloseOptions) => Promise<void>;
|
|
406
|
+
activeRuns: () => number;
|
|
407
|
+
}
|
|
408
|
+
declare const createAgent: (config: IAgentConfig, baseEventHandler?: EventHandler) => Promise<IAgent>;
|
|
409
|
+
|
|
410
|
+
/**
|
|
411
|
+
* Thrown from inside a tool's execute when the call was not approved. The AI
|
|
412
|
+
* SDK records it as a failed tool call (`ok: false`), so the replanner sees
|
|
413
|
+
* it; `toJSON` keeps the message when a trace is serialised.
|
|
414
|
+
*/
|
|
415
|
+
declare class ToolDeniedError extends Error {
|
|
416
|
+
readonly reason?: string;
|
|
417
|
+
constructor(reason?: string);
|
|
418
|
+
toJSON(): string;
|
|
419
|
+
}
|
|
420
|
+
declare const markReadOnly: <T extends object>(tool: T, readOnly?: boolean) => T;
|
|
421
|
+
declare const isReadOnlyTool: (tool: unknown) => boolean;
|
|
422
|
+
/**
|
|
423
|
+
* The most specific rule matching `name`: an exact key wins, then the
|
|
424
|
+
* longest matching '*' glob (ties: the first declared). Pure.
|
|
425
|
+
*/
|
|
426
|
+
declare const matchToolRule: (rules: Record<string, ToolPermission> | undefined, name: string) => {
|
|
427
|
+
pattern: string;
|
|
428
|
+
permission: ToolPermission;
|
|
429
|
+
} | undefined;
|
|
430
|
+
interface IToolDecisionInput {
|
|
431
|
+
name: string;
|
|
432
|
+
readOnly: boolean;
|
|
433
|
+
mode: ToolApprovalMode;
|
|
434
|
+
rules?: Record<string, ToolPermission>;
|
|
435
|
+
remembered?: ReadonlySet<string>;
|
|
436
|
+
builtIn?: boolean;
|
|
437
|
+
}
|
|
438
|
+
interface IToolDecision {
|
|
439
|
+
permission: ToolPermission;
|
|
440
|
+
source: 'builtin' | 'remembered' | 'rule' | 'mode';
|
|
441
|
+
rule?: string;
|
|
442
|
+
}
|
|
443
|
+
/**
|
|
444
|
+
* Decide one call. Pure. Order: built-in -> remembered "always allow" ->
|
|
445
|
+
* most specific rule -> mode default (autopilot: allow; read-only: allow if
|
|
446
|
+
* readOnly else deny; ask-writes: allow if readOnly else ask; ask-all: ask).
|
|
447
|
+
*/
|
|
448
|
+
declare const decideToolPermission: (input: IToolDecisionInput) => IToolDecision;
|
|
449
|
+
|
|
219
450
|
declare const getCurrentRunId: () => string | undefined;
|
|
220
451
|
declare const getCurrentRunSandbox: () => string | undefined;
|
|
221
452
|
|
|
222
453
|
declare const redactHeaders: (headers: Record<string, string> | undefined) => Record<string, string> | undefined;
|
|
454
|
+
interface ISdkUsageLike {
|
|
455
|
+
inputTokens?: number;
|
|
456
|
+
outputTokens?: number;
|
|
457
|
+
totalTokens?: number;
|
|
458
|
+
inputTokenDetails?: {
|
|
459
|
+
cacheReadTokens?: number;
|
|
460
|
+
cacheWriteTokens?: number;
|
|
461
|
+
};
|
|
462
|
+
outputTokenDetails?: {
|
|
463
|
+
reasoningTokens?: number;
|
|
464
|
+
};
|
|
465
|
+
reasoningTokens?: number;
|
|
466
|
+
cachedInputTokens?: number;
|
|
467
|
+
}
|
|
468
|
+
declare const normalizeUsage: (usage: ISdkUsageLike | undefined | null) => Required<IUsage>;
|
|
469
|
+
declare const addUsage: (a: IUsage, b: IUsage) => Required<IUsage>;
|
|
223
470
|
|
|
224
471
|
/**
|
|
225
472
|
* OAuth 2.1 for remote MCP servers, from Node.
|
|
@@ -364,20 +611,178 @@ declare const finishMcpOAuth: (provider: NodeOAuthProvider, callback: {
|
|
|
364
611
|
state?: string;
|
|
365
612
|
}, opts?: IOAuthRequestOptions) => Promise<void>;
|
|
366
613
|
|
|
367
|
-
|
|
368
|
-
|
|
614
|
+
type ProviderOptionsMap = Record<string, Record<string, unknown>>;
|
|
615
|
+
interface IResolvedThinking {
|
|
616
|
+
reasoning?: ThinkingLevel;
|
|
617
|
+
providerOptions?: ProviderOptionsMap;
|
|
618
|
+
}
|
|
619
|
+
/**
|
|
620
|
+
* Map a thinking setting to AI SDK call options. Pure.
|
|
621
|
+
*
|
|
622
|
+
* - false / undefined -> {} (provider default, nothing sent)
|
|
623
|
+
* - 'none' -> { reasoning: 'none' } (explicit disable, no provider options)
|
|
624
|
+
* - budgetTokens -> Anthropic `thinking` + Google `thinkingConfig` budgets
|
|
625
|
+
* - otherwise, unless includeThoughts is false -> ask Google / OpenAI to
|
|
626
|
+
* return their thoughts (summaries) so they can be streamed.
|
|
627
|
+
*
|
|
628
|
+
* Provider-specific options take precedence over `reasoning` inside the SDK.
|
|
629
|
+
*/
|
|
630
|
+
declare const resolveThinking: (setting: ThinkingSetting | undefined) => IResolvedThinking;
|
|
631
|
+
declare const mergeProviderOptions: (...layers: (ProviderOptionsMap | undefined)[]) => ProviderOptionsMap | undefined;
|
|
632
|
+
|
|
633
|
+
declare const resolveLimits: (config: Pick<IAgentConfig, "limits" | "maxTotalTokens">) => ITokenLimits;
|
|
634
|
+
/**
|
|
635
|
+
* The first cumulative cap `usage` has reached (>=), or undefined. Pure.
|
|
636
|
+
* Checked in order input, output, reasoning, total; a cap of 0 / undefined
|
|
637
|
+
* is "no cap".
|
|
638
|
+
*/
|
|
639
|
+
declare const checkLimits: (usage: IUsage, limits: ITokenLimits | undefined) => ILimitBreach | undefined;
|
|
640
|
+
|
|
641
|
+
declare const estimateTokens: (text: string) => number;
|
|
642
|
+
declare const SUMMARY_PREFIX = "[Summary of earlier conversation]";
|
|
643
|
+
interface ICompactHistoryOptions {
|
|
644
|
+
thresholdTokens?: number;
|
|
645
|
+
keepRecentTurns?: number;
|
|
646
|
+
summaryMaxTokens?: number;
|
|
647
|
+
force?: boolean;
|
|
648
|
+
signal?: AbortSignal;
|
|
369
649
|
timeoutMs?: number;
|
|
650
|
+
onUsage?: (usage: IUsage) => void;
|
|
370
651
|
}
|
|
371
|
-
interface
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
close: (options?: ICloseOptions) => Promise<void>;
|
|
379
|
-
activeRuns: () => number;
|
|
652
|
+
interface ICompactHistoryResult {
|
|
653
|
+
history: IConversationTurn[];
|
|
654
|
+
summary?: string;
|
|
655
|
+
beforeTokens: number;
|
|
656
|
+
afterTokens: number;
|
|
657
|
+
compacted: boolean;
|
|
658
|
+
usage?: IUsage;
|
|
380
659
|
}
|
|
381
|
-
|
|
660
|
+
/**
|
|
661
|
+
* Summarise all but the last `keepRecentTurns` turns into ONE assistant turn
|
|
662
|
+
* prefixed "[Summary of earlier conversation]" (an earlier summary turn is
|
|
663
|
+
* folded into the new one). Never throws: on failure, or below the
|
|
664
|
+
* threshold without `force`, the input comes back unchanged. The input array
|
|
665
|
+
* is never mutated.
|
|
666
|
+
*/
|
|
667
|
+
declare const compactHistory: (turns: IConversationTurn[], model: LanguageModel, opts?: ICompactHistoryOptions) => Promise<ICompactHistoryResult>;
|
|
668
|
+
type ToolModelOutput = Awaited<ReturnType<NonNullable<Tool['toModelOutput']>>>;
|
|
669
|
+
/**
|
|
670
|
+
* Clip what the MODEL sees of one tool result: text values, the JSON
|
|
671
|
+
* serialisation of json values (which then becomes text), and text parts of
|
|
672
|
+
* content values. Error / denied outputs pass through. Pure.
|
|
673
|
+
*/
|
|
674
|
+
declare const truncateToolModelOutput: (output: ToolModelOutput, maxChars: number) => ToolModelOutput;
|
|
675
|
+
/**
|
|
676
|
+
* Wrap a tool so the model sees at most `maxChars` of each result (with a
|
|
677
|
+
* "… [truncated N chars]" marker). An existing toModelOutput runs first and
|
|
678
|
+
* its value is clipped. The raw output (trace, events) is untouched.
|
|
679
|
+
*/
|
|
680
|
+
declare const withToolOutputLimit: <T extends Tool>(tool: T, maxChars: number) => T;
|
|
681
|
+
|
|
682
|
+
/**
|
|
683
|
+
* Validate a skill (name, description, content, files) and return a
|
|
684
|
+
* normalised copy. Throws a descriptive error on anything invalid.
|
|
685
|
+
*/
|
|
686
|
+
declare const defineSkill: (skill: ISkill) => ISkill;
|
|
687
|
+
/**
|
|
688
|
+
* Parse a SKILL.md: YAML-ish frontmatter between `---` lines with `name:`
|
|
689
|
+
* and `description:`, the body is the content. Throws a clear error when the
|
|
690
|
+
* frontmatter, the name or the description is missing or the name invalid.
|
|
691
|
+
*/
|
|
692
|
+
declare const parseSkillMarkdown: (markdown: string, files?: {
|
|
693
|
+
path: string;
|
|
694
|
+
content: string;
|
|
695
|
+
}[]) => ISkill;
|
|
696
|
+
/**
|
|
697
|
+
* Load every `<dir>/<skill>/SKILL.md`. Bundled files are the other text
|
|
698
|
+
* files under that skill folder (recursive; text extensions only; files over
|
|
699
|
+
* 256 KB skipped). Folders without a SKILL.md are ignored; duplicate skill
|
|
700
|
+
* names throw.
|
|
701
|
+
*/
|
|
702
|
+
declare const loadSkillsFromDir: (dir: string) => Promise<ISkill[]>;
|
|
703
|
+
|
|
704
|
+
declare class ToolBudgetError extends Error {
|
|
705
|
+
constructor(cap: number);
|
|
706
|
+
toJSON(): string;
|
|
707
|
+
}
|
|
708
|
+
|
|
709
|
+
interface ISearchToolsOptions {
|
|
710
|
+
server?: string;
|
|
711
|
+
limit?: number;
|
|
712
|
+
}
|
|
713
|
+
/**
|
|
714
|
+
* Rank catalogue entries for a free-text query. Pure.
|
|
715
|
+
* score = Σ over query terms of 3·nameHit + 2·serverHit + 1·descriptionHit,
|
|
716
|
+
* with prefix matching for terms of 3+ chars. Zero scores are dropped; ties
|
|
717
|
+
* keep catalogue order.
|
|
718
|
+
*/
|
|
719
|
+
declare const searchTools: <T extends IToolCatalogEntry>(catalog: T[], query: string, opts?: ISearchToolsOptions) => T[];
|
|
720
|
+
|
|
721
|
+
interface IResolvedPromptCaching {
|
|
722
|
+
enabled: boolean;
|
|
723
|
+
ttl?: '5m' | '1h';
|
|
724
|
+
key?: string;
|
|
725
|
+
}
|
|
726
|
+
declare const resolvePromptCaching: (setting: PromptCachingSetting | undefined) => IResolvedPromptCaching;
|
|
727
|
+
/**
|
|
728
|
+
* The `instructions` call option for a system prompt. With caching on, a
|
|
729
|
+
* SystemModelMessage carrying an Anthropic ephemeral cache breakpoint (other
|
|
730
|
+
* providers ignore the key); otherwise the plain string.
|
|
731
|
+
*/
|
|
732
|
+
declare const buildInstructions: (system: string, caching: IResolvedPromptCaching) => string | SystemModelMessage;
|
|
733
|
+
type WithProviderOptions = {
|
|
734
|
+
providerOptions?: unknown;
|
|
735
|
+
};
|
|
736
|
+
/**
|
|
737
|
+
* The conversation with a rolling cache breakpoint on its LAST message — the
|
|
738
|
+
* agent-loop pattern Claude Code uses: every tool-calling round re-sends the
|
|
739
|
+
* rounds before it, and with the breakpoint on the newest message each request
|
|
740
|
+
* reads all of them from the cache and writes only the new tail. Breakpoints
|
|
741
|
+
* on earlier messages are removed (the SDK carries a round's messages into the
|
|
742
|
+
* next one), so a request holds at most two — system + newest; Anthropic
|
|
743
|
+
* rejects more than four.
|
|
744
|
+
*/
|
|
745
|
+
declare const withRollingBreakpoint: <M extends WithProviderOptions>(messages: M[], caching: IResolvedPromptCaching) => M[];
|
|
746
|
+
|
|
747
|
+
/**
|
|
748
|
+
* Context editing inside one step's tool loop — what Anthropic's
|
|
749
|
+
* `clear_tool_uses` and Claude Code's micro-compaction do: once the loop's
|
|
750
|
+
* conversation grows past `triggerTokens`, the OLDEST tool results are replaced
|
|
751
|
+
* with a one-line stub (the calls stay, so the model knows what it did and can
|
|
752
|
+
* call again), keeping the `keep` most recent results verbatim. Clearing is
|
|
753
|
+
* sticky — a result cleared once stays cleared — so the prefix the provider
|
|
754
|
+
* cached does not flip back and forth between rounds.
|
|
755
|
+
*/
|
|
756
|
+
interface IToolResultClearing {
|
|
757
|
+
triggerTokens: number;
|
|
758
|
+
keep?: number;
|
|
759
|
+
}
|
|
760
|
+
interface IClearedInfo {
|
|
761
|
+
cleared: number;
|
|
762
|
+
beforeTokens: number;
|
|
763
|
+
afterTokens: number;
|
|
764
|
+
}
|
|
765
|
+
declare const createToolResultClearer: (opts: IToolResultClearing, onCleared?: (info: IClearedInfo) => void) => ((messages: ModelMessage[]) => ModelMessage[]);
|
|
766
|
+
|
|
767
|
+
type SubagentIsolation = 'worker' | 'in-process';
|
|
768
|
+
interface ISubagentToolOptions {
|
|
769
|
+
name: string;
|
|
770
|
+
description: string;
|
|
771
|
+
config: IAgentConfig;
|
|
772
|
+
isolation?: SubagentIsolation;
|
|
773
|
+
tools?: ToolSet;
|
|
774
|
+
maxConcurrent?: number;
|
|
775
|
+
timeoutMs?: number;
|
|
776
|
+
outputMaxChars?: number;
|
|
777
|
+
readOnly?: boolean;
|
|
778
|
+
}
|
|
779
|
+
/**
|
|
780
|
+
* Expose a whole agent as ONE tool of a parent agent: input `{ task }`,
|
|
781
|
+
* output the child's final text. Calls in one model step run in parallel
|
|
782
|
+
* (bounded by maxConcurrent); the parent's abort aborts the child; child
|
|
783
|
+
* usage is emitted on the parent as `usage` (phase 'subagent') so it counts
|
|
784
|
+
* against the parent's limits; child events arrive as `subagent.event`.
|
|
785
|
+
*/
|
|
786
|
+
declare const createSubagentTool: (opts: ISubagentToolOptions) => Tool;
|
|
382
787
|
|
|
383
|
-
export { type AgentEvent, type EventHandler, FileOAuthStore, type IAgent, type IAgentConfig, type IAgentRunOptions, type IAgentRunResult, type IAgentStageOverride, type ICloseOptions, type IConversationTurn, type IMcpHttpServerConfig, type IMcpServerConfig, type IMcpStdioServerConfig, type INodeOAuthProviderOptions, type IOAuthRequestOptions, type IOAuthStore, type IPersistence, type IPlan, type IPlanStep, type IRunSnapshot, type IStepResult, type IStepStartInfo, type IUsage, type LogLevel, MemoryOAuthStore, NodeOAuthProvider, type ProviderType, type ReplanCause, type ReplanTrigger, type ToolSelectionStrategy, beginMcpOAuth, createAgent, createNodeOAuthProvider, finishMcpOAuth, getCurrentRunId, getCurrentRunSandbox, redactHeaders };
|
|
788
|
+
export { type AgentEvent, type AgentStage, type BudgetKind, type EventHandler, FileOAuthStore, type IAgent, type IAgentConfig, type IAgentRunOptions, type IAgentRunResult, type IAgentStageOverride, type IClearedInfo, type ICloseOptions, type ICompactHistoryOptions, type ICompactHistoryResult, type ICompactOptions, type ICompactResult, type ICompactionConfig, type IConversationTurn, type ILimitBreach, type IMcpHttpServerConfig, type IMcpServerConfig, type IMcpStdioServerConfig, type INodeOAuthProviderOptions, type IOAuthRequestOptions, type IOAuthStore, type IPersistence, type IPlan, type IPlanStep, type IResolvedThinking, type IRunSnapshot, type ISearchToolsOptions, type ISkill, type IStepResult, type IStepStartInfo, type ISubagentToolOptions, type IThinkingConfig, type ITokenLimits, type IToolApprovalConfig, type IToolApprovalRequest, type IToolCatalogEntry, type IToolDecision, type IToolDecisionInput, type IToolResultClearing, type IUsage, type LogLevel, MemoryOAuthStore, NodeOAuthProvider, type PromptCachingSetting, type ProviderType, type ReplanCause, type ReplanTrigger, SUMMARY_PREFIX, type SubagentIsolation, type ThinkingLevel, type ThinkingSetting, type TokenLimitKind, type ToolApprovalDecision, type ToolApprovalMode, ToolBudgetError, ToolDeniedError, type ToolPermission, type ToolSelectionStrategy, type UsagePhase, addUsage, beginMcpOAuth, buildInstructions, checkLimits, compactHistory, createAgent, createNodeOAuthProvider, createSubagentTool, createToolResultClearer, decideToolPermission, defineSkill, estimateTokens, finishMcpOAuth, getCurrentRunId, getCurrentRunSandbox, isReadOnlyTool, loadSkillsFromDir, markReadOnly, matchToolRule, mergeProviderOptions, normalizeUsage, parseSkillMarkdown, redactHeaders, resolveLimits, resolvePromptCaching, resolveThinking, searchTools, truncateToolModelOutput, withRollingBreakpoint, withToolOutputLimit };
|