Commit Graph

7233 Commits

Author SHA1 Message Date
Eric Allam 84d430edcd Add support for triggering from the backend 2026-05-05 11:06:25 +01:00
Eric Allam 9e7b2d1ac5 feat(sdk): add onChatSuspend/onChatResume hooks, exitAfterPreloadIdle, chat.withClientData, and ChatBuilder 2026-05-05 11:06:25 +01:00
Eric Allam 828c34a819 feat(sdk): ctx on chat.task hooks; ai-chat E2B sandbox; docs patterns
- Pass TaskRunContext through chat lifecycle events, CompactedEvent, and
  ChatTaskRunPayload; use ctx.run.id for chat access tokens
- Export TaskRunContext from @trigger.dev/sdk
- ai-chat reference: executeCode via E2B, code-sandbox module, warm on
  onTurnStart, dispose on token onWait and onComplete; chat.local run id
- Docs: database persistence + code sandbox pattern pages; reference and
  backend updates for ctx; chat.defer anchor; navigation
2026-05-05 11:06:25 +01:00
Eric Allam b3106f8b2c Add run-scoped PAT renewal for chat transport 2026-05-05 11:06:25 +01:00
Eric Allam dbe5ae4b56 feat(sdk): ToolSet typing for toolFromTask, ai.toolExecute, deprecate ai.tool
- Assert toolFromTask return as AI SDK ToolSet-compatible; import ToolSet from ai
- Add changesets for @trigger.dev/sdk
- ai-chat reference: chat-tools module, registry language model helper, streamText cleanup
- Prisma migration removing user tool demo; demo docs and next config tweaks
2026-05-05 11:06:25 +01:00
Eric Allam fe90614142 feat(chat): add chat.inject() for background context injection and chat.defer improvements
- chat.inject(): queue model messages from background work for injection
  at the next prepareStep boundary or before the next turn's run()
- Deferred work from onTurnComplete no longer blocks waiting for next message
- Background queue persists across turns (not reset) so deferred work from
  onTurnComplete can inject into the next turn
- Reference app: self-review pattern using generateObject + chat.inject()
- Hide transient data-turn-status and data-background-context-injected parts in UI
2026-05-05 11:06:25 +01:00
Eric Allam 973bd2c711 feat(ai): add triggerAndSubscribe method and use it in ai.tool
Replace triggerAndWait with triggerAndSubscribe in ai.tool to fix:
- Parallel tool calls (no more preventMultipleWaits errors)
- Stop signal while suspended (parent stays alive, child gets cancelled)

New task.triggerAndSubscribe() method: trigger + subscribeToRun in a
single span, with abort signal support and cancelOnAbort option.

Convert deepResearch to a schemaTask + ai.tool in the reference app.

refs TRI-7986
2026-05-05 11:06:25 +01:00
Eric Allam a503e99a57 Add a writer to easily write chunks in callbacks 2026-05-05 11:06:25 +01:00
Eric Allam 843b85e356 feat(chat): add compaction option, pendingMessages steering, and usePendingMessages hook 2026-05-05 11:06:25 +01:00
Eric Allam e94ce5e8a8 better compaction support in our other chat variants 2026-05-05 11:06:25 +01:00
Eric Allam e06fbdb71d feat: support message compaction 2026-05-05 11:06:25 +01:00
Eric Allam 74c70394f9 refactor: rename warmTimeout to idleTimeout across chat APIs 2026-05-05 11:06:25 +01:00
Eric Allam fd1fbe6fd3 feat(chat): add chat.prompt API with provider registry support 2026-05-05 11:06:25 +01:00
Eric Allam 99f58bbb1a Add metadata to the streamText call 2026-05-05 11:06:25 +01:00
Eric Allam b7afc1752f Add support for toUIMessageStream() options 2026-05-05 11:06:25 +01:00
Eric Allam 6c1b4f8cca Introduce the chat session API and better docs organization 2026-05-05 11:06:25 +01:00
Eric Allam 981a5a09a4 feat(chat): add composable primitives, raw task example, and task mode switcher 2026-05-05 11:06:25 +01:00
Eric Allam 9d1bb5e4b8 feat(streams): add inputStream.waitWithWarmup(), warm timeout config in sidebar, preload payload option 2026-05-05 11:06:25 +01:00
Eric Allam 4a17be4eb4 fix(reference): replace hand-rolled HTML stripping with turndown 2026-05-05 11:06:25 +01:00
Eric Allam 9f705abb5c feat(chat): add chat.defer(), preload toggle, TTFB measurement, and fix ChatTaskWirePayload export 2026-05-05 11:06:25 +01:00
Eric Allam 7ef73da7bd feat(chat): auto-hydrate chat.local values in ai.tool subtasks 2026-05-05 11:06:25 +01:00
Eric Allam b54b500e16 docs: add sequence diagrams to ai-chat guide 2026-05-05 11:06:25 +01:00
Eric Allam 6cf3a01f38 docs: add mermaid architecture diagrams for ai-chat system 2026-05-05 11:06:25 +01:00
Eric Allam 77a1351276 feat(chat): add preload support, dynamic tools, and preload-specific timeouts
- Add onPreload hook and preloaded field to all lifecycle events
- Add transport.preload(chatId) for eagerly starting runs before first message
- Add preloadWarmTimeoutInSeconds and preloadTimeout task options
- Add preload:true run tag and chat.preloaded span attributes
- Add UserTool model for per-user dynamic tools loaded from DB
- Load dynamic tools in onPreload/onChatStart via chat.local
- Build dynamicTool() instances in run and spread into streamText tools
- Reference project: preload on new chat, dynamic company-info and user-preferences tools
2026-05-05 11:06:25 +01:00
Eric Allam c98f6f3c8d feat(ai): pass chat context and toolCallId to subtasks, add typed ai.chatContext helpers
- Store chat turn context (chatId, turn, continuation, clientData) in locals for auto-detection
- toolFromTask now auto-detects chat context and passes it to subtask metadata
- Skip serializing messages array (can be large, rarely needed by subtasks)
- Tag subtask runs with toolCallId for dashboard visibility
- Add ai.toolCallId() convenience helper
- Add ai.chatContext<typeof myChat>() with typed clientData inference
- Add ai.chatContextOrThrow<typeof myChat>() that throws if not in a chat context
- Update deepResearch example to use ai.chatContextOrThrow
- Document all helpers in ai-chat guide
2026-05-05 11:06:25 +01:00
Eric Allam fdd3f9b61f feat(chat): expose typed chat.stream, add deepResearch subtask example, per-chat model persistence, debug panel
- Export chat.stream (typed RealtimeDefinedStream<UIMessageChunk>) for writing custom data to the chat stream
- Add deepResearch subtask using data-* chunks to stream progress back to parent chat via target: root
- Use AI SDK data-research-progress chunk protocol with id-based updates for live progress
- Add ResearchProgress component and generic data-* fallback renderer in frontend
- Persist model per chat in DB (schema + onChatStart), model selector only on new chats
- Add collapsible debug panel showing run ID (with dashboard link), chat ID, model, status, session info
- Document chat.stream API, data-* chunks, and subtask streaming pattern in docs
2026-05-05 11:06:25 +01:00
Eric Allam 90a9556e89 Some improvements to the example ai-chat 2026-05-05 11:06:25 +01:00
Eric Allam 235a4d43fb feat(chat): add stop handling, abort cleanup, continuation support, and reference project enhancements
- Fix onFinish race condition: await onFinishPromise so capturedResponseMessage is set before accumulation
- Add chat.isStopped() helper accessible from anywhere during a turn
- Add chat.cleanupAbortedParts() to remove incomplete tool/reasoning/text parts on stop
- Auto-cleanup aborted parts before passing to onTurnComplete
- Clean incoming messages from frontend to prevent tool_use without tool_result API errors
- Add stopped and rawResponseMessage fields to TurnCompleteEvent
- Add continuation and previousRunId fields to all lifecycle hooks and run payload
- Add span attributes (chat.id, chat.turn, chat.stopped, chat.continuation, chat.previous_run_id, etc.)
- Add webFetch tool and reasoning model support to ai-chat reference project
- Render reasoning parts in frontend chat component
- Document all new fields in ai-chat guide
2026-05-05 11:06:25 +01:00
Eric Allam 704ab74b98 feat: add chat.local for per-run typed data with Proxy access and dirty tracking 2026-05-05 11:06:25 +01:00
Eric Allam 78923cf773 Make clientData typesafe and pass to all chat.task hooks 2026-05-05 11:06:25 +01:00
Eric Allam c85d541bc9 Add triggerOptions to the transport, auto-tag with the chat ID 2026-05-05 11:06:25 +01:00
Eric Allam c409e7da59 use locals for the chat pipe counter instead of a module global 2026-05-05 11:06:25 +01:00
Eric Allam ee3e9b2e5a fixed chat tests 2026-05-05 11:06:25 +01:00
Eric Allam 94b4e9aa57 update pnpm link file 2026-05-05 11:06:25 +01:00
Eric Allam d0826786e6 Minor fixes around reconnecting streams 2026-05-05 11:06:25 +01:00
Eric Allam 5c75341274 feat: add onTurnStart hook, lastEventId support, and stream resume deduplication 2026-05-05 11:06:25 +01:00
Eric Allam 4b1e4619ae remove postinstall hook 2026-05-05 11:06:25 +01:00
Eric Allam c7276e1797 Add ai chat to the sidebar for now 2026-05-05 11:06:25 +01:00
Eric Allam 4e6a5c83fd build full example with persisting messages, adding necessary hooks, and documenting it all 2026-05-05 11:06:25 +01:00
Eric Allam c5ec4a034b Accumulate messages in the task, allowing us to only have to send user mesages from the transport 2026-05-05 11:06:25 +01:00
Eric Allam 9bae6c0b35 Add some pending message support in the example 2026-05-05 11:06:25 +01:00
Eric Allam 6258122601 Fix double looping when resuming from an input stream waitpoint 2026-05-05 11:06:25 +01:00
Eric Allam 869b41daad Added better telemetry support to view turns 2026-05-05 11:06:25 +01:00
Eric Allam d5af5a3ae0 provide already converted UIMessages to the run function for better dx 2026-05-05 11:06:25 +01:00
Eric Allam 3b5e8f5346 Add clientData support 2026-05-05 11:06:25 +01:00
Eric Allam 522e85cbfc Add warmTimeoutInSeconds option 2026-05-05 11:06:25 +01:00
Eric Allam 3f66c56a11 add stopping support and fix issue with the OpenAI responses API and stopped streams 2026-05-05 11:06:25 +01:00
Eric Allam ba81c377cf use input streams and rename chatTask and chatState to chat.task and chat.state 2026-05-05 11:06:25 +01:00
Eric Allam e963271289 expose a useTriggerChatTransport hook 2026-05-05 11:06:25 +01:00
Eric Allam f92bf6c567 Added tool example 2026-05-05 11:06:25 +01:00