niceeval 0.17.0 → 0.18.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/INDEX.md +1 -0
- package/dist/adapter.cjs +4 -0
- package/dist/adapter.cjs.map +1 -1
- package/dist/adapter.d.cts +25 -14
- package/dist/adapter.d.mts +25 -14
- package/dist/adapter.d.ts +25 -14
- package/dist/assertions/measurements.cjs +45 -0
- package/dist/assertions/measurements.cjs.map +1 -0
- package/dist/assertions/measurements.d.cts +17 -0
- package/dist/assertions/measurements.d.mts +17 -0
- package/dist/assertions/measurements.d.ts +17 -0
- package/dist/assertions/measurements.js +8 -0
- package/dist/assertions/measurements.js.map +1 -0
- package/dist/define.cjs +2 -0
- package/dist/define.cjs.map +1 -1
- package/dist/expect/index.cjs +4 -1
- package/dist/expect/index.cjs.map +1 -1
- package/dist/expect/index.d.cts +3 -1
- package/dist/expect/index.d.mts +3 -1
- package/dist/expect/index.d.ts +3 -1
- package/dist/expect/index.js +20 -16
- package/dist/expect/index.mjs +20 -16
- package/dist/experiment/host/operations.cjs +3 -1
- package/dist/experiment/host/operations.cjs.map +1 -1
- package/dist/experiment/host/runtime.cjs +3 -1
- package/dist/experiment/host/runtime.cjs.map +1 -1
- package/dist/experiment/host/teardown.cjs +1 -0
- package/dist/experiment/host/teardown.cjs.map +1 -1
- package/dist/index.cjs +3 -19
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -7
- package/dist/index.d.mts +3 -7
- package/dist/index.d.ts +3 -7
- package/dist/index.js +12 -34
- package/dist/index.mjs +12 -34
- package/dist/model-slots.cjs +19 -0
- package/dist/model-slots.cjs.map +1 -1
- package/dist/model-slots.d.cts +7 -0
- package/dist/model-slots.d.mts +7 -0
- package/dist/model-slots.d.ts +7 -0
- package/dist/model-slots.js +8 -2
- package/dist/o11y/eval-usage.cjs +20 -2
- package/dist/o11y/eval-usage.cjs.map +1 -1
- package/dist/o11y/eval-usage.d.cts +7 -2
- package/dist/o11y/eval-usage.d.mts +7 -2
- package/dist/o11y/eval-usage.d.ts +7 -2
- package/dist/runner/adoption.cjs +1 -0
- package/dist/runner/adoption.cjs.map +1 -1
- package/dist/runner/eval-selection.cjs +15 -1
- package/dist/runner/eval-selection.cjs.map +1 -1
- package/dist/runner/eval-selection.d.cts +4 -0
- package/dist/runner/eval-selection.d.mts +4 -0
- package/dist/runner/eval-selection.d.ts +4 -0
- package/dist/runner/lock.cjs +1 -3
- package/dist/runner/lock.cjs.map +1 -1
- package/dist/runner/lock.d.cts +0 -2
- package/dist/runner/lock.d.mts +0 -2
- package/dist/runner/lock.d.ts +0 -2
- package/dist/runner/lock.js +14 -16
- package/dist/runner/types.cjs.map +1 -1
- package/dist/runner/types.d.cts +1 -0
- package/dist/runner/types.d.mts +1 -0
- package/dist/runner/types.d.ts +1 -0
- package/dist/sandbox/docker-profile/registry.cjs +1 -2
- package/dist/sandbox/docker-profile/registry.cjs.map +1 -1
- package/dist/sandbox/docker-profile/registry.d.cts +0 -1
- package/dist/sandbox/docker-profile/registry.d.mts +0 -1
- package/dist/sandbox/docker-profile/registry.d.ts +0 -1
- package/dist/sandbox/docker-profile/registry.js +2 -4
- package/dist/sandbox/index.cjs +1 -2
- package/dist/sandbox/index.cjs.map +1 -1
- package/dist/sandbox/index.d.cts +1 -1
- package/dist/sandbox/index.d.mts +1 -1
- package/dist/sandbox/index.d.ts +1 -1
- package/dist/sandbox/index.js +32 -34
- package/dist/sandbox/index.mjs +32 -34
- package/docs-site/zh/examples/integrations/ai-sdk-v7.mdx +5 -5
- package/docs-site/zh/examples/integrations/claude-sdk.mdx +5 -5
- package/docs-site/zh/examples/integrations/langgraph.mdx +3 -3
- package/docs-site/zh/examples/integrations/pi-sdk.mdx +5 -5
- package/docs-site/zh/explanation/judge.mdx +1 -1
- package/docs-site/zh/index.mdx +18 -0
- package/docs-site/zh/introduction.mdx +2 -1
- package/docs-site/zh/reference/define-agent.mdx +2 -2
- package/docs-site/zh/tutorials/authoring.mdx +2 -1
- package/docs-site/zh/tutorials/control-run-cost.mdx +84 -5
- package/docs-site/zh/tutorials/upgrade-0-18.mdx +64 -0
- package/docs-site/zh/tutorials/verify-judge.mdx +2 -1
- package/package.json +1 -1
package/INDEX.md
CHANGED
|
@@ -73,6 +73,7 @@
|
|
|
73
73
|
- `docs-site/zh/tutorials/sandbox-providers.mdx` — 选择并配置 Sandbox:Docker、Vercel 或 E2B:给 Coding Agent 选一个隔离运行环境:本地 Docker、Vercel 或 E2B。按顺序准备环境,并用预制镜像和缓存让每次评估更快开始。
|
|
74
74
|
- `docs-site/zh/tutorials/sandbox-reuse.mdx` — 在一批评估中复用 Sandbox:每条 Attempt 都新建 Sandbox 太慢时,用 sandboxReuse 让一批 Attempt 依次共用同一个 Sandbox。说明它省了什么、留下了什么,以及准备代码要怎么写才能安全重放。
|
|
75
75
|
- `docs-site/zh/tutorials/select-and-preview.mdx` — 运行前确认跑哪些、跑几次:列出有哪些 Experiment,用 ID 前缀和 tag 缩小范围,再用 --dry 看清这次会跑哪些评估用例、多少次,确认无误再花钱。
|
|
76
|
+
- `docs-site/zh/tutorials/upgrade-0-18.mdx` — 升级到 0.18:共享模型用途、原生数值材料与公开入口调整
|
|
76
77
|
- `docs-site/zh/tutorials/verify-judge.mdx` — 配置 Judge,并确认它真的能打分:给裁判模型 Judge 选好 Provider、模型和 API Key,再用一条最小评估跑一次真实判分,确认配置无误后再大批使用。
|
|
77
78
|
- `docs-site/zh/tutorials/viewing-results.mdx` — 查看运行结果:从总览找到失败原因:跑完评估后,用 niceeval show 在终端从总览逐层找到失败的那次运行,查看对话、耗时、用量和文件改动;在浏览器用 view 翻看;脚本和 CI 用 query 读 JSON。
|
|
78
79
|
- `docs-site/zh/tutorials/write-experiment.mdx` — 编写实验:比较模型、prompt 和 Agent:用 defineExperiment 固定被测 Agent、模型、flags 和运行次数。同一批评估用例写两份只差一个变量的 Experiment,就能比较两个模型或两版 prompt。
|
package/dist/adapter.cjs
CHANGED
|
@@ -6,6 +6,7 @@ exports.adapterIdentity = adapterIdentity;
|
|
|
6
6
|
exports.adapterAcceptsEval = adapterAcceptsEval;
|
|
7
7
|
exports.adapterContractRequiredByEval = adapterContractRequiredByEval;
|
|
8
8
|
exports.bindAdapterEvalContext = bindAdapterEvalContext;
|
|
9
|
+
const model_slots_ts_1 = require("./model-slots.cjs");
|
|
9
10
|
const adapter_cleanup_ts_1 = require("./shared/adapter-cleanup.cjs");
|
|
10
11
|
const runtime_ts_1 = require("./assertions/runtime.cjs");
|
|
11
12
|
const adapter_flags_ts_1 = require("./adapter-flags.cjs");
|
|
@@ -79,12 +80,14 @@ function boundEvalFactories(token) {
|
|
|
79
80
|
assertAdapterEvalInput(input, "defineEval");
|
|
80
81
|
return (0, define_ts_1.defineEvalForContext)("pass", input, {
|
|
81
82
|
[EVAL_ADAPTER_CONTRACT_TOKEN]: token,
|
|
83
|
+
requiredModelSlots: (0, model_slots_ts_1.normalizeModelRequirements)(input.requires),
|
|
82
84
|
});
|
|
83
85
|
},
|
|
84
86
|
defineScoreEval(input) {
|
|
85
87
|
assertAdapterEvalInput(input, "defineScoreEval");
|
|
86
88
|
return (0, define_ts_1.defineEvalForContext)("score", input, {
|
|
87
89
|
[EVAL_ADAPTER_CONTRACT_TOKEN]: token,
|
|
90
|
+
requiredModelSlots: (0, model_slots_ts_1.normalizeModelRequirements)(input.requires),
|
|
88
91
|
});
|
|
89
92
|
},
|
|
90
93
|
};
|
|
@@ -113,6 +116,7 @@ function implementAdapter(token, input, factory) {
|
|
|
113
116
|
};
|
|
114
117
|
return Object.freeze({
|
|
115
118
|
kind: "custom",
|
|
119
|
+
requiredModelSlots: (0, model_slots_ts_1.normalizeModelRequirements)(input.requires),
|
|
116
120
|
parseFlags: token.parseFlags,
|
|
117
121
|
name: input.name,
|
|
118
122
|
contract: token.name,
|
package/dist/adapter.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["ad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AU,CAAC;IAClC,CAAC;IACD,IAAA,iCAAoB,EAAC,IAAI,CAAC,KAAK,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC;IAC5C,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,IAAI,CAAW,CAAC;IAC7C,iBAAiB,CAAC,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC;IACzD,iBAAiB,CAAC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC;IACxD,IAAI,UAAU,KAAK,SAAS;QACxB,iBAAiB,CAAC,MAAM,EAAE,UAAU,EAAE,KAAK,EAAE,gBAAgB,CAAC,CAAC;IACnE,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAA0C,CAAC;AAC1E,CAAC","sourcesContent":["import type { ResolvedModelSlots } from \"./model-slots.ts\";\nimport { resolveAdapterCleanupTimeoutMs } from \"./shared/adapter-cleanup.ts\";\nimport type { AttemptSignal } from \"./shared/attempt-lifecycle.ts\";\nexport type { AttemptCancellation, AttemptSignal } from \"./shared/attempt-lifecycle.ts\";\nimport { bindAssertionContext } from \"./assertions/runtime.ts\";\nimport type { MatchContext } from \"./assertions/context-match.ts\";\nimport type { EvalUsage } from \"./o11y/eval-usage.ts\";\nimport type { ExperimentFlags } from \"./shared/types.ts\";\nimport { assertAdapterFlagsParser, type AdapterFlagsParser, type AdapterFlagsOutput, type AdapterFlagsParserValidation, type AdapterFlagsParserValidationArgs, } from \"./adapter-flags.ts\";\nimport type { AssertionCheck, AssertionSubject, AssertionsRuntime, BooleanAssertionHandle, MeasurementAssertionHandle, PolymorphicBooleanAssertionHandle, PolymorphicMeasurementAssertionHandle, } from \"./assertions/api.ts\";\nimport type { ScoreMatch } from \"./assertions/match.ts\";\nimport { defineEvalForContext } from \"./define.ts\";\nimport type { EvalDefinition, EvalInput, ScoreEvalInput } from \"./runner/types.ts\";\nimport type { EvaluationKind } from \"./shared/evaluation.ts\";\nimport type { JudgePresetMethods } from \"./context/assert-first.ts\";\nimport type { DiagnosticInput, ProgressUpdate } from \"./shared/types.ts\";\nimport type { AdapterIdentity } from \"./record/model/run-context.ts\";\nexport type { AdapterIdentity } from \"./record/model/run-context.ts\";\nconst ADAPTER_CONTRACT_TOKEN: unique symbol = Symbol(\"niceeval.adapterContractToken\");\nconst EVAL_ADAPTER_CONTRACT_TOKEN: unique symbol = Symbol(\"niceeval.evalAdapterContractToken\");\n/**\n * Synchronously assembles Attempt-local Assertion methods from the guarded app\n * facade and the shared check registrar. The returned object must contain only\n * ordinary, synchronously returning methods. Generic and overloaded Assertion\n * sugar is intentionally not callable after binding; use ordinary named\n * parameters so argument and native handle types remain exact.\n */\nexport type AdapterAssertionsFactory<Context extends object, Assertions extends object = object> = (context: AdapterAssertionsFactoryContext<Context>) => Assertions;\n/**\n * Definition inputs for Adapter Assertion sugar. `app` becomes callable after\n * assembly, and `check` may only be called by a returned Assertion method.\n */\nexport interface AdapterAssertionsFactoryContext<Context extends object> {\n readonly app: MatchContext<Context>;\n readonly check: AssertionCheck<\"polymorphic\", Context>;\n}\ntype BoundAdapterAssertionResult<Kind extends EvaluationKind, Result> = Result extends PolymorphicBooleanAssertionHandle<infer Refined, infer HasGate> ? BooleanAssertionHandle<Kind, Refined, HasGate> : Result extends PolymorphicMeasurementAssertionHandle<infer HasCondition> ? MeasurementAssertionHandle<Kind, HasCondition> : never;\ntype BoundAdapterAssertionMethod<Kind extends EvaluationKind, Method> = Method extends (...args: infer Args) => infer Result ? ((...args: Args) => Result) extends Method ? (...args: Args) => BoundAdapterAssertionResult<Kind, Result> : never : never;\ntype AdapterAssertionsFor<Assertions extends object | undefined, Kind extends EvaluationKind> = Assertions extends object ? {\n readonly [Key in keyof Assertions]: BoundAdapterAssertionMethod<Kind, Assertions[Key]>;\n} : {};\n/** Keys owned by the neutral Eval runtime or unsafe on a merged object root. */\nconst RESERVED_ADAPTER_CONTEXT_KEYS = [\n \"evaluationKind\",\n \"check\",\n \"judge\",\n \"factuality\",\n \"faithfulness\",\n \"instructionFollowing\",\n \"pairwisePreference\",\n \"closeQA\",\n \"usage\",\n \"elapsedMs\",\n \"maxTokens\",\n \"maxCost\",\n \"score\",\n \"group\",\n \"skip\",\n \"signal\",\n \"model\",\n \"reasoningEffort\",\n \"flags\",\n \"progress\",\n \"diagnostic\",\n \"log\",\n \"then\",\n \"Object\",\n \"constructor\",\n \"__defineGetter__\",\n \"__defineSetter__\",\n \"hasOwnProperty\",\n \"__lookupGetter__\",\n \"__lookupSetter__\",\n \"isPrototypeOf\",\n \"propertyIsEnumerable\",\n \"toString\",\n \"valueOf\",\n \"__proto__\",\n \"toLocaleString\",\n] as const;\nexport type ReservedAdapterContextKey = typeof RESERVED_ADAPTER_CONTEXT_KEYS[number];\ntype InvalidContextBranch<Context> = Context extends unknown ? Context extends object ? Context extends readonly unknown[] ? Context : Context extends (...args: readonly never[]) => unknown ? Context : string extends keyof Context ? Context : Extract<keyof Context, ReservedAdapterContextKey> extends never ? never : Context : Context : never;\ntype AdapterContextValidation<Context> = unknown extends Context ? unknown : [\n InvalidContextBranch<Context>\n] extends [\n never\n] ? unknown : {\n readonly invalidAdapterContext: InvalidContextBranch<Context>;\n};\ntype InvalidAssertionMethodKey<Context extends object, Assertions> = Assertions extends object ? {\n [Key in keyof Assertions]: Key extends string ? Key extends ReservedAdapterContextKey | keyof Context ? Key : Assertions[Key] extends (...args: readonly never[]) => infer Result ? Result extends PolymorphicBooleanAssertionHandle<unknown, boolean> | PolymorphicMeasurementAssertionHandle<boolean> ? never : Key : Key : Key;\n}[keyof Assertions] : \"assertions\";\ntype InvalidAdapterAssertions<Context extends object, Assertions extends object> = InvalidAssertionMethodKey<Context, Assertions>;\ntype AdapterAssertionsValidation<Context extends object, Assertions extends object> = [\n InvalidAdapterAssertions<Context, Assertions>\n] extends [\n never\n] ? unknown : {\n readonly invalidAdapterAssertions: InvalidAdapterAssertions<Context, Assertions>;\n};\ntype AdapterAssertionsValidationArgs<Context extends object, Assertions extends object> = [\n InvalidAdapterAssertions<Context, Assertions>\n] extends [\n never\n] ? [\n] : [\n error: {\n readonly invalidAdapterAssertions: InvalidAdapterAssertions<Context, Assertions>;\n }\n];\ntype AdapterFactory<Context extends object, Flags extends AdapterFlagsParser = undefined> = (context: AdapterCreateContext<AdapterFlagsOutput<Flags>>) => (Context & ThisType<Context>) | Promise<Context & ThisType<Context>>;\nexport interface AdapterCleanupContext {\n /** 整个清理窗口的固定毫秒预算,不为每个回调续期。 */\n readonly timeoutMs: number;\n /** 清理窗口实际开始时确定的 Unix 毫秒截止时间。 */\n readonly deadlineAt: number;\n /** 独立于执行信号;整个 Adapter 清理窗口截止时中止。 */\n readonly signal: AbortSignal;\n}\nexport interface AdapterCreateContext<Flags = ExperimentFlags> {\n /** Frozen application model selections for this Attempt. */\n readonly models: ResolvedModelSlots;\n recordUsage(input: import(\"./adapter-usage.ts\").AdapterUsageInput): void;\n /** Close application usage admission and declare whether the recorded collection is complete. */\n sealUsage(input: import(\"./adapter-usage.ts\").AdapterUsageSeal): void;\n attach(input: import(\"./adapter-attachments.ts\").AdapterAttachmentInput): Promise<import(\"./adapter-attachments.ts\").AdapterAttachmentReceipt>;\n recordTrace<Event extends import(\"./adapter-execution-trace.ts\").ExecutionTraceEvent>(input: import(\"./adapter-execution-trace.ts\").ExecutionTraceInput<Event>): Promise<import(\"./adapter-execution-trace.ts\").ExecutionTraceReceipt>;\n /** 当前 Eval 的公开 ID。 */\n readonly evalId: string;\n /** 当前 Experiment 的公开 ID。 */\n readonly experimentId: string;\n /** 当前 Attempt 的零起始序号。 */\n readonly attempt: number;\n /** Attempt 执行信号;reason 区分 timeout 与 cancelled,不用于 cleanup 窗口。 */\n readonly signal: AttemptSignal;\n /** Experiment 选择的模型。 */\n readonly model?: string;\n /** Experiment 选择的推理强度。 */\n readonly reasoningEffort?: string;\n /** Experiment 传给 Adapter 的只读 flags。 */\n readonly flags: Flags;\n /** 更新当前 Attempt 的人读进度。 */\n progress(update: ProgressUpdate): void;\n /** 为当前 Attempt 追加结构化诊断。 */\n diagnostic(input: DiagnosticInput): void;\n /** 为当前 Attempt 追加日志。 */\n log(message: string): void;\n /**\n * 登记 Attempt-local 资源释放。回调按全局 LIFO 执行;一项失败不会跳过其余项。\n * 零参数回调仍可直接传入。传入的 context 已冻结,同一 cleanup 窗口的回调共享一个 signal。\n */\n onCleanup(cleanup: (context: AdapterCleanupContext) => void | Promise<void>): void;\n}\ntype EvalContextBase<Kind extends EvaluationKind, Flags, Context> = JudgePresetMethods<Kind, Context> & {\n readonly usage: EvalUsage;\n readonly elapsedMs: import(\"./assertions/match.ts\").NumericMaterial;\n maxTokens(max: number): BooleanAssertionHandle<Kind, number>;\n maxCost(usd: number | string): BooleanAssertionHandle<Kind, string>;\n readonly evaluationKind: Kind;\n readonly signal: AbortSignal;\n readonly model?: string;\n readonly reasoningEffort?: string;\n readonly flags: Flags;\n progress(update: ProgressUpdate): void;\n diagnostic(input: DiagnosticInput): void;\n log(message: string): void;\n skip(reason: string): never;\n group<Value>(title: string, body: () => Value | PromiseLike<Value>): Promise<Awaited<Value>>;\n readonly check: AssertionCheck<Kind, Context>;\n readonly judge: <Value>(value: AssertionSubject<Value>, definition: ScoreMatch<NoInfer<Value>>) => MeasurementAssertionHandle<Kind>;\n};\n/** Agent-neutral author context shared by every Adapter Eval. */\nexport type EvalContext<Kind extends EvaluationKind = \"pass\", Flags = ExperimentFlags, Context = unknown> = EvalContextBase<Kind, Flags, Context> & (Kind extends \"score\" ? {\n readonly score: AssertionsRuntime<\"score\">[\"t\"][\"score\"];\n} : {});\ntype AdapterEvalFields = Omit<EvalInput<undefined>, \"test\" | \"sandbox\" | \"diff\"> & {\n readonly sandbox?: never;\n readonly diff?: never;\n};\ntype AdapterScoreEvalFields = Omit<ScoreEvalInput<undefined>, \"test\" | \"sandbox\" | \"diff\"> & {\n readonly sandbox?: never;\n readonly diff?: never;\n};\nexport type AdapterEvalInput<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined> = AdapterEvalFields & {\n test(t: EvalContext<\"pass\", AdapterFlagsOutput<Flags>, Context> & Readonly<Context> & AdapterAssertionsFor<Assertions, \"pass\">): void | Promise<void>;\n};\nexport type AdapterScoreEvalInput<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined> = AdapterScoreEvalFields & {\n test(t: EvalContext<\"score\", AdapterFlagsOutput<Flags>, Context> & Readonly<Context> & AdapterAssertionsFor<Assertions, \"score\">): void | Promise<void>;\n};\ninterface AdapterContractToken<Context extends object, Assertions extends object | undefined, Flags extends AdapterFlagsParser = undefined> {\n readonly name: string;\n readonly assertions: AdapterAssertionsFactory<Context> | undefined;\n readonly parseFlags: Flags;\n /** Keeps the Assertion method shape invariant without exposing a constructible brand. */\n readonly assertionTypes: (value: Assertions) => Assertions;\n /** Keeps the context parameter invariant without exposing a constructible brand. */\n readonly context: (value: Context) => Context;\n}\nexport interface AdapterEvalDefinition<Kind extends EvaluationKind, Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined> extends EvalDefinition<Kind, EvalContext<Kind, AdapterFlagsOutput<Flags>, Context> & Readonly<Context> & AdapterAssertionsFor<Assertions, Kind>, undefined> {\n readonly [EVAL_ADAPTER_CONTRACT_TOKEN]: AdapterContractToken<Context, Assertions, Flags>;\n}\n/** @internal Existential discovery view; concrete bound factories retain their exact Context. */\nexport interface AdapterRuntimeEvalDefinition<Kind extends EvaluationKind> extends EvalDefinition<Kind, never, undefined> {\n readonly [EVAL_ADAPTER_CONTRACT_TOKEN]: object;\n}\n/** Common public surface for an Adapter definition with bound Eval factories. */\nexport interface AdapterDefinition<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined> {\n readonly name: string;\n readonly parseFlags: Flags;\n defineEval(input: AdapterEvalInput<Context, Assertions, Flags>): AdapterEvalDefinition<\"pass\", Context, Assertions, Flags>;\n defineScoreEval(input: AdapterScoreEvalInput<Context, Assertions, Flags>): AdapterEvalDefinition<\"score\", Context, Assertions, Flags>;\n}\n/** Existential runtime view used by Experiment without erasing a concrete context to `any`. */\nexport interface AdapterRuntimeDefinition {\n readonly parseFlags?: Exclude<AdapterFlagsParser, undefined>;\n readonly kind: \"custom\";\n readonly name: string;\n readonly contract: string;\n readonly behaviorRevision: string | null;\n readonly cleanupTimeoutMs: number;\n readonly [ADAPTER_CONTRACT_TOKEN]: object;\n readonly defineEval: (...args: never[]) => unknown;\n readonly defineScoreEval: (...args: never[]) => unknown;\n create(context: AdapterCreateContext<unknown>): object | Promise<object>;\n}\nexport interface AdapterImplementation<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined> extends AdapterDefinition<Context, Assertions, Flags> {\n readonly kind: \"custom\";\n readonly contract: string;\n readonly behaviorRevision: string | null;\n readonly cleanupTimeoutMs: number;\n readonly [ADAPTER_CONTRACT_TOKEN]: AdapterContractToken<Context, Assertions, Flags>;\n create(context: AdapterCreateContext<AdapterFlagsOutput<Flags>>): Context | Promise<Context>;\n}\nexport type AdapterImplementationInput<Context extends object, ImplementationContext extends Context = Context, Flags extends AdapterFlagsParser = undefined> = {\n readonly name: string;\n readonly behaviorRevision?: string;\n /** Adapter 总清理预算,默认 30000 ms;允许整数 1–300000。 */\n readonly cleanupTimeoutMs?: number;\n readonly create: AdapterFactory<ImplementationContext, Flags>;\n} & AdapterContextValidation<NoInfer<ImplementationContext>>;\nexport interface AdapterContract<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined> extends AdapterDefinition<Context, Assertions, Flags> {\n readonly name: string;\n implement<ImplementationContext extends Context>(input: AdapterImplementationInput<Context, ImplementationContext, Flags>): AdapterImplementation<Context, Assertions, Flags>;\n /**\n * Returns a contract whose Eval factories and implementations share one flags parser.\n */\n withParseFlags<NextFlags extends Exclude<AdapterFlagsParser, undefined>>(parseFlags: NextFlags, ...validation: AdapterFlagsParserValidationArgs<NoInfer<NextFlags>>): AdapterContract<Context, Assertions, NextFlags>;\n /** Returns a contract whose implementations share this exact Assertion factory. */\n withAssertions<NextAssertions extends object>(factory: AdapterAssertionsFactory<Context, NextAssertions>, ...validation: AdapterAssertionsValidationArgs<Context, NoInfer<NextAssertions>>): AdapterContract<Context, NextAssertions, Flags>;\n}\nexport type Adapter = import(\"./agents/types.ts\").Agent | AdapterRuntimeDefinition;\nfunction assertNonEmptyString(value: unknown, field: string, factory: string): asserts value is string {\n if (typeof value !== \"string\" || value.trim() === \"\") {\n throw new TypeError(`${factory} requires a non-empty ${field}.`);\n }\n}\nfunction contractToken<Context extends object, Assertions extends object | undefined, Flags extends AdapterFlagsParser>(name: string, assertions: AdapterAssertionsFactory<Context> | undefined, parseFlags: Flags): AdapterContractToken<Context, Assertions, Flags> {\n return Object.freeze({\n name,\n assertions,\n parseFlags,\n assertionTypes: (value: Assertions) => value,\n context: (value: Context) => value,\n });\n}\nfunction assertAdapterEvalInput(value: {\n readonly sandbox?: unknown;\n readonly diff?: unknown;\n}, factory: \"defineEval\" | \"defineScoreEval\"): void {\n if (Object.hasOwn(value, \"sandbox\")) {\n throw new TypeError(`${factory} for an Adapter does not support sandbox.`);\n }\n if (Object.hasOwn(value, \"diff\")) {\n throw new TypeError(`${factory} for an Adapter does not support Agent workspace diff configuration.`);\n }\n}\nfunction boundEvalFactories<Context extends object, Assertions extends object | undefined, Flags extends AdapterFlagsParser>(token: AdapterContractToken<Context, Assertions, Flags>): Pick<AdapterDefinition<Context, Assertions, Flags>, \"defineEval\" | \"defineScoreEval\"> {\n return {\n defineEval(input) {\n assertAdapterEvalInput(input, \"defineEval\");\n return defineEvalForContext(\"pass\", input, {\n [EVAL_ADAPTER_CONTRACT_TOKEN]: token,\n }) as AdapterEvalDefinition<\"pass\", Context, Assertions, Flags>;\n },\n defineScoreEval(input) {\n assertAdapterEvalInput(input, \"defineScoreEval\");\n return defineEvalForContext(\"score\", input, {\n [EVAL_ADAPTER_CONTRACT_TOKEN]: token,\n }) as AdapterEvalDefinition<\"score\", Context, Assertions, Flags>;\n },\n };\n}\nfunction implementAdapter<Context extends object, Assertions extends object | undefined, Flags extends AdapterFlagsParser>(token: AdapterContractToken<Context, Assertions, Flags>, input: {\n readonly name: string;\n readonly behaviorRevision?: string;\n /** Adapter 总清理预算,默认 30000 ms;允许整数 1–300000。 */\n readonly cleanupTimeoutMs?: number;\n readonly create: AdapterFactory<Context, Flags>;\n}, factory: \"defineAdapter\" | \"AdapterContract.implement\"): AdapterImplementation<Context, Assertions, Flags> {\n assertNonEmptyString(input.name, \"name\", factory);\n if (input.behaviorRevision !== undefined) {\n assertNonEmptyString(input.behaviorRevision, \"behaviorRevision\", factory);\n }\n if (typeof input.create !== \"function\") {\n throw new TypeError(`${factory} requires create(context).`);\n }\n const cleanupTimeoutMs = resolveAdapterCleanupTimeoutMs(input.cleanupTimeoutMs);\n const authorCreate = input.create;\n const create = (context: AdapterCreateContext<AdapterFlagsOutput<Flags>>): Context | Promise<Context> => {\n const created = authorCreate(context);\n if (created instanceof Promise) {\n return created.then((value) => {\n assertPlainAdapterContext(value);\n return value;\n });\n }\n // Validate before a caller can pass a synchronous thenable to Promise adaptation.\n assertPlainAdapterContext(created);\n return created;\n };\n return Object.freeze({\n kind: \"custom\" as const,\n parseFlags: token.parseFlags,\n name: input.name,\n contract: token.name,\n behaviorRevision: input.behaviorRevision ?? null,\n cleanupTimeoutMs,\n create,\n [ADAPTER_CONTRACT_TOKEN]: token,\n ...boundEvalFactories(token),\n }) as AdapterImplementation<Context, Assertions, Flags>;\n}\n/** Defines one Adapter implementation with an automatically private contract. */\nexport function defineAdapter<Context extends object, Flags extends AdapterFlagsParser = undefined>(input: {\n readonly name: string;\n readonly behaviorRevision?: string;\n /** Adapter 总清理预算,默认 30000 ms;允许整数 1–300000。 */\n readonly cleanupTimeoutMs?: number;\n readonly create: AdapterFactory<Context, Flags>;\n readonly parseFlags?: Flags;\n readonly assertions?: undefined;\n} & AdapterContextValidation<NoInfer<Context>> & AdapterFlagsParserValidation<NoInfer<Flags>>): AdapterImplementation<Context, undefined, Flags>;\nexport function defineAdapter<Context extends object, Assertions extends object, Flags extends AdapterFlagsParser = undefined>(input: {\n readonly name: string;\n readonly behaviorRevision?: string;\n /** Adapter 总清理预算,默认 30000 ms;允许整数 1–300000。 */\n readonly cleanupTimeoutMs?: number;\n readonly create: AdapterFactory<Context, Flags>;\n readonly parseFlags?: Flags;\n /** Attempt-local Assertion sugar, assembled once after create() succeeds. */\n readonly assertions: AdapterAssertionsFactory<Context, Assertions>;\n} & AdapterContextValidation<NoInfer<Context>> & AdapterFlagsParserValidation<NoInfer<Flags>> & AdapterAssertionsValidation<Context, NoInfer<Assertions>>): AdapterImplementation<Context, Assertions, Flags>;\n// @concord-code ne-adapter-define-adapter\n// @concord-implements docs/feature/adapters/README.md\n// @concord-implements docs/feature/adapters/library/writing-an-adapter.md\nexport function defineAdapter(input: {\n readonly name: string;\n readonly behaviorRevision?: string;\n /** Adapter 总清理预算,默认 30000 ms;允许整数 1–300000。 */\n readonly cleanupTimeoutMs?: number;\n readonly create: AdapterFactory<object, AdapterFlagsParser>;\n readonly parseFlags?: Exclude<AdapterFlagsParser, undefined>;\n readonly assertions?: AdapterAssertionsFactory<object>;\n}): AdapterRuntimeDefinition {\n if (input.parseFlags !== undefined)\n assertAdapterFlagsParser(input.parseFlags);\n const assertions = input.assertions;\n if (assertions !== undefined && typeof assertions !== \"function\") {\n throw new TypeError(\"defineAdapter assertions must be a function.\");\n }\n return implementAdapter(contractToken<object, object | undefined, AdapterFlagsParser>(input.name, assertions, input.parseFlags), input, \"defineAdapter\");\n}\n/** Defines a reusable contract whose implementations and Evals share one runtime-only token. */\n// @concord-code ne-adapter-define-contract\n// @concord-implements docs/feature/adapters/README.md\n// @concord-implements docs/feature/adapters/architecture/agent-contract.md\nexport function defineAdapterContract<Context extends object>(input: {\n readonly name: string;\n} & AdapterContextValidation<NoInfer<Context>>): AdapterContract<Context> {\n assertNonEmptyString(input.name, \"name\", \"defineAdapterContract\");\n return makeAdapterContract(contractToken<Context, undefined, undefined>(input.name, undefined, undefined));\n}\nfunction makeAdapterContract<Context extends object, Assertions extends object | undefined, Flags extends AdapterFlagsParser>(token: AdapterContractToken<Context, Assertions, Flags>): AdapterContract<Context, Assertions, Flags> {\n const factories = boundEvalFactories(token);\n return Object.freeze({\n name: token.name,\n parseFlags: token.parseFlags,\n ...factories,\n implement<ImplementationContext extends Context>(implementation: AdapterImplementationInput<Context, ImplementationContext, Flags>) {\n return implementAdapter(token, implementation, \"AdapterContract.implement\");\n },\n withParseFlags<NextFlags extends Exclude<AdapterFlagsParser, undefined>>(parseFlags: NextFlags, ..._validation: AdapterFlagsParserValidationArgs<NoInfer<NextFlags>>) {\n assertAdapterFlagsParser(parseFlags);\n return makeAdapterContract(contractToken<Context, Assertions, NextFlags>(token.name, token.assertions, parseFlags));\n },\n withAssertions<NextAssertions extends object>(factory: AdapterAssertionsFactory<Context, NextAssertions>, ..._validation: AdapterAssertionsValidationArgs<Context, NoInfer<NextAssertions>>) {\n if (typeof factory !== \"function\") {\n throw new TypeError(\"AdapterContract.withAssertions requires a function.\");\n }\n return makeAdapterContract(contractToken<Context, NextAssertions, Flags>(token.name, factory, token.parseFlags));\n },\n });\n}\n/** The single credential-free persistence projection for an Adapter. */\nexport function adapterIdentity(adapter: Adapter): AdapterIdentity {\n return adapter.kind === \"custom\"\n ? Object.freeze({\n name: adapter.name,\n contract: adapter.contract,\n behaviorRevision: adapter.behaviorRevision,\n cleanupTimeoutMs: adapter.cleanupTimeoutMs,\n })\n : Object.freeze({\n name: adapter.name,\n contract: \"niceeval.agent/v1\",\n behaviorRevision: null,\n });\n}\n/** @internal Runtime contract pairing; the token itself never enters persistence. */\nexport function adapterAcceptsEval(adapter: Adapter, definition: object): boolean {\n const required = (definition as {\n readonly [EVAL_ADAPTER_CONTRACT_TOKEN]?: unknown;\n })[EVAL_ADAPTER_CONTRACT_TOKEN];\n if (adapter.kind === \"custom\") {\n const provided = adapter[ADAPTER_CONTRACT_TOKEN];\n return required !== undefined && provided !== undefined && required === provided;\n }\n return required === undefined;\n}\n/** @internal Returns the readable contract name without revealing the pairing token. */\nexport function adapterContractRequiredByEval(definition: object): string | undefined {\n return (definition as {\n readonly [EVAL_ADAPTER_CONTRACT_TOKEN]?: {\n readonly name: string;\n };\n })[EVAL_ADAPTER_CONTRACT_TOKEN]?.name;\n}\nconst RESERVED_ADAPTER_CONTEXT_KEY_SET: ReadonlySet<string> = new Set(RESERVED_ADAPTER_CONTEXT_KEYS);\nfunction assertPlainAdapterContext(value: unknown): asserts value is object {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n throw new TypeError(\"Adapter create(context) must return a plain object.\");\n }\n const prototype = Object.getPrototypeOf(value);\n if (prototype !== Object.prototype && prototype !== null) {\n throw new TypeError(\"Adapter create(context) must return an explicit plain object.\");\n }\n for (const key of Reflect.ownKeys(value)) {\n if (typeof key === \"string\" && RESERVED_ADAPTER_CONTEXT_KEY_SET.has(key)) {\n throw new TypeError(`Adapter context key ${JSON.stringify(key)} is reserved.`);\n }\n }\n}\nfunction forwardProperties(target: object, source: object, guardAccess: boolean, assertAuthorOpen: () => void): void {\n for (const key of Reflect.ownKeys(source)) {\n const descriptor = Object.getOwnPropertyDescriptor(source, key);\n if (descriptor === undefined)\n continue;\n if (\"value\" in descriptor && typeof descriptor.value === \"function\") {\n const method = guardAccess\n ? function (this: unknown, ...args: readonly unknown[]) {\n assertAuthorOpen();\n return Reflect.apply(descriptor.value, source, args);\n }\n : descriptor.value.bind(source);\n Object.defineProperty(target, key, {\n enumerable: true,\n configurable: false,\n writable: false,\n value: method,\n });\n }\n else {\n Object.defineProperty(target, key, {\n enumerable: true,\n configurable: false,\n get: () => {\n if (guardAccess)\n assertAuthorOpen();\n const value = Reflect.get(source, key, source);\n if (typeof value !== \"function\")\n return value;\n return guardAccess\n ? (...args: readonly unknown[]) => {\n assertAuthorOpen();\n return Reflect.apply(value, source, args);\n }\n : value.bind(source);\n },\n });\n }\n }\n}\n/** Observes only branded native Promises without reading an arbitrary `.then` property. */\nfunction observeNativePromiseRejection(value: unknown): boolean {\n if ((typeof value !== \"object\" && typeof value !== \"function\") || value === null)\n return false;\n try {\n void Reflect.apply(Promise.prototype.then, value, [\n undefined,\n () => undefined,\n ]);\n return true;\n }\n catch {\n return false;\n }\n}\nfunction assertPlainAdapterAssertions(value: unknown, context: object): asserts value is object {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n throw new TypeError(\"Adapter assertions factory must return a plain object of methods.\");\n }\n const prototype = Object.getPrototypeOf(value);\n if (prototype !== Object.prototype && prototype !== null) {\n observeNativePromiseRejection(value);\n throw new TypeError(\"Adapter assertions factory must return an explicit plain object.\");\n }\n const contextKeys = new Set(Reflect.ownKeys(context));\n for (const key of Reflect.ownKeys(value)) {\n if (typeof key !== \"string\") {\n throw new TypeError(\"Adapter assertion method names must be strings.\");\n }\n if (RESERVED_ADAPTER_CONTEXT_KEY_SET.has(key)) {\n throw new TypeError(`Adapter assertion method name ${JSON.stringify(key)} is reserved.`);\n }\n if (contextKeys.has(key)) {\n throw new TypeError(`Adapter assertion method name ${JSON.stringify(key)} conflicts with an app member.`);\n }\n const descriptor = Object.getOwnPropertyDescriptor(value, key);\n if (descriptor === undefined || !(\"value\" in descriptor) || typeof descriptor.value !== \"function\") {\n throw new TypeError(`Adapter assertion ${JSON.stringify(key)} must be an own data method.`);\n }\n }\n}\nfunction bindAdapterAppContext<Context>(context: Context, assertAppOpen: () => void): Readonly<Context> {\n const target = Object.create(null) as object;\n forwardProperties(target, context as object, true, assertAppOpen);\n return Object.freeze(target) as Readonly<Context>;\n}\nfunction bindAdapterAssertions<Kind extends EvaluationKind, Context extends object>(core: EvalContext<Kind>, context: Context, factory: AdapterAssertionsFactory<Context>, assertAuthorOpen: () => void): {\n readonly app: Readonly<Context>;\n readonly assertions: object;\n} {\n let assembled = false;\n const assertAppOpen = (): void => {\n assertAuthorOpen();\n if (!assembled) {\n throw new TypeError(\"Adapter assertions factory may only assemble methods; app access starts afterward.\");\n }\n };\n const app = bindAdapterAppContext(context, assertAppOpen);\n const handleFrames: Array<WeakSet<object>> = [];\n const check = (...args: readonly unknown[]): unknown => {\n assertAuthorOpen();\n const frame = handleFrames.at(-1);\n if (frame === undefined) {\n throw new TypeError(\"Adapter assertions factory may call check only from an assertion method.\");\n }\n const handle = Reflect.apply(core.check, undefined, args);\n if ((typeof handle !== \"object\" && typeof handle !== \"function\") || handle === null) {\n throw new TypeError(\"Adapter assertion check did not return an AssertionHandle.\");\n }\n frame.add(handle);\n return handle;\n };\n const authored = factory({ app: app as MatchContext<Context>, check: check as AssertionCheck<\"polymorphic\", Context> });\n assertPlainAdapterAssertions(authored, context);\n Object.freeze(authored);\n assembled = true;\n const assertions = Object.create(null) as object;\n for (const key of Reflect.ownKeys(authored)) {\n const descriptor = Object.getOwnPropertyDescriptor(authored, key)!;\n const method = descriptor.value as (...args: readonly unknown[]) => unknown;\n Object.defineProperty(assertions, key, {\n enumerable: true,\n configurable: false,\n writable: false,\n value: (...args: readonly unknown[]) => {\n assertAuthorOpen();\n const frame = new WeakSet<object>();\n handleFrames.push(frame);\n try {\n const handle = Reflect.apply(method, authored, args);\n if ((typeof handle !== \"object\" && typeof handle !== \"function\") || handle === null || !frame.has(handle)) {\n observeNativePromiseRejection(handle);\n throw new TypeError(`Adapter assertion ${JSON.stringify(key)} must synchronously return its own check() handle.`);\n }\n return handle;\n }\n finally {\n handleFrames.pop();\n }\n },\n });\n }\n return Object.freeze({ app, assertions: Object.freeze(assertions) });\n}\n/** @internal Builds the frozen single-t facade after create settles. */\n// @concord-code ne-adapter-bind-eval-context\n// @concord-implements docs/feature/adapters/architecture/agent-contract.md\nexport function bindAdapterEvalContext<Kind extends EvaluationKind, Context>(core: EvalContext<Kind>, context: Context, adapter: AdapterRuntimeDefinition, assertAuthorOpen: () => void): EvalContext<Kind> & Readonly<Context> {\n assertPlainAdapterContext(context);\n const token = adapter[ADAPTER_CONTRACT_TOKEN] as AdapterContractToken<Context & object, object | undefined>;\n let app: Readonly<Context>;\n let assertions: object | undefined;\n if (token.assertions === undefined) {\n app = bindAdapterAppContext(context, assertAuthorOpen);\n }\n else {\n const bound = bindAdapterAssertions(core, context, token.assertions, assertAuthorOpen);\n app = bound.app;\n assertions = bound.assertions;\n }\n bindAssertionContext(core.check, () => app);\n const target = Object.create(null) as object;\n forwardProperties(target, core, false, assertAuthorOpen);\n forwardProperties(target, app, false, assertAuthorOpen);\n if (assertions !== undefined)\n forwardProperties(target, assertions, false, assertAuthorOpen);\n return Object.freeze(target) as EvalContext<Kind> & Readonly<Context>;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"adapter.js","sourceRoot":"","sources":["adapter.ts"],"names":[],"mappings":";;AAkXA,sCAiBC;AAKD,sDAKC;AAuBD,0CAaC;AAED,gDASC;AAED,sEAMC;AAmKD,wDAoBC;AA3nBD,qDAAuI;AACvI,oEAA6E;AAG7E,wDAA+D;AAI/D,yDAA2L;AAG3L,2CAAmD;AAOnD,MAAM,sBAAsB,GAAkB,MAAM,CAAC,+BAA+B,CAAC,CAAC;AACtF,MAAM,2BAA2B,GAAkB,MAAM,CAAC,mCAAmC,CAAC,CAAC;AAsB/F,gFAAgF;AAChF,MAAM,6BAA6B,GAAG;IAClC,gBAAgB;IAChB,OAAO;IACP,OAAO;IACP,YAAY;IACZ,cAAc;IACd,sBAAsB;IACtB,oBAAoB;IACpB,SAAS;IACT,OAAO;IACP,WAAW;IACX,WAAW;IACX,SAAS;IACT,OAAO;IACP,OAAO;IACP,MAAM;IACN,QAAQ;IACR,OAAO;IACP,iBAAiB;IACjB,OAAO;IACP,UAAU;IACV,YAAY;IACZ,KAAK;IACL,MAAM;IACN,QAAQ;IACR,aAAa;IACb,kBAAkB;IAClB,kBAAkB;IAClB,gBAAgB;IAChB,kBAAkB;IAClB,kBAAkB;IAClB,eAAe;IACf,sBAAsB;IACtB,UAAU;IACV,SAAS;IACT,WAAW;IACX,gBAAgB;CAC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} from \"./model-slots.ts\";\nimport { resolveAdapterCleanupTimeoutMs } from \"./shared/adapter-cleanup.ts\";\nimport type { AttemptSignal } from \"./shared/attempt-lifecycle.ts\";\nexport type { AttemptCancellation, AttemptSignal } from \"./shared/attempt-lifecycle.ts\";\nimport { bindAssertionContext } from \"./assertions/runtime.ts\";\nimport type { MatchContext } from \"./assertions/context-match.ts\";\nimport type { EvalUsage } from \"./o11y/eval-usage.ts\";\nimport type { ExperimentFlags } from \"./shared/types.ts\";\nimport { assertAdapterFlagsParser, type AdapterFlagsParser, type AdapterFlagsOutput, type AdapterFlagsParserValidation, type AdapterFlagsParserValidationArgs, } from \"./adapter-flags.ts\";\nimport type { AssertionCheck, AssertionSubject, AssertionsRuntime, BooleanAssertionHandle, MeasurementAssertionHandle, PolymorphicBooleanAssertionHandle, PolymorphicMeasurementAssertionHandle, } from \"./assertions/api.ts\";\nimport type { ScoreMatch } from \"./assertions/match.ts\";\nimport { defineEvalForContext } from \"./define.ts\";\nimport type { EvalDefinition, EvalInput, ScoreEvalInput } from \"./runner/types.ts\";\nimport type { EvaluationKind } from \"./shared/evaluation.ts\";\nimport type { JudgePresetMethods } from \"./context/assert-first.ts\";\nimport type { DiagnosticInput, ProgressUpdate } from \"./shared/types.ts\";\nimport type { AdapterIdentity } from \"./record/model/run-context.ts\";\nexport type { AdapterIdentity } from \"./record/model/run-context.ts\";\nconst ADAPTER_CONTRACT_TOKEN: unique symbol = Symbol(\"niceeval.adapterContractToken\");\nconst EVAL_ADAPTER_CONTRACT_TOKEN: unique symbol = Symbol(\"niceeval.evalAdapterContractToken\");\n/**\n * Synchronously assembles Attempt-local Assertion methods from the guarded app\n * facade and the shared check registrar. The returned object must contain only\n * ordinary, synchronously returning methods. Generic and overloaded Assertion\n * sugar is intentionally not callable after binding; use ordinary named\n * parameters so argument and native handle types remain exact.\n */\nexport type AdapterAssertionsFactory<Context extends object, Assertions extends object = object> = (context: AdapterAssertionsFactoryContext<Context>) => Assertions;\n/**\n * Definition inputs for Adapter Assertion sugar. `app` becomes callable after\n * assembly, and `check` may only be called by a returned Assertion method.\n */\nexport interface AdapterAssertionsFactoryContext<Context extends object> {\n readonly app: MatchContext<Context>;\n readonly check: AssertionCheck<\"polymorphic\", Context>;\n}\ntype BoundAdapterAssertionResult<Kind extends EvaluationKind, Result> = Result extends PolymorphicBooleanAssertionHandle<infer Refined, infer HasGate> ? BooleanAssertionHandle<Kind, Refined, HasGate> : Result extends PolymorphicMeasurementAssertionHandle<infer HasCondition> ? MeasurementAssertionHandle<Kind, HasCondition> : never;\ntype BoundAdapterAssertionMethod<Kind extends EvaluationKind, Method> = Method extends (...args: infer Args) => infer Result ? ((...args: Args) => Result) extends Method ? (...args: Args) => BoundAdapterAssertionResult<Kind, Result> : never : never;\ntype AdapterAssertionsFor<Assertions extends object | undefined, Kind extends EvaluationKind> = Assertions extends object ? {\n readonly [Key in keyof Assertions]: BoundAdapterAssertionMethod<Kind, Assertions[Key]>;\n} : {};\n/** Keys owned by the neutral Eval runtime or unsafe on a merged object root. */\nconst RESERVED_ADAPTER_CONTEXT_KEYS = [\n \"evaluationKind\",\n \"check\",\n \"judge\",\n \"factuality\",\n \"faithfulness\",\n \"instructionFollowing\",\n \"pairwisePreference\",\n \"closeQA\",\n \"usage\",\n \"elapsedMs\",\n \"maxTokens\",\n \"maxCost\",\n \"score\",\n \"group\",\n \"skip\",\n \"signal\",\n \"model\",\n \"reasoningEffort\",\n \"flags\",\n \"progress\",\n \"diagnostic\",\n \"log\",\n \"then\",\n \"Object\",\n \"constructor\",\n \"__defineGetter__\",\n \"__defineSetter__\",\n \"hasOwnProperty\",\n \"__lookupGetter__\",\n \"__lookupSetter__\",\n \"isPrototypeOf\",\n \"propertyIsEnumerable\",\n \"toString\",\n \"valueOf\",\n \"__proto__\",\n \"toLocaleString\",\n] as const;\nexport type ReservedAdapterContextKey = typeof RESERVED_ADAPTER_CONTEXT_KEYS[number];\ntype InvalidContextBranch<Context> = Context extends unknown ? Context extends object ? Context extends readonly unknown[] ? Context : Context extends (...args: readonly never[]) => unknown ? Context : string extends keyof Context ? Context : Extract<keyof Context, ReservedAdapterContextKey> extends never ? never : Context : Context : never;\ntype AdapterContextValidation<Context> = unknown extends Context ? unknown : [\n InvalidContextBranch<Context>\n] extends [\n never\n] ? unknown : {\n readonly invalidAdapterContext: InvalidContextBranch<Context>;\n};\ntype InvalidAssertionMethodKey<Context extends object, Assertions> = Assertions extends object ? {\n [Key in keyof Assertions]: Key extends string ? Key extends ReservedAdapterContextKey | keyof Context ? Key : Assertions[Key] extends (...args: readonly never[]) => infer Result ? Result extends PolymorphicBooleanAssertionHandle<unknown, boolean> | PolymorphicMeasurementAssertionHandle<boolean> ? never : Key : Key : Key;\n}[keyof Assertions] : \"assertions\";\ntype InvalidAdapterAssertions<Context extends object, Assertions extends object> = InvalidAssertionMethodKey<Context, Assertions>;\ntype AdapterAssertionsValidation<Context extends object, Assertions extends object> = [\n InvalidAdapterAssertions<Context, Assertions>\n] extends [\n never\n] ? unknown : {\n readonly invalidAdapterAssertions: InvalidAdapterAssertions<Context, Assertions>;\n};\ntype AdapterAssertionsValidationArgs<Context extends object, Assertions extends object> = [\n InvalidAdapterAssertions<Context, Assertions>\n] extends [\n never\n] ? [\n] : [\n error: {\n readonly invalidAdapterAssertions: InvalidAdapterAssertions<Context, Assertions>;\n }\n];\ntype AdapterFactory<Context extends object, Flags extends AdapterFlagsParser = undefined> = (context: AdapterCreateContext<AdapterFlagsOutput<Flags>>) => (Context & ThisType<Context>) | Promise<Context & ThisType<Context>>;\nexport interface AdapterCleanupContext {\n /** 整个清理窗口的固定毫秒预算,不为每个回调续期。 */\n readonly timeoutMs: number;\n /** 清理窗口实际开始时确定的 Unix 毫秒截止时间。 */\n readonly deadlineAt: number;\n /** 独立于执行信号;整个 Adapter 清理窗口截止时中止。 */\n readonly signal: AbortSignal;\n}\nexport interface AdapterCreateContext<Flags = ExperimentFlags, Slots extends string = string> {\n /** Frozen application model selections for this Attempt. */\n readonly models: Readonly<Record<Slots, ResolvedModelSlot>>;\n recordUsage(input: Omit<import(\"./adapter-usage.ts\").AdapterUsageInput, \"modelSlot\"> & {\n readonly modelSlot?: Slots | null;\n }): void;\n /** Close application usage admission and declare whether the recorded collection is complete. */\n sealUsage(input: import(\"./adapter-usage.ts\").AdapterUsageSeal): void;\n attach(input: import(\"./adapter-attachments.ts\").AdapterAttachmentInput): Promise<import(\"./adapter-attachments.ts\").AdapterAttachmentReceipt>;\n recordTrace<Event extends import(\"./adapter-execution-trace.ts\").ExecutionTraceEvent>(input: import(\"./adapter-execution-trace.ts\").ExecutionTraceInput<Event>): Promise<import(\"./adapter-execution-trace.ts\").ExecutionTraceReceipt>;\n /** 当前 Eval 的公开 ID。 */\n readonly evalId: string;\n /** 当前 Experiment 的公开 ID。 */\n readonly experimentId: string;\n /** 当前 Attempt 的零起始序号。 */\n readonly attempt: number;\n /** Attempt 执行信号;reason 区分 timeout 与 cancelled,不用于 cleanup 窗口。 */\n readonly signal: AttemptSignal;\n /** Experiment 选择的模型。 */\n readonly model?: string;\n /** Experiment 选择的推理强度。 */\n readonly reasoningEffort?: string;\n /** Experiment 传给 Adapter 的只读 flags。 */\n readonly flags: Flags;\n /** 更新当前 Attempt 的人读进度。 */\n progress(update: ProgressUpdate): void;\n /** 为当前 Attempt 追加结构化诊断。 */\n diagnostic(input: DiagnosticInput): void;\n /** 为当前 Attempt 追加日志。 */\n log(message: string): void;\n /**\n * 登记 Attempt-local 资源释放。回调按全局 LIFO 执行;一项失败不会跳过其余项。\n * 零参数回调仍可直接传入。传入的 context 已冻结,同一 cleanup 窗口的回调共享一个 signal。\n */\n onCleanup(cleanup: (context: AdapterCleanupContext) => void | Promise<void>): void;\n}\ntype EvalContextBase<Kind extends EvaluationKind, Flags, Context> = JudgePresetMethods<Kind, Context> & {\n readonly usage: EvalUsage;\n readonly elapsedMs: import(\"./assertions/match.ts\").NumericMaterial;\n maxTokens(max: number): BooleanAssertionHandle<Kind, number>;\n maxCost(usd: number | string): BooleanAssertionHandle<Kind, string>;\n readonly evaluationKind: Kind;\n readonly signal: AbortSignal;\n readonly model?: string;\n readonly reasoningEffort?: string;\n readonly flags: Flags;\n progress(update: ProgressUpdate): void;\n diagnostic(input: DiagnosticInput): void;\n log(message: string): void;\n skip(reason: string): never;\n group<Value>(title: string, body: () => Value | PromiseLike<Value>): Promise<Awaited<Value>>;\n readonly check: AssertionCheck<Kind, Context>;\n readonly judge: <Value>(value: AssertionSubject<Value>, definition: ScoreMatch<NoInfer<Value>>) => MeasurementAssertionHandle<Kind>;\n};\n/** Agent-neutral author context shared by every Adapter Eval. */\nexport type EvalContext<Kind extends EvaluationKind = \"pass\", Flags = ExperimentFlags, Context = unknown> = EvalContextBase<Kind, Flags, Context> & (Kind extends \"score\" ? {\n readonly score: AssertionsRuntime<\"score\">[\"t\"][\"score\"];\n} : {});\ntype AdapterEvalFields = Omit<EvalInput<undefined>, \"test\" | \"sandbox\" | \"diff\"> & {\n readonly sandbox?: never;\n readonly diff?: never;\n};\ntype AdapterScoreEvalFields = Omit<ScoreEvalInput<undefined>, \"test\" | \"sandbox\" | \"diff\"> & {\n readonly sandbox?: never;\n readonly diff?: never;\n};\nexport type AdapterEvalInput<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined, Slots extends string = string> = AdapterEvalFields & {\n readonly requires?: ModelRequirements<Slots>;\n test(t: Omit<EvalContext<\"pass\", AdapterFlagsOutput<Flags>, Context>, \"usage\"> & {\n readonly usage: EvalUsage<NoInfer<Slots>>;\n } & Readonly<Context> & AdapterAssertionsFor<Assertions, \"pass\">): void | Promise<void>;\n};\nexport type AdapterScoreEvalInput<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined, Slots extends string = string> = AdapterScoreEvalFields & {\n readonly requires?: ModelRequirements<Slots>;\n test(t: Omit<EvalContext<\"score\", AdapterFlagsOutput<Flags>, Context>, \"usage\"> & {\n readonly usage: EvalUsage<NoInfer<Slots>>;\n } & Readonly<Context> & AdapterAssertionsFor<Assertions, \"score\">): void | Promise<void>;\n};\ninterface AdapterContractToken<Context extends object, Assertions extends object | undefined, Flags extends AdapterFlagsParser = undefined> {\n readonly name: string;\n readonly assertions: AdapterAssertionsFactory<Context> | undefined;\n readonly parseFlags: Flags;\n /** Keeps the Assertion method shape invariant without exposing a constructible brand. */\n readonly assertionTypes: (value: Assertions) => Assertions;\n /** Keeps the context parameter invariant without exposing a constructible brand. */\n readonly context: (value: Context) => Context;\n}\nexport interface AdapterEvalDefinition<Kind extends EvaluationKind, Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined> extends EvalDefinition<Kind, EvalContext<Kind, AdapterFlagsOutput<Flags>, Context> & Readonly<Context> & AdapterAssertionsFor<Assertions, Kind>, undefined> {\n readonly [EVAL_ADAPTER_CONTRACT_TOKEN]: AdapterContractToken<Context, Assertions, Flags>;\n}\n/** @internal Existential discovery view; concrete bound factories retain their exact Context. */\nexport interface AdapterRuntimeEvalDefinition<Kind extends EvaluationKind> extends EvalDefinition<Kind, never, undefined> {\n readonly [EVAL_ADAPTER_CONTRACT_TOKEN]: object;\n}\n/** Common public surface for an Adapter definition with bound Eval factories. */\nexport interface AdapterDefinition<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined> {\n readonly name: string;\n readonly parseFlags: Flags;\n defineEval<const Slots extends string = string>(input: AdapterEvalInput<Context, Assertions, Flags, Slots>): AdapterEvalDefinition<\"pass\", Context, Assertions, Flags>;\n defineScoreEval<const Slots extends string = string>(input: AdapterScoreEvalInput<Context, Assertions, Flags, Slots>): AdapterEvalDefinition<\"score\", Context, Assertions, Flags>;\n}\n/** Existential runtime view used by Experiment without erasing a concrete context to `any`. */\nexport interface AdapterRuntimeDefinition {\n readonly parseFlags?: Exclude<AdapterFlagsParser, undefined>;\n readonly kind: \"custom\";\n readonly requiredModelSlots?: readonly string[];\n readonly name: string;\n readonly contract: string;\n readonly behaviorRevision: string | null;\n readonly cleanupTimeoutMs: number;\n readonly [ADAPTER_CONTRACT_TOKEN]: object;\n readonly defineEval: (...args: never[]) => unknown;\n readonly defineScoreEval: (...args: never[]) => unknown;\n create(context: AdapterCreateContext<unknown>): object | Promise<object>;\n}\nexport interface AdapterImplementation<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined> extends AdapterDefinition<Context, Assertions, Flags> {\n readonly kind: \"custom\";\n readonly contract: string;\n readonly behaviorRevision: string | null;\n readonly cleanupTimeoutMs: number;\n readonly [ADAPTER_CONTRACT_TOKEN]: AdapterContractToken<Context, Assertions, Flags>;\n create(context: AdapterCreateContext<AdapterFlagsOutput<Flags>>): Context | Promise<Context>;\n}\nexport type AdapterImplementationInput<Context extends object, ImplementationContext extends Context = Context, Flags extends AdapterFlagsParser = undefined> = {\n readonly name: string;\n readonly behaviorRevision?: string;\n /** Adapter 总清理预算,默认 30000 ms;允许整数 1–300000。 */\n readonly cleanupTimeoutMs?: number;\n readonly create: AdapterFactory<ImplementationContext, Flags>;\n} & AdapterContextValidation<NoInfer<ImplementationContext>>;\nexport interface AdapterContract<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined> extends AdapterDefinition<Context, Assertions, Flags> {\n readonly name: string;\n implement<ImplementationContext extends Context>(input: AdapterImplementationInput<Context, ImplementationContext, Flags>): AdapterImplementation<Context, Assertions, Flags>;\n /**\n * Returns a contract whose Eval factories and implementations share one flags parser.\n */\n withParseFlags<NextFlags extends Exclude<AdapterFlagsParser, undefined>>(parseFlags: NextFlags, ...validation: AdapterFlagsParserValidationArgs<NoInfer<NextFlags>>): AdapterContract<Context, Assertions, NextFlags>;\n /** Returns a contract whose implementations share this exact Assertion factory. */\n withAssertions<NextAssertions extends object>(factory: AdapterAssertionsFactory<Context, NextAssertions>, ...validation: AdapterAssertionsValidationArgs<Context, NoInfer<NextAssertions>>): AdapterContract<Context, NextAssertions, Flags>;\n}\nexport type Adapter = import(\"./agents/types.ts\").Agent | AdapterRuntimeDefinition;\nfunction assertNonEmptyString(value: unknown, field: string, factory: string): asserts value is string {\n if (typeof value !== \"string\" || value.trim() === \"\") {\n throw new TypeError(`${factory} requires a non-empty ${field}.`);\n }\n}\nfunction contractToken<Context extends object, Assertions extends object | undefined, Flags extends AdapterFlagsParser>(name: string, assertions: AdapterAssertionsFactory<Context> | undefined, parseFlags: Flags): AdapterContractToken<Context, Assertions, Flags> {\n return Object.freeze({\n name,\n assertions,\n parseFlags,\n assertionTypes: (value: Assertions) => value,\n context: (value: Context) => value,\n });\n}\nfunction assertAdapterEvalInput(value: {\n readonly sandbox?: unknown;\n readonly diff?: unknown;\n}, factory: \"defineEval\" | \"defineScoreEval\"): void {\n if (Object.hasOwn(value, \"sandbox\")) {\n throw new TypeError(`${factory} for an Adapter does not support sandbox.`);\n }\n if (Object.hasOwn(value, \"diff\")) {\n throw new TypeError(`${factory} for an Adapter does not support Agent workspace diff configuration.`);\n }\n}\nfunction boundEvalFactories<Context extends object, Assertions extends object | undefined, Flags extends AdapterFlagsParser>(token: AdapterContractToken<Context, Assertions, Flags>): Pick<AdapterDefinition<Context, Assertions, Flags>, \"defineEval\" | \"defineScoreEval\"> {\n return {\n defineEval(input) {\n assertAdapterEvalInput(input, \"defineEval\");\n return defineEvalForContext(\"pass\", input, {\n [EVAL_ADAPTER_CONTRACT_TOKEN]: token,\n requiredModelSlots: normalizeModelRequirements(input.requires),\n }) as AdapterEvalDefinition<\"pass\", Context, Assertions, Flags>;\n },\n defineScoreEval(input) {\n assertAdapterEvalInput(input, \"defineScoreEval\");\n return defineEvalForContext(\"score\", input, {\n [EVAL_ADAPTER_CONTRACT_TOKEN]: token,\n requiredModelSlots: normalizeModelRequirements(input.requires),\n }) as AdapterEvalDefinition<\"score\", Context, Assertions, Flags>;\n },\n };\n}\nfunction implementAdapter<Context extends object, Assertions extends object | undefined, Flags extends AdapterFlagsParser>(token: AdapterContractToken<Context, Assertions, Flags>, input: {\n readonly name: string;\n readonly requires?: ModelRequirements;\n readonly behaviorRevision?: string;\n /** Adapter 总清理预算,默认 30000 ms;允许整数 1–300000。 */\n readonly cleanupTimeoutMs?: number;\n readonly create: AdapterFactory<Context, Flags>;\n}, factory: \"defineAdapter\" | \"AdapterContract.implement\"): AdapterImplementation<Context, Assertions, Flags> {\n assertNonEmptyString(input.name, \"name\", factory);\n if (input.behaviorRevision !== undefined) {\n assertNonEmptyString(input.behaviorRevision, \"behaviorRevision\", factory);\n }\n if (typeof input.create !== \"function\") {\n throw new TypeError(`${factory} requires create(context).`);\n }\n const cleanupTimeoutMs = resolveAdapterCleanupTimeoutMs(input.cleanupTimeoutMs);\n const authorCreate = input.create;\n const create = (context: AdapterCreateContext<AdapterFlagsOutput<Flags>>): Context | Promise<Context> => {\n const created = authorCreate(context);\n if (created instanceof Promise) {\n return created.then((value) => {\n assertPlainAdapterContext(value);\n return value;\n });\n }\n // Validate before a caller can pass a synchronous thenable to Promise adaptation.\n assertPlainAdapterContext(created);\n return created;\n };\n return Object.freeze({\n kind: \"custom\" as const,\n requiredModelSlots: normalizeModelRequirements(input.requires),\n parseFlags: token.parseFlags,\n name: input.name,\n contract: token.name,\n behaviorRevision: input.behaviorRevision ?? null,\n cleanupTimeoutMs,\n create,\n [ADAPTER_CONTRACT_TOKEN]: token,\n ...boundEvalFactories(token),\n }) as AdapterImplementation<Context, Assertions, Flags>;\n}\n/** Defines one Adapter implementation with an automatically private contract. */\nexport function defineAdapter<Context extends object, Flags extends AdapterFlagsParser = undefined, const Slots extends string = string>(input: {\n readonly name: string;\n readonly requires?: ModelRequirements<Slots>;\n readonly behaviorRevision?: string;\n /** Adapter 总清理预算,默认 30000 ms;允许整数 1–300000。 */\n readonly cleanupTimeoutMs?: number;\n readonly create: (context: AdapterCreateContext<AdapterFlagsOutput<Flags>, NoInfer<Slots>>) => (Context & ThisType<Context>) | Promise<Context & ThisType<Context>>;\n readonly parseFlags?: Flags;\n readonly assertions?: undefined;\n} & AdapterContextValidation<NoInfer<Context>> & AdapterFlagsParserValidation<NoInfer<Flags>>): AdapterImplementation<Context, undefined, Flags>;\nexport function defineAdapter<Context extends object, Assertions extends object, Flags extends AdapterFlagsParser = undefined, const Slots extends string = string>(input: {\n readonly name: string;\n readonly requires?: ModelRequirements<Slots>;\n readonly behaviorRevision?: string;\n /** Adapter 总清理预算,默认 30000 ms;允许整数 1–300000。 */\n readonly cleanupTimeoutMs?: number;\n readonly create: (context: AdapterCreateContext<AdapterFlagsOutput<Flags>, NoInfer<Slots>>) => (Context & ThisType<Context>) | Promise<Context & ThisType<Context>>;\n readonly parseFlags?: Flags;\n /** Attempt-local Assertion sugar, assembled once after create() succeeds. */\n readonly assertions: AdapterAssertionsFactory<Context, Assertions>;\n} & AdapterContextValidation<NoInfer<Context>> & AdapterFlagsParserValidation<NoInfer<Flags>> & AdapterAssertionsValidation<Context, NoInfer<Assertions>>): AdapterImplementation<Context, Assertions, Flags>;\n// @concord-code ne-adapter-define-adapter\n// @concord-implements docs/feature/adapters/README.md\n// @concord-implements docs/feature/adapters/library/writing-an-adapter.md\nexport function defineAdapter(input: {\n readonly name: string;\n readonly requires?: ModelRequirements;\n readonly behaviorRevision?: string;\n /** Adapter 总清理预算,默认 30000 ms;允许整数 1–300000。 */\n readonly cleanupTimeoutMs?: number;\n readonly create: AdapterFactory<object, AdapterFlagsParser>;\n readonly parseFlags?: Exclude<AdapterFlagsParser, undefined>;\n readonly assertions?: AdapterAssertionsFactory<object>;\n}): AdapterRuntimeDefinition {\n if (input.parseFlags !== undefined)\n assertAdapterFlagsParser(input.parseFlags);\n const assertions = input.assertions;\n if (assertions !== undefined && typeof assertions !== \"function\") {\n throw new TypeError(\"defineAdapter assertions must be a function.\");\n }\n return implementAdapter(contractToken<object, object | undefined, AdapterFlagsParser>(input.name, assertions, input.parseFlags), input, \"defineAdapter\");\n}\n/** Defines a reusable contract whose implementations and Evals share one runtime-only token. */\n// @concord-code ne-adapter-define-contract\n// @concord-implements docs/feature/adapters/README.md\n// @concord-implements docs/feature/adapters/architecture/agent-contract.md\nexport function defineAdapterContract<Context extends object>(input: {\n readonly name: string;\n} & AdapterContextValidation<NoInfer<Context>>): AdapterContract<Context> {\n assertNonEmptyString(input.name, \"name\", \"defineAdapterContract\");\n return makeAdapterContract(contractToken<Context, undefined, undefined>(input.name, undefined, undefined));\n}\nfunction makeAdapterContract<Context extends object, Assertions extends object | undefined, Flags extends AdapterFlagsParser>(token: AdapterContractToken<Context, Assertions, Flags>): AdapterContract<Context, Assertions, Flags> {\n const factories = boundEvalFactories(token);\n return Object.freeze({\n name: token.name,\n parseFlags: token.parseFlags,\n ...factories,\n implement<ImplementationContext extends Context>(implementation: AdapterImplementationInput<Context, ImplementationContext, Flags>) {\n return implementAdapter(token, implementation, \"AdapterContract.implement\");\n },\n withParseFlags<NextFlags extends Exclude<AdapterFlagsParser, undefined>>(parseFlags: NextFlags, ..._validation: AdapterFlagsParserValidationArgs<NoInfer<NextFlags>>) {\n assertAdapterFlagsParser(parseFlags);\n return makeAdapterContract(contractToken<Context, Assertions, NextFlags>(token.name, token.assertions, parseFlags));\n },\n withAssertions<NextAssertions extends object>(factory: AdapterAssertionsFactory<Context, NextAssertions>, ..._validation: AdapterAssertionsValidationArgs<Context, NoInfer<NextAssertions>>) {\n if (typeof factory !== \"function\") {\n throw new TypeError(\"AdapterContract.withAssertions requires a function.\");\n }\n return makeAdapterContract(contractToken<Context, NextAssertions, Flags>(token.name, factory, token.parseFlags));\n },\n });\n}\n/** The single credential-free persistence projection for an Adapter. */\nexport function adapterIdentity(adapter: Adapter): AdapterIdentity {\n return adapter.kind === \"custom\"\n ? Object.freeze({\n name: adapter.name,\n contract: adapter.contract,\n behaviorRevision: adapter.behaviorRevision,\n cleanupTimeoutMs: adapter.cleanupTimeoutMs,\n })\n : Object.freeze({\n name: adapter.name,\n contract: \"niceeval.agent/v1\",\n behaviorRevision: null,\n });\n}\n/** @internal Runtime contract pairing; the token itself never enters persistence. */\nexport function adapterAcceptsEval(adapter: Adapter, definition: object): boolean {\n const required = (definition as {\n readonly [EVAL_ADAPTER_CONTRACT_TOKEN]?: unknown;\n })[EVAL_ADAPTER_CONTRACT_TOKEN];\n if (adapter.kind === \"custom\") {\n const provided = adapter[ADAPTER_CONTRACT_TOKEN];\n return required !== undefined && provided !== undefined && required === provided;\n }\n return required === undefined;\n}\n/** @internal Returns the readable contract name without revealing the pairing token. */\nexport function adapterContractRequiredByEval(definition: object): string | undefined {\n return (definition as {\n readonly [EVAL_ADAPTER_CONTRACT_TOKEN]?: {\n readonly name: string;\n };\n })[EVAL_ADAPTER_CONTRACT_TOKEN]?.name;\n}\nconst RESERVED_ADAPTER_CONTEXT_KEY_SET: ReadonlySet<string> = new Set(RESERVED_ADAPTER_CONTEXT_KEYS);\nfunction assertPlainAdapterContext(value: unknown): asserts value is object {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n throw new TypeError(\"Adapter create(context) must return a plain object.\");\n }\n const prototype = Object.getPrototypeOf(value);\n if (prototype !== Object.prototype && prototype !== null) {\n throw new TypeError(\"Adapter create(context) must return an explicit plain object.\");\n }\n for (const key of Reflect.ownKeys(value)) {\n if (typeof key === \"string\" && RESERVED_ADAPTER_CONTEXT_KEY_SET.has(key)) {\n throw new TypeError(`Adapter context key ${JSON.stringify(key)} is reserved.`);\n }\n }\n}\nfunction forwardProperties(target: object, source: object, guardAccess: boolean, assertAuthorOpen: () => void): void {\n for (const key of Reflect.ownKeys(source)) {\n const descriptor = Object.getOwnPropertyDescriptor(source, key);\n if (descriptor === undefined)\n continue;\n if (\"value\" in descriptor && typeof descriptor.value === \"function\") {\n const method = guardAccess\n ? function (this: unknown, ...args: readonly unknown[]) {\n assertAuthorOpen();\n return Reflect.apply(descriptor.value, source, args);\n }\n : descriptor.value.bind(source);\n Object.defineProperty(target, key, {\n enumerable: true,\n configurable: false,\n writable: false,\n value: method,\n });\n }\n else {\n Object.defineProperty(target, key, {\n enumerable: true,\n configurable: false,\n get: () => {\n if (guardAccess)\n assertAuthorOpen();\n const value = Reflect.get(source, key, source);\n if (typeof value !== \"function\")\n return value;\n return guardAccess\n ? (...args: readonly unknown[]) => {\n assertAuthorOpen();\n return Reflect.apply(value, source, args);\n }\n : value.bind(source);\n },\n });\n }\n }\n}\n/** Observes only branded native Promises without reading an arbitrary `.then` property. */\nfunction observeNativePromiseRejection(value: unknown): boolean {\n if ((typeof value !== \"object\" && typeof value !== \"function\") || value === null)\n return false;\n try {\n void Reflect.apply(Promise.prototype.then, value, [\n undefined,\n () => undefined,\n ]);\n return true;\n }\n catch {\n return false;\n }\n}\nfunction assertPlainAdapterAssertions(value: unknown, context: object): asserts value is object {\n if (typeof value !== \"object\" || value === null || Array.isArray(value)) {\n throw new TypeError(\"Adapter assertions factory must return a plain object of methods.\");\n }\n const prototype = Object.getPrototypeOf(value);\n if (prototype !== Object.prototype && prototype !== null) {\n observeNativePromiseRejection(value);\n throw new TypeError(\"Adapter assertions factory must return an explicit plain object.\");\n }\n const contextKeys = new Set(Reflect.ownKeys(context));\n for (const key of Reflect.ownKeys(value)) {\n if (typeof key !== \"string\") {\n throw new TypeError(\"Adapter assertion method names must be strings.\");\n }\n if (RESERVED_ADAPTER_CONTEXT_KEY_SET.has(key)) {\n throw new TypeError(`Adapter assertion method name ${JSON.stringify(key)} is reserved.`);\n }\n if (contextKeys.has(key)) {\n throw new TypeError(`Adapter assertion method name ${JSON.stringify(key)} conflicts with an app member.`);\n }\n const descriptor = Object.getOwnPropertyDescriptor(value, key);\n if (descriptor === undefined || !(\"value\" in descriptor) || typeof descriptor.value !== \"function\") {\n throw new TypeError(`Adapter assertion ${JSON.stringify(key)} must be an own data method.`);\n }\n }\n}\nfunction bindAdapterAppContext<Context>(context: Context, assertAppOpen: () => void): Readonly<Context> {\n const target = Object.create(null) as object;\n forwardProperties(target, context as object, true, assertAppOpen);\n return Object.freeze(target) as Readonly<Context>;\n}\nfunction bindAdapterAssertions<Kind extends EvaluationKind, Context extends object>(core: EvalContext<Kind>, context: Context, factory: AdapterAssertionsFactory<Context>, assertAuthorOpen: () => void): {\n readonly app: Readonly<Context>;\n readonly assertions: object;\n} {\n let assembled = false;\n const assertAppOpen = (): void => {\n assertAuthorOpen();\n if (!assembled) {\n throw new TypeError(\"Adapter assertions factory may only assemble methods; app access starts afterward.\");\n }\n };\n const app = bindAdapterAppContext(context, assertAppOpen);\n const handleFrames: Array<WeakSet<object>> = [];\n const check = (...args: readonly unknown[]): unknown => {\n assertAuthorOpen();\n const frame = handleFrames.at(-1);\n if (frame === undefined) {\n throw new TypeError(\"Adapter assertions factory may call check only from an assertion method.\");\n }\n const handle = Reflect.apply(core.check, undefined, args);\n if ((typeof handle !== \"object\" && typeof handle !== \"function\") || handle === null) {\n throw new TypeError(\"Adapter assertion check did not return an AssertionHandle.\");\n }\n frame.add(handle);\n return handle;\n };\n const authored = factory({ app: app as MatchContext<Context>, check: check as AssertionCheck<\"polymorphic\", Context> });\n assertPlainAdapterAssertions(authored, context);\n Object.freeze(authored);\n assembled = true;\n const assertions = Object.create(null) as object;\n for (const key of Reflect.ownKeys(authored)) {\n const descriptor = Object.getOwnPropertyDescriptor(authored, key)!;\n const method = descriptor.value as (...args: readonly unknown[]) => unknown;\n Object.defineProperty(assertions, key, {\n enumerable: true,\n configurable: false,\n writable: false,\n value: (...args: readonly unknown[]) => {\n assertAuthorOpen();\n const frame = new WeakSet<object>();\n handleFrames.push(frame);\n try {\n const handle = Reflect.apply(method, authored, args);\n if ((typeof handle !== \"object\" && typeof handle !== \"function\") || handle === null || !frame.has(handle)) {\n observeNativePromiseRejection(handle);\n throw new TypeError(`Adapter assertion ${JSON.stringify(key)} must synchronously return its own check() handle.`);\n }\n return handle;\n }\n finally {\n handleFrames.pop();\n }\n },\n });\n }\n return Object.freeze({ app, assertions: Object.freeze(assertions) });\n}\n/** @internal Builds the frozen single-t facade after create settles. */\n// @concord-code ne-adapter-bind-eval-context\n// @concord-implements docs/feature/adapters/architecture/agent-contract.md\nexport function bindAdapterEvalContext<Kind extends EvaluationKind, Context>(core: EvalContext<Kind>, context: Context, adapter: AdapterRuntimeDefinition, assertAuthorOpen: () => void): EvalContext<Kind> & Readonly<Context> {\n assertPlainAdapterContext(context);\n const token = adapter[ADAPTER_CONTRACT_TOKEN] as AdapterContractToken<Context & object, object | undefined>;\n let app: Readonly<Context>;\n let assertions: object | undefined;\n if (token.assertions === undefined) {\n app = bindAdapterAppContext(context, assertAuthorOpen);\n }\n else {\n const bound = bindAdapterAssertions(core, context, token.assertions, assertAuthorOpen);\n app = bound.app;\n assertions = bound.assertions;\n }\n bindAssertionContext(core.check, () => app);\n const target = Object.create(null) as object;\n forwardProperties(target, core, false, assertAuthorOpen);\n forwardProperties(target, app, false, assertAuthorOpen);\n if (assertions !== undefined)\n forwardProperties(target, assertions, false, assertAuthorOpen);\n return Object.freeze(target) as EvalContext<Kind> & Readonly<Context>;\n}\n"]}
|
package/dist/adapter.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ModelRequirements, type ResolvedModelSlot } from "./model-slots.cjs";
|
|
2
2
|
import type { AttemptSignal } from "./shared/attempt-lifecycle.cjs";
|
|
3
3
|
export type { AttemptCancellation, AttemptSignal } from "./shared/attempt-lifecycle.cjs";
|
|
4
4
|
import type { MatchContext } from "./assertions/context-match.cjs";
|
|
@@ -62,10 +62,12 @@ export interface AdapterCleanupContext {
|
|
|
62
62
|
/** 独立于执行信号;整个 Adapter 清理窗口截止时中止。 */
|
|
63
63
|
readonly signal: AbortSignal;
|
|
64
64
|
}
|
|
65
|
-
export interface AdapterCreateContext<Flags = ExperimentFlags> {
|
|
65
|
+
export interface AdapterCreateContext<Flags = ExperimentFlags, Slots extends string = string> {
|
|
66
66
|
/** Frozen application model selections for this Attempt. */
|
|
67
|
-
readonly models:
|
|
68
|
-
recordUsage(input: import("./adapter-usage.cjs").AdapterUsageInput
|
|
67
|
+
readonly models: Readonly<Record<Slots, ResolvedModelSlot>>;
|
|
68
|
+
recordUsage(input: Omit<import("./adapter-usage.cjs").AdapterUsageInput, "modelSlot"> & {
|
|
69
|
+
readonly modelSlot?: Slots | null;
|
|
70
|
+
}): void;
|
|
69
71
|
/** Close application usage admission and declare whether the recorded collection is complete. */
|
|
70
72
|
sealUsage(input: import("./adapter-usage.cjs").AdapterUsageSeal): void;
|
|
71
73
|
attach(input: import("./adapter-attachments.cjs").AdapterAttachmentInput): Promise<import("./adapter-attachments.cjs").AdapterAttachmentReceipt>;
|
|
@@ -126,11 +128,17 @@ type AdapterScoreEvalFields = Omit<ScoreEvalInput<undefined>, "test" | "sandbox"
|
|
|
126
128
|
readonly sandbox?: never;
|
|
127
129
|
readonly diff?: never;
|
|
128
130
|
};
|
|
129
|
-
export type AdapterEvalInput<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined> = AdapterEvalFields & {
|
|
130
|
-
|
|
131
|
+
export type AdapterEvalInput<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined, Slots extends string = string> = AdapterEvalFields & {
|
|
132
|
+
readonly requires?: ModelRequirements<Slots>;
|
|
133
|
+
test(t: Omit<EvalContext<"pass", AdapterFlagsOutput<Flags>, Context>, "usage"> & {
|
|
134
|
+
readonly usage: EvalUsage<NoInfer<Slots>>;
|
|
135
|
+
} & Readonly<Context> & AdapterAssertionsFor<Assertions, "pass">): void | Promise<void>;
|
|
131
136
|
};
|
|
132
|
-
export type AdapterScoreEvalInput<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined> = AdapterScoreEvalFields & {
|
|
133
|
-
|
|
137
|
+
export type AdapterScoreEvalInput<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined, Slots extends string = string> = AdapterScoreEvalFields & {
|
|
138
|
+
readonly requires?: ModelRequirements<Slots>;
|
|
139
|
+
test(t: Omit<EvalContext<"score", AdapterFlagsOutput<Flags>, Context>, "usage"> & {
|
|
140
|
+
readonly usage: EvalUsage<NoInfer<Slots>>;
|
|
141
|
+
} & Readonly<Context> & AdapterAssertionsFor<Assertions, "score">): void | Promise<void>;
|
|
134
142
|
};
|
|
135
143
|
interface AdapterContractToken<Context extends object, Assertions extends object | undefined, Flags extends AdapterFlagsParser = undefined> {
|
|
136
144
|
readonly name: string;
|
|
@@ -152,13 +160,14 @@ export interface AdapterRuntimeEvalDefinition<Kind extends EvaluationKind> exten
|
|
|
152
160
|
export interface AdapterDefinition<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined> {
|
|
153
161
|
readonly name: string;
|
|
154
162
|
readonly parseFlags: Flags;
|
|
155
|
-
defineEval(input: AdapterEvalInput<Context, Assertions, Flags>): AdapterEvalDefinition<"pass", Context, Assertions, Flags>;
|
|
156
|
-
defineScoreEval(input: AdapterScoreEvalInput<Context, Assertions, Flags>): AdapterEvalDefinition<"score", Context, Assertions, Flags>;
|
|
163
|
+
defineEval<const Slots extends string = string>(input: AdapterEvalInput<Context, Assertions, Flags, Slots>): AdapterEvalDefinition<"pass", Context, Assertions, Flags>;
|
|
164
|
+
defineScoreEval<const Slots extends string = string>(input: AdapterScoreEvalInput<Context, Assertions, Flags, Slots>): AdapterEvalDefinition<"score", Context, Assertions, Flags>;
|
|
157
165
|
}
|
|
158
166
|
/** Existential runtime view used by Experiment without erasing a concrete context to `any`. */
|
|
159
167
|
export interface AdapterRuntimeDefinition {
|
|
160
168
|
readonly parseFlags?: Exclude<AdapterFlagsParser, undefined>;
|
|
161
169
|
readonly kind: "custom";
|
|
170
|
+
readonly requiredModelSlots?: readonly string[];
|
|
162
171
|
readonly name: string;
|
|
163
172
|
readonly contract: string;
|
|
164
173
|
readonly behaviorRevision: string | null;
|
|
@@ -195,21 +204,23 @@ export interface AdapterContract<Context extends object, Assertions extends obje
|
|
|
195
204
|
}
|
|
196
205
|
export type Adapter = import("./agents/types.cjs").Agent | AdapterRuntimeDefinition;
|
|
197
206
|
/** Defines one Adapter implementation with an automatically private contract. */
|
|
198
|
-
export declare function defineAdapter<Context extends object, Flags extends AdapterFlagsParser = undefined>(input: {
|
|
207
|
+
export declare function defineAdapter<Context extends object, Flags extends AdapterFlagsParser = undefined, const Slots extends string = string>(input: {
|
|
199
208
|
readonly name: string;
|
|
209
|
+
readonly requires?: ModelRequirements<Slots>;
|
|
200
210
|
readonly behaviorRevision?: string;
|
|
201
211
|
/** Adapter 总清理预算,默认 30000 ms;允许整数 1–300000。 */
|
|
202
212
|
readonly cleanupTimeoutMs?: number;
|
|
203
|
-
readonly create:
|
|
213
|
+
readonly create: (context: AdapterCreateContext<AdapterFlagsOutput<Flags>, NoInfer<Slots>>) => (Context & ThisType<Context>) | Promise<Context & ThisType<Context>>;
|
|
204
214
|
readonly parseFlags?: Flags;
|
|
205
215
|
readonly assertions?: undefined;
|
|
206
216
|
} & AdapterContextValidation<NoInfer<Context>> & AdapterFlagsParserValidation<NoInfer<Flags>>): AdapterImplementation<Context, undefined, Flags>;
|
|
207
|
-
export declare function defineAdapter<Context extends object, Assertions extends object, Flags extends AdapterFlagsParser = undefined>(input: {
|
|
217
|
+
export declare function defineAdapter<Context extends object, Assertions extends object, Flags extends AdapterFlagsParser = undefined, const Slots extends string = string>(input: {
|
|
208
218
|
readonly name: string;
|
|
219
|
+
readonly requires?: ModelRequirements<Slots>;
|
|
209
220
|
readonly behaviorRevision?: string;
|
|
210
221
|
/** Adapter 总清理预算,默认 30000 ms;允许整数 1–300000。 */
|
|
211
222
|
readonly cleanupTimeoutMs?: number;
|
|
212
|
-
readonly create:
|
|
223
|
+
readonly create: (context: AdapterCreateContext<AdapterFlagsOutput<Flags>, NoInfer<Slots>>) => (Context & ThisType<Context>) | Promise<Context & ThisType<Context>>;
|
|
213
224
|
readonly parseFlags?: Flags;
|
|
214
225
|
/** Attempt-local Assertion sugar, assembled once after create() succeeds. */
|
|
215
226
|
readonly assertions: AdapterAssertionsFactory<Context, Assertions>;
|
package/dist/adapter.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ModelRequirements, type ResolvedModelSlot } from "./model-slots.mjs";
|
|
2
2
|
import type { AttemptSignal } from "./shared/attempt-lifecycle.mjs";
|
|
3
3
|
export type { AttemptCancellation, AttemptSignal } from "./shared/attempt-lifecycle.mjs";
|
|
4
4
|
import type { MatchContext } from "./assertions/context-match.mjs";
|
|
@@ -62,10 +62,12 @@ export interface AdapterCleanupContext {
|
|
|
62
62
|
/** 独立于执行信号;整个 Adapter 清理窗口截止时中止。 */
|
|
63
63
|
readonly signal: AbortSignal;
|
|
64
64
|
}
|
|
65
|
-
export interface AdapterCreateContext<Flags = ExperimentFlags> {
|
|
65
|
+
export interface AdapterCreateContext<Flags = ExperimentFlags, Slots extends string = string> {
|
|
66
66
|
/** Frozen application model selections for this Attempt. */
|
|
67
|
-
readonly models:
|
|
68
|
-
recordUsage(input: import("./adapter-usage.mjs").AdapterUsageInput
|
|
67
|
+
readonly models: Readonly<Record<Slots, ResolvedModelSlot>>;
|
|
68
|
+
recordUsage(input: Omit<import("./adapter-usage.mjs").AdapterUsageInput, "modelSlot"> & {
|
|
69
|
+
readonly modelSlot?: Slots | null;
|
|
70
|
+
}): void;
|
|
69
71
|
/** Close application usage admission and declare whether the recorded collection is complete. */
|
|
70
72
|
sealUsage(input: import("./adapter-usage.mjs").AdapterUsageSeal): void;
|
|
71
73
|
attach(input: import("./adapter-attachments.mjs").AdapterAttachmentInput): Promise<import("./adapter-attachments.mjs").AdapterAttachmentReceipt>;
|
|
@@ -126,11 +128,17 @@ type AdapterScoreEvalFields = Omit<ScoreEvalInput<undefined>, "test" | "sandbox"
|
|
|
126
128
|
readonly sandbox?: never;
|
|
127
129
|
readonly diff?: never;
|
|
128
130
|
};
|
|
129
|
-
export type AdapterEvalInput<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined> = AdapterEvalFields & {
|
|
130
|
-
|
|
131
|
+
export type AdapterEvalInput<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined, Slots extends string = string> = AdapterEvalFields & {
|
|
132
|
+
readonly requires?: ModelRequirements<Slots>;
|
|
133
|
+
test(t: Omit<EvalContext<"pass", AdapterFlagsOutput<Flags>, Context>, "usage"> & {
|
|
134
|
+
readonly usage: EvalUsage<NoInfer<Slots>>;
|
|
135
|
+
} & Readonly<Context> & AdapterAssertionsFor<Assertions, "pass">): void | Promise<void>;
|
|
131
136
|
};
|
|
132
|
-
export type AdapterScoreEvalInput<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined> = AdapterScoreEvalFields & {
|
|
133
|
-
|
|
137
|
+
export type AdapterScoreEvalInput<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined, Slots extends string = string> = AdapterScoreEvalFields & {
|
|
138
|
+
readonly requires?: ModelRequirements<Slots>;
|
|
139
|
+
test(t: Omit<EvalContext<"score", AdapterFlagsOutput<Flags>, Context>, "usage"> & {
|
|
140
|
+
readonly usage: EvalUsage<NoInfer<Slots>>;
|
|
141
|
+
} & Readonly<Context> & AdapterAssertionsFor<Assertions, "score">): void | Promise<void>;
|
|
134
142
|
};
|
|
135
143
|
interface AdapterContractToken<Context extends object, Assertions extends object | undefined, Flags extends AdapterFlagsParser = undefined> {
|
|
136
144
|
readonly name: string;
|
|
@@ -152,13 +160,14 @@ export interface AdapterRuntimeEvalDefinition<Kind extends EvaluationKind> exten
|
|
|
152
160
|
export interface AdapterDefinition<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined> {
|
|
153
161
|
readonly name: string;
|
|
154
162
|
readonly parseFlags: Flags;
|
|
155
|
-
defineEval(input: AdapterEvalInput<Context, Assertions, Flags>): AdapterEvalDefinition<"pass", Context, Assertions, Flags>;
|
|
156
|
-
defineScoreEval(input: AdapterScoreEvalInput<Context, Assertions, Flags>): AdapterEvalDefinition<"score", Context, Assertions, Flags>;
|
|
163
|
+
defineEval<const Slots extends string = string>(input: AdapterEvalInput<Context, Assertions, Flags, Slots>): AdapterEvalDefinition<"pass", Context, Assertions, Flags>;
|
|
164
|
+
defineScoreEval<const Slots extends string = string>(input: AdapterScoreEvalInput<Context, Assertions, Flags, Slots>): AdapterEvalDefinition<"score", Context, Assertions, Flags>;
|
|
157
165
|
}
|
|
158
166
|
/** Existential runtime view used by Experiment without erasing a concrete context to `any`. */
|
|
159
167
|
export interface AdapterRuntimeDefinition {
|
|
160
168
|
readonly parseFlags?: Exclude<AdapterFlagsParser, undefined>;
|
|
161
169
|
readonly kind: "custom";
|
|
170
|
+
readonly requiredModelSlots?: readonly string[];
|
|
162
171
|
readonly name: string;
|
|
163
172
|
readonly contract: string;
|
|
164
173
|
readonly behaviorRevision: string | null;
|
|
@@ -195,21 +204,23 @@ export interface AdapterContract<Context extends object, Assertions extends obje
|
|
|
195
204
|
}
|
|
196
205
|
export type Adapter = import("./agents/types.mjs").Agent | AdapterRuntimeDefinition;
|
|
197
206
|
/** Defines one Adapter implementation with an automatically private contract. */
|
|
198
|
-
export declare function defineAdapter<Context extends object, Flags extends AdapterFlagsParser = undefined>(input: {
|
|
207
|
+
export declare function defineAdapter<Context extends object, Flags extends AdapterFlagsParser = undefined, const Slots extends string = string>(input: {
|
|
199
208
|
readonly name: string;
|
|
209
|
+
readonly requires?: ModelRequirements<Slots>;
|
|
200
210
|
readonly behaviorRevision?: string;
|
|
201
211
|
/** Adapter 总清理预算,默认 30000 ms;允许整数 1–300000。 */
|
|
202
212
|
readonly cleanupTimeoutMs?: number;
|
|
203
|
-
readonly create:
|
|
213
|
+
readonly create: (context: AdapterCreateContext<AdapterFlagsOutput<Flags>, NoInfer<Slots>>) => (Context & ThisType<Context>) | Promise<Context & ThisType<Context>>;
|
|
204
214
|
readonly parseFlags?: Flags;
|
|
205
215
|
readonly assertions?: undefined;
|
|
206
216
|
} & AdapterContextValidation<NoInfer<Context>> & AdapterFlagsParserValidation<NoInfer<Flags>>): AdapterImplementation<Context, undefined, Flags>;
|
|
207
|
-
export declare function defineAdapter<Context extends object, Assertions extends object, Flags extends AdapterFlagsParser = undefined>(input: {
|
|
217
|
+
export declare function defineAdapter<Context extends object, Assertions extends object, Flags extends AdapterFlagsParser = undefined, const Slots extends string = string>(input: {
|
|
208
218
|
readonly name: string;
|
|
219
|
+
readonly requires?: ModelRequirements<Slots>;
|
|
209
220
|
readonly behaviorRevision?: string;
|
|
210
221
|
/** Adapter 总清理预算,默认 30000 ms;允许整数 1–300000。 */
|
|
211
222
|
readonly cleanupTimeoutMs?: number;
|
|
212
|
-
readonly create:
|
|
223
|
+
readonly create: (context: AdapterCreateContext<AdapterFlagsOutput<Flags>, NoInfer<Slots>>) => (Context & ThisType<Context>) | Promise<Context & ThisType<Context>>;
|
|
213
224
|
readonly parseFlags?: Flags;
|
|
214
225
|
/** Attempt-local Assertion sugar, assembled once after create() succeeds. */
|
|
215
226
|
readonly assertions: AdapterAssertionsFactory<Context, Assertions>;
|
package/dist/adapter.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ModelRequirements, type ResolvedModelSlot } from "./model-slots.js";
|
|
2
2
|
import type { AttemptSignal } from "./shared/attempt-lifecycle.js";
|
|
3
3
|
export type { AttemptCancellation, AttemptSignal } from "./shared/attempt-lifecycle.js";
|
|
4
4
|
import type { MatchContext } from "./assertions/context-match.js";
|
|
@@ -62,10 +62,12 @@ export interface AdapterCleanupContext {
|
|
|
62
62
|
/** 独立于执行信号;整个 Adapter 清理窗口截止时中止。 */
|
|
63
63
|
readonly signal: AbortSignal;
|
|
64
64
|
}
|
|
65
|
-
export interface AdapterCreateContext<Flags = ExperimentFlags> {
|
|
65
|
+
export interface AdapterCreateContext<Flags = ExperimentFlags, Slots extends string = string> {
|
|
66
66
|
/** Frozen application model selections for this Attempt. */
|
|
67
|
-
readonly models:
|
|
68
|
-
recordUsage(input: import("./adapter-usage.js").AdapterUsageInput
|
|
67
|
+
readonly models: Readonly<Record<Slots, ResolvedModelSlot>>;
|
|
68
|
+
recordUsage(input: Omit<import("./adapter-usage.js").AdapterUsageInput, "modelSlot"> & {
|
|
69
|
+
readonly modelSlot?: Slots | null;
|
|
70
|
+
}): void;
|
|
69
71
|
/** Close application usage admission and declare whether the recorded collection is complete. */
|
|
70
72
|
sealUsage(input: import("./adapter-usage.js").AdapterUsageSeal): void;
|
|
71
73
|
attach(input: import("./adapter-attachments.js").AdapterAttachmentInput): Promise<import("./adapter-attachments.js").AdapterAttachmentReceipt>;
|
|
@@ -126,11 +128,17 @@ type AdapterScoreEvalFields = Omit<ScoreEvalInput<undefined>, "test" | "sandbox"
|
|
|
126
128
|
readonly sandbox?: never;
|
|
127
129
|
readonly diff?: never;
|
|
128
130
|
};
|
|
129
|
-
export type AdapterEvalInput<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined> = AdapterEvalFields & {
|
|
130
|
-
|
|
131
|
+
export type AdapterEvalInput<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined, Slots extends string = string> = AdapterEvalFields & {
|
|
132
|
+
readonly requires?: ModelRequirements<Slots>;
|
|
133
|
+
test(t: Omit<EvalContext<"pass", AdapterFlagsOutput<Flags>, Context>, "usage"> & {
|
|
134
|
+
readonly usage: EvalUsage<NoInfer<Slots>>;
|
|
135
|
+
} & Readonly<Context> & AdapterAssertionsFor<Assertions, "pass">): void | Promise<void>;
|
|
131
136
|
};
|
|
132
|
-
export type AdapterScoreEvalInput<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined> = AdapterScoreEvalFields & {
|
|
133
|
-
|
|
137
|
+
export type AdapterScoreEvalInput<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined, Slots extends string = string> = AdapterScoreEvalFields & {
|
|
138
|
+
readonly requires?: ModelRequirements<Slots>;
|
|
139
|
+
test(t: Omit<EvalContext<"score", AdapterFlagsOutput<Flags>, Context>, "usage"> & {
|
|
140
|
+
readonly usage: EvalUsage<NoInfer<Slots>>;
|
|
141
|
+
} & Readonly<Context> & AdapterAssertionsFor<Assertions, "score">): void | Promise<void>;
|
|
134
142
|
};
|
|
135
143
|
interface AdapterContractToken<Context extends object, Assertions extends object | undefined, Flags extends AdapterFlagsParser = undefined> {
|
|
136
144
|
readonly name: string;
|
|
@@ -152,13 +160,14 @@ export interface AdapterRuntimeEvalDefinition<Kind extends EvaluationKind> exten
|
|
|
152
160
|
export interface AdapterDefinition<Context extends object, Assertions extends object | undefined = undefined, Flags extends AdapterFlagsParser = undefined> {
|
|
153
161
|
readonly name: string;
|
|
154
162
|
readonly parseFlags: Flags;
|
|
155
|
-
defineEval(input: AdapterEvalInput<Context, Assertions, Flags>): AdapterEvalDefinition<"pass", Context, Assertions, Flags>;
|
|
156
|
-
defineScoreEval(input: AdapterScoreEvalInput<Context, Assertions, Flags>): AdapterEvalDefinition<"score", Context, Assertions, Flags>;
|
|
163
|
+
defineEval<const Slots extends string = string>(input: AdapterEvalInput<Context, Assertions, Flags, Slots>): AdapterEvalDefinition<"pass", Context, Assertions, Flags>;
|
|
164
|
+
defineScoreEval<const Slots extends string = string>(input: AdapterScoreEvalInput<Context, Assertions, Flags, Slots>): AdapterEvalDefinition<"score", Context, Assertions, Flags>;
|
|
157
165
|
}
|
|
158
166
|
/** Existential runtime view used by Experiment without erasing a concrete context to `any`. */
|
|
159
167
|
export interface AdapterRuntimeDefinition {
|
|
160
168
|
readonly parseFlags?: Exclude<AdapterFlagsParser, undefined>;
|
|
161
169
|
readonly kind: "custom";
|
|
170
|
+
readonly requiredModelSlots?: readonly string[];
|
|
162
171
|
readonly name: string;
|
|
163
172
|
readonly contract: string;
|
|
164
173
|
readonly behaviorRevision: string | null;
|
|
@@ -195,21 +204,23 @@ export interface AdapterContract<Context extends object, Assertions extends obje
|
|
|
195
204
|
}
|
|
196
205
|
export type Adapter = import("./agents/types.js").Agent | AdapterRuntimeDefinition;
|
|
197
206
|
/** Defines one Adapter implementation with an automatically private contract. */
|
|
198
|
-
export declare function defineAdapter<Context extends object, Flags extends AdapterFlagsParser = undefined>(input: {
|
|
207
|
+
export declare function defineAdapter<Context extends object, Flags extends AdapterFlagsParser = undefined, const Slots extends string = string>(input: {
|
|
199
208
|
readonly name: string;
|
|
209
|
+
readonly requires?: ModelRequirements<Slots>;
|
|
200
210
|
readonly behaviorRevision?: string;
|
|
201
211
|
/** Adapter 总清理预算,默认 30000 ms;允许整数 1–300000。 */
|
|
202
212
|
readonly cleanupTimeoutMs?: number;
|
|
203
|
-
readonly create:
|
|
213
|
+
readonly create: (context: AdapterCreateContext<AdapterFlagsOutput<Flags>, NoInfer<Slots>>) => (Context & ThisType<Context>) | Promise<Context & ThisType<Context>>;
|
|
204
214
|
readonly parseFlags?: Flags;
|
|
205
215
|
readonly assertions?: undefined;
|
|
206
216
|
} & AdapterContextValidation<NoInfer<Context>> & AdapterFlagsParserValidation<NoInfer<Flags>>): AdapterImplementation<Context, undefined, Flags>;
|
|
207
|
-
export declare function defineAdapter<Context extends object, Assertions extends object, Flags extends AdapterFlagsParser = undefined>(input: {
|
|
217
|
+
export declare function defineAdapter<Context extends object, Assertions extends object, Flags extends AdapterFlagsParser = undefined, const Slots extends string = string>(input: {
|
|
208
218
|
readonly name: string;
|
|
219
|
+
readonly requires?: ModelRequirements<Slots>;
|
|
209
220
|
readonly behaviorRevision?: string;
|
|
210
221
|
/** Adapter 总清理预算,默认 30000 ms;允许整数 1–300000。 */
|
|
211
222
|
readonly cleanupTimeoutMs?: number;
|
|
212
|
-
readonly create:
|
|
223
|
+
readonly create: (context: AdapterCreateContext<AdapterFlagsOutput<Flags>, NoInfer<Slots>>) => (Context & ThisType<Context>) | Promise<Context & ThisType<Context>>;
|
|
213
224
|
readonly parseFlags?: Flags;
|
|
214
225
|
/** Attempt-local Assertion sugar, assembled once after create() succeeds. */
|
|
215
226
|
readonly assertions: AdapterAssertionsFactory<Context, Assertions>;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.measured = measured;
|
|
4
|
+
exports.quantile = quantile;
|
|
5
|
+
/** Preserve a missing observation instead of coercing null to zero. */
|
|
6
|
+
function measured(value, options) {
|
|
7
|
+
if (typeof options?.unavailable !== "string" || options.unavailable.trim().length === 0) {
|
|
8
|
+
throw new TypeError("measured() requires a non-empty unavailable reason.");
|
|
9
|
+
}
|
|
10
|
+
if (value === null)
|
|
11
|
+
return Object.freeze({ state: "unavailable", reason: options.unavailable });
|
|
12
|
+
if (typeof value !== "number")
|
|
13
|
+
throw new TypeError("measured() requires a number or null.");
|
|
14
|
+
return Number.isFinite(value)
|
|
15
|
+
? Object.freeze({ state: "exact", value })
|
|
16
|
+
: Object.freeze({ state: "unavailable", reason: "non-finite-number" });
|
|
17
|
+
}
|
|
18
|
+
/** Compute a quantile without changing or retaining the samples. Empty or invalid samples remain unavailable. */
|
|
19
|
+
function quantile(samples, p, options = {}) {
|
|
20
|
+
if (!Array.isArray(samples))
|
|
21
|
+
throw new TypeError("quantile() requires an array of samples.");
|
|
22
|
+
if (!Number.isFinite(p) || p < 0 || p > 1)
|
|
23
|
+
throw new TypeError("quantile() probability must be a finite number in [0, 1].");
|
|
24
|
+
const method = options.method ?? "linear";
|
|
25
|
+
if (method !== "linear" && method !== "nearest-rank")
|
|
26
|
+
throw new TypeError("quantile() method must be linear or nearest-rank.");
|
|
27
|
+
const statistics = Object.freeze({ sampleCount: samples.length, probability: p, method });
|
|
28
|
+
if (samples.length === 0)
|
|
29
|
+
return Object.freeze({ state: "unavailable", reason: "no-samples", statistics });
|
|
30
|
+
for (const sample of samples) {
|
|
31
|
+
if (!Number.isFinite(sample))
|
|
32
|
+
return Object.freeze({ state: "unavailable", reason: "non-finite-sample", statistics });
|
|
33
|
+
}
|
|
34
|
+
const sorted = [...samples].sort((a, b) => a - b);
|
|
35
|
+
const position = (sorted.length - 1) * p;
|
|
36
|
+
const lower = sorted[Math.floor(position)];
|
|
37
|
+
const upper = sorted[Math.ceil(position)];
|
|
38
|
+
const fraction = position - Math.floor(position);
|
|
39
|
+
const delta = upper - lower;
|
|
40
|
+
const value = method === "nearest-rank"
|
|
41
|
+
? sorted[Math.max(0, Math.ceil(sorted.length * p) - 1)]
|
|
42
|
+
: Number.isFinite(delta) ? lower + delta * fraction : lower * (1 - fraction) + upper * fraction;
|
|
43
|
+
return Object.freeze({ state: "exact", value, statistics });
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=measurements.cjs.map
|