@trigger.dev/sdk 0.0.0-chat-prerelease-20260507122230 → 0.0.0-chat-prerelease-20260517214402

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 (102) hide show
  1. package/dist/commonjs/v3/ai.d.ts +59 -300
  2. package/dist/commonjs/v3/ai.js +619 -1884
  3. package/dist/commonjs/v3/ai.js.map +1 -1
  4. package/dist/commonjs/v3/auth.d.ts +0 -10
  5. package/dist/commonjs/v3/auth.js.map +1 -1
  6. package/dist/commonjs/v3/chat-client.d.ts +39 -78
  7. package/dist/commonjs/v3/chat-client.js +196 -210
  8. package/dist/commonjs/v3/chat-client.js.map +1 -1
  9. package/dist/commonjs/v3/chat-constants.d.ts +7 -0
  10. package/dist/commonjs/v3/chat-constants.js +14 -0
  11. package/dist/commonjs/v3/chat-constants.js.map +1 -0
  12. package/dist/commonjs/v3/chat-react.d.ts +1 -1
  13. package/dist/commonjs/v3/chat-react.js +10 -10
  14. package/dist/commonjs/v3/chat-react.js.map +1 -1
  15. package/dist/commonjs/v3/chat.d.ts +406 -245
  16. package/dist/commonjs/v3/chat.js +643 -588
  17. package/dist/commonjs/v3/chat.js.map +1 -1
  18. package/dist/commonjs/v3/chat.test.js +1690 -719
  19. package/dist/commonjs/v3/chat.test.js.map +1 -1
  20. package/dist/commonjs/v3/index.d.ts +1 -3
  21. package/dist/commonjs/v3/index.js +1 -5
  22. package/dist/commonjs/v3/index.js.map +1 -1
  23. package/dist/commonjs/v3/runs.d.ts +4 -4
  24. package/dist/commonjs/v3/test/mock-chat-agent.d.ts +0 -32
  25. package/dist/commonjs/v3/test/mock-chat-agent.js +34 -110
  26. package/dist/commonjs/v3/test/mock-chat-agent.js.map +1 -1
  27. package/dist/commonjs/version.js +1 -1
  28. package/dist/esm/v3/ai.d.ts +59 -300
  29. package/dist/esm/v3/ai.js +620 -1883
  30. package/dist/esm/v3/ai.js.map +1 -1
  31. package/dist/esm/v3/auth.d.ts +0 -10
  32. package/dist/esm/v3/auth.js.map +1 -1
  33. package/dist/esm/v3/chat-client.d.ts +39 -78
  34. package/dist/esm/v3/chat-client.js +196 -210
  35. package/dist/esm/v3/chat-client.js.map +1 -1
  36. package/dist/esm/v3/chat-constants.d.ts +7 -0
  37. package/dist/esm/v3/chat-constants.js +8 -0
  38. package/dist/esm/v3/chat-constants.js.map +1 -0
  39. package/dist/esm/v3/chat-react.d.ts +1 -1
  40. package/dist/esm/v3/chat-react.js +8 -8
  41. package/dist/esm/v3/chat-react.js.map +1 -1
  42. package/dist/esm/v3/chat.d.ts +406 -245
  43. package/dist/esm/v3/chat.js +643 -588
  44. package/dist/esm/v3/chat.js.map +1 -1
  45. package/dist/esm/v3/chat.test.js +1690 -719
  46. package/dist/esm/v3/chat.test.js.map +1 -1
  47. package/dist/esm/v3/index.d.ts +1 -3
  48. package/dist/esm/v3/index.js +1 -3
  49. package/dist/esm/v3/index.js.map +1 -1
  50. package/dist/esm/v3/test/mock-chat-agent.d.ts +0 -32
  51. package/dist/esm/v3/test/mock-chat-agent.js +34 -110
  52. package/dist/esm/v3/test/mock-chat-agent.js.map +1 -1
  53. package/dist/esm/version.js +1 -1
  54. package/package.json +6 -34
  55. package/dist/commonjs/v3/agentSkillsRuntime.d.ts +0 -28
  56. package/dist/commonjs/v3/agentSkillsRuntime.js +0 -123
  57. package/dist/commonjs/v3/agentSkillsRuntime.js.map +0 -1
  58. package/dist/commonjs/v3/ai-shared.d.ts +0 -161
  59. package/dist/commonjs/v3/ai-shared.js +0 -25
  60. package/dist/commonjs/v3/ai-shared.js.map +0 -1
  61. package/dist/commonjs/v3/chat-server.d.ts +0 -191
  62. package/dist/commonjs/v3/chat-server.js +0 -687
  63. package/dist/commonjs/v3/chat-server.js.map +0 -1
  64. package/dist/commonjs/v3/chat-server.test.d.ts +0 -1
  65. package/dist/commonjs/v3/chat-server.test.js +0 -515
  66. package/dist/commonjs/v3/chat-server.test.js.map +0 -1
  67. package/dist/commonjs/v3/sessions.d.ts +0 -188
  68. package/dist/commonjs/v3/sessions.js +0 -541
  69. package/dist/commonjs/v3/sessions.js.map +0 -1
  70. package/dist/commonjs/v3/skill.d.ts +0 -99
  71. package/dist/commonjs/v3/skill.js +0 -155
  72. package/dist/commonjs/v3/skill.js.map +0 -1
  73. package/dist/commonjs/v3/skills.d.ts +0 -2
  74. package/dist/commonjs/v3/skills.js +0 -6
  75. package/dist/commonjs/v3/skills.js.map +0 -1
  76. package/dist/commonjs/v3/test/test-session-handle.d.ts +0 -38
  77. package/dist/commonjs/v3/test/test-session-handle.js +0 -228
  78. package/dist/commonjs/v3/test/test-session-handle.js.map +0 -1
  79. package/dist/esm/v3/agentSkillsRuntime.d.ts +0 -28
  80. package/dist/esm/v3/agentSkillsRuntime.js +0 -96
  81. package/dist/esm/v3/agentSkillsRuntime.js.map +0 -1
  82. package/dist/esm/v3/ai-shared.d.ts +0 -161
  83. package/dist/esm/v3/ai-shared.js +0 -22
  84. package/dist/esm/v3/ai-shared.js.map +0 -1
  85. package/dist/esm/v3/chat-server.d.ts +0 -191
  86. package/dist/esm/v3/chat-server.js +0 -684
  87. package/dist/esm/v3/chat-server.js.map +0 -1
  88. package/dist/esm/v3/chat-server.test.d.ts +0 -1
  89. package/dist/esm/v3/chat-server.test.js +0 -513
  90. package/dist/esm/v3/chat-server.test.js.map +0 -1
  91. package/dist/esm/v3/sessions.d.ts +0 -188
  92. package/dist/esm/v3/sessions.js +0 -533
  93. package/dist/esm/v3/sessions.js.map +0 -1
  94. package/dist/esm/v3/skill.d.ts +0 -99
  95. package/dist/esm/v3/skill.js +0 -128
  96. package/dist/esm/v3/skill.js.map +0 -1
  97. package/dist/esm/v3/skills.d.ts +0 -2
  98. package/dist/esm/v3/skills.js +0 -2
  99. package/dist/esm/v3/skills.js.map +0 -1
  100. package/dist/esm/v3/test/test-session-handle.d.ts +0 -38
  101. package/dist/esm/v3/test/test-session-handle.js +0 -223
  102. package/dist/esm/v3/test/test-session-handle.js.map +0 -1
@@ -1,13 +1,12 @@
1
- import { AnyTask, type RealtimeDefinedInputStream, type RealtimeDefinedStream, Task, type inferSchemaIn, type inferSchemaOut, type TaskIdentifier, type TaskOptions, type TaskSchema, type TaskRunContext, type TaskWithSchema } from "@trigger.dev/core/v3";
1
+ import { AnyTask, Task, type inferSchemaIn, type inferSchemaOut, type TaskIdentifier, type TaskOptions, type TaskSchema, type TaskRunContext, type TaskWithSchema } from "@trigger.dev/core/v3";
2
2
  import type { FinishReason, ModelMessage, ToolSet, UIMessage, UIMessageChunk, UIMessageStreamOptions, LanguageModelUsage } from "ai";
3
3
  import { Tool, ToolCallOptions } from "ai";
4
4
  import { locals } from "./locals.js";
5
5
  import type { ResolvedPrompt } from "./prompt.js";
6
- import type { ResolvedSkill } from "./skill.js";
7
- import { type SessionTriggerConfig } from "@trigger.dev/core/v3";
6
+ import type { TriggerChatTaskParams, TriggerChatTaskResult } from "./chat.js";
8
7
  /** Re-export for typing `ctx` in `chat.agent` hooks without importing `@trigger.dev/core`. */
9
8
  export type { TaskRunContext } from "@trigger.dev/core/v3";
10
- import { type ChatStorePatchOperation } from "@trigger.dev/core/v3/chat-client";
9
+ import { CHAT_MESSAGES_STREAM_ID, CHAT_STOP_STREAM_ID } from "./chat-constants.js";
11
10
  export type ToolCallExecutionOptions = {
12
11
  toolCallId: string;
13
12
  experimental_context?: unknown;
@@ -133,28 +132,12 @@ export declare const ai: {
133
132
  */
134
133
  declare function createChatAccessToken<TTask extends AnyTask>(taskId: TaskIdentifier<TTask>): Promise<string>;
135
134
  /**
136
- * Listener fired when the store value changes. `operations` is present for
137
- * `patch()` updates and absent for `set()` (which is a full snapshot).
135
+ * The default stream key used for chat transport communication.
136
+ * Both `TriggerChatTransport` (frontend) and `pipeChat`/`chatAgent` (backend)
137
+ * use this key by default.
138
138
  */
139
- export type ChatStoreChangeListener<TStore = unknown> = (value: TStore, operations?: ChatStorePatchOperation[]) => void;
140
- /**
141
- * Replace the entire store value with `value`. Emits a `store-snapshot`
142
- * chunk on the chat output stream and fires all `onChange` listeners.
143
- */
144
- declare function chatStoreSet<TStore = unknown>(value: TStore): void;
145
- /**
146
- * Apply RFC 6902 JSON Patch operations to the current store value.
147
- * Emits a `store-delta` chunk on the chat output stream and fires all
148
- * `onChange` listeners with the new value and the operations.
149
- */
150
- declare function chatStorePatch(operations: ChatStorePatchOperation[]): void;
151
- /** Get the current store value. Returns `undefined` if no value has been set. */
152
- declare function chatStoreGet<TStore = unknown>(): TStore | undefined;
153
- /**
154
- * Subscribe to store changes for the current run. Returns an
155
- * unsubscribe function.
156
- */
157
- declare function chatStoreOnChange<TStore = unknown>(listener: ChatStoreChangeListener<TStore>): () => void;
139
+ export declare const CHAT_STREAM_KEY = "chat";
140
+ export { CHAT_MESSAGES_STREAM_ID, CHAT_STOP_STREAM_ID };
158
141
  /**
159
142
  * A stream writer passed to chat lifecycle callbacks (`onPreload`, `onChatStart`,
160
143
  * `onTurnStart`, `onTurnComplete`, `onCompacted`).
@@ -180,8 +163,25 @@ export type ChatWriter = {
180
163
  /** Merge another stream's chunks into the chat stream. */
181
164
  merge(stream: ReadableStream<UIMessageChunk>): void;
182
165
  };
183
- import type { ChatTaskWirePayload } from "./ai-shared.js";
184
- export type { ChatTaskWirePayload, ChatInputChunk } from "./ai-shared.js";
166
+ /**
167
+ * The wire payload shape sent by `TriggerChatTransport`.
168
+ * Uses `metadata` to match the AI SDK's `ChatRequestOptions` field name.
169
+ */
170
+ export type ChatTaskWirePayload<TMessage extends UIMessage = UIMessage, TMetadata = unknown> = {
171
+ messages: TMessage[];
172
+ chatId: string;
173
+ trigger: "submit-message" | "regenerate-message" | "preload" | "close" | "action";
174
+ messageId?: string;
175
+ metadata?: TMetadata;
176
+ /** Custom action payload when `trigger` is `"action"`. Validated against `actionSchema` on the backend. */
177
+ action?: unknown;
178
+ /** Whether this run is continuing an existing chat whose previous run ended. */
179
+ continuation?: boolean;
180
+ /** The run ID of the previous run (only set when `continuation` is true). */
181
+ previousRunId?: string;
182
+ /** Override idle timeout for this run (seconds). Set by transport.preload(). */
183
+ idleTimeoutInSeconds?: number;
184
+ };
185
185
  /**
186
186
  * The payload shape passed to the `chatAgent` run function.
187
187
  *
@@ -218,14 +218,6 @@ export type ChatTaskPayload<TClientData = unknown> = {
218
218
  previousRunId?: string;
219
219
  /** Whether this run was preloaded before the first message. */
220
220
  preloaded: boolean;
221
- /**
222
- * The friendlyId of the Session primitive backing this chat. Use with
223
- * `sessions.open(sessionId)` when you need direct access to the session's
224
- * `.in` / `.out` channels outside the hooks the agent already wires for
225
- * you. Undefined only for legacy transports that predate the sessions
226
- * migration.
227
- */
228
- sessionId?: string;
229
221
  };
230
222
  /**
231
223
  * Abort signals provided to the `chatAgent` run function.
@@ -263,28 +255,6 @@ export type ChatTurnUsage = LanguageModelUsage;
263
255
  * and converts to `ModelMessage[]` internally.
264
256
  */
265
257
  declare function setChatMessages<TUIM extends UIMessage = UIMessage>(uiMessages: TUIM[]): void;
266
- /**
267
- * A tool call surfaced by `chat.history.getPendingToolCalls()` /
268
- * `getResolvedToolCalls()`. Identifies the call by its `toolCallId` plus
269
- * the `messageId` of the assistant message that hosts it, so callers can
270
- * locate the part precisely without re-walking the chain.
271
- */
272
- export type ChatToolCallRef = {
273
- toolCallId: string;
274
- toolName: string;
275
- messageId: string;
276
- };
277
- /**
278
- * A new tool result surfaced by `chat.history.extractNewToolResults()`.
279
- * `errorText` is set iff the part is in `output-error` state; otherwise
280
- * `output` carries the resolved value.
281
- */
282
- export type ChatNewToolResult = {
283
- toolCallId: string;
284
- toolName: string;
285
- output: unknown;
286
- errorText?: string;
287
- };
288
258
  /** State stored in locals during prepareStep compaction. */
289
259
  interface CompactionState {
290
260
  summary: string;
@@ -463,7 +433,7 @@ export type PendingMessagesOptions<TUIM extends UIMessage = UIMessage> = {
463
433
  * between tool-call steps. The frontend can match on this to render
464
434
  * injection points inline in the assistant response.
465
435
  */
466
- export { PENDING_MESSAGE_INJECTED_TYPE } from "./ai-shared.js";
436
+ export declare const PENDING_MESSAGE_INJECTED_TYPE: "data-pending-message-injected";
467
437
  /**
468
438
  * Event passed to the `prepareMessages` hook.
469
439
  */
@@ -703,21 +673,6 @@ declare function setChatPrompt(resolved: ResolvedPrompt | string): void;
703
673
  * Read the stored prompt. Throws if `chat.prompt.set()` has not been called.
704
674
  */
705
675
  declare function getChatPrompt(): ChatPromptValue;
706
- /**
707
- * Store resolved skills for the current run. Call from any hook
708
- * (`onPreload`, `onChatStart`, `onTurnStart`) or `run()`.
709
- */
710
- declare function setChatSkills(skills: ResolvedSkill[]): void;
711
- /** Read the stored skills. Returns `undefined` if none set. */
712
- declare function getChatSkills(): ResolvedSkill[] | undefined;
713
- /**
714
- * Build the three tools we auto-inject into `streamText` when skills are
715
- * set: `loadSkill`, `readFile`, `bash`. Scoped per-skill by name.
716
- *
717
- * Exported so callers can use the same tools outside the auto-wired path
718
- * (e.g. in a `chat.createSession` loop with custom streamText).
719
- */
720
- export declare function buildSkillTools(skills: ResolvedSkill[]): Record<string, Tool>;
721
676
  /**
722
677
  * Options for {@link toStreamTextOptions}.
723
678
  */
@@ -736,16 +691,6 @@ export type ToStreamTextOptionsOptions = {
736
691
  registry?: {
737
692
  languageModel(modelId: string): unknown;
738
693
  };
739
- /**
740
- * User-defined tools to merge alongside the auto-injected skill tools
741
- * (`loadSkill`, `readFile`, `bash`). User tools win on name conflicts.
742
- *
743
- * If you don't pass `tools` here and skills are set, the returned options
744
- * will include just the skill tools — spread after any `tools` you pass
745
- * directly to `streamText` and they'll be replaced. Easiest: pass all
746
- * your tools here.
747
- */
748
- tools?: Record<string, Tool>;
749
694
  };
750
695
  /**
751
696
  * Returns an options object ready to spread into `streamText()`.
@@ -920,37 +865,6 @@ export type HydrateMessagesEvent<TClientData = unknown, TUIM extends UIMessage =
920
865
  /** The ID of the previous run (if continuation). */
921
866
  previousRunId?: string;
922
867
  };
923
- /**
924
- * Event passed to the `hydrateStore` callback.
925
- *
926
- * Called at turn start — before `run()` fires and before any incoming store
927
- * from the wire payload is applied. Return the authoritative store value
928
- * for this turn; it becomes the initial value `chat.store.get()` sees.
929
- */
930
- export type HydrateStoreEvent<TClientData = unknown, TStore = unknown> = {
931
- /** The unique identifier for the chat session. */
932
- chatId: string;
933
- /** The turn number (0-indexed). */
934
- turn: number;
935
- /** The trigger type for this turn. */
936
- trigger: "submit-message" | "regenerate-message" | "action" | "preload";
937
- /**
938
- * The in-memory store value from the previous turn of this run
939
- * (`undefined` on turn 0 and after continuations).
940
- */
941
- previousStore: TStore | undefined;
942
- /**
943
- * The store value the transport sent with this turn, if any.
944
- * Usually set by client-side `setStore` / `applyStorePatch`.
945
- */
946
- incomingStore: TStore | undefined;
947
- /** Parsed client data from the transport metadata. */
948
- clientData?: TClientData;
949
- /** Whether this run is continuing from a previous run. */
950
- continuation: boolean;
951
- /** The ID of the previous run (if continuation). */
952
- previousRunId?: string;
953
- };
954
868
  /**
955
869
  * Event passed to the `onValidateMessages` callback.
956
870
  */
@@ -1210,18 +1124,13 @@ export type ChatAgentOptions<TIdentifier extends string, TClientDataSchema exten
1210
1124
  /**
1211
1125
  * Called when the frontend sends a custom action via `transport.sendAction()`.
1212
1126
  *
1213
- * Actions are not turns. They fire `hydrateMessages` (if configured) and
1214
- * `onAction` onlyno `onTurnStart` / `prepareMessages` /
1215
- * `onBeforeTurnComplete` / `onTurnComplete`, no `run()`. Use
1216
- * `chat.history.*` inside `onAction` to mutate state.
1217
- *
1218
- * To produce a model response from an action, return a
1219
- * `StreamTextResult` (auto-piped), `string`, or `UIMessage`. Returning
1220
- * `void` or nothing is the side-effect-only default.
1127
+ * Fires after message hydration (if set) but before `onTurnStart` and `run()`.
1128
+ * Use `chat.history.*` to modify the conversation state the LLM will respond
1129
+ * to the modified state.
1221
1130
  */
1222
1131
  onAction?: (event: ActionEvent<[
1223
1132
  TActionSchema
1224
- ] extends [TaskSchema] ? inferSchemaOut<TActionSchema> : unknown, inferSchemaOut<TClientDataSchema>, TUIMessage>) => Promise<unknown> | unknown;
1133
+ ] extends [TaskSchema] ? inferSchemaOut<TActionSchema> : unknown, inferSchemaOut<TClientDataSchema>, TUIMessage>) => Promise<void> | void;
1225
1134
  /**
1226
1135
  * The run function for the chat task.
1227
1136
  *
@@ -1323,43 +1232,6 @@ export type ChatAgentOptions<TIdentifier extends string, TClientDataSchema exten
1323
1232
  * ```
1324
1233
  */
1325
1234
  hydrateMessages?: (event: HydrateMessagesEvent<inferSchemaOut<TClientDataSchema>, TUIMessage>) => TUIMessage[] | Promise<TUIMessage[]>;
1326
- /**
1327
- * Load the `chat.store` value for this turn from your backend.
1328
- *
1329
- * The store lives in memory on the agent instance for the lifetime of
1330
- * the run. After a continuation (idle timeout, `chat.requestUpgrade`,
1331
- * max turns), a new run starts with an empty store — this hook lets
1332
- * you restore it from your own persistence layer.
1333
- *
1334
- * Runs at turn start, before `run()` fires. The returned value replaces
1335
- * the in-memory store and is emitted as a `store-snapshot` chunk so the
1336
- * frontend sees the initial value.
1337
- *
1338
- * If both `hydrateStore` and `incomingStore` (from the wire payload) are
1339
- * present, `incomingStore` wins — it represents the client's latest
1340
- * local state and follows AG-UI's last-write-wins policy.
1341
- *
1342
- * @example
1343
- * ```ts
1344
- * chat.agent({
1345
- * id: "my-chat",
1346
- * hydrateStore: async ({ chatId, previousRunId }) => {
1347
- * return db.chatStore.findUnique({ where: { chatId } })?.value;
1348
- * },
1349
- * onTurnComplete: async ({ chatId }) => {
1350
- * await db.chatStore.upsert({
1351
- * where: { chatId },
1352
- * update: { value: chat.store.get() },
1353
- * create: { chatId, value: chat.store.get() },
1354
- * });
1355
- * },
1356
- * run: async ({ messages, signal }) => {
1357
- * return streamText({ model: openai("gpt-4o"), messages, abortSignal: signal });
1358
- * },
1359
- * });
1360
- * ```
1361
- */
1362
- hydrateStore?: (event: HydrateStoreEvent<inferSchemaOut<TClientDataSchema>>) => unknown | Promise<unknown>;
1363
1235
  /**
1364
1236
  * Called at the start of every turn, after message accumulation and `onChatStart` (turn 0),
1365
1237
  * but before the `run` function executes.
@@ -2309,58 +2181,32 @@ declare function chatLocal<T extends Record<string, unknown>>(options: {
2309
2181
  * // { model?: string; userId: string }
2310
2182
  * ```
2311
2183
  */
2312
- import type { InferChatClientData } from "./ai-shared.js";
2313
- export type { InferChatClientData, InferChatUIMessage } from "./ai-shared.js";
2314
- /**
2315
- * Options for {@link createChatStartSessionAction}.
2316
- */
2317
- export type CreateChatStartSessionActionOptions = {
2318
- /** TTL for the session-scoped public access token. @default "1h" */
2319
- tokenTTL?: string | number | Date;
2320
- /**
2321
- * Default trigger config used when starting a new session for a chat.
2322
- * Per-call `params.triggerConfig` shallow-merges on top.
2323
- */
2324
- triggerConfig?: Partial<SessionTriggerConfig>;
2325
- };
2184
+ export type InferChatClientData<TTask extends AnyTask> = TTask extends Task<string, ChatTaskWirePayload<any, infer TMetadata>, any> ? TMetadata : unknown;
2326
2185
  /**
2327
- * Params for the function returned by {@link createChatStartSessionAction}.
2186
+ * Extracts the UI message type from a chat task (wire payload `messages` items).
2187
+ *
2188
+ * @example
2189
+ * ```ts
2190
+ * import type { InferChatUIMessage } from "@trigger.dev/sdk/ai";
2191
+ * import type { myChat } from "@/trigger/chat";
2192
+ *
2193
+ * type Msg = InferChatUIMessage<typeof myChat>;
2194
+ * ```
2328
2195
  */
2329
- export type ChatStartSessionParams = {
2330
- /** Conversation id (mapped to the Session's `externalId`). */
2331
- chatId: string;
2332
- /**
2333
- * Per-call trigger config. Shallow-merged over the action's default
2334
- * `triggerConfig`. `basePayload` is the customer's wire payload (for
2335
- * `chat.agent`: anything beyond `chatId`/`messages`/`trigger`/`metadata`,
2336
- * which the runtime injects automatically).
2337
- */
2338
- triggerConfig?: Partial<SessionTriggerConfig>;
2339
- /** Pass-through metadata folded into the session row. */
2340
- metadata?: Record<string, unknown>;
2341
- };
2196
+ export type InferChatUIMessage<TTask extends AnyTask> = TTask extends Task<string, ChatTaskWirePayload<infer TUIM extends UIMessage, any>, any> ? TUIM : UIMessage;
2342
2197
  /**
2343
- * Result from {@link createChatStartSessionAction}'s returned function.
2198
+ * Options for {@link createChatTriggerAction}.
2344
2199
  */
2345
- export type ChatStartSessionResult = {
2346
- /**
2347
- * Session-scoped public access token (`read:sessions:{chatId} +
2348
- * write:sessions:{chatId}`). Pass this to the browser; the transport
2349
- * uses it to call `.in/append`, `.out`, `end-and-continue`.
2350
- */
2351
- publicAccessToken: string;
2352
- /** Friendly id of the run triggered alongside session create. */
2353
- runId: string;
2354
- /** Session friendlyId — informational. */
2355
- sessionId: string;
2200
+ export type CreateChatTriggerActionOptions = {
2201
+ /** TTL for the run-scoped public access token. @default "1h" */
2202
+ tokenTTL?: string | number | Date;
2356
2203
  };
2357
2204
  /**
2358
- * Creates a server-side helper that starts (or resumes) a Session for a
2359
- * given chatId — atomically creating the row, triggering the first run,
2360
- * and returning a session-scoped PAT for the browser to use.
2205
+ * Creates a function that triggers a chat task and returns a run-scoped session.
2361
2206
  *
2362
- * Wrap in a Next.js server action (or any server-side handler) so the
2363
- * customer's secret key never crosses to the browser.
2207
+ * Wrap the returned function in a Next.js server action (or any server-side handler)
2208
+ * to keep task triggering on the server. The function calls `tasks.trigger()` with
2209
+ * the secret key and mints a run-scoped PAT for stream subscription + input stream writes.
2364
2210
  *
2365
2211
  * @example
2366
2212
  * ```ts
@@ -2368,23 +2214,18 @@ export type ChatStartSessionResult = {
2368
2214
  * "use server";
2369
2215
  * import { chat } from "@trigger.dev/sdk/ai";
2370
2216
  *
2371
- * export const startChatSession = chat.createStartSessionAction("my-chat", {
2372
- * triggerConfig: { machine: "small-1x" },
2373
- * });
2217
+ * export const triggerChat = chat.createTriggerAction("my-chat");
2374
2218
  * ```
2375
2219
  *
2376
- * Then in the browser:
2220
+ * Then pass it to the transport:
2377
2221
  * ```tsx
2378
2222
  * const transport = useTriggerChatTransport({
2379
2223
  * task: "my-chat",
2380
- * accessToken: async ({ chatId }) => {
2381
- * const { publicAccessToken } = await startChatSession({ chatId });
2382
- * return publicAccessToken;
2383
- * },
2224
+ * triggerTask: triggerChat,
2384
2225
  * });
2385
2226
  * ```
2386
2227
  */
2387
- declare function createChatStartSessionAction(taskId: string, options?: CreateChatStartSessionActionOptions): (params: ChatStartSessionParams) => Promise<ChatStartSessionResult>;
2228
+ declare function createChatTriggerAction(taskId: string, options?: CreateChatTriggerActionOptions): (params: TriggerChatTaskParams) => Promise<TriggerChatTaskResult>;
2388
2229
  export declare const chat: {
2389
2230
  /** Create a chat agent. See {@link chatAgent}. */
2390
2231
  agent: typeof chatAgent;
@@ -2394,8 +2235,8 @@ export declare const chat: {
2394
2235
  withUIMessage: typeof withUIMessage;
2395
2236
  /** Create a chat task with a fixed client data schema. See {@link withClientData}. */
2396
2237
  withClientData: typeof withClientData;
2397
- /** Create a server-side helper for starting (or resuming) a Session for a chatId. See {@link createChatStartSessionAction}. */
2398
- createStartSessionAction: typeof createChatStartSessionAction;
2238
+ /** Create a server-side trigger action helper. See {@link createChatTriggerAction}. */
2239
+ createTriggerAction: typeof createChatTriggerAction;
2399
2240
  /** Pipe a stream to the chat transport. See {@link pipeChat}. */
2400
2241
  pipe: typeof pipeChat;
2401
2242
  /** Create a per-run typed local. See {@link chatLocal}. */
@@ -2423,7 +2264,7 @@ export declare const chat: {
2423
2264
  /** Queue model messages for injection at the next `prepareStep` boundary. See {@link injectBackgroundContext}. */
2424
2265
  inject: typeof injectBackgroundContext;
2425
2266
  /** Typed chat output stream for writing custom chunks or piping from subtasks. */
2426
- stream: RealtimeDefinedStream<UIMessageChunk>;
2267
+ stream: import("@trigger.dev/core/v3").RealtimeDefinedStream<UIMessageChunk>;
2427
2268
  /** Write data parts that persist to the response message. See {@link chatResponse}. */
2428
2269
  response: {
2429
2270
  /**
@@ -2432,36 +2273,8 @@ export declare const chat: {
2432
2273
  */
2433
2274
  write(part: UIMessageChunk): void;
2434
2275
  };
2435
- /**
2436
- * Typed, bidirectional shared data slot for the chat.
2437
- *
2438
- * Use from `chat.agent` hooks and `run()` to share state with the client.
2439
- * Setting emits a `store-snapshot` chunk; patching emits `store-delta`.
2440
- * The value persists across turns within the same run, and can be
2441
- * restored after continuations via the `hydrateStore` config option.
2442
- *
2443
- * ```ts
2444
- * chat.store.set({ plan: ["research", "draft", "review"] });
2445
- * chat.store.patch([{ op: "replace", path: "/status", value: "done" }]);
2446
- * const current = chat.store.get();
2447
- * const off = chat.store.onChange((value, ops) => { ... });
2448
- * ```
2449
- */
2450
- store: {
2451
- /** Replace the store value. Emits a `store-snapshot` chunk. */
2452
- set: typeof chatStoreSet;
2453
- /**
2454
- * Apply RFC 6902 JSON Patch operations to the current value.
2455
- * Emits a `store-delta` chunk.
2456
- */
2457
- patch: typeof chatStorePatch;
2458
- /** Read the current store value. Returns `undefined` if never set. */
2459
- get: typeof chatStoreGet;
2460
- /** Subscribe to store changes. Returns an unsubscribe function. */
2461
- onChange: typeof chatStoreOnChange;
2462
- };
2463
2276
  /** Pre-built input stream for receiving messages from the transport. */
2464
- messages: RealtimeDefinedInputStream<ChatTaskWirePayload>;
2277
+ messages: import("@trigger.dev/core/v3").RealtimeDefinedInputStream<ChatTaskWirePayload<UIMessage<unknown, import("ai").UIDataTypes, import("ai").UITools>, unknown>>;
2465
2278
  /** Create a managed stop signal wired to the stop input stream. See {@link createStopSignal}. */
2466
2279
  createStopSignal: typeof createStopSignal;
2467
2280
  /** Signal the frontend that the current turn is complete. See {@link chatWriteTurnComplete}. */
@@ -2481,20 +2294,6 @@ export declare const chat: {
2481
2294
  prompt: typeof getChatPrompt & {
2482
2295
  set: typeof setChatPrompt;
2483
2296
  };
2484
- /**
2485
- * Store and retrieve resolved agent skills for the current run.
2486
- *
2487
- * - `chat.skills.set([...])` — store an array of `ResolvedSkill`s
2488
- * - `chat.skills()` — read the stored skills (returns undefined if none)
2489
- *
2490
- * Skills set here are automatically injected into `streamText` by
2491
- * `chat.toStreamTextOptions()`: skill descriptions land in the system
2492
- * prompt and `loadSkill` / `readFile` / `bash` tools are added to the
2493
- * tool set.
2494
- */
2495
- skills: typeof getChatSkills & {
2496
- set: typeof setChatSkills;
2497
- };
2498
2297
  /**
2499
2298
  * Returns an options object ready to spread into `streamText()`.
2500
2299
  * Reads the stored prompt and returns `{ system, experimental_telemetry, ...config }`.
@@ -2515,40 +2314,6 @@ export declare const chat: {
2515
2314
  history: {
2516
2315
  /** Read the current accumulated UI messages (copy). */
2517
2316
  all(): UIMessage[];
2518
- /**
2519
- * Read the current chain as an ordered `UIMessage[]`. Alias for `all()` —
2520
- * use this when working alongside parent-aware APIs (TRI-9120) where
2521
- * "chain" disambiguates from "graph".
2522
- */
2523
- getChain(): UIMessage[];
2524
- /**
2525
- * Find a message by id. Returns `undefined` if no message with that id
2526
- * is present in the current chain.
2527
- */
2528
- findMessage(messageId: string): UIMessage | undefined;
2529
- /**
2530
- * Tool calls on the leaf assistant message still waiting on an answer
2531
- * (`input-available` state). Use this to gate fresh user turns during
2532
- * HITL flows: if `getPendingToolCalls().length > 0`, an `addToolOutput`
2533
- * is expected before any new user message.
2534
- *
2535
- * Returns `[]` if there is no assistant message yet, or if the leaf
2536
- * assistant has no pending tool calls.
2537
- */
2538
- getPendingToolCalls(): ChatToolCallRef[];
2539
- /**
2540
- * Tool calls across the chain with a final result (`output-available`
2541
- * or `output-error`). Use this to dedup re-saves when the AI SDK
2542
- * resends an assistant message with progressively more answered parts.
2543
- */
2544
- getResolvedToolCalls(): ChatToolCallRef[];
2545
- /**
2546
- * Pure helper: returns the tool parts in `message` whose results are
2547
- * not already represented in the current chain. Use this when
2548
- * persisting tool results to your own store: each call surfaces only
2549
- * the *new* answers, so writes stay idempotent across re-streams.
2550
- */
2551
- extractNewToolResults(message: UIMessage): ChatNewToolResult[];
2552
2317
  /** Replace all accumulated messages. Same as `chat.setMessages()`. */
2553
2318
  set(messages: UIMessage[]): void;
2554
2319
  /** Remove a specific message by ID. */
@@ -2568,10 +2333,4 @@ export declare const chat: {
2568
2333
  compact: typeof chatCompact;
2569
2334
  /** Read the current compaction state (summary + base message count). */
2570
2335
  getCompactionState: typeof getCompactionState;
2571
- /**
2572
- * The friendlyId (`session_*`) of the backing Session for the current chat.agent run.
2573
- * Useful for persisting alongside `runId` so reloads can resume the same session.
2574
- * Throws if called outside a chat.agent `run()` or hook.
2575
- */
2576
- readonly sessionId: string;
2577
2336
  };