Add exact runtime conformance lookup and agent-visible language limits

This commit is contained in:
Timothy J. Aveni
2026-09-17 11:29:56 -07:00
parent 47efd9659d
commit 169c0cdc37
19 changed files with 504 additions and 190 deletions
+37 -41
View File
@@ -123,6 +123,35 @@ export class RuntimeAuthorityError extends Error {
}
const targetForEdge = (edge, projectionId) => (edge.firstProjectionId === projectionId ? edge.secondObjectId : edge.firstObjectId);
export const createRuntimeContext = (camino, orch, request) => {
const acquiredPort = (objectId, interfaceRevisionId, conformance) => {
const invoke = async (operationId, input = {}) => {
const response = await orch.invokeCapability({
objectId,
capability: create(CapabilityRefSchema, { interfaceRevisionId, operationId, conformance }),
input: Object.fromEntries(Object.entries(input).map(([key, value]) => [key, jsToProtoValue(value)])),
});
if (!response.ok)
throw new Error(response.error || "Capability invocation failed");
for (const dependency of response.dependencies) {
if (dependency.kind === "state" || dependency.kind === "edge")
await recordDependency({
kind: dependency.kind,
objectId: dependency.objectId,
attachmentId: dependency.attachmentId,
...(dependency.kind === "edge" ? { projectionId: dependency.projectionId } : {}),
});
}
if (!response.result)
throw new Error("Capability returned no value");
return response.result;
};
return {
objectId: referenceFromWire(objectId),
interfaceRevisionId,
invoke: async (operation, input) => protoValueToJs(await invoke(operation, input)),
live: async (operation, input) => liveValue(await invoke(operation, input)),
};
};
const ports = new Map();
for (const dependency of request.dependencies) {
switch (dependency.binding.case) {
@@ -224,47 +253,7 @@ export const createRuntimeContext = (camino, orch, request) => {
case "interfaceRevisionId": {
const interfaceRevisionId = dependency.binding.value;
const dependencyObjectId = dependency.objectId || request.objectId;
const invoke = async (operationId, input) => {
const response = await orch.invokeCapability({
capability: create(CapabilityRefSchema, { interfaceRevisionId, operationId }),
objectId: dependencyObjectId,
input: Object.fromEntries(Object.entries(input).map(([key, value]) => [key, jsToProtoValue(value)])),
});
if (!response.ok)
throw new Error(response.error || `Capability ${operationId} failed`);
for (const dependency of response.dependencies) {
if (dependency.kind === "state") {
await recordDependency({
kind: "state",
objectId: dependency.objectId,
attachmentId: dependency.attachmentId,
});
}
else if (dependency.kind === "edge") {
await recordDependency({
kind: "edge",
objectId: dependency.objectId,
attachmentId: dependency.attachmentId,
projectionId: dependency.projectionId,
});
}
}
return response.result;
};
const capability = {
objectId: referenceFromWire(dependencyObjectId),
interfaceRevisionId,
async invoke(operationId, input = {}) {
return protoValueToJs(await invoke(operationId, input));
},
async live(operationId, input = {}) {
const value = await invoke(operationId, input);
if (!value)
throw new Error(`Capability ${operationId} returned no value`);
return liveValue(value);
},
};
ports.set(dependency.portId, capability);
ports.set(dependency.portId, acquiredPort(dependencyObjectId, interfaceRevisionId));
break;
}
case "constructorAtomId": {
@@ -292,6 +281,13 @@ export const createRuntimeContext = (camino, orch, request) => {
return port;
};
return {
async tryConform(object, interfaceRevisionId) {
const objectId = referenceToWire(object);
const { conformance } = await orch.tryConform({ objectId, interfaceRevisionId });
if (conformance && (conformance.objectId !== objectId || conformance.interfaceRevisionId !== interfaceRevisionId))
throw new Error("Conformance response does not match the requested view");
return conformance ? acquiredPort(objectId, interfaceRevisionId, conformance) : undefined;
},
get objectId() {
return referenceFromWire(request.objectId);
},