mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-17 07:03:25 +00:00
fix(hooks): fix ContextEventResult.messages type to AgentMessage[]
- Was incorrectly typed as Message[] which caused filtered messages to be ignored - Context event filter in plan-mode hook should now properly remove stale [PLAN MODE ACTIVE] messages
This commit is contained in:
parent
650d8f2615
commit
274d4a6247
2 changed files with 8 additions and 12 deletions
|
|
@ -293,19 +293,15 @@ export default function planModeHook(pi: HookAPI) {
|
||||||
|
|
||||||
// Filter out stale plan mode context messages from LLM context
|
// Filter out stale plan mode context messages from LLM context
|
||||||
// This ensures the agent only sees the CURRENT state (plan mode on/off)
|
// This ensures the agent only sees the CURRENT state (plan mode on/off)
|
||||||
(pi as any).on("context", async (event: { messages: Array<{ role: string; content: unknown }> }) => {
|
pi.on("context", async (event) => {
|
||||||
// Remove any previous plan-mode-context or plan-execution-context messages
|
// Only filter when NOT in plan mode (i.e., when executing)
|
||||||
// They'll be re-injected with current state via before_agent_start
|
if (planModeEnabled) return;
|
||||||
|
|
||||||
|
// Remove any previous plan-mode-context messages
|
||||||
const filtered = event.messages.filter((m) => {
|
const filtered = event.messages.filter((m) => {
|
||||||
if (m.role === "user" && Array.isArray(m.content)) {
|
if (m.role === "user" && Array.isArray(m.content)) {
|
||||||
// Check for our custom message types in user messages
|
const hasOldContext = m.content.some(
|
||||||
const hasOldContext = (m.content as Array<{ type: string; text?: string }>).some(
|
(c) => c.type === "text" && c.text.includes("[PLAN MODE ACTIVE]"),
|
||||||
(c) =>
|
|
||||||
c.type === "text" &&
|
|
||||||
c.text &&
|
|
||||||
(c.text.includes("[PLAN MODE ACTIVE]") ||
|
|
||||||
c.text.includes("[PLAN MODE DISABLED") ||
|
|
||||||
c.text.includes("[EXECUTING PLAN]")),
|
|
||||||
);
|
);
|
||||||
if (hasOldContext) return false;
|
if (hasOldContext) return false;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -577,7 +577,7 @@ export type HookEvent =
|
||||||
*/
|
*/
|
||||||
export interface ContextEventResult {
|
export interface ContextEventResult {
|
||||||
/** Modified messages to send instead of the original */
|
/** Modified messages to send instead of the original */
|
||||||
messages?: Message[];
|
messages?: AgentMessage[];
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue