Files
oh-my-pi/packages/coding-agent/src/modes/components/custom-message.ts
T
can1357 f1f6516056 refactor: reorganized exports and removed obsolete helper branches
- Removed export leakage by demoting many helper and const symbols to module-local scope.
- Renamed underscore-prefixed internals and cache fields, then updated related references and `satisfies never` checks.
- Deleted obsolete logic branches and helpers, including harmony-stream interruption flow and unused benchmark runtime helpers.
- Updated Biome config and manifests by broadening lint coverage and removing an unused `@napi-rs/cli` dev dependency.
- Adjusted tests and utilities to use renamed test helpers and remove redundant private test-only helpers/locals.
2026-05-14 04:36:19 +02:00

66 lines
1.6 KiB
TypeScript

import type { Component } from "@oh-my-pi/pi-tui";
import { Box, Container, Spacer } from "@oh-my-pi/pi-tui";
import type { MessageRenderer } from "../../extensibility/extensions/types";
import { theme } from "../../modes/theme/theme";
import type { CustomMessage } from "../../session/messages";
import { renderFramedMessage } from "./message-frame";
/**
* Component that renders a custom message entry from extensions.
* Uses distinct styling to differentiate from user messages.
*/
export class CustomMessageComponent extends Container {
#box: Box;
#customComponent?: Component;
#expanded = false;
constructor(
private readonly message: CustomMessage<unknown>,
private readonly customRenderer?: MessageRenderer,
) {
super();
this.addChild(new Spacer(1));
// Create box with custom background (used for default rendering)
this.#box = new Box(1, 1, t => theme.bg("customMessageBg", t));
this.#rebuild();
}
setExpanded(expanded: boolean): void {
if (this.#expanded !== expanded) {
this.#expanded = expanded;
this.#rebuild();
}
}
override invalidate(): void {
super.invalidate();
this.#rebuild();
}
#rebuild(): void {
if (this.#customComponent) {
this.removeChild(this.#customComponent);
this.#customComponent = undefined;
}
this.removeChild(this.#box);
const custom = renderFramedMessage({
message: this.message,
box: this.#box,
expanded: this.#expanded,
customRenderer: this.customRenderer,
// Extension messages render full content; no collapse-on-fold behaviour.
});
if (custom) {
this.#customComponent = custom;
this.addChild(custom);
} else {
this.addChild(this.#box);
}
}
}