Merge main into mobile remote connect
Co-authored-by: codex <[email protected]>
This commit is contained in:
commit
2cffe6742e
8 files changed
+427
-62
No files matched your search
@@ -641,7 +641,7 @@ jobs:
|
||||
|
||||
echo "Deploying hosted web app for $channel_name channel."
|
||||
deployment_url="$(
|
||||
bunx [email protected] deploy apps/web \
|
||||
bunx [email protected] deploy \
|
||||
--prod \
|
||||
--skip-domain \
|
||||
--yes \
|
||||
|
||||
@@ -14,6 +14,7 @@ import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/unstab
|
||||
import { AuthError, ServerAuth } from "./Services/ServerAuth.ts";
|
||||
import { SessionCredentialService } from "./Services/SessionCredentialService.ts";
|
||||
import { deriveAuthClientMetadata } from "./utils.ts";
|
||||
import { browserApiCorsHeaders } from "../httpCors.ts";
|
||||
|
||||
export const respondToAuthError = (error: AuthError) =>
|
||||
Effect.gen(function* () {
|
||||
@@ -27,7 +28,7 @@ export const respondToAuthError = (error: AuthError) =>
|
||||
{
|
||||
error: error.message,
|
||||
},
|
||||
{ status: error.status ?? 500 },
|
||||
{ status: error.status ?? 500, headers: browserApiCorsHeaders },
|
||||
);
|
||||
});
|
||||
|
||||
@@ -38,7 +39,10 @@ export const authSessionRouteLayer = HttpRouter.add(
|
||||
const request = yield* HttpServerRequest.HttpServerRequest;
|
||||
const serverAuth = yield* ServerAuth;
|
||||
const session = yield* serverAuth.getSessionState(request);
|
||||
return HttpServerResponse.jsonUnsafe(session, { status: 200 });
|
||||
return HttpServerResponse.jsonUnsafe(session, {
|
||||
status: 200,
|
||||
headers: browserApiCorsHeaders,
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
@@ -81,7 +85,10 @@ export const authBootstrapRouteLayer = HttpRouter.add(
|
||||
deriveAuthClientMetadata({ request }),
|
||||
);
|
||||
|
||||
return yield* HttpServerResponse.jsonUnsafe(result.response, { status: 200 }).pipe(
|
||||
return yield* HttpServerResponse.jsonUnsafe(result.response, {
|
||||
status: 200,
|
||||
headers: browserApiCorsHeaders,
|
||||
}).pipe(
|
||||
HttpServerResponse.setCookie(sessions.cookieName, result.sessionToken, {
|
||||
expires: DateTime.toDate(result.response.expiresAt),
|
||||
httpOnly: true,
|
||||
@@ -114,6 +121,7 @@ export const authBearerBootstrapRouteLayer = HttpRouter.add(
|
||||
);
|
||||
return HttpServerResponse.jsonUnsafe(result satisfies AuthBearerBootstrapResult, {
|
||||
status: 200,
|
||||
headers: browserApiCorsHeaders,
|
||||
});
|
||||
}).pipe(Effect.catchTag("AuthError", (error) => respondToAuthError(error))),
|
||||
);
|
||||
@@ -128,6 +136,7 @@ export const authWebSocketTokenRouteLayer = HttpRouter.add(
|
||||
const result = yield* serverAuth.issueWebSocketToken(session);
|
||||
return HttpServerResponse.jsonUnsafe(result satisfies AuthWebSocketTokenResult, {
|
||||
status: 200,
|
||||
headers: browserApiCorsHeaders,
|
||||
});
|
||||
}).pipe(Effect.catchTag("AuthError", (error) => respondToAuthError(error))),
|
||||
);
|
||||
|
||||
+11
-3
@@ -28,6 +28,11 @@ import { ProjectFaviconResolver } from "./project/Services/ProjectFaviconResolve
|
||||
import { ServerAuth } from "./auth/Services/ServerAuth.ts";
|
||||
import { respondToAuthError } from "./auth/http.ts";
|
||||
import { ServerEnvironment } from "./environment/Services/ServerEnvironment.ts";
|
||||
import {
|
||||
browserApiCorsAllowedHeaders,
|
||||
browserApiCorsAllowedMethods,
|
||||
browserApiCorsHeaders,
|
||||
} from "./httpCors.ts";
|
||||
|
||||
const PROJECT_FAVICON_CACHE_CONTROL = "public, max-age=3600";
|
||||
const FALLBACK_PROJECT_FAVICON_SVG = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" width="24" height="24" fill="none" stroke="#6b728080" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" data-fallback="project-favicon"><path d="M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-8l-2-2H4a2 2 0 0 0-2 2v12a2 2 0 0 0 2 2Z"/></svg>`;
|
||||
@@ -35,8 +40,8 @@ const OTLP_TRACES_PROXY_PATH = "/api/observability/v1/traces";
|
||||
const LOOPBACK_HOSTNAMES = new Set(["127.0.0.1", "::1", "localhost"]);
|
||||
|
||||
export const browserApiCorsLayer = HttpRouter.cors({
|
||||
allowedMethods: ["GET", "POST", "OPTIONS"],
|
||||
allowedHeaders: ["authorization", "b3", "traceparent", "content-type"],
|
||||
allowedMethods: [...browserApiCorsAllowedMethods],
|
||||
allowedHeaders: [...browserApiCorsAllowedHeaders],
|
||||
maxAge: 600,
|
||||
});
|
||||
|
||||
@@ -69,7 +74,10 @@ export const serverEnvironmentRouteLayer = HttpRouter.add(
|
||||
const descriptor = yield* Effect.service(ServerEnvironment).pipe(
|
||||
Effect.flatMap((serverEnvironment) => serverEnvironment.getDescriptor),
|
||||
);
|
||||
return HttpServerResponse.jsonUnsafe(descriptor, { status: 200 });
|
||||
return HttpServerResponse.jsonUnsafe(descriptor, {
|
||||
status: 200,
|
||||
headers: browserApiCorsHeaders,
|
||||
});
|
||||
}),
|
||||
);
|
||||
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
export const browserApiCorsAllowedMethods = ["GET", "POST", "OPTIONS"] as const;
|
||||
export const browserApiCorsAllowedHeaders = [
|
||||
"authorization",
|
||||
"b3",
|
||||
"traceparent",
|
||||
"content-type",
|
||||
] as const;
|
||||
|
||||
export const browserApiCorsHeaders = {
|
||||
"access-control-allow-origin": "*",
|
||||
"access-control-allow-methods": browserApiCorsAllowedMethods.join(", "),
|
||||
"access-control-allow-headers": browserApiCorsAllowedHeaders.join(", "),
|
||||
} as const;
|
||||
+105
-16
@@ -813,7 +813,12 @@ const bootstrapBrowserSession = (
|
||||
};
|
||||
});
|
||||
|
||||
const bootstrapBearerSession = (credential = defaultDesktopBootstrapToken) =>
|
||||
const bootstrapBearerSession = (
|
||||
credential = defaultDesktopBootstrapToken,
|
||||
options?: {
|
||||
readonly headers?: Record<string, string>;
|
||||
},
|
||||
) =>
|
||||
Effect.gen(function* () {
|
||||
const bootstrapUrl = yield* getHttpServerUrl("/api/auth/bootstrap/bearer");
|
||||
const response = yield* Effect.promise(() =>
|
||||
@@ -821,6 +826,7 @@ const bootstrapBearerSession = (credential = defaultDesktopBootstrapToken) =>
|
||||
method: "POST",
|
||||
headers: {
|
||||
"content-type": "application/json",
|
||||
...options?.headers,
|
||||
},
|
||||
body: JSON.stringify({
|
||||
credential,
|
||||
@@ -896,6 +902,22 @@ const splitHeaderTokens = (value: string | null) =>
|
||||
.filter((token) => token.length > 0)
|
||||
.toSorted();
|
||||
|
||||
const assertBrowserApiCorsHeaders = (headers: Headers) => {
|
||||
assert.equal(headers.get("access-control-allow-origin"), "*");
|
||||
assert.deepEqual(splitHeaderTokens(headers.get("access-control-allow-methods")), [
|
||||
"GET",
|
||||
"OPTIONS",
|
||||
"POST",
|
||||
]);
|
||||
assert.deepEqual(splitHeaderTokens(headers.get("access-control-allow-headers")), [
|
||||
"authorization",
|
||||
"b3",
|
||||
"content-type",
|
||||
"traceparent",
|
||||
]);
|
||||
};
|
||||
const crossOriginClientOrigin = "http://remote-client.test:3773";
|
||||
|
||||
const getWsServerUrl = (
|
||||
pathname = "",
|
||||
options?: { authenticated?: boolean; credential?: string },
|
||||
@@ -1017,6 +1039,28 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
||||
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
|
||||
);
|
||||
|
||||
it.effect("includes CORS headers on public environment descriptor responses", () =>
|
||||
Effect.gen(function* () {
|
||||
yield* buildAppUnderTest();
|
||||
|
||||
const url = yield* getHttpServerUrl("/.well-known/t3/environment");
|
||||
const response = yield* Effect.promise(() =>
|
||||
fetch(url, {
|
||||
headers: {
|
||||
origin: crossOriginClientOrigin,
|
||||
},
|
||||
}),
|
||||
);
|
||||
const body = (yield* Effect.promise(() =>
|
||||
response.json(),
|
||||
)) as typeof testEnvironmentDescriptor;
|
||||
|
||||
assert.equal(response.status, 200);
|
||||
assertBrowserApiCorsHeaders(response.headers);
|
||||
assert.deepEqual(body, testEnvironmentDescriptor);
|
||||
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
|
||||
);
|
||||
|
||||
it.effect("reports unauthenticated session state without requiring auth", () =>
|
||||
Effect.gen(function* () {
|
||||
yield* buildAppUnderTest();
|
||||
@@ -1140,6 +1184,62 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
||||
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
|
||||
);
|
||||
|
||||
it.effect("includes CORS headers on remote auth success responses", () =>
|
||||
Effect.gen(function* () {
|
||||
yield* buildAppUnderTest();
|
||||
|
||||
const origin = crossOriginClientOrigin;
|
||||
const { response: bootstrapResponse, body: bootstrapBody } = yield* bootstrapBearerSession(
|
||||
defaultDesktopBootstrapToken,
|
||||
{
|
||||
headers: { origin },
|
||||
},
|
||||
);
|
||||
|
||||
assert.equal(bootstrapResponse.status, 200);
|
||||
assertBrowserApiCorsHeaders(bootstrapResponse.headers);
|
||||
assert.equal(bootstrapBody.authenticated, true);
|
||||
assert.equal(typeof bootstrapBody.sessionToken, "string");
|
||||
|
||||
const sessionUrl = yield* getHttpServerUrl("/api/auth/session");
|
||||
const sessionResponse = yield* Effect.promise(() =>
|
||||
fetch(sessionUrl, {
|
||||
headers: {
|
||||
authorization: `Bearer ${bootstrapBody.sessionToken ?? ""}`,
|
||||
origin,
|
||||
},
|
||||
}),
|
||||
);
|
||||
const sessionBody = (yield* Effect.promise(() => sessionResponse.json())) as {
|
||||
readonly authenticated: boolean;
|
||||
readonly sessionMethod?: string;
|
||||
};
|
||||
|
||||
assert.equal(sessionResponse.status, 200);
|
||||
assertBrowserApiCorsHeaders(sessionResponse.headers);
|
||||
assert.equal(sessionBody.authenticated, true);
|
||||
assert.equal(sessionBody.sessionMethod, "bearer-session-token");
|
||||
|
||||
const wsTokenUrl = yield* getHttpServerUrl("/api/auth/ws-token");
|
||||
const wsTokenResponse = yield* Effect.promise(() =>
|
||||
fetch(wsTokenUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
authorization: `Bearer ${bootstrapBody.sessionToken ?? ""}`,
|
||||
origin,
|
||||
},
|
||||
}),
|
||||
);
|
||||
const wsTokenBody = (yield* Effect.promise(() => wsTokenResponse.json())) as {
|
||||
readonly token: string;
|
||||
};
|
||||
|
||||
assert.equal(wsTokenResponse.status, 200);
|
||||
assertBrowserApiCorsHeaders(wsTokenResponse.headers);
|
||||
assert.equal(typeof wsTokenBody.token, "string");
|
||||
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
|
||||
);
|
||||
|
||||
it.effect(
|
||||
"responds to remote auth websocket-token preflight requests with authorization CORS headers",
|
||||
() =>
|
||||
@@ -1151,7 +1251,7 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
||||
fetch(wsTokenUrl, {
|
||||
method: "OPTIONS",
|
||||
headers: {
|
||||
origin: "http://192.168.86.35:3773",
|
||||
origin: crossOriginClientOrigin,
|
||||
"access-control-request-method": "POST",
|
||||
"access-control-request-headers": "authorization",
|
||||
},
|
||||
@@ -1159,18 +1259,7 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
||||
);
|
||||
|
||||
assert.equal(response.status, 204);
|
||||
assert.equal(response.headers.get("access-control-allow-origin"), "*");
|
||||
assert.deepEqual(splitHeaderTokens(response.headers.get("access-control-allow-methods")), [
|
||||
"GET",
|
||||
"OPTIONS",
|
||||
"POST",
|
||||
]);
|
||||
assert.deepEqual(splitHeaderTokens(response.headers.get("access-control-allow-headers")), [
|
||||
"authorization",
|
||||
"b3",
|
||||
"content-type",
|
||||
"traceparent",
|
||||
]);
|
||||
assertBrowserApiCorsHeaders(response.headers);
|
||||
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
|
||||
);
|
||||
|
||||
@@ -1183,7 +1272,7 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
||||
fetch(wsTokenUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
origin: "http://192.168.86.35:3773",
|
||||
origin: crossOriginClientOrigin,
|
||||
},
|
||||
}),
|
||||
);
|
||||
@@ -1192,7 +1281,7 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
|
||||
};
|
||||
|
||||
assert.equal(response.status, 401);
|
||||
assert.equal(response.headers.get("access-control-allow-origin"), "*");
|
||||
assertBrowserApiCorsHeaders(response.headers);
|
||||
assert.equal(body.error, "Authentication required.");
|
||||
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
|
||||
);
|
||||
|
||||
@@ -48,6 +48,8 @@ vi.mock("@legendapp/list/react", async () => {
|
||||
|
||||
import { MessagesTimeline } from "./MessagesTimeline";
|
||||
|
||||
const MESSAGE_CREATED_AT = "2026-04-13T12:00:00.000Z";
|
||||
|
||||
function buildProps() {
|
||||
return {
|
||||
isWorking: false,
|
||||
@@ -73,6 +75,27 @@ function buildProps() {
|
||||
};
|
||||
}
|
||||
|
||||
function buildLongUserMessageText(tail = "deep hidden detail only after expand") {
|
||||
return Array.from({ length: 9 }, (_, index) =>
|
||||
index === 8 ? tail : `Line ${index + 1}: ${"verbose prompt content ".repeat(8).trim()}`,
|
||||
).join("\n");
|
||||
}
|
||||
|
||||
function buildUserTimelineEntry(text: string) {
|
||||
return {
|
||||
id: "entry-1",
|
||||
kind: "message" as const,
|
||||
createdAt: MESSAGE_CREATED_AT,
|
||||
message: {
|
||||
id: "message-1" as never,
|
||||
role: "user" as const,
|
||||
text,
|
||||
createdAt: MESSAGE_CREATED_AT,
|
||||
streaming: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe("MessagesTimeline", () => {
|
||||
afterEach(() => {
|
||||
scrollToEndSpy.mockReset();
|
||||
@@ -157,4 +180,87 @@ describe("MessagesTimeline", () => {
|
||||
await screen.unmount();
|
||||
}
|
||||
});
|
||||
|
||||
it("starts long user messages collapsed by default", async () => {
|
||||
const screen = await render(
|
||||
<MessagesTimeline
|
||||
{...buildProps()}
|
||||
timelineEntries={[buildUserTimelineEntry(buildLongUserMessageText())]}
|
||||
/>,
|
||||
);
|
||||
|
||||
try {
|
||||
const toggle = page.getByRole("button", { name: "Show full message" });
|
||||
await expect.element(toggle).toBeVisible();
|
||||
await expect.element(toggle).toHaveAttribute("aria-expanded", "false");
|
||||
|
||||
const messageBody = document.querySelector(
|
||||
"[data-user-message-body='true']",
|
||||
) as HTMLDivElement | null;
|
||||
expect(messageBody?.getAttribute("data-user-message-collapsed")).toBe("true");
|
||||
expect(messageBody?.className).toContain("max-h-44");
|
||||
expect(messageBody?.className).toContain("overflow-hidden");
|
||||
expect(messageBody?.getAttribute("data-user-message-fade")).toBe("true");
|
||||
expect(messageBody?.style.maskImage).toContain("linear-gradient");
|
||||
} finally {
|
||||
await screen.unmount();
|
||||
}
|
||||
});
|
||||
|
||||
it("expands and re-collapses long user messages from the toggle", async () => {
|
||||
const screen = await render(
|
||||
<MessagesTimeline
|
||||
{...buildProps()}
|
||||
timelineEntries={[buildUserTimelineEntry(buildLongUserMessageText())]}
|
||||
/>,
|
||||
);
|
||||
|
||||
try {
|
||||
const expandButton = page.getByRole("button", { name: "Show full message" });
|
||||
await expect.element(expandButton).toBeVisible();
|
||||
|
||||
expect(document.body.textContent ?? "").toContain("deep hidden detail only after expand");
|
||||
|
||||
await expandButton.click();
|
||||
|
||||
const collapseButton = page.getByRole("button", { name: "Show less" });
|
||||
await expect.element(collapseButton).toBeVisible();
|
||||
await expect.element(collapseButton).toHaveAttribute("aria-expanded", "true");
|
||||
|
||||
let messageBody = document.querySelector("[data-user-message-body='true']");
|
||||
expect(messageBody?.getAttribute("data-user-message-collapsed")).toBe("false");
|
||||
expect(messageBody?.className).not.toContain("max-h-44");
|
||||
expect(messageBody?.getAttribute("data-user-message-fade")).toBe("false");
|
||||
expect((messageBody as HTMLDivElement | null)?.style.maskImage ?? "").toBe("");
|
||||
|
||||
await collapseButton.click();
|
||||
|
||||
await expect.element(page.getByRole("button", { name: "Show full message" })).toBeVisible();
|
||||
messageBody = document.querySelector("[data-user-message-body='true']");
|
||||
expect(messageBody?.getAttribute("data-user-message-collapsed")).toBe("true");
|
||||
expect(messageBody?.className).toContain("max-h-44");
|
||||
expect(messageBody?.getAttribute("data-user-message-fade")).toBe("true");
|
||||
expect((messageBody as HTMLDivElement | null)?.style.maskImage).toContain("linear-gradient");
|
||||
} finally {
|
||||
await screen.unmount();
|
||||
}
|
||||
});
|
||||
|
||||
it("starts the newest long user prompt collapsed", async () => {
|
||||
const screen = await render(
|
||||
<MessagesTimeline
|
||||
{...buildProps()}
|
||||
timelineEntries={[buildUserTimelineEntry(buildLongUserMessageText("latest long prompt"))]}
|
||||
/>,
|
||||
);
|
||||
|
||||
try {
|
||||
await expect.element(page.getByRole("button", { name: "Show full message" })).toBeVisible();
|
||||
|
||||
const messageBody = document.querySelector("[data-user-message-body='true']");
|
||||
expect(messageBody?.getAttribute("data-user-message-collapsed")).toBe("true");
|
||||
} finally {
|
||||
await screen.unmount();
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -92,6 +92,7 @@ beforeAll(() => {
|
||||
});
|
||||
|
||||
const ACTIVE_THREAD_ENVIRONMENT_ID = EnvironmentId.make("environment-local");
|
||||
const MESSAGE_CREATED_AT = "2026-03-17T19:12:28.000Z";
|
||||
|
||||
function buildProps() {
|
||||
return {
|
||||
@@ -118,33 +119,73 @@ function buildProps() {
|
||||
};
|
||||
}
|
||||
|
||||
function buildLongUserMessageText(tail = "deep hidden detail only after expand") {
|
||||
return Array.from({ length: 9 }, (_, index) =>
|
||||
index === 8 ? tail : `Line ${index + 1}: ${"verbose prompt content ".repeat(8).trim()}`,
|
||||
).join("\n");
|
||||
}
|
||||
|
||||
function buildUserTimelineEntry(text: string) {
|
||||
return {
|
||||
id: "entry-1",
|
||||
kind: "message" as const,
|
||||
createdAt: MESSAGE_CREATED_AT,
|
||||
message: {
|
||||
id: MessageId.make("message-1"),
|
||||
role: "user" as const,
|
||||
text,
|
||||
createdAt: MESSAGE_CREATED_AT,
|
||||
streaming: false,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
describe("MessagesTimeline", () => {
|
||||
it("renders collapse controls for long user messages", async () => {
|
||||
const { MessagesTimeline } = await import("./MessagesTimeline");
|
||||
const markup = renderToStaticMarkup(
|
||||
<MessagesTimeline
|
||||
{...buildProps()}
|
||||
timelineEntries={[buildUserTimelineEntry(buildLongUserMessageText())]}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain("Show full message");
|
||||
expect(markup).toContain('data-user-message-collapsed="true"');
|
||||
expect(markup).toContain('data-user-message-fade="true"');
|
||||
expect(markup).toContain('data-user-message-footer="true"');
|
||||
});
|
||||
|
||||
it("does not render collapse controls for short user messages", async () => {
|
||||
const { MessagesTimeline } = await import("./MessagesTimeline");
|
||||
const markup = renderToStaticMarkup(
|
||||
<MessagesTimeline
|
||||
{...buildProps()}
|
||||
timelineEntries={[buildUserTimelineEntry("Short prompt.")]}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).not.toContain("Show full message");
|
||||
expect(markup).toContain('data-user-message-collapsible="false"');
|
||||
});
|
||||
|
||||
it("renders inline terminal labels with the composer chip UI", async () => {
|
||||
const { MessagesTimeline } = await import("./MessagesTimeline");
|
||||
const markup = renderToStaticMarkup(
|
||||
<MessagesTimeline
|
||||
{...buildProps()}
|
||||
timelineEntries={[
|
||||
{
|
||||
id: "entry-1",
|
||||
kind: "message",
|
||||
createdAt: "2026-03-17T19:12:28.000Z",
|
||||
message: {
|
||||
id: MessageId.make("message-2"),
|
||||
role: "user",
|
||||
text: [
|
||||
"yoo what's @terminal-1:1-5 mean",
|
||||
"",
|
||||
"<terminal_context>",
|
||||
"- Terminal 1 lines 1-5:",
|
||||
" 1 | julius@mac effect-http-ws-cli % bun i",
|
||||
" 2 | bun install v1.3.9 (cf6cdbbb)",
|
||||
"</terminal_context>",
|
||||
].join("\n"),
|
||||
createdAt: "2026-03-17T19:12:28.000Z",
|
||||
streaming: false,
|
||||
},
|
||||
},
|
||||
buildUserTimelineEntry(
|
||||
[
|
||||
buildLongUserMessageText("yoo what's @terminal-1:1-5 mean"),
|
||||
"",
|
||||
"<terminal_context>",
|
||||
"- Terminal 1 lines 1-5:",
|
||||
" 1 | julius@mac effect-http-ws-cli % bun i",
|
||||
" 2 | bun install v1.3.9 (cf6cdbbb)",
|
||||
"</terminal_context>",
|
||||
].join("\n"),
|
||||
),
|
||||
]}
|
||||
/>,
|
||||
);
|
||||
@@ -152,8 +193,23 @@ describe("MessagesTimeline", () => {
|
||||
expect(markup).toContain("Terminal 1 lines 1-5");
|
||||
expect(markup).toContain("lucide-terminal");
|
||||
expect(markup).toContain("yoo what's ");
|
||||
expect(markup).toContain("Show full message");
|
||||
}, 20_000);
|
||||
|
||||
it("keeps the copy button for collapsed long user messages", async () => {
|
||||
const { MessagesTimeline } = await import("./MessagesTimeline");
|
||||
const markup = renderToStaticMarkup(
|
||||
<MessagesTimeline
|
||||
{...buildProps()}
|
||||
timelineEntries={[buildUserTimelineEntry(buildLongUserMessageText())]}
|
||||
/>,
|
||||
);
|
||||
|
||||
expect(markup).toContain('aria-label="Copy link"');
|
||||
expect(markup).toContain('data-user-message-collapsed="true"');
|
||||
expect(markup).toContain('data-user-message-footer="true"');
|
||||
});
|
||||
|
||||
it("renders context compaction entries in the normal work log", async () => {
|
||||
const { MessagesTimeline } = await import("./MessagesTimeline");
|
||||
const markup = renderToStaticMarkup(
|
||||
|
||||
@@ -406,25 +406,25 @@ function UserTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "message"
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
{(displayedUserMessage.visibleText.trim().length > 0 || terminalContexts.length > 0) && (
|
||||
<UserMessageBody
|
||||
text={displayedUserMessage.visibleText}
|
||||
terminalContexts={terminalContexts}
|
||||
resolvedTheme={ctx.resolvedTheme}
|
||||
skills={ctx.skills}
|
||||
/>
|
||||
)}
|
||||
<div className="mt-1.5 flex items-center justify-end gap-2">
|
||||
<div className="flex items-center gap-1.5 opacity-0 transition-opacity duration-200 focus-within:opacity-100 group-hover:opacity-100">
|
||||
{displayedUserMessage.copyText && (
|
||||
<MessageCopyButton text={displayedUserMessage.copyText} />
|
||||
)}
|
||||
{canRevertAgentWork && <RevertUserMessageButton messageId={row.message.id} />}
|
||||
</div>
|
||||
<p className="text-right text-xs text-muted-foreground/50">
|
||||
{formatTimestamp(row.message.createdAt, ctx.timestampFormat)}
|
||||
</p>
|
||||
</div>
|
||||
<CollapsibleUserMessageBody
|
||||
text={displayedUserMessage.visibleText}
|
||||
terminalContexts={terminalContexts}
|
||||
resolvedTheme={ctx.resolvedTheme}
|
||||
skills={ctx.skills}
|
||||
footer={
|
||||
<>
|
||||
<div className="flex items-center gap-1.5 opacity-0 transition-opacity duration-200 focus-within:opacity-100 group-hover:opacity-100">
|
||||
{displayedUserMessage.copyText && (
|
||||
<MessageCopyButton text={displayedUserMessage.copyText} />
|
||||
)}
|
||||
{canRevertAgentWork && <RevertUserMessageButton messageId={row.message.id} />}
|
||||
</div>
|
||||
<p className="text-right text-xs text-muted-foreground/50">
|
||||
{formatTimestamp(row.message.createdAt, ctx.timestampFormat)}
|
||||
</p>
|
||||
</>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@@ -797,6 +797,90 @@ const UserMessageTerminalContextInlineLabel = memo(
|
||||
},
|
||||
);
|
||||
|
||||
const MAX_COLLAPSED_USER_MESSAGE_LINES = 8;
|
||||
const MAX_COLLAPSED_USER_MESSAGE_LENGTH = 600;
|
||||
const COLLAPSED_USER_MESSAGE_FADE_HEIGHT_REM = 1.75;
|
||||
const COLLAPSED_USER_MESSAGE_FADE_MASK = `linear-gradient(to bottom, black calc(100% - ${COLLAPSED_USER_MESSAGE_FADE_HEIGHT_REM}rem), transparent)`;
|
||||
|
||||
function shouldCollapseUserMessage(text: string): boolean {
|
||||
if (text.trim().length === 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (
|
||||
text.length > MAX_COLLAPSED_USER_MESSAGE_LENGTH ||
|
||||
text.split("\n").length > MAX_COLLAPSED_USER_MESSAGE_LINES
|
||||
);
|
||||
}
|
||||
|
||||
const CollapsibleUserMessageBody = memo(function CollapsibleUserMessageBody(props: {
|
||||
text: string;
|
||||
terminalContexts: ParsedTerminalContextEntry[];
|
||||
resolvedTheme: "light" | "dark";
|
||||
skills: ReadonlyArray<Pick<ServerProviderSkill, "name" | "displayName">>;
|
||||
footer?: ReactNode;
|
||||
}) {
|
||||
const [expanded, setExpanded] = useState(false);
|
||||
const hasVisibleBody = props.text.trim().length > 0 || props.terminalContexts.length > 0;
|
||||
const canCollapse = hasVisibleBody && shouldCollapseUserMessage(props.text);
|
||||
const isCollapsed = canCollapse && !expanded;
|
||||
|
||||
return (
|
||||
<div>
|
||||
{hasVisibleBody ? (
|
||||
<div
|
||||
className={cn("relative", isCollapsed && "max-h-44 overflow-hidden")}
|
||||
data-user-message-body="true"
|
||||
data-user-message-collapsed={isCollapsed ? "true" : "false"}
|
||||
data-user-message-collapsible={canCollapse ? "true" : "false"}
|
||||
data-user-message-fade={isCollapsed ? "true" : "false"}
|
||||
style={
|
||||
isCollapsed
|
||||
? {
|
||||
WebkitMaskImage: COLLAPSED_USER_MESSAGE_FADE_MASK,
|
||||
maskImage: COLLAPSED_USER_MESSAGE_FADE_MASK,
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
>
|
||||
<UserMessageBody
|
||||
text={props.text}
|
||||
terminalContexts={props.terminalContexts}
|
||||
resolvedTheme={props.resolvedTheme}
|
||||
skills={props.skills}
|
||||
/>
|
||||
</div>
|
||||
) : null}
|
||||
{canCollapse || props.footer ? (
|
||||
<div
|
||||
className={cn(
|
||||
"mt-1.5 flex items-center gap-2",
|
||||
canCollapse && props.footer ? "justify-between" : "justify-end",
|
||||
)}
|
||||
data-user-message-footer="true"
|
||||
>
|
||||
{canCollapse ? (
|
||||
<Button
|
||||
type="button"
|
||||
size="xs"
|
||||
variant="ghost"
|
||||
aria-expanded={expanded}
|
||||
data-scroll-anchor-ignore
|
||||
onClick={() => setExpanded((value) => !value)}
|
||||
className="-ml-1 h-6 rounded-md px-1.5 text-xs text-muted-foreground/72 hover:bg-muted/55 hover:text-foreground/85"
|
||||
>
|
||||
{expanded ? "Show less" : "Show full message"}
|
||||
</Button>
|
||||
) : null}
|
||||
{props.footer ? (
|
||||
<div className="ml-auto flex items-center gap-2">{props.footer}</div>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
);
|
||||
});
|
||||
|
||||
const UserMessageBody = memo(function UserMessageBody(props: {
|
||||
text: string;
|
||||
terminalContexts: ParsedTerminalContextEntry[];
|
||||
|
||||
Reference in new issue
Block a user