@agent-surface/core 0.16.0 → 0.17.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/README.md +2 -2
- package/dist/explain.d.ts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +331 -59
- package/dist/index.js.map +1 -1
- package/dist/{registry-CWjIFWHV.d.ts → registry-QvbeJMRD.d.ts} +21 -29
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -10,13 +10,13 @@ const contract = defineAgentComponentContract({
|
|
|
10
10
|
actions: { selectRows: actionContract({ description: "Select", input, effect: "local-state" }) },
|
|
11
11
|
});
|
|
12
12
|
|
|
13
|
-
const registry = createAgentSurfaceRegistry({
|
|
13
|
+
const registry = createAgentSurfaceRegistry({ authority });
|
|
14
14
|
registry.register(contract.bind({
|
|
15
15
|
observations: { readState: { read } },
|
|
16
16
|
actions: { selectRows: { execute } },
|
|
17
17
|
}));
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
The compiler authority is mandatory. Raw/unknown/stale/changed registrations fail closed. Use `createAgentExposureGateway(authority)` at final provider/MCP assembly.
|
|
21
21
|
|
|
22
22
|
See [Core API](../../docs/03-core-api.md).
|
package/dist/explain.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { D as DiscoveryDecision, A as AgentRouteInfo, a as AgentConsumer, b as AgentSurfaceRegistry, S as SnapshotContext } from './registry-
|
|
2
|
-
export { m as matchesScope } from './registry-
|
|
1
|
+
import { D as DiscoveryDecision, A as AgentRouteInfo, a as AgentConsumer, b as AgentSurfaceRegistry, S as SnapshotContext } from './registry-QvbeJMRD.js';
|
|
2
|
+
export { m as matchesScope } from './registry-QvbeJMRD.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* `explainSurface()` — the developer projection.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { J as JsonSchema, c as JsonValue, d as AgentInvocationResult, U as Unsubscribe, a as AgentConsumer, b as AgentSurfaceRegistry } from './registry-
|
|
2
|
-
export { e as AGENT_CAPABILITY_ERROR_CODES, f as AgentActionContext, g as AgentActionContract, h as AgentActionDefinition, i as AgentActionDescriptor, j as AgentAuthorizationContext, k as AgentCapabilityDescriptorUnion, l as AgentCapabilityErrorCode, n as AgentCapabilityErrorPayload, o as AgentComponentContract, p as AgentComponentContractDefinition, q as AgentComponentDefinition, r as AgentComponentDescriptor, s as AgentComponentRuntimeBindings, t as AgentConcurrency, u as AgentEffect, v as AgentEnvironment, w as AgentErrorRetry, x as AgentExposureGateway, y as AgentInvocation, z as AgentInvocationPolicyContext, B as AgentObservationContract, C as AgentObservationDefinition, E as AgentObservationDescriptor, F as AgentPolicy, G as AgentPolicyContext, H as AgentProcedureBinding, I as AgentProcedureBindingRuntimeConfig, K as AgentProcedureContract, L as AgentProcedureContractDefinition, M as AgentProcedureDescriptor, N as AgentProcedureEffect, O as AgentProcedureExecutor, P as AgentProcedureRefDescriptor, Q as AgentReadContext, R as AgentRegistrationHandle, A as AgentRouteInfo, T as AgentSchema, V as AgentSchemaError, W as AgentSchemaIssue, X as AgentSurfaceDefinitionError, Y as AgentSurfaceDefinitionErrorCode, Z as AgentSurfaceError, _ as AgentSurfaceEvent, $ as AgentSurfaceLimits, a0 as AgentSurfaceSnapshot, a1 as AuditEvent, a2 as AuditSink, a3 as CAPABILITY_CONTRACT_FORMAT_VERSION, a4 as
|
|
1
|
+
import { J as JsonSchema, c as JsonValue, d as AgentInvocationResult, U as Unsubscribe, a as AgentConsumer, b as AgentSurfaceRegistry } from './registry-QvbeJMRD.js';
|
|
2
|
+
export { e as AGENT_CAPABILITY_ERROR_CODES, f as AgentActionContext, g as AgentActionContract, h as AgentActionDefinition, i as AgentActionDescriptor, j as AgentAuthorizationContext, k as AgentCapabilityDescriptorUnion, l as AgentCapabilityErrorCode, n as AgentCapabilityErrorPayload, o as AgentComponentContract, p as AgentComponentContractDefinition, q as AgentComponentDefinition, r as AgentComponentDescriptor, s as AgentComponentRuntimeBindings, t as AgentConcurrency, u as AgentEffect, v as AgentEnvironment, w as AgentErrorRetry, x as AgentExposureGateway, y as AgentInvocation, z as AgentInvocationPolicyContext, B as AgentObservationContract, C as AgentObservationDefinition, E as AgentObservationDescriptor, F as AgentPolicy, G as AgentPolicyContext, H as AgentProcedureBinding, I as AgentProcedureBindingRuntimeConfig, K as AgentProcedureContract, L as AgentProcedureContractDefinition, M as AgentProcedureDescriptor, N as AgentProcedureEffect, O as AgentProcedureExecutor, P as AgentProcedureRefDescriptor, Q as AgentReadContext, R as AgentRegistrationHandle, A as AgentRouteInfo, T as AgentSchema, V as AgentSchemaError, W as AgentSchemaIssue, X as AgentSurfaceDefinitionError, Y as AgentSurfaceDefinitionErrorCode, Z as AgentSurfaceError, _ as AgentSurfaceEvent, $ as AgentSurfaceLimits, a0 as AgentSurfaceSnapshot, a1 as AuditEvent, a2 as AuditSink, a3 as CAPABILITY_CONTRACT_FORMAT_VERSION, a4 as CONFIRMATION_ESCALATION, a5 as CapabilityAuthority, a6 as CapabilityContractEntry, a7 as CapabilityContractKind, a8 as CapabilityContractManifest, a9 as CapabilityPolicyAttachment, aa as CompiledExternalAgentTool, ab as ConfirmationController, ac as ConfirmationEscalation, ad as DEFAULT_LIMITS, D as DiscoveryDecision, ae as ExternalAgentToolContract, af as ExternalAgentToolContractDefinition, ag as ExternalCapabilityContractDigest, ah as InvokeOptions, ai as PendingConfirmation, aj as PreconditionFailure, ak as ProcedureCallInfo, al as RegistrationCandidate, am as RegistryOptions, S as SnapshotContext, an as StandardSchemaV1, ao as action, ap as actionContract, aq as assertDefinitionAuthorized, ar as audit, as as authenticated, at as authorizeAgentProcedureBinding, au as composeInvokeChain, av as consoleAuditSink, aw as createAgentExposureGateway, ax as createAgentSurfaceRegistry, ay as createCapabilityAuthority, az as defineAgentComponent, aA as defineAgentComponentContract, aB as defineAgentProcedureContract, aC as defineExternalAgentToolContract, aD as deriveAgentComponentBinding, aE as emptyObjectSchema, aF as environment, aG as evaluateDiscovery, aH as fromJsonSchema, aI as fromStandardSchema, aJ as hasPermission, aK as isAgentSurfaceError, aL as memoryAuditSink, aM as observation, aN as observationContract, aO as rateLimit, aP as requireConfirmation, aQ as tenantBoundary, aR as validateComponentDefinition, aS as validateJsonSchemaDocument, aT as validateValueAgainstSchema } from './registry-QvbeJMRD.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Canonical ID grammar (docs/01 §identity):
|
package/dist/index.js
CHANGED
|
@@ -23,6 +23,7 @@ import {
|
|
|
23
23
|
consumerKeyOf,
|
|
24
24
|
createSnapshot,
|
|
25
25
|
decodeWireName,
|
|
26
|
+
deepFreeze,
|
|
26
27
|
encodeWireName,
|
|
27
28
|
encodeWireNameForInstance,
|
|
28
29
|
environment,
|
|
@@ -1945,11 +1946,147 @@ function drainObservationQueues(internals) {
|
|
|
1945
1946
|
for (const waiter of waiting) waiter.admit(false);
|
|
1946
1947
|
}
|
|
1947
1948
|
|
|
1949
|
+
// src/sha256.ts
|
|
1950
|
+
var K = new Uint32Array([
|
|
1951
|
+
1116352408,
|
|
1952
|
+
1899447441,
|
|
1953
|
+
3049323471,
|
|
1954
|
+
3921009573,
|
|
1955
|
+
961987163,
|
|
1956
|
+
1508970993,
|
|
1957
|
+
2453635748,
|
|
1958
|
+
2870763221,
|
|
1959
|
+
3624381080,
|
|
1960
|
+
310598401,
|
|
1961
|
+
607225278,
|
|
1962
|
+
1426881987,
|
|
1963
|
+
1925078388,
|
|
1964
|
+
2162078206,
|
|
1965
|
+
2614888103,
|
|
1966
|
+
3248222580,
|
|
1967
|
+
3835390401,
|
|
1968
|
+
4022224774,
|
|
1969
|
+
264347078,
|
|
1970
|
+
604807628,
|
|
1971
|
+
770255983,
|
|
1972
|
+
1249150122,
|
|
1973
|
+
1555081692,
|
|
1974
|
+
1996064986,
|
|
1975
|
+
2554220882,
|
|
1976
|
+
2821834349,
|
|
1977
|
+
2952996808,
|
|
1978
|
+
3210313671,
|
|
1979
|
+
3336571891,
|
|
1980
|
+
3584528711,
|
|
1981
|
+
113926993,
|
|
1982
|
+
338241895,
|
|
1983
|
+
666307205,
|
|
1984
|
+
773529912,
|
|
1985
|
+
1294757372,
|
|
1986
|
+
1396182291,
|
|
1987
|
+
1695183700,
|
|
1988
|
+
1986661051,
|
|
1989
|
+
2177026350,
|
|
1990
|
+
2456956037,
|
|
1991
|
+
2730485921,
|
|
1992
|
+
2820302411,
|
|
1993
|
+
3259730800,
|
|
1994
|
+
3345764771,
|
|
1995
|
+
3516065817,
|
|
1996
|
+
3600352804,
|
|
1997
|
+
4094571909,
|
|
1998
|
+
275423344,
|
|
1999
|
+
430227734,
|
|
2000
|
+
506948616,
|
|
2001
|
+
659060556,
|
|
2002
|
+
883997877,
|
|
2003
|
+
958139571,
|
|
2004
|
+
1322822218,
|
|
2005
|
+
1537002063,
|
|
2006
|
+
1747873779,
|
|
2007
|
+
1955562222,
|
|
2008
|
+
2024104815,
|
|
2009
|
+
2227730452,
|
|
2010
|
+
2361852424,
|
|
2011
|
+
2428436474,
|
|
2012
|
+
2756734187,
|
|
2013
|
+
3204031479,
|
|
2014
|
+
3329325298
|
|
2015
|
+
]);
|
|
2016
|
+
function rotateRight(value, shift) {
|
|
2017
|
+
return value >>> shift | value << 32 - shift;
|
|
2018
|
+
}
|
|
2019
|
+
function sha256(input) {
|
|
2020
|
+
const bytes = new TextEncoder().encode(input);
|
|
2021
|
+
const paddedLength = Math.ceil((bytes.length + 9) / 64) * 64;
|
|
2022
|
+
const padded = new Uint8Array(paddedLength);
|
|
2023
|
+
padded.set(bytes);
|
|
2024
|
+
padded[bytes.length] = 128;
|
|
2025
|
+
const bitLength = bytes.length * 8;
|
|
2026
|
+
const view = new DataView(padded.buffer);
|
|
2027
|
+
view.setUint32(paddedLength - 8, Math.floor(bitLength / 4294967296));
|
|
2028
|
+
view.setUint32(paddedLength - 4, bitLength >>> 0);
|
|
2029
|
+
const hash = new Uint32Array([
|
|
2030
|
+
1779033703,
|
|
2031
|
+
3144134277,
|
|
2032
|
+
1013904242,
|
|
2033
|
+
2773480762,
|
|
2034
|
+
1359893119,
|
|
2035
|
+
2600822924,
|
|
2036
|
+
528734635,
|
|
2037
|
+
1541459225
|
|
2038
|
+
]);
|
|
2039
|
+
const words = new Uint32Array(64);
|
|
2040
|
+
for (let offset = 0; offset < paddedLength; offset += 64) {
|
|
2041
|
+
for (let index = 0; index < 16; index += 1) {
|
|
2042
|
+
words[index] = view.getUint32(offset + index * 4);
|
|
2043
|
+
}
|
|
2044
|
+
for (let index = 16; index < 64; index += 1) {
|
|
2045
|
+
const a2 = words[index - 15];
|
|
2046
|
+
const b2 = words[index - 2];
|
|
2047
|
+
const sigma0 = rotateRight(a2, 7) ^ rotateRight(a2, 18) ^ a2 >>> 3;
|
|
2048
|
+
const sigma1 = rotateRight(b2, 17) ^ rotateRight(b2, 19) ^ b2 >>> 10;
|
|
2049
|
+
words[index] = words[index - 16] + sigma0 + words[index - 7] + sigma1 >>> 0;
|
|
2050
|
+
}
|
|
2051
|
+
let [a, b, c, d, e, f, g, h] = hash;
|
|
2052
|
+
for (let index = 0; index < 64; index += 1) {
|
|
2053
|
+
const sum1 = rotateRight(e, 6) ^ rotateRight(e, 11) ^ rotateRight(e, 25);
|
|
2054
|
+
const choice = e & f ^ ~e & g;
|
|
2055
|
+
const temp1 = h + sum1 + choice + K[index] + words[index] >>> 0;
|
|
2056
|
+
const sum0 = rotateRight(a, 2) ^ rotateRight(a, 13) ^ rotateRight(a, 22);
|
|
2057
|
+
const majority = a & b ^ a & c ^ b & c;
|
|
2058
|
+
const temp2 = sum0 + majority >>> 0;
|
|
2059
|
+
h = g;
|
|
2060
|
+
g = f;
|
|
2061
|
+
f = e;
|
|
2062
|
+
e = d + temp1 >>> 0;
|
|
2063
|
+
d = c;
|
|
2064
|
+
c = b;
|
|
2065
|
+
b = a;
|
|
2066
|
+
a = temp1 + temp2 >>> 0;
|
|
2067
|
+
}
|
|
2068
|
+
hash[0] = hash[0] + a >>> 0;
|
|
2069
|
+
hash[1] = hash[1] + b >>> 0;
|
|
2070
|
+
hash[2] = hash[2] + c >>> 0;
|
|
2071
|
+
hash[3] = hash[3] + d >>> 0;
|
|
2072
|
+
hash[4] = hash[4] + e >>> 0;
|
|
2073
|
+
hash[5] = hash[5] + f >>> 0;
|
|
2074
|
+
hash[6] = hash[6] + g >>> 0;
|
|
2075
|
+
hash[7] = hash[7] + h >>> 0;
|
|
2076
|
+
}
|
|
2077
|
+
return [...hash].map((value) => value.toString(16).padStart(8, "0")).join("");
|
|
2078
|
+
}
|
|
2079
|
+
|
|
1948
2080
|
// src/contract.ts
|
|
1949
|
-
var CAPABILITY_CONTRACT_FORMAT_VERSION =
|
|
1950
|
-
var
|
|
1951
|
-
|
|
1952
|
-
);
|
|
2081
|
+
var CAPABILITY_CONTRACT_FORMAT_VERSION = 4;
|
|
2082
|
+
var authorityStates = /* @__PURE__ */ new WeakMap();
|
|
2083
|
+
var componentBindingProofs = /* @__PURE__ */ new WeakMap();
|
|
2084
|
+
var capabilityContractProofs = /* @__PURE__ */ new WeakMap();
|
|
2085
|
+
var externalToolProofs = /* @__PURE__ */ new WeakMap();
|
|
2086
|
+
var unsafeAuthorityTestMode = false;
|
|
2087
|
+
function isUnsafeAuthorityTestMode() {
|
|
2088
|
+
return unsafeAuthorityTestMode;
|
|
2089
|
+
}
|
|
1953
2090
|
function observationContract(contract) {
|
|
1954
2091
|
return contract;
|
|
1955
2092
|
}
|
|
@@ -2024,12 +2161,7 @@ function defineAgentComponentContract(definition, compiled) {
|
|
|
2024
2161
|
...Object.keys(actions).length > 0 ? { actions } : {},
|
|
2025
2162
|
...bindings.procedures ? { procedures: bindings.procedures } : {}
|
|
2026
2163
|
};
|
|
2027
|
-
if (compiled)
|
|
2028
|
-
Object.defineProperty(bound, COMPILED_CAPABILITY_PROVENANCE, {
|
|
2029
|
-
value: compiled,
|
|
2030
|
-
enumerable: false
|
|
2031
|
-
});
|
|
2032
|
-
}
|
|
2164
|
+
if (compiled) componentBindingProofs.set(bound, compiled);
|
|
2033
2165
|
return bound;
|
|
2034
2166
|
}
|
|
2035
2167
|
};
|
|
@@ -2040,12 +2172,7 @@ function defineAgentProcedureContract(definition, compiled) {
|
|
|
2040
2172
|
kind: "agent-procedure-contract",
|
|
2041
2173
|
definition
|
|
2042
2174
|
};
|
|
2043
|
-
if (compiled)
|
|
2044
|
-
Object.defineProperty(contract, COMPILED_CAPABILITY_PROVENANCE, {
|
|
2045
|
-
value: compiled,
|
|
2046
|
-
enumerable: false
|
|
2047
|
-
});
|
|
2048
|
-
}
|
|
2175
|
+
if (compiled) capabilityContractProofs.set(contract, compiled);
|
|
2049
2176
|
return contract;
|
|
2050
2177
|
}
|
|
2051
2178
|
function defineExternalAgentToolContract(definition, compiled) {
|
|
@@ -2065,34 +2192,28 @@ function defineExternalAgentToolContract(definition, compiled) {
|
|
|
2065
2192
|
inputSchema: definition.input.jsonSchema,
|
|
2066
2193
|
execute: binding.execute
|
|
2067
2194
|
};
|
|
2068
|
-
|
|
2069
|
-
value: compiled,
|
|
2070
|
-
enumerable: false
|
|
2071
|
-
});
|
|
2195
|
+
externalToolProofs.set(tool, compiled);
|
|
2072
2196
|
return tool;
|
|
2073
2197
|
}
|
|
2074
2198
|
};
|
|
2075
|
-
if (compiled)
|
|
2076
|
-
Object.defineProperty(contract, COMPILED_CAPABILITY_PROVENANCE, {
|
|
2077
|
-
value: compiled,
|
|
2078
|
-
enumerable: false
|
|
2079
|
-
});
|
|
2080
|
-
}
|
|
2199
|
+
if (compiled) capabilityContractProofs.set(contract, compiled);
|
|
2081
2200
|
return contract;
|
|
2082
2201
|
}
|
|
2083
|
-
function
|
|
2084
|
-
const
|
|
2085
|
-
if (
|
|
2086
|
-
|
|
2087
|
-
|
|
2088
|
-
|
|
2089
|
-
|
|
2202
|
+
function deriveAgentComponentBinding(source, derived) {
|
|
2203
|
+
const proof = componentBindingProofs.get(source);
|
|
2204
|
+
if (proof) componentBindingProofs.set(derived, proof);
|
|
2205
|
+
return derived;
|
|
2206
|
+
}
|
|
2207
|
+
function authorizeAgentProcedureBinding(contract, definition) {
|
|
2208
|
+
const token = capabilityContractProofs.get(contract);
|
|
2209
|
+
if (token) {
|
|
2210
|
+
componentBindingProofs.set(definition, {
|
|
2211
|
+
manifestHash: token.manifestHash,
|
|
2212
|
+
declarationId: token.declarationId,
|
|
2213
|
+
capabilities: { [token.capabilityId]: token }
|
|
2214
|
+
});
|
|
2090
2215
|
}
|
|
2091
|
-
return
|
|
2092
|
-
}
|
|
2093
|
-
function tryCompiledCapabilityToken(contract) {
|
|
2094
|
-
const token = contract[COMPILED_CAPABILITY_PROVENANCE];
|
|
2095
|
-
return token && !("capabilities" in token) ? token : void 0;
|
|
2216
|
+
return definition;
|
|
2096
2217
|
}
|
|
2097
2218
|
function manifestIndex(manifest) {
|
|
2098
2219
|
if (manifest.formatVersion !== CAPABILITY_CONTRACT_FORMAT_VERSION || manifest.completeness?.status !== "proven" || typeof manifest.hash !== "string" || manifest.hash.length === 0) {
|
|
@@ -2100,6 +2221,13 @@ function manifestIndex(manifest) {
|
|
|
2100
2221
|
}
|
|
2101
2222
|
const index = /* @__PURE__ */ new Map();
|
|
2102
2223
|
for (const entry of manifest.capabilities) {
|
|
2224
|
+
const { contractHash, targets: _targets, ...contract } = entry;
|
|
2225
|
+
if (sha256(canonicalContractJson(contract)) !== contractHash) {
|
|
2226
|
+
throw new AgentSurfaceDefinitionError(
|
|
2227
|
+
"INVALID_DEFINITION",
|
|
2228
|
+
`compiled contract hash is invalid for "${entry.capabilityId}"`
|
|
2229
|
+
);
|
|
2230
|
+
}
|
|
2103
2231
|
const key = `${entry.declarationId}\0${entry.capabilityId}`;
|
|
2104
2232
|
if (index.has(key)) {
|
|
2105
2233
|
throw new AgentSurfaceDefinitionError(
|
|
@@ -2109,8 +2237,49 @@ function manifestIndex(manifest) {
|
|
|
2109
2237
|
}
|
|
2110
2238
|
index.set(key, entry);
|
|
2111
2239
|
}
|
|
2240
|
+
const { hash, ...payload } = manifest;
|
|
2241
|
+
if (sha256(canonicalContractJson(payload)) !== hash) {
|
|
2242
|
+
throw new AgentSurfaceDefinitionError("INVALID_DEFINITION", "compiled manifest hash is invalid");
|
|
2243
|
+
}
|
|
2112
2244
|
return index;
|
|
2113
2245
|
}
|
|
2246
|
+
function canonicalContractValue(value) {
|
|
2247
|
+
if (value === null) return "null";
|
|
2248
|
+
if (value === void 0) return "null";
|
|
2249
|
+
if (typeof value === "string" || typeof value === "boolean") return JSON.stringify(value);
|
|
2250
|
+
if (typeof value === "number") {
|
|
2251
|
+
if (!Number.isFinite(value)) throw new Error("contract contains a non-finite number");
|
|
2252
|
+
return JSON.stringify(Object.is(value, -0) ? 0 : value);
|
|
2253
|
+
}
|
|
2254
|
+
if (Array.isArray(value)) return `[${value.map(canonicalContractValue).join(",")}]`;
|
|
2255
|
+
const record = value;
|
|
2256
|
+
return `{${Object.keys(record).sort().filter((key) => record[key] !== void 0).map((key) => `${JSON.stringify(key)}:${canonicalContractValue(record[key])}`).join(",")}}`;
|
|
2257
|
+
}
|
|
2258
|
+
function canonicalContractJson(value) {
|
|
2259
|
+
return `${canonicalContractValue(value)}
|
|
2260
|
+
`;
|
|
2261
|
+
}
|
|
2262
|
+
function createCapabilityAuthority(manifest) {
|
|
2263
|
+
const snapshot = deepFreeze(
|
|
2264
|
+
JSON.parse(JSON.stringify(manifest))
|
|
2265
|
+
);
|
|
2266
|
+
const authority = Object.freeze({ manifest: snapshot });
|
|
2267
|
+
authorityStates.set(authority, { manifest: snapshot, index: manifestIndex(snapshot) });
|
|
2268
|
+
return authority;
|
|
2269
|
+
}
|
|
2270
|
+
function authorityState(authority) {
|
|
2271
|
+
const state = authorityStates.get(authority);
|
|
2272
|
+
if (!state) {
|
|
2273
|
+
throw new AgentSurfaceDefinitionError(
|
|
2274
|
+
"INVALID_DEFINITION",
|
|
2275
|
+
"invalid capability authority: use compiler-generated authority"
|
|
2276
|
+
);
|
|
2277
|
+
}
|
|
2278
|
+
return state;
|
|
2279
|
+
}
|
|
2280
|
+
function assertCapabilityAuthority(authority) {
|
|
2281
|
+
authorityState(authority);
|
|
2282
|
+
}
|
|
2114
2283
|
function assertToken(token, manifest, index) {
|
|
2115
2284
|
if (token.manifestHash !== manifest.hash) {
|
|
2116
2285
|
throw new AgentSurfaceDefinitionError(
|
|
@@ -2132,27 +2301,98 @@ function assertToken(token, manifest, index) {
|
|
|
2132
2301
|
);
|
|
2133
2302
|
}
|
|
2134
2303
|
}
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
if (
|
|
2304
|
+
var CONFIRMATION_RANK = { never: 0, optional: 1, required: 2 };
|
|
2305
|
+
function effectiveProcedureConfirmation(binding) {
|
|
2306
|
+
if (binding.ref.requiresApproval || binding.config.confirmation === "required") return "required";
|
|
2307
|
+
return binding.config.confirmation ?? "never";
|
|
2308
|
+
}
|
|
2309
|
+
function runtimeCapabilities(definition) {
|
|
2310
|
+
const sharedPolicies = definition.policies ?? [];
|
|
2311
|
+
return [
|
|
2312
|
+
...Object.entries(definition.observations ?? {}).map(([name, observation2]) => ({
|
|
2313
|
+
capabilityId: `view:${definition.type}.${name}`,
|
|
2314
|
+
kind: "observation",
|
|
2315
|
+
description: observation2.description,
|
|
2316
|
+
effect: "read",
|
|
2317
|
+
outputSchema: observation2.output.jsonSchema,
|
|
2318
|
+
policies: [...sharedPolicies, ...observation2.policies ?? []]
|
|
2319
|
+
})),
|
|
2320
|
+
...Object.entries(definition.actions ?? {}).map(([name, action2]) => ({
|
|
2321
|
+
capabilityId: `view:${definition.type}.${name}`,
|
|
2322
|
+
kind: "action",
|
|
2323
|
+
description: action2.description,
|
|
2324
|
+
effect: action2.effect,
|
|
2325
|
+
inputSchema: action2.input.jsonSchema,
|
|
2326
|
+
...action2.output ? { outputSchema: action2.output.jsonSchema } : {},
|
|
2327
|
+
confirmation: action2.confirmation ?? "never",
|
|
2328
|
+
policies: [...sharedPolicies, ...action2.policies ?? []]
|
|
2329
|
+
})),
|
|
2330
|
+
...(definition.procedures ?? []).map((binding) => ({
|
|
2331
|
+
capabilityId: binding.ref.id,
|
|
2332
|
+
kind: "procedure",
|
|
2333
|
+
description: binding.ref.description,
|
|
2334
|
+
effect: binding.ref.effect,
|
|
2335
|
+
inputSchema: binding.ref.inputSchema,
|
|
2336
|
+
...binding.ref.outputSchema ? { outputSchema: binding.ref.outputSchema } : {},
|
|
2337
|
+
confirmation: effectiveProcedureConfirmation(binding),
|
|
2338
|
+
policies: [...sharedPolicies, ...binding.config.policies ?? []]
|
|
2339
|
+
}))
|
|
2340
|
+
];
|
|
2341
|
+
}
|
|
2342
|
+
function assertPolicyCoverage(declared, runtime, capabilityId) {
|
|
2343
|
+
for (const attachment of declared ?? []) {
|
|
2344
|
+
const policy = runtime.find((candidate) => candidate.name === attachment.name);
|
|
2345
|
+
const phaseImplemented = !attachment.phase || attachment.phase === "discovery" && typeof policy?.onDiscovery === "function" || attachment.phase === "authorize" && typeof policy?.onAuthorize === "function" || attachment.phase === "invoke" && typeof policy?.onInvoke === "function";
|
|
2346
|
+
if (!policy || !phaseImplemented) {
|
|
2347
|
+
throw new AgentSurfaceDefinitionError(
|
|
2348
|
+
"INVALID_DEFINITION",
|
|
2349
|
+
`capability "${capabilityId}" omits required policy "${attachment.name}"${attachment.phase ? ` at ${attachment.phase}` : ""}`
|
|
2350
|
+
);
|
|
2351
|
+
}
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
function assertRuntimeMatchesContract(runtime, declared) {
|
|
2355
|
+
const mismatch = (field) => {
|
|
2356
|
+
throw new AgentSurfaceDefinitionError(
|
|
2357
|
+
"INVALID_DEFINITION",
|
|
2358
|
+
`runtime ${field} mismatch for "${runtime.capabilityId}"`
|
|
2359
|
+
);
|
|
2360
|
+
};
|
|
2361
|
+
if (declared.kind !== runtime.kind) mismatch("kind");
|
|
2362
|
+
if (declared.description !== runtime.description) mismatch("description");
|
|
2363
|
+
if (declared.effect !== runtime.effect) mismatch("effect");
|
|
2364
|
+
if (!jsonDeepEqual(declared.inputSchema, runtime.inputSchema)) {
|
|
2365
|
+
mismatch("input schema");
|
|
2366
|
+
}
|
|
2367
|
+
if (!jsonDeepEqual(declared.outputSchema, runtime.outputSchema)) {
|
|
2368
|
+
mismatch("output schema");
|
|
2369
|
+
}
|
|
2370
|
+
const declaredConfirmation = declared.confirmation ?? "never";
|
|
2371
|
+
const runtimeConfirmation = runtime.confirmation ?? "never";
|
|
2372
|
+
if (CONFIRMATION_RANK[runtimeConfirmation] < CONFIRMATION_RANK[declaredConfirmation]) {
|
|
2373
|
+
mismatch("confirmation");
|
|
2374
|
+
}
|
|
2375
|
+
assertPolicyCoverage(declared.policies, runtime.policies, runtime.capabilityId);
|
|
2376
|
+
}
|
|
2377
|
+
function assertDefinitionAuthorized(definition, authority) {
|
|
2378
|
+
const state = authorityState(authority);
|
|
2379
|
+
const provenance = componentBindingProofs.get(definition);
|
|
2380
|
+
if (!provenance) {
|
|
2138
2381
|
throw new AgentSurfaceDefinitionError(
|
|
2139
2382
|
"INVALID_DEFINITION",
|
|
2140
2383
|
`raw registration "${definition.type}" rejected: bind a compiler-generated contract`
|
|
2141
2384
|
);
|
|
2142
2385
|
}
|
|
2143
|
-
if (provenance.manifestHash !== manifest.hash) {
|
|
2386
|
+
if (provenance.manifestHash !== state.manifest.hash) {
|
|
2144
2387
|
throw new AgentSurfaceDefinitionError(
|
|
2145
2388
|
"INVALID_DEFINITION",
|
|
2146
2389
|
`stale contract "${provenance.declarationId}": manifest hash mismatch`
|
|
2147
2390
|
);
|
|
2148
2391
|
}
|
|
2149
|
-
const
|
|
2150
|
-
const expected =
|
|
2151
|
-
|
|
2152
|
-
|
|
2153
|
-
...(definition.procedures ?? []).map((binding) => binding.ref.id)
|
|
2154
|
-
];
|
|
2155
|
-
for (const capabilityId of expected) {
|
|
2392
|
+
const capabilities = runtimeCapabilities(definition);
|
|
2393
|
+
const expected = capabilities.map((capability) => capability.capabilityId);
|
|
2394
|
+
for (const capability of capabilities) {
|
|
2395
|
+
const capabilityId = capability.capabilityId;
|
|
2156
2396
|
const token = provenance.capabilities[capabilityId];
|
|
2157
2397
|
if (!token) {
|
|
2158
2398
|
throw new AgentSurfaceDefinitionError(
|
|
@@ -2160,7 +2400,9 @@ function assertDefinitionInManifest(definition, manifest) {
|
|
|
2160
2400
|
`capability "${capabilityId}" is absent from compiled contract "${provenance.declarationId}"`
|
|
2161
2401
|
);
|
|
2162
2402
|
}
|
|
2163
|
-
assertToken(token, manifest, index);
|
|
2403
|
+
assertToken(token, state.manifest, state.index);
|
|
2404
|
+
const declared = state.index.get(`${token.declarationId}\0${token.capabilityId}`);
|
|
2405
|
+
assertRuntimeMatchesContract(capability, declared);
|
|
2164
2406
|
}
|
|
2165
2407
|
for (const capabilityId of Object.keys(provenance.capabilities)) {
|
|
2166
2408
|
if (!expected.includes(capabilityId)) {
|
|
@@ -2171,19 +2413,38 @@ function assertDefinitionInManifest(definition, manifest) {
|
|
|
2171
2413
|
}
|
|
2172
2414
|
}
|
|
2173
2415
|
}
|
|
2174
|
-
function createAgentExposureGateway(
|
|
2175
|
-
const
|
|
2416
|
+
function createAgentExposureGateway(authority) {
|
|
2417
|
+
const state = authorityState(authority);
|
|
2176
2418
|
return {
|
|
2177
2419
|
expose(tools) {
|
|
2178
2420
|
return tools.map((tool) => {
|
|
2179
|
-
const token = tool
|
|
2421
|
+
const token = externalToolProofs.get(tool);
|
|
2180
2422
|
if (!token) {
|
|
2181
2423
|
throw new AgentSurfaceDefinitionError(
|
|
2182
2424
|
"INVALID_DEFINITION",
|
|
2183
2425
|
`raw provider tool "${tool.name}" rejected by compiled exposure gateway`
|
|
2184
2426
|
);
|
|
2185
2427
|
}
|
|
2186
|
-
assertToken(token, manifest, index);
|
|
2428
|
+
assertToken(token, state.manifest, state.index);
|
|
2429
|
+
const declared = state.index.get(`${token.declarationId}\0${token.capabilityId}`);
|
|
2430
|
+
if (declared.kind !== "external") {
|
|
2431
|
+
throw new AgentSurfaceDefinitionError(
|
|
2432
|
+
"INVALID_DEFINITION",
|
|
2433
|
+
`runtime kind mismatch for "${tool.name}"`
|
|
2434
|
+
);
|
|
2435
|
+
}
|
|
2436
|
+
if (declared.capabilityId !== tool.name || declared.description !== tool.description) {
|
|
2437
|
+
throw new AgentSurfaceDefinitionError(
|
|
2438
|
+
"INVALID_DEFINITION",
|
|
2439
|
+
`runtime external tool mismatch for "${tool.name}"`
|
|
2440
|
+
);
|
|
2441
|
+
}
|
|
2442
|
+
if (!jsonDeepEqual(declared.inputSchema, tool.inputSchema)) {
|
|
2443
|
+
throw new AgentSurfaceDefinitionError(
|
|
2444
|
+
"INVALID_DEFINITION",
|
|
2445
|
+
`runtime input schema mismatch for "${tool.name}"`
|
|
2446
|
+
);
|
|
2447
|
+
}
|
|
2187
2448
|
return tool;
|
|
2188
2449
|
});
|
|
2189
2450
|
}
|
|
@@ -2192,6 +2453,14 @@ function createAgentExposureGateway(manifest) {
|
|
|
2192
2453
|
|
|
2193
2454
|
// src/registry.ts
|
|
2194
2455
|
function createAgentSurfaceRegistry(options) {
|
|
2456
|
+
const unsafeTestMode = isUnsafeAuthorityTestMode();
|
|
2457
|
+
if (!options?.authority && !unsafeTestMode) {
|
|
2458
|
+
throw new AgentSurfaceDefinitionError(
|
|
2459
|
+
"INVALID_DEFINITION",
|
|
2460
|
+
"createAgentSurfaceRegistry requires a compiler-generated capability authority"
|
|
2461
|
+
);
|
|
2462
|
+
}
|
|
2463
|
+
if (options?.authority) assertCapabilityAuthority(options.authority);
|
|
2195
2464
|
const environment2 = options?.environment ?? "production";
|
|
2196
2465
|
const limits = { ...DEFAULT_LIMITS, ...options?.limits ?? {} };
|
|
2197
2466
|
const now = options?.now ?? (() => Date.now());
|
|
@@ -2338,7 +2607,10 @@ function createAgentSurfaceRegistry(options) {
|
|
|
2338
2607
|
surfaceId: internals.surfaceId,
|
|
2339
2608
|
register(definition) {
|
|
2340
2609
|
if (internals.disposed) throw new Error("register() called on a disposed registry");
|
|
2341
|
-
if (options?.
|
|
2610
|
+
if (options?.authority) assertDefinitionAuthorized(definition, options.authority);
|
|
2611
|
+
else if (!unsafeTestMode) {
|
|
2612
|
+
throw new AgentSurfaceDefinitionError("INVALID_DEFINITION", "capability authority unavailable");
|
|
2613
|
+
}
|
|
2342
2614
|
validateComponentDefinition(definition, limits, {
|
|
2343
2615
|
hasProcedureExecutor: internals.executor !== void 0
|
|
2344
2616
|
});
|
|
@@ -3028,28 +3300,29 @@ export {
|
|
|
3028
3300
|
AgentSurfaceDefinitionError,
|
|
3029
3301
|
AgentSurfaceError,
|
|
3030
3302
|
CAPABILITY_CONTRACT_FORMAT_VERSION,
|
|
3031
|
-
COMPILED_CAPABILITY_PROVENANCE,
|
|
3032
3303
|
CONFIRMATION_ESCALATION,
|
|
3033
3304
|
DEFAULT_LIMITS,
|
|
3034
3305
|
MAX_ID_LENGTH,
|
|
3035
3306
|
MAX_WIRE_NAME_LENGTH,
|
|
3036
3307
|
action,
|
|
3037
3308
|
actionContract,
|
|
3038
|
-
|
|
3309
|
+
assertDefinitionAuthorized,
|
|
3039
3310
|
assignWireNames,
|
|
3040
3311
|
audit,
|
|
3041
3312
|
authenticated,
|
|
3042
|
-
|
|
3313
|
+
authorizeAgentProcedureBinding,
|
|
3043
3314
|
composeInvokeChain,
|
|
3044
3315
|
consoleAuditSink,
|
|
3045
3316
|
createAgentExposureGateway,
|
|
3046
3317
|
createAgentSurfaceRegistry,
|
|
3047
3318
|
createAgentToolset,
|
|
3319
|
+
createCapabilityAuthority,
|
|
3048
3320
|
decodeWireName,
|
|
3049
3321
|
defineAgentComponent,
|
|
3050
3322
|
defineAgentComponentContract,
|
|
3051
3323
|
defineAgentProcedureContract,
|
|
3052
3324
|
defineExternalAgentToolContract,
|
|
3325
|
+
deriveAgentComponentBinding,
|
|
3053
3326
|
emptyObjectSchema,
|
|
3054
3327
|
encodeWireName,
|
|
3055
3328
|
encodeWireNameForInstance,
|
|
@@ -3072,7 +3345,6 @@ export {
|
|
|
3072
3345
|
rateLimit,
|
|
3073
3346
|
requireConfirmation,
|
|
3074
3347
|
tenantBoundary,
|
|
3075
|
-
tryCompiledCapabilityToken,
|
|
3076
3348
|
validateComponentDefinition,
|
|
3077
3349
|
validateJsonSchemaDocument,
|
|
3078
3350
|
validateValueAgainstSchema
|