@full-self-browsing/lattice 1.3.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-run-C6miAzwI.d.ts +45 -0
- package/dist/agent-run-C6miAzwI.d.ts.map +1 -0
- package/dist/agent-run-CgPVFl0Z.js +47 -0
- package/dist/agent-run-CgPVFl0Z.js.map +1 -0
- package/dist/agents.d.ts +5 -0
- package/dist/agents.js +6 -0
- package/dist/artifact-Bg6mJGnm.d.ts +125 -0
- package/dist/artifact-Bg6mJGnm.d.ts.map +1 -0
- package/dist/artifact-DOfpeXLb.js +140 -0
- package/dist/artifact-DOfpeXLb.js.map +1 -0
- package/dist/artifacts.d.ts +2 -0
- package/dist/artifacts.js +2 -0
- package/dist/audit.d.ts +3 -0
- package/dist/audit.js +4 -0
- package/dist/catalog-CAfYwB_-.js +91 -0
- package/dist/catalog-CAfYwB_-.js.map +1 -0
- package/dist/context-pack-Bz3GXmjv.js +99 -0
- package/dist/context-pack-Bz3GXmjv.js.map +1 -0
- package/dist/context.d.ts +2 -0
- package/dist/context.js +2 -0
- package/dist/contract-S3oJGlc9.d.ts +74 -0
- package/dist/contract-S3oJGlc9.d.ts.map +1 -0
- package/dist/core.d.ts +48 -0
- package/dist/core.d.ts.map +1 -0
- package/dist/core.js +95 -0
- package/dist/core.js.map +1 -0
- package/dist/errors-eEuEIx6X.js +407 -0
- package/dist/errors-eEuEIx6X.js.map +1 -0
- package/dist/eval.d.ts +2 -0
- package/dist/eval.js +2 -0
- package/dist/fingerprint-DodDbQKN.js +34 -0
- package/dist/fingerprint-DodDbQKN.js.map +1 -0
- package/dist/index-DpnHGHVL.d.ts +53 -0
- package/dist/index-DpnHGHVL.d.ts.map +1 -0
- package/dist/index.d.ts +78 -3234
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +365 -8434
- package/dist/index.js.map +1 -1
- package/dist/infer-DLqp5QIM.d.ts +96 -0
- package/dist/infer-DLqp5QIM.d.ts.map +1 -0
- package/dist/lineage-DBgoPWAZ.js +137 -0
- package/dist/lineage-DBgoPWAZ.js.map +1 -0
- package/dist/local-CXOGPJ1f.js +139 -0
- package/dist/local-CXOGPJ1f.js.map +1 -0
- package/dist/local-Dy--7peL.d.ts +10 -0
- package/dist/local-Dy--7peL.d.ts.map +1 -0
- package/dist/memory-CkQEW6m5.js +62 -0
- package/dist/memory-CkQEW6m5.js.map +1 -0
- package/dist/memory-DRig5EHV.d.ts +10 -0
- package/dist/memory-DRig5EHV.d.ts.map +1 -0
- package/dist/negotiate-ClD88hkc.js +10967 -0
- package/dist/negotiate-ClD88hkc.js.map +1 -0
- package/dist/otel-BgM4e55_.d.ts +421 -0
- package/dist/otel-BgM4e55_.d.ts.map +1 -0
- package/dist/permission-context-CUKMo79F.js +134 -0
- package/dist/permission-context-CUKMo79F.js.map +1 -0
- package/dist/plan-DFm8Llep.js +125 -0
- package/dist/plan-DFm8Llep.js.map +1 -0
- package/dist/preflight-DNHWuJ46.d.ts +64 -0
- package/dist/preflight-DNHWuJ46.d.ts.map +1 -0
- package/dist/provider-C2IfKsvz.d.ts +1178 -0
- package/dist/provider-C2IfKsvz.d.ts.map +1 -0
- package/dist/providers.d.ts +4 -0
- package/dist/providers.js +4 -0
- package/dist/rate-limit-group-nDsBJqSu.d.ts +235 -0
- package/dist/rate-limit-group-nDsBJqSu.d.ts.map +1 -0
- package/dist/receipt-FYouoPHv.js +205 -0
- package/dist/receipt-FYouoPHv.js.map +1 -0
- package/dist/replay-CtIhpLek.js +964 -0
- package/dist/replay-CtIhpLek.js.map +1 -0
- package/dist/result-DLEx2WvU.d.ts +38 -0
- package/dist/result-DLEx2WvU.d.ts.map +1 -0
- package/dist/router-DU4Z3pTd.js +314 -0
- package/dist/router-DU4Z3pTd.js.map +1 -0
- package/dist/router-Yo1-aDOv.d.ts +42 -0
- package/dist/router-Yo1-aDOv.d.ts.map +1 -0
- package/dist/routing.d.ts +6 -0
- package/dist/routing.js +4 -0
- package/dist/{run-crew-DDznbc3G.js → run-crew-B2fQLmgB.js} +16 -23
- package/dist/run-crew-B2fQLmgB.js.map +1 -0
- package/dist/run-crew-Bnve5dyI.d.ts +721 -0
- package/dist/run-crew-Bnve5dyI.d.ts.map +1 -0
- package/dist/{runtime-BTi8lr_O.js → runtime-Dxiet5YS.js} +100 -640
- package/dist/runtime-Dxiet5YS.js.map +1 -0
- package/dist/scaffolds-DKQrCRqh.d.ts +535 -0
- package/dist/scaffolds-DKQrCRqh.d.ts.map +1 -0
- package/dist/scaffolds-ekPIlBeU.js +3139 -0
- package/dist/scaffolds-ekPIlBeU.js.map +1 -0
- package/dist/schema-CNfa_VEy.d.ts +15 -0
- package/dist/schema-CNfa_VEy.d.ts.map +1 -0
- package/dist/storage-DJKmsaEI.d.ts +26 -0
- package/dist/storage-DJKmsaEI.d.ts.map +1 -0
- package/dist/storage.d.ts +10 -0
- package/dist/storage.d.ts.map +1 -0
- package/dist/storage.js +4 -0
- package/dist/tool-call-validation-BFoXkwbf.js +107 -0
- package/dist/tool-call-validation-BFoXkwbf.js.map +1 -0
- package/dist/tools-C4wHgGKQ.js +49 -0
- package/dist/tools-C4wHgGKQ.js.map +1 -0
- package/dist/tools.d.ts +46 -0
- package/dist/tools.d.ts.map +1 -0
- package/dist/tools.js +106 -0
- package/dist/tools.js.map +1 -0
- package/dist/validate-c7EL5uuH.js +224 -0
- package/dist/validate-c7EL5uuH.js.map +1 -0
- package/package.json +105 -6
- package/dist/run-crew-DDznbc3G.js.map +0 -1
- package/dist/runtime-BTi8lr_O.js.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,1991 +1,19 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { $ as XaiQuirks, $t as ExecutionPlanStub, A as SANITIZER_BY_FAILURE_MODE, At as defaultPiiDetectors, B as ModelCapabilityProfilePricingKey, Ct as ValidationIssue, D as NegotiationAuthError, Dt as evaluateTripwires, E as NegotiatedCapabilities, Et as TripwireResult, F as CapabilityAdapter, Ft as MustCiteInvariant, G as AdapterQuirks, H as RecommendedPromptStrategy, I as KnownFailureMode, It as NoPiiInvariant, J as LiteLLMQuirks, K as AnthropicQuirks, L as ModelCapabilityProfile, Lt as inv, M as getRecommendedSanitizers, Mt as InvariantDeclaration, N as ALL_KNOWN_FAILURE_MODES, Nt as InvariantOptions, O as negotiateCapabilities, Ot as PiiDetector, P as ALL_TRAINING_CLASSES, Pt as MatchesInvariant, Q as OpenRouterQuirks, R as ModelCapabilityProfileModality, T as Usage, Tt as TripwireEvidence, U as ToolCallSurface, V as ReasoningSurface, W as TrainingClass, X as OpenAICompatQuirks, Y as LmStudioQuirks, Yt as createMemorySessionStore, Z as OpenAIQuirks, _ as ProviderStreamOutputChunk, _n as output, b as ProviderStreamUsageChunk, bn as RunEventSink, d as ProviderRunRequest, dt as importMcpTools, et as ToolCallValidationError, f as ProviderRunResponse, ft as runTool, g as ProviderStreamGatewayChunk, gt as LatticeRunError, h as ProviderStreamCompleteChunk, ht as parseToolUseEnvelope, j as SanitizerKey, jt as FieldFromTableInvariant, k as synthesizeNegotiatedCapabilitiesFromRegistry, kt as PiiDetectorResult, l as ProviderRef, m as ProviderStreamChunk, mn as OutputContractMap, mt as ToolUseRequest, nt as ValidateToolCallsOption, o as ProviderGatewayMetadata, p as ProviderStream, pn as OutputContract, pt as toolArtifactRef, q as GeminiQuirks, qt as SessionRef, r as ProviderAdapter, rt as ValidatedToolCall, tt as ToolCallValidationFailureReason, ut as defineTool, v as ProviderStreamTextDeltaChunk, vn as RunEvent, wt as isTerminal, xn as TracerLike, xt as TripwireViolationError, y as ProviderStreamToolCallChunk, yn as RunEventKind, z as ModelCapabilityProfilePricing } from "./provider-C2IfKsvz.js";
|
|
2
|
+
import { A as FormatToolsMode, B as HookDenyDirective, C as EvictionHook, D as UnsubscribeFn, E as SurvivabilityAdapter, F as LatticeConfig, G as createHookPipeline, H as HookLifecycleEvent, I as NormalizedLatticeConfig, L as BAND, M as FormattedToolsHandle, N as formatToolsForProvider, O as createNoopSurvivabilityAdapter, P as toolSchemaToJsonSchema, R as Band, S as createNoopAgentHost, T as SerializedSnapshot, U as HookPipeline, V as HookHandler, _ as AgentHost, a as CrewPolicy, b as AgentStorage, c as defineAgent, d as AgentFailureKind, f as AgentIntent, g as IterationRecord, i as runAgentCrew, j as FormatToolsOptions, k as ConversationTurn, l as AgentDeniedError, m as AgentSuccess, n as CrewResult, o as CrewRateLimitOverride, p as AgentResult, r as RunAgentCrewOptions, s as AgentSpec, t as CrewAgentResult, u as AgentFailure, v as AgentScheduler, w as ResumePolicy, x as AgentTransport, y as AgentSnapshot, z as HookControls } from "./run-crew-Bnve5dyI.js";
|
|
3
|
+
import { _ as ArtifactTransformDescriptor, a as ArtifactOptions, b as GatewayPolicy, c as ArtifactSize, f as artifact, g as ArtifactParentRef, h as ArtifactLineage, i as ArtifactKind, l as ArtifactSource, n as ArtifactFingerprint, o as ArtifactPrivacy, r as ArtifactInput, s as ArtifactRef, u as ArtifactStorageRef, v as ArtifactTransformKind, x as PolicySpec, y as GatewayMetadataValue } from "./artifact-Bg6mJGnm.js";
|
|
4
|
+
import { _ as VerifyFail, a as KeyEntry, c as ReceiptEnvelope, d as ReceiptRoute, f as ReceiptSignature, g as VerifyErrorKind, h as VerifyError, i as ContractVerdict, l as ReceiptModel, m as ReceiptUsageCanonical, n as InferOutputMap, o as KeySet, p as ReceiptSigner, r as CapabilityReceiptBody, s as KeyState, t as InferOutput, u as ReceiptRedaction, v as VerifyOk, y as VerifyResult } from "./infer-DLqp5QIM.js";
|
|
5
|
+
import { i as StoredArtifactPayloadDescriptor, n as StorageLike, r as StoredArtifactEnvelope, t as ArtifactStore } from "./storage-DJKmsaEI.js";
|
|
6
|
+
import { a as QualityFloorInvariant, i as ContractRejectReasonCode, n as CapabilityContract, o as contract, r as CapabilityContractInput, t as BudgetInvariant } from "./contract-S3oJGlc9.js";
|
|
7
|
+
import { A as createCostTracker, C as ProgressStatus, D as createTranscriptStore, E as TranscriptStore, O as CostBudgetStatus, S as GoalProgressTracker, T as TokenEstimator, _ as STUCK_REASONS, a as withRateLimit, b as GoalProgressOptions, c as PermissionHookContext, d as createPermissionContext, f as createPermissionGuardHook, g as ActionRecord, h as ActionHistoryOptions, i as createRateLimitGroup, j as runAgent, k as CostTracker, l as PermissionRule, m as ActionHistory, n as RateLimitGroupOptions, o as PermissionContext, p as permissionGuardRegisterOptions, r as RateLimitLease, s as PermissionDecisionInput, t as RateLimitGroup, u as PermissionVerdict, v as StuckReason, w as createGoalProgressTracker, x as GoalProgressStep, y as createActionHistory } from "./rate-limit-group-nDsBJqSu.js";
|
|
8
|
+
import { a as EvalRegressionKind, i as EvalRegression, n as AgentRunSnapshot, o as evalAgentRun, r as EvalOptions, t as AgentEvalResult } from "./agent-run-C6miAzwI.js";
|
|
9
|
+
import { A as RemoteReceiptSignerProvider, B as ReplayEnvelope, D as RemoteReceiptSignRequest, E as RemoteReceiptPayloadFormat, F as ExternalExecutionMetadata, G as replayOffline, H as redactArtifactRef, I as ExternalExecutionSidecar, J as RunIntent, K as rerunLive, L as ExternalExecutionSidecarOutputSpec, M as createMemoryKeySet, N as ExternalExecutionAuditInput, O as RemoteReceiptSignResult, P as ExternalExecutionAuditResult, R as ExternalExecutionUsage, S as verifyReceipt, T as generateEd25519KeyPairJwk, U as redactPlan, V as createReplayEnvelope, W as redactReplayEnvelope, X as CreateReceiptInput, Y as createAI, Z as createReceipt, a as OtelHttpTraceConfig, b as materializeReplayEnvelope, c as OtelSpanLike, d as PhoenixOtlpConfigOptions, f as createLangfuseOtlpConfig, g as sanitizeRunEventAttributes, h as createPhoenixOtlpConfig, i as OtelContentCaptureMode, j as createRemoteReceiptSigner, k as RemoteReceiptSignerOptions, l as OtelSpanStatus, m as createOtelRunEventSink, n as OtelAttributeValue, o as OtelRunEventSinkOptions, p as createOtelReceiptAttributes, q as AI, r as OtelAttributes, s as OtelSanitizerOptions, t as LangfuseOtlpConfigOptions, u as OtelTracerLike, v as MaterializationError, w as createInMemorySigner, x as receiptCid, y as MaterializeReplayEnvelopeOptions, z as createExternalExecutionAudit } from "./otel-BgM4e55_.js";
|
|
10
|
+
import { n as RunResult, r as RunSuccess, t as RunFailure } from "./result-DLEx2WvU.js";
|
|
11
|
+
import { a as evaluateContractAgainstRoute, i as estimateRouteCost } from "./preflight-DNHWuJ46.js";
|
|
12
|
+
import { n as createMemoryArtifactStore } from "./memory-DRig5EHV.js";
|
|
13
|
+
import { A as stripChatTemplateArtifacts, C as createAISdkProvider, D as SanitizeOutputOption, E as InternalEnvelopeOptions, M as unwrapInternalEnvelope, O as SanitizerContext, T as createOpenAIProvider, a as CollectStreamOptions, b as createAnthropicProvider, c as createXaiProvider, d as LmStudioProviderOptions, f as createLmStudioProvider, g as createGeminiProvider, h as GeminiProviderOptions, i as getToolUseContract, j as stripReasoningTags, k as SanitizerFn, l as OpenRouterProviderOptions, m as createLiteLLMProvider, n as PROMPT_STRATEGIES, o as collectStream, p as LiteLLMProviderOptions, r as getStructuredOutputContract, s as XaiProviderOptions, t as PROMPT_SCAFFOLD_VERSION, u as createOpenRouterProvider, v as createFakeProvider, w as createOpenAICompatibleProvider, y as AnthropicProviderOptions } from "./scaffolds-DKQrCRqh.js";
|
|
14
|
+
import { n as createLocalArtifactStore } from "./local-Dy--7peL.js";
|
|
15
|
+
import { n as getCapabilityProfile, r as stripOpenRouterVariant, t as findCapabilityProfile } from "./index-DpnHGHVL.js";
|
|
2
16
|
|
|
3
|
-
//#region src/policy/policy.d.ts
|
|
4
|
-
interface PolicySpec {
|
|
5
|
-
readonly maxCostUsd?: number;
|
|
6
|
-
readonly latency?: "interactive" | "batch";
|
|
7
|
-
readonly privacy?: "standard" | "sensitive" | "restricted";
|
|
8
|
-
readonly providerAllowList?: readonly string[];
|
|
9
|
-
readonly providerDenyList?: readonly string[];
|
|
10
|
-
readonly noUpload?: boolean;
|
|
11
|
-
readonly noPublicUrl?: boolean;
|
|
12
|
-
readonly noLogging?: boolean;
|
|
13
|
-
readonly metadata?: Record<string, unknown>;
|
|
14
|
-
}
|
|
15
|
-
//#endregion
|
|
16
|
-
//#region src/artifacts/lineage.d.ts
|
|
17
|
-
type ArtifactTransformKind = "manual" | "generated" | "extraction" | "chunking" | "transcription" | "resizing" | "provider-packaging" | "tool-result" | "model-output";
|
|
18
|
-
interface ArtifactTransformDescriptor {
|
|
19
|
-
readonly kind: ArtifactTransformKind;
|
|
20
|
-
readonly name?: string;
|
|
21
|
-
readonly metadata?: Record<string, unknown>;
|
|
22
|
-
}
|
|
23
|
-
interface ArtifactParentRef {
|
|
24
|
-
readonly id: string;
|
|
25
|
-
readonly kind: ArtifactKind;
|
|
26
|
-
readonly mediaType?: string;
|
|
27
|
-
readonly source: ArtifactSource;
|
|
28
|
-
readonly label?: string;
|
|
29
|
-
readonly metadata?: Record<string, unknown>;
|
|
30
|
-
readonly privacy: ArtifactPrivacy;
|
|
31
|
-
readonly size?: ArtifactSize;
|
|
32
|
-
readonly fingerprint?: ArtifactFingerprint;
|
|
33
|
-
readonly storage?: ArtifactStorageRef;
|
|
34
|
-
readonly lineage?: ArtifactLineage;
|
|
35
|
-
}
|
|
36
|
-
interface ArtifactLineage {
|
|
37
|
-
readonly parents: readonly ArtifactParentRef[];
|
|
38
|
-
readonly transform: ArtifactTransformDescriptor;
|
|
39
|
-
}
|
|
40
|
-
//#endregion
|
|
41
|
-
//#region src/artifacts/artifact.d.ts
|
|
42
|
-
type ArtifactKind = "text" | "json" | "file" | "image" | "audio" | "video" | "document" | "url" | "tool-result";
|
|
43
|
-
type ProviderUploadArtifactSource = `provider-${"up"}${"load"}`;
|
|
44
|
-
type ArtifactSource = "inline" | "file" | "url" | "generated" | ProviderUploadArtifactSource | "tool";
|
|
45
|
-
type ArtifactPrivacy = NonNullable<PolicySpec["privacy"]>;
|
|
46
|
-
interface ArtifactSize {
|
|
47
|
-
readonly bytes?: number;
|
|
48
|
-
readonly characters?: number;
|
|
49
|
-
readonly pages?: number;
|
|
50
|
-
readonly width?: number;
|
|
51
|
-
readonly height?: number;
|
|
52
|
-
readonly durationMs?: number;
|
|
53
|
-
}
|
|
54
|
-
interface ArtifactFingerprint {
|
|
55
|
-
readonly algorithm: "sha256";
|
|
56
|
-
readonly value: string;
|
|
57
|
-
}
|
|
58
|
-
interface ArtifactStorageRef {
|
|
59
|
-
readonly storeId: string;
|
|
60
|
-
readonly key: string;
|
|
61
|
-
}
|
|
62
|
-
interface ArtifactOptions {
|
|
63
|
-
readonly id?: string;
|
|
64
|
-
readonly mediaType?: string;
|
|
65
|
-
readonly label?: string;
|
|
66
|
-
readonly metadata?: Record<string, unknown>;
|
|
67
|
-
readonly privacy?: ArtifactPrivacy;
|
|
68
|
-
readonly size?: ArtifactSize;
|
|
69
|
-
readonly fingerprint?: ArtifactFingerprint;
|
|
70
|
-
readonly storage?: ArtifactStorageRef;
|
|
71
|
-
readonly lineage?: ArtifactLineage;
|
|
72
|
-
}
|
|
73
|
-
interface ArtifactToolResultOptions extends ArtifactOptions {
|
|
74
|
-
readonly toolName: string;
|
|
75
|
-
readonly callId?: string;
|
|
76
|
-
}
|
|
77
|
-
interface ArtifactDerivedOptions extends ArtifactOptions {
|
|
78
|
-
readonly kind: ArtifactKind;
|
|
79
|
-
readonly source?: ArtifactSource;
|
|
80
|
-
readonly value?: unknown;
|
|
81
|
-
readonly parents: readonly ArtifactRef[];
|
|
82
|
-
readonly transform: ArtifactTransformDescriptor;
|
|
83
|
-
}
|
|
84
|
-
interface ArtifactRef {
|
|
85
|
-
readonly id: string;
|
|
86
|
-
readonly kind: ArtifactKind;
|
|
87
|
-
readonly mediaType?: string;
|
|
88
|
-
readonly source: ArtifactSource;
|
|
89
|
-
readonly label?: string;
|
|
90
|
-
readonly metadata?: Record<string, unknown>;
|
|
91
|
-
readonly privacy: ArtifactPrivacy;
|
|
92
|
-
readonly size?: ArtifactSize;
|
|
93
|
-
readonly fingerprint?: ArtifactFingerprint;
|
|
94
|
-
readonly storage?: ArtifactStorageRef;
|
|
95
|
-
readonly lineage?: ArtifactLineage;
|
|
96
|
-
}
|
|
97
|
-
type ArtifactInput = ArtifactRef & {
|
|
98
|
-
readonly value?: unknown;
|
|
99
|
-
};
|
|
100
|
-
declare const artifact: {
|
|
101
|
-
text(value: string, options?: ArtifactOptions): ArtifactInput;
|
|
102
|
-
json(value: unknown, options?: ArtifactOptions): ArtifactInput;
|
|
103
|
-
file(value: Blob | File | string, options?: ArtifactOptions): ArtifactInput;
|
|
104
|
-
image(value: Blob | File | string, options?: ArtifactOptions): ArtifactInput;
|
|
105
|
-
audio(value: Blob | File | string, options?: ArtifactOptions): ArtifactInput;
|
|
106
|
-
document(value: Blob | File | string, options?: ArtifactOptions): ArtifactInput;
|
|
107
|
-
url(value: string | URL, options?: ArtifactOptions): ArtifactInput;
|
|
108
|
-
toolResult(value: unknown, options: ArtifactToolResultOptions): ArtifactInput;
|
|
109
|
-
derive(input: ArtifactDerivedOptions): ArtifactInput;
|
|
110
|
-
};
|
|
111
|
-
//#endregion
|
|
112
|
-
//#region src/tracing/tracing.d.ts
|
|
113
|
-
interface TracerLike {
|
|
114
|
-
readonly kind: "tracer";
|
|
115
|
-
readonly span?: <T>(name: string, fn: () => T | Promise<T>, attributes?: Record<string, unknown>) => T | Promise<T>;
|
|
116
|
-
readonly event?: (name: string, attributes?: Record<string, unknown>) => void;
|
|
117
|
-
}
|
|
118
|
-
type RunEventKind = "run.start" | "artifact.ingested" | "context.packed" | "router.candidates" | "stage.start" | "stage.complete" | "provider.attempt" | "fallback.activated" | "validation.complete" | "validation.failed" | "artifact.created" | "run.complete" | "run.failed" | "tool.call" | "replay.offline" | "replay.live" | "step.transition" | "recovery.start" | "recovery.complete" | "recovery.failed" | "capabilities.negotiation.fallback";
|
|
119
|
-
interface RunEvent {
|
|
120
|
-
readonly kind: RunEventKind;
|
|
121
|
-
readonly timestamp: string;
|
|
122
|
-
readonly runId: string;
|
|
123
|
-
readonly planId?: string;
|
|
124
|
-
readonly stageId?: string;
|
|
125
|
-
readonly providerId?: string;
|
|
126
|
-
readonly modelId?: string;
|
|
127
|
-
readonly artifactId?: string;
|
|
128
|
-
readonly metadata?: Record<string, unknown>;
|
|
129
|
-
}
|
|
130
|
-
type RunEventSink = (event: RunEvent) => void | Promise<void>;
|
|
131
|
-
//#endregion
|
|
132
|
-
//#region src/contract/bands.d.ts
|
|
133
|
-
/**
|
|
134
|
-
* Hook lifecycle event vocabulary -- separate from RunEventKind by design.
|
|
135
|
-
*
|
|
136
|
-
* Phase 19 (v1.2) additively extends with BEFORE_AGENT_ITERATION and
|
|
137
|
-
* AFTER_AGENT_ITERATION — emitted by `runAgent` around each iteration's
|
|
138
|
-
* provider call. Existing four events continue to fire inside each
|
|
139
|
-
* iteration (BEFORE/AFTER_PROVIDER per native call; BEFORE/AFTER_TOOL
|
|
140
|
-
* per dispatched tool).
|
|
141
|
-
*/
|
|
142
|
-
type HookLifecycleEvent = "BEFORE_PROVIDER" | "AFTER_PROVIDER" | "BEFORE_TOOL" | "AFTER_TOOL" | "BEFORE_AGENT_ITERATION" | "AFTER_AGENT_ITERATION";
|
|
143
|
-
/**
|
|
144
|
-
* SAFETY-band veto mechanism — Phase 19.
|
|
145
|
-
*
|
|
146
|
-
* Handlers can deny an iteration by calling `controls.deny(reason)`. The
|
|
147
|
-
* pipeline records the latest reason and exposes it via `lastDenialReason()`.
|
|
148
|
-
* The reason resets at the start of each `run()` call.
|
|
149
|
-
*
|
|
150
|
-
* Composition convention: the agent runtime invokes BEFORE_AGENT_ITERATION
|
|
151
|
-
* before provider call, then checks `pipeline.lastDenialReason()`. If set,
|
|
152
|
-
* the iteration aborts with `agent-iteration-denied` failure.
|
|
153
|
-
*/
|
|
154
|
-
interface HookDenyDirective {
|
|
155
|
-
readonly reason: string;
|
|
156
|
-
}
|
|
157
|
-
/**
|
|
158
|
-
* Controls passed to each handler as an optional second argument.
|
|
159
|
-
*
|
|
160
|
-
* Backward compat: existing single-argument handlers (Phase 15 + Phase 16)
|
|
161
|
-
* ignore this and continue to work unchanged.
|
|
162
|
-
*/
|
|
163
|
-
interface HookControls {
|
|
164
|
-
/** Set a denial reason; the latest call wins per `run()`. */
|
|
165
|
-
readonly deny: (reason: string) => void;
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Priority bands. Lower number = higher priority (runs first).
|
|
169
|
-
*
|
|
170
|
-
* SAFETY (0) -- safety / breaker hooks; cannot be overridden by lower bands
|
|
171
|
-
* OBSERVABILITY (1) -- logging, metrics, audit; runs after safety, before extension
|
|
172
|
-
* EXTENSION (2) -- user-supplied hooks; runs last
|
|
173
|
-
*
|
|
174
|
-
* Within a band, handlers run in registration order.
|
|
175
|
-
*/
|
|
176
|
-
declare const BAND: {
|
|
177
|
-
readonly SAFETY: 0;
|
|
178
|
-
readonly OBSERVABILITY: 1;
|
|
179
|
-
readonly EXTENSION: 2;
|
|
180
|
-
};
|
|
181
|
-
type Band = typeof BAND[keyof typeof BAND];
|
|
182
|
-
/**
|
|
183
|
-
* Handler input -- frozen snapshot of the caller's context at run() time.
|
|
184
|
-
*
|
|
185
|
-
* structuredClone-then-Object.freeze: handlers receive a deep-cloned,
|
|
186
|
-
* surface-frozen view. Mutations on the handler side do NOT leak back to
|
|
187
|
-
* the calling site.
|
|
188
|
-
*
|
|
189
|
-
* The handler's return value is currently ignored; future revisions may
|
|
190
|
-
* add a typed return that downstream bands consume.
|
|
191
|
-
*/
|
|
192
|
-
interface HookHandler<TContext = unknown> {
|
|
193
|
-
(context: Readonly<TContext>, controls?: HookControls): void | Promise<void>;
|
|
194
|
-
}
|
|
195
|
-
interface RegisterOptions {
|
|
196
|
-
readonly band: Band;
|
|
197
|
-
readonly matcher?: RegExp;
|
|
198
|
-
readonly budgetMs?: number;
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* The HookPipeline interface returned by createHookPipeline().
|
|
202
|
-
*
|
|
203
|
-
* IMMUTABILITY: once freeze() is called, register() throws an Error whose
|
|
204
|
-
* .name === "PIPELINE_FROZEN". freeze() is irreversible by design --
|
|
205
|
-
* protects against late-binding hook injection mid-session.
|
|
206
|
-
*/
|
|
207
|
-
interface HookPipeline {
|
|
208
|
-
readonly kind: "hook-pipeline";
|
|
209
|
-
register<TContext = unknown>(event: HookLifecycleEvent, handler: HookHandler<TContext>, options: RegisterOptions): void;
|
|
210
|
-
freeze(): void;
|
|
211
|
-
isFrozen(): boolean;
|
|
212
|
-
run<TContext = unknown>(event: HookLifecycleEvent, context: TContext): Promise<void>;
|
|
213
|
-
/**
|
|
214
|
-
* Phase 19: returns the latest denial reason set by any handler during
|
|
215
|
-
* the most recent `run()` call. Resets to `null` at the start of each run.
|
|
216
|
-
* Read by the agent runtime to detect SAFETY-band veto.
|
|
217
|
-
*/
|
|
218
|
-
lastDenialReason(): string | null;
|
|
219
|
-
}
|
|
220
|
-
interface CreateHookPipelineOptions {
|
|
221
|
-
readonly tracer?: TracerLike;
|
|
222
|
-
readonly sessionId?: string;
|
|
223
|
-
readonly defaultBudgetMs?: number;
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Factory: build a fresh hook pipeline.
|
|
227
|
-
*/
|
|
228
|
-
declare function createHookPipeline(options?: CreateHookPipelineOptions): HookPipeline;
|
|
229
|
-
//#endregion
|
|
230
|
-
//#region src/contract/invariants.d.ts
|
|
231
|
-
/**
|
|
232
|
-
* Tripwire invariant declaration variants produced by the `inv` fluent
|
|
233
|
-
* builder. Each variant is a frozen value carrying a discriminant `kind`
|
|
234
|
-
* and an `id` (auto-generated or caller-supplied).
|
|
235
|
-
*
|
|
236
|
-
* Phase 8 reshapes the Phase 7 placeholder `{ kind: "policy"|"semantic"|"schema" }`
|
|
237
|
-
* into this discriminated union. Phase 7 never populated `invariants`
|
|
238
|
-
* (see 07-04-SUMMARY decisions), so the change is additive in practice
|
|
239
|
-
* but technically a breaking type change for any external caller that
|
|
240
|
-
* authored a literal of the old shape.
|
|
241
|
-
*/
|
|
242
|
-
interface MustCiteInvariant {
|
|
243
|
-
readonly id: string;
|
|
244
|
-
readonly kind: "must-cite";
|
|
245
|
-
readonly artifactName: string;
|
|
246
|
-
}
|
|
247
|
-
interface FieldFromTableInvariant {
|
|
248
|
-
readonly id: string;
|
|
249
|
-
readonly kind: "field-from-table";
|
|
250
|
-
readonly path: string;
|
|
251
|
-
readonly allowedValues: readonly string[];
|
|
252
|
-
}
|
|
253
|
-
interface NoPiiInvariant {
|
|
254
|
-
readonly id: string;
|
|
255
|
-
readonly kind: "no-pii";
|
|
256
|
-
readonly path: string;
|
|
257
|
-
}
|
|
258
|
-
interface MatchesInvariant<T = unknown> {
|
|
259
|
-
readonly id: string;
|
|
260
|
-
readonly kind: "matches";
|
|
261
|
-
readonly path: string;
|
|
262
|
-
readonly schema: StandardSchemaV1<unknown, T>;
|
|
263
|
-
}
|
|
264
|
-
type InvariantDeclaration = MustCiteInvariant | FieldFromTableInvariant | NoPiiInvariant | MatchesInvariant;
|
|
265
|
-
interface InvariantOptions {
|
|
266
|
-
readonly id?: string;
|
|
267
|
-
}
|
|
268
|
-
/**
|
|
269
|
-
* Fluent builder for tripwire invariants.
|
|
270
|
-
*
|
|
271
|
-
* Each helper returns a frozen `InvariantDeclaration` with an auto-generated
|
|
272
|
-
* id of the form `${kind}-${counter}`. Callers may override the id via the
|
|
273
|
-
* second-positional `options.id` arg.
|
|
274
|
-
*
|
|
275
|
-
* The counter is monotonic across kinds — calling `inv.mustCite("a")` then
|
|
276
|
-
* `inv.fieldFromTable("x", ["y"])` yields ids `must-cite-1` then
|
|
277
|
-
* `field-from-table-2`. This keeps ids globally unique within a process.
|
|
278
|
-
*
|
|
279
|
-
* Note on `inv.matches`: the caller supplies the StandardSchema validator,
|
|
280
|
-
* and the tripwire evaluator trusts whatever `~standard.validate` returns.
|
|
281
|
-
* This is by design — `matches` is the caller-driven escape hatch (see
|
|
282
|
-
* T-08-05 in the 08-01-PLAN threat register).
|
|
283
|
-
*/
|
|
284
|
-
declare const inv: {
|
|
285
|
-
readonly mustCite: (artifactName: string, options?: InvariantOptions) => MustCiteInvariant;
|
|
286
|
-
readonly fieldFromTable: (path: string, allowedValues: readonly string[], options?: InvariantOptions) => FieldFromTableInvariant;
|
|
287
|
-
readonly noPII: (path: string, options?: InvariantOptions) => NoPiiInvariant;
|
|
288
|
-
readonly matches: <T>(path: string, schema: StandardSchemaV1<unknown, T>, options?: InvariantOptions) => MatchesInvariant<T>;
|
|
289
|
-
/**
|
|
290
|
-
* Test-only: reset the auto-id counter. NOT exported from the package
|
|
291
|
-
* root barrel — callers must import `inv` directly from this module if
|
|
292
|
-
* they ever need it, which is intentional friction.
|
|
293
|
-
*/
|
|
294
|
-
readonly __resetCounterForTests: () => void;
|
|
295
|
-
};
|
|
296
|
-
//#endregion
|
|
297
|
-
//#region src/contract/pii-detectors.d.ts
|
|
298
|
-
/**
|
|
299
|
-
* Regex-based PII detectors used by the `no-pii` tripwire invariant.
|
|
300
|
-
*
|
|
301
|
-
* Phase 8 ships four detectors (email, US SSN, Luhn-valid credit card,
|
|
302
|
-
* US phone). They are intentionally regex-only — zero new dependencies —
|
|
303
|
-
* per the v1.1 scope locked in 08-CONTEXT.md.
|
|
304
|
-
*
|
|
305
|
-
* Each detector returns either `{ matched: true, substring }` carrying
|
|
306
|
-
* ONLY the matched fragment, or `{ matched: false }`. The substring shape
|
|
307
|
-
* is required so the tripwire evaluator can emit redacted evidence
|
|
308
|
-
* (Phase 9 receipts must not leak the full input).
|
|
309
|
-
*
|
|
310
|
-
* Detector order in `defaultPiiDetectors` is deterministic so the
|
|
311
|
-
* evaluator's first-violation semantics produce stable receipts.
|
|
312
|
-
*/
|
|
313
|
-
type PiiDetectorResult = {
|
|
314
|
-
readonly matched: true;
|
|
315
|
-
readonly substring: string;
|
|
316
|
-
} | {
|
|
317
|
-
readonly matched: false;
|
|
318
|
-
};
|
|
319
|
-
interface PiiDetector {
|
|
320
|
-
readonly name: string;
|
|
321
|
-
detect(input: string): PiiDetectorResult;
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* Default PII detectors used by `evaluateTripwires` for `no-pii` invariants.
|
|
325
|
-
*
|
|
326
|
-
* Order is deterministic: email, us-ssn, credit-card, us-phone. Callers who
|
|
327
|
-
* need a different set can pass their own list to `evaluateTripwires`.
|
|
328
|
-
*/
|
|
329
|
-
declare const defaultPiiDetectors: readonly PiiDetector[];
|
|
330
|
-
//#endregion
|
|
331
|
-
//#region src/contract/tripwire.d.ts
|
|
332
|
-
/**
|
|
333
|
-
* Evidence emitted when a tripwire invariant fires.
|
|
334
|
-
*
|
|
335
|
-
* `observed` is the SHAPE-MATCHED redacted payload, not the raw output:
|
|
336
|
-
* - for `must-cite`: the citations array as found at the located path
|
|
337
|
-
* - for `field-from-table`: the actual value at `path`
|
|
338
|
-
* - for `no-pii`: ONLY `{ detector, substring }` — never the full input
|
|
339
|
-
* (T-08-01 in the 08-01-PLAN threat register)
|
|
340
|
-
* - for `matches`: the value at `path`
|
|
341
|
-
*
|
|
342
|
-
* Phase 9 receipts will sign this evidence, so leaking the full PII into
|
|
343
|
-
* `observed` would defeat redact-before-sign.
|
|
344
|
-
*/
|
|
345
|
-
interface TripwireEvidence {
|
|
346
|
-
readonly invariantId: string;
|
|
347
|
-
readonly kind: "must-cite" | "field-from-table" | "no-pii" | "matches";
|
|
348
|
-
readonly path: string;
|
|
349
|
-
readonly observed: unknown;
|
|
350
|
-
readonly message: string;
|
|
351
|
-
}
|
|
352
|
-
type TripwireResult = {
|
|
353
|
-
readonly ok: true;
|
|
354
|
-
} | {
|
|
355
|
-
readonly ok: false;
|
|
356
|
-
readonly evidence: TripwireEvidence;
|
|
357
|
-
};
|
|
358
|
-
/**
|
|
359
|
-
* Pure tripwire evaluator.
|
|
360
|
-
*
|
|
361
|
-
* No I/O, no Date.now, no random — same `(output, invariants)` always
|
|
362
|
-
* returns the same `TripwireResult`. Phase 9 receipts can reconstruct the
|
|
363
|
-
* verdict deterministically (T-08-04).
|
|
364
|
-
*
|
|
365
|
-
* Evaluates invariants in declaration order; the FIRST failing invariant
|
|
366
|
-
* aborts and returns its evidence. Subsequent invariants are not evaluated.
|
|
367
|
-
*
|
|
368
|
-
* @param output The provider output to inspect.
|
|
369
|
-
* @param invariants Invariants to evaluate, in declaration order.
|
|
370
|
-
* @param detectors PII detectors used for `no-pii` invariants. Defaults
|
|
371
|
-
* to `defaultPiiDetectors`. Callers can pass a custom
|
|
372
|
-
* list to override.
|
|
373
|
-
*/
|
|
374
|
-
declare function evaluateTripwires(output: unknown, invariants: readonly InvariantDeclaration[], detectors?: readonly PiiDetector[]): Promise<TripwireResult>;
|
|
375
|
-
//#endregion
|
|
376
|
-
//#region src/capabilities/profile.d.ts
|
|
377
|
-
/**
|
|
378
|
-
* Closed enum of the 7 Lattice transport adapters (D-06). Adding a new
|
|
379
|
-
* adapter is a typed breaking change. Phase 34 quirk dispatch reads this
|
|
380
|
-
* field.
|
|
381
|
-
*/
|
|
382
|
-
type CapabilityAdapter = "openrouter" | "anthropic" | "openai" | "openai-compat" | "xai" | "gemini" | "lm-studio";
|
|
383
|
-
/**
|
|
384
|
-
* Closed enum of the 5 training-lineage buckets (D-14). Receipt v1.2
|
|
385
|
-
* (Phase 38) carries this value verbatim via the `modelClass` field.
|
|
386
|
-
* Stable across model patches — gpt-4o-2024-05-13 and gpt-4o-2024-08-06
|
|
387
|
-
* share a trainingClass so receipts remain comparable across rebuilds.
|
|
388
|
-
*/
|
|
389
|
-
type TrainingClass = "frontier_rlhf" | "mid_tier_rlhf" | "open_weight_instruct" | "open_weight_base" | "local_quantized";
|
|
390
|
-
/**
|
|
391
|
-
* Closed enum of the 5 recommended prompt-tuning buckets (research open
|
|
392
|
-
* question 2). DISTINCT from `TrainingClass`: `reasoning` is orthogonal
|
|
393
|
-
* to lineage (a frontier RLHF model with hidden_cot routes to the
|
|
394
|
-
* `reasoning` strategy bucket); `local` is the granularity boundary
|
|
395
|
-
* for the deployed-locally strategy bucket (vs the `local_quantized`
|
|
396
|
-
* lineage signal). Phase 35 prompt-scaffold dispatch reads this field.
|
|
397
|
-
*/
|
|
398
|
-
type RecommendedPromptStrategy = "frontier" | "mid_tier" | "open_weight" | "reasoning" | "local";
|
|
399
|
-
/**
|
|
400
|
-
* Closed enum of the 7 known model-class output-shape failure modes at
|
|
401
|
-
* v1.3.0 (D-12). Adding a member in v1.4+ is an intentional typed
|
|
402
|
-
* breaking change — Phase 36 sanitizer dispatch enforces exhaustiveness
|
|
403
|
-
* via a `_exhaustive: never` switch (see test-d/capabilities.test-d.ts).
|
|
404
|
-
*/
|
|
405
|
-
type KnownFailureMode = "internal_envelope_leak" | "reasoning_tag_leak" | "system_prompt_echo" | "template_artifact_leak" | "hallucinated_tool_name" | "malformed_tool_arguments" | "premature_termination";
|
|
406
|
-
/**
|
|
407
|
-
* Closed enum of the 5 reasoning-surface shapes a model exposes. Drives
|
|
408
|
-
* the Phase 36 sanitizer's choice of leak-cleanup pass (e.g., `<think>`
|
|
409
|
-
* tag stripping for `inlined_tags`).
|
|
410
|
-
*/
|
|
411
|
-
type ReasoningSurface = "none" | "hidden_cot" | "inlined_tags" | "interleaved_thinking" | "streamed_reasoning";
|
|
412
|
-
/**
|
|
413
|
-
* Closed enum of the 5 tool-call surface shapes a model exposes. Drives
|
|
414
|
-
* the Phase 37 tool-call validator's choice of arguments parser.
|
|
415
|
-
*/
|
|
416
|
-
type ToolCallSurface = "none" | "native_strict" | "native_lenient" | "json_only" | "text_only";
|
|
417
|
-
/**
|
|
418
|
-
* Phase 33 — D-05 / D-08 — Capability profile for one (adapter, model)
|
|
419
|
-
* pair. Sibling to `ModelCapability`, not a replacement. Built-time baked
|
|
420
|
-
* via the OpenRouter snapshot generator (Phase 33-03) plus hand-edited
|
|
421
|
-
* supplemental static profiles (Phase 33-04).
|
|
422
|
-
*
|
|
423
|
-
* Canonical key: `${adapter}:${modelId}` — one profile per (adapter,
|
|
424
|
-
* model) pair. `openrouter:openai/gpt-oss-120b` and `openai:gpt-oss-120b`
|
|
425
|
-
* are two distinct entries with the same `originFamily: "openai"`.
|
|
426
|
-
*/
|
|
427
|
-
interface ModelCapabilityProfile {
|
|
428
|
-
/**
|
|
429
|
-
* The model identifier as the adapter sees it. For OpenRouter this is
|
|
430
|
-
* the `vendor/model` shape (e.g., `openai/gpt-oss-120b`); for direct
|
|
431
|
-
* adapters this is the provider's native id (e.g., `claude-opus-4`).
|
|
432
|
-
* Combined with `adapter` to form the canonical lookup key `${adapter}:${id}` (D-08).
|
|
433
|
-
*/
|
|
434
|
-
readonly id: string;
|
|
435
|
-
/**
|
|
436
|
-
* The Lattice transport adapter that ships this profile (D-05 /
|
|
437
|
-
* D-06). Phase 34 adapter-quirk dispatch reads this field. Closed
|
|
438
|
-
* union of 7 values.
|
|
439
|
-
*/
|
|
440
|
-
readonly adapter: CapabilityAdapter;
|
|
441
|
-
/**
|
|
442
|
-
* The model creator (D-07). Open extensible string — new orgs emerge
|
|
443
|
-
* frequently and should not break the type. Examples: `openai`,
|
|
444
|
-
* `anthropic`, `meta`, `mistral`, `google`, `xai`, `deepseek`, `qwen`.
|
|
445
|
-
* Phase 35 prompt-scaffold dispatch falls back to
|
|
446
|
-
* `recommendedPromptStrategy` for unknown originFamily values.
|
|
447
|
-
*/
|
|
448
|
-
readonly originFamily: string;
|
|
449
|
-
/**
|
|
450
|
-
* Training-lineage classification (D-14). Receipt v1.2 `modelClass`
|
|
451
|
-
* (Phase 38) carries this value verbatim. Drives the failure-mode
|
|
452
|
-
* default set in the classifier.
|
|
453
|
-
*/
|
|
454
|
-
readonly trainingClass: TrainingClass;
|
|
455
|
-
/**
|
|
456
|
-
* Shape of the model's reasoning output. Drives the Phase 36
|
|
457
|
-
* sanitizer's reasoning-leak cleanup pass.
|
|
458
|
-
*/
|
|
459
|
-
readonly reasoningSurface: ReasoningSurface;
|
|
460
|
-
/**
|
|
461
|
-
* Shape of the model's tool-call output. Drives the Phase 37
|
|
462
|
-
* tool-call validator's arguments parser.
|
|
463
|
-
*/
|
|
464
|
-
readonly toolCallSurface: ToolCallSurface;
|
|
465
|
-
/**
|
|
466
|
-
* The actual context window the adapter will accept on a request, in
|
|
467
|
-
* tokens. For OpenRouter this is `top_provider.context_length ?? context_length`
|
|
468
|
-
* (Phase 33 Pitfall 2) — what OpenRouter routing actually offers, not
|
|
469
|
-
* the model card's aspirational maximum.
|
|
470
|
-
*/
|
|
471
|
-
readonly contextWindow: number;
|
|
472
|
-
/**
|
|
473
|
-
* Failure modes this model class is known to exhibit (D-14). Class-
|
|
474
|
-
* derived defaults plus per-family overrides. Phase 36 sanitizer
|
|
475
|
-
* dispatch exhaustively switches on each entry.
|
|
476
|
-
*/
|
|
477
|
-
readonly knownFailureModes: readonly KnownFailureMode[];
|
|
478
|
-
/**
|
|
479
|
-
* Recommended prompt-tuning bucket (research open question 2). Phase
|
|
480
|
-
* 35 prompt-scaffold dispatch reads this field. Distinct from
|
|
481
|
-
* `trainingClass` — see `RecommendedPromptStrategy` JSDoc.
|
|
482
|
-
*/
|
|
483
|
-
readonly recommendedPromptStrategy: RecommendedPromptStrategy;
|
|
484
|
-
}
|
|
485
|
-
/**
|
|
486
|
-
* Frozen list of every `KnownFailureMode` member. Useful for exhaustive
|
|
487
|
-
* iteration in downstream tests and Phase 36 sanitizer registration.
|
|
488
|
-
* Adding a new mode requires updating this array AND the
|
|
489
|
-
* `KnownFailureMode` union AND the Phase 36 exhaustive switch — the
|
|
490
|
-
* `satisfies` clause enforces array-vs-union parity at compile time.
|
|
491
|
-
*/
|
|
492
|
-
declare const ALL_KNOWN_FAILURE_MODES: readonly ["internal_envelope_leak", "reasoning_tag_leak", "system_prompt_echo", "template_artifact_leak", "hallucinated_tool_name", "malformed_tool_arguments", "premature_termination"];
|
|
493
|
-
/**
|
|
494
|
-
* Frozen list of every `TrainingClass` member. Useful for exhaustive
|
|
495
|
-
* iteration when constructing the failure-mode defaults table (D-14)
|
|
496
|
-
* and for Phase 38 receipt-class enumeration.
|
|
497
|
-
*/
|
|
498
|
-
declare const ALL_TRAINING_CLASSES: readonly ["frontier_rlhf", "mid_tier_rlhf", "open_weight_instruct", "open_weight_base", "local_quantized"];
|
|
499
|
-
//#endregion
|
|
500
|
-
//#region src/outputs/contracts.d.ts
|
|
501
|
-
type TextOutputContract = "text";
|
|
502
|
-
interface CitationRef {
|
|
503
|
-
readonly artifactId: string;
|
|
504
|
-
readonly label?: string;
|
|
505
|
-
readonly span?: {
|
|
506
|
-
readonly start?: number;
|
|
507
|
-
readonly end?: number;
|
|
508
|
-
};
|
|
509
|
-
readonly metadata?: Record<string, unknown>;
|
|
510
|
-
}
|
|
511
|
-
interface CitationsOutputContract {
|
|
512
|
-
readonly kind: "citations";
|
|
513
|
-
}
|
|
514
|
-
interface ArtifactRefsOutputContract {
|
|
515
|
-
readonly kind: "artifacts";
|
|
516
|
-
readonly artifactKind?: ArtifactKind | string;
|
|
517
|
-
}
|
|
518
|
-
type SchemaOutputContract = StandardSchemaV1;
|
|
519
|
-
type OutputContract = TextOutputContract | SchemaOutputContract | CitationsOutputContract | ArtifactRefsOutputContract;
|
|
520
|
-
type OutputContractMap = Record<string, OutputContract>;
|
|
521
|
-
declare const output: {
|
|
522
|
-
citations(): CitationsOutputContract;
|
|
523
|
-
artifacts(options?: {
|
|
524
|
-
readonly artifactKind?: ArtifactKind | string;
|
|
525
|
-
}): ArtifactRefsOutputContract;
|
|
526
|
-
};
|
|
527
|
-
//#endregion
|
|
528
|
-
//#region src/sessions/session.d.ts
|
|
529
|
-
interface SessionRef {
|
|
530
|
-
readonly id: string;
|
|
531
|
-
readonly kind?: "session-ref";
|
|
532
|
-
}
|
|
533
|
-
interface SessionTurn {
|
|
534
|
-
readonly id: string;
|
|
535
|
-
readonly task: string;
|
|
536
|
-
readonly artifactRefs: readonly ArtifactRef[];
|
|
537
|
-
readonly planId?: string;
|
|
538
|
-
readonly outputArtifactRefs: readonly ArtifactRef[];
|
|
539
|
-
readonly createdAt: string;
|
|
540
|
-
}
|
|
541
|
-
interface SessionSummary {
|
|
542
|
-
readonly id: string;
|
|
543
|
-
readonly artifactRef: ArtifactRef;
|
|
544
|
-
readonly sourceTurnIds: readonly string[];
|
|
545
|
-
readonly trust: "model-summary";
|
|
546
|
-
readonly createdAt: string;
|
|
547
|
-
}
|
|
548
|
-
interface SessionRecord extends SessionRef {
|
|
549
|
-
readonly kind: "session-ref";
|
|
550
|
-
readonly parentId?: string;
|
|
551
|
-
readonly branchPointRunId?: string;
|
|
552
|
-
readonly turns: readonly SessionTurn[];
|
|
553
|
-
readonly summaries: readonly SessionSummary[];
|
|
554
|
-
readonly artifactRefs: readonly ArtifactRef[];
|
|
555
|
-
readonly planIds: readonly string[];
|
|
556
|
-
readonly createdAt: string;
|
|
557
|
-
readonly updatedAt: string;
|
|
558
|
-
}
|
|
559
|
-
interface CreateSessionOptions {
|
|
560
|
-
readonly id?: string;
|
|
561
|
-
readonly parentId?: string;
|
|
562
|
-
readonly branchPointRunId?: string;
|
|
563
|
-
}
|
|
564
|
-
interface AppendSessionTurnInput {
|
|
565
|
-
readonly sessionId: string;
|
|
566
|
-
readonly task: string;
|
|
567
|
-
readonly artifactRefs: readonly ArtifactRef[];
|
|
568
|
-
readonly outputArtifactRefs?: readonly ArtifactRef[];
|
|
569
|
-
readonly planId?: string;
|
|
570
|
-
}
|
|
571
|
-
interface SessionStore {
|
|
572
|
-
readonly kind: "session-store";
|
|
573
|
-
readonly id: string;
|
|
574
|
-
create(options?: CreateSessionOptions): Promise<SessionRecord>;
|
|
575
|
-
load(id: string): Promise<SessionRecord | undefined>;
|
|
576
|
-
save(session: SessionRecord): Promise<SessionRecord>;
|
|
577
|
-
branch(parentId: string, options?: Omit<CreateSessionOptions, "parentId">): Promise<SessionRecord>;
|
|
578
|
-
appendTurn(input: AppendSessionTurnInput): Promise<SessionRecord>;
|
|
579
|
-
}
|
|
580
|
-
interface MemorySessionStoreOptions {
|
|
581
|
-
readonly id?: string;
|
|
582
|
-
}
|
|
583
|
-
declare function createMemorySessionStore(options?: MemorySessionStoreOptions): SessionStore;
|
|
584
|
-
//#endregion
|
|
585
|
-
//#region src/context/context-pack.d.ts
|
|
586
|
-
interface ContextPack extends ContextPackPlan {
|
|
587
|
-
readonly kind: "context-pack";
|
|
588
|
-
}
|
|
589
|
-
interface ContextSummarizer {
|
|
590
|
-
summarize(input: {
|
|
591
|
-
readonly artifacts: readonly ArtifactRef[];
|
|
592
|
-
readonly budgetTokens: number;
|
|
593
|
-
}): Promise<readonly ArtifactRef[]> | readonly ArtifactRef[];
|
|
594
|
-
}
|
|
595
|
-
//#endregion
|
|
596
|
-
//#region src/runtime/survivability.d.ts
|
|
597
|
-
/**
|
|
598
|
-
* MV3-survivability adapter contract -- Phase 5 (FSB v0.10.0-attempt-2).
|
|
599
|
-
*
|
|
600
|
-
* This module is a SIBLING of create-ai.ts (the Lattice runtime facade) and
|
|
601
|
-
* a SIBLING of contract/bands.ts (the hook pipeline factory) and
|
|
602
|
-
* contract/checkpoint.ts (the per-step receipt hook). It does NOT modify
|
|
603
|
-
* any of them; the SurvivabilityAdapter contract is composed from those
|
|
604
|
-
* surfaces by the consumer (FSB's lattice-runtime-adapter.js in Plan 05-05).
|
|
605
|
-
*
|
|
606
|
-
* What is the survivability problem?
|
|
607
|
-
* Some host runtimes can evict the execution context mid-flow with no
|
|
608
|
-
* synchronous shutdown signal:
|
|
609
|
-
* - Chrome MV3 service workers: evicted after 30s silence OR 5min idle.
|
|
610
|
-
* - Cloudflare Workers: evicted at end of each request unless waitUntil.
|
|
611
|
-
* - AWS Lambda: process freeze + thaw across invocations.
|
|
612
|
-
* Lattice's existing runtime (create-ai.ts) assumes the process stays
|
|
613
|
-
* live for the duration of a run. The SurvivabilityAdapter contract is
|
|
614
|
-
* the seam where a host runtime tells Lattice "here is how to serialize
|
|
615
|
-
* my state, here is how to deserialize it back, here is how to resume
|
|
616
|
-
* work after I get evicted and recreated."
|
|
617
|
-
*
|
|
618
|
-
* What this module SHIPS:
|
|
619
|
-
* - SurvivabilityAdapter<TState> interface (4 methods)
|
|
620
|
-
* - SerializedSnapshot type (string-encodable opaque envelope)
|
|
621
|
-
* - EvictionHook<TState> type (pre-eviction callback signature)
|
|
622
|
-
* - ResumePolicy literal-union (post-restore reconstruction verdict)
|
|
623
|
-
* - UnsubscribeFn type
|
|
624
|
-
* - createNoopSurvivabilityAdapter() reference implementation
|
|
625
|
-
*
|
|
626
|
-
* What this module DOES NOT ship:
|
|
627
|
-
* - chrome.storage.session integration (FSB-side; Plan 05-05).
|
|
628
|
-
* - offscreen-document message bus (FSB-side; Plan 05-04).
|
|
629
|
-
* - Auto-wiring into create-ai.ts runtime (deferred indefinitely; the
|
|
630
|
-
* contract is consumer-controlled).
|
|
631
|
-
* - Mid-API-request / mid-tool-dispatch recovery dispatcher (CONSERVATIVE
|
|
632
|
-
* recovery wiring is deferred to a follow-on FSB milestone per
|
|
633
|
-
* CONTEXT.md D-22; only the ResumePolicy taxonomy lands here).
|
|
634
|
-
*
|
|
635
|
-
* Composition conventions (NOT enforced; documented for callers):
|
|
636
|
-
* D-09: onEviction hooks SHOULD register in BAND.SAFETY band on the
|
|
637
|
-
* caller's HookPipeline so they run FIRST per Phase 2 priority
|
|
638
|
-
* ordering. This module does NOT auto-register; it ships the
|
|
639
|
-
* contract only.
|
|
640
|
-
* D-10: serialize(state) MAY include the latest checkpoint receipt
|
|
641
|
-
* envelope (Phase 3 createCheckpointHook output) inside the
|
|
642
|
-
* SerializedSnapshot.payload; deserialize() reconstructs session
|
|
643
|
-
* identifiers from the v1.1 receipt body's step-marker fields
|
|
644
|
-
* (stepName, stepIndex, parentStepName, previousStepName,
|
|
645
|
-
* sessionId, timestamp). The payload is opaque to Lattice -- the
|
|
646
|
-
* host runtime defines the shape.
|
|
647
|
-
*
|
|
648
|
-
* ResumePolicy taxonomy (CD-E resolution per attempt-1 02-04-PLAN.md):
|
|
649
|
-
* - SAFE: the snapshot was captured at a safe boundary (BEFORE_ITERATION
|
|
650
|
-
* or BEFORE_NEXT_ITERATION_SCHEDULE step markers) and can be replayed
|
|
651
|
-
* deterministically. The host runtime may re-arm the loop.
|
|
652
|
-
* - RECOVERY_AMBIGUOUS: the snapshot was captured during a tool dispatch
|
|
653
|
-
* where re-execution risk is non-zero (file write, network POST without
|
|
654
|
-
* Idempotency-Key, side-effecting browser action). Host should escalate
|
|
655
|
-
* to the user before deciding.
|
|
656
|
-
* - ON_ERROR_SW_EVICTION_MID_REQUEST: the eviction happened mid-API-call
|
|
657
|
-
* (the provider request was in flight). 6 of 7 FSB providers do NOT
|
|
658
|
-
* document Idempotency-Key headers; replay risks duplicate charges +
|
|
659
|
-
* duplicate responses. Host should treat the run as failed and surface
|
|
660
|
-
* the error to the user.
|
|
661
|
-
* - ON_ERROR_SW_EVICTION_MID_TOOL_DISPATCH: the eviction happened mid-
|
|
662
|
-
* tool-dispatch (a browser action was in progress). Re-execution risk
|
|
663
|
-
* is similar to mid-API-call but lands in a different recovery branch
|
|
664
|
-
* (the host may inspect the page state before deciding).
|
|
665
|
-
*
|
|
666
|
-
* SerializedSnapshot is intentionally opaque + string-encodable. The
|
|
667
|
-
* host runtime defines the payload shape; Lattice's only requirement
|
|
668
|
-
* is that serialize() followed by deserialize() round-trips the state.
|
|
669
|
-
*
|
|
670
|
-
* Ed25519 receipt envelope contract (carries forward from Phase 1-3):
|
|
671
|
-
* Callers MAY embed a v1.1 ReceiptEnvelope inside SerializedSnapshot.payload
|
|
672
|
-
* for signed checkpoint round-trip. verifyReceipt against the embedded
|
|
673
|
-
* envelope MUST return result.ok === true after a serialize -> deserialize
|
|
674
|
-
* cycle (Test 12). This validates that JSON.stringify + JSON.parse over
|
|
675
|
-
* the envelope preserves the JCS-canonical body bytes used by DSSE PAE.
|
|
676
|
-
*
|
|
677
|
-
* Threat model (Phase 5 CONTEXT.md security block):
|
|
678
|
-
* - PII via serialized state: callers MUST ensure SerializedSnapshot.payload
|
|
679
|
-
* contains only stable identifiers + user-controlled state the user has
|
|
680
|
-
* already consented to persist. Mirrors Phase 2 D-04 receipt-body contract
|
|
681
|
-
* (step-marker fields are stable identifiers, not free-form user input).
|
|
682
|
-
* - Snapshot tampering: the noop adapter does NOT sign the snapshot.
|
|
683
|
-
* Callers that need cryptographic integrity SHOULD embed a signed
|
|
684
|
-
* ReceiptEnvelope inside the payload + verify it on deserialize.
|
|
685
|
-
* Phase 5 ships the contract; signature wrapping is a follow-on.
|
|
686
|
-
*
|
|
687
|
-
* Vocabulary separation (carries forward Phase 2 D-12 + Phase 3 D-02):
|
|
688
|
-
* ResumePolicy is the survivability vocabulary -- separate from
|
|
689
|
-
* RunEventKind (tracing) AND separate from HookLifecycleEvent (bands).
|
|
690
|
-
* The three vocabularies meet only when a host runtime composes them.
|
|
691
|
-
*/
|
|
692
|
-
/**
|
|
693
|
-
* String-encodable opaque snapshot. The host runtime defines the payload
|
|
694
|
-
* shape; Lattice's only requirement is that serialize() followed by
|
|
695
|
-
* deserialize() round-trips the original state object.
|
|
696
|
-
*
|
|
697
|
-
* Why string-encodable? MV3's chrome.storage.session and most cross-process
|
|
698
|
-
* storage layers accept structured-clone-safe values. JSON-string payloads
|
|
699
|
-
* are the lowest-common-denominator that survives MV3 SW eviction +
|
|
700
|
-
* Cloudflare Worker freeze + Lambda thaw. Callers MAY use a richer payload
|
|
701
|
-
* shape (Uint8Array, Blob) IF the host runtime supports it; the contract
|
|
702
|
-
* does not constrain payload format beyond "deserialize round-trips it".
|
|
703
|
-
*/
|
|
704
|
-
interface SerializedSnapshot {
|
|
705
|
-
readonly kind: "survivability-snapshot";
|
|
706
|
-
readonly version: "lattice-survivability/v1";
|
|
707
|
-
readonly payload: string;
|
|
708
|
-
readonly capturedAt: string;
|
|
709
|
-
}
|
|
710
|
-
/**
|
|
711
|
-
* Pre-eviction callback. The host runtime CAN attempt to call this hook
|
|
712
|
-
* before the execution context is evicted, but MAY NOT be able to in
|
|
713
|
-
* every case (MV3 eviction has no synchronous signal -- the SW just
|
|
714
|
-
* stops). Callers should treat onEviction as best-effort: useful for
|
|
715
|
-
* gathering final state when the eviction is announced (e.g., user-
|
|
716
|
-
* initiated stop) but not load-bearing for involuntary eviction.
|
|
717
|
-
*
|
|
718
|
-
* The hook receives the current TState by reference. Mutations on the
|
|
719
|
-
* hook side leak to the caller's state -- this is deliberate (the hook
|
|
720
|
-
* is the LAST chance to update state before eviction). Callers who want
|
|
721
|
-
* structuredClone semantics SHOULD wrap state in their own freeze layer.
|
|
722
|
-
*/
|
|
723
|
-
type EvictionHook<TState> = (state: TState) => void | Promise<void>;
|
|
724
|
-
/**
|
|
725
|
-
* Return value of onEviction(); calling unsubscribes the hook.
|
|
726
|
-
*
|
|
727
|
-
* Idempotent -- calling twice has the same effect as calling once.
|
|
728
|
-
*/
|
|
729
|
-
type UnsubscribeFn = () => void;
|
|
730
|
-
/**
|
|
731
|
-
* Resume policy taxonomy. The host runtime calls adapter.resume(snapshot)
|
|
732
|
-
* after eviction + restore; the returned policy tells the host runtime
|
|
733
|
-
* how to react.
|
|
734
|
-
*
|
|
735
|
-
* The 4 literal members carry forward from FSB v0.10.0-attempt-1's
|
|
736
|
-
* 02-04-PLAN.md CONSERVATIVE recovery dispatch (preserved at
|
|
737
|
-
* .planning/milestones/v0.10.0-attempt-1-pre-pivot/02-state-inspectability-
|
|
738
|
-
* carve-out/02-04-PLAN.md). Per CONTEXT.md CD-E this is the locked union.
|
|
739
|
-
*/
|
|
740
|
-
type ResumePolicy = "SAFE" | "RECOVERY_AMBIGUOUS" | "ON_ERROR_SW_EVICTION_MID_REQUEST" | "ON_ERROR_SW_EVICTION_MID_TOOL_DISPATCH";
|
|
741
|
-
/**
|
|
742
|
-
* The SurvivabilityAdapter contract. Host runtimes implement this; Lattice
|
|
743
|
-
* runs against the interface.
|
|
744
|
-
*
|
|
745
|
-
* 4 methods (D-08 locked):
|
|
746
|
-
* - serialize(state): convert in-memory state to SerializedSnapshot
|
|
747
|
-
* - deserialize(snapshot): inverse of serialize
|
|
748
|
-
* - onEviction(hook): register a best-effort pre-eviction callback
|
|
749
|
-
* - resume(snapshot): return ResumePolicy verdict for the post-restore
|
|
750
|
-
* reconstruction. The host runtime acts on the policy.
|
|
751
|
-
*
|
|
752
|
-
* Adapters are POLYMORPHIC over TState -- the host runtime parameterizes
|
|
753
|
-
* the type. Lattice's vitest covers the contract surface with a noop
|
|
754
|
-
* adapter where TState = Record<string, unknown> for ergonomics.
|
|
755
|
-
*/
|
|
756
|
-
interface SurvivabilityAdapter<TState> {
|
|
757
|
-
readonly kind: "survivability-adapter";
|
|
758
|
-
readonly id: string;
|
|
759
|
-
serialize(state: TState): SerializedSnapshot;
|
|
760
|
-
deserialize(snapshot: SerializedSnapshot): TState;
|
|
761
|
-
onEviction(hook: EvictionHook<TState>): UnsubscribeFn;
|
|
762
|
-
resume(snapshot: SerializedSnapshot): Promise<ResumePolicy>;
|
|
763
|
-
}
|
|
764
|
-
/**
|
|
765
|
-
* Factory options for the reference noop adapter.
|
|
766
|
-
*
|
|
767
|
-
* - id: optional. Defaults to "noop-survivability". Useful when callers
|
|
768
|
-
* want to distinguish multiple adapter instances in test fixtures.
|
|
769
|
-
* - policy: optional. Sets the default ResumePolicy returned by resume().
|
|
770
|
-
* Defaults to "SAFE" (matches noop adapter semantics: no recovery
|
|
771
|
-
* ambiguity if nothing was ever persisted).
|
|
772
|
-
*/
|
|
773
|
-
interface NoopSurvivabilityAdapterOptions {
|
|
774
|
-
readonly id?: string;
|
|
775
|
-
readonly policy?: ResumePolicy;
|
|
776
|
-
}
|
|
777
|
-
/**
|
|
778
|
-
* Reference implementation of SurvivabilityAdapter<TState>. Records
|
|
779
|
-
* eviction events but does NOT persist; serialize / deserialize round-
|
|
780
|
-
* trip via JSON.stringify / JSON.parse. Analog to createFakeProvider
|
|
781
|
-
* in the providers/ module -- gives Lattice's vitest a complete shape-
|
|
782
|
-
* conformance target before the real (FSB-side) adapter ships in
|
|
783
|
-
* Plan 05-05.
|
|
784
|
-
*
|
|
785
|
-
* Per CONTEXT.md D-11 the noop adapter ships in Lattice (not FSB)
|
|
786
|
-
* because it covers the contract surface in Lattice's own test suite;
|
|
787
|
-
* FSB's real chrome.storage.session-backed adapter is glue layer.
|
|
788
|
-
*/
|
|
789
|
-
declare function createNoopSurvivabilityAdapter<TState = Record<string, unknown>>(options?: NoopSurvivabilityAdapterOptions): SurvivabilityAdapter<TState>;
|
|
790
|
-
//#endregion
|
|
791
|
-
//#region src/tools/tools.d.ts
|
|
792
|
-
interface ToolExecutionContext {
|
|
793
|
-
readonly signal?: AbortSignal;
|
|
794
|
-
readonly emit?: RunEventSink;
|
|
795
|
-
}
|
|
796
|
-
interface ToolDefinition<TSchema extends StandardSchemaV1 = StandardSchemaV1> {
|
|
797
|
-
readonly kind: "tool";
|
|
798
|
-
readonly name: string;
|
|
799
|
-
readonly description?: string;
|
|
800
|
-
readonly inputSchema: TSchema;
|
|
801
|
-
readonly execute: (input: StandardSchemaV1.InferOutput<TSchema>, context: ToolExecutionContext) => Promise<unknown> | unknown;
|
|
802
|
-
}
|
|
803
|
-
interface ToolCallResult {
|
|
804
|
-
readonly callId: string;
|
|
805
|
-
readonly toolName: string;
|
|
806
|
-
readonly artifact: ArtifactInput;
|
|
807
|
-
}
|
|
808
|
-
declare function defineTool<TSchema extends StandardSchemaV1>(definition: Omit<ToolDefinition<TSchema>, "kind">): ToolDefinition<TSchema>;
|
|
809
|
-
declare function runTool<TSchema extends StandardSchemaV1>(tool: ToolDefinition<TSchema>, input: unknown, context?: ToolExecutionContext): Promise<ToolCallResult>;
|
|
810
|
-
interface McpLikeClient {
|
|
811
|
-
readonly listTools?: () => Promise<readonly McpToolDescriptor[]> | readonly McpToolDescriptor[];
|
|
812
|
-
readonly callTool: (input: {
|
|
813
|
-
readonly name: string;
|
|
814
|
-
readonly arguments: unknown;
|
|
815
|
-
}) => Promise<unknown> | unknown;
|
|
816
|
-
}
|
|
817
|
-
interface McpToolDescriptor {
|
|
818
|
-
readonly name: string;
|
|
819
|
-
readonly description?: string;
|
|
820
|
-
readonly inputSchema: StandardSchemaV1;
|
|
821
|
-
}
|
|
822
|
-
declare function importMcpTools(client: McpLikeClient, toolNames?: readonly string[]): Promise<readonly ToolDefinition[]>;
|
|
823
|
-
declare function toolArtifactRef(result: ToolCallResult): ArtifactRef;
|
|
824
|
-
//#endregion
|
|
825
|
-
//#region src/agent/format-tools.d.ts
|
|
826
|
-
/**
|
|
827
|
-
* One turn in the running conversation.
|
|
828
|
-
*
|
|
829
|
-
* `role: "tool"` is used for tool-result turns; `toolCallId` and `toolName`
|
|
830
|
-
* are populated so the model can correlate the result with its prior
|
|
831
|
-
* `tool_call` envelope.
|
|
832
|
-
*/
|
|
833
|
-
interface ConversationTurn {
|
|
834
|
-
readonly role: "user" | "assistant" | "tool";
|
|
835
|
-
readonly content: string;
|
|
836
|
-
readonly toolCallId?: string;
|
|
837
|
-
readonly toolName?: string;
|
|
838
|
-
}
|
|
839
|
-
type FormatToolsMode = "native" | "prompt-reencoded" | "auto";
|
|
840
|
-
interface FormatToolsOptions {
|
|
841
|
-
/**
|
|
842
|
-
* Tool-use protocol mode. Defaults to `"auto"`, which currently resolves
|
|
843
|
-
* to `"prompt-reencoded"` for ALL 7 providers (Phase 19 simplification —
|
|
844
|
-
* native tool_use deferred to a follow-on milestone). Reserved for
|
|
845
|
-
* forward compatibility.
|
|
846
|
-
*/
|
|
847
|
-
readonly mode?: FormatToolsMode;
|
|
848
|
-
/**
|
|
849
|
-
* Optional system prompt to prepend. Useful for setting persona /
|
|
850
|
-
* domain-specific instructions on top of the tool-use envelope.
|
|
851
|
-
*/
|
|
852
|
-
readonly system?: string;
|
|
853
|
-
}
|
|
854
|
-
interface FormattedToolsHandle {
|
|
855
|
-
/**
|
|
856
|
-
* Builds the single `task` string passed to `ProviderAdapter.execute()`.
|
|
857
|
-
* Encodes the conversation, available tools, and response-envelope
|
|
858
|
-
* instructions.
|
|
859
|
-
*/
|
|
860
|
-
readonly buildTask: (conversation: readonly ConversationTurn[]) => string;
|
|
861
|
-
/**
|
|
862
|
-
* Phase 39 (v1.3): body-only sibling of `buildTask` — identical turn
|
|
863
|
-
* rendering minus the leading system block, so the byte-stable
|
|
864
|
-
* `describeForSystem()` prefix can be hoisted once per crew for
|
|
865
|
-
* prompt-cache sharing without duplication (39-05).
|
|
866
|
-
*
|
|
867
|
-
* Invariant: `describeForSystem() + "\n" + buildTaskBody(conversation)`
|
|
868
|
-
* reconstructs `buildTask(conversation)` byte-for-byte.
|
|
869
|
-
*/
|
|
870
|
-
readonly buildTaskBody: (conversation: readonly ConversationTurn[]) => string;
|
|
871
|
-
/**
|
|
872
|
-
* Parses the assistant's response text. Returns:
|
|
873
|
-
* - `ToolUseRequest[]` when the response contains one or more tool-call
|
|
874
|
-
* envelopes (parsed in declaration order).
|
|
875
|
-
* - `null` when the response is a final answer (no tool-call envelopes
|
|
876
|
-
* detected).
|
|
877
|
-
*
|
|
878
|
-
* The parser is forgiving: it tolerates extra prose around the JSON
|
|
879
|
-
* envelope (markdown fences, leading explanations) and the model
|
|
880
|
-
* occasionally drifting on whitespace.
|
|
881
|
-
*/
|
|
882
|
-
readonly parseToolUse: (responseText: string) => ReadonlyArray<ToolUseRequest> | null;
|
|
883
|
-
/**
|
|
884
|
-
* Returns the static system block describing available tools. Useful for
|
|
885
|
-
* tracing / logging the exact tool-description text fed to the model.
|
|
886
|
-
*/
|
|
887
|
-
readonly describeForSystem: () => string;
|
|
888
|
-
/**
|
|
889
|
-
* Effective mode this handle resolved to (`"prompt-reencoded"` for all
|
|
890
|
-
* v1.2 providers). Exposed for inspectability.
|
|
891
|
-
*/
|
|
892
|
-
readonly mode: "prompt-reencoded";
|
|
893
|
-
}
|
|
894
|
-
/**
|
|
895
|
-
* Convert a Standard Schema to a JSON Schema-shaped descriptor suitable for
|
|
896
|
-
* inclusion in an LLM tool description. Standard Schema vendors can
|
|
897
|
-
* optionally expose `toJSONSchema` on their schema objects; when absent,
|
|
898
|
-
* we fall back to a minimal structural description that lists the schema
|
|
899
|
-
* vendor + version + a placeholder. Models tolerate placeholder schemas in
|
|
900
|
-
* practice because the tool description is supplementary — what matters
|
|
901
|
-
* is the envelope contract (`{tool_call: {name, args}}`).
|
|
902
|
-
*/
|
|
903
|
-
declare function toolSchemaToJsonSchema(schema: StandardSchemaV1): unknown;
|
|
904
|
-
/**
|
|
905
|
-
* Builds the prompt-reencoded tool-use protocol handle for any provider.
|
|
906
|
-
*
|
|
907
|
-
* Phase 19 ships a uniform implementation across all 7 logical providers
|
|
908
|
-
* (openai, openai-compat, anthropic, gemini, xai, openrouter, lm-studio).
|
|
909
|
-
* The `providerName` argument is accepted for forward compatibility but
|
|
910
|
-
* does not branch the implementation in v1.2.
|
|
911
|
-
*/
|
|
912
|
-
declare function formatToolsForProvider(providerName: string, tools: ReadonlyArray<ToolDefinition<StandardSchemaV1>>, options?: FormatToolsOptions): FormattedToolsHandle;
|
|
913
|
-
declare function parseToolUseEnvelope(responseText: string): ReadonlyArray<ToolUseRequest> | null;
|
|
914
|
-
//#endregion
|
|
915
|
-
//#region src/agent/host.d.ts
|
|
916
|
-
/**
|
|
917
|
-
* Snapshot shape the agent loop serializes between iterations. The full
|
|
918
|
-
* shape is opaque to callers (they only see it through SerializedSnapshot
|
|
919
|
-
* via the configured SurvivabilityAdapter) but it's exported so reference
|
|
920
|
-
* implementations and tests can inspect the round-trip.
|
|
921
|
-
*/
|
|
922
|
-
interface AgentSnapshot {
|
|
923
|
-
readonly version: "agent-snapshot/v1";
|
|
924
|
-
readonly iterationIndex: number;
|
|
925
|
-
readonly conversation: readonly ConversationTurn[];
|
|
926
|
-
readonly cumulativeUsage: Usage;
|
|
927
|
-
readonly providerName: string;
|
|
928
|
-
readonly capturedAt: string;
|
|
929
|
-
/**
|
|
930
|
-
* Phase 39 (v1.3): dispatch ancestry chain of crew `AgentSpec` ids
|
|
931
|
-
* (root-first). Absent = root agent (single-agent runs never set it).
|
|
932
|
-
* Optional so existing serialized `agent-snapshot/v1` snapshots
|
|
933
|
-
* deserialize unchanged — the version literal stays `"agent-snapshot/v1"`
|
|
934
|
-
* (D-05; Pitfall 8). The crew dispatcher threads the chain through
|
|
935
|
-
* dispatch context in 39-05; cycle prevention rejects any dispatch whose
|
|
936
|
-
* target id already appears in the chain.
|
|
937
|
-
*/
|
|
938
|
-
readonly ancestry?: readonly string[];
|
|
939
|
-
}
|
|
940
|
-
/**
|
|
941
|
-
* Scheduler seam — controls how the agent loop yields between iterations.
|
|
942
|
-
*
|
|
943
|
-
* `scheduleNext(iterationIndex)` is called AFTER an AFTER_AGENT_ITERATION
|
|
944
|
-
* emission and BEFORE the next iteration's BEFORE_AGENT_ITERATION. The
|
|
945
|
-
* scheduler decides when to resume — synchronously (sync loop), on next
|
|
946
|
-
* tick (setTimeout/queueMicrotask), via a queue (Durable Object), or any
|
|
947
|
-
* other strategy.
|
|
948
|
-
*
|
|
949
|
-
* Default (noop): resolves immediately.
|
|
950
|
-
*/
|
|
951
|
-
interface AgentScheduler {
|
|
952
|
-
scheduleNext(iterationIndex: number): Promise<void>;
|
|
953
|
-
}
|
|
954
|
-
/**
|
|
955
|
-
* Transport seam — controls how a provider call is dispatched.
|
|
956
|
-
*
|
|
957
|
-
* `call(provider, request)` wraps the provider's `execute()` invocation.
|
|
958
|
-
* Default (noop): pass-through (`provider.execute!(request)`). Cross-process
|
|
959
|
-
* bridges (FSB's offscreen-document host) override to dispatch via
|
|
960
|
-
* `chrome.runtime.sendMessage`.
|
|
961
|
-
*
|
|
962
|
-
* Per the Phase 19 INV-03 parity invariant, the transport seam does NOT
|
|
963
|
-
* modify the `ProviderAdapter` interface — it operates on top of the
|
|
964
|
-
* existing `execute()` method.
|
|
965
|
-
*/
|
|
966
|
-
interface AgentTransport {
|
|
967
|
-
call(provider: ProviderAdapter, request: ProviderRunRequest): Promise<ProviderRunResponse>;
|
|
968
|
-
}
|
|
969
|
-
/**
|
|
970
|
-
* Storage seam — controls how agent state persists between iterations for
|
|
971
|
-
* resume after host eviction.
|
|
972
|
-
*
|
|
973
|
-
* Phase 20 composes this with the Phase 18 `SurvivabilityAdapter`:
|
|
974
|
-
* - The adapter serializes `AgentSnapshot` to `SerializedSnapshot` on
|
|
975
|
-
* each AFTER_AGENT_ITERATION; storage.save() persists the snapshot.
|
|
976
|
-
* - On run start, the agent loop calls storage.load(). If a non-null
|
|
977
|
-
* snapshot is returned, the adapter deserializes it; the loop resumes
|
|
978
|
-
* at the recorded iteration index.
|
|
979
|
-
* - On success, the loop calls storage.clear() so the next run starts
|
|
980
|
-
* fresh.
|
|
981
|
-
*
|
|
982
|
-
* Default (noop): save() is a no-op, load() returns null, clear() is a
|
|
983
|
-
* no-op. Suitable for Node tests where eviction never occurs.
|
|
984
|
-
*/
|
|
985
|
-
interface AgentStorage {
|
|
986
|
-
save(snapshot: SerializedSnapshot): Promise<void>;
|
|
987
|
-
load(): Promise<SerializedSnapshot | null>;
|
|
988
|
-
clear(): Promise<void>;
|
|
989
|
-
}
|
|
990
|
-
/**
|
|
991
|
-
* The host adapter — three optional seams, all swappable independently.
|
|
992
|
-
*
|
|
993
|
-
* Callers pass `host` on `AgentIntent`. The agent runtime falls back to
|
|
994
|
-
* `createNoopAgentHost()` when `intent.host` is absent (so Phase 19
|
|
995
|
-
* single-shot Node usage continues to work without explicit configuration).
|
|
996
|
-
*/
|
|
997
|
-
interface AgentHost {
|
|
998
|
-
readonly kind: "agent-host";
|
|
999
|
-
readonly scheduler?: AgentScheduler;
|
|
1000
|
-
readonly transport?: AgentTransport;
|
|
1001
|
-
readonly storage?: AgentStorage;
|
|
1002
|
-
}
|
|
1003
|
-
/**
|
|
1004
|
-
* Reference implementation suitable for Node tests + the Phase 19 default
|
|
1005
|
-
* behavior.
|
|
1006
|
-
*
|
|
1007
|
-
* - scheduler: resolves immediately (no yield between iterations).
|
|
1008
|
-
* - transport: pass-through to provider.execute().
|
|
1009
|
-
* - storage: save() / clear() are no-ops; load() always returns null.
|
|
1010
|
-
*
|
|
1011
|
-
* Equivalent to passing no host at all.
|
|
1012
|
-
*/
|
|
1013
|
-
declare function createNoopAgentHost(): AgentHost;
|
|
1014
|
-
//#endregion
|
|
1015
|
-
//#region src/contract/contract.d.ts
|
|
1016
|
-
/**
|
|
1017
|
-
* Budget invariant declaration attached to a CapabilityContract.
|
|
1018
|
-
*
|
|
1019
|
-
* Phase 7 implements `maxCostUsd` enforcement at pre-flight. The
|
|
1020
|
-
* `p95LatencyMs` field is declared per CONTRACT-02 but is informational
|
|
1021
|
-
* only in Phase 7 — latency observations are wired in a later phase.
|
|
1022
|
-
*
|
|
1023
|
-
* Phase 19 (v1.2) adds `maxIterations` and `maxWallTimeMs` for the agent
|
|
1024
|
-
* runtime. Both are additive and optional; non-agent callers ignore them.
|
|
1025
|
-
* `maxIterations` caps the number of `runAgent` iterations; `maxWallTimeMs`
|
|
1026
|
-
* caps wall-clock duration per `runAgent` invocation. Both are enforced
|
|
1027
|
-
* pre-iteration in the agent loop.
|
|
1028
|
-
*/
|
|
1029
|
-
interface BudgetInvariant {
|
|
1030
|
-
readonly maxCostUsd?: number;
|
|
1031
|
-
readonly maxIterations?: number;
|
|
1032
|
-
readonly maxWallTimeMs?: number;
|
|
1033
|
-
readonly p95LatencyMs?: number;
|
|
1034
|
-
}
|
|
1035
|
-
/**
|
|
1036
|
-
* Quality-floor invariant.
|
|
1037
|
-
*
|
|
1038
|
-
* `suite` is a fixture-directory path string; `minScore` is in 0..1.
|
|
1039
|
-
* Phase 7 forwards this into the pre-flight evaluator but only enforces
|
|
1040
|
-
* capability-side rejects. Full enforcement lives in Phase 12 (`lattice eval`).
|
|
1041
|
-
*/
|
|
1042
|
-
interface QualityFloorInvariant {
|
|
1043
|
-
readonly suite: string;
|
|
1044
|
-
readonly minScore: number;
|
|
1045
|
-
}
|
|
1046
|
-
/**
|
|
1047
|
-
* The full Capability Contract attached to `RunIntent.contract`.
|
|
1048
|
-
*
|
|
1049
|
-
* All fields are optional. v1.0 callers compile and run unchanged when
|
|
1050
|
-
* the field is omitted entirely. PROJECT.md explicitly rejects mandatory
|
|
1051
|
-
* contracts.
|
|
1052
|
-
*/
|
|
1053
|
-
interface CapabilityContract {
|
|
1054
|
-
readonly kind: "capability-contract";
|
|
1055
|
-
readonly budget?: BudgetInvariant;
|
|
1056
|
-
readonly invariants?: readonly InvariantDeclaration[];
|
|
1057
|
-
readonly qualityFloor?: QualityFloorInvariant;
|
|
1058
|
-
readonly requiredModalities?: readonly CapabilityModality[];
|
|
1059
|
-
readonly requiredPrivacy?: "standard" | "sensitive" | "restricted";
|
|
1060
|
-
}
|
|
1061
|
-
/**
|
|
1062
|
-
* Reject-reason taxonomy added to `RouteRejectReason.code` by Phase 7's
|
|
1063
|
-
* pre-flight evaluator. Closed four-value union per the locked decisions
|
|
1064
|
-
* in 07-CONTEXT.md.
|
|
1065
|
-
*/
|
|
1066
|
-
type ContractRejectReasonCode = "contract-budget-exceeded" | "contract-quality-floor" | "contract-modality-missing" | "contract-privacy-mismatch";
|
|
1067
|
-
/** Input shape accepted by `contract()`. Mirrors `CapabilityContract` minus `kind`. */
|
|
1068
|
-
interface CapabilityContractInput {
|
|
1069
|
-
readonly budget?: BudgetInvariant;
|
|
1070
|
-
readonly invariants?: readonly InvariantDeclaration[];
|
|
1071
|
-
readonly qualityFloor?: QualityFloorInvariant;
|
|
1072
|
-
readonly requiredModalities?: readonly CapabilityModality[];
|
|
1073
|
-
readonly requiredPrivacy?: "standard" | "sensitive" | "restricted";
|
|
1074
|
-
}
|
|
1075
|
-
/**
|
|
1076
|
-
* Factory for `CapabilityContract` values.
|
|
1077
|
-
*
|
|
1078
|
-
* Mirrors the `output()` and adapter factory style — exact-optional safe
|
|
1079
|
-
* (does not emit `field: undefined` properties under `exactOptionalPropertyTypes`).
|
|
1080
|
-
* Returns a frozen value with frozen nested objects so downstream code can
|
|
1081
|
-
* rely on structural immutability when canonicalizing in Phase 9.
|
|
1082
|
-
*/
|
|
1083
|
-
declare function contract(input?: CapabilityContractInput): CapabilityContract;
|
|
1084
|
-
//#endregion
|
|
1085
|
-
//#region src/outputs/infer.d.ts
|
|
1086
|
-
type InferOutput<C> = C extends "text" ? string : C extends StandardSchemaV1 ? StandardSchemaV1.InferOutput<C> : C extends CitationsOutputContract ? readonly CitationRef[] : C extends ArtifactRefsOutputContract ? readonly ArtifactRef[] : never;
|
|
1087
|
-
type InferOutputMap<T extends OutputContractMap> = { readonly [K in keyof T]: InferOutput<T[K]> };
|
|
1088
|
-
//#endregion
|
|
1089
|
-
//#region src/results/errors.d.ts
|
|
1090
|
-
interface ValidationIssue {
|
|
1091
|
-
readonly message: string;
|
|
1092
|
-
readonly path?: readonly (string | number | symbol)[];
|
|
1093
|
-
}
|
|
1094
|
-
interface ValidationError {
|
|
1095
|
-
readonly kind: "validation";
|
|
1096
|
-
readonly message: string;
|
|
1097
|
-
readonly output?: string;
|
|
1098
|
-
readonly issues: readonly ValidationIssue[];
|
|
1099
|
-
}
|
|
1100
|
-
interface ExecutionUnavailableError {
|
|
1101
|
-
readonly kind: "execution_unavailable";
|
|
1102
|
-
readonly message: string;
|
|
1103
|
-
}
|
|
1104
|
-
interface NoRouteError {
|
|
1105
|
-
readonly kind: "no_route";
|
|
1106
|
-
readonly message: string;
|
|
1107
|
-
readonly reasons: readonly string[];
|
|
1108
|
-
}
|
|
1109
|
-
interface ProviderExecutionError {
|
|
1110
|
-
readonly kind: "provider_execution";
|
|
1111
|
-
readonly message: string;
|
|
1112
|
-
readonly providerId?: string;
|
|
1113
|
-
readonly modelId?: string;
|
|
1114
|
-
}
|
|
1115
|
-
interface TimeoutError {
|
|
1116
|
-
readonly kind: "timeout";
|
|
1117
|
-
readonly message: string;
|
|
1118
|
-
}
|
|
1119
|
-
/**
|
|
1120
|
-
* Phase 7 addition: emitted by the runtime when no candidate route can
|
|
1121
|
-
* satisfy the caller-supplied `CapabilityContract` (budget, modality,
|
|
1122
|
-
* privacy, or quality-floor invariants).
|
|
1123
|
-
*
|
|
1124
|
-
* `noRouteReasons` carries the full deterministic-router rejection list
|
|
1125
|
-
* so callers can inspect per-candidate detail. Phase 9 (receipts) will
|
|
1126
|
-
* persist this array for deterministic verdict reconstruction.
|
|
1127
|
-
*/
|
|
1128
|
-
interface NoContractMatchError {
|
|
1129
|
-
readonly kind: "no-contract-match";
|
|
1130
|
-
readonly message: string;
|
|
1131
|
-
readonly noRouteReasons: readonly RouteRejectReason[];
|
|
1132
|
-
}
|
|
1133
|
-
/**
|
|
1134
|
-
* Phase 8 addition: emitted when a `CapabilityContract.invariants` tripwire
|
|
1135
|
-
* fires after the provider returned a schema-valid output. Carries the
|
|
1136
|
-
* `TripwireEvidence` produced by `evaluateTripwires`.
|
|
1137
|
-
*
|
|
1138
|
-
* `terminal: true` is a structural marker — combined with the `isTerminal()`
|
|
1139
|
-
* predicate it tells the fallback chain in `runWithConfig` to refuse retry.
|
|
1140
|
-
* `NoContractMatchError` does NOT carry the field (to avoid breaking Phase 7
|
|
1141
|
-
* callers) but `isTerminal()` still returns true for it via the kind check.
|
|
1142
|
-
*/
|
|
1143
|
-
interface TripwireViolationError {
|
|
1144
|
-
readonly kind: "tripwire-violated";
|
|
1145
|
-
readonly message: string;
|
|
1146
|
-
readonly invariantId: string;
|
|
1147
|
-
readonly evidence: TripwireEvidence;
|
|
1148
|
-
readonly terminal: true;
|
|
1149
|
-
}
|
|
1150
|
-
type LatticeRunError = ValidationError | ExecutionUnavailableError | NoRouteError | ProviderExecutionError | TimeoutError | NoContractMatchError | TripwireViolationError;
|
|
1151
|
-
/**
|
|
1152
|
-
* Returns `true` for run errors that MUST NOT be retried by the fallback
|
|
1153
|
-
* chain. Phase 8 covers two kinds:
|
|
1154
|
-
*
|
|
1155
|
-
* - `tripwire-violated` — the contract's invariants rejected the output;
|
|
1156
|
-
* a different provider will not change the verdict, so retry burns
|
|
1157
|
-
* budget for no gain (T-08-06 in 08-02-PLAN threat register).
|
|
1158
|
-
* - `no-contract-match` — no route satisfies the contract at all; the
|
|
1159
|
-
* run never executed and no retry will help.
|
|
1160
|
-
*
|
|
1161
|
-
* All other error kinds return `false` and remain eligible for fallback.
|
|
1162
|
-
* The predicate is exported so Phase 12's eval gate and any user-side
|
|
1163
|
-
* retry wrappers can share one source of truth.
|
|
1164
|
-
*/
|
|
1165
|
-
declare function isTerminal(error: LatticeRunError): boolean;
|
|
1166
|
-
//#endregion
|
|
1167
|
-
//#region src/agent/types.d.ts
|
|
1168
|
-
/**
|
|
1169
|
-
* Per-iteration record stored on `AgentSuccess.iterations` for inspectability.
|
|
1170
|
-
*
|
|
1171
|
-
* `toolCalls` carries content-addressed args/result hashes (sha256) so
|
|
1172
|
-
* downstream receipts can reference them without inlining the bodies.
|
|
1173
|
-
*
|
|
1174
|
-
* `deniedReason` is populated on iterations whose `BEFORE_AGENT_ITERATION`
|
|
1175
|
-
* SAFETY-band handler set `controls.deny(...)`.
|
|
1176
|
-
*/
|
|
1177
|
-
interface IterationRecord {
|
|
1178
|
-
readonly index: number;
|
|
1179
|
-
readonly provider: string;
|
|
1180
|
-
readonly promptTokens: number;
|
|
1181
|
-
readonly completionTokens: number;
|
|
1182
|
-
readonly costUsd: number | null;
|
|
1183
|
-
readonly durationMs: number;
|
|
1184
|
-
readonly toolCalls: ReadonlyArray<{
|
|
1185
|
-
readonly id: string;
|
|
1186
|
-
readonly name: string;
|
|
1187
|
-
readonly argsHash: string;
|
|
1188
|
-
readonly resultHash: string;
|
|
1189
|
-
}>;
|
|
1190
|
-
readonly deniedReason?: string;
|
|
1191
|
-
readonly receipt?: ReceiptEnvelope;
|
|
1192
|
-
}
|
|
1193
|
-
/**
|
|
1194
|
-
* Input shape accepted by `ai.runAgent(intent)`.
|
|
1195
|
-
*
|
|
1196
|
-
* All fields except `task` and `tools` are optional. The runtime supplies
|
|
1197
|
-
* sensible defaults (in-process host, fresh pipeline, no signer, no tracer).
|
|
1198
|
-
*
|
|
1199
|
-
* `TOutputs` parameterizes the final-answer schema map; defaults to a free-form
|
|
1200
|
-
* `{ answer: "text" }` shape when the field is omitted. Validation runs once
|
|
1201
|
-
* against the final assistant message (no intermediate iteration validation).
|
|
1202
|
-
*/
|
|
1203
|
-
interface AgentIntent<TOutputs extends OutputContractMap = OutputContractMap> {
|
|
1204
|
-
readonly task: string;
|
|
1205
|
-
readonly tools: ReadonlyArray<ToolDefinition<StandardSchemaV1>>;
|
|
1206
|
-
readonly host?: AgentHost;
|
|
1207
|
-
/**
|
|
1208
|
-
* Phase 20 (v1.2): when the agent loop resumes from a host.storage snapshot,
|
|
1209
|
-
* the configured SurvivabilityAdapter handles the serialize/deserialize
|
|
1210
|
-
* round-trip. When absent, runtime defaults to
|
|
1211
|
-
* `createNoopSurvivabilityAdapter<AgentSnapshot>()`.
|
|
1212
|
-
*/
|
|
1213
|
-
readonly survivabilityAdapter?: SurvivabilityAdapter<AgentSnapshot>;
|
|
1214
|
-
readonly contract?: CapabilityContract;
|
|
1215
|
-
readonly policy?: PolicySpec;
|
|
1216
|
-
readonly outputs?: TOutputs;
|
|
1217
|
-
readonly pipeline?: HookPipeline;
|
|
1218
|
-
readonly signer?: ReceiptSigner;
|
|
1219
|
-
readonly tracer?: TracerLike;
|
|
1220
|
-
/**
|
|
1221
|
-
* When `false`, the runtime will NOT auto-register `createCheckpointHook`
|
|
1222
|
-
* even if `signer` is provided. Callers who want full manual control over
|
|
1223
|
-
* receipt minting set this to `false` and register their own hook.
|
|
1224
|
-
* Defaults to `true` (auto-register when signer present).
|
|
1225
|
-
*/
|
|
1226
|
-
readonly autoRegisterCheckpoint?: boolean;
|
|
1227
|
-
}
|
|
1228
|
-
/**
|
|
1229
|
-
* Success result returned by `ai.runAgent` when the loop reaches a final
|
|
1230
|
-
* answer and (when `outputs` is declared) the final answer validates.
|
|
1231
|
-
*
|
|
1232
|
-
* `iterations[]` records every iteration that ran — including the one that
|
|
1233
|
-
* produced the final answer. `receipt` is the outermost receipt minted at
|
|
1234
|
-
* loop close when `signer` is configured (separate from per-iteration
|
|
1235
|
-
* receipts on `iterations[i].receipt`).
|
|
1236
|
-
*/
|
|
1237
|
-
interface AgentSuccess<TOutputs extends OutputContractMap = OutputContractMap> {
|
|
1238
|
-
readonly kind: "success";
|
|
1239
|
-
readonly output: InferOutputMap<TOutputs>;
|
|
1240
|
-
readonly usage: Usage;
|
|
1241
|
-
readonly iterations: ReadonlyArray<IterationRecord>;
|
|
1242
|
-
readonly receipt?: ReceiptEnvelope;
|
|
1243
|
-
}
|
|
1244
|
-
/**
|
|
1245
|
-
* Failure kinds specific to the agent loop. v1.1 `LatticeRunError.kind`
|
|
1246
|
-
* values remain valid (provider errors, no-contract-match, validation-failed,
|
|
1247
|
-
* tripwire-violated) and are reused verbatim. Phase 19 adds three
|
|
1248
|
-
* agent-specific kinds. Phase 39 (v1.3) adds `crew-budget-exceeded` —
|
|
1249
|
-
* crew-level shared-pool exhaustion, terminal across the parent/child
|
|
1250
|
-
* boundary (D-10).
|
|
1251
|
-
*/
|
|
1252
|
-
type AgentFailureKind = LatticeRunError["kind"] | "agent-iteration-denied" | "agent-max-iterations" | "agent-wall-time-exceeded" | "crew-budget-exceeded";
|
|
1253
|
-
/**
|
|
1254
|
-
* Failure result returned by `ai.runAgent`. Discriminates via `kind`.
|
|
1255
|
-
*
|
|
1256
|
-
* `iterations[]` carries any iterations that completed before the failure
|
|
1257
|
-
* (empty if the failure occurred pre-iteration). For `agent-iteration-denied`,
|
|
1258
|
-
* the failing iteration is the LAST entry and carries `deniedReason`.
|
|
1259
|
-
*/
|
|
1260
|
-
interface AgentFailure {
|
|
1261
|
-
readonly kind: AgentFailureKind;
|
|
1262
|
-
readonly usage: Usage;
|
|
1263
|
-
readonly iterations: ReadonlyArray<IterationRecord>;
|
|
1264
|
-
readonly reason?: string;
|
|
1265
|
-
readonly cause?: unknown;
|
|
1266
|
-
readonly receipt?: ReceiptEnvelope;
|
|
1267
|
-
}
|
|
1268
|
-
/**
|
|
1269
|
-
* Discriminated union returned by `ai.runAgent`.
|
|
1270
|
-
*/
|
|
1271
|
-
type AgentResult<TOutputs extends OutputContractMap = OutputContractMap> = AgentSuccess<TOutputs> | AgentFailure;
|
|
1272
|
-
/**
|
|
1273
|
-
* Typed error raised when a SAFETY-band handler sets `controls.deny(reason)`
|
|
1274
|
-
* during `BEFORE_AGENT_ITERATION`. Carries `terminal: true` semantics to
|
|
1275
|
-
* align with v1.1 `TripwireViolationError`: the failure is NOT retried by
|
|
1276
|
-
* the fallback chain.
|
|
1277
|
-
*
|
|
1278
|
-
* Surfaced via `AgentFailure { kind: "agent-iteration-denied", reason, ... }`
|
|
1279
|
-
* — callers can also catch the typed error if they prefer.
|
|
1280
|
-
*/
|
|
1281
|
-
declare class AgentDeniedError extends Error {
|
|
1282
|
-
readonly kind: "agent-iteration-denied";
|
|
1283
|
-
readonly terminal: true;
|
|
1284
|
-
readonly reason: string;
|
|
1285
|
-
readonly iterationIndex: number;
|
|
1286
|
-
constructor(reason: string, iterationIndex: number);
|
|
1287
|
-
}
|
|
1288
|
-
/**
|
|
1289
|
-
* Returned by `formatToolsForProvider` (Phase 19 Plan 19-03). Re-exported
|
|
1290
|
-
* here for convenience; the canonical declaration lives in format-tools.ts.
|
|
1291
|
-
*/
|
|
1292
|
-
interface ToolUseRequest {
|
|
1293
|
-
readonly id: string;
|
|
1294
|
-
readonly name: string;
|
|
1295
|
-
readonly args: unknown;
|
|
1296
|
-
}
|
|
1297
|
-
//#endregion
|
|
1298
|
-
//#region src/tools/tool-call-validation.d.ts
|
|
1299
|
-
type ToolCallValidationFailureReason = "unknown_tool" | "invalid_args" | "extra_fields";
|
|
1300
|
-
interface ValidatedToolCall {
|
|
1301
|
-
readonly id: string;
|
|
1302
|
-
readonly name: string;
|
|
1303
|
-
readonly args: unknown;
|
|
1304
|
-
}
|
|
1305
|
-
type ToolCallValidationTool = Pick<ToolDefinition, "name" | "inputSchema">;
|
|
1306
|
-
interface ValidateToolCallsOption {
|
|
1307
|
-
readonly tools: readonly ToolCallValidationTool[];
|
|
1308
|
-
readonly onFailure?: "throw" | "drop" | "callback";
|
|
1309
|
-
readonly onValidationFailure?: (error: ToolCallValidationError) => void | Promise<void>;
|
|
1310
|
-
readonly allowExtraFields?: boolean;
|
|
1311
|
-
}
|
|
1312
|
-
declare class ToolCallValidationError extends Error {
|
|
1313
|
-
readonly kind: "tool-call-validation";
|
|
1314
|
-
readonly reason: ToolCallValidationFailureReason;
|
|
1315
|
-
readonly toolName: string;
|
|
1316
|
-
readonly attemptedArgs: unknown;
|
|
1317
|
-
readonly validationIssues: readonly ValidationIssue[];
|
|
1318
|
-
readonly requestId: string;
|
|
1319
|
-
constructor(input: {
|
|
1320
|
-
readonly reason: ToolCallValidationFailureReason;
|
|
1321
|
-
readonly toolName: string;
|
|
1322
|
-
readonly attemptedArgs: unknown;
|
|
1323
|
-
readonly validationIssues?: readonly ValidationIssue[];
|
|
1324
|
-
readonly requestId: string;
|
|
1325
|
-
});
|
|
1326
|
-
}
|
|
1327
|
-
//#endregion
|
|
1328
|
-
//#region src/providers/quirks.d.ts
|
|
1329
|
-
/**
|
|
1330
|
-
* Universal 5-boolean shape every first-party adapter populates (SC-1 / D-03).
|
|
1331
|
-
*
|
|
1332
|
-
* - `supportsToolChoice` — adapter supports tool_choice / forced-tool-call mode
|
|
1333
|
-
* - `parallelToolCalls` — adapter supports parallel (multi-tool) calls in one turn
|
|
1334
|
-
* - `structuredOutputs` — adapter honors response_format JSON schema binding
|
|
1335
|
-
* - `responseFormatHonored` — adapter treats response_format as authoritative (false
|
|
1336
|
-
* for vanilla openai-compat servers; true for OpenAI/Anthropic/Gemini)
|
|
1337
|
-
* - `streamingDiverges` — streamed output differs from buffered output (true for
|
|
1338
|
-
* some self-hosted servers; false for OpenAI/Anthropic/Gemini)
|
|
1339
|
-
*/
|
|
1340
|
-
interface AdapterQuirks {
|
|
1341
|
-
readonly supportsToolChoice: boolean;
|
|
1342
|
-
readonly parallelToolCalls: boolean;
|
|
1343
|
-
readonly structuredOutputs: boolean;
|
|
1344
|
-
readonly responseFormatHonored: boolean;
|
|
1345
|
-
readonly streamingDiverges: boolean;
|
|
1346
|
-
}
|
|
1347
|
-
/**
|
|
1348
|
-
* Anthropic adapter quirks (extends AdapterQuirks with 3 Anthropic-specific flags).
|
|
1349
|
-
*
|
|
1350
|
-
* CITED: Anthropic prompt caching docs — https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching
|
|
1351
|
-
* - `promptCachingSupported`: cache_control on system and user turns is supported on
|
|
1352
|
-
* all active Claude models (claude-3-* and claude-*-4 families).
|
|
1353
|
-
*
|
|
1354
|
-
* CITED: Anthropic extended thinking docs — https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking
|
|
1355
|
-
* - `extendedThinkingSupported`: thinking blocks (claude-3-7-sonnet+ and claude-*-4) available
|
|
1356
|
-
* via the "thinking" request parameter.
|
|
1357
|
-
*
|
|
1358
|
-
* CITED: Anthropic tool use docs — https://docs.anthropic.com/en/docs/build-with-claude/tool-use
|
|
1359
|
-
* - `toolUseInputSchemaStrict`: Anthropic tool_use blocks require strict JSON Schema in
|
|
1360
|
-
* the input_schema field; the adapter enforces this at call time.
|
|
1361
|
-
*/
|
|
1362
|
-
interface AnthropicQuirks extends AdapterQuirks {
|
|
1363
|
-
readonly promptCachingSupported: boolean;
|
|
1364
|
-
readonly extendedThinkingSupported: boolean;
|
|
1365
|
-
readonly toolUseInputSchemaStrict: boolean;
|
|
1366
|
-
}
|
|
1367
|
-
/**
|
|
1368
|
-
* OpenAI adapter quirks (extends AdapterQuirks with 2 OpenAI-specific flags).
|
|
1369
|
-
*
|
|
1370
|
-
* CITED: OpenAI structured outputs docs — https://platform.openai.com/docs/guides/structured-outputs
|
|
1371
|
-
* - `strictModeSupported`: function-calling strict:true mode available on
|
|
1372
|
-
* gpt-4o-2024-08-06+ and o1+ series.
|
|
1373
|
-
* - `structuredOutputsTier2`: json_schema response_format mode (tier-2 structured outputs)
|
|
1374
|
-
* available on gpt-4o and gpt-4o-mini series.
|
|
1375
|
-
*/
|
|
1376
|
-
interface OpenAIQuirks extends AdapterQuirks {
|
|
1377
|
-
readonly strictModeSupported: boolean;
|
|
1378
|
-
readonly structuredOutputsTier2: boolean;
|
|
1379
|
-
}
|
|
1380
|
-
/**
|
|
1381
|
-
* OpenAI-compatible adapter quirks (same 5 base booleans, no new fields).
|
|
1382
|
-
*
|
|
1383
|
-
* Conservative defaults: openai-compat servers (vLLM, TGI, Ollama, custom)
|
|
1384
|
-
* vary widely in which response_format and tool_choice features they implement.
|
|
1385
|
-
* The factory populates the base fields conservatively (responseFormatHonored:
|
|
1386
|
-
* false, structuredOutputs: false) because the endpoint could be anything.
|
|
1387
|
-
* Consumers pointing at a known-good server should verify quirk values manually.
|
|
1388
|
-
*/
|
|
1389
|
-
interface OpenAICompatQuirks extends AdapterQuirks {}
|
|
1390
|
-
/**
|
|
1391
|
-
* Gemini adapter quirks (extends AdapterQuirks with 3 Gemini-specific flags).
|
|
1392
|
-
*
|
|
1393
|
-
* CITED: Gemini API docs — https://ai.google.dev/api/generate-content#v1beta.GenerationConfig
|
|
1394
|
-
* - `responseSchemaSupported`: responseSchema / responseJsonSchema on generateContent
|
|
1395
|
-
* is available on gemini-1.5-pro+ and gemini-2.x models.
|
|
1396
|
-
* - `safetySettingsConfigurable`: all 4 harm categories (HARASSMENT, HATE_SPEECH,
|
|
1397
|
-
* SEXUALLY_EXPLICIT, DANGEROUS_CONTENT) can be set to BLOCK_NONE — verified in
|
|
1398
|
-
* gemini.ts:50-55.
|
|
1399
|
-
*
|
|
1400
|
-
* CITED: Gemini API system instruction docs — https://ai.google.dev/api/generate-content#v1beta.GenerateContentRequest
|
|
1401
|
-
* - `systemInstructionSupported`: systemInstruction field on GenerateContentRequest
|
|
1402
|
-
* available on gemini-1.5+ series and later.
|
|
1403
|
-
*/
|
|
1404
|
-
interface GeminiQuirks extends AdapterQuirks {
|
|
1405
|
-
readonly responseSchemaSupported: boolean;
|
|
1406
|
-
readonly safetySettingsConfigurable: boolean;
|
|
1407
|
-
readonly systemInstructionSupported: boolean;
|
|
1408
|
-
}
|
|
1409
|
-
/**
|
|
1410
|
-
* xAI adapter quirks (extends AdapterQuirks with 2 xAI-specific flags).
|
|
1411
|
-
*
|
|
1412
|
-
* CITED: xAI API docs — https://docs.x.ai/api/endpoints
|
|
1413
|
-
* - `reasoningTokensReported`: completion_tokens_details.reasoning_tokens reported
|
|
1414
|
-
* in xAI API responses — verified in xai.ts:46-72.
|
|
1415
|
-
* - `logprobsSupported`: grok-4.20 silently ignores logprobs param per observed
|
|
1416
|
-
* behavior; flag indicates whether logprobs fields will be populated.
|
|
1417
|
-
*/
|
|
1418
|
-
interface XaiQuirks extends AdapterQuirks {
|
|
1419
|
-
readonly reasoningTokensReported: boolean;
|
|
1420
|
-
readonly logprobsSupported: boolean;
|
|
1421
|
-
}
|
|
1422
|
-
/**
|
|
1423
|
-
* OpenRouter adapter quirks (extends AdapterQuirks with 3 OpenRouter-specific flags).
|
|
1424
|
-
*
|
|
1425
|
-
* CITED: OpenRouter provider routing docs — https://openrouter.ai/docs/provider-routing
|
|
1426
|
-
* - `providerRoutingArraySupported`: the `provider.order` / `provider.only` /
|
|
1427
|
-
* `provider.ignore` arrays are supported for explicit routing control.
|
|
1428
|
-
* - `floorPricingHints`: `max_price`, `sort: "throughput" | "price"` hints on
|
|
1429
|
-
* GenerationConfig for cost-aware routing.
|
|
1430
|
-
* - `allowFallbacks`: `provider.allow_fallbacks: boolean` controls whether OpenRouter
|
|
1431
|
-
* retries with a different upstream provider on failure.
|
|
1432
|
-
*/
|
|
1433
|
-
interface OpenRouterQuirks extends AdapterQuirks {
|
|
1434
|
-
readonly providerRoutingArraySupported: boolean;
|
|
1435
|
-
readonly floorPricingHints: boolean;
|
|
1436
|
-
readonly allowFallbacks: boolean;
|
|
1437
|
-
}
|
|
1438
|
-
/**
|
|
1439
|
-
* LM Studio adapter quirks (extends AdapterQuirks with 2 LM Studio-specific flags).
|
|
1440
|
-
*
|
|
1441
|
-
* CITED: lmstudio-bug-tracker — Jinja template mismatches between model training and
|
|
1442
|
-
* LM Studio server defaults cause output format corruption.
|
|
1443
|
-
* - `customChatTemplateRiskFlag`: LM Studio servers can ship with broken chat templates
|
|
1444
|
-
* that don't match the model's training template; flag signals this risk.
|
|
1445
|
-
*
|
|
1446
|
-
* VERIFIED: lm-studio.ts:35-37 — apiKey is optional for LM Studio local servers.
|
|
1447
|
-
* - `noAuthRequired`: apiKey is NOT required for local LM Studio instances (no
|
|
1448
|
-
* authentication by default on localhost:1234).
|
|
1449
|
-
*/
|
|
1450
|
-
interface LmStudioQuirks extends AdapterQuirks {
|
|
1451
|
-
readonly customChatTemplateRiskFlag: boolean;
|
|
1452
|
-
readonly noAuthRequired: boolean;
|
|
1453
|
-
}
|
|
1454
|
-
//#endregion
|
|
1455
|
-
//#region src/capabilities/sanitizer-recommendations.d.ts
|
|
1456
|
-
/**
|
|
1457
|
-
* D-13 — Phase 36 sanitizer registration keys. Closed string-literal union;
|
|
1458
|
-
* adding a 4th sanitizer in v1.4 is an intentional typed breaking change
|
|
1459
|
-
* that mirrors the `KnownFailureMode` discipline.
|
|
1460
|
-
*
|
|
1461
|
-
* Phase 36 registers implementations under EXACTLY these 3 ids:
|
|
1462
|
-
* - "stripReasoningTags" — strips <think>/</think> (and model-specific) reasoning tags
|
|
1463
|
-
* - "stripChatTemplateArtifacts" — removes chat-template artifact leaks from output
|
|
1464
|
-
* - "unwrapInternalEnvelope" — extracts the user-visible payload from internal wrapper
|
|
1465
|
-
*/
|
|
1466
|
-
type SanitizerKey = "stripReasoningTags" | "stripChatTemplateArtifacts" | "unwrapInternalEnvelope";
|
|
1467
|
-
/**
|
|
1468
|
-
* D-14 + D-16 — Exhaustive mapping from KnownFailureMode to SanitizerKey
|
|
1469
|
-
* (or null when the failure mode is not a sanitizer concern). The
|
|
1470
|
-
* `Record<KnownFailureMode, ...>` annotation enforces compile-time
|
|
1471
|
-
* exhaustiveness — adding a new mode to KnownFailureMode in v1.4+ will
|
|
1472
|
-
* cause a type-check failure here until the planner decides on a mapping.
|
|
1473
|
-
*
|
|
1474
|
-
* Null semantics per D-16:
|
|
1475
|
-
* - system_prompt_echo -> null (consumer-side prompt engineering, not a sanitizer)
|
|
1476
|
-
* - hallucinated_tool_name -> null (Phase 37 tool-call validator territory)
|
|
1477
|
-
* - malformed_tool_arguments -> null (Phase 37 tool-call validator territory)
|
|
1478
|
-
* - premature_termination -> null (consumer-side max_tokens config)
|
|
1479
|
-
*/
|
|
1480
|
-
declare const SANITIZER_BY_FAILURE_MODE: Record<KnownFailureMode, SanitizerKey | null>;
|
|
1481
|
-
/**
|
|
1482
|
-
* D-14 / D-15 — Maps a list of known failure modes through the recommendation
|
|
1483
|
-
* table and filters nulls. `recommendedSanitizers` always contains real keys.
|
|
1484
|
-
*
|
|
1485
|
-
* Implementation:
|
|
1486
|
-
* - Iterates modes in input order (Set insertion order)
|
|
1487
|
-
* - Skips null entries (D-16)
|
|
1488
|
-
* - Deduplicates via Set (so repeated modes yield one key)
|
|
1489
|
-
* - Returns a readonly array (frozen via spread)
|
|
1490
|
-
*
|
|
1491
|
-
* Consumers use this to populate `NegotiatedCapabilities.recommendedSanitizers`.
|
|
1492
|
-
* Phase 36 registers implementations under the same key ids.
|
|
1493
|
-
*/
|
|
1494
|
-
declare function getRecommendedSanitizers(modes: readonly KnownFailureMode[]): readonly SanitizerKey[];
|
|
1495
|
-
//#endregion
|
|
1496
|
-
//#region src/capabilities/negotiate.d.ts
|
|
1497
|
-
/**
|
|
1498
|
-
* Phase 34 — SC-3 — Consumer-facing capability shape returned by
|
|
1499
|
-
* `adapter.negotiateCapabilities()` and the top-level `negotiateCapabilities()`
|
|
1500
|
-
* helper. Simplified relative to `ModelCapabilityProfile` (the registry
|
|
1501
|
-
* profile); consumers needing the full enum (e.g., native_strict vs
|
|
1502
|
-
* native_lenient) should look up the profile directly via `getCapabilityProfile`.
|
|
1503
|
-
*
|
|
1504
|
-
* Source values (D-09):
|
|
1505
|
-
* - "live" — /models endpoint hit, registry profile intersected
|
|
1506
|
-
* - "registry-fallback" — /models hit failed transiently (5xx/network/timeout),
|
|
1507
|
-
* fell back to Phase 33 static registry (D-09)
|
|
1508
|
-
* - "registry" — adapter intentionally has no /models endpoint
|
|
1509
|
-
* (LM Studio, openai-compat), OR consumer-adapter
|
|
1510
|
-
* fallback path (D-04)
|
|
1511
|
-
*/
|
|
1512
|
-
interface NegotiatedCapabilities {
|
|
1513
|
-
readonly modelId: string;
|
|
1514
|
-
readonly contextWindow: number;
|
|
1515
|
-
readonly supports: {
|
|
1516
|
-
readonly nativeToolCalling: boolean;
|
|
1517
|
-
readonly structuredOutputs: boolean;
|
|
1518
|
-
readonly parallelToolCalls: boolean;
|
|
1519
|
-
readonly extendedThinking: boolean;
|
|
1520
|
-
readonly streaming: boolean;
|
|
1521
|
-
};
|
|
1522
|
-
readonly knownFailureModes: readonly KnownFailureMode[];
|
|
1523
|
-
readonly recommendedSanitizers: readonly SanitizerKey[];
|
|
1524
|
-
readonly source: "live" | "registry-fallback" | "registry";
|
|
1525
|
-
}
|
|
1526
|
-
/**
|
|
1527
|
-
* D-10 — Typed error thrown by `negotiateCapabilities` when the adapter's
|
|
1528
|
-
* /models endpoint returns 401 or 403. Mirrors `AgentDeniedError` shape
|
|
1529
|
-
* (the only existing v1.2 `class extends Error` precedent in agent/types.ts).
|
|
1530
|
-
*
|
|
1531
|
-
* Why throw (vs return-as-error-union):
|
|
1532
|
-
* - Auth errors indicate a broken apiKey config — it is the caller's bug
|
|
1533
|
-
* - Silently falling back would hide the misconfiguration
|
|
1534
|
-
* - `try/catch` ergonomics work cleanly with `class extends Error`
|
|
1535
|
-
* - `instanceof NegotiationAuthError` is the consumer ergonomic
|
|
1536
|
-
*
|
|
1537
|
-
* IMPORTANT: `NegotiationAuthError` is throwable from `negotiateCapabilities`
|
|
1538
|
-
* ONLY — never from `execute()`. Auth errors from /models do NOT contaminate
|
|
1539
|
-
* the request path.
|
|
1540
|
-
*
|
|
1541
|
-
* T-34-01-02: message field set by adapter implementations in Plans 02-04
|
|
1542
|
-
* MUST NOT include the apiKey. Only adapter, modelId, and httpStatus are carried.
|
|
1543
|
-
*/
|
|
1544
|
-
declare class NegotiationAuthError extends Error {
|
|
1545
|
-
readonly kind: "negotiation-auth-failed";
|
|
1546
|
-
readonly adapter: CapabilityAdapter;
|
|
1547
|
-
readonly modelId: string;
|
|
1548
|
-
readonly httpStatus: 401 | 403;
|
|
1549
|
-
constructor(adapter: CapabilityAdapter, modelId: string, httpStatus: 401 | 403, message: string);
|
|
1550
|
-
}
|
|
1551
|
-
/**
|
|
1552
|
-
* Phase 34 — D-02 / D-04 — Top-level helper for capability negotiation.
|
|
1553
|
-
*
|
|
1554
|
-
* Pitfall 5 (zero live-path logic): delegates verbatim to
|
|
1555
|
-
* `adapter.negotiateCapabilities(modelId)` when the adapter implements it.
|
|
1556
|
-
* No inflight-coalescing, no cache, no source value transformation. The
|
|
1557
|
-
* adapter owns all of that.
|
|
1558
|
-
*
|
|
1559
|
-
* When the adapter has NO `negotiateCapabilities` (consumer-provided v1.2
|
|
1560
|
-
* adapters, third-party adapters), falls back to the Phase 33 registry
|
|
1561
|
-
* via `synthesizeNegotiatedCapabilitiesFromRegistry` with source "registry"
|
|
1562
|
-
* (D-04). Consumer adapters get useful behavior out of the box without any
|
|
1563
|
-
* migration code.
|
|
1564
|
-
*
|
|
1565
|
-
* Verifiable per Pitfall 5: grep for `new Map<` in this function body should
|
|
1566
|
-
* return zero matches; LOC count of the function body is < 10 lines.
|
|
1567
|
-
*/
|
|
1568
|
-
declare function negotiateCapabilities(adapter: ProviderAdapter, modelId: string): Promise<NegotiatedCapabilities>;
|
|
1569
|
-
/**
|
|
1570
|
-
* Phase 34 — D-04 / D-09 — Synthesizes a `NegotiatedCapabilities` shape from
|
|
1571
|
-
* the Phase 33 static registry. Used by:
|
|
1572
|
-
* 1. The top-level helper (above) for consumer-adapter fallback (D-04).
|
|
1573
|
-
* 2. Per-adapter negotiate() implementations (Plans 02-05) when /models
|
|
1574
|
-
* fails transiently (D-09, source "registry-fallback").
|
|
1575
|
-
*
|
|
1576
|
-
* Exported as a named export so Plans 02-05 can reuse the fallback synthesis
|
|
1577
|
-
* without duplicating the mapping logic.
|
|
1578
|
-
*
|
|
1579
|
-
* Implementation note: the boolean derivations are intentionally minimal
|
|
1580
|
-
* (heuristic, not definitive). The per-adapter negotiate() implementations
|
|
1581
|
-
* in Plans 02-05 own the richer derivation from live /models data.
|
|
1582
|
-
* This helper is a SAFETY NET for adapters without /models endpoints and
|
|
1583
|
-
* for transient-fallback cases.
|
|
1584
|
-
*
|
|
1585
|
-
* Anti-shape (documented in CONTEXT.md <specifics>): boolean `nativeToolCalling`
|
|
1586
|
-
* loses the strict-vs-lenient distinction in `toolCallSurface`. Consumers
|
|
1587
|
-
* needing the enum should look up the profile directly via `getCapabilityProfile`.
|
|
1588
|
-
*/
|
|
1589
|
-
declare function synthesizeNegotiatedCapabilitiesFromRegistry(adapter: CapabilityAdapter, modelId: string, source: "registry" | "registry-fallback"): NegotiatedCapabilities;
|
|
1590
|
-
//#endregion
|
|
1591
|
-
//#region src/providers/provider.d.ts
|
|
1592
|
-
type CapabilityModality = "text" | "json" | "image" | "audio" | "video" | "document" | "file" | "url" | "tool";
|
|
1593
|
-
type ProviderTransportMode = "inline" | "json" | "url" | "base64" | "provider-upload" | "file-id" | "extracted-text" | "transcript";
|
|
1594
|
-
type ProviderLatencyClass = "interactive" | "batch";
|
|
1595
|
-
interface ProviderPricingHint {
|
|
1596
|
-
/** @deprecated prefer `inputPer1kTokens` — kept for backward compatibility */
|
|
1597
|
-
readonly inputCostPer1M?: number;
|
|
1598
|
-
/** @deprecated prefer `outputPer1kTokens` — kept for backward compatibility */
|
|
1599
|
-
readonly outputCostPer1M?: number;
|
|
1600
|
-
/** Per-1000-prompt-token cost in USD. Preferred field for Phase 7+ pricing. */
|
|
1601
|
-
readonly inputPer1kTokens?: number;
|
|
1602
|
-
/** Per-1000-completion-token cost in USD. Preferred field for Phase 7+ pricing. */
|
|
1603
|
-
readonly outputPer1kTokens?: number;
|
|
1604
|
-
}
|
|
1605
|
-
/**
|
|
1606
|
-
* Normalized per-run usage at the result layer.
|
|
1607
|
-
*
|
|
1608
|
-
* `costUsd` is `number | null` (not optional, not `0`) so downstream
|
|
1609
|
-
* consumers can distinguish "free" (`0`) from "unmeasured" (`null`) when
|
|
1610
|
-
* provider pricing is unknown — see 07-CONTEXT.md "Cost Normalization & Usage".
|
|
1611
|
-
*
|
|
1612
|
-
* Distinct from `UsageRecord` on `ProviderAttemptRecord`: `UsageRecord`
|
|
1613
|
-
* is the per-attempt record, `Usage` is the per-run normalized shape
|
|
1614
|
-
* surfaced on `RunSuccess` / `RunFailure`.
|
|
1615
|
-
*/
|
|
1616
|
-
interface Usage {
|
|
1617
|
-
readonly promptTokens: number;
|
|
1618
|
-
readonly completionTokens: number;
|
|
1619
|
-
readonly costUsd: number | null;
|
|
1620
|
-
}
|
|
1621
|
-
interface ProviderDataPolicyHints {
|
|
1622
|
-
readonly privacy: readonly ("standard" | "sensitive" | "restricted")[];
|
|
1623
|
-
readonly uploadRetention?: "none" | "ephemeral" | "provider-default";
|
|
1624
|
-
readonly supportsNoLogging?: boolean;
|
|
1625
|
-
readonly supportsNoTraining?: boolean;
|
|
1626
|
-
}
|
|
1627
|
-
interface ModelCapability {
|
|
1628
|
-
readonly providerId: string;
|
|
1629
|
-
readonly modelId: string;
|
|
1630
|
-
readonly inputModalities: readonly CapabilityModality[];
|
|
1631
|
-
readonly outputModalities: readonly CapabilityModality[];
|
|
1632
|
-
readonly fileTransport: readonly ProviderTransportMode[];
|
|
1633
|
-
readonly contextWindow: number;
|
|
1634
|
-
readonly structuredOutput: boolean;
|
|
1635
|
-
readonly toolUse: boolean;
|
|
1636
|
-
readonly streaming: boolean;
|
|
1637
|
-
readonly pricing?: ProviderPricingHint;
|
|
1638
|
-
readonly latency: ProviderLatencyClass;
|
|
1639
|
-
readonly dataPolicy: ProviderDataPolicyHints;
|
|
1640
|
-
readonly available?: boolean;
|
|
1641
|
-
}
|
|
1642
|
-
interface ProviderRef {
|
|
1643
|
-
readonly id: string;
|
|
1644
|
-
readonly kind?: "provider-ref";
|
|
1645
|
-
}
|
|
1646
|
-
interface ProviderRunRequest {
|
|
1647
|
-
readonly task: string;
|
|
1648
|
-
readonly artifacts: readonly ArtifactInput[];
|
|
1649
|
-
readonly outputs: readonly string[];
|
|
1650
|
-
readonly outputContracts?: OutputContractMap;
|
|
1651
|
-
readonly policy?: unknown;
|
|
1652
|
-
readonly signal?: AbortSignal;
|
|
1653
|
-
readonly plan?: ExecutionPlan;
|
|
1654
|
-
readonly contextPack?: ContextPack;
|
|
1655
|
-
readonly providerPackaging?: ProviderPackagingPlan;
|
|
1656
|
-
readonly packagedArtifacts?: readonly ArtifactRef[];
|
|
1657
|
-
/**
|
|
1658
|
-
* Phase 39 — opt-in prompt-cache prefix (DELEG-04). Adapters that support
|
|
1659
|
-
* block-granular caching (Anthropic) hoist this to a `cache_control`-marked
|
|
1660
|
-
* system content block; adapters that ignore it MUST receive the prefix
|
|
1661
|
-
* folded into `task` by the caller instead (the crew dispatcher gates on
|
|
1662
|
-
* `quirks.promptCachingSupported`). The field is advisory, additive, and
|
|
1663
|
-
* absent for all existing callers — follows the Phase 37 `toolCalls`
|
|
1664
|
-
* additive-field precedent (request/response additive fields accepted;
|
|
1665
|
-
* `ProviderAdapter` METHODS frozen per INV-03).
|
|
1666
|
-
*/
|
|
1667
|
-
readonly cacheSystemPrefix?: string;
|
|
1668
|
-
}
|
|
1669
|
-
interface ProviderRunResponse {
|
|
1670
|
-
readonly rawOutputs: Record<string, unknown>;
|
|
1671
|
-
readonly artifactRefs?: readonly (ArtifactInput | ArtifactRef)[];
|
|
1672
|
-
/**
|
|
1673
|
-
* @deprecated Legacy per-attempt usage shape. Phase 7+ adapters should
|
|
1674
|
-
* populate `normalizedUsage` instead — Plan 04 will prefer `normalizedUsage`
|
|
1675
|
-
* when wiring `RunResult.usage`. Kept here for backward compatibility with
|
|
1676
|
-
* v1.0 adapters that already report this field.
|
|
1677
|
-
*/
|
|
1678
|
-
readonly usage?: UsageRecord;
|
|
1679
|
-
/**
|
|
1680
|
-
* Phase 7 normalized usage shape for `RunResult.usage`. Populated by all
|
|
1681
|
-
* Phase 7+ adapters (openai, openai-compat, ai-sdk, fake). `costUsd` is
|
|
1682
|
-
* `null` when pricing is unknown (per the cost-normalization decision in
|
|
1683
|
-
* 07-CONTEXT.md — distinguishes "free" from "unmeasured").
|
|
1684
|
-
*/
|
|
1685
|
-
readonly normalizedUsage?: Usage;
|
|
1686
|
-
readonly toolCalls?: readonly ValidatedToolCall[];
|
|
1687
|
-
readonly rawResponse?: unknown;
|
|
1688
|
-
}
|
|
1689
|
-
interface ProviderAdapter {
|
|
1690
|
-
readonly id: string;
|
|
1691
|
-
readonly kind: "provider-adapter";
|
|
1692
|
-
readonly capabilities?: readonly ModelCapability[];
|
|
1693
|
-
readonly execute?: (request: ProviderRunRequest) => Promise<ProviderRunResponse>;
|
|
1694
|
-
/**
|
|
1695
|
-
* Phase 34 — D-01 — Per-adapter behavioral deviation flags. OPTIONAL on the
|
|
1696
|
-
* base interface so v1.2 consumer adapters (4-field literals) continue to work
|
|
1697
|
-
* without modification (non-breaking). First-party adapter factories narrow the
|
|
1698
|
-
* return type to require `quirks` with the specific sub-interface for their adapter.
|
|
1699
|
-
*
|
|
1700
|
-
* D-03 discriminant-narrowing contract: consumers reading this field get
|
|
1701
|
-
* `AdapterQuirks` autocomplete. To access adapter-specific flags, cast after
|
|
1702
|
-
* an `adapter.id` discriminant check OR use the typed factory return directly.
|
|
1703
|
-
* Example: `(adapter.quirks as AnthropicQuirks).promptCachingSupported`.
|
|
1704
|
-
*/
|
|
1705
|
-
readonly quirks?: AdapterQuirks;
|
|
1706
|
-
/**
|
|
1707
|
-
* Phase 34 — D-02 — Capability negotiation via the provider's /models endpoint.
|
|
1708
|
-
* OPTIONAL on the base interface (non-breaking for v1.2 consumer adapters).
|
|
1709
|
-
* First-party adapters that have a /models endpoint implement this; adapters
|
|
1710
|
-
* without one (LM Studio, openai-compat) fall back to the Phase 33 registry.
|
|
1711
|
-
*
|
|
1712
|
-
* The top-level `negotiateCapabilities(adapter, modelId)` helper in
|
|
1713
|
-
* `capabilities/negotiate.ts` delegates to this method when present and
|
|
1714
|
-
* synthesizes from the registry otherwise (D-04).
|
|
1715
|
-
*/
|
|
1716
|
-
readonly negotiateCapabilities?: (modelId: string) => Promise<NegotiatedCapabilities>;
|
|
1717
|
-
}
|
|
1718
|
-
type ProviderRegistryInput = readonly (ProviderRef | ProviderAdapter | string)[];
|
|
1719
|
-
//#endregion
|
|
1720
|
-
//#region src/plan/plan.d.ts
|
|
1721
|
-
type ExecutionPlanStatus = "stub" | "planned" | "no-route" | "running" | "completed" | "failed";
|
|
1722
|
-
type ExecutionStageKind = "analysis" | "transforms" | "context-packing" | "provider-packaging" | "tool-execution" | "execution" | "validation" | "tripwire" | "persistence" | "replay";
|
|
1723
|
-
type ExecutionStageStatus = "pending" | "running" | "completed" | "skipped" | "failed";
|
|
1724
|
-
interface ExecutionPlanStage {
|
|
1725
|
-
readonly id: string;
|
|
1726
|
-
readonly kind: ExecutionStageKind;
|
|
1727
|
-
readonly status: ExecutionStageStatus;
|
|
1728
|
-
readonly inputArtifacts?: readonly string[];
|
|
1729
|
-
readonly outputArtifacts?: readonly string[];
|
|
1730
|
-
readonly warnings: readonly string[];
|
|
1731
|
-
readonly metadata?: Record<string, unknown>;
|
|
1732
|
-
}
|
|
1733
|
-
interface RouteRejectReason {
|
|
1734
|
-
readonly code: string;
|
|
1735
|
-
readonly message: string;
|
|
1736
|
-
}
|
|
1737
|
-
interface RouteCandidate {
|
|
1738
|
-
readonly providerId: string;
|
|
1739
|
-
readonly modelId: string;
|
|
1740
|
-
readonly capability: ModelCapability;
|
|
1741
|
-
readonly score: number;
|
|
1742
|
-
readonly accepted: boolean;
|
|
1743
|
-
readonly reasons: readonly RouteRejectReason[];
|
|
1744
|
-
readonly estimates: RouteEstimates;
|
|
1745
|
-
}
|
|
1746
|
-
interface RouteEstimates {
|
|
1747
|
-
readonly inputTokens: number;
|
|
1748
|
-
readonly outputTokens: number;
|
|
1749
|
-
readonly costUsd?: number;
|
|
1750
|
-
readonly latencyMs?: number;
|
|
1751
|
-
}
|
|
1752
|
-
interface SelectedRoute {
|
|
1753
|
-
readonly providerId: string;
|
|
1754
|
-
readonly modelId: string;
|
|
1755
|
-
readonly score: number;
|
|
1756
|
-
readonly estimates: RouteEstimates;
|
|
1757
|
-
readonly inputModalities: readonly CapabilityModality[];
|
|
1758
|
-
readonly outputModalities: readonly CapabilityModality[];
|
|
1759
|
-
readonly fileTransport: readonly ProviderTransportMode[];
|
|
1760
|
-
}
|
|
1761
|
-
interface FallbackRoute {
|
|
1762
|
-
readonly providerId: string;
|
|
1763
|
-
readonly modelId: string;
|
|
1764
|
-
readonly score: number;
|
|
1765
|
-
readonly reason: "policy-preserving-fallback";
|
|
1766
|
-
}
|
|
1767
|
-
interface RouteDecision {
|
|
1768
|
-
readonly catalogVersion: string;
|
|
1769
|
-
readonly selected?: SelectedRoute;
|
|
1770
|
-
readonly candidates: readonly RouteCandidate[];
|
|
1771
|
-
readonly rejected: readonly RouteCandidate[];
|
|
1772
|
-
readonly fallbackChain: readonly FallbackRoute[];
|
|
1773
|
-
readonly noRouteReasons: readonly RouteRejectReason[];
|
|
1774
|
-
}
|
|
1775
|
-
interface ContextPackPlan {
|
|
1776
|
-
readonly id: string;
|
|
1777
|
-
readonly tokenBudget: number;
|
|
1778
|
-
readonly estimatedTokens: number;
|
|
1779
|
-
readonly included: readonly ContextPackItemPlan[];
|
|
1780
|
-
readonly summarized: readonly ContextPackItemPlan[];
|
|
1781
|
-
readonly archived: readonly ContextPackItemPlan[];
|
|
1782
|
-
readonly omitted: readonly ContextPackItemPlan[];
|
|
1783
|
-
readonly warnings: readonly string[];
|
|
1784
|
-
}
|
|
1785
|
-
interface ContextPackItemPlan {
|
|
1786
|
-
readonly artifactId?: string;
|
|
1787
|
-
readonly sessionTurnId?: string;
|
|
1788
|
-
readonly reason: string;
|
|
1789
|
-
readonly estimatedTokens: number;
|
|
1790
|
-
readonly trust: "developer" | "user" | "tool" | "model-summary";
|
|
1791
|
-
}
|
|
1792
|
-
interface ProviderPackagingPlan {
|
|
1793
|
-
readonly providerId: string;
|
|
1794
|
-
readonly modelId: string;
|
|
1795
|
-
readonly artifacts: readonly ProviderPackagedArtifactPlan[];
|
|
1796
|
-
readonly warnings: readonly string[];
|
|
1797
|
-
}
|
|
1798
|
-
interface ProviderPackagedArtifactPlan {
|
|
1799
|
-
readonly artifactId: string;
|
|
1800
|
-
readonly transport: ProviderTransportMode;
|
|
1801
|
-
readonly mediaType?: string;
|
|
1802
|
-
readonly lineageTransform: "provider-packaging";
|
|
1803
|
-
readonly warnings: readonly string[];
|
|
1804
|
-
}
|
|
1805
|
-
interface ProviderAttemptRecord {
|
|
1806
|
-
readonly providerId: string;
|
|
1807
|
-
readonly modelId: string;
|
|
1808
|
-
readonly status: "pending" | "running" | "succeeded" | "failed" | "cancelled";
|
|
1809
|
-
readonly startedAt?: string;
|
|
1810
|
-
readonly completedAt?: string;
|
|
1811
|
-
readonly error?: string;
|
|
1812
|
-
readonly usage?: UsageRecord;
|
|
1813
|
-
}
|
|
1814
|
-
interface UsageRecord {
|
|
1815
|
-
readonly inputTokens?: number;
|
|
1816
|
-
readonly outputTokens?: number;
|
|
1817
|
-
readonly totalTokens?: number;
|
|
1818
|
-
readonly costUsd?: number;
|
|
1819
|
-
readonly latencyMs?: number;
|
|
1820
|
-
}
|
|
1821
|
-
interface ExecutionPlan {
|
|
1822
|
-
readonly id: string;
|
|
1823
|
-
readonly kind: "execution-plan";
|
|
1824
|
-
readonly version: 1;
|
|
1825
|
-
readonly createdAt: string;
|
|
1826
|
-
readonly status: ExecutionPlanStatus;
|
|
1827
|
-
readonly task: string;
|
|
1828
|
-
readonly outputNames: readonly string[];
|
|
1829
|
-
readonly artifactRefs: readonly ArtifactRef[];
|
|
1830
|
-
readonly route: RouteDecision;
|
|
1831
|
-
readonly stages: readonly ExecutionPlanStage[];
|
|
1832
|
-
readonly context?: ContextPackPlan;
|
|
1833
|
-
readonly providerPackaging?: ProviderPackagingPlan;
|
|
1834
|
-
readonly attempts: readonly ProviderAttemptRecord[];
|
|
1835
|
-
readonly warnings: readonly string[];
|
|
1836
|
-
readonly metadata?: Record<string, unknown>;
|
|
1837
|
-
}
|
|
1838
|
-
interface ExecutionPlanStub {
|
|
1839
|
-
readonly id: string;
|
|
1840
|
-
readonly kind: "plan-stub";
|
|
1841
|
-
readonly createdAt: string;
|
|
1842
|
-
readonly status: "stub";
|
|
1843
|
-
readonly stages: readonly [];
|
|
1844
|
-
readonly warnings: readonly string[];
|
|
1845
|
-
}
|
|
1846
|
-
type ResultPlan = ExecutionPlan | ExecutionPlanStub;
|
|
1847
|
-
//#endregion
|
|
1848
|
-
//#region src/receipts/types.d.ts
|
|
1849
|
-
type ContractVerdict = "success" | "tripwire-violated" | "no-contract-match" | "execution-failed" | "validation-failed";
|
|
1850
|
-
interface ReceiptUsageCanonical {
|
|
1851
|
-
readonly promptTokens: number;
|
|
1852
|
-
readonly completionTokens: number;
|
|
1853
|
-
readonly costUsd: string | null;
|
|
1854
|
-
}
|
|
1855
|
-
interface ReceiptModel {
|
|
1856
|
-
readonly requested: string;
|
|
1857
|
-
readonly observed: string | null;
|
|
1858
|
-
}
|
|
1859
|
-
interface ReceiptRoute {
|
|
1860
|
-
readonly providerId: string;
|
|
1861
|
-
readonly capabilityId: string;
|
|
1862
|
-
readonly attemptNumber: number;
|
|
1863
|
-
}
|
|
1864
|
-
interface ReceiptRedaction {
|
|
1865
|
-
readonly path: string;
|
|
1866
|
-
readonly reason: string;
|
|
1867
|
-
}
|
|
1868
|
-
interface CapabilityReceiptBody {
|
|
1869
|
-
readonly version: "lattice-receipt/v1" | "lattice-receipt/v1.1" | "lattice-receipt/v1.2";
|
|
1870
|
-
readonly receiptId: string;
|
|
1871
|
-
readonly runId: string;
|
|
1872
|
-
readonly issuedAt: string;
|
|
1873
|
-
readonly kid: string;
|
|
1874
|
-
readonly model: ReceiptModel;
|
|
1875
|
-
readonly route: ReceiptRoute;
|
|
1876
|
-
readonly modelClass?: TrainingClass;
|
|
1877
|
-
readonly parentReceiptCid?: string;
|
|
1878
|
-
readonly usage: ReceiptUsageCanonical;
|
|
1879
|
-
readonly contractVerdict: ContractVerdict;
|
|
1880
|
-
readonly contractHash: string | null;
|
|
1881
|
-
readonly inputHashes: readonly string[];
|
|
1882
|
-
readonly outputHash: string | null;
|
|
1883
|
-
readonly redactionPolicyId: string;
|
|
1884
|
-
readonly redactions: readonly ReceiptRedaction[];
|
|
1885
|
-
readonly noRouteReasons?: readonly RouteRejectReason[];
|
|
1886
|
-
readonly tripwireEvidence?: TripwireEvidence;
|
|
1887
|
-
readonly stepName?: string;
|
|
1888
|
-
readonly stepIndex?: number;
|
|
1889
|
-
readonly parentStepName?: string;
|
|
1890
|
-
readonly previousStepName?: string;
|
|
1891
|
-
readonly sessionId?: string;
|
|
1892
|
-
readonly timestamp?: string;
|
|
1893
|
-
}
|
|
1894
|
-
interface ReceiptSignature {
|
|
1895
|
-
readonly keyid: string;
|
|
1896
|
-
readonly sig: string;
|
|
1897
|
-
}
|
|
1898
|
-
interface ReceiptEnvelope {
|
|
1899
|
-
readonly payloadType: "application/vnd.lattice.receipt+json";
|
|
1900
|
-
readonly payload: string;
|
|
1901
|
-
readonly signatures: readonly ReceiptSignature[];
|
|
1902
|
-
}
|
|
1903
|
-
interface ReceiptSigner {
|
|
1904
|
-
readonly kid: string;
|
|
1905
|
-
sign(bytes: Uint8Array): Promise<Uint8Array>;
|
|
1906
|
-
readonly publicKeyJwk: JsonWebKey;
|
|
1907
|
-
}
|
|
1908
|
-
type KeyState = "active" | "retired" | "revoked";
|
|
1909
|
-
interface KeyEntry {
|
|
1910
|
-
readonly kid: string;
|
|
1911
|
-
readonly publicKeyJwk: JsonWebKey;
|
|
1912
|
-
readonly state: KeyState;
|
|
1913
|
-
}
|
|
1914
|
-
interface KeySet {
|
|
1915
|
-
lookup(kid: string): KeyEntry | undefined;
|
|
1916
|
-
}
|
|
1917
|
-
type VerifyErrorKind = "key-not-found" | "key-revoked" | "canonicalization-mismatch" | "signature-invalid" | "envelope-malformed" | "version-mismatch" | "schema-version-too-low";
|
|
1918
|
-
interface VerifyError {
|
|
1919
|
-
readonly kind: VerifyErrorKind;
|
|
1920
|
-
readonly message: string;
|
|
1921
|
-
}
|
|
1922
|
-
interface VerifyOk {
|
|
1923
|
-
readonly ok: true;
|
|
1924
|
-
readonly body: CapabilityReceiptBody;
|
|
1925
|
-
readonly keyState: KeyState;
|
|
1926
|
-
}
|
|
1927
|
-
interface VerifyFail {
|
|
1928
|
-
readonly ok: false;
|
|
1929
|
-
readonly error: VerifyError;
|
|
1930
|
-
}
|
|
1931
|
-
type VerifyResult = VerifyOk | VerifyFail;
|
|
1932
|
-
//#endregion
|
|
1933
|
-
//#region src/receipts/receipt.d.ts
|
|
1934
|
-
/**
|
|
1935
|
-
* Public input to createReceipt. Mirrors CapabilityReceiptBody minus:
|
|
1936
|
-
* - `version` (forced to "lattice-receipt/v1.2" per Phase 38)
|
|
1937
|
-
* - `kid` (forced from signer.kid — caller cannot mismatch)
|
|
1938
|
-
* - `redactions[]` (populated by redactReceiptBody)
|
|
1939
|
-
* - `usage.costUsd` (converted to canonical string by usageToCanonical)
|
|
1940
|
-
*
|
|
1941
|
-
* receiptId and issuedAt default to runtime-generated values when omitted.
|
|
1942
|
-
* redactionPolicyId defaults to DEFAULT_REDACTION_POLICY_ID.
|
|
1943
|
-
*/
|
|
1944
|
-
interface CreateReceiptInput {
|
|
1945
|
-
readonly runId: string;
|
|
1946
|
-
readonly issuedAt?: string;
|
|
1947
|
-
readonly receiptId?: string;
|
|
1948
|
-
readonly model: ReceiptModel;
|
|
1949
|
-
readonly route: ReceiptRoute;
|
|
1950
|
-
readonly modelClass?: TrainingClass;
|
|
1951
|
-
readonly parentReceiptCid?: string;
|
|
1952
|
-
readonly usage: Usage;
|
|
1953
|
-
readonly contractVerdict: ContractVerdict;
|
|
1954
|
-
readonly contractHash: string | null;
|
|
1955
|
-
readonly inputHashes: readonly string[];
|
|
1956
|
-
readonly outputHash: string | null;
|
|
1957
|
-
readonly redactionPolicyId?: string;
|
|
1958
|
-
readonly noRouteReasons?: readonly RouteRejectReason[];
|
|
1959
|
-
readonly tripwireEvidence?: TripwireEvidence;
|
|
1960
|
-
readonly stepName?: string;
|
|
1961
|
-
readonly stepIndex?: number;
|
|
1962
|
-
readonly parentStepName?: string;
|
|
1963
|
-
readonly previousStepName?: string;
|
|
1964
|
-
readonly sessionId?: string;
|
|
1965
|
-
readonly timestamp?: string;
|
|
1966
|
-
}
|
|
1967
|
-
/**
|
|
1968
|
-
* Build, redact, canonicalize, sign, and envelope a CapabilityReceipt.
|
|
1969
|
-
*
|
|
1970
|
-
* Ordering INVARIANT (09-CONTEXT.md, PITFALLS.md Pitfall #1):
|
|
1971
|
-
* redact -> canonicalize -> PAE -> sign -> encode
|
|
1972
|
-
*
|
|
1973
|
-
* The signed digest commits to canonicalize(redact(body)). The function
|
|
1974
|
-
* structure makes any other ordering impossible to write by accident —
|
|
1975
|
-
* canonicalizeReceiptBody is ONLY called on the output of redactReceiptBody.
|
|
1976
|
-
*
|
|
1977
|
-
* Defense in depth:
|
|
1978
|
-
* - body.kid is assigned from signer.kid, never from input (input has no
|
|
1979
|
-
* kid field). The signed body and the envelope keyid CANNOT disagree by
|
|
1980
|
-
* construction.
|
|
1981
|
-
* - signer.kid is also written to envelope.signatures[0].keyid, so the
|
|
1982
|
-
* verifier can cross-check (Step 7 of verifyReceipt).
|
|
1983
|
-
*
|
|
1984
|
-
* I-JSON guarantees: usage.costUsd is converted to string (or null) via
|
|
1985
|
-
* usageToCanonical. Receipts NEVER carry raw floats in the canonical form.
|
|
1986
|
-
*/
|
|
1987
|
-
declare function createReceipt(input: CreateReceiptInput, signer: ReceiptSigner): Promise<ReceiptEnvelope>;
|
|
1988
|
-
//#endregion
|
|
1989
17
|
//#region src/contract/checkpoint.d.ts
|
|
1990
18
|
/**
|
|
1991
19
|
* The tracer event name Lattice's checkpoint hook emits per step transition.
|
|
@@ -2068,1266 +96,82 @@ interface CheckpointHookOptions {
|
|
|
2068
96
|
*/
|
|
2069
97
|
declare function createCheckpointHook(options: CheckpointHookOptions): HookHandler<CheckpointHookContext>;
|
|
2070
98
|
//#endregion
|
|
2071
|
-
//#region src/
|
|
2072
|
-
/**
|
|
2073
|
-
* Result of a single pre-flight contract evaluation against a candidate
|
|
2074
|
-
* capability. `reasons` is empty when `ok` is true and contains one or more
|
|
2075
|
-
* `RouteRejectReason` entries when `ok` is false.
|
|
2076
|
-
*
|
|
2077
|
-
* The evaluator surfaces ALL failing reasons in a single pass — not the
|
|
2078
|
-
* first-failing only — so the deterministic router can aggregate per-candidate
|
|
2079
|
-
* rejection detail (CONTEXT.md "Pre-flight surfaces ALL failed candidates
|
|
2080
|
-
* with per-candidate rejection reasons").
|
|
2081
|
-
*/
|
|
2082
|
-
interface ContractPreflightResult {
|
|
2083
|
-
readonly ok: boolean;
|
|
2084
|
-
readonly reasons: readonly RouteRejectReason[];
|
|
2085
|
-
}
|
|
2086
|
-
/**
|
|
2087
|
-
* Input for the pure cost estimator. Token counts come from the router's
|
|
2088
|
-
* existing `estimateRoute()` helper so preflight and router agree on the
|
|
2089
|
-
* projected output size (one source of truth — see `evaluateContractAgainstRoute`).
|
|
2090
|
-
*/
|
|
2091
|
-
interface EstimateRouteCostInput {
|
|
2092
|
-
readonly capability: ModelCapability;
|
|
2093
|
-
readonly estimatedInputTokens: number;
|
|
2094
|
-
readonly estimatedOutputTokens: number;
|
|
2095
|
-
}
|
|
2096
|
-
/**
|
|
2097
|
-
* Pure cost estimator. Returns `null` when pricing is unknown (so downstream
|
|
2098
|
-
* gates can distinguish "free / zero" from "unmeasured" per the Phase 7
|
|
2099
|
-
* cost-normalization decision). Uses static catalog metadata only — no probes,
|
|
2100
|
-
* no external pricing APIs.
|
|
2101
|
-
*/
|
|
2102
|
-
declare function estimateRouteCost(input: EstimateRouteCostInput): number | null;
|
|
2103
|
-
/** Input for the pre-flight evaluator. */
|
|
2104
|
-
interface EvaluateContractInput {
|
|
2105
|
-
readonly capability: ModelCapability;
|
|
2106
|
-
readonly estimatedInputTokens: number;
|
|
2107
|
-
readonly estimatedOutputTokens: number;
|
|
2108
|
-
}
|
|
2109
|
-
/**
|
|
2110
|
-
* Pure pre-flight evaluator. Phase 9 receipts will reuse this for deterministic
|
|
2111
|
-
* verdict reconstruction.
|
|
2112
|
-
*
|
|
2113
|
-
* Token estimation: Phase 7 does NOT define a separate token estimator. Output-
|
|
2114
|
-
* token projection is the canonical responsibility of the router's existing
|
|
2115
|
-
* `estimateRoute()` helper (in `routing/router.ts`), which already produces an
|
|
2116
|
-
* `estimatedOutputTokens` value. The router passes that same value into this
|
|
2117
|
-
* evaluator via `EvaluateContractInput.estimatedOutputTokens`, so preflight
|
|
2118
|
-
* and the router always agree on the projected output size. Phase 9 receipts
|
|
2119
|
-
* will pin the router's estimate as the deterministic input — intentionally
|
|
2120
|
-
* one source of truth.
|
|
2121
|
-
*
|
|
2122
|
-
* Reject taxonomy (Phase 7 emits three of four codes):
|
|
2123
|
-
* - `contract-budget-exceeded` (CONTRACT-04 + COST-03)
|
|
2124
|
-
* - `contract-modality-missing` (CONTRACT-06)
|
|
2125
|
-
* - `contract-privacy-mismatch` (CONTRACT-06)
|
|
2126
|
-
* - `contract-quality-floor` (reserved for Phase 12 `lattice eval`; NEVER emitted here)
|
|
2127
|
-
*/
|
|
2128
|
-
declare function evaluateContractAgainstRoute(contract: CapabilityContract | undefined, input: EvaluateContractInput): ContractPreflightResult;
|
|
2129
|
-
//#endregion
|
|
2130
|
-
//#region src/receipts/keyset.d.ts
|
|
2131
|
-
/**
|
|
2132
|
-
* In-memory KeySet factory.
|
|
2133
|
-
*
|
|
2134
|
-
* Verification flow (plan 09-03):
|
|
2135
|
-
* - keySet.lookup(kid) returns undefined → VerifyError {kind: "key-not-found"}
|
|
2136
|
-
* - entry.state === "revoked" → VerifyError {kind: "key-revoked"}
|
|
2137
|
-
* - entry.state === "retired" → VerifyOk + keyState: "retired" (caller may warn)
|
|
2138
|
-
* - entry.state === "active" → VerifyOk + keyState: "active"
|
|
2139
|
-
*
|
|
2140
|
-
* Duplicate kids: last write wins (deterministic — callers control entry order).
|
|
2141
|
-
* Empty entries array is legal — every lookup returns undefined.
|
|
2142
|
-
* Returned KeySet exposes only `lookup` — no enumeration.
|
|
2143
|
-
*
|
|
2144
|
-
* See 09-CONTEXT.md "Key Management (UNRETROFITTABLE)".
|
|
2145
|
-
*/
|
|
2146
|
-
declare function createMemoryKeySet(entries: readonly KeyEntry[]): KeySet;
|
|
2147
|
-
//#endregion
|
|
2148
|
-
//#region src/receipts/sign.d.ts
|
|
2149
|
-
interface GeneratedEd25519KeyPair {
|
|
2150
|
-
readonly privateKeyJwk: JsonWebKey;
|
|
2151
|
-
readonly publicKeyJwk: JsonWebKey;
|
|
2152
|
-
}
|
|
2153
|
-
declare function generateEd25519KeyPairJwk(): Promise<GeneratedEd25519KeyPair>;
|
|
2154
|
-
declare function createInMemorySigner(privateKeyJwk: JsonWebKey, options: {
|
|
2155
|
-
readonly kid: string;
|
|
2156
|
-
readonly publicKeyJwk: JsonWebKey;
|
|
2157
|
-
}): ReceiptSigner;
|
|
2158
|
-
//#endregion
|
|
2159
|
-
//#region src/receipts/verify.d.ts
|
|
99
|
+
//#region src/providers/no-public-url.d.ts
|
|
2160
100
|
/**
|
|
2161
|
-
*
|
|
2162
|
-
*
|
|
2163
|
-
*
|
|
2164
|
-
* boundary (PITFALLS.md security: "Verifier panics on malformed receipts
|
|
2165
|
-
* -> DoS via crafted input"). All parsing failures become typed errors.
|
|
101
|
+
* Thrown when a run with `policy.noPublicUrl: true` is about to dispatch a
|
|
102
|
+
* request whose serialized body still contains a public http(s) URL derived
|
|
103
|
+
* from `request.artifacts` (value or string metadata entry).
|
|
2166
104
|
*
|
|
2167
|
-
*
|
|
2168
|
-
*
|
|
2169
|
-
* 2. payload bytes are not valid JSON -> envelope-malformed
|
|
2170
|
-
* 3. body shape check fails OR version unknown literal -> version-mismatch
|
|
2171
|
-
* 4. body.version === undefined OR "lattice-receipt/v1"-> schema-version-too-low (CRYPTO-01)
|
|
2172
|
-
* 5. keySet.lookup(keyid) === undefined -> key-not-found
|
|
2173
|
-
* 6. entry.state === "revoked" -> key-revoked
|
|
2174
|
-
* 7. re-canonicalized body != signed payloadBytes -> canonicalization-mismatch
|
|
2175
|
-
* 8. Ed25519 verification of PAE fails -> signature-invalid
|
|
2176
|
-
* 9. body.kid !== entry.kid (defense in depth) -> signature-invalid
|
|
2177
|
-
* 10. otherwise -> ok + keyState
|
|
105
|
+
* This is the single shared egress error class for all three adapter families
|
|
106
|
+
* (OpenAI-compatible, Anthropic, Gemini). Callers may `instanceof`-check it.
|
|
2178
107
|
*/
|
|
2179
|
-
declare
|
|
2180
|
-
//#endregion
|
|
2181
|
-
//#region src/sanitizers/sanitizers.d.ts
|
|
2182
|
-
interface SanitizerContext {
|
|
108
|
+
declare class NoPublicUrlEgressError extends Error {
|
|
2183
109
|
readonly providerId: string;
|
|
2184
|
-
readonly
|
|
2185
|
-
readonly
|
|
2186
|
-
|
|
2187
|
-
|
|
2188
|
-
|
|
2189
|
-
|
|
2190
|
-
|
|
2191
|
-
|
|
2192
|
-
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
|
|
2196
|
-
|
|
2197
|
-
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
readonly id?: string;
|
|
2201
|
-
readonly model: string;
|
|
2202
|
-
readonly baseUrl: string;
|
|
2203
|
-
readonly apiKey?: string;
|
|
2204
|
-
readonly fetch?: typeof fetch;
|
|
2205
|
-
/**
|
|
2206
|
-
* Phase 7 addition: caller-supplied per-1k pricing. When provided, the
|
|
2207
|
-
* adapter computes `normalizedUsage.costUsd` from the API-reported token
|
|
2208
|
-
* counts. When omitted, `normalizedUsage.costUsd` is `null` so downstream
|
|
2209
|
-
* consumers can distinguish "unmeasured" from "free" (per 07-CONTEXT.md).
|
|
2210
|
-
*/
|
|
2211
|
-
readonly pricing?: {
|
|
2212
|
-
readonly inputPer1kTokens?: number;
|
|
2213
|
-
readonly outputPer1kTokens?: number;
|
|
2214
|
-
};
|
|
2215
|
-
/**
|
|
2216
|
-
* Phase 34 — D-05/D-06/D-08 — TTL for the per-instance models cache.
|
|
2217
|
-
* Default 300_000ms (5 minutes). Set to 0 to disable caching.
|
|
2218
|
-
* Set to Infinity for process-lifetime caching.
|
|
2219
|
-
*
|
|
2220
|
-
* NOTE: for createOpenAICompatibleProvider, this option is accepted for
|
|
2221
|
-
* option-bag uniformity but is NOT USED — openai-compat has no /models
|
|
2222
|
-
* endpoint (D-04). Document in JSDoc for consumers pointing at known servers.
|
|
2223
|
-
*/
|
|
2224
|
-
readonly modelsCacheTtlMs?: number;
|
|
2225
|
-
/**
|
|
2226
|
-
* Phase 34 — D-11 — Number of retry attempts on transient /models errors
|
|
2227
|
-
* (5xx, network, timeout). Default 2. Set to 0 to disable retries.
|
|
2228
|
-
*
|
|
2229
|
-
* NOTE: for createOpenAICompatibleProvider, this option is accepted for
|
|
2230
|
-
* option-bag uniformity but is NOT USED — openai-compat has no /models
|
|
2231
|
-
* endpoint (D-04).
|
|
2232
|
-
*/
|
|
2233
|
-
readonly modelsRetryCount?: number;
|
|
2234
|
-
/**
|
|
2235
|
-
* Phase 34 — D-12 — Optional RunEventSink for capability negotiation events.
|
|
2236
|
-
* When provided, emits the "capabilities.negotiation.fallback" event on
|
|
2237
|
-
* transient /models errors (5xx, network, timeout).
|
|
2238
|
-
*
|
|
2239
|
-
* NOTE: for createOpenAICompatibleProvider, this option is accepted for
|
|
2240
|
-
* option-bag uniformity but the event is NOT FIRED for source: "registry"
|
|
2241
|
-
* (the documented happy path for openai-compat). Emitting events for the
|
|
2242
|
-
* intentional no-endpoint path would produce noisy false-positives.
|
|
2243
|
-
*/
|
|
2244
|
-
readonly runEventSink?: RunEventSink;
|
|
2245
|
-
/**
|
|
2246
|
-
* Phase 36 — Optional output sanitizer pipeline. When provided, string
|
|
2247
|
-
* rawOutputs are transformed in order after provider text extraction and
|
|
2248
|
-
* before the adapter returns.
|
|
2249
|
-
*/
|
|
2250
|
-
readonly sanitizeOutput?: SanitizeOutputOption;
|
|
2251
|
-
/**
|
|
2252
|
-
* Phase 37 — Optional returned tool-call validator. When provided, the
|
|
2253
|
-
* adapter parses prompt-reencoded tool_calls envelopes and returns
|
|
2254
|
-
* normalized validated calls without mutating rawOutputs or rawResponse.
|
|
2255
|
-
*/
|
|
2256
|
-
readonly validateToolCalls?: ValidateToolCallsOption;
|
|
2257
|
-
}
|
|
2258
|
-
interface SdkLikeProviderOptions {
|
|
2259
|
-
readonly id?: string;
|
|
2260
|
-
readonly model: string;
|
|
2261
|
-
readonly generate: (input: {
|
|
2262
|
-
readonly task: string;
|
|
2263
|
-
readonly outputNames: readonly string[];
|
|
2264
|
-
}) => Promise<ProviderRunResponse> | ProviderRunResponse;
|
|
2265
|
-
}
|
|
2266
|
-
/**
|
|
2267
|
-
* Phase 34 — D-04 / QUIRK-02 — OpenAI-compatible provider factory.
|
|
2268
|
-
*
|
|
2269
|
-
* This factory is the prototypical "intentional no remote /models endpoint"
|
|
2270
|
-
* adapter per D-04. The consumer points this adapter at any OpenAI-shaped
|
|
2271
|
-
* endpoint (vLLM, TGI, Ollama, custom), and the factory returns conservative
|
|
2272
|
-
* defaults for the quirks block because the server could be anything.
|
|
2273
|
-
*
|
|
2274
|
-
* The `negotiateCapabilities` method performs NO fetch; it returns
|
|
2275
|
-
* synthesizeNegotiatedCapabilitiesFromRegistry with source: "registry"
|
|
2276
|
-
* (the intentional-no-endpoint signal, as distinct from "registry-fallback"
|
|
2277
|
-
* which signals a transient failure). Plan 34-05 (LM Studio) reuses this
|
|
2278
|
-
* same pattern.
|
|
2279
|
-
*
|
|
2280
|
-
* D-04 citation: "consumer adapters without a /models endpoint skip the
|
|
2281
|
-
* fetch layer entirely and delegate to synthesizeNegotiatedCapabilitiesFromRegistry."
|
|
2282
|
-
*/
|
|
2283
|
-
declare function createOpenAICompatibleProvider(options: OpenAICompatibleProviderOptions): ProviderAdapter & {
|
|
2284
|
-
readonly quirks: OpenAICompatQuirks;
|
|
2285
|
-
readonly negotiateCapabilities: (modelId: string) => Promise<NegotiatedCapabilities>;
|
|
2286
|
-
};
|
|
2287
|
-
/**
|
|
2288
|
-
* Phase 34 — QUIRK-02 / NEG-01 / NEG-02 — OpenAI provider factory.
|
|
2289
|
-
*
|
|
2290
|
-
* Extends the base OpenAI-compat factory with:
|
|
2291
|
-
* 1. `quirks: OpenAIQuirks` — verified per RESEARCH §Q6 OpenAI vocabulary.
|
|
2292
|
-
* 2. `negotiateCapabilities(modelId)` — queries OpenAI /v1/models GET with
|
|
2293
|
-
* Authorization: Bearer header; SPARSE response; intersects with Phase 33
|
|
2294
|
-
* registry for supports.* (per RESEARCH §Anti-patterns — don't assume
|
|
2295
|
-
* OpenAI /v1/models returns capability flags, it doesn't).
|
|
2296
|
-
*
|
|
2297
|
-
* The negotiate() pattern mirrors Plan 34-02 (Anthropic thick reference):
|
|
2298
|
-
* - Per-instance TTL cache (modelsCacheTtlMs, default 300_000ms)
|
|
2299
|
-
* - Single-flight inflight coalescing with .finally cleanup (Pitfall 4)
|
|
2300
|
-
* - Retry with [0, 200, 1000]ms backoff (modelsRetryCount, default 2)
|
|
2301
|
-
* - 401/403 throws NegotiationAuthError (D-10: no retry, no fallback, no event)
|
|
2302
|
-
* - 5xx/network/timeout falls back to registry with source: "registry-fallback"
|
|
2303
|
-
* - emitFallbackEvent fires the "capabilities.negotiation.fallback" RunEvent
|
|
2304
|
-
*
|
|
2305
|
-
* SECURITY (T-34-03-07): inflight Map MUST use .finally cleanup to prevent
|
|
2306
|
-
* leak on rejection. Verifiable: grep `.finally` in this file.
|
|
2307
|
-
*/
|
|
2308
|
-
declare function createOpenAIProvider(options: OpenAICompatibleProviderOptions): ProviderAdapter & {
|
|
2309
|
-
readonly quirks: OpenAIQuirks;
|
|
2310
|
-
readonly negotiateCapabilities: (modelId: string) => Promise<NegotiatedCapabilities>;
|
|
2311
|
-
};
|
|
2312
|
-
declare function createAISdkProvider(options: SdkLikeProviderOptions): ProviderAdapter;
|
|
2313
|
-
//#endregion
|
|
2314
|
-
//#region src/providers/anthropic.d.ts
|
|
2315
|
-
/**
|
|
2316
|
-
* Options for {@link createAnthropicProvider}.
|
|
2317
|
-
*
|
|
2318
|
-
* Mirrors `OpenAICompatibleProviderOptions` ergonomics (Phase 7 pattern) but
|
|
2319
|
-
* for the Anthropic Messages API at `/v1/messages` -- which uses a top-level
|
|
2320
|
-
* `system` field and a `content[0].text` response shape that diverges from
|
|
2321
|
-
* the OpenAI Chat Completions schema (see FSB v0.9.x `extension/ai/universal-provider.js`
|
|
2322
|
-
* lines 280-297 + 566-573 for the production reference).
|
|
2323
|
-
*
|
|
2324
|
-
* SECURITY: `apiKey` is a runtime parameter -- do NOT hardcode or log it.
|
|
2325
|
-
*
|
|
2326
|
-
* DEFERRED (Phase 4 carryforward notes):
|
|
2327
|
-
* - prompt caching (Phase 39: opt-in via `ProviderRunRequest.cacheSystemPrefix` —
|
|
2328
|
-
* emitted as a cache_control-marked system block when present)
|
|
2329
|
-
* - streaming (deferred; this adapter is single-shot Promise -- per CONTEXT.md D-06)
|
|
2330
|
-
* - tool use (Anthropic tool_use blocks are deferred)
|
|
2331
|
-
* - resume-from-eviction -- see Phase 5 (MV3-survivability adapter contract)
|
|
2332
|
-
*
|
|
2333
|
-
* Ref: FSB v0.10.0-attempt-2 Phase 4 (D-02 + D-07: full custom adapter; preserve top-level `system`).
|
|
2334
|
-
*/
|
|
2335
|
-
interface AnthropicProviderOptions {
|
|
2336
|
-
readonly id?: string;
|
|
110
|
+
readonly artifactId: string;
|
|
111
|
+
readonly offendingUrl: string;
|
|
112
|
+
constructor(providerId: string, artifactId: string, offendingUrl: string);
|
|
113
|
+
}
|
|
114
|
+
//#endregion
|
|
115
|
+
//#region src/realtime/realtime.d.ts
|
|
116
|
+
declare const REALTIME_DIRECTION_SUPPORT_LEVEL: "direction-only";
|
|
117
|
+
type RealtimeSupportLevel = typeof REALTIME_DIRECTION_SUPPORT_LEVEL;
|
|
118
|
+
type RealtimeProviderKind = "openai-realtime" | "gemini-live";
|
|
119
|
+
type RealtimeTransportKind = "websocket" | "webrtc" | "sip";
|
|
120
|
+
type RealtimeSessionMode = "voice-agent" | "transcription" | "translation" | "live-multimodal";
|
|
121
|
+
type RealtimeInputModality = "text" | "audio" | "image" | "video";
|
|
122
|
+
type RealtimeOutputModality = "text" | "audio" | "tool";
|
|
123
|
+
type RealtimeCheckpointKind = "session.start" | "client.frame" | "server.frame" | "session.summary" | "session.close";
|
|
124
|
+
interface OpenAIRealtimeTarget {
|
|
125
|
+
readonly provider: "openai-realtime";
|
|
2337
126
|
readonly model: string;
|
|
2338
|
-
readonly
|
|
2339
|
-
|
|
2340
|
-
readonly baseUrl?: string;
|
|
2341
|
-
/** Defaults to `2023-06-01`. Override only if the consumer has tested a newer pinned version. */
|
|
2342
|
-
readonly anthropicVersion?: string;
|
|
2343
|
-
readonly fetch?: typeof fetch;
|
|
2344
|
-
readonly pricing?: {
|
|
2345
|
-
readonly inputPer1kTokens?: number;
|
|
2346
|
-
readonly outputPer1kTokens?: number;
|
|
2347
|
-
};
|
|
2348
|
-
/**
|
|
2349
|
-
* D-08: Per-instance TTL for the /v1/models response cache (milliseconds).
|
|
2350
|
-
* Default 300_000 (5 minutes). `0` disables caching (always re-fetch -- for testing).
|
|
2351
|
-
* `Infinity` disables expiry (process-lifetime for the instance).
|
|
2352
|
-
*/
|
|
2353
|
-
readonly modelsCacheTtlMs?: number;
|
|
2354
|
-
/**
|
|
2355
|
-
* D-11: Number of retries for transient /v1/models fetch failures (5xx, network,
|
|
2356
|
-
* timeout). Default 2 (3 total attempts). `0` disables retries.
|
|
2357
|
-
* Backoff schedule: [0ms, 200ms, 1000ms].
|
|
2358
|
-
*/
|
|
2359
|
-
readonly modelsRetryCount?: number;
|
|
2360
|
-
/**
|
|
2361
|
-
* D-12: Optional RunEventSink for emitting `capabilities.negotiation.fallback`
|
|
2362
|
-
* events when the /v1/models fetch falls back to the Phase 33 static registry.
|
|
2363
|
-
* If absent, fallback emits no event (no-op). Auth errors (401/403) never emit
|
|
2364
|
-
* the fallback event -- they throw `NegotiationAuthError` instead.
|
|
2365
|
-
*/
|
|
2366
|
-
readonly runEventSink?: RunEventSink;
|
|
2367
|
-
readonly sanitizeOutput?: SanitizeOutputOption;
|
|
2368
|
-
readonly validateToolCalls?: ValidateToolCallsOption;
|
|
127
|
+
readonly transport: RealtimeTransportKind;
|
|
128
|
+
readonly endpoint: "/v1/realtime" | "/v1/realtime/translations" | "/v1/realtime/transcription_sessions";
|
|
2369
129
|
}
|
|
2370
|
-
|
|
2371
|
-
readonly
|
|
2372
|
-
readonly negotiateCapabilities: (modelId: string) => Promise<NegotiatedCapabilities>;
|
|
2373
|
-
};
|
|
2374
|
-
//#endregion
|
|
2375
|
-
//#region src/providers/fake.d.ts
|
|
2376
|
-
interface FakeProviderOptions {
|
|
2377
|
-
readonly id?: string;
|
|
2378
|
-
readonly modelId?: string;
|
|
2379
|
-
readonly response?: ProviderRunResponse | ((request: ProviderRunRequest) => ProviderRunResponse | Promise<ProviderRunResponse>);
|
|
2380
|
-
readonly artifacts?: readonly ArtifactInput[];
|
|
2381
|
-
/**
|
|
2382
|
-
* Phase 7 addition: when provided, REPLACES the default single-capability
|
|
2383
|
-
* array so callers (notably Plan 07-04's modality/privacy reject tests)
|
|
2384
|
-
* can construct a fake adapter with arbitrary
|
|
2385
|
-
* `inputModalities` / `outputModalities` / `dataPolicy` / `pricing`
|
|
2386
|
-
* without mutating the returned adapter's readonly `capabilities` array.
|
|
2387
|
-
* When omitted, the existing default capability is used.
|
|
2388
|
-
*/
|
|
2389
|
-
readonly capabilities?: readonly ModelCapability[];
|
|
2390
|
-
}
|
|
2391
|
-
declare function createFakeProvider(options?: FakeProviderOptions): ProviderAdapter;
|
|
2392
|
-
//#endregion
|
|
2393
|
-
//#region src/providers/gemini.d.ts
|
|
2394
|
-
/**
|
|
2395
|
-
* Options for {@link createGeminiProvider}.
|
|
2396
|
-
*
|
|
2397
|
-
* Mirrors `OpenAICompatibleProviderOptions` ergonomics (Phase 7 pattern) but
|
|
2398
|
-
* for Google's Generative Language API at
|
|
2399
|
-
* `/v1beta/models/{model}:generateContent` -- which uses `contents[].parts[].text`
|
|
2400
|
-
* (NOT OpenAI's `messages[]`), `role: "model"` for assistant turns (NOT
|
|
2401
|
-
* `"assistant"`), authenticates via `?key=` query string for execute(), and applies a
|
|
2402
|
-
* 4-category `safetySettings` block at `BLOCK_NONE` thresholds (FSB convention
|
|
2403
|
-
* mirrored from `extension/ai/universal-provider.js:255-272`).
|
|
2404
|
-
*
|
|
2405
|
-
* SECURITY: `apiKey` is a runtime parameter -- do NOT hardcode or log it.
|
|
2406
|
-
*
|
|
2407
|
-
* DEFERRED (Phase 4 carryforward notes):
|
|
2408
|
-
* - multimodal (vision) -- deferred
|
|
2409
|
-
* - streaming -- deferred (single-shot Promise per CONTEXT.md D-06)
|
|
2410
|
-
* - tool use -- deferred
|
|
2411
|
-
* - resume-from-eviction -- see Phase 5 (MV3-survivability adapter contract)
|
|
2412
|
-
*
|
|
2413
|
-
* NOTE (Phase 34): negotiate() uses x-goog-api-key HEADER (preferred per RESEARCH §Q3).
|
|
2414
|
-
* The existing execute() path uses ?key= query string -- execute() migration is out-of-scope
|
|
2415
|
-
* for Phase 34 (additive only; T-34-04-01).
|
|
2416
|
-
*
|
|
2417
|
-
* Ref: FSB v0.10.0-attempt-2 Phase 4 (D-02 + D-07: full custom adapter; preserve role:"model").
|
|
2418
|
-
*/
|
|
2419
|
-
interface GeminiProviderOptions {
|
|
2420
|
-
readonly id?: string;
|
|
130
|
+
interface GeminiLiveTarget {
|
|
131
|
+
readonly provider: "gemini-live";
|
|
2421
132
|
readonly model: string;
|
|
2422
|
-
readonly
|
|
2423
|
-
|
|
2424
|
-
readonly
|
|
2425
|
-
|
|
2426
|
-
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2433
|
-
|
|
2434
|
-
readonly
|
|
2435
|
-
|
|
2436
|
-
* D-11: Number of retries on transient /models fetch errors. Default: 2.
|
|
2437
|
-
* Retry schedule: immediate + 200ms + 1000ms (3 total attempts at retryCount=2).
|
|
2438
|
-
* 0 = no retries (1 attempt total).
|
|
2439
|
-
*/
|
|
2440
|
-
readonly modelsRetryCount?: number;
|
|
2441
|
-
/**
|
|
2442
|
-
* D-12: Optional event sink for observability. When provided, the adapter
|
|
2443
|
-
* emits a "capabilities.negotiation.fallback" RunEvent on transient /models failure.
|
|
2444
|
-
* If absent, no event is emitted (silent fallback).
|
|
2445
|
-
*/
|
|
2446
|
-
readonly runEventSink?: RunEventSink;
|
|
2447
|
-
readonly sanitizeOutput?: SanitizeOutputOption;
|
|
2448
|
-
readonly validateToolCalls?: ValidateToolCallsOption;
|
|
2449
|
-
}
|
|
2450
|
-
/**
|
|
2451
|
-
* Phase 34 — D-03 / D-05..D-12 — Extended Gemini provider factory.
|
|
2452
|
-
*
|
|
2453
|
-
* Returns a `ProviderAdapter` narrowed to expose:
|
|
2454
|
-
* - `quirks: GeminiQuirks` — static adapter capability flags
|
|
2455
|
-
* - `negotiateCapabilities(modelId)` — live /v1beta/models fetch with medium-thick
|
|
2456
|
-
* derivation (inputTokenLimit + thinking + supportedGenerationMethods from upstream)
|
|
2457
|
-
* intersected with Phase 33 registry; TTL cache + inflight coalescing + retry +
|
|
2458
|
-
* auth-throw + transient-fallback + event.
|
|
2459
|
-
*
|
|
2460
|
-
* NOTE on auth strategy (T-34-04-01): negotiate() uses x-goog-api-key HEADER
|
|
2461
|
-
* (preferred per RESEARCH §Q3 -- avoids leaking the key in server-side logs that
|
|
2462
|
-
* capture URL query strings). The existing execute() path uses ?key= query string
|
|
2463
|
-
* and is NOT changed by Phase 34 (out-of-scope migration).
|
|
2464
|
-
*/
|
|
2465
|
-
declare function createGeminiProvider(options: GeminiProviderOptions): ProviderAdapter & {
|
|
2466
|
-
readonly quirks: GeminiQuirks;
|
|
2467
|
-
readonly negotiateCapabilities: (modelId: string) => Promise<NegotiatedCapabilities>;
|
|
2468
|
-
};
|
|
2469
|
-
//#endregion
|
|
2470
|
-
//#region src/providers/lm-studio.d.ts
|
|
2471
|
-
/**
|
|
2472
|
-
* Options for {@link createLmStudioProvider}.
|
|
2473
|
-
*
|
|
2474
|
-
* Thin wrapper around {@link createOpenAICompatibleProvider} pinned to
|
|
2475
|
-
* LM Studio's default local server URL `http://localhost:1234/v1`. Wire
|
|
2476
|
-
* shape is OpenAI Chat Completions. LM Studio is no-auth by convention
|
|
2477
|
-
* (CD-03): `apiKey` is OPTIONAL; when omitted, the underlying factory
|
|
2478
|
-
* sends no `Authorization` header (see
|
|
2479
|
-
* `lattice/packages/lattice/src/providers/adapters.ts:53` for the
|
|
2480
|
-
* conditional auth-header wiring).
|
|
2481
|
-
*
|
|
2482
|
-
* Phase 34 additions:
|
|
2483
|
-
* - `modelsCacheTtlMs` -- Reserved for future /models discovery; LM Studio
|
|
2484
|
-
* currently has no remote /models endpoint. Accepted for option-bag
|
|
2485
|
-
* uniformity but NOT USED (D-04 intentional no-endpoint pattern).
|
|
2486
|
-
* - `runEventSink` -- Accepted for option-bag uniformity but NEVER fired
|
|
2487
|
-
* because source: "registry" is the documented happy path for LM Studio
|
|
2488
|
-
* (no event for intentional no-endpoint per RESEARCH Open Question 5).
|
|
2489
|
-
*
|
|
2490
|
-
* DEFERRED (D-16 carryforward):
|
|
2491
|
-
* - latency-tail diagnostics -- observability concern; LM Studio is
|
|
2492
|
-
* the canary for latency tails (INV-03);
|
|
2493
|
-
* diagnostics module deferred to a
|
|
2494
|
-
* follow-on observability phase.
|
|
2495
|
-
* - streaming -- deferred (single-shot per D-06).
|
|
2496
|
-
* - resume-from-eviction -- see Phase 5 (MV3-survivability adapter).
|
|
2497
|
-
*
|
|
2498
|
-
* Ref: FSB v0.10.0-attempt-2 Phase 4 (D-03: thin wrapper; D-16: latency-tail deferred; CD-03 no-opt-out).
|
|
2499
|
-
*/
|
|
2500
|
-
interface LmStudioProviderOptions extends Omit<OpenAICompatibleProviderOptions, "id" | "baseUrl" | "apiKey"> {
|
|
2501
|
-
readonly id?: string;
|
|
2502
|
-
/** Defaults to `http://localhost:1234/v1`. Override for non-localhost deployments. */
|
|
2503
|
-
readonly baseUrl?: string;
|
|
2504
|
-
/**
|
|
2505
|
-
* Optional. LM Studio is no-auth by convention (CD-03 default).
|
|
2506
|
-
* When provided, sent as `Authorization: Bearer <apiKey>` (matches the
|
|
2507
|
-
* underlying OpenAI-compat factory). Use only for proxied LM Studio
|
|
2508
|
-
* deployments that have a token gate in front.
|
|
2509
|
-
*/
|
|
2510
|
-
readonly apiKey?: string;
|
|
2511
|
-
}
|
|
2512
|
-
/**
|
|
2513
|
-
* Phase 34 — D-04 / QUIRK-02 — LM Studio provider factory.
|
|
2514
|
-
*
|
|
2515
|
-
* LM Studio is the prototypical "intentional no remote /models endpoint"
|
|
2516
|
-
* adapter per D-04 (alongside OpenAI-compat). The factory returns conservative
|
|
2517
|
-
* defaults for the quirks block because LM Studio runs LOCAL quantized models
|
|
2518
|
-
* whose capabilities vary wildly by chat template + model file.
|
|
2519
|
-
*
|
|
2520
|
-
* The `negotiateCapabilities` method performs NO fetch; it returns
|
|
2521
|
-
* `synthesizeNegotiatedCapabilitiesFromRegistry` with source: "registry"
|
|
2522
|
-
* (the intentional-no-endpoint signal, distinct from "registry-fallback"
|
|
2523
|
-
* which signals a transient failure). Mirrors Plan 34-03 Task 2 (OpenAI-compat
|
|
2524
|
-
* registry-only pattern) verbatim.
|
|
2525
|
-
*
|
|
2526
|
-
* D-04 citation: "consumer adapters without a /models endpoint skip the
|
|
2527
|
-
* fetch layer entirely and delegate to synthesizeNegotiatedCapabilitiesFromRegistry."
|
|
2528
|
-
*
|
|
2529
|
-
* Open Question 5 (RESEARCH §): no event emitted for source: "registry" because
|
|
2530
|
-
* this is the intentional happy path for LM Studio -- emitting a "fallback" event
|
|
2531
|
-
* would produce false-positive noise for consumers monitoring the event stream.
|
|
2532
|
-
*/
|
|
2533
|
-
declare function createLmStudioProvider(options: LmStudioProviderOptions): ProviderAdapter & {
|
|
2534
|
-
readonly quirks: LmStudioQuirks;
|
|
2535
|
-
readonly negotiateCapabilities: (modelId: string) => Promise<NegotiatedCapabilities>;
|
|
2536
|
-
};
|
|
2537
|
-
//#endregion
|
|
2538
|
-
//#region src/providers/openrouter.d.ts
|
|
2539
|
-
/**
|
|
2540
|
-
* Options for {@link createOpenRouterProvider}.
|
|
2541
|
-
*
|
|
2542
|
-
* Thin wrapper around {@link createOpenAICompatibleProvider} pinned to
|
|
2543
|
-
* OpenRouter's base URL `https://openrouter.ai/api/v1`. Wire shape is
|
|
2544
|
-
* OpenAI Chat Completions; no provider-specific quirks at the
|
|
2545
|
-
* single-shot Promise contract level.
|
|
2546
|
-
*
|
|
2547
|
-
* SECURITY: `apiKey` is a runtime parameter -- do NOT hardcode or log it.
|
|
2548
|
-
*
|
|
2549
|
-
* DEFERRED (D-17 carryforward; Phase 4 ships the named adapter as a
|
|
2550
|
-
* first-class OpenAI-compat wrapper):
|
|
2551
|
-
* - model-routing array -- caller supplies `model` (single id); OpenRouter's
|
|
2552
|
-
* `models: [primary, fallback, ...]` array
|
|
2553
|
-
* feature is deferred to a follow-on phase.
|
|
2554
|
-
* - fallback-array -- deferred (same phase as model-routing).
|
|
2555
|
-
* - per-message routing -- deferred.
|
|
2556
|
-
* - streaming -- deferred (single-shot per CONTEXT.md D-06).
|
|
2557
|
-
* - resume-from-eviction -- see Phase 5 (MV3-survivability adapter).
|
|
2558
|
-
*
|
|
2559
|
-
* Ref: FSB v0.10.0-attempt-2 Phase 4 (D-03: thin wrapper; D-17: model-routing deferred).
|
|
2560
|
-
*/
|
|
2561
|
-
interface OpenRouterProviderOptions extends Omit<OpenAICompatibleProviderOptions, "id" | "baseUrl"> {
|
|
2562
|
-
readonly id?: string;
|
|
2563
|
-
/** Defaults to `https://openrouter.ai/api/v1`. Override for proxies. */
|
|
2564
|
-
readonly baseUrl?: string;
|
|
2565
|
-
/**
|
|
2566
|
-
* D-08: TTL for per-instance /models response cache, in milliseconds.
|
|
2567
|
-
* Default: 300_000ms (5 minutes). 0 = always refetch (tests). Infinity = process-lifetime.
|
|
2568
|
-
*/
|
|
2569
|
-
readonly modelsCacheTtlMs?: number;
|
|
2570
|
-
/**
|
|
2571
|
-
* D-11: Number of retries on transient /models fetch errors. Default: 2.
|
|
2572
|
-
* Retry schedule: immediate + 200ms + 1000ms (3 total attempts at retryCount=2).
|
|
2573
|
-
* 0 = no retries (1 attempt total).
|
|
2574
|
-
*/
|
|
2575
|
-
readonly modelsRetryCount?: number;
|
|
2576
|
-
/**
|
|
2577
|
-
* D-12: Optional event sink for observability. When provided, the adapter
|
|
2578
|
-
* emits a "capabilities.negotiation.fallback" RunEvent on transient /models failure.
|
|
2579
|
-
* If absent, no event is emitted (silent fallback).
|
|
2580
|
-
*/
|
|
2581
|
-
readonly runEventSink?: RunEventSink;
|
|
2582
|
-
}
|
|
2583
|
-
/**
|
|
2584
|
-
* Phase 34 — D-03 / D-05..D-12 — Extended OpenRouter provider factory.
|
|
2585
|
-
*
|
|
2586
|
-
* Returns a `ProviderAdapter` narrowed to expose:
|
|
2587
|
-
* - `quirks: OpenRouterQuirks` — static adapter capability flags (8 booleans)
|
|
2588
|
-
* - `negotiateCapabilities(modelId)` — live /api/v1/models fetch with rich /models
|
|
2589
|
-
* intersection (supported_parameters -> nativeToolCalling + structuredOutputs,
|
|
2590
|
-
* top_provider.context_length -> contextWindow) intersected with Phase 33 registry
|
|
2591
|
-
* for knownFailureModes + recommendedSanitizers.
|
|
2592
|
-
*
|
|
2593
|
-
* CRITICAL for ANCHOR CASE STUDY (session_1780792387779):
|
|
2594
|
-
* negotiate("openai/gpt-oss-120b:free") MUST resolve to:
|
|
2595
|
-
* - result.knownFailureModes.includes("internal_envelope_leak") -> TRUE
|
|
2596
|
-
* - result.recommendedSanitizers.includes("unwrapInternalEnvelope") -> TRUE
|
|
2597
|
-
* - result.source === "live" -> TRUE
|
|
2598
|
-
* This proves: live-fetch -> id suffix-strip via stripOpenRouterVariant
|
|
2599
|
-
* -> registry intersection -> getRecommendedSanitizers derivation.
|
|
2600
|
-
*
|
|
2601
|
-
* Anti-pattern (RESEARCH §Anti-pattern, lines 534-535):
|
|
2602
|
-
* The /api/v1/models endpoint is UNAUTHENTICATED (public discovery surface verified
|
|
2603
|
-
* Phase 33). Do NOT send Authorization Bearer to this endpoint -- it is NOT required
|
|
2604
|
-
* and would add unnecessary API key exposure surface in transit logs.
|
|
2605
|
-
*/
|
|
2606
|
-
declare function createOpenRouterProvider(options: OpenRouterProviderOptions): ProviderAdapter & {
|
|
2607
|
-
readonly quirks: OpenRouterQuirks;
|
|
2608
|
-
readonly negotiateCapabilities: (modelId: string) => Promise<NegotiatedCapabilities>;
|
|
2609
|
-
};
|
|
2610
|
-
//#endregion
|
|
2611
|
-
//#region src/providers/xai.d.ts
|
|
2612
|
-
/**
|
|
2613
|
-
* Options for {@link createXaiProvider}.
|
|
2614
|
-
*
|
|
2615
|
-
* Thin wrapper around {@link createOpenAICompatibleProvider} pinned to
|
|
2616
|
-
* xAI's base URL `https://api.x.ai/v1`. The wire shape is identical to
|
|
2617
|
-
* OpenAI Chat Completions, with one provider-specific quirk preserved:
|
|
2618
|
-
* `response.usage.completion_tokens_details.reasoning_tokens` (xAI's
|
|
2619
|
-
* separate reasoning-token accounting; see FSB
|
|
2620
|
-
* `extension/ai/universal-provider.js:585-594` for the production reference).
|
|
2621
|
-
*
|
|
2622
|
-
* SECURITY: `apiKey` is a runtime parameter -- do NOT hardcode or log it.
|
|
2623
|
-
*
|
|
2624
|
-
* DEFERRED (Phase 4 carryforward notes):
|
|
2625
|
-
* - tool-streaming -- deferred
|
|
2626
|
-
* - streaming -- deferred (single-shot Promise per CONTEXT.md D-06)
|
|
2627
|
-
* - resume-from-eviction -- see Phase 5 (MV3-survivability adapter contract)
|
|
2628
|
-
*
|
|
2629
|
-
* Ref: FSB v0.10.0-attempt-2 Phase 4 (D-03 + D-07: thin wrapper; reasoning_tokens quirk preserved).
|
|
2630
|
-
*
|
|
2631
|
-
* Phase 34 additions:
|
|
2632
|
-
* - `modelsCacheTtlMs?` — D-05/D-06/D-08; default 300_000ms; 0 disables; Infinity = process-lifetime
|
|
2633
|
-
* - `modelsRetryCount?` — D-11; default 2; 0 disables retry
|
|
2634
|
-
* - `runEventSink?` — D-12; fires "capabilities.negotiation.fallback" on transient errors
|
|
2635
|
-
*/
|
|
2636
|
-
interface XaiProviderOptions extends Omit<OpenAICompatibleProviderOptions, "id" | "baseUrl"> {
|
|
2637
|
-
readonly id?: string;
|
|
2638
|
-
/** Defaults to `https://api.x.ai/v1`. Override for proxies. */
|
|
2639
|
-
readonly baseUrl?: string;
|
|
2640
|
-
}
|
|
2641
|
-
/**
|
|
2642
|
-
* Phase 34 — QUIRK-02 / NEG-01 / NEG-02 — xAI provider factory.
|
|
2643
|
-
*
|
|
2644
|
-
* Extends the base OpenAI-compat execution wrapper with:
|
|
2645
|
-
* 1. `quirks: XaiQuirks` — verified per RESEARCH §Q6 xAI vocabulary.
|
|
2646
|
-
* 2. `negotiateCapabilities(modelId)` — queries xAI /v1/models GET with
|
|
2647
|
-
* Authorization: Bearer header; LENIENT-PARSE sparse OpenAI-shaped
|
|
2648
|
-
* response; intersects with Phase 33 registry for supports.*.
|
|
2649
|
-
*
|
|
2650
|
-
* CITED: RESEARCH §Q4 (INFERRED) — xAI /v1/models shape is undocumented;
|
|
2651
|
-
* assumed OpenAI-compatible based on the chat completions wire format.
|
|
2652
|
-
*
|
|
2653
|
-
* CITED: RESEARCH §A1 — Pitfall 1 lenient parse: if xAI publishes a
|
|
2654
|
-
* different /models shape, only the parsing logic updates; the contract
|
|
2655
|
-
* (source values, NegotiatedCapabilities shape) holds.
|
|
2656
|
-
*
|
|
2657
|
-
* The negotiate() pattern mirrors Plan 34-02 (Anthropic thick reference):
|
|
2658
|
-
* - Per-instance TTL cache (modelsCacheTtlMs, default 300_000ms)
|
|
2659
|
-
* - Single-flight inflight coalescing with .finally cleanup (Pitfall 4)
|
|
2660
|
-
* - Retry with [0, 200, 1000]ms backoff (modelsRetryCount, default 2)
|
|
2661
|
-
* - 401/403 throws NegotiationAuthError with adapter: "xai" (D-10)
|
|
2662
|
-
* - 5xx/network/timeout falls back to registry + emits fallback event
|
|
2663
|
-
*
|
|
2664
|
-
* SECURITY (T-34-03-07): inflight Map MUST use .finally cleanup to prevent
|
|
2665
|
-
* leak on rejection. Verifiable: grep `.finally` in this file.
|
|
2666
|
-
*/
|
|
2667
|
-
declare function createXaiProvider(options: XaiProviderOptions): ProviderAdapter & {
|
|
2668
|
-
readonly quirks: XaiQuirks;
|
|
2669
|
-
readonly negotiateCapabilities: (modelId: string) => Promise<NegotiatedCapabilities>;
|
|
2670
|
-
};
|
|
2671
|
-
//#endregion
|
|
2672
|
-
//#region src/results/result.d.ts
|
|
2673
|
-
interface RunSuccess<TOutputs extends OutputContractMap> {
|
|
2674
|
-
readonly ok: true;
|
|
2675
|
-
readonly outputs: InferOutputMap<TOutputs>;
|
|
2676
|
-
readonly artifacts: readonly ArtifactRef[];
|
|
2677
|
-
readonly usage: Usage;
|
|
2678
|
-
readonly plan: ResultPlan;
|
|
2679
|
-
readonly events?: readonly RunEvent[];
|
|
2680
|
-
/**
|
|
2681
|
-
* Phase 9 — signed capability receipt issued when `LatticeConfig.signer`
|
|
2682
|
-
* is configured. Undefined when no signer is set.
|
|
2683
|
-
*/
|
|
2684
|
-
readonly receipt?: ReceiptEnvelope;
|
|
2685
|
-
}
|
|
2686
|
-
interface RunFailure {
|
|
2687
|
-
readonly ok: false;
|
|
2688
|
-
readonly error: LatticeRunError;
|
|
2689
|
-
readonly usage: Usage;
|
|
2690
|
-
readonly raw?: unknown;
|
|
2691
|
-
readonly partialOutputs?: Record<string, unknown>;
|
|
2692
|
-
readonly plan: ResultPlan;
|
|
2693
|
-
readonly events?: readonly RunEvent[];
|
|
2694
|
-
/**
|
|
2695
|
-
* Phase 9 — signed capability receipt issued when `LatticeConfig.signer`
|
|
2696
|
-
* is configured. Undefined when no signer is set.
|
|
2697
|
-
*/
|
|
2698
|
-
readonly receipt?: ReceiptEnvelope;
|
|
2699
|
-
}
|
|
2700
|
-
type RunResult<TOutputs extends OutputContractMap> = RunSuccess<TOutputs> | RunFailure;
|
|
2701
|
-
//#endregion
|
|
2702
|
-
//#region src/storage/storage.d.ts
|
|
2703
|
-
interface ArtifactStore {
|
|
2704
|
-
readonly kind: "artifact-store";
|
|
2705
|
-
readonly id: string;
|
|
2706
|
-
put(artifact: ArtifactInput): Promise<ArtifactRef>;
|
|
2707
|
-
get(id: string): Promise<ArtifactRef | undefined>;
|
|
2708
|
-
load(id: string): Promise<ArtifactInput | undefined>;
|
|
2709
|
-
has(id: string): Promise<boolean>;
|
|
2710
|
-
delete(id: string): Promise<boolean>;
|
|
2711
|
-
list(): Promise<readonly ArtifactRef[]>;
|
|
2712
|
-
}
|
|
2713
|
-
type StorageLike = ArtifactStore;
|
|
2714
|
-
interface StoredArtifactPayloadDescriptor {
|
|
2715
|
-
readonly kind: "json" | "binary";
|
|
2716
|
-
readonly path: string;
|
|
2717
|
-
}
|
|
2718
|
-
interface StoredArtifactEnvelope {
|
|
2719
|
-
readonly version: 1;
|
|
2720
|
-
readonly ref: ArtifactRef;
|
|
2721
|
-
readonly payload?: StoredArtifactPayloadDescriptor;
|
|
2722
|
-
}
|
|
2723
|
-
//#endregion
|
|
2724
|
-
//#region src/runtime/config.d.ts
|
|
2725
|
-
interface LatticeConfig {
|
|
2726
|
-
readonly providers?: ProviderRegistryInput;
|
|
2727
|
-
readonly storage?: StorageLike | false;
|
|
2728
|
-
readonly sessions?: SessionStore | false;
|
|
2729
|
-
readonly defaults?: {
|
|
2730
|
-
readonly policy?: PolicySpec;
|
|
2731
|
-
};
|
|
2732
|
-
readonly tracing?: TracerLike | false;
|
|
2733
|
-
readonly events?: RunEventSink | readonly RunEventSink[];
|
|
2734
|
-
/**
|
|
2735
|
-
* Phase 9 — when configured, every terminal branch of `ai.run` emits a
|
|
2736
|
-
* signed `CapabilityReceipt` attached to `RunResult.receipt`. When absent,
|
|
2737
|
-
* no receipts are issued and `RunResult.receipt` is undefined.
|
|
2738
|
-
*/
|
|
2739
|
-
readonly signer?: ReceiptSigner;
|
|
2740
|
-
}
|
|
2741
|
-
type NormalizedProviderEntry = ProviderRef | ProviderAdapter;
|
|
2742
|
-
interface NormalizedLatticeConfig {
|
|
2743
|
-
readonly providers: readonly NormalizedProviderEntry[];
|
|
2744
|
-
readonly storage?: StorageLike;
|
|
2745
|
-
readonly sessions?: SessionStore;
|
|
2746
|
-
readonly defaults: {
|
|
2747
|
-
readonly policy?: PolicySpec;
|
|
2748
|
-
};
|
|
2749
|
-
readonly tracing?: TracerLike;
|
|
2750
|
-
readonly events: readonly RunEventSink[];
|
|
2751
|
-
readonly signer?: ReceiptSigner;
|
|
2752
|
-
}
|
|
2753
|
-
//#endregion
|
|
2754
|
-
//#region src/agent/crew/agent-spec.d.ts
|
|
2755
|
-
/**
|
|
2756
|
-
* Crew member specification. A literal sibling of `ToolDefinition`
|
|
2757
|
-
* discriminated by `kind: "agent"` (D-03).
|
|
2758
|
-
*/
|
|
2759
|
-
interface AgentSpec {
|
|
2760
|
-
readonly kind: "agent";
|
|
2761
|
-
readonly id: string;
|
|
2762
|
-
readonly intent: string;
|
|
2763
|
-
readonly tools: ReadonlyArray<ToolDefinition<StandardSchemaV1>>;
|
|
2764
|
-
readonly childAgents?: ReadonlyArray<AgentSpec>;
|
|
2765
|
-
readonly summaryReturnSchema: StandardSchemaV1;
|
|
2766
|
-
/** Optional per-agent sub-budget (D-07). */
|
|
2767
|
-
readonly contract?: CapabilityContract;
|
|
2768
|
-
}
|
|
2769
|
-
/**
|
|
2770
|
-
* Factory for `AgentSpec` values. Mirrors `defineTool` exactly: spread
|
|
2771
|
-
* preserves input identity (no cloning, no mutation) and absent optional
|
|
2772
|
-
* members stay absent (`exactOptionalPropertyTypes`-safe).
|
|
2773
|
-
*/
|
|
2774
|
-
declare function defineAgent(definition: Omit<AgentSpec, "kind">): AgentSpec;
|
|
2775
|
-
//#endregion
|
|
2776
|
-
//#region src/agent/crew/crew-policy.d.ts
|
|
2777
|
-
/** Per-adapter rate-limit override (keyed by `adapter.id` in `limits`). */
|
|
2778
|
-
interface CrewRateLimitOverride {
|
|
2779
|
-
readonly requestsPerMinute?: number;
|
|
2780
|
-
readonly tokensPerMinute?: number;
|
|
2781
|
-
}
|
|
2782
|
-
/** Crew-level policy contract (D-06, D-11, D-16). */
|
|
2783
|
-
interface CrewPolicy {
|
|
2784
|
-
/** Crew-level shared budget pool — `BudgetInvariant` reused verbatim. */
|
|
2785
|
-
readonly budget?: BudgetInvariant;
|
|
2786
|
-
readonly maxTotalIterations?: number;
|
|
2787
|
-
readonly maxIterationsPerAgent?: number;
|
|
2788
|
-
/** Forward-compat field; the v1.3 runtime rejects values > 1 (D-11). */
|
|
2789
|
-
readonly maxConcurrentChildren?: number;
|
|
2790
|
-
/** Delegation depth cap; defaults to 1 (parent→child only, D-05). */
|
|
2791
|
-
readonly maxDepth?: number;
|
|
2792
|
-
/** Per-adapter-id rate-limit overrides (D-16). */
|
|
2793
|
-
readonly limits?: Readonly<Record<string, CrewRateLimitOverride>>;
|
|
2794
|
-
/** "managed" (default) wraps transports in the rate-limit group; "unmanaged" skips it. */
|
|
2795
|
-
readonly coordination?: "managed" | "unmanaged";
|
|
2796
|
-
}
|
|
2797
|
-
//#endregion
|
|
2798
|
-
//#region src/agent/crew/run-crew.d.ts
|
|
2799
|
-
interface RunAgentCrewOptions {
|
|
2800
|
-
readonly root: AgentSpec;
|
|
2801
|
-
readonly hosts: {
|
|
2802
|
-
readonly childHost: AgentHost;
|
|
2803
|
-
};
|
|
2804
|
-
readonly policy?: CrewPolicy;
|
|
2805
|
-
/** Crew-level signer threaded into member loops and completion receipts. */
|
|
2806
|
-
readonly signer?: ReceiptSigner;
|
|
2807
|
-
/** Crew-level tracer threaded into member loops. */
|
|
2808
|
-
readonly tracer?: TracerLike;
|
|
2809
|
-
/** Crew-level hook pipeline threaded into member loops. */
|
|
2810
|
-
readonly pipeline?: HookPipeline;
|
|
2811
|
-
}
|
|
2812
|
-
interface CrewAgentResult {
|
|
2813
|
-
readonly id: string;
|
|
2814
|
-
readonly usage: Usage;
|
|
2815
|
-
readonly iterations: number;
|
|
2816
|
-
readonly receiptCids: readonly string[];
|
|
2817
|
-
}
|
|
2818
|
-
interface CrewResult {
|
|
2819
|
-
/** Parent result, with parent output untouched on success. */
|
|
2820
|
-
readonly result: AgentResult;
|
|
2821
|
-
/** Per-agent accounting records, including root parent and completed children. */
|
|
2822
|
-
readonly perAgent: ReadonlyArray<CrewAgentResult>;
|
|
2823
|
-
/** Crew aggregate usage: parent total + sum(child totals), no double-counting. */
|
|
2824
|
-
readonly usage: Usage;
|
|
2825
|
-
/** Total iterations across every recorded agent. */
|
|
2826
|
-
readonly totalIterations: number;
|
|
2827
|
-
/** All crew completion receipts, including the crew-root envelope. */
|
|
2828
|
-
readonly receipts: ReadonlyArray<ReceiptEnvelope>;
|
|
2829
|
-
readonly crewRootCid?: string;
|
|
2830
|
-
}
|
|
2831
|
-
/**
|
|
2832
|
-
* Execute a crew rooted at `options.root`.
|
|
2833
|
-
*/
|
|
2834
|
-
declare function runAgentCrew(options: RunAgentCrewOptions, config?: LatticeConfig): Promise<CrewResult>;
|
|
2835
|
-
//#endregion
|
|
2836
|
-
//#region src/runtime/create-ai.d.ts
|
|
2837
|
-
interface RuntimeOverrides {
|
|
2838
|
-
readonly provider?: string;
|
|
2839
|
-
readonly model?: string;
|
|
2840
|
-
readonly routingPolicy?: PolicySpec;
|
|
2841
|
-
readonly tokenBudget?: number;
|
|
2842
|
-
readonly summarizer?: ContextSummarizer;
|
|
2843
|
-
readonly transforms?: readonly RuntimeArtifactTransform[];
|
|
2844
|
-
readonly hooks?: RuntimeHooks;
|
|
2845
|
-
}
|
|
2846
|
-
interface RuntimeArtifactTransform {
|
|
2847
|
-
readonly name: string;
|
|
2848
|
-
transform(input: {
|
|
2849
|
-
readonly task: string;
|
|
2850
|
-
readonly artifacts: readonly ArtifactInput[];
|
|
2851
|
-
}): Promise<ArtifactInput | readonly ArtifactInput[]> | ArtifactInput | readonly ArtifactInput[];
|
|
2852
|
-
}
|
|
2853
|
-
interface RuntimeHooks {
|
|
2854
|
-
readonly beforeProviderCall?: (input: {
|
|
2855
|
-
readonly plan: ExecutionPlan;
|
|
2856
|
-
readonly request: ProviderRunRequest;
|
|
2857
|
-
}) => void | Promise<void>;
|
|
2858
|
-
readonly afterProviderCall?: (input: {
|
|
2859
|
-
readonly plan: ExecutionPlan;
|
|
2860
|
-
readonly response: unknown;
|
|
2861
|
-
}) => void | Promise<void>;
|
|
2862
|
-
}
|
|
2863
|
-
interface RunIntent<TOutputs extends OutputContractMap> {
|
|
2864
|
-
readonly task: string;
|
|
2865
|
-
readonly artifacts?: readonly ArtifactInput[];
|
|
2866
|
-
readonly outputs: TOutputs;
|
|
2867
|
-
readonly policy?: PolicySpec;
|
|
2868
|
-
readonly session?: SessionRef;
|
|
2869
|
-
readonly signal?: AbortSignal;
|
|
2870
|
-
readonly overrides?: RuntimeOverrides;
|
|
2871
|
-
readonly tools?: readonly ToolDefinition<any>[];
|
|
2872
|
-
readonly toolInputs?: Record<string, unknown>;
|
|
2873
|
-
readonly contract?: CapabilityContract;
|
|
2874
|
-
}
|
|
2875
|
-
interface AI {
|
|
2876
|
-
session(id: string): SessionRef;
|
|
2877
|
-
plan<const TOutputs extends OutputContractMap>(intent: RunIntent<TOutputs>): Promise<ExecutionPlan>;
|
|
2878
|
-
run<const TOutputs extends OutputContractMap>(intent: RunIntent<TOutputs>): Promise<RunResult<TOutputs>>;
|
|
2879
|
-
/**
|
|
2880
|
-
* Phase 19 (v1.2): single-agent execution loop. Drives multiple provider
|
|
2881
|
-
* iterations under one call, dispatching tool requests between iterations.
|
|
2882
|
-
* Composes with the v1.2 hook pipeline (SAFETY-band veto, OBSERVABILITY-band
|
|
2883
|
-
* checkpoint receipts) and the v1.2 capability receipts (when
|
|
2884
|
-
* `intent.signer` is provided + `intent.autoRegisterCheckpoint !== false`).
|
|
2885
|
-
*
|
|
2886
|
-
* See `packages/lattice/src/agent/runtime.ts` for orchestration details.
|
|
2887
|
-
*/
|
|
2888
|
-
runAgent<const TOutputs extends OutputContractMap>(intent: AgentIntent<TOutputs>): Promise<AgentResult<TOutputs>>;
|
|
2889
|
-
/**
|
|
2890
|
-
* Phase 39 (v1.3): opt-in multi-agent crew execution. Runs a literal
|
|
2891
|
-
* `AgentSpec` tree through the existing single-agent loop plus the crew
|
|
2892
|
-
* dispatcher, with shared budget/rate-limit coordination and chained
|
|
2893
|
-
* completion receipts.
|
|
2894
|
-
*
|
|
2895
|
-
* See `packages/lattice/src/agent/crew/run-crew.ts` for orchestration details.
|
|
2896
|
-
*/
|
|
2897
|
-
runAgentCrew(options: RunAgentCrewOptions): Promise<CrewResult>;
|
|
2898
|
-
}
|
|
2899
|
-
declare function createAI(config?: LatticeConfig): AI;
|
|
2900
|
-
//#endregion
|
|
2901
|
-
//#region src/replay/replay.d.ts
|
|
2902
|
-
interface ReplayEnvelope<TOutputs extends OutputContractMap = OutputContractMap> {
|
|
2903
|
-
readonly kind: "replay-envelope";
|
|
2904
|
-
readonly version: 1;
|
|
2905
|
-
readonly runtimeVersion: string;
|
|
2906
|
-
readonly catalogVersion: string;
|
|
2907
|
-
readonly createdAt: string;
|
|
2908
|
-
readonly plan: ExecutionPlan;
|
|
2909
|
-
readonly artifacts: readonly ArtifactRef[];
|
|
2910
|
-
readonly outputs?: InferOutputMap<TOutputs>;
|
|
2911
|
-
readonly warnings: readonly string[];
|
|
2912
|
-
readonly errors: readonly string[];
|
|
2913
|
-
readonly usage?: UsageRecord;
|
|
2914
|
-
readonly events: readonly RunEvent[];
|
|
2915
|
-
/**
|
|
2916
|
-
* Phase 10 — optional signed receipt recorded alongside the envelope so a
|
|
2917
|
-
* single artifact is sufficient to materialize an offline replay session
|
|
2918
|
-
* deterministically. Type-only import — replay.ts stays runtime-import-free
|
|
2919
|
-
* of the receipts builder.
|
|
2920
|
-
*/
|
|
2921
|
-
readonly receipt?: ReceiptEnvelope;
|
|
2922
|
-
/**
|
|
2923
|
-
* Phase 10 — optional contract recorded so replays can re-run pre-flight
|
|
2924
|
-
* checks deterministically.
|
|
2925
|
-
*/
|
|
2926
|
-
readonly contract?: CapabilityContract;
|
|
2927
|
-
}
|
|
2928
|
-
declare function createReplayEnvelope<TOutputs extends OutputContractMap>(result: RunResult<TOutputs>): ReplayEnvelope<TOutputs>;
|
|
2929
|
-
declare function replayOffline<TOutputs extends OutputContractMap>(envelope: ReplayEnvelope<TOutputs>): Promise<RunResult<TOutputs>>;
|
|
2930
|
-
declare function rerunLive<TOutputs extends OutputContractMap>(ai: AI, envelope: ReplayEnvelope<TOutputs>, intent: RunIntent<TOutputs>): Promise<RunResult<TOutputs>>;
|
|
2931
|
-
declare function redactReplayEnvelope<TOutputs extends OutputContractMap>(envelope: ReplayEnvelope<TOutputs>): ReplayEnvelope<TOutputs>;
|
|
2932
|
-
declare function redactPlan(plan: ExecutionPlan): ExecutionPlan;
|
|
2933
|
-
declare function redactArtifactRef(ref: ArtifactRef): ArtifactRef;
|
|
2934
|
-
//#endregion
|
|
2935
|
-
//#region src/replay/materialize.d.ts
|
|
2936
|
-
/**
|
|
2937
|
-
* Discriminated union of materialization failure modes.
|
|
2938
|
-
*
|
|
2939
|
-
* - "verify-failed" — receipt failed verifyReceipt (signature, key
|
|
2940
|
-
* missing/revoked, canonicalization mismatch).
|
|
2941
|
-
* - "artifact-load-failed" — the artifactLoader callback rejected for at
|
|
2942
|
-
* least one input hash.
|
|
2943
|
-
* - "envelope-malformed" — receipt verified but the verified body is
|
|
2944
|
-
* structurally unusable (should never happen
|
|
2945
|
-
* under verifyReceipt invariants, but kept as a
|
|
2946
|
-
* defensive third branch).
|
|
2947
|
-
*/
|
|
2948
|
-
interface MaterializationError {
|
|
2949
|
-
readonly kind: "verify-failed" | "artifact-load-failed" | "envelope-malformed";
|
|
2950
|
-
readonly message: string;
|
|
2951
|
-
}
|
|
2952
|
-
/**
|
|
2953
|
-
* Async callback that resolves an artifact body from its sha256 hex digest.
|
|
2954
|
-
* Phase 10 ships only the in-memory variant for tests. Phase 11's CLI plugs
|
|
2955
|
-
* in a filesystem-backed loader reading from `.lattice/fixtures/<sha256>.bin`.
|
|
2956
|
-
*/
|
|
2957
|
-
type ArtifactLoader = (hash: string) => Promise<ArtifactInput>;
|
|
2958
|
-
interface MaterializeReplayEnvelopeOptions<TOutputs extends OutputContractMap = OutputContractMap> {
|
|
2959
|
-
readonly artifactLoader: ArtifactLoader;
|
|
2960
|
-
readonly keySet: KeySet;
|
|
2961
|
-
/** Optional original task string. Defaults to "" when omitted. */
|
|
2962
|
-
readonly task?: string;
|
|
2963
|
-
/**
|
|
2964
|
-
* Optional caller-supplied outputs map. When provided, the resulting
|
|
2965
|
-
* `ReplayEnvelope.outputs` is populated and `replayOffline` will return
|
|
2966
|
-
* an `ok: true` result. When omitted, `replayOffline` reports an
|
|
2967
|
-
* `execution_unavailable` failure (current Phase 5 semantics).
|
|
2968
|
-
*/
|
|
2969
|
-
readonly outputs?: InferOutputMap<TOutputs>;
|
|
133
|
+
readonly transport: "websocket";
|
|
134
|
+
readonly endpoint: "wss://generativelanguage.googleapis.com/ws/google.ai.generativelanguage.v1beta.GenerativeService.BidiGenerateContent";
|
|
135
|
+
readonly preview: true;
|
|
136
|
+
}
|
|
137
|
+
type RealtimeProviderTarget = OpenAIRealtimeTarget | GeminiLiveTarget;
|
|
138
|
+
interface RealtimeSessionSpec {
|
|
139
|
+
readonly kind: "realtime-session-spec";
|
|
140
|
+
readonly supportLevel: RealtimeSupportLevel;
|
|
141
|
+
readonly sessionId: string;
|
|
142
|
+
readonly target: RealtimeProviderTarget;
|
|
143
|
+
readonly mode: RealtimeSessionMode;
|
|
144
|
+
readonly inputModalities: readonly RealtimeInputModality[];
|
|
145
|
+
readonly outputModalities: readonly RealtimeOutputModality[];
|
|
146
|
+
readonly artifactRefs?: readonly ArtifactRef[];
|
|
2970
147
|
readonly policy?: PolicySpec;
|
|
2971
|
-
readonly
|
|
2972
|
-
}
|
|
2973
|
-
/**
|
|
2974
|
-
* Pure async function that reconstructs a `ReplayEnvelope` from a receipt.
|
|
2975
|
-
*
|
|
2976
|
-
* Verify-FIRST ordering: `verifyReceipt` runs before `artifactLoader` is
|
|
2977
|
-
* touched. Tampered receipts MUST NOT cause loader side effects.
|
|
2978
|
-
*/
|
|
2979
|
-
declare function materializeReplayEnvelope<TOutputs extends OutputContractMap = OutputContractMap>(receipt: ReceiptEnvelope, options: MaterializeReplayEnvelopeOptions<TOutputs>): Promise<ReplayEnvelope<TOutputs>>;
|
|
2980
|
-
//#endregion
|
|
2981
|
-
//#region src/agent/runtime.d.ts
|
|
2982
|
-
/**
|
|
2983
|
-
* Resolves the runtime's behaviour for a single `ai.runAgent(intent)` call.
|
|
2984
|
-
*
|
|
2985
|
-
* Phase 19 ships an in-process default scheduler (the loop runs in the
|
|
2986
|
-
* calling Promise), direct transport (provider.execute()), and in-memory
|
|
2987
|
-
* transcript (the `conversation` array). Phase 20 promotes scheduler /
|
|
2988
|
-
* transport / storage to the pluggable `AgentHost` adapter.
|
|
2989
|
-
*
|
|
2990
|
-
* Phase 39: `runAgent` is a thin public wrapper over `runAgentInternal`
|
|
2991
|
-
* with no internal options — the public signature and behavior are
|
|
2992
|
-
* unchanged.
|
|
2993
|
-
*/
|
|
2994
|
-
declare function runAgent<TOutputs extends OutputContractMap = OutputContractMap>(intent: AgentIntent<TOutputs>, config?: LatticeConfig): Promise<AgentResult<TOutputs>>;
|
|
2995
|
-
//#endregion
|
|
2996
|
-
//#region src/agent/infra/cost-tracker.d.ts
|
|
2997
|
-
type CostBudgetStatus = "ok" | "warning" | "exceeded";
|
|
2998
|
-
interface CostTracker {
|
|
2999
|
-
readonly kind: "cost-tracker";
|
|
3000
|
-
/** Append a per-iteration Usage record. Mutates internal state. */
|
|
3001
|
-
recordIteration(usage: Usage): void;
|
|
3002
|
-
/** Returns the running sum across all recorded iterations. */
|
|
3003
|
-
total(): Usage;
|
|
3004
|
-
/**
|
|
3005
|
-
* Reports budget status against `contract.budget`:
|
|
3006
|
-
* - "ok" — under 80% of maxCostUsd.
|
|
3007
|
-
* - "warning" — at or over 80% but under 100%.
|
|
3008
|
-
* - "exceeded" — at or over 100% of maxCostUsd.
|
|
3009
|
-
* Returns "ok" when no budget is declared or when cumulative cost is null.
|
|
3010
|
-
*/
|
|
3011
|
-
budgetStatus(budget?: BudgetInvariant): CostBudgetStatus;
|
|
3012
|
-
}
|
|
3013
|
-
declare function createCostTracker(): CostTracker;
|
|
3014
|
-
//#endregion
|
|
3015
|
-
//#region src/agent/infra/transcript-store.d.ts
|
|
3016
|
-
/**
|
|
3017
|
-
* Token estimator used by `tailByTokens`. The default ~4 chars / token is
|
|
3018
|
-
* the OpenAI rule of thumb for English text. Callers with provider-specific
|
|
3019
|
-
* tokenizers can supply their own.
|
|
3020
|
-
*/
|
|
3021
|
-
type TokenEstimator = (text: string) => number;
|
|
3022
|
-
interface TranscriptStore {
|
|
3023
|
-
readonly kind: "transcript-store";
|
|
3024
|
-
append(turn: ConversationTurn): void;
|
|
3025
|
-
all(): readonly ConversationTurn[];
|
|
3026
|
-
/** Returns the first user turn (if any) + the most-recent `limit` turns. */
|
|
3027
|
-
tail(limit: number): readonly ConversationTurn[];
|
|
3028
|
-
/**
|
|
3029
|
-
* Returns the first user turn (if any) + the most-recent turns whose
|
|
3030
|
-
* combined token estimate fits within `maxTokens`. The default estimator
|
|
3031
|
-
* is the ~4 chars / token rule; callers can override for provider-
|
|
3032
|
-
* specific tokenizers.
|
|
3033
|
-
*/
|
|
3034
|
-
tailByTokens(maxTokens: number, estimator?: TokenEstimator): readonly ConversationTurn[];
|
|
3035
|
-
}
|
|
3036
|
-
declare function createTranscriptStore(): TranscriptStore;
|
|
3037
|
-
//#endregion
|
|
3038
|
-
//#region src/agent/infra/goal-progress.d.ts
|
|
3039
|
-
/**
|
|
3040
|
-
* GoalProgressTracker — Phase 21 (v1.2).
|
|
3041
|
-
*
|
|
3042
|
-
* Stuck-detection primitive. The caller declares a goal-satisfaction
|
|
3043
|
-
* score per iteration (0..1); the tracker reports a coarse status the
|
|
3044
|
-
* agent loop can use to back off or surface to the human.
|
|
3045
|
-
*/
|
|
3046
|
-
type ProgressStatus = "progressing" | "stalled" | "regressed";
|
|
3047
|
-
interface GoalProgressOptions {
|
|
3048
|
-
/**
|
|
3049
|
-
* Window of recent steps used for stall + regression detection.
|
|
3050
|
-
* Default 3. The tracker waits until it has at least this many steps
|
|
3051
|
-
* before reporting anything other than "progressing".
|
|
3052
|
-
*/
|
|
3053
|
-
readonly windowSize?: number;
|
|
3054
|
-
/** Max satisfaction delta across the window to count as "stalled". Default 0.02. */
|
|
3055
|
-
readonly stallThreshold?: number;
|
|
3056
|
-
/** Min drop from prior max to count as "regressed". Default 0.1. */
|
|
3057
|
-
readonly regressionThreshold?: number;
|
|
3058
|
-
}
|
|
3059
|
-
interface GoalProgressStep {
|
|
3060
|
-
readonly iterationIndex: number;
|
|
3061
|
-
readonly goalSatisfaction: number;
|
|
3062
|
-
}
|
|
3063
|
-
interface GoalProgressTracker {
|
|
3064
|
-
readonly kind: "goal-progress-tracker";
|
|
3065
|
-
recordStep(step: GoalProgressStep): void;
|
|
3066
|
-
status(): ProgressStatus;
|
|
3067
|
-
}
|
|
3068
|
-
declare function createGoalProgressTracker(options?: GoalProgressOptions): GoalProgressTracker;
|
|
3069
|
-
//#endregion
|
|
3070
|
-
//#region src/agent/infra/action-history.d.ts
|
|
3071
|
-
/**
|
|
3072
|
-
* ActionHistory — Phase 21 (v1.2).
|
|
3073
|
-
*
|
|
3074
|
-
* Detects stuck patterns in the agent loop's tool-call sequence:
|
|
3075
|
-
* - "consecutive-identical-tool-call" — same (toolName, argsHash) N+ times in a row
|
|
3076
|
-
* - "ping-pong" — last 4 records alternate between 2 distinct (toolName, argsHash) pairs
|
|
3077
|
-
* - "no-progress" — reserved for callers wiring goal-progress feedback here
|
|
3078
|
-
*
|
|
3079
|
-
* Standalone (no dependency on the agent runtime); callers register the
|
|
3080
|
-
* primitive externally and pump `recordAction` from their loop or hook.
|
|
3081
|
-
*/
|
|
3082
|
-
declare const STUCK_REASONS: readonly ["consecutive-identical-tool-call", "no-progress", "ping-pong"];
|
|
3083
|
-
type StuckReason = typeof STUCK_REASONS[number];
|
|
3084
|
-
interface ActionRecord {
|
|
3085
|
-
readonly iterationIndex: number;
|
|
3086
|
-
readonly toolName: string;
|
|
3087
|
-
readonly argsHash: string;
|
|
3088
|
-
}
|
|
3089
|
-
interface ActionHistoryOptions {
|
|
3090
|
-
/** Number of consecutive identical records that triggers the consecutive detector. Default 3. */
|
|
3091
|
-
readonly consecutiveLimit?: number;
|
|
3092
|
-
}
|
|
3093
|
-
interface ActionHistory {
|
|
3094
|
-
readonly kind: "action-history";
|
|
3095
|
-
/**
|
|
3096
|
-
* Append a record. Returns the latest StuckReason triggered by this
|
|
3097
|
-
* record, or null when no detector fires. The most recent reason wins
|
|
3098
|
-
* when multiple apply.
|
|
3099
|
-
*/
|
|
3100
|
-
recordAction(action: ActionRecord): StuckReason | null;
|
|
3101
|
-
history(): readonly ActionRecord[];
|
|
3102
|
-
}
|
|
3103
|
-
declare function createActionHistory(options?: ActionHistoryOptions): ActionHistory;
|
|
3104
|
-
//#endregion
|
|
3105
|
-
//#region src/agent/infra/permission-context.d.ts
|
|
3106
|
-
interface PermissionRule {
|
|
3107
|
-
/** Match on tool name. String = exact match; RegExp = test. Both undefined = match-any. */
|
|
3108
|
-
readonly toolName?: string | RegExp;
|
|
3109
|
-
/**
|
|
3110
|
-
* Optional resource matcher. The caller passes `resource` on each
|
|
3111
|
-
* decide() invocation; this rule fires only when the rule's resource
|
|
3112
|
-
* matches.
|
|
3113
|
-
*/
|
|
3114
|
-
readonly resource?: string | RegExp;
|
|
3115
|
-
readonly verdict: "allow" | "deny";
|
|
3116
|
-
readonly reason?: string;
|
|
3117
|
-
}
|
|
3118
|
-
interface PermissionDecisionInput {
|
|
3119
|
-
readonly toolName: string;
|
|
3120
|
-
readonly iterationIndex: number;
|
|
3121
|
-
readonly resource?: string;
|
|
3122
|
-
readonly args?: unknown;
|
|
3123
|
-
}
|
|
3124
|
-
type PermissionVerdict = {
|
|
3125
|
-
readonly allow: true;
|
|
3126
|
-
} | {
|
|
3127
|
-
readonly allow: false;
|
|
3128
|
-
readonly reason: string;
|
|
3129
|
-
};
|
|
3130
|
-
interface PermissionContext {
|
|
3131
|
-
readonly kind: "permission-context";
|
|
3132
|
-
decide(input: PermissionDecisionInput): PermissionVerdict;
|
|
3133
|
-
}
|
|
3134
|
-
declare function createPermissionContext(rules: readonly PermissionRule[]): PermissionContext;
|
|
3135
|
-
/**
|
|
3136
|
-
* Hook handler shape suitable for registering on `BEFORE_TOOL` at
|
|
3137
|
-
* BAND.SAFETY. Reads `toolName` and `iterationIndex` from the agent
|
|
3138
|
-
* runtime's BEFORE_TOOL context shape (`{ iterationIndex, toolName,
|
|
3139
|
-
* args }`) and translates a deny verdict into `controls.deny(reason)`.
|
|
3140
|
-
*/
|
|
3141
|
-
interface PermissionHookContext {
|
|
3142
|
-
readonly iterationIndex: number;
|
|
3143
|
-
readonly toolName: string;
|
|
3144
|
-
readonly resource?: string;
|
|
3145
|
-
readonly args?: unknown;
|
|
3146
|
-
}
|
|
3147
|
-
declare function createPermissionGuardHook(context: PermissionContext): HookHandler<PermissionHookContext>;
|
|
3148
|
-
/**
|
|
3149
|
-
* Convenience: returns RegisterOptions for the SAFETY-band registration.
|
|
3150
|
-
* Callers do `pipeline.register("BEFORE_TOOL", hook, permissionGuardRegisterOptions())`.
|
|
3151
|
-
*/
|
|
3152
|
-
declare function permissionGuardRegisterOptions(): RegisterOptions;
|
|
3153
|
-
//#endregion
|
|
3154
|
-
//#region src/agent/infra/rate-limit-group.d.ts
|
|
3155
|
-
interface RateLimitGroupOptions {
|
|
3156
|
-
/** Requests per minute. Defaults to 50 (Anthropic Tier 1). */
|
|
3157
|
-
readonly requestsPerMinute?: number;
|
|
3158
|
-
/** Input tokens per minute. Defaults to 30_000 (Anthropic Tier 1). */
|
|
3159
|
-
readonly tokensPerMinute?: number;
|
|
3160
|
-
/** Injectable clock for tests (defaults to `Date.now`). */
|
|
3161
|
-
readonly now?: () => number;
|
|
3162
|
-
}
|
|
3163
|
-
interface RateLimitLease {
|
|
3164
|
-
/**
|
|
3165
|
-
* Reconcile the reservation against actual usage. Refunds
|
|
3166
|
-
* `estimate - actual.promptTokens` to the token bucket when positive,
|
|
3167
|
-
* debits the difference when negative. Idempotent — only the first call
|
|
3168
|
-
* has an effect. Requests are never refunded.
|
|
3169
|
-
*/
|
|
3170
|
-
release(actual: {
|
|
3171
|
-
promptTokens: number;
|
|
3172
|
-
}): void;
|
|
3173
|
-
}
|
|
3174
|
-
interface RateLimitGroup {
|
|
3175
|
-
readonly kind: "rate-limit-group";
|
|
3176
|
-
/**
|
|
3177
|
-
* Reserve 1 request + `estimate.inputTokens` tokens. Resolves immediately
|
|
3178
|
-
* when both dimensions have capacity; otherwise the caller waits (FIFO)
|
|
3179
|
-
* until continuous drain refills the deficit.
|
|
3180
|
-
*/
|
|
3181
|
-
acquire(estimate: {
|
|
3182
|
-
inputTokens: number;
|
|
3183
|
-
}): Promise<RateLimitLease>;
|
|
3184
|
-
}
|
|
3185
|
-
declare function createRateLimitGroup(options?: RateLimitGroupOptions): RateLimitGroup;
|
|
3186
|
-
/**
|
|
3187
|
-
* Wrap an `AgentTransport` so every provider call is gated through `group`.
|
|
3188
|
-
*
|
|
3189
|
-
* Every transport wrapped with the SAME group instance shares one bucket —
|
|
3190
|
-
* `runAgentCrew` (39-06) wraps parent + child hosts with one shared group per
|
|
3191
|
-
* adapter instance, structurally guaranteeing crew-wide coordination (D-13).
|
|
3192
|
-
* `ProviderAdapter` is never modified (INV-03 parity invariant intact).
|
|
3193
|
-
*
|
|
3194
|
-
* - `inner` provided → dispatch nests through `inner.call(provider, request)`,
|
|
3195
|
-
* composing with consumer transports (e.g. cross-process bridges).
|
|
3196
|
-
* - `inner` undefined → falls through to `provider.execute(request)`, guarded
|
|
3197
|
-
* the same way as `createNoopAgentHost` (error names the provider id only).
|
|
3198
|
-
*
|
|
3199
|
-
* Release policy:
|
|
3200
|
-
* - Success → release with `normalizedUsage.promptTokens`; when usage is
|
|
3201
|
-
* missing or non-finite, fall back to the estimate (no NaN arithmetic —
|
|
3202
|
-
* the `costUsd: null` "unmeasured" discipline analog).
|
|
3203
|
-
* - Throw → release with the ORIGINAL estimate (burn — no refund; the
|
|
3204
|
-
* provider may have consumed quota despite the error) and rethrow the
|
|
3205
|
-
* same error unchanged. Request objects and headers are never serialized
|
|
3206
|
-
* into error paths.
|
|
3207
|
-
*/
|
|
3208
|
-
declare function withRateLimit(group: RateLimitGroup, inner?: AgentTransport): AgentTransport;
|
|
3209
|
-
//#endregion
|
|
3210
|
-
//#region src/receipts/cid.d.ts
|
|
3211
|
-
/**
|
|
3212
|
-
* Derive the content-addressed CID of a receipt envelope.
|
|
3213
|
-
*
|
|
3214
|
-
* Returns `sha256:<hex>` where `<hex>` is the 64-char lowercase SHA-256
|
|
3215
|
-
* digest of the decoded DSSE payload bytes. No KeySet, signer, or other
|
|
3216
|
-
* key material is required — callers chaining receipts (parentReceiptCid)
|
|
3217
|
-
* compute this from the parent envelope alone.
|
|
3218
|
-
*/
|
|
3219
|
-
declare function receiptCid(envelope: ReceiptEnvelope): Promise<string>;
|
|
3220
|
-
//#endregion
|
|
3221
|
-
//#region src/agent/eval.d.ts
|
|
3222
|
-
/**
|
|
3223
|
-
* Summary of an agent run sufficient for regression analysis. Callers
|
|
3224
|
-
* typically derive this from an `AgentSuccess` via `iterations.length` and
|
|
3225
|
-
* cumulative `usage`. The schema is intentionally minimal so callers can
|
|
3226
|
-
* persist + load it across runs without dragging the full ReplayEnvelope.
|
|
3227
|
-
*/
|
|
3228
|
-
interface AgentRunSnapshot {
|
|
3229
|
-
readonly iterationsToGoal: number;
|
|
3230
|
-
readonly usage: Usage;
|
|
3231
|
-
}
|
|
3232
|
-
interface EvalOptions {
|
|
3233
|
-
/**
|
|
3234
|
-
* Maximum tolerated INCREASE in iterations-to-goal versus the baseline.
|
|
3235
|
-
* Default 1 (one extra iteration tolerated). Set to 0 to require parity.
|
|
3236
|
-
*/
|
|
3237
|
-
readonly iterationsToGoalRegressionLimit?: number;
|
|
3238
|
-
/**
|
|
3239
|
-
* Maximum tolerated FRACTIONAL cost increase versus the baseline.
|
|
3240
|
-
* Default 0.10 (10% increase tolerated). Compared as
|
|
3241
|
-
* `(current - baseline) / baseline`. Cost regressions are only
|
|
3242
|
-
* considered when BOTH snapshots have a non-null `costUsd`; mixed-cost
|
|
3243
|
-
* snapshots emit a `mixed-cost-unknown` regression so callers can decide
|
|
3244
|
-
* how to handle them.
|
|
3245
|
-
*/
|
|
3246
|
-
readonly costUsdRegressionLimit?: number;
|
|
148
|
+
readonly checkpointing?: RealtimeCheckpointingSpec;
|
|
3247
149
|
}
|
|
3248
|
-
|
|
3249
|
-
|
|
3250
|
-
readonly
|
|
3251
|
-
readonly
|
|
3252
|
-
readonly current: number | null;
|
|
3253
|
-
readonly limit: number;
|
|
3254
|
-
readonly message: string;
|
|
150
|
+
interface RealtimeCheckpointingSpec {
|
|
151
|
+
readonly receiptThreading: "step-linked-list";
|
|
152
|
+
readonly summaryCheckpoints: "manual" | "session-close" | "interval";
|
|
153
|
+
readonly note: "direction-only";
|
|
3255
154
|
}
|
|
3256
|
-
interface
|
|
3257
|
-
readonly
|
|
3258
|
-
readonly
|
|
3259
|
-
|
|
3260
|
-
|
|
3261
|
-
|
|
3262
|
-
|
|
3263
|
-
|
|
3264
|
-
readonly id?: string;
|
|
155
|
+
interface RealtimeCheckpointInput {
|
|
156
|
+
readonly sessionId: string;
|
|
157
|
+
readonly provider: RealtimeProviderKind;
|
|
158
|
+
readonly checkpoint: RealtimeCheckpointKind;
|
|
159
|
+
readonly stepIndex: number;
|
|
160
|
+
readonly timestamp?: string;
|
|
161
|
+
readonly parentStepName?: string;
|
|
162
|
+
readonly previousStepName?: string;
|
|
3265
163
|
}
|
|
3266
|
-
|
|
3267
|
-
|
|
3268
|
-
|
|
3269
|
-
|
|
3270
|
-
readonly id?: string;
|
|
164
|
+
interface RealtimeReceiptDescriptors {
|
|
165
|
+
readonly sessionId: string;
|
|
166
|
+
readonly model: ReceiptModel;
|
|
167
|
+
readonly route: ReceiptRoute;
|
|
3271
168
|
}
|
|
3272
|
-
declare function
|
|
169
|
+
declare function createRealtimeCheckpointContext(input: RealtimeCheckpointInput): CheckpointHookContext;
|
|
170
|
+
declare function createRealtimeReceiptDescriptors(spec: RealtimeSessionSpec): RealtimeReceiptDescriptors;
|
|
171
|
+
declare function realtimeStepName(provider: RealtimeProviderKind, checkpoint: RealtimeCheckpointKind): string;
|
|
3273
172
|
//#endregion
|
|
3274
173
|
//#region src/version.d.ts
|
|
3275
|
-
declare const latticeVersion = "
|
|
3276
|
-
//#endregion
|
|
3277
|
-
//#region src/capabilities/lookup.d.ts
|
|
3278
|
-
/**
|
|
3279
|
-
* Strip the OpenRouter variant suffix (`:free` or `:thinking`) from an
|
|
3280
|
-
* OpenRouter-shaped id (`vendor/model:variant`). Other adapter id shapes
|
|
3281
|
-
* pass through verbatim — does not, for example, alter
|
|
3282
|
-
* `anthropic:claude-opus-4` (direct-adapter canonical key) or
|
|
3283
|
-
* `openai/gpt-4o:beta` (unrecognized variant per Pitfall 4).
|
|
3284
|
-
*
|
|
3285
|
-
* Exported because Phase 34 (adapter quirks) and Phase 36 (output
|
|
3286
|
-
* sanitizers) need the same normalization. Phase 33 D-11 scope.
|
|
3287
|
-
*/
|
|
3288
|
-
declare function stripOpenRouterVariant(id: string): string;
|
|
3289
|
-
/**
|
|
3290
|
-
* D-09 strict lookup — return the capability profile for the exact
|
|
3291
|
-
* `${adapter}:${modelId}` canonical key. Returns `undefined` if the key
|
|
3292
|
-
* is not registered. No fuzzy matching — use `findCapabilityProfile`
|
|
3293
|
-
* for that.
|
|
3294
|
-
*
|
|
3295
|
-
* Examples:
|
|
3296
|
-
* getCapabilityProfile("openrouter:openai/gpt-oss-120b") -> profile
|
|
3297
|
-
* getCapabilityProfile("anthropic:claude-opus-4") -> profile
|
|
3298
|
-
* getCapabilityProfile("not-a-real-key") -> undefined
|
|
3299
|
-
*
|
|
3300
|
-
* The lookup is case-sensitive on the canonical key. Threat T-33-02-01
|
|
3301
|
-
* mitigation: backing store is `Map<string, ModelCapabilityProfile>`,
|
|
3302
|
-
* not a plain object literal, so `__proto__` and other prototype-chain
|
|
3303
|
-
* keys are safe (Map uses SameValueZero, not property lookup).
|
|
3304
|
-
*/
|
|
3305
|
-
declare function getCapabilityProfile(canonicalKey: string): ModelCapabilityProfile | undefined;
|
|
3306
|
-
/**
|
|
3307
|
-
* D-10 fuzzy lookup — strip the OpenRouter variant suffix (if any) and
|
|
3308
|
-
* return ALL matching profiles across every adapter, in deterministic
|
|
3309
|
-
* order: direct adapters first (anthropic, openai, gemini, xai,
|
|
3310
|
-
* openai-compat, lm-studio), then OpenRouter.
|
|
3311
|
-
*
|
|
3312
|
-
* Useful for pre-routing capability inspection where the adapter has
|
|
3313
|
-
* not yet been chosen — the consumer can iterate the returned list
|
|
3314
|
-
* and pick the first compatible one. Returns `[]` when no match is
|
|
3315
|
-
* found across any adapter.
|
|
3316
|
-
*
|
|
3317
|
-
* Suffix-strip is OpenRouter-shape-only per D-11. Direct-adapter ids
|
|
3318
|
-
* pass through verbatim:
|
|
3319
|
-
* findCapabilityProfile("openai/gpt-oss-120b:free")
|
|
3320
|
-
* -> [openrouter:openai/gpt-oss-120b]
|
|
3321
|
-
* findCapabilityProfile("claude-opus-4")
|
|
3322
|
-
* -> [anthropic:claude-opus-4, ...] (no suffix-strip)
|
|
3323
|
-
*/
|
|
3324
|
-
declare function findCapabilityProfile(id: string): ModelCapabilityProfile[];
|
|
3325
|
-
//#endregion
|
|
3326
|
-
//#region src/prompts/scaffolds.d.ts
|
|
3327
|
-
declare const PROMPT_SCAFFOLD_VERSION: "lattice.prompt-scaffold/v1";
|
|
3328
|
-
declare const PROMPT_STRATEGIES: readonly ["frontier", "mid_tier", "open_weight", "reasoning", "local"];
|
|
3329
|
-
declare function getStructuredOutputContract(strategy: RecommendedPromptStrategy, schema: unknown): string;
|
|
3330
|
-
declare function getToolUseContract(strategy: RecommendedPromptStrategy, tools: unknown): string;
|
|
174
|
+
declare const latticeVersion = "1.5.0";
|
|
3331
175
|
//#endregion
|
|
3332
|
-
export { type AI, ALL_KNOWN_FAILURE_MODES, ALL_TRAINING_CLASSES, type ActionHistory, type ActionHistoryOptions, type ActionRecord, type AdapterQuirks, AgentDeniedError, type AgentEvalResult, type AgentFailure, type AgentFailureKind, type AgentHost, type AgentIntent, type AgentResult, type AgentRunSnapshot, type AgentScheduler, type AgentSnapshot, type AgentSpec, type AgentStorage, type AgentSuccess, type AgentTransport, type AnthropicProviderOptions, type AnthropicQuirks, type ArtifactFingerprint, type ArtifactInput, type ArtifactKind, type ArtifactLineage, type ArtifactOptions, type ArtifactParentRef, type ArtifactPrivacy, type ArtifactRef, type ArtifactSize, type ArtifactSource, type ArtifactStorageRef, type ArtifactStore, type ArtifactTransformDescriptor, type ArtifactTransformKind, BAND, type BudgetInvariant, type CapabilityAdapter, type CapabilityContract, type CapabilityContractInput, type CapabilityReceiptBody, type CheckpointHookContext, type CheckpointHookOptions, type ContractRejectReasonCode, type ContractVerdict, type ConversationTurn, type CostBudgetStatus, type CostTracker, type CreateReceiptInput, type CrewAgentResult, type CrewPolicy, type CrewRateLimitOverride, type CrewResult, DEFAULT_CHECKPOINT_BAND, type EvalOptions, type EvalRegression, type EvalRegressionKind, type EvictionHook, type ExecutionPlanStub, type FieldFromTableInvariant, type FormatToolsMode, type FormatToolsOptions, type FormattedToolsHandle, type GeminiProviderOptions, type GeminiQuirks, type GoalProgressOptions, type GoalProgressStep, type GoalProgressTracker, type HookControls, type HookDenyDirective, type HookLifecycleEvent, type HookPipeline, type InferOutput, type InferOutputMap, type InternalEnvelopeOptions, type InvariantDeclaration, type InvariantOptions, type IterationRecord, type KeyEntry, type KeySet, type KeyState, type KnownFailureMode, type LatticeConfig, type LatticeRunError, type LmStudioProviderOptions, type LmStudioQuirks, type MatchesInvariant, type MaterializationError, type MaterializeReplayEnvelopeOptions, type ModelCapabilityProfile, type MustCiteInvariant, type NegotiatedCapabilities, NegotiationAuthError, type NoPiiInvariant, type NormalizedLatticeConfig, type OpenAICompatQuirks, type OpenAIQuirks, type OpenRouterProviderOptions, type OpenRouterQuirks, type OutputContract, type OutputContractMap, PROMPT_SCAFFOLD_VERSION, PROMPT_STRATEGIES, type PermissionContext, type PermissionDecisionInput, type PermissionHookContext, type PermissionRule, type PermissionVerdict, type PiiDetector, type PiiDetectorResult, type PolicySpec, type ProgressStatus, type ProviderAdapter, type ProviderRef, type ProviderRunRequest, type ProviderRunResponse, type QualityFloorInvariant, type RateLimitGroup, type RateLimitGroupOptions, type RateLimitLease, type ReasoningSurface, type ReceiptEnvelope, type ReceiptModel, type ReceiptRedaction, type ReceiptRoute, type ReceiptSignature, type ReceiptSigner, type ReceiptUsageCanonical, type RecommendedPromptStrategy, type ReplayEnvelope, type ResumePolicy, type RunAgentCrewOptions, type RunEvent, type RunEventKind, type RunEventSink, type RunFailure, type RunIntent, type RunResult, type RunSuccess, SANITIZER_BY_FAILURE_MODE, STEP_TRANSITION_EVENT_NAME, STUCK_REASONS, type SanitizeOutputOption, type SanitizerContext, type SanitizerFn, type SanitizerKey, type SerializedSnapshot, type SessionRef, type StorageLike, type StoredArtifactEnvelope, type StoredArtifactPayloadDescriptor, type StuckReason, type SurvivabilityAdapter, type TokenEstimator, type ToolCallSurface, ToolCallValidationError, type ToolCallValidationFailureReason, type ToolUseRequest, type TracerLike, type TrainingClass, type TranscriptStore, type TripwireEvidence, type TripwireResult, type TripwireViolationError, type UnsubscribeFn, type Usage, type ValidateToolCallsOption, type ValidatedToolCall, type ValidationIssue, type VerifyError, type VerifyErrorKind, type VerifyFail, type VerifyOk, type VerifyResult, type XaiProviderOptions, type XaiQuirks, artifact, contract, createAI, createAISdkProvider, createActionHistory, createAnthropicProvider, createCheckpointHook, createCostTracker, createFakeProvider, createGeminiProvider, createGoalProgressTracker, createHookPipeline, createInMemorySigner, createLmStudioProvider, createLocalArtifactStore, createMemoryArtifactStore, createMemoryKeySet, createMemorySessionStore, createNoopAgentHost, createNoopSurvivabilityAdapter, createOpenAICompatibleProvider, createOpenAIProvider, createOpenRouterProvider, createPermissionContext, createPermissionGuardHook, createRateLimitGroup, createReceipt, createReplayEnvelope, createTranscriptStore, createXaiProvider, defaultPiiDetectors, defineAgent, defineTool, estimateRouteCost, evalAgentRun, evaluateContractAgainstRoute, evaluateTripwires, findCapabilityProfile, formatToolsForProvider, generateEd25519KeyPairJwk, getCapabilityProfile, getRecommendedSanitizers, getStructuredOutputContract, getToolUseContract, importMcpTools, inv, isTerminal, latticeVersion, materializeReplayEnvelope, negotiateCapabilities, output, parseToolUseEnvelope, permissionGuardRegisterOptions, receiptCid, redactArtifactRef, redactPlan, redactReplayEnvelope, replayOffline, rerunLive, runAgent, runAgentCrew, runTool, stripChatTemplateArtifacts, stripOpenRouterVariant, stripReasoningTags, synthesizeNegotiatedCapabilitiesFromRegistry, toolArtifactRef, toolSchemaToJsonSchema, unwrapInternalEnvelope, verifyReceipt, withRateLimit };
|
|
176
|
+
export { type AI, ALL_KNOWN_FAILURE_MODES, ALL_TRAINING_CLASSES, type ActionHistory, type ActionHistoryOptions, type ActionRecord, type AdapterQuirks, AgentDeniedError, type AgentEvalResult, type AgentFailure, type AgentFailureKind, type AgentHost, type AgentIntent, type AgentResult, type AgentRunSnapshot, type AgentScheduler, type AgentSnapshot, type AgentSpec, type AgentStorage, type AgentSuccess, type AgentTransport, type AnthropicProviderOptions, type AnthropicQuirks, type ArtifactFingerprint, type ArtifactInput, type ArtifactKind, type ArtifactLineage, type ArtifactOptions, type ArtifactParentRef, type ArtifactPrivacy, type ArtifactRef, type ArtifactSize, type ArtifactSource, type ArtifactStorageRef, type ArtifactStore, type ArtifactTransformDescriptor, type ArtifactTransformKind, BAND, type BudgetInvariant, type CapabilityAdapter, type CapabilityContract, type CapabilityContractInput, type CapabilityReceiptBody, type CheckpointHookContext, type CheckpointHookOptions, type CollectStreamOptions, type ContractRejectReasonCode, type ContractVerdict, type ConversationTurn, type CostBudgetStatus, type CostTracker, type CreateReceiptInput, type CrewAgentResult, type CrewPolicy, type CrewRateLimitOverride, type CrewResult, DEFAULT_CHECKPOINT_BAND, type EvalOptions, type EvalRegression, type EvalRegressionKind, type EvictionHook, type ExecutionPlanStub, type ExternalExecutionAuditInput, type ExternalExecutionAuditResult, type ExternalExecutionMetadata, type ExternalExecutionSidecar, type ExternalExecutionSidecarOutputSpec, type ExternalExecutionUsage, type FieldFromTableInvariant, type FormatToolsMode, type FormatToolsOptions, type FormattedToolsHandle, type GatewayMetadataValue, type GatewayPolicy, type GeminiLiveTarget, type GeminiProviderOptions, type GeminiQuirks, type GoalProgressOptions, type GoalProgressStep, type GoalProgressTracker, type HookControls, type HookDenyDirective, type HookLifecycleEvent, type HookPipeline, type InferOutput, type InferOutputMap, type InternalEnvelopeOptions, type InvariantDeclaration, type InvariantOptions, type IterationRecord, type KeyEntry, type KeySet, type KeyState, type KnownFailureMode, type LangfuseOtlpConfigOptions, type LatticeConfig, type LatticeRunError, type LiteLLMProviderOptions, type LiteLLMQuirks, type LmStudioProviderOptions, type LmStudioQuirks, type MatchesInvariant, type MaterializationError, type MaterializeReplayEnvelopeOptions, type ModelCapabilityProfile, type ModelCapabilityProfileModality, type ModelCapabilityProfilePricing, type ModelCapabilityProfilePricingKey, type MustCiteInvariant, type NegotiatedCapabilities, NegotiationAuthError, type NoPiiInvariant, NoPublicUrlEgressError, type NormalizedLatticeConfig, type OpenAICompatQuirks, type OpenAIQuirks, type OpenAIRealtimeTarget, type OpenRouterProviderOptions, type OpenRouterQuirks, type OtelAttributeValue, type OtelAttributes, type OtelContentCaptureMode, type OtelHttpTraceConfig, type OtelRunEventSinkOptions, type OtelSanitizerOptions, type OtelSpanLike, type OtelSpanStatus, type OtelTracerLike, type OutputContract, type OutputContractMap, PROMPT_SCAFFOLD_VERSION, PROMPT_STRATEGIES, type PermissionContext, type PermissionDecisionInput, type PermissionHookContext, type PermissionRule, type PermissionVerdict, type PhoenixOtlpConfigOptions, type PiiDetector, type PiiDetectorResult, type PolicySpec, type ProgressStatus, type ProviderAdapter, type ProviderGatewayMetadata, type ProviderRef, type ProviderRunRequest, type ProviderRunResponse, type ProviderStream, type ProviderStreamChunk, type ProviderStreamCompleteChunk, type ProviderStreamGatewayChunk, type ProviderStreamOutputChunk, type ProviderStreamTextDeltaChunk, type ProviderStreamToolCallChunk, type ProviderStreamUsageChunk, type QualityFloorInvariant, REALTIME_DIRECTION_SUPPORT_LEVEL, type RateLimitGroup, type RateLimitGroupOptions, type RateLimitLease, type RealtimeCheckpointInput, type RealtimeCheckpointKind, type RealtimeCheckpointingSpec, type RealtimeInputModality, type RealtimeOutputModality, type RealtimeProviderKind, type RealtimeProviderTarget, type RealtimeReceiptDescriptors, type RealtimeSessionMode, type RealtimeSessionSpec, type RealtimeSupportLevel, type RealtimeTransportKind, type ReasoningSurface, type ReceiptEnvelope, type ReceiptModel, type ReceiptRedaction, type ReceiptRoute, type ReceiptSignature, type ReceiptSigner, type ReceiptUsageCanonical, type RecommendedPromptStrategy, type RemoteReceiptPayloadFormat, type RemoteReceiptSignRequest, type RemoteReceiptSignResult, type RemoteReceiptSignerOptions, type RemoteReceiptSignerProvider, type ReplayEnvelope, type ResumePolicy, type RunAgentCrewOptions, type RunEvent, type RunEventKind, type RunEventSink, type RunFailure, type RunIntent, type RunResult, type RunSuccess, SANITIZER_BY_FAILURE_MODE, STEP_TRANSITION_EVENT_NAME, STUCK_REASONS, type SanitizeOutputOption, type SanitizerContext, type SanitizerFn, type SanitizerKey, type SerializedSnapshot, type SessionRef, type StorageLike, type StoredArtifactEnvelope, type StoredArtifactPayloadDescriptor, type StuckReason, type SurvivabilityAdapter, type TokenEstimator, type ToolCallSurface, ToolCallValidationError, type ToolCallValidationFailureReason, type ToolUseRequest, type TracerLike, type TrainingClass, type TranscriptStore, type TripwireEvidence, type TripwireResult, type TripwireViolationError, type UnsubscribeFn, type Usage, type ValidateToolCallsOption, type ValidatedToolCall, type ValidationIssue, type VerifyError, type VerifyErrorKind, type VerifyFail, type VerifyOk, type VerifyResult, type XaiProviderOptions, type XaiQuirks, artifact, collectStream, contract, createAI, createAISdkProvider, createActionHistory, createAnthropicProvider, createCheckpointHook, createCostTracker, createExternalExecutionAudit, createFakeProvider, createGeminiProvider, createGoalProgressTracker, createHookPipeline, createInMemorySigner, createLangfuseOtlpConfig, createLiteLLMProvider, createLmStudioProvider, createLocalArtifactStore, createMemoryArtifactStore, createMemoryKeySet, createMemorySessionStore, createNoopAgentHost, createNoopSurvivabilityAdapter, createOpenAICompatibleProvider, createOpenAIProvider, createOpenRouterProvider, createOtelReceiptAttributes, createOtelRunEventSink, createPermissionContext, createPermissionGuardHook, createPhoenixOtlpConfig, createRateLimitGroup, createRealtimeCheckpointContext, createRealtimeReceiptDescriptors, createReceipt, createRemoteReceiptSigner, createReplayEnvelope, createTranscriptStore, createXaiProvider, defaultPiiDetectors, defineAgent, defineTool, estimateRouteCost, evalAgentRun, evaluateContractAgainstRoute, evaluateTripwires, findCapabilityProfile, formatToolsForProvider, generateEd25519KeyPairJwk, getCapabilityProfile, getRecommendedSanitizers, getStructuredOutputContract, getToolUseContract, importMcpTools, inv, isTerminal, latticeVersion, materializeReplayEnvelope, negotiateCapabilities, output, parseToolUseEnvelope, permissionGuardRegisterOptions, realtimeStepName, receiptCid, redactArtifactRef, redactPlan, redactReplayEnvelope, replayOffline, rerunLive, runAgent, runAgentCrew, runTool, sanitizeRunEventAttributes, stripChatTemplateArtifacts, stripOpenRouterVariant, stripReasoningTags, synthesizeNegotiatedCapabilitiesFromRegistry, toolArtifactRef, toolSchemaToJsonSchema, unwrapInternalEnvelope, verifyReceipt, withRateLimit };
|
|
3333
177
|
//# sourceMappingURL=index.d.ts.map
|