@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.
- 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/assert.js +2 -1
- package/lib/built/segment-contract/delivery.js +1 -0
- package/lib/built/segment-contract/index.d.ts +2 -2
- package/lib/built/segment-contract/index.js +1 -1
- package/lib/built/segment-contract/json-schema.d.ts +1 -1
- package/lib/built/segment-contract/json-schema.js +33 -2
- package/lib/built/segment-contract/preview.js +7 -0
- package/lib/built/segment-contract/types.d.ts +2 -2
- package/lib/built/segment-contract/validate.d.ts +43 -2
- package/lib/built/segment-contract/validate.js +37 -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,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PermissionFeature
|
|
3
|
-
* 权限管理服务,继承自 Feature 抽象类
|
|
4
|
-
*/
|
|
5
|
-
import { Feature, FeatureJSON } from "@zhin.js/kernel";
|
|
6
|
-
import type { MaybePromise, RegisteredAdapter, AdapterMessage } from "../types.js";
|
|
7
|
-
import { Message as MessageClass } from "../message.js";
|
|
8
|
-
export type PermissionSubject = MessageClass<AdapterMessage<RegisteredAdapter>>;
|
|
9
|
-
export type PermissionItem<T extends RegisteredAdapter = RegisteredAdapter> = {
|
|
10
|
-
name: string | RegExp;
|
|
11
|
-
check: PermissionChecker<T>;
|
|
12
|
-
};
|
|
13
|
-
export type PermissionChecker<T extends RegisteredAdapter = RegisteredAdapter> = (name: string, message: MessageClass<AdapterMessage<T>>) => MaybePromise<boolean>;
|
|
14
|
-
/**
|
|
15
|
-
* PermissionFeature 扩展方法类型
|
|
16
|
-
*/
|
|
17
|
-
export interface PermissionContextExtensions {
|
|
18
|
-
addPermission(permission: PermissionItem): () => void;
|
|
19
|
-
}
|
|
20
|
-
declare module "../plugin.js" {
|
|
21
|
-
namespace Plugin {
|
|
22
|
-
interface Extensions extends PermissionContextExtensions {
|
|
23
|
-
}
|
|
24
|
-
interface Contexts {
|
|
25
|
-
permission: PermissionFeature;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
export declare class PermissionFeature extends Feature<PermissionItem> {
|
|
30
|
-
readonly name: "permission";
|
|
31
|
-
readonly icon = "Shield";
|
|
32
|
-
readonly desc = "\u6743\u9650";
|
|
33
|
-
constructor();
|
|
34
|
-
/**
|
|
35
|
-
* 检查权限(subject 为 Message 通讯上下文)
|
|
36
|
-
*/
|
|
37
|
-
check(name: string, subject: PermissionSubject): Promise<boolean>;
|
|
38
|
-
/**
|
|
39
|
-
* 序列化为 JSON
|
|
40
|
-
*/
|
|
41
|
-
toJSON(pluginName?: string): FeatureJSON;
|
|
42
|
-
/**
|
|
43
|
-
* 提供给 Plugin.prototype 的扩展方法
|
|
44
|
-
*/
|
|
45
|
-
get extensions(): {
|
|
46
|
-
addPermission(permission: PermissionItem): () => void;
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
export declare namespace Permissions {
|
|
50
|
-
function define<T extends RegisteredAdapter = RegisteredAdapter>(name: string | RegExp, check: PermissionChecker<T>): PermissionItem<T>;
|
|
51
|
-
}
|
package/lib/built/permission.js
DELETED
|
@@ -1,99 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* PermissionFeature
|
|
3
|
-
* 权限管理服务,继承自 Feature 抽象类
|
|
4
|
-
*/
|
|
5
|
-
import { Feature } from "@zhin.js/kernel";
|
|
6
|
-
import logger, { formatCompact } from "@zhin.js/logger";
|
|
7
|
-
import { isBuiltinPermit, parsePermitName } from "./permit-parse.js";
|
|
8
|
-
import { checkBuiltinPermit } from "./permit-check.js";
|
|
9
|
-
import { senderRolesFromMessage } from "./message-enrich.js";
|
|
10
|
-
function rolesForPermitCheck(message) {
|
|
11
|
-
return senderRolesFromMessage(message);
|
|
12
|
-
}
|
|
13
|
-
function auditPermitDenied(permit, message, reason) {
|
|
14
|
-
logger.debug(formatCompact({
|
|
15
|
-
op: 'permit_denied',
|
|
16
|
-
permit,
|
|
17
|
-
reason,
|
|
18
|
-
senderId: message.$sender.id,
|
|
19
|
-
adapter: message.$adapter,
|
|
20
|
-
endpoint: message.$endpoint,
|
|
21
|
-
}));
|
|
22
|
-
}
|
|
23
|
-
export class PermissionFeature extends Feature {
|
|
24
|
-
name = 'permission';
|
|
25
|
-
icon = 'Shield';
|
|
26
|
-
desc = '权限';
|
|
27
|
-
constructor() {
|
|
28
|
-
super();
|
|
29
|
-
const builtinRe = /^(adapter|group|private|channel|user|role)\([^)]*\)$/;
|
|
30
|
-
this.add(Permissions.define(builtinRe, (name, message) => {
|
|
31
|
-
const parsed = parsePermitName(name);
|
|
32
|
-
if (parsed && parsed.kind !== 'role') {
|
|
33
|
-
return checkBuiltinPermit(name, message, ['user']);
|
|
34
|
-
}
|
|
35
|
-
return checkBuiltinPermit(name, message, rolesForPermitCheck(message));
|
|
36
|
-
}), '__built-in__');
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* 检查权限(subject 为 Message 通讯上下文)
|
|
40
|
-
*/
|
|
41
|
-
async check(name, subject) {
|
|
42
|
-
const message = subject;
|
|
43
|
-
if (isBuiltinPermit(name)) {
|
|
44
|
-
const parsed = parsePermitName(name);
|
|
45
|
-
if (parsed && parsed.kind !== 'role') {
|
|
46
|
-
if (checkBuiltinPermit(name, message, ['user']))
|
|
47
|
-
return true;
|
|
48
|
-
}
|
|
49
|
-
else if (checkBuiltinPermit(name, message, rolesForPermitCheck(message))) {
|
|
50
|
-
return true;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
for (const permission of this.items) {
|
|
54
|
-
const passed = await permission.check(name, message);
|
|
55
|
-
if (passed)
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
auditPermitDenied(name, message);
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* 序列化为 JSON
|
|
63
|
-
*/
|
|
64
|
-
toJSON(pluginName) {
|
|
65
|
-
const list = pluginName ? this.getByPlugin(pluginName) : this.items;
|
|
66
|
-
return {
|
|
67
|
-
name: this.name,
|
|
68
|
-
icon: this.icon,
|
|
69
|
-
desc: this.desc,
|
|
70
|
-
count: list.length,
|
|
71
|
-
items: list.map(p => ({
|
|
72
|
-
name: p.name instanceof RegExp ? p.name.source : p.name,
|
|
73
|
-
})),
|
|
74
|
-
};
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* 提供给 Plugin.prototype 的扩展方法
|
|
78
|
-
*/
|
|
79
|
-
get extensions() {
|
|
80
|
-
const feature = this;
|
|
81
|
-
return {
|
|
82
|
-
addPermission(permission) {
|
|
83
|
-
const plugin = this;
|
|
84
|
-
const dispose = feature.add(permission, plugin.name);
|
|
85
|
-
const permName = permission.name instanceof RegExp ? permission.name.source : permission.name;
|
|
86
|
-
plugin.recordFeatureContribution(feature.name, permName);
|
|
87
|
-
plugin.onDispose(dispose);
|
|
88
|
-
return dispose;
|
|
89
|
-
},
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
export var Permissions;
|
|
94
|
-
(function (Permissions) {
|
|
95
|
-
function define(name, check) {
|
|
96
|
-
return { name, check };
|
|
97
|
-
}
|
|
98
|
-
Permissions.define = define;
|
|
99
|
-
})(Permissions || (Permissions = {}));
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 内置 permit 同步校验(adapter/group/private/channel/user/role)
|
|
3
|
-
*/
|
|
4
|
-
import type { Message } from '../message.js';
|
|
5
|
-
import { type SenderRole } from './roles.js';
|
|
6
|
-
export declare function checkBuiltinPermit(name: string, message: Message<any>, roles: readonly SenderRole[]): boolean;
|
|
7
|
-
export declare function checkBuiltinPermitList(permits: readonly string[], message: Message<any>, roles: readonly SenderRole[]): boolean;
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { isFrameworkSenderRole, roleSatisfies } from './roles.js';
|
|
2
|
-
import { parsePermitName } from './permit-parse.js';
|
|
3
|
-
function channelIdMatches(id, channelId) {
|
|
4
|
-
return id === '' || id === '*' || channelId === id;
|
|
5
|
-
}
|
|
6
|
-
export function checkBuiltinPermit(name, message, roles) {
|
|
7
|
-
const parsed = parsePermitName(name);
|
|
8
|
-
if (!parsed)
|
|
9
|
-
return false;
|
|
10
|
-
switch (parsed.kind) {
|
|
11
|
-
case 'adapter':
|
|
12
|
-
return parsed.values.some((v) => message.$adapter === v);
|
|
13
|
-
case 'group':
|
|
14
|
-
if (message.$channel?.type !== 'group')
|
|
15
|
-
return false;
|
|
16
|
-
return parsed.values.some((id) => channelIdMatches(id, String(message.$channel.id)));
|
|
17
|
-
case 'private':
|
|
18
|
-
if (message.$channel?.type !== 'private')
|
|
19
|
-
return false;
|
|
20
|
-
return parsed.values.some((id) => channelIdMatches(id, String(message.$channel.id)));
|
|
21
|
-
case 'channel':
|
|
22
|
-
if (message.$channel?.type !== 'channel')
|
|
23
|
-
return false;
|
|
24
|
-
return parsed.values.some((id) => channelIdMatches(id, String(message.$channel.id)));
|
|
25
|
-
case 'user':
|
|
26
|
-
return parsed.values.some((id) => String(message.$sender.id) === id);
|
|
27
|
-
case 'role':
|
|
28
|
-
return parsed.values.some((req) => isFrameworkSenderRole(req) && roleSatisfies(roles, [req]));
|
|
29
|
-
default:
|
|
30
|
-
return false;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
export function checkBuiltinPermitList(permits, message, roles) {
|
|
34
|
-
return permits.every((p) => checkBuiltinPermit(p, message, roles));
|
|
35
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Permit 语法解析:type(a,b,c) 括号内逗号为 OR;链式 .permit().permit() 为 AND(由调用方保证)。
|
|
3
|
-
*/
|
|
4
|
-
export type PermitKind = 'adapter' | 'group' | 'private' | 'channel' | 'user' | 'role';
|
|
5
|
-
export interface ParsedPermit {
|
|
6
|
-
kind: PermitKind;
|
|
7
|
-
values: string[];
|
|
8
|
-
}
|
|
9
|
-
export declare function parsePermitName(name: string): ParsedPermit | null;
|
|
10
|
-
export declare function isBuiltinPermit(name: string): boolean;
|
|
11
|
-
export interface ParsedPlatformPermit {
|
|
12
|
-
adapter: string;
|
|
13
|
-
perm: string;
|
|
14
|
-
}
|
|
15
|
-
export declare function parsePlatformPermitName(name: string): ParsedPlatformPermit | null;
|
|
16
|
-
export declare function isPlatformPermit(name: string): boolean;
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Permit 语法解析:type(a,b,c) 括号内逗号为 OR;链式 .permit().permit() 为 AND(由调用方保证)。
|
|
3
|
-
*/
|
|
4
|
-
const PERMIT_RE = /^(adapter|group|private|channel|user|role)\(([^)]*)\)$/;
|
|
5
|
-
export function parsePermitName(name) {
|
|
6
|
-
const m = name.match(PERMIT_RE);
|
|
7
|
-
if (!m)
|
|
8
|
-
return null;
|
|
9
|
-
const kind = m[1];
|
|
10
|
-
const inner = m[2].trim();
|
|
11
|
-
if (!inner)
|
|
12
|
-
return { kind, values: [''] };
|
|
13
|
-
const values = inner.split(',').map((v) => v.trim()).filter((v) => v.length > 0);
|
|
14
|
-
return { kind, values: values.length > 0 ? values : [''] };
|
|
15
|
-
}
|
|
16
|
-
export function isBuiltinPermit(name) {
|
|
17
|
-
return PERMIT_RE.test(name);
|
|
18
|
-
}
|
|
19
|
-
const PLATFORM_PERMIT_RE = /^platform\(([^,)]+),([^)]*)\)$/;
|
|
20
|
-
export function parsePlatformPermitName(name) {
|
|
21
|
-
const m = name.match(PLATFORM_PERMIT_RE);
|
|
22
|
-
if (!m)
|
|
23
|
-
return null;
|
|
24
|
-
const adapter = m[1].trim();
|
|
25
|
-
const perm = m[2].trim();
|
|
26
|
-
if (!adapter || !perm)
|
|
27
|
-
return null;
|
|
28
|
-
return { adapter, perm };
|
|
29
|
-
}
|
|
30
|
-
export function isPlatformPermit(name) {
|
|
31
|
-
return PLATFORM_PERMIT_RE.test(name);
|
|
32
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Platform permit — 适配器注册的平台级权限校验(场景治理、频道身份等)
|
|
3
|
-
*/
|
|
4
|
-
import type { Message } from '../message.js';
|
|
5
|
-
export type PlatformPermitChecker = (perm: string, message: Message<any>) => boolean;
|
|
6
|
-
export declare function registerPlatformPermitChecker(adapter: string, checker: PlatformPermitChecker): () => void;
|
|
7
|
-
export declare function clearPlatformPermitCheckers(): void;
|
|
8
|
-
export declare function checkPlatformPermit(name: string, message: Message<any>): boolean;
|
|
9
|
-
export declare function checkPlatformPermitList(permits: readonly string[], message: Message<any>): boolean;
|
|
10
|
-
/** OneBot / QQ 系 sender.role 归一化 */
|
|
11
|
-
export declare function normalizeQqSenderRole(role?: string): 'owner' | 'admin' | undefined;
|
|
12
|
-
/** 从 OneBot sender 对象写入 MessageSender.role / permissions */
|
|
13
|
-
export declare function applyQqSenderRoleToMessageSender(sender: {
|
|
14
|
-
role?: string;
|
|
15
|
-
permissions?: string[];
|
|
16
|
-
}, role?: string): void;
|
|
17
|
-
/** 常见 IM 平台场景身份:$sender.role 为 owner / admin */
|
|
18
|
-
export declare function createSceneRolePlatformChecker(): PlatformPermitChecker;
|
|
19
|
-
/** 为适配器注册默认场景治理 platform checker(幂等) */
|
|
20
|
-
export declare function registerDefaultScenePlatformPermitChecker(adapter: string): () => void;
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import { parsePlatformPermitName, isPlatformPermit } from './permit-parse.js';
|
|
2
|
-
const checkers = new Map();
|
|
3
|
-
const defaultSceneRegistrations = new Map();
|
|
4
|
-
export function registerPlatformPermitChecker(adapter, checker) {
|
|
5
|
-
const key = String(adapter);
|
|
6
|
-
const registrations = checkers.get(key) ?? [];
|
|
7
|
-
registrations.push(checker);
|
|
8
|
-
checkers.set(key, registrations);
|
|
9
|
-
return () => {
|
|
10
|
-
const current = checkers.get(key);
|
|
11
|
-
if (!current)
|
|
12
|
-
return;
|
|
13
|
-
const index = current.lastIndexOf(checker);
|
|
14
|
-
if (index >= 0)
|
|
15
|
-
current.splice(index, 1);
|
|
16
|
-
if (current.length === 0)
|
|
17
|
-
checkers.delete(key);
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
export function clearPlatformPermitCheckers() {
|
|
21
|
-
checkers.clear();
|
|
22
|
-
defaultSceneRegistrations.clear();
|
|
23
|
-
}
|
|
24
|
-
export function checkPlatformPermit(name, message) {
|
|
25
|
-
const parsed = parsePlatformPermitName(name);
|
|
26
|
-
if (!parsed)
|
|
27
|
-
return false;
|
|
28
|
-
if (String(message.$adapter) !== parsed.adapter)
|
|
29
|
-
return false;
|
|
30
|
-
const registrations = checkers.get(parsed.adapter);
|
|
31
|
-
const checker = registrations?.[registrations.length - 1];
|
|
32
|
-
if (!checker)
|
|
33
|
-
return false;
|
|
34
|
-
return checker(parsed.perm, message);
|
|
35
|
-
}
|
|
36
|
-
export function checkPlatformPermitList(permits, message) {
|
|
37
|
-
return permits.every((p) => isPlatformPermit(p) && checkPlatformPermit(p, message));
|
|
38
|
-
}
|
|
39
|
-
/** OneBot / QQ 系 sender.role 归一化 */
|
|
40
|
-
export function normalizeQqSenderRole(role) {
|
|
41
|
-
if (!role || role === 'member')
|
|
42
|
-
return undefined;
|
|
43
|
-
if (role === 'owner' || role === 'admin')
|
|
44
|
-
return role;
|
|
45
|
-
return undefined;
|
|
46
|
-
}
|
|
47
|
-
/** 从 OneBot sender 对象写入 MessageSender.role / permissions */
|
|
48
|
-
export function applyQqSenderRoleToMessageSender(sender, role) {
|
|
49
|
-
const normalized = normalizeQqSenderRole(role);
|
|
50
|
-
if (!normalized)
|
|
51
|
-
return;
|
|
52
|
-
sender.role = normalized;
|
|
53
|
-
sender.permissions = [normalized];
|
|
54
|
-
}
|
|
55
|
-
/** 常见 IM 平台场景身份:$sender.role 为 owner / admin */
|
|
56
|
-
export function createSceneRolePlatformChecker() {
|
|
57
|
-
return (perm, message) => {
|
|
58
|
-
const role = message.$sender?.role;
|
|
59
|
-
if (perm === 'scene_admin')
|
|
60
|
-
return role === 'admin' || role === 'owner';
|
|
61
|
-
if (perm === 'scene_owner')
|
|
62
|
-
return role === 'owner';
|
|
63
|
-
return false;
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
/** 为适配器注册默认场景治理 platform checker(幂等) */
|
|
67
|
-
export function registerDefaultScenePlatformPermitChecker(adapter) {
|
|
68
|
-
const key = String(adapter);
|
|
69
|
-
const existing = defaultSceneRegistrations.get(key);
|
|
70
|
-
if (existing) {
|
|
71
|
-
existing.references += 1;
|
|
72
|
-
return () => releaseDefaultSceneChecker(key, existing);
|
|
73
|
-
}
|
|
74
|
-
const checker = createSceneRolePlatformChecker();
|
|
75
|
-
const registration = {
|
|
76
|
-
checker,
|
|
77
|
-
dispose: registerPlatformPermitChecker(key, checker),
|
|
78
|
-
references: 1,
|
|
79
|
-
};
|
|
80
|
-
defaultSceneRegistrations.set(key, registration);
|
|
81
|
-
return () => releaseDefaultSceneChecker(key, registration);
|
|
82
|
-
}
|
|
83
|
-
function releaseDefaultSceneChecker(key, registration) {
|
|
84
|
-
if (defaultSceneRegistrations.get(key) !== registration)
|
|
85
|
-
return;
|
|
86
|
-
registration.references -= 1;
|
|
87
|
-
if (registration.references > 0)
|
|
88
|
-
return;
|
|
89
|
-
defaultSceneRegistrations.delete(key);
|
|
90
|
-
registration.dispose();
|
|
91
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type OutboundRichSegmentPolicy } from './types.js';
|
|
2
|
-
/** 全功能 IM:html/markdown/qrcode→image,tts→audio */
|
|
3
|
-
export declare const OUTBOUND_RICH_SEGMENT_POLICY_IM_FULL: OutboundRichSegmentPolicy;
|
|
4
|
-
/** 仅文本降级(无富媒体出站能力) */
|
|
5
|
-
export declare const OUTBOUND_RICH_SEGMENT_POLICY_TEXT_ONLY: OutboundRichSegmentPolicy;
|
|
6
|
-
/** 默认 registry 等价(html/markdown 文本,qrcode 图片,tts 音频) */
|
|
7
|
-
export declare const OUTBOUND_RICH_SEGMENT_POLICY_IM_DEFAULT: OutboundRichSegmentPolicy;
|
|
8
|
-
/** 无音频出站(tts 降级 text) */
|
|
9
|
-
export declare const OUTBOUND_RICH_SEGMENT_POLICY_NO_AUDIO: OutboundRichSegmentPolicy;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { BUILTIN_RICH_SEGMENT_KINDS, RICH_SEGMENT_MODE } from './types.js';
|
|
2
|
-
/** 全功能 IM:html/markdown/qrcode→image,tts→audio */
|
|
3
|
-
export const OUTBOUND_RICH_SEGMENT_POLICY_IM_FULL = {
|
|
4
|
-
[BUILTIN_RICH_SEGMENT_KINDS.QRCODE]: RICH_SEGMENT_MODE.IMAGE,
|
|
5
|
-
[BUILTIN_RICH_SEGMENT_KINDS.HTML]: RICH_SEGMENT_MODE.IMAGE,
|
|
6
|
-
[BUILTIN_RICH_SEGMENT_KINDS.MARKDOWN]: RICH_SEGMENT_MODE.IMAGE,
|
|
7
|
-
[BUILTIN_RICH_SEGMENT_KINDS.TTS]: RICH_SEGMENT_MODE.AUDIO,
|
|
8
|
-
};
|
|
9
|
-
/** 仅文本降级(无富媒体出站能力) */
|
|
10
|
-
export const OUTBOUND_RICH_SEGMENT_POLICY_TEXT_ONLY = {
|
|
11
|
-
[BUILTIN_RICH_SEGMENT_KINDS.QRCODE]: RICH_SEGMENT_MODE.TEXT,
|
|
12
|
-
[BUILTIN_RICH_SEGMENT_KINDS.HTML]: RICH_SEGMENT_MODE.TEXT,
|
|
13
|
-
[BUILTIN_RICH_SEGMENT_KINDS.MARKDOWN]: RICH_SEGMENT_MODE.TEXT,
|
|
14
|
-
[BUILTIN_RICH_SEGMENT_KINDS.TTS]: RICH_SEGMENT_MODE.TEXT,
|
|
15
|
-
};
|
|
16
|
-
/** 默认 registry 等价(html/markdown 文本,qrcode 图片,tts 音频) */
|
|
17
|
-
export const OUTBOUND_RICH_SEGMENT_POLICY_IM_DEFAULT = {
|
|
18
|
-
[BUILTIN_RICH_SEGMENT_KINDS.QRCODE]: RICH_SEGMENT_MODE.IMAGE,
|
|
19
|
-
[BUILTIN_RICH_SEGMENT_KINDS.HTML]: RICH_SEGMENT_MODE.TEXT,
|
|
20
|
-
[BUILTIN_RICH_SEGMENT_KINDS.MARKDOWN]: RICH_SEGMENT_MODE.TEXT,
|
|
21
|
-
[BUILTIN_RICH_SEGMENT_KINDS.TTS]: RICH_SEGMENT_MODE.AUDIO,
|
|
22
|
-
};
|
|
23
|
-
/** 无音频出站(tts 降级 text) */
|
|
24
|
-
export const OUTBOUND_RICH_SEGMENT_POLICY_NO_AUDIO = {
|
|
25
|
-
...OUTBOUND_RICH_SEGMENT_POLICY_IM_FULL,
|
|
26
|
-
[BUILTIN_RICH_SEGMENT_KINDS.TTS]: RICH_SEGMENT_MODE.TEXT,
|
|
27
|
-
};
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { MessageElement } from '../../types.js';
|
|
2
|
-
import type { RichSegmentRenderContext, RichSegmentRenderResult } from './types.js';
|
|
3
|
-
export declare abstract class RichSegment<TData> {
|
|
4
|
-
readonly data: TData;
|
|
5
|
-
abstract readonly segmentType: string;
|
|
6
|
-
constructor(data: TData);
|
|
7
|
-
abstract render(mode: string, ctx?: RichSegmentRenderContext): Promise<RichSegmentRenderResult>;
|
|
8
|
-
toJSON(): MessageElement;
|
|
9
|
-
}
|
|
10
|
-
export declare function isRichSegment(item: unknown): item is RichSegment<unknown>;
|
|
11
|
-
export declare function richSegmentKind(item: MessageElement | string): string | null;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { richSegmentRegistry } from './registry.js';
|
|
2
|
-
export class RichSegment {
|
|
3
|
-
data;
|
|
4
|
-
constructor(data) {
|
|
5
|
-
this.data = data;
|
|
6
|
-
}
|
|
7
|
-
toJSON() {
|
|
8
|
-
return { type: this.segmentType, data: this.data };
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
export function isRichSegment(item) {
|
|
12
|
-
return item instanceof RichSegment;
|
|
13
|
-
}
|
|
14
|
-
export function richSegmentKind(item) {
|
|
15
|
-
if (typeof item === 'string')
|
|
16
|
-
return null;
|
|
17
|
-
const type = item.type;
|
|
18
|
-
if (typeof type !== 'string')
|
|
19
|
-
return null;
|
|
20
|
-
if (richSegmentRegistry.has(type)) {
|
|
21
|
-
return type;
|
|
22
|
-
}
|
|
23
|
-
return null;
|
|
24
|
-
}
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
import { registerRichSegmentKind, richSegmentRegistry } from './registry.js';
|
|
2
|
-
import { wrapQrcodeSegment } from './qrcode-segment.js';
|
|
3
|
-
import { wrapHtmlSegment } from './html-segment.js';
|
|
4
|
-
import { wrapMarkdownSegment } from './markdown-segment.js';
|
|
5
|
-
import { wrapTtsSegment } from './tts-segment.js';
|
|
6
|
-
import { BUILTIN_RICH_SEGMENT_KINDS, RICH_SEGMENT_MODE } from './types.js';
|
|
7
|
-
function registerBuiltinRichSegmentKinds() {
|
|
8
|
-
registerRichSegmentKind({
|
|
9
|
-
kind: BUILTIN_RICH_SEGMENT_KINDS.QRCODE,
|
|
10
|
-
defaultMode: RICH_SEGMENT_MODE.IMAGE,
|
|
11
|
-
modes: [RICH_SEGMENT_MODE.IMAGE, RICH_SEGMENT_MODE.TEXT, RICH_SEGMENT_MODE.ORIGIN],
|
|
12
|
-
wrap: wrapQrcodeSegment,
|
|
13
|
-
});
|
|
14
|
-
registerRichSegmentKind({
|
|
15
|
-
kind: BUILTIN_RICH_SEGMENT_KINDS.HTML,
|
|
16
|
-
defaultMode: RICH_SEGMENT_MODE.TEXT,
|
|
17
|
-
modes: [RICH_SEGMENT_MODE.IMAGE, RICH_SEGMENT_MODE.TEXT, RICH_SEGMENT_MODE.ORIGIN],
|
|
18
|
-
wrap: wrapHtmlSegment,
|
|
19
|
-
});
|
|
20
|
-
registerRichSegmentKind({
|
|
21
|
-
kind: BUILTIN_RICH_SEGMENT_KINDS.MARKDOWN,
|
|
22
|
-
defaultMode: RICH_SEGMENT_MODE.TEXT,
|
|
23
|
-
modes: [RICH_SEGMENT_MODE.IMAGE, RICH_SEGMENT_MODE.TEXT, RICH_SEGMENT_MODE.ORIGIN],
|
|
24
|
-
wrap: wrapMarkdownSegment,
|
|
25
|
-
});
|
|
26
|
-
registerRichSegmentKind({
|
|
27
|
-
kind: BUILTIN_RICH_SEGMENT_KINDS.TTS,
|
|
28
|
-
defaultMode: RICH_SEGMENT_MODE.AUDIO,
|
|
29
|
-
modes: [RICH_SEGMENT_MODE.ORIGIN, RICH_SEGMENT_MODE.AUDIO, RICH_SEGMENT_MODE.TEXT],
|
|
30
|
-
wrap: wrapTtsSegment,
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
registerBuiltinRichSegmentKinds();
|
|
34
|
-
/** 内置 kind 的默认出站 policy(由 registry 生成,增 kind 时自动包含) */
|
|
35
|
-
export const DEFAULT_OUTBOUND_RICH_SEGMENT_POLICY = richSegmentRegistry.buildDefaultPolicy();
|
|
36
|
-
/** 测试:清空 registry 后重新注册内置 kind */
|
|
37
|
-
export function resetBuiltinRichSegmentKindsForTests() {
|
|
38
|
-
richSegmentRegistry.clearForTests();
|
|
39
|
-
registerBuiltinRichSegmentKinds();
|
|
40
|
-
}
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import type { RichSegmentCapabilityLoader, RichSegmentCapabilityLoaderOptions, RichSegmentRenderContext } from './types.js';
|
|
2
|
-
/** 注册 optional 包能力(如 html-renderer、未来 media-pipeline) */
|
|
3
|
-
export declare function registerRichSegmentCapabilityLoader(id: string, loader: RichSegmentCapabilityLoader): void;
|
|
4
|
-
/** 测试隔离 */
|
|
5
|
-
export declare function resetRichSegmentCapabilityLoadersForTests(): void;
|
|
6
|
-
export declare function createRichSegmentRenderContext(options?: RichSegmentCapabilityLoaderOptions): RichSegmentRenderContext;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { loadHtmlRenderer } from '../html-renderer-loader.js';
|
|
2
|
-
import { loadSpeechPipeline } from '../speech-loader.js';
|
|
3
|
-
const capabilityLoaders = new Map();
|
|
4
|
-
/** 注册 optional 包能力(如 html-renderer、未来 media-pipeline) */
|
|
5
|
-
export function registerRichSegmentCapabilityLoader(id, loader) {
|
|
6
|
-
capabilityLoaders.set(id, loader);
|
|
7
|
-
}
|
|
8
|
-
/** 测试隔离 */
|
|
9
|
-
export function resetRichSegmentCapabilityLoadersForTests() {
|
|
10
|
-
capabilityLoaders.clear();
|
|
11
|
-
registerCoreRichSegmentCapabilityLoaders();
|
|
12
|
-
}
|
|
13
|
-
function registerCoreRichSegmentCapabilityLoaders() {
|
|
14
|
-
registerRichSegmentCapabilityLoader('html-renderer', async (options) => loadHtmlRenderer({
|
|
15
|
-
getConfig: options.getConfig,
|
|
16
|
-
warn: options.warn,
|
|
17
|
-
}));
|
|
18
|
-
registerRichSegmentCapabilityLoader('speech', async (options) => loadSpeechPipeline({
|
|
19
|
-
getConfig: options.getConfig,
|
|
20
|
-
warn: options.warn,
|
|
21
|
-
}));
|
|
22
|
-
}
|
|
23
|
-
registerCoreRichSegmentCapabilityLoaders();
|
|
24
|
-
export function createRichSegmentRenderContext(options = {}) {
|
|
25
|
-
const cache = new Map();
|
|
26
|
-
const resolveCapability = async (id) => {
|
|
27
|
-
if (!cache.has(id)) {
|
|
28
|
-
const loader = capabilityLoaders.get(id);
|
|
29
|
-
cache.set(id, loader ? loader(options) : Promise.resolve(undefined));
|
|
30
|
-
}
|
|
31
|
-
return cache.get(id);
|
|
32
|
-
};
|
|
33
|
-
return {
|
|
34
|
-
resolveCapability,
|
|
35
|
-
warn: options.warn,
|
|
36
|
-
logContentChain: options.logContentChain,
|
|
37
|
-
};
|
|
38
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { RichSegment } from './base.js';
|
|
2
|
-
import { type RichSegmentRenderContext, type RichSegmentRenderResult } from './types.js';
|
|
3
|
-
export interface HtmlSegmentData {
|
|
4
|
-
html: string;
|
|
5
|
-
text?: string;
|
|
6
|
-
width?: number;
|
|
7
|
-
backgroundColor?: string;
|
|
8
|
-
fileName?: string;
|
|
9
|
-
}
|
|
10
|
-
export declare class HtmlSegment extends RichSegment<HtmlSegmentData> {
|
|
11
|
-
readonly segmentType: "html";
|
|
12
|
-
readonly type: "html";
|
|
13
|
-
render(mode: string, ctx?: RichSegmentRenderContext): Promise<RichSegmentRenderResult>;
|
|
14
|
-
}
|
|
15
|
-
export declare function wrapHtmlSegment(data: Record<string, unknown>): HtmlSegment;
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { segment } from '../../utils.js';
|
|
2
|
-
import { htmlToFallbackText } from '../html-to-text.js';
|
|
3
|
-
import { RichSegment } from './base.js';
|
|
4
|
-
import { RICH_SEGMENT_MODE } from './types.js';
|
|
5
|
-
async function resolveHtmlRenderer(ctx) {
|
|
6
|
-
if (!ctx)
|
|
7
|
-
return undefined;
|
|
8
|
-
return ctx.resolveCapability('html-renderer');
|
|
9
|
-
}
|
|
10
|
-
export class HtmlSegment extends RichSegment {
|
|
11
|
-
segmentType = 'html';
|
|
12
|
-
type = 'html';
|
|
13
|
-
async render(mode, ctx) {
|
|
14
|
-
if (mode === RICH_SEGMENT_MODE.ORIGIN) {
|
|
15
|
-
return this.toJSON();
|
|
16
|
-
}
|
|
17
|
-
if (mode === RICH_SEGMENT_MODE.TEXT) {
|
|
18
|
-
if (typeof this.data.text === 'string' && this.data.text.length > 0) {
|
|
19
|
-
return segment.text(this.data.text);
|
|
20
|
-
}
|
|
21
|
-
const html = typeof this.data.html === 'string' ? this.data.html : '';
|
|
22
|
-
return segment.text(html ? htmlToFallbackText(html) : '');
|
|
23
|
-
}
|
|
24
|
-
if (mode === RICH_SEGMENT_MODE.IMAGE) {
|
|
25
|
-
const html = typeof this.data.html === 'string' ? this.data.html : '';
|
|
26
|
-
if (!html) {
|
|
27
|
-
return segment.text('');
|
|
28
|
-
}
|
|
29
|
-
const renderer = await resolveHtmlRenderer(ctx);
|
|
30
|
-
if (!renderer) {
|
|
31
|
-
return this.render(RICH_SEGMENT_MODE.TEXT, ctx);
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
const result = await renderer.render(html, {
|
|
35
|
-
width: typeof this.data.width === 'number' ? this.data.width : 540,
|
|
36
|
-
format: 'png',
|
|
37
|
-
backgroundColor: typeof this.data.backgroundColor === 'string' ? this.data.backgroundColor : '#d8dce3',
|
|
38
|
-
});
|
|
39
|
-
if (result.format !== 'png' || typeof result.data !== 'object') {
|
|
40
|
-
return this.render(RICH_SEGMENT_MODE.TEXT, ctx);
|
|
41
|
-
}
|
|
42
|
-
const base64 = Buffer.from(result.data).toString('base64');
|
|
43
|
-
const fileName = typeof this.data.fileName === 'string' ? this.data.fileName : 'card.png';
|
|
44
|
-
return segment('image', { url: `base64://${base64}`, name: fileName });
|
|
45
|
-
}
|
|
46
|
-
catch {
|
|
47
|
-
return this.render(RICH_SEGMENT_MODE.TEXT, ctx);
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return this.render(RICH_SEGMENT_MODE.TEXT, ctx);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
export function wrapHtmlSegment(data) {
|
|
54
|
-
const html = typeof data.html === 'string' ? data.html : '';
|
|
55
|
-
return new HtmlSegment({
|
|
56
|
-
html,
|
|
57
|
-
text: typeof data.text === 'string' ? data.text : undefined,
|
|
58
|
-
width: typeof data.width === 'number' ? data.width : undefined,
|
|
59
|
-
backgroundColor: typeof data.backgroundColor === 'string' ? data.backgroundColor : undefined,
|
|
60
|
-
fileName: typeof data.fileName === 'string' ? data.fileName : undefined,
|
|
61
|
-
});
|
|
62
|
-
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import './builtins.js';
|
|
2
|
-
export * from './types.js';
|
|
3
|
-
export * from './registry.js';
|
|
4
|
-
export * from './capabilities.js';
|
|
5
|
-
export { DEFAULT_OUTBOUND_RICH_SEGMENT_POLICY, resetBuiltinRichSegmentKindsForTests, } from './builtins.js';
|
|
6
|
-
export * from './base.js';
|
|
7
|
-
export * from './qrcode-segment.js';
|
|
8
|
-
export * from './html-segment.js';
|
|
9
|
-
export * from './markdown-segment.js';
|
|
10
|
-
export * from './tts-segment.js';
|
|
11
|
-
export * from './markdown-to-text.js';
|
|
12
|
-
export * from './resolve.js';
|
|
13
|
-
export * from './adapter-policies.js';
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import './builtins.js';
|
|
2
|
-
export * from './types.js';
|
|
3
|
-
export * from './registry.js';
|
|
4
|
-
export * from './capabilities.js';
|
|
5
|
-
export { DEFAULT_OUTBOUND_RICH_SEGMENT_POLICY, resetBuiltinRichSegmentKindsForTests, } from './builtins.js';
|
|
6
|
-
export * from './base.js';
|
|
7
|
-
export * from './qrcode-segment.js';
|
|
8
|
-
export * from './html-segment.js';
|
|
9
|
-
export * from './markdown-segment.js';
|
|
10
|
-
export * from './tts-segment.js';
|
|
11
|
-
export * from './markdown-to-text.js';
|
|
12
|
-
export * from './resolve.js';
|
|
13
|
-
export * from './adapter-policies.js';
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { RichSegment } from './base.js';
|
|
2
|
-
import { type RichSegmentRenderContext, type RichSegmentRenderResult } from './types.js';
|
|
3
|
-
export interface MarkdownSegmentData {
|
|
4
|
-
content: string;
|
|
5
|
-
width?: number;
|
|
6
|
-
backgroundColor?: string;
|
|
7
|
-
fileName?: string;
|
|
8
|
-
}
|
|
9
|
-
export declare class MarkdownSegment extends RichSegment<MarkdownSegmentData> {
|
|
10
|
-
readonly segmentType: "markdown";
|
|
11
|
-
readonly type: "markdown";
|
|
12
|
-
render(mode: string, ctx?: RichSegmentRenderContext): Promise<RichSegmentRenderResult>;
|
|
13
|
-
}
|
|
14
|
-
export declare function wrapMarkdownSegment(data: Record<string, unknown>): MarkdownSegment;
|