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

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.
@@ -263,6 +263,28 @@ export type ChatTurnUsage = LanguageModelUsage;
263
263
  * and converts to `ModelMessage[]` internally.
264
264
  */
265
265
  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
+ };
266
288
  /** State stored in locals during prepareStep compaction. */
267
289
  interface CompactionState {
268
290
  summary: string;
@@ -1188,13 +1210,18 @@ export type ChatAgentOptions<TIdentifier extends string, TClientDataSchema exten
1188
1210
  /**
1189
1211
  * Called when the frontend sends a custom action via `transport.sendAction()`.
1190
1212
  *
1191
- * Fires after message hydration (if set) but before `onTurnStart` and `run()`.
1192
- * Use `chat.history.*` to modify the conversation state the LLM will respond
1193
- * to the modified state.
1213
+ * Actions are not turns. They fire `hydrateMessages` (if configured) and
1214
+ * `onAction` only no `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.
1194
1221
  */
1195
1222
  onAction?: (event: ActionEvent<[
1196
1223
  TActionSchema
1197
- ] extends [TaskSchema] ? inferSchemaOut<TActionSchema> : unknown, inferSchemaOut<TClientDataSchema>, TUIMessage>) => Promise<void> | void;
1224
+ ] extends [TaskSchema] ? inferSchemaOut<TActionSchema> : unknown, inferSchemaOut<TClientDataSchema>, TUIMessage>) => Promise<unknown> | unknown;
1198
1225
  /**
1199
1226
  * The run function for the chat task.
1200
1227
  *
@@ -2488,6 +2515,40 @@ export declare const chat: {
2488
2515
  history: {
2489
2516
  /** Read the current accumulated UI messages (copy). */
2490
2517
  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[];
2491
2552
  /** Replace all accumulated messages. Same as `chat.setMessages()`. */
2492
2553
  set(messages: UIMessage[]): void;
2493
2554
  /** Remove a specific message by ID. */