@arnilo/prism-hosts 0.0.0-stage → 0.13.1
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 +6197 -0
- package/host-builder/data/errors.json +558 -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 +255 -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 +318 -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 +68 -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,145 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { type Agent, createAgent, providerDone, providerTextDelta } from "@arnilo/prism";
|
|
3
|
+
import { mockProvider } from "@arnilo/prism/testing";
|
|
4
|
+
import {
|
|
5
|
+
calibrateJudge,
|
|
6
|
+
createJudgePanel,
|
|
7
|
+
createPairwiseJudge,
|
|
8
|
+
createRubricJudge,
|
|
9
|
+
defineDataset,
|
|
10
|
+
runComparison,
|
|
11
|
+
} from "@arnilo/prism-hosts/evals";
|
|
12
|
+
|
|
13
|
+
// Scripted verdicts demonstrate the API; they do not measure a real judge's quality.
|
|
14
|
+
async function mockAgent(model: string, replies: readonly string[]) {
|
|
15
|
+
return createAgent({
|
|
16
|
+
model: { provider: "mock", model },
|
|
17
|
+
packages: [mockProvider(replies.map((text) => [providerTextDelta(text), providerDone()]))],
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async function answer(agent: Agent, input: string, signal?: AbortSignal) {
|
|
22
|
+
const session = await agent.session();
|
|
23
|
+
try {
|
|
24
|
+
return await session.run(input, { signal });
|
|
25
|
+
} finally {
|
|
26
|
+
await session.close();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const started = performance.now();
|
|
31
|
+
const dataset = defineDataset({
|
|
32
|
+
id: "arithmetic",
|
|
33
|
+
version: "1",
|
|
34
|
+
items: Array.from({ length: 5 }, (_, i) => ({ id: `item-${i}`, input: "What is 2 + 2?", expected: "4" })),
|
|
35
|
+
});
|
|
36
|
+
const rubric = {
|
|
37
|
+
id: "correctness",
|
|
38
|
+
version: "1",
|
|
39
|
+
criteria: "Does the answer match the reference?",
|
|
40
|
+
scale: [
|
|
41
|
+
{ label: "no", score: 0, description: "Incorrect answer" },
|
|
42
|
+
{ label: "yes", score: 1, description: "Correct answer" },
|
|
43
|
+
],
|
|
44
|
+
};
|
|
45
|
+
const agents = await Promise.all([
|
|
46
|
+
mockAgent("candidate-a", ["4", "4", "5", "4", "5", "4"]),
|
|
47
|
+
mockAgent("candidate-b", ["2 + 2 = 4"]),
|
|
48
|
+
mockAgent(
|
|
49
|
+
"judge-a",
|
|
50
|
+
["yes", "yes", "yes", "no", "yes", "no", "yes"].map((label) =>
|
|
51
|
+
JSON.stringify({ reasoning: "Compared the answer with the reference.", label }),
|
|
52
|
+
),
|
|
53
|
+
),
|
|
54
|
+
mockAgent("judge-b", [JSON.stringify({ reasoning: "The answer is correct.", label: "yes" })]),
|
|
55
|
+
// Each item has one win per candidate across two trials, preserving a finite bootstrap fit.
|
|
56
|
+
mockAgent(
|
|
57
|
+
"judge-pair",
|
|
58
|
+
dataset.items
|
|
59
|
+
.flatMap(() => ["A", "B", "B", "A"])
|
|
60
|
+
.map((winner) => JSON.stringify({ reasoning: "Applied the comparison criteria.", winner })),
|
|
61
|
+
),
|
|
62
|
+
]);
|
|
63
|
+
const [candidateA, candidateB, judgeA, judgeB, pairAgent] = agents;
|
|
64
|
+
try {
|
|
65
|
+
const judge = createRubricJudge<string, string>({
|
|
66
|
+
agent: judgeA,
|
|
67
|
+
rubric,
|
|
68
|
+
judgedModel: candidateA.config.model,
|
|
69
|
+
reference: (item) => item.expected,
|
|
70
|
+
});
|
|
71
|
+
const [firstItem] = dataset.items;
|
|
72
|
+
assert.ok(firstItem);
|
|
73
|
+
const result = await answer(candidateA, firstItem.input);
|
|
74
|
+
const verdict = await judge.score({ item: firstItem, result });
|
|
75
|
+
assert.equal(verdict.metadata?.label, "yes");
|
|
76
|
+
assert.equal(verdict.score, 1);
|
|
77
|
+
console.log(judge.id, verdict.metadata?.label, verdict.score);
|
|
78
|
+
|
|
79
|
+
const panel = createJudgePanel({
|
|
80
|
+
id: "panel",
|
|
81
|
+
combine: "majority",
|
|
82
|
+
judges: [
|
|
83
|
+
judge,
|
|
84
|
+
createRubricJudge<string, string>({
|
|
85
|
+
id: "correctness-b",
|
|
86
|
+
agent: judgeB,
|
|
87
|
+
rubric,
|
|
88
|
+
judgedModel: candidateA.config.model,
|
|
89
|
+
reference: (item) => item.expected,
|
|
90
|
+
}),
|
|
91
|
+
],
|
|
92
|
+
});
|
|
93
|
+
const combined = await panel.score({ item: firstItem, result });
|
|
94
|
+
assert.equal(combined.metadata?.failedJudges, 0);
|
|
95
|
+
assert.equal(combined.metadata?.label, "yes");
|
|
96
|
+
assert.equal(combined.score, 1);
|
|
97
|
+
console.log(panel.id, combined.metadata?.label, combined.score);
|
|
98
|
+
|
|
99
|
+
const items = [];
|
|
100
|
+
for (const [i, item] of dataset.items.entries()) {
|
|
101
|
+
items.push({ item, result: await answer(candidateA, item.input), humanScore: i % 2 === 0 ? 1 : 0 });
|
|
102
|
+
}
|
|
103
|
+
const calibration = await calibrateJudge({ judge, items, seed: 1 });
|
|
104
|
+
assert.equal(calibration.n, 5);
|
|
105
|
+
assert.equal(calibration.judgeFailures, 0);
|
|
106
|
+
assert.equal(calibration.cohensKappa, 1);
|
|
107
|
+
console.log(judge.id, calibration.n, calibration.cohensKappa);
|
|
108
|
+
|
|
109
|
+
const leftModel = candidateA.config.model;
|
|
110
|
+
const rightModel = candidateB.config.model;
|
|
111
|
+
assert.ok(leftModel);
|
|
112
|
+
assert.ok(rightModel);
|
|
113
|
+
const pairwise = createPairwiseJudge<string, string>({
|
|
114
|
+
agent: pairAgent,
|
|
115
|
+
rubric: { id: "preference", version: "1", criteria: "Prefer the clearer correct answer." },
|
|
116
|
+
judgedModels: { left: leftModel, right: rightModel },
|
|
117
|
+
});
|
|
118
|
+
const comparison = await runComparison({
|
|
119
|
+
dataset,
|
|
120
|
+
trials: 2,
|
|
121
|
+
seed: 1,
|
|
122
|
+
concurrency: 1,
|
|
123
|
+
candidates: {
|
|
124
|
+
a: (item, signal) => answer(candidateA, item.input, signal),
|
|
125
|
+
b: (item, signal) => answer(candidateB, item.input, signal),
|
|
126
|
+
},
|
|
127
|
+
scorers: [pairwise],
|
|
128
|
+
});
|
|
129
|
+
assert.equal(comparison.failures, 0);
|
|
130
|
+
assert.equal(comparison.records.length, 10);
|
|
131
|
+
assert.deepEqual(comparison.wins, { a: 5, b: 5 });
|
|
132
|
+
assert.equal(comparison.positionConsistency[pairwise.id], 1);
|
|
133
|
+
assert.equal(comparison.ranking.length, 2);
|
|
134
|
+
console.log(pairwise.id, comparison.positionConsistency[pairwise.id]);
|
|
135
|
+
for (const row of comparison.ranking) {
|
|
136
|
+
assert.equal(row.strength, 1);
|
|
137
|
+
assert.deepEqual(row.ci95, [1, 1]);
|
|
138
|
+
assert.equal(row.rank, 1);
|
|
139
|
+
assert.ok(row.ci95);
|
|
140
|
+
console.log(row.scorerId, row.candidate, row.strength, ...row.ci95, row.rank);
|
|
141
|
+
}
|
|
142
|
+
assert.ok(performance.now() - started < 10_000, "judge example exceeded 10 seconds");
|
|
143
|
+
} finally {
|
|
144
|
+
await Promise.all(agents.map((agent) => agent.dispose()));
|
|
145
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { createAgent, providerDone, providerTextDelta } from "@arnilo/prism";
|
|
2
|
+
import { defineDataset, defineScorer, estimateOnline, runExperiment, scoreRunLive } from "@arnilo/prism-hosts/evals";
|
|
3
|
+
import { createMemoryEvaluationStore } from "@arnilo/prism-extensions/store-codecs";
|
|
4
|
+
import { mockProvider } from "@arnilo/prism/testing";
|
|
5
|
+
|
|
6
|
+
const scorer = defineScorer({
|
|
7
|
+
id: "contains-citation",
|
|
8
|
+
score: ({ result }) => ({
|
|
9
|
+
score: result.text.includes("[") ? 1 : 0,
|
|
10
|
+
reason: result.text.includes("[") ? "found citation marker" : "missing citation marker",
|
|
11
|
+
}),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const dataset = defineDataset({
|
|
15
|
+
id: "citations",
|
|
16
|
+
version: "1",
|
|
17
|
+
items: [
|
|
18
|
+
{ id: "1", input: "Summarize Prism with a citation" },
|
|
19
|
+
{ id: "2", input: "Say hello" },
|
|
20
|
+
],
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const agent = await createAgent({
|
|
24
|
+
model: { provider: "mock", model: "demo" },
|
|
25
|
+
packages: [
|
|
26
|
+
mockProvider([
|
|
27
|
+
[providerTextDelta("Prism is an agent harness [1]."), providerDone()],
|
|
28
|
+
[providerTextDelta("Hello there."), providerDone()],
|
|
29
|
+
[providerTextDelta("Follow up [2]."), providerDone()],
|
|
30
|
+
[providerTextDelta("Another note [3]."), providerDone()],
|
|
31
|
+
]),
|
|
32
|
+
],
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
const store = createMemoryEvaluationStore();
|
|
36
|
+
const report = await runExperiment({
|
|
37
|
+
agent,
|
|
38
|
+
dataset,
|
|
39
|
+
scorers: [scorer],
|
|
40
|
+
concurrency: 2,
|
|
41
|
+
store,
|
|
42
|
+
ownership: { tenantId: "demo" },
|
|
43
|
+
experimentId: "demo-exp",
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
console.log("experiment", report.experimentId, report.aggregate);
|
|
47
|
+
|
|
48
|
+
const session = await agent.session();
|
|
49
|
+
const liveResult1 = await session.run("Follow up with [2]");
|
|
50
|
+
const liveResult2 = await session.run("Follow up with [3]");
|
|
51
|
+
const liveRecords = [
|
|
52
|
+
...(await scoreRunLive(liveResult1, {
|
|
53
|
+
scorers: [scorer],
|
|
54
|
+
sampling: {
|
|
55
|
+
rate: 0.5,
|
|
56
|
+
strata: (r) => r.status,
|
|
57
|
+
rates: { completed: 1 },
|
|
58
|
+
always: (r) => r.status !== "completed",
|
|
59
|
+
},
|
|
60
|
+
seed: 1,
|
|
61
|
+
store,
|
|
62
|
+
ownership: { tenantId: "demo" },
|
|
63
|
+
})),
|
|
64
|
+
...(await scoreRunLive(liveResult2, {
|
|
65
|
+
scorers: [scorer],
|
|
66
|
+
sampling: {
|
|
67
|
+
rate: 0.5,
|
|
68
|
+
strata: (r) => r.status,
|
|
69
|
+
rates: { completed: 1 },
|
|
70
|
+
always: (r) => r.status !== "completed",
|
|
71
|
+
},
|
|
72
|
+
seed: 2,
|
|
73
|
+
store,
|
|
74
|
+
ownership: { tenantId: "demo" },
|
|
75
|
+
})),
|
|
76
|
+
];
|
|
77
|
+
|
|
78
|
+
const onlineEstimate = estimateOnline(liveRecords, { scorerId: "contains-citation", seed: 1 });
|
|
79
|
+
console.log("online estimate", onlineEstimate);
|
|
80
|
+
|
|
81
|
+
const page = await store.query({ tenantId: "demo", experimentId: "demo-exp" });
|
|
82
|
+
console.log(
|
|
83
|
+
"stored evaluations",
|
|
84
|
+
page.items.length,
|
|
85
|
+
page.items.map((item) => item.score),
|
|
86
|
+
);
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { createAgent, providerDone, providerTextDelta } from "@arnilo/prism";
|
|
2
|
+
import { assertEvaluationThreshold, defineDataset, defineScorer, powerAnalysis, runExperiment } from "@arnilo/prism-hosts/evals";
|
|
3
|
+
import { mockProvider } from "@arnilo/prism/testing";
|
|
4
|
+
|
|
5
|
+
const dataset = defineDataset({
|
|
6
|
+
id: "citations",
|
|
7
|
+
version: "1",
|
|
8
|
+
items: Array.from({ length: 20 }, (_, i) => ({ id: String(i), input: "cite" })),
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
async function evaluate(text: string) {
|
|
12
|
+
const agent = await createAgent({
|
|
13
|
+
model: { provider: "mock", model: "demo" },
|
|
14
|
+
packages: [mockProvider([[providerTextDelta(text), providerDone()]])],
|
|
15
|
+
});
|
|
16
|
+
try {
|
|
17
|
+
return await runExperiment({
|
|
18
|
+
agent,
|
|
19
|
+
dataset,
|
|
20
|
+
scorers: [defineScorer({ id: "citation", score: ({ result }) => ({ score: result.text.includes("[") ? 1 : 0 }) })],
|
|
21
|
+
});
|
|
22
|
+
} finally {
|
|
23
|
+
await agent.dispose();
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const baseline = await evaluate("answer [1]");
|
|
28
|
+
const candidate = await evaluate("updated answer [1]");
|
|
29
|
+
assertEvaluationThreshold(candidate, {
|
|
30
|
+
minimumMacroMean: 0.9,
|
|
31
|
+
maximumFailures: 0,
|
|
32
|
+
minimumLowerBound: { citation: 0.8 },
|
|
33
|
+
maximumRegression: { baseline, delta: 0.02 },
|
|
34
|
+
});
|
|
35
|
+
console.log(
|
|
36
|
+
JSON.stringify({
|
|
37
|
+
mean: candidate.aggregate.macroMean,
|
|
38
|
+
plannedDataset: powerAnalysis({ baselinePassRate: 0.85, minimumDetectableDrop: 0.05 }),
|
|
39
|
+
}),
|
|
40
|
+
);
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { createWorkflowTransitionChannel, type WorkflowEvent } from "@arnilo/prism-extensions/workflows";
|
|
2
|
+
import { createAgent, providerDone, providerTextDelta, providerUsage } from "@arnilo/prism";
|
|
3
|
+
import { createTimelineFolder, projectWorkflowTimeline, summarizeTimeline } from "@arnilo/prism-extensions/observability";
|
|
4
|
+
import {
|
|
5
|
+
agentNode,
|
|
6
|
+
createMemoryWorkflowCheckpoints,
|
|
7
|
+
defineWorkflow,
|
|
8
|
+
functionNode,
|
|
9
|
+
projectWorkflowGraphRun,
|
|
10
|
+
runWorkflow,
|
|
11
|
+
serializeWorkflowGraph,
|
|
12
|
+
workflowGraphToMermaid,
|
|
13
|
+
} from "@arnilo/prism-extensions/workflows";
|
|
14
|
+
import { mockProvider, createMockProvider } from "@arnilo/prism/testing";
|
|
15
|
+
import { providerPackage } from "@arnilo/prism/provider-kit";
|
|
16
|
+
|
|
17
|
+
// ============================================================================
|
|
18
|
+
// 1. Setup a 2-node workflow (extract → analyze) using mock providers
|
|
19
|
+
// ============================================================================
|
|
20
|
+
|
|
21
|
+
const provider = createMockProvider([
|
|
22
|
+
providerTextDelta("Entity extraction: found PRISM-072 and telemetry-seam."),
|
|
23
|
+
providerUsage({ inputTokens: 40, outputTokens: 20, totalTokens: 60 }),
|
|
24
|
+
providerDone(),
|
|
25
|
+
]);
|
|
26
|
+
|
|
27
|
+
const extractorAgent = await createAgent({
|
|
28
|
+
model: { provider: "mock", model: "demo" },
|
|
29
|
+
packages: [providerPackage("test-provider", [provider])],
|
|
30
|
+
tools: { add: [] },
|
|
31
|
+
instructions: "You extract technical entity names from input documents.",
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// Node 1: Agent node that extracts entities from raw input
|
|
35
|
+
const extractNode = agentNode({
|
|
36
|
+
agent: extractorAgent,
|
|
37
|
+
input: (ctx) => ({ text: ctx.workflowInput }),
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
// Node 2: Function node that synthesizes downstream output
|
|
41
|
+
const analyzeNode = functionNode({
|
|
42
|
+
execute: async (ctx) => {
|
|
43
|
+
const extracted = (ctx.upstream.extract as { text?: string } | undefined)?.text ?? "";
|
|
44
|
+
return {
|
|
45
|
+
analysis: `Analyzed entities from previous step: ${extracted.slice(0, 30)}...`,
|
|
46
|
+
confidence: 0.95,
|
|
47
|
+
};
|
|
48
|
+
},
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
const workflow = defineWorkflow({
|
|
52
|
+
id: "extract-and-analyze",
|
|
53
|
+
revision: "1.0.0",
|
|
54
|
+
nodes: {
|
|
55
|
+
extract: extractNode,
|
|
56
|
+
analyze: analyzeNode,
|
|
57
|
+
},
|
|
58
|
+
edges: [["extract", "analyze"]],
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
// ============================================================================
|
|
62
|
+
// 2. Run workflow, collect events and checkpoints
|
|
63
|
+
// ============================================================================
|
|
64
|
+
|
|
65
|
+
const events: WorkflowEvent[] = [];
|
|
66
|
+
const checkpoints = createMemoryWorkflowCheckpoints();
|
|
67
|
+
const ownership = { tenantId: "tenant-demo" };
|
|
68
|
+
|
|
69
|
+
const runResult = await runWorkflow(workflow, "Prism execution timeline provides host cockpit waterfalls and trajectory evals.", {
|
|
70
|
+
checkpoints,
|
|
71
|
+
ownership,
|
|
72
|
+
transitions: workflowEvents((event) => {
|
|
73
|
+
events.push(event);
|
|
74
|
+
}),
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
// ============================================================================
|
|
78
|
+
// 3. Project ExecutionTimeline & summarize for host dashboard / cockpit
|
|
79
|
+
// ============================================================================
|
|
80
|
+
|
|
81
|
+
const checkpointRecord = await checkpoints.load({
|
|
82
|
+
workflowId: workflow.id,
|
|
83
|
+
runId: runResult.runId,
|
|
84
|
+
ownership,
|
|
85
|
+
});
|
|
86
|
+
const checkpoint = checkpointRecord?.value;
|
|
87
|
+
|
|
88
|
+
// By default, content: "metadata" retains no raw prompt or output strings.
|
|
89
|
+
// To opt into redacted step I/O:
|
|
90
|
+
// content: "redacted_io",
|
|
91
|
+
// redactor: createSecretRedactor({ patterns: [/(?:sk-[A-Za-z0-9_-]{10,})/g] }),
|
|
92
|
+
const timeline = projectWorkflowTimeline(events, {
|
|
93
|
+
content: "metadata",
|
|
94
|
+
checkpoint,
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const summary = summarizeTimeline(timeline);
|
|
98
|
+
|
|
99
|
+
// ============================================================================
|
|
100
|
+
// 4. Serialize workflow graph and export Mermaid visualization
|
|
101
|
+
// ============================================================================
|
|
102
|
+
|
|
103
|
+
const graph = serializeWorkflowGraph(workflow);
|
|
104
|
+
const mermaid = workflowGraphToMermaid(graph);
|
|
105
|
+
const graphOverlay = projectWorkflowGraphRun(graph, timeline);
|
|
106
|
+
|
|
107
|
+
// ============================================================================
|
|
108
|
+
// 5. Demonstrate live incremental folding from agent session
|
|
109
|
+
// ============================================================================
|
|
110
|
+
|
|
111
|
+
const liveAgent = await createAgent({
|
|
112
|
+
model: { provider: "mock", model: "demo" },
|
|
113
|
+
packages: [
|
|
114
|
+
mockProvider([
|
|
115
|
+
[
|
|
116
|
+
providerTextDelta("Streaming timeline fold example."),
|
|
117
|
+
providerUsage({ inputTokens: 10, outputTokens: 5, totalTokens: 15 }),
|
|
118
|
+
providerDone(),
|
|
119
|
+
],
|
|
120
|
+
]),
|
|
121
|
+
],
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const session = await liveAgent.session();
|
|
125
|
+
const folder = createTimelineFolder({ content: "metadata" });
|
|
126
|
+
|
|
127
|
+
// Subscribe before starting the run: `session.run` emits `run.started` before it returns, so a
|
|
128
|
+
// subscriber attached afterwards misses the run identity (`timeline.runId` stays empty).
|
|
129
|
+
const subscription = session.subscribe();
|
|
130
|
+
const consume = (async () => {
|
|
131
|
+
for await (const event of subscription) {
|
|
132
|
+
folder.push(event);
|
|
133
|
+
}
|
|
134
|
+
})();
|
|
135
|
+
const agentResult = await session.run("Stream events");
|
|
136
|
+
await consume;
|
|
137
|
+
|
|
138
|
+
const liveTimeline = folder.snapshot();
|
|
139
|
+
const liveSummary = summarizeTimeline(liveTimeline);
|
|
140
|
+
|
|
141
|
+
// ============================================================================
|
|
142
|
+
// Print outputs
|
|
143
|
+
// ============================================================================
|
|
144
|
+
|
|
145
|
+
console.log(
|
|
146
|
+
JSON.stringify({
|
|
147
|
+
workflowRunId: runResult.runId,
|
|
148
|
+
workflowStatus: runResult.status,
|
|
149
|
+
timelineStepCount: timeline.steps.length,
|
|
150
|
+
timelineSummary: {
|
|
151
|
+
durationMs: summary.durationMs,
|
|
152
|
+
providerAttempts: summary.providerAttempts,
|
|
153
|
+
totalTokens: summary.usage?.totalTokens,
|
|
154
|
+
status: summary.status,
|
|
155
|
+
},
|
|
156
|
+
graphNodes: graph.nodes.map((n) => n.id),
|
|
157
|
+
graphOverlayNodeStatuses: Object.fromEntries(graphOverlay.nodes.map((n) => [n.id, n.run?.status])),
|
|
158
|
+
liveAgentRunId: agentResult.runId,
|
|
159
|
+
liveAgentStepCount: liveTimeline.steps.length,
|
|
160
|
+
liveAgentTokens: liveSummary.usage?.totalTokens,
|
|
161
|
+
}),
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
console.log("\n--- Workflow Mermaid Diagram ---");
|
|
165
|
+
console.log(mermaid);
|
|
166
|
+
|
|
167
|
+
function workflowEvents(consume: (event: WorkflowEvent) => void) {
|
|
168
|
+
const channel = createWorkflowTransitionChannel({ workflowId: "events", runId: "events" });
|
|
169
|
+
void (async () => {
|
|
170
|
+
for await (const event of channel.subscribe()) consume(event);
|
|
171
|
+
})();
|
|
172
|
+
return channel;
|
|
173
|
+
}
|