@indexnetwork/protocol 22.0.0-rc.499.1 → 64.0.0-rc.604.2

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 (561) hide show
  1. package/CHANGELOG.md +1841 -0
  2. package/IMPLEMENTATION.md +140 -181
  3. package/README.md +16 -20
  4. package/STABILITY.md +16 -11
  5. package/dist/{intents/intent.module.d.ts → capabilities/intents.d.ts} +182 -192
  6. package/dist/capabilities/intents.js +88 -0
  7. package/dist/capabilities/negotiations.d.ts +17 -0
  8. package/dist/capabilities/negotiations.js +16 -0
  9. package/dist/{networks/network.module.d.ts → capabilities/networks.d.ts} +33 -169
  10. package/dist/{networks/network.module.js → capabilities/networks.js} +6 -17
  11. package/dist/index.d.ts +57 -134
  12. package/dist/index.js +41 -105
  13. package/dist/internal/agents/agent.repository.port.d.ts +59 -0
  14. package/dist/internal/agents/agent.repository.port.js +7 -0
  15. package/dist/internal/agents/agent.types.d.ts +35 -0
  16. package/dist/{agents → internal/agents}/agent.types.js +1 -6
  17. package/dist/{intents → internal/intents}/graph/intent.graph.d.ts +142 -151
  18. package/dist/{intents → internal/intents}/graph/intent.graph.execute.d.ts +5 -1
  19. package/dist/{intents → internal/intents}/graph/intent.graph.execute.js +165 -46
  20. package/dist/internal/intents/graph/intent.graph.infer.d.ts +78 -0
  21. package/dist/internal/intents/graph/intent.graph.infer.js +122 -0
  22. package/dist/internal/intents/graph/intent.graph.js +108 -0
  23. package/dist/{intents → internal/intents}/graph/intent.graph.reconcile.d.ts +18 -9
  24. package/dist/internal/intents/graph/intent.graph.reconcile.js +173 -0
  25. package/dist/internal/intents/graph/intent.graph.shared.d.ts +55 -0
  26. package/dist/{intents → internal/intents}/graph/intent.graph.shared.js +25 -70
  27. package/dist/{intents → internal/intents}/graph/intent.graph.state.d.ts +96 -32
  28. package/dist/{intents → internal/intents}/graph/intent.graph.state.js +42 -31
  29. package/dist/internal/intents/intent.admission.d.ts +16 -0
  30. package/dist/internal/intents/intent.admission.js +30 -0
  31. package/dist/{intents → internal/intents}/intent.inferrer.d.ts +1 -40
  32. package/dist/{intents → internal/intents}/intent.inferrer.js +13 -49
  33. package/dist/internal/intents/intent.preparer.d.ts +52 -0
  34. package/dist/internal/intents/intent.preparer.js +87 -0
  35. package/dist/{intents → internal/intents}/intent.verifier.d.ts +3 -36
  36. package/dist/{intents → internal/intents}/intent.verifier.js +0 -17
  37. package/dist/{networks → internal/networks}/indexer.graph.d.ts +15 -200
  38. package/dist/{networks → internal/networks}/indexer.graph.js +19 -128
  39. package/dist/{networks → internal/networks}/indexer.state.d.ts +8 -63
  40. package/dist/internal/networks/indexer.state.js +70 -0
  41. package/dist/{networks → internal/networks}/membership.graph.d.ts +6 -6
  42. package/dist/{networks → internal/networks}/membership.graph.js +3 -3
  43. package/dist/{networks → internal/networks}/membership.state.d.ts +2 -2
  44. package/dist/{networks → internal/networks}/membership.state.js +2 -2
  45. package/dist/{networks → internal/networks}/network.graph.d.ts +9 -22
  46. package/dist/{networks → internal/networks}/network.graph.js +13 -27
  47. package/dist/{networks → internal/networks}/network.recommender.d.ts +2 -2
  48. package/dist/{networks → internal/networks}/network.recommender.js +2 -2
  49. package/dist/{networks → internal/networks}/network.state.d.ts +4 -7
  50. package/dist/{networks → internal/networks}/network.state.js +4 -4
  51. package/dist/internal/opportunities/negotiation-context.loader.d.ts +26 -0
  52. package/dist/internal/opportunities/negotiation-context.loader.js +36 -0
  53. package/dist/{opportunities → internal/opportunities}/opportunity.actor.d.ts +1 -1
  54. package/dist/{opportunities → internal/opportunities}/opportunity.actor.js +7 -1
  55. package/dist/internal/opportunities/opportunity.counterparties.d.ts +17 -0
  56. package/dist/internal/opportunities/opportunity.counterparties.js +19 -0
  57. package/dist/internal/opportunities/opportunity.events.d.ts +38 -0
  58. package/dist/internal/opportunities/opportunity.events.js +94 -0
  59. package/dist/{opportunities → internal/opportunities}/opportunity.feed-selection.d.ts +3 -9
  60. package/dist/internal/opportunities/opportunity.feed-selection.js +40 -0
  61. package/dist/internal/opportunities/opportunity.graph.modes.d.ts +39 -0
  62. package/dist/internal/opportunities/opportunity.graph.modes.js +138 -0
  63. package/dist/{opportunities → internal/opportunities}/opportunity.labels.d.ts +2 -3
  64. package/dist/internal/opportunities/opportunity.labels.js +9 -0
  65. package/dist/{opportunities → internal/opportunities}/opportunity.presentation.d.ts +17 -86
  66. package/dist/{opportunities → internal/opportunities}/opportunity.presentation.js +54 -447
  67. package/dist/{opportunities → internal/opportunities}/opportunity.update-admission.d.ts +2 -2
  68. package/dist/internal/opportunities/opportunity.utils.d.ts +105 -0
  69. package/dist/internal/opportunities/opportunity.utils.js +165 -0
  70. package/dist/{opportunities → internal/opportunities}/radar/radar.graph.d.ts +17 -17
  71. package/dist/{opportunities → internal/opportunities}/radar/radar.graph.js +41 -161
  72. package/dist/{opportunities → internal/opportunities}/radar/radar.state.d.ts +4 -11
  73. package/dist/{shared → internal/shared}/agent/model-signal.d.ts +1 -1
  74. package/dist/{shared → internal/shared}/agent/model-signal.js +1 -1
  75. package/dist/{shared → internal/shared}/agent/model.config.d.ts +28 -86
  76. package/dist/{shared → internal/shared}/agent/model.config.js +58 -69
  77. package/dist/internal/shared/agent/model.resolver.d.ts +33 -0
  78. package/dist/{shared → internal/shared}/agent/model.resolver.js +18 -33
  79. package/dist/internal/shared/agent/scope.d.ts +20 -0
  80. package/dist/internal/shared/agent/scope.js +24 -0
  81. package/dist/internal/shared/assignment/network-assignment.policy.d.ts +23 -0
  82. package/dist/internal/shared/assignment/network-assignment.policy.js +28 -0
  83. package/dist/{shared → internal/shared}/observability/log.d.ts +3 -6
  84. package/dist/{shared → internal/shared}/observability/log.js +9 -18
  85. package/dist/{shared → internal/shared}/observability/protocol.logger.d.ts +1 -1
  86. package/dist/{shared → internal/shared}/observability/protocol.logger.js +1 -1
  87. package/dist/internal/shared/observability/request-context.d.ts +29 -0
  88. package/dist/internal/shared/observability/request-context.js +17 -0
  89. package/dist/{shared → internal/shared}/utils/social-label.d.ts +2 -2
  90. package/dist/{shared → internal/shared}/utils/social-label.js +1 -1
  91. package/dist/platform/database/capabilities.d.ts +59 -0
  92. package/dist/{shared/interfaces/database.entities.d.ts → platform/database/entities.d.ts} +81 -121
  93. package/dist/{shared/interfaces/database.identity-queries.d.ts → platform/database/identity-queries.d.ts} +55 -20
  94. package/dist/platform/database/member-queries.d.ts +55 -0
  95. package/dist/platform/database/member-queries.js +4 -0
  96. package/dist/platform/database/negotiation.d.ts +38 -0
  97. package/dist/{shared/interfaces/database.network-queries.d.ts → platform/database/network-queries.d.ts} +66 -67
  98. package/dist/platform/database/network-queries.js +4 -0
  99. package/dist/{shared/interfaces/database.opportunity-queries.d.ts → platform/database/opportunity-queries.d.ts} +25 -109
  100. package/dist/{shared/interfaces/database.port.d.ts → platform/database/port.d.ts} +52 -117
  101. package/dist/{shared/interfaces/database.port.js → platform/database/port.js} +3 -5
  102. package/dist/platform/database.d.ts +23 -0
  103. package/dist/{shared/interfaces/database.interface.js → platform/database.js} +1 -1
  104. package/dist/{shared/interfaces/cache.interface.d.ts → platform/discovery/cache.d.ts} +2 -4
  105. package/dist/{shared/interfaces/cache.interface.js → platform/discovery/cache.js} +1 -1
  106. package/dist/platform/discovery/embedder.d.ts +31 -0
  107. package/dist/platform/runtime/errors.d.ts +6 -0
  108. package/dist/platform/runtime/errors.js +9 -0
  109. package/dist/platform/runtime/follow-up.d.ts +36 -0
  110. package/dist/platform/runtime/follow-up.js +4 -0
  111. package/dist/platform/runtime/observability.d.ts +34 -0
  112. package/dist/protocol/core.d.ts +11 -0
  113. package/dist/protocol/discovery.rules.d.ts +21 -0
  114. package/dist/protocol/discovery.rules.js +29 -0
  115. package/dist/protocol/negotiation.constants.d.ts +3 -0
  116. package/dist/protocol/negotiation.constants.js +3 -0
  117. package/dist/protocol/negotiation.rules.d.ts +73 -0
  118. package/dist/protocol/negotiation.rules.js +68 -0
  119. package/dist/protocol/protocol.prompt.d.ts +13 -0
  120. package/dist/protocol/protocol.prompt.js +190 -0
  121. package/dist/{shared → protocol}/schemas/discovery-question.schema.d.ts +13 -13
  122. package/dist/{shared → protocol}/schemas/discovery-question.schema.js +2 -2
  123. package/dist/{shared → protocol}/schemas/identity.schema.d.ts +4 -4
  124. package/dist/{shared → protocol}/schemas/identity.schema.js +4 -4
  125. package/dist/{shared → protocol}/schemas/network-assignment.schema.d.ts +11 -20
  126. package/dist/{shared → protocol}/schemas/network-assignment.schema.js +2 -9
  127. package/dist/protocol/schemas/underspecification.schema.d.ts +9 -0
  128. package/dist/protocol/schemas/underspecification.schema.js +12 -0
  129. package/package.json +7 -15
  130. package/dist/agents/agent.dispatcher.port.d.ts +0 -25
  131. package/dist/agents/agent.module.d.ts +0 -19
  132. package/dist/agents/agent.module.js +0 -11
  133. package/dist/agents/agent.repository.port.d.ts +0 -118
  134. package/dist/agents/agent.repository.port.js +0 -10
  135. package/dist/agents/agent.tools.d.ts +0 -16
  136. package/dist/agents/agent.tools.js +0 -351
  137. package/dist/agents/agent.tools.port.d.ts +0 -22
  138. package/dist/agents/agent.tools.port.js +0 -18
  139. package/dist/agents/agent.types.d.ts +0 -76
  140. package/dist/chat/chat-streaming.types.d.ts +0 -618
  141. package/dist/chat/chat-streaming.types.js +0 -297
  142. package/dist/chat/chat.agent.d.ts +0 -292
  143. package/dist/chat/chat.agent.js +0 -1010
  144. package/dist/chat/chat.graph.d.ts +0 -424
  145. package/dist/chat/chat.graph.js +0 -257
  146. package/dist/chat/chat.interrupt.classifier.d.ts +0 -25
  147. package/dist/chat/chat.interrupt.classifier.js +0 -64
  148. package/dist/chat/chat.persona.d.ts +0 -39
  149. package/dist/chat/chat.prompt.d.ts +0 -4
  150. package/dist/chat/chat.prompt.js +0 -12
  151. package/dist/chat/chat.prompt.modules.d.ts +0 -30
  152. package/dist/chat/chat.prompt.modules.js +0 -40
  153. package/dist/chat/chat.question-dedup.d.ts +0 -14
  154. package/dist/chat/chat.question-dedup.js +0 -17
  155. package/dist/chat/chat.state.d.ts +0 -135
  156. package/dist/chat/chat.state.js +0 -120
  157. package/dist/chat/chat.streamer.d.ts +0 -64
  158. package/dist/chat/chat.streamer.js +0 -217
  159. package/dist/chat/chat.suggester.d.ts +0 -23
  160. package/dist/chat/chat.suggester.js +0 -95
  161. package/dist/chat/chat.summarizer.d.ts +0 -20
  162. package/dist/chat/chat.summarizer.js +0 -97
  163. package/dist/chat/chat.title.generator.d.ts +0 -19
  164. package/dist/chat/chat.title.generator.js +0 -66
  165. package/dist/chat/chat.tools.d.ts +0 -5
  166. package/dist/chat/chat.tools.js +0 -62
  167. package/dist/chat/chat.utils.d.ts +0 -41
  168. package/dist/chat/chat.utils.js +0 -88
  169. package/dist/chat/negotiator.persona.d.ts +0 -74
  170. package/dist/chat/negotiator.persona.js +0 -154
  171. package/dist/chat/negotiator.prompt.d.ts +0 -45
  172. package/dist/chat/negotiator.prompt.js +0 -160
  173. package/dist/chat/negotiator.tools.d.ts +0 -42
  174. package/dist/chat/negotiator.tools.js +0 -134
  175. package/dist/chat/onboarding.persona.d.ts +0 -28
  176. package/dist/chat/onboarding.persona.js +0 -86
  177. package/dist/chat/onboarding.prompt.d.ts +0 -6
  178. package/dist/chat/onboarding.prompt.js +0 -63
  179. package/dist/chat/signal.persona.d.ts +0 -47
  180. package/dist/chat/signal.persona.js +0 -319
  181. package/dist/chat/signal.prompt.d.ts +0 -39
  182. package/dist/chat/signal.prompt.js +0 -136
  183. package/dist/contacts/contact.module.d.ts +0 -8
  184. package/dist/contacts/contact.module.js +0 -6
  185. package/dist/contacts/contact.repository.port.d.ts +0 -21
  186. package/dist/contacts/contact.repository.port.js +0 -12
  187. package/dist/contacts/contact.tools.d.ts +0 -17
  188. package/dist/contacts/contact.tools.js +0 -108
  189. package/dist/contacts/contact.tools.port.d.ts +0 -20
  190. package/dist/contacts/contact.tools.port.js +0 -16
  191. package/dist/contacts/contact.types.d.ts +0 -24
  192. package/dist/contacts/contact.types.js +0 -8
  193. package/dist/contexts/context.generator.d.ts +0 -95
  194. package/dist/contexts/context.generator.js +0 -127
  195. package/dist/contexts/context.module.d.ts +0 -13
  196. package/dist/contexts/context.module.js +0 -12
  197. package/dist/contexts/context.tools.port.d.ts +0 -9
  198. package/dist/discovery/hyde.documents.d.ts +0 -9
  199. package/dist/discovery/hyde.documents.js +0 -49
  200. package/dist/discovery/hyde.env.d.ts +0 -8
  201. package/dist/discovery/hyde.env.js +0 -9
  202. package/dist/discovery/hyde.frame.d.ts +0 -150
  203. package/dist/discovery/hyde.frame.js +0 -107
  204. package/dist/discovery/hyde.generator.d.ts +0 -38
  205. package/dist/discovery/hyde.generator.js +0 -103
  206. package/dist/discovery/hyde.graph.d.ts +0 -209
  207. package/dist/discovery/hyde.graph.js +0 -482
  208. package/dist/discovery/hyde.state.d.ts +0 -70
  209. package/dist/discovery/hyde.state.js +0 -85
  210. package/dist/discovery/hyde.strategies.d.ts +0 -17
  211. package/dist/discovery/hyde.strategies.js +0 -34
  212. package/dist/discovery/hyde.validator.d.ts +0 -78
  213. package/dist/discovery/hyde.validator.js +0 -48
  214. package/dist/discovery/index.d.ts +0 -26
  215. package/dist/discovery/index.js +0 -19
  216. package/dist/discovery/lens.inferrer.d.ts +0 -214
  217. package/dist/discovery/lens.inferrer.js +0 -152
  218. package/dist/enrichment/enrichment.generator.d.ts +0 -68
  219. package/dist/enrichment/enrichment.generator.js +0 -95
  220. package/dist/enrichment/enrichment.graph.d.ts +0 -544
  221. package/dist/enrichment/enrichment.graph.js +0 -695
  222. package/dist/enrichment/enrichment.state.d.ts +0 -141
  223. package/dist/enrichment/enrichment.state.js +0 -115
  224. package/dist/enrichment/enrichment.tools.context-read.d.ts +0 -10
  225. package/dist/enrichment/enrichment.tools.context-read.js +0 -353
  226. package/dist/enrichment/enrichment.tools.context-write.d.ts +0 -9
  227. package/dist/enrichment/enrichment.tools.context-write.js +0 -417
  228. package/dist/enrichment/enrichment.tools.d.ts +0 -13
  229. package/dist/enrichment/enrichment.tools.helpers.d.ts +0 -139
  230. package/dist/enrichment/enrichment.tools.helpers.js +0 -234
  231. package/dist/enrichment/enrichment.tools.js +0 -153
  232. package/dist/intents/graph/intent.graph.infer.d.ts +0 -44
  233. package/dist/intents/graph/intent.graph.infer.js +0 -97
  234. package/dist/intents/graph/intent.graph.js +0 -134
  235. package/dist/intents/graph/intent.graph.reconcile.js +0 -274
  236. package/dist/intents/graph/intent.graph.shared.d.ts +0 -68
  237. package/dist/intents/intake/intake.orchestrator.d.ts +0 -203
  238. package/dist/intents/intake/intake.orchestrator.js +0 -255
  239. package/dist/intents/intake/intake.pack.generator.d.ts +0 -57
  240. package/dist/intents/intake/intake.pack.generator.js +0 -90
  241. package/dist/intents/intent.clarifier.d.ts +0 -51
  242. package/dist/intents/intent.clarifier.js +0 -201
  243. package/dist/intents/intent.indexer.d.ts +0 -82
  244. package/dist/intents/intent.indexer.js +0 -170
  245. package/dist/intents/intent.module.js +0 -103
  246. package/dist/intents/intent.proposal.d.ts +0 -37
  247. package/dist/intents/intent.proposal.js +0 -14
  248. package/dist/intents/intent.reconciler.d.ts +0 -105
  249. package/dist/intents/intent.reconciler.js +0 -186
  250. package/dist/intents/intent.tools.d.ts +0 -27
  251. package/dist/intents/intent.tools.js +0 -808
  252. package/dist/maintenance/maintenance.graph.d.ts +0 -239
  253. package/dist/maintenance/maintenance.graph.js +0 -199
  254. package/dist/maintenance/maintenance.state.d.ts +0 -35
  255. package/dist/maintenance/maintenance.state.js +0 -55
  256. package/dist/mcp/elicitation.builder.d.ts +0 -53
  257. package/dist/mcp/elicitation.builder.js +0 -74
  258. package/dist/mcp/elicitation.dispatcher.d.ts +0 -36
  259. package/dist/mcp/elicitation.dispatcher.js +0 -86
  260. package/dist/mcp/mcp.authorization-policy.d.ts +0 -252
  261. package/dist/mcp/mcp.authorization-policy.js +0 -535
  262. package/dist/mcp/mcp.server.d.ts +0 -90
  263. package/dist/mcp/mcp.server.js +0 -631
  264. package/dist/negotiations/insight.generator.d.ts +0 -31
  265. package/dist/negotiations/insight.generator.js +0 -105
  266. package/dist/negotiations/negotiation.agent.d.ts +0 -130
  267. package/dist/negotiations/negotiation.agent.js +0 -396
  268. package/dist/negotiations/negotiation.answer-consumption.d.ts +0 -223
  269. package/dist/negotiations/negotiation.answer-consumption.js +0 -275
  270. package/dist/negotiations/negotiation.attribution.d.ts +0 -91
  271. package/dist/negotiations/negotiation.attribution.js +0 -109
  272. package/dist/negotiations/negotiation.candidates.d.ts +0 -83
  273. package/dist/negotiations/negotiation.candidates.js +0 -162
  274. package/dist/negotiations/negotiation.client-dm.d.ts +0 -50
  275. package/dist/negotiations/negotiation.client-dm.js +0 -66
  276. package/dist/negotiations/negotiation.consultation-policy.d.ts +0 -95
  277. package/dist/negotiations/negotiation.consultation-policy.js +0 -159
  278. package/dist/negotiations/negotiation.deadlock.contracts.d.ts +0 -10
  279. package/dist/negotiations/negotiation.deadlock.d.ts +0 -87
  280. package/dist/negotiations/negotiation.deadlock.js +0 -150
  281. package/dist/negotiations/negotiation.detail-reader.d.ts +0 -94
  282. package/dist/negotiations/negotiation.detail-reader.js +0 -91
  283. package/dist/negotiations/negotiation.expected-speaker.d.ts +0 -33
  284. package/dist/negotiations/negotiation.expected-speaker.js +0 -59
  285. package/dist/negotiations/negotiation.graph.d.ts +0 -694
  286. package/dist/negotiations/negotiation.graph.finalize.d.ts +0 -5
  287. package/dist/negotiations/negotiation.graph.finalize.js +0 -403
  288. package/dist/negotiations/negotiation.graph.init.d.ts +0 -54
  289. package/dist/negotiations/negotiation.graph.init.js +0 -256
  290. package/dist/negotiations/negotiation.graph.js +0 -94
  291. package/dist/negotiations/negotiation.graph.screen.d.ts +0 -23
  292. package/dist/negotiations/negotiation.graph.screen.js +0 -108
  293. package/dist/negotiations/negotiation.graph.shared.d.ts +0 -111
  294. package/dist/negotiations/negotiation.graph.shared.js +0 -168
  295. package/dist/negotiations/negotiation.graph.turn.d.ts +0 -134
  296. package/dist/negotiations/negotiation.graph.turn.js +0 -662
  297. package/dist/negotiations/negotiation.hermes-contract.d.ts +0 -31
  298. package/dist/negotiations/negotiation.hermes-contract.js +0 -72
  299. package/dist/negotiations/negotiation.intent-snapshot-provenance.d.ts +0 -21
  300. package/dist/negotiations/negotiation.intent-snapshot-provenance.js +0 -28
  301. package/dist/negotiations/negotiation.lifecycle-narration.d.ts +0 -18
  302. package/dist/negotiations/negotiation.lifecycle-narration.js +0 -87
  303. package/dist/negotiations/negotiation.memory.d.ts +0 -65
  304. package/dist/negotiations/negotiation.memory.js +0 -83
  305. package/dist/negotiations/negotiation.module.d.ts +0 -36
  306. package/dist/negotiations/negotiation.module.js +0 -23
  307. package/dist/negotiations/negotiation.protocol.d.ts +0 -1018
  308. package/dist/negotiations/negotiation.protocol.js +0 -224
  309. package/dist/negotiations/negotiation.question-safety.d.ts +0 -52
  310. package/dist/negotiations/negotiation.question-safety.js +0 -119
  311. package/dist/negotiations/negotiation.reflect.d.ts +0 -194
  312. package/dist/negotiations/negotiation.reflect.js +0 -145
  313. package/dist/negotiations/negotiation.scope.d.ts +0 -41
  314. package/dist/negotiations/negotiation.scope.js +0 -39
  315. package/dist/negotiations/negotiation.screen.contracts.d.ts +0 -88
  316. package/dist/negotiations/negotiation.screen.contracts.js +0 -58
  317. package/dist/negotiations/negotiation.screen.d.ts +0 -78
  318. package/dist/negotiations/negotiation.screen.js +0 -112
  319. package/dist/negotiations/negotiation.stall-gap.d.ts +0 -83
  320. package/dist/negotiations/negotiation.stall-gap.js +0 -152
  321. package/dist/negotiations/negotiation.stance.contracts.d.ts +0 -123
  322. package/dist/negotiations/negotiation.stance.contracts.js +0 -317
  323. package/dist/negotiations/negotiation.state.d.ts +0 -597
  324. package/dist/negotiations/negotiation.state.js +0 -286
  325. package/dist/negotiations/negotiation.summarizer.d.ts +0 -25
  326. package/dist/negotiations/negotiation.summarizer.js +0 -101
  327. package/dist/negotiations/negotiation.task-lock-policy.d.ts +0 -10
  328. package/dist/negotiations/negotiation.task-lock-policy.js +0 -22
  329. package/dist/negotiations/negotiation.tools.d.ts +0 -18
  330. package/dist/negotiations/negotiation.tools.js +0 -842
  331. package/dist/negotiations/negotiation.tools.port.d.ts +0 -17
  332. package/dist/negotiations/negotiation.turn-cap.d.ts +0 -9
  333. package/dist/negotiations/negotiation.turn-cap.js +0 -12
  334. package/dist/networks/indexer.state.js +0 -112
  335. package/dist/networks/network.tools.d.ts +0 -36
  336. package/dist/networks/network.tools.js +0 -594
  337. package/dist/opportunities/delivery-card.cache.d.ts +0 -25
  338. package/dist/opportunities/delivery-card.cache.js +0 -43
  339. package/dist/opportunities/discovery.env.d.ts +0 -20
  340. package/dist/opportunities/discovery.env.js +0 -109
  341. package/dist/opportunities/discriminator/discriminator.adjustments.d.ts +0 -90
  342. package/dist/opportunities/discriminator/discriminator.adjustments.js +0 -141
  343. package/dist/opportunities/discriminator/discriminator.assigner.d.ts +0 -78
  344. package/dist/opportunities/discriminator/discriminator.assigner.js +0 -153
  345. package/dist/opportunities/discriminator/discriminator.env.d.ts +0 -103
  346. package/dist/opportunities/discriminator/discriminator.env.js +0 -103
  347. package/dist/opportunities/discriminator/discriminator.miner.d.ts +0 -114
  348. package/dist/opportunities/discriminator/discriminator.miner.js +0 -228
  349. package/dist/opportunities/discriminator/discriminator.push.d.ts +0 -13
  350. package/dist/opportunities/discriminator/discriminator.push.js +0 -19
  351. package/dist/opportunities/discriminator/discriminator.question.d.ts +0 -58
  352. package/dist/opportunities/discriminator/discriminator.question.js +0 -155
  353. package/dist/opportunities/discriminator/discriminator.scorer.d.ts +0 -32
  354. package/dist/opportunities/discriminator/discriminator.scorer.js +0 -105
  355. package/dist/opportunities/discriminator/discriminator.shadow.d.ts +0 -32
  356. package/dist/opportunities/discriminator/discriminator.shadow.js +0 -90
  357. package/dist/opportunities/discriminator/discriminator.types.d.ts +0 -93
  358. package/dist/opportunities/discriminator/discriminator.types.js +0 -18
  359. package/dist/opportunities/negotiation-context.loader.d.ts +0 -59
  360. package/dist/opportunities/negotiation-context.loader.js +0 -90
  361. package/dist/opportunities/negotiation-evidence/negotiation-evidence.env.d.ts +0 -43
  362. package/dist/opportunities/negotiation-evidence/negotiation-evidence.env.js +0 -44
  363. package/dist/opportunities/negotiation-evidence/negotiation-evidence.extractor.d.ts +0 -24
  364. package/dist/opportunities/negotiation-evidence/negotiation-evidence.extractor.js +0 -188
  365. package/dist/opportunities/negotiation-evidence/negotiation-evidence.miner.d.ts +0 -26
  366. package/dist/opportunities/negotiation-evidence/negotiation-evidence.miner.js +0 -112
  367. package/dist/opportunities/negotiation-evidence/negotiation-evidence.shadow.d.ts +0 -19
  368. package/dist/opportunities/negotiation-evidence/negotiation-evidence.shadow.js +0 -61
  369. package/dist/opportunities/negotiation-evidence/negotiation-evidence.types.d.ts +0 -191
  370. package/dist/opportunities/negotiation-evidence/negotiation-evidence.types.js +0 -18
  371. package/dist/opportunities/negotiation-evidence/negotiation-evidence.verifier.d.ts +0 -34
  372. package/dist/opportunities/negotiation-evidence/negotiation-evidence.verifier.js +0 -91
  373. package/dist/opportunities/negotiation-summary.builder.d.ts +0 -37
  374. package/dist/opportunities/negotiation-summary.builder.js +0 -66
  375. package/dist/opportunities/opportunity.discovery-negotiation-summary.d.ts +0 -14
  376. package/dist/opportunities/opportunity.discovery-negotiation-summary.js +0 -46
  377. package/dist/opportunities/opportunity.enricher.d.ts +0 -71
  378. package/dist/opportunities/opportunity.enricher.js +0 -280
  379. package/dist/opportunities/opportunity.evaluator.d.ts +0 -289
  380. package/dist/opportunities/opportunity.evaluator.js +0 -516
  381. package/dist/opportunities/opportunity.evidence.d.ts +0 -22
  382. package/dist/opportunities/opportunity.evidence.js +0 -87
  383. package/dist/opportunities/opportunity.existing-negotiation.d.ts +0 -79
  384. package/dist/opportunities/opportunity.existing-negotiation.js +0 -118
  385. package/dist/opportunities/opportunity.feed-selection.js +0 -96
  386. package/dist/opportunities/opportunity.graph.d.ts +0 -1611
  387. package/dist/opportunities/opportunity.graph.discovery-strategies.d.ts +0 -109
  388. package/dist/opportunities/opportunity.graph.discovery-strategies.js +0 -451
  389. package/dist/opportunities/opportunity.graph.discovery.d.ts +0 -69
  390. package/dist/opportunities/opportunity.graph.discovery.js +0 -397
  391. package/dist/opportunities/opportunity.graph.evaluation.d.ts +0 -82
  392. package/dist/opportunities/opportunity.graph.evaluation.js +0 -608
  393. package/dist/opportunities/opportunity.graph.js +0 -193
  394. package/dist/opportunities/opportunity.graph.modes.d.ts +0 -538
  395. package/dist/opportunities/opportunity.graph.modes.js +0 -538
  396. package/dist/opportunities/opportunity.graph.negotiate.d.ts +0 -109
  397. package/dist/opportunities/opportunity.graph.negotiate.js +0 -392
  398. package/dist/opportunities/opportunity.graph.persist-node.d.ts +0 -93
  399. package/dist/opportunities/opportunity.graph.persist-node.js +0 -765
  400. package/dist/opportunities/opportunity.graph.prep.d.ts +0 -150
  401. package/dist/opportunities/opportunity.graph.prep.js +0 -381
  402. package/dist/opportunities/opportunity.graph.shared.d.ts +0 -173
  403. package/dist/opportunities/opportunity.graph.shared.js +0 -199
  404. package/dist/opportunities/opportunity.introducer-feature.d.ts +0 -2
  405. package/dist/opportunities/opportunity.introducer-feature.js +0 -4
  406. package/dist/opportunities/opportunity.introducer.d.ts +0 -77
  407. package/dist/opportunities/opportunity.introducer.js +0 -99
  408. package/dist/opportunities/opportunity.labels.js +0 -10
  409. package/dist/opportunities/opportunity.lifecycle.d.ts +0 -63
  410. package/dist/opportunities/opportunity.lifecycle.js +0 -181
  411. package/dist/opportunities/opportunity.module.d.ts +0 -54
  412. package/dist/opportunities/opportunity.module.js +0 -39
  413. package/dist/opportunities/opportunity.newborn-stamping.d.ts +0 -41
  414. package/dist/opportunities/opportunity.newborn-stamping.js +0 -81
  415. package/dist/opportunities/opportunity.owner-approval.d.ts +0 -118
  416. package/dist/opportunities/opportunity.owner-approval.js +0 -34
  417. package/dist/opportunities/opportunity.owner-provenance.d.ts +0 -6
  418. package/dist/opportunities/opportunity.owner-provenance.js +0 -28
  419. package/dist/opportunities/opportunity.persist.d.ts +0 -58
  420. package/dist/opportunities/opportunity.persist.js +0 -145
  421. package/dist/opportunities/opportunity.persistence-admission.d.ts +0 -39
  422. package/dist/opportunities/opportunity.persistence-admission.js +0 -59
  423. package/dist/opportunities/opportunity.state.d.ts +0 -451
  424. package/dist/opportunities/opportunity.state.js +0 -256
  425. package/dist/opportunities/opportunity.tools.cards.d.ts +0 -138
  426. package/dist/opportunities/opportunity.tools.cards.js +0 -212
  427. package/dist/opportunities/opportunity.tools.d.ts +0 -12
  428. package/dist/opportunities/opportunity.tools.js +0 -236
  429. package/dist/opportunities/opportunity.tools.list.d.ts +0 -10
  430. package/dist/opportunities/opportunity.tools.list.js +0 -489
  431. package/dist/opportunities/opportunity.tools.port.d.ts +0 -16
  432. package/dist/opportunities/opportunity.utils.d.ts +0 -217
  433. package/dist/opportunities/opportunity.utils.js +0 -395
  434. package/dist/opportunities/outcome/outcome.env.d.ts +0 -60
  435. package/dist/opportunities/outcome/outcome.env.js +0 -63
  436. package/dist/opportunities/outcome/outcome.hypotheses.d.ts +0 -29
  437. package/dist/opportunities/outcome/outcome.hypotheses.js +0 -117
  438. package/dist/opportunities/outcome/outcome.shadow.d.ts +0 -56
  439. package/dist/opportunities/outcome/outcome.shadow.js +0 -87
  440. package/dist/opportunities/outcome/outcome.types.d.ts +0 -110
  441. package/dist/opportunities/outcome/outcome.types.js +0 -26
  442. package/dist/opportunities/radar/radar.health.d.ts +0 -31
  443. package/dist/opportunities/radar/radar.health.js +0 -75
  444. package/dist/premises/premise.analyzer.d.ts +0 -35
  445. package/dist/premises/premise.analyzer.js +0 -115
  446. package/dist/premises/premise.decomposer.d.ts +0 -69
  447. package/dist/premises/premise.decomposer.js +0 -213
  448. package/dist/premises/premise.graph.d.ts +0 -345
  449. package/dist/premises/premise.graph.js +0 -278
  450. package/dist/premises/premise.indexer.d.ts +0 -35
  451. package/dist/premises/premise.indexer.js +0 -86
  452. package/dist/premises/premise.state.d.ts +0 -67
  453. package/dist/premises/premise.state.js +0 -94
  454. package/dist/premises/premise.tools.d.ts +0 -3
  455. package/dist/premises/premise.tools.js +0 -248
  456. package/dist/questions/question.env.d.ts +0 -27
  457. package/dist/questions/question.env.js +0 -27
  458. package/dist/questions/question.input.d.ts +0 -107
  459. package/dist/questions/question.module.d.ts +0 -30
  460. package/dist/questions/question.module.js +0 -28
  461. package/dist/questions/question.schema.d.ts +0 -1529
  462. package/dist/questions/question.schema.js +0 -420
  463. package/dist/shared/agent/activity-projection.d.ts +0 -271
  464. package/dist/shared/agent/activity-projection.js +0 -254
  465. package/dist/shared/agent/canonical-guidance.d.ts +0 -30
  466. package/dist/shared/agent/canonical-guidance.js +0 -246
  467. package/dist/shared/agent/model.resolver.d.ts +0 -48
  468. package/dist/shared/agent/tool.factory.d.ts +0 -17
  469. package/dist/shared/agent/tool.factory.js +0 -221
  470. package/dist/shared/agent/tool.helpers.d.ts +0 -482
  471. package/dist/shared/agent/tool.helpers.js +0 -232
  472. package/dist/shared/agent/tool.registry.d.ts +0 -25
  473. package/dist/shared/agent/tool.registry.js +0 -76
  474. package/dist/shared/agent/tool.runtime.d.ts +0 -28
  475. package/dist/shared/agent/tool.runtime.js +0 -194
  476. package/dist/shared/agent/tool.scope.d.ts +0 -44
  477. package/dist/shared/agent/tool.scope.js +0 -50
  478. package/dist/shared/agent/utility.tools.d.ts +0 -15
  479. package/dist/shared/agent/utility.tools.js +0 -322
  480. package/dist/shared/assignment/network-assignment.policy.d.ts +0 -61
  481. package/dist/shared/assignment/network-assignment.policy.js +0 -105
  482. package/dist/shared/interfaces/agent-dispatcher.interface.d.ts +0 -100
  483. package/dist/shared/interfaces/agent-dispatcher.interface.js +0 -12
  484. package/dist/shared/interfaces/auth.interface.d.ts +0 -37
  485. package/dist/shared/interfaces/auth.interface.js +0 -1
  486. package/dist/shared/interfaces/chat-message-writer.interface.d.ts +0 -18
  487. package/dist/shared/interfaces/chat-message-writer.interface.js +0 -1
  488. package/dist/shared/interfaces/chat-session.interface.d.ts +0 -23
  489. package/dist/shared/interfaces/chat-session.interface.js +0 -18
  490. package/dist/shared/interfaces/chat-summary.interface.d.ts +0 -16
  491. package/dist/shared/interfaces/chat-summary.interface.js +0 -1
  492. package/dist/shared/interfaces/database.capabilities.d.ts +0 -100
  493. package/dist/shared/interfaces/database.interface.d.ts +0 -16
  494. package/dist/shared/interfaces/database.member-queries.d.ts +0 -219
  495. package/dist/shared/interfaces/database.member-queries.js +0 -4
  496. package/dist/shared/interfaces/database.negotiation.d.ts +0 -329
  497. package/dist/shared/interfaces/database.negotiation.js +0 -26
  498. package/dist/shared/interfaces/database.network-queries.js +0 -4
  499. package/dist/shared/interfaces/database.opportunity-queries.js +0 -4
  500. package/dist/shared/interfaces/delivery-ledger.interface.d.ts +0 -40
  501. package/dist/shared/interfaces/delivery-ledger.interface.js +0 -5
  502. package/dist/shared/interfaces/embedder.interface.d.ts +0 -92
  503. package/dist/shared/interfaces/embedder.interface.js +0 -4
  504. package/dist/shared/interfaces/enrichment-run.interface.d.ts +0 -62
  505. package/dist/shared/interfaces/enrichment-run.interface.js +0 -1
  506. package/dist/shared/interfaces/enrichment.interface.js +0 -1
  507. package/dist/shared/interfaces/negotiation-events.interface.d.ts +0 -77
  508. package/dist/shared/interfaces/negotiation-events.interface.js +0 -6
  509. package/dist/shared/interfaces/negotiation-summary.interface.d.ts +0 -25
  510. package/dist/shared/interfaces/negotiation-summary.interface.js +0 -1
  511. package/dist/shared/interfaces/negotiator-memory.interface.d.ts +0 -58
  512. package/dist/shared/interfaces/negotiator-memory.interface.js +0 -11
  513. package/dist/shared/interfaces/queue.interface.d.ts +0 -23
  514. package/dist/shared/interfaces/queue.interface.js +0 -4
  515. package/dist/shared/interfaces/scraper.interface.js +0 -1
  516. package/dist/shared/interfaces/tool-request-context.interface.d.ts +0 -11
  517. package/dist/shared/interfaces/tool-request-context.interface.js +0 -1
  518. package/dist/shared/observability/request-context.d.ts +0 -27
  519. package/dist/shared/observability/request-context.js +0 -6
  520. package/dist/shared/schemas/mcp-auth.schema.d.ts +0 -87
  521. package/dist/shared/schemas/mcp-auth.schema.js +0 -56
  522. package/dist/shared/schemas/negotiation-digest.schema.d.ts +0 -58
  523. package/dist/shared/schemas/negotiation-digest.schema.js +0 -38
  524. package/dist/shared/schemas/negotiation-state.schema.d.ts +0 -343
  525. package/dist/shared/schemas/negotiation-state.schema.js +0 -81
  526. package/dist/shared/schemas/question-block.fixture.d.ts +0 -12
  527. package/dist/shared/schemas/question-block.fixture.js +0 -39
  528. package/dist/shared/schemas/question-block.schema.d.ts +0 -111
  529. package/dist/shared/schemas/question-block.schema.js +0 -124
  530. package/dist/shared/schemas/structured-question.schema.d.ts +0 -66
  531. package/dist/shared/schemas/structured-question.schema.js +0 -31
  532. package/dist/shared/schemas/underspecification.schema.d.ts +0 -13
  533. package/dist/shared/schemas/underspecification.schema.js +0 -16
  534. /package/dist/{opportunities → internal/opportunities}/opportunity.update-admission.js +0 -0
  535. /package/dist/{opportunities → internal/opportunities}/radar/radar.state.js +0 -0
  536. /package/dist/{shared → internal/shared}/network/metadata.renderer.d.ts +0 -0
  537. /package/dist/{shared → internal/shared}/network/metadata.renderer.js +0 -0
  538. /package/dist/{shared → internal/shared}/observability/debug-meta.sanitizer.d.ts +0 -0
  539. /package/dist/{shared → internal/shared}/observability/debug-meta.sanitizer.js +0 -0
  540. /package/dist/{shared → internal/shared}/observability/performance.d.ts +0 -0
  541. /package/dist/{shared → internal/shared}/observability/performance.js +0 -0
  542. /package/dist/{shared → internal/shared}/observability/trace.d.ts +0 -0
  543. /package/dist/{shared → internal/shared}/observability/trace.js +0 -0
  544. /package/dist/{shared → internal/shared}/utils/claim-safety.d.ts +0 -0
  545. /package/dist/{shared → internal/shared}/utils/claim-safety.js +0 -0
  546. /package/dist/{shared → internal/shared}/utils/telegram-handle.d.ts +0 -0
  547. /package/dist/{shared → internal/shared}/utils/telegram-handle.js +0 -0
  548. /package/dist/{shared/interfaces/database.capabilities.js → platform/database/capabilities.js} +0 -0
  549. /package/dist/{shared/interfaces/database.entities.js → platform/database/entities.js} +0 -0
  550. /package/dist/{shared/interfaces/database.identity-queries.js → platform/database/identity-queries.js} +0 -0
  551. /package/dist/{agents/agent.dispatcher.port.js → platform/database/negotiation.js} +0 -0
  552. /package/dist/{chat/chat.persona.js → platform/database/opportunity-queries.js} +0 -0
  553. /package/dist/{contexts/context.tools.port.js → platform/discovery/embedder.js} +0 -0
  554. /package/dist/{shared/interfaces/scraper.interface.d.ts → platform/discovery/scraper.d.ts} +0 -0
  555. /package/dist/{negotiations/negotiation.deadlock.contracts.js → platform/discovery/scraper.js} +0 -0
  556. /package/dist/{shared/interfaces/enrichment.interface.d.ts → platform/enrichment/ports.d.ts} +0 -0
  557. /package/dist/{negotiations/negotiation.tools.port.js → platform/enrichment/ports.js} +0 -0
  558. /package/dist/{opportunities/opportunity.tools.port.js → platform/runtime/observability.js} +0 -0
  559. /package/dist/{questions/question.input.js → protocol/core.js} +0 -0
  560. /package/dist/{shared → protocol}/schemas/chat-context.schema.d.ts +0 -0
  561. /package/dist/{shared → protocol}/schemas/chat-context.schema.js +0 -0
@@ -1,516 +0,0 @@
1
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
2
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
3
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
4
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
5
- return c > 3 && r && Object.defineProperty(target, key, r), r;
6
- };
7
- var __metadata = (this && this.__metadata) || function (k, v) {
8
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
9
- };
10
- import { HumanMessage, SystemMessage } from "@langchain/core/messages";
11
- import { tool } from "@langchain/core/tools";
12
- import { z } from "zod";
13
- import { protocolLogger } from "../shared/observability/protocol.logger.js";
14
- import { Timed } from "../shared/observability/performance.js";
15
- import { stripUuids } from "./opportunity.presentation.js";
16
- import { createStructuredModel } from "../shared/agent/model.config.js";
17
- import { invokeWithAbortSignal } from "../shared/agent/model-signal.js";
18
- import { renderOpportunityEvidenceForPrompt } from './opportunity.evidence.js';
19
- import { hasUnsupportedOpportunityClaim } from '../shared/utils/claim-safety.js';
20
- import { normalizeOpportunityActorIntent } from './opportunity.actor.js';
21
- const logger = protocolLogger("OpportunityEvaluator");
22
- const invokeLog = protocolLogger("OpportunityEvaluator:invoke");
23
- const invokeEntityBundleLog = protocolLogger("OpportunityEvaluator:invokeEntityBundle");
24
- // ──────────────────────────────────────────────────────────────
25
- // 1. SYSTEM PROMPT
26
- // ──────────────────────────────────────────────────────────────
27
- const systemPrompt = `
28
- You are an expert "Opportunity Matcher" and super-connector.
29
- Your Goal: Analyze a Source User's profile against a Candidate User's profile to identify A SINGLE HIGH-VALUE opportunity.
30
-
31
- Input:
32
- - Source Context: The Source User's own Profile.
33
- - Candidate Profile (JSON)
34
- - Existing Opportunities (Context of matches already made)
35
-
36
- Output:
37
- - A list containing EXACTLY ONE "Opportunity" if a match exists.
38
- - If NO match exists, return an empty list.
39
- - Score (0-100): How strong is this match?
40
- - 90-100: "Must Meet" (Perfect alignment).
41
- - 70-89: "Should Meet" (Strong overlaps, clear potential).
42
- - <70: No opportunity (Return empty list).
43
-
44
- **CRITICAL: VALENCY & REASONING**
45
-
46
- 1. **Valency Analysis**:
47
- - Determine the semantic role of the Candidate relative to the Source's goal.
48
- - "Agent": The Candidate CAN DO something for the Source (e.g., Source needs a dev, Candidate IS a dev).
49
- - "Patient": The Candidate NEEDS something from the Source (e.g., Source is a mentor, Candidate needs mentoring).
50
- - "Peer": Symmetric collaboration.
51
-
52
- 2. **Reasoning (Third-Party Analytical Perspective)**:
53
- - **reasoning**: A neutral, third-party explanation of why this opportunity exists. Written for other LLM agents to read and understand.
54
- - Mention BOTH users by their roles (e.g. "The source user" and "The candidate") and explain why they are a match.
55
- - Do NOT address either user as "you". Write from an objective observer's perspective.
56
- - Include what each side brings to the connection and why it is mutually valuable.
57
- - NEVER leak private intents. If someone's intent is confidential, describe their relevant attributes instead.
58
-
59
- **VISIBILITY IMPLICATIONS OF ROLE ASSIGNMENT**
60
-
61
- The valency role you assign directly controls who sees the opportunity and when:
62
- - "Agent" (helper/provider): LAST to see the opportunity — only after the Patient has committed to reaching out. Agents are protected from noise; they only see high-intent connections.
63
- - "Patient" (seeker/requester): Sees the opportunity early and decides whether to reach out.
64
- - "Peer" (symmetric): Both parties see the opportunity immediately and either can initiate.
65
-
66
- Choose the role carefully — it determines the entire flow of how the connection unfolds.
67
-
68
- Rules:
69
- 1. SYNTHESIS (CRITICAL): If multiple distinct match angles exist, SYNTHESIZE them into a SINGLE, robust opportunity.
70
- 2. NEVER address either user directly — always use third-party references ("the source", "the candidate").
71
- 3. COMPREHENSIVE: The single opportunity must capture ALL the value of the connection.
72
- 4. Be specific about the "Why" for BOTH sides in the reasoning.
73
- 5. DEDUPLICATION: Do NOT suggest opportunities that duplicate "Existing Opportunities".
74
- 6. Do not suggest an opportunity if the source and candidate clearly already know each other (e.g. same company, co-founders, same team).
75
- 7. SAME-SIDE MATCHING: If both the source and candidate are SEEKING the same resource (e.g., both looking for investors, both seeking a co-founder), this is not an opportunity. Return an empty list unless one side clearly OFFERS what the other SEEKS.
76
- 8. NETWORK CONTEXT IS NOT PERSON EVIDENCE: A network assignment, title, type, or metadata is retrieval and thematic context only. It is never proof that a person attended an event, belongs to a group, resides in a place, knows anyone else from the network, or shared a session, time, or location with anyone. Do not state or infer those claims in opportunity reasoning.
77
- `;
78
- // Entity-bundle system prompt (C2): entities + four match patterns + actors output
79
- // NOTE: entityBundleSystemPrompt uses a >= 30 threshold (permissive) while
80
- // systemPrompt uses >= 70 (strict). This is intentional: batch mode casts a wide
81
- // net so the calling pipeline can apply its own filters; pairwise mode is strict
82
- // because it returns a single yes/no decision per candidate pair.
83
- const entityBundleSystemPrompt = `
84
- You are an expert "Opportunity Matcher" and super-connector.
85
- Your Goal: Analyze a set of entities (people), each with a profile and optional intents, and identify HIGH-VALUE opportunities among them.
86
-
87
- Input:
88
- - DISCOVERER: The user ID who triggered discovery (for context; they may or may not be in the entity list).
89
- - ENTITIES: A set of entities. Each entity has:
90
- - userId, networkId (the index through which they were found)
91
- - evidenceKey (stable key for the matched resource when available)
92
- - profile: name, bio, location, interests, skills, context
93
- - intents (optional): list of { intentId, payload, summary } — some entities are profile-only, some have intents
94
- - ragScore, matchedVia (how they were found)
95
- - evidence (typed retrieval evidence: discovery kind, network, score, lens, source/candidate ids)
96
- - EXISTING OPPORTUNITIES: Context of matches already made (for deduplication).
97
-
98
- BEFORE SCORING — determine role satisfiability:
99
-
100
- Definitions:
101
- SUBSTITUTIVE ROLE: The candidate can directly fill the open position in the discoverer's intent. The candidate IS the person/entity the discoverer is seeking. Example: discoverer seeks "co-founder" → candidate is an engineer willing to co-found.
102
- COMPLEMENTARY ROLE: The candidate's contribution is defined relative to the seeker-sought relation from the outside — they fund, advise, recruit for, or enable the sought relationship rather than participating in it as the target. Example: discoverer seeks "co-founder" → candidate is a VC (funds the company, does not co-found it).
103
-
104
- Step 1 — Identify the open argument in each discoverer intent: what type of person or entity would satisfy the intent if found?
105
- Step 2 — For each candidate, ask: can this candidate directly fill that open argument position?
106
- YES → substitutive role. Proceed to scoring.
107
- NO → complementary role. Apply Rule 7 (score ≤ 30, return no opportunity).
108
- Step 3 — Contextual override: if the candidate's profile contains explicit evidence that they currently function in the substitutive role (e.g., a former investor who is now building full-time as a technical co-founder), re-evaluate Step 2 against their current role, not their categorical label.
109
-
110
- Match patterns to consider:
111
- 1. Profile-to-profile: Complementary backgrounds (skills, interests, location).
112
- 2. Profile-to-intents+profile: Someone's skills/background match another's stated goals (intents).
113
- 3. Intents+profile-to-profile: Someone's stated goals match another's skills/background.
114
- 4. Intents+profile-to-intents+profile: Complementary or reciprocal goals between two or more people.
115
-
116
- Output:
117
- - A list of verdicts with EXACTLY ONE verdict for EVERY candidate entity (never omit a candidate).
118
- - Each verdict has candidateId (the candidate USER ID), accepted, reasoning, score, and actors.
119
- - accepted=true verdicts must include exactly the source and that candidate as actors. accepted=false verdicts may use an empty actor list.
120
- - Rejected candidates still require a verdict: set accepted=false and score below the appropriate threshold.
121
- - A verdict score is 0-100:
122
- - 90-100: Must Meet — candidate's PRIMARY role directly matches what the discoverer seeks.
123
- - 70-89: Should Meet — meaningful overlap on role type AND complementary intent.
124
- - 50-69: Worth Considering — tangential overlap only.
125
- - <30: Complementary-role mismatch (candidate cannot fill the discoverer's open argument position), same-side match, or already acquainted.
126
- - IMPORTANT: Every candidate must be represented once and only once. Do not return an opportunity list and do not omit rejected candidates.
127
- - Actors in accepted verdicts:
128
- - userId
129
- - role: "agent" (can do something for others), "patient" (needs something from others), "peer" (symmetric collaboration)
130
- - intentId (optional): if the match is intent-driven, the specific intent ID for that user
131
- - evidenceKey (optional): copy the entity evidenceKey when the actor is driven by a specific listed entity
132
-
133
- VISIBILITY (role controls who sees the opportunity when):
134
- - agent: Last to see — after the patient has committed to reaching out.
135
- - patient: Sees early and decides whether to reach out.
136
- - peer: Both see immediately; either can initiate.
137
-
138
- Rules:
139
- 1. ONE OPPORTUNITY PER CANDIDATE: Create a SEPARATE opportunity for EACH candidate who matches. Do NOT combine multiple candidates into one opportunity. Each opportunity should have exactly 2 actors: the DISCOVERER and ONE candidate.
140
- 2. INDIVIDUAL REASONING: Write specific reasoning for EACH candidate individually. Do NOT mention other candidates in the reasoning. Focus on why THIS specific candidate matches THIS specific discoverer.
141
- 3. DEDUPLICATION: Do not suggest opportunities that duplicate Existing Opportunities.
142
- 4. Write reasoning from an objective observer's perspective; be specific about the "Why" for each side.
143
- 5. When in introduction mode, each opportunity must have exactly two actors — the two people being introduced. The discoverer (introducer) is added by the system and must not be included in your actors list.
144
- 6. ALREADY KNOW EACH OTHER: Do NOT suggest an opportunity if the entities clearly already know each other. Examples: co-founders of the same company, same team at the same organization, same employer, or any relationship that is obviously existing from their profiles (bio, context). When in doubt, if both profiles mention the same company/org/team in a way that implies they work together, return an empty list for that pair.
145
- 7. ROLE-SATISFIABILITY (evaluate before scoring): A candidate satisfies a discoverer's intent only if they can fill the SUBSTITUTIVE ROLE — the open argument position in the intent (the type of person the discoverer is seeking). A candidate in a COMPLEMENTARY ROLE (one that funds, advises, recruits for, or otherwise enables the sought relation from outside it) does not satisfy the intent, regardless of how closely associated their domain is.
146
- COMPLEMENTARY-ROLE CAP: If the candidate occupies a complementary rather than substitutive role relative to the discoverer's intent, score below 30 (e.g. 0–20). Return no opportunity. A "reject" score must be strictly below 30 so the candidate is not surfaced — never park a rejected candidate at exactly 30.
147
- CONTEXTUAL OVERRIDE: If the candidate's profile contains explicit evidence that they currently function in the substitutive role (not merely historically or tangentially), treat them as substitutive and score normally.
148
- 8. SAME-SIDE MATCHING: Before scoring, check whether the DISCOVERER and CANDIDATE are both SEEKING the same thing. Look at both parties' intents for directionality:
149
- - SEEKING signals: "looking for", "seeking", "want to find", "need", "raising", "hiring"
150
- - OFFERING signals: "can offer", "expert in", "investing in", "mentoring", "available for"
151
- If both parties have SEEKING intents targeting the same resource (e.g., both seeking investors, both seeking co-founders, both seeking mentorship), this is NOT an opportunity — score <30. An opportunity requires one side to OFFER what the other SEEKS.
152
- 9. LOCATION MATCHING: When the DISCOVERY REQUEST mentions a specific location (city, region, or country):
153
- a. If a candidate's profile.location is KNOWN and clearly does NOT match the requested location (different city/region), score below 30 (e.g. 0–25) and return no opportunity. An explicitly requested location is a hard constraint: a known geographic mismatch excludes the candidate.
154
- b. If a candidate's profile.location is UNKNOWN, EMPTY, or AMBIGUOUS, do NOT penalize — allow them through and score based on other factors. Note in reasoning that their location is unverified.
155
- c. If a candidate's profile.location matches or is reasonably close (e.g., "Bay Area" matches "San Francisco", "Remote" matches any location), score normally.
156
- d. "Remote" or "Global" locations are compatible with any requested location.
157
- 10. EVENT NETWORK CONTEXT: When NETWORK CONTEXTS includes an event-type network (identified by dates, location, schedule, or themes):
158
- a. TEMPORAL RELEVANCE: Event start/end dates may affect whether an explicitly stated event-related intent is timely. After an event ends, event-specific intents lose relevance unless the connection has lasting value.
159
- b. THEME ALIGNMENT: Event themes or tracks may be used as thematic retrieval context when a person's own profile or intent independently aligns with them.
160
- c. PROHIBITED INFERENCE: Network assignment, title, type, schedule, location, and metadata are retrieval context only. They are never proof that any person attended or will attend, belongs to the event or network, resides in its location, knows another person from it, or shared a session, time, place, or location with anyone. Do not infer co-attendance, same-place/same-time presence, session attendance, or peer roles from network co-membership.
161
- `;
162
- // ──────────────────────────────────────────────────────────────
163
- // 2. RESPONSE SCHEMA (Zod)
164
- // ──────────────────────────────────────────────────────────────
165
- const OpportunitySchema = z.object({
166
- reasoning: z.string().describe('Third-party analytical explanation of why this opportunity exists. Mentions both users by role. Written for other LLM agents to understand the match.'),
167
- score: z.number().min(0).max(100).describe('Relevance score 0-100'),
168
- valencyRole: z.enum(['Agent', 'Patient', 'Peer']).describe("The semantic role of the Candidate relative to the Source"),
169
- sourceId: z.string().describe('The user ID of the source'),
170
- candidateId: z.string().describe('The user ID of the candidate'),
171
- });
172
- const responseFormat = z.object({
173
- opportunities: z.array(OpportunitySchema).describe("List of opportunities identified"),
174
- });
175
- const ActorSchema = z.object({
176
- userId: z.string(),
177
- role: z.enum(['agent', 'patient', 'peer']),
178
- intentId: z.string().nullable()
179
- .transform((value) => normalizeOpportunityActorIntent(value) ?? null)
180
- .describe('If the match is intent-driven, the specific intent ID; null otherwise'),
181
- evidenceKey: z.string().nullable().optional().describe('Stable evidence key for the matched entity; null if unknown'),
182
- });
183
- const _OpportunityWithActorsSchema = z.object({
184
- reasoning: z.string(),
185
- score: z.number().min(0).max(100),
186
- actors: z.array(ActorSchema).min(2).describe('All actors in this opportunity with their roles'),
187
- });
188
- const EvaluatorVerdictSchema = z.object({
189
- candidateId: z.string().describe('The candidate USER ID being evaluated'),
190
- accepted: z.boolean().describe('Whether this candidate is a qualifying opportunity'),
191
- score: z.number().min(0).max(100),
192
- reasoning: z.string(),
193
- actors: z.array(ActorSchema).describe('Accepted verdicts include source and candidate actors; rejected verdicts may use an empty list'),
194
- });
195
- const entityBundleResponseFormat = z.object({
196
- verdicts: z.array(EvaluatorVerdictSchema).describe('Exactly one verdict for every candidate entity; include rejected candidates'),
197
- });
198
- /** Raised only after both bounded attempts return an incomplete evaluator batch. */
199
- export class EvaluatorIncompleteError extends Error {
200
- constructor() {
201
- super('evaluator-incomplete');
202
- this.name = 'EvaluatorIncompleteError';
203
- }
204
- }
205
- function reconcileEvaluatorVerdicts(verdicts, candidateIds, discovererId, introductionMode) {
206
- const expected = new Set(candidateIds);
207
- const seen = new Set();
208
- for (const verdict of verdicts) {
209
- if (!expected.has(verdict.candidateId) || seen.has(verdict.candidateId)) {
210
- throw new EvaluatorIncompleteError();
211
- }
212
- if (verdict.accepted) {
213
- const expectedActorIds = introductionMode
214
- ? expected
215
- : new Set([discovererId, verdict.candidateId]);
216
- const actorIds = verdict.actors.map((actor) => actor.userId);
217
- if (actorIds.length !== expectedActorIds.size ||
218
- new Set(actorIds).size !== expectedActorIds.size ||
219
- actorIds.some((actorId) => !expectedActorIds.has(actorId))) {
220
- throw new EvaluatorIncompleteError();
221
- }
222
- }
223
- seen.add(verdict.candidateId);
224
- }
225
- if (seen.size !== expected.size)
226
- throw new EvaluatorIncompleteError();
227
- return verdicts;
228
- }
229
- function isEvaluatorOutputError(error) {
230
- return error instanceof z.ZodError || error instanceof EvaluatorIncompleteError;
231
- }
232
- export class OpportunityEvaluator {
233
- constructor(options) {
234
- this.model = createStructuredModel("opportunityEvaluator", responseFormat, {
235
- name: "opportunity_evaluator"
236
- });
237
- this.entityBundleModel = options?.entityBundleModel ?? createStructuredModel("opportunityEvaluator", entityBundleResponseFormat, {
238
- name: "opportunity_evaluator_entity_bundle"
239
- });
240
- }
241
- /**
242
- * Main Entry Point: Batch analysis of candidates.
243
- *
244
- * @param sourceProfileContext - The profile context string of the user we are finding opportunities FOR.
245
- * @param candidates - List of potential matches to evaluate.
246
- * @param options - Config (minScore, valid types, etc).
247
- * @returns A sorted list of high-value `Opportunity` objects.
248
- */
249
- async invoke(sourceProfileContext, candidates, options) {
250
- const minScore = options.minScore || 70;
251
- invokeLog.verbose('Analyzing candidates', { count: candidates.length });
252
- if (candidates.length === 0) {
253
- logger.verbose('No candidates provided.');
254
- return [];
255
- }
256
- const opportunities = [];
257
- // Analyze each candidate in parallel (bounded)
258
- const promises = candidates.map(async (candidate) => {
259
- // Pass existing opportunities context if provided
260
- const existingContext = options.existingOpportunities || '';
261
- return this.analyzeMatch(sourceProfileContext, candidate, candidate.userId, existingContext, options.signal);
262
- });
263
- const results = await Promise.all(promises);
264
- results.flat().forEach(op => {
265
- if (op.score >= minScore) {
266
- opportunities.push(op);
267
- }
268
- });
269
- // Sort by score and take top 1
270
- const out = opportunities.sort((a, b) => b.score - a.score).slice(0, 1);
271
- invokeLog.verbose('Done', { accepted: out.length });
272
- return out;
273
- }
274
- /**
275
- * Analyze a single match pair using the primary Agent model.
276
- */
277
- async analyzeMatch(sourceProfileContext, candidateProfile, candidateUserId, existingOpportunities, signal) {
278
- try {
279
- // Construct the source context part of the prompt
280
- const sourceContext = `SOURCE PROFILE:\n${sourceProfileContext}`;
281
- const existingContextPart = existingOpportunities
282
- ? `\nEXISTING OPPORTUNITIES (Deduplication Context):\n${existingOpportunities}\n`
283
- : '';
284
- // Create candidate context using template string
285
- const candidateContext = `
286
- ID: ${candidateUserId}
287
- Name: ${candidateProfile.identity?.name || 'Unknown'}
288
- Bio: ${candidateProfile.identity?.bio || ''}
289
- Location: ${candidateProfile.identity?.location || ''}
290
- Interests: ${candidateProfile.attributes?.interests?.join(', ') || ''}
291
- Skills: ${candidateProfile.attributes?.skills?.join(', ') || ''}
292
-
293
- Context: ${candidateProfile.narrative?.context || ''}
294
- `;
295
- const messages = [
296
- new SystemMessage(systemPrompt),
297
- new HumanMessage(`${sourceContext}\n${existingContextPart}\nCANDIDATE PROFILE:\n${candidateContext}`)
298
- ];
299
- const result = await invokeWithAbortSignal(this.model, messages, signal);
300
- const output = responseFormat.parse(result);
301
- const mappedOpportunities = output.opportunities.map((op) => ({
302
- ...op,
303
- reasoning: stripUuids(op.reasoning),
304
- candidateId: candidateUserId,
305
- }));
306
- return mappedOpportunities;
307
- }
308
- catch (e) {
309
- const message = e instanceof Error ? e.message : String(e);
310
- logger.warn('Analysis failed for candidate', { candidateUserId, message });
311
- throw e;
312
- }
313
- }
314
- /**
315
- * Entity-bundle entry point (C3): single LLM call with all entities, returns 0..N opportunities with actors.
316
- */
317
- async invokeEntityBundle(input, options = {}) {
318
- const minScore = options.minScore ?? 70;
319
- const returnAll = options.returnAll ?? false;
320
- const totalEntities = input.entities?.length ?? 0;
321
- if (!input.entities?.length) {
322
- invokeEntityBundleLog.verbose('No entities.');
323
- return [];
324
- }
325
- const existingPart = input.existingOpportunities
326
- ? `\nEXISTING OPPORTUNITIES:\n${input.existingOpportunities}\n`
327
- : '';
328
- const introModePart = input.introductionMode
329
- ? `\nINTRODUCTION MODE: This is a human-curated introduction. ${input.introducerName ?? 'The introducer'} (DISCOVERER: ${input.discovererId}) explicitly wants these people to connect. This is NOT an automatic discovery — a real person saw value in this connection.
330
-
331
- CRITICAL REASONING INSTRUCTIONS FOR INTRODUCTIONS:
332
- - Your reasoning MUST acknowledge that this is an introduction initiated by ${input.introducerName ?? 'the introducer'}, not a system-discovered match.
333
- - Start reasoning with something like "${input.introducerName ?? 'The introducer'} is connecting [Name A] and [Name B] because..." or "This introduction by ${input.introducerName ?? 'the introducer'} brings together..."
334
- - Even if the parties' intents or profiles don't obviously overlap, the introduction is still valid because the introducer saw the connection. Explain what the introducer likely sees in this match.
335
- - If explicit intents align, mention them — but frame it as supporting the introducer's judgment, not as the primary reason.${input.introductionHint ? `\nINTRODUCER'S CONTEXT: "${input.introductionHint}" — use this to inform your reasoning about why the introducer made this connection.` : ''}
336
- - Actors must refer ONLY to the ENTITIES below (the people being introduced). Do not include the DISCOVERER as an actor.
337
- - You must output exactly two actors per opportunity (the two people being introduced). The introducer is added separately; do not include them in actors.
338
- - Be generous with scoring (70+ for any introduction with a plausible basis, since a human made the judgment).
339
- `
340
- : '';
341
- const discoveryQueryPart = input.discoveryQuery?.trim()
342
- ? `\nDISCOVERY REQUEST: The user asked: "${input.discoveryQuery.trim()}"
343
-
344
- CRITICAL SCORING RULES FOR DISCOVERY REQUESTS:
345
-
346
- 0. QUERY IS PRIMARY: The DISCOVERY REQUEST above is the primary evaluation criterion. The source user's stored INTENTS (if listed below) are background context — use them ONLY to fill in blanks when the query is too broad or vague to evaluate on its own. If the query is specific enough to score candidates, score strictly against the query and IGNORE stored intents. Never let a stored intent override or replace the query as the basis for scoring. When a specific query imposes a hard identity, role, capability, or location constraint, candidates that only match background context or thematic adjacency must score strictly below 30 and be omitted.
347
-
348
- 1. CLASSIFY THE QUERY TYPE — determine the predication type before scoring:
349
-
350
- IDENTITY/ROLE QUERY: The query term is a count noun or sortal that can serve as a predicate nominal — "X IS A [query]" is grammatical and meaningful. Examples: "samurai", "investors", "designers", "nurses", "founders". The user wants someone who IS that thing — not someone who works with, creates content about, or is tangentially associated with it.
351
- → Test: Can you say "this person IS a [query term]"? If yes, this is an identity query.
352
- → CRITICAL: Subject-matter contact is NOT identity. A character designer who draws samurai IS NOT a samurai. An engineer who raised funding IS NOT an investor. A journalist who covers finance IS NOT an investor. IS-A is not transitive through creative subject matter, professional adjacency, or domain familiarity.
353
-
354
- TOPICAL/DOMAIN QUERY: The query is a field, domain, or abstract topic — "X IS A [query]" is ungrammatical. Examples: "machine learning", "sustainability", "blockchain". The user wants someone who works in or has expertise in this domain.
355
- → Test: "This person IS a machine learning" makes no sense → topical query.
356
-
357
- NEED/CAPABILITY QUERY: The query contains a purposive frame — "someone to help with X", "need a Y", "looking for Z". The user describes a specific need.
358
-
359
- 2. APPLY TYPE-SPECIFIC SCORING:
360
-
361
- For IDENTITY/ROLE queries — apply a categorical gate:
362
- - First, make a binary IS-A judgment for each candidate: does this person's PRIMARY professional identity or self-description place them within the extension of the query term?
363
- - IS-A = TRUE → score 75-100 (modulated by intent alignment and profile richness)
364
- - IS-A = FALSE → score <30. Hard ceiling. Return no opportunity. Do NOT award surfacing credit for subject-matter adjacency, thematic association, creative output involving the query term, having received the thing, or being adjacent to people who are the thing.
365
- - Do NOT rescue a failed IS-A judgment with background intents. If the user searched "samurai" and the candidate is a visual artist (IS-A = false), the candidate's alignment with a background intent like "connect with visual artists" does not matter — the explicit query takes priority. If the user searched "investors" and the candidate merely raised money, score <30. If the user searched "scouts" and the candidate was scouted, score <30. If the user searched "art director", a solo illustrator is not enough: require explicit evidence that the candidate owns visual direction, leads/briefs other artists, manages a visual system, or is described as an art/creative director. General visual taste, composition skill, or illustration output alone is a failed IS-A judgment and must score <30.
366
-
367
- For TOPICAL/DOMAIN queries — apply gradient scoring:
368
- - 90-100: Deep expertise, primary focus area
369
- - 70-89: Substantial engagement, meaningful work in the domain
370
- - 50-69: Peripheral involvement, tangential connection
371
- - <50: No meaningful engagement
372
-
373
- For NEED/CAPABILITY queries — apply capability + availability scoring:
374
- - Score based on both capability match AND openness to the described collaboration
375
- - 90-100: Perfect capability match with explicit availability
376
- - 70-89: Strong capability, plausible availability
377
-
378
- 3. SAME-SIDE CHECK: If the candidate's intents show they are ALSO SEEKING what the discoverer is seeking (e.g., both looking for investors, both looking for co-founders), this is a same-side match. Score <30 regardless of keyword overlap in bios. The candidate must BE or OFFER what the discoverer is looking for, not also be looking for it.
379
-
380
- 4. LOCATION ENFORCEMENT: If the discovery request mentions a specific location (e.g., "in SF", "based in London", "Istanbul"), check each candidate's profile.location:
381
- - KNOWN MISMATCH (e.g., request says "SF" but candidate is "New York"): Score <30 and return no opportunity. State the mismatch in reasoning if returning diagnostic output. A known location mismatch is a hard query failure, even when the candidate otherwise matches the source's background interests.
382
- - UNKNOWN/EMPTY location: Do not penalize, and do NOT reject solely because the query contains a location. Treat location as unverified/missing evidence, then score on the non-location parts of the query. If the candidate strongly satisfies the requested role/domain (e.g., query "Unreal Engine developers in SF" and candidate is clearly an Unreal Engine developer with empty location), score normally enough to surface (typically 60-89) and note that location is unverified.
383
- - MATCH or COMPATIBLE (e.g., "Bay Area" ≈ "SF", "Remote" ≈ any): Score normally.
384
- `
385
- : '';
386
- const hasDiscoveryQuery = !!input.discoveryQuery?.trim();
387
- const entitiesBlock = input.entities.map((e) => {
388
- const isSource = e.userId === input.discovererId;
389
- // When an explicit discovery query is active, label the source user's stored
390
- // intents as background context so the LLM treats the query as primary.
391
- const intentsLabel = isSource && hasDiscoveryQuery ? 'BACKGROUND INTENTS (use only if query is too vague)' : 'INTENTS';
392
- const intentsPart = e.intents?.length
393
- ? `\n ${intentsLabel}:\n${e.intents.map((i) => ` - ${i.intentId}: ${i.payload}`).join('\n')}`
394
- : '';
395
- // Mask the discoverer's name so the LLM cannot leak it into reasoning.
396
- // The system prompt already says "use third-party references", but the LLM
397
- // ignores this when the actual name is visible. Masking it forces role-based
398
- // language ("the source user is looking…" instead of "Alice is looking…").
399
- const displayName = e.userId === input.discovererId
400
- ? '(source user)'
401
- : (e.profile.name ?? '');
402
- return `
403
- USER: ${e.userId}
404
- INDEX: ${e.networkId}
405
- EVIDENCE KEY: ${e.evidenceKey ?? '—'}
406
- PROFILE: Name: ${displayName} | Bio: ${e.profile.bio ?? ''} | Location: ${e.profile.location ?? ''} | Interests: ${e.profile.interests?.join(', ') ?? ''} | Skills: ${e.profile.skills?.join(', ') ?? ''} | Context: ${e.profile.context ?? ''}${intentsPart}
407
- RAG SCORE: ${e.ragScore ?? '—'}
408
- MATCHED VIA: ${e.matchedVia ?? '—'}
409
- EVIDENCE:
410
- ${renderOpportunityEvidenceForPrompt(e.evidence ?? [])}`;
411
- }).join('\n');
412
- const networkContextPart = input.networkContexts && Object.keys(input.networkContexts).length > 0
413
- ? `\n\nNETWORK CONTEXTS:\n${Object.entries(input.networkContexts).map(([nid, ctx]) => `[INDEX: ${nid}]\n${ctx}`).join('\n\n')}`
414
- : '';
415
- const humanContent = `DISCOVERER: ${input.discovererId}${introModePart}${discoveryQueryPart}${networkContextPart}\n\nENTITIES:\n${entitiesBlock}${existingPart}`;
416
- const messages = [
417
- new SystemMessage(entityBundleSystemPrompt),
418
- new HumanMessage(humanContent),
419
- ];
420
- const candidateIds = input.entities
421
- .filter((entity) => entity.userId !== input.discovererId)
422
- .map((entity) => entity.userId);
423
- if (new Set(candidateIds).size !== candidateIds.length) {
424
- throw new EvaluatorIncompleteError();
425
- }
426
- let parsedTotal = 0;
427
- let incompleteReason;
428
- for (let attempt = 0; attempt < 2; attempt++) {
429
- try {
430
- const result = await invokeWithAbortSignal(this.entityBundleModel, messages, options.signal);
431
- const parsed = entityBundleResponseFormat.parse(result);
432
- parsedTotal = parsed.verdicts.length;
433
- const verdicts = reconcileEvaluatorVerdicts(parsed.verdicts, candidateIds, input.discovererId, input.introductionMode ?? false);
434
- const accepted = verdicts
435
- .filter((verdict) => verdict.accepted)
436
- .map((verdict) => ({
437
- reasoning: stripUuids(verdict.reasoning),
438
- score: verdict.score,
439
- actors: verdict.actors,
440
- }))
441
- .filter((op) => op.actors.length >= 2);
442
- // Persistence safety is deterministic and precedes every score/returnAll
443
- // path. Network/context placement is not typed support provenance, so an
444
- // unsupported affiliation or presence claim rejects the whole result.
445
- const claimSafe = accepted.filter((op) => !hasUnsupportedOpportunityClaim(op.reasoning));
446
- const introGuard = input.introductionMode ? claimSafe.filter((op) => op.actors.length === 2) : claimSafe;
447
- const filtered = introGuard.filter((op) => op.score >= minScore);
448
- invokeEntityBundleLog.verbose('Done', {
449
- total: verdicts.length,
450
- afterClaimGuard: claimSafe.length,
451
- afterIntroGuard: introGuard.length,
452
- accepted: filtered.length,
453
- returnAll,
454
- });
455
- return returnAll ? introGuard : filtered;
456
- }
457
- catch (error) {
458
- if (!isEvaluatorOutputError(error))
459
- throw error;
460
- incompleteReason = error instanceof Error ? error.message : 'invalid output';
461
- }
462
- }
463
- invokeEntityBundleLog.error('Evaluator batch incomplete', {
464
- discovererId: input.discovererId,
465
- totalEntities,
466
- parsedTotal,
467
- minScore,
468
- reason: incompleteReason,
469
- });
470
- throw new EvaluatorIncompleteError();
471
- }
472
- /**
473
- * Factory method to expose the agent as a LangChain tool.
474
- * Simplified to only accept direct evaluation arguments.
475
- * PURE: Does not perform any database lookups.
476
- */
477
- static asTool() {
478
- return tool(async (args) => {
479
- const agent = new OpportunityEvaluator();
480
- const sourceProfileContext = args.sourceProfileContext;
481
- let candidates = [];
482
- if (args.candidatesJson) {
483
- try {
484
- candidates = JSON.parse(args.candidatesJson);
485
- }
486
- catch {
487
- logger.error("Failed to parse candidates JSON");
488
- }
489
- }
490
- const options = {
491
- minScore: args.minScore,
492
- };
493
- return await agent.invoke(sourceProfileContext, candidates, options);
494
- }, {
495
- name: 'opportunity_evaluator',
496
- description: 'Evaluates candidates against a source profile. SOURCE PROFILE CONTEXT MUST BE PROVIDED.',
497
- schema: z.object({
498
- sourceProfileContext: z.string().describe('The resolved source user profile context'),
499
- candidatesJson: z.string().optional().describe('JSON string list of Candidates'),
500
- minScore: z.number().optional().describe('Minimum score to accept a match')
501
- })
502
- });
503
- }
504
- }
505
- __decorate([
506
- Timed(),
507
- __metadata("design:type", Function),
508
- __metadata("design:paramtypes", [String, Array, Object]),
509
- __metadata("design:returntype", Promise)
510
- ], OpportunityEvaluator.prototype, "invoke", null);
511
- __decorate([
512
- Timed(),
513
- __metadata("design:type", Function),
514
- __metadata("design:paramtypes", [Object, Object]),
515
- __metadata("design:returntype", Promise)
516
- ], OpportunityEvaluator.prototype, "invokeEntityBundle", null);
@@ -1,22 +0,0 @@
1
- import type { OpportunityEvidence } from '../shared/schemas/network-assignment.schema.js';
2
- export interface EvidenceCandidateInput {
3
- networkId: string;
4
- similarity: number;
5
- lens: string;
6
- discoverySource?: 'query' | 'premise-similarity' | 'context-to-intent' | 'context-similarity';
7
- matchedStrategies?: string[];
8
- sourcePremiseId?: string;
9
- candidatePremiseId?: string;
10
- candidateIntentId?: string;
11
- sourceContextId?: string;
12
- candidateContextId?: string;
13
- candidatePayload?: string;
14
- candidateSummary?: string;
15
- }
16
- export declare function buildCandidateEvidence(candidate: EvidenceCandidateInput): OpportunityEvidence;
17
- export declare function withCandidateEvidence<T extends EvidenceCandidateInput>(candidate: T): T & {
18
- evidence: OpportunityEvidence[];
19
- };
20
- export declare function mergeOpportunityEvidence(...groups: Array<OpportunityEvidence[] | undefined>): OpportunityEvidence[];
21
- export declare function withMatchedStrategies(evidence: OpportunityEvidence[], strategies: string[]): OpportunityEvidence[];
22
- export declare function renderOpportunityEvidenceForPrompt(evidence: OpportunityEvidence[]): string;
@@ -1,87 +0,0 @@
1
- export function buildCandidateEvidence(candidate) {
2
- const kind = resolveEvidenceKind(candidate);
3
- return {
4
- kind,
5
- networkId: candidate.networkId,
6
- score: candidate.similarity,
7
- lens: candidate.lens,
8
- discoverySource: candidate.discoverySource,
9
- matchedStrategies: candidate.matchedStrategies,
10
- sourcePremiseId: candidate.sourcePremiseId,
11
- candidatePremiseId: candidate.candidatePremiseId,
12
- candidateIntentId: candidate.candidateIntentId,
13
- sourceContextId: candidate.sourceContextId,
14
- candidateContextId: candidate.candidateContextId,
15
- payload: candidate.candidatePayload,
16
- summary: candidate.candidateSummary,
17
- assertionText: candidate.candidatePremiseId ? candidate.candidatePayload : undefined,
18
- };
19
- }
20
- export function withCandidateEvidence(candidate) {
21
- return { ...candidate, evidence: [buildCandidateEvidence(candidate)] };
22
- }
23
- export function mergeOpportunityEvidence(...groups) {
24
- const byKey = new Map();
25
- for (const evidence of groups.flatMap((group) => group ?? [])) {
26
- const key = [
27
- evidence.kind,
28
- evidence.networkId,
29
- evidence.sourcePremiseId ?? '',
30
- evidence.candidatePremiseId ?? '',
31
- evidence.candidateIntentId ?? '',
32
- evidence.sourceContextId ?? '',
33
- evidence.candidateContextId ?? '',
34
- evidence.lens ?? '',
35
- ].join('|');
36
- const existing = byKey.get(key);
37
- if (!existing || (evidence.score ?? 0) > (existing.score ?? 0))
38
- byKey.set(key, evidence);
39
- }
40
- return Array.from(byKey.values());
41
- }
42
- export function withMatchedStrategies(evidence, strategies) {
43
- return evidence.map((item) => ({
44
- ...item,
45
- matchedStrategies: Array.from(new Set([...(item.matchedStrategies ?? []), ...strategies])),
46
- }));
47
- }
48
- export function renderOpportunityEvidenceForPrompt(evidence) {
49
- if (evidence.length === 0)
50
- return ' —';
51
- return evidence.map((item) => {
52
- const refs = [
53
- item.sourcePremiseId ? `sourcePremise=${item.sourcePremiseId}` : undefined,
54
- item.candidatePremiseId ? `candidatePremise=${item.candidatePremiseId}` : undefined,
55
- item.candidateIntentId ? `candidateIntent=${item.candidateIntentId}` : undefined,
56
- item.sourceContextId ? `sourceContext=${item.sourceContextId}` : undefined,
57
- item.candidateContextId ? `candidateContext=${item.candidateContextId}` : undefined,
58
- item.matchedStrategies?.length ? `strategies=${item.matchedStrategies.join(',')}` : undefined,
59
- ].filter(Boolean).join(', ');
60
- const text = item.summary ?? item.payload ?? item.assertionText ?? '';
61
- // IND-567 Fix B: when a query_premise entry has no text, warn the evaluator
62
- // so it does not treat a high RAG score as domain confirmation.
63
- // (text should be populated by Fix A; this fallback fires if the DB fetch
64
- // failed or the adapter omitted getPremise).
65
- const domainCaution = (item.kind === 'query_premise' && !text)
66
- ? ' [premise text unavailable — do NOT infer domain match from RAG score alone; verify domain alignment from profile]'
67
- : (item.kind === 'query_context' && !text)
68
- ? ' [context text unavailable — do NOT infer domain match from RAG score alone; verify domain alignment from profile]'
69
- : '';
70
- return ` - ${item.kind} on ${item.networkId} via ${item.lens ?? 'unknown'} score=${item.score?.toFixed(3) ?? '—'}${refs ? ` (${refs})` : ''}${text ? `: ${text}` : ''}${domainCaution}`;
71
- }).join('\n');
72
- }
73
- function resolveEvidenceKind(candidate) {
74
- if (candidate.discoverySource === 'premise-similarity')
75
- return 'premise_similarity';
76
- if (candidate.discoverySource === 'context-similarity')
77
- return 'context_similarity';
78
- if (candidate.discoverySource === 'context-to-intent')
79
- return 'context_to_intent';
80
- if (candidate.candidatePremiseId)
81
- return 'query_premise';
82
- if (candidate.candidateContextId)
83
- return 'query_context';
84
- if (candidate.candidateIntentId)
85
- return 'query_intent';
86
- return 'profile';
87
- }