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
4 changes: 4 additions & 0 deletions api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32242,6 +32242,9 @@ components:
description: 'Whether this OpenBot keeps the Windows computers it makes for people (listWindowsComputers and the operations beside it): true even while it can''t make one right now, which the list''s creation says. Absent or false, those operations answer 404, so an app shows nothing about them and doesn''t ask.'
attachmentLimits:
$ref: '#/components/schemas/AttachmentLimits'
attachmentsReadWhole:
type: boolean
description: Whether a Bot can read the whole of an attached text file or document, page by page, past the first 120000 characters it is shown with the message. Absent or false, as from an older OpenBot, a Bot reads only those first 120000 characters.
api:
type: array
description: 'The API versions this OpenBot serves, by major, such as v2. An app that speaks none of them can''t use it: when they are all newer than the app''s, the app needs an update; when they are all older, this OpenBot does. Absent from a release before it was published, which serves v2.'
Expand Down Expand Up @@ -60463,6 +60466,7 @@ components:
imageBytes: 104857600
documentBytes: 104857600
fileBytes: 104857600
attachmentsReadWhole: true
api:
- v2
minimumClients:
Expand Down
8 changes: 8 additions & 0 deletions api/openapi/admin-settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1478,6 +1478,13 @@ components:
shows nothing about them and doesn't ask.
attachmentLimits:
$ref: '#/components/schemas/AttachmentLimits'
attachmentsReadWhole:
type: boolean
description: >-
Whether a Bot can read the whole of an attached text file or
document, page by page, past the first 120000 characters it is
shown with the message. Absent or false, as from an older OpenBot,
a Bot reads only those first 120000 characters.
api:
type: array
description: >-
Expand Down Expand Up @@ -2784,6 +2791,7 @@ components:
imageBytes: 104857600
documentBytes: 104857600
fileBytes: 104857600
attachmentsReadWhole: true
api: [v2]
minimumClients:
desktop: 1.2.0
Expand Down
8 changes: 7 additions & 1 deletion app/src/components/channels/chat-transcript.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
} from "@openbot/shared/generate-image";
import { answeredBy } from "@openbot/shared/handoff-markers";
import { readBrief, readTaskReport } from "@openbot/shared/orchestration";
import { READ_ATTACHMENT_TOOL } from "@openbot/shared/read-attachment";
import { SEND_FILE_TOOL } from "@openbot/shared/send-file";
import { SUBAGENT_TOOL } from "@openbot/shared/subagent";
import {
Expand Down Expand Up @@ -196,6 +197,7 @@ import { TeamBotConsentCard } from "./team-bot-consent";
import { ReplyToolbar } from "./telemetry-assistant-message";
import {
ActivityAppMarks,
attachmentReadName,
dropRepeatedAppCards,
groupToolSteps,
LiveConnectorStep,
Expand Down Expand Up @@ -2133,7 +2135,11 @@ export function ServerToolLine({
const detail =
(appId && named.detail === appId ? connectorName(appId) : named.detail) ??
folderStepSubject(name, args, folders) ??
ownToolSubject(name, args);
ownToolSubject(name, args) ??
// The attached file a read was of, by the name its answer carries.
(name === READ_ATTACHMENT_TOOL && result !== undefined
? attachmentReadName(asText(result))
: undefined);
/*
* A refusal is not a result, and must not read like one.
*
Expand Down
9 changes: 8 additions & 1 deletion app/src/components/channels/composer/composer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -557,6 +557,8 @@ export function Composer({
* would never arrive. Every upload refusal in the app comes through here.
*/
const limits = attachmentLimits?.limits ?? DEFAULT_ATTACHMENT_LIMITS;
// Whether the Bot can read a large text file to its end: then nothing on the tile warns it is cut.
const readsWhole = attachmentLimits?.readsWhole === true;
/*
* A ref, so the callbacks below that report a refusal keep their identity (the SDK config is
* rebuilt from them) while still reaching the latest way to ask again.
Expand Down Expand Up @@ -1465,14 +1467,19 @@ export function Composer({
* NOT FOR A DOCUMENT. A PDF's bytes are mostly fonts and layout, and an Office file's are
* compressed, so its size says nothing about how many characters of text it holds, and a
* one-page invoice would be warned about.
*
* AND NOT ON A SERVER WHOSE BOTS READ THE WHOLE FILE (`attachmentsReadWhole`). The Bot is
* shown the first part with the message and reads the rest page by page when it needs it,
* so the file is not cut and a warning saying it may be would be wrong.
*/
mayTruncate:
!readsWhole &&
attachment.status !== "uploading" &&
attachment.size !== undefined &&
!stagedIsDocument(attachment) &&
mayBeTruncatedForModel(attachment.size),
})),
[staged],
[staged, readsWhole],
);

const isBusy = pending || isSubmitting;
Expand Down
71 changes: 70 additions & 1 deletion app/src/components/channels/tool-activity.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
readConnectPrompt,
SHOW_APP_ACCESS_TOOL,
} from "@openbot/shared/connect-prompt";
import { READ_ATTACHMENT_TOOL } from "@openbot/shared/read-attachment";
import {
READ_RESULT_PART,
withoutPartNote,
Expand Down Expand Up @@ -416,6 +417,12 @@ export type StepDetails = {
* has drawn a run of them as one row. Unset for every other step.
*/
rereads?: number;
/**
* The attached file a step read part of, by its id, and how many parts: one for a single read,
* more once `foldRereads` has drawn a run of reads of the same file as one row. Unset for every
* other step.
*/
attachment?: { id: string; name?: string; parts: number };
/** A command's terminal block, which its row opens to. See `commandCall`. */
terminal?: ReturnType<typeof commandCall>;
/** A subtask's own facts, which its row reads to find and draw the steps it took. */
Expand Down Expand Up @@ -617,6 +624,22 @@ function detailsOf(
: { kind: "tool" }),
};
}
if (name === READ_ATTACHMENT_TOOL) {
// A part of a file attached to the conversation, named by the file's name the answer carries.
const id =
typeof args.attachment_id === "string" ? args.attachment_id : step.id;
const fileName = attachmentReadName(answer);
return {
...outcome,
kind: "file",
label:
(refused ? ownToolAttempt(name) : null) ??
readToolName(name, outcome.pending).label,
...(fileName ? { detail: fileName } : {}),
attachment: { id, ...(fileName ? { name: fileName } : {}), parts: 1 },
pages: 0,
};
}
if (!name.startsWith("mcp__"))
return {
...outcome,
Expand Down Expand Up @@ -684,6 +707,20 @@ function detailsOf(
};
}

/**
* The name of the attached file a `read_attachment` step read part of, from the server's answer
* (`{ attachment_id, name, offset, text, next_offset, total_length }`), or undefined while it runs or
* when it was refused. One reading for a step on a line of its own and one folded with others.
*/
export function attachmentReadName(
answer: string | undefined,
): string | undefined {
const read = objectOf(answer);
return typeof read.name === "string" && read.name.trim()
? read.name.trim()
: undefined;
}

/**
* Which answer a `read_result_part` step read on in, and which part, in words: "Get transcript on
* Fireflies, part 2 of 3". The call names the read by the tool's name the Bot was offered, which
Expand Down Expand Up @@ -907,6 +944,10 @@ function rereadsPhrase(count: number, running: boolean): string {
* it read back was for the model), so the one row stands for all of them. Only rereads next to each
* other join: any other step between them ends the run. One that was blocked, didn't work or was cut
* off keeps its own row, so its status still reads beside it.
*
* A run of reads of one attached file is one row the same way: "Read an attached file", beside it
* "notes.txt, in 8 parts". A Bot reads a large file part by part, and each part is not news to the
* person, who attached the file.
*/
export function foldRereads(steps: readonly StepDetails[]): StepDetails[] {
const folded: StepDetails[] = [];
Expand All @@ -915,8 +956,31 @@ export function foldRereads(steps: readonly StepDetails[]): StepDetails[] {
!step.failed &&
!step.refused &&
!step.interrupted;
const readsOfOneFile = (last: StepDetails, step: StepDetails) =>
last.attachment !== undefined &&
step.attachment?.id === last.attachment.id &&
[last, step].every(
(read) => !read.failed && !read.refused && !read.interrupted,
);
for (const step of steps) {
const last = folded.at(-1);
if (last && step.attachment && readsOfOneFile(last, step)) {
const parts = (last.attachment?.parts ?? 1) + step.attachment.parts;
const name = step.attachment.name ?? last.attachment?.name;
const pending = last.pending || step.pending;
folded[folded.length - 1] = {
...last,
label: readToolName(READ_ATTACHMENT_TOOL, pending).label,
...(name ? { detail: `${name}, in ${parts} parts` } : {}),
pending,
attachment: {
id: step.attachment.id,
...(name ? { name } : {}),
parts,
},
};
continue;
}
if (!last || !joins(step) || !joins(last)) {
folded.push(step);
continue;
Expand Down Expand Up @@ -951,7 +1015,10 @@ export function summarise(all: readonly StepDetails[]): string {
const of = (kind: StepKind) => steps.filter((step) => step.kind === kind);
const phrases: string[] = [];
// Claude Code's own words for a run of reads and searches.
const files = of("file").length;
// An attached file read in parts is one file read, however many parts it took.
const files = new Set(
of("file").map((step) => step.attachment?.id ?? step.id),
).size;
if (files) phrases.push(`read ${plural(files, "file", "files")}`);
const patterns = of("pattern").length;
if (patterns)
Expand Down Expand Up @@ -1136,6 +1203,8 @@ function IconStack({ marks }: { marks: { kind: StepKind; appId?: string }[] }) {

/** The kind of step a call the server ran is, as `stepDetails` names it: research, an app, or one of ours. */
function serverStepKind(name: string): StepKind {
// A part of an attached file read: a file, as the folded row draws it.
if (name === READ_ATTACHMENT_TOOL) return "file";
if (!name.startsWith("mcp__")) return "tool";
const [, server = "", ...rest] = name.split("__");
return researchRoleOfTool(server, rest.join("__")) ?? "connector";
Expand Down
2 changes: 2 additions & 0 deletions app/src/lib/api/generated/model/deployment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ export interface Deployment {
/** Whether this OpenBot keeps the Windows computers it makes for people (listWindowsComputers and the operations beside it): true even while it can't make one right now, which the list's creation says. Absent or false, those operations answer 404, so an app shows nothing about them and doesn't ask. */
managedWindowsComputers?: boolean;
attachmentLimits?: AttachmentLimits;
/** Whether a Bot can read the whole of an attached text file or document, page by page, past the first 120000 characters it is shown with the message. Absent or false, as from an older OpenBot, a Bot reads only those first 120000 characters. */
attachmentsReadWhole?: boolean;
/**
* The API versions this OpenBot serves, by major, such as v2. An app that speaks none of them can't use it: when they are all newer than the app's, the app needs an update; when they are all older, this OpenBot does. Absent from a release before it was published, which serves v2.
* @minItems 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export const getGetDeploymentResponseMock = (): Deployment => ({
documentBytes: 104857600,
fileBytes: 104857600,
},
attachmentsReadWhole: true,
api: ["v2"],
minimumClients: { desktop: "1.2.0" },
launcherApi: 1,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ export const GetDeploymentResponse = zod
.describe(
"How large a file attached to a message may be, by kind, in bytes. An upload over its kind's limit is refused. Absent, as from an older OpenBot, the limits are 8388608 for an image or a document (a PDF, or a Word, Excel or PowerPoint file) and 1048576 for any other file. The limits can rise while OpenBot runs, so a client reads them again rather than keeping them for good. What a Bot's model is shown of a large file is a separate matter: the file is kept and can be downloaded whatever the model can read of it.",
),
attachmentsReadWhole: zod
.boolean()
.optional()
.describe(
"Whether a Bot can read the whole of an attached text file or document, page by page, past the first 120000 characters it is shown with the message. Absent or false, as from an older OpenBot, a Bot reads only those first 120000 characters.",
),
api: zod
.array(zod.string().regex(getDeploymentResponseApiItemRegExp))
.min(1)
Expand Down
24 changes: 19 additions & 5 deletions app/src/lib/deployment/queries.ts
Original file line number Diff line number Diff line change
Expand Up @@ -263,18 +263,25 @@ export function deploymentCompatibilityQueryOptions(
*
* Absent reads as today's 8MB and 1MB (`attachmentLimitsFrom`): an older server publishes nothing
* and takes exactly those, so assuming more would pass files it then refuses.
*
* And whether a Bot reads the whole of a large text file (`attachmentsReadWhole`), read with them
* because it too changes when the server is upgraded. Absent is no: an older server hands a Bot the
* first 120,000 characters and nothing more, and the composer keeps warning that a file may be cut.
*/
export function attachmentLimitsQueryOptions() {
return queryOptions({
queryKey: deploymentKeys.attachmentLimits(),
staleTime: 60_000,
refetchOnWindowFocus: true,
queryFn: async ({ signal }): Promise<AttachmentLimits> => {
queryFn: async ({ signal }): Promise<AttachmentReading> => {
const body = await readDeployment({
signal,
fallback: "Couldn't load how large a file may be.",
});
return attachmentLimitsFrom(body.attachmentLimits);
return {
limits: attachmentLimitsFrom(body.attachmentLimits),
readsWhole: body.attachmentsReadWhole === true,
};
},
});
}
Expand Down Expand Up @@ -303,9 +310,15 @@ export function desktopSignInsQueryOptions() {
});
}

/** The limits a composer screens a pick against, and how it asks for them again. */
export type ComposerAttachmentLimits = {
/** What a server says about attached files: how large each may be, and how much of one a Bot reads. */
export type AttachmentReading = {
limits: AttachmentLimits;
/** Whether a Bot can read the whole of a text file past the part it is first shown. */
readsWhole: boolean;
};

/** The limits a composer screens a pick against, and how it asks for them again. */
export type ComposerAttachmentLimits = AttachmentReading & {
/** Read the limits again, as after a refusal: the refusal may be the first sign they changed. */
refresh: () => void;
};
Expand All @@ -320,7 +333,8 @@ export function useAttachmentLimits(): ComposerAttachmentLimits {
const { refetch } = query;
return useMemo(
() => ({
limits: query.data ?? DEFAULT_ATTACHMENT_LIMITS,
limits: query.data?.limits ?? DEFAULT_ATTACHMENT_LIMITS,
readsWhole: query.data?.readsWhole ?? false,
refresh: () => void refetch(),
}),
[query.data, refetch],
Expand Down
Loading
Loading