@zhin.js/core 1.1.53 → 1.1.55
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -26
- package/lib/built/interaction-messages.d.ts +1 -1
- package/lib/built/login-assist.d.ts +12 -3
- package/lib/built/login-assist.js +32 -26
- package/lib/feature/handler.d.ts +12 -2
- package/lib/feature/handler.js +2 -1
- package/lib/index.d.ts +3 -1
- package/lib/index.js +2 -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 +34 -0
- package/lib/plugin-runtime/im/captured-endpoint-operation.js +1 -0
- package/lib/plugin-runtime/im/command-menu-navigation.d.ts +8 -1
- package/lib/plugin-runtime/im/command-menu-navigation.js +3 -3
- package/lib/plugin-runtime/im/contracts.d.ts +69 -48
- package/lib/plugin-runtime/im/contracts.js +65 -58
- 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 +13 -15
- package/lib/plugin-runtime/im/endpoint-runtime.js +194 -42
- package/lib/plugin-runtime/im/group-rule-violation.d.ts +5 -0
- package/lib/plugin-runtime/im/im-runtime.d.ts +3 -0
- package/lib/plugin-runtime/im/im-runtime.js +33 -7
- package/lib/plugin-runtime/im/inbound-runtime.d.ts +2 -0
- package/lib/plugin-runtime/im/inbound-runtime.js +138 -33
- package/lib/plugin-runtime/im/index.d.ts +2 -1
- package/lib/plugin-runtime/im/interaction-operation.d.ts +5 -1
- package/lib/plugin-runtime/im/interaction-runtime.d.ts +12 -2
- package/lib/plugin-runtime/im/interaction-runtime.js +50 -35
- package/lib/plugin-runtime/im/message-dispatcher.js +2 -2
- package/lib/plugin-runtime/im/operation-endpoint.d.ts +6 -0
- package/lib/plugin-runtime/im/operation-endpoint.js +2 -0
- package/lib/plugin-runtime/im/outbound-delivery-runtime.d.ts +16 -2
- package/lib/plugin-runtime/im/outbound-delivery-runtime.js +86 -20
- package/lib/plugin-runtime/im/outbound-renderer.d.ts +12 -3
- package/lib/plugin-runtime/im/outbound-renderer.js +20 -13
- 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/package.json +15 -15
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import {
|
|
2
|
+
import { operationEndpoint } from './operation-endpoint.js';
|
|
3
3
|
import { projectLocale } from './locale.js';
|
|
4
|
+
import { resolveLocale, } from '@zhin.js/plugin-runtime';
|
|
4
5
|
import { EndpointDeliveryError } from '@zhin.js/im-contract';
|
|
5
6
|
import { isCanonicalSegment } from '../../built/segment-contract/assert.js';
|
|
6
7
|
import { collectSegmentMedia } from '../../built/segment-contract/media.js';
|
|
@@ -34,26 +35,38 @@ export class OutboundDeliveryRuntime {
|
|
|
34
35
|
this.context = context;
|
|
35
36
|
this.#renderer = renderer;
|
|
36
37
|
}
|
|
37
|
-
async deliver(request, snapshot) {
|
|
38
|
+
async deliver(request, snapshot, execution) {
|
|
38
39
|
let rendering;
|
|
39
|
-
const receipt = await this.#deliver(request, snapshot, value => { rendering = value; });
|
|
40
|
+
const receipt = await this.#deliver(request, snapshot, value => { rendering = value; }, execution);
|
|
40
41
|
this.context.diagnostics?.delivery(snapshot.generation, request.conversation, receipt, rendering);
|
|
41
42
|
return receipt;
|
|
42
43
|
}
|
|
43
|
-
async #deliver(request, snapshot, observeRendering) {
|
|
44
|
+
async #deliver(request, snapshot, observeRendering, execution) {
|
|
44
45
|
const adapter = request.conversation.endpoint.id;
|
|
46
|
+
const boundEndpoint = request[operationEndpoint];
|
|
47
|
+
if (boundEndpoint && boundEndpoint.canonicalId !== adapter)
|
|
48
|
+
throw new Error('Outbound Endpoint binding does not match its conversation');
|
|
45
49
|
const presentation = resolveOutboundPresentation(snapshot, request.conversation, request.requester);
|
|
46
50
|
const jsxCache = new WeakMap();
|
|
47
51
|
const buttons = this.context.prepareButtons?.(request, snapshot);
|
|
48
|
-
const renderOptions = { jsxCache, bindButton: buttons?.bind };
|
|
52
|
+
const renderOptions = { jsxCache, bindButton: buttons?.bind, signal: boundEndpoint?.signal };
|
|
49
53
|
let initialPayload;
|
|
50
54
|
let initialProjection;
|
|
51
55
|
try {
|
|
52
|
-
const rendered = await this.#renderer.render(request.content,
|
|
53
|
-
|
|
56
|
+
const rendered = await this.#renderer.render(request.content, {
|
|
57
|
+
requester: request.requester,
|
|
58
|
+
snapshot: snapshot,
|
|
59
|
+
conversation: request.conversation,
|
|
60
|
+
incoming: request.incoming,
|
|
61
|
+
...renderOptions,
|
|
62
|
+
});
|
|
63
|
+
initialProjection = await projectOutboundPayload(rendered, request.conversation, snapshot, { deferInteractive: true, presentation, signal: renderOptions.signal });
|
|
54
64
|
initialPayload = initialProjection.payload;
|
|
55
65
|
}
|
|
56
66
|
catch (error) {
|
|
67
|
+
// Preparation precedes the transport boundary; cancellation here is confirmed not sent.
|
|
68
|
+
if (renderOptions.signal?.aborted)
|
|
69
|
+
return failedDeliveryReceipt('endpoint_inactive');
|
|
57
70
|
if (error instanceof EndpointDeliveryError && error.code === 'unsupported_operation' && error.disposition === 'not_sent')
|
|
58
71
|
return receiptFromEndpointError(error, false);
|
|
59
72
|
logRejectedPayload(request.conversation, 'render', error);
|
|
@@ -71,7 +84,12 @@ export class OutboundDeliveryRuntime {
|
|
|
71
84
|
requester: request.requester,
|
|
72
85
|
generation: snapshot.generation,
|
|
73
86
|
clientAdapter: adapters.clientAdapter(adapter),
|
|
74
|
-
}, initialPayload, () =>
|
|
87
|
+
}, initialPayload, () => {
|
|
88
|
+
if (!boundEndpoint)
|
|
89
|
+
return adapters.clientById(adapter);
|
|
90
|
+
boundEndpoint.assertActive();
|
|
91
|
+
return boundEndpoint.endpoint;
|
|
92
|
+
});
|
|
75
93
|
// Record identities and fallback text before middleware can mutate the array
|
|
76
94
|
// or its segments. Do not copy/serialize media buffers or streams.
|
|
77
95
|
const initialItems = Array.isArray(initialPayload) ? initialPayload.map(item => ({
|
|
@@ -93,10 +111,16 @@ export class OutboundDeliveryRuntime {
|
|
|
93
111
|
// Native payload replacements remain possible; only authoring values need evaluation.
|
|
94
112
|
const replacement = envelope.payload;
|
|
95
113
|
const replaced = replacement !== initialPayload && needsAuthoringRender(replacement)
|
|
96
|
-
? await this.#renderer.render(replacement,
|
|
114
|
+
? await this.#renderer.render(replacement, {
|
|
115
|
+
requester: request.requester,
|
|
116
|
+
snapshot: snapshot,
|
|
117
|
+
conversation: request.conversation,
|
|
118
|
+
incoming: request.incoming,
|
|
119
|
+
...renderOptions,
|
|
120
|
+
})
|
|
97
121
|
: replacement;
|
|
98
122
|
projection = await projectOutboundPayload(replaced, request.conversation, snapshot, {
|
|
99
|
-
presentation,
|
|
123
|
+
presentation, signal: renderOptions.signal,
|
|
100
124
|
inheritedFallbacks: retainsInitialProjection(replacement) ? initialProjection.rendering.fallbacks : [],
|
|
101
125
|
rememberFallback: (map) => {
|
|
102
126
|
for (const value of Object.values(map))
|
|
@@ -110,6 +134,10 @@ export class OutboundDeliveryRuntime {
|
|
|
110
134
|
buttonPayloads.add(value);
|
|
111
135
|
}
|
|
112
136
|
catch (error) {
|
|
137
|
+
if (renderOptions.signal?.aborted) {
|
|
138
|
+
receipt = failedDeliveryReceipt('endpoint_inactive');
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
113
141
|
const unsupported = error instanceof EndpointDeliveryError && error.code === 'unsupported_operation' && error.disposition === 'not_sent';
|
|
114
142
|
if (!unsupported)
|
|
115
143
|
logRejectedPayload(request.conversation, 'middleware_render', error);
|
|
@@ -126,15 +154,34 @@ export class OutboundDeliveryRuntime {
|
|
|
126
154
|
: Array.isArray(payload) && payload.every(isCanonicalSegment) ? payload : undefined;
|
|
127
155
|
// Capture known canonical content before the endpoint can mutate it.
|
|
128
156
|
// Inline rendering bytes and opaque extensions never become new history.
|
|
129
|
-
|
|
157
|
+
let contentSources = canonicalContent?.map(snapshotHistorySource);
|
|
158
|
+
let contentUnavailable = false;
|
|
130
159
|
const payloadLength = Array.isArray(payload) ? payload.length : 1;
|
|
131
160
|
try {
|
|
132
|
-
const
|
|
161
|
+
const sendRequest = {
|
|
133
162
|
conversation: request.conversation,
|
|
134
163
|
locale: resolveLocale(request.locale ?? projectLocale(snapshot)),
|
|
135
164
|
payload,
|
|
136
|
-
}
|
|
137
|
-
|
|
165
|
+
};
|
|
166
|
+
if (execution) {
|
|
167
|
+
const transported = await execution.send(sendRequest);
|
|
168
|
+
if (transported.confirmedContent) {
|
|
169
|
+
contentSources = transported.confirmedContent.map(snapshotHistorySource);
|
|
170
|
+
// Explicit physical evidence must never fall back to the planned logical body.
|
|
171
|
+
contentUnavailable = !contentSources.length || contentSources.some(source => source === undefined);
|
|
172
|
+
}
|
|
173
|
+
if (transported.contentUnavailable) {
|
|
174
|
+
contentSources = undefined;
|
|
175
|
+
contentUnavailable = true;
|
|
176
|
+
}
|
|
177
|
+
receipt = transported.result === undefined ? suppressedDeliveryReceipt()
|
|
178
|
+
: receiptFromEndpointResult(transported.result, request.conversation, contentSources?.length ?? payloadLength);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
const result = boundEndpoint ? await boundEndpoint.send(sendRequest)
|
|
182
|
+
: await requireAdapters(snapshot).send(adapter, sendRequest);
|
|
183
|
+
receipt = receiptFromEndpointResult(result, request.conversation, payloadLength);
|
|
184
|
+
}
|
|
138
185
|
}
|
|
139
186
|
catch (error) {
|
|
140
187
|
receipt = receiptFromEndpointError(error, true, request.conversation, payloadLength);
|
|
@@ -144,25 +191,36 @@ export class OutboundDeliveryRuntime {
|
|
|
144
191
|
if (receipt.status !== 'sent' && !receipt.failure?.deliveryUnknown && !receipt.parts?.length)
|
|
145
192
|
revokeButtons?.();
|
|
146
193
|
for (const part of evidence.parts) {
|
|
194
|
+
execution?.confirmed(part.part, part.content);
|
|
147
195
|
const partReceipt = { status: 'sent', ...(part.part.message ? { message: part.part.message } : {}),
|
|
148
196
|
...(part.part.outboundTextDigest ? { outboundTextDigest: part.part.outboundTextDigest } : {}) };
|
|
149
|
-
|
|
150
|
-
|
|
197
|
+
const history = execution?.history() ?? 'create';
|
|
198
|
+
if (part.part.message && history !== 'skip') {
|
|
199
|
+
try {
|
|
200
|
+
const content = part.content ?? (contentUnavailable || receipt.parts ? 'unavailable' : undefined);
|
|
201
|
+
if (history === 'create')
|
|
202
|
+
await this.context.record(request, partReceipt, content);
|
|
203
|
+
else
|
|
204
|
+
await this.context.recordUpdate?.(request, partReceipt, history.revision, content);
|
|
205
|
+
}
|
|
206
|
+
catch (error) {
|
|
207
|
+
logger.warn(formatCompact({ op: 'outbound_history_failed', error: error instanceof Error ? error.message : String(error) }));
|
|
208
|
+
}
|
|
151
209
|
}
|
|
152
210
|
try {
|
|
153
|
-
this.context.ledger?.(request.conversation, partReceipt, part.content ?? (receipt.parts ? undefined : payload));
|
|
211
|
+
this.context.ledger?.(request.conversation, partReceipt, part.content ?? (contentUnavailable || receipt.parts ? undefined : payload));
|
|
154
212
|
}
|
|
155
213
|
catch (error) {
|
|
156
214
|
logger.warn(`outbound ledger write failed: ${error instanceof Error ? error.message : String(error)}`);
|
|
157
215
|
}
|
|
158
|
-
if (part.part.message)
|
|
216
|
+
if (part.part.message && history !== 'skip')
|
|
159
217
|
this.context.publish({
|
|
160
218
|
direction: 'outbound',
|
|
161
219
|
rendering: projection.rendering,
|
|
162
220
|
conversation: request.conversation,
|
|
163
221
|
requester: request.requester,
|
|
164
222
|
contentPreview: part.content ? previewMessageContent(part.content)
|
|
165
|
-
: receipt.parts ? '[Message content unavailable; inspect its reference.]' : previewMessageContent(payload),
|
|
223
|
+
: contentUnavailable || receipt.parts ? '[Message content unavailable; inspect its reference.]' : previewMessageContent(payload),
|
|
166
224
|
messageId: part.part.message.id,
|
|
167
225
|
timestamp: Date.now(),
|
|
168
226
|
});
|
|
@@ -227,7 +285,7 @@ function receiptFromEndpointResult(result, conversation, payloadLength) {
|
|
|
227
285
|
message: Object.freeze({ conversation, id: result }),
|
|
228
286
|
});
|
|
229
287
|
}
|
|
230
|
-
function receiptFromEndpointError(error, attempted = true, conversation, payloadLength) {
|
|
288
|
+
export function receiptFromEndpointError(error, attempted = true, conversation, payloadLength) {
|
|
231
289
|
if (error instanceof EndpointDeliveryError) {
|
|
232
290
|
const parts = attempted && conversation ? normalizeEndpointParts(error.parts, conversation, payloadLength) : [];
|
|
233
291
|
// Disposition is transport evidence; an error code alone cannot override it.
|
|
@@ -278,6 +336,14 @@ function normalizeEndpointParts(parts, conversation, payloadLength) {
|
|
|
278
336
|
}));
|
|
279
337
|
}
|
|
280
338
|
function snapshotHistorySource(segment) {
|
|
339
|
+
if (segment.type === 'markdown') {
|
|
340
|
+
const data = segment.data;
|
|
341
|
+
// The AI authoring contract has one closed Markdown shape. Core extensions remain opaque.
|
|
342
|
+
if (Object.keys(segment).length !== 2 || !Object.hasOwn(segment, 'type') || !Object.hasOwn(segment, 'data')
|
|
343
|
+
|| Object.keys(data).length !== 1 || !Object.hasOwn(data, 'content') || typeof data.content !== 'string')
|
|
344
|
+
return undefined;
|
|
345
|
+
return { type: 'markdown', data: { content: data.content } };
|
|
346
|
+
}
|
|
281
347
|
// Forward entries and opaque card/extensions have no bounded, simple content contract here.
|
|
282
348
|
if (!isStrictCanonicalSegment(segment) || segment.type === 'forward')
|
|
283
349
|
return undefined;
|
|
@@ -4,14 +4,23 @@ 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
6
|
import { type OutboundProjection } from './outbound-projection.js';
|
|
7
|
-
|
|
7
|
+
/** One render operation's author, target, dependencies and shared JSX cache. */
|
|
8
|
+
export interface OutboundRenderContext {
|
|
9
|
+
readonly requester: PluginId;
|
|
10
|
+
readonly snapshot: RuntimeSnapshot;
|
|
11
|
+
readonly conversation?: ConversationRef;
|
|
12
|
+
readonly incoming?: IncomingContext;
|
|
8
13
|
readonly jsxCache?: WeakMap<JSXElement, Promise<unknown>>;
|
|
9
14
|
readonly bindButton?: MessageRenderOptions['bindButton'];
|
|
10
15
|
readonly signal?: AbortSignal;
|
|
11
16
|
}
|
|
17
|
+
/** Preview requires a concrete target but never sends or registers live buttons. */
|
|
18
|
+
export interface OutboundPreviewContext extends Pick<OutboundRenderContext, 'requester' | 'snapshot' | 'signal'> {
|
|
19
|
+
readonly conversation: ConversationRef;
|
|
20
|
+
}
|
|
12
21
|
export declare class OutboundRenderer {
|
|
13
22
|
#private;
|
|
14
23
|
/** Target projection only: no middleware, transport or live button registration. */
|
|
15
|
-
preview(content: SendContent,
|
|
16
|
-
render(content: SendContent,
|
|
24
|
+
preview(content: SendContent, context: OutboundPreviewContext): Promise<OutboundProjection>;
|
|
25
|
+
render(content: SendContent, context: OutboundRenderContext): Promise<unknown>;
|
|
17
26
|
}
|
|
@@ -12,7 +12,8 @@ const maxComponentDepth = 32;
|
|
|
12
12
|
const TEMPLATE_MARKER = '${';
|
|
13
13
|
export class OutboundRenderer {
|
|
14
14
|
/** Target projection only: no middleware, transport or live button registration. */
|
|
15
|
-
async preview(content,
|
|
15
|
+
async preview(content, context) {
|
|
16
|
+
const { requester, snapshot, conversation, signal } = context;
|
|
16
17
|
const adapters = requireAdapters(snapshot);
|
|
17
18
|
const endpointId = conversation.endpoint.id;
|
|
18
19
|
if (adapters.clientAdapter(endpointId) !== conversation.endpoint.adapter)
|
|
@@ -20,23 +21,29 @@ export class OutboundRenderer {
|
|
|
20
21
|
if (!adapters.list().find(item => item.id === endpointId)?.capabilities.includes('outbound')) {
|
|
21
22
|
throw new Error('Preview endpoint does not support outbound messages');
|
|
22
23
|
}
|
|
23
|
-
|
|
24
|
+
signal?.throwIfAborted();
|
|
24
25
|
const presentation = resolveOutboundPresentation(snapshot, conversation, requester);
|
|
25
26
|
const buttons = new JsxButtonRegistry().prepare({ content, requester, conversation }, snapshot);
|
|
26
|
-
const rendered = await this.render(content, requester, snapshot, conversation,
|
|
27
|
-
const result = await projectOutboundPayload(rendered, conversation, snapshot, {
|
|
28
|
-
|
|
27
|
+
const rendered = await this.render(content, { requester, snapshot, conversation, signal, bindButton: buttons.bind });
|
|
28
|
+
const result = await projectOutboundPayload(rendered, conversation, snapshot, { signal, presentation });
|
|
29
|
+
signal?.throwIfAborted();
|
|
29
30
|
return result;
|
|
30
31
|
}
|
|
31
|
-
async render(content,
|
|
32
|
-
|
|
32
|
+
async render(content, context) {
|
|
33
|
+
const { requester, snapshot, conversation, incoming, signal, bindButton } = context;
|
|
34
|
+
signal?.throwIfAborted();
|
|
33
35
|
const host = resolveComponentHost(snapshot);
|
|
34
36
|
const ctx = conversation ? buildTemplateContext(conversation, incoming) : undefined;
|
|
35
|
-
const
|
|
36
|
-
|
|
37
|
+
const operation = { requester, snapshot, host, template: ctx,
|
|
38
|
+
jsxCache: context.jsxCache ?? new WeakMap(), signal, bindButton };
|
|
39
|
+
const rendered = await this.#render(content, { operation, depth: 0,
|
|
40
|
+
arrayAncestors: new Set(), jsxAncestors: new Set() });
|
|
41
|
+
signal?.throwIfAborted();
|
|
37
42
|
return rendered;
|
|
38
43
|
}
|
|
39
|
-
async #render(content,
|
|
44
|
+
async #render(content, traversal) {
|
|
45
|
+
const { operation, depth, arrayAncestors, jsxAncestors } = traversal;
|
|
46
|
+
const { requester, snapshot, host, template: ctx, jsxCache, signal, bindButton } = operation;
|
|
40
47
|
signal?.throwIfAborted();
|
|
41
48
|
if (depth > maxComponentDepth)
|
|
42
49
|
throw new Error('Component render depth exceeded 32');
|
|
@@ -49,7 +56,7 @@ export class OutboundRenderer {
|
|
|
49
56
|
throw new RangeError('SendContent array depth exceeded 512');
|
|
50
57
|
// Each parallel branch gets its own ancestry; repeated sibling arrays are valid.
|
|
51
58
|
const ancestors = new Set(arrayAncestors).add(content);
|
|
52
|
-
const items = await Promise.all(content.map((item) => this.#render(item,
|
|
59
|
+
const items = await Promise.all(content.map((item) => this.#render(item, { ...traversal, arrayAncestors: ancestors })));
|
|
53
60
|
signal?.throwIfAborted();
|
|
54
61
|
return flattenOutboundArray(items);
|
|
55
62
|
}
|
|
@@ -69,7 +76,7 @@ export class OutboundRenderer {
|
|
|
69
76
|
return [];
|
|
70
77
|
// Resolve every SendContent shape with the same depth and ancestry
|
|
71
78
|
// guards as ComponentCall. Root raw payloads remain opaque.
|
|
72
|
-
return this.#render(rendered,
|
|
79
|
+
return this.#render(rendered, { ...traversal, depth: depth + 1, jsxAncestors: ancestors });
|
|
73
80
|
};
|
|
74
81
|
segments = typeof content.type === 'string' && !isNativeMessageTag(content.type)
|
|
75
82
|
? renderNamedComponent(content.type, content.props)
|
|
@@ -97,7 +104,7 @@ export class OutboundRenderer {
|
|
|
97
104
|
const rendered = await requireComponents(snapshot).render(requester, content.name, content.props, { snapshot, ...(signal ? { signal } : {}) });
|
|
98
105
|
if (rendered == null)
|
|
99
106
|
return [];
|
|
100
|
-
return this.#render(rendered,
|
|
107
|
+
return this.#render(rendered, { ...traversal, depth: depth + 1 });
|
|
101
108
|
}
|
|
102
109
|
throw new TypeError('Unsupported SendContent');
|
|
103
110
|
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type EndpointStreaming, type EndpointChildLease, type EndpointStreamSource } from '@zhin.js/adapter';
|
|
2
|
+
import { type DeliveryReceipt, type MessageRef, type Segment } from '@zhin.js/im-contract';
|
|
3
|
+
import type { Locale } from '@zhin.js/plugin-runtime';
|
|
4
|
+
import type { SendContent } from './contracts.js';
|
|
5
|
+
import { type OutboundDeliveryExecution } from './outbound-delivery-runtime.js';
|
|
6
|
+
/** Host-owned keys identify content, independently of model-authored or platform identifiers. */
|
|
7
|
+
export interface ReplyStreamSnapshot {
|
|
8
|
+
readonly revision: number;
|
|
9
|
+
readonly messages: readonly {
|
|
10
|
+
readonly key: string;
|
|
11
|
+
readonly complete: boolean;
|
|
12
|
+
readonly segments: readonly {
|
|
13
|
+
readonly key: string;
|
|
14
|
+
readonly complete: boolean;
|
|
15
|
+
readonly value: Segment;
|
|
16
|
+
}[];
|
|
17
|
+
}[];
|
|
18
|
+
}
|
|
19
|
+
export interface OpenReplyStreamOptions {
|
|
20
|
+
readonly locale?: Locale;
|
|
21
|
+
readonly source?: EndpointStreamSource;
|
|
22
|
+
readonly maxBufferedBytes?: number;
|
|
23
|
+
/** Revalidate trusted reply admission immediately before every platform submission. */
|
|
24
|
+
readonly beforeSubmit?: () => void;
|
|
25
|
+
/** Resource authorization/materialization; this must not submit an external message. */
|
|
26
|
+
readonly prepare?: (segments: readonly Segment[], signal: AbortSignal) => Promise<readonly Segment[]>;
|
|
27
|
+
}
|
|
28
|
+
export interface ConfirmedReplyContent {
|
|
29
|
+
/** Stable physical container key; one logical message can produce several containers. */
|
|
30
|
+
readonly key: string;
|
|
31
|
+
readonly segments: readonly Segment[];
|
|
32
|
+
readonly message?: MessageRef;
|
|
33
|
+
}
|
|
34
|
+
export interface CoreReplyStream {
|
|
35
|
+
readonly minIntervalMs?: number;
|
|
36
|
+
readonly receipt: DeliveryReceipt;
|
|
37
|
+
readonly confirmed: readonly ConfirmedReplyContent[];
|
|
38
|
+
/** Coalesces replaceable candidates; does not allocate a Promise for every model token. */
|
|
39
|
+
update(snapshot: ReplyStreamSnapshot): void;
|
|
40
|
+
finish(snapshot: ReplyStreamSnapshot): Promise<DeliveryReceipt>;
|
|
41
|
+
cancel(): Promise<DeliveryReceipt>;
|
|
42
|
+
}
|
|
43
|
+
interface ProgressiveReplyContext {
|
|
44
|
+
readonly endpoint: EndpointChildLease;
|
|
45
|
+
readonly streaming: EndpointStreaming;
|
|
46
|
+
readonly options: OpenReplyStreamOptions;
|
|
47
|
+
readonly deliver: (content: SendContent, execution: OutboundDeliveryExecution) => Promise<DeliveryReceipt>;
|
|
48
|
+
readonly release: () => void;
|
|
49
|
+
}
|
|
50
|
+
/** One producer, one sending pump, and one replaceable candidate rather than a queue per token. */
|
|
51
|
+
export declare function createCoreReplyStream(context: ProgressiveReplyContext): CoreReplyStream;
|
|
52
|
+
export {};
|