Commit Graph

7226 Commits

Author SHA1 Message Date
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
Eric Allam fefc7df9b8 Use a single run with iterative waitpoint token completions 2026-05-05 11:06:25 +01:00
Cursor Agent a7f4d277de fix(reference): use compatible @ai-sdk v3 packages, await convertToModelMessages
@ai-sdk/openai v3 and @ai-sdk/react v3 are needed for ai v6 compatibility.
convertToModelMessages is async in newer AI SDK versions.

Co-authored-by: Eric Allam <eric@trigger.dev>
2026-05-05 11:06:25 +01:00
Cursor Agent 3805d9186c feat(reference): add ai-chat Next.js reference project
Minimal example showcasing the new chatTask + TriggerChatTransport APIs:
- Backend: chatTask with streamText auto-pipe (src/trigger/chat.ts)
- Frontend: TriggerChatTransport with useChat (src/components/chat.tsx)
- Token generation via auth.createTriggerPublicToken (src/app/page.tsx)
- Tailwind v4 styling

Co-authored-by: Eric Allam <eric@trigger.dev>
2026-05-05 11:06:25 +01:00
Cursor Agent 499fc945dd docs(ai): add AI Chat with useChat guide
Comprehensive guide covering:
- Quick start with chatTask + TriggerChatTransport
- Backend patterns: simple (return streamText), complex (pipeChat),
  and manual (task + ChatTaskPayload)
- Frontend options: dynamic tokens, extra data, self-hosting
- ChatTaskPayload reference
- Added to Writing tasks navigation near Streams

Co-authored-by: Eric Allam <eric@trigger.dev>
2026-05-05 11:06:25 +01:00
Cursor Agent 037d1dad27 fix: address CodeRabbit review feedback
1. Add null/object guard before enqueuing UIMessageChunk from SSE stream
   to handle heartbeat or malformed events safely
2. Use incrementing counter instead of Date.now() in test message
   factories to avoid duplicate IDs
3. Add test covering publicAccessToken from trigger response being used
   for stream subscription auth

Co-authored-by: Eric Allam <eric@trigger.dev>
2026-05-05 11:06:25 +01:00
Cursor Agent f682235844 chore: update changeset to target @trigger.dev/sdk
Co-authored-by: Eric Allam <eric@trigger.dev>
2026-05-05 11:06:25 +01:00
Cursor Agent f0dd5e0907 refactor: delete packages/ai/ — moved to @trigger.dev/sdk subpaths
All functionality now lives in:
- @trigger.dev/sdk/chat (frontend transport)
- @trigger.dev/sdk/ai (backend chatTask, pipeChat)

Co-authored-by: Eric Allam <eric@trigger.dev>
2026-05-05 11:06:25 +01:00