mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-26 14:15:10 +00:00
fix(plugins): expose effective context budget in hooks
Add optional context budget/source/reference metadata to plugin hook contexts plus llm_output and sanitized model_call_* hook events. Thread the existing resolved context-window info through Pi embedded runs, CLI harness runs, and Codex app-server hook emission so plugins can observe the effective budget after agent/model/config caps. Document the metadata and cover the CLI, Pi, Codex app-server, and model-call paths with focused tests. Fixes #64327.
This commit is contained in:
@@ -196,8 +196,20 @@ export type PluginHookAgentContext = {
|
||||
messageProvider?: string;
|
||||
trigger?: string;
|
||||
channelId?: string;
|
||||
/** Resolved effective context-token budget after model/config/agent caps. */
|
||||
contextTokenBudget?: number;
|
||||
/** Source that supplied the resolved context-token budget. */
|
||||
contextWindowSource?: PluginHookContextWindowSource;
|
||||
/** Native/configured reference window when a lower cap wins. */
|
||||
contextWindowReferenceTokens?: number;
|
||||
};
|
||||
|
||||
export type PluginHookContextWindowSource =
|
||||
| "model"
|
||||
| "modelsConfig"
|
||||
| "agentContextTokens"
|
||||
| "default";
|
||||
|
||||
export type PluginHookBeforeAgentReplyEvent = {
|
||||
cleanedBody: string;
|
||||
};
|
||||
@@ -229,6 +241,12 @@ export type PluginHookModelCallBaseEvent = {
|
||||
model: string;
|
||||
api?: string;
|
||||
transport?: string;
|
||||
/** Resolved effective context-token budget after model/config/agent caps. */
|
||||
contextTokenBudget?: number;
|
||||
/** Source that supplied the resolved context-token budget. */
|
||||
contextWindowSource?: PluginHookContextWindowSource;
|
||||
/** Native/configured reference window when a lower cap wins. */
|
||||
contextWindowReferenceTokens?: number;
|
||||
};
|
||||
|
||||
export type PluginHookModelCallStartedEvent = PluginHookModelCallBaseEvent;
|
||||
@@ -249,6 +267,12 @@ export type PluginHookLlmOutputEvent = {
|
||||
sessionId: string;
|
||||
provider: string;
|
||||
model: string;
|
||||
/** Resolved effective context-token budget after model/config/agent caps. */
|
||||
contextTokenBudget?: number;
|
||||
/** Source that supplied the resolved context-token budget. */
|
||||
contextWindowSource?: PluginHookContextWindowSource;
|
||||
/** Native/configured reference window when a lower cap wins. */
|
||||
contextWindowReferenceTokens?: number;
|
||||
/**
|
||||
* Fully resolved provider/model ref used for the call.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user