MCPcopy Create free account
hub / github.com/CedarCopilot/cedar-OS / inputFormatter

Function inputFormatter

packages/cedar-os/src/utils/inputFormatter.ts:7–36  ·  view source on GitHub ↗
(content: JSONContent)

Source from the content-addressed store, hash-verified

5 * including handling of custom choice nodes (attrs.options/selectedOption).
6 */
7export function inputFormatter(content: JSONContent): string {
8 let result = '';
9
10 function walk(node: JSONContent) {
11 const anyNode = node as any;
12
13 // Extract text nodes
14 if (typeof anyNode.text === 'string') {
15 result += anyNode.text;
16 }
17
18 // Handle custom 'choice' nodes
19 if (anyNode.type === 'choice') {
20 const attrs = anyNode.attrs || {};
21 const options = Array.isArray(attrs.options) ? attrs.options : [];
22 const selected = attrs.selectedOption || options[0] || '';
23 if (typeof selected === 'string') {
24 result += selected;
25 }
26 }
27
28 // Recurse into children
29 if (Array.isArray(anyNode.content)) {
30 anyNode.content.forEach((child: JSONContent) => walk(child));
31 }
32 }
33
34 walk(content);
35 return result.trim();
36}

Callers

nothing calls this directly

Calls 1

walkFunction · 0.85

Tested by

no test coverage detected