@warmdrift/kgauto-compiler 2.0.0-alpha.27 → 2.0.0-alpha.28
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/chunk-WXCFWUCN.mjs +678 -0
- package/dist/glassbox/index.d.mts +3 -3
- package/dist/glassbox/index.d.ts +3 -3
- package/dist/glassbox-routes/index.d.mts +88 -6
- package/dist/glassbox-routes/index.d.ts +88 -6
- package/dist/glassbox-routes/index.js +1820 -8
- package/dist/glassbox-routes/index.mjs +320 -8
- package/dist/index.d.mts +184 -3
- package/dist/index.d.ts +184 -3
- package/dist/index.js +161 -5
- package/dist/index.mjs +107 -580
- package/dist/{ir-B_XX2LAO.d.ts → ir-5W0efxt9.d.ts} +86 -1
- package/dist/{ir-B9zqlwjH.d.mts → ir-MXCJA8L7.d.mts} +86 -1
- package/dist/profiles.d.mts +1 -1
- package/dist/profiles.d.ts +1 -1
- package/dist/{types-bt0aVJb8.d.ts → types-CiZ9HLIU.d.ts} +1 -1
- package/dist/{types-o9etg93a.d.mts → types-sDZQzPM6.d.mts} +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,678 @@
|
|
|
1
|
+
import {
|
|
2
|
+
tryGetProfile
|
|
3
|
+
} from "./chunk-JQGRWJZO.mjs";
|
|
4
|
+
|
|
5
|
+
// src/brain-query.ts
|
|
6
|
+
var FRESH_SNAPSHOT = {
|
|
7
|
+
data: null,
|
|
8
|
+
expiresAt: 0,
|
|
9
|
+
refreshing: false,
|
|
10
|
+
warned: false
|
|
11
|
+
};
|
|
12
|
+
var snapshot = { ...FRESH_SNAPSHOT };
|
|
13
|
+
var runtime;
|
|
14
|
+
function configureBrainQuery(rt) {
|
|
15
|
+
runtime = rt;
|
|
16
|
+
snapshot = { ...FRESH_SNAPSHOT };
|
|
17
|
+
}
|
|
18
|
+
function createBrainQueryCache(opts) {
|
|
19
|
+
return () => {
|
|
20
|
+
const rt = runtime;
|
|
21
|
+
if (!rt || !rt.enabledTables.has(opts.table)) {
|
|
22
|
+
return opts.bundledFallback();
|
|
23
|
+
}
|
|
24
|
+
const now = Date.now();
|
|
25
|
+
const stale = snapshot.expiresAt <= now;
|
|
26
|
+
if (stale && !snapshot.refreshing) {
|
|
27
|
+
snapshot.refreshing = true;
|
|
28
|
+
void asyncRefresh(rt);
|
|
29
|
+
}
|
|
30
|
+
if (snapshot.data) {
|
|
31
|
+
const rows = snapshot.data[opts.table];
|
|
32
|
+
if (Array.isArray(rows) && rows.length > 0) {
|
|
33
|
+
try {
|
|
34
|
+
return opts.mapRows(rows);
|
|
35
|
+
} catch {
|
|
36
|
+
return opts.bundledFallback();
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return opts.bundledFallback();
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
var pendingRefresh;
|
|
44
|
+
async function asyncRefresh(rt) {
|
|
45
|
+
const promise = doRefresh(rt);
|
|
46
|
+
pendingRefresh = promise;
|
|
47
|
+
try {
|
|
48
|
+
await promise;
|
|
49
|
+
} finally {
|
|
50
|
+
if (pendingRefresh === promise) pendingRefresh = void 0;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
var DEFAULT_CONFIG_URL = "https://kgauto-dashboard.vercel.app/api/kgauto-v2/config";
|
|
54
|
+
async function doRefresh(rt) {
|
|
55
|
+
const url = rt.configEndpoint ?? DEFAULT_CONFIG_URL;
|
|
56
|
+
try {
|
|
57
|
+
const res = await rt.fetchImpl(url, { method: "GET" });
|
|
58
|
+
if (!res.ok) {
|
|
59
|
+
throw new Error(`brain-query ${res.status}: ${res.statusText}`);
|
|
60
|
+
}
|
|
61
|
+
const body = await res.json();
|
|
62
|
+
if (runtime !== rt) return;
|
|
63
|
+
snapshot = {
|
|
64
|
+
data: body,
|
|
65
|
+
expiresAt: Date.now() + rt.ttlMs,
|
|
66
|
+
refreshing: false,
|
|
67
|
+
warned: snapshot.warned
|
|
68
|
+
};
|
|
69
|
+
} catch (err) {
|
|
70
|
+
if (runtime !== rt) return;
|
|
71
|
+
snapshot.refreshing = false;
|
|
72
|
+
snapshot.expiresAt = Date.now() + rt.ttlMs;
|
|
73
|
+
if (!snapshot.warned) {
|
|
74
|
+
snapshot.warned = true;
|
|
75
|
+
(rt.onError ?? defaultOnError)(err);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function defaultOnError(err) {
|
|
80
|
+
console.warn("[kgauto] brain-query failed (using bundled fallback):", err);
|
|
81
|
+
}
|
|
82
|
+
function isBrainQueryActiveFor(table) {
|
|
83
|
+
return runtime !== void 0 && runtime.enabledTables.has(table);
|
|
84
|
+
}
|
|
85
|
+
async function getPerAxisMetrics(opts) {
|
|
86
|
+
const fetchFn = opts.fetch ?? fetch;
|
|
87
|
+
const endpoint = opts.endpoint ?? runtime?.endpoint;
|
|
88
|
+
if (!endpoint) return null;
|
|
89
|
+
const windowDays = opts.windowDays ?? 30;
|
|
90
|
+
const body = {
|
|
91
|
+
p_app_id: opts.appId,
|
|
92
|
+
p_archetype: opts.archetype,
|
|
93
|
+
p_model: opts.model,
|
|
94
|
+
p_window_days: windowDays,
|
|
95
|
+
p_quality_floor: opts.qualityFloor ?? null
|
|
96
|
+
};
|
|
97
|
+
const headers = {
|
|
98
|
+
Accept: "application/json",
|
|
99
|
+
"Content-Type": "application/json",
|
|
100
|
+
...opts.apiKey ? { Authorization: `Bearer ${opts.apiKey}` } : {}
|
|
101
|
+
};
|
|
102
|
+
try {
|
|
103
|
+
const res = await fetchFn(`${endpoint}/rpc/get_per_axis_metrics`, {
|
|
104
|
+
method: "POST",
|
|
105
|
+
headers,
|
|
106
|
+
body: JSON.stringify(body)
|
|
107
|
+
});
|
|
108
|
+
if (!res.ok) return null;
|
|
109
|
+
const raw = await res.json();
|
|
110
|
+
return mapPerAxisMetrics(raw, opts.appId, opts.archetype, opts.model, windowDays);
|
|
111
|
+
} catch {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
function mapPerAxisMetrics(raw, fallbackAppId, fallbackArchetype, fallbackModel, fallbackWindowDays) {
|
|
116
|
+
if (raw === null || raw === void 0) return null;
|
|
117
|
+
if (typeof raw !== "object") return null;
|
|
118
|
+
const r = raw;
|
|
119
|
+
if (Array.isArray(raw)) {
|
|
120
|
+
if (raw.length === 0) return null;
|
|
121
|
+
return mapPerAxisMetrics(raw[0], fallbackAppId, fallbackArchetype, fallbackModel, fallbackWindowDays);
|
|
122
|
+
}
|
|
123
|
+
const num = (v) => {
|
|
124
|
+
if (v === null || v === void 0) return null;
|
|
125
|
+
if (typeof v === "number") return Number.isFinite(v) ? v : null;
|
|
126
|
+
if (typeof v === "string") {
|
|
127
|
+
const n = Number(v);
|
|
128
|
+
return Number.isFinite(n) ? n : null;
|
|
129
|
+
}
|
|
130
|
+
return null;
|
|
131
|
+
};
|
|
132
|
+
const int = (v) => {
|
|
133
|
+
const n = num(v);
|
|
134
|
+
return n === null ? 0 : Math.trunc(n);
|
|
135
|
+
};
|
|
136
|
+
const bool = (v) => {
|
|
137
|
+
if (v === null || v === void 0) return null;
|
|
138
|
+
if (typeof v === "boolean") return v;
|
|
139
|
+
return null;
|
|
140
|
+
};
|
|
141
|
+
const str = (v, fallback) => typeof v === "string" ? v : fallback;
|
|
142
|
+
const cost = r.cost_efficiency ?? {};
|
|
143
|
+
const time = r.time_efficiency ?? {};
|
|
144
|
+
const rel = r.reliability ?? {};
|
|
145
|
+
return {
|
|
146
|
+
appId: str(r.app_id, fallbackAppId),
|
|
147
|
+
archetype: str(r.archetype, fallbackArchetype),
|
|
148
|
+
model: str(r.model, fallbackModel),
|
|
149
|
+
windowDays: num(r.window_days) ?? fallbackWindowDays,
|
|
150
|
+
nRows: int(r.n_rows),
|
|
151
|
+
nRowsClean: int(r.n_rows_clean),
|
|
152
|
+
nQualityOutcomes: int(r.n_quality_outcomes),
|
|
153
|
+
magicRate: num(r.magic_rate),
|
|
154
|
+
qualityFloorMet: bool(r.quality_floor_met),
|
|
155
|
+
costEfficiency: {
|
|
156
|
+
avgCostUsd: num(cost.avg_cost_usd),
|
|
157
|
+
avgCostUsdClean: num(cost.avg_cost_usd_clean),
|
|
158
|
+
avgInputTokens: num(cost.avg_input_tokens),
|
|
159
|
+
avgOutputTokens: num(cost.avg_output_tokens),
|
|
160
|
+
inputTokenRatio: num(cost.input_token_ratio)
|
|
161
|
+
},
|
|
162
|
+
timeEfficiency: {
|
|
163
|
+
avgLatencyMs: num(time.avg_latency_ms),
|
|
164
|
+
avgTtftMs: num(time.avg_ttft_ms)
|
|
165
|
+
},
|
|
166
|
+
reliability: {
|
|
167
|
+
successRate: num(rel.success_rate),
|
|
168
|
+
successRateClean: num(rel.success_rate_clean),
|
|
169
|
+
emptyRate: num(rel.empty_rate),
|
|
170
|
+
emptyRateClean: num(rel.empty_rate_clean)
|
|
171
|
+
},
|
|
172
|
+
evidenceFreshnessDays: num(r.evidence_freshness_days)
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
// src/compatibility.ts
|
|
177
|
+
var ARCHETYPE_FLOOR_DEFAULT = 6;
|
|
178
|
+
var ABSOLUTE_FLOOR = 4;
|
|
179
|
+
function rawArchetypePerf(profile, archetype) {
|
|
180
|
+
return profile.archetypePerf?.[archetype] ?? 5;
|
|
181
|
+
}
|
|
182
|
+
function hasSequentialToolCliffForHunt(profile) {
|
|
183
|
+
if (profile.parallelToolCalls !== false) return false;
|
|
184
|
+
const huntScore = profile.archetypePerf?.hunt ?? 5;
|
|
185
|
+
return huntScore < ARCHETYPE_FLOOR_DEFAULT;
|
|
186
|
+
}
|
|
187
|
+
function adapterForCliff(profile, archetype) {
|
|
188
|
+
if (archetype === "hunt" && hasSequentialToolCliffForHunt(profile)) {
|
|
189
|
+
const otherScores = [];
|
|
190
|
+
if (profile.archetypePerf) {
|
|
191
|
+
for (const [k, v] of Object.entries(profile.archetypePerf)) {
|
|
192
|
+
if (k === "hunt") continue;
|
|
193
|
+
if (typeof v === "number") otherScores.push(v);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const sorted = [...otherScores].sort((a, b) => a - b);
|
|
197
|
+
const median = sorted.length === 0 ? ARCHETYPE_FLOOR_DEFAULT + 1 : sorted[Math.floor(sorted.length / 2)] ?? ARCHETYPE_FLOOR_DEFAULT + 1;
|
|
198
|
+
const estimated = Math.max(ARCHETYPE_FLOOR_DEFAULT + 1, median);
|
|
199
|
+
return {
|
|
200
|
+
adapter: {
|
|
201
|
+
parameter: "toolOrchestration",
|
|
202
|
+
value: "sequential",
|
|
203
|
+
consequence: "Tool calls run one at a time instead of in parallel \u2014 slower per step but reliable for this model."
|
|
204
|
+
},
|
|
205
|
+
estimatedScoreWithAdapter: estimated
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
return void 0;
|
|
209
|
+
}
|
|
210
|
+
function archetypeDescriptor(archetype) {
|
|
211
|
+
return archetype;
|
|
212
|
+
}
|
|
213
|
+
function getModelCompatibility(modelId, intent) {
|
|
214
|
+
const profile = tryGetProfile(modelId);
|
|
215
|
+
if (!profile) {
|
|
216
|
+
return {
|
|
217
|
+
status: "reject",
|
|
218
|
+
reason: `Model "${modelId}" is not registered with kgauto \u2014 no compatibility data available.`,
|
|
219
|
+
archetypePerf: 0
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
const { archetype, toolOrchestration } = intent;
|
|
223
|
+
const rawScore = rawArchetypePerf(profile, archetype);
|
|
224
|
+
const descriptor = archetypeDescriptor(archetype);
|
|
225
|
+
const adapterMatch = adapterForCliff(profile, archetype);
|
|
226
|
+
if (toolOrchestration === "sequential" && adapterMatch && adapterMatch.adapter.parameter === "toolOrchestration" && adapterMatch.adapter.value === "sequential") {
|
|
227
|
+
return {
|
|
228
|
+
status: "compatible",
|
|
229
|
+
reason: `Suited for ${descriptor} with sequential tool calls.`,
|
|
230
|
+
archetypePerf: rawScore
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
if (rawScore >= ARCHETYPE_FLOOR_DEFAULT) {
|
|
234
|
+
return {
|
|
235
|
+
status: "compatible",
|
|
236
|
+
reason: `Suited for ${descriptor}.`,
|
|
237
|
+
archetypePerf: rawScore
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
if (adapterMatch) {
|
|
241
|
+
return {
|
|
242
|
+
status: "requires-adapter",
|
|
243
|
+
reason: `Best with ${adapterMatch.adapter.value} ${adapterMatch.adapter.parameter === "toolOrchestration" ? "tool calls" : adapterMatch.adapter.parameter} for ${descriptor} \u2014 slower but works.`,
|
|
244
|
+
archetypePerf: rawScore,
|
|
245
|
+
archetypePerfWithAdapter: adapterMatch.estimatedScoreWithAdapter,
|
|
246
|
+
adapter: adapterMatch.adapter
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
return {
|
|
250
|
+
status: "reject",
|
|
251
|
+
reason: `Not suited for ${descriptor} \u2014 would underperform significantly.`,
|
|
252
|
+
archetypePerf: rawScore
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
// src/env.ts
|
|
257
|
+
var SUPPORTED_PROVIDERS = Object.freeze([
|
|
258
|
+
"anthropic",
|
|
259
|
+
"google",
|
|
260
|
+
"openai",
|
|
261
|
+
"deepseek"
|
|
262
|
+
]);
|
|
263
|
+
function isSupportedProvider(p) {
|
|
264
|
+
return SUPPORTED_PROVIDERS.includes(p);
|
|
265
|
+
}
|
|
266
|
+
var PROVIDER_ENV_KEYS = Object.freeze({
|
|
267
|
+
anthropic: Object.freeze(["ANTHROPIC_API_KEY"]),
|
|
268
|
+
google: Object.freeze([
|
|
269
|
+
"GOOGLE_API_KEY",
|
|
270
|
+
"GEMINI_API_KEY",
|
|
271
|
+
"GOOGLE_GENERATIVE_AI_API_KEY"
|
|
272
|
+
]),
|
|
273
|
+
openai: Object.freeze(["OPENAI_API_KEY"]),
|
|
274
|
+
deepseek: Object.freeze(["DEEPSEEK_API_KEY"])
|
|
275
|
+
});
|
|
276
|
+
function defaultEnv() {
|
|
277
|
+
return typeof process !== "undefined" && process.env ? process.env : {};
|
|
278
|
+
}
|
|
279
|
+
function readKeyValue(raw) {
|
|
280
|
+
if (raw === void 0) return void 0;
|
|
281
|
+
const trimmed = raw.trim();
|
|
282
|
+
return trimmed.length > 0 ? trimmed : void 0;
|
|
283
|
+
}
|
|
284
|
+
function resolveProviderKey(provider, opts = {}) {
|
|
285
|
+
if (!isSupportedProvider(provider)) return void 0;
|
|
286
|
+
const explicit = readKeyValue(opts.apiKeys?.[provider]);
|
|
287
|
+
if (explicit) return explicit;
|
|
288
|
+
const env = opts.envSource ?? defaultEnv();
|
|
289
|
+
for (const name of PROVIDER_ENV_KEYS[provider]) {
|
|
290
|
+
const v = readKeyValue(env[name]);
|
|
291
|
+
if (v) return v;
|
|
292
|
+
}
|
|
293
|
+
return void 0;
|
|
294
|
+
}
|
|
295
|
+
function isProviderReachable(provider, opts = {}) {
|
|
296
|
+
return resolveProviderKey(provider, opts) !== void 0;
|
|
297
|
+
}
|
|
298
|
+
function isModelReachable(modelId, opts = {}) {
|
|
299
|
+
const profile = tryGetProfile(modelId);
|
|
300
|
+
if (!profile) return false;
|
|
301
|
+
return isProviderReachable(profile.provider, opts);
|
|
302
|
+
}
|
|
303
|
+
function getReachabilityDiagnostic(opts = {}) {
|
|
304
|
+
const env = opts.envSource ?? defaultEnv();
|
|
305
|
+
const out = {};
|
|
306
|
+
for (const provider of SUPPORTED_PROVIDERS) {
|
|
307
|
+
if (readKeyValue(opts.apiKeys?.[provider])) {
|
|
308
|
+
out[provider] = { reachable: true, via: "apiKeys" };
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
const envKeyFound = PROVIDER_ENV_KEYS[provider].find((name) => readKeyValue(env[name]));
|
|
312
|
+
out[provider] = envKeyFound ? { reachable: true, via: "env", envKeyFound } : { reachable: false, via: null };
|
|
313
|
+
}
|
|
314
|
+
return out;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
// src/fallback.ts
|
|
318
|
+
var STARTER_CHAINS_GROUNDED = {
|
|
319
|
+
// Reasoning floor — never degrade. Walk UP on 429 to Opus → cross-provider.
|
|
320
|
+
critique: [
|
|
321
|
+
{ id: "claude-opus-4-7", grounding: "judgment", reason: "Highest reasoning bar, no degradation tier \u2014 engineer pick, awaiting measured backing" },
|
|
322
|
+
{ id: "claude-sonnet-4-6", grounding: "judgment", reason: "Same-provider walk-down from Opus on 429" },
|
|
323
|
+
{ id: "gemini-2.5-pro", grounding: "judgment", reason: "Cross-provider anchor in similar quality bracket" },
|
|
324
|
+
{ id: "gpt-5.5", grounding: "judgment", reason: "alpha.16: third-provider frontier-tier floor (archetypePerf=9)" }
|
|
325
|
+
],
|
|
326
|
+
// Reasoning matters — Sonnet primary; walk UP to Opus on 429.
|
|
327
|
+
plan: [
|
|
328
|
+
{ id: "claude-sonnet-4-6", grounding: "judgment", reason: "Reasoning + cost balance \u2014 engineer pick" },
|
|
329
|
+
{ id: "claude-opus-4-7", grounding: "judgment", reason: 'Same-provider walk-UP on 429 (rare exception to "always cheaper")' },
|
|
330
|
+
{ id: "gemini-2.5-pro", grounding: "judgment", reason: "Cross-provider anchor" },
|
|
331
|
+
{ id: "deepseek-v4-pro", grounding: "judgment", reason: "Tier 3 cost floor \u2014 no brain evidence yet" }
|
|
332
|
+
],
|
|
333
|
+
// Quality + cost match.
|
|
334
|
+
generate: [
|
|
335
|
+
{ id: "claude-sonnet-4-6", grounding: "judgment", reason: "Quality + cost match \u2014 engineer pick" },
|
|
336
|
+
{ id: "claude-haiku-4-5", grounding: "judgment", reason: "Same-provider step-down" },
|
|
337
|
+
{ id: "gemini-2.5-pro", grounding: "judgment", reason: "Cross-provider anchor" },
|
|
338
|
+
{ id: "gpt-5.4-mini", grounding: "judgment", reason: "alpha.16: third-provider tail (archetypePerf=7) \u2014 closes mono-Anthropic gap" }
|
|
339
|
+
],
|
|
340
|
+
// ask::sonnet — STARTER_CHAINS calls this "Quality + cost match" but
|
|
341
|
+
// tt-intel s78 prod data showed 27% empty rate. Labeled 'judgment' until
|
|
342
|
+
// evidence either validates or refutes the placement.
|
|
343
|
+
ask: [
|
|
344
|
+
{ id: "claude-sonnet-4-6", grounding: "judgment", reason: "Quality + cost match \u2014 engineer pick. NOTE: tt-intel s78 prod showed 27% empty rate; placement awaits measurement validation" },
|
|
345
|
+
{ id: "claude-haiku-4-5", grounding: "judgment", reason: "Same-provider step-down" },
|
|
346
|
+
{ id: "gemini-2.5-pro", grounding: "judgment", reason: "Cross-provider anchor" },
|
|
347
|
+
{ id: "gpt-5.4-mini", grounding: "judgment", reason: "alpha.16: third-provider tail (archetypePerf=7)" }
|
|
348
|
+
],
|
|
349
|
+
// Structured-output archetype — Flash skipped (alpha.8 MAX_TOKENS cliff,
|
|
350
|
+
// capability-fact); DeepSeek skipped (no brain evidence).
|
|
351
|
+
extract: [
|
|
352
|
+
{ id: "claude-sonnet-4-6", grounding: "judgment", reason: "Reliable structured-output anchor \u2014 engineer pick" },
|
|
353
|
+
{ id: "claude-haiku-4-5", grounding: "judgment", reason: "Same-provider step-down with native structured output" },
|
|
354
|
+
{ id: "gemini-2.5-pro", grounding: "judgment", reason: "Cross-provider anchor with structured-output support" },
|
|
355
|
+
{ id: "gpt-5.4", grounding: "capability-fact", reason: "alpha.16: third-provider floor \u2014 native structured-output capability (archetypePerf=8)" }
|
|
356
|
+
],
|
|
357
|
+
// Forgiving archetype — Sonnet primary but Flash safely floors it.
|
|
358
|
+
transform: [
|
|
359
|
+
{ id: "claude-sonnet-4-6", grounding: "judgment", reason: "Quality anchor \u2014 engineer pick" },
|
|
360
|
+
{ id: "claude-haiku-4-5", grounding: "judgment", reason: "Same-provider step-down" },
|
|
361
|
+
{ id: "gemini-2.5-pro", grounding: "judgment", reason: "Cross-provider anchor" },
|
|
362
|
+
{ id: "gemini-2.5-flash", grounding: "judgment", reason: "Cost floor \u2014 forgiving archetype tolerates Flash" }
|
|
363
|
+
],
|
|
364
|
+
// Parallel-tool throughput champion — Flash leads on the L-040 cliff
|
|
365
|
+
// (capability-fact: Flash 15-75 parallel calls/step vs DeepSeek 7-8).
|
|
366
|
+
hunt: [
|
|
367
|
+
{ id: "gemini-2.5-flash", grounding: "capability-fact", reason: "L-040 parallel-tool throughput champion (15-75 calls/step)" },
|
|
368
|
+
{ id: "gemini-2.5-pro", grounding: "capability-fact", reason: "Cross-provider tier 1 with strong parallel-tool support" },
|
|
369
|
+
{ id: "claude-sonnet-4-6", grounding: "judgment", reason: "Quality safety net for blocked-Flash case" },
|
|
370
|
+
{ id: "claude-haiku-4-5", grounding: "judgment", reason: "Reduced tool budget \u2014 cliff at 16 fires" }
|
|
371
|
+
],
|
|
372
|
+
// Cost-sensitive + tolerant. DeepSeek brain-evidence tier 1.
|
|
373
|
+
summarize: [
|
|
374
|
+
{ id: "gemini-2.5-flash", grounding: "judgment", reason: "Cost-sensitive primary \u2014 engineer pick" },
|
|
375
|
+
{ id: "deepseek-v4-flash", grounding: "measured", reason: "Brain-validated tier 1 for cost-sensitive summarize workloads", n: 169 },
|
|
376
|
+
{ id: "claude-haiku-4-5", grounding: "judgment", reason: "Quality safety net" },
|
|
377
|
+
{ id: "gemini-2.5-flash-lite", grounding: "judgment", reason: "Emergency floor \u2014 onboarded s22, no brain evidence yet" }
|
|
378
|
+
],
|
|
379
|
+
// Brain-validated DeepSeek tier 1 (169 rows, 0% empty rate).
|
|
380
|
+
classify: [
|
|
381
|
+
{ id: "gemini-2.5-flash", grounding: "judgment", reason: "Cost-sensitive primary \u2014 engineer pick" },
|
|
382
|
+
{ id: "deepseek-v4-flash", grounding: "measured", reason: "Brain-validated tier 1 (169 rows, 0% empty rate)", n: 169 },
|
|
383
|
+
{ id: "claude-haiku-4-5", grounding: "judgment", reason: "Quality safety net" },
|
|
384
|
+
{ id: "gemini-2.5-flash-lite", grounding: "judgment", reason: "Cache-discount 10\xD7 floor for repeat-prompt workloads" }
|
|
385
|
+
]
|
|
386
|
+
};
|
|
387
|
+
var STARTER_CHAINS = (() => {
|
|
388
|
+
const out = {};
|
|
389
|
+
for (const [archetype, entries] of Object.entries(STARTER_CHAINS_GROUNDED)) {
|
|
390
|
+
out[archetype] = entries.map((e) => e.id);
|
|
391
|
+
}
|
|
392
|
+
return out;
|
|
393
|
+
})();
|
|
394
|
+
var STARTER_CHAINS_BY_MODE_GROUNDED = {
|
|
395
|
+
hunt: {
|
|
396
|
+
sequential: [
|
|
397
|
+
{
|
|
398
|
+
id: "deepseek-v4-pro",
|
|
399
|
+
grounding: "judgment",
|
|
400
|
+
reason: "alpha.20 E3: cheap + good reasoning at single-step granularity; L-040 cliff silenced when sequential \u2014 hypothesis not yet measured"
|
|
401
|
+
},
|
|
402
|
+
{
|
|
403
|
+
id: "deepseek-v4-flash",
|
|
404
|
+
grounding: "judgment",
|
|
405
|
+
reason: "Cheapest viable; sibling-provider fallback"
|
|
406
|
+
},
|
|
407
|
+
{
|
|
408
|
+
id: "claude-sonnet-4-6",
|
|
409
|
+
grounding: "judgment",
|
|
410
|
+
reason: "Cross-provider safety net \u2014 Sonnet handles sequential agentic loops cleanly"
|
|
411
|
+
},
|
|
412
|
+
{
|
|
413
|
+
id: "gemini-2.5-pro",
|
|
414
|
+
grounding: "judgment",
|
|
415
|
+
reason: "Third-provider tail when no DeepSeek key reachable"
|
|
416
|
+
}
|
|
417
|
+
]
|
|
418
|
+
}
|
|
419
|
+
};
|
|
420
|
+
var STARTER_CHAINS_BY_MODE = (() => {
|
|
421
|
+
const out = {};
|
|
422
|
+
for (const [archetype, modes] of Object.entries(STARTER_CHAINS_BY_MODE_GROUNDED)) {
|
|
423
|
+
if (modes?.sequential) {
|
|
424
|
+
out[archetype] = {
|
|
425
|
+
sequential: modes.sequential.map((e) => e.id)
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
return out;
|
|
430
|
+
})();
|
|
431
|
+
function resolveStarterForMode(archetype, toolOrchestration, allChains) {
|
|
432
|
+
if (toolOrchestration === "sequential") {
|
|
433
|
+
const overlay = STARTER_CHAINS_BY_MODE[archetype]?.sequential;
|
|
434
|
+
if (overlay) return [...overlay];
|
|
435
|
+
}
|
|
436
|
+
return allChains[archetype];
|
|
437
|
+
}
|
|
438
|
+
function getDefaultFallbackChain(opts) {
|
|
439
|
+
const { archetype, primary, maxDepth = 3, policy, reachability, toolOrchestration } = opts;
|
|
440
|
+
if (maxDepth < 1) {
|
|
441
|
+
throw new Error(
|
|
442
|
+
`getDefaultFallbackChain: maxDepth must be >= 1, got ${maxDepth}`
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
const allChains = loadChainsFromBrain();
|
|
446
|
+
const starter = resolveStarterForMode(archetype, toolOrchestration, allChains);
|
|
447
|
+
if (!starter) {
|
|
448
|
+
throw new Error(
|
|
449
|
+
`getDefaultFallbackChain: unknown archetype "${archetype}". Known: ${Object.keys(allChains).join(", ")}`
|
|
450
|
+
);
|
|
451
|
+
}
|
|
452
|
+
let chain;
|
|
453
|
+
if (primary) {
|
|
454
|
+
chain = [primary, ...starter.filter((id) => id !== primary)];
|
|
455
|
+
} else {
|
|
456
|
+
chain = [...starter];
|
|
457
|
+
}
|
|
458
|
+
if (policy?.blockedModels && policy.blockedModels.length > 0) {
|
|
459
|
+
const blocked = new Set(policy.blockedModels);
|
|
460
|
+
chain = chain.filter((id) => !blocked.has(id));
|
|
461
|
+
}
|
|
462
|
+
const seen = /* @__PURE__ */ new Set();
|
|
463
|
+
const deduped = [];
|
|
464
|
+
for (const id of chain) {
|
|
465
|
+
if (!seen.has(id)) {
|
|
466
|
+
seen.add(id);
|
|
467
|
+
deduped.push(id);
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
let filtered = deduped;
|
|
471
|
+
if (reachability) {
|
|
472
|
+
filtered = deduped.filter((id) => isModelReachable(id, reachability));
|
|
473
|
+
}
|
|
474
|
+
return filtered.slice(0, maxDepth);
|
|
475
|
+
}
|
|
476
|
+
function getStarterChain(archetype) {
|
|
477
|
+
const chain = STARTER_CHAINS[archetype];
|
|
478
|
+
if (!chain) {
|
|
479
|
+
throw new Error(
|
|
480
|
+
`getStarterChain: unknown archetype "${archetype}"`
|
|
481
|
+
);
|
|
482
|
+
}
|
|
483
|
+
return [...chain];
|
|
484
|
+
}
|
|
485
|
+
function getAllStarterChains() {
|
|
486
|
+
const out = {};
|
|
487
|
+
for (const [archetype, chain] of Object.entries(STARTER_CHAINS)) {
|
|
488
|
+
out[archetype] = [...chain];
|
|
489
|
+
}
|
|
490
|
+
return out;
|
|
491
|
+
}
|
|
492
|
+
function getSequentialStarterChain(archetype) {
|
|
493
|
+
const overlay = STARTER_CHAINS_BY_MODE[archetype]?.sequential;
|
|
494
|
+
return overlay ? [...overlay] : void 0;
|
|
495
|
+
}
|
|
496
|
+
function copyEntry(e) {
|
|
497
|
+
const out = { id: e.id, grounding: e.grounding };
|
|
498
|
+
if (e.reason !== void 0) out.reason = e.reason;
|
|
499
|
+
if (e.n !== void 0) out.n = e.n;
|
|
500
|
+
return out;
|
|
501
|
+
}
|
|
502
|
+
function lookupStaticEntry(id, archetype) {
|
|
503
|
+
const archetypeEntries = STARTER_CHAINS_GROUNDED[archetype];
|
|
504
|
+
if (archetypeEntries) {
|
|
505
|
+
const hit = archetypeEntries.find((e) => e.id === id);
|
|
506
|
+
if (hit) return hit;
|
|
507
|
+
}
|
|
508
|
+
const seqOverlay = STARTER_CHAINS_BY_MODE_GROUNDED[archetype]?.sequential;
|
|
509
|
+
if (seqOverlay) {
|
|
510
|
+
const hit = seqOverlay.find((e) => e.id === id);
|
|
511
|
+
if (hit) return hit;
|
|
512
|
+
}
|
|
513
|
+
return void 0;
|
|
514
|
+
}
|
|
515
|
+
function resolveGroundedChainForArchetype(archetype, toolOrchestration) {
|
|
516
|
+
if (toolOrchestration === "sequential") {
|
|
517
|
+
const overlay = STARTER_CHAINS_BY_MODE_GROUNDED[archetype]?.sequential;
|
|
518
|
+
if (overlay) return overlay.map(copyEntry);
|
|
519
|
+
}
|
|
520
|
+
const allChains = loadChainsFromBrain();
|
|
521
|
+
const ids = allChains[archetype];
|
|
522
|
+
if (!ids) return void 0;
|
|
523
|
+
return ids.map((id) => {
|
|
524
|
+
const known = lookupStaticEntry(id, archetype);
|
|
525
|
+
if (known) return copyEntry(known);
|
|
526
|
+
return { id, grounding: "judgment" };
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
function getDefaultFallbackChainWithGrounding(opts) {
|
|
530
|
+
const {
|
|
531
|
+
archetype,
|
|
532
|
+
primary,
|
|
533
|
+
maxDepth = 3,
|
|
534
|
+
policy,
|
|
535
|
+
reachability,
|
|
536
|
+
toolOrchestration
|
|
537
|
+
} = opts;
|
|
538
|
+
if (maxDepth < 1) {
|
|
539
|
+
throw new Error(
|
|
540
|
+
`getDefaultFallbackChainWithGrounding: maxDepth must be >= 1, got ${maxDepth}`
|
|
541
|
+
);
|
|
542
|
+
}
|
|
543
|
+
const starter = resolveGroundedChainForArchetype(archetype, toolOrchestration);
|
|
544
|
+
if (!starter) {
|
|
545
|
+
throw new Error(
|
|
546
|
+
`getDefaultFallbackChainWithGrounding: unknown archetype "${archetype}". Known: ${Object.keys(STARTER_CHAINS_GROUNDED).join(", ")}`
|
|
547
|
+
);
|
|
548
|
+
}
|
|
549
|
+
let chain;
|
|
550
|
+
if (primary) {
|
|
551
|
+
const primaryEntry = (() => {
|
|
552
|
+
const inStarter = starter.find((e) => e.id === primary);
|
|
553
|
+
if (inStarter) return copyEntry(inStarter);
|
|
554
|
+
const knownAnywhere = lookupStaticEntry(primary, archetype);
|
|
555
|
+
if (knownAnywhere) return { ...copyEntry(knownAnywhere), id: primary };
|
|
556
|
+
return { id: primary, grounding: "judgment" };
|
|
557
|
+
})();
|
|
558
|
+
chain = [primaryEntry, ...starter.filter((e) => e.id !== primary)];
|
|
559
|
+
} else {
|
|
560
|
+
chain = [...starter];
|
|
561
|
+
}
|
|
562
|
+
if (policy?.blockedModels && policy.blockedModels.length > 0) {
|
|
563
|
+
const blocked = new Set(policy.blockedModels);
|
|
564
|
+
chain = chain.filter((e) => !blocked.has(e.id));
|
|
565
|
+
}
|
|
566
|
+
const seen = /* @__PURE__ */ new Set();
|
|
567
|
+
const deduped = [];
|
|
568
|
+
for (const e of chain) {
|
|
569
|
+
if (!seen.has(e.id)) {
|
|
570
|
+
seen.add(e.id);
|
|
571
|
+
deduped.push(e);
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
let filtered = deduped;
|
|
575
|
+
if (reachability) {
|
|
576
|
+
filtered = deduped.filter((e) => isModelReachable(e.id, reachability));
|
|
577
|
+
}
|
|
578
|
+
return filtered.slice(0, maxDepth);
|
|
579
|
+
}
|
|
580
|
+
function getStarterChainWithGrounding(archetype) {
|
|
581
|
+
const entries = STARTER_CHAINS_GROUNDED[archetype];
|
|
582
|
+
if (!entries) {
|
|
583
|
+
throw new Error(
|
|
584
|
+
`getStarterChainWithGrounding: unknown archetype "${archetype}"`
|
|
585
|
+
);
|
|
586
|
+
}
|
|
587
|
+
return entries.map(copyEntry);
|
|
588
|
+
}
|
|
589
|
+
function getAllStarterChainsWithGrounding() {
|
|
590
|
+
const out = {};
|
|
591
|
+
for (const [archetype, entries] of Object.entries(STARTER_CHAINS_GROUNDED)) {
|
|
592
|
+
out[archetype] = entries.map(copyEntry);
|
|
593
|
+
}
|
|
594
|
+
return out;
|
|
595
|
+
}
|
|
596
|
+
function getSequentialStarterChainWithGrounding(archetype) {
|
|
597
|
+
const overlay = STARTER_CHAINS_BY_MODE_GROUNDED[archetype]?.sequential;
|
|
598
|
+
return overlay ? overlay.map(copyEntry) : void 0;
|
|
599
|
+
}
|
|
600
|
+
function ensureCrossProviderTail(opts) {
|
|
601
|
+
const { chain, archetype, apiKeys, envSource } = opts;
|
|
602
|
+
if (chain.length < 1) return { chain };
|
|
603
|
+
const providers = /* @__PURE__ */ new Set();
|
|
604
|
+
for (const t of chain) {
|
|
605
|
+
const p = tryGetProfile(t);
|
|
606
|
+
if (p) providers.add(p.provider);
|
|
607
|
+
}
|
|
608
|
+
if (providers.size >= 2) return { chain };
|
|
609
|
+
const existingProvider = providers.values().next().value;
|
|
610
|
+
if (!existingProvider) return { chain };
|
|
611
|
+
const allChains = loadChainsFromBrain();
|
|
612
|
+
const fullChain = allChains[archetype];
|
|
613
|
+
if (!fullChain) return { chain };
|
|
614
|
+
for (const candidate of fullChain) {
|
|
615
|
+
if (chain.includes(candidate)) continue;
|
|
616
|
+
const cp = tryGetProfile(candidate);
|
|
617
|
+
if (!cp || cp.provider === existingProvider) continue;
|
|
618
|
+
if (!isModelReachable(candidate, { apiKeys, envSource })) continue;
|
|
619
|
+
return { chain: [...chain, candidate], appended: candidate };
|
|
620
|
+
}
|
|
621
|
+
return { chain };
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
// src/chains-brain.ts
|
|
625
|
+
function isChainsRow(x) {
|
|
626
|
+
if (!x || typeof x !== "object") return false;
|
|
627
|
+
const r = x;
|
|
628
|
+
return typeof r.archetype === "string" && typeof r.tier === "number" && typeof r.model_id === "string";
|
|
629
|
+
}
|
|
630
|
+
function mapRowsToChains(rows) {
|
|
631
|
+
const grouped = /* @__PURE__ */ new Map();
|
|
632
|
+
for (const row of rows) {
|
|
633
|
+
if (!isChainsRow(row)) continue;
|
|
634
|
+
const list = grouped.get(row.archetype) ?? [];
|
|
635
|
+
list.push(row);
|
|
636
|
+
grouped.set(row.archetype, list);
|
|
637
|
+
}
|
|
638
|
+
const out = {};
|
|
639
|
+
for (const [archetype, group] of grouped.entries()) {
|
|
640
|
+
group.sort((a, b) => a.tier - b.tier);
|
|
641
|
+
out[archetype] = group.map((r) => r.model_id);
|
|
642
|
+
}
|
|
643
|
+
const bundled = getAllStarterChains();
|
|
644
|
+
for (const archetype of Object.keys(bundled)) {
|
|
645
|
+
if (!out[archetype]) out[archetype] = bundled[archetype];
|
|
646
|
+
}
|
|
647
|
+
return out;
|
|
648
|
+
}
|
|
649
|
+
var loadChainsFromBrain = createBrainQueryCache({
|
|
650
|
+
table: "kgauto_chains",
|
|
651
|
+
mapRows: mapRowsToChains,
|
|
652
|
+
bundledFallback: getAllStarterChains
|
|
653
|
+
});
|
|
654
|
+
|
|
655
|
+
export {
|
|
656
|
+
configureBrainQuery,
|
|
657
|
+
createBrainQueryCache,
|
|
658
|
+
isBrainQueryActiveFor,
|
|
659
|
+
getPerAxisMetrics,
|
|
660
|
+
ARCHETYPE_FLOOR_DEFAULT,
|
|
661
|
+
ABSOLUTE_FLOOR,
|
|
662
|
+
getModelCompatibility,
|
|
663
|
+
PROVIDER_ENV_KEYS,
|
|
664
|
+
resolveProviderKey,
|
|
665
|
+
isProviderReachable,
|
|
666
|
+
isModelReachable,
|
|
667
|
+
getReachabilityDiagnostic,
|
|
668
|
+
loadChainsFromBrain,
|
|
669
|
+
getDefaultFallbackChain,
|
|
670
|
+
getStarterChain,
|
|
671
|
+
getAllStarterChains,
|
|
672
|
+
getSequentialStarterChain,
|
|
673
|
+
getDefaultFallbackChainWithGrounding,
|
|
674
|
+
getStarterChainWithGrounding,
|
|
675
|
+
getAllStarterChainsWithGrounding,
|
|
676
|
+
getSequentialStarterChainWithGrounding,
|
|
677
|
+
ensureCrossProviderTail
|
|
678
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { G as GlassboxEvent } from '../types-
|
|
2
|
-
export { A as AdvisoryFiredData, C as CompileDoneData, a as CompileStartData, E as ExecuteAttemptData, b as ExecuteSuccessData, F as FallbackWalkedData, c as GLASSBOX_STREAM_TTL_MS, d as GlassboxEventKind, e as GlassboxPubSub } from '../types-
|
|
3
|
-
import '../ir-
|
|
1
|
+
import { G as GlassboxEvent } from '../types-sDZQzPM6.mjs';
|
|
2
|
+
export { A as AdvisoryFiredData, C as CompileDoneData, a as CompileStartData, E as ExecuteAttemptData, b as ExecuteSuccessData, F as FallbackWalkedData, c as GLASSBOX_STREAM_TTL_MS, d as GlassboxEventKind, e as GlassboxPubSub } from '../types-sDZQzPM6.mjs';
|
|
3
|
+
import '../ir-MXCJA8L7.mjs';
|
|
4
4
|
import '../dialect.mjs';
|
|
5
5
|
|
|
6
6
|
/**
|
package/dist/glassbox/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { G as GlassboxEvent } from '../types-
|
|
2
|
-
export { A as AdvisoryFiredData, C as CompileDoneData, a as CompileStartData, E as ExecuteAttemptData, b as ExecuteSuccessData, F as FallbackWalkedData, c as GLASSBOX_STREAM_TTL_MS, d as GlassboxEventKind, e as GlassboxPubSub } from '../types-
|
|
3
|
-
import '../ir-
|
|
1
|
+
import { G as GlassboxEvent } from '../types-CiZ9HLIU.js';
|
|
2
|
+
export { A as AdvisoryFiredData, C as CompileDoneData, a as CompileStartData, E as ExecuteAttemptData, b as ExecuteSuccessData, F as FallbackWalkedData, c as GLASSBOX_STREAM_TTL_MS, d as GlassboxEventKind, e as GlassboxPubSub } from '../types-CiZ9HLIU.js';
|
|
3
|
+
import '../ir-5W0efxt9.js';
|
|
4
4
|
import '../dialect.js';
|
|
5
5
|
|
|
6
6
|
/**
|