@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
@@ -1865,6 +1865,47 @@
1865
1865
  }
1866
1866
  }
1867
1867
  }
1868
+ },
1869
+ "download_attachment": {
1870
+ "key": "download_attachment",
1871
+ "kind": "read",
1872
+ "name": "Download Attachment",
1873
+ "description": "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.",
1874
+ "requiresApproval": false,
1875
+ "requiredScopes": [
1876
+ "https://www.googleapis.com/auth/gmail.readonly"
1877
+ ],
1878
+ "inputSchema": {
1879
+ "type": "object",
1880
+ "required": [
1881
+ "message_id",
1882
+ "attachment_id"
1883
+ ],
1884
+ "properties": {
1885
+ "message_id": {
1886
+ "type": "string",
1887
+ "description": "Message ID the attachment belongs to (from get_thread)."
1888
+ },
1889
+ "attachment_id": {
1890
+ "type": "string",
1891
+ "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."
1892
+ },
1893
+ "filename": {
1894
+ "type": "string",
1895
+ "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."
1896
+ },
1897
+ "mime_type": {
1898
+ "type": "string",
1899
+ "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."
1900
+ },
1901
+ "inline_max_bytes": {
1902
+ "type": "integer",
1903
+ "minimum": 0,
1904
+ "maximum": 1048576,
1905
+ "description": "Return text content inline when the file is at most this many bytes (default 262144, max 1048576). Binary files are never inlined. 0 disables inlining; the attachment is still published."
1906
+ }
1907
+ }
1908
+ }
1868
1909
  }
1869
1910
  },
1870
1911
  "automation_events": null,
@@ -3420,7 +3461,63 @@
3420
3461
  ]
3421
3462
  }
3422
3463
  },
3423
- "actions_schema": null,
3464
+ "actions_schema": {
3465
+ "list_attachments": {
3466
+ "key": "list_attachments",
3467
+ "kind": "read",
3468
+ "name": "List Attachments",
3469
+ "description": "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.",
3470
+ "requiresApproval": false,
3471
+ "requiredScopes": [
3472
+ "Mail.Read"
3473
+ ],
3474
+ "inputSchema": {
3475
+ "type": "object",
3476
+ "required": [
3477
+ "message_id"
3478
+ ],
3479
+ "properties": {
3480
+ "message_id": {
3481
+ "type": "string",
3482
+ "description": "Message ID (the event's origin_id)."
3483
+ }
3484
+ }
3485
+ }
3486
+ },
3487
+ "download_attachment": {
3488
+ "key": "download_attachment",
3489
+ "kind": "read",
3490
+ "name": "Download Attachment",
3491
+ "description": "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`.",
3492
+ "requiresApproval": false,
3493
+ "requiredScopes": [
3494
+ "Mail.Read"
3495
+ ],
3496
+ "inputSchema": {
3497
+ "type": "object",
3498
+ "required": [
3499
+ "message_id",
3500
+ "attachment_id"
3501
+ ],
3502
+ "properties": {
3503
+ "message_id": {
3504
+ "type": "string",
3505
+ "description": "Message ID the attachment belongs to."
3506
+ },
3507
+ "attachment_id": {
3508
+ "type": "string",
3509
+ "description": "Attachment ID from list_attachments."
3510
+ },
3511
+ "inline_max_bytes": {
3512
+ "type": "integer",
3513
+ "minimum": 0,
3514
+ "maximum": 1048576,
3515
+ "description": "Return text content inline when the file is at most this many bytes (default 262144, max 1048576). Binary files are never inlined. 0 disables inlining; the attachment is still published."
3516
+ }
3517
+ }
3518
+ }
3519
+ }
3520
+ },
3424
3521
  "automation_events": null,
3425
3522
  "options_schema": null,
3426
3523
  "favicon_domain": "outlook.com",
@@ -4,6 +4,6 @@
4
4
  "server": "dist/server.bundle.mjs",
5
5
  "embeddingsServer": "dist/embeddings-server.mjs"
6
6
  },
7
- "version": "20.0.1",
7
+ "version": "20.1.0",
8
8
  "verify": "dist/verify.mjs"
9
9
  }
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Connector-owned chat-identity descriptors.
3
+ *
4
+ * A chat platform's "who is this sender" model has two connector-specific
5
+ * facts core code must never hardcode: which `entity_identities` namespace the
6
+ * link is stored under, and how a raw (team, user) pair from an inbound message
7
+ * becomes the storage key. Both live here, contributed by the connector that
8
+ * owns the platform — mirroring `ChannelReadIdentity` for the read-ACL gate.
9
+ *
10
+ * The server collects these in `lobu/stores/chat-identity-sources.ts` and
11
+ * dispatches on `platform`, so `resolveChatUserIdentity` names no connector.
12
+ *
13
+ * The KEY SHAPE is the whole point of the descriptor. Slack user ids are only
14
+ * unique within a workspace, so Slack's key is the composite `T…:U…` and a
15
+ * message without a team id must fail closed. A Google account id is globally
16
+ * unique, so Google's key is the bare id and there is nothing to scope it by.
17
+ * Getting that wrong in either direction is a mis-grant, not a wrong answer —
18
+ * these links authorize approvals and agent re-binding.
19
+ */
20
+
21
+ /** How one chat platform keys a sender identity. */
22
+ export interface ChatUserIdentity {
23
+ /** Chat platform key an inbound message arrives on (`slack`, `gchat`, …). */
24
+ platform: string;
25
+ /**
26
+ * The Better Auth `providerId` whose sign-in PROVES this identity. The login
27
+ * writer stamps the namespace only after a successful OAuth exchange with
28
+ * this provider; nothing else may mint the link.
29
+ */
30
+ providerId: string;
31
+ /** `entity_identities` namespace the key is stored under. */
32
+ namespace: string;
33
+ /**
34
+ * Build the storage key from an inbound message's team id and platform user
35
+ * id. Returns null when the inputs cannot form a valid key — callers treat
36
+ * null as "unlinked", which is the correct fail-closed answer.
37
+ *
38
+ * `teamId` is meaningful only for platforms whose user ids are tenant-scoped;
39
+ * globally-unique platforms ignore it.
40
+ */
41
+ buildUserKey(
42
+ teamId: string | null | undefined,
43
+ platformUserId: string | null | undefined,
44
+ ): string | null;
45
+ }
@@ -0,0 +1,107 @@
1
+ /**
2
+ * Google connector identity namespace and normalization.
3
+ *
4
+ * Single source of truth for `google_user_id` rules. Google sign-in writes it;
5
+ * the Google Chat sender lookup reads it. Connector-specific identity knowledge
6
+ * stays in the connector package so core code never names Google.
7
+ *
8
+ * WHY ONE NAMESPACE SERVES BOTH: a Google Chat `User.name` is `users/{id}`,
9
+ * where `{id}` is the same account id Google puts in the OIDC `sub` claim. So
10
+ * the Chat sender and the web signer are keyed identically, with no directory
11
+ * lookup in between. This was confirmed against real accounts before relying on
12
+ * it — the Chat-side user cache and the stored OIDC `sub` agree digit for
13
+ * digit — not inferred from Google's documentation alone.
14
+ */
15
+
16
+ import type { ChatUserIdentity } from './chat-user-identity.js';
17
+ import type { ConnectorIdentityModule } from './connector-identity-module.js';
18
+
19
+ /** Connector-owned identity namespaces (not SDK-global). */
20
+ export const GOOGLE_IDENTITY = {
21
+ /**
22
+ * The Google account id (the OIDC `sub`), bare and unscoped. Unlike Slack's
23
+ * `T…:U…`, this needs no tenant prefix: Google account ids are unique across
24
+ * all of Google, so there is no second workspace that can mint the same id.
25
+ */
26
+ USER_ID: 'google_user_id',
27
+ } as const;
28
+
29
+ export type GoogleIdentityNamespace =
30
+ (typeof GOOGLE_IDENTITY)[keyof typeof GOOGLE_IDENTITY];
31
+
32
+ /** Google Chat addresses a person as `users/{id}`; the stored key is bare. */
33
+ const GCHAT_USER_PREFIX = 'users/';
34
+
35
+ /**
36
+ * Canonicalize a Google account id to its bare numeric form, accepting either
37
+ * the raw ~21-digit id as the OIDC `sub` delivers it, or the Google Chat
38
+ * resource name that wraps the same digits as `users/<id>`.
39
+ *
40
+ * Digits only, deliberately, and that rule is load-bearing rather than mere
41
+ * hygiene. Not every stored Google OAuth account is a sign-in: a Google
42
+ * CONNECTOR grant (drive/gmail/calendar) writes one too, under a synthetic
43
+ * account id such as `connect_<n>_<n>` or `lobu-connector:<org>:google.drive:<id>`.
44
+ * A connector authorization is a different consent from proving who you are, so
45
+ * it must not mint a chat identity — and some of those grants DO request
46
+ * `openid`, so a scope check would not separate them. The numeric rule does.
47
+ *
48
+ * It also refuses a Chat app id, a service-account resource name, an id from
49
+ * another platform, and an empty string. Returns null when the value is not a
50
+ * bare Google account id.
51
+ */
52
+ export function normalizeGoogleUserId(
53
+ raw: string | null | undefined,
54
+ ): string | null {
55
+ if (typeof raw !== 'string') return null;
56
+ const trimmed = raw.trim();
57
+ if (!trimmed) return null;
58
+ const bare = trimmed.startsWith(GCHAT_USER_PREFIX)
59
+ ? trimmed.slice(GCHAT_USER_PREFIX.length)
60
+ : trimmed;
61
+ // Bounded length: a Google account id is ~21 digits. The cap keeps an
62
+ // unbounded string out of an indexed identity column.
63
+ return /^[0-9]{1,32}$/.test(bare) ? bare : null;
64
+ }
65
+
66
+ /**
67
+ * Normalize a Google identity namespace value. Returns `undefined` when the
68
+ * namespace is not Google-owned (caller should fall back to generic hygiene).
69
+ */
70
+ export function normalizeGoogleIdentityValue(
71
+ namespace: string,
72
+ raw: string,
73
+ ): string | null | undefined {
74
+ switch (namespace) {
75
+ case GOOGLE_IDENTITY.USER_ID:
76
+ return normalizeGoogleUserId(raw);
77
+ default:
78
+ return undefined;
79
+ }
80
+ }
81
+
82
+ /** The Google connector's contribution to the server identity wiring. */
83
+ export const googleIdentityModule: ConnectorIdentityModule = {
84
+ key: 'google',
85
+ // Not recall-indexed: `google_user_id` links a signer to a chat sender, it is
86
+ // not an event-recall key, so it ships no `idx_events_metadata_*` index.
87
+ recallNamespaces: [],
88
+ normalize: normalizeGoogleIdentityValue,
89
+ };
90
+
91
+ /**
92
+ * Google Chat's sender-identity model: a `gchat` message's sender is keyed by
93
+ * the bare Google account id, which a `google` sign-in proves.
94
+ *
95
+ * `teamId` is ignored on purpose. Slack needs it because two workspaces can
96
+ * both contain `U12345`; Google cannot produce two accounts with one id, so
97
+ * there is nothing to scope by and no cross-tenant bleed to prevent. Inbound
98
+ * Google Chat events carry no workspace id anyway.
99
+ */
100
+ export const gchatChatUserIdentity: ChatUserIdentity = {
101
+ platform: 'gchat',
102
+ providerId: 'google',
103
+ namespace: GOOGLE_IDENTITY.USER_ID,
104
+ buildUserKey(_teamId, platformUserId) {
105
+ return normalizeGoogleUserId(platformUserId);
106
+ },
107
+ };
@@ -21,6 +21,12 @@
21
21
  */
22
22
 
23
23
  import {
24
+ downloadSizeError,
25
+ fileDownloadOutput,
26
+ inlineContentBudget,
27
+ inlineMaxBytesSchema,
28
+ inlineText,
29
+ isTextualMimeType,
24
30
  type ActionContext,
25
31
  type ActionResult,
26
32
  ConnectorRuntime,
@@ -129,18 +135,6 @@ const EXPORT_MIME_TYPES: Record<string, string> = {
129
135
  'application/vnd.google-apps.script': 'application/vnd.google-apps.script+json',
130
136
  };
131
137
 
132
- /** MIME types we will inline as `payload_text` when they are not Google-native. */
133
- const TEXTUAL_MIME_TYPES = new Set([
134
- 'application/json',
135
- 'application/xml',
136
- 'application/x-yaml',
137
- 'application/yaml',
138
- 'application/javascript',
139
- 'application/typescript',
140
- 'application/sql',
141
- 'application/x-sh',
142
- ]);
143
-
144
138
  /**
145
139
  * Cap on text inlined into `payload_text`.
146
140
  *
@@ -151,18 +145,6 @@ const TEXTUAL_MIME_TYPES = new Set([
151
145
  */
152
146
  const MAX_INLINE_TEXT_BYTES = 256 * 1024;
153
147
 
154
- /**
155
- * Default and ceiling for the text `download_file` echoes back inline.
156
- *
157
- * Inlining is a convenience for the caller that wants to READ a small file
158
- * without a second fetch through the artifact's `download_url`. It is not the
159
- * transport: the attachment is published either way. The ceiling exists because
160
- * inline content lands in an agent's context verbatim, where a multi-megabyte
161
- * blob is worse than useless — the `download_url` is the path for anything big.
162
- */
163
- const DEFAULT_INLINE_CONTENT_BYTES = 256 * 1024;
164
- const MAX_INLINE_CONTENT_BYTES = 1024 * 1024;
165
-
166
148
  /**
167
149
  * Grace window subtracted from `last_sync_at` before deciding a file's content
168
150
  * is unchanged.
@@ -175,13 +157,6 @@ const MAX_INLINE_CONTENT_BYTES = 1024 * 1024;
175
157
  */
176
158
  const CONTENT_SKEW_GRACE_MS = 5 * 60 * 1000;
177
159
 
178
- /**
179
- * Ceiling on anything this connector pulls in one piece — Google's own hard cap
180
- * on `files.export` (requesting more returns a 403), reused as the `alt=media`
181
- * download ceiling so both content paths refuse at the same size.
182
- */
183
- const MAX_EXPORT_BYTES = 10 * 1024 * 1024;
184
-
185
160
  /** Field mask for files.list / changes.list. Drive v3 returns almost nothing without it. */
186
161
  const FILE_FIELDS =
187
162
  'id,name,mimeType,description,webViewLink,size,createdTime,modifiedTime,trashed,owners(emailAddress,displayName),lastModifyingUser(emailAddress,displayName),parents';
@@ -220,51 +195,6 @@ function isPageTokenRejection(status: number): boolean {
220
195
  return status === 404 || status === 410;
221
196
  }
222
197
 
223
- /**
224
- * Truncate encoded UTF-8 to at most `maxBytes` WITHOUT splitting a character.
225
- *
226
- * A plain `slice(0, maxBytes)` can cut mid-sequence, and the decoder turns the
227
- * orphaned bytes into U+FFFD — a garbage character that then gets stored and
228
- * embedded. Back off up to three bytes (the longest UTF-8 tail) until the slice
229
- * decodes cleanly, so a legitimate U+FFFD already in the source is preserved
230
- * while a manufactured one is impossible.
231
- */
232
- function decodeTruncated(encoded: Uint8Array, maxBytes: number): string {
233
- const strict = new TextDecoder('utf-8', { fatal: true });
234
- for (let end = maxBytes; end > maxBytes - 4 && end >= 0; end--) {
235
- try {
236
- return strict.decode(encoded.slice(0, end));
237
- } catch {
238
- // Slice ended mid-sequence — drop a byte and retry.
239
- }
240
- }
241
- // Unreachable: `encoded` always comes from TextEncoder, so one of the four
242
- // slices above lands on a character boundary. Returning lossily here would
243
- // manufacture the very U+FFFD this function exists to prevent.
244
- return '';
245
- }
246
-
247
- /**
248
- * Decode downloaded bytes as text and cut them to the inline budget.
249
- *
250
- * The decode comes FIRST because `decodeTruncated` requires well-formed UTF-8
251
- * (it hands back nothing rather than manufacture a U+FFFD), and a downloaded
252
- * file is not required to be any such thing — a latin-1 CSV would otherwise
253
- * inline as an empty string, the exact "looks like an empty file" outcome this
254
- * connector refuses everywhere else. Decoding lossily once and re-encoding
255
- * gives the truncator the input it documents, and makes a truncated file read
256
- * the same as the first page of an untruncated one.
257
- */
258
- function inlineText(
259
- bytes: Uint8Array,
260
- maxBytes: number
261
- ): { content: string; truncated: boolean } {
262
- const text = new TextDecoder('utf-8').decode(bytes);
263
- const encoded = new TextEncoder().encode(text);
264
- if (encoded.byteLength <= maxBytes) return { content: text, truncated: false };
265
- return { content: decodeTruncated(encoded, maxBytes), truncated: true };
266
- }
267
-
268
198
  function exportMimeTypeFor(mimeType: string | undefined): string | undefined {
269
199
  if (!mimeType) return undefined;
270
200
  return EXPORT_MIME_TYPES[mimeType];
@@ -274,12 +204,6 @@ function isGoogleNative(mimeType: string | undefined): boolean {
274
204
  return Boolean(mimeType?.startsWith('application/vnd.google-apps.'));
275
205
  }
276
206
 
277
- function isTextualMimeType(mimeType: string | undefined): boolean {
278
- if (!mimeType) return false;
279
- const base = mimeType.split(';')[0]!.trim().toLowerCase();
280
- return TEXTUAL_MIME_TYPES.has(base) || base.startsWith('text/');
281
- }
282
-
283
207
  /** Drive reports size as a decimal string, and omits it entirely for native files. */
284
208
  function parseSize(size: string | undefined): number | undefined {
285
209
  if (typeof size !== 'string' || size.length === 0) return undefined;
@@ -476,12 +400,7 @@ export default class GoogleDriveConnector extends ConnectorRuntime<
476
400
  type: 'string',
477
401
  description: 'Drive file ID to download.',
478
402
  },
479
- inline_max_bytes: {
480
- type: 'integer',
481
- minimum: 0,
482
- maximum: MAX_INLINE_CONTENT_BYTES,
483
- description: `Return text content inline when the file is at most this many bytes (default ${DEFAULT_INLINE_CONTENT_BYTES}, max ${MAX_INLINE_CONTENT_BYTES}). Binary files are never inlined. 0 disables inlining; the attachment is still published.`,
484
- },
403
+ inline_max_bytes: inlineMaxBytesSchema(),
485
404
  },
486
405
  },
487
406
  },
@@ -920,13 +839,7 @@ export default class GoogleDriveConnector extends ConnectorRuntime<
920
839
  const fileId = input.file_id as string;
921
840
  if (!fileId) return { success: false, error: 'file_id is required.' };
922
841
 
923
- const requestedInline = input.inline_max_bytes;
924
- const inlineMaxBytes = Math.min(
925
- typeof requestedInline === 'number' && Number.isFinite(requestedInline) && requestedInline >= 0
926
- ? requestedInline
927
- : DEFAULT_INLINE_CONTENT_BYTES,
928
- MAX_INLINE_CONTENT_BYTES
929
- );
842
+ const inlineMaxBytes = inlineContentBudget(input.inline_max_bytes);
930
843
 
931
844
  const file = await this.fetchFileMetadata(http, fileId);
932
845
  if (!file) {
@@ -939,23 +852,6 @@ export default class GoogleDriveConnector extends ConnectorRuntime<
939
852
  }
940
853
 
941
854
  const filename = file.name ?? file.id;
942
- // `kind` is deliberately omitted: the gateway infers it from the media type
943
- // (`inferKindFromMime`), so there is one rule rather than two that can
944
- // disagree about what counts as an image.
945
- const attachment = {
946
- filename,
947
- mime_type: fetched.contentType,
948
- data: fetched.bytes.toString('base64'),
949
- size_bytes: fetched.bytes.length,
950
- };
951
-
952
- // Text is TRUNCATED to the inline budget rather than withheld: an agent
953
- // peeking at a large log or CSV is better served by its first page than by
954
- // being told to go fetch a URL. The attachment always carries the whole
955
- // file, so truncating here loses nothing.
956
- const textual =
957
- fetched.exportedAs !== undefined || isTextualMimeType(file.mimeType);
958
- const inline = inlineMaxBytes > 0 && textual ? inlineText(fetched.bytes, inlineMaxBytes) : undefined;
959
855
 
960
856
  return {
961
857
  success: true,
@@ -964,20 +860,22 @@ export default class GoogleDriveConnector extends ConnectorRuntime<
964
860
  name: filename,
965
861
  mime_type: file.mimeType ?? '',
966
862
  exported_as: fetched.exportedAs,
967
- size_bytes: fetched.bytes.length,
968
- attachments: [attachment],
969
- ...(inline
970
- ? {
971
- content: inline.content,
972
- content_truncated: inline.truncated,
973
- line_count:
974
- inline.content.length === 0 ? 0 : inline.content.split('\n').length,
975
- }
976
- : {
977
- content_omitted_reason: textual
978
- ? 'inlining disabled'
979
- : 'file is binary; fetch it through the attachment download_url',
980
- }),
863
+ ...fileDownloadOutput({
864
+ bytes: fetched.bytes,
865
+ filename,
866
+ mimeType: fetched.contentType,
867
+ inlineMaxBytes,
868
+ // Always decide textuality from Drive's DECLARED `file.mimeType`,
869
+ // never from `fetched.contentType`: the latter is the alt=media
870
+ // response header, which Drive routinely serves as
871
+ // `application/octet-stream` even for a text file. Letting the
872
+ // default rule read `contentType` would silently stop inlining those.
873
+ // An Apps Script exports as `...script+json`, which no generic
874
+ // media-type rule reads as text; the other exports already land on a
875
+ // `text/*` type and need no override.
876
+ textual:
877
+ fetched.exportedAs !== undefined || isTextualMimeType(file.mimeType),
878
+ }),
981
879
  },
982
880
  };
983
881
  }
@@ -1031,19 +929,12 @@ export default class GoogleDriveConnector extends ConnectorRuntime<
1031
929
  const request = this.contentRequest(file);
1032
930
  if (!request.ok) return request;
1033
931
 
1034
- // Refuse before fetching. The isolate buffers the whole body, then base64s
1035
- // it to cross the host boundary at 4/3 the size, so an unbounded download
1036
- // is an out-of-memory kill rather than an error the caller can read.
1037
- // MAX_EXPORT_BYTES sits above the gateway's own attachment cap on purpose:
1038
- // the gateway stays the authority on what is too big to store, and this
1039
- // only stops what cannot physically make the trip.
1040
- const declaredSize = parseSize(file.size);
1041
- if (declaredSize !== undefined && declaredSize > MAX_EXPORT_BYTES) {
1042
- return {
1043
- ok: false,
1044
- error: `File ${file.name ?? file.id} is ${declaredSize} bytes, above the ${MAX_EXPORT_BYTES}-byte download limit.`,
1045
- };
1046
- }
932
+ // Refuse before fetching, so a 2 GB file costs nothing. The shared ceiling
933
+ // (MAX_CONNECTOR_DOWNLOAD_BYTES, rationale there) happens to coincide with
934
+ // Google's own hard cap on `files.export` — requesting more returns a 403 —
935
+ // so both content paths refuse at the size Drive refuses at anyway.
936
+ const declaredTooBig = downloadSizeError(parseSize(file.size), file.name ?? file.id);
937
+ if (declaredTooBig) return { ok: false, error: declaredTooBig };
1047
938
 
1048
939
  const response = await http.raw(request.url);
1049
940
  if (!response.ok) {
@@ -1054,14 +945,10 @@ export default class GoogleDriveConnector extends ConnectorRuntime<
1054
945
  }
1055
946
 
1056
947
  const bytes = Buffer.from(await response.arrayBuffer());
1057
- if (bytes.length > MAX_EXPORT_BYTES) {
1058
- // Drive omits `size` for native docs, so the export path only learns the
1059
- // real size here. Same refusal, after the fact.
1060
- return {
1061
- ok: false,
1062
- error: `File ${file.name ?? file.id} returned ${bytes.length} bytes, above the ${MAX_EXPORT_BYTES}-byte download limit.`,
1063
- };
1064
- }
948
+ // Drive omits `size` for native docs, so the export path only learns the
949
+ // real size here. Same refusal, after the fact.
950
+ const receivedTooBig = downloadSizeError(bytes.length, file.name ?? file.id);
951
+ if (receivedTooBig) return { ok: false, error: receivedTooBig };
1065
952
  if (bytes.length === 0) {
1066
953
  return { ok: false, error: `Drive file ${file.name ?? file.id} is empty.` };
1067
954
  }
@@ -1121,15 +1008,13 @@ export default class GoogleDriveConnector extends ConnectorRuntime<
1121
1008
  }
1122
1009
 
1123
1010
  const raw = await response.text();
1124
- const encoded = new TextEncoder().encode(raw);
1125
- const truncated = encoded.byteLength > maxBytes;
1126
- const text = truncated ? decodeTruncated(encoded, maxBytes) : raw;
1011
+ const { content: text, truncated } = inlineText(raw, maxBytes);
1127
1012
 
1128
1013
  return {
1129
1014
  ok: true,
1130
1015
  text,
1131
1016
  truncated,
1132
- byteCount: encoded.byteLength,
1017
+ byteCount: Buffer.byteLength(raw, 'utf8'),
1133
1018
  ...(exportMime ? { exportedAs: exportMime } : {}),
1134
1019
  };
1135
1020
  }