@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,255 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdtemp, rm } from "node:fs/promises";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import {
|
|
6
|
+
type Agent,
|
|
7
|
+
createAgent,
|
|
8
|
+
createMemorySessionStore,
|
|
9
|
+
definePackage,
|
|
10
|
+
type ModelProvider,
|
|
11
|
+
type ProviderEvent,
|
|
12
|
+
type ProviderRequest,
|
|
13
|
+
providerDone,
|
|
14
|
+
providerTextDelta,
|
|
15
|
+
providerToolCall,
|
|
16
|
+
type Session,
|
|
17
|
+
toolCallContent,
|
|
18
|
+
} from "@arnilo/prism";
|
|
19
|
+
import memorySystem, {
|
|
20
|
+
MEMORY_LTM_SERVICE,
|
|
21
|
+
MEMORY_SYSTEM_SERVICE,
|
|
22
|
+
type MemoryLtmPort,
|
|
23
|
+
type MemorySystemConfig,
|
|
24
|
+
type MemorySystemService,
|
|
25
|
+
} from "@arnilo/prism-memory-system";
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* The memory system's four partial-use profiles (plan 216 Task 6), each run end to end on one agent:
|
|
29
|
+
*
|
|
30
|
+
* - **`ltm`** (`{ stm: false, ltm }`): long-term memory alone. The model writes a fact note with `memory.insert`; there
|
|
31
|
+
* are no session tiers, no `recall` tool, no `memory:session` command and no `compaction` slot claim.
|
|
32
|
+
* - **`session`** (`{ stm, wm }`, the defaults): the session tiers with no cross-session store. A turn is observed and
|
|
33
|
+
* working memory gives the events verdicts; no `memory.*` tool and no `memory.ltm` service exist.
|
|
34
|
+
* - **`stm`** (`{ stm, wm: false }`): an event log with verbatim recall. Observed, never given a WM verdict.
|
|
35
|
+
* - **`full`** (every component): observed, kept in working memory and rehearsed (today's dropper, the `lowest-relevance` policy so
|
|
36
|
+
* it needs no model call), plus a long-term note. `sleep` is on and still a no-op.
|
|
37
|
+
*
|
|
38
|
+
* For each profile the demo asserts which tools, commands, slot claim and capabilities the package holds, and reads the
|
|
39
|
+
* `memory.system` service's `status()`. A component turned off loads and registers nothing. The worker models are
|
|
40
|
+
* scripted in one inline mock provider (`mock/main`, `mock/observer`, `mock/reflector`): no credential, no network.
|
|
41
|
+
* Run: `bun examples/memory-system.ts` (`--json` prints the per-profile report the package test reads).
|
|
42
|
+
*/
|
|
43
|
+
|
|
44
|
+
const MAIN_MODEL = { provider: "mock", model: "main", limits: { contextWindow: 64_000, maxOutputTokens: 0 } } as const;
|
|
45
|
+
const PACKAGE = "@arnilo/prism-memory-system";
|
|
46
|
+
const FACT = "The retry budget is capped at three attempts.";
|
|
47
|
+
|
|
48
|
+
export type ProfileName = "ltm" | "session" | "stm" | "full";
|
|
49
|
+
|
|
50
|
+
const STM = { model: "mock/observer", triggerTokens: 1 } as const;
|
|
51
|
+
const WM = { model: "mock/reflector", triggerTokens: 1 } as const;
|
|
52
|
+
|
|
53
|
+
/** The four profiles: documented recipes, not a config field. `root` is the long-term memory's directory. */
|
|
54
|
+
function profileConfig(profile: ProfileName, root: string): MemorySystemConfig {
|
|
55
|
+
const ltm = { tools: { root } };
|
|
56
|
+
switch (profile) {
|
|
57
|
+
case "ltm":
|
|
58
|
+
return { stm: false, ltm };
|
|
59
|
+
case "session":
|
|
60
|
+
return { stm: STM, wm: WM };
|
|
61
|
+
case "stm":
|
|
62
|
+
return { stm: STM, wm: false };
|
|
63
|
+
case "full":
|
|
64
|
+
return { stm: STM, wm: WM, rehearsal: { targetTokens: 1, policy: "lowest-relevance" }, ltm, sleep: {} };
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** The observer: one `record_event` call sourced from the first entry its prompt lists. */
|
|
69
|
+
function observe(request: ProviderRequest): ProviderEvent[] {
|
|
70
|
+
const prompt = request.messages.find((message) => message.role === "user")?.content[0];
|
|
71
|
+
const sourceId = prompt?.type === "text" ? /\[[^\]]+\] \[([^\]]+)\] (?:user|assistant|tool|system):/.exec(prompt.text)?.[1] : undefined;
|
|
72
|
+
if (request.messages.some((message) => message.role === "tool") || !sourceId) return [providerDone()];
|
|
73
|
+
return [
|
|
74
|
+
providerToolCall(
|
|
75
|
+
toolCallContent("observe-1", "record_event", { kind: "statement", description: FACT, relevance: "high", sourceEntryIds: [sourceId] }),
|
|
76
|
+
),
|
|
77
|
+
providerDone(),
|
|
78
|
+
];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Working memory: one `derive` over the first STM record its prompt lists. A fact gives the record no verdict, so it
|
|
83
|
+
* stays on the STM surface and the `full` profile's rehearsal still has a record to drop.
|
|
84
|
+
*/
|
|
85
|
+
function reflect(request: ProviderRequest): ProviderEvent[] {
|
|
86
|
+
const prompt = request.messages.find((message) => message.role === "user")?.content[0];
|
|
87
|
+
const id = prompt?.type === "text" ? /^- \[([a-f0-9]{12})\] \d{4}-/m.exec(prompt.text)?.[1] : undefined;
|
|
88
|
+
if (request.messages.some((message) => message.role === "tool") || !id) return [providerDone()];
|
|
89
|
+
return [
|
|
90
|
+
providerToolCall(toolCallContent("wm-1", "derive", { supportingIds: [id], text: `Durable: ${FACT}`, relevance: "high" })),
|
|
91
|
+
providerDone(),
|
|
92
|
+
];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The main model: writes the fact note when `memory.insert` is offered, then acknowledges. */
|
|
96
|
+
function answer(request: ProviderRequest): ProviderEvent[] {
|
|
97
|
+
const offered = request.tools?.some((tool) => tool.name === "memory.insert") === true;
|
|
98
|
+
const answered = request.messages.some((message) => message.role === "tool");
|
|
99
|
+
if (offered && !answered) {
|
|
100
|
+
return [
|
|
101
|
+
providerToolCall(toolCallContent("insert-1", "memory.insert", { text: FACT, kind: "fact", scope: "project", keywords: ["retry"] })),
|
|
102
|
+
providerDone(),
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
return [providerTextDelta("Noted."), providerDone()];
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
export interface ProfileReport {
|
|
109
|
+
readonly profile: ProfileName;
|
|
110
|
+
readonly capabilities: readonly string[];
|
|
111
|
+
readonly compactionOwner: string;
|
|
112
|
+
readonly tools: readonly string[];
|
|
113
|
+
readonly commands: readonly string[];
|
|
114
|
+
readonly components: Readonly<Record<string, boolean>>;
|
|
115
|
+
readonly ltmService: boolean;
|
|
116
|
+
readonly modelCalls: Readonly<Record<string, number>>;
|
|
117
|
+
readonly observations: number;
|
|
118
|
+
readonly wmItems: number;
|
|
119
|
+
readonly dropped: number;
|
|
120
|
+
readonly facts: number;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
interface SessionStatus {
|
|
124
|
+
readonly observations: { readonly recorded: number; readonly dropped: number };
|
|
125
|
+
readonly wmItems: { readonly recorded: number };
|
|
126
|
+
readonly inFlight: boolean;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Waits until the background pass a turn started has recorded an observation and settled. */
|
|
130
|
+
async function settled(agent: Agent, session: Session): Promise<SessionStatus> {
|
|
131
|
+
for (let attempt = 0; attempt < 1_000; attempt++) {
|
|
132
|
+
const status = (await agent.commands.run("memory:session:status", {}, { session })) as SessionStatus;
|
|
133
|
+
if (status.observations.recorded > 0 && !status.inFlight) return status;
|
|
134
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
135
|
+
}
|
|
136
|
+
throw new Error("the session tiers' background pass did not settle");
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
export async function runProfile(profile: ProfileName): Promise<ProfileReport> {
|
|
140
|
+
const root = await mkdtemp(join(tmpdir(), `prism-memory-system-${profile}-`));
|
|
141
|
+
const modelCalls: Record<string, number> = {};
|
|
142
|
+
const provider: ModelProvider = {
|
|
143
|
+
id: "mock",
|
|
144
|
+
async *generate(request) {
|
|
145
|
+
const model = request.model.model;
|
|
146
|
+
modelCalls[model] = (modelCalls[model] ?? 0) + 1;
|
|
147
|
+
yield* model === "observer" ? observe(request) : model === "reflector" ? reflect(request) : answer(request);
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
let services: { system?: MemorySystemService; ltm?: MemoryLtmPort } = {};
|
|
151
|
+
const host = definePackage({
|
|
152
|
+
name: "@example/memory-system-host",
|
|
153
|
+
version: "0.0.0",
|
|
154
|
+
description: "The demo's scripted provider, and a read of the services the memory system provides.",
|
|
155
|
+
requires: { api: 1 },
|
|
156
|
+
setup(prism) {
|
|
157
|
+
prism.providers.register(provider);
|
|
158
|
+
prism.hooks.on("session.opened", () => {
|
|
159
|
+
services = {
|
|
160
|
+
system: prism.services.consume<MemorySystemService>(MEMORY_SYSTEM_SERVICE),
|
|
161
|
+
ltm: prism.services.consume<MemoryLtmPort>(MEMORY_LTM_SERVICE),
|
|
162
|
+
};
|
|
163
|
+
});
|
|
164
|
+
},
|
|
165
|
+
})();
|
|
166
|
+
const agent = await createAgent({
|
|
167
|
+
id: `memory-system-${profile}`,
|
|
168
|
+
model: MAIN_MODEL,
|
|
169
|
+
slots: { store: createMemorySessionStore() },
|
|
170
|
+
packages: [host, memorySystem(profileConfig(profile, root))],
|
|
171
|
+
});
|
|
172
|
+
try {
|
|
173
|
+
const inspection = agent.inspect();
|
|
174
|
+
const session = await agent.session({ id: profile, create: true });
|
|
175
|
+
const components: Readonly<Record<string, boolean>> = services.system?.status().components ?? {};
|
|
176
|
+
// The session tiers are gated per session: this one turns them on.
|
|
177
|
+
if (components.stm) await agent.commands.run("memory:session", {}, { session });
|
|
178
|
+
await session.run(`Remember this: ${FACT}`);
|
|
179
|
+
const status = components.stm ? await settled(agent, session) : undefined;
|
|
180
|
+
const facts = services.ltm
|
|
181
|
+
? (await services.ltm.scanMetadata("project", { limit: 50 })).notes.filter((note) => note.kind === "fact").length
|
|
182
|
+
: 0;
|
|
183
|
+
await session.close();
|
|
184
|
+
return {
|
|
185
|
+
profile,
|
|
186
|
+
capabilities: [...(inspection.packages.find((entry) => entry.name === PACKAGE)?.capabilities ?? [])].sort(),
|
|
187
|
+
compactionOwner: inspection.slots.compaction,
|
|
188
|
+
tools: inspection.tools
|
|
189
|
+
.filter((tool) => tool.package === PACKAGE)
|
|
190
|
+
.map((tool) => tool.name)
|
|
191
|
+
.sort(),
|
|
192
|
+
commands: inspection.commands
|
|
193
|
+
.filter((command) => command.package === PACKAGE)
|
|
194
|
+
.map((command) => command.name)
|
|
195
|
+
.sort(),
|
|
196
|
+
components,
|
|
197
|
+
ltmService: services.ltm !== undefined,
|
|
198
|
+
modelCalls,
|
|
199
|
+
observations: status?.observations.recorded ?? 0,
|
|
200
|
+
wmItems: status?.wmItems.recorded ?? 0,
|
|
201
|
+
dropped: status?.observations.dropped ?? 0,
|
|
202
|
+
facts,
|
|
203
|
+
};
|
|
204
|
+
} finally {
|
|
205
|
+
await agent.dispose();
|
|
206
|
+
await rm(root, { recursive: true, force: true });
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** What each profile must show; the package test asserts the same through `--json`. */
|
|
211
|
+
export function checkProfile(report: ProfileReport): void {
|
|
212
|
+
const { profile } = report;
|
|
213
|
+
const on = (name: string) => report.components[name] === true;
|
|
214
|
+
const memoryTools = report.tools.filter((tool) => tool.startsWith("memory."));
|
|
215
|
+
// Long-term memory: its tools and its read-only port exist only when `ltm` is on, and it stored the fact.
|
|
216
|
+
assert.equal(memoryTools.length > 0, on("ltm"), `${profile}: memory.* tools follow ltm`);
|
|
217
|
+
assert.equal(report.ltmService, on("ltm"), `${profile}: the memory.ltm service follows ltm`);
|
|
218
|
+
assert.equal(report.facts, on("ltm") ? 1 : 0, `${profile}: the fact note`);
|
|
219
|
+
// The session tiers: the recall tool, the memory:session commands and the compaction slot follow stm.
|
|
220
|
+
assert.equal(report.tools.includes("recall"), on("stm"), `${profile}: recall follows stm`);
|
|
221
|
+
assert.equal(report.commands.includes("memory:session"), on("stm"), `${profile}: memory:session follows stm`);
|
|
222
|
+
assert.equal(report.compactionOwner === PACKAGE, on("stm"), `${profile}: the compaction slot follows stm`);
|
|
223
|
+
assert.equal(report.capabilities.includes("slot:compaction"), on("stm"), `${profile}: slot:compaction follows stm`);
|
|
224
|
+
assert.equal(report.capabilities.includes("credentials"), on("ltm"), `${profile}: credentials follows ltm`);
|
|
225
|
+
// The passes: observed with stm, given WM verdicts only with wm, rehearsed (dropped) only with rehearsal.
|
|
226
|
+
assert.equal(report.observations > 0, on("stm"), `${profile}: observations`);
|
|
227
|
+
assert.equal(report.wmItems > 0, on("wm"), `${profile}: WM items`);
|
|
228
|
+
assert.equal((report.modelCalls.reflector ?? 0) > 0, on("wm"), `${profile}: the reflector model is called only with wm`);
|
|
229
|
+
assert.equal((report.modelCalls.observer ?? 0) > 0, on("stm"), `${profile}: the observer model is called only with stm`);
|
|
230
|
+
assert.equal(report.dropped > 0, on("rehearsal"), `${profile}: rehearsal drops only when on`);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
const PROFILES: readonly ProfileName[] = ["ltm", "session", "stm", "full"];
|
|
234
|
+
|
|
235
|
+
if (import.meta.main) {
|
|
236
|
+
const reports: ProfileReport[] = [];
|
|
237
|
+
for (const profile of PROFILES) {
|
|
238
|
+
const report = await runProfile(profile);
|
|
239
|
+
checkProfile(report);
|
|
240
|
+
reports.push(report);
|
|
241
|
+
}
|
|
242
|
+
if (process.argv.includes("--json")) console.log(JSON.stringify(reports));
|
|
243
|
+
else
|
|
244
|
+
for (const report of reports) {
|
|
245
|
+
const components = Object.entries(report.components)
|
|
246
|
+
.filter(([, on]) => on)
|
|
247
|
+
.map(([name]) => name)
|
|
248
|
+
.join("+");
|
|
249
|
+
console.log(
|
|
250
|
+
`${report.profile.padEnd(7)} components ${components.padEnd(26)} tools ${String(report.tools.length).padStart(2)} ` +
|
|
251
|
+
`observations ${report.observations} WM items ${report.wmItems} dropped ${report.dropped} facts ${report.facts} ` +
|
|
252
|
+
`slot ${report.compactionOwner === PACKAGE ? "claimed" : "not claimed"} capabilities [${report.capabilities.join(", ")}]`,
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
// Plan 079 Task 8: network-free host composition — sqlite journal, mock agent, drain/stop.
|
|
2
|
+
import { createAgent, providerDone, providerTextDelta } from "@arnilo/prism";
|
|
3
|
+
import { createChannelRuntime } from "@arnilo/prism-hosts/channels";
|
|
4
|
+
import { createSqlitePersistence } from "@arnilo/prism-extensions/store-sqlite";
|
|
5
|
+
import { mockProvider } from "@arnilo/prism/testing";
|
|
6
|
+
import { type AgentIdentity } from "@arnilo/prism-extensions/governance";
|
|
7
|
+
const identity: AgentIdentity = {
|
|
8
|
+
tenantId: "example-tenant",
|
|
9
|
+
userId: "example-user",
|
|
10
|
+
principal: { kind: "user", id: "example-user" },
|
|
11
|
+
scopes: ["chat"],
|
|
12
|
+
issuedAt: new Date(0).toISOString(),
|
|
13
|
+
verified: true,
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export async function demo(): Promise<Record<string, unknown>> {
|
|
17
|
+
const persistence = createSqlitePersistence({ filename: ":memory:" });
|
|
18
|
+
try {
|
|
19
|
+
const agent = await createAgent({
|
|
20
|
+
id: "channel-agent",
|
|
21
|
+
model: { provider: "mock", model: "offline" },
|
|
22
|
+
packages: [mockProvider([[providerTextDelta("Host example reply."), providerDone()]])],
|
|
23
|
+
slots: { store: persistence },
|
|
24
|
+
runLedger: persistence,
|
|
25
|
+
});
|
|
26
|
+
const delivered: string[] = [];
|
|
27
|
+
const runtime = createChannelRuntime(agent, {
|
|
28
|
+
authorize: (input) =>
|
|
29
|
+
input.action === "notify" ? { identity, grantRevision: "rev-1", notifications: true } : { identity, grantRevision: "rev-1" },
|
|
30
|
+
deliver: (reply) => {
|
|
31
|
+
delivered.push(reply.text);
|
|
32
|
+
return { delivered: true };
|
|
33
|
+
},
|
|
34
|
+
checkpoints: persistence.checkpoints,
|
|
35
|
+
leases: persistence.leases,
|
|
36
|
+
});
|
|
37
|
+
const admission = await runtime.admit({
|
|
38
|
+
connectionId: "example",
|
|
39
|
+
externalConversationId: "chat-1",
|
|
40
|
+
externalActorId: "user-1",
|
|
41
|
+
eventId: "1",
|
|
42
|
+
text: "hello",
|
|
43
|
+
});
|
|
44
|
+
const drained = await runtime.drain();
|
|
45
|
+
// Opt-in reverse direction: one notice to the bound pair, no agent run, idempotent by `notifyId`.
|
|
46
|
+
const notice = await runtime.notify({
|
|
47
|
+
identity,
|
|
48
|
+
connectionId: "example",
|
|
49
|
+
externalConversationId: "chat-1",
|
|
50
|
+
notifyId: "job-1-done",
|
|
51
|
+
text: "The nightly job finished.",
|
|
52
|
+
});
|
|
53
|
+
const unresolved = await runtime.listUnresolved({ identity });
|
|
54
|
+
await runtime.stop();
|
|
55
|
+
return {
|
|
56
|
+
admission: admission.status,
|
|
57
|
+
settled: drained.settled,
|
|
58
|
+
delivered,
|
|
59
|
+
notice: notice.status,
|
|
60
|
+
unresolved: unresolved.length,
|
|
61
|
+
diagnostics: runtime.diagnostics(),
|
|
62
|
+
};
|
|
63
|
+
} finally {
|
|
64
|
+
persistence.close();
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
69
|
+
console.log(JSON.stringify(await demo()));
|
|
70
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type AgentEvent, createAgent, providerDone, providerTextDelta, providerUsage } from "@arnilo/prism";
|
|
2
|
+
import { mockProvider } from "@arnilo/prism/testing";
|
|
3
|
+
|
|
4
|
+
// Minimal host-app embed: create an agent + session, stream events while a
|
|
5
|
+
// prompt runs, and return the event-type sequence. Uses the mock provider —
|
|
6
|
+
// no network, no credentials.
|
|
7
|
+
//
|
|
8
|
+
// This is the canonical "hello world" host app. The subscribe consumer and
|
|
9
|
+
// session.run run concurrently via Promise.all: subscribe is an async
|
|
10
|
+
// generator that yields events as the run produces them, so it must be
|
|
11
|
+
// draining while run() is driving the provider turn.
|
|
12
|
+
export async function demo(): Promise<readonly string[]> {
|
|
13
|
+
const agent = await createAgent({
|
|
14
|
+
model: { provider: "mock", model: "demo" },
|
|
15
|
+
packages: [
|
|
16
|
+
mockProvider([
|
|
17
|
+
[providerTextDelta("Hello, host!"), providerUsage({ inputTokens: 4, outputTokens: 3, totalTokens: 7 }), providerDone()],
|
|
18
|
+
]),
|
|
19
|
+
],
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const session = await agent.session();
|
|
23
|
+
|
|
24
|
+
const types: string[] = [];
|
|
25
|
+
async function drain(): Promise<void> {
|
|
26
|
+
for await (const event of session.subscribe() as AsyncIterable<AgentEvent>) {
|
|
27
|
+
types.push(event.type);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
await Promise.all([drain(), session.run("Hi")]);
|
|
32
|
+
return types;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export async function main() {
|
|
36
|
+
console.log(JSON.stringify(await demo()));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (import.meta.url === `file://${process.argv[1]}`) {
|
|
40
|
+
await main();
|
|
41
|
+
}
|