@trigger.dev/sdk 0.0.0-prerelease-20260911094758 → 0.0.0-prerelease-windows-bundle-fix-20260928100448

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 (133) hide show
  1. package/dist/commonjs/v3/ai.d.ts +73 -12
  2. package/dist/commonjs/v3/ai.js +542 -289
  3. package/dist/commonjs/v3/ai.js.map +1 -1
  4. package/dist/commonjs/v3/auth.d.ts +10 -4
  5. package/dist/commonjs/v3/auth.js +8 -2
  6. package/dist/commonjs/v3/auth.js.map +1 -1
  7. package/dist/commonjs/v3/chat-client.js +7 -0
  8. package/dist/commonjs/v3/chat-client.js.map +1 -1
  9. package/dist/commonjs/v3/chat-server.d.ts +1 -0
  10. package/dist/commonjs/v3/chat-server.js +8 -0
  11. package/dist/commonjs/v3/chat-server.js.map +1 -1
  12. package/dist/commonjs/v3/chat.js +13 -9
  13. package/dist/commonjs/v3/chat.js.map +1 -1
  14. package/dist/commonjs/v3/compactionResponse.d.ts +9 -0
  15. package/dist/commonjs/v3/compactionResponse.js +37 -0
  16. package/dist/commonjs/v3/compactionResponse.js.map +1 -0
  17. package/dist/commonjs/v3/concurrency-shared.d.ts +13 -0
  18. package/dist/commonjs/v3/concurrency-shared.js +35 -0
  19. package/dist/commonjs/v3/concurrency-shared.js.map +1 -0
  20. package/dist/commonjs/v3/concurrencyLimits.d.ts +73 -0
  21. package/dist/commonjs/v3/concurrencyLimits.js +166 -0
  22. package/dist/commonjs/v3/concurrencyLimits.js.map +1 -0
  23. package/dist/commonjs/v3/index.d.ts +2 -1
  24. package/dist/commonjs/v3/index.js +3 -1
  25. package/dist/commonjs/v3/index.js.map +1 -1
  26. package/dist/commonjs/v3/managedChatResponse.d.ts +44 -0
  27. package/dist/commonjs/v3/managedChatResponse.js +233 -0
  28. package/dist/commonjs/v3/managedChatResponse.js.map +1 -0
  29. package/dist/commonjs/v3/queues.d.ts +31 -0
  30. package/dist/commonjs/v3/queues.js +31 -0
  31. package/dist/commonjs/v3/queues.js.map +1 -1
  32. package/dist/commonjs/v3/runs.d.ts +5 -0
  33. package/dist/commonjs/v3/sessionTracing.d.ts +7 -0
  34. package/dist/commonjs/v3/sessionTracing.js +44 -0
  35. package/dist/commonjs/v3/sessionTracing.js.map +1 -0
  36. package/dist/commonjs/v3/sessions.js +31 -34
  37. package/dist/commonjs/v3/sessions.js.map +1 -1
  38. package/dist/commonjs/v3/shared.d.ts +18 -1
  39. package/dist/commonjs/v3/shared.js +145 -52
  40. package/dist/commonjs/v3/shared.js.map +1 -1
  41. package/dist/commonjs/v3/steeringContext.d.ts +41 -0
  42. package/dist/commonjs/v3/steeringContext.js +118 -0
  43. package/dist/commonjs/v3/steeringContext.js.map +1 -0
  44. package/dist/commonjs/v3/test/transcript-storage-tests.js.map +1 -1
  45. package/dist/commonjs/v3/transcriptStorage.d.ts +5 -2
  46. package/dist/commonjs/v3/transcriptStorage.js +55 -4
  47. package/dist/commonjs/v3/transcriptStorage.js.map +1 -1
  48. package/dist/commonjs/version.js +1 -1
  49. package/dist/esm/v3/ai.d.ts +73 -12
  50. package/dist/esm/v3/ai.js +543 -290
  51. package/dist/esm/v3/ai.js.map +1 -1
  52. package/dist/esm/v3/auth.d.ts +10 -4
  53. package/dist/esm/v3/auth.js +8 -2
  54. package/dist/esm/v3/auth.js.map +1 -1
  55. package/dist/esm/v3/chat-client.js +7 -0
  56. package/dist/esm/v3/chat-client.js.map +1 -1
  57. package/dist/esm/v3/chat-server.d.ts +1 -0
  58. package/dist/esm/v3/chat-server.js +8 -0
  59. package/dist/esm/v3/chat-server.js.map +1 -1
  60. package/dist/esm/v3/chat.js +13 -9
  61. package/dist/esm/v3/chat.js.map +1 -1
  62. package/dist/esm/v3/compactionResponse.d.ts +9 -0
  63. package/dist/esm/v3/compactionResponse.js +34 -0
  64. package/dist/esm/v3/compactionResponse.js.map +1 -0
  65. package/dist/esm/v3/concurrency-shared.d.ts +13 -0
  66. package/dist/esm/v3/concurrency-shared.js +31 -0
  67. package/dist/esm/v3/concurrency-shared.js.map +1 -0
  68. package/dist/esm/v3/concurrencyLimits.d.ts +73 -0
  69. package/dist/esm/v3/concurrencyLimits.js +158 -0
  70. package/dist/esm/v3/concurrencyLimits.js.map +1 -0
  71. package/dist/esm/v3/index.d.ts +2 -1
  72. package/dist/esm/v3/index.js +2 -1
  73. package/dist/esm/v3/index.js.map +1 -1
  74. package/dist/esm/v3/managedChatResponse.d.ts +44 -0
  75. package/dist/esm/v3/managedChatResponse.js +228 -0
  76. package/dist/esm/v3/managedChatResponse.js.map +1 -0
  77. package/dist/esm/v3/queues.d.ts +31 -0
  78. package/dist/esm/v3/queues.js +31 -0
  79. package/dist/esm/v3/queues.js.map +1 -1
  80. package/dist/esm/v3/runs.d.ts +5 -0
  81. package/dist/esm/v3/sessionTracing.d.ts +7 -0
  82. package/dist/esm/v3/sessionTracing.js +40 -0
  83. package/dist/esm/v3/sessionTracing.js.map +1 -0
  84. package/dist/esm/v3/sessions.js +31 -34
  85. package/dist/esm/v3/sessions.js.map +1 -1
  86. package/dist/esm/v3/shared.d.ts +18 -1
  87. package/dist/esm/v3/shared.js +145 -53
  88. package/dist/esm/v3/shared.js.map +1 -1
  89. package/dist/esm/v3/steeringContext.d.ts +41 -0
  90. package/dist/esm/v3/steeringContext.js +113 -0
  91. package/dist/esm/v3/steeringContext.js.map +1 -0
  92. package/dist/esm/v3/test/transcript-storage-tests.js.map +1 -1
  93. package/dist/esm/v3/transcriptStorage.d.ts +5 -2
  94. package/dist/esm/v3/transcriptStorage.js +55 -5
  95. package/dist/esm/v3/transcriptStorage.js.map +1 -1
  96. package/dist/esm/version.js +1 -1
  97. package/docs/ai-chat/anatomy.mdx +44 -24
  98. package/docs/ai-chat/background-injection.mdx +54 -1
  99. package/docs/ai-chat/client-protocol.mdx +2 -0
  100. package/docs/ai-chat/error-handling.mdx +44 -76
  101. package/docs/ai-chat/frontend.mdx +27 -21
  102. package/docs/ai-chat/lifecycle-hooks.mdx +4 -2
  103. package/docs/ai-chat/migrating-from-hydrate-messages.mdx +299 -0
  104. package/docs/ai-chat/patterns/branching-conversations.mdx +95 -230
  105. package/docs/ai-chat/patterns/database-persistence.mdx +18 -7
  106. package/docs/ai-chat/patterns/human-in-the-loop.mdx +166 -164
  107. package/docs/ai-chat/patterns/tool-result-auditing.mdx +28 -27
  108. package/docs/ai-chat/pending-messages.mdx +19 -5
  109. package/docs/ai-chat/quick-start.mdx +26 -20
  110. package/docs/ai-chat/reference.mdx +6 -3
  111. package/docs/ai-chat/side-channels.mdx +1 -1
  112. package/docs/ai-chat/testing.mdx +16 -4
  113. package/docs/ai-chat/transcript-storage.mdx +14 -6
  114. package/docs/cli-env-commands.mdx +114 -0
  115. package/docs/cli-projects-commands.mdx +62 -0
  116. package/docs/cli-runs-commands.mdx +94 -0
  117. package/docs/concurrency.mdx +384 -0
  118. package/docs/database-connections.mdx +3 -3
  119. package/docs/deploy-environment-variables.mdx +6 -0
  120. package/docs/idempotency.mdx +43 -5
  121. package/docs/introduction.mdx +58 -152
  122. package/docs/limits.mdx +16 -6
  123. package/docs/observability/query.mdx +25 -0
  124. package/docs/queues.mdx +248 -0
  125. package/docs/reports.mdx +1 -1
  126. package/docs/runs/priority.mdx +2 -25
  127. package/docs/self-hosting/env/webapp.mdx +7 -0
  128. package/docs/tasks/overview.mdx +3 -5
  129. package/docs/troubleshooting-alerts.mdx +124 -1
  130. package/docs/troubleshooting.mdx +12 -0
  131. package/docs/writing-tasks-introduction.mdx +2 -1
  132. package/package.json +2 -2
  133. package/docs/queue-concurrency.mdx +0 -358
@@ -149,6 +149,41 @@ export declare const ai: {
149
149
  * ```
150
150
  */
151
151
  declare function createChatAccessToken<TTask extends AnyTask>(taskId: TaskIdentifier<TTask>): Promise<string>;
152
+ /**
153
+ * Register work that must land before anything from this turn reaches the
154
+ * frontend.
155
+ *
156
+ * Like {@link chatDefer} the work starts immediately and is never awaited by
157
+ * the hook that registered it, so it runs alongside the model and costs no
158
+ * time to first token. Unlike `chat.defer`, the output stream waits for it:
159
+ * no chunk of the answer is written to the session until it settles. That
160
+ * makes it the right home for a write the next page load has to see (a
161
+ * conversation row, a message insert), because a reader that can see the
162
+ * answer can also see what the write persisted.
163
+ *
164
+ * Reach for `chat.defer` instead when the timing does not matter for a
165
+ * reload: analytics, audit logs, search-index updates.
166
+ *
167
+ * This is not a consistency barrier for the turn. The work is still in flight
168
+ * while the model runs, so a tool, a `prepareStep`, or anything else executing
169
+ * during the turn can still read the state as it was before the write. It
170
+ * orders the write against what the frontend can see, nothing more. When the
171
+ * turn's own code has to read the write back, `await` it instead and accept
172
+ * the cost.
173
+ *
174
+ * A write registered here that fails, or outlasts the internal timeout, lets
175
+ * the stream through rather than stalling the conversation.
176
+ *
177
+ * @example
178
+ * ```ts
179
+ * onTurnStart: async ({ chatId, uiMessages }) => {
180
+ * chat.deferBeforeOutput(
181
+ * db.chat.update({ where: { id: chatId }, data: { messages: uiMessages } })
182
+ * );
183
+ * },
184
+ * ```
185
+ */
186
+ declare function chatDeferBeforeOutput(promiseOrFn: Promise<unknown> | (() => Promise<unknown>)): void;
152
187
  /**
153
188
  * A stream writer passed to chat lifecycle callbacks (`onPreload`, `onChatStart`,
154
189
  * `onTurnStart`, `onTurnComplete`, `onCompacted`).
@@ -380,6 +415,8 @@ export type ChatNewToolResult = {
380
415
  interface CompactionState {
381
416
  summary: string;
382
417
  baseResponseMessageCount: number;
418
+ /** Completed steps summarized this turn; unlike message counts, matches UI step markers. */
419
+ baseResponseStepCount: number;
383
420
  }
384
421
  /**
385
422
  * Event passed to `summarize` callbacks.
@@ -632,14 +669,24 @@ export type CompactedEvent = {
632
669
  export type ShouldCompactEvent = {
633
670
  /** The current model messages (full conversation). */
634
671
  messages: ModelMessage[];
635
- /** Total token count from the triggering step/turn. */
672
+ /**
673
+ * Total token count of the triggering model call: the step that just finished
674
+ * (`"inner"`), or the turn's LAST step (`"outer"`). This is the size of the
675
+ * context the model held on that call, which is what a compaction decision is
676
+ * about. It is never the sum over a multi-step turn; see `turnUsage` for that.
677
+ */
636
678
  totalTokens: number | undefined;
637
- /** Input token count from the triggering step/turn. */
679
+ /** Input token count of the triggering model call (see `totalTokens`). */
638
680
  inputTokens: number | undefined;
639
- /** Output token count from the triggering step/turn. */
681
+ /** Output token count of the triggering model call (see `totalTokens`). */
640
682
  outputTokens: number | undefined;
641
- /** Full usage object from the triggering step/turn. */
683
+ /** Full usage object of the triggering model call (see `totalTokens`). */
642
684
  usage?: LanguageModelUsage;
685
+ /**
686
+ * The whole turn's usage summed over every step, as the provider billed it.
687
+ * Only present when `source` is `"outer"`.
688
+ */
689
+ turnUsage?: LanguageModelUsage;
643
690
  /** Cumulative token usage across all completed turns. Present in chat.agent contexts. */
644
691
  totalUsage?: LanguageModelUsage;
645
692
  /** The chat session ID (if running inside a chat.agent). */
@@ -943,7 +990,7 @@ type AiStreamTextFn = typeof aiStreamTextSignature;
943
990
  * them: `function loop(messages: ModelMessage[], streamText: ChatStreamText)`.
944
991
  */
945
992
  export type ChatStreamText = AiStreamTextFn;
946
- declare function toStreamTextOptions(options?: ToStreamTextOptionsOptions): Record<string, unknown>;
993
+ declare function toStreamTextOptions(options?: ToStreamTextOptionsOptions, retain?: boolean): Record<string, unknown>;
947
994
  /**
948
995
  * Options for `pipeChat`.
949
996
  */
@@ -1058,7 +1105,9 @@ declare function chatTurn(): ActionTurn;
1058
1105
  * }
1059
1106
  * ```
1060
1107
  */
1061
- declare function pipeChat(source: UIMessageStreamable | AsyncIterable<unknown> | ReadableStream<unknown>, options?: PipeChatOptions): Promise<void>;
1108
+ declare function pipeChat(source: UIMessageStreamable | AsyncIterable<unknown> | ReadableStream<unknown>, options?: PipeChatOptions, capture?: {
1109
+ originalMessages?: UIMessage[];
1110
+ }): Promise<void>;
1062
1111
  /**
1063
1112
  * Options for defining a chat task.
1064
1113
  *
@@ -1409,13 +1458,17 @@ export type TurnCompleteEvent<TClientData = unknown, TUIM extends UIMessage = UI
1409
1458
  */
1410
1459
  uiMessages: TUIM[];
1411
1460
  /**
1412
- * Only the new model messages from this turn (user message(s) + assistant response).
1413
- * Useful for appending to an existing conversation record.
1461
+ * Model messages for this turn's user message(s) and complete assistant response,
1462
+ * including steps summarized during the turn. Same-ID approval and handover
1463
+ * continuations include the full replacement response, so these are not always
1464
+ * an append-only delta. Persist `messages` for future model context, or upsert
1465
+ * `newUIMessages` by ID for the visible conversation.
1414
1466
  */
1415
1467
  newMessages: ModelMessage[];
1416
1468
  /**
1417
- * Only the new UI messages from this turn (user message(s) + assistant response).
1418
- * Useful for inserting individual message records instead of overwriting the full history.
1469
+ * New or updated UI messages from this turn (user message(s) + assistant response).
1470
+ * Upsert by message ID: approval and handover continuations can replace an
1471
+ * existing assistant message.
1419
1472
  */
1420
1473
  newUIMessages: TUIM[];
1421
1474
  /** The assistant's response for this turn, with aborted parts cleaned up when `stopped` is true. Undefined if `pipeChat` was used manually. */
@@ -2864,8 +2917,11 @@ declare class ChatMessageAccumulator {
2864
2917
  modelMessages: ModelMessage[];
2865
2918
  uiMessages: UIMessage[];
2866
2919
  private _compaction?;
2920
+ /** The run a spliced head-start partial contributed, until its response replaces it. */
2921
+ private _handoverRun?;
2867
2922
  private _pendingMessages?;
2868
2923
  private _steeringQueue;
2924
+ private _pendingSteer;
2869
2925
  constructor(options?: {
2870
2926
  compaction?: ChatAgentCompactionOptions;
2871
2927
  pendingMessages?: PendingMessagesOptions;
@@ -2960,8 +3016,10 @@ declare class ChatMessageAccumulator {
2960
3016
  } | undefined>) | undefined;
2961
3017
  /**
2962
3018
  * Run outer-loop compaction if needed. Call after adding the response
2963
- * and capturing usage. Applies `compactModelMessages` and `compactUIMessages`
2964
- * callbacks if configured.
3019
+ * and capturing usage. Pass the LAST step's usage (`result.usage`), which is
3020
+ * the context the model held on its final call; `result.totalUsage` sums every
3021
+ * step of a tool-using turn and belongs in `context.turnUsage`. Applies
3022
+ * `compactModelMessages` and `compactUIMessages` callbacks if configured.
2965
3023
  *
2966
3024
  * @returns `true` if compaction was performed, `false` otherwise.
2967
3025
  */
@@ -2969,6 +3027,8 @@ declare class ChatMessageAccumulator {
2969
3027
  chatId?: string;
2970
3028
  turn?: number;
2971
3029
  clientData?: unknown;
3030
+ /** The whole turn summed over its steps (`result.totalUsage`). */
3031
+ turnUsage?: LanguageModelUsage;
2972
3032
  totalUsage?: LanguageModelUsage;
2973
3033
  }): Promise<boolean>;
2974
3034
  }
@@ -3382,6 +3442,7 @@ export declare const chat: {
3382
3442
  cleanupAbortedParts: typeof cleanupAbortedParts;
3383
3443
  /** Register background work that runs in parallel with streaming. See {@link chatDefer}. */
3384
3444
  defer: typeof chatDefer;
3445
+ deferBeforeOutput: typeof chatDeferBeforeOutput;
3385
3446
  /** Queue model messages for injection at the next `prepareStep` boundary. See {@link injectBackgroundContext}. */
3386
3447
  inject: typeof injectBackgroundContext;
3387
3448
  /** Typed chat output stream for writing custom chunks or piping from subtasks. */