@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
package/lib/command.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { SegmentMatcher } from 'segment-matcher';
|
|
2
|
-
import { toPermissionSubject } from '@zhin.js/permission';
|
|
3
|
-
/**
|
|
4
|
-
* MessageCommand类:经典命令系统(segment-matcher)。
|
|
5
|
-
*
|
|
6
|
-
* @deprecated 新插件请用 `defineCommand`(`zhin.js/command`)+ `commands/` 约定目录。
|
|
7
|
-
* 本类仍供 Agent init / game-kit hub / legacy `CommandFeature` 使用;计划随经典
|
|
8
|
-
* Plugin 路径一并退役。见 `docs/contributing/public-api-surface.md`。
|
|
9
|
-
*/
|
|
10
|
-
export class MessageCommand extends SegmentMatcher {
|
|
11
|
-
#callbacks = [];
|
|
12
|
-
#desc = [];
|
|
13
|
-
#usage = [];
|
|
14
|
-
#examples = [];
|
|
15
|
-
#permissions = [];
|
|
16
|
-
get helpInfo() {
|
|
17
|
-
return {
|
|
18
|
-
pattern: this.pattern,
|
|
19
|
-
desc: this.#desc,
|
|
20
|
-
usage: this.#usage,
|
|
21
|
-
examples: this.#examples
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
constructor(C, P = {}) {
|
|
25
|
-
super(C, {
|
|
26
|
-
at: ['qq', 'user_id'],
|
|
27
|
-
face: ['id'],
|
|
28
|
-
mention: ['qq', 'user_id'],
|
|
29
|
-
html: ['content'],
|
|
30
|
-
markdown: ['content'],
|
|
31
|
-
image: ['file', 'src', 'url'],
|
|
32
|
-
video: ['file', 'src', 'url'],
|
|
33
|
-
audio: ['file', 'src', 'url'],
|
|
34
|
-
file: ['file', 'src', 'url'],
|
|
35
|
-
reply: ['id', 'reply_id', 'message_id'],
|
|
36
|
-
quote: ['id', 'reply_id', 'message_id'],
|
|
37
|
-
forward: ['id', 'res_id', 'message_id'],
|
|
38
|
-
location: ['latitude', 'longitude'],
|
|
39
|
-
...P,
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
get help() {
|
|
43
|
-
return [
|
|
44
|
-
this.pattern,
|
|
45
|
-
...this.#desc,
|
|
46
|
-
...this.#usage,
|
|
47
|
-
...this.#examples
|
|
48
|
-
].join("\n");
|
|
49
|
-
}
|
|
50
|
-
desc(...desc) {
|
|
51
|
-
this.#desc.push(...desc);
|
|
52
|
-
return this;
|
|
53
|
-
}
|
|
54
|
-
usage(...usage) {
|
|
55
|
-
this.#usage.push(...usage);
|
|
56
|
-
return this;
|
|
57
|
-
}
|
|
58
|
-
examples(...examples) {
|
|
59
|
-
this.#examples.push(...examples);
|
|
60
|
-
return this;
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* 注册命令回调
|
|
64
|
-
* @param callback 命令处理函数
|
|
65
|
-
*/
|
|
66
|
-
action(callback) {
|
|
67
|
-
this.#callbacks.push(callback);
|
|
68
|
-
return this;
|
|
69
|
-
}
|
|
70
|
-
permit(...permissions) {
|
|
71
|
-
this.#permissions.push(...permissions);
|
|
72
|
-
return this;
|
|
73
|
-
}
|
|
74
|
-
/** 命令要求的 permit 列表(空表示所有人可用) */
|
|
75
|
-
get requiredPermits() {
|
|
76
|
-
return this.#permissions;
|
|
77
|
-
}
|
|
78
|
-
/** 与 handle 一致的 permit 校验,供帮助菜单等场景过滤不可见命令 */
|
|
79
|
-
async checkPermits(message, host) {
|
|
80
|
-
if (!this.#permissions.length)
|
|
81
|
-
return true;
|
|
82
|
-
if (!host)
|
|
83
|
-
return false;
|
|
84
|
-
const subject = toPermissionSubject(message);
|
|
85
|
-
return host.checkAll(this.#permissions, subject);
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* 处理消息,自动匹配命令并执行回调
|
|
89
|
-
* @param message 消息对象
|
|
90
|
-
* @param host PermissionHost(null 时有 permit 的命令 fail-closed)
|
|
91
|
-
* @returns 命令返回内容或undefined
|
|
92
|
-
*/
|
|
93
|
-
async handle(message, host) {
|
|
94
|
-
if (!(await this.checkPermits(message, host))) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
const matched = this.match(message.$content);
|
|
98
|
-
if (!matched)
|
|
99
|
-
return;
|
|
100
|
-
for (const handler of this.#callbacks) {
|
|
101
|
-
const result = await handler(message, matched);
|
|
102
|
-
if (result)
|
|
103
|
-
return result;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import type { Message } from './message.js';
|
|
2
|
-
import type { Notice } from './notice.js';
|
|
3
|
-
import type { Request } from './request.js';
|
|
4
|
-
import type { SendOptions } from './types.js';
|
|
5
|
-
import type { AIAccessScopeConfig } from './built/ai-access.js';
|
|
6
|
-
export type EndpointCapability = 'inbound' | 'outbound';
|
|
7
|
-
export declare const DEFAULT_ENDPOINT_CAPABILITIES: readonly EndpointCapability[];
|
|
8
|
-
/** 入站能力:含连接生命周期 */
|
|
9
|
-
export interface InboundEndpoint<Config extends object = object, Event extends object = object> {
|
|
10
|
-
$id: string;
|
|
11
|
-
$config: Config;
|
|
12
|
-
$connected: boolean;
|
|
13
|
-
$formatMessage(event: Event): Message<Event>;
|
|
14
|
-
$formatNotice?(event: unknown): Notice;
|
|
15
|
-
$formatRequest?(event: unknown): Request;
|
|
16
|
-
$connect(): Promise<void>;
|
|
17
|
-
$disconnect(): Promise<void>;
|
|
18
|
-
}
|
|
19
|
-
/** 出站能力:无连接方法 */
|
|
20
|
-
export interface OutboundEndpoint<Config extends object = object> {
|
|
21
|
-
$id: string;
|
|
22
|
-
$config: Config;
|
|
23
|
-
$connected: boolean;
|
|
24
|
-
$sendMessage(options: SendOptions): Promise<string>;
|
|
25
|
-
}
|
|
26
|
-
export type FullEndpoint<Config extends object = object, Event extends object = object> = InboundEndpoint<Config, Event> & OutboundEndpoint<Config>;
|
|
27
|
-
export type CapableEndpoint<Config extends object, Event extends object, Caps extends readonly EndpointCapability[]> = ('inbound' extends Caps[number] ? InboundEndpoint<Config, Event> : object) & ('outbound' extends Caps[number] ? OutboundEndpoint<Config> : object);
|
|
28
|
-
export declare class OutboundNotSupportedError extends Error {
|
|
29
|
-
constructor(endpointKey?: string);
|
|
30
|
-
}
|
|
31
|
-
export declare class InboundNotSupportedError extends Error {
|
|
32
|
-
constructor(endpointKey?: string);
|
|
33
|
-
}
|
|
34
|
-
export declare function registerEndpointCapabilities(endpoint: object, caps: readonly EndpointCapability[]): void;
|
|
35
|
-
export declare function getEndpointCapabilities(endpoint: object): readonly EndpointCapability[] | undefined;
|
|
36
|
-
export declare function resolveEndpointCapabilities(adapterCaps: readonly EndpointCapability[], endpointConfigCaps?: readonly EndpointCapability[]): readonly EndpointCapability[];
|
|
37
|
-
export declare function getAdapterCapabilities(adapter: object): readonly EndpointCapability[];
|
|
38
|
-
export declare function hasInbound(endpoint: object): boolean;
|
|
39
|
-
export declare function hasOutbound(endpoint: object): boolean;
|
|
40
|
-
export declare function assertInbound(endpoint: InboundEndpoint | OutboundEndpoint): asserts endpoint is InboundEndpoint;
|
|
41
|
-
export declare function assertOutbound(endpoint: InboundEndpoint | OutboundEndpoint): asserts endpoint is OutboundEndpoint;
|
|
42
|
-
export interface EndpointCapabilitiesConfig {
|
|
43
|
-
capabilities?: EndpointCapability[];
|
|
44
|
-
/** 本 Endpoint 的 AI 访问控制(覆盖 ai.access 全局默认) */
|
|
45
|
-
aiAccess?: AIAccessScopeConfig;
|
|
46
|
-
}
|
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
export const DEFAULT_ENDPOINT_CAPABILITIES = ['inbound', 'outbound'];
|
|
2
|
-
export class OutboundNotSupportedError extends Error {
|
|
3
|
-
constructor(endpointKey) {
|
|
4
|
-
super(endpointKey ? `Endpoint ${endpointKey} does not support outbound` : 'Outbound not supported');
|
|
5
|
-
this.name = 'OutboundNotSupportedError';
|
|
6
|
-
}
|
|
7
|
-
}
|
|
8
|
-
export class InboundNotSupportedError extends Error {
|
|
9
|
-
constructor(endpointKey) {
|
|
10
|
-
super(endpointKey ? `Endpoint ${endpointKey} does not support inbound` : 'Inbound not supported');
|
|
11
|
-
this.name = 'InboundNotSupportedError';
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
const endpointCapabilitiesRegistry = new WeakMap();
|
|
15
|
-
export function registerEndpointCapabilities(endpoint, caps) {
|
|
16
|
-
endpointCapabilitiesRegistry.set(endpoint, caps);
|
|
17
|
-
}
|
|
18
|
-
export function getEndpointCapabilities(endpoint) {
|
|
19
|
-
return endpointCapabilitiesRegistry.get(endpoint);
|
|
20
|
-
}
|
|
21
|
-
export function resolveEndpointCapabilities(adapterCaps, endpointConfigCaps) {
|
|
22
|
-
const resolved = endpointConfigCaps?.length ? [...endpointConfigCaps] : [...adapterCaps];
|
|
23
|
-
if (resolved.length === 0) {
|
|
24
|
-
throw new Error('Endpoint must declare at least one capability (inbound and/or outbound)');
|
|
25
|
-
}
|
|
26
|
-
for (const cap of resolved) {
|
|
27
|
-
if (!adapterCaps.includes(cap)) {
|
|
28
|
-
throw new Error(`Endpoint capability "${cap}" exceeds adapter capabilities [${adapterCaps.join(', ')}]`);
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return resolved;
|
|
32
|
-
}
|
|
33
|
-
export function getAdapterCapabilities(adapter) {
|
|
34
|
-
const ctor = adapter.constructor;
|
|
35
|
-
const caps = ctor.capabilities;
|
|
36
|
-
return caps?.length ? caps : DEFAULT_ENDPOINT_CAPABILITIES;
|
|
37
|
-
}
|
|
38
|
-
export function hasInbound(endpoint) {
|
|
39
|
-
const caps = getEndpointCapabilities(endpoint);
|
|
40
|
-
return caps ? caps.includes('inbound') : true;
|
|
41
|
-
}
|
|
42
|
-
export function hasOutbound(endpoint) {
|
|
43
|
-
const caps = getEndpointCapabilities(endpoint);
|
|
44
|
-
return caps ? caps.includes('outbound') : true;
|
|
45
|
-
}
|
|
46
|
-
export function assertInbound(endpoint) {
|
|
47
|
-
if (!hasInbound(endpoint)) {
|
|
48
|
-
throw new InboundNotSupportedError('$id' in endpoint ? String(endpoint.$id) : undefined);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
export function assertOutbound(endpoint) {
|
|
52
|
-
if (!hasOutbound(endpoint)) {
|
|
53
|
-
throw new OutboundNotSupportedError('$id' in endpoint ? String(endpoint.$id) : undefined);
|
|
54
|
-
}
|
|
55
|
-
}
|
package/lib/endpoint.d.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { Adapters, Adapter } from './adapter.js';
|
|
2
|
-
import type { EndpointCapabilitiesConfig, FullEndpoint } from './endpoint-capabilities.js';
|
|
3
|
-
import type { EndpointWithControl, EndpointWithManagement } from '@zhin.js/adapter';
|
|
4
|
-
export type { EndpointChannel, EndpointChannelParent, EndpointFriend, EndpointGroup, EndpointManagement, EndpointWithManagement, EndpointManagementCapability, } from '@zhin.js/adapter';
|
|
5
|
-
export { endpointManagementCapabilityIds, listEndpointManagementCapabilities, resolveEndpointManagement, } from '@zhin.js/adapter';
|
|
6
|
-
export type { EndpointControl, EndpointWithControl } from '@zhin.js/adapter';
|
|
7
|
-
export { endpointControlOf } from '@zhin.js/adapter';
|
|
8
|
-
export type { EndpointCapability, EndpointCapabilitiesConfig, InboundEndpoint, OutboundEndpoint, FullEndpoint, CapableEndpoint, } from './endpoint-capabilities.js';
|
|
9
|
-
export { DEFAULT_ENDPOINT_CAPABILITIES, OutboundNotSupportedError, InboundNotSupportedError, resolveEndpointCapabilities, registerEndpointCapabilities, getEndpointCapabilities, getAdapterCapabilities, hasInbound, hasOutbound, assertInbound, assertOutbound, } from './endpoint-capabilities.js';
|
|
10
|
-
/**
|
|
11
|
-
* Endpoint 接口:全双工平台机器人(入站 + 出站)。
|
|
12
|
-
* 纯入站 / 纯出站请实现 InboundEndpoint / OutboundEndpoint。
|
|
13
|
-
*/
|
|
14
|
-
export type Endpoint<Config extends object = object, Event extends object = object> = FullEndpoint<Config, Event> & EndpointWithManagement & EndpointWithControl;
|
|
15
|
-
export declare namespace Endpoint {
|
|
16
|
-
type Config<K extends keyof Adapters = keyof Adapters> = Adapter.EndpointConfig<Adapter.InferEndpoint<Adapters[K]>> & EndpointCapabilitiesConfig & {
|
|
17
|
-
context: K;
|
|
18
|
-
};
|
|
19
|
-
}
|
package/lib/endpoint.js
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
export { endpointManagementCapabilityIds, listEndpointManagementCapabilities, resolveEndpointManagement, } from '@zhin.js/adapter';
|
|
2
|
-
export { endpointControlOf } from '@zhin.js/adapter';
|
|
3
|
-
export { DEFAULT_ENDPOINT_CAPABILITIES, OutboundNotSupportedError, InboundNotSupportedError, resolveEndpointCapabilities, registerEndpointCapabilities, getEndpointCapabilities, getAdapterCapabilities, hasInbound, hasOutbound, assertInbound, assertOutbound, } from './endpoint-capabilities.js';
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @deprecated **已删除**。全局根插件注册表已移除;服务通过 Scope+Token 提供。
|
|
3
|
-
* 保留 no-op 签名供编译期过渡。
|
|
4
|
-
*/
|
|
5
|
-
/** @deprecated 已删除——不做任何事。 */
|
|
6
|
-
export declare function setHostRootPlugin(_plugin: unknown): void;
|
|
7
|
-
/** @deprecated 已删除——总是返回 null。 */
|
|
8
|
-
export declare function getHostRootPlugin(): null;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @deprecated **已删除**。全局根插件注册表已移除;服务通过 Scope+Token 提供。
|
|
3
|
-
* 保留 no-op 签名供编译期过渡。
|
|
4
|
-
*/
|
|
5
|
-
/** @deprecated 已删除——不做任何事。 */
|
|
6
|
-
export function setHostRootPlugin(_plugin) {
|
|
7
|
-
// no-op: legacy host root plugin registry has been removed
|
|
8
|
-
}
|
|
9
|
-
/** @deprecated 已删除——总是返回 null。 */
|
|
10
|
-
export function getHostRootPlugin() {
|
|
11
|
-
return null;
|
|
12
|
-
}
|
package/lib/plugin-context.d.ts
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Plugin 上下文管理 — AsyncLocalStorage + getPlugin
|
|
3
|
-
*
|
|
4
|
-
* 从 plugin.ts 提取的独立关注点,消除与 Plugin 类的循环依赖。
|
|
5
|
-
* usePlugin() 保留在 plugin.ts(需要 Plugin 构造函数)。
|
|
6
|
-
*/
|
|
7
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
8
|
-
import type { Plugin } from "./plugin.js";
|
|
9
|
-
export declare const storage: AsyncLocalStorage<Plugin>;
|
|
10
|
-
/**
|
|
11
|
-
* Plugin Runtime (`zhin runtime start`) 启动时调用。
|
|
12
|
-
* 标记后 getPlugin()/usePlugin() 在 ALS 为空时抛出更明确的迁移提示,
|
|
13
|
-
* 而非通用的 "must be called within a plugin context"。
|
|
14
|
-
*/
|
|
15
|
-
export declare function markPluginRuntimeActive(): void;
|
|
16
|
-
export declare function isPluginRuntimeActive(): boolean;
|
|
17
|
-
/** 测试重置 */
|
|
18
|
-
export declare function resetPluginRuntimeFlag(): void;
|
|
19
|
-
/**
|
|
20
|
-
* 获取当前文件路径(调用者)
|
|
21
|
-
*/
|
|
22
|
-
export declare function getCurrentFile(metaUrl?: string): string;
|
|
23
|
-
/**
|
|
24
|
-
* @deprecated **已删除**。请使用 `definePlugin` + 约定目录;运行时通过 Scope+Token 访问服务。
|
|
25
|
-
* @throws 总是抛出——仅保留签名供编译期过渡。
|
|
26
|
-
*/
|
|
27
|
-
export declare function getPlugin(): Plugin;
|
package/lib/plugin-context.js
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Plugin 上下文管理 — AsyncLocalStorage + getPlugin
|
|
3
|
-
*
|
|
4
|
-
* 从 plugin.ts 提取的独立关注点,消除与 Plugin 类的循环依赖。
|
|
5
|
-
* usePlugin() 保留在 plugin.ts(需要 Plugin 构造函数)。
|
|
6
|
-
*/
|
|
7
|
-
import { AsyncLocalStorage } from "node:async_hooks";
|
|
8
|
-
import * as path from "node:path";
|
|
9
|
-
import { fileURLToPath } from "node:url";
|
|
10
|
-
// ============================================================================
|
|
11
|
-
// AsyncLocalStorage 上下文
|
|
12
|
-
// ============================================================================
|
|
13
|
-
export const storage = new AsyncLocalStorage();
|
|
14
|
-
let _pluginRuntimeActive = false;
|
|
15
|
-
/**
|
|
16
|
-
* Plugin Runtime (`zhin runtime start`) 启动时调用。
|
|
17
|
-
* 标记后 getPlugin()/usePlugin() 在 ALS 为空时抛出更明确的迁移提示,
|
|
18
|
-
* 而非通用的 "must be called within a plugin context"。
|
|
19
|
-
*/
|
|
20
|
-
export function markPluginRuntimeActive() {
|
|
21
|
-
_pluginRuntimeActive = true;
|
|
22
|
-
}
|
|
23
|
-
export function isPluginRuntimeActive() {
|
|
24
|
-
return _pluginRuntimeActive;
|
|
25
|
-
}
|
|
26
|
-
/** 测试重置 */
|
|
27
|
-
export function resetPluginRuntimeFlag() {
|
|
28
|
-
_pluginRuntimeActive = false;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* 获取当前文件路径(调用者)
|
|
32
|
-
*/
|
|
33
|
-
export function getCurrentFile(metaUrl = import.meta.url) {
|
|
34
|
-
if (typeof metaUrl !== "string" || metaUrl.length === 0) {
|
|
35
|
-
return path.join(process.cwd(), "__zhin_edge_bootstrap__.mjs");
|
|
36
|
-
}
|
|
37
|
-
const previousPrepareStackTrace = Error.prepareStackTrace;
|
|
38
|
-
Error.prepareStackTrace = function (_, stack) {
|
|
39
|
-
return stack;
|
|
40
|
-
};
|
|
41
|
-
const stack = new Error().stack;
|
|
42
|
-
Error.prepareStackTrace = previousPrepareStackTrace;
|
|
43
|
-
const stackFiles = Array.from(new Set(stack.map((site) => site.getFileName())));
|
|
44
|
-
const idx = stackFiles.findIndex((f) => (metaUrl.startsWith('file://') ? f === fileURLToPath(metaUrl) : false) || f === metaUrl);
|
|
45
|
-
const result = stackFiles[idx + 1];
|
|
46
|
-
if (!result) {
|
|
47
|
-
return path.join(process.cwd(), "__zhin_edge_bootstrap__.mjs");
|
|
48
|
-
}
|
|
49
|
-
try {
|
|
50
|
-
return fileURLToPath(result);
|
|
51
|
-
}
|
|
52
|
-
catch {
|
|
53
|
-
return result;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* @deprecated **已删除**。请使用 `definePlugin` + 约定目录;运行时通过 Scope+Token 访问服务。
|
|
58
|
-
* @throws 总是抛出——仅保留签名供编译期过渡。
|
|
59
|
-
*/
|
|
60
|
-
export function getPlugin() {
|
|
61
|
-
throw new Error('getPlugin() has been removed. Use `definePlugin` + convention directories, '
|
|
62
|
-
+ 'and access services via Scope+Token. '
|
|
63
|
-
+ 'See docs/contributing/public-api-surface.md');
|
|
64
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import type { ConversationRef } from '@zhin.js/im-contract';
|
|
2
|
-
import type { Message } from './contracts.js';
|
|
3
|
-
/**
|
|
4
|
-
* Plugin Runtime IM 管线的 interactive action 回跳(旧轨
|
|
5
|
-
* `built/interactive-segments/handlers.ts` 的等价物):
|
|
6
|
-
* - 平台 callback 以 canonical action 段入站(telegram / discord,Wave 1 C 约定
|
|
7
|
-
* `{type:'action', data:{id, payload, sourceMessageId?}}`);
|
|
8
|
-
* - 'text' 端点的数字回跳:出站降级写入中央 fallback 存储的映射在此解析回 payload;
|
|
9
|
-
* - QQ 指令预填等直出 `prefix:session:id` 文本同样识别。
|
|
10
|
-
* payload 按 prefix 最长匹配路由给 `ImRuntime.registerInteractiveHandler`
|
|
11
|
-
* 注册的 handler。
|
|
12
|
-
*/
|
|
13
|
-
export type RuntimeInteractiveHandler = (message: Message) => Promise<boolean> | boolean;
|
|
14
|
-
export interface RegisteredRuntimeInteractiveHandler {
|
|
15
|
-
readonly prefix: string;
|
|
16
|
-
readonly handler: RuntimeInteractiveHandler;
|
|
17
|
-
}
|
|
18
|
-
/** 频道键:出站降级写入与入站回跳读取共用(由 ConversationRef 派生,稳定即可)。 */
|
|
19
|
-
export declare function runtimeInteractiveConversationKey(conversation: ConversationRef): string;
|
|
20
|
-
/** prefix 最长匹配(与旧轨 findHandler 一致)。 */
|
|
21
|
-
export declare function findRuntimeInteractiveHandler(handlers: readonly RegisteredRuntimeInteractiveHandler[], payload: string): RuntimeInteractiveHandler | undefined;
|
|
22
|
-
/**
|
|
23
|
-
* 从入站消息解析 interactive payload:
|
|
24
|
-
* action 段 → 中央 fallback map(裸数字)→ 指令预填直出 payload。
|
|
25
|
-
*/
|
|
26
|
-
export declare function resolveRuntimeInteractivePayload(message: Message): string | undefined;
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { resolvePayloadFromText } from '../../built/interactive-segments/action.js';
|
|
2
|
-
import { keyboardFallbackStore } from '../../built/interactive-segments/fallback-store.js';
|
|
3
|
-
/** 频道键:出站降级写入与入站回跳读取共用(由 ConversationRef 派生,稳定即可)。 */
|
|
4
|
-
export function runtimeInteractiveConversationKey(conversation) {
|
|
5
|
-
const base = `${String(conversation.endpoint.id)}~${conversation.kind}:${conversation.id}`;
|
|
6
|
-
const parent = conversation.parent
|
|
7
|
-
? `@${conversation.parent.kind}:${conversation.parent.id}`
|
|
8
|
-
: '';
|
|
9
|
-
const thread = conversation.threadId ? `#${conversation.threadId}` : '';
|
|
10
|
-
return `${base}${parent}${thread}`;
|
|
11
|
-
}
|
|
12
|
-
/** prefix 最长匹配(与旧轨 findHandler 一致)。 */
|
|
13
|
-
export function findRuntimeInteractiveHandler(handlers, payload) {
|
|
14
|
-
let match;
|
|
15
|
-
for (const entry of handlers) {
|
|
16
|
-
if (payload.startsWith(entry.prefix)) {
|
|
17
|
-
if (!match || entry.prefix.length > match.prefix.length) {
|
|
18
|
-
match = entry;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
return match?.handler;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* 从入站消息解析 interactive payload:
|
|
26
|
-
* action 段 → 中央 fallback map(裸数字)→ 指令预填直出 payload。
|
|
27
|
-
*/
|
|
28
|
-
export function resolveRuntimeInteractivePayload(message) {
|
|
29
|
-
const fromSegments = actionPayloadFromSegments(message.segments);
|
|
30
|
-
if (fromSegments)
|
|
31
|
-
return fromSegments;
|
|
32
|
-
const raw = message.content.trim();
|
|
33
|
-
if (!raw)
|
|
34
|
-
return undefined;
|
|
35
|
-
return resolvePayloadFromText(raw, keyboardFallbackStore.mapFor(runtimeInteractiveConversationKey(message.conversation)));
|
|
36
|
-
}
|
|
37
|
-
function actionPayloadFromSegments(segments) {
|
|
38
|
-
for (const seg of segments ?? []) {
|
|
39
|
-
if (seg.type !== 'action')
|
|
40
|
-
continue;
|
|
41
|
-
const payload = seg.data?.payload;
|
|
42
|
-
if (typeof payload === 'string' && payload)
|
|
43
|
-
return payload;
|
|
44
|
-
}
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Core service tokens — typed Token 替代 legacy string-based inject('x')。
|
|
3
|
-
*
|
|
4
|
-
* Slice 2:Token 指向当前 Feature 实例(双写窗口)。
|
|
5
|
-
* Slice 4:Feature 删除后,Token 类型改为 Runtime projection 接口。
|
|
6
|
-
*/
|
|
7
|
-
import type { CommandFeature } from '../../built/command.js';
|
|
8
|
-
import type { ComponentFeature } from '../../built/component.js';
|
|
9
|
-
import type { ScheduleFeature } from '../../built/schedule.js';
|
|
10
|
-
import type { ConfigFeature } from '../../built/config.js';
|
|
11
|
-
import type { SchemaFeature } from '../../built/schema-feature.js';
|
|
12
|
-
import type { MessageDispatcherService } from '../../built/dispatcher.js';
|
|
13
|
-
export declare const commandServiceToken: import("@zhin.js/plugin-runtime").Token<CommandFeature>;
|
|
14
|
-
export declare const componentServiceToken: import("@zhin.js/plugin-runtime").Token<ComponentFeature>;
|
|
15
|
-
export declare const schedulerServiceToken: import("@zhin.js/plugin-runtime").Token<ScheduleFeature>;
|
|
16
|
-
export declare const configServiceToken: import("@zhin.js/plugin-runtime").Token<ConfigFeature>;
|
|
17
|
-
export declare const schemaServiceToken: import("@zhin.js/plugin-runtime").Token<SchemaFeature>;
|
|
18
|
-
export declare const dispatcherServiceToken: import("@zhin.js/plugin-runtime").Token<MessageDispatcherService>;
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Core service tokens — typed Token 替代 legacy string-based inject('x')。
|
|
3
|
-
*
|
|
4
|
-
* Slice 2:Token 指向当前 Feature 实例(双写窗口)。
|
|
5
|
-
* Slice 4:Feature 删除后,Token 类型改为 Runtime projection 接口。
|
|
6
|
-
*/
|
|
7
|
-
import { createToken } from '@zhin.js/plugin-runtime';
|
|
8
|
-
export const commandServiceToken = createToken('zhin.im.command-service');
|
|
9
|
-
export const componentServiceToken = createToken('zhin.im.component-service');
|
|
10
|
-
export const schedulerServiceToken = createToken('zhin.im.scheduler-service');
|
|
11
|
-
export const configServiceToken = createToken('zhin.im.config-service');
|
|
12
|
-
export const schemaServiceToken = createToken('zhin.im.schema-service');
|
|
13
|
-
export const dispatcherServiceToken = createToken('zhin.im.dispatcher-service');
|