타입 별칭: SystemPrompt<TMetadata>
type SystemPrompt<TMetadata> =
| string
| {
content: string;
metadata?: TMetadata;
};
정의 위치: packages/ai/src/system-prompts.ts:39
chat({ systemPrompts: [...] })의 단일 항목입니다.
일반 문자열(일반적인 경우) 또는 프로바이더가 프롬프트에 타입이 지정된 메타데이터를 연결할 수 있는 구조화된 객체를 허용합니다. 예를 들어 프롬프트 캐싱을 위한 Anthropic의 cache_control, 향후 Gemini의 프롬프트별 안전성 재정의 등이 있습니다.
채팅 호출 위치에서 metadata는 어댑터가 다음을 통해 narrowing합니다.
~types['systemPromptMetadata']. 이를 선언하지 않는 프로바이더는 기본값 never를 상속하므로 필드에 의미 있는 값이 들어갈 수 없습니다. TS는 해당 위치에서 undefined만 허용하며, JS / as any를 통해 어댑터에 도달한 프로바이더 외부 메타데이터는 자동으로 삭제되고 wire에 기록되지 않습니다. 타입 안전한 프로바이더별 메타데이터는 프로바이더의 <Provider>SystemPromptMetadata 인터페이스(예: AnthropicSystemPromptMetadata)를 참조하세요.
타입 매개변수
TMetadata
TMetadata = unknown
예시
// The 90% case — plain strings work everywhere.
systemPrompts: ['Be concise.', 'Cite sources.']
// Provider-specific metadata via the object form. No `satisfies` cast
// is needed — the adapter narrows the `metadata` field's type at the
// call site so users get autocomplete and structural checking
// automatically.
import { anthropicText } from '@tanstack/ai-anthropic'
chat({
adapter: anthropicText(),
systemPrompts: [
{
content: 'Stable instructions — cache me.',
metadata: { cache_control: { type: 'ephemeral' } },
},
'Volatile per-request instruction.',
],
})