@opengeni/worker-bundle 0.20.0 → 0.20.3
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 +25 -2
- package/dist/activities/google-drive-publication.d.ts +53 -0
- package/dist/activities/image-generation-references.d.ts +2 -0
- package/dist/activities/knowledge-source-sync-driver.d.ts +21 -0
- package/dist/activities/knowledge-source-sync.d.ts +29 -1
- package/dist/activities/run-input.d.ts +20 -2
- package/dist/activities/session-state.d.ts +5 -3
- package/dist/activities/types.d.ts +27 -0
- package/dist/{activities-control-XURE4VKN.js → activities-control-BJSDRSIP.js} +369 -20
- package/dist/activities-control-BJSDRSIP.js.map +1 -0
- package/dist/activities-control.d.ts +2 -2
- package/dist/{activities-turn-6EBXGGLS.js → activities-turn-J5YO7XXX.js} +2281 -1074
- package/dist/activities-turn-J5YO7XXX.js.map +1 -0
- package/dist/activities.d.ts +3 -3
- package/dist/{chunk-TYNPCG4U.js → chunk-N5TJIFCE.js} +69 -1
- package/dist/chunk-N5TJIFCE.js.map +1 -0
- package/dist/{chunk-5GRJIP5H.js → chunk-P6Z2SLAA.js} +2 -2
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/observability-metrics.d.ts +37 -0
- package/dist/workflow-bundle.js +174 -4
- package/dist/workflows/session.d.ts +17 -1
- package/package.json +13 -13
- package/src/activities/agent-turn.ts +1801 -1175
- package/src/activities/documents.ts +6 -4
- package/src/activities/google-drive-publication.ts +840 -0
- package/src/activities/image-generation-references.ts +11 -2
- package/src/activities/knowledge-source-sync-driver.ts +23 -0
- package/src/activities/knowledge-source-sync.ts +384 -9
- package/src/activities/run-input.ts +175 -51
- package/src/activities/session-state.ts +69 -5
- package/src/activities/types.ts +27 -0
- package/src/activities.ts +2 -0
- package/src/observability-metrics.ts +184 -3
- package/src/workflows/session.ts +199 -8
- package/dist/activities-control-XURE4VKN.js.map +0 -1
- package/dist/activities-turn-6EBXGGLS.js.map +0 -1
- package/dist/chunk-TYNPCG4U.js.map +0 -1
- /package/dist/{chunk-5GRJIP5H.js.map → chunk-P6Z2SLAA.js.map} +0 -0
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
settingsWithRigImage,
|
|
24
24
|
withFirstPartyTools,
|
|
25
25
|
workflowIdForSession
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-P6Z2SLAA.js";
|
|
27
27
|
import {
|
|
28
28
|
recordCreditBalanceGauges,
|
|
29
29
|
recordCreditMicros,
|
|
@@ -39,7 +39,7 @@ import {
|
|
|
39
39
|
recordSandboxOrphansTerminated,
|
|
40
40
|
recordSandboxRotationBacklogGauges,
|
|
41
41
|
recordTurnsQueuedGauge
|
|
42
|
-
} from "./chunk-
|
|
42
|
+
} from "./chunk-N5TJIFCE.js";
|
|
43
43
|
|
|
44
44
|
// src/activities/browser-state-artifact-reaper.ts
|
|
45
45
|
import {
|
|
@@ -145,7 +145,7 @@ function createDocumentActivities(services, resolveDocumentServices) {
|
|
|
145
145
|
if (!resolveDocumentServices) {
|
|
146
146
|
throw new Error("document services are not configured");
|
|
147
147
|
}
|
|
148
|
-
const [{
|
|
148
|
+
const [{ getDocumentForIndexing, indexDocumentNow }, documentServices] = await Promise.all([
|
|
149
149
|
import("@opengeni/documents"),
|
|
150
150
|
resolveDocumentServices()
|
|
151
151
|
]);
|
|
@@ -173,9 +173,11 @@ function createDocumentActivities(services, resolveDocumentServices) {
|
|
|
173
173
|
if (suppliedCount !== 0 && suppliedCount !== suppliedAuthorityFields.length) {
|
|
174
174
|
throw new Error("document authority tuple is partial");
|
|
175
175
|
}
|
|
176
|
-
const claimedDocument = await
|
|
177
|
-
|
|
178
|
-
|
|
176
|
+
const claimedDocument = await getDocumentForIndexing(
|
|
177
|
+
lockedDb,
|
|
178
|
+
input.workspaceId,
|
|
179
|
+
input.documentId
|
|
180
|
+
);
|
|
179
181
|
if (!claimedDocument || claimedDocument.authorityKind !== storedAuthority.authorityKind || claimedDocument.authorityWorkspaceId !== storedAuthority.authorityWorkspaceId || claimedDocument.authoritySubjectId !== storedAuthority.authoritySubjectId) {
|
|
180
182
|
throw new Error("document authority changed before indexing");
|
|
181
183
|
}
|
|
@@ -431,6 +433,7 @@ import {
|
|
|
431
433
|
appendKnowledgeDocumentVersion,
|
|
432
434
|
appendKnowledgeSourceAclVersion,
|
|
433
435
|
beginKnowledgeSyncRun,
|
|
436
|
+
beginGoogleDriveObjectAclRefresh,
|
|
434
437
|
buildConnectionTokenResolver,
|
|
435
438
|
checkpointKnowledgeSourceSync,
|
|
436
439
|
claimKnowledgeSourceSyncLease,
|
|
@@ -452,6 +455,7 @@ import {
|
|
|
452
455
|
KnowledgeSourceSyncObservationFenceError,
|
|
453
456
|
reconcileKnowledgeSourceSyncCompleteScan,
|
|
454
457
|
reconcileKnowledgeSourceSyncLiveGeneration,
|
|
458
|
+
recordGoogleDriveObjectAclEvidence,
|
|
455
459
|
recordKnowledgeSourceSyncItemOutcomes,
|
|
456
460
|
recordKnowledgeSourceSyncObjectObservations,
|
|
457
461
|
recordUsageEvent as recordUsageEvent2,
|
|
@@ -747,6 +751,8 @@ var DRIVE_JSON_MAX_BYTES = 2 * 1024 * 1024;
|
|
|
747
751
|
var GOOGLE_DRIVE_FULL_RECONCILIATION_INTERVAL_MS = 24 * 60 * 60 * 1e3;
|
|
748
752
|
var GOOGLE_DRIVE_SYNC_INVOCATION_SLICE_MS = 3e4;
|
|
749
753
|
var GOOGLE_DRIVE_EXECUTION_CHECKPOINT_MAX_BYTES = 2 * 1024 * 1024;
|
|
754
|
+
var GOOGLE_DRIVE_ACL_FRESHNESS_MS = 26 * 60 * 60 * 1e3;
|
|
755
|
+
var GOOGLE_DRIVE_ACL_MAX_PRINCIPALS = 1e3;
|
|
750
756
|
var ATLASSIAN_API_BASE = "https://api.atlassian.com";
|
|
751
757
|
var ATLASSIAN_JSON_MAX_BYTES = 4 * 1024 * 1024;
|
|
752
758
|
function knowledgeSyncObservationPolicy(kind) {
|
|
@@ -1008,7 +1014,26 @@ function createKnowledgeSourceSyncActivities(services, resolveDocumentServices)
|
|
|
1008
1014
|
if (obligation.documentId !== details.version.documentId) {
|
|
1009
1015
|
throw new SyncFailure("authority_changed", false);
|
|
1010
1016
|
}
|
|
1011
|
-
if (obligation.status === "indexed") return obligation;
|
|
1017
|
+
if (obligation.status === "indexed" && !details.indexRequired) return obligation;
|
|
1018
|
+
if (obligation.status === "indexed" && details.indexRequired) {
|
|
1019
|
+
summary.phase = "index";
|
|
1020
|
+
try {
|
|
1021
|
+
const indexedDocument = await documentActivities.indexDocument({
|
|
1022
|
+
accountId: input.accountId,
|
|
1023
|
+
workspaceId: input.workspaceId,
|
|
1024
|
+
documentId: details.version.documentId,
|
|
1025
|
+
authorityKind: action.destination.kind,
|
|
1026
|
+
authorityWorkspaceId: action.destination.workspaceId,
|
|
1027
|
+
authoritySubjectId: action.destination.subjectId
|
|
1028
|
+
});
|
|
1029
|
+
if (indexedDocument.status !== "ready") {
|
|
1030
|
+
throw new Error("document indexing did not complete");
|
|
1031
|
+
}
|
|
1032
|
+
} catch {
|
|
1033
|
+
throw new SyncFailure("indexing_failed", true);
|
|
1034
|
+
}
|
|
1035
|
+
return obligation;
|
|
1036
|
+
}
|
|
1012
1037
|
if (obligation.status === "failed") {
|
|
1013
1038
|
const retried = await retryKnowledgeSourceSyncIndexObligation(db, {
|
|
1014
1039
|
accountId: input.accountId,
|
|
@@ -1061,6 +1086,64 @@ function createKnowledgeSourceSyncActivities(services, resolveDocumentServices)
|
|
|
1061
1086
|
}
|
|
1062
1087
|
return { ...obligation, status: "indexed" };
|
|
1063
1088
|
};
|
|
1089
|
+
const recordEntryAcl = async (details) => {
|
|
1090
|
+
if (!driver.readAcl || !provider.aclAuthority) {
|
|
1091
|
+
return { aclEligibility: "pending", aclEvidence: null };
|
|
1092
|
+
}
|
|
1093
|
+
await beginGoogleDriveObjectAclRefresh(db, {
|
|
1094
|
+
accountId: input.accountId,
|
|
1095
|
+
workspaceId: input.workspaceId,
|
|
1096
|
+
obligationId: details.obligation.id,
|
|
1097
|
+
sourceSyncGeneration: details.obligation.sourceSyncGeneration,
|
|
1098
|
+
sourceConfigGeneration: action.sourceConfigGeneration,
|
|
1099
|
+
sourceLifecycleGeneration: action.sourceLifecycleGeneration,
|
|
1100
|
+
objectLifecycleGeneration: details.object.lifecycleGeneration,
|
|
1101
|
+
objectVersionGeneration: details.version.versionGeneration
|
|
1102
|
+
});
|
|
1103
|
+
const remainingProviderRequests = action.limits.maxProviderRequests - summary.providerRequests;
|
|
1104
|
+
if (remainingProviderRequests < 1) {
|
|
1105
|
+
throw new SyncFailure("resource_limit", false);
|
|
1106
|
+
}
|
|
1107
|
+
const evidence = await driver.readAcl(details.entry, remainingProviderRequests);
|
|
1108
|
+
summary.providerRequests += evidence.providerRequests;
|
|
1109
|
+
if (summary.providerRequests > action.limits.maxProviderRequests) {
|
|
1110
|
+
throw new SyncFailure("resource_limit", false);
|
|
1111
|
+
}
|
|
1112
|
+
const recorded = await recordGoogleDriveObjectAclEvidence(db, {
|
|
1113
|
+
accountId: input.accountId,
|
|
1114
|
+
workspaceId: input.workspaceId,
|
|
1115
|
+
obligationId: details.obligation.id,
|
|
1116
|
+
connectionId: provider.aclAuthority.connectionId,
|
|
1117
|
+
connectionVersion: provider.aclAuthority.connectionVersion,
|
|
1118
|
+
sourceGooglePermissionId: provider.aclAuthority.sourceGooglePermissionId,
|
|
1119
|
+
sourceSyncGeneration: details.obligation.sourceSyncGeneration,
|
|
1120
|
+
sourceConfigGeneration: action.sourceConfigGeneration,
|
|
1121
|
+
sourceLifecycleGeneration: action.sourceLifecycleGeneration,
|
|
1122
|
+
objectLifecycleGeneration: details.object.lifecycleGeneration,
|
|
1123
|
+
objectVersionGeneration: details.version.versionGeneration,
|
|
1124
|
+
providerRevision: evidence.providerRevision,
|
|
1125
|
+
driveId: evidence.driveId,
|
|
1126
|
+
aclRevision: evidence.aclRevision,
|
|
1127
|
+
eligibility: evidence.eligibility,
|
|
1128
|
+
observedAt: evidence.observedAt,
|
|
1129
|
+
expiresAt: evidence.expiresAt,
|
|
1130
|
+
citationLocator: driver.citationLocator(details.entry),
|
|
1131
|
+
operationId: `drive-acl:${details.obligation.id}:${evidence.aclRevision}`,
|
|
1132
|
+
principals: evidence.principals
|
|
1133
|
+
});
|
|
1134
|
+
return {
|
|
1135
|
+
aclEligibility: evidence.eligibility,
|
|
1136
|
+
aclEvidence: {
|
|
1137
|
+
version: 1,
|
|
1138
|
+
provider: "google_drive",
|
|
1139
|
+
evidenceId: recorded.evidenceId,
|
|
1140
|
+
aclRevision: evidence.aclRevision,
|
|
1141
|
+
aclHash: recorded.aclHash,
|
|
1142
|
+
observedAt: evidence.observedAt,
|
|
1143
|
+
expiresAt: evidence.expiresAt
|
|
1144
|
+
}
|
|
1145
|
+
};
|
|
1146
|
+
};
|
|
1064
1147
|
const outcomes = [];
|
|
1065
1148
|
for (const entry of entriesToProcess) {
|
|
1066
1149
|
heartbeat({ sourceId: input.sourceId, externalObjectId: entry.externalObjectId });
|
|
@@ -1158,9 +1241,15 @@ function createKnowledgeSourceSyncActivities(services, resolveDocumentServices)
|
|
|
1158
1241
|
entry,
|
|
1159
1242
|
object,
|
|
1160
1243
|
version: currentVersion,
|
|
1161
|
-
indexRequired:
|
|
1244
|
+
indexRequired: (currentObservation?.documentChunkCount ?? 0) === 0,
|
|
1162
1245
|
obligation: currentObligation
|
|
1163
1246
|
});
|
|
1247
|
+
const objectAcl2 = await recordEntryAcl({
|
|
1248
|
+
entry,
|
|
1249
|
+
object,
|
|
1250
|
+
version: currentVersion,
|
|
1251
|
+
obligation: obligation2
|
|
1252
|
+
});
|
|
1164
1253
|
summary.unchanged += 1;
|
|
1165
1254
|
outcomes.push({
|
|
1166
1255
|
externalObjectId: entry.externalObjectId,
|
|
@@ -1168,7 +1257,8 @@ function createKnowledgeSourceSyncActivities(services, resolveDocumentServices)
|
|
|
1168
1257
|
contentSha256: currentVersion.contentSha256,
|
|
1169
1258
|
providerRevision: entry.externalVersionId,
|
|
1170
1259
|
metadataHash,
|
|
1171
|
-
aclEligibility:
|
|
1260
|
+
aclEligibility: objectAcl2.aclEligibility,
|
|
1261
|
+
aclEvidence: objectAcl2.aclEvidence,
|
|
1172
1262
|
indexObligationId: obligation2.id
|
|
1173
1263
|
});
|
|
1174
1264
|
continue;
|
|
@@ -1249,9 +1339,10 @@ function createKnowledgeSourceSyncActivities(services, resolveDocumentServices)
|
|
|
1249
1339
|
version: version2,
|
|
1250
1340
|
indexRequired: (currentObservation?.documentChunkCount ?? 0) === 0
|
|
1251
1341
|
});
|
|
1342
|
+
const objectAcl2 = await recordEntryAcl({ entry, object, version: version2, obligation: obligation2 });
|
|
1252
1343
|
summary.unchanged += 1;
|
|
1253
1344
|
summary.indexed += 1;
|
|
1254
|
-
summary.aclPending += 1;
|
|
1345
|
+
if (objectAcl2.aclEligibility === "pending") summary.aclPending += 1;
|
|
1255
1346
|
outcomes.push({
|
|
1256
1347
|
externalObjectId: entry.externalObjectId,
|
|
1257
1348
|
outcome: "unchanged",
|
|
@@ -1259,7 +1350,8 @@ function createKnowledgeSourceSyncActivities(services, resolveDocumentServices)
|
|
|
1259
1350
|
sizeBytes: bytes.byteLength,
|
|
1260
1351
|
providerRevision: entry.externalVersionId,
|
|
1261
1352
|
metadataHash,
|
|
1262
|
-
aclEligibility:
|
|
1353
|
+
aclEligibility: objectAcl2.aclEligibility,
|
|
1354
|
+
aclEvidence: objectAcl2.aclEvidence,
|
|
1263
1355
|
indexObligationId: obligation2.id
|
|
1264
1356
|
});
|
|
1265
1357
|
continue;
|
|
@@ -1349,9 +1441,10 @@ function createKnowledgeSourceSyncActivities(services, resolveDocumentServices)
|
|
|
1349
1441
|
version,
|
|
1350
1442
|
indexRequired: true
|
|
1351
1443
|
});
|
|
1444
|
+
const objectAcl = await recordEntryAcl({ entry, object, version, obligation });
|
|
1352
1445
|
summary.indexed += 1;
|
|
1353
1446
|
summary.imported += 1;
|
|
1354
|
-
summary.aclPending += 1;
|
|
1447
|
+
if (objectAcl.aclEligibility === "pending") summary.aclPending += 1;
|
|
1355
1448
|
summary.bytes += bytes.byteLength;
|
|
1356
1449
|
outcomes.push({
|
|
1357
1450
|
externalObjectId: entry.externalObjectId,
|
|
@@ -1360,7 +1453,8 @@ function createKnowledgeSourceSyncActivities(services, resolveDocumentServices)
|
|
|
1360
1453
|
sizeBytes: bytes.byteLength,
|
|
1361
1454
|
providerRevision: entry.externalVersionId,
|
|
1362
1455
|
metadataHash,
|
|
1363
|
-
aclEligibility:
|
|
1456
|
+
aclEligibility: objectAcl.aclEligibility,
|
|
1457
|
+
aclEvidence: objectAcl.aclEvidence,
|
|
1364
1458
|
indexObligationId: obligation.id
|
|
1365
1459
|
});
|
|
1366
1460
|
} catch (error) {
|
|
@@ -1771,6 +1865,11 @@ async function resolveKnowledgeSyncProvider(input) {
|
|
|
1771
1865
|
return {
|
|
1772
1866
|
kind: "google_drive",
|
|
1773
1867
|
selectedDestination: source.destination,
|
|
1868
|
+
aclAuthority: {
|
|
1869
|
+
connectionId: resolvedConnection.id,
|
|
1870
|
+
connectionVersion: resolvedConnection.version,
|
|
1871
|
+
sourceGooglePermissionId: metadata.googlePermissionId
|
|
1872
|
+
},
|
|
1774
1873
|
driver: googleDriveSyncDriver({
|
|
1775
1874
|
actionProviderCoordinationKey: action.providerCoordinationKey,
|
|
1776
1875
|
metadata,
|
|
@@ -1803,6 +1902,7 @@ async function resolveKnowledgeSyncProvider(input) {
|
|
|
1803
1902
|
return {
|
|
1804
1903
|
kind: "atlassian",
|
|
1805
1904
|
selectedDestination: source.destination,
|
|
1905
|
+
aclAuthority: null,
|
|
1806
1906
|
driver: atlassianSyncDriver({
|
|
1807
1907
|
actionProviderCoordinationKey: action.providerCoordinationKey,
|
|
1808
1908
|
metadata,
|
|
@@ -1866,7 +1966,8 @@ function googleDriveSyncDriver(input) {
|
|
|
1866
1966
|
getStartPageToken: async (driveId) => await getDriveStartPageToken(driveId, input.authorization),
|
|
1867
1967
|
listChanges: async (pageToken, driveId, pageSize) => await listDriveChanges(pageToken, driveId, pageSize, input.authorization),
|
|
1868
1968
|
getFile: async (fileId) => await getDriveFile(fileId, input.authorization),
|
|
1869
|
-
listChildren: async (request) => await listDriveChildren(request, input.authorization)
|
|
1969
|
+
listChildren: async (request) => await listDriveChildren(request, input.authorization),
|
|
1970
|
+
listPermissions: async (request) => await listDrivePermissions(request, input.authorization)
|
|
1870
1971
|
};
|
|
1871
1972
|
const clock = provider.now ?? Date.now;
|
|
1872
1973
|
const budgetLimits = {
|
|
@@ -2178,11 +2279,25 @@ function googleDriveSyncDriver(input) {
|
|
|
2178
2279
|
}
|
|
2179
2280
|
},
|
|
2180
2281
|
fetchContent: async (entry, maxBytes) => await fetchDriveBytes(entry, input.authorization, maxBytes),
|
|
2282
|
+
readAcl: async (entry, maxProviderRequests) => {
|
|
2283
|
+
if (!provider.listPermissions) {
|
|
2284
|
+
throw new SyncFailure("provider_rejected", false);
|
|
2285
|
+
}
|
|
2286
|
+
return await collectGoogleDriveAclEvidence({
|
|
2287
|
+
entry,
|
|
2288
|
+
maxProviderRequests,
|
|
2289
|
+
listPermissions: provider.listPermissions,
|
|
2290
|
+
getFile: provider.getFile,
|
|
2291
|
+
now: clock
|
|
2292
|
+
});
|
|
2293
|
+
},
|
|
2181
2294
|
citationLocator: (entry) => ({
|
|
2182
|
-
version:
|
|
2295
|
+
version: 2,
|
|
2183
2296
|
providerKey: "google-drive",
|
|
2184
2297
|
providerCoordinationKey: input.actionProviderCoordinationKey,
|
|
2185
2298
|
externalObjectId: entry.externalObjectId,
|
|
2299
|
+
providerRevision: entry.externalVersionId,
|
|
2300
|
+
driveId: entry.driveId,
|
|
2186
2301
|
sourceUri: entry.sourceUri
|
|
2187
2302
|
})
|
|
2188
2303
|
};
|
|
@@ -2428,6 +2543,193 @@ async function getDriveFile(fileId, authorization) {
|
|
|
2428
2543
|
await readResponseJsonBounded(response, DRIVE_JSON_MAX_BYTES, "Google Drive file metadata")
|
|
2429
2544
|
);
|
|
2430
2545
|
}
|
|
2546
|
+
async function listDrivePermissions(input, authorization) {
|
|
2547
|
+
if (!authorization) throw new SyncFailure("connection_reconnect_required", true, true);
|
|
2548
|
+
const url = new URL(`${DRIVE_API_BASE}/files/${encodeURIComponent(input.fileId)}/permissions`);
|
|
2549
|
+
url.searchParams.set("supportsAllDrives", "true");
|
|
2550
|
+
url.searchParams.set("pageSize", String(input.pageSize));
|
|
2551
|
+
url.searchParams.set(
|
|
2552
|
+
"fields",
|
|
2553
|
+
"nextPageToken,permissions(id,type,emailAddress,domain,role,allowFileDiscovery,expirationTime,deleted,permissionDetails(inherited))"
|
|
2554
|
+
);
|
|
2555
|
+
if (input.pageToken) url.searchParams.set("pageToken", input.pageToken);
|
|
2556
|
+
const response = await fetch(url, {
|
|
2557
|
+
headers: { authorization, accept: "application/json" },
|
|
2558
|
+
redirect: "error",
|
|
2559
|
+
signal: AbortSignal.timeout(15e3)
|
|
2560
|
+
});
|
|
2561
|
+
if (response.status === 403 || response.status === 404) {
|
|
2562
|
+
return { permissions: [], nextPageToken: null, denied: true };
|
|
2563
|
+
}
|
|
2564
|
+
if (!response.ok) throwGoogleDriveResponse(response);
|
|
2565
|
+
const payload = await readResponseJsonBounded(
|
|
2566
|
+
response,
|
|
2567
|
+
DRIVE_JSON_MAX_BYTES,
|
|
2568
|
+
"Google Drive permission list"
|
|
2569
|
+
);
|
|
2570
|
+
const rawPermissions = Array.isArray(payload.permissions) ? payload.permissions : null;
|
|
2571
|
+
if (!rawPermissions) throw new SyncFailure("provider_payload_invalid", false);
|
|
2572
|
+
return {
|
|
2573
|
+
permissions: rawPermissions.map(parseDrivePermission),
|
|
2574
|
+
nextPageToken: optionalString(payload.nextPageToken),
|
|
2575
|
+
denied: false
|
|
2576
|
+
};
|
|
2577
|
+
}
|
|
2578
|
+
async function collectGoogleDriveAclEvidence(input) {
|
|
2579
|
+
if (!Number.isSafeInteger(input.maxProviderRequests) || input.maxProviderRequests < 1) {
|
|
2580
|
+
throw new SyncFailure("resource_limit", false);
|
|
2581
|
+
}
|
|
2582
|
+
const now = input.now ?? Date.now;
|
|
2583
|
+
const observedAt = new Date(now());
|
|
2584
|
+
if (!Number.isFinite(observedAt.getTime())) {
|
|
2585
|
+
throw new SyncFailure("provider_payload_invalid", false);
|
|
2586
|
+
}
|
|
2587
|
+
const permissions = [];
|
|
2588
|
+
const seenTokens = /* @__PURE__ */ new Set();
|
|
2589
|
+
let pageToken = null;
|
|
2590
|
+
let providerRequests = 0;
|
|
2591
|
+
let permissionListDenied = false;
|
|
2592
|
+
do {
|
|
2593
|
+
if (providerRequests >= input.maxProviderRequests) {
|
|
2594
|
+
throw new SyncFailure("resource_limit", false);
|
|
2595
|
+
}
|
|
2596
|
+
providerRequests += 1;
|
|
2597
|
+
const page = await input.listPermissions({
|
|
2598
|
+
fileId: input.entry.externalObjectId,
|
|
2599
|
+
pageToken,
|
|
2600
|
+
pageSize: Math.min(100, GOOGLE_DRIVE_ACL_MAX_PRINCIPALS - permissions.length)
|
|
2601
|
+
});
|
|
2602
|
+
if (page.denied) {
|
|
2603
|
+
permissionListDenied = true;
|
|
2604
|
+
break;
|
|
2605
|
+
}
|
|
2606
|
+
permissions.push(...page.permissions);
|
|
2607
|
+
if (permissions.length > GOOGLE_DRIVE_ACL_MAX_PRINCIPALS) {
|
|
2608
|
+
throw new SyncFailure("resource_limit", false);
|
|
2609
|
+
}
|
|
2610
|
+
pageToken = page.nextPageToken;
|
|
2611
|
+
if (pageToken) {
|
|
2612
|
+
if (pageToken.length > 4096 || seenTokens.has(pageToken)) {
|
|
2613
|
+
throw new SyncFailure("provider_payload_invalid", false);
|
|
2614
|
+
}
|
|
2615
|
+
seenTokens.add(pageToken);
|
|
2616
|
+
}
|
|
2617
|
+
} while (pageToken);
|
|
2618
|
+
if (permissionListDenied) {
|
|
2619
|
+
if (!input.getFile || providerRequests >= input.maxProviderRequests) {
|
|
2620
|
+
return googleDriveDeniedAclEvidence(input.entry, observedAt, providerRequests);
|
|
2621
|
+
}
|
|
2622
|
+
providerRequests += 1;
|
|
2623
|
+
const current = await input.getFile(input.entry.externalObjectId);
|
|
2624
|
+
if (!current || current.trashed) {
|
|
2625
|
+
return googleDriveDeniedAclEvidence(input.entry, observedAt, providerRequests);
|
|
2626
|
+
}
|
|
2627
|
+
const aclRevision2 = createHash2("sha256").update(
|
|
2628
|
+
JSON.stringify({
|
|
2629
|
+
version: 1,
|
|
2630
|
+
mode: "source_owner_only",
|
|
2631
|
+
externalObjectId: input.entry.externalObjectId,
|
|
2632
|
+
providerRevision: input.entry.externalVersionId
|
|
2633
|
+
})
|
|
2634
|
+
).digest("hex");
|
|
2635
|
+
return {
|
|
2636
|
+
eligibility: "eligible",
|
|
2637
|
+
providerRevision: input.entry.externalVersionId,
|
|
2638
|
+
driveId: input.entry.driveId,
|
|
2639
|
+
aclRevision: aclRevision2,
|
|
2640
|
+
observedAt: observedAt.toISOString(),
|
|
2641
|
+
expiresAt: new Date(observedAt.getTime() + GOOGLE_DRIVE_ACL_FRESHNESS_MS).toISOString(),
|
|
2642
|
+
providerRequests,
|
|
2643
|
+
principals: []
|
|
2644
|
+
};
|
|
2645
|
+
}
|
|
2646
|
+
const canonicalPermissions = permissions.map((permission) => ({
|
|
2647
|
+
id: permission.id,
|
|
2648
|
+
type: permission.type,
|
|
2649
|
+
role: permission.role,
|
|
2650
|
+
emailAddress: permission.emailAddress,
|
|
2651
|
+
domain: permission.domain,
|
|
2652
|
+
allowFileDiscovery: permission.allowFileDiscovery,
|
|
2653
|
+
expirationTime: permission.expirationTime,
|
|
2654
|
+
inherited: permission.inherited
|
|
2655
|
+
})).sort((left, right) => JSON.stringify(left).localeCompare(JSON.stringify(right)));
|
|
2656
|
+
const aclRevision = createHash2("sha256").update(
|
|
2657
|
+
JSON.stringify({
|
|
2658
|
+
version: 1,
|
|
2659
|
+
externalObjectId: input.entry.externalObjectId,
|
|
2660
|
+
providerRevision: input.entry.externalVersionId,
|
|
2661
|
+
permissions: canonicalPermissions
|
|
2662
|
+
})
|
|
2663
|
+
).digest("hex");
|
|
2664
|
+
return {
|
|
2665
|
+
eligibility: "eligible",
|
|
2666
|
+
providerRevision: input.entry.externalVersionId,
|
|
2667
|
+
driveId: input.entry.driveId,
|
|
2668
|
+
aclRevision,
|
|
2669
|
+
observedAt: observedAt.toISOString(),
|
|
2670
|
+
expiresAt: new Date(observedAt.getTime() + GOOGLE_DRIVE_ACL_FRESHNESS_MS).toISOString(),
|
|
2671
|
+
providerRequests,
|
|
2672
|
+
principals: canonicalPermissions.map((permission) => ({
|
|
2673
|
+
type: permission.type,
|
|
2674
|
+
permissionId: permission.id,
|
|
2675
|
+
emailAddress: permission.emailAddress,
|
|
2676
|
+
domain: permission.domain,
|
|
2677
|
+
role: permission.role,
|
|
2678
|
+
inherited: permission.inherited,
|
|
2679
|
+
allowFileDiscovery: permission.allowFileDiscovery,
|
|
2680
|
+
expirationTime: permission.expirationTime
|
|
2681
|
+
}))
|
|
2682
|
+
};
|
|
2683
|
+
}
|
|
2684
|
+
function googleDriveDeniedAclEvidence(entry, observedAt, providerRequests) {
|
|
2685
|
+
return {
|
|
2686
|
+
eligibility: "denied",
|
|
2687
|
+
providerRevision: entry.externalVersionId,
|
|
2688
|
+
driveId: entry.driveId,
|
|
2689
|
+
aclRevision: createHash2("sha256").update(
|
|
2690
|
+
JSON.stringify({
|
|
2691
|
+
version: 1,
|
|
2692
|
+
mode: "provider_denied",
|
|
2693
|
+
externalObjectId: entry.externalObjectId,
|
|
2694
|
+
providerRevision: entry.externalVersionId
|
|
2695
|
+
})
|
|
2696
|
+
).digest("hex"),
|
|
2697
|
+
observedAt: observedAt.toISOString(),
|
|
2698
|
+
expiresAt: new Date(observedAt.getTime() + GOOGLE_DRIVE_ACL_FRESHNESS_MS).toISOString(),
|
|
2699
|
+
providerRequests,
|
|
2700
|
+
principals: []
|
|
2701
|
+
};
|
|
2702
|
+
}
|
|
2703
|
+
function parseDrivePermission(value) {
|
|
2704
|
+
const row = objectRecord(value);
|
|
2705
|
+
if (row.deleted === true) throw new SyncFailure("provider_payload_invalid", false);
|
|
2706
|
+
const type = requiredString(row.type, "permission.type");
|
|
2707
|
+
if (type !== "user" && type !== "group" && type !== "domain" && type !== "anyone") {
|
|
2708
|
+
throw new SyncFailure("provider_payload_invalid", false);
|
|
2709
|
+
}
|
|
2710
|
+
const role = requiredString(row.role, "permission.role");
|
|
2711
|
+
if (role !== "owner" && role !== "organizer" && role !== "fileOrganizer" && role !== "writer" && role !== "commenter" && role !== "reader") {
|
|
2712
|
+
throw new SyncFailure("provider_payload_invalid", false);
|
|
2713
|
+
}
|
|
2714
|
+
const permissionDetails = Array.isArray(row.permissionDetails) ? row.permissionDetails : [];
|
|
2715
|
+
return {
|
|
2716
|
+
id: requiredString(row.id, "permission.id"),
|
|
2717
|
+
type,
|
|
2718
|
+
role,
|
|
2719
|
+
emailAddress: optionalString(row.emailAddress),
|
|
2720
|
+
domain: optionalString(row.domain),
|
|
2721
|
+
allowFileDiscovery: typeof row.allowFileDiscovery === "boolean" ? row.allowFileDiscovery : null,
|
|
2722
|
+
expirationTime: optionalExactProviderTimestamp(row.expirationTime),
|
|
2723
|
+
inherited: permissionDetails.some((detail) => objectRecord(detail).inherited === true)
|
|
2724
|
+
};
|
|
2725
|
+
}
|
|
2726
|
+
function optionalExactProviderTimestamp(value) {
|
|
2727
|
+
const timestamp = optionalString(value);
|
|
2728
|
+
if (!timestamp) return null;
|
|
2729
|
+
const parsed = new Date(timestamp);
|
|
2730
|
+
if (!Number.isFinite(parsed.getTime())) throw new SyncFailure("provider_payload_invalid", false);
|
|
2731
|
+
return parsed.toISOString();
|
|
2732
|
+
}
|
|
2431
2733
|
function throwGoogleDriveResponse(response) {
|
|
2432
2734
|
if (response.status === 401 || response.status === 403) {
|
|
2433
2735
|
throw new SyncFailure("connection_reconnect_required", true, true);
|
|
@@ -6861,6 +7163,8 @@ function maintenanceErrorCategory(error) {
|
|
|
6861
7163
|
import {
|
|
6862
7164
|
settleSessionAttemptInterruptions,
|
|
6863
7165
|
applySessionTurnSettlement,
|
|
7166
|
+
enqueueSessionWorkflowWake,
|
|
7167
|
+
failSessionWorkBeforeAttemptClaim,
|
|
6864
7168
|
requestSessionTurnRecovery,
|
|
6865
7169
|
recoverSessionDispatch,
|
|
6866
7170
|
reconcileSessionAttemptQuiescence,
|
|
@@ -6880,6 +7184,8 @@ var WORKER_DEATH_MAX_REDISPATCHES = 3;
|
|
|
6880
7184
|
function createSessionStateActivities(services, overrides = {}) {
|
|
6881
7185
|
const settleSessionAttemptInterruptionsFn = overrides.settleSessionAttemptInterruptions ?? settleSessionAttemptInterruptions;
|
|
6882
7186
|
const applySessionTurnSettlementFn = overrides.applySessionTurnSettlement ?? applySessionTurnSettlement;
|
|
7187
|
+
const enqueueSessionWorkflowWakeFn = overrides.enqueueSessionWorkflowWake ?? enqueueSessionWorkflowWake;
|
|
7188
|
+
const failSessionWorkBeforeAttemptClaimFn = overrides.failSessionWorkBeforeAttemptClaim ?? failSessionWorkBeforeAttemptClaim;
|
|
6883
7189
|
const requestSessionTurnRecoveryFn = overrides.requestSessionTurnRecovery ?? requestSessionTurnRecovery;
|
|
6884
7190
|
const recoverSessionDispatchFn = overrides.recoverSessionDispatch ?? recoverSessionDispatch;
|
|
6885
7191
|
const reconcileSessionAttemptQuiescenceFn = overrides.reconcileSessionAttemptQuiescence ?? reconcileSessionAttemptQuiescence;
|
|
@@ -6900,16 +7206,58 @@ function createSessionStateActivities(services, overrides = {}) {
|
|
|
6900
7206
|
async function failSessionAttempt(input) {
|
|
6901
7207
|
const { db, bus, settings, observability, wakeSessionWorkflow } = await services();
|
|
6902
7208
|
const session = await requireSessionFn(db, input.workspaceId, input.sessionId);
|
|
6903
|
-
if (session.status === "failed") {
|
|
6904
|
-
return;
|
|
7209
|
+
if (session.status === "failed" || session.status === "cancelled") {
|
|
7210
|
+
return { action: "terminal" };
|
|
6905
7211
|
}
|
|
7212
|
+
const workflowId = input.workflowId ?? session.temporalWorkflowId ?? `session-${input.sessionId}`;
|
|
6906
7213
|
const turn = await getSessionTurnForAttemptFn(
|
|
6907
7214
|
db,
|
|
6908
7215
|
input.workspaceId,
|
|
6909
7216
|
input.sessionId,
|
|
6910
7217
|
input.attemptId
|
|
6911
7218
|
);
|
|
6912
|
-
if (!turn)
|
|
7219
|
+
if (!turn) {
|
|
7220
|
+
const attempt = await getSessionAttemptActivityRefFn(db, {
|
|
7221
|
+
accountId: input.accountId,
|
|
7222
|
+
workspaceId: input.workspaceId,
|
|
7223
|
+
sessionId: input.sessionId,
|
|
7224
|
+
attemptId: input.attemptId,
|
|
7225
|
+
temporalWorkflowId: workflowId
|
|
7226
|
+
});
|
|
7227
|
+
if (attempt) return { action: "stale" };
|
|
7228
|
+
if (input.preClaimFailureDisposition === "permanent" && input.trigger) {
|
|
7229
|
+
const failed = await failSessionWorkBeforeAttemptClaimFn(db, input.workspaceId, {
|
|
7230
|
+
accountId: input.accountId,
|
|
7231
|
+
sessionId: input.sessionId,
|
|
7232
|
+
workflowId,
|
|
7233
|
+
trigger: input.trigger,
|
|
7234
|
+
error: input.error ?? "Agent turn admission failed before attempt claim."
|
|
7235
|
+
});
|
|
7236
|
+
if (failed.action === "terminal") return { action: "terminal" };
|
|
7237
|
+
if (failed.action === "stale") return { action: "stale" };
|
|
7238
|
+
await publishDurableSessionEventsFn(bus, input.workspaceId, input.sessionId, failed.events);
|
|
7239
|
+
if (failed.turnId) {
|
|
7240
|
+
await deliverFailedChildTurnToParentFn(
|
|
7241
|
+
{ db, bus, settings, observability, wakeSessionWorkflow },
|
|
7242
|
+
input.workspaceId,
|
|
7243
|
+
input.sessionId,
|
|
7244
|
+
failed.turnId
|
|
7245
|
+
);
|
|
7246
|
+
}
|
|
7247
|
+
return { action: "failed" };
|
|
7248
|
+
}
|
|
7249
|
+
const requestedRetryDelayMs = input.retryDelayMs;
|
|
7250
|
+
const retryDelayMs = typeof requestedRetryDelayMs === "number" && Number.isFinite(requestedRetryDelayMs) ? Math.max(1e3, Math.min(6e4, Math.trunc(requestedRetryDelayMs))) : 6e4;
|
|
7251
|
+
await enqueueSessionWorkflowWakeFn(db, {
|
|
7252
|
+
accountId: input.accountId,
|
|
7253
|
+
workspaceId: input.workspaceId,
|
|
7254
|
+
sessionId: input.sessionId,
|
|
7255
|
+
temporalWorkflowId: workflowId,
|
|
7256
|
+
reason: "turn_activity_failed_before_attempt_claim",
|
|
7257
|
+
notBefore: new Date(Date.now() + retryDelayMs)
|
|
7258
|
+
});
|
|
7259
|
+
return { action: "unclaimed" };
|
|
7260
|
+
}
|
|
6913
7261
|
const trigger = await getSessionEventFn(db, input.workspaceId, turn.triggerEventId);
|
|
6914
7262
|
const result = await applySessionTurnSettlementFn(db, input.workspaceId, {
|
|
6915
7263
|
sessionId: input.sessionId,
|
|
@@ -6932,7 +7280,7 @@ function createSessionStateActivities(services, overrides = {}) {
|
|
|
6932
7280
|
]
|
|
6933
7281
|
});
|
|
6934
7282
|
if (result.action === "stale") {
|
|
6935
|
-
return;
|
|
7283
|
+
return { action: "stale" };
|
|
6936
7284
|
}
|
|
6937
7285
|
await publishDurableSessionEventsFn(bus, input.workspaceId, input.sessionId, result.events);
|
|
6938
7286
|
await deliverFailedChildTurnToParentFn(
|
|
@@ -6941,6 +7289,7 @@ function createSessionStateActivities(services, overrides = {}) {
|
|
|
6941
7289
|
input.sessionId,
|
|
6942
7290
|
turn.id
|
|
6943
7291
|
);
|
|
7292
|
+
return { action: "failed" };
|
|
6944
7293
|
}
|
|
6945
7294
|
async function settleSessionInterruptions(input) {
|
|
6946
7295
|
const { db, bus, observability } = await services();
|
|
@@ -7218,4 +7567,4 @@ export {
|
|
|
7218
7567
|
createControlActivities,
|
|
7219
7568
|
createControlActivitiesFromServices
|
|
7220
7569
|
};
|
|
7221
|
-
//# sourceMappingURL=activities-control-
|
|
7570
|
+
//# sourceMappingURL=activities-control-BJSDRSIP.js.map
|