@opengeni/worker-bundle 0.20.1 → 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.
@@ -59,7 +59,7 @@ export declare function providerRetryAfterMs(error: unknown, nowMs?: number): nu
59
59
  * this notice prevents a graceful runtime drop from becoming a silent source-
60
60
  * of-truth substitution or a false claim that the disconnected system was read.
61
61
  */
62
- export declare function unavailableMcpTurnInstructions(input: {
62
+ export declare function unavailableMcpOperationalContext(input: {
63
63
  droppedIds: readonly string[];
64
64
  droppedCount: number;
65
65
  }): string | undefined;
@@ -0,0 +1,53 @@
1
+ import { type AttemptToolDefinition } from "@opengeni/codemode";
2
+ import type { McpPersonalConnectionDelegation } from "@opengeni/contracts";
3
+ import { GOOGLE_DRIVE_FILE_SCOPE, GOOGLE_DRIVE_FULL_SCOPE, type GoogleDriveOutputDestination, type GoogleDrivePublicationReceipt as GoogleDrivePublicationReceiptValue, type GoogleDrivePublicationToolInput as GoogleDrivePublicationToolInputValue } from "@opengeni/contracts/google-drive";
4
+ import { beginConnectorActionExecution, completeConnectorActionExecution, getConnectionMetadata, getWorkspaceGrant, prepareConnectorActionApproval, requireFile, type ConnectorActionAttemptIdentity, type ConnectorActionInvocation, type Database, type ResolveConnectionCredentialInput, type ResolveConnectionCredentialResult } from "@opengeni/db";
5
+ import { readAuthorizedEditableArtifactMaterialization } from "@opengeni/db/editable-artifact-durable-export";
6
+ import { type FetchLike } from "@opengeni/network";
7
+ import type { ObjectStorage } from "@opengeni/storage";
8
+ export type GoogleDrivePublicationTarget = Readonly<{
9
+ ownerSubjectId: string;
10
+ connectionId: string;
11
+ destination: GoogleDriveOutputDestination;
12
+ credentialScope: typeof GOOGLE_DRIVE_FILE_SCOPE | typeof GOOGLE_DRIVE_FULL_SCOPE;
13
+ }>;
14
+ export type GoogleDrivePublicationPorts = {
15
+ getConnection: typeof getConnectionMetadata;
16
+ getMembership: typeof getWorkspaceGrant;
17
+ readMaterialization: typeof readAuthorizedEditableArtifactMaterialization;
18
+ requireFile: typeof requireFile;
19
+ prepare: typeof prepareConnectorActionApproval;
20
+ begin: typeof beginConnectorActionExecution;
21
+ complete: typeof completeConnectorActionExecution;
22
+ fetch: FetchLike;
23
+ };
24
+ export declare function resolveGoogleDrivePublicationTarget(db: Database, workspaceId: string, delegations: readonly McpPersonalConnectionDelegation[], ports?: Pick<GoogleDrivePublicationPorts, "getConnection" | "getMembership">): Promise<GoogleDrivePublicationTarget | null>;
25
+ export declare function googleDrivePublicationConnectorCall(target: GoogleDrivePublicationTarget, rawRequest: unknown, approvalId: string): ConnectorActionInvocation;
26
+ export declare function createGoogleDrivePublicationAttemptTool(input: {
27
+ db: Database;
28
+ objectStorage: ObjectStorage;
29
+ identity: ConnectorActionAttemptIdentity;
30
+ subjectId: string;
31
+ target: GoogleDrivePublicationTarget;
32
+ resolveCredential: (input: ResolveConnectionCredentialInput) => Promise<ResolveConnectionCredentialResult>;
33
+ signal?: AbortSignal;
34
+ ports?: GoogleDrivePublicationPorts;
35
+ }): AttemptToolDefinition;
36
+ export declare function authorizeGoogleDrivePublicationAttempt(input: {
37
+ db: Database;
38
+ identity: ConnectorActionAttemptIdentity;
39
+ target: GoogleDrivePublicationTarget;
40
+ approvalId: string;
41
+ arguments: unknown;
42
+ ports?: Pick<GoogleDrivePublicationPorts, "prepare">;
43
+ }): Promise<void>;
44
+ export declare function executeGoogleDrivePublication(input: {
45
+ db: Database;
46
+ objectStorage: ObjectStorage;
47
+ identity: ConnectorActionAttemptIdentity;
48
+ subjectId: string;
49
+ target: GoogleDrivePublicationTarget;
50
+ request: GoogleDrivePublicationToolInputValue;
51
+ resolveCredential: (input: ResolveConnectionCredentialInput) => Promise<ResolveConnectionCredentialResult>;
52
+ signal?: AbortSignal;
53
+ }, ports?: Pick<GoogleDrivePublicationPorts, "getConnection" | "readMaterialization" | "requireFile" | "fetch">): Promise<GoogleDrivePublicationReceiptValue>;
@@ -19,7 +19,9 @@ export type SandboxImageReferenceReader = (path: string, maxBytes: number) => Pr
19
19
  export declare function resolveImageGenerationReferences(input: {
20
20
  db: Database;
21
21
  objectStorage: ObjectStorage;
22
+ accountId: string;
22
23
  workspaceId: string;
24
+ subjectId: string | null;
23
25
  references: readonly ImageGenerationReference[];
24
26
  readSandboxFile?: SandboxImageReferenceReader;
25
27
  }): Promise<ResolvedImageGenerationReference[]>;
@@ -10,6 +10,26 @@ export type KnowledgeSourceSyncDriverInventory<Entry, StopReason extends string>
10
10
  elapsedMs: number;
11
11
  hardLimitReached: boolean;
12
12
  };
13
+ export type KnowledgeSourceSyncAclPrincipal = {
14
+ type: "user" | "group" | "domain" | "anyone";
15
+ permissionId?: string | null;
16
+ emailAddress?: string | null;
17
+ domain?: string | null;
18
+ role: "owner" | "organizer" | "fileOrganizer" | "writer" | "commenter" | "reader";
19
+ inherited?: boolean;
20
+ allowFileDiscovery?: boolean | null;
21
+ expirationTime?: string | null;
22
+ };
23
+ export type KnowledgeSourceSyncAclEvidence = {
24
+ eligibility: "eligible" | "denied";
25
+ providerRevision: string | null;
26
+ driveId: string | null;
27
+ aclRevision: string;
28
+ observedAt: string;
29
+ expiresAt: string;
30
+ providerRequests: number;
31
+ principals: KnowledgeSourceSyncAclPrincipal[];
32
+ };
13
33
  /** Provider port for deterministic knowledge ingestion. Implementations own
14
34
  * provider JSON and byte transfer; the shared activity owns authority,
15
35
  * persistence, indexing obligations, telemetry, and checkpoint settlement. */
@@ -20,4 +40,5 @@ export type KnowledgeSourceSyncDriver<Entry, StopReason extends string> = {
20
40
  inventory: (executionCheckpoint: Record<string, unknown> | null, providerCursor: Record<string, unknown> | null) => Promise<KnowledgeSourceSyncDriverInventory<Entry, StopReason>>;
21
41
  fetchContent: (entry: Entry, maxBytes: number) => Promise<Uint8Array>;
22
42
  citationLocator: (entry: Entry) => Record<string, unknown>;
43
+ readAcl?: (entry: Entry, maxProviderRequests: number) => Promise<KnowledgeSourceSyncAclEvidence>;
23
44
  };
@@ -2,8 +2,23 @@ import { GoogleDriveConnectionMetadata, type GoogleDriveSelectedSource } from "@
2
2
  import { type GoogleDriveInventoryEntry, type GoogleDriveInventoryPage, type GoogleDriveInventoryProviderItem, type GoogleDriveInventoryStopReason } from "@opengeni/documents/google-drive";
3
3
  import { deauthorizeKnowledgeSourceRetrieval, settleKnowledgeSourceSyncLease, type Database, type KnowledgeSourceSyncObjectObservationResult, type KnowledgeSourceSyncObservationFloor } from "@opengeni/db";
4
4
  import type { ControlActivityServices, RunKnowledgeSourceSyncBatchInput, RunKnowledgeSourceSyncBatchResult } from "./types.js";
5
- import type { KnowledgeSourceSyncDriver } from "./knowledge-source-sync-driver.js";
5
+ import type { KnowledgeSourceSyncAclEvidence, KnowledgeSourceSyncDriver } from "./knowledge-source-sync-driver.js";
6
6
  import { type GoogleDriveChangesPage } from "./google-drive-changes.js";
7
+ type GoogleDrivePermission = {
8
+ id: string;
9
+ type: "user" | "group" | "domain" | "anyone";
10
+ role: "owner" | "organizer" | "fileOrganizer" | "writer" | "commenter" | "reader";
11
+ emailAddress: string | null;
12
+ domain: string | null;
13
+ allowFileDiscovery: boolean | null;
14
+ expirationTime: string | null;
15
+ inherited: boolean;
16
+ };
17
+ type GoogleDrivePermissionsPage = {
18
+ permissions: GoogleDrivePermission[];
19
+ nextPageToken: string | null;
20
+ denied: boolean;
21
+ };
7
22
  export declare function knowledgeSyncObservationPolicy(kind: "google_drive" | "atlassian"): {
8
23
  revisionOrdering: "canonical_decimal";
9
24
  filterWithDriveDurability: boolean;
@@ -36,6 +51,11 @@ export type GoogleDriveSyncProviderPort = {
36
51
  pageToken: string | null;
37
52
  pageSize: number;
38
53
  }) => Promise<GoogleDriveInventoryPage>;
54
+ listPermissions?: (input: {
55
+ fileId: string;
56
+ pageToken: string | null;
57
+ pageSize: number;
58
+ }) => Promise<GoogleDrivePermissionsPage>;
39
59
  };
40
60
  export declare function googleDriveSyncDriver(input: {
41
61
  actionProviderCoordinationKey: string;
@@ -64,6 +84,13 @@ export declare function shouldProcessGoogleDriveDurableObservation(input: {
64
84
  aclGeneration: number;
65
85
  }): boolean;
66
86
  export declare function mergeGoogleDriveDurableObservationFloors(checkpoint: Record<string, unknown> | null, observations: KnowledgeSourceSyncObservationFloor[], maxItems: number): Record<string, unknown> | null;
87
+ export declare function collectGoogleDriveAclEvidence(input: {
88
+ entry: Pick<GoogleDriveInventoryEntry, "externalObjectId" | "externalVersionId" | "driveId">;
89
+ maxProviderRequests: number;
90
+ listPermissions: NonNullable<GoogleDriveSyncProviderPort["listPermissions"]>;
91
+ getFile?: GoogleDriveSyncProviderPort["getFile"];
92
+ now?: () => number;
93
+ }): Promise<KnowledgeSourceSyncAclEvidence>;
67
94
  export declare function googleDriveSyncProviderAccessAllowed(input: {
68
95
  connectionVersion: number;
69
96
  resolvedConnectionVersion: number | undefined;
@@ -73,3 +100,4 @@ export declare function googleDriveSyncProviderAccessAllowed(input: {
73
100
  }): boolean;
74
101
  export declare function confluenceCursor(value: unknown): string | null;
75
102
  export declare function adfToMarkdown(value: unknown): string;
103
+ export {};
@@ -23,9 +23,15 @@ export type PreparedTurnInput = {
23
23
  };
24
24
  export type TurnInputOptions = {
25
25
  turnId: string;
26
+ /** Frozen initiating-human authority for every model-visible file read. */
27
+ fileAuthority: {
28
+ accountId: string;
29
+ subjectId: string | null;
30
+ };
26
31
  recovering?: boolean;
27
32
  unavailableSandboxFilesNote?: string;
28
33
  runCredentialsNote?: string;
34
+ mcpAvailabilityNote?: string;
29
35
  providerApi: HistoryProviderApi;
30
36
  projectCanonicalHistory?: ModelHistoryAttachmentProjector;
31
37
  materializeModelHistory?: ModelHistoryAttachmentProjector;
@@ -60,8 +66,12 @@ export declare function modelAttachmentContentForFiles(files: FileAsset[], readF
60
66
  * and file bytes are memoized, so compaction/retry can reuse the same work and
61
67
  * the SDK's repeated tool loop never touches storage or rescans old history.
62
68
  */
63
- export declare function createModelHistoryAttachmentProjector(db: Database, workspaceId: string, policy: ModelAttachmentInputPolicy, readFileBytes?: (file: FileAsset) => Promise<Uint8Array>): ModelHistoryAttachmentProjector;
69
+ export declare function createModelHistoryAttachmentProjector(db: Database, authority: {
70
+ accountId: string;
71
+ workspaceId: string;
72
+ subjectId: string | null;
73
+ }, policy: ModelAttachmentInputPolicy, readFileBytes?: (file: FileAsset) => Promise<Uint8Array>): ModelHistoryAttachmentProjector;
64
74
  /** Add current trigger refs only when older/local history predates durable stamping. */
65
75
  export declare function withCurrentUserAttachmentRefs(historyItems: Array<Record<string, unknown>>, refs: FileResourceRef[]): Array<Record<string, unknown>>;
66
76
  export declare function turnInput(db: Database, runtime: OpenGeniRuntime, agent: any, trigger: Awaited<ReturnType<typeof getSessionEvent>>, options: TurnInputOptions): Promise<PreparedTurnInput>;
67
- export declare function userMessageTextWithAttachments(db: Database, workspaceId: string, text: string, resources: ResourceRef[]): Promise<string>;
77
+ export declare function userMessageTextWithAttachments(db: Database, accountId: string, workspaceId: string, subjectId: string | null, text: string, resources: ResourceRef[]): Promise<string>;
@@ -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 [{ getDocument, indexDocumentNow }, documentServices] = await Promise.all([
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 getDocument(lockedDb, input.workspaceId, input.documentId, {
177
- viewerSubjectId: storedAuthority.authoritySubjectId
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: true,
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: "pending",
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: "pending",
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: "pending",
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: 1,
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);
@@ -7265,4 +7567,4 @@ export {
7265
7567
  createControlActivities,
7266
7568
  createControlActivitiesFromServices
7267
7569
  };
7268
- //# sourceMappingURL=activities-control-SMKF2OBE.js.map
7570
+ //# sourceMappingURL=activities-control-BJSDRSIP.js.map