9a3bee0288
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" />
91 lines
3.8 KiB
TypeScript
91 lines
3.8 KiB
TypeScript
import { createElement } from "react";
|
|
import { renderToStaticMarkup } from "react-dom/server";
|
|
import { describe, expect, it } from "vitest";
|
|
import { restrictModelUrls, StreamdownRenderer } from "./StreamdownRenderer";
|
|
|
|
// streamdown calls urlTransform(url, key, node) to compute each url attribute; a
|
|
// returned undefined removes the attribute, so no request is ever issued.
|
|
const img = { tagName: "img" } as any;
|
|
const link = { tagName: "a" } as any;
|
|
|
|
describe("restrictModelUrls (image src)", () => {
|
|
it("drops a remote model-authored image (the favicon beacon)", () => {
|
|
expect(
|
|
restrictModelUrls("https://www.google.com/s2/favicons?domain=evil", "src", img)
|
|
).toBeUndefined();
|
|
});
|
|
|
|
it("drops any absolute or protocol-relative remote image", () => {
|
|
expect(restrictModelUrls("http://evil.tld/pixel.gif", "src", img)).toBeUndefined();
|
|
expect(restrictModelUrls("//evil.tld/pixel.gif", "src", img)).toBeUndefined();
|
|
});
|
|
|
|
it("drops a backslash-authority image, which the browser reads as protocol-relative", () => {
|
|
expect(restrictModelUrls("\\\\evil.example/pixel.gif", "src", img)).toBeUndefined();
|
|
expect(restrictModelUrls("/\\evil.example/pixel.gif", "src", img)).toBeUndefined();
|
|
});
|
|
|
|
it("drops an image hidden behind a leading C0 control, which the URL parser discards", () => {
|
|
expect(restrictModelUrls("\u0001//evil.tld/p.gif", "src", img)).toBeUndefined();
|
|
expect(restrictModelUrls("\u0000https://evil.tld/p.gif", "src", img)).toBeUndefined();
|
|
});
|
|
|
|
it("keeps inline and same-origin images", () => {
|
|
expect(restrictModelUrls("data:image/png;base64,AAAA", "src", img)).toBe(
|
|
"data:image/png;base64,AAAA"
|
|
);
|
|
expect(restrictModelUrls("blob:abc", "src", img)).toBe("blob:abc");
|
|
expect(restrictModelUrls("/local/pic.png", "src", img)).toBe("/local/pic.png");
|
|
});
|
|
});
|
|
|
|
describe("restrictModelUrls (link href)", () => {
|
|
it("keeps http(s), mailto and relative links", () => {
|
|
expect(restrictModelUrls("https://trigger.dev/docs", "href", link)).toBe(
|
|
"https://trigger.dev/docs"
|
|
);
|
|
expect(restrictModelUrls("http://example.com", "href", link)).toBe("http://example.com");
|
|
expect(restrictModelUrls("mailto:hi@trigger.dev", "href", link)).toBe("mailto:hi@trigger.dev");
|
|
expect(restrictModelUrls("/runs/123", "href", link)).toBe("/runs/123");
|
|
});
|
|
|
|
it("drops unsafe link schemes", () => {
|
|
expect(restrictModelUrls("javascript:alert(1)", "href", link)).toBeUndefined();
|
|
expect(restrictModelUrls("data:text/html,<script>", "href", link)).toBeUndefined();
|
|
});
|
|
});
|
|
|
|
// Force the lazy component to load, then return its resolved default so we can render it
|
|
// synchronously. This proves the policy is actually wired into the JSX, not just exported.
|
|
async function resolveStreamdownRenderer() {
|
|
const lazy = StreamdownRenderer as unknown as {
|
|
_payload: unknown;
|
|
_init: (payload: unknown) => (props: { children: string }) => JSX.Element;
|
|
};
|
|
try {
|
|
lazy._init(lazy._payload);
|
|
} catch (thenable) {
|
|
await thenable;
|
|
}
|
|
return lazy._init(lazy._payload);
|
|
}
|
|
|
|
describe("StreamdownRenderer (rendered markdown)", () => {
|
|
it("never lets a model-authored remote image src reach the DOM", async () => {
|
|
const Renderer = await resolveStreamdownRenderer();
|
|
const markdown = [
|
|
"",
|
|
"",
|
|
"",
|
|
].join("\n\n");
|
|
const html = renderToStaticMarkup(createElement(Renderer, null, markdown));
|
|
|
|
// No remote host is ever fetched: no absolute or protocol-relative image src survives.
|
|
expect(html).not.toContain('src="http');
|
|
expect(html).not.toContain('src="//');
|
|
expect(html).not.toContain("SECRET.evil.tld");
|
|
// A same-origin relative image is untouched, so the policy does not over-block.
|
|
expect(html).toContain('src="/local/pic.png"');
|
|
});
|
|
});
|