Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

normalizeSystemPrompts.md

39 lines1.1 KB

1---
2id: normalizeSystemPrompts
3title: normalizeSystemPrompts
4---
5​
6```ts
7function normalizeSystemPrompts<TMetadata>(prompts): NormalizedSystemPrompt<TMetadata>[];
8```
9​
10Defined in: packages/ai/src/system-prompts.ts:70
11​
12Normalise the public `systemPrompts` shape (`Array<string | { content, metadata? }>`)
13to a homogenous `Array<{ content, metadata? }>`. Adapters use this so they
14don't have to type-narrow string vs object inline.
15​
16Returns an empty array (never `undefined`) so callers can chain `.map` /
17`.join` without an extra null check.
18​
19Throws a `TypeError` (naming the offending index) if an object-form entry's
20`content` isn't a string. Public API boundary — callers reaching this
21function through `as any` / external JS would otherwise stream a literal
22`"undefined"` into the model's system prompt with no signal.
23​
24## Type Parameters
25​
26### TMetadata
27​
28`TMetadata` = `unknown`
29​
30## Parameters
31​
32### prompts
33​
34 \| readonly [`SystemPrompt`](../type-aliases/SystemPrompt.md)\<`unknown`\>[]
35 \| `undefined`
36​
37## Returns
38​
39[`NormalizedSystemPrompt`](../interfaces/NormalizedSystemPrompt.md)\<`TMetadata`\>[]