@warmdrift/kgauto-compiler 2.0.0-alpha.22 → 2.0.0-alpha.23
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/glassbox/index.d.mts +3 -3
- package/dist/glassbox/index.d.ts +3 -3
- package/dist/glassbox-routes/index.d.mts +2 -2
- package/dist/glassbox-routes/index.d.ts +2 -2
- package/dist/index.d.mts +43 -3
- package/dist/index.d.ts +43 -3
- package/dist/index.js +92 -0
- package/dist/index.mjs +91 -0
- package/dist/{ir-CruZBtpK.d.mts → ir-B9zqlwjH.d.mts} +38 -1
- package/dist/{ir-Wr5lc8Mi.d.ts → ir-B_XX2LAO.d.ts} +38 -1
- package/dist/profiles.d.mts +1 -1
- package/dist/profiles.d.ts +1 -1
- package/dist/{types-zk238uNL.d.mts → types-D9WndxeD.d.mts} +1 -1
- package/dist/{types-BiZKJU41.d.ts → types-DiWBWvxg.d.ts} +1 -1
- package/package.json +1 -1
|
@@ -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-D9WndxeD.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-D9WndxeD.mjs';
|
|
3
|
+
import '../ir-B9zqlwjH.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-DiWBWvxg.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-DiWBWvxg.js';
|
|
3
|
+
import '../ir-B_XX2LAO.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, R as RecordInput, e as RecordOutcomeInput, O as OutcomeResult, f as OracleScore, g as CompileResult, B as BestPracticeAdvisory, h as
|
|
2
|
-
export {
|
|
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, R as RecordInput, e as RecordOutcomeInput, O as OutcomeResult, f as OracleScore, g as CompileResult, B as BestPracticeAdvisory, h as PerAxisMetrics, i as Provider, j as ChainEntry, G as Grounding } from './ir-B9zqlwjH.mjs';
|
|
2
|
+
export { k as CallAttempt, l as CallError, m as ChainWithGrounding, n as Constraints, F as FallbackReason, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, o as MutationApplied, p as NormalizedTokens, q as OutcomeKind, r as PerAxisMetricsByModel, s as PromptSection, T as ToolCall, t as ToolDefinition } from './ir-B9zqlwjH.mjs';
|
|
3
3
|
import { ModelProfile } from './profiles.mjs';
|
|
4
4
|
export { ALIASES, CacheStrategy, CliffRule, LoweringSpec, RecoveryRule, StructuredOutputCapability, SystemPromptMode, allProfiles, getProfile, profilesByProvider, tryGetProfile } from './profiles.mjs';
|
|
5
5
|
import { IntentArchetypeName } from './dialect.mjs';
|
|
@@ -367,6 +367,46 @@ declare function runAdvisor(ir: PromptIR, result: AdvisorContext, profile: Model
|
|
|
367
367
|
* `BrainConfig.brainQuery.<table> = false`.
|
|
368
368
|
*/
|
|
369
369
|
declare function isBrainQueryActiveFor(table: string): boolean;
|
|
370
|
+
interface GetPerAxisMetricsOpts {
|
|
371
|
+
/** App id to filter on. Required. */
|
|
372
|
+
appId: string;
|
|
373
|
+
/** Intent archetype to filter on. Required. */
|
|
374
|
+
archetype: string;
|
|
375
|
+
/** Canonical model id to filter on. Required. */
|
|
376
|
+
model: string;
|
|
377
|
+
/**
|
|
378
|
+
* Window in days. Default 30. Only rows with
|
|
379
|
+
* `created_at > now() - windowDays` are counted.
|
|
380
|
+
*/
|
|
381
|
+
windowDays?: number;
|
|
382
|
+
/**
|
|
383
|
+
* Consumer-declared quality floor (0..1 oracle/approve-rate scale).
|
|
384
|
+
* When set, the response's `qualityFloorMet` is true/false; when omitted,
|
|
385
|
+
* `qualityFloorMet` is null (no floor declared, no judgment).
|
|
386
|
+
*/
|
|
387
|
+
qualityFloor?: number;
|
|
388
|
+
/** Pluggable fetch (tests inject mock). Defaults to global fetch. */
|
|
389
|
+
fetch?: typeof fetch;
|
|
390
|
+
/**
|
|
391
|
+
* PostgREST base endpoint (e.g. `https://kgauto-brain.vercel.app/api`).
|
|
392
|
+
* When omitted, falls back to the active configureBrainQuery runtime's
|
|
393
|
+
* endpoint. Returns null when neither is set.
|
|
394
|
+
*/
|
|
395
|
+
endpoint?: string;
|
|
396
|
+
/** Bearer token. Forwarded as `Authorization: Bearer ${apiKey}`. */
|
|
397
|
+
apiKey?: string;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Call the `get_per_axis_metrics` RPC and return the typed result.
|
|
401
|
+
*
|
|
402
|
+
* Returns null when:
|
|
403
|
+
* - no endpoint provided AND no configureBrainQuery runtime active
|
|
404
|
+
* - RPC returns empty / null / unexpected shape
|
|
405
|
+
* - brain unreachable / fetch throws / HTTP error
|
|
406
|
+
*
|
|
407
|
+
* Never throws — operator-facing query, must not blow up the caller.
|
|
408
|
+
*/
|
|
409
|
+
declare function getPerAxisMetrics(opts: GetPerAxisMetricsOpts): Promise<PerAxisMetrics | null>;
|
|
370
410
|
|
|
371
411
|
/**
|
|
372
412
|
* env.ts — provider env-key resolution + reachability predicates.
|
|
@@ -903,4 +943,4 @@ declare const loadAliasesFromBrain: () => Record<string, string>;
|
|
|
903
943
|
*/
|
|
904
944
|
declare function compile(ir: PromptIR, opts?: CompileOptions): CompileResult;
|
|
905
945
|
|
|
906
|
-
export { ApiKeys, type AppOracle, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, BestPracticeAdvisory, type BrainConfig, type BrainQueryConfig, CallOptions, CallResult, ChainEntry, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, type GetDefaultFallbackChainOpts, Grounding, IntentArchetypeName, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type ModelBrainRow, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PROVIDER_ENV_KEYS, type PricingRow, type ProfileToRowOptions, PromptIR, Provider, ProviderOverrides, type ProviderReachability, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, type SupportedProvider, buildLLMJudge, call, clearBrain, compile, configureBrain, countTokens, execute, getAllStarterChains, getAllStarterChainsWithGrounding, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getReachabilityDiagnostic, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStarterChain, getStarterChainWithGrounding, isBrainQueryActiveFor, isModelReachable, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, profileToRow, record, recordOutcome, resetTokenizer, resolvePricingAt, resolveProviderKey, runAdvisor, setTokenizer };
|
|
946
|
+
export { ApiKeys, type AppOracle, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, BestPracticeAdvisory, type BrainConfig, type BrainQueryConfig, CallOptions, CallResult, ChainEntry, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, type GetDefaultFallbackChainOpts, type GetPerAxisMetricsOpts, Grounding, IntentArchetypeName, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type ModelBrainRow, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PROVIDER_ENV_KEYS, PerAxisMetrics, type PricingRow, type ProfileToRowOptions, PromptIR, Provider, ProviderOverrides, type ProviderReachability, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, type SupportedProvider, buildLLMJudge, call, clearBrain, compile, configureBrain, countTokens, execute, getAllStarterChains, getAllStarterChainsWithGrounding, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getPerAxisMetrics, getReachabilityDiagnostic, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStarterChain, getStarterChainWithGrounding, isBrainQueryActiveFor, isModelReachable, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, profileToRow, record, recordOutcome, resetTokenizer, resolvePricingAt, resolveProviderKey, runAdvisor, setTokenizer };
|
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, R as RecordInput, e as RecordOutcomeInput, O as OutcomeResult, f as OracleScore, g as CompileResult, B as BestPracticeAdvisory, h as
|
|
2
|
-
export {
|
|
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, R as RecordInput, e as RecordOutcomeInput, O as OutcomeResult, f as OracleScore, g as CompileResult, B as BestPracticeAdvisory, h as PerAxisMetrics, i as Provider, j as ChainEntry, G as Grounding } from './ir-B_XX2LAO.js';
|
|
2
|
+
export { k as CallAttempt, l as CallError, m as ChainWithGrounding, n as Constraints, F as FallbackReason, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, o as MutationApplied, p as NormalizedTokens, q as OutcomeKind, r as PerAxisMetricsByModel, s as PromptSection, T as ToolCall, t as ToolDefinition } from './ir-B_XX2LAO.js';
|
|
3
3
|
import { ModelProfile } from './profiles.js';
|
|
4
4
|
export { ALIASES, CacheStrategy, CliffRule, LoweringSpec, RecoveryRule, StructuredOutputCapability, SystemPromptMode, allProfiles, getProfile, profilesByProvider, tryGetProfile } from './profiles.js';
|
|
5
5
|
import { IntentArchetypeName } from './dialect.js';
|
|
@@ -367,6 +367,46 @@ declare function runAdvisor(ir: PromptIR, result: AdvisorContext, profile: Model
|
|
|
367
367
|
* `BrainConfig.brainQuery.<table> = false`.
|
|
368
368
|
*/
|
|
369
369
|
declare function isBrainQueryActiveFor(table: string): boolean;
|
|
370
|
+
interface GetPerAxisMetricsOpts {
|
|
371
|
+
/** App id to filter on. Required. */
|
|
372
|
+
appId: string;
|
|
373
|
+
/** Intent archetype to filter on. Required. */
|
|
374
|
+
archetype: string;
|
|
375
|
+
/** Canonical model id to filter on. Required. */
|
|
376
|
+
model: string;
|
|
377
|
+
/**
|
|
378
|
+
* Window in days. Default 30. Only rows with
|
|
379
|
+
* `created_at > now() - windowDays` are counted.
|
|
380
|
+
*/
|
|
381
|
+
windowDays?: number;
|
|
382
|
+
/**
|
|
383
|
+
* Consumer-declared quality floor (0..1 oracle/approve-rate scale).
|
|
384
|
+
* When set, the response's `qualityFloorMet` is true/false; when omitted,
|
|
385
|
+
* `qualityFloorMet` is null (no floor declared, no judgment).
|
|
386
|
+
*/
|
|
387
|
+
qualityFloor?: number;
|
|
388
|
+
/** Pluggable fetch (tests inject mock). Defaults to global fetch. */
|
|
389
|
+
fetch?: typeof fetch;
|
|
390
|
+
/**
|
|
391
|
+
* PostgREST base endpoint (e.g. `https://kgauto-brain.vercel.app/api`).
|
|
392
|
+
* When omitted, falls back to the active configureBrainQuery runtime's
|
|
393
|
+
* endpoint. Returns null when neither is set.
|
|
394
|
+
*/
|
|
395
|
+
endpoint?: string;
|
|
396
|
+
/** Bearer token. Forwarded as `Authorization: Bearer ${apiKey}`. */
|
|
397
|
+
apiKey?: string;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* Call the `get_per_axis_metrics` RPC and return the typed result.
|
|
401
|
+
*
|
|
402
|
+
* Returns null when:
|
|
403
|
+
* - no endpoint provided AND no configureBrainQuery runtime active
|
|
404
|
+
* - RPC returns empty / null / unexpected shape
|
|
405
|
+
* - brain unreachable / fetch throws / HTTP error
|
|
406
|
+
*
|
|
407
|
+
* Never throws — operator-facing query, must not blow up the caller.
|
|
408
|
+
*/
|
|
409
|
+
declare function getPerAxisMetrics(opts: GetPerAxisMetricsOpts): Promise<PerAxisMetrics | null>;
|
|
370
410
|
|
|
371
411
|
/**
|
|
372
412
|
* env.ts — provider env-key resolution + reachability predicates.
|
|
@@ -903,4 +943,4 @@ declare const loadAliasesFromBrain: () => Record<string, string>;
|
|
|
903
943
|
*/
|
|
904
944
|
declare function compile(ir: PromptIR, opts?: CompileOptions): CompileResult;
|
|
905
945
|
|
|
906
|
-
export { ApiKeys, type AppOracle, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, BestPracticeAdvisory, type BrainConfig, type BrainQueryConfig, CallOptions, CallResult, ChainEntry, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, type GetDefaultFallbackChainOpts, Grounding, IntentArchetypeName, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type ModelBrainRow, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PROVIDER_ENV_KEYS, type PricingRow, type ProfileToRowOptions, PromptIR, Provider, ProviderOverrides, type ProviderReachability, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, type SupportedProvider, buildLLMJudge, call, clearBrain, compile, configureBrain, countTokens, execute, getAllStarterChains, getAllStarterChainsWithGrounding, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getReachabilityDiagnostic, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStarterChain, getStarterChainWithGrounding, isBrainQueryActiveFor, isModelReachable, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, profileToRow, record, recordOutcome, resetTokenizer, resolvePricingAt, resolveProviderKey, runAdvisor, setTokenizer };
|
|
946
|
+
export { ApiKeys, type AppOracle, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, BestPracticeAdvisory, type BrainConfig, type BrainQueryConfig, CallOptions, CallResult, ChainEntry, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, type GetDefaultFallbackChainOpts, type GetPerAxisMetricsOpts, Grounding, IntentArchetypeName, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type ModelBrainRow, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PROVIDER_ENV_KEYS, PerAxisMetrics, type PricingRow, type ProfileToRowOptions, PromptIR, Provider, ProviderOverrides, type ProviderReachability, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, type SupportedProvider, buildLLMJudge, call, clearBrain, compile, configureBrain, countTokens, execute, getAllStarterChains, getAllStarterChainsWithGrounding, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getPerAxisMetrics, getReachabilityDiagnostic, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStarterChain, getStarterChainWithGrounding, isBrainQueryActiveFor, isModelReachable, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, profileToRow, record, recordOutcome, resetTokenizer, resolvePricingAt, resolveProviderKey, runAdvisor, setTokenizer };
|
package/dist/index.js
CHANGED
|
@@ -43,6 +43,7 @@ __export(index_exports, {
|
|
|
43
43
|
getArchetypePerfScore: () => getArchetypePerfScore,
|
|
44
44
|
getDefaultFallbackChain: () => getDefaultFallbackChain,
|
|
45
45
|
getDefaultFallbackChainWithGrounding: () => getDefaultFallbackChainWithGrounding,
|
|
46
|
+
getPerAxisMetrics: () => getPerAxisMetrics,
|
|
46
47
|
getProfile: () => getProfile,
|
|
47
48
|
getReachabilityDiagnostic: () => getReachabilityDiagnostic,
|
|
48
49
|
getSequentialStarterChain: () => getSequentialStarterChain,
|
|
@@ -2025,6 +2026,96 @@ function defaultOnError(err) {
|
|
|
2025
2026
|
function isBrainQueryActiveFor(table) {
|
|
2026
2027
|
return runtime !== void 0 && runtime.enabledTables.has(table);
|
|
2027
2028
|
}
|
|
2029
|
+
async function getPerAxisMetrics(opts) {
|
|
2030
|
+
const fetchFn = opts.fetch ?? fetch;
|
|
2031
|
+
const endpoint = opts.endpoint ?? runtime?.endpoint;
|
|
2032
|
+
if (!endpoint) return null;
|
|
2033
|
+
const windowDays = opts.windowDays ?? 30;
|
|
2034
|
+
const body = {
|
|
2035
|
+
p_app_id: opts.appId,
|
|
2036
|
+
p_archetype: opts.archetype,
|
|
2037
|
+
p_model: opts.model,
|
|
2038
|
+
p_window_days: windowDays,
|
|
2039
|
+
p_quality_floor: opts.qualityFloor ?? null
|
|
2040
|
+
};
|
|
2041
|
+
const headers = {
|
|
2042
|
+
Accept: "application/json",
|
|
2043
|
+
"Content-Type": "application/json",
|
|
2044
|
+
...opts.apiKey ? { Authorization: `Bearer ${opts.apiKey}` } : {}
|
|
2045
|
+
};
|
|
2046
|
+
try {
|
|
2047
|
+
const res = await fetchFn(`${endpoint}/rpc/get_per_axis_metrics`, {
|
|
2048
|
+
method: "POST",
|
|
2049
|
+
headers,
|
|
2050
|
+
body: JSON.stringify(body)
|
|
2051
|
+
});
|
|
2052
|
+
if (!res.ok) return null;
|
|
2053
|
+
const raw = await res.json();
|
|
2054
|
+
return mapPerAxisMetrics(raw, opts.appId, opts.archetype, opts.model, windowDays);
|
|
2055
|
+
} catch {
|
|
2056
|
+
return null;
|
|
2057
|
+
}
|
|
2058
|
+
}
|
|
2059
|
+
function mapPerAxisMetrics(raw, fallbackAppId, fallbackArchetype, fallbackModel, fallbackWindowDays) {
|
|
2060
|
+
if (raw === null || raw === void 0) return null;
|
|
2061
|
+
if (typeof raw !== "object") return null;
|
|
2062
|
+
const r = raw;
|
|
2063
|
+
if (Array.isArray(raw)) {
|
|
2064
|
+
if (raw.length === 0) return null;
|
|
2065
|
+
return mapPerAxisMetrics(raw[0], fallbackAppId, fallbackArchetype, fallbackModel, fallbackWindowDays);
|
|
2066
|
+
}
|
|
2067
|
+
const num = (v) => {
|
|
2068
|
+
if (v === null || v === void 0) return null;
|
|
2069
|
+
if (typeof v === "number") return Number.isFinite(v) ? v : null;
|
|
2070
|
+
if (typeof v === "string") {
|
|
2071
|
+
const n = Number(v);
|
|
2072
|
+
return Number.isFinite(n) ? n : null;
|
|
2073
|
+
}
|
|
2074
|
+
return null;
|
|
2075
|
+
};
|
|
2076
|
+
const int = (v) => {
|
|
2077
|
+
const n = num(v);
|
|
2078
|
+
return n === null ? 0 : Math.trunc(n);
|
|
2079
|
+
};
|
|
2080
|
+
const bool = (v) => {
|
|
2081
|
+
if (v === null || v === void 0) return null;
|
|
2082
|
+
if (typeof v === "boolean") return v;
|
|
2083
|
+
return null;
|
|
2084
|
+
};
|
|
2085
|
+
const str = (v, fallback) => typeof v === "string" ? v : fallback;
|
|
2086
|
+
const cost = r.cost_efficiency ?? {};
|
|
2087
|
+
const time = r.time_efficiency ?? {};
|
|
2088
|
+
const rel = r.reliability ?? {};
|
|
2089
|
+
return {
|
|
2090
|
+
appId: str(r.app_id, fallbackAppId),
|
|
2091
|
+
archetype: str(r.archetype, fallbackArchetype),
|
|
2092
|
+
model: str(r.model, fallbackModel),
|
|
2093
|
+
windowDays: num(r.window_days) ?? fallbackWindowDays,
|
|
2094
|
+
nRows: int(r.n_rows),
|
|
2095
|
+
nRowsClean: int(r.n_rows_clean),
|
|
2096
|
+
nQualityOutcomes: int(r.n_quality_outcomes),
|
|
2097
|
+
magicRate: num(r.magic_rate),
|
|
2098
|
+
qualityFloorMet: bool(r.quality_floor_met),
|
|
2099
|
+
costEfficiency: {
|
|
2100
|
+
avgCostUsd: num(cost.avg_cost_usd),
|
|
2101
|
+
avgCostUsdClean: num(cost.avg_cost_usd_clean),
|
|
2102
|
+
avgInputTokens: num(cost.avg_input_tokens),
|
|
2103
|
+
avgOutputTokens: num(cost.avg_output_tokens),
|
|
2104
|
+
inputTokenRatio: num(cost.input_token_ratio)
|
|
2105
|
+
},
|
|
2106
|
+
timeEfficiency: {
|
|
2107
|
+
avgLatencyMs: num(time.avg_latency_ms),
|
|
2108
|
+
avgTtftMs: num(time.avg_ttft_ms)
|
|
2109
|
+
},
|
|
2110
|
+
reliability: {
|
|
2111
|
+
successRate: num(rel.success_rate),
|
|
2112
|
+
successRateClean: num(rel.success_rate_clean),
|
|
2113
|
+
emptyRate: num(rel.empty_rate),
|
|
2114
|
+
emptyRateClean: num(rel.empty_rate_clean)
|
|
2115
|
+
},
|
|
2116
|
+
evidenceFreshnessDays: num(r.evidence_freshness_days)
|
|
2117
|
+
};
|
|
2118
|
+
}
|
|
2028
2119
|
|
|
2029
2120
|
// src/archetype-perf-brain.ts
|
|
2030
2121
|
function isPerfRow(x) {
|
|
@@ -4238,6 +4329,7 @@ function compile2(ir, opts) {
|
|
|
4238
4329
|
getArchetypePerfScore,
|
|
4239
4330
|
getDefaultFallbackChain,
|
|
4240
4331
|
getDefaultFallbackChainWithGrounding,
|
|
4332
|
+
getPerAxisMetrics,
|
|
4241
4333
|
getProfile,
|
|
4242
4334
|
getReachabilityDiagnostic,
|
|
4243
4335
|
getSequentialStarterChain,
|
package/dist/index.mjs
CHANGED
|
@@ -820,6 +820,96 @@ function defaultOnError(err) {
|
|
|
820
820
|
function isBrainQueryActiveFor(table) {
|
|
821
821
|
return runtime !== void 0 && runtime.enabledTables.has(table);
|
|
822
822
|
}
|
|
823
|
+
async function getPerAxisMetrics(opts) {
|
|
824
|
+
const fetchFn = opts.fetch ?? fetch;
|
|
825
|
+
const endpoint = opts.endpoint ?? runtime?.endpoint;
|
|
826
|
+
if (!endpoint) return null;
|
|
827
|
+
const windowDays = opts.windowDays ?? 30;
|
|
828
|
+
const body = {
|
|
829
|
+
p_app_id: opts.appId,
|
|
830
|
+
p_archetype: opts.archetype,
|
|
831
|
+
p_model: opts.model,
|
|
832
|
+
p_window_days: windowDays,
|
|
833
|
+
p_quality_floor: opts.qualityFloor ?? null
|
|
834
|
+
};
|
|
835
|
+
const headers = {
|
|
836
|
+
Accept: "application/json",
|
|
837
|
+
"Content-Type": "application/json",
|
|
838
|
+
...opts.apiKey ? { Authorization: `Bearer ${opts.apiKey}` } : {}
|
|
839
|
+
};
|
|
840
|
+
try {
|
|
841
|
+
const res = await fetchFn(`${endpoint}/rpc/get_per_axis_metrics`, {
|
|
842
|
+
method: "POST",
|
|
843
|
+
headers,
|
|
844
|
+
body: JSON.stringify(body)
|
|
845
|
+
});
|
|
846
|
+
if (!res.ok) return null;
|
|
847
|
+
const raw = await res.json();
|
|
848
|
+
return mapPerAxisMetrics(raw, opts.appId, opts.archetype, opts.model, windowDays);
|
|
849
|
+
} catch {
|
|
850
|
+
return null;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
function mapPerAxisMetrics(raw, fallbackAppId, fallbackArchetype, fallbackModel, fallbackWindowDays) {
|
|
854
|
+
if (raw === null || raw === void 0) return null;
|
|
855
|
+
if (typeof raw !== "object") return null;
|
|
856
|
+
const r = raw;
|
|
857
|
+
if (Array.isArray(raw)) {
|
|
858
|
+
if (raw.length === 0) return null;
|
|
859
|
+
return mapPerAxisMetrics(raw[0], fallbackAppId, fallbackArchetype, fallbackModel, fallbackWindowDays);
|
|
860
|
+
}
|
|
861
|
+
const num = (v) => {
|
|
862
|
+
if (v === null || v === void 0) return null;
|
|
863
|
+
if (typeof v === "number") return Number.isFinite(v) ? v : null;
|
|
864
|
+
if (typeof v === "string") {
|
|
865
|
+
const n = Number(v);
|
|
866
|
+
return Number.isFinite(n) ? n : null;
|
|
867
|
+
}
|
|
868
|
+
return null;
|
|
869
|
+
};
|
|
870
|
+
const int = (v) => {
|
|
871
|
+
const n = num(v);
|
|
872
|
+
return n === null ? 0 : Math.trunc(n);
|
|
873
|
+
};
|
|
874
|
+
const bool = (v) => {
|
|
875
|
+
if (v === null || v === void 0) return null;
|
|
876
|
+
if (typeof v === "boolean") return v;
|
|
877
|
+
return null;
|
|
878
|
+
};
|
|
879
|
+
const str = (v, fallback) => typeof v === "string" ? v : fallback;
|
|
880
|
+
const cost = r.cost_efficiency ?? {};
|
|
881
|
+
const time = r.time_efficiency ?? {};
|
|
882
|
+
const rel = r.reliability ?? {};
|
|
883
|
+
return {
|
|
884
|
+
appId: str(r.app_id, fallbackAppId),
|
|
885
|
+
archetype: str(r.archetype, fallbackArchetype),
|
|
886
|
+
model: str(r.model, fallbackModel),
|
|
887
|
+
windowDays: num(r.window_days) ?? fallbackWindowDays,
|
|
888
|
+
nRows: int(r.n_rows),
|
|
889
|
+
nRowsClean: int(r.n_rows_clean),
|
|
890
|
+
nQualityOutcomes: int(r.n_quality_outcomes),
|
|
891
|
+
magicRate: num(r.magic_rate),
|
|
892
|
+
qualityFloorMet: bool(r.quality_floor_met),
|
|
893
|
+
costEfficiency: {
|
|
894
|
+
avgCostUsd: num(cost.avg_cost_usd),
|
|
895
|
+
avgCostUsdClean: num(cost.avg_cost_usd_clean),
|
|
896
|
+
avgInputTokens: num(cost.avg_input_tokens),
|
|
897
|
+
avgOutputTokens: num(cost.avg_output_tokens),
|
|
898
|
+
inputTokenRatio: num(cost.input_token_ratio)
|
|
899
|
+
},
|
|
900
|
+
timeEfficiency: {
|
|
901
|
+
avgLatencyMs: num(time.avg_latency_ms),
|
|
902
|
+
avgTtftMs: num(time.avg_ttft_ms)
|
|
903
|
+
},
|
|
904
|
+
reliability: {
|
|
905
|
+
successRate: num(rel.success_rate),
|
|
906
|
+
successRateClean: num(rel.success_rate_clean),
|
|
907
|
+
emptyRate: num(rel.empty_rate),
|
|
908
|
+
emptyRateClean: num(rel.empty_rate_clean)
|
|
909
|
+
},
|
|
910
|
+
evidenceFreshnessDays: num(r.evidence_freshness_days)
|
|
911
|
+
};
|
|
912
|
+
}
|
|
823
913
|
|
|
824
914
|
// src/archetype-perf-brain.ts
|
|
825
915
|
function isPerfRow(x) {
|
|
@@ -2744,6 +2834,7 @@ export {
|
|
|
2744
2834
|
getArchetypePerfScore,
|
|
2745
2835
|
getDefaultFallbackChain,
|
|
2746
2836
|
getDefaultFallbackChainWithGrounding,
|
|
2837
|
+
getPerAxisMetrics,
|
|
2747
2838
|
getProfile,
|
|
2748
2839
|
getReachabilityDiagnostic,
|
|
2749
2840
|
getSequentialStarterChain,
|
|
@@ -796,5 +796,42 @@ interface ChainWithGrounding {
|
|
|
796
796
|
/** Ordered: position 0 = primary, rising index = fallback positions. */
|
|
797
797
|
entries: ChainEntry[];
|
|
798
798
|
}
|
|
799
|
+
/** alpha.23 (s78 Phase 3): per-axis metrics returned by the brain RPC. */
|
|
800
|
+
interface PerAxisMetrics {
|
|
801
|
+
appId: string;
|
|
802
|
+
archetype: string;
|
|
803
|
+
model: string;
|
|
804
|
+
windowDays: number;
|
|
805
|
+
/** Total brain rows for this tuple in the window. */
|
|
806
|
+
nRows: number;
|
|
807
|
+
/** Subset of nRows with zero advisories fired — the "clean signal" comparator. */
|
|
808
|
+
nRowsClean: number;
|
|
809
|
+
/** Count of compile_outcome_quality entries joining to this tuple's outcomes. */
|
|
810
|
+
nQualityOutcomes: number;
|
|
811
|
+
/** Approve rate from quality outcomes. null when nQualityOutcomes === 0. */
|
|
812
|
+
magicRate: number | null;
|
|
813
|
+
/** Whether magicRate >= consumer-declared qualityFloor. null when no floor declared OR no outcomes. */
|
|
814
|
+
qualityFloorMet: boolean | null;
|
|
815
|
+
costEfficiency: {
|
|
816
|
+
avgCostUsd: number | null;
|
|
817
|
+
avgCostUsdClean: number | null;
|
|
818
|
+
avgInputTokens: number | null;
|
|
819
|
+
avgOutputTokens: number | null;
|
|
820
|
+
inputTokenRatio: number | null;
|
|
821
|
+
};
|
|
822
|
+
timeEfficiency: {
|
|
823
|
+
avgLatencyMs: number | null;
|
|
824
|
+
avgTtftMs: number | null;
|
|
825
|
+
};
|
|
826
|
+
reliability: {
|
|
827
|
+
successRate: number | null;
|
|
828
|
+
successRateClean: number | null;
|
|
829
|
+
emptyRate: number | null;
|
|
830
|
+
emptyRateClean: number | null;
|
|
831
|
+
};
|
|
832
|
+
evidenceFreshnessDays: number | null;
|
|
833
|
+
}
|
|
834
|
+
/** Per-axis metrics keyed by model — used for chain-comparison views. */
|
|
835
|
+
type PerAxisMetricsByModel = Record<string, PerAxisMetrics>;
|
|
799
836
|
|
|
800
|
-
export { type ApiKeys as A, type BestPracticeAdvisory as B, type CompilePolicy as C, type FallbackReason as F, type Grounding as G, type HistoryCachePolicy as H, type IntentDeclaration as I, type Message as M, type NormalizedResponse as N, type OutcomeResult as O, type ProviderOverrides as P, type RecordInput as R, type ToolCall as T, type CompiledRequest as a, type PromptIR as b, type CallOptions as c, type CallResult as d, type RecordOutcomeInput as e, type OracleScore as f, type CompileResult as g, type
|
|
837
|
+
export { type ApiKeys as A, type BestPracticeAdvisory as B, type CompilePolicy as C, type FallbackReason as F, type Grounding as G, type HistoryCachePolicy as H, type IntentDeclaration as I, type Message as M, type NormalizedResponse as N, type OutcomeResult as O, type ProviderOverrides as P, type RecordInput as R, type ToolCall as T, type CompiledRequest as a, type PromptIR as b, type CallOptions as c, type CallResult as d, type RecordOutcomeInput as e, type OracleScore as f, type CompileResult as g, type PerAxisMetrics as h, type Provider as i, type ChainEntry as j, type CallAttempt as k, CallError as l, type ChainWithGrounding as m, type Constraints as n, type MutationApplied as o, type NormalizedTokens as p, type OutcomeKind as q, type PerAxisMetricsByModel as r, type PromptSection as s, type ToolDefinition as t };
|
|
@@ -796,5 +796,42 @@ interface ChainWithGrounding {
|
|
|
796
796
|
/** Ordered: position 0 = primary, rising index = fallback positions. */
|
|
797
797
|
entries: ChainEntry[];
|
|
798
798
|
}
|
|
799
|
+
/** alpha.23 (s78 Phase 3): per-axis metrics returned by the brain RPC. */
|
|
800
|
+
interface PerAxisMetrics {
|
|
801
|
+
appId: string;
|
|
802
|
+
archetype: string;
|
|
803
|
+
model: string;
|
|
804
|
+
windowDays: number;
|
|
805
|
+
/** Total brain rows for this tuple in the window. */
|
|
806
|
+
nRows: number;
|
|
807
|
+
/** Subset of nRows with zero advisories fired — the "clean signal" comparator. */
|
|
808
|
+
nRowsClean: number;
|
|
809
|
+
/** Count of compile_outcome_quality entries joining to this tuple's outcomes. */
|
|
810
|
+
nQualityOutcomes: number;
|
|
811
|
+
/** Approve rate from quality outcomes. null when nQualityOutcomes === 0. */
|
|
812
|
+
magicRate: number | null;
|
|
813
|
+
/** Whether magicRate >= consumer-declared qualityFloor. null when no floor declared OR no outcomes. */
|
|
814
|
+
qualityFloorMet: boolean | null;
|
|
815
|
+
costEfficiency: {
|
|
816
|
+
avgCostUsd: number | null;
|
|
817
|
+
avgCostUsdClean: number | null;
|
|
818
|
+
avgInputTokens: number | null;
|
|
819
|
+
avgOutputTokens: number | null;
|
|
820
|
+
inputTokenRatio: number | null;
|
|
821
|
+
};
|
|
822
|
+
timeEfficiency: {
|
|
823
|
+
avgLatencyMs: number | null;
|
|
824
|
+
avgTtftMs: number | null;
|
|
825
|
+
};
|
|
826
|
+
reliability: {
|
|
827
|
+
successRate: number | null;
|
|
828
|
+
successRateClean: number | null;
|
|
829
|
+
emptyRate: number | null;
|
|
830
|
+
emptyRateClean: number | null;
|
|
831
|
+
};
|
|
832
|
+
evidenceFreshnessDays: number | null;
|
|
833
|
+
}
|
|
834
|
+
/** Per-axis metrics keyed by model — used for chain-comparison views. */
|
|
835
|
+
type PerAxisMetricsByModel = Record<string, PerAxisMetrics>;
|
|
799
836
|
|
|
800
|
-
export { type ApiKeys as A, type BestPracticeAdvisory as B, type CompilePolicy as C, type FallbackReason as F, type Grounding as G, type HistoryCachePolicy as H, type IntentDeclaration as I, type Message as M, type NormalizedResponse as N, type OutcomeResult as O, type ProviderOverrides as P, type RecordInput as R, type ToolCall as T, type CompiledRequest as a, type PromptIR as b, type CallOptions as c, type CallResult as d, type RecordOutcomeInput as e, type OracleScore as f, type CompileResult as g, type
|
|
837
|
+
export { type ApiKeys as A, type BestPracticeAdvisory as B, type CompilePolicy as C, type FallbackReason as F, type Grounding as G, type HistoryCachePolicy as H, type IntentDeclaration as I, type Message as M, type NormalizedResponse as N, type OutcomeResult as O, type ProviderOverrides as P, type RecordInput as R, type ToolCall as T, type CompiledRequest as a, type PromptIR as b, type CallOptions as c, type CallResult as d, type RecordOutcomeInput as e, type OracleScore as f, type CompileResult as g, type PerAxisMetrics as h, type Provider as i, type ChainEntry as j, type CallAttempt as k, CallError as l, type ChainWithGrounding as m, type Constraints as n, type MutationApplied as o, type NormalizedTokens as p, type OutcomeKind as q, type PerAxisMetricsByModel as r, type PromptSection as s, type ToolDefinition as t };
|
package/dist/profiles.d.mts
CHANGED
package/dist/profiles.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { o as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, k as CallAttempt } from './ir-B9zqlwjH.mjs';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Glass-Box observability types (alpha.17).
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { o as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, k as CallAttempt } from './ir-B_XX2LAO.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.23",
|
|
4
4
|
"description": "Prompt compiler + central learning brain for multi-model AI apps. Swap models without rewriting prompts.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|