@ddlqhd/agent-sdk 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -2
- package/dist/{chunk-5QMA2YBY.cjs → chunk-6X7EYQLS.cjs} +782 -114
- package/dist/chunk-6X7EYQLS.cjs.map +1 -0
- package/dist/{chunk-NDSL7NPN.js → chunk-D3UZNLZO.js} +769 -71
- package/dist/chunk-D3UZNLZO.js.map +1 -0
- package/dist/{chunk-Q3SOMX26.js → chunk-EQ5CXH44.js} +772 -111
- package/dist/chunk-EQ5CXH44.js.map +1 -0
- package/dist/chunk-LOYIGOBZ.js +54 -0
- package/dist/chunk-LOYIGOBZ.js.map +1 -0
- package/dist/{chunk-OHXW2YM6.js → chunk-MEJHTQJM.js} +289 -166
- package/dist/chunk-MEJHTQJM.js.map +1 -0
- package/dist/chunk-NYZD3THB.cjs +1521 -0
- package/dist/chunk-NYZD3THB.cjs.map +1 -0
- package/dist/chunk-OZO7D77N.cjs +59 -0
- package/dist/chunk-OZO7D77N.cjs.map +1 -0
- package/dist/{chunk-JF5AJQMU.cjs → chunk-Z45DHTDX.cjs} +291 -170
- package/dist/chunk-Z45DHTDX.cjs.map +1 -0
- package/dist/cli/index.cjs +47 -39
- package/dist/cli/index.cjs.map +1 -1
- package/dist/cli/index.js +22 -14
- package/dist/cli/index.js.map +1 -1
- package/dist/{index-DPsZ1zat.d.ts → index-Cw3SfEAB.d.ts} +20 -34
- package/dist/{index-RTPmFjMp.d.cts → index-D2Qntkn_.d.cts} +20 -34
- package/dist/index.cjs +125 -89
- package/dist/index.d.cts +62 -22
- package/dist/index.d.ts +62 -22
- package/dist/index.js +4 -4
- package/dist/models/index.cjs +19 -15
- package/dist/models/index.d.cts +55 -6
- package/dist/models/index.d.ts +55 -6
- package/dist/models/index.js +2 -2
- package/dist/tools/index.cjs +53 -61
- package/dist/tools/index.d.cts +3 -3
- package/dist/tools/index.d.ts +3 -3
- package/dist/tools/index.js +2 -2
- package/dist/{types-C0aX_Qdp.d.cts → types-CWPAYWzr.d.cts} +307 -61
- package/dist/{types-C0aX_Qdp.d.ts → types-CWPAYWzr.d.ts} +307 -61
- package/package.json +25 -14
- package/dist/chunk-5QMA2YBY.cjs.map +0 -1
- package/dist/chunk-CNSGZVRN.cjs +0 -152
- package/dist/chunk-CNSGZVRN.cjs.map +0 -1
- package/dist/chunk-JF5AJQMU.cjs.map +0 -1
- package/dist/chunk-NDSL7NPN.js.map +0 -1
- package/dist/chunk-OHXW2YM6.js.map +0 -1
- package/dist/chunk-Q3SOMX26.js.map +0 -1
- package/dist/chunk-WH3APNQ5.js +0 -147
- package/dist/chunk-WH3APNQ5.js.map +0 -1
- package/dist/chunk-X35MHWXE.cjs +0 -817
- package/dist/chunk-X35MHWXE.cjs.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { S as StorageConfig, M as Message, a as SessionInfo, b as StorageAdapter, T as ToolResult,
|
|
2
|
-
export {
|
|
3
|
-
import { T as ToolRegistry, S as SkillRegistry } from './index-
|
|
4
|
-
export { C as CreateAgentToolOptions, D as DEFAULT_GREP_HEAD_LIMIT, M as MAX_LINE_LENGTH, a as SkillLoader, b as SkillLoaderConfig, c as SubagentRequest, d as SubagentRunner, e as ToolExecuteOptions, f as ToolRegistryConfig, g as agentTool, h as bashTool, i as createAgentTool, j as createSkillLoader, k as createSkillRegistry, l as createSkillTool, m as createTool, n as editTool, o as getAllBuiltinTools, p as getFileSystemTools, q as getGlobalRegistry, r as getGrepTools, s as
|
|
5
|
-
export { AnthropicAdapter, AnthropicConfig, CreateModelConfig, ModelProvider, OllamaAdapter, OllamaConfig, OpenAIAdapter, OpenAIConfig, createAnthropic, createModel, createOllama, createOpenAI } from './models/index.cjs';
|
|
1
|
+
import { S as StorageConfig, M as Message, a as SessionInfo, b as StorageAdapter, c as MCPServerConfig, T as ToolResult, d as ToolDefinition, A as AgentConfig, e as SystemPrompt, f as StreamEvent, g as AgentResult, h as ModelAdapter, i as SessionTokenUsage, j as SDKLogger, L as LogEvent, k as TokenUsage, l as StreamChunk, P as ParsedSkill, m as MemoryConfig } from './types-CWPAYWzr.cjs';
|
|
2
|
+
export { n as AgentCallbacks, o as AgentErrorContext, p as AgentLifecycleCallbacks, q as AgentModelConfig, r as AgentRunContext, s as AgentRunEndContext, t as AgentRunEndReason, u as AgentRunStartContext, v as AskUserQuestionAnswer, w as AskUserQuestionItem, x as AskUserQuestionResolver, y as AssistantMessage, C as CLIConfig, z as CanUseToolCallback, B as ChatOptions, D as CommandHookConfig, E as CompletionResult, F as ContentPart, G as ContextManagerConfig, H as CreateAskUserQuestionToolOptions, I as FlatCommandHookEntry, J as FunctionHook, K as HookContext, N as HookDecisionContext, O as HookEventType, Q as HookGroupConfig, R as HookManager, U as HookObservationContext, V as HookResult, W as HooksSettings, X as HooksSettingsFile, Y as ImageContent, Z as LogRedactionConfig, _ as MCPOptions, $ as MCPPromptArgument, a0 as MCPResourceContent, a1 as MODEL_STREAM_EVENT_TYPES, a2 as MessageObservationContext, a3 as MessageRole, a4 as ModelCapabilities, a5 as ModelParams, a6 as ModelRequestStartContext, a7 as RunOptions, a8 as SDKLogLevel, a9 as SessionListOptions, aa as SkillConfig, ab as SkillDefinition, ac as SkillMetadata, ad as SkillOptions, ae as StreamChunkType, af as StreamEventAnnotations, ag as StreamEventType, ah as SystemMessage, ai as SystemMessageSource, aj as SystemPromptConfig, ak as TextContent, al as ThinkingContent, am as ToolCall, an as ToolExecutionBaseContext, ao as ToolExecutionContext, ap as ToolExecutionEndContext, aq as ToolExecutionPolicy, ar as ToolHandler, as as ToolHookObserver, at as ToolListOptions, au as ToolMessage, av as ToolResultMetadata, aw as ToolResultObservationContext, ax as ToolSchema, ay as UserMessage, az as UserMessageSource, aA as buildHookEnv, aB as createAskUserQuestionTool, aC as createFunctionHook, aD as formatAnswerSummary, aE as formatAskUserQuestionPrompt, aF as getInteractionTools, aG as isModelStreamEventType, aH as matchTool, aI as mergeCommandHookLayers, aJ as questionTool } from './types-CWPAYWzr.cjs';
|
|
3
|
+
import { T as ToolRegistry, S as SkillRegistry } from './index-D2Qntkn_.cjs';
|
|
4
|
+
export { C as CreateAgentToolOptions, D as DEFAULT_GREP_HEAD_LIMIT, M as MAX_LINE_LENGTH, a as SkillLoader, b as SkillLoaderConfig, c as SubagentRequest, d as SubagentRunner, e as ToolExecuteOptions, f as ToolRegistryConfig, g as agentTool, h as bashTool, i as createAgentTool, j as createSkillLoader, k as createSkillRegistry, l as createSkillTool, m as createTool, n as editTool, o as getAllBuiltinTools, p as getFileSystemTools, q as getGlobalRegistry, r as getGrepTools, s as getPlanningTools, t as getSafeBuiltinTools, u as getShellTools, v as getSkillTools, w as getSubagentTools, x as getWebTools, y as globTool, z as grepTool, A as loadHooksSettingsFromProject, B as loadHooksSettingsFromUser, E as parseHooksSettingsFile, F as readFileTool, G as subagentRequestSchema, H as todoWriteTool, I as truncateMatchLineForDisplay, J as webFetchTool, K as webSearchTool, L as writeFileTool } from './index-D2Qntkn_.cjs';
|
|
5
|
+
export { AnthropicAdapter, AnthropicConfig, AnthropicFetchRetryOptions, CreateModelConfig, DEFAULT_ADAPTER_CAPABILITIES, ModelProvider, OllamaAdapter, OllamaConfig, OpenAIAdapter, OpenAIConfig, createAnthropic, createModel, createOllama, createOpenAI } from './models/index.cjs';
|
|
6
6
|
import 'zod';
|
|
7
7
|
|
|
8
|
+
/** Published package version, read from package root `package.json`. */
|
|
9
|
+
declare const PACKAGE_VERSION: string;
|
|
10
|
+
|
|
8
11
|
/**
|
|
9
12
|
* 会话管理器配置
|
|
10
13
|
*/
|
|
@@ -73,18 +76,6 @@ declare class SessionManager {
|
|
|
73
76
|
*/
|
|
74
77
|
declare function createSessionManager(config?: StorageConfig): SessionManager;
|
|
75
78
|
|
|
76
|
-
interface StdioMCPConfig {
|
|
77
|
-
name: string;
|
|
78
|
-
command: string;
|
|
79
|
-
args?: string[];
|
|
80
|
-
env?: Record<string, string>;
|
|
81
|
-
}
|
|
82
|
-
interface HttpMCPConfig {
|
|
83
|
-
name: string;
|
|
84
|
-
url: string;
|
|
85
|
-
headers?: Record<string, string>;
|
|
86
|
-
}
|
|
87
|
-
type MCPClientConfig = StdioMCPConfig | HttpMCPConfig;
|
|
88
79
|
interface MCPTool {
|
|
89
80
|
name: string;
|
|
90
81
|
description?: string;
|
|
@@ -120,7 +111,7 @@ declare class MCPClient {
|
|
|
120
111
|
private _connected;
|
|
121
112
|
private _tools;
|
|
122
113
|
private _serverInfo?;
|
|
123
|
-
constructor(config:
|
|
114
|
+
constructor(config: MCPServerConfig);
|
|
124
115
|
connect(): Promise<void>;
|
|
125
116
|
disconnect(): Promise<void>;
|
|
126
117
|
listTools(): Promise<MCPTool[]>;
|
|
@@ -139,12 +130,12 @@ declare class MCPClient {
|
|
|
139
130
|
} | undefined;
|
|
140
131
|
get tools(): MCPTool[];
|
|
141
132
|
}
|
|
142
|
-
declare function createMCPClient(config:
|
|
133
|
+
declare function createMCPClient(config: MCPServerConfig): MCPClient;
|
|
143
134
|
|
|
144
135
|
declare class MCPAdapter {
|
|
145
136
|
private clients;
|
|
146
137
|
private toolMap;
|
|
147
|
-
addServer(config:
|
|
138
|
+
addServer(config: MCPServerConfig): Promise<void>;
|
|
148
139
|
removeServer(name: string): Promise<void>;
|
|
149
140
|
getToolDefinitions(): ToolDefinition[];
|
|
150
141
|
executeTool(fullName: string, args: unknown): Promise<ToolResult>;
|
|
@@ -158,6 +149,8 @@ declare class MCPAdapter {
|
|
|
158
149
|
}
|
|
159
150
|
declare function createMCPAdapter(): MCPAdapter;
|
|
160
151
|
|
|
152
|
+
/** Default upper bound for model↔tool rounds per user turn when `AgentConfig.maxIterations` is omitted. */
|
|
153
|
+
declare const DEFAULT_MAX_ITERATIONS = 400;
|
|
161
154
|
/**
|
|
162
155
|
* 流式执行选项
|
|
163
156
|
*/
|
|
@@ -185,7 +178,9 @@ declare class Agent {
|
|
|
185
178
|
private agentDepth;
|
|
186
179
|
private activeSubagentRuns;
|
|
187
180
|
private sessionUsage;
|
|
181
|
+
private static resolveModel;
|
|
188
182
|
constructor(config: AgentConfig);
|
|
183
|
+
private log;
|
|
189
184
|
/**
|
|
190
185
|
* 注册内置 + 自定义工具,或仅 {@link AgentConfig.exclusiveTools}。
|
|
191
186
|
*/
|
|
@@ -204,6 +199,16 @@ declare class Agent {
|
|
|
204
199
|
*/
|
|
205
200
|
private initializeMCP;
|
|
206
201
|
private annotateStreamEvent;
|
|
202
|
+
private baseRunContext;
|
|
203
|
+
/**
|
|
204
|
+
* 分发流式事件到 `callbacks.onEvent` 与 `lifecycle.onModelEvent` / `onModelUsage`。
|
|
205
|
+
*/
|
|
206
|
+
private emitStreamEvent;
|
|
207
|
+
/** 标注、触发观察回调并返回供 `yield` 的事件 */
|
|
208
|
+
private streamOut;
|
|
209
|
+
private emitAgentError;
|
|
210
|
+
private safeLifecycleVoid;
|
|
211
|
+
private emitRunEnd;
|
|
207
212
|
private static createEmptySessionUsage;
|
|
208
213
|
private resetSessionState;
|
|
209
214
|
/**
|
|
@@ -243,6 +248,10 @@ declare class Agent {
|
|
|
243
248
|
* 获取 Skill 注册中心
|
|
244
249
|
*/
|
|
245
250
|
getSkillRegistry(): SkillRegistry;
|
|
251
|
+
/**
|
|
252
|
+
* 解析后的模型适配器(`modelConfig` 已在构造时合并 `env` 并实例化)。
|
|
253
|
+
*/
|
|
254
|
+
getModel(): ModelAdapter;
|
|
246
255
|
/**
|
|
247
256
|
* 处理用户输入,检测并处理 skill 调用
|
|
248
257
|
* @param input 用户输入
|
|
@@ -353,13 +362,28 @@ declare class Agent {
|
|
|
353
362
|
*/
|
|
354
363
|
declare function createAgent(config: AgentConfig): Agent;
|
|
355
364
|
|
|
365
|
+
/**
|
|
366
|
+
* 当前 `process.env` 中值为 string 的键的快照,再叠 `overrides`(后者覆盖同名键)。
|
|
367
|
+
* 供应用层构造 model(如显式传入 `apiKey`)与 Agent 内部合并 MCP stdio 环境共用。
|
|
368
|
+
*
|
|
369
|
+
* 注意:快照包含当前进程 environ 中的敏感变量;传入 MCP 子进程时由调用方控制 `env` / `overrides`。
|
|
370
|
+
*/
|
|
371
|
+
declare function mergeProcessEnv(overrides?: Record<string, string>): Record<string, string>;
|
|
372
|
+
/**
|
|
373
|
+
* stdio MCP 子进程环境:`process.env` + 可选 Agent 级 `env` + 可选单服务 `MCPServerConfig.env`(优先级递增)。
|
|
374
|
+
*/
|
|
375
|
+
declare function mergeMcpStdioEnv(agentEnv?: Record<string, string>, serverEnv?: Record<string, string>): Record<string, string>;
|
|
376
|
+
|
|
356
377
|
/**
|
|
357
378
|
* Agent SDK 默认系统提示词
|
|
358
379
|
*
|
|
359
380
|
* 占位符说明:
|
|
360
381
|
* - {{SKILL_LIST}}: 会被运行时注入的skill列表替换
|
|
361
382
|
*/
|
|
362
|
-
declare const DEFAULT_SYSTEM_PROMPT = "You are an AI assistant powered by the Agent SDK. You can help users with various tasks by using your built-in tools and capabilities.\n\n## Core Capabilities\n\n### Tools\nYou have access to a set of tools that allow you to:\n- **File Operations**: read, write, list, delete files and directories\n- **Code Execution**: run shell commands, Python scripts, Node.js code\n- **Web Access**: make HTTP requests, fetch webpages, download files\n- **Custom Tools**: additional tools registered by the user or skills\n\nWhen to use tools:\n- Use tools when the task requires real-world actions (file I/O, computation, API calls)\n- Prefer reading files before modifying them\n- Use the simplest tool that gets the job done\n- Run multiple independent tool calls in parallel when possible\n\n**Prefer dedicated tools over Bash:** Do not use `Bash` to do work that has a first-class tool. This keeps actions reviewable and consistent.\n- **Read** for file contents \u2014 not `cat`, `head`, `tail`, or `sed` to print files\n- **Write** to create or overwrite files \u2014 not shell redirection or heredocs\n- **Edit** for targeted file changes \u2014 not `sed`, `awk`, or ad-hoc scripts to patch files\n- **Glob** to find paths by pattern \u2014 not `find` or `ls` for discovery\n- **Grep** to search file contents \u2014 not `grep` or `rg` in the shell (built-in line-by-line regex search; correct integration)\n- **WebFetch** / **WebSearch** when the task needs HTTP or web search (when configured)\n\nReserve **Bash** for real shell needs: `git`, package managers, build commands, compilers, and other operations that require a shell or are not covered above.\n\n### Skills\nSkills are instruction guides for specialized tasks. When activated, you receive the skill's full content including any referenced file paths.\n\n{{SKILL_LIST}}\n\n**Usage:**\n- **Listing skills**: When the user asks about available skills (e.g., \"what skills do you have\", \"\u4F60\u6709\u54EA\u4E9B\u6280\u80FD\", \"list your skills\") \u2192 Simply describe the skills listed above. Do NOT activate any skill.\n- **Activating skills**: When the user has a specific task that matches a skill's purpose \u2192 Call `Skill` with the skill name, then follow the returned instructions.\n- After activation, use the provided Base Path to read any referenced files.\n\n### Sessions\n- Conversations are persisted in sessions\n- Use session IDs to maintain context across multiple interactions\n- Previous messages provide important context for current tasks\n\n## Task Execution Principles\n\n1. **Plan First for Complex Tasks**: For multi-step tasks, you MUST call `
|
|
383
|
+
declare const DEFAULT_SYSTEM_PROMPT = "You are an AI assistant powered by the Agent SDK. You can help users with various tasks by using your built-in tools and capabilities.\n\n## Core Capabilities\n\n### Tools\nYou have access to a set of tools that allow you to:\n- **File Operations**: read, write, list, delete files and directories\n- **Code Execution**: run shell commands, Python scripts, Node.js code\n- **Web Access**: make HTTP requests, fetch webpages, download files\n- **Custom Tools**: additional tools registered by the user or skills\n\nWhen to use tools:\n- Use tools when the task requires real-world actions (file I/O, computation, API calls)\n- Prefer reading files before modifying them\n- Use the simplest tool that gets the job done\n- Run multiple independent tool calls in parallel when possible\n\n**Prefer dedicated tools over Bash:** Do not use `Bash` to do work that has a first-class tool. This keeps actions reviewable and consistent.\n- **Read** for file contents \u2014 not `cat`, `head`, `tail`, or `sed` to print files\n- **Write** to create or overwrite files \u2014 not shell redirection or heredocs\n- **Edit** for targeted file changes \u2014 not `sed`, `awk`, or ad-hoc scripts to patch files\n- **Glob** to find paths by pattern \u2014 not `find` or `ls` for discovery\n- **Grep** to search file contents \u2014 not `grep` or `rg` in the shell (built-in line-by-line regex search; correct integration)\n- **WebFetch** / **WebSearch** when the task needs HTTP or web search (when configured)\n- **TodoWrite** for structured multi-step task lists (see **Task Management with Todo List** below)\n\nReserve **Bash** for real shell needs: `git`, package managers, build commands, compilers, and other operations that require a shell or are not covered above.\n\n### Skills\nSkills are instruction guides for specialized tasks. When activated, you receive the skill's full content including any referenced file paths.\n\n{{SKILL_LIST}}\n\n**Usage:**\n- **Listing skills**: When the user asks about available skills (e.g., \"what skills do you have\", \"\u4F60\u6709\u54EA\u4E9B\u6280\u80FD\", \"list your skills\") \u2192 Simply describe the skills listed above. Do NOT activate any skill.\n- **Activating skills**: When the user has a specific task that matches a skill's purpose \u2192 Call `Skill` with the skill name, then follow the returned instructions.\n- After activation, use the provided Base Path to read any referenced files.\n\n### Sessions\n- Conversations are persisted in sessions\n- Use session IDs to maintain context across multiple interactions\n- Previous messages provide important context for current tasks\n\n## Task Execution Principles\n\n1. **Plan First for Complex Tasks**: For multi-step tasks, you MUST call `TodoWrite` BEFORE any other tool. Do NOT skip this step.\n2. **Be Direct**: Go straight to the point. Try the simplest approach first.\n3. **Be Concise**: If you can say it in one sentence, don't use three.\n4. **Read Before Modify**: Always understand existing code before changing it.\n5. **No Over-Engineering**: Only make changes directly requested or clearly necessary.\n6. **Prefer Edit Over Create**: Modify existing files rather than creating new ones when appropriate.\n7. **Handle Errors Gracefully**: Report errors clearly with actionable suggestions.\n\n## Task Management with Todo List\n\n**MANDATORY**: For multi-step tasks, call `TodoWrite` FIRST.\n\n**Workflow:**\n1. Receive complex task -> call `TodoWrite` immediately\n2. Mark tasks `in_progress` / `completed` as you work; several items may be `in_progress` at once when work is parallel\n3. **Replan freely:** if the plan was wrong or incomplete, call `TodoWrite` again with a revised full list (add, remove, reorder, or rewrite steps)\n4. **Before you finish your response** for a multi-step request, ensure **every** todo is `completed` via `TodoWrite` (unless you intentionally pause for a follow-up turn). Do not leave `pending` / `in_progress` items when the work is done\n\n**Example:**\nUser: \"Open Google, search X, summarize results, open first link, extract info\"\n-> Multi-step task detected -> call `TodoWrite` FIRST, then execute.\n\n## Output Format\n\n- Lead with the answer or action, not the reasoning\n- Skip filler words and unnecessary preamble\n- Use code blocks with language hints for code\n- Structure longer responses with headers and lists\n- Reference file paths with line numbers when relevant (e.g., `src/index.ts:42`)\n\n## Security Guidelines\n\n- Do not introduce security vulnerabilities (injection, XSS, etc.)\n- Validate user inputs at boundaries\n- Do not execute untrusted code without sandboxing\n- Respect file system permissions and access controls\n\n### High-risk actions (confirm with the user first)\n\nThere is no automatic approval UI: **ask in the conversation** (or use `AskUserQuestion`) before proceeding when an action is destructive, hard to reverse, or affects others. Examples:\n- Deleting files or branches, dropping data, `rm -rf`, overwriting uncommitted work\n- Hard-to-reverse git: force-push, `reset --hard`, rewriting published history, amending shared commits\n- Actions visible outside this machine: pushing code, opening/closing/commenting on PRs or issues, sending messages, posting to external services, changing shared CI/CD or cloud permissions\n- Broad dependency or infrastructure changes (e.g. major version bumps, lockfile rewrites) when impact is unclear\n\nDefault to explaining what you intend and getting explicit agreement unless the user already directed that exact action.\n\n## Tool hooks\n\nWhen hooks are configured (e.g. PreToolUse), a tool call may be **blocked** or its **inputs adjusted** before execution. If a tool fails with a message indicating a hook blocked or rejected the call, **do not** retry the identical tool call unchanged \u2014 read the reason, change your approach, or ask the user. Treat hook feedback as binding policy from the environment.\n\n## Interaction Style\n\n- Be helpful and proactive\n- Ask clarifying questions when instructions are ambiguous\n- Provide suggestions when you see opportunities for improvement\n- Acknowledge limitations honestly\n- Maintain a professional, friendly tone";
|
|
384
|
+
|
|
385
|
+
declare function formatSDKLog(event: LogEvent): string;
|
|
386
|
+
declare function createConsoleSDKLogger(): SDKLogger;
|
|
363
387
|
|
|
364
388
|
/**
|
|
365
389
|
* Same directory as {@link Agent} session storage: `<userBase>/.claude/sessions`.
|
|
@@ -562,6 +586,8 @@ declare function fromAsyncIterable(iterable: AsyncIterable<StreamEvent>): AgentS
|
|
|
562
586
|
interface StreamChunkProcessorOptions {
|
|
563
587
|
/** Emit `text_start` / `text_end` around assistant text deltas (Claude-style content blocks). Default true. */
|
|
564
588
|
emitTextBoundaries?: boolean;
|
|
589
|
+
/** Emit `thinking_start` / `thinking_end` around assistant thinking deltas. Default true. */
|
|
590
|
+
emitThinkingBoundaries?: boolean;
|
|
565
591
|
}
|
|
566
592
|
/**
|
|
567
593
|
* Stateful conversion from model `StreamChunk` to normalized `StreamEvent`s.
|
|
@@ -571,7 +597,9 @@ declare class StreamChunkProcessor {
|
|
|
571
597
|
private currentToolCall;
|
|
572
598
|
private lastUsage;
|
|
573
599
|
private inTextBlock;
|
|
600
|
+
private inThinkingBlock;
|
|
574
601
|
private readonly emitTextBoundaries;
|
|
602
|
+
private readonly emitThinkingBoundaries;
|
|
575
603
|
constructor(options?: StreamChunkProcessorOptions);
|
|
576
604
|
processChunk(chunk: StreamChunk): StreamEvent[];
|
|
577
605
|
/** End open text block and finalize any in-progress streamed tool call. */
|
|
@@ -581,6 +609,16 @@ declare class StreamChunkProcessor {
|
|
|
581
609
|
private safeParseJSON;
|
|
582
610
|
}
|
|
583
611
|
|
|
612
|
+
/**
|
|
613
|
+
* Builds the Agent-facing tool name for an MCP tool: `mcp__<serverName>__<toolName>`.
|
|
614
|
+
* Avoid `__` inside `serverName` or `toolName`; those segments are not escaped and would make parsing ambiguous.
|
|
615
|
+
*/
|
|
616
|
+
declare function formatMcpToolName(serverName: string, toolName: string): string;
|
|
617
|
+
/**
|
|
618
|
+
* True if `name` matches the MCP-prefixed tool naming convention (at least `mcp__<server>__<tool>`).
|
|
619
|
+
*/
|
|
620
|
+
declare function isMcpPrefixedToolName(name: string): boolean;
|
|
621
|
+
|
|
584
622
|
/**
|
|
585
623
|
* 解析 SKILL.md 文件
|
|
586
624
|
* 格式:
|
|
@@ -632,6 +670,8 @@ interface MCPConfigFile {
|
|
|
632
670
|
args?: string[];
|
|
633
671
|
/** 环境变量 */
|
|
634
672
|
env?: Record<string, string>;
|
|
673
|
+
/** stdio 子进程工作目录 */
|
|
674
|
+
cwd?: string;
|
|
635
675
|
/** URL (HTTP transport) */
|
|
636
676
|
url?: string;
|
|
637
677
|
/** HTTP headers */
|
|
@@ -661,4 +701,4 @@ declare function loadMCPConfig(configPath?: string, startDir?: string, userBaseP
|
|
|
661
701
|
*/
|
|
662
702
|
declare function validateMCPConfig(config: MCPConfigFile): string[];
|
|
663
703
|
|
|
664
|
-
export { Agent, AgentConfig, AgentResult, AgentStream,
|
|
704
|
+
export { Agent, AgentConfig, AgentResult, AgentStream, DEFAULT_MAX_ITERATIONS, DEFAULT_SYSTEM_PROMPT, JsonlStorage, LogEvent, MCPAdapter, MCPClient, type MCPConfigFile, type MCPConfigLoadResult, type MCPPrompt, type MCPResource, MCPServerConfig, type MCPTool, MemoryConfig, MemoryManager, MemoryStorage, Message, ModelAdapter, PACKAGE_VERSION, ParsedSkill, type PromptMessage, SDKLogger, SessionInfo, SessionManager, SessionTokenUsage, SkillRegistry, StorageAdapter, StorageConfig, StreamChunk, StreamChunkProcessor, type StreamChunkProcessorOptions, StreamEvent, type StreamOptions, SystemPrompt, TokenUsage, ToolDefinition, ToolRegistry, ToolResult, createAgent, createConsoleSDKLogger, createJsonlStorage, createMCPAdapter, createMCPClient, createMemoryStorage, createSessionManager, createStorage, createStream, formatMcpToolName, formatSDKLog, fromAsyncIterable, getLatestSessionId, getSessionStoragePath, isMcpPrefixedToolName, loadMCPConfig, mergeMcpStdioEnv, mergeProcessEnv, parseSkillMd, validateMCPConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
-
import { S as StorageConfig, M as Message, a as SessionInfo, b as StorageAdapter, T as ToolResult,
|
|
2
|
-
export {
|
|
3
|
-
import { T as ToolRegistry, S as SkillRegistry } from './index-
|
|
4
|
-
export { C as CreateAgentToolOptions, D as DEFAULT_GREP_HEAD_LIMIT, M as MAX_LINE_LENGTH, a as SkillLoader, b as SkillLoaderConfig, c as SubagentRequest, d as SubagentRunner, e as ToolExecuteOptions, f as ToolRegistryConfig, g as agentTool, h as bashTool, i as createAgentTool, j as createSkillLoader, k as createSkillRegistry, l as createSkillTool, m as createTool, n as editTool, o as getAllBuiltinTools, p as getFileSystemTools, q as getGlobalRegistry, r as getGrepTools, s as
|
|
5
|
-
export { AnthropicAdapter, AnthropicConfig, CreateModelConfig, ModelProvider, OllamaAdapter, OllamaConfig, OpenAIAdapter, OpenAIConfig, createAnthropic, createModel, createOllama, createOpenAI } from './models/index.js';
|
|
1
|
+
import { S as StorageConfig, M as Message, a as SessionInfo, b as StorageAdapter, c as MCPServerConfig, T as ToolResult, d as ToolDefinition, A as AgentConfig, e as SystemPrompt, f as StreamEvent, g as AgentResult, h as ModelAdapter, i as SessionTokenUsage, j as SDKLogger, L as LogEvent, k as TokenUsage, l as StreamChunk, P as ParsedSkill, m as MemoryConfig } from './types-CWPAYWzr.js';
|
|
2
|
+
export { n as AgentCallbacks, o as AgentErrorContext, p as AgentLifecycleCallbacks, q as AgentModelConfig, r as AgentRunContext, s as AgentRunEndContext, t as AgentRunEndReason, u as AgentRunStartContext, v as AskUserQuestionAnswer, w as AskUserQuestionItem, x as AskUserQuestionResolver, y as AssistantMessage, C as CLIConfig, z as CanUseToolCallback, B as ChatOptions, D as CommandHookConfig, E as CompletionResult, F as ContentPart, G as ContextManagerConfig, H as CreateAskUserQuestionToolOptions, I as FlatCommandHookEntry, J as FunctionHook, K as HookContext, N as HookDecisionContext, O as HookEventType, Q as HookGroupConfig, R as HookManager, U as HookObservationContext, V as HookResult, W as HooksSettings, X as HooksSettingsFile, Y as ImageContent, Z as LogRedactionConfig, _ as MCPOptions, $ as MCPPromptArgument, a0 as MCPResourceContent, a1 as MODEL_STREAM_EVENT_TYPES, a2 as MessageObservationContext, a3 as MessageRole, a4 as ModelCapabilities, a5 as ModelParams, a6 as ModelRequestStartContext, a7 as RunOptions, a8 as SDKLogLevel, a9 as SessionListOptions, aa as SkillConfig, ab as SkillDefinition, ac as SkillMetadata, ad as SkillOptions, ae as StreamChunkType, af as StreamEventAnnotations, ag as StreamEventType, ah as SystemMessage, ai as SystemMessageSource, aj as SystemPromptConfig, ak as TextContent, al as ThinkingContent, am as ToolCall, an as ToolExecutionBaseContext, ao as ToolExecutionContext, ap as ToolExecutionEndContext, aq as ToolExecutionPolicy, ar as ToolHandler, as as ToolHookObserver, at as ToolListOptions, au as ToolMessage, av as ToolResultMetadata, aw as ToolResultObservationContext, ax as ToolSchema, ay as UserMessage, az as UserMessageSource, aA as buildHookEnv, aB as createAskUserQuestionTool, aC as createFunctionHook, aD as formatAnswerSummary, aE as formatAskUserQuestionPrompt, aF as getInteractionTools, aG as isModelStreamEventType, aH as matchTool, aI as mergeCommandHookLayers, aJ as questionTool } from './types-CWPAYWzr.js';
|
|
3
|
+
import { T as ToolRegistry, S as SkillRegistry } from './index-Cw3SfEAB.js';
|
|
4
|
+
export { C as CreateAgentToolOptions, D as DEFAULT_GREP_HEAD_LIMIT, M as MAX_LINE_LENGTH, a as SkillLoader, b as SkillLoaderConfig, c as SubagentRequest, d as SubagentRunner, e as ToolExecuteOptions, f as ToolRegistryConfig, g as agentTool, h as bashTool, i as createAgentTool, j as createSkillLoader, k as createSkillRegistry, l as createSkillTool, m as createTool, n as editTool, o as getAllBuiltinTools, p as getFileSystemTools, q as getGlobalRegistry, r as getGrepTools, s as getPlanningTools, t as getSafeBuiltinTools, u as getShellTools, v as getSkillTools, w as getSubagentTools, x as getWebTools, y as globTool, z as grepTool, A as loadHooksSettingsFromProject, B as loadHooksSettingsFromUser, E as parseHooksSettingsFile, F as readFileTool, G as subagentRequestSchema, H as todoWriteTool, I as truncateMatchLineForDisplay, J as webFetchTool, K as webSearchTool, L as writeFileTool } from './index-Cw3SfEAB.js';
|
|
5
|
+
export { AnthropicAdapter, AnthropicConfig, AnthropicFetchRetryOptions, CreateModelConfig, DEFAULT_ADAPTER_CAPABILITIES, ModelProvider, OllamaAdapter, OllamaConfig, OpenAIAdapter, OpenAIConfig, createAnthropic, createModel, createOllama, createOpenAI } from './models/index.js';
|
|
6
6
|
import 'zod';
|
|
7
7
|
|
|
8
|
+
/** Published package version, read from package root `package.json`. */
|
|
9
|
+
declare const PACKAGE_VERSION: string;
|
|
10
|
+
|
|
8
11
|
/**
|
|
9
12
|
* 会话管理器配置
|
|
10
13
|
*/
|
|
@@ -73,18 +76,6 @@ declare class SessionManager {
|
|
|
73
76
|
*/
|
|
74
77
|
declare function createSessionManager(config?: StorageConfig): SessionManager;
|
|
75
78
|
|
|
76
|
-
interface StdioMCPConfig {
|
|
77
|
-
name: string;
|
|
78
|
-
command: string;
|
|
79
|
-
args?: string[];
|
|
80
|
-
env?: Record<string, string>;
|
|
81
|
-
}
|
|
82
|
-
interface HttpMCPConfig {
|
|
83
|
-
name: string;
|
|
84
|
-
url: string;
|
|
85
|
-
headers?: Record<string, string>;
|
|
86
|
-
}
|
|
87
|
-
type MCPClientConfig = StdioMCPConfig | HttpMCPConfig;
|
|
88
79
|
interface MCPTool {
|
|
89
80
|
name: string;
|
|
90
81
|
description?: string;
|
|
@@ -120,7 +111,7 @@ declare class MCPClient {
|
|
|
120
111
|
private _connected;
|
|
121
112
|
private _tools;
|
|
122
113
|
private _serverInfo?;
|
|
123
|
-
constructor(config:
|
|
114
|
+
constructor(config: MCPServerConfig);
|
|
124
115
|
connect(): Promise<void>;
|
|
125
116
|
disconnect(): Promise<void>;
|
|
126
117
|
listTools(): Promise<MCPTool[]>;
|
|
@@ -139,12 +130,12 @@ declare class MCPClient {
|
|
|
139
130
|
} | undefined;
|
|
140
131
|
get tools(): MCPTool[];
|
|
141
132
|
}
|
|
142
|
-
declare function createMCPClient(config:
|
|
133
|
+
declare function createMCPClient(config: MCPServerConfig): MCPClient;
|
|
143
134
|
|
|
144
135
|
declare class MCPAdapter {
|
|
145
136
|
private clients;
|
|
146
137
|
private toolMap;
|
|
147
|
-
addServer(config:
|
|
138
|
+
addServer(config: MCPServerConfig): Promise<void>;
|
|
148
139
|
removeServer(name: string): Promise<void>;
|
|
149
140
|
getToolDefinitions(): ToolDefinition[];
|
|
150
141
|
executeTool(fullName: string, args: unknown): Promise<ToolResult>;
|
|
@@ -158,6 +149,8 @@ declare class MCPAdapter {
|
|
|
158
149
|
}
|
|
159
150
|
declare function createMCPAdapter(): MCPAdapter;
|
|
160
151
|
|
|
152
|
+
/** Default upper bound for model↔tool rounds per user turn when `AgentConfig.maxIterations` is omitted. */
|
|
153
|
+
declare const DEFAULT_MAX_ITERATIONS = 400;
|
|
161
154
|
/**
|
|
162
155
|
* 流式执行选项
|
|
163
156
|
*/
|
|
@@ -185,7 +178,9 @@ declare class Agent {
|
|
|
185
178
|
private agentDepth;
|
|
186
179
|
private activeSubagentRuns;
|
|
187
180
|
private sessionUsage;
|
|
181
|
+
private static resolveModel;
|
|
188
182
|
constructor(config: AgentConfig);
|
|
183
|
+
private log;
|
|
189
184
|
/**
|
|
190
185
|
* 注册内置 + 自定义工具,或仅 {@link AgentConfig.exclusiveTools}。
|
|
191
186
|
*/
|
|
@@ -204,6 +199,16 @@ declare class Agent {
|
|
|
204
199
|
*/
|
|
205
200
|
private initializeMCP;
|
|
206
201
|
private annotateStreamEvent;
|
|
202
|
+
private baseRunContext;
|
|
203
|
+
/**
|
|
204
|
+
* 分发流式事件到 `callbacks.onEvent` 与 `lifecycle.onModelEvent` / `onModelUsage`。
|
|
205
|
+
*/
|
|
206
|
+
private emitStreamEvent;
|
|
207
|
+
/** 标注、触发观察回调并返回供 `yield` 的事件 */
|
|
208
|
+
private streamOut;
|
|
209
|
+
private emitAgentError;
|
|
210
|
+
private safeLifecycleVoid;
|
|
211
|
+
private emitRunEnd;
|
|
207
212
|
private static createEmptySessionUsage;
|
|
208
213
|
private resetSessionState;
|
|
209
214
|
/**
|
|
@@ -243,6 +248,10 @@ declare class Agent {
|
|
|
243
248
|
* 获取 Skill 注册中心
|
|
244
249
|
*/
|
|
245
250
|
getSkillRegistry(): SkillRegistry;
|
|
251
|
+
/**
|
|
252
|
+
* 解析后的模型适配器(`modelConfig` 已在构造时合并 `env` 并实例化)。
|
|
253
|
+
*/
|
|
254
|
+
getModel(): ModelAdapter;
|
|
246
255
|
/**
|
|
247
256
|
* 处理用户输入,检测并处理 skill 调用
|
|
248
257
|
* @param input 用户输入
|
|
@@ -353,13 +362,28 @@ declare class Agent {
|
|
|
353
362
|
*/
|
|
354
363
|
declare function createAgent(config: AgentConfig): Agent;
|
|
355
364
|
|
|
365
|
+
/**
|
|
366
|
+
* 当前 `process.env` 中值为 string 的键的快照,再叠 `overrides`(后者覆盖同名键)。
|
|
367
|
+
* 供应用层构造 model(如显式传入 `apiKey`)与 Agent 内部合并 MCP stdio 环境共用。
|
|
368
|
+
*
|
|
369
|
+
* 注意:快照包含当前进程 environ 中的敏感变量;传入 MCP 子进程时由调用方控制 `env` / `overrides`。
|
|
370
|
+
*/
|
|
371
|
+
declare function mergeProcessEnv(overrides?: Record<string, string>): Record<string, string>;
|
|
372
|
+
/**
|
|
373
|
+
* stdio MCP 子进程环境:`process.env` + 可选 Agent 级 `env` + 可选单服务 `MCPServerConfig.env`(优先级递增)。
|
|
374
|
+
*/
|
|
375
|
+
declare function mergeMcpStdioEnv(agentEnv?: Record<string, string>, serverEnv?: Record<string, string>): Record<string, string>;
|
|
376
|
+
|
|
356
377
|
/**
|
|
357
378
|
* Agent SDK 默认系统提示词
|
|
358
379
|
*
|
|
359
380
|
* 占位符说明:
|
|
360
381
|
* - {{SKILL_LIST}}: 会被运行时注入的skill列表替换
|
|
361
382
|
*/
|
|
362
|
-
declare const DEFAULT_SYSTEM_PROMPT = "You are an AI assistant powered by the Agent SDK. You can help users with various tasks by using your built-in tools and capabilities.\n\n## Core Capabilities\n\n### Tools\nYou have access to a set of tools that allow you to:\n- **File Operations**: read, write, list, delete files and directories\n- **Code Execution**: run shell commands, Python scripts, Node.js code\n- **Web Access**: make HTTP requests, fetch webpages, download files\n- **Custom Tools**: additional tools registered by the user or skills\n\nWhen to use tools:\n- Use tools when the task requires real-world actions (file I/O, computation, API calls)\n- Prefer reading files before modifying them\n- Use the simplest tool that gets the job done\n- Run multiple independent tool calls in parallel when possible\n\n**Prefer dedicated tools over Bash:** Do not use `Bash` to do work that has a first-class tool. This keeps actions reviewable and consistent.\n- **Read** for file contents \u2014 not `cat`, `head`, `tail`, or `sed` to print files\n- **Write** to create or overwrite files \u2014 not shell redirection or heredocs\n- **Edit** for targeted file changes \u2014 not `sed`, `awk`, or ad-hoc scripts to patch files\n- **Glob** to find paths by pattern \u2014 not `find` or `ls` for discovery\n- **Grep** to search file contents \u2014 not `grep` or `rg` in the shell (built-in line-by-line regex search; correct integration)\n- **WebFetch** / **WebSearch** when the task needs HTTP or web search (when configured)\n\nReserve **Bash** for real shell needs: `git`, package managers, build commands, compilers, and other operations that require a shell or are not covered above.\n\n### Skills\nSkills are instruction guides for specialized tasks. When activated, you receive the skill's full content including any referenced file paths.\n\n{{SKILL_LIST}}\n\n**Usage:**\n- **Listing skills**: When the user asks about available skills (e.g., \"what skills do you have\", \"\u4F60\u6709\u54EA\u4E9B\u6280\u80FD\", \"list your skills\") \u2192 Simply describe the skills listed above. Do NOT activate any skill.\n- **Activating skills**: When the user has a specific task that matches a skill's purpose \u2192 Call `Skill` with the skill name, then follow the returned instructions.\n- After activation, use the provided Base Path to read any referenced files.\n\n### Sessions\n- Conversations are persisted in sessions\n- Use session IDs to maintain context across multiple interactions\n- Previous messages provide important context for current tasks\n\n## Task Execution Principles\n\n1. **Plan First for Complex Tasks**: For multi-step tasks, you MUST call `
|
|
383
|
+
declare const DEFAULT_SYSTEM_PROMPT = "You are an AI assistant powered by the Agent SDK. You can help users with various tasks by using your built-in tools and capabilities.\n\n## Core Capabilities\n\n### Tools\nYou have access to a set of tools that allow you to:\n- **File Operations**: read, write, list, delete files and directories\n- **Code Execution**: run shell commands, Python scripts, Node.js code\n- **Web Access**: make HTTP requests, fetch webpages, download files\n- **Custom Tools**: additional tools registered by the user or skills\n\nWhen to use tools:\n- Use tools when the task requires real-world actions (file I/O, computation, API calls)\n- Prefer reading files before modifying them\n- Use the simplest tool that gets the job done\n- Run multiple independent tool calls in parallel when possible\n\n**Prefer dedicated tools over Bash:** Do not use `Bash` to do work that has a first-class tool. This keeps actions reviewable and consistent.\n- **Read** for file contents \u2014 not `cat`, `head`, `tail`, or `sed` to print files\n- **Write** to create or overwrite files \u2014 not shell redirection or heredocs\n- **Edit** for targeted file changes \u2014 not `sed`, `awk`, or ad-hoc scripts to patch files\n- **Glob** to find paths by pattern \u2014 not `find` or `ls` for discovery\n- **Grep** to search file contents \u2014 not `grep` or `rg` in the shell (built-in line-by-line regex search; correct integration)\n- **WebFetch** / **WebSearch** when the task needs HTTP or web search (when configured)\n- **TodoWrite** for structured multi-step task lists (see **Task Management with Todo List** below)\n\nReserve **Bash** for real shell needs: `git`, package managers, build commands, compilers, and other operations that require a shell or are not covered above.\n\n### Skills\nSkills are instruction guides for specialized tasks. When activated, you receive the skill's full content including any referenced file paths.\n\n{{SKILL_LIST}}\n\n**Usage:**\n- **Listing skills**: When the user asks about available skills (e.g., \"what skills do you have\", \"\u4F60\u6709\u54EA\u4E9B\u6280\u80FD\", \"list your skills\") \u2192 Simply describe the skills listed above. Do NOT activate any skill.\n- **Activating skills**: When the user has a specific task that matches a skill's purpose \u2192 Call `Skill` with the skill name, then follow the returned instructions.\n- After activation, use the provided Base Path to read any referenced files.\n\n### Sessions\n- Conversations are persisted in sessions\n- Use session IDs to maintain context across multiple interactions\n- Previous messages provide important context for current tasks\n\n## Task Execution Principles\n\n1. **Plan First for Complex Tasks**: For multi-step tasks, you MUST call `TodoWrite` BEFORE any other tool. Do NOT skip this step.\n2. **Be Direct**: Go straight to the point. Try the simplest approach first.\n3. **Be Concise**: If you can say it in one sentence, don't use three.\n4. **Read Before Modify**: Always understand existing code before changing it.\n5. **No Over-Engineering**: Only make changes directly requested or clearly necessary.\n6. **Prefer Edit Over Create**: Modify existing files rather than creating new ones when appropriate.\n7. **Handle Errors Gracefully**: Report errors clearly with actionable suggestions.\n\n## Task Management with Todo List\n\n**MANDATORY**: For multi-step tasks, call `TodoWrite` FIRST.\n\n**Workflow:**\n1. Receive complex task -> call `TodoWrite` immediately\n2. Mark tasks `in_progress` / `completed` as you work; several items may be `in_progress` at once when work is parallel\n3. **Replan freely:** if the plan was wrong or incomplete, call `TodoWrite` again with a revised full list (add, remove, reorder, or rewrite steps)\n4. **Before you finish your response** for a multi-step request, ensure **every** todo is `completed` via `TodoWrite` (unless you intentionally pause for a follow-up turn). Do not leave `pending` / `in_progress` items when the work is done\n\n**Example:**\nUser: \"Open Google, search X, summarize results, open first link, extract info\"\n-> Multi-step task detected -> call `TodoWrite` FIRST, then execute.\n\n## Output Format\n\n- Lead with the answer or action, not the reasoning\n- Skip filler words and unnecessary preamble\n- Use code blocks with language hints for code\n- Structure longer responses with headers and lists\n- Reference file paths with line numbers when relevant (e.g., `src/index.ts:42`)\n\n## Security Guidelines\n\n- Do not introduce security vulnerabilities (injection, XSS, etc.)\n- Validate user inputs at boundaries\n- Do not execute untrusted code without sandboxing\n- Respect file system permissions and access controls\n\n### High-risk actions (confirm with the user first)\n\nThere is no automatic approval UI: **ask in the conversation** (or use `AskUserQuestion`) before proceeding when an action is destructive, hard to reverse, or affects others. Examples:\n- Deleting files or branches, dropping data, `rm -rf`, overwriting uncommitted work\n- Hard-to-reverse git: force-push, `reset --hard`, rewriting published history, amending shared commits\n- Actions visible outside this machine: pushing code, opening/closing/commenting on PRs or issues, sending messages, posting to external services, changing shared CI/CD or cloud permissions\n- Broad dependency or infrastructure changes (e.g. major version bumps, lockfile rewrites) when impact is unclear\n\nDefault to explaining what you intend and getting explicit agreement unless the user already directed that exact action.\n\n## Tool hooks\n\nWhen hooks are configured (e.g. PreToolUse), a tool call may be **blocked** or its **inputs adjusted** before execution. If a tool fails with a message indicating a hook blocked or rejected the call, **do not** retry the identical tool call unchanged \u2014 read the reason, change your approach, or ask the user. Treat hook feedback as binding policy from the environment.\n\n## Interaction Style\n\n- Be helpful and proactive\n- Ask clarifying questions when instructions are ambiguous\n- Provide suggestions when you see opportunities for improvement\n- Acknowledge limitations honestly\n- Maintain a professional, friendly tone";
|
|
384
|
+
|
|
385
|
+
declare function formatSDKLog(event: LogEvent): string;
|
|
386
|
+
declare function createConsoleSDKLogger(): SDKLogger;
|
|
363
387
|
|
|
364
388
|
/**
|
|
365
389
|
* Same directory as {@link Agent} session storage: `<userBase>/.claude/sessions`.
|
|
@@ -562,6 +586,8 @@ declare function fromAsyncIterable(iterable: AsyncIterable<StreamEvent>): AgentS
|
|
|
562
586
|
interface StreamChunkProcessorOptions {
|
|
563
587
|
/** Emit `text_start` / `text_end` around assistant text deltas (Claude-style content blocks). Default true. */
|
|
564
588
|
emitTextBoundaries?: boolean;
|
|
589
|
+
/** Emit `thinking_start` / `thinking_end` around assistant thinking deltas. Default true. */
|
|
590
|
+
emitThinkingBoundaries?: boolean;
|
|
565
591
|
}
|
|
566
592
|
/**
|
|
567
593
|
* Stateful conversion from model `StreamChunk` to normalized `StreamEvent`s.
|
|
@@ -571,7 +597,9 @@ declare class StreamChunkProcessor {
|
|
|
571
597
|
private currentToolCall;
|
|
572
598
|
private lastUsage;
|
|
573
599
|
private inTextBlock;
|
|
600
|
+
private inThinkingBlock;
|
|
574
601
|
private readonly emitTextBoundaries;
|
|
602
|
+
private readonly emitThinkingBoundaries;
|
|
575
603
|
constructor(options?: StreamChunkProcessorOptions);
|
|
576
604
|
processChunk(chunk: StreamChunk): StreamEvent[];
|
|
577
605
|
/** End open text block and finalize any in-progress streamed tool call. */
|
|
@@ -581,6 +609,16 @@ declare class StreamChunkProcessor {
|
|
|
581
609
|
private safeParseJSON;
|
|
582
610
|
}
|
|
583
611
|
|
|
612
|
+
/**
|
|
613
|
+
* Builds the Agent-facing tool name for an MCP tool: `mcp__<serverName>__<toolName>`.
|
|
614
|
+
* Avoid `__` inside `serverName` or `toolName`; those segments are not escaped and would make parsing ambiguous.
|
|
615
|
+
*/
|
|
616
|
+
declare function formatMcpToolName(serverName: string, toolName: string): string;
|
|
617
|
+
/**
|
|
618
|
+
* True if `name` matches the MCP-prefixed tool naming convention (at least `mcp__<server>__<tool>`).
|
|
619
|
+
*/
|
|
620
|
+
declare function isMcpPrefixedToolName(name: string): boolean;
|
|
621
|
+
|
|
584
622
|
/**
|
|
585
623
|
* 解析 SKILL.md 文件
|
|
586
624
|
* 格式:
|
|
@@ -632,6 +670,8 @@ interface MCPConfigFile {
|
|
|
632
670
|
args?: string[];
|
|
633
671
|
/** 环境变量 */
|
|
634
672
|
env?: Record<string, string>;
|
|
673
|
+
/** stdio 子进程工作目录 */
|
|
674
|
+
cwd?: string;
|
|
635
675
|
/** URL (HTTP transport) */
|
|
636
676
|
url?: string;
|
|
637
677
|
/** HTTP headers */
|
|
@@ -661,4 +701,4 @@ declare function loadMCPConfig(configPath?: string, startDir?: string, userBaseP
|
|
|
661
701
|
*/
|
|
662
702
|
declare function validateMCPConfig(config: MCPConfigFile): string[];
|
|
663
703
|
|
|
664
|
-
export { Agent, AgentConfig, AgentResult, AgentStream,
|
|
704
|
+
export { Agent, AgentConfig, AgentResult, AgentStream, DEFAULT_MAX_ITERATIONS, DEFAULT_SYSTEM_PROMPT, JsonlStorage, LogEvent, MCPAdapter, MCPClient, type MCPConfigFile, type MCPConfigLoadResult, type MCPPrompt, type MCPResource, MCPServerConfig, type MCPTool, MemoryConfig, MemoryManager, MemoryStorage, Message, ModelAdapter, PACKAGE_VERSION, ParsedSkill, type PromptMessage, SDKLogger, SessionInfo, SessionManager, SessionTokenUsage, SkillRegistry, StorageAdapter, StorageConfig, StreamChunk, StreamChunkProcessor, type StreamChunkProcessorOptions, StreamEvent, type StreamOptions, SystemPrompt, TokenUsage, ToolDefinition, ToolRegistry, ToolResult, createAgent, createConsoleSDKLogger, createJsonlStorage, createMCPAdapter, createMCPClient, createMemoryStorage, createSessionManager, createStorage, createStream, formatMcpToolName, formatSDKLog, fromAsyncIterable, getLatestSessionId, getSessionStoragePath, isMcpPrefixedToolName, loadMCPConfig, mergeMcpStdioEnv, mergeProcessEnv, parseSkillMd, validateMCPConfig };
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import './chunk-A3S3AGE3.js';
|
|
3
|
-
export { Agent, DEFAULT_SYSTEM_PROMPT, JsonlStorage, MCPAdapter, MCPClient, MemoryManager, MemoryStorage, SessionManager, SkillLoader, SkillRegistry, StreamChunkProcessor, createAgent, createJsonlStorage, createMCPAdapter, createMCPClient, createMemoryStorage, createSessionManager, createSkillLoader, createSkillRegistry, createStorage, getLatestSessionId, getSessionStoragePath, loadMCPConfig, parseSkillMd, validateMCPConfig } from './chunk-
|
|
4
|
-
export { AnthropicAdapter, OllamaAdapter, OpenAIAdapter, createAnthropic, createModel, createOllama, createOpenAI } from './chunk-
|
|
5
|
-
export { DEFAULT_GREP_HEAD_LIMIT, HookManager, MAX_LINE_LENGTH, ToolRegistry, agentTool, bashTool, buildHookEnv, createAgentTool, createAskUserQuestionTool, createFunctionHook, createSkillTool, createTool, editTool, formatAnswerSummary, formatAskUserQuestionPrompt, getAllBuiltinTools, getFileSystemTools, getGlobalRegistry, getGrepTools, getInteractionTools, getSafeBuiltinTools, getShellTools, getSkillTools, getSubagentTools,
|
|
6
|
-
import './chunk-
|
|
3
|
+
export { Agent, DEFAULT_MAX_ITERATIONS, DEFAULT_SYSTEM_PROMPT, JsonlStorage, MCPAdapter, MCPClient, MODEL_STREAM_EVENT_TYPES, MemoryManager, MemoryStorage, PACKAGE_VERSION, SessionManager, SkillLoader, SkillRegistry, StreamChunkProcessor, createAgent, createJsonlStorage, createMCPAdapter, createMCPClient, createMemoryStorage, createSessionManager, createSkillLoader, createSkillRegistry, createStorage, formatMcpToolName, getLatestSessionId, getSessionStoragePath, isMcpPrefixedToolName, isModelStreamEventType, loadMCPConfig, parseSkillMd, validateMCPConfig } from './chunk-EQ5CXH44.js';
|
|
4
|
+
export { AnthropicAdapter, DEFAULT_ADAPTER_CAPABILITIES, OllamaAdapter, OpenAIAdapter, createAnthropic, createConsoleSDKLogger, createModel, createOllama, createOpenAI, formatSDKLog, mergeMcpStdioEnv, mergeProcessEnv } from './chunk-D3UZNLZO.js';
|
|
5
|
+
export { DEFAULT_GREP_HEAD_LIMIT, HookManager, MAX_LINE_LENGTH, ToolRegistry, agentTool, bashTool, buildHookEnv, createAgentTool, createAskUserQuestionTool, createFunctionHook, createSkillTool, createTool, editTool, formatAnswerSummary, formatAskUserQuestionPrompt, getAllBuiltinTools, getFileSystemTools, getGlobalRegistry, getGrepTools, getInteractionTools, getPlanningTools, getSafeBuiltinTools, getShellTools, getSkillTools, getSubagentTools, getWebTools, globTool, grepTool, loadHooksSettingsFromProject, loadHooksSettingsFromUser, matchTool, mergeCommandHookLayers, parseHooksSettingsFile, questionTool, readFileTool, subagentRequestSchema, todoWriteTool, truncateMatchLineForDisplay, webFetchTool, webSearchTool, writeFileTool } from './chunk-MEJHTQJM.js';
|
|
6
|
+
import './chunk-LOYIGOBZ.js';
|
|
7
7
|
|
|
8
8
|
// src/streaming/event-emitter.ts
|
|
9
9
|
var AgentStream = class _AgentStream {
|
package/dist/models/index.cjs
CHANGED
|
@@ -1,62 +1,66 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
'use strict';
|
|
3
3
|
|
|
4
|
-
var
|
|
5
|
-
var
|
|
4
|
+
var chunkNYZD3THB_cjs = require('../chunk-NYZD3THB.cjs');
|
|
5
|
+
var chunkOZO7D77N_cjs = require('../chunk-OZO7D77N.cjs');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
Object.defineProperty(exports, "AnthropicAdapter", {
|
|
10
10
|
enumerable: true,
|
|
11
|
-
get: function () { return
|
|
11
|
+
get: function () { return chunkNYZD3THB_cjs.AnthropicAdapter; }
|
|
12
|
+
});
|
|
13
|
+
Object.defineProperty(exports, "DEFAULT_ADAPTER_CAPABILITIES", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return chunkNYZD3THB_cjs.DEFAULT_ADAPTER_CAPABILITIES; }
|
|
12
16
|
});
|
|
13
17
|
Object.defineProperty(exports, "OllamaAdapter", {
|
|
14
18
|
enumerable: true,
|
|
15
|
-
get: function () { return
|
|
19
|
+
get: function () { return chunkNYZD3THB_cjs.OllamaAdapter; }
|
|
16
20
|
});
|
|
17
21
|
Object.defineProperty(exports, "OpenAIAdapter", {
|
|
18
22
|
enumerable: true,
|
|
19
|
-
get: function () { return
|
|
23
|
+
get: function () { return chunkNYZD3THB_cjs.OpenAIAdapter; }
|
|
20
24
|
});
|
|
21
25
|
Object.defineProperty(exports, "createAnthropic", {
|
|
22
26
|
enumerable: true,
|
|
23
|
-
get: function () { return
|
|
27
|
+
get: function () { return chunkNYZD3THB_cjs.createAnthropic; }
|
|
24
28
|
});
|
|
25
29
|
Object.defineProperty(exports, "createModel", {
|
|
26
30
|
enumerable: true,
|
|
27
|
-
get: function () { return
|
|
31
|
+
get: function () { return chunkNYZD3THB_cjs.createModel; }
|
|
28
32
|
});
|
|
29
33
|
Object.defineProperty(exports, "createOllama", {
|
|
30
34
|
enumerable: true,
|
|
31
|
-
get: function () { return
|
|
35
|
+
get: function () { return chunkNYZD3THB_cjs.createOllama; }
|
|
32
36
|
});
|
|
33
37
|
Object.defineProperty(exports, "createOpenAI", {
|
|
34
38
|
enumerable: true,
|
|
35
|
-
get: function () { return
|
|
39
|
+
get: function () { return chunkNYZD3THB_cjs.createOpenAI; }
|
|
36
40
|
});
|
|
37
41
|
Object.defineProperty(exports, "ollamaMessageContentToApiString", {
|
|
38
42
|
enumerable: true,
|
|
39
|
-
get: function () { return
|
|
43
|
+
get: function () { return chunkNYZD3THB_cjs.ollamaMessageContentToApiString; }
|
|
40
44
|
});
|
|
41
45
|
Object.defineProperty(exports, "ollamaStreamChunksFromChatData", {
|
|
42
46
|
enumerable: true,
|
|
43
|
-
get: function () { return
|
|
47
|
+
get: function () { return chunkNYZD3THB_cjs.ollamaStreamChunksFromChatData; }
|
|
44
48
|
});
|
|
45
49
|
Object.defineProperty(exports, "BaseModelAdapter", {
|
|
46
50
|
enumerable: true,
|
|
47
|
-
get: function () { return
|
|
51
|
+
get: function () { return chunkOZO7D77N_cjs.BaseModelAdapter; }
|
|
48
52
|
});
|
|
49
53
|
Object.defineProperty(exports, "mergeTokenUsage", {
|
|
50
54
|
enumerable: true,
|
|
51
|
-
get: function () { return
|
|
55
|
+
get: function () { return chunkOZO7D77N_cjs.mergeTokenUsage; }
|
|
52
56
|
});
|
|
53
57
|
Object.defineProperty(exports, "toolsToModelSchema", {
|
|
54
58
|
enumerable: true,
|
|
55
|
-
get: function () { return
|
|
59
|
+
get: function () { return chunkOZO7D77N_cjs.toolsToModelSchema; }
|
|
56
60
|
});
|
|
57
61
|
Object.defineProperty(exports, "zodToJsonSchema", {
|
|
58
62
|
enumerable: true,
|
|
59
|
-
get: function () { return
|
|
63
|
+
get: function () { return chunkOZO7D77N_cjs.zodToJsonSchema; }
|
|
60
64
|
});
|
|
61
65
|
//# sourceMappingURL=index.cjs.map
|
|
62
66
|
//# sourceMappingURL=index.cjs.map
|