@opengeni/worker-bundle 0.23.3-canary.0 → 0.23.4-canary.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-turn/admission.d.ts +10 -2
- package/dist/activities/agent-turn/claim.d.ts +1 -0
- package/dist/activities/agent-turn/codex.d.ts +2 -2
- package/dist/activities/agent-turn/list-models.d.ts +16 -0
- package/dist/activities/agent-turn/model-usage.d.ts +10 -1
- package/dist/activities/agent-turn/tool-environment.d.ts +1 -0
- package/dist/activities/agent-turn/tool-policy.d.ts +36 -5
- package/dist/activities/agent-turn/turn-context.d.ts +2 -0
- package/dist/activities/automations.d.ts +1 -0
- package/dist/activities/capabilities.d.ts +2 -1
- package/dist/activities/goals.d.ts +11 -0
- package/dist/activities/image-generation-references.d.ts +2 -1
- package/dist/activities/scheduled-tasks.d.ts +1 -0
- package/dist/activities/types.d.ts +8 -0
- package/dist/{activities-control-52W5IDWM.js → activities-control-SGU2WEVB.js} +206 -97
- package/dist/activities-control-SGU2WEVB.js.map +1 -0
- package/dist/activities-control.d.ts +2 -0
- package/dist/{activities-turn-A2G2KLSY.js → activities-turn-7EAQXW6Q.js} +301 -65
- package/dist/activities-turn-7EAQXW6Q.js.map +1 -0
- package/dist/activities.d.ts +2 -0
- package/dist/{chunk-IPVMCAW5.js → chunk-S2QVRVJW.js} +85 -23
- package/dist/chunk-S2QVRVJW.js.map +1 -0
- package/dist/{chunk-GFNXVZVQ.js → chunk-TJIPCHMP.js} +3 -2
- package/dist/chunk-TJIPCHMP.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +29 -6
- package/dist/index.js.map +1 -1
- package/dist/observability-metrics.d.ts +1 -0
- package/dist/workflow-bundle.js +26 -3
- package/dist/workflows/activities.d.ts +5 -0
- package/dist/workflows/automations.d.ts +5 -0
- package/package.json +17 -17
- package/src/activities/agent-run-admission.ts +7 -1
- package/src/activities/agent-turn/admission.ts +28 -6
- package/src/activities/agent-turn/claim.ts +25 -5
- package/src/activities/agent-turn/codex.ts +2 -2
- package/src/activities/agent-turn/compaction-prep.ts +2 -0
- package/src/activities/agent-turn/list-models.ts +101 -0
- package/src/activities/agent-turn/model-usage.ts +88 -42
- package/src/activities/agent-turn/run.ts +6 -3
- package/src/activities/agent-turn/stream-attempt.ts +8 -0
- package/src/activities/agent-turn/tool-environment.ts +62 -1
- package/src/activities/agent-turn/tool-policy.ts +58 -5
- package/src/activities/agent-turn/turn-context.ts +4 -0
- package/src/activities/automations.ts +122 -67
- package/src/activities/capabilities.ts +72 -2
- package/src/activities/goals.ts +107 -31
- package/src/activities/image-generation-references.ts +9 -9
- package/src/activities/scheduled-tasks.ts +120 -26
- package/src/activities/site-auth-maintenance.ts +12 -12
- package/src/activities/types.ts +6 -0
- package/src/activities.ts +1 -0
- package/src/activity-services.ts +4 -1
- package/src/github-rest-mcp.ts +2 -1
- package/src/index.ts +19 -4
- package/src/observability-metrics.ts +2 -0
- package/src/workflows/activities.ts +15 -0
- package/src/workflows/automations.ts +21 -2
- package/dist/activities-control-52W5IDWM.js.map +0 -1
- package/dist/activities-turn-A2G2KLSY.js.map +0 -1
- package/dist/chunk-GFNXVZVQ.js.map +0 -1
- package/dist/chunk-IPVMCAW5.js.map +0 -1
|
@@ -32,7 +32,7 @@ import {
|
|
|
32
32
|
scheduledUserMessagePayload,
|
|
33
33
|
withFirstPartyTools,
|
|
34
34
|
workflowIdForSession
|
|
35
|
-
} from "./chunk-
|
|
35
|
+
} from "./chunk-S2QVRVJW.js";
|
|
36
36
|
import {
|
|
37
37
|
inspectOpenSandboxKubernetesInventory,
|
|
38
38
|
recordCreditBalanceGauges,
|
|
@@ -52,7 +52,7 @@ import {
|
|
|
52
52
|
recordTurnsQueuedGauge,
|
|
53
53
|
recordWorkerDeathRecoveryMetrics,
|
|
54
54
|
runtimeMetricsHooksForObservability
|
|
55
|
-
} from "./chunk-
|
|
55
|
+
} from "./chunk-TJIPCHMP.js";
|
|
56
56
|
|
|
57
57
|
// src/activities/browser-state-artifact-reaper.ts
|
|
58
58
|
import {
|
|
@@ -139,12 +139,18 @@ function cleanupErrorCategory(error) {
|
|
|
139
139
|
}
|
|
140
140
|
|
|
141
141
|
// src/activities/automations.ts
|
|
142
|
-
import {
|
|
142
|
+
import {
|
|
143
|
+
resolveTurnExecutionPolicyV1,
|
|
144
|
+
WORKSPACE_GATEWAY_MODEL_ID_PREFIX,
|
|
145
|
+
WORKSPACE_OPENROUTER_MODEL_ID_PREFIX
|
|
146
|
+
} from "@opengeni/config";
|
|
143
147
|
import {
|
|
144
148
|
assertWorkspaceModelPolicyAllows,
|
|
145
149
|
canonicalConfiguredModel,
|
|
146
150
|
createAndStartSessionWithOutcome,
|
|
147
|
-
recordWorkspaceUsage
|
|
151
|
+
recordWorkspaceUsage,
|
|
152
|
+
resolveCatalogSettings,
|
|
153
|
+
resolveWorkspaceCatalogSettings
|
|
148
154
|
} from "@opengeni/core";
|
|
149
155
|
import {
|
|
150
156
|
AutomationAuthorityRevokedError,
|
|
@@ -155,14 +161,20 @@ import {
|
|
|
155
161
|
|
|
156
162
|
// src/activities/agent-run-admission.ts
|
|
157
163
|
import { configuredStaticUsageLimits } from "@opengeni/config";
|
|
164
|
+
import { modelFundingForAdmission } from "@opengeni/core";
|
|
158
165
|
import { getBillingBalance, isCodexBilledTurn, sumUsageQuantity } from "@opengeni/db";
|
|
159
166
|
async function agentRunAdmissionDenial(services, input) {
|
|
160
|
-
const
|
|
167
|
+
const codexBilled = await isCodexBilledTurn({
|
|
161
168
|
db: services.db,
|
|
162
169
|
settings: services.settings,
|
|
163
170
|
workspaceId: input.workspaceId,
|
|
164
171
|
model: input.model
|
|
165
172
|
});
|
|
173
|
+
const externallyBilled = modelFundingForAdmission(
|
|
174
|
+
services.settings,
|
|
175
|
+
input.model,
|
|
176
|
+
codexBilled
|
|
177
|
+
).fundedWithoutCredits;
|
|
166
178
|
if (!externallyBilled && (services.settings.billingMode === "stripe" || services.settings.usageLimitsMode === "managed")) {
|
|
167
179
|
if (services.entitlements) {
|
|
168
180
|
const decision = await services.entitlements.admitRun({
|
|
@@ -218,8 +230,19 @@ function createAutomationActivities(services, options = {}) {
|
|
|
218
230
|
const assertModelPolicy = options.assertModelPolicy ?? assertWorkspaceModelPolicyAllows;
|
|
219
231
|
const recordUsage = options.recordUsage ?? recordWorkspaceUsage;
|
|
220
232
|
return {
|
|
233
|
+
settleAutomationRunFailure: async (input) => {
|
|
234
|
+
const service = await services();
|
|
235
|
+
await settle(service.db, {
|
|
236
|
+
workspaceId: input.workspaceId,
|
|
237
|
+
runId: input.runId,
|
|
238
|
+
status: "failed",
|
|
239
|
+
errorCode: "dispatch_failed"
|
|
240
|
+
});
|
|
241
|
+
},
|
|
221
242
|
dispatchAutomationRun: async (input) => {
|
|
222
243
|
const service = await services();
|
|
244
|
+
const catalogSourceSettings = service.catalogSourceSettings ?? service.settings;
|
|
245
|
+
const deploymentCatalogSettings = (await resolveCatalogSettings(service.db, catalogSourceSettings)).settings;
|
|
223
246
|
const run = await claim(service.db, input);
|
|
224
247
|
if (!run) return { action: "not_found" };
|
|
225
248
|
if (run.status === "dispatched") {
|
|
@@ -227,61 +250,87 @@ function createAutomationActivities(services, options = {}) {
|
|
|
227
250
|
return { action: "already_dispatched", sessionId: run.sessionId };
|
|
228
251
|
}
|
|
229
252
|
if (run.status === "skipped") {
|
|
230
|
-
return {
|
|
253
|
+
return {
|
|
254
|
+
action: "skipped",
|
|
255
|
+
reason: run.errorCode ?? "authority_revoked"
|
|
256
|
+
};
|
|
231
257
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
await settle(service.db, {
|
|
235
|
-
workspaceId: input.workspaceId,
|
|
236
|
-
runId: run.id,
|
|
237
|
-
status: "skipped",
|
|
238
|
-
errorCode: "accepted_execution_mismatch"
|
|
239
|
-
});
|
|
240
|
-
return { action: "skipped", reason: "accepted_execution_mismatch" };
|
|
258
|
+
if (run.status === "failed") {
|
|
259
|
+
return { action: "failed", reason: run.errorCode ?? "dispatch_failed" };
|
|
241
260
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
261
|
+
try {
|
|
262
|
+
const accepted = run.acceptedExecution;
|
|
263
|
+
if (accepted.accountId !== input.accountId || accepted.workspaceId !== input.workspaceId || accepted.sourceId !== run.sourceId || accepted.triggerId !== run.triggerId || accepted.triggerRevision !== run.triggerRevision || accepted.eventId !== run.eventId) {
|
|
264
|
+
await settle(service.db, {
|
|
265
|
+
workspaceId: input.workspaceId,
|
|
266
|
+
runId: run.id,
|
|
267
|
+
status: "skipped",
|
|
268
|
+
errorCode: "accepted_execution_mismatch"
|
|
269
|
+
});
|
|
270
|
+
return { action: "skipped", reason: "accepted_execution_mismatch" };
|
|
271
|
+
}
|
|
272
|
+
const template = accepted.sessionTemplate;
|
|
273
|
+
const requestedModel = template.model ?? deploymentCatalogSettings.openaiModel;
|
|
274
|
+
const catalogSettings = requestedModel.startsWith(WORKSPACE_GATEWAY_MODEL_ID_PREFIX) || requestedModel.startsWith(WORKSPACE_OPENROUTER_MODEL_ID_PREFIX) ? (await resolveWorkspaceCatalogSettings(service.db, catalogSourceSettings, {
|
|
275
|
+
accountId: input.accountId,
|
|
257
276
|
workspaceId: input.workspaceId,
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
277
|
+
retainedProductModelId: requestedModel
|
|
278
|
+
})).settings : deploymentCatalogSettings;
|
|
279
|
+
const catalogService = { ...service, settings: catalogSettings };
|
|
280
|
+
let model;
|
|
281
|
+
try {
|
|
282
|
+
const configuredModel = canonicalConfiguredModel(catalogSettings, requestedModel);
|
|
283
|
+
if (!configuredModel) throw new Error("automation has no configured model");
|
|
284
|
+
await assertModelPolicy(service.db, catalogSettings, input.workspaceId, configuredModel);
|
|
285
|
+
model = configuredModel;
|
|
286
|
+
} catch (error) {
|
|
287
|
+
if (!isUnprocessableEntity(error)) throw error;
|
|
288
|
+
await settle(service.db, {
|
|
289
|
+
workspaceId: input.workspaceId,
|
|
290
|
+
runId: run.id,
|
|
291
|
+
status: "failed",
|
|
292
|
+
errorCode: "dispatch_failed"
|
|
293
|
+
});
|
|
294
|
+
return { action: "failed", reason: "dispatch_failed" };
|
|
295
|
+
}
|
|
296
|
+
const denial = await admit(catalogService, {
|
|
297
|
+
accountId: input.accountId,
|
|
268
298
|
workspaceId: input.workspaceId,
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
299
|
+
model,
|
|
300
|
+
requestedAgentRuns: 1
|
|
301
|
+
});
|
|
302
|
+
if (denial) {
|
|
303
|
+
await settle(service.db, {
|
|
304
|
+
workspaceId: input.workspaceId,
|
|
305
|
+
runId: run.id,
|
|
306
|
+
status: "failed",
|
|
307
|
+
errorCode: denial
|
|
308
|
+
});
|
|
309
|
+
return { action: "failed", reason: denial };
|
|
310
|
+
}
|
|
311
|
+
const reasoningEffort = template.reasoningEffort ?? catalogSettings.openaiReasoningEffort;
|
|
312
|
+
const sandboxBackend = template.sandboxBackend ?? catalogSettings.sandboxBackend;
|
|
313
|
+
if (sandboxBackend === "selfhosted") {
|
|
314
|
+
await settle(service.db, {
|
|
315
|
+
workspaceId: input.workspaceId,
|
|
316
|
+
runId: run.id,
|
|
317
|
+
status: "skipped",
|
|
318
|
+
errorCode: "interactive_compute_not_allowed"
|
|
319
|
+
});
|
|
320
|
+
return {
|
|
321
|
+
action: "skipped",
|
|
322
|
+
reason: "interactive_compute_not_allowed"
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
const turnExecutionPolicy = resolveTurnExecutionPolicyV1(catalogSettings, {
|
|
326
|
+
modelId: model,
|
|
327
|
+
requestedModelId: template.model,
|
|
328
|
+
modelSource: template.model ? "explicit" : "deployment",
|
|
329
|
+
reasoningEffort,
|
|
330
|
+
reasoningSource: template.reasoningEffort ? "explicit" : "deployment",
|
|
331
|
+
latencyMode: "standard",
|
|
332
|
+
latencyModeSource: "deployment"
|
|
272
333
|
});
|
|
273
|
-
return { action: "skipped", reason: "interactive_compute_not_allowed" };
|
|
274
|
-
}
|
|
275
|
-
const turnExecutionPolicy = resolveTurnExecutionPolicyV1(service.settings, {
|
|
276
|
-
modelId: model,
|
|
277
|
-
requestedModelId: template.model,
|
|
278
|
-
modelSource: template.model ? "explicit" : "deployment",
|
|
279
|
-
reasoningEffort,
|
|
280
|
-
reasoningSource: template.reasoningEffort ? "explicit" : "deployment",
|
|
281
|
-
latencyMode: "standard",
|
|
282
|
-
latencyModeSource: "deployment"
|
|
283
|
-
});
|
|
284
|
-
try {
|
|
285
334
|
const created = await createSession2({
|
|
286
335
|
db: service.db,
|
|
287
336
|
bus: service.bus,
|
|
@@ -329,11 +378,12 @@ function createAutomationActivities(services, options = {}) {
|
|
|
329
378
|
policyRole: template.policyRole,
|
|
330
379
|
firstPartyMcpPermissions: template.firstPartyMcpPermissions,
|
|
331
380
|
firstPartyMcpTools: template.firstPartyMcpTools,
|
|
381
|
+
retainWorkspaceCustomModel: model.startsWith(WORKSPACE_GATEWAY_MODEL_ID_PREFIX) || model.startsWith(WORKSPACE_OPENROUTER_MODEL_ID_PREFIX),
|
|
332
382
|
createIdempotencyKey: `automation-run:${run.id}`,
|
|
333
383
|
subjectId: accepted.serviceSubjectId
|
|
334
384
|
});
|
|
335
385
|
await recordUsage(
|
|
336
|
-
{ db: service.db, settings:
|
|
386
|
+
{ db: service.db, settings: catalogSettings },
|
|
337
387
|
{
|
|
338
388
|
accountId: input.accountId,
|
|
339
389
|
workspaceId: input.workspaceId,
|
|
@@ -367,17 +417,14 @@ function createAutomationActivities(services, options = {}) {
|
|
|
367
417
|
});
|
|
368
418
|
return { action: "skipped", reason: "authority_revoked" };
|
|
369
419
|
}
|
|
370
|
-
await settle(service.db, {
|
|
371
|
-
workspaceId: input.workspaceId,
|
|
372
|
-
runId: run.id,
|
|
373
|
-
status: "failed",
|
|
374
|
-
errorCode: "dispatch_failed"
|
|
375
|
-
});
|
|
376
420
|
throw error;
|
|
377
421
|
}
|
|
378
422
|
}
|
|
379
423
|
};
|
|
380
424
|
}
|
|
425
|
+
function isUnprocessableEntity(error) {
|
|
426
|
+
return error instanceof Error && "status" in error && error.status === 422;
|
|
427
|
+
}
|
|
381
428
|
|
|
382
429
|
// src/activities/documents.ts
|
|
383
430
|
import { configuredStaticUsageLimits as configuredStaticUsageLimits2 } from "@opengeni/config";
|
|
@@ -7229,13 +7276,16 @@ import {
|
|
|
7229
7276
|
ScheduledTaskRunAcceptedExecution,
|
|
7230
7277
|
normalizeAutomaticSessionTitle,
|
|
7231
7278
|
scheduledOccurrencePayloadUtf8Bytes,
|
|
7232
|
-
stableJson
|
|
7279
|
+
stableJson,
|
|
7280
|
+
TurnExecutionPolicyV1
|
|
7233
7281
|
} from "@opengeni/contracts";
|
|
7234
7282
|
import {
|
|
7235
7283
|
defaultSessionMcpServerIds,
|
|
7236
7284
|
openGeniSlackBotMetadata,
|
|
7237
7285
|
requireOpenGeniSlackBotConnection,
|
|
7286
|
+
resolveWorkspaceCatalogSettings as resolveWorkspaceCatalogSettings2,
|
|
7238
7287
|
resolveSessionToolPolicy,
|
|
7288
|
+
workspaceCustomModelReference,
|
|
7239
7289
|
scheduledSlackBotConnectionId,
|
|
7240
7290
|
swapActiveSandbox
|
|
7241
7291
|
} from "@opengeni/core";
|
|
@@ -7265,6 +7315,8 @@ import {
|
|
|
7265
7315
|
getVariableSet,
|
|
7266
7316
|
isCodexBilledModel,
|
|
7267
7317
|
initializeSessionStartAtomically,
|
|
7318
|
+
lockActiveWorkspaceGatewayCustomModelForAdmission,
|
|
7319
|
+
lockActiveWorkspaceOpenRouterCustomModelForAdmission,
|
|
7268
7320
|
materializeScheduledTaskReusableSessionFromRun,
|
|
7269
7321
|
listEnabledMcpCapabilityServerIds,
|
|
7270
7322
|
listInstalledApiIntegrationServerIdsForDelegations,
|
|
@@ -7283,8 +7335,9 @@ import {
|
|
|
7283
7335
|
withSessionActivityRlsContext
|
|
7284
7336
|
} from "@opengeni/db";
|
|
7285
7337
|
import { publishDurableSessionEvents } from "@opengeni/events";
|
|
7286
|
-
import { resolveFirstPartyMcpToolPolicy } from "@opengeni/config";
|
|
7338
|
+
import { resolveFirstPartyMcpToolPolicy, resolveTurnExecutionPolicyV1 as resolveTurnExecutionPolicyV12 } from "@opengeni/config";
|
|
7287
7339
|
import { Context as Context2 } from "@temporalio/activity";
|
|
7340
|
+
import { createHash as createHash5 } from "crypto";
|
|
7288
7341
|
|
|
7289
7342
|
// src/scheduled-alert-occurrence.ts
|
|
7290
7343
|
import { createHash as createHash4 } from "crypto";
|
|
@@ -7420,6 +7473,10 @@ function scheduledTaskRunProducerKey(input, suppliedActivityIdentity) {
|
|
|
7420
7473
|
workflowId: info.workflowExecution.workflowId
|
|
7421
7474
|
})}`;
|
|
7422
7475
|
}
|
|
7476
|
+
function scheduledTaskGeneratedSessionCreateIdempotencyKey(producerKey) {
|
|
7477
|
+
const digest = createHash5("sha256").update("scheduled-task-run\0", "utf8").update(producerKey, "utf8").digest("hex");
|
|
7478
|
+
return `scheduled-task-run:${digest}`;
|
|
7479
|
+
}
|
|
7423
7480
|
function scheduledTaskSessionTitle(taskName) {
|
|
7424
7481
|
return normalizeAutomaticSessionTitle(taskName) ?? "Scheduled run";
|
|
7425
7482
|
}
|
|
@@ -7440,11 +7497,20 @@ async function stampScheduledSessionTitle(db, input) {
|
|
|
7440
7497
|
function createScheduledTaskActivities(services) {
|
|
7441
7498
|
return {
|
|
7442
7499
|
dispatchScheduledTaskRun: async (input) => {
|
|
7443
|
-
const
|
|
7444
|
-
const { settings, db, bus, wakeSessionWorkflow } = service;
|
|
7500
|
+
const baseService = await services();
|
|
7445
7501
|
if (input.triggerType !== "scheduled" && !input.initiator) {
|
|
7446
7502
|
return { action: "blocked", reason: "malformed_manual_trigger" };
|
|
7447
7503
|
}
|
|
7504
|
+
const { db, bus, wakeSessionWorkflow } = baseService;
|
|
7505
|
+
const settingsForTask = async (task2, retainedProductModelId) => (await resolveWorkspaceCatalogSettings2(
|
|
7506
|
+
db,
|
|
7507
|
+
baseService.catalogSourceSettings ?? baseService.settings,
|
|
7508
|
+
{
|
|
7509
|
+
accountId: task2.accountId,
|
|
7510
|
+
workspaceId: task2.workspaceId,
|
|
7511
|
+
...retainedProductModelId !== void 0 ? { retainedProductModelId } : {}
|
|
7512
|
+
}
|
|
7513
|
+
)).settings;
|
|
7448
7514
|
const stableProducerKey = scheduledTaskRunProducerKey(input);
|
|
7449
7515
|
const priorRun = await getScheduledTaskRunByProducerKey(db, {
|
|
7450
7516
|
workspaceId: input.workspaceId,
|
|
@@ -7474,11 +7540,16 @@ function createScheduledTaskActivities(services) {
|
|
|
7474
7540
|
});
|
|
7475
7541
|
}
|
|
7476
7542
|
if (priorRun.status === "queued") {
|
|
7543
|
+
const acceptedPolicy = acceptedExecution.turnExecutionPolicy ? TurnExecutionPolicyV1.parse(acceptedExecution.turnExecutionPolicy) : null;
|
|
7544
|
+
const settings2 = await settingsForTask(
|
|
7545
|
+
acceptedExecution.task,
|
|
7546
|
+
acceptedPolicy?.productModelId ?? acceptedExecution.targetSessionExecution?.model ?? acceptedExecution.resolvedModel
|
|
7547
|
+
);
|
|
7477
7548
|
try {
|
|
7478
7549
|
return await recoverBoundScheduledTaskDispatch({
|
|
7479
7550
|
db,
|
|
7480
7551
|
bus,
|
|
7481
|
-
settings,
|
|
7552
|
+
settings: settings2,
|
|
7482
7553
|
wakeSessionWorkflow,
|
|
7483
7554
|
run: priorRun,
|
|
7484
7555
|
acceptedExecution,
|
|
@@ -7629,6 +7700,14 @@ function createScheduledTaskActivities(services) {
|
|
|
7629
7700
|
throw new Error("scheduled authority classes have different causal humans");
|
|
7630
7701
|
}
|
|
7631
7702
|
const taskAuthoritySubjectId = taskRevisionAuthority?.subjectId ?? taskPersonalResourceAuthoritySubjectId ?? taskConnectionAuthoritySubjectId;
|
|
7703
|
+
const acceptedTargetSessionId = task.runMode === "existing_session" ? task.targetSessionId : task.runMode === "reusable_session" ? task.reusableSessionId : null;
|
|
7704
|
+
const targetSessionExecutionBase = acceptedTargetSessionId ? await getScheduledTargetSessionExecution(
|
|
7705
|
+
db,
|
|
7706
|
+
task.workspaceId,
|
|
7707
|
+
acceptedTargetSessionId,
|
|
7708
|
+
taskAuthoritySubjectId
|
|
7709
|
+
) : null;
|
|
7710
|
+
const settings = await settingsForTask(task, targetSessionExecutionBase?.model);
|
|
7632
7711
|
const model = task.agentConfig.model ?? settings.openaiModel;
|
|
7633
7712
|
const reasoningEffort = task.agentConfig.reasoningEffort ?? settings.openaiReasoningEffort;
|
|
7634
7713
|
let sandboxBackend = task.agentConfig.sandboxBackend ?? settings.sandboxBackend;
|
|
@@ -7678,13 +7757,6 @@ function createScheduledTaskActivities(services) {
|
|
|
7678
7757
|
codexCompactionMode: isCodexBilledModel(model) ? resolveWorkspaceCodexCompactionDefault(workspace.settings) : "portable"
|
|
7679
7758
|
};
|
|
7680
7759
|
})() : null;
|
|
7681
|
-
const acceptedTargetSessionId = generatedTarget ? null : task.runMode === "existing_session" ? task.targetSessionId : task.reusableSessionId;
|
|
7682
|
-
const targetSessionExecutionBase = acceptedTargetSessionId ? await getScheduledTargetSessionExecution(
|
|
7683
|
-
db,
|
|
7684
|
-
task.workspaceId,
|
|
7685
|
-
acceptedTargetSessionId,
|
|
7686
|
-
taskAuthoritySubjectId
|
|
7687
|
-
) : null;
|
|
7688
7760
|
const targetSessionExecution = targetSessionExecutionBase ? await (async () => {
|
|
7689
7761
|
const [capabilityServerIds, apiIntegrationServerIds] = await Promise.all([
|
|
7690
7762
|
listEnabledMcpCapabilityServerIds(db, task.workspaceId),
|
|
@@ -7839,20 +7911,53 @@ function createScheduledTaskActivities(services) {
|
|
|
7839
7911
|
if ((acceptedVariableSet?.scope === "user" || acceptedRig?.scope === "user") && !causalHumanSubjectId) {
|
|
7840
7912
|
throw new Error("scheduled personal-resource execution has no causal human");
|
|
7841
7913
|
}
|
|
7842
|
-
const admissionDenial = await agentRunAdmissionDenial(
|
|
7843
|
-
|
|
7844
|
-
|
|
7845
|
-
|
|
7846
|
-
|
|
7847
|
-
|
|
7914
|
+
const admissionDenial = await agentRunAdmissionDenial(
|
|
7915
|
+
{ ...baseService, settings },
|
|
7916
|
+
{
|
|
7917
|
+
accountId: task.accountId,
|
|
7918
|
+
workspaceId: task.workspaceId,
|
|
7919
|
+
model: targetSessionExecution?.model ?? model,
|
|
7920
|
+
requestedAgentRuns: input.agentRunUsageIdempotencyKey ? 0 : 1
|
|
7921
|
+
}
|
|
7922
|
+
);
|
|
7848
7923
|
if (admissionDenial) {
|
|
7849
7924
|
return { action: "blocked", reason: admissionDenial };
|
|
7850
7925
|
}
|
|
7926
|
+
const acceptedModel = targetSessionExecution?.model ?? model;
|
|
7927
|
+
const acceptedReasoningEffort = targetSessionExecution?.reasoningEffort ?? reasoningEffort;
|
|
7928
|
+
const acceptedLatencyMode = targetSessionExecution?.latencyMode ?? "standard";
|
|
7929
|
+
const acceptedCustomModel = generatedTarget ? workspaceCustomModelReference(settings, acceptedModel) : null;
|
|
7930
|
+
const beforeFreshAgentRunCommit = acceptedCustomModel ? async (tx) => {
|
|
7931
|
+
const active = acceptedCustomModel.providerKind === "openrouter" ? await lockActiveWorkspaceOpenRouterCustomModelForAdmission(tx, {
|
|
7932
|
+
accountId: task.accountId,
|
|
7933
|
+
workspaceId: task.workspaceId,
|
|
7934
|
+
upstreamModelId: acceptedCustomModel.upstreamModelId
|
|
7935
|
+
}) : await lockActiveWorkspaceGatewayCustomModelForAdmission(tx, {
|
|
7936
|
+
accountId: task.accountId,
|
|
7937
|
+
workspaceId: task.workspaceId,
|
|
7938
|
+
upstreamModelId: acceptedCustomModel.upstreamModelId
|
|
7939
|
+
});
|
|
7940
|
+
if (!active) {
|
|
7941
|
+
throw new ScheduledRunTerminalAuthorityError(
|
|
7942
|
+
"scheduled_model_unavailable",
|
|
7943
|
+
`model is not available: ${acceptedModel}`
|
|
7944
|
+
);
|
|
7945
|
+
}
|
|
7946
|
+
} : void 0;
|
|
7947
|
+
const turnExecutionPolicy = resolveTurnExecutionPolicyV12(settings, {
|
|
7948
|
+
modelId: acceptedModel,
|
|
7949
|
+
requestedModelId: generatedTarget && task.agentConfig.model ? task.agentConfig.model : null,
|
|
7950
|
+
modelSource: generatedTarget ? task.agentConfig.model ? "explicit" : "deployment" : "session",
|
|
7951
|
+
reasoningEffort: acceptedReasoningEffort,
|
|
7952
|
+
reasoningSource: generatedTarget ? task.agentConfig.reasoningEffort ? "explicit" : "deployment" : "session",
|
|
7953
|
+
latencyMode: acceptedLatencyMode,
|
|
7954
|
+
latencyModeSource: generatedTarget ? "deployment" : "session"
|
|
7955
|
+
});
|
|
7851
7956
|
const deferredEvents = [];
|
|
7852
7957
|
const executeDispatch = async (dispatchDb, deferPublications) => {
|
|
7853
7958
|
const admittedRunId = crypto.randomUUID();
|
|
7854
7959
|
const generatedSessionBinding = generatedTarget ? {
|
|
7855
|
-
createIdempotencyKey: alertResponderSessionCreateIdempotencyKey ?? (task.runMode === "reusable_session" ? `scheduled-task-reusable:${task.id}:${task.authorityRevision}:${task.executionDigest}` :
|
|
7960
|
+
createIdempotencyKey: alertResponderSessionCreateIdempotencyKey ?? (task.runMode === "reusable_session" ? `scheduled-task-reusable:${task.id}:${task.authorityRevision}:${task.executionDigest}` : scheduledTaskGeneratedSessionCreateIdempotencyKey(stableProducerKey)),
|
|
7856
7961
|
effectiveMaxNestedAgentDepth: generatedSessionDepthPolicy.effectiveMaxNestedAgentDepth,
|
|
7857
7962
|
nestedAgentDepthPolicySource: generatedSessionDepthPolicy.nestedAgentDepthPolicySource,
|
|
7858
7963
|
codexCompactionMode: generatedSessionDepthPolicy.codexCompactionMode
|
|
@@ -7863,6 +7968,7 @@ function createScheduledTaskActivities(services) {
|
|
|
7863
7968
|
resolvedModel: model,
|
|
7864
7969
|
resolvedReasoningEffort: reasoningEffort,
|
|
7865
7970
|
resolvedLatencyMode: "standard",
|
|
7971
|
+
turnExecutionPolicy,
|
|
7866
7972
|
resolvedSandboxBackend: sandboxBackend,
|
|
7867
7973
|
resolvedSandboxOs: sandboxOs,
|
|
7868
7974
|
resolvedTools: taskTools,
|
|
@@ -7917,7 +8023,8 @@ function createScheduledTaskActivities(services) {
|
|
|
7917
8023
|
triggerType: input.triggerType,
|
|
7918
8024
|
producerKey: stableProducerKey,
|
|
7919
8025
|
scheduledAt: null,
|
|
7920
|
-
acceptedExecutionSnapshot: acceptedExecution
|
|
8026
|
+
acceptedExecutionSnapshot: acceptedExecution,
|
|
8027
|
+
...beforeFreshAgentRunCommit ? { beforeFreshAgentRunCommit } : {}
|
|
7921
8028
|
});
|
|
7922
8029
|
await recordScheduledTaskFiredUsage(dispatchDb, acceptedExecution, run);
|
|
7923
8030
|
if (run.status === "failed" && run.error === "scheduled_authority_exhausted") {
|
|
@@ -8562,6 +8669,10 @@ function createScheduledTaskActivities(services) {
|
|
|
8562
8669
|
if (error instanceof IncidentTelemetryPreflightBlockedError) {
|
|
8563
8670
|
return { action: "blocked", reason: error.reason };
|
|
8564
8671
|
}
|
|
8672
|
+
const terminalError = scheduledRunRecoveryTerminalError(error);
|
|
8673
|
+
if (terminalError?.code === "scheduled_model_unavailable") {
|
|
8674
|
+
return scheduledRunTerminalResult(terminalError.code);
|
|
8675
|
+
}
|
|
8565
8676
|
throw error;
|
|
8566
8677
|
}
|
|
8567
8678
|
if (dispatchOutcome.kind === "replay") {
|
|
@@ -9252,7 +9363,7 @@ function knowledgeSourceSyncEffectivelyPaused(task) {
|
|
|
9252
9363
|
}
|
|
9253
9364
|
|
|
9254
9365
|
// src/activities/site-auth-maintenance.ts
|
|
9255
|
-
import { resolveTurnExecutionPolicyV1 as
|
|
9366
|
+
import { resolveTurnExecutionPolicyV1 as resolveTurnExecutionPolicyV13 } from "@opengeni/config";
|
|
9256
9367
|
import {
|
|
9257
9368
|
DEFAULT_FIRST_PARTY_MCP_PERMISSIONS as DEFAULT_FIRST_PARTY_MCP_PERMISSIONS2,
|
|
9258
9369
|
SITE_AUTH_MAINTENANCE_CONNECTION_CONTEXT_KEY,
|
|
@@ -9262,7 +9373,8 @@ import {
|
|
|
9262
9373
|
assertWorkspaceModelPolicyAllows as assertWorkspaceModelPolicyAllows2,
|
|
9263
9374
|
canonicalConfiguredModel as canonicalConfiguredModel2,
|
|
9264
9375
|
createAndStartSessionWithOutcome as createAndStartSessionWithOutcome2,
|
|
9265
|
-
recordWorkspaceUsage as recordWorkspaceUsage2
|
|
9376
|
+
recordWorkspaceUsage as recordWorkspaceUsage2,
|
|
9377
|
+
resolveCatalogSettings as resolveCatalogSettings2
|
|
9266
9378
|
} from "@opengeni/core";
|
|
9267
9379
|
import {
|
|
9268
9380
|
claimSiteAuthMaintenance,
|
|
@@ -9338,23 +9450,20 @@ function createSiteAuthMaintenanceActivities(services, options = {}) {
|
|
|
9338
9450
|
return { maintainSiteAuthConnections };
|
|
9339
9451
|
}
|
|
9340
9452
|
async function dispatchMaintenanceSession(service, maintenance, dependencies) {
|
|
9341
|
-
const
|
|
9453
|
+
const catalogSettings = (await resolveCatalogSettings2(service.db, service.catalogSourceSettings ?? service.settings)).settings;
|
|
9454
|
+
const catalogService = { ...service, settings: catalogSettings };
|
|
9455
|
+
const model = canonicalConfiguredModel2(catalogSettings, catalogSettings.openaiModel);
|
|
9342
9456
|
if (!model) throw new Error("site auth maintenance has no configured model");
|
|
9343
|
-
await dependencies.assertModelPolicy(
|
|
9344
|
-
|
|
9345
|
-
service.settings,
|
|
9346
|
-
maintenance.workspaceId,
|
|
9347
|
-
model
|
|
9348
|
-
);
|
|
9349
|
-
const denial = await dependencies.admit(service, {
|
|
9457
|
+
await dependencies.assertModelPolicy(service.db, catalogSettings, maintenance.workspaceId, model);
|
|
9458
|
+
const denial = await dependencies.admit(catalogService, {
|
|
9350
9459
|
accountId: maintenance.accountId,
|
|
9351
9460
|
workspaceId: maintenance.workspaceId,
|
|
9352
9461
|
model,
|
|
9353
9462
|
requestedAgentRuns: 1
|
|
9354
9463
|
});
|
|
9355
9464
|
if (denial) throw new Error(`site auth maintenance admission denied: ${denial}`);
|
|
9356
|
-
const reasoningEffort =
|
|
9357
|
-
const turnExecutionPolicy =
|
|
9465
|
+
const reasoningEffort = catalogSettings.openaiReasoningEffort;
|
|
9466
|
+
const turnExecutionPolicy = resolveTurnExecutionPolicyV13(catalogSettings, {
|
|
9358
9467
|
modelId: model,
|
|
9359
9468
|
requestedModelId: null,
|
|
9360
9469
|
modelSource: "deployment",
|
|
@@ -9391,7 +9500,7 @@ async function dispatchMaintenanceSession(service, maintenance, dependencies) {
|
|
|
9391
9500
|
model,
|
|
9392
9501
|
reasoningEffort,
|
|
9393
9502
|
turnExecutionPolicy,
|
|
9394
|
-
sandboxBackend:
|
|
9503
|
+
sandboxBackend: catalogSettings.sandboxBackend,
|
|
9395
9504
|
metadata: {
|
|
9396
9505
|
role: "site_auth_maintenance",
|
|
9397
9506
|
[SITE_AUTH_MAINTENANCE_CONNECTION_CONTEXT_KEY]: maintenance.siteAuthConnectionId,
|
|
@@ -9415,7 +9524,7 @@ async function dispatchMaintenanceSession(service, maintenance, dependencies) {
|
|
|
9415
9524
|
});
|
|
9416
9525
|
try {
|
|
9417
9526
|
await dependencies.recordUsage(
|
|
9418
|
-
{ db: service.db, settings:
|
|
9527
|
+
{ db: service.db, settings: catalogSettings },
|
|
9419
9528
|
{
|
|
9420
9529
|
accountId: maintenance.accountId,
|
|
9421
9530
|
workspaceId: maintenance.workspaceId,
|
|
@@ -9937,4 +10046,4 @@ export {
|
|
|
9937
10046
|
createControlActivities,
|
|
9938
10047
|
createControlActivitiesFromServices
|
|
9939
10048
|
};
|
|
9940
|
-
//# sourceMappingURL=activities-control-
|
|
10049
|
+
//# sourceMappingURL=activities-control-SGU2WEVB.js.map
|