MCPcopy Create free account
hub / github.com/boringstack-xyz/boringstack / parseDefaultHeaders

Function parseDefaultHeaders

apps/api/src/lib/ai/ai.utils.ts:35–61  ·  view source on GitHub ↗
(
  raw: string
)

Source from the content-addressed store, hash-verified

33 * OPENAI_DEFAULT_HEADERS='{"HTTP-Referer":"https://example.com","X-Title":"My App"}'
34 */
35export const parseDefaultHeaders = (
36 raw: string
37): Record<string, string> | undefined => {
38 if (raw === "") {
39 return undefined;
40 }
41
42 let parsed: unknown;
43
44 try {
45 parsed = JSON.parse(raw);
46 } catch {
47 warnInvalid("is not valid JSON");
48
49 return undefined;
50 }
51
52 if (!isStringRecord(parsed)) {
53 warnInvalid("is not a JSON object");
54
55 return undefined;
56 }
57
58 const entries = collectStringEntries(parsed);
59
60 return Object.keys(entries).length > 0 ? entries : undefined;
61};

Callers 2

buildOpenAIFunction · 0.90
ai.utils.test.tsFile · 0.90

Calls 3

warnInvalidFunction · 0.85
isStringRecordFunction · 0.85
collectStringEntriesFunction · 0.85

Tested by

no test coverage detected