@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,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Truthful ACP capability negotiation (Phase 10 Task 2 freeze).
|
|
3
|
+
*
|
|
4
|
+
* `resolveAcpAgentCapabilities` is a pure function of host-wired seams: an
|
|
5
|
+
* absent seam omits the matching capability key — never an empty stub that
|
|
6
|
+
* implies support. Client capabilities are read from the initialize request
|
|
7
|
+
* and gate later client-method use (`resolveAcpClientCapabilities`).
|
|
8
|
+
*
|
|
9
|
+
* Frozen never-cells (scripts/phase10-freeze-manifest.json capabilityMatrix):
|
|
10
|
+
* mcpCapabilities.acp, sessionCapabilities.fork, auth, providers, nes,
|
|
11
|
+
* positionEncoding — all UNSTABLE v2 surface, never advertised in 0.0.27.
|
|
12
|
+
*/
|
|
13
|
+
import type { AgentCapabilities, ClientCapabilities, ContentBlock, McpServer } from "@agentclientprotocol/sdk";
|
|
14
|
+
import type { Session, SessionEntry } from "@arnilo/prism";
|
|
15
|
+
|
|
16
|
+
/** Structural stand-in for the old agent's session binding. Extra fields stay assignable. */
|
|
17
|
+
interface AcpSessionBinding {
|
|
18
|
+
readonly session: Session;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** One row of `session/list`; maps onto SDK `SessionInfo` (cwd is schema-required). */
|
|
22
|
+
export interface AcpSessionSummary {
|
|
23
|
+
readonly sessionId: string;
|
|
24
|
+
/** Absolute working directory. */
|
|
25
|
+
readonly cwd: string;
|
|
26
|
+
/** Complete ordered additional-root list, when the session has any. */
|
|
27
|
+
readonly additionalDirectories?: readonly string[];
|
|
28
|
+
readonly title?: string;
|
|
29
|
+
/** ISO 8601 timestamp of last activity. */
|
|
30
|
+
readonly updatedAt?: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Host-owned session store seams. Presence of a seam advertises the matching capability. */
|
|
34
|
+
export interface AcpSessionStoreSeams {
|
|
35
|
+
/** `session/load`: reconstruct a stored session. `sessionId` omitted means "most recent" (ACP spec). */
|
|
36
|
+
readonly load?: (input: {
|
|
37
|
+
readonly sessionId?: string;
|
|
38
|
+
readonly cwd: string;
|
|
39
|
+
readonly signal: AbortSignal;
|
|
40
|
+
}) => AcpSessionBinding | Promise<AcpSessionBinding>;
|
|
41
|
+
/** `session/list`: ordered known sessions; the agent pages by cursor. */
|
|
42
|
+
readonly list?: (input: {
|
|
43
|
+
readonly cwd?: string;
|
|
44
|
+
readonly signal: AbortSignal;
|
|
45
|
+
}) => readonly AcpSessionSummary[] | Promise<readonly AcpSessionSummary[]>;
|
|
46
|
+
/** `session/delete`: remove a stored session. */
|
|
47
|
+
readonly delete?: (input: { readonly sessionId: string; readonly signal: AbortSignal }) => void | Promise<void>;
|
|
48
|
+
/** `session/resume`: resume a session's durable run. */
|
|
49
|
+
readonly resume?: (input: {
|
|
50
|
+
readonly sessionId: string;
|
|
51
|
+
readonly cwd: string;
|
|
52
|
+
readonly signal: AbortSignal;
|
|
53
|
+
}) => AcpSessionBinding | Promise<AcpSessionBinding>;
|
|
54
|
+
/** F2: optional transcript source. When present, `session/load` and `session/resume`
|
|
55
|
+
* replay bounded, redacted `user_message_chunk`/`agent_message_chunk` text updates
|
|
56
|
+
* (≤ `maxReplayEvents` chunks, each ≤ `maxTextBytes`) before returning `sessionState`.
|
|
57
|
+
* Absent seam = no replay, behavior unchanged. */
|
|
58
|
+
readonly transcript?: (input: {
|
|
59
|
+
readonly sessionId: string;
|
|
60
|
+
readonly signal: AbortSignal;
|
|
61
|
+
}) => readonly SessionEntry[] | Promise<readonly SessionEntry[]>;
|
|
62
|
+
/** Policy seam: returns the allowed subset of requested additional directories (order preserved). */
|
|
63
|
+
readonly additionalDirectories?: (input: {
|
|
64
|
+
readonly directories: readonly string[];
|
|
65
|
+
readonly signal: AbortSignal;
|
|
66
|
+
}) => readonly string[] | Promise<readonly string[]>;
|
|
67
|
+
/** F6: host-owned session title (e.g., a first-prompt summary). Resolved on
|
|
68
|
+
* `session/new` (when a prompt is present) and `session/prompt`; a defined
|
|
69
|
+
* value that differs from the last emitted title produces `session_info_update`.
|
|
70
|
+
* Best-effort: `undefined` or a throw means no title and no update — the
|
|
71
|
+
* request never fails on title resolution. The host owns title storage. */
|
|
72
|
+
readonly title?: (input: {
|
|
73
|
+
readonly sessionId: string;
|
|
74
|
+
readonly prompt?: readonly ContentBlock[];
|
|
75
|
+
readonly signal: AbortSignal;
|
|
76
|
+
}) => string | undefined | Promise<string | undefined>;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** MCP seams. `mcpCapabilities.{http,sse}` are advertised per transport only when `select` is present. */
|
|
80
|
+
export interface AcpMcpSeams {
|
|
81
|
+
/** Host approval gate for client-supplied MCP servers; runs before any bridge connect. */
|
|
82
|
+
readonly select?: (input: { readonly servers: readonly McpServer[]; readonly signal: AbortSignal }) => boolean | Promise<boolean>;
|
|
83
|
+
/** Transports the host bridge supports (http/sse). Absent or empty => no MCP advertisement. */
|
|
84
|
+
readonly transports?: readonly ("http" | "sse")[];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Host-reported context window for truthful `usage_update` (B1). Absent/undefined/throw => the update is omitted. */
|
|
88
|
+
export interface AcpUsageSeam {
|
|
89
|
+
/**
|
|
90
|
+
* Return the model's context window in tokens. `model` is the provider model id
|
|
91
|
+
* from the finished turn's metadata. `undefined` (or a throw) omits the update
|
|
92
|
+
* entirely — the mapper never fabricates `size`.
|
|
93
|
+
*/
|
|
94
|
+
readonly contextWindow?: (input: {
|
|
95
|
+
readonly model?: string;
|
|
96
|
+
readonly signal: AbortSignal;
|
|
97
|
+
}) => number | undefined | Promise<number | undefined>;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** One slash command advertised to the client (F9). Maps onto SDK `AvailableCommand`. */
|
|
101
|
+
export interface AcpCommand {
|
|
102
|
+
readonly name: string;
|
|
103
|
+
readonly description: string;
|
|
104
|
+
readonly input?: { readonly hint: string };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** Host-owned slash-command list (F9). Absent seam ⇒ no `available_commands_update`. */
|
|
108
|
+
export interface AcpCommandsSeam {
|
|
109
|
+
readonly list: (input: {
|
|
110
|
+
readonly sessionId: string;
|
|
111
|
+
readonly signal: AbortSignal;
|
|
112
|
+
}) => readonly AcpCommand[] | Promise<readonly AcpCommand[]>;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/** Capability policy seams that do not own protocol handlers. */
|
|
116
|
+
export interface AcpCapabilitiesOptions {
|
|
117
|
+
readonly prompt?: {
|
|
118
|
+
/** Present => `promptCapabilities.image` and `promptCapabilities.audio` are advertised. */
|
|
119
|
+
readonly media?: (input: { readonly signal: AbortSignal }) => boolean | Promise<boolean>;
|
|
120
|
+
/** Present => `promptCapabilities.embeddedContext` is advertised. */
|
|
121
|
+
readonly embedded?: (input: { readonly signal: AbortSignal }) => boolean | Promise<boolean>;
|
|
122
|
+
};
|
|
123
|
+
/** Present => `usage_update` carries the host-reported context window; absent => the update is omitted. */
|
|
124
|
+
readonly usage?: AcpUsageSeam;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** The subset of agent options that drives capability advertisement. */
|
|
128
|
+
export interface AcpCapabilitiesSource {
|
|
129
|
+
readonly sessions?: AcpSessionStoreSeams;
|
|
130
|
+
readonly mcp?: AcpMcpSeams;
|
|
131
|
+
readonly capabilities?: AcpCapabilitiesOptions;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** O(1) over the frozen capability field count; never touches I/O. */
|
|
135
|
+
export function resolveAcpAgentCapabilities(options: AcpCapabilitiesSource): AgentCapabilities {
|
|
136
|
+
const sessionCapabilities: NonNullable<AgentCapabilities["sessionCapabilities"]> = { close: {} };
|
|
137
|
+
if (options.sessions?.list) sessionCapabilities.list = {};
|
|
138
|
+
if (options.sessions?.delete) sessionCapabilities.delete = {};
|
|
139
|
+
if (options.sessions?.resume) sessionCapabilities.resume = {};
|
|
140
|
+
if (options.sessions?.additionalDirectories) sessionCapabilities.additionalDirectories = {};
|
|
141
|
+
|
|
142
|
+
const capabilities: AgentCapabilities = { sessionCapabilities };
|
|
143
|
+
if (options.sessions?.load) capabilities.loadSession = true;
|
|
144
|
+
|
|
145
|
+
const prompt = options.capabilities?.prompt;
|
|
146
|
+
if (prompt?.media || prompt?.embedded) {
|
|
147
|
+
capabilities.promptCapabilities = {};
|
|
148
|
+
if (prompt.media) {
|
|
149
|
+
capabilities.promptCapabilities.image = true;
|
|
150
|
+
capabilities.promptCapabilities.audio = true;
|
|
151
|
+
}
|
|
152
|
+
if (prompt.embedded) capabilities.promptCapabilities.embeddedContext = true;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
const transports = options.mcp?.select ? options.mcp.transports : undefined;
|
|
156
|
+
if (transports?.length) {
|
|
157
|
+
capabilities.mcpCapabilities = {};
|
|
158
|
+
if (transports.includes("http")) capabilities.mcpCapabilities.http = true;
|
|
159
|
+
if (transports.includes("sse")) capabilities.mcpCapabilities.sse = true;
|
|
160
|
+
}
|
|
161
|
+
return capabilities;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/** Client-side advertisements read from the initialize request; every flag defaults closed. */
|
|
165
|
+
export interface ResolvedAcpClientCapabilities {
|
|
166
|
+
readonly fsReadTextFile: boolean;
|
|
167
|
+
readonly fsWriteTextFile: boolean;
|
|
168
|
+
readonly terminal: boolean;
|
|
169
|
+
readonly configOptionBoolean: boolean;
|
|
170
|
+
readonly elicitation: boolean;
|
|
171
|
+
/** UNSTABLE plan surface (F5): plan_update/plan_removed only for advertising clients. */
|
|
172
|
+
readonly plan: boolean;
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function resolveAcpClientCapabilities(client?: ClientCapabilities): ResolvedAcpClientCapabilities {
|
|
176
|
+
return {
|
|
177
|
+
fsReadTextFile: client?.fs?.readTextFile ?? false,
|
|
178
|
+
fsWriteTextFile: client?.fs?.writeTextFile ?? false,
|
|
179
|
+
terminal: client?.terminal ?? false,
|
|
180
|
+
configOptionBoolean: client?.session?.configOptions?.boolean != null,
|
|
181
|
+
elicitation: client?.elicitation != null,
|
|
182
|
+
plan: client?.plan != null,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ACP adapter error codes (Phase 10 freeze, scripts/phase10-freeze-manifest.json
|
|
3
|
+
* errorCodes): INPUT (malformed protocol input), LIMIT (frozen cap exceeded),
|
|
4
|
+
* POLICY (host policy denial), CAPABILITY (client method called without the
|
|
5
|
+
* matching initialize advertisement), MCP (MCP seam failures), RUN (run-level
|
|
6
|
+
* failure surfaced as a `session/prompt` request error, 0.2.8 B2).
|
|
7
|
+
*/
|
|
8
|
+
export type AcpErrorCode =
|
|
9
|
+
| "ERR_PRISM_ACP_INPUT"
|
|
10
|
+
| "ERR_PRISM_ACP_LIMIT"
|
|
11
|
+
| "ERR_PRISM_ACP_POLICY"
|
|
12
|
+
| "ERR_PRISM_ACP_CAPABILITY"
|
|
13
|
+
| "ERR_PRISM_ACP_MCP"
|
|
14
|
+
| "ERR_PRISM_ACP_RUN";
|
|
15
|
+
|
|
16
|
+
export class AcpError extends Error {
|
|
17
|
+
readonly code: AcpErrorCode;
|
|
18
|
+
|
|
19
|
+
constructor(code: AcpErrorCode, message: string) {
|
|
20
|
+
super(message);
|
|
21
|
+
this.name = "AcpError";
|
|
22
|
+
this.code = code;
|
|
23
|
+
}
|
|
24
|
+
}
|
package/acp/src/host.ts
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { HostPort, HostUi, HostUiRequest, HostUiResponse } from "@arnilo/prism";
|
|
2
|
+
import { boundAcpSession, brandAcpHost } from "./session-map.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Host port whose `ui` routes by the kernel-stamped `sessionId`.
|
|
6
|
+
* A kernel ask (`package` absent) and `secret` answer `unavailable`, so approvals
|
|
7
|
+
* suspend onto `session/request_permission` instead of a boolean confirm.
|
|
8
|
+
*/
|
|
9
|
+
export function acpHost(): HostPort {
|
|
10
|
+
const port: HostPort = {
|
|
11
|
+
ui: {
|
|
12
|
+
request: (async (request: HostUiRequest): Promise<HostUiResponse> => {
|
|
13
|
+
if (request.package === undefined || request.kind === "secret" || request.kind === "terminal") return { status: "unavailable" };
|
|
14
|
+
const bound = boundAcpSession(port, request.sessionId);
|
|
15
|
+
if (!bound) return { status: "unavailable" };
|
|
16
|
+
if (request.kind === "notify") {
|
|
17
|
+
await bound.notify(request.message);
|
|
18
|
+
return { status: "answered", value: undefined };
|
|
19
|
+
}
|
|
20
|
+
if (request.kind === "open-url") {
|
|
21
|
+
await bound.notify(request.url);
|
|
22
|
+
return { status: "answered", value: undefined };
|
|
23
|
+
}
|
|
24
|
+
if (!bound.elicitation) return { status: "unavailable" };
|
|
25
|
+
return bound.elicit({
|
|
26
|
+
kind: request.kind,
|
|
27
|
+
title: request.title,
|
|
28
|
+
detail: "detail" in request ? request.detail : undefined,
|
|
29
|
+
...(request.kind === "select" ? { options: request.options } : {}),
|
|
30
|
+
});
|
|
31
|
+
}) as HostUi["request"],
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
brandAcpHost(port);
|
|
35
|
+
return port;
|
|
36
|
+
}
|
package/acp/src/index.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export {
|
|
2
|
+
type AcpCapabilitiesOptions,
|
|
3
|
+
type AcpCapabilitiesSource,
|
|
4
|
+
type AcpCommand,
|
|
5
|
+
type AcpCommandsSeam,
|
|
6
|
+
type AcpMcpSeams,
|
|
7
|
+
type AcpSessionStoreSeams,
|
|
8
|
+
type AcpSessionSummary,
|
|
9
|
+
type AcpUsageSeam,
|
|
10
|
+
type ResolvedAcpClientCapabilities,
|
|
11
|
+
resolveAcpAgentCapabilities,
|
|
12
|
+
resolveAcpClientCapabilities,
|
|
13
|
+
} from "./capabilities.js";
|
|
14
|
+
export { AcpError, type AcpErrorCode } from "./errors.js";
|
|
15
|
+
export { acpHost } from "./host.js";
|
|
16
|
+
export { ACP_LIMITS, type AcpLimitOptions, type ResolvedAcpLimits, resolveAcpLimits } from "./limits.js";
|
|
17
|
+
export {
|
|
18
|
+
type AcpEventMapper,
|
|
19
|
+
type AcpEventMapperOptions,
|
|
20
|
+
type AcpLifecycleMapper,
|
|
21
|
+
createAcpEventMapper,
|
|
22
|
+
createAcpLifecycleMapper,
|
|
23
|
+
} from "./mapper.js";
|
|
24
|
+
export { type AcpPromptMedia, type AcpPromptOptions, type AcpPromptResult, projectAcpPrompt } from "./prompt.js";
|
|
25
|
+
export { type ServeAcpHandle, type ServeAcpOptions, serveAcp } from "./serve.js";
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { AcpError } from "./errors.js";
|
|
2
|
+
|
|
3
|
+
/** Defaults copied from `packages/ag-ui/src/limits.ts`. A host may narrow them, never raise them. */
|
|
4
|
+
export const ACP_LIMITS = {
|
|
5
|
+
maxEventBytes: 64 * 1024,
|
|
6
|
+
maxTextBytes: 64 * 1024,
|
|
7
|
+
maxReplayEvents: 100,
|
|
8
|
+
maxStreamEvents: 10_000,
|
|
9
|
+
maxStreamBytes: 10 * 1024 * 1024,
|
|
10
|
+
acpDiffBytes: 64 * 1024,
|
|
11
|
+
acpLocationsPerUpdate: 32,
|
|
12
|
+
acpImageBytes: 256 * 1024,
|
|
13
|
+
acpCommandsPerUpdate: 32,
|
|
14
|
+
} as const;
|
|
15
|
+
|
|
16
|
+
const HARD = {
|
|
17
|
+
maxEventBytes: 1024 * 1024,
|
|
18
|
+
maxTextBytes: 1024 * 1024,
|
|
19
|
+
maxReplayEvents: 500,
|
|
20
|
+
maxStreamEvents: 100_000,
|
|
21
|
+
maxStreamBytes: 64 * 1024 * 1024,
|
|
22
|
+
acpDiffBytes: 1024 * 1024,
|
|
23
|
+
acpLocationsPerUpdate: 128,
|
|
24
|
+
acpImageBytes: 1024 * 1024,
|
|
25
|
+
acpCommandsPerUpdate: 128,
|
|
26
|
+
} as const;
|
|
27
|
+
|
|
28
|
+
export type AcpLimitName = keyof typeof ACP_LIMITS;
|
|
29
|
+
|
|
30
|
+
export type AcpLimitOptions = { readonly [K in AcpLimitName]?: number };
|
|
31
|
+
|
|
32
|
+
export type ResolvedAcpLimits = { readonly [K in AcpLimitName]: number };
|
|
33
|
+
|
|
34
|
+
export function resolveAcpLimits(options: AcpLimitOptions = {}): ResolvedAcpLimits {
|
|
35
|
+
const resolved = {} as Record<AcpLimitName, number>;
|
|
36
|
+
for (const name of Object.keys(ACP_LIMITS) as AcpLimitName[]) {
|
|
37
|
+
resolved[name] = validate(name, options[name] ?? ACP_LIMITS[name]);
|
|
38
|
+
}
|
|
39
|
+
return resolved;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function validate(name: AcpLimitName, value: number): number {
|
|
43
|
+
const hard = HARD[name];
|
|
44
|
+
const minimum = name.endsWith("Bytes") ? (name === "maxTextBytes" ? 16 : 1024) : 1;
|
|
45
|
+
if (!Number.isSafeInteger(value) || value < minimum || value > hard) {
|
|
46
|
+
throw new AcpError("ERR_PRISM_ACP_LIMIT", `${name} must be a safe integer from ${minimum} through ${hard}`);
|
|
47
|
+
}
|
|
48
|
+
return value;
|
|
49
|
+
}
|