@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,19 @@
|
|
|
1
|
+
import type { Skill } from "@arnilo/prism";
|
|
2
|
+
import { createSkillRegistry, resolveActiveSkills } from "@arnilo/prism";
|
|
3
|
+
|
|
4
|
+
// Skill registry with progressive disclosure: skills activate by name and may
|
|
5
|
+
// declare which tool names they need. Skills cannot register missing tools or
|
|
6
|
+
// grant permissions by themselves.
|
|
7
|
+
export function demo() {
|
|
8
|
+
const summarize: Skill = {
|
|
9
|
+
name: "summarize",
|
|
10
|
+
description: "Summarize the conversation",
|
|
11
|
+
instructions: "Produce a concise summary.",
|
|
12
|
+
toolNames: [],
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const registry = createSkillRegistry([summarize]);
|
|
16
|
+
const active = resolveActiveSkills({ registry, names: ["summarize"], tools: [] });
|
|
17
|
+
|
|
18
|
+
return { count: active.length, first: active[0]?.name };
|
|
19
|
+
}
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { spawnSync } from "node:child_process";
|
|
3
|
+
import { mkdtempSync, rmSync } from "node:fs";
|
|
4
|
+
import { tmpdir } from "node:os";
|
|
5
|
+
import { join } from "node:path";
|
|
6
|
+
import { createAgent, definePackage } from "@arnilo/prism";
|
|
7
|
+
import { mockProvider, providerDone, providerTextDelta } from "@arnilo/prism/testing";
|
|
8
|
+
import { sqliteStore } from "@arnilo/prism-extensions/store-sqlite";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* A session survives a process restart on the SQLite store (roadmap Phase 6 Done):
|
|
12
|
+
*
|
|
13
|
+
* - process A lists `sqliteStore({ path })`, runs two turns, and bumps a counter the stand-in package
|
|
14
|
+
* keeps in `prism.state.session` (one `package_state` entry per write, on the session's branch);
|
|
15
|
+
* - A spawns process B over the same database file and session id; B builds a new agent, reopens the
|
|
16
|
+
* session with `agent.session({ id })`, and prints the message count and the counter value;
|
|
17
|
+
* - A asserts B's output: another pid, the same session, the same messages, and the counter the durable
|
|
18
|
+
* state carried across the process boundary.
|
|
19
|
+
*
|
|
20
|
+
* The stand-in package is defined inline with `definePackage` — no internal seam. Imports only
|
|
21
|
+
* `@arnilo/prism`, `@arnilo/prism/testing`, and `@arnilo/prism-extensions/store-sqlite`; no credential, no network.
|
|
22
|
+
* Run: bun examples/sqlite-resume.ts
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
const MODEL = { provider: "mock", model: "demo" } as const;
|
|
26
|
+
const DEFAULT_STEP = 1;
|
|
27
|
+
|
|
28
|
+
interface CounterConfig {
|
|
29
|
+
readonly step?: number;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const counter = definePackage<CounterConfig>({
|
|
33
|
+
name: "@acme/sqlite-counter",
|
|
34
|
+
version: "1.0.0",
|
|
35
|
+
description: "Bumps a counter kept in session state.",
|
|
36
|
+
requires: { api: 1 },
|
|
37
|
+
capabilities: ["session-state"],
|
|
38
|
+
config: {
|
|
39
|
+
type: "object",
|
|
40
|
+
properties: { step: { type: "integer", minimum: 1, default: DEFAULT_STEP } },
|
|
41
|
+
additionalProperties: false,
|
|
42
|
+
},
|
|
43
|
+
setup(prism) {
|
|
44
|
+
const total = prism.state.session("total", { n: 0 });
|
|
45
|
+
const step = prism.config.step ?? DEFAULT_STEP;
|
|
46
|
+
prism.commands.register({
|
|
47
|
+
name: "bump",
|
|
48
|
+
description: "Adds one step to the session total.",
|
|
49
|
+
run: async (_args, { session }) => {
|
|
50
|
+
if (!session) throw new Error("bump needs a session");
|
|
51
|
+
const next = { n: total.get(session).n + step };
|
|
52
|
+
await total.set(session, next);
|
|
53
|
+
return next.n;
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
prism.commands.register({
|
|
57
|
+
name: "total",
|
|
58
|
+
description: "Reads the session total.",
|
|
59
|
+
run: (_args, { session }) => {
|
|
60
|
+
if (!session) throw new Error("total needs a session");
|
|
61
|
+
return total.get(session).n;
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
function build(dir: string) {
|
|
68
|
+
return createAgent({
|
|
69
|
+
id: "sqlite-resume-demo",
|
|
70
|
+
model: MODEL,
|
|
71
|
+
packages: [
|
|
72
|
+
sqliteStore({ path: join(dir, "sessions.db") }),
|
|
73
|
+
counter({ step: DEFAULT_STEP }),
|
|
74
|
+
mockProvider([
|
|
75
|
+
[providerTextDelta("First turn."), providerDone()],
|
|
76
|
+
[providerTextDelta("Second turn."), providerDone()],
|
|
77
|
+
]),
|
|
78
|
+
],
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
type PhaseB = {
|
|
83
|
+
readonly phase: string;
|
|
84
|
+
readonly pid: number;
|
|
85
|
+
readonly sessionId: string;
|
|
86
|
+
readonly messageCount: number;
|
|
87
|
+
readonly counter: number;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/** Process A: write a session and package state, then assert what a fresh process reads back. */
|
|
91
|
+
async function phaseA(script: string): Promise<Record<string, unknown>> {
|
|
92
|
+
const dir = mkdtempSync(join(tmpdir(), "prism-sqlite-resume-"));
|
|
93
|
+
try {
|
|
94
|
+
const agent = await build(dir);
|
|
95
|
+
const session = await agent.session();
|
|
96
|
+
await session.run("first turn");
|
|
97
|
+
const afterFirst = await agent.commands.run("bump", {}, { session });
|
|
98
|
+
await session.run("second turn");
|
|
99
|
+
const afterSecond = await agent.commands.run("bump", {}, { session });
|
|
100
|
+
const messages = await session.messages();
|
|
101
|
+
await agent.dispose();
|
|
102
|
+
|
|
103
|
+
const child = spawnSync("bun", [script, "--phase=b", dir, session.id], { encoding: "utf8" });
|
|
104
|
+
assert.equal(child.status, 0, `phase B exited ${child.status}\n${child.stderr}`);
|
|
105
|
+
const b = JSON.parse(child.stdout.trim().split("\n").at(-1) ?? "{}") as PhaseB;
|
|
106
|
+
assert.equal(b.phase, "b", "phase B must report its phase");
|
|
107
|
+
assert.notEqual(b.pid, process.pid, "phase B must be another process");
|
|
108
|
+
assert.equal(b.sessionId, session.id, "phase B must reopen the same session id");
|
|
109
|
+
assert.equal(b.messageCount, messages.length, "phase B must see the same messages");
|
|
110
|
+
assert.equal(b.counter, afterSecond, "phase B must read the counter the store carried");
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
phase: "a",
|
|
114
|
+
sessionId: session.id,
|
|
115
|
+
messageCount: messages.length,
|
|
116
|
+
counter: { afterFirst, afterSecond },
|
|
117
|
+
child: b,
|
|
118
|
+
};
|
|
119
|
+
} finally {
|
|
120
|
+
rmSync(dir, { recursive: true, force: true });
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Process B: a new agent over the same file, resuming by session id. */
|
|
125
|
+
async function phaseB(dir: string, sessionId: string): Promise<PhaseB> {
|
|
126
|
+
const agent = await build(dir);
|
|
127
|
+
const session = await agent.session({ id: sessionId });
|
|
128
|
+
const messages = await session.messages();
|
|
129
|
+
const counter = await agent.commands.run("total", {}, { session });
|
|
130
|
+
await agent.dispose();
|
|
131
|
+
return { phase: "b", pid: process.pid, sessionId: session.id, messageCount: messages.length, counter: Number(counter) };
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
export async function demo(): Promise<Record<string, unknown>> {
|
|
135
|
+
const args = process.argv.slice(2);
|
|
136
|
+
const phase = args.find((arg) => arg.startsWith("--phase="))?.slice("--phase=".length) ?? "a";
|
|
137
|
+
if (phase === "b") {
|
|
138
|
+
const [dir, sessionId] = args.filter((arg) => !arg.startsWith("--phase="));
|
|
139
|
+
if (!dir || !sessionId) throw new Error("phase B needs a database directory and a session id");
|
|
140
|
+
return phaseB(dir, sessionId);
|
|
141
|
+
}
|
|
142
|
+
const script = process.argv[1];
|
|
143
|
+
if (!script) throw new Error("phase A needs its own script path to spawn process B");
|
|
144
|
+
return phaseA(script);
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (import.meta.url === `file://${process.argv[1]}`) console.log(JSON.stringify(await demo()));
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { mkdir, mkdtemp, writeFile } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import type { ProviderRequest, SystemPromptContribution } from "@arnilo/prism";
|
|
5
|
+
import { composeSystemPrompt, createAgent, providerDone } from "@arnilo/prism";
|
|
6
|
+
import { providerPackage } from "@arnilo/prism/provider-kit";
|
|
7
|
+
import { createMockProvider } from "@arnilo/prism/testing";
|
|
8
|
+
import { contextFiles, readContextFileLayers } from "@arnilo/prism-extensions/context-files";
|
|
9
|
+
|
|
10
|
+
// Context files: AGENTS.md (workspace, source: app) and SYSTEM.md (source: user) load as
|
|
11
|
+
// system-prompt layers through `@arnilo/prism-extensions/context-files`, which registers one
|
|
12
|
+
// `context.build` handler and composes them with `AgentConfig.instructions` (the base) via the
|
|
13
|
+
// kernel's `composeSystemPrompt`. The package is trust-gated, reads no home directory unless
|
|
14
|
+
// `globalRoot` is set, and caches the files per session.
|
|
15
|
+
//
|
|
16
|
+
// This demo builds a temp workspace + temp global root, writes the two files, shows the layers
|
|
17
|
+
// the package resolves, then runs a mock agent with the package loaded and prints the composed
|
|
18
|
+
// system instruction that reached the provider request — proving the order
|
|
19
|
+
// (base → SYSTEM.md → AGENTS.md) without any network or real credentials.
|
|
20
|
+
|
|
21
|
+
export async function demo(): Promise<{ composed: string; reachedProvider: boolean }> {
|
|
22
|
+
const workspace = await mkdtemp(join(tmpdir(), "prism-sp-example-ws-"));
|
|
23
|
+
const global = await mkdtemp(join(tmpdir(), "prism-sp-example-glob-"));
|
|
24
|
+
await mkdir(join(global, ".prism", "agent"), { recursive: true });
|
|
25
|
+
await writeFile(join(global, ".prism", "agent", "SYSTEM.md"), "Global system policy.");
|
|
26
|
+
await writeFile(join(workspace, "AGENTS.md"), "Project rule.");
|
|
27
|
+
|
|
28
|
+
// The same layering a host gets by loading the package, exposed directly for libraries that
|
|
29
|
+
// compose the prompt themselves.
|
|
30
|
+
const layers: readonly SystemPromptContribution[] = await readContextFileLayers({ workspaceRoot: workspace, globalRoot: global });
|
|
31
|
+
const composed = composeSystemPrompt(layers, { base: "You are helpful." }) ?? "";
|
|
32
|
+
|
|
33
|
+
const captured: ProviderRequest[] = [];
|
|
34
|
+
const provider = createMockProvider([providerDone()], {
|
|
35
|
+
onRequest: (request) => {
|
|
36
|
+
captured.push(request);
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
const session = await (
|
|
40
|
+
await createAgent({
|
|
41
|
+
model: { provider: "mock", model: "demo" },
|
|
42
|
+
packages: [providerPackage("test-provider", [provider]), contextFiles({ root: workspace, globalRoot: global })],
|
|
43
|
+
instructions: "You are helpful.",
|
|
44
|
+
})
|
|
45
|
+
).session();
|
|
46
|
+
|
|
47
|
+
// Fire run() (resolves into closeSubscribers) and drain the event stream in
|
|
48
|
+
// parallel — subscribe() only ends once run completes and closes the stream.
|
|
49
|
+
const done = session.run("Hi");
|
|
50
|
+
for await (const _event of session.subscribe()) {
|
|
51
|
+
void _event;
|
|
52
|
+
}
|
|
53
|
+
await done;
|
|
54
|
+
|
|
55
|
+
const input =
|
|
56
|
+
captured[0]?.messages
|
|
57
|
+
.flatMap((m) => m.content)
|
|
58
|
+
.map((block) => (block.type === "text" ? block.text : ""))
|
|
59
|
+
.join("\n") ?? "";
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
composed,
|
|
63
|
+
reachedProvider: input.includes("You are helpful.") && input.includes("Global system policy.") && input.includes("Project rule."),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// Runnable smoke test: `node examples/system-project-prompts.ts`. Network-free.
|
|
68
|
+
export async function main(): Promise<void> {
|
|
69
|
+
console.log(JSON.stringify(await demo()));
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
73
|
+
await main();
|
|
74
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { composeSystemPrompt, mergeSystemPromptConfig } from "@arnilo/prism";
|
|
2
|
+
|
|
3
|
+
// Layered system prompt composition: user, package, app, then run order (Phase 31: user is the global base).
|
|
4
|
+
// RunOptions.systemPrompt: false disables configured layers while keeping
|
|
5
|
+
// AgentConfig.instructions as the simple direct path.
|
|
6
|
+
export function demo() {
|
|
7
|
+
const config = [
|
|
8
|
+
{ id: "pkg", source: "package", mode: "append" as const, text: "Package policy." },
|
|
9
|
+
{ id: "app", source: "app", mode: "append" as const, text: "App policy." },
|
|
10
|
+
];
|
|
11
|
+
const run = [{ id: "run", source: "run", mode: "append" as const, text: "Run note." }];
|
|
12
|
+
|
|
13
|
+
const merged = mergeSystemPromptConfig(config, run);
|
|
14
|
+
const prompt = composeSystemPrompt(merged, { base: "You are helpful." });
|
|
15
|
+
|
|
16
|
+
// Disabling layers for a run:
|
|
17
|
+
const disabled = composeSystemPrompt(false, { base: "You are helpful." });
|
|
18
|
+
return { prompt, disabled };
|
|
19
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Explicit host composition for Phase 10 Channels. Calling this function (not importing it)
|
|
2
|
+
// verifies the Bot API token, acquires the receiver lease and begins long polling.
|
|
3
|
+
// Private DMs are always admitted; set `options.allowGroups` to also parse group/topic text
|
|
4
|
+
// (the host `authorize` still decides per chat, topic and sender).
|
|
5
|
+
import type { Agent } from "@arnilo/prism";
|
|
6
|
+
import {
|
|
7
|
+
connectTelegram,
|
|
8
|
+
type ChannelConnectionHandle,
|
|
9
|
+
type TelegramConnectOptions,
|
|
10
|
+
createTelegramWebhookHandler,
|
|
11
|
+
type TelegramWebhookHandler,
|
|
12
|
+
type TelegramWebhookHandlerOptions,
|
|
13
|
+
} from "@arnilo/prism-hosts/channels/telegram";
|
|
14
|
+
|
|
15
|
+
export async function startTelegramChannel(agent: Agent, options: TelegramConnectOptions): Promise<ChannelConnectionHandle> {
|
|
16
|
+
const handle = await connectTelegram(agent, options);
|
|
17
|
+
await handle.start();
|
|
18
|
+
return handle;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** Host-mounted webhook ingress. Prism does not create a listener or call setWebhook. */
|
|
22
|
+
export function mountTelegramWebhook(options: {
|
|
23
|
+
readonly webhook: Omit<TelegramWebhookHandlerOptions, "admit">;
|
|
24
|
+
readonly handle: ChannelConnectionHandle;
|
|
25
|
+
}): TelegramWebhookHandler {
|
|
26
|
+
return createTelegramWebhookHandler({
|
|
27
|
+
...options.webhook,
|
|
28
|
+
admit: (event) => options.handle.handle(event) as any,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { type AgentEvent, createAgent, providerDone, providerTextDelta, type ContextDraft, type ToolDefinition } from "@arnilo/prism";
|
|
2
|
+
import { providerPackage } from "@arnilo/prism/provider-kit";
|
|
3
|
+
|
|
4
|
+
type Plane = "knowledge" | "metric" | "scenario" | "objects";
|
|
5
|
+
|
|
6
|
+
function tool(name: string): ToolDefinition {
|
|
7
|
+
return {
|
|
8
|
+
name,
|
|
9
|
+
parameters: { type: "object", properties: {} },
|
|
10
|
+
execute(_args, context) {
|
|
11
|
+
return { toolCallId: context.toolCallId, name };
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function classify(last?: string): Plane {
|
|
17
|
+
if (!last) return "objects";
|
|
18
|
+
if (/wiki/i.test(last)) return "knowledge";
|
|
19
|
+
if (/metric/i.test(last)) return "metric";
|
|
20
|
+
if (/scenario/i.test(last)) return "scenario";
|
|
21
|
+
return "objects";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function prefix(plane: Plane): string {
|
|
25
|
+
return plane === "knowledge" ? "wiki." : plane === "metric" ? "metrics." : `${plane}.`;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Plane-switched tool narrowing on one continuing session, as a `context.build`
|
|
29
|
+
// handler over the draft's tool list (roadmap §2.4). Narrowing is restrictive-only:
|
|
30
|
+
// the handler may drop tools but never introduce one the agent does not have, and a
|
|
31
|
+
// call the model should not make is refused with a `tool.call` deny, not by hiding
|
|
32
|
+
// the schema. Fake provider — network-free, no credentials.
|
|
33
|
+
export async function demo() {
|
|
34
|
+
let generate = 0;
|
|
35
|
+
const agent = await createAgent({
|
|
36
|
+
model: { provider: "mock", model: "demo" },
|
|
37
|
+
packages: [
|
|
38
|
+
providerPackage("test-provider", [
|
|
39
|
+
{
|
|
40
|
+
id: "mock",
|
|
41
|
+
async *generate() {
|
|
42
|
+
generate += 1;
|
|
43
|
+
if (generate === 1) {
|
|
44
|
+
yield providerTextDelta("I'll search the wiki.");
|
|
45
|
+
yield {
|
|
46
|
+
type: "tool_call",
|
|
47
|
+
call: { type: "tool_call", id: "c1", name: "objects.list", arguments: {} },
|
|
48
|
+
};
|
|
49
|
+
} else {
|
|
50
|
+
yield providerTextDelta("I'll query metrics.");
|
|
51
|
+
}
|
|
52
|
+
yield providerDone();
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
]),
|
|
56
|
+
],
|
|
57
|
+
tools: { add: [tool("wiki.search"), tool("wiki.read"), tool("metrics.query"), tool("scenario.run"), tool("objects.list")] },
|
|
58
|
+
hooks: (hooks) => {
|
|
59
|
+
let plane: Plane = "objects";
|
|
60
|
+
hooks.on(
|
|
61
|
+
"context.build",
|
|
62
|
+
(draft: ContextDraft) => {
|
|
63
|
+
// The latest assistant text is the classification signal, read from the transcript.
|
|
64
|
+
const last = [...draft.messages].reverse().find((message) => message.role === "assistant");
|
|
65
|
+
plane = classify(
|
|
66
|
+
last?.content
|
|
67
|
+
.map((block) => (block.type === "text" ? block.text : ""))
|
|
68
|
+
.join(" ")
|
|
69
|
+
.trim() || undefined,
|
|
70
|
+
);
|
|
71
|
+
const keep = prefix(plane);
|
|
72
|
+
const tools = (draft.tools ?? []).filter((entry) => entry.name.startsWith(keep));
|
|
73
|
+
return tools.length === (draft.tools ?? []).length ? undefined : { ...draft, tools };
|
|
74
|
+
},
|
|
75
|
+
{ id: "plane-narrowing" },
|
|
76
|
+
);
|
|
77
|
+
// Anything outside the current plane is refused outright.
|
|
78
|
+
hooks.on(
|
|
79
|
+
"tool.call",
|
|
80
|
+
(payload) => (payload.name.startsWith(prefix(plane)) ? undefined : { deny: `tool ${payload.name} is outside the ${plane} plane` }),
|
|
81
|
+
{ id: "plane-gate" },
|
|
82
|
+
);
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
const session = await agent.session();
|
|
86
|
+
const menus: Array<{ count: number; idsHash: string }> = [];
|
|
87
|
+
for await (const event of session.stream("list objects", { limits: { maxToolRounds: 1 } }) as AsyncIterable<AgentEvent>) {
|
|
88
|
+
if (event.type === "turn.started" && event.metadata.tools) menus.push(event.metadata.tools);
|
|
89
|
+
}
|
|
90
|
+
return { menus };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
export async function main() {
|
|
94
|
+
console.log(JSON.stringify(await demo()));
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
98
|
+
await main();
|
|
99
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { ToolCallContent, ToolDefinition, ToolResult } from "@arnilo/prism";
|
|
2
|
+
import { createToolRegistry, dispatchToolCall, filterTools } from "@arnilo/prism";
|
|
3
|
+
|
|
4
|
+
// Host-owned tool registry: allow/deny filtering and dispatch. Unregistered
|
|
5
|
+
// tool calls fail closed and never execute.
|
|
6
|
+
export async function demo() {
|
|
7
|
+
const echo: ToolDefinition = {
|
|
8
|
+
name: "echo",
|
|
9
|
+
description: "Echo back the argument",
|
|
10
|
+
parameters: { type: "object", properties: { text: { type: "string" } }, required: ["text"] },
|
|
11
|
+
async execute(args: { text: string }, context): Promise<ToolResult> {
|
|
12
|
+
return { toolCallId: context.toolCallId, name: "echo", value: args.text };
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const registry = createToolRegistry([echo]);
|
|
17
|
+
|
|
18
|
+
const active = filterTools(registry.list(), { allow: ["echo"], deny: [] });
|
|
19
|
+
const call: ToolCallContent = { type: "tool_call", id: "tc_1", name: "echo", arguments: { text: "hi" } };
|
|
20
|
+
|
|
21
|
+
const result = await dispatchToolCall({
|
|
22
|
+
call,
|
|
23
|
+
registry,
|
|
24
|
+
context: { sessionId: "s1", runId: "r1", toolCallId: call.id },
|
|
25
|
+
filter: { allow: active.map((t) => t.name) },
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return { value: result.value, activeCount: active.length };
|
|
29
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Validator Demo (plan 191 Task 8).
|
|
3
|
+
*
|
|
4
|
+
* `validate` makes completion a checked claim. The run's task is captured, and at the natural end of every
|
|
5
|
+
* run one validator review asks a second model whether the answer completes it. The first review answers
|
|
6
|
+
* `incomplete` with what is missing, so the run continues with that list as a steer; the second answers
|
|
7
|
+
* `complete`, and the run is verified. The host gates on the `validator.verdict` events — a run that merely
|
|
8
|
+
* reports `completed` is not the same as a verified run.
|
|
9
|
+
*
|
|
10
|
+
* With `engine: { child }` the review is a hidden `delegate` child instead, which can check evidence with
|
|
11
|
+
* its own tools. This demo uses the model engine so it runs offline.
|
|
12
|
+
*
|
|
13
|
+
* Run: bun examples/validator.ts
|
|
14
|
+
*/
|
|
15
|
+
import { type AgentEvent, createAgent, createMemorySessionStore, type ModelProvider, providerDone, providerTextDelta } from "@arnilo/prism";
|
|
16
|
+
import { providerPackage } from "@arnilo/prism/provider-kit";
|
|
17
|
+
import advisor from "@arnilo/prism-extensions/advisor";
|
|
18
|
+
|
|
19
|
+
function mockProvider(): ModelProvider {
|
|
20
|
+
let reviews = 0;
|
|
21
|
+
return {
|
|
22
|
+
id: "mock",
|
|
23
|
+
async *generate(request) {
|
|
24
|
+
if (JSON.stringify(request.messages).includes("completion validator")) {
|
|
25
|
+
reviews += 1;
|
|
26
|
+
yield providerTextDelta(
|
|
27
|
+
reviews === 1
|
|
28
|
+
? '{"verdict":"incomplete","missing":["Add the CHANGELOG entry."],"evidence":"no changelog diff"}'
|
|
29
|
+
: '{"verdict":"complete","missing":[],"evidence":"CHANGELOG.md updated, tests pass"}',
|
|
30
|
+
);
|
|
31
|
+
} else {
|
|
32
|
+
yield providerTextDelta("Implemented the fix and added the CHANGELOG entry.");
|
|
33
|
+
}
|
|
34
|
+
yield providerDone({ inputTokens: 6, outputTokens: 3, totalTokens: 9 });
|
|
35
|
+
},
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export async function demo() {
|
|
40
|
+
const verdicts: unknown[] = [];
|
|
41
|
+
const agent = await createAgent({
|
|
42
|
+
id: "validator-demo",
|
|
43
|
+
model: { provider: "mock", model: "demo" },
|
|
44
|
+
slots: { store: createMemorySessionStore() },
|
|
45
|
+
hooks: (hooks) => {
|
|
46
|
+
hooks.on("package.event", (event: Extract<AgentEvent, { type: "package.event" }>) => {
|
|
47
|
+
if (event.name === "validator.verdict") verdicts.push(event.data);
|
|
48
|
+
});
|
|
49
|
+
},
|
|
50
|
+
packages: [
|
|
51
|
+
providerPackage("mock-provider", [mockProvider()]),
|
|
52
|
+
advisor({
|
|
53
|
+
model: { provider: "mock", model: "demo" },
|
|
54
|
+
tool: false,
|
|
55
|
+
validate: { criteria: "Tests pass and the changelog is updated.", maxRounds: 2 },
|
|
56
|
+
}),
|
|
57
|
+
],
|
|
58
|
+
});
|
|
59
|
+
const session = await agent.session();
|
|
60
|
+
const result = await session.run("Fix the parser bug and finish the task.");
|
|
61
|
+
await session.close();
|
|
62
|
+
await agent.dispose();
|
|
63
|
+
const verified = verdicts.at(-1) as { verdict?: string } | undefined;
|
|
64
|
+
return { status: result.status, verified: verified?.verdict === "verified", verdicts };
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (import.meta.main) console.log(JSON.stringify(await demo(), null, 2));
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
2
|
+
import { tmpdir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { createAgent } from "@arnilo/prism";
|
|
5
|
+
import { mockProvider, providerDone, providerTextDelta } from "@arnilo/prism/testing";
|
|
6
|
+
import { toolsCoding } from "@arnilo/prism-tools/coding";
|
|
7
|
+
import { toolsWeb } from "@arnilo/prism-tools/web";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Two halves of the same story, both offline.
|
|
11
|
+
*
|
|
12
|
+
* 1. A `toolsWeb` package whose key ref does not resolve registers nothing and writes a `warn`
|
|
13
|
+
* status note — the whole point of a ref-only key. `agent.inspect().statusNotes` names the
|
|
14
|
+
* missing ref, no `web_*` tool is registered, and the run still completes on the coding tools.
|
|
15
|
+
* The literal is never in the config, so the note can only echo the ref.
|
|
16
|
+
* 2. `toolsWeb({ backend: "native" })` is the keyless case: `web_fetch` (DNS-pinned fetch plus
|
|
17
|
+
* Markdown conversion) registers with no credential and no status note, and registering makes no
|
|
18
|
+
* network request. A fetch is only attempted when the model calls the tool.
|
|
19
|
+
*
|
|
20
|
+
* Imports only public package entry points and `@arnilo/prism/testing`; no credential, no network.
|
|
21
|
+
* Run: npm run build:core && node examples/web-no-key.ts
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
const MODEL = { provider: "mock", model: "demo" } as const;
|
|
25
|
+
|
|
26
|
+
export async function demo(): Promise<Record<string, unknown>> {
|
|
27
|
+
const root = await mkdtemp(join(tmpdir(), "prism-web-no-key-"));
|
|
28
|
+
try {
|
|
29
|
+
const agent = await createAgent({
|
|
30
|
+
id: "web-no-key",
|
|
31
|
+
model: MODEL,
|
|
32
|
+
packages: [
|
|
33
|
+
mockProvider([[providerTextDelta("No web tools; I'll answer from what I have."), providerDone()]]),
|
|
34
|
+
toolsWeb({ backend: "brave", apiKey: "env:PRISM_EXAMPLE_UNSET_KEY" }),
|
|
35
|
+
toolsCoding({ root }),
|
|
36
|
+
],
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const inspection = agent.inspect();
|
|
40
|
+
const webNote = inspection.statusNotes.find((note) => note.package === "@arnilo/prism-tools/web");
|
|
41
|
+
const webTools = inspection.tools.filter((tool) => tool.name.startsWith("web_"));
|
|
42
|
+
|
|
43
|
+
const session = await agent.session();
|
|
44
|
+
const result = await session.run("Summarize the repo.");
|
|
45
|
+
|
|
46
|
+
const native = await createAgent({
|
|
47
|
+
id: "web-native",
|
|
48
|
+
model: MODEL,
|
|
49
|
+
packages: [
|
|
50
|
+
mockProvider([[providerTextDelta("I can read a page without any key."), providerDone()]]),
|
|
51
|
+
toolsWeb({ backend: "native" }),
|
|
52
|
+
],
|
|
53
|
+
});
|
|
54
|
+
let nativeTools: string[];
|
|
55
|
+
let nativeNotes: string[];
|
|
56
|
+
try {
|
|
57
|
+
const nativeInspection = native.inspect();
|
|
58
|
+
nativeTools = nativeInspection.tools.filter((tool) => tool.name.startsWith("web_")).map((tool) => tool.name);
|
|
59
|
+
nativeNotes = nativeInspection.statusNotes.filter((note) => note.package === "@arnilo/prism-tools/web").map((note) => note.message);
|
|
60
|
+
} finally {
|
|
61
|
+
await native.dispose();
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return {
|
|
65
|
+
note: webNote?.message,
|
|
66
|
+
level: webNote?.level,
|
|
67
|
+
webTools: webTools.map((tool) => tool.name),
|
|
68
|
+
codingToolsRegistered: inspection.tools.some((tool) => tool.package === "@arnilo/prism-tools/coding"),
|
|
69
|
+
status: result.status,
|
|
70
|
+
reply: (await session.messages()).at(-1)?.content,
|
|
71
|
+
nativeTools,
|
|
72
|
+
nativeNotes,
|
|
73
|
+
};
|
|
74
|
+
} finally {
|
|
75
|
+
await rm(root, { recursive: true, force: true });
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export async function main() {
|
|
80
|
+
console.log(JSON.stringify(await demo(), null, 2));
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
84
|
+
await main();
|
|
85
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { type JsonSchema, validateJsonSchema } from "@arnilo/prism";
|
|
2
|
+
|
|
3
|
+
const jsonSchemaValidator = {
|
|
4
|
+
validate(schema: JsonSchema, value: unknown) {
|
|
5
|
+
const result = validateJsonSchema(schema, value);
|
|
6
|
+
return result.ok ? { ok: true as const, value: result.value } : { ok: false as const, errors: result.errors };
|
|
7
|
+
},
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
import { createBraveSearch, createFirecrawlExtractor, createFirecrawlFetch, createWebTools } from "@arnilo/prism-tools/web";
|
|
11
|
+
|
|
12
|
+
const reply = (value: unknown) => new Response(JSON.stringify(value), { headers: { "content-type": "application/json" } });
|
|
13
|
+
const fakeFetch: typeof fetch = async (input) => {
|
|
14
|
+
const path = new URL(String(input)).pathname;
|
|
15
|
+
if (path.includes("web/search"))
|
|
16
|
+
return reply({ web: { results: [{ title: "Prism", url: "https://example.com/prism", description: "SDK overview" }] } });
|
|
17
|
+
if (path.endsWith("/scrape"))
|
|
18
|
+
return reply({ success: true, data: { markdown: "# Prism", metadata: { sourceURL: "https://example.com/prism" } } });
|
|
19
|
+
return reply({ success: true, data: { title: "Prism" } });
|
|
20
|
+
};
|
|
21
|
+
const common = { credentials: async () => "fake-example-key", fetch: fakeFetch };
|
|
22
|
+
const search = createBraveSearch(common);
|
|
23
|
+
const fetchDocument = createFirecrawlFetch(common);
|
|
24
|
+
const extract = createFirecrawlExtractor({
|
|
25
|
+
...common,
|
|
26
|
+
schema: { type: "object", properties: { title: { type: "string" } }, required: ["title"] },
|
|
27
|
+
validator: jsonSchemaValidator,
|
|
28
|
+
});
|
|
29
|
+
const tools = createWebTools({ search, fetch: fetchDocument, extract });
|
|
30
|
+
|
|
31
|
+
const found = await search.search("Prism SDK", { count: 1 });
|
|
32
|
+
const document = await fetchDocument.fetch(found.results[0]!.url); // host chooses fetch path; model cannot switch adapters
|
|
33
|
+
console.log(
|
|
34
|
+
JSON.stringify({ tools: tools.map(({ name }) => name), citation: found.results[0]!.citationId, untrusted: document.untrusted }),
|
|
35
|
+
);
|