@warmdrift/kgauto-compiler 2.0.0-alpha.44 → 2.0.0-alpha.45
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/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/react/index.d.mts +2 -2
- package/dist/glassbox-routes/react/index.d.ts +2 -2
- package/dist/index.d.mts +68 -3
- package/dist/index.d.ts +68 -3
- package/dist/index.js +133 -0
- package/dist/index.mjs +130 -0
- package/dist/{ir-DARjQnvZ.d.mts → ir-BBKgsUX7.d.mts} +39 -1
- package/dist/{ir-DAUBaPhd.d.ts → ir-D3n-pBYI.d.ts} +39 -1
- package/dist/profiles.d.mts +1 -1
- package/dist/profiles.d.ts +1 -1
- package/dist/{types-CfVyRbCl.d.ts → types-B6z-8phQ.d.ts} +1 -1
- package/dist/{types-BDqNQxuX.d.ts → types-Bzw8tH-7.d.ts} +1 -1
- package/dist/{types-B5DzMhYm.d.mts → types-DMJqRzDF.d.mts} +1 -1
- package/dist/{types-Rq_fywDq.d.mts → types-xBWYk9Mm.d.mts} +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-DMJqRzDF.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-DMJqRzDF.mjs';
|
|
3
|
+
import '../ir-BBKgsUX7.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-Bzw8tH-7.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-Bzw8tH-7.js';
|
|
3
|
+
import '../ir-D3n-pBYI.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-DMJqRzDF.mjs';
|
|
2
|
+
import { a as TraceDetail, b as TraceSummary, c as TraceCounterfactual } from '../types-xBWYk9Mm.mjs';
|
|
3
|
+
export { A as AdvisoryRecord, T as TraceHealth, d as TraceSectionRewrite } from '../types-xBWYk9Mm.mjs';
|
|
4
|
+
import '../ir-BBKgsUX7.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-Bzw8tH-7.js';
|
|
2
|
+
import { a as TraceDetail, b as TraceSummary, c as TraceCounterfactual } from '../types-B6z-8phQ.js';
|
|
3
|
+
export { A as AdvisoryRecord, T as TraceHealth, d as TraceSectionRewrite } from '../types-B6z-8phQ.js';
|
|
4
|
+
import '../ir-D3n-pBYI.js';
|
|
5
5
|
import '../dialect.js';
|
|
6
6
|
|
|
7
7
|
/**
|
|
@@ -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-xBWYk9Mm.mjs';
|
|
3
|
+
import '../../ir-BBKgsUX7.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-B6z-8phQ.js';
|
|
3
|
+
import '../../ir-D3n-pBYI.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, f as SectionRewrite, R as RecordInput, g as RecordOutcomeInput, O as OutcomeResult, h as OracleScore, B as BestPracticeAdvisory, i as Adapter, j as PerAxisMetrics, k as Provider, l as ChainEntry, G as Grounding } from './ir-
|
|
2
|
-
export { m as CallAttempt, n as CallError, o as ChainModelEntry, p as ChainWithGrounding, q as Constraints, F as FallbackReason, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, r as MutationApplied, s as NormalizedTokens, t as OutcomeKind, u as PerAxisMetricsByModel, v as PromptSection, w as SectionKind, T as ToolCall,
|
|
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, f as SectionRewrite, R as RecordInput, g as RecordOutcomeInput, O as OutcomeResult, h as OracleScore, B as BestPracticeAdvisory, i as Adapter, j as PerAxisMetrics, k as Provider, l as ChainEntry, G as Grounding } from './ir-BBKgsUX7.mjs';
|
|
2
|
+
export { m as CallAttempt, n as CallError, o as ChainModelEntry, p as ChainWithGrounding, q as Constraints, F as FallbackReason, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, r as MutationApplied, s as NormalizedTokens, t as OutcomeKind, u as PerAxisMetricsByModel, v as PromptSection, w as SectionKind, x as ShadowProbeConfig, T as ToolCall, y as ToolDefinition } from './ir-BBKgsUX7.mjs';
|
|
3
3
|
import { ModelProfile, ArchetypeConvention } 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';
|
|
@@ -335,6 +335,71 @@ interface OutcomePayload {
|
|
|
335
335
|
* failure. Never throws.
|
|
336
336
|
*/
|
|
337
337
|
declare function recordOutcome(input: RecordOutcomeInput): Promise<OutcomeResult>;
|
|
338
|
+
/**
|
|
339
|
+
* True when the active brain config requests synchronous (awaited) writes.
|
|
340
|
+
* call()'s shadow-probe path reads this to decide whether to await the probe
|
|
341
|
+
* (Edge/Worker/Lambda — L-086) or fire-and-forget (Node). False when no brain
|
|
342
|
+
* is configured.
|
|
343
|
+
*/
|
|
344
|
+
declare function isBrainSync(): boolean;
|
|
345
|
+
/**
|
|
346
|
+
* Full-IR inline shadow-probe record input (Shape B, Phase 1 — s51). Carries
|
|
347
|
+
* ONLY response previews + metadata; the prompt (system/context/payload) is
|
|
348
|
+
* never included — `promptHash` is an irreversible grouping key, not content.
|
|
349
|
+
*/
|
|
350
|
+
interface ShadowProbeRecordInput {
|
|
351
|
+
appId: string;
|
|
352
|
+
archetype: string;
|
|
353
|
+
family: string;
|
|
354
|
+
candidateModel: string;
|
|
355
|
+
currentModel: string;
|
|
356
|
+
/** Irreversible grouping hash (NOT the prompt). */
|
|
357
|
+
promptHash: string;
|
|
358
|
+
/** Served model's response, truncated (RESPONSE text only — never the prompt). */
|
|
359
|
+
currentResponsePreview?: string;
|
|
360
|
+
/** Candidate model's response, truncated. */
|
|
361
|
+
candidateResponsePreview?: string;
|
|
362
|
+
tokensCurrentIn?: number;
|
|
363
|
+
tokensCurrentOut?: number;
|
|
364
|
+
tokensCandidateIn?: number;
|
|
365
|
+
tokensCandidateOut?: number;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Pure builder for the `probe_outcomes` row written by the inline shadow-probe.
|
|
369
|
+
* Exported so a test can assert the G3 privacy invariant: the row carries NO
|
|
370
|
+
* prompt/system/context text — only response previews + metadata + a hash.
|
|
371
|
+
*
|
|
372
|
+
* Phase 1 (judge: 'off'): `judge_verdict` / `judge_score` are null — the row
|
|
373
|
+
* is an unjudged sample for the Phase-2 offline batch judge. `prompt_fidelity`
|
|
374
|
+
* is 1.0 by construction (the candidate ran the full IR, not a truncated
|
|
375
|
+
* preview), and `replay_source='inline-full-ir'` marks it as a trustworthy row
|
|
376
|
+
* (vs the watchers' lossy `replay-preview`).
|
|
377
|
+
*/
|
|
378
|
+
declare function buildShadowProbeRow(input: ShadowProbeRecordInput): {
|
|
379
|
+
app_id: string;
|
|
380
|
+
intent_archetype: string;
|
|
381
|
+
family: string;
|
|
382
|
+
candidate_model: string;
|
|
383
|
+
current_model: string;
|
|
384
|
+
prompt_hash: string;
|
|
385
|
+
current_response: string | null;
|
|
386
|
+
candidate_response: string | null;
|
|
387
|
+
judge_verdict: null;
|
|
388
|
+
judge_score: null;
|
|
389
|
+
tokens_current_in: number | null;
|
|
390
|
+
tokens_current_out: number | null;
|
|
391
|
+
tokens_candidate_in: number | null;
|
|
392
|
+
tokens_candidate_out: number | null;
|
|
393
|
+
prompt_fidelity: number;
|
|
394
|
+
replay_source: 'inline-full-ir';
|
|
395
|
+
};
|
|
396
|
+
/**
|
|
397
|
+
* Persist one inline shadow-probe row to `probe_outcomes`. Fire-and-forget by
|
|
398
|
+
* default; honors `BrainConfig.sync` (L-086). Never throws — failures route to
|
|
399
|
+
* onError. Mirrors record()'s POST shape; consumer proxies forward
|
|
400
|
+
* `/probe_outcomes` the same way they forward `/outcomes`.
|
|
401
|
+
*/
|
|
402
|
+
declare function recordShadowProbe(input: ShadowProbeRecordInput): Promise<void>;
|
|
338
403
|
|
|
339
404
|
/**
|
|
340
405
|
* Oracle contract — how an app tells the brain whether a response was good.
|
|
@@ -2119,4 +2184,4 @@ declare function markPromoteReadyHandled(opts: MarkPromoteReadyHandledOptions):
|
|
|
2119
2184
|
*/
|
|
2120
2185
|
declare function compile(ir: PromptIR, opts?: CompileOptions): CompileResult;
|
|
2121
2186
|
|
|
2122
|
-
export { ABSOLUTE_FLOOR, type AISDKConvertedMessage, ARCHETYPE_FAMILY_FITS, ARCHETYPE_FLOOR_DEFAULT, type ActionableAdvisory, Adapter, type AdvisoryResolutionSource, type AdvisorySeverity, type AdvisoryStatus, type AdvisorySuggestedFix, ApiKeys, type AppOracle, type ApplySectionRewritesArgs, type ApplySectionRewritesResult, ArchetypeConvention, type ArchetypeFamilyFit, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, type AttachCacheControlResult, BestPracticeAdvisory, type BrainConfig, type BrainQueryConfig, type BrainReadEnv, CallOptions, CallResult, ChainEntry, type CompatibilityIntent, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, DEFAULT_FINDINGS_ENDPOINT, type ExclusionFindingRow, type ExclusionResolutionSource, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, FamilyResolutionError, type GetActionableAdvisoriesOptions, type GetDefaultFallbackChainOpts, type GetPerAxisMetricsOpts, type GetRecommendedPrimaryOptions, Grounding, IntentArchetypeName, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type MarkAdvisoryResolvedOptions, type MarkExclusionFindingHandledOptions, type MarkPromoteReadyHandledOptions, type ModelBrainRow, type ModelCompatibility, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PRODUCER_OWNED_RULE_CODES, PROVIDER_ENV_KEYS, PerAxisMetrics, type PricingRow, type ProfileToRowOptions, type PromoteReadyFindingRow, type PromoteReadyResolution, PromptIR, Provider, ProviderOverrides, type ProviderReachability, RULE_SEQUENTIAL_TOOL_CLIFF, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, SectionRewrite, type SupportedProvider, SystemModelMessage, TRANSLATOR_FLOOR, applyArchetypeConvention, applySectionRewrites, attachCacheControlToStreamTextInput, buildLLMJudge, call, clearBrain, compile, configureBrain, countTokens, deriveFamilyFromModelId, deriveOwnership, execute, findBetterFit, getActionableAdvisories, getAllStarterChains, getAllStarterChainsWithGrounding, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getModelCompatibility, getPerAxisMetrics, getReachabilityDiagnostic, getRecommendedPrimary, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStaleExclusionFindings, getStarterChain, getStarterChainWithGrounding, isBrainQueryActiveFor, isExclusionFindingsBrainActive, isModelReachable, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, markAdvisoryResolved, markExclusionFindingHandled, markPromoteReadyHandled, profileToRow, readBrainReadEnv, record, recordOutcome, resetTokenizer, resolveConventionsForProfile, resolvePricingAt, resolveProviderKey, runAdvisor, setTokenizer };
|
|
2187
|
+
export { ABSOLUTE_FLOOR, type AISDKConvertedMessage, ARCHETYPE_FAMILY_FITS, ARCHETYPE_FLOOR_DEFAULT, type ActionableAdvisory, Adapter, type AdvisoryResolutionSource, type AdvisorySeverity, type AdvisoryStatus, type AdvisorySuggestedFix, ApiKeys, type AppOracle, type ApplySectionRewritesArgs, type ApplySectionRewritesResult, ArchetypeConvention, type ArchetypeFamilyFit, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, type AttachCacheControlResult, BestPracticeAdvisory, type BrainConfig, type BrainQueryConfig, type BrainReadEnv, CallOptions, CallResult, ChainEntry, type CompatibilityIntent, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, DEFAULT_FINDINGS_ENDPOINT, type ExclusionFindingRow, type ExclusionResolutionSource, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, FamilyResolutionError, type GetActionableAdvisoriesOptions, type GetDefaultFallbackChainOpts, type GetPerAxisMetricsOpts, type GetRecommendedPrimaryOptions, Grounding, IntentArchetypeName, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type MarkAdvisoryResolvedOptions, type MarkExclusionFindingHandledOptions, type MarkPromoteReadyHandledOptions, type ModelBrainRow, type ModelCompatibility, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PRODUCER_OWNED_RULE_CODES, PROVIDER_ENV_KEYS, PerAxisMetrics, type PricingRow, type ProfileToRowOptions, type PromoteReadyFindingRow, type PromoteReadyResolution, PromptIR, Provider, ProviderOverrides, type ProviderReachability, RULE_SEQUENTIAL_TOOL_CLIFF, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, SectionRewrite, type ShadowProbeRecordInput, type SupportedProvider, SystemModelMessage, TRANSLATOR_FLOOR, applyArchetypeConvention, applySectionRewrites, attachCacheControlToStreamTextInput, buildLLMJudge, buildShadowProbeRow, call, clearBrain, compile, configureBrain, countTokens, deriveFamilyFromModelId, deriveOwnership, execute, findBetterFit, getActionableAdvisories, getAllStarterChains, getAllStarterChainsWithGrounding, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getModelCompatibility, getPerAxisMetrics, getReachabilityDiagnostic, getRecommendedPrimary, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStaleExclusionFindings, getStarterChain, getStarterChainWithGrounding, isBrainQueryActiveFor, isBrainSync, isExclusionFindingsBrainActive, isModelReachable, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, markAdvisoryResolved, markExclusionFindingHandled, markPromoteReadyHandled, profileToRow, readBrainReadEnv, record, recordOutcome, recordShadowProbe, resetTokenizer, resolveConventionsForProfile, 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, S as SystemModelMessage, e as CompileResult, f as SectionRewrite, R as RecordInput, g as RecordOutcomeInput, O as OutcomeResult, h as OracleScore, B as BestPracticeAdvisory, i as Adapter, j as PerAxisMetrics, k as Provider, l as ChainEntry, G as Grounding } from './ir-
|
|
2
|
-
export { m as CallAttempt, n as CallError, o as ChainModelEntry, p as ChainWithGrounding, q as Constraints, F as FallbackReason, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, r as MutationApplied, s as NormalizedTokens, t as OutcomeKind, u as PerAxisMetricsByModel, v as PromptSection, w as SectionKind, T as ToolCall,
|
|
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, f as SectionRewrite, R as RecordInput, g as RecordOutcomeInput, O as OutcomeResult, h as OracleScore, B as BestPracticeAdvisory, i as Adapter, j as PerAxisMetrics, k as Provider, l as ChainEntry, G as Grounding } from './ir-D3n-pBYI.js';
|
|
2
|
+
export { m as CallAttempt, n as CallError, o as ChainModelEntry, p as ChainWithGrounding, q as Constraints, F as FallbackReason, H as HistoryCachePolicy, I as IntentDeclaration, M as Message, r as MutationApplied, s as NormalizedTokens, t as OutcomeKind, u as PerAxisMetricsByModel, v as PromptSection, w as SectionKind, x as ShadowProbeConfig, T as ToolCall, y as ToolDefinition } from './ir-D3n-pBYI.js';
|
|
3
3
|
import { ModelProfile, ArchetypeConvention } 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';
|
|
@@ -335,6 +335,71 @@ interface OutcomePayload {
|
|
|
335
335
|
* failure. Never throws.
|
|
336
336
|
*/
|
|
337
337
|
declare function recordOutcome(input: RecordOutcomeInput): Promise<OutcomeResult>;
|
|
338
|
+
/**
|
|
339
|
+
* True when the active brain config requests synchronous (awaited) writes.
|
|
340
|
+
* call()'s shadow-probe path reads this to decide whether to await the probe
|
|
341
|
+
* (Edge/Worker/Lambda — L-086) or fire-and-forget (Node). False when no brain
|
|
342
|
+
* is configured.
|
|
343
|
+
*/
|
|
344
|
+
declare function isBrainSync(): boolean;
|
|
345
|
+
/**
|
|
346
|
+
* Full-IR inline shadow-probe record input (Shape B, Phase 1 — s51). Carries
|
|
347
|
+
* ONLY response previews + metadata; the prompt (system/context/payload) is
|
|
348
|
+
* never included — `promptHash` is an irreversible grouping key, not content.
|
|
349
|
+
*/
|
|
350
|
+
interface ShadowProbeRecordInput {
|
|
351
|
+
appId: string;
|
|
352
|
+
archetype: string;
|
|
353
|
+
family: string;
|
|
354
|
+
candidateModel: string;
|
|
355
|
+
currentModel: string;
|
|
356
|
+
/** Irreversible grouping hash (NOT the prompt). */
|
|
357
|
+
promptHash: string;
|
|
358
|
+
/** Served model's response, truncated (RESPONSE text only — never the prompt). */
|
|
359
|
+
currentResponsePreview?: string;
|
|
360
|
+
/** Candidate model's response, truncated. */
|
|
361
|
+
candidateResponsePreview?: string;
|
|
362
|
+
tokensCurrentIn?: number;
|
|
363
|
+
tokensCurrentOut?: number;
|
|
364
|
+
tokensCandidateIn?: number;
|
|
365
|
+
tokensCandidateOut?: number;
|
|
366
|
+
}
|
|
367
|
+
/**
|
|
368
|
+
* Pure builder for the `probe_outcomes` row written by the inline shadow-probe.
|
|
369
|
+
* Exported so a test can assert the G3 privacy invariant: the row carries NO
|
|
370
|
+
* prompt/system/context text — only response previews + metadata + a hash.
|
|
371
|
+
*
|
|
372
|
+
* Phase 1 (judge: 'off'): `judge_verdict` / `judge_score` are null — the row
|
|
373
|
+
* is an unjudged sample for the Phase-2 offline batch judge. `prompt_fidelity`
|
|
374
|
+
* is 1.0 by construction (the candidate ran the full IR, not a truncated
|
|
375
|
+
* preview), and `replay_source='inline-full-ir'` marks it as a trustworthy row
|
|
376
|
+
* (vs the watchers' lossy `replay-preview`).
|
|
377
|
+
*/
|
|
378
|
+
declare function buildShadowProbeRow(input: ShadowProbeRecordInput): {
|
|
379
|
+
app_id: string;
|
|
380
|
+
intent_archetype: string;
|
|
381
|
+
family: string;
|
|
382
|
+
candidate_model: string;
|
|
383
|
+
current_model: string;
|
|
384
|
+
prompt_hash: string;
|
|
385
|
+
current_response: string | null;
|
|
386
|
+
candidate_response: string | null;
|
|
387
|
+
judge_verdict: null;
|
|
388
|
+
judge_score: null;
|
|
389
|
+
tokens_current_in: number | null;
|
|
390
|
+
tokens_current_out: number | null;
|
|
391
|
+
tokens_candidate_in: number | null;
|
|
392
|
+
tokens_candidate_out: number | null;
|
|
393
|
+
prompt_fidelity: number;
|
|
394
|
+
replay_source: 'inline-full-ir';
|
|
395
|
+
};
|
|
396
|
+
/**
|
|
397
|
+
* Persist one inline shadow-probe row to `probe_outcomes`. Fire-and-forget by
|
|
398
|
+
* default; honors `BrainConfig.sync` (L-086). Never throws — failures route to
|
|
399
|
+
* onError. Mirrors record()'s POST shape; consumer proxies forward
|
|
400
|
+
* `/probe_outcomes` the same way they forward `/outcomes`.
|
|
401
|
+
*/
|
|
402
|
+
declare function recordShadowProbe(input: ShadowProbeRecordInput): Promise<void>;
|
|
338
403
|
|
|
339
404
|
/**
|
|
340
405
|
* Oracle contract — how an app tells the brain whether a response was good.
|
|
@@ -2119,4 +2184,4 @@ declare function markPromoteReadyHandled(opts: MarkPromoteReadyHandledOptions):
|
|
|
2119
2184
|
*/
|
|
2120
2185
|
declare function compile(ir: PromptIR, opts?: CompileOptions): CompileResult;
|
|
2121
2186
|
|
|
2122
|
-
export { ABSOLUTE_FLOOR, type AISDKConvertedMessage, ARCHETYPE_FAMILY_FITS, ARCHETYPE_FLOOR_DEFAULT, type ActionableAdvisory, Adapter, type AdvisoryResolutionSource, type AdvisorySeverity, type AdvisoryStatus, type AdvisorySuggestedFix, ApiKeys, type AppOracle, type ApplySectionRewritesArgs, type ApplySectionRewritesResult, ArchetypeConvention, type ArchetypeFamilyFit, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, type AttachCacheControlResult, BestPracticeAdvisory, type BrainConfig, type BrainQueryConfig, type BrainReadEnv, CallOptions, CallResult, ChainEntry, type CompatibilityIntent, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, DEFAULT_FINDINGS_ENDPOINT, type ExclusionFindingRow, type ExclusionResolutionSource, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, FamilyResolutionError, type GetActionableAdvisoriesOptions, type GetDefaultFallbackChainOpts, type GetPerAxisMetricsOpts, type GetRecommendedPrimaryOptions, Grounding, IntentArchetypeName, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type MarkAdvisoryResolvedOptions, type MarkExclusionFindingHandledOptions, type MarkPromoteReadyHandledOptions, type ModelBrainRow, type ModelCompatibility, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PRODUCER_OWNED_RULE_CODES, PROVIDER_ENV_KEYS, PerAxisMetrics, type PricingRow, type ProfileToRowOptions, type PromoteReadyFindingRow, type PromoteReadyResolution, PromptIR, Provider, ProviderOverrides, type ProviderReachability, RULE_SEQUENTIAL_TOOL_CLIFF, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, SectionRewrite, type SupportedProvider, SystemModelMessage, TRANSLATOR_FLOOR, applyArchetypeConvention, applySectionRewrites, attachCacheControlToStreamTextInput, buildLLMJudge, call, clearBrain, compile, configureBrain, countTokens, deriveFamilyFromModelId, deriveOwnership, execute, findBetterFit, getActionableAdvisories, getAllStarterChains, getAllStarterChainsWithGrounding, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getModelCompatibility, getPerAxisMetrics, getReachabilityDiagnostic, getRecommendedPrimary, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStaleExclusionFindings, getStarterChain, getStarterChainWithGrounding, isBrainQueryActiveFor, isExclusionFindingsBrainActive, isModelReachable, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, markAdvisoryResolved, markExclusionFindingHandled, markPromoteReadyHandled, profileToRow, readBrainReadEnv, record, recordOutcome, resetTokenizer, resolveConventionsForProfile, resolvePricingAt, resolveProviderKey, runAdvisor, setTokenizer };
|
|
2187
|
+
export { ABSOLUTE_FLOOR, type AISDKConvertedMessage, ARCHETYPE_FAMILY_FITS, ARCHETYPE_FLOOR_DEFAULT, type ActionableAdvisory, Adapter, type AdvisoryResolutionSource, type AdvisorySeverity, type AdvisoryStatus, type AdvisorySuggestedFix, ApiKeys, type AppOracle, type ApplySectionRewritesArgs, type ApplySectionRewritesResult, ArchetypeConvention, type ArchetypeFamilyFit, type ArchetypePerfMap, type ArchetypePerfNMap, type ArchetypePerfScoreResult, type AttachCacheControlResult, BestPracticeAdvisory, type BrainConfig, type BrainQueryConfig, type BrainReadEnv, CallOptions, CallResult, ChainEntry, type CompatibilityIntent, type CompileOptions, CompilePolicy, CompileResult, CompiledRequest, DEFAULT_FINDINGS_ENDPOINT, type ExclusionFindingRow, type ExclusionResolutionSource, type ExecuteErr, type ExecuteOk, type ExecuteOptions, type ExecuteResult, type FallbackPosture, FamilyResolutionError, type GetActionableAdvisoriesOptions, type GetDefaultFallbackChainOpts, type GetPerAxisMetricsOpts, type GetRecommendedPrimaryOptions, Grounding, IntentArchetypeName, type LLMJudgeOptions, MEASURED_GROUNDING_MIN_N, type MarkAdvisoryResolvedOptions, type MarkExclusionFindingHandledOptions, type MarkPromoteReadyHandledOptions, type ModelBrainRow, type ModelCompatibility, ModelProfile, NormalizedResponse, type OracleContext, OracleScore, type OutcomePayload, OutcomeResult, PRODUCER_OWNED_RULE_CODES, PROVIDER_ENV_KEYS, PerAxisMetrics, type PricingRow, type ProfileToRowOptions, type PromoteReadyFindingRow, type PromoteReadyResolution, PromptIR, Provider, ProviderOverrides, type ProviderReachability, RULE_SEQUENTIAL_TOOL_CLIFF, type ReachabilityOpts, RecordInput, RecordOutcomeInput, type RunAdvisorPhase2Context, SectionRewrite, type ShadowProbeRecordInput, type SupportedProvider, SystemModelMessage, TRANSLATOR_FLOOR, applyArchetypeConvention, applySectionRewrites, attachCacheControlToStreamTextInput, buildLLMJudge, buildShadowProbeRow, call, clearBrain, compile, configureBrain, countTokens, deriveFamilyFromModelId, deriveOwnership, execute, findBetterFit, getActionableAdvisories, getAllStarterChains, getAllStarterChainsWithGrounding, getArchetypePerfScore, getDefaultFallbackChain, getDefaultFallbackChainWithGrounding, getModelCompatibility, getPerAxisMetrics, getReachabilityDiagnostic, getRecommendedPrimary, getSequentialStarterChain, getSequentialStarterChainWithGrounding, getStaleExclusionFindings, getStarterChain, getStarterChainWithGrounding, isBrainQueryActiveFor, isBrainSync, isExclusionFindingsBrainActive, isModelReachable, isProviderReachable, loadAliasesFromBrain, loadArchetypePerfFromBrain, loadArchetypePerfNFromBrain, loadChainsFromBrain, loadModelsFromBrain, loadPricingFromBrain, markAdvisoryResolved, markExclusionFindingHandled, markPromoteReadyHandled, profileToRow, readBrainReadEnv, record, recordOutcome, recordShadowProbe, resetTokenizer, resolveConventionsForProfile, resolvePricingAt, resolveProviderKey, runAdvisor, setTokenizer };
|
package/dist/index.js
CHANGED
|
@@ -43,6 +43,7 @@ __export(index_exports, {
|
|
|
43
43
|
bucketHistory: () => bucketHistory,
|
|
44
44
|
bucketToolCount: () => bucketToolCount,
|
|
45
45
|
buildLLMJudge: () => buildLLMJudge,
|
|
46
|
+
buildShadowProbeRow: () => buildShadowProbeRow,
|
|
46
47
|
call: () => call,
|
|
47
48
|
clearBrain: () => clearBrain,
|
|
48
49
|
compile: () => compile2,
|
|
@@ -71,6 +72,7 @@ __export(index_exports, {
|
|
|
71
72
|
hashShape: () => hashShape,
|
|
72
73
|
isArchetype: () => isArchetype,
|
|
73
74
|
isBrainQueryActiveFor: () => isBrainQueryActiveFor,
|
|
75
|
+
isBrainSync: () => isBrainSync,
|
|
74
76
|
isExclusionFindingsBrainActive: () => isExclusionFindingsBrainActive,
|
|
75
77
|
isModelReachable: () => isModelReachable,
|
|
76
78
|
isProviderReachable: () => isProviderReachable,
|
|
@@ -89,6 +91,7 @@ __export(index_exports, {
|
|
|
89
91
|
readBrainReadEnv: () => readBrainReadEnv,
|
|
90
92
|
record: () => record,
|
|
91
93
|
recordOutcome: () => recordOutcome,
|
|
94
|
+
recordShadowProbe: () => recordShadowProbe,
|
|
92
95
|
resetTokenizer: () => resetTokenizer,
|
|
93
96
|
resolveConventionsForProfile: () => resolveConventionsForProfile,
|
|
94
97
|
resolvePricingAt: () => resolvePricingAt,
|
|
@@ -4472,6 +4475,61 @@ async function recordOutcome(input) {
|
|
|
4472
4475
|
void send();
|
|
4473
4476
|
return { ok: true };
|
|
4474
4477
|
}
|
|
4478
|
+
function isBrainSync() {
|
|
4479
|
+
return activeConfig?.sync === true;
|
|
4480
|
+
}
|
|
4481
|
+
function buildShadowProbeRow(input) {
|
|
4482
|
+
return {
|
|
4483
|
+
app_id: input.appId,
|
|
4484
|
+
intent_archetype: input.archetype,
|
|
4485
|
+
family: input.family,
|
|
4486
|
+
candidate_model: input.candidateModel,
|
|
4487
|
+
current_model: input.currentModel,
|
|
4488
|
+
prompt_hash: input.promptHash,
|
|
4489
|
+
current_response: input.currentResponsePreview ?? null,
|
|
4490
|
+
candidate_response: input.candidateResponsePreview ?? null,
|
|
4491
|
+
judge_verdict: null,
|
|
4492
|
+
judge_score: null,
|
|
4493
|
+
tokens_current_in: input.tokensCurrentIn ?? null,
|
|
4494
|
+
tokens_current_out: input.tokensCurrentOut ?? null,
|
|
4495
|
+
tokens_candidate_in: input.tokensCandidateIn ?? null,
|
|
4496
|
+
tokens_candidate_out: input.tokensCandidateOut ?? null,
|
|
4497
|
+
// Full IR was replayed (not a truncated preview), so fidelity is 1.0 — the
|
|
4498
|
+
// prompt-fidelity guard never fires on these rows.
|
|
4499
|
+
prompt_fidelity: 1,
|
|
4500
|
+
replay_source: "inline-full-ir"
|
|
4501
|
+
};
|
|
4502
|
+
}
|
|
4503
|
+
async function recordShadowProbe(input) {
|
|
4504
|
+
if (!activeConfig) return;
|
|
4505
|
+
const config = activeConfig;
|
|
4506
|
+
const fetchFn = config.fetchImpl ?? fetch;
|
|
4507
|
+
const row = buildShadowProbeRow(input);
|
|
4508
|
+
const send = async () => {
|
|
4509
|
+
try {
|
|
4510
|
+
const res = await fetchFn(`${config.endpoint}/probe_outcomes`, {
|
|
4511
|
+
method: "POST",
|
|
4512
|
+
headers: {
|
|
4513
|
+
"Content-Type": "application/json",
|
|
4514
|
+
Prefer: "return=minimal",
|
|
4515
|
+
...config.apiKey ? { Authorization: `Bearer ${config.apiKey}` } : {}
|
|
4516
|
+
},
|
|
4517
|
+
body: JSON.stringify(row)
|
|
4518
|
+
});
|
|
4519
|
+
if (!res.ok) {
|
|
4520
|
+
const text = await res.text().catch(() => "<no body>");
|
|
4521
|
+
throw new Error(`brain probe_outcomes ${res.status}: ${text}`);
|
|
4522
|
+
}
|
|
4523
|
+
} catch (err) {
|
|
4524
|
+
(config.onError ?? defaultOnError5)(err);
|
|
4525
|
+
}
|
|
4526
|
+
};
|
|
4527
|
+
if (config.sync) {
|
|
4528
|
+
await send();
|
|
4529
|
+
} else {
|
|
4530
|
+
void send();
|
|
4531
|
+
}
|
|
4532
|
+
}
|
|
4475
4533
|
|
|
4476
4534
|
// src/ir.ts
|
|
4477
4535
|
var CallError = class extends Error {
|
|
@@ -5951,6 +6009,19 @@ async function call(ir, opts = {}) {
|
|
|
5951
6009
|
);
|
|
5952
6010
|
}
|
|
5953
6011
|
}
|
|
6012
|
+
if (opts.shadowProbe) {
|
|
6013
|
+
const probe = runShadowProbe({
|
|
6014
|
+
ir,
|
|
6015
|
+
opts,
|
|
6016
|
+
servedModel: targetModel,
|
|
6017
|
+
servedResponse: validated.response
|
|
6018
|
+
});
|
|
6019
|
+
if (isBrainSync()) {
|
|
6020
|
+
await probe;
|
|
6021
|
+
} else {
|
|
6022
|
+
void probe;
|
|
6023
|
+
}
|
|
6024
|
+
}
|
|
5954
6025
|
return {
|
|
5955
6026
|
handle: initial.handle,
|
|
5956
6027
|
actualModel: targetModel,
|
|
@@ -6023,6 +6094,65 @@ function extractPromptPreview(ir) {
|
|
|
6023
6094
|
if (lastHist) return lastHist.slice(0, 200);
|
|
6024
6095
|
return void 0;
|
|
6025
6096
|
}
|
|
6097
|
+
function shouldSampleProbe(sampleRate, rng = Math.random) {
|
|
6098
|
+
if (!(sampleRate > 0)) return false;
|
|
6099
|
+
if (sampleRate >= 1) return true;
|
|
6100
|
+
return rng() < sampleRate;
|
|
6101
|
+
}
|
|
6102
|
+
function normalizeProbeCandidates(candidates) {
|
|
6103
|
+
const arr = Array.isArray(candidates) ? candidates : [candidates];
|
|
6104
|
+
return [...new Set(arr.filter((c) => typeof c === "string" && c.length > 0))];
|
|
6105
|
+
}
|
|
6106
|
+
function hashForProbe(s) {
|
|
6107
|
+
let h = 0;
|
|
6108
|
+
for (let i = 0; i < s.length; i++) h = (h << 5) - h + s.charCodeAt(i) | 0;
|
|
6109
|
+
return `h${(h >>> 0).toString(16)}`;
|
|
6110
|
+
}
|
|
6111
|
+
async function runShadowProbe(args) {
|
|
6112
|
+
try {
|
|
6113
|
+
const cfg = args.opts.shadowProbe;
|
|
6114
|
+
if (!shouldSampleProbe(cfg.sampleRate ?? 0.05)) return;
|
|
6115
|
+
const candidates = normalizeProbeCandidates(cfg.candidates);
|
|
6116
|
+
const promptHash = hashForProbe(args.ir.currentTurn?.content ?? "");
|
|
6117
|
+
for (const candidate of candidates) {
|
|
6118
|
+
if (candidate === args.servedModel) continue;
|
|
6119
|
+
if (deriveFamilyFromModelId(candidate) === "claude-opus") continue;
|
|
6120
|
+
if (!isModelReachable(candidate, { apiKeys: args.opts.apiKeys })) continue;
|
|
6121
|
+
try {
|
|
6122
|
+
const candCompile = compileAndRegister(
|
|
6123
|
+
{
|
|
6124
|
+
...args.ir,
|
|
6125
|
+
models: args.ir.models.includes(candidate) ? args.ir.models : [candidate, ...args.ir.models],
|
|
6126
|
+
constraints: { ...args.ir.constraints ?? {}, forceModel: candidate }
|
|
6127
|
+
},
|
|
6128
|
+
args.opts
|
|
6129
|
+
);
|
|
6130
|
+
const exec = await execute(candCompile.request, {
|
|
6131
|
+
apiKeys: args.opts.apiKeys,
|
|
6132
|
+
fetchImpl: args.opts.fetchImpl,
|
|
6133
|
+
providerOverrides: args.opts.providerOverrides
|
|
6134
|
+
});
|
|
6135
|
+
if (!exec.ok) continue;
|
|
6136
|
+
await recordShadowProbe({
|
|
6137
|
+
appId: args.ir.appId,
|
|
6138
|
+
archetype: args.ir.intent.archetype,
|
|
6139
|
+
family: deriveFamilyFromModelId(candidate) ?? candCompile.provider,
|
|
6140
|
+
candidateModel: candidate,
|
|
6141
|
+
currentModel: args.servedModel,
|
|
6142
|
+
promptHash,
|
|
6143
|
+
currentResponsePreview: args.servedResponse.text.slice(0, 2e3),
|
|
6144
|
+
candidateResponsePreview: exec.response.text.slice(0, 2e3),
|
|
6145
|
+
tokensCurrentIn: args.servedResponse.tokens.input,
|
|
6146
|
+
tokensCurrentOut: args.servedResponse.tokens.output,
|
|
6147
|
+
tokensCandidateIn: exec.response.tokens.input,
|
|
6148
|
+
tokensCandidateOut: exec.response.tokens.output
|
|
6149
|
+
});
|
|
6150
|
+
} catch {
|
|
6151
|
+
}
|
|
6152
|
+
}
|
|
6153
|
+
} catch {
|
|
6154
|
+
}
|
|
6155
|
+
}
|
|
6026
6156
|
function validateStructuredContract(exec, ir) {
|
|
6027
6157
|
if (!ir.constraints?.structuredOutput) {
|
|
6028
6158
|
return { ok: true, response: exec.response };
|
|
@@ -6564,6 +6694,7 @@ function compile2(ir, opts) {
|
|
|
6564
6694
|
bucketHistory,
|
|
6565
6695
|
bucketToolCount,
|
|
6566
6696
|
buildLLMJudge,
|
|
6697
|
+
buildShadowProbeRow,
|
|
6567
6698
|
call,
|
|
6568
6699
|
clearBrain,
|
|
6569
6700
|
compile,
|
|
@@ -6592,6 +6723,7 @@ function compile2(ir, opts) {
|
|
|
6592
6723
|
hashShape,
|
|
6593
6724
|
isArchetype,
|
|
6594
6725
|
isBrainQueryActiveFor,
|
|
6726
|
+
isBrainSync,
|
|
6595
6727
|
isExclusionFindingsBrainActive,
|
|
6596
6728
|
isModelReachable,
|
|
6597
6729
|
isProviderReachable,
|
|
@@ -6610,6 +6742,7 @@ function compile2(ir, opts) {
|
|
|
6610
6742
|
readBrainReadEnv,
|
|
6611
6743
|
record,
|
|
6612
6744
|
recordOutcome,
|
|
6745
|
+
recordShadowProbe,
|
|
6613
6746
|
resetTokenizer,
|
|
6614
6747
|
resolveConventionsForProfile,
|
|
6615
6748
|
resolvePricingAt,
|
package/dist/index.mjs
CHANGED
|
@@ -2825,6 +2825,61 @@ async function recordOutcome(input) {
|
|
|
2825
2825
|
void send();
|
|
2826
2826
|
return { ok: true };
|
|
2827
2827
|
}
|
|
2828
|
+
function isBrainSync() {
|
|
2829
|
+
return activeConfig?.sync === true;
|
|
2830
|
+
}
|
|
2831
|
+
function buildShadowProbeRow(input) {
|
|
2832
|
+
return {
|
|
2833
|
+
app_id: input.appId,
|
|
2834
|
+
intent_archetype: input.archetype,
|
|
2835
|
+
family: input.family,
|
|
2836
|
+
candidate_model: input.candidateModel,
|
|
2837
|
+
current_model: input.currentModel,
|
|
2838
|
+
prompt_hash: input.promptHash,
|
|
2839
|
+
current_response: input.currentResponsePreview ?? null,
|
|
2840
|
+
candidate_response: input.candidateResponsePreview ?? null,
|
|
2841
|
+
judge_verdict: null,
|
|
2842
|
+
judge_score: null,
|
|
2843
|
+
tokens_current_in: input.tokensCurrentIn ?? null,
|
|
2844
|
+
tokens_current_out: input.tokensCurrentOut ?? null,
|
|
2845
|
+
tokens_candidate_in: input.tokensCandidateIn ?? null,
|
|
2846
|
+
tokens_candidate_out: input.tokensCandidateOut ?? null,
|
|
2847
|
+
// Full IR was replayed (not a truncated preview), so fidelity is 1.0 — the
|
|
2848
|
+
// prompt-fidelity guard never fires on these rows.
|
|
2849
|
+
prompt_fidelity: 1,
|
|
2850
|
+
replay_source: "inline-full-ir"
|
|
2851
|
+
};
|
|
2852
|
+
}
|
|
2853
|
+
async function recordShadowProbe(input) {
|
|
2854
|
+
if (!activeConfig) return;
|
|
2855
|
+
const config = activeConfig;
|
|
2856
|
+
const fetchFn = config.fetchImpl ?? fetch;
|
|
2857
|
+
const row = buildShadowProbeRow(input);
|
|
2858
|
+
const send = async () => {
|
|
2859
|
+
try {
|
|
2860
|
+
const res = await fetchFn(`${config.endpoint}/probe_outcomes`, {
|
|
2861
|
+
method: "POST",
|
|
2862
|
+
headers: {
|
|
2863
|
+
"Content-Type": "application/json",
|
|
2864
|
+
Prefer: "return=minimal",
|
|
2865
|
+
...config.apiKey ? { Authorization: `Bearer ${config.apiKey}` } : {}
|
|
2866
|
+
},
|
|
2867
|
+
body: JSON.stringify(row)
|
|
2868
|
+
});
|
|
2869
|
+
if (!res.ok) {
|
|
2870
|
+
const text = await res.text().catch(() => "<no body>");
|
|
2871
|
+
throw new Error(`brain probe_outcomes ${res.status}: ${text}`);
|
|
2872
|
+
}
|
|
2873
|
+
} catch (err) {
|
|
2874
|
+
(config.onError ?? defaultOnError4)(err);
|
|
2875
|
+
}
|
|
2876
|
+
};
|
|
2877
|
+
if (config.sync) {
|
|
2878
|
+
await send();
|
|
2879
|
+
} else {
|
|
2880
|
+
void send();
|
|
2881
|
+
}
|
|
2882
|
+
}
|
|
2828
2883
|
|
|
2829
2884
|
// src/ir.ts
|
|
2830
2885
|
var CallError = class extends Error {
|
|
@@ -3589,6 +3644,19 @@ async function call(ir, opts = {}) {
|
|
|
3589
3644
|
);
|
|
3590
3645
|
}
|
|
3591
3646
|
}
|
|
3647
|
+
if (opts.shadowProbe) {
|
|
3648
|
+
const probe = runShadowProbe({
|
|
3649
|
+
ir,
|
|
3650
|
+
opts,
|
|
3651
|
+
servedModel: targetModel,
|
|
3652
|
+
servedResponse: validated.response
|
|
3653
|
+
});
|
|
3654
|
+
if (isBrainSync()) {
|
|
3655
|
+
await probe;
|
|
3656
|
+
} else {
|
|
3657
|
+
void probe;
|
|
3658
|
+
}
|
|
3659
|
+
}
|
|
3592
3660
|
return {
|
|
3593
3661
|
handle: initial.handle,
|
|
3594
3662
|
actualModel: targetModel,
|
|
@@ -3661,6 +3729,65 @@ function extractPromptPreview(ir) {
|
|
|
3661
3729
|
if (lastHist) return lastHist.slice(0, 200);
|
|
3662
3730
|
return void 0;
|
|
3663
3731
|
}
|
|
3732
|
+
function shouldSampleProbe(sampleRate, rng = Math.random) {
|
|
3733
|
+
if (!(sampleRate > 0)) return false;
|
|
3734
|
+
if (sampleRate >= 1) return true;
|
|
3735
|
+
return rng() < sampleRate;
|
|
3736
|
+
}
|
|
3737
|
+
function normalizeProbeCandidates(candidates) {
|
|
3738
|
+
const arr = Array.isArray(candidates) ? candidates : [candidates];
|
|
3739
|
+
return [...new Set(arr.filter((c) => typeof c === "string" && c.length > 0))];
|
|
3740
|
+
}
|
|
3741
|
+
function hashForProbe(s) {
|
|
3742
|
+
let h = 0;
|
|
3743
|
+
for (let i = 0; i < s.length; i++) h = (h << 5) - h + s.charCodeAt(i) | 0;
|
|
3744
|
+
return `h${(h >>> 0).toString(16)}`;
|
|
3745
|
+
}
|
|
3746
|
+
async function runShadowProbe(args) {
|
|
3747
|
+
try {
|
|
3748
|
+
const cfg = args.opts.shadowProbe;
|
|
3749
|
+
if (!shouldSampleProbe(cfg.sampleRate ?? 0.05)) return;
|
|
3750
|
+
const candidates = normalizeProbeCandidates(cfg.candidates);
|
|
3751
|
+
const promptHash = hashForProbe(args.ir.currentTurn?.content ?? "");
|
|
3752
|
+
for (const candidate of candidates) {
|
|
3753
|
+
if (candidate === args.servedModel) continue;
|
|
3754
|
+
if (deriveFamilyFromModelId(candidate) === "claude-opus") continue;
|
|
3755
|
+
if (!isModelReachable(candidate, { apiKeys: args.opts.apiKeys })) continue;
|
|
3756
|
+
try {
|
|
3757
|
+
const candCompile = compileAndRegister(
|
|
3758
|
+
{
|
|
3759
|
+
...args.ir,
|
|
3760
|
+
models: args.ir.models.includes(candidate) ? args.ir.models : [candidate, ...args.ir.models],
|
|
3761
|
+
constraints: { ...args.ir.constraints ?? {}, forceModel: candidate }
|
|
3762
|
+
},
|
|
3763
|
+
args.opts
|
|
3764
|
+
);
|
|
3765
|
+
const exec = await execute(candCompile.request, {
|
|
3766
|
+
apiKeys: args.opts.apiKeys,
|
|
3767
|
+
fetchImpl: args.opts.fetchImpl,
|
|
3768
|
+
providerOverrides: args.opts.providerOverrides
|
|
3769
|
+
});
|
|
3770
|
+
if (!exec.ok) continue;
|
|
3771
|
+
await recordShadowProbe({
|
|
3772
|
+
appId: args.ir.appId,
|
|
3773
|
+
archetype: args.ir.intent.archetype,
|
|
3774
|
+
family: deriveFamilyFromModelId(candidate) ?? candCompile.provider,
|
|
3775
|
+
candidateModel: candidate,
|
|
3776
|
+
currentModel: args.servedModel,
|
|
3777
|
+
promptHash,
|
|
3778
|
+
currentResponsePreview: args.servedResponse.text.slice(0, 2e3),
|
|
3779
|
+
candidateResponsePreview: exec.response.text.slice(0, 2e3),
|
|
3780
|
+
tokensCurrentIn: args.servedResponse.tokens.input,
|
|
3781
|
+
tokensCurrentOut: args.servedResponse.tokens.output,
|
|
3782
|
+
tokensCandidateIn: exec.response.tokens.input,
|
|
3783
|
+
tokensCandidateOut: exec.response.tokens.output
|
|
3784
|
+
});
|
|
3785
|
+
} catch {
|
|
3786
|
+
}
|
|
3787
|
+
}
|
|
3788
|
+
} catch {
|
|
3789
|
+
}
|
|
3790
|
+
}
|
|
3664
3791
|
function validateStructuredContract(exec, ir) {
|
|
3665
3792
|
if (!ir.constraints?.structuredOutput) {
|
|
3666
3793
|
return { ok: true, response: exec.response };
|
|
@@ -4201,6 +4328,7 @@ export {
|
|
|
4201
4328
|
bucketHistory,
|
|
4202
4329
|
bucketToolCount,
|
|
4203
4330
|
buildLLMJudge,
|
|
4331
|
+
buildShadowProbeRow,
|
|
4204
4332
|
call,
|
|
4205
4333
|
clearBrain,
|
|
4206
4334
|
compile2 as compile,
|
|
@@ -4229,6 +4357,7 @@ export {
|
|
|
4229
4357
|
hashShape,
|
|
4230
4358
|
isArchetype,
|
|
4231
4359
|
isBrainQueryActiveFor,
|
|
4360
|
+
isBrainSync,
|
|
4232
4361
|
isExclusionFindingsBrainActive,
|
|
4233
4362
|
isModelReachable,
|
|
4234
4363
|
isProviderReachable,
|
|
@@ -4247,6 +4376,7 @@ export {
|
|
|
4247
4376
|
readBrainReadEnv,
|
|
4248
4377
|
record,
|
|
4249
4378
|
recordOutcome,
|
|
4379
|
+
recordShadowProbe,
|
|
4250
4380
|
resetTokenizer,
|
|
4251
4381
|
resolveConventionsForProfile,
|
|
4252
4382
|
resolvePricingAt,
|
|
@@ -799,9 +799,47 @@ interface ProviderOverrides {
|
|
|
799
799
|
openai?: Record<string, unknown>;
|
|
800
800
|
deepseek?: Record<string, unknown>;
|
|
801
801
|
}
|
|
802
|
+
/**
|
|
803
|
+
* Full-IR inline shadow-probe config (Shape B, Phase 1 — 2026-05-29 s51).
|
|
804
|
+
*
|
|
805
|
+
* When set on `call()`, after the primary response is served kgauto re-lowers
|
|
806
|
+
* the SAME in-memory PromptIR to each candidate and runs it, persisting a
|
|
807
|
+
* `probe_outcomes` row with `replay_source='inline-full-ir'` and
|
|
808
|
+
* `prompt_fidelity=1.0` — a fair, full-prompt measurement (vs the watchers'
|
|
809
|
+
* lossy `prompt_preview` replay). The probe NEVER blocks the user response and
|
|
810
|
+
* NEVER persists the raw prompt (system/context/payload) — only response
|
|
811
|
+
* previews + metadata, same policy the brain already holds.
|
|
812
|
+
*
|
|
813
|
+
* This is the trustworthy path that earns the right to a quality verdict;
|
|
814
|
+
* `prompt_preview` replay is retired for verdicts (see CLAUDE.md).
|
|
815
|
+
*
|
|
816
|
+
* Phase 1 enforces `sampleRate` and runs the candidate with `judge: 'off'`
|
|
817
|
+
* (responses stored for an offline batch judge). `judge: 'opus'` (inline
|
|
818
|
+
* verdict) and `maxPerDay` (per-tuple daily cap, needs a brain-count read)
|
|
819
|
+
* are accepted by the type but ENFORCED IN PHASE 2.
|
|
820
|
+
*/
|
|
821
|
+
interface ShadowProbeConfig {
|
|
822
|
+
/** Model id(s) or family alias(es) to shadow-test against the served model, on the same IR. */
|
|
823
|
+
candidates: string | string[];
|
|
824
|
+
/** Probability [0,1] that any given call fires a probe. Default 0.05. */
|
|
825
|
+
sampleRate?: number;
|
|
826
|
+
/**
|
|
827
|
+
* 'off' (Phase 1 default): run candidate + store both responses for an
|
|
828
|
+
* offline batch judge. 'opus': judge candidate-vs-served inline (Phase 2).
|
|
829
|
+
*/
|
|
830
|
+
judge?: 'opus' | 'off';
|
|
831
|
+
/** Per-(appId, archetype, candidate) daily cap. Phase 2 (needs brain-count read). Default 20. */
|
|
832
|
+
maxPerDay?: number;
|
|
833
|
+
}
|
|
802
834
|
interface CallOptions {
|
|
803
835
|
/** Forwarded to compile(). */
|
|
804
836
|
policy?: CompilePolicy;
|
|
837
|
+
/**
|
|
838
|
+
* alpha (s51 Phase 1) — full-IR inline shadow-probe. When set, kgauto
|
|
839
|
+
* measures the candidate(s) on the same IR after serving the primary,
|
|
840
|
+
* fire-and-forget. See {@link ShadowProbeConfig}.
|
|
841
|
+
*/
|
|
842
|
+
shadowProbe?: ShadowProbeConfig;
|
|
805
843
|
toolRelevanceThreshold?: number;
|
|
806
844
|
compressHistoryAfter?: number;
|
|
807
845
|
/** Override API keys (defaults: process.env). */
|
|
@@ -1253,4 +1291,4 @@ interface PerAxisMetrics {
|
|
|
1253
1291
|
/** Per-axis metrics keyed by model — used for chain-comparison views. */
|
|
1254
1292
|
type PerAxisMetricsByModel = Record<string, PerAxisMetrics>;
|
|
1255
1293
|
|
|
1256
|
-
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 SystemModelMessage as S, type ToolCall as T, type CompiledRequest as a, type PromptIR as b, type CallOptions as c, type CallResult as d, type CompileResult as e, type SectionRewrite as f, type RecordOutcomeInput as g, type OracleScore as h, type Adapter as i, type PerAxisMetrics as j, type Provider as k, type ChainEntry as l, type CallAttempt as m, CallError as n, type ChainModelEntry as o, type ChainWithGrounding as p, type Constraints as q, type MutationApplied as r, type NormalizedTokens as s, type OutcomeKind as t, type PerAxisMetricsByModel as u, type PromptSection as v, type SectionKind as w, type
|
|
1294
|
+
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 SystemModelMessage as S, type ToolCall as T, type CompiledRequest as a, type PromptIR as b, type CallOptions as c, type CallResult as d, type CompileResult as e, type SectionRewrite as f, type RecordOutcomeInput as g, type OracleScore as h, type Adapter as i, type PerAxisMetrics as j, type Provider as k, type ChainEntry as l, type CallAttempt as m, CallError as n, type ChainModelEntry as o, type ChainWithGrounding as p, type Constraints as q, type MutationApplied as r, type NormalizedTokens as s, type OutcomeKind as t, type PerAxisMetricsByModel as u, type PromptSection as v, type SectionKind as w, type ShadowProbeConfig as x, type ToolDefinition as y };
|
|
@@ -799,9 +799,47 @@ interface ProviderOverrides {
|
|
|
799
799
|
openai?: Record<string, unknown>;
|
|
800
800
|
deepseek?: Record<string, unknown>;
|
|
801
801
|
}
|
|
802
|
+
/**
|
|
803
|
+
* Full-IR inline shadow-probe config (Shape B, Phase 1 — 2026-05-29 s51).
|
|
804
|
+
*
|
|
805
|
+
* When set on `call()`, after the primary response is served kgauto re-lowers
|
|
806
|
+
* the SAME in-memory PromptIR to each candidate and runs it, persisting a
|
|
807
|
+
* `probe_outcomes` row with `replay_source='inline-full-ir'` and
|
|
808
|
+
* `prompt_fidelity=1.0` — a fair, full-prompt measurement (vs the watchers'
|
|
809
|
+
* lossy `prompt_preview` replay). The probe NEVER blocks the user response and
|
|
810
|
+
* NEVER persists the raw prompt (system/context/payload) — only response
|
|
811
|
+
* previews + metadata, same policy the brain already holds.
|
|
812
|
+
*
|
|
813
|
+
* This is the trustworthy path that earns the right to a quality verdict;
|
|
814
|
+
* `prompt_preview` replay is retired for verdicts (see CLAUDE.md).
|
|
815
|
+
*
|
|
816
|
+
* Phase 1 enforces `sampleRate` and runs the candidate with `judge: 'off'`
|
|
817
|
+
* (responses stored for an offline batch judge). `judge: 'opus'` (inline
|
|
818
|
+
* verdict) and `maxPerDay` (per-tuple daily cap, needs a brain-count read)
|
|
819
|
+
* are accepted by the type but ENFORCED IN PHASE 2.
|
|
820
|
+
*/
|
|
821
|
+
interface ShadowProbeConfig {
|
|
822
|
+
/** Model id(s) or family alias(es) to shadow-test against the served model, on the same IR. */
|
|
823
|
+
candidates: string | string[];
|
|
824
|
+
/** Probability [0,1] that any given call fires a probe. Default 0.05. */
|
|
825
|
+
sampleRate?: number;
|
|
826
|
+
/**
|
|
827
|
+
* 'off' (Phase 1 default): run candidate + store both responses for an
|
|
828
|
+
* offline batch judge. 'opus': judge candidate-vs-served inline (Phase 2).
|
|
829
|
+
*/
|
|
830
|
+
judge?: 'opus' | 'off';
|
|
831
|
+
/** Per-(appId, archetype, candidate) daily cap. Phase 2 (needs brain-count read). Default 20. */
|
|
832
|
+
maxPerDay?: number;
|
|
833
|
+
}
|
|
802
834
|
interface CallOptions {
|
|
803
835
|
/** Forwarded to compile(). */
|
|
804
836
|
policy?: CompilePolicy;
|
|
837
|
+
/**
|
|
838
|
+
* alpha (s51 Phase 1) — full-IR inline shadow-probe. When set, kgauto
|
|
839
|
+
* measures the candidate(s) on the same IR after serving the primary,
|
|
840
|
+
* fire-and-forget. See {@link ShadowProbeConfig}.
|
|
841
|
+
*/
|
|
842
|
+
shadowProbe?: ShadowProbeConfig;
|
|
805
843
|
toolRelevanceThreshold?: number;
|
|
806
844
|
compressHistoryAfter?: number;
|
|
807
845
|
/** Override API keys (defaults: process.env). */
|
|
@@ -1253,4 +1291,4 @@ interface PerAxisMetrics {
|
|
|
1253
1291
|
/** Per-axis metrics keyed by model — used for chain-comparison views. */
|
|
1254
1292
|
type PerAxisMetricsByModel = Record<string, PerAxisMetrics>;
|
|
1255
1293
|
|
|
1256
|
-
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 SystemModelMessage as S, type ToolCall as T, type CompiledRequest as a, type PromptIR as b, type CallOptions as c, type CallResult as d, type CompileResult as e, type SectionRewrite as f, type RecordOutcomeInput as g, type OracleScore as h, type Adapter as i, type PerAxisMetrics as j, type Provider as k, type ChainEntry as l, type CallAttempt as m, CallError as n, type ChainModelEntry as o, type ChainWithGrounding as p, type Constraints as q, type MutationApplied as r, type NormalizedTokens as s, type OutcomeKind as t, type PerAxisMetricsByModel as u, type PromptSection as v, type SectionKind as w, type
|
|
1294
|
+
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 SystemModelMessage as S, type ToolCall as T, type CompiledRequest as a, type PromptIR as b, type CallOptions as c, type CallResult as d, type CompileResult as e, type SectionRewrite as f, type RecordOutcomeInput as g, type OracleScore as h, type Adapter as i, type PerAxisMetrics as j, type Provider as k, type ChainEntry as l, type CallAttempt as m, CallError as n, type ChainModelEntry as o, type ChainWithGrounding as p, type Constraints as q, type MutationApplied as r, type NormalizedTokens as s, type OutcomeKind as t, type PerAxisMetricsByModel as u, type PromptSection as v, type SectionKind as w, type ShadowProbeConfig as x, type ToolDefinition as y };
|
package/dist/profiles.d.mts
CHANGED
package/dist/profiles.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, m as CallAttempt } from './ir-
|
|
1
|
+
import { r as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, m as CallAttempt } from './ir-D3n-pBYI.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Glass-Box observability types (alpha.17).
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, m as CallAttempt } from './ir-
|
|
1
|
+
import { r as MutationApplied, B as BestPracticeAdvisory, F as FallbackReason, m as CallAttempt } from './ir-BBKgsUX7.mjs';
|
|
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.45",
|
|
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",
|