copilotz 1.0.0-rc.20 → 1.0.0-rc.21

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 (340) hide show
  1. package/CHANGELOG.md +417 -0
  2. package/README.md +295 -19
  3. package/hosts/orgs/mod.d.ts +4 -1
  4. package/hosts/orgs/mod.js +2 -2
  5. package/hosts/web/files.d.ts +6 -2
  6. package/hosts/web/files.js +36 -3
  7. package/hosts/web/node/mod.d.ts +1 -1
  8. package/hosts/web/node/mod.js +1 -1
  9. package/hosts/web/node/serve.d.ts +26 -0
  10. package/hosts/web/node/serve.js +23 -1
  11. package/hosts/web/routes.d.ts +28 -1
  12. package/hosts/web/routes.js +65 -10
  13. package/hosts/web/server.d.ts +5 -4
  14. package/hosts/web/server.js +1 -1
  15. package/package.json +2 -2
  16. package/plugins/access/accounts/collections/account.d.ts +2 -2
  17. package/plugins/access/contacts/actions/chat.d.ts +1 -0
  18. package/plugins/access/contacts/actions/chat.js +45 -0
  19. package/plugins/access/contacts/actions/forget.d.ts +1 -0
  20. package/plugins/access/contacts/actions/forget.js +56 -0
  21. package/plugins/access/contacts/actions/start.d.ts +1 -0
  22. package/plugins/access/contacts/actions/start.js +50 -0
  23. package/plugins/access/contacts/collections/contact.d.ts +81 -0
  24. package/plugins/access/contacts/collections/contact.js +58 -0
  25. package/plugins/access/contacts/contract.d.ts +10 -0
  26. package/plugins/access/contacts/contract.js +10 -0
  27. package/plugins/access/contacts/mod.d.ts +27 -0
  28. package/plugins/access/contacts/mod.js +49 -0
  29. package/plugins/access/contacts/views/contact.d.ts +8 -0
  30. package/plugins/access/contacts/views/contact.js +25 -0
  31. package/plugins/access/contacts/web.d.ts +7 -0
  32. package/plugins/access/contacts/web.js +11 -0
  33. package/plugins/access/directory/collections/credit-code.d.ts +1 -1
  34. package/plugins/access/directory/collections/invite.d.ts +1 -1
  35. package/plugins/access/identity/mod.js +8 -6
  36. package/plugins/access/mod.d.ts +7 -1
  37. package/plugins/access/mod.js +7 -2
  38. package/plugins/access/spaces/actions/agents.js +12 -6
  39. package/plugins/access/spaces/actions/create.js +10 -1
  40. package/plugins/access/spaces/actions/invitation.js +5 -2
  41. package/plugins/access/spaces/actions/keep.d.ts +1 -0
  42. package/plugins/access/spaces/actions/keep.js +55 -0
  43. package/plugins/access/spaces/actions/member.js +17 -4
  44. package/plugins/access/spaces/actions/rename.js +4 -0
  45. package/plugins/access/spaces/collections/member.d.ts +1 -1
  46. package/plugins/access/spaces/collections/request.d.ts +1 -1
  47. package/plugins/access/spaces/collections/space.d.ts +9 -0
  48. package/plugins/access/spaces/collections/space.js +2 -0
  49. package/plugins/access/spaces/contract.d.ts +4 -3
  50. package/plugins/access/spaces/contract.js +1 -1
  51. package/plugins/access/spaces/mod.d.ts +7 -1
  52. package/plugins/access/spaces/mod.js +8 -1
  53. package/plugins/access/spaces/resources/tools.d.ts +0 -5
  54. package/plugins/access/spaces/resources/tools.js +11 -1
  55. package/plugins/access/spaces/shared/agents.js +2 -2
  56. package/plugins/access/spaces/shared/can.d.ts +18 -3
  57. package/plugins/access/spaces/shared/can.js +32 -5
  58. package/plugins/access/spaces/shared/declared.d.ts +21 -0
  59. package/plugins/access/spaces/shared/declared.js +8 -0
  60. package/plugins/access/spaces/shared/labels.d.ts +7 -1
  61. package/plugins/access/spaces/shared/labels.js +56 -8
  62. package/plugins/access/spaces/shared/managers.js +2 -2
  63. package/plugins/access/spaces/shared/names.d.ts +9 -5
  64. package/plugins/access/spaces/shared/names.js +36 -19
  65. package/plugins/access/spaces/shared/reach.d.ts +20 -6
  66. package/plugins/access/spaces/shared/reach.js +62 -20
  67. package/plugins/access/spaces/shared/rules.d.ts +10 -5
  68. package/plugins/access/spaces/shared/rules.js +35 -10
  69. package/plugins/access/spaces/shared/seat.d.ts +3 -2
  70. package/plugins/access/spaces/shared/seat.js +9 -2
  71. package/plugins/access/spaces/views/where.d.ts +4 -2
  72. package/plugins/access/spaces/views/where.js +9 -0
  73. package/plugins/access/spaces/web.js +1 -1
  74. package/plugins/access/web.d.ts +1 -0
  75. package/plugins/access/web.js +1 -0
  76. package/plugins/agents/chat/actions/erase.d.ts +1 -0
  77. package/plugins/agents/chat/actions/erase.js +51 -0
  78. package/plugins/agents/chat/actions/open.d.ts +1 -0
  79. package/plugins/agents/chat/actions/open.js +49 -0
  80. package/plugins/agents/chat/actions/quiet.d.ts +1 -0
  81. package/plugins/agents/chat/actions/quiet.js +33 -0
  82. package/plugins/agents/chat/actions/say.d.ts +1 -0
  83. package/plugins/agents/chat/actions/say.js +82 -0
  84. package/plugins/agents/chat/actions/send.js +57 -19
  85. package/plugins/agents/chat/actions/shown.d.ts +1 -0
  86. package/plugins/agents/chat/actions/shown.js +35 -0
  87. package/plugins/agents/chat/collections/intent.d.ts +124 -0
  88. package/plugins/agents/chat/collections/intent.js +52 -0
  89. package/plugins/agents/chat/collections/message.d.ts +74 -1
  90. package/plugins/agents/chat/collections/message.js +23 -1
  91. package/plugins/agents/chat/collections/shown.d.ts +105 -0
  92. package/plugins/agents/chat/collections/shown.js +34 -0
  93. package/plugins/agents/chat/contract.d.ts +15 -7
  94. package/plugins/agents/chat/contract.js +7 -1
  95. package/plugins/agents/chat/mod.d.ts +20 -2
  96. package/plugins/agents/chat/mod.js +43 -4
  97. package/plugins/agents/chat/processors/failed.js +15 -5
  98. package/plugins/agents/chat/processors/turn.d.ts +1 -1
  99. package/plugins/agents/chat/processors/turn.js +95 -35
  100. package/plugins/agents/chat/shared/delivery.d.ts +16 -2
  101. package/plugins/agents/chat/shared/delivery.js +62 -7
  102. package/plugins/agents/chat/shared/send.d.ts +1 -3
  103. package/plugins/agents/chat/shared/send.js +2 -9
  104. package/plugins/agents/chat/shared/tools.d.ts +33 -0
  105. package/plugins/agents/chat/shared/tools.js +28 -0
  106. package/plugins/agents/chat/shared/types.d.ts +59 -1
  107. package/plugins/agents/chat/views/message.d.ts +4 -2
  108. package/plugins/agents/chat/views/message.js +22 -4
  109. package/plugins/agents/chat/views/prompt.js +38 -4
  110. package/plugins/agents/history/collections/outline.d.ts +1 -1
  111. package/plugins/agents/history/collections/summary.d.ts +1 -1
  112. package/plugins/agents/history/mod.js +2 -1
  113. package/plugins/agents/history/processors/erase.d.ts +3 -0
  114. package/plugins/agents/history/processors/erase.js +11 -0
  115. package/plugins/agents/memory/mod.js +2 -1
  116. package/plugins/agents/memory/processors/extract.d.ts +1 -1
  117. package/plugins/agents/memory/processors/extract.js +5 -0
  118. package/plugins/agents/memory/resources/tools.js +1 -1
  119. package/plugins/agents/memory/shared/settings.d.ts +7 -2
  120. package/plugins/agents/memory/shared/settings.js +9 -1
  121. package/plugins/agents/routines/collections/routine.d.ts +1 -1
  122. package/plugins/agents/routines/collections/run.d.ts +1 -1
  123. package/plugins/compute/apps/collections/app.d.ts +2 -2
  124. package/plugins/compute/cloud/resources/tools.js +3 -3
  125. package/plugins/compute/computers/collections/approval.d.ts +2 -2
  126. package/plugins/compute/computers/collections/grant.d.ts +1 -1
  127. package/plugins/compute/computers/collections/preview.d.ts +2 -2
  128. package/plugins/compute/computers/program/version.d.ts +1 -1
  129. package/plugins/compute/computers/program/version.js +1 -1
  130. package/plugins/compute/computers/resources/downloads.js +1 -1
  131. package/plugins/compute/computers/shared/wake.d.ts +1 -1
  132. package/plugins/compute/computers/shared/wake.js +17 -0
  133. package/plugins/interfaces/api/collections/key.d.ts +1 -1
  134. package/plugins/interfaces/api/shared/events.js +5 -4
  135. package/plugins/interfaces/maintenance/actions/read.d.ts +4 -0
  136. package/plugins/interfaces/maintenance/actions/read.js +76 -0
  137. package/plugins/interfaces/maintenance/actions/write.d.ts +4 -0
  138. package/plugins/interfaces/maintenance/actions/write.js +64 -0
  139. package/plugins/interfaces/maintenance/contract.d.ts +60 -0
  140. package/plugins/interfaces/maintenance/contract.js +2 -0
  141. package/plugins/interfaces/maintenance/mod.d.ts +52 -0
  142. package/plugins/interfaces/maintenance/mod.js +66 -0
  143. package/plugins/interfaces/maintenance/resources/routes.d.ts +71 -0
  144. package/plugins/interfaces/maintenance/resources/routes.js +457 -0
  145. package/plugins/interfaces/maintenance/shared/ops.d.ts +4 -0
  146. package/plugins/interfaces/maintenance/shared/ops.js +19 -0
  147. package/plugins/interfaces/mcp/actions/call.d.ts +11 -0
  148. package/plugins/interfaces/mcp/actions/call.js +304 -0
  149. package/plugins/interfaces/mcp/actions/prune.d.ts +1 -0
  150. package/plugins/interfaces/mcp/actions/prune.js +18 -0
  151. package/plugins/interfaces/mcp/collections/closed.d.ts +23 -0
  152. package/plugins/interfaces/mcp/collections/closed.js +17 -0
  153. package/plugins/interfaces/mcp/collections/rate.d.ts +27 -0
  154. package/plugins/interfaces/mcp/collections/rate.js +18 -0
  155. package/plugins/interfaces/mcp/collections/receipt.d.ts +46 -0
  156. package/plugins/interfaces/mcp/collections/receipt.js +46 -0
  157. package/plugins/interfaces/mcp/contract.d.ts +9 -0
  158. package/plugins/interfaces/mcp/contract.js +9 -0
  159. package/plugins/interfaces/mcp/mod.d.ts +84 -0
  160. package/plugins/interfaces/mcp/mod.js +122 -0
  161. package/plugins/interfaces/mcp/processors/closed.d.ts +13 -0
  162. package/plugins/interfaces/mcp/processors/closed.js +16 -0
  163. package/plugins/interfaces/mcp/resources/running.d.ts +21 -0
  164. package/plugins/interfaces/mcp/resources/running.js +36 -0
  165. package/plugins/interfaces/mcp/resources/server.d.ts +54 -0
  166. package/plugins/interfaces/mcp/resources/server.js +423 -0
  167. package/plugins/interfaces/mcp/resources/tools.d.ts +114 -0
  168. package/plugins/interfaces/mcp/resources/tools.js +324 -0
  169. package/plugins/interfaces/mcp/shared/caller.d.ts +45 -0
  170. package/plugins/interfaces/mcp/shared/caller.js +99 -0
  171. package/plugins/interfaces/mcp/shared/keys.d.ts +50 -0
  172. package/plugins/interfaces/mcp/shared/keys.js +53 -0
  173. package/plugins/interfaces/mcp/shared/settings.d.ts +187 -0
  174. package/plugins/interfaces/mcp/shared/settings.js +176 -0
  175. package/plugins/interfaces/mcp/views/offered.d.ts +20 -0
  176. package/plugins/interfaces/mcp/views/offered.js +20 -0
  177. package/plugins/interfaces/mod.d.ts +5 -1
  178. package/plugins/interfaces/mod.js +5 -1
  179. package/plugins/interfaces/terminal/actions/print.js +1 -1
  180. package/plugins/interfaces/terminal/actions/set.js +1 -1
  181. package/plugins/interfaces/terminal/collections/output.d.ts +1 -1
  182. package/plugins/interfaces/terminal/collections/shell.js +1 -1
  183. package/plugins/interfaces/voice/actions/block.d.ts +2 -0
  184. package/plugins/interfaces/voice/actions/block.js +74 -0
  185. package/plugins/interfaces/voice/actions/call.d.ts +19 -0
  186. package/plugins/interfaces/voice/actions/call.js +253 -0
  187. package/plugins/interfaces/voice/actions/hook.d.ts +5 -0
  188. package/plugins/interfaces/voice/actions/hook.js +225 -0
  189. package/plugins/interfaces/voice/actions/prune.d.ts +1 -0
  190. package/plugins/interfaces/voice/actions/prune.js +35 -0
  191. package/plugins/interfaces/voice/collections/blocked.d.ts +87 -0
  192. package/plugins/interfaces/voice/collections/blocked.js +34 -0
  193. package/plugins/interfaces/voice/collections/call.d.ts +279 -0
  194. package/plugins/interfaces/voice/collections/call.js +77 -0
  195. package/plugins/interfaces/voice/collections/phone.d.ts +74 -0
  196. package/plugins/interfaces/voice/collections/phone.js +26 -0
  197. package/plugins/interfaces/voice/contract.d.ts +14 -0
  198. package/plugins/interfaces/voice/contract.js +2 -0
  199. package/plugins/interfaces/voice/mod.d.ts +57 -0
  200. package/plugins/interfaces/voice/mod.js +118 -0
  201. package/plugins/interfaces/voice/processors/forget.d.ts +13 -0
  202. package/plugins/interfaces/voice/processors/forget.js +27 -0
  203. package/plugins/interfaces/voice/resources/relay.d.ts +77 -0
  204. package/plugins/interfaces/voice/resources/relay.js +428 -0
  205. package/plugins/interfaces/voice/resources/tools.d.ts +1 -0
  206. package/plugins/interfaces/voice/resources/tools.js +25 -0
  207. package/plugins/interfaces/voice/shared/caller.d.ts +27 -0
  208. package/plugins/interfaces/voice/shared/caller.js +38 -0
  209. package/plugins/interfaces/voice/shared/settings.d.ts +136 -0
  210. package/plugins/interfaces/voice/shared/settings.js +121 -0
  211. package/plugins/interfaces/voice/shared/signature.d.ts +11 -0
  212. package/plugins/interfaces/voice/shared/signature.js +34 -0
  213. package/plugins/interfaces/voice/views/call.d.ts +41 -0
  214. package/plugins/interfaces/voice/views/call.js +30 -0
  215. package/plugins/interfaces/voice/views/context.d.ts +9 -0
  216. package/plugins/interfaces/voice/views/context.js +14 -0
  217. package/plugins/interfaces/voice/views/message.d.ts +17 -0
  218. package/plugins/interfaces/voice/views/message.js +41 -0
  219. package/plugins/interfaces/whatsapp/actions/connect.js +3 -0
  220. package/plugins/interfaces/whatsapp/actions/disconnect.js +4 -1
  221. package/plugins/interfaces/whatsapp/actions/hook.js +27 -11
  222. package/plugins/interfaces/whatsapp/actions/set.d.ts +8 -0
  223. package/plugins/interfaces/whatsapp/actions/set.js +121 -0
  224. package/plugins/interfaces/whatsapp/collections/blocked.d.ts +29 -0
  225. package/plugins/interfaces/whatsapp/collections/blocked.js +22 -0
  226. package/plugins/interfaces/whatsapp/collections/code.d.ts +1 -1
  227. package/plugins/interfaces/whatsapp/collections/number.d.ts +90 -4
  228. package/plugins/interfaces/whatsapp/collections/number.js +36 -4
  229. package/plugins/interfaces/whatsapp/collections/phone.d.ts +13 -3
  230. package/plugins/interfaces/whatsapp/collections/phone.js +9 -3
  231. package/plugins/interfaces/whatsapp/collections/rate.d.ts +27 -0
  232. package/plugins/interfaces/whatsapp/collections/rate.js +13 -0
  233. package/plugins/interfaces/whatsapp/collections/sent.d.ts +24 -12
  234. package/plugins/interfaces/whatsapp/collections/sent.js +11 -7
  235. package/plugins/interfaces/whatsapp/collections/thread.d.ts +14 -6
  236. package/plugins/interfaces/whatsapp/collections/thread.js +7 -5
  237. package/plugins/interfaces/whatsapp/collections/typing.d.ts +70 -0
  238. package/plugins/interfaces/whatsapp/collections/typing.js +21 -0
  239. package/plugins/interfaces/whatsapp/contract.d.ts +27 -4
  240. package/plugins/interfaces/whatsapp/contract.js +34 -1
  241. package/plugins/interfaces/whatsapp/events/undelivered.d.ts +8 -0
  242. package/plugins/interfaces/whatsapp/events/undelivered.js +17 -0
  243. package/plugins/interfaces/whatsapp/mod.d.ts +28 -2
  244. package/plugins/interfaces/whatsapp/mod.js +65 -6
  245. package/plugins/interfaces/whatsapp/processors/forget.d.ts +6 -0
  246. package/plugins/interfaces/whatsapp/processors/forget.js +11 -0
  247. package/plugins/interfaces/whatsapp/processors/receive.d.ts +17 -3
  248. package/plugins/interfaces/whatsapp/processors/receive.js +264 -81
  249. package/plugins/interfaces/whatsapp/processors/reply.d.ts +25 -5
  250. package/plugins/interfaces/whatsapp/processors/reply.js +216 -20
  251. package/plugins/interfaces/whatsapp/processors/typing.d.ts +8 -0
  252. package/plugins/interfaces/whatsapp/processors/typing.js +25 -0
  253. package/plugins/interfaces/whatsapp/shared/customers.d.ts +13 -0
  254. package/plugins/interfaces/whatsapp/shared/customers.js +16 -0
  255. package/plugins/interfaces/whatsapp/shared/graph.d.ts +31 -6
  256. package/plugins/interfaces/whatsapp/shared/graph.js +117 -10
  257. package/plugins/interfaces/whatsapp/shared/media.d.ts +23 -0
  258. package/plugins/interfaces/whatsapp/shared/media.js +46 -0
  259. package/plugins/interfaces/whatsapp/shared/number.d.ts +19 -8
  260. package/plugins/interfaces/whatsapp/shared/number.js +64 -7
  261. package/plugins/interfaces/whatsapp/shared/parts.d.ts +94 -0
  262. package/plugins/interfaces/whatsapp/shared/parts.js +184 -0
  263. package/plugins/interfaces/whatsapp/shared/payload.d.ts +27 -1
  264. package/plugins/interfaces/whatsapp/shared/payload.js +36 -1
  265. package/plugins/interfaces/whatsapp/shared/settings.d.ts +49 -1
  266. package/plugins/interfaces/whatsapp/shared/settings.js +11 -0
  267. package/plugins/interfaces/whatsapp/views/message.d.ts +13 -0
  268. package/plugins/interfaces/whatsapp/views/message.js +13 -0
  269. package/plugins/interfaces/whatsapp/views/web/line.d.ts +24 -0
  270. package/plugins/interfaces/whatsapp/views/web/line.js +44 -0
  271. package/plugins/interfaces/whatsapp/views/web/space.d.ts +7 -5
  272. package/plugins/interfaces/whatsapp/views/web/space.js +17 -10
  273. package/plugins/interfaces/whatsapp/views/web/style.d.ts +1 -1
  274. package/plugins/interfaces/whatsapp/views/web/style.js +8 -0
  275. package/plugins/models/adapters/llm/anthropic.d.ts +1 -1
  276. package/plugins/models/adapters/llm/anthropic.js +28 -15
  277. package/plugins/models/adapters/llm/gemini.d.ts +1 -1
  278. package/plugins/models/adapters/llm/gemini.js +2 -1
  279. package/plugins/models/adapters/llm/openai-compatible.d.ts +1 -1
  280. package/plugins/models/adapters/llm/openai-compatible.js +2 -1
  281. package/plugins/models/adapters/llm/openai.d.ts +1 -1
  282. package/plugins/models/adapters/llm/openai.js +16 -4
  283. package/plugins/models/shared/types.d.ts +8 -0
  284. package/plugins/models/shared/types.js +10 -0
  285. package/runtime/actor.d.ts +6 -0
  286. package/runtime/actor.js +9 -4
  287. package/runtime/aggregate.js +8 -2
  288. package/runtime/blobs.d.ts +15 -12
  289. package/runtime/blobs.js +58 -11
  290. package/runtime/cache.d.ts +6 -0
  291. package/runtime/cache.js +19 -1
  292. package/runtime/define.d.ts +10 -0
  293. package/runtime/errors.d.ts +20 -2
  294. package/runtime/errors.js +7 -1
  295. package/runtime/executor.js +27 -11
  296. package/runtime/links.d.ts +31 -0
  297. package/runtime/links.js +60 -0
  298. package/runtime/maintain.d.ts +88 -0
  299. package/runtime/maintain.js +120 -0
  300. package/runtime/memory.js +7 -4
  301. package/runtime/mod.d.ts +6 -4
  302. package/runtime/mod.js +5 -2
  303. package/runtime/mongo.d.ts +13 -0
  304. package/runtime/mongo.js +39 -8
  305. package/runtime/observe.d.ts +2 -0
  306. package/runtime/observe.js +14 -10
  307. package/runtime/ops.d.ts +5 -0
  308. package/runtime/ops.js +10 -1
  309. package/runtime/owner.d.ts +18 -1
  310. package/runtime/owner.js +127 -61
  311. package/runtime/presence.d.ts +18 -0
  312. package/runtime/presence.js +25 -0
  313. package/runtime/registry.d.ts +5 -0
  314. package/runtime/registry.js +18 -0
  315. package/runtime/runtime.js +9 -3
  316. package/runtime/store.d.ts +48 -1
  317. package/runtime/wire.d.ts +1 -0
  318. package/runtime/wire.js +3 -1
  319. package/stores/blobs/files/mod.js +4 -2
  320. package/stores/blobs/gcs/mod.d.ts +3 -0
  321. package/stores/blobs/gcs/mod.js +6 -5
  322. package/stores/blobs/http/mod.d.ts +1 -1
  323. package/stores/blobs/http/mod.js +2 -1
  324. package/stores/latency/mod.js +5 -1
  325. package/stores/sql/postgres/maintenance.d.ts +24 -0
  326. package/stores/sql/postgres/maintenance.js +258 -0
  327. package/stores/sql/postgres/mod.d.ts +20 -4
  328. package/stores/sql/postgres/mod.js +363 -96
  329. package/stores/sql/postgres/update.js +3 -1
  330. package/stores/sql/shared/capped.d.ts +2 -0
  331. package/stores/sql/shared/capped.js +22 -0
  332. package/stores/sql/shared/rows.d.ts +14 -0
  333. package/stores/sql/shared/rows.js +29 -0
  334. package/stores/sql/shared/statement.d.ts +12 -0
  335. package/stores/sql/shared/statement.js +244 -0
  336. package/stores/sql/sqlite/apart.d.ts +11 -0
  337. package/stores/sql/sqlite/apart.js +219 -0
  338. package/stores/sql/sqlite/mod.d.ts +16 -2
  339. package/stores/sql/sqlite/mod.js +246 -51
  340. package/testing/mod.js +1 -1
@@ -0,0 +1,121 @@
1
+ /**
2
+ * `whatsapp.set`: those who manage a number's space open it to anyone, or
3
+ * close it again (`open`: a customer line, where a stranger who writes is a
4
+ * contact, in a chat of their own, answered by its agent), choose who
5
+ * answers there (`agent`: one that answers in the space; null, who answers
6
+ * new chats there) and how long a chat stays quiet before a customer's next
7
+ * message starts a new one (`gap`, in hours: 12 unless set), how many
8
+ * messages a customer may send a minute (`rate`: 20), how long they may
9
+ * write on before the agent answers them all at once (`quiet`, seconds: 4),
10
+ * and the language
11
+ * customers are told things in (`language`: `en`, `pt`). Closed again,
12
+ * strangers are told how to link their phone; its chats stay where they are.
13
+ * A Personal space's number isn't opened: it's its person's alone.
14
+ */
15
+ import { defineAction, failure, inPerson } from "../../../../runtime/mod.js";
16
+ import { GAP } from "../collections/number.js";
17
+ import { blockedKey } from "../collections/blocked.js";
18
+ import { mustManage } from "./connect.js";
19
+ import { PERSONAL } from "../../../access/spaces/contract.js";
20
+ export const setAction = defineAction({
21
+ description: "Opens a WhatsApp number to anyone (a customer line), or closes it",
22
+ input: {
23
+ type: "object",
24
+ properties: {
25
+ number: { type: "string" },
26
+ open: { type: "boolean" },
27
+ agent: { type: ["string", "null"] },
28
+ /** Hours. */
29
+ gap: { type: "number", minimum: 1, maximum: 720 },
30
+ /** Messages a customer may send a minute. */
31
+ rate: { type: "integer", minimum: 1, maximum: 600 },
32
+ /** Seconds a customer may write on before the agent answers. */
33
+ quiet: { type: "number", minimum: 0, maximum: 30 },
34
+ language: { type: "string", enum: ["en", "pt"] },
35
+ },
36
+ required: ["number"],
37
+ additionalProperties: false,
38
+ },
39
+ allow: inPerson,
40
+ run: async (ctx, input) => {
41
+ const numbers = ctx.db.collection("whatsapp_number");
42
+ const found = await numbers.findOne({ _id: input.number });
43
+ if (!found)
44
+ throw failure("not_found", "No such number here.");
45
+ await mustManage(ctx, found.in, "change its number");
46
+ if (found.declared) {
47
+ throw failure("invalid", "This number is the app's own: its settings say how it works.");
48
+ }
49
+ if (input.open) {
50
+ const space = await ctx.db.collection("space").findOne({ _id: found.in });
51
+ if (space?.kind === PERSONAL) {
52
+ throw failure("invalid", "A customer line belongs in a shared space: a Personal one is yours alone.");
53
+ }
54
+ }
55
+ const agent = input.agent;
56
+ if (agent) {
57
+ const { agents } = await ctx.call("space.roster", { space: found.in });
58
+ if (!agents.includes(agent)) {
59
+ throw failure("invalid", `"${agent}" doesn't answer in this space: add it as an editor first.`);
60
+ }
61
+ }
62
+ const set = {
63
+ ...(input.open ? { open: true } : {}),
64
+ ...(agent ? { agent } : {}),
65
+ ...(input.gap !== undefined ? { gap: input.gap } : {}),
66
+ ...(input.rate !== undefined ? { rate: input.rate } : {}),
67
+ ...(input.quiet !== undefined ? { quiet: input.quiet } : {}),
68
+ ...(input.language ? { language: input.language } : {}),
69
+ };
70
+ const unset = {
71
+ ...(input.open === false ? { open: "" } : {}),
72
+ ...(agent === null ? { agent: "" } : {}),
73
+ };
74
+ if (Object.keys(set).length || Object.keys(unset).length) {
75
+ // As the person: the rules say they manage the space.
76
+ await numbers.updateOne({ _id: found._id }, {
77
+ ...(Object.keys(set).length ? { $set: set } : {}),
78
+ ...(Object.keys(unset).length ? { $unset: unset } : {}),
79
+ });
80
+ }
81
+ const now = await numbers.findOne({ _id: found._id });
82
+ return { open: !!now?.open, agent: now?.agent ?? null, gap: now?.gap ?? GAP };
83
+ },
84
+ });
85
+ /**
86
+ * `whatsapp.block`: those who manage a number's space block the phone of
87
+ * one of its chats (a customer who abuses the line), or let it in again:
88
+ * what a blocked phone sends goes nowhere, and nothing is said to it, even
89
+ * once the contact is erased (the block is kept by the phone's hash).
90
+ */
91
+ export const blockAction = defineAction({
92
+ description: "Blocks the phone behind a WhatsApp chat, or lets it in again",
93
+ input: {
94
+ type: "object",
95
+ properties: { thread: { type: "string" }, blocked: { type: "boolean" } },
96
+ required: ["thread", "blocked"],
97
+ additionalProperties: false,
98
+ },
99
+ allow: inPerson,
100
+ run: async (ctx, input) => {
101
+ const system = ctx.as().db;
102
+ const chat = await system.collection("whatsapp_thread")
103
+ .findOne({ _id: input.thread });
104
+ const number = chat
105
+ ? await system.collection("whatsapp_number").findOne({ _id: chat.number })
106
+ : null;
107
+ if (!chat || !number)
108
+ throw failure("not_found", "No WhatsApp chat here.");
109
+ await mustManage(ctx, number.in, "block a phone");
110
+ const _id = await blockedKey(number._id, chat.phone);
111
+ const blocks = system.collection("whatsapp_blocked");
112
+ if (input.blocked) {
113
+ await blocks.replaceOne({ _id }, { number: number._id, at: new Date().toISOString() }, {
114
+ upsert: true,
115
+ });
116
+ }
117
+ else
118
+ await blocks.deleteOne({ _id });
119
+ return { blocked: input.blocked };
120
+ },
121
+ });
@@ -0,0 +1,29 @@
1
+ export declare const blocked: {
2
+ schema: {
3
+ readonly type: "object";
4
+ readonly properties: {
5
+ readonly number: {
6
+ readonly type: "string";
7
+ };
8
+ readonly at: {
9
+ readonly type: "string";
10
+ };
11
+ };
12
+ readonly required: readonly ["number", "at"];
13
+ };
14
+ events?: boolean;
15
+ records?: boolean;
16
+ durable?: false;
17
+ indexes?: string[][];
18
+ private?: string[];
19
+ queries?: Record<string, import("../../../../runtime/define.js").QueryDef<{
20
+ [x: string]: unknown;
21
+ number: string;
22
+ at: string;
23
+ } & {
24
+ _id: string;
25
+ }>> | undefined;
26
+ vectors?: string[];
27
+ };
28
+ /** A blocked phone's key: the number, and the phone's hash. */
29
+ export declare function blockedKey(number: string, phone: string): Promise<string>;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Phones a number's people blocked (`whatsapp.block`), by the number and a
3
+ * hash of the phone (`<number>:<sha256>`): what they send goes nowhere. Kept
4
+ * apart from the phone's own row, so erasing a contact (`contact.forget`)
5
+ * doesn't let them in again. The phone is kept only as that hash, which is
6
+ * unkeyed: someone holding the database could find it by trying every phone
7
+ * number. No events.
8
+ */
9
+ import { defineCollection } from "../../../../runtime/mod.js";
10
+ export const blocked = defineCollection({
11
+ schema: {
12
+ type: "object",
13
+ properties: { number: { type: "string" }, at: { type: "string" } },
14
+ required: ["number", "at"],
15
+ },
16
+ events: false,
17
+ });
18
+ /** A blocked phone's key: the number, and the phone's hash. */
19
+ export async function blockedKey(number, phone) {
20
+ const hash = await crypto.subtle.digest("SHA-256", new TextEncoder().encode(phone));
21
+ return `${number}:${[...new Uint8Array(hash)].map((b) => b.toString(16).padStart(2, "0")).join("")}`;
22
+ }
@@ -64,8 +64,8 @@ export declare const code: {
64
64
  [x: string]: unknown;
65
65
  number: string;
66
66
  at: string;
67
- code: string;
68
67
  person: string;
68
+ code: string;
69
69
  expires: string;
70
70
  } & {
71
71
  _id: string;
@@ -1,10 +1,11 @@
1
1
  /**
2
2
  * WhatsApp Business numbers connected to the app, each in a space (an
3
3
  * org's, a team's): its members see it and link their phones to it; those
4
- * who manage the space connect and disconnect it. What Meta knows it by (its
5
- * phone number id) and as (the number shown, the business's name). Its
6
- * credentials aren't here: they're in `whatsapp_secret`, which nothing
7
- * outside reads and no event carries.
4
+ * who manage the space connect and disconnect it, and may open it to anyone
5
+ * (`open`: a customer line, whose strangers are contacts, answered by
6
+ * `agent`). What Meta knows it by (its phone number id) and as (the number
7
+ * shown, the business's name). Its credentials aren't here: they're in
8
+ * `whatsapp_secret`, which nothing outside reads and no event carries.
8
9
  */
9
10
  import { type Infer } from "../../../../runtime/mod.js";
10
11
  declare const numberSchema: {
@@ -38,12 +39,58 @@ declare const numberSchema: {
38
39
  readonly problem: {
39
40
  readonly type: "string";
40
41
  };
42
+ /** Open to anyone: a customer line. Strangers who write are contacts, each in a chat. */
43
+ readonly open: {
44
+ readonly type: "boolean";
45
+ };
46
+ /** Who answers its customers: an agent of its space (else who answers new chats there). */
47
+ readonly agent: {
48
+ readonly type: "string";
49
+ };
50
+ /** Hours of quiet after which a customer's next message starts a new chat (`GAP`). */
51
+ readonly gap: {
52
+ readonly type: "number";
53
+ };
54
+ /** Messages a customer may send a minute (20): more go unanswered. */
55
+ readonly rate: {
56
+ readonly type: "integer";
57
+ };
58
+ /**
59
+ * Seconds a customer may write on before the agent answers (`QUIET`, up
60
+ * to 30; 0: at once): a burst of short messages gets one answer.
61
+ */
62
+ readonly quiet: {
63
+ readonly type: "number";
64
+ };
65
+ /** What customers are told in, when their message can't go on: `en`, `pt`. */
66
+ readonly language: {
67
+ readonly type: "string";
68
+ readonly enum: readonly ["en", "pt"];
69
+ };
70
+ /** The app's own line (its settings' `lines`): kept as they say, changed only there. */
71
+ readonly declared: {
72
+ readonly type: "boolean";
73
+ };
41
74
  readonly at: {
42
75
  readonly type: "string";
43
76
  };
44
77
  };
45
78
  readonly required: readonly ["in", "phoneId", "phone", "at"];
46
79
  };
80
+ /**
81
+ * Hours a customer's chat stays the one they're in, quiet: past them, their
82
+ * next message starts a new chat. Twelve: a conversation that goes on later
83
+ * the same day (asking in the morning, paying at lunch) stays one chat, and
84
+ * one the next morning starts afresh, inside the 24 hours Meta lets a
85
+ * business answer freely.
86
+ */
87
+ export declare const GAP = 12;
88
+ /**
89
+ * Seconds a customer's chat waits, quiet, before its agent answers: people
90
+ * send two or three short messages a few seconds apart, and each answer
91
+ * costs a turn and a message.
92
+ */
93
+ export declare const QUIET = 4;
47
94
  export declare const number: {
48
95
  schema: {
49
96
  readonly type: "object";
@@ -76,6 +123,38 @@ export declare const number: {
76
123
  readonly problem: {
77
124
  readonly type: "string";
78
125
  };
126
+ /** Open to anyone: a customer line. Strangers who write are contacts, each in a chat. */
127
+ readonly open: {
128
+ readonly type: "boolean";
129
+ };
130
+ /** Who answers its customers: an agent of its space (else who answers new chats there). */
131
+ readonly agent: {
132
+ readonly type: "string";
133
+ };
134
+ /** Hours of quiet after which a customer's next message starts a new chat (`GAP`). */
135
+ readonly gap: {
136
+ readonly type: "number";
137
+ };
138
+ /** Messages a customer may send a minute (20): more go unanswered. */
139
+ readonly rate: {
140
+ readonly type: "integer";
141
+ };
142
+ /**
143
+ * Seconds a customer may write on before the agent answers (`QUIET`, up
144
+ * to 30; 0: at once): a burst of short messages gets one answer.
145
+ */
146
+ readonly quiet: {
147
+ readonly type: "number";
148
+ };
149
+ /** What customers are told in, when their message can't go on: `en`, `pt`. */
150
+ readonly language: {
151
+ readonly type: "string";
152
+ readonly enum: readonly ["en", "pt"];
153
+ };
154
+ /** The app's own line (its settings' `lines`): kept as they say, changed only there. */
155
+ readonly declared: {
156
+ readonly type: "boolean";
157
+ };
79
158
  readonly at: {
80
159
  readonly type: "string";
81
160
  };
@@ -91,8 +170,15 @@ export declare const number: {
91
170
  [x: string]: unknown;
92
171
  by?: string | undefined;
93
172
  name?: string | undefined;
173
+ declared?: boolean | undefined;
174
+ open?: boolean | undefined;
94
175
  url?: string | undefined;
95
176
  problem?: string | undefined;
177
+ language?: "en" | "pt" | undefined;
178
+ agent?: string | undefined;
179
+ gap?: number | undefined;
180
+ quiet?: number | undefined;
181
+ rate?: number | undefined;
96
182
  at: string;
97
183
  in: string;
98
184
  phoneId: string;
@@ -1,10 +1,11 @@
1
1
  /**
2
2
  * WhatsApp Business numbers connected to the app, each in a space (an
3
3
  * org's, a team's): its members see it and link their phones to it; those
4
- * who manage the space connect and disconnect it. What Meta knows it by (its
5
- * phone number id) and as (the number shown, the business's name). Its
6
- * credentials aren't here: they're in `whatsapp_secret`, which nothing
7
- * outside reads and no event carries.
4
+ * who manage the space connect and disconnect it, and may open it to anyone
5
+ * (`open`: a customer line, whose strangers are contacts, answered by
6
+ * `agent`). What Meta knows it by (its phone number id) and as (the number
7
+ * shown, the business's name). Its credentials aren't here: they're in
8
+ * `whatsapp_secret`, which nothing outside reads and no event carries.
8
9
  */
9
10
  import { defineCollection } from "../../../../runtime/mod.js";
10
11
  const numberSchema = {
@@ -24,8 +25,39 @@ const numberSchema = {
24
25
  by: { type: "string" },
25
26
  /** What went wrong last talking to Meta (its token refused, say), until it works again. */
26
27
  problem: { type: "string" },
28
+ /** Open to anyone: a customer line. Strangers who write are contacts, each in a chat. */
29
+ open: { type: "boolean" },
30
+ /** Who answers its customers: an agent of its space (else who answers new chats there). */
31
+ agent: { type: "string" },
32
+ /** Hours of quiet after which a customer's next message starts a new chat (`GAP`). */
33
+ gap: { type: "number" },
34
+ /** Messages a customer may send a minute (20): more go unanswered. */
35
+ rate: { type: "integer" },
36
+ /**
37
+ * Seconds a customer may write on before the agent answers (`QUIET`, up
38
+ * to 30; 0: at once): a burst of short messages gets one answer.
39
+ */
40
+ quiet: { type: "number" },
41
+ /** What customers are told in, when their message can't go on: `en`, `pt`. */
42
+ language: { type: "string", enum: ["en", "pt"] },
43
+ /** The app's own line (its settings' `lines`): kept as they say, changed only there. */
44
+ declared: { type: "boolean" },
27
45
  at: { type: "string" },
28
46
  },
29
47
  required: ["in", "phoneId", "phone", "at"],
30
48
  };
49
+ /**
50
+ * Hours a customer's chat stays the one they're in, quiet: past them, their
51
+ * next message starts a new chat. Twelve: a conversation that goes on later
52
+ * the same day (asking in the morning, paying at lunch) stays one chat, and
53
+ * one the next morning starts afresh, inside the 24 hours Meta lets a
54
+ * business answer freely.
55
+ */
56
+ export const GAP = 12;
57
+ /**
58
+ * Seconds a customer's chat waits, quiet, before its agent answers: people
59
+ * send two or three short messages a few seconds apart, and each answer
60
+ * costs a turn and a message.
61
+ */
62
+ export const QUIET = 4;
31
63
  export const number = defineCollection({ schema: numberSchema, indexes: [["phoneId"]] });
@@ -4,8 +4,9 @@
4
4
  * sent the code the app gave them, and, for them, where their messages go
5
5
  * (`space`, their Personal space unless they chose another; `thread`, the
6
6
  * conversation they're in). One that isn't linked is only what's needed to
7
- * answer it politely, once a day, and to stop guessing codes. Each person
8
- * reads their own.
7
+ * answer it politely, once a day, and to stop guessing codes; on an open
8
+ * number, it's a contact (`contact`), in the chat it's in (`thread`). Each
9
+ * person reads their own.
9
10
  */
10
11
  import { type Infer } from "../../../../runtime/mod.js";
11
12
  declare const phoneSchema: {
@@ -38,6 +39,10 @@ declare const phoneSchema: {
38
39
  readonly thread: {
39
40
  readonly type: "string";
40
41
  };
42
+ /** On an open number, the contact it is (someone outside the org). */
43
+ readonly contact: {
44
+ readonly type: "string";
45
+ };
41
46
  /** When it was last told how to link: once a day. */
42
47
  readonly told: {
43
48
  readonly type: "string";
@@ -86,6 +91,10 @@ export declare const phone: {
86
91
  readonly thread: {
87
92
  readonly type: "string";
88
93
  };
94
+ /** On an open number, the contact it is (someone outside the org). */
95
+ readonly contact: {
96
+ readonly type: "string";
97
+ };
89
98
  /** When it was last told how to link: once a day. */
90
99
  readonly told: {
91
100
  readonly type: "string";
@@ -110,8 +119,9 @@ export declare const phone: {
110
119
  private?: string[];
111
120
  queries?: Record<string, import("../../../../runtime/define.js").QueryDef<{
112
121
  [x: string]: unknown;
113
- name?: string | undefined;
114
122
  person?: string | undefined;
123
+ contact?: string | undefined;
124
+ name?: string | undefined;
115
125
  thread?: string | undefined;
116
126
  told?: string | undefined;
117
127
  since?: string | undefined;
@@ -4,8 +4,9 @@
4
4
  * sent the code the app gave them, and, for them, where their messages go
5
5
  * (`space`, their Personal space unless they chose another; `thread`, the
6
6
  * conversation they're in). One that isn't linked is only what's needed to
7
- * answer it politely, once a day, and to stop guessing codes. Each person
8
- * reads their own.
7
+ * answer it politely, once a day, and to stop guessing codes; on an open
8
+ * number, it's a contact (`contact`), in the chat it's in (`thread`). Each
9
+ * person reads their own.
9
10
  */
10
11
  import { defineCollection } from "../../../../runtime/mod.js";
11
12
  const phoneSchema = {
@@ -24,6 +25,8 @@ const phoneSchema = {
24
25
  space: { type: "string" },
25
26
  /** The conversation their messages go to; a new one without it. */
26
27
  thread: { type: "string" },
28
+ /** On an open number, the contact it is (someone outside the org). */
29
+ contact: { type: "string" },
27
30
  /** When it was last told how to link: once a day. */
28
31
  told: { type: "string" },
29
32
  /** Codes it sent that didn't match, since `since`. */
@@ -33,4 +36,7 @@ const phoneSchema = {
33
36
  },
34
37
  required: ["number", "phone", "at"],
35
38
  };
36
- export const phone = defineCollection({ schema: phoneSchema, indexes: [["person"]] });
39
+ export const phone = defineCollection({
40
+ schema: phoneSchema,
41
+ indexes: [["person"], ["contact"]],
42
+ });
@@ -0,0 +1,27 @@
1
+ export declare const rate: {
2
+ schema: {
3
+ readonly type: "object";
4
+ readonly properties: {
5
+ readonly minute: {
6
+ readonly type: "integer";
7
+ };
8
+ readonly count: {
9
+ readonly type: "integer";
10
+ };
11
+ };
12
+ readonly required: readonly ["minute", "count"];
13
+ };
14
+ events?: boolean;
15
+ records?: boolean;
16
+ durable?: false;
17
+ indexes?: string[][];
18
+ private?: string[];
19
+ queries?: Record<string, import("../../../../runtime/define.js").QueryDef<{
20
+ [x: string]: unknown;
21
+ count: number;
22
+ minute: number;
23
+ } & {
24
+ _id: string;
25
+ }>> | undefined;
26
+ vectors?: string[];
27
+ };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * How many messages each customer's phone sent this minute (`<number>:<phone>`),
3
+ * for its number's `rate`. Kept in memory: gone on restart, when it matters least.
4
+ */
5
+ import { defineCollection } from "../../../../runtime/mod.js";
6
+ export const rate = defineCollection({
7
+ durable: false,
8
+ schema: {
9
+ type: "object",
10
+ properties: { minute: { type: "integer" }, count: { type: "integer" } },
11
+ required: ["minute", "count"],
12
+ },
13
+ });
@@ -1,19 +1,25 @@
1
1
  /**
2
2
  * What went out to WhatsApp: each part of an agent's message, once sent
3
- * (`<message>:<part>`), with WhatsApp's id for it. A ledger: a retried
4
- * delivery sends only the parts not on it, and a reply quoting one finds
5
- * the message it was.
3
+ * (`<message>:<part>`), and of what went after it (an addition,
4
+ * `<message>:<key>:<part>`), with WhatsApp's id for it. A ledger: a retried
5
+ * delivery sends only the parts not on it, and a reply quoting one (or a
6
+ * tap on it) finds the message it was, and the addition.
6
7
  */
7
8
  import { type Infer } from "../../../../runtime/mod.js";
8
9
  declare const sentSchema: {
9
10
  readonly type: "object";
10
11
  readonly properties: {
11
- /** The chat message it was (part of). */
12
+ /** The chat message it was (part of), or went after. */
12
13
  readonly message: {
13
14
  readonly type: "string";
14
15
  };
15
- readonly part: {
16
- readonly type: "integer";
16
+ /** Its chat. */
17
+ readonly thread: {
18
+ readonly type: "string";
19
+ };
20
+ /** The addition it was part of: `trips:9f2a`. */
21
+ readonly key: {
22
+ readonly type: "string";
17
23
  };
18
24
  /** WhatsApp's id for it. */
19
25
  readonly wamid: {
@@ -23,18 +29,23 @@ declare const sentSchema: {
23
29
  readonly type: "string";
24
30
  };
25
31
  };
26
- readonly required: readonly ["message", "part", "wamid", "at"];
32
+ readonly required: readonly ["message", "wamid", "at"];
27
33
  };
28
34
  export declare const sent: {
29
35
  schema: {
30
36
  readonly type: "object";
31
37
  readonly properties: {
32
- /** The chat message it was (part of). */
38
+ /** The chat message it was (part of), or went after. */
33
39
  readonly message: {
34
40
  readonly type: "string";
35
41
  };
36
- readonly part: {
37
- readonly type: "integer";
42
+ /** Its chat. */
43
+ readonly thread: {
44
+ readonly type: "string";
45
+ };
46
+ /** The addition it was part of: `trips:9f2a`. */
47
+ readonly key: {
48
+ readonly type: "string";
38
49
  };
39
50
  /** WhatsApp's id for it. */
40
51
  readonly wamid: {
@@ -44,7 +55,7 @@ export declare const sent: {
44
55
  readonly type: "string";
45
56
  };
46
57
  };
47
- readonly required: readonly ["message", "part", "wamid", "at"];
58
+ readonly required: readonly ["message", "wamid", "at"];
48
59
  };
49
60
  events?: boolean;
50
61
  records?: boolean;
@@ -53,9 +64,10 @@ export declare const sent: {
53
64
  private?: string[];
54
65
  queries?: Record<string, import("../../../../runtime/define.js").QueryDef<{
55
66
  [x: string]: unknown;
67
+ key?: string | undefined;
68
+ thread?: string | undefined;
56
69
  at: string;
57
70
  message: string;
58
- part: number;
59
71
  wamid: string;
60
72
  } & {
61
73
  _id: string;
@@ -1,24 +1,28 @@
1
1
  /**
2
2
  * What went out to WhatsApp: each part of an agent's message, once sent
3
- * (`<message>:<part>`), with WhatsApp's id for it. A ledger: a retried
4
- * delivery sends only the parts not on it, and a reply quoting one finds
5
- * the message it was.
3
+ * (`<message>:<part>`), and of what went after it (an addition,
4
+ * `<message>:<key>:<part>`), with WhatsApp's id for it. A ledger: a retried
5
+ * delivery sends only the parts not on it, and a reply quoting one (or a
6
+ * tap on it) finds the message it was, and the addition.
6
7
  */
7
8
  import { defineCollection } from "../../../../runtime/mod.js";
8
9
  const sentSchema = {
9
10
  type: "object",
10
11
  properties: {
11
- /** The chat message it was (part of). */
12
+ /** The chat message it was (part of), or went after. */
12
13
  message: { type: "string" },
13
- part: { type: "integer" },
14
+ /** Its chat. */
15
+ thread: { type: "string" },
16
+ /** The addition it was part of: `trips:9f2a`. */
17
+ key: { type: "string" },
14
18
  /** WhatsApp's id for it. */
15
19
  wamid: { type: "string" },
16
20
  at: { type: "string" },
17
21
  },
18
- required: ["message", "part", "wamid", "at"],
22
+ required: ["message", "wamid", "at"],
19
23
  };
20
24
  export const sent = defineCollection({
21
25
  schema: sentSchema,
22
26
  records: true,
23
- indexes: [["message"], ["wamid"]],
27
+ indexes: [["message"], ["wamid", "thread"]],
24
28
  });
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * Conversations that happen on WhatsApp, by thread id: the number and phone
3
- * they're with, and whose phone it is. What agents say there to that person
4
- * goes out to the phone, even after they've moved on to a new conversation.
5
- * Each person reads their own.
3
+ * they're with, and whose phone it is: a person's, or a contact's (a
4
+ * customer on an open number). What agents say there to them goes out to
5
+ * the phone, even after they've moved on to a new conversation. Each person
6
+ * reads their own.
6
7
  */
7
8
  import { type Infer } from "../../../../runtime/mod.js";
8
9
  declare const threadSchema: {
@@ -18,11 +19,14 @@ declare const threadSchema: {
18
19
  readonly person: {
19
20
  readonly type: "string";
20
21
  };
22
+ readonly contact: {
23
+ readonly type: "string";
24
+ };
21
25
  readonly at: {
22
26
  readonly type: "string";
23
27
  };
24
28
  };
25
- readonly required: readonly ["number", "phone", "person", "at"];
29
+ readonly required: readonly ["number", "phone", "at"];
26
30
  };
27
31
  export declare const chat: {
28
32
  schema: {
@@ -38,11 +42,14 @@ export declare const chat: {
38
42
  readonly person: {
39
43
  readonly type: "string";
40
44
  };
45
+ readonly contact: {
46
+ readonly type: "string";
47
+ };
41
48
  readonly at: {
42
49
  readonly type: "string";
43
50
  };
44
51
  };
45
- readonly required: readonly ["number", "phone", "person", "at"];
52
+ readonly required: readonly ["number", "phone", "at"];
46
53
  };
47
54
  events?: boolean;
48
55
  records?: boolean;
@@ -51,9 +58,10 @@ export declare const chat: {
51
58
  private?: string[];
52
59
  queries?: Record<string, import("../../../../runtime/define.js").QueryDef<{
53
60
  [x: string]: unknown;
61
+ person?: string | undefined;
62
+ contact?: string | undefined;
54
63
  number: string;
55
64
  at: string;
56
- person: string;
57
65
  phone: string;
58
66
  } & {
59
67
  _id: string;