UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

51 lines (50 loc) • 4.02 kB
/** * Where a turn-boundary attachment comes from — one word of a closed set, the producer of one `<system-reminder>` block the * runner delivers to the model at a turn boundary (a todo nudge, a changed-files notice, a listing, a delta …). The set is the * attachment lane's vocabulary: the lane's delivery-class table (`ATTACHMENT_DELIVERY_CLASS`, in `runner/turn-attachments.ts`) * is total over it, a frame receipt names one of its words, and the transcript row of a bundle message names the words of the * attachments it carries ({@link BundledAttachment}). The `steering_injected` echo's `source` reads this set by name and spells, * beside it, only the words no attachment-lane producer owns — so a word added here reaches the echo with no second edit, and a * word is a member of this set or one of those, never both. */ export declare const ATTACHMENT_SOURCES: readonly ["todo_reminder", "task_reminder", "tool_search_usage_reminder", "changed_files", "output_style", "date_change", "workflow_size_guideline_change", "budget_usd", "total_tokens_reminder", "background_tasks", "tools_delta", "mcp_unavailable", "agent_listing", "skills_listing", "mcp_instructions", "mcp_dropped_tools", "workflow_continuation", "skill_mention", "silent_turn_reminder", "elapsed_time_reminder"]; export type AttachmentSource = (typeof ATTACHMENT_SOURCES)[number]; /** Membership test for {@link AttachmentSource}. */ export declare function isAttachmentSource(v: unknown): v is AttachmentSource; /** * One attachment of a bundle message, as its transcript row states it (`UserMessage.attachments`): the attachment's * {@link AttachmentSource} and the length — in UTF-16 code units, the `.length` of the message text — of its framed block, the * `<system-reminder>` block the message text holds for it (shell tags and body). The blocks sit in the text in the order of the * list, one `"\n"` between neighbours and the first at offset 0, so a reader attributes any span of the text to a source by * these lengths alone; whatever follows the last block (the post-tool-batch context block, when that rode the same message) * belongs to none of them. */ export interface BundledAttachment { readonly source: AttachmentSource; readonly chars: number; } /** The string that joins two framed blocks in a bundle message's text. */ export declare const BUNDLE_BLOCK_SEPARATOR = "\n"; /** * THE composition of a bundle message: the framed blocks in order → the text they make and, per block, its source and its * length in that text. The text and the lengths come from this one function, so a length can never describe a text it was not * measured in. A reader of the lengths ({@link readBundledAttachments}) and a writer of the text agree on the separator * through {@link BUNDLE_BLOCK_SEPARATOR}. */ export declare function composeBundle(blocks: ReadonlyArray<{ readonly source: AttachmentSource; readonly block: string; }>): { readonly text: string; readonly attachments: readonly BundledAttachment[]; }; /** * The one reading of a bundle message's `attachments` member (the mint and the session import door both call it): a non-empty * list whose every entry names a member of {@link ATTACHMENT_SOURCES} and a non-negative integer length comes back as a fresh * canonical copy (extra keys never enter a log); anything else — wrong type, an empty list, an unknown word, a length that is * not a count, blocks that with their separators do not fit in the text (`textLength`, the length of the one text the message * holds) — is `undefined`, the whole member is refused rather than half-kept. The relation it can check is the one the text * leaves room for: the blocks start at offset 0 and sit one separator apart, so they take `Σ chars + (n − 1)` of the text and * anything after the last block (a post-tool-batch context block) is the rest. */ export declare function readBundledAttachments(raw: unknown, textLength: number): readonly BundledAttachment[] | undefined;