Files
Katia Bulatova 9a3bee0288 feat(webapp): dashboard agent — UI (#4529)
Stacked on #4418. Merge that first.

The UI slice of the dashboard agent: the side panel, the chat transport
wiring, message and card rendering, suggested prompts, and chat history.
#4418 works without this — the system is simply invisible. The diff is
mostly components, so the notes below cover only the three decisions you
can't read off the markup. Behavior and a hands-on walkthrough live in
GUIDEBOOK.md, which lands with #4525.

## Decisions worth knowing

- **Action rows always render at the end of a turn.** The model's
emission order isn't trusted for layout, so action blocks are split out
of the stream and appended last. Display only — `answered` stays keyed
on the emission index.
- **The last-chat memory is org-true.** It's keyed by the chat's own
organization, and a foreign or deleted chat comes back as a 404 the
client treats as gone, rather than an empty chat it keeps around.
- **A dead stream self-heals from the settled transcript.** Terminal
records are written to the chat row after the client's stream closes, so
the panel re-reads it. The poll gate is any unfinished turn — a dangling
tool part, not just an open investigation.

## Notes

- Gated by `canAccessDashboardAgent`; no behavior change with the flag
off.
- Page marks: `handle.agentPageContext` on 47 routes, ~20 lines each.
- Entry points: Ask Trigger button, ⌘J, Help & Feedback. The old ⌘I and
`?aiHelp=` links keep working.

## Screenshots

<img width="1440" height="788" alt="Screenshot 2026-08-07 at 15 14 29"
src="https://github.com/user-attachments/assets/f4e89e8d-13ed-4be3-a88d-d5cca3ece0fa"
/>
2026-08-12 08:38:59 +02:00

76 lines
2.5 KiB
TypeScript

import { readFileSync } from "node:fs";
import { join } from "node:path";
import { describe, expect, it } from "vitest";
// Each snippet is its own copyable CodeBlock, so it has to stand alone as a file.
const SNIPPET_FILES = [
"app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam._index/route.tsx",
"app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.tasks.dashboard/route.tsx",
];
type Snippet = { name: string; body: string };
function readSnippets(file: string): Snippet[] {
const source = readFileSync(join(__dirname, "..", file), "utf8");
const snippets: Snippet[] = [];
const declaration = /^const ([A-Z0-9_]*(?:CODE|EXAMPLE)) = `([\s\S]*?)`;$/gm;
for (const match of source.matchAll(declaration)) {
snippets.push({ name: match[1], body: match[2] });
}
return snippets;
}
function importedNames(body: string): Set<string> {
const names = new Set<string>();
for (const match of body.matchAll(/import \{([^}]*)\} from "@trigger\.dev\/sdk[^"]*";/g)) {
for (const name of match[1].split(",")) {
const trimmed = name.trim();
if (trimmed) names.add(trimmed);
}
}
return names;
}
// `export const helloWorld = task({` and `= schedules.task({` both root at their first identifier.
function usedNames(body: string): Set<string> {
const names = new Set<string>();
for (const match of body.matchAll(/^export const \w+ = ([A-Za-z_$][\w$]*)[.(]/gm)) {
names.add(match[1]);
}
return names;
}
describe("task code snippets", () => {
const snippets = SNIPPET_FILES.flatMap((file) =>
readSnippets(file).map((snippet) => ({ ...snippet, file }))
);
it("finds every snippet in both files", () => {
expect(snippets.map((s) => s.name).sort()).toEqual([
"AGENT_EXAMPLE",
"CHAT_AGENT_CODE",
"SCHEDULED_EXAMPLE",
"SCHEDULED_TASK_CODE",
"STANDARD_EXAMPLE",
"STANDARD_TASK_CODE",
]);
});
it.each(snippets)("$name imports every SDK symbol it uses", ({ name, body }) => {
const used = usedNames(body);
expect(used.size, `${name} declares no task`).toBeGreaterThan(0);
const imported = importedNames(body);
for (const symbol of used) {
expect(imported, `${name} uses "${symbol}" without importing it`).toContain(symbol);
}
});
it.each(snippets)("$name imports nothing it does not use", ({ name, body }) => {
const used = usedNames(body);
for (const symbol of importedNames(body)) {
expect(used, `${name} imports "${symbol}" but never uses it`).toContain(symbol);
}
});
});