@opengeni/worker-bundle 0.16.21 → 0.17.2
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.d.ts +145 -32
- package/dist/activities/api-integrations.d.ts +21 -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 +5 -5
- package/dist/activities/codex-image-generation.d.ts +21 -0
- package/dist/activities/context-compaction.d.ts +3 -0
- package/dist/activities/documents.d.ts +3 -2
- package/dist/activities/environment.d.ts +11 -7
- package/dist/activities/expiring-material-renewal.d.ts +5 -3
- 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 +2 -2
- 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 +13 -26
- package/dist/activities/parent-wake.d.ts +1 -1
- package/dist/activities/retained-screenshot-reaper.d.ts +32 -0
- package/dist/activities/retained-screenshots.d.ts +129 -0
- package/dist/activities/rig-verification.d.ts +82 -5
- package/dist/activities/run-credential-renewal.d.ts +2 -2
- package/dist/activities/run-input.d.ts +5 -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 +4 -4
- package/dist/activities/streaming.d.ts +1 -1
- package/dist/activities/types.d.ts +71 -5
- package/dist/activities/video-generation-admission.d.ts +38 -0
- package/dist/activities/video-generation-credential.d.ts +7 -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 +49 -0
- package/dist/activities/workflow-wake.d.ts +2 -2
- package/dist/activities/workspace-capture.d.ts +11 -1
- package/dist/activities-control-44KBWLSM.js +6885 -0
- package/dist/activities-control-44KBWLSM.js.map +1 -0
- package/dist/activities-control.d.ts +289 -0
- package/dist/activities-turn-K4CEDEGJ.js +14675 -0
- package/dist/activities-turn-K4CEDEGJ.js.map +1 -0
- package/dist/activities-turn.d.ts +17 -0
- package/dist/activities.d.ts +130 -147
- 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-E3RI3I33.js +828 -0
- package/dist/chunk-E3RI3I33.js.map +1 -0
- package/dist/chunk-GRFQTTSQ.js +448 -0
- package/dist/chunk-GRFQTTSQ.js.map +1 -0
- package/dist/chunk-KKCRGAGZ.js +3091 -0
- package/dist/chunk-KKCRGAGZ.js.map +1 -0
- package/dist/{chunk-BJUW5LCM.js → chunk-RAMNYSAW.js} +15 -12
- package/dist/chunk-RAMNYSAW.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/host-export.js +1 -1
- package/dist/index.d.ts +176 -10
- package/dist/index.js +675 -16460
- package/dist/index.js.map +1 -1
- package/dist/memory-pressure-guard.d.ts +57 -0
- package/dist/model-checkpoint-memory-collector.d.ts +22 -0
- package/dist/observability-metrics.d.ts +33 -0
- package/dist/sandbox-reaper-contract.d.ts +40 -0
- package/dist/sandbox-reaper-timeout.d.ts +14 -0
- package/dist/sandbox-resume.d.ts +40 -7
- package/dist/sandbox-routing.d.ts +13 -6
- package/dist/worker-service-lifecycle.d.ts +6 -2
- package/dist/workflow-bundle.js +1044 -363
- package/dist/workflows/activities.d.ts +7 -1
- 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/video-generation.d.ts +10 -0
- package/dist/workflows/workflow-wake.d.ts +1 -1
- package/dist/workflows.d.ts +9 -7
- package/package.json +34 -15
- package/src/activities/agent-turn.ts +1905 -559
- package/src/activities/api-integrations.ts +138 -0
- package/src/activities/codemode-dispatcher.ts +335 -0
- package/src/activities/codemode-token-renewal.ts +64 -0
- package/src/activities/codex-capacity.ts +16 -7
- package/src/activities/codex-image-generation.ts +56 -0
- package/src/activities/codex-rotation.ts +19 -5
- package/src/activities/context-compaction.ts +47 -6
- package/src/activities/documents.ts +14 -4
- package/src/activities/environment.ts +52 -60
- package/src/activities/expiring-material-renewal.ts +16 -7
- 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/git-credential-renewal.ts +3 -3
- package/src/activities/goals.ts +6 -2
- 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 +55 -55
- package/src/activities/recording.ts +4 -5
- package/src/activities/retained-screenshot-reaper.ts +202 -0
- package/src/activities/retained-screenshots.ts +1317 -0
- package/src/activities/rig-verification.ts +567 -77
- package/src/activities/run-credential-renewal.ts +9 -2
- package/src/activities/run-input.ts +40 -10
- package/src/activities/sandbox-images.ts +167 -0
- package/src/activities/sandbox-lease.ts +1065 -483
- package/src/activities/scheduled-tasks.ts +96 -7
- package/src/activities/session-state.ts +4 -4
- package/src/activities/streaming.ts +42 -3
- package/src/activities/types.ts +87 -5
- package/src/activities/video-generation-admission.ts +270 -0
- package/src/activities/video-generation-credential.ts +34 -0
- package/src/activities/video-generation-reconciliation.ts +578 -0
- package/src/activities/video-media-validation.ts +326 -0
- package/src/activities/video-output-retention.ts +314 -0
- package/src/activities/video-reference-staging.ts +263 -0
- package/src/activities/workflow-wake.ts +2 -2
- package/src/activities/workspace-capture.ts +77 -13
- package/src/activities-control.ts +54 -0
- package/src/activities-turn.ts +40 -0
- package/src/activities.ts +50 -118
- 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/host-export-pump.ts +28 -11
- package/src/http.ts +3 -6
- package/src/index.ts +277 -72
- package/src/memory-pressure-guard.ts +489 -0
- package/src/model-checkpoint-memory-collector.ts +116 -0
- package/src/observability-metrics.ts +202 -7
- package/src/sandbox-reaper-contract.ts +73 -0
- package/src/sandbox-reaper-timeout.ts +79 -0
- package/src/sandbox-resume.ts +331 -157
- package/src/sandbox-routing.ts +49 -39
- package/src/worker-service-lifecycle.ts +82 -12
- package/src/workflows/activities.ts +30 -0
- package/src/workflows/file-upload-reaper.ts +6 -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/video-generation.ts +36 -0
- package/src/workflows.ts +17 -1
- package/dist/activities/redaction.d.ts +0 -1
- package/dist/activities/toolspace-token-renewal.d.ts +0 -23
- package/dist/chunk-BJUW5LCM.js.map +0 -1
- package/src/activities/redaction.ts +0 -9
- package/src/activities/toolspace-token-renewal.ts +0 -57
|
@@ -17,18 +17,22 @@ import {
|
|
|
17
17
|
enqueueSessionWorkflowWakeIfRunnable,
|
|
18
18
|
getBillingBalance,
|
|
19
19
|
getScheduledTask,
|
|
20
|
+
ensureKnowledgeSourceSyncState,
|
|
20
21
|
getScheduledTaskPersonalConnectionDelegations,
|
|
21
22
|
getRig,
|
|
22
23
|
getVariableSet,
|
|
23
24
|
isCodexBilledTurn,
|
|
24
25
|
markScheduledTaskRunFailedIfQueued,
|
|
26
|
+
recordKnowledgeSourceSyncWake,
|
|
25
27
|
recordUsageEvent,
|
|
28
|
+
requireScheduledTaskTargetInTransaction,
|
|
26
29
|
requireSession,
|
|
27
30
|
setTemporalWorkflowId,
|
|
28
31
|
settleScheduledTaskRunInTransaction,
|
|
29
32
|
SessionSpawnDeniedDbError,
|
|
30
33
|
sumUsageQuantity,
|
|
31
34
|
updateScheduledTask,
|
|
35
|
+
updateScheduledTaskRun,
|
|
32
36
|
upsertSessionGoal,
|
|
33
37
|
} from "@opengeni/db";
|
|
34
38
|
import { appendAndPublishEvents, publishDurableSessionEvents } from "@opengeni/events";
|
|
@@ -40,12 +44,12 @@ import {
|
|
|
40
44
|
} from "./common";
|
|
41
45
|
import { withFirstPartyTools } from "./goals";
|
|
42
46
|
import type {
|
|
43
|
-
|
|
47
|
+
ControlActivityServices,
|
|
44
48
|
DispatchScheduledTaskRunInput,
|
|
45
49
|
DispatchScheduledTaskRunResult,
|
|
46
50
|
} from "./types";
|
|
47
51
|
|
|
48
|
-
export function createScheduledTaskActivities(services: () => Promise<
|
|
52
|
+
export function createScheduledTaskActivities(services: () => Promise<ControlActivityServices>) {
|
|
49
53
|
return {
|
|
50
54
|
dispatchScheduledTaskRun: async (
|
|
51
55
|
input: DispatchScheduledTaskRunInput,
|
|
@@ -54,7 +58,7 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
54
58
|
// Histories created before the manual-initiator workflow patch already
|
|
55
59
|
// contain this activity command. Reject their incomplete wire input here
|
|
56
60
|
// so replay consumes the recorded command and the retry loop settles.
|
|
57
|
-
if (input.triggerType
|
|
61
|
+
if (input.triggerType !== "scheduled" && !input.initiator) {
|
|
58
62
|
return { action: "blocked", reason: "malformed_manual_trigger" };
|
|
59
63
|
}
|
|
60
64
|
const task = await getScheduledTask(db, input.workspaceId, input.taskId);
|
|
@@ -64,6 +68,64 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
64
68
|
if (!task) {
|
|
65
69
|
return { action: "deleted" };
|
|
66
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
|
+
}
|
|
67
129
|
const taskPersonalConnectionDelegations = await getScheduledTaskPersonalConnectionDelegations(
|
|
68
130
|
db,
|
|
69
131
|
task.workspaceId,
|
|
@@ -183,7 +245,15 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
183
245
|
// Every dispatch carries the first-party MCP server; runtime visibility
|
|
184
246
|
// still follows the session's exact selection and authorization.
|
|
185
247
|
const taskTools = withFirstPartyTools(settings, task.agentConfig.tools);
|
|
186
|
-
|
|
248
|
+
const existingSessionId =
|
|
249
|
+
task.runMode === "existing_session" ? task.targetSessionId : task.reusableSessionId;
|
|
250
|
+
if (task.runMode === "existing_session" && !existingSessionId) {
|
|
251
|
+
throw new Error("scheduled task target session is unavailable");
|
|
252
|
+
}
|
|
253
|
+
if (
|
|
254
|
+
task.runMode === "new_session_per_run" ||
|
|
255
|
+
(task.runMode === "reusable_session" && !existingSessionId)
|
|
256
|
+
) {
|
|
187
257
|
// The FK on scheduled_tasks.variable_set_id is ON DELETE RESTRICT, so
|
|
188
258
|
// an attached variableSet must still exist here; fail closed if not.
|
|
189
259
|
const variableSet = task.variableSetId
|
|
@@ -369,7 +439,7 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
369
439
|
workflowWakeRevision: scheduledUpdate.workflowWakeRevision,
|
|
370
440
|
};
|
|
371
441
|
} else {
|
|
372
|
-
const session = await requireSession(db, task.workspaceId,
|
|
442
|
+
const session = await requireSession(db, task.workspaceId, existingSessionId!);
|
|
373
443
|
// A user-cancelled (terminal) reusable session must not be revived and
|
|
374
444
|
// re-billed on the next fire. Early check avoids the pre-lock goal
|
|
375
445
|
// upsert side-effect; the locked-callback check below is the
|
|
@@ -394,7 +464,7 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
394
464
|
// A recurring "maintain X" task re-establishes its objective on every
|
|
395
465
|
// fire: replace the goal text, reactivate it, and reset the counters.
|
|
396
466
|
const reusableGoal =
|
|
397
|
-
goalSpec && run.status === "queued"
|
|
467
|
+
task.runMode === "reusable_session" && goalSpec && run.status === "queued"
|
|
398
468
|
? await upsertSessionGoal(db, {
|
|
399
469
|
accountId: task.accountId,
|
|
400
470
|
workspaceId: task.workspaceId,
|
|
@@ -430,6 +500,7 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
430
500
|
],
|
|
431
501
|
};
|
|
432
502
|
},
|
|
503
|
+
{ activity: "semantic" },
|
|
433
504
|
);
|
|
434
505
|
await publishDurableSessionEvents(bus, task.workspaceId, session.id, goalEvents);
|
|
435
506
|
}
|
|
@@ -455,6 +526,13 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
455
526
|
personalConnectionDelegations: taskPersonalConnectionDelegations,
|
|
456
527
|
},
|
|
457
528
|
async (tx, wakeEventId) => {
|
|
529
|
+
if (task.runMode === "existing_session") {
|
|
530
|
+
await requireScheduledTaskTargetInTransaction(tx, {
|
|
531
|
+
workspaceId: task.workspaceId,
|
|
532
|
+
taskId: task.id,
|
|
533
|
+
targetSessionId: session.id,
|
|
534
|
+
});
|
|
535
|
+
}
|
|
458
536
|
if (!wakeEventId) throw new Error("Scheduled delivery has no wake event");
|
|
459
537
|
await settleScheduledTaskRunInTransaction(tx, {
|
|
460
538
|
workspaceId: task.workspaceId,
|
|
@@ -519,9 +597,20 @@ export function createScheduledTaskActivities(services: () => Promise<ActivitySe
|
|
|
519
597
|
};
|
|
520
598
|
}
|
|
521
599
|
|
|
600
|
+
function knowledgeSourceSyncEffectivelyPaused(task: {
|
|
601
|
+
status: "active" | "paused";
|
|
602
|
+
metadata: Record<string, unknown>;
|
|
603
|
+
}): boolean {
|
|
604
|
+
if (task.status === "paused") return true;
|
|
605
|
+
const value = task.metadata.knowledgeSourceSync;
|
|
606
|
+
if (!value || typeof value !== "object") return false;
|
|
607
|
+
const control = value as Record<string, unknown>;
|
|
608
|
+
return control.sourceEnabled === false || control.connectionPaused === true;
|
|
609
|
+
}
|
|
610
|
+
|
|
522
611
|
async function scheduledRunAdmissionDenial(
|
|
523
612
|
settings: Settings,
|
|
524
|
-
db:
|
|
613
|
+
db: ControlActivityServices["db"],
|
|
525
614
|
accountId: string,
|
|
526
615
|
workspaceId: string,
|
|
527
616
|
requestedAgentRuns: number,
|
|
@@ -18,7 +18,7 @@ import { publishDurableSessionEvents } from "@opengeni/events";
|
|
|
18
18
|
import { deliverFailedChildTurnToParent, notifyParentOfChildIdle } from "./parent-wake";
|
|
19
19
|
import { recordTurnsQueuedGauge } from "../observability-metrics";
|
|
20
20
|
import type {
|
|
21
|
-
|
|
21
|
+
ControlActivityServices,
|
|
22
22
|
ExpireSessionHumanInputInput,
|
|
23
23
|
ExpireSessionHumanInputResult,
|
|
24
24
|
PeekSessionWorkInput,
|
|
@@ -62,7 +62,7 @@ export type SessionStateActivityOverrides = Partial<{
|
|
|
62
62
|
export const WORKER_DEATH_MAX_REDISPATCHES = 3;
|
|
63
63
|
|
|
64
64
|
export function createSessionStateActivities(
|
|
65
|
-
services: () => Promise<
|
|
65
|
+
services: () => Promise<ControlActivityServices>,
|
|
66
66
|
overrides: SessionStateActivityOverrides = {},
|
|
67
67
|
) {
|
|
68
68
|
const settleSessionAttemptInterruptionsFn =
|
|
@@ -388,8 +388,8 @@ export function createSessionStateActivities(
|
|
|
388
388
|
}
|
|
389
389
|
|
|
390
390
|
async function refreshQueuedTurnsGauge(
|
|
391
|
-
db:
|
|
392
|
-
observability:
|
|
391
|
+
db: ControlActivityServices["db"],
|
|
392
|
+
observability: ControlActivityServices["observability"],
|
|
393
393
|
countQueuedTurnsFn: typeof countQueuedTurns,
|
|
394
394
|
recordTurnsQueuedGaugeFn: typeof recordTurnsQueuedGauge,
|
|
395
395
|
): Promise<void> {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { SessionEventType } from "@opengeni/contracts";
|
|
2
|
+
import { TURN_ACTIVITY_CANCELLATION_HEARTBEAT_INTERVAL_MS } from "@opengeni/core";
|
|
2
3
|
import type { AppendEventInput } from "@opengeni/db";
|
|
3
4
|
import { Context } from "@temporalio/activity";
|
|
4
5
|
|
|
@@ -176,13 +177,14 @@ export function currentActivityContext(): Context | null {
|
|
|
176
177
|
export function startActivityHeartbeat(
|
|
177
178
|
context: Context | null,
|
|
178
179
|
details: Record<string, unknown>,
|
|
180
|
+
schedule: typeof setInterval = setInterval,
|
|
179
181
|
): ReturnType<typeof setInterval> | null {
|
|
180
182
|
if (!context) {
|
|
181
183
|
return null;
|
|
182
184
|
}
|
|
183
|
-
const timer =
|
|
185
|
+
const timer = schedule(() => {
|
|
184
186
|
context.heartbeat({ ...details, at: new Date().toISOString() });
|
|
185
|
-
},
|
|
187
|
+
}, TURN_ACTIVITY_CANCELLATION_HEARTBEAT_INTERVAL_MS);
|
|
186
188
|
if ("unref" in timer && typeof timer.unref === "function") {
|
|
187
189
|
timer.unref();
|
|
188
190
|
}
|
|
@@ -196,5 +198,42 @@ export async function nextStreamEvent<T>(
|
|
|
196
198
|
if (!context) {
|
|
197
199
|
return await iterator.next();
|
|
198
200
|
}
|
|
199
|
-
|
|
201
|
+
const signal = context.cancellationSignal;
|
|
202
|
+
if (signal.aborted) {
|
|
203
|
+
throw signal.reason;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
// Context.cancelled never settles for a normally completed activity. Racing
|
|
207
|
+
// every token/event read against that lifetime promise leaves one losing
|
|
208
|
+
// Promise reaction attached for every event until the Context itself dies.
|
|
209
|
+
// Use the equivalent Temporal AbortSignal and remove each listener as soon as
|
|
210
|
+
// the iterator wins, so a long stream retains at most its one pending read.
|
|
211
|
+
return await new Promise<IteratorResult<T>>((resolve, reject) => {
|
|
212
|
+
let settled = false;
|
|
213
|
+
const settle = (complete: () => void) => {
|
|
214
|
+
if (settled) return;
|
|
215
|
+
settled = true;
|
|
216
|
+
signal.removeEventListener("abort", onAbort);
|
|
217
|
+
complete();
|
|
218
|
+
};
|
|
219
|
+
const onAbort = () => settle(() => reject(signal.reason));
|
|
220
|
+
|
|
221
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
222
|
+
if (signal.aborted) {
|
|
223
|
+
onAbort();
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
let next: PromiseLike<IteratorResult<T>>;
|
|
228
|
+
try {
|
|
229
|
+
next = iterator.next();
|
|
230
|
+
} catch (error) {
|
|
231
|
+
settle(() => reject(error));
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
void Promise.resolve(next).then(
|
|
235
|
+
(result) => settle(() => resolve(result)),
|
|
236
|
+
(error) => settle(() => reject(error)),
|
|
237
|
+
);
|
|
238
|
+
});
|
|
200
239
|
}
|
package/src/activities/types.ts
CHANGED
|
@@ -38,6 +38,18 @@ export type SignalCodexCapacityWorkflow = (input: {
|
|
|
38
38
|
wakeRevision: number;
|
|
39
39
|
}) => Promise<void>;
|
|
40
40
|
|
|
41
|
+
/** Start the versioned, per-box sandbox reaper from the history-stable legacy
|
|
42
|
+
* activity. The legacy Schedule workflow must keep its exact historical
|
|
43
|
+
* ScheduleActivity command across mixed-version worker pools. */
|
|
44
|
+
export type StartSandboxReaperWorkflow = () => Promise<"started" | "already_running">;
|
|
45
|
+
|
|
46
|
+
/** Start-or-observe the one durable reconciler for a paid video operation. */
|
|
47
|
+
export type StartVideoGenerationWorkflow = (input: {
|
|
48
|
+
accountId: string;
|
|
49
|
+
workspaceId: string;
|
|
50
|
+
operationId: string;
|
|
51
|
+
}) => Promise<"started" | "already_running">;
|
|
52
|
+
|
|
41
53
|
/** Exact activity-owned proof that the hard sandbox/tool fence physically
|
|
42
54
|
* drained. This is delivery evidence only: the workflow still validates the
|
|
43
55
|
* persisted attempt dispatch and commits the authoritative Postgres receipt. */
|
|
@@ -59,13 +71,13 @@ export type InspectSessionAttemptActivity = (input: {
|
|
|
59
71
|
activityId: string;
|
|
60
72
|
}) => Promise<"pending" | "settled">;
|
|
61
73
|
|
|
62
|
-
|
|
74
|
+
/** Services shared by both Temporal worker roles. Keep this graph free of the
|
|
75
|
+
* agent runtime and document parser so each process can load only its role. */
|
|
76
|
+
export type SharedActivityServices = {
|
|
63
77
|
settings: Settings;
|
|
64
78
|
db: Database;
|
|
65
79
|
bus: EventBus;
|
|
66
|
-
runtime: OpenGeniRuntime;
|
|
67
80
|
objectStorage: ObjectStorage | null;
|
|
68
|
-
documentServices: DocumentServices;
|
|
69
81
|
observability: Observability;
|
|
70
82
|
wakeSessionWorkflow: WakeSessionWorkflowSignal | null;
|
|
71
83
|
/** Durable signalWithStart fallback used only after the activity's direct
|
|
@@ -76,6 +88,10 @@ export type ActivityServices = {
|
|
|
76
88
|
inspectSessionAttemptActivity: InspectSessionAttemptActivity | null;
|
|
77
89
|
/** Revision-carrying capacity nudge; generic outbox repair is also sufficient. */
|
|
78
90
|
signalCodexCapacityWorkflow?: SignalCodexCapacityWorkflow | null;
|
|
91
|
+
/** Production control workers inject this Temporal client edge. A null edge
|
|
92
|
+
* deliberately retains the composite implementation for embedded/test hosts. */
|
|
93
|
+
startSandboxReaperWorkflow?: StartSandboxReaperWorkflow | null;
|
|
94
|
+
startVideoGenerationWorkflow?: StartVideoGenerationWorkflow | null;
|
|
79
95
|
// §7.5 P3 — host-entitlements port, the WORKER half of the same seam the API
|
|
80
96
|
// edge exposes on `AppDependencies`. When set, `ensureRunAllowed` (turn-entry
|
|
81
97
|
// AND the mid-stream budget valve) delegates the funding decision to
|
|
@@ -108,6 +124,23 @@ export type ActivityServices = {
|
|
|
108
124
|
connectionCredentials?: ConnectionCredentialsPort | null;
|
|
109
125
|
};
|
|
110
126
|
|
|
127
|
+
/** Control workers own short database and maintenance activities. Document
|
|
128
|
+
* parsing is resolved lazily by the indexing activity itself. */
|
|
129
|
+
export type ControlActivityServices = SharedActivityServices;
|
|
130
|
+
|
|
131
|
+
/** Turn workers own the model loop and never construct document parsers. */
|
|
132
|
+
export type TurnActivityServices = SharedActivityServices & {
|
|
133
|
+
runtime: OpenGeniRuntime;
|
|
134
|
+
/** Provider-free test/profiling seam; production injects the real runtime summarizer. */
|
|
135
|
+
summarizeContextForCompaction: typeof import("@opengeni/runtime").summarizeForCompaction;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
/** Full test/embedded harness retained as a source-compatible superset. */
|
|
139
|
+
export type ActivityServices = ControlActivityServices &
|
|
140
|
+
TurnActivityServices & {
|
|
141
|
+
documentServices: DocumentServices;
|
|
142
|
+
};
|
|
143
|
+
|
|
111
144
|
export type CodexCapacityWaitRef = {
|
|
112
145
|
waiterId: string;
|
|
113
146
|
generation: number;
|
|
@@ -134,6 +167,8 @@ export type ReconcileCodexCapacityWaitResult =
|
|
|
134
167
|
| { action: "resumed" | "paused" | "superseded" | "stale" };
|
|
135
168
|
|
|
136
169
|
export type ActivityDependencies = Partial<ActivityServices>;
|
|
170
|
+
export type ControlActivityDependencies = Partial<ControlActivityServices>;
|
|
171
|
+
export type TurnActivityDependencies = Partial<TurnActivityServices>;
|
|
137
172
|
|
|
138
173
|
export type RunAgentTurnInput = {
|
|
139
174
|
accountId: string;
|
|
@@ -145,6 +180,17 @@ export type RunAgentTurnInput = {
|
|
|
145
180
|
trigger: { kind: "next" } | { kind: "approval"; triggerEventId: string };
|
|
146
181
|
};
|
|
147
182
|
|
|
183
|
+
export type VideoGenerationTerminalStatus =
|
|
184
|
+
| "completed"
|
|
185
|
+
| "provider_failed"
|
|
186
|
+
| "cancelled_before_submit"
|
|
187
|
+
| "outcome_unknown"
|
|
188
|
+
| "retention_failed";
|
|
189
|
+
|
|
190
|
+
export type VideoGenerationReconcileResult =
|
|
191
|
+
| { action: "waiting"; delayMs: number }
|
|
192
|
+
| { action: "terminal"; status: VideoGenerationTerminalStatus };
|
|
193
|
+
|
|
148
194
|
export type SettleSessionInterruptionsInput = {
|
|
149
195
|
accountId: string;
|
|
150
196
|
workspaceId: string;
|
|
@@ -268,7 +314,10 @@ export type DispatchScheduledTaskRunInput = {
|
|
|
268
314
|
initiator?: never;
|
|
269
315
|
}
|
|
270
316
|
| {
|
|
271
|
-
triggerType: Extract<
|
|
317
|
+
triggerType: Extract<
|
|
318
|
+
ScheduledTaskTriggerType,
|
|
319
|
+
"manual" | "initial" | "provider_event" | "retry" | "repair"
|
|
320
|
+
>;
|
|
272
321
|
agentRunUsageIdempotencyKey: string;
|
|
273
322
|
/** Exact identity used by the API-side charge for this same trigger. */
|
|
274
323
|
initiator: TurnInitiator;
|
|
@@ -283,7 +332,8 @@ export type DispatchScheduledTaskRunResult =
|
|
|
283
332
|
| "insufficient_credits"
|
|
284
333
|
| "monthly_model_cost_limit"
|
|
285
334
|
| "monthly_agent_run_limit"
|
|
286
|
-
| "malformed_manual_trigger"
|
|
335
|
+
| "malformed_manual_trigger"
|
|
336
|
+
| "knowledge_source_paused";
|
|
287
337
|
}
|
|
288
338
|
| {
|
|
289
339
|
action: "start" | "signal";
|
|
@@ -293,6 +343,38 @@ export type DispatchScheduledTaskRunResult =
|
|
|
293
343
|
triggerEventId: string;
|
|
294
344
|
workflowId: string;
|
|
295
345
|
workflowWakeRevision: number | null;
|
|
346
|
+
}
|
|
347
|
+
| {
|
|
348
|
+
action: "knowledge_source_sync";
|
|
349
|
+
accountId: string;
|
|
350
|
+
workspaceId: string;
|
|
351
|
+
taskId: string;
|
|
352
|
+
scheduledTaskRunId: string;
|
|
353
|
+
sourceId: string;
|
|
354
|
+
overlapPolicy: "skip" | "buffer_one";
|
|
355
|
+
};
|
|
356
|
+
|
|
357
|
+
export type RunKnowledgeSourceSyncBatchInput = {
|
|
358
|
+
accountId: string;
|
|
359
|
+
workspaceId: string;
|
|
360
|
+
taskId: string;
|
|
361
|
+
scheduledTaskRunId: string;
|
|
362
|
+
sourceId: string;
|
|
363
|
+
overlapPolicy: "skip" | "buffer_one";
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
export type RunKnowledgeSourceSyncBatchResult =
|
|
367
|
+
| { action: "continue" }
|
|
368
|
+
| {
|
|
369
|
+
action: "complete";
|
|
370
|
+
bufferedWake: boolean;
|
|
371
|
+
bufferedScheduledTaskRunId?: string | null;
|
|
372
|
+
}
|
|
373
|
+
| { action: "skipped" | "buffered" }
|
|
374
|
+
| {
|
|
375
|
+
action: "failed";
|
|
376
|
+
bufferedWake: boolean;
|
|
377
|
+
bufferedScheduledTaskRunId?: string | null;
|
|
296
378
|
};
|
|
297
379
|
|
|
298
380
|
type DocumentIndexIdentity = {
|