@opengeni/worker-bundle 0.16.29 → 0.20.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 +12 -0
- package/dist/activities/agent-turn.d.ts +110 -19
- package/dist/activities/api-integrations.d.ts +21 -0
- package/dist/activities/browser-state-artifact-reaper.d.ts +29 -0
- package/dist/activities/capabilities.d.ts +6 -0
- package/dist/activities/codemode-dispatcher.d.ts +35 -0
- package/dist/activities/codemode-token-renewal.d.ts +23 -0
- package/dist/activities/codex-capacity.d.ts +6 -5
- package/dist/activities/codex-image-generation.d.ts +21 -0
- package/dist/activities/context-compaction.d.ts +1 -0
- package/dist/activities/documents.d.ts +3 -2
- package/dist/activities/environment.d.ts +17 -8
- package/dist/activities/expiring-material-renewal.d.ts +1 -1
- package/dist/activities/file-upload-reaper.d.ts +7 -2
- package/dist/activities/gateway-image-generation.d.ts +39 -0
- package/dist/activities/gateway-video-generation.d.ts +53 -0
- package/dist/activities/generated-images.d.ts +112 -0
- package/dist/activities/git-credential-renewal.d.ts +1 -1
- package/dist/activities/goals.d.ts +2 -2
- package/dist/activities/google-drive-changes.d.ts +99 -0
- package/dist/activities/image-generation-operation.d.ts +74 -0
- package/dist/activities/image-generation-references.d.ts +25 -0
- package/dist/activities/knowledge-source-sync-driver.d.ts +23 -0
- package/dist/activities/knowledge-source-sync.d.ts +75 -0
- package/dist/activities/packs.d.ts +21 -36
- package/dist/activities/parent-wake.d.ts +1 -1
- package/dist/activities/retained-screenshot-reaper.d.ts +2 -2
- package/dist/activities/retained-screenshots.d.ts +36 -0
- package/dist/activities/rig-verification.d.ts +82 -5
- package/dist/activities/run-credential-renewal.d.ts +1 -1
- package/dist/activities/run-input.d.ts +3 -1
- package/dist/activities/sandbox-images.d.ts +14 -0
- package/dist/activities/sandbox-lease.d.ts +47 -9
- package/dist/activities/scheduled-tasks.d.ts +2 -2
- package/dist/activities/session-state.d.ts +7 -5
- package/dist/activities/site-auth-maintenance.d.ts +27 -0
- package/dist/activities/streaming.d.ts +1 -1
- package/dist/activities/types.d.ts +87 -5
- package/dist/activities/video-generation-admission.d.ts +43 -0
- package/dist/activities/video-generation-credential.d.ts +24 -0
- package/dist/activities/video-generation-reconciliation.d.ts +13 -0
- package/dist/activities/video-media-validation.d.ts +34 -0
- package/dist/activities/video-output-retention.d.ts +36 -0
- package/dist/activities/video-reference-staging.d.ts +55 -0
- package/dist/activities/workflow-wake.d.ts +2 -2
- package/dist/activities/workspace-capture.d.ts +10 -1
- package/dist/activities/xai-auth.d.ts +23 -0
- package/dist/activities/xai-image-generation.d.ts +26 -0
- package/dist/activities/xai-video-generation.d.ts +18 -0
- package/dist/activities-control-XURE4VKN.js +7221 -0
- package/dist/activities-control-XURE4VKN.js.map +1 -0
- package/dist/activities-control.d.ts +297 -0
- package/dist/activities-turn-6EBXGGLS.js +16036 -0
- package/dist/activities-turn-6EBXGGLS.js.map +1 -0
- package/dist/activities-turn.d.ts +17 -0
- package/dist/activities.d.ts +138 -150
- package/dist/activity-services.d.ts +10 -0
- package/dist/artifact-materializer-entry.d.ts +6 -0
- package/dist/artifact-materializer-entry.js +2662 -0
- package/dist/artifact-materializer-entry.js.map +1 -0
- package/dist/artifact-outbox-entry.d.ts +2 -0
- package/dist/artifact-outbox-entry.js +681 -0
- package/dist/artifact-outbox-entry.js.map +1 -0
- package/dist/chunk-5GRJIP5H.js +3092 -0
- package/dist/chunk-5GRJIP5H.js.map +1 -0
- package/dist/chunk-GRFQTTSQ.js +448 -0
- package/dist/chunk-GRFQTTSQ.js.map +1 -0
- package/dist/chunk-TYNPCG4U.js +906 -0
- package/dist/chunk-TYNPCG4U.js.map +1 -0
- package/dist/concurrency.d.ts +108 -5
- package/dist/editable-artifact-hint-broker.d.ts +49 -0
- package/dist/editable-artifact-materializer-launcher.d.ts +49 -0
- package/dist/editable-artifact-materializer-service.d.ts +108 -0
- package/dist/editable-artifact-materializer-storage.d.ts +12 -0
- package/dist/editable-artifact-materializer-subprocess.d.ts +50 -0
- package/dist/editable-artifact-materializer.d.ts +262 -0
- package/dist/editable-artifact-outbox-dispatcher.d.ts +44 -0
- package/dist/editable-artifact-outbox-service.d.ts +70 -0
- package/dist/host-export.d.ts +1 -1
- package/dist/index.d.ts +189 -10
- package/dist/index.js +715 -17380
- package/dist/index.js.map +1 -1
- package/dist/memory-pressure-guard.d.ts +57 -0
- package/dist/model-checkpoint-memory-collector.d.ts +23 -0
- package/dist/model-context-contributions.d.ts +40 -0
- package/dist/observability-metrics.d.ts +53 -1
- package/dist/sandbox-reaper-contract.d.ts +40 -0
- package/dist/sandbox-reaper-timeout.d.ts +14 -0
- package/dist/sandbox-resume.d.ts +34 -7
- package/dist/sandbox-routing.d.ts +6 -0
- package/dist/worker-service-lifecycle.d.ts +6 -2
- package/dist/workflow-bundle.js +1094 -370
- package/dist/workflows/activities.d.ts +8 -2
- package/dist/workflows/document-index.d.ts +1 -1
- package/dist/workflows/knowledge-source-sync.d.ts +13 -0
- package/dist/workflows/rig-verification.d.ts +1 -1
- package/dist/workflows/sandbox-reaper.d.ts +8 -0
- package/dist/workflows/scheduled-tasks.d.ts +1 -1
- package/dist/workflows/session.d.ts +2 -2
- package/dist/workflows/site-auth-maintenance.d.ts +2 -0
- package/dist/workflows/video-generation.d.ts +10 -0
- package/dist/workflows/workflow-wake.d.ts +1 -1
- package/dist/workflows.d.ts +10 -7
- package/package.json +35 -15
- package/src/activities/agent-run-admission.ts +76 -0
- package/src/activities/agent-turn.ts +2600 -340
- package/src/activities/api-integrations.ts +138 -0
- package/src/activities/browser-state-artifact-reaper.ts +120 -0
- package/src/activities/capabilities.ts +10 -0
- package/src/activities/codemode-dispatcher.ts +335 -0
- package/src/activities/codemode-token-renewal.ts +64 -0
- package/src/activities/codex-capacity.ts +54 -7
- package/src/activities/codex-image-generation.ts +56 -0
- package/src/activities/context-compaction.ts +38 -3
- package/src/activities/documents.ts +14 -4
- package/src/activities/environment.ts +54 -45
- package/src/activities/expiring-material-renewal.ts +1 -1
- package/src/activities/file-upload-reaper.ts +34 -3
- package/src/activities/gateway-image-generation.ts +146 -0
- package/src/activities/gateway-video-generation.ts +298 -0
- package/src/activities/generated-images.ts +860 -0
- package/src/activities/goals.ts +8 -3
- package/src/activities/google-drive-changes.ts +454 -0
- package/src/activities/image-generation-operation.ts +333 -0
- package/src/activities/image-generation-references.ts +118 -0
- package/src/activities/knowledge-source-sync-driver.ts +27 -0
- package/src/activities/knowledge-source-sync.ts +2840 -0
- package/src/activities/mcp-credentials.ts +1 -0
- package/src/activities/packs.ts +75 -152
- package/src/activities/parent-wake.ts +13 -1
- package/src/activities/retained-screenshot-reaper.ts +2 -2
- package/src/activities/retained-screenshots.ts +453 -28
- package/src/activities/rig-verification.ts +554 -43
- package/src/activities/run-input.ts +22 -6
- package/src/activities/sandbox-images.ts +167 -0
- package/src/activities/sandbox-lease.ts +1065 -483
- package/src/activities/scheduled-tasks.ts +104 -74
- package/src/activities/session-state.ts +22 -4
- package/src/activities/site-auth-maintenance.ts +269 -0
- package/src/activities/streaming.ts +42 -3
- package/src/activities/types.ts +104 -5
- package/src/activities/video-generation-admission.ts +303 -0
- package/src/activities/video-generation-credential.ts +112 -0
- package/src/activities/video-generation-reconciliation.ts +771 -0
- package/src/activities/video-media-validation.ts +332 -0
- package/src/activities/video-output-retention.ts +314 -0
- package/src/activities/video-reference-staging.ts +350 -0
- package/src/activities/workflow-wake.ts +2 -2
- package/src/activities/workspace-capture.ts +44 -10
- package/src/activities/xai-auth.ts +122 -0
- package/src/activities/xai-image-generation.ts +86 -0
- package/src/activities/xai-video-generation.ts +69 -0
- package/src/activities-control.ts +58 -0
- package/src/activities-turn.ts +40 -0
- package/src/activities.ts +53 -124
- package/src/activity-services.ts +62 -0
- package/src/artifact-materializer-entry.ts +35 -0
- package/src/artifact-outbox-entry.ts +29 -0
- package/src/concurrency.ts +484 -6
- package/src/editable-artifact-hint-broker.ts +235 -0
- package/src/editable-artifact-materializer-launcher.ts +515 -0
- package/src/editable-artifact-materializer-service.ts +787 -0
- package/src/editable-artifact-materializer-storage.ts +413 -0
- package/src/editable-artifact-materializer-subprocess.ts +956 -0
- package/src/editable-artifact-materializer.ts +1289 -0
- package/src/editable-artifact-outbox-dispatcher.ts +244 -0
- package/src/editable-artifact-outbox-service.ts +438 -0
- package/src/index.ts +328 -72
- package/src/memory-pressure-guard.ts +489 -0
- package/src/model-checkpoint-memory-collector.ts +123 -0
- package/src/model-context-contributions.ts +159 -0
- package/src/observability-metrics.ts +297 -13
- package/src/sandbox-reaper-contract.ts +73 -0
- package/src/sandbox-reaper-timeout.ts +79 -0
- package/src/sandbox-resume.ts +294 -153
- package/src/sandbox-routing.ts +32 -24
- package/src/worker-service-lifecycle.ts +80 -14
- package/src/workflows/activities.ts +31 -0
- package/src/workflows/file-upload-reaper.ts +9 -1
- package/src/workflows/knowledge-source-sync.ts +83 -0
- package/src/workflows/sandbox-reaper.ts +183 -21
- package/src/workflows/scheduled-tasks.ts +42 -6
- package/src/workflows/session.ts +20 -6
- package/src/workflows/site-auth-maintenance.ts +14 -0
- package/src/workflows/video-generation.ts +36 -0
- package/src/workflows.ts +18 -1
- package/dist/activities/toolspace-token-renewal.d.ts +0 -23
- package/src/activities/toolspace-token-renewal.ts +0 -64
|
@@ -15,47 +15,50 @@ import {
|
|
|
15
15
|
createSession,
|
|
16
16
|
createSessionGoal,
|
|
17
17
|
enqueueSessionWorkflowWakeIfRunnable,
|
|
18
|
-
getBillingBalance,
|
|
19
18
|
getScheduledTask,
|
|
19
|
+
ensureKnowledgeSourceSyncState,
|
|
20
20
|
getScheduledTaskPersonalConnectionDelegations,
|
|
21
|
+
getScheduledTaskXaiProviderAccountAuthoritySnapshot,
|
|
21
22
|
getRig,
|
|
22
23
|
getVariableSet,
|
|
23
|
-
isCodexBilledTurn,
|
|
24
24
|
markScheduledTaskRunFailedIfQueued,
|
|
25
|
+
recordKnowledgeSourceSyncWake,
|
|
25
26
|
recordUsageEvent,
|
|
26
27
|
requireScheduledTaskTargetInTransaction,
|
|
27
28
|
requireSession,
|
|
28
29
|
setTemporalWorkflowId,
|
|
29
30
|
settleScheduledTaskRunInTransaction,
|
|
30
31
|
SessionSpawnDeniedDbError,
|
|
31
|
-
sumUsageQuantity,
|
|
32
32
|
updateScheduledTask,
|
|
33
|
+
updateScheduledTaskRun,
|
|
33
34
|
upsertSessionGoal,
|
|
34
35
|
} from "@opengeni/db";
|
|
35
36
|
import { appendAndPublishEvents, publishDurableSessionEvents } from "@opengeni/events";
|
|
36
|
-
import {
|
|
37
|
+
import { resolveFirstPartyMcpToolPolicy } from "@opengeni/config";
|
|
37
38
|
import {
|
|
38
39
|
assertReusableSessionRevivable,
|
|
39
40
|
scheduledUserMessagePayload,
|
|
40
41
|
workflowIdForSession,
|
|
41
42
|
} from "./common";
|
|
42
43
|
import { withFirstPartyTools } from "./goals";
|
|
44
|
+
import { agentRunAdmissionDenial } from "./agent-run-admission";
|
|
43
45
|
import type {
|
|
44
|
-
|
|
46
|
+
ControlActivityServices,
|
|
45
47
|
DispatchScheduledTaskRunInput,
|
|
46
48
|
DispatchScheduledTaskRunResult,
|
|
47
49
|
} from "./types";
|
|
48
50
|
|
|
49
|
-
export function createScheduledTaskActivities(services: () => Promise<
|
|
51
|
+
export function createScheduledTaskActivities(services: () => Promise<ControlActivityServices>) {
|
|
50
52
|
return {
|
|
51
53
|
dispatchScheduledTaskRun: async (
|
|
52
54
|
input: DispatchScheduledTaskRunInput,
|
|
53
55
|
): Promise<DispatchScheduledTaskRunResult> => {
|
|
54
|
-
const
|
|
56
|
+
const service = await services();
|
|
57
|
+
const { settings, db, bus, wakeSessionWorkflow } = service;
|
|
55
58
|
// Histories created before the manual-initiator workflow patch already
|
|
56
59
|
// contain this activity command. Reject their incomplete wire input here
|
|
57
60
|
// so replay consumes the recorded command and the retry loop settles.
|
|
58
|
-
if (input.triggerType
|
|
61
|
+
if (input.triggerType !== "scheduled" && !input.initiator) {
|
|
59
62
|
return { action: "blocked", reason: "malformed_manual_trigger" };
|
|
60
63
|
}
|
|
61
64
|
const task = await getScheduledTask(db, input.workspaceId, input.taskId);
|
|
@@ -65,11 +68,71 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
65
68
|
if (!task) {
|
|
66
69
|
return { action: "deleted" };
|
|
67
70
|
}
|
|
71
|
+
if (task.action.kind === "knowledge_source_sync") {
|
|
72
|
+
if (knowledgeSourceSyncEffectivelyPaused(task)) {
|
|
73
|
+
return { action: "blocked", reason: "knowledge_source_paused" };
|
|
74
|
+
}
|
|
75
|
+
const run = await createScheduledTaskRun(db, {
|
|
76
|
+
workspaceId: task.workspaceId,
|
|
77
|
+
taskId: task.id,
|
|
78
|
+
triggerType: input.triggerType,
|
|
79
|
+
producerKey:
|
|
80
|
+
input.producerKey ??
|
|
81
|
+
input.agentRunUsageIdempotencyKey ??
|
|
82
|
+
`knowledge-source-sync:${crypto.randomUUID()}`,
|
|
83
|
+
scheduledAt: null,
|
|
84
|
+
});
|
|
85
|
+
await ensureKnowledgeSourceSyncState(db, task);
|
|
86
|
+
await recordKnowledgeSourceSyncWake(db, {
|
|
87
|
+
accountId: task.accountId,
|
|
88
|
+
workspaceId: task.workspaceId,
|
|
89
|
+
sourceId: task.action.sourceId,
|
|
90
|
+
scheduledTaskId: task.id,
|
|
91
|
+
scheduledTaskRunId: run.id,
|
|
92
|
+
cause: input.triggerType,
|
|
93
|
+
producerKey:
|
|
94
|
+
input.producerKey ??
|
|
95
|
+
input.agentRunUsageIdempotencyKey ??
|
|
96
|
+
`knowledge-source-sync:${run.id}`,
|
|
97
|
+
sourceConfigGeneration: task.action.sourceConfigGeneration,
|
|
98
|
+
sourceLifecycleGeneration: task.action.sourceLifecycleGeneration,
|
|
99
|
+
});
|
|
100
|
+
await recordUsageEvent(db, {
|
|
101
|
+
accountId: task.accountId,
|
|
102
|
+
workspaceId: task.workspaceId,
|
|
103
|
+
eventType: "knowledge_source_sync.fired",
|
|
104
|
+
quantity: 1,
|
|
105
|
+
unit: "run",
|
|
106
|
+
sourceResourceType: "scheduled_task_run",
|
|
107
|
+
sourceResourceId: run.id,
|
|
108
|
+
initiator: input.initiator ?? { kind: "service", subjectId: "scheduler" },
|
|
109
|
+
initiatorContext: { scheduledTaskId: task.id, scheduledTaskRunId: run.id },
|
|
110
|
+
origin: "scheduled_task",
|
|
111
|
+
idempotencyKey: `usage:knowledge_source_sync.fired:${run.id}`,
|
|
112
|
+
});
|
|
113
|
+
if (run.status === "queued") {
|
|
114
|
+
await updateScheduledTaskRun(db, task.workspaceId, run.id, {
|
|
115
|
+
status: "dispatched",
|
|
116
|
+
actionKind: "knowledge_source_sync",
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
return {
|
|
120
|
+
action: "knowledge_source_sync",
|
|
121
|
+
accountId: task.accountId,
|
|
122
|
+
workspaceId: task.workspaceId,
|
|
123
|
+
taskId: task.id,
|
|
124
|
+
scheduledTaskRunId: run.id,
|
|
125
|
+
sourceId: task.action.sourceId,
|
|
126
|
+
overlapPolicy: task.overlapPolicy as "skip" | "buffer_one",
|
|
127
|
+
};
|
|
128
|
+
}
|
|
68
129
|
const taskPersonalConnectionDelegations = await getScheduledTaskPersonalConnectionDelegations(
|
|
69
130
|
db,
|
|
70
131
|
task.workspaceId,
|
|
71
132
|
task.id,
|
|
72
133
|
);
|
|
134
|
+
const taskXaiProviderAccountAuthoritySnapshot =
|
|
135
|
+
await getScheduledTaskXaiProviderAccountAuthoritySnapshot(db, task.workspaceId, task.id);
|
|
73
136
|
// A scheduled bot selection was authorized when the task was written,
|
|
74
137
|
// but connection status and tenant/role binding are mutable. Revalidate
|
|
75
138
|
// before any session/model cost and never fall back to a personal Slack
|
|
@@ -87,25 +150,13 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
87
150
|
if (slackBotConnection && !slackBotMetadata) {
|
|
88
151
|
throw new Error("OpenGeni Slack bot connection metadata is invalid");
|
|
89
152
|
}
|
|
90
|
-
// The scheduled task's model can be codex/<slug>; resolve it here so the
|
|
91
|
-
// admission gate can skip the credit/cost gates for a codex-billed run
|
|
92
|
-
// (paid by the user's ChatGPT/Codex plan). This file uses BASE settings (no
|
|
93
|
-
// codex overlay), so the predicate does its own active-credential read.
|
|
94
153
|
const model = task.agentConfig.model ?? settings.openaiModel;
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
settings,
|
|
154
|
+
const admissionDenial = await agentRunAdmissionDenial(service, {
|
|
155
|
+
accountId: task.accountId,
|
|
98
156
|
workspaceId: task.workspaceId,
|
|
99
157
|
model,
|
|
158
|
+
requestedAgentRuns: input.agentRunUsageIdempotencyKey ? 0 : 1,
|
|
100
159
|
});
|
|
101
|
-
const admissionDenial = await scheduledRunAdmissionDenial(
|
|
102
|
-
settings,
|
|
103
|
-
db,
|
|
104
|
-
task.accountId,
|
|
105
|
-
task.workspaceId,
|
|
106
|
-
input.agentRunUsageIdempotencyKey ? 0 : 1,
|
|
107
|
-
isCodexRun,
|
|
108
|
-
);
|
|
109
160
|
if (admissionDenial) {
|
|
110
161
|
return { action: "blocked", reason: admissionDenial };
|
|
111
162
|
}
|
|
@@ -226,6 +277,7 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
226
277
|
initialMessage: task.agentConfig.prompt,
|
|
227
278
|
resources: task.agentConfig.resources,
|
|
228
279
|
tools: taskTools,
|
|
280
|
+
firstPartyMcpTools: resolveFirstPartyMcpToolPolicy(settings).default,
|
|
229
281
|
metadata: {
|
|
230
282
|
...taskMetadata,
|
|
231
283
|
model,
|
|
@@ -253,6 +305,7 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
253
305
|
rigId: frozenRigId,
|
|
254
306
|
rigVersionId: frozenRigVersionId,
|
|
255
307
|
personalConnectionDelegations: taskPersonalConnectionDelegations,
|
|
308
|
+
initialXaiProviderAccountAuthoritySnapshot: taskXaiProviderAccountAuthoritySnapshot,
|
|
256
309
|
maxNestedAgentDepthOverride: task.agentConfig.maxNestedAgentDepth ?? null,
|
|
257
310
|
// The durable agent config was privilege-checked when the task
|
|
258
311
|
// was created/updated. Preserve that explicit policy if a broader
|
|
@@ -343,8 +396,16 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
343
396
|
task.id,
|
|
344
397
|
run.id,
|
|
345
398
|
),
|
|
346
|
-
lineage: {
|
|
399
|
+
lineage: {
|
|
400
|
+
scheduledTaskId: task.id,
|
|
401
|
+
scheduledTaskRunId: run.id,
|
|
402
|
+
...(taskXaiProviderAccountAuthoritySnapshot.scope === "user" &&
|
|
403
|
+
task.createdBy.kind === "subject"
|
|
404
|
+
? { xaiAuthoritySubjectId: task.createdBy.subjectId }
|
|
405
|
+
: {}),
|
|
406
|
+
},
|
|
347
407
|
personalConnectionDelegations: taskPersonalConnectionDelegations,
|
|
408
|
+
xaiProviderAccountAuthoritySnapshot: taskXaiProviderAccountAuthoritySnapshot,
|
|
348
409
|
},
|
|
349
410
|
async (tx, wakeEventId) => {
|
|
350
411
|
if (!wakeEventId) throw new Error("Scheduled delivery has no wake event");
|
|
@@ -439,6 +500,7 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
439
500
|
],
|
|
440
501
|
};
|
|
441
502
|
},
|
|
503
|
+
{ activity: "semantic" },
|
|
442
504
|
);
|
|
443
505
|
await publishDurableSessionEvents(bus, task.workspaceId, session.id, goalEvents);
|
|
444
506
|
}
|
|
@@ -460,8 +522,16 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
460
522
|
task.id,
|
|
461
523
|
run.id,
|
|
462
524
|
),
|
|
463
|
-
lineage: {
|
|
525
|
+
lineage: {
|
|
526
|
+
scheduledTaskId: task.id,
|
|
527
|
+
scheduledTaskRunId: run.id,
|
|
528
|
+
...(taskXaiProviderAccountAuthoritySnapshot.scope === "user" &&
|
|
529
|
+
task.createdBy.kind === "subject"
|
|
530
|
+
? { xaiAuthoritySubjectId: task.createdBy.subjectId }
|
|
531
|
+
: {}),
|
|
532
|
+
},
|
|
464
533
|
personalConnectionDelegations: taskPersonalConnectionDelegations,
|
|
534
|
+
xaiProviderAccountAuthoritySnapshot: taskXaiProviderAccountAuthoritySnapshot,
|
|
465
535
|
},
|
|
466
536
|
async (tx, wakeEventId) => {
|
|
467
537
|
if (task.runMode === "existing_session") {
|
|
@@ -535,53 +605,13 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
535
605
|
};
|
|
536
606
|
}
|
|
537
607
|
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
// credit-balance gate and the monthly model-cost cap. The agent-run COUNT cap
|
|
548
|
-
// below is a volume quota (not a credit/cost gate) and is intentionally kept.
|
|
549
|
-
if (
|
|
550
|
-
!isCodexRun &&
|
|
551
|
-
(settings.billingMode === "stripe" || settings.usageLimitsMode === "managed")
|
|
552
|
-
) {
|
|
553
|
-
const balance = await getBillingBalance(db, accountId);
|
|
554
|
-
if (balance.balanceMicros <= 0) {
|
|
555
|
-
return "insufficient_credits";
|
|
556
|
-
}
|
|
557
|
-
}
|
|
558
|
-
if (settings.usageLimitsMode === "static" || settings.usageLimitsMode === "managed") {
|
|
559
|
-
const limits = configuredStaticUsageLimits(settings);
|
|
560
|
-
if (!isCodexRun && limits.maxMonthlyCostMicrosPerAccount) {
|
|
561
|
-
const used = await sumUsageQuantity(db, {
|
|
562
|
-
accountId,
|
|
563
|
-
eventType: "model.cost",
|
|
564
|
-
since: startOfUtcMonth(),
|
|
565
|
-
});
|
|
566
|
-
if (used >= limits.maxMonthlyCostMicrosPerAccount) {
|
|
567
|
-
return "monthly_model_cost_limit";
|
|
568
|
-
}
|
|
569
|
-
}
|
|
570
|
-
if (limits.maxMonthlyAgentRunsPerWorkspace) {
|
|
571
|
-
const used = await sumUsageQuantity(db, {
|
|
572
|
-
workspaceId,
|
|
573
|
-
eventType: "agent_run.created",
|
|
574
|
-
since: startOfUtcMonth(),
|
|
575
|
-
});
|
|
576
|
-
if (used + requestedAgentRuns > limits.maxMonthlyAgentRunsPerWorkspace) {
|
|
577
|
-
return "monthly_agent_run_limit";
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
}
|
|
581
|
-
return null;
|
|
582
|
-
}
|
|
583
|
-
|
|
584
|
-
function startOfUtcMonth(): Date {
|
|
585
|
-
const now = new Date();
|
|
586
|
-
return new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth(), 1));
|
|
608
|
+
function knowledgeSourceSyncEffectivelyPaused(task: {
|
|
609
|
+
status: "active" | "paused";
|
|
610
|
+
metadata: Record<string, unknown>;
|
|
611
|
+
}): boolean {
|
|
612
|
+
if (task.status === "paused") return true;
|
|
613
|
+
const value = task.metadata.knowledgeSourceSync;
|
|
614
|
+
if (!value || typeof value !== "object") return false;
|
|
615
|
+
const control = value as Record<string, unknown>;
|
|
616
|
+
return control.sourceEnabled === false || control.connectionPaused === true;
|
|
587
617
|
}
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
getSessionAttemptActivityRef,
|
|
10
10
|
getSessionEvent,
|
|
11
11
|
getSessionTurnForAttempt,
|
|
12
|
+
expireSessionInteractionIntervention as expireSessionInteractionInterventionDb,
|
|
12
13
|
expireSessionHumanInputRequest,
|
|
13
14
|
markSessionAttemptQuiesced,
|
|
14
15
|
requireSession,
|
|
@@ -18,9 +19,11 @@ import { publishDurableSessionEvents } from "@opengeni/events";
|
|
|
18
19
|
import { deliverFailedChildTurnToParent, notifyParentOfChildIdle } from "./parent-wake";
|
|
19
20
|
import { recordTurnsQueuedGauge } from "../observability-metrics";
|
|
20
21
|
import type {
|
|
21
|
-
|
|
22
|
+
ControlActivityServices,
|
|
22
23
|
ExpireSessionHumanInputInput,
|
|
23
24
|
ExpireSessionHumanInputResult,
|
|
25
|
+
ExpireSessionInteractionInterventionInput,
|
|
26
|
+
ExpireSessionInteractionInterventionResult,
|
|
24
27
|
PeekSessionWorkInput,
|
|
25
28
|
FailSessionAttemptInput,
|
|
26
29
|
SettleSessionInterruptionsInput,
|
|
@@ -46,6 +49,7 @@ export type SessionStateActivityOverrides = Partial<{
|
|
|
46
49
|
getSessionEvent: typeof getSessionEvent;
|
|
47
50
|
getSessionTurnForAttempt: typeof getSessionTurnForAttempt;
|
|
48
51
|
expireSessionHumanInputRequest: typeof expireSessionHumanInputRequest;
|
|
52
|
+
expireSessionInteractionIntervention: typeof expireSessionInteractionInterventionDb;
|
|
49
53
|
requireSession: typeof requireSession;
|
|
50
54
|
settleSessionIdleWithParentOutbox: typeof settleSessionIdleWithParentOutbox;
|
|
51
55
|
markSessionAttemptQuiesced: typeof markSessionAttemptQuiesced;
|
|
@@ -62,7 +66,7 @@ export type SessionStateActivityOverrides = Partial<{
|
|
|
62
66
|
export const WORKER_DEATH_MAX_REDISPATCHES = 3;
|
|
63
67
|
|
|
64
68
|
export function createSessionStateActivities(
|
|
65
|
-
services: () => Promise<
|
|
69
|
+
services: () => Promise<ControlActivityServices>,
|
|
66
70
|
overrides: SessionStateActivityOverrides = {},
|
|
67
71
|
) {
|
|
68
72
|
const settleSessionAttemptInterruptionsFn =
|
|
@@ -82,6 +86,8 @@ export function createSessionStateActivities(
|
|
|
82
86
|
const getSessionTurnForAttemptFn = overrides.getSessionTurnForAttempt ?? getSessionTurnForAttempt;
|
|
83
87
|
const expireSessionHumanInputRequestFn =
|
|
84
88
|
overrides.expireSessionHumanInputRequest ?? expireSessionHumanInputRequest;
|
|
89
|
+
const expireSessionInteractionInterventionFn =
|
|
90
|
+
overrides.expireSessionInteractionIntervention ?? expireSessionInteractionInterventionDb;
|
|
85
91
|
const requireSessionFn = overrides.requireSession ?? requireSession;
|
|
86
92
|
const settleSessionIdleWithParentOutboxFn =
|
|
87
93
|
overrides.settleSessionIdleWithParentOutbox ?? settleSessionIdleWithParentOutbox;
|
|
@@ -347,6 +353,17 @@ export function createSessionStateActivities(
|
|
|
347
353
|
};
|
|
348
354
|
}
|
|
349
355
|
|
|
356
|
+
async function expireSessionInteractionIntervention(
|
|
357
|
+
input: ExpireSessionInteractionInterventionInput,
|
|
358
|
+
): Promise<ExpireSessionInteractionInterventionResult> {
|
|
359
|
+
const { db, bus } = await services();
|
|
360
|
+
const result = await expireSessionInteractionInterventionFn(db, input);
|
|
361
|
+
if (result.events.length > 0) {
|
|
362
|
+
await publishDurableSessionEventsFn(bus, input.workspaceId, input.sessionId, result.events);
|
|
363
|
+
}
|
|
364
|
+
return { action: result.action };
|
|
365
|
+
}
|
|
366
|
+
|
|
350
367
|
async function markSessionIdle(input: MarkSessionIdleInput): Promise<void> {
|
|
351
368
|
const { db, bus, settings, observability, wakeSessionWorkflow } = await services();
|
|
352
369
|
const settled = await settleSessionIdleWithParentOutboxFn(
|
|
@@ -383,13 +400,14 @@ export function createSessionStateActivities(
|
|
|
383
400
|
recoverEscapedMcpTimeout,
|
|
384
401
|
peekSessionWork,
|
|
385
402
|
expireSessionHumanInput,
|
|
403
|
+
expireSessionInteractionIntervention,
|
|
386
404
|
markSessionIdle,
|
|
387
405
|
};
|
|
388
406
|
}
|
|
389
407
|
|
|
390
408
|
async function refreshQueuedTurnsGauge(
|
|
391
|
-
db:
|
|
392
|
-
observability:
|
|
409
|
+
db: ControlActivityServices["db"],
|
|
410
|
+
observability: ControlActivityServices["observability"],
|
|
393
411
|
countQueuedTurnsFn: typeof countQueuedTurns,
|
|
394
412
|
recordTurnsQueuedGaugeFn: typeof recordTurnsQueuedGauge,
|
|
395
413
|
): Promise<void> {
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { resolveTurnExecutionPolicyV1 } from "@opengeni/config";
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_FIRST_PARTY_MCP_PERMISSIONS,
|
|
4
|
+
SITE_AUTH_MAINTENANCE_CONNECTION_CONTEXT_KEY,
|
|
5
|
+
SITE_AUTH_MAINTENANCE_OPERATION_CONTEXT_KEY,
|
|
6
|
+
type FirstPartyMcpToolName,
|
|
7
|
+
} from "@opengeni/contracts";
|
|
8
|
+
import {
|
|
9
|
+
assertWorkspaceModelPolicyAllows,
|
|
10
|
+
canonicalConfiguredModel,
|
|
11
|
+
createAndStartSessionWithOutcome,
|
|
12
|
+
recordWorkspaceUsage,
|
|
13
|
+
} from "@opengeni/core";
|
|
14
|
+
import {
|
|
15
|
+
claimSiteAuthMaintenance,
|
|
16
|
+
confirmSiteAuthMaintenanceSessionInTransaction,
|
|
17
|
+
deferSiteAuthMaintenance,
|
|
18
|
+
type SiteAuthMaintenanceClaim,
|
|
19
|
+
} from "@opengeni/db";
|
|
20
|
+
import { agentRunAdmissionDenial } from "./agent-run-admission";
|
|
21
|
+
import type { ControlActivityServices } from "./types";
|
|
22
|
+
|
|
23
|
+
export const SITE_AUTH_MAINTENANCE_CLAIM_TIMEOUT_MS = 10 * 60 * 1_000;
|
|
24
|
+
export const SITE_AUTH_MAINTENANCE_BATCH_SIZE = 16;
|
|
25
|
+
|
|
26
|
+
const MAINTENANCE_TOOLS = [
|
|
27
|
+
"interaction_discover",
|
|
28
|
+
"browser_open",
|
|
29
|
+
"browser_tabs",
|
|
30
|
+
"browser_observe",
|
|
31
|
+
"browser_act",
|
|
32
|
+
"browser_debug",
|
|
33
|
+
"browser_auth",
|
|
34
|
+
"interaction_request_human",
|
|
35
|
+
"browser_identity",
|
|
36
|
+
"browser_lifecycle",
|
|
37
|
+
] as const satisfies readonly FirstPartyMcpToolName[];
|
|
38
|
+
|
|
39
|
+
export type MaintainSiteAuthConnectionsResult = {
|
|
40
|
+
claimed: number;
|
|
41
|
+
started: number;
|
|
42
|
+
deferred: number;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
export type SiteAuthMaintenanceOptions = {
|
|
46
|
+
claimTimeoutMs?: number;
|
|
47
|
+
batchSize?: number;
|
|
48
|
+
claim?: typeof claimSiteAuthMaintenance;
|
|
49
|
+
confirm?: typeof confirmSiteAuthMaintenanceSessionInTransaction;
|
|
50
|
+
defer?: typeof deferSiteAuthMaintenance;
|
|
51
|
+
createSession?: typeof createAndStartSessionWithOutcome;
|
|
52
|
+
admit?: typeof agentRunAdmissionDenial;
|
|
53
|
+
recordUsage?: typeof recordWorkspaceUsage;
|
|
54
|
+
assertModelPolicy?: typeof assertWorkspaceModelPolicyAllows;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/** Dispatch bounded, auditable agent sessions for due authentication checks.
|
|
58
|
+
* A hidden claim id/session id pair makes every crash point replayable. */
|
|
59
|
+
export function createSiteAuthMaintenanceActivities(
|
|
60
|
+
services: () => Promise<ControlActivityServices>,
|
|
61
|
+
options: SiteAuthMaintenanceOptions = {},
|
|
62
|
+
) {
|
|
63
|
+
const claimTimeoutMs = options.claimTimeoutMs ?? SITE_AUTH_MAINTENANCE_CLAIM_TIMEOUT_MS;
|
|
64
|
+
const batchSize = options.batchSize ?? SITE_AUTH_MAINTENANCE_BATCH_SIZE;
|
|
65
|
+
const claim = options.claim ?? claimSiteAuthMaintenance;
|
|
66
|
+
const confirm = options.confirm ?? confirmSiteAuthMaintenanceSessionInTransaction;
|
|
67
|
+
const defer = options.defer ?? deferSiteAuthMaintenance;
|
|
68
|
+
const createSession = options.createSession ?? createAndStartSessionWithOutcome;
|
|
69
|
+
const admit = options.admit ?? agentRunAdmissionDenial;
|
|
70
|
+
const recordUsage = options.recordUsage ?? recordWorkspaceUsage;
|
|
71
|
+
const assertModelPolicy = options.assertModelPolicy ?? assertWorkspaceModelPolicyAllows;
|
|
72
|
+
|
|
73
|
+
async function maintainSiteAuthConnections(): Promise<MaintainSiteAuthConnectionsResult> {
|
|
74
|
+
const service = await services();
|
|
75
|
+
const claims = await claim(service.db, { claimTimeoutMs, limit: batchSize });
|
|
76
|
+
const result: MaintainSiteAuthConnectionsResult = {
|
|
77
|
+
claimed: claims.length,
|
|
78
|
+
started: 0,
|
|
79
|
+
deferred: 0,
|
|
80
|
+
};
|
|
81
|
+
for (const maintenance of claims) {
|
|
82
|
+
try {
|
|
83
|
+
await dispatchMaintenanceSession(service, maintenance, {
|
|
84
|
+
confirm,
|
|
85
|
+
createSession,
|
|
86
|
+
admit,
|
|
87
|
+
recordUsage,
|
|
88
|
+
assertModelPolicy,
|
|
89
|
+
});
|
|
90
|
+
result.started += 1;
|
|
91
|
+
} catch (error) {
|
|
92
|
+
const released = await defer(service.db, {
|
|
93
|
+
accountId: maintenance.accountId,
|
|
94
|
+
workspaceId: maintenance.workspaceId,
|
|
95
|
+
siteAuthConnectionId: maintenance.siteAuthConnectionId,
|
|
96
|
+
operationId: maintenance.operationId,
|
|
97
|
+
sessionId: maintenance.sessionId,
|
|
98
|
+
retryAt: maintenanceRetryAt(maintenance),
|
|
99
|
+
}).catch(() => false);
|
|
100
|
+
if (released) result.deferred += 1;
|
|
101
|
+
service.observability.warn("site auth maintenance dispatch deferred", {
|
|
102
|
+
workspaceId: maintenance.workspaceId,
|
|
103
|
+
siteAuthConnectionId: maintenance.siteAuthConnectionId,
|
|
104
|
+
action: maintenance.action,
|
|
105
|
+
errorCategory: maintenanceErrorCategory(error),
|
|
106
|
+
claimReleased: released,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
if (result.claimed > 0) {
|
|
111
|
+
service.observability.info("site auth maintenance swept", result);
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
return { maintainSiteAuthConnections };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async function dispatchMaintenanceSession(
|
|
120
|
+
service: ControlActivityServices,
|
|
121
|
+
maintenance: SiteAuthMaintenanceClaim,
|
|
122
|
+
dependencies: {
|
|
123
|
+
confirm: typeof confirmSiteAuthMaintenanceSessionInTransaction;
|
|
124
|
+
createSession: typeof createAndStartSessionWithOutcome;
|
|
125
|
+
admit: typeof agentRunAdmissionDenial;
|
|
126
|
+
recordUsage: typeof recordWorkspaceUsage;
|
|
127
|
+
assertModelPolicy: typeof assertWorkspaceModelPolicyAllows;
|
|
128
|
+
},
|
|
129
|
+
): Promise<void> {
|
|
130
|
+
const model = canonicalConfiguredModel(service.settings, service.settings.openaiModel);
|
|
131
|
+
if (!model) throw new Error("site auth maintenance has no configured model");
|
|
132
|
+
await dependencies.assertModelPolicy(
|
|
133
|
+
service.db,
|
|
134
|
+
service.settings,
|
|
135
|
+
maintenance.workspaceId,
|
|
136
|
+
model,
|
|
137
|
+
);
|
|
138
|
+
const denial = await dependencies.admit(service, {
|
|
139
|
+
accountId: maintenance.accountId,
|
|
140
|
+
workspaceId: maintenance.workspaceId,
|
|
141
|
+
model,
|
|
142
|
+
requestedAgentRuns: 1,
|
|
143
|
+
});
|
|
144
|
+
if (denial) throw new Error(`site auth maintenance admission denied: ${denial}`);
|
|
145
|
+
const reasoningEffort = service.settings.openaiReasoningEffort;
|
|
146
|
+
const turnExecutionPolicy = resolveTurnExecutionPolicyV1(service.settings, {
|
|
147
|
+
modelId: model,
|
|
148
|
+
requestedModelId: null,
|
|
149
|
+
modelSource: "deployment",
|
|
150
|
+
reasoningEffort,
|
|
151
|
+
reasoningSource: "deployment",
|
|
152
|
+
latencyMode: "standard",
|
|
153
|
+
latencyModeSource: "deployment",
|
|
154
|
+
});
|
|
155
|
+
const created = await dependencies.createSession({
|
|
156
|
+
requestedSessionId: maintenance.sessionId,
|
|
157
|
+
db: service.db,
|
|
158
|
+
bus: service.bus,
|
|
159
|
+
workflowClient: {
|
|
160
|
+
wakeSessionWorkflow: async (input) => {
|
|
161
|
+
await service.wakeSessionWorkflow?.(input);
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
beforeCreateCommit: async (tx, sessionId) => {
|
|
165
|
+
const confirmed = await dependencies.confirm(tx, {
|
|
166
|
+
accountId: maintenance.accountId,
|
|
167
|
+
workspaceId: maintenance.workspaceId,
|
|
168
|
+
siteAuthConnectionId: maintenance.siteAuthConnectionId,
|
|
169
|
+
operationId: maintenance.operationId,
|
|
170
|
+
sessionId,
|
|
171
|
+
});
|
|
172
|
+
if (!confirmed) throw new Error("site auth maintenance claim changed before session start");
|
|
173
|
+
},
|
|
174
|
+
accountId: maintenance.accountId,
|
|
175
|
+
workspaceId: maintenance.workspaceId,
|
|
176
|
+
initialMessage: maintenancePrompt(maintenance),
|
|
177
|
+
resources: [],
|
|
178
|
+
tools: [{ kind: "mcp", id: "opengeni" }],
|
|
179
|
+
toolPolicy: { mode: "explicit", inheritedFromSessionId: null },
|
|
180
|
+
model,
|
|
181
|
+
reasoningEffort,
|
|
182
|
+
turnExecutionPolicy,
|
|
183
|
+
sandboxBackend: service.settings.sandboxBackend,
|
|
184
|
+
metadata: {
|
|
185
|
+
role: "site_auth_maintenance",
|
|
186
|
+
[SITE_AUTH_MAINTENANCE_CONNECTION_CONTEXT_KEY]: maintenance.siteAuthConnectionId,
|
|
187
|
+
[SITE_AUTH_MAINTENANCE_OPERATION_CONTEXT_KEY]: maintenance.operationId,
|
|
188
|
+
},
|
|
189
|
+
createdBy: {
|
|
190
|
+
kind: "service",
|
|
191
|
+
subjectId: "site-auth-maintenance",
|
|
192
|
+
label: "OpenGeni authentication maintenance",
|
|
193
|
+
},
|
|
194
|
+
createdByContext: {
|
|
195
|
+
[SITE_AUTH_MAINTENANCE_CONNECTION_CONTEXT_KEY]: maintenance.siteAuthConnectionId,
|
|
196
|
+
[SITE_AUTH_MAINTENANCE_OPERATION_CONTEXT_KEY]: maintenance.operationId,
|
|
197
|
+
},
|
|
198
|
+
instructions:
|
|
199
|
+
"Complete only the exact browser-auth maintenance run in the initial request. Use the canonical browser/auth tools, preserve their causal fences, expose no secrets, never publish a BrowserIdentity revision, and do not perform unrelated work.",
|
|
200
|
+
policyRole: "site_auth_maintenance",
|
|
201
|
+
firstPartyMcpPermissions: [...DEFAULT_FIRST_PARTY_MCP_PERMISSIONS],
|
|
202
|
+
firstPartyMcpTools: [...MAINTENANCE_TOOLS],
|
|
203
|
+
createIdempotencyKey: `site-auth-maintenance:${maintenance.operationId}`,
|
|
204
|
+
subjectId: "site-auth-maintenance",
|
|
205
|
+
});
|
|
206
|
+
try {
|
|
207
|
+
await dependencies.recordUsage(
|
|
208
|
+
{ db: service.db, settings: service.settings },
|
|
209
|
+
{
|
|
210
|
+
accountId: maintenance.accountId,
|
|
211
|
+
workspaceId: maintenance.workspaceId,
|
|
212
|
+
subjectId: "site-auth-maintenance",
|
|
213
|
+
eventType: "agent_run.created",
|
|
214
|
+
quantity: 1,
|
|
215
|
+
unit: "run",
|
|
216
|
+
sourceResourceType: "site_auth_connection",
|
|
217
|
+
sourceResourceId: maintenance.siteAuthConnectionId,
|
|
218
|
+
sessionId: created.session.id,
|
|
219
|
+
initiator: created.session.createdBy,
|
|
220
|
+
initiatorContext: created.session.createdByContext,
|
|
221
|
+
origin: "system",
|
|
222
|
+
idempotencyKey: `agent_run.created:site-auth-maintenance:${maintenance.operationId}`,
|
|
223
|
+
},
|
|
224
|
+
);
|
|
225
|
+
} catch (error) {
|
|
226
|
+
service.observability.warn("site auth maintenance usage recording failed", {
|
|
227
|
+
workspaceId: maintenance.workspaceId,
|
|
228
|
+
siteAuthConnectionId: maintenance.siteAuthConnectionId,
|
|
229
|
+
errorCategory: maintenanceErrorCategory(error),
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function maintenancePrompt(maintenance: SiteAuthMaintenanceClaim): string {
|
|
235
|
+
const action = maintenance.action === "repair" ? "repair authentication" : "check authentication";
|
|
236
|
+
return [
|
|
237
|
+
`Perform one scheduled SiteAuthConnection maintenance run: ${action}.`,
|
|
238
|
+
`Connection id: ${maintenance.siteAuthConnectionId}`,
|
|
239
|
+
`Connection: ${maintenance.name} (${maintenance.accountLabel})`,
|
|
240
|
+
`Purpose: ${maintenance.action}`,
|
|
241
|
+
maintenance.loginUrl ? `Login URL: ${maintenance.loginUrl}` : null,
|
|
242
|
+
maintenance.verificationUrlPrefixes.length > 0
|
|
243
|
+
? `Verification URL prefixes: ${maintenance.verificationUrlPrefixes.join(", ")}`
|
|
244
|
+
: "No dedicated verification URL is configured; use the connection's allowed origins.",
|
|
245
|
+
maintenance.preferredIdentityId
|
|
246
|
+
? `Preferred BrowserIdentity: ${maintenance.preferredIdentityId}`
|
|
247
|
+
: "No preferred BrowserIdentity is configured.",
|
|
248
|
+
maintenance.preferredPlacement
|
|
249
|
+
? `Preferred placement: ${JSON.stringify(maintenance.preferredPlacement)}`
|
|
250
|
+
: "Use the normal managed-browser placement.",
|
|
251
|
+
maintenance.preferredNetworkRouteId
|
|
252
|
+
? `Preferred NetworkRoute: ${maintenance.preferredNetworkRouteId}`
|
|
253
|
+
: "No preferred NetworkRoute is configured.",
|
|
254
|
+
"First call browser_auth get_connection and ensure this exact maintenance action is still active. Open a new browser (do not reuse an unrelated session) with the preferred identity, placement, and network route. Observe the current page, start one AuthRun with the exact purpose above, and settle it as verified, failed, cancelled, or a durable human intervention. For an external_provider authority use advance_external. If authentication is already valid, verify it without logging in again. If a health check finds invalid authentication, report it failed; automatic repair, when enabled, is a separate maintenance run. Never save/publish browser state in this run.",
|
|
255
|
+
]
|
|
256
|
+
.filter((line): line is string => line !== null)
|
|
257
|
+
.join("\n");
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
function maintenanceRetryAt(maintenance: SiteAuthMaintenanceClaim): Date {
|
|
261
|
+
const retrySeconds = Math.min(maintenance.healthPolicy.intervalSeconds ?? 300, 15 * 60);
|
|
262
|
+
return new Date(Date.now() + retrySeconds * 1_000);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
function maintenanceErrorCategory(error: unknown): string {
|
|
266
|
+
if (!error || typeof error !== "object") return "unknown";
|
|
267
|
+
const name = (error as { name?: unknown }).name;
|
|
268
|
+
return typeof name === "string" && name.length <= 100 ? name : "unknown";
|
|
269
|
+
}
|