@tangle-network/agent-eval 0.220.2 → 0.221.0
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/CHANGELOG.md +30 -0
- package/dist/adapters/http.d.ts +2 -2
- package/dist/{agent-profile-D01Io2Xw.d.ts → agent-profile-Bc7ADJY4.d.ts} +2 -2
- package/dist/{agent-profile-D01Io2Xw.d.ts.map → agent-profile-Bc7ADJY4.d.ts.map} +1 -1
- package/dist/analyst/index.d.ts +77 -78
- package/dist/analyst/index.d.ts.map +1 -1
- package/dist/analyst/index.js +204 -25
- package/dist/analyst/index.js.map +1 -1
- package/dist/{analyze-runs-DqPJaJ4X.js → analyze-runs-CHmsykNJ.js} +4 -4
- package/dist/{analyze-runs-DqPJaJ4X.js.map → analyze-runs-CHmsykNJ.js.map} +1 -1
- package/dist/{analyze-runs-BWAHBDAw.d.ts → analyze-runs-D7In4c3z.d.ts} +2 -2
- package/dist/{analyze-runs-BWAHBDAw.d.ts.map → analyze-runs-D7In4c3z.d.ts.map} +1 -1
- package/dist/{benchmark-command-Dx0E4a6z.js → benchmark-command-8XQfpUK3.js} +13 -11
- package/dist/benchmark-command-8XQfpUK3.js.map +1 -0
- package/dist/benchmarks/index.d.ts +4 -4
- package/dist/benchmarks/index.js +3 -3
- package/dist/calibration-CTwxpJ-t.js +197 -0
- package/dist/calibration-CTwxpJ-t.js.map +1 -0
- package/dist/campaign/index.d.ts +6 -6
- package/dist/campaign/index.js +5 -5
- package/dist/{campaign-BVPC6ODQ.js → campaign-Bt6rbWIU.js} +9 -8
- package/dist/{campaign-BVPC6ODQ.js.map → campaign-Bt6rbWIU.js.map} +1 -1
- package/dist/cli.js +1 -1
- package/dist/{completion-verifier-Cigap8CG.js → completion-verifier-YwoeujPl.js} +2 -2
- package/dist/{completion-verifier-Cigap8CG.js.map → completion-verifier-YwoeujPl.js.map} +1 -1
- package/dist/contract/index.d.ts +10 -10
- package/dist/contract/index.js +7 -7
- package/dist/decision-point-Co3u3W8k.js +831 -0
- package/dist/decision-point-Co3u3W8k.js.map +1 -0
- package/dist/default-registry-BMHqNR6_.d.ts +257 -0
- package/dist/default-registry-BMHqNR6_.d.ts.map +1 -0
- package/dist/{default-registry-ovrIBGmH.js → default-registry-BbFCkqvB.js} +607 -14
- package/dist/default-registry-BbFCkqvB.js.map +1 -0
- package/dist/{define-agent-eval-C2nFhHPu.d.ts → define-agent-eval-Bsoi2GUV.d.ts} +7 -7
- package/dist/{define-agent-eval-C2nFhHPu.d.ts.map → define-agent-eval-Bsoi2GUV.d.ts.map} +1 -1
- package/dist/{define-agent-eval-UQY3VbJ2.js → define-agent-eval-CJhECJNL.js} +4 -4
- package/dist/{define-agent-eval-UQY3VbJ2.js.map → define-agent-eval-CJhECJNL.js.map} +1 -1
- package/dist/diagnosis/index.d.ts +2 -2
- package/dist/diagnosis/index.js +1 -1
- package/dist/{dspy-rlm-engine-Bn_Mt_LW.js → dspy-rlm-engine-BTy7u0jQ.js} +3 -3
- package/dist/{dspy-rlm-engine-Bn_Mt_LW.js.map → dspy-rlm-engine-BTy7u0jQ.js.map} +1 -1
- package/dist/{engine-BpGGw6cd.d.ts → engine-BF95CWzH.d.ts} +2 -2
- package/dist/{engine-BpGGw6cd.d.ts.map → engine-BF95CWzH.d.ts.map} +1 -1
- package/dist/{eval-campaign-BUMIxKTE.js → eval-campaign-DoX5vz3E.js} +2 -2
- package/dist/{eval-campaign-BUMIxKTE.js.map → eval-campaign-DoX5vz3E.js.map} +1 -1
- package/dist/{evaluation-CBdQt_kr.d.ts → evaluation-D1PGzkPR.d.ts} +3 -3
- package/dist/{evaluation-CBdQt_kr.d.ts.map → evaluation-D1PGzkPR.d.ts.map} +1 -1
- package/dist/evaluation-wdGyZ7jV.js +147 -0
- package/dist/evaluation-wdGyZ7jV.js.map +1 -0
- package/dist/evaluation.d.ts +1 -1
- package/dist/evaluation.js +1 -136
- package/dist/{exact-types-BYFmYq44.d.ts → exact-types-CVn1QxFO.d.ts} +2 -2
- package/dist/{exact-types-BYFmYq44.d.ts.map → exact-types-CVn1QxFO.d.ts.map} +1 -1
- package/dist/experiment/index.d.ts +3 -3
- package/dist/experiment/index.js +2 -2
- package/dist/{external-optimizer-process-wOLfzsCC.js → external-optimizer-process-E5yY2SYS.js} +2 -2
- package/dist/{external-optimizer-process-wOLfzsCC.js.map → external-optimizer-process-E5yY2SYS.js.map} +1 -1
- package/dist/{external-optimizer-subprocess-D670Oxf2.js → external-optimizer-subprocess-DA02c_L6.js} +12 -19
- package/dist/{external-optimizer-subprocess-D670Oxf2.js.map → external-optimizer-subprocess-DA02c_L6.js.map} +1 -1
- package/dist/{feedback-trajectory-DhB9WzYg.d.ts → feedback-trajectory-BZhVCWuz.d.ts} +3 -3
- package/dist/{feedback-trajectory-DhB9WzYg.d.ts.map → feedback-trajectory-BZhVCWuz.d.ts.map} +1 -1
- package/dist/finding-composition-8n0fFgVI.js +131 -0
- package/dist/finding-composition-8n0fFgVI.js.map +1 -0
- package/dist/{findings-store-CvNo712L.js → findings-store-DRiFdoid.js} +4 -4
- package/dist/{findings-store-CvNo712L.js.map → findings-store-DRiFdoid.js.map} +1 -1
- package/dist/{index-CVFStrQD.d.ts → index-BJZ7s-sv.d.ts} +7 -58
- package/dist/index-BJZ7s-sv.d.ts.map +1 -0
- package/dist/{index-Q6DvdcwI.d.ts → index-BvX3CFNS.d.ts} +6 -6
- package/dist/{index-Q6DvdcwI.d.ts.map → index-BvX3CFNS.d.ts.map} +1 -1
- package/dist/index-DWd1gUwR.d.ts +1086 -0
- package/dist/index-DWd1gUwR.d.ts.map +1 -0
- package/dist/{index-DAXfpVf7.d.ts → index-y7i8l6Y_.d.ts} +8 -8
- package/dist/{index-DAXfpVf7.d.ts.map → index-y7i8l6Y_.d.ts.map} +1 -1
- package/dist/index.d.ts +18 -17
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +15 -15
- package/dist/{kind-factory-BhxbtUsQ.js → kind-factory-Dl0PmNQL.js} +2 -2
- package/dist/{kind-factory-BhxbtUsQ.js.map → kind-factory-Dl0PmNQL.js.map} +1 -1
- package/dist/{llm-judge-Cc8vDJh_.js → llm-judge-3uAeRawE.js} +4 -4
- package/dist/{llm-judge-Cc8vDJh_.js.map → llm-judge-3uAeRawE.js.map} +1 -1
- package/dist/{matrix-Cf-AGxGh.d.ts → matrix-BXo3PSqM.d.ts} +2 -2
- package/dist/{matrix-Cf-AGxGh.d.ts.map → matrix-BXo3PSqM.d.ts.map} +1 -1
- package/dist/meta-eval/index.d.ts +3 -638
- package/dist/meta-eval/index.js +3 -193
- package/dist/meta-eval/index.js.map +1 -1
- package/dist/multishot/golden/index.d.ts +1 -1
- package/dist/multishot/index.d.ts +2 -2
- package/dist/openapi.json +1 -1
- package/dist/outcome-observations-FLmRpgYa.js +78 -0
- package/dist/outcome-observations-FLmRpgYa.js.map +1 -0
- package/dist/{paired-arms-Ct4LTKc1.js → paired-arms-B2ttLc0_.js} +108 -31
- package/dist/paired-arms-B2ttLc0_.js.map +1 -0
- package/dist/{power-and-mde-N5nU4_Ly.js → power-and-mde-CQX-0weG.js} +2 -2
- package/dist/{power-and-mde-N5nU4_Ly.js.map → power-and-mde-CQX-0weG.js.map} +1 -1
- package/dist/{prime-protocol-CckHBxGu.d.ts → prime-protocol-BEaqBoQE.d.ts} +2 -2
- package/dist/{prime-protocol-CckHBxGu.d.ts.map → prime-protocol-BEaqBoQE.d.ts.map} +1 -1
- package/dist/{proposal-findings-E1aSC_cU.js → proposal-findings-D0_zkQ2l.js} +2 -2
- package/dist/{proposal-findings-E1aSC_cU.js.map → proposal-findings-D0_zkQ2l.js.map} +1 -1
- package/dist/{registry-B_yG-1jh.d.ts → registry-DDKaUrmM.d.ts} +3 -3
- package/dist/{registry-B_yG-1jh.d.ts.map → registry-DDKaUrmM.d.ts.map} +1 -1
- package/dist/reporting.d.ts +1 -1
- package/dist/reporting.js +3 -3
- package/dist/rl.d.ts +4 -5
- package/dist/rl.d.ts.map +1 -1
- package/dist/rl.js +5 -4
- package/dist/rl.js.map +1 -1
- package/dist/{rubric-predictive-validity-noY7uE03.d.ts → rubric-predictive-validity-Cd5SCtAf.d.ts} +58 -3
- package/dist/rubric-predictive-validity-Cd5SCtAf.d.ts.map +1 -0
- package/dist/{rubric-predictive-validity-D3_oI72N.js → rubric-predictive-validity-CeKW2GQN.js} +3 -77
- package/dist/rubric-predictive-validity-CeKW2GQN.js.map +1 -0
- package/dist/search/index.d.ts +2 -2
- package/dist/{search-kernel-Dloxd6gs.d.ts → search-kernel-C6__V0IS.d.ts} +2 -2
- package/dist/{search-kernel-Dloxd6gs.d.ts.map → search-kernel-C6__V0IS.d.ts.map} +1 -1
- package/dist/{skillopt-optimization-method-DLKqdhcR.js → skillopt-optimization-method-D21dH_Bh.js} +4 -4
- package/dist/{skillopt-optimization-method-DLKqdhcR.js.map → skillopt-optimization-method-D21dH_Bh.js.map} +1 -1
- package/dist/{statistical-heldout-3z3I-kJN.d.ts → statistical-heldout-pD1Yah-0.d.ts} +58 -8
- package/dist/statistical-heldout-pD1Yah-0.d.ts.map +1 -0
- package/dist/{store-otlp-dyWE3wAG.js → store-otlp-BVZfR168.js} +2 -2
- package/dist/{store-otlp-dyWE3wAG.js.map → store-otlp-BVZfR168.js.map} +1 -1
- package/dist/{store-tool-spans-DIUgZbzu.js → store-tool-spans-CjYiF4fF.js} +3 -3
- package/dist/{store-tool-spans-DIUgZbzu.js.map → store-tool-spans-CjYiF4fF.js.map} +1 -1
- package/dist/{store-tool-spans-DPwXHQkH.d.ts → store-tool-spans-DfnwWMFR.d.ts} +4 -4
- package/dist/{store-tool-spans-DPwXHQkH.d.ts.map → store-tool-spans-DfnwWMFR.d.ts.map} +1 -1
- package/dist/{summary-report-BsXJoYX5.js → summary-report-DHDWxe6p.js} +3 -3
- package/dist/{summary-report-BsXJoYX5.js.map → summary-report-DHDWxe6p.js.map} +1 -1
- package/dist/systemone-D3MrW63C.d.ts +400 -0
- package/dist/systemone-D3MrW63C.d.ts.map +1 -0
- package/dist/{systemone-protocol-DKoi1NdK.d.ts → systemone-protocol-Bl2EI2KQ.d.ts} +4 -2
- package/dist/{systemone-protocol-DKoi1NdK.d.ts.map → systemone-protocol-Bl2EI2KQ.d.ts.map} +1 -1
- package/dist/systemone-protocol.d.ts +2 -2
- package/dist/systemone-protocol.js +7 -7
- package/dist/systemone-protocol.js.map +1 -1
- package/dist/{systemone-review-CUBMuTLi.d.ts → systemone-review-C8DRiT_-.d.ts} +3 -3
- package/dist/{systemone-review-CUBMuTLi.d.ts.map → systemone-review-C8DRiT_-.d.ts.map} +1 -1
- package/dist/{systemone-review-DzdOJ8I6.js → systemone-review-DFGtIUcf.js} +2 -2
- package/dist/{systemone-review-DzdOJ8I6.js.map → systemone-review-DFGtIUcf.js.map} +1 -1
- package/dist/systemone.d.ts +5 -5
- package/dist/systemone.js +5 -343
- package/dist/{tool-groups-LISbBWCg.d.ts → tool-groups-DK1bu5TD.d.ts} +3 -3
- package/dist/tool-groups-DK1bu5TD.d.ts.map +1 -0
- package/dist/{trace-questions-C42fYEE4.d.ts → trace-questions-D_OKYZ6u.d.ts} +3 -3
- package/dist/{trace-questions-C42fYEE4.d.ts.map → trace-questions-D_OKYZ6u.d.ts.map} +1 -1
- package/dist/trace-repair/index.d.ts +1 -1
- package/dist/traces.d.ts +3 -3
- package/dist/traces.js +3 -3
- package/dist/{types-DqFMNTgK.js → types-CnWmj8NW.js} +19 -6
- package/dist/types-CnWmj8NW.js.map +1 -0
- package/dist/{types-CHfn1zg5.d.ts → types-DDKfH-N6.d.ts} +2 -2
- package/dist/{types-CHfn1zg5.d.ts.map → types-DDKfH-N6.d.ts.map} +1 -1
- package/dist/{types-8yQzNm8u.d.ts → types-DGImvHIr.d.ts} +150 -4
- package/dist/types-DGImvHIr.d.ts.map +1 -0
- package/dist/{types-D8GXK9Z5.d.ts → types-IERw_HxR.d.ts} +2 -2
- package/dist/{types-D8GXK9Z5.d.ts.map → types-IERw_HxR.d.ts.map} +1 -1
- package/dist/wire/index.d.ts +1 -1
- package/docs/behavioral-trace-questions.md +99 -0
- package/docs/experiment.md +27 -0
- package/docs/finding-layers.md +54 -1
- package/docs/systemone.md +107 -0
- package/package.json +1 -1
- package/dist/benchmark-command-Dx0E4a6z.js.map +0 -1
- package/dist/default-registry-Cwg_QN3d.d.ts +0 -70
- package/dist/default-registry-Cwg_QN3d.d.ts.map +0 -1
- package/dist/default-registry-ovrIBGmH.js.map +0 -1
- package/dist/evaluation.js.map +0 -1
- package/dist/index-CVFStrQD.d.ts.map +0 -1
- package/dist/judge-gate-Dc_mXQsL.d.ts +0 -453
- package/dist/judge-gate-Dc_mXQsL.d.ts.map +0 -1
- package/dist/meta-eval/index.d.ts.map +0 -1
- package/dist/outcome-store-CNt4iZ67.d.ts +0 -58
- package/dist/outcome-store-CNt4iZ67.d.ts.map +0 -1
- package/dist/paired-arms-Ct4LTKc1.js.map +0 -1
- package/dist/rubric-predictive-validity-D3_oI72N.js.map +0 -1
- package/dist/rubric-predictive-validity-noY7uE03.d.ts.map +0 -1
- package/dist/statistical-heldout-3z3I-kJN.d.ts.map +0 -1
- package/dist/systemone-DVA7t76V.d.ts +0 -135
- package/dist/systemone-DVA7t76V.d.ts.map +0 -1
- package/dist/systemone.js.map +0 -1
- package/dist/tool-groups-LISbBWCg.d.ts.map +0 -1
- package/dist/types-8yQzNm8u.d.ts.map +0 -1
- package/dist/types-DqFMNTgK.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"evaluation-wdGyZ7jV.js","names":[],"sources":["../src/analyst/evaluation-context.ts","../src/evaluation.ts"],"sourcesContent":["import { CostLedger } from '../cost-ledger'\nimport type { EvaluationContext } from '../evaluation'\nimport type { AnalystContext } from './types'\n\n/** One deadline, spending authority and usage bridge for every evaluation-backed analyst. */\nexport function analystEvaluationContext(\n context: AnalystContext,\n actor: string,\n): {\n evaluation: EvaluationContext\n analystContext: AnalystContext & { signal: AbortSignal }\n} {\n const signals = context.signal ? [context.signal] : []\n if (context.deadlineMs !== undefined) {\n const remaining = context.deadlineMs - Date.now()\n if (!Number.isFinite(remaining)) throw new TypeError('Analyst deadline must be finite')\n if (remaining <= 0) throw new DOMException('Analyst deadline exceeded', 'TimeoutError')\n signals.push(AbortSignal.timeout(Math.ceil(remaining)))\n }\n const signal = AbortSignal.any(signals)\n signal.throwIfAborted()\n return {\n analystContext: { ...context, signal },\n evaluation: {\n signal,\n // No implicit account overrides an evaluator's configured spending authority.\n costLedger:\n context.costLedger ??\n (context.budgetUsd === undefined\n ? undefined\n : new CostLedger({ costCeilingUsd: context.budgetUsd })),\n actor,\n channel: 'analyst',\n costPhase: context.costPhase,\n costTags: { ...context.tags, runId: context.runId, correlationId: context.correlationId },\n onReceipt: (receipt) =>\n context.recordUsage?.({\n calls: 1,\n tokens: receipt.usageUnknown\n ? null\n : { input: receipt.inputTokens, output: receipt.outputTokens },\n cost: receipt.costUnknown\n ? { kind: 'uncaptured', usd: null }\n : {\n kind: receipt.actualCostUsd === undefined ? 'estimated' : 'observed',\n usd: receipt.costUsd,\n },\n }),\n },\n }\n}\n","import { analystEvaluationContext } from './analyst/evaluation-context'\nimport type { Analyst, AnalystContext, AnalystFinding } from './analyst/types'\nimport type { JudgeConfig, JudgeScore, Scenario } from './campaign/types'\nimport type {\n CostChannel,\n CostLedgerHandle,\n CostReceipt,\n CostReceiptInput,\n MaximumCharge,\n} from './cost-ledger'\nimport { CostLedger } from './cost-ledger'\n\nexport interface EvaluationResult<T> {\n value: T\n receipt: CostReceipt\n durationMs: number\n}\n\nexport interface EvaluationContext {\n /** Physical paid-call identity, forwarded through the existing ledger and transport.\n * Reusing it in one ledger conflicts; it is not an automatic result-replay policy. */\n callId?: string\n signal?: AbortSignal\n costLedger?: CostLedgerHandle\n actor?: string\n channel?: CostChannel\n costPhase?: string\n costTags?: Record<string, string>\n maximumCharge?: MaximumCharge\n /** Awaited after accounting and before validation or result delivery. */\n onReceipt?: (receipt: CostReceipt) => void | Promise<void>\n}\n\nexport type CostedEvaluator<I, O> = (\n input: I,\n context?: EvaluationContext,\n) => Promise<EvaluationResult<O>>\n\nexport interface EvaluatorOptions<I, O> {\n execute: (input: I, context: { signal: AbortSignal; idempotencyKey: string }) => Promise<O>\n receipt: (value: O) => CostReceiptInput\n receiptFromError?: (error: Error) => CostReceiptInput | undefined\n model?: string | ((input: I) => string)\n costLedger?: CostLedgerHandle\n maximumCharge?: MaximumCharge\n /** Awaited after accounting, so invalid output never erases paid work. */\n validate?: (value: O, input: I) => void | Promise<void>\n}\n\n/** A metered function, independent of providers, question formats, and application policy. */\nexport function createEvaluator<I, O>(options: EvaluatorOptions<I, O>): CostedEvaluator<I, O> {\n const defaults = { ...options }\n const ledger = defaults.costLedger ?? new CostLedger()\n return async (input, context = {}) => {\n context.signal?.throwIfAborted()\n const started = performance.now()\n const paid = await (context.costLedger ?? ledger).runPaidCall({\n callId: context.callId,\n actor: context.actor ?? 'evaluation',\n channel: context.channel ?? 'evaluation',\n phase: context.costPhase ?? 'evaluation',\n tags: context.costTags,\n model: typeof defaults.model === 'function' ? defaults.model(input) : defaults.model,\n signal: context.signal,\n maximumCharge: context.maximumCharge ?? defaults.maximumCharge,\n execute: (signal, idempotencyKey) => defaults.execute(input, { signal, idempotencyKey }),\n receipt: defaults.receipt,\n receiptFromError: defaults.receiptFromError,\n })\n if (paid.receipt) await context.onReceipt?.(paid.receipt)\n if (!paid.succeeded) throw paid.error\n // A transport can complete after cancellation. Keep its paid receipt, not a live decision.\n context.signal?.throwIfAborted()\n await defaults.validate?.(paid.value, input)\n context.signal?.throwIfAborted()\n return { value: paid.value, receipt: paid.receipt, durationMs: performance.now() - started }\n }\n}\n\nexport interface EvaluationJudgeOptions<A, S extends Scenario, O> {\n name: string\n version: string\n dimensions: JudgeConfig<A, S>['dimensions']\n evaluate: CostedEvaluator<{ artifact: A; scenario: S }, O>\n map: (value: O, input: { artifact: A; scenario: S }) => JudgeScore | Promise<JudgeScore>\n /** Persist the complete observation before reducing it to a verdict. */\n record?: (\n result: EvaluationResult<O>,\n input: { artifact: A; scenario: S },\n ) => void | Promise<void>\n appliesTo?: (scenario: S) => boolean\n}\n\n/** Return the existing contract. Mapping never performs another inference call. */\nexport function asJudge<A, S extends Scenario, O>(\n options: EvaluationJudgeOptions<A, S, O>,\n): JudgeConfig<A, S> {\n // The version describes these callbacks, not later mutations of the caller's options.\n const config = { ...options, dimensions: structuredClone(options.dimensions) }\n return {\n name: config.name,\n judgeVersion: config.version,\n dimensions: config.dimensions,\n appliesTo: config.appliesTo,\n async score({ artifact, scenario, signal, costLedger, costPhase, costTags }) {\n signal.throwIfAborted()\n const input = { artifact, scenario }\n const result = await config.evaluate(input, {\n signal,\n costLedger,\n actor: config.name,\n channel: 'judge',\n costPhase,\n costTags: { ...costTags, scenarioId: scenario.id },\n })\n await config.record?.(result, input)\n signal.throwIfAborted()\n const score = await config.map(result.value, input)\n signal.throwIfAborted()\n return score\n },\n }\n}\n\nexport interface EvaluationAnalystOptions<I, O> {\n id: string\n version: string\n description: string\n inputKind: Analyst<I>['inputKind']\n cost: Analyst<I>['cost']\n evaluate: (\n input: I,\n context: EvaluationContext,\n analystContext: AnalystContext,\n ) => Promise<EvaluationResult<O>>\n map: (value: O, input: I, context: AnalystContext) => AnalystFinding[] | Promise<AnalystFinding[]>\n record?: (result: EvaluationResult<O>, input: I, context: AnalystContext) => void | Promise<void>\n}\n\n/** Registry, graph, and trace consumers keep the same Analyst interface. */\nexport function asAnalyst<I, O>(options: EvaluationAnalystOptions<I, O>): Analyst<I> {\n const config = { ...options, cost: structuredClone(options.cost) }\n return {\n id: config.id,\n version: config.version,\n description: config.description,\n inputKind: config.inputKind,\n cost: config.cost,\n async analyze(input, context) {\n const { evaluation, analystContext } = analystEvaluationContext(context, config.id)\n const signal = analystContext.signal\n const result = await config.evaluate(input, evaluation, analystContext)\n await config.record?.(result, input, analystContext)\n signal.throwIfAborted()\n const findings = await config.map(result.value, input, analystContext)\n signal.throwIfAborted()\n return findings\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AAO,OAAO,KAAK;GAClD,OAAO,eAAe;GACtB,OAAO;EACT;CACF;AACF;;AAkBA,SAAgB,UAAgB,SAAqD;CACnF,MAAM,SAAS;EAAE,GAAG;EAAS,MAAM,gBAAgB,QAAQ,IAAI;CAAE;CACjE,OAAO;EACL,IAAI,OAAO;EACX,SAAS,OAAO;EAChB,aAAa,OAAO;EACpB,WAAW,OAAO;EAClB,MAAM,OAAO;EACb,MAAM,QAAQ,OAAO,SAAS;GAC5B,MAAM,EAAE,YAAY,mBAAmB,yBAAyB,SAAS,OAAO,EAAE;GAClF,MAAM,SAAS,eAAe;GAC9B,MAAM,SAAS,MAAM,OAAO,SAAS,OAAO,YAAY,cAAc;GACtE,MAAM,OAAO,SAAS,QAAQ,OAAO,cAAc;GACnD,OAAO,eAAe;GACtB,MAAM,WAAW,MAAM,OAAO,IAAI,OAAO,OAAO,OAAO,cAAc;GACrE,OAAO,eAAe;GACtB,OAAO;EACT;CACF;AACF"}
|
package/dist/evaluation.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as EvaluationResult, c as asJudge, i as EvaluationJudgeOptions, l as createEvaluator, n as EvaluationAnalystOptions, o as EvaluatorOptions, r as EvaluationContext, s as asAnalyst, t as CostedEvaluator } from "./evaluation-
|
|
1
|
+
import { a as EvaluationResult, c as asJudge, i as EvaluationJudgeOptions, l as createEvaluator, n as EvaluationAnalystOptions, o as EvaluatorOptions, r as EvaluationContext, s as asAnalyst, t as CostedEvaluator } from "./evaluation-D1PGzkPR.js";
|
|
2
2
|
export { CostedEvaluator, EvaluationAnalystOptions, EvaluationContext, EvaluationJudgeOptions, EvaluationResult, EvaluatorOptions, asAnalyst, asJudge, createEvaluator };
|
package/dist/evaluation.js
CHANGED
|
@@ -1,137 +1,2 @@
|
|
|
1
|
-
import { t as
|
|
2
|
-
//#region src/evaluation.ts
|
|
3
|
-
/** A metered function, independent of providers, question formats, and application policy. */
|
|
4
|
-
function createEvaluator(options) {
|
|
5
|
-
const defaults = { ...options };
|
|
6
|
-
const ledger = defaults.costLedger ?? new CostLedger();
|
|
7
|
-
return async (input, context = {}) => {
|
|
8
|
-
context.signal?.throwIfAborted();
|
|
9
|
-
const started = performance.now();
|
|
10
|
-
const paid = await (context.costLedger ?? ledger).runPaidCall({
|
|
11
|
-
callId: context.callId,
|
|
12
|
-
actor: context.actor ?? "evaluation",
|
|
13
|
-
channel: context.channel ?? "evaluation",
|
|
14
|
-
phase: context.costPhase ?? "evaluation",
|
|
15
|
-
tags: context.costTags,
|
|
16
|
-
model: typeof defaults.model === "function" ? defaults.model(input) : defaults.model,
|
|
17
|
-
signal: context.signal,
|
|
18
|
-
maximumCharge: context.maximumCharge ?? defaults.maximumCharge,
|
|
19
|
-
execute: (signal, idempotencyKey) => defaults.execute(input, {
|
|
20
|
-
signal,
|
|
21
|
-
idempotencyKey
|
|
22
|
-
}),
|
|
23
|
-
receipt: defaults.receipt,
|
|
24
|
-
receiptFromError: defaults.receiptFromError
|
|
25
|
-
});
|
|
26
|
-
if (paid.receipt) await context.onReceipt?.(paid.receipt);
|
|
27
|
-
if (!paid.succeeded) throw paid.error;
|
|
28
|
-
context.signal?.throwIfAborted();
|
|
29
|
-
await defaults.validate?.(paid.value, input);
|
|
30
|
-
context.signal?.throwIfAborted();
|
|
31
|
-
return {
|
|
32
|
-
value: paid.value,
|
|
33
|
-
receipt: paid.receipt,
|
|
34
|
-
durationMs: performance.now() - started
|
|
35
|
-
};
|
|
36
|
-
};
|
|
37
|
-
}
|
|
38
|
-
/** Return the existing contract. Mapping never performs another inference call. */
|
|
39
|
-
function asJudge(options) {
|
|
40
|
-
const config = {
|
|
41
|
-
...options,
|
|
42
|
-
dimensions: structuredClone(options.dimensions)
|
|
43
|
-
};
|
|
44
|
-
return {
|
|
45
|
-
name: config.name,
|
|
46
|
-
judgeVersion: config.version,
|
|
47
|
-
dimensions: config.dimensions,
|
|
48
|
-
appliesTo: config.appliesTo,
|
|
49
|
-
async score({ artifact, scenario, signal, costLedger, costPhase, costTags }) {
|
|
50
|
-
signal.throwIfAborted();
|
|
51
|
-
const input = {
|
|
52
|
-
artifact,
|
|
53
|
-
scenario
|
|
54
|
-
};
|
|
55
|
-
const result = await config.evaluate(input, {
|
|
56
|
-
signal,
|
|
57
|
-
costLedger,
|
|
58
|
-
actor: config.name,
|
|
59
|
-
channel: "judge",
|
|
60
|
-
costPhase,
|
|
61
|
-
costTags: {
|
|
62
|
-
...costTags,
|
|
63
|
-
scenarioId: scenario.id
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
await config.record?.(result, input);
|
|
67
|
-
signal.throwIfAborted();
|
|
68
|
-
const score = await config.map(result.value, input);
|
|
69
|
-
signal.throwIfAborted();
|
|
70
|
-
return score;
|
|
71
|
-
}
|
|
72
|
-
};
|
|
73
|
-
}
|
|
74
|
-
/** Registry, graph, and trace consumers keep the same Analyst interface. */
|
|
75
|
-
function asAnalyst(options) {
|
|
76
|
-
const config = {
|
|
77
|
-
...options,
|
|
78
|
-
cost: structuredClone(options.cost)
|
|
79
|
-
};
|
|
80
|
-
return {
|
|
81
|
-
id: config.id,
|
|
82
|
-
version: config.version,
|
|
83
|
-
description: config.description,
|
|
84
|
-
inputKind: config.inputKind,
|
|
85
|
-
cost: config.cost,
|
|
86
|
-
async analyze(input, context) {
|
|
87
|
-
const signals = context.signal ? [context.signal] : [];
|
|
88
|
-
if (context.deadlineMs !== void 0) {
|
|
89
|
-
const remaining = context.deadlineMs - Date.now();
|
|
90
|
-
if (!Number.isFinite(remaining)) throw new TypeError("Analyst deadline must be finite");
|
|
91
|
-
if (remaining <= 0) throw new DOMException("Analyst deadline exceeded", "TimeoutError");
|
|
92
|
-
signals.push(AbortSignal.timeout(Math.ceil(remaining)));
|
|
93
|
-
}
|
|
94
|
-
const signal = AbortSignal.any(signals);
|
|
95
|
-
signal.throwIfAborted();
|
|
96
|
-
const analystContext = {
|
|
97
|
-
...context,
|
|
98
|
-
signal
|
|
99
|
-
};
|
|
100
|
-
const result = await config.evaluate(input, {
|
|
101
|
-
signal,
|
|
102
|
-
costLedger: context.costLedger ?? (context.budgetUsd === void 0 ? void 0 : new CostLedger({ costCeilingUsd: context.budgetUsd })),
|
|
103
|
-
actor: config.id,
|
|
104
|
-
channel: "analyst",
|
|
105
|
-
costPhase: context.costPhase,
|
|
106
|
-
costTags: {
|
|
107
|
-
...context.tags,
|
|
108
|
-
runId: context.runId,
|
|
109
|
-
correlationId: context.correlationId
|
|
110
|
-
},
|
|
111
|
-
onReceipt: (receipt) => context.recordUsage?.({
|
|
112
|
-
calls: 1,
|
|
113
|
-
tokens: receipt.usageUnknown ? null : {
|
|
114
|
-
input: receipt.inputTokens,
|
|
115
|
-
output: receipt.outputTokens
|
|
116
|
-
},
|
|
117
|
-
cost: receipt.costUnknown ? {
|
|
118
|
-
kind: "uncaptured",
|
|
119
|
-
usd: null
|
|
120
|
-
} : {
|
|
121
|
-
kind: receipt.actualCostUsd === void 0 ? "estimated" : "observed",
|
|
122
|
-
usd: receipt.costUsd
|
|
123
|
-
}
|
|
124
|
-
})
|
|
125
|
-
}, analystContext);
|
|
126
|
-
await config.record?.(result, input, analystContext);
|
|
127
|
-
signal.throwIfAborted();
|
|
128
|
-
const findings = await config.map(result.value, input, analystContext);
|
|
129
|
-
signal.throwIfAborted();
|
|
130
|
-
return findings;
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
//#endregion
|
|
1
|
+
import { n as asJudge, r as createEvaluator, t as asAnalyst } from "./evaluation-wdGyZ7jV.js";
|
|
135
2
|
export { asAnalyst, asJudge, createEvaluator };
|
|
136
|
-
|
|
137
|
-
//# sourceMappingURL=evaluation.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as AnalystRunEvent, d as AnalystRunSummary, t as Analyst, u as AnalystRunResult } from "./types-
|
|
1
|
+
import { c as AnalystRunEvent, d as AnalystRunSummary, t as Analyst, u as AnalystRunResult } from "./types-DGImvHIr.js";
|
|
2
2
|
import { z } from "zod";
|
|
3
3
|
//#region src/analyst/exact-types.d.ts
|
|
4
4
|
/** Analyst metadata required before the exact registry path will execute it. */
|
|
@@ -231,4 +231,4 @@ declare const exactExecutionPlanSchema: z.ZodObject<{
|
|
|
231
231
|
}, z.core.$strict>;
|
|
232
232
|
//#endregion
|
|
233
233
|
export { ExactAnalystRunPolicySnapshot as a, ExactAnalystSnapshot as c, ExactExecutionComponentSnapshot as d, ExactAnalystRunEvent as i, ExactCapableAnalyst as l, ExactAnalystExecutionPlanSnapshot as n, ExactAnalystRunResult as o, ExactAnalystRunCompletion as r, ExactAnalystRunSummary as s, ExactAnalystBudgetSnapshot as t, ExactExecutionComponentIdentity as u };
|
|
234
|
-
//# sourceMappingURL=exact-types-
|
|
234
|
+
//# sourceMappingURL=exact-types-CVn1QxFO.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"exact-types-
|
|
1
|
+
{"version":3,"file":"exact-types-CVn1QxFO.d.ts","names":[],"sources":["../src/analyst/exact-types.ts"],"mappings":";;;;UAMiB,oBAAoB,0BAA0B,QAAQ;;WAE5D,iBAAiB,SAAS;;KAGhC,aAAa,KAAK,0BAA0B,mBACpC,aAAa,UACtB,+BACc,aAAa,IAAI,aAAa,EAAE,WAC5C;KAEM,uBAAuB,aAAa,EAAE,aAAa;KACnD,6BAA6B,aAAa,EAAE,aAAa;;UAGpD;EACf;EACA;EACA,QAAQ,SAAS;;;UAIF;EACf;EACA;EACA;;KAyBU,gCAAgC,aAAa,EAAE,aAAa;KAC5D,oCAAoC,aAC9C,EAAE,aAAa;KAGL,yBAAyB;;EAEnC;;KAGU;EACN;;EAEA;EACA;IAAS;IAAe;;;UAGb,8BAA8B;EAC7C,aAAa;EACb,gBAAgB;EAChB,YAAY;;;KAIF,wBACP,QAAQ;EAAmB;;EAC1B,gBAAgB;MAEjB,KAAK,QAAQ;EAAmB;;EAC/B,SAAS;KAEX,QAAQ;EAAmB;MAC1B,KAAK,QAAQ;EAAmB;;EAC/B,SAAS;MAEV,KAAK,QAAQ;EAAmB;;EAC/B,QAAQ;;cAwCR,uBAAqB,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAOzB,EAAA,KAAA;cAII,sBAAoB,EAAA,uBAAA,EAAA;;;;;;;;;;;GAaxB,EAAA,KAAA;cAiBI,sBAAoB,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAYxB,EAAA,KAAA;cAEI,0BAAwB,EAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+E1B,EAAA,KAAA"}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { n as bonferroni, r as holm, t as benjaminiHochberg } from "../multiplicity-DIWHvysC.js";
|
|
2
|
-
import { At as
|
|
2
|
+
import { $ as paretoPolicy, At as EProcess, B as ArmPopulationSummary, Bt as mcnemar, C as signManifest, Ct as FinalEvidenceError, Dt as FinalEvidenceRecord, E as MatchedPair, Et as FinalEvidenceOutcome, F as comparePairedArms, Gt as wilson, H as PowerPreflightOptions, Ht as pairedRiskDifferenceExact, I as pairArms, L as pairRunRecords, Lt as ProportionInterval, Mt as EProcessState, Nt as EProcessStep, O as PairArmsOptions, Ot as FinalEvidenceReservation, Pt as eProcess, Q as buildEvidenceVector, R as ArmAssignment, S as manifestContentDigest, St as FinalEvidenceConflictError, Tt as FinalEvidenceMeasurement, U as powerPreflight, Ut as pairedRiskDifferenceScore, V as PowerPreflight, Vt as pairedRiskDifference, Z as PromotionPolicy, _ as HypothesisManifest, at as CampaignEvidenceContext, b as SignedManifestAlgo, ct as EvidenceAuthority, d as SequentialObservation, dt as EvidenceReceipt, et as paretoSignificanceGate, f as SequentialPairedGate, ft as EvidenceReceiptVerification, g as sequentialPairedGate, h as sequentialDecide, ht as verifyEvidenceReceipt, i as PairedHoldout, j as PairedArmRow, jt as EProcessOptions, k as PairArmsResult, kt as openFinalEvidenceLedger, lt as EvidenceAuthorityKind, mt as isIndependentEvidence, n as HeldoutSignificance, o as heldoutSignificance, ot as createCampaignEvidenceReceipt, p as SequentialPairedGateOptions, pt as createEvidenceReceipt, q as EvidenceVector, r as HeldoutSignificanceOptions, s as pairHoldout, st as CreateEvidenceReceiptInput, u as SequentialGateDecision, ut as EvidenceBinding, v as HypothesisResult, w as verifyManifest, wt as FinalEvidenceLedger, x as hashJson, y as SignedManifest, z as ArmPopulationReading } from "../statistical-heldout-pD1Yah-0.js";
|
|
3
3
|
import { c as BOOTSTRAP_GATE_MIN_N, l as PairedBootstrapOptions, m as pairedBootstrap, u as PairedBootstrapResult } from "../paired-promotion-decision-CQMJ5xGN.js";
|
|
4
4
|
import { a as requiredPairedSampleSize, i as pairedMde, n as mcnemarPower, o as requiredSampleSize, r as mcnemarRequiredN, t as mulberry32 } from "../random-DGEyr3zG.js";
|
|
5
5
|
import { at as summarizeEvaluationUnits, it as defineEvaluationClaim, nt as EvaluationClaim, rt as EvaluationUnitSummary } from "../search-ledger-types-p2xKfiDJ.js";
|
|
6
|
-
import { a as PairedEvalueStep, i as PairedEvalueSequence, o as SequentialCrossingHorizon, r as PairedEvalueOptions, s as SequentialCrossingHorizonOptions, u as pairedEvalueSequence } from "../sequential-KwGspfeR.js";
|
|
7
6
|
import { a as JsonValue, i as EvidenceRecord, n as IntervalSpec, r as computeInterval, t as ComputedInterval } from "../interval-ohuOJurX.js";
|
|
7
|
+
import { a as PairedEvalueStep, i as PairedEvalueSequence, o as SequentialCrossingHorizon, r as PairedEvalueOptions, s as SequentialCrossingHorizonOptions, u as pairedEvalueSequence } from "../sequential-KwGspfeR.js";
|
|
8
8
|
import { z } from "zod";
|
|
9
9
|
//#region src/experiment/ast/predicate.d.ts
|
|
10
10
|
/**
|
|
@@ -985,5 +985,5 @@ interface ProspectiveCanaryJoinInput {
|
|
|
985
985
|
*/
|
|
986
986
|
export declare function joinProspectiveCanaryReceipts(input: ProspectiveCanaryJoinInput): CanaryObservation[];
|
|
987
987
|
//#endregion
|
|
988
|
-
export { type AdmissionExecution, type AdmissionPartition, type AdmissionRule, type AdmissionStage, type ArmRealizedBudget, type ArmSpec, BOOTSTRAP_GATE_MIN_N, type BudgetRule, type CampaignEvidenceContext, type CanaryArm, type CanaryAssignmentReceipt, type CanaryCohortReceipt, type CanaryCohortVerifier, type CanaryObservation, type CanaryRefusal, type ClusteredPowerOptions, type ClusteredPowerPoint, type ClusteredPowerRefusal, type ClusteredPowerResult, type ComputedInterval, type Condition, type CreateEvidenceReceiptInput, type DecisionBranch, type DecisionOutcome, type DecisionRule, type DerivedQuantities, type EProcess, type EProcessOptions, type EProcessState, type EProcessStep, type Estimand, type EstimandResult, type EvaluationClaim, type EvaluationUnitSummary, type EvidenceAuthority, type EvidenceAuthorityKind, type EvidenceBinding, type EvidenceDenominator, type EvidenceReceipt, type EvidenceReceiptVerification, type EvidenceRecord, type EvidenceRegistryRecord, type EvidenceState, type EvidenceVector, type ExperimentFunnel, type ExperimentGateEvidence, type ExperimentSpec, FinalEvidenceConflictError, FinalEvidenceError, type FinalEvidenceLedger, type FinalEvidenceMeasurement, type FinalEvidenceOutcome, type FinalEvidenceRecord, type FinalEvidenceReservation, type FunnelPartitionCount, type FunnelStageCount, type FunnelStageInput, type HaltOutcome, type HaltRule, type HeldoutSignificance, type HeldoutSignificanceOptions, type HypothesisManifest, type HypothesisResult, type IntervalSpec, type JsonValue, type MatchedBudgetRule, type MatchedBudgetVerdict, type MatchedPair, type NLadderProjection, type Obligation, type OutcomeSpec, type PairArmsOptions, type PairArmsResult, type PairedArmRow, type PairedBootstrapOptions, type PairedBootstrapResult, type PairedEvalueOptions, type PairedEvalueSequence, type PairedEvalueStep, type PairedHoldout, type PowerPreflight, type PowerPreflightOptions, type Predicate, type PromotionPolicy, type ProportionInterval, type ProspectiveCanaryAssignment, type ProspectiveCanaryBilling, type ProspectiveCanaryExecution, type ProspectiveCanaryJoinInput, type ProspectiveCanaryOutcome, type RandomizedCanaryDecision, type RandomizedCanaryRule, type RegisteredExperiment, type ReissuePolicy, type ReissueVerdict, type SealAmendment, type SealedExperiment, type SealedRandomizedCanaryRule, type SeedDerivation, type SelectionRule, type SequentialCrossingHorizon, type SequentialCrossingHorizonOptions, type SequentialGateDecision, type SequentialObservation, type SequentialPairedGate, type SequentialPairedGateOptions, type SetExpr, type SignFlipFloor, type SignedManifest, type SignedManifestAlgo, type UniformPassDecision, type UniformPassSchedule, type ValidityGate, type ValidityGateResult, benjaminiHochberg, bonferroni, buildEvidenceVector, comparePairedArms, computeInterval, createCampaignEvidenceReceipt, createEvidenceReceipt, defineEvaluationClaim, eProcess, hashJson, heldoutSignificance, holm, isIndependentEvidence, manifestContentDigest, mcnemar, mcnemarPower, mcnemarRequiredN, mulberry32, openFinalEvidenceLedger, pairArms, pairHoldout, pairRunRecords, pairedBootstrap, pairedEvalueSequence, pairedMde, pairedRiskDifference, pairedRiskDifferenceExact, pairedRiskDifferenceScore, paretoPolicy, paretoSignificanceGate, powerPreflight, requiredPairedSampleSize, requiredSampleSize, sequentialDecide, sequentialPairedGate, signManifest, summarizeEvaluationUnits, verifyEvidenceReceipt, verifyManifest, wilson };
|
|
988
|
+
export { type AdmissionExecution, type AdmissionPartition, type AdmissionRule, type AdmissionStage, type ArmAssignment, type ArmPopulationReading, type ArmPopulationSummary, type ArmRealizedBudget, type ArmSpec, BOOTSTRAP_GATE_MIN_N, type BudgetRule, type CampaignEvidenceContext, type CanaryArm, type CanaryAssignmentReceipt, type CanaryCohortReceipt, type CanaryCohortVerifier, type CanaryObservation, type CanaryRefusal, type ClusteredPowerOptions, type ClusteredPowerPoint, type ClusteredPowerRefusal, type ClusteredPowerResult, type ComputedInterval, type Condition, type CreateEvidenceReceiptInput, type DecisionBranch, type DecisionOutcome, type DecisionRule, type DerivedQuantities, type EProcess, type EProcessOptions, type EProcessState, type EProcessStep, type Estimand, type EstimandResult, type EvaluationClaim, type EvaluationUnitSummary, type EvidenceAuthority, type EvidenceAuthorityKind, type EvidenceBinding, type EvidenceDenominator, type EvidenceReceipt, type EvidenceReceiptVerification, type EvidenceRecord, type EvidenceRegistryRecord, type EvidenceState, type EvidenceVector, type ExperimentFunnel, type ExperimentGateEvidence, type ExperimentSpec, FinalEvidenceConflictError, FinalEvidenceError, type FinalEvidenceLedger, type FinalEvidenceMeasurement, type FinalEvidenceOutcome, type FinalEvidenceRecord, type FinalEvidenceReservation, type FunnelPartitionCount, type FunnelStageCount, type FunnelStageInput, type HaltOutcome, type HaltRule, type HeldoutSignificance, type HeldoutSignificanceOptions, type HypothesisManifest, type HypothesisResult, type IntervalSpec, type JsonValue, type MatchedBudgetRule, type MatchedBudgetVerdict, type MatchedPair, type NLadderProjection, type Obligation, type OutcomeSpec, type PairArmsOptions, type PairArmsResult, type PairedArmRow, type PairedBootstrapOptions, type PairedBootstrapResult, type PairedEvalueOptions, type PairedEvalueSequence, type PairedEvalueStep, type PairedHoldout, type PowerPreflight, type PowerPreflightOptions, type Predicate, type PromotionPolicy, type ProportionInterval, type ProspectiveCanaryAssignment, type ProspectiveCanaryBilling, type ProspectiveCanaryExecution, type ProspectiveCanaryJoinInput, type ProspectiveCanaryOutcome, type RandomizedCanaryDecision, type RandomizedCanaryRule, type RegisteredExperiment, type ReissuePolicy, type ReissueVerdict, type SealAmendment, type SealedExperiment, type SealedRandomizedCanaryRule, type SeedDerivation, type SelectionRule, type SequentialCrossingHorizon, type SequentialCrossingHorizonOptions, type SequentialGateDecision, type SequentialObservation, type SequentialPairedGate, type SequentialPairedGateOptions, type SetExpr, type SignFlipFloor, type SignedManifest, type SignedManifestAlgo, type UniformPassDecision, type UniformPassSchedule, type ValidityGate, type ValidityGateResult, benjaminiHochberg, bonferroni, buildEvidenceVector, comparePairedArms, computeInterval, createCampaignEvidenceReceipt, createEvidenceReceipt, defineEvaluationClaim, eProcess, hashJson, heldoutSignificance, holm, isIndependentEvidence, manifestContentDigest, mcnemar, mcnemarPower, mcnemarRequiredN, mulberry32, openFinalEvidenceLedger, pairArms, pairHoldout, pairRunRecords, pairedBootstrap, pairedEvalueSequence, pairedMde, pairedRiskDifference, pairedRiskDifferenceExact, pairedRiskDifferenceScore, paretoPolicy, paretoSignificanceGate, powerPreflight, requiredPairedSampleSize, requiredSampleSize, sequentialDecide, sequentialPairedGate, signManifest, summarizeEvaluationUnits, verifyEvidenceReceipt, verifyManifest, wilson };
|
|
989
989
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/experiment/index.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { n as CaptureIntegrityError, s as ValidationError } from "../errors-BcOs5MKW.js";
|
|
2
2
|
import { a as hashCanonical, t as LEDGER_HASH_PATTERN } from "../canonical-Dq2hOQ8L.js";
|
|
3
3
|
import { d as signManifest, f as verifyManifest, l as hashJson, u as manifestContentDigest } from "../agent-profile-cell-B1V1gUZs.js";
|
|
4
|
+
import { n as pairArms, r as pairRunRecords, t as comparePairedArms } from "../paired-arms-B2ttLc0_.js";
|
|
4
5
|
import { t as mulberry32 } from "../random-DDDcC7YU.js";
|
|
5
|
-
import { n as pairArms, r as pairRunRecords, t as comparePairedArms } from "../paired-arms-Ct4LTKc1.js";
|
|
6
6
|
import { n as bonferroni, r as holm, t as benjaminiHochberg } from "../multiplicity-Sg0U7h8j.js";
|
|
7
7
|
import { a as pairedRiskDifferenceScore, i as pairedRiskDifferenceExact, r as pairedRiskDifference, s as wilson, t as mcnemar } from "../paired-binary-B_nejA44.js";
|
|
8
8
|
import { c as studentTCdf, i as pairedBootstrap, l as studentTQuantile, n as BOOTSTRAP_GATE_MIN_N } from "../mean-BbA_JCzW.js";
|
|
9
|
-
import { a as requiredSampleSize, i as requiredPairedSampleSize, n as mcnemarRequiredN, r as pairedMde, t as mcnemarPower } from "../power-and-mde-
|
|
9
|
+
import { a as requiredSampleSize, i as requiredPairedSampleSize, n as mcnemarRequiredN, r as pairedMde, t as mcnemarPower } from "../power-and-mde-CQX-0weG.js";
|
|
10
10
|
import { t as eProcess } from "../sequential-eprocess-DodI6RoF.js";
|
|
11
11
|
import { a as heldoutSignificance, o as pairHoldout } from "../statistical-heldout-Bksv92Th.js";
|
|
12
12
|
import { S as openFinalEvidenceLedger, b as FinalEvidenceConflictError, i as verifyEvidenceReceipt, n as createEvidenceReceipt, r as isIndependentEvidence, t as createCampaignEvidenceReceipt, x as FinalEvidenceError, y as powerPreflight } from "../campaign-evidence-DunzcJGv.js";
|
package/dist/{external-optimizer-process-wOLfzsCC.js → external-optimizer-process-E5yY2SYS.js}
RENAMED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { n as contentHash } from "./verdict-cache-CL_7tePD.js";
|
|
2
|
-
import { _ as resolveExternalOptimizerCallbackLimits, a as closeServer, c as waitForActiveHandlers, h as isExternalTextCandidate, o as listenLocal, s as sendJsonIfOpen } from "./external-optimizer-subprocess-
|
|
2
|
+
import { _ as resolveExternalOptimizerCallbackLimits, a as closeServer, c as waitForActiveHandlers, h as isExternalTextCandidate, o as listenLocal, s as sendJsonIfOpen } from "./external-optimizer-subprocess-DA02c_L6.js";
|
|
3
3
|
import { n as isRecord } from "./json-BhdsJaOQ.js";
|
|
4
4
|
import { createServer } from "node:http";
|
|
5
5
|
//#region src/campaign/external-optimizer-callback.ts
|
|
@@ -233,4 +233,4 @@ function cloneCandidate(candidate) {
|
|
|
233
233
|
//#endregion
|
|
234
234
|
export { startExternalOptimizerCallback as t };
|
|
235
235
|
|
|
236
|
-
//# sourceMappingURL=external-optimizer-process-
|
|
236
|
+
//# sourceMappingURL=external-optimizer-process-E5yY2SYS.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"external-optimizer-process-wOLfzsCC.js","names":[],"sources":["../src/campaign/external-optimizer-callback.ts"],"sourcesContent":["import { createServer, type IncomingMessage, type ServerResponse } from 'node:http'\nimport { contentHash } from '../verdict-cache'\nimport {\n type ExternalOptimizerCallback,\n type ExternalOptimizerCallbackLimits,\n type ExternalOptimizerEvaluationObservation,\n type ExternalTextCandidate,\n type ExternalTextEvaluationRequest,\n isExternalTextCandidate,\n resolveExternalOptimizerCallbackLimits,\n} from './external-optimizer-contracts'\nimport { isRecord } from '../llm-client/json'\nimport {\n closeServer,\n listenLocal,\n sendJsonIfOpen,\n waitForActiveHandlers,\n} from './external-optimizer-http'\n\ntype UnsequencedObservation = ExternalOptimizerEvaluationObservation extends infer T\n ? T extends ExternalOptimizerEvaluationObservation\n ? Omit<T, 'sequence'>\n : never\n : never\n\nexport async function startExternalOptimizerCallback<TResponse>(args: {\n token: string\n maxEvaluations: number\n acceptEvaluation?: () => number | undefined\n evaluate: (request: ExternalTextEvaluationRequest, signal: AbortSignal) => Promise<TResponse>\n observe?: (observation: ExternalOptimizerEvaluationObservation) => void\n /** Loopback JSON byte limits. Omitted fields use finite defaults. */\n limits?: Partial<ExternalOptimizerCallbackLimits>\n signal?: AbortSignal\n}): Promise<ExternalOptimizerCallback> {\n assertCallbackConfig(args)\n const limits = resolveExternalOptimizerCallbackLimits(args.limits)\n args.signal?.throwIfAborted()\n let evaluations = 0\n let accepting = true\n let closePromise: Promise<void> | undefined\n const activeControllers = new Set<AbortController>()\n const activeHandlers = new Set<Promise<void>>()\n const proposedCandidateHashes = new Set<string>()\n let observationSequence = 0\n const server = createServer((request, response) => {\n if (!accepting) {\n sendJsonIfOpen(response, 503, { error: 'external optimizer callback is closing' })\n return\n }\n\n const controller = new AbortController()\n const abortRequest = (): void => {\n request.destroy()\n response.destroy()\n }\n activeControllers.add(controller)\n controller.signal.addEventListener('abort', abortRequest, { once: true })\n\n let handler!: Promise<void>\n handler = handleCallback(\n request,\n response,\n controller.signal,\n args,\n limits,\n () => {\n const accepted = args.acceptEvaluation ? args.acceptEvaluation() : evaluations + 1\n if (accepted === undefined) return undefined\n if (!Number.isSafeInteger(accepted) || accepted <= 0) {\n throw new Error('external optimizer callback: invalid accepted evaluation count')\n }\n if (accepted > args.maxEvaluations) return undefined\n evaluations += 1\n return accepted\n },\n (observation) => {\n if (!args.observe) return\n args.observe({ ...observation, sequence: ++observationSequence })\n },\n proposedCandidateHashes,\n ).finally(() => {\n controller.signal.removeEventListener('abort', abortRequest)\n activeControllers.delete(controller)\n activeHandlers.delete(handler)\n })\n activeHandlers.add(handler)\n void handler.catch(() => undefined)\n })\n const port = await listenLocal(server)\n const close = (): Promise<void> => {\n closePromise ??= closeCallbackServer()\n return closePromise\n }\n const onAbort = (): void => {\n void close().catch(() => undefined)\n }\n args.signal?.addEventListener('abort', onAbort, { once: true })\n if (args.signal?.aborted) onAbort()\n return {\n url: `http://127.0.0.1:${port}/evaluate`,\n token: args.token,\n evaluations: () => evaluations,\n close,\n }\n\n async function closeCallbackServer(): Promise<void> {\n args.signal?.removeEventListener('abort', onAbort)\n accepting = false\n const closingServer = closeServer(server)\n server.closeIdleConnections?.()\n for (const controller of activeControllers) controller.abort()\n const [serverResult] = await Promise.allSettled([\n closingServer,\n waitForActiveHandlers(activeHandlers),\n ])\n if (activeControllers.size !== 0 || activeHandlers.size !== 0) {\n throw new Error('external optimizer callback closed with active request work')\n }\n if (serverResult?.status === 'rejected') throw serverResult.reason\n }\n}\n\nasync function handleCallback<TResponse>(\n request: IncomingMessage,\n response: ServerResponse,\n signal: AbortSignal,\n args: {\n token: string\n maxEvaluations: number\n acceptEvaluation?: () => number | undefined\n evaluate: (request: ExternalTextEvaluationRequest, signal: AbortSignal) => Promise<TResponse>\n observe?: (observation: ExternalOptimizerEvaluationObservation) => void\n },\n limits: ExternalOptimizerCallbackLimits,\n nextEvaluation: () => number | undefined,\n observe: (observation: UnsequencedObservation) => void,\n proposedCandidateHashes: Set<string>,\n): Promise<void> {\n try {\n if (request.method !== 'POST' || request.url !== '/evaluate') {\n sendJsonIfOpen(response, 404, { error: 'not found' })\n return\n }\n if (request.headers.authorization !== `Bearer ${args.token}`) {\n sendJsonIfOpen(response, 401, { error: 'unauthorized' })\n return\n }\n let body: unknown\n try {\n body = await readJson(request, limits.maxRequestBytes)\n } catch {\n observe({ kind: 'refusal', reason: 'invalid-request' })\n sendJsonIfOpen(response, 400, { error: 'request body must be bounded valid JSON' })\n return\n }\n if (\n !isRecord(body) ||\n !isExternalTextCandidate(body.candidate) ||\n typeof body.exampleId !== 'string'\n ) {\n observe({ kind: 'refusal', reason: 'invalid-request' })\n sendJsonIfOpen(response, 400, { error: 'candidate and exampleId are required strings' })\n return\n }\n const candidate = cloneCandidate(body.candidate)\n const candidateHash = contentHash({ kind: 'external-text-candidate', candidate })\n if (!proposedCandidateHashes.has(candidateHash)) {\n observe({ kind: 'proposal', candidate, candidateHash })\n proposedCandidateHashes.add(candidateHash)\n }\n const count = nextEvaluation()\n if (count === undefined) {\n observe({\n kind: 'refusal',\n reason: 'evaluation-limit',\n candidate,\n candidateHash,\n exampleId: body.exampleId,\n })\n sendJsonIfOpen(response, 429, { error: 'evaluation limit reached' })\n return\n }\n let result: TResponse\n try {\n result = await args.evaluate({ candidate, exampleId: body.exampleId }, signal)\n } catch (error) {\n observe({\n kind: 'refusal',\n reason: 'evaluation-failed',\n candidate,\n candidateHash,\n exampleId: body.exampleId,\n })\n // The thrown detail is the only diagnostic for a failed evaluation —\n // an opaque 500 costs the caller a blind debugging round.\n sendJsonIfOpen(response, 500, {\n error: `evaluation failed: ${String(error).slice(0, 400)}`,\n })\n return\n }\n let encoded: string\n try {\n encoded = encodeJsonResponse(result)\n } catch {\n observe({\n kind: 'refusal',\n reason: 'evaluation-failed',\n candidate,\n candidateHash,\n exampleId: body.exampleId,\n })\n sendJsonIfOpen(response, 500, { error: 'evaluation response must be valid JSON' })\n return\n }\n if (Buffer.byteLength(encoded) > limits.maxResponseBytes) {\n observe({\n kind: 'refusal',\n reason: 'evaluation-failed',\n candidate,\n candidateHash,\n exampleId: body.exampleId,\n })\n sendJsonIfOpen(response, 413, { error: 'evaluation response too large' })\n return\n }\n observe({\n kind: 'evaluation',\n candidate,\n candidateHash,\n exampleId: body.exampleId,\n evaluationNumber: count,\n response: structuredClone(result),\n })\n sendEncodedJsonIfOpen(response, 200, encoded)\n } catch {\n sendJsonIfOpen(response, 500, { error: 'evaluation failed' })\n }\n}\n\nfunction readJson(request: IncomingMessage, maxRequestBytes: number): Promise<unknown> {\n return new Promise((resolvePromise, reject) => {\n let size = 0\n const chunks: Buffer[] = []\n request.on('data', (chunk: Buffer) => {\n size += chunk.length\n if (size > maxRequestBytes) {\n reject(new Error('callback body too large'))\n request.destroy()\n return\n }\n chunks.push(chunk)\n })\n request.on('error', reject)\n request.on('end', () => {\n try {\n resolvePromise(JSON.parse(Buffer.concat(chunks).toString('utf8')))\n } catch (error) {\n reject(error)\n }\n })\n })\n}\n\nfunction encodeJsonResponse(value: unknown): string {\n const encoded = JSON.stringify(value)\n if (encoded === undefined) throw new Error('evaluation response must be JSON-serializable')\n return encoded\n}\n\nfunction sendEncodedJsonIfOpen(response: ServerResponse, status: number, encoded: string): void {\n if (response.destroyed || response.writableEnded) return\n response.writeHead(status, {\n 'content-type': 'application/json; charset=utf-8',\n 'content-length': String(Buffer.byteLength(encoded)),\n })\n response.end(encoded)\n}\n\nfunction assertCallbackConfig(args: {\n token: string\n maxEvaluations: number\n acceptEvaluation?: () => number | undefined\n evaluate: (request: ExternalTextEvaluationRequest, signal: AbortSignal) => Promise<unknown>\n observe?: (observation: ExternalOptimizerEvaluationObservation) => void\n limits?: Partial<ExternalOptimizerCallbackLimits>\n signal?: AbortSignal\n}): void {\n if (typeof args.token !== 'string' || !args.token.trim()) {\n throw new Error('external optimizer callback: token must be non-empty')\n }\n if (!Number.isSafeInteger(args.maxEvaluations) || args.maxEvaluations <= 0) {\n throw new Error('external optimizer callback: maxEvaluations must be a positive safe integer')\n }\n if (args.acceptEvaluation !== undefined && typeof args.acceptEvaluation !== 'function') {\n throw new Error('external optimizer callback: acceptEvaluation must be a function')\n }\n if (typeof args.evaluate !== 'function') {\n throw new Error('external optimizer callback: evaluate must be a function')\n }\n if (args.observe !== undefined && typeof args.observe !== 'function') {\n throw new Error('external optimizer callback: observe must be a function')\n }\n}\n\nfunction cloneCandidate(candidate: ExternalTextCandidate): ExternalTextCandidate {\n return typeof candidate === 'string' ? candidate : { ...candidate }\n}\n"],"mappings":";;;;;AAyBA,eAAsB,+BAA0C,MASzB;CACrC,qBAAqB,IAAI;CACzB,MAAM,SAAS,uCAAuC,KAAK,MAAM;CACjE,KAAK,QAAQ,eAAe;CAC5B,IAAI,cAAc;CAClB,IAAI,YAAY;CAChB,IAAI;CACJ,MAAM,oCAAoB,IAAI,IAAqB;CACnD,MAAM,iCAAiB,IAAI,IAAmB;CAC9C,MAAM,0CAA0B,IAAI,IAAY;CAChD,IAAI,sBAAsB;CAC1B,MAAM,SAAS,cAAc,SAAS,aAAa;EACjD,IAAI,CAAC,WAAW;GACd,eAAe,UAAU,KAAK,EAAE,OAAO,yCAAyC,CAAC;GACjF;EACF;EAEA,MAAM,aAAa,IAAI,gBAAgB;EACvC,MAAM,qBAA2B;GAC/B,QAAQ,QAAQ;GAChB,SAAS,QAAQ;EACnB;EACA,kBAAkB,IAAI,UAAU;EAChC,WAAW,OAAO,iBAAiB,SAAS,cAAc,EAAE,MAAM,KAAK,CAAC;EAExE,IAAI;EACJ,UAAU,eACR,SACA,UACA,WAAW,QACX,MACA,cACM;GACJ,MAAM,WAAW,KAAK,mBAAmB,KAAK,iBAAiB,IAAI,cAAc;GACjF,IAAI,aAAa,KAAA,GAAW,OAAO,KAAA;GACnC,IAAI,CAAC,OAAO,cAAc,QAAQ,KAAK,YAAY,GACjD,MAAM,IAAI,MAAM,gEAAgE;GAElF,IAAI,WAAW,KAAK,gBAAgB,OAAO,KAAA;GAC3C,eAAe;GACf,OAAO;EACT,IACC,gBAAgB;GACf,IAAI,CAAC,KAAK,SAAS;GACnB,KAAK,QAAQ;IAAE,GAAG;IAAa,UAAU,EAAE;GAAoB,CAAC;EAClE,GACA,uBACF,CAAC,CAAC,cAAc;GACd,WAAW,OAAO,oBAAoB,SAAS,YAAY;GAC3D,kBAAkB,OAAO,UAAU;G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AQrB;CACP,IAAI,OAAO,KAAK,UAAU,YAAY,CAAC,KAAK,MAAM,KAAK,GACrD,MAAM,IAAI,MAAM,sDAAsD;CAExE,IAAI,CAAC,OAAO,cAAc,KAAK,cAAc,KAAK,KAAK,kBAAkB,GACvE,MAAM,IAAI,MAAM,6EAA6E;CAE/F,IAAI,KAAK,qBAAqB,KAAA,KAAa,OAAO,KAAK,qBAAqB,YAC1E,MAAM,IAAI,MAAM,kEAAkE;CAEpF,IAAI,OAAO,KAAK,aAAa,YAC3B,MAAM,IAAI,MAAM,0DAA0D;CAE5E,IAAI,KAAK,YAAY,KAAA,KAAa,OAAO,KAAK,YAAY,YACxD,MAAM,IAAI,MAAM,yDAAyD;AAE7E;AAEA,SAAS,eAAe,WAAyD;CAC/E,OAAO,OAAO,cAAc,WAAW,YAAY,EAAE,GAAG,UAAU;AACpE"}
|
|
1
|
+
{"version":3,"file":"external-optimizer-process-E5yY2SYS.js","names":[],"sources":["../src/campaign/external-optimizer-callback.ts"],"sourcesContent":["import { createServer, type IncomingMessage, type ServerResponse } from 'node:http'\nimport { contentHash } from '../verdict-cache'\nimport {\n type ExternalOptimizerCallback,\n type ExternalOptimizerCallbackLimits,\n type ExternalOptimizerEvaluationObservation,\n type ExternalTextCandidate,\n type ExternalTextEvaluationRequest,\n isExternalTextCandidate,\n resolveExternalOptimizerCallbackLimits,\n} from './external-optimizer-contracts'\nimport { isRecord } from '../llm-client/json'\nimport {\n closeServer,\n listenLocal,\n sendJsonIfOpen,\n waitForActiveHandlers,\n} from './external-optimizer-http'\n\ntype UnsequencedObservation = ExternalOptimizerEvaluationObservation extends infer T\n ? T extends ExternalOptimizerEvaluationObservation\n ? Omit<T, 'sequence'>\n : never\n : never\n\nexport async function startExternalOptimizerCallback<TResponse>(args: {\n token: string\n maxEvaluations: number\n acceptEvaluation?: () => number | undefined\n evaluate: (request: ExternalTextEvaluationRequest, signal: AbortSignal) => Promise<TResponse>\n observe?: (observation: ExternalOptimizerEvaluationObservation) => void\n /** Loopback JSON byte limits. Omitted fields use finite defaults. */\n limits?: Partial<ExternalOptimizerCallbackLimits>\n signal?: AbortSignal\n}): Promise<ExternalOptimizerCallback> {\n assertCallbackConfig(args)\n const limits = resolveExternalOptimizerCallbackLimits(args.limits)\n args.signal?.throwIfAborted()\n let evaluations = 0\n let accepting = true\n let closePromise: Promise<void> | undefined\n const activeControllers = new Set<AbortController>()\n const activeHandlers = new Set<Promise<void>>()\n const proposedCandidateHashes = new Set<string>()\n let observationSequence = 0\n const server = createServer((request, response) => {\n if (!accepting) {\n sendJsonIfOpen(response, 503, { error: 'external optimizer callback is closing' })\n return\n }\n\n const controller = new AbortController()\n const abortRequest = (): void => {\n request.destroy()\n response.destroy()\n }\n activeControllers.add(controller)\n controller.signal.addEventListener('abort', abortRequest, { once: true })\n\n let handler!: Promise<void>\n handler = handleCallback(\n request,\n response,\n controller.signal,\n args,\n limits,\n () => {\n const accepted = args.acceptEvaluation ? args.acceptEvaluation() : evaluations + 1\n if (accepted === undefined) return undefined\n if (!Number.isSafeInteger(accepted) || accepted <= 0) {\n throw new Error('external optimizer callback: invalid accepted evaluation count')\n }\n if (accepted > args.maxEvaluations) return undefined\n evaluations += 1\n return accepted\n },\n (observation) => {\n if (!args.observe) return\n args.observe({ ...observation, sequence: ++observationSequence })\n },\n proposedCandidateHashes,\n ).finally(() => {\n controller.signal.removeEventListener('abort', abortRequest)\n activeControllers.delete(controller)\n activeHandlers.delete(handler)\n })\n activeHandlers.add(handler)\n void handler.catch(() => undefined)\n })\n const port = await listenLocal(server)\n const close = (): Promise<void> => {\n closePromise ??= closeCallbackServer()\n return closePromise\n }\n const onAbort = (): void => {\n void close().catch(() => undefined)\n }\n args.signal?.addEventListener('abort', onAbort, { once: true })\n if (args.signal?.aborted) onAbort()\n return {\n url: `http://127.0.0.1:${port}/evaluate`,\n token: args.token,\n evaluations: () => evaluations,\n close,\n }\n\n async function closeCallbackServer(): Promise<void> {\n args.signal?.removeEventListener('abort', onAbort)\n accepting = false\n const closingServer = closeServer(server)\n server.closeIdleConnections?.()\n for (const controller of activeControllers) controller.abort()\n const [serverResult] = await Promise.allSettled([\n closingServer,\n waitForActiveHandlers(activeHandlers),\n ])\n if (activeControllers.size !== 0 || activeHandlers.size !== 0) {\n throw new Error('external optimizer callback closed with active request work')\n }\n if (serverResult?.status === 'rejected') throw serverResult.reason\n }\n}\n\nasync function handleCallback<TResponse>(\n request: IncomingMessage,\n response: ServerResponse,\n signal: AbortSignal,\n args: {\n token: string\n maxEvaluations: number\n acceptEvaluation?: () => number | undefined\n evaluate: (request: ExternalTextEvaluationRequest, signal: AbortSignal) => Promise<TResponse>\n observe?: (observation: ExternalOptimizerEvaluationObservation) => void\n },\n limits: ExternalOptimizerCallbackLimits,\n nextEvaluation: () => number | undefined,\n observe: (observation: UnsequencedObservation) => void,\n proposedCandidateHashes: Set<string>,\n): Promise<void> {\n try {\n if (request.method !== 'POST' || request.url !== '/evaluate') {\n sendJsonIfOpen(response, 404, { error: 'not found' })\n return\n }\n if (request.headers.authorization !== `Bearer ${args.token}`) {\n sendJsonIfOpen(response, 401, { error: 'unauthorized' })\n return\n }\n let body: unknown\n try {\n body = await readJson(request, limits.maxRequestBytes)\n } catch {\n observe({ kind: 'refusal', reason: 'invalid-request' })\n sendJsonIfOpen(response, 400, { error: 'request body must be bounded valid JSON' })\n return\n }\n if (\n !isRecord(body) ||\n !isExternalTextCandidate(body.candidate) ||\n typeof body.exampleId !== 'string'\n ) {\n observe({ kind: 'refusal', reason: 'invalid-request' })\n sendJsonIfOpen(response, 400, { error: 'candidate and exampleId are required strings' })\n return\n }\n const candidate = cloneCandidate(body.candidate)\n const candidateHash = contentHash({ kind: 'external-text-candidate', candidate })\n if (!proposedCandidateHashes.has(candidateHash)) {\n observe({ kind: 'proposal', candidate, candidateHash })\n proposedCandidateHashes.add(candidateHash)\n }\n const count = nextEvaluation()\n if (count === undefined) {\n observe({\n kind: 'refusal',\n reason: 'evaluation-limit',\n candidate,\n candidateHash,\n exampleId: body.exampleId,\n })\n sendJsonIfOpen(response, 429, { error: 'evaluation limit reached' })\n return\n }\n let result: TResponse\n try {\n result = await args.evaluate({ candidate, exampleId: body.exampleId }, signal)\n } catch (error) {\n observe({\n kind: 'refusal',\n reason: 'evaluation-failed',\n candidate,\n candidateHash,\n exampleId: body.exampleId,\n })\n // The thrown detail is the only diagnostic for a failed evaluation —\n // an opaque 500 costs the caller a blind debugging round.\n sendJsonIfOpen(response, 500, {\n error: `evaluation failed: ${String(error).slice(0, 400)}`,\n })\n return\n }\n let encoded: string\n try {\n encoded = encodeJsonResponse(result)\n } catch {\n observe({\n kind: 'refusal',\n reason: 'evaluation-failed',\n candidate,\n candidateHash,\n exampleId: body.exampleId,\n })\n sendJsonIfOpen(response, 500, { error: 'evaluation response must be valid JSON' })\n return\n }\n if (Buffer.byteLength(encoded) > limits.maxResponseBytes) {\n observe({\n kind: 'refusal',\n reason: 'evaluation-failed',\n candidate,\n candidateHash,\n exampleId: body.exampleId,\n })\n sendJsonIfOpen(response, 413, { error: 'evaluation response too large' })\n return\n }\n observe({\n kind: 'evaluation',\n candidate,\n candidateHash,\n exampleId: body.exampleId,\n evaluationNumber: count,\n response: structuredClone(result),\n })\n sendEncodedJsonIfOpen(response, 200, encoded)\n } catch {\n sendJsonIfOpen(response, 500, { error: 'evaluation failed' })\n }\n}\n\nfunction readJson(request: IncomingMessage, maxRequestBytes: number): Promise<unknown> {\n return new Promise((resolvePromise, reject) => {\n let size = 0\n const chunks: Buffer[] = []\n request.on('data', (chunk: Buffer) => {\n size += chunk.length\n if (size > maxRequestBytes) {\n reject(new Error('callback body too large'))\n request.destroy()\n return\n }\n chunks.push(chunk)\n })\n request.on('error', reject)\n request.on('end', () => {\n try {\n resolvePromise(JSON.parse(Buffer.concat(chunks).toString('utf8')))\n } catch (error) {\n reject(error)\n }\n })\n })\n}\n\nfunction encodeJsonResponse(value: unknown): string {\n const encoded = JSON.stringify(value)\n if (encoded === undefined) throw new Error('evaluation response must be JSON-serializable')\n return encoded\n}\n\nfunction sendEncodedJsonIfOpen(response: ServerResponse, status: number, encoded: string): void {\n if (response.destroyed || response.writableEnded) return\n response.writeHead(status, {\n 'content-type': 'application/json; charset=utf-8',\n 'content-length': String(Buffer.byteLength(encoded)),\n })\n response.end(encoded)\n}\n\nfunction assertCallbackConfig(args: {\n token: string\n maxEvaluations: number\n acceptEvaluation?: () => number | undefined\n evaluate: (request: ExternalTextEvaluationRequest, signal: AbortSignal) => Promise<unknown>\n observe?: (observation: ExternalOptimizerEvaluationObservation) => void\n limits?: Partial<ExternalOptimizerCallbackLimits>\n signal?: AbortSignal\n}): void {\n if (typeof args.token !== 'string' || !args.token.trim()) {\n throw new Error('external optimizer callback: token must be non-empty')\n }\n if (!Number.isSafeInteger(args.maxEvaluations) || args.maxEvaluations <= 0) {\n throw new Error('external optimizer callback: maxEvaluations must be a positive safe integer')\n }\n if (args.acceptEvaluation !== undefined && typeof args.acceptEvaluation !== 'function') {\n throw new Error('external optimizer callback: acceptEvaluation must be a function')\n }\n if (typeof args.evaluate !== 'function') {\n throw new Error('external optimizer callback: evaluate must be a function')\n }\n if (args.observe !== undefined && typeof args.observe !== 'function') {\n throw new Error('external optimizer callback: observe must be a function')\n }\n}\n\nfunction cloneCandidate(candidate: ExternalTextCandidate): ExternalTextCandidate {\n return typeof candidate === 'string' ? candidate : { ...candidate }\n}\n"],"mappings":";;;;;AAyBA,eAAsB,+BAA0C,MASzB;CACrC,qBAAqB,IAAI;CACzB,MAAM,SAAS,uCAAuC,KAAK,MAAM;CACjE,KAAK,QAAQ,eAAe;CAC5B,IAAI,cAAc;CAClB,IAAI,YAAY;CAChB,IAAI;CACJ,MAAM,oCAAoB,IAAI,IAAqB;CACnD,MAAM,iCAAiB,IAAI,IAAmB;CAC9C,MAAM,0CAA0B,IAAI,IAAY;CAChD,IAAI,sBAAsB;CAC1B,MAAM,SAAS,cAAc,SAAS,aAAa;EACjD,IAAI,CAAC,WAAW;GACd,eAAe,UAAU,K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AO,OAAO,cAAc,WAAW,YAAY,EAAE,GAAG,UAAU;AACpE"}
|
package/dist/{external-optimizer-subprocess-D670Oxf2.js → external-optimizer-subprocess-DA02c_L6.js}
RENAMED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { c as errorMessage } from "./errors-BcOs5MKW.js";
|
|
2
|
+
import { a as findingTreatmentSchema, c as findingEvidenceRefSchema, i as findingConditionsSchema, s as findingCalibrationSchema } from "./finding-composition-8n0fFgVI.js";
|
|
2
3
|
import { t as canonicalJson } from "./verdict-cache-CL_7tePD.js";
|
|
3
4
|
import { c as costForTokenPricing, t as CostLedger } from "./cost-ledger-BGZB6yY2.js";
|
|
4
5
|
import { t as deepFreezeCanonicalJson } from "./deep-freeze-CurcOQg3.js";
|
|
5
6
|
import { n as appendSearchLedgerLine, r as tryWithSearchLedgerFileLock } from "./search-ledger-file-Bd5Tioq6.js";
|
|
6
|
-
import { n as FINDING_SCOPE_FIELDS, t as ANALYST_SEVERITIES } from "./types-
|
|
7
|
+
import { n as FINDING_SCOPE_FIELDS, t as ANALYST_SEVERITIES } from "./types-CnWmj8NW.js";
|
|
7
8
|
import { n as isRecord } from "./json-BhdsJaOQ.js";
|
|
8
9
|
import { c as ModelSubstitutionError, d as assertServedModelPolicy, u as assertServedModel } from "./llm-client-DXuOTseU.js";
|
|
9
10
|
import { t as isNonnegativeFiniteNumber } from "./nonnegative-number-DvdMxg_f.js";
|
|
@@ -183,11 +184,7 @@ const methodSchema = z.object({
|
|
|
183
184
|
]),
|
|
184
185
|
name: nonEmpty,
|
|
185
186
|
version: nonEmpty,
|
|
186
|
-
calibration:
|
|
187
|
-
gold_n: z.number().int().positive(),
|
|
188
|
-
agreement: unitRate,
|
|
189
|
-
kappa: finite.refine((value) => value >= -1 && value <= 1, { message: "must be in [-1,1]" })
|
|
190
|
-
}).strict().optional()
|
|
187
|
+
calibration: findingCalibrationSchema.optional()
|
|
191
188
|
}).strict();
|
|
192
189
|
const measureSchema = z.object({
|
|
193
190
|
name: nonEmpty,
|
|
@@ -210,17 +207,7 @@ const findingObject = z.object({
|
|
|
210
207
|
area: nonEmpty,
|
|
211
208
|
claim: nonEmpty,
|
|
212
209
|
rationale: z.string().optional(),
|
|
213
|
-
evidence_refs: z.array(
|
|
214
|
-
kind: z.enum([
|
|
215
|
-
"span",
|
|
216
|
-
"event",
|
|
217
|
-
"artifact",
|
|
218
|
-
"finding",
|
|
219
|
-
"metric"
|
|
220
|
-
]),
|
|
221
|
-
uri: nonEmpty,
|
|
222
|
-
excerpt: z.string().optional()
|
|
223
|
-
}).strict()),
|
|
210
|
+
evidence_refs: z.array(findingEvidenceRefSchema),
|
|
224
211
|
recommended_action: z.string().optional(),
|
|
225
212
|
validation_plan: z.string().optional(),
|
|
226
213
|
confidence: unitRate,
|
|
@@ -234,7 +221,9 @@ const findingObject = z.object({
|
|
|
234
221
|
confounders: z.array(nonEmpty).optional(),
|
|
235
222
|
valid_for: nonEmpty.optional(),
|
|
236
223
|
claim_id: nonEmpty.optional(),
|
|
237
|
-
evidence_units: z.array(evidenceUnitSchema).min(1).optional()
|
|
224
|
+
evidence_units: z.array(evidenceUnitSchema).min(1).optional(),
|
|
225
|
+
treatment: z.array(findingTreatmentSchema).optional(),
|
|
226
|
+
conditions: z.array(findingConditionsSchema).optional()
|
|
238
227
|
}).strict();
|
|
239
228
|
function checkFinding(finding, context) {
|
|
240
229
|
const issue = (path, message) => context.addIssue({
|
|
@@ -258,6 +247,10 @@ function checkFinding(finding, context) {
|
|
|
258
247
|
if (measure?.interval && measure.interval[0] > measure.interval[1]) issue(["measure", "interval"], "interval lower bound exceeds its upper bound");
|
|
259
248
|
if (measure?.level !== void 0 && measure.interval === void 0) issue(["measure", "level"], "level describes an interval; none is present");
|
|
260
249
|
if (finding.method?.kind !== "judged" && finding.method?.calibration !== void 0) issue(["method", "calibration"], "only judged findings carry a calibration");
|
|
250
|
+
for (const field of ["treatment", "conditions"]) {
|
|
251
|
+
const values = finding[field];
|
|
252
|
+
if (values && new Set(values.map((value) => value.id)).size !== values.length) issue([field], "composition ids must be unique");
|
|
253
|
+
}
|
|
261
254
|
if (!units) return;
|
|
262
255
|
const ids = units.map((unit) => unit.id);
|
|
263
256
|
if (new Set(ids).size !== ids.length) issue(["evidence_units"], "unit ids must be unique");
|
|
@@ -2160,4 +2153,4 @@ function summarizeProcessOutput(capture, max = 4e3) {
|
|
|
2160
2153
|
//#endregion
|
|
2161
2154
|
export { spanningWindow as A, UNKNOWN_LINEAGE as C, mostSevere as D, mergeEvidenceUnits as E, fsCampaignStorage as M, inMemoryCampaignStorage as N, parseAnalystFinding as O, ProposalFindingSchema as S, lineageRoots as T, resolveExternalOptimizerCallbackLimits as _, closeServer as a, AnalystFindingSchema as b, waitForActiveHandlers as c, assertExternalOptimizerModelBudget as d, assertJsonValue as f, removeCredentialEnvironment as g, isExternalTextCandidate as h, startExternalOptimizerModelProxy as i, createRunCostLedger as j, readFindingScope as k, DEFAULT_EXTERNAL_OPTIMIZER_CALLBACK_LIMITS as l, isCandidateText as m, closeExternalOptimizerResources as n, listenLocal as o, assertNoCredentialValues as p, runWithCleanup as r, sendJsonIfOpen as s, runExternalOptimizerProcess as t, DEFAULT_EXTERNAL_OPTIMIZER_PROCESS_LIMITS as u, resolveExternalOptimizerProcessLimits as v, independentUnitCount as w, FINDING_LAYERS as x, safePathComponent as y };
|
|
2162
2155
|
|
|
2163
|
-
//# sourceMappingURL=external-optimizer-subprocess-
|
|
2156
|
+
//# sourceMappingURL=external-optimizer-subprocess-DA02c_L6.js.map
|