@lobu/runtime-server 20.0.1 → 20.1.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 (157) hide show
  1. package/dist/catalogs/connectors.json +98 -1
  2. package/dist/component.json +1 -1
  3. package/dist/connectors/chat-user-identity.ts +45 -0
  4. package/dist/connectors/google-identity.ts +107 -0
  5. package/dist/connectors/google_drive.ts +36 -151
  6. package/dist/connectors/google_gmail.ts +149 -0
  7. package/dist/connectors/microsoft_outlook.ts +193 -0
  8. package/dist/connectors/slack-identity.ts +20 -0
  9. package/dist/dependencies.bun.lock +42 -42
  10. package/dist/owletto/dist/assets/_-CfcfHJO8.js +1 -0
  11. package/dist/owletto/dist/assets/{_-BTmsEMQo.js → _-DdvHIadV.js} +2 -2
  12. package/dist/owletto/dist/assets/_agentId-BTmFhpb6.js +1 -0
  13. package/dist/owletto/dist/assets/{_agentId-DON3NuNk.js → _agentId-DbTBU4KZ.js} +1 -1
  14. package/dist/owletto/dist/assets/{_automationId-Bprfhhg8.js → _automationId-C7dZzg6X.js} +1 -1
  15. package/dist/owletto/dist/assets/{_connectorKey._connectionId-75LMK1pB.js → _connectorKey._connectionId-NQf43Ew3.js} +1 -1
  16. package/dist/owletto/dist/assets/{_connectorKey.index-N0fJPz8N.js → _connectorKey.index-D-0ZNsgM.js} +1 -1
  17. package/dist/owletto/dist/assets/{_conversationId-BY5q9MHG.js → _conversationId-F5YmyLV9.js} +1 -1
  18. package/dist/owletto/dist/assets/{_deploymentId-DFh2d5Pm.js → _deploymentId-3LTMi0ZT.js} +1 -1
  19. package/dist/owletto/dist/assets/_name-BKeZbc-h.js +1 -0
  20. package/dist/owletto/dist/assets/{_owner-B92z-CVu.js → _owner-DglbbDEx.js} +1 -1
  21. package/dist/owletto/dist/assets/_skillKey-DhiGYYFq.js +1 -0
  22. package/dist/owletto/dist/assets/{_slug-CvHxtUEf.js → _slug-CnQDfsCE.js} +1 -1
  23. package/dist/owletto/dist/assets/{accept-invitation-CXSrxBJN.js → accept-invitation-Dgoyublh.js} +1 -1
  24. package/dist/owletto/dist/assets/{activity-route-view-C9W2Ipni.js → activity-route-view-BNzKO6aD.js} +1 -1
  25. package/dist/owletto/dist/assets/{agent-card-controls-CLupkefQ.js → agent-card-controls-VJgcB5-0.js} +1 -1
  26. package/dist/owletto/dist/assets/{agent-client-setup-list-DgFv4h0W.js → agent-client-setup-list-C5KRNRw3.js} +1 -1
  27. package/dist/owletto/dist/assets/{agent-connect-pages-DT8R_qnj.js → agent-connect-pages-BFSb6vmW.js} +1 -1
  28. package/dist/owletto/dist/assets/{agent-editor-form-ayUg3Ws1.js → agent-editor-form-CajEehVn.js} +1 -1
  29. package/dist/owletto/dist/assets/{agent-guardrails-route-D-b6CIt2.js → agent-guardrails-route-CZ_rXj-3.js} +1 -1
  30. package/dist/owletto/dist/assets/{agent-loading-shells-DjMpSoub.js → agent-loading-shells-Dczhk067.js} +1 -1
  31. package/dist/owletto/dist/assets/{agent-permissions-matrix-BuGatiEq.js → agent-permissions-matrix-DIVHvpZG.js} +1 -1
  32. package/dist/owletto/dist/assets/{agent-skill-context-DKpIFmCh.js → agent-skill-context-CxglCznW.js} +1 -1
  33. package/dist/owletto/dist/assets/{agent-skills-route-DqIMttMK.js → agent-skills-route-CatU8soC.js} +1 -1
  34. package/dist/owletto/dist/assets/{agent-subpage-shell-Bojgj1uq.js → agent-subpage-shell-DVSUdIBn.js} +1 -1
  35. package/dist/owletto/dist/assets/agent-thread-DnLUOzXk.js +134 -0
  36. package/dist/owletto/dist/assets/agents-OLmcj-qM.js +1 -0
  37. package/dist/owletto/dist/assets/{agents-workbench-BojDv6gX.js → agents-workbench-BOKifKIO.js} +1 -1
  38. package/dist/owletto/dist/assets/{app._appId-DNNB5FaI.js → app._appId-BXmITXO7.js} +1 -1
  39. package/dist/owletto/dist/assets/{automation-detail-content-CzqrHc4P.js → automation-detail-content-wJC9hhmA.js} +1 -1
  40. package/dist/owletto/dist/assets/automations-OLmcj-qM.js +1 -0
  41. package/dist/owletto/dist/assets/{calendar-VAaxHxss.js → calendar-taCoBmAh.js} +1 -1
  42. package/dist/owletto/dist/assets/{callback-0VB9tUCF.js → callback-CJxC8u_x.js} +1 -1
  43. package/dist/owletto/dist/assets/{card-HMQT7vU5.js → card-kpw3EaKC.js} +1 -1
  44. package/dist/owletto/dist/assets/{claim-C2-YTMw-.js → claim-DLHRN0bA.js} +1 -1
  45. package/dist/owletto/dist/assets/{clients-C0I3V7XE.js → clients-R4JsT_Fz.js} +1 -1
  46. package/dist/owletto/dist/assets/{code-editor-hOZHdlxM.js → code-editor-D3X0yQdI.js} +1 -1
  47. package/dist/owletto/dist/assets/connect-1ysEq9l0.js +1 -0
  48. package/dist/owletto/dist/assets/connect._clientId-BbMPs6l3.js +1 -0
  49. package/dist/owletto/dist/assets/{connected._clientId-BFuU4-8j.js → connected._clientId-ByH4etku.js} +1 -1
  50. package/dist/owletto/dist/assets/{connection-De_2AD46.js → connection-DdBkXNbX.js} +1 -1
  51. package/dist/owletto/dist/assets/{connection-feed-detail-Cbn85fG9.js → connection-feed-detail-DF93zx0A.js} +1 -1
  52. package/dist/owletto/dist/assets/{connector-provenance-B17-ze5S.js → connector-provenance-N3sc0nbo.js} +1 -1
  53. package/dist/owletto/dist/assets/{connectors-KnNED_-4.js → connectors-Ckn_aoNE.js} +1 -1
  54. package/dist/owletto/dist/assets/{consent-BOYb4pNu.js → consent-Bi6KCVtT.js} +1 -1
  55. package/dist/owletto/dist/assets/{core.esm-COW6Pfy6.js → core.esm-CFYXLQXH.js} +1 -1
  56. package/dist/owletto/dist/assets/{create-BFpUZ_mU.js → create-BiHpu2f4.js} +1 -1
  57. package/dist/owletto/dist/assets/create-C37QtjbJ.js +1 -0
  58. package/dist/owletto/dist/assets/{create-automation-form-CRenA7Ix.js → create-automation-form-Cv2RHsQ6.js} +1 -1
  59. package/dist/owletto/dist/assets/create-kAQa5_Q7.js +1 -0
  60. package/dist/owletto/dist/assets/{create._connectorKey-D4dIDQIQ.js → create._connectorKey-Qynix_hA.js} +1 -1
  61. package/dist/owletto/dist/assets/{cronstrue-BrlFh5Jy.js → cronstrue-D7xlYtGk.js} +1 -1
  62. package/dist/owletto/dist/assets/deployments-C5kSeowq.js +1 -0
  63. package/dist/owletto/dist/assets/{deployments-body-CXqfjLqj.js → deployments-body-BPCALbQe.js} +1 -1
  64. package/dist/owletto/dist/assets/{device-B0BBIdVx.js → device-DToHXxDM.js} +1 -1
  65. package/dist/owletto/dist/assets/{device-pin-tombstone-BBYes4en.js → device-pin-tombstone-DrTJYNKG.js} +1 -1
  66. package/dist/owletto/dist/assets/{device-rows-E63OZ9Cp.js → device-rows-fVm-zAiU.js} +1 -1
  67. package/dist/owletto/dist/assets/{device._deviceId-JN0cUCGe.js → device._deviceId-CIe7taim.js} +1 -1
  68. package/dist/owletto/dist/assets/{entity-options-qan9-Ycm.js → entity-options-DOGD_EyZ.js} +1 -1
  69. package/dist/owletto/dist/assets/{entity-page-CozUOlVP.js → entity-page-C8oDszRY.js} +1 -1
  70. package/dist/owletto/dist/assets/{entity-type-page-xISySjVW.js → entity-type-page-BfxIgJLq.js} +1 -1
  71. package/dist/owletto/dist/assets/{events-feed-DmZ3Ig3X.js → events-feed-B9OqmSBy.js} +1 -1
  72. package/dist/owletto/dist/assets/{full-page-spinner-Q_J5Wcop.js → full-page-spinner-DTSqneUO.js} +1 -1
  73. package/dist/owletto/dist/assets/guardrails-9Mr6avxk.js +1 -0
  74. package/dist/owletto/dist/assets/identity-DMfCjdBz.js +1 -0
  75. package/dist/owletto/dist/assets/{index-BKZMzuMS.js → index-Bfux0kHb.js} +34 -34
  76. package/dist/owletto/dist/assets/{index-pKfsEvLt.js → index-Bq4m-sK0.js} +1 -1
  77. package/dist/owletto/dist/assets/{index-CGx4og7r.js → index-CK2-iHcz.js} +1 -1
  78. package/dist/owletto/dist/assets/{index-C78ucWDF.js → index-CMOHHdFH.js} +1 -1
  79. package/dist/owletto/dist/assets/{index-BwVojwkg.js → index-COgBJ_ab.js} +1 -1
  80. package/dist/owletto/dist/assets/index-CkwwaMrx.js +1 -0
  81. package/dist/owletto/dist/assets/index-D0lZrXrY.js +1 -0
  82. package/dist/owletto/dist/assets/{index-DmB-3GhU.js → index-DYe_DVHa.js} +1 -1
  83. package/dist/owletto/dist/assets/index-DZadnZpq.js +1 -0
  84. package/dist/owletto/dist/assets/{index-DLZbFRSM.js → index-DcWyuLQS.js} +1 -1
  85. package/dist/owletto/dist/assets/{index-BwN9pHNs.js → index-DkKALC2l.js} +1 -1
  86. package/dist/owletto/dist/assets/index-DlqjyZKQ.js +1 -0
  87. package/dist/owletto/dist/assets/index-Dv0huHrO.js +1 -0
  88. package/dist/owletto/dist/assets/index-DxIDxgPJ.js +1 -0
  89. package/dist/owletto/dist/assets/index-bKUccXCc.js +1 -0
  90. package/dist/owletto/dist/assets/{index-C9Dtjaoi.js → index-jGZeANLE.js} +1 -1
  91. package/dist/owletto/dist/assets/{json-diff-1FNS_wGA.js → json-diff-CANZD4MQ.js} +1 -1
  92. package/dist/owletto/dist/assets/{list-skeleton-B6gjzr8t.js → list-skeleton-DZTUxpBx.js} +1 -1
  93. package/dist/owletto/dist/assets/{login-S9EGV_EA.js → login-D53geSP7.js} +1 -1
  94. package/dist/owletto/dist/assets/{logout-BOXPSr57.js → logout-DKQS25qd.js} +1 -1
  95. package/dist/owletto/dist/assets/{member-scope-gate-yGr4lrGD.js → member-scope-gate-C4QyRm2Q.js} +1 -1
  96. package/dist/owletto/dist/assets/{memory-browse-page-5n3MvqdS.js → memory-browse-page-DOpV3vht.js} +1 -1
  97. package/dist/owletto/dist/assets/{model-selector-9ZRlR7Sa.js → model-selector-CvU3VP90.js} +1 -1
  98. package/dist/owletto/dist/assets/models-ooBIWFuB.js +1 -0
  99. package/dist/owletto/dist/assets/new-B8_sRMYD.js +1 -0
  100. package/dist/owletto/dist/assets/{new-D4wlbvAZ.js → new-DIjOVXrQ.js} +1 -1
  101. package/dist/owletto/dist/assets/{new-BeZJOJgR.js → new-Df1q7GEj.js} +1 -1
  102. package/dist/owletto/dist/assets/{oauth-workspace-access-DoE-9F42.js → oauth-workspace-access-DWfiekRz.js} +1 -1
  103. package/dist/owletto/dist/assets/{organization-BezNEJK7.js → organization-DHEC7kDq.js} +1 -1
  104. package/dist/owletto/dist/assets/{permissions-GkKtC6a5.js → permissions-i7iwnE1a.js} +1 -1
  105. package/dist/owletto/dist/assets/{proposal-review-shell-Bk9D_9YN.js → proposal-review-shell-C_LcyUEF.js} +1 -1
  106. package/dist/owletto/dist/assets/{recent-BVvscz1V.js → recent-By19_Buq.js} +1 -1
  107. package/dist/owletto/dist/assets/{renderer-CAyr3B3s.js → renderer-B1UThnk2.js} +1 -1
  108. package/dist/owletto/dist/assets/{reset-password-atCMI5uQ.js → reset-password-Dsz5-Xeo.js} +1 -1
  109. package/dist/owletto/dist/assets/{runs-CftQDTkq.js → runs-BQ11PAQT.js} +1 -1
  110. package/dist/owletto/dist/assets/{runs-panel-BkRtr_C4.js → runs-panel-wkV1aGD9.js} +1 -1
  111. package/dist/owletto/dist/assets/{runs-table-CWCl38L5.js → runs-table-DzSWYkaf.js} +1 -1
  112. package/dist/owletto/dist/assets/{schema-value-normalization-C9Lm83-q.js → schema-value-normalization--DhnhJNf.js} +1 -1
  113. package/dist/owletto/dist/assets/{settings-CgTgofgd.js → settings-Bu239SXe.js} +1 -1
  114. package/dist/owletto/dist/assets/settings-FxbIvOhH.js +1 -0
  115. package/dist/owletto/dist/assets/skills-MBZ5ilDK.js +1 -0
  116. package/dist/owletto/dist/assets/{switch-BOGbkDQb.js → switch-CCKllS7w.js} +1 -1
  117. package/dist/owletto/dist/assets/{use-mention-search-C9ckRw0s.js → use-mention-search-CldNZTiT.js} +1 -1
  118. package/dist/owletto/dist/index.html +1 -1
  119. package/dist/server-main.bundle.mjs +3950 -3509
  120. package/npm-shrinkwrap.json +164 -160
  121. package/package.json +1 -1
  122. package/vendor/connector-sdk/dist/file-output.d.ts +97 -0
  123. package/vendor/connector-sdk/dist/file-output.js +176 -0
  124. package/vendor/connector-sdk/dist/index.d.ts +2 -0
  125. package/vendor/connector-sdk/dist/index.js +1 -0
  126. package/vendor/connector-sdk/package.json +1 -1
  127. package/vendor/core/dist/classify-error.js +50 -2
  128. package/vendor/core/dist/constants.d.ts +13 -6
  129. package/vendor/core/dist/constants.js +22 -8
  130. package/vendor/core/dist/errors.d.ts +20 -0
  131. package/vendor/core/dist/errors.js +21 -1
  132. package/vendor/core/package.json +1 -1
  133. package/dist/owletto/dist/assets/_-ea0K1u_g.js +0 -1
  134. package/dist/owletto/dist/assets/_agentId-qF8hi8Cf.js +0 -1
  135. package/dist/owletto/dist/assets/_name-OY_X_Zm-.js +0 -1
  136. package/dist/owletto/dist/assets/_skillKey-CeEE23_w.js +0 -1
  137. package/dist/owletto/dist/assets/agent-thread-R8Pego9t.js +0 -134
  138. package/dist/owletto/dist/assets/agents-C9x76gSX.js +0 -1
  139. package/dist/owletto/dist/assets/automations-C9x76gSX.js +0 -1
  140. package/dist/owletto/dist/assets/connect-DSr_gD8x.js +0 -1
  141. package/dist/owletto/dist/assets/connect._clientId-CTamwGrw.js +0 -1
  142. package/dist/owletto/dist/assets/create-CblXKFGZ.js +0 -1
  143. package/dist/owletto/dist/assets/create-ChUbSYvl.js +0 -1
  144. package/dist/owletto/dist/assets/deployments-DTFrUY7p.js +0 -1
  145. package/dist/owletto/dist/assets/guardrails-BB9iOxE3.js +0 -1
  146. package/dist/owletto/dist/assets/identity-DYbfG4hU.js +0 -1
  147. package/dist/owletto/dist/assets/index-7d9B918E.js +0 -1
  148. package/dist/owletto/dist/assets/index-BsDA0XzK.js +0 -1
  149. package/dist/owletto/dist/assets/index-C4Lz_gB-.js +0 -1
  150. package/dist/owletto/dist/assets/index-CO65Rkad.js +0 -1
  151. package/dist/owletto/dist/assets/index-CT_kxGkR.js +0 -1
  152. package/dist/owletto/dist/assets/index-CrKgNtiq.js +0 -1
  153. package/dist/owletto/dist/assets/index-DUIbfL6x.js +0 -1
  154. package/dist/owletto/dist/assets/models-LOhfJ0sb.js +0 -1
  155. package/dist/owletto/dist/assets/new-Dxn1qrmS.js +0 -1
  156. package/dist/owletto/dist/assets/settings-BKMOjfYf.js +0 -1
  157. package/dist/owletto/dist/assets/skills-DWr8qR3U.js +0 -1
@@ -6,6 +6,10 @@
6
6
  */
7
7
 
8
8
  import {
9
+ downloadSizeError,
10
+ fileDownloadOutput,
11
+ inlineContentBudget,
12
+ inlineMaxBytesSchema,
9
13
  type ActionContext,
10
14
  type ActionResult,
11
15
  ConnectorRuntime,
@@ -403,6 +407,38 @@ export default class GmailConnector extends ConnectorRuntime<GmailCheckpoint, Gm
403
407
  },
404
408
  },
405
409
  },
410
+ download_attachment: {
411
+ key: 'download_attachment',
412
+ kind: 'read',
413
+ name: 'Download Attachment',
414
+ description:
415
+ 'Download one attachment from a Gmail message. The bytes are published as an attachment with a `download_url` a device can fetch, and small text files are ALSO returned inline as `content`. Get `attachment_id` from `get_thread`, which lists each message\'s attachments.',
416
+ requiresApproval: false,
417
+ requiredScopes: ['https://www.googleapis.com/auth/gmail.readonly'],
418
+ inputSchema: {
419
+ type: 'object',
420
+ required: ['message_id', 'attachment_id'],
421
+ properties: {
422
+ message_id: {
423
+ type: 'string',
424
+ description: 'Message ID the attachment belongs to (from get_thread).',
425
+ },
426
+ attachment_id: {
427
+ type: 'string',
428
+ description: 'Attachment ID from get_thread. Gmail re-issues these per fetch, so use one from a recent get_thread rather than a stored copy.',
429
+ },
430
+ filename: {
431
+ type: 'string',
432
+ description: 'Name to publish the attachment under. Pass the filename get_thread reported for this attachment; nothing looks it up for you, so omitting it names the file after the attachment ID.',
433
+ },
434
+ mime_type: {
435
+ type: 'string',
436
+ description: 'Media type of the bytes. Pass the type get_thread reported for this attachment; nothing looks it up for you, so omitting it falls back to application/octet-stream, which also stops a text file being returned inline.',
437
+ },
438
+ inline_max_bytes: inlineMaxBytesSchema(),
439
+ },
440
+ },
441
+ },
406
442
  },
407
443
  };
408
444
 
@@ -585,6 +621,8 @@ export default class GmailConnector extends ConnectorRuntime<GmailCheckpoint, Gm
585
621
  return await this.searchEmails(http, ctx.input);
586
622
  case 'get_thread':
587
623
  return await this.getThread(http, ctx.input);
624
+ case 'download_attachment':
625
+ return await this.downloadAttachment(http, ctx.input);
588
626
  default:
589
627
  return { success: false, error: `Unknown action: ${ctx.actionKey}` };
590
628
  }
@@ -981,6 +1019,11 @@ export default class GmailConnector extends ConnectorRuntime<GmailCheckpoint, Gm
981
1019
  received_at: Number.isFinite(Number(msg.internalDate)) ? new Date(Number(msg.internalDate)).toISOString() : null,
982
1020
  snippet: msg.snippet,
983
1021
  body: await this.extractBody(msg.payload, http, msg.id),
1022
+ // Without this an agent can see that a mail HAS an attachment and
1023
+ // still have no way to name it: `attachment_id` exists nowhere else in
1024
+ // the connector's output, and download_attachment cannot be called
1025
+ // without one.
1026
+ attachments: this.collectAttachments(msg.payload),
984
1027
  });
985
1028
  }
986
1029
 
@@ -1173,6 +1216,112 @@ export default class GmailConnector extends ConnectorRuntime<GmailCheckpoint, Gm
1173
1216
 
1174
1217
  private readonly emailBodyConverter = createEmailBodyConverter();
1175
1218
 
1219
+ /**
1220
+ * List a message's attachment parts so an agent can name one.
1221
+ *
1222
+ * Gmail models an attachment as a leaf MIME part carrying a `filename` and a
1223
+ * `body.attachmentId`. The walk mirrors `extractBody`'s, but keeps exactly
1224
+ * what that one discards: a part with a filename is skipped there as "not
1225
+ * body text", which is precisely what makes it an attachment here.
1226
+ *
1227
+ * Inline parts (an embedded signature image) are included: they are real
1228
+ * bytes a caller may want, and Gmail does not mark them differently enough
1229
+ * to filter on without also dropping legitimate attachments.
1230
+ */
1231
+ private collectAttachments(
1232
+ payload: GmailMessagePayload
1233
+ ): Array<{ attachment_id: string; filename: string; mime_type: string; size_bytes: number }> {
1234
+ const found: Array<{
1235
+ attachment_id: string;
1236
+ filename: string;
1237
+ mime_type: string;
1238
+ size_bytes: number;
1239
+ }> = [];
1240
+ const walk = (part: GmailMessagePayload): void => {
1241
+ if (part.body?.attachmentId && part.filename) {
1242
+ found.push({
1243
+ attachment_id: part.body.attachmentId,
1244
+ filename: part.filename,
1245
+ mime_type: part.mimeType,
1246
+ size_bytes: part.body.size ?? 0,
1247
+ });
1248
+ }
1249
+ for (const child of part.parts ?? []) walk(child);
1250
+ };
1251
+ walk(payload);
1252
+ return found;
1253
+ }
1254
+
1255
+ /**
1256
+ * Download one attachment's bytes and publish them.
1257
+ *
1258
+ * Gmail returns the bytes base64url-encoded inside a JSON envelope rather
1259
+ * than as a body, and carries no filename or media type on that response —
1260
+ * both live on the MIME part, which is why `get_thread` reports them and why
1261
+ * they can be passed back in here.
1262
+ */
1263
+ private async downloadAttachment(
1264
+ http: HttpClient,
1265
+ input: Record<string, unknown>
1266
+ ): Promise<ActionResult> {
1267
+ const messageId = input.message_id as string;
1268
+ const attachmentId = input.attachment_id as string;
1269
+ if (!messageId) return { success: false, error: 'message_id is required.' };
1270
+ if (!attachmentId) return { success: false, error: 'attachment_id is required.' };
1271
+
1272
+ const response = await http.raw(
1273
+ `${this.BASE_URL}/messages/${encodeURIComponent(messageId)}/attachments/${encodeURIComponent(attachmentId)}`
1274
+ );
1275
+ if (!response.ok) {
1276
+ return {
1277
+ success: false,
1278
+ error: `Gmail attachment error (${response.status}): ${await response.text()}`,
1279
+ };
1280
+ }
1281
+
1282
+ const envelope = (await response.json()) as { data?: string; size?: number };
1283
+ const filename = (input.filename as string) || attachmentId;
1284
+ const mimeType = (input.mime_type as string) || 'application/octet-stream';
1285
+
1286
+ // Gmail has no size endpoint, so the base64 string is already in hand by
1287
+ // the time the declared size can be read. Refusing here still keeps the
1288
+ // decoded bytes and the base64 copy `fileDownloadOutput` re-encodes from
1289
+ // ever existing alongside it — three copies of the file is the OOM.
1290
+ const declaredTooBig = downloadSizeError(envelope.size, filename);
1291
+ if (declaredTooBig) return { success: false, error: declaredTooBig };
1292
+
1293
+ if (!envelope.data) {
1294
+ return { success: false, error: `Gmail attachment ${filename} returned no data.` };
1295
+ }
1296
+
1297
+ // Gmail uses base64URL (RFC 4648 §5); Buffer's 'base64' decoder accepts
1298
+ // both alphabets, so no translation is needed.
1299
+ const bytes = Buffer.from(envelope.data, 'base64');
1300
+ if (bytes.length === 0) {
1301
+ return { success: false, error: `Gmail attachment ${filename} is empty.` };
1302
+ }
1303
+ // Gmail's `size` is the decoded length, but it is advisory: an attachment
1304
+ // that omits it only reveals its real size here.
1305
+ const receivedTooBig = downloadSizeError(bytes.length, filename);
1306
+ if (receivedTooBig) return { success: false, error: receivedTooBig };
1307
+
1308
+ return {
1309
+ success: true,
1310
+ output: {
1311
+ message_id: messageId,
1312
+ attachment_id: attachmentId,
1313
+ name: filename,
1314
+ mime_type: mimeType,
1315
+ ...fileDownloadOutput({
1316
+ bytes,
1317
+ filename,
1318
+ mimeType,
1319
+ inlineMaxBytes: inlineContentBudget(input.inline_max_bytes),
1320
+ }),
1321
+ },
1322
+ };
1323
+ }
1324
+
1176
1325
  private async extractBody(
1177
1326
  payload: GmailMessagePayload,
1178
1327
  http: HttpClient,
@@ -6,10 +6,16 @@
6
6
  */
7
7
 
8
8
  import {
9
+ type ActionContext,
10
+ type ActionResult,
9
11
  type RuntimeConnectorDefinition,
10
12
  ConnectorRuntime,
13
+ downloadSizeError,
11
14
  type EventEnvelope,
15
+ fileDownloadOutput,
12
16
  type HttpClient,
17
+ inlineContentBudget,
18
+ inlineMaxBytesSchema,
13
19
  paginateByCursor,
14
20
  requireBearerClient,
15
21
  type SyncContext,
@@ -20,6 +26,21 @@ import {
20
26
  // Microsoft Graph API types
21
27
  // ---------------------------------------------------------------------------
22
28
 
29
+ /**
30
+ * One `/messages/{id}/attachments` entry. `contentBytes` is present only on
31
+ * `#microsoft.graph.fileAttachment`; the reference and item subtypes carry a
32
+ * link or an embedded resource instead.
33
+ */
34
+ interface GraphAttachment {
35
+ id: string;
36
+ name?: string;
37
+ contentType?: string;
38
+ size?: number;
39
+ isInline?: boolean;
40
+ contentBytes?: string;
41
+ '@odata.type'?: string;
42
+ }
43
+
23
44
  interface GraphMessage {
24
45
  id: string;
25
46
  conversationId: string;
@@ -218,6 +239,51 @@ export default class MicrosoftOutlookConnector extends ConnectorRuntime {
218
239
  },
219
240
  },
220
241
  },
242
+ actions: {
243
+ list_attachments: {
244
+ key: 'list_attachments',
245
+ kind: 'read',
246
+ name: 'List Attachments',
247
+ description:
248
+ "List a message's attachments with their IDs, names, types and sizes. The feed only reports `has_attachments`, so this is how an agent learns what to download.",
249
+ requiresApproval: false,
250
+ requiredScopes: ['Mail.Read'],
251
+ inputSchema: {
252
+ type: 'object',
253
+ required: ['message_id'],
254
+ properties: {
255
+ message_id: {
256
+ type: 'string',
257
+ description: 'Message ID (the event\'s origin_id).',
258
+ },
259
+ },
260
+ },
261
+ },
262
+ download_attachment: {
263
+ key: 'download_attachment',
264
+ kind: 'read',
265
+ name: 'Download Attachment',
266
+ description:
267
+ 'Download one attachment from an Outlook message. The bytes are published as an attachment with a `download_url` a device can fetch, and small text files are ALSO returned inline as `content`. Get `attachment_id` from `list_attachments`.',
268
+ requiresApproval: false,
269
+ requiredScopes: ['Mail.Read'],
270
+ inputSchema: {
271
+ type: 'object',
272
+ required: ['message_id', 'attachment_id'],
273
+ properties: {
274
+ message_id: {
275
+ type: 'string',
276
+ description: 'Message ID the attachment belongs to.',
277
+ },
278
+ attachment_id: {
279
+ type: 'string',
280
+ description: 'Attachment ID from list_attachments.',
281
+ },
282
+ inline_max_bytes: inlineMaxBytesSchema(),
283
+ },
284
+ },
285
+ },
286
+ },
221
287
  };
222
288
 
223
289
  private readonly API_BASE = 'https://graph.microsoft.com/v1.0';
@@ -248,6 +314,133 @@ export default class MicrosoftOutlookConnector extends ConnectorRuntime {
248
314
  // -------------------------------------------------------------------------
249
315
  // execute
250
316
  // -------------------------------------------------------------------------
317
+
318
+ async execute(ctx: ActionContext): Promise<ActionResult> {
319
+ try {
320
+ const http = requireBearerClient(ctx.credentials, {
321
+ errorPrefix: 'Microsoft Graph API',
322
+ label: 'Microsoft Outlook',
323
+ });
324
+
325
+ switch (ctx.actionKey) {
326
+ case 'list_attachments':
327
+ return await this.listAttachments(http, ctx.input);
328
+ case 'download_attachment':
329
+ return await this.downloadAttachment(http, ctx.input);
330
+ default:
331
+ return { success: false, error: `Unknown action: ${ctx.actionKey}` };
332
+ }
333
+ } catch (error) {
334
+ return {
335
+ success: false,
336
+ error: error instanceof Error ? error.message : String(error),
337
+ };
338
+ }
339
+ }
340
+
341
+ /**
342
+ * List a message's attachments without their bytes.
343
+ *
344
+ * `$select` is load-bearing, not a micro-optimisation: Graph serialises
345
+ * `contentBytes` into the LIST response by default, so an unfiltered call on
346
+ * a mail with three 5 MB files returns ~20 MB of base64 the caller never
347
+ * asked for — which on the isolate lane is an out-of-memory kill.
348
+ *
349
+ * Reference attachments (a OneDrive link) and item attachments (an embedded
350
+ * mail) carry no `contentBytes` at all. `type` echoes the `@odata.type`
351
+ * annotation that marks which subtype each entry is, so a caller can usually
352
+ * see up front why `download_attachment` will refuse one. It is an annotation
353
+ * rather than a selected property, so treat it as advisory and empty when
354
+ * absent — the authoritative refusal comes from `download_attachment`, whose
355
+ * single-attachment GET is not `$select`ed and always carries the subtype.
356
+ */
357
+ private async listAttachments(
358
+ http: HttpClient,
359
+ input: Record<string, unknown>
360
+ ): Promise<ActionResult> {
361
+ const messageId = input.message_id as string;
362
+ if (!messageId) return { success: false, error: 'message_id is required.' };
363
+
364
+ const response = (await http.get(
365
+ `${this.API_BASE}/me/messages/${encodeURIComponent(messageId)}/attachments?$select=id,name,contentType,size,isInline`
366
+ )) as { value?: GraphAttachment[] };
367
+
368
+ return {
369
+ success: true,
370
+ output: {
371
+ message_id: messageId,
372
+ attachments: (response.value ?? []).map((attachment) => ({
373
+ attachment_id: attachment.id,
374
+ filename: attachment.name ?? attachment.id,
375
+ mime_type: attachment.contentType ?? 'application/octet-stream',
376
+ size_bytes: attachment.size ?? 0,
377
+ is_inline: Boolean(attachment.isInline),
378
+ type: attachment['@odata.type'] ?? '',
379
+ })),
380
+ },
381
+ };
382
+ }
383
+
384
+ /**
385
+ * Download one attachment's bytes and publish them.
386
+ *
387
+ * Graph returns the bytes base64 inside the attachment resource rather than
388
+ * as a body. The `$value` endpoint would hand back raw bytes, but it 404s for
389
+ * anything that is not a file attachment, so the JSON shape is used for both
390
+ * the bytes and the readable refusal.
391
+ */
392
+ private async downloadAttachment(
393
+ http: HttpClient,
394
+ input: Record<string, unknown>
395
+ ): Promise<ActionResult> {
396
+ const messageId = input.message_id as string;
397
+ const attachmentId = input.attachment_id as string;
398
+ if (!messageId) return { success: false, error: 'message_id is required.' };
399
+ if (!attachmentId) return { success: false, error: 'attachment_id is required.' };
400
+
401
+ const attachment = (await http.get(
402
+ `${this.API_BASE}/me/messages/${encodeURIComponent(messageId)}/attachments/${encodeURIComponent(attachmentId)}`
403
+ )) as GraphAttachment;
404
+
405
+ // Refuse on the DECLARED size before decoding, so the decoded bytes and the
406
+ // base64 copy re-encoded for the attachment never join the string in memory.
407
+ const declaredTooBig = downloadSizeError(attachment.size, attachment.name ?? attachmentId);
408
+ if (declaredTooBig) return { success: false, error: declaredTooBig };
409
+
410
+ if (!attachment.contentBytes) {
411
+ return {
412
+ success: false,
413
+ error: `Outlook attachment ${attachment.name ?? attachmentId} carries no bytes (${attachment['@odata.type'] ?? 'unknown type'}). Only file attachments can be downloaded; a reference attachment lives in OneDrive and an item attachment is an embedded message.`,
414
+ };
415
+ }
416
+
417
+ const bytes = Buffer.from(attachment.contentBytes, 'base64');
418
+ if (bytes.length === 0) {
419
+ return { success: false, error: `Outlook attachment ${attachment.name ?? attachmentId} is empty.` };
420
+ }
421
+ const receivedTooBig = downloadSizeError(bytes.length, attachment.name ?? attachmentId);
422
+ if (receivedTooBig) return { success: false, error: receivedTooBig };
423
+
424
+ const filename = attachment.name ?? attachmentId;
425
+ const mimeType = attachment.contentType ?? 'application/octet-stream';
426
+
427
+ return {
428
+ success: true,
429
+ output: {
430
+ message_id: messageId,
431
+ attachment_id: attachmentId,
432
+ name: filename,
433
+ mime_type: mimeType,
434
+ ...fileDownloadOutput({
435
+ bytes,
436
+ filename,
437
+ mimeType,
438
+ inlineMaxBytes: inlineContentBudget(input.inline_max_bytes),
439
+ }),
440
+ },
441
+ };
442
+ }
443
+
251
444
  // -------------------------------------------------------------------------
252
445
  // Feed: messages
253
446
  // -------------------------------------------------------------------------
@@ -13,6 +13,7 @@ import type {
13
13
  AclSourceDef,
14
14
  ChannelReadIdentity,
15
15
  } from '@lobu/connector-sdk';
16
+ import type { ChatUserIdentity } from './chat-user-identity.js';
16
17
  import type { ConnectorIdentityModule } from './connector-identity-module.js';
17
18
 
18
19
  /** Connector-owned identity namespaces (not SDK-global). */
@@ -125,6 +126,25 @@ export const slackChannelReadIdentity: ChannelReadIdentity = {
125
126
  },
126
127
  };
127
128
 
129
+ /**
130
+ * Slack's chat-sender identity model — how an inbound message's sender maps to
131
+ * the `slack_user_id` a Slack sign-in stamped. Shares `normalizeSlackUserId`
132
+ * with the writer so the key matches byte-for-byte.
133
+ *
134
+ * The team id is REQUIRED: `buildUserKey` returns null without it rather than
135
+ * falling back to a bare `U…`. Two workspaces can legitimately contain the same
136
+ * bare id, and this link authorizes approvals and agent re-binding, so an
137
+ * unscoped key would be a mis-grant.
138
+ */
139
+ export const slackChatUserIdentity: ChatUserIdentity = {
140
+ platform: 'slack',
141
+ providerId: 'slack',
142
+ namespace: SLACK_IDENTITY.USER_ID,
143
+ buildUserKey(teamId, platformUserId) {
144
+ return normalizeSlackUserId(teamId, platformUserId);
145
+ },
146
+ };
147
+
128
148
  /** A Slack channel and the (bare `U…`) ids of its members. */
129
149
  export interface SlackChannelInput {
130
150
  /** Bare Slack channel id (`C…` / `G…`). */