@ai-zen/agents-sdk 0.12.0 → 1.0.0-alpha.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.
- package/CHANGELOG.md +103 -36
- package/README.md +29 -21
- package/README.zh.md +29 -21
- package/dist/{plugin → agent-plugins}/AutoRefreshToolsPlugin.js +2 -2
- package/dist/{plugin → agent-plugins}/UnknownToolHintPlugin.d.ts +7 -5
- package/dist/{plugin → agent-plugins}/UnknownToolHintPlugin.js +9 -5
- package/dist/config/ConfigManager.d.ts +17 -0
- package/dist/config/ConfigManager.js +44 -1
- package/dist/config/constants.js +67 -37
- package/dist/index.d.ts +37 -29
- package/dist/index.js +28 -21
- package/dist/runtime/SdkAgent.d.ts +5 -5
- package/dist/runtime/SdkAgent.js +4 -4
- package/dist/runtime/TaskMigrationService.d.ts +1 -1
- package/dist/runtime/TaskMigrationService.js +2 -2
- package/dist/runtime/createAgent.d.ts +4 -4
- package/dist/runtime/createAgent.js +8 -8
- package/dist/runtime/createModel.d.ts +3 -3
- package/dist/runtime/createModel.js +3 -3
- package/dist/scope/Scope.d.ts +111 -0
- package/dist/scope/Scope.js +165 -0
- package/dist/scope/ScopePlugin.d.ts +51 -0
- package/dist/scope/ScopePlugin.js +1 -0
- package/dist/scope/plugins/allInOne.d.ts +18 -0
- package/dist/scope/plugins/allInOne.js +23 -0
- package/dist/{capabilities/implements → scope/plugins}/builtin/BatchEditTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/BatchEditTool.js +1 -1
- package/dist/scope/plugins/builtin/BuiltinToolsScopePlugin.d.ts +20 -0
- package/dist/scope/plugins/builtin/BuiltinToolsScopePlugin.js +30 -0
- package/dist/{capabilities/implements → scope/plugins}/builtin/CopyTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/CopyTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/CwdTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/CwdTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/DownloadFileTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/DownloadFileTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/EditTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/EditTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/ExecAsyncTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/ExecAsyncTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/ExecTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/ExecTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/ExistTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/ExistTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/FindTextTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/FindTextTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/GenerateImageTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/GenerateImageTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/GlobTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/GlobTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/InspectFileTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/InspectFileTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/LsTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/LsTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/MkdirTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/MkdirTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/ReadFileTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/ReadFileTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/RenameTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/RenameTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/RmTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/RmTool.js +1 -1
- package/dist/{runtime → scope/plugins/builtin}/SdkCallbackTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/SleepTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/SleepTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/ViewImageTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/ViewImageTool.js +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/WriteFileTool.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/WriteFileTool.js +1 -1
- package/dist/{capabilities/discovery/builtin.d.ts → scope/plugins/builtin/discover.d.ts} +1 -1
- package/dist/{capabilities/discovery/builtin.js → scope/plugins/builtin/discover.js} +1 -1
- package/dist/{capabilities/implements → scope/plugins}/builtin/index.d.ts +2 -2
- package/dist/{capabilities/implements → scope/plugins}/builtin/index.js +1 -1
- package/dist/{runtime → scope/plugins/mcp}/McpConnectionManager.d.ts +1 -1
- package/dist/{runtime → scope/plugins/mcp}/McpConnectionManager.js +1 -1
- package/dist/scope/plugins/mcp/McpScopePlugin.d.ts +29 -0
- package/dist/scope/plugins/mcp/McpScopePlugin.js +60 -0
- package/dist/{capabilities/discovery/mcp.d.ts → scope/plugins/mcp/discover.d.ts} +1 -1
- package/dist/{capabilities/discovery/mcp.js → scope/plugins/mcp/discover.js} +1 -1
- package/dist/{capabilities/implements → scope/plugins/mcp}/mcpTools.d.ts +2 -2
- package/dist/{capabilities/implements → scope/plugins/mcp}/mcpTools.js +2 -2
- package/dist/scope/plugins/skills/SkillsScopePlugin.d.ts +28 -0
- package/dist/scope/plugins/skills/SkillsScopePlugin.js +48 -0
- package/dist/{capabilities/discovery/skills.js → scope/plugins/skills/discover.js} +1 -1
- package/dist/{capabilities/implements → scope/plugins/skills}/skillTools.d.ts +1 -1
- package/dist/{capabilities/implements → scope/plugins/skills}/skillTools.js +3 -3
- package/dist/scope/plugins/subagents/SubAgentsScopePlugin.d.ts +20 -0
- package/dist/scope/plugins/subagents/SubAgentsScopePlugin.js +34 -0
- package/dist/{capabilities/discovery/subagents.d.ts → scope/plugins/subagents/discover.d.ts} +1 -1
- package/dist/{capabilities/implements → scope/plugins/subagents}/subAgentTools.d.ts +3 -3
- package/dist/{capabilities/implements → scope/plugins/subagents}/subAgentTools.js +5 -5
- package/dist/scope/plugins/usertools/UserToolsScopePlugin.d.ts +24 -0
- package/dist/scope/plugins/usertools/UserToolsScopePlugin.js +28 -0
- package/dist/{capabilities/discovery/usertools.js → scope/plugins/usertools/discover.js} +1 -1
- package/dist/types/index.d.ts +23 -2
- package/package.json +3 -3
- package/dist/runtime/Provider.d.ts +0 -119
- package/dist/runtime/Provider.js +0 -218
- /package/dist/{plugin → agent-plugins}/AutoMigratePlugin.d.ts +0 -0
- /package/dist/{plugin → agent-plugins}/AutoMigratePlugin.js +0 -0
- /package/dist/{plugin → agent-plugins}/AutoRefreshToolsPlugin.d.ts +0 -0
- /package/dist/{plugin → agent-plugins}/ContextGuardPlugin.d.ts +0 -0
- /package/dist/{plugin → agent-plugins}/ContextGuardPlugin.js +0 -0
- /package/dist/{capabilities → scope}/PermissionEvaluator.d.ts +0 -0
- /package/dist/{capabilities → scope}/PermissionEvaluator.js +0 -0
- /package/dist/{capabilities → scope}/disclosure.d.ts +0 -0
- /package/dist/{capabilities → scope}/disclosure.js +0 -0
- /package/dist/{runtime → scope/plugins/builtin}/SdkCallbackTool.js +0 -0
- /package/dist/{capabilities/implements → scope/plugins}/builtin/outputGuard.d.ts +0 -0
- /package/dist/{capabilities/implements → scope/plugins}/builtin/outputGuard.js +0 -0
- /package/dist/{capabilities/implements → scope/plugins}/builtin/test-helpers.d.ts +0 -0
- /package/dist/{capabilities/implements → scope/plugins}/builtin/test-helpers.js +0 -0
- /package/dist/{capabilities/discovery/skills.d.ts → scope/plugins/skills/discover.d.ts} +0 -0
- /package/dist/{capabilities/discovery/subagents.js → scope/plugins/subagents/discover.js} +0 -0
- /package/dist/{capabilities/discovery/usertools.d.ts → scope/plugins/usertools/discover.d.ts} +0 -0
|
@@ -54,17 +54,28 @@ export class ConfigManager {
|
|
|
54
54
|
}
|
|
55
55
|
/**
|
|
56
56
|
* 确保 config.json 存在。不存在时写入出厂默认配置 DSL。
|
|
57
|
+
*
|
|
58
|
+
* 已存在时执行「出厂模型清单同步」(见 syncManagedModels):
|
|
59
|
+
* models / imageModels 中凡是**没有** `custom: true` 的条目一律视为出厂托管,
|
|
60
|
+
* 会被移除并替换为 DEFAULT_APP_CONFIG 中的最新定义;标了 `custom: true` 的
|
|
61
|
+
* 条目视为用户自有,原样保留。同步结果与磁盘内容一致时不写盘。
|
|
57
62
|
*/
|
|
58
63
|
async ensureDefaultConfig() {
|
|
64
|
+
let existing;
|
|
59
65
|
try {
|
|
60
66
|
await fs.access(this.configPath);
|
|
61
|
-
|
|
67
|
+
existing = await this.read();
|
|
62
68
|
}
|
|
63
69
|
catch {
|
|
64
70
|
await this.ensureDirs();
|
|
65
71
|
await this.write(DEFAULT_APP_CONFIG);
|
|
66
72
|
return { ...DEFAULT_APP_CONFIG };
|
|
67
73
|
}
|
|
74
|
+
const synced = syncManagedModels(existing);
|
|
75
|
+
if (JSON.stringify(synced) !== JSON.stringify(existing)) {
|
|
76
|
+
await this.write(synced);
|
|
77
|
+
}
|
|
78
|
+
return synced;
|
|
68
79
|
}
|
|
69
80
|
/**
|
|
70
81
|
* 确保 basePath/agents/default.json 存在。
|
|
@@ -234,6 +245,38 @@ export class ConfigManager {
|
|
|
234
245
|
await fs.rename(tmpPath, path);
|
|
235
246
|
}
|
|
236
247
|
}
|
|
248
|
+
/**
|
|
249
|
+
* 同步出厂托管的模型清单(与默认 Agent 的 custom 机制一致)。
|
|
250
|
+
*
|
|
251
|
+
* 规则:
|
|
252
|
+
* - 未标 `custom: true` 的条目 → 由 SDK 托管,从结果中移除,改用 defaults 中的最新定义;
|
|
253
|
+
* - 标了 `custom: true` 的条目 → 用户自有,原样保留;与出厂定义同 id 时用户版本优先;
|
|
254
|
+
* - 默认模型 ID(defaultModel / defaultImageModel / defaultMigrationModel)
|
|
255
|
+
* 在合并后若已不存在 → 回退到出厂默认,避免悬空引用。
|
|
256
|
+
*
|
|
257
|
+
* 端点(endpoints)不参与托管,始终保持用户配置。
|
|
258
|
+
*/
|
|
259
|
+
export function syncManagedModels(config) {
|
|
260
|
+
const pick = (existing, defaults) => {
|
|
261
|
+
const kept = (existing ?? []).filter((m) => m.custom === true);
|
|
262
|
+
const keptIds = new Set(kept.map((m) => m.id));
|
|
263
|
+
// 出厂定义在前,用户自有条目随后;同 id 时用户版本胜出(出厂侧已剔除)
|
|
264
|
+
return [...defaults.filter((m) => !keptIds.has(m.id)), ...kept];
|
|
265
|
+
};
|
|
266
|
+
const models = pick(config.models, DEFAULT_APP_CONFIG.models);
|
|
267
|
+
const imageModels = pick(config.imageModels, DEFAULT_APP_CONFIG.imageModels ?? []);
|
|
268
|
+
const modelIds = new Set(models.map((m) => m.id));
|
|
269
|
+
const imageIds = new Set(imageModels.map((m) => m.id));
|
|
270
|
+
const resolve = (id, ids, fallback) => id && ids.has(id) ? id : fallback;
|
|
271
|
+
return {
|
|
272
|
+
...config,
|
|
273
|
+
models,
|
|
274
|
+
imageModels,
|
|
275
|
+
defaultModel: resolve(config.defaultModel, modelIds, DEFAULT_APP_CONFIG.defaultModel),
|
|
276
|
+
defaultImageModel: resolve(config.defaultImageModel, imageIds, DEFAULT_APP_CONFIG.defaultImageModel),
|
|
277
|
+
defaultMigrationModel: resolve(config.defaultMigrationModel, modelIds, DEFAULT_APP_CONFIG.defaultMigrationModel),
|
|
278
|
+
};
|
|
279
|
+
}
|
|
237
280
|
/**
|
|
238
281
|
* 比较两段消息列表的提示词内容是否一致。
|
|
239
282
|
*
|
package/dist/config/constants.js
CHANGED
|
@@ -85,71 +85,101 @@ export const DEFAULT_APP_CONFIG = {
|
|
|
85
85
|
description: "DeepSeek API 端点",
|
|
86
86
|
},
|
|
87
87
|
],
|
|
88
|
+
// 模型清单(2026-10-03 依据各厂商官方来源核对):
|
|
89
|
+
// OpenAI → openai.com 发布公告 / API 目录(platform 文档站对脚本有访问限制)
|
|
90
|
+
// 智谱 → docs.bigmodel.cn 模型概览/定价 + open.bigmodel.cn/api/paas/v4/models
|
|
91
|
+
// DeepSeek → api-docs.deepseek.com 定价页与 News + api.deepseek.com/v1/models
|
|
92
|
+
//
|
|
93
|
+
// 更新策略:本清单为「出厂托管」清单。用户 config.json 中凡未标 `custom: true`
|
|
94
|
+
// 的模型(含 imageModels)在初始化时一律被移除并替换为本清单中的最新定义;
|
|
95
|
+
// 标了 `custom: true` 的条目视为用户自有,原样保留。实现见
|
|
96
|
+
// ConfigManager.syncManagedModels。
|
|
97
|
+
//
|
|
98
|
+
// maxContextTokens 是「任务迁移(交接)触发阈值」,不是模型的真实上下文窗口:
|
|
99
|
+
// 迁移判断只看 API 响应返回的 usage.prompt_tokens。窗口 ≥1M 的模型统一取 250K
|
|
100
|
+
// (约 25%),glm-4.7-flash 窗口仅 200K,取 100K。
|
|
88
101
|
models: [
|
|
102
|
+
// ---------- OpenAI ----------
|
|
89
103
|
{
|
|
90
|
-
id: "gpt-
|
|
91
|
-
name: "GPT-
|
|
104
|
+
id: "gpt-6-astra",
|
|
105
|
+
name: "GPT-6 Astra",
|
|
92
106
|
endpointId: "openai",
|
|
93
|
-
modelName: "gpt-
|
|
107
|
+
modelName: "gpt-6-astra",
|
|
94
108
|
maxContextTokens: 250_000,
|
|
95
109
|
defaultParams: {},
|
|
96
|
-
|
|
110
|
+
vision: true,
|
|
111
|
+
description: "OpenAI 最强旗舰(2026-09):高级分析、软件工程、深度研究与科学工作",
|
|
97
112
|
},
|
|
98
113
|
{
|
|
99
|
-
id: "
|
|
100
|
-
name: "
|
|
101
|
-
endpointId: "
|
|
102
|
-
modelName: "
|
|
114
|
+
id: "gpt-6.1-sol",
|
|
115
|
+
name: "GPT-6.1 Sol",
|
|
116
|
+
endpointId: "openai",
|
|
117
|
+
modelName: "gpt-6.1-sol",
|
|
103
118
|
maxContextTokens: 250_000,
|
|
104
119
|
defaultParams: {},
|
|
105
|
-
|
|
120
|
+
vision: true,
|
|
121
|
+
description: "OpenAI 最新旗舰(2026-09-29):Agentic Coding、计算机操作与文档密集型专业任务",
|
|
106
122
|
},
|
|
107
123
|
{
|
|
108
|
-
id: "
|
|
109
|
-
name: "
|
|
110
|
-
endpointId: "
|
|
111
|
-
modelName: "
|
|
124
|
+
id: "gpt-6-luna",
|
|
125
|
+
name: "GPT-6 Luna",
|
|
126
|
+
endpointId: "openai",
|
|
127
|
+
modelName: "gpt-6-luna",
|
|
112
128
|
maxContextTokens: 250_000,
|
|
113
129
|
defaultParams: {},
|
|
114
130
|
vision: true,
|
|
115
|
-
description: "
|
|
131
|
+
description: "OpenAI GPT-6 系列快速低成本模型:适合高吞吐、低延迟场景",
|
|
116
132
|
},
|
|
133
|
+
// ---------- 智谱 BigModel ----------
|
|
117
134
|
{
|
|
118
|
-
id: "glm-
|
|
119
|
-
name: "GLM-
|
|
135
|
+
id: "glm-5.3",
|
|
136
|
+
name: "GLM-5.3",
|
|
120
137
|
endpointId: "bigmodelcn",
|
|
121
|
-
modelName: "glm-
|
|
138
|
+
modelName: "glm-5.3",
|
|
122
139
|
maxContextTokens: 250_000,
|
|
123
|
-
defaultParams: {},
|
|
124
|
-
description: "
|
|
140
|
+
defaultParams: { thinking: { type: "enabled" }, reasoning_effort: "max" },
|
|
141
|
+
description: "智谱最新旗舰:复杂软件工程与长程 Agent 任务(强制开启思考,1M 上下文)",
|
|
125
142
|
},
|
|
126
143
|
{
|
|
127
|
-
id: "
|
|
128
|
-
name: "
|
|
129
|
-
endpointId: "
|
|
130
|
-
modelName: "
|
|
144
|
+
id: "glm-5.3-flash",
|
|
145
|
+
name: "GLM-5.3-Flash",
|
|
146
|
+
endpointId: "bigmodelcn",
|
|
147
|
+
modelName: "glm-5.3-flash",
|
|
131
148
|
maxContextTokens: 250_000,
|
|
132
|
-
defaultParams: { thinking: { type: "
|
|
133
|
-
|
|
149
|
+
defaultParams: { thinking: { type: "enabled" }, reasoning_effort: "max" },
|
|
150
|
+
vision: true,
|
|
151
|
+
description: "智谱原生多模态模型(图片/视频/文件):视觉 Coding,1M 上下文",
|
|
134
152
|
},
|
|
135
153
|
{
|
|
136
|
-
id: "
|
|
137
|
-
name: "
|
|
138
|
-
endpointId: "
|
|
139
|
-
modelName: "
|
|
154
|
+
id: "glm-5.3-flashx",
|
|
155
|
+
name: "GLM-5.3-FlashX",
|
|
156
|
+
endpointId: "bigmodelcn",
|
|
157
|
+
modelName: "glm-5.3-flashx",
|
|
140
158
|
maxContextTokens: 250_000,
|
|
141
|
-
defaultParams: { thinking: { type: "enabled" } },
|
|
142
|
-
|
|
159
|
+
defaultParams: { thinking: { type: "enabled" }, reasoning_effort: "max" },
|
|
160
|
+
vision: true,
|
|
161
|
+
description: "GLM-5.3-Flash 高速版(200 tokens/s),原生多模态",
|
|
162
|
+
},
|
|
163
|
+
{
|
|
164
|
+
id: "glm-4.7-flash",
|
|
165
|
+
name: "GLM-4.7-Flash",
|
|
166
|
+
endpointId: "bigmodelcn",
|
|
167
|
+
modelName: "glm-4.7-flash",
|
|
168
|
+
// 该模型真实窗口仅 200K,阈值下调至 100K(约窗口的 50%),留足 response 空间
|
|
169
|
+
maxContextTokens: 100_000,
|
|
170
|
+
defaultParams: {},
|
|
171
|
+
description: "智谱免费文本模型:200K 上下文,适合轻量任务",
|
|
143
172
|
},
|
|
173
|
+
// ---------- DeepSeek ----------
|
|
144
174
|
{
|
|
145
|
-
id: "deepseek-
|
|
146
|
-
name: "DeepSeek-V4-Flash
|
|
175
|
+
id: "deepseek-flash",
|
|
176
|
+
name: "DeepSeek-V4.1-Flash",
|
|
147
177
|
endpointId: "deepseek",
|
|
148
|
-
modelName: "deepseek-
|
|
178
|
+
modelName: "deepseek-flash",
|
|
149
179
|
maxContextTokens: 250_000,
|
|
150
180
|
defaultParams: { thinking: { type: "enabled" } },
|
|
151
181
|
vision: true,
|
|
152
|
-
description: "DeepSeek
|
|
182
|
+
description: "DeepSeek 旗舰(2026-09-10):552B MoE 非对称架构,原生多模态,1M 上下文",
|
|
153
183
|
},
|
|
154
184
|
],
|
|
155
185
|
imageModels: [
|
|
@@ -176,10 +206,10 @@ export const DEFAULT_APP_CONFIG = {
|
|
|
176
206
|
defaultSize: "1024x1024",
|
|
177
207
|
},
|
|
178
208
|
],
|
|
179
|
-
defaultModel: "deepseek-
|
|
209
|
+
defaultModel: "deepseek-flash",
|
|
180
210
|
defaultImageModel: "cogview-4",
|
|
181
211
|
defaultAgent: "default",
|
|
182
|
-
defaultMigrationModel: "deepseek-
|
|
212
|
+
defaultMigrationModel: "deepseek-flash",
|
|
183
213
|
// 工具输出上限(字符数),与 DEFAULT_MAX_TOOL_OUTPUT 保持一致
|
|
184
214
|
maxToolOutput: 32_768,
|
|
185
215
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -1,42 +1,50 @@
|
|
|
1
1
|
export type { PermissionPolicy, AgentPermissions, Endpoint, Model, ImageModel, AgentDefinition, AppConfig, ToolEnv, McpIcon, McpAnnotations, McpToolDef, McpResourceDef, McpPromptDef, McpServerManifest, McpServerConfig, McpConnectionState, } from "./types/index.js";
|
|
2
|
-
export { PermissionEvaluator } from "./
|
|
3
|
-
export type { CandidateSets } from "./
|
|
4
|
-
export { createDisclosureParam } from "./
|
|
5
|
-
export type { DisclosureParam } from "./
|
|
6
|
-
export { discoverBuiltinTools } from "./
|
|
7
|
-
export { discoverSubAgents } from "./
|
|
8
|
-
export { discoverSkills, readSkill } from "./
|
|
9
|
-
export type { SkillInfo, Frontmatter } from "./
|
|
10
|
-
export { discoverMcpServers } from "./
|
|
11
|
-
export { discoverUserTools } from "./
|
|
2
|
+
export { PermissionEvaluator } from "./scope/PermissionEvaluator.js";
|
|
3
|
+
export type { CandidateSets } from "./scope/PermissionEvaluator.js";
|
|
4
|
+
export { createDisclosureParam } from "./scope/disclosure.js";
|
|
5
|
+
export type { DisclosureParam } from "./scope/disclosure.js";
|
|
6
|
+
export { discoverBuiltinTools } from "./scope/plugins/builtin/discover.js";
|
|
7
|
+
export { discoverSubAgents } from "./scope/plugins/subagents/discover.js";
|
|
8
|
+
export { discoverSkills, readSkill } from "./scope/plugins/skills/discover.js";
|
|
9
|
+
export type { SkillInfo, Frontmatter } from "./scope/plugins/skills/discover.js";
|
|
10
|
+
export { discoverMcpServers } from "./scope/plugins/mcp/discover.js";
|
|
11
|
+
export { discoverUserTools } from "./scope/plugins/usertools/discover.js";
|
|
12
|
+
export { Scope } from "./scope/Scope.js";
|
|
13
|
+
export type { FilterOutput, ExcludeOptions, FilterOptions, } from "./scope/Scope.js";
|
|
14
|
+
export type { ScopePlugin, ScopeCandidates } from "./scope/ScopePlugin.js";
|
|
15
|
+
export { BuiltinToolsScopePlugin } from "./scope/plugins/builtin/BuiltinToolsScopePlugin.js";
|
|
16
|
+
export { UserToolsScopePlugin } from "./scope/plugins/usertools/UserToolsScopePlugin.js";
|
|
17
|
+
export { SkillsScopePlugin } from "./scope/plugins/skills/SkillsScopePlugin.js";
|
|
18
|
+
export { McpScopePlugin } from "./scope/plugins/mcp/McpScopePlugin.js";
|
|
19
|
+
export { SubAgentsScopePlugin } from "./scope/plugins/subagents/SubAgentsScopePlugin.js";
|
|
20
|
+
export { allInOne } from "./scope/plugins/allInOne.js";
|
|
21
|
+
export type { AllInOneOptions } from "./scope/plugins/allInOne.js";
|
|
12
22
|
export { ConfigManager, DEFAULT_AGENT_ID, DEFAULT_AGENT_DEFINITION, DEFAULT_SUBAGENT_ID, DEFAULT_SUBAGENT_DEFINITION, DEFAULT_APP_CONFIG, DEFAULT_MCP_CONFIG, CONFIG_SUB_DIRS, } from "./config/ConfigManager.js";
|
|
13
23
|
export { EntityRepository } from "./shared/EntityRepository.js";
|
|
14
24
|
export { AgentRepository } from "./crud/AgentRepository.js";
|
|
15
|
-
export { Provider } from "./runtime/Provider.js";
|
|
16
|
-
export type { FilterOutput, ExcludeOptions } from "./runtime/Provider.js";
|
|
17
25
|
export { createModel } from "./runtime/createModel.js";
|
|
18
26
|
export { SdkAgent } from "./runtime/SdkAgent.js";
|
|
19
27
|
export type { AgentPlugin, SendContext } from "./runtime/SdkAgent.js";
|
|
20
28
|
export { createAgent } from "./runtime/createAgent.js";
|
|
21
|
-
export { McpConnectionManager } from "./
|
|
22
|
-
export type { McpConnectOptions } from "./
|
|
23
|
-
export { SdkCallbackTool } from "./
|
|
24
|
-
export type { SdkCallbackToolOptions } from "./
|
|
29
|
+
export { McpConnectionManager } from "./scope/plugins/mcp/McpConnectionManager.js";
|
|
30
|
+
export type { McpConnectOptions } from "./scope/plugins/mcp/McpConnectionManager.js";
|
|
31
|
+
export { SdkCallbackTool } from "./scope/plugins/builtin/SdkCallbackTool.js";
|
|
32
|
+
export type { SdkCallbackToolOptions } from "./scope/plugins/builtin/SdkCallbackTool.js";
|
|
25
33
|
export { TaskMigrationService } from "./runtime/TaskMigrationService.js";
|
|
26
34
|
export type { MigrationContext, MigrationStrategy, TaskMigrationServiceOptions, } from "./runtime/TaskMigrationService.js";
|
|
27
|
-
export { AutoMigratePlugin } from "./
|
|
28
|
-
export type { AutoMigrateOptions } from "./
|
|
29
|
-
export { AutoRefreshToolsPlugin } from "./
|
|
30
|
-
export { ContextGuardPlugin } from "./
|
|
31
|
-
export type { ContextGuardOptions } from "./
|
|
32
|
-
export { UnknownToolHintPlugin } from "./
|
|
33
|
-
export { BUILTIN_TOOL_CLASSES } from "./
|
|
34
|
-
export { CwdTool, ReadFileTool, InspectFileTool, WriteFileTool, ExecTool, MkdirTool, RmTool, GlobTool, LsTool, ExistTool, FindTextTool, DownloadFileTool, RenameTool, CopyTool, BatchEditTool, EditTool, ExecAsyncTool, SleepTool, } from "./
|
|
35
|
-
export { GenerateImageTool } from "./
|
|
36
|
-
export { ViewImageTool } from "./
|
|
37
|
-
export { createLoadSkillTool, createCallSkillSubAgentTool } from "./
|
|
38
|
-
export { createLoadMcpTool, createCallMcpTool, createReadMcpResourceTool } from "./
|
|
39
|
-
export { createSubAgentTool } from "./
|
|
35
|
+
export { AutoMigratePlugin } from "./agent-plugins/AutoMigratePlugin.js";
|
|
36
|
+
export type { AutoMigrateOptions } from "./agent-plugins/AutoMigratePlugin.js";
|
|
37
|
+
export { AutoRefreshToolsPlugin } from "./agent-plugins/AutoRefreshToolsPlugin.js";
|
|
38
|
+
export { ContextGuardPlugin } from "./agent-plugins/ContextGuardPlugin.js";
|
|
39
|
+
export type { ContextGuardOptions } from "./agent-plugins/ContextGuardPlugin.js";
|
|
40
|
+
export { UnknownToolHintPlugin } from "./agent-plugins/UnknownToolHintPlugin.js";
|
|
41
|
+
export { BUILTIN_TOOL_CLASSES } from "./scope/plugins/builtin/index.js";
|
|
42
|
+
export { CwdTool, ReadFileTool, InspectFileTool, WriteFileTool, ExecTool, MkdirTool, RmTool, GlobTool, LsTool, ExistTool, FindTextTool, DownloadFileTool, RenameTool, CopyTool, BatchEditTool, EditTool, ExecAsyncTool, SleepTool, } from "./scope/plugins/builtin/index.js";
|
|
43
|
+
export { GenerateImageTool } from "./scope/plugins/builtin/GenerateImageTool.js";
|
|
44
|
+
export { ViewImageTool } from "./scope/plugins/builtin/ViewImageTool.js";
|
|
45
|
+
export { createLoadSkillTool, createCallSkillSubAgentTool } from "./scope/plugins/skills/skillTools.js";
|
|
46
|
+
export { createLoadMcpTool, createCallMcpTool, createReadMcpResourceTool } from "./scope/plugins/mcp/mcpTools.js";
|
|
47
|
+
export { createSubAgentTool } from "./scope/plugins/subagents/subAgentTools.js";
|
|
40
48
|
export { getLogger, setLogger } from "./shared/logger.js";
|
|
41
49
|
export type { Logger, LogFunctions } from "./shared/logger.js";
|
|
42
50
|
export { SdkError, ContextOverflowError } from "./shared/errors.js";
|
package/dist/index.js
CHANGED
|
@@ -1,38 +1,45 @@
|
|
|
1
1
|
// 能力管线
|
|
2
|
-
export { PermissionEvaluator } from "./
|
|
3
|
-
export { createDisclosureParam } from "./
|
|
2
|
+
export { PermissionEvaluator } from "./scope/PermissionEvaluator.js";
|
|
3
|
+
export { createDisclosureParam } from "./scope/disclosure.js";
|
|
4
4
|
// 发现
|
|
5
|
-
export { discoverBuiltinTools } from "./
|
|
6
|
-
export { discoverSubAgents } from "./
|
|
7
|
-
export { discoverSkills, readSkill } from "./
|
|
8
|
-
export { discoverMcpServers } from "./
|
|
9
|
-
export { discoverUserTools } from "./
|
|
5
|
+
export { discoverBuiltinTools } from "./scope/plugins/builtin/discover.js";
|
|
6
|
+
export { discoverSubAgents } from "./scope/plugins/subagents/discover.js";
|
|
7
|
+
export { discoverSkills, readSkill } from "./scope/plugins/skills/discover.js";
|
|
8
|
+
export { discoverMcpServers } from "./scope/plugins/mcp/discover.js";
|
|
9
|
+
export { discoverUserTools } from "./scope/plugins/usertools/discover.js";
|
|
10
|
+
// Scope — 全局上下文 + 能力装配编排容器
|
|
11
|
+
export { Scope } from "./scope/Scope.js";
|
|
12
|
+
export { BuiltinToolsScopePlugin } from "./scope/plugins/builtin/BuiltinToolsScopePlugin.js";
|
|
13
|
+
export { UserToolsScopePlugin } from "./scope/plugins/usertools/UserToolsScopePlugin.js";
|
|
14
|
+
export { SkillsScopePlugin } from "./scope/plugins/skills/SkillsScopePlugin.js";
|
|
15
|
+
export { McpScopePlugin } from "./scope/plugins/mcp/McpScopePlugin.js";
|
|
16
|
+
export { SubAgentsScopePlugin } from "./scope/plugins/subagents/SubAgentsScopePlugin.js";
|
|
17
|
+
export { allInOne } from "./scope/plugins/allInOne.js";
|
|
10
18
|
// 配置 — ConfigManager
|
|
11
19
|
export { ConfigManager, DEFAULT_AGENT_ID, DEFAULT_AGENT_DEFINITION, DEFAULT_SUBAGENT_ID, DEFAULT_SUBAGENT_DEFINITION, DEFAULT_APP_CONFIG, DEFAULT_MCP_CONFIG, CONFIG_SUB_DIRS, } from "./config/ConfigManager.js";
|
|
12
20
|
// CRUD — 实体仓储(仅 Agent 定义等能力实体)
|
|
13
21
|
export { EntityRepository } from "./shared/EntityRepository.js";
|
|
14
22
|
export { AgentRepository } from "./crud/AgentRepository.js";
|
|
15
23
|
// 运行时
|
|
16
|
-
export { Provider } from "./runtime/Provider.js";
|
|
17
24
|
export { createModel } from "./runtime/createModel.js";
|
|
18
25
|
export { SdkAgent } from "./runtime/SdkAgent.js";
|
|
19
26
|
export { createAgent } from "./runtime/createAgent.js";
|
|
20
|
-
export { McpConnectionManager } from "./
|
|
21
|
-
export { SdkCallbackTool } from "./
|
|
27
|
+
export { McpConnectionManager } from "./scope/plugins/mcp/McpConnectionManager.js";
|
|
28
|
+
export { SdkCallbackTool } from "./scope/plugins/builtin/SdkCallbackTool.js";
|
|
22
29
|
export { TaskMigrationService } from "./runtime/TaskMigrationService.js";
|
|
23
30
|
// 插件
|
|
24
|
-
export { AutoMigratePlugin } from "./
|
|
25
|
-
export { AutoRefreshToolsPlugin } from "./
|
|
26
|
-
export { ContextGuardPlugin } from "./
|
|
27
|
-
export { UnknownToolHintPlugin } from "./
|
|
31
|
+
export { AutoMigratePlugin } from "./agent-plugins/AutoMigratePlugin.js";
|
|
32
|
+
export { AutoRefreshToolsPlugin } from "./agent-plugins/AutoRefreshToolsPlugin.js";
|
|
33
|
+
export { ContextGuardPlugin } from "./agent-plugins/ContextGuardPlugin.js";
|
|
34
|
+
export { UnknownToolHintPlugin } from "./agent-plugins/UnknownToolHintPlugin.js";
|
|
28
35
|
// 工具 — 内置工具类 + 动态工具工厂
|
|
29
|
-
export { BUILTIN_TOOL_CLASSES } from "./
|
|
30
|
-
export { CwdTool, ReadFileTool, InspectFileTool, WriteFileTool, ExecTool, MkdirTool, RmTool, GlobTool, LsTool, ExistTool, FindTextTool, DownloadFileTool, RenameTool, CopyTool, BatchEditTool, EditTool, ExecAsyncTool, SleepTool, } from "./
|
|
31
|
-
export { GenerateImageTool } from "./
|
|
32
|
-
export { ViewImageTool } from "./
|
|
33
|
-
export { createLoadSkillTool, createCallSkillSubAgentTool } from "./
|
|
34
|
-
export { createLoadMcpTool, createCallMcpTool, createReadMcpResourceTool } from "./
|
|
35
|
-
export { createSubAgentTool } from "./
|
|
36
|
+
export { BUILTIN_TOOL_CLASSES } from "./scope/plugins/builtin/index.js";
|
|
37
|
+
export { CwdTool, ReadFileTool, InspectFileTool, WriteFileTool, ExecTool, MkdirTool, RmTool, GlobTool, LsTool, ExistTool, FindTextTool, DownloadFileTool, RenameTool, CopyTool, BatchEditTool, EditTool, ExecAsyncTool, SleepTool, } from "./scope/plugins/builtin/index.js";
|
|
38
|
+
export { GenerateImageTool } from "./scope/plugins/builtin/GenerateImageTool.js";
|
|
39
|
+
export { ViewImageTool } from "./scope/plugins/builtin/ViewImageTool.js";
|
|
40
|
+
export { createLoadSkillTool, createCallSkillSubAgentTool } from "./scope/plugins/skills/skillTools.js";
|
|
41
|
+
export { createLoadMcpTool, createCallMcpTool, createReadMcpResourceTool } from "./scope/plugins/mcp/mcpTools.js";
|
|
42
|
+
export { createSubAgentTool } from "./scope/plugins/subagents/subAgentTools.js";
|
|
36
43
|
// 共享
|
|
37
44
|
export { getLogger, setLogger } from "./shared/logger.js";
|
|
38
45
|
export { SdkError, ContextOverflowError } from "./shared/errors.js";
|
|
@@ -2,14 +2,14 @@ import type OpenAI from "openai";
|
|
|
2
2
|
import { Agent } from "@ai-zen/agents-core";
|
|
3
3
|
import type { AgentNS, Tool } from "@ai-zen/agents-core";
|
|
4
4
|
import type { AgentDefinition } from "../types/index.js";
|
|
5
|
-
import type {
|
|
5
|
+
import type { Scope } from "../scope/Scope.js";
|
|
6
6
|
export type { AgentPlugin, SendContext } from "@ai-zen/agents-core";
|
|
7
7
|
/**
|
|
8
8
|
* SDK Agent — 继承 Core Agent,携带 SDK 层额外信息。
|
|
9
9
|
*
|
|
10
10
|
* Core Agent 不感知权限、文件系统等业务逻辑;
|
|
11
11
|
* SdkAgent 在 Core Agent 基础上增加了 SDK 层需要的元数据:
|
|
12
|
-
* -
|
|
12
|
+
* - scope:全局 Scope 实例
|
|
13
13
|
* - definition:Agent 原始定义(含权限 permissions)
|
|
14
14
|
*
|
|
15
15
|
* 插件能力(use / init / send 钩子分发)继承自 Core Agent,此处不再重复实现。
|
|
@@ -17,12 +17,12 @@ export type { AgentPlugin, SendContext } from "@ai-zen/agents-core";
|
|
|
17
17
|
* 权限统一从 `definition.permissions` 读取,不再单独持有。
|
|
18
18
|
*/
|
|
19
19
|
export declare class SdkAgent extends Agent {
|
|
20
|
-
/** 全局
|
|
21
|
-
readonly
|
|
20
|
+
/** 全局 Scope 实例 */
|
|
21
|
+
readonly scope: Scope;
|
|
22
22
|
/** Agent 原始定义 */
|
|
23
23
|
readonly definition: AgentDefinition;
|
|
24
24
|
constructor(params: {
|
|
25
|
-
|
|
25
|
+
scope: Scope;
|
|
26
26
|
definition: AgentDefinition;
|
|
27
27
|
client: OpenAI;
|
|
28
28
|
model: string;
|
package/dist/runtime/SdkAgent.js
CHANGED
|
@@ -4,7 +4,7 @@ import { Agent } from "@ai-zen/agents-core";
|
|
|
4
4
|
*
|
|
5
5
|
* Core Agent 不感知权限、文件系统等业务逻辑;
|
|
6
6
|
* SdkAgent 在 Core Agent 基础上增加了 SDK 层需要的元数据:
|
|
7
|
-
* -
|
|
7
|
+
* - scope:全局 Scope 实例
|
|
8
8
|
* - definition:Agent 原始定义(含权限 permissions)
|
|
9
9
|
*
|
|
10
10
|
* 插件能力(use / init / send 钩子分发)继承自 Core Agent,此处不再重复实现。
|
|
@@ -12,8 +12,8 @@ import { Agent } from "@ai-zen/agents-core";
|
|
|
12
12
|
* 权限统一从 `definition.permissions` 读取,不再单独持有。
|
|
13
13
|
*/
|
|
14
14
|
export class SdkAgent extends Agent {
|
|
15
|
-
/** 全局
|
|
16
|
-
|
|
15
|
+
/** 全局 Scope 实例 */
|
|
16
|
+
scope;
|
|
17
17
|
/** Agent 原始定义 */
|
|
18
18
|
definition;
|
|
19
19
|
constructor(params) {
|
|
@@ -25,7 +25,7 @@ export class SdkAgent extends Agent {
|
|
|
25
25
|
tools: params.tools,
|
|
26
26
|
allowJsonParseError: params.allowJsonParseError,
|
|
27
27
|
});
|
|
28
|
-
this.
|
|
28
|
+
this.scope = params.scope;
|
|
29
29
|
this.definition = params.definition;
|
|
30
30
|
}
|
|
31
31
|
}
|
|
@@ -55,7 +55,7 @@ export interface TaskMigrationServiceOptions {
|
|
|
55
55
|
*
|
|
56
56
|
* 一个服务实例对应一次迁移上下文。它**不持有**任何模型调用——生成交接文档时
|
|
57
57
|
* 默认复用传入 `agent`(`SdkAgent`)自身的 `client` / `model` / `modelConfig`,
|
|
58
|
-
* 因此无需
|
|
58
|
+
* 因此无需 Scope、无需独立「迁移 Agent」对象,也无需自建 OpenAI 客户端。
|
|
59
59
|
* 如需用不同模型生成交接文档,可在构造时显式传入 `client` / `model` / `modelConfig`,
|
|
60
60
|
* 未传则 migrate 时回退到 agent 自带的配置。
|
|
61
61
|
*
|
|
@@ -5,7 +5,7 @@ import { getLogger } from "../shared/logger.js";
|
|
|
5
5
|
*
|
|
6
6
|
* 一个服务实例对应一次迁移上下文。它**不持有**任何模型调用——生成交接文档时
|
|
7
7
|
* 默认复用传入 `agent`(`SdkAgent`)自身的 `client` / `model` / `modelConfig`,
|
|
8
|
-
* 因此无需
|
|
8
|
+
* 因此无需 Scope、无需独立「迁移 Agent」对象,也无需自建 OpenAI 客户端。
|
|
9
9
|
* 如需用不同模型生成交接文档,可在构造时显式传入 `client` / `model` / `modelConfig`,
|
|
10
10
|
* 未传则 migrate 时回退到 agent 自带的配置。
|
|
11
11
|
*
|
|
@@ -143,7 +143,7 @@ export class TaskMigrationService {
|
|
|
143
143
|
const historyText = TaskMigrationService.serializeMessages(agent.messages.filter((m) => !m.omit));
|
|
144
144
|
const messageCountBefore = agent.messages.length;
|
|
145
145
|
// 生成交接文档所用模型调用:优先使用构造时传入的 client/model/modelConfig,
|
|
146
|
-
// 未传则回退到 agent 自带的(无需
|
|
146
|
+
// 未传则回退到 agent 自带的(无需 Scope / 独立迁移 Agent)。
|
|
147
147
|
const client = this.client ?? agent.client;
|
|
148
148
|
const model = this.model ?? agent.model;
|
|
149
149
|
const modelConfig = this.modelConfig ?? agent.modelConfig;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { SdkAgent } from "./SdkAgent.js";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Scope } from "../scope/Scope.js";
|
|
3
3
|
/**
|
|
4
4
|
* 从磁盘创建 Agent。
|
|
5
5
|
*
|
|
6
|
-
* 通过
|
|
6
|
+
* 通过 Scope 获取已发现的能力,读取 Agent 定义,过滤并实例化工具,产出 SdkAgent。
|
|
7
7
|
*
|
|
8
8
|
* ```ts
|
|
9
|
-
* const agent = await createAgent(
|
|
9
|
+
* const agent = await createAgent(scope, "my-agent");
|
|
10
10
|
* // agent 是 SdkAgent,可直接注册插件、发送消息
|
|
11
11
|
* ```
|
|
12
12
|
*/
|
|
13
|
-
export declare function createAgent(
|
|
13
|
+
export declare function createAgent(scope: Scope, agentId: string): Promise<SdkAgent>;
|
|
@@ -4,22 +4,22 @@ import { createModel } from "./createModel.js";
|
|
|
4
4
|
/**
|
|
5
5
|
* 从磁盘创建 Agent。
|
|
6
6
|
*
|
|
7
|
-
* 通过
|
|
7
|
+
* 通过 Scope 获取已发现的能力,读取 Agent 定义,过滤并实例化工具,产出 SdkAgent。
|
|
8
8
|
*
|
|
9
9
|
* ```ts
|
|
10
|
-
* const agent = await createAgent(
|
|
10
|
+
* const agent = await createAgent(scope, "my-agent");
|
|
11
11
|
* // agent 是 SdkAgent,可直接注册插件、发送消息
|
|
12
12
|
* ```
|
|
13
13
|
*/
|
|
14
|
-
export async function createAgent(
|
|
15
|
-
const definition = await new AgentRepository(
|
|
14
|
+
export async function createAgent(scope, agentId) {
|
|
15
|
+
const definition = await new AgentRepository(scope.agentsDir).read(agentId);
|
|
16
16
|
if (!definition)
|
|
17
17
|
throw new Error(`Agent "${agentId}" 不存在`);
|
|
18
|
-
const modelId = definition.modelId ??
|
|
18
|
+
const modelId = definition.modelId ?? scope.config.defaultModel;
|
|
19
19
|
if (!modelId)
|
|
20
20
|
throw new Error("未指定模型且无默认模型");
|
|
21
|
-
const { client, model, modelConfig } = createModel(
|
|
22
|
-
const tools =
|
|
21
|
+
const { client, model, modelConfig } = createModel(scope, modelId);
|
|
22
|
+
const tools = scope.buildTools(definition, {
|
|
23
23
|
exclude: {
|
|
24
24
|
subagents: definition.function?.name
|
|
25
25
|
? [definition.function.name]
|
|
@@ -27,7 +27,7 @@ export async function createAgent(provider, agentId) {
|
|
|
27
27
|
},
|
|
28
28
|
});
|
|
29
29
|
const agent = new SdkAgent({
|
|
30
|
-
|
|
30
|
+
scope,
|
|
31
31
|
definition,
|
|
32
32
|
client,
|
|
33
33
|
model,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import OpenAI from "openai";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Scope } from "../scope/Scope.js";
|
|
3
3
|
/**
|
|
4
4
|
* Agent 模型装配结果:openai SDK client + 模型名 + 模型参数。
|
|
5
5
|
* Agent 构造时直接消费此结构。
|
|
@@ -13,9 +13,9 @@ export interface AgentModel {
|
|
|
13
13
|
modelConfig?: Record<string, unknown>;
|
|
14
14
|
}
|
|
15
15
|
/**
|
|
16
|
-
* 模型工厂 — 根据 modelId 和
|
|
16
|
+
* 模型工厂 — 根据 modelId 和 Scope 装配 openai SDK client。
|
|
17
17
|
*
|
|
18
18
|
* 端点(baseUrl / apiKey)来自 config.endpoints,发送给 API 的模型名 = modelName || id。
|
|
19
19
|
* 任何 OpenAI 兼容端点(OpenAI / 智谱 BigModel / DeepSeek 等)均可通过 baseURL 接入。
|
|
20
20
|
*/
|
|
21
|
-
export declare function createModel(
|
|
21
|
+
export declare function createModel(scope: Scope, modelId: string): AgentModel;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import OpenAI from "openai";
|
|
2
2
|
/**
|
|
3
|
-
* 模型工厂 — 根据 modelId 和
|
|
3
|
+
* 模型工厂 — 根据 modelId 和 Scope 装配 openai SDK client。
|
|
4
4
|
*
|
|
5
5
|
* 端点(baseUrl / apiKey)来自 config.endpoints,发送给 API 的模型名 = modelName || id。
|
|
6
6
|
* 任何 OpenAI 兼容端点(OpenAI / 智谱 BigModel / DeepSeek 等)均可通过 baseURL 接入。
|
|
7
7
|
*/
|
|
8
|
-
export function createModel(
|
|
9
|
-
const config =
|
|
8
|
+
export function createModel(scope, modelId) {
|
|
9
|
+
const config = scope.config;
|
|
10
10
|
const modelConfig = config.models.find((m) => m.id === modelId);
|
|
11
11
|
if (!modelConfig)
|
|
12
12
|
throw new Error(`模型 "${modelId}" 不存在`);
|