import { a as TokenUsage, r as ModelPricing } from "./cost-CiXR1eKW.js"; import { h as GenAiProviderName } from "./semconv-BdR5pWDh.js"; import { RequestLogger } from "autotel"; import { OnMissingContext } from "autotel-audit"; //#region src/agent/context.d.ts interface AgentContext { traceId: string; spanId: string; correlationId: string; setAttribute(key: string, value: string | number | boolean): void; setAttributes(attrs: Record): void; } declare const MISSING_CONTEXT_MESSAGE: string; declare function resolveContextSafe(ctx?: AgentContext): AgentContext | null; declare function resolveContext(ctx?: AgentContext): AgentContext; /** Warn (once per action) that an agent action is running without a trace context. */ declare function warnMissingContextOnce(action: string): void; /** A no-op {@link AgentContext} whose attribute setters do nothing. */ declare function noopAgentContext(): AgentContext; /** Adapt an OpenTelemetry span (or span-like object) to {@link AgentContext}. */ declare function agentContextFromSpan(span: { spanContext(): { traceId: string; spanId: string; }; setAttribute(key: string, value: string | number | boolean): void; setAttributes(attrs: Record): void; }): AgentContext; declare function toAttributeValue(value: unknown): string | number | boolean | string[] | number[] | boolean[] | undefined; //#endregion //#region src/agent/privacy.d.ts type PrivacyProfileInput = PrivacyProfileName | PrivacyProfile; /** * What a privacy profile took out of a payload. Redaction reduces risk; it * cannot prove a payload is clean, and a sanitised payload with no counts is * indistinguishable from one that never held anything sensitive. */ interface SanitizationEvidence { /** Values dropped entirely (`dropKeys`). */ redacted: number; /** Values replaced by a hash (`hashKeys`). */ hashed: number; /** Values partially obscured (`maskKeys`). */ masked: number; /** Strings cut at `maxStringLength`. */ truncated: number; } /** A value after sanitising: primitives, or containers of sanitised values. */ type SanitizedValue = string | number | boolean | null | undefined | SanitizedValue[] | { [key: string]: SanitizedValue; }; declare function resolvePrivacyProfile(profile?: PrivacyProfileInput): PrivacyProfile; declare function sanitizeAuditPayload(value: unknown, profile?: PrivacyProfileInput): SanitizedValue; /** * Sanitize, and report what was taken out. Use this wherever the sanitised * payload is shown, exported, or shared — the counts are what let a reader * tell a clean payload from a stripped one. */ declare function sanitizeAuditPayloadWithEvidence(value: unknown, profile?: PrivacyProfileInput): { value: SanitizedValue; evidence: SanitizationEvidence; }; //#endregion //#region src/agent/types.d.ts /** * Free-form metadata a caller attaches to a GenAI operation. Serialized onto a * span or an event, so it holds what JSON can carry. */ type GenAiMetadata = { [key: string]: string | number | boolean | null | GenAiMetadata | Array; }; type PolicyDecision = 'permit' | 'deny' | 'challenge' | 'observe' | 'error'; type ToolStatus = 'planned' | 'complete' | 'error' | 'blocked'; type AgentOutcome = 'success' | 'failure'; type AgentEventKind = 'action' | 'tool_call' | 'policy_decision' | 'handoff'; type AiLifecycleStage = 'plan' | 'design' | 'develop' | 'deploy' | 'operate' | 'monitor' | 'decommission'; type AgentIdentityStatus = 'active' | 'rotated' | 'revoked' | 'expired'; type AgentSessionStatus = 'active' | 'completed' | 'failed' | 'revoked' | 'expired'; type PrivacyProfileName = 'strict' | 'pci' | 'healthcare'; interface AgentIdentity { id: string; version?: string; framework?: string; model?: string; role?: string; sessionId?: string; conversationId?: string; } interface DelegationContext { parentIdentity: string; scope?: string | string[]; tokenId?: string; delegationId?: string; authorityLineage?: string[]; authorityLineageHash?: string; depth?: number; issuedAt?: string | Date; expiresAt?: string | Date; } interface ToolCallMetadata { name: string; callId?: string; input?: unknown; inputHash?: string; output?: unknown; outputHash?: string; status?: ToolStatus; executionMs?: number; } /** * LLM call metadata for an agent action. When present on a tool call or action, * autotel-genai records canonical OpenTelemetry GenAI attributes on the span — * `gen_ai.request.model`, `gen_ai.usage.input_tokens` / `output_tokens`, and the * estimated `gen_ai.usage.cost.usd`. Token usage is usually known only after the * call; supply it via `usage` if known up front, or via the `extractUsage` * option to pull it from the handler's result. */ interface AgentAiMetadata { /** Model id, e.g. `gpt-4o`, `claude-sonnet-4`, `@cf/meta/llama-3.1-8b-instruct-fp8`. */ model: string; /** * `gen_ai.operation.name` — `chat` | `text_completion` | `embeddings` | * `invoke_agent` | `execute_tool` | custom. */ operation?: string; /** `gen_ai.provider.name` — e.g. `openai`, `anthropic`, `gcp.gemini`. */ provider?: GenAiProviderName; /** Model the provider actually served (`gen_ai.response.model`). */ responseModel?: string; /** Provider response id (`gen_ai.response.id`). */ responseId?: string; /** Token counts, if known up front (otherwise use `AgentActionOptions.extractUsage`). */ usage?: TokenUsage; /** Provider finish reasons, e.g. `['stop']`. */ finishReasons?: string[]; /** Per-call pricing override/extension for cost estimation. */ pricing?: Record; } interface PolicyMetadata { decision: PolicyDecision; policyId?: string; riskScore?: number; reason?: string; } interface GovernanceMetadata { reviewRequired?: boolean; reviewerId?: string; controlId?: string | string[]; documentationUrl?: string; lifecycleStage?: AiLifecycleStage; framework?: string; } interface AgentSessionMetadata { status?: AgentSessionStatus; startedAt?: string | Date; endedAt?: string | Date; delegatedBy?: string; } interface AgentSessionActionMetadata extends AgentActionMetadata { session?: AgentSessionMetadata; } interface AgentDecisionMetadata { summary: string; inputHash?: string; policyIds?: string[]; justificationCodes?: string[]; evidenceIds?: string[]; reviewRequired?: boolean; confidence?: number; } interface AgentActionMetadata { action: string; resource?: string; actorId?: string; category?: string; outcome?: AgentOutcome; schemaVersion?: string; eventKind?: AgentEventKind; agent: AgentIdentity; delegation?: DelegationContext; tool?: ToolCallMetadata; ai?: AgentAiMetadata; policy?: PolicyMetadata; governance?: GovernanceMetadata; session?: AgentSessionMetadata; decision?: AgentDecisionMetadata; reasoningSummary?: string; } interface AgentActionOptions { ctx?: AgentContext; emitNow?: boolean; forceKeep?: boolean; logger?: RequestLogger; /** * Behaviour when no trace context can be resolved. Defaults to `warn` * (best-effort: run the action un-audited, warn once). Agent audit is * observability — a missing context must never crash the wrapped tool call. * See {@link OnMissingContext}. */ onMissingContext?: OnMissingContext; /** * Pull token usage from the handler's result, for actions carrying * {@link AgentAiMetadata}. Called once after the handler resolves; the * returned usage drives the recorded GenAI token + cost attributes. Most LLM * SDKs expose this on the response (e.g. `res.usage`). */ extractUsage?: (result: unknown) => TokenUsage | undefined; } interface AgentToolCallOptions extends AgentActionOptions { hashResult?: boolean; } type AgentHandler = (ctx: AgentContext, logger: RequestLogger) => T | Promise; /** Action metadata that always carries tool details (for tool-call wrappers). */ type AgentToolCallActionMetadata = AgentActionMetadata & { tool: ToolCallMetadata; }; /** * Factory used by `defineAgentAction` / `defineAgentToolCall`. Mirrors the * `trace()` factory shape: receive the audit context, return the handler that * runs per call. `logger` may be ignored. */ type AgentActionFactory = (ctx: AgentContext, logger: RequestLogger) => (...args: TArgs) => TResult | Promise; /** * Metadata for a defined wrapper: either a static object or a function of the * call arguments (so call-specific fields like `tool.input` can be hashed). */ type AgentMetadataInput = TMetadata | ((...args: TArgs) => TMetadata); interface PrivacyProfile { name: string; hashKeys?: RegExp[]; dropKeys?: RegExp[]; maskKeys?: RegExp[]; maxStringLength?: number; } interface AgentIdentityRecord { agent: AgentIdentity; scopes: string[]; status: AgentIdentityStatus; tokenId?: string; tokenHash?: string; delegatedBy?: string; provisionedAt: string; rotatedAt?: string; revokedAt?: string; revocationReason?: string; expiresAt?: string; metadata?: GenAiMetadata; } interface AgentIdentityRegistry { provisionIdentity(input: { agent: AgentIdentity; scopes?: string[]; tokenId?: string; delegatedBy?: string; provisionedAt?: string | Date; expiresAt?: string | Date; metadata?: GenAiMetadata; }): AgentIdentityRecord; rotateIdentity(agentId: string, input?: { scopes?: string[]; tokenId?: string; delegatedBy?: string; rotatedAt?: string | Date; expiresAt?: string | Date; metadata?: GenAiMetadata; }): AgentIdentityRecord; revokeIdentity(agentId: string, input: { reason: string; revokedAt?: string | Date; }): AgentIdentityRecord; getIdentity(agentId: string): AgentIdentityRecord | undefined; getIdentityStatus(agentId: string, at?: string): AgentIdentityStatus | undefined; assertUsable(agentId: string, at?: string): AgentIdentityRecord; assertScopes(agentId: string, requiredScopes: string[]): AgentIdentityRecord; issueDelegation(agentId: string, input: { parentIdentity: string; scope?: string | string[]; tokenId?: string; delegationId?: string; authorityLineage?: string[]; issuedAt?: string | Date; expiresAt?: string | Date; }): DelegationContext; list(): AgentIdentityRecord[]; } interface ScopedToolDefinition { action: string; resource?: string; category?: string; agent: AgentIdentity; delegation?: DelegationContext; tool: Pick; requiredScopes?: string[]; policyId?: string; riskScore?: number; reviewRequired?: boolean; governance?: GovernanceMetadata; decision?: AgentDecisionMetadata; privacyProfile?: PrivacyProfileName | PrivacyProfile; identityRegistry?: AgentIdentityRegistry; } interface AgentAuditEventEnvelope { schemaVersion: string; emittedAt: string; eventHash: string; previousEventHash?: string; signature?: string; metadata: AgentActionMetadata; evidence?: unknown; /** * What sanitising {@link AgentAuditEventEnvelope.evidence} removed. Covered * by `eventHash`, so a reader can trust the counts as far as they trust the * chain. Absent when there was no evidence payload, and on envelopes written * before this field existed. */ sanitization?: SanitizationEvidence; } //#endregion //#region src/agent/agent-security.d.ts /** Canonical agent security attribute keys (Google SAIF / human-control aligned). */ declare const AGENT_SECURITY_ATTR: { readonly controllerId: 'agent.controller.id'; readonly inputProvenance: 'agent.input.provenance'; readonly actionRiskClass: 'agent.action.risk_class'; readonly consentRequired: 'agent.consent.required'; readonly consentOutcome: 'agent.consent.outcome'; readonly consentEvidence: 'agent.consent.evidence'; readonly scopeActive: 'agent.scope.active'; readonly memoryOperation: 'agent.memory.operation'; readonly memoryIsolationKey: 'agent.memory.isolation_key'; readonly memoryContentHash: 'agent.memory.content_hash'; readonly planStepIndex: 'agent.plan.step_index'; readonly planToolIntents: 'agent.plan.tool_intents'; readonly planPolicyIds: 'agent.plan.policy_ids'; readonly outputFormat: 'agent.output.format'; readonly outputContainsUrl: 'agent.output.contains_url'; readonly outputUrlCount: 'agent.output.url_count'; }; type AgentInputProvenance = 'user_direct' | 'user_voice' | 'rag' | 'memory' | 'tool_result' | 'external_untrusted'; type AgentActionRiskClass = 'read' | 'write' | 'destructive' | 'financial' | 'exfiltration_capable'; type AgentConsentOutcome = 'approved' | 'denied' | 'timeout' | 'revoked'; /** * Whether a consent outcome was witnessed or reconstructed. * * No IDE or agent runtime reports the human's click, so an approval is usually * deduced from the tool having run after a prompt. That deduction is worth * recording and must never be cited as a human decision, which it cannot be * told apart from unless the record says which it is. */ type AgentConsentEvidence = 'observed' | 'inferred'; type AgentMemoryOperation = 'read' | 'write' | 'delete' | 'search'; type AgentOutputFormat = 'text' | 'markdown' | 'html' | 'json' | 'mixed'; interface AgentSecurityRecordOptions { ctx?: AgentContext; } interface RecordControllerInput extends AgentSecurityRecordOptions { /** Controlling human user id — hashed before emission unless already a digest. */ controllerId: string; /** Pass a stable per-deployment salt to `hashIdentifier`. */ hashSalt?: string; /** When false, emit the id as given (must not be raw PII). Default true. */ hash?: boolean; } interface RecordInputProvenanceInput extends AgentSecurityRecordOptions { provenance: AgentInputProvenance; } interface RecordHumanApprovalInput extends AgentSecurityRecordOptions { toolCallId: string; toolName?: string; approved: boolean; required?: boolean; controllerId?: string; hashSalt?: string; /** * How the outcome was established. Defaults to `'inferred'`: a caller that * did not say it witnessed the decision did not witness it, and the weaker * claim is the safe default for a record an auditor may rely on. */ evidence?: AgentConsentEvidence; } interface RecordActiveScopesInput extends AgentSecurityRecordOptions { scopes: string[]; } interface RecordMemoryAccessInput extends AgentSecurityRecordOptions { operation: AgentMemoryOperation; isolationKey: string; contentHash?: string; } interface RecordPlanStepInput extends AgentSecurityRecordOptions { stepIndex: number; toolIntents?: string[]; policyIds?: string[]; summary?: string; } interface RecordRenderOutputInput extends AgentSecurityRecordOptions { format?: AgentOutputFormat; containsUrl?: boolean; urlCount?: number; } interface ActionRiskHints { readOnlyHint?: boolean; destructiveHint?: boolean; openWorldHint?: boolean; untrustedContentHint?: boolean; financial?: boolean; exfiltrationCapable?: boolean; } /** * Derive a coarse action risk class from MCP tool hints or explicit overrides. */ declare function deriveActionRiskClass(hints: ActionRiskHints, override?: AgentActionRiskClass): AgentActionRiskClass; declare function recordControllerId(input: RecordControllerInput): void; declare function recordInputProvenance(input: RecordInputProvenanceInput): void; declare function recordHumanApproval(input: RecordHumanApprovalInput): void; declare function recordActiveScopes(input: RecordActiveScopesInput): void; declare function recordActionRiskClass(riskClass: AgentActionRiskClass, options?: AgentSecurityRecordOptions): void; declare function recordMemoryAccess(input: RecordMemoryAccessInput): void; declare function recordPlanStep(input: RecordPlanStepInput): void; declare function recordRenderOutput(input: RecordRenderOutputInput): void; /** Best-effort variant — no throw when trace context is missing. */ declare function tryRecordHumanApproval(input: RecordHumanApprovalInput): boolean; //#endregion export { PrivacyProfileName as $, AgentAiMetadata as A, AgentOutcome as B, recordMemoryAccess as C, AgentActionFactory as D, tryRecordHumanApproval as E, AgentIdentity as F, AgentToolCallOptions as G, AgentSessionMetadata as H, AgentIdentityRecord as I, GenAiMetadata as J, AiLifecycleStage as K, AgentIdentityRegistry as L, AgentDecisionMetadata as M, AgentEventKind as N, AgentActionMetadata as O, AgentHandler as P, PrivacyProfile as Q, AgentIdentityStatus as R, recordInputProvenance as S, recordRenderOutput as T, AgentSessionStatus as U, AgentSessionActionMetadata as V, AgentToolCallActionMetadata as W, PolicyDecision as X, GovernanceMetadata as Y, PolicyMetadata as Z, deriveActionRiskClass as _, AgentConsentOutcome as a, resolvePrivacyProfile as at, recordControllerId as b, AgentOutputFormat as c, AgentContext as ct, RecordControllerInput as d, ScopedToolDefinition as et, RecordHumanApprovalInput as f, RecordRenderOutputInput as g, RecordPlanStepInput as h, AgentConsentEvidence as i, SanitizationEvidence as it, AgentAuditEventEnvelope as j, AgentActionOptions as k, AgentSecurityRecordOptions as l, agentContextFromSpan as lt, RecordMemoryAccessInput as m, ActionRiskHints as n, ToolStatus as nt, AgentInputProvenance as o, sanitizeAuditPayload as ot, RecordInputProvenanceInput as p, DelegationContext as q, AgentActionRiskClass as r, PrivacyProfileInput as rt, AgentMemoryOperation as s, sanitizeAuditPayloadWithEvidence as st, AGENT_SECURITY_ATTR as t, ToolCallMetadata as tt, RecordActiveScopesInput as u, recordActionRiskClass as v, recordPlanStep as w, recordHumanApproval as x, recordActiveScopes as y, AgentMetadataInput as z };