@arnilo/prism-hosts 0.13.1 → 0.14.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 +2 -0
- package/a2a/README.md +195 -0
- package/a2a/src/card.ts +208 -0
- package/a2a/src/codec.ts +523 -0
- package/a2a/src/connect.ts +415 -0
- package/a2a/src/errors.ts +87 -0
- package/a2a/src/index.ts +40 -0
- package/a2a/src/limits.ts +43 -0
- package/a2a/src/pending.ts +28 -0
- package/a2a/src/proxy.ts +526 -0
- package/a2a/src/serve.ts +886 -0
- package/acp/README.md +3 -1
- package/acp/src/limits.ts +3 -16
- package/acp/src/mapper.ts +26 -5
- package/acp/src/serve.ts +6 -5
- package/ag-ui/README.md +2 -1
- package/ag-ui/src/a2ui.ts +8 -31
- package/ag-ui/src/ag-ui-mapper.ts +27 -1
- package/ag-ui/src/encrypted-value.ts +3 -3
- package/ag-ui/src/handler.ts +4 -4
- package/ag-ui/src/index.ts +0 -33
- package/ag-ui/src/limits.ts +5 -88
- package/ag-ui/src/projectors.ts +8 -6
- package/ag-ui/src/renderer/bind.ts +2 -1
- package/channels/README.md +61 -5
- package/channels/src/discord-gateway.ts +354 -0
- package/channels/src/discord.ts +873 -0
- package/channels/src/index.ts +4 -2
- package/channels/src/limits.ts +3 -19
- package/channels/src/pairing.ts +1 -2
- package/channels/src/runtime-turn.ts +10 -2
- package/channels/src/signal.ts +11 -19
- package/channels/src/slack.ts +854 -0
- package/channels/src/telegram.ts +22 -44
- package/channels/src/types.ts +5 -2
- package/devtools/README.md +1 -1
- package/driver-process/src/driver.ts +3 -1
- package/driver-process/src/testing.ts +1 -1
- package/driver-process/src/turn.ts +5 -1
- package/evals/README.md +11 -7
- package/evals/src/calibration.ts +5 -13
- package/evals/src/compare-experiments.ts +1 -2
- package/evals/src/comparison.ts +7 -25
- package/evals/src/curate.ts +3 -9
- package/evals/src/dataset.ts +0 -2
- package/evals/src/index.ts +3 -20
- package/evals/src/injection.ts +33 -6
- package/evals/src/judge.ts +9 -13
- package/evals/src/limits.ts +0 -17
- package/evals/src/rubric-judge.ts +5 -10
- package/evals/src/scenario-runner.ts +8 -4
- package/evals/src/scenarios.ts +5 -5
- package/evals/src/score.ts +3 -5
- package/evals/src/stats.ts +0 -2
- package/evals/src/threshold.ts +3 -3
- package/evals/src/toolless-session.ts +7 -3
- package/evals/src/trace.ts +8 -14
- package/evals/src/trajectory.ts +45 -11
- package/evals/src/types.ts +2 -2
- package/evals/src/user-simulator.ts +1 -7
- package/evals/src/util.ts +3 -9
- package/headless/README.md +20 -1
- package/headless/src/authority.ts +14 -1
- package/headless/src/errors.ts +3 -1
- package/headless/src/index.ts +10 -1
- package/headless/src/limits.ts +2 -2
- package/headless/src/pending.ts +4 -3
- package/headless/src/recover.ts +126 -0
- package/headless/src/resume.ts +1 -1
- package/host-builder/data/api.json +1271 -1360
- package/host-builder/data/errors.json +199 -185
- package/host-builder/data/examples/a2a-client.ts +125 -0
- package/host-builder/data/examples/a2a-server.ts +133 -0
- package/host-builder/data/examples/autonomous-coding-loop.ts +1 -1
- package/host-builder/data/examples/build-workflow.ts +2 -2
- package/host-builder/data/examples/caveman-ponytail.ts +1 -1
- package/host-builder/data/examples/channel-discord.ts +176 -0
- package/host-builder/data/examples/channel-slack.ts +146 -0
- package/host-builder/data/examples/continue-after-failure.ts +80 -0
- package/host-builder/data/examples/custom-adapter.ts +1 -1
- package/host-builder/data/examples/decision-models.ts +1 -1
- package/host-builder/data/examples/define-package.ts +1 -1
- package/host-builder/data/examples/delegate.ts +74 -9
- package/host-builder/data/examples/durable-loops-and-approvals.ts +11 -10
- package/host-builder/data/examples/governance-deny.ts +1 -1
- package/host-builder/data/examples/guardrail-content.ts +126 -0
- package/host-builder/data/examples/headless-host.ts +1 -1
- package/host-builder/data/examples/long-running-job.ts +129 -0
- package/host-builder/data/examples/long-term-memory.ts +1 -1
- package/host-builder/data/examples/mcp-oauth.ts +197 -0
- package/host-builder/data/examples/mcp-trust.ts +1 -1
- package/host-builder/data/examples/memory-and-wiki.ts +2 -2
- package/host-builder/data/examples/memory-system.ts +19 -9
- package/host-builder/data/examples/model-router-aggregate-budgets.ts +1 -1
- package/host-builder/data/examples/parallel-tools.ts +70 -0
- package/host-builder/data/examples/remote-agent.ts +1 -1
- package/host-builder/data/examples/serve-tools.ts +1 -1
- package/host-builder/data/examples/session-memory.ts +18 -16
- package/host-builder/data/examples/side-call.ts +1 -1
- package/host-builder/data/examples/sqlite-resume.ts +1 -1
- package/host-builder/data/examples/structured-output.ts +57 -0
- package/host-builder/data/examples.json +14 -4
- package/host-builder/skills/prism-host-builder/SKILL.md +1 -1
- package/host-builder/skills/prism-host-builder/references/choosing.md +14 -10
- package/host-builder/skills/prism-host-builder/references/pitfalls.md +5 -3
- package/host-builder/skills/prism-host-builder/references/recipes.md +5 -5
- package/host-builder/skills/prism-host-builder/references/verification.md +1 -1
- package/host-builder/src/check/runner.ts +2 -3
- package/host-builder/src/server.ts +2 -2
- package/mcp-server/README.md +3 -3
- package/mcp-server/src/bounds.ts +3 -3
- package/mcp-server/src/serve-tools.ts +2 -9
- package/mcp-server/src/serve.ts +2 -4
- package/mcp-server/src/server.ts +10 -20
- package/package.json +12 -6
- package/remote/README.md +7 -4
- package/remote/src/channel.ts +6 -2
- package/remote/src/connect.ts +9 -3
- package/remote/src/errors.ts +3 -1
- package/remote/src/limits.ts +3 -13
- package/remote/src/mirror.ts +2 -1
- package/remote/src/pending.ts +4 -3
- package/remote/src/protocol.ts +3 -0
- package/remote/src/serve.ts +43 -5
- package/remote/src/session-proxy.ts +28 -5
- package/remote/src/testing.ts +3 -1
- package/remote/src/wire.ts +74 -14
package/channels/src/telegram.ts
CHANGED
|
@@ -5,7 +5,7 @@ import { type Agent, type OwnershipScope } from "@arnilo/prism";
|
|
|
5
5
|
import type { CheckpointStore, LeaseRecord, LeaseStore } from "./checkpoint-contract.js";
|
|
6
6
|
import { bindChannelHostUi } from "./host-ui.js";
|
|
7
7
|
import { retryableAdmission } from "./admission.js";
|
|
8
|
-
import { DEFAULT_CHANNEL_LIMITS
|
|
8
|
+
import { DEFAULT_CHANNEL_LIMITS } from "./limits.js";
|
|
9
9
|
import { createChannelStateStore } from "./state.js";
|
|
10
10
|
import { type ChannelSecretSource, resolveChannelSecretRef, createChannelRedactor } from "./secret-ref.js";
|
|
11
11
|
import { createMemoryCheckpointStore, createMemoryLeaseStore } from "./memory-stores.js";
|
|
@@ -32,7 +32,6 @@ const DEFAULT_POLL_TIMEOUT_SECONDS = 30;
|
|
|
32
32
|
const DEFAULT_POLL_LIMIT = 100;
|
|
33
33
|
const DEFAULT_LEASE_TTL_MS = 90_000;
|
|
34
34
|
const DEFAULT_MAX_REQUEST_BYTES = 128 * 1024;
|
|
35
|
-
const HARD_MAX_REQUEST_BYTES = 1024 * 1024;
|
|
36
35
|
const TELEGRAM_TEXT_CODE_UNITS = 3500;
|
|
37
36
|
const MAX_SEND_ATTEMPTS = 5;
|
|
38
37
|
/** One preview slot per chat: repeated updates with the same id replace that draft; a new id would create a second one. */
|
|
@@ -220,10 +219,15 @@ function apiOrigin(value: string | undefined): string {
|
|
|
220
219
|
return parsed.origin;
|
|
221
220
|
}
|
|
222
221
|
|
|
223
|
-
|
|
222
|
+
/** A host-set adapter limit, at least `min`. The host's value is the cap (plan 239 Task 5). */
|
|
223
|
+
/** Telegram Bot API `getUpdates` maxima. */
|
|
224
|
+
const TELEGRAM_MAX_POLL_TIMEOUT_SECONDS = 50;
|
|
225
|
+
const TELEGRAM_MAX_POLL_LIMIT = 100;
|
|
226
|
+
|
|
227
|
+
function boundedInteger(value: number | undefined, fallback: number, min: number, name: string): number {
|
|
224
228
|
const resolved = value ?? fallback;
|
|
225
|
-
if (!Number.isSafeInteger(resolved) || resolved < min
|
|
226
|
-
throw new TypeError(`Telegram ${name} must be an integer
|
|
229
|
+
if (!Number.isSafeInteger(resolved) || resolved < min) {
|
|
230
|
+
throw new TypeError(`Telegram ${name} must be an integer of at least ${min}`);
|
|
227
231
|
}
|
|
228
232
|
return resolved;
|
|
229
233
|
}
|
|
@@ -745,23 +749,15 @@ export function createTelegramAdapter(options: TelegramAdapterOptions): Telegram
|
|
|
745
749
|
) {
|
|
746
750
|
throw new TypeError("Telegram connectionId must be a bounded non-empty string");
|
|
747
751
|
}
|
|
748
|
-
const pollTimeoutSeconds = boundedInteger(options.pollTimeoutSeconds, DEFAULT_POLL_TIMEOUT_SECONDS, 1,
|
|
749
|
-
const pollLimit = boundedInteger(options.pollLimit, DEFAULT_POLL_LIMIT, 1,
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
);
|
|
758
|
-
const maxAttachmentBytes = boundedInteger(
|
|
759
|
-
options.maxAttachmentBytes,
|
|
760
|
-
DEFAULT_CHANNEL_LIMITS.maxAttachmentBytes,
|
|
761
|
-
1,
|
|
762
|
-
HARD_CHANNEL_LIMITS.maxAttachmentBytes,
|
|
763
|
-
"maxAttachmentBytes",
|
|
764
|
-
);
|
|
752
|
+
const pollTimeoutSeconds = boundedInteger(options.pollTimeoutSeconds, DEFAULT_POLL_TIMEOUT_SECONDS, 1, "pollTimeoutSeconds");
|
|
753
|
+
const pollLimit = boundedInteger(options.pollLimit, DEFAULT_POLL_LIMIT, 1, "pollLimit");
|
|
754
|
+
// Telegram's own getUpdates ranges (wire format, not work limits).
|
|
755
|
+
if (pollTimeoutSeconds > TELEGRAM_MAX_POLL_TIMEOUT_SECONDS)
|
|
756
|
+
throw new TypeError(`Telegram pollTimeoutSeconds must be at most ${TELEGRAM_MAX_POLL_TIMEOUT_SECONDS}`);
|
|
757
|
+
if (pollLimit > TELEGRAM_MAX_POLL_LIMIT) throw new TypeError(`Telegram pollLimit must be at most ${TELEGRAM_MAX_POLL_LIMIT}`);
|
|
758
|
+
const leaseTtlMs = boundedInteger(options.leaseTtlMs, DEFAULT_LEASE_TTL_MS, pollTimeoutSeconds * 1000 + 10_000, "leaseTtlMs");
|
|
759
|
+
const maxResponseBytes = boundedInteger(options.maxResponseBytes, DEFAULT_MAX_REQUEST_BYTES, 1024, "maxResponseBytes");
|
|
760
|
+
const maxAttachmentBytes = boundedInteger(options.maxAttachmentBytes, DEFAULT_CHANNEL_LIMITS.maxAttachmentBytes, 1, "maxAttachmentBytes");
|
|
765
761
|
const api = telegramApi({ ...options, maxResponseBytes });
|
|
766
762
|
const allowGroups = options.allowGroups === true;
|
|
767
763
|
const sendDrafts = options.sendDrafts === true;
|
|
@@ -1084,30 +1080,12 @@ export function createTelegramWebhookHandler(options: TelegramWebhookHandlerOpti
|
|
|
1084
1080
|
if (!validWebhookSecret(value)) throw new TypeError("Telegram webhookSecret must be 1-256 URL-safe characters");
|
|
1085
1081
|
return value;
|
|
1086
1082
|
}));
|
|
1087
|
-
const leaseTtlMs = boundedInteger(options.leaseTtlMs, DEFAULT_LEASE_TTL_MS, 5_000,
|
|
1088
|
-
const maxRequestBytes = boundedInteger(
|
|
1089
|
-
|
|
1090
|
-
DEFAULT_MAX_REQUEST_BYTES,
|
|
1091
|
-
1024,
|
|
1092
|
-
HARD_MAX_REQUEST_BYTES,
|
|
1093
|
-
"maxRequestBytes",
|
|
1094
|
-
);
|
|
1095
|
-
const maxResponseBytes = boundedInteger(
|
|
1096
|
-
options.maxResponseBytes,
|
|
1097
|
-
DEFAULT_MAX_REQUEST_BYTES,
|
|
1098
|
-
1024,
|
|
1099
|
-
HARD_MAX_REQUEST_BYTES,
|
|
1100
|
-
"maxResponseBytes",
|
|
1101
|
-
);
|
|
1083
|
+
const leaseTtlMs = boundedInteger(options.leaseTtlMs, DEFAULT_LEASE_TTL_MS, 5_000, "leaseTtlMs");
|
|
1084
|
+
const maxRequestBytes = boundedInteger(options.maxRequestBytes, DEFAULT_MAX_REQUEST_BYTES, 1024, "maxRequestBytes");
|
|
1085
|
+
const maxResponseBytes = boundedInteger(options.maxResponseBytes, DEFAULT_MAX_REQUEST_BYTES, 1024, "maxResponseBytes");
|
|
1102
1086
|
const api = telegramApi({ ...options, maxResponseBytes });
|
|
1103
1087
|
const allowGroups = options.allowGroups === true;
|
|
1104
|
-
const maxAttachmentBytes = boundedInteger(
|
|
1105
|
-
options.maxAttachmentBytes,
|
|
1106
|
-
DEFAULT_CHANNEL_LIMITS.maxAttachmentBytes,
|
|
1107
|
-
1,
|
|
1108
|
-
HARD_CHANNEL_LIMITS.maxAttachmentBytes,
|
|
1109
|
-
"maxAttachmentBytes",
|
|
1110
|
-
);
|
|
1088
|
+
const maxAttachmentBytes = boundedInteger(options.maxAttachmentBytes, DEFAULT_CHANNEL_LIMITS.maxAttachmentBytes, 1, "maxAttachmentBytes");
|
|
1111
1089
|
const media = createInboundMedia({
|
|
1112
1090
|
connectionId: options.connectionId,
|
|
1113
1091
|
allowGroups,
|
package/channels/src/types.ts
CHANGED
|
@@ -37,8 +37,11 @@ export interface ChannelAdmission {
|
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
export interface ChannelCapabilities {
|
|
40
|
-
/**
|
|
41
|
-
|
|
40
|
+
/**
|
|
41
|
+
* Telegram advances a poll offset; Signal has no transport acknowledgment step; Slack (and
|
|
42
|
+
* Discord) acknowledge each delivery within a platform deadline after `admit` settles.
|
|
43
|
+
*/
|
|
44
|
+
readonly acknowledgement: "telegram_offset" | "none" | "deadline";
|
|
42
45
|
readonly controls: "callback" | "command";
|
|
43
46
|
/** Platform text ceiling for one outbound message, in UTF-16 code units. */
|
|
44
47
|
readonly maxTextCodeUnits: number;
|
package/devtools/README.md
CHANGED
|
@@ -82,7 +82,7 @@ Unknown sessions answer 404 with `ERR_PRISM_DEVTOOLS_NOT_FOUND`. A malformed que
|
|
|
82
82
|
|
|
83
83
|
- Replay pages are at most 500 entries; the page shows 100 at a time.
|
|
84
84
|
- The live feed keeps the newest 500 rows on screen. Each subscription uses the agent's bounded queue
|
|
85
|
-
(`SubscribeOptions.maxQueuedEvents`, default
|
|
85
|
+
(`SubscribeOptions.maxQueuedEvents`, default 4096; `overflow` default `coalesce`).
|
|
86
86
|
- The browser module is transpiled once per process and cached. The package ships source, so there is no
|
|
87
87
|
build step and no `dist/`.
|
|
88
88
|
|
|
@@ -30,6 +30,8 @@ import { jsonRpc } from "./transports/json-rpc.js";
|
|
|
30
30
|
import { jsonlStream } from "./transports/jsonl-stream.js";
|
|
31
31
|
import { createTurn } from "./turn.js";
|
|
32
32
|
|
|
33
|
+
const DEFAULT_HOOK_TIMEOUT_MS = 5000;
|
|
34
|
+
|
|
33
35
|
export function adapterDriver(adapter: AgentAdapter): DriverDefinition<ProcessDriverConfig> {
|
|
34
36
|
assertAdapter(adapter);
|
|
35
37
|
return defineDriver<ProcessDriverConfig>({
|
|
@@ -134,7 +136,7 @@ async function runAdapter(adapter: AgentAdapter, ctx: DriverRunContext<ProcessDr
|
|
|
134
136
|
}
|
|
135
137
|
: noHooks,
|
|
136
138
|
failClosed: adapter.hooks?.failClosed ?? { exitCode: 2, stdout: "" },
|
|
137
|
-
timeoutMs: adapter.hooks?.timeoutMs ??
|
|
139
|
+
timeoutMs: adapter.hooks?.timeoutMs ?? DEFAULT_HOOK_TIMEOUT_MS,
|
|
138
140
|
askSupport: { rewrite: adapter.descriptor.controls.rewrite },
|
|
139
141
|
},
|
|
140
142
|
);
|
|
@@ -91,7 +91,7 @@ export async function adapterConformance(adapter: AgentAdapter, options: Adapter
|
|
|
91
91
|
definePackage({
|
|
92
92
|
name: "conformance-workspace",
|
|
93
93
|
version: "1.0.0",
|
|
94
|
-
requires: { api:
|
|
94
|
+
requires: { api: 2 },
|
|
95
95
|
setup(prism) {
|
|
96
96
|
prism.services.provide("workspace", { worktree: { bound: () => ({ path: worktree }) } });
|
|
97
97
|
},
|
|
@@ -78,7 +78,11 @@ export function createTurn(
|
|
|
78
78
|
}
|
|
79
79
|
if (decoded.sessionId !== undefined) {
|
|
80
80
|
encoding.sessionId = decoded.sessionId;
|
|
81
|
-
if (adapter.session.strategy === "vendor")
|
|
81
|
+
if (adapter.session.strategy === "vendor") {
|
|
82
|
+
const state = run.state("vendor-session");
|
|
83
|
+
const payload = [redact(decoded.sessionId)];
|
|
84
|
+
await (state.replace ? state.replace(payload) : state.append(payload));
|
|
85
|
+
}
|
|
82
86
|
}
|
|
83
87
|
if (decoded.turnId !== undefined) encoding.turnId = decoded.turnId;
|
|
84
88
|
if (decoded.stop) {
|
package/evals/README.md
CHANGED
|
@@ -148,7 +148,7 @@ mapped to the existing `mulberry32` 32-bit stream; repeated calls with the same
|
|
|
148
148
|
Invalid input, a throwing statistic, or a non-finite statistic result throws `EvalError` with
|
|
149
149
|
`code: "ERR_PRISM_EVAL_STATS"`.
|
|
150
150
|
|
|
151
|
-
Resamples must be integers
|
|
151
|
+
Resamples must be positive integers (the host's value is the cap), including when permutation
|
|
152
152
|
enumeration is exact. Bootstrap costs `O(resamples × N)` in expectation for a linear-time statistic,
|
|
153
153
|
plus sorting `resamples` statistics; unequal cluster sizes can produce longer individual resamples.
|
|
154
154
|
Monte Carlo permutation costs `O(resamples × N)`; exact permutation costs `O(2^N × N)` for `N ≤ 16`.
|
|
@@ -185,6 +185,7 @@ Custom scorers use `defineScorer`; the built-ins cover the common trajectory che
|
|
|
185
185
|
| `createToolCallMatchScorer` | `timeline` | with `deny` or `invariant: true` | expected tool calls present, in order or unordered |
|
|
186
186
|
| `createApprovalBeforeEffectScorer({ tools })` | `timeline` | yes | an effect passes only with an `approved` `hitl` step for the same `toolCallId` before it |
|
|
187
187
|
| `createGuardrailPackScorer({ forbidTools })` | `timeline` | yes | no guardrail-pack denial for the forbidden tools |
|
|
188
|
+
| `createGuardrailFlaggedScorer({ pack })` | `timeline` | no | a rule of `pack` fired (any action); a detector measure for the injection suite |
|
|
188
189
|
| `createSchemaScorer` | `timeline` | no | final output parses against a JSON schema |
|
|
189
190
|
| `createErrorClassScorer()` | `timeline` | with `deny` | denied error classes never appear (and scores `0` with no evidence) |
|
|
190
191
|
| `createNoLoopScorer` | `timeline` | yes | no repeated identical tool call |
|
|
@@ -290,7 +291,7 @@ const result = await runScenario(
|
|
|
290
291
|
);
|
|
291
292
|
```
|
|
292
293
|
|
|
293
|
-
- `turns` is bounded, not truncated: more turns than `maxTurns` (default 8
|
|
294
|
+
- `turns` is bounded, not truncated: more turns than `maxTurns` (default 8; the host's value is the cap) throws `ERR_PRISM_EVAL_SCENARIO_BOUNDS` before the agent is built, so a cut-off scenario cannot pass for the wrong reason.
|
|
294
295
|
- `status` is `succeeded`, `failed`, or `aborted` (a host signal, or a final run the agent aborted). A throwing `assertReply` stops the scenario with `failed` and `ERR_PRISM_EVAL_SCENARIO_ASSERTION` naming the turn.
|
|
295
296
|
- `scoreTurns: "each"` scores every turn on that turn's result and timeline slice, recording `metadata.turnIndex`; the default `"last"` scores only the final turn. `"each"` multiplies scorer calls (and judge cost) by the turn count.
|
|
296
297
|
|
|
@@ -343,7 +344,7 @@ no continuation. The versioned prompt contains only persona, hidden goal, stop
|
|
|
343
344
|
token, and text conversation: expected answers, environment state, timelines,
|
|
344
345
|
and tool I/O are excluded. The resolved scorer redactor (`redactor` plus
|
|
345
346
|
`secrets`) redacts this data before sending it to the simulator and redacts the
|
|
346
|
-
recorded simulation turns. `timeoutMs` defaults to 30,000
|
|
347
|
+
recorded simulation turns. `timeoutMs` defaults to 30,000;
|
|
347
348
|
prompts are capped at 1 MiB and replies at 16 KiB. Empty, oversized, failed, or
|
|
348
349
|
timed-out replies fail the scenario with `ERR_PRISM_EVAL_USER_SIMULATOR` and skip
|
|
349
350
|
its scorers with that reason. Per-turn scoring is deferred until simulation
|
|
@@ -440,7 +441,7 @@ items are excluded, so inspect `pairedItems` before drawing conclusions.
|
|
|
440
441
|
`scorers` selects distinct scorer ids; by default all observed scorer ids from
|
|
441
442
|
both reports are compared and required on every paired item. `seed` defaults to
|
|
442
443
|
zero. `resamples` overrides both bootstrap (default 2,000) and Monte Carlo
|
|
443
|
-
permutation (default 10,000)
|
|
444
|
+
permutation (default 10,000). Invalid numerical
|
|
444
445
|
options throw `ERR_PRISM_EVAL_STATS`. `alpha` changes significance only; `ci95`
|
|
445
446
|
always has 95% coverage. Comparison is pure and makes no agent calls.
|
|
446
447
|
|
|
@@ -746,8 +747,8 @@ rejects the operation. Empty or single-category agreement and constant-rank
|
|
|
746
747
|
correlation are `null`, with no fabricated agreement or NaN in serialized reports.
|
|
747
748
|
The confusion matrix has ascending numeric `labels`, human rows and judge columns
|
|
748
749
|
in `counts`. Exact numeric scores are categories; align human and judge scales
|
|
749
|
-
before measuring agreement.
|
|
750
|
-
|
|
750
|
+
before measuring agreement. The estimated numeric matrix storage is capped at the
|
|
751
|
+
default report byte budget (`DEFAULT_REPORT_MAX_BYTES`).
|
|
751
752
|
|
|
752
753
|
The report includes unweighted `cohensKappa`, nominal `krippendorffAlpha` for two
|
|
753
754
|
complete raters, and average-tie-rank `spearman`. `scale: "ordinal"` additionally
|
|
@@ -796,7 +797,8 @@ console.log(suite.benignUtility, suite.utilityUnderAttack, suite.attackSuccessRa
|
|
|
796
797
|
```
|
|
797
798
|
|
|
798
799
|
The factory receives `hooks`, `slots`, and the current `item` (also available to
|
|
799
|
-
ordinary experiment factories). Forward hooks and slots into `createAgent
|
|
800
|
+
ordinary experiment factories). Forward hooks and slots into `createAgent`;
|
|
801
|
+
do not spread `extra`, because `createAgent` rejects the unknown `item` key.
|
|
800
802
|
Factories must create isolated agents; manage their disposal as with
|
|
801
803
|
`runExperiment`. Existing hooks run alongside the injection hook, so approval
|
|
802
804
|
and output guardrails still apply. Each trial has its own injection closure,
|
|
@@ -841,3 +843,5 @@ rates. No model judge calls are added.
|
|
|
841
843
|
Runs = tasks × (1 + attacks × carriers) × trials. Four built-in attacks mean
|
|
842
844
|
**5 runs per task/trial for one carrier**, or **13 for all three**.
|
|
843
845
|
See `examples/eval-injection.ts` for a runnable example that falls for one attack.
|
|
846
|
+
|
|
847
|
+
**Detectors.** `detectors` takes up to 8 extra scorers with unique ids, for example `createGuardrailFlaggedScorer({ pack: "injection-markers" })`. The scorer gives 1 when any `pack:<pack>/…` rule fired on the timeline, whether that rule denied, redacted, or only flagged. Each detector is reported as `suite.detection[id] = { caught, falsePositive }`: `caught` is its pass rate on attacked items and `falsePositive` its pass rate on benign items, both `InjectionRate`. Per-attack and per-carrier groups also carry `detection` with the attacked side. To compare a no-pack arm with a packs arm, pass both reports to `compareExperiments`. A judge rule that failed under `onError: "allow"` still emits a record, and the timeline does not project its outcome, so `createGuardrailFlaggedScorer` over-counts for packs with judge rules.
|
package/evals/src/calibration.ts
CHANGED
|
@@ -10,14 +10,7 @@ import {
|
|
|
10
10
|
type SecretRedactor,
|
|
11
11
|
} from "@arnilo/prism";
|
|
12
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";
|
|
13
|
+
import { DEFAULT_REPORT_MAX_BYTES, DEFAULT_TRACE_PAGE_SIZE, DEFAULT_TRACE_PAGES } from "./limits.js";
|
|
21
14
|
import { checkRequirements } from "./score.js";
|
|
22
15
|
import { bootstrapInterval, cohensKappa, krippendorffAlpha, spearman } from "./stats.js";
|
|
23
16
|
import { createPersistenceTraceResolver, limit, pages } from "./trace.js";
|
|
@@ -39,7 +32,7 @@ export async function calibrateJudge<TInput = unknown, TExpected = unknown>(
|
|
|
39
32
|
options: CalibrateJudgeOptions<TInput, TExpected>,
|
|
40
33
|
): Promise<CalibrationReport> {
|
|
41
34
|
const { judge, items, scale = "nominal", seed = 0, signal } = options;
|
|
42
|
-
if (!["nominal", "ordinal"].includes(scale) || !Number.isSafeInteger(seed)
|
|
35
|
+
if (!["nominal", "ordinal"].includes(scale) || !Number.isSafeInteger(seed)) {
|
|
43
36
|
throw new EvalError("invalid calibration scale, seed, or item count", "ERR_PRISM_EVAL_CALIBRATION");
|
|
44
37
|
}
|
|
45
38
|
signal?.throwIfAborted();
|
|
@@ -62,7 +55,7 @@ export async function calibrateJudge<TInput = unknown, TExpected = unknown>(
|
|
|
62
55
|
}
|
|
63
56
|
const labels = [...new Set([...human, ...judged])].sort((a, b) => a - b);
|
|
64
57
|
const indices = new Map(labels.map((label, i) => [label, i]));
|
|
65
|
-
if (labels.length ** 2 * 8 >
|
|
58
|
+
if (labels.length ** 2 * 8 > DEFAULT_REPORT_MAX_BYTES) {
|
|
66
59
|
throw new EvalError("calibration confusion matrix exceeds report bounds", "ERR_PRISM_EVAL_CALIBRATION");
|
|
67
60
|
}
|
|
68
61
|
const counts = labels.map(() => labels.map(() => 0));
|
|
@@ -123,13 +116,12 @@ export async function labeledItemsFromFeedback(
|
|
|
123
116
|
throw new EvalError("calibration feedback requires explicit ownership without query overrides", "ERR_PRISM_EVAL_TRACE_OWNERSHIP");
|
|
124
117
|
}
|
|
125
118
|
signal?.throwIfAborted();
|
|
126
|
-
const pageSize = limit(options.traceLimits?.pageSize, DEFAULT_TRACE_PAGE_SIZE,
|
|
127
|
-
const maxPages = limit(options.traceLimits?.maxPages, DEFAULT_TRACE_PAGES,
|
|
119
|
+
const pageSize = limit(options.traceLimits?.pageSize, DEFAULT_TRACE_PAGE_SIZE, "pageSize");
|
|
120
|
+
const maxPages = limit(options.traceLimits?.maxPages, DEFAULT_TRACE_PAGES, "maxPages");
|
|
128
121
|
const records = await pages(
|
|
129
122
|
(cursor) => options.feedbackStore.query({ ...query, ...ownership, limit: pageSize, cursor, signal }),
|
|
130
123
|
maxPages,
|
|
131
124
|
);
|
|
132
|
-
if (records.length > HARD_DATASET_ITEMS) throw new EvalError("too many calibration feedback items", "ERR_PRISM_EVAL_CALIBRATION");
|
|
133
125
|
const resolver = createPersistenceTraceResolver(options.persistence);
|
|
134
126
|
const redactor = resolveRedactor(options.redactor, options.secrets);
|
|
135
127
|
const output: CalibrationItem<Message | undefined>[] = [];
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { EvalError } from "./errors.js";
|
|
2
|
-
import { HARD_STATS_RESAMPLES } from "./limits.js";
|
|
3
2
|
import { benjaminiHochberg, bootstrapInterval, mcnemarExact, pairedPermutationTest } from "./stats.js";
|
|
4
3
|
import type { CompareExperimentsOptions, ExperimentComparison, ExperimentReport } from "./types.js";
|
|
5
4
|
|
|
@@ -57,7 +56,7 @@ export function compareExperiments(
|
|
|
57
56
|
alpha <= 0 ||
|
|
58
57
|
alpha >= 1 ||
|
|
59
58
|
!Number.isSafeInteger(seed) ||
|
|
60
|
-
(resamples !== undefined && (!Number.isSafeInteger(resamples) || resamples < 1
|
|
59
|
+
(resamples !== undefined && (!Number.isSafeInteger(resamples) || resamples < 1))
|
|
61
60
|
) {
|
|
62
61
|
throw new EvalError("Comparison requires alpha in (0, 1), an integer seed, and valid resamples", "ERR_PRISM_EVAL_STATS");
|
|
63
62
|
}
|
package/evals/src/comparison.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { type RunResult, resolveRedactor } from "@arnilo/prism";
|
|
2
2
|
import { EvalError } from "./errors.js";
|
|
3
|
-
import {
|
|
4
|
-
DEFAULT_CANDIDATE_MAX_BYTES,
|
|
5
|
-
DEFAULT_COMPARISON_CANDIDATES,
|
|
6
|
-
DEFAULT_JUDGE_MAX_OUTPUT_BYTES,
|
|
7
|
-
HARD_CANDIDATE_MAX_BYTES,
|
|
8
|
-
HARD_COMPARISON_CANDIDATES,
|
|
9
|
-
HARD_JUDGE_MAX_OUTPUT_BYTES,
|
|
10
|
-
} from "./limits.js";
|
|
3
|
+
import { DEFAULT_CANDIDATE_MAX_BYTES, DEFAULT_COMPARISON_CANDIDATES, DEFAULT_JUDGE_MAX_OUTPUT_BYTES } from "./limits.js";
|
|
11
4
|
import { resolveTrialsConfig } from "./scenarios.js";
|
|
12
5
|
import { bootstrapInterval, bradleyTerry } from "./stats.js";
|
|
13
6
|
import type { ComparisonRecord, ComparisonReport, RunComparisonOptions } from "./types.js";
|
|
@@ -19,30 +12,19 @@ export async function runComparison<TInput = unknown, TExpected = unknown>(
|
|
|
19
12
|
): Promise<ComparisonReport> {
|
|
20
13
|
const candidates = Object.keys(options.candidates).sort();
|
|
21
14
|
const maxCandidates = options.maxCandidates ?? DEFAULT_COMPARISON_CANDIDATES;
|
|
22
|
-
if (!Number.isInteger(maxCandidates) || maxCandidates < 2
|
|
23
|
-
throw new EvalError(
|
|
15
|
+
if (!Number.isInteger(maxCandidates) || maxCandidates < 2) {
|
|
16
|
+
throw new EvalError("maxCandidates must be an integer of at least 2", "ERR_PRISM_EVAL_COMPARISON_BOUNDS");
|
|
24
17
|
}
|
|
25
18
|
if (candidates.length < 2 || candidates.length > maxCandidates || !options.scorers.length) {
|
|
26
19
|
throw new EvalError("comparison requires bounded candidates and at least one scorer", "ERR_PRISM_EVAL_COMPARISON");
|
|
27
20
|
}
|
|
28
|
-
const boundedBytes = (value: number | undefined, fallback: number,
|
|
21
|
+
const boundedBytes = (value: number | undefined, fallback: number, name: string) => {
|
|
29
22
|
const selected = value ?? fallback;
|
|
30
|
-
if (!Number.isInteger(selected) || selected < 1
|
|
31
|
-
throw new EvalError(`${name} is out of bounds`, "ERR_PRISM_EVAL_COMPARISON_BOUNDS");
|
|
23
|
+
if (!Number.isInteger(selected) || selected < 1) throw new EvalError(`${name} is out of bounds`, "ERR_PRISM_EVAL_COMPARISON_BOUNDS");
|
|
32
24
|
return selected;
|
|
33
25
|
};
|
|
34
|
-
const maxCandidateBytes = boundedBytes(
|
|
35
|
-
|
|
36
|
-
DEFAULT_CANDIDATE_MAX_BYTES,
|
|
37
|
-
HARD_CANDIDATE_MAX_BYTES,
|
|
38
|
-
"maxCandidateBytes",
|
|
39
|
-
);
|
|
40
|
-
const maxScorerOutputBytes = boundedBytes(
|
|
41
|
-
options.maxScorerOutputBytes,
|
|
42
|
-
DEFAULT_JUDGE_MAX_OUTPUT_BYTES,
|
|
43
|
-
HARD_JUDGE_MAX_OUTPUT_BYTES,
|
|
44
|
-
"maxScorerOutputBytes",
|
|
45
|
-
);
|
|
26
|
+
const maxCandidateBytes = boundedBytes(options.maxCandidateBytes, DEFAULT_CANDIDATE_MAX_BYTES, "maxCandidateBytes");
|
|
27
|
+
const maxScorerOutputBytes = boundedBytes(options.maxScorerOutputBytes, DEFAULT_JUDGE_MAX_OUTPUT_BYTES, "maxScorerOutputBytes");
|
|
46
28
|
const { count: trials } = resolveTrialsConfig(options.trials, options.seed);
|
|
47
29
|
if (options.seed !== undefined && !Number.isSafeInteger(options.seed))
|
|
48
30
|
throw new EvalError("seed must be a safe integer", "ERR_PRISM_EVAL_TRIALS");
|
package/evals/src/curate.ts
CHANGED
|
@@ -11,13 +11,7 @@ import type {
|
|
|
11
11
|
import { resolveRedactor } from "@arnilo/prism";
|
|
12
12
|
import { defineDataset } from "./dataset.js";
|
|
13
13
|
import { EvalError } from "./errors.js";
|
|
14
|
-
import {
|
|
15
|
-
DEFAULT_TRACE_PAGE_SIZE,
|
|
16
|
-
DEFAULT_TRACE_PAGES,
|
|
17
|
-
HARD_CURATION_ITEM_MAX_BYTES,
|
|
18
|
-
HARD_TRACE_PAGE_SIZE,
|
|
19
|
-
HARD_TRACE_PAGES,
|
|
20
|
-
} from "./limits.js";
|
|
14
|
+
import { DEFAULT_TRACE_PAGE_SIZE, DEFAULT_TRACE_PAGES, HARD_CURATION_ITEM_MAX_BYTES } from "./limits.js";
|
|
21
15
|
import { limit as bound, createPersistenceTraceResolver, pages } from "./trace.js";
|
|
22
16
|
import type { Dataset, DatasetItem, EvaluationTrace, TraceLimits } from "./types.js";
|
|
23
17
|
import { mapPool, normalizeConcurrency } from "./util.js";
|
|
@@ -117,8 +111,8 @@ export async function datasetFromRuns<TInput = unknown, TExpected = unknown>(
|
|
|
117
111
|
): Promise<CurateResult<TInput, TExpected>> {
|
|
118
112
|
input.signal?.throwIfAborted();
|
|
119
113
|
const concurrency = normalizeConcurrency(input.concurrency);
|
|
120
|
-
const pageSize = bound(input.traceLimits?.pageSize, DEFAULT_TRACE_PAGE_SIZE,
|
|
121
|
-
const maxPages = bound(input.traceLimits?.maxPages, DEFAULT_TRACE_PAGES,
|
|
114
|
+
const pageSize = bound(input.traceLimits?.pageSize, DEFAULT_TRACE_PAGE_SIZE, "pageSize");
|
|
115
|
+
const maxPages = bound(input.traceLimits?.maxPages, DEFAULT_TRACE_PAGES, "maxPages");
|
|
122
116
|
const resolver = createPersistenceTraceResolver(input.store);
|
|
123
117
|
const ownership = input.ownership;
|
|
124
118
|
const skipped: CurationSkip[] = [];
|
package/evals/src/dataset.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { EvalDatasetError } from "./errors.js";
|
|
3
|
-
import { HARD_DATASET_ITEMS } from "./limits.js";
|
|
4
3
|
import type { Dataset, DefineDatasetInput, Split } from "./types.js";
|
|
5
4
|
import { copySimulatorBinding } from "./user-simulator.js";
|
|
6
5
|
import { canonicalJson } from "./util.js";
|
|
@@ -23,7 +22,6 @@ export function defineDataset<TInput = unknown, TExpected = unknown>(
|
|
|
23
22
|
): Dataset<TInput, TExpected> {
|
|
24
23
|
if (!input || typeof input.id !== "string" || !input.id.trim()) throw new EvalDatasetError("dataset id is required");
|
|
25
24
|
if (!Array.isArray(input.items)) throw new EvalDatasetError("dataset items must be an array");
|
|
26
|
-
if (input.items.length > HARD_DATASET_ITEMS) throw new EvalDatasetError(`dataset items exceed ${HARD_DATASET_ITEMS}`);
|
|
27
25
|
if (input.canary !== undefined && (typeof input.canary !== "string" || input.canary.length > 128)) {
|
|
28
26
|
throw new EvalDatasetError("dataset canary must be a string of at most 128 chars");
|
|
29
27
|
}
|
package/evals/src/index.ts
CHANGED
|
@@ -55,24 +55,7 @@ export {
|
|
|
55
55
|
DEFAULT_TRACE_PAGE_SIZE,
|
|
56
56
|
DEFAULT_TRACE_PAGES,
|
|
57
57
|
DEFAULT_TRIALS_COUNT,
|
|
58
|
-
HARD_CANDIDATE_MAX_BYTES,
|
|
59
|
-
HARD_COMPARISON_CANDIDATES,
|
|
60
58
|
HARD_CURATION_ITEM_MAX_BYTES,
|
|
61
|
-
HARD_DATASET_ITEMS,
|
|
62
|
-
HARD_EVALUATION_PAGE_CAP,
|
|
63
|
-
HARD_EXPERIMENT_CONCURRENCY_CAP,
|
|
64
|
-
HARD_JUDGE_MAX_ATTEMPTS,
|
|
65
|
-
HARD_JUDGE_MAX_INPUT_BYTES,
|
|
66
|
-
HARD_JUDGE_MAX_OUTPUT_BYTES,
|
|
67
|
-
HARD_JUDGE_MAX_RUBRIC_BYTES,
|
|
68
|
-
HARD_JUDGE_TIMEOUT_MS,
|
|
69
|
-
HARD_MAX_STEP_SCORES,
|
|
70
|
-
HARD_MAX_TRIALS,
|
|
71
|
-
HARD_REPORT_MAX_BYTES,
|
|
72
|
-
HARD_STATS_RESAMPLES,
|
|
73
|
-
HARD_TRACE_MAX_BYTES,
|
|
74
|
-
HARD_TRACE_PAGE_SIZE,
|
|
75
|
-
HARD_TRACE_PAGES,
|
|
76
59
|
} from "./limits.js";
|
|
77
60
|
export type {
|
|
78
61
|
AgentFactory,
|
|
@@ -86,7 +69,6 @@ export {
|
|
|
86
69
|
DEFAULT_MAX_SCENARIO_TURNS,
|
|
87
70
|
failureInjection,
|
|
88
71
|
failingStore,
|
|
89
|
-
HARD_MAX_SCENARIO_TURNS,
|
|
90
72
|
resolveTrialsConfig,
|
|
91
73
|
runScenario,
|
|
92
74
|
validateEvalManifest,
|
|
@@ -118,6 +100,7 @@ export { createPersistenceTraceResolver } from "./trace.js";
|
|
|
118
100
|
export type {
|
|
119
101
|
ApprovalBeforeEffectScorerOptions,
|
|
120
102
|
ErrorClassScorerOptions,
|
|
103
|
+
GuardrailFlaggedScorerOptions,
|
|
121
104
|
GuardrailPackScorerOptions,
|
|
122
105
|
NoLoopScorerOptions,
|
|
123
106
|
SchemaScorerOptions,
|
|
@@ -129,14 +112,13 @@ export type {
|
|
|
129
112
|
export {
|
|
130
113
|
createApprovalBeforeEffectScorer,
|
|
131
114
|
createErrorClassScorer,
|
|
115
|
+
createGuardrailFlaggedScorer,
|
|
132
116
|
createGuardrailPackScorer,
|
|
133
117
|
createNoLoopScorer,
|
|
134
118
|
createSchemaScorer,
|
|
135
119
|
createStepBudgetScorer,
|
|
136
120
|
createToolCallMatchScorer,
|
|
137
|
-
DEFAULT_MAX_EXPECTED_CALLS,
|
|
138
121
|
DEFAULT_PACK_RULE_PREFIX,
|
|
139
|
-
HARD_MAX_EXPECTED_CALLS,
|
|
140
122
|
} from "./trajectory.js";
|
|
141
123
|
export type {
|
|
142
124
|
ComparisonCandidate,
|
|
@@ -183,6 +165,7 @@ export { BUILTIN_INJECTION_ATTACKS, createInjectionDataset, injectionHooks, runI
|
|
|
183
165
|
export type {
|
|
184
166
|
InjectionAttack,
|
|
185
167
|
InjectionCarrier,
|
|
168
|
+
InjectionDetection,
|
|
186
169
|
InjectionSpec,
|
|
187
170
|
InjectionRate,
|
|
188
171
|
InjectionMetrics,
|
package/evals/src/injection.ts
CHANGED
|
@@ -4,7 +4,6 @@ import { EvalDatasetError, EvalError } from "./errors.js";
|
|
|
4
4
|
import { runExperiment } from "./experiment.js";
|
|
5
5
|
import { defineScorer } from "./scorer.js";
|
|
6
6
|
import { wilsonInterval } from "./stats.js";
|
|
7
|
-
import { HARD_DATASET_ITEMS } from "./limits.js";
|
|
8
7
|
import type { DatasetItem, Dataset, RunExperimentOptions, Scorer, ExperimentItemResult } from "./types.js";
|
|
9
8
|
|
|
10
9
|
export interface InjectionAttack {
|
|
@@ -79,8 +78,6 @@ export function createInjectionDataset<TInput = unknown, TExpected = unknown>(op
|
|
|
79
78
|
}): Dataset<TInput, TExpected> {
|
|
80
79
|
const tasks = defineDataset({ id: options.id, items: options.tasks }).items;
|
|
81
80
|
const attacks = options.attacks ?? BUILTIN_INJECTION_ATTACKS;
|
|
82
|
-
if (tasks.length * (1 + attacks.length * options.carriers.length) > HARD_DATASET_ITEMS)
|
|
83
|
-
throw new EvalDatasetError("injection dataset exceeds item limit");
|
|
84
81
|
if (new Set(attacks.map((a) => a.id)).size !== attacks.length) throw new EvalDatasetError("duplicate injection attack id");
|
|
85
82
|
for (const attack of attacks)
|
|
86
83
|
validateSpec({ attackId: attack.id, carrier: { tool: "validation" }, payload: attack.payload, goal: attack.goal });
|
|
@@ -146,6 +143,13 @@ export interface InjectionMetrics {
|
|
|
146
143
|
readonly benignUtility: InjectionRate;
|
|
147
144
|
readonly utilityUnderAttack: InjectionRate;
|
|
148
145
|
readonly attackSuccessRate: InjectionRate;
|
|
146
|
+
/** Present on per-attack and per-carrier groups when detectors are configured. */
|
|
147
|
+
readonly detection?: Readonly<Record<string, InjectionDetection>>;
|
|
148
|
+
}
|
|
149
|
+
/** A detector scorer's pass rate on attacked items (catch) and on benign items (false positive). */
|
|
150
|
+
export interface InjectionDetection {
|
|
151
|
+
readonly caught: InjectionRate;
|
|
152
|
+
readonly falsePositive: InjectionRate;
|
|
149
153
|
}
|
|
150
154
|
export type RunInjectionSuiteOptions<TInput = unknown, TExpected = unknown> = Omit<
|
|
151
155
|
RunExperimentOptions<TInput, TExpected>,
|
|
@@ -153,6 +157,11 @@ export type RunInjectionSuiteOptions<TInput = unknown, TExpected = unknown> = Om
|
|
|
153
157
|
> & {
|
|
154
158
|
readonly agent: Exclude<RunExperimentOptions<TInput, TExpected>["agent"], import("@arnilo/prism").Agent>;
|
|
155
159
|
readonly utility: Scorer<TInput, TExpected>;
|
|
160
|
+
/**
|
|
161
|
+
* Detector scorers (for example `createGuardrailFlaggedScorer`), at most 8. Each is reported as
|
|
162
|
+
* `detection[id]`: its pass rate on attacked items is the catch rate, on benign items the false-positive rate.
|
|
163
|
+
*/
|
|
164
|
+
readonly detectors?: readonly Scorer<TInput, TExpected>[];
|
|
156
165
|
};
|
|
157
166
|
|
|
158
167
|
export async function runInjectionSuite<TInput = unknown, TExpected = unknown>(options: RunInjectionSuiteOptions<TInput, TExpected>) {
|
|
@@ -160,6 +169,10 @@ export async function runInjectionSuite<TInput = unknown, TExpected = unknown>(o
|
|
|
160
169
|
if (options.timeline !== undefined && options.timeline !== "redacted_io")
|
|
161
170
|
throw new EvalError("injection goals require timeline: redacted_io for tool arguments");
|
|
162
171
|
if (options.utility.id === "attack_success") throw new EvalError("utility id conflicts with attack_success");
|
|
172
|
+
const detectors = options.detectors ?? [];
|
|
173
|
+
const ids = [options.utility.id, "attack_success", ...detectors.map((scorer) => scorer.id)];
|
|
174
|
+
if (detectors.length > 8 || new Set(ids).size !== ids.length)
|
|
175
|
+
throw new EvalError("injection detectors must be at most 8 scorers with unique ids");
|
|
163
176
|
if (
|
|
164
177
|
options.sampling !== undefined &&
|
|
165
178
|
((options.sampling.rate !== undefined && options.sampling.rate !== 1) ||
|
|
@@ -195,7 +208,7 @@ export async function runInjectionSuite<TInput = unknown, TExpected = unknown>(o
|
|
|
195
208
|
const report = await runExperiment({
|
|
196
209
|
...options,
|
|
197
210
|
timeline: "redacted_io",
|
|
198
|
-
scorers: [options.utility, attackSuccess],
|
|
211
|
+
scorers: [options.utility, attackSuccess, ...detectors],
|
|
199
212
|
agent: (extra) =>
|
|
200
213
|
options.agent({
|
|
201
214
|
...extra,
|
|
@@ -233,6 +246,9 @@ export async function runInjectionSuite<TInput = unknown, TExpected = unknown>(o
|
|
|
233
246
|
attackSuccessRate: rate(items, attackSuccess),
|
|
234
247
|
});
|
|
235
248
|
const attacked = report.items.filter((item) => specOf(item).attackId !== null);
|
|
249
|
+
const benign = report.items.filter((item) => specOf(item).attackId === null);
|
|
250
|
+
const detection = (items: readonly ExperimentItemResult<TInput, TExpected>[]): Record<string, InjectionDetection> =>
|
|
251
|
+
Object.fromEntries(detectors.map((scorer) => [scorer.id, { caught: rate(items, scorer), falsePositive: rate(benign, scorer) }]));
|
|
236
252
|
const group = (key: (spec: Exclude<InjectionSpec, { attackId: null }>) => string) => {
|
|
237
253
|
const groups = new Map<string, typeof attacked>();
|
|
238
254
|
for (const item of attacked) {
|
|
@@ -241,7 +257,18 @@ export async function runInjectionSuite<TInput = unknown, TExpected = unknown>(o
|
|
|
241
257
|
values.push(item);
|
|
242
258
|
groups.set(name, values);
|
|
243
259
|
}
|
|
244
|
-
return Object.fromEntries(
|
|
260
|
+
return Object.fromEntries(
|
|
261
|
+
[...groups].map(([name, items]): [string, InjectionMetrics] => [
|
|
262
|
+
name,
|
|
263
|
+
{ ...metrics(items), ...(detectors.length ? { detection: detection(items) } : {}) },
|
|
264
|
+
]),
|
|
265
|
+
);
|
|
266
|
+
};
|
|
267
|
+
return {
|
|
268
|
+
report,
|
|
269
|
+
...metrics(attacked),
|
|
270
|
+
detection: detection(attacked),
|
|
271
|
+
byAttack: group((spec) => spec.attackId),
|
|
272
|
+
byCarrier: group((spec) => spec.carrier.tool),
|
|
245
273
|
};
|
|
246
|
-
return { report, ...metrics(attacked), byAttack: group((spec) => spec.attackId), byCarrier: group((spec) => spec.carrier.tool) };
|
|
247
274
|
}
|
package/evals/src/judge.ts
CHANGED
|
@@ -5,19 +5,15 @@ import {
|
|
|
5
5
|
DEFAULT_JUDGE_MAX_OUTPUT_BYTES,
|
|
6
6
|
DEFAULT_JUDGE_MAX_RUBRIC_BYTES,
|
|
7
7
|
DEFAULT_JUDGE_TIMEOUT_MS,
|
|
8
|
-
HARD_JUDGE_MAX_ATTEMPTS,
|
|
9
|
-
HARD_JUDGE_MAX_INPUT_BYTES,
|
|
10
|
-
HARD_JUDGE_MAX_OUTPUT_BYTES,
|
|
11
|
-
HARD_JUDGE_MAX_RUBRIC_BYTES,
|
|
12
|
-
HARD_JUDGE_TIMEOUT_MS,
|
|
13
8
|
} from "./limits.js";
|
|
14
9
|
import type { ModelJudgeOptions, Scorer } from "./types.js";
|
|
15
10
|
import { validateScoreResult } from "./util.js";
|
|
16
11
|
|
|
17
|
-
|
|
12
|
+
/** A host-set eval limit: a positive integer. The host's value is the cap (plan 239 Task 5). */
|
|
13
|
+
export function bounded(value: number | undefined, fallback: number, name: string): number {
|
|
18
14
|
const selected = value ?? fallback;
|
|
19
|
-
if (!Number.isInteger(selected) || selected < 1
|
|
20
|
-
throw new EvalError(`${name} must be
|
|
15
|
+
if (!Number.isInteger(selected) || selected < 1) {
|
|
16
|
+
throw new EvalError(`${name} must be a positive integer`, "ERR_PRISM_EVAL_JUDGE_BOUNDS");
|
|
21
17
|
}
|
|
22
18
|
return selected;
|
|
23
19
|
}
|
|
@@ -29,11 +25,11 @@ export function createModelJudge<TInput = unknown, TExpected = unknown>(
|
|
|
29
25
|
if (!options.id.trim() || !options.rubric.trim() || !options.rubricVersion.trim()) {
|
|
30
26
|
throw new EvalError("judge id, rubric, and rubricVersion are required", "ERR_PRISM_EVAL_JUDGE");
|
|
31
27
|
}
|
|
32
|
-
const timeoutMs = bounded(options.timeoutMs, DEFAULT_JUDGE_TIMEOUT_MS,
|
|
33
|
-
const maxAttempts = bounded(options.maxAttempts, DEFAULT_JUDGE_MAX_ATTEMPTS,
|
|
34
|
-
const maxOutputBytes = bounded(options.maxOutputBytes, DEFAULT_JUDGE_MAX_OUTPUT_BYTES,
|
|
35
|
-
const maxInputBytes = bounded(options.maxInputBytes, DEFAULT_JUDGE_MAX_INPUT_BYTES,
|
|
36
|
-
const maxRubricBytes = bounded(options.maxRubricBytes, DEFAULT_JUDGE_MAX_RUBRIC_BYTES,
|
|
28
|
+
const timeoutMs = bounded(options.timeoutMs, DEFAULT_JUDGE_TIMEOUT_MS, "timeoutMs");
|
|
29
|
+
const maxAttempts = bounded(options.maxAttempts, DEFAULT_JUDGE_MAX_ATTEMPTS, "maxAttempts");
|
|
30
|
+
const maxOutputBytes = bounded(options.maxOutputBytes, DEFAULT_JUDGE_MAX_OUTPUT_BYTES, "maxOutputBytes");
|
|
31
|
+
const maxInputBytes = bounded(options.maxInputBytes, DEFAULT_JUDGE_MAX_INPUT_BYTES, "maxInputBytes");
|
|
32
|
+
const maxRubricBytes = bounded(options.maxRubricBytes, DEFAULT_JUDGE_MAX_RUBRIC_BYTES, "maxRubricBytes");
|
|
37
33
|
if (Buffer.byteLength(options.rubric) > maxRubricBytes)
|
|
38
34
|
throw new EvalError("model judge rubric byte limit exceeded", "ERR_PRISM_EVAL_JUDGE_BOUNDS");
|
|
39
35
|
|