@zhin.js/core 1.1.54 → 1.1.56
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/interaction-messages.d.ts +1 -1
- package/lib/index.d.ts +3 -0
- package/lib/index.js +1 -0
- package/lib/jsx/message-tags.d.ts +3 -3
- package/lib/jsx/message-tags.js +3 -0
- package/lib/plugin-runtime/im/captured-endpoint-operation.d.ts +5 -1
- package/lib/plugin-runtime/im/command-menu-navigation.d.ts +1 -1
- package/lib/plugin-runtime/im/command-menu-navigation.js +2 -1
- package/lib/plugin-runtime/im/contracts.d.ts +8 -1
- package/lib/plugin-runtime/im/contracts.js +20 -1
- package/lib/plugin-runtime/im/conversation-runtime.d.ts +2 -0
- package/lib/plugin-runtime/im/conversation-runtime.js +41 -4
- package/lib/plugin-runtime/im/endpoint-runtime.d.ts +4 -1
- package/lib/plugin-runtime/im/endpoint-runtime.js +38 -2
- package/lib/plugin-runtime/im/im-runtime.js +12 -4
- package/lib/plugin-runtime/im/inbound-runtime.d.ts +8 -1
- package/lib/plugin-runtime/im/inbound-runtime.js +1 -0
- package/lib/plugin-runtime/im/index.d.ts +2 -0
- package/lib/plugin-runtime/im/index.js +1 -0
- package/lib/plugin-runtime/im/message-dispatcher.js +2 -1
- package/lib/plugin-runtime/im/operation-resources.d.ts +15 -0
- package/lib/plugin-runtime/im/operation-resources.js +2 -0
- package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +16 -2
- package/lib/plugin-runtime/im/outbound-delivery-runtime.js +49 -14
- package/lib/plugin-runtime/im/outbound-segments.d.ts +1 -1
- package/lib/plugin-runtime/im/outbound-segments.js +2 -20
- package/lib/plugin-runtime/im/progressive-reply.d.ts +52 -0
- package/lib/plugin-runtime/im/progressive-reply.js +495 -0
- package/lib/plugin-runtime/im/runtime-middleware.d.ts +2 -0
- package/lib/plugin-runtime/im/runtime-middleware.js +5 -0
- package/lib/side-event/index.d.ts +0 -1
- package/lib/side-event/index.js +0 -1
- package/lib/side-event/normalize.d.ts +0 -28
- package/lib/side-event/normalize.js +0 -100
- package/lib/side-event/scene-events.js +1 -1
- package/lib/side-event/types.d.ts +0 -6
- package/lib/side-event/types.js +1 -57
- package/package.json +15 -15
- package/lib/side-event/dispatch.d.ts +0 -15
- package/lib/side-event/dispatch.js +0 -168
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const interactionMessages: (locale: import("@zhin.js/plugin-runtime").Locale | undefined, key: "number" | "fallback" | "
|
|
1
|
+
export declare const interactionMessages: (locale: import("@zhin.js/plugin-runtime").Locale | undefined, key: "number" | "fallback" | "minLength" | "maxLength" | "pattern" | "integer" | "min" | "max" | "confirmOrCancel" | "select" | "invalidSelection" | "minSelections" | "maxSelections" | "minItems" | "maxItems" | "invalidNumbers" | "invalidBooleans" | "confirm" | "cancel" | "confirmation" | "selection" | "multiple" | "list" | "ended" | "expired" | "timeout", values?: import("@zhin.js/plugin-runtime").MessageValues) => string;
|
package/lib/index.d.ts
CHANGED
|
@@ -47,3 +47,6 @@ export type { ConversationRef, DeliveryReceipt } from '@zhin.js/im-contract';
|
|
|
47
47
|
export { conversationRefKey } from '@zhin.js/im-contract';
|
|
48
48
|
export { readOperationSession } from '@zhin.js/feature-kit';
|
|
49
49
|
export type { CapabilityContext, OperationClientPort, OperationSession, OperationScene, OperationSender, OperationMessage, OperationMessageRef } from '@zhin.js/feature-kit';
|
|
50
|
+
/** ADR 0044: adapter capability types, re-exported so the agent layer reads them through core. */
|
|
51
|
+
export type { TurnCapabilities, AdapterCapabilityProfile, CapabilityFacts } from '@zhin.js/adapter';
|
|
52
|
+
export { adapterFeatureId, isAdapterIndex } from '@zhin.js/adapter';
|
package/lib/index.js
CHANGED
|
@@ -44,3 +44,4 @@ export { Schema } from '@zhin.js/schema';
|
|
|
44
44
|
export { ScheduleEngine, Scheduler, } from '@zhin.js/kernel';
|
|
45
45
|
export { conversationRefKey } from '@zhin.js/im-contract';
|
|
46
46
|
export { readOperationSession } from '@zhin.js/feature-kit';
|
|
47
|
+
export { adapterFeatureId, isAdapterIndex } from '@zhin.js/adapter';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { type JSXElement, type JSXRenderable } from '@zhin.js/jsx';
|
|
2
2
|
import type { MediaRef, Segment } from '@zhin.js/im-contract';
|
|
3
3
|
import type { Message, SendContent } from '../plugin-runtime/im/contracts.js';
|
|
4
|
-
import type { ButtonData } from '../built/interactive-segments/types.js';
|
|
4
|
+
import type { ActionSegmentData, ButtonData, KeyboardSegmentData } from '../built/interactive-segments/types.js';
|
|
5
5
|
export type TextProps = {
|
|
6
6
|
readonly text: string;
|
|
7
7
|
readonly children?: never;
|
|
@@ -107,8 +107,8 @@ export declare const Dice: (props: {
|
|
|
107
107
|
export declare const Rps: (props: {
|
|
108
108
|
readonly result?: number;
|
|
109
109
|
}) => JSXElement;
|
|
110
|
-
export declare const Keyboard: (props:
|
|
111
|
-
export declare const Action: (props:
|
|
110
|
+
export declare const Keyboard: (props: KeyboardSegmentData) => JSXElement;
|
|
111
|
+
export declare const Action: (props: ActionSegmentData) => JSXElement;
|
|
112
112
|
export declare const Link: (props: {
|
|
113
113
|
readonly url: string;
|
|
114
114
|
readonly text?: string;
|
package/lib/jsx/message-tags.js
CHANGED
|
@@ -40,6 +40,9 @@ export const Forward = nativeTag('forward');
|
|
|
40
40
|
export const Share = nativeTag('share');
|
|
41
41
|
export const Dice = nativeTag('dice');
|
|
42
42
|
export const Rps = nativeTag('rps');
|
|
43
|
+
// Explicit annotations keep the emitted .d.ts on the leaf type module. Inferred, they
|
|
44
|
+
// print as import("../index.js"), dragging the whole core entry (and @zhin.js/ai,
|
|
45
|
+
// database drivers) into every packed consumer that only imports a feature subpath.
|
|
43
46
|
export const Keyboard = nativeTag('keyboard');
|
|
44
47
|
export const Action = nativeTag('action');
|
|
45
48
|
export const Link = nativeTag('link');
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { EndpointControl, EndpointManagement } from '@zhin.js/adapter';
|
|
2
|
-
import type { ConversationRef, DeliveryReceipt } from '@zhin.js/im-contract';
|
|
2
|
+
import type { ConversationRef, DeliveryReceipt, SelfProfilePort } from '@zhin.js/im-contract';
|
|
3
3
|
import type { Locale, PluginId } from '@zhin.js/plugin-runtime';
|
|
4
4
|
import type { SendContent } from './contracts.js';
|
|
5
|
+
import type { CoreReplyStream, OpenReplyStreamOptions } from './progressive-reply.js';
|
|
5
6
|
/** Capture while the source Message/event is active, before handing work to an asynchronous owner. */
|
|
6
7
|
export interface CaptureEndpointOperationInput {
|
|
7
8
|
/** Canonical complete source address; never an account alias. */
|
|
@@ -20,11 +21,14 @@ export interface CapturedEndpointOperation {
|
|
|
20
21
|
/** The same guarded semantic ports as ordinary calls, pinned to the retained Client. */
|
|
21
22
|
readonly control?: EndpointControl;
|
|
22
23
|
readonly management?: EndpointManagement;
|
|
24
|
+
/** Current account facts and approved mutations, under the same retained operation. */
|
|
25
|
+
readonly profile?: SelfProfilePort;
|
|
23
26
|
/** Uses the ordinary renderer/middleware/delivery pipeline with the captured author. */
|
|
24
27
|
send(content: SendContent, options?: Readonly<{
|
|
25
28
|
locale?: Locale;
|
|
26
29
|
signal?: AbortSignal;
|
|
27
30
|
}>): Promise<DeliveryReceipt>;
|
|
31
|
+
openReplyStream?(options?: OpenReplyStreamOptions): CoreReplyStream | undefined;
|
|
28
32
|
/** Stops new calls and releases source/Root leases after accepted calls drain; never stops the account. */
|
|
29
33
|
release(): void;
|
|
30
34
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
+
import { type RuntimeSnapshot } from '@zhin.js/plugin-runtime';
|
|
1
2
|
import type { CommandDispatchResult, CommandIndex } from '@zhin.js/command';
|
|
2
3
|
import type { ConversationRef } from '@zhin.js/im-contract';
|
|
3
|
-
import type { RuntimeSnapshot } from '@zhin.js/plugin-runtime';
|
|
4
4
|
import type { SendContent } from './contracts.js';
|
|
5
5
|
/** Rendering dependencies for one menu response; callbacks retain the same generation. */
|
|
6
6
|
export interface CommandMenuReplyContext {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readOperationInputResources } from '@zhin.js/feature-kit';
|
|
1
2
|
import { createMessages } from '@zhin.js/plugin-runtime';
|
|
2
3
|
import { Fragment, jsx } from '@zhin.js/jsx';
|
|
3
4
|
import { resolveOutboundInteractivePolicy, resolveOutboundMarkdownPolicy, resolveOutboundSupportedSegments } from './outbound-segments.js';
|
|
@@ -28,7 +29,7 @@ export async function commandMenuReply(result, { commands, snapshot, conversatio
|
|
|
28
29
|
if (disabled)
|
|
29
30
|
return [];
|
|
30
31
|
const input = `${menu.keyword}${menu.pluginKey ? ` ${menu.pluginKey}` : ''} --page ${page}`;
|
|
31
|
-
const next = await commands.dispatch({ input: input, source: message, commandPrefix: prefix, snapshot: snapshot, locale: menu.locale });
|
|
32
|
+
const next = await commands.dispatch({ input: input, source: message, commandPrefix: prefix, snapshot: snapshot, locale: menu.locale, operation: readOperationInputResources(message, snapshot) });
|
|
32
33
|
return commandMenuReply(next, { commands: commands, snapshot: snapshot, conversation: message.conversation, prefix: prefix });
|
|
33
34
|
},
|
|
34
35
|
});
|
|
@@ -2,7 +2,7 @@ import type { CapturedEndpointOperation } from './captured-endpoint-operation.js
|
|
|
2
2
|
import type { JSXElement } from '@zhin.js/jsx';
|
|
3
3
|
import { type CommandMenuPage } from '@zhin.js/command';
|
|
4
4
|
import { type PluginId, type RuntimeSnapshot, type Locale } from '@zhin.js/plugin-runtime';
|
|
5
|
-
import { operationInputBinding, operationInputSignal, operationSession, type OperationSession } from '@zhin.js/feature-kit';
|
|
5
|
+
import { operationInputBinding, operationInputSignal, operationInputResources, operationSession, type OperationSession, type OperationResourceView, type CapabilityOperationFactory } from '@zhin.js/feature-kit';
|
|
6
6
|
import type { ConversationRef, DeliveryReceipt, MessageRef } from '@zhin.js/im-contract';
|
|
7
7
|
import type { MessageOrigin } from './inbound-origin.js';
|
|
8
8
|
import type { OperationEndpointSource } from './operation-endpoint.js';
|
|
@@ -194,6 +194,11 @@ export interface RuntimeMessageOperation {
|
|
|
194
194
|
readonly signal?: AbortSignal;
|
|
195
195
|
readonly captureInteraction?: (owner: PluginId) => CapturedEndpointOperation;
|
|
196
196
|
readonly session?: RuntimeMessageSessionBinding;
|
|
197
|
+
readonly createOperationResources?: (input: Readonly<{
|
|
198
|
+
message: RuntimeMessage;
|
|
199
|
+
owner: PluginId;
|
|
200
|
+
signal: AbortSignal;
|
|
201
|
+
}>) => OperationResourceView | undefined;
|
|
197
202
|
readonly registerOperationView?: (view: object, owner: PluginId) => void;
|
|
198
203
|
readonly presentation?: RuntimeMessagePresentation;
|
|
199
204
|
}
|
|
@@ -225,6 +230,8 @@ export declare class RuntimeMessage implements MessageBase {
|
|
|
225
230
|
[operationSession](): OperationSession<string> | undefined;
|
|
226
231
|
/** @internal A frozen view whose sends retain the current author's exact operation. */
|
|
227
232
|
[operationInputBinding](owner: PluginId, snapshot: RuntimeSnapshot): RuntimeMessage;
|
|
233
|
+
/** @internal Metadata fields cannot replace this actual leased operation factory. */
|
|
234
|
+
[operationInputResources](snapshot: RuntimeSnapshot): CapabilityOperationFactory | undefined;
|
|
228
235
|
/** @internal Explicit operation cancellation; replacement alone does not end accepted work. */
|
|
229
236
|
[operationInputSignal](): AbortSignal | undefined;
|
|
230
237
|
/** @internal The command/handler author's actual leased operation. */
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { commandFeatureId, isCommandIndex } from '@zhin.js/command';
|
|
2
2
|
import { resolveLocale } from '@zhin.js/plugin-runtime';
|
|
3
|
-
import { operationInputBinding, operationInputSignal, operationSession } from '@zhin.js/feature-kit';
|
|
3
|
+
import { operationInputBinding, operationInputSignal, operationInputResources, operationSession } from '@zhin.js/feature-kit';
|
|
4
4
|
import { interactionOperationScope } from './interaction-operation.js';
|
|
5
5
|
const componentCallBrand = 'zhin.component-call/1';
|
|
6
6
|
const rawContentBrand = 'zhin.raw-content/1';
|
|
@@ -148,6 +148,25 @@ export class RuntimeMessage {
|
|
|
148
148
|
},
|
|
149
149
|
});
|
|
150
150
|
}
|
|
151
|
+
/** @internal Metadata fields cannot replace this actual leased operation factory. */
|
|
152
|
+
[operationInputResources](snapshot) {
|
|
153
|
+
this.#operation.assertActive?.();
|
|
154
|
+
if (snapshot !== this.#operation.snapshot || snapshot.generation !== this.generation) {
|
|
155
|
+
throw new Error('Message resources belong to another generation operation');
|
|
156
|
+
}
|
|
157
|
+
if (!this.#operation.createOperationResources)
|
|
158
|
+
return undefined;
|
|
159
|
+
const signal = this.#operation.signal ?? new AbortController().signal;
|
|
160
|
+
return Object.freeze({ signal, create: (input) => {
|
|
161
|
+
this.#operation.assertActive?.();
|
|
162
|
+
if (!snapshot.tree.has(input.owner))
|
|
163
|
+
throw new Error(`Unknown operation owner: ${input.owner}`);
|
|
164
|
+
const actualSignal = input.signal === signal ? signal : AbortSignal.any([signal, input.signal]);
|
|
165
|
+
return Object.freeze({ signal: actualSignal, resources: this.#operation.createOperationResources?.({
|
|
166
|
+
message: this, owner: input.owner, signal: actualSignal,
|
|
167
|
+
}) });
|
|
168
|
+
} });
|
|
169
|
+
}
|
|
151
170
|
/** @internal Explicit operation cancellation; replacement alone does not end accepted work. */
|
|
152
171
|
[operationInputSignal]() {
|
|
153
172
|
this.#operation.assertActive?.();
|
|
@@ -28,6 +28,8 @@ export declare class ConversationRuntime {
|
|
|
28
28
|
commitContext(conversation: ConversationRef, consumer: string, cursor: number): Promise<void>;
|
|
29
29
|
recordIncoming(input: IncomingMessage, sender: MessageSenderRef | undefined): Promise<number | undefined>;
|
|
30
30
|
recordOutbound(request: SendRequest, receipt: DeliveryReceipt, canonicalContent?: readonly Segment[] | 'unavailable'): Promise<void>;
|
|
31
|
+
/** Records a confirmed replacement body without inventing another physical message. */
|
|
32
|
+
recordOutboundUpdate(request: SendRequest, receipt: DeliveryReceipt, revision: number, canonicalContent?: readonly Segment[] | 'unavailable'): Promise<void>;
|
|
31
33
|
/** Records a normalized notice; returns the stored event (with its sequence) when newly appended. */
|
|
32
34
|
recordNotice(notice: Notice): Promise<SequencedConversationEvent | undefined>;
|
|
33
35
|
/** Join requests / invitations into a group or channel become `scene.join_requested` (#996). */
|
|
@@ -26,7 +26,7 @@ export class ConversationRuntime {
|
|
|
26
26
|
if (reference.kind !== 'message')
|
|
27
27
|
return undefined;
|
|
28
28
|
const message = await this.#events.getMessage(reference.message);
|
|
29
|
-
return message && message.contentStatus !== 'unavailable'
|
|
29
|
+
return message && !message.recalled && message.contentStatus !== 'unavailable'
|
|
30
30
|
? Object.freeze({ status: 'resolved', reference, value: message })
|
|
31
31
|
: undefined;
|
|
32
32
|
}
|
|
@@ -42,14 +42,14 @@ export class ConversationRuntime {
|
|
|
42
42
|
const excluded = new Set(excludeMessageId ? [excludeMessageId] : []);
|
|
43
43
|
for (const entry of events) {
|
|
44
44
|
// Only message timestamps are runtime-assigned; notice clocks are adapter-defined.
|
|
45
|
-
if (entry.event.type === 'message.created' && entry.event.timestamp < notBefore)
|
|
45
|
+
if ((entry.event.type === 'message.created' || entry.event.type === 'message.updated') && entry.event.timestamp < notBefore)
|
|
46
46
|
continue;
|
|
47
47
|
if (await this.#isOwnRecall(entry.event)) {
|
|
48
48
|
if (entry.event.type === 'message.recalled')
|
|
49
49
|
excluded.add(entry.event.message.id);
|
|
50
50
|
continue;
|
|
51
51
|
}
|
|
52
|
-
if (entry.event.type === 'message.created'
|
|
52
|
+
if ((entry.event.type === 'message.created' || entry.event.type === 'message.updated')
|
|
53
53
|
&& this.#interactionAnswers.has(messageRefKey(entry.event.message.ref)))
|
|
54
54
|
continue;
|
|
55
55
|
relevant.push(entry);
|
|
@@ -133,6 +133,24 @@ export class ConversationRuntime {
|
|
|
133
133
|
}),
|
|
134
134
|
}));
|
|
135
135
|
}
|
|
136
|
+
/** Records a confirmed replacement body without inventing another physical message. */
|
|
137
|
+
async recordOutboundUpdate(request, receipt, revision, canonicalContent) {
|
|
138
|
+
if (receipt.status !== 'sent' || !receipt.message?.id)
|
|
139
|
+
return;
|
|
140
|
+
const original = await this.#events.getMessage(receipt.message);
|
|
141
|
+
if (!original)
|
|
142
|
+
throw new Error('Cannot record an update before its original message');
|
|
143
|
+
const { contentStatus: _status, outboundTextDigest: _digest, ...identity } = original;
|
|
144
|
+
await this.#events.append(Object.freeze({
|
|
145
|
+
eventId: `message:${messageRefKey(receipt.message)}:revision:${revision}`,
|
|
146
|
+
conversation: request.conversation, timestamp: Date.now(), type: 'message.updated',
|
|
147
|
+
message: Object.freeze({ ...identity, revision,
|
|
148
|
+
segments: canonicalContent === 'unavailable' ? [] : canonicalContent ?? segmentsFromContent(request.content),
|
|
149
|
+
...(canonicalContent === 'unavailable' ? { contentStatus: 'unavailable' } : {}),
|
|
150
|
+
...(canonicalContent !== 'unavailable' && canonicalContent?.length && canonicalContent.every(segment => segment.type === 'text') && receipt.outboundTextDigest
|
|
151
|
+
? { outboundTextDigest: receipt.outboundTextDigest } : {}), }),
|
|
152
|
+
}));
|
|
153
|
+
}
|
|
136
154
|
/** Records a normalized notice; returns the stored event (with its sequence) when newly appended. */
|
|
137
155
|
async recordNotice(notice) {
|
|
138
156
|
const event = conversationEventFromNotice(notice);
|
|
@@ -297,11 +315,29 @@ function conversationEventFromNotice(notice) {
|
|
|
297
315
|
function aggregateConversationContext(events, excluded) {
|
|
298
316
|
const ordinary = [];
|
|
299
317
|
const noisy = new Map();
|
|
318
|
+
const latestMessages = new Map();
|
|
319
|
+
const recalled = new Set();
|
|
320
|
+
for (const entry of events) {
|
|
321
|
+
const event = entry.event;
|
|
322
|
+
if (event.type === 'message.recalled')
|
|
323
|
+
recalled.add(messageRefKey(event.message));
|
|
324
|
+
if (event.type !== 'message.created' && event.type !== 'message.updated')
|
|
325
|
+
continue;
|
|
326
|
+
const key = messageRefKey(event.message.ref), previous = latestMessages.get(key);
|
|
327
|
+
if (recalled.has(key))
|
|
328
|
+
continue;
|
|
329
|
+
const previousRevision = previous && (previous.event.type === 'message.created' || previous.event.type === 'message.updated')
|
|
330
|
+
? previous.event.message.revision ?? 0 : -1;
|
|
331
|
+
if ((event.message.revision ?? 0) > previousRevision)
|
|
332
|
+
latestMessages.set(key, entry);
|
|
333
|
+
}
|
|
300
334
|
for (const { sequence, event } of events) {
|
|
301
335
|
// #996: these reach the model only through the short ephemeral `[Scene events]` block.
|
|
302
336
|
if (SCENE_ONLY_EVENT_TYPES.has(event.type))
|
|
303
337
|
continue;
|
|
304
|
-
if (event.type === 'message.created') {
|
|
338
|
+
if (event.type === 'message.created' || event.type === 'message.updated') {
|
|
339
|
+
if (latestMessages.get(messageRefKey(event.message.ref))?.sequence !== sequence)
|
|
340
|
+
continue;
|
|
305
341
|
if (excluded.has(event.message.ref.id))
|
|
306
342
|
continue;
|
|
307
343
|
const text = describeConversationMessage(event.message);
|
|
@@ -365,6 +401,7 @@ function describeConversationEvent(event) {
|
|
|
365
401
|
case 'member.role_changed':
|
|
366
402
|
return `${event.member.displayName ?? event.member.id} (${event.member.id}) role ${event.role} was ${event.enabled ? 'enabled' : 'disabled'}${actor ? ` by ${actor}` : ''}.`;
|
|
367
403
|
case 'message.created':
|
|
404
|
+
case 'message.updated':
|
|
368
405
|
case 'scene.join_requested':
|
|
369
406
|
case 'scene.notice_updated':
|
|
370
407
|
case 'member.card_changed':
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { OutboundDeliveryExecution } from './outbound-delivery-runtime.js';
|
|
1
2
|
import type { CaptureEndpointOperationInput, CapturedEndpointOperation } from './captured-endpoint-operation.js';
|
|
2
3
|
export type { CaptureEndpointOperationInput, CapturedEndpointOperation } from './captured-endpoint-operation.js';
|
|
3
4
|
import { AdapterIndex, type AdapterEndpointPhase, type AdapterOperation, type AdapterEndpointSummary, type EndpointTransportState, type EndpointManagement, type EndpointManagementCapability } from '@zhin.js/adapter';
|
|
@@ -52,7 +53,7 @@ interface EndpointRuntimeContext {
|
|
|
52
53
|
/** Independently retain the current operation snapshot for detached source work. */
|
|
53
54
|
retain(): SnapshotLease;
|
|
54
55
|
release(lease: SnapshotLease): void;
|
|
55
|
-
send(request: SendRequest, snapshot: RuntimeSnapshot): Promise<DeliveryReceipt>;
|
|
56
|
+
send(request: SendRequest, snapshot: RuntimeSnapshot, execution?: OutboundDeliveryExecution): Promise<DeliveryReceipt>;
|
|
56
57
|
}
|
|
57
58
|
/** Owns generation-leased Endpoint discovery, control, management, and Console delivery. */
|
|
58
59
|
export declare class EndpointRuntime {
|
|
@@ -69,12 +70,14 @@ export declare class EndpointRuntime {
|
|
|
69
70
|
captureOperation(input: CaptureEndpointOperationInput): CapturedEndpointOperation;
|
|
70
71
|
send(input: RuntimeEndpointSendInput): Promise<{
|
|
71
72
|
messageId: string;
|
|
73
|
+
receipt: DeliveryReceipt;
|
|
72
74
|
}>;
|
|
73
75
|
/** Resolves a persisted identity exactly in the current operation generation. */
|
|
74
76
|
sendTarget(target: DeliveryTarget, content: unknown, requester?: PluginId, options?: Readonly<{
|
|
75
77
|
locale?: Locale;
|
|
76
78
|
}>): Promise<{
|
|
77
79
|
messageId: string;
|
|
80
|
+
receipt: DeliveryReceipt;
|
|
78
81
|
}>;
|
|
79
82
|
addReaction(input: RuntimeEndpointReactionInput): Promise<string | null>;
|
|
80
83
|
removeReaction(input: RuntimeEndpointRemoveReactionInput): Promise<void>;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { operationEndpoint } from './operation-endpoint.js';
|
|
2
|
+
import { createCoreReplyStream } from './progressive-reply.js';
|
|
3
|
+
import { supportsIncrementalOutbound } from './runtime-middleware.js';
|
|
2
4
|
import { adapterFeatureId, isAdapterIndex, } from '@zhin.js/adapter';
|
|
3
5
|
import { normalizeDeliveryTarget } from '@zhin.js/plugin-runtime';
|
|
4
6
|
import { EndpointDeliveryError, } from '@zhin.js/im-contract';
|
|
@@ -123,6 +125,7 @@ export class EndpointRuntime {
|
|
|
123
125
|
return Object.freeze({
|
|
124
126
|
target, signal: captured.signal, control: controls,
|
|
125
127
|
management: index.management(id, scope),
|
|
128
|
+
profile: index.profile(id, scope),
|
|
126
129
|
send: async (content, options) => {
|
|
127
130
|
assertActive();
|
|
128
131
|
// Retain the source authority, while each send owns its caller cancellation.
|
|
@@ -142,6 +145,37 @@ export class EndpointRuntime {
|
|
|
142
145
|
releaseCall();
|
|
143
146
|
}
|
|
144
147
|
},
|
|
148
|
+
openReplyStream: (options = {}) => {
|
|
149
|
+
assertActive();
|
|
150
|
+
if (!captured.streaming || !supportsIncrementalOutbound(snapshot.value, target.endpoint.adapter))
|
|
151
|
+
return undefined;
|
|
152
|
+
if (captured.streaming.supports?.({ conversation: target, source: options.source }) === false)
|
|
153
|
+
return undefined;
|
|
154
|
+
const releaseCall = retainCall();
|
|
155
|
+
let streamLease;
|
|
156
|
+
try {
|
|
157
|
+
streamLease = index.acquire(id, captured.signal, captured.endpoint);
|
|
158
|
+
const retained = streamLease;
|
|
159
|
+
return createCoreReplyStream({ endpoint: retained, streaming: retained.streaming, options,
|
|
160
|
+
deliver: (content, execution) => {
|
|
161
|
+
// Opening admitted this whole stream; capture.release only closes new admission.
|
|
162
|
+
retained.assertActive();
|
|
163
|
+
return this.context.send({ conversation: target, requester, content,
|
|
164
|
+
...(options.locale ? { locale: options.locale } : {}), [operationEndpoint]: retained }, snapshot.value, execution);
|
|
165
|
+
},
|
|
166
|
+
release: () => { try {
|
|
167
|
+
retained.release();
|
|
168
|
+
}
|
|
169
|
+
finally {
|
|
170
|
+
releaseCall();
|
|
171
|
+
} }, });
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
streamLease?.release();
|
|
175
|
+
releaseCall();
|
|
176
|
+
throw error;
|
|
177
|
+
}
|
|
178
|
+
},
|
|
145
179
|
release: () => {
|
|
146
180
|
if (released)
|
|
147
181
|
return;
|
|
@@ -333,9 +367,11 @@ function normalizeConsoleContent(content) {
|
|
|
333
367
|
function requireSentReceipt(result) {
|
|
334
368
|
if (result.status !== 'sent') {
|
|
335
369
|
throw new EndpointDeliveryError(result.failure?.code ?? `outbound_${result.status}`, result.failure?.message ?? 'Outbound delivery was suppressed.', result.failure?.deliveryUnknown ? 'unknown'
|
|
336
|
-
: result.status === 'rejected' ? 'rejected' : 'not_sent'
|
|
370
|
+
: result.status === 'rejected' ? 'rejected' : 'not_sent', { receipt: result, ...(result.parts ? { parts: result.parts.map(part => ({
|
|
371
|
+
...(part.message ? { messageId: part.message.id } : {}), ...(part.sourceIndices ? { sourceIndices: part.sourceIndices } : {}),
|
|
372
|
+
})) } : {}) });
|
|
337
373
|
}
|
|
338
|
-
return { messageId: result.message?.id ?? '' };
|
|
374
|
+
return { messageId: result.message?.id ?? '', receipt: result };
|
|
339
375
|
}
|
|
340
376
|
/** A canonical message/address cannot be redirected by a second endpoint selector. */
|
|
341
377
|
function assertSameEndpoint(expected, actual) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { imOperationResourcesToken } from './operation-resources.js';
|
|
2
|
+
import { OwnerOperation, createToken, readLeasedRootResource, generationAdmissionBinder, } from '@zhin.js/plugin-runtime';
|
|
2
3
|
import { AsyncLocalStorage } from 'node:async_hooks';
|
|
3
4
|
import { PermissionHost, permissionHostToken } from '@zhin.js/permission';
|
|
4
5
|
import { CommandExecutionBudget, commandExecutionAdmissionToken } from '@zhin.js/command/internal/execution';
|
|
@@ -56,6 +57,7 @@ export class ImRuntime {
|
|
|
56
57
|
diagnostics: this.#messageDiagnostics,
|
|
57
58
|
ledger: (conversation, receipt, payload) => ledger.record(conversation, receipt, payload),
|
|
58
59
|
record: (request, receipt, canonicalContent) => this.#conversations.recordOutbound(request, receipt, canonicalContent),
|
|
60
|
+
recordUpdate: (request, receipt, revision, canonicalContent) => this.#conversations.recordOutboundUpdate(request, receipt, revision, canonicalContent),
|
|
59
61
|
rememberFallback: (conversation, generation, map) => this.#interactions.rememberFallback(conversation, generation, map),
|
|
60
62
|
publish: (event) => this.#messageEventStream.publish(event),
|
|
61
63
|
prepareButtons: (request, snapshot) => this.#interactions.prepareButtons(request, snapshot),
|
|
@@ -66,6 +68,12 @@ export class ImRuntime {
|
|
|
66
68
|
diagnostics: this.#messageDiagnostics,
|
|
67
69
|
interactions: this.#interactions,
|
|
68
70
|
captureOperation: input => this.endpoints.captureOperation(input),
|
|
71
|
+
createOperationResources: input => {
|
|
72
|
+
const snapshots = this.#snapshots;
|
|
73
|
+
if (!snapshots || !snapshots.owns(input.lease) || !input.lease.active)
|
|
74
|
+
throw new Error('IM operation lease is not active');
|
|
75
|
+
return readLeasedRootResource(snapshots, input.lease, imOperationResourcesToken)?.open({ ...input, snapshots });
|
|
76
|
+
},
|
|
69
77
|
inboundClaim: options.inboundClaim,
|
|
70
78
|
originClassifier,
|
|
71
79
|
deduper,
|
|
@@ -86,7 +94,7 @@ export class ImRuntime {
|
|
|
86
94
|
acquire: () => this.#acquire(),
|
|
87
95
|
retain: () => this.#retainSnapshot(),
|
|
88
96
|
release: (lease) => this.#release(lease),
|
|
89
|
-
send: (request, snapshot) => this.#deliver(request, snapshot),
|
|
97
|
+
send: (request, snapshot, execution) => this.#deliver(request, snapshot, execution),
|
|
90
98
|
});
|
|
91
99
|
}
|
|
92
100
|
/** Process composition replaces the bootstrap memory store after required DB activation. */
|
|
@@ -260,8 +268,8 @@ export class ImRuntime {
|
|
|
260
268
|
}
|
|
261
269
|
}
|
|
262
270
|
/** All unified outbound entry points observe the actual delivery, never their own caller/drain promise. */
|
|
263
|
-
#deliver(request, snapshot) {
|
|
264
|
-
const delivery = this.#outbound.deliver(request, snapshot);
|
|
271
|
+
#deliver(request, snapshot, execution) {
|
|
272
|
+
const delivery = this.#outbound.deliver(request, snapshot, execution);
|
|
265
273
|
this.#commandOperation.getStore()?.trackSend(delivery);
|
|
266
274
|
return delivery;
|
|
267
275
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CaptureEndpointOperationInput, CapturedEndpointOperation } from './captured-endpoint-operation.js';
|
|
2
|
-
import type { GenerationAdmissionGate, RuntimeSnapshot, SnapshotLease } from '@zhin.js/plugin-runtime';
|
|
2
|
+
import type { GenerationAdmissionGate, PluginId, RuntimeSnapshot, SnapshotLease } from '@zhin.js/plugin-runtime';
|
|
3
3
|
import type { EndpointEvent, PeerRegistry } from '@zhin.js/adapter';
|
|
4
|
+
import { type OperationResourceView } from '@zhin.js/feature-kit';
|
|
4
5
|
import type { DeliveryReceipt } from '@zhin.js/im-contract';
|
|
5
6
|
import type { UserInteraction } from '@zhin.js/interaction';
|
|
6
7
|
import type { CommandExecutionBudget, CommandOperationController } from '@zhin.js/command/internal/execution';
|
|
@@ -19,6 +20,12 @@ interface InboundRuntimeContext {
|
|
|
19
20
|
readonly diagnostics?: RuntimeMessageDiagnostics;
|
|
20
21
|
readonly interactions: InboundInteractionPort;
|
|
21
22
|
captureOperation(input: CaptureEndpointOperationInput): CapturedEndpointOperation;
|
|
23
|
+
createOperationResources?(input: Readonly<{
|
|
24
|
+
lease: SnapshotLease;
|
|
25
|
+
message: import('./contracts.js').RuntimeMessage;
|
|
26
|
+
owner: PluginId;
|
|
27
|
+
signal: AbortSignal;
|
|
28
|
+
}>): OperationResourceView | undefined;
|
|
22
29
|
readonly inboundClaim?: (message: Message) => boolean | Promise<boolean>;
|
|
23
30
|
/** Trusted origin classifier. Absent: messages carry no origin (legacy behavior). */
|
|
24
31
|
readonly originClassifier?: InboundOriginClassifier;
|
|
@@ -332,6 +332,7 @@ export class InboundRuntime {
|
|
|
332
332
|
captureInteraction: owner => this.context.captureOperation({ target: conversation,
|
|
333
333
|
client: source.client, requester: owner, signal: boundEndpoint.signal }),
|
|
334
334
|
registerOperationView: commandOperation?.bind,
|
|
335
|
+
createOperationResources: request => this.context.createOperationResources?.({ ...request, lease }),
|
|
335
336
|
assertActive: () => {
|
|
336
337
|
if (!active)
|
|
337
338
|
throw new Error('Message author binding scope has ended');
|
|
@@ -5,6 +5,7 @@ export * from './ingress-route.js';
|
|
|
5
5
|
export { isMessageOrigin, roomMembershipToken } from './inbound-origin.js';
|
|
6
6
|
export type { MessageOrigin, RoomInboundRouteInput, RoomMembershipPort, RoomRouteDecision, } from './inbound-origin.js';
|
|
7
7
|
export * from './im-runtime.js';
|
|
8
|
+
export * from './operation-resources.js';
|
|
8
9
|
export * from './login-assist-host.js';
|
|
9
10
|
export * from './group-rule-violation.js';
|
|
10
11
|
export * from './member-welcome.js';
|
|
@@ -14,6 +15,7 @@ export type { RuntimeMessageDiagnostic, RuntimeMessageDiagnosticStep, RuntimeMes
|
|
|
14
15
|
export type { RuntimeMessageEvent, RuntimeMessageEventSource, RuntimeMessageRendering, RuntimeSceneEventSignal, RuntimeSceneEventSource, OutboundFallbackReason, } from './message-events.js';
|
|
15
16
|
export * from './outbound-renderer.js';
|
|
16
17
|
export * from './outbound-segments.js';
|
|
18
|
+
export type { CoreReplyStream, OpenReplyStreamOptions, ReplyStreamSnapshot, ConfirmedReplyContent } from './progressive-reply.js';
|
|
17
19
|
export * from '../../notice.js';
|
|
18
20
|
export * from '../../request.js';
|
|
19
21
|
export * from '../../system-event.js';
|
|
@@ -3,6 +3,7 @@ export { EndpointRuntime } from './endpoint-runtime.js';
|
|
|
3
3
|
export * from './ingress-route.js';
|
|
4
4
|
export { isMessageOrigin, roomMembershipToken } from './inbound-origin.js';
|
|
5
5
|
export * from './im-runtime.js';
|
|
6
|
+
export * from './operation-resources.js';
|
|
6
7
|
export * from './login-assist-host.js';
|
|
7
8
|
export * from './group-rule-violation.js';
|
|
8
9
|
export * from './member-welcome.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { readOperationInputResources } from '@zhin.js/feature-kit';
|
|
1
2
|
import { adapterFeatureId, isAdapterIndex } from '@zhin.js/adapter';
|
|
2
3
|
import { commandFeatureId, isCommandIndex, } from '@zhin.js/command';
|
|
3
4
|
import { formatCompact, getLogger, truncatePreview } from '@zhin.js/logger';
|
|
@@ -87,7 +88,7 @@ export class MessageDispatcher {
|
|
|
87
88
|
: undefined;
|
|
88
89
|
const matchInput = structuredInput ?? input;
|
|
89
90
|
note('dispatch', 'started');
|
|
90
|
-
const result = await commands.dispatch({ input: matchInput, source: message, interactionFactory: interactionFactory, commandPrefix: prefix, snapshot: snapshot });
|
|
91
|
+
const result = await commands.dispatch({ input: matchInput, source: message, interactionFactory: interactionFactory, commandPrefix: prefix, snapshot: snapshot, operation: readOperationInputResources(message, snapshot) });
|
|
91
92
|
const feedback = await renderCommandFeedback(result, message, snapshot);
|
|
92
93
|
if (feedback)
|
|
93
94
|
return dispatchOutcome(Object.freeze({ ...result, value: feedback.content }), feedback.owner);
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { type PluginId, type SnapshotLease, type SnapshotReader } from '@zhin.js/plugin-runtime';
|
|
2
|
+
import type { OperationResourceView } from '@zhin.js/feature-kit';
|
|
3
|
+
import type { RuntimeMessage } from './contracts.js';
|
|
4
|
+
/** Trusted composition port. Only Core supplies the controlled message and real held lease. */
|
|
5
|
+
export interface ImOperationResourcesInput {
|
|
6
|
+
readonly lease: SnapshotLease;
|
|
7
|
+
readonly snapshots: SnapshotReader;
|
|
8
|
+
readonly message: RuntimeMessage;
|
|
9
|
+
readonly owner: PluginId;
|
|
10
|
+
readonly signal: AbortSignal;
|
|
11
|
+
}
|
|
12
|
+
export interface ImOperationResourcesPort {
|
|
13
|
+
open(input: ImOperationResourcesInput): OperationResourceView | undefined;
|
|
14
|
+
}
|
|
15
|
+
export declare const imOperationResourcesToken: import("@zhin.js/plugin-runtime").Token<ImOperationResourcesPort>;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type RuntimeSnapshot } from '@zhin.js/plugin-runtime';
|
|
2
|
-
import { type ConversationRef, type DeliveryReceipt, type Segment } from '@zhin.js/im-contract';
|
|
2
|
+
import { type ConversationRef, type DeliveryReceipt, type DeliveryPart, type EndpointSendResult, type Segment } from '@zhin.js/im-contract';
|
|
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';
|
|
@@ -9,17 +9,31 @@ interface OutboundDeliveryContext {
|
|
|
9
9
|
readonly diagnostics?: RuntimeMessageDiagnostics;
|
|
10
10
|
prepareButtons?(request: SendRequest, snapshot: RuntimeSnapshot): JsxButtonBatch;
|
|
11
11
|
record(request: SendRequest, receipt: DeliveryReceipt, canonicalContent?: readonly Segment[] | 'unavailable'): Promise<void>;
|
|
12
|
+
recordUpdate?(request: SendRequest, receipt: DeliveryReceipt, revision: number, canonicalContent?: readonly Segment[] | 'unavailable'): Promise<void>;
|
|
12
13
|
/** Side-channel correlation ledger for inbound origin; failures never affect the receipt. */
|
|
13
14
|
ledger?(conversation: ConversationRef, receipt: DeliveryReceipt, payload: unknown): void;
|
|
14
15
|
rememberFallback(conversation: ConversationRef, generation: number, map: Record<string, string>): Record<string, string> | void;
|
|
15
16
|
publish(event: RuntimeMessageEvent): void;
|
|
16
17
|
}
|
|
18
|
+
/** Internal transport continuation. Rendering, policy and middleware still own every submitted revision. */
|
|
19
|
+
export interface OutboundDeliveryExecution {
|
|
20
|
+
send(request: import('@zhin.js/adapter').EndpointSendRequest): Promise<{
|
|
21
|
+
readonly result?: EndpointSendResult;
|
|
22
|
+
readonly confirmedContent?: readonly Segment[];
|
|
23
|
+
readonly contentUnavailable?: true;
|
|
24
|
+
}>;
|
|
25
|
+
history(): 'create' | 'skip' | Readonly<{
|
|
26
|
+
revision: number;
|
|
27
|
+
}>;
|
|
28
|
+
confirmed(part: DeliveryPart, content: readonly Segment[] | undefined): void;
|
|
29
|
+
}
|
|
17
30
|
/** Owns rendering, policy projection, middleware, Endpoint delivery, and delivery facts. */
|
|
18
31
|
export declare class OutboundDeliveryRuntime {
|
|
19
32
|
#private;
|
|
20
33
|
private readonly context;
|
|
21
34
|
constructor(context: OutboundDeliveryContext, renderer?: OutboundRenderer);
|
|
22
|
-
deliver(request: SendRequest, snapshot: RuntimeSnapshot): Promise<DeliveryReceipt>;
|
|
35
|
+
deliver(request: SendRequest, snapshot: RuntimeSnapshot, execution?: OutboundDeliveryExecution): Promise<DeliveryReceipt>;
|
|
23
36
|
}
|
|
24
37
|
export declare function failedDeliveryReceipt(code: string, retryable?: boolean): DeliveryReceipt;
|
|
38
|
+
export declare function receiptFromEndpointError(error: unknown, attempted?: boolean, conversation?: ConversationRef, payloadLength?: number): DeliveryReceipt;
|
|
25
39
|
export {};
|