@opengeni/worker-bundle 0.11.8 → 0.12.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/index.js CHANGED
@@ -12511,6 +12511,16 @@ async function terminateProviderBox(settings, lease, observability, persistArchi
12511
12511
  }
12512
12512
 
12513
12513
  // src/activities/scheduled-tasks.ts
12514
+ import {
12515
+ OPENGENI_SLACK_BOT_CREDENTIAL_LABEL,
12516
+ OPENGENI_SLACK_BOT_CREDENTIAL_ROLE,
12517
+ OPENGENI_SLACK_BOT_SESSION_METADATA_KEY
12518
+ } from "@opengeni/contracts";
12519
+ import {
12520
+ openGeniSlackBotMetadata,
12521
+ requireOpenGeniSlackBotConnection,
12522
+ scheduledSlackBotConnectionId
12523
+ } from "@opengeni/core";
12514
12524
  import {
12515
12525
  appendSessionEventsWithLockedSessionUpdate,
12516
12526
  addSessionSystemUpdateWithSourceMutation as addSessionSystemUpdateWithSourceMutation2,
@@ -12540,6 +12550,15 @@ function createScheduledTaskActivities(services) {
12540
12550
  dispatchScheduledTaskRun: async (input) => {
12541
12551
  const { settings, db, bus, wakeSessionWorkflow } = await services();
12542
12552
  const task = await requireScheduledTask(db, input.workspaceId, input.taskId);
12553
+ const slackBotConnection = task.agentConfig.slackBotConnectionId ? await requireOpenGeniSlackBotConnection(
12554
+ db,
12555
+ task.workspaceId,
12556
+ task.agentConfig.slackBotConnectionId
12557
+ ) : null;
12558
+ const slackBotMetadata = slackBotConnection ? openGeniSlackBotMetadata(slackBotConnection.metadata) : null;
12559
+ if (slackBotConnection && !slackBotMetadata) {
12560
+ throw new Error("OpenGeni Slack bot connection metadata is invalid");
12561
+ }
12543
12562
  const model = task.agentConfig.model ?? settings.openaiModel;
12544
12563
  const isCodexRun = await isCodexBilledTurn2({
12545
12564
  db,
@@ -12640,6 +12659,8 @@ function createScheduledTaskActivities(services) {
12640
12659
  frozenRigVersionId = rig.activeVersion.id;
12641
12660
  }
12642
12661
  let session;
12662
+ const taskMetadata = { ...task.agentConfig.metadata };
12663
+ delete taskMetadata[OPENGENI_SLACK_BOT_SESSION_METADATA_KEY];
12643
12664
  try {
12644
12665
  session = await createSession(db, {
12645
12666
  accountId: task.accountId,
@@ -12648,11 +12669,14 @@ function createScheduledTaskActivities(services) {
12648
12669
  resources: task.agentConfig.resources,
12649
12670
  tools: taskTools,
12650
12671
  metadata: {
12651
- ...task.agentConfig.metadata,
12672
+ ...taskMetadata,
12652
12673
  model,
12653
12674
  reasoningEffort,
12654
12675
  scheduledTaskId: task.id,
12655
- scheduledTaskRunId: run.id
12676
+ scheduledTaskRunId: run.id,
12677
+ ...slackBotConnection ? {
12678
+ [OPENGENI_SLACK_BOT_SESSION_METADATA_KEY]: slackBotConnection.id
12679
+ } : {}
12656
12680
  },
12657
12681
  createdBy: {
12658
12682
  kind: "service",
@@ -12706,7 +12730,15 @@ function createScheduledTaskActivities(services) {
12706
12730
  scheduledTaskId: task.id,
12707
12731
  scheduledTaskRunId: run.id,
12708
12732
  // Names/ids only; never values.
12709
- ...variableSet ? { variableSetId: variableSet.id, variableSetName: variableSet.name } : {}
12733
+ ...variableSet ? { variableSetId: variableSet.id, variableSetName: variableSet.name } : {},
12734
+ ...slackBotConnection && slackBotMetadata ? {
12735
+ slackBotConnection: {
12736
+ credentialRole: OPENGENI_SLACK_BOT_CREDENTIAL_ROLE,
12737
+ credentialLabel: OPENGENI_SLACK_BOT_CREDENTIAL_LABEL,
12738
+ connectionId: slackBotConnection.id,
12739
+ slackTeamId: slackBotMetadata.slackTeamId
12740
+ }
12741
+ } : {}
12710
12742
  }
12711
12743
  },
12712
12744
  ...goal ? [
@@ -12783,6 +12815,11 @@ function createScheduledTaskActivities(services) {
12783
12815
  "scheduled task variableSet attachment does not match its reusable session"
12784
12816
  );
12785
12817
  }
12818
+ if (scheduledSlackBotConnectionId(session.metadata) !== (task.agentConfig.slackBotConnectionId ?? null)) {
12819
+ throw new Error(
12820
+ "scheduled task OpenGeni Slack bot binding does not match its reusable session"
12821
+ );
12822
+ }
12786
12823
  const reusableGoal = goalSpec && run.status === "queued" ? await upsertSessionGoal(db, {
12787
12824
  accountId: task.accountId,
12788
12825
  workspaceId: task.workspaceId,
@@ -14286,7 +14323,35 @@ import {
14286
14323
  } from "@opengeni/core";
14287
14324
 
14288
14325
  // src/concurrency.ts
14289
- var TURN_WORKER_MAX_CONCURRENT_TURNS = 16;
14326
+ function turnWorkerConcurrencyOptions(settings) {
14327
+ if (settings.turnWorkerConcurrencyMode === "fixed") {
14328
+ return {
14329
+ maxConcurrentActivityTaskExecutions: settings.turnWorkerMaxConcurrentTurns
14330
+ };
14331
+ }
14332
+ return {
14333
+ tuner: {
14334
+ tunerOptions: {
14335
+ targetCpuUsage: settings.turnWorkerTargetCpuUsage,
14336
+ targetMemoryUsage: settings.turnWorkerTargetMemoryUsage
14337
+ },
14338
+ activityTaskSlotOptions: {
14339
+ minimumSlots: 1,
14340
+ maximumSlots: settings.turnWorkerMaxConcurrentTurns,
14341
+ rampThrottle: "50ms"
14342
+ }
14343
+ }
14344
+ };
14345
+ }
14346
+ function turnWorkerConcurrencyLogFields(settings) {
14347
+ const resourceBased = settings.turnWorkerConcurrencyMode === "resource-based";
14348
+ return {
14349
+ concurrencyMode: settings.turnWorkerConcurrencyMode,
14350
+ maxConcurrentTurns: settings.turnWorkerMaxConcurrentTurns,
14351
+ targetCpuUsage: resourceBased ? settings.turnWorkerTargetCpuUsage : null,
14352
+ targetMemoryUsage: resourceBased ? settings.turnWorkerTargetMemoryUsage : null
14353
+ };
14354
+ }
14290
14355
  var CONTROL_WORKER_MAX_CONCURRENT_ACTIVITIES = 32;
14291
14356
  var CONTROL_WORKER_MAX_CONCURRENT_WORKFLOW_TASKS = 40;
14292
14357
 
@@ -14422,10 +14487,10 @@ async function createOpenGeniWorker(options) {
14422
14487
  taskQueue: options.role === "control" ? settings.temporalTaskQueue : turnTaskQueue(settings.temporalTaskQueue),
14423
14488
  ...options.role === "control" ? {
14424
14489
  ...options.workflowBundle ? { workflowBundle: options.workflowBundle } : resolveOpenGeniWorkflowDefinition(),
14425
- maxConcurrentWorkflowTaskExecutions: CONTROL_WORKER_MAX_CONCURRENT_WORKFLOW_TASKS
14426
- } : {},
14490
+ maxConcurrentWorkflowTaskExecutions: CONTROL_WORKER_MAX_CONCURRENT_WORKFLOW_TASKS,
14491
+ maxConcurrentActivityTaskExecutions: CONTROL_WORKER_MAX_CONCURRENT_ACTIVITIES
14492
+ } : turnWorkerConcurrencyOptions(settings),
14427
14493
  activities,
14428
- maxConcurrentActivityTaskExecutions: options.role === "turn" ? TURN_WORKER_MAX_CONCURRENT_TURNS : CONTROL_WORKER_MAX_CONCURRENT_ACTIVITIES,
14429
14494
  // Cancellation is delivered through an activity heartbeat. The SDK would
14430
14495
  // otherwise throttle a two-minute heartbeat timeout to its 60-second cap,
14431
14496
  // making Pause/Steer take roughly a minute even though runAgentTurn emits a
@@ -14757,7 +14822,12 @@ async function createOpenGeniWorkerService(options) {
14757
14822
  observability.info("OpenGeni worker listening", {
14758
14823
  role: options.role,
14759
14824
  temporalTaskQueue: options.role === "control" ? settings.temporalTaskQueue : turnTaskQueue(settings.temporalTaskQueue),
14760
- maxConcurrentActivityTaskExecutions: options.role === "turn" ? TURN_WORKER_MAX_CONCURRENT_TURNS : CONTROL_WORKER_MAX_CONCURRENT_ACTIVITIES,
14825
+ ...options.role === "turn" ? turnWorkerConcurrencyLogFields(settings) : {
14826
+ concurrencyMode: "fixed",
14827
+ maxConcurrentTurns: CONTROL_WORKER_MAX_CONCURRENT_ACTIVITIES,
14828
+ targetCpuUsage: null,
14829
+ targetMemoryUsage: null
14830
+ },
14761
14831
  maxConcurrentWorkflowTaskExecutions: options.role === "control" ? CONTROL_WORKER_MAX_CONCURRENT_WORKFLOW_TASKS : 0,
14762
14832
  httpPort: options.http === false ? null : settings.workerHttpPort
14763
14833
  });