type Json = string | number | boolean | null | { [key: string]: Json | undefined; } | Json[]; interface PromptBlockRow { block_type: string; bound_tool: string | null; category_id: string | null; content: string; created_at: string; created_by: string | null; deleted_at: string | null; description: string | null; icon_name: string | null; id: string; label: string; metadata: Json; name: string; organization_id: string; published_to_web: boolean; published_to_web_at: string | null; published_to_web_by: string | null; shown_to: string | null; skill_id: string | null; sort_order: number; source_kind: string; source_ref: string | null; test_expires_at: string | null; test_run_id: string | null; updated_at: string; updated_by: string | null; version: number; visibility: string; } interface PromptBlockVariantRow { condition: Json; content: string; created_at: string; created_by: string | null; deleted_at: string | null; id: string; label: string; metadata: Json; organization_id: string; prompt_block_id: string; sort_order: number; updated_at: string; updated_by: string | null; version: number; } /** One entry of the server preview's `prompt_blocks` report (Model view and chip panel). */ interface PromptBlockReportEntry { name: string; level: string; block_id?: string | null; variant_id?: string | null; source_kind?: string | null; bound_tool?: string | null; chars?: number | null; } type BlockLane = "mine" | "organization" | "system"; declare const BLOCK_LANES: readonly BlockLane[]; declare const BLOCK_LANE_LABEL: Record; /** The URL param the library's lane lives in (`/agents/prompt-blocks?lane=system`). */ declare const BLOCK_LANE_PARAM = "lane"; declare const DEFAULT_BLOCK_LANE: BlockLane; /** A lane the address names, when it is one of ours; otherwise the default lane. */ declare function blockLaneFromParam(value: string | null): BlockLane; /** The Matrx System organization: system blocks live here. */ declare const SYSTEM_ORG_ID = "39c38960-d30c-4840-b0c1-c9960de95582"; declare function laneOf(row: Pick, meId: string | null): BlockLane; declare function partitionByLane>(rows: readonly T[], meId: string | null): Record; declare function matchesQuery(row: Pick, query: string): boolean; /** A bound-tool block is "may be stale" when the tool changed after the block's last edit. */ declare function mayBeStale(blockUpdatedAt: string, toolUpdatedAt: string | null | undefined): boolean; /** The variant condition grammar (v1): provider, model/alias, latest, reasoning. First match wins. */ declare const REASONING_LEVELS: readonly ["none", "minimal", "low", "medium", "high", "max", "auto", "unset"]; interface BlockCondition { provider?: string[]; model?: string[]; latest?: boolean; reasoning?: string[]; } declare function parseCondition(value: unknown): BlockCondition; /** `{}` never matches: a variant must say when it applies. */ declare function isEmptyCondition(c: BlockCondition): boolean; declare function describeCondition(c: BlockCondition): string; /** The jsonb to store: only keys that carry something. */ declare function conditionToJson(c: BlockCondition): Record; /** * Prompt block tokens — pure text helpers. `{{}}` is a prompt block the agent declares; the * server replaces it on the first turn with `\n…\n`. `{{!}}` is the author's * escaped example and stays plain text. Variables (`{{name}}`) are never touched here. */ declare const BLOCK_NAME_PATTERN = "[a-z][a-z0-9_-]{0,63}"; declare const BLOCK_NAME_RE: RegExp; interface BlockTextSegment { kind: "text" | "block"; text: string; /** Set when `kind` is "block". */ name?: string; } declare function isValidBlockName(name: string): boolean; declare function blockToken(name: string): string; /** Lower-cases a label into a valid block name ("Research rules!" -> "research_rules"). */ declare function toBlockName(label: string): string; /** Every distinct block name used in `text`, in order of first appearance. */ declare function blockNamesInText(text: string): string[]; /** Cuts `text` into plain runs and block tokens; every byte is kept. */ declare function splitBlockText(text: string): BlockTextSegment[]; type BlockChipState = "ok" | "undeclared" | "missing"; /** * How a token in the prompt reads: declared and found -> ok; declared but nothing resolves -> * missing (the run would be refused); used but not declared -> undeclared (left as written). */ declare function blockChipState(name: string, declared: ReadonlySet, missing: ReadonlySet): BlockChipState; interface TypedTrigger { /** Index of the `{{<`. */ start: number; /** What was typed after it. */ query: string; } /** `{{ { eq(column: string, value: unknown): PromptBlocksFilter; neq(column: string, value: unknown): PromptBlocksFilter; is(column: string, value: null): PromptBlocksFilter; contains(column: string, value: unknown): PromptBlocksFilter; order(column: string, options?: { ascending?: boolean; }): PromptBlocksFilter; limit(count: number): PromptBlocksFilter; select(columns?: string): PromptBlocksFilter; single(): PromiseLike; maybeSingle(): PromiseLike; } /** The calls the door makes. Hosts pass their supabase-js client (cast once at the seam). */ interface PromptBlocksClient { schema(name: string): { from(table: string): { select(columns?: string): PromptBlocksFilter; insert(values: unknown): PromptBlocksFilter; update(values: unknown): PromptBlocksFilter; }; }; } interface NewBlock { name: string; label: string; content: string; description?: string | null; source_kind?: "authored" | "skill"; source_ref?: string | null; bound_tool?: string | null; metadata?: Json; organization_id: string; visibility: string; /** A test run's stamp (test data is archived by the run that made it). */ test_run_id?: string | null; } type BlockPatch = Partial>; interface UsingAgent { id: string; name: string; } interface SkillOption { skill_id: string; label: string; } /** * Bind the door to a host client. `Row`/`VariantRow` let a host with generated database types read * its own row types back (they must fit PromptBlockRow / PromptBlockVariantRow). */ declare function createPromptBlockDoor(db: () => PromptBlocksClient): { listBlocks(limit?: number): Promise; listBlocksNamed(name: string): Promise; getBlock(id: string): Promise; createBlock(input: NewBlock): Promise; updateBlock(id: string, patch: BlockPatch): Promise; /** Soft delete: archived blocks stop resolving, history stays. */ archiveBlock(id: string): Promise; listVariants(blockId: string): Promise; createVariant(block: Pick, input: { label: string; condition: Record; content: string; sort_order: number; }): Promise; updateVariant(id: string, patch: Partial> & { condition?: Record; }): Promise; archiveVariant(id: string): Promise; /** Agents declaring `name` (an edit to the block goes live in all of them). */ agentsUsing(name: string): Promise; toolUpdatedAt(toolName: string): Promise; listSkills(): Promise; listToolNames(): Promise; }; type PromptBlockDoor = ReturnType>; interface LocalPrompt { id: string; name: string; content: string; category: string; createdAt: number; updatedAt: number; isPinned: boolean; } /** Read Matrx Local's `matrx-system-prompts` value; anything that is not a prompt is dropped. */ declare function parseLocalPrompts(raw: unknown): LocalPrompt[]; /** Where a block that came from a computer's library says it came from (metadata.local_prompt). */ interface LocalPromptOrigin { source: string; id: string; category: string; pinned: boolean; } declare function localOriginOf(row: Pick): LocalPromptOrigin | null; /** A block name not yet taken: `name`, then `name-2`, `name-3`… */ declare function freeBlockName(base: string, taken: ReadonlySet): string; /** The personal block a local prompt becomes (the caller picks a free name and the organization). */ declare function localPromptToBlock(prompt: LocalPrompt, opts: { source: string; name: string; organizationId: string; testRunId?: string | null; }): NewBlock; export { BLOCK_LANES, BLOCK_LANE_LABEL, BLOCK_LANE_PARAM, BLOCK_NAME_PATTERN, BLOCK_NAME_RE, DEFAULT_BLOCK_LANE, REASONING_LEVELS, SYSTEM_ORG_ID, applyBlockInsert, blockChipState, blockLaneFromParam, blockNamesInText, blockToken, conditionToJson, createPromptBlockDoor, declaredNames, describeCondition, freeBlockName, isEmptyCondition, isValidBlockName, laneOf, localOriginOf, localPromptToBlock, matchesQuery, mayBeStale, parseCondition, parseLocalPrompts, partitionByLane, splitBlockText, toBlockName, typedTriggerAt, withDeclared, withoutDeclared }; export type { BlockChipState, BlockCondition, BlockLane, BlockPatch, BlockTextSegment, DeclaredBlock, Json, LocalPrompt, LocalPromptOrigin, NewBlock, PromptBlockDoor, PromptBlockReportEntry, PromptBlockRow, PromptBlockVariantRow, PromptBlocksClient, PromptBlocksDbError, PromptBlocksFilter, SkillOption, TypedTrigger, UsingAgent };