Skip to content

feat: ai-chat reference project + MCP agent-chat tooling (5/5)#3546

Open
ericallam wants to merge 4 commits into
feature/agent-view-dashboardfrom
feature/ai-chat-reference-and-cli
Open

feat: ai-chat reference project + MCP agent-chat tooling (5/5)#3546
ericallam wants to merge 4 commits into
feature/agent-view-dashboardfrom
feature/ai-chat-reference-and-cli

Conversation

@ericallam
Copy link
Copy Markdown
Member

@ericallam ericallam commented May 10, 2026

Layer 5 of 5 in the chat.agent stack split

Top of the chat.agent stack: a full Next.js reference project that
exercises chat.agent end-to-end, plus the CLI MCP tools that drive
agent runs from Claude Code / Cursor / etc.

Targets feature/agent-view-dashboard — merge last

references/ai-chat

  • Full Next.js app with prisma persistence, multi-chat sidebar,
    per-chat model picker, debug panel, tool examples, smoke tests
  • Reference tools: getCurrentTime, searchHackerNews,
    createGithubIssue, PR review helpers, code sandbox
  • chat-client-test orchestrator for concurrent-send stress
  • references/hello-world chatAgent + triggerAndSubscribe examples

CLI MCP tooling for chat.agent

  • mcp/tools/agentChat.ts (start_agent_chat, send_agent_message,
    close_agent_chat)
  • mcp/tools/agents.ts + tasks.ts (list agents, agent run details)
  • dev-run-controller OOM kill + taskRunProcessPool tweaks
  • dev/managed entry-point hooks for skills bundling
  • buildWorker + bundleSkills (agent skills support)

Includes ai-tool-helpers + mcp-agent-chat-sessions changesets, plus
the streamdown@2 patch and pnpm-lock reconciliation.

Stack

  • L1 → main: #3542 Sessions dashboard, task_kind, and chat-ready hardening
  • L2 → L1: #3543 chat.agent runtime
  • L3 → L2: #3544 browser chat client + transport
  • L4 → L3: #3545 agent-view dashboard
  • L5 → L4 (this PR)

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 10, 2026

🦋 Changeset detected

Latest commit: 3c71eeb

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 30 packages
Name Type
@trigger.dev/sdk Patch
trigger.dev Patch
@trigger.dev/python Patch
@internal/sdk-compat-tests Patch
references-ai-chat Patch
d3-chat Patch
references-d3-openai-agents Patch
references-nextjs-realtime Patch
references-realtime-hooks-test Patch
references-realtime-streams Patch
references-telemetry Patch
@trigger.dev/build Patch
@trigger.dev/core Patch
@trigger.dev/react-hooks Patch
@trigger.dev/redis-worker Patch
@trigger.dev/rsc Patch
@trigger.dev/schema-to-json Patch
@trigger.dev/database Patch
@trigger.dev/otlp-importer Patch
@internal/cache Patch
@internal/clickhouse Patch
@internal/llm-model-catalog Patch
@internal/redis Patch
@internal/replication Patch
@internal/run-engine Patch
@internal/schedule-engine Patch
@internal/testcontainers Patch
@internal/tracing Patch
@internal/tsql Patch
@internal/zod-worker Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 10, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 5feadc52-519d-466d-99be-f400ba9ea0cc

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/ai-chat-reference-and-cli

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 2 potential issues.

View 4 additional findings in Devin Review.

Open in Devin Review

},
});
session.runId = result.id;
session.lastEventId = undefined;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Resetting lastEventId to undefined on upgrade causes SSE replay of entire session history

In collectAgentResponse, when a trigger:upgrade-required chunk is received, session.lastEventId is set to undefined (line 390) before recursively calling collectAgentResponse. The recursive call creates a new SSEStreamSubscription using session.lastEventId (now undefined) as the lastEventId option (agentChat.ts:338), which means the new subscription replays the entire session .out stream from the very beginning.

Since session .out is a durable stream containing all historical chunks across runs, the replayed events will include old turns' trigger:turn-complete chunks. The first historical trigger:turn-complete hit (line 366-368) immediately breaks the collection loop, causing the function to return with empty/partial text from a previous turn instead of the new run's response.

Expected fix

Keep session.lastEventId as-is (pointing to the trigger:upgrade-required chunk's SSE id) so the recursive subscription resumes right after the upgrade marker, where the new run's output will appear.

Suggested change
session.lastEventId = undefined;
reader.releaseLock();
Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

packageVersion: buildManifest.packageVersion,
cliPackageVersion: buildManifest.cliPackageVersion,
tasks: workerManifest.tasks,
prompts: workerManifest.prompts,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚩 managed-index-controller adds prompts but not skills to worker registration payload

Both dev-index-worker.ts:187 and managed-index-worker.ts:183 now emit skills: resourceCatalog.listSkillManifests() in their worker manifests. The managed-index-controller.ts forwards tasks, prompts (newly added at line 107), and queues to the server — but does NOT forward skills. If skills need to be registered server-side (for dashboard display, deploy metadata, etc.), this omission would silently drop them in the managed (production) indexing path. Could be intentional if skills are only used at runtime and don't need server-side registration, but it's asymmetric with the prompts addition in the same PR.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

@ericallam ericallam force-pushed the feature/agent-view-dashboard branch from ecfac76 to 7ee523e Compare May 11, 2026 19:01
@ericallam ericallam force-pushed the feature/ai-chat-reference-and-cli branch from 882544c to 5baac29 Compare May 11, 2026 19:01
@ericallam ericallam force-pushed the feature/agent-view-dashboard branch from 7ee523e to fdc61c6 Compare May 12, 2026 08:23
@ericallam ericallam force-pushed the feature/ai-chat-reference-and-cli branch from 5baac29 to e16efbb Compare May 12, 2026 08:23
@ericallam ericallam force-pushed the feature/agent-view-dashboard branch from fdc61c6 to 96700b1 Compare May 12, 2026 08:35
@ericallam ericallam force-pushed the feature/ai-chat-reference-and-cli branch from e16efbb to f4a7923 Compare May 12, 2026 08:35
@ericallam ericallam force-pushed the feature/agent-view-dashboard branch from 96700b1 to 482d752 Compare May 12, 2026 08:40
@ericallam ericallam force-pushed the feature/ai-chat-reference-and-cli branch from f4a7923 to 04b98af Compare May 12, 2026 08:40
@ericallam ericallam force-pushed the feature/agent-view-dashboard branch from 482d752 to 920e876 Compare May 12, 2026 08:46
@ericallam ericallam force-pushed the feature/ai-chat-reference-and-cli branch from 04b98af to 417344a Compare May 12, 2026 08:46
@ericallam ericallam force-pushed the feature/agent-view-dashboard branch from 920e876 to d96e2f7 Compare May 12, 2026 08:52
@ericallam ericallam force-pushed the feature/ai-chat-reference-and-cli branch from 417344a to 43fde3f Compare May 12, 2026 08:52
@ericallam ericallam force-pushed the feature/agent-view-dashboard branch from d96e2f7 to 3256f42 Compare May 12, 2026 09:44
@ericallam ericallam force-pushed the feature/ai-chat-reference-and-cli branch from 43fde3f to c27cef9 Compare May 12, 2026 09:44
@ericallam ericallam force-pushed the feature/agent-view-dashboard branch from 3256f42 to 220b33c Compare May 12, 2026 09:46
@ericallam ericallam force-pushed the feature/ai-chat-reference-and-cli branch from c27cef9 to 48f030a Compare May 12, 2026 09:47
ericallam added 4 commits May 12, 2026 10:48
Adds chat.agent({...}), a session-aware task definition for AI chat
agents. The runtime sits on top of the Sessions primitive and handles:

- Delta-only wire: each /in/append carries at most one message; agent
  rebuilds prior history at run boot from an S3 snapshot + session.out
  replay tail. Awaited snapshot writes after every onTurnComplete keep
  the chain durable across idle suspends.
- Lifecycle hooks: onChatStart, onTurnStart, onTurnComplete, onAction,
  onValidateMessages, hydrateMessages (short-circuits snapshot+replay
  if the customer owns history).
- chat.history read primitives for HITL flows (getPendingToolCalls,
  getResolvedToolCalls, extractNewToolResults, findMessage, all/getChain).
- chat.local — per-run typed data with Proxy access + dirty tracking.
- chat.headStart — first-turn TTFC bridge via a customer HTTP handler.
- oomMachine — one-shot OOM-retry on a larger machine; cutoff derived
  from latest trigger:turn-complete chunk on session.out.
- Actions are no longer turns — onAction may mutate via chat.history.*
  and may return a StreamTextResult without bumping the turn counter.
- gen_ai.conversation.id stamped on chat spans + metrics for telemetry.
- Skills runtime (loadable per-agent and per-task) + agent skills bundling.

Snapshot + replay integration tests in apps/webapp/test/.
mockChatAgent test harness updated for the new wire.

Includes the chat-agent, chat-agent-delta-wire-snapshots,
chat-history-read-primitives, chat-head-start, chat-actions-no-turn,
chat-session-attributes, agent-skills, and mock-chat-agent-test-harness
changesets.
The browser-facing half of chat.agent: a TriggerChatTransport that
plugs into ai-sdk's useChat, plus AgentChat for direct programmatic
use. Together they let a Next.js or React app drive a chat.agent
task in trigger.dev cloud over SSE.

- TriggerChatTransport (packages/trigger-sdk/src/v3/chat.ts):
  Vercel ai-sdk Transport implementation. Delta-only wire sends, SSE
  reconnection with lastEventId resume, stop/abort cleanup, dynamic
  accessToken refresh, X-Peek-Settled fast-close.
- AgentChat (chat-client.ts): direct programmatic chat with the same
  underlying transport.
- useTriggerChatTransport (chat-react.ts): React hook for the
  ai-sdk Transport.
- chat-tab-coordinator: cross-tab leader election for shared SSE.
- auth.ts: token plumbing for the transport.
- packages/core/src/v3/chat-client.ts: shared envelope/wire types
  used by both browser and server runtime.
Dashboard surfaces for inspecting and debugging chat.agent runs.
Depends on the Sessions primitive (L1) and chat.agent runtime (L2+L3).

Run inspector — chat-aware:
- AgentView + AgentMessageView (run inspector tab for chat.agent runs)
- AIChatMessages + AISpanDetails + types.ts (per-span chat message
  rendering, tool-call/tool-output handling)
- PromptSpanDetails (gen_ai.* span detail panel)
- StreamdownRenderer + shikiTheme (markdown renderer with shiki
  highlighting and v2 patch)
- useAutoScrollToBottom hook

Playground UI (interactive chat.agent debugger):
- /playground index + /playground/$agentParam routes
- /agents route + AgentListPresenter
- PlaygroundPresenter (per-org basin variants, clientData wiring)
- realtime session routes for playground + run inspector chat
- AI-generate-payload + AIPayloadTabContent for the test panel

Navigation + theming:
- SideMenu links for Agents and Playground
- BlankStatePanels copy updates
- tailwind config + tailwind.css storybook hooks
- streamdown@2 dep in apps/webapp/package.json

Includes agent-view-sessions, playground-trigger-config-fields,
run-agent-view, and streamdown-v2-upgrade .server-changes.
Top of the chat.agent stack: a full Next.js reference project that
exercises chat.agent end-to-end, plus the CLI MCP tools that drive
agent runs from Claude Code / Cursor / etc.

references/ai-chat:
- Full Next.js app with prisma persistence, multi-chat sidebar,
  per-chat model picker, debug panel, tool examples, smoke tests
- Reference tools: getCurrentTime, searchHackerNews, createGithubIssue,
  PR review helpers, code sandbox
- chat-client-test orchestrator for concurrent-send stress
- references/hello-world chatAgent + triggerAndSubscribe examples

CLI MCP tooling for chat.agent:
- mcp/tools/agentChat.ts (start_agent_chat, send_agent_message,
  close_agent_chat)
- mcp/tools/agents.ts + tasks.ts (list agents, agent run details)
- dev-run-controller OOM kill + taskRunProcessPool tweaks
- dev/managed entry-point hooks for skills bundling
- buildWorker + bundleSkills (agent skills support)

Includes ai-tool-helpers + mcp-agent-chat-sessions changesets, plus
the streamdown@2 patch and pnpm-lock reconciliation.

(Will be renamed to feature/ai-chat-reference-and-cli before push.)
@ericallam ericallam force-pushed the feature/agent-view-dashboard branch from 220b33c to 067109f Compare May 12, 2026 09:48
@ericallam ericallam force-pushed the feature/ai-chat-reference-and-cli branch from 48f030a to 3c71eeb Compare May 12, 2026 09:49
@ericallam ericallam force-pushed the feature/agent-view-dashboard branch from 067109f to c1f6db7 Compare May 12, 2026 09:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant