feat(ai): add generic metadata field to StreamOptions, closes #1384
Add metadata?: Record<string, unknown> to StreamOptions so providers can extract fields they understand. Anthropic provider extracts user_id for abuse tracking and rate limiting. Other providers ignore it. Based on #1384 by @7Sageer, reworked to use a generic type instead of Anthropic-specific typing on the base interface.
This commit is contained in:
@@ -594,6 +594,13 @@ function buildParams(
|
||||
}
|
||||
}
|
||||
|
||||
if (options?.metadata) {
|
||||
const userId = options.metadata.user_id;
|
||||
if (typeof userId === "string") {
|
||||
params.metadata = { user_id: userId };
|
||||
}
|
||||
}
|
||||
|
||||
if (options?.toolChoice) {
|
||||
if (typeof options.toolChoice === "string") {
|
||||
params.tool_choice = { type: options.toolChoice };
|
||||
|
||||
Reference in New Issue
Block a user