@indexnetwork/protocol 4.3.3-rc.308.1 → 4.3.4-rc.310.1

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 (136) hide show
  1. package/IMPLEMENTATION.md +2 -2
  2. package/dist/chat/chat.agent.d.ts +1 -1
  3. package/dist/chat/chat.agent.d.ts.map +1 -1
  4. package/dist/chat/chat.agent.js +12 -2
  5. package/dist/chat/chat.agent.js.map +1 -1
  6. package/dist/chat/chat.graph.d.ts +16 -0
  7. package/dist/chat/chat.graph.d.ts.map +1 -1
  8. package/dist/chat/chat.graph.js +5 -2
  9. package/dist/chat/chat.graph.js.map +1 -1
  10. package/dist/chat/chat.prompt.d.ts.map +1 -1
  11. package/dist/chat/chat.prompt.js +44 -37
  12. package/dist/chat/chat.prompt.js.map +1 -1
  13. package/dist/chat/chat.prompt.modules.js +8 -8
  14. package/dist/chat/chat.prompt.modules.js.map +1 -1
  15. package/dist/chat/chat.state.d.ts +7 -4
  16. package/dist/chat/chat.state.d.ts.map +1 -1
  17. package/dist/chat/chat.state.js +12 -3
  18. package/dist/chat/chat.state.js.map +1 -1
  19. package/dist/chat/chat.streamer.d.ts +5 -0
  20. package/dist/chat/chat.streamer.d.ts.map +1 -1
  21. package/dist/chat/chat.streamer.js +13 -4
  22. package/dist/chat/chat.streamer.js.map +1 -1
  23. package/dist/chat/tests/chat.graph.mocks.d.ts +1 -1
  24. package/dist/chat/tests/chat.graph.mocks.js +1 -1
  25. package/dist/chat/tests/chat.graph.mocks.js.map +1 -1
  26. package/dist/contact/contact.tools.js +6 -6
  27. package/dist/contact/contact.tools.js.map +1 -1
  28. package/dist/enrichment/enrichment.tools.d.ts.map +1 -1
  29. package/dist/enrichment/enrichment.tools.js +23 -26
  30. package/dist/enrichment/enrichment.tools.js.map +1 -1
  31. package/dist/index.d.ts +1 -1
  32. package/dist/index.d.ts.map +1 -1
  33. package/dist/index.js +1 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/integration/integration.tools.js +1 -1
  36. package/dist/integration/integration.tools.js.map +1 -1
  37. package/dist/intent/intent.graph.d.ts.map +1 -1
  38. package/dist/intent/intent.graph.js +9 -9
  39. package/dist/intent/intent.graph.js.map +1 -1
  40. package/dist/intent/intent.indexer.d.ts +1 -1
  41. package/dist/intent/intent.indexer.js +4 -4
  42. package/dist/intent/intent.indexer.js.map +1 -1
  43. package/dist/intent/intent.state.d.ts +8 -8
  44. package/dist/intent/intent.state.js +8 -8
  45. package/dist/intent/intent.state.js.map +1 -1
  46. package/dist/intent/intent.tools.d.ts.map +1 -1
  47. package/dist/intent/intent.tools.js +87 -70
  48. package/dist/intent/intent.tools.js.map +1 -1
  49. package/dist/maintenance/maintenance.graph.d.ts +2 -2
  50. package/dist/maintenance/maintenance.graph.d.ts.map +1 -1
  51. package/dist/maintenance/maintenance.graph.js.map +1 -1
  52. package/dist/mcp/mcp.server.d.ts +5 -7
  53. package/dist/mcp/mcp.server.d.ts.map +1 -1
  54. package/dist/mcp/mcp.server.js +11 -20
  55. package/dist/mcp/mcp.server.js.map +1 -1
  56. package/dist/negotiation/negotiation.tools.d.ts.map +1 -1
  57. package/dist/negotiation/negotiation.tools.js +11 -7
  58. package/dist/negotiation/negotiation.tools.js.map +1 -1
  59. package/dist/network/indexer/indexer.graph.d.ts +2 -2
  60. package/dist/network/indexer/indexer.graph.d.ts.map +1 -1
  61. package/dist/network/indexer/indexer.graph.js +13 -13
  62. package/dist/network/indexer/indexer.graph.js.map +1 -1
  63. package/dist/network/indexer/indexer.state.d.ts +3 -3
  64. package/dist/network/indexer/indexer.state.d.ts.map +1 -1
  65. package/dist/network/indexer/indexer.state.js +4 -4
  66. package/dist/network/indexer/indexer.state.js.map +1 -1
  67. package/dist/network/membership/membership.graph.d.ts +1 -1
  68. package/dist/network/membership/membership.graph.js +21 -21
  69. package/dist/network/membership/membership.graph.js.map +1 -1
  70. package/dist/network/membership/membership.state.d.ts +2 -2
  71. package/dist/network/membership/membership.state.js +2 -2
  72. package/dist/network/membership/membership.state.js.map +1 -1
  73. package/dist/network/network.graph.d.ts +1 -1
  74. package/dist/network/network.graph.d.ts.map +1 -1
  75. package/dist/network/network.graph.js +13 -13
  76. package/dist/network/network.graph.js.map +1 -1
  77. package/dist/network/network.state.d.ts +3 -3
  78. package/dist/network/network.state.d.ts.map +1 -1
  79. package/dist/network/network.state.js +3 -3
  80. package/dist/network/network.state.js.map +1 -1
  81. package/dist/network/network.tools.js +68 -68
  82. package/dist/network/network.tools.js.map +1 -1
  83. package/dist/opportunity/opportunity.discover.d.ts +1 -1
  84. package/dist/opportunity/opportunity.discover.d.ts.map +1 -1
  85. package/dist/opportunity/opportunity.discover.js +1 -1
  86. package/dist/opportunity/opportunity.discover.js.map +1 -1
  87. package/dist/opportunity/opportunity.graph.js +11 -11
  88. package/dist/opportunity/opportunity.graph.js.map +1 -1
  89. package/dist/opportunity/opportunity.introducer.d.ts +3 -3
  90. package/dist/opportunity/opportunity.introducer.d.ts.map +1 -1
  91. package/dist/opportunity/opportunity.introducer.js +2 -2
  92. package/dist/opportunity/opportunity.introducer.js.map +1 -1
  93. package/dist/opportunity/opportunity.state.d.ts +1 -1
  94. package/dist/opportunity/opportunity.state.js +1 -1
  95. package/dist/opportunity/opportunity.state.js.map +1 -1
  96. package/dist/opportunity/opportunity.tools.d.ts.map +1 -1
  97. package/dist/opportunity/opportunity.tools.js +43 -47
  98. package/dist/opportunity/opportunity.tools.js.map +1 -1
  99. package/dist/premise/premise.indexer.d.ts +1 -1
  100. package/dist/premise/premise.indexer.js +5 -5
  101. package/dist/premise/premise.indexer.js.map +1 -1
  102. package/dist/questioner/questioner.tools.d.ts +1 -1
  103. package/dist/questioner/questioner.tools.d.ts.map +1 -1
  104. package/dist/questioner/questioner.tools.js +5 -6
  105. package/dist/questioner/questioner.tools.js.map +1 -1
  106. package/dist/shared/agent/tool.factory.d.ts +1 -1
  107. package/dist/shared/agent/tool.factory.d.ts.map +1 -1
  108. package/dist/shared/agent/tool.factory.js +10 -11
  109. package/dist/shared/agent/tool.factory.js.map +1 -1
  110. package/dist/shared/agent/tool.helpers.d.ts +6 -6
  111. package/dist/shared/agent/tool.helpers.d.ts.map +1 -1
  112. package/dist/shared/agent/tool.helpers.js +2 -2
  113. package/dist/shared/agent/tool.helpers.js.map +1 -1
  114. package/dist/shared/agent/tool.registry.js +1 -1
  115. package/dist/shared/agent/tool.registry.js.map +1 -1
  116. package/dist/shared/agent/tool.scope.d.ts +12 -0
  117. package/dist/shared/agent/tool.scope.d.ts.map +1 -1
  118. package/dist/shared/agent/tool.scope.js +14 -0
  119. package/dist/shared/agent/tool.scope.js.map +1 -1
  120. package/dist/shared/agent/utility.tools.js +20 -20
  121. package/dist/shared/agent/utility.tools.js.map +1 -1
  122. package/dist/shared/interfaces/auth.interface.d.ts +3 -3
  123. package/dist/shared/interfaces/auth.interface.js.map +1 -1
  124. package/dist/shared/interfaces/database.interface.d.ts +59 -59
  125. package/dist/shared/interfaces/database.interface.d.ts.map +1 -1
  126. package/dist/shared/interfaces/database.interface.js.map +1 -1
  127. package/dist/shared/interfaces/discovery-run.interface.d.ts +1 -1
  128. package/dist/shared/interfaces/discovery-run.interface.d.ts.map +1 -1
  129. package/dist/shared/interfaces/discovery-run.interface.js.map +1 -1
  130. package/dist/shared/interfaces/embedder.interface.d.ts +2 -2
  131. package/dist/shared/interfaces/embedder.interface.d.ts.map +1 -1
  132. package/dist/shared/interfaces/embedder.interface.js.map +1 -1
  133. package/dist/shared/interfaces/enrichment-run.interface.d.ts +1 -1
  134. package/dist/shared/interfaces/enrichment-run.interface.d.ts.map +1 -1
  135. package/dist/shared/interfaces/enrichment-run.interface.js.map +1 -1
  136. package/package.json +1 -1
@@ -2,7 +2,7 @@
2
2
  * Introducer Discovery: proactive discovery of connector-flow opportunities
3
3
  * between a user's contacts.
4
4
  *
5
- * Selects top-N contacts from the user's personal index and runs scoped
5
+ * Selects top-N contacts from the user's personal network and runs scoped
6
6
  * HyDE discovery for each, creating latent introducer opportunities that
7
7
  * the user (as introducer) must approve before parties see them.
8
8
  */
@@ -22,9 +22,9 @@ export interface ContactWithIntents {
22
22
  }
23
23
  /** Database methods needed for introducer discovery contact selection. */
24
24
  export interface IntroducerDiscoveryDatabase {
25
- /** Get the user's personal index ID. */
25
+ /** Get the user's personal network ID. */
26
26
  getPersonalIndexId(userId: string): Promise<string | null>;
27
- /** Get contacts from a personal index with their intent freshness data. */
27
+ /** Get contacts from a personal network with their intent freshness data. */
28
28
  getContactsWithIntentFreshness(personalIndexId: string, ownerId: string, limit: number): Promise<ContactWithIntents[]>;
29
29
  }
30
30
  /** Queue interface for enqueuing introducer discovery jobs. */
@@ -1 +1 @@
1
- {"version":3,"file":"opportunity.introducer.d.ts","sourceRoot":"/","sources":["opportunity/opportunity.introducer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,0DAA0D;AAC1D,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC,mDAAmD;AACnD,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAE5C,sEAAsE;AACtE,eAAO,MAAM,2BAA2B,EAAG,sBAA+B,CAAC;AAE3E,oFAAoF;AACpF,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,iDAAiD;IACjD,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,0EAA0E;AAC1E,MAAM,WAAW,2BAA2B;IAC1C,wCAAwC;IACxC,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAAC;IAC3D,2EAA2E;IAC3E,8BAA8B,CAC5B,eAAe,EAAE,MAAM,EACvB,OAAO,EAAE,MAAM,EACf,KAAK,EAAE,MAAM,GACZ,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAAC;CAClC;AAED,+DAA+D;AAC/D,MAAM,WAAW,wBAAwB;IACvC,MAAM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H,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,2BAA2B,EACrC,KAAK,EAAE,wBAAwB,EAC/B,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,yBAAyB,CAAC,CAoDpC"}
@@ -2,7 +2,7 @@
2
2
  * Introducer Discovery: proactive discovery of connector-flow opportunities
3
3
  * between a user's contacts.
4
4
  *
5
- * Selects top-N contacts from the user's personal index and runs scoped
5
+ * Selects top-N contacts from the user's personal network and runs scoped
6
6
  * HyDE discovery for each, creating latent introducer opportunities that
7
7
  * the user (as introducer) must approve before parties see them.
8
8
  */
@@ -26,7 +26,7 @@ export const INTRODUCER_DISCOVERY_SOURCE = 'introducer_discovery';
26
26
  export async function selectContactsForDiscovery(database, userId, limit = MAX_CONTACTS_PER_CYCLE) {
27
27
  const personalIndexId = await database.getPersonalIndexId(userId);
28
28
  if (!personalIndexId) {
29
- logger.verbose(`[IntroducerDiscovery] No personal index found — userId=${userId}`);
29
+ logger.verbose(`[IntroducerDiscovery] No personal network found — userId=${userId}`);
30
30
  return [];
31
31
  }
32
32
  const contacts = await database.getContactsWithIntentFreshness(personalIndexId, userId, limit);
@@ -1 +1 @@
1
- {"version":3,"file":"opportunity.introducer.js","sourceRoot":"/","sources":["opportunity/opportunity.introducer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAC;AAE5E,MAAM,MAAM,GAAG,cAAc,CAAC,qBAAqB,CAAC,CAAC;AAErD,0DAA0D;AAC1D,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAExC,mDAAmD;AACnD,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC;AAE5C,sEAAsE;AACtE,MAAM,CAAC,MAAM,2BAA2B,GAAG,sBAA+B,CAAC;AAsC3E;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,QAAqC,EACrC,MAAc,EACd,QAAgB,sBAA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C,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;YAC/E,MAAM,CAAC,KAAK,CAAC,6CAA6C,MAAM,EAAE,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IACD,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,WAAW,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;IAEvF,MAAM,CAAC,IAAI,CAAC,2DAA2D,MAAM,sBAAsB,QAAQ,CAAC,MAAM,iBAAiB,YAAY,EAAE,CAAC,CAAC;IAEnJ,OAAO,EAAE,iBAAiB,EAAE,QAAQ,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC;AAC9D,CAAC","sourcesContent":["/**\n * Introducer Discovery: proactive discovery of connector-flow opportunities\n * between a user's contacts.\n *\n * Selects top-N contacts from the user's personal index and runs scoped\n * HyDE discovery for each, creating latent introducer opportunities that\n * the user (as introducer) must approve before parties see them.\n */\n\nimport { protocolLogger } from '../shared/observability/protocol.logger.js';\n\nconst logger = protocolLogger('IntroducerDiscovery');\n\n/** Maximum contacts to evaluate per maintenance cycle. */\nexport const MAX_CONTACTS_PER_CYCLE = 5;\n\n/** Maximum candidate opportunities per contact. */\nexport const MAX_CANDIDATES_PER_CONTACT = 3;\n\n/** Detection source value for introducer-discovered opportunities. */\nexport const INTRODUCER_DISCOVERY_SOURCE = 'introducer_discovery' as const;\n\n/** A contact with their active intents, used for introducer discovery selection. */\nexport interface ContactWithIntents {\n userId: string;\n /** Most recent intent updatedAt timestamp (ISO string or null). */\n latestIntentAt: string | null;\n /** Number of active intents this contact has. */\n intentCount: number;\n}\n\n/** Database methods needed for introducer discovery contact selection. */\nexport interface IntroducerDiscoveryDatabase {\n /** Get the user's personal index ID. */\n getPersonalIndexId(userId: string): Promise<string | null>;\n /** Get contacts from a personal index with their intent freshness data. */\n getContactsWithIntentFreshness(\n personalIndexId: string,\n ownerId: string,\n limit: number,\n ): Promise<ContactWithIntents[]>;\n}\n\n/** Queue interface for enqueuing introducer discovery jobs. */\nexport interface IntroducerDiscoveryQueue {\n addJob(\n data: { intentId: string; userId: string; indexIds?: string[]; contactUserId?: string },\n options?: { priority?: number; jobId?: string },\n ): Promise<unknown>;\n}\n\n/** Result of a single introducer discovery cycle. */\nexport interface IntroducerDiscoveryResult {\n contactsEvaluated: number;\n jobsEnqueued: number;\n skippedReason?: string;\n}\n\n/**\n * Select top-N contacts for introducer discovery, sorted by intent freshness.\n * Contacts with no active intents are excluded.\n *\n * @param database - Database adapter with contact/intent queries\n * @param userId - The introducer user\n * @param limit - Max contacts to return (default MAX_CONTACTS_PER_CYCLE)\n * @returns Sorted contacts with intent data\n */\nexport async function selectContactsForDiscovery(\n database: IntroducerDiscoveryDatabase,\n userId: string,\n limit: number = MAX_CONTACTS_PER_CYCLE,\n): Promise<ContactWithIntents[]> {\n const personalIndexId = await database.getPersonalIndexId(userId);\n if (!personalIndexId) {\n logger.verbose(`[IntroducerDiscovery] No personal index found — userId=${userId}`);\n return [];\n }\n\n const contacts = await database.getContactsWithIntentFreshness(\n personalIndexId,\n userId,\n limit,\n );\n\n logger.verbose(`[IntroducerDiscovery] Selected contacts for discovery — userId=${userId} totalContacts=${contacts.length} limit=${limit}`);\n\n return contacts;\n}\n\n/**\n * Determine whether introducer discovery should run based on the current\n * connector-flow composition. Triggers when connector-flow count is below\n * the soft target.\n *\n * @param connectorFlowCount - Current number of connector-flow opportunities\n * @param connectorFlowTarget - Soft target (default 2)\n * @returns Whether introducer discovery should run\n */\nexport function shouldRunIntroducerDiscovery(\n connectorFlowCount: number,\n connectorFlowTarget: number = 2,\n): boolean {\n return connectorFlowCount < connectorFlowTarget;\n}\n\n/**\n * Run introducer discovery for a user: select contacts, enqueue discovery jobs.\n * Each job uses onBehalfOfUserId so the opportunity graph treats the user as introducer.\n *\n * @param database - Database adapter for contact queries\n * @param queue - Queue for enqueuing discovery jobs\n * @param userId - The introducer user\n * @returns Summary of the discovery cycle\n */\nexport async function runIntroducerDiscovery(\n database: IntroducerDiscoveryDatabase,\n queue: IntroducerDiscoveryQueue,\n userId: string,\n): Promise<IntroducerDiscoveryResult> {\n const personalIndexId = await database.getPersonalIndexId(userId);\n if (!personalIndexId) {\n return { contactsEvaluated: 0, jobsEnqueued: 0, skippedReason: 'no_personal_index' };\n }\n\n const contacts = await selectContactsForDiscovery(database, userId);\n if (contacts.length === 0) {\n return { contactsEvaluated: 0, jobsEnqueued: 0, skippedReason: 'no_contacts' };\n }\n\n const bucket = Math.floor(Date.now() / (12 * 60 * 60 * 1000)); // 12h dedup bucket\n\n const results = await Promise.allSettled(\n contacts.map(async (contact) => {\n // For each contact, we enqueue a discovery job using one of their intents\n // The opportunity graph will use onBehalfOfUserId to discover on behalf of the contact\n // while the userId (introducer) gets the introducer role\n const jobId = `introducer-discovery-${userId}-${contact.userId}-${bucket}`;\n try {\n await queue.addJob(\n {\n intentId: `introducer:${contact.userId}`,\n userId,\n indexIds: [personalIndexId],\n contactUserId: contact.userId,\n },\n { priority: 15, jobId }, // Lower priority than regular rediscovery (10)\n );\n return true;\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n if (/duplicate|already exists|job.*id/i.test(message)) {\n logger.verbose(`[IntroducerDiscovery] Job skipped (duplicate) — userId=${userId} contactUserId=${contact.userId} error=${message}`);\n return false;\n }\n throw err;\n }\n }),\n );\n\n for (const r of results) {\n if (r.status === 'rejected') {\n const errMsg = r.reason instanceof Error ? r.reason.message : String(r.reason);\n logger.error(`[IntroducerDiscovery] Job enqueue failed: ${errMsg}`);\n }\n }\n const jobsEnqueued = results.filter((r) => r.status === 'fulfilled' && r.value).length;\n\n logger.info(`[IntroducerDiscovery] Discovery cycle complete — userId=${userId} contactsEvaluated=${contacts.length} jobsEnqueued=${jobsEnqueued}`);\n\n return { contactsEvaluated: contacts.length, jobsEnqueued };\n}\n"]}
1
+ {"version":3,"file":"op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AC,MAAM,CAAC,GAAG,CAAC,CAAC;YACjE,IAAI,mCAAmC,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;gBACtD,MAAM,CAAC,OAAO,CAAC,0DAA0D,MAAM,kBAAkB,OAAO,CAAC,MAAM,UAAU,OAAO,EAAE,CAAC,CAAC;gBACpI,OAAO,KAAK,CAAC;YACf,CAAC;YACD,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC,CAAC,CACH,CAAC;IAEF,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACxB,IAAI,CAAC,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;YAC5B,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;YAC/E,MAAM,CAAC,KAAK,CAAC,6CAA6C,MAAM,EAAE,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IACD,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,WAAW,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;IAEvF,MAAM,CAAC,IAAI,CAAC,2DAA2D,MAAM,sBAAsB,QAAQ,CAAC,MAAM,iBAAiB,YAAY,EAAE,CAAC,CAAC;IAEnJ,OAAO,EAAE,iBAAiB,EAAE,QAAQ,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC;AAC9D,CAAC","sourcesContent":["/**\n * Introducer Discovery: proactive discovery of connector-flow opportunities\n * between a user's contacts.\n *\n * Selects top-N contacts from the user's personal network and runs scoped\n * HyDE discovery for each, creating latent introducer opportunities that\n * the user (as introducer) must approve before parties see them.\n */\n\nimport { protocolLogger } from '../shared/observability/protocol.logger.js';\n\nconst logger = protocolLogger('IntroducerDiscovery');\n\n/** Maximum contacts to evaluate per maintenance cycle. */\nexport const MAX_CONTACTS_PER_CYCLE = 5;\n\n/** Maximum candidate opportunities per contact. */\nexport const MAX_CANDIDATES_PER_CONTACT = 3;\n\n/** Detection source value for introducer-discovered opportunities. */\nexport const INTRODUCER_DISCOVERY_SOURCE = 'introducer_discovery' as const;\n\n/** A contact with their active intents, used for introducer discovery selection. */\nexport interface ContactWithIntents {\n userId: string;\n /** Most recent intent updatedAt timestamp (ISO string or null). */\n latestIntentAt: string | null;\n /** Number of active intents this contact has. */\n intentCount: number;\n}\n\n/** Database methods needed for introducer discovery contact selection. */\nexport interface IntroducerDiscoveryDatabase {\n /** Get the user's personal network ID. */\n getPersonalIndexId(userId: string): Promise<string | null>;\n /** Get contacts from a personal network with their intent freshness data. */\n getContactsWithIntentFreshness(\n personalIndexId: string,\n ownerId: string,\n limit: number,\n ): Promise<ContactWithIntents[]>;\n}\n\n/** Queue interface for enqueuing introducer discovery jobs. */\nexport interface IntroducerDiscoveryQueue {\n addJob(\n data: { intentId: string; userId: string; indexIds?: string[]; contactUserId?: string },\n options?: { priority?: number; jobId?: string },\n ): Promise<unknown>;\n}\n\n/** Result of a single introducer discovery cycle. */\nexport interface IntroducerDiscoveryResult {\n contactsEvaluated: number;\n jobsEnqueued: number;\n skippedReason?: string;\n}\n\n/**\n * Select top-N contacts for introducer discovery, sorted by intent freshness.\n * Contacts with no active intents are excluded.\n *\n * @param database - Database adapter with contact/intent queries\n * @param userId - The introducer user\n * @param limit - Max contacts to return (default MAX_CONTACTS_PER_CYCLE)\n * @returns Sorted contacts with intent data\n */\nexport async function selectContactsForDiscovery(\n database: IntroducerDiscoveryDatabase,\n userId: string,\n limit: number = MAX_CONTACTS_PER_CYCLE,\n): Promise<ContactWithIntents[]> {\n const personalIndexId = await database.getPersonalIndexId(userId);\n if (!personalIndexId) {\n logger.verbose(`[IntroducerDiscovery] No personal network found — userId=${userId}`);\n return [];\n }\n\n const contacts = await database.getContactsWithIntentFreshness(\n personalIndexId,\n userId,\n limit,\n );\n\n logger.verbose(`[IntroducerDiscovery] Selected contacts for discovery — userId=${userId} totalContacts=${contacts.length} limit=${limit}`);\n\n return contacts;\n}\n\n/**\n * Determine whether introducer discovery should run based on the current\n * connector-flow composition. Triggers when connector-flow count is below\n * the soft target.\n *\n * @param connectorFlowCount - Current number of connector-flow opportunities\n * @param connectorFlowTarget - Soft target (default 2)\n * @returns Whether introducer discovery should run\n */\nexport function shouldRunIntroducerDiscovery(\n connectorFlowCount: number,\n connectorFlowTarget: number = 2,\n): boolean {\n return connectorFlowCount < connectorFlowTarget;\n}\n\n/**\n * Run introducer discovery for a user: select contacts, enqueue discovery jobs.\n * Each job uses onBehalfOfUserId so the opportunity graph treats the user as introducer.\n *\n * @param database - Database adapter for contact queries\n * @param queue - Queue for enqueuing discovery jobs\n * @param userId - The introducer user\n * @returns Summary of the discovery cycle\n */\nexport async function runIntroducerDiscovery(\n database: IntroducerDiscoveryDatabase,\n queue: IntroducerDiscoveryQueue,\n userId: string,\n): Promise<IntroducerDiscoveryResult> {\n const personalIndexId = await database.getPersonalIndexId(userId);\n if (!personalIndexId) {\n return { contactsEvaluated: 0, jobsEnqueued: 0, skippedReason: 'no_personal_index' };\n }\n\n const contacts = await selectContactsForDiscovery(database, userId);\n if (contacts.length === 0) {\n return { contactsEvaluated: 0, jobsEnqueued: 0, skippedReason: 'no_contacts' };\n }\n\n const bucket = Math.floor(Date.now() / (12 * 60 * 60 * 1000)); // 12h dedup bucket\n\n const results = await Promise.allSettled(\n contacts.map(async (contact) => {\n // For each contact, we enqueue a discovery job using one of their intents\n // The opportunity graph will use onBehalfOfUserId to discover on behalf of the contact\n // while the userId (introducer) gets the introducer role\n const jobId = `introducer-discovery-${userId}-${contact.userId}-${bucket}`;\n try {\n await queue.addJob(\n {\n intentId: `introducer:${contact.userId}`,\n userId,\n indexIds: [personalIndexId],\n contactUserId: contact.userId,\n },\n { priority: 15, jobId }, // Lower priority than regular rediscovery (10)\n );\n return true;\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n if (/duplicate|already exists|job.*id/i.test(message)) {\n logger.verbose(`[IntroducerDiscovery] Job skipped (duplicate) — userId=${userId} contactUserId=${contact.userId} error=${message}`);\n return false;\n }\n throw err;\n }\n }),\n );\n\n for (const r of results) {\n if (r.status === 'rejected') {\n const errMsg = r.reason instanceof Error ? r.reason.message : String(r.reason);\n logger.error(`[IntroducerDiscovery] Job enqueue failed: ${errMsg}`);\n }\n }\n const jobsEnqueued = results.filter((r) => r.status === 'fulfilled' && r.value).length;\n\n logger.info(`[IntroducerDiscovery] Discovery cycle complete — userId=${userId} contactsEvaluated=${contacts.length} jobsEnqueued=${jobsEnqueued}`);\n\n return { contactsEvaluated: contacts.length, jobsEnqueued };\n}\n"]}
@@ -171,7 +171,7 @@ export declare const OpportunityGraphState: import("@langchain/langgraph").Annot
171
171
  networkId: import("@langchain/langgraph").BaseChannel<Id<"networks"> | undefined, Id<"networks"> | import("@langchain/langgraph").OverwriteValue<Id<"networks"> | undefined> | undefined, unknown>;
172
172
  /**
173
173
  * Optional set of indexes discovery may search within (e.g. a network-scoped
174
- * agent's reachable indexes: the bound network plus the user's personal index).
174
+ * agent's reachable networks: the bound network plus the user's personal network).
175
175
  * The scope node intersects this with the user's actual memberships. Ignored
176
176
  * when `networkId` is set (single-network override). When unset, discovery
177
177
  * spans all of the user's networks.
@@ -40,7 +40,7 @@ export const OpportunityGraphState = Annotation.Root({
40
40
  }),
41
41
  /**
42
42
  * Optional set of indexes discovery may search within (e.g. a network-scoped
43
- * agent's reachable indexes: the bound network plus the user's personal index).
43
+ * agent's reachable networks: the bound network plus the user's personal network).
44
44
  * The scope node intersects this with the user's actual memberships. Ignored
45
45
  * when `networkId` is set (single-network override). When unset, discovery
46
46
  * spans all of the user's networks.
@@ -1 +1 @@
1
- {"version":3,"file":"opportunity.state.js","sourceRoot":"/","sources":["opportunity/opportunity.state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAA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AAU,CAOX;QACb,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI;QAC7B,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS;KACzB,CAAC;IAEF,uBAAuB;IAEvB;;;;OAIG;IACH,KAAK,EAAE,UAAU,CAA2E;QAC1F,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QACnD,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE;KAClB,CAAC;IAEF,sEAAsE;IACtE,YAAY,EAAE,UAAU,CAAmB;QACzC,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,CAAC;QACvC,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE;KAClB,CAAC;IAEF;;;;;;;;OAQG;IACH,qBAAqB,EAAE,UAAU,CAAyB;QACxD,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QACnD,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE;KAClB,CAAC;IAEF,sFAAsF;IACtF,gBAAgB,EAAE,UAAU,CAA0B;QACpD,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,IAAI;QACtC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI;KACpB,CAAC;CACH,CAAC,CAAC","sourcesContent":["import { Annotation } from \"@langchain/langgraph\";\nimport type { Id } from '../shared/interfaces/database.interface.js';\nimport type { OpportunityStatus, Opportunity } from '../shared/interfaces/database.interface.js';\nimport type { Lens } from '../shared/interfaces/embedder.interface.js';\nimport type { EvaluatorEntity } from './opportunity.evaluator.js';\nimport type { DebugMetaAgent } from '../chat/chat-streaming.types.js';\nimport type { OpportunityEvidence } from '../shared/schemas/network-assignment.schema.js';\nimport type { DiscoveryNegotiation, DiscoverySummary } from \"./question.prompt.js\";\n\n/**\n * Opportunity Graph State (Linear Multi-Step Workflow)\n * \n * Flow: Prep → Scope → Discovery → Evaluation → Ranking → Persist → END\n * \n * Following the intent graph pattern with Annotation-based state management.\n */\n\n/** Asker's profile shape (identity + context). Used by sourceProfile annotation. */\nexport interface SourceProfileData {\n identity?: { name?: string; bio?: string; location?: string };\n context?: string;\n}\n\n/**\n * Indexed intent with hyde document (from prep node)\n */\nexport interface IndexedIntent {\n intentId: Id<'intents'>;\n payload: string;\n summary?: string;\n hydeDocumentId?: string;\n hydeEmbedding?: number[];\n indexes: Id<'networks'>[];\n}\n\n/**\n * Target index for search (from scope node)\n */\nexport interface TargetNetwork {\n networkId: Id<'networks'>;\n title: string;\n memberCount: number;\n}\n\n/**\n * Candidate match from discovery (semantic search).\n */\nexport interface CandidateMatch {\n candidateUserId: Id<'users'>;\n candidateIntentId?: Id<'intents'>;\n /** Source premise that produced this candidate (set when discoverySource is 'premise-similarity'). */\n sourcePremiseId?: Id<'premises'>;\n /** Candidate premise that matched this candidate (set for premise-based matches). */\n candidatePremiseId?: Id<'premises'>;\n /** Source context that produced this candidate (set when discoverySource is 'context-to-intent'). */\n sourceContextId?: string;\n networkId: Id<'networks'>;\n similarity: number;\n /** Free-text lens label that produced this match. */\n lens: string;\n candidatePayload: string;\n candidateSummary?: string;\n /** How this candidate was found: 'query' (HyDE from search text), 'premise-similarity', or 'context-to-intent'. */\n discoverySource?: 'query' | 'premise-similarity' | 'context-to-intent';\n /** Which discovery strategies found this candidate (set by mergeStrategyCandidates). */\n matchedStrategies?: string[];\n /** Typed evidence that explains why this candidate entered evaluation. */\n evidence?: OpportunityEvidence[];\n}\n\n/**\n * Evaluated candidate with LLM scoring (legacy; used when evaluator returns source/candidate pair).\n * candidateIntentId is set for intent matches; omitted for profile-only matches.\n */\nexport interface EvaluatedCandidate {\n sourceUserId: Id<'users'>;\n candidateUserId: Id<'users'>;\n sourceIntentId?: Id<'intents'>;\n candidateIntentId?: Id<'intents'>;\n networkId: Id<'networks'>;\n score: number; // 0-100\n reasoning: string; // Third-party analytical explanation of the match (for LLM agents)\n valencyRole: 'Agent' | 'Patient' | 'Peer';\n /** Free-text lens label that produced this match. */\n lens: string;\n}\n\n/**\n * Actor in an evaluated opportunity (from entity-bundle evaluator).\n * networkId is filled from the entity bundle in the graph, not by the evaluator.\n */\nexport interface EvaluatedOpportunityActor {\n userId: Id<'users'>;\n role: 'agent' | 'patient' | 'peer';\n intentId?: Id<'intents'>;\n networkId: Id<'networks'>;\n}\n\n/**\n * Evaluated opportunity with multi-actor output (entity-bundle evaluator).\n */\nexport interface EvaluatedOpportunity {\n actors: EvaluatedOpportunityActor[];\n score: number;\n reasoning: string;\n evidence?: OpportunityEvidence[];\n}\n\n/**\n * Which flow triggered this graph invocation. Determines initial persist status,\n * park-window timeout, streaming behavior, and whether AbortSignal is honored.\n *\n * - 'ambient' (default): queue-driven. Persists at the trigger default of\n * `pending` unless `options.initialStatus` overrides (the queue worker\n * passes `'latent'`, chat-bound ambient discovery passes `'draft'`). 5-min\n * park window, no streaming, ignores abort.\n * - 'orchestrator': chat-driven. Persists at the trigger default of\n * `negotiating` unless `options.initialStatus` overrides. 60s park window,\n * streams `opportunity_draft_ready` events, honors abort.\n *\n * See {@link resolveInitialStatus} for the exact fallback used when\n * `options.initialStatus` is undefined.\n */\nexport type OpportunityTrigger = 'ambient' | 'orchestrator';\n\n/**\n * Resolves the initial status for opportunities created in the persist node.\n *\n * Explicit `options.initialStatus` always wins (callers like the chat tool or\n * maintenance scripts override per-call). When the caller leaves it\n * undefined, the trigger drives the default:\n * - 'orchestrator' → 'negotiating' (chat-driven; negotiations run before the\n * user sees a draft card).\n * - 'ambient' (or any other trigger) → 'pending' (long-standing default for\n * queue- and intent-driven discovery).\n *\n * Lives here rather than in opportunity.graph.ts so unit tests can exercise\n * it without pulling in the full graph (and the evaluator's LLM requirements).\n *\n * @param trigger - The graph invocation's trigger\n * @param explicit - Caller-supplied initial status from options.initialStatus\n */\nexport function resolveInitialStatus(\n trigger: OpportunityTrigger,\n explicit: OpportunityStatus | undefined,\n): OpportunityStatus {\n if (explicit !== undefined) return explicit;\n return trigger === 'orchestrator' ? 'negotiating' : 'pending';\n}\n\n/**\n * Options passed to the graph\n */\nexport interface OpportunityGraphOptions {\n /** Initial status for created opportunities (default: 'pending') */\n initialStatus?: OpportunityStatus;\n /** Minimum score threshold (default: 50) */\n minScore?: number;\n /** Maximum opportunities to return (default: 20) */\n limit?: number;\n /** Pre-inferred lenses (if not provided, lens inference runs automatically in HyDE graph) */\n lenses?: Lens[];\n /** User's search query for HyDE generation */\n hydeDescription?: string;\n /** Existing opportunities summary for evaluator deduplication */\n existingOpportunities?: string;\n /** Chat session ID for draft opportunities; stored as context.conversationId for visibility filtering. */\n conversationId?: string;\n /**\n * MCP-only: cap the negotiate-phase wall-clock at this many milliseconds.\n * When set, `negotiateNode` races `negotiateCandidates(...)` against a timer;\n * if the timer wins, the node returns early with a `timed_out` trace and the\n * unawaited negotiation chains finalize each opp's DB status in the\n * background. Set to 20_000 by the MCP `discover_opportunities` handler.\n * Chat, ambient queue, and all other callers omit this — existing behavior.\n */\n negotiateTimeoutMs?: number;\n}\n\n/**\n * Opportunity Graph State Annotation\n */\nexport const OpportunityGraphState = Annotation.Root({\n // ─── Input Fields (Required) ───\n userId: Annotation<Id<'users'>>({\n reducer: (curr, next) => next ?? curr,\n default: () => '' as Id<'users'>,\n }),\n \n searchQuery: Annotation<string | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n \n networkId: Annotation<Id<'networks'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /**\n * Optional set of indexes discovery may search within (e.g. a network-scoped\n * agent's reachable indexes: the bound network plus the user's personal index).\n * The scope node intersects this with the user's actual memberships. Ignored\n * when `networkId` is set (single-network override). When unset, discovery\n * spans all of the user's networks.\n */\n indexScope: Annotation<Id<'networks'>[] | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Optional intent to use as discovery source and for triggeredBy. When set, used for search text (if query empty) and persist. */\n triggerIntentId: Annotation<Id<'intents'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Optional: restrict discovery to this specific user ID only (direct connection). */\n targetUserId: Annotation<Id<'users'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Optional: discover on behalf of this user (introducer flow). When set, prep/eval use this user's profile/intents; userId becomes the introducer. */\n onBehalfOfUserId: Annotation<Id<'users'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n options: Annotation<OpportunityGraphOptions>({\n reducer: (curr, next) => next ?? curr,\n default: () => ({}),\n }),\n\n /**\n * Which flow triggered this graph invocation. See {@link OpportunityTrigger}\n * for the exact branch behavior and {@link resolveInitialStatus} for the\n * persist default when `options.initialStatus` is unset.\n *\n * - 'ambient' (default): queue-driven, persist default `pending`, 5-min\n * park window, no streaming, ignores abort.\n * - 'orchestrator': chat-driven, persist default `negotiating`, 60s park\n * window, streams `opportunity_draft_ready` events, honors abort.\n */\n trigger: Annotation<OpportunityTrigger>({\n reducer: (curr, next) => next ?? curr,\n default: () => 'ambient',\n }),\n\n /**\n * Accepted opportunities the persist node discovered between the discoverer\n * and a candidate actor (same pair, status='accepted'). The orchestrator\n * branch populates this so the discover_opportunities tool (Task 7) can tell\n * the LLM \"these pairs are already connected, surface the existing chat\n * rather than creating a new draft\". Always empty for the ambient trigger.\n *\n * Left intentionally minimal — conversationId/URL resolution happens at\n * Start Chat time (Task 8), not here.\n */\n dedupAlreadyAccepted: Annotation<Array<{\n opportunityId: string;\n counterpartyUserId: string;\n }>>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /**\n * Operation mode controls graph flow:\n * - 'create': Existing discover pipeline (Prep → Scope → Discovery → Evaluation → Ranking → Persist)\n * - 'create_introduction': Introduction path (validation → evaluation → persist) for chat-driven intros\n * - 'continue_discovery': Pagination path (Prep → Evaluation → Ranking → Persist) using pre-loaded candidates\n * - 'read': List opportunities filtered by userId and optionally networkId (fast path)\n * - 'update': Change opportunity status (accept, reject, etc.)\n * - 'delete': Expire/archive an opportunity\n * - 'send': Promote latent opportunity to pending + queue notification\n * - 'negotiate_existing': Load an existing opportunity by opportunityId and run bilateral negotiation.\n * Used after introducer approval to trigger the normal negotiation flow.\n * - 'approve_introduction': Mark the caller as having approved a latent introducer opportunity,\n * then enqueue a negotiate_existing job for that opportunity.\n *\n * Defaults to 'create' for backward compatibility.\n */\n operationMode: Annotation<'create' | 'create_introduction' | 'continue_discovery' | 'read' | 'update' | 'delete' | 'send' | 'negotiate_existing' | 'approve_introduction'>({\n reducer: (curr, next) => next ?? curr,\n default: () => 'create' as const,\n }),\n\n /** Introduction mode: pre-gathered entities (profiles + intents per party). */\n introductionEntities: Annotation<EvaluatorEntity[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Introduction mode: optional hint from the introducer. */\n introductionHint: Annotation<string | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** When set (e.g. chat scope), networkId must match this. */\n requiredNetworkId: Annotation<Id<'networks'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Set by intro_evaluation; used by persist to build manual detection and introducer actor. */\n introductionContext: Annotation<{ createdByName?: string } | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Target opportunity ID for update/delete/send modes. */\n opportunityId: Annotation<string | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** New status for update mode (e.g. 'accepted', 'rejected'). */\n newStatus: Annotation<string | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n \n // ─── Intermediate Fields (Accumulated) ───\n \n /** User's indexed intents with hyde documents (from prep) */\n indexedIntents: Annotation<IndexedIntent[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n \n /** User's network memberships (from prep) */\n userNetworks: Annotation<Id<'networks'>[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n \n /** Target indexes to search within (from scope) */\n targetNetworks: Annotation<TargetNetwork[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Per-index relevancy scores for dedup tie-breaking. Background path: from intent_indexes. Chat path: transient from IntentIndexer. */\n indexRelevancyScores: Annotation<Record<string, number>>({\n reducer: (curr, next) => next ?? curr,\n default: () => ({}),\n }),\n\n /** Whether discovery used intent (path A) or user context (path B/C). Used by persist for triggeredBy. In-memory routing state only; never persisted. */\n discoverySource: Annotation<'intent' | 'context'>({\n reducer: (curr, next) => next ?? curr,\n default: () => 'intent',\n }),\n\n /** Resolved intent ID used for this discovery run (when discoverySource is 'intent'). Set by intent-resolution. */\n resolvedTriggerIntentId: Annotation<Id<'intents'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Asker's profile (from prep). Used for profile-as-source discovery and evaluation. */\n sourceProfile: Annotation<SourceProfileData | null>({\n reducer: (curr, next) => next ?? curr,\n default: () => null,\n }),\n\n /** User's active premises with embeddings (from prep). Used for premise-to-premise discovery path D. */\n sourcePremises: Annotation<Array<{ premiseId: Id<'premises'>; embedding: number[] }>>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** User context embeddings per network (from prep). Used for context-to-intent discovery. */\n sourceContexts: Annotation<Array<{ contextId: string; networkId: Id<'networks'>; embedding: number[] }>>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Resolved intent is in at least one target index (path A vs C). */\n resolvedIntentInIndex: Annotation<boolean>({\n reducer: (curr, next) => next ?? curr,\n default: () => false,\n }),\n\n /** Create-intent signal: when true, tool should return createIntentSuggested so agent can auto-call create_intent. */\n createIntentSuggested: Annotation<boolean>({\n reducer: (curr, next) => next ?? curr,\n default: () => false,\n }),\n\n /** Suggested description for create_intent when createIntentSuggested is true. */\n suggestedIntentDescription: Annotation<string | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** HyDE embeddings per lens label (from discovery) */\n hydeEmbeddings: Annotation<Record<string, number[]>>({\n reducer: (curr, next) => next ?? curr,\n default: () => ({}),\n }),\n \n /** Candidate matches from semantic search (from discovery) */\n candidates: Annotation<CandidateMatch[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Candidates not yet evaluated (for pagination -- cached in Redis by caller). */\n remainingCandidates: Annotation<CandidateMatch[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Discovery session ID for pagination (maps to Redis cache key). */\n discoveryId: Annotation<string | null>({\n reducer: (curr, next) => next ?? curr,\n default: () => null,\n }),\n\n /** Evaluated candidates with scores (from evaluation; legacy) */\n evaluatedCandidates: Annotation<EvaluatedCandidate[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Evaluated opportunities with actors (from entity-bundle evaluator) */\n evaluatedOpportunities: Annotation<EvaluatedOpportunity[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n \n // ─── Output Fields (Overwrite per turn) ───\n \n /** Final ranked and persisted opportunities */\n opportunities: Annotation<Opportunity[]>({\n reducer: (curr, next) => next,\n default: () => [],\n }),\n\n /** Discovery path: pairs skipped because an opportunity already exists between viewer and candidate (no duplicate created). */\n existingBetweenActors: Annotation<Array<{\n candidateUserId: Id<'users'>;\n networkId: Id<'networks'>;\n existingOpportunityId?: Id<'opportunities'>;\n existingStatus?: OpportunityStatus;\n }>>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n \n /** Error message if any step fails */\n error: Annotation<string | undefined>({\n reducer: (curr, next) => next,\n default: () => undefined,\n }),\n\n /** Output for read mode: enriched list of opportunities. */\n readResult: Annotation<{\n count: number;\n message?: string;\n opportunities: Array<{\n id: string;\n indexName: string;\n connectedWith: string[];\n suggestedBy: string | null;\n reasoning: string;\n status: string;\n category: string;\n confidence: number | null;\n source: string | null;\n }>;\n } | undefined>({\n reducer: (curr, next) => next,\n default: () => undefined,\n }),\n\n /** Output for update/delete/send modes. */\n mutationResult: Annotation<{\n success: boolean;\n message?: string;\n opportunityId?: string;\n notified?: string[];\n conversationId?: string;\n error?: string;\n } | undefined>({\n reducer: (curr, next) => next,\n default: () => undefined,\n }),\n\n // ─── Trace Output ───\n\n /**\n * Accumulated trace entries from each graph node.\n * Used for observability: surfaces internal processing steps (search query, HyDE strategies,\n * candidates found, evaluation results) to the frontend.\n */\n trace: Annotation<Array<{ node: string; detail?: string; data?: Record<string, unknown> }>>({\n reducer: (curr, next) => [...curr, ...(next || [])],\n default: () => [],\n }),\n\n /** Timing records for each agent invocation within this graph run. */\n agentTimings: Annotation<DebugMetaAgent[]>({\n reducer: (acc, val) => [...acc, ...val],\n default: () => [],\n }),\n\n /**\n * Per-candidate negotiation records captured by `negotiateNode`. Populated\n * regardless of accept/reject so the question generator sees a complete\n * picture. Populated for ALL triggers (ambient + orchestrator) since the\n * negotiate node's `onCandidateResolved` hook is unconditional; only the\n * orchestrator streaming side-effects (opportunity_draft_ready emission)\n * are trigger-gated. Empty when the negotiate node was skipped (no\n * opportunities to negotiate).\n */\n discoveryNegotiations: Annotation<DiscoveryNegotiation[]>({\n reducer: (curr, next) => [...curr, ...(next || [])],\n default: () => [],\n }),\n\n /** Aggregate counters across `discoveryNegotiations`. Built in the negotiate node. */\n discoverySummary: Annotation<DiscoverySummary | null>({\n reducer: (_curr, next) => next ?? null,\n default: () => null,\n }),\n});\n"]}
1
+ {"version":3,"file":"opportunity.state.js","sourceRoot":"/","sources":["opportunity/opportunity.state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AA6HlD;;;;;;;;;;;;;;;;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E,IAAI,EAAE,EAAE,CAAC,IAAI;QAC7B,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS;KACzB,CAAC;IAEF,uBAAuB;IAEvB;;;;OAIG;IACH,KAAK,EAAE,UAAU,CAA2E;QAC1F,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QACnD,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE;KAClB,CAAC;IAEF,sEAAsE;IACtE,YAAY,EAAE,UAAU,CAAmB;QACzC,OAAO,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,GAAG,CAAC;QACvC,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE;KAClB,CAAC;IAEF;;;;;;;;OAQG;IACH,qBAAqB,EAAE,UAAU,CAAyB;QACxD,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QACnD,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE;KAClB,CAAC;IAEF,sFAAsF;IACtF,gBAAgB,EAAE,UAAU,CAA0B;QACpD,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,IAAI;QACtC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI;KACpB,CAAC;CACH,CAAC,CAAC","sourcesContent":["import { Annotation } from \"@langchain/langgraph\";\nimport type { Id } from '../shared/interfaces/database.interface.js';\nimport type { OpportunityStatus, Opportunity } from '../shared/interfaces/database.interface.js';\nimport type { Lens } from '../shared/interfaces/embedder.interface.js';\nimport type { EvaluatorEntity } from './opportunity.evaluator.js';\nimport type { DebugMetaAgent } from '../chat/chat-streaming.types.js';\nimport type { OpportunityEvidence } from '../shared/schemas/network-assignment.schema.js';\nimport type { DiscoveryNegotiation, DiscoverySummary } from \"./question.prompt.js\";\n\n/**\n * Opportunity Graph State (Linear Multi-Step Workflow)\n *\n * Flow: Prep → Scope → Discovery → Evaluation → Ranking → Persist → END\n *\n * Following the intent graph pattern with Annotation-based state management.\n */\n\n/** Asker's profile shape (identity + context). Used by sourceProfile annotation. */\nexport interface SourceProfileData {\n identity?: { name?: string; bio?: string; location?: string };\n context?: string;\n}\n\n/**\n * Indexed intent with hyde document (from prep node)\n */\nexport interface IndexedIntent {\n intentId: Id<'intents'>;\n payload: string;\n summary?: string;\n hydeDocumentId?: string;\n hydeEmbedding?: number[];\n indexes: Id<'networks'>[];\n}\n\n/**\n * Target index for search (from scope node)\n */\nexport interface TargetNetwork {\n networkId: Id<'networks'>;\n title: string;\n memberCount: number;\n}\n\n/**\n * Candidate match from discovery (semantic search).\n */\nexport interface CandidateMatch {\n candidateUserId: Id<'users'>;\n candidateIntentId?: Id<'intents'>;\n /** Source premise that produced this candidate (set when discoverySource is 'premise-similarity'). */\n sourcePremiseId?: Id<'premises'>;\n /** Candidate premise that matched this candidate (set for premise-based matches). */\n candidatePremiseId?: Id<'premises'>;\n /** Source context that produced this candidate (set when discoverySource is 'context-to-intent'). */\n sourceContextId?: string;\n networkId: Id<'networks'>;\n similarity: number;\n /** Free-text lens label that produced this match. */\n lens: string;\n candidatePayload: string;\n candidateSummary?: string;\n /** How this candidate was found: 'query' (HyDE from search text), 'premise-similarity', or 'context-to-intent'. */\n discoverySource?: 'query' | 'premise-similarity' | 'context-to-intent';\n /** Which discovery strategies found this candidate (set by mergeStrategyCandidates). */\n matchedStrategies?: string[];\n /** Typed evidence that explains why this candidate entered evaluation. */\n evidence?: OpportunityEvidence[];\n}\n\n/**\n * Evaluated candidate with LLM scoring (legacy; used when evaluator returns source/candidate pair).\n * candidateIntentId is set for intent matches; omitted for profile-only matches.\n */\nexport interface EvaluatedCandidate {\n sourceUserId: Id<'users'>;\n candidateUserId: Id<'users'>;\n sourceIntentId?: Id<'intents'>;\n candidateIntentId?: Id<'intents'>;\n networkId: Id<'networks'>;\n score: number; // 0-100\n reasoning: string; // Third-party analytical explanation of the match (for LLM agents)\n valencyRole: 'Agent' | 'Patient' | 'Peer';\n /** Free-text lens label that produced this match. */\n lens: string;\n}\n\n/**\n * Actor in an evaluated opportunity (from entity-bundle evaluator).\n * networkId is filled from the entity bundle in the graph, not by the evaluator.\n */\nexport interface EvaluatedOpportunityActor {\n userId: Id<'users'>;\n role: 'agent' | 'patient' | 'peer';\n intentId?: Id<'intents'>;\n networkId: Id<'networks'>;\n}\n\n/**\n * Evaluated opportunity with multi-actor output (entity-bundle evaluator).\n */\nexport interface EvaluatedOpportunity {\n actors: EvaluatedOpportunityActor[];\n score: number;\n reasoning: string;\n evidence?: OpportunityEvidence[];\n}\n\n/**\n * Which flow triggered this graph invocation. Determines initial persist status,\n * park-window timeout, streaming behavior, and whether AbortSignal is honored.\n *\n * - 'ambient' (default): queue-driven. Persists at the trigger default of\n * `pending` unless `options.initialStatus` overrides (the queue worker\n * passes `'latent'`, chat-bound ambient discovery passes `'draft'`). 5-min\n * park window, no streaming, ignores abort.\n * - 'orchestrator': chat-driven. Persists at the trigger default of\n * `negotiating` unless `options.initialStatus` overrides. 60s park window,\n * streams `opportunity_draft_ready` events, honors abort.\n *\n * See {@link resolveInitialStatus} for the exact fallback used when\n * `options.initialStatus` is undefined.\n */\nexport type OpportunityTrigger = 'ambient' | 'orchestrator';\n\n/**\n * Resolves the initial status for opportunities created in the persist node.\n *\n * Explicit `options.initialStatus` always wins (callers like the chat tool or\n * maintenance scripts override per-call). When the caller leaves it\n * undefined, the trigger drives the default:\n * - 'orchestrator' → 'negotiating' (chat-driven; negotiations run before the\n * user sees a draft card).\n * - 'ambient' (or any other trigger) → 'pending' (long-standing default for\n * queue- and intent-driven discovery).\n *\n * Lives here rather than in opportunity.graph.ts so unit tests can exercise\n * it without pulling in the full graph (and the evaluator's LLM requirements).\n *\n * @param trigger - The graph invocation's trigger\n * @param explicit - Caller-supplied initial status from options.initialStatus\n */\nexport function resolveInitialStatus(\n trigger: OpportunityTrigger,\n explicit: OpportunityStatus | undefined,\n): OpportunityStatus {\n if (explicit !== undefined) return explicit;\n return trigger === 'orchestrator' ? 'negotiating' : 'pending';\n}\n\n/**\n * Options passed to the graph\n */\nexport interface OpportunityGraphOptions {\n /** Initial status for created opportunities (default: 'pending') */\n initialStatus?: OpportunityStatus;\n /** Minimum score threshold (default: 50) */\n minScore?: number;\n /** Maximum opportunities to return (default: 20) */\n limit?: number;\n /** Pre-inferred lenses (if not provided, lens inference runs automatically in HyDE graph) */\n lenses?: Lens[];\n /** User's search query for HyDE generation */\n hydeDescription?: string;\n /** Existing opportunities summary for evaluator deduplication */\n existingOpportunities?: string;\n /** Chat session ID for draft opportunities; stored as context.conversationId for visibility filtering. */\n conversationId?: string;\n /**\n * MCP-only: cap the negotiate-phase wall-clock at this many milliseconds.\n * When set, `negotiateNode` races `negotiateCandidates(...)` against a timer;\n * if the timer wins, the node returns early with a `timed_out` trace and the\n * unawaited negotiation chains finalize each opp's DB status in the\n * background. Set to 20_000 by the MCP `discover_opportunities` handler.\n * Chat, ambient queue, and all other callers omit this — existing behavior.\n */\n negotiateTimeoutMs?: number;\n}\n\n/**\n * Opportunity Graph State Annotation\n */\nexport const OpportunityGraphState = Annotation.Root({\n // ─── Input Fields (Required) ───\n userId: Annotation<Id<'users'>>({\n reducer: (curr, next) => next ?? curr,\n default: () => '' as Id<'users'>,\n }),\n\n searchQuery: Annotation<string | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n networkId: Annotation<Id<'networks'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /**\n * Optional set of indexes discovery may search within (e.g. a network-scoped\n * agent's reachable networks: the bound network plus the user's personal network).\n * The scope node intersects this with the user's actual memberships. Ignored\n * when `networkId` is set (single-network override). When unset, discovery\n * spans all of the user's networks.\n */\n indexScope: Annotation<Id<'networks'>[] | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Optional intent to use as discovery source and for triggeredBy. When set, used for search text (if query empty) and persist. */\n triggerIntentId: Annotation<Id<'intents'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Optional: restrict discovery to this specific user ID only (direct connection). */\n targetUserId: Annotation<Id<'users'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Optional: discover on behalf of this user (introducer flow). When set, prep/eval use this user's profile/intents; userId becomes the introducer. */\n onBehalfOfUserId: Annotation<Id<'users'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n options: Annotation<OpportunityGraphOptions>({\n reducer: (curr, next) => next ?? curr,\n default: () => ({}),\n }),\n\n /**\n * Which flow triggered this graph invocation. See {@link OpportunityTrigger}\n * for the exact branch behavior and {@link resolveInitialStatus} for the\n * persist default when `options.initialStatus` is unset.\n *\n * - 'ambient' (default): queue-driven, persist default `pending`, 5-min\n * park window, no streaming, ignores abort.\n * - 'orchestrator': chat-driven, persist default `negotiating`, 60s park\n * window, streams `opportunity_draft_ready` events, honors abort.\n */\n trigger: Annotation<OpportunityTrigger>({\n reducer: (curr, next) => next ?? curr,\n default: () => 'ambient',\n }),\n\n /**\n * Accepted opportunities the persist node discovered between the discoverer\n * and a candidate actor (same pair, status='accepted'). The orchestrator\n * branch populates this so the discover_opportunities tool (Task 7) can tell\n * the LLM \"these pairs are already connected, surface the existing chat\n * rather than creating a new draft\". Always empty for the ambient trigger.\n *\n * Left intentionally minimal — conversationId/URL resolution happens at\n * Start Chat time (Task 8), not here.\n */\n dedupAlreadyAccepted: Annotation<Array<{\n opportunityId: string;\n counterpartyUserId: string;\n }>>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /**\n * Operation mode controls graph flow:\n * - 'create': Existing discover pipeline (Prep → Scope → Discovery → Evaluation → Ranking → Persist)\n * - 'create_introduction': Introduction path (validation → evaluation → persist) for chat-driven intros\n * - 'continue_discovery': Pagination path (Prep → Evaluation → Ranking → Persist) using pre-loaded candidates\n * - 'read': List opportunities filtered by userId and optionally networkId (fast path)\n * - 'update': Change opportunity status (accept, reject, etc.)\n * - 'delete': Expire/archive an opportunity\n * - 'send': Promote latent opportunity to pending + queue notification\n * - 'negotiate_existing': Load an existing opportunity by opportunityId and run bilateral negotiation.\n * Used after introducer approval to trigger the normal negotiation flow.\n * - 'approve_introduction': Mark the caller as having approved a latent introducer opportunity,\n * then enqueue a negotiate_existing job for that opportunity.\n *\n * Defaults to 'create' for backward compatibility.\n */\n operationMode: Annotation<'create' | 'create_introduction' | 'continue_discovery' | 'read' | 'update' | 'delete' | 'send' | 'negotiate_existing' | 'approve_introduction'>({\n reducer: (curr, next) => next ?? curr,\n default: () => 'create' as const,\n }),\n\n /** Introduction mode: pre-gathered entities (profiles + intents per party). */\n introductionEntities: Annotation<EvaluatorEntity[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Introduction mode: optional hint from the introducer. */\n introductionHint: Annotation<string | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** When set (e.g. chat scope), networkId must match this. */\n requiredNetworkId: Annotation<Id<'networks'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Set by intro_evaluation; used by persist to build manual detection and introducer actor. */\n introductionContext: Annotation<{ createdByName?: string } | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Target opportunity ID for update/delete/send modes. */\n opportunityId: Annotation<string | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** New status for update mode (e.g. 'accepted', 'rejected'). */\n newStatus: Annotation<string | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n // ─── Intermediate Fields (Accumulated) ───\n\n /** User's indexed intents with hyde documents (from prep) */\n indexedIntents: Annotation<IndexedIntent[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** User's network memberships (from prep) */\n userNetworks: Annotation<Id<'networks'>[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Target indexes to search within (from scope) */\n targetNetworks: Annotation<TargetNetwork[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Per-index relevancy scores for dedup tie-breaking. Background path: from intent_indexes. Chat path: transient from IntentIndexer. */\n indexRelevancyScores: Annotation<Record<string, number>>({\n reducer: (curr, next) => next ?? curr,\n default: () => ({}),\n }),\n\n /** Whether discovery used intent (path A) or user context (path B/C). Used by persist for triggeredBy. In-memory routing state only; never persisted. */\n discoverySource: Annotation<'intent' | 'context'>({\n reducer: (curr, next) => next ?? curr,\n default: () => 'intent',\n }),\n\n /** Resolved intent ID used for this discovery run (when discoverySource is 'intent'). Set by intent-resolution. */\n resolvedTriggerIntentId: Annotation<Id<'intents'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Asker's profile (from prep). Used for profile-as-source discovery and evaluation. */\n sourceProfile: Annotation<SourceProfileData | null>({\n reducer: (curr, next) => next ?? curr,\n default: () => null,\n }),\n\n /** User's active premises with embeddings (from prep). Used for premise-to-premise discovery path D. */\n sourcePremises: Annotation<Array<{ premiseId: Id<'premises'>; embedding: number[] }>>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** User context embeddings per network (from prep). Used for context-to-intent discovery. */\n sourceContexts: Annotation<Array<{ contextId: string; networkId: Id<'networks'>; embedding: number[] }>>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Resolved intent is in at least one target index (path A vs C). */\n resolvedIntentInIndex: Annotation<boolean>({\n reducer: (curr, next) => next ?? curr,\n default: () => false,\n }),\n\n /** Create-intent signal: when true, tool should return createIntentSuggested so agent can auto-call create_intent. */\n createIntentSuggested: Annotation<boolean>({\n reducer: (curr, next) => next ?? curr,\n default: () => false,\n }),\n\n /** Suggested description for create_intent when createIntentSuggested is true. */\n suggestedIntentDescription: Annotation<string | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** HyDE embeddings per lens label (from discovery) */\n hydeEmbeddings: Annotation<Record<string, number[]>>({\n reducer: (curr, next) => next ?? curr,\n default: () => ({}),\n }),\n\n /** Candidate matches from semantic search (from discovery) */\n candidates: Annotation<CandidateMatch[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Candidates not yet evaluated (for pagination -- cached in Redis by caller). */\n remainingCandidates: Annotation<CandidateMatch[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Discovery session ID for pagination (maps to Redis cache key). */\n discoveryId: Annotation<string | null>({\n reducer: (curr, next) => next ?? curr,\n default: () => null,\n }),\n\n /** Evaluated candidates with scores (from evaluation; legacy) */\n evaluatedCandidates: Annotation<EvaluatedCandidate[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Evaluated opportunities with actors (from entity-bundle evaluator) */\n evaluatedOpportunities: Annotation<EvaluatedOpportunity[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n // ─── Output Fields (Overwrite per turn) ───\n\n /** Final ranked and persisted opportunities */\n opportunities: Annotation<Opportunity[]>({\n reducer: (curr, next) => next,\n default: () => [],\n }),\n\n /** Discovery path: pairs skipped because an opportunity already exists between viewer and candidate (no duplicate created). */\n existingBetweenActors: Annotation<Array<{\n candidateUserId: Id<'users'>;\n networkId: Id<'networks'>;\n existingOpportunityId?: Id<'opportunities'>;\n existingStatus?: OpportunityStatus;\n }>>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Error message if any step fails */\n error: Annotation<string | undefined>({\n reducer: (curr, next) => next,\n default: () => undefined,\n }),\n\n /** Output for read mode: enriched list of opportunities. */\n readResult: Annotation<{\n count: number;\n message?: string;\n opportunities: Array<{\n id: string;\n indexName: string;\n connectedWith: string[];\n suggestedBy: string | null;\n reasoning: string;\n status: string;\n category: string;\n confidence: number | null;\n source: string | null;\n }>;\n } | undefined>({\n reducer: (curr, next) => next,\n default: () => undefined,\n }),\n\n /** Output for update/delete/send modes. */\n mutationResult: Annotation<{\n success: boolean;\n message?: string;\n opportunityId?: string;\n notified?: string[];\n conversationId?: string;\n error?: string;\n } | undefined>({\n reducer: (curr, next) => next,\n default: () => undefined,\n }),\n\n // ─── Trace Output ───\n\n /**\n * Accumulated trace entries from each graph node.\n * Used for observability: surfaces internal processing steps (search query, HyDE strategies,\n * candidates found, evaluation results) to the frontend.\n */\n trace: Annotation<Array<{ node: string; detail?: string; data?: Record<string, unknown> }>>({\n reducer: (curr, next) => [...curr, ...(next || [])],\n default: () => [],\n }),\n\n /** Timing records for each agent invocation within this graph run. */\n agentTimings: Annotation<DebugMetaAgent[]>({\n reducer: (acc, val) => [...acc, ...val],\n default: () => [],\n }),\n\n /**\n * Per-candidate negotiation records captured by `negotiateNode`. Populated\n * regardless of accept/reject so the question generator sees a complete\n * picture. Populated for ALL triggers (ambient + orchestrator) since the\n * negotiate node's `onCandidateResolved` hook is unconditional; only the\n * orchestrator streaming side-effects (opportunity_draft_ready emission)\n * are trigger-gated. Empty when the negotiate node was skipped (no\n * opportunities to negotiate).\n */\n discoveryNegotiations: Annotation<DiscoveryNegotiation[]>({\n reducer: (curr, next) => [...curr, ...(next || [])],\n default: () => [],\n }),\n\n /** Aggregate counters across `discoveryNegotiations`. Built in the negotiate node. */\n discoverySummary: Annotation<DiscoverySummary | null>({\n reducer: (_curr, next) => next ?? null,\n default: () => null,\n }),\n});\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"opportunity.tools.d.ts","sourceRoot":"/","sources":["opportunity/opportunity.tools.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AA+B5E,OAAO,KAAK,EAAE,WAAW,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CAAC,GAAG;IACnD,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,IAAI,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC1B,QAAQ,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACnC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,SAAS,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC/B,UAAU,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAChC,6EAA6E;IAC7E,cAAc,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACpC,KAAK,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,yEAAyE;IACzE,UAAU,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;CAClC,CAAC;AAEF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,mBAAmB,EAAE,EAC5B,IAAI,EAAE;IACJ,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,aAAa,GAAG,eAAe,CAAC;IACxC,8FAA8F;IAC9F,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,GACA,MAAM,CA2DR;AAuDD;;;;;;;;;GASG;AACH,MAAM,MAAM,wBAAwB,GAChC,iBAAiB,GACjB,oBAAoB,GACpB,wBAAwB,GACxB,uBAAuB,GACvB,gBAAgB,GAChB,gBAAgB,CAAC;AAUrB,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,2CA8uD5E"}
@@ -1,7 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { requestContext } from "../shared/observability/request-context.js";
3
3
  import { success, error, UUID_REGEX } from "../shared/agent/tool.helpers.js";
4
- import { deriveDiscoveryNetworkIds } from "../shared/agent/tool.scope.js";
4
+ import { deriveDiscoveryNetworkIds, focusedNetworkId, focusedNetworkLabel } from "../shared/agent/tool.scope.js";
5
5
  import { MINIMAL_MAIN_TEXT_MAX_CHARS, getPrimaryActionLabel, SECONDARY_ACTION_LABEL } from "./opportunity.labels.js";
6
6
  import { viewerCentricCardSummary, narratorRemarkFromReasoning, stripUuids } from "./opportunity.presentation.js";
7
7
  import { runDiscoverFromQuery, continueDiscovery } from "./opportunity.discover.js";
@@ -354,7 +354,7 @@ export function buildOpportunityPresentation(cards, opts) {
354
354
  * Encoded as JSON of a normalized object — NOT a delimiter join — so a
355
355
  * user-supplied string containing the delimiter can never make two distinct
356
356
  * requests collide. `hint` and each entity's `networkId` are included because
357
- * they change the discovery result (different reason / different shared index),
357
+ * they change the discovery result (different reason / different shared network),
358
358
  * so requests that differ only in those must NOT coalesce. Natural-language
359
359
  * fields (`searchQuery`, `hint`) are lowercased; identifiers and the opaque
360
360
  * `continueFrom` pagination token are only trimmed (case-sensitive) so distinct
@@ -386,17 +386,13 @@ function discoveryRunSignature(input, scopeKey) {
386
386
  * coalesce only when they resolve to the same focused discovery boundary. For
387
387
  * scoped contexts, that boundary is the scope envelope (`scopeType`/`scopeId`),
388
388
  * not the personal-inclusive allowed network reach used for self-owned writes.
389
- * When no scope envelope is present, legacy `indexScope` remains part of the
390
- * key so older contexts with different unscoped reach do not coalesce.
389
+ * Unscoped requests intentionally share a single empty-scope key; concrete
390
+ * allowed reach is derived from memberships at execution time.
391
391
  */
392
392
  function discoveryScopeKey(ctx) {
393
393
  return JSON.stringify({
394
- networkId: (ctx.networkId ?? "").trim(),
395
394
  scopeType: (ctx.scopeType ?? "").trim(),
396
395
  scopeId: (ctx.scopeId ?? "").trim(),
397
- indexScope: ctx.scopeType && ctx.scopeId
398
- ? []
399
- : [...(ctx.indexScope ?? [])].map((s) => s.trim()).sort(),
400
396
  });
401
397
  }
402
398
  function confirmDeliveryError(code, retryable, message) {
@@ -418,9 +414,9 @@ export function createOpportunityTools(defineTool, deps) {
418
414
  "Opportunities are the core output of the discovery engine, representing potential valuable connections between people.\n\n" +
419
415
  "**NOT for person lookup** — use read_user_contexts(query=name) to find people by name.\n\n" +
420
416
  "**Four modes:**\n" +
421
- "1. **Discovery** (most common): pass `searchQuery` and/or `networkId`. The system finds other users in shared indexes " +
417
+ "1. **Discovery** (most common): pass `searchQuery` and/or `networkId`. The system finds other users in shared networkes " +
422
418
  "whose intents semantically complement the query. Uses HyDE embeddings and LLM evaluation for scoring.\n" +
423
- "2. **Introduction**: pass `partyUserIds` (2+ user IDs) + `entities` (pre-gathered profiles and intents from shared indexes). " +
419
+ "2. **Introduction**: pass `partyUserIds` (2+ user IDs) + `entities` (pre-gathered profiles and intents from shared networkes). " +
424
420
  "You MUST call read_user_contexts and read_intents for each party BEFORE calling this. " +
425
421
  "Optionally pass `hint` with the user's reason for the introduction.\n" +
426
422
  "3. **Direct connection**: pass `targetUserId` + `searchQuery`. Creates an opportunity between the current user and one specific person.\n" +
@@ -438,13 +434,13 @@ export function createOpportunityTools(defineTool, deps) {
438
434
  "Do NOT call create_intent for these phrasings — create_intent is only for when the user explicitly " +
439
435
  "asks to \"create\", \"save\", \"add\", or \"remember\" a signal.\n\n" +
440
436
  "**Personal-index scoping.** When the user says \"in my network\", \"from my contacts\", \"people I know\", " +
441
- "or similar scoping language, pass the user's personal index ID (from memberships where `isPersonal: true`) " +
442
- "as `networkId`. The personal index contains the user's contacts — scoping discovery to it restricts " +
437
+ "or similar scoping language, pass the user's personal network ID (from memberships where `isPersonal: true`) " +
438
+ "as `networkId`. The personal network contains the user's contacts — scoping discovery to it restricts " +
443
439
  "results to people the user already knows. Without this scoping language, omit networkId to let discovery " +
444
- "run across all indexes.\n\n" +
440
+ "run across all networks.\n\n" +
445
441
  "**Introduction mode prerequisites.** When using `partyUserIds` + `entities`, YOU must pre-fetch each party's " +
446
442
  "profile and intents before calling this tool. The entities array must include each party's userId, profile, " +
447
- "intents from shared indexes, and the shared networkId. Call read_user_contexts, read_network_memberships, " +
443
+ "intents from shared networkes, and the shared networkId. Call read_user_contexts, read_network_memberships, " +
448
444
  "and read_intents for both parties first. The introducer (current user) must NOT appear in entities.\n\n" +
449
445
  "**Signal-visibility follow-up.** If the response includes `suggestIntentCreationForVisibility: true` and " +
450
446
  "`suggestedIntentDescription`, after presenting opportunity cards ask the user ONCE whether they'd also like " +
@@ -463,7 +459,7 @@ export function createOpportunityTools(defineTool, deps) {
463
459
  networkId: z
464
460
  .string()
465
461
  .optional()
466
- .describe("Index UUID to scope discovery to a specific community. Get from read_networks. In an index-scoped chat, omitting this runs discovery only in the scoped community; pass the personal index ID (from read_networks, isPersonal=true) only when the user explicitly asks to discover among contacts."),
462
+ .describe("Network UUID to scope discovery to a specific community. Get from read_networks. In an network-scoped chat, omitting this runs discovery only in the scoped community; pass the personal network ID (from read_networks, isPersonal=true) only when the user explicitly asks to discover among contacts."),
467
463
  intentId: z
468
464
  .string()
469
465
  .optional()
@@ -505,13 +501,13 @@ export function createOpportunityTools(defineTool, deps) {
505
501
  .optional(),
506
502
  networkId: z
507
503
  .string()
508
- .describe("Shared index this entity's data comes from (required for intro mode)"),
504
+ .describe("Shared network this entity's data comes from (required for intro mode)"),
509
505
  }))
510
506
  .optional()
511
507
  .describe("Introduction mode: pre-gathered profile and intent data for each party being introduced. " +
512
- "Each entry needs userId, networkId (the shared index), and optionally profile (name, bio, skills, interests) and intents (intentId, payload). " +
508
+ "Each entry needs userId, networkId (the shared network), and optionally profile (name, bio, skills, interests) and intents (intentId, payload). " +
513
509
  "Gather this data by calling read_user_contexts and read_intents for each party BEFORE calling discover_opportunities. " +
514
- "All entities must share the same networkId (the shared index where both parties are members)."),
510
+ "All entities must share the same networkId (the shared network where both parties are members)."),
515
511
  hint: z
516
512
  .string()
517
513
  .optional()
@@ -519,11 +515,13 @@ export function createOpportunityTools(defineTool, deps) {
519
515
  "'complementary skills for a startup'). Helps the evaluator produce better match reasoning."),
520
516
  }),
521
517
  handler: async ({ context, query }) => {
522
- // Strict scope enforcement: when chat is index-scoped, only allow that index
523
- if (context.networkId &&
518
+ const scopedNetworkId = focusedNetworkId(context);
519
+ const scopedIndexLabel = focusedNetworkLabel(context);
520
+ // Strict scope enforcement: when chat is network-scoped, only allow that index
521
+ if (scopedNetworkId &&
524
522
  query.networkId?.trim() &&
525
- query.networkId.trim() !== context.networkId) {
526
- return error(`This chat is scoped to ${context.indexName ?? "this index"}. You can only create opportunities in this community.`);
523
+ query.networkId.trim() !== scopedNetworkId) {
524
+ return error(`This chat is scoped to ${scopedIndexLabel}. You can only create opportunities in this community.`);
527
525
  }
528
526
  // Distinguish an explicit `query.networkId` override (caller wants discovery
529
527
  // scoped to one specific index) from an implicit scoped-chat context.
@@ -568,10 +566,8 @@ export function createOpportunityTools(defineTool, deps) {
568
566
  userId: context.userId,
569
567
  userName: context.userName,
570
568
  userEmail: context.userEmail,
571
- ...(context.networkId ? { networkId: context.networkId } : {}),
572
- ...(context.scopeType && context.scopeId ? { scopeType: context.scopeType, scopeId: context.scopeId } : {}),
569
+ ...(scopedNetworkId ? { scopeType: 'network', scopeId: scopedNetworkId } : {}),
573
570
  ...(context.indexName ? { indexName: context.indexName } : {}),
574
- indexScope: context.indexScope,
575
571
  ...(context.sessionId ? { sessionId: context.sessionId } : {}),
576
572
  ...(context.agentId ? { agentId: context.agentId } : {}),
577
573
  ...(context.clientSurface ? { clientSurface: context.clientSurface } : {}),
@@ -618,7 +614,7 @@ export function createOpportunityTools(defineTool, deps) {
618
614
  cache,
619
615
  userId: context.userId,
620
616
  discoveryId: query.continueFrom,
621
- expectedIndexId: context.networkId,
617
+ expectedIndexId: scopedNetworkId,
622
618
  limit: 20,
623
619
  presenter: createOpportunityPresenter(),
624
620
  useHomeCardFormat: true,
@@ -733,7 +729,7 @@ export function createOpportunityTools(defineTool, deps) {
733
729
  networkId: primaryNetworkId,
734
730
  introductionEntities: evaluatorEntities,
735
731
  introductionHint: query.hint,
736
- requiredNetworkId: context.networkId ?? undefined,
732
+ requiredNetworkId: scopedNetworkId,
737
733
  options: {
738
734
  initialStatus: "draft",
739
735
  ...(context.sessionId ? { conversationId: context.sessionId } : {}),
@@ -869,7 +865,7 @@ export function createOpportunityTools(defineTool, deps) {
869
865
  }
870
866
  else if (context.scopeType === 'network' && context.scopeId) {
871
867
  // Scoped chat: discovery is focused-network only. Self-owned writes may
872
- // include personal indexes, but opportunity visibility must not.
868
+ // include personal networkes, but opportunity visibility must not.
873
869
  const scopedDiscoveryIds = deriveDiscoveryNetworkIds({
874
870
  memberships: context.userNetworks,
875
871
  scopeType: context.scopeType,
@@ -877,13 +873,12 @@ export function createOpportunityTools(defineTool, deps) {
877
873
  });
878
874
  indexScope = scopedDiscoveryIds;
879
875
  }
880
- else if (context.networkId) {
881
- // Legacy scoped context without a scope envelope: preserve focused-only
882
- // discovery using the focused network id.
883
- indexScope = [context.networkId];
876
+ else if (scopedNetworkId) {
877
+ // Scoped context: preserve focused-only discovery using the scope envelope.
878
+ indexScope = [scopedNetworkId];
884
879
  }
885
880
  else {
886
- // No scope - use all indexes (only in unscoped chat)
881
+ // No scope - use all networks (only in unscoped chat)
887
882
  const _scopeGraphStart = Date.now();
888
883
  const _scopeIndexTraceEmitter = requestContext.getStore()?.traceEmitter;
889
884
  _scopeIndexTraceEmitter?.({ type: "graph_start", name: "index" });
@@ -1294,7 +1289,7 @@ export function createOpportunityTools(defineTool, deps) {
1294
1289
  const listOpportunities = defineTool({
1295
1290
  name: "list_opportunities",
1296
1291
  description: "Lists the authenticated user's actionable opportunities (discovered connections). Returns opportunity cards ready for display.\n\n" +
1297
- "**What are opportunities?** Matches between users whose intents complement each other within shared indexes. " +
1292
+ "**What are opportunities?** Matches between users whose intents complement each other within shared networkes. " +
1298
1293
  "Each opportunity has a status: draft (not yet sent), pending (sent, awaiting response), accepted, rejected, or expired.\n\n" +
1299
1294
  "**What this returns:** Only draft and pending opportunities — the ones the user can still act on. " +
1300
1295
  "Accepted, rejected, and expired ones are not surfaced through this tool.\n\n" +
@@ -1305,22 +1300,22 @@ export function createOpportunityTools(defineTool, deps) {
1305
1300
  networkId: z
1306
1301
  .string()
1307
1302
  .optional()
1308
- .describe("Index UUID to filter opportunities to a specific community. Get from read_networks. Defaults to the scoped index in index-scoped chats. Omit to see opportunities across all indexes."),
1303
+ .describe("Network UUID to filter opportunities to a specific community. Get from read_networks. Defaults to the scoped network in network-scoped chats. Omit to see opportunities across all networks."),
1309
1304
  includeDigestMarkers: z
1310
1305
  .boolean()
1311
1306
  .optional()
1312
1307
  .describe("Internal scheduled-digest mode only. When true, includes hidden delivery markers so the digest send pass can confirm only edited-in opportunities."),
1313
1308
  }),
1314
1309
  handler: async ({ context, query }) => {
1315
- // Strict scope enforcement: when chat is index-scoped, only allow that index
1316
- if (context.networkId &&
1310
+ const scopedNetworkId = focusedNetworkId(context);
1311
+ const scopedIndexLabel = focusedNetworkLabel(context);
1312
+ // Strict scope enforcement: when chat is network-scoped, only allow that index
1313
+ if (scopedNetworkId &&
1317
1314
  query.networkId?.trim() &&
1318
- query.networkId.trim() !== context.networkId) {
1319
- return error("This chat is scoped to " +
1320
- (context.indexName ?? "this index") +
1321
- ". You can only list opportunities from this community.");
1315
+ query.networkId.trim() !== scopedNetworkId) {
1316
+ return error(`This chat is scoped to ${scopedIndexLabel}. You can only list opportunities from this community.`);
1322
1317
  }
1323
- const effectiveIndexId = (context.networkId || query.networkId?.trim()) ?? undefined;
1318
+ const effectiveIndexId = (scopedNetworkId || query.networkId?.trim()) ?? undefined;
1324
1319
  if (effectiveIndexId && !UUID_REGEX.test(effectiveIndexId)) {
1325
1320
  return error("Invalid network ID format.");
1326
1321
  }
@@ -1816,13 +1811,14 @@ export function createOpportunityTools(defineTool, deps) {
1816
1811
  if (UPDATE_OPPORTUNITY_BLOCKED_STATUSES.has(opportunity.status)) {
1817
1812
  return error(`This opportunity is already ${opportunity.status} and cannot be updated.`);
1818
1813
  }
1819
- // Strict scope enforcement: when chat is index-scoped, the caller's own
1814
+ // Strict scope enforcement: when chat is network-scoped, the caller's own
1820
1815
  // actor entry on this opportunity must be anchored on the bound network.
1821
1816
  // Mirrors the per-actor filter in getOpportunitiesForUser — relying on
1822
- // `context.networkId` or any-actor matches would let a counterpart's
1823
- // network presence shadow a viewer whose own actor is elsewhere.
1824
- if (context.networkId) {
1825
- const callerOnBoundNetwork = opportunity.actors?.some((a) => a.userId === context.userId && a.networkId === context.networkId);
1817
+ // a focus-scope id or any-actor matches would let a counterpart's network
1818
+ // presence shadow a viewer whose own actor is elsewhere.
1819
+ const scopedNetworkId = focusedNetworkId(context);
1820
+ if (scopedNetworkId) {
1821
+ const callerOnBoundNetwork = opportunity.actors?.some((a) => a.userId === context.userId && a.networkId === scopedNetworkId);
1826
1822
  if (!callerOnBoundNetwork) {
1827
1823
  return error("Opportunity not found.");
1828
1824
  }