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

normalizeSystemPrompts.md

40 lines1.2 KB

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