@trigger.dev/sdk 4.8.0 → 4.8.2

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 (101) hide show
  1. package/dist/commonjs/v3/ai-shared.d.ts +6 -0
  2. package/dist/commonjs/v3/ai-shared.js +7 -1
  3. package/dist/commonjs/v3/ai-shared.js.map +1 -1
  4. package/dist/commonjs/v3/ai.d.ts +45 -0
  5. package/dist/commonjs/v3/ai.js +110 -69
  6. package/dist/commonjs/v3/ai.js.map +1 -1
  7. package/dist/commonjs/v3/auth.d.ts +2 -1
  8. package/dist/commonjs/v3/auth.js +18 -12
  9. package/dist/commonjs/v3/auth.js.map +1 -1
  10. package/dist/commonjs/v3/chat-client.d.ts +11 -2
  11. package/dist/commonjs/v3/chat-client.js +28 -10
  12. package/dist/commonjs/v3/chat-client.js.map +1 -1
  13. package/dist/commonjs/v3/chat-react.d.ts +21 -0
  14. package/dist/commonjs/v3/chat-react.js +86 -30
  15. package/dist/commonjs/v3/chat-react.js.map +1 -1
  16. package/dist/commonjs/v3/chat.d.ts +1 -0
  17. package/dist/commonjs/v3/chat.js +4 -1
  18. package/dist/commonjs/v3/chat.js.map +1 -1
  19. package/dist/commonjs/v3/managedChatResponse.d.ts +13 -5
  20. package/dist/commonjs/v3/managedChatResponse.js +36 -18
  21. package/dist/commonjs/v3/managedChatResponse.js.map +1 -1
  22. package/dist/commonjs/v3/steeringContext.d.ts +11 -0
  23. package/dist/commonjs/v3/steeringContext.js +44 -3
  24. package/dist/commonjs/v3/steeringContext.js.map +1 -1
  25. package/dist/commonjs/v3/subAgentStream.d.ts +50 -0
  26. package/dist/commonjs/v3/subAgentStream.js +154 -0
  27. package/dist/commonjs/v3/subAgentStream.js.map +1 -0
  28. package/dist/commonjs/v3/transcriptStorage.js +3 -0
  29. package/dist/commonjs/v3/transcriptStorage.js.map +1 -1
  30. package/dist/commonjs/v3/uiMessageChunks.js +5 -1
  31. package/dist/commonjs/v3/uiMessageChunks.js.map +1 -1
  32. package/dist/commonjs/version.js +1 -1
  33. package/dist/esm/v3/ai-shared.d.ts +6 -0
  34. package/dist/esm/v3/ai-shared.js +6 -0
  35. package/dist/esm/v3/ai-shared.js.map +1 -1
  36. package/dist/esm/v3/ai.d.ts +45 -0
  37. package/dist/esm/v3/ai.js +113 -72
  38. package/dist/esm/v3/ai.js.map +1 -1
  39. package/dist/esm/v3/auth.d.ts +2 -1
  40. package/dist/esm/v3/auth.js +19 -13
  41. package/dist/esm/v3/auth.js.map +1 -1
  42. package/dist/esm/v3/chat-client.d.ts +11 -2
  43. package/dist/esm/v3/chat-client.js +29 -11
  44. package/dist/esm/v3/chat-client.js.map +1 -1
  45. package/dist/esm/v3/chat-react.d.ts +21 -0
  46. package/dist/esm/v3/chat-react.js +81 -30
  47. package/dist/esm/v3/chat-react.js.map +1 -1
  48. package/dist/esm/v3/chat.d.ts +1 -0
  49. package/dist/esm/v3/chat.js +1 -0
  50. package/dist/esm/v3/chat.js.map +1 -1
  51. package/dist/esm/v3/managedChatResponse.d.ts +13 -5
  52. package/dist/esm/v3/managedChatResponse.js +36 -18
  53. package/dist/esm/v3/managedChatResponse.js.map +1 -1
  54. package/dist/esm/v3/steeringContext.d.ts +11 -0
  55. package/dist/esm/v3/steeringContext.js +44 -4
  56. package/dist/esm/v3/steeringContext.js.map +1 -1
  57. package/dist/esm/v3/subAgentStream.d.ts +50 -0
  58. package/dist/esm/v3/subAgentStream.js +149 -0
  59. package/dist/esm/v3/subAgentStream.js.map +1 -0
  60. package/dist/esm/v3/transcriptStorage.js +3 -0
  61. package/dist/esm/v3/transcriptStorage.js.map +1 -1
  62. package/dist/esm/v3/uiMessageChunks.js +5 -1
  63. package/dist/esm/v3/uiMessageChunks.js.map +1 -1
  64. package/dist/esm/version.js +1 -1
  65. package/docs/ai/prompts.mdx +9 -6
  66. package/docs/ai-chat/background-injection.mdx +2 -0
  67. package/docs/ai-chat/chat-local.mdx +4 -4
  68. package/docs/ai-chat/client-protocol.mdx +1 -0
  69. package/docs/ai-chat/fast-starts.mdx +1 -1
  70. package/docs/ai-chat/frontend.mdx +15 -0
  71. package/docs/ai-chat/overview.mdx +5 -4
  72. package/docs/ai-chat/patterns/database-persistence.mdx +3 -3
  73. package/docs/ai-chat/patterns/native-compaction.mdx +6 -6
  74. package/docs/ai-chat/patterns/sub-agents.mdx +82 -56
  75. package/docs/ai-chat/patterns/version-upgrades.mdx +3 -3
  76. package/docs/ai-chat/pending-messages.mdx +2 -0
  77. package/docs/ai-chat/quick-start.mdx +1 -1
  78. package/docs/ai-chat/reference.mdx +22 -0
  79. package/docs/ai-chat/server-chat.mdx +11 -7
  80. package/docs/ai-chat/side-channels.mdx +2 -2
  81. package/docs/ai-chat/types.mdx +5 -5
  82. package/docs/config/config-file.mdx +2 -2
  83. package/docs/database-connections.mdx +2 -2
  84. package/docs/how-to-reduce-your-spend.mdx +4 -0
  85. package/docs/introduction.mdx +104 -24
  86. package/docs/limits.mdx +41 -0
  87. package/docs/mcp-tools.mdx +5 -0
  88. package/docs/observability/query.mdx +29 -0
  89. package/docs/self-hosting/docker.mdx +62 -0
  90. package/docs/self-hosting/env/supervisor.mdx +4 -0
  91. package/docs/self-hosting/env/webapp.mdx +38 -0
  92. package/docs/self-hosting/kubernetes.mdx +2 -0
  93. package/docs/self-hosting/overview.mdx +2 -0
  94. package/docs/troubleshooting-alerts.mdx +39 -0
  95. package/docs/webhooks/deliveries.mdx +4 -0
  96. package/docs/webhooks/overview.mdx +8 -0
  97. package/docs/webhooks/sources.mdx +3 -1
  98. package/docs/webhooks/waiters.mdx +3 -3
  99. package/package.json +2 -2
  100. package/skills/trigger-chat-agent-advanced/SKILL.md +17 -7
  101. package/skills/trigger-cost-savings/SKILL.md +1 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trigger.dev/sdk",
3
- "version": "4.8.0",
3
+ "version": "4.8.2",
4
4
  "description": "trigger.dev Node.JS SDK",
5
5
  "license": "MIT",
6
6
  "publishConfig": {
@@ -69,7 +69,7 @@
69
69
  "dependencies": {
70
70
  "@opentelemetry/api": "1.9.1",
71
71
  "@opentelemetry/semantic-conventions": "1.41.1",
72
- "@trigger.dev/core": "4.8.0",
72
+ "@trigger.dev/core": "4.8.2",
73
73
  "uncrypto": "^0.1.3"
74
74
  },
75
75
  "devDependencies": {
@@ -95,22 +95,27 @@ mutate with `sessions.update`, end with `sessions.close` (terminal, idempotent).
95
95
 
96
96
  ### 2. Durable sub-agent as a streaming tool
97
97
 
98
- `AgentChat` inside an AI SDK `tool()` delegates to a durable sub-agent; its response streams as
99
- preliminary tool results. Give the tool a `toModelOutput` so the model sees a compact summary.
98
+ `AgentChat` inside an AI SDK `tool()` delegates to a durable sub-agent; `chat.forwardSubAgent`
99
+ streams its reply to the frontend and returns the final message as the tool output. Give the tool a
100
+ `toModelOutput` so the model sees a compact summary.
100
101
 
101
102
  ```ts
102
103
  import { tool } from "ai";
104
+ import { chat } from "@trigger.dev/sdk/ai";
103
105
  import { AgentChat } from "@trigger.dev/sdk/chat";
104
106
  import { z } from "zod";
105
107
 
106
108
  const researchTool = tool({
107
109
  description: "Delegate research to a specialist agent.",
108
110
  inputSchema: z.object({ topic: z.string() }),
109
- execute: async function* ({ topic }, { abortSignal }) {
110
- const chat = new AgentChat({ agent: "research-agent" });
111
- const stream = await chat.sendMessage(topic, { abortSignal });
112
- yield* stream.messages(); // UIMessage snapshots become preliminary tool results
113
- await chat.close();
111
+ execute: async ({ topic }, { toolCallId, abortSignal }) => {
112
+ const researcher = new AgentChat({ agent: "research-agent" });
113
+ try {
114
+ const stream = await researcher.sendMessage(topic, { abortSignal });
115
+ return await chat.forwardSubAgent(stream, { toolCallId }); // chunks out once, final UIMessage back
116
+ } finally {
117
+ await researcher.close();
118
+ }
114
119
  },
115
120
  toModelOutput: ({ output: message }) => {
116
121
  const lastText = message?.parts?.findLast((p: { type: string }) => p.type === "text") as
@@ -121,6 +126,11 @@ const researchTool = tool({
121
126
  });
122
127
  ```
123
128
 
129
+ On the frontend, `useSubAgentMessages()` from `@trigger.dev/sdk/chat/react` rebuilds each sub-agent
130
+ while it runs: pass its `onData` to `useChat` and render `subAgents.get(part.toolCallId) ?? part.output`.
131
+ Do not `yield* stream.messages()` from a tool: every snapshot repeats the whole message, so the bytes
132
+ written grow with the square of the reply length.
133
+
124
134
  For a subtask exposed via `execute: ai.toolExecute(task)`, stream progress to the agent's run with
125
135
  `chat.stream.writer({ target: "root" })`. `target` accepts `"self" | "parent" | "root" | <runId>`.
126
136
  Inside the subtask, read context with `ai.toolCallId()` and `ai.chatContextOrThrow<typeof myChat>()`
@@ -105,6 +105,7 @@ Larger machines cost proportionally more per second of compute:
105
105
  ## Key principles
106
106
 
107
107
  - **Waits > 5 seconds are free** — checkpointed, no compute charge.
108
+ - **Webhook filters skip runs** — a webhook delivery starts no run when no subscriber's filter matches, so it costs no compute (a run already waiting for that webhook still resumes). Receiving webhooks has no separate charge.
108
109
  - **Start small, scale up** — the default `small-1x` is right for most tasks.
109
110
  - **I/O-bound tasks don't need big machines** — API calls and DB queries wait on the network.
110
111
  - **Debounce saves the most on high-frequency tasks** — it consolidates bursts into single runs.