@opengeni/worker-bundle 2.3.1 → 2.3.2-canary.37090756480001
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/dist/activities/agent-turn/claude-usage-observer.d.ts +30 -6
- package/dist/activities/agent-turn/credential-leases.d.ts +5 -32
- package/dist/activities/agent-turn/errors.d.ts +3 -0
- package/dist/activities/agent-turn/finalization-monitor.d.ts +1 -1
- package/dist/activities/agent-turn/finalization.d.ts +2 -0
- package/dist/activities/agent-turn/quiescence.d.ts +3 -4
- package/dist/activities/agent-turn/subscription-lease.d.ts +38 -0
- package/dist/activities/agent-turn/turn-context.d.ts +1 -1
- package/dist/activities/model-call-fact-reconciler.d.ts +34 -0
- package/dist/activities/session-state.d.ts +2 -2
- package/dist/activities/types.d.ts +7 -0
- package/dist/{activities-control-3HAH4FMG.js → activities-control-3BY4IJKL.js} +166 -35
- package/dist/activities-control-3BY4IJKL.js.map +1 -0
- package/dist/activities-control.d.ts +6 -4
- package/dist/{activities-turn-KU25J3VQ.js → activities-turn-TTNAVGKN.js} +263 -308
- package/dist/activities-turn-TTNAVGKN.js.map +1 -0
- package/dist/activities.d.ts +6 -4
- package/dist/{chunk-3K3ULWEE.js → chunk-PA7Z55P4.js} +242 -17
- package/dist/chunk-PA7Z55P4.js.map +1 -0
- package/dist/{chunk-YG27NEMX.js → chunk-YOI3Z3GF.js} +9 -1
- package/dist/chunk-YOI3Z3GF.js.map +1 -0
- package/dist/http.d.ts +1 -1
- package/dist/index.d.ts +6 -2
- package/dist/index.js +82 -16
- package/dist/index.js.map +1 -1
- package/dist/observability-metrics.d.ts +6 -1
- package/dist/sandbox-resume.d.ts +3 -0
- package/dist/session-event-fanout.d.ts +6 -0
- package/dist/worker-service-lifecycle.d.ts +12 -0
- package/dist/workflow-bundle.js +3 -2
- package/package.json +21 -21
- package/src/activities/agent-turn/claim.ts +13 -0
- package/src/activities/agent-turn/claude-usage-observer.ts +99 -8
- package/src/activities/agent-turn/credential-leases.ts +86 -213
- package/src/activities/agent-turn/errors.ts +61 -1
- package/src/activities/agent-turn/failure-settlement.ts +59 -5
- package/src/activities/agent-turn/finalization-monitor.ts +3 -4
- package/src/activities/agent-turn/finalization.ts +8 -3
- package/src/activities/agent-turn/quiescence.ts +3 -4
- package/src/activities/agent-turn/run.ts +24 -20
- package/src/activities/agent-turn/sandbox-establish.ts +2 -0
- package/src/activities/agent-turn/sandbox-runtime.ts +5 -1
- package/src/activities/agent-turn/skill-selection.ts +2 -0
- package/src/activities/agent-turn/subscription-lease.ts +115 -0
- package/src/activities/agent-turn/turn-context.ts +1 -4
- package/src/activities/codex-rotation.ts +2 -12
- package/src/activities/model-call-fact-reconciler.ts +112 -0
- package/src/activities/sandbox-lease.ts +59 -8
- package/src/activities/session-state.ts +29 -4
- package/src/activities/types.ts +7 -0
- package/src/activities-control.ts +2 -0
- package/src/activities-turn.ts +5 -0
- package/src/activities.ts +7 -0
- package/src/http.ts +4 -2
- package/src/index.ts +39 -9
- package/src/observability-metrics.ts +27 -0
- package/src/sandbox-resume.ts +9 -0
- package/src/sandbox-routing.ts +77 -0
- package/src/session-event-fanout.ts +23 -0
- package/src/worker-service-lifecycle.ts +53 -0
- package/src/workflows/file-upload-reaper.ts +2 -0
- package/src/workflows/session.ts +6 -1
- package/dist/activities-control-3HAH4FMG.js.map +0 -1
- package/dist/activities-turn-KU25J3VQ.js.map +0 -1
- package/dist/chunk-3K3ULWEE.js.map +0 -1
- package/dist/chunk-YG27NEMX.js.map +0 -1
package/dist/activities.d.ts
CHANGED
|
@@ -85,6 +85,7 @@ export declare function createActivityTestHarness(dependencies?: ActivityDepende
|
|
|
85
85
|
}>;
|
|
86
86
|
enqueueGoalRetryWake: (input: import("./activities.js").MaybeContinueGoalInput) => Promise<void>;
|
|
87
87
|
maybeContinueGoal: (input: import("./activities.js").MaybeContinueGoalInput) => Promise<import("./activities.js").MaybeContinueGoalResult>;
|
|
88
|
+
reconcileRecentModelCallFacts: () => Promise<import("./activities/model-call-fact-reconciler.js").ReconcileRecentModelCallFactsResult>;
|
|
88
89
|
runKnowledgeSourceSyncBatch: (input: import("./activities.js").RunKnowledgeSourceSyncBatchInput) => Promise<import("./activities.js").RunKnowledgeSourceSyncBatchResult>;
|
|
89
90
|
maintainRetainedScreenshots: () => Promise<import("./activities/retained-screenshot-reaper.js").MaintainRetainedScreenshotsResult>;
|
|
90
91
|
verifyRigChange: (input: {
|
|
@@ -185,8 +186,8 @@ export declare function createActivityTestHarness(dependencies?: ActivityDepende
|
|
|
185
186
|
admissionFence?: import("@opengeni/db").SessionAdmissionFence;
|
|
186
187
|
} | {
|
|
187
188
|
kind: "admission-blocked";
|
|
188
|
-
reason?: "sandbox_setup_outcome_unknown";
|
|
189
|
-
ref?: import("@opengeni/db").SandboxSetupOutcomeUnknown;
|
|
189
|
+
reason?: "sandbox_setup_outcome_unknown" | "sandbox_setup_recovery_exhausted";
|
|
190
|
+
ref?: import("@opengeni/db").SandboxSetupOutcomeUnknown | import("@opengeni/db").SandboxSetupRecoveryExhausted;
|
|
190
191
|
} | {
|
|
191
192
|
kind: "sandbox-lifecycle-wait";
|
|
192
193
|
ref: import("@opengeni/db").SandboxLifecycleWait;
|
|
@@ -319,8 +320,8 @@ export declare const peekSessionWork: (input: import("./activities/types.js").Pe
|
|
|
319
320
|
admissionFence?: import("@opengeni/db").SessionAdmissionFence;
|
|
320
321
|
} | {
|
|
321
322
|
kind: "admission-blocked";
|
|
322
|
-
reason?: "sandbox_setup_outcome_unknown";
|
|
323
|
-
ref?: import("@opengeni/db").SandboxSetupOutcomeUnknown;
|
|
323
|
+
reason?: "sandbox_setup_outcome_unknown" | "sandbox_setup_recovery_exhausted";
|
|
324
|
+
ref?: import("@opengeni/db").SandboxSetupOutcomeUnknown | import("@opengeni/db").SandboxSetupRecoveryExhausted;
|
|
324
325
|
} | {
|
|
325
326
|
kind: "sandbox-lifecycle-wait";
|
|
326
327
|
ref: import("@opengeni/db").SandboxLifecycleWait;
|
|
@@ -413,6 +414,7 @@ export declare const recoverVideoGenerationWorkflows: () => Promise<{
|
|
|
413
414
|
}>;
|
|
414
415
|
export declare const maintainRetainedScreenshots: () => Promise<import("./activities/retained-screenshot-reaper.js").MaintainRetainedScreenshotsResult>;
|
|
415
416
|
export declare const maintainBrowserStateArtifacts: () => Promise<import("./activities/browser-state-artifact-reaper.js").MaintainBrowserStateArtifactsResult>;
|
|
417
|
+
export declare const reconcileRecentModelCallFacts: () => Promise<import("./activities/model-call-fact-reconciler.js").ReconcileRecentModelCallFactsResult>;
|
|
416
418
|
export declare const maintainSiteAuthConnections: () => Promise<import("./activities/site-auth-maintenance.js").MaintainSiteAuthConnectionsResult>;
|
|
417
419
|
export declare const dispatchSessionWorkflowWakes: () => Promise<import("./activities/workflow-wake.js").DispatchSessionWorkflowWakesResult>;
|
|
418
420
|
export declare const verifyRigChange: (input: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
observabilityEventBusOptions
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-YOI3Z3GF.js";
|
|
4
4
|
|
|
5
5
|
// src/activity-services.ts
|
|
6
6
|
import {
|
|
@@ -579,6 +579,7 @@ async function refreshExhaustedXaiQuota(input) {
|
|
|
579
579
|
}
|
|
580
580
|
|
|
581
581
|
// src/activities/codex-rotation.ts
|
|
582
|
+
import { subscriptionAccountShardIndex } from "@opengeni/config";
|
|
582
583
|
import { codexPlanExcludesModel, connectionModelAllowed } from "@opengeni/db";
|
|
583
584
|
function codexAccountServesModel(account, modelId, now) {
|
|
584
585
|
return connectionModelAllowed(account.allowedModelIds, modelId) && !codexPlanExcludesModel(account, modelId, now);
|
|
@@ -630,21 +631,13 @@ function isCodexCredentialHealthy(acct, now) {
|
|
|
630
631
|
function isCodexCredentialEligible(acct, now) {
|
|
631
632
|
return acct.allocatorEnabled && isCodexCredentialHealthy(acct, now);
|
|
632
633
|
}
|
|
633
|
-
function fnv1a32(input) {
|
|
634
|
-
let hash = 2166136261;
|
|
635
|
-
for (let i = 0; i < input.length; i++) {
|
|
636
|
-
hash ^= input.charCodeAt(i);
|
|
637
|
-
hash = Math.imul(hash, 16777619);
|
|
638
|
-
}
|
|
639
|
-
return hash >>> 0;
|
|
640
|
-
}
|
|
641
634
|
function shardCredentialForSession(args) {
|
|
642
635
|
const { sessionId, accounts, now } = args;
|
|
643
636
|
const eligibles = accounts.filter((acct) => isCodexCredentialEligible(acct, now));
|
|
644
637
|
if (eligibles.length === 0) {
|
|
645
638
|
return null;
|
|
646
639
|
}
|
|
647
|
-
const index =
|
|
640
|
+
const index = subscriptionAccountShardIndex(sessionId, eligibles.length);
|
|
648
641
|
return eligibles[index].id;
|
|
649
642
|
}
|
|
650
643
|
function chooseShardedHome(args) {
|
|
@@ -4953,6 +4946,18 @@ function warnDrainSnapshotFailure(observability, message, error, lease) {
|
|
|
4953
4946
|
}
|
|
4954
4947
|
}
|
|
4955
4948
|
|
|
4949
|
+
// src/session-event-fanout.ts
|
|
4950
|
+
async function publishDurableSessionEvents2(bus, workspaceId, events, onError = () => void 0) {
|
|
4951
|
+
if (!bus || !events?.length) return;
|
|
4952
|
+
for (const sessionId of new Set(events.map((event) => event.sessionId))) {
|
|
4953
|
+
await bus.publish(
|
|
4954
|
+
workspaceId,
|
|
4955
|
+
sessionId,
|
|
4956
|
+
events.filter((event) => event.sessionId === sessionId)
|
|
4957
|
+
).catch(onError);
|
|
4958
|
+
}
|
|
4959
|
+
}
|
|
4960
|
+
|
|
4956
4961
|
// src/sandbox-archive-storage.ts
|
|
4957
4962
|
import { uploadWorkspaceArchiveSpool } from "@opengeni/storage";
|
|
4958
4963
|
import { randomUUID as randomUUID2 } from "crypto";
|
|
@@ -5086,6 +5091,7 @@ async function deleteUnpublishedWorkspaceArchiveObject(objectStorage, ref, metri
|
|
|
5086
5091
|
}
|
|
5087
5092
|
|
|
5088
5093
|
// src/sandbox-routing.ts
|
|
5094
|
+
import { isDeepStrictEqual as isDeepStrictEqual3 } from "util";
|
|
5089
5095
|
import { sandboxLifecycleTransitionWaitMs as sandboxLifecycleTransitionWaitMs2 } from "@opengeni/config";
|
|
5090
5096
|
import {
|
|
5091
5097
|
createProviderCommandRetainer,
|
|
@@ -6476,6 +6482,11 @@ async function resumeBoxForTurnOnce(services, ids, kind, holderId) {
|
|
|
6476
6482
|
expectedBackend: ids.backend
|
|
6477
6483
|
});
|
|
6478
6484
|
if (marked.status === "marked") {
|
|
6485
|
+
await publishDurableSessionEvents2(
|
|
6486
|
+
services.bus,
|
|
6487
|
+
ids.workspaceId,
|
|
6488
|
+
marked.backgroundCommandEvents
|
|
6489
|
+
);
|
|
6479
6490
|
await services.onSandboxLost?.({
|
|
6480
6491
|
sandboxGroupId: ids.sandboxGroupId,
|
|
6481
6492
|
instanceId: live.instanceId,
|
|
@@ -6647,6 +6658,11 @@ async function resolveCurrentHomeBackend(services, ids, established) {
|
|
|
6647
6658
|
diagnostic: "provider_not_found_during_home_route_rebind"
|
|
6648
6659
|
});
|
|
6649
6660
|
if (marked.status === "marked") {
|
|
6661
|
+
await publishDurableSessionEvents2(
|
|
6662
|
+
services.bus,
|
|
6663
|
+
ids.workspaceId,
|
|
6664
|
+
marked.backgroundCommandEvents
|
|
6665
|
+
);
|
|
6650
6666
|
await services.onHomeSandboxLost?.({
|
|
6651
6667
|
sandboxGroupId: ids.sandboxGroupId,
|
|
6652
6668
|
instanceId: lease.instanceId,
|
|
@@ -6892,6 +6908,33 @@ function settleRetainedProcessForTurn(services, ids) {
|
|
|
6892
6908
|
}
|
|
6893
6909
|
};
|
|
6894
6910
|
}
|
|
6911
|
+
function isRetainedProcessSettledForTurn(services, ids) {
|
|
6912
|
+
const fence = ids.workspaceMutationFence;
|
|
6913
|
+
if (!fence) return void 0;
|
|
6914
|
+
return async ({
|
|
6915
|
+
backend,
|
|
6916
|
+
process: process2
|
|
6917
|
+
}) => {
|
|
6918
|
+
const durable = await getRetainedProcess(services.db, {
|
|
6919
|
+
workspaceId: ids.workspaceId,
|
|
6920
|
+
sessionId: ids.sessionId,
|
|
6921
|
+
processId: process2.id
|
|
6922
|
+
});
|
|
6923
|
+
if (!durable || durable.state === "active" || durable.providerSessionId !== process2.providerSessionId || durable.providerBackend !== (sandboxBackendForSdkBackendId(backend.kind) ?? backend.kind) || durable.providerInstanceId !== backend.providerInstanceId || durable.leaseEpoch !== backend.leaseEpoch || durable.routeKind !== (backend.sandboxId === null ? "home" : "active") || durable.routeTargetId !== backend.sandboxId || durable.routeEpoch !== backend.activeEpoch)
|
|
6924
|
+
return false;
|
|
6925
|
+
if (process2.providerCommand) {
|
|
6926
|
+
const command = await retainedProviderCommandPersistence(services.db, {
|
|
6927
|
+
accountId: fence.accountId,
|
|
6928
|
+
workspaceId: ids.workspaceId,
|
|
6929
|
+
sessionId: ids.sessionId,
|
|
6930
|
+
processId: process2.id
|
|
6931
|
+
}).load();
|
|
6932
|
+
if (!command || command.kind !== process2.providerCommand.kind || command.execId !== process2.providerCommand.execId || command.taskId !== process2.providerCommand.taskId || command.sandboxId !== process2.providerCommand.sandboxId || Boolean(command.pty) !== Boolean(process2.providerCommand.pty) || command.kind === "modal-router-v1" && process2.providerCommand.kind === "modal-router-v1" && !isDeepStrictEqual3(command.supervision, process2.providerCommand.supervision))
|
|
6933
|
+
return false;
|
|
6934
|
+
}
|
|
6935
|
+
return true;
|
|
6936
|
+
};
|
|
6937
|
+
}
|
|
6895
6938
|
function adoptRetainedProcessAsBackgroundCommandForTurn(services, ids) {
|
|
6896
6939
|
const fence = ids.workspaceMutationFence;
|
|
6897
6940
|
if (!fence) return void 0;
|
|
@@ -6934,6 +6977,7 @@ function wrapTurnBoxWithRouting(services, ids, established) {
|
|
|
6934
6977
|
const beforeProcessMutation = beforeRetainedProcessMutation(services, ids);
|
|
6935
6978
|
const afterProcessMutation = afterRetainedProcessMutation(services, ids);
|
|
6936
6979
|
const settleProcess = settleRetainedProcessForTurn(services, ids);
|
|
6980
|
+
const isProcessSettled = isRetainedProcessSettledForTurn(services, ids);
|
|
6937
6981
|
const adoptProcessAsBackgroundCommand = adoptRetainedProcessAsBackgroundCommandForTurn(
|
|
6938
6982
|
services,
|
|
6939
6983
|
ids
|
|
@@ -7106,6 +7150,7 @@ function wrapTurnBoxWithRouting(services, ids, established) {
|
|
|
7106
7150
|
...beforeProcessMutation ? { beforeProcessMutation } : {},
|
|
7107
7151
|
...afterProcessMutation ? { afterProcessMutation } : {},
|
|
7108
7152
|
...settleProcess ? { settleProcess } : {},
|
|
7153
|
+
...isProcessSettled ? { isProcessSettled } : {},
|
|
7109
7154
|
...ids.workspaceMutationFence ? { observeProcessTerminal: observeRetainedProcessTerminalForTurn(services, ids) } : {},
|
|
7110
7155
|
...ids.workspaceMutationFence ? { captureProcessOutput: captureRetainedProcessOutputForTurn(services, ids) } : {},
|
|
7111
7156
|
...adoptProcessAsBackgroundCommand ? { adoptProcessAsBackgroundCommand } : {},
|
|
@@ -7128,6 +7173,11 @@ function wrapTurnBoxWithRouting(services, ids, established) {
|
|
|
7128
7173
|
diagnostic: "provider_not_found_during_routed_operation"
|
|
7129
7174
|
});
|
|
7130
7175
|
if (marked.status === "marked") {
|
|
7176
|
+
await publishDurableSessionEvents2(
|
|
7177
|
+
services.bus,
|
|
7178
|
+
ids.workspaceId,
|
|
7179
|
+
marked.backgroundCommandEvents
|
|
7180
|
+
);
|
|
7131
7181
|
await services.onHomeSandboxLost?.({
|
|
7132
7182
|
sandboxGroupId: home.sandboxGroupId,
|
|
7133
7183
|
instanceId: expectedInstanceId,
|
|
@@ -7154,6 +7204,7 @@ function wrapLazyTurnBoxWithRouting(services, ids, args) {
|
|
|
7154
7204
|
const beforeProcessMutation = beforeRetainedProcessMutation(services, ids);
|
|
7155
7205
|
const afterProcessMutation = afterRetainedProcessMutation(services, ids);
|
|
7156
7206
|
const settleProcess = settleRetainedProcessForTurn(services, ids);
|
|
7207
|
+
const isProcessSettled = isRetainedProcessSettledForTurn(services, ids);
|
|
7157
7208
|
const adoptProcessAsBackgroundCommand = adoptRetainedProcessAsBackgroundCommandForTurn(
|
|
7158
7209
|
services,
|
|
7159
7210
|
ids
|
|
@@ -7310,6 +7361,7 @@ function wrapLazyTurnBoxWithRouting(services, ids, args) {
|
|
|
7310
7361
|
...beforeProcessMutation ? { beforeProcessMutation } : {},
|
|
7311
7362
|
...afterProcessMutation ? { afterProcessMutation } : {},
|
|
7312
7363
|
...settleProcess ? { settleProcess } : {},
|
|
7364
|
+
...isProcessSettled ? { isProcessSettled } : {},
|
|
7313
7365
|
...ids.workspaceMutationFence ? { observeProcessTerminal: observeRetainedProcessTerminalForTurn(services, ids) } : {},
|
|
7314
7366
|
...ids.workspaceMutationFence ? { captureProcessOutput: captureRetainedProcessOutputForTurn(services, ids) } : {},
|
|
7315
7367
|
...adoptProcessAsBackgroundCommand ? { adoptProcessAsBackgroundCommand } : {},
|
|
@@ -7333,6 +7385,11 @@ function wrapLazyTurnBoxWithRouting(services, ids, args) {
|
|
|
7333
7385
|
diagnostic: "provider_not_found_during_routed_operation"
|
|
7334
7386
|
});
|
|
7335
7387
|
if (marked.status === "marked") {
|
|
7388
|
+
await publishDurableSessionEvents2(
|
|
7389
|
+
services.bus,
|
|
7390
|
+
ids.workspaceId,
|
|
7391
|
+
marked.backgroundCommandEvents
|
|
7392
|
+
);
|
|
7336
7393
|
await services.onHomeSandboxLost?.({
|
|
7337
7394
|
sandboxGroupId: home.sandboxGroupId,
|
|
7338
7395
|
instanceId: backend.providerInstanceId,
|
|
@@ -7901,7 +7958,7 @@ import {
|
|
|
7901
7958
|
stableJson
|
|
7902
7959
|
} from "@opengeni/contracts";
|
|
7903
7960
|
import { createHash as createHash3 } from "crypto";
|
|
7904
|
-
import { isDeepStrictEqual as
|
|
7961
|
+
import { isDeepStrictEqual as isDeepStrictEqual4 } from "util";
|
|
7905
7962
|
var INCIDENT_TELEMETRY_AUTHORITY_FENCE_LINEAGE_KEY = "incidentTelemetryAuthorityFence";
|
|
7906
7963
|
function incidentTelemetryPreflightDeclaration(agentConfig, incidentTriggered) {
|
|
7907
7964
|
const rawConfig = agentConfig;
|
|
@@ -7934,7 +7991,7 @@ function evaluateIncidentTelemetryPreflight(input) {
|
|
|
7934
7991
|
return blocked("incident_preflight_metadata_missing");
|
|
7935
7992
|
}
|
|
7936
7993
|
if (preflight.requiredResources.some(
|
|
7937
|
-
(required) => !input.responder.resources.some((selected) =>
|
|
7994
|
+
(required) => !input.responder.resources.some((selected) => isDeepStrictEqual4(selected, required))
|
|
7938
7995
|
)) {
|
|
7939
7996
|
return blocked("incident_responder_under_capable");
|
|
7940
7997
|
}
|
|
@@ -8326,6 +8383,127 @@ async function checkpointHistoryBeforeProviderDispatch(historySink, route) {
|
|
|
8326
8383
|
}
|
|
8327
8384
|
}
|
|
8328
8385
|
|
|
8386
|
+
// src/activities/agent-turn/claude-usage-observer.ts
|
|
8387
|
+
import { createHash as createHash4 } from "crypto";
|
|
8388
|
+
import {
|
|
8389
|
+
emptyClaudeUsage,
|
|
8390
|
+
mergeClaudeUsage,
|
|
8391
|
+
parseClaudeUsageHeaders
|
|
8392
|
+
} from "@opengeni/config";
|
|
8393
|
+
var ClaudeSubscriptionConnectionUnavailable = class extends Error {
|
|
8394
|
+
status = 409;
|
|
8395
|
+
code = "claude_subscription_connection_changed";
|
|
8396
|
+
constructor() {
|
|
8397
|
+
super(
|
|
8398
|
+
"Claude connection changed or was disconnected. Start a new turn with the current connection."
|
|
8399
|
+
);
|
|
8400
|
+
}
|
|
8401
|
+
};
|
|
8402
|
+
async function createClaudeUsageObserver(providers, latest, readCredential) {
|
|
8403
|
+
const managedProviderIds = new Set(
|
|
8404
|
+
providers.filter(
|
|
8405
|
+
(provider) => provider.kind === "claude-subscription-workspace" || provider.kind === "claude-subscription-organization"
|
|
8406
|
+
).map((provider) => provider.id)
|
|
8407
|
+
);
|
|
8408
|
+
const bindings = await Promise.all(
|
|
8409
|
+
providers.filter(
|
|
8410
|
+
(provider) => provider.kind === "claude-subscription-workspace" || provider.kind === "claude-subscription-organization"
|
|
8411
|
+
).map(async (provider) => {
|
|
8412
|
+
const scope = provider.kind === "claude-subscription-workspace" ? "workspace" : "organization";
|
|
8413
|
+
const binding = provider.anthropic?.credentialBinding;
|
|
8414
|
+
if (binding && provider.apiKey)
|
|
8415
|
+
return [
|
|
8416
|
+
provider.id,
|
|
8417
|
+
{
|
|
8418
|
+
scope,
|
|
8419
|
+
token: provider.apiKey,
|
|
8420
|
+
expectedConnectionId: binding.connectionId,
|
|
8421
|
+
expectedCredentialVersion: binding.credentialVersion
|
|
8422
|
+
}
|
|
8423
|
+
];
|
|
8424
|
+
const credential = await readCredential(scope).catch(() => null);
|
|
8425
|
+
if (!credential || credential.token !== provider.apiKey) return null;
|
|
8426
|
+
return [
|
|
8427
|
+
provider.id,
|
|
8428
|
+
{
|
|
8429
|
+
scope,
|
|
8430
|
+
token: credential.token,
|
|
8431
|
+
expectedConnectionId: credential.connectionId,
|
|
8432
|
+
expectedCredentialVersion: credential.credentialVersion
|
|
8433
|
+
}
|
|
8434
|
+
];
|
|
8435
|
+
})
|
|
8436
|
+
);
|
|
8437
|
+
const captured = new Map(bindings.filter((binding) => binding !== null));
|
|
8438
|
+
const observeBinding = (binding, response, upstreamModelId, requestToken) => {
|
|
8439
|
+
if (requestToken === null) return;
|
|
8440
|
+
if (!binding) return;
|
|
8441
|
+
const { scope, ...capturedIdentity } = binding;
|
|
8442
|
+
const identity = { ...capturedIdentity, token: requestToken ?? capturedIdentity.token };
|
|
8443
|
+
const tokenKey = createHash4("sha256").update(identity.token).digest("hex");
|
|
8444
|
+
const captureKey = `${scope}:${identity.expectedConnectionId}:${identity.expectedCredentialVersion}:${tokenKey}`;
|
|
8445
|
+
const previous = latest.get(captureKey);
|
|
8446
|
+
let observation = parseClaudeUsageHeaders(response.headers, /* @__PURE__ */ new Date(), upstreamModelId);
|
|
8447
|
+
if (observation && previous?.observation) {
|
|
8448
|
+
const merged = mergeClaudeUsage(
|
|
8449
|
+
mergeClaudeUsage(emptyClaudeUsage(binding.expectedCredentialVersion), previous.observation),
|
|
8450
|
+
observation
|
|
8451
|
+
);
|
|
8452
|
+
observation = {
|
|
8453
|
+
windows: merged.windows,
|
|
8454
|
+
observedAt: merged.observedAt,
|
|
8455
|
+
source: merged.source,
|
|
8456
|
+
requestStatus: merged.requestStatus ?? null,
|
|
8457
|
+
requestRestrictions: merged.requestRestrictions ?? []
|
|
8458
|
+
};
|
|
8459
|
+
}
|
|
8460
|
+
if (observation || response.status === 401)
|
|
8461
|
+
latest.set(captureKey, {
|
|
8462
|
+
scope,
|
|
8463
|
+
...identity,
|
|
8464
|
+
...previous?.observation && !observation ? { observation: previous.observation } : {},
|
|
8465
|
+
...observation ? { observation } : {},
|
|
8466
|
+
...response.status === 401 ? { refresh: { status: "reconnect", checkedAt: (/* @__PURE__ */ new Date()).toISOString() } } : {}
|
|
8467
|
+
});
|
|
8468
|
+
};
|
|
8469
|
+
const observe = (providerId, response, upstreamModelId, requestToken) => observeBinding(captured.get(providerId), response, upstreamModelId, requestToken);
|
|
8470
|
+
const prepareRequestWithObserver = async (providerId, headers, resolve) => {
|
|
8471
|
+
if (!managedProviderIds.has(providerId)) return { headers, observe };
|
|
8472
|
+
const binding = captured.get(providerId);
|
|
8473
|
+
if (!binding) throw new ClaudeSubscriptionConnectionUnavailable();
|
|
8474
|
+
const credential = await resolve({
|
|
8475
|
+
scope: binding.scope,
|
|
8476
|
+
expectedConnectionId: binding.expectedConnectionId,
|
|
8477
|
+
expectedCredentialVersion: binding.expectedCredentialVersion
|
|
8478
|
+
});
|
|
8479
|
+
if (!credential || credential.connectionId !== binding.expectedConnectionId || credential.credentialVersion !== binding.expectedCredentialVersion)
|
|
8480
|
+
throw new ClaudeSubscriptionConnectionUnavailable();
|
|
8481
|
+
const dispatched = Object.freeze({ ...binding, token: credential.token });
|
|
8482
|
+
captured.set(providerId, dispatched);
|
|
8483
|
+
headers.set("authorization", `Bearer ${credential.token}`);
|
|
8484
|
+
headers.delete("x-api-key");
|
|
8485
|
+
return {
|
|
8486
|
+
headers,
|
|
8487
|
+
observe: (_providerId, response, upstreamModelId, requestToken) => observeBinding(dispatched, response, upstreamModelId, requestToken)
|
|
8488
|
+
};
|
|
8489
|
+
};
|
|
8490
|
+
return Object.assign(observe, {
|
|
8491
|
+
prepareRequestWithObserver,
|
|
8492
|
+
async prepareRequest(...args) {
|
|
8493
|
+
return (await prepareRequestWithObserver(...args)).headers;
|
|
8494
|
+
},
|
|
8495
|
+
binding(providerId) {
|
|
8496
|
+
const binding = captured.get(providerId);
|
|
8497
|
+
return binding ? { ...binding } : void 0;
|
|
8498
|
+
},
|
|
8499
|
+
renew(providerId, credential) {
|
|
8500
|
+
const binding = captured.get(providerId);
|
|
8501
|
+
if (binding && binding.expectedConnectionId === credential.connectionId && binding.expectedCredentialVersion === credential.credentialVersion)
|
|
8502
|
+
captured.set(providerId, { ...binding, token: credential.token });
|
|
8503
|
+
}
|
|
8504
|
+
});
|
|
8505
|
+
}
|
|
8506
|
+
|
|
8329
8507
|
// src/activities/agent-turn/sandbox-provision.ts
|
|
8330
8508
|
import {
|
|
8331
8509
|
SandboxLeaseRecoveryBlockedError as SandboxLeaseRecoveryBlockedError2,
|
|
@@ -8954,6 +9132,7 @@ import {
|
|
|
8954
9132
|
} from "@opengeni/db";
|
|
8955
9133
|
import {
|
|
8956
9134
|
ActiveBackendUnresolvableError as ActiveBackendUnresolvableError2,
|
|
9135
|
+
AnthropicProviderRejection,
|
|
8957
9136
|
CompactionProviderResponseError,
|
|
8958
9137
|
EmptyCompactionSummaryError,
|
|
8959
9138
|
compactionProviderRejection,
|
|
@@ -8962,6 +9141,7 @@ import {
|
|
|
8962
9141
|
isMcpTransportConnectivityError,
|
|
8963
9142
|
isModalTaskExecStartPreDispatchUnavailableError,
|
|
8964
9143
|
isModalCommandStartOutcomeUnknownError,
|
|
9144
|
+
isProviderCommandObservationUnavailableError,
|
|
8965
9145
|
isRoutingMutationOutcomeUnknownError,
|
|
8966
9146
|
RoutingWorkspaceRootChangedError,
|
|
8967
9147
|
ResponsesStreamingTerminalError,
|
|
@@ -8971,7 +9151,8 @@ import {
|
|
|
8971
9151
|
classifyProviderQuotaError,
|
|
8972
9152
|
providerQuotaExhaustedMessage,
|
|
8973
9153
|
SelfhostedWorkspaceRootChangedError,
|
|
8974
|
-
UNKNOWN_MODEL_FINISH_REASON_CODE
|
|
9154
|
+
UNKNOWN_MODEL_FINISH_REASON_CODE,
|
|
9155
|
+
AnthropicRequestError
|
|
8975
9156
|
} from "@opengeni/runtime";
|
|
8976
9157
|
import {
|
|
8977
9158
|
mcpTransportRequestFailureDiagnostic
|
|
@@ -8985,7 +9166,7 @@ import {
|
|
|
8985
9166
|
FileResourceRef,
|
|
8986
9167
|
resourceMountPath
|
|
8987
9168
|
} from "@opengeni/contracts";
|
|
8988
|
-
import { createHash as
|
|
9169
|
+
import { createHash as createHash5 } from "crypto";
|
|
8989
9170
|
import {
|
|
8990
9171
|
getActiveSessionHistoryItemsPaged,
|
|
8991
9172
|
getFilesForSubject,
|
|
@@ -9103,7 +9284,7 @@ async function modelAttachmentContentForFiles(files, readFileBytes, options = {}
|
|
|
9103
9284
|
});
|
|
9104
9285
|
continue;
|
|
9105
9286
|
}
|
|
9106
|
-
if (
|
|
9287
|
+
if (createHash5("sha256").update(bytes).digest("hex") !== checksum) {
|
|
9107
9288
|
console.error("model attachment checksum did not match finalized metadata", {
|
|
9108
9289
|
fileId: file.id
|
|
9109
9290
|
});
|
|
@@ -9772,7 +9953,9 @@ function retryableDatabaseFailureCode(error) {
|
|
|
9772
9953
|
function postClaimDatabaseRecoveryFailure(input) {
|
|
9773
9954
|
const code = retryableDatabaseFailureCode(input.error);
|
|
9774
9955
|
if (!code || input.executionGeneration < 1) return null;
|
|
9775
|
-
if (input.sandboxSetupOutcomeUnknown && input.providerRecovery)
|
|
9956
|
+
if (input.sandboxSetupOutcomeUnknown && input.sandboxSetupRecoveryExhausted || (input.sandboxSetupOutcomeUnknown || input.sandboxSetupRecoveryExhausted) && input.providerRecovery) {
|
|
9957
|
+
return null;
|
|
9958
|
+
}
|
|
9776
9959
|
if (input.providerRecovery && (!Number.isSafeInteger(input.providerRecovery.providerRecoveryCount) || input.providerRecovery.providerRecoveryCount <= 0 || input.providerRecovery.providerRecoveryCount > MAX_AUTOMATIC_PROVIDER_RECOVERIES || !/^[a-z][a-z0-9_]{0,63}$/.test(input.providerRecovery.failureCode))) {
|
|
9777
9960
|
return null;
|
|
9778
9961
|
}
|
|
@@ -9782,6 +9965,7 @@ function postClaimDatabaseRecoveryFailure(input) {
|
|
|
9782
9965
|
executionGeneration: input.executionGeneration,
|
|
9783
9966
|
code,
|
|
9784
9967
|
...input.sandboxSetupOutcomeUnknown ? { sandboxSetupOutcomeUnknown: true } : {},
|
|
9968
|
+
...input.sandboxSetupRecoveryExhausted ? { sandboxSetupRecoveryExhausted: true } : {},
|
|
9785
9969
|
...input.providerRecovery ? {
|
|
9786
9970
|
providerFailureCode: input.providerRecovery.failureCode,
|
|
9787
9971
|
providerRecoveryCount: input.providerRecovery.providerRecoveryCount
|
|
@@ -10101,11 +10285,31 @@ function findPostgresDriverError(error) {
|
|
|
10101
10285
|
function isRawDatabaseQueryError(error) {
|
|
10102
10286
|
return error instanceof Error && "query" in error && typeof error.query === "string" && "params" in error && Array.isArray(error.params);
|
|
10103
10287
|
}
|
|
10288
|
+
function anthropicRequestDiagnostic(error) {
|
|
10289
|
+
if (error instanceof AnthropicRequestError) return error;
|
|
10290
|
+
return error instanceof Error && error.cause instanceof AnthropicRequestError ? error.cause : void 0;
|
|
10291
|
+
}
|
|
10104
10292
|
function agentRunFailurePayload(error, options = {}) {
|
|
10105
10293
|
const failure = baseAgentRunFailurePayload(error, options);
|
|
10106
10294
|
const diagnostic = materializationVerificationDiagnostic(error);
|
|
10295
|
+
const anthropic = anthropicRequestDiagnostic(error);
|
|
10296
|
+
if (anthropic) {
|
|
10297
|
+
return {
|
|
10298
|
+
...failure,
|
|
10299
|
+
code: failure.code ?? anthropic.code,
|
|
10300
|
+
retryable: failure.retryable ?? false,
|
|
10301
|
+
...anthropic.detail ? { detail: anthropic.detail } : {},
|
|
10302
|
+
...anthropic.request_id ? { requestId: anthropic.request_id } : {}
|
|
10303
|
+
};
|
|
10304
|
+
}
|
|
10107
10305
|
return diagnostic ? { ...failure, materializationDiagnostic: diagnostic } : failure;
|
|
10108
10306
|
}
|
|
10307
|
+
function agentRunRecoveryFailurePayload(error, failure) {
|
|
10308
|
+
if (!anthropicRequestDiagnostic(error)) return failure;
|
|
10309
|
+
const recovery = { ...failure };
|
|
10310
|
+
delete recovery.detail;
|
|
10311
|
+
return recovery;
|
|
10312
|
+
}
|
|
10109
10313
|
function baseAgentRunFailurePayload(error, options = {}) {
|
|
10110
10314
|
if (error instanceof SandboxMaterializationVerificationError) {
|
|
10111
10315
|
return {
|
|
@@ -10140,6 +10344,17 @@ function baseAgentRunFailurePayload(error, options = {}) {
|
|
|
10140
10344
|
...Object.keys(database).length > 0 ? { database } : {}
|
|
10141
10345
|
};
|
|
10142
10346
|
}
|
|
10347
|
+
if (error instanceof ClaudeSubscriptionConnectionUnavailable) {
|
|
10348
|
+
return { error: error.message, code: error.code, retryable: false };
|
|
10349
|
+
}
|
|
10350
|
+
if (error instanceof AnthropicProviderRejection) {
|
|
10351
|
+
return {
|
|
10352
|
+
error: error.message,
|
|
10353
|
+
code: error.code === "content_policy_violation" ? "provider_safety_refusal" : error.code,
|
|
10354
|
+
retryable: false,
|
|
10355
|
+
...error.request_id ? { requestId: error.request_id } : {}
|
|
10356
|
+
};
|
|
10357
|
+
}
|
|
10143
10358
|
const safetyRefusalDiagnostic = providerSafetyRefusalDiagnostic(error);
|
|
10144
10359
|
if (safetyRefusalDiagnostic !== void 0) {
|
|
10145
10360
|
return {
|
|
@@ -10199,6 +10414,13 @@ function baseAgentRunFailurePayload(error, options = {}) {
|
|
|
10199
10414
|
retryable: true
|
|
10200
10415
|
};
|
|
10201
10416
|
}
|
|
10417
|
+
if (isProviderCommandObservationUnavailableError(error)) {
|
|
10418
|
+
return {
|
|
10419
|
+
error: "A managed sandbox command cannot be observed. Its exact invocation and writer remain retained; setup is blocked without replay until the incomplete operation can be reconciled.",
|
|
10420
|
+
code: "sandbox_command_observation_unavailable",
|
|
10421
|
+
retryable: false
|
|
10422
|
+
};
|
|
10423
|
+
}
|
|
10202
10424
|
if (isModalCommandStartOutcomeUnknownError(error)) {
|
|
10203
10425
|
return {
|
|
10204
10426
|
error: "A managed sandbox command has an unknown outcome. Its original invocation remains fenced; setup is blocked without replay until the incomplete operation can be reconciled.",
|
|
@@ -10483,6 +10705,7 @@ export {
|
|
|
10483
10705
|
startActivityHeartbeat,
|
|
10484
10706
|
nextStreamEvent,
|
|
10485
10707
|
warnDrainSnapshotFailure,
|
|
10708
|
+
publishDurableSessionEvents2 as publishDurableSessionEvents,
|
|
10486
10709
|
persistWorkspaceArchiveCandidate,
|
|
10487
10710
|
putVersion1TarArchiveOrInline,
|
|
10488
10711
|
sandboxLeaseHolderIdForAttempt,
|
|
@@ -10513,6 +10736,7 @@ export {
|
|
|
10513
10736
|
resolveIncidentTelemetryResponderMetadata,
|
|
10514
10737
|
validateIncidentTelemetrySystemUpdateAuthority,
|
|
10515
10738
|
checkpointHistoryBeforeProviderDispatch,
|
|
10739
|
+
createClaudeUsageObserver,
|
|
10516
10740
|
projectRejectedProviderArtifacts,
|
|
10517
10741
|
createModelHistoryAttachmentProjector,
|
|
10518
10742
|
turnInput,
|
|
@@ -10570,9 +10794,10 @@ export {
|
|
|
10570
10794
|
classifyContextWindowOverflowError,
|
|
10571
10795
|
classifyXaiCredentialFailure,
|
|
10572
10796
|
agentRunFailurePayload,
|
|
10797
|
+
agentRunRecoveryFailurePayload,
|
|
10573
10798
|
codexCredentialCooldownUntil,
|
|
10574
10799
|
classifyCodexCredentialFailure,
|
|
10575
10800
|
codexUsageLimitFailurePayload,
|
|
10576
10801
|
CODEX_USAGE_LIMIT_MAX_RESUME_MS
|
|
10577
10802
|
};
|
|
10578
|
-
//# sourceMappingURL=chunk-
|
|
10803
|
+
//# sourceMappingURL=chunk-PA7Z55P4.js.map
|