@ddlqhd/agent-sdk 0.1.0 → 0.1.1

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.
Files changed (48) hide show
  1. package/README.md +4 -2
  2. package/dist/{chunk-NDSL7NPN.js → chunk-742JTNYI.js} +224 -19
  3. package/dist/chunk-742JTNYI.js.map +1 -0
  4. package/dist/{chunk-5QMA2YBY.cjs → chunk-AJD3DTL7.cjs} +57 -28
  5. package/dist/chunk-AJD3DTL7.cjs.map +1 -0
  6. package/dist/{chunk-X35MHWXE.cjs → chunk-DQFTAD3I.cjs} +231 -24
  7. package/dist/chunk-DQFTAD3I.cjs.map +1 -0
  8. package/dist/{chunk-Q3SOMX26.js → chunk-DXMVWGLJ.js} +52 -25
  9. package/dist/chunk-DXMVWGLJ.js.map +1 -0
  10. package/dist/chunk-LOYIGOBZ.js +54 -0
  11. package/dist/chunk-LOYIGOBZ.js.map +1 -0
  12. package/dist/chunk-OZO7D77N.cjs +59 -0
  13. package/dist/chunk-OZO7D77N.cjs.map +1 -0
  14. package/dist/{chunk-JF5AJQMU.cjs → chunk-Q3L4GIBG.cjs} +211 -58
  15. package/dist/chunk-Q3L4GIBG.cjs.map +1 -0
  16. package/dist/{chunk-OHXW2YM6.js → chunk-THKEF32L.js} +210 -57
  17. package/dist/chunk-THKEF32L.js.map +1 -0
  18. package/dist/cli/index.cjs +36 -37
  19. package/dist/cli/index.cjs.map +1 -1
  20. package/dist/cli/index.js +11 -12
  21. package/dist/cli/index.js.map +1 -1
  22. package/dist/{index-DPsZ1zat.d.ts → index-DGPDMbW5.d.cts} +8 -21
  23. package/dist/{index-RTPmFjMp.d.cts → index-nEfayAzD.d.ts} +8 -21
  24. package/dist/index.cjs +91 -79
  25. package/dist/index.d.cts +26 -6
  26. package/dist/index.d.ts +26 -6
  27. package/dist/index.js +4 -4
  28. package/dist/models/index.cjs +15 -15
  29. package/dist/models/index.d.cts +50 -6
  30. package/dist/models/index.d.ts +50 -6
  31. package/dist/models/index.js +2 -2
  32. package/dist/tools/index.cjs +51 -51
  33. package/dist/tools/index.d.cts +3 -3
  34. package/dist/tools/index.d.ts +3 -3
  35. package/dist/tools/index.js +2 -2
  36. package/dist/{types-C0aX_Qdp.d.cts → types-BLf9IqRs.d.cts} +34 -49
  37. package/dist/{types-C0aX_Qdp.d.ts → types-BLf9IqRs.d.ts} +34 -49
  38. package/package.json +15 -4
  39. package/dist/chunk-5QMA2YBY.cjs.map +0 -1
  40. package/dist/chunk-CNSGZVRN.cjs +0 -152
  41. package/dist/chunk-CNSGZVRN.cjs.map +0 -1
  42. package/dist/chunk-JF5AJQMU.cjs.map +0 -1
  43. package/dist/chunk-NDSL7NPN.js.map +0 -1
  44. package/dist/chunk-OHXW2YM6.js.map +0 -1
  45. package/dist/chunk-Q3SOMX26.js.map +0 -1
  46. package/dist/chunk-WH3APNQ5.js +0 -147
  47. package/dist/chunk-WH3APNQ5.js.map +0 -1
  48. package/dist/chunk-X35MHWXE.cjs.map +0 -1
@@ -128,52 +128,10 @@ declare const questionsSchema: z.ZodObject<{
128
128
  options: z.ZodArray<z.ZodObject<{
129
129
  label: z.ZodString;
130
130
  description: z.ZodString;
131
- }, "strip", z.ZodTypeAny, {
132
- description: string;
133
- label: string;
134
- }, {
135
- description: string;
136
- label: string;
137
- }>, "many">;
131
+ }, z.core.$strip>>;
138
132
  multiSelect: z.ZodDefault<z.ZodBoolean>;
139
- }, "strip", z.ZodTypeAny, {
140
- options: {
141
- description: string;
142
- label: string;
143
- }[];
144
- question: string;
145
- header: string;
146
- multiSelect: boolean;
147
- }, {
148
- options: {
149
- description: string;
150
- label: string;
151
- }[];
152
- question: string;
153
- header: string;
154
- multiSelect?: boolean | undefined;
155
- }>, "many">;
156
- }, "strip", z.ZodTypeAny, {
157
- questions: {
158
- options: {
159
- description: string;
160
- label: string;
161
- }[];
162
- question: string;
163
- header: string;
164
- multiSelect: boolean;
165
- }[];
166
- }, {
167
- questions: {
168
- options: {
169
- description: string;
170
- label: string;
171
- }[];
172
- question: string;
173
- header: string;
174
- multiSelect?: boolean | undefined;
175
- }[];
176
- }>;
133
+ }, z.core.$strip>>;
134
+ }, z.core.$strip>;
177
135
  type AskUserQuestionItem = z.infer<typeof questionsSchema>['questions'][number];
178
136
  type AskUserQuestionAnswer = {
179
137
  questionIndex: number;
@@ -314,6 +272,8 @@ interface ModelParams {
314
272
  * When true, adapters may attach `providerRaw` on each {@link StreamChunk} (e.g. Anthropic SSE JSON object).
315
273
  */
316
274
  includeRawStreamEvents?: boolean;
275
+ /** 会话标识;Agent 会在每次模型请求中填入,各适配器自行决定是否映射到 HTTP 请求。 */
276
+ sessionId?: string;
317
277
  }
318
278
  /**
319
279
  * 流式块类型
@@ -450,7 +410,7 @@ interface ToolDefinition {
450
410
  /** 工具描述 */
451
411
  description: string;
452
412
  /** 参数 Schema (Zod) */
453
- parameters: z.ZodSchema;
413
+ parameters: z.ZodType;
454
414
  /** 处理函数 */
455
415
  handler: ToolHandler;
456
416
  /** 是否危险操作 */
@@ -710,12 +670,30 @@ interface ToolExecutionPolicy {
710
670
  allowedTools?: string[];
711
671
  canUseTool?: CanUseToolCallback;
712
672
  }
673
+ /**
674
+ * 与 `createModel` 参数对齐,供 `AgentConfig.modelConfig` 使用(避免 `types` 依赖 `models`)。
675
+ */
676
+ interface AgentModelConfig {
677
+ provider: 'openai' | 'anthropic' | 'ollama';
678
+ apiKey?: string;
679
+ baseUrl?: string;
680
+ model?: string;
681
+ /** Ollama:对应 `/api/chat` 的 `think` */
682
+ think?: boolean | 'low' | 'medium' | 'high';
683
+ }
713
684
  /**
714
685
  * Agent 配置
715
686
  */
716
687
  interface AgentConfig {
717
- /** 模型适配器 */
718
- model: ModelAdapter;
688
+ /**
689
+ * 模型适配器;与 {@link modelConfig} 二选一。
690
+ * 若需让 {@link env} 参与 API Key 等解析,请使用 `modelConfig`,由 Agent 内部调用 {@link mergeProcessEnv} 后构造适配器。
691
+ */
692
+ model?: ModelAdapter;
693
+ /**
694
+ * 由 Agent 在内部通过 `createModel(modelConfig, env)` 构造适配器;与 `model` 二选一。
695
+ */
696
+ modelConfig?: AgentModelConfig;
719
697
  /** 系统提示 (字符串或配置对象) */
720
698
  systemPrompt?: SystemPrompt;
721
699
  /**
@@ -751,6 +729,13 @@ interface AgentConfig {
751
729
  skills?: string[];
752
730
  /** MCP 服务器配置 */
753
731
  mcpServers?: MCPServerConfig[];
732
+ /**
733
+ * 对当前进程环境的补充与覆盖(合并到 stdio MCP 子进程;键与 `process.env` 冲突时以本字段为准)。
734
+ * 与 {@link includeEnvironment}(往 system prompt 注入工作区描述)无关。
735
+ * 使用 `modelConfig` 时,`env` 会一并用于构造模型适配器;若传入现成 `model`,请自行用 `mergeProcessEnv` 解析密钥等。
736
+ * 完整继承会将 `process.env` 中的敏感变量一并带入 MCP 子进程,由调用方控制。
737
+ */
738
+ env?: Record<string, string>;
754
739
  /** 用户级基础路径,默认 ~ (homedir),用于定位 .claude/ 目录 */
755
740
  userBasePath?: string;
756
741
  /** 存储配置 */
@@ -914,4 +899,4 @@ interface SkillOptions {
914
899
  path?: string;
915
900
  }
916
901
 
917
- export { type StreamEventAnnotations as $, type AgentConfig as A, HookManager as B, type CLIConfig as C, type HookResult as D, type HooksSettings as E, type FlatCommandHookEntry as F, type HooksSettingsFile as G, type HookContext as H, type ImageContent as I, type MCPOptions as J, type MCPPromptArgument as K, type MCPResourceContent as L, type Message as M, type MessageRole as N, type ModelAdapter as O, type ParsedSkill as P, type ModelCapabilities as Q, type ModelParams as R, type StorageConfig as S, type ToolResult as T, type RunOptions as U, type SessionListOptions as V, type SkillConfig as W, type SkillDefinition as X, type SkillMetadata as Y, type SkillOptions as Z, type StreamChunkType as _, type SessionInfo as a, type StreamEventType as a0, type SystemMessage as a1, type SystemPromptConfig as a2, type TextContent as a3, type ThinkingContent as a4, type ToolCall as a5, type ToolExecutionContext as a6, type ToolExecutionPolicy as a7, type ToolHandler as a8, type ToolListOptions as a9, type ToolMessage as aa, type ToolResultMetadata as ab, type ToolSchema as ac, type UserMessage as ad, buildHookEnv as ae, createAskUserQuestionTool as af, createFunctionHook as ag, formatAnswerSummary as ah, formatAskUserQuestionPrompt as ai, getInteractionTools as aj, matchTool as ak, mergeCommandHookLayers as al, questionTool as am, type StorageAdapter as b, type ToolDefinition as c, type SystemPrompt as d, type StreamEvent as e, type AgentResult as f, type MCPServerConfig as g, type SessionTokenUsage as h, type TokenUsage as i, type StreamChunk as j, type MemoryConfig as k, type AgentCallbacks as l, type AskUserQuestionAnswer as m, type AskUserQuestionItem as n, type AskUserQuestionResolver as o, type AssistantMessage as p, type CanUseToolCallback as q, type ChatOptions as r, type CommandHookConfig as s, type CompletionResult as t, type ContentPart as u, type ContextManagerConfig as v, type CreateAskUserQuestionToolOptions as w, type FunctionHook as x, type HookEventType as y, type HookGroupConfig as z };
902
+ export { type StreamChunkType as $, type AgentConfig as A, type HookEventType as B, type CLIConfig as C, type HookGroupConfig as D, HookManager as E, type FlatCommandHookEntry as F, type HookResult as G, type HookContext as H, type HooksSettings as I, type HooksSettingsFile as J, type ImageContent as K, type MCPOptions as L, type Message as M, type MCPPromptArgument as N, type MCPResourceContent as O, type ParsedSkill as P, type MessageRole as Q, type ModelCapabilities as R, type StorageConfig as S, type ToolResult as T, type ModelParams as U, type RunOptions as V, type SessionListOptions as W, type SkillConfig as X, type SkillDefinition as Y, type SkillMetadata as Z, type SkillOptions as _, type SessionInfo as a, type StreamEventAnnotations as a0, type StreamEventType as a1, type SystemMessage as a2, type SystemPromptConfig as a3, type TextContent as a4, type ThinkingContent as a5, type ToolCall as a6, type ToolExecutionContext as a7, type ToolExecutionPolicy as a8, type ToolHandler as a9, type ToolListOptions as aa, type ToolMessage as ab, type ToolResultMetadata as ac, type ToolSchema as ad, type UserMessage as ae, buildHookEnv as af, createAskUserQuestionTool as ag, createFunctionHook as ah, formatAnswerSummary as ai, formatAskUserQuestionPrompt as aj, getInteractionTools as ak, matchTool as al, mergeCommandHookLayers as am, questionTool as an, type StorageAdapter as b, type ToolDefinition as c, type SystemPrompt as d, type StreamEvent as e, type AgentResult as f, type ModelAdapter as g, type MCPServerConfig as h, type SessionTokenUsage as i, type TokenUsage as j, type StreamChunk as k, type MemoryConfig as l, type AgentCallbacks as m, type AgentModelConfig as n, type AskUserQuestionAnswer as o, type AskUserQuestionItem as p, type AskUserQuestionResolver as q, type AssistantMessage as r, type CanUseToolCallback as s, type ChatOptions as t, type CommandHookConfig as u, type CompletionResult as v, type ContentPart as w, type ContextManagerConfig as x, type CreateAskUserQuestionToolOptions as y, type FunctionHook as z };
@@ -128,52 +128,10 @@ declare const questionsSchema: z.ZodObject<{
128
128
  options: z.ZodArray<z.ZodObject<{
129
129
  label: z.ZodString;
130
130
  description: z.ZodString;
131
- }, "strip", z.ZodTypeAny, {
132
- description: string;
133
- label: string;
134
- }, {
135
- description: string;
136
- label: string;
137
- }>, "many">;
131
+ }, z.core.$strip>>;
138
132
  multiSelect: z.ZodDefault<z.ZodBoolean>;
139
- }, "strip", z.ZodTypeAny, {
140
- options: {
141
- description: string;
142
- label: string;
143
- }[];
144
- question: string;
145
- header: string;
146
- multiSelect: boolean;
147
- }, {
148
- options: {
149
- description: string;
150
- label: string;
151
- }[];
152
- question: string;
153
- header: string;
154
- multiSelect?: boolean | undefined;
155
- }>, "many">;
156
- }, "strip", z.ZodTypeAny, {
157
- questions: {
158
- options: {
159
- description: string;
160
- label: string;
161
- }[];
162
- question: string;
163
- header: string;
164
- multiSelect: boolean;
165
- }[];
166
- }, {
167
- questions: {
168
- options: {
169
- description: string;
170
- label: string;
171
- }[];
172
- question: string;
173
- header: string;
174
- multiSelect?: boolean | undefined;
175
- }[];
176
- }>;
133
+ }, z.core.$strip>>;
134
+ }, z.core.$strip>;
177
135
  type AskUserQuestionItem = z.infer<typeof questionsSchema>['questions'][number];
178
136
  type AskUserQuestionAnswer = {
179
137
  questionIndex: number;
@@ -314,6 +272,8 @@ interface ModelParams {
314
272
  * When true, adapters may attach `providerRaw` on each {@link StreamChunk} (e.g. Anthropic SSE JSON object).
315
273
  */
316
274
  includeRawStreamEvents?: boolean;
275
+ /** 会话标识;Agent 会在每次模型请求中填入,各适配器自行决定是否映射到 HTTP 请求。 */
276
+ sessionId?: string;
317
277
  }
318
278
  /**
319
279
  * 流式块类型
@@ -450,7 +410,7 @@ interface ToolDefinition {
450
410
  /** 工具描述 */
451
411
  description: string;
452
412
  /** 参数 Schema (Zod) */
453
- parameters: z.ZodSchema;
413
+ parameters: z.ZodType;
454
414
  /** 处理函数 */
455
415
  handler: ToolHandler;
456
416
  /** 是否危险操作 */
@@ -710,12 +670,30 @@ interface ToolExecutionPolicy {
710
670
  allowedTools?: string[];
711
671
  canUseTool?: CanUseToolCallback;
712
672
  }
673
+ /**
674
+ * 与 `createModel` 参数对齐,供 `AgentConfig.modelConfig` 使用(避免 `types` 依赖 `models`)。
675
+ */
676
+ interface AgentModelConfig {
677
+ provider: 'openai' | 'anthropic' | 'ollama';
678
+ apiKey?: string;
679
+ baseUrl?: string;
680
+ model?: string;
681
+ /** Ollama:对应 `/api/chat` 的 `think` */
682
+ think?: boolean | 'low' | 'medium' | 'high';
683
+ }
713
684
  /**
714
685
  * Agent 配置
715
686
  */
716
687
  interface AgentConfig {
717
- /** 模型适配器 */
718
- model: ModelAdapter;
688
+ /**
689
+ * 模型适配器;与 {@link modelConfig} 二选一。
690
+ * 若需让 {@link env} 参与 API Key 等解析,请使用 `modelConfig`,由 Agent 内部调用 {@link mergeProcessEnv} 后构造适配器。
691
+ */
692
+ model?: ModelAdapter;
693
+ /**
694
+ * 由 Agent 在内部通过 `createModel(modelConfig, env)` 构造适配器;与 `model` 二选一。
695
+ */
696
+ modelConfig?: AgentModelConfig;
719
697
  /** 系统提示 (字符串或配置对象) */
720
698
  systemPrompt?: SystemPrompt;
721
699
  /**
@@ -751,6 +729,13 @@ interface AgentConfig {
751
729
  skills?: string[];
752
730
  /** MCP 服务器配置 */
753
731
  mcpServers?: MCPServerConfig[];
732
+ /**
733
+ * 对当前进程环境的补充与覆盖(合并到 stdio MCP 子进程;键与 `process.env` 冲突时以本字段为准)。
734
+ * 与 {@link includeEnvironment}(往 system prompt 注入工作区描述)无关。
735
+ * 使用 `modelConfig` 时,`env` 会一并用于构造模型适配器;若传入现成 `model`,请自行用 `mergeProcessEnv` 解析密钥等。
736
+ * 完整继承会将 `process.env` 中的敏感变量一并带入 MCP 子进程,由调用方控制。
737
+ */
738
+ env?: Record<string, string>;
754
739
  /** 用户级基础路径,默认 ~ (homedir),用于定位 .claude/ 目录 */
755
740
  userBasePath?: string;
756
741
  /** 存储配置 */
@@ -914,4 +899,4 @@ interface SkillOptions {
914
899
  path?: string;
915
900
  }
916
901
 
917
- export { type StreamEventAnnotations as $, type AgentConfig as A, HookManager as B, type CLIConfig as C, type HookResult as D, type HooksSettings as E, type FlatCommandHookEntry as F, type HooksSettingsFile as G, type HookContext as H, type ImageContent as I, type MCPOptions as J, type MCPPromptArgument as K, type MCPResourceContent as L, type Message as M, type MessageRole as N, type ModelAdapter as O, type ParsedSkill as P, type ModelCapabilities as Q, type ModelParams as R, type StorageConfig as S, type ToolResult as T, type RunOptions as U, type SessionListOptions as V, type SkillConfig as W, type SkillDefinition as X, type SkillMetadata as Y, type SkillOptions as Z, type StreamChunkType as _, type SessionInfo as a, type StreamEventType as a0, type SystemMessage as a1, type SystemPromptConfig as a2, type TextContent as a3, type ThinkingContent as a4, type ToolCall as a5, type ToolExecutionContext as a6, type ToolExecutionPolicy as a7, type ToolHandler as a8, type ToolListOptions as a9, type ToolMessage as aa, type ToolResultMetadata as ab, type ToolSchema as ac, type UserMessage as ad, buildHookEnv as ae, createAskUserQuestionTool as af, createFunctionHook as ag, formatAnswerSummary as ah, formatAskUserQuestionPrompt as ai, getInteractionTools as aj, matchTool as ak, mergeCommandHookLayers as al, questionTool as am, type StorageAdapter as b, type ToolDefinition as c, type SystemPrompt as d, type StreamEvent as e, type AgentResult as f, type MCPServerConfig as g, type SessionTokenUsage as h, type TokenUsage as i, type StreamChunk as j, type MemoryConfig as k, type AgentCallbacks as l, type AskUserQuestionAnswer as m, type AskUserQuestionItem as n, type AskUserQuestionResolver as o, type AssistantMessage as p, type CanUseToolCallback as q, type ChatOptions as r, type CommandHookConfig as s, type CompletionResult as t, type ContentPart as u, type ContextManagerConfig as v, type CreateAskUserQuestionToolOptions as w, type FunctionHook as x, type HookEventType as y, type HookGroupConfig as z };
902
+ export { type StreamChunkType as $, type AgentConfig as A, type HookEventType as B, type CLIConfig as C, type HookGroupConfig as D, HookManager as E, type FlatCommandHookEntry as F, type HookResult as G, type HookContext as H, type HooksSettings as I, type HooksSettingsFile as J, type ImageContent as K, type MCPOptions as L, type Message as M, type MCPPromptArgument as N, type MCPResourceContent as O, type ParsedSkill as P, type MessageRole as Q, type ModelCapabilities as R, type StorageConfig as S, type ToolResult as T, type ModelParams as U, type RunOptions as V, type SessionListOptions as W, type SkillConfig as X, type SkillDefinition as Y, type SkillMetadata as Z, type SkillOptions as _, type SessionInfo as a, type StreamEventAnnotations as a0, type StreamEventType as a1, type SystemMessage as a2, type SystemPromptConfig as a3, type TextContent as a4, type ThinkingContent as a5, type ToolCall as a6, type ToolExecutionContext as a7, type ToolExecutionPolicy as a8, type ToolHandler as a9, type ToolListOptions as aa, type ToolMessage as ab, type ToolResultMetadata as ac, type ToolSchema as ad, type UserMessage as ae, buildHookEnv as af, createAskUserQuestionTool as ag, createFunctionHook as ah, formatAnswerSummary as ai, formatAskUserQuestionPrompt as aj, getInteractionTools as ak, matchTool as al, mergeCommandHookLayers as am, questionTool as an, type StorageAdapter as b, type ToolDefinition as c, type SystemPrompt as d, type StreamEvent as e, type AgentResult as f, type ModelAdapter as g, type MCPServerConfig as h, type SessionTokenUsage as i, type TokenUsage as j, type StreamChunk as k, type MemoryConfig as l, type AgentCallbacks as m, type AgentModelConfig as n, type AskUserQuestionAnswer as o, type AskUserQuestionItem as p, type AskUserQuestionResolver as q, type AssistantMessage as r, type CanUseToolCallback as s, type ChatOptions as t, type CommandHookConfig as u, type CompletionResult as v, type ContentPart as w, type ContextManagerConfig as x, type CreateAskUserQuestionToolOptions as y, type FunctionHook as z };
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.1.0",
6
+ "version": "0.1.1",
7
7
  "description": "A TypeScript Agent SDK with multi-model support, MCP integration, skill system, and streaming",
8
8
  "type": "module",
9
9
  "main": "./dist/index.cjs",
@@ -51,6 +51,14 @@
51
51
  ],
52
52
  "author": "",
53
53
  "license": "MIT",
54
+ "repository": {
55
+ "type": "git",
56
+ "url": "git+https://github.com/ddlqhd/agent-sdk.git"
57
+ },
58
+ "homepage": "https://github.com/ddlqhd/agent-sdk#readme",
59
+ "bugs": {
60
+ "url": "https://github.com/ddlqhd/agent-sdk/issues"
61
+ },
54
62
  "dependencies": {
55
63
  "@modelcontextprotocol/sdk": "^1.27.0",
56
64
  "@mozilla/readability": "^0.6.0",
@@ -63,8 +71,10 @@
63
71
  "ipaddr.js": "^2.3.0",
64
72
  "linkedom": "^0.18.12",
65
73
  "micromatch": "^4.0.8",
66
- "turndown": "^7.2.3",
67
- "zod": "^3.23.0"
74
+ "turndown": "^7.2.3"
75
+ },
76
+ "peerDependencies": {
77
+ "zod": "^4.0.0"
68
78
  },
69
79
  "devDependencies": {
70
80
  "@types/micromatch": "^4.0.10",
@@ -72,7 +82,8 @@
72
82
  "@types/turndown": "^5.0.6",
73
83
  "tsup": "^8.0.0",
74
84
  "typescript": "^5.4.0",
75
- "vitest": "^1.6.0"
85
+ "vitest": "^1.6.0",
86
+ "zod": "^4.0.0"
76
87
  },
77
88
  "engines": {
78
89
  "node": ">=18.0.0"