mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 07:03:25 +00:00
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:
parent
28c0991281
commit
1e88c5e463
4 changed files with 18 additions and 0 deletions
|
|
@ -2,6 +2,10 @@
|
||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Added optional `metadata` field to `StreamOptions` for passing provider-specific metadata (e.g. Anthropic `user_id` for abuse tracking/rate limiting) ([#1384](https://github.com/badlogic/pi-mono/pull/1384) by [@7Sageer](https://github.com/7Sageer))
|
||||||
|
|
||||||
## [0.52.9] - 2026-02-08
|
## [0.52.9] - 2026-02-08
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
|
||||||
|
|
@ -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 (options?.toolChoice) {
|
||||||
if (typeof options.toolChoice === "string") {
|
if (typeof options.toolChoice === "string") {
|
||||||
params.tool_choice = { type: options.toolChoice };
|
params.tool_choice = { type: options.toolChoice };
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ export function buildBaseOptions(model: Model<Api>, options?: SimpleStreamOption
|
||||||
headers: options?.headers,
|
headers: options?.headers,
|
||||||
onPayload: options?.onPayload,
|
onPayload: options?.onPayload,
|
||||||
maxRetryDelayMs: options?.maxRetryDelayMs,
|
maxRetryDelayMs: options?.maxRetryDelayMs,
|
||||||
|
metadata: options?.metadata,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -87,6 +87,12 @@ export interface StreamOptions {
|
||||||
* Default: 60000 (60 seconds). Set to 0 to disable the cap.
|
* Default: 60000 (60 seconds). Set to 0 to disable the cap.
|
||||||
*/
|
*/
|
||||||
maxRetryDelayMs?: number;
|
maxRetryDelayMs?: number;
|
||||||
|
/**
|
||||||
|
* Optional metadata to include in API requests.
|
||||||
|
* Providers extract the fields they understand and ignore the rest.
|
||||||
|
* For example, Anthropic uses `user_id` for abuse tracking and rate limiting.
|
||||||
|
*/
|
||||||
|
metadata?: Record<string, unknown>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ProviderStreamOptions = StreamOptions & Record<string, unknown>;
|
export type ProviderStreamOptions = StreamOptions & Record<string, unknown>;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue