@zhin.js/core 1.1.34 → 1.1.37
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 +84 -142
- package/lib/built/ai-access.d.ts +36 -0
- package/lib/built/ai-access.js +46 -0
- package/lib/built/ai-outbound/extensions/onebot-keyboard.d.ts +2 -0
- package/lib/built/ai-outbound/extensions/onebot-keyboard.js +67 -0
- package/lib/built/ai-outbound/extensions/qq-message.d.ts +3 -0
- package/lib/built/ai-outbound/extensions/qq-message.js +23 -0
- package/lib/built/ai-outbound/index.d.ts +8 -0
- package/lib/built/ai-outbound/index.js +8 -0
- package/lib/built/ai-outbound/parse.d.ts +13 -0
- package/lib/built/ai-outbound/parse.js +104 -0
- package/lib/built/ai-outbound/plain-mention-rewrite.d.ts +6 -0
- package/lib/built/ai-outbound/plain-mention-rewrite.js +37 -0
- package/lib/built/ai-outbound/prompt.d.ts +11 -0
- package/lib/built/ai-outbound/prompt.js +44 -0
- package/lib/built/ai-outbound/resolve.d.ts +4 -0
- package/lib/built/ai-outbound/resolve.js +64 -0
- package/lib/built/ai-outbound/structured-detect.d.ts +3 -0
- package/lib/built/ai-outbound/structured-detect.js +6 -0
- package/lib/built/ai-outbound/types.d.ts +49 -0
- package/lib/built/ai-outbound/types.js +5 -0
- package/lib/built/ai-trigger.d.ts +12 -17
- package/lib/built/ai-trigger.js +39 -70
- package/lib/built/common-adapter-tools.d.ts +33 -29
- package/lib/built/common-adapter-tools.js +79 -67
- package/lib/built/generated-qrcode.d.ts +24 -0
- package/lib/built/generated-qrcode.js +45 -0
- package/lib/built/generic-segment-mapper.d.ts +4 -0
- package/lib/built/generic-segment-mapper.js +190 -0
- package/lib/built/html-segment-fallback.d.ts +2 -5
- package/lib/built/html-segment-fallback.js +0 -16
- package/lib/built/html-to-text.d.ts +0 -1
- package/lib/built/html-to-text.js +15 -15
- package/lib/built/interactive-segments/action.d.ts +17 -0
- package/lib/built/interactive-segments/action.js +69 -0
- package/lib/built/interactive-segments/button-spec.d.ts +10 -0
- package/lib/built/interactive-segments/button-spec.js +21 -0
- package/lib/built/interactive-segments/index.d.ts +6 -0
- package/lib/built/interactive-segments/index.js +6 -0
- package/lib/built/interactive-segments/keyboard-segment.d.ts +10 -0
- package/lib/built/interactive-segments/keyboard-segment.js +11 -0
- package/lib/built/interactive-segments/onebot-keyboard.d.ts +6 -0
- package/lib/built/interactive-segments/onebot-keyboard.js +49 -0
- package/lib/built/interactive-segments/resolve.d.ts +14 -0
- package/lib/built/interactive-segments/resolve.js +109 -0
- package/lib/built/interactive-segments/types.d.ts +45 -0
- package/lib/built/interactive-segments/types.js +9 -0
- package/lib/built/login-assist.d.ts +43 -16
- package/lib/built/login-assist.js +113 -11
- package/lib/built/message-enrich.d.ts +32 -0
- package/lib/built/message-enrich.js +67 -0
- package/lib/built/outbound-media-utils.d.ts +9 -0
- package/lib/built/outbound-media-utils.js +62 -0
- package/lib/built/queue-im-field-contract.d.ts +7 -2
- package/lib/built/queue-im-field-contract.js +13 -4
- package/lib/built/rich-segments/markdown-to-text.d.ts +3 -0
- package/lib/built/rich-segments/markdown-to-text.js +27 -0
- package/lib/built/roles.d.ts +4 -5
- package/lib/built/roles.js +4 -5
- package/lib/built/segment-contract/assert.d.ts +7 -0
- package/lib/built/segment-contract/assert.js +39 -0
- package/lib/built/segment-contract/delivery.d.ts +5 -0
- package/lib/built/segment-contract/delivery.js +40 -0
- package/lib/built/segment-contract/image.d.ts +5 -0
- package/lib/built/segment-contract/image.js +10 -0
- package/lib/built/segment-contract/index.d.ts +10 -0
- package/lib/built/segment-contract/index.js +9 -0
- package/lib/built/segment-contract/json-schema.d.ts +28 -0
- package/lib/built/segment-contract/json-schema.js +128 -0
- package/lib/built/segment-contract/media.d.ts +12 -0
- package/lib/built/segment-contract/media.js +22 -0
- package/lib/built/segment-contract/mention.d.ts +10 -0
- package/lib/built/segment-contract/mention.js +26 -0
- package/lib/built/segment-contract/preview.d.ts +3 -0
- package/lib/built/segment-contract/preview.js +159 -0
- package/lib/built/segment-contract/text.d.ts +7 -0
- package/lib/built/segment-contract/text.js +34 -0
- package/lib/built/segment-contract/types.d.ts +58 -0
- package/lib/built/segment-contract/types.js +1 -0
- package/lib/built/segment-contract/validate.d.ts +229 -0
- package/lib/built/segment-contract/validate.js +172 -0
- package/lib/built/tool-access.d.ts +5 -0
- package/lib/built/tool-access.js +17 -0
- package/lib/built/user-interaction.d.ts +30 -0
- package/lib/built/user-interaction.js +244 -0
- package/lib/component.d.ts +0 -1
- package/lib/component.js +30 -14
- package/lib/errors.d.ts +2 -3
- package/lib/errors.js +4 -5
- package/lib/feature/adapter.d.ts +2 -0
- package/lib/feature/adapter.js +2 -0
- package/lib/feature/command.d.ts +2 -0
- package/lib/feature/command.js +2 -0
- package/lib/feature/component.d.ts +2 -0
- package/lib/feature/component.js +2 -0
- package/lib/feature/handler.d.ts +48 -0
- package/lib/feature/handler.js +26 -0
- package/lib/feature/middleware.d.ts +2 -0
- package/lib/feature/middleware.js +2 -0
- package/lib/im-scene.d.ts +29 -0
- package/lib/im-scene.js +75 -0
- package/lib/im-session-id.d.ts +39 -0
- package/lib/im-session-id.js +47 -0
- package/lib/index.d.ts +29 -36
- package/lib/index.js +27 -41
- package/lib/jsx-dev-runtime.d.ts +0 -1
- package/lib/jsx-dev-runtime.js +0 -1
- package/lib/jsx-runtime.d.ts +1 -1
- package/lib/jsx-runtime.js +0 -1
- package/lib/jsx.d.ts +19 -22
- package/lib/jsx.js +0 -1
- package/lib/message.d.ts +17 -12
- package/lib/message.js +16 -13
- package/lib/models/system-log.d.ts +0 -3
- package/lib/models/system-log.js +1 -9
- package/lib/models/user.d.ts +0 -3
- package/lib/models/user.js +1 -8
- package/lib/notice.d.ts +16 -60
- package/lib/notice.js +1 -4
- package/lib/plugin-runtime/im/contracts.d.ts +191 -0
- package/lib/plugin-runtime/im/contracts.js +169 -0
- package/lib/plugin-runtime/im/conversation-runtime.d.ts +19 -0
- package/lib/plugin-runtime/im/conversation-runtime.js +312 -0
- package/lib/plugin-runtime/im/endpoint-runtime.d.ts +79 -0
- package/lib/plugin-runtime/im/endpoint-runtime.js +162 -0
- package/lib/plugin-runtime/im/im-runtime.d.ts +84 -0
- package/lib/plugin-runtime/im/im-runtime.js +201 -0
- package/lib/plugin-runtime/im/inbound-runtime.d.ts +31 -0
- package/lib/plugin-runtime/im/inbound-runtime.js +252 -0
- package/lib/plugin-runtime/im/index.d.ts +11 -0
- package/lib/plugin-runtime/im/index.js +9 -0
- package/lib/plugin-runtime/im/ingress-route.d.ts +10 -0
- package/lib/plugin-runtime/im/ingress-route.js +10 -0
- package/lib/plugin-runtime/im/interaction-runtime.d.ts +23 -0
- package/lib/plugin-runtime/im/interaction-runtime.js +181 -0
- package/lib/plugin-runtime/im/interactive-router.d.ts +17 -0
- package/lib/plugin-runtime/im/interactive-router.js +98 -0
- package/lib/plugin-runtime/im/login-assist-host.d.ts +6 -0
- package/lib/plugin-runtime/im/login-assist-host.js +6 -0
- package/lib/plugin-runtime/im/message-bus.d.ts +38 -0
- package/lib/plugin-runtime/im/message-bus.js +40 -0
- package/lib/plugin-runtime/im/message-dispatcher.d.ts +18 -0
- package/lib/plugin-runtime/im/message-dispatcher.js +107 -0
- package/lib/plugin-runtime/im/message-events.d.ts +26 -0
- package/lib/plugin-runtime/im/message-events.js +61 -0
- package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +19 -0
- package/lib/plugin-runtime/im/outbound-delivery-runtime.js +165 -0
- package/lib/plugin-runtime/im/outbound-renderer.d.ts +7 -0
- package/lib/plugin-runtime/im/outbound-renderer.js +70 -0
- package/lib/plugin-runtime/im/outbound-segments.d.ts +71 -0
- package/lib/plugin-runtime/im/outbound-segments.js +219 -0
- package/lib/plugin-runtime/im/public-api.d.ts +6 -0
- package/lib/plugin-runtime/im/public-api.js +6 -0
- package/lib/plugin-runtime/im/runtime-middleware.d.ts +3 -0
- package/lib/plugin-runtime/im/runtime-middleware.js +13 -0
- package/lib/request.d.ts +17 -62
- package/lib/request.js +0 -4
- package/lib/side-event/base.d.ts +51 -0
- package/lib/side-event/base.js +30 -0
- package/lib/side-event/dispatch.d.ts +15 -0
- package/lib/side-event/dispatch.js +140 -0
- package/lib/side-event/index.d.ts +4 -0
- package/lib/side-event/index.js +4 -0
- package/lib/side-event/normalize.d.ts +38 -0
- package/lib/side-event/normalize.js +111 -0
- package/lib/side-event/types.d.ts +23 -0
- package/lib/side-event/types.js +55 -0
- package/lib/system-event.d.ts +14 -0
- package/lib/system-event.js +7 -0
- package/lib/types.d.ts +35 -193
- package/lib/types.js +0 -1
- package/lib/utils.d.ts +81 -6
- package/lib/utils.js +54 -25
- package/package.json +94 -16
- package/lib/adapter.d.ts +0 -96
- package/lib/adapter.d.ts.map +0 -1
- package/lib/adapter.js +0 -217
- package/lib/adapter.js.map +0 -1
- package/lib/agent-prompt.d.ts +0 -37
- package/lib/agent-prompt.d.ts.map +0 -1
- package/lib/agent-prompt.js +0 -2
- package/lib/agent-prompt.js.map +0 -1
- package/lib/bot.d.ts +0 -38
- package/lib/bot.d.ts.map +0 -1
- package/lib/bot.js +0 -2
- package/lib/bot.js.map +0 -1
- package/lib/built/adapter-process.d.ts +0 -43
- package/lib/built/adapter-process.d.ts.map +0 -1
- package/lib/built/adapter-process.js +0 -81
- package/lib/built/adapter-process.js.map +0 -1
- package/lib/built/agent-preset.d.ts +0 -65
- package/lib/built/agent-preset.d.ts.map +0 -1
- package/lib/built/agent-preset.js +0 -80
- package/lib/built/agent-preset.js.map +0 -1
- package/lib/built/ai-trigger.d.ts.map +0 -1
- package/lib/built/ai-trigger.js.map +0 -1
- package/lib/built/command.d.ts +0 -68
- package/lib/built/command.d.ts.map +0 -1
- package/lib/built/command.js +0 -92
- package/lib/built/command.js.map +0 -1
- package/lib/built/common-adapter-tools.d.ts.map +0 -1
- package/lib/built/common-adapter-tools.js.map +0 -1
- package/lib/built/component.d.ts +0 -69
- package/lib/built/component.d.ts.map +0 -1
- package/lib/built/component.js +0 -99
- package/lib/built/component.js.map +0 -1
- package/lib/built/config.d.ts +0 -99
- package/lib/built/config.d.ts.map +0 -1
- package/lib/built/config.js +0 -355
- package/lib/built/config.js.map +0 -1
- package/lib/built/cron.d.ts +0 -75
- package/lib/built/cron.d.ts.map +0 -1
- package/lib/built/cron.js +0 -122
- package/lib/built/cron.js.map +0 -1
- package/lib/built/database.d.ts +0 -66
- package/lib/built/database.d.ts.map +0 -1
- package/lib/built/database.js +0 -100
- package/lib/built/database.js.map +0 -1
- package/lib/built/dispatcher.d.ts +0 -139
- package/lib/built/dispatcher.d.ts.map +0 -1
- package/lib/built/dispatcher.js +0 -361
- package/lib/built/dispatcher.js.map +0 -1
- package/lib/built/html-segment-fallback.d.ts.map +0 -1
- package/lib/built/html-segment-fallback.js.map +0 -1
- package/lib/built/html-to-text.d.ts.map +0 -1
- package/lib/built/html-to-text.js.map +0 -1
- package/lib/built/inbound-runner.d.ts +0 -23
- package/lib/built/inbound-runner.d.ts.map +0 -1
- package/lib/built/inbound-runner.js +0 -37
- package/lib/built/inbound-runner.js.map +0 -1
- package/lib/built/login-assist.d.ts.map +0 -1
- package/lib/built/login-assist.js.map +0 -1
- package/lib/built/mcp-mesh-registrar.d.ts +0 -9
- package/lib/built/mcp-mesh-registrar.d.ts.map +0 -1
- package/lib/built/mcp-mesh-registrar.js +0 -17
- package/lib/built/mcp-mesh-registrar.js.map +0 -1
- package/lib/built/message-filter.d.ts +0 -177
- package/lib/built/message-filter.d.ts.map +0 -1
- package/lib/built/message-filter.js +0 -241
- package/lib/built/message-filter.js.map +0 -1
- package/lib/built/permission.d.ts +0 -55
- package/lib/built/permission.d.ts.map +0 -1
- package/lib/built/permission.js +0 -112
- package/lib/built/permission.js.map +0 -1
- package/lib/built/prepend-quote-context.d.ts +0 -35
- package/lib/built/prepend-quote-context.d.ts.map +0 -1
- package/lib/built/prepend-quote-context.js +0 -131
- package/lib/built/prepend-quote-context.js.map +0 -1
- package/lib/built/queue-im-field-contract.d.ts.map +0 -1
- package/lib/built/queue-im-field-contract.js.map +0 -1
- package/lib/built/roles.d.ts.map +0 -1
- package/lib/built/roles.js.map +0 -1
- package/lib/built/runtime-io.d.ts +0 -10
- package/lib/built/runtime-io.d.ts.map +0 -1
- package/lib/built/runtime-io.js +0 -68
- package/lib/built/runtime-io.js.map +0 -1
- package/lib/built/schema-feature.d.ts +0 -78
- package/lib/built/schema-feature.d.ts.map +0 -1
- package/lib/built/schema-feature.js +0 -132
- package/lib/built/schema-feature.js.map +0 -1
- package/lib/built/skill.d.ts +0 -121
- package/lib/built/skill.d.ts.map +0 -1
- package/lib/built/skill.js +0 -152
- package/lib/built/skill.js.map +0 -1
- package/lib/built/tool.d.ts +0 -150
- package/lib/built/tool.d.ts.map +0 -1
- package/lib/built/tool.js +0 -383
- package/lib/built/tool.js.map +0 -1
- package/lib/command.d.ts +0 -42
- package/lib/command.d.ts.map +0 -1
- package/lib/command.js +0 -75
- package/lib/command.js.map +0 -1
- package/lib/component.d.ts.map +0 -1
- package/lib/component.js.map +0 -1
- package/lib/errors.d.ts.map +0 -1
- package/lib/errors.js.map +0 -1
- package/lib/index.d.ts.map +0 -1
- package/lib/index.js.map +0 -1
- package/lib/jsx-dev-runtime.d.ts.map +0 -1
- package/lib/jsx-dev-runtime.js.map +0 -1
- package/lib/jsx-runtime.d.ts.map +0 -1
- package/lib/jsx-runtime.js.map +0 -1
- package/lib/jsx.d.ts.map +0 -1
- package/lib/jsx.js.map +0 -1
- package/lib/message-quote.d.ts +0 -11
- package/lib/message-quote.d.ts.map +0 -1
- package/lib/message-quote.js +0 -91
- package/lib/message-quote.js.map +0 -1
- package/lib/message.d.ts.map +0 -1
- package/lib/message.js.map +0 -1
- package/lib/models/system-log.d.ts.map +0 -1
- package/lib/models/system-log.js.map +0 -1
- package/lib/models/user.d.ts.map +0 -1
- package/lib/models/user.js.map +0 -1
- package/lib/notice.d.ts.map +0 -1
- package/lib/notice.js.map +0 -1
- package/lib/plugin.d.ts +0 -258
- package/lib/plugin.d.ts.map +0 -1
- package/lib/plugin.js +0 -688
- package/lib/plugin.js.map +0 -1
- package/lib/prompt.d.ts +0 -118
- package/lib/prompt.d.ts.map +0 -1
- package/lib/prompt.js +0 -244
- package/lib/prompt.js.map +0 -1
- package/lib/request.d.ts.map +0 -1
- package/lib/request.js.map +0 -1
- package/lib/scheduler/scheduler.d.ts +0 -49
- package/lib/scheduler/scheduler.d.ts.map +0 -1
- package/lib/scheduler/scheduler.js +0 -352
- package/lib/scheduler/scheduler.js.map +0 -1
- package/lib/scheduler/types.d.ts +0 -71
- package/lib/scheduler/types.d.ts.map +0 -1
- package/lib/scheduler/types.js +0 -8
- package/lib/scheduler/types.js.map +0 -1
- package/lib/tool-zod.d.ts +0 -28
- package/lib/tool-zod.d.ts.map +0 -1
- package/lib/tool-zod.js +0 -98
- package/lib/tool-zod.js.map +0 -1
- package/lib/types-generator.d.ts +0 -6
- package/lib/types-generator.d.ts.map +0 -1
- package/lib/types-generator.js +0 -72
- package/lib/types-generator.js.map +0 -1
- package/lib/types.d.ts.map +0 -1
- package/lib/types.js.map +0 -1
- package/lib/utils.d.ts.map +0 -1
- package/lib/utils.js.map +0 -1
package/lib/built/skill.js
DELETED
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SkillFeature — AI 可见能力描述层
|
|
3
|
-
*
|
|
4
|
-
* 核心概念:
|
|
5
|
-
* Plugin = 运行时容器(生命周期、服务注册、中间件)
|
|
6
|
-
* Skill = AI 可见的能力接口(名称、描述、工具列表)
|
|
7
|
-
*
|
|
8
|
-
* Skill 记录由运行时注入(如 Agent 从磁盘 SKILL.md 同步),供 Agent 粗筛与工具关联。
|
|
9
|
-
*
|
|
10
|
-
* SkillFeature 全局收集所有 Skill,供 Agent 进行两级过滤:
|
|
11
|
-
* 1. 粗筛:根据用户消息选择相关 Skill
|
|
12
|
-
* 2. 细筛:从选中 Skill 内选择具体 Tool
|
|
13
|
-
*/
|
|
14
|
-
import { Feature } from '@zhin.js/kernel';
|
|
15
|
-
// ============================================================================
|
|
16
|
-
// SkillFeature 实现
|
|
17
|
-
// ============================================================================
|
|
18
|
-
export class SkillFeature extends Feature {
|
|
19
|
-
name = 'skill';
|
|
20
|
-
icon = 'Brain';
|
|
21
|
-
desc = '技能';
|
|
22
|
-
/** 按名称索引 */
|
|
23
|
-
byName = new Map();
|
|
24
|
-
/**
|
|
25
|
-
* 添加 Skill
|
|
26
|
-
*/
|
|
27
|
-
add(skill, pluginName) {
|
|
28
|
-
this.byName.set(skill.name, skill);
|
|
29
|
-
return super.add(skill, pluginName);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* 移除 Skill
|
|
33
|
-
*/
|
|
34
|
-
remove(skill) {
|
|
35
|
-
this.byName.delete(skill.name);
|
|
36
|
-
return super.remove(skill);
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* 按名称获取 Skill
|
|
40
|
-
*/
|
|
41
|
-
get(name) {
|
|
42
|
-
return this.byName.get(name);
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* 清理所有 Skill 注册(热重载时由 Plugin.stop() 调用)
|
|
46
|
-
*/
|
|
47
|
-
dispose() {
|
|
48
|
-
this.byName.clear();
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* 获取所有已注册 Skill
|
|
52
|
-
*/
|
|
53
|
-
getAll() {
|
|
54
|
-
return [...this.items];
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* 按关键词/标签搜索相关 Skill
|
|
58
|
-
* 返回按相关性排序的 Skill 列表
|
|
59
|
-
*/
|
|
60
|
-
search(query, options) {
|
|
61
|
-
const maxResults = options?.maxResults ?? 5;
|
|
62
|
-
const platform = options?.platform;
|
|
63
|
-
const scored = this.items
|
|
64
|
-
.filter(skill => {
|
|
65
|
-
// 平台过滤:有 platforms 限制的 skill 必须匹配当前平台
|
|
66
|
-
if (platform && skill.platforms?.length) {
|
|
67
|
-
return skill.platforms.includes(platform);
|
|
68
|
-
}
|
|
69
|
-
return true;
|
|
70
|
-
})
|
|
71
|
-
.map(skill => ({ skill, score: this.#scoreSkill(skill, query) }))
|
|
72
|
-
.filter(({ score }) => score > 0)
|
|
73
|
-
.sort((a, b) => b.score - a.score)
|
|
74
|
-
.slice(0, maxResults);
|
|
75
|
-
return scored.map(({ skill }) => skill);
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* 获取所有 Skill 的工具(扁平化)
|
|
79
|
-
*/
|
|
80
|
-
collectAllTools() {
|
|
81
|
-
const tools = [];
|
|
82
|
-
for (const skill of this.items) {
|
|
83
|
-
tools.push(...skill.tools);
|
|
84
|
-
}
|
|
85
|
-
return tools;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* 已注册 Skill 数量
|
|
89
|
-
*/
|
|
90
|
-
get size() {
|
|
91
|
-
return this.items.length;
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* 简单的关键词匹配评分
|
|
95
|
-
*/
|
|
96
|
-
#scoreSkill(skill, query) {
|
|
97
|
-
const lowerQuery = query.toLowerCase();
|
|
98
|
-
let score = 0;
|
|
99
|
-
// 关键词精确匹配
|
|
100
|
-
if (skill.keywords) {
|
|
101
|
-
for (const kw of skill.keywords) {
|
|
102
|
-
if (lowerQuery.includes(kw.toLowerCase()))
|
|
103
|
-
score += 1.0;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
// 标签匹配
|
|
107
|
-
if (skill.tags) {
|
|
108
|
-
for (const tag of skill.tags) {
|
|
109
|
-
if (lowerQuery.includes(tag.toLowerCase()))
|
|
110
|
-
score += 0.5;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
// 名称匹配
|
|
114
|
-
if (lowerQuery.includes(skill.name.toLowerCase()))
|
|
115
|
-
score += 0.3;
|
|
116
|
-
// 描述匹配(双向)
|
|
117
|
-
const lowerDesc = skill.description.toLowerCase();
|
|
118
|
-
if (lowerDesc.includes(lowerQuery))
|
|
119
|
-
score += 0.2;
|
|
120
|
-
if (lowerQuery.includes(lowerDesc))
|
|
121
|
-
score += 0.15;
|
|
122
|
-
// 工具名/描述匹配
|
|
123
|
-
for (const tool of skill.tools) {
|
|
124
|
-
if (lowerQuery.includes(tool.name.toLowerCase()))
|
|
125
|
-
score += 0.4;
|
|
126
|
-
if (tool.description && lowerQuery.includes(tool.description.toLowerCase().slice(0, 10))) {
|
|
127
|
-
score += 0.1;
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
return score;
|
|
131
|
-
}
|
|
132
|
-
/**
|
|
133
|
-
* 序列化为 JSON
|
|
134
|
-
*/
|
|
135
|
-
toJSON(pluginName) {
|
|
136
|
-
const list = pluginName ? this.getByPlugin(pluginName) : this.items;
|
|
137
|
-
return {
|
|
138
|
-
name: this.name,
|
|
139
|
-
icon: this.icon,
|
|
140
|
-
desc: this.desc,
|
|
141
|
-
count: list.length,
|
|
142
|
-
items: list.map(s => ({
|
|
143
|
-
name: s.name,
|
|
144
|
-
desc: s.description,
|
|
145
|
-
toolCount: s.tools.length,
|
|
146
|
-
keywords: s.keywords,
|
|
147
|
-
tags: s.tags,
|
|
148
|
-
})),
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
//# sourceMappingURL=skill.js.map
|
package/lib/built/skill.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"skill.js","sourceRoot":"","sources":["../../src/built/skill.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,OAAO,EAAe,MAAM,iBAAiB,CAAC;AA6EvD,+EAA+E;AAC/E,kBAAkB;AAClB,+EAA+E;AAE/E,MAAM,OAAO,YAAa,SAAQ,OAAc;IACrC,IAAI,GAAG,OAAgB,CAAC;IACxB,IAAI,GAAG,OAAO,CAAC;IACf,IAAI,GAAG,IAAI,CAAC;IAErB,YAAY;IACH,MAAM,GAAG,IAAI,GAAG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,CAAC,CAAC,EAAE,CAAC,CAAC;gBACpB,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,IAAI,EAAE,CAAC,CAAC,WAAW;gBACnB,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM;gBACzB,QAAQ,EAAE,CAAC,CAAC,QAAQ;gBACpB,IAAI,EAAE,CAAC,CAAC,IAAI;aACb,CAAC,CAAC;SACJ,CAAC;IACJ,CAAC;CACF"}
|
package/lib/built/tool.d.ts
DELETED
|
@@ -1,150 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ToolFeature — 统一的工具管理服务
|
|
3
|
-
* 工具仅面向 AI(通过 MCP 注册),不再与 Command 互转
|
|
4
|
-
*/
|
|
5
|
-
import { Feature, FeatureJSON } from "@zhin.js/kernel";
|
|
6
|
-
import type { Tool, ToolContext, ToolJsonSchema, ToolParametersSchema, PropertySchema, MaybePromise, ToolScope } from "../types.js";
|
|
7
|
-
/**
|
|
8
|
-
* 检查工具是否可被当前上下文访问
|
|
9
|
-
*/
|
|
10
|
-
export declare function canAccessTool(tool: Tool, context: ToolContext): boolean;
|
|
11
|
-
/**
|
|
12
|
-
* 从参数定义中提取参数信息
|
|
13
|
-
*/
|
|
14
|
-
export declare function extractParamInfo(parameters: ToolJsonSchema): Tool.ParamInfo[];
|
|
15
|
-
/**
|
|
16
|
-
* 定义工具的辅助函数(提供类型推断)
|
|
17
|
-
*/
|
|
18
|
-
export declare function defineTool<TArgs extends Record<string, any> = Record<string, any>>(tool: Tool<TArgs>): Tool;
|
|
19
|
-
/**
|
|
20
|
-
* 参数定义(带顺序)
|
|
21
|
-
*/
|
|
22
|
-
interface ParamDef {
|
|
23
|
-
name: string;
|
|
24
|
-
schema: PropertySchema;
|
|
25
|
-
required: boolean;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* ZhinTool 类
|
|
29
|
-
* 提供链式调用风格来定义工具
|
|
30
|
-
*/
|
|
31
|
-
export declare class ZhinTool {
|
|
32
|
-
#private;
|
|
33
|
-
constructor(name: string);
|
|
34
|
-
get name(): string;
|
|
35
|
-
get description(): string;
|
|
36
|
-
get params(): ParamDef[];
|
|
37
|
-
desc(description: string): this;
|
|
38
|
-
param(name: string, schema: PropertySchema, required?: boolean): this;
|
|
39
|
-
platform(...platforms: string[]): this;
|
|
40
|
-
scope(...scopes: ToolScope[]): this;
|
|
41
|
-
requireAnyRole(...roles: import('./roles.js').SenderRole[]): this;
|
|
42
|
-
permit(...permissions: string[]): this;
|
|
43
|
-
tag(...tags: string[]): this;
|
|
44
|
-
keyword(...keywords: string[]): this;
|
|
45
|
-
hidden(value?: boolean): this;
|
|
46
|
-
/**
|
|
47
|
-
* 标记此工具允许被预执行(opt-in)。
|
|
48
|
-
* 仅适用于无副作用的只读工具(如获取系统状态、读取配置等)。
|
|
49
|
-
* 默认为 false,即不预执行。
|
|
50
|
-
*/
|
|
51
|
-
preExec(value?: boolean): this;
|
|
52
|
-
/** 设置工具分类(如 file / shell / web),用于展示与 TOOLS.md 协同 */
|
|
53
|
-
kind(value: string): this;
|
|
54
|
-
execute(callback: (args: Record<string, any>, context?: ToolContext) => MaybePromise<any>): this;
|
|
55
|
-
toTool(): Tool;
|
|
56
|
-
toJSON(): {
|
|
57
|
-
name: string;
|
|
58
|
-
description: string;
|
|
59
|
-
parameters: ToolParametersSchema;
|
|
60
|
-
platforms?: string[];
|
|
61
|
-
scopes?: ToolScope[];
|
|
62
|
-
requiredAnyRole?: import('./roles.js').SenderRole[];
|
|
63
|
-
tags?: string[];
|
|
64
|
-
};
|
|
65
|
-
get help(): string;
|
|
66
|
-
toString(): string;
|
|
67
|
-
}
|
|
68
|
-
export declare function isZhinTool(obj: any): obj is ZhinTool;
|
|
69
|
-
/**
|
|
70
|
-
* 工具输入类型(支持 Tool 对象或 ZhinTool 实例)
|
|
71
|
-
*/
|
|
72
|
-
export type ToolInput = Tool | ZhinTool;
|
|
73
|
-
/**
|
|
74
|
-
* ToolContext 扩展方法类型
|
|
75
|
-
*/
|
|
76
|
-
export interface ToolContextExtensions {
|
|
77
|
-
/** 添加工具 */
|
|
78
|
-
addTool(tool: ToolInput): () => void;
|
|
79
|
-
}
|
|
80
|
-
declare module "../plugin.js" {
|
|
81
|
-
namespace Plugin {
|
|
82
|
-
interface Extensions extends ToolContextExtensions {
|
|
83
|
-
}
|
|
84
|
-
interface Contexts {
|
|
85
|
-
tool: ToolFeature;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
export declare class ToolFeature extends Feature<Tool> {
|
|
90
|
-
#private;
|
|
91
|
-
readonly name: "tool";
|
|
92
|
-
readonly icon = "Wrench";
|
|
93
|
-
readonly desc = "\u5DE5\u5177";
|
|
94
|
-
/** 按名称索引 */
|
|
95
|
-
readonly byName: Map<string, Tool<Record<string, any>>>;
|
|
96
|
-
/**
|
|
97
|
-
* 添加工具(仅注册到 ToolFeature,不再生成 Command)
|
|
98
|
-
* @param toolInput 工具或 ZhinTool 实例
|
|
99
|
-
* @param pluginName 注册插件名
|
|
100
|
-
*/
|
|
101
|
-
addTool(toolInput: ToolInput, pluginName: string): () => void;
|
|
102
|
-
/**
|
|
103
|
-
* 移除工具
|
|
104
|
-
*/
|
|
105
|
-
removeTool(name: string): boolean;
|
|
106
|
-
/**
|
|
107
|
-
* 获取工具
|
|
108
|
-
*/
|
|
109
|
-
get(name: string): Tool | undefined;
|
|
110
|
-
/**
|
|
111
|
-
* 获取所有工具
|
|
112
|
-
*/
|
|
113
|
-
getAll(): Tool[];
|
|
114
|
-
/**
|
|
115
|
-
* 根据标签过滤工具
|
|
116
|
-
*/
|
|
117
|
-
getByTags(tags: string[]): Tool[];
|
|
118
|
-
/**
|
|
119
|
-
* 执行工具
|
|
120
|
-
*/
|
|
121
|
-
execute(name: string, args: Record<string, any>, context?: ToolContext): Promise<any>;
|
|
122
|
-
/**
|
|
123
|
-
* 根据上下文过滤工具
|
|
124
|
-
*/
|
|
125
|
-
filterByContext(tools: Tool[], context: ToolContext): Tool[];
|
|
126
|
-
/**
|
|
127
|
-
* 按插件名获取工具
|
|
128
|
-
*/
|
|
129
|
-
getToolsByPlugin(pluginName: string): Tool[];
|
|
130
|
-
/**
|
|
131
|
-
* 生命周期: 销毁时清理所有工具
|
|
132
|
-
*/
|
|
133
|
-
dispose(): void;
|
|
134
|
-
/**
|
|
135
|
-
* 兼容旧接口:tools Map
|
|
136
|
-
*/
|
|
137
|
-
get tools(): Map<string, Tool>;
|
|
138
|
-
/**
|
|
139
|
-
* 序列化为 JSON
|
|
140
|
-
*/
|
|
141
|
-
toJSON(pluginName?: string): FeatureJSON;
|
|
142
|
-
/**
|
|
143
|
-
* 提供给 Plugin.prototype 的扩展方法
|
|
144
|
-
*/
|
|
145
|
-
get extensions(): {
|
|
146
|
-
addTool(tool: ToolInput): () => void;
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
export {};
|
|
150
|
-
//# sourceMappingURL=tool.d.ts.map
|
package/lib/built/tool.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/built/tool.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEvD,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,cAAc,EAAE,oBAAoB,EAAE,cAAc,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAGpI;;GAEG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,WAAW,GAAG,OAAO,CAQvE;AAMD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,UAAU,EAAE,cAAc,GAAG,IAAI,CAAC,SAAS,EAAE,CAY7E;AAED;;GAEG;AACH,wBAAgB,UAAU,CAAC,KAAK,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM,CAAC,MA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AAC,IAAI,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS;IAInC;;OAEG;IACH,MAAM,IAAI,IAAI,EAAE;IAIhB;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE;IAMjC;;OAEG;IACG,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,OAAO,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,GAAG,CAAC;IAQ3F;;OAEG;IACH,eAAe,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,OAAO,EAAE,WAAW,GAAG,IAAI,EAAE;IAI5D;;OAEG;IACH,gBAAgB,CAAC,UAAU,EAAE,MAAM,GAAG,IAAI,EAAE;IAW5C;;OAEG;IACH,OAAO,IAAI,IAAI;IAKf;;OAEG;IACH,IAAI,KAAK,IAAI,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC,CAE7B;IAED;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,WAAW;IAgBxC;;OAEG;IACH,IAAI,UAAU;sBAGI,SAAS,SAzI8B,IAAI;MAkJ5D;CACF"}
|
package/lib/built/tool.js
DELETED
|
@@ -1,383 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ToolFeature — 统一的工具管理服务
|
|
3
|
-
* 工具仅面向 AI(通过 MCP 注册),不再与 Command 互转
|
|
4
|
-
*/
|
|
5
|
-
import { Feature } from "@zhin.js/kernel";
|
|
6
|
-
import { getPlugin } from "../plugin.js";
|
|
7
|
-
import { roleSatisfies, resolveRolesFromContext } from './roles.js';
|
|
8
|
-
/**
|
|
9
|
-
* 检查工具是否可被当前上下文访问
|
|
10
|
-
*/
|
|
11
|
-
export function canAccessTool(tool, context) {
|
|
12
|
-
if (tool.platforms?.length && (!context.platform || !tool.platforms.includes(context.platform))) {
|
|
13
|
-
return false;
|
|
14
|
-
}
|
|
15
|
-
if (tool.scopes?.length && (!context.scope || !tool.scopes.includes(context.scope))) {
|
|
16
|
-
return false;
|
|
17
|
-
}
|
|
18
|
-
return roleSatisfies(resolveRolesFromContext(context), tool.requiredAnyRole);
|
|
19
|
-
}
|
|
20
|
-
// ============================================================================
|
|
21
|
-
// Tool 工具函数
|
|
22
|
-
// ============================================================================
|
|
23
|
-
/**
|
|
24
|
-
* 从参数定义中提取参数信息
|
|
25
|
-
*/
|
|
26
|
-
export function extractParamInfo(parameters) {
|
|
27
|
-
if (!parameters.properties)
|
|
28
|
-
return [];
|
|
29
|
-
const required = parameters.required || [];
|
|
30
|
-
return Object.entries(parameters.properties).map(([name, schema]) => ({
|
|
31
|
-
name,
|
|
32
|
-
type: schema.type,
|
|
33
|
-
required: required.includes(name),
|
|
34
|
-
description: schema.description,
|
|
35
|
-
default: schema.default,
|
|
36
|
-
enum: schema.enum,
|
|
37
|
-
}));
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* 定义工具的辅助函数(提供类型推断)
|
|
41
|
-
*/
|
|
42
|
-
export function defineTool(tool) {
|
|
43
|
-
return tool;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* ZhinTool 类
|
|
47
|
-
* 提供链式调用风格来定义工具
|
|
48
|
-
*/
|
|
49
|
-
export class ZhinTool {
|
|
50
|
-
#name;
|
|
51
|
-
#description = '';
|
|
52
|
-
/** 有序的参数列表 */
|
|
53
|
-
#params = [];
|
|
54
|
-
#execute;
|
|
55
|
-
#platforms = [];
|
|
56
|
-
#scopes = [];
|
|
57
|
-
#requiredAnyRole = [];
|
|
58
|
-
#permissions = [];
|
|
59
|
-
#tags = [];
|
|
60
|
-
#keywords = [];
|
|
61
|
-
#hidden = false;
|
|
62
|
-
#source;
|
|
63
|
-
#preExecutable = false;
|
|
64
|
-
#kind;
|
|
65
|
-
constructor(name) {
|
|
66
|
-
this.#name = name;
|
|
67
|
-
}
|
|
68
|
-
get name() {
|
|
69
|
-
return this.#name;
|
|
70
|
-
}
|
|
71
|
-
get description() {
|
|
72
|
-
return this.#description;
|
|
73
|
-
}
|
|
74
|
-
get params() {
|
|
75
|
-
return [...this.#params];
|
|
76
|
-
}
|
|
77
|
-
desc(description) {
|
|
78
|
-
this.#description = description;
|
|
79
|
-
return this;
|
|
80
|
-
}
|
|
81
|
-
param(name, schema, required = false) {
|
|
82
|
-
const existingIndex = this.#params.findIndex(p => p.name === name);
|
|
83
|
-
if (existingIndex >= 0) {
|
|
84
|
-
this.#params[existingIndex] = { name, schema, required };
|
|
85
|
-
}
|
|
86
|
-
else {
|
|
87
|
-
this.#params.push({ name, schema, required });
|
|
88
|
-
}
|
|
89
|
-
return this;
|
|
90
|
-
}
|
|
91
|
-
platform(...platforms) {
|
|
92
|
-
this.#platforms.push(...platforms);
|
|
93
|
-
return this;
|
|
94
|
-
}
|
|
95
|
-
scope(...scopes) {
|
|
96
|
-
this.#scopes.push(...scopes);
|
|
97
|
-
return this;
|
|
98
|
-
}
|
|
99
|
-
requireAnyRole(...roles) {
|
|
100
|
-
this.#requiredAnyRole = [...roles];
|
|
101
|
-
return this;
|
|
102
|
-
}
|
|
103
|
-
permit(...permissions) {
|
|
104
|
-
this.#permissions.push(...permissions);
|
|
105
|
-
return this;
|
|
106
|
-
}
|
|
107
|
-
tag(...tags) {
|
|
108
|
-
this.#tags.push(...tags);
|
|
109
|
-
return this;
|
|
110
|
-
}
|
|
111
|
-
keyword(...keywords) {
|
|
112
|
-
this.#keywords.push(...keywords);
|
|
113
|
-
return this;
|
|
114
|
-
}
|
|
115
|
-
hidden(value = true) {
|
|
116
|
-
this.#hidden = value;
|
|
117
|
-
return this;
|
|
118
|
-
}
|
|
119
|
-
/**
|
|
120
|
-
* 标记此工具允许被预执行(opt-in)。
|
|
121
|
-
* 仅适用于无副作用的只读工具(如获取系统状态、读取配置等)。
|
|
122
|
-
* 默认为 false,即不预执行。
|
|
123
|
-
*/
|
|
124
|
-
preExec(value = true) {
|
|
125
|
-
this.#preExecutable = value;
|
|
126
|
-
return this;
|
|
127
|
-
}
|
|
128
|
-
/** 设置工具分类(如 file / shell / web),用于展示与 TOOLS.md 协同 */
|
|
129
|
-
kind(value) {
|
|
130
|
-
this.#kind = value;
|
|
131
|
-
return this;
|
|
132
|
-
}
|
|
133
|
-
execute(callback) {
|
|
134
|
-
this.#execute = callback;
|
|
135
|
-
return this;
|
|
136
|
-
}
|
|
137
|
-
#buildParameters() {
|
|
138
|
-
const properties = {};
|
|
139
|
-
const required = [];
|
|
140
|
-
const sortedParams = [...this.#params].sort((a, b) => {
|
|
141
|
-
if (a.required && !b.required)
|
|
142
|
-
return -1;
|
|
143
|
-
if (!a.required && b.required)
|
|
144
|
-
return 1;
|
|
145
|
-
return 0;
|
|
146
|
-
});
|
|
147
|
-
for (const param of sortedParams) {
|
|
148
|
-
properties[param.name] = param.schema;
|
|
149
|
-
if (param.required) {
|
|
150
|
-
required.push(param.name);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
return {
|
|
154
|
-
type: 'object',
|
|
155
|
-
properties,
|
|
156
|
-
required: required.length > 0 ? required : undefined,
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
toTool() {
|
|
160
|
-
if (!this.#execute) {
|
|
161
|
-
throw new Error(`Tool "${this.#name}" has no execute() defined`);
|
|
162
|
-
}
|
|
163
|
-
const tool = {
|
|
164
|
-
name: this.#name,
|
|
165
|
-
description: this.#description,
|
|
166
|
-
parameters: this.#buildParameters(),
|
|
167
|
-
execute: this.#execute,
|
|
168
|
-
};
|
|
169
|
-
if (this.#platforms.length > 0)
|
|
170
|
-
tool.platforms = this.#platforms;
|
|
171
|
-
if (this.#scopes.length > 0)
|
|
172
|
-
tool.scopes = this.#scopes;
|
|
173
|
-
if (this.#requiredAnyRole.length > 0)
|
|
174
|
-
tool.requiredAnyRole = [...this.#requiredAnyRole];
|
|
175
|
-
if (this.#permissions.length > 0)
|
|
176
|
-
tool.permissions = this.#permissions;
|
|
177
|
-
if (this.#tags.length > 0)
|
|
178
|
-
tool.tags = this.#tags;
|
|
179
|
-
if (this.#hidden)
|
|
180
|
-
tool.hidden = this.#hidden;
|
|
181
|
-
if (this.#source)
|
|
182
|
-
tool.source = this.#source;
|
|
183
|
-
if (this.#keywords.length > 0)
|
|
184
|
-
tool.keywords = this.#keywords;
|
|
185
|
-
if (this.#preExecutable)
|
|
186
|
-
tool.preExecutable = true;
|
|
187
|
-
if (this.#kind)
|
|
188
|
-
tool.kind = this.#kind;
|
|
189
|
-
return tool;
|
|
190
|
-
}
|
|
191
|
-
toJSON() {
|
|
192
|
-
const json = {
|
|
193
|
-
name: this.#name,
|
|
194
|
-
description: this.#description,
|
|
195
|
-
parameters: this.#buildParameters(),
|
|
196
|
-
};
|
|
197
|
-
if (this.#platforms.length > 0)
|
|
198
|
-
json.platforms = this.#platforms;
|
|
199
|
-
if (this.#scopes.length > 0)
|
|
200
|
-
json.scopes = this.#scopes;
|
|
201
|
-
if (this.#requiredAnyRole.length > 0)
|
|
202
|
-
json.requiredAnyRole = [...this.#requiredAnyRole];
|
|
203
|
-
if (this.#tags.length > 0)
|
|
204
|
-
json.tags = this.#tags;
|
|
205
|
-
return json;
|
|
206
|
-
}
|
|
207
|
-
get help() {
|
|
208
|
-
const lines = [this.#name];
|
|
209
|
-
if (this.#description)
|
|
210
|
-
lines.push(` ${this.#description}`);
|
|
211
|
-
if (this.#params.length > 0) {
|
|
212
|
-
lines.push(' 参数:');
|
|
213
|
-
for (const param of this.#params) {
|
|
214
|
-
const required = param.required ? '(必填)' : '(可选)';
|
|
215
|
-
const desc = param.schema.description || '';
|
|
216
|
-
lines.push(` ${param.name}: ${param.schema.type} ${required} ${desc}`);
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
if (this.#requiredAnyRole.length > 0) {
|
|
220
|
-
lines.push(` 角色: ${this.#requiredAnyRole.join(', ')}`);
|
|
221
|
-
}
|
|
222
|
-
if (this.#platforms.length > 0) {
|
|
223
|
-
lines.push(` 平台: ${this.#platforms.join(', ')}`);
|
|
224
|
-
}
|
|
225
|
-
if (this.#scopes.length > 0) {
|
|
226
|
-
lines.push(` 场景: ${this.#scopes.join(', ')}`);
|
|
227
|
-
}
|
|
228
|
-
return lines.join('\n');
|
|
229
|
-
}
|
|
230
|
-
toString() {
|
|
231
|
-
return `[ZhinTool: ${this.#name}] ${this.#description}`;
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
export function isZhinTool(obj) {
|
|
235
|
-
return obj instanceof ZhinTool;
|
|
236
|
-
}
|
|
237
|
-
// ============================================================================
|
|
238
|
-
// ToolFeature 实现
|
|
239
|
-
// ============================================================================
|
|
240
|
-
export class ToolFeature extends Feature {
|
|
241
|
-
name = 'tool';
|
|
242
|
-
icon = 'Wrench';
|
|
243
|
-
desc = '工具';
|
|
244
|
-
/** 按名称索引 */
|
|
245
|
-
byName = new Map();
|
|
246
|
-
/** 工具到插件名的映射 */
|
|
247
|
-
#toolPluginMap = new Map();
|
|
248
|
-
/**
|
|
249
|
-
* 添加工具(仅注册到 ToolFeature,不再生成 Command)
|
|
250
|
-
* @param toolInput 工具或 ZhinTool 实例
|
|
251
|
-
* @param pluginName 注册插件名
|
|
252
|
-
*/
|
|
253
|
-
addTool(toolInput, pluginName) {
|
|
254
|
-
const zhinTool = isZhinTool(toolInput) ? toolInput : null;
|
|
255
|
-
const tool = zhinTool ? zhinTool.toTool() : toolInput;
|
|
256
|
-
// Re-register (e.g. adapter hot-reload) must not leave duplicate entries in items[]
|
|
257
|
-
if (this.byName.has(tool.name)) {
|
|
258
|
-
this.removeTool(tool.name);
|
|
259
|
-
}
|
|
260
|
-
const toolWithSource = {
|
|
261
|
-
...tool,
|
|
262
|
-
source: tool.source || `plugin:${pluginName}`,
|
|
263
|
-
tags: [...(tool.tags || []), 'plugin', pluginName],
|
|
264
|
-
};
|
|
265
|
-
this.byName.set(tool.name, toolWithSource);
|
|
266
|
-
this.#toolPluginMap.set(tool.name, pluginName);
|
|
267
|
-
// Use Feature.add for item tracking
|
|
268
|
-
const baseDispose = super.add(toolWithSource, pluginName);
|
|
269
|
-
return () => {
|
|
270
|
-
this.removeTool(tool.name);
|
|
271
|
-
baseDispose();
|
|
272
|
-
};
|
|
273
|
-
}
|
|
274
|
-
/**
|
|
275
|
-
* 移除工具
|
|
276
|
-
*/
|
|
277
|
-
removeTool(name) {
|
|
278
|
-
const tool = this.byName.get(name);
|
|
279
|
-
if (!tool)
|
|
280
|
-
return false;
|
|
281
|
-
this.byName.delete(name);
|
|
282
|
-
this.#toolPluginMap.delete(name);
|
|
283
|
-
// 移除 item
|
|
284
|
-
super.remove(tool);
|
|
285
|
-
return true;
|
|
286
|
-
}
|
|
287
|
-
/**
|
|
288
|
-
* 获取工具
|
|
289
|
-
*/
|
|
290
|
-
get(name) {
|
|
291
|
-
return this.byName.get(name);
|
|
292
|
-
}
|
|
293
|
-
/**
|
|
294
|
-
* 获取所有工具
|
|
295
|
-
*/
|
|
296
|
-
getAll() {
|
|
297
|
-
return [...this.items];
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* 根据标签过滤工具
|
|
301
|
-
*/
|
|
302
|
-
getByTags(tags) {
|
|
303
|
-
return this.items.filter(tool => tags.some(tag => tool.tags?.includes(tag)));
|
|
304
|
-
}
|
|
305
|
-
/**
|
|
306
|
-
* 执行工具
|
|
307
|
-
*/
|
|
308
|
-
async execute(name, args, context) {
|
|
309
|
-
const tool = this.byName.get(name);
|
|
310
|
-
if (!tool) {
|
|
311
|
-
throw new Error(`Tool "${name}" not found`);
|
|
312
|
-
}
|
|
313
|
-
return tool.execute(args, context);
|
|
314
|
-
}
|
|
315
|
-
/**
|
|
316
|
-
* 根据上下文过滤工具
|
|
317
|
-
*/
|
|
318
|
-
filterByContext(tools, context) {
|
|
319
|
-
return tools.filter(tool => canAccessTool(tool, context));
|
|
320
|
-
}
|
|
321
|
-
/**
|
|
322
|
-
* 按插件名获取工具
|
|
323
|
-
*/
|
|
324
|
-
getToolsByPlugin(pluginName) {
|
|
325
|
-
const result = [];
|
|
326
|
-
for (const [toolName, pName] of this.#toolPluginMap) {
|
|
327
|
-
if (pName === pluginName) {
|
|
328
|
-
const tool = this.byName.get(toolName);
|
|
329
|
-
if (tool)
|
|
330
|
-
result.push(tool);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
return result;
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* 生命周期: 销毁时清理所有工具
|
|
337
|
-
*/
|
|
338
|
-
dispose() {
|
|
339
|
-
this.byName.clear();
|
|
340
|
-
this.#toolPluginMap.clear();
|
|
341
|
-
}
|
|
342
|
-
/**
|
|
343
|
-
* 兼容旧接口:tools Map
|
|
344
|
-
*/
|
|
345
|
-
get tools() {
|
|
346
|
-
return this.byName;
|
|
347
|
-
}
|
|
348
|
-
/**
|
|
349
|
-
* 序列化为 JSON
|
|
350
|
-
*/
|
|
351
|
-
toJSON(pluginName) {
|
|
352
|
-
const list = pluginName ? this.getByPlugin(pluginName) : this.items;
|
|
353
|
-
return {
|
|
354
|
-
name: this.name,
|
|
355
|
-
icon: this.icon,
|
|
356
|
-
desc: this.desc,
|
|
357
|
-
count: list.length,
|
|
358
|
-
items: list.map(t => ({
|
|
359
|
-
name: t.name,
|
|
360
|
-
desc: t.description,
|
|
361
|
-
platforms: t.platforms,
|
|
362
|
-
tags: t.tags,
|
|
363
|
-
})),
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* 提供给 Plugin.prototype 的扩展方法
|
|
368
|
-
*/
|
|
369
|
-
get extensions() {
|
|
370
|
-
const feature = this;
|
|
371
|
-
return {
|
|
372
|
-
addTool(tool) {
|
|
373
|
-
const plugin = getPlugin();
|
|
374
|
-
const toolObj = isZhinTool(tool) ? tool.toTool() : tool;
|
|
375
|
-
const dispose = feature.addTool(tool, plugin.name);
|
|
376
|
-
plugin.recordFeatureContribution(feature.name, toolObj.name);
|
|
377
|
-
plugin.onDispose(dispose);
|
|
378
|
-
return dispose;
|
|
379
|
-
},
|
|
380
|
-
};
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
//# sourceMappingURL=tool.js.map
|