@lobu/runtime-server 20.2.0 → 21.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 (270) hide show
  1. package/dist/catalogs/automations.json +0 -8
  2. package/dist/component.json +1 -1
  3. package/dist/connectors/README.md +15 -16
  4. package/dist/connectors/github.ts +274 -193
  5. package/dist/connectors/google_calendar.ts +54 -160
  6. package/dist/connectors/google_drive.ts +106 -131
  7. package/dist/connectors/google_gmail.ts +53 -30
  8. package/dist/connectors/hackernews.ts +2 -5
  9. package/dist/connectors/jira.ts +71 -27
  10. package/dist/connectors/linear.ts +55 -21
  11. package/dist/connectors/microsoft_outlook.ts +151 -110
  12. package/dist/connectors/postgres.ts +19 -11
  13. package/dist/connectors/producthunt.ts +11 -7
  14. package/dist/connectors/reddit.ts +36 -6
  15. package/dist/connectors/rss.ts +2 -2
  16. package/dist/connectors/whatsapp_web.ts +5 -4
  17. package/dist/connectors/x.ts +32 -17
  18. package/dist/connectors/youtube.ts +18 -5
  19. package/dist/db/migrations/20260917000000_views.sql +271 -0
  20. package/dist/db/migrations/20260917000001_views_attach_index.sql +14 -0
  21. package/dist/db/migrations/20260918000000_runs_turn_tool_event_uniq.sql +51 -0
  22. package/dist/db/migrations/20260923230000_runs_connector_artifact_hash.sql +32 -0
  23. package/dist/db/migrations/20260924000000_resource_source_files.sql +17 -0
  24. package/dist/db/migrations/20260928120000_classification_consolidation.sql +51 -0
  25. package/dist/dependencies.bun.lock +113 -102
  26. package/dist/guest.bundle.js +78 -10
  27. package/dist/owletto/dist/assets/_-00GgOtdu.js +1 -0
  28. package/dist/owletto/dist/assets/_-XlUwOWCI.js +2 -0
  29. package/dist/owletto/dist/assets/_agentId-B2DrawIk.js +1 -0
  30. package/dist/owletto/dist/assets/_agentId-CS0AcWH2.js +1 -0
  31. package/dist/owletto/dist/assets/_automationId-BLnqLtUv.js +1 -0
  32. package/dist/owletto/dist/assets/{_connectorKey._connectionId-BAJGfcy7.js → _connectorKey._connectionId-DcUWoZ-C.js} +1 -1
  33. package/dist/owletto/dist/assets/{_connectorKey.index-BBF8vGJS.js → _connectorKey.index-C_yKycN_.js} +1 -1
  34. package/dist/owletto/dist/assets/_conversationId-CpuEvflw.js +1 -0
  35. package/dist/owletto/dist/assets/_deploymentId-BL9tnDFl.js +1 -0
  36. package/dist/owletto/dist/assets/_name-DlxjWkKk.js +1 -0
  37. package/dist/owletto/dist/assets/_owner-Cg50UU6m.js +1 -0
  38. package/dist/owletto/dist/assets/_shape-BWZW4mj8.js +1 -0
  39. package/dist/owletto/dist/assets/_skillKey-B25fO0_O.js +1 -0
  40. package/dist/owletto/dist/assets/_slug-DbD-wv2m.js +1 -0
  41. package/dist/owletto/dist/assets/_viewKey-BcTEvQ3N.js +1 -0
  42. package/dist/owletto/dist/assets/_viewKey-W4RjiUWL.js +1 -0
  43. package/dist/owletto/dist/assets/_viewKey-iGPCKSda.js +1 -0
  44. package/dist/owletto/dist/assets/accept-invitation-BmQKbQem.js +1 -0
  45. package/dist/owletto/dist/assets/activity-route-view-BvtAoGVt.js +1 -0
  46. package/dist/owletto/dist/assets/{agent-card-controls-CZO6GI0s.js → agent-card-controls-bhTMPoVi.js} +1 -1
  47. package/dist/owletto/dist/assets/{agent-client-setup-list-_chLOorY.js → agent-client-setup-list-BBbq_2B1.js} +1 -1
  48. package/dist/owletto/dist/assets/{agent-connect-pages-DWBgSIYT.js → agent-connect-pages-DkDlFVY5.js} +1 -1
  49. package/dist/owletto/dist/assets/{agent-editor-form-BTNlg0kQ.js → agent-editor-form-DwHD9j1Y.js} +1 -1
  50. package/dist/owletto/dist/assets/{agent-guardrails-route-B5uoMC6o.js → agent-guardrails-route-0PsTrqMC.js} +1 -1
  51. package/dist/owletto/dist/assets/{agent-loading-shells-CLoLeFcB.js → agent-loading-shells-BQLjzMPy.js} +1 -1
  52. package/dist/owletto/dist/assets/{agent-permissions-matrix-TP00-MYL.js → agent-permissions-matrix-B-Q5rmuB.js} +1 -1
  53. package/dist/owletto/dist/assets/{agent-skill-context-D4a2QCoZ.js → agent-skill-context-s42Q4Wjo.js} +1 -1
  54. package/dist/owletto/dist/assets/{agent-skills-route-KVDDTbJB.js → agent-skills-route-Cwq1QrhW.js} +1 -1
  55. package/dist/owletto/dist/assets/{agent-subpage-shell-DuVYZvBE.js → agent-subpage-shell-DtzoRy6N.js} +1 -1
  56. package/dist/owletto/dist/assets/agent-thread-D7AGGjRV.js +8 -0
  57. package/dist/owletto/dist/assets/agents-BqCKU4CT.js +1 -0
  58. package/dist/owletto/dist/assets/agents-workbench-Cl7FO7b3.js +1 -0
  59. package/dist/owletto/dist/assets/app-bridge-BH3g2mKG.js +127 -0
  60. package/dist/owletto/dist/assets/{app._appId-D0_LQTJU.js → app._appId-CqYz3AOO.js} +1 -1
  61. package/dist/owletto/dist/assets/automation-detail-content-CKSywvzE.js +1 -0
  62. package/dist/owletto/dist/assets/automations-BqCKU4CT.js +1 -0
  63. package/dist/owletto/dist/assets/{calendar-C0XpOHd8.js → calendar-CHXehtu0.js} +1 -1
  64. package/dist/owletto/dist/assets/{callback-CO_K9eR-.js → callback-DZ3YyXeV.js} +1 -1
  65. package/dist/owletto/dist/assets/{card-DeFQuU_J.js → card-4Ull9W6d.js} +1 -1
  66. package/dist/owletto/dist/assets/{claim-CUpWOSie.js → claim-BGLCPLXq.js} +1 -1
  67. package/dist/owletto/dist/assets/clients-C7ubnFsS.js +1 -0
  68. package/dist/owletto/dist/assets/{code-editor-BqGUZFt6.js → code-editor-BHiWR94J.js} +1 -1
  69. package/dist/owletto/dist/assets/connect-BNatqg6j.js +1 -0
  70. package/dist/owletto/dist/assets/connect._clientId-BGG2IqiQ.js +1 -0
  71. package/dist/owletto/dist/assets/connected._clientId-7RU89sVW.js +1 -0
  72. package/dist/owletto/dist/assets/{connection-BgAlYjeV.js → connection-CTaUGXl6.js} +1 -1
  73. package/dist/owletto/dist/assets/{connection-feed-detail-B3ePAinf.js → connection-feed-detail-B1xieiEh.js} +1 -1
  74. package/dist/owletto/dist/assets/{connector-provenance-DgsDg0Z9.js → connector-provenance-DRdUEmQ1.js} +1 -1
  75. package/dist/owletto/dist/assets/{connectors-CqPQPo9U.js → connectors-NBwCLuZg.js} +1 -1
  76. package/dist/owletto/dist/assets/{consent-bswcIzsf.js → consent-fmhPPlpi.js} +1 -1
  77. package/dist/owletto/dist/assets/{core.esm-DsLgjoel.js → core.esm-C-eNiUAl.js} +1 -1
  78. package/dist/owletto/dist/assets/{create-Dwo04oWV.js → create-8bBbQJGY.js} +1 -1
  79. package/dist/owletto/dist/assets/create-Cl6cfNAp.js +1 -0
  80. package/dist/owletto/dist/assets/create-DrVso8O7.js +1 -0
  81. package/dist/owletto/dist/assets/create-automation-form-De8J-JD5.js +2 -0
  82. package/dist/owletto/dist/assets/{create._connectorKey-CCBb2pil.js → create._connectorKey-CHAotlsF.js} +1 -1
  83. package/dist/owletto/dist/assets/{cronstrue-ChFyC9ps.js → cronstrue-C5yTgk5z.js} +1 -1
  84. package/dist/owletto/dist/assets/deployments-C7M3fV5K.js +1 -0
  85. package/dist/owletto/dist/assets/deployments-D1gbQwsy.js +1 -0
  86. package/dist/owletto/dist/assets/deployments-body-DycIGlnL.js +1 -0
  87. package/dist/owletto/dist/assets/device-DyPnQkhO.js +1 -0
  88. package/dist/owletto/dist/assets/{device-pin-tombstone-1ikyqSdb.js → device-pin-tombstone-CwJitllC.js} +1 -1
  89. package/dist/owletto/dist/assets/device-rows-BBhW1C7Y.js +1 -0
  90. package/dist/owletto/dist/assets/{device._deviceId-DTYKGBY8.js → device._deviceId-XswfXHOc.js} +1 -1
  91. package/dist/owletto/dist/assets/entity-options-utGBmFX0.js +1 -0
  92. package/dist/owletto/dist/assets/entity-page-BxwuqqWk.js +1 -0
  93. package/dist/owletto/dist/assets/entity-type-page-BrWqk6so.js +1 -0
  94. package/dist/owletto/dist/assets/event-page-LIm4EDmJ.js +1 -0
  95. package/dist/owletto/dist/assets/events-feed-C4L8mQV7.js +1 -0
  96. package/dist/owletto/dist/assets/{full-page-spinner-BN2G_YiM.js → full-page-spinner-DsU-Cb3L.js} +1 -1
  97. package/dist/owletto/dist/assets/guardrails-CGFWCfbQ.js +1 -0
  98. package/dist/owletto/dist/assets/identity-uPYpPogR.js +1 -0
  99. package/dist/owletto/dist/assets/{index-hSE2E46p.js → index-1YrrvVJ4.js} +1 -1
  100. package/dist/owletto/dist/assets/index-BKMafTe4.js +1 -0
  101. package/dist/owletto/dist/assets/index-BsL1-C2-.js +1 -0
  102. package/dist/owletto/dist/assets/index-C58oW727.js +1 -0
  103. package/dist/owletto/dist/assets/index-C8CR2-Ck.css +1 -0
  104. package/dist/owletto/dist/assets/{index-OUb5Mlez.js → index-CDz3-ieP.js} +10 -10
  105. package/dist/owletto/dist/assets/{index-C6VAJ8Ku.js → index-CQ4s6nzy.js} +1 -1
  106. package/dist/owletto/dist/assets/index-CpWKAAGX.js +1 -0
  107. package/dist/owletto/dist/assets/{index-vdqhlocx.js → index-D2dcENg2.js} +1 -1
  108. package/dist/owletto/dist/assets/{index-C2oCgDX7.js → index-DCK0KhMM.js} +1 -1
  109. package/dist/owletto/dist/assets/{index-C-u4yR8Z.js → index-DXqiRON3.js} +1 -1
  110. package/dist/owletto/dist/assets/index-DgEc5IvT.js +1 -0
  111. package/dist/owletto/dist/assets/index-DtRfQcRH.js +7898 -0
  112. package/dist/owletto/dist/assets/index-DvhM9tuI.js +1 -0
  113. package/dist/owletto/dist/assets/index-DwtfHCHB.js +1 -0
  114. package/dist/owletto/dist/assets/index-DyYFZjh-.js +1 -0
  115. package/dist/owletto/dist/assets/index-nOYvNROJ.js +1 -0
  116. package/dist/owletto/dist/assets/index-oDoJENMF.js +1 -0
  117. package/dist/owletto/dist/assets/index-rPdUEOa3.js +1 -0
  118. package/dist/owletto/dist/assets/{json-diff-DnsW7Pin.js → json-diff-DYeX-xLk.js} +2 -2
  119. package/dist/owletto/dist/assets/{list-skeleton-CHzLN7GK.js → list-skeleton-s4GPSJ8J.js} +1 -1
  120. package/dist/owletto/dist/assets/login-Di5VF2F_.js +1 -0
  121. package/dist/owletto/dist/assets/logout-BuaQGSnw.js +1 -0
  122. package/dist/owletto/dist/assets/member-scope-gate-CJqJZk7T.js +1 -0
  123. package/dist/owletto/dist/assets/memory-browse-page-Bibfs2sK.js +101 -0
  124. package/dist/owletto/dist/assets/missing-view-CD4DOaG8.js +1 -0
  125. package/dist/owletto/dist/assets/{model-selector-DfbmHjLu.js → model-selector-XC5CI2Et.js} +1 -1
  126. package/dist/owletto/dist/assets/models--8mTFOLz.js +1 -0
  127. package/dist/owletto/dist/assets/{new-Df_dY6Z5.js → new-BzkA1sq2.js} +1 -1
  128. package/dist/owletto/dist/assets/new-C3f0BShb.js +1 -0
  129. package/dist/owletto/dist/assets/new-DA5LF6iB.js +1 -0
  130. package/dist/owletto/dist/assets/{oauth-workspace-access-D9GmiMfK.js → oauth-workspace-access-D6epOq0R.js} +1 -1
  131. package/dist/owletto/dist/assets/{organization-uSDYkJpX.js → organization-DOtBRqDQ.js} +1 -1
  132. package/dist/owletto/dist/assets/{permissions-Fe0DP6b8.js → permissions-D8uJHINS.js} +1 -1
  133. package/dist/owletto/dist/assets/{proposal-review-shell-D9HwnDda.js → proposal-review-shell-C3K-JXjb.js} +1 -1
  134. package/dist/owletto/dist/assets/{recent-C03LhMD7.js → recent-CFcWceBl.js} +1 -1
  135. package/dist/owletto/dist/assets/{renderer-CHNejd95.js → renderer-1nRJFMGx.js} +2 -2
  136. package/dist/owletto/dist/assets/{reset-password-CuISnlG_.js → reset-password-9RTWhBEb.js} +1 -1
  137. package/dist/owletto/dist/assets/runs-_yVh6PPB.js +1 -0
  138. package/dist/owletto/dist/assets/{runs-panel-DsdESupx.js → runs-panel-B2852xus.js} +1 -1
  139. package/dist/owletto/dist/assets/runs-table--dnFQatY.js +1 -0
  140. package/dist/owletto/dist/assets/{schema-value-normalization-B--OWDL8.js → schema-value-normalization-BspxVEGy.js} +1 -1
  141. package/dist/owletto/dist/assets/{settings-wGNHtsDP.js → settings-9lDASETT.js} +1 -1
  142. package/dist/owletto/dist/assets/settings-DQo_ZS2P.js +1 -0
  143. package/dist/owletto/dist/assets/skills-a5xQ4RE9.js +1 -0
  144. package/dist/owletto/dist/assets/{switch-Dzse_XFM.js → switch-CxDXvPGE.js} +1 -1
  145. package/dist/owletto/dist/assets/use-applied-views-DvMT3wap.js +1 -0
  146. package/dist/owletto/dist/assets/{use-mention-search-uyW1Uwf6.js → use-mention-search-CeTEE3oE.js} +1 -1
  147. package/dist/owletto/dist/assets/view-frame-HoBawpT2.js +1 -0
  148. package/dist/owletto/dist/index.html +2 -2
  149. package/dist/providers.json +0 -1
  150. package/dist/server-main.bundle.mjs +8997 -7479
  151. package/npm-shrinkwrap.json +543 -485
  152. package/package.json +5 -2
  153. package/vendor/connector-sdk/dist/connector-runtime.d.ts +4 -6
  154. package/vendor/connector-sdk/dist/connector-runtime.js +3 -5
  155. package/vendor/connector-sdk/dist/connector-types.d.ts +28 -15
  156. package/vendor/connector-sdk/dist/define-connector.d.ts +4 -1
  157. package/vendor/connector-sdk/dist/define-connector.js +4 -1
  158. package/vendor/connector-sdk/dist/http-client.d.ts +18 -7
  159. package/vendor/connector-sdk/dist/http-client.js +15 -13
  160. package/vendor/connector-sdk/dist/index.d.ts +1 -1
  161. package/vendor/connector-sdk/dist/retry.d.ts +15 -3
  162. package/vendor/connector-sdk/dist/retry.js +40 -64
  163. package/vendor/connector-sdk/package.json +1 -1
  164. package/vendor/core/dist/agent-policy.js +3 -0
  165. package/vendor/core/dist/connector-query-errors.d.ts +3 -3
  166. package/vendor/core/dist/connector-query-errors.js +8 -3
  167. package/vendor/core/dist/contracts/tools/manage-auth-profiles.d.ts +14 -0
  168. package/vendor/core/dist/contracts/tools/manage-auth-profiles.js +12 -1
  169. package/vendor/core/dist/contracts/tools/manage-automations.d.ts +0 -10
  170. package/vendor/core/dist/contracts/tools/manage-automations.js +0 -33
  171. package/vendor/core/dist/contracts/tools/manage-classifiers.d.ts +4 -34
  172. package/vendor/core/dist/contracts/tools/manage-classifiers.js +13 -44
  173. package/vendor/core/dist/contracts/tools/manage-connections.d.ts +24 -0
  174. package/vendor/core/dist/contracts/tools/manage-connections.js +13 -0
  175. package/vendor/core/dist/contracts/tools/manage-entity-schema.d.ts +15 -25
  176. package/vendor/core/dist/contracts/tools/manage-entity-schema.js +3 -5
  177. package/vendor/core/dist/contracts/tools/manage-entity.d.ts +0 -9
  178. package/vendor/core/dist/contracts/tools/manage-entity.js +0 -6
  179. package/vendor/core/dist/contracts/tools/manage-feeds.d.ts +11 -0
  180. package/vendor/core/dist/contracts/tools/manage-feeds.js +12 -1
  181. package/vendor/core/dist/contracts/tools/manage-operations.d.ts +47 -6
  182. package/vendor/core/dist/contracts/tools/manage-operations.js +36 -1
  183. package/vendor/core/dist/contracts/tools/manage-views.d.ts +293 -0
  184. package/vendor/core/dist/contracts/tools/manage-views.js +203 -0
  185. package/vendor/core/dist/contracts/tools/source-files-schema.d.ts +7 -0
  186. package/vendor/core/dist/contracts/tools/source-files-schema.js +19 -0
  187. package/vendor/core/dist/contracts/tools/source-files.d.ts +14 -0
  188. package/vendor/core/dist/contracts/tools/source-files.js +55 -0
  189. package/vendor/core/dist/contracts/tools/view-attach.d.ts +20 -0
  190. package/vendor/core/dist/contracts/tools/view-attach.js +45 -0
  191. package/vendor/core/dist/contracts/tools/view-content-hash.d.ts +37 -0
  192. package/vendor/core/dist/contracts/tools/view-content-hash.js +58 -0
  193. package/vendor/core/dist/contracts/tools/view-path.d.ts +18 -0
  194. package/vendor/core/dist/contracts/tools/view-path.js +24 -0
  195. package/vendor/core/dist/contracts/worker/protocol.d.ts +90 -8
  196. package/vendor/core/dist/contracts/worker/protocol.js +70 -10
  197. package/vendor/core/dist/index.d.ts +1 -1
  198. package/vendor/core/dist/provider-config-types.d.ts +0 -9
  199. package/vendor/core/dist/reserved.d.ts +3 -3
  200. package/vendor/core/dist/reserved.js +9 -1
  201. package/vendor/core/dist/sdk-compat.d.ts +1 -1
  202. package/vendor/core/dist/utils/secret-redaction.js +2 -0
  203. package/vendor/core/package.json +30 -5
  204. package/vendor/views/dist/api.d.ts +184 -0
  205. package/vendor/views/dist/api.js +410 -0
  206. package/vendor/views/dist/bridge.d.ts +141 -0
  207. package/vendor/views/dist/bridge.js +330 -0
  208. package/vendor/views/dist/index.d.ts +12 -0
  209. package/vendor/views/dist/index.js +10 -0
  210. package/vendor/views/package.json +35 -0
  211. package/dist/owletto/dist/assets/_-Ds4DyQjj.js +0 -2
  212. package/dist/owletto/dist/assets/_-VmyR6aN_.js +0 -1
  213. package/dist/owletto/dist/assets/_agentId-BAVnp0c7.js +0 -1
  214. package/dist/owletto/dist/assets/_agentId-Df-3rGi5.js +0 -1
  215. package/dist/owletto/dist/assets/_automationId-D696vOjd.js +0 -1
  216. package/dist/owletto/dist/assets/_conversationId-Ci4rgrHm.js +0 -1
  217. package/dist/owletto/dist/assets/_deploymentId-Iy-D5PDq.js +0 -1
  218. package/dist/owletto/dist/assets/_name-CeGwb0oK.js +0 -1
  219. package/dist/owletto/dist/assets/_owner-CFR1G8OX.js +0 -1
  220. package/dist/owletto/dist/assets/_skillKey-DuLcQWBu.js +0 -1
  221. package/dist/owletto/dist/assets/_slug-CDSO20ac.js +0 -1
  222. package/dist/owletto/dist/assets/accept-invitation-Db5jklHT.js +0 -1
  223. package/dist/owletto/dist/assets/activity-route-view-DVW3DoB7.js +0 -1
  224. package/dist/owletto/dist/assets/agent-thread-CzCJU3-R.js +0 -134
  225. package/dist/owletto/dist/assets/agents-DFs57C3c.js +0 -1
  226. package/dist/owletto/dist/assets/agents-workbench-C2bUlJP2.js +0 -1
  227. package/dist/owletto/dist/assets/automation-detail-content-DWkdhnv2.js +0 -1
  228. package/dist/owletto/dist/assets/automations-DFs57C3c.js +0 -1
  229. package/dist/owletto/dist/assets/clients-DhYr4lyL.js +0 -1
  230. package/dist/owletto/dist/assets/connect-Dtb-E5An.js +0 -1
  231. package/dist/owletto/dist/assets/connect._clientId-DWtceAAw.js +0 -1
  232. package/dist/owletto/dist/assets/connected._clientId-CMe-wTuV.js +0 -1
  233. package/dist/owletto/dist/assets/create-CcXUdke7.js +0 -1
  234. package/dist/owletto/dist/assets/create-Cp6hMoeU.js +0 -1
  235. package/dist/owletto/dist/assets/create-automation-form-CJ4meayB.js +0 -1
  236. package/dist/owletto/dist/assets/deployments-CjfFxyDA.js +0 -1
  237. package/dist/owletto/dist/assets/deployments-body-Cg0KiWGr.js +0 -1
  238. package/dist/owletto/dist/assets/device-DpY67Jaj.js +0 -1
  239. package/dist/owletto/dist/assets/device-rows-Cp3yMcuV.js +0 -1
  240. package/dist/owletto/dist/assets/entity-options-1EaSGMX4.js +0 -1
  241. package/dist/owletto/dist/assets/entity-page-DJmM70dv.js +0 -1
  242. package/dist/owletto/dist/assets/entity-type-page-C3mT7tXn.js +0 -1
  243. package/dist/owletto/dist/assets/events-feed-iliGfjit.js +0 -1
  244. package/dist/owletto/dist/assets/guardrails-CLlnRRy9.js +0 -1
  245. package/dist/owletto/dist/assets/identity-MSLryUi8.js +0 -1
  246. package/dist/owletto/dist/assets/index-3o4Eepb4.js +0 -1
  247. package/dist/owletto/dist/assets/index-BUr8321-.js +0 -7898
  248. package/dist/owletto/dist/assets/index-Bulu5ldM.js +0 -1
  249. package/dist/owletto/dist/assets/index-BvbfITqH.js +0 -1
  250. package/dist/owletto/dist/assets/index-ChcQMdod.css +0 -1
  251. package/dist/owletto/dist/assets/index-Clw9ZBj-.js +0 -1
  252. package/dist/owletto/dist/assets/index-D2oL4Ydo.js +0 -1
  253. package/dist/owletto/dist/assets/index-D7wulT4y.js +0 -1
  254. package/dist/owletto/dist/assets/index-DOLFe19K.js +0 -1
  255. package/dist/owletto/dist/assets/index-DTSA0Xh1.js +0 -1
  256. package/dist/owletto/dist/assets/index-DxXXVPU0.js +0 -1
  257. package/dist/owletto/dist/assets/index-nzvsA3hT.js +0 -1
  258. package/dist/owletto/dist/assets/login-CCKNM0gV.js +0 -1
  259. package/dist/owletto/dist/assets/logout-B-N2aodZ.js +0 -1
  260. package/dist/owletto/dist/assets/member-scope-gate-B560Wg-t.js +0 -1
  261. package/dist/owletto/dist/assets/memory-browse-page-DMDqKJn7.js +0 -101
  262. package/dist/owletto/dist/assets/models-M51OGDRE.js +0 -1
  263. package/dist/owletto/dist/assets/new-BVQS9H-Y.js +0 -1
  264. package/dist/owletto/dist/assets/new-DxDVE9nL.js +0 -1
  265. package/dist/owletto/dist/assets/runs-BnYdToDc.js +0 -1
  266. package/dist/owletto/dist/assets/runs-table-B7jKuILd.js +0 -1
  267. package/dist/owletto/dist/assets/settings-Bg9yCCoN.js +0 -1
  268. package/dist/owletto/dist/assets/skills-CN5Ube7A.js +0 -1
  269. package/vendor/core/dist/contracts/tools/manage-view-templates.d.ts +0 -165
  270. package/vendor/core/dist/contracts/tools/manage-view-templates.js +0 -130
@@ -47,6 +47,13 @@ import {
47
47
  type SyncContext,
48
48
  type SyncResult,
49
49
  } from "@lobu/connector-sdk";
50
+
51
+ /** What one X sync gathers before it is committed. */
52
+ type XSyncPage = {
53
+ events: EventEnvelope[];
54
+ checkpoint: Record<string, unknown>;
55
+ metadata?: SyncResult["metadata"];
56
+ };
50
57
  import { X_IDENTITY, normalizeXHandle } from "./x-identity.js";
51
58
 
52
59
  /** OAuth scopes needed per feed for the API path (not used to pause browser-capable feeds). */
@@ -1061,7 +1068,7 @@ export function finalizeDmSyncResult(
1061
1068
  messages: XDmMessage[],
1062
1069
  checkpoint: XCheckpoint,
1063
1070
  metadata: Record<string, unknown>,
1064
- ): SyncResult {
1071
+ ): XSyncPage {
1065
1072
  const seenIds = new Set<string>();
1066
1073
  const deduped = messages.filter((message) => {
1067
1074
  if (!message.id || !message.text || seenIds.has(message.id)) return false;
@@ -1104,7 +1111,7 @@ export function finalizeSyncResult(
1104
1111
  checkpoint: XCheckpoint,
1105
1112
  metadata: Record<string, unknown>,
1106
1113
  options?: { originType?: string },
1107
- ): SyncResult {
1114
+ ): XSyncPage {
1108
1115
  const seenIds = new Set<string>();
1109
1116
  const deduped = tweets.filter((tweet) => {
1110
1117
  if (!tweet.id || !tweet.text || seenIds.has(tweet.id)) return false;
@@ -1151,7 +1158,7 @@ export function finalizeLikedTweetsResult(
1151
1158
  pagesRead: number;
1152
1159
  historicalItemsRead: number;
1153
1160
  },
1154
- ): SyncResult {
1161
+ ): XSyncPage {
1155
1162
  // A browser backfill intentionally re-observes the newest page on every run.
1156
1163
  // Do not drop the old boundary: deterministic origin ids let ingestion update
1157
1164
  // metrics/media without creating a second canonical event.
@@ -1498,7 +1505,7 @@ function shouldFallbackToExtension(error: unknown): boolean {
1498
1505
  return isOAuthScopeOrAuthError(error) || isOAuthLookupFallbackError(error);
1499
1506
  }
1500
1507
 
1501
- async function syncWithOAuthFallback<T extends SyncResult>(
1508
+ async function syncWithOAuthFallback<T extends XSyncPage>(
1502
1509
  oauthFn: () => Promise<T>,
1503
1510
  extensionFn: () => Promise<T>,
1504
1511
  ): Promise<T> {
@@ -1511,7 +1518,7 @@ async function syncWithOAuthFallback<T extends SyncResult>(
1511
1518
  }
1512
1519
 
1513
1520
  /** Browser-first feeds fall back to the extension unless `use_oauth` is set. */
1514
- async function syncOAuthWithOptionalFallback<T extends SyncResult>(
1521
+ async function syncOAuthWithOptionalFallback<T extends XSyncPage>(
1515
1522
  config: Record<string, unknown>,
1516
1523
  oauthFn: () => Promise<T>,
1517
1524
  extensionFn: () => Promise<T>,
@@ -1774,7 +1781,7 @@ async function syncViaOAuthApi(
1774
1781
  ctx: SyncContext,
1775
1782
  config: Record<string, unknown>,
1776
1783
  checkpoint: XCheckpoint,
1777
- ): Promise<SyncResult> {
1784
+ ): Promise<XSyncPage> {
1778
1785
  const accessToken = ctx.credentials?.accessToken;
1779
1786
  if (!accessToken) {
1780
1787
  throw new Error("OAuth access token missing for X connector");
@@ -1876,7 +1883,7 @@ async function syncViaExtension(args: {
1876
1883
  /** Extra metadata to fold into the result (e.g. which timeline tab). */
1877
1884
  metadata?: Record<string, unknown>;
1878
1885
  originType?: string;
1879
- }): Promise<SyncResult> {
1886
+ }): Promise<XSyncPage> {
1880
1887
  const { ctx, url, interceptPatterns, parseResponse, maxScrolls, checkpoint } =
1881
1888
  args;
1882
1889
  const result = await extensionNetworkSync<XTweet>({
@@ -1909,7 +1916,7 @@ async function syncSearchViaExtension(
1909
1916
  ctx: SyncContext,
1910
1917
  config: Record<string, unknown>,
1911
1918
  checkpoint: XCheckpoint,
1912
- ): Promise<SyncResult> {
1919
+ ): Promise<XSyncPage> {
1913
1920
  const searchQuery = buildSearchQuery(config);
1914
1921
  const maxScrolls = readMaxPages(config);
1915
1922
  const searchFilter = (config.search_filter as string) ?? "live";
@@ -1930,7 +1937,7 @@ async function syncMyTweetsViaOAuthApi(
1930
1937
  ctx: SyncContext,
1931
1938
  config: Record<string, unknown>,
1932
1939
  checkpoint: XCheckpoint,
1933
- ): Promise<SyncResult> {
1940
+ ): Promise<XSyncPage> {
1934
1941
  const accessToken = ctx.credentials?.accessToken;
1935
1942
  if (!accessToken) {
1936
1943
  throw new Error("OAuth access token missing for my_tweets feed");
@@ -1977,7 +1984,7 @@ async function syncMyTweetsViaExtension(
1977
1984
  ctx: SyncContext,
1978
1985
  config: Record<string, unknown>,
1979
1986
  checkpoint: XCheckpoint,
1980
- ): Promise<SyncResult> {
1987
+ ): Promise<XSyncPage> {
1981
1988
  const accountHandle = await resolveAccountHandle(config);
1982
1989
  const maxScrolls = readMaxPages(config);
1983
1990
  const profileUrl = `https://x.com/${encodeURIComponent(accountHandle)}`;
@@ -1997,7 +2004,7 @@ async function syncLikedTweetsViaExtension(
1997
2004
  ctx: SyncContext,
1998
2005
  config: Record<string, unknown>,
1999
2006
  checkpoint: XCheckpoint,
2000
- ): Promise<SyncResult> {
2007
+ ): Promise<XSyncPage> {
2001
2008
  const accountHandle = await resolveAccountHandle(config);
2002
2009
  const likesUrl = `https://x.com/${encodeURIComponent(accountHandle)}/likes`;
2003
2010
  const dispatcher = requireExtensionDispatcher(ctx);
@@ -2130,7 +2137,7 @@ async function syncLikedTweetsViaOAuthApi(
2130
2137
  ctx: SyncContext,
2131
2138
  config: Record<string, unknown>,
2132
2139
  checkpoint: XCheckpoint,
2133
- ): Promise<SyncResult> {
2140
+ ): Promise<XSyncPage> {
2134
2141
  const accessToken = ctx.credentials?.accessToken;
2135
2142
  if (!accessToken) {
2136
2143
  throw new Error("OAuth access token missing for liked_tweets feed");
@@ -2201,7 +2208,7 @@ async function syncBookmarksViaOAuthApi(
2201
2208
  ctx: SyncContext,
2202
2209
  config: Record<string, unknown>,
2203
2210
  checkpoint: XCheckpoint,
2204
- ): Promise<SyncResult> {
2211
+ ): Promise<XSyncPage> {
2205
2212
  const accessToken = ctx.credentials?.accessToken;
2206
2213
  if (!accessToken) {
2207
2214
  throw new Error("OAuth access token missing for bookmarks feed");
@@ -2240,7 +2247,7 @@ async function syncBookmarksViaExtension(
2240
2247
  ctx: SyncContext,
2241
2248
  config: Record<string, unknown>,
2242
2249
  checkpoint: XCheckpoint,
2243
- ): Promise<SyncResult> {
2250
+ ): Promise<XSyncPage> {
2244
2251
  const maxScrolls = readMaxPages(config);
2245
2252
 
2246
2253
  return syncViaExtension({
@@ -2278,7 +2285,7 @@ async function syncDirectMessagesViaOAuthApi(
2278
2285
  ctx: SyncContext,
2279
2286
  config: Record<string, unknown>,
2280
2287
  checkpoint: XCheckpoint,
2281
- ): Promise<SyncResult> {
2288
+ ): Promise<XSyncPage> {
2282
2289
  const accessToken = ctx.credentials?.accessToken;
2283
2290
  if (!accessToken) {
2284
2291
  throw new Error(
@@ -2332,7 +2339,7 @@ async function syncDirectMessagesViaExtension(
2332
2339
  ctx: SyncContext,
2333
2340
  config: Record<string, unknown>,
2334
2341
  checkpoint: XCheckpoint,
2335
- ): Promise<SyncResult> {
2342
+ ): Promise<XSyncPage> {
2336
2343
  const maxScrolls = readMaxPages(config);
2337
2344
  let authUserId =
2338
2345
  typeof config.account_user_id === "string"
@@ -2378,7 +2385,7 @@ async function syncHomeFeedViaDomScrape(
2378
2385
  ctx: SyncContext,
2379
2386
  config: Record<string, unknown>,
2380
2387
  checkpoint: XCheckpoint,
2381
- ): Promise<SyncResult> {
2388
+ ): Promise<XSyncPage> {
2382
2389
  const maxScrolls = readScrollBudget(config, { defaultMax: 10, cap: 30 });
2383
2390
  const { items: rows, loggedIn } = await extensionDomScrape<HomeFeedRow>({
2384
2391
  dispatcher: requireExtensionDispatcher(ctx),
@@ -3343,6 +3350,14 @@ export default class XConnector extends ConnectorRuntime {
3343
3350
  }
3344
3351
 
3345
3352
  private async syncFeed(ctx: SyncContext): Promise<SyncResult> {
3353
+ // Collected whole, then committed once: an OAuth attempt that fails part
3354
+ // way falls back to the extension, and nothing it gathered may land first.
3355
+ const page = await this.collectFeed(ctx);
3356
+ await ctx.commit(page.events, page.checkpoint);
3357
+ return { status: "complete", ...(page.metadata ? { metadata: page.metadata } : {}) };
3358
+ }
3359
+
3360
+ private async collectFeed(ctx: SyncContext): Promise<XSyncPage> {
3346
3361
  const config = ctx.config as Record<string, unknown>;
3347
3362
  const checkpoint = (ctx.checkpoint ?? {}) as XCheckpoint;
3348
3363
  const feedKey = ctx.feedKey ?? "tweets";
@@ -31,6 +31,13 @@ import {
31
31
  type SyncResult,
32
32
  } from '@lobu/connector-sdk';
33
33
 
34
+ /** What one YouTube sync gathers before it is committed. */
35
+ type YouTubeSyncPage = {
36
+ events: EventEnvelope[];
37
+ checkpoint: Record<string, unknown>;
38
+ metadata?: SyncResult['metadata'];
39
+ };
40
+
34
41
  // ---------------------------------------------------------------------------
35
42
  // YouTube API types
36
43
  // ---------------------------------------------------------------------------
@@ -613,6 +620,12 @@ export default class YouTubeConnector extends ConnectorRuntime {
613
620
  // -------------------------------------------------------------------------
614
621
 
615
622
  private async syncFeed(ctx: SyncContext): Promise<SyncResult> {
623
+ const page = await this.collectFeed(ctx);
624
+ await ctx.commit(page.events, page.checkpoint);
625
+ return { status: 'complete', ...(page.metadata ? { metadata: page.metadata } : {}) };
626
+ }
627
+
628
+ private async collectFeed(ctx: SyncContext): Promise<YouTubeSyncPage> {
616
629
  const auth = this.resolveAuth(ctx);
617
630
 
618
631
  switch (ctx.feedKey) {
@@ -800,7 +813,7 @@ export default class YouTubeConnector extends ConnectorRuntime {
800
813
  // Feed: liked_videos
801
814
  // -------------------------------------------------------------------------
802
815
 
803
- private async syncLikedVideos(ctx: SyncContext, auth: YouTubeAuth): Promise<SyncResult> {
816
+ private async syncLikedVideos(ctx: SyncContext, auth: YouTubeAuth): Promise<YouTubeSyncPage> {
804
817
  this.requireOAuth(auth, 'liked_videos');
805
818
  const maxResults = Math.min(Math.max((ctx.config.max_results as number) ?? 500, 1), 5000);
806
819
  const likesPlaylistId = await this.fetchLikesPlaylistId(auth);
@@ -820,7 +833,7 @@ export default class YouTubeConnector extends ConnectorRuntime {
820
833
  // Feed: playlists
821
834
  // -------------------------------------------------------------------------
822
835
 
823
- private async syncPlaylists(ctx: SyncContext, auth: YouTubeAuth): Promise<SyncResult> {
836
+ private async syncPlaylists(ctx: SyncContext, auth: YouTubeAuth): Promise<YouTubeSyncPage> {
824
837
  this.requireOAuth(auth, 'playlists');
825
838
  const maxPlaylists = Math.min(Math.max((ctx.config.max_playlists as number) ?? 100, 1), 500);
826
839
  const includeItems = (ctx.config.include_items as boolean) ?? true;
@@ -894,7 +907,7 @@ export default class YouTubeConnector extends ConnectorRuntime {
894
907
  // Feed: subscriptions
895
908
  // -------------------------------------------------------------------------
896
909
 
897
- private async syncSubscriptions(ctx: SyncContext, auth: YouTubeAuth): Promise<SyncResult> {
910
+ private async syncSubscriptions(ctx: SyncContext, auth: YouTubeAuth): Promise<YouTubeSyncPage> {
898
911
  this.requireOAuth(auth, 'subscriptions');
899
912
  const maxResults = Math.min(Math.max((ctx.config.max_results as number) ?? 1000, 1), 5000);
900
913
  const events: EventEnvelope[] = [];
@@ -964,7 +977,7 @@ export default class YouTubeConnector extends ConnectorRuntime {
964
977
  // Feed: videos (keyword search)
965
978
  // -------------------------------------------------------------------------
966
979
 
967
- private async syncSearchVideos(ctx: SyncContext, auth: YouTubeAuth): Promise<SyncResult> {
980
+ private async syncSearchVideos(ctx: SyncContext, auth: YouTubeAuth): Promise<YouTubeSyncPage> {
968
981
  const searchQuery = ctx.config.search_query as string;
969
982
  if (!searchQuery) {
970
983
  throw new Error('search_query is required.');
@@ -1250,7 +1263,7 @@ export default class YouTubeConnector extends ConnectorRuntime {
1250
1263
  return events;
1251
1264
  }
1252
1265
 
1253
- private buildListCheckpointResult(events: EventEnvelope[]): SyncResult {
1266
+ private buildListCheckpointResult(events: EventEnvelope[]): YouTubeSyncPage {
1254
1267
  events.sort((a, b) => b.occurred_at.getTime() - a.occurred_at.getTime());
1255
1268
  const latest = events.length > 0 ? events[0].occurred_at.toISOString() : undefined;
1256
1269
  return {
@@ -0,0 +1,271 @@
1
+ -- Lobu views replace view templates (phase 1).
2
+ --
3
+ -- New table `views`: one row per view with its current source, compiled
4
+ -- browser bundle, content hash, extracted attach/params/actions metadata and
5
+ -- `last_writer` (apply_id | tool call | user). Same source means the same
6
+ -- hash and no write. Git is the only history of definitions, so there is no
7
+ -- versions table. Deleted: `view_template_versions`,
8
+ -- `view_template_active_tabs`, plus the default-template pointer columns on
9
+ -- `entity_types` and `entities`. Nothing else in the schema changes.
10
+ --
11
+ -- The 17 stored demo template rows are converted, never cleared: every
12
+ -- `view_template_versions` row becomes one `views` row. The active version of
13
+ -- each (resource, tab) group keeps the plain derived key; superseded versions
14
+ -- keep `-v<version>` suffixed keys so no authored content is lost. The
15
+ -- original JSON template is preserved verbatim inside the converted module as
16
+ -- `TEMPLATE`, with the attach/params/actions the row carried. Converted rows
17
+ -- store an empty `compiled_code` and are inert until re-saved through
18
+ -- `manage_views` with a real TSX module, which compiles and fills the bundle.
19
+ --
20
+ -- Lock safety: the dropped tables are small org-config tables (tens of rows;
21
+ -- 17 version rows measured on prod 2026-09-16), so the ACCESS EXCLUSIVE lock
22
+ -- on DROP is held for milliseconds and no concurrent writer blocks on it.
23
+ -- The conversion is one INSERT ... SELECT, fail-closed: key collisions fall
24
+ -- back to deterministic `legacy-view-<id>` keys, and any unexpected conflict
25
+ -- aborts the transaction instead of discarding authored data. The attach GIN
26
+ -- index ships in the follow-up 20260917000001 migration (CONCURRENTLY cannot
27
+ -- run inside this transactional file).
28
+ -- migrate:up
29
+ CREATE TABLE IF NOT EXISTS public.views (
30
+ id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
31
+ organization_id text NOT NULL,
32
+ key text NOT NULL,
33
+ name text NOT NULL,
34
+ description text NOT NULL DEFAULT '',
35
+ source_code text NOT NULL,
36
+ compiled_code text NOT NULL DEFAULT '',
37
+ content_hash text NOT NULL,
38
+ attach jsonb NOT NULL DEFAULT '[]'::jsonb,
39
+ params jsonb NOT NULL DEFAULT '{}'::jsonb,
40
+ actions jsonb NOT NULL DEFAULT '{}'::jsonb,
41
+ last_writer text NOT NULL,
42
+ created_at timestamp with time zone DEFAULT now() NOT NULL,
43
+ updated_at timestamp with time zone DEFAULT now() NOT NULL,
44
+ CONSTRAINT views_key_check CHECK ((key ~ '^[a-z0-9][a-z0-9-]{0,63}$'::text)),
45
+ CONSTRAINT views_organization_key_unique UNIQUE (organization_id, key)
46
+ );
47
+
48
+ -- Convert every stored template version into a view. Grouped by
49
+ -- (organization, resource, tab); the active version of each group keeps the
50
+ -- plain key and superseded versions keep `-v<version>` keys. Active means the
51
+ -- parent pointer column for default tabs, `view_template_active_tabs` for
52
+ -- named tabs, and the latest version when no pointer names one.
53
+ WITH ranked AS (
54
+ SELECT v.*,
55
+ ROW_NUMBER() OVER (
56
+ PARTITION BY v.organization_id, v.resource_type, v.resource_id, COALESCE(v.tab_name, '')
57
+ ORDER BY v.version DESC
58
+ ) AS rn
59
+ FROM public.view_template_versions v
60
+ ),
61
+ active_default AS (
62
+ SELECT et.organization_id, 'entity_type'::text AS resource_type, et.slug AS resource_id,
63
+ et.current_view_template_version_id AS version_id
64
+ FROM public.entity_types et
65
+ WHERE et.current_view_template_version_id IS NOT NULL
66
+ UNION ALL
67
+ SELECT e.organization_id, 'entity'::text AS resource_type, e.id::text AS resource_id,
68
+ e.current_view_template_version_id AS version_id
69
+ FROM public.entities e
70
+ WHERE e.current_view_template_version_id IS NOT NULL
71
+ ),
72
+ active_tabs AS (
73
+ SELECT organization_id, resource_type, resource_id, tab_name,
74
+ current_version_id AS version_id
75
+ FROM public.view_template_active_tabs
76
+ ),
77
+ flagged AS (
78
+ SELECT r.organization_id, r.resource_type, r.resource_id, r.tab_name,
79
+ r.id, r.version, r.json_template, r.created_by, r.rn,
80
+ CASE
81
+ WHEN r.tab_name IS NULL AND d.version_id = r.id THEN true
82
+ WHEN r.tab_name IS NOT NULL AND t.version_id = r.id THEN true
83
+ WHEN r.rn = 1
84
+ AND NOT EXISTS (
85
+ SELECT 1 FROM active_default d2
86
+ WHERE d2.organization_id = r.organization_id
87
+ AND d2.resource_type = r.resource_type
88
+ AND d2.resource_id = r.resource_id
89
+ AND r.tab_name IS NULL
90
+ )
91
+ AND NOT EXISTS (
92
+ SELECT 1 FROM active_tabs t2
93
+ WHERE t2.organization_id = r.organization_id
94
+ AND t2.resource_type = r.resource_type
95
+ AND t2.resource_id = r.resource_id
96
+ AND t2.tab_name IS NOT DISTINCT FROM r.tab_name
97
+ AND r.tab_name IS NOT NULL
98
+ )
99
+ THEN true
100
+ ELSE false
101
+ END AS is_active
102
+ FROM ranked r
103
+ LEFT JOIN active_default d
104
+ ON d.organization_id = r.organization_id
105
+ AND d.resource_type = r.resource_type
106
+ AND d.resource_id = r.resource_id
107
+ AND r.tab_name IS NULL
108
+ LEFT JOIN active_tabs t
109
+ ON t.organization_id = r.organization_id
110
+ AND t.resource_type = r.resource_type
111
+ AND t.resource_id = r.resource_id
112
+ AND t.tab_name = r.tab_name
113
+ AND r.tab_name IS NOT NULL
114
+ ),
115
+ shaped AS (
116
+ SELECT f.organization_id, f.resource_type, f.resource_id, f.tab_name,
117
+ f.id, f.version, f.json_template, f.created_by, f.rn, f.is_active,
118
+ -- Slug the key from tab + resource; trim to the key grammar the views
119
+ -- table enforces. Values are data, never identifiers, so anything outside
120
+ -- [a-z0-9] folds to a dash.
121
+ NULLIF(
122
+ TRIM(
123
+ BOTH '-' FROM REGEXP_REPLACE(
124
+ LOWER(COALESCE(f.tab_name, 'default') || '-' || f.resource_type || '-' || f.resource_id),
125
+ '[^a-z0-9]+', '-', 'g'
126
+ )
127
+ ),
128
+ ''
129
+ ) AS base_key,
130
+ CASE WHEN f.tab_name IS NULL THEN 'overview' ELSE 'tab' END AS placement,
131
+ CASE WHEN JSONB_TYPEOF(f.json_template->'interactions') = 'object'
132
+ THEN COALESCE((
133
+ SELECT JSONB_OBJECT_AGG(e.key, JSONB_BUILD_OBJECT('emits', e.value->>'emits'))
134
+ FROM JSONB_EACH(f.json_template->'interactions') AS e(key, value)
135
+ WHERE JSONB_TYPEOF(e.value) = 'object'
136
+ AND e.value->>'emits' IS NOT NULL
137
+ AND e.value->>'emits' <> ''
138
+ ), '{}'::jsonb)
139
+ ELSE '{}'::jsonb
140
+ END AS actions
141
+ FROM flagged f
142
+ ),
143
+ keyed AS (
144
+ SELECT s.*,
145
+ COALESCE(s.base_key, 'view') AS slug,
146
+ CASE WHEN s.resource_type = 'entity_type'
147
+ THEN JSONB_BUILD_ARRAY(JSONB_BUILD_OBJECT('type', s.resource_id, 'placement', s.placement))
148
+ ELSE JSONB_BUILD_ARRAY(
149
+ CASE WHEN s.resource_id ~ '^[0-9]+$'
150
+ THEN JSONB_BUILD_OBJECT('entity', s.resource_id::bigint, 'placement', s.placement)
151
+ ELSE JSONB_BUILD_OBJECT('entity', s.resource_id, 'placement', s.placement)
152
+ END
153
+ )
154
+ END AS attach
155
+ FROM shaped s
156
+ ),
157
+ sourced AS (
158
+ SELECT k.organization_id, k.resource_id, k.resource_type, k.tab_name,
159
+ k.id, k.version, k.created_by, k.is_active, k.slug, k.attach, k.actions,
160
+ -- Newlines in resource ids would break out of the `//` header comment,
161
+ -- so they fold to spaces. Everything else below is value concatenation,
162
+ -- never a string literal, so quotes need no escaping.
163
+ '// Converted from view template ('
164
+ || k.resource_type || ':'
165
+ || REPLACE(REPLACE(k.resource_id, CHR(10), ' '), CHR(13), ' ')
166
+ || COALESCE('/' || REPLACE(REPLACE(k.tab_name, CHR(10), ' '), CHR(13), ' '), '')
167
+ || ', v' || k.version::text
168
+ || ') by migration 20260917000000_views.' || CHR(10)
169
+ || '// The original JSON template is preserved below as TEMPLATE.'
170
+ || CHR(10)
171
+ || '// Re-save through manage_views with a real TSX module to recompile this view.'
172
+ || CHR(10)
173
+ || 'export const view = { attach: ' || k.attach::text
174
+ || ', params: {}, actions: ' || k.actions::text || ' };' || CHR(10)
175
+ || 'const TEMPLATE = ' || k.json_template::text || ';' || CHR(10)
176
+ || 'export default function ConvertedView() { return null; }' || CHR(10)
177
+ AS source_code
178
+ FROM keyed k
179
+ ),
180
+ final AS (
181
+ SELECT s.organization_id,
182
+ LEFT(s.slug, 64) AS plain_key,
183
+ LEFT(s.slug, 44) || '-v' || s.version::text AS versioned_key,
184
+ s.is_active, s.version, s.id,
185
+ LEFT(
186
+ s.resource_id
187
+ || COALESCE(' / ' || NULLIF(s.tab_name, ''), ''),
188
+ 120
189
+ ) AS view_name,
190
+ 'Converted from a view template by migration 20260917000000_views; re-save to recompile.'
191
+ AS view_description,
192
+ s.source_code,
193
+ SUBSTRING(MD5(s.source_code) FROM 1 FOR 16) AS source_hash,
194
+ s.attach, s.actions, s.created_by
195
+ FROM sourced s
196
+ ),
197
+ deduped AS (
198
+ SELECT f.*,
199
+ CASE WHEN f.is_active THEN f.plain_key ELSE f.versioned_key END AS candidate_key,
200
+ COUNT(*) OVER (
201
+ PARTITION BY f.organization_id,
202
+ CASE WHEN f.is_active THEN f.plain_key ELSE f.versioned_key END
203
+ ) AS key_count
204
+ FROM final f
205
+ )
206
+ INSERT INTO public.views (
207
+ organization_id, key, name, description, source_code, compiled_code,
208
+ content_hash, attach, params, actions, last_writer
209
+ )
210
+ SELECT d.organization_id,
211
+ CASE
212
+ WHEN d.key_count > 1 OR d.candidate_key ~ '^legacy-view-[0-9]+$'
213
+ THEN 'legacy-view-' || d.id::text
214
+ ELSE d.candidate_key
215
+ END,
216
+ d.view_name, d.view_description, d.source_code, '',
217
+ d.source_hash, d.attach, '{}'::jsonb, d.actions,
218
+ 'migration:view-templates'
219
+ FROM deduped d;
220
+
221
+ -- Retire the template tables and their default-template pointers. The foreign
222
+ -- keys go first so the table drops do not depend on drop order.
223
+ ALTER TABLE ONLY public.entities DROP CONSTRAINT IF EXISTS entities_view_template_version_fk;
224
+ ALTER TABLE ONLY public.entity_types DROP CONSTRAINT IF EXISTS entity_types_view_template_version_fk;
225
+ -- The template feature is retired; every stored row converts into a `views`
226
+ -- row above, so no authored content is lost.
227
+ -- squawk-ignore ban-drop-table
228
+ DROP TABLE IF EXISTS public.view_template_active_tabs;
229
+ -- squawk-ignore ban-drop-table
230
+ DROP TABLE IF EXISTS public.view_template_versions;
231
+ ALTER TABLE ONLY public.entities DROP COLUMN IF EXISTS current_view_template_version_id;
232
+ ALTER TABLE ONLY public.entity_types DROP COLUMN IF EXISTS current_view_template_version_id;
233
+
234
+ -- migrate:down
235
+ -- Irreversible for data: converted template rows are not restored (recover
236
+ -- them from a backup). The retired schema comes back empty so a down/up
237
+ -- round-trip keeps working. Foreign keys are deliberately not recreated: the
238
+ -- down path exists for local rollback, where old code runs its joins without
239
+ -- needing the constraints enforced.
240
+ CREATE TABLE IF NOT EXISTS public.view_template_versions (
241
+ id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
242
+ resource_type text NOT NULL,
243
+ resource_id text NOT NULL,
244
+ organization_id text NOT NULL,
245
+ version bigint NOT NULL,
246
+ tab_name text,
247
+ tab_order bigint DEFAULT 0,
248
+ json_template jsonb NOT NULL,
249
+ change_notes text,
250
+ created_by text NOT NULL,
251
+ created_at timestamp with time zone DEFAULT now(),
252
+ CONSTRAINT view_template_versions_resource_type_check CHECK ((resource_type = ANY (ARRAY['entity_type'::text, 'entity'::text])))
253
+ );
254
+
255
+ CREATE TABLE IF NOT EXISTS public.view_template_active_tabs (
256
+ id bigint GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
257
+ resource_type text NOT NULL,
258
+ resource_id text NOT NULL,
259
+ organization_id text NOT NULL,
260
+ tab_name text NOT NULL,
261
+ tab_order bigint DEFAULT 0,
262
+ current_version_id bigint NOT NULL,
263
+ CONSTRAINT view_template_active_tabs_resource_type_check CHECK ((resource_type = ANY (ARRAY['entity_type'::text, 'entity'::text]))),
264
+ CONSTRAINT view_template_active_tabs_unique UNIQUE (resource_type, resource_id, organization_id, tab_name)
265
+ );
266
+
267
+ ALTER TABLE ONLY public.entities ADD COLUMN IF NOT EXISTS current_view_template_version_id bigint;
268
+ ALTER TABLE ONLY public.entity_types ADD COLUMN IF NOT EXISTS current_view_template_version_id bigint;
269
+
270
+ -- squawk-ignore ban-drop-table
271
+ DROP TABLE IF EXISTS public.views;
@@ -0,0 +1,14 @@
1
+ -- Attach index for `views` (phase 1).
2
+ --
3
+ -- Mount-point reads filter views by their attach lines (`attach @> ...`), so
4
+ -- the payload gets a GIN index like the other jsonb filter columns. Split
5
+ -- from 20260917000000_views because CONCURRENTLY cannot run inside that
6
+ -- file's transactional section (one statement per transaction:false file).
7
+ -- No reader exists in PR1 yet: the index is pre-provisioned for the PR3 mount
8
+ -- points so the stacked rollout adds no later schema change for it.
9
+ -- migrate:up transaction:false
10
+ CREATE INDEX CONCURRENTLY IF NOT EXISTS idx_views_attach
11
+ ON public.views USING gin (attach);
12
+
13
+ -- migrate:down transaction:false
14
+ DROP INDEX CONCURRENTLY IF EXISTS public.idx_views_attach;
@@ -0,0 +1,51 @@
1
+ -- migrate:up transaction:false
2
+
3
+ -- Keyed idempotence for agent-turn tool traces (#3662 follow-up).
4
+ --
5
+ -- Heartbeat tool receipts are `thread_response` rows carrying a
6
+ -- `customEvent.name = 'tool_use'` payload, keyed by the canonical
7
+ -- (organization, conversation, initiating input message, tool call id) tuple in
8
+ -- `idempotency_key` (`turn-tool:v1:...`, set by the agent-turn worker API).
9
+ --
10
+ -- The pre-existing `runs_idempotency_key_uniq` partial index only covers live
11
+ -- rows (`status IN ('pending','claimed','running')`): once a trace is claimed
12
+ -- and delivered it drops out of that index, so a heartbeat retry re-inserted
13
+ -- the same trace as a second row and the beat ACKed all events. This index is
14
+ -- scoped to exactly the tool-trace shape across ALL statuses — pending,
15
+ -- claimed, failed and delivered alike — so a retry collides no matter what
16
+ -- delivery state the first insert has reached. A conflicting same-key payload
17
+ -- (same key, different trace body) collides too; the worker API re-reads the
18
+ -- stored row and rejects it rather than ACKing, so the worker keeps the
19
+ -- evidence queued instead of retiring it unwritten.
20
+ --
21
+ -- Narrowly scoped on purpose: only `thread_response` rows whose payload is a
22
+ -- `tool_use` custom event and that carry a key participate. Every other row —
23
+ -- including keyless legacy traces — stays out of the index entirely.
24
+
25
+ -- Fail loudly before index construction if an earlier partial rollout already
26
+ -- wrote duplicate keyed rows. This migration never chooses a winner or deletes
27
+ -- evidence; an operator must inspect and reconcile the conflicting facts.
28
+ DO $$
29
+ BEGIN
30
+ IF EXISTS (
31
+ SELECT 1
32
+ FROM public.runs
33
+ WHERE queue_name = 'thread_response'
34
+ AND action_input->'customEvent'->>'name' = 'tool_use'
35
+ AND idempotency_key IS NOT NULL
36
+ GROUP BY idempotency_key
37
+ HAVING count(*) > 1
38
+ ) THEN
39
+ RAISE EXCEPTION 'duplicate keyed agent-turn tool traces block idx_runs_turn_tool_event_uniq';
40
+ END IF;
41
+ END $$;
42
+
43
+ CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS idx_runs_turn_tool_event_uniq
44
+ ON public.runs (idempotency_key)
45
+ WHERE queue_name = 'thread_response'
46
+ AND action_input->'customEvent'->>'name' = 'tool_use'
47
+ AND idempotency_key IS NOT NULL;
48
+
49
+ -- migrate:down transaction:false
50
+
51
+ DROP INDEX CONCURRENTLY IF EXISTS public.idx_runs_turn_tool_event_uniq;
@@ -0,0 +1,32 @@
1
+ -- migrate:up
2
+ -- Deliberately requires the existing quiesced deployment: old replicas must
3
+ -- stop admitting/claiming connector runs before this one-time cutover.
4
+ -- Cost: ADD COLUMN is metadata-only, with no history backfill. The cutover
5
+ -- updates pending connector runs only. Tested on fixtures, not production size.
6
+ SET LOCAL lock_timeout = '5s';
7
+ SET LOCAL statement_timeout = '60s';
8
+
9
+ ALTER TABLE runs ADD COLUMN IF NOT EXISTS connector_artifact_hash text;
10
+
11
+ -- Today's mutable version row cannot prove yesterday's admitted identity.
12
+ -- Preserve the run as a visible failure; never guess its hash or replay it.
13
+ UPDATE runs r
14
+ SET status = 'failed', completed_at = CURRENT_TIMESTAMP,
15
+ approval_status = CASE WHEN approval_status = 'pending' THEN 'rejected' ELSE approval_status END,
16
+ error_message = 'The admitted connector manifest was not recorded. Re-run this operation against the current device contract.'
17
+ WHERE r.status = 'pending'
18
+ AND r.run_type IN ('sync', 'action', 'auth')
19
+ AND r.connector_artifact_hash IS NULL
20
+ AND (
21
+ SELECT cv.source_path LIKE 'device-manifest://%'
22
+ AND cv.compiled_code IS NULL AND cv.compile_config_hash IS NULL
23
+ AND cv.source_code IS NULL AND cv.compiled_code_hash IS NOT NULL
24
+ FROM connector_versions cv
25
+ WHERE cv.connector_key = r.connector_key AND cv.version = r.connector_version
26
+ AND (cv.organization_id = r.organization_id OR cv.organization_id IS NULL)
27
+ ORDER BY cv.organization_id NULLS LAST
28
+ LIMIT 1
29
+ );
30
+
31
+ -- migrate:down
32
+ ALTER TABLE runs DROP COLUMN IF EXISTS connector_artifact_hash;
@@ -0,0 +1,17 @@
1
+ -- migrate:up
2
+ ALTER TABLE views
3
+ ADD COLUMN IF NOT EXISTS source_files jsonb,
4
+ ADD COLUMN IF NOT EXISTS dependencies jsonb,
5
+ ADD COLUMN IF NOT EXISTS source_complete boolean;
6
+
7
+ ALTER TABLE connector_versions
8
+ ADD COLUMN IF NOT EXISTS source_files jsonb,
9
+ ADD COLUMN IF NOT EXISTS dependencies jsonb,
10
+ ADD COLUMN IF NOT EXISTS source_complete boolean;
11
+
12
+ -- Existing artifacts have unknown source provenance. Re-saving captures it;
13
+ -- neither a compiled-code hash nor source-looking text proves completeness.
14
+
15
+ -- migrate:down
16
+ ALTER TABLE connector_versions DROP COLUMN IF EXISTS source_files, DROP COLUMN IF EXISTS dependencies, DROP COLUMN IF EXISTS source_complete;
17
+ ALTER TABLE views DROP COLUMN IF EXISTS source_files, DROP COLUMN IF EXISTS dependencies, DROP COLUMN IF EXISTS source_complete;