@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
@@ -1 +1 @@
1
- {"version":3,"file":"ai-runtime-cjs.cjs","sourceRoot":"","sources":["../../../src/imports/ai-runtime-cjs.cts"],"names":[],"mappings":";AAAA,8EAA8E;AAC9E,iFAAiF;;AAEjF,aAAa;AACb,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;AAEzB,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,sBAAsB,GAAG,EAAE,CAAC,sBAAsB,CAAC;AAClE,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,WAAW,GAAG,EAAE,CAAC,WAAW,CAAC;AAC5C,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,UAAU,GAAG,EAAE,CAAC,UAAU,CAAC;AAC1C,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,WAAW,GAAG,EAAE,CAAC,WAAW,CAAC;AAC5C,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,YAAY,GAAG,EAAE,CAAC,YAAY,CAAC;AAC9C,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,UAAU,GAAG,EAAE,CAAC,UAAU,CAAC;AAC1C,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,mBAAmB,GAAG,EAAE,CAAC,mBAAmB,CAAC;AAC5D,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,WAAW,GAAG,EAAE,CAAC,WAAW,CA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AAa;AACb,MAAM,CAAC,OAAO,CAAC,IAAI,GAAG,EAAE,CAAC,IAAI,CAAC;AAC9B,aAAa;AACb,MAAM,CAAC,OAAO,CAAC,SAAS,GAAG,EAAE,CAAC,SAAS,CAAC"}
@@ -7,6 +7,8 @@ const ai = require("ai");
7
7
  // @ts-ignore
8
8
  module.exports.convertToModelMessages = ai.convertToModelMessages;
9
9
  // @ts-ignore
10
+ module.exports.createUIMessageStream = ai.createUIMessageStream;
11
+ // @ts-ignore
10
12
  module.exports.dynamicTool = ai.dynamicTool;
11
13
  // @ts-ignore
12
14
  module.exports.generateId = ai.generateId;
@@ -3307,6 +3307,11 @@ export type ChatStartSessionParams<TChat extends AnyTask = AnyTask> = {
3307
3307
  * server-side metadata that doesn't go through the agent's `clientDataSchema`.
3308
3308
  */
3309
3309
  metadata?: Record<string, unknown>;
3310
+ /**
3311
+ * Up to 10 tags on the Session row, for filtering sessions in the dashboard.
3312
+ * Run tags go in `triggerConfig.tags`.
3313
+ */
3314
+ tags?: string[];
3310
3315
  };
3311
3316
  /**
3312
3317
  * Result from {@link createChatStartSessionAction}'s returned function.
@@ -20,7 +20,9 @@ const chatRouteWait_js_1 = require("./chatRouteWait.js");
20
20
  const ai_runtime_js_1 = require("../imports/ai-runtime.js");
21
21
  const transcriptStorage_js_1 = require("./transcriptStorage.js");
22
22
  const compactionResponse_js_1 = require("./compactionResponse.js");
23
+ const toolResultOrder_js_1 = require("./toolResultOrder.js");
23
24
  const managedChatResponse_js_1 = require("./managedChatResponse.js");
25
+ const uiMessageChunks_js_1 = require("./uiMessageChunks.js");
24
26
  const steeringContext_js_1 = require("./steeringContext.js");
25
27
  let transcriptStorageOverride;
26
28
  /**
@@ -219,9 +221,9 @@ function __setReplaySessionOutTailImplForTests(impl) {
219
221
  * 2. Filter out the agent's control chunks (`type: "trigger:*"`) — they
220
222
  * ride on the same stream as the user-visible UIMessageChunks.
221
223
  * 3. Split chunks at `start`/`finish` boundaries so each segment is a
222
- * single message, then feed each segment through the AI SDK's
223
- * `readUIMessageStream` reducer (the same one `useChat` uses on the
224
- * browser side) and grab the final emitted snapshot.
224
+ * single message, then reduce each segment with the AI SDK's reducer
225
+ * (the same one `useChat` uses on the browser side) via
226
+ * {@link reduceUIMessageChunks}, which builds only the final state.
225
227
  * 4. The trailing message — if it never received a `finish` chunk —
226
228
  * goes through `cleanupAbortedParts` so partial in-flight parts
227
229
  * don't leak into the next turn's accumulator. Drop it entirely
@@ -272,8 +274,8 @@ async function replaySessionOutTail(sessionId, options) {
272
274
  }
273
275
  if (!current) {
274
276
  // Chunk arrived before any `start`. Synthesize a segment so the reducer
275
- // has something to work with — `readUIMessageStream` tolerates a missing
276
- // `start` because we pass `message: undefined`.
277
+ // has something to work with. The reducer tolerates a missing `start`
278
+ // and leaves the message ID empty.
277
279
  current = { chunks: [], closed: false };
278
280
  segments.push(current);
279
281
  }
@@ -289,18 +291,9 @@ async function replaySessionOutTail(sessionId, options) {
289
291
  for (let i = 0; i < segments.length; i++) {
290
292
  const seg = segments[i];
291
293
  const isTrailing = i === segments.length - 1 && !seg.closed;
292
- const segmentStream = new ReadableStream({
293
- start(controller) {
294
- for (const c of seg.chunks)
295
- controller.enqueue(c);
296
- controller.close();
297
- },
298
- });
299
294
  let last;
300
295
  try {
301
- for await (const snapshot of (0, ai_runtime_js_1.readUIMessageStream)({ stream: segmentStream })) {
302
- last = snapshot;
303
- }
296
+ last = await (0, uiMessageChunks_js_1.reduceUIMessageChunks)(seg.chunks);
304
297
  }
305
298
  catch (error) {
306
299
  // Reducer error — the segment is malformed. Skip it and keep going so a
@@ -333,15 +326,15 @@ async function replaySessionOutTail(sessionId, options) {
333
326
  }
334
327
  /**
335
328
  * Test-only entry point that bypasses `__setReplaySessionOutTailImplForTests`
336
- * and reaches the real `apiClient.subscribeToSessionStream` + chunk-segment
337
- * splitter + `readUIMessageStream` reducer. Pairs with the snapshot
329
+ * and reaches the real `apiClient.readSessionStreamRecords` + chunk-segment
330
+ * splitter + {@link reduceUIMessageChunks} reducer. Pairs with the snapshot
338
331
  * production-path wrappers above. Lets `replay-session-out.test.ts` drive
339
332
  * synthetic chunk sequences through the real reducer to lock down chunk-
340
333
  * stream → `UIMessage[]` correctness — if the AI SDK's chunk semantics
341
334
  * shift in a future version, the test catches it before customers do.
342
335
  *
343
- * Tests should mock `apiClient.subscribeToSessionStream` (e.g. via
344
- * `vi.spyOn(apiClient, ...)`) to feed a `ReadableStream<UIMessageChunk>`.
336
+ * Tests should stub `apiClient.readSessionStreamRecords` to return the
337
+ * recorded chunks as session stream records.
345
338
  *
346
339
  * Not part of the public API.
347
340
  * @internal
@@ -3553,7 +3546,11 @@ function toStreamTextOptions(options, retain = true) {
3553
3546
  });
3554
3547
  locals_js_1.locals.set(chatPendingBackgroundKey, pendingBackground);
3555
3548
  }
3556
- return resultMessages ? { messages: resultMessages } : undefined;
3549
+ // 4. Parallel tool results in call order, the order the next turn's history
3550
+ // will list them in. See `withToolResultsInCallOrder`.
3551
+ const base = resultMessages ?? messages;
3552
+ const ordered = (0, toolResultOrder_js_1.withToolResultsInCallOrder)(base);
3553
+ return resultMessages || ordered !== base ? { messages: ordered } : undefined;
3557
3554
  };
3558
3555
  }
3559
3556
  if (retain && typeof result.prepareStep === "function") {
@@ -5758,8 +5755,11 @@ function chatAgent(options) {
5758
5755
  }
5759
5756
  }
5760
5757
  catch (error) {
5761
- // Handle AbortError from streamText gracefully
5762
- if (error instanceof Error && error.name === "AbortError") {
5758
+ // A stop aborts with a string reason, which the managed pipe
5759
+ // rethrows as-is. Match the reason itself so a real failure
5760
+ // after a stop is still reported.
5761
+ if ((error instanceof Error && error.name === "AbortError") ||
5762
+ (combinedSignal.aborted && error === combinedSignal.reason)) {
5763
5763
  if (runSignal.aborted) {
5764
5764
  return "exit"; // Full run cancellation — exit
5765
5765
  }
@@ -7595,7 +7595,7 @@ function tapUIMessageChunks(source, buffer) {
7595
7595
  * Reconstruct a partial assistant `UIMessage` from the raw chunks that
7596
7596
  * streamed before a failure — the fallback for {@link pipeChatAndCapture}
7597
7597
  * when a transport error abandons the stream before `onFinish` runs. Uses the
7598
- * same `readUIMessageStream` reducer as the boot-time replay path. Returns
7598
+ * same {@link reduceUIMessageChunks} reducer as the boot-time replay path. Returns
7599
7599
  * `undefined` if there's nothing to assemble or the reducer throws.
7600
7600
  */
7601
7601
  async function assemblePartialFromChunks(chunks) {
@@ -7606,18 +7606,7 @@ async function assemblePartialFromChunks(chunks) {
7606
7606
  if (relevant.length === 0)
7607
7607
  return undefined;
7608
7608
  try {
7609
- const stream = new ReadableStream({
7610
- start(controller) {
7611
- for (const chunk of relevant)
7612
- controller.enqueue(chunk);
7613
- controller.close();
7614
- },
7615
- });
7616
- let last;
7617
- for await (const message of (0, ai_runtime_js_1.readUIMessageStream)({ stream })) {
7618
- last = message;
7619
- }
7620
- return last;
7609
+ return await (0, uiMessageChunks_js_1.reduceUIMessageChunks)(relevant);
7621
7610
  }
7622
7611
  catch {
7623
7612
  return undefined;
@@ -8863,6 +8852,7 @@ function createChatStartSessionAction(taskId, options) {
8863
8852
  taskIdentifier: taskId,
8864
8853
  triggerConfig,
8865
8854
  metadata: params.metadata,
8855
+ ...(params.tags !== undefined ? { tags: params.tags } : {}),
8866
8856
  };
8867
8857
  const baseURLOption = options?.baseURL;
8868
8858
  const fetchOverride = options?.fetch;