@opengeni/worker-bundle 2.2.0-canary.36844267522001 → 2.2.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 -3
- package/dist/activities/agent-turn/admission.d.ts +3 -24
- package/dist/activities/agent-turn/claude-usage-observer.d.ts +1 -13
- package/dist/activities/agent-turn/run-credentials.d.ts +0 -2
- package/dist/activities/agent-turn/stream-attempt.d.ts +0 -1
- package/dist/activities/agent-turn/turn-context.d.ts +0 -1
- package/dist/activities/goals.d.ts +0 -8
- package/dist/activities/run-credentials.d.ts +2 -4
- package/dist/activities/types.d.ts +1 -1
- package/dist/{activities-control-KQ5OK2GD.js → activities-control-MHNA3CYV.js} +66 -28
- package/dist/activities-control-MHNA3CYV.js.map +1 -0
- package/dist/{activities-turn-LSRAUGEK.js → activities-turn-FQ5OO2WW.js} +195 -459
- package/dist/activities-turn-FQ5OO2WW.js.map +1 -0
- package/dist/{chunk-WADNTBZZ.js → chunk-RZAAGRFQ.js} +64 -109
- package/dist/chunk-RZAAGRFQ.js.map +1 -0
- package/dist/index.js +1 -1
- package/dist/workflow-bundle.js +1 -1
- package/package.json +20 -20
- package/src/activities/agent-run-admission.ts +1 -17
- package/src/activities/agent-turn/admission.ts +1 -64
- package/src/activities/agent-turn/claim.ts +14 -56
- package/src/activities/agent-turn/claude-usage-observer.ts +1 -33
- package/src/activities/agent-turn/failure-settlement.ts +0 -5
- package/src/activities/agent-turn/run-credentials.ts +3 -15
- package/src/activities/agent-turn/run.ts +3 -32
- package/src/activities/agent-turn/stream-attempt.ts +32 -58
- package/src/activities/agent-turn/tool-environment.ts +20 -13
- package/src/activities/agent-turn/turn-context.ts +0 -1
- package/src/activities/capabilities.ts +14 -52
- package/src/activities/goals.ts +78 -36
- package/src/activities/knowledge-indexing.ts +0 -29
- package/src/activities/run-credentials.ts +16 -22
- package/src/activities/scheduled-tasks.ts +0 -1
- package/src/activities/types.ts +0 -1
- package/src/activities/workspace-credential-provider.ts +0 -12
- package/dist/activities/agent-turn/model-call-admission.d.ts +0 -15
- package/dist/activities-control-KQ5OK2GD.js.map +0 -1
- package/dist/activities-turn-LSRAUGEK.js.map +0 -1
- package/dist/chunk-WADNTBZZ.js.map +0 -1
- package/src/activities/agent-turn/model-call-admission.ts +0 -94
|
@@ -1242,7 +1242,7 @@ function createDocumentActivities(services, resolveDocumentServices) {
|
|
|
1242
1242
|
// src/activities/goals.ts
|
|
1243
1243
|
import {
|
|
1244
1244
|
allowedFirstPartyMcpToolsForSession,
|
|
1245
|
-
configuredStaticUsageLimits
|
|
1245
|
+
configuredStaticUsageLimits,
|
|
1246
1246
|
policyProviderIdForModel,
|
|
1247
1247
|
resolveModelProvider,
|
|
1248
1248
|
resolveTurnExecutionPolicyV1,
|
|
@@ -1258,92 +1258,19 @@ import {
|
|
|
1258
1258
|
import { isCodexBilledModel } from "@opengeni/codex";
|
|
1259
1259
|
import {
|
|
1260
1260
|
enqueueSessionWorkflowWakeIfRunnable,
|
|
1261
|
+
getBillingBalance,
|
|
1261
1262
|
getWorkspaceModelPolicy,
|
|
1262
1263
|
getSessionGoal,
|
|
1264
|
+
isCodexBilledTurn,
|
|
1263
1265
|
materializeGoalContinuation,
|
|
1264
|
-
requireSession
|
|
1266
|
+
requireSession,
|
|
1267
|
+
sumUsageQuantity
|
|
1265
1268
|
} from "@opengeni/db";
|
|
1266
1269
|
import {
|
|
1267
|
-
modelFundingForAdmission
|
|
1270
|
+
modelFundingForAdmission,
|
|
1268
1271
|
resolveCatalogSettings as resolveCatalogSettings2,
|
|
1269
1272
|
resolveWorkspaceCatalogSettings
|
|
1270
1273
|
} from "@opengeni/core";
|
|
1271
|
-
|
|
1272
|
-
// src/activities/agent-run-admission.ts
|
|
1273
|
-
import { configuredStaticUsageLimits } from "@opengeni/config";
|
|
1274
|
-
import { modelFundingForAdmission } from "@opengeni/core";
|
|
1275
|
-
import {
|
|
1276
|
-
checkWorkspaceAllowance,
|
|
1277
|
-
getBillingBalance,
|
|
1278
|
-
isCodexBilledTurn,
|
|
1279
|
-
sumUsageQuantity
|
|
1280
|
-
} from "@opengeni/db";
|
|
1281
|
-
async function agentRunAdmissionDenial(services, input) {
|
|
1282
|
-
const codexBilled = await isCodexBilledTurn({
|
|
1283
|
-
db: services.db,
|
|
1284
|
-
settings: services.settings,
|
|
1285
|
-
workspaceId: input.workspaceId,
|
|
1286
|
-
model: input.model
|
|
1287
|
-
});
|
|
1288
|
-
const externallyBilled = modelFundingForAdmission(
|
|
1289
|
-
services.settings,
|
|
1290
|
-
input.model,
|
|
1291
|
-
codexBilled
|
|
1292
|
-
).fundedWithoutCredits;
|
|
1293
|
-
if (!externallyBilled && (services.settings.billingMode === "stripe" || services.settings.usageLimitsMode === "managed")) {
|
|
1294
|
-
if (services.entitlements) {
|
|
1295
|
-
const decision = await services.entitlements.admitRun({
|
|
1296
|
-
accountId: input.accountId,
|
|
1297
|
-
workspaceId: input.workspaceId,
|
|
1298
|
-
action: "agent_run:create",
|
|
1299
|
-
quantity: input.requestedAgentRuns
|
|
1300
|
-
});
|
|
1301
|
-
if (!decision.allowed) return "insufficient_credits";
|
|
1302
|
-
} else {
|
|
1303
|
-
const balance = await getBillingBalance(services.db, input.accountId);
|
|
1304
|
-
if (balance.balanceMicros <= 0) return "insufficient_credits";
|
|
1305
|
-
}
|
|
1306
|
-
}
|
|
1307
|
-
if (!externallyBilled) {
|
|
1308
|
-
const refusal = await checkWorkspaceAllowance(services.db, {
|
|
1309
|
-
accountId: input.accountId,
|
|
1310
|
-
workspaceId: input.workspaceId,
|
|
1311
|
-
subjectId: input.initiatingHumanSubjectId ?? null
|
|
1312
|
-
});
|
|
1313
|
-
if (refusal) return refusal.code;
|
|
1314
|
-
}
|
|
1315
|
-
if (services.settings.usageLimitsMode !== "static" && services.settings.usageLimitsMode !== "managed") {
|
|
1316
|
-
return null;
|
|
1317
|
-
}
|
|
1318
|
-
const limits = configuredStaticUsageLimits(services.settings);
|
|
1319
|
-
if (!externallyBilled && limits.maxMonthlyCostMicrosPerAccount) {
|
|
1320
|
-
const used = await sumUsageQuantity(services.db, {
|
|
1321
|
-
accountId: input.accountId,
|
|
1322
|
-
eventType: "model.cost",
|
|
1323
|
-
since: startOfUtcMonth()
|
|
1324
|
-
});
|
|
1325
|
-
if (used >= limits.maxMonthlyCostMicrosPerAccount) {
|
|
1326
|
-
return "monthly_model_cost_limit";
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
if (limits.maxMonthlyAgentRunsPerWorkspace) {
|
|
1330
|
-
const used = await sumUsageQuantity(services.db, {
|
|
1331
|
-
workspaceId: input.workspaceId,
|
|
1332
|
-
eventType: "agent_run.created",
|
|
1333
|
-
since: startOfUtcMonth()
|
|
1334
|
-
});
|
|
1335
|
-
if (used + input.requestedAgentRuns > limits.maxMonthlyAgentRunsPerWorkspace) {
|
|
1336
|
-
return "monthly_agent_run_limit";
|
|
1337
|
-
}
|
|
1338
|
-
}
|
|
1339
|
-
return null;
|
|
1340
|
-
}
|
|
1341
|
-
function startOfUtcMonth() {
|
|
1342
|
-
const now = /* @__PURE__ */ new Date();
|
|
1343
|
-
return new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1));
|
|
1344
|
-
}
|
|
1345
|
-
|
|
1346
|
-
// src/activities/goals.ts
|
|
1347
1274
|
function createGoalActivities(services) {
|
|
1348
1275
|
async function enqueueGoalRetryWake(input) {
|
|
1349
1276
|
const { db } = await services();
|
|
@@ -1390,6 +1317,24 @@ function createGoalActivities(services) {
|
|
|
1390
1317
|
if (!modelPolicyBlocked && session.codexCompactionMode === "remote_v2" && !isCodexBilledModel(continuationModel)) {
|
|
1391
1318
|
modelPolicyBlocked = `session is locked to Codex remote compaction v2; model "${continuationModel}" is not a Codex subscription model`;
|
|
1392
1319
|
}
|
|
1320
|
+
const isCodexRun = await isCodexBilledTurn({
|
|
1321
|
+
db,
|
|
1322
|
+
settings,
|
|
1323
|
+
workspaceId: input.workspaceId,
|
|
1324
|
+
model: continuationModel
|
|
1325
|
+
});
|
|
1326
|
+
const fundedWithoutCredits = goalContinuationFundedWithoutCredits(
|
|
1327
|
+
settings,
|
|
1328
|
+
continuationModel,
|
|
1329
|
+
isCodexRun
|
|
1330
|
+
);
|
|
1331
|
+
const budgetBlocked = await goalRunBudgetBlocked(
|
|
1332
|
+
settings,
|
|
1333
|
+
db,
|
|
1334
|
+
input.accountId,
|
|
1335
|
+
input.workspaceId,
|
|
1336
|
+
fundedWithoutCredits
|
|
1337
|
+
);
|
|
1393
1338
|
const turnExecutionPolicy = resolveTurnExecutionPolicyV1(settings, {
|
|
1394
1339
|
modelId: continuationModel,
|
|
1395
1340
|
requestedModelId: null,
|
|
@@ -1414,21 +1359,7 @@ function createGoalActivities(services) {
|
|
|
1414
1359
|
// A model-policy block takes precedence: it is deterministic (a budget
|
|
1415
1360
|
// pause can clear on its own; a policy pause needs a model/policy change)
|
|
1416
1361
|
// and rides the same visible-pause channel.
|
|
1417
|
-
|
|
1418
|
-
const budgetBlocked = modelPolicyBlocked ? null : await goalRunBudgetBlocked(
|
|
1419
|
-
{ ...service, settings, db: tx },
|
|
1420
|
-
{
|
|
1421
|
-
accountId: input.accountId,
|
|
1422
|
-
workspaceId: input.workspaceId,
|
|
1423
|
-
model: continuationModel,
|
|
1424
|
-
initiatingHumanSubjectId: causalTurn?.initiatingHumanSubjectId ?? null
|
|
1425
|
-
}
|
|
1426
|
-
);
|
|
1427
|
-
return {
|
|
1428
|
-
budgetBlocked: modelPolicyBlocked ?? budgetBlocked?.message ?? null,
|
|
1429
|
-
budgetPausedReason: modelPolicyBlocked ? "limits" : budgetBlocked?.pausedReason ?? "limits"
|
|
1430
|
-
};
|
|
1431
|
-
},
|
|
1362
|
+
budgetBlocked: modelPolicyBlocked ?? budgetBlocked,
|
|
1432
1363
|
policy: {
|
|
1433
1364
|
model: continuationModel,
|
|
1434
1365
|
reasoningEffort: continuationReasoningEffort,
|
|
@@ -1486,6 +1417,9 @@ function goalContinuationModelDecision(input) {
|
|
|
1486
1417
|
blocked: `workspace model policy blocks model "${input.inheritedModel}"; pick an allowed model or change the workspace model policy`
|
|
1487
1418
|
};
|
|
1488
1419
|
}
|
|
1420
|
+
function goalContinuationFundedWithoutCredits(settings, model, codexBilled) {
|
|
1421
|
+
return modelFundingForAdmission(settings, model, codexBilled).fundedWithoutCredits;
|
|
1422
|
+
}
|
|
1489
1423
|
function goalContinuationPrompt(_goal, _autoContinuation, _cap, options = {}) {
|
|
1490
1424
|
const waitingGuidance = options.inputWaitAvailable ? [
|
|
1491
1425
|
"Waiting on child sessions, background commands, or external events:",
|
|
@@ -1560,19 +1494,41 @@ function withFirstPartyTools(settings, tools) {
|
|
|
1560
1494
|
}
|
|
1561
1495
|
return mergeToolRefs(tools, [{ kind: "mcp", id: "opengeni" }]);
|
|
1562
1496
|
}
|
|
1563
|
-
async function goalRunBudgetBlocked(
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1497
|
+
async function goalRunBudgetBlocked(settings, db, accountId, workspaceId, fundedWithoutCredits) {
|
|
1498
|
+
if (!fundedWithoutCredits && (settings.billingMode === "stripe" || settings.usageLimitsMode === "managed")) {
|
|
1499
|
+
const balance = await getBillingBalance(db, accountId);
|
|
1500
|
+
if (balance.balanceMicros <= 0) {
|
|
1501
|
+
return "insufficient OpenGeni credits";
|
|
1502
|
+
}
|
|
1503
|
+
}
|
|
1504
|
+
if (settings.usageLimitsMode === "static" || settings.usageLimitsMode === "managed") {
|
|
1505
|
+
const limits = configuredStaticUsageLimits(settings);
|
|
1506
|
+
if (!fundedWithoutCredits && limits.maxMonthlyCostMicrosPerAccount) {
|
|
1507
|
+
const used = await sumUsageQuantity(db, {
|
|
1508
|
+
accountId,
|
|
1509
|
+
eventType: "model.cost",
|
|
1510
|
+
since: startOfUtcMonth()
|
|
1511
|
+
});
|
|
1512
|
+
if (used >= limits.maxMonthlyCostMicrosPerAccount) {
|
|
1513
|
+
return `monthly model cost limit reached (${limits.maxMonthlyCostMicrosPerAccount} micros)`;
|
|
1514
|
+
}
|
|
1515
|
+
}
|
|
1516
|
+
if (limits.maxMonthlyAgentRunsPerWorkspace) {
|
|
1517
|
+
const used = await sumUsageQuantity(db, {
|
|
1518
|
+
workspaceId,
|
|
1519
|
+
eventType: "agent_run.created",
|
|
1520
|
+
since: startOfUtcMonth()
|
|
1521
|
+
});
|
|
1522
|
+
if (used + 1 > limits.maxMonthlyAgentRunsPerWorkspace) {
|
|
1523
|
+
return `monthly agent run limit reached (${limits.maxMonthlyAgentRunsPerWorkspace})`;
|
|
1524
|
+
}
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
return null;
|
|
1528
|
+
}
|
|
1529
|
+
function startOfUtcMonth() {
|
|
1530
|
+
const now = /* @__PURE__ */ new Date();
|
|
1531
|
+
return new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1));
|
|
1576
1532
|
}
|
|
1577
1533
|
|
|
1578
1534
|
// src/activities/knowledge-source-sync.ts
|
|
@@ -10370,7 +10326,6 @@ export {
|
|
|
10370
10326
|
signalPendingCodexCapacityWakeTargets,
|
|
10371
10327
|
armAndReconcileCodexCapacityWait,
|
|
10372
10328
|
createCodexCapacityActivities,
|
|
10373
|
-
agentRunAdmissionDenial,
|
|
10374
10329
|
createDocumentActivities,
|
|
10375
10330
|
createGoalActivities,
|
|
10376
10331
|
withFirstPartyTools,
|
|
@@ -10473,4 +10428,4 @@ export {
|
|
|
10473
10428
|
codexUsageLimitFailurePayload,
|
|
10474
10429
|
CODEX_USAGE_LIMIT_MAX_RESUME_MS
|
|
10475
10430
|
};
|
|
10476
|
-
//# sourceMappingURL=chunk-
|
|
10431
|
+
//# sourceMappingURL=chunk-RZAAGRFQ.js.map
|