tide-commander 1.211.0 → 1.213.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.
Files changed (115) hide show
  1. package/CHANGELOG.md +19 -0
  2. package/dist/assets/{AudioPlayer-BkW6rbHa.js → AudioPlayer-0XoYDzY7.js} +1 -1
  3. package/dist/assets/{BossLogsModal-CWJfLRLA.js → BossLogsModal-Bod63t3S.js} +1 -1
  4. package/dist/assets/{BossSpawnModal-DMxCXROC.js → BossSpawnModal-CBAbxdbF.js} +1 -1
  5. package/dist/assets/{ControlsModal-BaSSGPXP.js → ControlsModal-ClQA01Ds.js} +1 -1
  6. package/dist/assets/{DockerLogsModal-C_Nb5L_a.js → DockerLogsModal-XYgD5MGG.js} +1 -1
  7. package/dist/assets/{EmbeddedEditor-CG0ULJUZ.js → EmbeddedEditor-BoI_2YQu.js} +1 -1
  8. package/dist/assets/{FcStdViewer-BgEgrxaw.js → FcStdViewer-CHyQKC6X.js} +1 -1
  9. package/dist/assets/{GcodeViewer-CTlX7eA7.js → GcodeViewer-DiQHpS1l.js} +1 -1
  10. package/dist/assets/{GlbViewer-CKaX8cFI.js → GlbViewer-DGul3n90.js} +1 -1
  11. package/dist/assets/{GmailOAuthSetup-1AhXjBRc.js → GmailOAuthSetup-DX-d12Ru.js} +1 -1
  12. package/dist/assets/{GoogleOAuthSetup-DqPgZjOY.js → GoogleOAuthSetup-Co5P70hM.js} +1 -1
  13. package/dist/assets/{IframeModal-ClN_kGcP.js → IframeModal-DHZGNCTd.js} +1 -1
  14. package/dist/assets/{IntegrationsPanel-ckrmRwYi.js → IntegrationsPanel-BPclkyML.js} +2 -2
  15. package/dist/assets/{LogViewerModal-D_eGItAQ.js → LogViewerModal-ByjB2seT.js} +1 -1
  16. package/dist/assets/{MonitoringModal-BrsQN8tD.js → MonitoringModal-gUhUFyfc.js} +1 -1
  17. package/dist/assets/{PM2LogsModal-CKfdmFqw.js → PM2LogsModal-C-k2vE9y.js} +1 -1
  18. package/dist/assets/{PluginsPanel-Bfqcnrsb.js → PluginsPanel-B5_HFZE2.js} +1 -1
  19. package/dist/assets/{RestoreArchivedAreaModal-oZSTlXhf.js → RestoreArchivedAreaModal-ChCA7e1o.js} +1 -1
  20. package/dist/assets/{Scene2DCanvas-B2oTAqlK.js → Scene2DCanvas-CUIwcRFS.js} +1 -1
  21. package/dist/assets/{SceneManager-pnDsJdS-.js → SceneManager-Cv9nvN7Y.js} +1 -1
  22. package/dist/assets/{SkillsPanel-AQimvs-1.js → SkillsPanel-CKZjcpyA.js} +1 -1
  23. package/dist/assets/{SlackMultiInstanceSetup-U4d0XsWJ.js → SlackMultiInstanceSetup-DkaFYIT4.js} +1 -1
  24. package/dist/assets/{SpawnModal-DgKO0K6L.js → SpawnModal-Bk5wz6qM.js} +1 -1
  25. package/dist/assets/{StatisticsModal-DDC8OYen.js → StatisticsModal-CSI4I5dD.js} +1 -1
  26. package/dist/assets/{StlViewer-DJZ7Qgp0.js → StlViewer-C50PVmER.js} +1 -1
  27. package/dist/assets/{SubordinateAssignmentModal-DCM6PpB_.js → SubordinateAssignmentModal-B6HBv3jI.js} +1 -1
  28. package/dist/assets/{ThreeAreaSelector-CjEcL3Kh.js → ThreeAreaSelector-BH6Jl_wy.js} +1 -1
  29. package/dist/assets/{ThreeViewShortcuts-UakjRD8w.js → ThreeViewShortcuts-DWI1rRyg.js} +1 -1
  30. package/dist/assets/{TriggerManagerPanel-C42VLQu6.js → TriggerManagerPanel-CIM3fekd.js} +1 -1
  31. package/dist/assets/{VideoPlayer-UW43AiLH.js → VideoPlayer-BqXneIFS.js} +1 -1
  32. package/dist/assets/{WorkflowEditorPanel-DUvf5X0c.js → WorkflowEditorPanel-Dnc8JUGC.js} +1 -1
  33. package/dist/assets/{abnfDiagram-VRR7QNED-KDmvD_Gi.js → abnfDiagram-VRR7QNED--d8igfFs.js} +1 -1
  34. package/dist/assets/{arc-D8Dnwz7O.js → arc-CQZ9HaPq.js} +1 -1
  35. package/dist/assets/{architectureDiagram-ZJ3FMSHR-DzHUfCXK.js → architectureDiagram-ZJ3FMSHR-BzkW_z4S.js} +1 -1
  36. package/dist/assets/{area-logos-JqUib9Ux.js → area-logos-C_Dt4sR6.js} +1 -1
  37. package/dist/assets/{blockDiagram-677ZJIJ3-CwOc3I3e.js → blockDiagram-677ZJIJ3-Dv97cSYA.js} +1 -1
  38. package/dist/assets/{c4Diagram-LMCZKHZV-ByDTz6Pi.js → c4Diagram-LMCZKHZV-C06G-yIj.js} +1 -1
  39. package/dist/assets/channel-D3YwkWcG.js +1 -0
  40. package/dist/assets/{chunk-2Q5K7J3B-CJ-5lUjr.js → chunk-2Q5K7J3B-BsyNFa-J.js} +1 -1
  41. package/dist/assets/{chunk-32BRIVSS-ClxbX6JR.js → chunk-32BRIVSS-CgRk3-tJ.js} +1 -1
  42. package/dist/assets/{chunk-5VM5RSS4-D-B4g6BP.js → chunk-5VM5RSS4-CMnRwv4f.js} +1 -1
  43. package/dist/assets/{chunk-EX3LRPZG-DE_ym6tm.js → chunk-EX3LRPZG-_QBKsKXW.js} +1 -1
  44. package/dist/assets/{chunk-JWPE2WC7-DbFNU_Ef.js → chunk-JWPE2WC7-k9YbHD_j.js} +1 -1
  45. package/dist/assets/{chunk-MOJQB5TN-BonkkykU.js → chunk-MOJQB5TN-CKXUL6Fi.js} +1 -1
  46. package/dist/assets/{chunk-RYQCIY6F-CqaRznBG.js → chunk-RYQCIY6F-BIAhlmfk.js} +1 -1
  47. package/dist/assets/{chunk-V7JOEXUC-DI5OpSJo.js → chunk-V7JOEXUC-DcYniTD8.js} +1 -1
  48. package/dist/assets/{chunk-VR4S4FIN-DzHJs5bu.js → chunk-VR4S4FIN-D-bNt12a.js} +1 -1
  49. package/dist/assets/{chunk-XXDRQBXY-x9Zsg6mD.js → chunk-XXDRQBXY-DobHwO4_.js} +1 -1
  50. package/dist/assets/classDiagram-OUVF2IWQ-DocPV6XK.js +1 -0
  51. package/dist/assets/classDiagram-v2-EOCWNBFH-DocPV6XK.js +1 -0
  52. package/dist/assets/{cose-bilkent-JH36ORCC-B4Gh0RgK.js → cose-bilkent-JH36ORCC-Ba_C8Q81.js} +1 -1
  53. package/dist/assets/{cynefin-VYW2F7L2-1rocbocI.js → cynefin-VYW2F7L2-Hb-1zR6k.js} +1 -1
  54. package/dist/assets/{cynefinDiagram-TSTJHNR4-BCbOrdTH.js → cynefinDiagram-TSTJHNR4-amXmiyQW.js} +1 -1
  55. package/dist/assets/{dagre-VKFMJZFB-CquTDGCQ.js → dagre-VKFMJZFB-BNUucpZJ.js} +1 -1
  56. package/dist/assets/{diagram-FQU43EPY-CtRps2DK.js → diagram-FQU43EPY-CuYw58Um.js} +1 -1
  57. package/dist/assets/{diagram-G47NLZAW-C8uHzoun.js → diagram-G47NLZAW-Dg9fCLeP.js} +1 -1
  58. package/dist/assets/{diagram-NH7WQ7WH-BzGxTXmO.js → diagram-NH7WQ7WH-qeg5sjuS.js} +1 -1
  59. package/dist/assets/{diagram-OA4YK3LP-BoUlY6He.js → diagram-OA4YK3LP-DOwtG87b.js} +1 -1
  60. package/dist/assets/{diagram-WEI45ONY-EewNkn4I.js → diagram-WEI45ONY-BM33pC3i.js} +1 -1
  61. package/dist/assets/{ebnfDiagram-CCIWWBDH-DAp0_rYI.js → ebnfDiagram-CCIWWBDH-hJnMt_nO.js} +1 -1
  62. package/dist/assets/{erDiagram-Q63AITRT-CIDiaIv_.js → erDiagram-Q63AITRT-Dv4DTadC.js} +1 -1
  63. package/dist/assets/{flowDiagram-23GEKE2U-ZQudeco2.js → flowDiagram-23GEKE2U-8DDRTZ5q.js} +1 -1
  64. package/dist/assets/{ganttDiagram-NO4QXBWP-DDa9u7Kj.js → ganttDiagram-NO4QXBWP-IWVSonaN.js} +1 -1
  65. package/dist/assets/{gitGraphDiagram-IHSO6WYX-D0LPqp_M.js → gitGraphDiagram-IHSO6WYX-B8SRF6Rm.js} +1 -1
  66. package/dist/assets/{index-CmZ79Am7.js → index-B99LPOqY.js} +1 -1
  67. package/dist/assets/{index-BuW-OFAQ.js → index-BIXZ5ma2.js} +1 -1
  68. package/dist/assets/{index-CM0wRsAP.js → index-C8sTxLSh.js} +1 -1
  69. package/dist/assets/{index-tU947Zt1.js → index-CPxwxV3y.js} +1 -1
  70. package/dist/assets/{index-CgtrBMsu.js → index-CfzJePLs.js} +1 -1
  71. package/dist/assets/{index-D0O_xUmt.js → index-CoQeR3M4.js} +1 -1
  72. package/dist/assets/{index-BMILmzZt.js → index-DZXJouwG.js} +3 -3
  73. package/dist/assets/{index-DjZWtEFJ.js → index-H2kZgwuS.js} +1 -1
  74. package/dist/assets/{index-CbjaD3wY.js → index-iox2Avj1.js} +2 -2
  75. package/dist/assets/{infoDiagram-FWYZ7A6U-CD4Ws76i.js → infoDiagram-FWYZ7A6U-DiW8Da6O.js} +1 -1
  76. package/dist/assets/{ishikawaDiagram-FXEZZL3T-DSEmTd2f.js → ishikawaDiagram-FXEZZL3T-BX9Iv2Bx.js} +1 -1
  77. package/dist/assets/{journeyDiagram-5HDEW3XC-3_c5LjHs.js → journeyDiagram-5HDEW3XC-DxOx3HNu.js} +1 -1
  78. package/dist/assets/{kanban-definition-HUTT4EX6-24lijuGn.js → kanban-definition-HUTT4EX6-CXU91xhp.js} +1 -1
  79. package/dist/assets/{linear-B_K6Qcv3.js → linear-BN1q8PcL.js} +1 -1
  80. package/dist/assets/{main-D0r07JA_.js → main-DAjvgfMx.js} +13 -13
  81. package/dist/assets/{mermaid.core-B6sgvfs-.js → mermaid.core-DDz9Iaty.js} +4 -4
  82. package/dist/assets/{mindmap-definition-LN4V7U3C-BsAOrAHj.js → mindmap-definition-LN4V7U3C-DpJ8aYp2.js} +1 -1
  83. package/dist/assets/{pegDiagram-2B236MQR-DdfupKz5.js → pegDiagram-2B236MQR-DNWtKvhp.js} +1 -1
  84. package/dist/assets/{pieDiagram-ENE6RG2P-D1YBZYdK.js → pieDiagram-ENE6RG2P-B5qvWe8-.js} +1 -1
  85. package/dist/assets/{quadrantDiagram-ABIIQ3AL-Bw-hoDGQ.js → quadrantDiagram-ABIIQ3AL-DcxOc9Jk.js} +1 -1
  86. package/dist/assets/{railroadDiagram-RFXS5EU6-CkmO-Wgv.js → railroadDiagram-RFXS5EU6-CHK9rRAr.js} +1 -1
  87. package/dist/assets/{requirementDiagram-TGXJPOKE-CSI19yqY.js → requirementDiagram-TGXJPOKE-B1q3f28r.js} +1 -1
  88. package/dist/assets/{sankeyDiagram-HTMAVEWB-BvLYUk8J.js → sankeyDiagram-HTMAVEWB-SDg0XTUl.js} +1 -1
  89. package/dist/assets/{sequenceDiagram-DBY2YBRQ-DSQLX4Eb.js → sequenceDiagram-DBY2YBRQ-C5zqmKlJ.js} +1 -1
  90. package/dist/assets/{sizeCapture-X5ZJPWSS-DfyzoJ-u.js → sizeCapture-X5ZJPWSS-B1w0ijos.js} +1 -1
  91. package/dist/assets/{stateDiagram-2N3HPSRC-G3bxzIPH.js → stateDiagram-2N3HPSRC-Dx17zSPT.js} +1 -1
  92. package/dist/assets/stateDiagram-v2-6OUMAXLB-CoNQS9IV.js +1 -0
  93. package/dist/assets/{swimlanes-5IMT3BWC-CDZGonhF.js → swimlanes-5IMT3BWC-C49X991f.js} +2 -2
  94. package/dist/assets/swimlanesDiagram-G3AALYLV-Yyot49f1.js +8 -0
  95. package/dist/assets/{timeline-definition-FHXFAJF6-C5QDZq49.js → timeline-definition-FHXFAJF6-DpOqNBNt.js} +1 -1
  96. package/dist/assets/{vennDiagram-L72KCM5P-0a1v0gi5.js → vennDiagram-L72KCM5P-CkMpg3xS.js} +1 -1
  97. package/dist/assets/{wardleyDiagram-EHGQE667-DArhtjvR.js → wardleyDiagram-EHGQE667-zJk9PTKN.js} +1 -1
  98. package/dist/assets/{web-BgCc_AGi.js → web-3dLaLyVf.js} +1 -1
  99. package/dist/assets/{web-BU7b4YVF.js → web-BL_6uaSX.js} +1 -1
  100. package/dist/assets/{web-BiQ9JdSl.js → web-DI0lko8Q.js} +1 -1
  101. package/dist/assets/{xychartDiagram-FW5EYKEG-BIZcXzGL.js → xychartDiagram-FW5EYKEG-DqYA8n2Y.js} +1 -1
  102. package/dist/build-info.json +1 -1
  103. package/dist/index.html +1 -1
  104. package/dist/src/packages/server/integrations/google-calendar/calendar-client.js +11 -4
  105. package/dist/src/packages/server/integrations/google-calendar/calendar-routes.js +3 -1
  106. package/dist/src/packages/server/integrations/google-calendar/calendar-skill.js +9 -1
  107. package/dist/src/packages/server/integrations/google-drive/drive-client.js +189 -19
  108. package/dist/src/packages/server/integrations/google-drive/drive-routes.js +48 -0
  109. package/dist/src/packages/server/integrations/google-drive/drive-skill.js +29 -1
  110. package/package.json +1 -1
  111. package/dist/assets/channel-C9DXs2xS.js +0 -1
  112. package/dist/assets/classDiagram-OUVF2IWQ-apBPMHmB.js +0 -1
  113. package/dist/assets/classDiagram-v2-EOCWNBFH-apBPMHmB.js +0 -1
  114. package/dist/assets/stateDiagram-v2-6OUMAXLB-DCUADcVF.js +0 -1
  115. package/dist/assets/swimlanesDiagram-G3AALYLV-Ddwy1JnL.js +0 -8
@@ -8,6 +8,10 @@ import { google } from 'googleapis';
8
8
  import { loadConfig, updateConfig } from './drive-config.js';
9
9
  import { getTokenHealth, needsReauth, notifyTokenRotated, onTokenRotated, probeTokenHealth, reportGoogleApiError, reportGoogleApiSuccess, startTokenHealthMonitor, } from '../google-auth/token-health.js';
10
10
  import { Readable } from 'stream';
11
+ import { pipeline } from 'stream/promises';
12
+ import * as fs from 'fs';
13
+ import * as os from 'os';
14
+ import * as path from 'path';
11
15
  // ─── State ───
12
16
  let ctx = null;
13
17
  let driveApi = null;
@@ -213,37 +217,114 @@ export async function getFile(fileId) {
213
217
  });
214
218
  return mapDriveFile(result.data);
215
219
  }
220
+ /**
221
+ * Maximum payload `getFileContent` will inline into a JSON response.
222
+ *
223
+ * Above this the JSON round-trip stops being viable long before Drive does — base64
224
+ * inflates by 4/3 and Node caps a single string at ~512 MB — so oversized reads are
225
+ * refused with a pointer to `downloadFile`, which streams to disk instead.
226
+ */
227
+ const MAX_INLINE_CONTENT_BYTES = 10 * 1024 * 1024;
228
+ /**
229
+ * Open the raw byte stream for a Drive file, exporting it first if it's a native
230
+ * Google Workspace doc. Nothing is buffered in memory: callers pipe it to disk or to
231
+ * an HTTP response, which is what makes multi-hundred-MB files downloadable at all.
232
+ */
233
+ export async function openDownloadStream(fileId, exportMimeType) {
234
+ if (!driveApi)
235
+ throw new Error('Google Drive not configured');
236
+ const meta = await driveApi.files.get({
237
+ fileId,
238
+ fields: 'name, mimeType, size',
239
+ supportsAllDrives: true,
240
+ });
241
+ const name = meta.data.name || fileId;
242
+ const sourceMimeType = meta.data.mimeType || 'application/octet-stream';
243
+ if (sourceMimeType.startsWith('application/vnd.google-apps.')) {
244
+ const exportType = exportMimeType || getDefaultExportType(sourceMimeType);
245
+ const result = await driveApi.files.export({ fileId, mimeType: exportType }, { responseType: 'stream' });
246
+ // Exported bytes are generated on the fly, so Drive reports no size up front.
247
+ return { stream: result.data, name, mimeType: exportType, exported: true };
248
+ }
249
+ const result = await driveApi.files.get({ fileId, alt: 'media', supportsAllDrives: true }, { responseType: 'stream' });
250
+ return {
251
+ stream: result.data,
252
+ name,
253
+ mimeType: sourceMimeType,
254
+ size: meta.data.size ? Number(meta.data.size) : undefined,
255
+ exported: false,
256
+ };
257
+ }
258
+ /**
259
+ * Download a Drive file straight to the local filesystem.
260
+ *
261
+ * Streams through a `.part` file and renames on success, so an interrupted transfer
262
+ * never leaves a truncated file sitting at the destination path.
263
+ */
264
+ export async function downloadFile(fileId, params = {}) {
265
+ const { stream, name, mimeType, exported } = await openDownloadStream(fileId, params.exportMimeType);
266
+ const targetPath = resolveDestPath(params.destPath, suggestFileName(name, mimeType, exported));
267
+ if (params.overwrite === false && fs.existsSync(targetPath)) {
268
+ stream.destroy();
269
+ throw new Error(`Destination already exists: ${targetPath} (pass overwrite=true to replace it)`);
270
+ }
271
+ await fs.promises.mkdir(path.dirname(targetPath), { recursive: true });
272
+ const partPath = `${targetPath}.part-${process.pid}-${Date.now()}`;
273
+ try {
274
+ await pipeline(stream, fs.createWriteStream(partPath));
275
+ await fs.promises.rename(partPath, targetPath);
276
+ }
277
+ catch (err) {
278
+ await fs.promises.rm(partPath, { force: true }).catch(() => { });
279
+ throw err;
280
+ }
281
+ const { size } = await fs.promises.stat(targetPath);
282
+ return { fileId, name, path: targetPath, bytes: size, mimeType, exported };
283
+ }
284
+ /**
285
+ * Read a file's content into memory.
286
+ *
287
+ * Binary files come back base64-encoded. The previous version asked googleapis for
288
+ * `responseType: 'text'`, which ran every byte through a UTF-8 decode — zips, PDFs and
289
+ * images arrived full of U+FFFD replacement characters, and anything past Node's string
290
+ * limit threw `Cannot create a string longer than ...`. Use `downloadFile` for anything
291
+ * large; this endpoint refuses payloads over MAX_INLINE_CONTENT_BYTES.
292
+ */
216
293
  export async function getFileContent(fileId, exportMimeType) {
217
294
  if (!driveApi)
218
295
  throw new Error('Google Drive not configured');
219
296
  // First, get the file metadata to check its type
220
297
  const meta = await driveApi.files.get({
221
298
  fileId,
222
- fields: 'mimeType, name',
299
+ fields: 'mimeType, name, size',
223
300
  supportsAllDrives: true,
224
301
  });
225
302
  const fileMimeType = meta.data.mimeType || '';
303
+ const name = meta.data.name || fileId;
304
+ const declaredSize = meta.data.size ? Number(meta.data.size) : undefined;
305
+ // Refuse before transferring anything — Drive already told us how big this is.
306
+ if (declaredSize !== undefined && declaredSize > MAX_INLINE_CONTENT_BYTES) {
307
+ throw new Error(`${name} is ${formatBytes(declaredSize)}, over the ${formatBytes(MAX_INLINE_CONTENT_BYTES)} inline limit. `
308
+ + `Use GET /api/drive/files/${fileId}/download?destPath=/absolute/path to stream it to disk instead.`);
309
+ }
226
310
  // Google Workspace files (Docs, Sheets, Slides) must be exported
227
- if (fileMimeType.startsWith('application/vnd.google-apps.')) {
228
- const exportType = exportMimeType || getDefaultExportType(fileMimeType);
229
- const result = await driveApi.files.export({
230
- fileId,
231
- mimeType: exportType,
232
- }, { responseType: 'text' });
233
- return {
234
- content: typeof result.data === 'string' ? result.data : String(result.data),
235
- mimeType: exportType,
236
- };
311
+ const isGoogleDoc = fileMimeType.startsWith('application/vnd.google-apps.');
312
+ const resultMimeType = isGoogleDoc ? (exportMimeType || getDefaultExportType(fileMimeType)) : fileMimeType;
313
+ const result = isGoogleDoc
314
+ ? await driveApi.files.export({ fileId, mimeType: resultMimeType }, { responseType: 'arraybuffer' })
315
+ : await driveApi.files.get({ fileId, alt: 'media', supportsAllDrives: true }, { responseType: 'arraybuffer' });
316
+ const buffer = toBuffer(result.data);
317
+ if (buffer.length > MAX_INLINE_CONTENT_BYTES) {
318
+ throw new Error(`${name} is ${formatBytes(buffer.length)}, over the ${formatBytes(MAX_INLINE_CONTENT_BYTES)} inline limit. `
319
+ + `Use GET /api/drive/files/${fileId}/download?destPath=/absolute/path to stream it to disk instead.`);
237
320
  }
238
- // Regular files: download content
239
- const result = await driveApi.files.get({
240
- fileId,
241
- alt: 'media',
242
- supportsAllDrives: true,
243
- }, { responseType: 'text' });
321
+ const binary = !isTextContent(buffer, resultMimeType);
244
322
  return {
245
- content: typeof result.data === 'string' ? result.data : String(result.data),
246
- mimeType: fileMimeType,
323
+ content: binary ? buffer.toString('base64') : buffer.toString('utf-8'),
324
+ mimeType: resultMimeType,
325
+ encoding: binary ? 'base64' : 'utf-8',
326
+ bytes: buffer.length,
327
+ name,
247
328
  };
248
329
  }
249
330
  export async function createFile(params) {
@@ -648,6 +729,95 @@ function mapSharedDrive(data) {
648
729
  : undefined,
649
730
  };
650
731
  }
732
+ /** Normalize whatever googleapis hands back for `responseType: 'arraybuffer'` into a Buffer. */
733
+ function toBuffer(data) {
734
+ if (Buffer.isBuffer(data))
735
+ return data;
736
+ if (data instanceof ArrayBuffer)
737
+ return Buffer.from(data);
738
+ if (ArrayBuffer.isView(data))
739
+ return Buffer.from(data.buffer, data.byteOffset, data.byteLength);
740
+ return Buffer.from(String(data ?? ''), 'utf-8');
741
+ }
742
+ /**
743
+ * Decide whether bytes can be handed back as a UTF-8 string.
744
+ *
745
+ * The mime type alone lies often enough (Drive labels plenty of real files
746
+ * `application/octet-stream`), so the bytes get the final say: a NUL byte or a failed
747
+ * round-trip through UTF-8 means base64. Getting this wrong is the corruption bug.
748
+ */
749
+ function isTextContent(buffer, mimeType) {
750
+ if (buffer.length === 0)
751
+ return true;
752
+ const looksTextual = mimeType.startsWith('text/')
753
+ || /^application\/(json|xml|javascript|x-ndjson|yaml|x-yaml|sql|x-sh)\b/.test(mimeType)
754
+ || /\+(json|xml)\b/.test(mimeType);
755
+ const sample = buffer.subarray(0, Math.min(buffer.length, 8192));
756
+ if (sample.includes(0))
757
+ return false;
758
+ const decoded = new TextDecoder('utf-8', { fatal: false }).decode(sample);
759
+ if (decoded.includes('\uFFFD'))
760
+ return false;
761
+ if (looksTextual)
762
+ return true;
763
+ // Unlabeled but clean UTF-8 with no control-character noise: treat as text.
764
+ return !/[\u0000-\u0008\u000B\u000C\u000E-\u001F]/.test(decoded);
765
+ }
766
+ /** Pick the filename to write on disk, appending an extension when an export changed the format. */
767
+ function suggestFileName(driveName, mimeType, exported) {
768
+ const safe = driveName.replace(/[/\\\u0000]/g, '_').trim() || 'drive-file';
769
+ if (!exported)
770
+ return safe;
771
+ const ext = EXPORT_EXTENSIONS[mimeType];
772
+ if (!ext || safe.toLowerCase().endsWith(ext))
773
+ return safe;
774
+ return `${safe}${ext}`;
775
+ }
776
+ const EXPORT_EXTENSIONS = {
777
+ 'text/plain': '.txt',
778
+ 'text/csv': '.csv',
779
+ 'text/html': '.html',
780
+ 'text/markdown': '.md',
781
+ 'application/pdf': '.pdf',
782
+ 'image/png': '.png',
783
+ 'image/jpeg': '.jpg',
784
+ 'image/svg+xml': '.svg',
785
+ 'application/rtf': '.rtf',
786
+ 'application/zip': '.zip',
787
+ 'application/epub+zip': '.epub',
788
+ 'application/x-vnd.oasis.opendocument.spreadsheet': '.ods',
789
+ 'application/vnd.oasis.opendocument.text': '.odt',
790
+ 'application/vnd.oasis.opendocument.presentation': '.odp',
791
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document': '.docx',
792
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet': '.xlsx',
793
+ 'application/vnd.openxmlformats-officedocument.presentationml.presentation': '.pptx',
794
+ };
795
+ /**
796
+ * Resolve the caller's `destPath` into an absolute file path.
797
+ * A directory (existing, or written with a trailing separator) gets the Drive name appended.
798
+ */
799
+ function resolveDestPath(destPath, suggestedName) {
800
+ const raw = (destPath || '').trim();
801
+ if (!raw)
802
+ return path.join(os.tmpdir(), suggestedName);
803
+ const expanded = raw === '~' || raw.startsWith('~/') ? path.join(os.homedir(), raw.slice(1)) : raw;
804
+ const resolved = path.resolve(expanded);
805
+ const isDirectory = /[/\\]$/.test(raw)
806
+ || (fs.existsSync(resolved) && fs.statSync(resolved).isDirectory());
807
+ return isDirectory ? path.join(resolved, suggestedName) : resolved;
808
+ }
809
+ function formatBytes(bytes) {
810
+ if (bytes < 1024)
811
+ return `${bytes} B`;
812
+ const units = ['KB', 'MB', 'GB', 'TB'];
813
+ let value = bytes / 1024;
814
+ let unit = 0;
815
+ while (value >= 1024 && unit < units.length - 1) {
816
+ value /= 1024;
817
+ unit++;
818
+ }
819
+ return `${value.toFixed(1)} ${units[unit]}`;
820
+ }
651
821
  function getDefaultExportType(googleMimeType) {
652
822
  switch (googleMimeType) {
653
823
  case 'application/vnd.google-apps.document':
@@ -4,6 +4,7 @@
4
4
  * Mounted at /api/drive/ by the integration registry.
5
5
  */
6
6
  import { Router } from 'express';
7
+ import { pipeline } from 'stream/promises';
7
8
  import * as driveClient from './drive-client.js';
8
9
  import { createLogger } from '../../utils/logger.js';
9
10
  const log = createLogger('DriveRoutes');
@@ -53,6 +54,53 @@ router.get('/files/:fileId/content', async (req, res) => {
53
54
  res.status(500).json({ error: `Failed to read file content: ${err instanceof Error ? err.message : err}` });
54
55
  }
55
56
  });
57
+ // GET|POST /api/drive/files/:fileId/download — Download a file's real bytes.
58
+ //
59
+ // With `destPath`, the server streams Drive -> disk and answers with JSON metadata.
60
+ // Without it, the raw bytes are streamed back to the caller (`curl -o file.zip`).
61
+ // Either way nothing is buffered in memory or squeezed through a JSON string, which is
62
+ // what `GET /content` used to do — corrupting binaries and blowing up on large files.
63
+ async function handleDownload(req, res) {
64
+ const body = (req.body || {});
65
+ const destPath = req.query.destPath ?? body.destPath;
66
+ const exportAs = req.query.exportAs ?? body.exportAs;
67
+ const overwrite = req.query.overwrite === 'false' || body.overwrite === false ? false : true;
68
+ try {
69
+ if (destPath) {
70
+ const result = await driveClient.downloadFile(req.params.fileId, {
71
+ destPath,
72
+ exportMimeType: exportAs,
73
+ overwrite,
74
+ });
75
+ res.json(result);
76
+ return;
77
+ }
78
+ // No destination: stream the bytes straight through to the HTTP response.
79
+ const { stream, name, mimeType, size } = await driveClient.openDownloadStream(req.params.fileId, exportAs);
80
+ res.setHeader('Content-Type', mimeType || 'application/octet-stream');
81
+ res.setHeader('Content-Disposition', `attachment; filename*=UTF-8''${encodeURIComponent(name)}`);
82
+ if (size !== undefined)
83
+ res.setHeader('Content-Length', String(size));
84
+ try {
85
+ await pipeline(stream, res);
86
+ }
87
+ catch (err) {
88
+ // Headers are already out, so there is no way to turn this into a JSON error —
89
+ // destroy the response so the client sees a truncated transfer instead of a
90
+ // silently short file it would treat as complete.
91
+ log.error(`Drive download stream error: ${err}`);
92
+ res.destroy(err instanceof Error ? err : new Error(String(err)));
93
+ }
94
+ }
95
+ catch (err) {
96
+ log.error(`Drive download error: ${err}`);
97
+ if (!res.headersSent) {
98
+ res.status(500).json({ error: `Failed to download file: ${err instanceof Error ? err.message : err}` });
99
+ }
100
+ }
101
+ }
102
+ router.get('/files/:fileId/download', handleDownload);
103
+ router.post('/files/:fileId/download', handleDownload);
56
104
  // POST /api/drive/files — Create a new file. Either `content` (UTF-8 string) or `filePath` (absolute host path) is required.
57
105
  router.post('/files', async (req, res) => {
58
106
  try {
@@ -23,12 +23,14 @@ Query params: \`folderId\`, \`mimeType\`, \`maxResults\`, \`pageToken\`, \`order
23
23
  curl -s "http://localhost:5174/api/drive/files/FILE_ID"
24
24
  \`\`\`
25
25
 
26
- ## Read File Content
26
+ ## Read File Content (small text files)
27
27
 
28
28
  \`\`\`bash
29
29
  curl -s "http://localhost:5174/api/drive/files/FILE_ID/content"
30
30
  \`\`\`
31
31
 
32
+ Response: \`{ content, mimeType, encoding, bytes, name }\`. \`encoding\` is \`utf-8\` for text, \`base64\` for binary — always check it before using \`content\`.
33
+
32
34
  For Google Docs/Sheets/Slides, content is automatically exported as text. Override with \`?exportAs=text/html\` or \`?exportAs=application/pdf\`.
33
35
 
34
36
  Export format defaults:
@@ -36,6 +38,31 @@ Export format defaults:
36
38
  - Google Sheets -> text/csv
37
39
  - Google Slides -> text/plain
38
40
 
41
+ Files over 10 MB are rejected with an error pointing at the download endpoint. **For any binary (zip, pdf, image, installer, video) or anything large, use \`/download\` below — do not use this endpoint.**
42
+
43
+ ## Download a File to Disk (binaries and large files)
44
+
45
+ \`\`\`bash
46
+ curl -s "http://localhost:5174/api/drive/files/FILE_ID/download?destPath=/home/user/downloads/"
47
+ \`\`\`
48
+
49
+ Streams the file straight from Drive to the local filesystem — no size limit, no encoding, byte-for-byte identical to the original. Works for 500 MB zips just as well as for a small PDF.
50
+
51
+ Query params (also accepted as JSON body fields via \`POST\` to the same URL):
52
+ - \`destPath\` — where to write it. An absolute path (\`/tmp/build.zip\`), a \`~/\` path, or a directory (existing, or ending in \`/\`) in which case the Drive file name is used. Omit it to stream the bytes back over HTTP instead (see below). Missing parent directories are created.
53
+ - \`exportAs\` — export format for native Google Docs/Sheets/Slides (e.g. \`application/pdf\`, \`application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\`). Ignored for regular files.
54
+ - \`overwrite=false\` — fail instead of replacing an existing file at the destination.
55
+
56
+ Response: \`{ fileId, name, path, bytes, mimeType, exported }\` — \`path\` is the absolute path written.
57
+
58
+ To pipe the bytes yourself instead of writing them server-side, omit \`destPath\` and let curl save them:
59
+
60
+ \`\`\`bash
61
+ curl -s "http://localhost:5174/api/drive/files/FILE_ID/download" -o /home/user/downloads/Componentes.zip
62
+ \`\`\`
63
+
64
+ The download is written through a temporary \`.part\` file and renamed on success, so an interrupted transfer never leaves a truncated file at \`destPath\`. Verify large downloads with \`ls -l\` or a checksum against the \`size\` reported by \`GET /files/FILE_ID\`.
65
+
39
66
  ## Create a File
40
67
 
41
68
  \`\`\`bash
@@ -241,6 +268,7 @@ To list files across every Shared Drive the user has access to, set \`includeIte
241
268
  ## Notes
242
269
  - Auth headers are added automatically by the system.
243
270
  - Google Workspace files (Docs, Sheets, Slides) are exported to text when reading content.
271
+ - Binary files (zip, pdf, images, installers) must go through \`/download\`, not \`/content\`.
244
272
  - File IDs can be found in Google Drive URLs or from list/search results.
245
273
  - Use \`folderId\` to scope operations to a specific folder.
246
274
  - Shared Drives (formerly Team Drives) are distinct from \"My Drive\" folders and require the \`driveId\` param for targeted queries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tide-commander",
3
- "version": "1.211.0",
3
+ "version": "1.213.0",
4
4
  "description": "Visual multi-agent orchestrator and manager for Claude Code with 3D/2D interface",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1 +0,0 @@
1
- import{U as a,C as n}from"./mermaid.core-B6sgvfs-.js";const t=(r,o)=>a.lang.round(n.parse(r)[o]);export{t as c};
@@ -1 +0,0 @@
1
- import{s as a,c as s,a as e,C as t}from"./chunk-V7JOEXUC-DI5OpSJo.js";import{_ as i}from"./mermaid.core-B6sgvfs-.js";import"./chunk-5VM5RSS4-D-B4g6BP.js";import"./chunk-XXDRQBXY-x9Zsg6mD.js";import"./chunk-VR4S4FIN-DzHJs5bu.js";import"./chunk-32BRIVSS-ClxbX6JR.js";import"./main-D0r07JA_.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-DYBBrXTx.js";var b={parser:e,get db(){return new t},renderer:s,styles:a,init:i(r=>{r.class||(r.class={}),r.class.arrowMarkerAbsolute=r.arrowMarkerAbsolute},"init")};export{b as diagram};
@@ -1 +0,0 @@
1
- import{s as a,c as s,a as e,C as t}from"./chunk-V7JOEXUC-DI5OpSJo.js";import{_ as i}from"./mermaid.core-B6sgvfs-.js";import"./chunk-5VM5RSS4-D-B4g6BP.js";import"./chunk-XXDRQBXY-x9Zsg6mD.js";import"./chunk-VR4S4FIN-DzHJs5bu.js";import"./chunk-32BRIVSS-ClxbX6JR.js";import"./main-D0r07JA_.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-DYBBrXTx.js";var b={parser:e,get db(){return new t},renderer:s,styles:a,init:i(r=>{r.class||(r.class={}),r.class.arrowMarkerAbsolute=r.arrowMarkerAbsolute},"init")};export{b as diagram};
@@ -1 +0,0 @@
1
- import{s as r,b as e,a,S as s}from"./chunk-EX3LRPZG-DE_ym6tm.js";import{_ as i}from"./mermaid.core-B6sgvfs-.js";import"./chunk-XXDRQBXY-x9Zsg6mD.js";import"./chunk-VR4S4FIN-DzHJs5bu.js";import"./chunk-32BRIVSS-ClxbX6JR.js";import"./main-D0r07JA_.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-DYBBrXTx.js";var b={parser:a,get db(){return new s(2)},renderer:e,styles:r,init:i(t=>{t.state||(t.state={}),t.state.arrowMarkerAbsolute=t.arrowMarkerAbsolute},"init")};export{b as diagram};
@@ -1,8 +0,0 @@
1
- import{c as r,s as e}from"./flowDiagram-23GEKE2U-ZQudeco2.js";import{_ as a}from"./mermaid.core-B6sgvfs-.js";import"./chunk-5VM5RSS4-D-B4g6BP.js";import"./chunk-XXDRQBXY-x9Zsg6mD.js";import"./chunk-VR4S4FIN-DzHJs5bu.js";import"./chunk-32BRIVSS-ClxbX6JR.js";import"./channel-C9DXs2xS.js";import"./main-D0r07JA_.js";import"./vendor-react--Eh9ivFN.js";import"./vendor-three-DYBBrXTx.js";var o=a(t=>`${e(t)}
2
- .swimlane.cluster rect {
3
- stroke: ${t.clusterBorder} !important;
4
- }
5
- [data-look="neo"].cluster rect {
6
- filter: none;
7
- }
8
- `,"getStyles"),m=o,_=r({defaultLayout:"swimlane",styles:m});export{_ as diagram};