MCPcopy Create free account
hub / github.com/ShipSecAI/studio / createPreview

Function createPreview

frontend/src/utils/textPreview.ts:14–38  ·  view source on GitHub ↗
(
  message: string | undefined | null,
  options: PreviewOptions = {},
)

Source from the content-addressed store, hash-verified

12const DEFAULT_LINE_LIMIT = 4;
13
14export function createPreview(
15 message: string | undefined | null,
16 options: PreviewOptions = {},
17): PreviewResult {
18 if (!message) {
19 return { text: '', truncated: false };
20 }
21
22 const charLimit = options.charLimit ?? DEFAULT_CHAR_LIMIT;
23 const lineLimit = options.lineLimit ?? DEFAULT_LINE_LIMIT;
24
25 const lines = message.split('\n');
26
27 if (lines.length > lineLimit) {
28 const text = lines.slice(0, lineLimit).join('\n').trimEnd();
29 return { text, truncated: true };
30 }
31
32 if (message.length > charLimit) {
33 const text = message.slice(0, charLimit).replace(/\s+$/g, '');
34 return { text, truncated: true };
35 }
36
37 return { text: message, truncated: false };
38}

Callers 1

EventInspectorFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected