@zhin.js/core 1.1.35 → 1.1.38

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.
Files changed (197) hide show
  1. package/README.md +79 -193
  2. package/lib/built/ai-outbound/index.d.ts +0 -1
  3. package/lib/built/ai-outbound/index.js +0 -1
  4. package/lib/built/ai-outbound/types.d.ts +0 -9
  5. package/lib/built/ai-trigger.d.ts +0 -5
  6. package/lib/built/ai-trigger.js +1 -27
  7. package/lib/built/common-adapter-tools.d.ts +0 -2
  8. package/lib/built/common-adapter-tools.js +0 -4
  9. package/lib/built/html-segment-fallback.d.ts +2 -5
  10. package/lib/built/html-segment-fallback.js +0 -15
  11. package/lib/built/interactive-segments/index.d.ts +0 -2
  12. package/lib/built/interactive-segments/index.js +0 -2
  13. package/lib/built/interactive-segments/keyboard-segment.d.ts +0 -1
  14. package/lib/built/interactive-segments/keyboard-segment.js +0 -1
  15. package/lib/built/interactive-segments/onebot-keyboard.d.ts +0 -1
  16. package/lib/built/interactive-segments/onebot-keyboard.js +0 -2
  17. package/lib/built/interactive-segments/resolve.d.ts +0 -1
  18. package/lib/built/interactive-segments/resolve.js +0 -1
  19. package/lib/built/interactive-segments/types.d.ts +0 -5
  20. package/lib/built/login-assist.d.ts +1 -8
  21. package/lib/built/message-enrich.d.ts +2 -8
  22. package/lib/built/message-enrich.js +3 -11
  23. package/lib/built/segment-contract/assert.js +2 -1
  24. package/lib/built/segment-contract/delivery.js +1 -0
  25. package/lib/built/segment-contract/index.d.ts +2 -2
  26. package/lib/built/segment-contract/index.js +1 -1
  27. package/lib/built/segment-contract/json-schema.d.ts +1 -1
  28. package/lib/built/segment-contract/json-schema.js +33 -2
  29. package/lib/built/segment-contract/preview.js +7 -0
  30. package/lib/built/segment-contract/types.d.ts +2 -2
  31. package/lib/built/segment-contract/validate.d.ts +43 -2
  32. package/lib/built/segment-contract/validate.js +37 -3
  33. package/lib/built/tool-access.d.ts +5 -0
  34. package/lib/built/tool-access.js +17 -0
  35. package/lib/built/user-interaction.js +0 -4
  36. package/lib/feature/handler.d.ts +1 -5
  37. package/lib/index.d.ts +4 -45
  38. package/lib/index.js +3 -39
  39. package/lib/message.d.ts +1 -2
  40. package/lib/models/system-log.d.ts +0 -2
  41. package/lib/models/system-log.js +1 -8
  42. package/lib/models/user.d.ts +0 -2
  43. package/lib/models/user.js +1 -7
  44. package/lib/notice.d.ts +1 -2
  45. package/lib/plugin-runtime/im/conversation-runtime.d.ts +19 -0
  46. package/lib/plugin-runtime/im/conversation-runtime.js +312 -0
  47. package/lib/plugin-runtime/im/endpoint-runtime.d.ts +79 -0
  48. package/lib/plugin-runtime/im/endpoint-runtime.js +162 -0
  49. package/lib/plugin-runtime/im/im-runtime.d.ts +13 -106
  50. package/lib/plugin-runtime/im/im-runtime.js +58 -1061
  51. package/lib/plugin-runtime/im/inbound-runtime.d.ts +31 -0
  52. package/lib/plugin-runtime/im/inbound-runtime.js +252 -0
  53. package/lib/plugin-runtime/im/index.d.ts +4 -2
  54. package/lib/plugin-runtime/im/index.js +2 -2
  55. package/lib/plugin-runtime/im/ingress-route.d.ts +10 -0
  56. package/lib/plugin-runtime/im/ingress-route.js +10 -0
  57. package/lib/plugin-runtime/im/interaction-runtime.d.ts +23 -0
  58. package/lib/plugin-runtime/im/interaction-runtime.js +181 -0
  59. package/lib/plugin-runtime/im/interactive-router.d.ts +17 -0
  60. package/lib/plugin-runtime/im/interactive-router.js +98 -0
  61. package/lib/plugin-runtime/im/message-bus.d.ts +3 -3
  62. package/lib/plugin-runtime/im/message-bus.js +3 -3
  63. package/lib/plugin-runtime/im/message-events.d.ts +26 -0
  64. package/lib/plugin-runtime/im/message-events.js +61 -0
  65. package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +19 -0
  66. package/lib/plugin-runtime/im/outbound-delivery-runtime.js +165 -0
  67. package/lib/plugin-runtime/im/outbound-segments.d.ts +2 -3
  68. package/lib/plugin-runtime/im/outbound-segments.js +3 -4
  69. package/lib/plugin-runtime/im/runtime-middleware.d.ts +3 -0
  70. package/lib/plugin-runtime/im/runtime-middleware.js +13 -0
  71. package/lib/request.d.ts +1 -2
  72. package/lib/side-event/base.d.ts +1 -2
  73. package/lib/side-event/normalize.d.ts +1 -5
  74. package/lib/side-event/normalize.js +1 -11
  75. package/lib/system-event.d.ts +1 -2
  76. package/lib/types.d.ts +9 -116
  77. package/lib/utils.d.ts +51 -24
  78. package/lib/utils.js +11 -23
  79. package/package.json +18 -28
  80. package/lib/adapter.d.ts +0 -145
  81. package/lib/adapter.js +0 -377
  82. package/lib/built/adapter-process.d.ts +0 -58
  83. package/lib/built/adapter-process.js +0 -128
  84. package/lib/built/agent-preset.d.ts +0 -64
  85. package/lib/built/agent-preset.js +0 -79
  86. package/lib/built/ai-outbound/adapter-access.d.ts +0 -3
  87. package/lib/built/ai-outbound/adapter-access.js +0 -9
  88. package/lib/built/authorization.d.ts +0 -10
  89. package/lib/built/authorization.js +0 -76
  90. package/lib/built/command.d.ts +0 -72
  91. package/lib/built/command.js +0 -105
  92. package/lib/built/component.d.ts +0 -67
  93. package/lib/built/component.js +0 -97
  94. package/lib/built/config.d.ts +0 -98
  95. package/lib/built/config.js +0 -372
  96. package/lib/built/connect-endpoint-instance.d.ts +0 -17
  97. package/lib/built/connect-endpoint-instance.js +0 -42
  98. package/lib/built/database.d.ts +0 -68
  99. package/lib/built/database.js +0 -106
  100. package/lib/built/dispatcher.d.ts +0 -141
  101. package/lib/built/dispatcher.js +0 -383
  102. package/lib/built/endpoint-commands.d.ts +0 -3
  103. package/lib/built/endpoint-commands.js +0 -99
  104. package/lib/built/endpoint-lifecycle-service.d.ts +0 -28
  105. package/lib/built/endpoint-lifecycle-service.js +0 -242
  106. package/lib/built/endpoint-lifecycle.d.ts +0 -27
  107. package/lib/built/endpoint-lifecycle.js +0 -36
  108. package/lib/built/endpoint-manager.d.ts +0 -34
  109. package/lib/built/endpoint-manager.js +0 -1
  110. package/lib/built/html-renderer-loader.d.ts +0 -13
  111. package/lib/built/html-renderer-loader.js +0 -33
  112. package/lib/built/inbound-pipeline.d.ts +0 -37
  113. package/lib/built/inbound-pipeline.js +0 -63
  114. package/lib/built/inbound-runner.d.ts +0 -22
  115. package/lib/built/inbound-runner.js +0 -34
  116. package/lib/built/interactive-segment-contract.d.ts +0 -6
  117. package/lib/built/interactive-segment-contract.js +0 -9
  118. package/lib/built/interactive-segments/fallback-store.d.ts +0 -29
  119. package/lib/built/interactive-segments/fallback-store.js +0 -63
  120. package/lib/built/interactive-segments/handlers.d.ts +0 -16
  121. package/lib/built/interactive-segments/handlers.js +0 -74
  122. package/lib/built/introspection-format.d.ts +0 -10
  123. package/lib/built/introspection-format.js +0 -28
  124. package/lib/built/management-command-guard.d.ts +0 -15
  125. package/lib/built/management-command-guard.js +0 -25
  126. package/lib/built/message-filter.d.ts +0 -176
  127. package/lib/built/message-filter.js +0 -239
  128. package/lib/built/optional-peer-import.d.ts +0 -3
  129. package/lib/built/optional-peer-import.js +0 -33
  130. package/lib/built/outbound-media-contract.d.ts +0 -22
  131. package/lib/built/outbound-media-contract.js +0 -10
  132. package/lib/built/permission.d.ts +0 -51
  133. package/lib/built/permission.js +0 -99
  134. package/lib/built/permit-check.d.ts +0 -7
  135. package/lib/built/permit-check.js +0 -35
  136. package/lib/built/permit-parse.d.ts +0 -16
  137. package/lib/built/permit-parse.js +0 -32
  138. package/lib/built/platform-permit.d.ts +0 -20
  139. package/lib/built/platform-permit.js +0 -91
  140. package/lib/built/rich-segments/adapter-policies.d.ts +0 -9
  141. package/lib/built/rich-segments/adapter-policies.js +0 -27
  142. package/lib/built/rich-segments/base.d.ts +0 -11
  143. package/lib/built/rich-segments/base.js +0 -24
  144. package/lib/built/rich-segments/builtins.d.ts +0 -4
  145. package/lib/built/rich-segments/builtins.js +0 -40
  146. package/lib/built/rich-segments/capabilities.d.ts +0 -6
  147. package/lib/built/rich-segments/capabilities.js +0 -38
  148. package/lib/built/rich-segments/html-segment.d.ts +0 -15
  149. package/lib/built/rich-segments/html-segment.js +0 -62
  150. package/lib/built/rich-segments/index.d.ts +0 -13
  151. package/lib/built/rich-segments/index.js +0 -13
  152. package/lib/built/rich-segments/markdown-segment.d.ts +0 -14
  153. package/lib/built/rich-segments/markdown-segment.js +0 -58
  154. package/lib/built/rich-segments/qrcode-segment.d.ts +0 -18
  155. package/lib/built/rich-segments/qrcode-segment.js +0 -73
  156. package/lib/built/rich-segments/registry.d.ts +0 -16
  157. package/lib/built/rich-segments/registry.js +0 -52
  158. package/lib/built/rich-segments/resolve.d.ts +0 -5
  159. package/lib/built/rich-segments/resolve.js +0 -87
  160. package/lib/built/rich-segments/tts-segment.d.ts +0 -13
  161. package/lib/built/rich-segments/tts-segment.js +0 -51
  162. package/lib/built/rich-segments/types.d.ts +0 -79
  163. package/lib/built/rich-segments/types.js +0 -17
  164. package/lib/built/runtime-io.d.ts +0 -9
  165. package/lib/built/runtime-io.js +0 -67
  166. package/lib/built/schedule.d.ts +0 -54
  167. package/lib/built/schedule.js +0 -112
  168. package/lib/built/schema-endpoint-manager.d.ts +0 -17
  169. package/lib/built/schema-endpoint-manager.js +0 -73
  170. package/lib/built/schema-feature.d.ts +0 -77
  171. package/lib/built/schema-feature.js +0 -130
  172. package/lib/built/skill.d.ts +0 -120
  173. package/lib/built/skill.js +0 -151
  174. package/lib/built/speech-loader.d.ts +0 -14
  175. package/lib/built/speech-loader.js +0 -32
  176. package/lib/built/tool.d.ts +0 -151
  177. package/lib/built/tool.js +0 -388
  178. package/lib/command.d.ts +0 -50
  179. package/lib/command.js +0 -106
  180. package/lib/endpoint-capabilities.d.ts +0 -46
  181. package/lib/endpoint-capabilities.js +0 -55
  182. package/lib/endpoint.d.ts +0 -19
  183. package/lib/endpoint.js +0 -3
  184. package/lib/host-plugin-registry.d.ts +0 -8
  185. package/lib/host-plugin-registry.js +0 -12
  186. package/lib/plugin-context.d.ts +0 -27
  187. package/lib/plugin-context.js +0 -64
  188. package/lib/plugin-runtime/im/interactive.d.ts +0 -26
  189. package/lib/plugin-runtime/im/interactive.js +0 -46
  190. package/lib/plugin-runtime/im/service-tokens.d.ts +0 -18
  191. package/lib/plugin-runtime/im/service-tokens.js +0 -13
  192. package/lib/plugin.d.ts +0 -268
  193. package/lib/plugin.js +0 -583
  194. package/lib/schema-interaction.d.ts +0 -117
  195. package/lib/schema-interaction.js +0 -247
  196. package/lib/tool-zod.d.ts +0 -43
  197. package/lib/tool-zod.js +0 -184
@@ -1,112 +0,0 @@
1
- /**
2
- * ScheduleFeature — 管理插件注册的内存定时任务
3
- */
4
- import { Feature, ScheduleEngine, getScheduleEngine, setScheduleEngine } from '@zhin.js/kernel';
5
- function ensureEngine() {
6
- let engine = getScheduleEngine();
7
- if (!engine) {
8
- engine = new ScheduleEngine();
9
- setScheduleEngine(engine);
10
- }
11
- return engine;
12
- }
13
- export class ScheduleFeature extends Feature {
14
- name = 'schedule';
15
- icon = 'Clock';
16
- desc = '日历调度';
17
- byName = new Map();
18
- add(handle, pluginName) {
19
- this.byName.set(handle.id, handle);
20
- return super.add(handle, pluginName);
21
- }
22
- remove(handle) {
23
- if (!this.byName.has(handle.id) && !this.items.includes(handle)) {
24
- return false;
25
- }
26
- this.byName.delete(handle.id);
27
- const removed = super.remove(handle);
28
- if (removed) {
29
- handle.dispose();
30
- }
31
- return removed;
32
- }
33
- get(id) {
34
- return this.byName.get(id);
35
- }
36
- stopAll() {
37
- for (const handle of this.items) {
38
- handle.dispose();
39
- }
40
- }
41
- getStatus() {
42
- const engine = getScheduleEngine();
43
- const engineStatus = engine?.getStatus() ?? [];
44
- const byId = new Map(engineStatus.map((s) => [s.id, s]));
45
- return this.items.map((handle) => {
46
- let pluginName = 'unknown';
47
- for (const [name, items] of this.pluginItems) {
48
- if (items.includes(handle)) {
49
- pluginName = name;
50
- break;
51
- }
52
- }
53
- const st = byId.get(handle.id);
54
- return {
55
- id: handle.id,
56
- kind: handle.descriptor.kind,
57
- expression: handle.descriptor.cron,
58
- running: st?.running ?? true,
59
- nextExecution: st?.nextExecution ?? null,
60
- plugin: pluginName,
61
- };
62
- });
63
- }
64
- dispose() {
65
- this.stopAll();
66
- }
67
- toJSON(pluginName) {
68
- const list = pluginName ? this.getByPlugin(pluginName) : this.items;
69
- return {
70
- name: this.name,
71
- icon: this.icon,
72
- desc: this.desc,
73
- count: list.length,
74
- items: list.map((h) => ({
75
- id: h.id,
76
- kind: h.descriptor.kind,
77
- cron: h.descriptor.cron,
78
- })),
79
- };
80
- }
81
- get extensions() {
82
- const feature = this;
83
- return {
84
- addSchedule(descriptor, callback, id) {
85
- const plugin = this;
86
- const jobId = id ?? `sched_${Math.random().toString(36).slice(2, 10)}`;
87
- const engine = ensureEngine();
88
- const disposeEngine = engine.register(jobId, descriptor.kind, async () => {
89
- await callback();
90
- }, {
91
- cron: descriptor.cron,
92
- everyMs: descriptor.everyMs,
93
- atMs: descriptor.atMs,
94
- scatterInput: descriptor.scatterInput,
95
- holidayInput: descriptor.holidayInput,
96
- tz: descriptor.tz,
97
- });
98
- const handle = {
99
- id: jobId,
100
- descriptor,
101
- dispose: () => {
102
- disposeEngine();
103
- },
104
- };
105
- const dispose = feature.add(handle, plugin.name);
106
- plugin.recordFeatureContribution(feature.name, jobId);
107
- plugin.onDispose(dispose);
108
- return dispose;
109
- },
110
- };
111
- }
112
- }
@@ -1,17 +0,0 @@
1
- import type { Schema } from '@zhin.js/schema';
2
- import { Adapter } from '../adapter.js';
3
- import type { EndpointConfigRecord, EndpointManager, ProvisionContext } from './endpoint-manager.js';
4
- export declare class SchemaEndpointManager implements EndpointManager {
5
- private readonly adapter;
6
- private readonly schema;
7
- constructor(adapter: Adapter, schema: Schema);
8
- supportsProvision(): boolean;
9
- listEndpoints(): EndpointConfigRecord[];
10
- addEndpoint(ctx: ProvisionContext): Promise<EndpointConfigRecord>;
11
- editEndpoint(name: string, ctx: ProvisionContext): Promise<EndpointConfigRecord>;
12
- removeEndpoint(name: string): Promise<boolean>;
13
- startEndpoint(name: string, ctx: ProvisionContext): Promise<void>;
14
- stopEndpoint(name: string): Promise<boolean>;
15
- }
16
- export declare function resolveEndpointManager(adapter: Adapter): EndpointManager | null;
17
- export declare function adapterSupportsProvision(adapter: Adapter): boolean;
@@ -1,73 +0,0 @@
1
- import { SchemaInteraction } from '../schema-interaction.js';
2
- function readConfigEndpoints(root, context) {
3
- const configService = root.inject('config');
4
- const raw = configService?.getRaw(configService.primaryFile);
5
- return (raw?.endpoints ?? []).filter((e) => e.context === context);
6
- }
7
- export class SchemaEndpointManager {
8
- adapter;
9
- schema;
10
- constructor(adapter, schema) {
11
- this.adapter = adapter;
12
- this.schema = schema;
13
- }
14
- supportsProvision() {
15
- return true;
16
- }
17
- listEndpoints() {
18
- return readConfigEndpoints(this.adapter.plugin.root, String(this.adapter.name));
19
- }
20
- async addEndpoint(ctx) {
21
- const interaction = new SchemaInteraction(this.adapter.plugin, ctx.message);
22
- await ctx.onStatusUpdate(`请按提示填写 ${String(this.adapter.name)} endpoint 配置:`);
23
- const name = await interaction.text('Endpoint id(zhin.config endpoints[].id):');
24
- const fields = await interaction.getValueWithSchema(this.schema);
25
- return {
26
- context: String(this.adapter.name),
27
- id: name.trim(),
28
- ...fields,
29
- };
30
- }
31
- async editEndpoint(name, ctx) {
32
- const existing = this.listEndpoints().find((e) => e.id === name);
33
- if (!existing) {
34
- throw new Error(`配置中不存在 ${String(this.adapter.name)}/${name}`);
35
- }
36
- await ctx.onStatusUpdate(`编辑 ${String(this.adapter.name)}/${name},留空字段将保留原值。`);
37
- const interaction = new SchemaInteraction(this.adapter.plugin, ctx.message);
38
- const fields = await interaction.getValueWithSchema(this.schema);
39
- return {
40
- ...existing,
41
- ...fields,
42
- context: String(this.adapter.name),
43
- id: name,
44
- };
45
- }
46
- async removeEndpoint(name) {
47
- return this.listEndpoints().some((e) => e.id === name);
48
- }
49
- async startEndpoint(name, ctx) {
50
- const rec = this.listEndpoints().find((e) => e.id === name);
51
- if (!rec)
52
- throw new Error(`配置中不存在 ${String(this.adapter.name)}/${name}`);
53
- await ctx.onStatusUpdate(`正在连接 ${String(this.adapter.name)}/${name}…`);
54
- }
55
- async stopEndpoint(name) {
56
- return this.adapter.endpoints.has(name);
57
- }
58
- }
59
- export function resolveEndpointManager(adapter) {
60
- const custom = adapter.getEndpointManager?.();
61
- if (custom)
62
- return custom;
63
- const schema = adapter.getEndpointConfigSchema?.() ??
64
- adapter.constructor.endpointConfigSchema;
65
- if (schema) {
66
- return new SchemaEndpointManager(adapter, schema);
67
- }
68
- return null;
69
- }
70
- export function adapterSupportsProvision(adapter) {
71
- const manager = resolveEndpointManager(adapter);
72
- return manager?.supportsProvision() ?? false;
73
- }
@@ -1,77 +0,0 @@
1
- /**
2
- * SchemaFeature — 插件配置 Schema 注册表
3
- *
4
- * 插件通过 declareConfig(key, schema) 声明配置项及其 Schema,
5
- * SchemaFeature 全局收集后供 Web 控制台渲染配置编辑表单。
6
- *
7
- * 与 ConfigFeature 协作:
8
- * - declareConfig 内部调用 addConfig(key, defaults) 写入默认值
9
- * - Schema.toJSON() 传给前端驱动 PluginConfigForm
10
- * - reloadable 标记决定保存后是否自动重载插件
11
- */
12
- import { Schema } from '@zhin.js/schema';
13
- import { Feature, FeatureJSON } from '@zhin.js/kernel';
14
- export interface SchemaRecord {
15
- /** 配置 key(对应 zhin.config.yml 中的顶级字段) */
16
- key: string;
17
- /** Schema 实例 */
18
- schema: Schema;
19
- /** 保存后是否支持热重载(http/database 等底层服务应为 false) */
20
- reloadable: boolean;
21
- }
22
- export interface SchemaContextExtensions {
23
- /**
24
- * 声明插件配置 Schema
25
- * @param key 配置 key,如 "rss"
26
- * @param schema Schema.object({...}) 定义
27
- * @param options.reloadable 保存后是否自动重载,默认 true
28
- * @returns 当前配置值(已合并默认值)
29
- */
30
- declareConfig<T extends Record<string, any>>(key: string, schema: Schema<T>, options?: {
31
- reloadable?: boolean;
32
- }): Required<T>;
33
- }
34
- declare module '../plugin.js' {
35
- namespace Plugin {
36
- interface Extensions extends SchemaContextExtensions {
37
- }
38
- interface Contexts {
39
- schema: SchemaFeature;
40
- }
41
- }
42
- }
43
- export declare class SchemaFeature extends Feature<SchemaRecord> {
44
- readonly name: "schema";
45
- readonly icon = "FileCode";
46
- readonly desc = "\u914D\u7F6E\u6A21\u578B";
47
- /**
48
- * 按配置 key 查找 Schema
49
- */
50
- getByKey(key: string): SchemaRecord | null;
51
- /**
52
- * 获取指定插件名注册的 Schema
53
- */
54
- getByPluginName(pluginName: string): SchemaRecord | null;
55
- /**
56
- * 获取某个 key 的 Schema 实例(WebSocket handler 使用)
57
- */
58
- get(keyOrPlugin: string): Schema | null;
59
- /**
60
- * 判断某个 key 对应的插件是否支持热重载
61
- */
62
- isReloadable(keyOrPlugin: string): boolean;
63
- /**
64
- * 通过 pluginName 获取对应的 config key
65
- */
66
- resolveConfigKey(pluginName: string): string | null;
67
- /**
68
- * 返回 pluginName → configKey 的映射
69
- */
70
- getPluginKeyMap(): Map<string, string>;
71
- toJSON(pluginName?: string): FeatureJSON;
72
- get extensions(): {
73
- declareConfig<T extends Record<string, any>>(key: string, schema: Schema<T>, options?: {
74
- reloadable?: boolean;
75
- }): Required<T>;
76
- };
77
- }
@@ -1,130 +0,0 @@
1
- /**
2
- * SchemaFeature — 插件配置 Schema 注册表
3
- *
4
- * 插件通过 declareConfig(key, schema) 声明配置项及其 Schema,
5
- * SchemaFeature 全局收集后供 Web 控制台渲染配置编辑表单。
6
- *
7
- * 与 ConfigFeature 协作:
8
- * - declareConfig 内部调用 addConfig(key, defaults) 写入默认值
9
- * - Schema.toJSON() 传给前端驱动 PluginConfigForm
10
- * - reloadable 标记决定保存后是否自动重载插件
11
- */
12
- import { Feature } from '@zhin.js/kernel';
13
- // ============================================================================
14
- // SchemaFeature
15
- // ============================================================================
16
- export class SchemaFeature extends Feature {
17
- name = 'schema';
18
- icon = 'FileCode';
19
- desc = '配置模型';
20
- /**
21
- * 按配置 key 查找 Schema
22
- */
23
- getByKey(key) {
24
- return this.items.find(r => r.key === key) ?? null;
25
- }
26
- /**
27
- * 获取指定插件名注册的 Schema
28
- */
29
- getByPluginName(pluginName) {
30
- const list = this.getByPlugin(pluginName);
31
- return list.length > 0 ? list[0] : null;
32
- }
33
- /**
34
- * 获取某个 key 的 Schema 实例(WebSocket handler 使用)
35
- */
36
- get(keyOrPlugin) {
37
- const byKey = this.getByKey(keyOrPlugin);
38
- if (byKey)
39
- return byKey.schema;
40
- const byPlugin = this.getByPluginName(keyOrPlugin);
41
- return byPlugin?.schema ?? null;
42
- }
43
- /**
44
- * 判断某个 key 对应的插件是否支持热重载
45
- */
46
- isReloadable(keyOrPlugin) {
47
- const byKey = this.getByKey(keyOrPlugin);
48
- if (byKey)
49
- return byKey.reloadable;
50
- const byPlugin = this.getByPluginName(keyOrPlugin);
51
- return byPlugin?.reloadable ?? true;
52
- }
53
- /**
54
- * 通过 pluginName 获取对应的 config key
55
- */
56
- resolveConfigKey(pluginName) {
57
- const byKey = this.getByKey(pluginName);
58
- if (byKey)
59
- return byKey.key;
60
- const byPlugin = this.getByPluginName(pluginName);
61
- return byPlugin?.key ?? null;
62
- }
63
- /**
64
- * 返回 pluginName → configKey 的映射
65
- */
66
- getPluginKeyMap() {
67
- const map = new Map();
68
- for (const [pluginName, records] of this.pluginItems) {
69
- if (records.length > 0) {
70
- map.set(pluginName, records[0].key);
71
- }
72
- }
73
- return map;
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(r => ({
83
- name: r.key,
84
- reloadable: r.reloadable,
85
- schema: r.schema.toJSON(),
86
- })),
87
- };
88
- }
89
- get extensions() {
90
- const feature = this;
91
- return {
92
- declareConfig(key, schema, options) {
93
- const plugin = this;
94
- const reloadable = options?.reloadable ?? true;
95
- // 从 Schema 提取默认值
96
- const defaults = extractDefaults(schema);
97
- // 注册到 ConfigFeature(写入 config.yml 的默认值)
98
- if (typeof plugin.addConfig === 'function') {
99
- plugin.addConfig(key, defaults);
100
- }
101
- // 注册到 SchemaFeature
102
- const record = { key, schema, reloadable };
103
- const dispose = feature.add(record, plugin.name);
104
- plugin.recordFeatureContribution(feature.name, key);
105
- plugin.onDispose(dispose);
106
- // 读取当前配置并与默认值合并
107
- const root = plugin.root ?? plugin;
108
- const configService = root.inject('config');
109
- const appConfig = configService?.getPrimary?.() ?? {};
110
- const current = appConfig[key] ?? {};
111
- return { ...defaults, ...current };
112
- },
113
- };
114
- }
115
- }
116
- // ============================================================================
117
- // 辅助:从 Schema 提取默认值
118
- // ============================================================================
119
- function extractDefaults(schema) {
120
- const json = schema.toJSON();
121
- const result = {};
122
- const fields = json.object || json.properties || json.dict || {};
123
- for (const [fieldKey, fieldSchema] of Object.entries(fields)) {
124
- const field = fieldSchema;
125
- if (field.default !== undefined) {
126
- result[fieldKey] = field.default;
127
- }
128
- }
129
- return result;
130
- }
@@ -1,120 +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, FeatureJSON } from '@zhin.js/kernel';
15
- import type { Tool } from '../types.js';
16
- /**
17
- * Skill — AI 可见的能力描述
18
- */
19
- export interface Skill {
20
- /** 技能名称(通常与插件名一致) */
21
- name: string;
22
- /** 技能描述(AI 用来理解这个 Skill 的用途) */
23
- description: string;
24
- /** 该 Skill 提供的工具列表 */
25
- tools: Tool[];
26
- /**
27
- * 支持的平台列表
28
- * 例如:['icqq', 'discord']
29
- * 不填则为通用 Skill(所有平台可用)
30
- */
31
- platforms?: string[];
32
- /**
33
- * 触发关键词
34
- * 当用户消息包含这些关键词时,优先选择此 Skill
35
- */
36
- keywords?: string[];
37
- /**
38
- * 分类标签
39
- * 用于按领域分组(如 'news', 'weather', 'entertainment')
40
- */
41
- tags?: string[];
42
- /** 来源插件名 */
43
- pluginName: string;
44
- /**
45
- * SKILL.md 文件的绝对路径
46
- * 存在时 activate_skill 可按需加载完整指令内容
47
- */
48
- filePath?: string;
49
- /**
50
- * 是否常驻注入 system prompt
51
- * 仅在 filePath 存在时有效
52
- */
53
- always?: boolean;
54
- }
55
- /**
56
- * SKILL.md frontmatter 常见字段(类型提示;运行时由 Agent 等同步到 SkillFeature)
57
- */
58
- export interface SkillMetadata {
59
- /** 技能描述(必填) */
60
- description: string;
61
- /** 触发关键词(可选) */
62
- keywords?: string[];
63
- /** 分类标签(可选) */
64
- tags?: string[];
65
- }
66
- declare module '../plugin.js' {
67
- namespace Plugin {
68
- interface Contexts {
69
- skill: SkillFeature;
70
- }
71
- }
72
- }
73
- export declare class SkillFeature extends Feature<Skill> {
74
- #private;
75
- readonly name: "skill";
76
- readonly icon = "Brain";
77
- readonly desc = "\u6280\u80FD";
78
- /** 按名称索引 */
79
- readonly byName: Map<string, Skill>;
80
- /**
81
- * 添加 Skill
82
- */
83
- add(skill: Skill, pluginName: string): () => void;
84
- /**
85
- * 移除 Skill
86
- */
87
- remove(skill: Skill): boolean;
88
- /**
89
- * 按名称获取 Skill
90
- */
91
- get(name: string): Skill | undefined;
92
- /**
93
- * 清理所有 Skill 注册(热重载时由 Plugin.stop() 调用)
94
- */
95
- dispose(): void;
96
- /**
97
- * 获取所有已注册 Skill
98
- */
99
- getAll(): Skill[];
100
- /**
101
- * 按关键词/标签搜索相关 Skill
102
- * 返回按相关性排序的 Skill 列表
103
- */
104
- search(query: string, options?: {
105
- maxResults?: number;
106
- platform?: string;
107
- }): Skill[];
108
- /**
109
- * 获取所有 Skill 的工具(扁平化)
110
- */
111
- collectAllTools(): Tool[];
112
- /**
113
- * 已注册 Skill 数量
114
- */
115
- get size(): number;
116
- /**
117
- * 序列化为 JSON
118
- */
119
- toJSON(pluginName?: string): FeatureJSON;
120
- }
@@ -1,151 +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
- }
@@ -1,14 +0,0 @@
1
- import type { SpeechPipelineForRichSegment } from './rich-segments/types.js';
2
- /** 动态 import 时使用的包名(与 @zhin.js/speech package.json 一致) */
3
- export declare const SPEECH_PACKAGE = "@zhin.js/speech";
4
- export interface LoadSpeechPipelineOptions {
5
- getConfig?: () => Record<string, unknown> | undefined;
6
- warn?: (message: string) => void;
7
- }
8
- /** zhin 启动时已创建 pipeline 时注入 */
9
- export declare function seedSpeechPipeline(pipeline: SpeechPipelineForRichSegment): void;
10
- /** 动态加载 @zhin.js/speech;未安装时 warn 一次并返回 undefined */
11
- export declare function loadSpeechPipeline(opts?: LoadSpeechPipelineOptions): Promise<SpeechPipelineForRichSegment | undefined>;
12
- /** 测试用:重置加载缓存 */
13
- export declare function resetSpeechLoaderForTests(): void;
14
- export type { SpeechPipelineForRichSegment };