@zhin.js/core 1.1.57 → 1.1.58
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 +74 -411
- 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 +4 -7
- package/lib/plugin-runtime/im/index.js +4 -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
|
@@ -1,7 +1,139 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
import { bindOperationInput } from '@zhin.js/feature-kit';
|
|
1
3
|
import { conversationRefKey } from '@zhin.js/im-contract';
|
|
4
|
+
import { jsx } from '@zhin.js/jsx';
|
|
5
|
+
import { interactionMessages as t } from '../../built/interaction-messages.js';
|
|
2
6
|
import { resolvePayloadFromText } from '../../built/interactive-segments/action.js';
|
|
3
|
-
import {
|
|
4
|
-
|
|
7
|
+
import { isKeyboardSegment } from '../../built/interactive-segments/types.js';
|
|
8
|
+
import { operationEndpoint } from './contracts.js';
|
|
9
|
+
const JSX_BUTTON_PREFIX = 'zhin:jsx:';
|
|
10
|
+
const JSX_BUTTON_TTL_MS = 60 * 60 * 1000;
|
|
11
|
+
export function isJsxButtonPayload(payload) {
|
|
12
|
+
return payload?.startsWith(JSX_BUTTON_PREFIX) === true;
|
|
13
|
+
}
|
|
14
|
+
function hasIdenticalPluginTree(left, right) {
|
|
15
|
+
if (left === right)
|
|
16
|
+
return true;
|
|
17
|
+
if (left.size !== right.size)
|
|
18
|
+
return false;
|
|
19
|
+
for (const [id, node] of left) {
|
|
20
|
+
if (right.get(id) !== node)
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Checks whether the plugin incarnation that registered a callback/interaction
|
|
27
|
+
* is still live in `currentSnapshot`.
|
|
28
|
+
* Survives HMR of unrelated plugins (where another plugin's node in `tree` changed
|
|
29
|
+
* while `origin.node` is unchanged), while retiring if the owning plugin was reloaded/removed,
|
|
30
|
+
* its endpoint signal aborted, or the runtime performed a full-generation retirement.
|
|
31
|
+
*/
|
|
32
|
+
export function isPluginIncarnationAlive(origin, currentSnapshot) {
|
|
33
|
+
if (origin.signal?.aborted) {
|
|
34
|
+
return false;
|
|
35
|
+
}
|
|
36
|
+
if (origin.snapshot === currentSnapshot) {
|
|
37
|
+
return true;
|
|
38
|
+
}
|
|
39
|
+
if (!origin.node || hasIdenticalPluginTree(origin.snapshot.tree, currentSnapshot.tree)) {
|
|
40
|
+
return false;
|
|
41
|
+
}
|
|
42
|
+
const currentNode = currentSnapshot.tree.get(origin.requester);
|
|
43
|
+
return currentNode !== undefined && currentNode === origin.node;
|
|
44
|
+
}
|
|
45
|
+
/** Plugin-incarnation-owned callbacks: survive unrelated plugin HMR; retired when owning plugin reloads. */
|
|
46
|
+
export class JsxButtonRegistry {
|
|
47
|
+
#bindings = new Map();
|
|
48
|
+
prepare(request, snapshot) {
|
|
49
|
+
const pending = new Map();
|
|
50
|
+
const node = snapshot.tree.get(request.requester);
|
|
51
|
+
const signal = request[operationEndpoint]?.signal;
|
|
52
|
+
return {
|
|
53
|
+
bind: (props) => {
|
|
54
|
+
const { onClick, payload: manualPayload, children, label, id, ...options } = props;
|
|
55
|
+
if (onClick !== undefined && typeof onClick !== 'function')
|
|
56
|
+
throw new TypeError('Button onClick must be a function');
|
|
57
|
+
if (onClick && manualPayload !== undefined)
|
|
58
|
+
throw new TypeError('Button accepts onClick or payload, not both');
|
|
59
|
+
if (!onClick && typeof manualPayload !== 'string')
|
|
60
|
+
throw new TypeError('Button requires onClick or payload');
|
|
61
|
+
const payload = onClick ? `${JSX_BUTTON_PREFIX}${randomUUID()}` : manualPayload;
|
|
62
|
+
if (onClick && !props.disabled)
|
|
63
|
+
pending.set(payload, {
|
|
64
|
+
onClick,
|
|
65
|
+
requester: request.requester,
|
|
66
|
+
snapshot,
|
|
67
|
+
node,
|
|
68
|
+
...(signal ? { signal } : {}),
|
|
69
|
+
conversationKey: conversationRefKey(request.conversation),
|
|
70
|
+
expiresAt: 0,
|
|
71
|
+
});
|
|
72
|
+
return { type: 'keyboard', data: { rows: [[{
|
|
73
|
+
...options,
|
|
74
|
+
id: id ?? randomUUID(),
|
|
75
|
+
label: label ?? children,
|
|
76
|
+
payload,
|
|
77
|
+
...(onClick ? { mode: 'callback' } : {}),
|
|
78
|
+
}]] } };
|
|
79
|
+
},
|
|
80
|
+
activate: (payloads) => {
|
|
81
|
+
const activated = [];
|
|
82
|
+
this.#prune(snapshot);
|
|
83
|
+
for (const [payload, binding] of pending) {
|
|
84
|
+
if (!payloads.has(payload))
|
|
85
|
+
continue;
|
|
86
|
+
this.#bindings.set(payload, { ...binding, expiresAt: Date.now() + JSX_BUTTON_TTL_MS });
|
|
87
|
+
activated.push(payload);
|
|
88
|
+
}
|
|
89
|
+
pending.clear();
|
|
90
|
+
return () => { for (const payload of activated)
|
|
91
|
+
this.#bindings.delete(payload); };
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
async dispatch(message, payload, snapshot) {
|
|
96
|
+
if (!isJsxButtonPayload(payload))
|
|
97
|
+
return false;
|
|
98
|
+
this.#prune(snapshot);
|
|
99
|
+
const binding = this.#bindings.get(payload);
|
|
100
|
+
// Never invoke a retired closure. The reply uses this incoming operation's scope.
|
|
101
|
+
if (!binding || !isPluginIncarnationAlive(binding, snapshot)) {
|
|
102
|
+
if (binding)
|
|
103
|
+
this.#bindings.delete(payload);
|
|
104
|
+
await message.$reply(t(message.locale, 'expired'));
|
|
105
|
+
return true;
|
|
106
|
+
}
|
|
107
|
+
if (binding.conversationKey !== conversationRefKey(message.conversation))
|
|
108
|
+
return true;
|
|
109
|
+
const bound = bindOperationInput(message, binding.requester, snapshot);
|
|
110
|
+
const content = await binding.onClick(bound);
|
|
111
|
+
if (typeof content === 'number')
|
|
112
|
+
await bound.$reply(jsx('text', { text: String(content) }));
|
|
113
|
+
else if (content != null && typeof content !== 'boolean')
|
|
114
|
+
await bound.$reply(content);
|
|
115
|
+
return true;
|
|
116
|
+
}
|
|
117
|
+
#prune(currentSnapshot) {
|
|
118
|
+
const now = Date.now();
|
|
119
|
+
for (const [payload, binding] of this.#bindings) {
|
|
120
|
+
if (binding.expiresAt <= now || (currentSnapshot && !isPluginIncarnationAlive(binding, currentSnapshot))) {
|
|
121
|
+
this.#bindings.delete(payload);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
export function collectButtonPayloads(payload) {
|
|
127
|
+
const result = new Set();
|
|
128
|
+
for (const item of Array.isArray(payload) ? payload : [payload]) {
|
|
129
|
+
if (isKeyboardSegment(item)) {
|
|
130
|
+
for (const row of item.data.rows)
|
|
131
|
+
for (const button of row)
|
|
132
|
+
result.add(button.payload);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return result;
|
|
136
|
+
}
|
|
5
137
|
const DEFAULT_FALLBACK_TTL_MS = 60 * 60 * 1000;
|
|
6
138
|
const MAX_EXPIRED_BATCHES = 1000;
|
|
7
139
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { UserInteractionFactory } from '@zhin.js/
|
|
1
|
+
import type { UserInteractionFactory } from '@zhin.js/im-contract';
|
|
2
2
|
import type { PluginId, RuntimeSnapshot } from '@zhin.js/plugin-runtime';
|
|
3
3
|
import type { Message, MessageDispatchResult, SendContent } from './contracts.js';
|
|
4
4
|
/**
|
|
@@ -2,8 +2,7 @@ import { readOperationInputResources } from '@zhin.js/feature-kit';
|
|
|
2
2
|
import { adapterFeatureId, isAdapterIndex } from '@zhin.js/adapter';
|
|
3
3
|
import { commandFeatureId, isCommandIndex, } from '@zhin.js/command';
|
|
4
4
|
import { formatCompact, getLogger, truncatePreview } from '@zhin.js/logger';
|
|
5
|
-
import { renderCommandFeedback } from './command-feedback.js';
|
|
6
|
-
import { commandMenuReply } from './command-menu-navigation.js';
|
|
5
|
+
import { commandMenuReply, renderCommandFeedback } from './command-feedback.js';
|
|
7
6
|
const logger = getLogger('command');
|
|
8
7
|
function dispatchOutcome(result, replyOwner = result.owner) {
|
|
9
8
|
return { dispatch: result, ...(result.value !== undefined && replyOwner
|
|
@@ -1,6 +1,36 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type { ConversationRef } from '@zhin.js/im-contract';
|
|
3
|
-
import type { MessageSenderRef } from './contracts.js';
|
|
1
|
+
import { type PluginId } from '@zhin.js/plugin-runtime';
|
|
2
|
+
import type { ConversationRef, DeliveryReceipt } from '@zhin.js/im-contract';
|
|
3
|
+
import type { Message, MessageSenderRef, OutboundEnvelope, SendContent } from './contracts.js';
|
|
4
|
+
export interface EndpointEvent {
|
|
5
|
+
readonly adapter: string;
|
|
6
|
+
readonly endpointKey: string;
|
|
7
|
+
readonly error?: Error;
|
|
8
|
+
}
|
|
9
|
+
export interface MessageBusEventMap {
|
|
10
|
+
'message.receive': [message: Message];
|
|
11
|
+
'before.sendMessage': [envelope: OutboundEnvelope];
|
|
12
|
+
'message.send': [payload: {
|
|
13
|
+
adapter: string;
|
|
14
|
+
endpointKey: string;
|
|
15
|
+
content: SendContent;
|
|
16
|
+
receipt: DeliveryReceipt;
|
|
17
|
+
}];
|
|
18
|
+
'endpoint.connect': [event: EndpointEvent];
|
|
19
|
+
'endpoint.disconnect': [event: EndpointEvent];
|
|
20
|
+
'endpoint.error': [event: EndpointEvent];
|
|
21
|
+
}
|
|
22
|
+
export type MessageBusEventName = keyof MessageBusEventMap;
|
|
23
|
+
export declare class MessageBus {
|
|
24
|
+
private readonly emitter;
|
|
25
|
+
constructor();
|
|
26
|
+
on<E extends MessageBusEventName>(event: E, listener: (...args: MessageBusEventMap[E]) => void): () => void;
|
|
27
|
+
once<E extends MessageBusEventName>(event: E, listener: (...args: MessageBusEventMap[E]) => void): () => void;
|
|
28
|
+
emit<E extends MessageBusEventName>(event: E, ...args: MessageBusEventMap[E]): void;
|
|
29
|
+
off<E extends MessageBusEventName>(event: E, listener: (...args: MessageBusEventMap[E]) => void): void;
|
|
30
|
+
listenerCount(event: MessageBusEventName): number;
|
|
31
|
+
removeAllListeners(event?: MessageBusEventName): void;
|
|
32
|
+
}
|
|
33
|
+
export declare const messageBusToken: import("@zhin.js/plugin-runtime").Token<MessageBus>;
|
|
4
34
|
export type OutboundFallbackReason = 'renderer_unavailable' | 'renderer_failed' | 'media_unsupported' | 'html_text_policy' | 'markdown_text_policy' | 'interactive_text_policy';
|
|
5
35
|
/** Final payload handed to the Endpoint, not a claim about the remote client's display. */
|
|
6
36
|
export interface RuntimeMessageRendering {
|
|
@@ -1,3 +1,37 @@
|
|
|
1
|
+
import { EventEmitter } from 'node:events';
|
|
2
|
+
import { createToken } from '@zhin.js/plugin-runtime';
|
|
3
|
+
export class MessageBus {
|
|
4
|
+
emitter = new EventEmitter();
|
|
5
|
+
constructor() {
|
|
6
|
+
this.emitter.setMaxListeners(50);
|
|
7
|
+
}
|
|
8
|
+
on(event, listener) {
|
|
9
|
+
this.emitter.on(event, listener);
|
|
10
|
+
return () => this.emitter.off(event, listener);
|
|
11
|
+
}
|
|
12
|
+
once(event, listener) {
|
|
13
|
+
this.emitter.once(event, listener);
|
|
14
|
+
return () => this.emitter.off(event, listener);
|
|
15
|
+
}
|
|
16
|
+
emit(event, ...args) {
|
|
17
|
+
this.emitter.emit(event, ...args);
|
|
18
|
+
}
|
|
19
|
+
off(event, listener) {
|
|
20
|
+
this.emitter.off(event, listener);
|
|
21
|
+
}
|
|
22
|
+
listenerCount(event) {
|
|
23
|
+
return this.emitter.listenerCount(event);
|
|
24
|
+
}
|
|
25
|
+
removeAllListeners(event) {
|
|
26
|
+
if (event) {
|
|
27
|
+
this.emitter.removeAllListeners(event);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
this.emitter.removeAllListeners();
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
export const messageBusToken = createToken('zhin.im.message-bus');
|
|
1
35
|
const messagePreviewLimit = 200;
|
|
2
36
|
/** Owns one ImRuntime's observer subscriptions without exposing publication authority. */
|
|
3
37
|
export class RuntimeMessageEventStream {
|
|
@@ -3,8 +3,7 @@ import { type ConversationRef, type DeliveryReceipt, type DeliveryPart, type End
|
|
|
3
3
|
import { type SendRequest } from './contracts.js';
|
|
4
4
|
import { OutboundRenderer } from './outbound-renderer.js';
|
|
5
5
|
import { type RuntimeMessageEvent } from './message-events.js';
|
|
6
|
-
import { type JsxButtonBatch, type PluginIncarnationRef } from './
|
|
7
|
-
import type { RememberFallbackContext } from './interactive-router.js';
|
|
6
|
+
import { type JsxButtonBatch, type PluginIncarnationRef, type RememberFallbackContext } from './interactive-router.js';
|
|
8
7
|
import type { RuntimeMessageDiagnostics } from './message-diagnostics.js';
|
|
9
8
|
interface OutboundDeliveryContext {
|
|
10
9
|
readonly diagnostics?: RuntimeMessageDiagnostics;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import {
|
|
3
|
-
import { projectLocale } from './locale.js';
|
|
2
|
+
import { projectLocale, runRuntimeMiddleware } from './inbound-spine.js';
|
|
4
3
|
import { resolveLocale, } from '@zhin.js/plugin-runtime';
|
|
5
4
|
import { EndpointDeliveryError } from '@zhin.js/im-contract';
|
|
6
5
|
import { isCanonicalSegment } from '../../built/segment-contract/assert.js';
|
|
@@ -8,15 +7,12 @@ import { collectSegmentMedia } from '../../built/segment-contract/media.js';
|
|
|
8
7
|
import { isStrictCanonicalSegment } from '../../built/segment-contract/validate.js';
|
|
9
8
|
import { formatCompact, getLogger } from '@zhin.js/logger';
|
|
10
9
|
import { isJsxElement } from '@zhin.js/jsx';
|
|
11
|
-
import { createOutboundEnvelope, isComponentCall, isRawContent } from './contracts.js';
|
|
12
|
-
import { OutboundRenderer } from './outbound-renderer.js';
|
|
13
|
-
import { projectOutboundPayload } from './outbound-projection.js';
|
|
10
|
+
import { createOutboundEnvelope, isComponentCall, isRawContent, operationEndpoint } from './contracts.js';
|
|
11
|
+
import { OutboundRenderer, projectOutboundPayload, resolveOutboundPresentation } from './outbound-renderer.js';
|
|
14
12
|
import { flattenOutboundArray } from '../../built/outbound-content-arrays.js';
|
|
15
13
|
import { requireAdapters } from './endpoint-runtime.js';
|
|
16
14
|
import { formatConversationLog, previewMessageContent } from './message-events.js';
|
|
17
|
-
import {
|
|
18
|
-
import { collectButtonPayloads } from './jsx-button-registry.js';
|
|
19
|
-
import { resolveOutboundPresentation } from './outbound-presentation.js';
|
|
15
|
+
import { collectButtonPayloads } from './interactive-router.js';
|
|
20
16
|
const logger = getLogger('im.outbound');
|
|
21
17
|
/** A payload that cannot be rendered is not sent; say why, or the failure is invisible to the operator. */
|
|
22
18
|
function logRejectedPayload(conversation, stage, error) {
|
|
@@ -1,9 +1,39 @@
|
|
|
1
1
|
import { type PluginId, type RuntimeSnapshot } from '@zhin.js/plugin-runtime';
|
|
2
|
-
import type
|
|
2
|
+
import { type ConversationRef } from '@zhin.js/im-contract';
|
|
3
3
|
import { type JSXElement } from '@zhin.js/jsx';
|
|
4
4
|
import { type MessageRenderOptions } from '../../jsx/message-renderer.js';
|
|
5
5
|
import { type IncomingContext, type SendContent } from './contracts.js';
|
|
6
|
-
import {
|
|
6
|
+
import type { OutboundFallbackReason, RuntimeMessageRendering } from './message-events.js';
|
|
7
|
+
/** Keep the adapter's presentation or prefer its existing readable text fallback. */
|
|
8
|
+
export type OutboundPresentationMode = 'default' | 'text';
|
|
9
|
+
export interface OutboundPresentationPreferences {
|
|
10
|
+
readonly html?: OutboundPresentationMode;
|
|
11
|
+
readonly markdown?: OutboundPresentationMode;
|
|
12
|
+
readonly interactive?: OutboundPresentationMode;
|
|
13
|
+
}
|
|
14
|
+
export interface OutboundPresentationContext {
|
|
15
|
+
readonly conversation: ConversationRef;
|
|
16
|
+
readonly requester: PluginId;
|
|
17
|
+
readonly generation: number;
|
|
18
|
+
}
|
|
19
|
+
/** A synchronous, side-effect-free decision, shared by delivery and target previews. */
|
|
20
|
+
export type OutboundPresentation = (context: OutboundPresentationContext) => OutboundPresentationPreferences | undefined;
|
|
21
|
+
export declare const outboundPresentationToken: import("@zhin.js/plugin-runtime").Token<OutboundPresentation>;
|
|
22
|
+
/** Resolve once per operation; replacements reuse this detached, immutable decision. */
|
|
23
|
+
export declare function resolveOutboundPresentation(snapshot: RuntimeSnapshot, conversation: ConversationRef, requester: PluginId): OutboundPresentationPreferences | undefined;
|
|
24
|
+
export interface OutboundProjection {
|
|
25
|
+
readonly payload: unknown;
|
|
26
|
+
readonly rendering: RuntimeMessageRendering;
|
|
27
|
+
}
|
|
28
|
+
/** Shared by transport and target-aware previews. Does not send or register callbacks. */
|
|
29
|
+
export declare function projectOutboundPayload(rendered: unknown, conversation: ConversationRef, snapshot: RuntimeSnapshot, options?: {
|
|
30
|
+
readonly rememberFallback?: (map: Record<string, string>) => Record<string, string> | void;
|
|
31
|
+
readonly inheritedFallbacks?: readonly OutboundFallbackReason[];
|
|
32
|
+
/** Keep keyboard payloads until outbound middleware has had a chance to replace them. */
|
|
33
|
+
readonly deferInteractive?: boolean;
|
|
34
|
+
readonly signal?: AbortSignal;
|
|
35
|
+
readonly presentation?: OutboundPresentationPreferences;
|
|
36
|
+
}): Promise<OutboundProjection>;
|
|
7
37
|
/** One render operation's author, target, dependencies and shared JSX cache. */
|
|
8
38
|
export interface OutboundRenderContext {
|
|
9
39
|
readonly requester: PluginId;
|
|
@@ -1,13 +1,104 @@
|
|
|
1
|
-
import { componentHostToken } from '@zhin.js/plugin-runtime';
|
|
1
|
+
import { componentHostToken, createToken, htmlRendererToken } from '@zhin.js/plugin-runtime';
|
|
2
|
+
import { EndpointDeliveryError } from '@zhin.js/im-contract';
|
|
3
|
+
import { formatCompact, getLogger } from '@zhin.js/logger';
|
|
2
4
|
import { isJsxElement } from '@zhin.js/jsx';
|
|
3
5
|
import { isNativeMessageTag, renderToSegments } from '../../jsx/message-renderer.js';
|
|
4
6
|
import { flattenOutboundArray, MAX_OUTBOUND_ARRAY_DEPTH } from '../../built/outbound-content-arrays.js';
|
|
7
|
+
import { assertCanonicalSegments } from '../../built/segment-contract/assert.js';
|
|
5
8
|
import { componentFeatureId, isComponentIndex, } from '@zhin.js/component';
|
|
6
9
|
import { isComponentCall, isRawContent, isSegmentContent, } from './contracts.js';
|
|
7
|
-
import { JsxButtonRegistry } from './
|
|
10
|
+
import { JsxButtonRegistry } from './interactive-router.js';
|
|
8
11
|
import { requireAdapters } from './endpoint-runtime.js';
|
|
9
|
-
import {
|
|
10
|
-
|
|
12
|
+
import { applyOutboundInteractivePolicy, applyOutboundMarkdownPolicy, normalizeOutboundPayload, resolveOutboundHtmlPolicy, resolveOutboundInteractivePolicy, resolveOutboundMarkdownPolicy, resolveOutboundMediaPolicy, resolveOutboundSupportedSegments, } from './outbound-segments.js';
|
|
13
|
+
export const outboundPresentationToken = createToken('zhin.outbound-presentation', 'Root-selected outbound presentation within the adapter capability boundary');
|
|
14
|
+
const outboundLogger = getLogger('im.outbound');
|
|
15
|
+
/** Resolve once per operation; replacements reuse this detached, immutable decision. */
|
|
16
|
+
export function resolveOutboundPresentation(snapshot, conversation, requester) {
|
|
17
|
+
const policy = snapshot.resources.get(snapshot.root)?.get(outboundPresentationToken.id);
|
|
18
|
+
if (policy === undefined)
|
|
19
|
+
return undefined;
|
|
20
|
+
try {
|
|
21
|
+
const view = Object.freeze({
|
|
22
|
+
endpoint: Object.freeze({ id: conversation.endpoint.id, adapter: conversation.endpoint.adapter }),
|
|
23
|
+
kind: conversation.kind,
|
|
24
|
+
id: conversation.id,
|
|
25
|
+
...(conversation.parent ? { parent: Object.freeze({ kind: conversation.parent.kind, id: conversation.parent.id }) } : {}),
|
|
26
|
+
...(conversation.threadId !== undefined ? { threadId: conversation.threadId } : {}),
|
|
27
|
+
});
|
|
28
|
+
const result = policy(Object.freeze({ conversation: view, requester, generation: snapshot.generation }));
|
|
29
|
+
if (result === undefined)
|
|
30
|
+
return undefined;
|
|
31
|
+
if (result && typeof result === 'object' && 'then' in result) {
|
|
32
|
+
// An accidentally async policy is outside the contract. Consume a possible
|
|
33
|
+
// rejection without waiting for it or applying a later decision to this send.
|
|
34
|
+
void Promise.resolve(result).catch(() => undefined);
|
|
35
|
+
throw new TypeError('Outbound presentation must be synchronous');
|
|
36
|
+
}
|
|
37
|
+
if (!result || typeof result !== 'object')
|
|
38
|
+
throw new TypeError('Invalid outbound presentation');
|
|
39
|
+
const { html, markdown, interactive } = result;
|
|
40
|
+
for (const value of [html, markdown, interactive]) {
|
|
41
|
+
if (value !== undefined && value !== 'default' && value !== 'text')
|
|
42
|
+
throw new TypeError('Invalid outbound presentation mode');
|
|
43
|
+
}
|
|
44
|
+
return Object.freeze({ html, markdown, interactive });
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
// Never log the callback error, content or user-provided values; do not retry it.
|
|
48
|
+
outboundLogger.warn(formatCompact({ op: 'outbound_presentation', status: 'fallback', reason: 'policy_failed', generation: snapshot.generation }));
|
|
49
|
+
return undefined;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** Shared by transport and target-aware previews. Does not send or register callbacks. */
|
|
53
|
+
export async function projectOutboundPayload(rendered, conversation, snapshot, options = {}) {
|
|
54
|
+
options.signal?.throwIfAborted();
|
|
55
|
+
const adapter = conversation.endpoint.id;
|
|
56
|
+
const reasons = new Set(options.inheritedFallbacks);
|
|
57
|
+
const values = Array.isArray(rendered) ? flattenOutboundArray(rendered) : rendered;
|
|
58
|
+
const contains = (type) => (Array.isArray(values) ? values : [values])
|
|
59
|
+
.some(value => value && typeof value === 'object' && value.type === type);
|
|
60
|
+
const markdown = options.presentation?.markdown === 'text' ? 'text' : resolveOutboundMarkdownPolicy(adapter, snapshot);
|
|
61
|
+
if (markdown === 'text' && contains('markdown'))
|
|
62
|
+
reasons.add('markdown_text_policy');
|
|
63
|
+
const host = snapshot.resources.get(snapshot.root)?.get(htmlRendererToken.id);
|
|
64
|
+
let payload = await normalizeOutboundPayload(applyOutboundMarkdownPolicy(values, markdown), host, {
|
|
65
|
+
mediaPolicy: resolveOutboundMediaPolicy(adapter, snapshot),
|
|
66
|
+
htmlPolicy: options.presentation?.html === 'text' ? 'text' : resolveOutboundHtmlPolicy(adapter, snapshot),
|
|
67
|
+
onFallback: reason => reasons.add(reason),
|
|
68
|
+
signal: options.signal,
|
|
69
|
+
});
|
|
70
|
+
options.signal?.throwIfAborted();
|
|
71
|
+
const interactive = options.presentation?.interactive === 'text' ? 'text' : resolveOutboundInteractivePolicy(adapter, snapshot);
|
|
72
|
+
if (interactive === 'text' && Array.isArray(payload) && payload.some(item => item?.type === 'keyboard')) {
|
|
73
|
+
reasons.add('interactive_text_policy');
|
|
74
|
+
}
|
|
75
|
+
if (!options.deferInteractive)
|
|
76
|
+
payload = applyOutboundInteractivePolicy(payload, interactive, options.rememberFallback);
|
|
77
|
+
if (Array.isArray(payload)) {
|
|
78
|
+
payload = payload.filter(item => !(item?.type === 'text' && item.data?.text === ''));
|
|
79
|
+
assertCanonicalSegments(payload);
|
|
80
|
+
}
|
|
81
|
+
const supported = resolveOutboundSupportedSegments(adapter, snapshot);
|
|
82
|
+
const supportedPayload = options.deferInteractive ? applyOutboundInteractivePolicy(payload, interactive) : payload;
|
|
83
|
+
if (supported && Array.isArray(supportedPayload)) {
|
|
84
|
+
const unsupported = supportedPayload.find(segment => segment && typeof segment === 'object'
|
|
85
|
+
&& typeof segment.type === 'string' && !supported.includes(segment.type));
|
|
86
|
+
if (unsupported)
|
|
87
|
+
throw new EndpointDeliveryError('unsupported_operation', `Adapter does not support canonical segment ${unsupported.type}`, 'not_sent');
|
|
88
|
+
}
|
|
89
|
+
const forms = new Set();
|
|
90
|
+
for (const item of Array.isArray(payload) ? payload : [payload]) {
|
|
91
|
+
if (typeof item === 'string' || item?.type === 'text')
|
|
92
|
+
forms.add('text');
|
|
93
|
+
else if (item?.type === 'image')
|
|
94
|
+
forms.add('image');
|
|
95
|
+
else if (item != null)
|
|
96
|
+
forms.add('native');
|
|
97
|
+
}
|
|
98
|
+
return Object.freeze({ payload, rendering: Object.freeze({
|
|
99
|
+
forms: Object.freeze([...forms]), fallbacks: Object.freeze([...reasons]),
|
|
100
|
+
}) });
|
|
101
|
+
}
|
|
11
102
|
const maxComponentDepth = 32;
|
|
12
103
|
const TEMPLATE_MARKER = '${';
|
|
13
104
|
export class OutboundRenderer {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhin.js/core",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.58",
|
|
4
4
|
"description": "Zhin机器人核心框架",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./lib/index.js",
|
|
@@ -57,29 +57,28 @@
|
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"qrcode": "^1.5.4",
|
|
59
59
|
"segment-matcher": "^1.0.5",
|
|
60
|
-
"@zhin.js/adapter": "1.1.
|
|
61
|
-
"@zhin.js/command": "1.1.
|
|
62
|
-
"@zhin.js/component": "1.1.
|
|
60
|
+
"@zhin.js/adapter": "1.1.30",
|
|
61
|
+
"@zhin.js/command": "1.1.16",
|
|
62
|
+
"@zhin.js/component": "1.1.15",
|
|
63
63
|
"@zhin.js/database": "1.1.7",
|
|
64
|
-
"@zhin.js/handler": "1.1.
|
|
65
|
-
"@zhin.js/im-contract": "1.1.
|
|
66
|
-
"@zhin.js/interaction": "1.1.2",
|
|
64
|
+
"@zhin.js/handler": "1.1.14",
|
|
65
|
+
"@zhin.js/im-contract": "1.1.13",
|
|
67
66
|
"@zhin.js/kernel": "1.1.6",
|
|
68
67
|
"@zhin.js/logger": "1.1.2",
|
|
69
|
-
"@zhin.js/middleware": "1.1.
|
|
70
|
-
"@zhin.js/permission": "1.1.
|
|
71
|
-
"@zhin.js/plugin-runtime": "1.1.
|
|
72
|
-
"@zhin.js/schedule-feature": "1.1.
|
|
68
|
+
"@zhin.js/middleware": "1.1.15",
|
|
69
|
+
"@zhin.js/permission": "1.1.14",
|
|
70
|
+
"@zhin.js/plugin-runtime": "1.1.22",
|
|
71
|
+
"@zhin.js/schedule-feature": "1.1.14",
|
|
73
72
|
"@zhin.js/schema": "1.1.5",
|
|
74
|
-
"@zhin.js/jsx": "1.1.
|
|
75
|
-
"@zhin.js/feature-kit": "1.1.
|
|
73
|
+
"@zhin.js/jsx": "1.1.12",
|
|
74
|
+
"@zhin.js/feature-kit": "1.1.14"
|
|
76
75
|
},
|
|
77
76
|
"devDependencies": {
|
|
78
77
|
"@types/node": "^26.1.2",
|
|
79
78
|
"@types/qrcode": "^1.5.6",
|
|
80
79
|
"ajv": "8.18.0",
|
|
81
80
|
"typescript": "^6.0.3",
|
|
82
|
-
"@zhin.js/ai": "1.1.
|
|
81
|
+
"@zhin.js/ai": "1.1.53"
|
|
83
82
|
},
|
|
84
83
|
"repository": {
|
|
85
84
|
"type": "git",
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import type { EndpointControl, EndpointManagement } from '@zhin.js/adapter';
|
|
2
|
-
import type { ConversationRef, DeliveryReceipt, SelfProfilePort } from '@zhin.js/im-contract';
|
|
3
|
-
import type { Locale, PluginId } from '@zhin.js/plugin-runtime';
|
|
4
|
-
import type { SendContent } from './contracts.js';
|
|
5
|
-
import type { CoreReplyStream, OpenReplyStreamOptions } from './progressive-reply.js';
|
|
6
|
-
/** Capture while the source Message/event is active, before handing work to an asynchronous owner. */
|
|
7
|
-
export interface CaptureEndpointOperationInput {
|
|
8
|
-
/** Canonical complete source address; never an account alias. */
|
|
9
|
-
readonly target: ConversationRef;
|
|
10
|
-
/** Actual source Client, checked against the selected account incarnation. */
|
|
11
|
-
readonly client: unknown;
|
|
12
|
-
/** Lifetime of the work that is retaining the source operation. */
|
|
13
|
-
readonly signal?: AbortSignal;
|
|
14
|
-
/** Author supplied by trusted composition or the owner-bound Host facade. */
|
|
15
|
-
readonly requester?: PluginId;
|
|
16
|
-
}
|
|
17
|
-
/** Retained execution authority for one concrete Client; consumers must release it in finally. */
|
|
18
|
-
export interface CapturedEndpointOperation {
|
|
19
|
-
readonly target: ConversationRef;
|
|
20
|
-
readonly signal: AbortSignal;
|
|
21
|
-
/** The same guarded semantic ports as ordinary calls, pinned to the retained Client. */
|
|
22
|
-
readonly control?: EndpointControl;
|
|
23
|
-
readonly management?: EndpointManagement;
|
|
24
|
-
/** Current account facts and approved mutations, under the same retained operation. */
|
|
25
|
-
readonly profile?: SelfProfilePort;
|
|
26
|
-
/** Uses the ordinary renderer/middleware/delivery pipeline with the captured author. */
|
|
27
|
-
send(content: SendContent, options?: Readonly<{
|
|
28
|
-
locale?: Locale;
|
|
29
|
-
signal?: AbortSignal;
|
|
30
|
-
}>): Promise<DeliveryReceipt>;
|
|
31
|
-
openReplyStream?(options?: OpenReplyStreamOptions): CoreReplyStream | undefined;
|
|
32
|
-
/** Stops new calls and releases source/Root leases after accepted calls drain; never stops the account. */
|
|
33
|
-
release(): void;
|
|
34
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { type RuntimeSnapshot } from '@zhin.js/plugin-runtime';
|
|
2
|
-
import type { CommandDispatchResult, CommandIndex } from '@zhin.js/command';
|
|
3
|
-
import type { ConversationRef } from '@zhin.js/im-contract';
|
|
4
|
-
import type { SendContent } from './contracts.js';
|
|
5
|
-
/** Rendering dependencies for one menu response; callbacks retain the same generation. */
|
|
6
|
-
export interface CommandMenuReplyContext {
|
|
7
|
-
readonly commands: CommandIndex;
|
|
8
|
-
readonly snapshot: RuntimeSnapshot;
|
|
9
|
-
readonly conversation: ConversationRef;
|
|
10
|
-
readonly prefix: string;
|
|
11
|
-
}
|
|
12
|
-
/** IM-only presentation: Command remains independent of JSX, adapters and callback registries. */
|
|
13
|
-
export declare function commandMenuReply(result: CommandDispatchResult, { commands, snapshot, conversation, prefix }: CommandMenuReplyContext): Promise<SendContent>;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { readOperationInputResources } from '@zhin.js/feature-kit';
|
|
2
|
-
import { createMessages } from '@zhin.js/plugin-runtime';
|
|
3
|
-
import { Fragment, jsx } from '@zhin.js/jsx';
|
|
4
|
-
import { resolveOutboundInteractivePolicy, resolveOutboundMarkdownPolicy, resolveOutboundSupportedSegments } from './outbound-segments.js';
|
|
5
|
-
import { presentCommandMenu } from './command-menu-presentation.js';
|
|
6
|
-
const menuMessages = createMessages({
|
|
7
|
-
page: { 'zh-CN': '**指令菜单** · 第 {page}/{pages} 页', en: '**Command menu** · Page {page}/{pages}' },
|
|
8
|
-
previous: { 'zh-CN': '上一页', en: 'Previous' },
|
|
9
|
-
next: { 'zh-CN': '下一页', en: 'Next' },
|
|
10
|
-
});
|
|
11
|
-
/** IM-only presentation: Command remains independent of JSX, adapters and callback registries. */
|
|
12
|
-
export async function commandMenuReply(result, { commands, snapshot, conversation, prefix }) {
|
|
13
|
-
// Only validated menus carry this metadata; other command return values stay opaque.
|
|
14
|
-
const menu = result.menu;
|
|
15
|
-
if (!menu)
|
|
16
|
-
return result.value;
|
|
17
|
-
const content = await presentCommandMenu(menu, result.value, snapshot, conversation);
|
|
18
|
-
if (menu.pages <= 1)
|
|
19
|
-
return content;
|
|
20
|
-
const endpoint = conversation.endpoint.id;
|
|
21
|
-
const supported = resolveOutboundSupportedSegments(endpoint, snapshot);
|
|
22
|
-
if (resolveOutboundMarkdownPolicy(endpoint, snapshot) !== 'native'
|
|
23
|
-
|| resolveOutboundInteractivePolicy(endpoint, snapshot) !== 'native'
|
|
24
|
-
|| supported && (!supported.includes('markdown') || !supported.includes('keyboard')))
|
|
25
|
-
return content;
|
|
26
|
-
const button = (page, label, disabled) => jsx('button', {
|
|
27
|
-
label, disabled, style: disabled ? 'secondary' : 'primary',
|
|
28
|
-
onClick: async (message) => {
|
|
29
|
-
if (disabled)
|
|
30
|
-
return [];
|
|
31
|
-
const input = `${menu.keyword}${menu.pluginKey ? ` ${menu.pluginKey}` : ''} --page ${page}`;
|
|
32
|
-
const next = await commands.dispatch({ input: input, source: message, commandPrefix: prefix, snapshot: snapshot, locale: menu.locale, operation: readOperationInputResources(message, snapshot) });
|
|
33
|
-
return commandMenuReply(next, { commands: commands, snapshot: snapshot, conversation: message.conversation, prefix: prefix });
|
|
34
|
-
},
|
|
35
|
-
});
|
|
36
|
-
return [content,
|
|
37
|
-
{ type: 'markdown', data: { content: menuMessages(menu.locale, 'page', { page: menu.page, pages: menu.pages }) } },
|
|
38
|
-
jsx(Fragment, { children: [
|
|
39
|
-
button(menu.page - 1, menuMessages(menu.locale, 'previous'), menu.page === 1),
|
|
40
|
-
button(menu.page + 1, menuMessages(menu.locale, 'next'), menu.page === menu.pages),
|
|
41
|
-
] }),
|
|
42
|
-
];
|
|
43
|
-
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import type { CommandMenuPage } from '@zhin.js/command';
|
|
2
|
-
import type { ConversationRef } from '@zhin.js/im-contract';
|
|
3
|
-
import { type RuntimeSnapshot } from '@zhin.js/plugin-runtime';
|
|
4
|
-
import type { SendContent } from './contracts.js';
|
|
5
|
-
export interface CommandMenuPresentationInput {
|
|
6
|
-
readonly page: CommandMenuPage;
|
|
7
|
-
readonly conversation: ConversationRef;
|
|
8
|
-
readonly generation: number;
|
|
9
|
-
}
|
|
10
|
-
/** Root-selected menu content. `undefined` retains the built-in presentation. */
|
|
11
|
-
export type CommandMenuPresenter = (input: CommandMenuPresentationInput) => SendContent | undefined | Promise<SendContent | undefined>;
|
|
12
|
-
export declare const commandMenuPresentationToken: import("@zhin.js/plugin-runtime").Token<CommandMenuPresenter>;
|
|
13
|
-
/** The current Root owns both the selected presenter and the resulting content. */
|
|
14
|
-
export declare function presentCommandMenu(page: CommandMenuPage, fallback: SendContent, snapshot: RuntimeSnapshot, conversation: ConversationRef): Promise<SendContent>;
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { formatCompact, getLogger } from '@zhin.js/logger';
|
|
2
|
-
import { createToken } from '@zhin.js/plugin-runtime';
|
|
3
|
-
export const commandMenuPresentationToken = createToken('zhin.command-menu-presentation', 'Root-selected command menu presentation; framework pagination remains unchanged');
|
|
4
|
-
const logger = getLogger('command');
|
|
5
|
-
/** The current Root owns both the selected presenter and the resulting content. */
|
|
6
|
-
export async function presentCommandMenu(page, fallback, snapshot, conversation) {
|
|
7
|
-
const presenter = snapshot.resources.get(snapshot.root)?.get(commandMenuPresentationToken.id);
|
|
8
|
-
if (!presenter)
|
|
9
|
-
return fallback;
|
|
10
|
-
try {
|
|
11
|
-
const view = Object.freeze({
|
|
12
|
-
endpoint: Object.freeze({ id: conversation.endpoint.id, adapter: conversation.endpoint.adapter }),
|
|
13
|
-
kind: conversation.kind, id: conversation.id,
|
|
14
|
-
...(conversation.parent ? { parent: Object.freeze({ kind: conversation.parent.kind, id: conversation.parent.id }) } : {}),
|
|
15
|
-
...(conversation.threadId !== undefined ? { threadId: conversation.threadId } : {}),
|
|
16
|
-
});
|
|
17
|
-
const content = await presenter(Object.freeze({ page, conversation: view, generation: snapshot.generation }));
|
|
18
|
-
return content === undefined ? fallback : content;
|
|
19
|
-
}
|
|
20
|
-
catch {
|
|
21
|
-
// A presentation failure must not expose content, re-run commands or cause a second send.
|
|
22
|
-
logger.warn(formatCompact({ op: 'command_menu_presentation', status: 'fallback', reason: 'presenter_failed', generation: snapshot.generation }));
|
|
23
|
-
return fallback;
|
|
24
|
-
}
|
|
25
|
-
}
|