MCPcopy
hub / github.com/opactorai/Claudable / pickFirstString

Function pickFirstString

components/chat/ChatLog.tsx:111–137  ·  view source on GitHub ↗
(value: unknown)

Source from the content-addressed store, hash-verified

109};
110
111const pickFirstString = (value: unknown): string | undefined => {
112 if (typeof value === 'string') {
113 const trimmed = value.trim();
114 return trimmed.length > 0 ? trimmed : undefined;
115 }
116 if (typeof value === 'number' || typeof value === 'boolean') {
117 return String(value);
118 }
119 if (Array.isArray(value)) {
120 for (const entry of value) {
121 const candidate = pickFirstString(entry);
122 if (candidate) return candidate;
123 }
124 return undefined;
125 }
126 if (value && typeof value === 'object') {
127 const obj = value as Record<string, unknown>;
128 const nestedKeys = ['path', 'filepath', 'filePath', 'file_path', 'target', 'value'];
129 for (const key of nestedKeys) {
130 if (key in obj) {
131 const candidate = pickFirstString(obj[key]);
132 if (candidate) return candidate;
133 }
134 }
135 }
136 return undefined;
137};
138
139const extractPathFromInput = (input: unknown, action?: ToolAction): string | undefined => {
140 if (!input || typeof input !== 'object') return undefined;

Callers 6

extractPathFromInputFunction · 0.70
extractToolCallIdFunction · 0.70
addPartFunction · 0.70
processToolContentFunction · 0.70
shouldDisplayMessageFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected