MCPcopy Create free account
hub / github.com/MatterAIOrg/OrbCode / sanitizeTitle

Function sanitizeTitle

src/auth/auth.ts:168–188  ·  view source on GitHub ↗

* Extract a clean title from potentially malformed input: a plain string, * a JSON object string ('{"title":"…"}'), or an object with a title field. * Ported from the extension's taskMetadata sanitizeTitle.

(raw: unknown)

Source from the content-addressed store, hash-verified

166 * Ported from the extension's taskMetadata sanitizeTitle.
167 */
168function sanitizeTitle(raw: unknown): string | undefined {
169 if (raw == null) return undefined;
170 if (typeof raw === "string") {
171 const trimmed = raw.trim();
172 if (!trimmed) return undefined;
173 if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
174 try {
175 const extracted = sanitizeTitle(JSON.parse(trimmed));
176 if (extracted) return extracted;
177 } catch {
178 // not JSON, use as plain string
179 }
180 }
181 return trimmed;
182 }
183 if (typeof raw === "object") {
184 const maybe = (raw as Record<string, unknown>)["title"];
185 if (maybe != null) return sanitizeTitle(maybe);
186 }
187 return undefined;
188}
189
190/**
191 * Fetch the backend-generated task title (GET /axoncode/meta/<taskId>).

Callers 1

fetchTaskTitleFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected