mirror of
https://github.com/getcompanion-ai/co-mono.git
synced 2026-04-16 15:02:32 +00:00
Add CustomMessageEntry rendering infrastructure
- Add renderCustomMessage to HookAPI for registering custom renderers - Add CustomMessageRenderer type and CustomMessageRenderOptions - Store customMessageRenderers in LoadedHook - Add getCustomMessageRenderer(customType) to HookRunner - SessionContext.entries now aligned with messages (same length, corresponding indices) TUI can now correlate messages with their source entries to identify custom_message entries and use hook-provided renderers.
This commit is contained in:
parent
3ecaaa5937
commit
11a7845ceb
7 changed files with 83 additions and 10 deletions
|
|
@ -340,6 +340,7 @@ function createFactoryFromLoadedHook(loaded: LoadedHook): HookFactory {
|
|||
function createLoadedHooksFromDefinitions(definitions: Array<{ path?: string; factory: HookFactory }>): LoadedHook[] {
|
||||
return definitions.map((def) => {
|
||||
const handlers = new Map<string, Array<(...args: unknown[]) => Promise<unknown>>>();
|
||||
const customMessageRenderers = new Map<string, any>();
|
||||
let sendHandler: (text: string, attachments?: any[]) => void = () => {};
|
||||
|
||||
const api = {
|
||||
|
|
@ -351,6 +352,9 @@ function createLoadedHooksFromDefinitions(definitions: Array<{ path?: string; fa
|
|||
send: (text: string, attachments?: any[]) => {
|
||||
sendHandler(text, attachments);
|
||||
},
|
||||
renderCustomMessage: (customType: string, renderer: any) => {
|
||||
customMessageRenderers.set(customType, renderer);
|
||||
},
|
||||
};
|
||||
|
||||
def.factory(api as any);
|
||||
|
|
@ -359,6 +363,7 @@ function createLoadedHooksFromDefinitions(definitions: Array<{ path?: string; fa
|
|||
path: def.path ?? "<inline>",
|
||||
resolvedPath: def.path ?? "<inline>",
|
||||
handlers,
|
||||
customMessageRenderers,
|
||||
setSendHandler: (handler: (text: string, attachments?: any[]) => void) => {
|
||||
sendHandler = handler;
|
||||
},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue