@zhin.js/core 1.1.35 → 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 +79 -193
- package/lib/built/ai-outbound/index.d.ts +0 -1
- package/lib/built/ai-outbound/index.js +0 -1
- package/lib/built/ai-outbound/types.d.ts +0 -9
- package/lib/built/ai-trigger.d.ts +0 -5
- package/lib/built/ai-trigger.js +1 -27
- package/lib/built/common-adapter-tools.d.ts +0 -2
- package/lib/built/common-adapter-tools.js +0 -4
- package/lib/built/html-segment-fallback.d.ts +2 -5
- package/lib/built/html-segment-fallback.js +0 -15
- package/lib/built/interactive-segments/index.d.ts +0 -2
- package/lib/built/interactive-segments/index.js +0 -2
- package/lib/built/interactive-segments/keyboard-segment.d.ts +0 -1
- package/lib/built/interactive-segments/keyboard-segment.js +0 -1
- package/lib/built/interactive-segments/onebot-keyboard.d.ts +0 -1
- package/lib/built/interactive-segments/onebot-keyboard.js +0 -2
- package/lib/built/interactive-segments/resolve.d.ts +0 -1
- package/lib/built/interactive-segments/resolve.js +0 -1
- package/lib/built/interactive-segments/types.d.ts +0 -5
- package/lib/built/login-assist.d.ts +1 -8
- package/lib/built/message-enrich.d.ts +2 -8
- package/lib/built/message-enrich.js +3 -11
- package/lib/built/segment-contract/validate.d.ts +2 -2
- package/lib/built/segment-contract/validate.js +1 -3
- package/lib/built/tool-access.d.ts +5 -0
- package/lib/built/tool-access.js +17 -0
- package/lib/built/user-interaction.js +0 -4
- package/lib/feature/handler.d.ts +1 -5
- package/lib/index.d.ts +4 -45
- package/lib/index.js +3 -39
- package/lib/message.d.ts +1 -2
- package/lib/models/system-log.d.ts +0 -2
- package/lib/models/system-log.js +1 -8
- package/lib/models/user.d.ts +0 -2
- package/lib/models/user.js +1 -7
- package/lib/notice.d.ts +1 -2
- 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 +13 -106
- package/lib/plugin-runtime/im/im-runtime.js +58 -1061
- 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 +4 -2
- package/lib/plugin-runtime/im/index.js +2 -2
- 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/message-bus.d.ts +3 -3
- package/lib/plugin-runtime/im/message-bus.js +3 -3
- 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-segments.d.ts +2 -3
- package/lib/plugin-runtime/im/outbound-segments.js +3 -4
- 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 +1 -2
- package/lib/side-event/base.d.ts +1 -2
- package/lib/side-event/normalize.d.ts +1 -5
- package/lib/side-event/normalize.js +1 -11
- package/lib/system-event.d.ts +1 -2
- package/lib/types.d.ts +9 -116
- package/lib/utils.d.ts +51 -24
- package/lib/utils.js +11 -23
- package/package.json +18 -28
- package/lib/adapter.d.ts +0 -145
- package/lib/adapter.js +0 -377
- package/lib/built/adapter-process.d.ts +0 -58
- package/lib/built/adapter-process.js +0 -128
- package/lib/built/agent-preset.d.ts +0 -64
- package/lib/built/agent-preset.js +0 -79
- package/lib/built/ai-outbound/adapter-access.d.ts +0 -3
- package/lib/built/ai-outbound/adapter-access.js +0 -9
- package/lib/built/authorization.d.ts +0 -10
- package/lib/built/authorization.js +0 -76
- package/lib/built/command.d.ts +0 -72
- package/lib/built/command.js +0 -105
- package/lib/built/component.d.ts +0 -67
- package/lib/built/component.js +0 -97
- package/lib/built/config.d.ts +0 -98
- package/lib/built/config.js +0 -372
- package/lib/built/connect-endpoint-instance.d.ts +0 -17
- package/lib/built/connect-endpoint-instance.js +0 -42
- package/lib/built/database.d.ts +0 -68
- package/lib/built/database.js +0 -106
- package/lib/built/dispatcher.d.ts +0 -141
- package/lib/built/dispatcher.js +0 -383
- package/lib/built/endpoint-commands.d.ts +0 -3
- package/lib/built/endpoint-commands.js +0 -99
- package/lib/built/endpoint-lifecycle-service.d.ts +0 -28
- package/lib/built/endpoint-lifecycle-service.js +0 -242
- package/lib/built/endpoint-lifecycle.d.ts +0 -27
- package/lib/built/endpoint-lifecycle.js +0 -36
- package/lib/built/endpoint-manager.d.ts +0 -34
- package/lib/built/endpoint-manager.js +0 -1
- package/lib/built/html-renderer-loader.d.ts +0 -13
- package/lib/built/html-renderer-loader.js +0 -33
- package/lib/built/inbound-pipeline.d.ts +0 -37
- package/lib/built/inbound-pipeline.js +0 -63
- package/lib/built/inbound-runner.d.ts +0 -22
- package/lib/built/inbound-runner.js +0 -34
- package/lib/built/interactive-segment-contract.d.ts +0 -6
- package/lib/built/interactive-segment-contract.js +0 -9
- package/lib/built/interactive-segments/fallback-store.d.ts +0 -29
- package/lib/built/interactive-segments/fallback-store.js +0 -63
- package/lib/built/interactive-segments/handlers.d.ts +0 -16
- package/lib/built/interactive-segments/handlers.js +0 -74
- package/lib/built/introspection-format.d.ts +0 -10
- package/lib/built/introspection-format.js +0 -28
- package/lib/built/management-command-guard.d.ts +0 -15
- package/lib/built/management-command-guard.js +0 -25
- package/lib/built/message-filter.d.ts +0 -176
- package/lib/built/message-filter.js +0 -239
- package/lib/built/optional-peer-import.d.ts +0 -3
- package/lib/built/optional-peer-import.js +0 -33
- package/lib/built/outbound-media-contract.d.ts +0 -22
- package/lib/built/outbound-media-contract.js +0 -10
- package/lib/built/permission.d.ts +0 -51
- package/lib/built/permission.js +0 -99
- package/lib/built/permit-check.d.ts +0 -7
- package/lib/built/permit-check.js +0 -35
- package/lib/built/permit-parse.d.ts +0 -16
- package/lib/built/permit-parse.js +0 -32
- package/lib/built/platform-permit.d.ts +0 -20
- package/lib/built/platform-permit.js +0 -91
- package/lib/built/rich-segments/adapter-policies.d.ts +0 -9
- package/lib/built/rich-segments/adapter-policies.js +0 -27
- package/lib/built/rich-segments/base.d.ts +0 -11
- package/lib/built/rich-segments/base.js +0 -24
- package/lib/built/rich-segments/builtins.d.ts +0 -4
- package/lib/built/rich-segments/builtins.js +0 -40
- package/lib/built/rich-segments/capabilities.d.ts +0 -6
- package/lib/built/rich-segments/capabilities.js +0 -38
- package/lib/built/rich-segments/html-segment.d.ts +0 -15
- package/lib/built/rich-segments/html-segment.js +0 -62
- package/lib/built/rich-segments/index.d.ts +0 -13
- package/lib/built/rich-segments/index.js +0 -13
- package/lib/built/rich-segments/markdown-segment.d.ts +0 -14
- package/lib/built/rich-segments/markdown-segment.js +0 -58
- package/lib/built/rich-segments/qrcode-segment.d.ts +0 -18
- package/lib/built/rich-segments/qrcode-segment.js +0 -73
- package/lib/built/rich-segments/registry.d.ts +0 -16
- package/lib/built/rich-segments/registry.js +0 -52
- package/lib/built/rich-segments/resolve.d.ts +0 -5
- package/lib/built/rich-segments/resolve.js +0 -87
- package/lib/built/rich-segments/tts-segment.d.ts +0 -13
- package/lib/built/rich-segments/tts-segment.js +0 -51
- package/lib/built/rich-segments/types.d.ts +0 -79
- package/lib/built/rich-segments/types.js +0 -17
- package/lib/built/runtime-io.d.ts +0 -9
- package/lib/built/runtime-io.js +0 -67
- package/lib/built/schedule.d.ts +0 -54
- package/lib/built/schedule.js +0 -112
- package/lib/built/schema-endpoint-manager.d.ts +0 -17
- package/lib/built/schema-endpoint-manager.js +0 -73
- package/lib/built/schema-feature.d.ts +0 -77
- package/lib/built/schema-feature.js +0 -130
- package/lib/built/skill.d.ts +0 -120
- package/lib/built/skill.js +0 -151
- package/lib/built/speech-loader.d.ts +0 -14
- package/lib/built/speech-loader.js +0 -32
- package/lib/built/tool.d.ts +0 -151
- package/lib/built/tool.js +0 -388
- package/lib/command.d.ts +0 -50
- package/lib/command.js +0 -106
- package/lib/endpoint-capabilities.d.ts +0 -46
- package/lib/endpoint-capabilities.js +0 -55
- package/lib/endpoint.d.ts +0 -19
- package/lib/endpoint.js +0 -3
- package/lib/host-plugin-registry.d.ts +0 -8
- package/lib/host-plugin-registry.js +0 -12
- package/lib/plugin-context.d.ts +0 -27
- package/lib/plugin-context.js +0 -64
- package/lib/plugin-runtime/im/interactive.d.ts +0 -26
- package/lib/plugin-runtime/im/interactive.js +0 -46
- package/lib/plugin-runtime/im/service-tokens.d.ts +0 -18
- package/lib/plugin-runtime/im/service-tokens.js +0 -13
- package/lib/plugin.d.ts +0 -268
- package/lib/plugin.js +0 -583
- package/lib/schema-interaction.d.ts +0 -117
- package/lib/schema-interaction.js +0 -247
- package/lib/tool-zod.d.ts +0 -43
- package/lib/tool-zod.js +0 -184
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* AgentPreset — 插件声明的专长 Agent 预设
|
|
3
|
-
*
|
|
4
|
-
* 核心概念:
|
|
5
|
-
* Tool = 单个 AI 可调用的能力(函数)
|
|
6
|
-
* Skill = 一组相关 Tool + 发现元数据(SKILL.md)
|
|
7
|
-
* Agent = 针对特定领域的 Agent 预设(*.agent.md)
|
|
8
|
-
*
|
|
9
|
-
* Agent 预设以标准 *.agent.md 文件提供,框架自动扫描发现。
|
|
10
|
-
* 主 Agent(ZhinAgent)可根据用户请求自动委派给匹配的专长 Agent。
|
|
11
|
-
*/
|
|
12
|
-
import { Feature } from '@zhin.js/kernel';
|
|
13
|
-
export class AgentPresetFeature extends Feature {
|
|
14
|
-
name = 'agentPreset';
|
|
15
|
-
icon = 'Endpoint';
|
|
16
|
-
desc = 'Agent 预设';
|
|
17
|
-
byName = new Map();
|
|
18
|
-
add(preset, pluginName) {
|
|
19
|
-
this.byName.set(preset.name, preset);
|
|
20
|
-
return super.add(preset, pluginName);
|
|
21
|
-
}
|
|
22
|
-
remove(preset, pluginName) {
|
|
23
|
-
this.byName.delete(preset.name);
|
|
24
|
-
return super.remove(preset, pluginName);
|
|
25
|
-
}
|
|
26
|
-
get(name) {
|
|
27
|
-
return this.byName.get(name);
|
|
28
|
-
}
|
|
29
|
-
/** 清理所有预设注册(热重载时由 Plugin.stop() 调用) */
|
|
30
|
-
dispose() {
|
|
31
|
-
this.byName.clear();
|
|
32
|
-
}
|
|
33
|
-
getAll() {
|
|
34
|
-
return [...this.items];
|
|
35
|
-
}
|
|
36
|
-
search(query, options) {
|
|
37
|
-
const maxResults = options?.maxResults ?? 5;
|
|
38
|
-
const lower = query.toLowerCase();
|
|
39
|
-
const scored = this.items
|
|
40
|
-
.map(preset => ({ preset, score: this.#scorePreset(preset, lower) }))
|
|
41
|
-
.filter(({ score }) => score > 0)
|
|
42
|
-
.sort((a, b) => b.score - a.score)
|
|
43
|
-
.slice(0, maxResults);
|
|
44
|
-
return scored.map(({ preset }) => preset);
|
|
45
|
-
}
|
|
46
|
-
#scorePreset(preset, query) {
|
|
47
|
-
let score = 0;
|
|
48
|
-
if (preset.name.toLowerCase().includes(query))
|
|
49
|
-
score += 10;
|
|
50
|
-
if (preset.description.toLowerCase().includes(query))
|
|
51
|
-
score += 5;
|
|
52
|
-
for (const kw of preset.keywords || []) {
|
|
53
|
-
if (kw.toLowerCase().includes(query) || query.includes(kw.toLowerCase()))
|
|
54
|
-
score += 8;
|
|
55
|
-
}
|
|
56
|
-
for (const tag of preset.tags || []) {
|
|
57
|
-
if (tag.toLowerCase().includes(query))
|
|
58
|
-
score += 3;
|
|
59
|
-
}
|
|
60
|
-
return score;
|
|
61
|
-
}
|
|
62
|
-
toJSON(pluginName) {
|
|
63
|
-
const list = pluginName ? this.getByPlugin(pluginName) : this.items;
|
|
64
|
-
return {
|
|
65
|
-
name: this.name,
|
|
66
|
-
icon: this.icon,
|
|
67
|
-
desc: this.desc,
|
|
68
|
-
count: list.length,
|
|
69
|
-
items: list.map(p => ({
|
|
70
|
-
name: p.name,
|
|
71
|
-
desc: p.description,
|
|
72
|
-
keywords: p.keywords,
|
|
73
|
-
tags: p.tags,
|
|
74
|
-
model: p.model,
|
|
75
|
-
provider: p.provider,
|
|
76
|
-
})),
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { type AiOutboundCapabilities, type AiOutboundExtensionDefinition } from './types.js';
|
|
2
|
-
export declare function getAdapterAiOutboundCapabilities(adapterInstance: object): AiOutboundCapabilities;
|
|
3
|
-
export declare function getAdapterAiOutboundExtensions(adapterInstance: object): readonly AiOutboundExtensionDefinition[];
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { DEFAULT_AI_OUTBOUND_CAPABILITIES, } from './types.js';
|
|
2
|
-
export function getAdapterAiOutboundCapabilities(adapterInstance) {
|
|
3
|
-
const ctor = adapterInstance.constructor;
|
|
4
|
-
return ctor.aiOutboundCapabilities ?? DEFAULT_AI_OUTBOUND_CAPABILITIES;
|
|
5
|
-
}
|
|
6
|
-
export function getAdapterAiOutboundExtensions(adapterInstance) {
|
|
7
|
-
const ctor = adapterInstance.constructor;
|
|
8
|
-
return ctor.aiOutboundExtensions ?? [];
|
|
9
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 授权重算 — ConfigFeature + Message 为单一真相源($sender.isMaster/isTrusted 为 enrich 快照)
|
|
3
|
-
*/
|
|
4
|
-
import type { Plugin } from '../plugin.js';
|
|
5
|
-
import type { Message } from '../message.js';
|
|
6
|
-
import { type SenderRolesResult } from './ai-trigger.js';
|
|
7
|
-
/**
|
|
8
|
-
* 从 ConfigFeature + Message 重算发送者角色(含群角色与 master/trusted)
|
|
9
|
-
*/
|
|
10
|
-
export declare function resolveSubjectRoles(plugin: Plugin, message: Message<any>): SenderRolesResult;
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { mergeAITriggerConfig, resolveSenderRoles, } from './ai-trigger.js';
|
|
2
|
-
import { formatCompact, getLogger } from '@zhin.js/logger';
|
|
3
|
-
const logger = getLogger('Authorization');
|
|
4
|
-
function findEndpointEntryFromConfig(config, adapter, endpointKey) {
|
|
5
|
-
// 1) top-level endpoints[] (legacy / flat format)
|
|
6
|
-
const topLevel = config.endpoints;
|
|
7
|
-
if (Array.isArray(topLevel)) {
|
|
8
|
-
const found = topLevel.find((b) => b.context === adapter && String(b.id) === endpointKey);
|
|
9
|
-
if (found)
|
|
10
|
-
return found;
|
|
11
|
-
}
|
|
12
|
-
// 2) plugins.<adapter> — adapter-level master/trusted + nested endpoints[]
|
|
13
|
-
const adapterConfig = config.plugins?.[adapter];
|
|
14
|
-
if (!adapterConfig)
|
|
15
|
-
return undefined;
|
|
16
|
-
const nested = adapterConfig.endpoints;
|
|
17
|
-
const entry = Array.isArray(nested)
|
|
18
|
-
? nested.find((b) => String(b.id) === endpointKey)
|
|
19
|
-
: undefined;
|
|
20
|
-
// Merge adapter-level master/trusted onto the matched endpoint entry
|
|
21
|
-
// so that resolveSenderRoles sees them in one place
|
|
22
|
-
const merged = {
|
|
23
|
-
context: adapter,
|
|
24
|
-
...(entry ?? { id: endpointKey }),
|
|
25
|
-
};
|
|
26
|
-
if (adapterConfig.master != null && merged.master == null) {
|
|
27
|
-
merged.master = adapterConfig.master;
|
|
28
|
-
}
|
|
29
|
-
if (adapterConfig.trusted != null && merged.trusted == null) {
|
|
30
|
-
merged.trusted = adapterConfig.trusted;
|
|
31
|
-
}
|
|
32
|
-
return merged;
|
|
33
|
-
}
|
|
34
|
-
function readTriggerConfig(plugin) {
|
|
35
|
-
const root = plugin.root ?? plugin;
|
|
36
|
-
try {
|
|
37
|
-
const ai = root.inject('ai');
|
|
38
|
-
if (ai?.getTriggerConfig)
|
|
39
|
-
return ai.getTriggerConfig();
|
|
40
|
-
}
|
|
41
|
-
catch (e) {
|
|
42
|
-
logger.debug(formatCompact({ auth: 'trigger_config_fallback', reason: 'ai_not_ready' }));
|
|
43
|
-
}
|
|
44
|
-
try {
|
|
45
|
-
const configSvc = root.inject('config');
|
|
46
|
-
const primary = configSvc?.getPrimary?.();
|
|
47
|
-
return primary?.ai?.trigger ?? {};
|
|
48
|
-
}
|
|
49
|
-
catch (e) {
|
|
50
|
-
logger.debug(formatCompact({ auth: 'trigger_config_read_error' }));
|
|
51
|
-
return {};
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function readEndpointConfig(plugin, message) {
|
|
55
|
-
const root = plugin.root ?? plugin;
|
|
56
|
-
try {
|
|
57
|
-
const configSvc = root.inject('config');
|
|
58
|
-
const primary = configSvc?.getPrimary?.();
|
|
59
|
-
if (!primary)
|
|
60
|
-
return undefined;
|
|
61
|
-
const entry = findEndpointEntryFromConfig(primary, String(message.$adapter), String(message.$endpoint));
|
|
62
|
-
return entry;
|
|
63
|
-
}
|
|
64
|
-
catch (e) {
|
|
65
|
-
logger.debug(formatCompact({ auth: 'endpoint_config_read_error' }));
|
|
66
|
-
return undefined;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* 从 ConfigFeature + Message 重算发送者角色(含群角色与 master/trusted)
|
|
71
|
-
*/
|
|
72
|
-
export function resolveSubjectRoles(plugin, message) {
|
|
73
|
-
const triggerConfig = mergeAITriggerConfig(readTriggerConfig(plugin));
|
|
74
|
-
const endpointConfig = readEndpointConfig(plugin, message);
|
|
75
|
-
return resolveSenderRoles(message, triggerConfig, endpointConfig);
|
|
76
|
-
}
|
package/lib/built/command.d.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CommandFeature
|
|
3
|
-
* 管理所有插件注册的命令,继承自 Feature 抽象类
|
|
4
|
-
*/
|
|
5
|
-
import { Feature, FeatureJSON } from "@zhin.js/kernel";
|
|
6
|
-
/** 命令 pattern 的首个词(用于前缀排序) */
|
|
7
|
-
export declare function commandLeadingToken(pattern: string): string;
|
|
8
|
-
/** 命令匹配优先级:首词越长越优先;同首词则完整 pattern 越长越优先 */
|
|
9
|
-
export declare function compareCommandPatterns(a: string, b: string): number;
|
|
10
|
-
import { MessageCommand } from "../command.js";
|
|
11
|
-
import { Message } from "../message.js";
|
|
12
|
-
import type { RegisteredAdapter, AdapterMessage } from "../types.js";
|
|
13
|
-
import type { PermissionHost } from '@zhin.js/permission';
|
|
14
|
-
/**
|
|
15
|
-
* CommandContext 扩展方法类型
|
|
16
|
-
*/
|
|
17
|
-
export interface CommandContextExtensions {
|
|
18
|
-
/** @deprecated 使用 `defineCommand` + `commands/`;勿在新代码调用。 */
|
|
19
|
-
addCommand<T extends RegisteredAdapter>(command: MessageCommand<T>): () => void;
|
|
20
|
-
}
|
|
21
|
-
declare module "../plugin.js" {
|
|
22
|
-
namespace Plugin {
|
|
23
|
-
interface Extensions extends CommandContextExtensions {
|
|
24
|
-
}
|
|
25
|
-
interface Contexts {
|
|
26
|
-
command: CommandFeature;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* 命令服务 Feature(经典 MessageCommand 注册表)。
|
|
32
|
-
*
|
|
33
|
-
* @deprecated 新命令走 `@zhin.js/command` 的 `defineCommand` + 约定目录发现。
|
|
34
|
-
* 本 Feature 仍服务 Agent / game-kit / legacy Plugin.addCommand。
|
|
35
|
-
*/
|
|
36
|
-
export declare class CommandFeature extends Feature<MessageCommand<RegisteredAdapter>> {
|
|
37
|
-
readonly name: "command";
|
|
38
|
-
readonly icon = "Terminal";
|
|
39
|
-
readonly desc = "\u547D\u4EE4";
|
|
40
|
-
/** 按 pattern 索引 */
|
|
41
|
-
readonly byName: Map<string, MessageCommand<"process">>;
|
|
42
|
-
/**
|
|
43
|
-
* 添加命令
|
|
44
|
-
*/
|
|
45
|
-
add(command: MessageCommand<RegisteredAdapter>, pluginName: string): () => void;
|
|
46
|
-
/**
|
|
47
|
-
* 移除命令
|
|
48
|
-
*/
|
|
49
|
-
remove(command: MessageCommand<RegisteredAdapter>): boolean;
|
|
50
|
-
/**
|
|
51
|
-
* 按 pattern 获取命令
|
|
52
|
-
*/
|
|
53
|
-
get(pattern: string): MessageCommand<RegisteredAdapter> | undefined;
|
|
54
|
-
/**
|
|
55
|
-
* 处理消息,依次尝试匹配命令(较长前缀优先,避免 `teach` 抢 `teach-list`)
|
|
56
|
-
*/
|
|
57
|
-
handle(message: Message<AdapterMessage<RegisteredAdapter>>, host: PermissionHost | null): Promise<any>;
|
|
58
|
-
/**
|
|
59
|
-
* 生命周期: 销毁时清理所有命令
|
|
60
|
-
*/
|
|
61
|
-
dispose(): void;
|
|
62
|
-
/**
|
|
63
|
-
* 序列化为 JSON
|
|
64
|
-
*/
|
|
65
|
-
toJSON(pluginName?: string): FeatureJSON;
|
|
66
|
-
/**
|
|
67
|
-
* 提供给 Plugin.prototype 的扩展方法
|
|
68
|
-
*/
|
|
69
|
-
get extensions(): {
|
|
70
|
-
addCommand<T extends RegisteredAdapter>(command: MessageCommand<T>): () => void;
|
|
71
|
-
};
|
|
72
|
-
}
|
package/lib/built/command.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* CommandFeature
|
|
3
|
-
* 管理所有插件注册的命令,继承自 Feature 抽象类
|
|
4
|
-
*/
|
|
5
|
-
import { Feature } from "@zhin.js/kernel";
|
|
6
|
-
/** 命令 pattern 的首个词(用于前缀排序) */
|
|
7
|
-
export function commandLeadingToken(pattern) {
|
|
8
|
-
return pattern.split(/\s/)[0] ?? "";
|
|
9
|
-
}
|
|
10
|
-
/** 命令匹配优先级:首词越长越优先;同首词则完整 pattern 越长越优先 */
|
|
11
|
-
export function compareCommandPatterns(a, b) {
|
|
12
|
-
const leadDiff = commandLeadingToken(b).length - commandLeadingToken(a).length;
|
|
13
|
-
if (leadDiff !== 0)
|
|
14
|
-
return leadDiff;
|
|
15
|
-
const lenDiff = b.length - a.length;
|
|
16
|
-
if (lenDiff !== 0)
|
|
17
|
-
return lenDiff;
|
|
18
|
-
const tokA = a.trim().split(/\s+/).length;
|
|
19
|
-
const tokB = b.trim().split(/\s+/).length;
|
|
20
|
-
return tokB - tokA;
|
|
21
|
-
}
|
|
22
|
-
/**
|
|
23
|
-
* 命令服务 Feature(经典 MessageCommand 注册表)。
|
|
24
|
-
*
|
|
25
|
-
* @deprecated 新命令走 `@zhin.js/command` 的 `defineCommand` + 约定目录发现。
|
|
26
|
-
* 本 Feature 仍服务 Agent / game-kit / legacy Plugin.addCommand。
|
|
27
|
-
*/
|
|
28
|
-
export class CommandFeature extends Feature {
|
|
29
|
-
name = 'command';
|
|
30
|
-
icon = 'Terminal';
|
|
31
|
-
desc = '命令';
|
|
32
|
-
/** 按 pattern 索引 */
|
|
33
|
-
byName = new Map();
|
|
34
|
-
/**
|
|
35
|
-
* 添加命令
|
|
36
|
-
*/
|
|
37
|
-
add(command, pluginName) {
|
|
38
|
-
this.byName.set(command.pattern, command);
|
|
39
|
-
return super.add(command, pluginName);
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* 移除命令
|
|
43
|
-
*/
|
|
44
|
-
remove(command) {
|
|
45
|
-
this.byName.delete(command.pattern);
|
|
46
|
-
return super.remove(command);
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* 按 pattern 获取命令
|
|
50
|
-
*/
|
|
51
|
-
get(pattern) {
|
|
52
|
-
return this.byName.get(pattern);
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* 处理消息,依次尝试匹配命令(较长前缀优先,避免 `teach` 抢 `teach-list`)
|
|
56
|
-
*/
|
|
57
|
-
async handle(message, host) {
|
|
58
|
-
const commands = [...this.items].sort((a, b) => compareCommandPatterns(a.pattern, b.pattern));
|
|
59
|
-
for (const command of commands) {
|
|
60
|
-
const result = await command.handle(message, host);
|
|
61
|
-
if (result)
|
|
62
|
-
return result;
|
|
63
|
-
}
|
|
64
|
-
return null;
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* 生命周期: 销毁时清理所有命令
|
|
68
|
-
*/
|
|
69
|
-
dispose() {
|
|
70
|
-
this.byName.clear();
|
|
71
|
-
}
|
|
72
|
-
/**
|
|
73
|
-
* 序列化为 JSON
|
|
74
|
-
*/
|
|
75
|
-
toJSON(pluginName) {
|
|
76
|
-
const list = pluginName ? this.getByPlugin(pluginName) : this.items;
|
|
77
|
-
return {
|
|
78
|
-
name: this.name,
|
|
79
|
-
icon: this.icon,
|
|
80
|
-
desc: this.desc,
|
|
81
|
-
count: list.length,
|
|
82
|
-
items: list.map(c => ({
|
|
83
|
-
name: c.pattern,
|
|
84
|
-
desc: c.helpInfo?.desc,
|
|
85
|
-
usage: c.helpInfo?.usage,
|
|
86
|
-
examples: c.helpInfo?.examples,
|
|
87
|
-
})),
|
|
88
|
-
};
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* 提供给 Plugin.prototype 的扩展方法
|
|
92
|
-
*/
|
|
93
|
-
get extensions() {
|
|
94
|
-
const feature = this;
|
|
95
|
-
return {
|
|
96
|
-
addCommand(command) {
|
|
97
|
-
const plugin = this;
|
|
98
|
-
const dispose = feature.add(command, plugin.name);
|
|
99
|
-
plugin.recordFeatureContribution(feature.name, command.pattern);
|
|
100
|
-
plugin.onDispose(dispose);
|
|
101
|
-
return dispose;
|
|
102
|
-
},
|
|
103
|
-
};
|
|
104
|
-
}
|
|
105
|
-
}
|
package/lib/built/component.d.ts
DELETED
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ComponentFeature
|
|
3
|
-
* 管理所有插件注册的组件,继承自 Feature 抽象类
|
|
4
|
-
*/
|
|
5
|
-
import { Feature, FeatureJSON, type PluginLike } from '@zhin.js/kernel';
|
|
6
|
-
import { Component } from "../component.js";
|
|
7
|
-
/**
|
|
8
|
-
* ComponentContext 扩展方法类型
|
|
9
|
-
*/
|
|
10
|
-
export interface ComponentContextExtensions {
|
|
11
|
-
/** 添加组件 */
|
|
12
|
-
addComponent<T extends Component<any>>(component: T): () => void;
|
|
13
|
-
}
|
|
14
|
-
declare module "../plugin.js" {
|
|
15
|
-
namespace Plugin {
|
|
16
|
-
interface Extensions extends ComponentContextExtensions {
|
|
17
|
-
}
|
|
18
|
-
interface Contexts {
|
|
19
|
-
component: ComponentFeature;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* 组件服务 Feature
|
|
25
|
-
*/
|
|
26
|
-
export declare class ComponentFeature extends Feature<Component<any>> {
|
|
27
|
-
#private;
|
|
28
|
-
readonly name: "component";
|
|
29
|
-
readonly icon = "Box";
|
|
30
|
-
readonly desc = "\u7EC4\u4EF6";
|
|
31
|
-
/** 按名称索引 */
|
|
32
|
-
readonly byName: Map<string, Component<any>>;
|
|
33
|
-
/**
|
|
34
|
-
* 添加组件
|
|
35
|
-
*/
|
|
36
|
-
add(component: Component<any>, pluginName: string): () => void;
|
|
37
|
-
/**
|
|
38
|
-
* 移除组件
|
|
39
|
-
*/
|
|
40
|
-
remove(component: Component<any>): boolean;
|
|
41
|
-
/**
|
|
42
|
-
* 获取所有组件名称
|
|
43
|
-
*/
|
|
44
|
-
getAllNames(): string[];
|
|
45
|
-
/**
|
|
46
|
-
* 按名称获取组件
|
|
47
|
-
*/
|
|
48
|
-
get(name: string): Component<any> | undefined;
|
|
49
|
-
/**
|
|
50
|
-
* 生命周期: 挂载时注册消息渲染监听器
|
|
51
|
-
*/
|
|
52
|
-
mounted(plugin: PluginLike): void;
|
|
53
|
-
/**
|
|
54
|
-
* 生命周期: 销毁时移除监听器
|
|
55
|
-
*/
|
|
56
|
-
dispose(): void;
|
|
57
|
-
/**
|
|
58
|
-
* 序列化为 JSON
|
|
59
|
-
*/
|
|
60
|
-
toJSON(pluginName?: string): FeatureJSON;
|
|
61
|
-
/**
|
|
62
|
-
* 提供给 Plugin.prototype 的扩展方法
|
|
63
|
-
*/
|
|
64
|
-
get extensions(): {
|
|
65
|
-
addComponent<T extends Component<any>>(component: T): () => void;
|
|
66
|
-
};
|
|
67
|
-
}
|
package/lib/built/component.js
DELETED
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ComponentFeature
|
|
3
|
-
* 管理所有插件注册的组件,继承自 Feature 抽象类
|
|
4
|
-
*/
|
|
5
|
-
import { Feature } from '@zhin.js/kernel';
|
|
6
|
-
import { renderComponents } from "../component.js";
|
|
7
|
-
/**
|
|
8
|
-
* 组件服务 Feature
|
|
9
|
-
*/
|
|
10
|
-
export class ComponentFeature extends Feature {
|
|
11
|
-
name = 'component';
|
|
12
|
-
icon = 'Box';
|
|
13
|
-
desc = '组件';
|
|
14
|
-
/** 按名称索引 */
|
|
15
|
-
byName = new Map();
|
|
16
|
-
/** 内部状态:消息渲染监听器 & 宿主插件 */
|
|
17
|
-
#listener;
|
|
18
|
-
#rootPlugin;
|
|
19
|
-
/**
|
|
20
|
-
* 添加组件
|
|
21
|
-
*/
|
|
22
|
-
add(component, pluginName) {
|
|
23
|
-
this.byName.set(component.name, component);
|
|
24
|
-
return super.add(component, pluginName);
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* 移除组件
|
|
28
|
-
*/
|
|
29
|
-
remove(component) {
|
|
30
|
-
this.byName.delete(component.name);
|
|
31
|
-
return super.remove(component);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* 获取所有组件名称
|
|
35
|
-
*/
|
|
36
|
-
getAllNames() {
|
|
37
|
-
return Array.from(this.byName.keys());
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* 按名称获取组件
|
|
41
|
-
*/
|
|
42
|
-
get(name) {
|
|
43
|
-
return this.byName.get(name);
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* 生命周期: 挂载时注册消息渲染监听器
|
|
47
|
-
*/
|
|
48
|
-
mounted(plugin) {
|
|
49
|
-
const p = plugin;
|
|
50
|
-
this.#rootPlugin = p;
|
|
51
|
-
this.#listener = (options) => {
|
|
52
|
-
return renderComponents(this.byName, options);
|
|
53
|
-
};
|
|
54
|
-
p.root.on('before.sendMessage', this.#listener);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* 生命周期: 销毁时移除监听器
|
|
58
|
-
*/
|
|
59
|
-
dispose() {
|
|
60
|
-
if (this.#listener && this.#rootPlugin) {
|
|
61
|
-
this.#rootPlugin.root.off('before.sendMessage', this.#listener);
|
|
62
|
-
this.#listener = undefined;
|
|
63
|
-
}
|
|
64
|
-
this.byName.clear();
|
|
65
|
-
}
|
|
66
|
-
/**
|
|
67
|
-
* 序列化为 JSON
|
|
68
|
-
*/
|
|
69
|
-
toJSON(pluginName) {
|
|
70
|
-
const list = pluginName ? this.getByPlugin(pluginName) : this.items;
|
|
71
|
-
return {
|
|
72
|
-
name: this.name,
|
|
73
|
-
icon: this.icon,
|
|
74
|
-
desc: this.desc,
|
|
75
|
-
count: list.length,
|
|
76
|
-
items: list.map(c => ({
|
|
77
|
-
name: c.name,
|
|
78
|
-
type: 'component',
|
|
79
|
-
})),
|
|
80
|
-
};
|
|
81
|
-
}
|
|
82
|
-
/**
|
|
83
|
-
* 提供给 Plugin.prototype 的扩展方法
|
|
84
|
-
*/
|
|
85
|
-
get extensions() {
|
|
86
|
-
const feature = this;
|
|
87
|
-
return {
|
|
88
|
-
addComponent(component) {
|
|
89
|
-
const plugin = this;
|
|
90
|
-
const dispose = feature.add(component, plugin.name);
|
|
91
|
-
plugin.recordFeatureContribution(feature.name, component.name);
|
|
92
|
-
plugin.onDispose(dispose);
|
|
93
|
-
return dispose;
|
|
94
|
-
},
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
}
|
package/lib/built/config.d.ts
DELETED
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
import { Schema } from "@zhin.js/schema";
|
|
2
|
-
import { Feature, FeatureJSON } from "@zhin.js/kernel";
|
|
3
|
-
/** Deno / Node 统一的工作目录(`Deno.chdir` 后应与 `process.cwd()` 一致) */
|
|
4
|
-
export declare function runtimeCwd(): string;
|
|
5
|
-
export declare class ConfigLoader<T extends object> {
|
|
6
|
-
#private;
|
|
7
|
-
filename: string;
|
|
8
|
-
initial: T;
|
|
9
|
-
schema?: Schema<T> | undefined;
|
|
10
|
-
get data(): T;
|
|
11
|
-
get raw(): T;
|
|
12
|
-
get extension(): string;
|
|
13
|
-
/** `load()` / `patchKey()` 使用的绝对路径 */
|
|
14
|
-
get resolvedPath(): string;
|
|
15
|
-
constructor(filename: string, initial: T, schema?: Schema<T> | undefined);
|
|
16
|
-
resolvePath(baseDir?: string): string;
|
|
17
|
-
load(baseDir?: string): void;
|
|
18
|
-
save(fullPath?: string): void;
|
|
19
|
-
/**
|
|
20
|
-
* 精准修改单个顶层 key 并写回文件
|
|
21
|
-
* 保留注释、格式和未修改字段(如 ${VAR} 环境变量引用)
|
|
22
|
-
*/
|
|
23
|
-
patchKey(key: string, value: any): void;
|
|
24
|
-
}
|
|
25
|
-
/** 解析 endpoint 配置中的 `${ENV}` 引用(运行时 add 后热连接用) */
|
|
26
|
-
export declare function resolveEndpointConfigEnv(config: Record<string, unknown>): Record<string, unknown>;
|
|
27
|
-
export declare function mergeConfigDefaults<T>(defaults: T, overrides: unknown): T;
|
|
28
|
-
export declare namespace ConfigLoader {
|
|
29
|
-
const supportedExtensions: string[];
|
|
30
|
-
/**
|
|
31
|
-
* 自动发现配置文件(按优先级:yml > yaml > json > toml)
|
|
32
|
-
*/
|
|
33
|
-
function discover(basename: string, cwd?: string): string | null;
|
|
34
|
-
function load<T extends object>(filename: string, initial?: T, schema?: Schema<T>, baseDir?: string): ConfigLoader<T>;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* 配置项声明记录
|
|
38
|
-
*/
|
|
39
|
-
export interface ConfigRecord {
|
|
40
|
-
key: string;
|
|
41
|
-
defaultValue: any;
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* ConfigFeature 扩展方法类型
|
|
45
|
-
*/
|
|
46
|
-
export interface ConfigContextExtensions {
|
|
47
|
-
/** 声明插件配置项(key + 默认值),如果配置文件中不存在则写入默认值 */
|
|
48
|
-
addConfig(key: string, defaultValue: any): () => void;
|
|
49
|
-
}
|
|
50
|
-
declare module "../plugin.js" {
|
|
51
|
-
namespace Plugin {
|
|
52
|
-
interface Extensions extends ConfigContextExtensions {
|
|
53
|
-
}
|
|
54
|
-
interface Contexts {
|
|
55
|
-
config: ConfigFeature;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
export declare class ConfigFeature extends Feature<ConfigRecord> {
|
|
60
|
-
#private;
|
|
61
|
-
readonly name: "config";
|
|
62
|
-
readonly icon = "Settings";
|
|
63
|
-
readonly desc = "\u914D\u7F6E";
|
|
64
|
-
/** 内部配置文件管理 */
|
|
65
|
-
readonly configs: Map<string, ConfigLoader<any>>;
|
|
66
|
-
/** 获取主配置文件名 */
|
|
67
|
-
get primaryFile(): string;
|
|
68
|
-
/**
|
|
69
|
-
* 加载配置文件
|
|
70
|
-
*/
|
|
71
|
-
load<T extends object>(filename: string, initial?: Partial<T>, schema?: Schema<T>, baseDir?: string): ConfigLoader<T>;
|
|
72
|
-
/**
|
|
73
|
-
* 获取配置数据(代理模式,自动保存)
|
|
74
|
-
*/
|
|
75
|
-
get<T extends object>(filename: string, initial?: Partial<T>, schema?: Schema<T>): T;
|
|
76
|
-
/**
|
|
77
|
-
* 获取主配置文件数据(第一个加载的配置文件)
|
|
78
|
-
*/
|
|
79
|
-
getPrimary<T extends object>(): T;
|
|
80
|
-
/**
|
|
81
|
-
* 获取原始配置数据
|
|
82
|
-
*/
|
|
83
|
-
getRaw<T extends object>(filename: string, initial?: Partial<T>, schema?: Schema<T>): T;
|
|
84
|
-
/**
|
|
85
|
-
* 更新配置文件内容
|
|
86
|
-
*/
|
|
87
|
-
set<T extends object>(filename: string, data: T): void;
|
|
88
|
-
/**
|
|
89
|
-
* 序列化为 JSON
|
|
90
|
-
*/
|
|
91
|
-
toJSON(pluginName?: string): FeatureJSON;
|
|
92
|
-
/**
|
|
93
|
-
* 提供给 Plugin.prototype 的扩展方法
|
|
94
|
-
*/
|
|
95
|
-
get extensions(): {
|
|
96
|
-
addConfig(key: string, defaultValue: any): () => void;
|
|
97
|
-
};
|
|
98
|
-
}
|