@tangle-network/agent-app 0.43.60 → 0.43.62
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/dist/assistant/index.d.ts +1 -1
- package/dist/assistant/index.js +1 -1
- package/dist/chat-routes/index.d.ts +262 -3
- package/dist/chat-routes/index.js +315 -13
- package/dist/chat-routes/index.js.map +1 -1
- package/dist/chat-store/index.d.ts +38 -2
- package/dist/chat-store/index.js +30 -1
- package/dist/chat-store/index.js.map +1 -1
- package/dist/{chunk-IG46XCZM.js → chunk-BG52UKNN.js} +5 -1
- package/dist/{chunk-IG46XCZM.js.map → chunk-BG52UKNN.js.map} +1 -1
- package/dist/{chunk-VCOD5AOR.js → chunk-YN7QR7MJ.js} +16 -9
- package/dist/chunk-YN7QR7MJ.js.map +1 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -2
- package/dist/stream/index.d.ts +17 -2
- package/dist/stream/index.js +4 -2
- package/dist/{stream-normalizer-C3M--r6y.d.ts → stream-normalizer-BlCP_Cdd.d.ts} +18 -1
- package/dist/web-react/index.d.ts +1 -1
- package/dist/web-react/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-VCOD5AOR.js.map +0 -1
|
@@ -11,7 +11,7 @@ import '../sandbox-terminal-ChNEdHF8.js';
|
|
|
11
11
|
import '../catalog/index.js';
|
|
12
12
|
import '../harness/index.js';
|
|
13
13
|
import '../attachment-validation-tPRp-PP1.js';
|
|
14
|
-
import '../stream-normalizer-
|
|
14
|
+
import '../stream-normalizer-BlCP_Cdd.js';
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* Wire + UI types for the in-app assistant panel. The wire shapes mirror the
|
package/dist/assistant/index.js
CHANGED
|
@@ -8,7 +8,7 @@ import "../chunk-HCOROIRT.js";
|
|
|
8
8
|
import "../chunk-BPSV5AA2.js";
|
|
9
9
|
import "../chunk-FBVLEGEG.js";
|
|
10
10
|
import "../chunk-DTSPS2HV.js";
|
|
11
|
-
import "../chunk-
|
|
11
|
+
import "../chunk-BG52UKNN.js";
|
|
12
12
|
import "../chunk-YKOM4ZLQ.js";
|
|
13
13
|
import "../chunk-YJMCRXQQ.js";
|
|
14
14
|
import "../chunk-CQZSAR77.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { g as ChatMessagePart, L as ChatTurnRequestPayload, M as ChatTurnPartInput, N as ChatTurnFilePartInput, a as ChatAttachmentPart, C as ChatAttachmentKind, f as ChatMentionPart } from '../parts-n9XUon0a.js';
|
|
2
2
|
export { O as ChatAttachmentInput, e as ChatMentionKind, P as ChatTurnInputError, Q as ChatTurnTextPartInput, R as DISPATCH_MAX_MEDIA_PARTS, T as DISPATCH_MAX_PARTS, U as DISPATCH_REQUEST_MAX_BYTES, V as DISPATCH_STRUCTURAL_RESERVE_BYTES, K as FileMention, W as FileMentionsToPartsOptions, X as INLINE_PARTS_MAX_BYTES, Y as MENTION_MAX_COUNT, Z as ProducerErrorEvent, _ as ProducerNoticeEvent, $ as ProducerPassthroughEvent, a0 as ProducerPassthroughEventType, a1 as ProducerReasoningEvent, a2 as ProducerTextEvent, a3 as ProducerToolCallEvent, a4 as ProducerToolResultEvent, a5 as ProducerUsageEvent, a6 as ProducerWireEvent, a7 as SandboxMentionPathCheck, a8 as assertPromptPartsWithinCap, a9 as base64WireLen, aa as buildMentionPromptBlock, ab as chatTurnRequestInit, ac as fileMentionsToParts, ad as formatBytes, ae as mediaTypeForMentionPath, af as mentionKindForPath, ag as parseChatTurnParts, ah as parseFileMentions, ai as promptPartsByteSize, aj as validateSandboxMentionPath } from '../parts-n9XUon0a.js';
|
|
3
3
|
export { A as ALLOWED_ATTACHMENT_SNIFFED_MIMES, a as ATTACHMENT_ACCEPT, b as ATTACHMENT_MAX_COUNT, c as AttachmentTypeCheckResult, C as CreateSandboxFileIndexRouteOptions, F as FileIndexAuthorization, d as FileIndexCache, e as FileIndexReadyResponse, f as FileIndexResponse, g as FileIndexWarmingResponse, M as MAX_ATTACHMENT_TOTAL_BYTES, h as MAX_BINARY_ATTACHMENT_BYTES, i as MAX_TEXT_ATTACHMENT_BYTES, S as SandboxFileTreeSource, j as SandboxTreeFile, k as SandboxTreeResult, l as SniffResult, m as attachmentSizeErrorMessage, n as attachmentTotalSizeErrorMessage, o as checkAttachmentType, p as createSandboxFileIndexRoute, s as sanitizeAttachmentFileName, q as sniffBinary } from '../attachment-validation-tPRp-PP1.js';
|
|
4
4
|
import { ChatTurnIdentity, ChatTurnProducer } from '@tangle-network/agent-runtime';
|
|
@@ -6,7 +6,7 @@ import { InteractionAnswerRoute, InteractionAnswerRouteOptions } from '../intera
|
|
|
6
6
|
import { PersistedChatMessageForTurn } from '../stream/index.js';
|
|
7
7
|
import { d as TurnEventStore } from '../turn-buffer-DGnAPKwa.js';
|
|
8
8
|
export { D as DEFAULT_STALE_TURN_LOCK_GRACE_MS, a as DEFAULT_TERMINAL_TURN_LOCK_GRACE_MS, R as ReconcileStaleTurnLockOptions, b as ReconcileStaleTurnLockResult, S as StaleTurnLockSandboxProbeResult, c as StaleTurnLockSessionProbeResult, r as reconcileStaleTurnLock } from '../stale-turn-lock-DucQzvXu.js';
|
|
9
|
-
import { J as JsonRecord } from '../stream-normalizer-
|
|
9
|
+
import { J as JsonRecord } from '../stream-normalizer-BlCP_Cdd.js';
|
|
10
10
|
import { SandboxExecChannel, PromptInputPart } from '../sandbox/index.js';
|
|
11
11
|
import '@tangle-network/agent-interface';
|
|
12
12
|
import '../contract-TjB68uqA.js';
|
|
@@ -17,6 +17,177 @@ import '../types-CBRyqijY.js';
|
|
|
17
17
|
import '../harness/index.js';
|
|
18
18
|
import '../model-DmdkIteM.js';
|
|
19
19
|
|
|
20
|
+
/**
|
|
21
|
+
* Incremental ("draft") persistence of the assistant row WHILE a turn streams.
|
|
22
|
+
*
|
|
23
|
+
* Why this exists — the scale argument, not a convenience:
|
|
24
|
+
*
|
|
25
|
+
* A live turn is readable from two places. The hot path is the session
|
|
26
|
+
* gateway's in-memory/Redis event buffer, which exists so a viewer survives a
|
|
27
|
+
* network blip: it is keyed one sorted set per session, refreshed on every
|
|
28
|
+
* push, and expires on a TTL. Its memory cost is `arrival_rate x TTL x
|
|
29
|
+
* bytes_per_session` — strictly LINEAR in the TTL. Stretching that TTL to
|
|
30
|
+
* cover "a viewer who opens the tab later" is a category error: it buys memory
|
|
31
|
+
* proportional to the increase and still serves nothing to a viewer who
|
|
32
|
+
* arrives past the new horizon.
|
|
33
|
+
*
|
|
34
|
+
* So the hot buffer must stay SHORT (live delivery + reconnect only), and
|
|
35
|
+
* durable storage must serve history. That only works if durable storage
|
|
36
|
+
* actually HAS the in-flight turn — which, before this module, it did not: the
|
|
37
|
+
* assistant row was written once, after the stream drained. A viewer arriving
|
|
38
|
+
* mid-turn past the hot window read an empty transcript.
|
|
39
|
+
*
|
|
40
|
+
* This module closes that gap: the assistant row is inserted early and patched
|
|
41
|
+
* on a coalesced cadence, so the durable transcript is at most one interval
|
|
42
|
+
* (default 2 s) behind the live stream and the hot buffer never has to be the
|
|
43
|
+
* history tier.
|
|
44
|
+
*
|
|
45
|
+
* Mechanism only. It owns no vocabulary: the caller supplies the snapshot
|
|
46
|
+
* function, the store, and the deterministic row id.
|
|
47
|
+
*
|
|
48
|
+
* Four properties the cadence guarantees:
|
|
49
|
+
* - **Time-floored.** At most one write per `intervalMs`, never one per token.
|
|
50
|
+
* - **Dirty-gated.** Only content-bearing events arm a write; heartbeats,
|
|
51
|
+
* status pings, and lifecycle envelopes never do.
|
|
52
|
+
* - **Single-flight.** A write already in flight suppresses the next trigger
|
|
53
|
+
* instead of queueing; the final write is authoritative regardless of how
|
|
54
|
+
* many drafts landed.
|
|
55
|
+
* - **Best-effort.** A store failure is logged and swallowed — a durability
|
|
56
|
+
* optimization must never kill a healthy stream (the same rule
|
|
57
|
+
* `withDurableChatProjection` already states).
|
|
58
|
+
*/
|
|
59
|
+
|
|
60
|
+
/** Message row shape the writer reads back when re-entering a turn. */
|
|
61
|
+
interface DraftStoredMessage {
|
|
62
|
+
id: string;
|
|
63
|
+
role: 'user' | 'assistant' | 'system' | 'tool';
|
|
64
|
+
content: string;
|
|
65
|
+
parts?: ChatMessagePart[] | null;
|
|
66
|
+
}
|
|
67
|
+
/** Values written to the assistant row — the intersection of the append and
|
|
68
|
+
* patch shapes, so one snapshot serves both. */
|
|
69
|
+
interface AssistantRowValues {
|
|
70
|
+
content: string;
|
|
71
|
+
parts?: ChatMessagePart[];
|
|
72
|
+
model?: string | null;
|
|
73
|
+
inputTokens?: number | null;
|
|
74
|
+
outputTokens?: number | null;
|
|
75
|
+
reasoningTokens?: number | null;
|
|
76
|
+
cacheReadTokens?: number | null;
|
|
77
|
+
cacheWriteTokens?: number | null;
|
|
78
|
+
costUsd?: number | null;
|
|
79
|
+
}
|
|
80
|
+
/** The store capability incremental persistence needs on top of
|
|
81
|
+
* `appendMessage`. A store without `updateMessage` cannot patch a row, so it
|
|
82
|
+
* cannot draft at all — the caller keeps today's single-write behavior. */
|
|
83
|
+
interface AssistantDraftStore {
|
|
84
|
+
listMessages(threadId: string): Promise<DraftStoredMessage[]>;
|
|
85
|
+
appendMessage(input: AssistantRowValues & {
|
|
86
|
+
id?: string;
|
|
87
|
+
threadId: string;
|
|
88
|
+
role: 'user' | 'assistant';
|
|
89
|
+
}): Promise<unknown>;
|
|
90
|
+
updateMessage?(id: string, patch: AssistantRowValues): Promise<unknown>;
|
|
91
|
+
deleteMessage?(id: string): Promise<unknown>;
|
|
92
|
+
}
|
|
93
|
+
/** Live snapshot of the assistant body, taken from the producer's own
|
|
94
|
+
* accumulators. `parts` is the DRAFT projection (`draftParts()`), never the
|
|
95
|
+
* finalized one — see `draftAssistantParts`. */
|
|
96
|
+
interface AssistantDraftSnapshot {
|
|
97
|
+
content: string;
|
|
98
|
+
parts?: Array<Record<string, unknown>>;
|
|
99
|
+
usage?: ChatTurnUsage;
|
|
100
|
+
model?: string;
|
|
101
|
+
}
|
|
102
|
+
/** Product-tunable cadence. Defaults are stated on each field; a product with
|
|
103
|
+
* a chattier or heavier workload moves them without forking the writer. */
|
|
104
|
+
interface DraftPersistenceTuning {
|
|
105
|
+
/** Minimum wall-clock gap between draft writes, in ms. Default 2000.
|
|
106
|
+
*
|
|
107
|
+
* Justification for 2 s, from a measured tool-heavy production run (517
|
|
108
|
+
* stream events over ~90 s wall = ~5.7 events/s): a 2 s floor with the
|
|
109
|
+
* dirty gate turns 517 candidate writes into <= 45, while leaving the
|
|
110
|
+
* durable row at most 2 s stale — an order of magnitude below the time it
|
|
111
|
+
* takes a viewer to open a tab and render, so a late viewer never perceives
|
|
112
|
+
* the lag. Fleet arithmetic at 10k concurrent 60 s runs: <= 30 updates per
|
|
113
|
+
* run x 167 run-starts/s = ~334 row-updates/s spread over per-tenant
|
|
114
|
+
* shards. Lower it and write amplification grows with no perceptible
|
|
115
|
+
* freshness gain; raise it past ~5 s and a late viewer starts seeing a
|
|
116
|
+
* visibly truncated answer. */
|
|
117
|
+
intervalMs?: number;
|
|
118
|
+
/** Serialized-parts size (bytes) past which the interval backs off, so a
|
|
119
|
+
* turn accumulating a megabyte-scale `parts` blob does not rewrite it every
|
|
120
|
+
* interval. Default 262144 (256 KiB) -> interval x 2.5; ten times that ->
|
|
121
|
+
* interval x 5. The final write is never throttled. */
|
|
122
|
+
backoffBytes?: number;
|
|
123
|
+
/** Per-tool-part output cap applied to DRAFTS ONLY (bytes). A tool returning
|
|
124
|
+
* a large blob would otherwise be rewritten in full on every draft. The
|
|
125
|
+
* final write always carries the untruncated value. Default 32768 (32 KiB);
|
|
126
|
+
* 0 disables truncation. */
|
|
127
|
+
maxDraftToolOutputBytes?: number;
|
|
128
|
+
}
|
|
129
|
+
/** Define the inputs required to construct an assistant draft writer */
|
|
130
|
+
interface AssistantDraftWriterOptions extends DraftPersistenceTuning {
|
|
131
|
+
store: AssistantDraftStore;
|
|
132
|
+
threadId: string;
|
|
133
|
+
/** DETERMINISTIC row id for this turn's assistant message — the whole
|
|
134
|
+
* idempotency mechanism. Derived from the turn's existing identity
|
|
135
|
+
* (`deriveExecutionId` in the interactive lane, the turn id in the detached
|
|
136
|
+
* lane), so a re-entered turn addresses the SAME row: the writer looks the
|
|
137
|
+
* id up before its first insert and patches what it finds. */
|
|
138
|
+
messageId: string;
|
|
139
|
+
/** Read the producer's live accumulators. Returns null before the producer
|
|
140
|
+
* is resolved (the assembly defers box resolution into the first pull). */
|
|
141
|
+
snapshot(): AssistantDraftSnapshot | null;
|
|
142
|
+
/** Pre-persist text transform (`/redact`'s `redactPII`). Applied to the
|
|
143
|
+
* draft's scalar content AND every draft text part — parity with the final
|
|
144
|
+
* write, or incremental persistence would re-open the at-rest PII leak that
|
|
145
|
+
* transform closed, just seconds earlier and on every turn. */
|
|
146
|
+
transformText?(text: string): string | Promise<string>;
|
|
147
|
+
log?: (message: string, meta?: Record<string, unknown>) => void;
|
|
148
|
+
}
|
|
149
|
+
/** Coalescing writer that keeps one durable assistant row in step with a
|
|
150
|
+
* streaming turn. Created per turn; not reusable. */
|
|
151
|
+
interface AssistantDraftWriter {
|
|
152
|
+
/** Arm/trigger a draft write from one engine event. Synchronous by design —
|
|
153
|
+
* the write itself is fire-and-forget so the stream is never blocked on
|
|
154
|
+
* store latency. */
|
|
155
|
+
notify(event: {
|
|
156
|
+
type?: unknown;
|
|
157
|
+
}): void;
|
|
158
|
+
/** Stop drafting and settle any in-flight write. Called before the final
|
|
159
|
+
* write so a late draft can never clobber the authoritative row. */
|
|
160
|
+
close(): Promise<void>;
|
|
161
|
+
/** Write the AUTHORITATIVE completion values onto this turn's row —
|
|
162
|
+
* insert-or-patch under the same deterministic id, un-throttled and
|
|
163
|
+
* un-truncated. Errors propagate: the final write is the one that must not
|
|
164
|
+
* fail silently. Implies {@link close}. */
|
|
165
|
+
finalize(values: AssistantRowValues): Promise<void>;
|
|
166
|
+
/** The durable row this turn is writing, once one exists. */
|
|
167
|
+
rowId(): string | undefined;
|
|
168
|
+
/** Retract the row for a turn that produced nothing (mirrors the final
|
|
169
|
+
* write's empty-turn skip, which leaves no row at all today). Also retracts
|
|
170
|
+
* a row a PREVIOUS attempt left behind, so a re-entered turn that ends
|
|
171
|
+
* empty converges on "no row" rather than a stale partial. */
|
|
172
|
+
discard(): Promise<void>;
|
|
173
|
+
/** Diagnostics: how many draft writes actually reached the store. */
|
|
174
|
+
writeCount(): number;
|
|
175
|
+
}
|
|
176
|
+
/** True when this event should arm a draft write. */
|
|
177
|
+
declare function isDraftContentEvent(event: {
|
|
178
|
+
type?: unknown;
|
|
179
|
+
}): boolean;
|
|
180
|
+
/** Build the coalescing draft writer for one turn. */
|
|
181
|
+
declare function createAssistantDraftWriter(options: AssistantDraftWriterOptions): AssistantDraftWriter;
|
|
182
|
+
/** True when a store can support incremental persistence at all. Without
|
|
183
|
+
* `updateMessage` a draft row could never be patched, so the caller keeps
|
|
184
|
+
* today's exact single-write behavior. */
|
|
185
|
+
declare function storeSupportsDraftPersistence(store: AssistantDraftStore): boolean;
|
|
186
|
+
/** The default deterministic assistant-row id for a turn. Readable on purpose
|
|
187
|
+
* (an operator grepping a transcript row id finds the run), and stable across
|
|
188
|
+
* re-entries because every input already is. */
|
|
189
|
+
declare function assistantRowIdForTurn(turnKey: string): string;
|
|
190
|
+
|
|
20
191
|
/**
|
|
21
192
|
* `createChatTurnRoutes` — the assembled server chat vertical (issue #188
|
|
22
193
|
* Phase 1). One factory composing the pieces every product re-wired by hand:
|
|
@@ -80,6 +251,10 @@ interface ChatTurnMessageStore {
|
|
|
80
251
|
parts?: ChatMessagePart[] | null;
|
|
81
252
|
}>>;
|
|
82
253
|
appendMessage(input: {
|
|
254
|
+
/** Caller-assigned row id. Honored by `/chat-store`'s `createChatStore`;
|
|
255
|
+
* a product store free to ignore it (the writer then adopts whatever id
|
|
256
|
+
* the insert returns). Set only by incremental persistence. */
|
|
257
|
+
id?: string;
|
|
83
258
|
threadId: string;
|
|
84
259
|
role: 'user' | 'assistant';
|
|
85
260
|
content: string;
|
|
@@ -92,12 +267,35 @@ interface ChatTurnMessageStore {
|
|
|
92
267
|
cacheWriteTokens?: number | null;
|
|
93
268
|
costUsd?: number | null;
|
|
94
269
|
}): Promise<unknown>;
|
|
270
|
+
/** Patch an existing row. Its PRESENCE is what enables incremental assistant
|
|
271
|
+
* persistence — a store without it keeps today's exact single-write-on-
|
|
272
|
+
* completion behavior, which is what makes this additive. */
|
|
273
|
+
updateMessage?(id: string, patch: {
|
|
274
|
+
content?: string;
|
|
275
|
+
parts?: ChatMessagePart[];
|
|
276
|
+
model?: string | null;
|
|
277
|
+
inputTokens?: number | null;
|
|
278
|
+
outputTokens?: number | null;
|
|
279
|
+
reasoningTokens?: number | null;
|
|
280
|
+
cacheReadTokens?: number | null;
|
|
281
|
+
cacheWriteTokens?: number | null;
|
|
282
|
+
costUsd?: number | null;
|
|
283
|
+
}): Promise<unknown>;
|
|
284
|
+
/** Remove a row. Used to retract a draft assistant row for a turn that ended
|
|
285
|
+
* producing nothing, so the empty-turn case still leaves no row at all. */
|
|
286
|
+
deleteMessage?(id: string): Promise<unknown>;
|
|
95
287
|
}
|
|
96
288
|
/** `ChatTurnProducer` plus the persisted projection the assembly reads after
|
|
97
289
|
* drain. `createSandboxChatProducer` returns this; a router-lane producer
|
|
98
290
|
* may omit the optional members (finalText persists as a single text part). */
|
|
99
291
|
interface ChatTurnRouteProducer extends ChatTurnProducer {
|
|
100
292
|
assistantParts?(): Array<Record<string, unknown>>;
|
|
293
|
+
/** MID-STREAM snapshot of the same projection, safe to call while the turn
|
|
294
|
+
* is running: no dangling-tool terminalization, no pending-ask settlement
|
|
295
|
+
* (see `/stream`'s `draftAssistantParts`). Read by incremental persistence.
|
|
296
|
+
* A producer that omits it still drafts — the scalar text — but persists no
|
|
297
|
+
* parts until the turn completes. */
|
|
298
|
+
draftParts?(): Array<Record<string, unknown>>;
|
|
101
299
|
usage?(): ChatTurnUsage;
|
|
102
300
|
model?: string;
|
|
103
301
|
}
|
|
@@ -276,6 +474,34 @@ interface CreateChatTurnRoutesOptions<TContext = void> {
|
|
|
276
474
|
/** Pre-persist transform of the final text (e.g. `/redact`'s `redactPII`).
|
|
277
475
|
* Live stream is never altered. */
|
|
278
476
|
transformFinalText?(text: string): string | Promise<string>;
|
|
477
|
+
/** Incremental persistence of the assistant row WHILE the turn streams
|
|
478
|
+
* (`./draft-persistence`), so a viewer arriving mid-run is served from
|
|
479
|
+
* durable storage instead of the streaming gateway's hot event buffer.
|
|
480
|
+
*
|
|
481
|
+
* This is what lets the gateway keep that hot buffer SHORT at scale: its
|
|
482
|
+
* Redis footprint is one sorted set per session refreshed on every push, so
|
|
483
|
+
* memory grows LINEARLY with `ttl x concurrent sessions`. Stretching the
|
|
484
|
+
* TTL to cover late viewers buys memory proportional to the increase and
|
|
485
|
+
* still serves nothing past the new horizon. The buffer stays a reconnect
|
|
486
|
+
* window; durable storage — kept at most one cadence interval stale by this
|
|
487
|
+
* option — is the history tier.
|
|
488
|
+
*
|
|
489
|
+
* Enabled by DEFAULT whenever `store.updateMessage` exists (every
|
|
490
|
+
* `/chat-store` consumer); a store without it keeps today's exact
|
|
491
|
+
* single-write behavior. Pass `false` to opt out, or an object to tune the
|
|
492
|
+
* cadence. Wiring it against a store that cannot patch rows throws at route
|
|
493
|
+
* construction rather than silently no-op'ing. */
|
|
494
|
+
incrementalPersistence?: false | DraftPersistenceTuning;
|
|
495
|
+
/** Deterministic durable row id for this turn's assistant message. Default
|
|
496
|
+
* `assistant:<executionId>` — already stable across retries because
|
|
497
|
+
* `deriveExecutionId` is. Override only if the product's message ids have a
|
|
498
|
+
* format constraint; it MUST stay deterministic per turn or a re-entered
|
|
499
|
+
* turn will duplicate its row instead of converging. */
|
|
500
|
+
draftMessageId?(args: {
|
|
501
|
+
identity: ChatTurnIdentity;
|
|
502
|
+
executionId: string;
|
|
503
|
+
threadId: string;
|
|
504
|
+
}): string;
|
|
279
505
|
/** Post-processing after a turn settles (billing, titles, audit). Fires with
|
|
280
506
|
* `failed:true` + `failureReason` when the turn carried a terminal error
|
|
281
507
|
* event (model 402 / rate-limit / server error) instead of a clean
|
|
@@ -508,6 +734,35 @@ interface DetachedTurnOptions {
|
|
|
508
734
|
* Unset, a re-stream over a `running` buffer is still attempted but logged
|
|
509
735
|
* as a possible-duplication hazard. */
|
|
510
736
|
resetBuffer?: (turnId: string) => Promise<void>;
|
|
737
|
+
/** Own the durable assistant row for this turn instead of returning the body
|
|
738
|
+
* for the caller to insert — and keep it in step with the stream.
|
|
739
|
+
*
|
|
740
|
+
* An autonomous run is exactly the case a late viewer hits: nobody is
|
|
741
|
+
* watching when it starts, so by the time a browser opens the session the
|
|
742
|
+
* streaming gateway's hot event buffer may already have expired it. Keeping
|
|
743
|
+
* that buffer short is what makes it affordable at scale (its Redis
|
|
744
|
+
* footprint is linear in `ttl x concurrent sessions`), so the durable row —
|
|
745
|
+
* written incrementally here — is what serves the late viewer.
|
|
746
|
+
*
|
|
747
|
+
* WIRING THIS TRANSFERS ROW OWNERSHIP: the returned {@link
|
|
748
|
+
* DetachedTurnResult.messageId} names the row this call wrote (draft rows
|
|
749
|
+
* during the stream, authoritative values at the end, retraction when the
|
|
750
|
+
* turn produced nothing). The caller must NOT insert its own assistant row
|
|
751
|
+
* for the turn. Omit the seam and nothing changes — the result is returned
|
|
752
|
+
* and the caller persists it exactly as today.
|
|
753
|
+
*
|
|
754
|
+
* Idempotency reuses the turn's own identity: the row id defaults to
|
|
755
|
+
* `assistant:<turnId>`, so a durable driver re-invoking after a crash
|
|
756
|
+
* patches the same row instead of duplicating parts. */
|
|
757
|
+
persist?: DraftPersistenceTuning & {
|
|
758
|
+
store: AssistantDraftStore;
|
|
759
|
+
threadId: string;
|
|
760
|
+
/** Deterministic row id. Default `assistant:<turnId>`. */
|
|
761
|
+
messageId?: string;
|
|
762
|
+
/** Pre-persist text transform (`/redact`), applied to drafts AND the final
|
|
763
|
+
* write — parity with the interactive lane's `transformFinalText`. */
|
|
764
|
+
transformText?: (text: string) => string | Promise<string>;
|
|
765
|
+
};
|
|
511
766
|
log?: (message: string, meta?: Record<string, unknown>) => void;
|
|
512
767
|
}
|
|
513
768
|
/** Describe the result of a detached turn including state, text, parts, usage, and optional error or cache flag */
|
|
@@ -526,6 +781,10 @@ interface DetachedTurnResult {
|
|
|
526
781
|
/** True when a prior buffer meant this call returned a cached/finished result
|
|
527
782
|
* WITHOUT re-streaming (durable-driver retry after a crash). */
|
|
528
783
|
cached: boolean;
|
|
784
|
+
/** The durable assistant row this call wrote, when `persist` was wired.
|
|
785
|
+
* `null` when the turn produced nothing and the row was retracted. Absent
|
|
786
|
+
* when the caller owns persistence (today's behavior). */
|
|
787
|
+
messageId?: string | null;
|
|
529
788
|
}
|
|
530
789
|
/**
|
|
531
790
|
* Stream a detached turn into the live turn-event buffer, durably.
|
|
@@ -1051,4 +1310,4 @@ interface PromoteAgentFilePartOptions {
|
|
|
1051
1310
|
/** Promote a part of an agent file with optional byte limits and MIME type detection */
|
|
1052
1311
|
declare function promoteAgentFilePart(options: PromoteAgentFilePartOptions): Promise<PromoteFilePartResult>;
|
|
1053
1312
|
|
|
1054
|
-
export { type AttachmentPathArgs, type AttachmentPathCheck, type AttachmentReadResult, type AttachmentUploadAuthorization, type AttachmentWriteResult, type BuildDispatchPartsInput, ChatAttachmentKind, type ChatRouteDurableProjection, type ChatRouteDurableProjectionLogger, type ChatTurnAuthorization, type ChatTurnAuthorizeArgs, ChatTurnFilePartInput, type ChatTurnGateResult, type ChatTurnHeartbeat, type ChatTurnInputPatch, type ChatTurnLifecycle, type ChatTurnLifecycleComplete, type ChatTurnLifecycleError, type ChatTurnLifecycleStart, type ChatTurnLock, type ChatTurnLockResult, type ChatTurnMessageStore, ChatTurnPartInput, type ChatTurnProduceArgs, ChatTurnRequestPayload, type ChatTurnRouteProducer, type ChatTurnRoutes, type ChatTurnUsage, type CreateAttachmentUploadRouteOptions, type CreateChatTurnRoutesOptions, type CreateUploadRouteOptions, type DetachedTurnFinal, type DetachedTurnOptions, type DetachedTurnParts, type DetachedTurnResult, type DispatchPartsOutcome, type FilePartPromotionOutcome, PROMOTE_MAX_FILE_BYTES, type PromoteAgentFilePartOptions, type PromoteFilePartResult, PromptInputPart, type RawAgentFilePart, type ReadAttachmentFn, type ReadSandboxMentionFn, type ResolveChatAttachmentsOptions, type ResolveChatAttachmentsResult, type SandboxChatProducerOptions, type SandboxUploadSink, UPLOAD_INLINE_MAX_BYTES, UPLOAD_MAX_FILE_BYTES, type UploadAuthorization, type UploadedChatFile, type WriteAttachmentFn, buildDispatchParts, bytesToBase64, createAttachmentUploadRoute, createChatTurnRoutes, createSandboxChatProducer, createUploadRoute, defaultValidateAttachmentPath, promoteAgentFilePart, resolveChatAttachments, runDetachedTurn, sanitizeUploadFilename, sniffMimeFromName, withDurableChatProjection };
|
|
1313
|
+
export { type AssistantDraftSnapshot, type AssistantDraftStore, type AssistantDraftWriter, type AssistantDraftWriterOptions, type AssistantRowValues, type AttachmentPathArgs, type AttachmentPathCheck, type AttachmentReadResult, type AttachmentUploadAuthorization, type AttachmentWriteResult, type BuildDispatchPartsInput, ChatAttachmentKind, type ChatRouteDurableProjection, type ChatRouteDurableProjectionLogger, type ChatTurnAuthorization, type ChatTurnAuthorizeArgs, ChatTurnFilePartInput, type ChatTurnGateResult, type ChatTurnHeartbeat, type ChatTurnInputPatch, type ChatTurnLifecycle, type ChatTurnLifecycleComplete, type ChatTurnLifecycleError, type ChatTurnLifecycleStart, type ChatTurnLock, type ChatTurnLockResult, type ChatTurnMessageStore, ChatTurnPartInput, type ChatTurnProduceArgs, ChatTurnRequestPayload, type ChatTurnRouteProducer, type ChatTurnRoutes, type ChatTurnUsage, type CreateAttachmentUploadRouteOptions, type CreateChatTurnRoutesOptions, type CreateUploadRouteOptions, type DetachedTurnFinal, type DetachedTurnOptions, type DetachedTurnParts, type DetachedTurnResult, type DispatchPartsOutcome, type DraftPersistenceTuning, type DraftStoredMessage, type FilePartPromotionOutcome, PROMOTE_MAX_FILE_BYTES, type PromoteAgentFilePartOptions, type PromoteFilePartResult, PromptInputPart, type RawAgentFilePart, type ReadAttachmentFn, type ReadSandboxMentionFn, type ResolveChatAttachmentsOptions, type ResolveChatAttachmentsResult, type SandboxChatProducerOptions, type SandboxUploadSink, UPLOAD_INLINE_MAX_BYTES, UPLOAD_MAX_FILE_BYTES, type UploadAuthorization, type UploadedChatFile, type WriteAttachmentFn, assistantRowIdForTurn, buildDispatchParts, bytesToBase64, createAssistantDraftWriter, createAttachmentUploadRoute, createChatTurnRoutes, createSandboxChatProducer, createUploadRoute, defaultValidateAttachmentPath, isDraftContentEvent, promoteAgentFilePart, resolveChatAttachments, runDetachedTurn, sanitizeUploadFilename, sniffMimeFromName, storeSupportsDraftPersistence, withDurableChatProjection };
|