mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-20 03:00:29 +00:00
Cleanup: unify HookMessage naming and simplify SessionContext
- Rename HookAppMessage to HookMessage, isHookAppMessage to isHookMessage - Remove entries array from SessionContext (use isHookMessage type guard instead) - HookMessage.content now accepts string directly (not just array) - Fix streamMessage type in AgentState (AppMessage, not Message) - Rename CustomMessageComponent to HookMessageComponent - Fix test hook to use pi.sendMessage
This commit is contained in:
parent
a2515cf43f
commit
204d27581b
13 changed files with 62 additions and 106 deletions
|
|
@ -27,7 +27,6 @@ export type {
|
|||
HookEvent,
|
||||
HookEventContext,
|
||||
HookFactory,
|
||||
HookMessage,
|
||||
HookMessageRenderer,
|
||||
HookMessageRenderOptions,
|
||||
HookUIContext,
|
||||
|
|
|
|||
|
|
@ -9,15 +9,9 @@ import * as path from "node:path";
|
|||
import { fileURLToPath } from "node:url";
|
||||
import { createJiti } from "jiti";
|
||||
import { getAgentDir } from "../../config.js";
|
||||
import type { HookMessage } from "../messages.js";
|
||||
import { execCommand } from "./runner.js";
|
||||
import type {
|
||||
ExecOptions,
|
||||
HookAPI,
|
||||
HookFactory,
|
||||
HookMessage,
|
||||
HookMessageRenderer,
|
||||
RegisteredCommand,
|
||||
} from "./types.js";
|
||||
import type { ExecOptions, HookAPI, HookFactory, HookMessageRenderer, RegisteredCommand } from "./types.js";
|
||||
|
||||
// Create require function to resolve module paths at runtime
|
||||
const require = createRequire(import.meta.url);
|
||||
|
|
@ -56,7 +50,10 @@ type HandlerFn = (...args: unknown[]) => Promise<unknown>;
|
|||
/**
|
||||
* Send message handler type for pi.sendMessage().
|
||||
*/
|
||||
export type SendMessageHandler = <T = unknown>(message: HookMessage<T>, triggerTurn?: boolean) => void;
|
||||
export type SendMessageHandler = <T = unknown>(
|
||||
message: Pick<HookMessage<T>, "customType" | "content" | "display" | "details">,
|
||||
triggerTurn?: boolean,
|
||||
) => void;
|
||||
|
||||
/**
|
||||
* Append entry handler type for pi.appendEntry().
|
||||
|
|
|
|||
|
|
@ -11,8 +11,9 @@ import type { Component } from "@mariozechner/pi-tui";
|
|||
import type { Theme } from "../../modes/interactive/theme/theme.js";
|
||||
import type { CompactionPreparation, CompactionResult } from "../compaction.js";
|
||||
import type { ExecOptions, ExecResult } from "../exec.js";
|
||||
import type { HookMessage } from "../messages.js";
|
||||
import type { ModelRegistry } from "../model-registry.js";
|
||||
import type { CompactionEntry, CustomMessageEntry, SessionManager } from "../session-manager.js";
|
||||
import type { CompactionEntry, SessionManager } from "../session-manager.js";
|
||||
import type { EditToolDetails } from "../tools/edit.js";
|
||||
import type {
|
||||
BashToolDetails,
|
||||
|
|
@ -380,14 +381,6 @@ export interface SessionEventResult {
|
|||
*/
|
||||
export type HookHandler<E, R = void> = (event: E, ctx: HookEventContext) => Promise<R>;
|
||||
|
||||
/**
|
||||
* Options passed to custom message renderers.
|
||||
*/
|
||||
/**
|
||||
* Message type for hooks to send. Creates CustomMessageEntry in the session.
|
||||
*/
|
||||
export type HookMessage<T = unknown> = Pick<CustomMessageEntry<T>, "customType" | "content" | "display" | "details">;
|
||||
|
||||
export interface HookMessageRenderOptions {
|
||||
/** Whether the view is expanded */
|
||||
expanded: boolean;
|
||||
|
|
@ -463,7 +456,10 @@ export interface HookAPI {
|
|||
* @param triggerTurn - If true and agent is idle, triggers a new LLM turn. Default: false.
|
||||
* If agent is streaming, message is queued and triggerTurn is ignored.
|
||||
*/
|
||||
sendMessage<T = unknown>(message: HookMessage<T>, triggerTurn?: boolean): void;
|
||||
sendMessage<T = unknown>(
|
||||
message: Pick<HookMessage<T>, "customType" | "content" | "display" | "details">,
|
||||
triggerTurn?: boolean,
|
||||
): void;
|
||||
|
||||
/**
|
||||
* Append a custom entry to the session for hook state persistence.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue