mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-19 00:05:24 +00:00
Add authHeader option and fix print mode error handling
- Add 'authHeader' boolean option to models.json provider config When true, adds 'Authorization: Bearer <apiKey>' to model headers Useful for providers requiring explicit auth headers (fixes #81) - Fix print mode (-p) silently failing on errors Now outputs error message to stderr and exits with code 1 when assistant message has stopReason of error/aborted
This commit is contained in:
parent
398591fdb0
commit
51195bc9fc
3 changed files with 24 additions and 2 deletions
|
|
@ -46,6 +46,7 @@ const ProviderConfigSchema = Type.Object({
|
|||
]),
|
||||
),
|
||||
headers: Type.Optional(Type.Record(Type.String(), Type.String())),
|
||||
authHeader: Type.Optional(Type.Boolean()),
|
||||
models: Type.Array(ModelDefinitionSchema),
|
||||
});
|
||||
|
||||
|
|
@ -177,9 +178,17 @@ function parseModels(config: ModelsConfig): Model<Api>[] {
|
|||
}
|
||||
|
||||
// Merge headers: provider headers are base, model headers override
|
||||
const headers =
|
||||
let headers =
|
||||
providerConfig.headers || modelDef.headers ? { ...providerConfig.headers, ...modelDef.headers } : undefined;
|
||||
|
||||
// If authHeader is true, add Authorization header with resolved API key
|
||||
if (providerConfig.authHeader) {
|
||||
const resolvedKey = resolveApiKey(providerConfig.apiKey);
|
||||
if (resolvedKey) {
|
||||
headers = { ...headers, Authorization: `Bearer ${resolvedKey}` };
|
||||
}
|
||||
}
|
||||
|
||||
models.push({
|
||||
id: modelDef.id,
|
||||
name: modelDef.name,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue