@opengeni/worker-bundle 0.20.3 → 0.22.0-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 +52 -0
- package/dist/activities/agent-turn/agent-build.d.ts +89 -0
- package/dist/activities/agent-turn/claim.d.ts +67 -0
- package/dist/activities/agent-turn/codex-capacity.d.ts +40 -0
- package/dist/activities/agent-turn/codex.d.ts +32 -0
- package/dist/activities/agent-turn/compaction-prep.d.ts +88 -0
- package/dist/activities/agent-turn/credential-leases.d.ts +56 -0
- package/dist/activities/agent-turn/errors.d.ts +253 -0
- package/dist/activities/agent-turn/failure-settlement.d.ts +33 -0
- package/dist/activities/agent-turn/file-resources.d.ts +37 -0
- package/dist/activities/agent-turn/finalization.d.ts +42 -0
- package/dist/activities/agent-turn/github-repository-bindings.d.ts +105 -0
- package/dist/activities/agent-turn/governance-model.d.ts +66 -0
- package/dist/activities/agent-turn/history-sink.d.ts +52 -0
- package/dist/activities/agent-turn/history.d.ts +63 -0
- package/dist/activities/agent-turn/media-artifacts.d.ts +145 -0
- package/dist/activities/agent-turn/model-usage.d.ts +218 -0
- package/dist/activities/agent-turn/quiescence.d.ts +135 -0
- package/dist/activities/agent-turn/run-credentials.d.ts +84 -0
- package/dist/activities/agent-turn/run.d.ts +3 -0
- package/dist/activities/agent-turn/sandbox-establish.d.ts +93 -0
- package/dist/activities/agent-turn/sandbox-provision.d.ts +89 -0
- package/dist/activities/agent-turn/sandbox-route.d.ts +151 -0
- package/dist/activities/agent-turn/sandbox-runtime.d.ts +44 -0
- package/dist/activities/agent-turn/stream-attempt.d.ts +107 -0
- package/dist/activities/agent-turn/tool-environment.d.ts +142 -0
- package/dist/activities/agent-turn/tool-policy.d.ts +127 -0
- package/dist/activities/agent-turn/tool-result-spill.d.ts +59 -0
- package/dist/activities/agent-turn/turn-context.d.ts +144 -0
- package/dist/activities/agent-turn/xai-capacity.d.ts +2 -0
- package/dist/activities/agent-turn.d.ts +12 -954
- package/dist/activities/automations.d.ts +16 -0
- package/dist/activities/common.d.ts +1 -1
- package/dist/activities/connector-attachments.d.ts +13 -0
- package/dist/activities/documents.d.ts +1 -0
- package/dist/activities/environment.d.ts +26 -15
- package/dist/activities/generated-images.d.ts +1 -1
- package/dist/activities/git-credential-renewal.d.ts +3 -1
- package/dist/activities/goals.d.ts +4 -1
- package/dist/activities/google-drive-provider.d.ts +29 -0
- package/dist/activities/google-drive-publication.d.ts +17 -4
- package/dist/activities/incident-telemetry-authority.d.ts +52 -0
- package/dist/activities/incident-telemetry-preflight.d.ts +71 -0
- package/dist/activities/knowledge-source-sync.d.ts +4 -0
- package/dist/activities/mcp-credentials.d.ts +9 -3
- package/dist/activities/open-suffix-resume.d.ts +77 -0
- package/dist/activities/packs.d.ts +3 -11
- package/dist/activities/parent-wake.d.ts +19 -0
- package/dist/activities/retained-screenshot-reaper.d.ts +1 -1
- package/dist/activities/retained-screenshots.d.ts +1 -1
- package/dist/activities/rig-verification.d.ts +1 -1
- package/dist/activities/run-input.d.ts +9 -10
- package/dist/activities/sandbox-images.d.ts +1 -14
- package/dist/activities/sandbox-lease.d.ts +21 -3
- package/dist/activities/scheduled-tasks.d.ts +47 -0
- package/dist/activities/types.d.ts +23 -2
- package/dist/activities/video-media-validation.d.ts +1 -1
- package/dist/activities/video-output-retention.d.ts +1 -2
- package/dist/activities/xai-auth.d.ts +3 -0
- package/dist/{activities-control-BJSDRSIP.js → activities-control-DKG22ONJ.js} +2646 -551
- package/dist/activities-control-DKG22ONJ.js.map +1 -0
- package/dist/activities-control.d.ts +6 -2
- package/dist/activities-turn-4IMC3MAA.js +21326 -0
- package/dist/activities-turn-4IMC3MAA.js.map +1 -0
- package/dist/activities.d.ts +7 -3
- package/dist/artifact-materializer-entry.js +41 -22
- package/dist/artifact-materializer-entry.js.map +1 -1
- package/dist/{chunk-N5TJIFCE.js → chunk-CE7TPKBS.js} +468 -1
- package/dist/chunk-CE7TPKBS.js.map +1 -0
- package/dist/chunk-CNYGVRKF.js +4698 -0
- package/dist/chunk-CNYGVRKF.js.map +1 -0
- package/dist/connection-provider-use.d.ts +18 -0
- package/dist/editable-artifact-materializer.d.ts +4 -3
- package/dist/github-rest-mcp.d.ts +26 -0
- package/dist/index.d.ts +10 -2
- package/dist/index.js +58 -14
- package/dist/index.js.map +1 -1
- package/dist/knowledge-source-sync-activity-policy.d.ts +2 -0
- package/dist/model-context-contributions.d.ts +8 -4
- package/dist/observability-metrics.d.ts +63 -4
- package/dist/opensandbox-kubernetes-inventory.d.ts +21 -0
- package/dist/personal-github-git-credentials.d.ts +9 -0
- package/dist/pr-review-credentials.d.ts +6 -0
- package/dist/sandbox-archive-storage.d.ts +45 -0
- package/dist/sandbox-resume.d.ts +65 -6
- package/dist/sandbox-routing.d.ts +38 -2
- package/dist/scheduled-alert-occurrence.d.ts +33 -0
- package/dist/workflow-bundle.js +87 -28
- package/dist/workflows/activities.d.ts +1 -0
- package/dist/workflows/automations.d.ts +6 -0
- package/dist/workflows/document-index.d.ts +1 -0
- package/dist/workflows.d.ts +1 -0
- package/package.json +17 -17
- package/src/activities/agent-turn/admission.ts +292 -0
- package/src/activities/agent-turn/agent-build.ts +802 -0
- package/src/activities/agent-turn/claim.ts +590 -0
- package/src/activities/agent-turn/codex-capacity.ts +720 -0
- package/src/activities/agent-turn/codex.ts +94 -0
- package/src/activities/agent-turn/compaction-prep.ts +722 -0
- package/src/activities/agent-turn/credential-leases.ts +240 -0
- package/src/activities/agent-turn/errors.ts +1068 -0
- package/src/activities/agent-turn/failure-settlement.ts +1436 -0
- package/src/activities/agent-turn/file-resources.ts +227 -0
- package/src/activities/agent-turn/finalization.ts +754 -0
- package/src/activities/agent-turn/github-repository-bindings.ts +300 -0
- package/src/activities/agent-turn/governance-model.ts +465 -0
- package/src/activities/agent-turn/history-sink.ts +139 -0
- package/src/activities/agent-turn/history.ts +200 -0
- package/src/activities/agent-turn/media-artifacts.ts +359 -0
- package/src/activities/agent-turn/model-usage.ts +823 -0
- package/src/activities/agent-turn/quiescence.ts +353 -0
- package/src/activities/agent-turn/run-credentials.ts +761 -0
- package/src/activities/agent-turn/run.ts +1530 -0
- package/src/activities/agent-turn/sandbox-establish.ts +1207 -0
- package/src/activities/agent-turn/sandbox-provision.ts +569 -0
- package/src/activities/agent-turn/sandbox-route.ts +358 -0
- package/src/activities/agent-turn/sandbox-runtime.ts +731 -0
- package/src/activities/agent-turn/stream-attempt.ts +1670 -0
- package/src/activities/agent-turn/tool-environment.ts +729 -0
- package/src/activities/agent-turn/tool-policy.ts +216 -0
- package/src/activities/agent-turn/tool-result-spill.ts +265 -0
- package/src/activities/agent-turn/turn-context.ts +281 -0
- package/src/activities/agent-turn/xai-capacity.ts +229 -0
- package/src/activities/agent-turn.ts +12 -12701
- package/src/activities/api-integrations.ts +3 -0
- package/src/activities/automations.ts +214 -0
- package/src/activities/codemode-dispatcher.ts +12 -1
- package/src/activities/common.ts +1 -5
- package/src/activities/connector-attachments.ts +168 -0
- package/src/activities/context-compaction.ts +18 -0
- package/src/activities/environment.ts +151 -55
- package/src/activities/generated-images.ts +26 -11
- package/src/activities/git-credential-renewal.ts +13 -3
- package/src/activities/goals.ts +85 -19
- package/src/activities/google-drive-provider.ts +178 -0
- package/src/activities/google-drive-publication.ts +147 -49
- package/src/activities/incident-telemetry-authority.ts +327 -0
- package/src/activities/incident-telemetry-preflight.ts +317 -0
- package/src/activities/knowledge-source-sync.ts +178 -37
- package/src/activities/mcp-credentials.ts +191 -17
- package/src/activities/open-suffix-resume.ts +422 -0
- package/src/activities/packs.ts +12 -60
- package/src/activities/parent-wake.ts +64 -14
- package/src/activities/retained-screenshot-reaper.ts +6 -3
- package/src/activities/retained-screenshots.ts +15 -47
- package/src/activities/rig-verification.ts +1 -1
- package/src/activities/run-input.ts +102 -142
- package/src/activities/sandbox-images.ts +7 -166
- package/src/activities/sandbox-lease.ts +406 -15
- package/src/activities/scheduled-tasks.ts +2103 -411
- package/src/activities/session-state.ts +10 -2
- package/src/activities/types.ts +32 -2
- package/src/activities/video-media-validation.ts +3 -3
- package/src/activities/video-output-retention.ts +2 -57
- package/src/activities/xai-auth.ts +8 -0
- package/src/activities-control.ts +2 -0
- package/src/activities.ts +3 -0
- package/src/activity-services.ts +13 -4
- package/src/connection-provider-use.ts +36 -0
- package/src/editable-artifact-materializer-subprocess.ts +25 -14
- package/src/editable-artifact-materializer.ts +29 -18
- package/src/github-rest-mcp.ts +713 -0
- package/src/http.ts +16 -6
- package/src/index.ts +40 -5
- package/src/knowledge-source-sync-activity-policy.ts +2 -0
- package/src/model-context-contributions.ts +33 -10
- package/src/observability-metrics.ts +357 -0
- package/src/opensandbox-kubernetes-inventory.ts +292 -0
- package/src/personal-github-git-credentials.ts +331 -0
- package/src/pr-review-credentials.ts +163 -0
- package/src/sandbox-archive-storage.ts +159 -0
- package/src/sandbox-resume.ts +449 -63
- package/src/sandbox-routing.ts +314 -16
- package/src/scheduled-alert-occurrence.ts +176 -0
- package/src/workflows/activities.ts +18 -2
- package/src/workflows/automations.ts +11 -0
- package/src/workflows/session.ts +13 -3
- package/src/workflows.ts +1 -0
- package/dist/activities-control-BJSDRSIP.js.map +0 -1
- package/dist/activities-turn-J5YO7XXX.js +0 -17243
- package/dist/activities-turn-J5YO7XXX.js.map +0 -1
- package/dist/chunk-N5TJIFCE.js.map +0 -1
- package/dist/chunk-P6Z2SLAA.js +0 -3092
- package/dist/chunk-P6Z2SLAA.js.map +0 -1
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import { heartbeat } from "@temporalio/activity";
|
|
3
|
-
import
|
|
3
|
+
import {
|
|
4
|
+
googleDriveProviderRetryOptions,
|
|
5
|
+
type GoogleDriveProviderRetryOptions,
|
|
6
|
+
type Settings,
|
|
7
|
+
} from "@opengeni/config";
|
|
4
8
|
import {
|
|
5
9
|
KnowledgeSourceSyncRunSummary,
|
|
6
10
|
type ScheduledTask,
|
|
@@ -79,7 +83,13 @@ import {
|
|
|
79
83
|
type KnowledgeSourceSyncObservationFloor,
|
|
80
84
|
} from "@opengeni/db";
|
|
81
85
|
import { readResponseJsonBounded } from "@opengeni/network";
|
|
86
|
+
import type { Observability } from "@opengeni/observability";
|
|
82
87
|
import { createDocumentActivities } from "./documents";
|
|
88
|
+
import {
|
|
89
|
+
fetchGoogleDriveProvider,
|
|
90
|
+
GoogleDriveProviderTransportError,
|
|
91
|
+
type GoogleDriveProviderOperation,
|
|
92
|
+
} from "./google-drive-provider";
|
|
83
93
|
import type {
|
|
84
94
|
ControlActivityServices,
|
|
85
95
|
RunKnowledgeSourceSyncBatchInput,
|
|
@@ -212,6 +222,10 @@ export function createKnowledgeSourceSyncActivities(
|
|
|
212
222
|
reconnectRequired: false,
|
|
213
223
|
failures: [],
|
|
214
224
|
};
|
|
225
|
+
observability.info("Knowledge source sync started", {
|
|
226
|
+
provider: providerLabel,
|
|
227
|
+
outcome: "started",
|
|
228
|
+
});
|
|
215
229
|
try {
|
|
216
230
|
summary.phase = "inventory";
|
|
217
231
|
const resolved = await getKnowledgeSourceForSyncAuthority(db, {
|
|
@@ -303,6 +317,7 @@ export function createKnowledgeSourceSyncActivities(
|
|
|
303
317
|
const provider = await resolveKnowledgeSyncProvider({
|
|
304
318
|
db,
|
|
305
319
|
settings,
|
|
320
|
+
observability,
|
|
306
321
|
accountId: input.accountId,
|
|
307
322
|
workspaceId: input.workspaceId,
|
|
308
323
|
action,
|
|
@@ -1112,6 +1127,7 @@ export function createKnowledgeSourceSyncActivities(
|
|
|
1112
1127
|
labels: { provider: providerLabel },
|
|
1113
1128
|
amount: summary.bytes,
|
|
1114
1129
|
});
|
|
1130
|
+
recordSyncHealthTelemetry(observability, providerLabel, summary, "succeeded");
|
|
1115
1131
|
return {
|
|
1116
1132
|
action: "complete",
|
|
1117
1133
|
bufferedWake: settled.bufferedWake,
|
|
@@ -1199,6 +1215,7 @@ export function createKnowledgeSourceSyncActivities(
|
|
|
1199
1215
|
labels: { provider: providerLabel },
|
|
1200
1216
|
amount: summary.bytes,
|
|
1201
1217
|
});
|
|
1218
|
+
recordSyncHealthTelemetry(observability, providerLabel, summary, "failed", failure);
|
|
1202
1219
|
return {
|
|
1203
1220
|
action: "failed",
|
|
1204
1221
|
bufferedWake: settled.bufferedWake,
|
|
@@ -1333,6 +1350,7 @@ export type GoogleDriveSyncProviderPort = {
|
|
|
1333
1350
|
async function resolveKnowledgeSyncProvider(input: {
|
|
1334
1351
|
db: Database;
|
|
1335
1352
|
settings: Settings;
|
|
1353
|
+
observability: Observability;
|
|
1336
1354
|
accountId: string;
|
|
1337
1355
|
workspaceId: string;
|
|
1338
1356
|
action: Extract<ScheduledTask["action"], { kind: "knowledge_source_sync" }>;
|
|
@@ -1486,6 +1504,8 @@ async function resolveKnowledgeSyncProvider(input: {
|
|
|
1486
1504
|
workspaceId: input.workspaceId,
|
|
1487
1505
|
initiatingSubjectId: action.initiatingSubjectId,
|
|
1488
1506
|
authorization,
|
|
1507
|
+
retry: googleDriveProviderRetryOptions(input.settings),
|
|
1508
|
+
observability: input.observability,
|
|
1489
1509
|
limits: action.limits,
|
|
1490
1510
|
connectionId: resolvedConnection.id,
|
|
1491
1511
|
fullReconciliationIntervalMs: GOOGLE_DRIVE_FULL_RECONCILIATION_INTERVAL_MS,
|
|
@@ -1614,6 +1634,8 @@ export function googleDriveSyncDriver(input: {
|
|
|
1614
1634
|
workspaceId: string;
|
|
1615
1635
|
initiatingSubjectId: string;
|
|
1616
1636
|
authorization: string | undefined;
|
|
1637
|
+
retry: GoogleDriveProviderRetryOptions;
|
|
1638
|
+
observability: Observability;
|
|
1617
1639
|
fullReconciliationIntervalMs: number;
|
|
1618
1640
|
observedExternalObjectIds: (ids: string[]) => Promise<Set<string>>;
|
|
1619
1641
|
provider?: GoogleDriveSyncProviderPort;
|
|
@@ -1628,12 +1650,22 @@ export function googleDriveSyncDriver(input: {
|
|
|
1628
1650
|
const maxElapsedMs = input.limits.maxElapsedSeconds * 1_000;
|
|
1629
1651
|
const provider: GoogleDriveSyncProviderPort = input.provider ?? {
|
|
1630
1652
|
getStartPageToken: async (driveId) =>
|
|
1631
|
-
await getDriveStartPageToken(driveId, input.authorization),
|
|
1653
|
+
await getDriveStartPageToken(driveId, input.authorization, input.retry, input.observability),
|
|
1632
1654
|
listChanges: async (pageToken, driveId, pageSize) =>
|
|
1633
|
-
await listDriveChanges(
|
|
1634
|
-
|
|
1635
|
-
|
|
1636
|
-
|
|
1655
|
+
await listDriveChanges(
|
|
1656
|
+
pageToken,
|
|
1657
|
+
driveId,
|
|
1658
|
+
pageSize,
|
|
1659
|
+
input.authorization,
|
|
1660
|
+
input.retry,
|
|
1661
|
+
input.observability,
|
|
1662
|
+
),
|
|
1663
|
+
getFile: async (fileId) =>
|
|
1664
|
+
await getDriveFile(fileId, input.authorization, input.retry, input.observability),
|
|
1665
|
+
listChildren: async (request) =>
|
|
1666
|
+
await listDriveChildren(request, input.authorization, input.retry, input.observability),
|
|
1667
|
+
listPermissions: async (request) =>
|
|
1668
|
+
await listDrivePermissions(request, input.authorization, input.retry, input.observability),
|
|
1637
1669
|
};
|
|
1638
1670
|
const clock = provider.now ?? Date.now;
|
|
1639
1671
|
const budgetLimits = {
|
|
@@ -1986,7 +2018,7 @@ export function googleDriveSyncDriver(input: {
|
|
|
1986
2018
|
}
|
|
1987
2019
|
},
|
|
1988
2020
|
fetchContent: async (entry, maxBytes) =>
|
|
1989
|
-
await fetchDriveBytes(entry, input.authorization, maxBytes),
|
|
2021
|
+
await fetchDriveBytes(entry, input.authorization, maxBytes, input.retry, input.observability),
|
|
1990
2022
|
readAcl: async (entry, maxProviderRequests) => {
|
|
1991
2023
|
if (!provider.listPermissions) {
|
|
1992
2024
|
throw new SyncFailure("provider_rejected", false);
|
|
@@ -2333,16 +2365,20 @@ function googleDriveInventoryStopIsHard(
|
|
|
2333
2365
|
async function getDriveStartPageToken(
|
|
2334
2366
|
driveId: string | null,
|
|
2335
2367
|
authorization: string | undefined,
|
|
2368
|
+
retry: GoogleDriveProviderRetryOptions,
|
|
2369
|
+
observability: Observability,
|
|
2336
2370
|
): Promise<string> {
|
|
2337
2371
|
if (!authorization) throw new SyncFailure("connection_reconnect_required", true, true);
|
|
2338
2372
|
const url = new URL(`${DRIVE_API_BASE}/changes/startPageToken`);
|
|
2339
2373
|
url.searchParams.set("supportsAllDrives", "true");
|
|
2340
2374
|
if (driveId) url.searchParams.set("driveId", driveId);
|
|
2341
|
-
const response = await
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2375
|
+
const response = await requestGoogleDrive(
|
|
2376
|
+
url,
|
|
2377
|
+
{ headers: { authorization, accept: "application/json" } },
|
|
2378
|
+
"start_page_token",
|
|
2379
|
+
retry,
|
|
2380
|
+
observability,
|
|
2381
|
+
);
|
|
2346
2382
|
if (!response.ok) throwGoogleDriveResponse(response);
|
|
2347
2383
|
const payload = (await readResponseJsonBounded(
|
|
2348
2384
|
response,
|
|
@@ -2357,6 +2393,8 @@ async function listDriveChanges(
|
|
|
2357
2393
|
driveId: string | null,
|
|
2358
2394
|
pageSize: number,
|
|
2359
2395
|
authorization: string | undefined,
|
|
2396
|
+
retry: GoogleDriveProviderRetryOptions,
|
|
2397
|
+
observability: Observability,
|
|
2360
2398
|
): Promise<GoogleDriveChangesPage> {
|
|
2361
2399
|
if (!authorization) throw new SyncFailure("connection_reconnect_required", true, true);
|
|
2362
2400
|
const url = new URL(`${DRIVE_API_BASE}/changes`);
|
|
@@ -2370,11 +2408,13 @@ async function listDriveChanges(
|
|
|
2370
2408
|
"nextPageToken,newStartPageToken,changes(fileId,removed,time,driveId,file(id,name,mimeType,driveId,parents,modifiedTime,createdTime,version,md5Checksum,size,webViewLink,trashed))",
|
|
2371
2409
|
);
|
|
2372
2410
|
if (driveId) url.searchParams.set("driveId", driveId);
|
|
2373
|
-
const response = await
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2411
|
+
const response = await requestGoogleDrive(
|
|
2412
|
+
url,
|
|
2413
|
+
{ headers: { authorization, accept: "application/json" } },
|
|
2414
|
+
"list_changes",
|
|
2415
|
+
retry,
|
|
2416
|
+
observability,
|
|
2417
|
+
);
|
|
2378
2418
|
if (response.status === 410) throw new GoogleDriveCursorInvalidError();
|
|
2379
2419
|
if (!response.ok) throwGoogleDriveResponse(response);
|
|
2380
2420
|
const payload = (await readResponseJsonBounded(
|
|
@@ -2401,6 +2441,8 @@ async function listDriveChanges(
|
|
|
2401
2441
|
async function getDriveFile(
|
|
2402
2442
|
fileId: string,
|
|
2403
2443
|
authorization: string | undefined,
|
|
2444
|
+
retry: GoogleDriveProviderRetryOptions,
|
|
2445
|
+
observability: Observability,
|
|
2404
2446
|
): Promise<GoogleDriveInventoryProviderItem | null> {
|
|
2405
2447
|
if (!authorization) throw new SyncFailure("connection_reconnect_required", true, true);
|
|
2406
2448
|
const url = new URL(`${DRIVE_API_BASE}/files/${encodeURIComponent(fileId)}`);
|
|
@@ -2409,11 +2451,13 @@ async function getDriveFile(
|
|
|
2409
2451
|
"fields",
|
|
2410
2452
|
"id,name,mimeType,driveId,parents,modifiedTime,createdTime,version,md5Checksum,size,webViewLink,trashed",
|
|
2411
2453
|
);
|
|
2412
|
-
const response = await
|
|
2413
|
-
|
|
2414
|
-
|
|
2415
|
-
|
|
2416
|
-
|
|
2454
|
+
const response = await requestGoogleDrive(
|
|
2455
|
+
url,
|
|
2456
|
+
{ headers: { authorization, accept: "application/json" } },
|
|
2457
|
+
"get_file",
|
|
2458
|
+
retry,
|
|
2459
|
+
observability,
|
|
2460
|
+
);
|
|
2417
2461
|
if (response.status === 404) return null;
|
|
2418
2462
|
if (!response.ok) throwGoogleDriveResponse(response);
|
|
2419
2463
|
return parseDriveProviderItem(
|
|
@@ -2424,6 +2468,8 @@ async function getDriveFile(
|
|
|
2424
2468
|
async function listDrivePermissions(
|
|
2425
2469
|
input: { fileId: string; pageToken: string | null; pageSize: number },
|
|
2426
2470
|
authorization: string | undefined,
|
|
2471
|
+
retry: GoogleDriveProviderRetryOptions,
|
|
2472
|
+
observability: Observability,
|
|
2427
2473
|
): Promise<GoogleDrivePermissionsPage> {
|
|
2428
2474
|
if (!authorization) throw new SyncFailure("connection_reconnect_required", true, true);
|
|
2429
2475
|
const url = new URL(`${DRIVE_API_BASE}/files/${encodeURIComponent(input.fileId)}/permissions`);
|
|
@@ -2434,11 +2480,13 @@ async function listDrivePermissions(
|
|
|
2434
2480
|
"nextPageToken,permissions(id,type,emailAddress,domain,role,allowFileDiscovery,expirationTime,deleted,permissionDetails(inherited))",
|
|
2435
2481
|
);
|
|
2436
2482
|
if (input.pageToken) url.searchParams.set("pageToken", input.pageToken);
|
|
2437
|
-
const response = await
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2483
|
+
const response = await requestGoogleDrive(
|
|
2484
|
+
url,
|
|
2485
|
+
{ headers: { authorization, accept: "application/json" } },
|
|
2486
|
+
"list_permissions",
|
|
2487
|
+
retry,
|
|
2488
|
+
observability,
|
|
2489
|
+
);
|
|
2442
2490
|
if (response.status === 403 || response.status === 404) {
|
|
2443
2491
|
return { permissions: [], nextPageToken: null, denied: true };
|
|
2444
2492
|
}
|
|
@@ -2655,6 +2703,31 @@ function throwGoogleDriveResponse(response: Response): never {
|
|
|
2655
2703
|
);
|
|
2656
2704
|
}
|
|
2657
2705
|
|
|
2706
|
+
async function requestGoogleDrive(
|
|
2707
|
+
url: URL,
|
|
2708
|
+
init: RequestInit,
|
|
2709
|
+
operation: GoogleDriveProviderOperation,
|
|
2710
|
+
retry: GoogleDriveProviderRetryOptions,
|
|
2711
|
+
observability: Observability,
|
|
2712
|
+
): Promise<Response> {
|
|
2713
|
+
try {
|
|
2714
|
+
return await fetchGoogleDriveProvider({
|
|
2715
|
+
fetchImpl: fetch,
|
|
2716
|
+
url,
|
|
2717
|
+
init,
|
|
2718
|
+
operation,
|
|
2719
|
+
policy: retry,
|
|
2720
|
+
observability,
|
|
2721
|
+
heartbeat: (details) => heartbeat({ provider: "google_drive", ...details }),
|
|
2722
|
+
});
|
|
2723
|
+
} catch (error) {
|
|
2724
|
+
if (error instanceof GoogleDriveProviderTransportError) {
|
|
2725
|
+
throw new SyncFailure("provider_unavailable", true);
|
|
2726
|
+
}
|
|
2727
|
+
throw error;
|
|
2728
|
+
}
|
|
2729
|
+
}
|
|
2730
|
+
|
|
2658
2731
|
function selectedDriveSource(
|
|
2659
2732
|
metadata: ReturnType<typeof GoogleDriveConnectionMetadata.parse>,
|
|
2660
2733
|
externalSourceId: string,
|
|
@@ -2683,6 +2756,8 @@ export function googleDriveSyncProviderAccessAllowed(input: {
|
|
|
2683
2756
|
async function listDriveChildren(
|
|
2684
2757
|
input: { folderId: string; driveId: string | null; pageToken: string | null; pageSize: number },
|
|
2685
2758
|
authorization: string | undefined,
|
|
2759
|
+
retry: GoogleDriveProviderRetryOptions,
|
|
2760
|
+
observability: Observability,
|
|
2686
2761
|
): Promise<GoogleDriveInventoryPage> {
|
|
2687
2762
|
if (!authorization) throw new SyncFailure("connection_reconnect_required", true, true);
|
|
2688
2763
|
const url = new URL(`${DRIVE_API_BASE}/files`);
|
|
@@ -2702,11 +2777,13 @@ async function listDriveChildren(
|
|
|
2702
2777
|
url.searchParams.set("corpora", "drive");
|
|
2703
2778
|
url.searchParams.set("driveId", input.driveId);
|
|
2704
2779
|
}
|
|
2705
|
-
const response = await
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2780
|
+
const response = await requestGoogleDrive(
|
|
2781
|
+
url,
|
|
2782
|
+
{ headers: { authorization, accept: "application/json" } },
|
|
2783
|
+
"list_children",
|
|
2784
|
+
retry,
|
|
2785
|
+
observability,
|
|
2786
|
+
);
|
|
2710
2787
|
if (!response.ok) {
|
|
2711
2788
|
if (response.status === 401 || response.status === 403) {
|
|
2712
2789
|
throw new SyncFailure("connection_reconnect_required", true, true);
|
|
@@ -2753,6 +2830,8 @@ async function fetchDriveBytes(
|
|
|
2753
2830
|
entry: GoogleDriveInventoryEntry,
|
|
2754
2831
|
authorization: string | undefined,
|
|
2755
2832
|
maxBytes: number,
|
|
2833
|
+
retry: GoogleDriveProviderRetryOptions,
|
|
2834
|
+
observability: Observability,
|
|
2756
2835
|
): Promise<Uint8Array> {
|
|
2757
2836
|
if (!authorization) throw new SyncFailure("connection_reconnect_required", true, true);
|
|
2758
2837
|
const url =
|
|
@@ -2765,11 +2844,13 @@ async function fetchDriveBytes(
|
|
|
2765
2844
|
url.searchParams.set("alt", "media");
|
|
2766
2845
|
url.searchParams.set("supportsAllDrives", "true");
|
|
2767
2846
|
}
|
|
2768
|
-
const response = await
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2847
|
+
const response = await requestGoogleDrive(
|
|
2848
|
+
url,
|
|
2849
|
+
{ headers: { authorization } },
|
|
2850
|
+
entry.transfer.action === "export" ? "export" : "download",
|
|
2851
|
+
retry,
|
|
2852
|
+
observability,
|
|
2853
|
+
);
|
|
2773
2854
|
if (!response.ok) {
|
|
2774
2855
|
if (response.status === 401 || response.status === 403) {
|
|
2775
2856
|
throw new SyncFailure("connection_reconnect_required", true, true);
|
|
@@ -3201,6 +3282,66 @@ function inventoryLimit(
|
|
|
3201
3282
|
return null;
|
|
3202
3283
|
}
|
|
3203
3284
|
|
|
3285
|
+
function recordSyncHealthTelemetry(
|
|
3286
|
+
observability: Observability,
|
|
3287
|
+
provider: "google_drive" | "atlassian",
|
|
3288
|
+
summary: KnowledgeSourceSyncRunSummary,
|
|
3289
|
+
outcome: "succeeded" | "failed",
|
|
3290
|
+
failure?: SyncFailure,
|
|
3291
|
+
): void {
|
|
3292
|
+
observability.observeHistogram({
|
|
3293
|
+
name: "opengeni_knowledge_source_sync_terminal_batch_duration_seconds",
|
|
3294
|
+
help: "Terminal knowledge-source activity batch duration by provider and outcome.",
|
|
3295
|
+
labels: { provider, outcome },
|
|
3296
|
+
value: Math.max(0, summary.elapsedMs) / 1_000,
|
|
3297
|
+
});
|
|
3298
|
+
if (summary.providerRequests > 0) {
|
|
3299
|
+
observability.incrementCounter({
|
|
3300
|
+
name: "opengeni_knowledge_source_sync_provider_requests_total",
|
|
3301
|
+
help: "Logical provider requests consumed by knowledge-source synchronization.",
|
|
3302
|
+
labels: { provider, outcome },
|
|
3303
|
+
amount: summary.providerRequests,
|
|
3304
|
+
});
|
|
3305
|
+
}
|
|
3306
|
+
if (summary.limitReached) {
|
|
3307
|
+
observability.incrementCounter({
|
|
3308
|
+
name: "opengeni_knowledge_source_sync_limit_hits_total",
|
|
3309
|
+
help: "Knowledge-source synchronization runs stopped by an explicit resource budget.",
|
|
3310
|
+
labels: { provider, limit: summary.limitReached },
|
|
3311
|
+
});
|
|
3312
|
+
}
|
|
3313
|
+
if (summary.reconnectRequired) {
|
|
3314
|
+
observability.incrementCounter({
|
|
3315
|
+
name: "opengeni_knowledge_source_sync_reconnect_required_total",
|
|
3316
|
+
help: "Knowledge-source synchronization failures requiring connector reconnection.",
|
|
3317
|
+
labels: { provider },
|
|
3318
|
+
});
|
|
3319
|
+
}
|
|
3320
|
+
if (failure) {
|
|
3321
|
+
observability.incrementCounter({
|
|
3322
|
+
name: "opengeni_knowledge_source_sync_failures_total",
|
|
3323
|
+
help: "Knowledge-source synchronization terminal failures by bounded reason.",
|
|
3324
|
+
labels: {
|
|
3325
|
+
provider,
|
|
3326
|
+
reason: failure.code,
|
|
3327
|
+
retryable: failure.retryable ? "true" : "false",
|
|
3328
|
+
},
|
|
3329
|
+
});
|
|
3330
|
+
observability.warn("Knowledge source sync failed", {
|
|
3331
|
+
provider,
|
|
3332
|
+
outcome: failure.retryable ? "retryable_failed" : "failed",
|
|
3333
|
+
reason: failure.code,
|
|
3334
|
+
durationMs: summary.elapsedMs,
|
|
3335
|
+
});
|
|
3336
|
+
return;
|
|
3337
|
+
}
|
|
3338
|
+
observability.info("Knowledge source sync completed", {
|
|
3339
|
+
provider,
|
|
3340
|
+
outcome: "succeeded",
|
|
3341
|
+
durationMs: summary.elapsedMs,
|
|
3342
|
+
});
|
|
3343
|
+
}
|
|
3344
|
+
|
|
3204
3345
|
type SyncFailureCode = KnowledgeSourceSyncRunSummary["failures"][number]["code"];
|
|
3205
3346
|
|
|
3206
3347
|
class SyncFailure extends Error {
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import type { Settings } from "@opengeni/config";
|
|
2
|
-
import type { ConnectionCredentialsPort
|
|
2
|
+
import type { ConnectionCredentialsPort } from "@opengeni/contracts";
|
|
3
3
|
import {
|
|
4
4
|
buildConnectionTokenResolver,
|
|
5
5
|
buildHostConnectionTokenResolver,
|
|
6
|
+
resolveAcceptedConnectionUse,
|
|
7
|
+
sessionTenancyProductActivated,
|
|
6
8
|
type Database,
|
|
7
9
|
type ResolveConnectionCredentialInput,
|
|
8
10
|
type ResolveConnectionCredentialResult,
|
|
11
|
+
type SessionTurnForExecution,
|
|
9
12
|
} from "@opengeni/db";
|
|
13
|
+
import { recordTenancyCompatibilityLaneUse, type Observability } from "@opengeni/observability";
|
|
10
14
|
|
|
11
15
|
export function connectionTokenResolverForTurn(input: {
|
|
12
16
|
db: Database;
|
|
@@ -17,23 +21,193 @@ export function connectionTokenResolverForTurn(input: {
|
|
|
17
21
|
sessionId: string;
|
|
18
22
|
rootSessionId: string;
|
|
19
23
|
attemptId: string;
|
|
20
|
-
turn:
|
|
24
|
+
turn: SessionTurnForExecution;
|
|
25
|
+
authorizeAcceptedUse?: typeof resolveAcceptedConnectionUse;
|
|
26
|
+
/** Test seam for the activation fence on pre-snapshot workspace refs. */
|
|
27
|
+
isSessionTenancyProductActivated?: typeof sessionTenancyProductActivated;
|
|
28
|
+
/** Optional; used only for content-free compatibility-lane counters. */
|
|
29
|
+
observability?: Observability | null | undefined;
|
|
21
30
|
}): (request: ResolveConnectionCredentialInput) => Promise<ResolveConnectionCredentialResult> {
|
|
22
31
|
const hostResolver = input.connectionCredentials?.mcpCredentials;
|
|
23
|
-
|
|
24
|
-
|
|
32
|
+
const baseResolver = hostResolver
|
|
33
|
+
? buildHostConnectionTokenResolver(hostResolver, {
|
|
34
|
+
accountId: input.accountId,
|
|
35
|
+
workspaceId: input.workspaceId,
|
|
36
|
+
sessionId: input.sessionId,
|
|
37
|
+
rootSessionId: input.rootSessionId,
|
|
38
|
+
turnId: input.turn.id,
|
|
39
|
+
attemptId: input.attemptId,
|
|
40
|
+
executionGeneration: input.turn.executionGeneration,
|
|
41
|
+
initiator: input.turn.initiator,
|
|
42
|
+
initiatorContext: input.turn.initiatorContext,
|
|
43
|
+
surface: "model",
|
|
44
|
+
})
|
|
45
|
+
: buildConnectionTokenResolver(input.db, input.settings);
|
|
46
|
+
return async (request) => {
|
|
47
|
+
const acceptedDelegation = input.turn.personalConnectionDelegations.find(
|
|
48
|
+
(delegation) =>
|
|
49
|
+
(delegation.connectionType === undefined ||
|
|
50
|
+
delegation.connectionType === "mcp" ||
|
|
51
|
+
(delegation.connectionType === "github_personal" &&
|
|
52
|
+
delegation.serverId === "github:personal" &&
|
|
53
|
+
request.serverId === "github:personal" &&
|
|
54
|
+
request.connectionRef.provider === "github" &&
|
|
55
|
+
request.connectionRef.kind === "oauth2" &&
|
|
56
|
+
request.connectionRef.providerDomain === "github.com" &&
|
|
57
|
+
request.credentialTarget === "http_api" &&
|
|
58
|
+
isGitHubApiDestination(request.destinationUrl))) &&
|
|
59
|
+
delegation.serverId === request.serverId &&
|
|
60
|
+
delegation.connectionId === request.connectionRef.connectionId,
|
|
61
|
+
);
|
|
62
|
+
const subjectScope: "subject" | "workspace" =
|
|
63
|
+
request.connectionRef.subjectScope === "subject" ? "subject" : "workspace";
|
|
64
|
+
// Every subject-scoped request must match an exact connection frozen on the
|
|
65
|
+
// accepted turn. This also hard-fences pre-cutover common-user turns that
|
|
66
|
+
// lack a userDelegation: the DB resolver denies those rows because only a
|
|
67
|
+
// true legacy_user connection is eligible for bounded compatibility.
|
|
68
|
+
if (
|
|
69
|
+
subjectScope === "subject" &&
|
|
70
|
+
(!acceptedDelegation || !request.connectionRef.connectionId)
|
|
71
|
+
) {
|
|
72
|
+
return {
|
|
73
|
+
status: "auth_needed",
|
|
74
|
+
reason: "personal_authority_unavailable",
|
|
75
|
+
providerDomain: request.connectionRef.providerDomain,
|
|
76
|
+
...(request.connectionRef.provider ? { provider: request.connectionRef.provider } : {}),
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
// Workspace-scope requests now run through the same accepted-use authority
|
|
80
|
+
// (migration 0279): the exact workspace-owned connection is revalidated
|
|
81
|
+
// inside the canonical lifecycle fences and every use leaves an idempotent
|
|
82
|
+
// audit fact. A ref with no connection id is the bounded pre-snapshot
|
|
83
|
+
// legacy path - it cannot be authorized by exact identity, so it keeps the
|
|
84
|
+
// unprivileged resolution the old short-circuit used.
|
|
85
|
+
if (subjectScope === "workspace" && !request.connectionRef.connectionId) {
|
|
86
|
+
if (
|
|
87
|
+
await (input.isSessionTenancyProductActivated ?? sessionTenancyProductActivated)(
|
|
88
|
+
input.db,
|
|
89
|
+
input.workspaceId,
|
|
90
|
+
)
|
|
91
|
+
) {
|
|
92
|
+
return {
|
|
93
|
+
status: "auth_needed",
|
|
94
|
+
reason: "missing_connection",
|
|
95
|
+
providerDomain: request.connectionRef.providerDomain,
|
|
96
|
+
...(request.connectionRef.provider ? { provider: request.connectionRef.provider } : {}),
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
// This lane writes no `connection_use_audit_facts` row, so this counter is
|
|
100
|
+
// the only evidence it was taken. Lane name only - never the server,
|
|
101
|
+
// provider domain, connection, or subject.
|
|
102
|
+
recordTenancyCompatibilityLaneUse(input.observability, "connection_pre_snapshot_ref");
|
|
103
|
+
return await baseResolver(request);
|
|
104
|
+
}
|
|
105
|
+
const credentialUseContext = {
|
|
106
|
+
accountId: input.accountId,
|
|
107
|
+
workspaceId: input.workspaceId,
|
|
108
|
+
sessionId: input.sessionId,
|
|
109
|
+
turnId: input.turn.id,
|
|
110
|
+
attemptId: input.attemptId,
|
|
111
|
+
executionGeneration: input.turn.executionGeneration,
|
|
112
|
+
physicalRequestId: crypto.randomUUID(),
|
|
113
|
+
usePhase: "credential_resolution" as const,
|
|
114
|
+
};
|
|
115
|
+
const authorityBinding = {
|
|
116
|
+
serverId: request.serverId,
|
|
117
|
+
// Both lane guards above require an exact connection id at this point.
|
|
118
|
+
...(request.connectionRef.connectionId
|
|
119
|
+
? { connectionId: request.connectionRef.connectionId }
|
|
120
|
+
: {}),
|
|
121
|
+
providerDomain: request.connectionRef.providerDomain,
|
|
122
|
+
...(request.connectionRef.kind ? { connectionKind: request.connectionRef.kind } : {}),
|
|
123
|
+
subjectScope,
|
|
124
|
+
...(subjectScope === "subject" && request.subjectId
|
|
125
|
+
? { ownerSubjectId: request.subjectId }
|
|
126
|
+
: {}),
|
|
127
|
+
};
|
|
128
|
+
const authorize = async (
|
|
129
|
+
context: Omit<typeof credentialUseContext, "usePhase"> & {
|
|
130
|
+
usePhase: "credential_resolution" | "provider_request";
|
|
131
|
+
},
|
|
132
|
+
) =>
|
|
133
|
+
await (input.authorizeAcceptedUse ?? resolveAcceptedConnectionUse)(input.db, {
|
|
134
|
+
...context,
|
|
135
|
+
...authorityBinding,
|
|
136
|
+
});
|
|
137
|
+
const withProviderRequestAuthorization = (
|
|
138
|
+
result: ResolveConnectionCredentialResult,
|
|
139
|
+
): ResolveConnectionCredentialResult => {
|
|
140
|
+
if (result.status !== "ok") return result;
|
|
141
|
+
return {
|
|
142
|
+
...result,
|
|
143
|
+
authorizeProviderRequest: async () => {
|
|
144
|
+
const authorization = await authorize({
|
|
145
|
+
...credentialUseContext,
|
|
146
|
+
physicalRequestId: crypto.randomUUID(),
|
|
147
|
+
usePhase: "provider_request",
|
|
148
|
+
});
|
|
149
|
+
return authorization.status === "authorized";
|
|
150
|
+
},
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
// One place records the `legacy_user` lane for both resolution paths: the
|
|
154
|
+
// scope comes back on the resolver result when the DB resolver authorized
|
|
155
|
+
// internally, and on the resolution itself when the host resolver did.
|
|
156
|
+
const recordAuthorizedScope = (scope: "workspace" | "user" | "legacy_user" | undefined) => {
|
|
157
|
+
if (scope === "legacy_user") {
|
|
158
|
+
recordTenancyCompatibilityLaneUse(input.observability, "connection_legacy_user");
|
|
159
|
+
}
|
|
160
|
+
};
|
|
161
|
+
if (!hostResolver) {
|
|
162
|
+
const result = await baseResolver({
|
|
163
|
+
...request,
|
|
164
|
+
connectionUseContext: credentialUseContext,
|
|
165
|
+
});
|
|
166
|
+
if (result.status === "ok") recordAuthorizedScope(result.connectionUseAttribution?.scope);
|
|
167
|
+
return withProviderRequestAuthorization(result);
|
|
168
|
+
}
|
|
169
|
+
const authorization = await authorize(credentialUseContext);
|
|
170
|
+
if (authorization.status === "denied") {
|
|
171
|
+
return {
|
|
172
|
+
status: "auth_needed",
|
|
173
|
+
reason:
|
|
174
|
+
request.connectionRef.subjectScope === "subject"
|
|
175
|
+
? "personal_authority_unavailable"
|
|
176
|
+
: "missing_connection",
|
|
177
|
+
providerDomain: request.connectionRef.providerDomain,
|
|
178
|
+
...(request.connectionRef.provider ? { provider: request.connectionRef.provider } : {}),
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
recordAuthorizedScope(authorization.attribution.scope);
|
|
182
|
+
const result = await baseResolver({
|
|
183
|
+
...request,
|
|
184
|
+
connectionUseContext: credentialUseContext,
|
|
185
|
+
connectionUseAuthority: authorization.attribution,
|
|
186
|
+
connectionRef: {
|
|
187
|
+
...request.connectionRef,
|
|
188
|
+
connectionId: authorization.attribution.connectionId,
|
|
189
|
+
kind: authorization.connectionKind,
|
|
190
|
+
subjectScope: authorization.attribution.scope === "workspace" ? "workspace" : "subject",
|
|
191
|
+
},
|
|
192
|
+
...(authorization.attribution.ownerSubjectId
|
|
193
|
+
? { subjectId: authorization.attribution.ownerSubjectId }
|
|
194
|
+
: {}),
|
|
195
|
+
});
|
|
196
|
+
return withProviderRequestAuthorization(result);
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function isGitHubApiDestination(value: string): boolean {
|
|
201
|
+
try {
|
|
202
|
+
const url = new URL(value);
|
|
203
|
+
return (
|
|
204
|
+
url.protocol === "https:" &&
|
|
205
|
+
url.origin === "https://api.github.com" &&
|
|
206
|
+
url.username === "" &&
|
|
207
|
+
url.password === "" &&
|
|
208
|
+
url.hash === ""
|
|
209
|
+
);
|
|
210
|
+
} catch {
|
|
211
|
+
return false;
|
|
25
212
|
}
|
|
26
|
-
return buildHostConnectionTokenResolver(hostResolver, {
|
|
27
|
-
accountId: input.accountId,
|
|
28
|
-
workspaceId: input.workspaceId,
|
|
29
|
-
sessionId: input.sessionId,
|
|
30
|
-
rootSessionId: input.rootSessionId,
|
|
31
|
-
turnId: input.turn.id,
|
|
32
|
-
attemptId: input.attemptId,
|
|
33
|
-
executionGeneration: input.turn.executionGeneration,
|
|
34
|
-
initiator: input.turn.initiator,
|
|
35
|
-
initiatorContext: input.turn.initiatorContext,
|
|
36
|
-
surface: "model",
|
|
37
|
-
allowOfficialGmailRestDestination: input.settings.gmailRestAdapterEnabled,
|
|
38
|
-
});
|
|
39
213
|
}
|