@bowenqt/qiniu-ai-sdk 0.37.0 → 0.38.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 +27 -10
- package/README.zh-CN.md +4 -2
- package/bin/qiniu-ai.mjs +13 -0
- package/dist/ai/a2a/expert.d.ts +15 -3
- package/dist/ai/a2a/expert.d.ts.map +1 -1
- package/dist/ai/a2a/expert.js +46 -32
- package/dist/ai/a2a/expert.js.map +1 -1
- package/dist/ai/a2a/expert.mjs +46 -32
- package/dist/ai/a2a/types.d.ts +2 -2
- package/dist/ai/a2a/types.d.ts.map +1 -1
- package/dist/ai/agent-graph.d.ts +3 -0
- package/dist/ai/agent-graph.d.ts.map +1 -1
- package/dist/ai/agent-graph.js +17 -7
- package/dist/ai/agent-graph.js.map +1 -1
- package/dist/ai/agent-graph.mjs +17 -7
- package/dist/ai/create-agent.d.ts +13 -1
- package/dist/ai/create-agent.d.ts.map +1 -1
- package/dist/ai/create-agent.js +147 -8
- package/dist/ai/create-agent.js.map +1 -1
- package/dist/ai/create-agent.mjs +147 -8
- package/dist/ai/generate-text.d.ts +15 -0
- package/dist/ai/generate-text.d.ts.map +1 -1
- package/dist/ai/generate-text.js +4 -9
- package/dist/ai/generate-text.js.map +1 -1
- package/dist/ai/generate-text.mjs +4 -9
- package/dist/ai/nodes/execute-node.d.ts.map +1 -1
- package/dist/ai/nodes/execute-node.js +16 -0
- package/dist/ai/nodes/execute-node.js.map +1 -1
- package/dist/ai/nodes/execute-node.mjs +16 -0
- package/dist/ai/tool-approval.d.ts +6 -0
- package/dist/ai/tool-approval.d.ts.map +1 -1
- package/dist/ai/tool-approval.js +21 -0
- package/dist/ai/tool-approval.js.map +1 -1
- package/dist/ai/tool-approval.mjs +21 -0
- package/dist/cli/skill-cli.d.ts +23 -0
- package/dist/cli/skill-cli.d.ts.map +1 -0
- package/dist/cli/skill-cli.js +335 -0
- package/dist/cli/skill-cli.js.map +1 -0
- package/dist/cli/skill-cli.mjs +295 -0
- package/dist/lib/mcp-host-types.d.ts +79 -0
- package/dist/lib/mcp-host-types.d.ts.map +1 -0
- package/dist/lib/mcp-host-types.js +11 -0
- package/dist/lib/mcp-host-types.js.map +1 -0
- package/dist/lib/mcp-host-types.mjs +10 -0
- package/dist/lib/tool-registry.d.ts +5 -0
- package/dist/lib/tool-registry.d.ts.map +1 -1
- package/dist/lib/tool-registry.js +14 -0
- package/dist/lib/tool-registry.js.map +1 -1
- package/dist/lib/tool-registry.mjs +14 -0
- package/dist/lib/tool-schema.d.ts +49 -0
- package/dist/lib/tool-schema.d.ts.map +1 -0
- package/dist/lib/tool-schema.js +273 -0
- package/dist/lib/tool-schema.js.map +1 -0
- package/dist/lib/tool-schema.mjs +269 -0
- package/dist/lib/version.d.ts +3 -0
- package/dist/lib/version.d.ts.map +1 -0
- package/dist/lib/version.js +6 -0
- package/dist/lib/version.js.map +1 -0
- package/dist/lib/version.mjs +3 -0
- package/dist/modules/mcp/client.d.ts +4 -0
- package/dist/modules/mcp/client.d.ts.map +1 -1
- package/dist/modules/mcp/client.js +4 -0
- package/dist/modules/mcp/client.js.map +1 -1
- package/dist/modules/mcp/client.mjs +4 -0
- package/dist/modules/skills/installer.d.ts +44 -0
- package/dist/modules/skills/installer.d.ts.map +1 -0
- package/dist/modules/skills/installer.js +102 -0
- package/dist/modules/skills/installer.js.map +1 -0
- package/dist/modules/skills/installer.mjs +65 -0
- package/dist/modules/skills/loader.d.ts +1 -5
- package/dist/modules/skills/loader.d.ts.map +1 -1
- package/dist/modules/skills/loader.js +4 -18
- package/dist/modules/skills/loader.js.map +1 -1
- package/dist/modules/skills/loader.mjs +4 -18
- package/dist/modules/skills/lockfile.d.ts +43 -0
- package/dist/modules/skills/lockfile.d.ts.map +1 -0
- package/dist/modules/skills/lockfile.js +81 -0
- package/dist/modules/skills/lockfile.js.map +1 -0
- package/dist/modules/skills/lockfile.mjs +43 -0
- package/dist/modules/skills/manifest.d.ts +36 -0
- package/dist/modules/skills/manifest.d.ts.map +1 -1
- package/dist/modules/skills/manifest.js +22 -0
- package/dist/modules/skills/manifest.js.map +1 -1
- package/dist/modules/skills/manifest.mjs +21 -0
- package/dist/modules/skills/reference-mode.d.ts +29 -0
- package/dist/modules/skills/reference-mode.d.ts.map +1 -0
- package/dist/modules/skills/reference-mode.js +56 -0
- package/dist/modules/skills/reference-mode.js.map +1 -0
- package/dist/modules/skills/reference-mode.mjs +53 -0
- package/dist/modules/skills/registry-protocol.d.ts +57 -0
- package/dist/modules/skills/registry-protocol.d.ts.map +1 -0
- package/dist/modules/skills/registry-protocol.js +26 -0
- package/dist/modules/skills/registry-protocol.js.map +1 -0
- package/dist/modules/skills/registry-protocol.mjs +22 -0
- package/dist/modules/skills/registry.d.ts +39 -2
- package/dist/modules/skills/registry.d.ts.map +1 -1
- package/dist/modules/skills/registry.js +158 -4
- package/dist/modules/skills/registry.js.map +1 -1
- package/dist/modules/skills/registry.mjs +158 -4
- package/dist/modules/skills/validator.d.ts +31 -0
- package/dist/modules/skills/validator.d.ts.map +1 -0
- package/dist/modules/skills/validator.js +94 -0
- package/dist/modules/skills/validator.js.map +1 -0
- package/dist/modules/skills/validator.mjs +57 -0
- package/dist/node/index.d.ts +8 -1
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +17 -1
- package/dist/node/index.js.map +1 -1
- package/dist/node/index.mjs +7 -0
- package/dist/node/mcp-host.d.ts +56 -0
- package/dist/node/mcp-host.d.ts.map +1 -0
- package/dist/node/mcp-host.js +233 -0
- package/dist/node/mcp-host.js.map +1 -0
- package/dist/node/mcp-host.mjs +229 -0
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -35,11 +35,13 @@
|
|
|
35
35
|
### Advanced Capabilities
|
|
36
36
|
- 📋 **Skills Injection** — Markdown-based agent knowledge (Claude Skills compatible)
|
|
37
37
|
- 🏪 **Skill Marketplace** — Remote skill loading with SHA256 integrity verification (v0.32.0+)
|
|
38
|
-
-
|
|
38
|
+
- 🔐 **Security Hardening** — Atomic remote install, cumulative size limits, deny-first tool policy (v0.38.0+)
|
|
39
|
+
- ⚡ **MCP Tool Policy** — SDK-native timeout, progress reset, output truncation per server (v0.38.0+)
|
|
40
|
+
- 🔗 **MCP Host** — `NodeMCPHost` with stdio + HTTP transport + per-server tool policies
|
|
39
41
|
- 🖥️ **MCP Server** — Built-in Qiniu MCP server for OCR/Censor/Vframe tools
|
|
40
42
|
- 💾 **Checkpointer** — State persistence (Memory, Redis, PostgreSQL, Kodo)
|
|
41
43
|
- 🧠 **Memory Manager** — Short-term + long-term memory with LLM summarization
|
|
42
|
-
- ✅ **Tool Approval (HITL)** — Human-in-the-loop
|
|
44
|
+
- ✅ **Tool Approval (HITL)** — Human-in-the-loop with deny-first source policy (v0.38.0+)
|
|
43
45
|
- ⏸️ **Interrupt/Resume** — Resumable execution with checkpoint-based restore
|
|
44
46
|
- 📊 **Structured Telemetry** — MetricsCollector with Prometheus format export (v0.32.0+)
|
|
45
47
|
- 📋 **Log Export** — Request log export with filtering and pagination (v0.36.0+)
|
|
@@ -272,25 +274,31 @@ const handler = createMetricsHandler(metrics);
|
|
|
272
274
|
// GET /metrics → Prometheus format output
|
|
273
275
|
```
|
|
274
276
|
|
|
275
|
-
### MCP
|
|
277
|
+
### MCP Host with Tool Policy (v0.38.0+)
|
|
276
278
|
|
|
277
279
|
```typescript
|
|
278
|
-
import {
|
|
280
|
+
import { NodeMCPHost } from '@bowenqt/qiniu-ai-sdk/node';
|
|
279
281
|
|
|
280
|
-
const
|
|
282
|
+
const host = new NodeMCPHost({
|
|
281
283
|
servers: [
|
|
282
284
|
{
|
|
283
285
|
name: 'github',
|
|
284
286
|
transport: 'stdio',
|
|
285
287
|
command: 'npx',
|
|
286
288
|
args: ['-y', '@modelcontextprotocol/server-github'],
|
|
287
|
-
|
|
289
|
+
toolPolicy: {
|
|
290
|
+
timeout: 15000, // SDK-native request timeout
|
|
291
|
+
resetTimeoutOnProgress: true, // Reset on progress notifications
|
|
292
|
+
maxTotalTimeout: 120000, // Absolute ceiling
|
|
293
|
+
maxOutputLength: 500_000, // Output truncation
|
|
294
|
+
requiresApproval: false, // HITL per server
|
|
295
|
+
},
|
|
288
296
|
},
|
|
289
297
|
],
|
|
290
298
|
});
|
|
291
299
|
|
|
292
|
-
await
|
|
293
|
-
const tools =
|
|
300
|
+
await host.connect();
|
|
301
|
+
const tools = host.getTools();
|
|
294
302
|
```
|
|
295
303
|
|
|
296
304
|
### Checkpointer (State Persistence)
|
|
@@ -410,14 +418,23 @@ await instance.kill();
|
|
|
410
418
|
|
|
411
419
|
---
|
|
412
420
|
|
|
413
|
-
## 🛠️ CLI
|
|
421
|
+
## 🛠️ CLI Tools
|
|
414
422
|
|
|
415
|
-
|
|
423
|
+
### MCP Server
|
|
416
424
|
|
|
417
425
|
```bash
|
|
418
426
|
npx qiniu-mcp-server
|
|
419
427
|
```
|
|
420
428
|
|
|
429
|
+
### Skill Manager (v0.38.0+)
|
|
430
|
+
|
|
431
|
+
```bash
|
|
432
|
+
npx qiniu-ai skill list # List installed skills
|
|
433
|
+
npx qiniu-ai skill verify # Verify integrity (path + hash)
|
|
434
|
+
npx qiniu-ai skill verify --fix # Reconstruct lockfile from local dirs
|
|
435
|
+
npx qiniu-ai skill remove <name> # Remove skill + lockfile entry
|
|
436
|
+
```
|
|
437
|
+
|
|
421
438
|
**Environment variables:**
|
|
422
439
|
- `QINIU_API_KEY` — API key for OCR/Censor operations
|
|
423
440
|
- `QINIU_ACCESS_KEY` / `QINIU_SECRET_KEY` — For Vframe/signed operations
|
package/README.zh-CN.md
CHANGED
|
@@ -35,11 +35,13 @@
|
|
|
35
35
|
### 高级能力
|
|
36
36
|
- 📋 **技能注入** — Markdown 格式的 Agent 知识库(兼容 Claude Skills)
|
|
37
37
|
- 🏪 **Skill 市场** — 远程技能加载 + SHA256 完整性验证 (v0.32.0+)
|
|
38
|
-
-
|
|
38
|
+
- 🔐 **安全加固** — 原子远程安装、累计大小限制、deny-first 工具策略 (v0.38.0+)
|
|
39
|
+
- ⚡ **MCP 工具策略** — SDK 原生 timeout、进度重置、输出截断,按服务器配置 (v0.38.0+)
|
|
40
|
+
- 🔗 **MCP Host** — `NodeMCPHost` 支持 stdio + HTTP 传输 + 按服务器工具策略
|
|
39
41
|
- 🖥️ **MCP 服务端** — 内置七牛 MCP Server(OCR/审核/抽帧)
|
|
40
42
|
- 💾 **Checkpointer** — 状态持久化(Memory、Redis、PostgreSQL、Kodo)
|
|
41
43
|
- 🧠 **Memory Manager** — 短期 + 长期记忆,LLM 自动摘要
|
|
42
|
-
- ✅ **工具审批 (HITL)** — 敏感操作人工确认
|
|
44
|
+
- ✅ **工具审批 (HITL)** — 敏感操作人工确认 + deny-first 来源策略 (v0.38.0+)
|
|
43
45
|
- ⏸️ **中断/恢复** — 基于检查点的可恢复执行
|
|
44
46
|
- 📊 **结构化指标** — MetricsCollector + Prometheus 格式导出 (v0.32.0+)
|
|
45
47
|
- 📋 **日志导出** — 请求日志导出,支持筛选和分页 (v0.36.0+)
|
package/bin/qiniu-ai.mjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Qiniu AI CLI — Skill management and SDK utilities.
|
|
4
|
+
*
|
|
5
|
+
* Usage:
|
|
6
|
+
* npx qiniu-ai skill list [--dir <skills-dir>]
|
|
7
|
+
* npx qiniu-ai skill verify [--fix] [--dir <skills-dir>]
|
|
8
|
+
* npx qiniu-ai skill remove <name> [--dir <skills-dir>]
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { runCLI } from '../dist/cli/skill-cli.mjs';
|
|
12
|
+
|
|
13
|
+
runCLI(process.argv.slice(2));
|
package/dist/ai/a2a/expert.d.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AgentExpert - Expose agent tools for A2A collaboration.
|
|
3
|
+
*
|
|
4
|
+
* v5 changes:
|
|
5
|
+
* - tools getter: lazy lookup from agent._tools (dynamic, reflects MCP hot updates)
|
|
6
|
+
* - expose: '*' | string[] (wildcard or whitelist)
|
|
7
|
+
* - callTool: reads from agent._tools at call time, not from cached snapshot
|
|
3
8
|
*/
|
|
4
9
|
import type { Agent } from '../create-agent';
|
|
5
10
|
import type { Tool } from '../generate-text';
|
|
@@ -10,19 +15,22 @@ import type { AgentExpertConfig, A2AMessage, CallToolRequest, RunTaskRequest, Ru
|
|
|
10
15
|
export declare class AgentExpert {
|
|
11
16
|
/** Unique expert ID */
|
|
12
17
|
readonly id: string;
|
|
13
|
-
/** Exposed tools (with prefix) */
|
|
14
|
-
readonly tools: Record<string, Tool>;
|
|
15
18
|
private agent;
|
|
16
19
|
private config;
|
|
17
20
|
private rateLimiter?;
|
|
18
|
-
private originalTools;
|
|
19
21
|
private constructor();
|
|
20
22
|
/**
|
|
21
23
|
* Create an AgentExpert from an Agent.
|
|
22
24
|
*/
|
|
23
25
|
static from(agent: Agent, config: AgentExpertConfig): AgentExpert;
|
|
26
|
+
/**
|
|
27
|
+
* Dynamic tools getter — reads from agent._tools every time.
|
|
28
|
+
* MCP hot updates are automatically reflected.
|
|
29
|
+
*/
|
|
30
|
+
get tools(): Record<string, Tool>;
|
|
24
31
|
/**
|
|
25
32
|
* Direct tool call with full request.
|
|
33
|
+
* Uses lazy lookup from agent._tools at call time.
|
|
26
34
|
*/
|
|
27
35
|
callTool(request: CallToolRequest): Promise<A2AMessage>;
|
|
28
36
|
/**
|
|
@@ -33,5 +41,9 @@ export declare class AgentExpert {
|
|
|
33
41
|
* Get list of exposed tool names (without prefix).
|
|
34
42
|
*/
|
|
35
43
|
getExposedToolNames(): string[];
|
|
44
|
+
/**
|
|
45
|
+
* Build exposed tools from current agent._tools.
|
|
46
|
+
*/
|
|
47
|
+
private buildExposedTools;
|
|
36
48
|
}
|
|
37
49
|
//# sourceMappingURL=expert.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expert.d.ts","sourceRoot":"","sources":["../../../src/ai/a2a/expert.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"expert.d.ts","sourceRoot":"","sources":["../../../src/ai/a2a/expert.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EAAE,IAAI,EAA+B,MAAM,kBAAkB,CAAC;AAC1E,OAAO,KAAK,EACR,iBAAiB,EACjB,UAAU,EACV,eAAe,EACf,cAAc,EACd,aAAa,EAChB,MAAM,SAAS,CAAC;AAajB;;GAEG;AACH,qBAAa,WAAW;IACpB,uBAAuB;IACvB,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IAEpB,OAAO,CAAC,KAAK,CAAQ;IACrB,OAAO,CAAC,MAAM,CAKZ;IACF,OAAO,CAAC,WAAW,CAAC,CAAiB;IAErC,OAAO;IAgBP;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,iBAAiB,GAAG,WAAW;IAQjE;;;OAGG;IACH,IAAI,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAEhC;IAED;;;OAGG;IACG,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,UAAU,CAAC;IA4E7D;;OAEG;IACG,OAAO,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC;IAgB9D;;OAEG;IACH,mBAAmB,IAAI,MAAM,EAAE;IAW/B;;OAEG;IACH,OAAO,CAAC,iBAAiB;CAmB5B"}
|
package/dist/ai/a2a/expert.js
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* AgentExpert - Expose agent tools for A2A collaboration.
|
|
4
|
+
*
|
|
5
|
+
* v5 changes:
|
|
6
|
+
* - tools getter: lazy lookup from agent._tools (dynamic, reflects MCP hot updates)
|
|
7
|
+
* - expose: '*' | string[] (wildcard or whitelist)
|
|
8
|
+
* - callTool: reads from agent._tools at call time, not from cached snapshot
|
|
4
9
|
*/
|
|
5
10
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
11
|
exports.AgentExpert = void 0;
|
|
@@ -14,7 +19,7 @@ const rate_limiter_1 = require("./rate-limiter");
|
|
|
14
19
|
* Wraps an Agent to expose selected tools for A2A collaboration.
|
|
15
20
|
*/
|
|
16
21
|
class AgentExpert {
|
|
17
|
-
constructor(agent, config,
|
|
22
|
+
constructor(agent, config, rateLimiter) {
|
|
18
23
|
this.agent = agent;
|
|
19
24
|
this.id = agent.id;
|
|
20
25
|
this.config = {
|
|
@@ -23,41 +28,31 @@ class AgentExpert {
|
|
|
23
28
|
validateArgs: config.validateArgs ?? true,
|
|
24
29
|
rateLimit: config.rateLimit,
|
|
25
30
|
};
|
|
26
|
-
this.tools = tools;
|
|
27
|
-
this.originalTools = originalTools;
|
|
28
31
|
this.rateLimiter = rateLimiter;
|
|
29
32
|
}
|
|
30
33
|
/**
|
|
31
34
|
* Create an AgentExpert from an Agent.
|
|
32
35
|
*/
|
|
33
36
|
static from(agent, config) {
|
|
34
|
-
const originalTools = agent._tools;
|
|
35
|
-
const prefix = config.prefix ?? `${agent.id}_`;
|
|
36
|
-
const expertId = agent.id;
|
|
37
|
-
// Single shared rate limiter instance
|
|
38
37
|
const rateLimiter = config.rateLimit
|
|
39
38
|
? new rate_limiter_1.A2ARateLimiter(config.rateLimit)
|
|
40
39
|
: undefined;
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
const prefixedName = `${prefix}${toolName}`;
|
|
50
|
-
exposedTools[prefixedName] = createWrappedTool(tool, toolName, expertId, rateLimiter, config.validateArgs ?? true);
|
|
51
|
-
}
|
|
52
|
-
return new AgentExpert(agent, config, exposedTools, originalTools, rateLimiter);
|
|
40
|
+
return new AgentExpert(agent, config, rateLimiter);
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Dynamic tools getter — reads from agent._tools every time.
|
|
44
|
+
* MCP hot updates are automatically reflected.
|
|
45
|
+
*/
|
|
46
|
+
get tools() {
|
|
47
|
+
return this.buildExposedTools();
|
|
53
48
|
}
|
|
54
49
|
/**
|
|
55
50
|
* Direct tool call with full request.
|
|
51
|
+
* Uses lazy lookup from agent._tools at call time.
|
|
56
52
|
*/
|
|
57
53
|
async callTool(request) {
|
|
58
54
|
const requestId = request.requestId ?? (0, types_1.generateRequestId)();
|
|
59
55
|
const { from = '', tool, args, signal } = request;
|
|
60
|
-
// Create base request for responses
|
|
61
56
|
const baseRequest = {
|
|
62
57
|
requestId,
|
|
63
58
|
type: 'request',
|
|
@@ -67,23 +62,22 @@ class AgentExpert {
|
|
|
67
62
|
tool,
|
|
68
63
|
args,
|
|
69
64
|
};
|
|
70
|
-
//
|
|
71
|
-
if (!this.config.expose.includes(tool)) {
|
|
65
|
+
// Expose strategy check
|
|
66
|
+
if (this.config.expose !== '*' && !this.config.expose.includes(tool)) {
|
|
72
67
|
return (0, types_1.createA2AError)(baseRequest, 'TOOL_NOT_EXPOSED', `Tool "${tool}" is not exposed by this expert`);
|
|
73
68
|
}
|
|
74
|
-
//
|
|
75
|
-
const
|
|
76
|
-
if (!
|
|
69
|
+
// Lazy lookup: get tool from current agent._tools (dynamic)
|
|
70
|
+
const currentTool = this.agent._tools[tool];
|
|
71
|
+
if (!currentTool) {
|
|
77
72
|
return (0, types_1.createA2AError)(baseRequest, 'TOOL_NOT_FOUND', `Tool "${tool}" not found`);
|
|
78
73
|
}
|
|
79
74
|
// Check abort signal
|
|
80
75
|
if (signal?.aborted) {
|
|
81
76
|
return (0, types_1.createA2AError)(baseRequest, 'CANCELLED', 'Request was cancelled');
|
|
82
77
|
}
|
|
83
|
-
// Rate limiting
|
|
78
|
+
// Rate limiting
|
|
84
79
|
if (this.rateLimiter) {
|
|
85
80
|
try {
|
|
86
|
-
// Use execute() which handles queue fairness and abort
|
|
87
81
|
await this.rateLimiter.execute(this.id, tool, async () => { }, signal);
|
|
88
82
|
}
|
|
89
83
|
catch (error) {
|
|
@@ -97,18 +91,18 @@ class AgentExpert {
|
|
|
97
91
|
}
|
|
98
92
|
}
|
|
99
93
|
// Validate args
|
|
100
|
-
if (this.config.validateArgs &&
|
|
101
|
-
const validationResult = (0, validation_1.validateSchema)(args,
|
|
94
|
+
if (this.config.validateArgs && currentTool.parameters) {
|
|
95
|
+
const validationResult = (0, validation_1.validateSchema)(args, currentTool.parameters);
|
|
102
96
|
if (!validationResult.valid) {
|
|
103
97
|
return (0, types_1.createA2AError)(baseRequest, 'VALIDATION_ERROR', validationResult.error?.message ?? 'Validation failed');
|
|
104
98
|
}
|
|
105
99
|
}
|
|
106
100
|
// Execute tool
|
|
107
101
|
try {
|
|
108
|
-
if (!
|
|
102
|
+
if (!currentTool.execute) {
|
|
109
103
|
throw new Error(`Tool "${tool}" has no execute function`);
|
|
110
104
|
}
|
|
111
|
-
const result = await
|
|
105
|
+
const result = await currentTool.execute(args, {
|
|
112
106
|
toolCallId: requestId,
|
|
113
107
|
messages: [],
|
|
114
108
|
abortSignal: signal,
|
|
@@ -138,15 +132,35 @@ class AgentExpert {
|
|
|
138
132
|
* Get list of exposed tool names (without prefix).
|
|
139
133
|
*/
|
|
140
134
|
getExposedToolNames() {
|
|
135
|
+
if (this.config.expose === '*') {
|
|
136
|
+
return Object.keys(this.agent._tools);
|
|
137
|
+
}
|
|
141
138
|
return [...this.config.expose];
|
|
142
139
|
}
|
|
140
|
+
// ========================================================================
|
|
141
|
+
// Private
|
|
142
|
+
// ========================================================================
|
|
143
|
+
/**
|
|
144
|
+
* Build exposed tools from current agent._tools.
|
|
145
|
+
*/
|
|
146
|
+
buildExposedTools() {
|
|
147
|
+
const currentTools = this.agent._tools;
|
|
148
|
+
const result = {};
|
|
149
|
+
for (const [name, tool] of Object.entries(currentTools)) {
|
|
150
|
+
if (this.config.expose === '*' || this.config.expose.includes(name)) {
|
|
151
|
+
const prefixedName = `${this.config.prefix}${name}`;
|
|
152
|
+
result[prefixedName] = createWrappedTool(tool, name, this.id, this.rateLimiter, this.config.validateArgs);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return result;
|
|
156
|
+
}
|
|
143
157
|
}
|
|
144
158
|
exports.AgentExpert = AgentExpert;
|
|
145
159
|
// ============================================================================
|
|
146
160
|
// Helper Functions
|
|
147
161
|
// ============================================================================
|
|
148
162
|
/**
|
|
149
|
-
* Create a wrapped tool
|
|
163
|
+
* Create a wrapped tool — all tools go through execute() for FIFO fairness.
|
|
150
164
|
*/
|
|
151
165
|
function createWrappedTool(original, toolName, expertId, rateLimiter, validateArgs) {
|
|
152
166
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"expert.js","sourceRoot":"","sources":["../../../src/ai/a2a/expert.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"expert.js","sourceRoot":"","sources":["../../../src/ai/a2a/expert.ts"],"names":[],"mappings":";AAAA;;;;;;;GAOG;;;AAWH,mCAIiB;AACjB,6CAA+D;AAC/D,iDAA4E;AAE5E,+EAA+E;AAC/E,cAAc;AACd,+EAA+E;AAE/E;;GAEG;AACH,MAAa,WAAW;IAapB,YACI,KAAY,EACZ,MAAyB,EACzB,WAA4B;QAE5B,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QACnB,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG;YACV,MAAM,EAAE,MAAM,CAAC,MAAM;YACrB,MAAM,EAAE,MAAM,CAAC,MAAM,IAAI,GAAG,IAAI,CAAC,EAAE,GAAG;YACtC,YAAY,EAAE,MAAM,CAAC,YAAY,IAAI,IAAI;YACzC,SAAS,EAAE,MAAM,CAAC,SAAS;SAC9B,CAAC;QACF,IAAI,CA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KAAK,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE;YAC7B,gDAAgD;YAChD,IAAI,WAAW,EAAE,CAAC;gBACd,MAAM,WAAW,CAAC,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,KAAK,IAAI,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAC;YACxF,CAAC;YAED,WAAW;YACX,IAAI,YAAY,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC;gBACtC,MAAM,MAAM,GAAG,IAAA,2BAAc,EAAC,IAA+B,EAAE,QAAQ,CAAC,UAAwB,CAAC,CAAC;gBAClG,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;oBAChB,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,EAAE,OAAO,IAAI,mBAAmB,CAAC,CAAC;gBAClE,CAAC;YACL,CAAC;YAED,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;gBACpB,MAAM,IAAI,KAAK,CAAC,8BAA8B,CAAC,CAAC;YACpD,CAAC;YACD,OAAO,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QAC3C,CAAC;KACJ,CAAC;AACN,CAAC"}
|
package/dist/ai/a2a/expert.mjs
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* AgentExpert - Expose agent tools for A2A collaboration.
|
|
3
|
+
*
|
|
4
|
+
* v5 changes:
|
|
5
|
+
* - tools getter: lazy lookup from agent._tools (dynamic, reflects MCP hot updates)
|
|
6
|
+
* - expose: '*' | string[] (wildcard or whitelist)
|
|
7
|
+
* - callTool: reads from agent._tools at call time, not from cached snapshot
|
|
3
8
|
*/
|
|
4
9
|
import { generateRequestId, createA2AResponse, createA2AError, } from './types.mjs';
|
|
5
10
|
import { validateSchema } from './validation.mjs';
|
|
@@ -11,7 +16,7 @@ import { A2ARateLimiter, RateLimitError, AbortError } from './rate-limiter.mjs';
|
|
|
11
16
|
* Wraps an Agent to expose selected tools for A2A collaboration.
|
|
12
17
|
*/
|
|
13
18
|
export class AgentExpert {
|
|
14
|
-
constructor(agent, config,
|
|
19
|
+
constructor(agent, config, rateLimiter) {
|
|
15
20
|
this.agent = agent;
|
|
16
21
|
this.id = agent.id;
|
|
17
22
|
this.config = {
|
|
@@ -20,41 +25,31 @@ export class AgentExpert {
|
|
|
20
25
|
validateArgs: config.validateArgs ?? true,
|
|
21
26
|
rateLimit: config.rateLimit,
|
|
22
27
|
};
|
|
23
|
-
this.tools = tools;
|
|
24
|
-
this.originalTools = originalTools;
|
|
25
28
|
this.rateLimiter = rateLimiter;
|
|
26
29
|
}
|
|
27
30
|
/**
|
|
28
31
|
* Create an AgentExpert from an Agent.
|
|
29
32
|
*/
|
|
30
33
|
static from(agent, config) {
|
|
31
|
-
const originalTools = agent._tools;
|
|
32
|
-
const prefix = config.prefix ?? `${agent.id}_`;
|
|
33
|
-
const expertId = agent.id;
|
|
34
|
-
// Single shared rate limiter instance
|
|
35
34
|
const rateLimiter = config.rateLimit
|
|
36
35
|
? new A2ARateLimiter(config.rateLimit)
|
|
37
36
|
: undefined;
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
const prefixedName = `${prefix}${toolName}`;
|
|
47
|
-
exposedTools[prefixedName] = createWrappedTool(tool, toolName, expertId, rateLimiter, config.validateArgs ?? true);
|
|
48
|
-
}
|
|
49
|
-
return new AgentExpert(agent, config, exposedTools, originalTools, rateLimiter);
|
|
37
|
+
return new AgentExpert(agent, config, rateLimiter);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Dynamic tools getter — reads from agent._tools every time.
|
|
41
|
+
* MCP hot updates are automatically reflected.
|
|
42
|
+
*/
|
|
43
|
+
get tools() {
|
|
44
|
+
return this.buildExposedTools();
|
|
50
45
|
}
|
|
51
46
|
/**
|
|
52
47
|
* Direct tool call with full request.
|
|
48
|
+
* Uses lazy lookup from agent._tools at call time.
|
|
53
49
|
*/
|
|
54
50
|
async callTool(request) {
|
|
55
51
|
const requestId = request.requestId ?? generateRequestId();
|
|
56
52
|
const { from = '', tool, args, signal } = request;
|
|
57
|
-
// Create base request for responses
|
|
58
53
|
const baseRequest = {
|
|
59
54
|
requestId,
|
|
60
55
|
type: 'request',
|
|
@@ -64,23 +59,22 @@ export class AgentExpert {
|
|
|
64
59
|
tool,
|
|
65
60
|
args,
|
|
66
61
|
};
|
|
67
|
-
//
|
|
68
|
-
if (!this.config.expose.includes(tool)) {
|
|
62
|
+
// Expose strategy check
|
|
63
|
+
if (this.config.expose !== '*' && !this.config.expose.includes(tool)) {
|
|
69
64
|
return createA2AError(baseRequest, 'TOOL_NOT_EXPOSED', `Tool "${tool}" is not exposed by this expert`);
|
|
70
65
|
}
|
|
71
|
-
//
|
|
72
|
-
const
|
|
73
|
-
if (!
|
|
66
|
+
// Lazy lookup: get tool from current agent._tools (dynamic)
|
|
67
|
+
const currentTool = this.agent._tools[tool];
|
|
68
|
+
if (!currentTool) {
|
|
74
69
|
return createA2AError(baseRequest, 'TOOL_NOT_FOUND', `Tool "${tool}" not found`);
|
|
75
70
|
}
|
|
76
71
|
// Check abort signal
|
|
77
72
|
if (signal?.aborted) {
|
|
78
73
|
return createA2AError(baseRequest, 'CANCELLED', 'Request was cancelled');
|
|
79
74
|
}
|
|
80
|
-
// Rate limiting
|
|
75
|
+
// Rate limiting
|
|
81
76
|
if (this.rateLimiter) {
|
|
82
77
|
try {
|
|
83
|
-
// Use execute() which handles queue fairness and abort
|
|
84
78
|
await this.rateLimiter.execute(this.id, tool, async () => { }, signal);
|
|
85
79
|
}
|
|
86
80
|
catch (error) {
|
|
@@ -94,18 +88,18 @@ export class AgentExpert {
|
|
|
94
88
|
}
|
|
95
89
|
}
|
|
96
90
|
// Validate args
|
|
97
|
-
if (this.config.validateArgs &&
|
|
98
|
-
const validationResult = validateSchema(args,
|
|
91
|
+
if (this.config.validateArgs && currentTool.parameters) {
|
|
92
|
+
const validationResult = validateSchema(args, currentTool.parameters);
|
|
99
93
|
if (!validationResult.valid) {
|
|
100
94
|
return createA2AError(baseRequest, 'VALIDATION_ERROR', validationResult.error?.message ?? 'Validation failed');
|
|
101
95
|
}
|
|
102
96
|
}
|
|
103
97
|
// Execute tool
|
|
104
98
|
try {
|
|
105
|
-
if (!
|
|
99
|
+
if (!currentTool.execute) {
|
|
106
100
|
throw new Error(`Tool "${tool}" has no execute function`);
|
|
107
101
|
}
|
|
108
|
-
const result = await
|
|
102
|
+
const result = await currentTool.execute(args, {
|
|
109
103
|
toolCallId: requestId,
|
|
110
104
|
messages: [],
|
|
111
105
|
abortSignal: signal,
|
|
@@ -135,14 +129,34 @@ export class AgentExpert {
|
|
|
135
129
|
* Get list of exposed tool names (without prefix).
|
|
136
130
|
*/
|
|
137
131
|
getExposedToolNames() {
|
|
132
|
+
if (this.config.expose === '*') {
|
|
133
|
+
return Object.keys(this.agent._tools);
|
|
134
|
+
}
|
|
138
135
|
return [...this.config.expose];
|
|
139
136
|
}
|
|
137
|
+
// ========================================================================
|
|
138
|
+
// Private
|
|
139
|
+
// ========================================================================
|
|
140
|
+
/**
|
|
141
|
+
* Build exposed tools from current agent._tools.
|
|
142
|
+
*/
|
|
143
|
+
buildExposedTools() {
|
|
144
|
+
const currentTools = this.agent._tools;
|
|
145
|
+
const result = {};
|
|
146
|
+
for (const [name, tool] of Object.entries(currentTools)) {
|
|
147
|
+
if (this.config.expose === '*' || this.config.expose.includes(name)) {
|
|
148
|
+
const prefixedName = `${this.config.prefix}${name}`;
|
|
149
|
+
result[prefixedName] = createWrappedTool(tool, name, this.id, this.rateLimiter, this.config.validateArgs);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return result;
|
|
153
|
+
}
|
|
140
154
|
}
|
|
141
155
|
// ============================================================================
|
|
142
156
|
// Helper Functions
|
|
143
157
|
// ============================================================================
|
|
144
158
|
/**
|
|
145
|
-
* Create a wrapped tool
|
|
159
|
+
* Create a wrapped tool — all tools go through execute() for FIFO fairness.
|
|
146
160
|
*/
|
|
147
161
|
function createWrappedTool(original, toolName, expertId, rateLimiter, validateArgs) {
|
|
148
162
|
return {
|
package/dist/ai/a2a/types.d.ts
CHANGED
|
@@ -60,8 +60,8 @@ export interface RateLimitConfig {
|
|
|
60
60
|
* AgentExpert configuration.
|
|
61
61
|
*/
|
|
62
62
|
export interface AgentExpertConfig {
|
|
63
|
-
/** Tool names to expose (
|
|
64
|
-
expose: string[];
|
|
63
|
+
/** Tool names to expose: '*' (all, including dynamic MCP) or string[] (whitelist) */
|
|
64
|
+
expose: '*' | string[];
|
|
65
65
|
/** Prefix for exposed tool names (default: `{agentId}_`) */
|
|
66
66
|
prefix?: string;
|
|
67
67
|
/** Rate limiting configuration */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/ai/a2a/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH;;GAEG;AACH,MAAM,WAAW,UAAU;IACvB,yDAAyD;IACzD,SAAS,EAAE,MAAM,CAAC;IAClB,mBAAmB;IACnB,IAAI,EAAE,SAAS,GAAG,UAAU,GAAG,OAAO,GAAG,QAAQ,CAAC;IAClD,sBAAsB;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,sBAAsB;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,iCAAiC;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,oCAAoC;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;IAGlB,wBAAwB;IACxB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,qBAAqB;IACrB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAG/B,4BAA4B;IAC5B,MAAM,CAAC,EAAE,OAAO,CAAC;IAGjB,oBAAoB;IACpB,KAAK,CAAC,EAAE,QAAQ,CAAC;CACpB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WAAW,cAAc;IAC3B,kBAAkB;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,oCAAoC;IACpC,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,kDAAkD;IAClD,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B,mBAAmB;IACnB,MAAM,EAAE,MAAM,CAAC;IACf,iBAAiB;IACjB,SAAS,EAAE,MAAM,CAAC;CACrB;AAMD;;GAEG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAE1C;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAC5B,IAAI,EAAE,MAAM,EACZ,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAC7B,QAAQ,CAAC,EAAE,MAAM,GAClB,UAAU,CAWZ;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAC7B,OAAO,EAAE,UAAU,EACnB,MAAM,EAAE,OAAO,GAChB,UAAU,CASZ;AAED;;GAEG;AACH,wBAAgB,cAAc,CAC1B,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,MAAM,GACf,UAAU,CASZ"}
|
package/dist/ai/agent-graph.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type { QiniuAI } from '../client';
|
|
|
8
8
|
import type { ResponseFormat } from '../lib/types';
|
|
9
9
|
import type { RegisteredTool } from '../lib/tool-registry';
|
|
10
10
|
import type { Skill } from '../modules/skills';
|
|
11
|
+
import type { ReferenceMode } from '../modules/skills/reference-mode';
|
|
11
12
|
import { type TokenEstimatorConfig } from '../lib/token-estimator';
|
|
12
13
|
import type { MemoryManager } from './memory';
|
|
13
14
|
import type { AgentState, InternalMessage, StepResult, AgentGraphEvents } from './internal-types';
|
|
@@ -46,6 +47,8 @@ export interface AgentGraphOptions {
|
|
|
46
47
|
threadId?: string;
|
|
47
48
|
/** Auto-retry configuration for RecoverableError handling */
|
|
48
49
|
autoRetry?: AutoRetryConfig;
|
|
50
|
+
/** Skill reference injection mode (default: 'none') */
|
|
51
|
+
skillReferenceMode?: ReferenceMode;
|
|
49
52
|
}
|
|
50
53
|
/**
|
|
51
54
|
* Configuration for automatic retry of recoverable errors.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent-graph.d.ts","sourceRoot":"","sources":["../../src/ai/agent-graph.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"agent-graph.d.ts","sourceRoot":"","sources":["../../src/ai/agent-graph.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AAOtE,OAAO,EAAyB,KAAK,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE1F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC9C,OAAO,KAAK,EACR,UAAU,EACV,eAAe,EAEf,UAAU,EACV,gBAAgB,EACnB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEtD,OAAO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AO,CAAC,QAAQ,CAAC,KAAK,CAAqC;IAC3D,OAAO,CAAC,KAAK,CAAoB;IACjC,gFAAgF;IAChF,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA4C;IACpE,0BAA0B;IAC1B,OAAO,CAAC,kBAAkB,CAAS;IACnC,OAAO,CAAC,aAAa,CAAgB;IACrC,OAAO,CAAC,eAAe,CAAK;gBAEhB,OAAO,EAAE,iBAAiB;IAStC;;;OAGG;IACH,UAAU,IAAI,YAAY;IAI1B;;;OAGG;IACH,YAAY,IAAI,IAAI;IAIpB;;;OAGG;IACH,OAAO,CAAC,eAAe;IAuCvB;;;OAGG;IACH,OAAO,CAAC,6BAA6B;IAgBrC;;OAEG;IACG,MAAM,CAAC,QAAQ,EAAE,eAAe,EAAE,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAmGpE;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4BG;IACG,eAAe,CACjB,QAAQ,EAAE,eAAe,EAAE,EAC3B,OAAO,EAAE,gBAAgB,GAC1B,OAAO,CAAC,eAAe,CAAC;IA8Q3B;;OAEG;IACH,OAAO,CAAC,UAAU;IAclB;;OAEG;YACW,WAAW;IAqFzB;;OAEG;YACW,WAAW;IA6EzB;;;OAGG;IACH,OAAO,CAAC,YAAY;CAyDvB"}
|
package/dist/ai/agent-graph.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
*/
|
|
8
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
9
|
exports.AgentGraph = void 0;
|
|
10
|
+
const reference_mode_1 = require("../modules/skills/reference-mode");
|
|
10
11
|
const graph_1 = require("./graph");
|
|
11
12
|
const predict_node_1 = require("./nodes/predict-node");
|
|
12
13
|
const execute_node_1 = require("./nodes/execute-node");
|
|
@@ -591,6 +592,7 @@ class AgentGraph {
|
|
|
591
592
|
injectSkills(messages, skills) {
|
|
592
593
|
// Sort skills by name (ASCII order)
|
|
593
594
|
const sortedSkills = [...skills].sort((a, b) => a.name.localeCompare(b.name));
|
|
595
|
+
const mode = this.options.skillReferenceMode ?? 'none';
|
|
594
596
|
// Find insertion point (after first system message, or at start)
|
|
595
597
|
let insertIndex = 0;
|
|
596
598
|
for (let i = 0; i < messages.length; i++) {
|
|
@@ -599,21 +601,29 @@ class AgentGraph {
|
|
|
599
601
|
break;
|
|
600
602
|
}
|
|
601
603
|
}
|
|
602
|
-
// Create skill messages
|
|
603
|
-
const
|
|
604
|
+
// Create skill messages (using referenceMode for content + token recalculation)
|
|
605
|
+
const processedSkills = sortedSkills.map(skill => {
|
|
606
|
+
const { injectedContent, injectedTokenCount } = (0, reference_mode_1.applyReferenceMode)({ instruction: skill.content, references: skill.references }, mode);
|
|
607
|
+
return { skill, injectedContent, injectedTokenCount };
|
|
608
|
+
});
|
|
609
|
+
const skillMessages = processedSkills.map(({ injectedContent }) => ({
|
|
604
610
|
role: 'system',
|
|
605
|
-
content:
|
|
611
|
+
content: injectedContent,
|
|
606
612
|
_meta: {
|
|
607
|
-
skillId: skill.name,
|
|
613
|
+
skillId: processedSkills[0].skill.name, // will be overwritten below
|
|
608
614
|
droppable: true,
|
|
609
615
|
},
|
|
610
616
|
}));
|
|
611
|
-
//
|
|
612
|
-
|
|
617
|
+
// Fix _meta.skillId per message
|
|
618
|
+
processedSkills.forEach(({ skill }, idx) => {
|
|
619
|
+
skillMessages[idx]._meta.skillId = skill.name;
|
|
620
|
+
});
|
|
621
|
+
// Build injected skill metadata (using recalculated token counts)
|
|
622
|
+
const injectedSkills = processedSkills.map(({ skill, injectedTokenCount }, idx) => ({
|
|
613
623
|
name: skill.name,
|
|
614
624
|
priority: idx, // Lower index = lower priority = drop first
|
|
615
625
|
messageIndex: insertIndex + idx,
|
|
616
|
-
tokenCount:
|
|
626
|
+
tokenCount: injectedTokenCount,
|
|
617
627
|
}));
|
|
618
628
|
// Insert skill messages
|
|
619
629
|
const newMessages = [
|