@vostride/agent-qa-model 0.0.0-stage → 0.2.1
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/LICENSE.md +105 -0
- package/NOTICE.md +11 -0
- package/dist/index.cjs +1701 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +272 -0
- package/dist/index.d.ts +272 -0
- package/dist/index.js +1636 -0
- package/dist/index.js.map +1 -0
- package/package.json +64 -4
- package/README.md +0 -3
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,272 @@
|
|
|
1
|
+
import { LanguageModelV3 } from '@ai-sdk/provider';
|
|
2
|
+
import { ModelProfile, ModelCapabilities, ModelProviderId, MaskFn } from '@vostride/agent-qa-schema';
|
|
3
|
+
export { ModelAuthDeclaration, ModelCapabilities, ModelProfile, ModelProviderId } from '@vostride/agent-qa-schema';
|
|
4
|
+
import { ModelMessage, LanguageModelUsage, LanguageModelMiddleware } from 'ai';
|
|
5
|
+
|
|
6
|
+
type ResolvedModelAuth = {
|
|
7
|
+
kind: 'api-key';
|
|
8
|
+
apiKey: string;
|
|
9
|
+
} | {
|
|
10
|
+
kind: 'bearer-token';
|
|
11
|
+
token: string;
|
|
12
|
+
} | {
|
|
13
|
+
kind: 'auth-fetch';
|
|
14
|
+
modelAdapter: 'openai-responses' | 'anthropic-messages';
|
|
15
|
+
fetch: typeof globalThis.fetch;
|
|
16
|
+
} | {
|
|
17
|
+
kind: 'none';
|
|
18
|
+
};
|
|
19
|
+
interface Transport {
|
|
20
|
+
baseURL?: string;
|
|
21
|
+
headers?: Record<string, string>;
|
|
22
|
+
apiKey?: string;
|
|
23
|
+
authToken?: string;
|
|
24
|
+
fetch?: typeof globalThis.fetch;
|
|
25
|
+
providerOptions?: ModelProfile['providerOptions'];
|
|
26
|
+
}
|
|
27
|
+
declare function deriveTransport(profile: ModelProfile, auth: ResolvedModelAuth): Transport;
|
|
28
|
+
|
|
29
|
+
declare function anthropicCompatible(transport: Transport, modelId: string): LanguageModelV3;
|
|
30
|
+
declare function anthropicSubscription(transport: Transport, modelId: string): LanguageModelV3;
|
|
31
|
+
|
|
32
|
+
type JSONValue = string | number | boolean | null | JSONValue[] | {
|
|
33
|
+
[key: string]: JSONValue | undefined;
|
|
34
|
+
};
|
|
35
|
+
type ProviderOptions = Record<string, Record<string, JSONValue | undefined>> | undefined;
|
|
36
|
+
interface ProviderOptionsConfig {
|
|
37
|
+
provider?: string;
|
|
38
|
+
modelAdapter?: 'openai-responses' | 'anthropic-messages';
|
|
39
|
+
fetch?: typeof globalThis.fetch;
|
|
40
|
+
}
|
|
41
|
+
declare function openaiCompatible(transport: Transport, modelId: string): LanguageModelV3;
|
|
42
|
+
declare function openaiSubscription(transport: Transport, modelId: string): LanguageModelV3;
|
|
43
|
+
declare function getProviderOptions(config: ProviderOptionsConfig): ProviderOptions;
|
|
44
|
+
|
|
45
|
+
type AdapterBody = (transport: Transport, modelId: string) => LanguageModelV3;
|
|
46
|
+
|
|
47
|
+
declare function gemini(transport: Transport, modelId: string): LanguageModelV3;
|
|
48
|
+
|
|
49
|
+
type LogEntry = {
|
|
50
|
+
source: string;
|
|
51
|
+
level?: string;
|
|
52
|
+
message: string;
|
|
53
|
+
};
|
|
54
|
+
/**
|
|
55
|
+
* Compact a log-shaped burst into a deterministic, bounded string (D-13/D-15).
|
|
56
|
+
* Groups typed `{source, level, message}` entries by `source::level::normalized`,
|
|
57
|
+
* counts each class, and renders it with the first ≤5 raw samples seen (monotonic:
|
|
58
|
+
* once a class has 5 samples, growing the burst never changes which 5 are shown;
|
|
59
|
+
* the onset occurrence is always retained). Classes render in sorted-key order.
|
|
60
|
+
*/
|
|
61
|
+
declare function compactLogs(entries: LogEntry[]): string;
|
|
62
|
+
/**
|
|
63
|
+
* Bound a single structured value for prompt inclusion (D-14). Safe-stringifies the
|
|
64
|
+
* value verbatim (variable tokens preserved — the planner may need them exactly) and,
|
|
65
|
+
* only if it exceeds `BLOB_CEILING`, slices and appends the visible truncation marker.
|
|
66
|
+
* `undefined` in ⇒ `undefined` out. Never throws on cyclic input (V5).
|
|
67
|
+
*/
|
|
68
|
+
declare function guardBlob(value: unknown): string | undefined;
|
|
69
|
+
/**
|
|
70
|
+
* The composed pre-prompt guard for one tool-output value (CTXB-06): a burst of
|
|
71
|
+
* log-shaped entries (console `{level, text}` / network `{url, method, status}` /
|
|
72
|
+
* generic `{source?, level?, message}`) routes through {@link compactLogs};
|
|
73
|
+
* anything else through {@link guardBlob}. Compacted output is still bounded by
|
|
74
|
+
* the blob ceiling so a burst of all-distinct classes cannot flood the prompt.
|
|
75
|
+
*/
|
|
76
|
+
declare function guardToolOutput(value: unknown): string | undefined;
|
|
77
|
+
|
|
78
|
+
declare function parseRealWindow(error: unknown): number | undefined;
|
|
79
|
+
declare function isContextOverflow(error: unknown): boolean;
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Caller-supplied degrade controls (D-07/D-09). Policy-free: no default/safety margin is
|
|
83
|
+
* baked here — Phase 355 supplies the concrete budget and pin predicate.
|
|
84
|
+
*
|
|
85
|
+
* - `budget` — the token ceiling the degraded prompt must fit under.
|
|
86
|
+
* - `pin` — a caller pin predicate; a message matching it is never evicted or truncated.
|
|
87
|
+
* The substrate stays tier-ignorant (355 pins its tiers explicitly).
|
|
88
|
+
* - `estimate` — the estimator the damage loop re-runs after each eviction. Optional so
|
|
89
|
+
* `degrade` stays a standalone-testable pure function; the Plan-03 factory passes its own.
|
|
90
|
+
*/
|
|
91
|
+
interface DegradeOptions {
|
|
92
|
+
budget: number;
|
|
93
|
+
pin?: (message: ModelMessage, index: number) => boolean;
|
|
94
|
+
estimate?: (messages: ModelMessage[]) => number;
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Discriminated degrade result (D-09). `ok:true` carries the fitted messages; `ok:false`
|
|
98
|
+
* is the structured cannot-fit outcome returned when system + final + pinned content alone
|
|
99
|
+
* exceeds the budget — degrade never throws and never violates a pin, returning the
|
|
100
|
+
* best-effort hygiene-reduced messages instead.
|
|
101
|
+
*/
|
|
102
|
+
type DegradeOutcome = {
|
|
103
|
+
ok: true;
|
|
104
|
+
messages: ModelMessage[];
|
|
105
|
+
} | {
|
|
106
|
+
ok: false;
|
|
107
|
+
reason: 'pinned-content-exceeds-budget';
|
|
108
|
+
messages: ModelMessage[];
|
|
109
|
+
};
|
|
110
|
+
/**
|
|
111
|
+
* The instance shape returned by the Plan-03 factory and consumed through the runner's
|
|
112
|
+
* provider-neutral port (D-05). Prompt tokens only; the substrate is policy-free.
|
|
113
|
+
*/
|
|
114
|
+
interface TokenAccounting {
|
|
115
|
+
estimate(messages: ModelMessage[]): number;
|
|
116
|
+
recordUsage(usage: LanguageModelUsage, messages: ModelMessage[]): void;
|
|
117
|
+
getCeilings(): {
|
|
118
|
+
contextWindow: number;
|
|
119
|
+
maxOutput: number;
|
|
120
|
+
};
|
|
121
|
+
degrade(messages: ModelMessage[], options: DegradeOptions): DegradeOutcome;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Factory construction options (Plan 03).
|
|
125
|
+
*
|
|
126
|
+
* - `getCapabilities` — the D-04 lazy ceilings thunk (composes v46 `resolveCapabilities`),
|
|
127
|
+
* read on every estimate/degrade so a mid-run overflow-learned window shrink applies next turn.
|
|
128
|
+
* - `perImageTokens` — the D-12 injectable flat per-image constant (test/chat-layer tuning).
|
|
129
|
+
*/
|
|
130
|
+
interface TokenAccountingOptions {
|
|
131
|
+
getCapabilities: () => ModelCapabilities;
|
|
132
|
+
perImageTokens?: number;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
declare function createTokenAccounting(options: TokenAccountingOptions): TokenAccounting;
|
|
136
|
+
|
|
137
|
+
interface FamilyEntry {
|
|
138
|
+
match: readonly string[];
|
|
139
|
+
caps: ModelCapabilities;
|
|
140
|
+
}
|
|
141
|
+
declare const UNKNOWN_FLOOR: ModelCapabilities;
|
|
142
|
+
declare const FAMILIES: readonly FamilyEntry[];
|
|
143
|
+
declare function matchFamily(model: string): ModelCapabilities | undefined;
|
|
144
|
+
|
|
145
|
+
declare const overrideStore: Map<string, number>;
|
|
146
|
+
declare function capabilityKey(provider: string, model: string): string;
|
|
147
|
+
declare function getObservedWindow(key: string): number | undefined;
|
|
148
|
+
|
|
149
|
+
declare function resolveCapabilities(profile: ModelProfile): ModelCapabilities;
|
|
150
|
+
|
|
151
|
+
interface CatalogEntry {
|
|
152
|
+
id: string;
|
|
153
|
+
label: string;
|
|
154
|
+
vision: boolean;
|
|
155
|
+
notes?: string;
|
|
156
|
+
}
|
|
157
|
+
declare const MODEL_CATALOG: Record<ModelProviderId, CatalogEntry[]>;
|
|
158
|
+
declare function getModelCatalog(): Record<ModelProviderId, CatalogEntry[]>;
|
|
159
|
+
|
|
160
|
+
interface FetchLiveModelsOptions {
|
|
161
|
+
baseURL: string;
|
|
162
|
+
headers?: Record<string, string>;
|
|
163
|
+
fetchImpl?: typeof globalThis.fetch;
|
|
164
|
+
timeoutMs?: number;
|
|
165
|
+
ttlMs?: number;
|
|
166
|
+
}
|
|
167
|
+
declare function fetchLiveModels(opts: FetchLiveModelsOptions): Promise<CatalogEntry[]>;
|
|
168
|
+
declare function mergeCatalog(staticEntries: CatalogEntry[], live: CatalogEntry[]): CatalogEntry[];
|
|
169
|
+
|
|
170
|
+
declare const toolSchemaMiddleware: LanguageModelMiddleware;
|
|
171
|
+
|
|
172
|
+
declare function capabilityUpdateMiddleware(profile: ModelProfile): LanguageModelMiddleware;
|
|
173
|
+
|
|
174
|
+
interface DebugLoggingOptions {
|
|
175
|
+
/** Force enable/disable. When omitted, resolves from the `AGENT_QA_DEBUG_LLM` env flag. */
|
|
176
|
+
enabled?: boolean;
|
|
177
|
+
/** Line sink. Defaults to stderr. Injected by tests as a spy. */
|
|
178
|
+
sink?: (line: string) => void;
|
|
179
|
+
}
|
|
180
|
+
declare function debugLoggingMiddleware(options?: DebugLoggingOptions): LanguageModelMiddleware;
|
|
181
|
+
|
|
182
|
+
declare function dropEmptyMessagesMiddleware(): LanguageModelMiddleware;
|
|
183
|
+
|
|
184
|
+
declare function deriveExamplesMiddleware(): LanguageModelMiddleware;
|
|
185
|
+
|
|
186
|
+
declare function extractJsonStrategy(text: string): string;
|
|
187
|
+
|
|
188
|
+
declare function repairMiddleware(): LanguageModelMiddleware;
|
|
189
|
+
|
|
190
|
+
interface RetryMiddlewareOptions {
|
|
191
|
+
maxRetries?: number;
|
|
192
|
+
initialDelayInMs?: number;
|
|
193
|
+
backoffFactor?: number;
|
|
194
|
+
}
|
|
195
|
+
declare function retryMiddleware({ maxRetries, initialDelayInMs, backoffFactor, }?: RetryMiddlewareOptions): LanguageModelMiddleware;
|
|
196
|
+
|
|
197
|
+
declare function stripUnsupportedParamsMiddleware(params: readonly string[]): LanguageModelMiddleware;
|
|
198
|
+
|
|
199
|
+
type ProviderAuthMode = 'api-key' | 'bearer-token' | 'subscription' | 'none';
|
|
200
|
+
interface ProviderDescriptor {
|
|
201
|
+
id: string;
|
|
202
|
+
label: string;
|
|
203
|
+
adapter: AdapterBody;
|
|
204
|
+
needsBaseURL: boolean;
|
|
205
|
+
authModes: ProviderAuthMode[];
|
|
206
|
+
subscription?: boolean;
|
|
207
|
+
credentialOptional?: boolean;
|
|
208
|
+
modelAdapter?: 'openai-responses' | 'anthropic-messages';
|
|
209
|
+
baseURLPlaceholder?: string;
|
|
210
|
+
defaultModel?: string;
|
|
211
|
+
unsupportedParams?: readonly string[];
|
|
212
|
+
}
|
|
213
|
+
declare function registerProvider(descriptor: ProviderDescriptor): void;
|
|
214
|
+
declare function getProvider(id: string): ProviderDescriptor | undefined;
|
|
215
|
+
declare function listProviders(): ProviderDescriptor[];
|
|
216
|
+
declare function clearProviderRegistry(): void;
|
|
217
|
+
|
|
218
|
+
/** Neutral facts for one completed provider dispatch. Missing facts are omitted. */
|
|
219
|
+
interface ModelCallReport {
|
|
220
|
+
inputTokens?: number;
|
|
221
|
+
outputTokens?: number;
|
|
222
|
+
cachedInputTokens?: number;
|
|
223
|
+
respondingModelId?: string;
|
|
224
|
+
}
|
|
225
|
+
type ModelCallEvent = {
|
|
226
|
+
kind: 'start';
|
|
227
|
+
} | {
|
|
228
|
+
kind: 'success';
|
|
229
|
+
report: ModelCallReport;
|
|
230
|
+
} | {
|
|
231
|
+
kind: 'failure';
|
|
232
|
+
};
|
|
233
|
+
declare const MODEL_CALL_EVENT_KINDS: readonly ["start", "success", "failure"];
|
|
234
|
+
/** An explicit assertion that raw usage and response metadata retain this wire origin. */
|
|
235
|
+
type ModelCallReportOrigin = 'openai-chat' | 'openai-responses' | 'anthropic-messages' | 'gemini';
|
|
236
|
+
declare const MODEL_CALL_REPORT_ORIGINS: readonly ["openai-chat", "openai-responses", "anthropic-messages", "gemini"];
|
|
237
|
+
interface ModelCallObservation {
|
|
238
|
+
/** Legacy notification, invoked once per dispatch, without provider data. */
|
|
239
|
+
onProviderCall?: () => void;
|
|
240
|
+
/** No prompts, credentials, response bodies or error text cross this callback. */
|
|
241
|
+
onCall?: (event: ModelCallEvent) => void;
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
interface ModelProviderOverrides {
|
|
245
|
+
languageModels?: Record<string, LanguageModelV3>;
|
|
246
|
+
/** Trusted custom/override adapter assertion; omitted means no cache/model authority. */
|
|
247
|
+
providerReportOrigin?: ModelCallReportOrigin;
|
|
248
|
+
}
|
|
249
|
+
declare function createModel(profile: ModelProfile, auth: ResolvedModelAuth, mask: MaskFn, overrides?: ModelProviderOverrides, observation?: ModelCallObservation): LanguageModelV3;
|
|
250
|
+
|
|
251
|
+
declare function validateProfile(profile: ModelProfile): void;
|
|
252
|
+
|
|
253
|
+
interface VisionSizingConfig {
|
|
254
|
+
screenshotSize?: number;
|
|
255
|
+
effectiveResolution?: number;
|
|
256
|
+
}
|
|
257
|
+
declare function resolveVisionConfig(servicesVision: VisionSizingConfig | undefined): VisionSizingConfig;
|
|
258
|
+
|
|
259
|
+
interface VisionGate {
|
|
260
|
+
attachImage: boolean;
|
|
261
|
+
captureMode: 'full' | 'textOnly';
|
|
262
|
+
promptNote: string;
|
|
263
|
+
}
|
|
264
|
+
/** 439 D-19: the configured `vision` when set, otherwise what the capability table says. */
|
|
265
|
+
declare function visionFromConfig(configured: boolean | undefined, capabilities: {
|
|
266
|
+
vision: boolean;
|
|
267
|
+
}): boolean;
|
|
268
|
+
declare function resolveVisionGate(model: {
|
|
269
|
+
vision: boolean;
|
|
270
|
+
}): VisionGate;
|
|
271
|
+
|
|
272
|
+
export { type AdapterBody, type CatalogEntry, type DebugLoggingOptions, type DegradeOptions, type DegradeOutcome, FAMILIES, type LogEntry, MODEL_CALL_EVENT_KINDS, MODEL_CALL_REPORT_ORIGINS, MODEL_CATALOG, type ModelCallEvent, type ModelCallObservation, type ModelCallReport, type ModelCallReportOrigin, type ModelProviderOverrides, type ProviderAuthMode, type ProviderDescriptor, type ResolvedModelAuth, type TokenAccounting, type TokenAccountingOptions, type Transport, UNKNOWN_FLOOR, type VisionGate, type VisionSizingConfig, anthropicCompatible, anthropicSubscription, capabilityKey, capabilityUpdateMiddleware, clearProviderRegistry, compactLogs, createModel, createTokenAccounting, debugLoggingMiddleware, deriveExamplesMiddleware, deriveTransport, dropEmptyMessagesMiddleware, extractJsonStrategy, fetchLiveModels, gemini, getModelCatalog, getObservedWindow, getProvider, getProviderOptions, guardBlob, guardToolOutput, isContextOverflow as isContextLengthOverflow, isContextOverflow, listProviders, matchFamily, mergeCatalog, openaiCompatible, openaiSubscription, overrideStore, parseRealWindow, registerProvider, repairMiddleware, resolveCapabilities, resolveVisionConfig, resolveVisionGate, retryMiddleware, stripUnsupportedParamsMiddleware, toolSchemaMiddleware, validateProfile, visionFromConfig };
|