@trigger.dev/sdk 4.5.15 → 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 (159) 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/custom.mdx +14 -1
  140. package/docs/config/extensions/syncEnvVars.mdx +6 -0
  141. package/docs/deploy-environment-variables.mdx +23 -2
  142. package/docs/deployment/overview.mdx +4 -8
  143. package/docs/deployment/preview-branches.mdx +4 -4
  144. package/docs/deployment/version-skew-protection.mdx +62 -0
  145. package/docs/github-integration.mdx +1 -1
  146. package/docs/introduction.mdx +58 -152
  147. package/docs/manual-setup.mdx +7 -7
  148. package/docs/mcp-tools.mdx +9 -0
  149. package/docs/quick-start.mdx +3 -3
  150. package/docs/realtime/auth.mdx +1 -1
  151. package/docs/reports.mdx +157 -0
  152. package/docs/self-hosting/security.mdx +17 -0
  153. package/docs/tasks/scheduled.mdx +24 -0
  154. package/docs/triggering.mdx +1 -1
  155. package/docs/troubleshooting-zod.mdx +158 -0
  156. package/docs/troubleshooting.mdx +1 -1
  157. package/package.json +4 -4
  158. package/skills/trigger-authoring-chat-agent/SKILL.md +41 -29
  159. package/skills/trigger-chat-agent-advanced/SKILL.md +54 -19
@@ -177,6 +177,20 @@ export type ChatTransportSendSource = "submit-message" | "regenerate-message" |
177
177
  * stream fails unrecoverably.
178
178
  */
179
179
  export type ChatTransportEvent = {
180
+ /**
181
+ * The chat's run is parked waiting for its deployment (version skew protection). Messages
182
+ * sent meanwhile are durable and drain when it lands, but nothing answers until then.
183
+ * Re-emitted on every send while parked; clear the notice on `first-chunk`.
184
+ */
185
+ type: "run-pending-version";
186
+ chatId: string;
187
+ timestamp: number;
188
+ /**
189
+ * Where we learned it: creating the session, a send, the `headStart` POST, or an
190
+ * upgrade handing over to a deployment that has not landed yet.
191
+ */
192
+ source: "start" | "send" | "head-start" | "upgrade";
193
+ } | {
180
194
  type: "message-sent";
181
195
  chatId: string;
182
196
  timestamp: number;
@@ -213,6 +227,14 @@ export type ChatTransportEvent = {
213
227
  timestamp: number;
214
228
  error: Error;
215
229
  status?: number;
230
+ } | {
231
+ type: "session-closed";
232
+ chatId: string;
233
+ timestamp: number;
234
+ /** The reason supplied to `chat.close()` / `sessions.close()`, if any. */
235
+ reason?: string;
236
+ /** How the transport learned: the terminal record, or a refused send. */
237
+ source: "stream" | "append";
216
238
  } | {
217
239
  type: "first-chunk";
218
240
  chatId: string;
@@ -288,6 +310,11 @@ export type StartSessionParams<TClientData = unknown> = {
288
310
  export type StartSessionResult = {
289
311
  /** Session-scoped PAT — `read:sessions:{chatId} + write:sessions:{chatId}`. */
290
312
  publicAccessToken: string;
313
+ /**
314
+ * Pass through `pendingVersion` from `chat.createStartSessionAction` (or `POST
315
+ * /api/v1/sessions`) and the transport emits `run-pending-version`.
316
+ */
317
+ pendingVersion?: boolean;
291
318
  };
292
319
  /**
293
320
  * Public surface of {@link TriggerChatTransport}'s session state. Everything
@@ -301,6 +328,10 @@ export type ChatSessionPersistedState = {
301
328
  /** The `.in` append sequence of the last send this client owned; reused as `sinceInSeq` on reconnect. */
302
329
  activeInputSeq?: number;
303
330
  isStreaming?: boolean;
331
+ /** Set once the session is closed. Persisted so a reload doesn't retry a dead session. */
332
+ closed?: boolean;
333
+ /** The reason the session was closed, when one was given. */
334
+ closedReason?: string;
304
335
  };
305
336
  /**
306
337
  * Common options for the {@link TriggerChatTransport}.
@@ -493,10 +524,10 @@ export type TriggerChatTransportOptions<TClientData = unknown> = {
493
524
  */
494
525
  export declare class TriggerChatTransport implements ChatTransport<UIMessage> {
495
526
  private readonly taskId;
496
- private readonly resolveAccessToken;
497
- private readonly resolveStartSession;
527
+ private resolveAccessToken;
528
+ private resolveStartSession;
498
529
  private readonly resolveBaseURLFn;
499
- private readonly fetchOverride;
530
+ private fetchOverride;
500
531
  private readonly extraHeaders;
501
532
  private readonly streamTimeoutSeconds;
502
533
  private defaultMetadata;
@@ -506,6 +537,7 @@ export declare class TriggerChatTransport implements ChatTransport<UIMessage> {
506
537
  private _onSessionChange;
507
538
  private _onEvent;
508
539
  private sessions;
540
+ private pendingResumeCursors;
509
541
  private activeStreams;
510
542
  private pendingStarts;
511
543
  private lastTurnSends;
@@ -579,16 +611,35 @@ export declare class TriggerChatTransport implements ChatTransport<UIMessage> {
579
611
  */
580
612
  stopGeneration: (chatId: string) => Promise<boolean>;
581
613
  /**
582
- * Send a custom action chunk (for `chat.agent`'s `actionSchema` /
583
- * `onAction` hook). Actions are not turns — only `hydrateMessages`
584
- * and `onAction` fire on the agent side. The returned stream
585
- * carries any model response `onAction` produced (when it returns a
586
- * `StreamTextResult`); for `void`-returning side-effect-only actions
587
- * the stream completes immediately with `trigger:turn-complete`.
614
+ * Clear the supersede gate armed by a stop. Call this when the stopped
615
+ * turn died without ever writing its `trigger:turn-complete` boundary,
616
+ * otherwise the next turn stays gated forever.
588
617
  */
589
- sendAction: (chatId: string, action: unknown) => Promise<ReadableStream<UIMessageChunk>>;
618
+ clearSupersedeGate: (chatId: string) => void;
619
+ /**
620
+ * Send a custom action chunk (for `chat.agent`'s `actionSchema` /
621
+ * `onAction` hook). An action is an edit: only `hydrateMessages` and
622
+ * `onAction` fire on the agent side, and the returned stream completes
623
+ * with `trigger:turn-complete` once the edit is persisted. When `onAction`
624
+ * returns `chat.turn()` the turn's response follows on the same stream.
625
+ * Per-action `metadata` is merged over the transport's `clientData`.
626
+ */
627
+ sendAction: (chatId: string, action: unknown, options?: {
628
+ abortSignal?: AbortSignal;
629
+ metadata?: Record<string, unknown>;
630
+ }) => Promise<ReadableStream<UIMessageChunk>>;
590
631
  getSession: (chatId: string) => ChatSessionPersistedState | undefined;
591
632
  setSession(chatId: string, session: ChatSessionPersistedState): void;
633
+ /**
634
+ * Seed the `.out` resume cursor from a loaded transcript. Applied to the
635
+ * session now if it exists, otherwise held until the session is created so
636
+ * the first live subscription opens past the persisted history instead of
637
+ * replaying it. Never moves an existing cursor backward: the transcript load
638
+ * is async, so a live `.out` record can already have advanced the session
639
+ * past the snapshot, and overwriting it would replay those records.
640
+ */
641
+ seedResumeCursor: (chatId: string, lastEventId: string) => void;
642
+ private applyPendingResumeCursor;
592
643
  setOnSessionChange(callback: ((chatId: string, session: ChatSessionPersistedState | null) => void) | undefined): void;
593
644
  /** Update the `onEvent` callback without recreating the transport. */
594
645
  setOnEvent(callback: ((event: ChatTransportEvent) => void) | undefined): void;
@@ -606,6 +657,16 @@ export declare class TriggerChatTransport implements ChatTransport<UIMessage> {
606
657
  * transport see the latest value the next time they fire.
607
658
  */
608
659
  setClientData(clientData: Record<string, unknown> | undefined): void;
660
+ /**
661
+ * Update the request-time callbacks. Same reason as `setClientData`:
662
+ * a host that rebuilds these per render (a dashboard navigating between
663
+ * projects) would otherwise keep hitting the endpoint captured at
664
+ * construction. Every read goes through the live field, so the next
665
+ * request uses the latest callback.
666
+ */
667
+ setAccessToken(accessToken: (params: AccessTokenParams) => string | Promise<string>): void;
668
+ setStartSession(startSession: ((params: StartSessionParams<Record<string, unknown>>) => Promise<StartSessionResult>) | undefined): void;
669
+ setFetch(fetchOverride: ChatFetchOverride | undefined): void;
609
670
  isReadOnly(chatId: string): boolean;
610
671
  hasClaim(chatId: string): boolean;
611
672
  addReadOnlyListener(fn: (chatId: string, isReadOnly: boolean) => void): void;
@@ -616,6 +677,20 @@ export declare class TriggerChatTransport implements ChatTransport<UIMessage> {
616
677
  dispose(): void;
617
678
  private serializeInputChunk;
618
679
  private toPersisted;
680
+ /**
681
+ * Flip a session to closed and tell listeners once. Terminal: sends and
682
+ * reconnects stop from here on, and there is no reopening.
683
+ */
684
+ private markSessionClosed;
685
+ /**
686
+ * Whether the conversation has been closed — by the agent via
687
+ * `chat.close()`, or from outside via `sessions.close()`. Closed is
688
+ * one-way: the transport refuses further sends and reconnects, and the
689
+ * transcript stays readable.
690
+ */
691
+ sessionStatus: (chatId: string) => "open" | "closed";
692
+ /** The reason the session was closed, when one was given. */
693
+ sessionClosedReason: (chatId: string) => string | undefined;
619
694
  private notifySessionChange;
620
695
  /**
621
696
  * Resolves the session state for a chatId, starting the session if
@@ -631,6 +706,13 @@ export declare class TriggerChatTransport implements ChatTransport<UIMessage> {
631
706
  * via `accessToken` and retry once. Surfaces non-auth errors as-is.
632
707
  */
633
708
  private resolveBaseURL;
709
+ /**
710
+ * `fetchClient` for an `out` subscription. Reads `this.fetchOverride` on
711
+ * every call, not once per subscription: a watch-mode subscription
712
+ * reconnects for the lifetime of the page, and `setFetch` may have swapped
713
+ * the override in between.
714
+ */
715
+ private sseFetchClient;
634
716
  private doFetch;
635
717
  private appendInputChunk;
636
718
  private callWithAuthRetry;