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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,12 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged.
`COMPUTER_MEMORY_HIGH_PERCENT=0` and `COMPUTER_TAB_IDLE_MS=0` (Helm: `computers.memoryHighPercent`
and `computers.tabIdleMs`) keep the old behaviour.

### An approval cuts a long value between characters

An approval shows what a Bot is about to type, write or send, cut to 2,000 characters, and each field
on the OpenTag card is cut to 300. When the cut landed inside an emoji, the approval showed a "�"
before the "…". The cut now drops the half character instead.

### A computer closes browsers nobody is using when its memory runs high

A computer runs one browser for each Bot that is browsing, and the only limits were a count and half
Expand Down
3 changes: 2 additions & 1 deletion server/src/approvals/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
withApprovalContext,
} from "@openbot/toolkit/continuation";
import type { AuditInitiator } from "../audit";
import { cutAtCodeUnits } from "../channels/text";

/** `handled` answers a hand-off: the person did it themselves, so it is never executed for them. */
export type ApprovalDecision =
Expand Down Expand Up @@ -374,7 +375,7 @@ export function approvalPreview(args: unknown, depth = 0): unknown {
]),
);
if (typeof args === "string")
return (args.length > 2000 ? `${args.slice(0, 1999)}…` : args)
return (args.length > 2000 ? `${cutAtCodeUnits(args, 1999)}…` : args)
.replace(
/((?:password|token|secret|api[_-]?key)\s*[=:]\s*)[^\s;]+/gi,
"$1[private value]",
Expand Down
3 changes: 2 additions & 1 deletion server/src/delivery/opentag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
import { timingSafeEqual } from "node:crypto";
import { z } from "zod";
import { cutAtCodeUnits } from "../channels/text";
import { DELIVERY_REQUEST_TIMEOUT_MS } from "../timeouts";
import {
type BindingTransport,
Expand Down Expand Up @@ -391,7 +392,7 @@ export function approvalFields(preview: unknown) {
}
function clip(value: string | undefined, max = 300) {
const text = value ?? "";
return text.length <= max ? text : `${text.slice(0, max - 1)}…`;
return text.length <= max ? text : `${cutAtCodeUnits(text, max - 1)}…`;
}

/** Minimal AG-UI SSE writer: `data: <event>\n\n` per event, as `@ag-ui/client`'s parser reads it. */
Expand Down
20 changes: 20 additions & 0 deletions server/tests/approvals.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,26 @@ test("an approval preview shows what will be typed, written or sent, and still h
});
});

test("an approval preview cuts a long value between characters, not inside an emoji", async () => {
const { approvalPreview } = await import("../src/approvals/types");
const { approvalFields } = await import("../src/delivery/opentag");
const hasLoneSurrogate = (text: string) =>
/[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?<![\uD800-\uDBFF])[\uDC00-\uDFFF]/.test(
text,
);
// Each cut lands between the two halves of the emoji that follows the letters.
const long = `${"a".repeat(1998)}😀${"b".repeat(100)}`;
const preview = approvalPreview(long) as string;
expect(hasLoneSurrogate(preview)).toBe(false);
expect(preview).toBe(`${"a".repeat(1998)}…`);

const field = approvalFields({
text: `${"a".repeat(298)}😀${"b".repeat(10)}`,
});
expect(hasLoneSurrogate(field[0]?.value ?? "")).toBe(false);
expect(field[0]?.value).toBe(`${"a".repeat(298)}…`);
});

test("an approved action interrupted before its result was saved continues the conversation once, without repeating", async () => {
const store = storeFixture();
const service = serviceModule.createApprovalService(store);
Expand Down