@ai-zen/agents-sdk 1.0.0-alpha.25 → 1.0.0-alpha.26
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 +134 -0
- package/README.md +5 -5
- package/README.zh.md +5 -5
- package/dist/agent-plugins/AutoMigratePlugin.js +1 -3
- package/dist/agent-plugins/AutoRefreshToolsPlugin.js +1 -3
- package/dist/agent-plugins/ContextGuardPlugin.d.ts +15 -1
- package/dist/agent-plugins/ContextGuardPlugin.js +11 -1
- package/dist/config/ConfigManager.js +1 -1
- package/dist/config/constants.js +5 -8
- package/dist/config/migrate.js +1 -3
- package/dist/index.d.ts +5 -5
- package/dist/index.js +3 -3
- package/dist/runtime/HandoffService.d.ts +5 -4
- package/dist/runtime/HandoffService.js +17 -14
- package/dist/runtime/createAgent.js +1 -3
- package/dist/scope/Scope.d.ts +3 -1
- package/dist/scope/Scope.js +3 -1
- package/dist/scope/plugins/builtin/BatchEditTool.js +15 -8
- package/dist/scope/plugins/builtin/DownloadFileTool.d.ts +1 -0
- package/dist/scope/plugins/builtin/DownloadFileTool.js +54 -30
- package/dist/scope/plugins/builtin/EditTool.js +13 -18
- package/dist/scope/plugins/builtin/ExecTool.js +127 -18
- package/dist/scope/plugins/builtin/FindTextTool.js +6 -1
- package/dist/scope/plugins/builtin/GenerateImageTool.js +80 -14
- package/dist/scope/plugins/builtin/GlobTool.js +6 -1
- package/dist/scope/plugins/builtin/SpawnTool.js +28 -45
- package/dist/scope/plugins/builtin/ViewImageTool.js +6 -2
- package/dist/scope/plugins/builtin/searchBase.d.ts +9 -0
- package/dist/scope/plugins/builtin/searchBase.js +17 -0
- package/dist/scope/plugins/builtin/test-helpers.d.ts +3 -3
- package/dist/scope/plugins/builtin/test-helpers.js +3 -3
- package/dist/scope/plugins/builtin/textEdit.d.ts +17 -0
- package/dist/scope/plugins/builtin/textEdit.js +37 -0
- package/dist/scope/plugins/mcp/McpConnectionManager.d.ts +9 -1
- package/dist/scope/plugins/mcp/McpConnectionManager.js +88 -9
- package/dist/scope/plugins/mcp/McpScopePlugin.js +7 -6
- package/dist/scope/plugins/mcp/mcpTools.d.ts +2 -2
- package/dist/scope/plugins/mcp/mcpTools.js +42 -10
- package/dist/scope/plugins/skills/SkillsScopePlugin.js +2 -3
- package/dist/scope/plugins/skills/discover.js +25 -5
- package/dist/scope/plugins/skills/skillTools.js +13 -1
- package/dist/scope/plugins/subagents/SubAgentsScopePlugin.js +1 -3
- package/dist/scope/plugins/usertools/discover.js +8 -2
- package/dist/shared/EntityRepository.js +1 -3
- package/dist/shared/content-blocks.d.ts +5 -12
- package/dist/shared/content-blocks.js +1 -1
- package/dist/types/index.d.ts +48 -0
- package/package.json +4 -5
|
@@ -18,7 +18,9 @@
|
|
|
18
18
|
* | 内联体积超过上限且无法上传 | 抛错(不静默塞进请求体) |
|
|
19
19
|
*/
|
|
20
20
|
import type { AgentNS } from "@ai-zen/agents-core";
|
|
21
|
-
import type { AppConfig, Endpoint, Model } from "../types/index.js";
|
|
21
|
+
import type { AppConfig, Endpoint, Model, ToolEnvDeps, UploadFn } from "../types/index.js";
|
|
22
|
+
/** 上传函数类型(定义在 types,此处再导出方便既有引用) */
|
|
23
|
+
export type { UploadFn };
|
|
22
24
|
/** 扩展名 → MIME。图片走视觉通道,其余走 `file` 块 */
|
|
23
25
|
export declare const MIME_BY_EXT: Record<string, string>;
|
|
24
26
|
/** 按扩展名推断 MIME;未知扩展名返回 undefined */
|
|
@@ -51,13 +53,6 @@ export type FileSource = {
|
|
|
51
53
|
mime: string;
|
|
52
54
|
filename?: string;
|
|
53
55
|
};
|
|
54
|
-
/** Files API 上传函数签名(可注入,便于测试与替换实现) */
|
|
55
|
-
export type UploadFn = (input: {
|
|
56
|
-
endpoint: Endpoint;
|
|
57
|
-
data: Uint8Array;
|
|
58
|
-
filename: string;
|
|
59
|
-
signal?: AbortSignal;
|
|
60
|
-
}) => Promise<string>;
|
|
61
56
|
export interface FileToSectionInput {
|
|
62
57
|
source: FileSource;
|
|
63
58
|
/** 当前模型所用端点:决定能否走 Files API */
|
|
@@ -67,10 +62,8 @@ export interface FileToSectionInput {
|
|
|
67
62
|
signal?: AbortSignal;
|
|
68
63
|
/** 覆盖内联体积上限 */
|
|
69
64
|
maxInlineBytes?: number;
|
|
70
|
-
/**
|
|
71
|
-
deps?:
|
|
72
|
-
upload?: UploadFn;
|
|
73
|
-
};
|
|
65
|
+
/** 依赖注入(测试 / 宿主用),缺省走 OpenAI SDK 的 Files API */
|
|
66
|
+
deps?: ToolEnvDeps;
|
|
74
67
|
}
|
|
75
68
|
export interface FileToSectionResult {
|
|
76
69
|
section: AgentNS.MessageContentSection;
|
|
@@ -68,7 +68,7 @@ export const DEFAULT_MAX_INLINE_BYTES = 8 * 1024 * 1024;
|
|
|
68
68
|
export function resolveModelAndEndpoint(config, apiModelName) {
|
|
69
69
|
const models = config.models ?? [];
|
|
70
70
|
const endpoints = config.endpoints ?? [];
|
|
71
|
-
const findEndpoint = (id) => (id ? endpoints.find((e) => e.id === id) ?? null : null);
|
|
71
|
+
const findEndpoint = (id) => (id ? (endpoints.find((e) => e.id === id) ?? null) : null);
|
|
72
72
|
const byApiName = apiModelName
|
|
73
73
|
? models.find((m) => (m.modelName ?? m.id) === apiModelName)
|
|
74
74
|
: undefined;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -222,6 +222,52 @@ export interface AppConfig {
|
|
|
222
222
|
*/
|
|
223
223
|
abortedToolRoundStrategy?: AbortedToolRoundStrategy;
|
|
224
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Files API 上传函数签名(默认实现走 OpenAI SDK 的 `POST {baseUrl}/files`)。
|
|
227
|
+
*
|
|
228
|
+
* 出网动作做成可注入的依赖,而不是让测试去 mock `openai` 模块:模块级 mock 在
|
|
229
|
+
* `isolate: false` 的共享模块图里会因加载顺序失效(谁先把真实 SDK 拉进缓存,
|
|
230
|
+
* 后注册的 mock 就再也不生效)。
|
|
231
|
+
*/
|
|
232
|
+
export type UploadFn = (input: {
|
|
233
|
+
endpoint: Endpoint;
|
|
234
|
+
data: Uint8Array;
|
|
235
|
+
filename: string;
|
|
236
|
+
signal?: AbortSignal;
|
|
237
|
+
}) => Promise<string>;
|
|
238
|
+
/** 图片生成函数签名(默认实现走 OpenAI SDK 的 `images.generate`) */
|
|
239
|
+
export type GenerateImageFn = (input: {
|
|
240
|
+
endpoint: Endpoint;
|
|
241
|
+
/** 发给端点的图片模型名(`ImageModel.modelName ?? id`) */
|
|
242
|
+
model: string;
|
|
243
|
+
prompt: string;
|
|
244
|
+
size?: string;
|
|
245
|
+
quality?: string;
|
|
246
|
+
signal?: AbortSignal;
|
|
247
|
+
}) => Promise<{
|
|
248
|
+
created?: number;
|
|
249
|
+
/**
|
|
250
|
+
* 端点返回的图片列表。二选一:
|
|
251
|
+
* - `url`:临时图片链接(多数厂商);
|
|
252
|
+
* - `b64_json`:base64 内联(部分模型只返回它),由工具落盘后给出本地路径。
|
|
253
|
+
*/
|
|
254
|
+
data?: {
|
|
255
|
+
url?: string;
|
|
256
|
+
b64_json?: string;
|
|
257
|
+
}[];
|
|
258
|
+
}>;
|
|
259
|
+
/**
|
|
260
|
+
* 外部依赖注入点 — 所有出网动作的唯一出口。
|
|
261
|
+
*
|
|
262
|
+
* 缺省(不传)时全部走真实 OpenAI SDK;测试与宿主(CLI / Desktop)可按需替换,
|
|
263
|
+
* 这样业务代码里的网络调用不再需要 `vi.mock("openai")` 之类打穿模块图的技巧。
|
|
264
|
+
*/
|
|
265
|
+
export interface ToolEnvDeps {
|
|
266
|
+
/** 上传文件到端点 Files API,默认 `POST {baseUrl}/files`(purpose=user_data) */
|
|
267
|
+
upload?: UploadFn;
|
|
268
|
+
/** 调用端点生成图片,默认 `client.images.generate` */
|
|
269
|
+
generateImage?: GenerateImageFn;
|
|
270
|
+
}
|
|
225
271
|
/**
|
|
226
272
|
* 工具环境 — Scope 的能力插件在实例化内置工具时注入的环境信息。
|
|
227
273
|
*
|
|
@@ -233,6 +279,8 @@ export interface ToolEnv {
|
|
|
233
279
|
cwd: string;
|
|
234
280
|
/** 应用配置 */
|
|
235
281
|
config: AppConfig;
|
|
282
|
+
/** 外部依赖注入点(默认全部走真实 OpenAI SDK) */
|
|
283
|
+
deps?: ToolEnvDeps;
|
|
236
284
|
}
|
|
237
285
|
/** MCP 连接状态 */
|
|
238
286
|
export type McpConnectionState = "disconnected" | "connecting" | "connected" | "error";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-zen/agents-sdk",
|
|
3
|
-
"version": "1.0.0-alpha.
|
|
3
|
+
"version": "1.0.0-alpha.26",
|
|
4
4
|
"description": "AI-Zen Agents SDK — shared business logic for CLI and Desktop",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"author": "LZQCN",
|
|
26
26
|
"license": "MIT",
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@ai-zen/agents-core": "^4.5.
|
|
28
|
+
"@ai-zen/agents-core": "^4.5.4",
|
|
29
29
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
30
30
|
"dayjs": "^1.11.21",
|
|
31
31
|
"openai": "^7.5.0"
|
|
@@ -48,10 +48,9 @@
|
|
|
48
48
|
"build": "tsc",
|
|
49
49
|
"format": "prettier --write .",
|
|
50
50
|
"format:check": "prettier --check .",
|
|
51
|
-
"pretest": "tsc --noEmit",
|
|
51
|
+
"pretest": "tsc --noEmit -p tsconfig.test.json",
|
|
52
52
|
"test": "vitest run",
|
|
53
|
-
"test:integration": "npm run pretest && vitest run --config vitest.integration.config.ts",
|
|
54
53
|
"test:e2e": "npm run pretest && vitest run --config vitest.e2e.config.ts",
|
|
55
|
-
"test:all": "npm run pretest && vitest run &&
|
|
54
|
+
"test:all": "npm run pretest && vitest run && npm run build && vitest run --config vitest.e2e.config.ts"
|
|
56
55
|
}
|
|
57
56
|
}
|