Skip to content

Commit 5cebb73

Browse files
committed
A single read of an attached file names the file, with a file's icon
Found in the end-to-end run: a Bot that read only the end of a file made one read, drawn on a line of its own, and the line said "Read an attached file" with a wrench and no file. It now names the file the answer carries and draws a file, as the folded row does.
1 parent e7f3b28 commit 5cebb73

3 files changed

Lines changed: 47 additions & 6 deletions

File tree

‎app/src/components/channels/chat-transcript.tsx‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
} from "@openbot/shared/generate-image";
1818
import { answeredBy } from "@openbot/shared/handoff-markers";
1919
import { readBrief, readTaskReport } from "@openbot/shared/orchestration";
20+
import { READ_ATTACHMENT_TOOL } from "@openbot/shared/read-attachment";
2021
import { SEND_FILE_TOOL } from "@openbot/shared/send-file";
2122
import { SUBAGENT_TOOL } from "@openbot/shared/subagent";
2223
import {
@@ -196,6 +197,7 @@ import { TeamBotConsentCard } from "./team-bot-consent";
196197
import { ReplyToolbar } from "./telemetry-assistant-message";
197198
import {
198199
ActivityAppMarks,
200+
attachmentReadName,
199201
dropRepeatedAppCards,
200202
groupToolSteps,
201203
LiveConnectorStep,
@@ -2133,7 +2135,11 @@ export function ServerToolLine({
21332135
const detail =
21342136
(appId && named.detail === appId ? connectorName(appId) : named.detail) ??
21352137
folderStepSubject(name, args, folders) ??
2136-
ownToolSubject(name, args);
2138+
ownToolSubject(name, args) ??
2139+
// The attached file a read was of, by the name its answer carries.
2140+
(name === READ_ATTACHMENT_TOOL && result !== undefined
2141+
? attachmentReadName(asText(result))
2142+
: undefined);
21372143
/*
21382144
* A refusal is not a result, and must not read like one.
21392145
*

‎app/src/components/channels/tool-activity.tsx‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -626,13 +626,9 @@ function detailsOf(
626626
}
627627
if (name === READ_ATTACHMENT_TOOL) {
628628
// A part of a file attached to the conversation, named by the file's name the answer carries.
629-
const read = objectOf(answer);
630629
const id =
631630
typeof args.attachment_id === "string" ? args.attachment_id : step.id;
632-
const fileName =
633-
typeof read.name === "string" && read.name.trim()
634-
? read.name.trim()
635-
: undefined;
631+
const fileName = attachmentReadName(answer);
636632
return {
637633
...outcome,
638634
kind: "file",
@@ -711,6 +707,20 @@ function detailsOf(
711707
};
712708
}
713709

710+
/**
711+
* The name of the attached file a `read_attachment` step read part of, from the server's answer
712+
* (`{ attachment_id, name, offset, text, next_offset, total_length }`), or undefined while it runs or
713+
* when it was refused. One reading for a step on a line of its own and one folded with others.
714+
*/
715+
export function attachmentReadName(
716+
answer: string | undefined,
717+
): string | undefined {
718+
const read = objectOf(answer);
719+
return typeof read.name === "string" && read.name.trim()
720+
? read.name.trim()
721+
: undefined;
722+
}
723+
714724
/**
715725
* Which answer a `read_result_part` step read on in, and which part, in words: "Get transcript on
716726
* Fireflies, part 2 of 3". The call names the read by the tool's name the Bot was offered, which
@@ -1193,6 +1203,8 @@ function IconStack({ marks }: { marks: { kind: StepKind; appId?: string }[] }) {
11931203

11941204
/** The kind of step a call the server ran is, as `stepDetails` names it: research, an app, or one of ours. */
11951205
function serverStepKind(name: string): StepKind {
1206+
// A part of an attached file read: a file, as the folded row draws it.
1207+
if (name === READ_ATTACHMENT_TOOL) return "file";
11961208
if (!name.startsWith("mcp__")) return "tool";
11971209
const [, server = "", ...rest] = name.split("__");
11981210
return researchRoleOfTool(server, rest.join("__")) ?? "connector";

‎app/tests/attachment-read-steps.test.tsx‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { GlobalRegistrator } from "@happy-dom/global-registrator";
44
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
55
import { cleanup, fireEvent, render } from "@testing-library/react";
66
import { toVisibleChatItems } from "../src/components/channels/chat-messages";
7+
import { ServerToolLine } from "../src/components/channels/chat-transcript";
78
import {
89
groupToolSteps,
910
ToolActivity,
@@ -96,6 +97,28 @@ test("reads of one attached file are one row naming the file and its parts", ()
9697
expect(view.container.textContent).not.toContain("row,value");
9798
});
9899

100+
/*
101+
* FOUND IN THE END-TO-END RUN, Chromium: a Bot that read only the end of the file made one read,
102+
* drawn on a line of its own, and that line said "Read an attached file" with a wrench and no file.
103+
* It names the file and draws a file, as the folded row does.
104+
*/
105+
test("one read on a line of its own names the file it read", () => {
106+
const [, result] = readPart("solo", 450_000);
107+
const view = render(
108+
<QueryClientProvider client={new QueryClient()}>
109+
<ServerToolLine
110+
args={JSON.stringify({ attachment_id: FILE_ID, offset: 450_000 })}
111+
name="read_attachment"
112+
result={String((result as { content: string }).content)}
113+
/>
114+
</QueryClientProvider>,
115+
);
116+
const text = view.container.textContent ?? "";
117+
expect(text).toContain("Read an attached file");
118+
expect(text).toContain("survey-export.txt");
119+
expect(text).not.toContain("row,value");
120+
});
121+
99122
test("while a part is being read, the line says the Bot is reading an attached file", () => {
100123
const view = draw(
101124
[...readPart("a", 120_000), ...readPart("b", 170_000, false)],

0 commit comments

Comments
 (0)