@indexnetwork/protocol 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (365) hide show
  1. package/dist/agents/chat.agent.d.ts +218 -0
  2. package/dist/agents/chat.agent.d.ts.map +1 -0
  3. package/dist/agents/chat.agent.js +884 -0
  4. package/dist/agents/chat.agent.js.map +1 -0
  5. package/dist/agents/chat.prompt.d.ts +18 -0
  6. package/dist/agents/chat.prompt.d.ts.map +1 -0
  7. package/dist/agents/chat.prompt.js +372 -0
  8. package/dist/agents/chat.prompt.js.map +1 -0
  9. package/dist/agents/chat.prompt.modules.d.ts +61 -0
  10. package/dist/agents/chat.prompt.modules.d.ts.map +1 -0
  11. package/dist/agents/chat.prompt.modules.js +366 -0
  12. package/dist/agents/chat.prompt.modules.js.map +1 -0
  13. package/dist/agents/chat.title.generator.d.ts +20 -0
  14. package/dist/agents/chat.title.generator.d.ts.map +1 -0
  15. package/dist/agents/chat.title.generator.js +66 -0
  16. package/dist/agents/chat.title.generator.js.map +1 -0
  17. package/dist/agents/home.categorizer.d.ts +28 -0
  18. package/dist/agents/home.categorizer.d.ts.map +1 -0
  19. package/dist/agents/home.categorizer.js +170 -0
  20. package/dist/agents/home.categorizer.js.map +1 -0
  21. package/dist/agents/hyde.generator.d.ts +27 -0
  22. package/dist/agents/hyde.generator.d.ts.map +1 -0
  23. package/dist/agents/hyde.generator.js +75 -0
  24. package/dist/agents/hyde.generator.js.map +1 -0
  25. package/dist/agents/hyde.strategies.d.ts +17 -0
  26. package/dist/agents/hyde.strategies.d.ts.map +1 -0
  27. package/dist/agents/hyde.strategies.js +29 -0
  28. package/dist/agents/hyde.strategies.js.map +1 -0
  29. package/dist/agents/intent.clarifier.d.ts +29 -0
  30. package/dist/agents/intent.clarifier.d.ts.map +1 -0
  31. package/dist/agents/intent.clarifier.js +186 -0
  32. package/dist/agents/intent.clarifier.js.map +1 -0
  33. package/dist/agents/intent.indexer.d.ts +77 -0
  34. package/dist/agents/intent.indexer.d.ts.map +1 -0
  35. package/dist/agents/intent.indexer.js +164 -0
  36. package/dist/agents/intent.indexer.js.map +1 -0
  37. package/dist/agents/intent.inferrer.d.ts +95 -0
  38. package/dist/agents/intent.inferrer.d.ts.map +1 -0
  39. package/dist/agents/intent.inferrer.js +238 -0
  40. package/dist/agents/intent.inferrer.js.map +1 -0
  41. package/dist/agents/intent.reconciler.d.ts +106 -0
  42. package/dist/agents/intent.reconciler.d.ts.map +1 -0
  43. package/dist/agents/intent.reconciler.js +184 -0
  44. package/dist/agents/intent.reconciler.js.map +1 -0
  45. package/dist/agents/intent.verifier.d.ts +97 -0
  46. package/dist/agents/intent.verifier.d.ts.map +1 -0
  47. package/dist/agents/intent.verifier.js +234 -0
  48. package/dist/agents/intent.verifier.js.map +1 -0
  49. package/dist/agents/invite.generator.d.ts +47 -0
  50. package/dist/agents/invite.generator.d.ts.map +1 -0
  51. package/dist/agents/invite.generator.js +56 -0
  52. package/dist/agents/invite.generator.js.map +1 -0
  53. package/dist/agents/lens.inferrer.d.ts +37 -0
  54. package/dist/agents/lens.inferrer.d.ts.map +1 -0
  55. package/dist/agents/lens.inferrer.js +98 -0
  56. package/dist/agents/lens.inferrer.js.map +1 -0
  57. package/dist/agents/model.config.d.ts +120 -0
  58. package/dist/agents/model.config.d.ts.map +1 -0
  59. package/dist/agents/model.config.js +76 -0
  60. package/dist/agents/model.config.js.map +1 -0
  61. package/dist/agents/negotiation.insights.generator.d.ts +32 -0
  62. package/dist/agents/negotiation.insights.generator.d.ts.map +1 -0
  63. package/dist/agents/negotiation.insights.generator.js +105 -0
  64. package/dist/agents/negotiation.insights.generator.js.map +1 -0
  65. package/dist/agents/negotiation.proposer.d.ts +26 -0
  66. package/dist/agents/negotiation.proposer.d.ts.map +1 -0
  67. package/dist/agents/negotiation.proposer.js +67 -0
  68. package/dist/agents/negotiation.proposer.js.map +1 -0
  69. package/dist/agents/negotiation.responder.d.ts +26 -0
  70. package/dist/agents/negotiation.responder.d.ts.map +1 -0
  71. package/dist/agents/negotiation.responder.js +71 -0
  72. package/dist/agents/negotiation.responder.js.map +1 -0
  73. package/dist/agents/opportunity.evaluator.d.ts +253 -0
  74. package/dist/agents/opportunity.evaluator.d.ts.map +1 -0
  75. package/dist/agents/opportunity.evaluator.js +413 -0
  76. package/dist/agents/opportunity.evaluator.js.map +1 -0
  77. package/dist/agents/opportunity.presenter.d.ts +115 -0
  78. package/dist/agents/opportunity.presenter.d.ts.map +1 -0
  79. package/dist/agents/opportunity.presenter.js +524 -0
  80. package/dist/agents/opportunity.presenter.js.map +1 -0
  81. package/dist/agents/profile.generator.d.ts +67 -0
  82. package/dist/agents/profile.generator.d.ts.map +1 -0
  83. package/dist/agents/profile.generator.js +97 -0
  84. package/dist/agents/profile.generator.js.map +1 -0
  85. package/dist/agents/profile.hyde.generator.d.ts +43 -0
  86. package/dist/agents/profile.hyde.generator.d.ts.map +1 -0
  87. package/dist/agents/profile.hyde.generator.js +113 -0
  88. package/dist/agents/profile.hyde.generator.js.map +1 -0
  89. package/dist/agents/suggestion.generator.d.ts +24 -0
  90. package/dist/agents/suggestion.generator.d.ts.map +1 -0
  91. package/dist/agents/suggestion.generator.js +96 -0
  92. package/dist/agents/suggestion.generator.js.map +1 -0
  93. package/dist/graphs/chat.graph.d.ts +312 -0
  94. package/dist/graphs/chat.graph.d.ts.map +1 -0
  95. package/dist/graphs/chat.graph.js +267 -0
  96. package/dist/graphs/chat.graph.js.map +1 -0
  97. package/dist/graphs/home.graph.d.ts +180 -0
  98. package/dist/graphs/home.graph.d.ts.map +1 -0
  99. package/dist/graphs/home.graph.js +598 -0
  100. package/dist/graphs/home.graph.js.map +1 -0
  101. package/dist/graphs/hyde.graph.d.ts +110 -0
  102. package/dist/graphs/hyde.graph.d.ts.map +1 -0
  103. package/dist/graphs/hyde.graph.js +235 -0
  104. package/dist/graphs/hyde.graph.js.map +1 -0
  105. package/dist/graphs/index.graph.d.ts +620 -0
  106. package/dist/graphs/index.graph.d.ts.map +1 -0
  107. package/dist/graphs/index.graph.js +226 -0
  108. package/dist/graphs/index.graph.js.map +1 -0
  109. package/dist/graphs/index_membership.graph.d.ts +250 -0
  110. package/dist/graphs/index_membership.graph.d.ts.map +1 -0
  111. package/dist/graphs/index_membership.graph.js +204 -0
  112. package/dist/graphs/index_membership.graph.js.map +1 -0
  113. package/dist/graphs/intent.graph.d.ts +490 -0
  114. package/dist/graphs/intent.graph.d.ts.map +1 -0
  115. package/dist/graphs/intent.graph.js +787 -0
  116. package/dist/graphs/intent.graph.js.map +1 -0
  117. package/dist/graphs/intent_index.graph.d.ts +396 -0
  118. package/dist/graphs/intent_index.graph.d.ts.map +1 -0
  119. package/dist/graphs/intent_index.graph.js +331 -0
  120. package/dist/graphs/intent_index.graph.js.map +1 -0
  121. package/dist/graphs/maintenance.graph.d.ts +177 -0
  122. package/dist/graphs/maintenance.graph.d.ts.map +1 -0
  123. package/dist/graphs/maintenance.graph.js +173 -0
  124. package/dist/graphs/maintenance.graph.js.map +1 -0
  125. package/dist/graphs/negotiation.graph.d.ts +819 -0
  126. package/dist/graphs/negotiation.graph.d.ts.map +1 -0
  127. package/dist/graphs/negotiation.graph.js +255 -0
  128. package/dist/graphs/negotiation.graph.js.map +1 -0
  129. package/dist/graphs/opportunity.graph.d.ts +1082 -0
  130. package/dist/graphs/opportunity.graph.d.ts.map +1 -0
  131. package/dist/graphs/opportunity.graph.js +2534 -0
  132. package/dist/graphs/opportunity.graph.js.map +1 -0
  133. package/dist/graphs/profile.graph.d.ts +617 -0
  134. package/dist/graphs/profile.graph.d.ts.map +1 -0
  135. package/dist/graphs/profile.graph.js +839 -0
  136. package/dist/graphs/profile.graph.js.map +1 -0
  137. package/dist/graphs/tests/chat.graph.mocks.d.ts +104 -0
  138. package/dist/graphs/tests/chat.graph.mocks.d.ts.map +1 -0
  139. package/dist/graphs/tests/chat.graph.mocks.js +225 -0
  140. package/dist/graphs/tests/chat.graph.mocks.js.map +1 -0
  141. package/dist/index.d.ts +62 -0
  142. package/dist/index.d.ts.map +1 -0
  143. package/dist/index.js +44 -0
  144. package/dist/index.js.map +1 -0
  145. package/dist/interfaces/auth.interface.d.ts +15 -0
  146. package/dist/interfaces/auth.interface.d.ts.map +1 -0
  147. package/dist/interfaces/auth.interface.js +2 -0
  148. package/dist/interfaces/auth.interface.js.map +1 -0
  149. package/dist/interfaces/cache.interface.d.ts +43 -0
  150. package/dist/interfaces/cache.interface.d.ts.map +1 -0
  151. package/dist/interfaces/cache.interface.js +6 -0
  152. package/dist/interfaces/cache.interface.js.map +1 -0
  153. package/dist/interfaces/chat-session.interface.d.ts +11 -0
  154. package/dist/interfaces/chat-session.interface.d.ts.map +1 -0
  155. package/dist/interfaces/chat-session.interface.js +2 -0
  156. package/dist/interfaces/chat-session.interface.js.map +1 -0
  157. package/dist/interfaces/contact.interface.d.ts +48 -0
  158. package/dist/interfaces/contact.interface.d.ts.map +1 -0
  159. package/dist/interfaces/contact.interface.js +2 -0
  160. package/dist/interfaces/contact.interface.js.map +1 -0
  161. package/dist/interfaces/database.interface.d.ts +1495 -0
  162. package/dist/interfaces/database.interface.d.ts.map +1 -0
  163. package/dist/interfaces/database.interface.js +2 -0
  164. package/dist/interfaces/database.interface.js.map +1 -0
  165. package/dist/interfaces/embedder.interface.d.ts +85 -0
  166. package/dist/interfaces/embedder.interface.d.ts.map +1 -0
  167. package/dist/interfaces/embedder.interface.js +5 -0
  168. package/dist/interfaces/embedder.interface.js.map +1 -0
  169. package/dist/interfaces/enrichment.interface.d.ts +40 -0
  170. package/dist/interfaces/enrichment.interface.d.ts.map +1 -0
  171. package/dist/interfaces/enrichment.interface.js +2 -0
  172. package/dist/interfaces/enrichment.interface.js.map +1 -0
  173. package/dist/interfaces/integration.interface.d.ts +91 -0
  174. package/dist/interfaces/integration.interface.d.ts.map +1 -0
  175. package/dist/interfaces/integration.interface.js +2 -0
  176. package/dist/interfaces/integration.interface.js.map +1 -0
  177. package/dist/interfaces/queue.interface.d.ts +17 -0
  178. package/dist/interfaces/queue.interface.d.ts.map +1 -0
  179. package/dist/interfaces/queue.interface.js +5 -0
  180. package/dist/interfaces/queue.interface.js.map +1 -0
  181. package/dist/interfaces/scraper.interface.d.ts +31 -0
  182. package/dist/interfaces/scraper.interface.d.ts.map +1 -0
  183. package/dist/interfaces/scraper.interface.js +2 -0
  184. package/dist/interfaces/scraper.interface.js.map +1 -0
  185. package/dist/interfaces/storage.interface.d.ts +46 -0
  186. package/dist/interfaces/storage.interface.d.ts.map +1 -0
  187. package/dist/interfaces/storage.interface.js +6 -0
  188. package/dist/interfaces/storage.interface.js.map +1 -0
  189. package/dist/mcp/mcp.server.d.ts +29 -0
  190. package/dist/mcp/mcp.server.d.ts.map +1 -0
  191. package/dist/mcp/mcp.server.js +171 -0
  192. package/dist/mcp/mcp.server.js.map +1 -0
  193. package/dist/states/chat.state.d.ts +126 -0
  194. package/dist/states/chat.state.d.ts.map +1 -0
  195. package/dist/states/chat.state.js +112 -0
  196. package/dist/states/chat.state.js.map +1 -0
  197. package/dist/states/home.state.d.ts +100 -0
  198. package/dist/states/home.state.d.ts.map +1 -0
  199. package/dist/states/home.state.js +74 -0
  200. package/dist/states/home.state.js.map +1 -0
  201. package/dist/states/hyde.state.d.ts +54 -0
  202. package/dist/states/hyde.state.d.ts.map +1 -0
  203. package/dist/states/hyde.state.js +66 -0
  204. package/dist/states/hyde.state.js.map +1 -0
  205. package/dist/states/index.state.d.ts +179 -0
  206. package/dist/states/index.state.d.ts.map +1 -0
  207. package/dist/states/index.state.js +56 -0
  208. package/dist/states/index.state.js.map +1 -0
  209. package/dist/states/index_membership.state.d.ts +77 -0
  210. package/dist/states/index_membership.state.d.ts.map +1 -0
  211. package/dist/states/index_membership.state.js +43 -0
  212. package/dist/states/index_membership.state.js.map +1 -0
  213. package/dist/states/intent.state.d.ts +203 -0
  214. package/dist/states/intent.state.d.ts.map +1 -0
  215. package/dist/states/intent.state.js +153 -0
  216. package/dist/states/intent.state.js.map +1 -0
  217. package/dist/states/intent_index.state.d.ts +148 -0
  218. package/dist/states/intent_index.state.d.ts.map +1 -0
  219. package/dist/states/intent_index.state.js +100 -0
  220. package/dist/states/intent_index.state.js.map +1 -0
  221. package/dist/states/maintenance.state.d.ts +36 -0
  222. package/dist/states/maintenance.state.d.ts.map +1 -0
  223. package/dist/states/maintenance.state.js +56 -0
  224. package/dist/states/maintenance.state.js.map +1 -0
  225. package/dist/states/negotiation.state.d.ts +230 -0
  226. package/dist/states/negotiation.state.d.ts.map +1 -0
  227. package/dist/states/negotiation.state.js +82 -0
  228. package/dist/states/negotiation.state.js.map +1 -0
  229. package/dist/states/opportunity.state.d.ts +300 -0
  230. package/dist/states/opportunity.state.d.ts.map +1 -0
  231. package/dist/states/opportunity.state.js +207 -0
  232. package/dist/states/opportunity.state.js.map +1 -0
  233. package/dist/states/profile.state.d.ts +172 -0
  234. package/dist/states/profile.state.d.ts.map +1 -0
  235. package/dist/states/profile.state.js +133 -0
  236. package/dist/states/profile.state.js.map +1 -0
  237. package/dist/streamers/chat.streamer.d.ts +55 -0
  238. package/dist/streamers/chat.streamer.d.ts.map +1 -0
  239. package/dist/streamers/chat.streamer.js +186 -0
  240. package/dist/streamers/chat.streamer.js.map +1 -0
  241. package/dist/streamers/index.d.ts +3 -0
  242. package/dist/streamers/index.d.ts.map +1 -0
  243. package/dist/streamers/index.js +3 -0
  244. package/dist/streamers/index.js.map +1 -0
  245. package/dist/streamers/response.streamer.d.ts +36 -0
  246. package/dist/streamers/response.streamer.d.ts.map +1 -0
  247. package/dist/streamers/response.streamer.js +46 -0
  248. package/dist/streamers/response.streamer.js.map +1 -0
  249. package/dist/support/chat.utils.d.ts +42 -0
  250. package/dist/support/chat.utils.d.ts.map +1 -0
  251. package/dist/support/chat.utils.js +89 -0
  252. package/dist/support/chat.utils.js.map +1 -0
  253. package/dist/support/debug-meta.sanitizer.d.ts +18 -0
  254. package/dist/support/debug-meta.sanitizer.d.ts.map +1 -0
  255. package/dist/support/debug-meta.sanitizer.js +82 -0
  256. package/dist/support/debug-meta.sanitizer.js.map +1 -0
  257. package/dist/support/feed.health.d.ts +32 -0
  258. package/dist/support/feed.health.d.ts.map +1 -0
  259. package/dist/support/feed.health.js +76 -0
  260. package/dist/support/feed.health.js.map +1 -0
  261. package/dist/support/introducer.discovery.d.ts +78 -0
  262. package/dist/support/introducer.discovery.d.ts.map +1 -0
  263. package/dist/support/introducer.discovery.js +101 -0
  264. package/dist/support/introducer.discovery.js.map +1 -0
  265. package/dist/support/log.d.ts +65 -0
  266. package/dist/support/log.d.ts.map +1 -0
  267. package/dist/support/log.js +76 -0
  268. package/dist/support/log.js.map +1 -0
  269. package/dist/support/lucide.icon-catalog.d.ts +22 -0
  270. package/dist/support/lucide.icon-catalog.d.ts.map +1 -0
  271. package/dist/support/lucide.icon-catalog.js +101 -0
  272. package/dist/support/lucide.icon-catalog.js.map +1 -0
  273. package/dist/support/opportunity.card-text.d.ts +39 -0
  274. package/dist/support/opportunity.card-text.d.ts.map +1 -0
  275. package/dist/support/opportunity.card-text.js +333 -0
  276. package/dist/support/opportunity.card-text.js.map +1 -0
  277. package/dist/support/opportunity.constants.d.ts +9 -0
  278. package/dist/support/opportunity.constants.d.ts.map +1 -0
  279. package/dist/support/opportunity.constants.js +11 -0
  280. package/dist/support/opportunity.constants.js.map +1 -0
  281. package/dist/support/opportunity.discover.d.ts +144 -0
  282. package/dist/support/opportunity.discover.d.ts.map +1 -0
  283. package/dist/support/opportunity.discover.js +610 -0
  284. package/dist/support/opportunity.discover.js.map +1 -0
  285. package/dist/support/opportunity.enricher.d.ts +44 -0
  286. package/dist/support/opportunity.enricher.d.ts.map +1 -0
  287. package/dist/support/opportunity.enricher.js +245 -0
  288. package/dist/support/opportunity.enricher.js.map +1 -0
  289. package/dist/support/opportunity.persist.d.ts +39 -0
  290. package/dist/support/opportunity.persist.d.ts.map +1 -0
  291. package/dist/support/opportunity.persist.js +63 -0
  292. package/dist/support/opportunity.persist.js.map +1 -0
  293. package/dist/support/opportunity.presentation.d.ts +21 -0
  294. package/dist/support/opportunity.presentation.d.ts.map +1 -0
  295. package/dist/support/opportunity.presentation.js +75 -0
  296. package/dist/support/opportunity.presentation.js.map +1 -0
  297. package/dist/support/opportunity.sanitize.d.ts +18 -0
  298. package/dist/support/opportunity.sanitize.d.ts.map +1 -0
  299. package/dist/support/opportunity.sanitize.js +89 -0
  300. package/dist/support/opportunity.sanitize.js.map +1 -0
  301. package/dist/support/opportunity.utils.d.ts +99 -0
  302. package/dist/support/opportunity.utils.d.ts.map +1 -0
  303. package/dist/support/opportunity.utils.js +184 -0
  304. package/dist/support/opportunity.utils.js.map +1 -0
  305. package/dist/support/performance.d.ts +19 -0
  306. package/dist/support/performance.d.ts.map +1 -0
  307. package/dist/support/performance.js +43 -0
  308. package/dist/support/performance.js.map +1 -0
  309. package/dist/support/profile.enrichment-display-name.d.ts +16 -0
  310. package/dist/support/profile.enrichment-display-name.d.ts.map +1 -0
  311. package/dist/support/profile.enrichment-display-name.js +22 -0
  312. package/dist/support/profile.enrichment-display-name.js.map +1 -0
  313. package/dist/support/protocol.logger.d.ts +22 -0
  314. package/dist/support/protocol.logger.d.ts.map +1 -0
  315. package/dist/support/protocol.logger.js +44 -0
  316. package/dist/support/protocol.logger.js.map +1 -0
  317. package/dist/support/request-context.d.ts +19 -0
  318. package/dist/support/request-context.d.ts.map +1 -0
  319. package/dist/support/request-context.js +7 -0
  320. package/dist/support/request-context.js.map +1 -0
  321. package/dist/tools/contact.tools.d.ts +7 -0
  322. package/dist/tools/contact.tools.d.ts.map +1 -0
  323. package/dist/tools/contact.tools.js +115 -0
  324. package/dist/tools/contact.tools.js.map +1 -0
  325. package/dist/tools/index.d.ts +17 -0
  326. package/dist/tools/index.d.ts.map +1 -0
  327. package/dist/tools/index.js +140 -0
  328. package/dist/tools/index.js.map +1 -0
  329. package/dist/tools/index.tools.d.ts +3 -0
  330. package/dist/tools/index.tools.d.ts.map +1 -0
  331. package/dist/tools/index.tools.js +423 -0
  332. package/dist/tools/index.tools.js.map +1 -0
  333. package/dist/tools/integration.tools.d.ts +13 -0
  334. package/dist/tools/integration.tools.d.ts.map +1 -0
  335. package/dist/tools/integration.tools.js +77 -0
  336. package/dist/tools/integration.tools.js.map +1 -0
  337. package/dist/tools/intent.tools.d.ts +3 -0
  338. package/dist/tools/intent.tools.d.ts.map +1 -0
  339. package/dist/tools/intent.tools.js +458 -0
  340. package/dist/tools/intent.tools.js.map +1 -0
  341. package/dist/tools/opportunity.tools.d.ts +44 -0
  342. package/dist/tools/opportunity.tools.d.ts.map +1 -0
  343. package/dist/tools/opportunity.tools.js +814 -0
  344. package/dist/tools/opportunity.tools.js.map +1 -0
  345. package/dist/tools/profile.tools.d.ts +3 -0
  346. package/dist/tools/profile.tools.d.ts.map +1 -0
  347. package/dist/tools/profile.tools.js +513 -0
  348. package/dist/tools/profile.tools.js.map +1 -0
  349. package/dist/tools/tool.helpers.d.ts +225 -0
  350. package/dist/tools/tool.helpers.d.ts.map +1 -0
  351. package/dist/tools/tool.helpers.js +172 -0
  352. package/dist/tools/tool.helpers.js.map +1 -0
  353. package/dist/tools/tool.registry.d.ts +12 -0
  354. package/dist/tools/tool.registry.d.ts.map +1 -0
  355. package/dist/tools/tool.registry.js +62 -0
  356. package/dist/tools/tool.registry.js.map +1 -0
  357. package/dist/tools/utility.tools.d.ts +3 -0
  358. package/dist/tools/utility.tools.d.ts.map +1 -0
  359. package/dist/tools/utility.tools.js +107 -0
  360. package/dist/tools/utility.tools.js.map +1 -0
  361. package/dist/types/chat-streaming.types.d.ts +472 -0
  362. package/dist/types/chat-streaming.types.d.ts.map +1 -0
  363. package/dist/types/chat-streaming.types.js +260 -0
  364. package/dist/types/chat-streaming.types.js.map +1 -0
  365. package/package.json +32 -0
@@ -0,0 +1,1495 @@
1
+ import { ProfileDocument } from '../agents/profile.generator.js';
2
+ /** Branded string ID for type-safe entity references (keyed by Drizzle table name). */
3
+ export type Id<T extends string = string> = string & {
4
+ readonly __table?: T;
5
+ };
6
+ /** Onboarding flow state stored as JSON on the user record. */
7
+ export interface OnboardingState {
8
+ completedAt?: string;
9
+ flow?: 1 | 2 | 3;
10
+ currentStep?: 'profile' | 'summary' | 'connections' | 'create_index' | 'invite_members' | 'join_indexes';
11
+ indexId?: string;
12
+ invitationCode?: string;
13
+ }
14
+ /** Social-media handles stored as JSON on the user record. */
15
+ export interface UserSocials {
16
+ x?: string;
17
+ linkedin?: string;
18
+ github?: string;
19
+ websites?: string[];
20
+ }
21
+ /** Detection metadata recorded when an opportunity is created. */
22
+ export interface OpportunityDetection {
23
+ source: 'opportunity_graph' | 'chat' | 'manual' | 'cron' | 'member_added' | 'enrichment';
24
+ createdBy?: Id<'users'> | string;
25
+ createdByName?: string;
26
+ triggeredBy?: Id<'intents'>;
27
+ timestamp: string;
28
+ enrichedFrom?: string[];
29
+ }
30
+ /** A participant (user + index) involved in an opportunity. */
31
+ export interface OpportunityActor {
32
+ indexId: Id<'indexes'>;
33
+ userId: Id<'users'>;
34
+ intent?: Id<'intents'>;
35
+ role: string;
36
+ }
37
+ /** Individual signal contributing to an opportunity score. */
38
+ export interface OpportunitySignal {
39
+ type: string;
40
+ weight: number;
41
+ detail?: string;
42
+ }
43
+ /** LLM-generated interpretation of an opportunity's category and confidence. */
44
+ export interface OpportunityInterpretation {
45
+ category: string;
46
+ reasoning: string;
47
+ confidence: number;
48
+ signals?: OpportunitySignal[];
49
+ }
50
+ /** Optional scoping context (index / conversation) for an opportunity. */
51
+ export interface OpportunityContext {
52
+ indexId?: Id<'indexes'>;
53
+ conversationId?: Id<'conversations'>;
54
+ }
55
+ /** User record returned by getUser (minimal fields plus optional profile fields). */
56
+ export interface UserRecord {
57
+ id: string;
58
+ name: string;
59
+ email: string;
60
+ intro?: string | null;
61
+ avatar?: string | null;
62
+ location?: string | null;
63
+ socials?: UserSocials | null;
64
+ onboarding?: OnboardingState | null;
65
+ isGhost?: boolean;
66
+ deletedAt?: Date | null;
67
+ }
68
+ /**
69
+ * Minimal intent representation used for graph state population.
70
+ * Contains only the fields needed for reconciliation logic.
71
+ */
72
+ export interface ActiveIntent {
73
+ /** Unique identifier of the intent */
74
+ id: string;
75
+ /** Full intent description/payload */
76
+ payload: string;
77
+ /** Short summary of the intent (may be null if not generated) */
78
+ summary: string | null;
79
+ /** When the intent was created */
80
+ createdAt: Date;
81
+ }
82
+ /**
83
+ * Input data for creating a new intent.
84
+ * Supports the full intent pipeline including embedding and index association.
85
+ */
86
+ export interface CreateIntentData {
87
+ /** The user who owns this intent */
88
+ userId: string;
89
+ /** Full intent description/payload */
90
+ payload: string;
91
+ /** Pre-computed summary (optional, will be generated if not provided) */
92
+ summary?: string | null;
93
+ /** Pre-computed embedding vector (optional, will be generated if not provided) */
94
+ embedding?: number[];
95
+ /** Whether the intent should be hidden from public views */
96
+ isIncognito?: boolean;
97
+ /** Index IDs to associate with (optional, uses dynamic scoping if empty) */
98
+ indexIds?: string[];
99
+ /** Source type for provenance tracking */
100
+ sourceType?: 'file' | 'integration' | 'link' | 'discovery_form' | 'enrichment';
101
+ /** Source ID for provenance tracking */
102
+ sourceId?: string;
103
+ /** Confidence score from inference (0-1, required) */
104
+ confidence: number;
105
+ /** How the intent was inferred */
106
+ inferenceType: 'explicit' | 'implicit';
107
+ /** Semantic entropy from verifier (0 specific -> 1 vague) */
108
+ semanticEntropy?: number | null;
109
+ /** Referential anchor extracted by verifier (if any) */
110
+ referentialAnchor?: string | null;
111
+ /** Felicity authority score from verifier (0-100) */
112
+ felicityAuthority?: number | null;
113
+ /** Felicity sincerity score from verifier (0-100) */
114
+ felicitySincerity?: number | null;
115
+ /** Donnellan intent mode */
116
+ intentMode?: 'REFERENTIAL' | 'ATTRIBUTIVE' | null;
117
+ /** Speech act category used by protocol enum */
118
+ speechActType?: 'COMMISSIVE' | 'DIRECTIVE' | null;
119
+ }
120
+ /**
121
+ * Input data for updating an existing intent.
122
+ * All fields are optional - only provided fields will be updated.
123
+ */
124
+ export interface UpdateIntentData {
125
+ /** Updated intent description/payload */
126
+ payload?: string;
127
+ /** Updated summary */
128
+ summary?: string | null;
129
+ /** Updated embedding vector */
130
+ embedding?: number[];
131
+ /** Updated incognito status */
132
+ isIncognito?: boolean;
133
+ /** Updated index associations (replaces existing) */
134
+ indexIds?: string[];
135
+ /** Semantic entropy from verifier (0 specific -> 1 vague) */
136
+ semanticEntropy?: number | null;
137
+ /** Referential anchor extracted by verifier (if any) */
138
+ referentialAnchor?: string | null;
139
+ /** Felicity authority score from verifier (0-100) */
140
+ felicityAuthority?: number | null;
141
+ /** Felicity sincerity score from verifier (0-100) */
142
+ felicitySincerity?: number | null;
143
+ /** Donnellan intent mode */
144
+ intentMode?: 'REFERENTIAL' | 'ATTRIBUTIVE' | null;
145
+ /** Speech act category used by protocol enum */
146
+ speechActType?: 'COMMISSIVE' | 'DIRECTIVE' | null;
147
+ }
148
+ /**
149
+ * The result of a successful intent creation.
150
+ * Contains the core fields needed for immediate use.
151
+ */
152
+ export interface CreatedIntent {
153
+ /** Unique identifier of the created intent */
154
+ id: string;
155
+ /** Full intent description/payload */
156
+ payload: string;
157
+ /** Generated or provided summary */
158
+ summary: string | null;
159
+ /** Incognito status */
160
+ isIncognito: boolean;
161
+ /** Creation timestamp */
162
+ createdAt: Date;
163
+ /** Last update timestamp */
164
+ updatedAt: Date;
165
+ /** Owner user ID */
166
+ userId: string;
167
+ }
168
+ /**
169
+ * Full intent record with all fields (for detailed queries).
170
+ */
171
+ export interface IntentRecord extends CreatedIntent {
172
+ /** Archival timestamp (null if active) */
173
+ archivedAt: Date | null;
174
+ /** Embedding vector (may be null) */
175
+ embedding?: number[] | null;
176
+ /** Source type for provenance */
177
+ sourceType?: string | null;
178
+ /** Source ID for provenance */
179
+ sourceId?: string | null;
180
+ }
181
+ /**
182
+ * Intent with similarity score from vector search.
183
+ */
184
+ export interface SimilarIntent extends IntentRecord {
185
+ /** Cosine similarity score (0-1) */
186
+ similarity: number;
187
+ }
188
+ /**
189
+ * Result of an archive operation.
190
+ */
191
+ export interface ArchiveResult {
192
+ /** Whether the operation succeeded */
193
+ success: boolean;
194
+ /** Error message if failed */
195
+ error?: string;
196
+ }
197
+ /**
198
+ * Options for vector similarity search.
199
+ */
200
+ export interface SimilarIntentSearchOptions {
201
+ /** Maximum number of results to return (default: 10) */
202
+ limit?: number;
203
+ /** Minimum similarity threshold (default: 0.7) */
204
+ threshold?: number;
205
+ }
206
+ /**
207
+ * Represents a user's membership in an index with full details.
208
+ * Used for displaying index memberships in chat (index_query).
209
+ */
210
+ export interface IndexMembership {
211
+ /** Unique identifier of the index */
212
+ indexId: string;
213
+ /** Display title of the index */
214
+ indexTitle: string;
215
+ /** Index description/prompt (what the community is about) */
216
+ indexPrompt: string | null;
217
+ /** Member's permissions in this index */
218
+ permissions: string[];
219
+ /** Member's custom prompt (overrides index prompt for their intents) */
220
+ memberPrompt: string | null;
221
+ /** Whether new intents are auto-assigned to this index */
222
+ autoAssign: boolean;
223
+ /** Whether this is the user's personal index ("My Network") */
224
+ isPersonal: boolean;
225
+ /** When the user joined the index */
226
+ joinedAt: Date;
227
+ }
228
+ /**
229
+ * Represents an index owned by the user with full details.
230
+ */
231
+ export interface OwnedIndex {
232
+ /** Index ID */
233
+ id: string;
234
+ /** Display title */
235
+ title: string;
236
+ /** Index purpose/scope prompt */
237
+ prompt: string | null;
238
+ /** Cover image URL */
239
+ imageUrl: string | null;
240
+ /** Permission settings */
241
+ permissions: {
242
+ joinPolicy: 'anyone' | 'invite_only';
243
+ allowGuestVibeCheck: boolean;
244
+ invitationLink: {
245
+ code: string;
246
+ } | null;
247
+ };
248
+ /** Whether this is a personal index */
249
+ isPersonal: boolean;
250
+ /** When the index was created */
251
+ createdAt: Date;
252
+ /** When the index was last updated */
253
+ updatedAt: Date;
254
+ /** Member count */
255
+ memberCount: number;
256
+ /** Total intents indexed */
257
+ intentCount: number;
258
+ /** Owner summary */
259
+ user: {
260
+ id: string;
261
+ name: string;
262
+ avatar: string | null;
263
+ };
264
+ /** Aggregate counts for frontend compatibility */
265
+ _count: {
266
+ members: number;
267
+ };
268
+ }
269
+ /**
270
+ * Member details visible to index owners (and optionally to members with privacy rules).
271
+ */
272
+ export interface IndexMemberDetails {
273
+ /** User ID */
274
+ userId: string;
275
+ /** User's display name */
276
+ name: string;
277
+ /** User's avatar URL */
278
+ avatar: string | null;
279
+ /** User's email; only present when viewer is owner/admin or the member themselves (privacy-safe) */
280
+ email?: string | null;
281
+ /** Member's permissions in this index */
282
+ permissions: string[];
283
+ /** Member's custom prompt */
284
+ memberPrompt: string | null;
285
+ /** Whether auto-assign is enabled */
286
+ autoAssign: boolean;
287
+ /** When they joined */
288
+ joinedAt: Date;
289
+ /** Count of their intents in this index */
290
+ intentCount: number;
291
+ /** Whether this user is a ghost (not yet onboarded) */
292
+ isGhost?: boolean;
293
+ }
294
+ /**
295
+ * Intent details visible to index owners.
296
+ */
297
+ export interface IndexedIntentDetails {
298
+ /** Intent ID */
299
+ id: string;
300
+ /** Intent payload/description */
301
+ payload: string;
302
+ /** Intent summary */
303
+ summary: string | null;
304
+ /** Owner's user ID */
305
+ userId: string;
306
+ /** Owner's name */
307
+ userName: string;
308
+ /** When the intent was created */
309
+ createdAt: Date;
310
+ }
311
+ /**
312
+ * Options for updating index settings.
313
+ */
314
+ export interface UpdateIndexSettingsData {
315
+ /** New title (optional) */
316
+ title?: string;
317
+ /** New prompt (optional) */
318
+ prompt?: string | null;
319
+ /** New image URL (optional) */
320
+ imageUrl?: string | null;
321
+ /** New join policy (optional) */
322
+ joinPolicy?: 'anyone' | 'invite_only';
323
+ /** Allow guest vibe check (optional) */
324
+ allowGuestVibeCheck?: boolean;
325
+ }
326
+ export type HydeSourceType = 'intent' | 'profile' | 'query';
327
+ export interface HydeDocument {
328
+ id: string;
329
+ sourceType: HydeSourceType;
330
+ sourceId: string | null;
331
+ sourceText: string | null;
332
+ strategy: string;
333
+ targetCorpus: string;
334
+ hydeText: string;
335
+ hydeEmbedding: number[];
336
+ context: Record<string, unknown> | null;
337
+ createdAt: Date;
338
+ expiresAt: Date | null;
339
+ }
340
+ export interface CreateHydeDocumentData {
341
+ sourceType: HydeSourceType;
342
+ sourceId?: string;
343
+ sourceText?: string;
344
+ strategy: string;
345
+ targetCorpus: string;
346
+ hydeText: string;
347
+ hydeEmbedding: number[];
348
+ context?: Record<string, unknown>;
349
+ expiresAt?: Date;
350
+ }
351
+ export type OpportunityStatus = 'latent' | 'draft' | 'pending' | 'accepted' | 'rejected' | 'expired';
352
+ export interface Opportunity {
353
+ id: string;
354
+ detection: OpportunityDetection;
355
+ actors: OpportunityActor[];
356
+ interpretation: OpportunityInterpretation;
357
+ context: OpportunityContext;
358
+ confidence: string;
359
+ status: OpportunityStatus;
360
+ createdAt: Date;
361
+ updatedAt: Date;
362
+ expiresAt: Date | null;
363
+ }
364
+ export interface CreateOpportunityData {
365
+ detection: OpportunityDetection;
366
+ actors: OpportunityActor[];
367
+ interpretation: OpportunityInterpretation;
368
+ context: OpportunityContext;
369
+ confidence: string;
370
+ status?: OpportunityStatus;
371
+ expiresAt?: Date;
372
+ }
373
+ export interface OpportunityQueryOptions {
374
+ status?: OpportunityStatus;
375
+ indexId?: string;
376
+ role?: string;
377
+ limit?: number;
378
+ offset?: number;
379
+ /** When set, include draft opportunities for this chat session. When unset, exclude all draft opportunities (e.g. home view, API). */
380
+ conversationId?: string;
381
+ }
382
+ /**
383
+ * Abstract database interface for performing specific domain operations.
384
+ * Decouples the protocol layer from the infrastructure layer.
385
+ */
386
+ export interface Database {
387
+ /**
388
+ * Retrieves a user profile by userId.
389
+ * @param userId - The unique identifier of the user
390
+ * @returns The user's profile or null if not found
391
+ */
392
+ getProfile(userId: string): Promise<ProfileDocument | null>;
393
+ /**
394
+ * Creates or updates a user profile.
395
+ * @param userId - The unique identifier of the user
396
+ * @param profile - The profile data to save
397
+ */
398
+ saveProfile(userId: string, profile: ProfileDocument): Promise<void>;
399
+ /**
400
+ * Retrieves basic user information (name, email, socials) by userId.
401
+ * @param userId - The unique identifier of the user
402
+ * @returns The user record or null if not found
403
+ */
404
+ getUser(userId: string): Promise<UserRecord | null>;
405
+ /**
406
+ * Updates user account fields (name, location, socials).
407
+ * Merges socials with existing values (does not overwrite the whole object).
408
+ * Used by create_user_profile tool to persist user-provided info before
409
+ * invoking the Profile Graph in generate mode.
410
+ *
411
+ * @param userId - The unique identifier of the user
412
+ * @param data - Partial user fields to update
413
+ * @returns The updated user record or null if not found
414
+ */
415
+ updateUser(userId: string, data: {
416
+ name?: string;
417
+ intro?: string;
418
+ location?: string;
419
+ socials?: UserSocials;
420
+ onboarding?: OnboardingState;
421
+ }): Promise<UserRecord | null>;
422
+ /**
423
+ * Soft-delete a ghost user and all their contact memberships.
424
+ * Used when enrichment determines the entity is not a real person.
425
+ * @param userId - The ghost user to soft-delete
426
+ * @returns true if the user was soft-deleted
427
+ */
428
+ softDeleteGhost(userId: string): Promise<boolean>;
429
+ /**
430
+ * Retrieves all active (non-archived) intents for a user.
431
+ * Used to populate the `activeIntents` field in the Intent Graph state
432
+ * before graph execution.
433
+ *
434
+ * @param userId - The unique identifier of the user
435
+ * @returns Array of active intents with minimal fields needed for reconciliation
436
+ *
437
+ * @example
438
+ * ```typescript
439
+ * const activeIntents = await db.getActiveIntents(userId);
440
+ * const formattedIntents = activeIntents
441
+ * .map(i => `ID: ${i.id}, Description: ${i.payload}, Summary: ${i.summary || 'N/A'}`)
442
+ * .join('\n');
443
+ * ```
444
+ */
445
+ getActiveIntents(userId: string): Promise<ActiveIntent[]>;
446
+ /**
447
+ * Get active intents that belong to the user and are assigned to a specific index.
448
+ * Caller must be a member of that index; only the user's own intents are returned.
449
+ *
450
+ * @param userId - The user requesting (must be a member of the index)
451
+ * @param indexNameOrId - Index UUID or display name (e.g. "Commons")
452
+ * @returns Array of active intents in that index for the user, or empty if not a member / no match
453
+ */
454
+ getIntentsInIndexForMember(userId: string, indexNameOrId: string): Promise<ActiveIntent[]>;
455
+ /**
456
+ * Creates a new intent with full processing pipeline.
457
+ * Handles summarization, embedding generation, and index association.
458
+ *
459
+ * Called when the reconciler outputs a "create" action.
460
+ *
461
+ * @param data - The intent creation data
462
+ * @returns The created intent with generated fields
463
+ *
464
+ * @example
465
+ * ```typescript
466
+ * // After graph outputs CREATE action
467
+ * const newIntent = await db.createIntent({
468
+ * userId,
469
+ * payload: action.payload,
470
+ * confidence: action.score / 100,
471
+ * inferenceType: 'explicit',
472
+ * sourceType: 'discovery_form'
473
+ * });
474
+ * ```
475
+ */
476
+ createIntent(data: CreateIntentData): Promise<CreatedIntent>;
477
+ /**
478
+ * Updates an existing intent.
479
+ * Re-generates summary and embedding if payload changes.
480
+ *
481
+ * Called when the reconciler outputs an "update" action.
482
+ *
483
+ * @param intentId - The unique identifier of the intent to update
484
+ * @param data - The fields to update
485
+ * @returns The updated intent or null if not found
486
+ * @throws Error if the intent exists but user doesn't have access
487
+ *
488
+ * @example
489
+ * ```typescript
490
+ * // After graph outputs UPDATE action
491
+ * const updated = await db.updateIntent(action.id, {
492
+ * payload: action.payload
493
+ * });
494
+ * ```
495
+ */
496
+ updateIntent(intentId: string, data: UpdateIntentData): Promise<CreatedIntent | null>;
497
+ /**
498
+ * Archives (soft-deletes) an intent.
499
+ * Sets the archivedAt timestamp rather than hard deleting.
500
+ *
501
+ * Called when the reconciler outputs an "expire" action.
502
+ *
503
+ * @param intentId - The unique identifier of the intent to archive
504
+ * @returns Result object indicating success or failure with error message
505
+ *
506
+ * @example
507
+ * ```typescript
508
+ * // After graph outputs EXPIRE action
509
+ * const result = await db.archiveIntent(action.id);
510
+ * if (!result.success) {
511
+ * console.error(`Failed to archive: ${result.error}`);
512
+ * }
513
+ * ```
514
+ */
515
+ archiveIntent(intentId: string): Promise<ArchiveResult>;
516
+ /**
517
+ * Retrieves a single intent by ID.
518
+ *
519
+ * @param intentId - The unique identifier of the intent
520
+ * @returns The full intent record or null if not found
521
+ */
522
+ getIntent(intentId: string): Promise<IntentRecord | null>;
523
+ /**
524
+ * Retrieves an intent with ownership verification.
525
+ * Ensures the requesting user owns the intent before returning.
526
+ *
527
+ * Used for processing operations (refine, suggestions) that require ownership.
528
+ *
529
+ * @param intentId - The unique identifier of the intent
530
+ * @param userId - The user requesting access
531
+ * @returns The intent if found and owned by user, null if not found
532
+ * @throws Error with message 'Access denied' if intent exists but is not owned by user
533
+ *
534
+ * @example
535
+ * ```typescript
536
+ * try {
537
+ * const intent = await db.getIntentWithOwnership(intentId, userId);
538
+ * if (!intent) return res.status(404).json({ error: 'Not found' });
539
+ * // Process intent...
540
+ * } catch (e) {
541
+ * if (e.message === 'Access denied') {
542
+ * return res.status(403).json({ error: 'Forbidden' });
543
+ * }
544
+ * throw e;
545
+ * }
546
+ * ```
547
+ */
548
+ getIntentWithOwnership(intentId: string, userId: string): Promise<IntentRecord | null>;
549
+ /**
550
+ * Gets Index IDs where the user has auto-assign membership enabled.
551
+ * Used for determining which indexes to associate new intents with.
552
+ *
553
+ * @param userId - The unique identifier of the user
554
+ * @returns Array of index IDs
555
+ *
556
+ * @example
557
+ * ```typescript
558
+ * const indexIds = await db.getUserIndexIds(userId);
559
+ * if (indexIds.length > 0) {
560
+ * await db.associateIntentWithIndexes(intentId, indexIds);
561
+ * }
562
+ * ```
563
+ */
564
+ getUserIndexIds(userId: string): Promise<string[]>;
565
+ /**
566
+ * Retrieves all indexes the user is a member of with full details.
567
+ * Used for displaying index memberships in chat (index_query).
568
+ *
569
+ * @param userId - The unique identifier of the user
570
+ * @returns Array of index memberships with details
571
+ */
572
+ getIndexMemberships(userId: string): Promise<IndexMembership[]>;
573
+ /**
574
+ * Get a single index membership by index and user.
575
+ * Used when the preloaded memberships list may not contain this index (e.g. after isIndexMember check).
576
+ *
577
+ * @param indexId - The index ID
578
+ * @param userId - The user ID
579
+ * @returns The membership or null if not found
580
+ */
581
+ getIndexMembership(indexId: string, userId: string): Promise<IndexMembership | null>;
582
+ /**
583
+ * Get index by ID (id and title only). Used for opportunity presentation.
584
+ */
585
+ getIndex(indexId: string): Promise<{
586
+ id: string;
587
+ title: string;
588
+ } | null>;
589
+ /**
590
+ * Get index by ID with permissions (e.g. joinPolicy). Used by chat tools for create_index_membership.
591
+ */
592
+ getIndexWithPermissions(indexId: string): Promise<{
593
+ id: string;
594
+ title: string;
595
+ permissions: {
596
+ joinPolicy: 'anyone' | 'invite_only';
597
+ };
598
+ } | null>;
599
+ /**
600
+ * Associates an intent with one or more indexes.
601
+ * Creates entries in the intentIndexes join table.
602
+ *
603
+ * @param intentId - The intent to associate
604
+ * @param indexIds - Array of index IDs to associate with
605
+ *
606
+ * @example
607
+ * ```typescript
608
+ * await db.associateIntentWithIndexes(intentId, ['idx_1', 'idx_2']);
609
+ * ```
610
+ */
611
+ associateIntentWithIndexes(intentId: string, indexIds: string[]): Promise<void>;
612
+ /**
613
+ * Finds semantically similar intents using vector search.
614
+ * Used for deduplication during intent creation and discovery.
615
+ *
616
+ * Privacy scoping: Results are always filtered by userId to ensure
617
+ * users only see their own intents.
618
+ *
619
+ * @param embedding - The query embedding vector
620
+ * @param userId - The user ID for privacy scoping (required)
621
+ * @param options - Search options (limit, threshold)
622
+ * @returns Array of intents with similarity scores, sorted by similarity
623
+ *
624
+ * @example
625
+ * ```typescript
626
+ * // Check for duplicates before creating
627
+ * const embedding = await embedder.generate(payload);
628
+ * const similar = await db.findSimilarIntents(embedding, userId, {
629
+ * limit: 5,
630
+ * threshold: 0.85
631
+ * });
632
+ * if (similar.length > 0 && similar[0].similarity > 0.95) {
633
+ * // Likely duplicate - consider updating instead
634
+ * }
635
+ * ```
636
+ */
637
+ findSimilarIntents(embedding: number[], userId: string, options?: SimilarIntentSearchOptions): Promise<SimilarIntent[]>;
638
+ /**
639
+ * Intent fields needed for index appropriateness evaluation.
640
+ */
641
+ getIntentForIndexing(intentId: string): Promise<{
642
+ id: string;
643
+ payload: string;
644
+ userId: string;
645
+ sourceType: string | null;
646
+ sourceId: string | null;
647
+ } | null>;
648
+ /**
649
+ * Index + member prompts for a user in an index (only when member has autoAssign).
650
+ * Returns null if user is not a member or autoAssign is false.
651
+ */
652
+ getIndexMemberContext(indexId: string, userId: string): Promise<{
653
+ indexId: string;
654
+ indexPrompt: string | null;
655
+ memberPrompt: string | null;
656
+ } | null>;
657
+ /**
658
+ * Whether the intent is currently assigned to the index.
659
+ */
660
+ isIntentAssignedToIndex(intentId: string, indexId: string): Promise<boolean>;
661
+ /**
662
+ * Assigns an intent to an index (inserts intent_indexes row).
663
+ */
664
+ assignIntentToIndex(intentId: string, indexId: string, relevancyScore?: number): Promise<void>;
665
+ /**
666
+ * Returns per-index relevancy scores for an intent's index assignments.
667
+ */
668
+ getIntentIndexScores(intentId: string): Promise<Array<{
669
+ indexId: string;
670
+ relevancyScore: number | null;
671
+ }>>;
672
+ /**
673
+ * Removes an intent from an index (deletes intent_indexes row).
674
+ */
675
+ unassignIntentFromIndex(intentId: string, indexId: string): Promise<void>;
676
+ /**
677
+ * Returns all index IDs that an intent is registered to.
678
+ */
679
+ getIndexIdsForIntent(intentId: string): Promise<string[]>;
680
+ /**
681
+ * Get indexes where the user has owner permissions.
682
+ * Returns full index details with member and intent counts.
683
+ *
684
+ * @param userId - The user ID to check ownership for
685
+ * @returns Array of owned indexes with counts
686
+ */
687
+ getOwnedIndexes(userId: string): Promise<OwnedIndex[]>;
688
+ /**
689
+ * Get public indexes (joinPolicy 'anyone') that the user has not joined.
690
+ * Used for discovering communities available to join.
691
+ *
692
+ * @param userId - The user ID to check memberships against
693
+ * @returns Object containing array of public indexes with owner info
694
+ */
695
+ getPublicIndexesNotJoined(userId: string): Promise<{
696
+ indexes: Array<{
697
+ id: string;
698
+ title: string;
699
+ prompt: string | null;
700
+ memberCount: number;
701
+ owner: {
702
+ id: string;
703
+ name: string;
704
+ avatar: string | null;
705
+ } | null;
706
+ }>;
707
+ }>;
708
+ /**
709
+ * Check if user is an owner of a specific index.
710
+ *
711
+ * @param indexId - The index to check
712
+ * @param userId - The user to verify ownership for
713
+ * @returns True if user is an owner
714
+ */
715
+ isIndexOwner(indexId: string, userId: string): Promise<boolean>;
716
+ /**
717
+ * Check if user is a member of a specific index.
718
+ *
719
+ * @param indexId - The index to check
720
+ * @param userId - The user to verify membership for
721
+ * @returns True if user is a member
722
+ */
723
+ isIndexMember(indexId: string, userId: string): Promise<boolean>;
724
+ /**
725
+ * Get all members of an index with their details.
726
+ * **OWNER ONLY** - throws if user is not an owner.
727
+ *
728
+ * @param indexId - The index to get members for
729
+ * @param requestingUserId - The user requesting (must be owner)
730
+ * @returns Array of member details with intent counts
731
+ * @throws Error if requestingUserId is not an owner
732
+ */
733
+ getIndexMembersForOwner(indexId: string, requestingUserId: string): Promise<IndexMemberDetails[]>;
734
+ /**
735
+ * Get all members of an index with their details.
736
+ * **MEMBER ONLY** - any member of the index can list members (not just owners).
737
+ * Returns same shape as getIndexMembersForOwner; email may be omitted for privacy.
738
+ *
739
+ * @param indexId - The index to get members for
740
+ * @param requestingUserId - The user requesting (must be a member of the index)
741
+ * @returns Array of member details with intent counts
742
+ * @throws Error if requestingUserId is not a member of the index
743
+ */
744
+ getIndexMembersForMember(indexId: string, requestingUserId: string): Promise<IndexMemberDetails[]>;
745
+ /**
746
+ * Get all members from every index the user is a member of (deduplicated).
747
+ * Used for mentionable-users: anyone who shares at least one index with the requesting user.
748
+ *
749
+ * @param userId - The signed-in user
750
+ * @returns Array of member summaries (id, name, avatar only; no email)
751
+ */
752
+ getMembersFromUserIndexes(userId: Id<'users'>): Promise<{
753
+ userId: Id<'users'>;
754
+ name: string;
755
+ avatar: string | null;
756
+ }[]>;
757
+ /**
758
+ * Get all indexed intents for an index.
759
+ * **OWNER ONLY** - throws if user is not an owner.
760
+ *
761
+ * @param indexId - The index to get intents for
762
+ * @param requestingUserId - The user requesting (must be owner)
763
+ * @param options - Pagination options
764
+ * @returns Array of intent details with owner info
765
+ * @throws Error if requestingUserId is not an owner
766
+ */
767
+ getIndexIntentsForOwner(indexId: string, requestingUserId: string, options?: {
768
+ limit?: number;
769
+ offset?: number;
770
+ }): Promise<IndexedIntentDetails[]>;
771
+ /**
772
+ * Get all indexed intents for an index.
773
+ * **MEMBER ONLY** - any member of the index can list intents (not just owners).
774
+ *
775
+ * @param indexId - The index to get intents for
776
+ * @param requestingUserId - The user requesting (must be a member of the index)
777
+ * @param options - Pagination options
778
+ * @returns Array of intent details with owner info
779
+ * @throws Error if requestingUserId is not a member of the index
780
+ */
781
+ getIndexIntentsForMember(indexId: string, requestingUserId: string, options?: {
782
+ limit?: number;
783
+ offset?: number;
784
+ }): Promise<IndexedIntentDetails[]>;
785
+ /**
786
+ * Update index settings.
787
+ * **OWNER ONLY** - throws if user is not an owner.
788
+ *
789
+ * @param indexId - The index to update
790
+ * @param requestingUserId - The user requesting (must be owner)
791
+ * @param data - The settings to update
792
+ * @returns The updated index
793
+ * @throws Error if requestingUserId is not an owner
794
+ */
795
+ updateIndexSettings(indexId: string, requestingUserId: string, data: UpdateIndexSettingsData): Promise<OwnedIndex>;
796
+ /**
797
+ * Soft-delete an index (set deletedAt).
798
+ * Caller must ensure index is not personal and has no other members.
799
+ *
800
+ * @param indexId - The index to soft-delete
801
+ */
802
+ softDeleteIndex(indexId: string): Promise<void>;
803
+ /**
804
+ * Delete a user's profile (removes profile row).
805
+ * Used after confirmation in chat tools.
806
+ *
807
+ * @param userId - User whose profile to delete
808
+ */
809
+ deleteProfile(userId: string): Promise<void>;
810
+ /**
811
+ * Get a user's profile including its row id (for update_user_profile validation).
812
+ *
813
+ * @param userId - The user whose profile to fetch
814
+ * @returns Profile with id, or null if not found
815
+ */
816
+ getProfileByUserId(userId: string): Promise<(ProfileDocument & {
817
+ id: string;
818
+ }) | null>;
819
+ /**
820
+ * Create a new index and return its record.
821
+ *
822
+ * @param data - Title, optional prompt, optional imageUrl, optional joinPolicy
823
+ * @returns The created index with id, title, prompt, imageUrl, permissions
824
+ */
825
+ createIndex(data: {
826
+ title: string;
827
+ prompt?: string | null;
828
+ imageUrl?: string | null;
829
+ joinPolicy?: 'anyone' | 'invite_only';
830
+ }): Promise<{
831
+ id: string;
832
+ title: string;
833
+ prompt: string | null;
834
+ imageUrl: string | null;
835
+ permissions: {
836
+ joinPolicy: 'anyone' | 'invite_only';
837
+ invitationLink: {
838
+ code: string;
839
+ } | null;
840
+ allowGuestVibeCheck: boolean;
841
+ };
842
+ }>;
843
+ /**
844
+ * Count members in an index (for delete guard).
845
+ *
846
+ * @param indexId - The index to count
847
+ * @returns Number of members
848
+ */
849
+ getIndexMemberCount(indexId: string): Promise<number>;
850
+ /**
851
+ * Add a user as a member of an index (replaces deprecated lib/index-members.ts).
852
+ *
853
+ * @param indexId - The index to add to
854
+ * @param userId - The user to add
855
+ * @param role - owner | admin | member
856
+ * @returns success and optionally alreadyMember if they were already in the index
857
+ */
858
+ addMemberToIndex(indexId: string, userId: string, role: 'owner' | 'admin' | 'member'): Promise<{
859
+ success: boolean;
860
+ alreadyMember?: boolean;
861
+ }>;
862
+ /**
863
+ * Removes a user from an index.
864
+ * Only the index owner can remove members. Cannot remove the owner.
865
+ *
866
+ * @param indexId - The index to remove from
867
+ * @param userId - The user to remove
868
+ * @returns success, or wasOwner/notMember if removal failed
869
+ */
870
+ removeMemberFromIndex(indexId: string, userId: string): Promise<{
871
+ success: boolean;
872
+ wasOwner?: boolean;
873
+ notMember?: boolean;
874
+ }>;
875
+ /**
876
+ * Get a HyDE document by source and strategy/lens hash.
877
+ * Returns the first matching document when multiple target corpuses exist.
878
+ *
879
+ * @param sourceType - 'intent' | 'profile' | 'query'
880
+ * @param sourceId - Source entity ID (e.g. intent ID, user ID)
881
+ * @param strategy - Lens hash (SHA-256 of lens label) or legacy strategy name
882
+ * @returns The HyDE document or null if not found
883
+ */
884
+ getHydeDocument(sourceType: HydeSourceType, sourceId: string, strategy: string): Promise<HydeDocument | null>;
885
+ /**
886
+ * Get all HyDE documents for a source (all strategies).
887
+ *
888
+ * @param sourceType - 'intent' | 'profile' | 'query'
889
+ * @param sourceId - Source entity ID
890
+ * @returns Array of HyDE documents for that source
891
+ */
892
+ getHydeDocumentsForSource(sourceType: HydeSourceType, sourceId: string): Promise<HydeDocument[]>;
893
+ /**
894
+ * Save a HyDE document (upsert by sourceType + sourceId + strategy/lensHash + targetCorpus).
895
+ *
896
+ * @param data - HyDE document data
897
+ * @returns The saved HyDE document
898
+ */
899
+ saveHydeDocument(data: CreateHydeDocumentData): Promise<HydeDocument>;
900
+ /**
901
+ * Delete all HyDE documents for a source (e.g. when intent/profile archived).
902
+ *
903
+ * @param sourceType - 'intent' | 'profile' | 'query'
904
+ * @param sourceId - Source entity ID
905
+ * @returns Number of documents deleted
906
+ */
907
+ deleteHydeDocumentsForSource(sourceType: HydeSourceType, sourceId: string): Promise<number>;
908
+ /**
909
+ * Delete expired HyDE documents (expires_at <= now). Used by maintenance jobs.
910
+ *
911
+ * @returns Number of documents deleted
912
+ */
913
+ deleteExpiredHydeDocuments(): Promise<number>;
914
+ /**
915
+ * Get stale HyDE documents for refresh (e.g. createdAt < threshold).
916
+ *
917
+ * @param threshold - Date threshold; documents created before this are considered stale
918
+ * @returns Array of stale HyDE documents
919
+ */
920
+ getStaleHydeDocuments(threshold: Date): Promise<HydeDocument[]>;
921
+ /**
922
+ * Create a new opportunity.
923
+ *
924
+ * @param data - Opportunity creation data
925
+ * @returns The created opportunity
926
+ */
927
+ createOpportunity(data: CreateOpportunityData): Promise<Opportunity>;
928
+ /**
929
+ * Get a single opportunity by ID.
930
+ *
931
+ * @param id - Opportunity ID
932
+ * @returns The opportunity or null if not found
933
+ */
934
+ getOpportunity(id: string): Promise<Opportunity | null>;
935
+ /**
936
+ * Resolve an opportunity identifier (full UUID or short prefix) to a full UUID.
937
+ * @param idOrPrefix - Full UUID or short hex prefix
938
+ * @param userId - The user ID (for visibility scoping)
939
+ * @returns Resolved ID, ambiguous marker, or null if not found
940
+ */
941
+ resolveOpportunityId(idOrPrefix: string, userId: string): Promise<{
942
+ id: string;
943
+ } | {
944
+ ambiguous: true;
945
+ } | null>;
946
+ /**
947
+ * Get opportunities for a user (as any actor role).
948
+ *
949
+ * @param userId - User ID (actor userId)
950
+ * @param options - Optional filters and pagination
951
+ * @returns Array of opportunities
952
+ */
953
+ getOpportunitiesForUser(userId: string, options?: OpportunityQueryOptions): Promise<Opportunity[]>;
954
+ /**
955
+ * Get opportunities in an index (for index admins).
956
+ *
957
+ * @param indexId - Index ID
958
+ * @param options - Optional filters and pagination
959
+ * @returns Array of opportunities
960
+ */
961
+ getOpportunitiesForIndex(indexId: string, options?: OpportunityQueryOptions): Promise<Opportunity[]>;
962
+ /**
963
+ * Update an opportunity's status.
964
+ *
965
+ * @param id - Opportunity ID
966
+ * @param status - New status
967
+ * @returns The updated opportunity or null if not found
968
+ */
969
+ updateOpportunityStatus(id: string, status: OpportunityStatus): Promise<Opportunity | null>;
970
+ /**
971
+ * Create one opportunity and expire others in a single transaction.
972
+ * Atomic: insert then update status to 'expired' for each id in expireIds.
973
+ * Used when enriching replaces overlapping opportunities so subscribers see consistent state.
974
+ *
975
+ * @param data - Opportunity creation data (caller may set status when enriched)
976
+ * @param expireIds - Opportunity IDs to set status to 'expired'
977
+ * @returns The created opportunity and the list of opportunities that were expired
978
+ */
979
+ createOpportunityAndExpireIds(data: CreateOpportunityData, expireIds: string[]): Promise<{
980
+ created: Opportunity;
981
+ expired: Opportunity[];
982
+ }>;
983
+ /**
984
+ * Check if an opportunity already exists between the given actors in the index (deduplication).
985
+ *
986
+ * @param actorIds - Array of user IDs that would be actors
987
+ * @param indexId - Index ID
988
+ * @returns True if a non-expired opportunity exists with exactly these actors in this index
989
+ */
990
+ opportunityExistsBetweenActors(actorIds: string[], indexId: string): Promise<boolean>;
991
+ /**
992
+ * Return one non-expired opportunity between the given actors in the index, if any.
993
+ * Used to avoid creating a duplicate and to surface existing opportunity id/status.
994
+ *
995
+ * @param actorIds - Array of user IDs that would be actors
996
+ * @param indexId - Index ID
997
+ * @returns The first matching opportunity's id and status, or null
998
+ */
999
+ getOpportunityBetweenActors(actorIds: string[], indexId: string): Promise<{
1000
+ id: Id<'opportunities'>;
1001
+ status: OpportunityStatus;
1002
+ } | null>;
1003
+ /**
1004
+ * Find opportunities whose non-introducer actor set exactly matches the given user IDs.
1005
+ * Overlap semantics: exact actor-set equality — an opportunity is returned only if its set of
1006
+ * non-introducer actor userIds (ignoring introducers) equals the set of actorUserIds. Index-agnostic;
1007
+ * opportunities are not scoped to a single index.
1008
+ *
1009
+ * @param actorUserIds - Typed user IDs of non-introducer actors (order-independent; compared as sets)
1010
+ * @param options - Optional excludeStatuses (no default). Uses OpportunityStatus.
1011
+ * @returns Promise of opportunities matching the exact actor set, excluding specified statuses
1012
+ */
1013
+ findOverlappingOpportunities(actorUserIds: Id<'users'>[], options?: {
1014
+ excludeStatuses?: OpportunityStatus[];
1015
+ }): Promise<Opportunity[]>;
1016
+ /**
1017
+ * Expire opportunities referencing an intent (e.g. when intent is archived).
1018
+ *
1019
+ * @param intentId - Intent ID to match in opportunity actors
1020
+ * @returns Number of opportunities updated to expired
1021
+ */
1022
+ expireOpportunitiesByIntent(intentId: string): Promise<number>;
1023
+ /**
1024
+ * Expire opportunities for a user removed from an index.
1025
+ *
1026
+ * @param indexId - Index ID
1027
+ * @param userId - User ID that was removed
1028
+ * @returns Number of opportunities updated to expired
1029
+ */
1030
+ expireOpportunitiesForRemovedMember(indexId: string, userId: string): Promise<number>;
1031
+ /**
1032
+ * Expire opportunities whose expires_at <= now. Used by maintenance cron.
1033
+ *
1034
+ * @returns Number of opportunities updated to expired
1035
+ */
1036
+ expireStaleOpportunities(): Promise<number>;
1037
+ /**
1038
+ * Get accepted opportunities between two actors (same actor pair, status accepted).
1039
+ * Used when building accepted-opportunities meta after accept (e.g. for chat channel).
1040
+ *
1041
+ * @param userId - First actor user ID
1042
+ * @param counterpartUserId - Second actor user ID
1043
+ * @returns Accepted opportunities between these two users, newest first
1044
+ */
1045
+ getAcceptedOpportunitiesBetweenActors(userId: string, counterpartUserId: string): Promise<Opportunity[]>;
1046
+ /**
1047
+ * Accept all sibling opportunities between the same actor pair in one transaction.
1048
+ * Selects opportunities where both userId and counterpartUserId are actors and status
1049
+ * is not accepted/expired/rejected, excludes excludeOpportunityId, then bulk-updates status to accepted.
1050
+ * Rolls back on any failure.
1051
+ *
1052
+ * @param userId - First actor user ID
1053
+ * @param counterpartUserId - Second actor user ID
1054
+ * @param excludeOpportunityId - Opportunity ID to exclude (the one already being accepted)
1055
+ * @returns IDs of opportunities that were updated to accepted
1056
+ */
1057
+ acceptSiblingOpportunities(userId: string, counterpartUserId: string, excludeOpportunityId: string): Promise<string[]>;
1058
+ /** Create a ghost user (unregistered contact) with empty profile. */
1059
+ createGhostUser(data: {
1060
+ name: string;
1061
+ email: string;
1062
+ }): Promise<{
1063
+ id: string;
1064
+ }>;
1065
+ /** Upsert a contact membership in the owner's personal index (index_members with permissions=['contact']). */
1066
+ upsertContactMembership(ownerId: string, contactUserId: string, options?: {
1067
+ restore?: boolean;
1068
+ }): Promise<void>;
1069
+ /** Hard-delete a contact membership from the owner's personal index. */
1070
+ hardDeleteContactMembership(ownerId: string, contactUserId: string): Promise<void>;
1071
+ /** Get all contact members from the owner's personal index with user details. */
1072
+ getContactMembers(ownerId: string): Promise<Array<{
1073
+ userId: string;
1074
+ user: {
1075
+ id: string;
1076
+ name: string;
1077
+ email: string;
1078
+ avatar: string | null;
1079
+ isGhost: boolean;
1080
+ };
1081
+ }>>;
1082
+ /** Clear a reverse opt-out (reactivate soft-deleted contact membership in another user's personal index). */
1083
+ clearReverseOptOut(ownerId: string, otherUserId: string): Promise<void>;
1084
+ /**
1085
+ * Returns the IDs of personal indexes where the given user is a contact member.
1086
+ * Used for auto-assigning new intents to personal indexes of contacts who imported this user.
1087
+ *
1088
+ * @param userId - The user whose contact memberships to look up
1089
+ * @returns Array of personal index IDs
1090
+ */
1091
+ getPersonalIndexesForContact(userId: string): Promise<{
1092
+ indexId: string;
1093
+ }[]>;
1094
+ /** Find a user by email. */
1095
+ getUserByEmail(email: string): Promise<{
1096
+ id: string;
1097
+ name: string;
1098
+ email: string;
1099
+ isGhost: boolean;
1100
+ } | null>;
1101
+ }
1102
+ /**
1103
+ * Context-bound database for accessing the authenticated user's own resources.
1104
+ * Created with authUserId bound at construction; no userId parameter needed on methods.
1105
+ *
1106
+ * **NOT index-scoped**: Returns ALL of the user's own resources regardless of index.
1107
+ * This is critical for the IntentReconciler which needs the full picture for deduplication.
1108
+ *
1109
+ * Use via `createUserDatabase(db, authUserId)` factory function.
1110
+ */
1111
+ export interface UserDatabase {
1112
+ /** The bound authenticated user ID */
1113
+ readonly authUserId: string;
1114
+ /** Get the authenticated user's profile. */
1115
+ getProfile(): Promise<ProfileDocument | null>;
1116
+ /** Get the authenticated user's profile with row ID. */
1117
+ getProfileByUserId(): Promise<(ProfileDocument & {
1118
+ id: string;
1119
+ }) | null>;
1120
+ /** Save/update the authenticated user's profile. */
1121
+ saveProfile(profile: ProfileDocument): Promise<void>;
1122
+ /** Delete the authenticated user's profile. */
1123
+ deleteProfile(): Promise<void>;
1124
+ /** Get the authenticated user's basic record (name, email, socials). */
1125
+ getUser(): Promise<UserRecord | null>;
1126
+ /** Update the authenticated user's account fields. */
1127
+ updateUser(data: {
1128
+ name?: string;
1129
+ intro?: string;
1130
+ location?: string;
1131
+ socials?: UserSocials;
1132
+ onboarding?: OnboardingState;
1133
+ }): Promise<UserRecord | null>;
1134
+ /** Get ALL active intents for the authenticated user (not index-filtered). */
1135
+ getActiveIntents(): Promise<ActiveIntent[]>;
1136
+ /** Get a single intent by ID (ownership enforced). */
1137
+ getIntent(intentId: string): Promise<IntentRecord | null>;
1138
+ /** Create a new intent for the authenticated user. */
1139
+ createIntent(data: Omit<CreateIntentData, 'userId'>): Promise<CreatedIntent>;
1140
+ /** Update an intent owned by the authenticated user. */
1141
+ updateIntent(intentId: string, data: UpdateIntentData): Promise<CreatedIntent | null>;
1142
+ /** Archive an intent owned by the authenticated user. */
1143
+ archiveIntent(intentId: string): Promise<ArchiveResult>;
1144
+ /** Find similar intents among the user's own intents (for deduplication). */
1145
+ findSimilarIntents(embedding: number[], options?: SimilarIntentSearchOptions): Promise<SimilarIntent[]>;
1146
+ /** Get intent fields for indexing (own intent). */
1147
+ getIntentForIndexing(intentId: string): Promise<{
1148
+ id: string;
1149
+ payload: string;
1150
+ userId: string;
1151
+ sourceType: string | null;
1152
+ sourceId: string | null;
1153
+ } | null>;
1154
+ /** Associate an intent with indexes. */
1155
+ associateIntentWithIndexes(intentId: string, indexIds: string[]): Promise<void>;
1156
+ /** Assign an intent to an index. */
1157
+ assignIntentToIndex(intentId: string, indexId: string, relevancyScore?: number): Promise<void>;
1158
+ /** Unassign an intent from an index. */
1159
+ unassignIntentFromIndex(intentId: string, indexId: string): Promise<void>;
1160
+ /** Get index IDs for an intent. */
1161
+ getIndexIdsForIntent(intentId: string): Promise<string[]>;
1162
+ /** Check if intent is assigned to index. */
1163
+ isIntentAssignedToIndex(intentId: string, indexId: string): Promise<boolean>;
1164
+ /** Get all index memberships for the authenticated user. */
1165
+ getIndexMemberships(): Promise<IndexMembership[]>;
1166
+ /** Get index IDs with auto-assign enabled for the authenticated user. */
1167
+ getUserIndexIds(): Promise<string[]>;
1168
+ /** Get indexes owned by the authenticated user. */
1169
+ getOwnedIndexes(): Promise<OwnedIndex[]>;
1170
+ /** Get a specific index membership for the authenticated user. */
1171
+ getIndexMembership(indexId: string): Promise<IndexMembership | null>;
1172
+ /** Get index + member context for the authenticated user (for auto-assign). */
1173
+ getIndexMemberContext(indexId: string): Promise<{
1174
+ indexId: string;
1175
+ indexPrompt: string | null;
1176
+ memberPrompt: string | null;
1177
+ } | null>;
1178
+ /** Create a new index (user becomes owner). */
1179
+ createIndex(data: {
1180
+ title: string;
1181
+ prompt?: string | null;
1182
+ imageUrl?: string | null;
1183
+ joinPolicy?: 'anyone' | 'invite_only';
1184
+ }): Promise<{
1185
+ id: string;
1186
+ title: string;
1187
+ prompt: string | null;
1188
+ imageUrl: string | null;
1189
+ permissions: {
1190
+ joinPolicy: 'anyone' | 'invite_only';
1191
+ invitationLink: {
1192
+ code: string;
1193
+ } | null;
1194
+ allowGuestVibeCheck: boolean;
1195
+ };
1196
+ }>;
1197
+ /** Update index settings (owner only). */
1198
+ updateIndexSettings(indexId: string, data: UpdateIndexSettingsData): Promise<OwnedIndex>;
1199
+ /** Soft-delete an index (owner only). */
1200
+ softDeleteIndex(indexId: string): Promise<void>;
1201
+ /** Get public indexes (joinPolicy 'anyone') that the user has not joined. */
1202
+ getPublicIndexesNotJoined(): Promise<{
1203
+ indexes: Array<{
1204
+ id: string;
1205
+ title: string;
1206
+ prompt: string | null;
1207
+ memberCount: number;
1208
+ owner: {
1209
+ id: string;
1210
+ name: string;
1211
+ avatar: string | null;
1212
+ } | null;
1213
+ }>;
1214
+ }>;
1215
+ /** Join a public index (validates joinPolicy === 'anyone'). */
1216
+ joinPublicIndex(indexId: string): Promise<{
1217
+ success: boolean;
1218
+ alreadyMember?: boolean;
1219
+ }>;
1220
+ /** Get opportunities where the authenticated user is an actor. */
1221
+ getOpportunitiesForUser(options?: OpportunityQueryOptions): Promise<Opportunity[]>;
1222
+ /** Get a specific opportunity (if user is an actor). */
1223
+ getOpportunity(id: string): Promise<Opportunity | null>;
1224
+ /** Update an opportunity's status (if user is an actor). */
1225
+ updateOpportunityStatus(id: string, status: OpportunityStatus): Promise<Opportunity | null>;
1226
+ /** Get accepted opportunities between the authenticated user and another actor. */
1227
+ getAcceptedOpportunitiesBetweenActors(counterpartUserId: string): Promise<Opportunity[]>;
1228
+ /** Accept sibling opportunities between the authenticated user and another actor. */
1229
+ acceptSiblingOpportunities(counterpartUserId: string, excludeOpportunityId: string): Promise<string[]>;
1230
+ /** Get a HyDE document for the user's own source. */
1231
+ getHydeDocument(sourceType: HydeSourceType, sourceId: string, strategy: string): Promise<HydeDocument | null>;
1232
+ /** Get all HyDE documents for the user's own source. */
1233
+ getHydeDocumentsForSource(sourceType: HydeSourceType, sourceId: string): Promise<HydeDocument[]>;
1234
+ /** Save a HyDE document for the user's own source. */
1235
+ saveHydeDocument(data: CreateHydeDocumentData): Promise<HydeDocument>;
1236
+ /** Delete HyDE documents for the user's own source. */
1237
+ deleteHydeDocumentsForSource(sourceType: HydeSourceType, sourceId: string): Promise<number>;
1238
+ }
1239
+ /**
1240
+ * Context-bound database for LLM/system operations that access cross-user resources.
1241
+ * Created with authUserId + indexScope[]; validates membership before access.
1242
+ *
1243
+ * **Index-scoped**: All cross-user operations are restricted to users/resources
1244
+ * within the bound indexScope[]. This prevents the LLM from accessing arbitrary users' data.
1245
+ *
1246
+ * Use via `createSystemDatabase(db, authUserId, indexScope)` factory function.
1247
+ */
1248
+ export interface SystemDatabase {
1249
+ /** The bound authenticated user ID */
1250
+ readonly authUserId: string;
1251
+ /** The indexes the authenticated user has access to (determines cross-user scope) */
1252
+ readonly indexScope: string[];
1253
+ /** Get a user's profile (requires shared index membership). */
1254
+ getProfile(userId: string): Promise<ProfileDocument | null>;
1255
+ /** Get a user's basic record (requires shared index membership). */
1256
+ getUser(userId: string): Promise<UserRecord | null>;
1257
+ /** Get all intents in an index (cross-user, requires membership). */
1258
+ getIntentsInIndex(indexId: string, options?: {
1259
+ limit?: number;
1260
+ offset?: number;
1261
+ }): Promise<IndexedIntentDetails[]>;
1262
+ /** Get a specific user's intents in an index (requires shared membership). */
1263
+ getUserIntentsInIndex(userId: string, indexId: string): Promise<ActiveIntent[]>;
1264
+ /** Get a single intent by ID (if in scope). */
1265
+ getIntent(intentId: string): Promise<IntentRecord | null>;
1266
+ /** Find similar intents across users within the index scope. */
1267
+ findSimilarIntentsInScope(embedding: number[], options?: SimilarIntentSearchOptions): Promise<SimilarIntent[]>;
1268
+ /** Check if a user is a member of an index. */
1269
+ isIndexMember(indexId: string, userId: string): Promise<boolean>;
1270
+ /** Check if a user is an owner of an index. */
1271
+ isIndexOwner(indexId: string, userId: string): Promise<boolean>;
1272
+ /** Get all members of an index (requires membership). */
1273
+ getIndexMembers(indexId: string): Promise<IndexMemberDetails[]>;
1274
+ /** Get all members across all indexes in scope (deduplicated). */
1275
+ getMembersFromScope(): Promise<{
1276
+ userId: Id<'users'>;
1277
+ name: string;
1278
+ avatar: string | null;
1279
+ }[]>;
1280
+ /** Add a user to an index (requires ownership or 'anyone' policy). */
1281
+ addMemberToIndex(indexId: string, userId: string, role: 'owner' | 'admin' | 'member'): Promise<{
1282
+ success: boolean;
1283
+ alreadyMember?: boolean;
1284
+ }>;
1285
+ /** Remove a user from an index (requires ownership). Cannot remove the owner. */
1286
+ removeMemberFromIndex(indexId: string, userId: string): Promise<{
1287
+ success: boolean;
1288
+ wasOwner?: boolean;
1289
+ notMember?: boolean;
1290
+ }>;
1291
+ /** Get index info by ID (requires scope). */
1292
+ getIndex(indexId: string): Promise<{
1293
+ id: string;
1294
+ title: string;
1295
+ } | null>;
1296
+ /** Get index with permissions (requires scope). */
1297
+ getIndexWithPermissions(indexId: string): Promise<{
1298
+ id: string;
1299
+ title: string;
1300
+ permissions: {
1301
+ joinPolicy: 'anyone' | 'invite_only';
1302
+ };
1303
+ } | null>;
1304
+ /** Get member count for an index (requires scope). */
1305
+ getIndexMemberCount(indexId: string): Promise<number>;
1306
+ /** Create an opportunity (cross-user). */
1307
+ createOpportunity(data: CreateOpportunityData): Promise<Opportunity>;
1308
+ /** Create opportunity and expire overlapping ones atomically. */
1309
+ createOpportunityAndExpireIds(data: CreateOpportunityData, expireIds: string[]): Promise<{
1310
+ created: Opportunity;
1311
+ expired: Opportunity[];
1312
+ }>;
1313
+ /** Get an opportunity by ID (for system processing). */
1314
+ getOpportunity(id: string): Promise<Opportunity | null>;
1315
+ /** Get opportunities for an index (requires membership). */
1316
+ getOpportunitiesForIndex(indexId: string, options?: OpportunityQueryOptions): Promise<Opportunity[]>;
1317
+ /** Update an opportunity's status (system-level). */
1318
+ updateOpportunityStatus(id: string, status: OpportunityStatus): Promise<Opportunity | null>;
1319
+ /** Check if opportunity exists between actors in an index. */
1320
+ opportunityExistsBetweenActors(actorIds: string[], indexId: string): Promise<boolean>;
1321
+ /** Return one opportunity between actors in the index (id + status), or null. */
1322
+ getOpportunityBetweenActors(actorIds: string[], indexId: string): Promise<{
1323
+ id: Id<'opportunities'>;
1324
+ status: OpportunityStatus;
1325
+ } | null>;
1326
+ /** Find overlapping opportunities by actor set. */
1327
+ findOverlappingOpportunities(actorUserIds: Id<'users'>[], options?: {
1328
+ excludeStatuses?: OpportunityStatus[];
1329
+ }): Promise<Opportunity[]>;
1330
+ /** Expire opportunities referencing an intent. */
1331
+ expireOpportunitiesByIntent(intentId: string): Promise<number>;
1332
+ /** Expire opportunities for a removed member. */
1333
+ expireOpportunitiesForRemovedMember(indexId: string, userId: string): Promise<number>;
1334
+ /** Expire stale opportunities (maintenance). */
1335
+ expireStaleOpportunities(): Promise<number>;
1336
+ /** Get a HyDE document (cross-user for matching). */
1337
+ getHydeDocument(sourceType: HydeSourceType, sourceId: string, strategy: string): Promise<HydeDocument | null>;
1338
+ /** Get all HyDE documents for a source (cross-user). */
1339
+ getHydeDocumentsForSource(sourceType: HydeSourceType, sourceId: string): Promise<HydeDocument[]>;
1340
+ /** Save a HyDE document (system-level). */
1341
+ saveHydeDocument(data: CreateHydeDocumentData): Promise<HydeDocument>;
1342
+ /** Delete expired HyDE documents (maintenance). */
1343
+ deleteExpiredHydeDocuments(): Promise<number>;
1344
+ /** Get stale HyDE documents for refresh (maintenance). */
1345
+ getStaleHydeDocuments(threshold: Date): Promise<HydeDocument[]>;
1346
+ }
1347
+ /**
1348
+ * Database interface narrowed for Profile Graph operations.
1349
+ * Provides full profile lifecycle: read, write, HyDE management, and query mode.
1350
+ *
1351
+ * Access layer: Primarily UserDatabase (user's own profile)
1352
+ */
1353
+ export type ProfileGraphDatabase = Pick<Database, 'getProfile' | 'getUser' | 'updateUser' | 'saveProfile' | 'getProfileByUserId' | 'getHydeDocument' | 'saveHydeDocument' | 'softDeleteGhost'>;
1354
+ /**
1355
+ * Composite database interface for Chat Graph.
1356
+ * Includes direct ChatGraph operations plus all methods needed by
1357
+ * internally composed subgraphs (ProfileGraph, OpportunityGraph, IntentGraph, IndexGraph).
1358
+ *
1359
+ * Use this type when ChatGraph orchestrates subgraphs internally.
1360
+ *
1361
+ * Access layer: Both UserDatabase + SystemDatabase (orchestrates all operations)
1362
+ */
1363
+ export type ChatGraphCompositeDatabase = Pick<Database, 'getProfile' | 'getActiveIntents' | 'getIntentsInIndexForMember' | 'getUser' | 'updateUser' | 'saveProfile' | 'softDeleteGhost' | 'createIntent' | 'updateIntent' | 'archiveIntent' | 'createOpportunity' | 'getOpportunity' | 'opportunityExistsBetweenActors' | 'getOpportunityBetweenActors' | 'findOverlappingOpportunities' | 'getOpportunitiesForUser' | 'updateOpportunityStatus' | 'getHydeDocument' | 'getHydeDocumentsForSource' | 'saveHydeDocument' | 'getIntent' | 'getPublicIndexesNotJoined' | 'getUserIndexIds' | 'getIndexMemberships' | 'getIndexMembership' | 'getIndex' | 'getIndexWithPermissions' | 'getIntentForIndexing' | 'getIndexMemberContext' | 'isIntentAssignedToIndex' | 'assignIntentToIndex' | 'unassignIntentFromIndex' | 'getIndexIdsForIntent' | 'getIntentIndexScores' | 'getPersonalIndexesForContact' | 'getOwnedIndexes' | 'isIndexOwner' | 'isIndexMember' | 'getIndexMembersForOwner' | 'getIndexMembersForMember' | 'getMembersFromUserIndexes' | 'getIndexIntentsForOwner' | 'getIndexIntentsForMember' | 'updateIndexSettings' | 'softDeleteIndex' | 'deleteProfile' | 'getProfileByUserId' | 'createIndex' | 'getIndexMemberCount' | 'addMemberToIndex' | 'removeMemberFromIndex'>;
1364
+ /**
1365
+ * Database interface for Opportunity Graph operations.
1366
+ * Includes prep/scope (index membership, intents, index details), persist (create, dedupe),
1367
+ * and CRUD operations (read, update status, send).
1368
+ *
1369
+ * Access layer: SystemDatabase (cross-user opportunity operations)
1370
+ */
1371
+ export type OpportunityGraphDatabase = Pick<Database, 'getProfile' | 'createOpportunity' | 'opportunityExistsBetweenActors' | 'getOpportunityBetweenActors' | 'findOverlappingOpportunities' | 'getUserIndexIds' | 'getIndexMemberships' | 'getActiveIntents' | 'getIndexIdsForIntent' | 'getIndex' | 'getIndexMemberCount' | 'getIntentIndexScores' | 'getIndexMemberContext' | 'getOpportunity' | 'getOpportunitiesForUser' | 'updateOpportunityStatus' | 'isIndexMember' | 'getUser' | 'getIntent'>;
1372
+ /**
1373
+ * Database interface for the negotiation graph (A2A conversation/task/artifact persistence).
1374
+ *
1375
+ * Access layer: ConversationDatabaseAdapter
1376
+ */
1377
+ export interface NegotiationDatabase {
1378
+ /**
1379
+ * Creates an A2A conversation between negotiation agents.
1380
+ * @param participants - Agent participant descriptors
1381
+ * @returns The created conversation with its id
1382
+ */
1383
+ createConversation(participants: {
1384
+ participantId: string;
1385
+ participantType: 'user' | 'agent';
1386
+ }[]): Promise<{
1387
+ id: string;
1388
+ }>;
1389
+ /**
1390
+ * Persists a negotiation turn message within a conversation.
1391
+ * @param data - Message payload including conversation, sender, role, and structured parts
1392
+ * @returns The persisted message record
1393
+ */
1394
+ createMessage(data: {
1395
+ conversationId: string;
1396
+ senderId: string;
1397
+ role: 'user' | 'agent';
1398
+ parts: unknown[];
1399
+ taskId?: string;
1400
+ metadata?: Record<string, unknown> | null;
1401
+ }): Promise<{
1402
+ id: string;
1403
+ senderId: string;
1404
+ role: 'user' | 'agent';
1405
+ parts: unknown;
1406
+ createdAt: Date;
1407
+ }>;
1408
+ /**
1409
+ * Creates a task to track the negotiation lifecycle within a conversation.
1410
+ * @param conversationId - Parent conversation id
1411
+ * @param metadata - Task metadata (type, sourceUserId, candidateUserId)
1412
+ * @returns The created task with id, conversationId, and initial state
1413
+ */
1414
+ createTask(conversationId: string, metadata?: Record<string, unknown>): Promise<{
1415
+ id: string;
1416
+ conversationId: string;
1417
+ state: string;
1418
+ }>;
1419
+ /**
1420
+ * Transitions a task to a new state (e.g. working, completed, failed).
1421
+ * @param taskId - Task to update
1422
+ * @param state - Target state
1423
+ * @param statusMessage - Optional status message or structured status
1424
+ * @returns The updated task record
1425
+ */
1426
+ updateTaskState(taskId: string, state: string, statusMessage?: unknown): Promise<{
1427
+ id: string;
1428
+ conversationId: string;
1429
+ state: string;
1430
+ }>;
1431
+ /**
1432
+ * Persists a negotiation outcome artifact attached to a task.
1433
+ * @param data - Artifact payload including task reference, name, structured parts, and metadata
1434
+ * @returns The created artifact with its id
1435
+ */
1436
+ createArtifact(data: {
1437
+ taskId: string;
1438
+ name?: string;
1439
+ parts: unknown[];
1440
+ metadata?: Record<string, unknown> | null;
1441
+ }): Promise<{
1442
+ id: string;
1443
+ }>;
1444
+ }
1445
+ /**
1446
+ * Database interface for opportunity controller (API).
1447
+ *
1448
+ * Access layer: Both UserDatabase + SystemDatabase (API handles auth)
1449
+ */
1450
+ export type OpportunityControllerDatabase = Pick<Database, 'getOpportunity' | 'getOpportunitiesForUser' | 'getOpportunitiesForIndex' | 'resolveOpportunityId' | 'updateOpportunityStatus' | 'createOpportunity' | 'createOpportunityAndExpireIds' | 'opportunityExistsBetweenActors' | 'findOverlappingOpportunities' | 'getAcceptedOpportunitiesBetweenActors' | 'acceptSiblingOpportunities' | 'isIndexOwner' | 'isIndexMember' | 'getUser' | 'getIndex' | 'getIndexMemberships' | 'getProfile' | 'getActiveIntents' | 'upsertContactMembership'>;
1451
+ /**
1452
+ * Database interface narrowed for Intent Graph operations.
1453
+ * Provides state population (getActiveIntents), action execution (create/update/archive),
1454
+ * and read operations (query intents; getIntentsInIndexForMember for index-scoped reads).
1455
+ *
1456
+ * Access layer: UserDatabase (mutations on own intents) + SystemDatabase (index-scoped reads)
1457
+ */
1458
+ export type IntentGraphDatabase = Pick<Database, 'getActiveIntents' | 'getIntentsInIndexForMember' | 'createIntent' | 'updateIntent' | 'archiveIntent' | 'isIndexMember' | 'getIndexIntentsForMember' | 'getUser' | 'getProfile' | 'getPersonalIndexesForContact' | 'assignIntentToIndex'>;
1459
+ /**
1460
+ * Database interface narrowed for Index Graph CRUD operations.
1461
+ * Handles create, read, update, delete of indexes (communities).
1462
+ *
1463
+ * Access layer: UserDatabase (CRUD on own indexes and memberships)
1464
+ */
1465
+ export type IndexGraphDatabase = Pick<Database, 'getIndexMemberships' | 'getOwnedIndexes' | 'getPublicIndexesNotJoined' | 'isIndexOwner' | 'isIndexMember' | 'getIndex' | 'createIndex' | 'addMemberToIndex' | 'updateIndexSettings' | 'softDeleteIndex' | 'getIndexMemberCount'>;
1466
+ /**
1467
+ * Database interface narrowed for Intent Index Graph operations.
1468
+ * Provides intent/index context and assignment for intent–index evaluation.
1469
+ * (Migrated from the old IndexGraphDatabase.)
1470
+ *
1471
+ * Access layer: UserDatabase (own intent assignment) + SystemDatabase (index context)
1472
+ */
1473
+ export type IntentIndexGraphDatabase = Pick<Database, 'getIntentForIndexing' | 'getIndexMemberContext' | 'isIntentAssignedToIndex' | 'assignIntentToIndex' | 'unassignIntentFromIndex' | 'getIntent' | 'isIndexMember' | 'getIndexIdsForIntent' | 'getIndexIntentsForMember' | 'getIntentsInIndexForMember'>;
1474
+ /**
1475
+ * Database interface narrowed for Index Membership Graph operations.
1476
+ * Handles CRUD for index memberships (add, list, remove members).
1477
+ *
1478
+ * Access layer: SystemDatabase (cross-user membership operations)
1479
+ */
1480
+ export type IndexMembershipGraphDatabase = Pick<Database, 'isIndexMember' | 'isIndexOwner' | 'getIndexWithPermissions' | 'addMemberToIndex' | 'removeMemberFromIndex' | 'getIndexMembersForMember'>;
1481
+ /**
1482
+ * Database interface narrowed for HyDE Graph operations.
1483
+ * Provides HyDE document CRUD and intent lookup for refresh.
1484
+ *
1485
+ * Access layer: UserDatabase (own HyDE) + SystemDatabase (cross-user matching)
1486
+ */
1487
+ export type HydeGraphDatabase = Pick<Database, 'getHydeDocument' | 'getHydeDocumentsForSource' | 'saveHydeDocument' | 'getIntent'>;
1488
+ /**
1489
+ * Database interface for Home Graph (opportunity home view).
1490
+ * Load opportunities, enrich with profile/index, and support presenter context.
1491
+ *
1492
+ * Access layer: UserDatabase (own opportunities and profile)
1493
+ */
1494
+ export type HomeGraphDatabase = Pick<Database, 'getOpportunitiesForUser' | 'getOpportunity' | 'getProfile' | 'getActiveIntents' | 'getIndex' | 'getUser'>;
1495
+ //# sourceMappingURL=database.interface.d.ts.map