@agentplat/inference-control 0.3.0-beta.2 → 0.3.0-beta.4
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/README.md +360 -0
- package/dist/anytime-semantic-guarantees.d.ts +216 -0
- package/dist/anytime-semantic-guarantees.d.ts.map +1 -0
- package/dist/anytime-semantic-guarantees.js +817 -0
- package/dist/anytime-semantic-guarantees.js.map +1 -0
- package/dist/assessor-ensemble-contracts.d.ts +145 -0
- package/dist/assessor-ensemble-contracts.d.ts.map +1 -0
- package/dist/assessor-ensemble-contracts.js +29 -0
- package/dist/assessor-ensemble-contracts.js.map +1 -0
- package/dist/assessor-ensemble-runtime.d.ts +55 -0
- package/dist/assessor-ensemble-runtime.d.ts.map +1 -0
- package/dist/assessor-ensemble-runtime.js +308 -0
- package/dist/assessor-ensemble-runtime.js.map +1 -0
- package/dist/assessor-ensemble-validation.d.ts +12 -0
- package/dist/assessor-ensemble-validation.d.ts.map +1 -0
- package/dist/assessor-ensemble-validation.js +156 -0
- package/dist/assessor-ensemble-validation.js.map +1 -0
- package/dist/assessor-ensemble.d.ts +4 -0
- package/dist/assessor-ensemble.d.ts.map +1 -0
- package/dist/assessor-ensemble.js +4 -0
- package/dist/assessor-ensemble.js.map +1 -0
- package/dist/cognitive-adapters.d.ts +92 -0
- package/dist/cognitive-adapters.d.ts.map +1 -0
- package/dist/cognitive-adapters.js +263 -0
- package/dist/cognitive-adapters.js.map +1 -0
- package/dist/context-integrity-analyzers.d.ts +35 -0
- package/dist/context-integrity-analyzers.d.ts.map +1 -0
- package/dist/context-integrity-analyzers.js +387 -0
- package/dist/context-integrity-analyzers.js.map +1 -0
- package/dist/context-integrity-contracts.d.ts +304 -0
- package/dist/context-integrity-contracts.d.ts.map +1 -0
- package/dist/context-integrity-contracts.js +24 -0
- package/dist/context-integrity-contracts.js.map +1 -0
- package/dist/context-integrity-model.d.ts +25 -0
- package/dist/context-integrity-model.d.ts.map +1 -0
- package/dist/context-integrity-model.js +192 -0
- package/dist/context-integrity-model.js.map +1 -0
- package/dist/context-integrity-portable-agent.d.ts +79 -0
- package/dist/context-integrity-portable-agent.d.ts.map +1 -0
- package/dist/context-integrity-portable-agent.js +511 -0
- package/dist/context-integrity-portable-agent.js.map +1 -0
- package/dist/context-integrity-role-alignment.d.ts +28 -0
- package/dist/context-integrity-role-alignment.d.ts.map +1 -0
- package/dist/context-integrity-role-alignment.js +95 -0
- package/dist/context-integrity-role-alignment.js.map +1 -0
- package/dist/context-integrity-runtime.d.ts +95 -0
- package/dist/context-integrity-runtime.d.ts.map +1 -0
- package/dist/context-integrity-runtime.js +1512 -0
- package/dist/context-integrity-runtime.js.map +1 -0
- package/dist/context-integrity.d.ts +5 -0
- package/dist/context-integrity.d.ts.map +1 -0
- package/dist/context-integrity.js +5 -0
- package/dist/context-integrity.js.map +1 -0
- package/dist/governed-role-evolution.d.ts +172 -0
- package/dist/governed-role-evolution.d.ts.map +1 -0
- package/dist/governed-role-evolution.js +613 -0
- package/dist/governed-role-evolution.js.map +1 -0
- package/dist/heterogeneous-agent-composition.d.ts +96 -0
- package/dist/heterogeneous-agent-composition.d.ts.map +1 -0
- package/dist/heterogeneous-agent-composition.js +512 -0
- package/dist/heterogeneous-agent-composition.js.map +1 -0
- package/dist/index.d.ts +21 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -13
- package/dist/index.js.map +1 -1
- package/dist/intervention-adapters.d.ts +29 -0
- package/dist/intervention-adapters.d.ts.map +1 -0
- package/dist/intervention-adapters.js +107 -0
- package/dist/intervention-adapters.js.map +1 -0
- package/dist/intervention-contracts.d.ts +311 -0
- package/dist/intervention-contracts.d.ts.map +1 -0
- package/dist/intervention-contracts.js +28 -0
- package/dist/intervention-contracts.js.map +1 -0
- package/dist/intervention-runtime.d.ts +86 -0
- package/dist/intervention-runtime.d.ts.map +1 -0
- package/dist/intervention-runtime.js +958 -0
- package/dist/intervention-runtime.js.map +1 -0
- package/dist/intervention-validation.d.ts +27 -0
- package/dist/intervention-validation.d.ts.map +1 -0
- package/dist/intervention-validation.js +273 -0
- package/dist/intervention-validation.js.map +1 -0
- package/dist/intervention.d.ts +6 -0
- package/dist/intervention.d.ts.map +1 -0
- package/dist/intervention.js +6 -0
- package/dist/intervention.js.map +1 -0
- package/dist/model.d.ts +18 -0
- package/dist/model.d.ts.map +1 -1
- package/dist/model.js +60 -2
- package/dist/model.js.map +1 -1
- package/dist/operational-cognitive-control.d.ts +208 -0
- package/dist/operational-cognitive-control.d.ts.map +1 -0
- package/dist/operational-cognitive-control.js +590 -0
- package/dist/operational-cognitive-control.js.map +1 -0
- package/dist/portable-agent.d.ts +50 -0
- package/dist/portable-agent.d.ts.map +1 -0
- package/dist/portable-agent.js +243 -0
- package/dist/portable-agent.js.map +1 -0
- package/dist/reference-controllers.d.ts +121 -0
- package/dist/reference-controllers.d.ts.map +1 -0
- package/dist/reference-controllers.js +411 -0
- package/dist/reference-controllers.js.map +1 -0
- package/dist/role-alignment-portable-agent.d.ts +145 -0
- package/dist/role-alignment-portable-agent.d.ts.map +1 -0
- package/dist/role-alignment-portable-agent.js +484 -0
- package/dist/role-alignment-portable-agent.js.map +1 -0
- package/dist/role-alignment.d.ts +226 -0
- package/dist/role-alignment.d.ts.map +1 -0
- package/dist/role-alignment.js +1074 -0
- package/dist/role-alignment.js.map +1 -0
- package/dist/role-realignment-portable-agent.d.ts +163 -0
- package/dist/role-realignment-portable-agent.d.ts.map +1 -0
- package/dist/role-realignment-portable-agent.js +634 -0
- package/dist/role-realignment-portable-agent.js.map +1 -0
- package/dist/role-realignment.d.ts +368 -0
- package/dist/role-realignment.d.ts.map +1 -0
- package/dist/role-realignment.js +1609 -0
- package/dist/role-realignment.js.map +1 -0
- package/dist/semantic-alignment-assessors.d.ts +12 -0
- package/dist/semantic-alignment-assessors.d.ts.map +1 -0
- package/dist/semantic-alignment-assessors.js +55 -0
- package/dist/semantic-alignment-assessors.js.map +1 -0
- package/dist/semantic-alignment-contracts.d.ts +385 -0
- package/dist/semantic-alignment-contracts.d.ts.map +1 -0
- package/dist/semantic-alignment-contracts.js +16 -0
- package/dist/semantic-alignment-contracts.js.map +1 -0
- package/dist/semantic-alignment-memory.d.ts +53 -0
- package/dist/semantic-alignment-memory.d.ts.map +1 -0
- package/dist/semantic-alignment-memory.js +170 -0
- package/dist/semantic-alignment-memory.js.map +1 -0
- package/dist/semantic-alignment-runtime.d.ts +67 -0
- package/dist/semantic-alignment-runtime.d.ts.map +1 -0
- package/dist/semantic-alignment-runtime.js +778 -0
- package/dist/semantic-alignment-runtime.js.map +1 -0
- package/dist/semantic-alignment-validation.d.ts +31 -0
- package/dist/semantic-alignment-validation.d.ts.map +1 -0
- package/dist/semantic-alignment-validation.js +477 -0
- package/dist/semantic-alignment-validation.js.map +1 -0
- package/dist/semantic-alignment.d.ts +8 -0
- package/dist/semantic-alignment.d.ts.map +1 -0
- package/dist/semantic-alignment.js +8 -0
- package/dist/semantic-alignment.js.map +1 -0
- package/dist/semantic-horizon-budget.d.ts +118 -0
- package/dist/semantic-horizon-budget.d.ts.map +1 -0
- package/dist/semantic-horizon-budget.js +536 -0
- package/dist/semantic-horizon-budget.js.map +1 -0
- package/dist/semantic-metric-engine.d.ts +96 -0
- package/dist/semantic-metric-engine.d.ts.map +1 -0
- package/dist/semantic-metric-engine.js +396 -0
- package/dist/semantic-metric-engine.js.map +1 -0
- package/package.json +79 -7
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { PortableAgentAdapterRegistryV1, PortableAgentSessionRuntimeV1, type PortableAgentAdapterManifestV1, type PortableAgentAdapterRequirementsV1, type PortableAgentAdapterV1, type PortableAgentControlPortV1, type PortableAgentControlRequestV1, type PortableAgentStateStoreV1 } from "@agentplat/runtime/adapter";
|
|
2
|
+
import type { InferenceInterventionAdapterDescriptorV1, RepresentationInterventionSidecarPortV1 } from "./intervention-contracts.js";
|
|
3
|
+
import { HeterogeneousInferenceInterventionRuntimeV1 } from "./intervention-runtime.js";
|
|
4
|
+
import type { RoleAlignmentPortableAgentControlV1 } from "./role-alignment-portable-agent.js";
|
|
5
|
+
import type { SemanticActionAuthorizationV1, SemanticActionEffectReceiptV1, SemanticActionEffectSinkV1 } from "./semantic-alignment-contracts.js";
|
|
6
|
+
import { SemanticAlignmentAgilityRuntimeV1 } from "./semantic-alignment-runtime.js";
|
|
7
|
+
export type HeterogeneousAgentRouteKindV1 = "open_weight_representation" | "opaque_api";
|
|
8
|
+
export interface HeterogeneousAgentRouteV1 {
|
|
9
|
+
readonly schemaVersion: 1;
|
|
10
|
+
readonly routeId: string;
|
|
11
|
+
readonly routeKind: HeterogeneousAgentRouteKindV1;
|
|
12
|
+
readonly representationAccess: "read_write" | "opaque";
|
|
13
|
+
readonly interventionAdapter: InferenceInterventionAdapterDescriptorV1;
|
|
14
|
+
readonly portableAdapterBindingDigest: string;
|
|
15
|
+
readonly representationSidecarBindingDigest: string | null;
|
|
16
|
+
readonly routeDigest: string;
|
|
17
|
+
}
|
|
18
|
+
export interface SemanticPortableMaterialBindingV1 {
|
|
19
|
+
readonly materialHandle: string;
|
|
20
|
+
/** Exact content identity that assessors must verify after resolving the handle. */
|
|
21
|
+
readonly materialDigest: string;
|
|
22
|
+
readonly candidateCourseActionDigests: readonly string[];
|
|
23
|
+
readonly selectedCourseActionDigest: string | null;
|
|
24
|
+
readonly modalities: readonly ("text" | "image" | "audio" | "video" | "sensor")[];
|
|
25
|
+
}
|
|
26
|
+
/** Application-owned bridge from portable data to provider-owned semantic material. */
|
|
27
|
+
export interface SemanticPortableMaterialPortV1 {
|
|
28
|
+
bind(request: PortableAgentControlRequestV1): SemanticPortableMaterialBindingV1 | Promise<SemanticPortableMaterialBindingV1>;
|
|
29
|
+
}
|
|
30
|
+
export interface ComposeHeterogeneousPortableAgentV1 {
|
|
31
|
+
readonly composerId: string;
|
|
32
|
+
readonly composerVersion: number;
|
|
33
|
+
readonly implementationId: string;
|
|
34
|
+
readonly route: HeterogeneousAgentRouteV1;
|
|
35
|
+
readonly manifest: PortableAgentAdapterManifestV1;
|
|
36
|
+
readonly adapter: PortableAgentAdapterV1;
|
|
37
|
+
readonly semanticRuntime: SemanticAlignmentAgilityRuntimeV1;
|
|
38
|
+
readonly semanticMaterial: SemanticPortableMaterialPortV1;
|
|
39
|
+
readonly roleAlignmentControl: RoleAlignmentPortableAgentControlV1;
|
|
40
|
+
readonly interventionControl: BoundHeterogeneousInterventionPortableControlV1;
|
|
41
|
+
/** Inclusive logical-time ceiling accepted for requests in this session. */
|
|
42
|
+
readonly maximumSessionLogicalTimeMs: number;
|
|
43
|
+
readonly stateStore?: PortableAgentStateStoreV1;
|
|
44
|
+
readonly maximumSessionSnapshotBytes?: number;
|
|
45
|
+
readonly clock?: () => Date;
|
|
46
|
+
}
|
|
47
|
+
export interface BoundHeterogeneousInterventionPortableControlV1 extends PortableAgentControlPortV1 {
|
|
48
|
+
readonly interventionAdapterDescriptorDigest: string;
|
|
49
|
+
readonly representationSidecarBindingDigest: string | null;
|
|
50
|
+
readonly interventionBindingDigest: string;
|
|
51
|
+
readonly interventionPolicyDigest: string;
|
|
52
|
+
readonly maximumStep: number;
|
|
53
|
+
}
|
|
54
|
+
export interface HeterogeneousPortableAgentCompositionV1 {
|
|
55
|
+
readonly route: HeterogeneousAgentRouteV1;
|
|
56
|
+
readonly maximumSessionLogicalTimeMs: number;
|
|
57
|
+
readonly registry: PortableAgentAdapterRegistryV1;
|
|
58
|
+
readonly control: PortableAgentControlPortV1;
|
|
59
|
+
readonly semanticControl: PortableAgentControlPortV1;
|
|
60
|
+
readonly actionGateway: HeterogeneousPortableActionGatewayV1;
|
|
61
|
+
readonly sessionRuntime: PortableAgentSessionRuntimeV1;
|
|
62
|
+
readonly requiredSessionCapabilities: PortableAgentAdapterRequirementsV1;
|
|
63
|
+
}
|
|
64
|
+
/** Final provider-neutral effect boundary for an allowed portable proposal. */
|
|
65
|
+
export interface HeterogeneousPortableActionGatewayV1 {
|
|
66
|
+
dispatch(input: {
|
|
67
|
+
readonly request: PortableAgentControlRequestV1;
|
|
68
|
+
/** Must originate from a trusted monotonic logical-time source. */
|
|
69
|
+
readonly currentLogicalTimeMs: number;
|
|
70
|
+
}, sink: SemanticActionEffectSinkV1): Promise<{
|
|
71
|
+
readonly authorization: SemanticActionAuthorizationV1;
|
|
72
|
+
readonly effectReceipt: SemanticActionEffectReceiptV1;
|
|
73
|
+
}>;
|
|
74
|
+
}
|
|
75
|
+
export declare function createHeterogeneousAgentRouteV1(input: Omit<HeterogeneousAgentRouteV1, "routeDigest">): HeterogeneousAgentRouteV1;
|
|
76
|
+
export declare function composeHeterogeneousPortableAgentV1(options: ComposeHeterogeneousPortableAgentV1): HeterogeneousPortableAgentCompositionV1;
|
|
77
|
+
export declare function createSemanticPortableAgentControlV1(input: {
|
|
78
|
+
readonly controlId: string;
|
|
79
|
+
readonly controlVersion: number;
|
|
80
|
+
readonly implementationId: string;
|
|
81
|
+
readonly runtime: SemanticAlignmentAgilityRuntimeV1;
|
|
82
|
+
readonly material: SemanticPortableMaterialPortV1;
|
|
83
|
+
readonly maximumLogicalTimeMs: number;
|
|
84
|
+
}): PortableAgentControlPortV1;
|
|
85
|
+
export declare function createHeterogeneousPortableActionGatewayV1(input: {
|
|
86
|
+
readonly runtime: SemanticAlignmentAgilityRuntimeV1;
|
|
87
|
+
readonly sessions: Pick<PortableAgentSessionRuntimeV1, "getSession">;
|
|
88
|
+
}): HeterogeneousPortableActionGatewayV1;
|
|
89
|
+
export declare function bindHeterogeneousInterventionPortableControlV1(input: {
|
|
90
|
+
readonly runtime: HeterogeneousInferenceInterventionRuntimeV1;
|
|
91
|
+
}): BoundHeterogeneousInterventionPortableControlV1;
|
|
92
|
+
export declare function representationSidecarBindingDigestV1(sidecar: RepresentationInterventionSidecarPortV1 | null): string | null;
|
|
93
|
+
export declare function portableAdapterBindingDigestV1(manifest: PortableAgentAdapterManifestV1): string;
|
|
94
|
+
export declare function portableSemanticRequestIdV1(request: PortableAgentControlRequestV1): string;
|
|
95
|
+
export declare function portableActionPayloadV1(request: PortableAgentControlRequestV1): string;
|
|
96
|
+
//# sourceMappingURL=heterogeneous-agent-composition.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heterogeneous-agent-composition.d.ts","sourceRoot":"","sources":["../src/heterogeneous-agent-composition.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,512 @@
|
|
|
1
|
+
import { PortableAgentAdapterRegistryV1, PortableAgentSessionRuntimeV1, } from "@agentplat/runtime/adapter";
|
|
2
|
+
import { HeterogeneousInferenceInterventionRuntimeV1 } from "./intervention-runtime.js";
|
|
3
|
+
import { assertInferenceInterventionAdapterDescriptorV1 } from "./intervention-validation.js";
|
|
4
|
+
import { canonicalizeControlJsonV1 } from "./canonical.js";
|
|
5
|
+
import { createCompositePortableAgentControlV1 } from "./portable-agent.js";
|
|
6
|
+
import { SemanticAlignmentAgilityRuntimeV1 } from "./semantic-alignment-runtime.js";
|
|
7
|
+
import { createSemanticControlRequestV1, digestSemanticControlV1, digestSemanticOperationPayloadV1, } from "./semantic-alignment-validation.js";
|
|
8
|
+
import { assertDigest, assertIdentifier, assertSafeInteger, deepFreeze, } from "./validation.js";
|
|
9
|
+
const boundInterventionControls = new WeakSet();
|
|
10
|
+
const PORTABLE_CONTROL_SEQUENCE_STRIDE = 16_384;
|
|
11
|
+
const PORTABLE_CONTROL_MAXIMUM_ITEM_INDEX = 4_095;
|
|
12
|
+
const PORTABLE_CONTROL_MAXIMUM_ORDINAL = 12_289;
|
|
13
|
+
export function createHeterogeneousAgentRouteV1(input) {
|
|
14
|
+
if (input.schemaVersion !== 1)
|
|
15
|
+
throw new TypeError("heterogeneous_route_schema_invalid");
|
|
16
|
+
assertIdentifier(input.routeId, "routeId");
|
|
17
|
+
if (!["open_weight_representation", "opaque_api"].includes(input.routeKind))
|
|
18
|
+
throw new TypeError("heterogeneous_route_kind_invalid");
|
|
19
|
+
assertInferenceInterventionAdapterDescriptorV1(input.interventionAdapter);
|
|
20
|
+
assertDigest(input.portableAdapterBindingDigest, "portableAdapterBindingDigest");
|
|
21
|
+
const capabilities = new Set(input.interventionAdapter.capabilities);
|
|
22
|
+
for (const required of [
|
|
23
|
+
"pre_input_filter",
|
|
24
|
+
"output_gate",
|
|
25
|
+
"action_gate",
|
|
26
|
+
])
|
|
27
|
+
if (!capabilities.has(required))
|
|
28
|
+
throw new TypeError(`heterogeneous_route_capability_missing:${required}`);
|
|
29
|
+
if (input.routeKind === "open_weight_representation") {
|
|
30
|
+
if (input.interventionAdapter.agentClass === "opaque_api_model")
|
|
31
|
+
throw new TypeError("open_weight_route_agent_class_invalid");
|
|
32
|
+
if (input.representationAccess !== "read_write" ||
|
|
33
|
+
!capabilities.has("representation_intervention"))
|
|
34
|
+
throw new TypeError("open_weight_route_requires_representation_intervention");
|
|
35
|
+
if (input.representationSidecarBindingDigest === null)
|
|
36
|
+
throw new TypeError("open_weight_route_requires_sidecar_binding");
|
|
37
|
+
assertDigest(input.representationSidecarBindingDigest, "representationSidecarBindingDigest");
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
if (input.representationAccess !== "opaque" ||
|
|
41
|
+
capabilities.has("representation_intervention"))
|
|
42
|
+
throw new TypeError("opaque_route_must_not_claim_representation_access");
|
|
43
|
+
if (input.interventionAdapter.agentClass !== "opaque_api_model")
|
|
44
|
+
throw new TypeError("opaque_route_agent_class_invalid");
|
|
45
|
+
if (input.representationSidecarBindingDigest !== null)
|
|
46
|
+
throw new TypeError("opaque_route_must_not_bind_representation_sidecar");
|
|
47
|
+
}
|
|
48
|
+
const body = deepFreeze({ ...input });
|
|
49
|
+
return deepFreeze({
|
|
50
|
+
...body,
|
|
51
|
+
routeDigest: digestSemanticControlV1("route", body),
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
export function composeHeterogeneousPortableAgentV1(options) {
|
|
55
|
+
assertIdentifier(options.composerId, "composerId");
|
|
56
|
+
assertSafeInteger(options.composerVersion, "composerVersion", 1);
|
|
57
|
+
assertIdentifier(options.implementationId, "implementationId");
|
|
58
|
+
const expectedRoute = createHeterogeneousAgentRouteV1(stripRouteDigest(options.route));
|
|
59
|
+
if (expectedRoute.routeDigest !== options.route.routeDigest)
|
|
60
|
+
throw new TypeError("heterogeneous_route_digest_invalid");
|
|
61
|
+
if (options.route.portableAdapterBindingDigest !==
|
|
62
|
+
portableAdapterBindingDigestV1(options.manifest))
|
|
63
|
+
throw new TypeError("heterogeneous_portable_adapter_binding_mismatch");
|
|
64
|
+
if (!(options.semanticRuntime instanceof SemanticAlignmentAgilityRuntimeV1))
|
|
65
|
+
throw new TypeError("semantic_runtime_required");
|
|
66
|
+
if (!options.semanticRuntime.options.actionAuthorization)
|
|
67
|
+
throw new TypeError("semantic_action_authorization_boundary_required");
|
|
68
|
+
assertSafeInteger(options.maximumSessionLogicalTimeMs, "maximumSessionLogicalTimeMs", 0);
|
|
69
|
+
if (!options.semanticMaterial ||
|
|
70
|
+
typeof options.semanticMaterial.bind !== "function")
|
|
71
|
+
throw new TypeError("semantic_material_port_required");
|
|
72
|
+
for (const [name, control] of [
|
|
73
|
+
["role_alignment", options.roleAlignmentControl],
|
|
74
|
+
["intervention", options.interventionControl],
|
|
75
|
+
]) {
|
|
76
|
+
if (!control || typeof control.evaluate !== "function")
|
|
77
|
+
throw new TypeError(`${name}_portable_control_required`);
|
|
78
|
+
}
|
|
79
|
+
const interventionBinding = options.interventionControl;
|
|
80
|
+
if (!boundInterventionControls.has(interventionBinding) ||
|
|
81
|
+
interventionBinding.interventionAdapterDescriptorDigest !==
|
|
82
|
+
options.route.interventionAdapter.descriptorDigest ||
|
|
83
|
+
interventionBinding.representationSidecarBindingDigest !==
|
|
84
|
+
options.route.representationSidecarBindingDigest)
|
|
85
|
+
throw new TypeError("portable_intervention_control_binding_mismatch");
|
|
86
|
+
if (!options.roleAlignmentControl.binding)
|
|
87
|
+
throw new TypeError("portable_role_alignment_binding_missing");
|
|
88
|
+
assertDigest(options.roleAlignmentControl.binding.policyDigest, "roleAlignment.policyDigest");
|
|
89
|
+
assertDigest(options.roleAlignmentControl.binding.assessorBindingDigest, "roleAlignment.assessorBindingDigest");
|
|
90
|
+
const requiredPoints = ["post_output", "pre_action", "pre_step"];
|
|
91
|
+
if (requiredPoints.some((point) => !options.manifest.controlPoints.includes(point)))
|
|
92
|
+
throw new TypeError("portable_adapter_missing_mandatory_control_point");
|
|
93
|
+
if (options.route.routeKind === "opaque_api" &&
|
|
94
|
+
options.manifest.agentKinds.some((kind) => kind === "symbolic"))
|
|
95
|
+
throw new TypeError("opaque_api_route_agent_kind_invalid");
|
|
96
|
+
const maximumControlSequence = (options.manifest.maximumStepsPerSession - 1) *
|
|
97
|
+
PORTABLE_CONTROL_SEQUENCE_STRIDE +
|
|
98
|
+
PORTABLE_CONTROL_MAXIMUM_ORDINAL;
|
|
99
|
+
if (!Number.isSafeInteger(maximumControlSequence))
|
|
100
|
+
throw new RangeError("heterogeneous_control_sequence_capacity_exhausted");
|
|
101
|
+
if (maximumControlSequence >
|
|
102
|
+
options.semanticRuntime.options.policy.limits.maximumSequence)
|
|
103
|
+
throw new RangeError("semantic_policy_sequence_capacity_insufficient");
|
|
104
|
+
if (maximumControlSequence > interventionBinding.maximumStep)
|
|
105
|
+
throw new RangeError("intervention_policy_step_capacity_insufficient");
|
|
106
|
+
if (options.maximumSessionLogicalTimeMs >
|
|
107
|
+
options.semanticRuntime.options.policy.limits.maximumLogicalTimeMs)
|
|
108
|
+
throw new RangeError("semantic_policy_logical_time_capacity_insufficient");
|
|
109
|
+
const semanticControl = createSemanticPortableAgentControlV1({
|
|
110
|
+
controlId: `${options.composerId}.semantic`,
|
|
111
|
+
controlVersion: options.composerVersion,
|
|
112
|
+
implementationId: options.implementationId,
|
|
113
|
+
runtime: options.semanticRuntime,
|
|
114
|
+
material: options.semanticMaterial,
|
|
115
|
+
maximumLogicalTimeMs: options.maximumSessionLogicalTimeMs,
|
|
116
|
+
});
|
|
117
|
+
const prerequisiteControl = createCompositePortableAgentControlV1({
|
|
118
|
+
controlId: `${options.composerId}.prerequisites`,
|
|
119
|
+
controlVersion: options.composerVersion,
|
|
120
|
+
implementationId: options.implementationId,
|
|
121
|
+
controls: [options.roleAlignmentControl, options.interventionControl],
|
|
122
|
+
});
|
|
123
|
+
const control = Object.freeze({
|
|
124
|
+
controlId: options.composerId,
|
|
125
|
+
controlVersion: options.composerVersion,
|
|
126
|
+
implementationId: options.implementationId,
|
|
127
|
+
async evaluate(portable) {
|
|
128
|
+
try {
|
|
129
|
+
const prerequisite = await prerequisiteControl.evaluate(portable);
|
|
130
|
+
if (prerequisite.disposition !== "allow")
|
|
131
|
+
return prerequisite;
|
|
132
|
+
if (portable.checkpoint === "pre_action") {
|
|
133
|
+
// Build once after prerequisites so volatile material cannot change
|
|
134
|
+
// between semantic evaluation and receipt issuance.
|
|
135
|
+
const evaluation = await buildSemanticPortableEvaluationV1({
|
|
136
|
+
runtime: options.semanticRuntime,
|
|
137
|
+
material: options.semanticMaterial,
|
|
138
|
+
maximumLogicalTimeMs: options.maximumSessionLogicalTimeMs,
|
|
139
|
+
}, portable);
|
|
140
|
+
const authorized = await options.semanticRuntime.authorizeAction(evaluation);
|
|
141
|
+
if (!authorized.authorization)
|
|
142
|
+
return portableSemanticDecisionV1(authorized.decision);
|
|
143
|
+
return allow("semantic_control_allowed");
|
|
144
|
+
}
|
|
145
|
+
const semantic = await semanticControl.evaluate(portable);
|
|
146
|
+
return semantic;
|
|
147
|
+
}
|
|
148
|
+
catch {
|
|
149
|
+
return deny("heterogeneous_composite_control_unavailable");
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
const registry = new PortableAgentAdapterRegistryV1().register({
|
|
154
|
+
manifest: options.manifest,
|
|
155
|
+
adapter: options.adapter,
|
|
156
|
+
});
|
|
157
|
+
const requiredSessionCapabilities = deepFreeze({
|
|
158
|
+
agentKinds: [...options.manifest.agentKinds],
|
|
159
|
+
inputModalities: [...options.manifest.inputModalities],
|
|
160
|
+
outputModalities: [...options.manifest.outputModalities],
|
|
161
|
+
interactionMode: options.manifest.interactionModes[0],
|
|
162
|
+
controlPoints: [...requiredPoints],
|
|
163
|
+
requireCancellation: options.manifest.supportsCancellation,
|
|
164
|
+
requireCheckpoint: false,
|
|
165
|
+
requireRestore: false,
|
|
166
|
+
});
|
|
167
|
+
const negotiation = registry.negotiate(options.manifest, requiredSessionCapabilities);
|
|
168
|
+
if (!negotiation.accepted)
|
|
169
|
+
throw new TypeError("portable_adapter_control_route_negotiation_failed");
|
|
170
|
+
const sessionRuntime = new PortableAgentSessionRuntimeV1({
|
|
171
|
+
registry,
|
|
172
|
+
control,
|
|
173
|
+
...(options.stateStore ? { stateStore: options.stateStore } : {}),
|
|
174
|
+
...(options.maximumSessionSnapshotBytes
|
|
175
|
+
? { maximumSessionSnapshotBytes: options.maximumSessionSnapshotBytes }
|
|
176
|
+
: {}),
|
|
177
|
+
...(options.clock ? { clock: options.clock } : {}),
|
|
178
|
+
});
|
|
179
|
+
const actionGateway = createHeterogeneousPortableActionGatewayV1({
|
|
180
|
+
runtime: options.semanticRuntime,
|
|
181
|
+
sessions: sessionRuntime,
|
|
182
|
+
});
|
|
183
|
+
return Object.freeze({
|
|
184
|
+
route: expectedRoute,
|
|
185
|
+
maximumSessionLogicalTimeMs: options.maximumSessionLogicalTimeMs,
|
|
186
|
+
registry,
|
|
187
|
+
control,
|
|
188
|
+
semanticControl,
|
|
189
|
+
actionGateway,
|
|
190
|
+
sessionRuntime,
|
|
191
|
+
requiredSessionCapabilities,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
export function createSemanticPortableAgentControlV1(input) {
|
|
195
|
+
assertIdentifier(input.controlId, "controlId");
|
|
196
|
+
assertSafeInteger(input.controlVersion, "controlVersion", 1);
|
|
197
|
+
assertIdentifier(input.implementationId, "implementationId");
|
|
198
|
+
if (!input.runtime || typeof input.runtime.evaluate !== "function")
|
|
199
|
+
throw new TypeError("semantic_runtime_required");
|
|
200
|
+
if (!input.material || typeof input.material.bind !== "function")
|
|
201
|
+
throw new TypeError("semantic_material_port_required");
|
|
202
|
+
assertSafeInteger(input.maximumLogicalTimeMs, "maximumLogicalTimeMs", 0);
|
|
203
|
+
if (input.maximumLogicalTimeMs >
|
|
204
|
+
input.runtime.options.policy.limits.maximumLogicalTimeMs)
|
|
205
|
+
throw new RangeError("semantic_control_logical_time_capacity_insufficient");
|
|
206
|
+
return Object.freeze({
|
|
207
|
+
controlId: input.controlId,
|
|
208
|
+
controlVersion: input.controlVersion,
|
|
209
|
+
implementationId: input.implementationId,
|
|
210
|
+
async evaluate(portable) {
|
|
211
|
+
try {
|
|
212
|
+
const evaluation = await buildSemanticPortableEvaluationV1(input, portable);
|
|
213
|
+
const decision = await input.runtime.evaluate(evaluation);
|
|
214
|
+
if (decision.disposition === "allow")
|
|
215
|
+
return allow("semantic_control_allowed");
|
|
216
|
+
// Portable controls have no steering payload channel. Stopping is the
|
|
217
|
+
// only non-bypass interpretation until the application supplies a new step.
|
|
218
|
+
if (decision.disposition === "steer")
|
|
219
|
+
return abstain("semantic_steering_required");
|
|
220
|
+
if (decision.disposition === "abstain")
|
|
221
|
+
return abstain("semantic_control_abstained");
|
|
222
|
+
return deny("semantic_control_blocked");
|
|
223
|
+
}
|
|
224
|
+
catch {
|
|
225
|
+
return deny("semantic_control_unavailable");
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
}
|
|
230
|
+
async function buildSemanticPortableEvaluationV1(input, portable) {
|
|
231
|
+
const runtime = input.runtime;
|
|
232
|
+
const binding = runtime.options.binding;
|
|
233
|
+
assertPortableSemanticBindingV1(runtime, portable);
|
|
234
|
+
assertSafeInteger(portable.stepSequence, "stepSequence", 1);
|
|
235
|
+
if (portable.stepSequence > portable.manifest.maximumStepsPerSession)
|
|
236
|
+
throw new RangeError("portable_step_sequence_exceeded");
|
|
237
|
+
assertSafeInteger(portable.request.logicalTimeMs, "request.logicalTimeMs", 0);
|
|
238
|
+
if (portable.request.logicalTimeMs > input.maximumLogicalTimeMs)
|
|
239
|
+
throw new RangeError("portable_logical_time_exceeded");
|
|
240
|
+
const itemIndex = portable.checkpointItemIndex ?? 0;
|
|
241
|
+
assertSafeInteger(itemIndex, "checkpointItemIndex", 0);
|
|
242
|
+
if (portable.checkpoint === "pre_step" && itemIndex !== 0)
|
|
243
|
+
throw new RangeError("portable_pre_step_item_index_invalid");
|
|
244
|
+
if (itemIndex > PORTABLE_CONTROL_MAXIMUM_ITEM_INDEX)
|
|
245
|
+
throw new RangeError("portable_checkpoint_item_index_exceeded");
|
|
246
|
+
const ordinal = checkpointOrdinal(portable.checkpoint, itemIndex);
|
|
247
|
+
const sequence = (portable.stepSequence - 1) * PORTABLE_CONTROL_SEQUENCE_STRIDE + ordinal;
|
|
248
|
+
const logicalTimeMs = portable.request.logicalTimeMs;
|
|
249
|
+
if (!Number.isSafeInteger(sequence))
|
|
250
|
+
throw new RangeError("portable_semantic_clock_exhausted");
|
|
251
|
+
const material = await input.material.bind(portable);
|
|
252
|
+
assertDigest(material.materialDigest, "material.materialDigest");
|
|
253
|
+
const state = await runtime.getState();
|
|
254
|
+
const target = targetFor(portable);
|
|
255
|
+
const context = {
|
|
256
|
+
observations: portable.request.observations.map((item) => ({
|
|
257
|
+
observationId: item.observationId,
|
|
258
|
+
sourceId: item.sourceId,
|
|
259
|
+
sourceZone: item.sourceZone,
|
|
260
|
+
contentDigest: item.contentReference?.contentDigest ??
|
|
261
|
+
digestSemanticControlV1("request", item.content),
|
|
262
|
+
})),
|
|
263
|
+
roleBindingId: portable.role.roleBindingId,
|
|
264
|
+
roleRevision: portable.role.roleRevision,
|
|
265
|
+
checkpointItemIndex: itemIndex,
|
|
266
|
+
};
|
|
267
|
+
const interventionPayload = portable.checkpoint === "pre_action" && portable.actionProposal
|
|
268
|
+
? portableActionPayloadV1(portable)
|
|
269
|
+
: undefined;
|
|
270
|
+
const request = createSemanticControlRequestV1({
|
|
271
|
+
schemaVersion: 1,
|
|
272
|
+
requestId: portableSemanticRequestIdV1(portable),
|
|
273
|
+
checkpoint: portable.checkpoint,
|
|
274
|
+
bindingDigest: binding.bindingDigest,
|
|
275
|
+
missionAnchorDigest: binding.missionAnchorDigest,
|
|
276
|
+
roleAnchorDigest: binding.roleAnchorDigest,
|
|
277
|
+
authorityDigest: binding.authorityDigest,
|
|
278
|
+
sequence,
|
|
279
|
+
step: portable.stepSequence,
|
|
280
|
+
logicalTimeMs,
|
|
281
|
+
targetDigest: digestSemanticControlV1("request", target),
|
|
282
|
+
contextDigest: digestSemanticControlV1("request", context),
|
|
283
|
+
selectedCourseActionDigest: material.selectedCourseActionDigest,
|
|
284
|
+
candidateCourseActionDigests: material.candidateCourseActionDigests,
|
|
285
|
+
priorCourseActionDigests: state?.courseActionHistory ?? [],
|
|
286
|
+
modalities: material.modalities,
|
|
287
|
+
materialDigest: material.materialDigest,
|
|
288
|
+
actionPayloadDigest: interventionPayload === undefined
|
|
289
|
+
? null
|
|
290
|
+
: digestSemanticOperationPayloadV1(interventionPayload, runtime.options.policy.limits.maximumActionPayloadBytes),
|
|
291
|
+
materialHandle: material.materialHandle,
|
|
292
|
+
});
|
|
293
|
+
return {
|
|
294
|
+
request,
|
|
295
|
+
...(interventionPayload === undefined ? {} : { interventionPayload }),
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
export function createHeterogeneousPortableActionGatewayV1(input) {
|
|
299
|
+
if (!(input.runtime instanceof SemanticAlignmentAgilityRuntimeV1))
|
|
300
|
+
throw new TypeError("semantic_runtime_required");
|
|
301
|
+
if (!input.runtime.options.actionAuthorization)
|
|
302
|
+
throw new TypeError("semantic_action_authorization_boundary_required");
|
|
303
|
+
if (!input.sessions || typeof input.sessions.getSession !== "function")
|
|
304
|
+
throw new TypeError("portable_session_lookup_required");
|
|
305
|
+
return Object.freeze({
|
|
306
|
+
async dispatch(value, sink) {
|
|
307
|
+
const portable = value.request;
|
|
308
|
+
if (portable.checkpoint !== "pre_action" || !portable.actionProposal)
|
|
309
|
+
throw new TypeError("heterogeneous_action_gateway_requires_proposal");
|
|
310
|
+
assertSafeInteger(value.currentLogicalTimeMs, "currentLogicalTimeMs", 0);
|
|
311
|
+
assertPortableSemanticBindingV1(input.runtime, portable);
|
|
312
|
+
const session = await input.sessions.getSession(portable.sessionId);
|
|
313
|
+
const itemIndex = portable.checkpointItemIndex ?? 0;
|
|
314
|
+
assertSafeInteger(itemIndex, "checkpointItemIndex", 0);
|
|
315
|
+
if (itemIndex > PORTABLE_CONTROL_MAXIMUM_ITEM_INDEX)
|
|
316
|
+
throw new RangeError("portable_checkpoint_item_index_exceeded");
|
|
317
|
+
const record = session?.stepRecords.find((item) => item.stepId === portable.request.stepId &&
|
|
318
|
+
item.stepSequence === portable.stepSequence);
|
|
319
|
+
const retainedProposal = record?.result.actionProposals[itemIndex];
|
|
320
|
+
if (!session ||
|
|
321
|
+
session.status !== "active" ||
|
|
322
|
+
session.tenantId !== portable.tenantId ||
|
|
323
|
+
session.agentId !== portable.agentId ||
|
|
324
|
+
session.objectiveId !== portable.role.objectiveId ||
|
|
325
|
+
session.role.roleBindingId !== portable.role.roleBindingId ||
|
|
326
|
+
session.role.roleRevision !== portable.role.roleRevision ||
|
|
327
|
+
!record ||
|
|
328
|
+
record.status !== "completed" ||
|
|
329
|
+
record.result.status !== "completed" ||
|
|
330
|
+
record.roleBindingId !== portable.role.roleBindingId ||
|
|
331
|
+
record.roleRevision !== portable.role.roleRevision ||
|
|
332
|
+
!retainedProposal ||
|
|
333
|
+
digestSemanticControlV1("request", record.request) !==
|
|
334
|
+
digestSemanticControlV1("request", portable.request) ||
|
|
335
|
+
digestSemanticControlV1("request", retainedProposal) !==
|
|
336
|
+
digestSemanticControlV1("request", portable.actionProposal))
|
|
337
|
+
throw new TypeError("heterogeneous_action_session_commit_unverified");
|
|
338
|
+
const targetDigest = digestSemanticControlV1("request", targetFor(portable));
|
|
339
|
+
const payloadDigest = digestSemanticOperationPayloadV1(portableActionPayloadV1(portable), input.runtime.options.policy.limits.maximumActionPayloadBytes);
|
|
340
|
+
return input.runtime.dispatchAuthorizedAction({
|
|
341
|
+
authorizationId: portableSemanticRequestIdV1(portable),
|
|
342
|
+
expectedTargetDigest: targetDigest,
|
|
343
|
+
expectedActionPayloadDigest: payloadDigest,
|
|
344
|
+
currentLogicalTimeMs: value.currentLogicalTimeMs,
|
|
345
|
+
}, sink);
|
|
346
|
+
},
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
export function bindHeterogeneousInterventionPortableControlV1(input) {
|
|
350
|
+
if (!(input.runtime instanceof HeterogeneousInferenceInterventionRuntimeV1))
|
|
351
|
+
throw new TypeError("intervention_runtime_required");
|
|
352
|
+
const runtime = input.runtime;
|
|
353
|
+
const descriptor = runtime.options.adapter.descriptor;
|
|
354
|
+
assertInferenceInterventionAdapterDescriptorV1(descriptor);
|
|
355
|
+
const sidecarDigest = representationSidecarBindingDigestV1(runtime.options.sidecar ?? null);
|
|
356
|
+
const control = Object.freeze({
|
|
357
|
+
controlId: `heterogeneous-intervention.${descriptor.adapterId}`,
|
|
358
|
+
controlVersion: descriptor.adapterVersion,
|
|
359
|
+
implementationId: `heterogeneous-intervention.${descriptor.adapterId}.v${descriptor.adapterVersion}`,
|
|
360
|
+
interventionAdapterDescriptorDigest: descriptor.descriptorDigest,
|
|
361
|
+
representationSidecarBindingDigest: sidecarDigest,
|
|
362
|
+
interventionBindingDigest: runtime.options.binding.bindingDigest,
|
|
363
|
+
interventionPolicyDigest: runtime.options.policy.policyDigest,
|
|
364
|
+
maximumStep: runtime.options.policy.maximumStep,
|
|
365
|
+
async evaluate(request) {
|
|
366
|
+
try {
|
|
367
|
+
const binding = runtime.options.binding;
|
|
368
|
+
if (request.sessionId !== binding.sessionId ||
|
|
369
|
+
request.agentId !== binding.agentId ||
|
|
370
|
+
request.role.objectiveId !== binding.missionId ||
|
|
371
|
+
(request.role.roleBindingId !== binding.roleId &&
|
|
372
|
+
request.role.roleKey !== binding.roleId))
|
|
373
|
+
return deny("intervention_portable_binding_mismatch");
|
|
374
|
+
assertSafeInteger(request.stepSequence, "stepSequence", 1);
|
|
375
|
+
if (request.stepSequence > request.manifest.maximumStepsPerSession)
|
|
376
|
+
return deny("intervention_step_sequence_exceeded");
|
|
377
|
+
const itemIndex = request.checkpointItemIndex ?? 0;
|
|
378
|
+
assertSafeInteger(itemIndex, "checkpointItemIndex", 0);
|
|
379
|
+
if (request.checkpoint === "pre_step" && itemIndex !== 0)
|
|
380
|
+
return deny("intervention_pre_step_item_index_invalid");
|
|
381
|
+
if (itemIndex > PORTABLE_CONTROL_MAXIMUM_ITEM_INDEX)
|
|
382
|
+
return deny("intervention_checkpoint_item_index_exceeded");
|
|
383
|
+
const ordinal = checkpointOrdinal(request.checkpoint, itemIndex);
|
|
384
|
+
const step = (request.stepSequence - 1) * PORTABLE_CONTROL_SEQUENCE_STRIDE +
|
|
385
|
+
ordinal;
|
|
386
|
+
const logicalTimeMs = request.request.logicalTimeMs;
|
|
387
|
+
if (!Number.isSafeInteger(step) || !Number.isSafeInteger(logicalTimeMs))
|
|
388
|
+
return deny("intervention_portable_clock_exhausted");
|
|
389
|
+
const payload = canonicalizeControlJsonV1(targetFor(request));
|
|
390
|
+
const result = request.checkpoint === "pre_action"
|
|
391
|
+
? await runtime.gateOperation({
|
|
392
|
+
operationId: `portable-intervention-${request.sessionId}-${request.request.stepId}-${request.checkpoint}-${itemIndex}`,
|
|
393
|
+
kind: "action",
|
|
394
|
+
step,
|
|
395
|
+
logicalTimeMs,
|
|
396
|
+
payload,
|
|
397
|
+
})
|
|
398
|
+
: await runtime.gateCheckpoint({
|
|
399
|
+
operationId: `portable-intervention-${request.sessionId}-${request.request.stepId}-${request.checkpoint}-${itemIndex}`,
|
|
400
|
+
kind: request.checkpoint === "pre_step" ? "input" : "output",
|
|
401
|
+
step,
|
|
402
|
+
logicalTimeMs,
|
|
403
|
+
payload,
|
|
404
|
+
});
|
|
405
|
+
return result.allowed
|
|
406
|
+
? allow("intervention_runtime_allowed")
|
|
407
|
+
: deny("intervention_runtime_blocked");
|
|
408
|
+
}
|
|
409
|
+
catch {
|
|
410
|
+
return deny("intervention_runtime_unavailable");
|
|
411
|
+
}
|
|
412
|
+
},
|
|
413
|
+
});
|
|
414
|
+
boundInterventionControls.add(control);
|
|
415
|
+
return control;
|
|
416
|
+
}
|
|
417
|
+
export function representationSidecarBindingDigestV1(sidecar) {
|
|
418
|
+
if (!sidecar)
|
|
419
|
+
return null;
|
|
420
|
+
assertIdentifier(sidecar.sidecarId, "sidecarId");
|
|
421
|
+
assertSafeInteger(sidecar.sidecarVersion, "sidecarVersion", 1);
|
|
422
|
+
assertDigest(sidecar.sidecarImplementationDigest, "sidecarImplementationDigest");
|
|
423
|
+
return digestSemanticControlV1("route", {
|
|
424
|
+
kind: "representation-sidecar-binding",
|
|
425
|
+
sidecarId: sidecar.sidecarId,
|
|
426
|
+
sidecarVersion: sidecar.sidecarVersion,
|
|
427
|
+
sidecarImplementationDigest: sidecar.sidecarImplementationDigest,
|
|
428
|
+
});
|
|
429
|
+
}
|
|
430
|
+
export function portableAdapterBindingDigestV1(manifest) {
|
|
431
|
+
return digestSemanticControlV1("route", {
|
|
432
|
+
kind: "portable-adapter-binding",
|
|
433
|
+
manifest: manifest,
|
|
434
|
+
});
|
|
435
|
+
}
|
|
436
|
+
function targetFor(request) {
|
|
437
|
+
if (request.checkpoint === "post_output")
|
|
438
|
+
return request.output;
|
|
439
|
+
if (request.checkpoint === "pre_action")
|
|
440
|
+
return request.actionProposal;
|
|
441
|
+
return {
|
|
442
|
+
role: request.role,
|
|
443
|
+
request: request.request,
|
|
444
|
+
manifest: {
|
|
445
|
+
adapterId: request.manifest.adapterId,
|
|
446
|
+
adapterVersion: request.manifest.adapterVersion,
|
|
447
|
+
implementationId: request.manifest.implementationId,
|
|
448
|
+
},
|
|
449
|
+
};
|
|
450
|
+
}
|
|
451
|
+
export function portableSemanticRequestIdV1(request) {
|
|
452
|
+
const itemIndex = request.checkpointItemIndex ?? 0;
|
|
453
|
+
assertSafeInteger(itemIndex, "checkpointItemIndex", 0);
|
|
454
|
+
const identityDigest = digestSemanticControlV1("route", {
|
|
455
|
+
kind: "portable-semantic-request",
|
|
456
|
+
tenantId: request.tenantId,
|
|
457
|
+
sessionId: request.sessionId,
|
|
458
|
+
agentId: request.agentId,
|
|
459
|
+
roleBindingId: request.role.roleBindingId,
|
|
460
|
+
roleRevision: request.role.roleRevision,
|
|
461
|
+
stepId: request.request.stepId,
|
|
462
|
+
stepSequence: request.stepSequence,
|
|
463
|
+
checkpoint: request.checkpoint,
|
|
464
|
+
checkpointItemIndex: itemIndex,
|
|
465
|
+
});
|
|
466
|
+
return `portable-semantic:${identityDigest}`;
|
|
467
|
+
}
|
|
468
|
+
export function portableActionPayloadV1(request) {
|
|
469
|
+
if (request.checkpoint !== "pre_action" || !request.actionProposal)
|
|
470
|
+
throw new TypeError("portable_action_payload_requires_proposal");
|
|
471
|
+
// Canonical full-proposal bytes bind actionId, class, input, risk and metadata.
|
|
472
|
+
return canonicalizeControlJsonV1(request.actionProposal);
|
|
473
|
+
}
|
|
474
|
+
function assertPortableSemanticBindingV1(runtime, portable) {
|
|
475
|
+
const binding = runtime.options.binding;
|
|
476
|
+
if (portable.sessionId !== binding.sessionId ||
|
|
477
|
+
portable.agentId !== binding.agentId ||
|
|
478
|
+
portable.role.objectiveId !== binding.missionId ||
|
|
479
|
+
(portable.role.roleBindingId !== binding.roleId &&
|
|
480
|
+
portable.role.roleKey !== binding.roleId))
|
|
481
|
+
throw new TypeError("semantic_portable_binding_mismatch");
|
|
482
|
+
}
|
|
483
|
+
function checkpointOrdinal(checkpoint, itemIndex) {
|
|
484
|
+
if (checkpoint === "pre_step")
|
|
485
|
+
return 1;
|
|
486
|
+
if (checkpoint === "post_output")
|
|
487
|
+
return 2 + itemIndex;
|
|
488
|
+
return 8_194 + itemIndex;
|
|
489
|
+
}
|
|
490
|
+
function stripRouteDigest(route) {
|
|
491
|
+
const { routeDigest: _ignored, ...body } = route;
|
|
492
|
+
return body;
|
|
493
|
+
}
|
|
494
|
+
function allow(reasonCode) {
|
|
495
|
+
return Object.freeze({ disposition: "allow", reasonCode });
|
|
496
|
+
}
|
|
497
|
+
function deny(reasonCode) {
|
|
498
|
+
return Object.freeze({ disposition: "deny", reasonCode });
|
|
499
|
+
}
|
|
500
|
+
function abstain(reasonCode) {
|
|
501
|
+
return Object.freeze({ disposition: "abstain", reasonCode });
|
|
502
|
+
}
|
|
503
|
+
function portableSemanticDecisionV1(decision) {
|
|
504
|
+
if (decision.disposition === "allow")
|
|
505
|
+
return allow("semantic_control_allowed");
|
|
506
|
+
if (decision.disposition === "steer")
|
|
507
|
+
return abstain("semantic_steering_required");
|
|
508
|
+
if (decision.disposition === "abstain")
|
|
509
|
+
return abstain("semantic_control_abstained");
|
|
510
|
+
return deny("semantic_control_blocked");
|
|
511
|
+
}
|
|
512
|
+
//# sourceMappingURL=heterogeneous-agent-composition.js.map
|