@ai-zen/agents-sdk 0.6.0 → 0.7.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 +37 -0
- package/README.md +10 -7
- package/README.zh.md +10 -7
- package/dist/capabilities/discovery/builtin.d.ts +3 -3
- package/dist/capabilities/discovery/builtin.js +4 -12
- package/dist/capabilities/implements/builtin/FindTextTool.d.ts +3 -0
- package/dist/capabilities/implements/builtin/FindTextTool.js +69 -23
- package/dist/capabilities/implements/builtin/GenerateImageTool.d.ts +8 -8
- package/dist/capabilities/implements/builtin/GenerateImageTool.js +26 -27
- package/dist/capabilities/implements/builtin/ViewImageTool.d.ts +24 -0
- package/dist/capabilities/implements/builtin/ViewImageTool.js +109 -0
- package/dist/capabilities/implements/builtin/index.d.ts +6 -4
- package/dist/capabilities/implements/builtin/index.js +8 -4
- package/dist/capabilities/implements/skillTools.js +5 -5
- package/dist/capabilities/implements/subAgentTools.js +17 -8
- package/dist/config/constants.js +12 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/plugin/AutoMigratePlugin.d.ts +1 -1
- package/dist/plugin/AutoMigratePlugin.js +1 -1
- package/dist/plugin/AutoRefreshToolsPlugin.d.ts +1 -1
- package/dist/plugin/AutoRefreshToolsPlugin.js +2 -2
- package/dist/plugin/ContextGuardPlugin.d.ts +2 -2
- package/dist/plugin/ContextGuardPlugin.js +1 -1
- package/dist/plugin/UnknownToolHintPlugin.d.ts +21 -0
- package/dist/plugin/UnknownToolHintPlugin.js +30 -0
- package/dist/runtime/Provider.d.ts +8 -7
- package/dist/runtime/Provider.js +14 -4
- package/dist/runtime/SdkAgent.d.ts +14 -107
- package/dist/runtime/SdkAgent.js +8 -120
- package/dist/runtime/SdkCallbackTool.d.ts +12 -4
- package/dist/runtime/SdkCallbackTool.js +5 -2
- package/dist/runtime/createAgent.js +4 -3
- package/dist/runtime/createModel.d.ts +17 -4
- package/dist/runtime/createModel.js +15 -11
- package/dist/types/index.d.ts +2 -0
- package/package.json +3 -2
|
@@ -19,11 +19,14 @@ export class SdkCallbackTool extends Tool {
|
|
|
19
19
|
super();
|
|
20
20
|
this.env = options.env;
|
|
21
21
|
}
|
|
22
|
-
/** 桥接 core 的 Tool.exec:解析参数 → call →
|
|
22
|
+
/** 桥接 core 的 Tool.exec:解析参数 → call → 序列化/透传内容块 */
|
|
23
23
|
async exec(ctx) {
|
|
24
|
-
const result = await this.call(ctx.
|
|
24
|
+
const result = await this.call(ctx.parsedArgs, ctx);
|
|
25
25
|
if (typeof result === "string")
|
|
26
26
|
return result;
|
|
27
|
+
// 内容块数组(图片/文件等)直接透传,让模型能收到结构化内容
|
|
28
|
+
if (Array.isArray(result))
|
|
29
|
+
return result;
|
|
27
30
|
// JSON.stringify(undefined) 返回 undefined(非字符串),会破坏 Promise<string> 契约
|
|
28
31
|
return JSON.stringify(result) ?? "";
|
|
29
32
|
}
|
|
@@ -18,8 +18,8 @@ export async function createAgent(provider, agentId) {
|
|
|
18
18
|
const modelId = definition.modelId ?? provider.config.defaultModel;
|
|
19
19
|
if (!modelId)
|
|
20
20
|
throw new Error("未指定模型且无默认模型");
|
|
21
|
-
const model = createModel(provider, modelId);
|
|
22
|
-
const tools = provider.buildTools(definition
|
|
21
|
+
const { client, model, modelConfig } = createModel(provider, modelId);
|
|
22
|
+
const tools = provider.buildTools(definition, {
|
|
23
23
|
exclude: {
|
|
24
24
|
subagents: definition.function?.name
|
|
25
25
|
? [definition.function.name]
|
|
@@ -29,10 +29,11 @@ export async function createAgent(provider, agentId) {
|
|
|
29
29
|
const agent = new SdkAgent({
|
|
30
30
|
provider,
|
|
31
31
|
definition,
|
|
32
|
+
client,
|
|
32
33
|
model,
|
|
34
|
+
modelConfig,
|
|
33
35
|
messages: definition.messages,
|
|
34
36
|
tools,
|
|
35
|
-
permissions: definition.permissions,
|
|
36
37
|
});
|
|
37
38
|
return agent;
|
|
38
39
|
}
|
|
@@ -1,8 +1,21 @@
|
|
|
1
|
-
import
|
|
1
|
+
import OpenAI from "openai";
|
|
2
2
|
import type { Provider } from "./Provider.js";
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Agent 模型装配结果:openai SDK client + 模型名 + 模型参数。
|
|
5
|
+
* Agent 构造时直接消费此结构。
|
|
6
|
+
*/
|
|
7
|
+
export interface AgentModel {
|
|
8
|
+
/** openai 官方 SDK 客户端 */
|
|
9
|
+
client: OpenAI;
|
|
10
|
+
/** 发送给 API 的模型名 */
|
|
11
|
+
model: string;
|
|
12
|
+
/** 模型参数(defaultParams),透传给 API(可含厂商特有字段,如 DeepSeek thinking) */
|
|
13
|
+
modelConfig?: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 模型工厂 — 根据 modelId 和 Provider 装配 openai SDK client。
|
|
5
17
|
*
|
|
6
|
-
*
|
|
18
|
+
* 端点(baseUrl / apiKey)来自 config.endpoints,发送给 API 的模型名 = modelName || id。
|
|
19
|
+
* 任何 OpenAI 兼容端点(OpenAI / 智谱 BigModel / DeepSeek 等)均可通过 baseURL 接入。
|
|
7
20
|
*/
|
|
8
|
-
export declare function createModel(provider: Provider, modelId: string):
|
|
21
|
+
export declare function createModel(provider: Provider, modelId: string): AgentModel;
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import OpenAI from "openai";
|
|
2
2
|
/**
|
|
3
|
-
* 模型工厂 — 根据 modelId 和 Provider
|
|
3
|
+
* 模型工厂 — 根据 modelId 和 Provider 装配 openai SDK client。
|
|
4
4
|
*
|
|
5
|
-
*
|
|
5
|
+
* 端点(baseUrl / apiKey)来自 config.endpoints,发送给 API 的模型名 = modelName || id。
|
|
6
|
+
* 任何 OpenAI 兼容端点(OpenAI / 智谱 BigModel / DeepSeek 等)均可通过 baseURL 接入。
|
|
6
7
|
*/
|
|
7
8
|
export function createModel(provider, modelId) {
|
|
8
9
|
const config = provider.config;
|
|
@@ -12,15 +13,18 @@ export function createModel(provider, modelId) {
|
|
|
12
13
|
const endpointConfig = config.endpoints.find((e) => e.id === modelConfig.endpointId);
|
|
13
14
|
if (!endpointConfig)
|
|
14
15
|
throw new Error(`端点 "${modelConfig.endpointId}" 未配置`);
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
16
|
+
if (!endpointConfig.apiKey) {
|
|
17
|
+
throw new Error(`端点 "${endpointConfig.name}" 的 API Key 未设置`);
|
|
18
|
+
}
|
|
19
|
+
const client = new OpenAI({
|
|
20
|
+
apiKey: endpointConfig.apiKey,
|
|
21
|
+
baseURL: endpointConfig.baseUrl,
|
|
18
22
|
});
|
|
19
23
|
// 发送给 API 的模型名:modelName > id
|
|
20
24
|
const apiModelName = modelConfig.modelName || modelConfig.id;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
return {
|
|
26
|
+
client,
|
|
27
|
+
model: apiModelName,
|
|
28
|
+
modelConfig: modelConfig.defaultParams,
|
|
29
|
+
};
|
|
26
30
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -29,6 +29,8 @@ export interface Model {
|
|
|
29
29
|
maxContextTokens: number;
|
|
30
30
|
maxContextChars?: number;
|
|
31
31
|
defaultParams?: Record<string, unknown>;
|
|
32
|
+
/** 是否支持图片输入(视觉模型)。看图工具(viewImage)仅对视觉模型启用;generateImage 是否返回图片内容块也据此判断 */
|
|
33
|
+
vision?: boolean;
|
|
32
34
|
description?: string;
|
|
33
35
|
version?: number;
|
|
34
36
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-zen/agents-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
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",
|
|
@@ -18,7 +18,8 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
20
20
|
"dayjs": "^1.11.21",
|
|
21
|
-
"
|
|
21
|
+
"openai": "^7.5.0",
|
|
22
|
+
"@ai-zen/agents-core": "^4.0.0"
|
|
22
23
|
},
|
|
23
24
|
"devDependencies": {
|
|
24
25
|
"@types/node": "^24.12.2",
|