/**
* Typed tool contracts.
*
* A tool is an owned effect seam for an agent. The contract carries the data shape, authority,
* approval, idempotency, dimensionless cost, and sensitivity metadata that every adapter needs.
* Adapters call {@link executeTool}; they do not reimplement admission.
*
* This module is deliberately token-only in its evidence and idempotency stores. It never persists
* tool arguments, results, request bodies, or business values.
*/
import type { RequestBudget } from "./budget.js";
import { type ExecutionPolicy, type ExecutionPolicyAdapter } from "./execution-policy.js";
import { type IdempotencyScope } from "./idempotency.js";
import { type EffectCost, type RequestLedger, type SealedEffectLedger } from "./ledger.js";
import { type InferOutput, type StandardIssue, type StandardSchemaV1 } from "./schema/standard.js";
import { type ProtoPoisoning } from "./server/proto-guard.js";
export type ToolSensitivity = "public" | "internal" | "sensitive" | "secret";
export type ToolApprovalPolicy = {
readonly kind: "none";
} | {
readonly kind: "required";
} | {
readonly kind: "threshold";
readonly level: number;
};
export type ToolApproval = {
readonly granted: true;
readonly level?: number;
} | {
readonly granted: false;
readonly reason?: string;
};
export interface ToolAnnotations {
readonly title?: string;
readonly readOnlyHint?: boolean;
readonly destructiveHint?: boolean;
readonly idempotentHint?: boolean;
readonly openWorldHint?: boolean;
}
export interface ToolIdempotencyPolicy {
readonly scope: Exclude;
/** Return an opaque bounded key. The key must not contain a request body or secret. */
readonly key: (input: Input) => string | PromiseLike;
}
export interface ToolContractOptions {
readonly name: string;
readonly description: string;
readonly input: InputSchema;
readonly output: OutputSchema;
readonly capability?: string;
readonly approval?: ToolApprovalPolicy;
readonly idempotency?: ToolIdempotencyPolicy;
/** Dimensionless counters such as `{ calls: 1, ms: 20 }`; never prices. */
readonly cost?: EffectCost;
readonly sensitivity?: ToolSensitivity;
readonly annotations?: ToolAnnotations;
readonly policy?: ExecutionPolicy;
readonly execute: (input: Input, context: ToolExecutionContext) => Output | PromiseLike