@warmdrift/kgauto-compiler 2.0.0-alpha.91 → 2.0.0-alpha.92
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-54IXD5BT.mjs → chunk-4G73BYES.mjs} +7 -2
- package/dist/{chunk-BVEXV5KC.mjs → chunk-FEMPY6EC.mjs} +5 -1
- package/dist/{chunk-AUZTO6Q5.mjs → chunk-QOQV66PU.mjs} +1 -1
- package/dist/dialect.d.mts +11 -1
- package/dist/dialect.d.ts +11 -1
- package/dist/dialect.js +7 -2
- package/dist/dialect.mjs +5 -3
- package/dist/glassbox/index.d.mts +3 -3
- package/dist/glassbox/index.d.ts +3 -3
- package/dist/glassbox-routes/format.d.mts +2 -2
- package/dist/glassbox-routes/format.d.ts +2 -2
- package/dist/glassbox-routes/index.d.mts +4 -4
- package/dist/glassbox-routes/index.d.ts +4 -4
- package/dist/glassbox-routes/index.js +7 -2
- package/dist/glassbox-routes/index.mjs +1 -1
- package/dist/glassbox-routes/react/index.d.mts +2 -2
- package/dist/glassbox-routes/react/index.d.ts +2 -2
- package/dist/index.d.mts +15 -4
- package/dist/index.d.ts +15 -4
- package/dist/index.js +89 -11
- package/dist/index.mjs +83 -12
- package/dist/{ir-DeYMLWge.d.mts → ir-BPYh68mv.d.mts} +95 -1
- package/dist/{ir-CTx026t0.d.ts → ir-BWnE6LaB.d.ts} +95 -1
- package/dist/key-health.js +1 -1
- package/dist/key-health.mjs +1 -1
- package/dist/profiles.d.mts +1 -1
- package/dist/profiles.d.ts +1 -1
- package/dist/{types-Cp9ot1HV.d.ts → types-BCHv34P7.d.ts} +1 -1
- package/dist/{types-cBzinzUR.d.mts → types-BgvLmT3s.d.mts} +1 -1
- package/dist/{types-BKbRtmUb.d.ts → types-BhxC4hdx.d.ts} +1 -1
- package/dist/{types-DD36cCbZ.d.mts → types-eLelJBj-.d.mts} +1 -1
- package/package.json +1 -1
|
@@ -322,7 +322,8 @@ var SUPPORTED_PROVIDERS = Object.freeze([
|
|
|
322
322
|
"openai",
|
|
323
323
|
"deepseek",
|
|
324
324
|
"zai",
|
|
325
|
-
"moonshot"
|
|
325
|
+
"moonshot",
|
|
326
|
+
"openrouter"
|
|
326
327
|
]);
|
|
327
328
|
function isSupportedProvider(p) {
|
|
328
329
|
return SUPPORTED_PROVIDERS.includes(p);
|
|
@@ -343,7 +344,11 @@ var PROVIDER_ENV_KEYS = Object.freeze({
|
|
|
343
344
|
// alpha.65 — Moonshot AI (Kimi family). MOONSHOT_API_KEY is canonical
|
|
344
345
|
// (api.moonshot.ai); KIMI_API_KEY covers the platform.kimi.ai rebrand
|
|
345
346
|
// surface so consumers keyed under either name resolve.
|
|
346
|
-
moonshot: Object.freeze(["MOONSHOT_API_KEY", "KIMI_API_KEY"])
|
|
347
|
+
moonshot: Object.freeze(["MOONSHOT_API_KEY", "KIMI_API_KEY"]),
|
|
348
|
+
// alpha.92 — the OpenRouter gateway route (execute-leg contract). This is
|
|
349
|
+
// a ROUTE key, not a vendor key: it never makes a vendor "reachable" for
|
|
350
|
+
// chain composition — only explicit `route: 'openrouter'` calls use it.
|
|
351
|
+
openrouter: Object.freeze(["OPENROUTER_API_KEY"])
|
|
347
352
|
});
|
|
348
353
|
function defaultEnv() {
|
|
349
354
|
return typeof process !== "undefined" && process.env ? process.env : {};
|
|
@@ -91,6 +91,9 @@ function hashShape(s) {
|
|
|
91
91
|
function learningKey(archetype, model, shape) {
|
|
92
92
|
return `${DIALECT_VERSION}::${archetype}::${model}::${hashShape(shape)}`;
|
|
93
93
|
}
|
|
94
|
+
function routeScopedModel(model, route) {
|
|
95
|
+
return route === "openrouter" ? `${model}@openrouter` : model;
|
|
96
|
+
}
|
|
94
97
|
|
|
95
98
|
export {
|
|
96
99
|
DIALECT_VERSION,
|
|
@@ -102,5 +105,6 @@ export {
|
|
|
102
105
|
bucketToolCount,
|
|
103
106
|
bucketHistory,
|
|
104
107
|
hashShape,
|
|
105
|
-
learningKey
|
|
108
|
+
learningKey,
|
|
109
|
+
routeScopedModel
|
|
106
110
|
};
|
package/dist/dialect.d.mts
CHANGED
|
@@ -133,5 +133,15 @@ declare function hashShape(s: ShapeSignature): string;
|
|
|
133
133
|
* any app can produce and any app can benefit from.
|
|
134
134
|
*/
|
|
135
135
|
declare function learningKey(archetype: IntentArchetypeName, model: string, shape: ShapeSignature): string;
|
|
136
|
+
/**
|
|
137
|
+
* alpha.92 — the model segment of a learning key, route-scoped. A route is
|
|
138
|
+
* part of a measurement's identity (execute-leg contract): the same model id
|
|
139
|
+
* through a gateway is a different serving stack per host, so non-direct
|
|
140
|
+
* evidence carries the route dimension (`model@openrouter`) and can never
|
|
141
|
+
* pollute direct-vendor evidence. ONE derivation, used by compile() and
|
|
142
|
+
* registerCompile() both — two inline encodings of one concept is the s75
|
|
143
|
+
* drift shape.
|
|
144
|
+
*/
|
|
145
|
+
declare function routeScopedModel(model: string, route?: 'direct' | 'openrouter'): string;
|
|
136
146
|
|
|
137
|
-
export { ALL_ARCHETYPES, type ContextBucket, DIALECT_VERSION, type HistoryDepth, INTENT_ARCHETYPES, type IntentArchetypeName, type OutputMode, type ShapeSignature, type ToolCountBucket, bucketContext, bucketHistory, bucketToolCount, hashShape, isArchetype, learningKey, resolveOutputMode };
|
|
147
|
+
export { ALL_ARCHETYPES, type ContextBucket, DIALECT_VERSION, type HistoryDepth, INTENT_ARCHETYPES, type IntentArchetypeName, type OutputMode, type ShapeSignature, type ToolCountBucket, bucketContext, bucketHistory, bucketToolCount, hashShape, isArchetype, learningKey, resolveOutputMode, routeScopedModel };
|
package/dist/dialect.d.ts
CHANGED
|
@@ -133,5 +133,15 @@ declare function hashShape(s: ShapeSignature): string;
|
|
|
133
133
|
* any app can produce and any app can benefit from.
|
|
134
134
|
*/
|
|
135
135
|
declare function learningKey(archetype: IntentArchetypeName, model: string, shape: ShapeSignature): string;
|
|
136
|
+
/**
|
|
137
|
+
* alpha.92 — the model segment of a learning key, route-scoped. A route is
|
|
138
|
+
* part of a measurement's identity (execute-leg contract): the same model id
|
|
139
|
+
* through a gateway is a different serving stack per host, so non-direct
|
|
140
|
+
* evidence carries the route dimension (`model@openrouter`) and can never
|
|
141
|
+
* pollute direct-vendor evidence. ONE derivation, used by compile() and
|
|
142
|
+
* registerCompile() both — two inline encodings of one concept is the s75
|
|
143
|
+
* drift shape.
|
|
144
|
+
*/
|
|
145
|
+
declare function routeScopedModel(model: string, route?: 'direct' | 'openrouter'): string;
|
|
136
146
|
|
|
137
|
-
export { ALL_ARCHETYPES, type ContextBucket, DIALECT_VERSION, type HistoryDepth, INTENT_ARCHETYPES, type IntentArchetypeName, type OutputMode, type ShapeSignature, type ToolCountBucket, bucketContext, bucketHistory, bucketToolCount, hashShape, isArchetype, learningKey, resolveOutputMode };
|
|
147
|
+
export { ALL_ARCHETYPES, type ContextBucket, DIALECT_VERSION, type HistoryDepth, INTENT_ARCHETYPES, type IntentArchetypeName, type OutputMode, type ShapeSignature, type ToolCountBucket, bucketContext, bucketHistory, bucketToolCount, hashShape, isArchetype, learningKey, resolveOutputMode, routeScopedModel };
|
package/dist/dialect.js
CHANGED
|
@@ -29,7 +29,8 @@ __export(dialect_exports, {
|
|
|
29
29
|
hashShape: () => hashShape,
|
|
30
30
|
isArchetype: () => isArchetype,
|
|
31
31
|
learningKey: () => learningKey,
|
|
32
|
-
resolveOutputMode: () => resolveOutputMode
|
|
32
|
+
resolveOutputMode: () => resolveOutputMode,
|
|
33
|
+
routeScopedModel: () => routeScopedModel
|
|
33
34
|
});
|
|
34
35
|
module.exports = __toCommonJS(dialect_exports);
|
|
35
36
|
var DIALECT_VERSION = "v1";
|
|
@@ -124,6 +125,9 @@ function hashShape(s) {
|
|
|
124
125
|
function learningKey(archetype, model, shape) {
|
|
125
126
|
return `${DIALECT_VERSION}::${archetype}::${model}::${hashShape(shape)}`;
|
|
126
127
|
}
|
|
128
|
+
function routeScopedModel(model, route) {
|
|
129
|
+
return route === "openrouter" ? `${model}@openrouter` : model;
|
|
130
|
+
}
|
|
127
131
|
// Annotate the CommonJS export names for ESM import in node:
|
|
128
132
|
0 && (module.exports = {
|
|
129
133
|
ALL_ARCHETYPES,
|
|
@@ -135,5 +139,6 @@ function learningKey(archetype, model, shape) {
|
|
|
135
139
|
hashShape,
|
|
136
140
|
isArchetype,
|
|
137
141
|
learningKey,
|
|
138
|
-
resolveOutputMode
|
|
142
|
+
resolveOutputMode,
|
|
143
|
+
routeScopedModel
|
|
139
144
|
});
|
package/dist/dialect.mjs
CHANGED
|
@@ -8,8 +8,9 @@ import {
|
|
|
8
8
|
hashShape,
|
|
9
9
|
isArchetype,
|
|
10
10
|
learningKey,
|
|
11
|
-
resolveOutputMode
|
|
12
|
-
|
|
11
|
+
resolveOutputMode,
|
|
12
|
+
routeScopedModel
|
|
13
|
+
} from "./chunk-FEMPY6EC.mjs";
|
|
13
14
|
export {
|
|
14
15
|
ALL_ARCHETYPES,
|
|
15
16
|
DIALECT_VERSION,
|
|
@@ -20,5 +21,6 @@ export {
|
|
|
20
21
|
hashShape,
|
|
21
22
|
isArchetype,
|
|
22
23
|
learningKey,
|
|
23
|
-
resolveOutputMode
|
|
24
|
+
resolveOutputMode,
|
|
25
|
+
routeScopedModel
|
|
24
26
|
};
|
|
@@ -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-BgvLmT3s.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-BgvLmT3s.mjs';
|
|
3
|
+
import '../ir-BPYh68mv.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-BhxC4hdx.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-BhxC4hdx.js';
|
|
3
|
+
import '../ir-BWnE6LaB.js';
|
|
4
4
|
import '../dialect.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { G as GlassboxEvent } from '../types-
|
|
2
|
-
import { a as TraceDetail, b as TraceSummary, c as TraceCounterfactual } from '../types-
|
|
3
|
-
export { A as AdvisoryRecord, T as TraceHealth, d as TraceSectionRewrite } from '../types-
|
|
4
|
-
import '../ir-
|
|
1
|
+
import { G as GlassboxEvent } from '../types-BgvLmT3s.mjs';
|
|
2
|
+
import { a as TraceDetail, b as TraceSummary, c as TraceCounterfactual } from '../types-eLelJBj-.mjs';
|
|
3
|
+
export { A as AdvisoryRecord, T as TraceHealth, d as TraceSectionRewrite } from '../types-eLelJBj-.mjs';
|
|
4
|
+
import '../ir-BPYh68mv.mjs';
|
|
5
5
|
import '../dialect.mjs';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { G as GlassboxEvent } from '../types-
|
|
2
|
-
import { a as TraceDetail, b as TraceSummary, c as TraceCounterfactual } from '../types-
|
|
3
|
-
export { A as AdvisoryRecord, T as TraceHealth, d as TraceSectionRewrite } from '../types-
|
|
4
|
-
import '../ir-
|
|
1
|
+
import { G as GlassboxEvent } from '../types-BhxC4hdx.js';
|
|
2
|
+
import { a as TraceDetail, b as TraceSummary, c as TraceCounterfactual } from '../types-BCHv34P7.js';
|
|
3
|
+
export { A as AdvisoryRecord, T as TraceHealth, d as TraceSectionRewrite } from '../types-BCHv34P7.js';
|
|
4
|
+
import '../ir-BWnE6LaB.js';
|
|
5
5
|
import '../dialect.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -1979,7 +1979,8 @@ var SUPPORTED_PROVIDERS = Object.freeze([
|
|
|
1979
1979
|
"openai",
|
|
1980
1980
|
"deepseek",
|
|
1981
1981
|
"zai",
|
|
1982
|
-
"moonshot"
|
|
1982
|
+
"moonshot",
|
|
1983
|
+
"openrouter"
|
|
1983
1984
|
]);
|
|
1984
1985
|
function isSupportedProvider(p) {
|
|
1985
1986
|
return SUPPORTED_PROVIDERS.includes(p);
|
|
@@ -2000,7 +2001,11 @@ var PROVIDER_ENV_KEYS = Object.freeze({
|
|
|
2000
2001
|
// alpha.65 — Moonshot AI (Kimi family). MOONSHOT_API_KEY is canonical
|
|
2001
2002
|
// (api.moonshot.ai); KIMI_API_KEY covers the platform.kimi.ai rebrand
|
|
2002
2003
|
// surface so consumers keyed under either name resolve.
|
|
2003
|
-
moonshot: Object.freeze(["MOONSHOT_API_KEY", "KIMI_API_KEY"])
|
|
2004
|
+
moonshot: Object.freeze(["MOONSHOT_API_KEY", "KIMI_API_KEY"]),
|
|
2005
|
+
// alpha.92 — the OpenRouter gateway route (execute-leg contract). This is
|
|
2006
|
+
// a ROUTE key, not a vendor key: it never makes a vendor "reachable" for
|
|
2007
|
+
// chain composition — only explicit `route: 'openrouter'` calls use it.
|
|
2008
|
+
openrouter: Object.freeze(["OPENROUTER_API_KEY"])
|
|
2004
2009
|
});
|
|
2005
2010
|
function defaultEnv() {
|
|
2006
2011
|
return typeof process !== "undefined" && process.env ? process.env : {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { a as TraceDetail } from '../../types-
|
|
3
|
-
import '../../ir-
|
|
2
|
+
import { a as TraceDetail } from '../../types-eLelJBj-.mjs';
|
|
3
|
+
import '../../ir-BPYh68mv.mjs';
|
|
4
4
|
import '../../dialect.mjs';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
|
-
import { a as TraceDetail } from '../../types-
|
|
3
|
-
import '../../ir-
|
|
2
|
+
import { a as TraceDetail } from '../../types-BCHv34P7.js';
|
|
3
|
+
import '../../ir-BWnE6LaB.js';
|
|
4
4
|
import '../../dialect.js';
|
|
5
5
|
|
|
6
6
|
/**
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CompilePolicy, N as NormalizedResponse, A as ApiKeys, P as ProviderOverrides, a as CompiledRequest, b as PromptIR, c as CallOptions, d as CallResult, S as SystemModelMessage, e as CompileResult, B as BestPracticeAdvisory, F as FallbackReason, f as SectionRewrite, R as RecordInput, g as RecordOutcomeInput, O as OutcomeResult, h as OutcomeSource, i as OracleScore, j as Adapter, k as PerAxisMetrics, l as Provider, m as ChainEntry, G as Grounding } from './ir-
|
|
2
|
-
export { n as CallAttempt, o as CallError, p as ChainModelEntry, q as ChainWithGrounding, r as Constraints, E as EffortLevel, s as GoldenCaptureOptions, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, t as MutationApplied, u as NormalizedTokens, v as OutcomeKind, w as PerAxisMetricsByModel, x as PromptSection, y as SectionKind, z as ShadowProbeConfig, T as ToolCall, D as ToolDefinition, J as captureGoldenIr, K as hasMutation, L as mutationId, Q as parseGoldenCaptureRate, U as resolveGoldenCaptureRate, V as shouldCaptureGolden } from './ir-
|
|
1
|
+
import { C as CompilePolicy, N as NormalizedResponse, A as ApiKeys, P as ProviderOverrides, a as CompiledRequest, b as PromptIR, c as CallOptions, d as CallResult, S as SystemModelMessage, e as CompileResult, B as BestPracticeAdvisory, F as FallbackReason, f as SectionRewrite, R as RecordInput, g as RecordOutcomeInput, O as OutcomeResult, h as OutcomeSource, i as OracleScore, j as Adapter, k as PerAxisMetrics, l as Provider, m as ChainEntry, G as Grounding } from './ir-BPYh68mv.mjs';
|
|
2
|
+
export { n as CallAttempt, o as CallError, p as ChainModelEntry, q as ChainWithGrounding, r as Constraints, E as EffortLevel, s as GoldenCaptureOptions, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, t as MutationApplied, u as NormalizedTokens, v as OutcomeKind, w as PerAxisMetricsByModel, x as PromptSection, y as SectionKind, z as ShadowProbeConfig, T as ToolCall, D as ToolDefinition, J as captureGoldenIr, K as hasMutation, L as mutationId, Q as parseGoldenCaptureRate, U as resolveGoldenCaptureRate, V as shouldCaptureGolden } from './ir-BPYh68mv.mjs';
|
|
3
3
|
import { ModelProfile, ArchetypeConvention } from './profiles.mjs';
|
|
4
4
|
export { ALIASES, CacheStrategy, CliffRule, LATENCY_TIER_MS, LatencyTier, LoweringSpec, RecoveryRule, StructuredOutputCapability, SystemPromptMode, _testClearConsumerProfiles, allProfiles, bestEffortProfile, getProfile, inferProviderFromId, latencyTierOf, profilesByProvider, registerProfiles, resolveModelAlias, tryGetProfile } from './profiles.mjs';
|
|
5
5
|
export { BrainForwardConfig, BrainForwardRoutes, createBrainForwardRoutes } from './brain-proxy.mjs';
|
|
@@ -47,6 +47,13 @@ interface CompileOptions {
|
|
|
47
47
|
* time. `registerCompile` reads it to derive the linkage. Absent ⇒ root call.
|
|
48
48
|
*/
|
|
49
49
|
parentHandle?: string;
|
|
50
|
+
/**
|
|
51
|
+
* alpha.92 — lower for a gateway route (execute-leg contract). Threaded
|
|
52
|
+
* from `CallOptions.route`. The canonical profile drives every pass
|
|
53
|
+
* (cliffs, scoring, budgets) unchanged; only the wire destination and the
|
|
54
|
+
* learning-key encoding change. Absent ⇒ direct vendor wire.
|
|
55
|
+
*/
|
|
56
|
+
route?: 'direct' | 'openrouter';
|
|
50
57
|
}
|
|
51
58
|
|
|
52
59
|
/**
|
|
@@ -666,6 +673,10 @@ interface OutcomePayload {
|
|
|
666
673
|
provider?: string;
|
|
667
674
|
shape_key?: string;
|
|
668
675
|
learning_key?: string;
|
|
676
|
+
/** alpha.92 (migration 067) — route identity: 'direct' | 'openrouter'. */
|
|
677
|
+
route?: string;
|
|
678
|
+
/** alpha.92 — gateway-reported serving host (OpenRouter `provider` field). */
|
|
679
|
+
route_host?: string;
|
|
669
680
|
mutations_applied: string[];
|
|
670
681
|
tokens_in: number;
|
|
671
682
|
tokens_out: number;
|
|
@@ -1270,7 +1281,7 @@ declare function runStrategyEvalWithAttribution(opts: Omit<GoldenEvalOptions, 'a
|
|
|
1270
1281
|
* guard in `tests/version.test.ts` fails the suite (and therefore
|
|
1271
1282
|
* `prepublishOnly`) when they diverge — a stale constant cannot reach npm.
|
|
1272
1283
|
*/
|
|
1273
|
-
declare const LIBRARY_VERSION = "2.0.0-alpha.
|
|
1284
|
+
declare const LIBRARY_VERSION = "2.0.0-alpha.92";
|
|
1274
1285
|
|
|
1275
1286
|
/**
|
|
1276
1287
|
* Oracle contract — how an app tells the brain whether a response was good.
|
|
@@ -2668,7 +2679,7 @@ declare function getPerAxisMetrics(opts: GetPerAxisMetricsOpts): Promise<PerAxis
|
|
|
2668
2679
|
* no execute() handler, no env-var convention). Narrowing here keeps the
|
|
2669
2680
|
* reachability check structurally honest.
|
|
2670
2681
|
*/
|
|
2671
|
-
type SupportedProvider = 'anthropic' | 'google' | 'openai' | 'deepseek' | 'zai' | 'moonshot';
|
|
2682
|
+
type SupportedProvider = 'anthropic' | 'google' | 'openai' | 'deepseek' | 'zai' | 'moonshot' | 'openrouter';
|
|
2672
2683
|
/**
|
|
2673
2684
|
* Per-provider env var names kgauto recognizes. Order doesn't matter —
|
|
2674
2685
|
* first-present wins. Multiple names per provider supported because Google
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { C as CompilePolicy, N as NormalizedResponse, A as ApiKeys, P as ProviderOverrides, a as CompiledRequest, b as PromptIR, c as CallOptions, d as CallResult, S as SystemModelMessage, e as CompileResult, B as BestPracticeAdvisory, F as FallbackReason, f as SectionRewrite, R as RecordInput, g as RecordOutcomeInput, O as OutcomeResult, h as OutcomeSource, i as OracleScore, j as Adapter, k as PerAxisMetrics, l as Provider, m as ChainEntry, G as Grounding } from './ir-
|
|
2
|
-
export { n as CallAttempt, o as CallError, p as ChainModelEntry, q as ChainWithGrounding, r as Constraints, E as EffortLevel, s as GoldenCaptureOptions, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, t as MutationApplied, u as NormalizedTokens, v as OutcomeKind, w as PerAxisMetricsByModel, x as PromptSection, y as SectionKind, z as ShadowProbeConfig, T as ToolCall, D as ToolDefinition, J as captureGoldenIr, K as hasMutation, L as mutationId, Q as parseGoldenCaptureRate, U as resolveGoldenCaptureRate, V as shouldCaptureGolden } from './ir-
|
|
1
|
+
import { C as CompilePolicy, N as NormalizedResponse, A as ApiKeys, P as ProviderOverrides, a as CompiledRequest, b as PromptIR, c as CallOptions, d as CallResult, S as SystemModelMessage, e as CompileResult, B as BestPracticeAdvisory, F as FallbackReason, f as SectionRewrite, R as RecordInput, g as RecordOutcomeInput, O as OutcomeResult, h as OutcomeSource, i as OracleScore, j as Adapter, k as PerAxisMetrics, l as Provider, m as ChainEntry, G as Grounding } from './ir-BWnE6LaB.js';
|
|
2
|
+
export { n as CallAttempt, o as CallError, p as ChainModelEntry, q as ChainWithGrounding, r as Constraints, E as EffortLevel, s as GoldenCaptureOptions, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, t as MutationApplied, u as NormalizedTokens, v as OutcomeKind, w as PerAxisMetricsByModel, x as PromptSection, y as SectionKind, z as ShadowProbeConfig, T as ToolCall, D as ToolDefinition, J as captureGoldenIr, K as hasMutation, L as mutationId, Q as parseGoldenCaptureRate, U as resolveGoldenCaptureRate, V as shouldCaptureGolden } from './ir-BWnE6LaB.js';
|
|
3
3
|
import { ModelProfile, ArchetypeConvention } from './profiles.js';
|
|
4
4
|
export { ALIASES, CacheStrategy, CliffRule, LATENCY_TIER_MS, LatencyTier, LoweringSpec, RecoveryRule, StructuredOutputCapability, SystemPromptMode, _testClearConsumerProfiles, allProfiles, bestEffortProfile, getProfile, inferProviderFromId, latencyTierOf, profilesByProvider, registerProfiles, resolveModelAlias, tryGetProfile } from './profiles.js';
|
|
5
5
|
export { BrainForwardConfig, BrainForwardRoutes, createBrainForwardRoutes } from './brain-proxy.js';
|
|
@@ -47,6 +47,13 @@ interface CompileOptions {
|
|
|
47
47
|
* time. `registerCompile` reads it to derive the linkage. Absent ⇒ root call.
|
|
48
48
|
*/
|
|
49
49
|
parentHandle?: string;
|
|
50
|
+
/**
|
|
51
|
+
* alpha.92 — lower for a gateway route (execute-leg contract). Threaded
|
|
52
|
+
* from `CallOptions.route`. The canonical profile drives every pass
|
|
53
|
+
* (cliffs, scoring, budgets) unchanged; only the wire destination and the
|
|
54
|
+
* learning-key encoding change. Absent ⇒ direct vendor wire.
|
|
55
|
+
*/
|
|
56
|
+
route?: 'direct' | 'openrouter';
|
|
50
57
|
}
|
|
51
58
|
|
|
52
59
|
/**
|
|
@@ -666,6 +673,10 @@ interface OutcomePayload {
|
|
|
666
673
|
provider?: string;
|
|
667
674
|
shape_key?: string;
|
|
668
675
|
learning_key?: string;
|
|
676
|
+
/** alpha.92 (migration 067) — route identity: 'direct' | 'openrouter'. */
|
|
677
|
+
route?: string;
|
|
678
|
+
/** alpha.92 — gateway-reported serving host (OpenRouter `provider` field). */
|
|
679
|
+
route_host?: string;
|
|
669
680
|
mutations_applied: string[];
|
|
670
681
|
tokens_in: number;
|
|
671
682
|
tokens_out: number;
|
|
@@ -1270,7 +1281,7 @@ declare function runStrategyEvalWithAttribution(opts: Omit<GoldenEvalOptions, 'a
|
|
|
1270
1281
|
* guard in `tests/version.test.ts` fails the suite (and therefore
|
|
1271
1282
|
* `prepublishOnly`) when they diverge — a stale constant cannot reach npm.
|
|
1272
1283
|
*/
|
|
1273
|
-
declare const LIBRARY_VERSION = "2.0.0-alpha.
|
|
1284
|
+
declare const LIBRARY_VERSION = "2.0.0-alpha.92";
|
|
1274
1285
|
|
|
1275
1286
|
/**
|
|
1276
1287
|
* Oracle contract — how an app tells the brain whether a response was good.
|
|
@@ -2668,7 +2679,7 @@ declare function getPerAxisMetrics(opts: GetPerAxisMetricsOpts): Promise<PerAxis
|
|
|
2668
2679
|
* no execute() handler, no env-var convention). Narrowing here keeps the
|
|
2669
2680
|
* reachability check structurally honest.
|
|
2670
2681
|
*/
|
|
2671
|
-
type SupportedProvider = 'anthropic' | 'google' | 'openai' | 'deepseek' | 'zai' | 'moonshot';
|
|
2682
|
+
type SupportedProvider = 'anthropic' | 'google' | 'openai' | 'deepseek' | 'zai' | 'moonshot' | 'openrouter';
|
|
2672
2683
|
/**
|
|
2673
2684
|
* Per-provider env var names kgauto recognizes. Order doesn't matter —
|
|
2674
2685
|
* first-present wins. Multiple names per provider supported because Google
|
package/dist/index.js
CHANGED
|
@@ -2977,6 +2977,9 @@ function hashShape(s) {
|
|
|
2977
2977
|
function learningKey(archetype, model, shape) {
|
|
2978
2978
|
return `${DIALECT_VERSION}::${archetype}::${model}::${hashShape(shape)}`;
|
|
2979
2979
|
}
|
|
2980
|
+
function routeScopedModel(model, route) {
|
|
2981
|
+
return route === "openrouter" ? `${model}@openrouter` : model;
|
|
2982
|
+
}
|
|
2980
2983
|
|
|
2981
2984
|
// src/passes.ts
|
|
2982
2985
|
function passSlice(ir) {
|
|
@@ -3634,7 +3637,26 @@ function passApplyConventions(ir, profile) {
|
|
|
3634
3637
|
}
|
|
3635
3638
|
|
|
3636
3639
|
// src/lower.ts
|
|
3640
|
+
var OPENROUTER_VENDOR_SLUG = {
|
|
3641
|
+
anthropic: "anthropic",
|
|
3642
|
+
google: "google",
|
|
3643
|
+
openai: "openai",
|
|
3644
|
+
deepseek: "deepseek",
|
|
3645
|
+
zai: "z-ai",
|
|
3646
|
+
moonshot: "moonshotai"
|
|
3647
|
+
};
|
|
3648
|
+
var OPENROUTER_ID_OVERRIDES = Object.freeze({});
|
|
3649
|
+
function openRouterModelId(profile) {
|
|
3650
|
+
const override = OPENROUTER_ID_OVERRIDES[profile.id];
|
|
3651
|
+
if (override) return override;
|
|
3652
|
+
const slug = OPENROUTER_VENDOR_SLUG[profile.provider];
|
|
3653
|
+
if (!slug) throw new Error(`No OpenRouter vendor slug for provider ${profile.provider} (model ${profile.id})`);
|
|
3654
|
+
return `${slug}/${profile.id}`;
|
|
3655
|
+
}
|
|
3637
3656
|
function lower(ir, profile, hints = {}) {
|
|
3657
|
+
if (hints.route === "openrouter") {
|
|
3658
|
+
return lowerOpenRouter(ir, profile);
|
|
3659
|
+
}
|
|
3638
3660
|
switch (profile.provider) {
|
|
3639
3661
|
case "anthropic":
|
|
3640
3662
|
return lowerAnthropic(ir, profile, hints);
|
|
@@ -3987,6 +4009,23 @@ function lowerZai(ir, profile, hints) {
|
|
|
3987
4009
|
}
|
|
3988
4010
|
};
|
|
3989
4011
|
}
|
|
4012
|
+
function lowerOpenRouter(ir, profile) {
|
|
4013
|
+
const parts = buildOpenAICompatibleParts(ir);
|
|
4014
|
+
return {
|
|
4015
|
+
request: {
|
|
4016
|
+
provider: "openrouter",
|
|
4017
|
+
model: openRouterModelId(profile),
|
|
4018
|
+
messages: parts.messages,
|
|
4019
|
+
tools: parts.tools,
|
|
4020
|
+
response_format: parts.response_format
|
|
4021
|
+
},
|
|
4022
|
+
diagnostics: {
|
|
4023
|
+
cacheableTokens: 0,
|
|
4024
|
+
historyCacheableTokens: parts.historyCacheableTokens,
|
|
4025
|
+
estimatedCacheSavingsUsd: 0
|
|
4026
|
+
}
|
|
4027
|
+
};
|
|
4028
|
+
}
|
|
3990
4029
|
function lowerMoonshot(ir, profile) {
|
|
3991
4030
|
const parts = buildOpenAICompatibleParts(ir);
|
|
3992
4031
|
return {
|
|
@@ -4088,7 +4127,8 @@ var SUPPORTED_PROVIDERS = Object.freeze([
|
|
|
4088
4127
|
"openai",
|
|
4089
4128
|
"deepseek",
|
|
4090
4129
|
"zai",
|
|
4091
|
-
"moonshot"
|
|
4130
|
+
"moonshot",
|
|
4131
|
+
"openrouter"
|
|
4092
4132
|
]);
|
|
4093
4133
|
function isSupportedProvider(p) {
|
|
4094
4134
|
return SUPPORTED_PROVIDERS.includes(p);
|
|
@@ -4109,7 +4149,11 @@ var PROVIDER_ENV_KEYS = Object.freeze({
|
|
|
4109
4149
|
// alpha.65 — Moonshot AI (Kimi family). MOONSHOT_API_KEY is canonical
|
|
4110
4150
|
// (api.moonshot.ai); KIMI_API_KEY covers the platform.kimi.ai rebrand
|
|
4111
4151
|
// surface so consumers keyed under either name resolve.
|
|
4112
|
-
moonshot: Object.freeze(["MOONSHOT_API_KEY", "KIMI_API_KEY"])
|
|
4152
|
+
moonshot: Object.freeze(["MOONSHOT_API_KEY", "KIMI_API_KEY"]),
|
|
4153
|
+
// alpha.92 — the OpenRouter gateway route (execute-leg contract). This is
|
|
4154
|
+
// a ROUTE key, not a vendor key: it never makes a vendor "reachable" for
|
|
4155
|
+
// chain composition — only explicit `route: 'openrouter'` calls use it.
|
|
4156
|
+
openrouter: Object.freeze(["OPENROUTER_API_KEY"])
|
|
4113
4157
|
});
|
|
4114
4158
|
function defaultEnv() {
|
|
4115
4159
|
return typeof process !== "undefined" && process.env ? process.env : {};
|
|
@@ -6187,12 +6231,13 @@ function compile(ir, opts = {}) {
|
|
|
6187
6231
|
const lowered = lower(workingIR, profile, {
|
|
6188
6232
|
forceThinkingZero: cliffs.value.loweringHints.forceThinkingZero,
|
|
6189
6233
|
forceTerseOutput: cliffs.value.loweringHints.forceTerseOutput,
|
|
6190
|
-
wireOverrides
|
|
6234
|
+
wireOverrides,
|
|
6235
|
+
route: opts.route
|
|
6191
6236
|
});
|
|
6192
6237
|
validateFinalFit(workingIR, profile, inputTokens);
|
|
6193
6238
|
const handle = makeHandle();
|
|
6194
6239
|
const finalShape = computeShape(workingIR, inputTokens);
|
|
6195
|
-
const _learningKey = learningKey(ir.intent.archetype, profile.id, finalShape);
|
|
6240
|
+
const _learningKey = learningKey(ir.intent.archetype, routeScopedModel(profile.id, opts.route), finalShape);
|
|
6196
6241
|
const historyCacheMarkIndex = computeHistoryCacheMarkIndex(workingIR);
|
|
6197
6242
|
const systemMessages = buildSystemMessages(workingIR, profile.provider);
|
|
6198
6243
|
const systemCacheMarkIndex = lastCacheableSystemIndex(systemMessages);
|
|
@@ -6419,7 +6464,7 @@ function validateFinalFit(ir, profile, tokens) {
|
|
|
6419
6464
|
}
|
|
6420
6465
|
|
|
6421
6466
|
// src/version.ts
|
|
6422
|
-
var LIBRARY_VERSION = "2.0.0-alpha.
|
|
6467
|
+
var LIBRARY_VERSION = "2.0.0-alpha.92";
|
|
6423
6468
|
|
|
6424
6469
|
// src/pricing-brain.ts
|
|
6425
6470
|
function isPricingRow(x) {
|
|
@@ -6694,7 +6739,7 @@ async function flushBrainDeadLetter() {
|
|
|
6694
6739
|
}
|
|
6695
6740
|
var compileRegistry = /* @__PURE__ */ new Map();
|
|
6696
6741
|
var REGISTRY_MAX_ENTRIES = 1e4;
|
|
6697
|
-
function registerCompile(appId, archetype, ir, result, parentHandle) {
|
|
6742
|
+
function registerCompile(appId, archetype, ir, result, parentHandle, route) {
|
|
6698
6743
|
if (compileRegistry.size >= REGISTRY_MAX_ENTRIES) {
|
|
6699
6744
|
const cutoff = Math.floor(REGISTRY_MAX_ENTRIES * 0.25);
|
|
6700
6745
|
let evicted = 0;
|
|
@@ -6726,7 +6771,10 @@ function registerCompile(appId, archetype, ir, result, parentHandle) {
|
|
|
6726
6771
|
model: result.target,
|
|
6727
6772
|
provider: result.provider,
|
|
6728
6773
|
shapeKey,
|
|
6729
|
-
|
|
6774
|
+
route: route ?? "direct",
|
|
6775
|
+
// alpha.92 — route-scoped for non-direct routes: the same model id on a
|
|
6776
|
+
// gateway is a different serving stack (Venice/StreamLake, 2026-08-26).
|
|
6777
|
+
learningKey: learningKey(archetype, routeScopedModel(result.target, route), shape),
|
|
6730
6778
|
estimatedTokensIn: tokens,
|
|
6731
6779
|
mutationsApplied: result.mutationsApplied.map((m) => m.id),
|
|
6732
6780
|
// alpha.30: cache the in-memory advisories so record() can auto-persist
|
|
@@ -6920,6 +6968,11 @@ function buildPayload(input, reg) {
|
|
|
6920
6968
|
provider: reg?.provider,
|
|
6921
6969
|
shape_key: reg?.shapeKey,
|
|
6922
6970
|
learning_key: reg?.learningKey,
|
|
6971
|
+
// alpha.92 (migration 067) — route identity on every row. Input wins
|
|
6972
|
+
// (a manual record() replaying through a gateway states its own route);
|
|
6973
|
+
// registry fills the call() path; column default covers legacy writers.
|
|
6974
|
+
route: input.route ?? reg?.route ?? "direct",
|
|
6975
|
+
route_host: input.routeHost,
|
|
6923
6976
|
mutations_applied: mutationsApplied,
|
|
6924
6977
|
tokens_in: input.tokensIn,
|
|
6925
6978
|
tokens_out: input.tokensOut,
|
|
@@ -7714,6 +7767,7 @@ var OPENAI_URL = "https://api.openai.com/v1/chat/completions";
|
|
|
7714
7767
|
var DEEPSEEK_URL = "https://api.deepseek.com/chat/completions";
|
|
7715
7768
|
var ZAI_URL = "https://api.z.ai/api/paas/v4/chat/completions";
|
|
7716
7769
|
var MOONSHOT_URL = "https://api.moonshot.ai/v1/chat/completions";
|
|
7770
|
+
var OPENROUTER_URL = "https://openrouter.ai/api/v1/chat/completions";
|
|
7717
7771
|
async function execute(request, opts = {}) {
|
|
7718
7772
|
const merged = applyOverrides(request, opts.providerOverrides);
|
|
7719
7773
|
switch (merged.provider) {
|
|
@@ -7737,6 +7791,12 @@ async function execute(request, opts = {}) {
|
|
|
7737
7791
|
opts,
|
|
7738
7792
|
{ provider: "moonshot", url: MOONSHOT_URL, missingKeyMessage: "MOONSHOT_API_KEY missing" }
|
|
7739
7793
|
);
|
|
7794
|
+
case "openrouter":
|
|
7795
|
+
return executeOpenAICompatible(
|
|
7796
|
+
merged,
|
|
7797
|
+
opts,
|
|
7798
|
+
{ provider: "openrouter", url: OPENROUTER_URL, missingKeyMessage: "OPENROUTER_API_KEY missing" }
|
|
7799
|
+
);
|
|
7740
7800
|
default: {
|
|
7741
7801
|
const _exhaustive = merged;
|
|
7742
7802
|
throw new Error(`execute(): no executor for provider: ${JSON.stringify(_exhaustive)}`);
|
|
@@ -7936,6 +7996,7 @@ function normalizeOpenAILike(raw) {
|
|
|
7936
7996
|
const r = raw;
|
|
7937
7997
|
const choice = r.choices?.[0];
|
|
7938
7998
|
const text = choice?.message?.content ?? "";
|
|
7999
|
+
const routeHost = typeof raw?.provider === "string" ? raw.provider : void 0;
|
|
7939
8000
|
const toolCalls = (choice?.message?.tool_calls ?? []).filter((tc) => tc.function?.name).map((tc, i) => ({
|
|
7940
8001
|
id: tc.id ?? `tc-${i}`,
|
|
7941
8002
|
name: tc.function.name,
|
|
@@ -7948,7 +8009,7 @@ function normalizeOpenAILike(raw) {
|
|
|
7948
8009
|
total: u.total_tokens ?? (u.prompt_tokens ?? 0) + (u.completion_tokens ?? 0),
|
|
7949
8010
|
cached: u.prompt_tokens_details?.cached_tokens
|
|
7950
8011
|
};
|
|
7951
|
-
return { text, structuredOutput: null, toolCalls, tokens, finishReason: choice?.finish_reason, raw };
|
|
8012
|
+
return { text, structuredOutput: null, toolCalls, tokens, finishReason: choice?.finish_reason, routeHost, raw };
|
|
7952
8013
|
}
|
|
7953
8014
|
function applyOverrides(request, overrides) {
|
|
7954
8015
|
if (!overrides) return request;
|
|
@@ -8387,6 +8448,7 @@ async function call(ir, opts = {}) {
|
|
|
8387
8448
|
handle: initial.handle,
|
|
8388
8449
|
source: opts.source,
|
|
8389
8450
|
endUserId: opts.endUserId,
|
|
8451
|
+
route: opts.route,
|
|
8390
8452
|
tokensIn: 0,
|
|
8391
8453
|
tokensOut: 0,
|
|
8392
8454
|
latencyMs: latencyMs2,
|
|
@@ -8441,6 +8503,7 @@ async function call(ir, opts = {}) {
|
|
|
8441
8503
|
handle: initial.handle,
|
|
8442
8504
|
source: opts.source,
|
|
8443
8505
|
endUserId: opts.endUserId,
|
|
8506
|
+
route: opts.route,
|
|
8444
8507
|
tokensIn: 0,
|
|
8445
8508
|
tokensOut: 0,
|
|
8446
8509
|
latencyMs: latencyMs2,
|
|
@@ -8584,6 +8647,11 @@ async function call(ir, opts = {}) {
|
|
|
8584
8647
|
handle: initial.handle,
|
|
8585
8648
|
source: opts.source,
|
|
8586
8649
|
endUserId: opts.endUserId,
|
|
8650
|
+
// alpha.92 — route identity on the row (registry also carries it;
|
|
8651
|
+
// input wins in buildPayload, so state it explicitly here with the
|
|
8652
|
+
// host the gateway reported for the WINNING attempt).
|
|
8653
|
+
route: opts.route,
|
|
8654
|
+
routeHost: validated.response.routeHost,
|
|
8587
8655
|
tokensIn: validated.response.tokens.input,
|
|
8588
8656
|
tokensOut: validated.response.tokens.output,
|
|
8589
8657
|
latencyMs: latencyMs2,
|
|
@@ -8664,6 +8732,12 @@ async function call(ir, opts = {}) {
|
|
|
8664
8732
|
provider: activeCompile.provider,
|
|
8665
8733
|
response: validated.response,
|
|
8666
8734
|
latencyMs: latencyMs2,
|
|
8735
|
+
// alpha.92 — route identity + the served profile's cliffs flagged
|
|
8736
|
+
// route-unverified on a non-direct route (guards still fired; their
|
|
8737
|
+
// evidence is vendor-route evidence — see the execute-leg contract).
|
|
8738
|
+
route: opts.route ?? "direct",
|
|
8739
|
+
routeHost: validated.response.routeHost,
|
|
8740
|
+
routeUnverifiedCliffs: opts.route === "openrouter" ? (tryGetProfile(targetModel)?.cliffs ?? []).map((c) => c.metric) : void 0,
|
|
8667
8741
|
mutationsApplied: activeCompile.mutationsApplied,
|
|
8668
8742
|
attempts,
|
|
8669
8743
|
servedBy: targetModel,
|
|
@@ -8708,6 +8782,7 @@ async function call(ir, opts = {}) {
|
|
|
8708
8782
|
handle: initial.handle,
|
|
8709
8783
|
source: opts.source,
|
|
8710
8784
|
endUserId: opts.endUserId,
|
|
8785
|
+
route: opts.route,
|
|
8711
8786
|
tokensIn: lastErr?.tokens?.input ?? 0,
|
|
8712
8787
|
tokensOut: lastErr?.tokens?.output ?? 0,
|
|
8713
8788
|
latencyMs,
|
|
@@ -8751,9 +8826,12 @@ function compileAndRegister(ir, opts) {
|
|
|
8751
8826
|
toolRelevanceThreshold: opts.toolRelevanceThreshold,
|
|
8752
8827
|
compressHistoryAfter: opts.compressHistoryAfter,
|
|
8753
8828
|
// alpha.68 / Release A — carry the fan-out parent handle through to compile.
|
|
8754
|
-
parentHandle: opts.parentHandle
|
|
8829
|
+
parentHandle: opts.parentHandle,
|
|
8830
|
+
// alpha.92 — gateway route (execute-leg contract): changes the wire +
|
|
8831
|
+
// learning-key encoding, never the pass pipeline.
|
|
8832
|
+
route: opts.route
|
|
8755
8833
|
});
|
|
8756
|
-
registerCompile(ir.appId, ir.intent.archetype, ir, result, opts.parentHandle);
|
|
8834
|
+
registerCompile(ir.appId, ir.intent.archetype, ir, result, opts.parentHandle, opts.route);
|
|
8757
8835
|
return result;
|
|
8758
8836
|
}
|
|
8759
8837
|
function extractPromptPreview(ir) {
|
|
@@ -11192,7 +11270,7 @@ function planDecomposition(args) {
|
|
|
11192
11270
|
// src/index.ts
|
|
11193
11271
|
function compile2(ir, opts) {
|
|
11194
11272
|
const result = compile(ir, opts);
|
|
11195
|
-
registerCompile(ir.appId, ir.intent.archetype, ir, result, opts?.parentHandle);
|
|
11273
|
+
registerCompile(ir.appId, ir.intent.archetype, ir, result, opts?.parentHandle, opts?.route);
|
|
11196
11274
|
return result;
|
|
11197
11275
|
}
|
|
11198
11276
|
// Annotate the CommonJS export names for ESM import in node:
|
package/dist/index.mjs
CHANGED
|
@@ -11,15 +11,16 @@ import {
|
|
|
11
11
|
hashShape,
|
|
12
12
|
isArchetype,
|
|
13
13
|
learningKey,
|
|
14
|
-
resolveOutputMode
|
|
15
|
-
|
|
14
|
+
resolveOutputMode,
|
|
15
|
+
routeScopedModel
|
|
16
|
+
} from "./chunk-FEMPY6EC.mjs";
|
|
16
17
|
import {
|
|
17
18
|
KEY_FINGERPRINT_DOMAIN,
|
|
18
19
|
KEY_FINGERPRINT_LENGTH,
|
|
19
20
|
LIBRARY_VERSION,
|
|
20
21
|
createKeyHealthRoute,
|
|
21
22
|
keyFingerprint
|
|
22
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-QOQV66PU.mjs";
|
|
23
24
|
import {
|
|
24
25
|
ABSOLUTE_FLOOR,
|
|
25
26
|
ARCHETYPE_FLOOR_DEFAULT,
|
|
@@ -57,7 +58,7 @@ import {
|
|
|
57
58
|
policySetHas,
|
|
58
59
|
readBrainReadEnv,
|
|
59
60
|
resolveProviderKey
|
|
60
|
-
} from "./chunk-
|
|
61
|
+
} from "./chunk-4G73BYES.mjs";
|
|
61
62
|
import {
|
|
62
63
|
ALIASES,
|
|
63
64
|
LATENCY_TIER_MS,
|
|
@@ -1169,7 +1170,26 @@ function passApplyConventions(ir, profile) {
|
|
|
1169
1170
|
}
|
|
1170
1171
|
|
|
1171
1172
|
// src/lower.ts
|
|
1173
|
+
var OPENROUTER_VENDOR_SLUG = {
|
|
1174
|
+
anthropic: "anthropic",
|
|
1175
|
+
google: "google",
|
|
1176
|
+
openai: "openai",
|
|
1177
|
+
deepseek: "deepseek",
|
|
1178
|
+
zai: "z-ai",
|
|
1179
|
+
moonshot: "moonshotai"
|
|
1180
|
+
};
|
|
1181
|
+
var OPENROUTER_ID_OVERRIDES = Object.freeze({});
|
|
1182
|
+
function openRouterModelId(profile) {
|
|
1183
|
+
const override = OPENROUTER_ID_OVERRIDES[profile.id];
|
|
1184
|
+
if (override) return override;
|
|
1185
|
+
const slug = OPENROUTER_VENDOR_SLUG[profile.provider];
|
|
1186
|
+
if (!slug) throw new Error(`No OpenRouter vendor slug for provider ${profile.provider} (model ${profile.id})`);
|
|
1187
|
+
return `${slug}/${profile.id}`;
|
|
1188
|
+
}
|
|
1172
1189
|
function lower(ir, profile, hints = {}) {
|
|
1190
|
+
if (hints.route === "openrouter") {
|
|
1191
|
+
return lowerOpenRouter(ir, profile);
|
|
1192
|
+
}
|
|
1173
1193
|
switch (profile.provider) {
|
|
1174
1194
|
case "anthropic":
|
|
1175
1195
|
return lowerAnthropic(ir, profile, hints);
|
|
@@ -1522,6 +1542,23 @@ function lowerZai(ir, profile, hints) {
|
|
|
1522
1542
|
}
|
|
1523
1543
|
};
|
|
1524
1544
|
}
|
|
1545
|
+
function lowerOpenRouter(ir, profile) {
|
|
1546
|
+
const parts = buildOpenAICompatibleParts(ir);
|
|
1547
|
+
return {
|
|
1548
|
+
request: {
|
|
1549
|
+
provider: "openrouter",
|
|
1550
|
+
model: openRouterModelId(profile),
|
|
1551
|
+
messages: parts.messages,
|
|
1552
|
+
tools: parts.tools,
|
|
1553
|
+
response_format: parts.response_format
|
|
1554
|
+
},
|
|
1555
|
+
diagnostics: {
|
|
1556
|
+
cacheableTokens: 0,
|
|
1557
|
+
historyCacheableTokens: parts.historyCacheableTokens,
|
|
1558
|
+
estimatedCacheSavingsUsd: 0
|
|
1559
|
+
}
|
|
1560
|
+
};
|
|
1561
|
+
}
|
|
1525
1562
|
function lowerMoonshot(ir, profile) {
|
|
1526
1563
|
const parts = buildOpenAICompatibleParts(ir);
|
|
1527
1564
|
return {
|
|
@@ -3173,12 +3210,13 @@ function compile(ir, opts = {}) {
|
|
|
3173
3210
|
const lowered = lower(workingIR, profile, {
|
|
3174
3211
|
forceThinkingZero: cliffs.value.loweringHints.forceThinkingZero,
|
|
3175
3212
|
forceTerseOutput: cliffs.value.loweringHints.forceTerseOutput,
|
|
3176
|
-
wireOverrides
|
|
3213
|
+
wireOverrides,
|
|
3214
|
+
route: opts.route
|
|
3177
3215
|
});
|
|
3178
3216
|
validateFinalFit(workingIR, profile, inputTokens);
|
|
3179
3217
|
const handle = makeHandle();
|
|
3180
3218
|
const finalShape = computeShape(workingIR, inputTokens);
|
|
3181
|
-
const _learningKey = learningKey(ir.intent.archetype, profile.id, finalShape);
|
|
3219
|
+
const _learningKey = learningKey(ir.intent.archetype, routeScopedModel(profile.id, opts.route), finalShape);
|
|
3182
3220
|
const historyCacheMarkIndex = computeHistoryCacheMarkIndex(workingIR);
|
|
3183
3221
|
const systemMessages = buildSystemMessages(workingIR, profile.provider);
|
|
3184
3222
|
const systemCacheMarkIndex = lastCacheableSystemIndex(systemMessages);
|
|
@@ -3677,7 +3715,7 @@ async function flushBrainDeadLetter() {
|
|
|
3677
3715
|
}
|
|
3678
3716
|
var compileRegistry = /* @__PURE__ */ new Map();
|
|
3679
3717
|
var REGISTRY_MAX_ENTRIES = 1e4;
|
|
3680
|
-
function registerCompile(appId, archetype, ir, result, parentHandle) {
|
|
3718
|
+
function registerCompile(appId, archetype, ir, result, parentHandle, route) {
|
|
3681
3719
|
if (compileRegistry.size >= REGISTRY_MAX_ENTRIES) {
|
|
3682
3720
|
const cutoff = Math.floor(REGISTRY_MAX_ENTRIES * 0.25);
|
|
3683
3721
|
let evicted = 0;
|
|
@@ -3709,7 +3747,10 @@ function registerCompile(appId, archetype, ir, result, parentHandle) {
|
|
|
3709
3747
|
model: result.target,
|
|
3710
3748
|
provider: result.provider,
|
|
3711
3749
|
shapeKey,
|
|
3712
|
-
|
|
3750
|
+
route: route ?? "direct",
|
|
3751
|
+
// alpha.92 — route-scoped for non-direct routes: the same model id on a
|
|
3752
|
+
// gateway is a different serving stack (Venice/StreamLake, 2026-08-26).
|
|
3753
|
+
learningKey: learningKey(archetype, routeScopedModel(result.target, route), shape),
|
|
3713
3754
|
estimatedTokensIn: tokens,
|
|
3714
3755
|
mutationsApplied: result.mutationsApplied.map((m) => m.id),
|
|
3715
3756
|
// alpha.30: cache the in-memory advisories so record() can auto-persist
|
|
@@ -3903,6 +3944,11 @@ function buildPayload(input, reg) {
|
|
|
3903
3944
|
provider: reg?.provider,
|
|
3904
3945
|
shape_key: reg?.shapeKey,
|
|
3905
3946
|
learning_key: reg?.learningKey,
|
|
3947
|
+
// alpha.92 (migration 067) — route identity on every row. Input wins
|
|
3948
|
+
// (a manual record() replaying through a gateway states its own route);
|
|
3949
|
+
// registry fills the call() path; column default covers legacy writers.
|
|
3950
|
+
route: input.route ?? reg?.route ?? "direct",
|
|
3951
|
+
route_host: input.routeHost,
|
|
3906
3952
|
mutations_applied: mutationsApplied,
|
|
3907
3953
|
tokens_in: input.tokensIn,
|
|
3908
3954
|
tokens_out: input.tokensOut,
|
|
@@ -4697,6 +4743,7 @@ var OPENAI_URL = "https://api.openai.com/v1/chat/completions";
|
|
|
4697
4743
|
var DEEPSEEK_URL = "https://api.deepseek.com/chat/completions";
|
|
4698
4744
|
var ZAI_URL = "https://api.z.ai/api/paas/v4/chat/completions";
|
|
4699
4745
|
var MOONSHOT_URL = "https://api.moonshot.ai/v1/chat/completions";
|
|
4746
|
+
var OPENROUTER_URL = "https://openrouter.ai/api/v1/chat/completions";
|
|
4700
4747
|
async function execute(request, opts = {}) {
|
|
4701
4748
|
const merged = applyOverrides(request, opts.providerOverrides);
|
|
4702
4749
|
switch (merged.provider) {
|
|
@@ -4720,6 +4767,12 @@ async function execute(request, opts = {}) {
|
|
|
4720
4767
|
opts,
|
|
4721
4768
|
{ provider: "moonshot", url: MOONSHOT_URL, missingKeyMessage: "MOONSHOT_API_KEY missing" }
|
|
4722
4769
|
);
|
|
4770
|
+
case "openrouter":
|
|
4771
|
+
return executeOpenAICompatible(
|
|
4772
|
+
merged,
|
|
4773
|
+
opts,
|
|
4774
|
+
{ provider: "openrouter", url: OPENROUTER_URL, missingKeyMessage: "OPENROUTER_API_KEY missing" }
|
|
4775
|
+
);
|
|
4723
4776
|
default: {
|
|
4724
4777
|
const _exhaustive = merged;
|
|
4725
4778
|
throw new Error(`execute(): no executor for provider: ${JSON.stringify(_exhaustive)}`);
|
|
@@ -4919,6 +4972,7 @@ function normalizeOpenAILike(raw) {
|
|
|
4919
4972
|
const r = raw;
|
|
4920
4973
|
const choice = r.choices?.[0];
|
|
4921
4974
|
const text = choice?.message?.content ?? "";
|
|
4975
|
+
const routeHost = typeof raw?.provider === "string" ? raw.provider : void 0;
|
|
4922
4976
|
const toolCalls = (choice?.message?.tool_calls ?? []).filter((tc) => tc.function?.name).map((tc, i) => ({
|
|
4923
4977
|
id: tc.id ?? `tc-${i}`,
|
|
4924
4978
|
name: tc.function.name,
|
|
@@ -4931,7 +4985,7 @@ function normalizeOpenAILike(raw) {
|
|
|
4931
4985
|
total: u.total_tokens ?? (u.prompt_tokens ?? 0) + (u.completion_tokens ?? 0),
|
|
4932
4986
|
cached: u.prompt_tokens_details?.cached_tokens
|
|
4933
4987
|
};
|
|
4934
|
-
return { text, structuredOutput: null, toolCalls, tokens, finishReason: choice?.finish_reason, raw };
|
|
4988
|
+
return { text, structuredOutput: null, toolCalls, tokens, finishReason: choice?.finish_reason, routeHost, raw };
|
|
4935
4989
|
}
|
|
4936
4990
|
function applyOverrides(request, overrides) {
|
|
4937
4991
|
if (!overrides) return request;
|
|
@@ -5069,6 +5123,7 @@ async function call(ir, opts = {}) {
|
|
|
5069
5123
|
handle: initial.handle,
|
|
5070
5124
|
source: opts.source,
|
|
5071
5125
|
endUserId: opts.endUserId,
|
|
5126
|
+
route: opts.route,
|
|
5072
5127
|
tokensIn: 0,
|
|
5073
5128
|
tokensOut: 0,
|
|
5074
5129
|
latencyMs: latencyMs2,
|
|
@@ -5123,6 +5178,7 @@ async function call(ir, opts = {}) {
|
|
|
5123
5178
|
handle: initial.handle,
|
|
5124
5179
|
source: opts.source,
|
|
5125
5180
|
endUserId: opts.endUserId,
|
|
5181
|
+
route: opts.route,
|
|
5126
5182
|
tokensIn: 0,
|
|
5127
5183
|
tokensOut: 0,
|
|
5128
5184
|
latencyMs: latencyMs2,
|
|
@@ -5266,6 +5322,11 @@ async function call(ir, opts = {}) {
|
|
|
5266
5322
|
handle: initial.handle,
|
|
5267
5323
|
source: opts.source,
|
|
5268
5324
|
endUserId: opts.endUserId,
|
|
5325
|
+
// alpha.92 — route identity on the row (registry also carries it;
|
|
5326
|
+
// input wins in buildPayload, so state it explicitly here with the
|
|
5327
|
+
// host the gateway reported for the WINNING attempt).
|
|
5328
|
+
route: opts.route,
|
|
5329
|
+
routeHost: validated.response.routeHost,
|
|
5269
5330
|
tokensIn: validated.response.tokens.input,
|
|
5270
5331
|
tokensOut: validated.response.tokens.output,
|
|
5271
5332
|
latencyMs: latencyMs2,
|
|
@@ -5346,6 +5407,12 @@ async function call(ir, opts = {}) {
|
|
|
5346
5407
|
provider: activeCompile.provider,
|
|
5347
5408
|
response: validated.response,
|
|
5348
5409
|
latencyMs: latencyMs2,
|
|
5410
|
+
// alpha.92 — route identity + the served profile's cliffs flagged
|
|
5411
|
+
// route-unverified on a non-direct route (guards still fired; their
|
|
5412
|
+
// evidence is vendor-route evidence — see the execute-leg contract).
|
|
5413
|
+
route: opts.route ?? "direct",
|
|
5414
|
+
routeHost: validated.response.routeHost,
|
|
5415
|
+
routeUnverifiedCliffs: opts.route === "openrouter" ? (tryGetProfile(targetModel)?.cliffs ?? []).map((c) => c.metric) : void 0,
|
|
5349
5416
|
mutationsApplied: activeCompile.mutationsApplied,
|
|
5350
5417
|
attempts,
|
|
5351
5418
|
servedBy: targetModel,
|
|
@@ -5390,6 +5457,7 @@ async function call(ir, opts = {}) {
|
|
|
5390
5457
|
handle: initial.handle,
|
|
5391
5458
|
source: opts.source,
|
|
5392
5459
|
endUserId: opts.endUserId,
|
|
5460
|
+
route: opts.route,
|
|
5393
5461
|
tokensIn: lastErr?.tokens?.input ?? 0,
|
|
5394
5462
|
tokensOut: lastErr?.tokens?.output ?? 0,
|
|
5395
5463
|
latencyMs,
|
|
@@ -5433,9 +5501,12 @@ function compileAndRegister(ir, opts) {
|
|
|
5433
5501
|
toolRelevanceThreshold: opts.toolRelevanceThreshold,
|
|
5434
5502
|
compressHistoryAfter: opts.compressHistoryAfter,
|
|
5435
5503
|
// alpha.68 / Release A — carry the fan-out parent handle through to compile.
|
|
5436
|
-
parentHandle: opts.parentHandle
|
|
5504
|
+
parentHandle: opts.parentHandle,
|
|
5505
|
+
// alpha.92 — gateway route (execute-leg contract): changes the wire +
|
|
5506
|
+
// learning-key encoding, never the pass pipeline.
|
|
5507
|
+
route: opts.route
|
|
5437
5508
|
});
|
|
5438
|
-
registerCompile(ir.appId, ir.intent.archetype, ir, result, opts.parentHandle);
|
|
5509
|
+
registerCompile(ir.appId, ir.intent.archetype, ir, result, opts.parentHandle, opts.route);
|
|
5439
5510
|
return result;
|
|
5440
5511
|
}
|
|
5441
5512
|
function extractPromptPreview(ir) {
|
|
@@ -7499,7 +7570,7 @@ function planDecomposition(args) {
|
|
|
7499
7570
|
// src/index.ts
|
|
7500
7571
|
function compile2(ir, opts) {
|
|
7501
7572
|
const result = compile(ir, opts);
|
|
7502
|
-
registerCompile(ir.appId, ir.intent.archetype, ir, result, opts?.parentHandle);
|
|
7573
|
+
registerCompile(ir.appId, ir.intent.archetype, ir, result, opts?.parentHandle, opts?.route);
|
|
7503
7574
|
return result;
|
|
7504
7575
|
}
|
|
7505
7576
|
export {
|
|
@@ -440,7 +440,21 @@ interface PromptIR {
|
|
|
440
440
|
*/
|
|
441
441
|
historyCachePolicy?: HistoryCachePolicy;
|
|
442
442
|
}
|
|
443
|
-
type Provider = 'anthropic' | 'google' | 'openai' | 'deepseek' | 'zai' | 'moonshot' | 'mistral' | 'xai';
|
|
443
|
+
type Provider = 'anthropic' | 'google' | 'openai' | 'deepseek' | 'zai' | 'moonshot' | 'mistral' | 'xai' | 'openrouter';
|
|
444
|
+
/**
|
|
445
|
+
* alpha.92 — the route a call travels, part of a measurement's identity
|
|
446
|
+
* (execute-leg design contract, 2026-08-26). `'direct'` = the vendor's own
|
|
447
|
+
* API (every measurement before this release; the default, and the only
|
|
448
|
+
* route consumer production traffic uses unless a consumer explicitly opts
|
|
449
|
+
* in later). `'openrouter'` = the OpenRouter gateway — the STARTER tier for
|
|
450
|
+
* eval and candidate admission. The route matters because the model behind
|
|
451
|
+
* a name is a different serving stack per gateway host: the same
|
|
452
|
+
* `deepseek-v4-flash` id was served by "Venice" and by "StreamLake"
|
|
453
|
+
* emitting PARALLEL tool calls — behavior opposite to the vendor-API
|
|
454
|
+
* evidence our cliff rests on. Vendor-keyed evidence does not transfer
|
|
455
|
+
* through a gateway, so verdicts never silently transfer across routes.
|
|
456
|
+
*/
|
|
457
|
+
type CallRoute = 'direct' | 'openrouter';
|
|
444
458
|
/**
|
|
445
459
|
* Mutation IDs that fired during compile. Empty in v1 (no mutation engine
|
|
446
460
|
* yet). Populated when the brain is online and pushing mutations.
|
|
@@ -592,6 +606,22 @@ type CompiledRequest = {
|
|
|
592
606
|
}>;
|
|
593
607
|
tools?: unknown[];
|
|
594
608
|
response_format?: unknown;
|
|
609
|
+
} | {
|
|
610
|
+
/**
|
|
611
|
+
* alpha.92 — the OpenRouter gateway route. OpenAI-compatible wire;
|
|
612
|
+
* `model` is the OpenRouter id (`vendor/model`, e.g.
|
|
613
|
+
* `deepseek/deepseek-v4-flash`), mapped from the CANONICAL profile id
|
|
614
|
+
* by `openRouterModelId()` — the canonical id stays the measurement
|
|
615
|
+
* identity everywhere else.
|
|
616
|
+
*/
|
|
617
|
+
provider: 'openrouter';
|
|
618
|
+
model: string;
|
|
619
|
+
messages: Array<{
|
|
620
|
+
role: string;
|
|
621
|
+
content: unknown;
|
|
622
|
+
}>;
|
|
623
|
+
tools?: unknown[];
|
|
624
|
+
response_format?: unknown;
|
|
595
625
|
};
|
|
596
626
|
/**
|
|
597
627
|
* Best-practice advisory emitted by the compiler at compile time. Non-fatal —
|
|
@@ -1065,6 +1095,14 @@ interface NormalizedResponse {
|
|
|
1065
1095
|
tokens: NormalizedTokens;
|
|
1066
1096
|
/** Provider-specific finish reason, passed through unchanged. */
|
|
1067
1097
|
finishReason?: string;
|
|
1098
|
+
/**
|
|
1099
|
+
* alpha.92 — the serving host a gateway reported (OpenRouter's response
|
|
1100
|
+
* `provider` field, captured verbatim: "Venice", "StreamLake", …).
|
|
1101
|
+
* Undefined on direct vendor calls and on gateways that don't report it.
|
|
1102
|
+
* Discarding this would be the L-073 silent-drop at birth — the gateway
|
|
1103
|
+
* itself tells us which stack served the call.
|
|
1104
|
+
*/
|
|
1105
|
+
routeHost?: string;
|
|
1068
1106
|
/** Untouched provider response — escape hatch for consumers needing fields not yet normalized. */
|
|
1069
1107
|
raw: unknown;
|
|
1070
1108
|
/** Set when structuredOutput parsing was attempted and failed. */
|
|
@@ -1077,6 +1115,8 @@ interface ApiKeys {
|
|
|
1077
1115
|
deepseek?: string;
|
|
1078
1116
|
zai?: string;
|
|
1079
1117
|
moonshot?: string;
|
|
1118
|
+
/** alpha.92 — the OpenRouter gateway route's key (a route key, not a vendor key). */
|
|
1119
|
+
openrouter?: string;
|
|
1080
1120
|
}
|
|
1081
1121
|
/**
|
|
1082
1122
|
* Per-provider override fields shallow-merged into the lowered request before
|
|
@@ -1090,6 +1130,8 @@ interface ProviderOverrides {
|
|
|
1090
1130
|
deepseek?: Record<string, unknown>;
|
|
1091
1131
|
zai?: Record<string, unknown>;
|
|
1092
1132
|
moonshot?: Record<string, unknown>;
|
|
1133
|
+
/** alpha.92 — overrides for requests traveling the OpenRouter route. */
|
|
1134
|
+
openrouter?: Record<string, unknown>;
|
|
1093
1135
|
}
|
|
1094
1136
|
/**
|
|
1095
1137
|
* Full-IR inline shadow-probe config (Shape B, Phase 1 — 2026-05-29 s51).
|
|
@@ -1180,6 +1222,24 @@ interface CallOptions {
|
|
|
1180
1222
|
* money attributable to the customer). See {@link RecordInput.endUserId}.
|
|
1181
1223
|
*/
|
|
1182
1224
|
endUserId?: string;
|
|
1225
|
+
/**
|
|
1226
|
+
* alpha.92 — route this call through a gateway instead of the vendor's
|
|
1227
|
+
* own API. Omit (or `'direct'`) for normal calls — this is the STARTER
|
|
1228
|
+
* tier for eval and candidate admission, NOT a consumer routing surface:
|
|
1229
|
+
* production traffic stays direct-vendor-only by default per the
|
|
1230
|
+
* execute-leg design contract. When `'openrouter'`:
|
|
1231
|
+
* - lowering emits the OpenAI-compatible wire with the OpenRouter id
|
|
1232
|
+
* (canonical id stays the measurement identity),
|
|
1233
|
+
* - the outcome row records `route='openrouter'` + `route_host` (the
|
|
1234
|
+
* serving host OpenRouter reports),
|
|
1235
|
+
* - the learning key gains the route dimension (`…::model@openrouter`),
|
|
1236
|
+
* so gateway evidence never pollutes direct-vendor evidence,
|
|
1237
|
+
* - cliff guards still apply but are route-unverified (see
|
|
1238
|
+
* {@link CallResult.routeUnverifiedCliffs}) — never assume a host
|
|
1239
|
+
* fixed a vendor cliff.
|
|
1240
|
+
* Requires `OPENROUTER_API_KEY`.
|
|
1241
|
+
*/
|
|
1242
|
+
route?: CallRoute;
|
|
1183
1243
|
/**
|
|
1184
1244
|
* alpha.84 — fires once per FAILED attempt during the fallback walk, before
|
|
1185
1245
|
* the walk continues. IC-Cairn's filing, 2026-07-29.
|
|
@@ -1429,6 +1489,28 @@ interface CallResult {
|
|
|
1429
1489
|
provider: Provider;
|
|
1430
1490
|
response: NormalizedResponse;
|
|
1431
1491
|
latencyMs: number;
|
|
1492
|
+
/**
|
|
1493
|
+
* alpha.92 — the route this call traveled. `'direct'` unless the caller
|
|
1494
|
+
* passed `CallOptions.route`. Part of the measurement's identity: the
|
|
1495
|
+
* outcome row and learning key are route-scoped, and verdicts never
|
|
1496
|
+
* silently transfer across routes.
|
|
1497
|
+
*/
|
|
1498
|
+
route: CallRoute;
|
|
1499
|
+
/**
|
|
1500
|
+
* alpha.92 — the serving host the gateway reported for the winning
|
|
1501
|
+
* attempt (OpenRouter's `provider` field: "Venice", "StreamLake", …).
|
|
1502
|
+
* Undefined on direct calls.
|
|
1503
|
+
*/
|
|
1504
|
+
routeHost?: string;
|
|
1505
|
+
/**
|
|
1506
|
+
* alpha.92 — cliff metrics of the served profile that applied on a
|
|
1507
|
+
* non-direct route. The guards STILL FIRED (conservative default: never
|
|
1508
|
+
* assume a host fixed a vendor cliff) but their evidence is vendor-route
|
|
1509
|
+
* evidence — a different serving stack may not share the cliff. The
|
|
1510
|
+
* probe-suite can promote/demote per (cliff × route). Undefined on
|
|
1511
|
+
* direct calls or when the served profile has no cliffs.
|
|
1512
|
+
*/
|
|
1513
|
+
routeUnverifiedCliffs?: string[];
|
|
1432
1514
|
/** Mutations that fired during compile (informational, mirrors CompileResult.mutationsApplied). */
|
|
1433
1515
|
mutationsApplied: MutationApplied[];
|
|
1434
1516
|
/** One entry per provider attempt — observability for retry/fallback walks. */
|
|
@@ -1592,6 +1674,18 @@ interface RecordInput {
|
|
|
1592
1674
|
* Omit for traffic that has no end user.
|
|
1593
1675
|
*/
|
|
1594
1676
|
endUserId?: string;
|
|
1677
|
+
/**
|
|
1678
|
+
* alpha.92 — the route the call traveled (migration 067). `call()` sets
|
|
1679
|
+
* this automatically from `CallOptions.route`; manual `record()` callers
|
|
1680
|
+
* replaying through a gateway set it themselves. Omit for direct calls —
|
|
1681
|
+
* the column defaults to `'direct'`.
|
|
1682
|
+
*/
|
|
1683
|
+
route?: CallRoute;
|
|
1684
|
+
/**
|
|
1685
|
+
* alpha.92 — the gateway-reported serving host ("Venice", "StreamLake").
|
|
1686
|
+
* Only meaningful with a non-direct `route`.
|
|
1687
|
+
*/
|
|
1688
|
+
routeHost?: string;
|
|
1595
1689
|
/** Actual tokens consumed (post-call). */
|
|
1596
1690
|
tokensIn: number;
|
|
1597
1691
|
tokensOut: number;
|
|
@@ -440,7 +440,21 @@ interface PromptIR {
|
|
|
440
440
|
*/
|
|
441
441
|
historyCachePolicy?: HistoryCachePolicy;
|
|
442
442
|
}
|
|
443
|
-
type Provider = 'anthropic' | 'google' | 'openai' | 'deepseek' | 'zai' | 'moonshot' | 'mistral' | 'xai';
|
|
443
|
+
type Provider = 'anthropic' | 'google' | 'openai' | 'deepseek' | 'zai' | 'moonshot' | 'mistral' | 'xai' | 'openrouter';
|
|
444
|
+
/**
|
|
445
|
+
* alpha.92 — the route a call travels, part of a measurement's identity
|
|
446
|
+
* (execute-leg design contract, 2026-08-26). `'direct'` = the vendor's own
|
|
447
|
+
* API (every measurement before this release; the default, and the only
|
|
448
|
+
* route consumer production traffic uses unless a consumer explicitly opts
|
|
449
|
+
* in later). `'openrouter'` = the OpenRouter gateway — the STARTER tier for
|
|
450
|
+
* eval and candidate admission. The route matters because the model behind
|
|
451
|
+
* a name is a different serving stack per gateway host: the same
|
|
452
|
+
* `deepseek-v4-flash` id was served by "Venice" and by "StreamLake"
|
|
453
|
+
* emitting PARALLEL tool calls — behavior opposite to the vendor-API
|
|
454
|
+
* evidence our cliff rests on. Vendor-keyed evidence does not transfer
|
|
455
|
+
* through a gateway, so verdicts never silently transfer across routes.
|
|
456
|
+
*/
|
|
457
|
+
type CallRoute = 'direct' | 'openrouter';
|
|
444
458
|
/**
|
|
445
459
|
* Mutation IDs that fired during compile. Empty in v1 (no mutation engine
|
|
446
460
|
* yet). Populated when the brain is online and pushing mutations.
|
|
@@ -592,6 +606,22 @@ type CompiledRequest = {
|
|
|
592
606
|
}>;
|
|
593
607
|
tools?: unknown[];
|
|
594
608
|
response_format?: unknown;
|
|
609
|
+
} | {
|
|
610
|
+
/**
|
|
611
|
+
* alpha.92 — the OpenRouter gateway route. OpenAI-compatible wire;
|
|
612
|
+
* `model` is the OpenRouter id (`vendor/model`, e.g.
|
|
613
|
+
* `deepseek/deepseek-v4-flash`), mapped from the CANONICAL profile id
|
|
614
|
+
* by `openRouterModelId()` — the canonical id stays the measurement
|
|
615
|
+
* identity everywhere else.
|
|
616
|
+
*/
|
|
617
|
+
provider: 'openrouter';
|
|
618
|
+
model: string;
|
|
619
|
+
messages: Array<{
|
|
620
|
+
role: string;
|
|
621
|
+
content: unknown;
|
|
622
|
+
}>;
|
|
623
|
+
tools?: unknown[];
|
|
624
|
+
response_format?: unknown;
|
|
595
625
|
};
|
|
596
626
|
/**
|
|
597
627
|
* Best-practice advisory emitted by the compiler at compile time. Non-fatal —
|
|
@@ -1065,6 +1095,14 @@ interface NormalizedResponse {
|
|
|
1065
1095
|
tokens: NormalizedTokens;
|
|
1066
1096
|
/** Provider-specific finish reason, passed through unchanged. */
|
|
1067
1097
|
finishReason?: string;
|
|
1098
|
+
/**
|
|
1099
|
+
* alpha.92 — the serving host a gateway reported (OpenRouter's response
|
|
1100
|
+
* `provider` field, captured verbatim: "Venice", "StreamLake", …).
|
|
1101
|
+
* Undefined on direct vendor calls and on gateways that don't report it.
|
|
1102
|
+
* Discarding this would be the L-073 silent-drop at birth — the gateway
|
|
1103
|
+
* itself tells us which stack served the call.
|
|
1104
|
+
*/
|
|
1105
|
+
routeHost?: string;
|
|
1068
1106
|
/** Untouched provider response — escape hatch for consumers needing fields not yet normalized. */
|
|
1069
1107
|
raw: unknown;
|
|
1070
1108
|
/** Set when structuredOutput parsing was attempted and failed. */
|
|
@@ -1077,6 +1115,8 @@ interface ApiKeys {
|
|
|
1077
1115
|
deepseek?: string;
|
|
1078
1116
|
zai?: string;
|
|
1079
1117
|
moonshot?: string;
|
|
1118
|
+
/** alpha.92 — the OpenRouter gateway route's key (a route key, not a vendor key). */
|
|
1119
|
+
openrouter?: string;
|
|
1080
1120
|
}
|
|
1081
1121
|
/**
|
|
1082
1122
|
* Per-provider override fields shallow-merged into the lowered request before
|
|
@@ -1090,6 +1130,8 @@ interface ProviderOverrides {
|
|
|
1090
1130
|
deepseek?: Record<string, unknown>;
|
|
1091
1131
|
zai?: Record<string, unknown>;
|
|
1092
1132
|
moonshot?: Record<string, unknown>;
|
|
1133
|
+
/** alpha.92 — overrides for requests traveling the OpenRouter route. */
|
|
1134
|
+
openrouter?: Record<string, unknown>;
|
|
1093
1135
|
}
|
|
1094
1136
|
/**
|
|
1095
1137
|
* Full-IR inline shadow-probe config (Shape B, Phase 1 — 2026-05-29 s51).
|
|
@@ -1180,6 +1222,24 @@ interface CallOptions {
|
|
|
1180
1222
|
* money attributable to the customer). See {@link RecordInput.endUserId}.
|
|
1181
1223
|
*/
|
|
1182
1224
|
endUserId?: string;
|
|
1225
|
+
/**
|
|
1226
|
+
* alpha.92 — route this call through a gateway instead of the vendor's
|
|
1227
|
+
* own API. Omit (or `'direct'`) for normal calls — this is the STARTER
|
|
1228
|
+
* tier for eval and candidate admission, NOT a consumer routing surface:
|
|
1229
|
+
* production traffic stays direct-vendor-only by default per the
|
|
1230
|
+
* execute-leg design contract. When `'openrouter'`:
|
|
1231
|
+
* - lowering emits the OpenAI-compatible wire with the OpenRouter id
|
|
1232
|
+
* (canonical id stays the measurement identity),
|
|
1233
|
+
* - the outcome row records `route='openrouter'` + `route_host` (the
|
|
1234
|
+
* serving host OpenRouter reports),
|
|
1235
|
+
* - the learning key gains the route dimension (`…::model@openrouter`),
|
|
1236
|
+
* so gateway evidence never pollutes direct-vendor evidence,
|
|
1237
|
+
* - cliff guards still apply but are route-unverified (see
|
|
1238
|
+
* {@link CallResult.routeUnverifiedCliffs}) — never assume a host
|
|
1239
|
+
* fixed a vendor cliff.
|
|
1240
|
+
* Requires `OPENROUTER_API_KEY`.
|
|
1241
|
+
*/
|
|
1242
|
+
route?: CallRoute;
|
|
1183
1243
|
/**
|
|
1184
1244
|
* alpha.84 — fires once per FAILED attempt during the fallback walk, before
|
|
1185
1245
|
* the walk continues. IC-Cairn's filing, 2026-07-29.
|
|
@@ -1429,6 +1489,28 @@ interface CallResult {
|
|
|
1429
1489
|
provider: Provider;
|
|
1430
1490
|
response: NormalizedResponse;
|
|
1431
1491
|
latencyMs: number;
|
|
1492
|
+
/**
|
|
1493
|
+
* alpha.92 — the route this call traveled. `'direct'` unless the caller
|
|
1494
|
+
* passed `CallOptions.route`. Part of the measurement's identity: the
|
|
1495
|
+
* outcome row and learning key are route-scoped, and verdicts never
|
|
1496
|
+
* silently transfer across routes.
|
|
1497
|
+
*/
|
|
1498
|
+
route: CallRoute;
|
|
1499
|
+
/**
|
|
1500
|
+
* alpha.92 — the serving host the gateway reported for the winning
|
|
1501
|
+
* attempt (OpenRouter's `provider` field: "Venice", "StreamLake", …).
|
|
1502
|
+
* Undefined on direct calls.
|
|
1503
|
+
*/
|
|
1504
|
+
routeHost?: string;
|
|
1505
|
+
/**
|
|
1506
|
+
* alpha.92 — cliff metrics of the served profile that applied on a
|
|
1507
|
+
* non-direct route. The guards STILL FIRED (conservative default: never
|
|
1508
|
+
* assume a host fixed a vendor cliff) but their evidence is vendor-route
|
|
1509
|
+
* evidence — a different serving stack may not share the cliff. The
|
|
1510
|
+
* probe-suite can promote/demote per (cliff × route). Undefined on
|
|
1511
|
+
* direct calls or when the served profile has no cliffs.
|
|
1512
|
+
*/
|
|
1513
|
+
routeUnverifiedCliffs?: string[];
|
|
1432
1514
|
/** Mutations that fired during compile (informational, mirrors CompileResult.mutationsApplied). */
|
|
1433
1515
|
mutationsApplied: MutationApplied[];
|
|
1434
1516
|
/** One entry per provider attempt — observability for retry/fallback walks. */
|
|
@@ -1592,6 +1674,18 @@ interface RecordInput {
|
|
|
1592
1674
|
* Omit for traffic that has no end user.
|
|
1593
1675
|
*/
|
|
1594
1676
|
endUserId?: string;
|
|
1677
|
+
/**
|
|
1678
|
+
* alpha.92 — the route the call traveled (migration 067). `call()` sets
|
|
1679
|
+
* this automatically from `CallOptions.route`; manual `record()` callers
|
|
1680
|
+
* replaying through a gateway set it themselves. Omit for direct calls —
|
|
1681
|
+
* the column defaults to `'direct'`.
|
|
1682
|
+
*/
|
|
1683
|
+
route?: CallRoute;
|
|
1684
|
+
/**
|
|
1685
|
+
* alpha.92 — the gateway-reported serving host ("Venice", "StreamLake").
|
|
1686
|
+
* Only meaningful with a non-direct `route`.
|
|
1687
|
+
*/
|
|
1688
|
+
routeHost?: string;
|
|
1595
1689
|
/** Actual tokens consumed (post-call). */
|
|
1596
1690
|
tokensIn: number;
|
|
1597
1691
|
tokensOut: number;
|
package/dist/key-health.js
CHANGED
|
@@ -28,7 +28,7 @@ __export(key_health_exports, {
|
|
|
28
28
|
module.exports = __toCommonJS(key_health_exports);
|
|
29
29
|
|
|
30
30
|
// src/version.ts
|
|
31
|
-
var LIBRARY_VERSION = "2.0.0-alpha.
|
|
31
|
+
var LIBRARY_VERSION = "2.0.0-alpha.92";
|
|
32
32
|
|
|
33
33
|
// src/key-health.ts
|
|
34
34
|
var JSON_HEADERS = { "Content-Type": "application/json" };
|
package/dist/key-health.mjs
CHANGED
package/dist/profiles.d.mts
CHANGED
package/dist/profiles.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, n as CallAttempt } from './ir-
|
|
1
|
+
import { t as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, n as CallAttempt } from './ir-BPYh68mv.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Glass-Box observability types (alpha.17).
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, n as CallAttempt } from './ir-
|
|
1
|
+
import { t as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, n as CallAttempt } from './ir-BWnE6LaB.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Glass-Box observability types (alpha.17).
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@warmdrift/kgauto-compiler",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.92",
|
|
4
4
|
"description": "Prompt compiler with executable provider knowledge for multi-model AI apps: normalized multi-provider transport with fallback chains, compile-time cliff guards, a curated model registry, and a telemetry flight recorder. Swap models without rewriting prompts.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|