diff --git a/packages/app/e2e/regression/session-timeline-tool-projection.spec.ts b/packages/app/e2e/regression/session-timeline-tool-projection.spec.ts index 99f1acf270b..b3e72041ef3 100644 --- a/packages/app/e2e/regression/session-timeline-tool-projection.spec.ts +++ b/packages/app/e2e/regression/session-timeline-tool-projection.spec.ts @@ -83,6 +83,17 @@ test("labels all web search provider variants", async ({ page }) => { await expect(page.getByRole("button", { name: /^Web Search/ })).toBeVisible() }) +test("labels V2 read tools from their path input", async ({ page }) => { + const id = "prt_read_path" + await setupTimeline(page, { + messages: [userMessage(), assistantMessage([toolPart(id, "read", "completed", { path: "src/a.ts" })])], + }) + + const group = page.locator(`[data-timeline-part-ids="${id}"]`) + await group.locator('[data-slot="collapsible-trigger"]').click() + await expect(group.locator('[data-slot="basic-tool-tool-subtitle"]')).toHaveText("a.ts") +}) + function questionInput() { return { questions: [{ header: "Stability", question: "Keep it stable?", options: [] }] } } diff --git a/packages/session-ui/src/components/message-part.tsx b/packages/session-ui/src/components/message-part.tsx index 9dd0c6edc0d..79dd0e63cc2 100644 --- a/packages/session-ui/src/components/message-part.tsx +++ b/packages/session-ui/src/components/message-part.tsx @@ -474,6 +474,11 @@ function webSearchProviderLabel(provider: unknown, i18n: ReturnType) { + if (typeof input.path === "string") return input.path + if (typeof input.filePath === "string") return input.filePath +} + export function getToolInfo( tool: string, input: any = {}, @@ -481,12 +486,14 @@ export function getToolInfo( ): ToolInfo { const i18n = useI18n() switch (tool) { - case "read": + case "read": { + const path = readToolPath(input) return { icon: "glasses", title: i18n.t("ui.tool.read"), - subtitle: input.filePath ? getFilename(input.filePath) : undefined, + subtitle: path ? getFilename(path) : undefined, } + } case "list": return { icon: "bullet-list", @@ -847,7 +854,7 @@ function contextToolDetail(part: ToolPart): string | undefined { function contextToolTrigger(part: ToolPart, i18n: ReturnType) { const input = (part.state.input ?? {}) as Record const path = typeof input.path === "string" ? input.path : "/" - const filePath = typeof input.filePath === "string" ? input.filePath : undefined + const filePath = readToolPath(input) const pattern = typeof input.pattern === "string" ? input.pattern : undefined const include = typeof input.include === "string" ? input.include : undefined const offset = typeof input.offset === "number" ? input.offset : undefined @@ -1793,7 +1800,7 @@ ToolRegistry.register({ icon="glasses" trigger={{ title: i18n.t("ui.tool.read"), - subtitle: props.input.filePath ? getFilename(props.input.filePath) : "", + subtitle: getFilename(readToolPath(props.input) ?? ""), args, }} />