@trigger.dev/sdk 4.7.1 → 4.7.3

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 (42) 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.d.ts +5 -0
  4. package/dist/commonjs/v3/ai.js +25 -35
  5. package/dist/commonjs/v3/ai.js.map +1 -1
  6. package/dist/commonjs/v3/chat-server.d.ts +7 -0
  7. package/dist/commonjs/v3/chat-server.js +3 -0
  8. package/dist/commonjs/v3/chat-server.js.map +1 -1
  9. package/dist/commonjs/v3/managedChatResponse.js +3 -15
  10. package/dist/commonjs/v3/managedChatResponse.js.map +1 -1
  11. package/dist/commonjs/v3/test/mock-chat-agent.js +4 -15
  12. package/dist/commonjs/v3/test/mock-chat-agent.js.map +1 -1
  13. package/dist/commonjs/v3/toolResultOrder.d.ts +15 -0
  14. package/dist/commonjs/v3/toolResultOrder.js +58 -0
  15. package/dist/commonjs/v3/toolResultOrder.js.map +1 -0
  16. package/dist/commonjs/v3/uiMessageChunks.d.ts +1 -0
  17. package/dist/commonjs/v3/uiMessageChunks.js +119 -0
  18. package/dist/commonjs/v3/uiMessageChunks.js.map +1 -0
  19. package/dist/commonjs/version.js +1 -1
  20. package/dist/esm/imports/ai-runtime.d.ts +2 -2
  21. package/dist/esm/imports/ai-runtime.js +2 -2
  22. package/dist/esm/imports/ai-runtime.js.map +1 -1
  23. package/dist/esm/v3/ai.d.ts +5 -0
  24. package/dist/esm/v3/ai.js +26 -36
  25. package/dist/esm/v3/ai.js.map +1 -1
  26. package/dist/esm/v3/chat-server.d.ts +7 -0
  27. package/dist/esm/v3/chat-server.js +3 -0
  28. package/dist/esm/v3/chat-server.js.map +1 -1
  29. package/dist/esm/v3/managedChatResponse.js +4 -16
  30. package/dist/esm/v3/managedChatResponse.js.map +1 -1
  31. package/dist/esm/v3/test/mock-chat-agent.js +4 -15
  32. package/dist/esm/v3/test/mock-chat-agent.js.map +1 -1
  33. package/dist/esm/v3/toolResultOrder.d.ts +15 -0
  34. package/dist/esm/v3/toolResultOrder.js +55 -0
  35. package/dist/esm/v3/toolResultOrder.js.map +1 -0
  36. package/dist/esm/v3/uiMessageChunks.d.ts +1 -0
  37. package/dist/esm/v3/uiMessageChunks.js +116 -0
  38. package/dist/esm/v3/uiMessageChunks.js.map +1 -0
  39. package/dist/esm/version.js +1 -1
  40. package/docs/self-hosting/env/supervisor.mdx +0 -1
  41. package/docs/self-hosting/env/webapp.mdx +1 -0
  42. package/package.json +2 -2
package/dist/esm/v3/ai.js CHANGED
@@ -4,10 +4,12 @@ import { accessoryAttributes, apiClientManager, controlSubtype, generateJWT, get
4
4
  import { trace } from "@opentelemetry/api";
5
5
  import { traceSessionIdle } from "./sessionTracing.js";
6
6
  import { waitForChatRouteAfterIdle } from "./chatRouteWait.js";
7
- import { tool as aiTool, convertToModelMessages, dynamicTool, generateId as generateMessageId, getToolName, isToolUIPart, jsonSchema, readUIMessageStream, streamText as aiStreamText, zodSchema, } from "../imports/ai-runtime.js";
7
+ import { tool as aiTool, convertToModelMessages, dynamicTool, generateId as generateMessageId, getToolName, isToolUIPart, jsonSchema, streamText as aiStreamText, zodSchema, } from "../imports/ai-runtime.js";
8
8
  import { createTranscriptShadow, defaultStorage, diffTranscript, fingerprintMessage, parseTranscriptRuntimeState, restoreModelLane, } from "./transcriptStorage.js";
9
9
  import { responseAfterCompaction } from "./compactionResponse.js";
10
+ import { withToolResultsInCallOrder } from "./toolResultOrder.js";
10
11
  import { ManagedChatResponse, createOrderedChatWriter } from "./managedChatResponse.js";
12
+ import { reduceUIMessageChunks } from "./uiMessageChunks.js";
11
13
  import { convertSteeredMessages, retainStepMessages, steeringMarkers, } from "./steeringContext.js";
12
14
  let transcriptStorageOverride;
13
15
  /**
@@ -196,9 +198,9 @@ export function __setReplaySessionOutTailImplForTests(impl) {
196
198
  * 2. Filter out the agent's control chunks (`type: "trigger:*"`) — they
197
199
  * ride on the same stream as the user-visible UIMessageChunks.
198
200
  * 3. Split chunks at `start`/`finish` boundaries so each segment is a
199
- * single message, then feed each segment through the AI SDK's
200
- * `readUIMessageStream` reducer (the same one `useChat` uses on the
201
- * browser side) and grab the final emitted snapshot.
201
+ * single message, then reduce each segment with the AI SDK's reducer
202
+ * (the same one `useChat` uses on the browser side) via
203
+ * {@link reduceUIMessageChunks}, which builds only the final state.
202
204
  * 4. The trailing message — if it never received a `finish` chunk —
203
205
  * goes through `cleanupAbortedParts` so partial in-flight parts
204
206
  * don't leak into the next turn's accumulator. Drop it entirely
@@ -249,8 +251,8 @@ async function replaySessionOutTail(sessionId, options) {
249
251
  }
250
252
  if (!current) {
251
253
  // Chunk arrived before any `start`. Synthesize a segment so the reducer
252
- // has something to work with — `readUIMessageStream` tolerates a missing
253
- // `start` because we pass `message: undefined`.
254
+ // has something to work with. The reducer tolerates a missing `start`
255
+ // and leaves the message ID empty.
254
256
  current = { chunks: [], closed: false };
255
257
  segments.push(current);
256
258
  }
@@ -266,18 +268,9 @@ async function replaySessionOutTail(sessionId, options) {
266
268
  for (let i = 0; i < segments.length; i++) {
267
269
  const seg = segments[i];
268
270
  const isTrailing = i === segments.length - 1 && !seg.closed;
269
- const segmentStream = new ReadableStream({
270
- start(controller) {
271
- for (const c of seg.chunks)
272
- controller.enqueue(c);
273
- controller.close();
274
- },
275
- });
276
271
  let last;
277
272
  try {
278
- for await (const snapshot of readUIMessageStream({ stream: segmentStream })) {
279
- last = snapshot;
280
- }
273
+ last = await reduceUIMessageChunks(seg.chunks);
281
274
  }
282
275
  catch (error) {
283
276
  // Reducer error — the segment is malformed. Skip it and keep going so a
@@ -310,15 +303,15 @@ async function replaySessionOutTail(sessionId, options) {
310
303
  }
311
304
  /**
312
305
  * Test-only entry point that bypasses `__setReplaySessionOutTailImplForTests`
313
- * and reaches the real `apiClient.subscribeToSessionStream` + chunk-segment
314
- * splitter + `readUIMessageStream` reducer. Pairs with the snapshot
306
+ * and reaches the real `apiClient.readSessionStreamRecords` + chunk-segment
307
+ * splitter + {@link reduceUIMessageChunks} reducer. Pairs with the snapshot
315
308
  * production-path wrappers above. Lets `replay-session-out.test.ts` drive
316
309
  * synthetic chunk sequences through the real reducer to lock down chunk-
317
310
  * stream → `UIMessage[]` correctness — if the AI SDK's chunk semantics
318
311
  * shift in a future version, the test catches it before customers do.
319
312
  *
320
- * Tests should mock `apiClient.subscribeToSessionStream` (e.g. via
321
- * `vi.spyOn(apiClient, ...)`) to feed a `ReadableStream<UIMessageChunk>`.
313
+ * Tests should stub `apiClient.readSessionStreamRecords` to return the
314
+ * recorded chunks as session stream records.
322
315
  *
323
316
  * Not part of the public API.
324
317
  * @internal
@@ -3540,7 +3533,11 @@ function toStreamTextOptions(options, retain = true) {
3540
3533
  });
3541
3534
  locals.set(chatPendingBackgroundKey, pendingBackground);
3542
3535
  }
3543
- return resultMessages ? { messages: resultMessages } : undefined;
3536
+ // 4. Parallel tool results in call order, the order the next turn's history
3537
+ // will list them in. See `withToolResultsInCallOrder`.
3538
+ const base = resultMessages ?? messages;
3539
+ const ordered = withToolResultsInCallOrder(base);
3540
+ return resultMessages || ordered !== base ? { messages: ordered } : undefined;
3544
3541
  };
3545
3542
  }
3546
3543
  if (retain && typeof result.prepareStep === "function") {
@@ -5745,8 +5742,11 @@ function chatAgent(options) {
5745
5742
  }
5746
5743
  }
5747
5744
  catch (error) {
5748
- // Handle AbortError from streamText gracefully
5749
- if (error instanceof Error && error.name === "AbortError") {
5745
+ // A stop aborts with a string reason, which the managed pipe
5746
+ // rethrows as-is. Match the reason itself so a real failure
5747
+ // after a stop is still reported.
5748
+ if ((error instanceof Error && error.name === "AbortError") ||
5749
+ (combinedSignal.aborted && error === combinedSignal.reason)) {
5750
5750
  if (runSignal.aborted) {
5751
5751
  return "exit"; // Full run cancellation — exit
5752
5752
  }
@@ -7582,7 +7582,7 @@ function tapUIMessageChunks(source, buffer) {
7582
7582
  * Reconstruct a partial assistant `UIMessage` from the raw chunks that
7583
7583
  * streamed before a failure — the fallback for {@link pipeChatAndCapture}
7584
7584
  * when a transport error abandons the stream before `onFinish` runs. Uses the
7585
- * same `readUIMessageStream` reducer as the boot-time replay path. Returns
7585
+ * same {@link reduceUIMessageChunks} reducer as the boot-time replay path. Returns
7586
7586
  * `undefined` if there's nothing to assemble or the reducer throws.
7587
7587
  */
7588
7588
  async function assemblePartialFromChunks(chunks) {
@@ -7593,18 +7593,7 @@ async function assemblePartialFromChunks(chunks) {
7593
7593
  if (relevant.length === 0)
7594
7594
  return undefined;
7595
7595
  try {
7596
- const stream = new ReadableStream({
7597
- start(controller) {
7598
- for (const chunk of relevant)
7599
- controller.enqueue(chunk);
7600
- controller.close();
7601
- },
7602
- });
7603
- let last;
7604
- for await (const message of readUIMessageStream({ stream })) {
7605
- last = message;
7606
- }
7607
- return last;
7596
+ return await reduceUIMessageChunks(relevant);
7608
7597
  }
7609
7598
  catch {
7610
7599
  return undefined;
@@ -8850,6 +8839,7 @@ function createChatStartSessionAction(taskId, options) {
8850
8839
  taskIdentifier: taskId,
8851
8840
  triggerConfig,
8852
8841
  metadata: params.metadata,
8842
+ ...(params.tags !== undefined ? { tags: params.tags } : {}),
8853
8843
  };
8854
8844
  const baseURLOption = options?.baseURL;
8855
8845
  const fetchOverride = options?.fetch;