MCPcopy
hub / github.com/infinitered/reactotron / truncate

Function truncate

lib/reactotron-mcp/src/serialization.ts:16–24  ·  view source on GitHub ↗
(text: string, limit: number, guidance?: string)

Source from the content-addressed store, hash-verified

14 * that tells the LLM how to get more specific data.
15 */
16export function truncate(text: string, limit: number, guidance?: string): string {
17 if (text.length <= limit) return text
18
19 const suffix = guidance
20 ? `\n\n[TRUNCATED — response was ~${(text.length / 1000).toFixed(0)}K chars. ${guidance}]`
21 : `\n\n[TRUNCATED — response was ~${(text.length / 1000).toFixed(0)}K chars.]`
22
23 return text.slice(0, limit - suffix.length) + suffix
24}
25
26/**
27 * Serialize data as compact JSON, then truncate if it exceeds the limit.

Callers 2

safeSerializeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected