@wirecat/drive-cli 0.44.0 → 0.45.1

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.
Files changed (168) hide show
  1. package/dist/bin/drive.js +35 -40
  2. package/dist/bundle/all-profiles-O7CNQ7FO.js +26 -0
  3. package/dist/bundle/anthropic-6T67J2CE.js +71 -0
  4. package/dist/bundle/app-server-BVBZT3UY.js +237 -0
  5. package/dist/bundle/bun-O6RL6LRQ.js +169 -0
  6. package/dist/bundle/bun-sqlite-54W7JUY3.js +70 -0
  7. package/dist/bundle/chunk-2DLAJGRN.js +62 -0
  8. package/dist/bundle/chunk-37MAA6F2.js +5624 -0
  9. package/dist/bundle/chunk-3HRDEJJW.js +161 -0
  10. package/dist/bundle/chunk-3Z7WSD2A.js +433 -0
  11. package/dist/bundle/chunk-44FV5JAS.js +1855 -0
  12. package/dist/bundle/chunk-4DW6QGEV.js +164 -0
  13. package/dist/bundle/chunk-4NGLRHWO.js +24 -0
  14. package/dist/bundle/chunk-5DPV7X27.js +663 -0
  15. package/dist/bundle/chunk-5FONRUG6.js +24805 -0
  16. package/dist/bundle/chunk-5MGIL5LW.js +846 -0
  17. package/dist/bundle/chunk-5TC3NCAF.js +42 -0
  18. package/dist/bundle/chunk-6Y2BYFXQ.js +65 -0
  19. package/dist/bundle/chunk-A3FU4RR6.js +150 -0
  20. package/dist/bundle/chunk-ADLS6FVG.js +24600 -0
  21. package/dist/bundle/chunk-AIXLOMH4.js +63 -0
  22. package/dist/bundle/chunk-AOOD3RMK.js +384 -0
  23. package/dist/bundle/chunk-AUS6TKP5.js +1975 -0
  24. package/dist/bundle/chunk-B2J6FJNL.js +19 -0
  25. package/dist/bundle/chunk-BEXHAGXH.js +3542 -0
  26. package/dist/bundle/chunk-BHE7ZY2N.js +2352 -0
  27. package/dist/bundle/chunk-BJ3JRO34.js +2356 -0
  28. package/dist/bundle/chunk-BQUPOB5H.js +2315 -0
  29. package/dist/bundle/chunk-CFZWPIVC.js +1092 -0
  30. package/dist/bundle/chunk-CKR3DVUK.js +754 -0
  31. package/dist/bundle/chunk-CVIKKIGE.js +76 -0
  32. package/dist/bundle/chunk-D67JGWSC.js +190 -0
  33. package/dist/bundle/chunk-DDYR6DYL.js +78 -0
  34. package/dist/bundle/chunk-DFDN6AUB.js +21 -0
  35. package/dist/bundle/chunk-DL7D6Y3B.js +18102 -0
  36. package/dist/bundle/chunk-DORXXBFC.js +484 -0
  37. package/dist/bundle/chunk-DXKVEOSS.js +53 -0
  38. package/dist/bundle/chunk-DXQEJWI3.js +522 -0
  39. package/dist/bundle/chunk-FEULDMWM.js +35598 -0
  40. package/dist/bundle/chunk-G3FAOS52.js +630 -0
  41. package/dist/bundle/chunk-GHOWRW7E.js +237 -0
  42. package/dist/bundle/chunk-GNFHZZ55.js +264 -0
  43. package/dist/bundle/chunk-GNI7INK6.js +18 -0
  44. package/dist/bundle/chunk-GOR3Z2FR.js +17 -0
  45. package/dist/bundle/chunk-GQW4GRYR.js +886 -0
  46. package/dist/bundle/chunk-GWPKIRNQ.js +220 -0
  47. package/dist/bundle/chunk-GYCUY4CL.js +9 -0
  48. package/dist/bundle/chunk-HEPIOCHN.js +8181 -0
  49. package/dist/bundle/chunk-HTQTIKWP.js +928 -0
  50. package/dist/bundle/chunk-IAW5A7OR.js +1913 -0
  51. package/dist/bundle/chunk-IGMRWQP3.js +1071 -0
  52. package/dist/bundle/chunk-IKNU5A5Y.js +82 -0
  53. package/dist/bundle/chunk-JVTVAZ5X.js +1054 -0
  54. package/dist/bundle/chunk-K74PQVQZ.js +168 -0
  55. package/dist/bundle/chunk-K7FRUB33.js +795 -0
  56. package/dist/bundle/chunk-KADPV4YA.js +45 -0
  57. package/dist/bundle/chunk-KJMBV574.js +16225 -0
  58. package/dist/bundle/chunk-LHIL46I3.js +31 -0
  59. package/dist/bundle/chunk-LJARCTGL.js +60 -0
  60. package/dist/bundle/chunk-LOTQ2HMT.js +3954 -0
  61. package/dist/bundle/chunk-MAXN7COO.js +99 -0
  62. package/dist/bundle/chunk-MFS52LTZ.js +570 -0
  63. package/dist/bundle/chunk-MFSIOSUM.js +1714 -0
  64. package/dist/bundle/chunk-NB2N6L3R.js +138 -0
  65. package/dist/bundle/chunk-NDNTLUPS.js +58 -0
  66. package/dist/bundle/chunk-NLEB26GA.js +288 -0
  67. package/dist/bundle/chunk-NP3XLLN3.js +73 -0
  68. package/dist/bundle/chunk-NW7IMGRR.js +6848 -0
  69. package/dist/bundle/chunk-O5EHUB2V.js +2 -0
  70. package/dist/bundle/chunk-OWXTPXIQ.js +215 -0
  71. package/dist/bundle/chunk-PDBBBUY7.js +166 -0
  72. package/dist/bundle/chunk-PH74B2VZ.js +122 -0
  73. package/dist/bundle/chunk-PJ7IQVOM.js +421 -0
  74. package/dist/bundle/chunk-Q2Z3VCM4.js +2 -0
  75. package/dist/bundle/chunk-QTJUH3LS.js +15572 -0
  76. package/dist/bundle/chunk-QW36EOAM.js +106 -0
  77. package/dist/bundle/chunk-QWSRPXCJ.js +281 -0
  78. package/dist/bundle/chunk-R2A3K7ZF.js +193 -0
  79. package/dist/bundle/chunk-R2QRP7EJ.js +835 -0
  80. package/dist/bundle/chunk-RCS2SCX5.js +375 -0
  81. package/dist/bundle/chunk-RJ633GFA.js +25 -0
  82. package/dist/bundle/chunk-SBZB7HMU.js +1055 -0
  83. package/dist/bundle/chunk-SMHQA5J6.js +459 -0
  84. package/dist/bundle/chunk-SWMMR3FR.js +48 -0
  85. package/dist/bundle/chunk-TRMIV3OA.js +18 -0
  86. package/dist/bundle/chunk-VAGF723Z.js +74 -0
  87. package/dist/bundle/chunk-VCYFEWPD.js +18078 -0
  88. package/dist/bundle/chunk-VHQNVG3J.js +263 -0
  89. package/dist/bundle/chunk-VHT2WI4I.js +2941 -0
  90. package/dist/bundle/chunk-VYBOYBLX.js +100 -0
  91. package/dist/bundle/chunk-WUFCYDKB.js +71 -0
  92. package/dist/bundle/chunk-XAZQTJXR.js +3402 -0
  93. package/dist/bundle/chunk-XEBFFKXO.js +111 -0
  94. package/dist/bundle/chunk-XF5MFUEB.js +498 -0
  95. package/dist/bundle/chunk-XFLCVHSQ.js +50 -0
  96. package/dist/bundle/chunk-Y5E2WNWB.js +35 -0
  97. package/dist/bundle/chunk-ZBM4GEV2.js +120 -0
  98. package/dist/bundle/chunk-ZVVMGPBJ.js +50 -0
  99. package/dist/bundle/command-contract-MXCBV3GJ.js +38 -0
  100. package/dist/bundle/dist-MWTMOYWT.js +7577 -0
  101. package/dist/bundle/dist-PY3MVR3G.js +21 -0
  102. package/dist/bundle/drive.js +50 -0
  103. package/dist/bundle/echarts-LD3AI55P.js +42501 -0
  104. package/dist/bundle/embed-FJKIIM43.js +37 -0
  105. package/dist/bundle/embedder-NNQ5ZC25.js +110 -0
  106. package/dist/bundle/entry-ZYSNPDSD.js +15 -0
  107. package/dist/bundle/failure-MJJXFR63.js +37 -0
  108. package/dist/bundle/first-run-KA2UPZAU.js +24 -0
  109. package/dist/bundle/first-screen-VQ3RXDMF.js +36 -0
  110. package/dist/bundle/google-ZYDFTHLN.js +32 -0
  111. package/dist/bundle/google-api-2GT5PAW2.js +82 -0
  112. package/dist/bundle/identity-JQFQXQIR.js +10 -0
  113. package/dist/bundle/instructions-RZMSW3OC.js +11 -0
  114. package/dist/bundle/login-JU6NKW5P.js +158 -0
  115. package/dist/bundle/mcp-2PZDI7WE.js +501 -0
  116. package/dist/bundle/mcp-JOQMFGBC.js +95 -0
  117. package/dist/bundle/mcp-OQBZXELQ.js +165 -0
  118. package/dist/bundle/mdast-util-from-markdown-FXEPSNER.js +1958 -0
  119. package/dist/bundle/mdast-util-gfm-SZM5GBDF.js +2103 -0
  120. package/dist/bundle/micromark-extension-gfm-GRL24TU6.js +1838 -0
  121. package/dist/bundle/node-P4E63KXA.js +2340 -0
  122. package/dist/bundle/node-TLZSIHIJ.js +21 -0
  123. package/dist/bundle/node-ZRLYQL7J.js +176 -0
  124. package/dist/bundle/node-sqlite-TXPSRROT.js +46 -0
  125. package/dist/bundle/oauth-NAIBKERJ.js +18 -0
  126. package/dist/bundle/open-3P5EPXPV.js +20 -0
  127. package/dist/bundle/process-LL77573L.js +91 -0
  128. package/dist/bundle/program-CZ55L6EW.js +24078 -0
  129. package/dist/bundle/prompt-3TX2SWOY.js +13 -0
  130. package/dist/bundle/reasons-GF2TYGX6.js +11 -0
  131. package/dist/bundle/recognize-IFXOJHEA.js +191 -0
  132. package/dist/bundle/remote-663M42Y5.js +28 -0
  133. package/dist/bundle/rerank-OT2F2DBV.js +51 -0
  134. package/dist/bundle/serve-PDNNI6O6.js +20 -0
  135. package/dist/bundle/server-BFOEPMR7.js +56 -0
  136. package/dist/bundle/server-K566PJ7H.js +69 -0
  137. package/dist/bundle/services-5MCTECBU.js +333 -0
  138. package/dist/bundle/sqlite-runtime-BF3KDM7W.js +17 -0
  139. package/dist/bundle/state-SZX65E74.js +34 -0
  140. package/dist/bundle/store-TCWNLA3V.js +125 -0
  141. package/dist/bundle/store-UKPGGAPW.js +142 -0
  142. package/dist/bundle/store-maintenance-command-QHLUVBTJ.js +57 -0
  143. package/dist/bundle/terminal-TFCTWLOS.js +11 -0
  144. package/dist/bundle/tokens-DFCFRF7I.js +103 -0
  145. package/dist/commands/mcp.d.ts.map +1 -1
  146. package/dist/commands/mcp.js +82 -36
  147. package/dist/commands/mcp.js.map +1 -1
  148. package/dist/contract-overrides.d.ts.map +1 -1
  149. package/dist/contract-overrides.js +59 -53
  150. package/dist/contract-overrides.js.map +1 -1
  151. package/dist/mcp.d.ts +6 -5
  152. package/dist/mcp.d.ts.map +1 -1
  153. package/dist/mcp.js +13 -10
  154. package/dist/mcp.js.map +1 -1
  155. package/dist/program.js +4 -4
  156. package/dist/program.js.map +1 -1
  157. package/dist/registry.d.ts +2 -2
  158. package/dist/registry.d.ts.map +1 -1
  159. package/dist/registry.js +3 -3
  160. package/dist/registry.js.map +1 -1
  161. package/dist/state.d.ts +13 -2
  162. package/dist/state.d.ts.map +1 -1
  163. package/dist/state.js +12 -2
  164. package/dist/state.js.map +1 -1
  165. package/dist/version.d.ts +1 -1
  166. package/dist/version.js +1 -1
  167. package/package.json +7 -5
  168. package/skills/drive-cli/SKILL.md +1 -0
@@ -0,0 +1,263 @@
1
+ import { createRequire as __bundleRequire } from "node:module";
2
+ const require = __bundleRequire(import.meta.url);
3
+ import {
4
+ DOC,
5
+ MAX_ENTRIES,
6
+ READABLE,
7
+ SHEET,
8
+ XLSX,
9
+ supported,
10
+ tooManyEntries
11
+ } from "./chunk-VAGF723Z.js";
12
+ import {
13
+ googleError
14
+ } from "./chunk-2DLAJGRN.js";
15
+ import {
16
+ extractText
17
+ } from "./chunk-VCYFEWPD.js";
18
+ import {
19
+ MAX_TEXT_CHARS
20
+ } from "./chunk-5TC3NCAF.js";
21
+ import {
22
+ CliError
23
+ } from "./chunk-BJ3JRO34.js";
24
+ import {
25
+ importFrom
26
+ } from "./chunk-Y5E2WNWB.js";
27
+ import {
28
+ __name
29
+ } from "./chunk-ZVVMGPBJ.js";
30
+
31
+ // dist/google.js
32
+ import { docs } from "@googleapis/docs";
33
+ import { drive } from "@googleapis/drive";
34
+
35
+ // dist/documents.js
36
+ var elementsText = /* @__PURE__ */ __name((elements) => elements.map((element) => {
37
+ if (element.paragraph)
38
+ return (element.paragraph.elements ?? []).map((part) => part.textRun?.content ?? part.person?.personProperties?.name ?? part.richLink?.richLinkProperties?.title ?? "").join("");
39
+ if (element.table)
40
+ return `${(element.table.tableRows ?? []).map((row) => (row.tableCells ?? []).map((cell) => elementsText(cell.content ?? []).trim()).join(" ")).join("\n")}
41
+ `;
42
+ if (element.tableOfContents)
43
+ return elementsText(element.tableOfContents.content ?? []);
44
+ return "";
45
+ }).join(""), "elementsText");
46
+ var documentTabs = /* @__PURE__ */ __name((document) => {
47
+ const walk = /* @__PURE__ */ __name((tabs) => tabs.flatMap((tab) => {
48
+ const content = tab.documentTab;
49
+ const footnotes = Object.values(content?.footnotes ?? {}).map((footnote) => elementsText(footnote.content ?? [])).join("\n");
50
+ return [
51
+ {
52
+ id: tab.tabProperties?.tabId ?? "",
53
+ title: tab.tabProperties?.title ?? "",
54
+ text: [elementsText(content?.body?.content ?? []), footnotes].filter(Boolean).join("\n")
55
+ },
56
+ ...walk(tab.childTabs ?? [])
57
+ ];
58
+ }), "walk");
59
+ return walk(document.tabs ?? []);
60
+ }, "documentTabs");
61
+
62
+ // dist/google.js
63
+ var FIELDS = "*";
64
+ var userOf = /* @__PURE__ */ __name((user) => ({
65
+ ...user.permissionId ? { id: user.permissionId } : {},
66
+ ...user.emailAddress ? { email: user.emailAddress } : {},
67
+ ...user.displayName ? { name: user.displayName } : {}
68
+ }), "userOf");
69
+ var MAX_PAGES = 1e3;
70
+ var MAX_BYTES = 50 * 1024 * 1024;
71
+ var metadataOf = /* @__PURE__ */ __name((file) => {
72
+ if (!file.id || !file.mimeType || file.name === void 0 || file.name === null)
73
+ throw new CliError("invalid_response", "Google returned incomplete file metadata");
74
+ return {
75
+ providerMetadata: file,
76
+ id: file.id,
77
+ name: file.name,
78
+ mime: file.mimeType,
79
+ parents: file.parents ?? [],
80
+ url: file.webViewLink ?? `https://drive.google.com/file/d/${file.id}/view`,
81
+ trashed: file.trashed ?? false,
82
+ canDownload: file.capabilities?.canDownload !== false,
83
+ ...file.size ? { size: Number(file.size) } : {},
84
+ ...file.version ? { version: file.version } : {},
85
+ ...file.modifiedTime ? { modifiedAt: file.modifiedTime } : {},
86
+ ...file.createdTime ? { createdAt: file.createdTime } : {},
87
+ ...file.description ? { description: file.description } : {},
88
+ ...file.driveId ? { driveId: file.driveId } : {},
89
+ ...file.owners ? { owners: file.owners.map(userOf) } : {},
90
+ ...file.lastModifyingUser ? { lastModifiedBy: userOf(file.lastModifyingUser) } : {}
91
+ };
92
+ }, "metadataOf");
93
+ var ENGINE_LABEL = {
94
+ unpdf: "PDF",
95
+ mammoth: "Word",
96
+ "word-extractor": "Word (.doc)",
97
+ "@napi-rs/canvas": "scanned PDF",
98
+ "defuddle/node": "web page",
99
+ linkedom: "HTML"
100
+ };
101
+ var sheetTabs = /* @__PURE__ */ __name((text) => text.split(/^# (.*)$/m).slice(1).flatMap((part, index, parts) => index % 2 ? [] : [{ id: part, title: part, text: (parts[index + 1] ?? "").trim() }]), "sheetTabs");
102
+ var readFile = /* @__PURE__ */ __name(async (bytes, file, mime) => {
103
+ const read = await extractText(bytes, { kind: "document", name: file.name, mime, path: file.name }, (name) => importFrom(new URL("../google.js", import.meta.url).href, name));
104
+ if (read.status === "extracted")
105
+ return read.text;
106
+ const reason = read.status === "needs-agent" ? "file has no text layer (a scan or images only); OCR is not supported" : read.status === "engine-missing" ? `${ENGINE_LABEL[read.engine]} files need the package ${read.engine} installed next to drive; then run drive <profile> sync --rescan` : read.status === "unreadable" ? "file could not be read as text; it may be damaged or protected" : read.status === "unsupported" ? "file contents do not match its type" : `file is too large for the document readers (over 50 MB, or over ${MAX_TEXT_CHARS} characters of text)`;
107
+ throw new CliError("validation_error", reason);
108
+ }, "readFile");
109
+ var googleSource = /* @__PURE__ */ __name((auth) => {
110
+ const api = drive({ version: "v3", auth });
111
+ const documents = docs({ version: "v1", auth });
112
+ const safe = /* @__PURE__ */ __name(async (fn) => {
113
+ try {
114
+ return await fn();
115
+ } catch (error) {
116
+ throw googleError(error);
117
+ }
118
+ }, "safe");
119
+ const metadata = /* @__PURE__ */ __name((id) => safe(async () => metadataOf((await api.files.get({ fileId: id, fields: FIELDS, supportsAllDrives: true }, { timeout: 3e4 })).data)), "metadata");
120
+ return {
121
+ metadata,
122
+ identity: /* @__PURE__ */ __name(() => safe(async () => {
123
+ const id = (await api.about.get({ fields: "user(permissionId)" }, { timeout: 3e4 })).data.user?.permissionId;
124
+ if (!id)
125
+ throw new CliError("invalid_response", "Google did not identify the signed-in account");
126
+ return id;
127
+ }), "identity"),
128
+ children: /* @__PURE__ */ __name((id) => safe(async () => {
129
+ const files = [];
130
+ const seen = /* @__PURE__ */ new Set();
131
+ let pageToken;
132
+ for (let page = 0; page < MAX_PAGES; page++) {
133
+ const { data } = await api.files.list({
134
+ q: `'${id}' in parents and trashed = false`,
135
+ fields: `nextPageToken,incompleteSearch,files(${FIELDS})`,
136
+ pageSize: 1e3,
137
+ supportsAllDrives: true,
138
+ includeItemsFromAllDrives: true,
139
+ ...pageToken ? { pageToken } : {}
140
+ }, { timeout: 3e4 });
141
+ if (data.incompleteSearch)
142
+ throw new CliError("provider_error", "Google folder listing was incomplete; sync state was preserved");
143
+ for (const file of data.files ?? [])
144
+ files.push(metadataOf(file));
145
+ if (files.length > MAX_ENTRIES)
146
+ throw tooManyEntries();
147
+ if (!data.nextPageToken)
148
+ return files;
149
+ if (seen.has(data.nextPageToken))
150
+ throw new CliError("invalid_response", "Google repeated a folder page token");
151
+ seen.add(data.nextPageToken);
152
+ pageToken = data.nextPageToken;
153
+ }
154
+ throw new CliError("provider_error", "folder pagination exceeded its bound; sync state was preserved");
155
+ }), "children"),
156
+ startToken: /* @__PURE__ */ __name(() => safe(async () => {
157
+ const token = (await api.changes.getStartPageToken({ supportsAllDrives: true }, { timeout: 3e4 })).data.startPageToken;
158
+ if (!token)
159
+ throw new CliError("invalid_response", "Google returned no change-feed token");
160
+ return token;
161
+ }), "startToken"),
162
+ changes: /* @__PURE__ */ __name((token) => safe(async () => {
163
+ const items = [];
164
+ const seen = /* @__PURE__ */ new Set();
165
+ let pageToken = token;
166
+ for (let page = 0; page < MAX_PAGES; page++) {
167
+ if (seen.has(pageToken))
168
+ throw new CliError("invalid_response", "Google repeated a change-feed page token");
169
+ seen.add(pageToken);
170
+ const { data } = await api.changes.list({
171
+ pageToken,
172
+ pageSize: 1e3,
173
+ includeRemoved: true,
174
+ includeCorpusRemovals: true,
175
+ supportsAllDrives: true,
176
+ includeItemsFromAllDrives: true,
177
+ fields: `nextPageToken,newStartPageToken,changes(fileId,removed,file(${FIELDS}))`
178
+ }, { timeout: 3e4 });
179
+ for (const change of data.changes ?? []) {
180
+ if (!change.fileId)
181
+ continue;
182
+ items.push({
183
+ id: change.fileId,
184
+ removed: change.removed ?? false,
185
+ ...change.file ? { file: metadataOf(change.file) } : {}
186
+ });
187
+ }
188
+ if (items.length > MAX_ENTRIES)
189
+ throw new CliError("provider_error", `Google lists more than ${MAX_ENTRIES} changes since the last sync, the most one sync reads; \`sync --rescan\` reads the chosen folders instead, which works while they hold at most ${MAX_ENTRIES} entries`, { reason: "listing.too-large" });
190
+ if (data.nextPageToken) {
191
+ pageToken = data.nextPageToken;
192
+ continue;
193
+ }
194
+ if (!data.newStartPageToken)
195
+ throw new CliError("invalid_response", "Google returned no final change-feed token");
196
+ return { items, cursor: data.newStartPageToken };
197
+ }
198
+ throw new CliError("provider_error", "change-feed pagination exceeded its bound; sync state was preserved");
199
+ }), "changes"),
200
+ bytes: /* @__PURE__ */ __name((id) => safe(async () => {
201
+ const data = (await api.files.get({ fileId: id, alt: "media", supportsAllDrives: true }, { responseType: "arraybuffer", timeout: 12e4 })).data;
202
+ return new Uint8Array(data);
203
+ }), "bytes"),
204
+ content: /* @__PURE__ */ __name((id, maxChars = MAX_TEXT_CHARS) => safe(async () => {
205
+ const before = await metadata(id);
206
+ if (!before.canDownload)
207
+ throw new CliError("permission_error", "downloads are restricted for this source");
208
+ if (!supported(before))
209
+ throw new CliError("validation_error", "this source type is not supported for text ingestion");
210
+ if ((before.size ?? 0) > MAX_BYTES)
211
+ throw new CliError("validation_error", "file exceeds the ingestion bound; it was not downloaded");
212
+ let markdown;
213
+ let text;
214
+ let tabs = [];
215
+ let raw;
216
+ if (before.mime === DOC) {
217
+ raw = (await documents.documents.get({ documentId: id, includeTabsContent: true, suggestionsViewMode: "PREVIEW_WITHOUT_SUGGESTIONS" }, { timeout: 3e4 })).data;
218
+ tabs = documentTabs(raw);
219
+ if (tabs.length === 0)
220
+ throw new CliError("invalid_response", "Google returned no document tabs");
221
+ const exported = (await api.files.export({ fileId: id, mimeType: "text/markdown" }, { responseType: "text", timeout: 3e4 })).data;
222
+ if (typeof exported !== "string")
223
+ throw new CliError("invalid_response", "Google returned a non-text Markdown export");
224
+ markdown = exported;
225
+ text = tabs.map((tab) => `${tab.title ? `# ${tab.title}
226
+
227
+ ` : ""}${tab.text}`).join("\n\n");
228
+ } else if (before.mime === SHEET || READABLE.has(before.mime)) {
229
+ const mime = before.mime === SHEET ? XLSX : before.mime;
230
+ const bytes = (before.mime === SHEET ? await api.files.export({ fileId: id, mimeType: XLSX }, { responseType: "arraybuffer", timeout: 12e4 }) : await api.files.get({ fileId: id, alt: "media", supportsAllDrives: true }, { responseType: "arraybuffer", timeout: 12e4 })).data;
231
+ text = await readFile(new Uint8Array(bytes), before, mime);
232
+ if (mime === XLSX) {
233
+ tabs = sheetTabs(text);
234
+ }
235
+ markdown = text;
236
+ } else {
237
+ markdown = (await api.files.get({ fileId: id, alt: "media", supportsAllDrives: true }, { responseType: "text", timeout: 3e4 })).data;
238
+ text = markdown;
239
+ }
240
+ if (Buffer.byteLength(markdown) > MAX_BYTES)
241
+ throw new CliError("validation_error", "document text is over 50 MB; it was not imported");
242
+ if (text.length >= maxChars)
243
+ throw new CliError("validation_error", maxChars >= MAX_TEXT_CHARS ? `text reaches ${MAX_TEXT_CHARS} characters, the most the document readers return; it was not imported` : `text reaches the ${maxChars}-character limit; raise it with drive <profile> config set max_text_chars <n>`, { reason: "document.too-long", text_limit: maxChars });
244
+ const after = await metadata(id);
245
+ if (after.version !== before.version || after.modifiedAt !== before.modifiedAt)
246
+ throw new CliError("provider_error", "document changed during export; retry sync", {
247
+ reason: "source.changed",
248
+ retryable: true
249
+ });
250
+ const result = { metadata: after, markdown, text: text.replace(/\r\n?/g, "\n"), tabs, ...raw ? { raw } : {} };
251
+ if (Buffer.byteLength(JSON.stringify(result)) > MAX_BYTES)
252
+ throw new CliError("validation_error", "document snapshot exceeds the ingestion bound");
253
+ return result;
254
+ }), "content")
255
+ };
256
+ }, "googleSource");
257
+
258
+ export {
259
+ userOf,
260
+ metadataOf,
261
+ readFile,
262
+ googleSource
263
+ };