niceeval 0.14.4-canary.67 → 0.15.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.
Files changed (53) hide show
  1. package/INDEX.md +2 -2
  2. package/dist/adapter.cjs +162 -14
  3. package/dist/adapter.cjs.map +1 -1
  4. package/dist/adapter.d.cts +82 -17
  5. package/dist/adapter.d.mts +82 -17
  6. package/dist/adapter.d.ts +82 -17
  7. package/dist/agents/index.cjs.map +1 -1
  8. package/dist/agents/index.d.cts +2 -1
  9. package/dist/agents/index.d.mts +2 -1
  10. package/dist/agents/index.d.ts +2 -1
  11. package/dist/assertions/api.cjs.map +1 -1
  12. package/dist/assertions/api.d.cts +32 -12
  13. package/dist/assertions/api.d.mts +32 -12
  14. package/dist/assertions/api.d.ts +32 -12
  15. package/dist/assertions/runtime.cjs +4 -1
  16. package/dist/assertions/runtime.cjs.map +1 -1
  17. package/dist/coordination/platform/node-process-identity.cjs +99 -21
  18. package/dist/coordination/platform/node-process-identity.cjs.map +1 -1
  19. package/dist/coordination/platform/node-process-identity.d.cts +17 -1
  20. package/dist/coordination/platform/node-process-identity.d.mts +17 -1
  21. package/dist/coordination/platform/node-process-identity.d.ts +17 -1
  22. package/dist/coordination/platform/node-process-identity.js +2 -0
  23. package/dist/index.cjs.map +1 -1
  24. package/dist/index.d.cts +2 -2
  25. package/dist/index.d.mts +2 -2
  26. package/dist/index.d.ts +2 -2
  27. package/dist/record/sqlite/current-schema.cjs +437 -5
  28. package/dist/record/sqlite/current-schema.cjs.map +1 -1
  29. package/dist/record/sqlite/current-schema.d.cts +4 -4
  30. package/dist/record/sqlite/current-schema.d.mts +4 -4
  31. package/dist/record/sqlite/current-schema.d.ts +4 -4
  32. package/dist/record/sqlite/schema.d.cts +1 -1
  33. package/dist/record/sqlite/schema.d.mts +1 -1
  34. package/dist/record/sqlite/schema.d.ts +1 -1
  35. package/dist/runner/attempt-resources.cjs +2 -1
  36. package/dist/runner/attempt-resources.cjs.map +1 -1
  37. package/dist/runner/attempt-resources.d.cts +2 -1
  38. package/dist/runner/attempt-resources.d.mts +2 -1
  39. package/dist/runner/attempt-resources.d.ts +2 -1
  40. package/dist/runner/attempt.cjs +7 -3
  41. package/dist/runner/attempt.cjs.map +1 -1
  42. package/dist/runner/node-process-identity.js +2 -0
  43. package/dist/types.cjs.map +1 -1
  44. package/dist/types.d.cts +2 -1
  45. package/dist/types.d.mts +2 -1
  46. package/dist/types.d.ts +2 -1
  47. package/dist/view/function-runtime.mjs +528 -29
  48. package/docs-site/zh/reference/define-agent.mdx +125 -3
  49. package/docs-site/zh/troubleshooting/debugging.mdx +2 -0
  50. package/docs-site/zh/tutorials/custom-application.mdx +87 -17
  51. package/docs-site/zh/tutorials/evaluation-kinds.mdx +1 -1
  52. package/docs-site/zh/tutorials/viewing-results.mdx +2 -1
  53. package/package.json +1 -1
package/INDEX.md CHANGED
@@ -51,7 +51,7 @@
51
51
  - `docs-site/zh/tutorials/connect-your-agent.mdx` — 接入你的 Agent:写一个 Adapter、配置一个 Experiment,并运行第一条评估用例。再把配置和参数从 Experiment 传给 Adapter 与被测应用。
52
52
  - `docs-site/zh/tutorials/control-run-cost.mdx` — 控制一次运行的成本:用 attempts、首过即停、budget、并发和结果沿用分别控制统计样本、停止派发、花费保护与资源占用。
53
53
  - `docs-site/zh/tutorials/criteria-files.mdx` — 隐藏测试判分:让判据文件进缓存 fingerprint:用 loadText 在模块顶层读入隐藏测试、跑测脚本等判据文件,文件内容进入 fingerprint:改一字节自动重跑,不靠人工 --rerun。
54
- - `docs-site/zh/tutorials/custom-application.mdx` — 评估自定义 LLM 应用:保留应用自己的方法与上下文,用 NiceEval 评估生成内容、社交互动和游戏步骤。
54
+ - `docs-site/zh/tutorials/custom-application.mdx` — 评估自定义应用:保留应用自己的方法与上下文,用 NiceEval 评估结构化结果和业务操作。
55
55
  - `docs-site/zh/tutorials/dataset-fanout.mdx` — 数据驱动测试(dataset fan-out):用多份数据运行同一套评估用例:从 .eval.ts 文件导出数组或 keyed record,将一套评估逻辑展开为多个 case。用 loadYaml 或 loadJson 读取外部测试集,并获得稳定 ID。
56
56
  - `docs-site/zh/tutorials/debug-lifecycle-plan.mdx` — 运行前检查 Sandbox 计划:用 niceeval debug 查看 Experiment、评估组、评估用例与 Agent 的实际 action 顺序和数值,而不创建运行资源。
57
57
  - `docs-site/zh/tutorials/docker-in-docker.mdx` — 让 Sandbox 使用 Docker:根据任务信任边界选择 Docker socket、raw privileged DinD 或受管 rootless DinD,并为 Agent 准备 Docker CLI 与 daemon。
@@ -94,7 +94,7 @@
94
94
  - `docs-site/zh/reference/builtin-agents.mdx` — 内置 Agent 能力参考:NiceEval 内置的 claude-code、codex、bub 适配器分别做到了哪些能力,对应哪些断言,以及已知限制。
95
95
  - `docs-site/zh/reference/capabilities.mdx` — 能力与证据覆盖参考:Agent 的构造方式、运行时行为与必填的六通道 evidenceCoverage 声明,怎样共同决定 NiceEval 的断言能相信什么。
96
96
  - `docs-site/zh/reference/cli.mdx` — CLI:用固定的 query、show 和 view 读取 canonical SQLite Record。
97
- - `docs-site/zh/reference/define-agent.mdx` — defineAgent defineSandboxAgent:Adapter 参考:defineAgent defineSandboxAgent 参考:AgentContext、AgentSession、Sandbox 接口和共享 Sandbox 辅助函数。
97
+ - `docs-site/zh/reference/define-agent.mdx` — 定义评估对象:Adapter 参考:自定义 Adapter Agent 接入的上下文、断言方法和资源生命周期。
98
98
  - `docs-site/zh/reference/define-config.mdx` — defineConfig:项目默认配置:defineConfig 参考:Judge Runtime、Reporters、并发、超时和 Sandbox 默认值。
99
99
  - `docs-site/zh/reference/define-eval.mdx` — defineEval:声明、配置并运行 NiceEval 评估用例:defineEval 参考:选项、test context t、Turn 返回值、Sandbox 辅助函数,以及数组和 keyed record 测试集导出。
100
100
  - `docs-site/zh/reference/events.mdx` — 标准事件流参考:StreamEvent 的十种事件:每种的字段、什么时候吐、哪些断言消费它。adapter 的核心工作就是产出这条流。
package/dist/adapter.cjs CHANGED
@@ -49,8 +49,13 @@ function assertNonEmptyString(value, field, factory) {
49
49
  throw new TypeError(`${factory} requires a non-empty ${field}.`);
50
50
  }
51
51
  }
52
- function contractToken(name) {
53
- return Object.freeze({ name, context: (value) => value });
52
+ function contractToken(name, assertions) {
53
+ return Object.freeze({
54
+ name,
55
+ assertions,
56
+ assertionTypes: (value) => value,
57
+ context: (value) => value,
58
+ });
54
59
  }
55
60
  function assertAdapterEvalInput(value, factory) {
56
61
  if (Object.hasOwn(value, "sandbox")) {
@@ -108,19 +113,31 @@ function implementAdapter(token, input, factory) {
108
113
  });
109
114
  }
110
115
  function defineAdapter(input) {
111
- return implementAdapter(contractToken(input.name), input, "defineAdapter");
116
+ const assertions = input.assertions;
117
+ if (assertions !== undefined && typeof assertions !== "function") {
118
+ throw new TypeError("defineAdapter assertions must be a function.");
119
+ }
120
+ return implementAdapter(contractToken(input.name, assertions), input, "defineAdapter");
112
121
  }
113
122
  /** Defines a reusable contract whose implementations and Evals share one runtime-only token. */
114
123
  function defineAdapterContract(input) {
115
124
  assertNonEmptyString(input.name, "name", "defineAdapterContract");
116
- const token = contractToken(input.name);
125
+ return makeAdapterContract(contractToken(input.name, undefined));
126
+ }
127
+ function makeAdapterContract(token) {
117
128
  const factories = boundEvalFactories(token);
118
129
  return Object.freeze({
119
- name: input.name,
130
+ name: token.name,
120
131
  ...factories,
121
132
  implement(implementation) {
122
133
  return implementAdapter(token, implementation, "AdapterContract.implement");
123
134
  },
135
+ withAssertions(factory, ..._validation) {
136
+ if (typeof factory !== "function") {
137
+ throw new TypeError("AdapterContract.withAssertions requires a function.");
138
+ }
139
+ return makeAdapterContract(contractToken(token.name, factory));
140
+ },
124
141
  });
125
142
  }
126
143
  /** The single credential-free persistence projection for an Adapter. */
@@ -165,16 +182,18 @@ function assertPlainAdapterContext(value) {
165
182
  }
166
183
  }
167
184
  }
168
- function forwardProperties(target, source, guardMethods, assertAuthorOpen) {
185
+ function forwardProperties(target, source, guardAccess, assertAuthorOpen) {
169
186
  for (const key of Reflect.ownKeys(source)) {
170
- const initial = Reflect.get(source, key, source);
171
- if (typeof initial === "function") {
172
- const method = guardMethods
187
+ const descriptor = Object.getOwnPropertyDescriptor(source, key);
188
+ if (descriptor === undefined)
189
+ continue;
190
+ if ("value" in descriptor && typeof descriptor.value === "function") {
191
+ const method = guardAccess
173
192
  ? function (...args) {
174
193
  assertAuthorOpen();
175
- return Reflect.apply(initial, source, args);
194
+ return Reflect.apply(descriptor.value, source, args);
176
195
  }
177
- : initial.bind(source);
196
+ : descriptor.value.bind(source);
178
197
  Object.defineProperty(target, key, {
179
198
  enumerable: true,
180
199
  configurable: false,
@@ -186,17 +205,146 @@ function forwardProperties(target, source, guardMethods, assertAuthorOpen) {
186
205
  Object.defineProperty(target, key, {
187
206
  enumerable: true,
188
207
  configurable: false,
189
- get: () => Reflect.get(source, key, source),
208
+ get: () => {
209
+ if (guardAccess)
210
+ assertAuthorOpen();
211
+ const value = Reflect.get(source, key, source);
212
+ if (typeof value !== "function")
213
+ return value;
214
+ return guardAccess
215
+ ? (...args) => {
216
+ assertAuthorOpen();
217
+ return Reflect.apply(value, source, args);
218
+ }
219
+ : value.bind(source);
220
+ },
190
221
  });
191
222
  }
192
223
  }
193
224
  }
225
+ /** Observes only branded native Promises without reading an arbitrary `.then` property. */
226
+ function observeNativePromiseRejection(value) {
227
+ if ((typeof value !== "object" && typeof value !== "function") || value === null)
228
+ return false;
229
+ try {
230
+ void Reflect.apply(Promise.prototype.then, value, [
231
+ undefined,
232
+ () => undefined,
233
+ ]);
234
+ return true;
235
+ }
236
+ catch {
237
+ return false;
238
+ }
239
+ }
240
+ function assertPlainAdapterAssertions(value, context) {
241
+ if (typeof value !== "object" || value === null || Array.isArray(value)) {
242
+ throw new TypeError("Adapter assertions factory must return a plain object of methods.");
243
+ }
244
+ const prototype = Object.getPrototypeOf(value);
245
+ if (prototype !== Object.prototype && prototype !== null) {
246
+ observeNativePromiseRejection(value);
247
+ throw new TypeError("Adapter assertions factory must return an explicit plain object.");
248
+ }
249
+ const contextKeys = new Set(Reflect.ownKeys(context));
250
+ for (const key of Reflect.ownKeys(value)) {
251
+ if (typeof key !== "string") {
252
+ throw new TypeError("Adapter assertion method names must be strings.");
253
+ }
254
+ if (RESERVED_ADAPTER_CONTEXT_KEY_SET.has(key)) {
255
+ throw new TypeError(`Adapter assertion method name ${JSON.stringify(key)} is reserved.`);
256
+ }
257
+ if (contextKeys.has(key)) {
258
+ throw new TypeError(`Adapter assertion method name ${JSON.stringify(key)} conflicts with an app member.`);
259
+ }
260
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
261
+ if (descriptor === undefined || !("value" in descriptor) || typeof descriptor.value !== "function") {
262
+ throw new TypeError(`Adapter assertion ${JSON.stringify(key)} must be an own data method.`);
263
+ }
264
+ }
265
+ }
266
+ function bindAdapterAppContext(context, assertAppOpen) {
267
+ const target = Object.create(null);
268
+ forwardProperties(target, context, true, assertAppOpen);
269
+ return Object.freeze(target);
270
+ }
271
+ function bindAdapterAssertions(core, context, factory, assertAuthorOpen) {
272
+ let assembled = false;
273
+ const assertAppOpen = () => {
274
+ assertAuthorOpen();
275
+ if (!assembled) {
276
+ throw new TypeError("Adapter assertions factory may only assemble methods; app access starts afterward.");
277
+ }
278
+ };
279
+ const app = bindAdapterAppContext(context, assertAppOpen);
280
+ const handleFrames = [];
281
+ const check = (...args) => {
282
+ assertAuthorOpen();
283
+ const frame = handleFrames.at(-1);
284
+ if (frame === undefined) {
285
+ throw new TypeError("Adapter assertions factory may call check only from an assertion method.");
286
+ }
287
+ const handle = Reflect.apply(core.check, undefined, args);
288
+ if ((typeof handle !== "object" && typeof handle !== "function") || handle === null) {
289
+ throw new TypeError("Adapter assertion check did not return an AssertionHandle.");
290
+ }
291
+ frame.add(handle);
292
+ return handle;
293
+ };
294
+ const authored = factory({
295
+ app,
296
+ check: check,
297
+ });
298
+ assertPlainAdapterAssertions(authored, context);
299
+ Object.freeze(authored);
300
+ assembled = true;
301
+ const assertions = Object.create(null);
302
+ for (const key of Reflect.ownKeys(authored)) {
303
+ const descriptor = Object.getOwnPropertyDescriptor(authored, key);
304
+ const method = descriptor.value;
305
+ Object.defineProperty(assertions, key, {
306
+ enumerable: true,
307
+ configurable: false,
308
+ writable: false,
309
+ value: (...args) => {
310
+ assertAuthorOpen();
311
+ const frame = new WeakSet();
312
+ handleFrames.push(frame);
313
+ try {
314
+ const handle = Reflect.apply(method, authored, args);
315
+ if ((typeof handle !== "object" && typeof handle !== "function") || handle === null || !frame.has(handle)) {
316
+ observeNativePromiseRejection(handle);
317
+ throw new TypeError(`Adapter assertion ${JSON.stringify(key)} must synchronously return its own check() handle.`);
318
+ }
319
+ return handle;
320
+ }
321
+ finally {
322
+ handleFrames.pop();
323
+ }
324
+ },
325
+ });
326
+ }
327
+ return Object.freeze({ app, assertions: Object.freeze(assertions) });
328
+ }
194
329
  /** @internal Builds the frozen single-t facade after create settles. */
195
- function bindAdapterEvalContext(core, context, assertAuthorOpen) {
330
+ function bindAdapterEvalContext(core, context, adapter, assertAuthorOpen) {
196
331
  assertPlainAdapterContext(context);
332
+ const token = adapter[ADAPTER_CONTRACT_TOKEN];
333
+ let app;
334
+ let assertions;
335
+ if (token.assertions === undefined) {
336
+ app = bindAdapterAppContext(context, assertAuthorOpen);
337
+ }
338
+ else {
339
+ const bound = bindAdapterAssertions(core, context, token.assertions, assertAuthorOpen);
340
+ app = bound.app;
341
+ assertions = bound.assertions;
342
+ }
197
343
  const target = Object.create(null);
198
344
  forwardProperties(target, core, false, assertAuthorOpen);
199
- forwardProperties(target, context, true, assertAuthorOpen);
345
+ forwardProperties(target, app, false, assertAuthorOpen);
346
+ if (assertions !== undefined)
347
+ forwardProperties(target, assertions, false, assertAuthorOpen);
200
348
  return Object.freeze(target);
201
349
  }
202
350
  //# sourceMappingURL=adapter.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"adapter.js","sourceRoot":"","sources":["adapter.ts"],"names":[],"mappings":";;AA+NA,sCAMC;AAED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GAAG,EAAE;gBAC/B,UAAU,EAAE,IAAI;gBAChB,YAAY,EAAE,KAAK;gBACnB,GAAG,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,MAAM,CAAC;aAC9C,CAAC,CAAC;QACP,CAAC;IACL,CAAC;AACL,CAAC;AACD,wEAAwE;AACxE,SAAgB,sBAAsB,CAAuC,IAAuB,EAAE,OAAgB,EAAE,gBAA4B;IAChJ,yBAAyB,CAAC,OAAO,CAAC,CAAC;IACnC,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,OAAO,EAAE,IAAI,EAAE,gBAAgB,CAAC,CAAC;IAC3D,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,CAA0C,CAAC;AAC1E,CAAC","sourcesContent":["import type { AssertionSubject, AssertionsRuntime, MeasurementAssertionHandle, } 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, JsonValue, 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/** 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 \"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 AdapterFactory<Context extends object> = (context: AdapterCreateContext) => (Context & ThisType<Context>) | Promise<Context & ThisType<Context>>;\nexport interface AdapterCreateContext {\n readonly evalId: string;\n readonly experimentId: string;\n readonly attempt: number;\n readonly signal: AbortSignal;\n readonly model?: string;\n readonly reasoningEffort?: string;\n readonly flags: Readonly<Record<string, JsonValue>>;\n progress(update: ProgressUpdate): void;\n diagnostic(input: DiagnosticInput): void;\n log(message: string): void;\n onCleanup(cleanup: () => void | Promise<void>): void;\n}\ntype EvalContextBase<Kind extends EvaluationKind> = JudgePresetMethods<Kind> & {\n readonly evaluationKind: Kind;\n readonly signal: AbortSignal;\n readonly model?: string;\n readonly reasoningEffort?: string;\n readonly flags: Readonly<Record<string, JsonValue>>;\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: AssertionsRuntime<Kind>[\"t\"][\"check\"];\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\"> = EvalContextBase<Kind> & (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> = AdapterEvalFields & {\n test(t: EvalContext<\"pass\"> & Readonly<Context>): void | Promise<void>;\n};\nexport type AdapterScoreEvalInput<Context extends object> = AdapterScoreEvalFields & {\n test(t: EvalContext<\"score\"> & Readonly<Context>): void | Promise<void>;\n};\ninterface AdapterContractToken<Context extends object> {\n readonly name: string;\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> extends EvalDefinition<Kind, EvalContext<Kind> & Readonly<Context>, undefined> {\n readonly [EVAL_ADAPTER_CONTRACT_TOKEN]: AdapterContractToken<Context>;\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> {\n readonly name: string;\n defineEval(input: AdapterEvalInput<Context>): AdapterEvalDefinition<\"pass\", Context>;\n defineScoreEval(input: AdapterScoreEvalInput<Context>): AdapterEvalDefinition<\"score\", Context>;\n}\n/** Existential runtime view used by Experiment without erasing a concrete context to `any`. */\nexport interface AdapterRuntimeDefinition {\n readonly kind: \"custom\";\n readonly name: string;\n readonly contract: string;\n readonly behaviorRevision: string | null;\n readonly [ADAPTER_CONTRACT_TOKEN]: object;\n readonly defineEval: (...args: never[]) => unknown;\n readonly defineScoreEval: (...args: never[]) => unknown;\n create(context: AdapterCreateContext): object | Promise<object>;\n}\nexport interface AdapterImplementation<Context extends object> extends AdapterDefinition<Context> {\n readonly kind: \"custom\";\n readonly contract: string;\n readonly behaviorRevision: string | null;\n readonly [ADAPTER_CONTRACT_TOKEN]: AdapterContractToken<Context>;\n create(context: AdapterCreateContext): Context | Promise<Context>;\n}\nexport type AdapterImplementationInput<Context extends object, ImplementationContext extends Context = Context> = {\n readonly name: string;\n readonly behaviorRevision?: string;\n readonly create: AdapterFactory<ImplementationContext>;\n} & AdapterContextValidation<NoInfer<ImplementationContext>>;\nexport interface AdapterContract<Context extends object> extends AdapterDefinition<Context> {\n readonly name: string;\n implement<ImplementationContext extends Context>(input: AdapterImplementationInput<Context, ImplementationContext>): AdapterImplementation<Context>;\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>(name: string): AdapterContractToken<Context> {\n return Object.freeze({ name, context: (value: Context) => value });\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>(token: AdapterContractToken<Context>): Pick<AdapterDefinition<Context>, \"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>;\n },\n defineScoreEval(input) {\n assertAdapterEvalInput(input, \"defineScoreEval\");\n return defineEvalForContext(\"score\", input, {\n [EVAL_ADAPTER_CONTRACT_TOKEN]: token,\n }) as AdapterEvalDefinition<\"score\", Context>;\n },\n };\n}\nfunction implementAdapter<Context extends object>(token: AdapterContractToken<Context>, input: {\n readonly name: string;\n readonly behaviorRevision?: string;\n readonly create: AdapterFactory<Context>;\n}, factory: \"defineAdapter\" | \"AdapterContract.implement\"): AdapterImplementation<Context> {\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 authorCreate = input.create;\n const create = (context: AdapterCreateContext): 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 name: input.name,\n contract: token.name,\n behaviorRevision: input.behaviorRevision ?? null,\n create,\n [ADAPTER_CONTRACT_TOKEN]: token,\n ...boundEvalFactories(token),\n }) as AdapterImplementation<Context>;\n}\n/** Defines one Adapter implementation with an automatically private contract. */\nexport function defineAdapter<Context extends object>(input: {\n readonly name: string;\n readonly behaviorRevision?: string;\n readonly create: AdapterFactory<Context>;\n} & AdapterContextValidation<NoInfer<Context>>): AdapterImplementation<Context>;\nexport function defineAdapter(input: {\n readonly name: string;\n readonly behaviorRevision?: string;\n readonly create: AdapterFactory<object>;\n}): AdapterRuntimeDefinition {\n return implementAdapter(contractToken<object>(input.name), input, \"defineAdapter\");\n}\n/** Defines a reusable contract whose implementations and Evals share one runtime-only token. */\nexport function defineAdapterContract<Context extends object>(input: {\n readonly name: string;\n} & AdapterContextValidation<NoInfer<Context>>): AdapterContract<Context> {\n assertNonEmptyString(input.name, \"name\", \"defineAdapterContract\");\n const token = contractToken<Context>(input.name);\n const factories = boundEvalFactories(token);\n return Object.freeze({\n name: input.name,\n ...factories,\n implement<ImplementationContext extends Context>(implementation: AdapterImplementationInput<Context, ImplementationContext>) {\n return implementAdapter(token, implementation, \"AdapterContract.implement\");\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 })\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]?: AdapterContractToken<object>;\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, guardMethods: boolean, assertAuthorOpen: () => void): void {\n for (const key of Reflect.ownKeys(source)) {\n const initial = Reflect.get(source, key, source);\n if (typeof initial === \"function\") {\n const method = guardMethods\n ? function (this: unknown, ...args: readonly unknown[]) {\n assertAuthorOpen();\n return Reflect.apply(initial, source, args);\n }\n : initial.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: () => Reflect.get(source, key, source),\n });\n }\n }\n}\n/** @internal Builds the frozen single-t facade after create settles. */\nexport function bindAdapterEvalContext<Kind extends EvaluationKind, Context>(core: EvalContext<Kind>, context: Context, assertAuthorOpen: () => void): EvalContext<Kind> & Readonly<Context> {\n assertPlainAdapterContext(context);\n const target = Object.create(null) as object;\n forwardProperties(target, core, false, assertAuthorOpen);\n forwardProperties(target, context, true, 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":";;AAgTA,sCAWC;AAED,sDAKC;AAkBD,0CAYC;AAED,gDASC;AAED,sEAMC;AAoKD,wDAmBC;AAxiBD,2CAAmD;AAOnD,MAAM,sBAAsB,GAAkB,MAAM,CAAC,+BAA+B,CAAC,CAAC;AACtF,MAAM,2BAA2B,GAAkB,MAAM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MAAM,KAAK,GAAG,qBAAqB,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,CAAC,UAAU,EAAE,gBAAgB,CAAC,CAAC;QACvF,GAAG,GAAG,KAAK,CAAC,GAAG,CAAC;QAChB,UAAU,GAAG,KAAK,CAAC,UAAU,CAAC;IAClC,CAAC;IACD,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 { 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, JsonValue, 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: Readonly<Context>;\n readonly check: AssertionCheck<\"polymorphic\">;\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 \"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> = (context: AdapterCreateContext) => (Context & ThisType<Context>) | Promise<Context & ThisType<Context>>;\nexport interface AdapterCleanupContext {\n /** 当前 Adapter cleanup 总窗口的取消信号。它独立于 Attempt signal,并在 30 秒总预算结束时取消。 */\n readonly signal: AbortSignal;\n}\nexport interface AdapterCreateContext {\n /** 当前 Eval 的公开 ID。 */\n readonly evalId: string;\n /** 当前 Experiment 的公开 ID。 */\n readonly experimentId: string;\n /** 当前 Attempt 的零起始序号。 */\n readonly attempt: number;\n /** Attempt 执行信号;取消或超时后会中止,不用于 cleanup 窗口。 */\n readonly signal: AbortSignal;\n /** Experiment 选择的模型。 */\n readonly model?: string;\n /** Experiment 选择的推理强度。 */\n readonly reasoningEffort?: string;\n /** Experiment 传给 Adapter 的只读 flags。 */\n readonly flags: Readonly<Record<string, JsonValue>>;\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> = JudgePresetMethods<Kind> & {\n readonly evaluationKind: Kind;\n readonly signal: AbortSignal;\n readonly model?: string;\n readonly reasoningEffort?: string;\n readonly flags: Readonly<Record<string, JsonValue>>;\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: AssertionsRuntime<Kind>[\"t\"][\"check\"];\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\"> = EvalContextBase<Kind> & (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> = AdapterEvalFields & {\n test(t: EvalContext<\"pass\"> & Readonly<Context> & AdapterAssertionsFor<Assertions, \"pass\">): void | Promise<void>;\n};\nexport type AdapterScoreEvalInput<Context extends object, Assertions extends object | undefined = undefined> = AdapterScoreEvalFields & {\n test(t: EvalContext<\"score\"> & Readonly<Context> & AdapterAssertionsFor<Assertions, \"score\">): void | Promise<void>;\n};\ninterface AdapterContractToken<Context extends object, Assertions extends object | undefined> {\n readonly name: string;\n readonly assertions: AdapterAssertionsFactory<Context> | undefined;\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> extends EvalDefinition<Kind, EvalContext<Kind> & Readonly<Context> & AdapterAssertionsFor<Assertions, Kind>, undefined> {\n readonly [EVAL_ADAPTER_CONTRACT_TOKEN]: AdapterContractToken<Context, Assertions>;\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> {\n readonly name: string;\n defineEval(input: AdapterEvalInput<Context, Assertions>): AdapterEvalDefinition<\"pass\", Context, Assertions>;\n defineScoreEval(input: AdapterScoreEvalInput<Context, Assertions>): AdapterEvalDefinition<\"score\", Context, Assertions>;\n}\n/** Existential runtime view used by Experiment without erasing a concrete context to `any`. */\nexport interface AdapterRuntimeDefinition {\n readonly kind: \"custom\";\n readonly name: string;\n readonly contract: string;\n readonly behaviorRevision: string | null;\n readonly [ADAPTER_CONTRACT_TOKEN]: object;\n readonly defineEval: (...args: never[]) => unknown;\n readonly defineScoreEval: (...args: never[]) => unknown;\n create(context: AdapterCreateContext): object | Promise<object>;\n}\nexport interface AdapterImplementation<Context extends object, Assertions extends object | undefined = undefined> extends AdapterDefinition<Context, Assertions> {\n readonly kind: \"custom\";\n readonly contract: string;\n readonly behaviorRevision: string | null;\n readonly [ADAPTER_CONTRACT_TOKEN]: AdapterContractToken<Context, Assertions>;\n create(context: AdapterCreateContext): Context | Promise<Context>;\n}\nexport type AdapterImplementationInput<Context extends object, ImplementationContext extends Context = Context> = {\n readonly name: string;\n readonly behaviorRevision?: string;\n readonly create: AdapterFactory<ImplementationContext>;\n} & AdapterContextValidation<NoInfer<ImplementationContext>>;\nexport interface AdapterContract<Context extends object, Assertions extends object | undefined = undefined> extends AdapterDefinition<Context, Assertions> {\n readonly name: string;\n implement<ImplementationContext extends Context>(input: AdapterImplementationInput<Context, ImplementationContext>): AdapterImplementation<Context, Assertions>;\n /**\n * Returns a contract whose Eval factories and every implementation share\n * this exact Assertion factory. Implementations cannot replace it.\n */\n withAssertions<NextAssertions extends object>(factory: AdapterAssertionsFactory<Context, NextAssertions>, ...validation: AdapterAssertionsValidationArgs<Context, NoInfer<NextAssertions>>): AdapterContract<Context, NextAssertions>;\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>(name: string, assertions: AdapterAssertionsFactory<Context> | undefined): AdapterContractToken<Context, Assertions> {\n return Object.freeze({\n name,\n assertions,\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>(token: AdapterContractToken<Context, Assertions>): Pick<AdapterDefinition<Context, Assertions>, \"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>;\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>;\n },\n };\n}\nfunction implementAdapter<Context extends object, Assertions extends object | undefined>(token: AdapterContractToken<Context, Assertions>, input: {\n readonly name: string;\n readonly behaviorRevision?: string;\n readonly create: AdapterFactory<Context>;\n}, factory: \"defineAdapter\" | \"AdapterContract.implement\"): AdapterImplementation<Context, Assertions> {\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 authorCreate = input.create;\n const create = (context: AdapterCreateContext): 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 name: input.name,\n contract: token.name,\n behaviorRevision: input.behaviorRevision ?? null,\n create,\n [ADAPTER_CONTRACT_TOKEN]: token,\n ...boundEvalFactories(token),\n }) as AdapterImplementation<Context, Assertions>;\n}\n/** Defines one Adapter implementation with an automatically private contract. */\nexport function defineAdapter<Context extends object>(input: {\n readonly name: string;\n readonly behaviorRevision?: string;\n readonly create: AdapterFactory<Context>;\n readonly assertions?: undefined;\n} & AdapterContextValidation<NoInfer<Context>>): AdapterImplementation<Context>;\nexport function defineAdapter<Context extends object, Assertions extends object>(input: {\n readonly name: string;\n readonly behaviorRevision?: string;\n readonly create: AdapterFactory<Context>;\n /** Attempt-local Assertion sugar, assembled once after create() succeeds. */\n readonly assertions: AdapterAssertionsFactory<Context, Assertions>;\n} & AdapterContextValidation<NoInfer<Context>> & AdapterAssertionsValidation<Context, NoInfer<Assertions>>): AdapterImplementation<Context, Assertions>;\nexport function defineAdapter(input: {\n readonly name: string;\n readonly behaviorRevision?: string;\n readonly create: AdapterFactory<object>;\n readonly assertions?: AdapterAssertionsFactory<object>;\n}): AdapterRuntimeDefinition {\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>(input.name, assertions), input, \"defineAdapter\");\n}\n/** Defines a reusable contract whose implementations and Evals share one runtime-only token. */\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>(input.name, undefined));\n}\nfunction makeAdapterContract<Context extends object, Assertions extends object | undefined>(token: AdapterContractToken<Context, Assertions>): AdapterContract<Context, Assertions> {\n const factories = boundEvalFactories(token);\n return Object.freeze({\n name: token.name,\n ...factories,\n implement<ImplementationContext extends Context>(implementation: AdapterImplementationInput<Context, ImplementationContext>) {\n return implementAdapter(token, implementation, \"AdapterContract.implement\");\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>(token.name, factory));\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 })\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({\n app,\n check: check as AssertionCheck<\"polymorphic\">,\n });\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. */\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 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,4 +1,4 @@
1
- import type { AssertionSubject, AssertionsRuntime, MeasurementAssertionHandle } from "./assertions/api.cjs";
1
+ import type { AssertionCheck, AssertionSubject, AssertionsRuntime, BooleanAssertionHandle, MeasurementAssertionHandle, PolymorphicBooleanAssertionHandle, PolymorphicMeasurementAssertionHandle } from "./assertions/api.cjs";
2
2
  import type { ScoreMatch } from "./assertions/match.cjs";
3
3
  import type { EvalDefinition, EvalInput, ScoreEvalInput } from "./runner/types.cjs";
4
4
  import type { EvaluationKind } from "./shared/evaluation.cjs";
@@ -8,6 +8,27 @@ import type { AdapterIdentity } from "./record/model/run-context.cjs";
8
8
  export type { AdapterIdentity } from "./record/model/run-context.cjs";
9
9
  declare const ADAPTER_CONTRACT_TOKEN: unique symbol;
10
10
  declare const EVAL_ADAPTER_CONTRACT_TOKEN: unique symbol;
11
+ /**
12
+ * Synchronously assembles Attempt-local Assertion methods from the guarded app
13
+ * facade and the shared check registrar. The returned object must contain only
14
+ * ordinary, synchronously returning methods. Generic and overloaded Assertion
15
+ * sugar is intentionally not callable after binding; use ordinary named
16
+ * parameters so argument and native handle types remain exact.
17
+ */
18
+ export type AdapterAssertionsFactory<Context extends object, Assertions extends object = object> = (context: AdapterAssertionsFactoryContext<Context>) => Assertions;
19
+ /**
20
+ * Definition inputs for Adapter Assertion sugar. `app` becomes callable after
21
+ * assembly, and `check` may only be called by a returned Assertion method.
22
+ */
23
+ export interface AdapterAssertionsFactoryContext<Context extends object> {
24
+ readonly app: Readonly<Context>;
25
+ readonly check: AssertionCheck<"polymorphic">;
26
+ }
27
+ type 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;
28
+ type BoundAdapterAssertionMethod<Kind extends EvaluationKind, Method> = Method extends (...args: infer Args) => infer Result ? ((...args: Args) => Result) extends Method ? (...args: Args) => BoundAdapterAssertionResult<Kind, Result> : never : never;
29
+ type AdapterAssertionsFor<Assertions extends object | undefined, Kind extends EvaluationKind> = Assertions extends object ? {
30
+ readonly [Key in keyof Assertions]: BoundAdapterAssertionMethod<Kind, Assertions[Key]>;
31
+ } : {};
11
32
  /** Keys owned by the neutral Eval runtime or unsafe on a merged object root. */
12
33
  declare const RESERVED_ADAPTER_CONTEXT_KEYS: readonly ["evaluationKind", "check", "judge", "factuality", "faithfulness", "instructionFollowing", "pairwisePreference", "closeQA", "score", "group", "skip", "signal", "model", "reasoningEffort", "flags", "progress", "diagnostic", "log", "then", "Object", "constructor", "__defineGetter__", "__defineSetter__", "hasOwnProperty", "__lookupGetter__", "__lookupSetter__", "isPrototypeOf", "propertyIsEnumerable", "toString", "valueOf", "__proto__", "toLocaleString"];
13
34
  export type ReservedAdapterContextKey = typeof RESERVED_ADAPTER_CONTEXT_KEYS[number];
@@ -15,19 +36,47 @@ type InvalidContextBranch<Context> = Context extends unknown ? Context extends o
15
36
  type AdapterContextValidation<Context> = unknown extends Context ? unknown : [InvalidContextBranch<Context>] extends [never] ? unknown : {
16
37
  readonly invalidAdapterContext: InvalidContextBranch<Context>;
17
38
  };
39
+ type InvalidAssertionMethodKey<Context extends object, Assertions> = Assertions extends object ? {
40
+ [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;
41
+ }[keyof Assertions] : "assertions";
42
+ type InvalidAdapterAssertions<Context extends object, Assertions extends object> = InvalidAssertionMethodKey<Context, Assertions>;
43
+ type AdapterAssertionsValidation<Context extends object, Assertions extends object> = [InvalidAdapterAssertions<Context, Assertions>] extends [never] ? unknown : {
44
+ readonly invalidAdapterAssertions: InvalidAdapterAssertions<Context, Assertions>;
45
+ };
46
+ type AdapterAssertionsValidationArgs<Context extends object, Assertions extends object> = [InvalidAdapterAssertions<Context, Assertions>] extends [never] ? [] : [error: {
47
+ readonly invalidAdapterAssertions: InvalidAdapterAssertions<Context, Assertions>;
48
+ }];
18
49
  type AdapterFactory<Context extends object> = (context: AdapterCreateContext) => (Context & ThisType<Context>) | Promise<Context & ThisType<Context>>;
50
+ export interface AdapterCleanupContext {
51
+ /** 当前 Adapter cleanup 总窗口的取消信号。它独立于 Attempt signal,并在 30 秒总预算结束时取消。 */
52
+ readonly signal: AbortSignal;
53
+ }
19
54
  export interface AdapterCreateContext {
55
+ /** 当前 Eval 的公开 ID。 */
20
56
  readonly evalId: string;
57
+ /** 当前 Experiment 的公开 ID。 */
21
58
  readonly experimentId: string;
59
+ /** 当前 Attempt 的零起始序号。 */
22
60
  readonly attempt: number;
61
+ /** Attempt 执行信号;取消或超时后会中止,不用于 cleanup 窗口。 */
23
62
  readonly signal: AbortSignal;
63
+ /** Experiment 选择的模型。 */
24
64
  readonly model?: string;
65
+ /** Experiment 选择的推理强度。 */
25
66
  readonly reasoningEffort?: string;
67
+ /** Experiment 传给 Adapter 的只读 flags。 */
26
68
  readonly flags: Readonly<Record<string, JsonValue>>;
69
+ /** 更新当前 Attempt 的人读进度。 */
27
70
  progress(update: ProgressUpdate): void;
71
+ /** 为当前 Attempt 追加结构化诊断。 */
28
72
  diagnostic(input: DiagnosticInput): void;
73
+ /** 为当前 Attempt 追加日志。 */
29
74
  log(message: string): void;
30
- onCleanup(cleanup: () => void | Promise<void>): void;
75
+ /**
76
+ * 登记 Attempt-local 资源释放。回调按全局 LIFO 执行;一项失败不会跳过其余项。
77
+ * 零参数回调仍可直接传入。传入的 context 已冻结,同一 cleanup 窗口的回调共享一个 signal。
78
+ */
79
+ onCleanup(cleanup: (context: AdapterCleanupContext) => void | Promise<void>): void;
31
80
  }
32
81
  type EvalContextBase<Kind extends EvaluationKind> = JudgePresetMethods<Kind> & {
33
82
  readonly evaluationKind: Kind;
@@ -55,29 +104,32 @@ type AdapterScoreEvalFields = Omit<ScoreEvalInput<undefined>, "test" | "sandbox"
55
104
  readonly sandbox?: never;
56
105
  readonly diff?: never;
57
106
  };
58
- export type AdapterEvalInput<Context extends object> = AdapterEvalFields & {
59
- test(t: EvalContext<"pass"> & Readonly<Context>): void | Promise<void>;
107
+ export type AdapterEvalInput<Context extends object, Assertions extends object | undefined = undefined> = AdapterEvalFields & {
108
+ test(t: EvalContext<"pass"> & Readonly<Context> & AdapterAssertionsFor<Assertions, "pass">): void | Promise<void>;
60
109
  };
61
- export type AdapterScoreEvalInput<Context extends object> = AdapterScoreEvalFields & {
62
- test(t: EvalContext<"score"> & Readonly<Context>): void | Promise<void>;
110
+ export type AdapterScoreEvalInput<Context extends object, Assertions extends object | undefined = undefined> = AdapterScoreEvalFields & {
111
+ test(t: EvalContext<"score"> & Readonly<Context> & AdapterAssertionsFor<Assertions, "score">): void | Promise<void>;
63
112
  };
64
- interface AdapterContractToken<Context extends object> {
113
+ interface AdapterContractToken<Context extends object, Assertions extends object | undefined> {
65
114
  readonly name: string;
115
+ readonly assertions: AdapterAssertionsFactory<Context> | undefined;
116
+ /** Keeps the Assertion method shape invariant without exposing a constructible brand. */
117
+ readonly assertionTypes: (value: Assertions) => Assertions;
66
118
  /** Keeps the context parameter invariant without exposing a constructible brand. */
67
119
  readonly context: (value: Context) => Context;
68
120
  }
69
- export interface AdapterEvalDefinition<Kind extends EvaluationKind, Context extends object> extends EvalDefinition<Kind, EvalContext<Kind> & Readonly<Context>, undefined> {
70
- readonly [EVAL_ADAPTER_CONTRACT_TOKEN]: AdapterContractToken<Context>;
121
+ export interface AdapterEvalDefinition<Kind extends EvaluationKind, Context extends object, Assertions extends object | undefined = undefined> extends EvalDefinition<Kind, EvalContext<Kind> & Readonly<Context> & AdapterAssertionsFor<Assertions, Kind>, undefined> {
122
+ readonly [EVAL_ADAPTER_CONTRACT_TOKEN]: AdapterContractToken<Context, Assertions>;
71
123
  }
72
124
  /** @internal Existential discovery view; concrete bound factories retain their exact Context. */
73
125
  export interface AdapterRuntimeEvalDefinition<Kind extends EvaluationKind> extends EvalDefinition<Kind, never, undefined> {
74
126
  readonly [EVAL_ADAPTER_CONTRACT_TOKEN]: object;
75
127
  }
76
128
  /** Common public surface for an Adapter definition with bound Eval factories. */
77
- export interface AdapterDefinition<Context extends object> {
129
+ export interface AdapterDefinition<Context extends object, Assertions extends object | undefined = undefined> {
78
130
  readonly name: string;
79
- defineEval(input: AdapterEvalInput<Context>): AdapterEvalDefinition<"pass", Context>;
80
- defineScoreEval(input: AdapterScoreEvalInput<Context>): AdapterEvalDefinition<"score", Context>;
131
+ defineEval(input: AdapterEvalInput<Context, Assertions>): AdapterEvalDefinition<"pass", Context, Assertions>;
132
+ defineScoreEval(input: AdapterScoreEvalInput<Context, Assertions>): AdapterEvalDefinition<"score", Context, Assertions>;
81
133
  }
82
134
  /** Existential runtime view used by Experiment without erasing a concrete context to `any`. */
83
135
  export interface AdapterRuntimeDefinition {
@@ -90,11 +142,11 @@ export interface AdapterRuntimeDefinition {
90
142
  readonly defineScoreEval: (...args: never[]) => unknown;
91
143
  create(context: AdapterCreateContext): object | Promise<object>;
92
144
  }
93
- export interface AdapterImplementation<Context extends object> extends AdapterDefinition<Context> {
145
+ export interface AdapterImplementation<Context extends object, Assertions extends object | undefined = undefined> extends AdapterDefinition<Context, Assertions> {
94
146
  readonly kind: "custom";
95
147
  readonly contract: string;
96
148
  readonly behaviorRevision: string | null;
97
- readonly [ADAPTER_CONTRACT_TOKEN]: AdapterContractToken<Context>;
149
+ readonly [ADAPTER_CONTRACT_TOKEN]: AdapterContractToken<Context, Assertions>;
98
150
  create(context: AdapterCreateContext): Context | Promise<Context>;
99
151
  }
100
152
  export type AdapterImplementationInput<Context extends object, ImplementationContext extends Context = Context> = {
@@ -102,9 +154,14 @@ export type AdapterImplementationInput<Context extends object, ImplementationCon
102
154
  readonly behaviorRevision?: string;
103
155
  readonly create: AdapterFactory<ImplementationContext>;
104
156
  } & AdapterContextValidation<NoInfer<ImplementationContext>>;
105
- export interface AdapterContract<Context extends object> extends AdapterDefinition<Context> {
157
+ export interface AdapterContract<Context extends object, Assertions extends object | undefined = undefined> extends AdapterDefinition<Context, Assertions> {
106
158
  readonly name: string;
107
- implement<ImplementationContext extends Context>(input: AdapterImplementationInput<Context, ImplementationContext>): AdapterImplementation<Context>;
159
+ implement<ImplementationContext extends Context>(input: AdapterImplementationInput<Context, ImplementationContext>): AdapterImplementation<Context, Assertions>;
160
+ /**
161
+ * Returns a contract whose Eval factories and every implementation share
162
+ * this exact Assertion factory. Implementations cannot replace it.
163
+ */
164
+ withAssertions<NextAssertions extends object>(factory: AdapterAssertionsFactory<Context, NextAssertions>, ...validation: AdapterAssertionsValidationArgs<Context, NoInfer<NextAssertions>>): AdapterContract<Context, NextAssertions>;
108
165
  }
109
166
  export type Adapter = import("./agents/types.cjs").Agent | AdapterRuntimeDefinition;
110
167
  /** Defines one Adapter implementation with an automatically private contract. */
@@ -112,7 +169,15 @@ export declare function defineAdapter<Context extends object>(input: {
112
169
  readonly name: string;
113
170
  readonly behaviorRevision?: string;
114
171
  readonly create: AdapterFactory<Context>;
172
+ readonly assertions?: undefined;
115
173
  } & AdapterContextValidation<NoInfer<Context>>): AdapterImplementation<Context>;
174
+ export declare function defineAdapter<Context extends object, Assertions extends object>(input: {
175
+ readonly name: string;
176
+ readonly behaviorRevision?: string;
177
+ readonly create: AdapterFactory<Context>;
178
+ /** Attempt-local Assertion sugar, assembled once after create() succeeds. */
179
+ readonly assertions: AdapterAssertionsFactory<Context, Assertions>;
180
+ } & AdapterContextValidation<NoInfer<Context>> & AdapterAssertionsValidation<Context, NoInfer<Assertions>>): AdapterImplementation<Context, Assertions>;
116
181
  /** Defines a reusable contract whose implementations and Evals share one runtime-only token. */
117
182
  export declare function defineAdapterContract<Context extends object>(input: {
118
183
  readonly name: string;
@@ -124,4 +189,4 @@ export declare function adapterAcceptsEval(adapter: Adapter, definition: object)
124
189
  /** @internal Returns the readable contract name without revealing the pairing token. */
125
190
  export declare function adapterContractRequiredByEval(definition: object): string | undefined;
126
191
  /** @internal Builds the frozen single-t facade after create settles. */
127
- export declare function bindAdapterEvalContext<Kind extends EvaluationKind, Context>(core: EvalContext<Kind>, context: Context, assertAuthorOpen: () => void): EvalContext<Kind> & Readonly<Context>;
192
+ export declare function bindAdapterEvalContext<Kind extends EvaluationKind, Context>(core: EvalContext<Kind>, context: Context, adapter: AdapterRuntimeDefinition, assertAuthorOpen: () => void): EvalContext<Kind> & Readonly<Context>;