@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,244 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type ApprovalOutcome,
|
|
3
|
+
type Decision,
|
|
4
|
+
HARD_MAX_PENDING_DECISIONS,
|
|
5
|
+
HARD_MAX_SESSION_LIST_LIMIT,
|
|
6
|
+
type JsonObject,
|
|
7
|
+
MAX_DECISION_REASON_BYTES,
|
|
8
|
+
MAX_SESSION_LINK_ID_LENGTH,
|
|
9
|
+
type Message,
|
|
10
|
+
type OwnershipScope,
|
|
11
|
+
type PendingDecision,
|
|
12
|
+
type Principal,
|
|
13
|
+
type RunOptions,
|
|
14
|
+
type SessionListQuery,
|
|
15
|
+
type SessionParentLink,
|
|
16
|
+
type SteerOptions,
|
|
17
|
+
} from "@arnilo/prism";
|
|
18
|
+
import { RemoteError } from "./errors.js";
|
|
19
|
+
import type { RemoteRunOptions } from "./protocol.js";
|
|
20
|
+
|
|
21
|
+
export const MAX_APPROVAL_ID_LENGTH = 256;
|
|
22
|
+
export const MAX_SESSION_LIST_CURSOR_LENGTH = 512;
|
|
23
|
+
|
|
24
|
+
const RUN_OPTION_KEYS = new Set(["metadata", "limits", "interactive"]);
|
|
25
|
+
const DECISION_KEYS = new Set(["approvalId", "outcome", "reason", "elicitation"]);
|
|
26
|
+
const APPROVAL_OUTCOMES: ReadonlySet<ApprovalOutcome> = new Set(["allow_once", "allow_for_run", "reject_once", "reject_for_run"]);
|
|
27
|
+
const OWNERSHIP_KEYS = new Set(["tenantId", "accountId", "userId"]);
|
|
28
|
+
const SESSION_LIST_LINK_STRING_KEYS = ["agentId", "parentSessionId", "workflowRunId", "delegationId", "actorAgent"] as const;
|
|
29
|
+
const SESSION_LIST_QUERY_KEYS = new Set<string>(["cursor", "limit", "order", ...SESSION_LIST_LINK_STRING_KEYS, "actorKind"]);
|
|
30
|
+
const PARENT_LINK_KEYS = ["sessionId", "agentId", "workflowRunId", "delegationId"] as const;
|
|
31
|
+
const PARENT_LINK_KEY_SET = new Set<string>(PARENT_LINK_KEYS);
|
|
32
|
+
|
|
33
|
+
export const isObject = (value: unknown): value is JsonObject => value !== null && typeof value === "object" && !Array.isArray(value);
|
|
34
|
+
|
|
35
|
+
export function invalid(message: string): RemoteError {
|
|
36
|
+
return new RemoteError("invalid_params", message);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function str(params: JsonObject, key: string): string {
|
|
40
|
+
const value = params[key];
|
|
41
|
+
if (typeof value !== "string" || value === "") throw invalid(`${key} must be a non-empty string`);
|
|
42
|
+
return value;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function parseInput(value: unknown): string | Message | readonly Message[] {
|
|
46
|
+
if (typeof value === "string" || isObject(value) || Array.isArray(value)) {
|
|
47
|
+
return value as string | Message | readonly Message[];
|
|
48
|
+
}
|
|
49
|
+
throw invalid("input must be a string, a message, or a message list");
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Wire `RunOptions` is an allow-list: a client never chooses `principal`, `ownership`, `redactor`, `signal`, … */
|
|
53
|
+
export function parseRunOptions(value: unknown, principal: Principal | undefined, ownership: OwnershipScope | undefined): RunOptions {
|
|
54
|
+
const identity: RunOptions = {
|
|
55
|
+
...(principal ? { principal } : {}),
|
|
56
|
+
...(ownership ? { ownership } : {}),
|
|
57
|
+
};
|
|
58
|
+
if (value === undefined) return identity;
|
|
59
|
+
if (!isObject(value)) throw invalid("options must be an object");
|
|
60
|
+
for (const key of Object.keys(value)) {
|
|
61
|
+
if (!RUN_OPTION_KEYS.has(key)) throw invalid(`option ${key} is not allowed over the wire`);
|
|
62
|
+
}
|
|
63
|
+
const wire = value as RemoteRunOptions;
|
|
64
|
+
if (wire.metadata !== undefined && !isObject(wire.metadata)) throw invalid("metadata must be an object");
|
|
65
|
+
if (wire.limits !== undefined && !isObject(wire.limits)) throw invalid("limits must be an object");
|
|
66
|
+
if (wire.interactive !== undefined && typeof wire.interactive !== "boolean") {
|
|
67
|
+
throw invalid("interactive must be a boolean");
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
...(wire.metadata ? { metadata: wire.metadata } : {}),
|
|
71
|
+
...(wire.limits ? { limits: wire.limits as RunOptions["limits"] } : {}),
|
|
72
|
+
...(wire.interactive !== undefined ? { interactive: wire.interactive } : {}),
|
|
73
|
+
...identity,
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
export interface ParseDecisionsOptions {
|
|
78
|
+
readonly allowModifiedArguments?: boolean;
|
|
79
|
+
readonly pending?: readonly PendingDecision[];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function isApprovalOutcome(value: unknown): value is ApprovalOutcome {
|
|
83
|
+
return typeof value === "string" && APPROVAL_OUTCOMES.has(value as ApprovalOutcome);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Validates and constructs `Decision` items from wire input. Only `approvalId` (≤ 256 chars), `outcome`
|
|
88
|
+
* (one of the four `ApprovalOutcome` values), `reason` (≤ 2 KiB), and `elicitation` (JSON object, only for
|
|
89
|
+
* pending elicitation decisions) are accepted by default; `modifiedArguments` requires `allowModifiedArguments: true`.
|
|
90
|
+
*/
|
|
91
|
+
export function parseDecisions(value: unknown, options: ParseDecisionsOptions = {}): readonly Decision[] {
|
|
92
|
+
if (!Array.isArray(value) || value.length === 0) throw invalid("decisions must be a non-empty list");
|
|
93
|
+
if (value.length > HARD_MAX_PENDING_DECISIONS) {
|
|
94
|
+
throw invalid(`decisions must contain at most ${HARD_MAX_PENDING_DECISIONS} items`);
|
|
95
|
+
}
|
|
96
|
+
const pendingById = options.pending ? new Map(options.pending.map((item) => [item.approvalId, item])) : undefined;
|
|
97
|
+
const out: Decision[] = [];
|
|
98
|
+
for (const item of value) {
|
|
99
|
+
if (!isObject(item)) throw invalid("malformed decision");
|
|
100
|
+
for (const key of Object.keys(item)) {
|
|
101
|
+
if (key === "modifiedArguments") {
|
|
102
|
+
if (options.allowModifiedArguments !== true) {
|
|
103
|
+
throw invalid("modifiedArguments is not allowed over the wire unless allowModifiedArguments is enabled");
|
|
104
|
+
}
|
|
105
|
+
continue;
|
|
106
|
+
}
|
|
107
|
+
if (!DECISION_KEYS.has(key)) {
|
|
108
|
+
throw invalid(`decision field ${key} is not allowed over the wire`);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (typeof item.approvalId !== "string" || item.approvalId.length === 0 || item.approvalId.length > MAX_APPROVAL_ID_LENGTH) {
|
|
112
|
+
throw invalid(`approvalId must be a non-empty string of at most ${MAX_APPROVAL_ID_LENGTH} characters`);
|
|
113
|
+
}
|
|
114
|
+
if (!isApprovalOutcome(item.outcome)) {
|
|
115
|
+
throw invalid("outcome must be a valid ApprovalOutcome");
|
|
116
|
+
}
|
|
117
|
+
let reason: string | undefined;
|
|
118
|
+
if (item.reason !== undefined) {
|
|
119
|
+
if (typeof item.reason !== "string" || Buffer.byteLength(item.reason, "utf8") > MAX_DECISION_REASON_BYTES) {
|
|
120
|
+
throw invalid(`reason must be a string of at most ${MAX_DECISION_REASON_BYTES} bytes`);
|
|
121
|
+
}
|
|
122
|
+
reason = item.reason;
|
|
123
|
+
}
|
|
124
|
+
let elicitation: JsonObject | undefined;
|
|
125
|
+
if (item.elicitation !== undefined) {
|
|
126
|
+
if (!isObject(item.elicitation)) {
|
|
127
|
+
throw invalid("elicitation must be a JSON object");
|
|
128
|
+
}
|
|
129
|
+
const target = pendingById?.get(item.approvalId);
|
|
130
|
+
if (target?.kind !== "elicitation") {
|
|
131
|
+
throw invalid("elicitation is only allowed for pending elicitation decisions");
|
|
132
|
+
}
|
|
133
|
+
elicitation = item.elicitation;
|
|
134
|
+
}
|
|
135
|
+
let modifiedArguments: JsonObject | undefined;
|
|
136
|
+
if (item.modifiedArguments !== undefined) {
|
|
137
|
+
if (!isObject(item.modifiedArguments)) {
|
|
138
|
+
throw invalid("modifiedArguments must be a JSON object");
|
|
139
|
+
}
|
|
140
|
+
modifiedArguments = item.modifiedArguments;
|
|
141
|
+
}
|
|
142
|
+
out.push({
|
|
143
|
+
approvalId: item.approvalId,
|
|
144
|
+
outcome: item.outcome,
|
|
145
|
+
...(reason !== undefined ? { reason } : {}),
|
|
146
|
+
...(elicitation !== undefined ? { elicitation } : {}),
|
|
147
|
+
...(modifiedArguments !== undefined ? { modifiedArguments } : {}),
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
return out;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/** Validates wire `SteerOptions`: only `softInterrupt: boolean` is accepted. */
|
|
154
|
+
export function parseSteerOptions(value: unknown): SteerOptions | undefined {
|
|
155
|
+
if (value === undefined) return undefined;
|
|
156
|
+
if (!isObject(value)) throw invalid("options must be an object");
|
|
157
|
+
for (const key of Object.keys(value)) {
|
|
158
|
+
if (key !== "softInterrupt") throw invalid(`steer option ${key} is not allowed over the wire`);
|
|
159
|
+
}
|
|
160
|
+
if (value.softInterrupt !== undefined && typeof value.softInterrupt !== "boolean") {
|
|
161
|
+
throw invalid("softInterrupt must be a boolean");
|
|
162
|
+
}
|
|
163
|
+
return value.softInterrupt !== undefined ? { softInterrupt: value.softInterrupt } : {};
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Validates wire `SessionListQuery`: accepts only documented `SessionListQuery` filter and pagination keys,
|
|
168
|
+
* drops client-supplied ownership keys (`tenantId`, `accountId`, `userId`), and applies the server's `ownership` scope.
|
|
169
|
+
*/
|
|
170
|
+
export function parseSessionListQuery(value: unknown, ownership?: OwnershipScope): SessionListQuery | undefined {
|
|
171
|
+
if (value === undefined) {
|
|
172
|
+
return ownership ? { ...ownership } : undefined;
|
|
173
|
+
}
|
|
174
|
+
if (!isObject(value)) throw invalid("query must be an object");
|
|
175
|
+
for (const key of Object.keys(value)) {
|
|
176
|
+
if (OWNERSHIP_KEYS.has(key)) continue;
|
|
177
|
+
if (!SESSION_LIST_QUERY_KEYS.has(key)) {
|
|
178
|
+
throw invalid(`query field ${key} is not allowed over the wire`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (value.limit !== undefined) {
|
|
182
|
+
if (
|
|
183
|
+
typeof value.limit !== "number" ||
|
|
184
|
+
!Number.isSafeInteger(value.limit) ||
|
|
185
|
+
value.limit < 1 ||
|
|
186
|
+
value.limit > HARD_MAX_SESSION_LIST_LIMIT
|
|
187
|
+
) {
|
|
188
|
+
throw invalid(`limit must be an integer from 1 to ${HARD_MAX_SESSION_LIST_LIMIT}`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (value.cursor !== undefined) {
|
|
192
|
+
if (typeof value.cursor !== "string" || value.cursor.length === 0 || value.cursor.length > MAX_SESSION_LIST_CURSOR_LENGTH) {
|
|
193
|
+
throw invalid(`cursor must be a non-empty string of at most ${MAX_SESSION_LIST_CURSOR_LENGTH} characters`);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (value.order !== undefined && value.order !== "asc" && value.order !== "desc") {
|
|
197
|
+
throw invalid('order must be "asc" or "desc"');
|
|
198
|
+
}
|
|
199
|
+
if (value.actorKind !== undefined && value.actorKind !== "prism" && value.actorKind !== "external") {
|
|
200
|
+
throw invalid('actorKind must be "prism" or "external"');
|
|
201
|
+
}
|
|
202
|
+
for (const key of SESSION_LIST_LINK_STRING_KEYS) {
|
|
203
|
+
const field = value[key];
|
|
204
|
+
if (field !== undefined && (typeof field !== "string" || field.length === 0 || field.length > MAX_SESSION_LINK_ID_LENGTH)) {
|
|
205
|
+
throw invalid(`${key} must be a non-empty string of at most ${MAX_SESSION_LINK_ID_LENGTH} characters`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
const out: SessionListQuery = {
|
|
209
|
+
...(value.cursor !== undefined ? { cursor: value.cursor as string } : {}),
|
|
210
|
+
...(value.limit !== undefined ? { limit: value.limit as number } : {}),
|
|
211
|
+
...(value.order !== undefined ? { order: value.order as "asc" | "desc" } : {}),
|
|
212
|
+
...(value.agentId !== undefined ? { agentId: value.agentId as string } : {}),
|
|
213
|
+
...(value.parentSessionId !== undefined ? { parentSessionId: value.parentSessionId as string } : {}),
|
|
214
|
+
...(value.workflowRunId !== undefined ? { workflowRunId: value.workflowRunId as string } : {}),
|
|
215
|
+
...(value.delegationId !== undefined ? { delegationId: value.delegationId as string } : {}),
|
|
216
|
+
...(value.actorKind !== undefined ? { actorKind: value.actorKind as "prism" | "external" } : {}),
|
|
217
|
+
...(value.actorAgent !== undefined ? { actorAgent: value.actorAgent as string } : {}),
|
|
218
|
+
...(ownership ?? {}),
|
|
219
|
+
};
|
|
220
|
+
return Object.keys(out).length > 0 ? out : undefined;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/** Validates wire `SessionParentLink`: accepts only `SessionParentLink` string fields ≤ `MAX_SESSION_LINK_ID_LENGTH`. */
|
|
224
|
+
export function parseSessionParentLink(value: unknown): SessionParentLink | undefined {
|
|
225
|
+
if (value === undefined) return undefined;
|
|
226
|
+
if (!isObject(value)) throw invalid("parent must be an object");
|
|
227
|
+
for (const key of Object.keys(value)) {
|
|
228
|
+
if (!PARENT_LINK_KEY_SET.has(key)) {
|
|
229
|
+
throw invalid(`parent field ${key} is not allowed over the wire`);
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
for (const key of PARENT_LINK_KEYS) {
|
|
233
|
+
const field = value[key];
|
|
234
|
+
if (field !== undefined && (typeof field !== "string" || field.length === 0 || field.length > MAX_SESSION_LINK_ID_LENGTH)) {
|
|
235
|
+
throw invalid(`parent.${key} must be a non-empty string of at most ${MAX_SESSION_LINK_ID_LENGTH} characters`);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return {
|
|
239
|
+
...(value.sessionId !== undefined ? { sessionId: value.sessionId as string } : {}),
|
|
240
|
+
...(value.agentId !== undefined ? { agentId: value.agentId as string } : {}),
|
|
241
|
+
...(value.workflowRunId !== undefined ? { workflowRunId: value.workflowRunId as string } : {}),
|
|
242
|
+
...(value.delegationId !== undefined ? { delegationId: value.delegationId as string } : {}),
|
|
243
|
+
};
|
|
244
|
+
}
|