@dudko.dev/agent 0.0.36 → 0.0.38
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 +151 -4
- package/dist/cli.js +116 -72
- package/dist/index.cjs +86 -57
- package/dist/index.d.cts +204 -3
- package/dist/index.d.ts +204 -3
- package/dist/index.js +86 -57
- package/dist/subagent-worker.js +73 -53
- package/package.json +11 -11
package/dist/index.d.cts
CHANGED
|
@@ -3,6 +3,102 @@ import { FetchLike } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
|
3
3
|
import { ToolSet, LanguageModel, Tool, SystemModelMessage, ModelMessage } from 'ai';
|
|
4
4
|
import { OAuthClientMetadata, OAuthClientInformationMixed, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Steering a run that is already going.
|
|
8
|
+
*
|
|
9
|
+
* `run()` takes one goal and returns when the run is over, so a host that wants to
|
|
10
|
+
* say something mid-run — "actually use the staging database" — or stop one
|
|
11
|
+
* subagent out of several has nothing to call. A `RunControl` is the handle: create
|
|
12
|
+
* one, pass it as `run(goal, { control })`, and use it from anywhere while the run
|
|
13
|
+
* is in flight.
|
|
14
|
+
*
|
|
15
|
+
* A message is not interrupt. The run never cuts a tool call short (it may be a
|
|
16
|
+
* write): the message is held until the next boundary — the next tool-calling round
|
|
17
|
+
* inside a step, or the end of the step — and is then shown to the model. At a step
|
|
18
|
+
* boundary it also forces the replanner to look at the plan again, because a plan
|
|
19
|
+
* made before the user spoke may no longer be the right one.
|
|
20
|
+
*/
|
|
21
|
+
/** One running subagent, as the host sees it. */
|
|
22
|
+
interface SubagentInfo {
|
|
23
|
+
id: string;
|
|
24
|
+
/** The subagent tool's `name`. */
|
|
25
|
+
name: string;
|
|
26
|
+
task: string;
|
|
27
|
+
/** The profile the parent chose for this call, when it chose one. */
|
|
28
|
+
profile?: string;
|
|
29
|
+
startedAt: number;
|
|
30
|
+
}
|
|
31
|
+
interface RunControl {
|
|
32
|
+
/**
|
|
33
|
+
* Queue a message for the run. `false` when there is nothing to deliver it to — the text
|
|
34
|
+
* is empty, or the run has already finished (send it as a new run instead).
|
|
35
|
+
*
|
|
36
|
+
* Accepted does not mean delivered: a message that arrives after the last boundary
|
|
37
|
+
* (while the answer is being written) comes back in `RunResult.undelivered`, so the
|
|
38
|
+
* host can send it next.
|
|
39
|
+
*/
|
|
40
|
+
send(text: string): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Messages sent and not yet delivered. Once the run is over: the ones it never got to show
|
|
43
|
+
* the model (the same list as `RunResult.undelivered`, which a run that threw cannot return).
|
|
44
|
+
*/
|
|
45
|
+
pending(): string[];
|
|
46
|
+
/** The subagents running under this run right now (a snapshot; `subagent.*` events are the stream). */
|
|
47
|
+
subagents(): SubagentInfo[];
|
|
48
|
+
/**
|
|
49
|
+
* Stop ONE running subagent. Its delegation fails with a message the parent model can
|
|
50
|
+
* route around, and the run carries on — unlike aborting the run, which stops everything.
|
|
51
|
+
* `false` when no subagent with that id is running.
|
|
52
|
+
*/
|
|
53
|
+
stopSubagent(id: string): boolean;
|
|
54
|
+
}
|
|
55
|
+
declare const createRunControl: () => RunControl;
|
|
56
|
+
|
|
57
|
+
type EgressErrorCode = 'disabled' | 'bad-url' | 'bad-protocol' | 'bad-port' | 'bad-method' | 'credentials-in-url' | 'denied-host' | 'not-allowed-host' | 'denied-address' | 'dns' | 'bad-redirect' | 'too-many-redirects' | 'too-large' | 'timeout';
|
|
58
|
+
declare class EgressError extends Error {
|
|
59
|
+
readonly code: EgressErrorCode;
|
|
60
|
+
constructor(code: EgressErrorCode, message: string);
|
|
61
|
+
toJSON(): string;
|
|
62
|
+
}
|
|
63
|
+
interface IResolvedAddress {
|
|
64
|
+
address: string;
|
|
65
|
+
family: 4 | 6;
|
|
66
|
+
}
|
|
67
|
+
interface IEgressPolicy {
|
|
68
|
+
allow?: string[];
|
|
69
|
+
deny?: string[];
|
|
70
|
+
allowPrivateNetwork?: boolean;
|
|
71
|
+
protocols?: ('https' | 'http')[];
|
|
72
|
+
ports?: number[];
|
|
73
|
+
methods?: string[];
|
|
74
|
+
maxRedirects?: number;
|
|
75
|
+
maxResponseBytes?: number;
|
|
76
|
+
timeoutMs?: number;
|
|
77
|
+
ca?: string | string[];
|
|
78
|
+
lookup?: (hostname: string) => Promise<IResolvedAddress[]>;
|
|
79
|
+
}
|
|
80
|
+
interface IResolvedEgressPolicy {
|
|
81
|
+
allow: string[];
|
|
82
|
+
deny: string[];
|
|
83
|
+
allowPrivateNetwork: boolean;
|
|
84
|
+
protocols: ('https' | 'http')[];
|
|
85
|
+
ports: number[];
|
|
86
|
+
methods: string[];
|
|
87
|
+
maxRedirects: number;
|
|
88
|
+
maxResponseBytes: number;
|
|
89
|
+
timeoutMs: number;
|
|
90
|
+
ca?: string | string[];
|
|
91
|
+
lookup: (hostname: string) => Promise<IResolvedAddress[]>;
|
|
92
|
+
}
|
|
93
|
+
declare const resolveEgressPolicy: (policy?: IEgressPolicy) => IResolvedEgressPolicy;
|
|
94
|
+
type AddressClass = 'public' | 'private' | 'never';
|
|
95
|
+
declare const classifyAddress: (address: string) => AddressClass;
|
|
96
|
+
declare const hostMatches: (host: string, pattern: string) => boolean;
|
|
97
|
+
declare const checkEgressUrl: (url: URL, policy: IResolvedEgressPolicy, method?: string) => void;
|
|
98
|
+
declare const checkRedirect: (from: URL, to: URL) => void;
|
|
99
|
+
type SafeFetch = (input: string | URL, init?: RequestInit) => Promise<Response>;
|
|
100
|
+
declare const createSafeFetch: (policy?: IEgressPolicy) => SafeFetch;
|
|
101
|
+
|
|
6
102
|
type ProviderType = 'openai' | 'anthropic' | 'openai-compatible' | 'google' | 'xai' | 'azure' | 'amazon-bedrock' | 'google-vertex' | 'deepseek' | 'gateway' | 'cloudflare';
|
|
7
103
|
type LogLevel = 'none' | 'error' | 'warn' | 'info' | 'debug';
|
|
8
104
|
type ToolSelectionStrategy = 'all' | 'plan-narrowed' | 'search' | 'auto';
|
|
@@ -53,6 +149,26 @@ interface ISkill {
|
|
|
53
149
|
path: string;
|
|
54
150
|
content: string;
|
|
55
151
|
}[];
|
|
152
|
+
origin?: ISkillOrigin;
|
|
153
|
+
}
|
|
154
|
+
interface ISkillOrigin {
|
|
155
|
+
kind: 'learned';
|
|
156
|
+
at: number;
|
|
157
|
+
revision: number;
|
|
158
|
+
runId?: string;
|
|
159
|
+
sources?: string[];
|
|
160
|
+
fetched?: string[];
|
|
161
|
+
}
|
|
162
|
+
interface ISkillStore {
|
|
163
|
+
list: () => ISkill[] | Promise<ISkill[]>;
|
|
164
|
+
save: (skill: ISkill) => void | Promise<void>;
|
|
165
|
+
remove: (name: string) => boolean | Promise<boolean>;
|
|
166
|
+
}
|
|
167
|
+
interface ILearningConfig {
|
|
168
|
+
store?: ISkillStore;
|
|
169
|
+
maxSkills?: number;
|
|
170
|
+
maxSkillChars?: number;
|
|
171
|
+
nudge?: boolean;
|
|
56
172
|
}
|
|
57
173
|
type ToolApprovalMode = 'autopilot' | 'ask-writes' | 'ask-all' | 'read-only';
|
|
58
174
|
type ToolPermission = 'allow' | 'ask' | 'deny';
|
|
@@ -122,6 +238,8 @@ interface IAgentConfig {
|
|
|
122
238
|
/** @deprecated use `synthesizer: { model }` */
|
|
123
239
|
synthesizerModel?: string;
|
|
124
240
|
mcpServers: Record<string, IMcpServerConfig>;
|
|
241
|
+
egress?: boolean | IEgressPolicy;
|
|
242
|
+
learning?: boolean | ILearningConfig;
|
|
125
243
|
tools?: ToolSet;
|
|
126
244
|
availableTools?: string[];
|
|
127
245
|
excludedTools?: string[];
|
|
@@ -191,7 +309,7 @@ interface IStepResult {
|
|
|
191
309
|
blocked: boolean;
|
|
192
310
|
}
|
|
193
311
|
type ReplanTrigger = 'failure' | 'always' | ((result: IStepResult) => boolean | Promise<boolean>);
|
|
194
|
-
type ReplanCause = 'last-step' | 'clean-step' | 'llm-decision';
|
|
312
|
+
type ReplanCause = 'last-step' | 'clean-step' | 'llm-decision' | 'user-message';
|
|
195
313
|
type UsagePhase = 'plan' | 'execute' | 'replan' | 'synthesize' | 'compact' | 'subagent';
|
|
196
314
|
type AgentEventBody = {
|
|
197
315
|
type: 'plan.thought-delta';
|
|
@@ -299,6 +417,7 @@ type AgentEventBody = {
|
|
|
299
417
|
id: string;
|
|
300
418
|
name: string;
|
|
301
419
|
task: string;
|
|
420
|
+
profile?: string;
|
|
302
421
|
} | {
|
|
303
422
|
type: 'subagent.event';
|
|
304
423
|
id: string;
|
|
@@ -315,6 +434,32 @@ type AgentEventBody = {
|
|
|
315
434
|
id: string;
|
|
316
435
|
name: string;
|
|
317
436
|
error: string;
|
|
437
|
+
stopped?: boolean;
|
|
438
|
+
} | {
|
|
439
|
+
type: 'message.queued';
|
|
440
|
+
id: string;
|
|
441
|
+
text: string;
|
|
442
|
+
} | {
|
|
443
|
+
type: 'message.delivered';
|
|
444
|
+
id: string;
|
|
445
|
+
text: string;
|
|
446
|
+
at: 'round' | 'step' | 'final';
|
|
447
|
+
} | {
|
|
448
|
+
type: 'egress.request';
|
|
449
|
+
url: string;
|
|
450
|
+
allowed: boolean;
|
|
451
|
+
status?: number;
|
|
452
|
+
reason?: string;
|
|
453
|
+
} | {
|
|
454
|
+
type: 'skill.learned';
|
|
455
|
+
name: string;
|
|
456
|
+
description: string;
|
|
457
|
+
update: boolean;
|
|
458
|
+
chars: number;
|
|
459
|
+
sources: string[];
|
|
460
|
+
} | {
|
|
461
|
+
type: 'skill.forgotten';
|
|
462
|
+
name: string;
|
|
318
463
|
} | {
|
|
319
464
|
type: 'revisions.exceeded';
|
|
320
465
|
cap: number;
|
|
@@ -339,6 +484,7 @@ interface IAgentRunOptions {
|
|
|
339
484
|
onEvent?: EventHandler;
|
|
340
485
|
onStepStart?: (info: IStepStartInfo) => void;
|
|
341
486
|
resumeFromRunId?: string;
|
|
487
|
+
control?: RunControl;
|
|
342
488
|
}
|
|
343
489
|
interface IAgentRunResult {
|
|
344
490
|
text: string;
|
|
@@ -347,6 +493,7 @@ interface IAgentRunResult {
|
|
|
347
493
|
iterations: number;
|
|
348
494
|
usage: IUsage;
|
|
349
495
|
compactedHistory?: IConversationTurn[];
|
|
496
|
+
undelivered?: string[];
|
|
350
497
|
}
|
|
351
498
|
interface IRunSnapshot {
|
|
352
499
|
runId: string;
|
|
@@ -367,6 +514,10 @@ interface IRunSnapshot {
|
|
|
367
514
|
traceSummaryUpTo?: number;
|
|
368
515
|
activeSkills?: string[];
|
|
369
516
|
toolCallCount?: number;
|
|
517
|
+
userUpdates?: {
|
|
518
|
+
text: string;
|
|
519
|
+
reconciled: boolean;
|
|
520
|
+
}[];
|
|
370
521
|
}
|
|
371
522
|
interface IPersistence {
|
|
372
523
|
onRunStart?: (snapshot: IRunSnapshot) => void | Promise<void>;
|
|
@@ -397,7 +548,10 @@ interface IAgent {
|
|
|
397
548
|
listSkills: () => {
|
|
398
549
|
name: string;
|
|
399
550
|
description: string;
|
|
551
|
+
learned?: true;
|
|
400
552
|
}[];
|
|
553
|
+
listLearnedSkills: () => ISkill[];
|
|
554
|
+
forgetSkill: (name: string) => Promise<boolean>;
|
|
401
555
|
compact: (options: ICompactOptions) => Promise<ICompactResult>;
|
|
402
556
|
setToolApprovalMode: (mode: ToolApprovalMode) => void;
|
|
403
557
|
getToolApprovalMode: () => ToolApprovalMode;
|
|
@@ -764,7 +918,53 @@ interface IClearedInfo {
|
|
|
764
918
|
}
|
|
765
919
|
declare const createToolResultClearer: (opts: IToolResultClearing, onCleared?: (info: IClearedInfo) => void) => ((messages: ModelMessage[]) => ModelMessage[]);
|
|
766
920
|
|
|
921
|
+
declare const SAVE_SKILL_TOOL = "save_skill";
|
|
922
|
+
declare const FORGET_SKILL_TOOL = "forget_skill";
|
|
923
|
+
declare const findSecret: (text: string) => string | undefined;
|
|
924
|
+
declare const normalizeSkillName: (raw: string) => string | undefined;
|
|
925
|
+
declare class MemorySkillStore implements ISkillStore {
|
|
926
|
+
private readonly skills;
|
|
927
|
+
list(): ISkill[];
|
|
928
|
+
save(skill: ISkill): void;
|
|
929
|
+
remove(name: string): boolean;
|
|
930
|
+
}
|
|
931
|
+
declare class DirSkillStore implements ISkillStore {
|
|
932
|
+
private readonly dir;
|
|
933
|
+
constructor(dir: string);
|
|
934
|
+
list(): Promise<ISkill[]>;
|
|
935
|
+
save(skill: ISkill): Promise<void>;
|
|
936
|
+
remove(name: string): Promise<boolean>;
|
|
937
|
+
}
|
|
938
|
+
interface ILearning {
|
|
939
|
+
tools: ToolSet;
|
|
940
|
+
learned: () => ISkill[];
|
|
941
|
+
forget: (name: string) => Promise<boolean>;
|
|
942
|
+
}
|
|
943
|
+
interface ISaveSkillInput {
|
|
944
|
+
name: string;
|
|
945
|
+
description: string;
|
|
946
|
+
instructions: string;
|
|
947
|
+
sources?: string[];
|
|
948
|
+
}
|
|
949
|
+
declare const createLearning: (cfg: ILearningConfig, skills: ISkill[], emit: EventHandler, warn: (message: string) => void) => Promise<ILearning>;
|
|
950
|
+
|
|
951
|
+
declare const WEB_FETCH_TOOL = "web_fetch";
|
|
952
|
+
declare const htmlToText: (html: string) => {
|
|
953
|
+
title?: string;
|
|
954
|
+
text: string;
|
|
955
|
+
};
|
|
956
|
+
interface IWebFetchOptions {
|
|
957
|
+
policy?: IEgressPolicy;
|
|
958
|
+
fetch?: SafeFetch;
|
|
959
|
+
}
|
|
960
|
+
declare const createWebFetchTool: (options?: IWebFetchOptions) => Tool;
|
|
961
|
+
declare const createEgressTools: (egress: boolean | IEgressPolicy | undefined) => ToolSet | undefined;
|
|
962
|
+
|
|
767
963
|
type SubagentIsolation = 'worker' | 'in-process';
|
|
964
|
+
interface ISubagentProfile {
|
|
965
|
+
description: string;
|
|
966
|
+
config?: Partial<IAgentConfig>;
|
|
967
|
+
}
|
|
768
968
|
interface ISubagentToolOptions {
|
|
769
969
|
name: string;
|
|
770
970
|
description: string;
|
|
@@ -775,6 +975,7 @@ interface ISubagentToolOptions {
|
|
|
775
975
|
timeoutMs?: number;
|
|
776
976
|
outputMaxChars?: number;
|
|
777
977
|
readOnly?: boolean;
|
|
978
|
+
profiles?: Record<string, ISubagentProfile>;
|
|
778
979
|
}
|
|
779
980
|
/**
|
|
780
981
|
* Expose a whole agent as ONE tool of a parent agent: input `{ task }`,
|
|
@@ -785,5 +986,5 @@ interface ISubagentToolOptions {
|
|
|
785
986
|
*/
|
|
786
987
|
declare const createSubagentTool: (opts: ISubagentToolOptions) => Tool;
|
|
787
988
|
|
|
788
|
-
export { FileOAuthStore, MemoryOAuthStore, NodeOAuthProvider, SUMMARY_PREFIX, ToolBudgetError, ToolDeniedError, 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 };
|
|
789
|
-
export type { AgentEvent, AgentStage, BudgetKind, EventHandler, IAgent, IAgentConfig, IAgentRunOptions, IAgentRunResult, IAgentStageOverride, IClearedInfo, ICloseOptions, ICompactHistoryOptions, ICompactHistoryResult, ICompactOptions, ICompactResult, ICompactionConfig, IConversationTurn, ILimitBreach, IMcpHttpServerConfig, IMcpServerConfig, IMcpStdioServerConfig, INodeOAuthProviderOptions, IOAuthRequestOptions, IOAuthStore, IPersistence, IPlan, IPlanStep, IResolvedThinking, IRunSnapshot, ISearchToolsOptions, ISkill, IStepResult, IStepStartInfo, ISubagentToolOptions, IThinkingConfig, ITokenLimits, IToolApprovalConfig, IToolApprovalRequest, IToolCatalogEntry, IToolDecision, IToolDecisionInput, IToolResultClearing, IUsage, LogLevel, PromptCachingSetting, ProviderType, ReplanCause, ReplanTrigger, SubagentIsolation, ThinkingLevel, ThinkingSetting, TokenLimitKind, ToolApprovalDecision, ToolApprovalMode, ToolPermission, ToolSelectionStrategy, UsagePhase };
|
|
989
|
+
export { DirSkillStore, EgressError, FORGET_SKILL_TOOL, FileOAuthStore, MemoryOAuthStore, MemorySkillStore, NodeOAuthProvider, SAVE_SKILL_TOOL, SUMMARY_PREFIX, ToolBudgetError, ToolDeniedError, WEB_FETCH_TOOL, addUsage, beginMcpOAuth, buildInstructions, checkEgressUrl, checkLimits, checkRedirect, classifyAddress, compactHistory, createAgent, createEgressTools, createLearning, createNodeOAuthProvider, createRunControl, createSafeFetch, createSubagentTool, createToolResultClearer, createWebFetchTool, decideToolPermission, defineSkill, estimateTokens, findSecret, finishMcpOAuth, getCurrentRunId, getCurrentRunSandbox, hostMatches, htmlToText, isReadOnlyTool, loadSkillsFromDir, markReadOnly, matchToolRule, mergeProviderOptions, normalizeSkillName, normalizeUsage, parseSkillMarkdown, redactHeaders, resolveEgressPolicy, resolveLimits, resolvePromptCaching, resolveThinking, searchTools, truncateToolModelOutput, withRollingBreakpoint, withToolOutputLimit };
|
|
990
|
+
export type { AgentEvent, AgentStage, BudgetKind, EgressErrorCode, EventHandler, IAgent, IAgentConfig, IAgentRunOptions, IAgentRunResult, IAgentStageOverride, IClearedInfo, ICloseOptions, ICompactHistoryOptions, ICompactHistoryResult, ICompactOptions, ICompactResult, ICompactionConfig, IConversationTurn, IEgressPolicy, ILearning, ILearningConfig, ILimitBreach, IMcpHttpServerConfig, IMcpServerConfig, IMcpStdioServerConfig, INodeOAuthProviderOptions, IOAuthRequestOptions, IOAuthStore, IPersistence, IPlan, IPlanStep, IResolvedAddress, IResolvedThinking, IRunSnapshot, ISaveSkillInput, ISearchToolsOptions, ISkill, ISkillOrigin, ISkillStore, IStepResult, IStepStartInfo, ISubagentProfile, ISubagentToolOptions, IThinkingConfig, ITokenLimits, IToolApprovalConfig, IToolApprovalRequest, IToolCatalogEntry, IToolDecision, IToolDecisionInput, IToolResultClearing, IUsage, LogLevel, PromptCachingSetting, ProviderType, ReplanCause, ReplanTrigger, RunControl, SafeFetch, SubagentInfo, SubagentIsolation, ThinkingLevel, ThinkingSetting, TokenLimitKind, ToolApprovalDecision, ToolApprovalMode, ToolPermission, ToolSelectionStrategy, UsagePhase };
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,102 @@ import { FetchLike } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
|
3
3
|
import { ToolSet, LanguageModel, Tool, SystemModelMessage, ModelMessage } from 'ai';
|
|
4
4
|
import { OAuthClientMetadata, OAuthClientInformationMixed, OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Steering a run that is already going.
|
|
8
|
+
*
|
|
9
|
+
* `run()` takes one goal and returns when the run is over, so a host that wants to
|
|
10
|
+
* say something mid-run — "actually use the staging database" — or stop one
|
|
11
|
+
* subagent out of several has nothing to call. A `RunControl` is the handle: create
|
|
12
|
+
* one, pass it as `run(goal, { control })`, and use it from anywhere while the run
|
|
13
|
+
* is in flight.
|
|
14
|
+
*
|
|
15
|
+
* A message is not interrupt. The run never cuts a tool call short (it may be a
|
|
16
|
+
* write): the message is held until the next boundary — the next tool-calling round
|
|
17
|
+
* inside a step, or the end of the step — and is then shown to the model. At a step
|
|
18
|
+
* boundary it also forces the replanner to look at the plan again, because a plan
|
|
19
|
+
* made before the user spoke may no longer be the right one.
|
|
20
|
+
*/
|
|
21
|
+
/** One running subagent, as the host sees it. */
|
|
22
|
+
interface SubagentInfo {
|
|
23
|
+
id: string;
|
|
24
|
+
/** The subagent tool's `name`. */
|
|
25
|
+
name: string;
|
|
26
|
+
task: string;
|
|
27
|
+
/** The profile the parent chose for this call, when it chose one. */
|
|
28
|
+
profile?: string;
|
|
29
|
+
startedAt: number;
|
|
30
|
+
}
|
|
31
|
+
interface RunControl {
|
|
32
|
+
/**
|
|
33
|
+
* Queue a message for the run. `false` when there is nothing to deliver it to — the text
|
|
34
|
+
* is empty, or the run has already finished (send it as a new run instead).
|
|
35
|
+
*
|
|
36
|
+
* Accepted does not mean delivered: a message that arrives after the last boundary
|
|
37
|
+
* (while the answer is being written) comes back in `RunResult.undelivered`, so the
|
|
38
|
+
* host can send it next.
|
|
39
|
+
*/
|
|
40
|
+
send(text: string): boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Messages sent and not yet delivered. Once the run is over: the ones it never got to show
|
|
43
|
+
* the model (the same list as `RunResult.undelivered`, which a run that threw cannot return).
|
|
44
|
+
*/
|
|
45
|
+
pending(): string[];
|
|
46
|
+
/** The subagents running under this run right now (a snapshot; `subagent.*` events are the stream). */
|
|
47
|
+
subagents(): SubagentInfo[];
|
|
48
|
+
/**
|
|
49
|
+
* Stop ONE running subagent. Its delegation fails with a message the parent model can
|
|
50
|
+
* route around, and the run carries on — unlike aborting the run, which stops everything.
|
|
51
|
+
* `false` when no subagent with that id is running.
|
|
52
|
+
*/
|
|
53
|
+
stopSubagent(id: string): boolean;
|
|
54
|
+
}
|
|
55
|
+
declare const createRunControl: () => RunControl;
|
|
56
|
+
|
|
57
|
+
type EgressErrorCode = 'disabled' | 'bad-url' | 'bad-protocol' | 'bad-port' | 'bad-method' | 'credentials-in-url' | 'denied-host' | 'not-allowed-host' | 'denied-address' | 'dns' | 'bad-redirect' | 'too-many-redirects' | 'too-large' | 'timeout';
|
|
58
|
+
declare class EgressError extends Error {
|
|
59
|
+
readonly code: EgressErrorCode;
|
|
60
|
+
constructor(code: EgressErrorCode, message: string);
|
|
61
|
+
toJSON(): string;
|
|
62
|
+
}
|
|
63
|
+
interface IResolvedAddress {
|
|
64
|
+
address: string;
|
|
65
|
+
family: 4 | 6;
|
|
66
|
+
}
|
|
67
|
+
interface IEgressPolicy {
|
|
68
|
+
allow?: string[];
|
|
69
|
+
deny?: string[];
|
|
70
|
+
allowPrivateNetwork?: boolean;
|
|
71
|
+
protocols?: ('https' | 'http')[];
|
|
72
|
+
ports?: number[];
|
|
73
|
+
methods?: string[];
|
|
74
|
+
maxRedirects?: number;
|
|
75
|
+
maxResponseBytes?: number;
|
|
76
|
+
timeoutMs?: number;
|
|
77
|
+
ca?: string | string[];
|
|
78
|
+
lookup?: (hostname: string) => Promise<IResolvedAddress[]>;
|
|
79
|
+
}
|
|
80
|
+
interface IResolvedEgressPolicy {
|
|
81
|
+
allow: string[];
|
|
82
|
+
deny: string[];
|
|
83
|
+
allowPrivateNetwork: boolean;
|
|
84
|
+
protocols: ('https' | 'http')[];
|
|
85
|
+
ports: number[];
|
|
86
|
+
methods: string[];
|
|
87
|
+
maxRedirects: number;
|
|
88
|
+
maxResponseBytes: number;
|
|
89
|
+
timeoutMs: number;
|
|
90
|
+
ca?: string | string[];
|
|
91
|
+
lookup: (hostname: string) => Promise<IResolvedAddress[]>;
|
|
92
|
+
}
|
|
93
|
+
declare const resolveEgressPolicy: (policy?: IEgressPolicy) => IResolvedEgressPolicy;
|
|
94
|
+
type AddressClass = 'public' | 'private' | 'never';
|
|
95
|
+
declare const classifyAddress: (address: string) => AddressClass;
|
|
96
|
+
declare const hostMatches: (host: string, pattern: string) => boolean;
|
|
97
|
+
declare const checkEgressUrl: (url: URL, policy: IResolvedEgressPolicy, method?: string) => void;
|
|
98
|
+
declare const checkRedirect: (from: URL, to: URL) => void;
|
|
99
|
+
type SafeFetch = (input: string | URL, init?: RequestInit) => Promise<Response>;
|
|
100
|
+
declare const createSafeFetch: (policy?: IEgressPolicy) => SafeFetch;
|
|
101
|
+
|
|
6
102
|
type ProviderType = 'openai' | 'anthropic' | 'openai-compatible' | 'google' | 'xai' | 'azure' | 'amazon-bedrock' | 'google-vertex' | 'deepseek' | 'gateway' | 'cloudflare';
|
|
7
103
|
type LogLevel = 'none' | 'error' | 'warn' | 'info' | 'debug';
|
|
8
104
|
type ToolSelectionStrategy = 'all' | 'plan-narrowed' | 'search' | 'auto';
|
|
@@ -53,6 +149,26 @@ interface ISkill {
|
|
|
53
149
|
path: string;
|
|
54
150
|
content: string;
|
|
55
151
|
}[];
|
|
152
|
+
origin?: ISkillOrigin;
|
|
153
|
+
}
|
|
154
|
+
interface ISkillOrigin {
|
|
155
|
+
kind: 'learned';
|
|
156
|
+
at: number;
|
|
157
|
+
revision: number;
|
|
158
|
+
runId?: string;
|
|
159
|
+
sources?: string[];
|
|
160
|
+
fetched?: string[];
|
|
161
|
+
}
|
|
162
|
+
interface ISkillStore {
|
|
163
|
+
list: () => ISkill[] | Promise<ISkill[]>;
|
|
164
|
+
save: (skill: ISkill) => void | Promise<void>;
|
|
165
|
+
remove: (name: string) => boolean | Promise<boolean>;
|
|
166
|
+
}
|
|
167
|
+
interface ILearningConfig {
|
|
168
|
+
store?: ISkillStore;
|
|
169
|
+
maxSkills?: number;
|
|
170
|
+
maxSkillChars?: number;
|
|
171
|
+
nudge?: boolean;
|
|
56
172
|
}
|
|
57
173
|
type ToolApprovalMode = 'autopilot' | 'ask-writes' | 'ask-all' | 'read-only';
|
|
58
174
|
type ToolPermission = 'allow' | 'ask' | 'deny';
|
|
@@ -122,6 +238,8 @@ interface IAgentConfig {
|
|
|
122
238
|
/** @deprecated use `synthesizer: { model }` */
|
|
123
239
|
synthesizerModel?: string;
|
|
124
240
|
mcpServers: Record<string, IMcpServerConfig>;
|
|
241
|
+
egress?: boolean | IEgressPolicy;
|
|
242
|
+
learning?: boolean | ILearningConfig;
|
|
125
243
|
tools?: ToolSet;
|
|
126
244
|
availableTools?: string[];
|
|
127
245
|
excludedTools?: string[];
|
|
@@ -191,7 +309,7 @@ interface IStepResult {
|
|
|
191
309
|
blocked: boolean;
|
|
192
310
|
}
|
|
193
311
|
type ReplanTrigger = 'failure' | 'always' | ((result: IStepResult) => boolean | Promise<boolean>);
|
|
194
|
-
type ReplanCause = 'last-step' | 'clean-step' | 'llm-decision';
|
|
312
|
+
type ReplanCause = 'last-step' | 'clean-step' | 'llm-decision' | 'user-message';
|
|
195
313
|
type UsagePhase = 'plan' | 'execute' | 'replan' | 'synthesize' | 'compact' | 'subagent';
|
|
196
314
|
type AgentEventBody = {
|
|
197
315
|
type: 'plan.thought-delta';
|
|
@@ -299,6 +417,7 @@ type AgentEventBody = {
|
|
|
299
417
|
id: string;
|
|
300
418
|
name: string;
|
|
301
419
|
task: string;
|
|
420
|
+
profile?: string;
|
|
302
421
|
} | {
|
|
303
422
|
type: 'subagent.event';
|
|
304
423
|
id: string;
|
|
@@ -315,6 +434,32 @@ type AgentEventBody = {
|
|
|
315
434
|
id: string;
|
|
316
435
|
name: string;
|
|
317
436
|
error: string;
|
|
437
|
+
stopped?: boolean;
|
|
438
|
+
} | {
|
|
439
|
+
type: 'message.queued';
|
|
440
|
+
id: string;
|
|
441
|
+
text: string;
|
|
442
|
+
} | {
|
|
443
|
+
type: 'message.delivered';
|
|
444
|
+
id: string;
|
|
445
|
+
text: string;
|
|
446
|
+
at: 'round' | 'step' | 'final';
|
|
447
|
+
} | {
|
|
448
|
+
type: 'egress.request';
|
|
449
|
+
url: string;
|
|
450
|
+
allowed: boolean;
|
|
451
|
+
status?: number;
|
|
452
|
+
reason?: string;
|
|
453
|
+
} | {
|
|
454
|
+
type: 'skill.learned';
|
|
455
|
+
name: string;
|
|
456
|
+
description: string;
|
|
457
|
+
update: boolean;
|
|
458
|
+
chars: number;
|
|
459
|
+
sources: string[];
|
|
460
|
+
} | {
|
|
461
|
+
type: 'skill.forgotten';
|
|
462
|
+
name: string;
|
|
318
463
|
} | {
|
|
319
464
|
type: 'revisions.exceeded';
|
|
320
465
|
cap: number;
|
|
@@ -339,6 +484,7 @@ interface IAgentRunOptions {
|
|
|
339
484
|
onEvent?: EventHandler;
|
|
340
485
|
onStepStart?: (info: IStepStartInfo) => void;
|
|
341
486
|
resumeFromRunId?: string;
|
|
487
|
+
control?: RunControl;
|
|
342
488
|
}
|
|
343
489
|
interface IAgentRunResult {
|
|
344
490
|
text: string;
|
|
@@ -347,6 +493,7 @@ interface IAgentRunResult {
|
|
|
347
493
|
iterations: number;
|
|
348
494
|
usage: IUsage;
|
|
349
495
|
compactedHistory?: IConversationTurn[];
|
|
496
|
+
undelivered?: string[];
|
|
350
497
|
}
|
|
351
498
|
interface IRunSnapshot {
|
|
352
499
|
runId: string;
|
|
@@ -367,6 +514,10 @@ interface IRunSnapshot {
|
|
|
367
514
|
traceSummaryUpTo?: number;
|
|
368
515
|
activeSkills?: string[];
|
|
369
516
|
toolCallCount?: number;
|
|
517
|
+
userUpdates?: {
|
|
518
|
+
text: string;
|
|
519
|
+
reconciled: boolean;
|
|
520
|
+
}[];
|
|
370
521
|
}
|
|
371
522
|
interface IPersistence {
|
|
372
523
|
onRunStart?: (snapshot: IRunSnapshot) => void | Promise<void>;
|
|
@@ -397,7 +548,10 @@ interface IAgent {
|
|
|
397
548
|
listSkills: () => {
|
|
398
549
|
name: string;
|
|
399
550
|
description: string;
|
|
551
|
+
learned?: true;
|
|
400
552
|
}[];
|
|
553
|
+
listLearnedSkills: () => ISkill[];
|
|
554
|
+
forgetSkill: (name: string) => Promise<boolean>;
|
|
401
555
|
compact: (options: ICompactOptions) => Promise<ICompactResult>;
|
|
402
556
|
setToolApprovalMode: (mode: ToolApprovalMode) => void;
|
|
403
557
|
getToolApprovalMode: () => ToolApprovalMode;
|
|
@@ -764,7 +918,53 @@ interface IClearedInfo {
|
|
|
764
918
|
}
|
|
765
919
|
declare const createToolResultClearer: (opts: IToolResultClearing, onCleared?: (info: IClearedInfo) => void) => ((messages: ModelMessage[]) => ModelMessage[]);
|
|
766
920
|
|
|
921
|
+
declare const SAVE_SKILL_TOOL = "save_skill";
|
|
922
|
+
declare const FORGET_SKILL_TOOL = "forget_skill";
|
|
923
|
+
declare const findSecret: (text: string) => string | undefined;
|
|
924
|
+
declare const normalizeSkillName: (raw: string) => string | undefined;
|
|
925
|
+
declare class MemorySkillStore implements ISkillStore {
|
|
926
|
+
private readonly skills;
|
|
927
|
+
list(): ISkill[];
|
|
928
|
+
save(skill: ISkill): void;
|
|
929
|
+
remove(name: string): boolean;
|
|
930
|
+
}
|
|
931
|
+
declare class DirSkillStore implements ISkillStore {
|
|
932
|
+
private readonly dir;
|
|
933
|
+
constructor(dir: string);
|
|
934
|
+
list(): Promise<ISkill[]>;
|
|
935
|
+
save(skill: ISkill): Promise<void>;
|
|
936
|
+
remove(name: string): Promise<boolean>;
|
|
937
|
+
}
|
|
938
|
+
interface ILearning {
|
|
939
|
+
tools: ToolSet;
|
|
940
|
+
learned: () => ISkill[];
|
|
941
|
+
forget: (name: string) => Promise<boolean>;
|
|
942
|
+
}
|
|
943
|
+
interface ISaveSkillInput {
|
|
944
|
+
name: string;
|
|
945
|
+
description: string;
|
|
946
|
+
instructions: string;
|
|
947
|
+
sources?: string[];
|
|
948
|
+
}
|
|
949
|
+
declare const createLearning: (cfg: ILearningConfig, skills: ISkill[], emit: EventHandler, warn: (message: string) => void) => Promise<ILearning>;
|
|
950
|
+
|
|
951
|
+
declare const WEB_FETCH_TOOL = "web_fetch";
|
|
952
|
+
declare const htmlToText: (html: string) => {
|
|
953
|
+
title?: string;
|
|
954
|
+
text: string;
|
|
955
|
+
};
|
|
956
|
+
interface IWebFetchOptions {
|
|
957
|
+
policy?: IEgressPolicy;
|
|
958
|
+
fetch?: SafeFetch;
|
|
959
|
+
}
|
|
960
|
+
declare const createWebFetchTool: (options?: IWebFetchOptions) => Tool;
|
|
961
|
+
declare const createEgressTools: (egress: boolean | IEgressPolicy | undefined) => ToolSet | undefined;
|
|
962
|
+
|
|
767
963
|
type SubagentIsolation = 'worker' | 'in-process';
|
|
964
|
+
interface ISubagentProfile {
|
|
965
|
+
description: string;
|
|
966
|
+
config?: Partial<IAgentConfig>;
|
|
967
|
+
}
|
|
768
968
|
interface ISubagentToolOptions {
|
|
769
969
|
name: string;
|
|
770
970
|
description: string;
|
|
@@ -775,6 +975,7 @@ interface ISubagentToolOptions {
|
|
|
775
975
|
timeoutMs?: number;
|
|
776
976
|
outputMaxChars?: number;
|
|
777
977
|
readOnly?: boolean;
|
|
978
|
+
profiles?: Record<string, ISubagentProfile>;
|
|
778
979
|
}
|
|
779
980
|
/**
|
|
780
981
|
* Expose a whole agent as ONE tool of a parent agent: input `{ task }`,
|
|
@@ -785,5 +986,5 @@ interface ISubagentToolOptions {
|
|
|
785
986
|
*/
|
|
786
987
|
declare const createSubagentTool: (opts: ISubagentToolOptions) => Tool;
|
|
787
988
|
|
|
788
|
-
export { FileOAuthStore, MemoryOAuthStore, NodeOAuthProvider, SUMMARY_PREFIX, ToolBudgetError, ToolDeniedError, 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 };
|
|
789
|
-
export type { AgentEvent, AgentStage, BudgetKind, EventHandler, IAgent, IAgentConfig, IAgentRunOptions, IAgentRunResult, IAgentStageOverride, IClearedInfo, ICloseOptions, ICompactHistoryOptions, ICompactHistoryResult, ICompactOptions, ICompactResult, ICompactionConfig, IConversationTurn, ILimitBreach, IMcpHttpServerConfig, IMcpServerConfig, IMcpStdioServerConfig, INodeOAuthProviderOptions, IOAuthRequestOptions, IOAuthStore, IPersistence, IPlan, IPlanStep, IResolvedThinking, IRunSnapshot, ISearchToolsOptions, ISkill, IStepResult, IStepStartInfo, ISubagentToolOptions, IThinkingConfig, ITokenLimits, IToolApprovalConfig, IToolApprovalRequest, IToolCatalogEntry, IToolDecision, IToolDecisionInput, IToolResultClearing, IUsage, LogLevel, PromptCachingSetting, ProviderType, ReplanCause, ReplanTrigger, SubagentIsolation, ThinkingLevel, ThinkingSetting, TokenLimitKind, ToolApprovalDecision, ToolApprovalMode, ToolPermission, ToolSelectionStrategy, UsagePhase };
|
|
989
|
+
export { DirSkillStore, EgressError, FORGET_SKILL_TOOL, FileOAuthStore, MemoryOAuthStore, MemorySkillStore, NodeOAuthProvider, SAVE_SKILL_TOOL, SUMMARY_PREFIX, ToolBudgetError, ToolDeniedError, WEB_FETCH_TOOL, addUsage, beginMcpOAuth, buildInstructions, checkEgressUrl, checkLimits, checkRedirect, classifyAddress, compactHistory, createAgent, createEgressTools, createLearning, createNodeOAuthProvider, createRunControl, createSafeFetch, createSubagentTool, createToolResultClearer, createWebFetchTool, decideToolPermission, defineSkill, estimateTokens, findSecret, finishMcpOAuth, getCurrentRunId, getCurrentRunSandbox, hostMatches, htmlToText, isReadOnlyTool, loadSkillsFromDir, markReadOnly, matchToolRule, mergeProviderOptions, normalizeSkillName, normalizeUsage, parseSkillMarkdown, redactHeaders, resolveEgressPolicy, resolveLimits, resolvePromptCaching, resolveThinking, searchTools, truncateToolModelOutput, withRollingBreakpoint, withToolOutputLimit };
|
|
990
|
+
export type { AgentEvent, AgentStage, BudgetKind, EgressErrorCode, EventHandler, IAgent, IAgentConfig, IAgentRunOptions, IAgentRunResult, IAgentStageOverride, IClearedInfo, ICloseOptions, ICompactHistoryOptions, ICompactHistoryResult, ICompactOptions, ICompactResult, ICompactionConfig, IConversationTurn, IEgressPolicy, ILearning, ILearningConfig, ILimitBreach, IMcpHttpServerConfig, IMcpServerConfig, IMcpStdioServerConfig, INodeOAuthProviderOptions, IOAuthRequestOptions, IOAuthStore, IPersistence, IPlan, IPlanStep, IResolvedAddress, IResolvedThinking, IRunSnapshot, ISaveSkillInput, ISearchToolsOptions, ISkill, ISkillOrigin, ISkillStore, IStepResult, IStepStartInfo, ISubagentProfile, ISubagentToolOptions, IThinkingConfig, ITokenLimits, IToolApprovalConfig, IToolApprovalRequest, IToolCatalogEntry, IToolDecision, IToolDecisionInput, IToolResultClearing, IUsage, LogLevel, PromptCachingSetting, ProviderType, ReplanCause, ReplanTrigger, RunControl, SafeFetch, SubagentInfo, SubagentIsolation, ThinkingLevel, ThinkingSetting, TokenLimitKind, ToolApprovalDecision, ToolApprovalMode, ToolPermission, ToolSelectionStrategy, UsagePhase };
|