limixbot 0.3.40 → 0.3.41

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 (125) hide show
  1. package/dist/assets/{ActivityPanel-C78UlJ_B.js → ActivityPanel-DZG0IUAb.js} +1 -1
  2. package/dist/assets/{App-DoK6OnP_.js → App-CJdHarVp.js} +76 -76
  3. package/dist/assets/{AppEventEditor-CrUG4a3D.js → AppEventEditor-DDozbnOv.js} +1 -1
  4. package/dist/assets/{BotSettingsDialog-CvcYYLw-.js → BotSettingsDialog-ZoAbxSXP.js} +1 -1
  5. package/dist/assets/{BrowserPanel-CCfO4ItU.js → BrowserPanel-CDHo6Tn8.js} +1 -1
  6. package/dist/assets/{BrowserProfilesManager-BfuF_oUa.js → BrowserProfilesManager-C1MPUJeW.js} +1 -1
  7. package/dist/assets/{CloudAddDialog-DSqiG9RZ.js → CloudAddDialog-D-IbJwTX.js} +1 -1
  8. package/dist/assets/{ComputerFilesPane-q5cwxKow.js → ComputerFilesPane-Crhoemc3.js} +1 -1
  9. package/dist/assets/{ComputerPanel-Cqw5ivpE.js → ComputerPanel-D4j4PIWz.js} +2 -2
  10. package/dist/assets/{DataPanel-CI_7GCCI.js → DataPanel-CPoKXLU9.js} +1 -1
  11. package/dist/assets/{DesktopViewer-BX0YJJ9T.js → DesktopViewer-aVjkMSMD.js} +1 -1
  12. package/dist/assets/{FilesView-CePiPQtk.js → FilesView-YJcm42XT.js} +1 -1
  13. package/dist/assets/{GrokMoveDialog-plHjPcxW.js → GrokMoveDialog-BUevTZlU.js} +1 -1
  14. package/dist/assets/{InspectorPanel-BtJWpmNb.js → InspectorPanel-3vZ7Hak-.js} +1 -1
  15. package/dist/assets/{KeyboardShortcutsModal-CvI39Dyv.js → KeyboardShortcutsModal-WMyOgiio.js} +1 -1
  16. package/dist/assets/{LiveDesktop-CWCNNVVb.js → LiveDesktop-B3gbZyLF.js} +1 -1
  17. package/dist/assets/{LocalVmWorkspace-Dj0D8KZg.js → LocalVmWorkspace-DOubDR3q.js} +1 -1
  18. package/dist/assets/{MacLocalControl-DI9rmipM.js → MacLocalControl-BjBEyxaS.js} +1 -1
  19. package/dist/assets/{MarkdownFilePreview-C2wq8ggW.js → MarkdownFilePreview-BFY_qUaz.js} +1 -1
  20. package/dist/assets/{MenuMotion-9KpZfoc6.js → MenuMotion-DYvg3Y0j.js} +1 -1
  21. package/dist/assets/{NewBotDialog-yH4tNqbg.js → NewBotDialog-Bn5iED5Y.js} +1 -1
  22. package/dist/assets/{PhoneAppDialog-C7-lv79J.js → PhoneAppDialog-Bgloj_d7.js} +1 -1
  23. package/dist/assets/{PlacesRail-DgLRkWzN.js → PlacesRail-lvsLiimN.js} +1 -1
  24. package/dist/assets/{PluginsPanel-BjhDlFfS.js → PluginsPanel-Dh93YAqc.js} +1 -1
  25. package/dist/assets/{ProIntroduction-CX5wa_L9.js → ProIntroduction-C8F7cMAc.js} +1 -1
  26. package/dist/assets/{RemoteAgentSettingsPanel-uKPEbc5u.js → RemoteAgentSettingsPanel-Bp_0BeDv.js} +1 -1
  27. package/dist/assets/{RoomPanel-CUN0w3uU.js → RoomPanel-DzD_Hwgk.js} +1 -1
  28. package/dist/assets/{RoutinesPage-C1DsUtyJ.js → RoutinesPage-yasXFvIW.js} +1 -1
  29. package/dist/assets/{SettingsModal-Ly5CgfzY.js → SettingsModal-BUkF5lkV.js} +4 -4
  30. package/dist/assets/{ShareTeamDialog-bekuOz52.js → ShareTeamDialog-Dzzqw_BR.js} +1 -1
  31. package/dist/assets/{SignedInSites-B3Pypdn7.js → SignedInSites-1TKw2QzT.js} +1 -1
  32. package/dist/assets/{TeamLibraryPanel-D6jp7yJH.js → TeamLibraryPanel-CC0G2mYh.js} +1 -1
  33. package/dist/assets/{TeamMapPage-Ds-NTRhm.js → TeamMapPage-Ba0YA7eC.js} +1 -1
  34. package/dist/assets/{TriggersPage-B9I-fybZ.js → TriggersPage-CL1gWcMv.js} +1 -1
  35. package/dist/assets/{VisibilitySection-Bmoy4R5T.js → VisibilitySection-rAjBj4Er.js} +1 -1
  36. package/dist/assets/{WebhookTrigger-D222Fm7h.js → WebhookTrigger-DJnoilPI.js} +1 -1
  37. package/dist/assets/{WorksOnGrid-Ihbs1ZDY.js → WorksOnGrid-DMyjNgJ7.js} +1 -1
  38. package/dist/assets/{abnfDiagram-YUKMZFIV-iRkRRTmn.js → abnfDiagram-YUKMZFIV-CBW50M4i.js} +1 -1
  39. package/dist/assets/{activity-D3yGGWz9.js → activity-Do2k3mZG.js} +1 -1
  40. package/dist/assets/{architectureDiagram-47P4ROYG-B-l-Tbc0.js → architectureDiagram-47P4ROYG-COydFAli.js} +1 -1
  41. package/dist/assets/{blockDiagram-E7TT5TSB-BPHNVO2-.js → blockDiagram-E7TT5TSB-Bdo2_X9c.js} +1 -1
  42. package/dist/assets/{c4Diagram-CRA5TL53-Ces14mNL.js → c4Diagram-CRA5TL53-BYk2S2UT.js} +1 -1
  43. package/dist/assets/{calendar-days-DNgw_jzq.js → calendar-days-BeTMH5fp.js} +1 -1
  44. package/dist/assets/channel-B9n_GxPq.js +1 -0
  45. package/dist/assets/{chunk-2Q5K7J3B-BBv2HgLY.js → chunk-2Q5K7J3B-DOtIddN3.js} +1 -1
  46. package/dist/assets/{chunk-5VM5RSS4-Ms8vx6uj.js → chunk-5VM5RSS4-B4C7BoQt.js} +1 -1
  47. package/dist/assets/{chunk-7TKQ45FW-CoQ_n3fY.js → chunk-7TKQ45FW-B0BHWucP.js} +1 -1
  48. package/dist/assets/{chunk-AW2ZBBNX-CLnH6qE9.js → chunk-AW2ZBBNX-CJrwE9R9.js} +1 -1
  49. package/dist/assets/{chunk-FVRAUYC3-CzEI0PkV.js → chunk-FVRAUYC3-DF93Bqmk.js} +2 -2
  50. package/dist/assets/{chunk-HTAEGDNF-tQeKhP4P.js → chunk-HTAEGDNF-la8NgRgV.js} +1 -1
  51. package/dist/assets/{chunk-JWPE2WC7-Bels7hbY.js → chunk-JWPE2WC7-L0lPJGK0.js} +1 -1
  52. package/dist/assets/{chunk-KQW6MTUR-C_OPTqju.js → chunk-KQW6MTUR-DqtGsigA.js} +1 -1
  53. package/dist/assets/{chunk-XXDRQBXY-lLPvGZOB.js → chunk-XXDRQBXY-CdZZyfPW.js} +1 -1
  54. package/dist/assets/{classDiagram-v2-K4WV4PDN-DEGC9KSb.js → classDiagram-v2-K4WV4PDN-BmzBwOGd.js} +1 -1
  55. package/dist/assets/{coins-BUPhLqLr.js → coins-S-i07yhx.js} +1 -1
  56. package/dist/assets/{core-Cmvm9EBY.js → core-BatOV9GP.js} +1 -1
  57. package/dist/assets/{cose-bilkent-JH36ORCC-B4guJJ7b.js → cose-bilkent-JH36ORCC-DKZB2O3B.js} +1 -1
  58. package/dist/assets/{cynefin-EF2NZ3EQ-DzL2Ko-S.js → cynefin-EF2NZ3EQ-B6pmxRta.js} +1 -1
  59. package/dist/assets/{cynefinDiagram-3GCD6N5R-DOhRhSCa.js → cynefinDiagram-3GCD6N5R-B13ZC2BI.js} +1 -1
  60. package/dist/assets/{dagre-W4DXFKR2-ClVlfmbp.js → dagre-W4DXFKR2-BGVzBIbu.js} +1 -1
  61. package/dist/assets/{diagram-2UJZ2QOL-CCORQMGQ.js → diagram-2UJZ2QOL-DYi3uAFS.js} +1 -1
  62. package/dist/assets/{diagram-OVF4WLC6-BA05pSeN.js → diagram-OVF4WLC6-CC_ICBIc.js} +1 -1
  63. package/dist/assets/{diagram-PFPMY2P6-Buk95mAY.js → diagram-PFPMY2P6-aCEZHESH.js} +1 -1
  64. package/dist/assets/{diagram-UMYRVEAY-C_N8yC5C.js → diagram-UMYRVEAY-CvmaQeZP.js} +1 -1
  65. package/dist/assets/{diagram-YEKJPTXX-BcGFdDU0.js → diagram-YEKJPTXX-1fMOPjTt.js} +1 -1
  66. package/dist/assets/{diagram-ZIFT7M5P-CrsI0m0f.js → diagram-ZIFT7M5P-qc3RhTvH.js} +1 -1
  67. package/dist/assets/{ebnfDiagram-VR2GEFS7-ZuofO3J3.js → ebnfDiagram-VR2GEFS7-B_u7ZpcW.js} +1 -1
  68. package/dist/assets/{elk-IJKZMXRS-B9HPBoMc.js → elk-IJKZMXRS-TGCsQDlL.js} +1 -1
  69. package/dist/assets/{erDiagram-O2IAPWRE-yblUS7CX.js → erDiagram-O2IAPWRE-BKMwoO3H.js} +1 -1
  70. package/dist/assets/{file-up-CJGgT920.js → file-up-DbsojZOa.js} +1 -1
  71. package/dist/assets/{flowDiagram-OXPTDLAJ-BoRQKWEE.js → flowDiagram-OXPTDLAJ-ByQ8sl5K.js} +1 -1
  72. package/dist/assets/{ganttDiagram-R7TSEDQI-Mqmf_lTP.js → ganttDiagram-R7TSEDQI-BO5jsZ4i.js} +1 -1
  73. package/dist/assets/{gitGraphDiagram-XJZIOB7I-ChOVYU-I.js → gitGraphDiagram-XJZIOB7I-B22KG2ho.js} +1 -1
  74. package/dist/assets/{import-name-D_O0Z9qB.js → import-name-pHr4dPZm.js} +1 -1
  75. package/dist/assets/{index-BNuCZ6CX.js → index-Grd_nfDb.js} +2 -2
  76. package/dist/assets/{index-BvjpOIdn.js → index-W93Ai2Bi.js} +1 -1
  77. package/dist/assets/{infoDiagram-5W2HQ5XZ-DzVrRFee.js → infoDiagram-5W2HQ5XZ-HdwUwMOS.js} +1 -1
  78. package/dist/assets/{ishikawaDiagram-K3B6WC7H-B1AtMtWp.js → ishikawaDiagram-K3B6WC7H-CoAJTIyF.js} +1 -1
  79. package/dist/assets/{journeyDiagram-COXZFDF6-D98AinIQ.js → journeyDiagram-COXZFDF6-DHyU5Xir.js} +1 -1
  80. package/dist/assets/{kanban-definition-P3RFRI5V-DyF07Cia.js → kanban-definition-P3RFRI5V-RgsXG5FT.js} +1 -1
  81. package/dist/assets/{mcp-servers-CWLCIWVv.js → mcp-servers-amktn-FJ.js} +1 -1
  82. package/dist/assets/{mermaid.core-BkGLuasi.js → mermaid.core-BpAUyD7f.js} +4 -4
  83. package/dist/assets/{mindmap-definition-LZFPQGKD-CtEZ4egD.js → mindmap-definition-LZFPQGKD-CTf8RGLd.js} +1 -1
  84. package/dist/assets/{minimize-D02to6Fy.js → minimize-B34Shsdr.js} +1 -1
  85. package/dist/assets/{monitor-cPSwTZbh.js → monitor-BS4ugqnK.js} +1 -1
  86. package/dist/assets/{new-bot-BAm0i3N-.js → new-bot-C5hCeo2f.js} +1 -1
  87. package/dist/assets/{org-library-CVRs5XpH.js → org-library-BNgYibrj.js} +1 -1
  88. package/dist/assets/{package-format-nP_LfEpp.js → package-format-UAGSPtJn.js} +1 -1
  89. package/dist/assets/{pegDiagram-BGZESJAR-BA9RLREu.js → pegDiagram-BGZESJAR-B4QXE8kd.js} +1 -1
  90. package/dist/assets/{pieDiagram-CAPJLFHJ-BR2mMjlL.js → pieDiagram-CAPJLFHJ-Rkmvk88E.js} +1 -1
  91. package/dist/assets/{quadrantDiagram-GDMTTRAM-F5WV656C.js → quadrantDiagram-GDMTTRAM-_jDgqTi0.js} +1 -1
  92. package/dist/assets/{rail-C4RLSvjm.js → rail-CNXlLBbY.js} +1 -1
  93. package/dist/assets/{railroadDiagram-SM67HX2B-Cd6uxfxc.js → railroadDiagram-SM67HX2B-BLkj9MvC.js} +1 -1
  94. package/dist/assets/{remote-desktop-panel-eUh-91Nm.js → remote-desktop-panel-DkVpVDgT.js} +1 -1
  95. package/dist/assets/{requirementDiagram-X7JNWC4A-Cfo_0cMh.js → requirementDiagram-X7JNWC4A-Bgsg8iiY.js} +1 -1
  96. package/dist/assets/{sankeyDiagram-UM26HJRW-TDjyYx-y.js → sankeyDiagram-UM26HJRW-B1TLh0eZ.js} +1 -1
  97. package/dist/assets/{sequenceDiagram-ZO4K6R2Y-Ko062Fce.js → sequenceDiagram-ZO4K6R2Y-CO__-6Wr.js} +1 -1
  98. package/dist/assets/{sizeCapture-INFHLROL-BrrtOSNi.js → sizeCapture-INFHLROL-BI46RDzq.js} +1 -1
  99. package/dist/assets/{stateDiagram-v2-TBUQTH76-B1qzPqwN.js → stateDiagram-v2-TBUQTH76-OzLDaTpE.js} +1 -1
  100. package/dist/assets/{styles-CYPAO9i1.js → styles-CewcaVc5.js} +2 -2
  101. package/dist/assets/{swimlanes-N4OXWK64-Dsuqhiei.js → swimlanes-N4OXWK64-CsPs93Ij.js} +1 -1
  102. package/dist/assets/swimlanesDiagram-K3J5GTZL-DUfFJSi9.js +8 -0
  103. package/dist/assets/{team-share-zViFUsSH.js → team-share-BjJaxqdW.js} +1 -1
  104. package/dist/assets/{timeline-definition-YOQAKGHF-zBd8HYLV.js → timeline-definition-YOQAKGHF-_ZwJoWnd.js} +1 -1
  105. package/dist/assets/{usecaseDiagram-VIAY4XPW-DkA9LTMv.js → usecaseDiagram-VIAY4XPW-BC05iPIW.js} +1 -1
  106. package/dist/assets/{vennDiagram-BLWOH2XV-BU2g61ns.js → vennDiagram-BLWOH2XV-xgthUL1H.js} +1 -1
  107. package/dist/assets/vi-DcBzysyy.js +15 -0
  108. package/dist/assets/{wardleyDiagram-YMQ3BMBF-Bigp2Sxm.js → wardleyDiagram-YMQ3BMBF-BLcV7LRh.js} +1 -1
  109. package/dist/assets/{xychartDiagram-TAQBALBS-DrSgdkAt.js → xychartDiagram-TAQBALBS-C2IwACfF.js} +1 -1
  110. package/dist/index.html +2 -2
  111. package/dist/rail.html +4 -4
  112. package/dist-server/index.js +2691 -2681
  113. package/dist-server/package.json +1 -1
  114. package/dist-server/server/bot-api-host.js +20 -12
  115. package/dist-server/server/bot-visibility.js +6 -2
  116. package/dist-server/server/host/visibility-host.js +4 -1
  117. package/dist-server/server/index.js +21 -6
  118. package/dist-server/server/limix-channel-identity.js +41 -0
  119. package/dist-server/server/limix-channel-review.js +53 -0
  120. package/dist-server/server/routes/bot-messages.js +3 -0
  121. package/dist-server/shared/bot-api.js +1 -0
  122. package/package.json +1 -1
  123. package/dist/assets/channel-CLFluAXE.js +0 -1
  124. package/dist/assets/swimlanesDiagram-K3J5GTZL-Ck2z47VC.js +0 -8
  125. package/dist/assets/vi-D2CCwYiV.js +0 -15
@@ -1 +1 @@
1
- {"type":"module","version":"0.3.40"}
1
+ {"type":"module","version":"0.3.41"}
@@ -1,3 +1,4 @@
1
+ import { channelConversationSchema, parseChannelHeader } from "./limix-channel-identity.js";
1
2
  import { channelAttachmentSchema, channelReplyAttachments, saveChannelAttachments } from "./limix-channel-media.js";
2
3
  import { deleteAttachment } from "./attachments.js";
3
4
  // The Bot API's two sides. Outside: `POST /hooks/api/bots/<id>/messages` on the webhook receiver, a bearer key, a
@@ -24,6 +25,8 @@ const callSchema = z.object({
24
25
  message: z.string().min(1).max(BOT_API_MAX_MESSAGE_CHARS),
25
26
  attachments: z.array(channelAttachmentSchema).max(4).optional(),
26
27
  thread: z.string().regex(/^[\w-]{1,128}$/).optional(),
28
+ conversation: channelConversationSchema.optional(),
29
+ channel: z.enum(["telegram", "zalo", "discord", "facebook"]).optional(),
27
30
  /** Seconds to wait for the reply, for a caller that knows nothing in its path drops a quiet connection. */
28
31
  wait: z.number().min(0).max(BOT_API_MAX_WAIT_MS / 1000).optional(),
29
32
  });
@@ -39,6 +42,11 @@ function callerWords(error) {
39
42
  }
40
43
  const COULD_NOT_ANSWER = "The bot could not answer. Open this thread in the app to see why.";
41
44
  const BUSY = "The bot is busy. Try again soon.";
45
+ function failBeforeAcceptance(code) {
46
+ throw Object.assign(new Error(BUSY), { status: 409, forCaller: true, code, retryable: true });
47
+ }
48
+ const retryableBusySchema = z.object({ forCaller: z.literal(true), retryable: z.literal(true), code: z.enum(["thread_busy", "capacity_busy"]) });
49
+ const CHANNEL_NAMES = { telegram: "Telegram", zalo: "Zalo", discord: "Discord", facebook: "Facebook" };
42
50
  const CANNOT_CONFINE = "This bot's AI can't take Bot API calls. Choose another AI for this bot.";
43
51
  function detailOf(error) {
44
52
  const parsed = z.object({ detail: z.string() }).safeParse(error);
@@ -103,18 +111,20 @@ export function createBotApiHost(deps) {
103
111
  if (threadId !== undefined) {
104
112
  const task = store.taskByThread(botId, threadId);
105
113
  // Only a thread this API opened: the caller never writes into the person's own conversations.
106
- if (!task || task.botApi !== true || isLimixOwnerThread(threadId) !== owner)
114
+ if (!task || task.botApi !== true || isLimixOwnerThread(threadId) !== owner || (deps.channelIdentities && !deps.channelIdentities.matches(threadId, call.conversation, owner)))
107
115
  fail(404, "no such thread");
108
116
  if (deps.threadBusy(botId, threadId))
109
- return { status: 409, body: { thread: threadId, status: "working" } };
117
+ failBeforeAcceptance("thread_busy");
110
118
  }
111
119
  if (!deps.canStart(botId, threadId ?? ""))
112
- fail(409, BUSY, "The bot already had as many conversations going as it may");
120
+ failBeforeAcceptance("capacity_busy");
121
+ if (!manager.admit(botId))
122
+ fail(429, "Too many calls: this key takes 10 a minute");
113
123
  const message = withoutAttachedImages(call.message);
114
124
  let opened = false;
115
125
  if (threadId === undefined) {
116
126
  // Asks from the start, with none of the bot's saved allowances: nothing may answer an approval for an outside caller.
117
- const task = store.createTask(botId, message.slice(0, 80), false, undefined, undefined, "ask", undefined, undefined, (created) => deps.opened?.(created.threadId));
127
+ const task = store.createTask(botId, `${call.channel ? CHANNEL_NAMES[call.channel] + " · " : ""}${call.conversation ? call.conversation.senderId + " · " : ""}${message.slice(0, 80)}`, false, undefined, undefined, "ask", undefined, undefined, (created) => deps.opened?.(created.threadId));
118
128
  if (!task)
119
129
  fail(404, "no such bot");
120
130
  threadId = task.threadId;
@@ -122,6 +132,8 @@ export function createBotApiHost(deps) {
122
132
  store.patchTask(botId, threadId, { botApi: true, outside: true });
123
133
  if (owner)
124
134
  markLimixOwnerThread(threadId);
135
+ if (call.conversation)
136
+ deps.channelIdentities?.bind(threadId, call.conversation, owner);
125
137
  }
126
138
  const media = await saveChannelAttachments(call.attachments ?? []);
127
139
  const receivedAt = Date.now();
@@ -211,7 +223,7 @@ export function createBotApiHost(deps) {
211
223
  if (req.method === "GET") {
212
224
  const threadId = url.searchParams.get("thread") ?? "";
213
225
  const task = /^[\w-]{1,128}$/.test(threadId) ? deps.store.taskByThread(botId, threadId) : undefined;
214
- if (!task || task.botApi !== true || isLimixOwnerThread(threadId) !== limixOwner) {
226
+ if (!task || task.botApi !== true || isLimixOwnerThread(threadId) !== limixOwner || (deps.channelIdentities && !deps.channelIdentities.matches(threadId, parseChannelHeader(req.headers["x-limix-conversation"]), limixOwner))) {
215
227
  json(res, 404, { error: "no such thread" });
216
228
  return true;
217
229
  }
@@ -240,14 +252,9 @@ export function createBotApiHost(deps) {
240
252
  json(res, status, { error: message });
241
253
  return true;
242
254
  }
243
- if (!manager.admit(botId)) {
244
- manager.record(botId, { outcome: "rejected", statusCode: 429, reason: "Rate limit exceeded", preview: call.message });
245
- json(res, 429, { error: "Too many calls: this key takes 10 a minute" });
246
- return true;
247
- }
248
255
  if (pendingFor(botId) >= BOT_API_MAX_PENDING) {
249
256
  manager.record(botId, { outcome: "rejected", statusCode: 409, reason: "The bot is busy", preview: call.message });
250
- json(res, 409, { error: `The bot is busy: ${BOT_API_MAX_PENDING} calls are still being answered` });
257
+ json(res, 409, { error: `The bot is busy: ${BOT_API_MAX_PENDING} calls are still being answered`, code: "capacity_busy", retryable: true });
251
258
  return true;
252
259
  }
253
260
  try {
@@ -258,7 +265,8 @@ export function createBotApiHost(deps) {
258
265
  }
259
266
  catch (error) {
260
267
  manager.record(botId, { outcome: "rejected", statusCode: statusOf(error), reason: detailOf(error), preview: call.message });
261
- json(res, statusOf(error), { error: callerWords(error) });
268
+ const busy = retryableBusySchema.safeParse(error);
269
+ json(res, statusOf(error), { error: callerWords(error), ...(busy.success ? { code: busy.data.code, retryable: true } : {}) });
262
270
  }
263
271
  return true;
264
272
  }
@@ -155,7 +155,7 @@ export class VisibleSet {
155
155
  this.viewer = viewer;
156
156
  this.audiences = audiences ?? null;
157
157
  // On a Team Cloud nobody's view is everything, an admin's included: each conversation has its own audience.
158
- this.everything = this.audiences === null && (viewer.kind === "all" ||
158
+ this.everything = !bots.some(bot => bot.tasks?.some(task => task.botApi)) && this.audiences === null && (viewer.kind === "all" ||
159
159
  (!bots.some((bot) => isRestricted(bot.visibility)) && !groups.some((group) => isRestricted(group.audienceFloor))));
160
160
  this.ownerOf = ownerOf ?? ((threadId) => this.indexedOwner(threadId));
161
161
  if (this.everything)
@@ -213,7 +213,7 @@ export class VisibleSet {
213
213
  }
214
214
  /** Conversations have audiences of their own (a Team Cloud): a bot's tasks are then filtered one by one. */
215
215
  get filtersThreads() {
216
- return this.audiences !== null;
216
+ return this.audiences !== null || [...this.bots.values()].some(bot => bot.tasks?.some(task => task.botApi));
217
217
  }
218
218
  /** An unknown thread is not visible to a member; on a Team Cloud another person's conversation is visible to nobody,
219
219
  * an admin included. */
@@ -234,6 +234,10 @@ export class VisibleSet {
234
234
  return this.ownerOf(threadId) !== undefined ? !this.thread(threadId) : !this.audienceShows(threadId);
235
235
  }
236
236
  audienceShows(threadId) {
237
+ const holder = this.ownerOf(threadId);
238
+ const task = holder?.bot ? this.bots.get(holder.bot)?.tasks?.find(task => task.threadId === threadId) : undefined;
239
+ if (task?.botApi && (this.viewer.channelReviewUntil ?? 0) <= Date.now())
240
+ return false;
237
241
  const audience = this.audiences?.of(threadId);
238
242
  return audience === undefined || audienceIncludes(audience, { admin: this.viewer.kind === "all", person: this.audiences.person, seesRoom: (groupId) => this.group(groupId) });
239
243
  }
@@ -1,3 +1,4 @@
1
+ import { channelReviewActive } from "../limix-channel-review.js";
1
2
  // Who sees what on this server (bot-visibility.ts): each session's viewer and its VisibleSet (cached until the next bot,
2
3
  // room or conversation change), the one check every request naming a bot, conversation, room, routine or file passes, and
3
4
  // the per-conversation filter a list uses. On a Team Cloud an admin is a viewer with a person too: every bot and room, but
@@ -10,7 +11,7 @@ export function createVisibilityHost(deps) {
10
11
  group: (id) => deps.store().group(id), botByThread: (id) => deps.store().botByThread(id), groupByThread: (id) => deps.store().groupByThread(id) };
11
12
  function viewerFor(auth) {
12
13
  if (auth.kind === "loopback" || (auth.scopes.includes("admin") && !deps.team))
13
- return SEES_EVERYTHING;
14
+ return { ...SEES_EVERYTHING, channelReviewUntil: auth.channelReviewUntil };
14
15
  if (auth.scopes.includes("admin"))
15
16
  return { kind: "all", email: auth.session.email ?? "" };
16
17
  return { kind: "member", ...(auth.session.email ? { email: auth.session.email } : {}) };
@@ -30,6 +31,8 @@ export function createVisibilityHost(deps) {
30
31
  return owner ?? undefined;
31
32
  }
32
33
  function visibleTo(viewer) {
34
+ if (viewer.channelReviewUntil)
35
+ return new VisibleSet(store.bots, store.groups, { ...viewer, channelReviewUntil: channelReviewActive(viewer.channelReviewUntil) ? viewer.channelReviewUntil : 0 }, threadOwner, deps.audiencesFor(viewer));
33
36
  const key = viewer.kind === "all" ? (viewer.email === undefined ? "*" : `admin:${viewer.email.trim().toLowerCase()}`) : `member:${viewer.email?.trim().toLowerCase() ?? ""}`;
34
37
  let set = visibleSets.get(key);
35
38
  if (!set) {
@@ -1,3 +1,6 @@
1
+ import { channelReviewRoute, channelReviewUntil } from "./limix-channel-review.js";
2
+ import { ChannelIdentityRegistry } from "./limix-channel-identity.js";
3
+ import { BOT_API_INTERNAL_CHAT_REQUIRED } from "../shared/bot-api.js";
1
4
  // Import first: it reads a Cloud home's secrets off the launcher's pipe before any module can start a process.
2
5
  import { BOOT_CLOUD_SECRETS } from "./cloud-secrets-boot.js";
3
6
  import { startFailureText } from "./start-failure-text.js";
@@ -1157,8 +1160,7 @@ async function answeringCardAs(auth, threadId, requestId, work, via) {
1157
1160
  }
1158
1161
  const { viewerFor, threadOwner, visibleTo, forgetVisibility, threadShown, subjectVisible, hiddenRoutineTarget, roomFeedsBot, settleRoomFloor } = createVisibilityHost({ store: () => store, routines: () => routines,
1159
1162
  team: Boolean(CLOUD_TEAM), audiencesFor: (viewer) => { const audiences = teamHost.audiencesFor(viewer), person = audiences?.person; return audiences && person ? { ...audiences, routineHome: teamRoutines.home, ownTask: (task) => personRooms.taskForPerson(task, person) } : audiences && { ...audiences, routineHome: teamRoutines.home }; }, threadsReferencing });
1160
- if (CLOUD_TEAM)
1161
- hideOthersSyncFolders(() => store.bots, threadShown);
1163
+ hideOthersSyncFolders(() => store.bots, threadShown);
1162
1164
  const notificationListed = notificationListedFor(threadShown, CLOUD_TEAM ? (auth, entry) => teamOwners.routing.notificationReaches(teamOwners.viewer(auth), entry) : undefined, CLOUD_TEAM ? (auth) => (auth.kind === "session" ? personKey(auth.session) : null) : undefined);
1163
1165
  const botAccess = createBotAccessHost({ visibleFor: (auth) => visibleTo(viewerFor(auth)), store: () => store, routines: () => routines, threadOwner, routineWriter: (id) => cloudRoutineAuthors?.writer(id) }), { levelOf } = botAccess;
1164
1166
  const accessRequests = createAccessRequests({ team: CLOUD_TEAM, store: () => store, people: () => teamOwners.people?.list() ?? [], profileName: (email) => teamHost.people.profile(personKey({ id: "", email })).name, inbox: () => teamMessages.inbox, visibleTo, levelOf, writeAccess: (bot, access) => writeAccess({ store, publicGroupState, broadcast, audienceChanged }, bot, access), record: (row, by) => appendAdminAction(DATA_DIR, { ...row, actor: { kind: "session", sessionId: "", label: by, email: by } }) });
@@ -2241,10 +2243,10 @@ function hasDirectDispatch(botId) {
2241
2243
  return [...directTurnDispatchClaims.values()].some((claim) => claim.botId === botId);
2242
2244
  }
2243
2245
  /** Must match what startTurn admits for a direct thread. */
2244
- function canAdmitDirectTurn(botId, threadId) {
2246
+ function canAdmitDirectTurn(botId, threadId, startedByABot = true) {
2245
2247
  return admit("peer", {}, {
2246
2248
  threadBusy: threadBusy(botId, threadId),
2247
- atCapacity: botAtThreadCapacity(botId, undefined, true),
2249
+ atCapacity: botAtThreadCapacity(botId, threadId, startedByABot),
2248
2250
  groupTurn: Boolean(activeGroupTurnForBot(botId)),
2249
2251
  }).action === "start";
2250
2252
  }
@@ -7407,6 +7409,9 @@ class DirectSendRefused extends Error {
7407
7409
  }
7408
7410
  }
7409
7411
  function directSendRefusal(botId, threadId) {
7412
+ if (store.taskByThread(botId, threadId)?.botApi) {
7413
+ return new DirectSendRefused(409, { error: BOT_API_INTERNAL_CHAT_REQUIRED, code: "channel_thread" });
7414
+ }
7410
7415
  try {
7411
7416
  assertWithinBudget(cfg, DATA_DIR);
7412
7417
  }
@@ -9793,7 +9798,7 @@ const webhooks = new WebhookManager({
9793
9798
  }, ...createWebhookRoomPost({ store, cfg, roomTalks })
9794
9799
  });
9795
9800
  const webhookRequests = new WebhookRequestService({ store, webhooks, botName: (botId) => store.bot(botId)?.name ?? "the bot" });
9796
- const botApi = createBotApiHost({ store, startTurn, threadBusy, canStart: canAdmitDirectTurn, canConfine: (botId) => registry.get(store.bot(botId)?.modelSelection.instanceId ?? "")?.adapter.capabilities.guestTurns === "confined", discard: (botId, threadId) => { store.deleteTask(botId, threadId); }, included: () => !cloudPlanTier.starter(), opened: (threadId) => { if (CLOUD_OWNER_KEY)
9801
+ const botApi = createBotApiHost({ channelIdentities: new ChannelIdentityRegistry(join(DATA_DIR, "limix-channel-identities.json")), store, startTurn, threadBusy, canStart: (botId, threadId) => canAdmitDirectTurn(botId, threadId, false), canConfine: (botId) => registry.get(store.bot(botId)?.modelSelection.instanceId ?? "")?.adapter.capabilities.guestTurns === "confined", discard: (botId, threadId) => { store.deleteTask(botId, threadId); }, included: () => !cloudPlanTier.starter(), opened: (threadId) => { if (CLOUD_OWNER_KEY)
9797
9802
  threadStarters.set(threadId, CLOUD_OWNER_KEY); }, hooksBaseUrl: () => webhookIngressStatus().baseUrl, manageRefusal: (auth, botId) => auth.scopes.includes("admin") || (CLOUD_TEAM && levelOf(auth, botId) === "edit") ? null : refusalFor(store.bot(botId)?.name ?? "this bot", "edit").error, claimRequest: () => { cloudPower?.arrived("/hooks", {}); moveFreeze.assertTurns(); return workspaceMaintenance.request(); }, record: (auth, row) => appendAdminAction(DATA_DIR, { ...row, actor: decisionActorFor(auth) }) });
9798
9803
  const appTriggers = createAppTriggerHost({ store, webhooks, webhookBase: () => webhookIngressStatus().baseUrl, routines: () => routines, botState: unattendedDispatchState, timeZone: routineTimeZone, emit: broadcast, connectionMode: () => composio.connectionMode(cfg),
9799
9804
  access: composio.brokerAccess, connectedApps: () => composio.connectedServices(cfg), visibleBot: (auth, botId) => visibleTo(viewerFor(auth)).bot(botId),
@@ -12994,6 +12999,11 @@ const handleRequest = async (req, res) => {
12994
12999
  if (cloudPower && gate.auth.kind === "session")
12995
13000
  cloudPower.request(path, req.headers, res); // someone using a Cloud home keeps it awake
12996
13001
  const auth = gate.auth;
13002
+ auth.channelReviewUntil = channelReviewUntil(req.headers.cookie);
13003
+ if (await channelReviewRoute({ req, res, url, path, method, auth, json, readBody }))
13004
+ return;
13005
+ if (!auth.channelReviewUntil && (/backup|export|session-search|search|activity|logs/.test(path)) && store.bots.some(bot => bot.tasks?.some(task => task.botApi)))
13006
+ return json(res, 403, { error: "Unlock channel conversations before accessing archives, search or activity." });
12997
13007
  if (HOSTED_WORKSPACE && auth.kind === "session") {
12998
13008
  const failure = workspaceAccess
12999
13009
  ? await workspaceAccess.authorize(req, auth)
@@ -13012,7 +13022,12 @@ const handleRequest = async (req, res) => {
13012
13022
  return json(res, 403, refused);
13013
13023
  // Every bot a member is sent (on a Team Cloud an admin's too) comes narrowed to what they may see once the request is done (memberBot).
13014
13024
  if (viewer.kind === "member" || visible.filtersThreads)
13015
- onJsonBody(res, (body) => memberBody(body, visibleTo(viewer)));
13025
+ onJsonBody(res, (body) => {
13026
+ const narrowed = memberBody(body, visibleTo(viewer));
13027
+ if (!channelReviewUntil(req.headers.cookie) && path.endsWith("/bot-api") && narrowed && typeof narrowed === "object")
13028
+ return { ...narrowed, calls: [] };
13029
+ return narrowed;
13030
+ });
13016
13031
  beginAdminAudit(req, res, method, path, auth);
13017
13032
  if (method === "POST" && path === "/api/workspace-backup/restore" && teamComputers.list().some(computer => computer.section !== null)) {
13018
13033
  return json(res, 409, { error: "Unassign team computers before restoring a workspace; restored team names must not gain access to existing desktops" });
@@ -0,0 +1,41 @@
1
+ import { z } from "zod";
2
+ import { readFileSync, writeFileSync, renameSync, mkdirSync, existsSync } from "node:fs";
3
+ import { dirname } from "node:path";
4
+ const id = z.string().min(1).max(200).regex(/^[^\x00-\x1f]+$/);
5
+ export const channelConversationSchema = z.object({
6
+ connectionId: id, platform: z.enum(["telegram", "zalo", "discord", "facebook"]),
7
+ chatId: id, senderId: id, topicId: id.optional(), kind: z.enum(["private", "group"]),
8
+ }).strict().refine(value => value.kind !== "group" || value.senderId === "group");
9
+ export function channelScope(value, owner) {
10
+ return JSON.stringify([value.platform, value.connectionId, value.kind, value.chatId, value.topicId ?? "", value.senderId, owner]);
11
+ }
12
+ export function parseChannelHeader(value) {
13
+ if (value === undefined)
14
+ return undefined;
15
+ if (typeof value !== "string" || value.length > 2048 || !/^[A-Za-z0-9_-]+$/.test(value))
16
+ throw new Error("Invalid conversation identity");
17
+ return channelConversationSchema.parse(JSON.parse(Buffer.from(value, "base64url").toString("utf8")));
18
+ }
19
+ /** Bindings are additional to Bot API authorization. A different sender cannot continue a bound transcript. */
20
+ export class ChannelIdentityRegistry {
21
+ records;
22
+ file;
23
+ constructor(file) {
24
+ this.file = file;
25
+ this.records = existsSync(file) ? z.record(z.string(), z.string()).parse(JSON.parse(readFileSync(file, "utf8"))) : {};
26
+ }
27
+ matches(thread, identity, owner) {
28
+ const bound = this.records[thread];
29
+ return identity ? bound === channelScope(identity, owner) : bound === undefined;
30
+ }
31
+ bind(thread, identity, owner) {
32
+ const scope = channelScope(identity, owner);
33
+ if (this.records[thread] && this.records[thread] !== scope)
34
+ throw new Error("Conversation identity mismatch");
35
+ const next = { ...this.records, [thread]: scope };
36
+ mkdirSync(dirname(this.file), { recursive: true });
37
+ writeFileSync(this.file + ".tmp", JSON.stringify(next), { mode: 0o600 });
38
+ renameSync(this.file + ".tmp", this.file);
39
+ this.records = next;
40
+ }
41
+ }
@@ -0,0 +1,53 @@
1
+ import { randomBytes } from "node:crypto";
2
+ import { limixOwnerCall } from "./limix-owner-lane.js";
3
+ const grants = new Map();
4
+ const tickets = new Map();
5
+ export const channelReviewActive = (until) => until > Date.now() && [...grants.values()].includes(until);
6
+ export function channelReviewUntil(cookie) {
7
+ const token = /(?:^|; )limix_channel_review=([A-Za-z0-9_-]{43})(?:;|$)/.exec(cookie ?? "")?.[1];
8
+ const until = token ? grants.get(token) ?? 0 : 0;
9
+ return until > Date.now() ? until : 0;
10
+ }
11
+ export async function channelReviewRoute(ctx) {
12
+ const { path, method, req, res, auth, json, readBody } = ctx;
13
+ if (!path.startsWith("/api/limix/channel-review/"))
14
+ return false;
15
+ if (!auth.scopes.includes("admin") || method !== "POST") {
16
+ json(res, 403, { error: "Administrator access required" });
17
+ return true;
18
+ }
19
+ for (const map of [grants, tickets])
20
+ for (const [key, expiry] of map)
21
+ if (expiry <= Date.now())
22
+ map.delete(key);
23
+ if (path.endsWith("/grant")) {
24
+ if (!limixOwnerCall(req.headers["x-limix-owner"])) {
25
+ json(res, 403, { error: "Password verification required" });
26
+ return true;
27
+ }
28
+ const token = randomBytes(32).toString("base64url");
29
+ tickets.set(token, Date.now() + 30000);
30
+ json(res, 200, { token });
31
+ return true;
32
+ }
33
+ if (path.endsWith("/unlock")) {
34
+ const body = await readBody(req, 4096);
35
+ const token = body && typeof body.token === "string" ? body.token : "";
36
+ if (!tickets.has(token)) {
37
+ json(res, 403, { error: "Password verification expired" });
38
+ return true;
39
+ }
40
+ tickets.delete(token);
41
+ const session = randomBytes(32).toString("base64url"), until = Date.now() + 5 * 60000;
42
+ grants.set(session, until);
43
+ res.setHeader("set-cookie", `limix_channel_review=${session}; HttpOnly; SameSite=Strict; Path=/; Max-Age=300`);
44
+ json(res, 200, { until });
45
+ return true;
46
+ }
47
+ const token = /(?:^|; )limix_channel_review=([A-Za-z0-9_-]{43})/.exec(req.headers.cookie ?? "")?.[1];
48
+ if (token)
49
+ grants.delete(token);
50
+ res.setHeader("set-cookie", "limix_channel_review=; HttpOnly; SameSite=Strict; Path=/; Max-Age=0");
51
+ json(res, 200, { locked: true });
52
+ return true;
53
+ }
@@ -1,3 +1,4 @@
1
+ import { BOT_API_INTERNAL_CHAT_REQUIRED } from "../../shared/bot-api.js";
1
2
  import { randomUUID } from "node:crypto";
2
3
  import { z } from "zod";
3
4
  import { ROOM_VIEW_ONLY } from "../../shared/app.js";
@@ -120,6 +121,8 @@ export function createBotMessageRoutes(deps) {
120
121
  const notYours = cloudGuestSendRefusal(auth, threadId);
121
122
  if (notYours)
122
123
  return json(res, 403, { error: notYours });
124
+ if (store.taskByThread(bot.id, threadId)?.botApi)
125
+ return json(res, 409, { error: BOT_API_INTERNAL_CHAT_REQUIRED, code: "channel_thread" });
123
126
  if (body.mode !== undefined && body.mode !== "chat" && body.mode !== "goal")
124
127
  return json(res, 400, { error: "mode must be chat or goal" });
125
128
  if (body.mode === "goal") {
@@ -15,3 +15,4 @@ export function botApiCurl(endpoint, key = BOT_API_KEY_PLACEHOLDER) {
15
15
  ` -d '{"message": "Hello! What can you do?"}'`,
16
16
  ].join("\n");
17
17
  }
18
+ export const BOT_API_INTERNAL_CHAT_REQUIRED = "This conversation belongs to a connected channel. Open the bot internal chat to configure it; channel messages must arrive through its Bot API.";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "limixbot",
3
- "version": "0.3.40",
3
+ "version": "0.3.41",
4
4
  "description": "Run the Limix Bot server anywhere and pair your devices to it (Leox ৹ Limix AI)",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -1 +0,0 @@
1
- import{U as a,C as n}from"./mermaid.core-BkGLuasi.js";const t=(r,o)=>a.lang.round(n.parse(r)[o]);export{t as c};
@@ -1,8 +0,0 @@
1
- import{c as r,s as e}from"./flowDiagram-OXPTDLAJ-BoRQKWEE.js";import{_ as o}from"./mermaid.core-BkGLuasi.js";import"./chunk-5VM5RSS4-Ms8vx6uj.js";import"./chunk-XXDRQBXY-lLPvGZOB.js";import"./chunk-KQW6MTUR-C_OPTqju.js";import"./chunk-7TKQ45FW-CoQ_n3fY.js";import"./channel-CLFluAXE.js";import"./styles-CYPAO9i1.js";import"./step-CkmJJ7wq.js";var a=o(t=>`${e(t)}
2
- .swimlane.cluster:not([data-color-id]) rect {
3
- stroke: ${t.clusterBorder} !important;
4
- }
5
- [data-look="neo"].cluster rect {
6
- filter: none;
7
- }
8
- `,"getStyles"),m=a,y=r({styles:m});export{y as diagram};