@arnilo/prism-hosts 0.0.0-stage → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +394 -0
- package/LICENSE +21 -0
- package/README.md +34 -2
- package/acp/README.md +87 -0
- package/acp/src/capabilities.ts +184 -0
- package/acp/src/errors.ts +24 -0
- package/acp/src/host.ts +36 -0
- package/acp/src/index.ts +25 -0
- package/acp/src/limits.ts +49 -0
- package/acp/src/mapper.ts +419 -0
- package/acp/src/permission.ts +37 -0
- package/acp/src/projection.ts +39 -0
- package/acp/src/prompt.ts +170 -0
- package/acp/src/serve.ts +345 -0
- package/acp/src/session-map.ts +49 -0
- package/ag-ui/README.md +56 -0
- package/ag-ui/src/a2ui.ts +570 -0
- package/ag-ui/src/ag-ui-mapper.ts +507 -0
- package/ag-ui/src/encrypted-value.ts +40 -0
- package/ag-ui/src/errors.ts +29 -0
- package/ag-ui/src/handler.ts +642 -0
- package/ag-ui/src/index.ts +177 -0
- package/ag-ui/src/input.ts +190 -0
- package/ag-ui/src/limits.ts +279 -0
- package/ag-ui/src/mcp-apps.ts +256 -0
- package/ag-ui/src/mcp.ts +94 -0
- package/ag-ui/src/projection.ts +201 -0
- package/ag-ui/src/projectors.ts +272 -0
- package/ag-ui/src/renderer/bind.ts +152 -0
- package/ag-ui/src/renderer/core.ts +270 -0
- package/ag-ui/src/renderer/index.ts +165 -0
- package/ag-ui/src/replay.ts +189 -0
- package/ag-ui/src/types.ts +66 -0
- package/channels/README.md +139 -0
- package/channels/src/admission.ts +8 -0
- package/channels/src/approvals.ts +262 -0
- package/channels/src/checkpoint-contract.ts +97 -0
- package/channels/src/delivery.ts +116 -0
- package/channels/src/host-ui.ts +356 -0
- package/channels/src/identity.ts +46 -0
- package/channels/src/index.ts +82 -0
- package/channels/src/limits.ts +49 -0
- package/channels/src/memory-stores.ts +112 -0
- package/channels/src/pairing.ts +178 -0
- package/channels/src/runtime-admit.ts +389 -0
- package/channels/src/runtime-core.ts +621 -0
- package/channels/src/runtime-reconcile.ts +299 -0
- package/channels/src/runtime-turn.ts +664 -0
- package/channels/src/runtime-types.ts +95 -0
- package/channels/src/runtime.ts +86 -0
- package/channels/src/secret-ref.ts +42 -0
- package/channels/src/signal.ts +790 -0
- package/channels/src/state.ts +355 -0
- package/channels/src/telegram.ts +1317 -0
- package/channels/src/types.ts +442 -0
- package/devtools/README.md +92 -0
- package/devtools/bin/prism-devtools.ts +63 -0
- package/devtools/src/args.ts +71 -0
- package/devtools/src/bun.d.ts +27 -0
- package/devtools/src/compare.ts +190 -0
- package/devtools/src/errors.ts +15 -0
- package/devtools/src/index.ts +25 -0
- package/devtools/src/replay.ts +36 -0
- package/devtools/src/security.ts +80 -0
- package/devtools/src/serve.ts +259 -0
- package/devtools/src/ui/assets.ts +108 -0
- package/devtools/src/ui/inspector.ts +182 -0
- package/driver-process/README.md +197 -0
- package/driver-process/src/abort.ts +74 -0
- package/driver-process/src/adapter.ts +211 -0
- package/driver-process/src/driver.ts +303 -0
- package/driver-process/src/errors.ts +17 -0
- package/driver-process/src/extend.ts +72 -0
- package/driver-process/src/index.ts +5 -0
- package/driver-process/src/inspect.ts +33 -0
- package/driver-process/src/session.ts +72 -0
- package/driver-process/src/testing.ts +394 -0
- package/driver-process/src/transports/json-rpc.ts +147 -0
- package/driver-process/src/transports/jsonl-stream.ts +12 -0
- package/driver-process/src/transports/types.ts +11 -0
- package/driver-process/src/turn.ts +106 -0
- package/evals/README.md +843 -0
- package/evals/src/calibration.ts +179 -0
- package/evals/src/citation-integrity.ts +98 -0
- package/evals/src/citations.ts +45 -0
- package/evals/src/compare-experiments.ts +153 -0
- package/evals/src/comparison.ts +230 -0
- package/evals/src/curate.ts +257 -0
- package/evals/src/dataset.ts +81 -0
- package/evals/src/erp-invariants.ts +163 -0
- package/evals/src/errors.ts +23 -0
- package/evals/src/experiment.ts +537 -0
- package/evals/src/failure-injection.ts +77 -0
- package/evals/src/feedback.ts +53 -0
- package/evals/src/index.ts +198 -0
- package/evals/src/injection.ts +247 -0
- package/evals/src/judge-panel.ts +109 -0
- package/evals/src/judge.ts +89 -0
- package/evals/src/limits.ts +50 -0
- package/evals/src/report-record.ts +47 -0
- package/evals/src/rubric-judge.ts +334 -0
- package/evals/src/scenario-runner.ts +317 -0
- package/evals/src/scenarios.ts +81 -0
- package/evals/src/score.ts +328 -0
- package/evals/src/scorer.ts +21 -0
- package/evals/src/state-match.ts +130 -0
- package/evals/src/stats.ts +635 -0
- package/evals/src/threshold.ts +117 -0
- package/evals/src/timeline.ts +38 -0
- package/evals/src/toolless-session.ts +33 -0
- package/evals/src/trace.ts +80 -0
- package/evals/src/trajectory.ts +623 -0
- package/evals/src/types.ts +672 -0
- package/evals/src/user-simulator.ts +101 -0
- package/evals/src/util.ts +207 -0
- package/headless/README.md +172 -0
- package/headless/src/answers.ts +91 -0
- package/headless/src/authority.ts +32 -0
- package/headless/src/errors.ts +36 -0
- package/headless/src/index.ts +17 -0
- package/headless/src/limits.ts +11 -0
- package/headless/src/pending.ts +16 -0
- package/headless/src/policy.ts +36 -0
- package/headless/src/resume.ts +103 -0
- package/headless/src/route.ts +153 -0
- package/headless/src/scheduler/clock.ts +22 -0
- package/headless/src/scheduler/cron.ts +19 -0
- package/headless/src/scheduler/firing.ts +58 -0
- package/headless/src/scheduler/index.ts +399 -0
- package/headless/src/scheduler/lease.ts +38 -0
- package/headless/src/scheduler/missed.ts +12 -0
- package/headless/src/scheduler/state.ts +132 -0
- package/host-builder/README.md +251 -0
- package/host-builder/bin/prism-host-builder.ts +169 -0
- package/host-builder/data/api.json +6167 -0
- package/host-builder/data/errors.json +546 -0
- package/host-builder/data/examples/acp.ts +63 -0
- package/host-builder/data/examples/adapters/conformance.ts +34 -0
- package/host-builder/data/examples/adapters/fixtures/rpc-server.json +26 -0
- package/host-builder/data/examples/adapters/fixtures/stream-cli.json +27 -0
- package/host-builder/data/examples/adapters/fixtures/workspace-config.json +28 -0
- package/host-builder/data/examples/adapters/rpc-server.dialect.ts +218 -0
- package/host-builder/data/examples/adapters/rpc-server.ts +309 -0
- package/host-builder/data/examples/adapters/stream-cli.dialect.ts +165 -0
- package/host-builder/data/examples/adapters/stream-cli.ts +256 -0
- package/host-builder/data/examples/adapters/workspace-config.dialect.ts +172 -0
- package/host-builder/data/examples/adapters/workspace-config.ts +251 -0
- package/host-builder/data/examples/advisor.ts +94 -0
- package/host-builder/data/examples/ag-ui-a2ui.ts +80 -0
- package/host-builder/data/examples/ag-ui-mcp-apps.ts +44 -0
- package/host-builder/data/examples/ag-ui-server.ts +118 -0
- package/host-builder/data/examples/agent-durable-approval.ts +43 -0
- package/host-builder/data/examples/api-key-auth.ts +23 -0
- package/host-builder/data/examples/approval.ts +92 -0
- package/host-builder/data/examples/attention-compiler.ts +81 -0
- package/host-builder/data/examples/autonomous-coding-loop.ts +343 -0
- package/host-builder/data/examples/behavior-evaluation.ts +303 -0
- package/host-builder/data/examples/build-workflow.ts +334 -0
- package/host-builder/data/examples/cache-aware-prompt-assembly.ts +139 -0
- package/host-builder/data/examples/caveman-ponytail.ts +197 -0
- package/host-builder/data/examples/cli.ts +31 -0
- package/host-builder/data/examples/coding-approval.ts +115 -0
- package/host-builder/data/examples/coding-browser-evaluation.ts +208 -0
- package/host-builder/data/examples/coding-compaction.ts +30 -0
- package/host-builder/data/examples/coding-goal-verify.ts +121 -0
- package/host-builder/data/examples/coding-tools-capability-gaps.ts +75 -0
- package/host-builder/data/examples/compaction.ts +36 -0
- package/host-builder/data/examples/connected-slack-mcp.ts +67 -0
- package/host-builder/data/examples/context.ts +29 -0
- package/host-builder/data/examples/custom-adapter.ts +256 -0
- package/host-builder/data/examples/custom-builders.ts +66 -0
- package/host-builder/data/examples/custom-loop.ts +89 -0
- package/host-builder/data/examples/custom-provider.ts +70 -0
- package/host-builder/data/examples/custom-session-store.ts +72 -0
- package/host-builder/data/examples/custom-tools-skills-context.ts +97 -0
- package/host-builder/data/examples/decision-models.ts +98 -0
- package/host-builder/data/examples/define-package.ts +188 -0
- package/host-builder/data/examples/delegate.ts +200 -0
- package/host-builder/data/examples/discover-skills.ts +65 -0
- package/host-builder/data/examples/drive-rag-sync.ts +44 -0
- package/host-builder/data/examples/durable-approval.ts +139 -0
- package/host-builder/data/examples/durable-investigation.ts +93 -0
- package/host-builder/data/examples/durable-loops-and-approvals.ts +94 -0
- package/host-builder/data/examples/enterprise-identity.ts +21 -0
- package/host-builder/data/examples/enterprise-policy-audit.ts +50 -0
- package/host-builder/data/examples/enterprise-work-connectors.ts +103 -0
- package/host-builder/data/examples/eval-injection.ts +73 -0
- package/host-builder/data/examples/eval-judges.ts +145 -0
- package/host-builder/data/examples/evals.ts +86 -0
- package/host-builder/data/examples/evaluation-gate.ts +40 -0
- package/host-builder/data/examples/execution-timeline.ts +173 -0
- package/host-builder/data/examples/external-agent.ts +541 -0
- package/host-builder/data/examples/external-app-db-backed.ts +344 -0
- package/host-builder/data/examples/governance-deny.ts +122 -0
- package/host-builder/data/examples/guardrail-packs.ts +240 -0
- package/host-builder/data/examples/headless-host.ts +245 -0
- package/host-builder/data/examples/hooks-audit-command.mjs +31 -0
- package/host-builder/data/examples/hooks-json.ts +87 -0
- package/host-builder/data/examples/host-builder-agent.ts +150 -0
- package/host-builder/data/examples/host-hooks.ts +71 -0
- package/host-builder/data/examples/host-step-loop-timeline.ts +212 -0
- package/host-builder/data/examples/hosted-sandbox.ts +48 -0
- package/host-builder/data/examples/instruction-injection.ts +127 -0
- package/host-builder/data/examples/jsonl-stores-branching.ts +49 -0
- package/host-builder/data/examples/long-term-memory.ts +158 -0
- package/host-builder/data/examples/manifest.ts +112 -0
- package/host-builder/data/examples/mcp-server.ts +48 -0
- package/host-builder/data/examples/mcp-trust.ts +173 -0
- package/host-builder/data/examples/memory-and-wiki.ts +315 -0
- package/host-builder/data/examples/memory-lifecycle.ts +302 -0
- package/host-builder/data/examples/memory-system.ts +252 -0
- package/host-builder/data/examples/messaging-agent.ts +70 -0
- package/host-builder/data/examples/minimal-host-app.ts +41 -0
- package/host-builder/data/examples/model-router-aggregate-budgets.ts +364 -0
- package/host-builder/data/examples/model-router.ts +106 -0
- package/host-builder/data/examples/obscura.ts +48 -0
- package/host-builder/data/examples/observability.ts +116 -0
- package/host-builder/data/examples/open-connector-sidecar.ts +105 -0
- package/host-builder/data/examples/openai-compatible.ts +70 -0
- package/host-builder/data/examples/package-skills.ts +85 -0
- package/host-builder/data/examples/phase9-coding-intelligence.ts +221 -0
- package/host-builder/data/examples/provider-registration.ts +29 -0
- package/host-builder/data/examples/provider-resolver.ts +39 -0
- package/host-builder/data/examples/rag.ts +40 -0
- package/host-builder/data/examples/remote-agent-server.ts +45 -0
- package/host-builder/data/examples/remote-agent.ts +124 -0
- package/host-builder/data/examples/research-ledger.ts +79 -0
- package/host-builder/data/examples/revocation-propagation.ts +287 -0
- package/host-builder/data/examples/run-feedback.ts +93 -0
- package/host-builder/data/examples/scanned-document-rag.ts +48 -0
- package/host-builder/data/examples/sdk-basics.ts +21 -0
- package/host-builder/data/examples/secure-agent.ts +55 -0
- package/host-builder/data/examples/semantic-memory.ts +52 -0
- package/host-builder/data/examples/serve-tools.ts +495 -0
- package/host-builder/data/examples/session-memory.ts +317 -0
- package/host-builder/data/examples/session-search.ts +131 -0
- package/host-builder/data/examples/session.ts +52 -0
- package/host-builder/data/examples/side-call.ts +64 -0
- package/host-builder/data/examples/signal-agent.ts +9 -0
- package/host-builder/data/examples/skills-progressive-disclosure.ts +88 -0
- package/host-builder/data/examples/skills.ts +19 -0
- package/host-builder/data/examples/sqlite-resume.ts +147 -0
- package/host-builder/data/examples/system-project-prompts.ts +74 -0
- package/host-builder/data/examples/system-prompts.ts +19 -0
- package/host-builder/data/examples/telegram-agent.ts +30 -0
- package/host-builder/data/examples/tool-narrowing-planes.ts +99 -0
- package/host-builder/data/examples/tools.ts +29 -0
- package/host-builder/data/examples/validator.ts +67 -0
- package/host-builder/data/examples/web-no-key.ts +85 -0
- package/host-builder/data/examples/web-research.ts +35 -0
- package/host-builder/data/examples/workflow-event-sink.ts +114 -0
- package/host-builder/data/examples/workflow-loop.ts +93 -0
- package/host-builder/data/examples/workflow-multimodal-document.ts +94 -0
- package/host-builder/data/examples/workflow-parallel-research.ts +111 -0
- package/host-builder/data/examples/workflow-postgres-resume.ts +75 -0
- package/host-builder/data/examples/workflow-research-and-review.ts +98 -0
- package/host-builder/data/examples/workflow-sqlite-resume.ts +163 -0
- package/host-builder/data/examples.json +130 -0
- package/host-builder/skills/prism-host-builder/SKILL.md +85 -0
- package/host-builder/skills/prism-host-builder/references/choosing.md +101 -0
- package/host-builder/skills/prism-host-builder/references/layout.md +52 -0
- package/host-builder/skills/prism-host-builder/references/pitfalls.md +50 -0
- package/host-builder/skills/prism-host-builder/references/recipes.md +129 -0
- package/host-builder/skills/prism-host-builder/references/security.md +52 -0
- package/host-builder/skills/prism-host-builder/references/upgrading.md +67 -0
- package/host-builder/skills/prism-host-builder/references/verification.md +108 -0
- package/host-builder/src/check/child.ts +108 -0
- package/host-builder/src/check/conformance.ts +13 -0
- package/host-builder/src/check/inspect.ts +20 -0
- package/host-builder/src/check/manifest.ts +23 -0
- package/host-builder/src/check/runner.ts +181 -0
- package/host-builder/src/check/targets.ts +65 -0
- package/host-builder/src/errors.ts +35 -0
- package/host-builder/src/index.ts +25 -0
- package/host-builder/src/indexes.ts +145 -0
- package/host-builder/src/install/install.ts +400 -0
- package/host-builder/src/install/targets.ts +50 -0
- package/host-builder/src/lookup/api.ts +127 -0
- package/host-builder/src/lookup/bound.ts +38 -0
- package/host-builder/src/lookup/docs.ts +238 -0
- package/host-builder/src/lookup/errors.ts +92 -0
- package/host-builder/src/lookup/examples.ts +117 -0
- package/host-builder/src/lookup/text.ts +60 -0
- package/host-builder/src/server.ts +300 -0
- package/host-builder/src/version.ts +38 -0
- package/mcp-server/README.md +219 -0
- package/mcp-server/src/bounds.ts +23 -0
- package/mcp-server/src/host.ts +31 -0
- package/mcp-server/src/index.ts +27 -0
- package/mcp-server/src/serve-tools.ts +408 -0
- package/mcp-server/src/serve.ts +329 -0
- package/mcp-server/src/server.ts +331 -0
- package/mcp-server/src/session-map.ts +47 -0
- package/mcp-server/src/skill-resources.ts +85 -0
- package/mcp-server/src/types.ts +215 -0
- package/package.json +130 -4
- package/remote/README.md +244 -0
- package/remote/src/attribution.ts +22 -0
- package/remote/src/auth.ts +30 -0
- package/remote/src/bun-module.d.ts +34 -0
- package/remote/src/channel.ts +86 -0
- package/remote/src/connect.ts +212 -0
- package/remote/src/dispatcher.ts +282 -0
- package/remote/src/errors.ts +59 -0
- package/remote/src/host-ui.ts +152 -0
- package/remote/src/http-gate.ts +43 -0
- package/remote/src/index.ts +53 -0
- package/remote/src/jsonl.ts +69 -0
- package/remote/src/limits.ts +43 -0
- package/remote/src/mirror.ts +90 -0
- package/remote/src/pending.ts +22 -0
- package/remote/src/protocol.ts +107 -0
- package/remote/src/serve.ts +560 -0
- package/remote/src/session-proxy.ts +219 -0
- package/remote/src/sse.ts +38 -0
- package/remote/src/stdio-client.ts +41 -0
- package/remote/src/testing-fixtures/serve-stdio.ts +32 -0
- package/remote/src/testing.ts +230 -0
- package/remote/src/transport.ts +139 -0
- package/remote/src/transports/client.ts +126 -0
- package/remote/src/transports/network.ts +268 -0
- package/remote/src/wire.ts +244 -0
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import {
|
|
2
|
+
resolveRedactor,
|
|
3
|
+
type Message,
|
|
4
|
+
type OwnershipScope,
|
|
5
|
+
type ProductionPersistenceStore,
|
|
6
|
+
type RunFeedbackQuery,
|
|
7
|
+
type RunFeedbackRecord,
|
|
8
|
+
type RunFeedbackStore,
|
|
9
|
+
type RunResult,
|
|
10
|
+
type SecretRedactor,
|
|
11
|
+
} from "@arnilo/prism";
|
|
12
|
+
import { EvalError } from "./errors.js";
|
|
13
|
+
import {
|
|
14
|
+
DEFAULT_TRACE_PAGE_SIZE,
|
|
15
|
+
DEFAULT_TRACE_PAGES,
|
|
16
|
+
HARD_DATASET_ITEMS,
|
|
17
|
+
HARD_REPORT_MAX_BYTES,
|
|
18
|
+
HARD_TRACE_PAGE_SIZE,
|
|
19
|
+
HARD_TRACE_PAGES,
|
|
20
|
+
} from "./limits.js";
|
|
21
|
+
import { checkRequirements } from "./score.js";
|
|
22
|
+
import { bootstrapInterval, cohensKappa, krippendorffAlpha, spearman } from "./stats.js";
|
|
23
|
+
import { createPersistenceTraceResolver, limit, pages } from "./trace.js";
|
|
24
|
+
import type { CalibrationItem, CalibrationReport, Scorer, TraceLimits } from "./types.js";
|
|
25
|
+
import { assertFiniteUnitInterval, exactOwnershipMatches, validateScoreResult } from "./util.js";
|
|
26
|
+
|
|
27
|
+
export interface CalibrateJudgeOptions<TInput = unknown, TExpected = unknown> {
|
|
28
|
+
readonly judge: Scorer<TInput, TExpected>;
|
|
29
|
+
readonly items: readonly CalibrationItem<TInput, TExpected>[];
|
|
30
|
+
readonly scale?: "nominal" | "ordinal";
|
|
31
|
+
readonly seed?: number;
|
|
32
|
+
readonly signal?: AbortSignal;
|
|
33
|
+
readonly redactor?: SecretRedactor;
|
|
34
|
+
readonly secrets?: readonly (string | undefined)[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Score labels once, then bootstrap paired items without additional judge calls. */
|
|
38
|
+
export async function calibrateJudge<TInput = unknown, TExpected = unknown>(
|
|
39
|
+
options: CalibrateJudgeOptions<TInput, TExpected>,
|
|
40
|
+
): Promise<CalibrationReport> {
|
|
41
|
+
const { judge, items, scale = "nominal", seed = 0, signal } = options;
|
|
42
|
+
if (!["nominal", "ordinal"].includes(scale) || !Number.isSafeInteger(seed) || items.length > HARD_DATASET_ITEMS) {
|
|
43
|
+
throw new EvalError("invalid calibration scale, seed, or item count", "ERR_PRISM_EVAL_CALIBRATION");
|
|
44
|
+
}
|
|
45
|
+
signal?.throwIfAborted();
|
|
46
|
+
checkRequirements([judge], { timeline: false, trace: false, environment: false });
|
|
47
|
+
for (const row of items) assertFiniteUnitInterval(row.humanScore, "humanScore");
|
|
48
|
+
const redactor = resolveRedactor(options.redactor, options.secrets);
|
|
49
|
+
const human: number[] = [],
|
|
50
|
+
judged: number[] = [];
|
|
51
|
+
let judgeFailures = 0;
|
|
52
|
+
for (const { item, result, humanScore } of items) {
|
|
53
|
+
signal?.throwIfAborted();
|
|
54
|
+
try {
|
|
55
|
+
const verdict = validateScoreResult(await judge.score({ item, result, expected: item.expected, redactor, signal }));
|
|
56
|
+
human.push(humanScore);
|
|
57
|
+
judged.push(verdict.score);
|
|
58
|
+
} catch {
|
|
59
|
+
judgeFailures++;
|
|
60
|
+
}
|
|
61
|
+
signal?.throwIfAborted();
|
|
62
|
+
}
|
|
63
|
+
const labels = [...new Set([...human, ...judged])].sort((a, b) => a - b);
|
|
64
|
+
const indices = new Map(labels.map((label, i) => [label, i]));
|
|
65
|
+
if (labels.length ** 2 * 8 > HARD_REPORT_MAX_BYTES) {
|
|
66
|
+
throw new EvalError("calibration confusion matrix exceeds report bounds", "ERR_PRISM_EVAL_CALIBRATION");
|
|
67
|
+
}
|
|
68
|
+
const counts = labels.map(() => labels.map(() => 0));
|
|
69
|
+
for (let i = 0; i < human.length; i++) counts[indices.get(human[i]!)!]![indices.get(judged[i]!)!]!++;
|
|
70
|
+
const kappa = cohensKappa(human, judged);
|
|
71
|
+
return {
|
|
72
|
+
n: human.length,
|
|
73
|
+
judgeFailures,
|
|
74
|
+
cohensKappa: kappa ?? null,
|
|
75
|
+
...(scale === "ordinal" ? { weightedKappa: cohensKappa(human, judged, true) ?? null } : {}),
|
|
76
|
+
krippendorffAlpha: krippendorffAlpha(human, judged) ?? null,
|
|
77
|
+
spearman: spearman(human, judged) ?? null,
|
|
78
|
+
confusion: { labels, counts },
|
|
79
|
+
...(kappa === undefined
|
|
80
|
+
? {}
|
|
81
|
+
: {
|
|
82
|
+
kappaCi95: bootstrapInterval(
|
|
83
|
+
human.map((_, i) => i),
|
|
84
|
+
{
|
|
85
|
+
// Degenerate one-category resamples provide no agreement evidence; use the worst kappa.
|
|
86
|
+
seed,
|
|
87
|
+
statistic: (sample) =>
|
|
88
|
+
cohensKappa(
|
|
89
|
+
sample.map((i) => human[i]!),
|
|
90
|
+
sample.map((i) => judged[i]!),
|
|
91
|
+
) ?? -1,
|
|
92
|
+
},
|
|
93
|
+
),
|
|
94
|
+
}),
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export interface LabeledItemsFromFeedbackOptions {
|
|
99
|
+
readonly feedbackStore: RunFeedbackStore;
|
|
100
|
+
readonly persistence: ProductionPersistenceStore;
|
|
101
|
+
readonly ownership: OwnershipScope;
|
|
102
|
+
readonly query?: Omit<RunFeedbackQuery, keyof OwnershipScope>;
|
|
103
|
+
readonly toScore?: (feedback: RunFeedbackRecord) => number | undefined;
|
|
104
|
+
readonly traceLimits?: TraceLimits;
|
|
105
|
+
readonly signal?: AbortSignal;
|
|
106
|
+
readonly redactor?: SecretRedactor;
|
|
107
|
+
readonly secrets?: readonly (string | undefined)[];
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Read bounded owner-scoped feedback and traces; never include feedback in the judge's item/result. */
|
|
111
|
+
export async function labeledItemsFromFeedback(
|
|
112
|
+
options: LabeledItemsFromFeedbackOptions,
|
|
113
|
+
): Promise<readonly CalibrationItem<Message | undefined>[]> {
|
|
114
|
+
const { ownership, query = {}, signal } = options;
|
|
115
|
+
if (
|
|
116
|
+
!ownership.tenantId?.trim() ||
|
|
117
|
+
!(ownership.accountId?.trim() || ownership.userId?.trim()) ||
|
|
118
|
+
(ownership.accountId !== undefined && !ownership.accountId.trim()) ||
|
|
119
|
+
(ownership.userId !== undefined && !ownership.userId.trim()) ||
|
|
120
|
+
Object.keys(ownership).some((key) => !["tenantId", "accountId", "userId"].includes(key)) ||
|
|
121
|
+
["tenantId", "accountId", "userId"].some((key) => key in query)
|
|
122
|
+
) {
|
|
123
|
+
throw new EvalError("calibration feedback requires explicit ownership without query overrides", "ERR_PRISM_EVAL_TRACE_OWNERSHIP");
|
|
124
|
+
}
|
|
125
|
+
signal?.throwIfAborted();
|
|
126
|
+
const pageSize = limit(options.traceLimits?.pageSize, DEFAULT_TRACE_PAGE_SIZE, HARD_TRACE_PAGE_SIZE, "pageSize");
|
|
127
|
+
const maxPages = limit(options.traceLimits?.maxPages, DEFAULT_TRACE_PAGES, HARD_TRACE_PAGES, "maxPages");
|
|
128
|
+
const records = await pages(
|
|
129
|
+
(cursor) => options.feedbackStore.query({ ...query, ...ownership, limit: pageSize, cursor, signal }),
|
|
130
|
+
maxPages,
|
|
131
|
+
);
|
|
132
|
+
if (records.length > HARD_DATASET_ITEMS) throw new EvalError("too many calibration feedback items", "ERR_PRISM_EVAL_CALIBRATION");
|
|
133
|
+
const resolver = createPersistenceTraceResolver(options.persistence);
|
|
134
|
+
const redactor = resolveRedactor(options.redactor, options.secrets);
|
|
135
|
+
const output: CalibrationItem<Message | undefined>[] = [];
|
|
136
|
+
for (const record of records) {
|
|
137
|
+
signal?.throwIfAborted();
|
|
138
|
+
if (!exactOwnershipMatches(ownership, record)) throw new EvalError("feedback ownership mismatch", "ERR_PRISM_EVAL_TRACE_OWNERSHIP");
|
|
139
|
+
const humanScore = options.toScore ? options.toScore(record) : record.rating === undefined ? undefined : (record.rating + 1) / 2;
|
|
140
|
+
if (humanScore === undefined) continue;
|
|
141
|
+
assertFiniteUnitInterval(humanScore, "humanScore");
|
|
142
|
+
const trace = await resolver({
|
|
143
|
+
...ownership,
|
|
144
|
+
sessionId: record.sessionId,
|
|
145
|
+
runId: record.runId,
|
|
146
|
+
limits: options.traceLimits,
|
|
147
|
+
redactor,
|
|
148
|
+
signal,
|
|
149
|
+
});
|
|
150
|
+
const messages = trace.events.flatMap((row) => (row.event.type === "message.completed" ? [row.event.message] : []));
|
|
151
|
+
const message = [...messages].reverse().find((row) => row.role === "assistant");
|
|
152
|
+
const content = message?.content ?? [];
|
|
153
|
+
const run = trace.run;
|
|
154
|
+
if (!["succeeded", "failed", "aborted", "suspended", "denied"].includes(run.status ?? "")) {
|
|
155
|
+
throw new EvalError("calibration requires a settled run", "ERR_PRISM_EVAL_CALIBRATION");
|
|
156
|
+
}
|
|
157
|
+
const result: RunResult = {
|
|
158
|
+
sessionId: run.sessionId,
|
|
159
|
+
runId: run.id,
|
|
160
|
+
status:
|
|
161
|
+
run.status === "succeeded"
|
|
162
|
+
? run.stopReason
|
|
163
|
+
? "stopped"
|
|
164
|
+
: "completed"
|
|
165
|
+
: run.status === "denied"
|
|
166
|
+
? "stopped"
|
|
167
|
+
: (run.status as "failed" | "aborted" | "suspended"),
|
|
168
|
+
text: content.flatMap((block) => (block.type === "text" ? [block.text] : [])).join(""),
|
|
169
|
+
content,
|
|
170
|
+
message,
|
|
171
|
+
messages,
|
|
172
|
+
error: run.error,
|
|
173
|
+
abortReason: run.abortReason,
|
|
174
|
+
stopReason: run.status === "denied" ? "denied" : run.stopReason,
|
|
175
|
+
};
|
|
176
|
+
output.push({ item: { id: record.id, input: messages.find((row) => row.role === "user") }, result, humanScore });
|
|
177
|
+
}
|
|
178
|
+
return output;
|
|
179
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ArtifactApproval,
|
|
3
|
+
type ArtifactCitation,
|
|
4
|
+
type ArtifactRevision,
|
|
5
|
+
citationBindingDigest,
|
|
6
|
+
HARD_CITATION_EXCERPT_BYTES,
|
|
7
|
+
} from "@arnilo/prism/artifacts";
|
|
8
|
+
|
|
9
|
+
export type CitationIntegrityReason =
|
|
10
|
+
| "ok"
|
|
11
|
+
| "missing_source"
|
|
12
|
+
| "hash_mismatch"
|
|
13
|
+
| "span_mismatch"
|
|
14
|
+
| "revoked_acl"
|
|
15
|
+
| "revision_changed"
|
|
16
|
+
| "excerpt_too_large"
|
|
17
|
+
| "cross_tenant";
|
|
18
|
+
|
|
19
|
+
export interface CitationLiveSource {
|
|
20
|
+
readonly contentHash: string;
|
|
21
|
+
readonly revision: string;
|
|
22
|
+
readonly body?: string;
|
|
23
|
+
readonly tenantId?: string;
|
|
24
|
+
readonly authorized?: boolean;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface CitationIntegrityResult {
|
|
28
|
+
readonly ok: boolean;
|
|
29
|
+
readonly reason: CitationIntegrityReason;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function normalizeCitationHash(value: string): string {
|
|
33
|
+
const raw = value.startsWith("sha256:") ? value.slice("sha256:".length) : value;
|
|
34
|
+
return raw.trim().toLowerCase();
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** Deterministic source existence / hash / span / ACL check. Ignores `support`. */
|
|
38
|
+
export function checkCitationIntegrity(
|
|
39
|
+
citation: ArtifactCitation,
|
|
40
|
+
live?: CitationLiveSource,
|
|
41
|
+
options?: { readonly boundRevision?: string; readonly maxExcerptBytes?: number },
|
|
42
|
+
): CitationIntegrityResult {
|
|
43
|
+
const maxExcerpt = options?.maxExcerptBytes ?? HARD_CITATION_EXCERPT_BYTES;
|
|
44
|
+
if (citation.excerpt !== undefined && Buffer.byteLength(citation.excerpt, "utf8") > maxExcerpt) {
|
|
45
|
+
return { ok: false, reason: "excerpt_too_large" };
|
|
46
|
+
}
|
|
47
|
+
if (!live) return { ok: false, reason: "missing_source" };
|
|
48
|
+
if (live.authorized === false) return { ok: false, reason: "revoked_acl" };
|
|
49
|
+
if (citation.tenantId && live.tenantId && citation.tenantId !== live.tenantId) {
|
|
50
|
+
return { ok: false, reason: "cross_tenant" };
|
|
51
|
+
}
|
|
52
|
+
if (!citation.contentHash) return { ok: false, reason: "missing_source" };
|
|
53
|
+
if (normalizeCitationHash(citation.contentHash) !== normalizeCitationHash(live.contentHash)) {
|
|
54
|
+
return { ok: false, reason: "hash_mismatch" };
|
|
55
|
+
}
|
|
56
|
+
if (citation.revision !== undefined && citation.revision !== live.revision) {
|
|
57
|
+
return { ok: false, reason: "revision_changed" };
|
|
58
|
+
}
|
|
59
|
+
if (options?.boundRevision !== undefined && options.boundRevision !== live.revision) {
|
|
60
|
+
return { ok: false, reason: "revision_changed" };
|
|
61
|
+
}
|
|
62
|
+
if (citation.span) {
|
|
63
|
+
const { start, end } = citation.span;
|
|
64
|
+
if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start < 0 || end <= start) {
|
|
65
|
+
return { ok: false, reason: "span_mismatch" };
|
|
66
|
+
}
|
|
67
|
+
if (live.body !== undefined) {
|
|
68
|
+
const sliced = live.body.slice(start, end);
|
|
69
|
+
if (citation.excerpt !== undefined && sliced !== citation.excerpt) {
|
|
70
|
+
return { ok: false, reason: "span_mismatch" };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
} else if (citation.excerpt !== undefined && live.body !== undefined && citation.excerpt !== live.body) {
|
|
74
|
+
return { ok: false, reason: "span_mismatch" };
|
|
75
|
+
}
|
|
76
|
+
return { ok: true, reason: "ok" };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** True when the approval digest still matches the revision and (if given) live sources pass integrity. */
|
|
80
|
+
export function approvalEvidenceIntact(
|
|
81
|
+
approval: ArtifactApproval,
|
|
82
|
+
revision: ArtifactRevision,
|
|
83
|
+
liveSources?: Readonly<Record<string, CitationLiveSource>>,
|
|
84
|
+
): CitationIntegrityResult {
|
|
85
|
+
if (approval.evidenceDigest !== undefined && approval.evidenceDigest !== citationBindingDigest(revision.citations)) {
|
|
86
|
+
return { ok: false, reason: "revision_changed" };
|
|
87
|
+
}
|
|
88
|
+
if (liveSources === undefined) return { ok: true, reason: "ok" };
|
|
89
|
+
for (const citation of revision.citations ?? []) {
|
|
90
|
+
if (!citation.sourceId && !citation.contentHash) continue;
|
|
91
|
+
const live = citation.sourceId ? liveSources[citation.sourceId] : undefined;
|
|
92
|
+
const result = checkCitationIntegrity(citation, live, {
|
|
93
|
+
...(citation.revision === undefined ? {} : { boundRevision: citation.revision }),
|
|
94
|
+
});
|
|
95
|
+
if (!result.ok) return result;
|
|
96
|
+
}
|
|
97
|
+
return { ok: true, reason: "ok" };
|
|
98
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { type ArtifactCitation } from "@arnilo/prism/artifacts";
|
|
2
|
+
import { type CitationLiveSource, checkCitationIntegrity } from "./citation-integrity.js";
|
|
3
|
+
import { defineScorer } from "./scorer.js";
|
|
4
|
+
import type { Scorer } from "./types.js";
|
|
5
|
+
|
|
6
|
+
export interface CitationIntegrityItem {
|
|
7
|
+
readonly citation: ArtifactCitation;
|
|
8
|
+
readonly live?: CitationLiveSource;
|
|
9
|
+
readonly boundRevision?: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface CitationIntegrityScorerOptions {
|
|
13
|
+
readonly id?: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** Invariant 0 on missing source, hash/span mismatch, or revoked ACL. `support` cannot raise the score. */
|
|
17
|
+
export function createCitationIntegrityScorer<TInput = unknown, TExpected = unknown>(
|
|
18
|
+
options?: CitationIntegrityScorerOptions,
|
|
19
|
+
): Scorer<TInput, TExpected> {
|
|
20
|
+
return defineScorer({
|
|
21
|
+
id: options?.id ?? "citation_integrity",
|
|
22
|
+
description: "citation source/hash/span/ACL integrity; semantic support is ignored",
|
|
23
|
+
requires: ["environment"],
|
|
24
|
+
invariant: true,
|
|
25
|
+
score(input) {
|
|
26
|
+
const env = input.environment as { citations?: readonly CitationIntegrityItem[] } | undefined;
|
|
27
|
+
const items = env?.citations;
|
|
28
|
+
if (!Array.isArray(items)) {
|
|
29
|
+
return { score: 0, reason: "no citation environment" };
|
|
30
|
+
}
|
|
31
|
+
for (const item of items) {
|
|
32
|
+
if (!item?.citation) {
|
|
33
|
+
return { score: 0, reason: "missing_source" };
|
|
34
|
+
}
|
|
35
|
+
const result = checkCitationIntegrity(item.citation, item.live, {
|
|
36
|
+
...(item.boundRevision === undefined ? {} : { boundRevision: item.boundRevision }),
|
|
37
|
+
});
|
|
38
|
+
if (!result.ok) {
|
|
39
|
+
return { score: 0, reason: result.reason };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return { score: 1 };
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { EvalError } from "./errors.js";
|
|
2
|
+
import { HARD_STATS_RESAMPLES } from "./limits.js";
|
|
3
|
+
import { benjaminiHochberg, bootstrapInterval, mcnemarExact, pairedPermutationTest } from "./stats.js";
|
|
4
|
+
import type { CompareExperimentsOptions, ExperimentComparison, ExperimentReport } from "./types.js";
|
|
5
|
+
|
|
6
|
+
function paired(condition: unknown, message: string): asserts condition {
|
|
7
|
+
if (!condition) throw new EvalError(message, "ERR_PRISM_EVAL_COMPARE_UNPAIRED");
|
|
8
|
+
}
|
|
9
|
+
const mean = (values: readonly number[]) => values.reduce((sum, value) => sum + value, 0) / values.length;
|
|
10
|
+
|
|
11
|
+
function itemsByTag(report: ExperimentReport) {
|
|
12
|
+
const groups = new Map<string, ExperimentReport["items"][number][]>();
|
|
13
|
+
for (const item of report.items)
|
|
14
|
+
for (const tag of new Set(item.item.tags ?? [])) {
|
|
15
|
+
const items = groups.get(tag) ?? [];
|
|
16
|
+
items.push(item);
|
|
17
|
+
groups.set(tag, items);
|
|
18
|
+
}
|
|
19
|
+
return groups;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function indexItems(report: ExperimentReport) {
|
|
23
|
+
const items = new Map<string, Map<string, number[]>>();
|
|
24
|
+
for (const item of report.items) {
|
|
25
|
+
paired(
|
|
26
|
+
typeof item.item.id === "string" && item.item.id.length && !items.has(item.item.id),
|
|
27
|
+
"Comparison requires unique nonempty item ids",
|
|
28
|
+
);
|
|
29
|
+
const scores = new Map<string, number[]>();
|
|
30
|
+
for (const row of item.evaluations) {
|
|
31
|
+
// Failed/skipped records are not numeric observations.
|
|
32
|
+
if (row.status !== "scored") continue;
|
|
33
|
+
paired(
|
|
34
|
+
typeof row.score === "number" && Number.isFinite(row.score) && row.score >= 0 && row.score <= 1,
|
|
35
|
+
`Invalid score for ${row.scorerId} on item ${item.item.id}`,
|
|
36
|
+
);
|
|
37
|
+
const values = scores.get(row.scorerId) ?? [];
|
|
38
|
+
values.push(row.score);
|
|
39
|
+
scores.set(row.scorerId, values);
|
|
40
|
+
}
|
|
41
|
+
items.set(item.item.id, scores);
|
|
42
|
+
}
|
|
43
|
+
return items;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** Miller (2024), §4: pair item means, bootstrap their differences, and control FDR across scorers.
|
|
47
|
+
* Positive differences favor the candidate. Unshared items are excluded; missing paired scores fail closed.
|
|
48
|
+
*/
|
|
49
|
+
export function compareExperiments(
|
|
50
|
+
baseline: ExperimentReport,
|
|
51
|
+
candidate: ExperimentReport,
|
|
52
|
+
options: CompareExperimentsOptions = {},
|
|
53
|
+
): ExperimentComparison {
|
|
54
|
+
const { seed = 0, resamples, alpha = 0.05 } = options;
|
|
55
|
+
if (
|
|
56
|
+
!Number.isFinite(alpha) ||
|
|
57
|
+
alpha <= 0 ||
|
|
58
|
+
alpha >= 1 ||
|
|
59
|
+
!Number.isSafeInteger(seed) ||
|
|
60
|
+
(resamples !== undefined && (!Number.isSafeInteger(resamples) || resamples < 1 || resamples > HARD_STATS_RESAMPLES))
|
|
61
|
+
) {
|
|
62
|
+
throw new EvalError("Comparison requires alpha in (0, 1), an integer seed, and valid resamples", "ERR_PRISM_EVAL_STATS");
|
|
63
|
+
}
|
|
64
|
+
paired(baseline.datasetContentHash === candidate.datasetContentHash, "Comparison requires matching dataset content hashes");
|
|
65
|
+
paired(baseline.datasetId === candidate.datasetId, "Comparison requires matching dataset ids");
|
|
66
|
+
paired(
|
|
67
|
+
baseline.datasetVersion === undefined || candidate.datasetVersion === undefined || baseline.datasetVersion === candidate.datasetVersion,
|
|
68
|
+
"Comparison requires matching dataset versions",
|
|
69
|
+
);
|
|
70
|
+
paired(
|
|
71
|
+
!baseline.manifest || !candidate.manifest || baseline.manifest.datasetVersion === candidate.manifest.datasetVersion,
|
|
72
|
+
"Comparison requires matching manifest dataset versions",
|
|
73
|
+
);
|
|
74
|
+
const left = indexItems(baseline),
|
|
75
|
+
right = indexItems(candidate);
|
|
76
|
+
const singleTrial = [baseline, candidate].every(
|
|
77
|
+
(report) => (report.trials?.count ?? 1) === 1 && report.items.every((item) => item.trials.length <= 1),
|
|
78
|
+
);
|
|
79
|
+
const ids = [...left.keys()].filter((id) => right.has(id)).sort();
|
|
80
|
+
paired(ids.length >= 2, "Comparison requires at least two paired items");
|
|
81
|
+
const scorerIds = options.scorers ?? [...new Set([...left.values(), ...right.values()].flatMap((scores) => [...scores.keys()]))].sort();
|
|
82
|
+
paired(
|
|
83
|
+
scorerIds.length > 0 &&
|
|
84
|
+
new Set(scorerIds).size === scorerIds.length &&
|
|
85
|
+
scorerIds.every((id) => typeof id === "string" && id.length > 0),
|
|
86
|
+
"Comparison requires distinct nonempty scorer ids",
|
|
87
|
+
);
|
|
88
|
+
const entries = scorerIds.map((id) => {
|
|
89
|
+
const a: number[] = [],
|
|
90
|
+
b: number[] = [];
|
|
91
|
+
let binary = singleTrial,
|
|
92
|
+
aOnly = 0,
|
|
93
|
+
bOnly = 0;
|
|
94
|
+
for (const itemId of ids) {
|
|
95
|
+
const x = left.get(itemId)!.get(id),
|
|
96
|
+
y = right.get(itemId)!.get(id);
|
|
97
|
+
paired(x?.length && y?.length, `Missing scorer ${id} on paired item ${itemId}`);
|
|
98
|
+
const xMean = mean(x),
|
|
99
|
+
yMean = mean(y);
|
|
100
|
+
a.push(xMean);
|
|
101
|
+
b.push(yMean);
|
|
102
|
+
binary &&= x.length === 1 && y.length === 1 && (xMean === 0 || xMean === 1) && (yMean === 0 || yMean === 1);
|
|
103
|
+
if (xMean === 1 && yMean === 0) aOnly++;
|
|
104
|
+
if (xMean === 0 && yMean === 1) bOnly++;
|
|
105
|
+
}
|
|
106
|
+
const differences = b.map((value, i) => value - a[i]!);
|
|
107
|
+
return [
|
|
108
|
+
id,
|
|
109
|
+
{
|
|
110
|
+
baselineMean: mean(a),
|
|
111
|
+
candidateMean: mean(b),
|
|
112
|
+
difference: mean(differences),
|
|
113
|
+
ci95: bootstrapInterval(differences, { statistic: mean, seed, resamples }),
|
|
114
|
+
pValue: binary ? mcnemarExact(aOnly, bOnly) : pairedPermutationTest(differences, { seed, resamples }),
|
|
115
|
+
test: binary ? ("mcnemar" as const) : ("paired_permutation" as const),
|
|
116
|
+
},
|
|
117
|
+
] as const;
|
|
118
|
+
});
|
|
119
|
+
const qValues = benjaminiHochberg(entries.map(([, stats]) => stats.pValue));
|
|
120
|
+
const byTag: Record<string, ExperimentComparison> = Object.create(null);
|
|
121
|
+
if (options.byTag) {
|
|
122
|
+
const aTags = itemsByTag(baseline),
|
|
123
|
+
bTags = itemsByTag(candidate);
|
|
124
|
+
for (const tag of [...aTags.keys()].sort()) {
|
|
125
|
+
const a = aTags.get(tag)!;
|
|
126
|
+
const b = bTags.get(tag) ?? [];
|
|
127
|
+
const rightIds = new Set(b.map((item) => item.item.id));
|
|
128
|
+
if (a.filter((item) => rightIds.has(item.item.id)).length < 2) continue;
|
|
129
|
+
byTag[tag] = compareExperiments({ ...baseline, items: a }, { ...candidate, items: b }, { ...options, byTag: false });
|
|
130
|
+
}
|
|
131
|
+
const stats = Object.values(byTag).flatMap((tag) => Object.values(tag.scorers));
|
|
132
|
+
const adjusted = benjaminiHochberg(stats.map((row) => row.pValue));
|
|
133
|
+
let index = 0;
|
|
134
|
+
for (const [tag, comparison] of Object.entries(byTag)) {
|
|
135
|
+
byTag[tag] = {
|
|
136
|
+
...comparison,
|
|
137
|
+
scorers: Object.fromEntries(
|
|
138
|
+
Object.entries(comparison.scorers).map(([id, row]) => {
|
|
139
|
+
const qValue = adjusted[index++]!;
|
|
140
|
+
return [id, { ...row, qValue, significant: qValue <= alpha }];
|
|
141
|
+
}),
|
|
142
|
+
),
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
...(options.byTag ? { byTag } : {}),
|
|
148
|
+
pairedItems: ids.length,
|
|
149
|
+
scorers: Object.fromEntries(
|
|
150
|
+
entries.map(([id, stats], i) => [id, { ...stats, qValue: qValues[i]!, significant: qValues[i]! <= alpha }]),
|
|
151
|
+
),
|
|
152
|
+
};
|
|
153
|
+
}
|