UNPKG

@adonis-agora/agent

Version:

Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.

101 lines • 5.32 kB
import type { UIMessage } from 'ai'; import React from 'react'; import type { AnyToolUIPart, MessageUsageInfo, TranscriptFile, TranscriptUiBlock } from '../transcript/model.js'; import { type EditSubmitInput, type MessageActionInput, type TranscriptItem } from '../transcript/use-chat-transcript.js'; export type { AnyToolUIPart, MessageUsageInfo } from '../transcript/model.js'; export { formatRelativeTime } from '../transcript/model.js'; export type RenderToolPartFn = (part: AnyToolUIPart, key: string) => React.ReactNode; /** Render a run of consecutive tool parts as one block (e.g. a collapsible tool group). */ export type RenderToolGroupFn = (parts: AnyToolUIPart[], key: string) => React.ReactNode; /** Render a message's text — pass a markdown renderer (e.g. `AgentMarkdown`) here if desired. */ export type RenderTextFn = (text: string, ctx: { isStreaming: boolean; }) => React.ReactNode; /** Render a run of files — attachments on a user turn, or files the model produced. */ export type RenderFilesFn = (files: TranscriptFile[]) => React.ReactNode; /** * Render a component the server pushed into the message — look `block.component` up in your own * registry. Omitted → drawn by the enclosing `<GenuiProvider>` (`/genui`) if there is one, else not * drawn (there is no sensible default for an app's own component). */ export type RenderUiFn = (block: TranscriptUiBlock) => React.ReactNode; /** Render the body of a reasoning run; the disclosure toggle around it stays this component's. */ export type RenderReasoningFn = (text: string, ctx: { isStreaming: boolean; isOpen: boolean; }) => React.ReactNode; export interface MessageItemClassNames { root?: string; /** Resolved per role so user/assistant/system bubbles can differ. */ byRole?: Partial<Record<UIMessage['role'], string>>; text?: string; /** The action row under the bubble (copy / fork / regenerate / usage / timestamp). */ actions?: string; actionButton?: string; usage?: string; timestamp?: string; editTextarea?: string; editActions?: string; reasoning?: string; reasoningToggle?: string; reasoningText?: string; files?: string; file?: string; fileImage?: string; } interface MessageRenderSlots { renderToolPart?: RenderToolPartFn; /** Takes precedence over `renderToolPart` for a run of consecutive tool parts. */ renderToolGroup?: RenderToolGroupFn; renderText?: RenderTextFn; renderReasoning?: RenderReasoningFn; /** Draw files yourself — a gallery, a viewer. Omitted → images inline, everything else a link. */ renderFiles?: RenderFilesFn; /** * Draw a server-pushed component (a `ui` stream frame). Omitted → the enclosing `<GenuiProvider>` * draws it; without one, not drawn. */ renderUi?: RenderUiFn; /** * Extra content for the action row, after the built-in affordances and before usage — a badge * naming which agent answered, a status pill. Rendered for every message that has an action row. */ meta?: React.ReactNode; /** Label on the reasoning disclosure toggle. Default `"Reasoning"`. */ reasoningLabel?: React.ReactNode; classNames?: MessageItemClassNames; } export interface MessageItemProps extends MessageRenderSlots { message: UIMessage; /** Marks the in-flight assistant bubble (e.g. for a caret animation / deferred markdown render). */ isStreaming?: boolean; /** User bubble gets a pencil → inline textarea; submitting calls back with the new text. */ editable?: boolean; onEditSubmit?: (input: EditSubmitInput) => void | Promise<void>; /** Assistant bubble gets a "Regenerate" affordance. */ regeneratable?: boolean; onRegenerate?: (input: MessageActionInput) => void | Promise<void>; /** When provided, a "Fork" affordance calls back with this message's id. */ onFork?: (input: MessageActionInput) => void | Promise<void>; /** Server-aggregated usage for this assistant turn (cost + tokens line). */ usage?: MessageUsageInfo | null; /** ISO timestamp of the persisted message; rendered as a relative-time line when set. */ createdAt?: string | null; } export interface MessageItemViewProps extends MessageRenderSlots { item: TranscriptItem; } /** * Styling-agnostic renderer for a single v7 `UIMessage`. Ports flip's full chat-item UX — * copy, fork, regenerate, inline edit-and-resubmit, collapsible reasoning, usage line, relative * timestamp, and tool grouping — but with ALL styling left to `classNames` and every action * surfaced as a callback, so no design-system / icon / date library is pulled in (relative time * uses Intl.RelativeTimeFormat). * * All of the logic lives in `useTranscriptItem`; this is one rendering of it. An app that wants * different markup drives that hook and writes its own. */ export declare function MessageItem({ message, isStreaming, editable, onEditSubmit, regeneratable, onRegenerate, onFork, usage, createdAt, ...slots }: MessageItemProps): React.JSX.Element; /** The default markup for one modelled message — what `MessageItem` renders once it has an item. */ export declare function MessageItemView({ item, ...given }: MessageItemViewProps): React.JSX.Element; //# sourceMappingURL=message-item.d.ts.map