aboutsummaryrefslogtreecommitdiff
path: root/src/domains
diff options
context:
space:
mode:
Diffstat (limited to 'src/domains')
-rw-r--r--src/domains/js.ts7
-rw-r--r--src/domains/network.ts6
-rw-r--r--src/domains/render.ts2
3 files changed, 3 insertions, 12 deletions
diff --git a/src/domains/js.ts b/src/domains/js.ts
index b43387c..d2588d0 100644
--- a/src/domains/js.ts
+++ b/src/domains/js.ts
@@ -6,6 +6,7 @@ import { Type } from "typebox";
import { Markdown, Text } from "@mariozechner/pi-tui";
import { getMarkdownTheme, keyHint } from "@mariozechner/pi-coding-agent";
import { type Result, err, ok } from "../util/result";
+import { formatBytes } from "../util/bytes";
import { defineBrowserTool, type ToolErr, type ToolOk } from "../util/tool";
import { evalJs } from "./cdp-call";
import { applyTruncation } from "../util/truncate";
@@ -13,12 +14,6 @@ import { asNumber, asRecord, asString, isRecord } from "../util/guards";
const COMPACT_PREVIEW_BYTES = 120;
-const formatBytes = (n: number): string => {
- if (n >= 1_048_576) return `${(n / 1_048_576).toFixed(1)} MB`;
- if (n >= 1024) return `${(n / 1024).toFixed(1)} KB`;
- return `${n} B`;
-};
-
// The AsyncFunction constructor is the documented way to compile user source; a plain `unknown` cast would lose the constructor signature, so this typed cast stays.
const AsyncFunction = Object.getPrototypeOf(async () => {}).constructor as
new (...args: ReadonlyArray<string>) => (...args: ReadonlyArray<unknown>) => Promise<unknown>;
diff --git a/src/domains/network.ts b/src/domains/network.ts
index 5520f40..aeb1aa6 100644
--- a/src/domains/network.ts
+++ b/src/domains/network.ts
@@ -2,6 +2,7 @@ import { Type } from "typebox";
import { Markdown, Text } from "@mariozechner/pi-tui";
import { getMarkdownTheme, keyHint } from "@mariozechner/pi-coding-agent";
import { type Result, err, ok } from "../util/result";
+import { formatBytes } from "../util/bytes";
import { defineBrowserTool, type ToolErr, type ToolOk } from "../util/tool";
import { cdpCall } from "./cdp-call";
import { applyTruncation } from "../util/truncate";
@@ -99,11 +100,6 @@ const renderNetworkMarkdown = (
const failed = records.filter((r) => r.failed || (r.status !== undefined && r.status >= 500)).length;
const totalBytes = records.reduce((s, r) => s + (r.responseBodySize ?? 0), 0);
- const formatBytes = (n: number): string => {
- if (n >= 1_048_576) return `${(n / 1_048_576).toFixed(1)} MB`;
- if (n >= 1024) return `${(n / 1024).toFixed(1)} KB`;
- return `${n} B`;
- };
const showWindow = (() => {
const finished = records.filter((r) => r.durationMs !== undefined);
if (finished.length === 0) return "";
diff --git a/src/domains/render.ts b/src/domains/render.ts
index 3f7f0dc..2f8d07f 100644
--- a/src/domains/render.ts
+++ b/src/domains/render.ts
@@ -6,7 +6,7 @@ import { isRecord } from "../util/guards";
const COMPACT_PREVIEW_LINES = 6;
-export type ExpandableText = {
+type ExpandableText = {
readonly summary: string;
readonly body: string;
readonly fullOutputPath?: string;