agent-embassy 1.6.0 → 1.6.1
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 +11 -0
- package/dist/src/gateway/cli.d.ts +1 -1
- package/dist/src/gateway/cli.js +1 -1
- package/dist/src/gateway/codex-app-server.d.ts +2 -2
- package/dist/src/gateway/codex-app-server.js +4 -2
- package/dist/src/gateway/codex-app-server.js.map +1 -1
- package/dist/src/gateway/providers.d.ts +1 -0
- package/dist/src/gateway/providers.js +47 -21
- package/dist/src/gateway/providers.js.map +1 -1
- package/dist/src/gateway/service.js +7 -2
- package/dist/src/gateway/service.js.map +1 -1
- package/package.json +1 -1
|
@@ -2,7 +2,7 @@ import path from "node:path";
|
|
|
2
2
|
import { chmod, lstat, mkdir, mkdtemp, readdir, realpath, rmdir, } from "node:fs/promises";
|
|
3
3
|
import { BridgeError } from "../errors.js";
|
|
4
4
|
import { CLAUDE_PEER_COMPATIBILITY, ClaudePeerAdapter, } from "./claude-peer.js";
|
|
5
|
-
import { certifiedCompatibilityVersions, compatibilityProbeNames, evaluateCompatibilityAttestation, isCompatibilityAttestation, isCompatibilityVersion, sharesCompatibilityMajor, UNKNOWN_COMPATIBILITY_VERSION, } from "./compatibility.js";
|
|
5
|
+
import { certifiedCompatibilityVersions, compatibilityCoversWrites, compatibilityProbeNames, evaluateCompatibilityAttestation, isCompatibilityAttestation, isCompatibilityVersion, sharesCompatibilityMajor, UNKNOWN_COMPATIBILITY_VERSION, } from "./compatibility.js";
|
|
6
6
|
import { CODEX_APP_SERVER_WRITABLE_VERSIONS, CodexAppServerConnector, CodexConnectorError, codexWriteProbeFailure, } from "./codex-app-server.js";
|
|
7
7
|
import { LocalCodexTransportError } from "./codex-local-transport.js";
|
|
8
8
|
import { ClaudeNativeHelperSupervisor, } from "./claude-helper-supervisor.js";
|
|
@@ -1940,6 +1940,16 @@ function validateCodexFactory(factory, options = {}) {
|
|
|
1940
1940
|
throw new BridgeError("CODEX_FACTORY_ATTESTATION_INVALID", "The local Codex provider requires exact schema and write attestations.");
|
|
1941
1941
|
}
|
|
1942
1942
|
}
|
|
1943
|
+
function codexFactoryWritesEnabled(factory, attestation, writeProbePassed = false) {
|
|
1944
|
+
return ((attestation.tier === "certified" &&
|
|
1945
|
+
CODEX_APP_SERVER_WRITABLE_VERSIONS.includes(attestation.version) &&
|
|
1946
|
+
factory.writableReady &&
|
|
1947
|
+
factory.writeCompatibility !== null) ||
|
|
1948
|
+
(!factory.writableReady &&
|
|
1949
|
+
factory.writeCompatibility === null &&
|
|
1950
|
+
writeProbePassed &&
|
|
1951
|
+
compatibilityCoversWrites(attestation)));
|
|
1952
|
+
}
|
|
1943
1953
|
function codexRouteState(observation) {
|
|
1944
1954
|
if (observation.connection !== "ready")
|
|
1945
1955
|
return "stale";
|
|
@@ -1999,6 +2009,7 @@ export class LocalCodexGatewayProvider {
|
|
|
1999
2009
|
callbackDrainFrozen = false;
|
|
2000
2010
|
writeProbeObservationsByGeneration = new Map();
|
|
2001
2011
|
writeProbeResults = new Map();
|
|
2012
|
+
writeProbeDecline;
|
|
2002
2013
|
writeProbeOverflow;
|
|
2003
2014
|
compatibilityAttested;
|
|
2004
2015
|
compatibilityFailureCode;
|
|
@@ -2014,7 +2025,9 @@ export class LocalCodexGatewayProvider {
|
|
|
2014
2025
|
this.factory = options.factory;
|
|
2015
2026
|
this.refreshFactory = options.refreshFactory;
|
|
2016
2027
|
exactLocalHost(options.factory.hostId);
|
|
2017
|
-
this.compatibilityAttested =
|
|
2028
|
+
this.compatibilityAttested =
|
|
2029
|
+
options.factory.writableReady &&
|
|
2030
|
+
options.factory.writeCompatibility !== null;
|
|
2018
2031
|
this.maxCallbacks = positiveBounded(options.maxCallbackEvents, MAX_CODEX_CALLBACKS, 4_096);
|
|
2019
2032
|
this.maxRoutes = positiveBounded(options.maxRoutes, MAX_CODEX_ROUTES, 256);
|
|
2020
2033
|
this.maxReplyBytes = positiveBounded(options.maxReplyBytes, MAX_TRANSIENT_REPLY_BYTES, 1024 * 1024);
|
|
@@ -2073,14 +2086,11 @@ export class LocalCodexGatewayProvider {
|
|
|
2073
2086
|
attestation.safeErrorCode ?? "CODEX_COMPATIBILITY_CHECK_FAILED";
|
|
2074
2087
|
return;
|
|
2075
2088
|
}
|
|
2076
|
-
const
|
|
2077
|
-
CODEX_APP_SERVER_WRITABLE_VERSIONS.includes(attestation.version) &&
|
|
2078
|
-
this.factory.writableReady &&
|
|
2079
|
-
this.factory.writeCompatibility !== null;
|
|
2089
|
+
const writesEnabled = codexFactoryWritesEnabled(this.factory, attestation, this.latestWriteCompatibilityProbeObservation(this.factory.endpointGeneration)?.outcome === "pass");
|
|
2080
2090
|
const schemaObserved = attestation.tier === "schema_attested" &&
|
|
2081
2091
|
!this.factory.writableReady &&
|
|
2082
2092
|
this.factory.writeCompatibility === null;
|
|
2083
|
-
if ((!
|
|
2093
|
+
if ((!writesEnabled && !schemaObserved) ||
|
|
2084
2094
|
(this.endpointUnavailable && pending === undefined) ||
|
|
2085
2095
|
!pendingMatches) {
|
|
2086
2096
|
throw new BridgeError("CODEX_COMPATIBILITY_ATTESTATION_MISMATCH", "The Codex compatibility attestation does not match this endpoint.");
|
|
@@ -2089,8 +2099,8 @@ export class LocalCodexGatewayProvider {
|
|
|
2089
2099
|
this.pendingEndpointRefreshEvent = undefined;
|
|
2090
2100
|
this.pendingEndpointRefreshSelectorClaimed = false;
|
|
2091
2101
|
this.clearEndpointActivationRetry();
|
|
2092
|
-
this.compatibilityAttested =
|
|
2093
|
-
this.endpointUnavailable = !
|
|
2102
|
+
this.compatibilityAttested = writesEnabled;
|
|
2103
|
+
this.endpointUnavailable = !writesEnabled;
|
|
2094
2104
|
this.compatibilityFailureCode = undefined;
|
|
2095
2105
|
}
|
|
2096
2106
|
releaseEndpointRefreshSelectorClaim(endpointGeneration) {
|
|
@@ -2113,6 +2123,9 @@ export class LocalCodexGatewayProvider {
|
|
|
2113
2123
|
return (this.writeProbeObservationsByGeneration.get(endpointGeneration) ??
|
|
2114
2124
|
(this.writeProbeOverflow?.endpointGeneration === endpointGeneration
|
|
2115
2125
|
? this.writeProbeOverflow.observation
|
|
2126
|
+
: undefined) ??
|
|
2127
|
+
(this.writeProbeDecline?.endpointGeneration === endpointGeneration
|
|
2128
|
+
? this.writeProbeDecline.observation
|
|
2116
2129
|
: undefined));
|
|
2117
2130
|
}
|
|
2118
2131
|
async runCompatibilityProbes(context) {
|
|
@@ -2217,10 +2230,13 @@ export class LocalCodexGatewayProvider {
|
|
|
2217
2230
|
if (cached !== undefined)
|
|
2218
2231
|
return await cached;
|
|
2219
2232
|
if (this.writeProbeOverflow?.key === key) {
|
|
2220
|
-
|
|
2233
|
+
if (this.writeProbeResults.size >= MAX_CODEX_WRITE_PROBE_ATTEMPTS) {
|
|
2234
|
+
return this.writeProbeOverflow.observation;
|
|
2235
|
+
}
|
|
2236
|
+
this.writeProbeOverflow = undefined;
|
|
2221
2237
|
}
|
|
2222
2238
|
if (this.writeProbeResults.size >= MAX_CODEX_WRITE_PROBE_ATTEMPTS) {
|
|
2223
|
-
const observation = Object.freeze(codexWriteProbeFailure("
|
|
2239
|
+
const observation = Object.freeze(codexWriteProbeFailure("CODEX_WRITE_PROBE_CAPACITY_EXHAUSTED"));
|
|
2224
2240
|
this.writeProbeOverflow = Object.freeze({
|
|
2225
2241
|
endpointGeneration: factory.endpointGeneration,
|
|
2226
2242
|
key,
|
|
@@ -2235,7 +2251,20 @@ export class LocalCodexGatewayProvider {
|
|
|
2235
2251
|
}
|
|
2236
2252
|
const pending = this.executeCodexWriteProbe(connector, context).then((result) => {
|
|
2237
2253
|
const observation = Object.freeze({ ...result });
|
|
2238
|
-
|
|
2254
|
+
if (observation.outcome === "fail" &&
|
|
2255
|
+
(observation.safeErrorCode ===
|
|
2256
|
+
"CODEX_WRITE_PROBE_MODEL_PIN_UNAVAILABLE" ||
|
|
2257
|
+
observation.safeErrorCode ===
|
|
2258
|
+
"CODEX_WRITE_PROBE_RATE_LIMIT_CONSTRAINED")) {
|
|
2259
|
+
this.writeProbeResults.delete(key);
|
|
2260
|
+
this.writeProbeDecline = Object.freeze({
|
|
2261
|
+
endpointGeneration: factory.endpointGeneration,
|
|
2262
|
+
observation,
|
|
2263
|
+
});
|
|
2264
|
+
}
|
|
2265
|
+
else {
|
|
2266
|
+
this.writeProbeObservationsByGeneration.set(factory.endpointGeneration, observation);
|
|
2267
|
+
}
|
|
2239
2268
|
if (observation.outcome === "fail" && this.callbacks !== undefined) {
|
|
2240
2269
|
invokeCallback(() => this.callbacks?.onProtocolNotice?.({
|
|
2241
2270
|
code: observation.safeErrorCode,
|
|
@@ -2366,7 +2395,7 @@ export class LocalCodexGatewayProvider {
|
|
|
2366
2395
|
safeErrorCode: this.compatibilityFailureCode,
|
|
2367
2396
|
};
|
|
2368
2397
|
}
|
|
2369
|
-
return this.
|
|
2398
|
+
return !this.compatibilityAttested
|
|
2370
2399
|
? {
|
|
2371
2400
|
health: "degraded",
|
|
2372
2401
|
compatibility: "compatible",
|
|
@@ -2550,10 +2579,6 @@ export class LocalCodexGatewayProvider {
|
|
|
2550
2579
|
route.endpointGeneration !== this.factory.endpointGeneration) {
|
|
2551
2580
|
return { state: "failed", safeErrorCode: "CODEX_ROUTE_UNAVAILABLE" };
|
|
2552
2581
|
}
|
|
2553
|
-
if (!this.factory.writableReady ||
|
|
2554
|
-
this.factory.writeCompatibility === null) {
|
|
2555
|
-
return { state: "failed", safeErrorCode: "CODEX_WRITES_DISABLED" };
|
|
2556
|
-
}
|
|
2557
2582
|
const guard = route.connector.guard();
|
|
2558
2583
|
if (!guard.writableReady) {
|
|
2559
2584
|
return { state: "failed", safeErrorCode: "CODEX_WRITES_DISABLED" };
|
|
@@ -2755,7 +2780,9 @@ export class LocalCodexGatewayProvider {
|
|
|
2755
2780
|
}
|
|
2756
2781
|
const admittedFactory = this.factory;
|
|
2757
2782
|
const creation = (async () => {
|
|
2758
|
-
const route = await this.createRoute(threadId, admittedFactory, queueInitialObservation
|
|
2783
|
+
const route = await this.createRoute(threadId, admittedFactory, queueInitialObservation, this.pendingEndpointAttestation === undefined
|
|
2784
|
+
? this.compatibilityAttested
|
|
2785
|
+
: codexFactoryWritesEnabled(admittedFactory, this.pendingEndpointAttestation, this.latestWriteCompatibilityProbeObservation(admittedFactory.endpointGeneration)?.outcome === "pass"));
|
|
2759
2786
|
if (this.closing || this.closed) {
|
|
2760
2787
|
await this.closeRoute(route);
|
|
2761
2788
|
throw new BridgeError("CODEX_PROVIDER_UNAVAILABLE", "The local Codex provider closed during route creation.");
|
|
@@ -2779,13 +2806,12 @@ export class LocalCodexGatewayProvider {
|
|
|
2779
2806
|
this.routeCreations.delete(threadId);
|
|
2780
2807
|
}
|
|
2781
2808
|
}
|
|
2782
|
-
async createRoute(threadId, factory, queueInitialObservation) {
|
|
2809
|
+
async createRoute(threadId, factory, queueInitialObservation, writesEnabled) {
|
|
2783
2810
|
let transport;
|
|
2784
2811
|
let connector;
|
|
2785
2812
|
const generation = Symbol(threadId);
|
|
2786
2813
|
try {
|
|
2787
2814
|
transport = await factory.connectTransport();
|
|
2788
|
-
const writesEnabled = factory.writableReady && factory.writeCompatibility !== null;
|
|
2789
2815
|
connector = await CodexAppServerConnector.connect({
|
|
2790
2816
|
compatibility: factory.writeCompatibility ?? factory.schemaCompatibility,
|
|
2791
2817
|
writesEnabled,
|
|
@@ -3053,7 +3079,7 @@ export class LocalCodexGatewayProvider {
|
|
|
3053
3079
|
if (this.closing || this.closed)
|
|
3054
3080
|
break;
|
|
3055
3081
|
try {
|
|
3056
|
-
const route = await this.createRoute(routeHandle, replacementFactory, false);
|
|
3082
|
+
const route = await this.createRoute(routeHandle, replacementFactory, false, codexFactoryWritesEnabled(replacementFactory, attestation, this.latestWriteCompatibilityProbeObservation(replacementFactory.endpointGeneration)?.outcome === "pass"));
|
|
3057
3083
|
if (this.closing || this.closed) {
|
|
3058
3084
|
await this.closeRoute(route);
|
|
3059
3085
|
break;
|