Commit Graph

7274 Commits

Author SHA1 Message Date
Eric Allam b27da8b976 fix(chat): include "action" in ChatTaskPayload.trigger type
run() is invoked with trigger: "action" after onAction processes a
typed action, but the type previously omitted it. Adding it lets
users cleanly short-circuit the LLM call for actions that don't
need a response (e.g. user-initiated compaction):
  if (trigger === "action") return;
2026-05-10 22:11:20 +01:00
Eric Allam 0a401d8bb7 feat(chat): add chat.endRun()
Exit the loop after the current turn completes without the
upgrade-required signal that chat.requestUpgrade() sends. Use when an
agent finishes its work on its own terms — one-shot responses, goal
achieved, budget exhausted — instead of waiting idle for the next
user message. Callable from run(), chat.defer(),
onBeforeTurnComplete, or onTurnComplete.

Resolves TRI-8391.
2026-05-10 22:11:20 +01:00
Eric Allam fded2cd87e feat(chat): expose finishReason on turn-complete events
Surface the AI SDK's FinishReason on TurnCompleteEvent and
BeforeTurnCompleteEvent. Gives hooks a clean signal for distinguishing
a normal turn end from one paused on a pending tool call (HITL flows
like ask_user). Undefined for manual pipeChat() or aborted streams.
2026-05-10 22:11:20 +01:00
Eric Allam 220eeeeafd feat(sdk): add mockChatAgent test harness with locals DI
Drives a chat.agent definition through real turns offline — send
messages, actions, and stop signals; inspect captured chunks; assert
on hook order. Pre-seed dependencies via setupLocals so hooks read
test instances (DB clients, stubs) via locals.get() instead of
leaking through untrusted clientData.

Adds ai-chat reference tests exercising the harness across basic
flow, onValidateMessages, hydrateMessages, and actions.
2026-05-10 22:11:20 +01:00
Eric Allam 0973ae64cd feat(core): add runInMockTaskContext test infrastructure
In-memory managers for locals, lifecycle hooks, runtime, input streams,
and realtime streams, plus a mock TaskContext. Lets task code be driven
end-to-end without hitting the Trigger.dev runtime — send data into
input streams, inspect chunks written to output streams, and pre-seed
locals for dependency injection.
2026-05-10 22:11:03 +01:00
Eric Allam cf7aec8944 fix(ai-chat): defer multi-tab broadcasts, disable streamdown word animation 2026-05-10 22:11:03 +01:00
Eric Allam 788661adba feat(chat): multi-tab coordination via BroadcastChannel 2026-05-10 22:11:03 +01:00
Eric Allam 3de23d1552 chore(ai-chat): remove test-big-error trigger from onValidateMessages 2026-05-10 22:11:03 +01:00
Eric Allam a7078eb0cb feat(ai-chat): add askUser tool for HITL testing, verify TRI-8556 fix 2026-05-10 22:11:03 +01:00
Eric Allam ecc8ee7cc9 fix pnpm lock file 2026-05-10 22:11:03 +01:00
Eric Allam 5bb7ae6823 fix(chat): prevent useChat resume from hanging on completed turns
Add isStreaming flag to session state — set true when streaming starts,
  false on turn-complete. reconnectToStream returns null immediately when
  isStreaming is false, so resume: true is safe to pass unconditionally.
2026-05-10 22:11:03 +01:00
Eric Allam 49df95b924 feat(chat): add hydrateMessages, chat.history, and custom actions
Backend-controlled message history via hydrateMessages hook — loads from
  DB on every turn, replacing the linear accumulator. Imperative chat.history
  API (rollbackTo, remove, replace, slice) for modifying history from any
  hook or run(). Custom actions via actionSchema + onAction — typed actions
  sent through transport.sendAction() that wake the agent, modify state,
  then trigger run(). Adds sendAction to both TriggerChatTransport and
  AgentChat.
2026-05-10 22:11:03 +01:00
Eric Allam 8c43c74ead feat(chat): add chat.response API for persistent data parts, transient flag support 2026-05-10 22:11:03 +01:00
Eric Allam 27cb3cc3ca prevent preloads from firing twice when in React strictMode 2026-05-10 22:11:03 +01:00
Eric Allam 1cf81d186d fix: restore applyPrepareMessages call after agentcrumbs strip 2026-05-10 22:11:03 +01:00
Eric Allam d54e6a291f feat(chat): tool approvals support — ID-matched message replacement, sendEmail example, approval UI 2026-05-10 22:11:03 +01:00
Eric Allam d6ac62fc5d feat(chat): allow generateMessageId in uiMessageStreamOptions, auto-pass originalMessages 2026-05-10 22:11:03 +01:00
Eric Allam 258ddb2305 fix(sdk): inject prepareStep in toStreamTextOptions even without chat.prompt.set() 2026-05-10 22:11:03 +01:00
Eric Allam b99bd75a8f feat(chat): add stopGeneration, fix onTurnComplete/onFinishPromise, add /chats/[chatId] route to ai-chat 2026-05-10 22:11:03 +01:00
Eric Allam e9586959b6 Add run agent view 2026-05-10 22:11:03 +01:00
Eric Allam 77a755c753 Support for upgrading an agent to a new version 2026-05-10 22:11:03 +01:00
Eric Allam 7f649efbba Add support for optionally validating UI messages 2026-05-10 22:11:03 +01:00
Eric Allam 15c2ee8cd6 add agent mcp tools 2026-05-10 22:11:03 +01:00
Eric Allam 9831a2f951 Add server-to-server chat support and subagent support to the playground, plus docs 2026-05-10 22:11:03 +01:00
Eric Allam 55029507ee Add the chat client and strip agent crumbs 2026-05-10 22:11:03 +01:00
Eric Allam f4817fd9d2 Some design tweaks, improvements to playground options, rename unnamed preloaded conversations on first message 2026-05-10 22:11:03 +01:00
Eric Allam ae2123b49a playground ui tweaks 2026-05-10 22:11:03 +01:00
Eric Allam 91b21ea6af feat: upgrade streamdown to v2.5.0 with custom Trigger.dev Shiki theme
- Upgrade streamdown from v1.4.0 to v2.5.0 with @streamdown/code plugin
- Custom Shiki theme matching the Trigger.dev VS Code dark theme colors
- Consolidate duplicated lazy StreamdownRenderer into shared component
- Patch streamdown to inline highlighted body (fixes Arc browser)
- Add streamdown storybook page for visual testing
- Handle AGENT triggerSource in TestTaskPresenter exhaustive switch
- Update Tailwind config to scan streamdown dist for utility classes
2026-05-10 22:11:03 +01:00
Eric Allam 89de993b54 chat.task -> chat.agent
plus playground support, including playground conversations, and a new
agent list
2026-05-10 22:10:22 +01:00
Eric Allam 254bf42fe9 Add support for triggering from the backend 2026-05-10 22:10:16 +01:00
Eric Allam 817367aa73 feat(sdk): add onChatSuspend/onChatResume hooks, exitAfterPreloadIdle, chat.withClientData, and ChatBuilder 2026-05-10 22:10:11 +01:00
Eric Allam dde3934670 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-10 22:10:11 +01:00
Eric Allam 5a8ba63726 Add run-scoped PAT renewal for chat transport 2026-05-10 22:09:48 +01:00
Eric Allam be820d084a 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-10 22:09:48 +01:00
Eric Allam 71abce7f93 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-10 22:09:48 +01:00
Eric Allam 9d334e8ace 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-10 22:09:48 +01:00
Eric Allam 49e858ef56 Add a writer to easily write chunks in callbacks 2026-05-10 22:09:48 +01:00
Eric Allam f05d638717 feat(chat): add compaction option, pendingMessages steering, and usePendingMessages hook 2026-05-10 22:09:48 +01:00
Eric Allam f7442f1312 better compaction support in our other chat variants 2026-05-10 22:09:48 +01:00
Eric Allam c21e920a3b feat: support message compaction 2026-05-10 22:09:48 +01:00
Eric Allam aeb0fbb6a2 refactor: rename warmTimeout to idleTimeout across chat APIs 2026-05-10 22:09:48 +01:00
Eric Allam 856d2527d0 feat(chat): add chat.prompt API with provider registry support 2026-05-10 22:09:48 +01:00
Eric Allam 18ca682169 Add metadata to the streamText call 2026-05-10 22:08:38 +01:00
Eric Allam 78900720af Add support for toUIMessageStream() options 2026-05-10 22:08:38 +01:00
Eric Allam 1f6ea4b2d9 Introduce the chat session API and better docs organization 2026-05-10 22:08:38 +01:00
Eric Allam 25f7dedd14 feat(chat): add composable primitives, raw task example, and task mode switcher 2026-05-10 22:08:38 +01:00
Eric Allam 2908b3598d feat(streams): add inputStream.waitWithWarmup(), warm timeout config in sidebar, preload payload option 2026-05-10 22:08:38 +01:00
Eric Allam 7aa5964141 fix(reference): replace hand-rolled HTML stripping with turndown 2026-05-10 22:08:38 +01:00
Eric Allam dc84597ff5 feat(chat): add chat.defer(), preload toggle, TTFB measurement, and fix ChatTaskWirePayload export 2026-05-10 22:08:35 +01:00
Eric Allam 3d0b02752e feat(chat): auto-hydrate chat.local values in ai.tool subtasks 2026-05-10 22:08:35 +01:00