@opengeni/worker-bundle 1.0.2 → 1.1.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/dist/activities/agent-run-admission.d.ts +1 -14
- package/dist/activities/agent-turn/errors.d.ts +3 -0
- package/dist/activities/agent-turn/provider-recovery-metrics.d.ts +18 -0
- package/dist/activities/agent-turn/turn-context.d.ts +5 -0
- package/dist/activities/goals.d.ts +1 -17
- package/dist/activities/types.d.ts +1 -1
- package/dist/{activities-control-BNPTRTOE.js → activities-control-XZAIMFQJ.js} +23 -7
- package/dist/activities-control-XZAIMFQJ.js.map +1 -0
- package/dist/{activities-turn-5LGZOSVU.js → activities-turn-4EEVNZCC.js} +97 -5
- package/dist/activities-turn-4EEVNZCC.js.map +1 -0
- package/dist/{chunk-LJX7Z2KP.js → chunk-OT64XARC.js} +38 -162
- package/dist/chunk-OT64XARC.js.map +1 -0
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/workflow-bundle.js +1 -1
- package/package.json +21 -21
- package/src/activities/agent-run-admission.ts +1 -98
- package/src/activities/agent-turn/claim.ts +11 -0
- package/src/activities/agent-turn/compaction-prep.ts +15 -0
- package/src/activities/agent-turn/errors.ts +30 -15
- package/src/activities/agent-turn/failure-settlement.ts +22 -0
- package/src/activities/agent-turn/provider-recovery-metrics.ts +64 -0
- package/src/activities/agent-turn/stream-attempt.ts +10 -0
- package/src/activities/agent-turn/tool-environment.ts +9 -2
- package/src/activities/agent-turn/turn-context.ts +4 -0
- package/src/activities/goals.ts +17 -113
- package/src/activities/scheduled-tasks.ts +18 -3
- package/src/activities/types.ts +1 -0
- package/src/index.ts +0 -2
- package/dist/activities-control-BNPTRTOE.js.map +0 -1
- package/dist/activities-turn-5LGZOSVU.js.map +0 -1
- package/dist/chunk-LJX7Z2KP.js.map +0 -1
|
@@ -1235,109 +1235,25 @@ function createDocumentActivities(services, resolveDocumentServices) {
|
|
|
1235
1235
|
// src/activities/goals.ts
|
|
1236
1236
|
import {
|
|
1237
1237
|
allowedFirstPartyMcpToolsForSession,
|
|
1238
|
-
|
|
1239
|
-
isModelAvailableForNewSelection,
|
|
1240
|
-
policyProviderIdForModel,
|
|
1241
|
-
resolveModelProvider,
|
|
1242
|
-
resolveTurnExecutionPolicyV1,
|
|
1243
|
-
withCodexCatalogProvider,
|
|
1244
|
-
withXaiSubscriptionCatalogProvider,
|
|
1245
|
-
WORKSPACE_GATEWAY_MODEL_ID_PREFIX,
|
|
1246
|
-
WORKSPACE_OPENROUTER_MODEL_ID_PREFIX
|
|
1238
|
+
resolveTurnExecutionPolicyV1
|
|
1247
1239
|
} from "@opengeni/config";
|
|
1248
1240
|
import {
|
|
1249
|
-
evaluateWorkspaceModelPolicy,
|
|
1250
1241
|
mergeToolRefs,
|
|
1251
1242
|
readTurnExecutionPolicyV1 as readTurnExecutionPolicyV12
|
|
1252
1243
|
} from "@opengeni/contracts";
|
|
1253
|
-
import { isCodexBilledModel } from "@opengeni/codex";
|
|
1254
1244
|
import {
|
|
1255
1245
|
enqueueSessionWorkflowWakeIfRunnable,
|
|
1256
|
-
getWorkspaceModelPolicy,
|
|
1257
1246
|
getSessionGoal,
|
|
1258
1247
|
getSessionTurn,
|
|
1259
1248
|
materializeGoalContinuation,
|
|
1260
1249
|
requireSession
|
|
1261
1250
|
} from "@opengeni/db";
|
|
1262
1251
|
import {
|
|
1263
|
-
modelFundingForAdmission
|
|
1264
|
-
|
|
1265
|
-
|
|
1252
|
+
modelFundingForAdmission,
|
|
1253
|
+
goalRunBudgetBlocked,
|
|
1254
|
+
resolveGoalModelAdmission
|
|
1266
1255
|
} from "@opengeni/core";
|
|
1267
|
-
|
|
1268
|
-
// src/activities/agent-run-admission.ts
|
|
1269
|
-
import { configuredStaticUsageLimits } from "@opengeni/config";
|
|
1270
|
-
import { modelFundingForAdmission } from "@opengeni/core";
|
|
1271
|
-
import {
|
|
1272
|
-
checkWorkspaceAllowance,
|
|
1273
|
-
getBillingBalance,
|
|
1274
|
-
isCodexBilledTurn,
|
|
1275
|
-
sumUsageQuantity
|
|
1276
|
-
} from "@opengeni/db";
|
|
1277
|
-
async function agentRunAdmissionDenial(services, input) {
|
|
1278
|
-
const codexBilled = await isCodexBilledTurn({
|
|
1279
|
-
db: services.db,
|
|
1280
|
-
settings: services.settings,
|
|
1281
|
-
workspaceId: input.workspaceId,
|
|
1282
|
-
model: input.model
|
|
1283
|
-
});
|
|
1284
|
-
const externallyBilled = modelFundingForAdmission(
|
|
1285
|
-
services.settings,
|
|
1286
|
-
input.model,
|
|
1287
|
-
codexBilled
|
|
1288
|
-
).fundedWithoutCredits;
|
|
1289
|
-
if (!externallyBilled && (services.settings.billingMode === "stripe" || services.settings.usageLimitsMode === "managed")) {
|
|
1290
|
-
if (services.entitlements) {
|
|
1291
|
-
const decision = await services.entitlements.admitRun({
|
|
1292
|
-
accountId: input.accountId,
|
|
1293
|
-
workspaceId: input.workspaceId,
|
|
1294
|
-
action: "agent_run:create",
|
|
1295
|
-
quantity: input.requestedAgentRuns
|
|
1296
|
-
});
|
|
1297
|
-
if (!decision.allowed) return "insufficient_credits";
|
|
1298
|
-
} else {
|
|
1299
|
-
const balance = await getBillingBalance(services.db, input.accountId);
|
|
1300
|
-
if (balance.balanceMicros <= 0) return "insufficient_credits";
|
|
1301
|
-
}
|
|
1302
|
-
}
|
|
1303
|
-
if (!externallyBilled) {
|
|
1304
|
-
const refusal = await checkWorkspaceAllowance(services.db, {
|
|
1305
|
-
accountId: input.accountId,
|
|
1306
|
-
workspaceId: input.workspaceId,
|
|
1307
|
-
subjectId: input.initiatingHumanSubjectId ?? null
|
|
1308
|
-
});
|
|
1309
|
-
if (refusal) return refusal.code;
|
|
1310
|
-
}
|
|
1311
|
-
if (services.settings.usageLimitsMode !== "static" && services.settings.usageLimitsMode !== "managed") {
|
|
1312
|
-
return null;
|
|
1313
|
-
}
|
|
1314
|
-
const limits = configuredStaticUsageLimits(services.settings);
|
|
1315
|
-
if (!externallyBilled && limits.maxMonthlyCostMicrosPerAccount) {
|
|
1316
|
-
const used = await sumUsageQuantity(services.db, {
|
|
1317
|
-
accountId: input.accountId,
|
|
1318
|
-
eventType: "model.cost",
|
|
1319
|
-
since: startOfUtcMonth()
|
|
1320
|
-
});
|
|
1321
|
-
if (used >= limits.maxMonthlyCostMicrosPerAccount) {
|
|
1322
|
-
return "monthly_model_cost_limit";
|
|
1323
|
-
}
|
|
1324
|
-
}
|
|
1325
|
-
if (limits.maxMonthlyAgentRunsPerWorkspace) {
|
|
1326
|
-
const used = await sumUsageQuantity(services.db, {
|
|
1327
|
-
workspaceId: input.workspaceId,
|
|
1328
|
-
eventType: "agent_run.created",
|
|
1329
|
-
since: startOfUtcMonth()
|
|
1330
|
-
});
|
|
1331
|
-
if (used + input.requestedAgentRuns > limits.maxMonthlyAgentRunsPerWorkspace) {
|
|
1332
|
-
return "monthly_agent_run_limit";
|
|
1333
|
-
}
|
|
1334
|
-
}
|
|
1335
|
-
return null;
|
|
1336
|
-
}
|
|
1337
|
-
function startOfUtcMonth() {
|
|
1338
|
-
const now = /* @__PURE__ */ new Date();
|
|
1339
|
-
return new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1));
|
|
1340
|
-
}
|
|
1256
|
+
import { goalContinuationModelDecision, goalRunBudgetBlocked as goalRunBudgetBlocked2 } from "@opengeni/core";
|
|
1341
1257
|
|
|
1342
1258
|
// src/activities/agent-turn/credential-restriction.ts
|
|
1343
1259
|
import { readTurnExecutionPolicyV1 } from "@opengeni/contracts";
|
|
@@ -1373,29 +1289,18 @@ function createGoalActivities(services) {
|
|
|
1373
1289
|
if (session.status === "failed" || session.status === "cancelled") {
|
|
1374
1290
|
return { action: "none" };
|
|
1375
1291
|
}
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1292
|
+
const modelDecision = await resolveGoalModelAdmission(db, catalogSourceSettings, {
|
|
1293
|
+
accountId: input.accountId,
|
|
1294
|
+
workspaceId: input.workspaceId,
|
|
1295
|
+
model: session.model,
|
|
1296
|
+
codexCompactionMode: session.codexCompactionMode,
|
|
1297
|
+
latencyMode: session.latencyMode
|
|
1298
|
+
});
|
|
1299
|
+
const settings = modelDecision.settings;
|
|
1300
|
+
const continuationModel = modelDecision.model;
|
|
1379
1301
|
const continuationReasoningEffort = session.reasoningEffort;
|
|
1380
1302
|
const continuationLatencyMode = session.latencyMode;
|
|
1381
|
-
const
|
|
1382
|
-
if (inheritedContinuationModel.startsWith(WORKSPACE_GATEWAY_MODEL_ID_PREFIX) || inheritedContinuationModel.startsWith(WORKSPACE_OPENROUTER_MODEL_ID_PREFIX) || session.model.startsWith(WORKSPACE_GATEWAY_MODEL_ID_PREFIX) || session.model.startsWith(WORKSPACE_OPENROUTER_MODEL_ID_PREFIX)) {
|
|
1383
|
-
settings = (await resolveWorkspaceCatalogSettings(db, catalogSourceSettings, {
|
|
1384
|
-
accountId: input.accountId,
|
|
1385
|
-
workspaceId: input.workspaceId,
|
|
1386
|
-
retainedProductModelIds: [inheritedContinuationModel, session.model]
|
|
1387
|
-
})).settings;
|
|
1388
|
-
}
|
|
1389
|
-
const modelDecision = goalContinuationModelDecision({
|
|
1390
|
-
settings,
|
|
1391
|
-
workspaceModelPolicy,
|
|
1392
|
-
inheritedModel: inheritedContinuationModel
|
|
1393
|
-
});
|
|
1394
|
-
continuationModel = modelDecision.model;
|
|
1395
|
-
let modelPolicyBlocked = modelDecision.blocked;
|
|
1396
|
-
if (!modelPolicyBlocked && session.codexCompactionMode === "remote_v2" && !isCodexBilledModel(continuationModel)) {
|
|
1397
|
-
modelPolicyBlocked = `session is locked to Codex remote compaction v2; model "${continuationModel}" is not a Codex subscription model`;
|
|
1398
|
-
}
|
|
1303
|
+
const modelPolicyBlocked = modelDecision.blocked;
|
|
1399
1304
|
const turnExecutionPolicy = modelPolicyBlocked ? void 0 : resolveTurnExecutionPolicyV1(settings, {
|
|
1400
1305
|
modelId: continuationModel,
|
|
1401
1306
|
requestedModelId: null,
|
|
@@ -1450,9 +1355,10 @@ function createGoalActivities(services) {
|
|
|
1450
1355
|
initiatingHumanSubjectId: causalTurn?.initiatingHumanSubjectId ?? null
|
|
1451
1356
|
}
|
|
1452
1357
|
);
|
|
1358
|
+
const pausedReason = modelPolicyBlocked ? modelDecision.pausedReason : budgetBlocked?.pausedReason;
|
|
1453
1359
|
return {
|
|
1454
1360
|
budgetBlocked: modelPolicyBlocked ?? budgetBlocked?.message ?? null,
|
|
1455
|
-
|
|
1361
|
+
...pausedReason ? { budgetPausedReason: pausedReason } : {}
|
|
1456
1362
|
};
|
|
1457
1363
|
},
|
|
1458
1364
|
policy: continuationPolicy,
|
|
@@ -1483,34 +1389,6 @@ function createGoalActivities(services) {
|
|
|
1483
1389
|
maybeContinueGoal
|
|
1484
1390
|
};
|
|
1485
1391
|
}
|
|
1486
|
-
function goalContinuationModelDecision(input) {
|
|
1487
|
-
const catalogSettings = input.settings.supergrokSubscriptionEnabled ? withXaiSubscriptionCatalogProvider(
|
|
1488
|
-
input.settings.codexSubscriptionEnabled ? withCodexCatalogProvider(input.settings) : input.settings
|
|
1489
|
-
) : input.settings.codexSubscriptionEnabled ? withCodexCatalogProvider(input.settings) : input.settings;
|
|
1490
|
-
const policyBlocks = (modelId) => input.workspaceModelPolicy !== null && !evaluateWorkspaceModelPolicy(input.workspaceModelPolicy, {
|
|
1491
|
-
providerId: policyProviderIdForModel(catalogSettings, modelId),
|
|
1492
|
-
modelId
|
|
1493
|
-
}).allowed;
|
|
1494
|
-
if (!resolveModelProvider(catalogSettings, input.inheritedModel)) {
|
|
1495
|
-
return {
|
|
1496
|
-
model: input.inheritedModel,
|
|
1497
|
-
blocked: `model "${input.inheritedModel}" is no longer in the deployment or workspace catalog; choose an available model before resuming the goal`
|
|
1498
|
-
};
|
|
1499
|
-
}
|
|
1500
|
-
if (!isModelAvailableForNewSelection(catalogSettings, input.inheritedModel)) {
|
|
1501
|
-
return {
|
|
1502
|
-
model: input.inheritedModel,
|
|
1503
|
-
blocked: `model "${input.inheritedModel}" is retired from new selection; choose an available model before resuming the goal`
|
|
1504
|
-
};
|
|
1505
|
-
}
|
|
1506
|
-
if (!policyBlocks(input.inheritedModel)) {
|
|
1507
|
-
return { model: input.inheritedModel, blocked: null };
|
|
1508
|
-
}
|
|
1509
|
-
return {
|
|
1510
|
-
model: input.inheritedModel,
|
|
1511
|
-
blocked: `workspace model policy blocks model "${input.inheritedModel}"; pick an allowed model or change the workspace model policy`
|
|
1512
|
-
};
|
|
1513
|
-
}
|
|
1514
1392
|
function goalContinuationPrompt(_goal, _autoContinuation, _cap, options = {}) {
|
|
1515
1393
|
const waitingGuidance = options.inputWaitAvailable ? [
|
|
1516
1394
|
"Waiting on child sessions, background commands, or external events:",
|
|
@@ -1587,20 +1465,6 @@ function withFirstPartyTools(settings, tools) {
|
|
|
1587
1465
|
}
|
|
1588
1466
|
return mergeToolRefs(tools, [{ kind: "mcp", id: "opengeni" }]);
|
|
1589
1467
|
}
|
|
1590
|
-
async function goalRunBudgetBlocked(services, input) {
|
|
1591
|
-
const denial = await agentRunAdmissionDenial(services, { ...input, requestedAgentRuns: 1 });
|
|
1592
|
-
if (denial === null) return null;
|
|
1593
|
-
if (denial === "allowance_exhausted") {
|
|
1594
|
-
return { pausedReason: "allowance", message: "Opengeni usage allowance exhausted" };
|
|
1595
|
-
}
|
|
1596
|
-
const limits = configuredStaticUsageLimits2(services.settings);
|
|
1597
|
-
const messages = {
|
|
1598
|
-
insufficient_credits: "insufficient Opengeni credits",
|
|
1599
|
-
monthly_model_cost_limit: `monthly model cost limit reached (${limits.maxMonthlyCostMicrosPerAccount} micros)`,
|
|
1600
|
-
monthly_agent_run_limit: `monthly agent run limit reached (${limits.maxMonthlyAgentRunsPerWorkspace})`
|
|
1601
|
-
};
|
|
1602
|
-
return { pausedReason: "limits", message: messages[denial] };
|
|
1603
|
-
}
|
|
1604
1468
|
|
|
1605
1469
|
// src/activities/knowledge-source-sync.ts
|
|
1606
1470
|
import {
|
|
@@ -9903,6 +9767,10 @@ var PROVIDER_BACKPRESSURE_DELAY_MS = 6e4;
|
|
|
9903
9767
|
var PROVIDER_CONNECTIVITY_BACKOFF_MS = [2e3, 5e3, 15e3, 3e4, 6e4];
|
|
9904
9768
|
var MAX_AUTOMATIC_PROVIDER_RECOVERIES = PROVIDER_CONNECTIVITY_BACKOFF_MS.length;
|
|
9905
9769
|
var PROVIDER_RATE_LIMIT_BACKOFF_MS = [1e4, 2e4, 4e4, 6e4, 12e4];
|
|
9770
|
+
function providerRecoveryJitterMs(delayMs, sample) {
|
|
9771
|
+
const bounded = Number.isFinite(sample) ? Math.max(0, Math.min(sample, 1)) : 0;
|
|
9772
|
+
return Math.floor(Math.min(5e3, delayMs * 0.2) * bounded);
|
|
9773
|
+
}
|
|
9906
9774
|
var POST_COMPACTION_CONTINUATION_EMPTY_CODE = "post_compaction_continuation_empty";
|
|
9907
9775
|
var PostCompactionContinuationEmptyError = class extends Error {
|
|
9908
9776
|
code = POST_COMPACTION_CONTINUATION_EMPTY_CODE;
|
|
@@ -9935,7 +9803,7 @@ function providerRecoveryResult(input) {
|
|
|
9935
9803
|
) : PROVIDER_BACKPRESSURE_DELAY_MS;
|
|
9936
9804
|
return {
|
|
9937
9805
|
status: "recovering",
|
|
9938
|
-
continueDelayMs
|
|
9806
|
+
continueDelayMs: continueDelayMs + (input.failureCode === "provider_rate_limited" || input.failureCode === "provider_unavailable" || input.failureCode === "upstream_connectivity_unavailable" ? providerRecoveryJitterMs(continueDelayMs, input.jitterSample ?? 0) : 0)
|
|
9939
9807
|
};
|
|
9940
9808
|
}
|
|
9941
9809
|
function providerRecoveryExhaustedFailure(failure, recovery) {
|
|
@@ -10402,14 +10270,25 @@ function providerSafetyRefusalDiagnostic(error) {
|
|
|
10402
10270
|
function isProviderSafetyRefusal(error) {
|
|
10403
10271
|
return providerSafetyRefusalDiagnostic(error) !== void 0;
|
|
10404
10272
|
}
|
|
10273
|
+
function providerHttpStatus(error) {
|
|
10274
|
+
let current = error;
|
|
10275
|
+
const seen = /* @__PURE__ */ new Set();
|
|
10276
|
+
for (let depth = 0; depth < 6 && current && typeof current === "object"; depth += 1) {
|
|
10277
|
+
if (seen.has(current)) break;
|
|
10278
|
+
seen.add(current);
|
|
10279
|
+
const value = current;
|
|
10280
|
+
const status = Number(value.status ?? value.statusCode);
|
|
10281
|
+
if (Number.isInteger(status) && status >= 100 && status < 600) return status;
|
|
10282
|
+
current = value.cause;
|
|
10283
|
+
}
|
|
10284
|
+
return void 0;
|
|
10285
|
+
}
|
|
10405
10286
|
function isTransientProviderError(error) {
|
|
10406
10287
|
if (error instanceof ResponsesStreamingTerminalError) {
|
|
10407
10288
|
return error.category === "unavailable";
|
|
10408
10289
|
}
|
|
10409
10290
|
if (isProviderSafetyRefusal(error)) return false;
|
|
10410
|
-
const status =
|
|
10411
|
-
error.status ?? error.statusCode
|
|
10412
|
-
) : void 0;
|
|
10291
|
+
const status = providerHttpStatus(error);
|
|
10413
10292
|
if (status !== void 0 && Number.isFinite(status)) {
|
|
10414
10293
|
return status >= 500 && status < 600;
|
|
10415
10294
|
}
|
|
@@ -10592,9 +10471,7 @@ function baseAgentRunFailurePayload(error, options = {}) {
|
|
|
10592
10471
|
};
|
|
10593
10472
|
}
|
|
10594
10473
|
const message = error instanceof Error ? error.message : String(error);
|
|
10595
|
-
const status =
|
|
10596
|
-
error.status ?? error.statusCode
|
|
10597
|
-
) : void 0;
|
|
10474
|
+
const status = providerHttpStatus(error);
|
|
10598
10475
|
const code = typeof error === "object" && error !== null && "code" in error ? String(error.code) : void 0;
|
|
10599
10476
|
if (error instanceof ActiveSessionHistoryLimitExceededError) {
|
|
10600
10477
|
return {
|
|
@@ -10928,7 +10805,6 @@ export {
|
|
|
10928
10805
|
signalPendingCodexCapacityWakeTargets,
|
|
10929
10806
|
armAndReconcileCodexCapacityWait,
|
|
10930
10807
|
createCodexCapacityActivities,
|
|
10931
|
-
agentRunAdmissionDenial,
|
|
10932
10808
|
createDocumentActivities,
|
|
10933
10809
|
turnCredentialRestriction,
|
|
10934
10810
|
createGoalActivities,
|
|
@@ -11037,4 +10913,4 @@ export {
|
|
|
11037
10913
|
CODEX_USAGE_LIMIT_MAX_RESUME_MS,
|
|
11038
10914
|
classifyClaudeCredentialFailure
|
|
11039
10915
|
};
|
|
11040
|
-
//# sourceMappingURL=chunk-
|
|
10916
|
+
//# sourceMappingURL=chunk-OT64XARC.js.map
|