mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-19 20:00:41 +00:00
feat(ai): add headers option to StreamOptions for custom HTTP headers
- Added headers field to base StreamOptions interface - Updated all providers to merge options.headers with defaults - Forward headers and onPayload through streamSimple/completeSimple - Bedrock not supported (uses AWS SDK auth)
This commit is contained in:
parent
20c7b5fed4
commit
d2be6486a4
10 changed files with 96 additions and 28 deletions
|
|
@ -123,7 +123,7 @@ export const streamOpenAICodexResponses: StreamFunction<"openai-codex-responses"
|
|||
const accountId = extractAccountId(apiKey);
|
||||
const body = buildRequestBody(model, context, options);
|
||||
options?.onPayload?.(body);
|
||||
const headers = buildHeaders(model.headers, accountId, apiKey, options?.sessionId);
|
||||
const headers = buildHeaders(model.headers, options?.headers, accountId, apiKey, options?.sessionId);
|
||||
const bodyJson = JSON.stringify(body);
|
||||
|
||||
// Fetch with retry logic for rate limits and transient errors
|
||||
|
|
@ -697,6 +697,7 @@ function extractAccountId(token: string): string {
|
|||
|
||||
function buildHeaders(
|
||||
initHeaders: Record<string, string> | undefined,
|
||||
additionalHeaders: Record<string, string> | undefined,
|
||||
accountId: string,
|
||||
token: string,
|
||||
sessionId?: string,
|
||||
|
|
@ -709,6 +710,9 @@ function buildHeaders(
|
|||
headers.set("User-Agent", `pi (${os.platform()} ${os.release()}; ${os.arch()})`);
|
||||
headers.set("accept", "text/event-stream");
|
||||
headers.set("content-type", "application/json");
|
||||
for (const [key, value] of Object.entries(additionalHeaders || {})) {
|
||||
headers.set(key, value);
|
||||
}
|
||||
|
||||
if (sessionId) {
|
||||
headers.set("session_id", sessionId);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue