mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-16 13:04:08 +00:00
Add resolveApiKey to before_compact hook event
This commit is contained in:
parent
5aa53ded11
commit
43a5447a80
4 changed files with 9 additions and 0 deletions
|
|
@ -2,6 +2,10 @@
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
- **Compaction hook `resolveApiKey`**: The `before_compact` session event now includes `resolveApiKey` function to resolve API keys for any model (checks settings, OAuth, env vars). Useful for hooks that need to call different models during custom compaction.
|
||||
|
||||
## [0.27.5] - 2025-12-24
|
||||
|
||||
### Added
|
||||
|
|
|
|||
|
|
@ -184,6 +184,7 @@ For `before_compact` events, additional fields are available:
|
|||
- `event.tokensBefore`: Current context token count
|
||||
- `event.model`: Model to use for summarization
|
||||
- `event.apiKey`: API key for the model
|
||||
- `event.resolveApiKey`: Function to resolve API key for any model (checks settings, OAuth, env vars)
|
||||
- `event.customInstructions`: Optional custom focus for summary (from `/compact` command)
|
||||
|
||||
Return `{ compactionEntry }` to provide a custom summary instead of the default. The `compactionEntry` must have: `type: "compaction"`, `timestamp`, `summary`, `firstKeptEntryIndex` (from `cutPoint`), `tokensBefore`.
|
||||
|
|
|
|||
|
|
@ -772,6 +772,7 @@ export class AgentSession {
|
|||
customInstructions,
|
||||
model: this.model,
|
||||
apiKey,
|
||||
resolveApiKey: this._resolveApiKey,
|
||||
})) as SessionEventResult | undefined;
|
||||
|
||||
if (result?.cancel) {
|
||||
|
|
@ -922,6 +923,7 @@ export class AgentSession {
|
|||
customInstructions: undefined,
|
||||
model: this.model,
|
||||
apiKey,
|
||||
resolveApiKey: this._resolveApiKey,
|
||||
})) as SessionEventResult | undefined;
|
||||
|
||||
if (hookResult?.cancel) {
|
||||
|
|
|
|||
|
|
@ -135,6 +135,8 @@ export type SessionEvent =
|
|||
customInstructions?: string;
|
||||
model: Model<any>;
|
||||
apiKey: string;
|
||||
/** Resolve API key for any model (checks settings, OAuth, env vars) */
|
||||
resolveApiKey: (model: Model<any>) => Promise<string | undefined>;
|
||||
})
|
||||
| (SessionEventBase & {
|
||||
reason: "compact";
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue