@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
package/acp/src/serve.ts
ADDED
|
@@ -0,0 +1,345 @@
|
|
|
1
|
+
import { Readable, Writable } from "node:stream";
|
|
2
|
+
import {
|
|
3
|
+
type AgentContext,
|
|
4
|
+
agent,
|
|
5
|
+
methods,
|
|
6
|
+
ndJsonStream,
|
|
7
|
+
PROTOCOL_VERSION,
|
|
8
|
+
RequestError,
|
|
9
|
+
type RequestPermissionResponse,
|
|
10
|
+
type SessionUpdate,
|
|
11
|
+
type Stream,
|
|
12
|
+
} from "@agentclientprotocol/sdk";
|
|
13
|
+
import type { Agent, AgentEvent, AgentFinishReason, Decision, JsonObject, PendingDecision, Session } from "@arnilo/prism";
|
|
14
|
+
import { isSessionNotFound } from "@arnilo/prism";
|
|
15
|
+
import manifest from "../../package.json" with { type: "json" };
|
|
16
|
+
import { AcpError } from "./errors.js";
|
|
17
|
+
import { resolveAcpLimits } from "./limits.js";
|
|
18
|
+
import { createAcpEventMapper } from "./mapper.js";
|
|
19
|
+
import { decisionForPermission, elicitationRequest, PERMISSION_OPTIONS } from "./permission.js";
|
|
20
|
+
import { projectAcpPrompt } from "./prompt.js";
|
|
21
|
+
import { bindAcpSession, type ElicitRequest, type ElicitResult, isAcpHost, unbindAcpSession } from "./session-map.js";
|
|
22
|
+
|
|
23
|
+
export interface ServeAcpOptions {
|
|
24
|
+
/** Serve one local stdio peer. Mutually exclusive with `stream`. */
|
|
25
|
+
readonly stdio?: true;
|
|
26
|
+
/** ACP `Stream` for in-process tests and embedded hosts. */
|
|
27
|
+
readonly stream?: Stream;
|
|
28
|
+
/** Per-connection allow/deny. Absent allows the peer. `false` is a JSON-RPC error and creates no session. */
|
|
29
|
+
readonly authorize?: (input: { readonly peer: "stdio" | "stream" }) => boolean | Promise<boolean>;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface ServeAcpHandle {
|
|
33
|
+
readonly closed: Promise<void>;
|
|
34
|
+
close(): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const STOP: Readonly<Record<AgentFinishReason, "max_turn_requests" | "max_tokens" | "refusal" | "end_turn">> = {
|
|
38
|
+
turn_limit: "max_turn_requests",
|
|
39
|
+
token_limit: "max_tokens",
|
|
40
|
+
refusal: "refusal",
|
|
41
|
+
hook_stop: "end_turn",
|
|
42
|
+
hook_limit: "end_turn",
|
|
43
|
+
denied: "refusal",
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Serve an existing agent over ACP v1. Approvals suspend (`interactive: false`) and
|
|
48
|
+
* resume through one `session/request_permission` per pending decision.
|
|
49
|
+
*/
|
|
50
|
+
export function serveAcp(prism: Agent, options: ServeAcpOptions): ServeAcpHandle {
|
|
51
|
+
if (options.stdio === true && options.stream) throw new AcpError("ERR_PRISM_ACP_INPUT", "serveAcp takes stdio or stream, not both");
|
|
52
|
+
if (options.stdio !== true && !options.stream)
|
|
53
|
+
throw new AcpError("ERR_PRISM_ACP_INPUT", "serveAcp requires { stdio: true } or { stream }");
|
|
54
|
+
const stream = options.stream ?? stdioStream();
|
|
55
|
+
const limits = resolveAcpLimits();
|
|
56
|
+
const host = isAcpHost(prism.config.host) ? prism.config.host : undefined;
|
|
57
|
+
const sessions = new Map<string, Session>();
|
|
58
|
+
const cancelled = new Set<string>();
|
|
59
|
+
const cancelWaiters = new Map<string, Array<() => void>>();
|
|
60
|
+
let elicitation = false;
|
|
61
|
+
let authorized = false;
|
|
62
|
+
let opened = false;
|
|
63
|
+
|
|
64
|
+
const app = agent({ name: "prism" });
|
|
65
|
+
app.onRequest(methods.agent.initialize, async (ctx) => {
|
|
66
|
+
opened = true;
|
|
67
|
+
const allowed = options.authorize ? await options.authorize({ peer: options.stdio === true ? "stdio" : "stream" }) : true;
|
|
68
|
+
authorized = allowed === true;
|
|
69
|
+
if (!authorized) throw RequestError.invalidRequest(undefined, "connection denied");
|
|
70
|
+
elicitation = ctx.params.clientCapabilities?.elicitation != null;
|
|
71
|
+
return {
|
|
72
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
73
|
+
agentCapabilities: { loadSession: true },
|
|
74
|
+
agentInfo: { name: "prism", version: manifest.version },
|
|
75
|
+
};
|
|
76
|
+
});
|
|
77
|
+
app.onRequest(methods.agent.session.new, async (ctx) => {
|
|
78
|
+
assertAuthorized(authorized, opened);
|
|
79
|
+
rejectMcpServers(ctx.params.mcpServers);
|
|
80
|
+
const session = await prism.session();
|
|
81
|
+
remember(session, ctx.client);
|
|
82
|
+
await publishCommands(ctx.client, session);
|
|
83
|
+
return { sessionId: session.id };
|
|
84
|
+
});
|
|
85
|
+
app.onRequest(methods.agent.session.load, async (ctx) => {
|
|
86
|
+
assertAuthorized(authorized, opened);
|
|
87
|
+
rejectMcpServers(ctx.params.mcpServers);
|
|
88
|
+
const session = await openStored(prism, ctx.params.sessionId);
|
|
89
|
+
remember(session, ctx.client);
|
|
90
|
+
await replay(ctx.client, session);
|
|
91
|
+
await publishCommands(ctx.client, session);
|
|
92
|
+
return {};
|
|
93
|
+
});
|
|
94
|
+
app.onRequest(methods.agent.session.prompt, async (ctx) => {
|
|
95
|
+
assertAuthorized(authorized, opened);
|
|
96
|
+
const session = sessions.get(ctx.params.sessionId);
|
|
97
|
+
if (!session) throw RequestError.invalidParams(undefined, "unknown session");
|
|
98
|
+
cancelled.delete(session.id);
|
|
99
|
+
const text = await promptText(ctx.params.prompt);
|
|
100
|
+
const command = commandOf(text, prism);
|
|
101
|
+
if (command) {
|
|
102
|
+
await prism.commands.run(command.name, command.args, { session });
|
|
103
|
+
return { stopReason: "end_turn" as const };
|
|
104
|
+
}
|
|
105
|
+
const stopReason = await runPrompt(session, text, ctx.client, ctx.signal);
|
|
106
|
+
return { stopReason };
|
|
107
|
+
});
|
|
108
|
+
app.onNotification(methods.agent.session.cancel, (ctx) => {
|
|
109
|
+
const session = sessions.get(ctx.params.sessionId);
|
|
110
|
+
if (!session) return;
|
|
111
|
+
cancelled.add(session.id);
|
|
112
|
+
session.abort();
|
|
113
|
+
for (const wake of cancelWaiters.get(session.id) ?? []) wake();
|
|
114
|
+
cancelWaiters.delete(session.id);
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
const connection = app.connect(stream);
|
|
118
|
+
return {
|
|
119
|
+
closed: connection.closed,
|
|
120
|
+
close: async () => {
|
|
121
|
+
for (const id of sessions.keys()) unbindAcpSession(host, id);
|
|
122
|
+
sessions.clear();
|
|
123
|
+
connection.close();
|
|
124
|
+
await connection.closed.catch(() => undefined);
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
function remember(session: Session, client: AgentContext): void {
|
|
129
|
+
sessions.set(session.id, session);
|
|
130
|
+
if (!host) return;
|
|
131
|
+
bindAcpSession(host, session.id, {
|
|
132
|
+
elicitation,
|
|
133
|
+
notify: async (text) => {
|
|
134
|
+
await send(client, session.id, { sessionUpdate: "agent_message_chunk", content: { type: "text", text: clip(text) } });
|
|
135
|
+
},
|
|
136
|
+
elicit: (request) => elicit(client, session.id, request),
|
|
137
|
+
cancelPermission: () => cancelled.add(session.id),
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
async function runPrompt(
|
|
142
|
+
session: Session,
|
|
143
|
+
input: string,
|
|
144
|
+
client: AgentContext,
|
|
145
|
+
signal: AbortSignal,
|
|
146
|
+
): Promise<"end_turn" | "max_tokens" | "max_turn_requests" | "refusal" | "cancelled"> {
|
|
147
|
+
const mapper = createAcpEventMapper({ redactor: prism.config.redactor });
|
|
148
|
+
let pending: readonly PendingDecision[] | undefined;
|
|
149
|
+
let stop: "end_turn" | "max_tokens" | "max_turn_requests" | "refusal" | "cancelled" = "end_turn";
|
|
150
|
+
let failed: string | undefined;
|
|
151
|
+
const consume = async (events: AsyncIterable<AgentEvent>): Promise<void> => {
|
|
152
|
+
let sent = 0;
|
|
153
|
+
for await (const event of events) {
|
|
154
|
+
if (cancelled.has(session.id) || signal.aborted) {
|
|
155
|
+
stop = "cancelled";
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (event.type === "run.suspended") {
|
|
159
|
+
pending = event.interruption.pendingDecisions ?? [];
|
|
160
|
+
continue;
|
|
161
|
+
}
|
|
162
|
+
if (event.type === "run.failed") {
|
|
163
|
+
failed = event.error.message;
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (event.type === "run.completed") {
|
|
167
|
+
stop = event.status === "completed" || !event.stopReason ? "end_turn" : STOP[event.stopReason];
|
|
168
|
+
}
|
|
169
|
+
if (sent >= limits.maxStreamEvents) continue;
|
|
170
|
+
for (const update of await mapper.map(event)) {
|
|
171
|
+
await send(client, session.id, update);
|
|
172
|
+
sent += 1;
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
};
|
|
176
|
+
await consume(session.stream(input, { interactive: false, signal }));
|
|
177
|
+
while (pending && pending.length > 0 && !cancelled.has(session.id) && !signal.aborted && !failed) {
|
|
178
|
+
const decisions = await requestPermissions(client, session.id, pending);
|
|
179
|
+
if (cancelled.has(session.id) || signal.aborted) return "cancelled";
|
|
180
|
+
pending = undefined;
|
|
181
|
+
await consume(session.resume(decisions, { interactive: false, signal }));
|
|
182
|
+
}
|
|
183
|
+
if (failed) throw RequestError.internalError(undefined, clip(failed));
|
|
184
|
+
return cancelled.has(session.id) || signal.aborted ? "cancelled" : stop;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
async function requestPermissions(client: AgentContext, sessionId: string, pending: readonly PendingDecision[]): Promise<Decision[]> {
|
|
188
|
+
const decisions: Decision[] = [];
|
|
189
|
+
for (const item of pending) {
|
|
190
|
+
if (cancelled.has(sessionId)) {
|
|
191
|
+
decisions.push({ approvalId: item.approvalId, outcome: "reject_once" });
|
|
192
|
+
continue;
|
|
193
|
+
}
|
|
194
|
+
let response: RequestPermissionResponse;
|
|
195
|
+
try {
|
|
196
|
+
const cancelledResponse: RequestPermissionResponse = { outcome: { outcome: "cancelled" } };
|
|
197
|
+
response = await Promise.race<RequestPermissionResponse>([
|
|
198
|
+
client.request(methods.client.session.requestPermission, {
|
|
199
|
+
sessionId,
|
|
200
|
+
toolCall: {
|
|
201
|
+
toolCallId: clip(item.toolCallId ?? item.approvalId),
|
|
202
|
+
title: clip(item.scope.toolName ?? "tool"),
|
|
203
|
+
kind: "other",
|
|
204
|
+
status: "pending",
|
|
205
|
+
},
|
|
206
|
+
options: [...PERMISSION_OPTIONS],
|
|
207
|
+
}),
|
|
208
|
+
whenCancelled(sessionId).then(() => cancelledResponse),
|
|
209
|
+
]);
|
|
210
|
+
} catch {
|
|
211
|
+
response = { outcome: { outcome: "cancelled" as const } };
|
|
212
|
+
}
|
|
213
|
+
if (cancelled.has(sessionId)) {
|
|
214
|
+
decisions.push({ approvalId: item.approvalId, outcome: "reject_once" });
|
|
215
|
+
continue;
|
|
216
|
+
}
|
|
217
|
+
decisions.push(decisionForPermission(item, response));
|
|
218
|
+
}
|
|
219
|
+
return decisions;
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
async function publishCommands(client: AgentContext, session: Session): Promise<void> {
|
|
223
|
+
const availableCommands = prism.commands
|
|
224
|
+
.list()
|
|
225
|
+
.slice(0, limits.acpCommandsPerUpdate)
|
|
226
|
+
.map((command) => ({
|
|
227
|
+
name: clip(command.name),
|
|
228
|
+
description: clip(command.description),
|
|
229
|
+
}));
|
|
230
|
+
if (availableCommands.length === 0) return;
|
|
231
|
+
await send(client, session.id, { sessionUpdate: "available_commands_update", availableCommands });
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
async function replay(client: AgentContext, session: Session): Promise<void> {
|
|
235
|
+
const messages = await session.messages();
|
|
236
|
+
let sent = 0;
|
|
237
|
+
for (const message of messages) {
|
|
238
|
+
if (message.role !== "user" && message.role !== "assistant") continue;
|
|
239
|
+
for (const block of message.content) {
|
|
240
|
+
if (block.type !== "text" || sent >= limits.maxReplayEvents) continue;
|
|
241
|
+
const text = clip(prism.config.redactor?.redact(block.text) ?? block.text);
|
|
242
|
+
await send(client, session.id, {
|
|
243
|
+
sessionUpdate: message.role === "user" ? "user_message_chunk" : "agent_message_chunk",
|
|
244
|
+
messageId: message.id,
|
|
245
|
+
content: { type: "text", text },
|
|
246
|
+
});
|
|
247
|
+
sent += 1;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
function whenCancelled(sessionId: string): Promise<void> {
|
|
253
|
+
if (cancelled.has(sessionId)) return Promise.resolve();
|
|
254
|
+
return new Promise((resolve) => {
|
|
255
|
+
const list = cancelWaiters.get(sessionId) ?? [];
|
|
256
|
+
list.push(resolve);
|
|
257
|
+
cancelWaiters.set(sessionId, list);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
function clip(value: string): string {
|
|
262
|
+
const redacted = prism.config.redactor?.redact(value) ?? value;
|
|
263
|
+
if (Buffer.byteLength(redacted, "utf8") <= limits.maxTextBytes) return redacted;
|
|
264
|
+
return redacted.slice(0, limits.maxTextBytes);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
async function send(client: AgentContext, sessionId: string, update: SessionUpdate): Promise<void> {
|
|
268
|
+
await client.notify(methods.client.session.update, { sessionId, update });
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
async function elicit(client: AgentContext, sessionId: string, request: ElicitRequest): Promise<ElicitResult> {
|
|
272
|
+
const schema =
|
|
273
|
+
request.kind === "confirm"
|
|
274
|
+
? { type: "object" as const, properties: { approved: { type: "boolean" as const } }, required: ["approved"] }
|
|
275
|
+
: request.kind === "select"
|
|
276
|
+
? {
|
|
277
|
+
type: "object" as const,
|
|
278
|
+
properties: { value: { type: "string" as const, enum: (request.options ?? []).map((option) => option.value) } },
|
|
279
|
+
required: ["value"],
|
|
280
|
+
}
|
|
281
|
+
: { type: "object" as const, properties: { value: { type: "string" as const } }, required: ["value"] };
|
|
282
|
+
try {
|
|
283
|
+
const response = await client.request(
|
|
284
|
+
methods.client.elicitation.create,
|
|
285
|
+
elicitationRequest(sessionId, clip(request.title), request.detail ? clip(request.detail) : undefined, schema as never),
|
|
286
|
+
);
|
|
287
|
+
if (response.action !== "accept") return { status: "dismissed" };
|
|
288
|
+
const content = response.content;
|
|
289
|
+
if (request.kind === "confirm") {
|
|
290
|
+
const approved = content && typeof content === "object" && "approved" in content ? content.approved === true : false;
|
|
291
|
+
return approved ? { status: "answered", value: true } : { status: "dismissed" };
|
|
292
|
+
}
|
|
293
|
+
const value = content && typeof content === "object" && "value" in content ? content.value : undefined;
|
|
294
|
+
return typeof value === "string" ? { status: "answered", value } : { status: "dismissed" };
|
|
295
|
+
} catch {
|
|
296
|
+
return { status: "unavailable" };
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
function stdioStream(): Stream {
|
|
302
|
+
return ndJsonStream(
|
|
303
|
+
Writable.toWeb(process.stdout) as WritableStream<Uint8Array>,
|
|
304
|
+
Readable.toWeb(process.stdin) as ReadableStream<Uint8Array>,
|
|
305
|
+
);
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
function assertAuthorized(authorized: boolean, opened: boolean): void {
|
|
309
|
+
if (!opened || !authorized) throw RequestError.invalidRequest(undefined, "connection denied");
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
function rejectMcpServers(servers: readonly unknown[]): void {
|
|
313
|
+
if (servers.length > 0) throw RequestError.invalidParams(undefined, "mcpServers is not supported");
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
async function openStored(prism: Agent, id: string): Promise<Session> {
|
|
317
|
+
try {
|
|
318
|
+
return await prism.session({ id });
|
|
319
|
+
} catch (error) {
|
|
320
|
+
if (isSessionNotFound(error)) throw RequestError.invalidParams(undefined, "unknown session");
|
|
321
|
+
throw error;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
async function promptText(prompt: readonly { readonly type: string }[]): Promise<string> {
|
|
326
|
+
const limits = resolveAcpLimits();
|
|
327
|
+
const projected = await projectAcpPrompt(prompt, {
|
|
328
|
+
maxBlocks: 32,
|
|
329
|
+
maxTextBytes: limits.maxTextBytes,
|
|
330
|
+
maxMediaParts: 0,
|
|
331
|
+
maxMediaBytes: limits.maxEventBytes,
|
|
332
|
+
capabilities: { image: false, audio: false, embeddedContext: false },
|
|
333
|
+
});
|
|
334
|
+
return projected.text;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function commandOf(text: string, prism: Agent): { readonly name: string; readonly args: JsonObject } | undefined {
|
|
338
|
+
if (!text.startsWith("/")) return undefined;
|
|
339
|
+
const body = text.slice(1).trim();
|
|
340
|
+
const space = body.indexOf(" ");
|
|
341
|
+
const name = space === -1 ? body : body.slice(0, space);
|
|
342
|
+
if (!prism.commands.list().some((command) => command.name === name)) return undefined;
|
|
343
|
+
const rest = space === -1 ? "" : body.slice(space + 1).trim();
|
|
344
|
+
return { name, args: rest.length > 0 ? { text: rest } : {} };
|
|
345
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { HostPort } from "@arnilo/prism";
|
|
2
|
+
|
|
3
|
+
/** One ACP session bound to the connection that owns it. */
|
|
4
|
+
export interface BoundAcpSession {
|
|
5
|
+
readonly elicitation: boolean;
|
|
6
|
+
notify(text: string): Promise<void>;
|
|
7
|
+
elicit(request: ElicitRequest): Promise<ElicitResult>;
|
|
8
|
+
/** Unblock a permission wait. The prompt maps the result to `reject_once` and does not run the tool. */
|
|
9
|
+
cancelPermission(): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export interface ElicitRequest {
|
|
13
|
+
readonly kind: "confirm" | "select" | "input";
|
|
14
|
+
readonly title: string;
|
|
15
|
+
readonly detail?: string;
|
|
16
|
+
readonly options?: readonly { readonly value: string; readonly label?: string }[];
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export type ElicitResult =
|
|
20
|
+
| { readonly status: "answered"; readonly value: boolean | string | readonly string[] }
|
|
21
|
+
| { readonly status: "dismissed" }
|
|
22
|
+
| { readonly status: "unavailable" };
|
|
23
|
+
|
|
24
|
+
const branded = new WeakSet<object>();
|
|
25
|
+
const tables = new WeakMap<object, Map<string, BoundAcpSession>>();
|
|
26
|
+
|
|
27
|
+
export function brandAcpHost(port: HostPort): void {
|
|
28
|
+
branded.add(port);
|
|
29
|
+
tables.set(port, new Map());
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export function isAcpHost(port: HostPort | undefined): port is HostPort {
|
|
33
|
+
return port !== undefined && branded.has(port);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function bindAcpSession(port: HostPort | undefined, sessionId: string, bound: BoundAcpSession): void {
|
|
37
|
+
if (!port) return;
|
|
38
|
+
tables.get(port)?.set(sessionId, bound);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export function unbindAcpSession(port: HostPort | undefined, sessionId: string): void {
|
|
42
|
+
if (!port) return;
|
|
43
|
+
tables.get(port)?.delete(sessionId);
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export function boundAcpSession(port: HostPort, sessionId: string | undefined): BoundAcpSession | undefined {
|
|
47
|
+
if (!sessionId) return undefined;
|
|
48
|
+
return tables.get(port)?.get(sessionId);
|
|
49
|
+
}
|
package/ag-ui/README.md
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
# @arnilo/prism-hosts/ag-ui
|
|
2
|
+
|
|
3
|
+
Host library that serves a Prism `Agent` over AG-UI, plus the framework-free protocol adapters and a reference renderer. Import is inert: no network, listener, run, tool, state, filesystem, or editor capability starts or appears on import.
|
|
4
|
+
|
|
5
|
+
> Released in 0.0.12 as an event mapper; Phase 8 HITL/A2UI in 0.0.25. Phase 10 (plan 161) reshapes it into a host library over the public `Agent`/`Session` API and moves it to `packages/hosts/ag-ui`. Install it with the matching `@arnilo/prism` version.
|
|
6
|
+
|
|
7
|
+
## AG-UI
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { createAgUiHandler } from "@arnilo/prism-hosts/ag-ui";
|
|
11
|
+
|
|
12
|
+
const handle = createAgUiHandler(agent, { authorize: (req) => checkBearer(req) });
|
|
13
|
+
Bun.serve({ port: 8787, fetch: handle });
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`createAgUiHandler(agent, options?)` returns a `(request: Request) => Promise<Response>` and a schema-validated `capabilities` snapshot:
|
|
17
|
+
|
|
18
|
+
- `threadId` selects the session: `agent.session({ id: threadId, create: true, ownership: authorization.ownership })`.
|
|
19
|
+
- The run streams `session.stream(messages, { ownership: authorization.ownership, interactive: false })` as bounded AG-UI SSE through `createAgUiEventMapper`.
|
|
20
|
+
- A suspended run ends in `RUN_FINISHED` with `outcome: { type: "interrupt", interrupts }`. Each interrupt stands for one pending decision and carries its `approvalId`, tool call id, tool name, and redacted reason in `metadata`.
|
|
21
|
+
- A later request resumes per `@ag-ui/core` `ResumeEntry`: `{ interruptId, status: "resolved" | "cancelled", payload? }`. `status: "cancelled"` is `reject_once`; a resolved payload is exactly `{ outcome: ApprovalOutcome }`. The batch becomes `session.resume(decisions, { ownership: authorization.ownership })` after opening `agent.session({ id: threadId, ownership: authorization.ownership })`.
|
|
22
|
+
- A client disconnect (or the request's `signal`) aborts the run through `session.abort()`.
|
|
23
|
+
- `authorize` is the per-request gate and defaults to **default-deny**: omit it, or return `false`, and the request is `403` before any session opens.
|
|
24
|
+
|
|
25
|
+
`allow_once` / `allow_for_run` / `reject_once` / `reject_for_run` map straight through to the kernel's `ApprovalOutcome`; the kernel re-validates every decision against the recorded pending set under CAS, so a foreign interrupt id, an unknown id, or a drifted agent fails closed before any tool runs.
|
|
26
|
+
|
|
27
|
+
Other root exports:
|
|
28
|
+
|
|
29
|
+
- `createAgUiEventMapper()` — ordered current AG-UI lifecycle/step/text/tool/state/activity/reasoning/raw/custom mapper through safe host projection.
|
|
30
|
+
- `createReasoningEncryptedValue()` — bounded `REASONING_ENCRYPTED_VALUE` fragment from a host-owned `encrypt` function; fails closed, never infers from reasoning signatures.
|
|
31
|
+
- `createPersistenceAgUiReplay()` / `createAgentEventSourceAgUiReplay()` / `createCoWorkReplay()` — ownership-scoped durable replay and co-work page adapters (host-wired; the handler only projects one bounded co-work page after the run when `coWork` is set).
|
|
32
|
+
- `createMessagesFromSessionProjection` / `createStateFromStoreProjection` / `createActivityFromToolProgressProjection` / `composeAgUiProjections` — standard projectors. `Awaitable<T>` hooks are awaited in event order, never `Promise.all`.
|
|
33
|
+
- `createAgUiMcpAdapter()` — host-selected reviewed Prism MCP tools for a host-assembled agent; linked Apps emit standard activity.
|
|
34
|
+
- `createAgUiMcpAppHandler()` / `createAgUiMcpAppSandbox()` — authenticated single-bridge Apps JSON-RPC proxy plus renderer sandbox/CSP config; never executes HTML.
|
|
35
|
+
- `@arnilo/prism-hosts/ag-ui/renderer` — framework-free reference renderer: `createA2UiRenderer({ stream, catalog?, limits?, onAction?, onError?, dom? })` consumes an AG-UI event stream and renders `a2ui-surface` snapshots/deltas into DOM surfaces from a host component catalog. DOM-free `reduceA2UiOps` core, thin DOM binding with default text/container catalog, server-side A2UI caps enforced client-side, fail-closed drops with bounded error events, unknown components render explicit placeholders, never executes remote HTML. Main entry stays runtime-agnostic.
|
|
36
|
+
|
|
37
|
+
Hosts supply authorization, redaction, safe projections, and replay correlation storage. Raw tool args/results/progress, state, activity, reasoning, and raw events stay absent unless a bounded projector returns safe data. Secrets never reach an SSE frame.
|
|
38
|
+
|
|
39
|
+
## ACP
|
|
40
|
+
|
|
41
|
+
ACP v1 serving lives in [`@arnilo/prism-hosts/acp`](../acp/README.md) (plan 161). `@arnilo/prism-hosts/ag-ui` no longer ships the `./acp` subpath: `serveAcp(agent, …)` and `acpHost()` serve any Prism `Agent`, and the ACP event mapper lives there too. See [docs/acp.md](../acp/README.md) for the released 0.12 contract.
|
|
42
|
+
|
|
43
|
+
## Cost, security, and failure behavior
|
|
44
|
+
|
|
45
|
+
- **Narrow-only session ownership:** `createAgUiHandler` passes `authorization.ownership` both when opening the session (`agent.session({ id: threadId, create, ownership: authorization.ownership })`) and on `session.stream` / `session.resume`. Both session opens happen before the SSE response starts.
|
|
46
|
+
- **Indistinguishable `404` on absent or foreign sessions:** `SessionNotFoundError` and `OwnershipScopeError` map to `404 ERR_PRISM_AG_UI_NOT_FOUND` (`{"error":{"code":"ERR_PRISM_AG_UI_NOT_FOUND","message":"Session not found"}}`) before the SSE stream opens, so a response never distinguishes an absent thread from another user's thread.
|
|
47
|
+
- **Scoped pending interrupts:** the handler's in-memory `pending` interrupt map records `authorization.ownership` alongside `threadId` and `approvalId`. A resume request from a different ownership scope is rejected before any session open as a foreign interrupt (`400 ERR_PRISM_AG_UI_INPUT`, matching a wrong `threadId`).
|
|
48
|
+
- **Thread-id squatting avoidance:** because `create: true` on a `threadId` already owned by another scope fails closed with `404 ERR_PRISM_AG_UI_NOT_FOUND`, multi-user hosts should generate `threadId` values on the server or namespace client-supplied ids by principal/scope (for example `${tenantId}:${userId}:${clientThreadId}`).
|
|
49
|
+
|
|
50
|
+
## Limits and security
|
|
51
|
+
|
|
52
|
+
Defaults / hard: request/event/state/activity/reasoning/raw 64 KiB / 1 MiB; input 128 / 1024 messages, 32 / 256 tools/contexts, 8 / 64 interrupts, 16 / 64 media parts; patches 128 / 4096 operations; JSON depth 16 / 64, properties 128 / 4096, arrays 512 / 8192; replay 100 / 500 records; queue 128 / 4096 events; stream 10,000 / 100,000 events and 10 / 64 MiB; request wall time 120 seconds / 30 minutes. SSE only; WebSocket/protobuf/push stay undeclared. Overflow closes with a bounded error. Resume decisions are bounded to 128 entries, 8 KiB reasons, and 64 KiB payloads before the kernel re-validates them.
|
|
53
|
+
|
|
54
|
+
Run the demos with `bun examples/ag-ui-server.ts` (approval interrupt/resume), `bun examples/ag-ui-a2ui.ts` (A2UI painting), and `bun examples/ag-ui-mcp-apps.ts` (MCP Apps proxy).
|
|
55
|
+
|
|
56
|
+
Protocol dependencies are optional peers of `@arnilo/prism-hosts`. Install `@ag-ui/core@1.0.4` and `zod@^4.6.6` for the handler's protocol validation. The renderer only needs `@ag-ui/core`. See the [bundle dependency table](../README.md).
|