@opengeni/worker-bundle 2.2.0-canary.36855269964001 → 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.
Files changed (44) hide show
  1. package/dist/activities/agent-run-admission.d.ts +1 -3
  2. package/dist/activities/agent-turn/admission.d.ts +3 -24
  3. package/dist/activities/agent-turn/claude-usage-observer.d.ts +1 -13
  4. package/dist/activities/agent-turn/run-credentials.d.ts +0 -2
  5. package/dist/activities/agent-turn/stream-attempt.d.ts +0 -1
  6. package/dist/activities/agent-turn/turn-context.d.ts +0 -1
  7. package/dist/activities/goals.d.ts +0 -8
  8. package/dist/activities/run-credentials.d.ts +2 -4
  9. package/dist/activities/types.d.ts +1 -1
  10. package/dist/{activities-control-YKXRDVMB.js → activities-control-MHNA3CYV.js} +66 -28
  11. package/dist/activities-control-MHNA3CYV.js.map +1 -0
  12. package/dist/{activities-turn-V37B7CQY.js → activities-turn-FQ5OO2WW.js} +197 -540
  13. package/dist/activities-turn-FQ5OO2WW.js.map +1 -0
  14. package/dist/{chunk-ZCCLJK3V.js → chunk-RZAAGRFQ.js} +65 -145
  15. package/dist/chunk-RZAAGRFQ.js.map +1 -0
  16. package/dist/index.js +1 -1
  17. package/dist/workflow-bundle.js +1 -1
  18. package/package.json +20 -20
  19. package/src/activities/agent-run-admission.ts +1 -17
  20. package/src/activities/agent-turn/admission.ts +1 -64
  21. package/src/activities/agent-turn/claim.ts +14 -56
  22. package/src/activities/agent-turn/claude-usage-observer.ts +1 -33
  23. package/src/activities/agent-turn/errors.ts +0 -46
  24. package/src/activities/agent-turn/failure-settlement.ts +0 -5
  25. package/src/activities/agent-turn/run-credentials.ts +3 -15
  26. package/src/activities/agent-turn/run.ts +3 -32
  27. package/src/activities/agent-turn/stream-attempt.ts +35 -138
  28. package/src/activities/agent-turn/tool-environment.ts +20 -13
  29. package/src/activities/agent-turn/turn-context.ts +0 -1
  30. package/src/activities/capabilities.ts +14 -52
  31. package/src/activities/goals.ts +78 -38
  32. package/src/activities/knowledge-indexing.ts +0 -29
  33. package/src/activities/run-credentials.ts +16 -22
  34. package/src/activities/scheduled-tasks.ts +0 -1
  35. package/src/activities/types.ts +0 -1
  36. package/src/activities/workspace-credential-provider.ts +0 -12
  37. package/src/sandbox-routing.ts +2 -4
  38. package/dist/activities/agent-turn/final-reply.d.ts +0 -18
  39. package/dist/activities/agent-turn/model-call-admission.d.ts +0 -15
  40. package/dist/activities-control-YKXRDVMB.js.map +0 -1
  41. package/dist/activities-turn-V37B7CQY.js.map +0 -1
  42. package/dist/chunk-ZCCLJK3V.js.map +0 -1
  43. package/src/activities/agent-turn/final-reply.ts +0 -46
  44. 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 as configuredStaticUsageLimits2,
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 as modelFundingForAdmission2,
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
- admission: async (tx, causalTurn) => {
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:",
@@ -1541,8 +1475,6 @@ function goalContinuationPrompt(_goal, _autoContinuation, _cap, options = {}) {
1541
1475
  "- For document report deliverables (a document the user asked for, or a large report meant to be kept or shared), follow the Documents Skill: create the durable native document first, inspect its relevant final head after the last edit, and provide the returned artifact reference. Declare report requirements through the available goal tools before authoring and satisfy every persisted report requirement with verified artifact delivery evidence before completion. Sandbox paths and raw file IDs do not prove report delivery. If artifact tooling or access is unavailable, keep that deliverable incomplete and state the blocker; never invent proof or silently substitute a local report. Ordinary chat answers, short progress updates, source-code links, and explicitly requested local-file work remain outside this report contract.",
1542
1476
  "",
1543
1477
  "Do not rely on intent, partial progress, memory of earlier work, or a plausible final answer as proof of completion. Call opengeni__goal_complete with concrete evidence only when the full objective is actually achieved and no required work remains.",
1544
- "Goal evidence is a short proof for the ledger, not the deliverable. After goal_complete succeeds, finish this same turn with the requested user-facing answer, or a concise summary and retained artifact link. Goal completion stops future automatic continuations; it does not send the answer or end this turn. Never compress a report into evidence or omit the final reply.",
1545
- "Goal progress notes are short human-readable milestone statuses, not raw transcripts or continuation instructions. Keep normal spaces and summarize detail instead of squeezing words into a ledger field. The text and successCriteria fields each allow 8192 UTF-8 bytes, progressNote allows 8192 UTF-8 bytes, rationale allows 2048 UTF-8 bytes, and evidence allows 8192 characters.",
1546
1478
  "",
1547
1479
  ...waitingGuidance,
1548
1480
  ...childNoticeGuidance,
@@ -1562,19 +1494,41 @@ function withFirstPartyTools(settings, tools) {
1562
1494
  }
1563
1495
  return mergeToolRefs(tools, [{ kind: "mcp", id: "opengeni" }]);
1564
1496
  }
1565
- async function goalRunBudgetBlocked(services, input) {
1566
- const denial = await agentRunAdmissionDenial(services, { ...input, requestedAgentRuns: 1 });
1567
- if (denial === null) return null;
1568
- if (denial === "allowance_exhausted") {
1569
- return { pausedReason: "allowance", message: "OpenGeni usage allowance exhausted" };
1570
- }
1571
- const limits = configuredStaticUsageLimits2(services.settings);
1572
- const messages = {
1573
- insufficient_credits: "insufficient OpenGeni credits",
1574
- monthly_model_cost_limit: `monthly model cost limit reached (${limits.maxMonthlyCostMicrosPerAccount} micros)`,
1575
- monthly_agent_run_limit: `monthly agent run limit reached (${limits.maxMonthlyAgentRunsPerWorkspace})`
1576
- };
1577
- return { pausedReason: "limits", message: messages[denial] };
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));
1578
1532
  }
1579
1533
 
1580
1534
  // src/activities/knowledge-source-sync.ts
@@ -6672,7 +6626,7 @@ function afterPersistableHomeMutation(services, ids, home) {
6672
6626
  if (!exactAdmission || typeof exactAdmission.id !== "string" || typeof exactAdmission.workspaceGeneration !== "number" || !("providerBinding" in boundAdmission)) {
6673
6627
  throw new Error("Persistable home mutation settlement lacked its bound admission");
6674
6628
  }
6675
- if ((outcome === "resolved" || outcome === "outcome_unknown") && retainedProcess) {
6629
+ if (outcome === "resolved" && retainedProcess) {
6676
6630
  try {
6677
6631
  await retainWorkspaceProviderCommand(services.db, {
6678
6632
  accountId: fence.accountId,
@@ -6717,8 +6671,6 @@ function afterPersistableHomeMutation(services, ids, home) {
6717
6671
  }
6718
6672
  return;
6719
6673
  }
6720
- if (outcome === "outcome_unknown")
6721
- throw new Error("Outcome-unknown command settlement requires its exact retained invocation");
6722
6674
  await verifyWorkspaceMutationSettlement(services.db, {
6723
6675
  accountId: fence.accountId,
6724
6676
  workspaceId: ids.workspaceId,
@@ -8918,7 +8870,6 @@ import {
8918
8870
  isModalTaskExecStartPreDispatchUnavailableError,
8919
8871
  isRoutingMutationOutcomeUnknownError,
8920
8872
  RoutingWorkspaceRootChangedError,
8921
- ResponsesStreamingTerminalError,
8922
8873
  SandboxMaterializationVerificationError,
8923
8874
  materializationVerificationDiagnostic,
8924
8875
  PROVIDER_QUOTA_EXHAUSTED_CODE,
@@ -9883,7 +9834,6 @@ function shouldRecoverCompactionProviderFailure(error) {
9883
9834
  return agentRunFailurePayload(error).retryable === true;
9884
9835
  }
9885
9836
  function classifyContextWindowOverflowError(error) {
9886
- if (isProviderSafetyRefusal(error)) return null;
9887
9837
  const fields = collectErrorStrings(error);
9888
9838
  const matched = fields.find(
9889
9839
  (value) => /context[_\s-]*length[_\s-]*exceeded/i.test(value) || /exceeds?\s+(?:the\s+)?context\s+window/i.test(value) || /maximum\s+context\s+length/i.test(value) || /context\s+window[^.]*exceed/i.test(value)
@@ -9929,7 +9879,6 @@ function collectErrorStrings(value, seen = /* @__PURE__ */ new WeakSet()) {
9929
9879
  }
9930
9880
  seen.add(value);
9931
9881
  const out = [];
9932
- if (value instanceof ResponsesStreamingTerminalError) out.push(value.detail);
9933
9882
  const record = value;
9934
9883
  for (const key of ["message", "code", "type", "name", "param"]) {
9935
9884
  const field = record[key];
@@ -9947,9 +9896,6 @@ function isExactStatuslessUpstreamConnectivityMessage(message) {
9947
9896
  return message.trim().toLowerCase() === STATUSLESS_UPSTREAM_CONNECTIVITY_MESSAGE;
9948
9897
  }
9949
9898
  function providerSafetyRefusalDiagnostic(error) {
9950
- if (error instanceof ResponsesStreamingTerminalError) {
9951
- return error.category === "safety" ? error.detail : void 0;
9952
- }
9953
9899
  return collectErrorStrings(error).find(
9954
9900
  (value) => /^(?:content_policy_violation|content_filter|safety_violation|bio_policy|cyber_policy)$/.test(
9955
9901
  value
@@ -9960,9 +9906,6 @@ function isProviderSafetyRefusal(error) {
9960
9906
  return providerSafetyRefusalDiagnostic(error) !== void 0;
9961
9907
  }
9962
9908
  function isTransientProviderError(error) {
9963
- if (error instanceof ResponsesStreamingTerminalError) {
9964
- return error.category === "unavailable";
9965
- }
9966
9909
  if (isProviderSafetyRefusal(error)) return false;
9967
9910
  const status = typeof error === "object" && error !== null ? Number(
9968
9911
  error.status ?? error.statusCode
@@ -10078,28 +10021,6 @@ function baseAgentRunFailurePayload(error, options = {}) {
10078
10021
  detail: safetyRefusalDiagnostic
10079
10022
  };
10080
10023
  }
10081
- if (error instanceof ResponsesStreamingTerminalError) {
10082
- const quota2 = error.category === "unknown" || error.category === "rate_limit" ? classifyProviderQuotaExhaustionError({
10083
- code: error.code,
10084
- error: { code: error.code, type: error.type, message: error.detail },
10085
- retryAfterSeconds: error.retryAfterSeconds
10086
- }) : null;
10087
- if (quota2) {
10088
- return {
10089
- error: providerQuotaExhaustedMessage(quota2.scope),
10090
- code: PROVIDER_QUOTA_EXHAUSTED_CODE,
10091
- retryable: false,
10092
- quotaScope: quota2.scope,
10093
- detail: error.detail
10094
- };
10095
- }
10096
- return {
10097
- error: error.category === "rate_limit" ? "Model provider rate limit hit. Try again in a minute or lower the reasoning effort." : error.category === "unavailable" ? "The model provider is temporarily unavailable. The same turn will retry after a short delay." : "The model provider rejected the response. Automatic retries stopped.",
10098
- code: error.category === "rate_limit" ? "provider_rate_limited" : error.category === "unavailable" ? "provider_unavailable" : "provider_request_rejected",
10099
- retryable: error.category === "rate_limit" || error.category === "unavailable",
10100
- detail: error.detail
10101
- };
10102
- }
10103
10024
  const message = error instanceof Error ? error.message : String(error);
10104
10025
  const status = typeof error === "object" && error !== null ? Number(
10105
10026
  error.status ?? error.statusCode
@@ -10405,7 +10326,6 @@ export {
10405
10326
  signalPendingCodexCapacityWakeTargets,
10406
10327
  armAndReconcileCodexCapacityWait,
10407
10328
  createCodexCapacityActivities,
10408
- agentRunAdmissionDenial,
10409
10329
  createDocumentActivities,
10410
10330
  createGoalActivities,
10411
10331
  withFirstPartyTools,
@@ -10508,4 +10428,4 @@ export {
10508
10428
  codexUsageLimitFailurePayload,
10509
10429
  CODEX_USAGE_LIMIT_MAX_RESUME_MS
10510
10430
  };
10511
- //# sourceMappingURL=chunk-ZCCLJK3V.js.map
10431
+ //# sourceMappingURL=chunk-RZAAGRFQ.js.map