@zhin.js/core 1.1.57 → 1.1.59
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/lib/built/user-interaction.d.ts +1 -1
- package/lib/feature/command.d.ts +2 -4
- package/lib/feature/command.js +1 -2
- package/lib/feature/middleware.d.ts +2 -2
- package/lib/feature/middleware.js +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/plugin-runtime/im/command-feedback.d.ts +20 -1
- package/lib/plugin-runtime/im/command-feedback.js +63 -0
- package/lib/plugin-runtime/im/contracts.d.ts +60 -5
- package/lib/plugin-runtime/im/contracts.js +6 -2
- package/lib/plugin-runtime/im/endpoint-runtime.d.ts +2 -3
- package/lib/plugin-runtime/im/endpoint-runtime.js +2 -2
- package/lib/plugin-runtime/im/host/component-host-installer.d.ts +2 -0
- package/lib/plugin-runtime/im/host/component-host-installer.js +14 -0
- package/lib/plugin-runtime/im/host/conversation-migration.d.ts +5 -0
- package/lib/plugin-runtime/im/host/conversation-migration.js +75 -0
- package/lib/plugin-runtime/im/host/database-config.d.ts +10 -0
- package/lib/plugin-runtime/im/host/database-config.js +114 -0
- package/lib/plugin-runtime/im/host/database-host-installer.d.ts +13 -0
- package/lib/plugin-runtime/im/host/database-host-installer.js +389 -0
- package/lib/plugin-runtime/im/host/database-state.d.ts +9 -0
- package/lib/plugin-runtime/im/host/database-state.js +91 -0
- package/lib/plugin-runtime/im/host/index.d.ts +8 -0
- package/lib/plugin-runtime/im/host/index.js +8 -0
- package/lib/plugin-runtime/im/host/locale-host-installer.d.ts +3 -0
- package/lib/plugin-runtime/im/host/locale-host-installer.js +60 -0
- package/lib/plugin-runtime/im/host/outbound-host-installer.d.ts +8 -0
- package/lib/plugin-runtime/im/host/outbound-host-installer.js +153 -0
- package/lib/plugin-runtime/im/host/sender-enrichment.d.ts +33 -0
- package/lib/plugin-runtime/im/host/sender-enrichment.js +215 -0
- package/lib/plugin-runtime/im/im-runtime.d.ts +7 -3
- package/lib/plugin-runtime/im/im-runtime.js +9 -7
- package/lib/plugin-runtime/im/inbound-dedup.d.ts +32 -0
- package/lib/plugin-runtime/im/inbound-dedup.js +138 -1
- package/lib/plugin-runtime/im/inbound-origin.d.ts +24 -2
- package/lib/plugin-runtime/im/inbound-origin.js +108 -1
- package/lib/plugin-runtime/im/inbound-runtime.d.ts +10 -13
- package/lib/plugin-runtime/im/inbound-runtime.js +92 -412
- package/lib/plugin-runtime/im/inbound-spine.d.ts +194 -0
- package/lib/plugin-runtime/im/inbound-spine.js +333 -0
- package/lib/plugin-runtime/im/index.d.ts +5 -7
- package/lib/plugin-runtime/im/index.js +5 -6
- package/lib/plugin-runtime/im/interaction-runtime.d.ts +4 -7
- package/lib/plugin-runtime/im/interaction-runtime.js +5 -8
- package/lib/plugin-runtime/im/interactive-router.d.ts +31 -4
- package/lib/plugin-runtime/im/interactive-router.js +134 -2
- package/lib/plugin-runtime/im/message-dispatcher.d.ts +1 -1
- package/lib/plugin-runtime/im/message-dispatcher.js +1 -2
- package/lib/plugin-runtime/im/message-events.d.ts +33 -3
- package/lib/plugin-runtime/im/message-events.js +34 -0
- package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +1 -2
- package/lib/plugin-runtime/im/outbound-delivery-runtime.js +4 -8
- package/lib/plugin-runtime/im/outbound-renderer.d.ts +32 -2
- package/lib/plugin-runtime/im/outbound-renderer.js +95 -4
- package/package.json +13 -14
- package/lib/plugin-runtime/im/captured-endpoint-operation.d.ts +0 -34
- package/lib/plugin-runtime/im/captured-endpoint-operation.js +0 -1
- package/lib/plugin-runtime/im/command-menu-navigation.d.ts +0 -13
- package/lib/plugin-runtime/im/command-menu-navigation.js +0 -43
- package/lib/plugin-runtime/im/command-menu-presentation.d.ts +0 -14
- package/lib/plugin-runtime/im/command-menu-presentation.js +0 -25
- package/lib/plugin-runtime/im/group-rule-violation.d.ts +0 -52
- package/lib/plugin-runtime/im/group-rule-violation.js +0 -10
- package/lib/plugin-runtime/im/ingress-route.d.ts +0 -10
- package/lib/plugin-runtime/im/ingress-route.js +0 -10
- package/lib/plugin-runtime/im/interaction-operation.d.ts +0 -12
- package/lib/plugin-runtime/im/interaction-operation.js +0 -2
- package/lib/plugin-runtime/im/jsx-button-registry.d.ts +0 -31
- package/lib/plugin-runtime/im/jsx-button-registry.js +0 -135
- package/lib/plugin-runtime/im/locale.d.ts +0 -5
- package/lib/plugin-runtime/im/locale.js +0 -12
- package/lib/plugin-runtime/im/login-assist-host.d.ts +0 -6
- package/lib/plugin-runtime/im/login-assist-host.js +0 -6
- package/lib/plugin-runtime/im/member-welcome.d.ts +0 -8
- package/lib/plugin-runtime/im/member-welcome.js +0 -11
- package/lib/plugin-runtime/im/message-bus.d.ts +0 -38
- package/lib/plugin-runtime/im/message-bus.js +0 -40
- package/lib/plugin-runtime/im/operation-endpoint.d.ts +0 -6
- package/lib/plugin-runtime/im/operation-endpoint.js +0 -2
- package/lib/plugin-runtime/im/operation-resources.d.ts +0 -15
- package/lib/plugin-runtime/im/operation-resources.js +0 -2
- package/lib/plugin-runtime/im/outbound-ledger.d.ts +0 -24
- package/lib/plugin-runtime/im/outbound-ledger.js +0 -114
- package/lib/plugin-runtime/im/outbound-presentation.d.ts +0 -19
- package/lib/plugin-runtime/im/outbound-presentation.js +0 -41
- package/lib/plugin-runtime/im/outbound-projection.d.ts +0 -17
- package/lib/plugin-runtime/im/outbound-projection.js +0 -55
- package/lib/plugin-runtime/im/runtime-middleware.d.ts +0 -5
- package/lib/plugin-runtime/im/runtime-middleware.js +0 -18
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
import type { EndpointEvent } from '@zhin.js/adapter';
|
|
2
|
+
import type { ConversationRef, DeliveryReceipt, UserInteraction, UserInteractionFactory } from '@zhin.js/im-contract';
|
|
3
|
+
import { type InboundTerminalControl } from '@zhin.js/middleware';
|
|
4
|
+
import { type GenerationAdmissionGate, type Locale, type PluginId, type RuntimeSnapshot, type SnapshotLease } from '@zhin.js/plugin-runtime';
|
|
5
|
+
import { HandlerIndex } from '../../feature/handler.js';
|
|
6
|
+
import { type IncomingNotice, type Notice } from '../../notice.js';
|
|
7
|
+
import { type IncomingRequest, type Request } from '../../request.js';
|
|
8
|
+
import type { EndpointEventContext } from '../../side-event/base.js';
|
|
9
|
+
import { type IncomingSystemEvent, type SystemEvent } from '../../system-event.js';
|
|
10
|
+
import { type CapturedEndpointOperation, type Message, type MessageDispatchResult, type SendContent, type SendRequest } from './contracts.js';
|
|
11
|
+
import type { RuntimeInteractionCoordinator } from './interaction-runtime.js';
|
|
12
|
+
import type { RuntimeMessageDiagnostics } from './message-diagnostics.js';
|
|
13
|
+
import type { MessageDispatchOutcome } from './message-dispatcher.js';
|
|
14
|
+
export { arbitrateRoomInboundDeduplication, buildRoomInboundRouteInput, resolveRoomMembership, type InboundRoomRouteRequest, } from './inbound-dedup.js';
|
|
15
|
+
/** Generation-owned hooks before ordinary dispatch and after it misses. */
|
|
16
|
+
export interface IngressRoute {
|
|
17
|
+
preRoute?(message: Message, lease: SnapshotLease, requester: PluginId, conversationSequence: number | undefined): Promise<boolean>;
|
|
18
|
+
shouldRouteBeforeDispatch?(message: Message): boolean;
|
|
19
|
+
route(message: Message, lease: SnapshotLease, requester: PluginId, conversationSequence: number | undefined): Promise<boolean>;
|
|
20
|
+
}
|
|
21
|
+
export declare const ingressRouteToken: import("@zhin.js/plugin-runtime").Token<IngressRoute>;
|
|
22
|
+
export declare function resolveIngressRoute(snapshot: RuntimeSnapshot): IngressRoute | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* 群管违规上报(ADR 0039 §5,切片 E)。
|
|
25
|
+
*
|
|
26
|
+
* content-moderation 等插件只负责「判定违规」,「判定后做什么」交给 Agent host 的群规执行器:
|
|
27
|
+
* 按该群生效规则的阶梯执行提醒 / 警告 / 禁言(以规则批准作硬闸批准)/ 建议踢人(每次人批出卡)。
|
|
28
|
+
* Agent host 在根作用域提供本 token;未装 Agent(没有本资源)时插件只能提醒 / 警告,不能禁言或踢人。
|
|
29
|
+
*/
|
|
30
|
+
/** 插件可上报的违规类型(`flood` 由宿主本地检测,不经插件)。 @public */
|
|
31
|
+
export type GroupRuleViolationTrigger = 'advertising' | 'abuse';
|
|
32
|
+
/** @public */
|
|
33
|
+
export interface GroupRuleViolationReport {
|
|
34
|
+
/** Runtime-only authority captured from the actual incoming Client; never persist this object. */
|
|
35
|
+
readonly source: Readonly<{
|
|
36
|
+
client: unknown;
|
|
37
|
+
signal: AbortSignal;
|
|
38
|
+
}>;
|
|
39
|
+
/** 违规消息所在的群会话(`kind` 必须是 `group`)。 */
|
|
40
|
+
readonly conversation: ConversationRef;
|
|
41
|
+
readonly memberId: string;
|
|
42
|
+
readonly memberName?: string;
|
|
43
|
+
/** 入站消息上的平台角色(群主 / 管理员豁免)。 */
|
|
44
|
+
readonly memberRoles?: readonly unknown[];
|
|
45
|
+
readonly trigger: GroupRuleViolationTrigger;
|
|
46
|
+
/** 原消息发出时间(毫秒)。 */
|
|
47
|
+
readonly sentAt: number;
|
|
48
|
+
readonly messageId?: string;
|
|
49
|
+
/** 命中证据(原文摘录)。 */
|
|
50
|
+
readonly evidence?: readonly string[];
|
|
51
|
+
/**
|
|
52
|
+
* 入群不久即发广告:不按阶梯,直接出一张踢人审批卡(每次人批,绝不自动踢)。
|
|
53
|
+
* 只对 `advertising` 生效。
|
|
54
|
+
*/
|
|
55
|
+
readonly newcomer?: boolean;
|
|
56
|
+
/** `remind` / `warn` 档的附加动作:撤回原消息(调用方绑定到这条原消息)。 */
|
|
57
|
+
readonly recall?: () => Promise<void>;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* `handled`:执行器已按规则处理(含被控制面 / 豁免 / 冷却跳过),调用方不得再自行提醒或处罚。
|
|
61
|
+
* `no_rule`:该群该类型没有可用规则,调用方可退回只提醒 / 警告。
|
|
62
|
+
* @public
|
|
63
|
+
*/
|
|
64
|
+
export type GroupRuleViolationOutcome = 'handled' | 'no_rule';
|
|
65
|
+
/** 迁移结果:`created` 新建了待确认规则;`exists` 该群该类型已有规则(任意状态);`unavailable` 规则存储不可用。 @public */
|
|
66
|
+
export type GroupRuleDefaultOutcome = 'created' | 'exists' | 'unavailable';
|
|
67
|
+
/** @public */
|
|
68
|
+
export interface GroupRuleViolationSink {
|
|
69
|
+
report(violation: GroupRuleViolationReport): Promise<GroupRuleViolationOutcome>;
|
|
70
|
+
/**
|
|
71
|
+
* 迁移:该群该类型还没有任何规则时,按默认模板(提醒 → 警告 → 禁言 600 秒,冷静期 30 分钟)
|
|
72
|
+
* 生成一条 `pending` 规则并在群里出预览卡,等群主 / 管理员确认一次。已有任意状态的规则则不动。
|
|
73
|
+
*/
|
|
74
|
+
ensureDefaultRule(input: Readonly<{
|
|
75
|
+
conversation: ConversationRef;
|
|
76
|
+
trigger: GroupRuleViolationTrigger;
|
|
77
|
+
}>): Promise<GroupRuleDefaultOutcome>;
|
|
78
|
+
}
|
|
79
|
+
/** @public */
|
|
80
|
+
export declare const groupRuleViolationToken: import("@zhin.js/plugin-runtime").Token<GroupRuleViolationSink>;
|
|
81
|
+
/**
|
|
82
|
+
* 入群欢迎归属(#1012 A9 方案②)。
|
|
83
|
+
*
|
|
84
|
+
* Agent 会话级欢迎(ADR 0037 切片 A,session-ops `welcome.enabled` + MemberLifecycle)由 Agent host 在根作用域提供本 token。
|
|
85
|
+
* 插件里的旧欢迎(如 group-suite `welcomeMessage`)发送前先问归属:已被会话级欢迎接管的会话,插件不再发送,
|
|
86
|
+
* 欢迎统一走 MemberLifecycle(合并窗口、小时上限、控制面、session-gate),避免同一次入群双发。
|
|
87
|
+
* 未装 Agent(没有本资源)时插件保持原行为。
|
|
88
|
+
*/
|
|
89
|
+
/** @public */
|
|
90
|
+
export interface MemberWelcomeOwner {
|
|
91
|
+
/** 该会话的入群欢迎是否已由会话级欢迎接管(session-ops `welcome.enabled`)。只读内存,不发送、不写审计。 */
|
|
92
|
+
ownsWelcome(conversation: ConversationRef): boolean;
|
|
93
|
+
}
|
|
94
|
+
/** @public */
|
|
95
|
+
export declare const memberWelcomeOwnerToken: import("@zhin.js/plugin-runtime").Token<MemberWelcomeOwner>;
|
|
96
|
+
/** Runs the generation-owned middleware projection or the terminal directly. */
|
|
97
|
+
export declare function runRuntimeMiddleware<TInput>(snapshot: RuntimeSnapshot, input: TInput, terminal: () => Promise<void>, target: 'inbound' | 'outbound'): Promise<void>;
|
|
98
|
+
/** Legacy outbound middleware sees one complete reply unless its author explicitly supports revisions. */
|
|
99
|
+
export declare function supportsIncrementalOutbound(snapshot: RuntimeSnapshot, adapter: string): boolean;
|
|
100
|
+
export declare function projectLocale(snapshot: RuntimeSnapshot): Locale;
|
|
101
|
+
/** Resolve once per operation; callbacks retain the original operation's language. */
|
|
102
|
+
export declare function messageLocale(snapshot: RuntimeSnapshot, conversation: Pick<ConversationRef, 'endpoint'>, senderId?: string): Promise<Locale>;
|
|
103
|
+
export type InboundSpineStage = 'pre-route' | 'before-dispatch-route' | 'handlers' | 'interactive' | 'command' | 'agent-ingress' | 'none';
|
|
104
|
+
export type InboundCommandObserve = (stage: 'prefix' | 'dispatch', status: 'mismatch' | 'matched' | 'empty_input' | 'commands_unavailable' | 'started') => void;
|
|
105
|
+
export interface InboundTurnRecord {
|
|
106
|
+
readonly turnId: string;
|
|
107
|
+
readonly conversation: Message['conversation'];
|
|
108
|
+
readonly senderId?: string;
|
|
109
|
+
readonly stage: InboundSpineStage;
|
|
110
|
+
readonly matched: boolean;
|
|
111
|
+
readonly command?: string;
|
|
112
|
+
readonly owner?: PluginId;
|
|
113
|
+
readonly replied: boolean;
|
|
114
|
+
readonly durationMs: number;
|
|
115
|
+
}
|
|
116
|
+
export interface InboundTurnEnvelope {
|
|
117
|
+
readonly turnId?: string;
|
|
118
|
+
readonly message: Message;
|
|
119
|
+
readonly lease: SnapshotLease;
|
|
120
|
+
readonly requester: PluginId;
|
|
121
|
+
readonly conversationSequence: number | undefined;
|
|
122
|
+
readonly admission?: GenerationAdmissionGate;
|
|
123
|
+
readonly signal?: AbortSignal;
|
|
124
|
+
readonly interactionFactory?: UserInteractionFactory;
|
|
125
|
+
readonly ingressRoute?: IngressRoute;
|
|
126
|
+
readonly diagnostics?: Pick<RuntimeMessageDiagnostics, 'route' | 'step'>;
|
|
127
|
+
readonly onTurnComplete?: (record: InboundTurnRecord) => void | Promise<void>;
|
|
128
|
+
runHandlers(): Promise<void>;
|
|
129
|
+
dispatchInteractive(): Promise<MessageDispatchResult | undefined>;
|
|
130
|
+
dispatchCommand(observe: InboundCommandObserve): Promise<MessageDispatchOutcome>;
|
|
131
|
+
hasReplied(): boolean;
|
|
132
|
+
findEventHandlerName?(event: string): string | undefined;
|
|
133
|
+
}
|
|
134
|
+
export interface InboundSpineOutcome {
|
|
135
|
+
readonly dispatch: MessageDispatchResult;
|
|
136
|
+
readonly stage: InboundSpineStage;
|
|
137
|
+
readonly record: InboundTurnRecord;
|
|
138
|
+
readonly reply?: {
|
|
139
|
+
readonly owner: PluginId;
|
|
140
|
+
readonly content: SendContent;
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
export declare function executeInboundTurnSpine(envelope: InboundTurnEnvelope, control?: InboundTerminalControl): Promise<InboundSpineOutcome>;
|
|
144
|
+
export type InboundInteractionPort = Pick<RuntimeInteractionCoordinator<GenerationAdmissionGate>, 'create' | 'createForMessage' | 'createFromUnknown' | 'dispatch' | 'resolveClaim'> & Partial<Pick<RuntimeInteractionCoordinator<GenerationAdmissionGate>, 'hasPendingAnswer'>>;
|
|
145
|
+
export interface InboundOutcome {
|
|
146
|
+
readonly dispatch: MessageDispatchResult;
|
|
147
|
+
readonly reply?: {
|
|
148
|
+
readonly owner: PluginId;
|
|
149
|
+
readonly content: SendContent;
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/** Native arguments and cancellation belong to the same already-admitted Root operation. */
|
|
153
|
+
export interface InboundHandlerDispatch {
|
|
154
|
+
readonly lease: SnapshotLease;
|
|
155
|
+
readonly event: string;
|
|
156
|
+
readonly args: readonly unknown[];
|
|
157
|
+
readonly signal?: AbortSignal;
|
|
158
|
+
readonly interactions: InboundInteractionPort;
|
|
159
|
+
readonly deliver: (request: SendRequest, snapshot: RuntimeSnapshot) => Promise<DeliveryReceipt>;
|
|
160
|
+
readonly captureInteraction?: (owner: PluginId, conversation: ConversationRef) => CapturedEndpointOperation;
|
|
161
|
+
}
|
|
162
|
+
/** A side-event interaction uses its admitted author's exact snapshot and cancellation. */
|
|
163
|
+
export interface InboundSideInteractionRequest {
|
|
164
|
+
readonly payload: Notice | Request;
|
|
165
|
+
readonly snapshot: RuntimeSnapshot;
|
|
166
|
+
readonly requester: PluginId;
|
|
167
|
+
readonly signal: AbortSignal;
|
|
168
|
+
readonly interactions: InboundInteractionPort;
|
|
169
|
+
readonly deliver: (request: SendRequest, snapshot: RuntimeSnapshot) => Promise<DeliveryReceipt>;
|
|
170
|
+
readonly retain?: () => CapturedEndpointOperation;
|
|
171
|
+
}
|
|
172
|
+
export interface InboundInteractiveDispatch {
|
|
173
|
+
readonly message: Message;
|
|
174
|
+
readonly requester: PluginId;
|
|
175
|
+
readonly admission?: GenerationAdmissionGate;
|
|
176
|
+
readonly snapshot: RuntimeSnapshot;
|
|
177
|
+
readonly interactions: InboundInteractionPort;
|
|
178
|
+
}
|
|
179
|
+
export declare function runInboundMiddlewareAndSpine(envelope: InboundTurnEnvelope, diagnostics?: RuntimeMessageDiagnostics): Promise<InboundOutcome>;
|
|
180
|
+
export declare function dispatchInboundHandlers({ lease, event, args, signal, interactions, deliver, captureInteraction, }: InboundHandlerDispatch): Promise<void>;
|
|
181
|
+
export declare function createInteractionForSideEvent({ payload, snapshot, requester, signal, interactions, deliver, retain, }: InboundSideInteractionRequest): UserInteraction | undefined;
|
|
182
|
+
export declare function dispatchInboundInteractive({ message, requester, admission, snapshot, interactions, }: InboundInteractiveDispatch): Promise<MessageDispatchResult | undefined>;
|
|
183
|
+
export declare function dispatchCanonicalEndpointEvent(input: {
|
|
184
|
+
readonly source: EndpointEvent<IncomingNotice | IncomingRequest | IncomingSystemEvent>;
|
|
185
|
+
readonly context: EndpointEventContext;
|
|
186
|
+
readonly assertActive: () => void;
|
|
187
|
+
readonly recordNotice: (notice: Notice) => Promise<unknown>;
|
|
188
|
+
readonly recordRequest?: (request: Request) => Promise<unknown>;
|
|
189
|
+
readonly dispatch: (payload: Notice | Request | SystemEvent) => Promise<void>;
|
|
190
|
+
}): Promise<void>;
|
|
191
|
+
export declare function interactionResult(requester: PluginId): MessageDispatchResult;
|
|
192
|
+
export declare function withRequestActionScope(request: IncomingRequest, dispatch: (request: IncomingRequest) => Promise<void>, assertOperation: () => void): Promise<void>;
|
|
193
|
+
export declare function handlers(snapshot: RuntimeSnapshot): HandlerIndex | undefined;
|
|
194
|
+
export declare function withEndpointEventPayload<TPayload, TClient, TName extends string>(source: EndpointEvent<unknown, TClient, TName>, payload: TPayload): EndpointEvent<TPayload, TClient, TName>;
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
import { bindOperationInput, operationInputBinding } from '@zhin.js/feature-kit';
|
|
2
|
+
import { formatCompact, getLogger } from '@zhin.js/logger';
|
|
3
|
+
import { isMiddlewareIndex, middlewareFeatureId, } from '@zhin.js/middleware';
|
|
4
|
+
import { createToken, projectLocaleToken, resolveLocale, userLocalePreferencesToken, } from '@zhin.js/plugin-runtime';
|
|
5
|
+
import { handlerFeatureId, isHandlerIndex } from '../../feature/handler.js';
|
|
6
|
+
import { RuntimeNotice } from '../../notice.js';
|
|
7
|
+
import { RuntimeRequest } from '../../request.js';
|
|
8
|
+
import { RuntimeSystemEvent } from '../../system-event.js';
|
|
9
|
+
import { RuntimeMessage, } from './contracts.js';
|
|
10
|
+
import { formatConversationLog } from './message-events.js';
|
|
11
|
+
export { arbitrateRoomInboundDeduplication, buildRoomInboundRouteInput, resolveRoomMembership, } from './inbound-dedup.js';
|
|
12
|
+
const logger = getLogger('im.inbound');
|
|
13
|
+
export const ingressRouteToken = createToken('zhin.im.ingress-route');
|
|
14
|
+
export function resolveIngressRoute(snapshot) {
|
|
15
|
+
const candidate = snapshot.resources.get(snapshot.root)?.get(ingressRouteToken.id);
|
|
16
|
+
return candidate
|
|
17
|
+
&& typeof candidate === 'object'
|
|
18
|
+
&& typeof candidate.route === 'function'
|
|
19
|
+
? candidate
|
|
20
|
+
: undefined;
|
|
21
|
+
}
|
|
22
|
+
/** @public */
|
|
23
|
+
export const groupRuleViolationToken = createToken('zhin.im.group-rule-violations');
|
|
24
|
+
/** @public */
|
|
25
|
+
export const memberWelcomeOwnerToken = createToken('zhin.im.member-welcome-owner');
|
|
26
|
+
/** Runs the generation-owned middleware projection or the terminal directly. */
|
|
27
|
+
export async function runRuntimeMiddleware(snapshot, input, terminal, target) {
|
|
28
|
+
const index = middlewareProjection(snapshot);
|
|
29
|
+
if (index)
|
|
30
|
+
await index.run(input, terminal, target, snapshot);
|
|
31
|
+
else
|
|
32
|
+
await terminal();
|
|
33
|
+
}
|
|
34
|
+
function middlewareProjection(snapshot) {
|
|
35
|
+
const projection = snapshot.projections.get(middlewareFeatureId);
|
|
36
|
+
return isMiddlewareIndex(projection) ? projection : undefined;
|
|
37
|
+
}
|
|
38
|
+
/** Legacy outbound middleware sees one complete reply unless its author explicitly supports revisions. */
|
|
39
|
+
export function supportsIncrementalOutbound(snapshot, adapter) {
|
|
40
|
+
return middlewareProjection(snapshot)?.list().every(record => record.target !== 'outbound'
|
|
41
|
+
|| record.adapter !== undefined && record.adapter !== adapter || record.incremental === true) ?? true;
|
|
42
|
+
}
|
|
43
|
+
export function projectLocale(snapshot) {
|
|
44
|
+
return resolveLocale(snapshot.resources.get(snapshot.root)?.get(projectLocaleToken.id)
|
|
45
|
+
?? snapshot.config.get(snapshot.root)?.locale);
|
|
46
|
+
}
|
|
47
|
+
/** Resolve once per operation; callbacks retain the original operation's language. */
|
|
48
|
+
export async function messageLocale(snapshot, conversation, senderId) {
|
|
49
|
+
const preferences = snapshot.resources.get(snapshot.root)?.get(userLocalePreferencesToken.id);
|
|
50
|
+
return senderId && preferences
|
|
51
|
+
? await preferences.get(conversation.endpoint, senderId) ?? projectLocale(snapshot)
|
|
52
|
+
: projectLocale(snapshot);
|
|
53
|
+
}
|
|
54
|
+
export async function executeInboundTurnSpine(envelope, control) {
|
|
55
|
+
const startedAt = Date.now();
|
|
56
|
+
const { message, lease, requester, conversationSequence, diagnostics } = envelope;
|
|
57
|
+
const turnId = envelope.turnId ?? `${message.id}:${conversationSequence ?? 0}`;
|
|
58
|
+
const finish = async (dispatch, stage, replied, reply) => {
|
|
59
|
+
const record = Object.freeze({
|
|
60
|
+
turnId,
|
|
61
|
+
conversation: message.conversation,
|
|
62
|
+
...(message.sender?.id ? { senderId: message.sender.id } : {}),
|
|
63
|
+
stage,
|
|
64
|
+
matched: dispatch.matched,
|
|
65
|
+
...(dispatch.command ? { command: dispatch.command } : {}),
|
|
66
|
+
...(dispatch.owner ? { owner: dispatch.owner } : {}),
|
|
67
|
+
replied,
|
|
68
|
+
durationMs: Math.max(0, Date.now() - startedAt),
|
|
69
|
+
});
|
|
70
|
+
await envelope.onTurnComplete?.(record);
|
|
71
|
+
return {
|
|
72
|
+
dispatch,
|
|
73
|
+
stage,
|
|
74
|
+
record,
|
|
75
|
+
...(reply ? { reply } : {}),
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
const ingressRoute = envelope.ingressRoute ?? resolveIngressRoute(lease.value);
|
|
79
|
+
const preRouted = await ingressRoute?.preRoute?.(message, lease, requester, conversationSequence) === true;
|
|
80
|
+
if (preRouted) {
|
|
81
|
+
diagnostics?.route('agent');
|
|
82
|
+
const dispatch = Object.freeze({ matched: true, command: 'pre-route', owner: requester });
|
|
83
|
+
const replied = envelope.hasReplied();
|
|
84
|
+
await control?.reportDispatch({
|
|
85
|
+
matched: true,
|
|
86
|
+
path: 'handler',
|
|
87
|
+
handlerId: 'pre-route',
|
|
88
|
+
replied,
|
|
89
|
+
});
|
|
90
|
+
return finish(dispatch, 'pre-route', replied);
|
|
91
|
+
}
|
|
92
|
+
if (ingressRoute?.shouldRouteBeforeDispatch?.(message) === true) {
|
|
93
|
+
const handled = await ingressRoute.route(message, lease, requester, conversationSequence);
|
|
94
|
+
if (handled) {
|
|
95
|
+
diagnostics?.route('agent');
|
|
96
|
+
const dispatch = Object.freeze({ matched: true, command: 'ai', owner: requester });
|
|
97
|
+
const replied = envelope.hasReplied();
|
|
98
|
+
await control?.reportDispatch({
|
|
99
|
+
matched: true,
|
|
100
|
+
path: 'handler',
|
|
101
|
+
handlerId: 'ai',
|
|
102
|
+
replied,
|
|
103
|
+
});
|
|
104
|
+
return finish(dispatch, 'before-dispatch-route', replied);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const repliedBeforeHandlers = envelope.hasReplied();
|
|
108
|
+
diagnostics?.step('handlers', 'started');
|
|
109
|
+
await envelope.runHandlers();
|
|
110
|
+
diagnostics?.step('handlers', 'completed');
|
|
111
|
+
const repliedDuringHandlers = !repliedBeforeHandlers && envelope.hasReplied();
|
|
112
|
+
const interactive = await envelope.dispatchInteractive();
|
|
113
|
+
if (interactive)
|
|
114
|
+
diagnostics?.route('interaction');
|
|
115
|
+
const dispatched = interactive
|
|
116
|
+
? undefined
|
|
117
|
+
: await envelope.dispatchCommand((stage, status) => diagnostics?.step(stage, status));
|
|
118
|
+
let result = interactive ?? dispatched.dispatch;
|
|
119
|
+
let stage = interactive
|
|
120
|
+
? 'interactive'
|
|
121
|
+
: dispatched?.dispatch.matched
|
|
122
|
+
? 'command'
|
|
123
|
+
: 'none';
|
|
124
|
+
if (!result.matched && ingressRoute) {
|
|
125
|
+
logger.debug(formatCompact({
|
|
126
|
+
op: 'unmatched',
|
|
127
|
+
conv: formatConversationLog(message.conversation),
|
|
128
|
+
}));
|
|
129
|
+
const handled = await ingressRoute.route(message, lease, requester, conversationSequence);
|
|
130
|
+
if (handled) {
|
|
131
|
+
diagnostics?.route('agent');
|
|
132
|
+
result = Object.freeze({ matched: true, command: 'ai', owner: requester });
|
|
133
|
+
stage = 'agent-ingress';
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
const response = dispatched?.reply ?? (interactive?.value !== undefined && interactive.owner
|
|
137
|
+
? { owner: interactive.owner, content: interactive.value }
|
|
138
|
+
: undefined);
|
|
139
|
+
const replied = envelope.hasReplied() || response !== undefined;
|
|
140
|
+
if (interactive) {
|
|
141
|
+
await control?.reportDispatch({
|
|
142
|
+
matched: true,
|
|
143
|
+
path: 'button',
|
|
144
|
+
handlerId: interactive.command ?? 'interactive',
|
|
145
|
+
replied,
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
else if (dispatched?.dispatch.matched) {
|
|
149
|
+
await control?.reportDispatch({
|
|
150
|
+
matched: true,
|
|
151
|
+
path: 'command',
|
|
152
|
+
...(dispatched.dispatch.command ? { handlerId: dispatched.dispatch.command } : {}),
|
|
153
|
+
replied,
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
else if (result.matched) {
|
|
157
|
+
await control?.reportDispatch({
|
|
158
|
+
matched: true,
|
|
159
|
+
path: 'handler',
|
|
160
|
+
...(result.command ? { handlerId: result.command } : {}),
|
|
161
|
+
replied,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
else if (repliedDuringHandlers) {
|
|
165
|
+
stage = 'handlers';
|
|
166
|
+
const handlerName = envelope.findEventHandlerName?.('message.receive') ?? 'message.receive';
|
|
167
|
+
await control?.reportDispatch({
|
|
168
|
+
matched: true,
|
|
169
|
+
path: 'handler',
|
|
170
|
+
handlerId: handlerName,
|
|
171
|
+
replied: true,
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
await control?.reportDispatch({
|
|
176
|
+
matched: false,
|
|
177
|
+
path: 'none',
|
|
178
|
+
replied,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
return finish(result, stage, replied, response);
|
|
182
|
+
}
|
|
183
|
+
export async function runInboundMiddlewareAndSpine(envelope, diagnostics) {
|
|
184
|
+
const { message, lease } = envelope;
|
|
185
|
+
const terminal = (control) => executeInboundTurnSpine(envelope, control);
|
|
186
|
+
const middleware = lease.value.projections.get(middlewareFeatureId);
|
|
187
|
+
if (isMiddlewareIndex(middleware))
|
|
188
|
+
diagnostics?.step('middleware', 'entered');
|
|
189
|
+
const outcome = isMiddlewareIndex(middleware)
|
|
190
|
+
? await middleware.runInbound(message, terminal, {
|
|
191
|
+
stop: (owner) => {
|
|
192
|
+
diagnostics?.route('middleware');
|
|
193
|
+
diagnostics?.step('middleware', 'stopped');
|
|
194
|
+
return { dispatch: { matched: true, command: 'middleware', owner } };
|
|
195
|
+
},
|
|
196
|
+
replace: (owner, value, downstream) => {
|
|
197
|
+
diagnostics?.step('middleware', 'replaced');
|
|
198
|
+
if (!downstream?.dispatch.matched)
|
|
199
|
+
diagnostics?.route('middleware');
|
|
200
|
+
return {
|
|
201
|
+
dispatch: downstream?.dispatch.matched
|
|
202
|
+
? downstream.dispatch
|
|
203
|
+
: { matched: true, command: 'middleware', owner },
|
|
204
|
+
reply: { owner, content: value },
|
|
205
|
+
};
|
|
206
|
+
},
|
|
207
|
+
}, lease.value)
|
|
208
|
+
: await terminal();
|
|
209
|
+
if (isMiddlewareIndex(middleware))
|
|
210
|
+
diagnostics?.step('middleware', 'completed');
|
|
211
|
+
return outcome;
|
|
212
|
+
}
|
|
213
|
+
export async function dispatchInboundHandlers({ lease, event, args, signal = lease.stopSignal, interactions, deliver, captureInteraction, }) {
|
|
214
|
+
const snapshot = lease.value;
|
|
215
|
+
const index = handlers(snapshot);
|
|
216
|
+
if (!index)
|
|
217
|
+
return;
|
|
218
|
+
const options = {
|
|
219
|
+
snapshot,
|
|
220
|
+
signal,
|
|
221
|
+
resolveInteraction: (name, interactionArgs, owner) => {
|
|
222
|
+
const eventContext = interactionArgs[0];
|
|
223
|
+
const payload = eventContext?.payload;
|
|
224
|
+
if (name === 'message.receive' && payload instanceof RuntimeMessage) {
|
|
225
|
+
return interactions.createFromUnknown(bindOperationInput(payload, owner, snapshot));
|
|
226
|
+
}
|
|
227
|
+
if (name === 'notice.receive' || name === 'request.receive') {
|
|
228
|
+
return createInteractionForSideEvent({
|
|
229
|
+
payload: payload,
|
|
230
|
+
snapshot,
|
|
231
|
+
requester: owner,
|
|
232
|
+
signal,
|
|
233
|
+
interactions,
|
|
234
|
+
deliver,
|
|
235
|
+
...(captureInteraction ? { retain: () => captureInteraction(owner, payload.conversation) } : {}),
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
return undefined;
|
|
239
|
+
},
|
|
240
|
+
};
|
|
241
|
+
await index.dispatch(event, args, options);
|
|
242
|
+
}
|
|
243
|
+
export function createInteractionForSideEvent({ payload, snapshot, requester, signal, interactions, deliver, retain, }) {
|
|
244
|
+
const conversation = payload.conversation;
|
|
245
|
+
if (!conversation)
|
|
246
|
+
return undefined;
|
|
247
|
+
const source = Object.freeze({
|
|
248
|
+
conversation,
|
|
249
|
+
...(payload.actor?.id
|
|
250
|
+
? { sender: Object.freeze({ id: payload.actor.id }) }
|
|
251
|
+
: {}),
|
|
252
|
+
$reply: (content) => deliver({
|
|
253
|
+
conversation,
|
|
254
|
+
requester,
|
|
255
|
+
content,
|
|
256
|
+
}, snapshot),
|
|
257
|
+
});
|
|
258
|
+
return interactions.create(source, undefined, { snapshot, owner: requester, signal, retain });
|
|
259
|
+
}
|
|
260
|
+
export async function dispatchInboundInteractive({ message, requester, admission, snapshot, interactions, }) {
|
|
261
|
+
const handled = await interactions.dispatch(message, admission, snapshot);
|
|
262
|
+
return handled
|
|
263
|
+
? Object.freeze({ matched: true, command: 'interactive', owner: requester })
|
|
264
|
+
: undefined;
|
|
265
|
+
}
|
|
266
|
+
export async function dispatchCanonicalEndpointEvent(input) {
|
|
267
|
+
const { source, context, assertActive, recordNotice, recordRequest, dispatch } = input;
|
|
268
|
+
if (source.payload.type !== source.name.split('.')[0]) {
|
|
269
|
+
throw new TypeError('Endpoint event payload type does not match its gateway event');
|
|
270
|
+
}
|
|
271
|
+
switch (source.payload.type) {
|
|
272
|
+
case 'notice': {
|
|
273
|
+
const notice = new RuntimeNotice(source.payload, context);
|
|
274
|
+
await recordNotice(notice);
|
|
275
|
+
await dispatch(notice);
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
case 'request':
|
|
279
|
+
await withRequestActionScope(source.payload, async (reqInput) => {
|
|
280
|
+
const request = new RuntimeRequest(reqInput, context);
|
|
281
|
+
const recording = Promise.resolve(recordRequest?.(request)).catch(() => undefined);
|
|
282
|
+
try {
|
|
283
|
+
await dispatch(request);
|
|
284
|
+
}
|
|
285
|
+
finally {
|
|
286
|
+
await recording;
|
|
287
|
+
}
|
|
288
|
+
}, assertActive);
|
|
289
|
+
break;
|
|
290
|
+
case 'system':
|
|
291
|
+
await dispatch(new RuntimeSystemEvent(source.payload, context));
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
export function interactionResult(requester) {
|
|
296
|
+
return Object.freeze({ matched: true, command: 'interaction', owner: requester });
|
|
297
|
+
}
|
|
298
|
+
export async function withRequestActionScope(request, dispatch, assertOperation) {
|
|
299
|
+
let active = true;
|
|
300
|
+
const actions = new Set();
|
|
301
|
+
const run = (action) => {
|
|
302
|
+
if (!active)
|
|
303
|
+
throw new Error('Request action port expired with its generation operation');
|
|
304
|
+
const operation = Promise.resolve().then(() => { assertOperation(); return action(); });
|
|
305
|
+
actions.add(operation);
|
|
306
|
+
void operation.then(() => actions.delete(operation), () => actions.delete(operation));
|
|
307
|
+
return operation;
|
|
308
|
+
};
|
|
309
|
+
const scoped = Object.freeze({ ...request,
|
|
310
|
+
$approve: async (remark) => run(() => request.$approve(remark)),
|
|
311
|
+
$reject: async (reason) => run(() => request.$reject(reason)),
|
|
312
|
+
});
|
|
313
|
+
try {
|
|
314
|
+
await dispatch(scoped);
|
|
315
|
+
}
|
|
316
|
+
finally {
|
|
317
|
+
active = false;
|
|
318
|
+
await Promise.allSettled([...actions]);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
export function handlers(snapshot) {
|
|
322
|
+
const projection = snapshot.projections.get(handlerFeatureId);
|
|
323
|
+
return isHandlerIndex(projection) ? projection : undefined;
|
|
324
|
+
}
|
|
325
|
+
export function withEndpointEventPayload(source, payload) {
|
|
326
|
+
return Object.freeze({
|
|
327
|
+
name: source.name,
|
|
328
|
+
payload,
|
|
329
|
+
endpoint: source.endpoint,
|
|
330
|
+
client: source.client,
|
|
331
|
+
[operationInputBinding]: (owner, snapshot) => withEndpointEventPayload(source, bindOperationInput(payload, owner, snapshot)),
|
|
332
|
+
});
|
|
333
|
+
}
|
|
@@ -1,20 +1,18 @@
|
|
|
1
1
|
export * from './contracts.js';
|
|
2
2
|
export { EndpointRuntime } from './endpoint-runtime.js';
|
|
3
3
|
export type { CaptureEndpointOperationInput, CapturedEndpointOperation, EndpointRuntimeDetail, EndpointRuntimeSummary, RuntimeEndpointEditInput, RuntimeEndpointMessageInput, RuntimeEndpointReactionInput, RuntimeEndpointRemoveReactionInput, RuntimeEndpointSendInput, RuntimeEndpointTypingInput, } from './endpoint-runtime.js';
|
|
4
|
-
export * from './
|
|
4
|
+
export * from './inbound-spine.js';
|
|
5
|
+
export * from './host/index.js';
|
|
5
6
|
export { isMessageOrigin, roomMembershipToken } from './inbound-origin.js';
|
|
6
7
|
export type { MessageOrigin, RoomInboundRouteInput, RoomMembershipPort, RoomRouteDecision, } from './inbound-origin.js';
|
|
7
8
|
export * from './im-runtime.js';
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './login-assist-host.js';
|
|
10
|
-
export * from './group-rule-violation.js';
|
|
11
|
-
export * from './member-welcome.js';
|
|
12
|
-
export * from './message-bus.js';
|
|
9
|
+
export * from './command-feedback.js';
|
|
13
10
|
export * from './message-dispatcher.js';
|
|
14
11
|
export type { RuntimeMessageDiagnostic, RuntimeMessageDiagnosticStep, RuntimeMessageDiagnosticDelivery, RuntimeMessageDiagnosticsReader, } from './message-diagnostics.js';
|
|
15
|
-
export type
|
|
12
|
+
export { MessageBus, messageBusToken, type EndpointEvent, type MessageBusEventMap, type MessageBusEventName, type RuntimeMessageEvent, type RuntimeMessageEventSource, type RuntimeMessageRendering, type RuntimeSceneEventSignal, type RuntimeSceneEventSource, type OutboundFallbackReason, } from './message-events.js';
|
|
16
13
|
export * from './outbound-renderer.js';
|
|
17
14
|
export * from './outbound-segments.js';
|
|
15
|
+
export { renderToSegments, isNativeMessageTag, type MessageRenderOptions } from '../../jsx/message-renderer.js';
|
|
18
16
|
export type { CoreReplyStream, OpenReplyStreamOptions, ReplyStreamSnapshot, ConfirmedReplyContent } from './progressive-reply.js';
|
|
19
17
|
export * from '../../notice.js';
|
|
20
18
|
export * from '../../request.js';
|
|
@@ -1,16 +1,15 @@
|
|
|
1
1
|
export * from './contracts.js';
|
|
2
2
|
export { EndpointRuntime } from './endpoint-runtime.js';
|
|
3
|
-
export * from './
|
|
3
|
+
export * from './inbound-spine.js';
|
|
4
|
+
export * from './host/index.js';
|
|
4
5
|
export { isMessageOrigin, roomMembershipToken } from './inbound-origin.js';
|
|
5
6
|
export * from './im-runtime.js';
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './login-assist-host.js';
|
|
8
|
-
export * from './group-rule-violation.js';
|
|
9
|
-
export * from './member-welcome.js';
|
|
10
|
-
export * from './message-bus.js';
|
|
7
|
+
export * from './command-feedback.js';
|
|
11
8
|
export * from './message-dispatcher.js';
|
|
9
|
+
export { MessageBus, messageBusToken, } from './message-events.js';
|
|
12
10
|
export * from './outbound-renderer.js';
|
|
13
11
|
export * from './outbound-segments.js';
|
|
12
|
+
export { renderToSegments, isNativeMessageTag } from '../../jsx/message-renderer.js';
|
|
14
13
|
export * from '../../notice.js';
|
|
15
14
|
export * from '../../request.js';
|
|
16
15
|
export * from '../../system-event.js';
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import { type RuntimeSnapshot, type Locale } from '@zhin.js/plugin-runtime';
|
|
2
|
-
import { type ConversationRef, type DeliveryReceipt, type MessageRef } from '@zhin.js/im-contract';
|
|
3
|
-
import type
|
|
4
|
-
import {
|
|
5
|
-
import { type InteractionOperationScope } from './interaction-operation.js';
|
|
6
|
-
import { RuntimeInteractiveRouter, type RememberFallbackContext } from './interactive-router.js';
|
|
2
|
+
import { type ConversationRef, type DeliveryReceipt, type MessageRef, type UserInteraction } from '@zhin.js/im-contract';
|
|
3
|
+
import { type InteractionOperationScope, type Message, type MessageSenderRef, type SendContent, type SendRequest } from './contracts.js';
|
|
4
|
+
import { RuntimeInteractiveRouter, type JsxButtonBatch, type PluginIncarnationRef, type RememberFallbackContext } from './interactive-router.js';
|
|
7
5
|
import type { Segment } from '../../built/segment-contract/types.js';
|
|
8
|
-
|
|
9
|
-
export { isPluginIncarnationAlive, type PluginIncarnationRef } from './jsx-button-registry.js';
|
|
6
|
+
export { isPluginIncarnationAlive, type PluginIncarnationRef } from './interactive-router.js';
|
|
10
7
|
/** A live conversational prompt; its callbacks still require the original subject and generation. */
|
|
11
8
|
export interface PendingUserInteraction {
|
|
12
9
|
readonly id: string;
|
|
@@ -1,15 +1,12 @@
|
|
|
1
1
|
import { resolveLocale } from '@zhin.js/plugin-runtime';
|
|
2
2
|
import { interactionMessages as t } from '../../built/interaction-messages.js';
|
|
3
|
-
import { projectLocale } from './
|
|
4
|
-
import { conversationRefKey } from '@zhin.js/im-contract';
|
|
3
|
+
import { projectLocale } from './inbound-spine.js';
|
|
4
|
+
import { conversationRefKey, } from '@zhin.js/im-contract';
|
|
5
5
|
import { assertUserInteractionRequest, parseUserInteractionAnswer, projectUserInteraction, renderUserInteraction, } from '../../built/user-interaction.js';
|
|
6
6
|
import { randomUUID } from 'node:crypto';
|
|
7
|
-
import { RuntimeMessage } from './contracts.js';
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
import { actionPayloadFromSegments, RuntimeInteractiveRouter, } from './interactive-router.js';
|
|
11
|
-
import { isJsxButtonPayload, isPluginIncarnationAlive, JsxButtonRegistry, } from './jsx-button-registry.js';
|
|
12
|
-
export { isPluginIncarnationAlive } from './jsx-button-registry.js';
|
|
7
|
+
import { RuntimeMessage, interactionOperationScope, operationEndpoint, } from './contracts.js';
|
|
8
|
+
import { actionPayloadFromSegments, isJsxButtonPayload, isPluginIncarnationAlive, JsxButtonRegistry, RuntimeInteractiveRouter, } from './interactive-router.js';
|
|
9
|
+
export { isPluginIncarnationAlive } from './interactive-router.js';
|
|
13
10
|
const ASK_ACTION_PREFIX = 'zhin:ask:';
|
|
14
11
|
class UserInteractionTimeoutError extends Error {
|
|
15
12
|
constructor(message) {
|
|
@@ -1,9 +1,35 @@
|
|
|
1
1
|
import { type ConversationRef } from '@zhin.js/im-contract';
|
|
2
|
-
import type { RuntimeSnapshot } from '@zhin.js/plugin-runtime';
|
|
2
|
+
import type { PluginId, PluginNodeSnapshot, RuntimeSnapshot } from '@zhin.js/plugin-runtime';
|
|
3
3
|
import type { Segment } from '../../built/segment-contract/types.js';
|
|
4
|
-
import type {
|
|
5
|
-
import { type
|
|
6
|
-
export
|
|
4
|
+
import type { ButtonProps } from '../../jsx/message-tags.js';
|
|
5
|
+
import { type Message, type SendRequest } from './contracts.js';
|
|
6
|
+
export declare function isJsxButtonPayload(payload: string | undefined): boolean;
|
|
7
|
+
export interface PluginIncarnationRef {
|
|
8
|
+
readonly requester: PluginId;
|
|
9
|
+
readonly snapshot: RuntimeSnapshot;
|
|
10
|
+
readonly node: PluginNodeSnapshot | undefined;
|
|
11
|
+
readonly signal?: AbortSignal;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Checks whether the plugin incarnation that registered a callback/interaction
|
|
15
|
+
* is still live in `currentSnapshot`.
|
|
16
|
+
* Survives HMR of unrelated plugins (where another plugin's node in `tree` changed
|
|
17
|
+
* while `origin.node` is unchanged), while retiring if the owning plugin was reloaded/removed,
|
|
18
|
+
* its endpoint signal aborted, or the runtime performed a full-generation retirement.
|
|
19
|
+
*/
|
|
20
|
+
export declare function isPluginIncarnationAlive(origin: PluginIncarnationRef, currentSnapshot: RuntimeSnapshot): boolean;
|
|
21
|
+
export interface JsxButtonBatch {
|
|
22
|
+
bind(props: ButtonProps): Segment;
|
|
23
|
+
/** Publish callbacks immediately before transport; revoke them on definitive non-delivery. */
|
|
24
|
+
activate(payloads: ReadonlySet<string>): () => void;
|
|
25
|
+
}
|
|
26
|
+
/** Plugin-incarnation-owned callbacks: survive unrelated plugin HMR; retired when owning plugin reloads. */
|
|
27
|
+
export declare class JsxButtonRegistry {
|
|
28
|
+
#private;
|
|
29
|
+
prepare(request: SendRequest, snapshot: RuntimeSnapshot): JsxButtonBatch;
|
|
30
|
+
dispatch(message: Message, payload: string, snapshot: RuntimeSnapshot): Promise<boolean>;
|
|
31
|
+
}
|
|
32
|
+
export declare function collectButtonPayloads(payload: unknown): Set<string>;
|
|
7
33
|
type RuntimeInteractiveHandler = (message: Message) => Promise<boolean> | boolean;
|
|
8
34
|
export interface InteractiveRouterOptions {
|
|
9
35
|
readonly fallbackTtlMs?: number;
|
|
@@ -52,3 +78,4 @@ export declare class RuntimeInteractiveRouter<Admission = never> {
|
|
|
52
78
|
}
|
|
53
79
|
/** @internal Payload of the first action segment (platform callback) that carries a non-empty string. */
|
|
54
80
|
export declare function actionPayloadFromSegments(segments: readonly Segment[] | undefined): string | undefined;
|
|
81
|
+
export {};
|