@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,95 @@
|
|
|
1
|
+
import type { Agent, OwnershipScope, SecretRedactor } from "@arnilo/prism";
|
|
2
|
+
import type { ChannelDeliveryJournal } from "./delivery.js";
|
|
3
|
+
import type { ChannelStateStore } from "./state.js";
|
|
4
|
+
import type {
|
|
5
|
+
ChannelAuthorization,
|
|
6
|
+
ChannelInboundEvent,
|
|
7
|
+
ChannelOperationRecord,
|
|
8
|
+
ChannelRuntimeOptions,
|
|
9
|
+
ResolvedChannelLimits,
|
|
10
|
+
} from "./types.js";
|
|
11
|
+
|
|
12
|
+
export const MAX_ID_BYTES = 256;
|
|
13
|
+
export const MAX_ERROR_BYTES = 512;
|
|
14
|
+
export const TRUNCATION_MARKER = "…[truncated]";
|
|
15
|
+
export const GENERIC_FAILURE = "The request failed before it produced an answer.";
|
|
16
|
+
export const HELP_TEXT = "Commands: /help, /status, /new, /cancel.";
|
|
17
|
+
export const COMMAND_NAMES: ReadonlySet<string> = new Set(["help", "status", "new", "cancel"]);
|
|
18
|
+
export const MAX_ATTACHMENT_REFS = 8;
|
|
19
|
+
export const MAX_ATTACHMENT_META_BYTES = 256;
|
|
20
|
+
export const UNSUPPORTED_MEDIA_NOTICE = "That attachment cannot be processed by the selected agent.";
|
|
21
|
+
|
|
22
|
+
export interface Turn {
|
|
23
|
+
readonly event: ChannelInboundEvent;
|
|
24
|
+
readonly authorization: ChannelAuthorization;
|
|
25
|
+
readonly ownership: OwnershipScope;
|
|
26
|
+
readonly alias?: string;
|
|
27
|
+
readonly operationId: string;
|
|
28
|
+
cancelled: boolean;
|
|
29
|
+
controller?: AbortController;
|
|
30
|
+
opVersion?: number;
|
|
31
|
+
opRecord?: ChannelOperationRecord;
|
|
32
|
+
lease?: RouteLease;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export interface RouteLease {
|
|
36
|
+
readonly key: string;
|
|
37
|
+
token: string;
|
|
38
|
+
fencingToken: number;
|
|
39
|
+
expiresAt: number;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface RouteState {
|
|
43
|
+
readonly connectionId: string;
|
|
44
|
+
readonly externalConversationId: string;
|
|
45
|
+
readonly externalActorId: string;
|
|
46
|
+
readonly threadId?: string;
|
|
47
|
+
readonly alias?: string;
|
|
48
|
+
generation: number;
|
|
49
|
+
sessionId?: string;
|
|
50
|
+
leafId?: string;
|
|
51
|
+
suspended: boolean;
|
|
52
|
+
suspendedRun?: { readonly operationId: string; readonly runId: string; readonly sessionId: string; readonly approvalId?: string };
|
|
53
|
+
resuming: boolean;
|
|
54
|
+
pumping: boolean;
|
|
55
|
+
hydrated: boolean;
|
|
56
|
+
bindingVersion?: number;
|
|
57
|
+
ownershipHint?: OwnershipScope;
|
|
58
|
+
lease?: RouteLease;
|
|
59
|
+
readonly queue: Turn[];
|
|
60
|
+
active?: Turn;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface Counters {
|
|
64
|
+
admitted: number;
|
|
65
|
+
denied: number;
|
|
66
|
+
unsupported: number;
|
|
67
|
+
duplicates: number;
|
|
68
|
+
completed: number;
|
|
69
|
+
failed: number;
|
|
70
|
+
cancelled: number;
|
|
71
|
+
suspended: number;
|
|
72
|
+
deliveries: number;
|
|
73
|
+
deliveryFailures: number;
|
|
74
|
+
truncated: number;
|
|
75
|
+
storageFailures: number;
|
|
76
|
+
leaseLosses: number;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export interface RuntimeContext {
|
|
80
|
+
readonly agent: Agent;
|
|
81
|
+
readonly options: ChannelRuntimeOptions;
|
|
82
|
+
readonly limits: ResolvedChannelLimits;
|
|
83
|
+
readonly redactor: SecretRedactor | undefined;
|
|
84
|
+
readonly journal: ChannelStateStore | undefined;
|
|
85
|
+
readonly replies: ChannelDeliveryJournal | undefined;
|
|
86
|
+
readonly approvals: ReturnType<typeof import("./approvals.js").createChannelApprovalStore> | undefined;
|
|
87
|
+
readonly leaseOwnerId: string;
|
|
88
|
+
readonly counters: Counters;
|
|
89
|
+
readonly routes: Map<string, RouteState>;
|
|
90
|
+
readonly seenEvents: Map<string, { ids: Set<string>; order: string[] }>;
|
|
91
|
+
readonly inflight: Set<Promise<void>>;
|
|
92
|
+
readonly slotWaiters: (() => void)[];
|
|
93
|
+
activeRuns: number;
|
|
94
|
+
stopped: boolean;
|
|
95
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { randomUUID } from "node:crypto";
|
|
2
|
+
import type { Agent } from "@arnilo/prism";
|
|
3
|
+
import { createChannelApprovalStore } from "./approvals.js";
|
|
4
|
+
import { createChannelDeliveryJournal } from "./delivery.js";
|
|
5
|
+
import { registerChannelHostUi } from "./host-ui.js";
|
|
6
|
+
import { resolveChannelLimits } from "./limits.js";
|
|
7
|
+
import { createRuntimeAdmit } from "./runtime-admit.js";
|
|
8
|
+
import { createRuntimeCore } from "./runtime-core.js";
|
|
9
|
+
import { createRuntimeReconcile } from "./runtime-reconcile.js";
|
|
10
|
+
import { createRuntimeTurn } from "./runtime-turn.js";
|
|
11
|
+
import type { Counters, RuntimeContext } from "./runtime-types.js";
|
|
12
|
+
import { createChannelStateStore } from "./state.js";
|
|
13
|
+
import type { ChannelRuntime, ChannelRuntimeOptions } from "./types.js";
|
|
14
|
+
|
|
15
|
+
export function createChannelRuntime(agent: Agent, options: ChannelRuntimeOptions): ChannelRuntime {
|
|
16
|
+
const limits = resolveChannelLimits(options.limits);
|
|
17
|
+
const journal =
|
|
18
|
+
options.checkpoints === undefined
|
|
19
|
+
? undefined
|
|
20
|
+
: createChannelStateStore({ checkpoints: options.checkpoints, maxJournalRecordBytes: limits.maxJournalRecordBytes });
|
|
21
|
+
const replies =
|
|
22
|
+
options.checkpoints === undefined
|
|
23
|
+
? undefined
|
|
24
|
+
: createChannelDeliveryJournal({ checkpoints: options.checkpoints, maxJournalRecordBytes: limits.maxJournalRecordBytes });
|
|
25
|
+
const counters: Counters = {
|
|
26
|
+
admitted: 0,
|
|
27
|
+
denied: 0,
|
|
28
|
+
unsupported: 0,
|
|
29
|
+
duplicates: 0,
|
|
30
|
+
completed: 0,
|
|
31
|
+
failed: 0,
|
|
32
|
+
cancelled: 0,
|
|
33
|
+
suspended: 0,
|
|
34
|
+
deliveries: 0,
|
|
35
|
+
deliveryFailures: 0,
|
|
36
|
+
truncated: 0,
|
|
37
|
+
storageFailures: 0,
|
|
38
|
+
leaseLosses: 0,
|
|
39
|
+
};
|
|
40
|
+
const ctx: RuntimeContext = {
|
|
41
|
+
agent,
|
|
42
|
+
options,
|
|
43
|
+
limits,
|
|
44
|
+
redactor: options.redactor,
|
|
45
|
+
journal,
|
|
46
|
+
replies,
|
|
47
|
+
approvals: options.checkpoints === undefined ? undefined : createChannelApprovalStore(options.checkpoints),
|
|
48
|
+
leaseOwnerId: `channel-runtime-${randomUUID()}`,
|
|
49
|
+
counters,
|
|
50
|
+
routes: new Map(),
|
|
51
|
+
seenEvents: new Map(),
|
|
52
|
+
inflight: new Set(),
|
|
53
|
+
slotWaiters: [],
|
|
54
|
+
activeRuns: 0,
|
|
55
|
+
stopped: false,
|
|
56
|
+
};
|
|
57
|
+
const core = createRuntimeCore(ctx);
|
|
58
|
+
const turns = createRuntimeTurn(ctx, core);
|
|
59
|
+
const admissions = createRuntimeAdmit(ctx, core, turns);
|
|
60
|
+
const recovery = createRuntimeReconcile(ctx, core);
|
|
61
|
+
let ui: ReturnType<typeof registerChannelHostUi>;
|
|
62
|
+
const runtime: ChannelRuntime = {
|
|
63
|
+
async admit(event) {
|
|
64
|
+
if (
|
|
65
|
+
ctx.stopped ||
|
|
66
|
+
!core.validEvent(event) ||
|
|
67
|
+
Buffer.byteLength(event.text, "utf8") > limits.maxInputBytes ||
|
|
68
|
+
core.declaredAttachmentBytes(event) > limits.maxAttachmentBytes
|
|
69
|
+
)
|
|
70
|
+
return admissions.admit(event);
|
|
71
|
+
return (await ui.admit(event)) ?? (await admissions.admit(event));
|
|
72
|
+
},
|
|
73
|
+
notify: admissions.notifyBinding,
|
|
74
|
+
drain: recovery.drain,
|
|
75
|
+
diagnostics: recovery.diagnostics,
|
|
76
|
+
async stop() {
|
|
77
|
+
ui.close();
|
|
78
|
+
await recovery.stop();
|
|
79
|
+
},
|
|
80
|
+
reconcile: recovery.reconcile,
|
|
81
|
+
listUnresolved: recovery.listUnresolved,
|
|
82
|
+
prune: recovery.prune,
|
|
83
|
+
};
|
|
84
|
+
ui = registerChannelHostUi(runtime, ctx, core);
|
|
85
|
+
return runtime;
|
|
86
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { Agent, CredentialResolver, SecretRedactor } from "@arnilo/prism";
|
|
2
|
+
import { createEnvRefCredentialResolver, redactSecrets } from "@arnilo/prism";
|
|
3
|
+
|
|
4
|
+
export const CHANNEL_TOKEN_LITERAL_CODE = "ERR_PRISM_CHANNEL_TOKEN_LITERAL";
|
|
5
|
+
|
|
6
|
+
export class ChannelTokenLiteralError extends Error {
|
|
7
|
+
readonly code = CHANNEL_TOKEN_LITERAL_CODE;
|
|
8
|
+
constructor(message = "Channel credential must be a ref (env: or keyring:), not a literal secret") {
|
|
9
|
+
super(message);
|
|
10
|
+
this.name = "ChannelTokenLiteralError";
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/** A lazily resolved channel secret (the kit's `SecretSource` shape). `connect*` builds it from a ref. */
|
|
15
|
+
export type ChannelSecretSource = () => Promise<string>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Resolves an `env:`/`keyring:` ref through the agent's directly assigned credentials slot, else the
|
|
19
|
+
* kernel's `env:` resolver. A literal fails with {@link ChannelTokenLiteralError}; an unresolved ref fails closed.
|
|
20
|
+
*/
|
|
21
|
+
export async function resolveChannelSecretRef(agent: Agent, ref: string): Promise<string> {
|
|
22
|
+
if (typeof ref !== "string" || (!ref.startsWith("env:") && !ref.startsWith("keyring:"))) {
|
|
23
|
+
throw new ChannelTokenLiteralError();
|
|
24
|
+
}
|
|
25
|
+
const assigned = agent.config?.slots?.credentials;
|
|
26
|
+
const resolver: CredentialResolver = typeof assigned === "object" ? assigned : createEnvRefCredentialResolver();
|
|
27
|
+
const resolved = (await resolver.resolve(ref, { package: "@arnilo/prism-hosts/channels" }))?.value;
|
|
28
|
+
if (!resolved || resolved.trim().length === 0) {
|
|
29
|
+
throw new Error(`Failed to resolve channel credential reference: ${ref}`);
|
|
30
|
+
}
|
|
31
|
+
return resolved;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export function createChannelRedactor(secret: string | readonly string[], agentRedactor?: SecretRedactor): SecretRedactor {
|
|
35
|
+
const secrets = typeof secret === "string" ? [secret] : secret;
|
|
36
|
+
return {
|
|
37
|
+
redact<T>(value: T): T {
|
|
38
|
+
const masked = redactSecrets(value, secrets);
|
|
39
|
+
return agentRedactor ? agentRedactor.redact(masked) : masked;
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
}
|