@sema-agent/core
Version:
Stateless, task-oriented AI agent core
31 lines (30 loc) • 3.18 kB
TypeScript
import type { ImageContent, Message, TextContent } from "../llm/index.js";
import type { AgentMessage, BashExecutionMessage, CompactionSummaryMessage, CustomMessage } from "../loop/types.js";
export type { BashExecutionMessage, CompactionSummaryMessage, CustomMessage, } from "../loop/types.js";
/** Harness-only transcript entries that can be normalized into LLM messages. */
export type HarnessMessage = AgentMessage | BashExecutionMessage | CustomMessage | CompactionSummaryMessage;
export declare function asAgentMessage(message: HarnessMessage): AgentMessage;
export declare const COMPACTION_SUMMARY_PREFIX = "This session is being continued from a previous conversation that ran out of context. The summary below covers the earlier portion of the conversation.\n\n<summary>\n";
export declare const COMPACTION_SUMMARY_SUFFIX = "\n</summary>\n\nRecent messages are preserved verbatim below. Continue the conversation from where it left off without asking the user any further questions. Resume directly \u2014 do not acknowledge the summary, do not recap what was happening, do not preface with \"I'll continue\" or similar. Pick up the last task as if the break never happened.";
/** Render a shell execution record as user-visible context text for the model. */
export declare function bashExecutionToText(msg: BashExecutionMessage): string;
/** Build a persisted compaction summary message from the repository timestamp string.
* `elidedMessages` (RB-398-b①): the render-time count of messages this summary stands in for —
* drives the wrapper's scale disclosure; omitted ⇒ the wrapper stays byte-identical.
* `unsummarizedMessages` (PTL-shortfall accounting): how many of those the summary does NOT cover
* (input shed by a reactive prompt-too-long retry); omitted / 0 ⇒ no uncovered clause. */
export declare function createCompactionSummaryMessage(summary: string, tokensBefore: number, timestamp: string, elidedMessages?: number, unsummarizedMessages?: number): CompactionSummaryMessage;
/** Build a custom transcript message that can be shown and replayed into context. */
export declare function createCustomMessage(customType: string, content: string | (TextContent | ImageContent)[], display: boolean, details: unknown, timestamp: string): CustomMessage;
/** Prefix stamped on a salvaged block so readers (model, summaries, humans) see it is a normalization
* product, not authored content. */
export declare const NORMALIZED_CONTENT_PREFIX = "[invalid content block normalized to text]";
/**
* Fail-soft salvage for a possibly-contaminated LLM message (件b): any structurally-invalid
* `content` shape (bare object as the whole field, or a typeless/unknown-type block in the array) is
* normalized to a prefixed text block. Legal messages are returned BY REFERENCE, untouched. Shared by
* `convertToLlm` (provider leg) and `serializeConversation` (compaction leg) — one helper, two mouths.
*/
export declare function normalizeLlmMessageContent<T extends Message>(message: T): T;
/** Convert harness transcript messages into the LLM-facing message sequence. */
export declare function convertToLlm(messages: AgentMessage[]): Message[];