Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion scripts/check-browser-manifest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ for (const entry of entries) {

const KNOWN_LANES = new Set(["gate", "extended", "extendedFixture", "production", "perf", "manual"]);
// Static harness pages do not open the workspace, so they do not see the welcome dialog.
const welcomeExempt = new Set(["assistant_activity.mjs"]);
const welcomeExempt = new Set(["assistant_activity.mjs", "assistant_reference_overflow.mjs"]);
for (const entry of entries) {
const text = entry.file === undefined ? "" : fs.readFileSync(path.join(browserDir, entry.file), "utf8");
const importsSrc = text.includes('"/src/');
Expand Down
1 change: 1 addition & 0 deletions scripts/run-browser-suite.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ const workflows = [
{ name: "locale", script: "tests/browser/locale.mjs" },
{ name: "creation closure", script: "scripts/verify_creation_browser.mjs" },
{ name: "assistant activity", script: "tests/browser/assistant_activity.mjs" },
{ name: "assistant reference overflow", script: "tests/browser/assistant_reference_overflow.mjs" },
{
name: "generation reference",
script: "tests/browser/canvas_generation_reference.mjs",
Expand Down
38 changes: 12 additions & 26 deletions src/canvas/AssistantPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ import { AgentPicker } from "./AgentPicker";
import { ModelPicker } from "./AssistantPickers";
import { SkillPicker } from "./SkillPicker";
import { CanvasIcon } from "./CanvasIcon";
import { assetDisplayName } from "./assetNames.ts";
import { ChatReferenceChip } from "./ChatReferenceChip";
import {
currentReferences,
fingerprintMatches,
Expand Down Expand Up @@ -42,15 +44,6 @@ import { useReferenceUploads } from "./useReferenceUploads.tsx";
import { useT } from "../i18n/I18nProvider.tsx";
import type { MessageKey } from "../i18n/types.ts";

function kindOf(asset: ChatAsset) {
return asset.type.startsWith("image/")
? "image"
: asset.type.startsWith("video/")
? "video"
: asset.type.startsWith("audio/")
? "audio"
: "text";
}

/** OpenDirector conversation tools in an OpenDirector floating canvas window. */
export function AssistantPanel({
Expand Down Expand Up @@ -449,25 +442,18 @@ export function AssistantPanel({
) : part.type === "skill" ? (
<span key={index} className="cw-chat-skill-token">/{part.name}</span>
) : (
<span
<ChatReferenceChip
key={index}
className="cw-chat-reference"
data-preview-asset={part.assetId}
>
{assetPreviews[part.assetId] ? (
<img src={assetPreviews[part.assetId]} alt="" />
) : (
<CanvasIcon
name={kindOf(
message.assets?.find(
(asset) => asset.id === part.assetId,
) ?? ({ type: "text/plain" } as ChatAsset),
)}
size={18}
/>
name={part.name}
assetId={part.assetId}
asset={message.assets?.find(
(asset) => asset.id === part.assetId,
)}
<span>{part.name}</span>
</span>
previewSrc={assetPreviews[part.assetId]}
ariaLabel={t("assistant.reference.chip", {
name: assetDisplayName(part.name),
})}
/>
),
)
) : (
Expand Down
50 changes: 50 additions & 0 deletions src/canvas/ChatReferenceChip.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import type { ChatAsset } from "../backend/chat";
import { assetDisplayName } from "./assetNames.ts";
import { CanvasIcon } from "./CanvasIcon";

function kindOf(asset: ChatAsset) {
return asset.type.startsWith("image/")
? "image"
: asset.type.startsWith("video/")
? "video"
: asset.type.startsWith("audio/")
? "audio"
: "text";
}

/** Reference chip in a sent user bubble. Matches the composer chip's truncation. */
export function ChatReferenceChip({
name,
assetId,
asset,
previewSrc,
ariaLabel,
}: {
name: string;
assetId: string;
asset?: ChatAsset;
previewSrc?: string;
ariaLabel?: string;
}) {
const displayName = assetDisplayName(name);
return (
<span
className="cw-chat-reference"
data-preview-asset={assetId}
aria-label={ariaLabel}
title={displayName || undefined}
>
{previewSrc ? (
<img src={previewSrc} alt="" />
) : (
<CanvasIcon
name={kindOf(asset ?? ({ type: "text/plain" } as ChatAsset))}
size={18}
/>
)}
{displayName ? (
<span className="cw-chat-reference-label">{displayName}</span>
) : null}
</span>
);
}
1 change: 1 addition & 0 deletions src/canvas/reference-mentions.css
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@
height: 1.5em;
margin: 0 0.15em;
padding: 0 0.2em;
overflow: hidden;
border: 1px solid var(--chat-border, #ffffff20);
border-radius: 4px;
background: var(--chat-surface, #303034);
Expand Down
14 changes: 14 additions & 0 deletions tests/browser/assistant_reference_overflow.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8" />
<title>Assistant reference overflow test</title>
</head>
<body>
<div id="reference-overflow-test"></div>
<script
type="module"
src="/tests/browser/assistant_reference_overflow_fixture.tsx"
></script>
</body>
</html>
Loading
Loading