Skip to content

Commit ea9d6f7

Browse files
authored
feat(webapp): pin the dashboard agent to a deployed version (#4128)
## Summary The dashboard agent runs as a `chat.agent` in its own Trigger.dev project, deployed separately from the app that starts its sessions. This adds independent, non-disruptive deploys for it: a new workflow deploys the agent with `--skip-promotion` (so a deploy never becomes the current version on its own), and the app pins its sessions to a chosen version. ## How it works `DASHBOARD_AGENT_VERSION` (unset by default) pins agent sessions to a specific deployed version; when unset, sessions run on the project environment's current version. The pin is passed on session start and head start and is forwarded to every continuation run, so a pinned session stays on its version for its whole life. Cutting over to a new build becomes a config change (set the version) rather than a redeploy, and rollback is flipping it back. The workflow (`dashboard-agent-deploy.yml`) runs a leg per environment (staging and prod), each gated by its own environment, and triggers on pushes to `main` that touch the agent or its store (also available via manual dispatch). Deploy versions are per-environment, so each environment pins to its own leg's version.
1 parent 0f349dd commit ea9d6f7

4 files changed

Lines changed: 88 additions & 2 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
name: "🤖 Deploy dashboard agent"
2+
3+
# Deploys the @internal/dashboard-agent chat.agent to its Trigger.dev project
4+
# with --skip-promotion, so a deploy never becomes "current" on its own. The
5+
# consuming app cuts over by pinning DASHBOARD_AGENT_VERSION to the new version.
6+
# Runs a leg per environment (staging + prod), each gated by its own environment;
7+
# a push to main that touches the agent or its store triggers both. Version
8+
# numbers are per-environment, so pin each environment to its own leg's version.
9+
10+
on:
11+
push:
12+
branches: [main]
13+
paths:
14+
- "internal-packages/dashboard-agent/**"
15+
- "internal-packages/dashboard-agent-db/**"
16+
workflow_dispatch:
17+
18+
permissions: {}
19+
20+
jobs:
21+
deploy:
22+
name: Deploy dashboard agent (${{ matrix.environment }})
23+
runs-on: ubuntu-latest
24+
strategy:
25+
fail-fast: false
26+
matrix:
27+
environment: [staging, prod]
28+
# Per-environment reviewer gate + source of the scoped deploy PAT.
29+
environment: dashboard-agent-${{ matrix.environment }}
30+
concurrency:
31+
group: dashboard-agent-deploy-${{ matrix.environment }}
32+
cancel-in-progress: false
33+
permissions:
34+
contents: read
35+
env:
36+
TRIGGER_API_URL: https://api.trigger.dev
37+
TRIGGER_DASHBOARD_AGENT_PROJECT_REF: ${{ vars.TRIGGER_DASHBOARD_AGENT_PROJECT_REF }}
38+
steps:
39+
- name: Checkout
40+
uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7.0.0
41+
with:
42+
persist-credentials: false
43+
44+
- name: Setup pnpm
45+
uses: pnpm/action-setup@fc06bc1257f339d1d5d8b3a19a8cae5388b55320 # v5.0.0
46+
with:
47+
version: 10.33.2
48+
49+
- name: Setup node
50+
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
51+
with:
52+
node-version: 20.20.2
53+
cache: "pnpm"
54+
55+
- name: Install + build the CLI and the agent's deps
56+
run: |
57+
set -euo pipefail
58+
pnpm install --frozen-lockfile
59+
# Prisma client is needed because the build closure pulls in @trigger.dev/database.
60+
pnpm run generate
61+
# Config-time imports the agent's trigger.config.ts needs: defineConfig (sdk), aptGet (build).
62+
pnpm run build --filter trigger.dev --filter @trigger.dev/build --filter @trigger.dev/sdk
63+
64+
- name: Deploy (--skip-promotion)
65+
working-directory: internal-packages/dashboard-agent
66+
env:
67+
TRIGGER_ACCESS_TOKEN: ${{ secrets.TRIGGER_DASHBOARD_AGENT_DEPLOY_TOKEN }}
68+
# Invoke the built CLI directly (what the workspace .bin/trigger wrapper does),
69+
# so a not-yet-linked bin after a fresh install can't break the deploy.
70+
run: node ../../packages/cli-v3/dist/esm/index.js deploy --skip-promotion --env ${{ matrix.environment }}

apps/webapp/app/env.server.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ const EnvironmentSchema = z
106106
// standard chat.agent SDK flow. When unset, the live agent is disabled — the
107107
// conversation store / History still work, no chat can start.
108108
DASHBOARD_AGENT_SECRET_KEY: z.string().optional(),
109+
// Pins agent sessions to a specific deployed version (paired with
110+
// --skip-promotion deploys); unset => the project env's current version.
111+
DASHBOARD_AGENT_VERSION: z.string().optional(),
109112
// Global default for the `hasDashboardAgentAccess` flag. "0" (off) ships the
110113
// agent dark; flip to "1" to enable it for everyone at GA. Per-org overrides
111114
// (org featureFlags) win regardless.

apps/webapp/app/services/dashboardAgent.server.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,22 @@ export function isDashboardAgentConfigured(): boolean {
5757
return Boolean(env.DASHBOARD_AGENT_SECRET_KEY);
5858
}
5959

60+
// Pins every agent session (and its continuation runs) to a deployed version
61+
// when DASHBOARD_AGENT_VERSION is set; unset runs on the env's current version.
62+
export function dashboardAgentTriggerConfig(): { lockToVersion: string } | undefined {
63+
return env.DASHBOARD_AGENT_VERSION ? { lockToVersion: env.DASHBOARD_AGENT_VERSION } : undefined;
64+
}
65+
6066
export async function startDashboardAgentSession(params: {
6167
chatId: string;
6268
clientData?: Record<string, unknown>;
6369
}): Promise<{ publicAccessToken: string }> {
6470
const config = dashboardAgentConfig();
6571
if (!config) throw new Error("DASHBOARD_AGENT_SECRET_KEY is not set");
66-
const startSession = chat.createStartSessionAction(TASK_ID, { apiClient: config });
72+
const startSession = chat.createStartSessionAction(TASK_ID, {
73+
apiClient: config,
74+
triggerConfig: dashboardAgentTriggerConfig(),
75+
});
6776
return startSession({ chatId: params.chatId, clientData: params.clientData });
6877
}
6978

apps/webapp/app/services/dashboardAgentHeadStart.server.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import {
99
import { chat as chatServer } from "@trigger.dev/sdk/chat-server";
1010
import { streamText, type UIMessage } from "ai";
1111
import { env } from "~/env.server";
12-
import { dashboardAgentApiOrigin } from "~/services/dashboardAgent.server";
12+
import {
13+
dashboardAgentApiOrigin,
14+
dashboardAgentTriggerConfig,
15+
} from "~/services/dashboardAgent.server";
1316
import { logger } from "~/services/logger.server";
1417

1518
const TASK_ID = "dashboard-agent";
@@ -43,6 +46,7 @@ export async function startDashboardAgentHeadStart(params: {
4346
chatId: params.chatId,
4447
messages: params.messages,
4548
metadata: params.metadata,
49+
triggerConfig: dashboardAgentTriggerConfig(),
4650
// Scope session creation + the agent trigger to the agent's project/env. The
4751
// Anthropic key here only powers the warm step-1 call.
4852
apiClient: {

0 commit comments

Comments
 (0)