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
@@ -1,4 +1,5 @@
1
1
  import { nameOf, namesIn } from "../shared/names.js";
2
+ import { docKey } from "../shared/reach.js";
2
3
  const who = (key) => {
3
4
  const [kind, ...rest] = key.split(":");
4
5
  return { kind, id: rest.join(":") };
@@ -12,13 +13,20 @@ export const whereView = (thread, ctx) => {
12
13
  const members = ctx.db.collection("member").find({ space: thread.in }).value ?? [];
13
14
  const sources = ctx.db.collection("member").find({ member: `space:${thread.in}` }).value ??
14
15
  [];
16
+ const outside = thread._id
17
+ ? ctx.db.collection("member").find({ space: docKey("thread", thread._id) }).value ?? []
18
+ : [];
15
19
  if (!space)
16
20
  return undefined;
17
21
  // People by name.
18
22
  const names = namesIn(ctx, [
19
23
  ...(space.owner ? [space.owner] : []),
20
24
  ...members.filter((m) => m.member.startsWith("person:")).map((m) => m.member),
25
+ ...outside.map((m) => m.member),
21
26
  ]);
27
+ const shared = outside.length
28
+ ? `Also in it, from outside the org: ${outside.map((m) => nameOf(m.member, names)).join(", ")}. They see only this conversation: whatever you write here, they read too.`
29
+ : "";
22
30
  if (space.kind === "personal") {
23
31
  const owner = nameOf(space.owner ?? "", names);
24
32
  return `This conversation is in ${owner}'s Personal space: only ${owner} sees what's here.`;
@@ -35,5 +43,6 @@ export const whereView = (thread, ctx) => {
35
43
  sources.length
36
44
  ? `It draws on: ${sources.map((s) => `${s.space} (${s.role})`).join(", ")}.`
37
45
  : "",
46
+ shared,
38
47
  ].filter(Boolean).join("\n");
39
48
  };
@@ -63,7 +63,7 @@ export const spacesWeb = definePlugin({
63
63
  },
64
64
  resources: {
65
65
  // Where people's names are, for Views here too: a browser loads only front ends.
66
- names: { collection: PROFILE },
66
+ names: { people: { collection: PROFILE } },
67
67
  sidebar: {
68
68
  invitations: { view: "invitations", order: 3 },
69
69
  spaces: { title: "Spaces", view: "spaces", order: 10 },
@@ -1,3 +1,4 @@
1
1
  /** The access theme's web front ends, for the browser, beside the plugins they show. */
2
2
  export * from "./spaces/web.js";
3
3
  export { accountsWeb } from "./accounts/web.js";
4
+ export { contactsWeb } from "./contacts/web.js";
@@ -1,3 +1,4 @@
1
1
  /** The access theme's web front ends, for the browser, beside the plugins they show. */
2
2
  export * from "./spaces/web.js";
3
3
  export { accountsWeb } from "./accounts/web.js";
4
+ export { contactsWeb } from "./contacts/web.js";
@@ -0,0 +1 @@
1
+ export declare const eraseAction: import("../../../../runtime/define.js").ActionDef;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * `chat.erase`: a chat, gone with everything chat keeps of it (its messages,
3
+ * files, waits, what's being written, the steps in flight, turns waiting for
4
+ * a quiet moment, and the subthreads hanging from it), for erasing someone's personal data (LGPD,
5
+ * GDPR). Other plugins erase what they keep of it on `thread.deleted` (the
6
+ * history plugin, its summaries). Ledgers (records: what was `shown` after
7
+ * its answers, what went out to WhatsApp) can't be changed, and the event
8
+ * log keeps what happened: both stay until retention removes them. Trusted
9
+ * code only: it calls this once it decided whose data goes (`contact.forget`).
10
+ */
11
+ import { defineAction } from "../../../../runtime/mod.js";
12
+ import { quietId } from "../shared/delivery.js";
13
+ export const eraseAction = defineAction({
14
+ description: "Erases a chat and everything in it",
15
+ input: {
16
+ type: "object",
17
+ properties: { thread: { type: "string" } },
18
+ required: ["thread"],
19
+ additionalProperties: false,
20
+ },
21
+ run: async (ctx, input) => {
22
+ const messages = ctx.db.collection("message");
23
+ // The chat and the subthreads hanging from it, all the way down: one read per level.
24
+ const all = [input.thread];
25
+ for (let level = [input.thread]; level.length;) {
26
+ const hanging = await messages.find({ thread: { $in: level }, subthread: { $exists: true } });
27
+ level = hanging.map((m) => m.subthread).filter((id) => !all.includes(id));
28
+ all.push(...level);
29
+ }
30
+ // Who wrote there, and who answers there: their quiet windows (`chat.send`'s `quiet`) end too.
31
+ const [senders, threads] = await Promise.all([
32
+ messages.find({ thread: { $in: all } }),
33
+ ctx.db.collection("thread").find({ _id: { $in: all } }),
34
+ ]);
35
+ const from = [...new Set(senders.map((m) => m.from))];
36
+ const agents = [...new Set(threads.flatMap((t) => t.agents ?? []))];
37
+ await ctx.transaction(async (tx) => {
38
+ for (const thread of all) {
39
+ for (const sender of from) {
40
+ for (const agent of agents)
41
+ tx.unschedule(quietId(thread, sender, agent));
42
+ }
43
+ }
44
+ for (const collection of ["message", "file", "live", "wait", "intent"]) {
45
+ await tx.db.collection(collection).deleteMany({ thread: { $in: all } });
46
+ }
47
+ await tx.db.collection("thread").deleteMany({ _id: { $in: all } });
48
+ });
49
+ return { erased: all.length };
50
+ },
51
+ });
@@ -0,0 +1 @@
1
+ export declare const openAction: import("../../../../runtime/define.js").ActionDef;
@@ -0,0 +1,49 @@
1
+ /**
2
+ * `chat.open`: an empty chat in a space, before anything is said in it: a
3
+ * chat to share on its own (a contact's, on a customer line), or one a page
4
+ * opens. With `thread`, that's its id, and opening it again changes nothing
5
+ * (a retry opens the same one). Its messages go to `agents`, who must answer
6
+ * in the space (`not_here` otherwise), else to who answers new chats there.
7
+ */
8
+ import { defineAction, failure, people } from "../../../../runtime/mod.js";
9
+ import { agentsNamed, now, rosterOf } from "../shared/agents.js";
10
+ export const openAction = defineAction({
11
+ description: "Opens an empty chat in a space",
12
+ input: {
13
+ type: "object",
14
+ properties: {
15
+ thread: { type: "string", minLength: 1, maxLength: 200 },
16
+ in: { type: "string", minLength: 1 },
17
+ agents: { type: "array", items: { type: "string" }, maxItems: 10 },
18
+ title: { type: "string", minLength: 1, maxLength: 120 },
19
+ /** An agent working there may name it, as what it found. */
20
+ renamable: { type: "boolean" },
21
+ },
22
+ required: ["in"],
23
+ additionalProperties: false,
24
+ },
25
+ allow: people,
26
+ run: async (ctx, input) => {
27
+ const threads = ctx.db.collection("thread");
28
+ const id = input.thread ?? crypto.randomUUID();
29
+ if (input.thread && await threads.findOne({ _id: id }))
30
+ return { thread: id };
31
+ const roster = await rosterOf(ctx, input.in);
32
+ const asked = input.agents ?? roster.default;
33
+ const agents = await agentsNamed(ctx, asked);
34
+ const away = asked.filter((name) => !agents[name] || (!roster.open && !roster.here.includes(name)));
35
+ if (away.length) {
36
+ throw failure("not_here", `${away.join(", ")} ${away.length === 1 ? "doesn't" : "don't"} answer in that space.`);
37
+ }
38
+ await threads.insertOne({
39
+ _id: id,
40
+ agents: asked,
41
+ in: input.in,
42
+ ...(input.title ? { title: input.title } : {}),
43
+ ...(input.renamable ? { renamable: true } : {}),
44
+ messages: 0,
45
+ at: now(),
46
+ });
47
+ return { thread: id };
48
+ },
49
+ });
@@ -0,0 +1 @@
1
+ export declare const quietAction: import("../../../../runtime/define.js").ActionDef;
@@ -0,0 +1,33 @@
1
+ /**
2
+ * `chat.quiet`: a turn that waited for its sender to be quiet (a customer
3
+ * writing several short messages in a row: `chat.send`'s `quiet`) starts
4
+ * now, for the latest of them; the agent reads them all, and answers once.
5
+ * Called by the timer each message set again in its place, as whoever sent
6
+ * it; by nobody else. A message that's gone by then (its chat erased) starts
7
+ * nothing.
8
+ */
9
+ import { defineAction } from "../../../../runtime/mod.js";
10
+ export const quietAction = defineAction({
11
+ description: "Starts a turn that waited for its chat to be quiet",
12
+ input: {
13
+ type: "object",
14
+ properties: {
15
+ thread: { type: "string" },
16
+ agent: { type: "string" },
17
+ trigger: { type: "string" },
18
+ hops: { type: "integer" },
19
+ },
20
+ required: ["thread", "agent", "trigger", "hops"],
21
+ additionalProperties: false,
22
+ },
23
+ run: async (ctx, turn) => {
24
+ // Its message, as whoever sent it reads it: gone (its chat erased, they're out of it), no turn.
25
+ if (!await ctx.db.collection("message").findOne({ _id: turn.trigger }))
26
+ return;
27
+ await ctx.transaction((tx) => {
28
+ // The same id it would have had at once: one turn per message, however often called.
29
+ tx.emit("turn.requested", turn, { id: `${turn.trigger}:${turn.agent}` });
30
+ return Promise.resolve();
31
+ });
32
+ },
33
+ });
@@ -0,0 +1 @@
1
+ export declare const sayAction: import("../../../../runtime/define.js").ActionDef;
@@ -0,0 +1,82 @@
1
+ /**
2
+ * `chat.say`: an agent (`from`) says something in a chat without thinking
3
+ * it, no model call and no turn: a fixed message trusted code decides on (a
4
+ * payment confirmed). It goes to `to` (people by id, contacts as
5
+ * `contact:<id>`), else to whoever last wrote there who isn't an agent, and
6
+ * out through the chat's medium (WhatsApp) like any of its answers. It's
7
+ * said to people, never to agents, so it starts no turn, by an agent that
8
+ * answers there. Its `id` comes from what caused it (a payment's): saying it
9
+ * again in that chat sends nothing (the message is `<thread>:say:<id>`). Only
10
+ * trusted code calls it.
11
+ */
12
+ import { defineAction, failure, invalid } from "../../../../runtime/mod.js";
13
+ import { agentsNamed, now, rosterOf } from "../shared/agents.js";
14
+ import { noted } from "../shared/summary.js";
15
+ export const sayAction = defineAction({
16
+ description: "An agent's fixed message in a chat, without a model call",
17
+ input: {
18
+ type: "object",
19
+ properties: {
20
+ /** The message's id, from what caused it: the same id is said once. */
21
+ id: { type: "string", minLength: 1, maxLength: 200 },
22
+ thread: { type: "string" },
23
+ /** The agent saying it. */
24
+ from: { type: "string" },
25
+ text: { type: "string", minLength: 1 },
26
+ to: { type: "array", items: { type: "string" }, maxItems: 20 },
27
+ },
28
+ required: ["id", "thread", "from", "text"],
29
+ additionalProperties: false,
30
+ },
31
+ run: async (ctx, input) => {
32
+ const messages = ctx.db.collection("message");
33
+ // Its id is the chat's own: a cause says it once in each chat, and never anywhere else.
34
+ const id = `${input.thread}:say:${input.id}`;
35
+ if (await messages.findOne({ _id: id }))
36
+ return { message: id };
37
+ const thread = await ctx.db.collection("thread").findOne({ _id: input.thread });
38
+ if (!thread)
39
+ throw failure("not_found", `No chat "${input.thread}".`);
40
+ // Said by an agent that answers there.
41
+ const roster = await rosterOf(ctx, thread.in);
42
+ if (!roster.here.includes(input.from) && !thread.agents?.includes(input.from)) {
43
+ throw failure("not_here", `${input.from} doesn't answer in this chat.`);
44
+ }
45
+ // Whoever last wrote there who isn't an agent, unless it says whom.
46
+ const latest = input.to ? [] : await messages.find({ thread: thread._id, private: { $ne: true } }, { sort: { at: -1 }, limit: 20 });
47
+ const agents = await agentsNamed(ctx, [
48
+ input.from,
49
+ ...input.to ?? latest.map((m) => m.from),
50
+ ]);
51
+ if (!agents[input.from])
52
+ throw invalid(`No agent "${input.from}".`);
53
+ const last = latest.find((m) => !agents[m.from])?.from;
54
+ const to = input.to ?? (last ? [last] : []);
55
+ if (to.some((name) => agents[name])) {
56
+ throw invalid("An agent says this to people: to ask another agent, send it a message.");
57
+ }
58
+ const said = {
59
+ _id: id,
60
+ thread: thread._id,
61
+ ...(thread.in ? { in: thread.in } : {}),
62
+ from: input.from,
63
+ to,
64
+ text: input.text,
65
+ // After a person's message, as an agent's answer is.
66
+ hops: 1,
67
+ at: now(),
68
+ };
69
+ try {
70
+ await ctx.transaction(async (tx) => {
71
+ await tx.db.collection("message").insertOne(said);
72
+ await noted(tx, said);
73
+ });
74
+ }
75
+ catch (error) {
76
+ // Said just now, by the same cause.
77
+ if (error.code !== "duplicate_key")
78
+ throw error;
79
+ }
80
+ return { message: said._id };
81
+ },
82
+ });
@@ -1,20 +1,33 @@
1
1
  /**
2
- * A person's message. It goes to `to` when given, else to the agents
3
- * `@mentioned` in it, else to the sender of the message it replies to,
4
- * else to the thread's agents (a new thread's: those it names, or who
5
- * answers new chats in its space). Only agents answering in its space
6
- * answer there: naming one that doesn't fails (`not_here`). Audio sent with it is transcribed first
7
- * (what agents read): if that fails, nothing is sent and the call fails
8
- * with `transcription_failed`; `transcribe: false` sends it as it is. `via`
9
- * says what sent it for the person (a routine); a new thread takes `title`
10
- * and `renamable` in the same commit, so its first turn already has them.
2
+ * A person's message, or a contact's (someone outside the org, in a chat
3
+ * shared with them: the rules keep them to it). It goes to `to` when given,
4
+ * else to the agents `@mentioned` in it, else to the sender of the message
5
+ * it replies to, else to the thread's agents (a new thread's: those it
6
+ * names, or who answers new chats in its space). A contact's goes to the
7
+ * sender of what it replies to, else the thread's agents: never whom it
8
+ * names. It replies only to a message of the same conversation that its
9
+ * sender reads. Only agents answering in
10
+ * its space answer there: naming one that doesn't fails (`not_here`). Audio
11
+ * sent with it is transcribed first (what agents read): if that fails,
12
+ * nothing is sent and the call fails with `transcription_failed`;
13
+ * `transcribe: false` sends it as it is. `via` says what sent it for the
14
+ * person (a routine); a new thread takes `title` and `renamable` in the same
15
+ * commit, so its first turn already has them. `tap` says it was a choice
16
+ * tapped (a button), not typed. With `quiet`, agents answer once the sender
17
+ * has been quiet that long (a burst of short messages, answered together).
11
18
  */
12
- import { defineAction, people } from "../../../../runtime/mod.js";
19
+ import { defineAction, peopleOrContacts } from "../../../../runtime/mod.js";
13
20
  import { agentsNamed, mentions, NO_ANSWER, now, rosterOf } from "../shared/agents.js";
14
21
  import { delivery } from "../shared/delivery.js";
15
22
  import { movedBy, startedWith } from "../shared/summary.js";
16
23
  import { settingsOf } from "../shared/types.js";
17
24
  const names = { type: "array", items: { type: "string" } };
25
+ /** Who a message is from, pinned to whoever sends it: a person by id, a contact as `contact:<id>`. */
26
+ const fromOf = (actor) => actor?.kind === "person"
27
+ ? actor.id
28
+ : actor?.kind === "contact"
29
+ ? `contact:${actor.id}`
30
+ : undefined;
18
31
  export const sendAction = defineAction({
19
32
  input: {
20
33
  type: "object",
@@ -72,15 +85,35 @@ export const sendAction = defineAction({
72
85
  },
73
86
  /** What a new thread is called (an existing one keeps its name). */
74
87
  title: { type: "string", minLength: 1, maxLength: 120 },
88
+ /**
89
+ * A choice tapped, not typed (a button's): what it means (`id`), what it
90
+ * said (`title`, the message's text when it says none) and the addition
91
+ * it was in (`key`).
92
+ */
93
+ tap: {
94
+ type: "object",
95
+ properties: {
96
+ id: { type: "string", minLength: 1, maxLength: 256 },
97
+ title: { type: "string", maxLength: 256 },
98
+ key: { type: "string", maxLength: 120 },
99
+ },
100
+ required: ["id"],
101
+ additionalProperties: false,
102
+ },
75
103
  /** A new thread an agent may name, as what it found. */
76
104
  renamable: { type: "boolean" },
105
+ /**
106
+ * Ms the sender may write on before agents answer (a customer writing in
107
+ * bursts): they answer once it's been quiet that long, everything at once.
108
+ */
109
+ quiet: { type: "integer", minimum: 0, maximum: 30_000 },
77
110
  },
78
111
  additionalProperties: false,
79
112
  },
80
- // People write as themselves: their own messages.
81
- allow: people,
113
+ // People and contacts write as themselves: their own messages.
114
+ allow: peopleOrContacts,
82
115
  run: async (ctx, input) => {
83
- const said = input.text ?? "";
116
+ const said = input.text ?? input.tap?.title ?? "";
84
117
  if (!said.trim() && !input.files?.length) {
85
118
  throw Object.assign(new Error("A message says something, or sends a file"), {
86
119
  code: "invalid",
@@ -89,14 +122,18 @@ export const sendAction = defineAction({
89
122
  const threads = ctx.db.collection("thread");
90
123
  const threadId = input.thread ?? crypto.randomUUID();
91
124
  const existing = input.thread ? await threads.findOne({ _id: threadId }) : null;
92
- const replied = input.replyTo
125
+ // What it answers: a message the sender reads, in this conversation (else it answers nothing).
126
+ const found = input.replyTo
93
127
  ? await ctx.db.collection("message").findOne({ _id: input.replyTo })
94
128
  : null;
129
+ const replied = found?.thread === threadId ? found : null;
95
130
  const where = existing ? existing.in : input.in;
96
131
  const roster = await rosterOf(ctx, where);
97
132
  const members = existing ? existing.agents ?? [] : roster.default;
98
- const mentioned = mentions(said);
99
- const asked = input.to ??
133
+ // A contact talks with whom its chat is with: what it says names nobody else.
134
+ const contact = ctx.actor?.kind === "contact";
135
+ const mentioned = contact ? [] : mentions(said);
136
+ const asked = (contact ? undefined : input.to) ??
100
137
  (mentioned.length ? mentioned : replied ? [replied.from] : members);
101
138
  // Agents answer only where they work: one named that doesn't is refused; one gone, left out.
102
139
  const agents = await agentsNamed(ctx, asked);
@@ -156,16 +193,17 @@ export const sendAction = defineAction({
156
193
  }
157
194
  : {}),
158
195
  thread: threadId,
159
- from: ctx.actor?.kind === "person" ? ctx.actor.id : input.from ?? "user",
196
+ from: fromOf(ctx.actor) ?? input.from ?? "user",
160
197
  ...(where ? { in: where } : {}),
161
198
  to: [...to],
162
199
  text: said,
163
200
  hops: 0,
164
- ...(input.replyTo ? { replyTo: input.replyTo } : {}),
201
+ ...(replied ? { replyTo: replied._id } : {}),
165
202
  ...(input.via ? { via: input.via } : {}),
203
+ ...(input.tap ? { tap: input.tap } : {}),
166
204
  at: now(),
167
205
  };
168
- const deliver = await delivery(ctx, sent);
206
+ const deliver = await delivery(ctx, sent, sent.thread, true, input.quiet ?? 0);
169
207
  await ctx.transaction(async (tx) => {
170
208
  // The chat's summary moves with the write that touches it anyway.
171
209
  if (existing) {
@@ -0,0 +1 @@
1
+ export declare const shownAction: import("../../../../runtime/define.js").ActionDef;
@@ -0,0 +1,35 @@
1
+ /**
2
+ * `chat.shown`: an interface says an addition went out after an answer (see
3
+ * `Addition`), once per chat per key. Trusted code only, and unrecorded:
4
+ * called from a job, it runs inline and its record goes with the job's next
5
+ * write. Interfaces don't write chat's collections: they say it here.
6
+ */
7
+ import { defineAction } from "../../../../runtime/mod.js";
8
+ import { now } from "../shared/agents.js";
9
+ export const shownAction = defineAction({
10
+ description: "Records that an addition went out after an answer",
11
+ input: {
12
+ type: "object",
13
+ properties: {
14
+ thread: { type: "string" },
15
+ key: { type: "string", pattern: "^[\\w:.-]{1,120}$" },
16
+ after: { type: "string" },
17
+ medium: { type: "string", minLength: 1, maxLength: 40 },
18
+ fallback: { type: "boolean" },
19
+ note: { type: "string", maxLength: 500 },
20
+ },
21
+ required: ["thread", "key", "after", "medium"],
22
+ additionalProperties: false,
23
+ },
24
+ record: false,
25
+ run: async (ctx, input) => {
26
+ const thread = await ctx.as().db.collection("thread").findOne({ _id: input.thread });
27
+ ctx.record("shown", {
28
+ _id: `${input.thread}:${input.key}`,
29
+ ...input,
30
+ ...(thread?.in ? { in: thread.in } : {}),
31
+ at: now(),
32
+ });
33
+ return { shown: `${input.thread}:${input.key}` };
34
+ },
35
+ });
@@ -0,0 +1,124 @@
1
+ import type { LlmState, ToolCall } from "../../../models/contract.js";
2
+ import type { Told } from "../shared/types.js";
3
+ export declare const intent: {
4
+ schema: {
5
+ readonly type: "object";
6
+ readonly properties: {
7
+ readonly thread: {
8
+ readonly type: "string";
9
+ };
10
+ readonly agent: {
11
+ readonly type: "string";
12
+ };
13
+ /** Its place in the turn: the step's message is `<turn>:<step>`. */
14
+ readonly step: {
15
+ readonly type: "integer";
16
+ };
17
+ /** What the model wrote with its calls. */
18
+ readonly text: {
19
+ readonly type: "string";
20
+ };
21
+ /** Its model's state, sent back with the step. */
22
+ readonly state: {
23
+ readonly type: "object";
24
+ };
25
+ /** What the turn was told, when the step is its first message. */
26
+ readonly told: {
27
+ readonly type: "array";
28
+ readonly items: {
29
+ readonly type: "object";
30
+ readonly properties: {
31
+ readonly name: {
32
+ readonly type: "string";
33
+ };
34
+ readonly text: {
35
+ readonly type: "string";
36
+ };
37
+ };
38
+ readonly required: readonly ["name", "text"];
39
+ };
40
+ };
41
+ /** The calls, in the model's order. */
42
+ readonly calls: {
43
+ readonly type: "array";
44
+ readonly items: {
45
+ readonly type: "object";
46
+ readonly properties: {
47
+ readonly id: {
48
+ readonly type: "string";
49
+ };
50
+ readonly name: {
51
+ readonly type: "string";
52
+ };
53
+ readonly input: {
54
+ readonly type: "object";
55
+ };
56
+ };
57
+ readonly required: readonly ["id", "name"];
58
+ };
59
+ };
60
+ /** What each call returned, by its place in `calls`. */
61
+ readonly outputs: {
62
+ readonly type: "object";
63
+ readonly additionalProperties: {
64
+ readonly type: "string";
65
+ };
66
+ };
67
+ readonly at: {
68
+ readonly type: "string";
69
+ };
70
+ };
71
+ readonly required: readonly ["thread", "agent", "step", "calls", "outputs", "at"];
72
+ };
73
+ events?: boolean;
74
+ records?: boolean;
75
+ durable?: false;
76
+ indexes?: string[][];
77
+ private?: string[];
78
+ queries?: Record<string, import("../../../../runtime/define.js").QueryDef<{
79
+ [x: string]: unknown;
80
+ text?: string | undefined;
81
+ state?: {
82
+ [x: string]: unknown;
83
+ } | undefined;
84
+ told?: {
85
+ [x: string]: unknown;
86
+ name: string;
87
+ text: string;
88
+ }[] | undefined;
89
+ at: string;
90
+ thread: string;
91
+ agent: string;
92
+ step: number;
93
+ calls: {
94
+ [x: string]: unknown;
95
+ input?: {
96
+ [x: string]: unknown;
97
+ } | undefined;
98
+ id: string;
99
+ name: string;
100
+ }[];
101
+ outputs: {
102
+ [x: string]: string;
103
+ };
104
+ } & {
105
+ _id: string;
106
+ }>> | undefined;
107
+ vectors?: string[];
108
+ };
109
+ /** An intent, as it is written: its `_id` is its turn's. */
110
+ export type Intent = {
111
+ thread: string;
112
+ agent: string;
113
+ step: number;
114
+ text?: string;
115
+ state?: LlmState;
116
+ told?: Told[];
117
+ calls: ToolCall[];
118
+ outputs: Record<string, string>;
119
+ at: string;
120
+ };
121
+ /** What a call that never returned says, in the step a turn keeps when it ends without it. */
122
+ export declare const CUT_SHORT: string;
123
+ /** What a message that was never sent says there. */
124
+ export declare const NOT_SENT = "Not sent: the turn ended before it was.";
@@ -0,0 +1,52 @@
1
+ /**
2
+ * A turn's step before it commits: the tool calls its model asked for,
3
+ * written before any of them runs, and what each returned as soon as it did.
4
+ * A retried turn finds it and goes on with these same calls instead of asking
5
+ * the model again: a call that returned isn't run again, one cut short runs
6
+ * again as itself (the same `callId`). It goes in the commit that writes the
7
+ * step; a turn that ends without that (failed for good, or stopped) keeps it
8
+ * as its step, saying which calls never returned. One per running turn, by
9
+ * the turn's id; trusted code's only, and no events.
10
+ */
11
+ import { defineCollection } from "../../../../runtime/mod.js";
12
+ const intentSchema = {
13
+ type: "object",
14
+ properties: {
15
+ thread: { type: "string" },
16
+ agent: { type: "string" },
17
+ /** Its place in the turn: the step's message is `<turn>:<step>`. */
18
+ step: { type: "integer" },
19
+ /** What the model wrote with its calls. */
20
+ text: { type: "string" },
21
+ /** Its model's state, sent back with the step. */
22
+ state: { type: "object" },
23
+ /** What the turn was told, when the step is its first message. */
24
+ told: {
25
+ type: "array",
26
+ items: {
27
+ type: "object",
28
+ properties: { name: { type: "string" }, text: { type: "string" } },
29
+ required: ["name", "text"],
30
+ },
31
+ },
32
+ /** The calls, in the model's order. */
33
+ calls: {
34
+ type: "array",
35
+ items: {
36
+ type: "object",
37
+ properties: { id: { type: "string" }, name: { type: "string" }, input: { type: "object" } },
38
+ required: ["id", "name"],
39
+ },
40
+ },
41
+ /** What each call returned, by its place in `calls`. */
42
+ outputs: { type: "object", additionalProperties: { type: "string" } },
43
+ at: { type: "string" },
44
+ },
45
+ required: ["thread", "agent", "step", "calls", "outputs", "at"],
46
+ };
47
+ export const intent = defineCollection({ schema: intentSchema, events: false });
48
+ /** What a call that never returned says, in the step a turn keeps when it ends without it. */
49
+ export const CUT_SHORT = "Interrupted before it returned: it may or may not have taken effect. " +
50
+ "Check before calling it again.";
51
+ /** What a message that was never sent says there. */
52
+ export const NOT_SENT = "Not sent: the turn ended before it was.";