@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.
Files changed (322) hide show
  1. package/CHANGELOG.md +394 -0
  2. package/LICENSE +21 -0
  3. package/README.md +34 -2
  4. package/acp/README.md +87 -0
  5. package/acp/src/capabilities.ts +184 -0
  6. package/acp/src/errors.ts +24 -0
  7. package/acp/src/host.ts +36 -0
  8. package/acp/src/index.ts +25 -0
  9. package/acp/src/limits.ts +49 -0
  10. package/acp/src/mapper.ts +419 -0
  11. package/acp/src/permission.ts +37 -0
  12. package/acp/src/projection.ts +39 -0
  13. package/acp/src/prompt.ts +170 -0
  14. package/acp/src/serve.ts +345 -0
  15. package/acp/src/session-map.ts +49 -0
  16. package/ag-ui/README.md +56 -0
  17. package/ag-ui/src/a2ui.ts +570 -0
  18. package/ag-ui/src/ag-ui-mapper.ts +507 -0
  19. package/ag-ui/src/encrypted-value.ts +40 -0
  20. package/ag-ui/src/errors.ts +29 -0
  21. package/ag-ui/src/handler.ts +642 -0
  22. package/ag-ui/src/index.ts +177 -0
  23. package/ag-ui/src/input.ts +190 -0
  24. package/ag-ui/src/limits.ts +279 -0
  25. package/ag-ui/src/mcp-apps.ts +256 -0
  26. package/ag-ui/src/mcp.ts +94 -0
  27. package/ag-ui/src/projection.ts +201 -0
  28. package/ag-ui/src/projectors.ts +272 -0
  29. package/ag-ui/src/renderer/bind.ts +152 -0
  30. package/ag-ui/src/renderer/core.ts +270 -0
  31. package/ag-ui/src/renderer/index.ts +165 -0
  32. package/ag-ui/src/replay.ts +189 -0
  33. package/ag-ui/src/types.ts +66 -0
  34. package/channels/README.md +139 -0
  35. package/channels/src/admission.ts +8 -0
  36. package/channels/src/approvals.ts +262 -0
  37. package/channels/src/checkpoint-contract.ts +97 -0
  38. package/channels/src/delivery.ts +116 -0
  39. package/channels/src/host-ui.ts +356 -0
  40. package/channels/src/identity.ts +46 -0
  41. package/channels/src/index.ts +82 -0
  42. package/channels/src/limits.ts +49 -0
  43. package/channels/src/memory-stores.ts +112 -0
  44. package/channels/src/pairing.ts +178 -0
  45. package/channels/src/runtime-admit.ts +389 -0
  46. package/channels/src/runtime-core.ts +621 -0
  47. package/channels/src/runtime-reconcile.ts +299 -0
  48. package/channels/src/runtime-turn.ts +664 -0
  49. package/channels/src/runtime-types.ts +95 -0
  50. package/channels/src/runtime.ts +86 -0
  51. package/channels/src/secret-ref.ts +42 -0
  52. package/channels/src/signal.ts +790 -0
  53. package/channels/src/state.ts +355 -0
  54. package/channels/src/telegram.ts +1317 -0
  55. package/channels/src/types.ts +442 -0
  56. package/devtools/README.md +92 -0
  57. package/devtools/bin/prism-devtools.ts +63 -0
  58. package/devtools/src/args.ts +71 -0
  59. package/devtools/src/bun.d.ts +27 -0
  60. package/devtools/src/compare.ts +190 -0
  61. package/devtools/src/errors.ts +15 -0
  62. package/devtools/src/index.ts +25 -0
  63. package/devtools/src/replay.ts +36 -0
  64. package/devtools/src/security.ts +80 -0
  65. package/devtools/src/serve.ts +259 -0
  66. package/devtools/src/ui/assets.ts +108 -0
  67. package/devtools/src/ui/inspector.ts +182 -0
  68. package/driver-process/README.md +197 -0
  69. package/driver-process/src/abort.ts +74 -0
  70. package/driver-process/src/adapter.ts +211 -0
  71. package/driver-process/src/driver.ts +303 -0
  72. package/driver-process/src/errors.ts +17 -0
  73. package/driver-process/src/extend.ts +72 -0
  74. package/driver-process/src/index.ts +5 -0
  75. package/driver-process/src/inspect.ts +33 -0
  76. package/driver-process/src/session.ts +72 -0
  77. package/driver-process/src/testing.ts +394 -0
  78. package/driver-process/src/transports/json-rpc.ts +147 -0
  79. package/driver-process/src/transports/jsonl-stream.ts +12 -0
  80. package/driver-process/src/transports/types.ts +11 -0
  81. package/driver-process/src/turn.ts +106 -0
  82. package/evals/README.md +843 -0
  83. package/evals/src/calibration.ts +179 -0
  84. package/evals/src/citation-integrity.ts +98 -0
  85. package/evals/src/citations.ts +45 -0
  86. package/evals/src/compare-experiments.ts +153 -0
  87. package/evals/src/comparison.ts +230 -0
  88. package/evals/src/curate.ts +257 -0
  89. package/evals/src/dataset.ts +81 -0
  90. package/evals/src/erp-invariants.ts +163 -0
  91. package/evals/src/errors.ts +23 -0
  92. package/evals/src/experiment.ts +537 -0
  93. package/evals/src/failure-injection.ts +77 -0
  94. package/evals/src/feedback.ts +53 -0
  95. package/evals/src/index.ts +198 -0
  96. package/evals/src/injection.ts +247 -0
  97. package/evals/src/judge-panel.ts +109 -0
  98. package/evals/src/judge.ts +89 -0
  99. package/evals/src/limits.ts +50 -0
  100. package/evals/src/report-record.ts +47 -0
  101. package/evals/src/rubric-judge.ts +334 -0
  102. package/evals/src/scenario-runner.ts +317 -0
  103. package/evals/src/scenarios.ts +81 -0
  104. package/evals/src/score.ts +328 -0
  105. package/evals/src/scorer.ts +21 -0
  106. package/evals/src/state-match.ts +130 -0
  107. package/evals/src/stats.ts +635 -0
  108. package/evals/src/threshold.ts +117 -0
  109. package/evals/src/timeline.ts +38 -0
  110. package/evals/src/toolless-session.ts +33 -0
  111. package/evals/src/trace.ts +80 -0
  112. package/evals/src/trajectory.ts +623 -0
  113. package/evals/src/types.ts +672 -0
  114. package/evals/src/user-simulator.ts +101 -0
  115. package/evals/src/util.ts +207 -0
  116. package/headless/README.md +172 -0
  117. package/headless/src/answers.ts +91 -0
  118. package/headless/src/authority.ts +32 -0
  119. package/headless/src/errors.ts +36 -0
  120. package/headless/src/index.ts +17 -0
  121. package/headless/src/limits.ts +11 -0
  122. package/headless/src/pending.ts +16 -0
  123. package/headless/src/policy.ts +36 -0
  124. package/headless/src/resume.ts +103 -0
  125. package/headless/src/route.ts +153 -0
  126. package/headless/src/scheduler/clock.ts +22 -0
  127. package/headless/src/scheduler/cron.ts +19 -0
  128. package/headless/src/scheduler/firing.ts +58 -0
  129. package/headless/src/scheduler/index.ts +399 -0
  130. package/headless/src/scheduler/lease.ts +38 -0
  131. package/headless/src/scheduler/missed.ts +12 -0
  132. package/headless/src/scheduler/state.ts +132 -0
  133. package/host-builder/README.md +251 -0
  134. package/host-builder/bin/prism-host-builder.ts +169 -0
  135. package/host-builder/data/api.json +6197 -0
  136. package/host-builder/data/errors.json +558 -0
  137. package/host-builder/data/examples/acp.ts +63 -0
  138. package/host-builder/data/examples/adapters/conformance.ts +34 -0
  139. package/host-builder/data/examples/adapters/fixtures/rpc-server.json +26 -0
  140. package/host-builder/data/examples/adapters/fixtures/stream-cli.json +27 -0
  141. package/host-builder/data/examples/adapters/fixtures/workspace-config.json +28 -0
  142. package/host-builder/data/examples/adapters/rpc-server.dialect.ts +218 -0
  143. package/host-builder/data/examples/adapters/rpc-server.ts +309 -0
  144. package/host-builder/data/examples/adapters/stream-cli.dialect.ts +165 -0
  145. package/host-builder/data/examples/adapters/stream-cli.ts +256 -0
  146. package/host-builder/data/examples/adapters/workspace-config.dialect.ts +172 -0
  147. package/host-builder/data/examples/adapters/workspace-config.ts +251 -0
  148. package/host-builder/data/examples/advisor.ts +94 -0
  149. package/host-builder/data/examples/ag-ui-a2ui.ts +80 -0
  150. package/host-builder/data/examples/ag-ui-mcp-apps.ts +44 -0
  151. package/host-builder/data/examples/ag-ui-server.ts +118 -0
  152. package/host-builder/data/examples/agent-durable-approval.ts +43 -0
  153. package/host-builder/data/examples/api-key-auth.ts +23 -0
  154. package/host-builder/data/examples/approval.ts +92 -0
  155. package/host-builder/data/examples/attention-compiler.ts +81 -0
  156. package/host-builder/data/examples/autonomous-coding-loop.ts +343 -0
  157. package/host-builder/data/examples/behavior-evaluation.ts +303 -0
  158. package/host-builder/data/examples/build-workflow.ts +334 -0
  159. package/host-builder/data/examples/cache-aware-prompt-assembly.ts +139 -0
  160. package/host-builder/data/examples/caveman-ponytail.ts +197 -0
  161. package/host-builder/data/examples/cli.ts +31 -0
  162. package/host-builder/data/examples/coding-approval.ts +115 -0
  163. package/host-builder/data/examples/coding-browser-evaluation.ts +208 -0
  164. package/host-builder/data/examples/coding-compaction.ts +30 -0
  165. package/host-builder/data/examples/coding-goal-verify.ts +121 -0
  166. package/host-builder/data/examples/coding-tools-capability-gaps.ts +75 -0
  167. package/host-builder/data/examples/compaction.ts +36 -0
  168. package/host-builder/data/examples/connected-slack-mcp.ts +67 -0
  169. package/host-builder/data/examples/context.ts +29 -0
  170. package/host-builder/data/examples/custom-adapter.ts +256 -0
  171. package/host-builder/data/examples/custom-builders.ts +66 -0
  172. package/host-builder/data/examples/custom-loop.ts +89 -0
  173. package/host-builder/data/examples/custom-provider.ts +70 -0
  174. package/host-builder/data/examples/custom-session-store.ts +72 -0
  175. package/host-builder/data/examples/custom-tools-skills-context.ts +97 -0
  176. package/host-builder/data/examples/decision-models.ts +98 -0
  177. package/host-builder/data/examples/define-package.ts +188 -0
  178. package/host-builder/data/examples/delegate.ts +200 -0
  179. package/host-builder/data/examples/discover-skills.ts +65 -0
  180. package/host-builder/data/examples/drive-rag-sync.ts +44 -0
  181. package/host-builder/data/examples/durable-approval.ts +139 -0
  182. package/host-builder/data/examples/durable-investigation.ts +93 -0
  183. package/host-builder/data/examples/durable-loops-and-approvals.ts +94 -0
  184. package/host-builder/data/examples/enterprise-identity.ts +21 -0
  185. package/host-builder/data/examples/enterprise-policy-audit.ts +50 -0
  186. package/host-builder/data/examples/enterprise-work-connectors.ts +103 -0
  187. package/host-builder/data/examples/eval-injection.ts +73 -0
  188. package/host-builder/data/examples/eval-judges.ts +145 -0
  189. package/host-builder/data/examples/evals.ts +86 -0
  190. package/host-builder/data/examples/evaluation-gate.ts +40 -0
  191. package/host-builder/data/examples/execution-timeline.ts +173 -0
  192. package/host-builder/data/examples/external-agent.ts +541 -0
  193. package/host-builder/data/examples/external-app-db-backed.ts +344 -0
  194. package/host-builder/data/examples/governance-deny.ts +122 -0
  195. package/host-builder/data/examples/guardrail-packs.ts +240 -0
  196. package/host-builder/data/examples/headless-host.ts +245 -0
  197. package/host-builder/data/examples/hooks-audit-command.mjs +31 -0
  198. package/host-builder/data/examples/hooks-json.ts +87 -0
  199. package/host-builder/data/examples/host-builder-agent.ts +150 -0
  200. package/host-builder/data/examples/host-hooks.ts +71 -0
  201. package/host-builder/data/examples/host-step-loop-timeline.ts +212 -0
  202. package/host-builder/data/examples/hosted-sandbox.ts +48 -0
  203. package/host-builder/data/examples/instruction-injection.ts +127 -0
  204. package/host-builder/data/examples/jsonl-stores-branching.ts +49 -0
  205. package/host-builder/data/examples/long-term-memory.ts +158 -0
  206. package/host-builder/data/examples/manifest.ts +112 -0
  207. package/host-builder/data/examples/mcp-server.ts +48 -0
  208. package/host-builder/data/examples/mcp-trust.ts +173 -0
  209. package/host-builder/data/examples/memory-and-wiki.ts +315 -0
  210. package/host-builder/data/examples/memory-lifecycle.ts +302 -0
  211. package/host-builder/data/examples/memory-system.ts +255 -0
  212. package/host-builder/data/examples/messaging-agent.ts +70 -0
  213. package/host-builder/data/examples/minimal-host-app.ts +41 -0
  214. package/host-builder/data/examples/model-router-aggregate-budgets.ts +364 -0
  215. package/host-builder/data/examples/model-router.ts +106 -0
  216. package/host-builder/data/examples/obscura.ts +48 -0
  217. package/host-builder/data/examples/observability.ts +116 -0
  218. package/host-builder/data/examples/open-connector-sidecar.ts +105 -0
  219. package/host-builder/data/examples/openai-compatible.ts +70 -0
  220. package/host-builder/data/examples/package-skills.ts +85 -0
  221. package/host-builder/data/examples/phase9-coding-intelligence.ts +221 -0
  222. package/host-builder/data/examples/provider-registration.ts +29 -0
  223. package/host-builder/data/examples/provider-resolver.ts +39 -0
  224. package/host-builder/data/examples/rag.ts +40 -0
  225. package/host-builder/data/examples/remote-agent-server.ts +45 -0
  226. package/host-builder/data/examples/remote-agent.ts +124 -0
  227. package/host-builder/data/examples/research-ledger.ts +79 -0
  228. package/host-builder/data/examples/revocation-propagation.ts +287 -0
  229. package/host-builder/data/examples/run-feedback.ts +93 -0
  230. package/host-builder/data/examples/scanned-document-rag.ts +48 -0
  231. package/host-builder/data/examples/sdk-basics.ts +21 -0
  232. package/host-builder/data/examples/secure-agent.ts +55 -0
  233. package/host-builder/data/examples/semantic-memory.ts +52 -0
  234. package/host-builder/data/examples/serve-tools.ts +495 -0
  235. package/host-builder/data/examples/session-memory.ts +318 -0
  236. package/host-builder/data/examples/session-search.ts +131 -0
  237. package/host-builder/data/examples/session.ts +52 -0
  238. package/host-builder/data/examples/side-call.ts +68 -0
  239. package/host-builder/data/examples/signal-agent.ts +9 -0
  240. package/host-builder/data/examples/skills-progressive-disclosure.ts +88 -0
  241. package/host-builder/data/examples/skills.ts +19 -0
  242. package/host-builder/data/examples/sqlite-resume.ts +147 -0
  243. package/host-builder/data/examples/system-project-prompts.ts +74 -0
  244. package/host-builder/data/examples/system-prompts.ts +19 -0
  245. package/host-builder/data/examples/telegram-agent.ts +30 -0
  246. package/host-builder/data/examples/tool-narrowing-planes.ts +99 -0
  247. package/host-builder/data/examples/tools.ts +29 -0
  248. package/host-builder/data/examples/validator.ts +67 -0
  249. package/host-builder/data/examples/web-no-key.ts +85 -0
  250. package/host-builder/data/examples/web-research.ts +35 -0
  251. package/host-builder/data/examples/workflow-event-sink.ts +114 -0
  252. package/host-builder/data/examples/workflow-loop.ts +93 -0
  253. package/host-builder/data/examples/workflow-multimodal-document.ts +94 -0
  254. package/host-builder/data/examples/workflow-parallel-research.ts +111 -0
  255. package/host-builder/data/examples/workflow-postgres-resume.ts +75 -0
  256. package/host-builder/data/examples/workflow-research-and-review.ts +98 -0
  257. package/host-builder/data/examples/workflow-sqlite-resume.ts +163 -0
  258. package/host-builder/data/examples.json +130 -0
  259. package/host-builder/skills/prism-host-builder/SKILL.md +85 -0
  260. package/host-builder/skills/prism-host-builder/references/choosing.md +101 -0
  261. package/host-builder/skills/prism-host-builder/references/layout.md +52 -0
  262. package/host-builder/skills/prism-host-builder/references/pitfalls.md +50 -0
  263. package/host-builder/skills/prism-host-builder/references/recipes.md +129 -0
  264. package/host-builder/skills/prism-host-builder/references/security.md +52 -0
  265. package/host-builder/skills/prism-host-builder/references/upgrading.md +67 -0
  266. package/host-builder/skills/prism-host-builder/references/verification.md +108 -0
  267. package/host-builder/src/check/child.ts +108 -0
  268. package/host-builder/src/check/conformance.ts +13 -0
  269. package/host-builder/src/check/inspect.ts +20 -0
  270. package/host-builder/src/check/manifest.ts +23 -0
  271. package/host-builder/src/check/runner.ts +181 -0
  272. package/host-builder/src/check/targets.ts +65 -0
  273. package/host-builder/src/errors.ts +35 -0
  274. package/host-builder/src/index.ts +25 -0
  275. package/host-builder/src/indexes.ts +145 -0
  276. package/host-builder/src/install/install.ts +400 -0
  277. package/host-builder/src/install/targets.ts +50 -0
  278. package/host-builder/src/lookup/api.ts +127 -0
  279. package/host-builder/src/lookup/bound.ts +38 -0
  280. package/host-builder/src/lookup/docs.ts +238 -0
  281. package/host-builder/src/lookup/errors.ts +92 -0
  282. package/host-builder/src/lookup/examples.ts +117 -0
  283. package/host-builder/src/lookup/text.ts +60 -0
  284. package/host-builder/src/server.ts +300 -0
  285. package/host-builder/src/version.ts +38 -0
  286. package/mcp-server/README.md +219 -0
  287. package/mcp-server/src/bounds.ts +23 -0
  288. package/mcp-server/src/host.ts +31 -0
  289. package/mcp-server/src/index.ts +27 -0
  290. package/mcp-server/src/serve-tools.ts +408 -0
  291. package/mcp-server/src/serve.ts +329 -0
  292. package/mcp-server/src/server.ts +331 -0
  293. package/mcp-server/src/session-map.ts +47 -0
  294. package/mcp-server/src/skill-resources.ts +85 -0
  295. package/mcp-server/src/types.ts +215 -0
  296. package/package.json +130 -4
  297. package/remote/README.md +244 -0
  298. package/remote/src/attribution.ts +22 -0
  299. package/remote/src/auth.ts +30 -0
  300. package/remote/src/bun-module.d.ts +34 -0
  301. package/remote/src/channel.ts +86 -0
  302. package/remote/src/connect.ts +212 -0
  303. package/remote/src/dispatcher.ts +282 -0
  304. package/remote/src/errors.ts +59 -0
  305. package/remote/src/host-ui.ts +152 -0
  306. package/remote/src/http-gate.ts +43 -0
  307. package/remote/src/index.ts +53 -0
  308. package/remote/src/jsonl.ts +69 -0
  309. package/remote/src/limits.ts +43 -0
  310. package/remote/src/mirror.ts +90 -0
  311. package/remote/src/pending.ts +22 -0
  312. package/remote/src/protocol.ts +107 -0
  313. package/remote/src/serve.ts +560 -0
  314. package/remote/src/session-proxy.ts +219 -0
  315. package/remote/src/sse.ts +38 -0
  316. package/remote/src/stdio-client.ts +41 -0
  317. package/remote/src/testing-fixtures/serve-stdio.ts +32 -0
  318. package/remote/src/testing.ts +230 -0
  319. package/remote/src/transport.ts +139 -0
  320. package/remote/src/transports/client.ts +126 -0
  321. package/remote/src/transports/network.ts +268 -0
  322. package/remote/src/wire.ts +244 -0
@@ -0,0 +1,47 @@
1
+ import type { HostPort } from "@arnilo/prism";
2
+
3
+ /** One MCP session bound to the agent session running under it. */
4
+ export interface BoundMcpSession {
5
+ /** True only on a 2025-era connection whose client advertised `elicitation.form`. */
6
+ readonly elicitation: boolean;
7
+ elicit(request: ElicitRequest): Promise<ElicitResult>;
8
+ }
9
+
10
+ export interface ElicitRequest {
11
+ readonly kind: "confirm" | "select" | "input";
12
+ readonly title: string;
13
+ readonly detail?: string;
14
+ readonly options?: readonly { readonly value: string; readonly label?: string }[];
15
+ }
16
+
17
+ export type ElicitResult =
18
+ | { readonly status: "answered"; readonly value: boolean | string | readonly string[] }
19
+ | { readonly status: "dismissed" }
20
+ | { readonly status: "unavailable" };
21
+
22
+ const branded = new WeakSet<object>();
23
+ const tables = new WeakMap<object, Map<string, BoundMcpSession>>();
24
+
25
+ export function brandMcpHost(port: HostPort): void {
26
+ branded.add(port);
27
+ tables.set(port, new Map());
28
+ }
29
+
30
+ export function isMcpHost(port: HostPort | undefined): port is HostPort {
31
+ return port !== undefined && branded.has(port);
32
+ }
33
+
34
+ export function bindMcpSession(port: HostPort | undefined, sessionId: string, bound: BoundMcpSession): void {
35
+ if (!port) return;
36
+ tables.get(port)?.set(sessionId, bound);
37
+ }
38
+
39
+ export function unbindMcpSession(port: HostPort | undefined, sessionId: string): void {
40
+ if (!port) return;
41
+ tables.get(port)?.delete(sessionId);
42
+ }
43
+
44
+ export function boundMcpSession(port: HostPort, sessionId: string | undefined): BoundMcpSession | undefined {
45
+ if (!sessionId) return undefined;
46
+ return tables.get(port)?.get(sessionId);
47
+ }
@@ -0,0 +1,85 @@
1
+ import type { Skill } from "@arnilo/prism";
2
+ import { MAX_RESOURCE_BYTES } from "./serve-tools.js";
3
+ import type { ServeToolsResource } from "./types.js";
4
+
5
+ /** A lent skill is served as `prism-skill://<name>`. */
6
+ const SKILL_RESOURCE_SCHEME = "prism-skill://";
7
+
8
+ /** A skill that qualified for lending but could not be served. Never truncated: the vendor either gets the whole skill or none of it. */
9
+ export interface SkippedSkillResource {
10
+ readonly name: string;
11
+ readonly reason: "oversized";
12
+ /** The rendered `SKILL.md` size in UTF-8 bytes. */
13
+ readonly bytes: number;
14
+ }
15
+
16
+ /** What {@linkcode skillResources} returns: pass `resources` to `serveTools`, and report `skipped`. */
17
+ export interface SkillResources {
18
+ readonly resources: readonly ServeToolsResource[];
19
+ readonly skipped: readonly SkippedSkillResource[];
20
+ }
21
+
22
+ /** One frontmatter value in block style (the subset every Agent Skills reader accepts): quoted strings, nested mappings, `- ` lists. */
23
+ function renderYaml(key: string, value: unknown, indent: string): string[] {
24
+ const label = `${indent}${/^[A-Za-z0-9_-]+$/.test(key) ? key : JSON.stringify(key)}:`;
25
+ if (Array.isArray(value)) {
26
+ if (value.length === 0) return [`${label} []`];
27
+ return [
28
+ label,
29
+ ...value.map((item) => `${indent} - ${typeof item === "object" && item !== null ? JSON.stringify(item) : scalar(item)}`),
30
+ ];
31
+ }
32
+ if (typeof value === "object" && value !== null) {
33
+ const entries = Object.entries(value);
34
+ return entries.length === 0 ? [`${label} {}`] : [label, ...entries.flatMap(([k, v]) => renderYaml(k, v, `${indent} `))];
35
+ }
36
+ return [`${label} ${scalar(value)}`];
37
+ }
38
+
39
+ const scalar = (value: unknown): string => (typeof value === "string" ? JSON.stringify(value) : String(value));
40
+
41
+ /**
42
+ * The skill as a standard Agent Skills `SKILL.md`: frontmatter (`name`, `description`, then every other key the
43
+ * skill carries), a blank line, and the body. Built from the in-memory skill, so it needs no file and cannot drift
44
+ * from what the agent loaded.
45
+ */
46
+ function renderSkillMarkdown(skill: Skill): string {
47
+ const front = [`name: ${JSON.stringify(skill.name)}`];
48
+ if (skill.description !== undefined) front.push(`description: ${JSON.stringify(skill.description)}`);
49
+ for (const [key, value] of Object.entries(skill.metadata ?? {})) front.push(...renderYaml(key, value, ""));
50
+ return `---\n${front.join("\n")}\n---\n\n${skill.instructions ?? ""}`;
51
+ }
52
+
53
+ /**
54
+ * Skills to lend alongside served tools, as `serveTools` resources (`options.resources`).
55
+ *
56
+ * A skill is lent only when its `requiresTools` is non-empty and every name in it is in `servedToolNames`, so a
57
+ * vendor agent never reads guidance for a tool it was not given. A skill with no `requiresTools` is not lent (its
58
+ * applicability to these tools is unknown), and neither is one with no body. A skill whose rendered `SKILL.md`
59
+ * exceeds the 256 KiB resource bound is reported in `skipped`, never truncated. A repeated skill name keeps the
60
+ * first one. Pure and deterministic: input order is kept, nothing is read or sent.
61
+ *
62
+ * `servedToolNames` are the registered names (the `allow` list), the same ones a skill's `requiresTools` uses.
63
+ * `serveTools`' `prefix` is not applied to skill text, so a prefixed endpoint shows the vendor different tool names
64
+ * than the skill names.
65
+ */
66
+ export function skillResources(skills: readonly Skill[], servedToolNames: readonly string[]): SkillResources {
67
+ const served = new Set(servedToolNames);
68
+ const seen = new Set<string>();
69
+ const resources: ServeToolsResource[] = [];
70
+ const skipped: SkippedSkillResource[] = [];
71
+ for (const skill of skills) {
72
+ const required = skill.requiresTools;
73
+ if (required === undefined || required.length === 0 || !required.every((name) => served.has(name))) continue;
74
+ if (skill.instructions === undefined || skill.instructions.trim() === "" || seen.has(skill.name)) continue;
75
+ seen.add(skill.name);
76
+ const text = renderSkillMarkdown(skill);
77
+ const bytes = Buffer.byteLength(text, "utf8");
78
+ if (bytes > MAX_RESOURCE_BYTES) {
79
+ skipped.push({ name: skill.name, reason: "oversized", bytes });
80
+ continue;
81
+ }
82
+ resources.push({ uri: `${SKILL_RESOURCE_SCHEME}${encodeURIComponent(skill.name)}`, name: skill.name, mimeType: "text/markdown", text });
83
+ }
84
+ return { resources, skipped };
85
+ }
@@ -0,0 +1,215 @@
1
+ import type { EventOrigin, JsonObject, JsonValue, OwnershipScope, SecretRedactor, ToolCapabilityKind, ToolDefinition } from "@arnilo/prism";
2
+ import type { CallbackBroker, McpEndpoint } from "@arnilo/prism/driver-kit";
3
+ import type { McpProtectedResource } from "@arnilo/prism-extensions/mcp";
4
+ import type { AuthInfo, CallToolResult, ServerEventBus, ServerNotifier, Transport } from "@modelcontextprotocol/server";
5
+
6
+ /** What `serveMcp`'s `authorize` callback receives before any session is opened. */
7
+ export interface PrismMcpAuthorizationInput {
8
+ readonly kind: "tool" | "prompt";
9
+ readonly name: string;
10
+ readonly arguments: JsonObject;
11
+ readonly authInfo?: AuthInfo;
12
+ readonly sessionId?: string;
13
+ readonly signal: AbortSignal;
14
+ }
15
+
16
+ /**
17
+ * A host decision. `ownership` is carried through unchanged; identity is the agent's own
18
+ * governance concern (governance hooks), not this transport's.
19
+ */
20
+ export interface PrismMcpAuthorization {
21
+ readonly allowed: true;
22
+ readonly ownership?: OwnershipScope;
23
+ readonly metadata?: Readonly<Record<string, unknown>>;
24
+ }
25
+
26
+ export type PrismMcpAuthorizer = (
27
+ input: PrismMcpAuthorizationInput,
28
+ ) => false | PrismMcpAuthorization | Promise<false | PrismMcpAuthorization>;
29
+
30
+ /** Options for {@linkcode serveMcp}. Exactly one transport must be selected. */
31
+ export interface ServeMcpOptions {
32
+ /** Serve the process's stdio. */
33
+ readonly stdio?: true;
34
+ /** Serve a caller-owned transport (in-process tests, embedded hosts). */
35
+ readonly transport?: Transport;
36
+ /** Serve a web-standard Streamable HTTP handler built by {@linkcode createPrismMcpWebHandler}. */
37
+ readonly http?: CreatePrismMcpWebHandlerOptions;
38
+ /**
39
+ * Allow/deny every tool and prompt before a session is opened. Absent allows
40
+ * the peer (a local stdio process); a throwing callback denies.
41
+ */
42
+ readonly authorize?: PrismMcpAuthorizer;
43
+ /** Tool name. Default `prompt`. */
44
+ readonly toolName?: string;
45
+ readonly serverName?: string;
46
+ readonly serverVersion?: string;
47
+ /** Masks secrets in tool results and errors. */
48
+ readonly redactor?: SecretRedactor;
49
+ /** Byte ceiling on one `prompt` argument. Default 64 KiB, hard cap 1 MiB. */
50
+ readonly maxPromptBytes?: number;
51
+ /** Byte ceiling on one tool/prompt result. Default 1 MiB, hard cap 8 MiB. */
52
+ readonly maxResultBytes?: number;
53
+ }
54
+
55
+ /** Handle returned by {@linkcode serveMcp}. */
56
+ export interface ServeMcpHandle {
57
+ /** Resolves when the connection ends or {@linkcode ServeMcpHandle.close} is called. */
58
+ readonly closed: Promise<void>;
59
+ close(): Promise<void>;
60
+ /** Web-standard handler; present only for `{ http }`. */
61
+ readonly handler?: (request: Request) => Promise<Response>;
62
+ }
63
+
64
+ export interface PrismMcpRequestIdentity {
65
+ /** Stable non-secret principal identifier derived from validated host auth. */
66
+ readonly id: string;
67
+ readonly ownership?: OwnershipScope;
68
+ }
69
+
70
+ export interface CreatePrismMcpWebHandlerOptions {
71
+ readonly resolveAuthInfo?: (request: Request) => AuthInfo | undefined | Promise<AuthInfo | undefined>;
72
+ /** Required for stateful sessions; binds every session request to one validated host principal. */
73
+ readonly resolveIdentity?: (
74
+ request: Request,
75
+ authInfo: AuthInfo | undefined,
76
+ ) => PrismMcpRequestIdentity | false | Promise<PrismMcpRequestIdentity | false>;
77
+ /** When set, serves RFC 9728 protected-resource metadata and challenges unauthenticated requests. */
78
+ readonly protectedResource?: McpProtectedResource;
79
+ /** Legacy-only: configures sessionful 2025-era serving beside the modern handler. */
80
+ readonly sessionIdGenerator?: () => string;
81
+ readonly maxSessions?: number;
82
+ /** Exact Host header allowlist; checked before body parsing and auth on every request. */
83
+ readonly allowedHosts?: readonly string[];
84
+ /** Exact Origin allowlist; checked before body parsing and auth on every request. */
85
+ readonly allowedOrigins?: readonly string[];
86
+ readonly maxRequestBytes?: number;
87
+ readonly maxResponseBytes?: number;
88
+ readonly maxConcurrentRequests?: number;
89
+ readonly requestTimeoutMs?: number;
90
+ /** Ceiling on concurrently open modern `subscriptions/listen` streams (SDK default 1024). */
91
+ readonly maxSubscriptions?: number;
92
+ /** SSE keepalive interval in ms for modern subscription streams; 0 disables (SDK default 15000). */
93
+ readonly keepAliveMs?: number;
94
+ }
95
+
96
+ /**
97
+ * Callable web handler with SDK lifecycle/notification properties. The call
98
+ * signature stays source-compatible with pre-2.0 handlers; `fetch` is the
99
+ * same function as the web-standard face, `close` tears down both eras, and
100
+ * `notify`/`bus` publish to open modern `subscriptions/listen` streams.
101
+ */
102
+ export type PrismMcpWebHandler = ((request: Request) => Promise<Response>) & {
103
+ readonly fetch: (request: Request) => Promise<Response>;
104
+ close(): Promise<void>;
105
+ readonly notify: ServerNotifier;
106
+ readonly bus: ServerEventBus;
107
+ };
108
+
109
+ /** Options for {@linkcode servePrismMcpStdio} (dual-era stdio serving). */
110
+ export interface ServePrismMcpStdioOptions {
111
+ /** `serve` (default) pins a 2025-era instance for a legacy opening; `reject` answers it with the unsupported-protocol-version error. */
112
+ readonly legacy?: "serve" | "reject";
113
+ /** Bring your own transport instead of the process's stdio. */
114
+ readonly transport?: Transport;
115
+ /** Ceiling on concurrently open `subscriptions/listen` streams on the connection (SDK default 1024). */
116
+ readonly maxSubscriptions?: number;
117
+ }
118
+
119
+ /** Handle returned by {@linkcode servePrismMcpStdio}. */
120
+ export interface PrismMcpStdioHandle {
121
+ close(): Promise<void>;
122
+ }
123
+
124
+ /** A static MCP resource `serveTools` serves. Host-supplied text, served as-is. */
125
+ export interface ServeToolsResource {
126
+ readonly uri: string;
127
+ readonly name: string;
128
+ readonly mimeType?: string;
129
+ /** Served verbatim. Never put a secret here: `resources/read` returns it to the client unchanged. */
130
+ readonly text: string;
131
+ }
132
+
133
+ /** Bounds for {@linkcode serveTools}. */
134
+ export interface ServeToolsLimits {
135
+ /** In-flight `tools/call` ceiling. Default 8, hard cap 64. A call over the cap is a JSON-RPC error, never queued. */
136
+ readonly maxConcurrentCalls?: number;
137
+ /** Byte ceiling on one tool result. Default 1 MiB, hard cap 8 MiB. */
138
+ readonly resultBytes?: number;
139
+ }
140
+
141
+ /** How the driver's binary reaches the served tools. */
142
+ export type ServeToolsTransport = "loopback-http" | "stdio-relay";
143
+
144
+ /** The neutral permission-tool input, after decoding. */
145
+ export interface PermissionRequest {
146
+ readonly toolName: string;
147
+ readonly input: JsonObject;
148
+ /** Defaults to a fresh random id. */
149
+ readonly toolCallId?: string;
150
+ }
151
+
152
+ /** The neutral permission-tool decision, the JSON text of a neutral `tools/call` result. */
153
+ export interface PermissionDecision {
154
+ readonly behavior: "allow" | "deny";
155
+ /** Present on an allow when `rewrite` is set and the gate rewrote the arguments. */
156
+ readonly updatedInput?: JsonObject;
157
+ /** Present on a deny: why the call was not allowed. */
158
+ readonly message?: string;
159
+ }
160
+
161
+ /**
162
+ * Maps a vendor's permission-prompt shape to and from the neutral one. `decode` receives the raw
163
+ * `tools/call` arguments; `encode` returns the whole MCP result. This is the only vendor-shape hook
164
+ * in the package — none ships. A throwing `decode` or `encode` denies in the neutral shape.
165
+ */
166
+ export interface PermissionCodec {
167
+ decode(args: JsonValue): PermissionRequest;
168
+ encode(decision: PermissionDecision): CallToolResult;
169
+ }
170
+
171
+ /** The optional permission-prompt tool {@linkcode serveTools} serves beside the allow list. */
172
+ export interface ServeToolsPermissionTool {
173
+ /** Served as `prefix + name`; must not collide with an allow-listed tool. */
174
+ readonly name: string;
175
+ /** The effects `run.ask` gates on. Default `() => ALL_TOOL_EFFECTS`, as `effectsTable` treats an unknown name. */
176
+ readonly effects?: (toolName: string) => readonly ToolCapabilityKind[];
177
+ /** Pass `rewrite: true` to `run.ask`, so a gate rewrite becomes `updatedInput`. Default `false`. */
178
+ readonly rewrite?: boolean;
179
+ readonly codec?: PermissionCodec;
180
+ }
181
+
182
+ /** Options for {@linkcode serveTools}. */
183
+ export interface ServeToolsOptions {
184
+ /** The run's callback broker. `serveTools` mounts its handler on `route("mcp")` and unregisters it on close. */
185
+ readonly broker: CallbackBroker;
186
+ /** The tool definitions to resolve the allow list against (no run-time registry read exists). */
187
+ readonly tools: readonly ToolDefinition[];
188
+ /** Tool names to serve. Every other tool is invisible; a call naming one is a JSON-RPC error. */
189
+ readonly allow: readonly string[];
190
+ readonly transport: ServeToolsTransport;
191
+ /** The bridge origin every served call is attributed to. */
192
+ readonly origin: EventOrigin;
193
+ /** Prepended to each served tool name in `tools/list` and `tools/call`. */
194
+ readonly prefix?: string;
195
+ /** Also serve a permission-prompt tool backed by `run.ask`. Each decision is one `prism.permissions` entry. */
196
+ readonly permissionTool?: ServeToolsPermissionTool;
197
+ readonly resources?: readonly ServeToolsResource[];
198
+ readonly limits?: ServeToolsLimits;
199
+ /** Required for `stdio-relay`: the binary to spawn. `relay mcp --run <dir>` is appended. */
200
+ readonly relay?: { readonly command: readonly string[] };
201
+ /** Bearer-token environment variable name. Default `PRISM_MCP_TOKEN`. */
202
+ readonly headerEnv?: string;
203
+ }
204
+
205
+ /** Handle returned by {@linkcode serveTools}. */
206
+ export interface ServeToolsHandle {
207
+ /** Map this into the driver's own MCP configuration; never carries the token. */
208
+ readonly endpoint: McpEndpoint;
209
+ /** The child's environment: the bearer token under `headerEnv` for `loopback-http`, empty for `stdio-relay`. */
210
+ readonly env: Readonly<Record<string, string>>;
211
+ /** The served tool names, prefixed: the allow list in order, then the permission tool when one is served. */
212
+ readonly tools: readonly string[];
213
+ /** Idempotent: unregisters the route, closes the web handler, and drops the abort listener. */
214
+ close(): Promise<void>;
215
+ }
package/package.json CHANGED
@@ -1,6 +1,132 @@
1
1
  {
2
2
  "name": "@arnilo/prism-hosts",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.13.1",
4
+ "description": "Prism host libraries, process driver and version-exact host-builder kit. Import each library through its subpath.",
5
+ "type": "module",
6
+ "exports": {
7
+ "./mcp-server": "./mcp-server/src/index.ts",
8
+ "./acp": "./acp/src/index.ts",
9
+ "./ag-ui": "./ag-ui/src/index.ts",
10
+ "./ag-ui/renderer": "./ag-ui/src/renderer/index.ts",
11
+ "./channels": "./channels/src/index.ts",
12
+ "./channels/telegram": "./channels/src/telegram.ts",
13
+ "./channels/signal": "./channels/src/signal.ts",
14
+ "./evals": "./evals/src/index.ts",
15
+ "./devtools": "./devtools/src/index.ts",
16
+ "./remote": "./remote/src/index.ts",
17
+ "./remote/testing": "./remote/src/testing.ts",
18
+ "./headless": "./headless/src/index.ts",
19
+ "./host-builder": "./host-builder/src/index.ts",
20
+ "./driver-process": "./driver-process/src/index.ts",
21
+ "./driver-process/testing": "./driver-process/src/testing.ts"
22
+ },
23
+ "files": [
24
+ "mcp-server/src",
25
+ "!mcp-server/src/**/__tests__",
26
+ "mcp-server/README.md",
27
+ "acp/src",
28
+ "!acp/src/**/__tests__",
29
+ "acp/README.md",
30
+ "ag-ui/src",
31
+ "!ag-ui/src/**/__tests__",
32
+ "ag-ui/README.md",
33
+ "channels/src",
34
+ "!channels/src/**/__tests__",
35
+ "channels/README.md",
36
+ "evals/src",
37
+ "!evals/src/**/__tests__",
38
+ "evals/README.md",
39
+ "devtools/src",
40
+ "!devtools/src/**/__tests__",
41
+ "devtools/bin",
42
+ "devtools/README.md",
43
+ "remote/src",
44
+ "!remote/src/**/__tests__",
45
+ "remote/README.md",
46
+ "headless/src",
47
+ "!headless/src/**/__tests__",
48
+ "headless/README.md",
49
+ "host-builder/src",
50
+ "!host-builder/src/**/__tests__",
51
+ "host-builder/bin",
52
+ "host-builder/data",
53
+ "host-builder/skills",
54
+ "host-builder/README.md",
55
+ "driver-process/src",
56
+ "!driver-process/src/**/__tests__",
57
+ "driver-process/README.md",
58
+ "README.md",
59
+ "CHANGELOG.md",
60
+ "LICENSE"
61
+ ],
62
+ "scripts": {
63
+ "test": "bun ../../scripts/with-build-lock.mjs --shared bun test --parallel=4 --timeout=0 mcp-server/src acp/src ag-ui/src channels/src evals/src devtools/src remote/src headless/src host-builder/src driver-process/src --path-ignore-patterns=channels/src/__tests__/postgres.integration.test.ts",
64
+ "typecheck": "tsc -p tsconfig.json --noEmit",
65
+ "test:postgres": "bun ../../scripts/require-postgres-url.mjs && bun ../../scripts/with-build-lock.mjs --shared bun test --timeout=0 channels/src/__tests__/postgres.integration.test.ts",
66
+ "pack:dry-run": "bun pm pack --dry-run"
67
+ },
68
+ "peerDependencies": {
69
+ "@arnilo/prism": ">=0.13.0 <1.0.0",
70
+ "@agentclientprotocol/sdk": "1.4.0",
71
+ "@ag-ui/core": "1.0.4",
72
+ "@modelcontextprotocol/server": "^2.3.0",
73
+ "zod": "^4.6.6"
74
+ },
75
+ "devDependencies": {
76
+ "@modelcontextprotocol/client": "^2.3.0",
77
+ "@types/node": "^22.20.0",
78
+ "typescript": "^7.0.2",
79
+ "@arnilo/prism-extensions": "0.13.2",
80
+ "@arnilo/prism-tools": "0.13.2",
81
+ "@ag-ui/client": "1.0.4",
82
+ "@types/pg": "^8.23.1",
83
+ "pg": "^8.23.0",
84
+ "@agentclientprotocol/sdk": "1.4.0",
85
+ "@ag-ui/core": "1.0.4",
86
+ "@modelcontextprotocol/server": "^2.3.0",
87
+ "zod": "^4.6.6"
88
+ },
89
+ "engines": {
90
+ "bun": ">=1.4.4"
91
+ },
92
+ "license": "MIT",
93
+ "repository": {
94
+ "type": "git",
95
+ "url": "git+https://github.com/ashiqrniloy/prism.git",
96
+ "directory": "packages/hosts"
97
+ },
98
+ "bugs": {
99
+ "url": "https://github.com/ashiqrniloy/prism/issues"
100
+ },
101
+ "homepage": "https://github.com/ashiqrniloy/prism/tree/main/packages/hosts#readme",
102
+ "keywords": [
103
+ "prism",
104
+ "hosts",
105
+ "agents"
106
+ ],
107
+ "sideEffects": false,
108
+ "publishConfig": {
109
+ "access": "public"
110
+ },
111
+ "bin": {
112
+ "prism-devtools": "./devtools/bin/prism-devtools.ts",
113
+ "prism-host-builder": "./host-builder/bin/prism-host-builder.ts"
114
+ },
115
+ "dependencies": {
116
+ "@arnilo/prism-extensions": "^0.13.0"
117
+ },
118
+ "peerDependenciesMeta": {
119
+ "@agentclientprotocol/sdk": {
120
+ "optional": true
121
+ },
122
+ "@ag-ui/core": {
123
+ "optional": true
124
+ },
125
+ "@modelcontextprotocol/server": {
126
+ "optional": true
127
+ },
128
+ "zod": {
129
+ "optional": true
130
+ }
131
+ }
132
+ }