@trigger.dev/sdk 4.5.16 → 4.6.0

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.
Files changed (156) hide show
  1. package/dist/commonjs/imports/ai-runtime-cjs.cjs.map +1 -1
  2. package/dist/commonjs/imports/ai-runtime.js +2 -0
  3. package/dist/commonjs/v3/ai-shared.d.ts +15 -0
  4. package/dist/commonjs/v3/ai-shared.js +35 -1
  5. package/dist/commonjs/v3/ai-shared.js.map +1 -1
  6. package/dist/commonjs/v3/ai.d.ts +311 -25
  7. package/dist/commonjs/v3/ai.js +1633 -380
  8. package/dist/commonjs/v3/ai.js.map +1 -1
  9. package/dist/commonjs/v3/auth.d.ts +10 -4
  10. package/dist/commonjs/v3/auth.js.map +1 -1
  11. package/dist/commonjs/v3/chat-client.d.ts +11 -2
  12. package/dist/commonjs/v3/chat-client.js +227 -111
  13. package/dist/commonjs/v3/chat-client.js.map +1 -1
  14. package/dist/commonjs/v3/chat-react.d.ts +88 -0
  15. package/dist/commonjs/v3/chat-react.js +130 -1
  16. package/dist/commonjs/v3/chat-react.js.map +1 -1
  17. package/dist/commonjs/v3/chat-server.d.ts +42 -6
  18. package/dist/commonjs/v3/chat-server.js +52 -7
  19. package/dist/commonjs/v3/chat-server.js.map +1 -1
  20. package/dist/commonjs/v3/chat.d.ts +92 -10
  21. package/dist/commonjs/v3/chat.js +328 -73
  22. package/dist/commonjs/v3/chat.js.map +1 -1
  23. package/dist/commonjs/v3/chatSnapshotIo.d.ts +2 -0
  24. package/dist/commonjs/v3/chatSnapshotIo.js +173 -0
  25. package/dist/commonjs/v3/chatSnapshotIo.js.map +1 -0
  26. package/dist/commonjs/v3/chatVersionSkew.d.ts +12 -0
  27. package/dist/commonjs/v3/chatVersionSkew.js +30 -0
  28. package/dist/commonjs/v3/chatVersionSkew.js.map +1 -0
  29. package/dist/commonjs/v3/externalDeploymentId.d.ts +23 -0
  30. package/dist/commonjs/v3/externalDeploymentId.js +43 -0
  31. package/dist/commonjs/v3/externalDeploymentId.js.map +1 -0
  32. package/dist/commonjs/v3/retry.d.ts +4 -0
  33. package/dist/commonjs/v3/retry.js +22 -13
  34. package/dist/commonjs/v3/retry.js.map +1 -1
  35. package/dist/commonjs/v3/sessions.d.ts +15 -2
  36. package/dist/commonjs/v3/sessions.js +12 -1
  37. package/dist/commonjs/v3/sessions.js.map +1 -1
  38. package/dist/commonjs/v3/shared.js +30 -36
  39. package/dist/commonjs/v3/shared.js.map +1 -1
  40. package/dist/commonjs/v3/test/index.d.ts +1 -0
  41. package/dist/commonjs/v3/test/index.js +3 -1
  42. package/dist/commonjs/v3/test/index.js.map +1 -1
  43. package/dist/commonjs/v3/test/mock-chat-agent.d.ts +47 -4
  44. package/dist/commonjs/v3/test/mock-chat-agent.js +116 -10
  45. package/dist/commonjs/v3/test/mock-chat-agent.js.map +1 -1
  46. package/dist/commonjs/v3/test/test-session-handle.js +6 -0
  47. package/dist/commonjs/v3/test/test-session-handle.js.map +1 -1
  48. package/dist/commonjs/v3/test/transcript-storage-tests.d.ts +40 -0
  49. package/dist/commonjs/v3/test/transcript-storage-tests.js +258 -0
  50. package/dist/commonjs/v3/test/transcript-storage-tests.js.map +1 -0
  51. package/dist/commonjs/v3/transcriptStorage.d.ts +261 -0
  52. package/dist/commonjs/v3/transcriptStorage.js +374 -0
  53. package/dist/commonjs/v3/transcriptStorage.js.map +1 -0
  54. package/dist/commonjs/version.js +1 -1
  55. package/dist/esm/imports/ai-runtime.d.ts +2 -2
  56. package/dist/esm/imports/ai-runtime.js +2 -2
  57. package/dist/esm/imports/ai-runtime.js.map +1 -1
  58. package/dist/esm/v3/ai-shared.d.ts +15 -0
  59. package/dist/esm/v3/ai-shared.js +33 -0
  60. package/dist/esm/v3/ai-shared.js.map +1 -1
  61. package/dist/esm/v3/ai.d.ts +311 -25
  62. package/dist/esm/v3/ai.js +1625 -377
  63. package/dist/esm/v3/ai.js.map +1 -1
  64. package/dist/esm/v3/auth.d.ts +10 -4
  65. package/dist/esm/v3/auth.js.map +1 -1
  66. package/dist/esm/v3/chat-client.d.ts +11 -2
  67. package/dist/esm/v3/chat-client.js +228 -112
  68. package/dist/esm/v3/chat-client.js.map +1 -1
  69. package/dist/esm/v3/chat-react.d.ts +88 -0
  70. package/dist/esm/v3/chat-react.js +127 -1
  71. package/dist/esm/v3/chat-react.js.map +1 -1
  72. package/dist/esm/v3/chat-server.d.ts +42 -6
  73. package/dist/esm/v3/chat-server.js +53 -8
  74. package/dist/esm/v3/chat-server.js.map +1 -1
  75. package/dist/esm/v3/chat.d.ts +92 -10
  76. package/dist/esm/v3/chat.js +329 -74
  77. package/dist/esm/v3/chat.js.map +1 -1
  78. package/dist/esm/v3/chatSnapshotIo.d.ts +2 -0
  79. package/dist/esm/v3/chatSnapshotIo.js +165 -0
  80. package/dist/esm/v3/chatSnapshotIo.js.map +1 -0
  81. package/dist/esm/v3/chatVersionSkew.d.ts +12 -0
  82. package/dist/esm/v3/chatVersionSkew.js +27 -0
  83. package/dist/esm/v3/chatVersionSkew.js.map +1 -0
  84. package/dist/esm/v3/externalDeploymentId.d.ts +23 -0
  85. package/dist/esm/v3/externalDeploymentId.js +38 -0
  86. package/dist/esm/v3/externalDeploymentId.js.map +1 -0
  87. package/dist/esm/v3/retry.d.ts +4 -0
  88. package/dist/esm/v3/retry.js +14 -8
  89. package/dist/esm/v3/retry.js.map +1 -1
  90. package/dist/esm/v3/sessions.d.ts +15 -2
  91. package/dist/esm/v3/sessions.js +11 -1
  92. package/dist/esm/v3/sessions.js.map +1 -1
  93. package/dist/esm/v3/shared.js +17 -23
  94. package/dist/esm/v3/shared.js.map +1 -1
  95. package/dist/esm/v3/test/index.d.ts +1 -0
  96. package/dist/esm/v3/test/index.js +1 -0
  97. package/dist/esm/v3/test/index.js.map +1 -1
  98. package/dist/esm/v3/test/mock-chat-agent.d.ts +47 -4
  99. package/dist/esm/v3/test/mock-chat-agent.js +118 -12
  100. package/dist/esm/v3/test/mock-chat-agent.js.map +1 -1
  101. package/dist/esm/v3/test/test-session-handle.js +6 -0
  102. package/dist/esm/v3/test/test-session-handle.js.map +1 -1
  103. package/dist/esm/v3/test/transcript-storage-tests.d.ts +40 -0
  104. package/dist/esm/v3/test/transcript-storage-tests.js +255 -0
  105. package/dist/esm/v3/test/transcript-storage-tests.js.map +1 -0
  106. package/dist/esm/v3/transcriptStorage.d.ts +261 -0
  107. package/dist/esm/v3/transcriptStorage.js +360 -0
  108. package/dist/esm/v3/transcriptStorage.js.map +1 -0
  109. package/dist/esm/version.js +1 -1
  110. package/docs/ai-chat/actions.mdx +55 -23
  111. package/docs/ai-chat/anatomy.mdx +47 -27
  112. package/docs/ai-chat/backend.mdx +125 -48
  113. package/docs/ai-chat/background-injection.mdx +122 -19
  114. package/docs/ai-chat/client-protocol.mdx +5 -4
  115. package/docs/ai-chat/compaction.mdx +13 -7
  116. package/docs/ai-chat/custom-agents.mdx +23 -0
  117. package/docs/ai-chat/fast-starts.mdx +27 -20
  118. package/docs/ai-chat/frontend.mdx +19 -14
  119. package/docs/ai-chat/how-it-works.mdx +1 -1
  120. package/docs/ai-chat/lifecycle-hooks.mdx +6 -2
  121. package/docs/ai-chat/migrating-from-a-route-handler.mdx +16 -14
  122. package/docs/ai-chat/migrating-from-hydrate-messages.mdx +299 -0
  123. package/docs/ai-chat/patterns/database-persistence.mdx +24 -9
  124. package/docs/ai-chat/patterns/native-compaction.mdx +310 -0
  125. package/docs/ai-chat/patterns/persistence-and-replay.mdx +34 -23
  126. package/docs/ai-chat/patterns/skills.mdx +7 -10
  127. package/docs/ai-chat/patterns/version-upgrades.mdx +79 -6
  128. package/docs/ai-chat/pending-messages.mdx +3 -3
  129. package/docs/ai-chat/prompt-caching.mdx +23 -25
  130. package/docs/ai-chat/quick-start.mdx +11 -11
  131. package/docs/ai-chat/reference.mdx +69 -10
  132. package/docs/ai-chat/sessions.mdx +6 -1
  133. package/docs/ai-chat/side-channels.mdx +1 -1
  134. package/docs/ai-chat/testing.mdx +2 -1
  135. package/docs/ai-chat/tools.mdx +18 -13
  136. package/docs/ai-chat/transcript-storage.mdx +247 -0
  137. package/docs/ai-chat/upgrade-guide.mdx +2 -2
  138. package/docs/apikeys.mdx +27 -45
  139. package/docs/config/extensions/syncEnvVars.mdx +6 -0
  140. package/docs/deploy-environment-variables.mdx +23 -2
  141. package/docs/deployment/overview.mdx +4 -8
  142. package/docs/deployment/preview-branches.mdx +4 -4
  143. package/docs/deployment/version-skew-protection.mdx +62 -0
  144. package/docs/introduction.mdx +58 -152
  145. package/docs/manual-setup.mdx +7 -7
  146. package/docs/mcp-tools.mdx +9 -0
  147. package/docs/quick-start.mdx +3 -3
  148. package/docs/realtime/auth.mdx +1 -1
  149. package/docs/reports.mdx +157 -0
  150. package/docs/self-hosting/security.mdx +17 -0
  151. package/docs/tasks/scheduled.mdx +24 -0
  152. package/docs/triggering.mdx +1 -1
  153. package/docs/troubleshooting-zod.mdx +158 -0
  154. package/package.json +4 -4
  155. package/skills/trigger-authoring-chat-agent/SKILL.md +41 -29
  156. package/skills/trigger-chat-agent-advanced/SKILL.md +54 -19
@@ -0,0 +1,261 @@
1
+ import { type TaskRunContext, type TranscriptSnapshotEntry } from "@trigger.dev/core/v3";
2
+ import type { ModelMessage, UIMessage } from "ai";
3
+ /**
4
+ * One change to a transcript. Ops address messages by id; position is the
5
+ * storage's own concern.
6
+ *
7
+ * - `put` upserts by `message.id`: an unknown id appends, a known id is
8
+ * replaced in place. `final` is false when the runtime captured a partial
9
+ * assistant message from an errored or stopped turn; it defaults to true.
10
+ * - `remove` deletes by id and is a no-op for an unknown id.
11
+ * - `truncateAfter` drops every message ordered after `afterId` (a rollback)
12
+ * and is a no-op when `afterId` is unknown.
13
+ * - `state` replaces the opaque runtime record; `null` clears it.
14
+ */
15
+ export type TranscriptChange = {
16
+ op: "put";
17
+ message: UIMessage;
18
+ final?: boolean;
19
+ } | {
20
+ op: "remove";
21
+ id: string;
22
+ } | {
23
+ op: "truncateAfter";
24
+ afterId: string;
25
+ } | {
26
+ op: "state";
27
+ value: unknown | null;
28
+ };
29
+ export type TranscriptChangeReason = "turn-start" | "turn-complete" | "turn-error" | "action" | "compaction" | "recovery";
30
+ export type TranscriptCursors = {
31
+ lastOutEventId?: string;
32
+ lastInEventId?: string;
33
+ };
34
+ /**
35
+ * What the runtime hands to `save`: the ordered changes since the last save
36
+ * (one transaction where the backend supports it), the whole transcript as
37
+ * it stands after those changes, and the stream cursors the next boot should
38
+ * resume from. A row-per-message store applies `changes`; a store that keeps
39
+ * the conversation as one document writes `transcript` as-is and needs no
40
+ * state of its own. Cursors are runtime-computed and persisted opaquely; a
41
+ * storage never interprets them.
42
+ */
43
+ export type TranscriptChangeset = {
44
+ reason: TranscriptChangeReason;
45
+ changes: TranscriptChange[];
46
+ transcript: TranscriptState;
47
+ cursors?: TranscriptCursors;
48
+ };
49
+ /** The tenant scope of a read. A render read has no run, so this is all `load` gets. */
50
+ export type TranscriptScope<TClientData = unknown> = {
51
+ chatId: string;
52
+ clientData: TClientData;
53
+ };
54
+ /** The run context of a write. Supplied by the runtime; always in-run. */
55
+ export type TranscriptStorageContext<TClientData = unknown> = TranscriptScope<TClientData> & {
56
+ turn: number;
57
+ trigger: "submit-message" | "regenerate-message" | "action";
58
+ runId: string;
59
+ ctx: TaskRunContext;
60
+ };
61
+ export type TranscriptLoadOptions = {
62
+ /** Return at most this many messages, the most recent ones. */
63
+ limit?: number;
64
+ /** Return messages ordered before this message id (a `nextCursor` from a previous page). */
65
+ before?: string;
66
+ };
67
+ export type TranscriptLoadResult<TUIMessage extends UIMessage = UIMessage> = {
68
+ messages: TUIMessage[];
69
+ state: unknown | null;
70
+ cursors?: TranscriptCursors;
71
+ /** The id to pass as `before` for the previous page; absent on the last page. */
72
+ nextCursor?: string;
73
+ /**
74
+ * Ids among `messages` that were saved with `final: false` (a partial
75
+ * answer). A storage that keeps `final` returns them so a partial stays
76
+ * partial when a continuation saves it again unchanged; a storage that
77
+ * does not keep `final` may leave this out.
78
+ */
79
+ nonFinalIds?: string[];
80
+ };
81
+ /** What `loadContext` receives on every turn and action. */
82
+ export type LoadContextEvent<TClientData = unknown, TUIMessage extends UIMessage = UIMessage> = {
83
+ chatId: string;
84
+ /** The turn number (0-indexed). */
85
+ turn: number;
86
+ trigger: "submit-message" | "regenerate-message" | "action";
87
+ /** The messages the frontend sent for this turn. Empty for actions. */
88
+ incomingMessages: TUIMessage[];
89
+ /** The runtime's transcript before this turn, including any tail it recovered. */
90
+ previousMessages: TUIMessage[];
91
+ clientData?: TClientData;
92
+ continuation: boolean;
93
+ previousRunId?: string;
94
+ };
95
+ /**
96
+ * A persistence adapter for a `chat.agent` transcript. The runtime calls
97
+ * `load` once at a continuation boot and `save` after every change to the
98
+ * conversation. Both are best-effort from the runtime's point of view: an
99
+ * error is logged and the turn continues.
100
+ *
101
+ * `loadContext` is optional. Its presence declares that the application
102
+ * owns the model's context: the runtime calls it on every turn and action
103
+ * and uses what it returns as the conversation, instead of the transcript
104
+ * it accumulated. Tail recovery still runs and `save` is still called.
105
+ */
106
+ export type TranscriptStorage<TClientData = unknown> = {
107
+ load<TUIMessage extends UIMessage = UIMessage>(scope: TranscriptScope<TClientData>, opts?: TranscriptLoadOptions): Promise<TranscriptLoadResult<TUIMessage>>;
108
+ save(ctx: TranscriptStorageContext<TClientData>, changeset: TranscriptChangeset): Promise<void>;
109
+ loadContext?<TUIMessage extends UIMessage = UIMessage>(scope: TranscriptScope<TClientData>, event: LoadContextEvent<TClientData, TUIMessage>): Promise<TUIMessage[]> | TUIMessage[];
110
+ };
111
+ /** An in-memory transcript: ordered entries plus the opaque state record. */
112
+ export type TranscriptState<TUIMessage extends UIMessage = UIMessage> = {
113
+ entries: TranscriptSnapshotEntry<TUIMessage>[];
114
+ state: unknown | null;
115
+ };
116
+ export declare function emptyTranscriptState<TUIMessage extends UIMessage = UIMessage>(): TranscriptState<TUIMessage>;
117
+ /**
118
+ * Apply changes to a transcript, in order. Pure: returns a new state and
119
+ * never mutates the input. Replaying the same changes converges, which is
120
+ * what lets a storage retry a failed write without checking what landed.
121
+ */
122
+ export declare function reduceTranscriptChanges<TUIMessage extends UIMessage = UIMessage>(prev: TranscriptState<TUIMessage>, changes: readonly TranscriptChange[]): TranscriptState<TUIMessage>;
123
+ /**
124
+ * What the runtime remembers about the transcript it last handed to
125
+ * `save`: the ids in order and a fingerprint per message, so the next
126
+ * changeset can be derived from the accumulator without asking the storage.
127
+ */
128
+ export type TranscriptShadow = {
129
+ ids: string[];
130
+ fingerprints: Map<string, string>;
131
+ /** Ids last saved with `final: false`. Everything else was saved final. */
132
+ nonFinal: Set<string>;
133
+ };
134
+ /**
135
+ * Build the shadow for `messages`. An id is non-final when this save says so
136
+ * (`nonFinalIds`) or when it was non-final before and its content has not
137
+ * changed: a partial answer stays partial until the message itself changes.
138
+ */
139
+ export declare function createTranscriptShadow(messages: readonly UIMessage[], nonFinalIds?: ReadonlySet<string>, previous?: TranscriptShadow): TranscriptShadow;
140
+ /**
141
+ * Derive the changes that take `shadow` to `next`.
142
+ *
143
+ * The common prefix (by id) is compared message by message and a changed
144
+ * message becomes an in-place `put`. Past the prefix, everything the shadow
145
+ * still had is dropped with one `truncateAfter` on the last common id (or
146
+ * one `remove` per message when there is no common prefix) and everything
147
+ * `next` has is appended with `put`, in order. Applying the result with
148
+ * {@link reduceTranscriptChanges} reproduces `next` exactly, including
149
+ * order, for any two lists.
150
+ */
151
+ export declare function diffTranscript(shadow: TranscriptShadow, next: readonly UIMessage[], options?: {
152
+ nonFinalIds?: ReadonlySet<string>;
153
+ }): {
154
+ changes: TranscriptChange[];
155
+ shadow: TranscriptShadow;
156
+ };
157
+ /**
158
+ * The built-in storage: the transcript in the platform's object store, read by
159
+ * the Sessions dashboard and the transcript API.
160
+ *
161
+ * One object per conversation, rewritten each turn, holding the transcript plus
162
+ * the runtime state. Once a conversation has been compacted, it keeps roughly
163
+ * the last hundred messages rather than all of them, so the object stops
164
+ * growing with the conversation. An app that needs the full history keeps its
165
+ * own transcript storage.
166
+ */
167
+ export declare function snapshotTranscriptStorage(): TranscriptStorage<unknown>;
168
+ /** The storage `chat.agent` uses when none is configured: {@link snapshotTranscriptStorage}. */
169
+ export declare const defaultStorage: TranscriptStorage<unknown>;
170
+ export type MemoryTranscriptStorage = TranscriptStorage<unknown> & {
171
+ /** The stored transcript for a chat, or `undefined` when nothing has been saved. */
172
+ transcript(chatId: string): (TranscriptState & {
173
+ cursors?: TranscriptCursors;
174
+ }) | undefined;
175
+ /** Every changeset `save` received, in order. */
176
+ readonly changesets: Array<{
177
+ ctx: TranscriptStorageContext<unknown>;
178
+ changeset: TranscriptChangeset;
179
+ }>;
180
+ };
181
+ /**
182
+ * A storage that keeps every transcript in process memory. The reference
183
+ * implementation for the conformance tests, and a way to inspect exactly
184
+ * what the runtime hands a storage.
185
+ */
186
+ export declare function memoryTranscriptStorage(): MemoryTranscriptStorage;
187
+ type ModelLaneInjection = {
188
+ afterId: string;
189
+ messages: ModelMessage[];
190
+ };
191
+ /**
192
+ * What the runtime keeps in the storage's `state` slot: the parts of the
193
+ * model's context that cannot be rebuilt from the transcript. Opaque to a
194
+ * storage; only the runtime reads it.
195
+ *
196
+ * `compaction` is the whole model lane after a compaction, covering the
197
+ * transcript prefix ending at `throughId`. It is used as long as `throughId`
198
+ * still exists in the transcript, so a rollback or truncation that removes it
199
+ * rebuilds the lane from the transcript instead. Editing a message before
200
+ * `throughId` in place is unsupported and does not invalidate the lane.
201
+ * `injections` are conversational messages `chat.inject` added, anchored
202
+ * after the transcript message they followed.
203
+ */
204
+ export type TranscriptRuntimeState = {
205
+ v: 1;
206
+ compaction?: {
207
+ modelMessages: ModelMessage[];
208
+ throughId: string;
209
+ };
210
+ injections?: ModelLaneInjection[];
211
+ /** `chat.inject` messages queued but not yet drained into a turn when the save happened. */
212
+ queued?: ModelMessage[];
213
+ };
214
+ /**
215
+ * The slice of a transcript worth storing, which is the last `keep` messages
216
+ * once a conversation has compacted, and all of it before that.
217
+ *
218
+ * Expressed relative to the compaction watermark rather than as a plain tail,
219
+ * because everything after the watermark is live context that the next boot
220
+ * converts and must never be dropped. The runtime stamps the watermark at the
221
+ * newest message on each compacted save, so in practice the two coincide and
222
+ * this keeps the last `keep`; the watermark-relative form is what keeps it
223
+ * correct if a watermark ever lands earlier in the transcript.
224
+ *
225
+ * Without a watermark nothing is dropped: every entry is still context.
226
+ *
227
+ * This is what stops the object rewritten each turn from growing with the
228
+ * conversation. An app that needs the whole history keeps its own transcript
229
+ * storage.
230
+ */
231
+ export declare function trimTranscriptForSnapshot<TEntry extends {
232
+ id: string;
233
+ }>(entries: TEntry[], state: unknown, opts: {
234
+ keep: number;
235
+ }): TEntry[];
236
+ /**
237
+ * Rewrite runtime state so it still describes the transcript window being
238
+ * persisted.
239
+ *
240
+ * A compaction watermark that has moved out of the window becomes `""`, which
241
+ * is how a restored lane says "the compacted messages cover everything before
242
+ * this window". Left as-is, the watermark would name an entry the window does
243
+ * not contain, and restoring the lane would discard the compacted messages and
244
+ * re-convert the window from scratch — an agent that has silently forgotten the
245
+ * conversation. Injections anchored outside the window go too: the span they
246
+ * belonged to is already inside the compacted lane.
247
+ */
248
+ export declare function normalizeRuntimeStateForWindow(state: unknown, windowIds: Iterable<string>): unknown;
249
+ export declare function parseTranscriptRuntimeState(value: unknown): TranscriptRuntimeState | undefined;
250
+ /**
251
+ * Rebuild the model lane for a transcript at boot. Uses the persisted
252
+ * compacted lane while the transcript still contains its `throughId`
253
+ * boundary, then converts the rest of the transcript, re-inserting persisted
254
+ * injections after the messages they followed.
255
+ */
256
+ export declare function restoreModelLane<TUIMessage extends UIMessage>(messages: TUIMessage[], state: TranscriptRuntimeState | undefined, convert: (messages: TUIMessage[]) => Promise<ModelMessage[]>): Promise<{
257
+ messages: ModelMessage[];
258
+ compacted: boolean;
259
+ injections: ModelLaneInjection[];
260
+ }>;
261
+ export {};
@@ -0,0 +1,374 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defaultStorage = void 0;
4
+ exports.emptyTranscriptState = emptyTranscriptState;
5
+ exports.reduceTranscriptChanges = reduceTranscriptChanges;
6
+ exports.fingerprintMessage = fingerprintMessage;
7
+ exports.createTranscriptShadow = createTranscriptShadow;
8
+ exports.diffTranscript = diffTranscript;
9
+ exports.snapshotTranscriptStorage = snapshotTranscriptStorage;
10
+ exports.memoryTranscriptStorage = memoryTranscriptStorage;
11
+ exports.trimTranscriptForSnapshot = trimTranscriptForSnapshot;
12
+ exports.normalizeRuntimeStateForWindow = normalizeRuntimeStateForWindow;
13
+ exports.parseTranscriptRuntimeState = parseTranscriptRuntimeState;
14
+ exports.restoreModelLane = restoreModelLane;
15
+ const v3_1 = require("@trigger.dev/core/v3");
16
+ const chatSnapshotIo_js_1 = require("./chatSnapshotIo.js");
17
+ function emptyTranscriptState() {
18
+ return { entries: [], state: null };
19
+ }
20
+ /**
21
+ * Apply changes to a transcript, in order. Pure: returns a new state and
22
+ * never mutates the input. Replaying the same changes converges, which is
23
+ * what lets a storage retry a failed write without checking what landed.
24
+ */
25
+ function reduceTranscriptChanges(prev, changes) {
26
+ let entries = prev.entries.slice();
27
+ let state = prev.state;
28
+ for (const change of changes) {
29
+ switch (change.op) {
30
+ case "put": {
31
+ const message = change.message;
32
+ const entry = { id: message.id, final: change.final ?? true, message };
33
+ const idx = entries.findIndex((e) => e.id === message.id);
34
+ if (idx === -1)
35
+ entries.push(entry);
36
+ else
37
+ entries[idx] = entry;
38
+ break;
39
+ }
40
+ case "remove": {
41
+ entries = entries.filter((e) => e.id !== change.id);
42
+ break;
43
+ }
44
+ case "truncateAfter": {
45
+ const idx = entries.findIndex((e) => e.id === change.afterId);
46
+ if (idx !== -1)
47
+ entries = entries.slice(0, idx + 1);
48
+ break;
49
+ }
50
+ case "state": {
51
+ state = change.value ?? null;
52
+ break;
53
+ }
54
+ }
55
+ }
56
+ return { entries, state };
57
+ }
58
+ /**
59
+ * The content identity the transcript shadow compares messages by. @internal
60
+ */
61
+ function fingerprintMessage(message) {
62
+ return JSON.stringify(message);
63
+ }
64
+ /**
65
+ * Build the shadow for `messages`. An id is non-final when this save says so
66
+ * (`nonFinalIds`) or when it was non-final before and its content has not
67
+ * changed: a partial answer stays partial until the message itself changes.
68
+ */
69
+ function createTranscriptShadow(messages, nonFinalIds, previous) {
70
+ const ids = [];
71
+ const fingerprints = new Map();
72
+ const nonFinal = new Set();
73
+ for (const message of messages) {
74
+ const fingerprint = fingerprintMessage(message);
75
+ ids.push(message.id);
76
+ fingerprints.set(message.id, fingerprint);
77
+ if (nonFinalIds?.has(message.id) ||
78
+ (previous?.nonFinal.has(message.id) && previous.fingerprints.get(message.id) === fingerprint)) {
79
+ nonFinal.add(message.id);
80
+ }
81
+ }
82
+ return { ids, fingerprints, nonFinal };
83
+ }
84
+ /**
85
+ * Derive the changes that take `shadow` to `next`.
86
+ *
87
+ * The common prefix (by id) is compared message by message and a changed
88
+ * message becomes an in-place `put`. Past the prefix, everything the shadow
89
+ * still had is dropped with one `truncateAfter` on the last common id (or
90
+ * one `remove` per message when there is no common prefix) and everything
91
+ * `next` has is appended with `put`, in order. Applying the result with
92
+ * {@link reduceTranscriptChanges} reproduces `next` exactly, including
93
+ * order, for any two lists.
94
+ */
95
+ function diffTranscript(shadow, next, options = {}) {
96
+ const nextShadow = createTranscriptShadow(next, options.nonFinalIds, shadow);
97
+ const changes = [];
98
+ const put = (message) => {
99
+ const final = nextShadow.nonFinal.has(message.id) ? false : undefined;
100
+ changes.push(final === undefined ? { op: "put", message } : { op: "put", message, final });
101
+ };
102
+ let lcp = 0;
103
+ while (lcp < shadow.ids.length && lcp < next.length && shadow.ids[lcp] === next[lcp].id) {
104
+ lcp++;
105
+ }
106
+ for (let i = 0; i < lcp; i++) {
107
+ const message = next[i];
108
+ if (shadow.fingerprints.get(message.id) !== nextShadow.fingerprints.get(message.id) ||
109
+ shadow.nonFinal.has(message.id) !== nextShadow.nonFinal.has(message.id)) {
110
+ put(message);
111
+ }
112
+ }
113
+ if (shadow.ids.length > lcp) {
114
+ if (lcp > 0) {
115
+ changes.push({ op: "truncateAfter", afterId: shadow.ids[lcp - 1] });
116
+ }
117
+ else {
118
+ for (const id of shadow.ids)
119
+ changes.push({ op: "remove", id });
120
+ }
121
+ }
122
+ for (let i = lcp; i < next.length; i++) {
123
+ put(next[i]);
124
+ }
125
+ return { changes, shadow: nextShadow };
126
+ }
127
+ /**
128
+ * Roughly how many messages the snapshot keeps once a conversation has
129
+ * compacted. Raising it costs bytes on every save; lowering it shortens how far
130
+ * back a conversation can be rendered from the platform's own store.
131
+ */
132
+ const SNAPSHOT_KEEP_MESSAGES = 100;
133
+ /**
134
+ * The built-in storage: the transcript in the platform's object store, read by
135
+ * the Sessions dashboard and the transcript API.
136
+ *
137
+ * One object per conversation, rewritten each turn, holding the transcript plus
138
+ * the runtime state. Once a conversation has been compacted, it keeps roughly
139
+ * the last hundred messages rather than all of them, so the object stops
140
+ * growing with the conversation. An app that needs the full history keeps its
141
+ * own transcript storage.
142
+ */
143
+ function snapshotTranscriptStorage() {
144
+ return {
145
+ async load(scope, opts) {
146
+ if (opts?.limit !== undefined || opts?.before !== undefined) {
147
+ const page = await readTranscriptPage(scope.chatId, opts);
148
+ if (page)
149
+ return page;
150
+ }
151
+ const snapshot = await (0, chatSnapshotIo_js_1.readChatSnapshot)(scope.chatId);
152
+ const full = snapshot
153
+ ? { entries: snapshot.messages, state: snapshot.state }
154
+ : emptyTranscriptState();
155
+ return {
156
+ ...pageEntries(full.entries, opts),
157
+ state: full.state,
158
+ cursors: snapshot
159
+ ? { lastOutEventId: snapshot.lastOutEventId, lastInEventId: snapshot.lastInEventId }
160
+ : undefined,
161
+ };
162
+ },
163
+ async save(ctx, changeset) {
164
+ const entries = trimTranscriptForSnapshot(changeset.transcript.entries, changeset.transcript.state, { keep: SNAPSHOT_KEEP_MESSAGES });
165
+ await (0, chatSnapshotIo_js_1.writeChatSnapshot)(ctx.chatId, {
166
+ version: 2,
167
+ savedAt: Date.now(),
168
+ messages: entries,
169
+ state: normalizeRuntimeStateForWindow(changeset.transcript.state, entries.map((entry) => entry.id)),
170
+ lastOutEventId: changeset.cursors?.lastOutEventId,
171
+ lastInEventId: changeset.cursors?.lastInEventId,
172
+ });
173
+ },
174
+ };
175
+ }
176
+ /**
177
+ * A page of the platform transcript read server-side, for a render read with
178
+ * `limit`/`before` from an app server holding a secret key. `undefined` when
179
+ * the call is not possible from here (a run's public token cannot use the
180
+ * endpoint), so the caller falls back to reading the whole blob.
181
+ *
182
+ * Carries no runtime `state`: the endpoint serves the transcript only, so a
183
+ * paged result always reports `state: null`. The model lane is restored from
184
+ * the whole-blob read instead, which is reachable only with private auth.
185
+ */
186
+ async function readTranscriptPage(chatId, opts) {
187
+ try {
188
+ const page = await v3_1.apiClientManager.clientOrThrow().getSessionTranscript(chatId, opts);
189
+ return {
190
+ messages: page.messages,
191
+ state: null,
192
+ cursors: page.cursors,
193
+ nextCursor: page.nextCursor,
194
+ };
195
+ }
196
+ catch {
197
+ return undefined;
198
+ }
199
+ }
200
+ /** The storage `chat.agent` uses when none is configured: {@link snapshotTranscriptStorage}. */
201
+ exports.defaultStorage = snapshotTranscriptStorage();
202
+ function pageEntries(all, opts) {
203
+ const page = (0, v3_1.pageTranscriptEntries)(all, opts);
204
+ return {
205
+ messages: page.entries.map((e) => e.message),
206
+ nextCursor: page.nextCursor,
207
+ nonFinalIds: page.entries.filter((e) => !e.final).map((e) => e.id),
208
+ };
209
+ }
210
+ /**
211
+ * A storage that keeps every transcript in process memory. The reference
212
+ * implementation for the conformance tests, and a way to inspect exactly
213
+ * what the runtime hands a storage.
214
+ */
215
+ function memoryTranscriptStorage() {
216
+ const transcripts = new Map();
217
+ const changesets = [];
218
+ return {
219
+ changesets,
220
+ transcript(chatId) {
221
+ return transcripts.get(chatId);
222
+ },
223
+ async load(scope, opts) {
224
+ const stored = transcripts.get(scope.chatId);
225
+ if (!stored)
226
+ return { messages: [], state: null, cursors: undefined, nextCursor: undefined };
227
+ return {
228
+ ...pageEntries(stored.entries, opts),
229
+ state: stored.state,
230
+ cursors: stored.cursors,
231
+ };
232
+ },
233
+ async save(ctx, changeset) {
234
+ changesets.push({ ctx, changeset });
235
+ const prev = transcripts.get(ctx.chatId);
236
+ const next = reduceTranscriptChanges(prev ?? emptyTranscriptState(), changeset.changes);
237
+ transcripts.set(ctx.chatId, { ...next, cursors: changeset.cursors ?? prev?.cursors });
238
+ },
239
+ };
240
+ }
241
+ /**
242
+ * The slice of a transcript worth storing, which is the last `keep` messages
243
+ * once a conversation has compacted, and all of it before that.
244
+ *
245
+ * Expressed relative to the compaction watermark rather than as a plain tail,
246
+ * because everything after the watermark is live context that the next boot
247
+ * converts and must never be dropped. The runtime stamps the watermark at the
248
+ * newest message on each compacted save, so in practice the two coincide and
249
+ * this keeps the last `keep`; the watermark-relative form is what keeps it
250
+ * correct if a watermark ever lands earlier in the transcript.
251
+ *
252
+ * Without a watermark nothing is dropped: every entry is still context.
253
+ *
254
+ * This is what stops the object rewritten each turn from growing with the
255
+ * conversation. An app that needs the whole history keeps its own transcript
256
+ * storage.
257
+ */
258
+ function trimTranscriptForSnapshot(entries, state, opts) {
259
+ const throughId = parseTranscriptRuntimeState(state)?.compaction?.throughId;
260
+ if (throughId === undefined || throughId === "")
261
+ return entries;
262
+ const idx = entries.findIndex((entry) => entry.id === throughId);
263
+ if (idx === -1)
264
+ return entries;
265
+ // Keep the watermark entry itself, so a restored lane can still find it.
266
+ const start = Math.max(0, idx + 1 - Math.max(1, opts.keep));
267
+ return start === 0 ? entries : entries.slice(start);
268
+ }
269
+ /**
270
+ * Rewrite runtime state so it still describes the transcript window being
271
+ * persisted.
272
+ *
273
+ * A compaction watermark that has moved out of the window becomes `""`, which
274
+ * is how a restored lane says "the compacted messages cover everything before
275
+ * this window". Left as-is, the watermark would name an entry the window does
276
+ * not contain, and restoring the lane would discard the compacted messages and
277
+ * re-convert the window from scratch — an agent that has silently forgotten the
278
+ * conversation. Injections anchored outside the window go too: the span they
279
+ * belonged to is already inside the compacted lane.
280
+ */
281
+ function normalizeRuntimeStateForWindow(state, windowIds) {
282
+ const runtimeState = parseTranscriptRuntimeState(state);
283
+ if (!runtimeState)
284
+ return state;
285
+ const ids = new Set(windowIds);
286
+ const compaction = runtimeState.compaction;
287
+ const watermarkOutside = compaction !== undefined && compaction.throughId !== "" && !ids.has(compaction.throughId);
288
+ const injections = runtimeState.injections?.filter((injection) => injection.afterId === "" || ids.has(injection.afterId));
289
+ if (!watermarkOutside && injections?.length === runtimeState.injections?.length) {
290
+ return state;
291
+ }
292
+ return {
293
+ ...runtimeState,
294
+ ...(compaction
295
+ ? {
296
+ compaction: {
297
+ modelMessages: compaction.modelMessages,
298
+ throughId: watermarkOutside ? "" : compaction.throughId,
299
+ },
300
+ }
301
+ : {}),
302
+ ...(injections ? { injections } : {}),
303
+ };
304
+ }
305
+ function parseTranscriptRuntimeState(value) {
306
+ if (!value || typeof value !== "object")
307
+ return undefined;
308
+ const record = value;
309
+ if (record.v !== 1)
310
+ return undefined;
311
+ const out = { v: 1 };
312
+ const compaction = record.compaction;
313
+ if (compaction &&
314
+ typeof compaction === "object" &&
315
+ Array.isArray(compaction.modelMessages) &&
316
+ typeof compaction.throughId === "string") {
317
+ out.compaction = {
318
+ modelMessages: compaction.modelMessages,
319
+ throughId: compaction.throughId,
320
+ };
321
+ }
322
+ if (Array.isArray(record.injections)) {
323
+ out.injections = record.injections.flatMap((entry) => {
324
+ const inj = entry;
325
+ return inj && typeof inj.afterId === "string" && Array.isArray(inj.messages)
326
+ ? [{ afterId: inj.afterId, messages: inj.messages }]
327
+ : [];
328
+ });
329
+ }
330
+ if (Array.isArray(record.queued) && record.queued.length > 0) {
331
+ out.queued = record.queued;
332
+ }
333
+ return out;
334
+ }
335
+ /**
336
+ * Rebuild the model lane for a transcript at boot. Uses the persisted
337
+ * compacted lane while the transcript still contains its `throughId`
338
+ * boundary, then converts the rest of the transcript, re-inserting persisted
339
+ * injections after the messages they followed.
340
+ */
341
+ async function restoreModelLane(messages, state, convert) {
342
+ const lane = [];
343
+ let start = 0;
344
+ let compacted = false;
345
+ if (state?.compaction) {
346
+ const throughId = state.compaction.throughId;
347
+ const idx = throughId === "" ? -1 : messages.findIndex((m) => m.id === throughId);
348
+ if (idx !== -1 || throughId === "") {
349
+ lane.push(...state.compaction.modelMessages);
350
+ start = idx + 1;
351
+ compacted = true;
352
+ }
353
+ }
354
+ const anchored = (state?.injections ?? [])
355
+ .map((inj) => ({
356
+ inj,
357
+ idx: inj.afterId === "" ? -1 : messages.findIndex((m) => m.id === inj.afterId),
358
+ }))
359
+ .filter(({ inj, idx }) => (inj.afterId === "" ? start === 0 : idx >= start))
360
+ .sort((a, b) => a.idx - b.idx);
361
+ let cursor = start;
362
+ for (const { inj, idx } of anchored) {
363
+ if (idx + 1 > cursor) {
364
+ lane.push(...(await convert(messages.slice(cursor, idx + 1))));
365
+ cursor = idx + 1;
366
+ }
367
+ lane.push(...inj.messages);
368
+ }
369
+ if (cursor < messages.length) {
370
+ lane.push(...(await convert(messages.slice(cursor))));
371
+ }
372
+ return { messages: lane, compacted, injections: anchored.map(({ inj }) => inj) };
373
+ }
374
+ //# sourceMappingURL=transcriptStorage.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transcriptStorage.js","sourceRoot":"","sources":["../../../src/v3/transcriptStorage.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,6CAK8B;AAE9B,2DAA0E;AAiI1E;IAGE,OAAO,EAAE,OAAO,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC;AACtC,CAAC;AAED;;;;GAIG;AACH,iCACE,IAAiC,EACjC,OAAoC;IAEpC,IAAI,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;IACnC,IAAI,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;IACvB,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;QAC7B,QAAQ,MAAM,CAAC,EAAE,EAAE,C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G,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;IAEjC,IAAI,MAAM,GAAG,KAAK,CAAC;IACnB,KAAK,MAAM,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,QAAQ,EAAE,CAAC;QACpC,IAAI,GAAG,GAAG,CAAC,GAAG,MAAM,EAAE,CAAC;YACrB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC/D,MAAM,GAAG,GAAG,GAAG,CAAC,CAAC;QACnB,CAAC;QACD,IAAI,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC7B,CAAC;IACD,IAAI,MAAM,GAAG,QAAQ,CAAC,MAAM,EAAE,CAAC;QAC7B,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IACxD,CAAC;IAED,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,CAAC,EAAE,CAAC;AACnF,CAAC"}
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = "4.5.16";
4
+ exports.VERSION = "4.6.0";
5
5
  //# sourceMappingURL=version.js.map
@@ -1,2 +1,2 @@
1
- import { convertToModelMessages, dynamicTool, generateId, getToolName, isToolUIPart, jsonSchema, readUIMessageStream, stepCountIs, tool, zodSchema } from "ai";
2
- export { convertToModelMessages, dynamicTool, generateId, getToolName, isToolUIPart, jsonSchema, readUIMessageStream, stepCountIs, tool, zodSchema, };
1
+ import { convertToModelMessages, dynamicTool, generateId, getToolName, isToolUIPart, jsonSchema, readUIMessageStream, stepCountIs, streamText, tool, zodSchema } from "ai";
2
+ export { convertToModelMessages, dynamicTool, generateId, getToolName, isToolUIPart, jsonSchema, readUIMessageStream, stepCountIs, streamText, tool, zodSchema, };