/** * Public `agency.*` namespace — the canonical entry point for TS code * that wants to participate in an Agency run (read context, push * thread messages, install handlers, create checkpoints, etc.). * * Every method is a thin wrapper over an existing runtime function; * no new behavior is added here. The namespace exists for * discoverability and to give docs/IDEs a single surface to point at. * * Naming conventions: * - No underscore prefix. Read APIs throw on missing frame by * default; `*Maybe` variants return `undefined` instead. * `callsite()` is the lone exception: callsite is intrinsically * optional (bootstrap frames omit it) so it always returns * `CallsiteLocation | undefined` even from inside a valid frame. * - `with*` prefix for scope-installing helpers (run a callback with * a temporary modification to the active frame). * - Thread-related operations live under `agency.thread.*` to keep * the top-level surface lean; e.g. `agency.thread.user("hi")` and * `agency.thread.current()`. * - Codegen-emitted internals (`getRuntimeContext`, `agencyStore`, * `__threads`, `__stateStack`, `__call`, `__callMethod`, * `runInTestContext`) keep their existing names and are still * exported from `agency-lang/runtime` because generated code * imports them directly. TS helper authors should prefer * `agency.*`. */ import * as smoltalk from "smoltalk"; import { type CallsiteLocation } from "./asyncContext.js"; import { addCost, addTokens } from "./cost.js"; import { interrupt, type InterruptOpts } from "./agencyInterrupt.js"; import { llm as _llm } from "./agencyLlm.js"; import type { RestoreOptions } from "./errors.js"; import { withResumableScope as _withResumableScope, type ResumableScope, type ResumableScopeOpts } from "./resumableScope.js"; import { type WithLockOptions } from "./lock.js"; import type { Checkpoint } from "./state/checkpointStore.js"; import type { RuntimeContext } from "./state/context.js"; import type { StateStack } from "./state/stateStack.js"; import type { MessageThread } from "./state/messageThread.js"; import type { ThreadStore } from "./state/threadStore.js"; import type { HandlerFn } from "./types.js"; import type { MemoryConfig } from "./memory/types.js"; /** Plain record describing a thread in the run's registry. Slug-ified * ids (`t0`, `t1`, ...) wrap the internal counter strings so LLMs see * short, easy-to-quote identifiers. `label` and `summary` are * surfaced directly from the underlying `MessageThread` (post-Commit-B: * no more module-level TS cache). */ export type ThreadInfoTS = { id: string; parentId: string | null; threadType: "thread" | "subthread"; messageCount: number; isActive: boolean; /** Snapshot of the thread's messages in smoltalk's wire format. * Consumers that need flat `{role, content}` records can call * `m.role` / `m.content` directly; tool-call / structured-content * variants land here untouched (no lossy coercion). */ messages: smoltalk.MessageJSON[]; /** Optional user-supplied label from `thread(label: "...") { ... }`. * `null` when no label was given. */ label: string | null; /** Cached summary written by the stdlib's `summaryFor()` helper. * `null` until the summary is computed (lazy on first * `listThreads()`). */ summary: string | null; }; /** * Public `agency` namespace — the canonical entry point for TS code * that wants to participate in an Agency run. Users access everything * through `agency.(...)`; there are no individual named * exports. */ export declare const agency: { ctx: () => RuntimeContext; ctxMaybe: () => RuntimeContext | undefined; callsite: () => CallsiteLocation | undefined; global: (name: string, moduleId?: string) => T; thread: { current: () => MessageThread; user: (content: string) => void; system: (content: string) => void; assistant: (content: string) => void; store: () => ThreadStore; storeMaybe: () => ThreadStore | undefined; with: (threadId: string, fn: () => T | Promise) => Promise; }; checkpoint: () => Promise; getCheckpoint: (id: number) => Checkpoint; restore: (idOrCp: number | Checkpoint, opts?: RestoreOptions) => void; withCallsite: (loc: CallsiteLocation, fn: () => T) => T; withHandler: (handler: HandlerFn, fn: () => Promise) => Promise; withCostGuard: (maxCost: number, fn: () => Promise) => Promise; withTimeGuard: (maxMs: number, fn: () => Promise) => Promise; withLock: (name: string, fn: () => T | Promise, opts?: WithLockOptions) => Promise; addCost: typeof addCost; addTokens: typeof addTokens; withResumableScope: typeof _withResumableScope; llm: typeof _llm; interrupt: typeof interrupt; memory: { enable: (config: MemoryConfig) => Promise; disable: () => void; setId: (id: string) => Promise; enabled: () => boolean; remember: (content: string) => Promise; recall: (query: string) => Promise; forget: (query: string) => Promise; }; threads: { list: () => ThreadInfoTS[]; get: (id: string, offset?: number, limit?: number) => smoltalk.MessageJSON[]; current: () => string | undefined; }; withTestContext: (args: { ctx: RuntimeContext; stack: StateStack; threads: ThreadStore; }, fn: () => T) => T; }; export type { InterruptOpts, ResumableScope, ResumableScopeOpts }; export type { MemoryConfig, WithLockOptions };