mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-20 16:05:11 +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
|
|
@ -6,8 +6,13 @@
|
||||||
|
|
||||||
- **Compaction UI**: Simplified collapsed compaction indicator to show warning-colored text with token count instead of styled banner. Removed redundant success message after compaction. ([#108](https://github.com/badlogic/pi-mono/issues/108))
|
- **Compaction UI**: Simplified collapsed compaction indicator to show warning-colored text with token count instead of styled banner. Removed redundant success message after compaction. ([#108](https://github.com/badlogic/pi-mono/issues/108))
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- **Print mode error handling**: `-p` flag now outputs error messages and exits with code 1 when requests fail, instead of silently producing no output.
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|
||||||
|
- **`authHeader` option in models.json**: Custom providers can set `"authHeader": true` to automatically add `Authorization: Bearer <apiKey>` header. Useful for providers that require explicit auth headers. ([#81](https://github.com/badlogic/pi-mono/issues/81))
|
||||||
- **`--append-system-prompt` Flag**: Append additional text or file contents to the system prompt. Supports both inline text and file paths. Complements `--system-prompt` for layering custom instructions without replacing the base system prompt. ([#114](https://github.com/badlogic/pi-mono/pull/114) by [@markusylisiurunen](https://github.com/markusylisiurunen))
|
- **`--append-system-prompt` Flag**: Append additional text or file contents to the system prompt. Supports both inline text and file paths. Complements `--system-prompt` for layering custom instructions without replacing the base system prompt. ([#114](https://github.com/badlogic/pi-mono/pull/114) by [@markusylisiurunen](https://github.com/markusylisiurunen))
|
||||||
- **Thinking Block Toggle**: Added `Ctrl+T` shortcut to toggle visibility of LLM thinking blocks. When toggled off, shows a static "Thinking..." label instead of full content. Useful for reducing visual clutter during long conversations. ([#113](https://github.com/badlogic/pi-mono/pull/113) by [@markusylisiurunen](https://github.com/markusylisiurunen))
|
- **Thinking Block Toggle**: Added `Ctrl+T` shortcut to toggle visibility of LLM thinking blocks. When toggled off, shows a static "Thinking..." label instead of full content. Useful for reducing visual clutter during long conversations. ([#113](https://github.com/badlogic/pi-mono/pull/113) by [@markusylisiurunen](https://github.com/markusylisiurunen))
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -817,7 +817,15 @@ async function runSingleShotMode(
|
||||||
if (mode === "text") {
|
if (mode === "text") {
|
||||||
const lastMessage = agent.state.messages[agent.state.messages.length - 1];
|
const lastMessage = agent.state.messages[agent.state.messages.length - 1];
|
||||||
if (lastMessage.role === "assistant") {
|
if (lastMessage.role === "assistant") {
|
||||||
for (const content of lastMessage.content) {
|
const assistantMsg = lastMessage as AssistantMessage;
|
||||||
|
|
||||||
|
// Check for error/aborted and output error message
|
||||||
|
if (assistantMsg.stopReason === "error" || assistantMsg.stopReason === "aborted") {
|
||||||
|
console.error(assistantMsg.errorMessage || `Request ${assistantMsg.stopReason}`);
|
||||||
|
process.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const content of assistantMsg.content) {
|
||||||
if (content.type === "text") {
|
if (content.type === "text") {
|
||||||
console.log(content.text);
|
console.log(content.text);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -46,6 +46,7 @@ const ProviderConfigSchema = Type.Object({
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
headers: Type.Optional(Type.Record(Type.String(), Type.String())),
|
headers: Type.Optional(Type.Record(Type.String(), Type.String())),
|
||||||
|
authHeader: Type.Optional(Type.Boolean()),
|
||||||
models: Type.Array(ModelDefinitionSchema),
|
models: Type.Array(ModelDefinitionSchema),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -177,9 +178,17 @@ function parseModels(config: ModelsConfig): Model<Api>[] {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Merge headers: provider headers are base, model headers override
|
// Merge headers: provider headers are base, model headers override
|
||||||
const headers =
|
let headers =
|
||||||
providerConfig.headers || modelDef.headers ? { ...providerConfig.headers, ...modelDef.headers } : undefined;
|
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({
|
models.push({
|
||||||
id: modelDef.id,
|
id: modelDef.id,
|
||||||
name: modelDef.name,
|
name: modelDef.name,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue