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,122 @@
1
+ /**
2
+ * MCP: models outside the app (ChatGPT, Claude, any MCP client) call the
3
+ * app's tools: the same tools its own agents use, run the same way, each
4
+ * conversation a chat in the app, so what's built for its agents (a
5
+ * booking, its debugging, its queries) works for them too.
6
+ *
7
+ * - **A line** is an MCP server the app declares in its settings
8
+ * (`resources.mcp.lines.<name>`), at `POST /mcp/<name>` (under many orgs,
9
+ * `/o/<org>/mcp/<name>`): the space its conversations' chats live in, the
10
+ * tools it offers (`tools`, by name: only these, each with its
11
+ * `tool:<name>` View, what a model reads of it), how each is shown (its
12
+ * title, hints such as `readOnly`, what ChatGPT says while and after it
13
+ * runs), who calls (`client`, `ChatGPT`), its limits. Anyone may call it:
14
+ * no sign-in yet. In ChatGPT, the app's connector points at that URL.
15
+ * - **A conversation** is a contact (someone outside the org) in a chat of
16
+ * its own in the line's space: they reach that chat and nothing else; the
17
+ * space's members read it. ChatGPT names its conversation in every call
18
+ * (`_meta["openai/session"]`, with its user, `openai/subject`); a client
19
+ * that names none is given a handle (`chat`, which the line's tools then
20
+ * take), said once at the end of its first answer (`chat: <handle>`), or,
21
+ * with `handles: false`, is refused. Ids come from these through an HMAC
22
+ * with the app's secret (the `links` resource's): nothing maps them, and a
23
+ * stranger can't work out another's. Erased (`contact.forget`,
24
+ * `chat.erase`), a conversation is over for good (see processors/).
25
+ * - **A call** (see actions/call.ts) runs the tool through chat's runner,
26
+ * as the conversation's contact, and is written in the chat as a step,
27
+ * as an agent's is; its answer is what the app's own agents read of it
28
+ * (the tool's View); an error says its message only when it's public
29
+ * (`failure(code, message, { public: true })`). A request sent again to a
30
+ * tool that changes things is answered from the first; a read-only tool
31
+ * always runs.
32
+ * - **Limits** (a line's `limits`): calls at once (in the runtime, on the
33
+ * line, from one caller's address, in one conversation: the server is busy
34
+ * past them), how long the route waits for an answer (20 s: then the model
35
+ * is told it's still working, while few calls are, and asking again under
36
+ * any request id gets what it did, from its receipt) and a call may run (a
37
+ * minute: then it's stopped; tools should honour `ctx.signal`), calls a
38
+ * minute (by conversation, by caller's address, in all), new
39
+ * conversations an hour (by user, by address, in all), and sizes. Only
40
+ * calls taken count. The caller's address is believed only as the app's
41
+ * front says it (`caller`: its header, and its secret, without which a
42
+ * request is refused, or the proxies' hops); one that can't be read counts
43
+ * with every other such call, as one caller.
44
+ * - **The protocol** (see resources/server.ts): MCP's Streamable HTTP,
45
+ * JSON-RPC 2.0, with no session; 2026-07-28 and the versions with a
46
+ * handshake (2025-11-25, 2025-06-18, 2025-03-26). Tools are all it serves.
47
+ *
48
+ * **Security notes** (to verify in ChatGPT's developer mode before a line
49
+ * offers more):
50
+ *
51
+ * - **What names a conversation is a bearer value.** Whoever holds it
52
+ * reaches that chat as its contact. A handle is in the model's transcript
53
+ * (it has to be: a model reads only an answer's content, never its
54
+ * `_meta`), so it goes wherever the transcript goes (shared, exported).
55
+ * `openai/session` and `openai/subject` are ChatGPT's, sent only to us,
56
+ * but whether ChatGPT scopes `openai/session` to one connector (or the
57
+ * same id reaches every app in a conversation) isn't verified.
58
+ * - **So, until it is,** a line shouldn't offer tools that read personal
59
+ * data back (a saved buyer's details, past orders): a leaked key would
60
+ * read them. A tool that only writes, or reads what the conversation
61
+ * itself said, risks only that conversation.
62
+ * - **A tool's own Action calls** are plugin code, as an agent's tools'
63
+ * are on WhatsApp: their `allow` isn't asked (the rules still keep them to
64
+ * the contact's chat). A tool offered here may call trusted Actions for
65
+ * the contact: offer only tools whose every call is safe for anyone.
66
+ *
67
+ * ```ts
68
+ * plugins: [models, chat, ...access, mcp]
69
+ * resources: {
70
+ * links: { origin, secret }, // the secret its ids are made with
71
+ * spaces: { line: { name: "ChatGPT", agents: ["booking"] } },
72
+ * mcp: {
73
+ * caller: { header: "cf-connecting-ip", front: env.FRONT_SECRET },
74
+ * lines: { chatgpt: { in: "line", client: "ChatGPT", handles: false,
75
+ * tools: { search_trips: { annotations: { readOnly: true }, invoking: "Buscando…" } } } },
76
+ * },
77
+ * }
78
+ * views: { "tool:search_trips": { llm: tripsForModels } } // each offered tool's, in a plugin
79
+ * ```
80
+ */
81
+ import { definePlugin, linksOf } from "../../../runtime/mod.js";
82
+ import { callAction } from "./actions/call.js";
83
+ import { pruneAction } from "./actions/prune.js";
84
+ import { closed } from "./collections/closed.js";
85
+ import { rate } from "./collections/rate.js";
86
+ import { receipt } from "./collections/receipt.js";
87
+ import { erasedProcessor, forgottenProcessor } from "./processors/closed.js";
88
+ import { serveMcp } from "./resources/server.js";
89
+ import { linesOf, PATH, problemOf, settingsProblem } from "./shared/settings.js";
90
+ import { offeredView } from "./views/offered.js";
91
+ export * from "./contract.js";
92
+ export const mcp = definePlugin({
93
+ name: "mcp",
94
+ requires: ["chat", "spaces", "contacts"],
95
+ collections: { mcp_receipt: receipt, mcp_rate: rate, mcp_closed: closed },
96
+ actions: { "mcp.call": callAction, "mcp.prune": pruneAction },
97
+ processors: { "mcp.forgotten": forgottenProcessor, "mcp.erased": erasedProcessor },
98
+ // What's past goes: counters, receipts.
99
+ schedules: { "mcp.prune": { every: "10m", call: "mcp.prune", input: {} } },
100
+ // Which tools a contact is offered, as each tool's `offer` says.
101
+ views: { "mcp:offered": { mcp: offeredView } },
102
+ // At start: every line the app declares has what it needs, and the secret its ids come from.
103
+ check: (merged) => {
104
+ const settings = settingsProblem(merged.resources);
105
+ if (settings)
106
+ throw new Error(`mcp.${settings}`);
107
+ const lines = Object.entries(linesOf(merged));
108
+ if (lines.length && !linksOf(merged.resources)) {
109
+ throw new Error("mcp needs the links resource (its origin and secret): its ids are made with it");
110
+ }
111
+ for (const [name, line] of lines) {
112
+ const problem = problemOf(name, line, merged.resources);
113
+ if (problem)
114
+ throw new Error(`mcp.lines.${name} ${problem}`);
115
+ }
116
+ },
117
+ resources: {
118
+ mcp: {},
119
+ routes: { mcp: { path: PATH, serve: serveMcp } },
120
+ },
121
+ });
122
+ export default mcp;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Erasing an MCP conversation sticks. Its ids come from what names it
3
+ * (ChatGPT's session, a handle), so the same session would otherwise come
4
+ * back to the same contact and chat, made again. Instead, each is closed
5
+ * for good (`mcp_closed`), and the conversation's next call says so:
6
+ *
7
+ * - **A contact erased** (`contact.deleted`, `contact.forget`): one that
8
+ * came by MCP (`via: "mcp"`).
9
+ * - **A chat erased** (`thread.deleted`, `chat.erase`): an MCP chat (`mcp-…`).
10
+ */
11
+ import type { ProcessorDef } from "../../../../runtime/mod.js";
12
+ export declare const forgottenProcessor: ProcessorDef;
13
+ export declare const erasedProcessor: ProcessorDef;
@@ -0,0 +1,16 @@
1
+ const close = (ctx, id) => ctx.as().db.collection("mcp_closed").replaceOne({ _id: id }, { at: new Date().toISOString() }, { upsert: true });
2
+ export const forgottenProcessor = {
3
+ on: "contact.deleted",
4
+ where: { "doc.via": "mcp" },
5
+ key: (event) => String(event.data._id),
6
+ run: async (ctx, event) => void await close(ctx, `contact:${event.data._id}`),
7
+ };
8
+ export const erasedProcessor = {
9
+ on: "thread.deleted",
10
+ key: (event) => String(event.data._id),
11
+ run: async (ctx, event) => {
12
+ const thread = String(event.data._id);
13
+ if (thread.startsWith("mcp-"))
14
+ await close(ctx, `thread:${thread}`);
15
+ },
16
+ };
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Calls running now, counted by the MCP route for its limits at once: in
3
+ * the runtime, on a line, from a caller's address, in a conversation. Kept
4
+ * by runtime, so under the orgs host (a runtime each) one org's calls never
5
+ * take another's places. A request takes its places whole or not at all,
6
+ * and gives them back once it's answered. In this process's memory: a
7
+ * runtime's calls all come through it.
8
+ */
9
+ /** One count a request goes by: its key, the most it may reach, and how much the request adds. */
10
+ export type Place = {
11
+ key: string;
12
+ most: number;
13
+ adds?: number;
14
+ };
15
+ /** Takes every place, or none: its release (once), or undefined when one is full. */
16
+ export declare function hold(runtime: object, places: Place[]): (() => void) | undefined;
17
+ /** What a request too many is told, and thrown with, to answer as busy. */
18
+ export declare const busy: () => Error & {
19
+ busy: true;
20
+ };
21
+ export declare const isBusy: (error: unknown) => boolean;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Calls running now, counted by the MCP route for its limits at once: in
3
+ * the runtime, on a line, from a caller's address, in a conversation. Kept
4
+ * by runtime, so under the orgs host (a runtime each) one org's calls never
5
+ * take another's places. A request takes its places whole or not at all,
6
+ * and gives them back once it's answered. In this process's memory: a
7
+ * runtime's calls all come through it.
8
+ */
9
+ const running = new WeakMap();
10
+ /** Takes every place, or none: its release (once), or undefined when one is full. */
11
+ export function hold(runtime, places) {
12
+ const counts = running.get(runtime) ?? new Map();
13
+ running.set(runtime, counts);
14
+ if (places.some((p) => (counts.get(p.key) ?? 0) + (p.adds ?? 1) > p.most))
15
+ return undefined;
16
+ for (const p of places)
17
+ counts.set(p.key, (counts.get(p.key) ?? 0) + (p.adds ?? 1));
18
+ let released = false;
19
+ return () => {
20
+ if (released)
21
+ return;
22
+ released = true;
23
+ for (const p of places) {
24
+ const left = (counts.get(p.key) ?? 0) - (p.adds ?? 1);
25
+ if (left > 0)
26
+ counts.set(p.key, left);
27
+ else
28
+ counts.delete(p.key);
29
+ }
30
+ };
31
+ }
32
+ /** What a request too many is told, and thrown with, to answer as busy. */
33
+ export const busy = () => Object.assign(new Error("Busy: too many calls at once. Try again in a moment."), {
34
+ busy: true,
35
+ });
36
+ export const isBusy = (error) => error?.busy === true;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * The MCP route: each line's server at `POST /mcp/<line>` (under many orgs,
3
+ * `/o/<org>/mcp/<line>`), MCP's Streamable HTTP transport, written here
4
+ * with no dependency. It keeps no session: every request carries all it
5
+ * needs, as ChatGPT sends them (it stopped echoing `Mcp-Session-Id` in 2026)
6
+ * and as MCP 2026-07-28 says.
7
+ *
8
+ * - **HTTP.** A POST, `application/json`, within the line's `body` limit,
9
+ * answered with JSON (never a stream). GET and DELETE answer 405: there's
10
+ * no stream to open and no session to end. A request with an `Origin` (a
11
+ * browser's page) is refused unless the line names it: no browser calls
12
+ * MCP. No cookie is read: whoever calls is nobody but their
13
+ * conversation's contact.
14
+ * - **Who calls.** With the app's `caller` settings, the caller's address,
15
+ * as its front says it (see shared/caller.ts); a request that came around
16
+ * the front (without its secret) is refused (403).
17
+ * - **At once.** Tool calls running at once: in the runtime (`mcp.atOnce`,
18
+ * 4), on the line (`limits.atOnce`, 4), from one caller's address
19
+ * (`addressAtOnce`, 2: a batch's every call counts) and in one
20
+ * conversation (`chatAtOnce`, 2), each call taking its places until it's
21
+ * done. Past any, it's busy (503, `Retry-After`, -31000, its own code),
22
+ * before anything runs; in a batch, that call's answer says so (and a
23
+ * batch busy for every call is a 503). A batch with more tool calls than
24
+ * one caller may run at once could never be served: it's refused
25
+ * (-32600). A call that hasn't answered within the line's `timeout` is
26
+ * answered "still working" while it goes on, as long as few do (2 on the
27
+ * line, 1 from an address); else it's stopped (see tools.ts).
28
+ * - **JSON-RPC 2.0.** One message a request. A notification (or a reply)
29
+ * answers 202. Bad JSON is -32700, a malformed message -32600, an unknown
30
+ * method -32601, bad params -32602; what fails inside says -32603 and
31
+ * nothing more (it's logged here). A batch (a list of messages) is taken
32
+ * only from a 2025-03-26 client (later versions have none; that one's
33
+ * servers must take them): at most 10 messages, answered one after
34
+ * another, as one call at once.
35
+ * - **Versions.** 2026-07-28 (modern: no handshake; each request says its
36
+ * version and capabilities in `_meta`, and repeats its method and name in
37
+ * headers, which must match: else 400, -32020) and 2025-11-25, 2025-06-18
38
+ * and 2025-03-26 (legacy: `initialize`, answered without a session id; a
39
+ * request without `MCP-Protocol-Version` is 2025-03-26). Any other is 400,
40
+ * -32022, with those it takes.
41
+ * - **Methods.** `initialize`, `server/discover`, `ping`, `tools/list`,
42
+ * `tools/call` (see tools.ts). Tools are all the server has.
43
+ *
44
+ * Sources: https://modelcontextprotocol.io/specification/2026-07-28 (transport,
45
+ * versioning, tools), https://modelcontextprotocol.io/specification/2025-11-25,
46
+ * https://developers.openai.com/apps-sdk/reference (ChatGPT's `_meta`).
47
+ */
48
+ import { type Runtime } from "../../../../runtime/mod.js";
49
+ /** What the web host hands the route: the runtime. */
50
+ export type McpHost = {
51
+ runtime: Pick<Runtime, "call" | "cancel" | "describe" | "observe">;
52
+ };
53
+ /** Answers a request to `/mcp/<line>`. */
54
+ export declare function serveMcp(request: Request, host?: McpHost): Promise<Response>;