Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.

next
ts 38 lines 1.7 KB
Raw
1 /**
2 * Makes command output repeatable before a model sees it.
3 *
4 * A fixture is matched against the conversation, so anything that differs
5 * between two runs of the same journey (a port, a temporary directory, a clock
6 * reading) would make a replay miss. The fake backend already fixes ids and
7 * timestamps; this removes what the machine adds.
8 */
9
10 import { SEEDED_AT, SEEDED_EXPIRY, type FakeComposio } from '@e2e-tests/cli-fake-backend';
11
12 /** Stable stand-ins for the fake's per-run URLs. */
13 export const SCRUBBED_BACKEND_URL = 'https://backend.composio.test';
14 export const SCRUBBED_DASHBOARD_URL = 'https://dashboard.composio.test';
15
16 const HEAD_CHARACTERS = 2500;
17 const TAIL_CHARACTERS = 1500;
18 const SEEDED_TIMESTAMPS = new Set([SEEDED_AT, SEEDED_EXPIRY]);
19
20 /** Keeps both ends: a parse error sits under a page of help, at the very end. */
21 const truncate = (text: string): string =>
22 text.length <= HEAD_CHARACTERS + TAIL_CHARACTERS
23 ? text
24 : `${text.slice(0, HEAD_CHARACTERS)}\n[... ${text.length - HEAD_CHARACTERS - TAIL_CHARACTERS} characters omitted ...]\n${text.slice(-TAIL_CHARACTERS)}`;
25
26 export const scrub = (text: string, fake: FakeComposio): string =>
27 truncate(
28 text
29 .replace(/\x1b\[[0-9;]*m/g, '')
30 .replaceAll(fake.docker.https, SCRUBBED_DASHBOARD_URL)
31 .replaceAll(fake.docker.http, SCRUBBED_BACKEND_URL)
32 .replace(/composio-run-artifacts-[A-Za-z0-9]+/g, 'composio-run-artifacts-SCRUBBED')
33 .replace(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d+)?Z/g, timestamp =>
34 SEEDED_TIMESTAMPS.has(timestamp) ? timestamp : '<timestamp>'
35 )
36 .replace(/\[\d{2}:\d{2}:\d{2}\.\d{3}\]/g, '[<time>]')
37 .replace(/composio-cli-\d{4}-\d{2}-\d{2}/g, 'composio-cli-<date>')
38 );