UNPKG

@sema-agent/core

Version:

Stateless, task-oriented AI agent core

55 lines (54 loc) • 4.02 kB
import { type LegToolResultView } from "../tool-result-store.js"; import type { AgentTool } from "../../internal/harness.js"; import type { NestedUsageAccum, RunnerDeps, TaskSpec } from "../types.js"; import type { SpendAccount } from "../spend-account.js"; import type { PrepareResume } from "./contracts.js"; import type { ToolSelector } from "../tool-face.js"; export interface PrepareOffloadWrappersInput { /** borrowed-readonly — the REBOUND spec (the config-doors result); read for the per-task coarse * offload knob and for the run's identity (principal, isolation scope) its store view writes and reads as. */ spec: Pick<TaskSpec, "toolResultThresholdChars" | "principal" | "isolationScope">; /** borrowed-readonly — the leg's compiled selector, read through the valve (`valveLeaves`): an offloaded result is read back through the * reader tool, so a leg whose valve does not leave the reader (a sub-agent whose lists leave it out, a deployment that excludes it, a * run whose whole face is switched off) offloads nothing — a preview that sends the model to a tool it does not have is a dead end. */ selector: Pick<ToolSelector, "admits">; /** borrowed-readonly — the deployment's coarse offload knob and its injected store (used AS-IS when * present; a Runner-shared instance is viewed per task, see the body). */ deps: Pick<RunnerDeps, "toolResultThresholdChars" | "toolResultStore" | "onNotice">; /** borrowed-readonly — the resume leg, read for the checkpoint seed's nested-usage snapshot so * delegated cost spent before a suspend is not lost; `undefined` on a fresh run. */ resume: Pick<PrepareResume, "seed"> | undefined; /** borrowed-readonly — the run's isolation scope (`scopeKeyOf(spec)`, minted by the * driver — the partition, which is the person when no partition is named): the namespace a Runner-shared * store is scoped under. Never the registry domain. */ offloadScope: string; /** borrowed-readonly — the acquired session id, the offload wrapper's ref-minting coordinate. */ sessionId: string; /** borrowed-readonly — the leg's spend-account node: the nested figure reads everything under it. */ spend: SpendAccount; } export interface PrepareOffloadWrappersResult { /** borrowed-readonly — the run's nested sub-run usage (`Prepared.nestedStats`): a live read of everything under the leg's * spend-account node, plus what a resumed leg carried from the chain before it. Nothing writes it; the account does. */ nestedStats: NestedUsageAccum; /** borrowed-readonly — the store the wrappers close over, or `undefined` when offload is disabled * (threshold 0 / non-finite). The driver reads it for the reserved-name door, the ReadToolResult * mount, the durable-suspend gate and the compaction lane. Not a resource: nothing to release. */ offloadStore: LegToolResultView | undefined; /** borrowed-mutable — the LIVE "currently callable tools" accessor cell the offload preview's * pageback hint reads. Mutation owners after this call: the deferred-disclosure branch of the * driver sets `.current` once the deferred/active sets exist; nothing else writes it. */ offloadReachableToolsRef: { current?: () => ReadonlySet<string>; }; /** borrowed-readonly — wrap a CALLER tool (per-tool `offload` / `offloadThresholdChars` honored). */ maybeOffload: (tool: AgentTool, perTool?: { offload?: boolean; offloadThresholdChars?: number; }) => AgentTool; /** borrowed-readonly — wrap a FIRST-PARTY mount (the per-tool persistence table; Read/Write exempt). */ firstPartyOffload: (tool: AgentTool) => AgentTool; /** borrowed-readonly — wrap a REMOTE-PEER mount (MCP `_meta` size declaration, else 50K). */ remoteToolOffload: (tool: AgentTool) => AgentTool; } export declare function prepareOffloadWrappers(input: PrepareOffloadWrappersInput): PrepareOffloadWrappersResult;