@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
|
@@ -0,0 +1,1178 @@
|
|
|
1
|
+
import { i as ArtifactKind, r as ArtifactInput, s as ArtifactRef } from "./artifact-Bg6mJGnm.js";
|
|
2
|
+
import { StandardSchemaV1 } from "@standard-schema/spec";
|
|
3
|
+
|
|
4
|
+
//#region src/tracing/tracing.d.ts
|
|
5
|
+
interface TracerLike {
|
|
6
|
+
readonly kind: "tracer";
|
|
7
|
+
readonly span?: <T>(name: string, fn: () => T | Promise<T>, attributes?: Record<string, unknown>) => T | Promise<T>;
|
|
8
|
+
readonly event?: (name: string, attributes?: Record<string, unknown>) => void;
|
|
9
|
+
}
|
|
10
|
+
type RunEventKind = "run.start" | "artifact.ingested" | "context.packed" | "router.candidates" | "stage.start" | "stage.complete" | "provider.attempt" | "stream.start" | "stream.complete" | "stream.failed" | "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";
|
|
11
|
+
interface RunEvent {
|
|
12
|
+
readonly kind: RunEventKind;
|
|
13
|
+
readonly timestamp: string;
|
|
14
|
+
readonly runId: string;
|
|
15
|
+
readonly planId?: string;
|
|
16
|
+
readonly stageId?: string;
|
|
17
|
+
readonly providerId?: string;
|
|
18
|
+
readonly modelId?: string;
|
|
19
|
+
readonly artifactId?: string;
|
|
20
|
+
readonly metadata?: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
type RunEventSink = (event: RunEvent) => void | Promise<void>;
|
|
23
|
+
//#endregion
|
|
24
|
+
//#region src/outputs/contracts.d.ts
|
|
25
|
+
type TextOutputContract = "text";
|
|
26
|
+
interface CitationRef {
|
|
27
|
+
readonly artifactId: string;
|
|
28
|
+
readonly label?: string;
|
|
29
|
+
readonly span?: {
|
|
30
|
+
readonly start?: number;
|
|
31
|
+
readonly end?: number;
|
|
32
|
+
};
|
|
33
|
+
readonly metadata?: Record<string, unknown>;
|
|
34
|
+
}
|
|
35
|
+
interface CitationsOutputContract {
|
|
36
|
+
readonly kind: "citations";
|
|
37
|
+
}
|
|
38
|
+
interface ArtifactRefsOutputContract {
|
|
39
|
+
readonly kind: "artifacts";
|
|
40
|
+
readonly artifactKind?: ArtifactKind | string;
|
|
41
|
+
}
|
|
42
|
+
type SchemaOutputContract = StandardSchemaV1;
|
|
43
|
+
type OutputContract = TextOutputContract | SchemaOutputContract | CitationsOutputContract | ArtifactRefsOutputContract;
|
|
44
|
+
type OutputContractMap = Record<string, OutputContract>;
|
|
45
|
+
declare const output: {
|
|
46
|
+
citations(): CitationsOutputContract;
|
|
47
|
+
artifacts(options?: {
|
|
48
|
+
readonly artifactKind?: ArtifactKind | string;
|
|
49
|
+
}): ArtifactRefsOutputContract;
|
|
50
|
+
};
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/plan/plan.d.ts
|
|
53
|
+
type ExecutionPlanStatus = "stub" | "planned" | "no-route" | "running" | "completed" | "failed";
|
|
54
|
+
type ExecutionStageKind = "analysis" | "transforms" | "context-packing" | "provider-packaging" | "tool-execution" | "execution" | "validation" | "tripwire" | "persistence" | "replay";
|
|
55
|
+
type ExecutionStageStatus = "pending" | "running" | "completed" | "skipped" | "failed";
|
|
56
|
+
interface ExecutionPlanStage {
|
|
57
|
+
readonly id: string;
|
|
58
|
+
readonly kind: ExecutionStageKind;
|
|
59
|
+
readonly status: ExecutionStageStatus;
|
|
60
|
+
readonly inputArtifacts?: readonly string[];
|
|
61
|
+
readonly outputArtifacts?: readonly string[];
|
|
62
|
+
readonly warnings: readonly string[];
|
|
63
|
+
readonly metadata?: Record<string, unknown>;
|
|
64
|
+
}
|
|
65
|
+
interface RouteRejectReason {
|
|
66
|
+
readonly code: string;
|
|
67
|
+
readonly message: string;
|
|
68
|
+
}
|
|
69
|
+
interface RouteCandidate {
|
|
70
|
+
readonly providerId: string;
|
|
71
|
+
readonly modelId: string;
|
|
72
|
+
readonly capability: ModelCapability;
|
|
73
|
+
readonly score: number;
|
|
74
|
+
readonly accepted: boolean;
|
|
75
|
+
readonly reasons: readonly RouteRejectReason[];
|
|
76
|
+
readonly estimates: RouteEstimates;
|
|
77
|
+
}
|
|
78
|
+
interface RouteEstimates {
|
|
79
|
+
readonly inputTokens: number;
|
|
80
|
+
readonly outputTokens: number;
|
|
81
|
+
readonly costUsd?: number;
|
|
82
|
+
readonly latencyMs?: number;
|
|
83
|
+
}
|
|
84
|
+
interface SelectedRoute {
|
|
85
|
+
readonly providerId: string;
|
|
86
|
+
readonly modelId: string;
|
|
87
|
+
readonly score: number;
|
|
88
|
+
readonly estimates: RouteEstimates;
|
|
89
|
+
readonly inputModalities: readonly CapabilityModality[];
|
|
90
|
+
readonly outputModalities: readonly CapabilityModality[];
|
|
91
|
+
readonly fileTransport: readonly ProviderTransportMode[];
|
|
92
|
+
}
|
|
93
|
+
interface FallbackRoute {
|
|
94
|
+
readonly providerId: string;
|
|
95
|
+
readonly modelId: string;
|
|
96
|
+
readonly score: number;
|
|
97
|
+
readonly reason: "policy-preserving-fallback";
|
|
98
|
+
}
|
|
99
|
+
interface RouteDecision {
|
|
100
|
+
readonly catalogVersion: string;
|
|
101
|
+
readonly selected?: SelectedRoute;
|
|
102
|
+
readonly candidates: readonly RouteCandidate[];
|
|
103
|
+
readonly rejected: readonly RouteCandidate[];
|
|
104
|
+
readonly fallbackChain: readonly FallbackRoute[];
|
|
105
|
+
readonly noRouteReasons: readonly RouteRejectReason[];
|
|
106
|
+
}
|
|
107
|
+
interface ContextPackPlan {
|
|
108
|
+
readonly id: string;
|
|
109
|
+
readonly tokenBudget: number;
|
|
110
|
+
readonly estimatedTokens: number;
|
|
111
|
+
readonly included: readonly ContextPackItemPlan[];
|
|
112
|
+
readonly summarized: readonly ContextPackItemPlan[];
|
|
113
|
+
readonly archived: readonly ContextPackItemPlan[];
|
|
114
|
+
readonly omitted: readonly ContextPackItemPlan[];
|
|
115
|
+
readonly warnings: readonly string[];
|
|
116
|
+
}
|
|
117
|
+
interface ContextPackItemPlan {
|
|
118
|
+
readonly artifactId?: string;
|
|
119
|
+
readonly sessionTurnId?: string;
|
|
120
|
+
readonly reason: string;
|
|
121
|
+
readonly estimatedTokens: number;
|
|
122
|
+
readonly trust: "developer" | "user" | "tool" | "model-summary";
|
|
123
|
+
}
|
|
124
|
+
interface ProviderPackagingPlan {
|
|
125
|
+
readonly providerId: string;
|
|
126
|
+
readonly modelId: string;
|
|
127
|
+
readonly artifacts: readonly ProviderPackagedArtifactPlan[];
|
|
128
|
+
readonly warnings: readonly string[];
|
|
129
|
+
}
|
|
130
|
+
interface ProviderPackagedArtifactPlan {
|
|
131
|
+
readonly artifactId: string;
|
|
132
|
+
readonly transport: ProviderTransportMode;
|
|
133
|
+
readonly mediaType?: string;
|
|
134
|
+
readonly lineageTransform: "provider-packaging";
|
|
135
|
+
readonly providerRequest?: ProviderPackagedArtifactRequestPlan;
|
|
136
|
+
readonly warnings: readonly string[];
|
|
137
|
+
}
|
|
138
|
+
type ProviderPackagedArtifactSourceType = ProviderTransportMode | "file-reference";
|
|
139
|
+
interface ProviderPackagedArtifactRequestPlan {
|
|
140
|
+
readonly shape: string;
|
|
141
|
+
readonly sourceType: ProviderPackagedArtifactSourceType;
|
|
142
|
+
readonly reason: string;
|
|
143
|
+
readonly mediaType?: string;
|
|
144
|
+
readonly sizeBytes?: number;
|
|
145
|
+
readonly reference?: ProviderPackagedArtifactReferencePlan;
|
|
146
|
+
}
|
|
147
|
+
interface ProviderPackagedArtifactReferencePlan {
|
|
148
|
+
readonly kind: "url" | "file-id" | "file-uri" | "storage";
|
|
149
|
+
readonly metadataKey?: string;
|
|
150
|
+
}
|
|
151
|
+
interface ProviderAttemptRecord {
|
|
152
|
+
readonly providerId: string;
|
|
153
|
+
readonly modelId: string;
|
|
154
|
+
readonly status: "pending" | "running" | "succeeded" | "failed" | "cancelled";
|
|
155
|
+
readonly startedAt?: string;
|
|
156
|
+
readonly completedAt?: string;
|
|
157
|
+
readonly error?: string;
|
|
158
|
+
readonly usage?: UsageRecord;
|
|
159
|
+
readonly metadata?: Record<string, unknown>;
|
|
160
|
+
}
|
|
161
|
+
interface UsageRecord {
|
|
162
|
+
readonly inputTokens?: number;
|
|
163
|
+
readonly outputTokens?: number;
|
|
164
|
+
readonly totalTokens?: number;
|
|
165
|
+
readonly costUsd?: number;
|
|
166
|
+
readonly latencyMs?: number;
|
|
167
|
+
}
|
|
168
|
+
interface ExecutionPlan {
|
|
169
|
+
readonly id: string;
|
|
170
|
+
readonly kind: "execution-plan";
|
|
171
|
+
readonly version: 1;
|
|
172
|
+
readonly createdAt: string;
|
|
173
|
+
readonly status: ExecutionPlanStatus;
|
|
174
|
+
readonly task: string;
|
|
175
|
+
readonly outputNames: readonly string[];
|
|
176
|
+
readonly artifactRefs: readonly ArtifactRef[];
|
|
177
|
+
readonly route: RouteDecision;
|
|
178
|
+
readonly stages: readonly ExecutionPlanStage[];
|
|
179
|
+
readonly context?: ContextPackPlan;
|
|
180
|
+
readonly providerPackaging?: ProviderPackagingPlan;
|
|
181
|
+
readonly attempts: readonly ProviderAttemptRecord[];
|
|
182
|
+
readonly warnings: readonly string[];
|
|
183
|
+
readonly metadata?: Record<string, unknown>;
|
|
184
|
+
}
|
|
185
|
+
interface ExecutionPlanStub {
|
|
186
|
+
readonly id: string;
|
|
187
|
+
readonly kind: "plan-stub";
|
|
188
|
+
readonly createdAt: string;
|
|
189
|
+
readonly status: "stub";
|
|
190
|
+
readonly stages: readonly [];
|
|
191
|
+
readonly warnings: readonly string[];
|
|
192
|
+
}
|
|
193
|
+
type ResultPlan = ExecutionPlan | ExecutionPlanStub;
|
|
194
|
+
//#endregion
|
|
195
|
+
//#region src/sessions/session.d.ts
|
|
196
|
+
interface SessionRef {
|
|
197
|
+
readonly id: string;
|
|
198
|
+
readonly kind?: "session-ref";
|
|
199
|
+
}
|
|
200
|
+
interface SessionTurn {
|
|
201
|
+
readonly id: string;
|
|
202
|
+
readonly task: string;
|
|
203
|
+
readonly artifactRefs: readonly ArtifactRef[];
|
|
204
|
+
readonly planId?: string;
|
|
205
|
+
readonly outputArtifactRefs: readonly ArtifactRef[];
|
|
206
|
+
readonly createdAt: string;
|
|
207
|
+
}
|
|
208
|
+
interface SessionSummary {
|
|
209
|
+
readonly id: string;
|
|
210
|
+
readonly artifactRef: ArtifactRef;
|
|
211
|
+
readonly sourceTurnIds: readonly string[];
|
|
212
|
+
readonly trust: "model-summary";
|
|
213
|
+
readonly createdAt: string;
|
|
214
|
+
}
|
|
215
|
+
interface SessionRecord extends SessionRef {
|
|
216
|
+
readonly kind: "session-ref";
|
|
217
|
+
readonly parentId?: string;
|
|
218
|
+
readonly branchPointRunId?: string;
|
|
219
|
+
readonly turns: readonly SessionTurn[];
|
|
220
|
+
readonly summaries: readonly SessionSummary[];
|
|
221
|
+
readonly artifactRefs: readonly ArtifactRef[];
|
|
222
|
+
readonly planIds: readonly string[];
|
|
223
|
+
readonly createdAt: string;
|
|
224
|
+
readonly updatedAt: string;
|
|
225
|
+
}
|
|
226
|
+
interface CreateSessionOptions {
|
|
227
|
+
readonly id?: string;
|
|
228
|
+
readonly parentId?: string;
|
|
229
|
+
readonly branchPointRunId?: string;
|
|
230
|
+
}
|
|
231
|
+
interface AppendSessionTurnInput {
|
|
232
|
+
readonly sessionId: string;
|
|
233
|
+
readonly task: string;
|
|
234
|
+
readonly artifactRefs: readonly ArtifactRef[];
|
|
235
|
+
readonly outputArtifactRefs?: readonly ArtifactRef[];
|
|
236
|
+
readonly planId?: string;
|
|
237
|
+
}
|
|
238
|
+
interface SessionStore {
|
|
239
|
+
readonly kind: "session-store";
|
|
240
|
+
readonly id: string;
|
|
241
|
+
create(options?: CreateSessionOptions): Promise<SessionRecord>;
|
|
242
|
+
load(id: string): Promise<SessionRecord | undefined>;
|
|
243
|
+
save(session: SessionRecord): Promise<SessionRecord>;
|
|
244
|
+
branch(parentId: string, options?: Omit<CreateSessionOptions, "parentId">): Promise<SessionRecord>;
|
|
245
|
+
appendTurn(input: AppendSessionTurnInput): Promise<SessionRecord>;
|
|
246
|
+
}
|
|
247
|
+
interface MemorySessionStoreOptions {
|
|
248
|
+
readonly id?: string;
|
|
249
|
+
}
|
|
250
|
+
declare function createMemorySessionStore(options?: MemorySessionStoreOptions): SessionStore;
|
|
251
|
+
//#endregion
|
|
252
|
+
//#region src/context/context-pack.d.ts
|
|
253
|
+
type TrustLabel = "developer" | "user" | "tool" | "model-summary";
|
|
254
|
+
interface ContextPack extends ContextPackPlan {
|
|
255
|
+
readonly kind: "context-pack";
|
|
256
|
+
}
|
|
257
|
+
interface BuildContextPackInput {
|
|
258
|
+
readonly task: string;
|
|
259
|
+
readonly artifacts: readonly ArtifactInput[];
|
|
260
|
+
readonly route?: SelectedRoute;
|
|
261
|
+
readonly session?: SessionRecord;
|
|
262
|
+
readonly tokenBudget?: number;
|
|
263
|
+
}
|
|
264
|
+
interface ContextSummarizer {
|
|
265
|
+
summarize(input: {
|
|
266
|
+
readonly artifacts: readonly ArtifactRef[];
|
|
267
|
+
readonly budgetTokens: number;
|
|
268
|
+
}): Promise<readonly ArtifactRef[]> | readonly ArtifactRef[];
|
|
269
|
+
}
|
|
270
|
+
declare function buildContextPack(input: BuildContextPackInput): ContextPack;
|
|
271
|
+
declare function estimateArtifactTokens(artifact: ArtifactInput | ArtifactRef): number;
|
|
272
|
+
declare function estimateTokens(value: string): number;
|
|
273
|
+
declare function toContextArtifactRefs(artifacts: readonly ArtifactInput[]): readonly ArtifactRef[];
|
|
274
|
+
//#endregion
|
|
275
|
+
//#region src/contract/invariants.d.ts
|
|
276
|
+
/**
|
|
277
|
+
* Tripwire invariant declaration variants produced by the `inv` fluent
|
|
278
|
+
* builder. Each variant is a frozen value carrying a discriminant `kind`
|
|
279
|
+
* and an `id` (auto-generated or caller-supplied).
|
|
280
|
+
*
|
|
281
|
+
* Phase 8 reshapes the Phase 7 placeholder `{ kind: "policy"|"semantic"|"schema" }`
|
|
282
|
+
* into this discriminated union. Phase 7 never populated `invariants`
|
|
283
|
+
* (see 07-04-SUMMARY decisions), so the change is additive in practice
|
|
284
|
+
* but technically a breaking type change for any external caller that
|
|
285
|
+
* authored a literal of the old shape.
|
|
286
|
+
*/
|
|
287
|
+
interface MustCiteInvariant {
|
|
288
|
+
readonly id: string;
|
|
289
|
+
readonly kind: "must-cite";
|
|
290
|
+
readonly artifactName: string;
|
|
291
|
+
}
|
|
292
|
+
interface FieldFromTableInvariant {
|
|
293
|
+
readonly id: string;
|
|
294
|
+
readonly kind: "field-from-table";
|
|
295
|
+
readonly path: string;
|
|
296
|
+
readonly allowedValues: readonly string[];
|
|
297
|
+
}
|
|
298
|
+
interface NoPiiInvariant {
|
|
299
|
+
readonly id: string;
|
|
300
|
+
readonly kind: "no-pii";
|
|
301
|
+
readonly path: string;
|
|
302
|
+
}
|
|
303
|
+
interface MatchesInvariant<T = unknown> {
|
|
304
|
+
readonly id: string;
|
|
305
|
+
readonly kind: "matches";
|
|
306
|
+
readonly path: string;
|
|
307
|
+
readonly schema: StandardSchemaV1<unknown, T>;
|
|
308
|
+
}
|
|
309
|
+
type InvariantDeclaration = MustCiteInvariant | FieldFromTableInvariant | NoPiiInvariant | MatchesInvariant;
|
|
310
|
+
interface InvariantOptions {
|
|
311
|
+
readonly id?: string;
|
|
312
|
+
}
|
|
313
|
+
/**
|
|
314
|
+
* Fluent builder for tripwire invariants.
|
|
315
|
+
*
|
|
316
|
+
* Each helper returns a frozen `InvariantDeclaration` with an auto-generated
|
|
317
|
+
* id of the form `${kind}-${counter}`. Callers may override the id via the
|
|
318
|
+
* second-positional `options.id` arg.
|
|
319
|
+
*
|
|
320
|
+
* The counter is monotonic across kinds — calling `inv.mustCite("a")` then
|
|
321
|
+
* `inv.fieldFromTable("x", ["y"])` yields ids `must-cite-1` then
|
|
322
|
+
* `field-from-table-2`. This keeps ids globally unique within a process.
|
|
323
|
+
*
|
|
324
|
+
* Note on `inv.matches`: the caller supplies the StandardSchema validator,
|
|
325
|
+
* and the tripwire evaluator trusts whatever `~standard.validate` returns.
|
|
326
|
+
* This is by design — `matches` is the caller-driven escape hatch (see
|
|
327
|
+
* T-08-05 in the 08-01-PLAN threat register).
|
|
328
|
+
*/
|
|
329
|
+
declare const inv: {
|
|
330
|
+
readonly mustCite: (artifactName: string, options?: InvariantOptions) => MustCiteInvariant;
|
|
331
|
+
readonly fieldFromTable: (path: string, allowedValues: readonly string[], options?: InvariantOptions) => FieldFromTableInvariant;
|
|
332
|
+
readonly noPII: (path: string, options?: InvariantOptions) => NoPiiInvariant;
|
|
333
|
+
readonly matches: <T>(path: string, schema: StandardSchemaV1<unknown, T>, options?: InvariantOptions) => MatchesInvariant<T>;
|
|
334
|
+
/**
|
|
335
|
+
* Test-only: reset the auto-id counter. NOT exported from the package
|
|
336
|
+
* root barrel — callers must import `inv` directly from this module if
|
|
337
|
+
* they ever need it, which is intentional friction.
|
|
338
|
+
*/
|
|
339
|
+
readonly __resetCounterForTests: () => void;
|
|
340
|
+
};
|
|
341
|
+
//#endregion
|
|
342
|
+
//#region src/contract/pii-detectors.d.ts
|
|
343
|
+
/**
|
|
344
|
+
* Regex-based PII detectors used by the `no-pii` tripwire invariant.
|
|
345
|
+
*
|
|
346
|
+
* Phase 8 ships four detectors (email, US SSN, Luhn-valid credit card,
|
|
347
|
+
* US phone). They are intentionally regex-only — zero new dependencies —
|
|
348
|
+
* per the v1.1 scope locked in 08-CONTEXT.md.
|
|
349
|
+
*
|
|
350
|
+
* Each detector returns either `{ matched: true, substring }` carrying
|
|
351
|
+
* ONLY the matched fragment, or `{ matched: false }`. The substring shape
|
|
352
|
+
* is required so the tripwire evaluator can emit redacted evidence
|
|
353
|
+
* (Phase 9 receipts must not leak the full input).
|
|
354
|
+
*
|
|
355
|
+
* Detector order in `defaultPiiDetectors` is deterministic so the
|
|
356
|
+
* evaluator's first-violation semantics produce stable receipts.
|
|
357
|
+
*/
|
|
358
|
+
type PiiDetectorResult = {
|
|
359
|
+
readonly matched: true;
|
|
360
|
+
readonly substring: string;
|
|
361
|
+
} | {
|
|
362
|
+
readonly matched: false;
|
|
363
|
+
};
|
|
364
|
+
interface PiiDetector {
|
|
365
|
+
readonly name: string;
|
|
366
|
+
detect(input: string): PiiDetectorResult;
|
|
367
|
+
}
|
|
368
|
+
/**
|
|
369
|
+
* Default PII detectors used by `evaluateTripwires` for `no-pii` invariants.
|
|
370
|
+
*
|
|
371
|
+
* Order is deterministic: email, us-ssn, credit-card, us-phone. Callers who
|
|
372
|
+
* need a different set can pass their own list to `evaluateTripwires`.
|
|
373
|
+
*/
|
|
374
|
+
declare const defaultPiiDetectors: readonly PiiDetector[];
|
|
375
|
+
//#endregion
|
|
376
|
+
//#region src/contract/tripwire.d.ts
|
|
377
|
+
/**
|
|
378
|
+
* Evidence emitted when a tripwire invariant fires.
|
|
379
|
+
*
|
|
380
|
+
* `observed` is the SHAPE-MATCHED redacted payload, not the raw output:
|
|
381
|
+
* - for `must-cite`: the citations array as found at the located path
|
|
382
|
+
* - for `field-from-table`: the actual value at `path`
|
|
383
|
+
* - for `no-pii`: ONLY `{ detector, substring }` — never the full input
|
|
384
|
+
* (T-08-01 in the 08-01-PLAN threat register)
|
|
385
|
+
* - for `matches`: the value at `path`
|
|
386
|
+
*
|
|
387
|
+
* Phase 9 receipts will sign this evidence, so leaking the full PII into
|
|
388
|
+
* `observed` would defeat redact-before-sign.
|
|
389
|
+
*/
|
|
390
|
+
interface TripwireEvidence {
|
|
391
|
+
readonly invariantId: string;
|
|
392
|
+
readonly kind: "must-cite" | "field-from-table" | "no-pii" | "matches";
|
|
393
|
+
readonly path: string;
|
|
394
|
+
readonly observed: unknown;
|
|
395
|
+
readonly message: string;
|
|
396
|
+
}
|
|
397
|
+
type TripwireResult = {
|
|
398
|
+
readonly ok: true;
|
|
399
|
+
} | {
|
|
400
|
+
readonly ok: false;
|
|
401
|
+
readonly evidence: TripwireEvidence;
|
|
402
|
+
};
|
|
403
|
+
/**
|
|
404
|
+
* Pure tripwire evaluator.
|
|
405
|
+
*
|
|
406
|
+
* No I/O, no Date.now, no random — same `(output, invariants)` always
|
|
407
|
+
* returns the same `TripwireResult`. Phase 9 receipts can reconstruct the
|
|
408
|
+
* verdict deterministically (T-08-04).
|
|
409
|
+
*
|
|
410
|
+
* Evaluates invariants in declaration order; the FIRST failing invariant
|
|
411
|
+
* aborts and returns its evidence. Subsequent invariants are not evaluated.
|
|
412
|
+
*
|
|
413
|
+
* @param output The provider output to inspect.
|
|
414
|
+
* @param invariants Invariants to evaluate, in declaration order.
|
|
415
|
+
* @param detectors PII detectors used for `no-pii` invariants. Defaults
|
|
416
|
+
* to `defaultPiiDetectors`. Callers can pass a custom
|
|
417
|
+
* list to override.
|
|
418
|
+
*/
|
|
419
|
+
declare function evaluateTripwires(output: unknown, invariants: readonly InvariantDeclaration[], detectors?: readonly PiiDetector[]): Promise<TripwireResult>;
|
|
420
|
+
//#endregion
|
|
421
|
+
//#region src/results/errors.d.ts
|
|
422
|
+
interface ValidationIssue {
|
|
423
|
+
readonly message: string;
|
|
424
|
+
readonly path?: readonly (string | number | symbol)[];
|
|
425
|
+
}
|
|
426
|
+
interface ValidationError {
|
|
427
|
+
readonly kind: "validation";
|
|
428
|
+
readonly message: string;
|
|
429
|
+
readonly output?: string;
|
|
430
|
+
readonly issues: readonly ValidationIssue[];
|
|
431
|
+
}
|
|
432
|
+
interface ExecutionUnavailableError {
|
|
433
|
+
readonly kind: "execution_unavailable";
|
|
434
|
+
readonly message: string;
|
|
435
|
+
}
|
|
436
|
+
interface NoRouteError {
|
|
437
|
+
readonly kind: "no_route";
|
|
438
|
+
readonly message: string;
|
|
439
|
+
readonly reasons: readonly string[];
|
|
440
|
+
}
|
|
441
|
+
interface ProviderExecutionError {
|
|
442
|
+
readonly kind: "provider_execution";
|
|
443
|
+
readonly message: string;
|
|
444
|
+
readonly providerId?: string;
|
|
445
|
+
readonly modelId?: string;
|
|
446
|
+
}
|
|
447
|
+
interface TimeoutError {
|
|
448
|
+
readonly kind: "timeout";
|
|
449
|
+
readonly message: string;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Phase 7 addition: emitted by the runtime when no candidate route can
|
|
453
|
+
* satisfy the caller-supplied `CapabilityContract` (budget, modality,
|
|
454
|
+
* privacy, or quality-floor invariants).
|
|
455
|
+
*
|
|
456
|
+
* `noRouteReasons` carries the full deterministic-router rejection list
|
|
457
|
+
* so callers can inspect per-candidate detail. Phase 9 (receipts) will
|
|
458
|
+
* persist this array for deterministic verdict reconstruction.
|
|
459
|
+
*/
|
|
460
|
+
interface NoContractMatchError {
|
|
461
|
+
readonly kind: "no-contract-match";
|
|
462
|
+
readonly message: string;
|
|
463
|
+
readonly noRouteReasons: readonly RouteRejectReason[];
|
|
464
|
+
}
|
|
465
|
+
/**
|
|
466
|
+
* Phase 8 addition: emitted when a `CapabilityContract.invariants` tripwire
|
|
467
|
+
* fires after the provider returned a schema-valid output. Carries the
|
|
468
|
+
* `TripwireEvidence` produced by `evaluateTripwires`.
|
|
469
|
+
*
|
|
470
|
+
* `terminal: true` is a structural marker — combined with the `isTerminal()`
|
|
471
|
+
* predicate it tells the fallback chain in `runWithConfig` to refuse retry.
|
|
472
|
+
* `NoContractMatchError` does NOT carry the field (to avoid breaking Phase 7
|
|
473
|
+
* callers) but `isTerminal()` still returns true for it via the kind check.
|
|
474
|
+
*/
|
|
475
|
+
interface TripwireViolationError {
|
|
476
|
+
readonly kind: "tripwire-violated";
|
|
477
|
+
readonly message: string;
|
|
478
|
+
readonly invariantId: string;
|
|
479
|
+
readonly evidence: TripwireEvidence;
|
|
480
|
+
readonly terminal: true;
|
|
481
|
+
}
|
|
482
|
+
type LatticeRunError = ValidationError | ExecutionUnavailableError | NoRouteError | ProviderExecutionError | TimeoutError | NoContractMatchError | TripwireViolationError;
|
|
483
|
+
/**
|
|
484
|
+
* Returns `true` for run errors that MUST NOT be retried by the fallback
|
|
485
|
+
* chain. Phase 8 covers two kinds:
|
|
486
|
+
*
|
|
487
|
+
* - `tripwire-violated` — the contract's invariants rejected the output;
|
|
488
|
+
* a different provider will not change the verdict, so retry burns
|
|
489
|
+
* budget for no gain (T-08-06 in 08-02-PLAN threat register).
|
|
490
|
+
* - `no-contract-match` — no route satisfies the contract at all; the
|
|
491
|
+
* run never executed and no retry will help.
|
|
492
|
+
*
|
|
493
|
+
* All other error kinds return `false` and remain eligible for fallback.
|
|
494
|
+
* The predicate is exported so Phase 12's eval gate and any user-side
|
|
495
|
+
* retry wrappers can share one source of truth.
|
|
496
|
+
*/
|
|
497
|
+
declare function isTerminal(error: LatticeRunError): boolean;
|
|
498
|
+
//#endregion
|
|
499
|
+
//#region src/tools/tool-use.d.ts
|
|
500
|
+
interface ToolUseRequest {
|
|
501
|
+
readonly id: string;
|
|
502
|
+
readonly name: string;
|
|
503
|
+
readonly args: unknown;
|
|
504
|
+
}
|
|
505
|
+
declare function parseToolUseEnvelope(responseText: string): ReadonlyArray<ToolUseRequest> | null;
|
|
506
|
+
//#endregion
|
|
507
|
+
//#region src/tools/tools.d.ts
|
|
508
|
+
interface ToolExecutionContext {
|
|
509
|
+
readonly signal?: AbortSignal;
|
|
510
|
+
readonly emit?: RunEventSink;
|
|
511
|
+
}
|
|
512
|
+
interface ToolDefinition<TSchema extends StandardSchemaV1 = StandardSchemaV1> {
|
|
513
|
+
readonly kind: "tool";
|
|
514
|
+
readonly name: string;
|
|
515
|
+
readonly description?: string;
|
|
516
|
+
readonly inputSchema: TSchema;
|
|
517
|
+
readonly execute: (input: StandardSchemaV1.InferOutput<TSchema>, context: ToolExecutionContext) => Promise<unknown> | unknown;
|
|
518
|
+
}
|
|
519
|
+
interface ToolCallResult {
|
|
520
|
+
readonly callId: string;
|
|
521
|
+
readonly toolName: string;
|
|
522
|
+
readonly artifact: ArtifactInput;
|
|
523
|
+
}
|
|
524
|
+
declare function defineTool<TSchema extends StandardSchemaV1>(definition: Omit<ToolDefinition<TSchema>, "kind">): ToolDefinition<TSchema>;
|
|
525
|
+
declare function runTool<TSchema extends StandardSchemaV1>(tool: ToolDefinition<TSchema>, input: unknown, context?: ToolExecutionContext): Promise<ToolCallResult>;
|
|
526
|
+
interface McpLikeClient {
|
|
527
|
+
readonly listTools?: () => Promise<readonly McpToolDescriptor[]> | readonly McpToolDescriptor[];
|
|
528
|
+
readonly callTool: (input: {
|
|
529
|
+
readonly name: string;
|
|
530
|
+
readonly arguments: unknown;
|
|
531
|
+
}) => Promise<unknown> | unknown;
|
|
532
|
+
}
|
|
533
|
+
interface McpToolDescriptor {
|
|
534
|
+
readonly name: string;
|
|
535
|
+
readonly description?: string;
|
|
536
|
+
readonly inputSchema: StandardSchemaV1;
|
|
537
|
+
}
|
|
538
|
+
declare function importMcpTools(client: McpLikeClient, toolNames?: readonly string[]): Promise<readonly ToolDefinition[]>;
|
|
539
|
+
declare function toolArtifactRef(result: ToolCallResult): ArtifactRef;
|
|
540
|
+
//#endregion
|
|
541
|
+
//#region src/tools/tool-call-validation.d.ts
|
|
542
|
+
type ToolCallValidationFailureReason = "unknown_tool" | "invalid_args" | "extra_fields";
|
|
543
|
+
interface ValidatedToolCall {
|
|
544
|
+
readonly id: string;
|
|
545
|
+
readonly name: string;
|
|
546
|
+
readonly args: unknown;
|
|
547
|
+
}
|
|
548
|
+
type ToolCallValidationTool = Pick<ToolDefinition, "name" | "inputSchema">;
|
|
549
|
+
interface ValidateToolCallsOption {
|
|
550
|
+
readonly tools: readonly ToolCallValidationTool[];
|
|
551
|
+
readonly onFailure?: "throw" | "drop" | "callback";
|
|
552
|
+
readonly onValidationFailure?: (error: ToolCallValidationError) => void | Promise<void>;
|
|
553
|
+
readonly allowExtraFields?: boolean;
|
|
554
|
+
}
|
|
555
|
+
declare class ToolCallValidationError extends Error {
|
|
556
|
+
readonly kind: "tool-call-validation";
|
|
557
|
+
readonly reason: ToolCallValidationFailureReason;
|
|
558
|
+
readonly toolName: string;
|
|
559
|
+
readonly attemptedArgs: unknown;
|
|
560
|
+
readonly validationIssues: readonly ValidationIssue[];
|
|
561
|
+
readonly requestId: string;
|
|
562
|
+
constructor(input: {
|
|
563
|
+
readonly reason: ToolCallValidationFailureReason;
|
|
564
|
+
readonly toolName: string;
|
|
565
|
+
readonly attemptedArgs: unknown;
|
|
566
|
+
readonly validationIssues?: readonly ValidationIssue[];
|
|
567
|
+
readonly requestId: string;
|
|
568
|
+
});
|
|
569
|
+
}
|
|
570
|
+
declare function validateToolCallRequests(requests: readonly ToolUseRequest[], option: ValidateToolCallsOption | undefined): Promise<readonly ValidatedToolCall[] | undefined>;
|
|
571
|
+
//#endregion
|
|
572
|
+
//#region src/providers/quirks.d.ts
|
|
573
|
+
/**
|
|
574
|
+
* Universal 5-boolean shape every first-party adapter populates (SC-1 / D-03).
|
|
575
|
+
*
|
|
576
|
+
* - `supportsToolChoice` — adapter supports tool_choice / forced-tool-call mode
|
|
577
|
+
* - `parallelToolCalls` — adapter supports parallel (multi-tool) calls in one turn
|
|
578
|
+
* - `structuredOutputs` — adapter honors response_format JSON schema binding
|
|
579
|
+
* - `responseFormatHonored` — adapter treats response_format as authoritative (false
|
|
580
|
+
* for vanilla openai-compat servers; true for OpenAI/Anthropic/Gemini)
|
|
581
|
+
* - `streamingDiverges` — streamed output differs from buffered output (true for
|
|
582
|
+
* some self-hosted servers; false for OpenAI/Anthropic/Gemini)
|
|
583
|
+
*/
|
|
584
|
+
interface AdapterQuirks {
|
|
585
|
+
readonly supportsToolChoice: boolean;
|
|
586
|
+
readonly parallelToolCalls: boolean;
|
|
587
|
+
readonly structuredOutputs: boolean;
|
|
588
|
+
readonly responseFormatHonored: boolean;
|
|
589
|
+
readonly streamingDiverges: boolean;
|
|
590
|
+
}
|
|
591
|
+
/**
|
|
592
|
+
* Anthropic adapter quirks (extends AdapterQuirks with 3 Anthropic-specific flags).
|
|
593
|
+
*
|
|
594
|
+
* CITED: Anthropic prompt caching docs — https://docs.anthropic.com/en/docs/build-with-claude/prompt-caching
|
|
595
|
+
* - `promptCachingSupported`: cache_control on system and user turns is supported on
|
|
596
|
+
* all active Claude models (claude-3-* and claude-*-4 families).
|
|
597
|
+
*
|
|
598
|
+
* CITED: Anthropic extended thinking docs — https://docs.anthropic.com/en/docs/build-with-claude/extended-thinking
|
|
599
|
+
* - `extendedThinkingSupported`: thinking blocks (claude-3-7-sonnet+ and claude-*-4) available
|
|
600
|
+
* via the "thinking" request parameter.
|
|
601
|
+
*
|
|
602
|
+
* CITED: Anthropic tool use docs — https://docs.anthropic.com/en/docs/build-with-claude/tool-use
|
|
603
|
+
* - `toolUseInputSchemaStrict`: Anthropic tool_use blocks require strict JSON Schema in
|
|
604
|
+
* the input_schema field; the adapter enforces this at call time.
|
|
605
|
+
*/
|
|
606
|
+
interface AnthropicQuirks extends AdapterQuirks {
|
|
607
|
+
readonly promptCachingSupported: boolean;
|
|
608
|
+
readonly extendedThinkingSupported: boolean;
|
|
609
|
+
readonly toolUseInputSchemaStrict: boolean;
|
|
610
|
+
}
|
|
611
|
+
/**
|
|
612
|
+
* OpenAI adapter quirks (extends AdapterQuirks with 2 OpenAI-specific flags).
|
|
613
|
+
*
|
|
614
|
+
* CITED: OpenAI structured outputs docs — https://platform.openai.com/docs/guides/structured-outputs
|
|
615
|
+
* - `strictModeSupported`: function-calling strict:true mode available on
|
|
616
|
+
* gpt-4o-2024-08-06+ and o1+ series.
|
|
617
|
+
* - `structuredOutputsTier2`: json_schema response_format mode (tier-2 structured outputs)
|
|
618
|
+
* available on gpt-4o and gpt-4o-mini series.
|
|
619
|
+
*/
|
|
620
|
+
interface OpenAIQuirks extends AdapterQuirks {
|
|
621
|
+
readonly strictModeSupported: boolean;
|
|
622
|
+
readonly structuredOutputsTier2: boolean;
|
|
623
|
+
}
|
|
624
|
+
/**
|
|
625
|
+
* OpenAI-compatible adapter quirks (same 5 base booleans, no new fields).
|
|
626
|
+
*
|
|
627
|
+
* Conservative defaults: openai-compat servers (vLLM, TGI, Ollama, custom)
|
|
628
|
+
* vary widely in which response_format and tool_choice features they implement.
|
|
629
|
+
* The factory populates the base fields conservatively (responseFormatHonored:
|
|
630
|
+
* false, structuredOutputs: false) because the endpoint could be anything.
|
|
631
|
+
* Consumers pointing at a known-good server should verify quirk values manually.
|
|
632
|
+
*/
|
|
633
|
+
interface OpenAICompatQuirks extends AdapterQuirks {}
|
|
634
|
+
/**
|
|
635
|
+
* Gemini adapter quirks (extends AdapterQuirks with 3 Gemini-specific flags).
|
|
636
|
+
*
|
|
637
|
+
* CITED: Gemini API docs — https://ai.google.dev/api/generate-content#v1beta.GenerationConfig
|
|
638
|
+
* - `responseSchemaSupported`: responseSchema / responseJsonSchema on generateContent
|
|
639
|
+
* is available on gemini-1.5-pro+ and gemini-2.x models.
|
|
640
|
+
* - `safetySettingsConfigurable`: all 4 harm categories (HARASSMENT, HATE_SPEECH,
|
|
641
|
+
* SEXUALLY_EXPLICIT, DANGEROUS_CONTENT) can be set to BLOCK_NONE — verified in
|
|
642
|
+
* gemini.ts:50-55.
|
|
643
|
+
*
|
|
644
|
+
* CITED: Gemini API system instruction docs — https://ai.google.dev/api/generate-content#v1beta.GenerateContentRequest
|
|
645
|
+
* - `systemInstructionSupported`: systemInstruction field on GenerateContentRequest
|
|
646
|
+
* available on gemini-1.5+ series and later.
|
|
647
|
+
*/
|
|
648
|
+
interface GeminiQuirks extends AdapterQuirks {
|
|
649
|
+
readonly responseSchemaSupported: boolean;
|
|
650
|
+
readonly safetySettingsConfigurable: boolean;
|
|
651
|
+
readonly systemInstructionSupported: boolean;
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* xAI adapter quirks (extends AdapterQuirks with 2 xAI-specific flags).
|
|
655
|
+
*
|
|
656
|
+
* CITED: xAI API docs — https://docs.x.ai/api/endpoints
|
|
657
|
+
* - `reasoningTokensReported`: completion_tokens_details.reasoning_tokens reported
|
|
658
|
+
* in xAI API responses — verified in xai.ts:46-72.
|
|
659
|
+
* - `logprobsSupported`: grok-4.20 silently ignores logprobs param per observed
|
|
660
|
+
* behavior; flag indicates whether logprobs fields will be populated.
|
|
661
|
+
*/
|
|
662
|
+
interface XaiQuirks extends AdapterQuirks {
|
|
663
|
+
readonly reasoningTokensReported: boolean;
|
|
664
|
+
readonly logprobsSupported: boolean;
|
|
665
|
+
}
|
|
666
|
+
/**
|
|
667
|
+
* OpenRouter adapter quirks (extends AdapterQuirks with 3 OpenRouter-specific flags).
|
|
668
|
+
*
|
|
669
|
+
* CITED: OpenRouter provider routing docs — https://openrouter.ai/docs/provider-routing
|
|
670
|
+
* - `providerRoutingArraySupported`: the `provider.order` / `provider.only` /
|
|
671
|
+
* `provider.ignore` arrays are supported for explicit routing control.
|
|
672
|
+
* - `floorPricingHints`: `max_price`, `sort: "throughput" | "price"` hints on
|
|
673
|
+
* GenerationConfig for cost-aware routing.
|
|
674
|
+
* - `allowFallbacks`: `provider.allow_fallbacks: boolean` controls whether OpenRouter
|
|
675
|
+
* retries with a different upstream provider on failure.
|
|
676
|
+
*/
|
|
677
|
+
interface OpenRouterQuirks extends AdapterQuirks {
|
|
678
|
+
readonly providerRoutingArraySupported: boolean;
|
|
679
|
+
readonly floorPricingHints: boolean;
|
|
680
|
+
readonly allowFallbacks: boolean;
|
|
681
|
+
}
|
|
682
|
+
/**
|
|
683
|
+
* LM Studio adapter quirks (extends AdapterQuirks with 2 LM Studio-specific flags).
|
|
684
|
+
*
|
|
685
|
+
* CITED: lmstudio-bug-tracker — Jinja template mismatches between model training and
|
|
686
|
+
* LM Studio server defaults cause output format corruption.
|
|
687
|
+
* - `customChatTemplateRiskFlag`: LM Studio servers can ship with broken chat templates
|
|
688
|
+
* that don't match the model's training template; flag signals this risk.
|
|
689
|
+
*
|
|
690
|
+
* VERIFIED: lm-studio.ts:35-37 — apiKey is optional for LM Studio local servers.
|
|
691
|
+
* - `noAuthRequired`: apiKey is NOT required for local LM Studio instances (no
|
|
692
|
+
* authentication by default on localhost:1234).
|
|
693
|
+
*/
|
|
694
|
+
interface LmStudioQuirks extends AdapterQuirks {
|
|
695
|
+
readonly customChatTemplateRiskFlag: boolean;
|
|
696
|
+
readonly noAuthRequired: boolean;
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* LiteLLM adapter quirks (extends AdapterQuirks with gateway-specific flags).
|
|
700
|
+
*
|
|
701
|
+
* LiteLLM is consumed as an OpenAI-compatible gateway. Lattice does not start,
|
|
702
|
+
* embed, or depend on a LiteLLM gateway process; these flags describe the
|
|
703
|
+
* helper's supported gateway metadata contract over HTTP.
|
|
704
|
+
*/
|
|
705
|
+
interface LiteLLMQuirks extends AdapterQuirks {
|
|
706
|
+
readonly gatewayMetadataSupported: boolean;
|
|
707
|
+
readonly gatewayFallbacksSupported: boolean;
|
|
708
|
+
readonly openAIErrorMapping: boolean;
|
|
709
|
+
}
|
|
710
|
+
//#endregion
|
|
711
|
+
//#region src/capabilities/profile.d.ts
|
|
712
|
+
/**
|
|
713
|
+
* Closed enum of the 8 Lattice transport adapters (D-06). Adding a new
|
|
714
|
+
* adapter is a typed breaking change. Phase 34 quirk dispatch reads this
|
|
715
|
+
* field.
|
|
716
|
+
*/
|
|
717
|
+
type CapabilityAdapter = "openrouter" | "anthropic" | "openai" | "openai-compat" | "xai" | "gemini" | "lm-studio" | "litellm";
|
|
718
|
+
/**
|
|
719
|
+
* Closed enum of the 5 training-lineage buckets (D-14). Receipt v1.2
|
|
720
|
+
* (Phase 38) carries this value verbatim via the `modelClass` field.
|
|
721
|
+
* Stable across model patches — gpt-4o-2024-05-13 and gpt-4o-2024-08-06
|
|
722
|
+
* share a trainingClass so receipts remain comparable across rebuilds.
|
|
723
|
+
*/
|
|
724
|
+
type TrainingClass = "frontier_rlhf" | "mid_tier_rlhf" | "open_weight_instruct" | "open_weight_base" | "local_quantized";
|
|
725
|
+
/**
|
|
726
|
+
* Closed enum of the 5 recommended prompt-tuning buckets (research open
|
|
727
|
+
* question 2). DISTINCT from `TrainingClass`: `reasoning` is orthogonal
|
|
728
|
+
* to lineage (a frontier RLHF model with hidden_cot routes to the
|
|
729
|
+
* `reasoning` strategy bucket); `local` is the granularity boundary
|
|
730
|
+
* for the deployed-locally strategy bucket (vs the `local_quantized`
|
|
731
|
+
* lineage signal). Phase 35 prompt-scaffold dispatch reads this field.
|
|
732
|
+
*/
|
|
733
|
+
type RecommendedPromptStrategy = "frontier" | "mid_tier" | "open_weight" | "reasoning" | "local";
|
|
734
|
+
/**
|
|
735
|
+
* Closed enum of the 7 known model-class output-shape failure modes at
|
|
736
|
+
* v1.3.0 (D-12). Adding a member in v1.4+ is an intentional typed
|
|
737
|
+
* breaking change — Phase 36 sanitizer dispatch enforces exhaustiveness
|
|
738
|
+
* via a `_exhaustive: never` switch (see test-d/capabilities.test-d.ts).
|
|
739
|
+
*/
|
|
740
|
+
type KnownFailureMode = "internal_envelope_leak" | "reasoning_tag_leak" | "system_prompt_echo" | "template_artifact_leak" | "hallucinated_tool_name" | "malformed_tool_arguments" | "premature_termination";
|
|
741
|
+
/**
|
|
742
|
+
* Closed enum of the 5 reasoning-surface shapes a model exposes. Drives
|
|
743
|
+
* the Phase 36 sanitizer's choice of leak-cleanup pass (e.g., `<think>`
|
|
744
|
+
* tag stripping for `inlined_tags`).
|
|
745
|
+
*/
|
|
746
|
+
type ReasoningSurface = "none" | "hidden_cot" | "inlined_tags" | "interleaved_thinking" | "streamed_reasoning";
|
|
747
|
+
/**
|
|
748
|
+
* Closed enum of the 5 tool-call surface shapes a model exposes. Drives
|
|
749
|
+
* the Phase 37 tool-call validator's choice of arguments parser.
|
|
750
|
+
*/
|
|
751
|
+
type ToolCallSurface = "none" | "native_strict" | "native_lenient" | "json_only" | "text_only";
|
|
752
|
+
type ModelCapabilityProfilePricingKey = "prompt" | "completion" | "image" | "audio" | "web_search" | "internal_reasoning" | "input_cache_read" | "input_cache_write";
|
|
753
|
+
type ModelCapabilityProfilePricing = Partial<Record<ModelCapabilityProfilePricingKey, string>>;
|
|
754
|
+
type ModelCapabilityProfileModality = "text" | "image" | "audio" | "video" | "file" | "embeddings";
|
|
755
|
+
/**
|
|
756
|
+
* Phase 33 — D-05 / D-08 — Capability profile for one (adapter, model)
|
|
757
|
+
* pair. Sibling to `ModelCapability`, not a replacement. Built-time baked
|
|
758
|
+
* via the OpenRouter snapshot generator (Phase 33-03) plus hand-edited
|
|
759
|
+
* supplemental static profiles (Phase 33-04).
|
|
760
|
+
*
|
|
761
|
+
* Canonical key: `${adapter}:${modelId}` — one profile per (adapter,
|
|
762
|
+
* model) pair. `openrouter:openai/gpt-oss-120b` and `openai:gpt-oss-120b`
|
|
763
|
+
* are two distinct entries with the same `originFamily: "openai"`.
|
|
764
|
+
*/
|
|
765
|
+
interface ModelCapabilityProfile {
|
|
766
|
+
/**
|
|
767
|
+
* The model identifier as the adapter sees it. For OpenRouter this is
|
|
768
|
+
* the `vendor/model` shape (e.g., `openai/gpt-oss-120b`); for direct
|
|
769
|
+
* adapters this is the provider's native id (e.g., `claude-opus-4`).
|
|
770
|
+
* Combined with `adapter` to form the canonical lookup key `${adapter}:${id}` (D-08).
|
|
771
|
+
*/
|
|
772
|
+
readonly id: string;
|
|
773
|
+
/**
|
|
774
|
+
* The Lattice transport adapter that ships this profile (D-05 /
|
|
775
|
+
* D-06). Phase 34 adapter-quirk dispatch reads this field. Closed
|
|
776
|
+
* union of 8 values.
|
|
777
|
+
*/
|
|
778
|
+
readonly adapter: CapabilityAdapter;
|
|
779
|
+
/**
|
|
780
|
+
* The model creator (D-07). Open extensible string — new orgs emerge
|
|
781
|
+
* frequently and should not break the type. Examples: `openai`,
|
|
782
|
+
* `anthropic`, `meta`, `mistral`, `google`, `xai`, `deepseek`, `qwen`.
|
|
783
|
+
* Phase 35 prompt-scaffold dispatch falls back to
|
|
784
|
+
* `recommendedPromptStrategy` for unknown originFamily values.
|
|
785
|
+
*/
|
|
786
|
+
readonly originFamily: string;
|
|
787
|
+
/**
|
|
788
|
+
* Training-lineage classification (D-14). Receipt v1.2 `modelClass`
|
|
789
|
+
* (Phase 38) carries this value verbatim. Drives the failure-mode
|
|
790
|
+
* default set in the classifier.
|
|
791
|
+
*/
|
|
792
|
+
readonly trainingClass: TrainingClass;
|
|
793
|
+
/**
|
|
794
|
+
* Shape of the model's reasoning output. Drives the Phase 36
|
|
795
|
+
* sanitizer's reasoning-leak cleanup pass.
|
|
796
|
+
*/
|
|
797
|
+
readonly reasoningSurface: ReasoningSurface;
|
|
798
|
+
/**
|
|
799
|
+
* Shape of the model's tool-call output. Drives the Phase 37
|
|
800
|
+
* tool-call validator's arguments parser.
|
|
801
|
+
*/
|
|
802
|
+
readonly toolCallSurface: ToolCallSurface;
|
|
803
|
+
/**
|
|
804
|
+
* The actual context window the adapter will accept on a request, in
|
|
805
|
+
* tokens. For OpenRouter this is `top_provider.context_length ?? context_length`
|
|
806
|
+
* (Phase 33 Pitfall 2) — what OpenRouter routing actually offers, not
|
|
807
|
+
* the model card's aspirational maximum.
|
|
808
|
+
*/
|
|
809
|
+
readonly contextWindow: number;
|
|
810
|
+
readonly pricing?: ModelCapabilityProfilePricing;
|
|
811
|
+
readonly inputModalities?: readonly ModelCapabilityProfileModality[];
|
|
812
|
+
readonly outputModalities?: readonly ModelCapabilityProfileModality[];
|
|
813
|
+
readonly supportedParameters?: readonly string[];
|
|
814
|
+
/**
|
|
815
|
+
* Failure modes this model class is known to exhibit (D-14). Class-
|
|
816
|
+
* derived defaults plus per-family overrides. Phase 36 sanitizer
|
|
817
|
+
* dispatch exhaustively switches on each entry.
|
|
818
|
+
*/
|
|
819
|
+
readonly knownFailureModes: readonly KnownFailureMode[];
|
|
820
|
+
/**
|
|
821
|
+
* Recommended prompt-tuning bucket (research open question 2). Phase
|
|
822
|
+
* 35 prompt-scaffold dispatch reads this field. Distinct from
|
|
823
|
+
* `trainingClass` — see `RecommendedPromptStrategy` JSDoc.
|
|
824
|
+
*/
|
|
825
|
+
readonly recommendedPromptStrategy: RecommendedPromptStrategy;
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* Frozen list of every `KnownFailureMode` member. Useful for exhaustive
|
|
829
|
+
* iteration in downstream tests and Phase 36 sanitizer registration.
|
|
830
|
+
* Adding a new mode requires updating this array AND the
|
|
831
|
+
* `KnownFailureMode` union AND the Phase 36 exhaustive switch — the
|
|
832
|
+
* `satisfies` clause enforces array-vs-union parity at compile time.
|
|
833
|
+
*/
|
|
834
|
+
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"];
|
|
835
|
+
/**
|
|
836
|
+
* Frozen list of every `TrainingClass` member. Useful for exhaustive
|
|
837
|
+
* iteration when constructing the failure-mode defaults table (D-14)
|
|
838
|
+
* and for Phase 38 receipt-class enumeration.
|
|
839
|
+
*/
|
|
840
|
+
declare const ALL_TRAINING_CLASSES: readonly ["frontier_rlhf", "mid_tier_rlhf", "open_weight_instruct", "open_weight_base", "local_quantized"];
|
|
841
|
+
//#endregion
|
|
842
|
+
//#region src/capabilities/sanitizer-recommendations.d.ts
|
|
843
|
+
/**
|
|
844
|
+
* D-13 — Phase 36 sanitizer registration keys. Closed string-literal union;
|
|
845
|
+
* adding a 4th sanitizer in v1.4 is an intentional typed breaking change
|
|
846
|
+
* that mirrors the `KnownFailureMode` discipline.
|
|
847
|
+
*
|
|
848
|
+
* Phase 36 registers implementations under EXACTLY these 3 ids:
|
|
849
|
+
* - "stripReasoningTags" — strips <think>/</think> (and model-specific) reasoning tags
|
|
850
|
+
* - "stripChatTemplateArtifacts" — removes chat-template artifact leaks from output
|
|
851
|
+
* - "unwrapInternalEnvelope" — extracts the user-visible payload from internal wrapper
|
|
852
|
+
*/
|
|
853
|
+
type SanitizerKey = "stripReasoningTags" | "stripChatTemplateArtifacts" | "unwrapInternalEnvelope";
|
|
854
|
+
/**
|
|
855
|
+
* D-14 + D-16 — Exhaustive mapping from KnownFailureMode to SanitizerKey
|
|
856
|
+
* (or null when the failure mode is not a sanitizer concern). The
|
|
857
|
+
* `Record<KnownFailureMode, ...>` annotation enforces compile-time
|
|
858
|
+
* exhaustiveness — adding a new mode to KnownFailureMode in v1.4+ will
|
|
859
|
+
* cause a type-check failure here until the planner decides on a mapping.
|
|
860
|
+
*
|
|
861
|
+
* Null semantics per D-16:
|
|
862
|
+
* - system_prompt_echo -> null (consumer-side prompt engineering, not a sanitizer)
|
|
863
|
+
* - hallucinated_tool_name -> null (Phase 37 tool-call validator territory)
|
|
864
|
+
* - malformed_tool_arguments -> null (Phase 37 tool-call validator territory)
|
|
865
|
+
* - premature_termination -> null (consumer-side max_tokens config)
|
|
866
|
+
*/
|
|
867
|
+
declare const SANITIZER_BY_FAILURE_MODE: Record<KnownFailureMode, SanitizerKey | null>;
|
|
868
|
+
/**
|
|
869
|
+
* D-14 / D-15 — Maps a list of known failure modes through the recommendation
|
|
870
|
+
* table and filters nulls. `recommendedSanitizers` always contains real keys.
|
|
871
|
+
*
|
|
872
|
+
* Implementation:
|
|
873
|
+
* - Iterates modes in input order (Set insertion order)
|
|
874
|
+
* - Skips null entries (D-16)
|
|
875
|
+
* - Deduplicates via Set (so repeated modes yield one key)
|
|
876
|
+
* - Returns a readonly array (frozen via spread)
|
|
877
|
+
*
|
|
878
|
+
* Consumers use this to populate `NegotiatedCapabilities.recommendedSanitizers`.
|
|
879
|
+
* Phase 36 registers implementations under the same key ids.
|
|
880
|
+
*/
|
|
881
|
+
declare function getRecommendedSanitizers(modes: readonly KnownFailureMode[]): readonly SanitizerKey[];
|
|
882
|
+
//#endregion
|
|
883
|
+
//#region src/capabilities/negotiate.d.ts
|
|
884
|
+
/**
|
|
885
|
+
* Phase 34 — SC-3 — Consumer-facing capability shape returned by
|
|
886
|
+
* `adapter.negotiateCapabilities()` and the top-level `negotiateCapabilities()`
|
|
887
|
+
* helper. Simplified relative to `ModelCapabilityProfile` (the registry
|
|
888
|
+
* profile); consumers needing the full enum (e.g., native_strict vs
|
|
889
|
+
* native_lenient) should look up the profile directly via `getCapabilityProfile`.
|
|
890
|
+
*
|
|
891
|
+
* Source values (D-09):
|
|
892
|
+
* - "live" — /models endpoint hit, registry profile intersected
|
|
893
|
+
* - "registry-fallback" — /models hit failed transiently (5xx/network/timeout),
|
|
894
|
+
* fell back to Phase 33 static registry (D-09)
|
|
895
|
+
* - "registry" — adapter intentionally has no /models endpoint
|
|
896
|
+
* (LM Studio, openai-compat), OR consumer-adapter
|
|
897
|
+
* fallback path (D-04)
|
|
898
|
+
*/
|
|
899
|
+
interface NegotiatedCapabilities {
|
|
900
|
+
readonly modelId: string;
|
|
901
|
+
readonly contextWindow: number;
|
|
902
|
+
readonly supports: {
|
|
903
|
+
readonly nativeToolCalling: boolean;
|
|
904
|
+
readonly structuredOutputs: boolean;
|
|
905
|
+
readonly parallelToolCalls: boolean;
|
|
906
|
+
readonly extendedThinking: boolean;
|
|
907
|
+
readonly streaming: boolean;
|
|
908
|
+
};
|
|
909
|
+
readonly knownFailureModes: readonly KnownFailureMode[];
|
|
910
|
+
readonly recommendedSanitizers: readonly SanitizerKey[];
|
|
911
|
+
readonly source: "live" | "registry-fallback" | "registry";
|
|
912
|
+
}
|
|
913
|
+
/**
|
|
914
|
+
* D-10 — Typed error thrown by `negotiateCapabilities` when the adapter's
|
|
915
|
+
* /models endpoint returns 401 or 403. Mirrors `AgentDeniedError` shape
|
|
916
|
+
* (the only existing v1.2 `class extends Error` precedent in agent/types.ts).
|
|
917
|
+
*
|
|
918
|
+
* Why throw (vs return-as-error-union):
|
|
919
|
+
* - Auth errors indicate a broken apiKey config — it is the caller's bug
|
|
920
|
+
* - Silently falling back would hide the misconfiguration
|
|
921
|
+
* - `try/catch` ergonomics work cleanly with `class extends Error`
|
|
922
|
+
* - `instanceof NegotiationAuthError` is the consumer ergonomic
|
|
923
|
+
*
|
|
924
|
+
* IMPORTANT: `NegotiationAuthError` is throwable from `negotiateCapabilities`
|
|
925
|
+
* ONLY — never from `execute()`. Auth errors from /models do NOT contaminate
|
|
926
|
+
* the request path.
|
|
927
|
+
*
|
|
928
|
+
* T-34-01-02: message field set by adapter implementations in Plans 02-04
|
|
929
|
+
* MUST NOT include the apiKey. Only adapter, modelId, and httpStatus are carried.
|
|
930
|
+
*/
|
|
931
|
+
declare class NegotiationAuthError extends Error {
|
|
932
|
+
readonly kind: "negotiation-auth-failed";
|
|
933
|
+
readonly adapter: CapabilityAdapter;
|
|
934
|
+
readonly modelId: string;
|
|
935
|
+
readonly httpStatus: 401 | 403;
|
|
936
|
+
constructor(adapter: CapabilityAdapter, modelId: string, httpStatus: 401 | 403, message: string);
|
|
937
|
+
}
|
|
938
|
+
/**
|
|
939
|
+
* Phase 34 — D-02 / D-04 — Top-level helper for capability negotiation.
|
|
940
|
+
*
|
|
941
|
+
* Pitfall 5 (zero live-path logic): delegates verbatim to
|
|
942
|
+
* `adapter.negotiateCapabilities(modelId)` when the adapter implements it.
|
|
943
|
+
* No inflight-coalescing, no cache, no source value transformation. The
|
|
944
|
+
* adapter owns all of that.
|
|
945
|
+
*
|
|
946
|
+
* When the adapter has NO `negotiateCapabilities` (consumer-provided v1.2
|
|
947
|
+
* adapters, third-party adapters), falls back to the Phase 33 registry
|
|
948
|
+
* via `synthesizeNegotiatedCapabilitiesFromRegistry` with source "registry"
|
|
949
|
+
* (D-04). Consumer adapters get useful behavior out of the box without any
|
|
950
|
+
* migration code.
|
|
951
|
+
*
|
|
952
|
+
* Verifiable per Pitfall 5: grep for `new Map<` in this function body should
|
|
953
|
+
* return zero matches; LOC count of the function body is < 10 lines.
|
|
954
|
+
*/
|
|
955
|
+
declare function negotiateCapabilities(adapter: ProviderAdapter, modelId: string): Promise<NegotiatedCapabilities>;
|
|
956
|
+
/**
|
|
957
|
+
* Phase 34 — D-04 / D-09 — Synthesizes a `NegotiatedCapabilities` shape from
|
|
958
|
+
* the Phase 33 static registry. Used by:
|
|
959
|
+
* 1. The top-level helper (above) for consumer-adapter fallback (D-04).
|
|
960
|
+
* 2. Per-adapter negotiate() implementations (Plans 02-05) when /models
|
|
961
|
+
* fails transiently (D-09, source "registry-fallback").
|
|
962
|
+
*
|
|
963
|
+
* Exported as a named export so Plans 02-05 can reuse the fallback synthesis
|
|
964
|
+
* without duplicating the mapping logic.
|
|
965
|
+
*
|
|
966
|
+
* Implementation note: the boolean derivations are intentionally minimal
|
|
967
|
+
* (heuristic, not definitive). The per-adapter negotiate() implementations
|
|
968
|
+
* in Plans 02-05 own the richer derivation from live /models data.
|
|
969
|
+
* This helper is a SAFETY NET for adapters without /models endpoints and
|
|
970
|
+
* for transient-fallback cases.
|
|
971
|
+
*
|
|
972
|
+
* Anti-shape (documented in CONTEXT.md <specifics>): boolean `nativeToolCalling`
|
|
973
|
+
* loses the strict-vs-lenient distinction in `toolCallSurface`. Consumers
|
|
974
|
+
* needing the enum should look up the profile directly via `getCapabilityProfile`.
|
|
975
|
+
*/
|
|
976
|
+
declare function synthesizeNegotiatedCapabilitiesFromRegistry(adapter: CapabilityAdapter, modelId: string, source: "registry" | "registry-fallback"): NegotiatedCapabilities;
|
|
977
|
+
//#endregion
|
|
978
|
+
//#region src/providers/provider.d.ts
|
|
979
|
+
type CapabilityModality = "text" | "json" | "image" | "audio" | "video" | "document" | "file" | "url" | "tool";
|
|
980
|
+
type ProviderTransportMode = "inline" | "json" | "url" | "base64" | "provider-upload" | "file-id" | "extracted-text" | "transcript";
|
|
981
|
+
type ProviderLatencyClass = "interactive" | "batch";
|
|
982
|
+
interface ProviderPricingHint {
|
|
983
|
+
/** @deprecated prefer `inputPer1kTokens` — kept for backward compatibility */
|
|
984
|
+
readonly inputCostPer1M?: number;
|
|
985
|
+
/** @deprecated prefer `outputPer1kTokens` — kept for backward compatibility */
|
|
986
|
+
readonly outputCostPer1M?: number;
|
|
987
|
+
/** Per-1000-prompt-token cost in USD. Preferred field for Phase 7+ pricing. */
|
|
988
|
+
readonly inputPer1kTokens?: number;
|
|
989
|
+
/** Per-1000-completion-token cost in USD. Preferred field for Phase 7+ pricing. */
|
|
990
|
+
readonly outputPer1kTokens?: number;
|
|
991
|
+
}
|
|
992
|
+
/**
|
|
993
|
+
* Normalized per-run usage at the result layer.
|
|
994
|
+
*
|
|
995
|
+
* `costUsd` is `number | null` (not optional, not `0`) so downstream
|
|
996
|
+
* consumers can distinguish "free" (`0`) from "unmeasured" (`null`) when
|
|
997
|
+
* provider pricing is unknown — see 07-CONTEXT.md "Cost Normalization & Usage".
|
|
998
|
+
*
|
|
999
|
+
* Distinct from `UsageRecord` on `ProviderAttemptRecord`: `UsageRecord`
|
|
1000
|
+
* is the per-attempt record, `Usage` is the per-run normalized shape
|
|
1001
|
+
* surfaced on `RunSuccess` / `RunFailure`.
|
|
1002
|
+
*/
|
|
1003
|
+
interface Usage {
|
|
1004
|
+
readonly promptTokens: number;
|
|
1005
|
+
readonly completionTokens: number;
|
|
1006
|
+
readonly costUsd: number | null;
|
|
1007
|
+
}
|
|
1008
|
+
interface ProviderDataPolicyHints {
|
|
1009
|
+
readonly privacy: readonly ("standard" | "sensitive" | "restricted")[];
|
|
1010
|
+
readonly uploadRetention?: "none" | "ephemeral" | "provider-default";
|
|
1011
|
+
readonly supportsNoLogging?: boolean;
|
|
1012
|
+
readonly supportsNoTraining?: boolean;
|
|
1013
|
+
}
|
|
1014
|
+
interface ModelCapability {
|
|
1015
|
+
readonly providerId: string;
|
|
1016
|
+
readonly modelId: string;
|
|
1017
|
+
readonly inputModalities: readonly CapabilityModality[];
|
|
1018
|
+
readonly outputModalities: readonly CapabilityModality[];
|
|
1019
|
+
readonly fileTransport: readonly ProviderTransportMode[];
|
|
1020
|
+
readonly contextWindow: number;
|
|
1021
|
+
readonly structuredOutput: boolean;
|
|
1022
|
+
readonly toolUse: boolean;
|
|
1023
|
+
readonly streaming: boolean;
|
|
1024
|
+
readonly pricing?: ProviderPricingHint;
|
|
1025
|
+
readonly latency: ProviderLatencyClass;
|
|
1026
|
+
readonly dataPolicy: ProviderDataPolicyHints;
|
|
1027
|
+
readonly available?: boolean;
|
|
1028
|
+
}
|
|
1029
|
+
interface ProviderRef {
|
|
1030
|
+
readonly id: string;
|
|
1031
|
+
readonly kind?: "provider-ref";
|
|
1032
|
+
}
|
|
1033
|
+
type ProviderToolDefinition = Pick<ToolDefinition<StandardSchemaV1>, "name" | "description" | "inputSchema">;
|
|
1034
|
+
type ProviderToolChoice = "auto" | "none" | "required" | {
|
|
1035
|
+
readonly type: "tool";
|
|
1036
|
+
readonly name: string;
|
|
1037
|
+
};
|
|
1038
|
+
interface ProviderStructuredOutputRequest {
|
|
1039
|
+
readonly output: string;
|
|
1040
|
+
readonly schema: StandardSchemaV1;
|
|
1041
|
+
readonly name?: string;
|
|
1042
|
+
readonly strict?: boolean;
|
|
1043
|
+
}
|
|
1044
|
+
interface ProviderRunRequest {
|
|
1045
|
+
readonly task: string;
|
|
1046
|
+
readonly artifacts: readonly ArtifactInput[];
|
|
1047
|
+
readonly outputs: readonly string[];
|
|
1048
|
+
readonly outputContracts?: OutputContractMap;
|
|
1049
|
+
readonly policy?: unknown;
|
|
1050
|
+
readonly signal?: AbortSignal;
|
|
1051
|
+
readonly plan?: ExecutionPlan;
|
|
1052
|
+
readonly contextPack?: ContextPack;
|
|
1053
|
+
readonly providerPackaging?: ProviderPackagingPlan;
|
|
1054
|
+
readonly packagedArtifacts?: readonly ArtifactRef[];
|
|
1055
|
+
/**
|
|
1056
|
+
* Phase 39 — opt-in prompt-cache prefix (DELEG-04). Adapters that support
|
|
1057
|
+
* block-granular caching (Anthropic) hoist this to a `cache_control`-marked
|
|
1058
|
+
* system content block; adapters that ignore it MUST receive the prefix
|
|
1059
|
+
* folded into `task` by the caller instead (the crew dispatcher gates on
|
|
1060
|
+
* `quirks.promptCachingSupported`). The field is advisory, additive, and
|
|
1061
|
+
* absent for all existing callers — follows the Phase 37 `toolCalls`
|
|
1062
|
+
* additive-field precedent (request/response additive fields accepted;
|
|
1063
|
+
* `ProviderAdapter` METHODS frozen per INV-03).
|
|
1064
|
+
*/
|
|
1065
|
+
readonly cacheSystemPrefix?: string;
|
|
1066
|
+
/**
|
|
1067
|
+
* Phase 51 — Provider-only native tool declarations. This is an explicit
|
|
1068
|
+
* opt-in so existing `ai.run()` and agent prompt-reencoded behavior does not
|
|
1069
|
+
* change merely because output contracts or tools exist elsewhere.
|
|
1070
|
+
*/
|
|
1071
|
+
readonly nativeTools?: readonly ProviderToolDefinition[];
|
|
1072
|
+
readonly nativeToolChoice?: ProviderToolChoice;
|
|
1073
|
+
readonly nativeStructuredOutput?: ProviderStructuredOutputRequest;
|
|
1074
|
+
}
|
|
1075
|
+
interface ProviderGatewayMetadata {
|
|
1076
|
+
readonly used: boolean;
|
|
1077
|
+
readonly requestedModel?: string;
|
|
1078
|
+
readonly observedModel?: string;
|
|
1079
|
+
readonly fallbackModels?: readonly string[];
|
|
1080
|
+
readonly policy?: Record<string, unknown>;
|
|
1081
|
+
}
|
|
1082
|
+
interface ProviderFinishMetadata {
|
|
1083
|
+
readonly reason?: string;
|
|
1084
|
+
readonly toolCallIds?: readonly string[];
|
|
1085
|
+
readonly metadata?: Record<string, unknown>;
|
|
1086
|
+
}
|
|
1087
|
+
interface ProviderRunResponse {
|
|
1088
|
+
readonly rawOutputs: Record<string, unknown>;
|
|
1089
|
+
readonly artifactRefs?: readonly (ArtifactInput | ArtifactRef)[];
|
|
1090
|
+
/**
|
|
1091
|
+
* @deprecated Legacy per-attempt usage shape. Phase 7+ adapters should
|
|
1092
|
+
* populate `normalizedUsage` instead — Plan 04 will prefer `normalizedUsage`
|
|
1093
|
+
* when wiring `RunResult.usage`. Kept here for backward compatibility with
|
|
1094
|
+
* v1.0 adapters that already report this field.
|
|
1095
|
+
*/
|
|
1096
|
+
readonly usage?: UsageRecord;
|
|
1097
|
+
/**
|
|
1098
|
+
* Phase 7 normalized usage shape for `RunResult.usage`. Populated by all
|
|
1099
|
+
* Phase 7+ adapters (openai, openai-compat, ai-sdk, fake). `costUsd` is
|
|
1100
|
+
* `null` when pricing is unknown (per the cost-normalization decision in
|
|
1101
|
+
* 07-CONTEXT.md — distinguishes "free" from "unmeasured").
|
|
1102
|
+
*/
|
|
1103
|
+
readonly normalizedUsage?: Usage;
|
|
1104
|
+
readonly toolCalls?: readonly ValidatedToolCall[];
|
|
1105
|
+
readonly gateway?: ProviderGatewayMetadata;
|
|
1106
|
+
readonly finish?: ProviderFinishMetadata;
|
|
1107
|
+
readonly rawResponse?: unknown;
|
|
1108
|
+
}
|
|
1109
|
+
interface ProviderStreamTextDeltaChunk {
|
|
1110
|
+
readonly kind: "text-delta";
|
|
1111
|
+
readonly output?: string;
|
|
1112
|
+
readonly text: string;
|
|
1113
|
+
}
|
|
1114
|
+
interface ProviderStreamOutputChunk {
|
|
1115
|
+
readonly kind: "output";
|
|
1116
|
+
readonly output: string;
|
|
1117
|
+
readonly value: unknown;
|
|
1118
|
+
}
|
|
1119
|
+
interface ProviderStreamUsageChunk {
|
|
1120
|
+
readonly kind: "usage";
|
|
1121
|
+
readonly usage?: UsageRecord;
|
|
1122
|
+
readonly normalizedUsage?: Usage;
|
|
1123
|
+
}
|
|
1124
|
+
interface ProviderStreamGatewayChunk {
|
|
1125
|
+
readonly kind: "gateway";
|
|
1126
|
+
readonly gateway: ProviderGatewayMetadata;
|
|
1127
|
+
}
|
|
1128
|
+
interface ProviderStreamToolCallChunk {
|
|
1129
|
+
readonly kind: "tool-call";
|
|
1130
|
+
readonly toolCall: ValidatedToolCall;
|
|
1131
|
+
}
|
|
1132
|
+
interface ProviderStreamCompleteChunk {
|
|
1133
|
+
readonly kind: "complete";
|
|
1134
|
+
readonly rawOutputs?: Record<string, unknown>;
|
|
1135
|
+
readonly artifactRefs?: readonly (ArtifactInput | ArtifactRef)[];
|
|
1136
|
+
readonly usage?: UsageRecord;
|
|
1137
|
+
readonly normalizedUsage?: Usage;
|
|
1138
|
+
readonly gateway?: ProviderGatewayMetadata;
|
|
1139
|
+
readonly toolCalls?: readonly ValidatedToolCall[];
|
|
1140
|
+
readonly finish?: ProviderFinishMetadata;
|
|
1141
|
+
readonly rawResponse?: unknown;
|
|
1142
|
+
}
|
|
1143
|
+
type ProviderStreamChunk = ProviderStreamTextDeltaChunk | ProviderStreamOutputChunk | ProviderStreamUsageChunk | ProviderStreamGatewayChunk | ProviderStreamToolCallChunk | ProviderStreamCompleteChunk;
|
|
1144
|
+
type ProviderStream = AsyncIterable<ProviderStreamChunk>;
|
|
1145
|
+
interface ProviderAdapter {
|
|
1146
|
+
readonly id: string;
|
|
1147
|
+
readonly kind: "provider-adapter";
|
|
1148
|
+
readonly capabilities?: readonly ModelCapability[];
|
|
1149
|
+
readonly execute?: (request: ProviderRunRequest) => Promise<ProviderRunResponse>;
|
|
1150
|
+
readonly executeStream?: (request: ProviderRunRequest) => ProviderStream | Promise<ProviderStream>;
|
|
1151
|
+
/**
|
|
1152
|
+
* Phase 34 — D-01 — Per-adapter behavioral deviation flags. OPTIONAL on the
|
|
1153
|
+
* base interface so v1.2 consumer adapters (4-field literals) continue to work
|
|
1154
|
+
* without modification (non-breaking). First-party adapter factories narrow the
|
|
1155
|
+
* return type to require `quirks` with the specific sub-interface for their adapter.
|
|
1156
|
+
*
|
|
1157
|
+
* D-03 discriminant-narrowing contract: consumers reading this field get
|
|
1158
|
+
* `AdapterQuirks` autocomplete. To access adapter-specific flags, cast after
|
|
1159
|
+
* an `adapter.id` discriminant check OR use the typed factory return directly.
|
|
1160
|
+
* Example: `(adapter.quirks as AnthropicQuirks).promptCachingSupported`.
|
|
1161
|
+
*/
|
|
1162
|
+
readonly quirks?: AdapterQuirks;
|
|
1163
|
+
/**
|
|
1164
|
+
* Phase 34 — D-02 — Capability negotiation via the provider's /models endpoint.
|
|
1165
|
+
* OPTIONAL on the base interface (non-breaking for v1.2 consumer adapters).
|
|
1166
|
+
* First-party adapters that have a /models endpoint implement this; adapters
|
|
1167
|
+
* without one (LM Studio, openai-compat) fall back to the Phase 33 registry.
|
|
1168
|
+
*
|
|
1169
|
+
* The top-level `negotiateCapabilities(adapter, modelId)` helper in
|
|
1170
|
+
* `capabilities/negotiate.ts` delegates to this method when present and
|
|
1171
|
+
* synthesizes from the registry otherwise (D-04).
|
|
1172
|
+
*/
|
|
1173
|
+
readonly negotiateCapabilities?: (modelId: string) => Promise<NegotiatedCapabilities>;
|
|
1174
|
+
}
|
|
1175
|
+
type ProviderRegistryInput = readonly (ProviderRef | ProviderAdapter | string)[];
|
|
1176
|
+
//#endregion
|
|
1177
|
+
export { XaiQuirks as $, ExecutionPlanStub as $t, SANITIZER_BY_FAILURE_MODE as A, defaultPiiDetectors as At, ModelCapabilityProfilePricingKey as B, ContextSummarizer as Bt, ProviderToolDefinition as C, ValidationIssue as Ct, NegotiationAuthError as D, evaluateTripwires as Dt, NegotiatedCapabilities as E, TripwireResult as Et, CapabilityAdapter as F, MustCiteInvariant as Ft, AdapterQuirks as G, toContextArtifactRefs as Gt, RecommendedPromptStrategy as H, buildContextPack as Ht, KnownFailureMode as I, NoPiiInvariant as It, LiteLLMQuirks as J, SessionStore as Jt, AnthropicQuirks as K, SessionRecord as Kt, ModelCapabilityProfile as L, inv as Lt, getRecommendedSanitizers as M, InvariantDeclaration as Mt, ALL_KNOWN_FAILURE_MODES as N, InvariantOptions as Nt, negotiateCapabilities as O, PiiDetector as Ot, ALL_TRAINING_CLASSES as P, MatchesInvariant as Pt, OpenRouterQuirks as Q, ExecutionPlan as Qt, ModelCapabilityProfileModality as R, BuildContextPackInput as Rt, ProviderToolChoice as S, ValidationError as St, Usage as T, TripwireEvidence as Tt, ToolCallSurface as U, estimateArtifactTokens as Ut, ReasoningSurface as V, TrustLabel as Vt, TrainingClass as W, estimateTokens as Wt, OpenAICompatQuirks as X, ContextPackItemPlan as Xt, LmStudioQuirks as Y, createMemorySessionStore as Yt, OpenAIQuirks as Z, ContextPackPlan as Zt, ProviderStreamOutputChunk as _, output as _n, NoContractMatchError as _t, ProviderFinishMetadata as a, RouteDecision as an, McpLikeClient as at, ProviderStreamUsageChunk as b, RunEventSink as bn, TimeoutError as bt, ProviderPricingHint as c, SelectedRoute as cn, ToolDefinition as ct, ProviderRunRequest as d, CitationRef as dn, importMcpTools as dt, FallbackRoute as en, ToolCallValidationError as et, ProviderRunResponse as f, CitationsOutputContract as fn, runTool as ft, ProviderStreamGatewayChunk as g, TextOutputContract as gn, LatticeRunError as gt, ProviderStreamCompleteChunk as h, SchemaOutputContract as hn, parseToolUseEnvelope as ht, ProviderDataPolicyHints as i, RouteCandidate as in, validateToolCallRequests as it, SanitizerKey as j, FieldFromTableInvariant as jt, synthesizeNegotiatedCapabilitiesFromRegistry as k, PiiDetectorResult as kt, ProviderRef as l, UsageRecord as ln, ToolExecutionContext as lt, ProviderStreamChunk as m, OutputContractMap as mn, ToolUseRequest as mt, ModelCapability as n, ProviderPackagingPlan as nn, ValidateToolCallsOption as nt, ProviderGatewayMetadata as o, RouteEstimates as on, McpToolDescriptor as ot, ProviderStream as p, OutputContract as pn, toolArtifactRef as pt, GeminiQuirks as q, SessionRef as qt, ProviderAdapter as r, ResultPlan as rn, ValidatedToolCall as rt, ProviderLatencyClass as s, RouteRejectReason as sn, ToolCallResult as st, CapabilityModality as t, ProviderAttemptRecord as tn, ToolCallValidationFailureReason as tt, ProviderRegistryInput as u, ArtifactRefsOutputContract as un, defineTool as ut, ProviderStreamTextDeltaChunk as v, RunEvent as vn, NoRouteError as vt, ProviderTransportMode as w, isTerminal as wt, ProviderStructuredOutputRequest as x, TracerLike as xn, TripwireViolationError as xt, ProviderStreamToolCallChunk as y, RunEventKind as yn, ProviderExecutionError as yt, ModelCapabilityProfilePricing as z, ContextPack as zt };
|
|
1178
|
+
//# sourceMappingURL=provider-C2IfKsvz.d.ts.map
|