@indexnetwork/protocol 4.16.0-rc.358.1 → 4.17.0-rc.360.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 (66) hide show
  1. package/CHANGELOG.md +8 -1
  2. package/dist/contact/contact.inviter.d.ts.map +1 -1
  3. package/dist/contact/contact.inviter.js +12 -5
  4. package/dist/contact/contact.inviter.js.map +1 -1
  5. package/dist/index.d.ts +3 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +2 -0
  8. package/dist/index.js.map +1 -1
  9. package/dist/opportunity/delivery-card.cache.d.ts.map +1 -1
  10. package/dist/opportunity/delivery-card.cache.js +7 -3
  11. package/dist/opportunity/delivery-card.cache.js.map +1 -1
  12. package/dist/opportunity/discriminator/discriminator.adjustments.d.ts +22 -15
  13. package/dist/opportunity/discriminator/discriminator.adjustments.d.ts.map +1 -1
  14. package/dist/opportunity/discriminator/discriminator.adjustments.js +39 -20
  15. package/dist/opportunity/discriminator/discriminator.adjustments.js.map +1 -1
  16. package/dist/opportunity/feed/feed.categorizer.d.ts.map +1 -1
  17. package/dist/opportunity/feed/feed.categorizer.js +6 -0
  18. package/dist/opportunity/feed/feed.categorizer.js.map +1 -1
  19. package/dist/opportunity/feed/feed.graph.d.ts +2 -0
  20. package/dist/opportunity/feed/feed.graph.d.ts.map +1 -1
  21. package/dist/opportunity/feed/feed.graph.js +53 -28
  22. package/dist/opportunity/feed/feed.graph.js.map +1 -1
  23. package/dist/opportunity/feed/feed.state.d.ts +3 -1
  24. package/dist/opportunity/feed/feed.state.d.ts.map +1 -1
  25. package/dist/opportunity/feed/feed.state.js.map +1 -1
  26. package/dist/opportunity/opportunity.claim-safety.d.ts +25 -0
  27. package/dist/opportunity/opportunity.claim-safety.d.ts.map +1 -0
  28. package/dist/opportunity/opportunity.claim-safety.js +89 -0
  29. package/dist/opportunity/opportunity.claim-safety.js.map +1 -0
  30. package/dist/opportunity/opportunity.discover.d.ts.map +1 -1
  31. package/dist/opportunity/opportunity.discover.js +6 -1
  32. package/dist/opportunity/opportunity.discover.js.map +1 -1
  33. package/dist/opportunity/opportunity.evaluator.d.ts.map +1 -1
  34. package/dist/opportunity/opportunity.evaluator.js +13 -8
  35. package/dist/opportunity/opportunity.evaluator.js.map +1 -1
  36. package/dist/opportunity/opportunity.graph.d.ts +23 -0
  37. package/dist/opportunity/opportunity.graph.d.ts.map +1 -1
  38. package/dist/opportunity/opportunity.graph.js +172 -17
  39. package/dist/opportunity/opportunity.graph.js.map +1 -1
  40. package/dist/opportunity/opportunity.persist.d.ts +8 -1
  41. package/dist/opportunity/opportunity.persist.d.ts.map +1 -1
  42. package/dist/opportunity/opportunity.persist.js +23 -2
  43. package/dist/opportunity/opportunity.persist.js.map +1 -1
  44. package/dist/opportunity/opportunity.presentation-cache.d.ts +7 -0
  45. package/dist/opportunity/opportunity.presentation-cache.d.ts.map +1 -0
  46. package/dist/opportunity/opportunity.presentation-cache.js +15 -0
  47. package/dist/opportunity/opportunity.presentation-cache.js.map +1 -0
  48. package/dist/opportunity/opportunity.presentation.d.ts.map +1 -1
  49. package/dist/opportunity/opportunity.presentation.js +8 -5
  50. package/dist/opportunity/opportunity.presentation.js.map +1 -1
  51. package/dist/opportunity/opportunity.presenter.d.ts +4 -4
  52. package/dist/opportunity/opportunity.presenter.d.ts.map +1 -1
  53. package/dist/opportunity/opportunity.presenter.js +55 -14
  54. package/dist/opportunity/opportunity.presenter.js.map +1 -1
  55. package/dist/opportunity/opportunity.safe-presentation.d.ts +1 -1
  56. package/dist/opportunity/opportunity.safe-presentation.d.ts.map +1 -1
  57. package/dist/opportunity/opportunity.safe-presentation.js +22 -9
  58. package/dist/opportunity/opportunity.safe-presentation.js.map +1 -1
  59. package/dist/opportunity/opportunity.tools.d.ts +1 -17
  60. package/dist/opportunity/opportunity.tools.d.ts.map +1 -1
  61. package/dist/opportunity/opportunity.tools.js +32 -2
  62. package/dist/opportunity/opportunity.tools.js.map +1 -1
  63. package/dist/shared/interfaces/database.interface.d.ts +46 -2
  64. package/dist/shared/interfaces/database.interface.d.ts.map +1 -1
  65. package/dist/shared/interfaces/database.interface.js.map +1 -1
  66. package/package.json +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"opportunity.claim-safety.js","sourceRoot":"/","sources":["opportunity/opportunity.claim-safety.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,MAAM,0BAA0B,GAAsB;IACpD,yEAAyE;IACzE,yCAAyC;IACzC,0KAA0K;IAC1K,gFAAgF;IAChF,gDAAgD;IAChD,6GAA6G;IAC7G,yIAAyI;IACzI,mKAAmK;IACnK,oLAAoL;IACpL,wHAAwH;IAExH,wEAAwE;IACxE,sEAAsE;IACtE,2IAA2I;IAC3I,+DAA+D;IAC/D,+DAA+D;IAC/D,8DAA8D;IAC9D,qJAAqJ;IAErJ,yEAAyE;IACzE,uEAAuE;IACvE,yGAAyG;IACzG,oCAAoC;IACpC,+FAA+F;IAC/F,4DAA4D;IAC5D,sHAAsH;IACtH,oCAAoC;IACpC,uFAAuF;IACvF,oJAAoJ;IACpJ,6HAA6H;IAC7H,qGAAqG;IAErG,yEAAyE;IACzE,yEAAyE;IACzE,2GAA2G;IAC3G,kDAAkD;IAClD,sCAAsC;IACtC,6DAA6D;IAC7D,0EAA0E;IAC1E,gJAAgJ;IAChJ,8HAA8H;IAE9H,oEAAoE;IACpE,kHAAkH;IAClH,sCAAsC;CACvC,CAAC;AAEF,iFAAiF;AACjF,MAAM,UAAU,8BAA8B,CAAC,IAA+B;IAC5E,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE;QAAE,OAAO,KAAK,CAAC;IAChC,OAAO,mBAAmB,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,qCAAqC,CAAC,CAAC;AAC/E,CAAC;AAED,2EAA2E;AAC3E,MAAM,UAAU,qCAAqC,CAAC,QAAgB;IACpE,OAAO,0BAA0B,CAAC,IAAI,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC;AAC9E,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,iCAAiC,CAAC,IAA+B;IAC/E,IAAI,CAAC,IAAI,EAAE,IAAI,EAAE;QAAE,OAAO,EAAE,CAAC;IAC7B,OAAO,mBAAmB,CAAC,IAAI,CAAC;SAC7B,MAAM,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,qCAAqC,CAAC,QAAQ,CAAC,CAAC;SACtE,IAAI,CAAC,GAAG,CAAC;SACT,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,IAAI,EAAE,CAAC;AACZ,CAAC;AAED,SAAS,mBAAmB,CAAC,IAAY;IACvC,OAAO,IAAI;SACR,IAAI,EAAE;SACN,KAAK,CAAC,mBAAmB,CAAC;SAC1B,GAAG,CAAC,CAAC,QAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC;SAClC,MAAM,CAAC,OAAO,CAAC,CAAC;AACrB,CAAC","sourcesContent":["/**\n * Deterministic guard for unsupported person-affiliation and presence claims.\n *\n * Opportunity presentation contracts currently do not carry typed provenance\n * proving attendance, membership, residence, or shared presence. The guard\n * therefore fails closed: a sentence making one of those claims is rejected\n * rather than loosely \"grounded\" against network/context text.\n *\n * The patterns are deliberately phrase-based. They target factual claims such\n * as \"Alice is a member of...\" while leaving generic domain phrases such as\n * \"membership model\" and \"team members\" alone. This is not a general factuality\n * checker and does not attempt semantic inference beyond the listed claim\n * families.\n */\n\nconst UNSUPPORTED_CLAIM_PATTERNS: readonly RegExp[] = [\n // Attendance and co-attendance claims. Relational grammar avoids product\n // phrases such as \"attendee management\".\n /\\b(?:co[-\\s]?attendance|co[-\\s]?attendee(?:s)?|co[-\\s]?attend(?:ed|ing)?|(?:another|fellow)\\s+(?:(?:event|session|conference|summit|gathering|meetup)\\s+)?attendees?)\\b/i,\n /\\b(?:is|are|was|were|will be|has been|have been|as)\\s+(?:an?\\s+)?attendees?\\b/i,\n /\\b(?:a|an|this|that)\\s+attendee\\s+(?:of|at)\\b/i,\n /\\b(?:will\\s+|plans?\\s+to\\s+)?attend(?:ed|ing)?\\s+(?!to\\b)(?:(?:at|in)\\s+)?(?:the\\s+)?[\\p{L}\\p{N}&'’.-]+\\b/iu,\n /\\b(?:is|are|was|were|will be)\\s+going\\s+to\\s+(?:the\\s+)?(?:event|session|conference|summit|gathering|meetup|[A-Z][\\p{L}\\p{N}&'’.-]*)\\b/u,\n /\\b(?:[Pp]articipat(?:ed|ing)|[Pp]articipants?)\\b(?=.{0,40}\\b(?:in|at)\\s+(?:the\\s+)?(?:event|session|conference|summit|gathering|meetup|[A-Z][\\p{L}\\p{N}&'’.-]*))/u,\n /\\b(?:[Ww]ent\\s+to|[Tt]ook\\s+part\\s+in|(?:[Ww]as|[Ww]ere|[Ii]s|[Aa]re)\\s+present\\s+at)\\s+(?:the\\s+)?(?:event|session|conference|summit|gathering|meetup|[A-Z][\\p{L}\\p{N}&'’.-]*)\\b/u,\n /\\b(?:session\\s+attendance|attendance\\s+(?:at|in)\\s+(?:the\\s+)?(?:event|session|conference|summit|gathering|meetup))\\b/i,\n\n // Shared event/session/place/time claims, including \"both were at ...\".\n /\\b(?:same|the same)\\s+(?:event|session|place|location|venue|time)\\b/i,\n /\\b(?:share|shared|sharing)\\s+(?:an?\\s+|the\\s+)?(?:event|session|workshop|conference|summit|gathering|meetup|place|location|venue|time)\\b/i,\n /\\bboth\\s+(?:were|are|will be|have been)\\s+(?:at|in|during)\\b/i,\n /\\b(?:were|are|will be|have been)\\s+both\\s+(?:at|in|during)\\b/i,\n /\\b(?:will|would|are|were)\\s+both\\s+be?\\s*(?:at|in|during)\\b/i,\n /\\bboth\\b.{0,80}\\b(?:attend(?:ed|ing)?|participat(?:e|ed|ing)|met|meet|meeting|stayed|stay)\\b.{0,60}\\b(?:event|session|place|location|venue|time)\\b/i,\n\n // Factual membership/affiliation claims. Generic descriptions of product\n // users (\"members of cooperatives\") and \"team members\" stay untouched.\n /\\b(?:is|are|was|were|be|being|been|became|become|as)\\s+(?:an?\\s+)?(?:fellow\\s+)?members?\\s+(?:of|in)\\b/i,\n /\\b(?:another|fellow)\\s+members?\\b/i,\n /\\b(?:is|are|was|were|be|being|been|as)\\s+(?:an?\\s+)?(?:community|network|event)\\s+members?\\b/i,\n /\\b(?:a|an|this|that)\\s+(?:fellow\\s+)?member\\s+(?:of|in)\\b/i,\n /\\b(?:is|are|was|were|be|being|been)\\s+(?:an?\\s+)?part\\s+of\\s+(?:the\\s+)?[^.!?]{0,60}\\b(?:community|network|event)\\b/i,\n /\\bfellow\\s+members?\\s+(?:of|in)\\b/i,\n /\\b(?:a|an)\\s+(?:[A-Z][\\p{L}\\p{N}&'’.-]*\\s+){1,6}(?:community\\s+|network\\s+)?member\\b/u,\n /\\b(?:[Bb]elongs?|[Bb]elonged)\\s+to\\s+(?:the\\s+)?(?:[Nn]etwork|[Cc]ommunity|[Ee]vent|(?:[A-Z][\\p{L}\\p{N}&'’.-]*\\s+){1,5}[A-Z][\\p{L}\\p{N}&'’.-]*)\\b/u,\n /\\b[Jj]oined\\s+(?:the\\s+)?(?:[Nn]etwork|[Cc]ommunity|[Ee]vent|(?:[A-Z][\\p{L}\\p{N}&'’.-]*\\s+){1,5}[A-Z][\\p{L}\\p{N}&'’.-]*)\\b/u,\n /\\b[Aa]ffiliated\\s+with\\s+(?:the\\s+)?(?:[Nn]etwork|[Cc]ommunity|[Ee]vent|[A-Z][\\p{L}\\p{N}&'’.-]*)\\b/u,\n\n // Residence/co-residence claims. Require person-claim grammar so generic\n // audience descriptions such as \"tools for residents of Berlin\" survive.\n /\\b(?:is|are|was|were|be|being|been|as)\\s+(?:an?\\s+)?(?:local\\s+|long[-\\s]?time\\s+|co[-\\s]?)?residents?\\b/i,\n /\\bco[-\\s]?(?:reside|resides|resided|residing)\\b/i,\n /\\b(?:another|fellow)\\s+residents?\\b/i,\n /\\b(?:a|an|this|that)\\s+(?:co[-\\s]?)?resident\\s+(?:of|in)\\b/i,\n /\\b(?:a|an)\\s+(?:[A-Z][\\p{L}\\p{N}&'’.-]*\\s+){1,6}(?:co[-\\s]?)?resident\\b/u,\n /\\b(?:[Hh]e|[Ss]he|[Tt]hey|[A-Z][\\p{L}'’.-]+)\\s+(?:reside|resides|resided|residing|live|lives|lived|living|(?:is|are|was|were)\\s+based)\\s+in\\b/u,\n /\\b(?:[Hh]e|[Ss]he|[Tt]hey|[A-Z][\\p{L}'’.-]+)\\s+calls?\\s+[A-Z][\\p{L}\\p{N}&'’.-]*(?:\\s+[A-Z][\\p{L}\\p{N}&'’.-]*){0,5}\\s+home\\b/u,\n\n // Relationship claims inferred from shared network/event placement.\n /\\b(?:know|knows|knew|met|meet)\\b.{0,60}\\b(?:through|from|at)\\s+(?:the\\s+)?(?:network|community|event|session)\\b/i,\n /\\bcrossed\\s+paths\\s+(?:at|during)\\b/i,\n];\n\n/** Returns true when text contains an unsupported affiliation/presence claim. */\nexport function hasUnsupportedOpportunityClaim(text: string | null | undefined): boolean {\n if (!text?.trim()) return false;\n return splitClaimSentences(text).some(isUnsupportedOpportunityClaimSentence);\n}\n\n/** Returns true when one sentence contains an unsupported claim family. */\nexport function isUnsupportedOpportunityClaimSentence(sentence: string): boolean {\n return UNSUPPORTED_CLAIM_PATTERNS.some((pattern) => pattern.test(sentence));\n}\n\n/**\n * Removes complete sentences containing unsupported claims and preserves the\n * remaining sentence order. An all-unsafe input becomes an empty string so the\n * caller can apply a field-specific deterministic default.\n */\nexport function stripUnsupportedOpportunityClaims(text: string | null | undefined): string {\n if (!text?.trim()) return \"\";\n return splitClaimSentences(text)\n .filter((sentence) => !isUnsupportedOpportunityClaimSentence(sentence))\n .join(\" \")\n .replace(/\\s+/g, \" \")\n .trim();\n}\n\nfunction splitClaimSentences(text: string): string[] {\n return text\n .trim()\n .split(/(?<=[.!?])\\s+|\\n+/)\n .map((sentence) => sentence.trim())\n .filter(Boolean);\n}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AM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,SAAS,CAAC,EAAE,oBAAoB,CAAC;IACjC,iBAAiB,CAAC,EAAE,OAAO,CAAC;CAC7B,GAAG,OAAO,CAAC,cAAc,CAAC,CAgI1B"}
@@ -314,7 +314,12 @@ async function enrichOpportunities(input) {
314
314
  name: item.profile?.identity?.name ?? nameByUserId.get(item.candidateUserId) ?? undefined,
315
315
  avatar: avatarByUserId.get(item.candidateUserId) ?? null,
316
316
  bio: truncateForChat(item.profile?.identity?.bio),
317
- matchReason: truncateForChat(item.opportunity.interpretation?.reasoning ?? "") ?? "",
317
+ matchReason: safeFallbackSummary(item.opportunity.interpretation?.reasoning, {
318
+ counterpartName: item.profile?.identity?.name ?? nameByUserId.get(item.candidateUserId) ?? undefined,
319
+ viewerName,
320
+ maxChars: MAX_FIELD_CHARS,
321
+ emptyText: "A suggested connection.",
322
+ }),
318
323
  score: item.confidence,
319
324
  status: chatSessionId && !existingOpportunityIds?.has(item.opportunity.id) ? "draft" : item.opportunity.status,
320
325
  viewerRole: item.viewerRole,
@@ -1 +1 @@
1
- {"version":3,"file":"opportunity.discover.js","sourceRoot":"/","sources":["opportunity/opportunity.discover.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH,OAAO,EAAE,2BAA2B,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAE3G,OAAO,EAAwB,sBAAsB,EAA4H,MAAM,4BAA4B,CAAC;AACpN,OAAO,EAAE,2BAA2B,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACrH,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAM7F,OAAO,EAAE,mBAAmB,EAA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AAE,KAAK;YACZ,KAAK,EAAE,CAAC;YACR,OAAO,EAAE,mEAAmE;YAC5E,UAAU;YACV,UAAU;SACX,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,mBAAmB,CAAC;QACzC,aAAa;QACb,QAAQ;QACR,MAAM;QACN,aAAa;QACb,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;QAC1C,UAAU;KACX,CAAC,CAAC;IAEH,OAAO;QACL,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,QAAQ,CAAC,MAAM;QACtB,aAAa,EAAE,QAAQ;QACvB,UAAU;QACV,UAAU;KACX,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Run discovery from an ad-hoc query (e.g. chat \"find me a mentor\", \"who needs a React developer\").\n *\n * Invokes the opportunity graph with the query as sourceText. The HyDE graph's\n * LensInferrer automatically infers search lenses from the query, replacing the\n * old hardcoded strategy selection. Returns formatted candidates (enriched with\n * profile name/bio) for chat display.\n *\n * Used by the discover_opportunities chat tool.\n */\n\nimport type { Opportunity, ChatGraphCompositeDatabase, UserRecord } from \"../shared/interfaces/database.interface.js\";\nimport type { Cache } from \"../shared/interfaces/cache.interface.js\";\nimport type { OpportunityGraphOptions, CandidateMatch, SourceProfileData } from \"./opportunity.state.js\";\nimport type { DiscoveryNegotiation, DiscoverySummary } from \"./question.prompt.js\";\nimport type { QuestionerEnqueueFn } from \"../questioner/questioner.types.js\";\nimport { discoveryQuestionsInputMode, discoveryQuestionsTimeoutMs } from \"../questioner/questioner.env.js\";\nimport type { ToolScopeType } from \"../shared/agent/tool.scope.js\";\nimport { OpportunityPresenter, gatherPresenterContext, type OpportunityPresentationResult, type HomeCardPresentationResult, type HomeCardLLMResult, type HomeCardPresenterInput } from \"./opportunity.presenter.js\";\nimport { MINIMAL_MAIN_TEXT_MAX_CHARS, getPrimaryActionLabel, SECONDARY_ACTION_LABEL } from \"./opportunity.labels.js\";\nimport { narratorRemarkFromReasoning } from \"./opportunity.presentation.js\";\nimport { safeFallbackSummary } from \"./opportunity.safe-presentation.js\";\nimport { protocolLogger, withCallLogging } from \"../shared/observability/protocol.logger.js\";\nimport type { ChatSummaryReader } from \"../shared/interfaces/chat-summary.interface.js\";\nimport type { ChatContextDigest } from \"../shared/schemas/chat-context.schema.js\";\nimport type { QuestionGeneratorReader } from \"../shared/interfaces/question-generator.interface.js\";\nimport type { NegotiationSummaryReader } from \"../shared/interfaces/negotiation-summary.interface.js\";\nimport type { DiscoveryNegotiationDigest } from \"../shared/schemas/negotiation-digest.schema.js\";\nimport { buildFallbackDigest } from \"../negotiation/negotiation.summarizer.js\";\nimport type { Question, QuestionStrategy } from \"../shared/schemas/question.schema.js\";\nimport { traceAgent, tracePhase } from \"../shared/observability/trace.js\";\nimport { requestContext } from \"../shared/observability/request-context.js\";\nimport { buildDiscoveryQuestionInput } from \"./discovery-question.helper.js\";\nimport { invokeWithAbortSignal } from \"../shared/agent/model-signal.js\";\n\nconst logger = protocolLogger(\"OpportunityDiscover\");\nconst discoverFromQueryLog = protocolLogger(\"OpportunityDiscover:runDiscoverFromQuery\");\nconst enrichLog = protocolLogger(\"OpportunityDiscover:enrichOpportunities\");\n\n/**\n * Per-negotiation summarizer budget. The summarizer fires one LLM call per\n * partial-or-full negotiation (concurrently via Promise.all). Without a cap\n * one slow OpenRouter route dominates the post-discovery tail and pushes the\n * whole MCP response past Railway's ~60 s no-upstream-bytes timeout. Falls\n * back to a deterministic digest when the deadline fires, so question\n * generation still has structured input.\n */\nconst NEGOTIATION_SUMMARY_TIMEOUT_MS_DEFAULT = 5_000;\n\n/**\n * Parse a positive integer env var, clamped to the safe-integer range so a\n * malformed env value cannot crash `AbortSignal.timeout` (which throws on\n * values outside `[0, MAX_SAFE_INTEGER]`). Mirrors the precedent in\n * `negotiation.agent.ts` (`isValidTimeoutMs`).\n */\nfunction parsePositiveIntEnv(name: string, fallback: number): number {\n const raw = process.env[name];\n if (!raw) return fallback;\n const n = Number.parseInt(raw, 10);\n if (!Number.isFinite(n) || n <= 0 || n > Number.MAX_SAFE_INTEGER) return fallback;\n return n;\n}\n\nfunction combineWithDeadline(\n callerSignal: AbortSignal | undefined,\n deadlineMs: number,\n): AbortSignal {\n const deadline = AbortSignal.timeout(deadlineMs);\n if (!callerSignal) return deadline;\n return AbortSignal.any([callerSignal, deadline]);\n}\n\n/** Compiled opportunity graph (from OpportunityGraphFactory.createGraph()). */\nexport type CompiledOpportunityGraph = ReturnType<\n import(\"./opportunity.graph.js\").OpportunityGraphFactory[\"createGraph\"]\n>;\n\nexport interface DiscoverInput {\n /** Compiled opportunity graph (already has DB, embedder, cache, HyDE graph). */\n opportunityGraph: CompiledOpportunityGraph;\n /** Database for enriching candidates with profile (getProfile). */\n database: ChatGraphCompositeDatabase;\n userId: string;\n query: string;\n indexScope: string[];\n limit?: number;\n /** Optional intent to use as discovery source and for triggeredBy (e.g. from opportunity queue). */\n triggerIntentId?: string;\n /** When set, filter discovery candidates to this specific user only (direct connection). */\n targetUserId?: string;\n /** When set, discover on behalf of this user (introducer flow). The caller (userId) becomes the introducer. */\n onBehalfOfUserId?: string;\n /** When provided, each opportunity is enriched with personalized presentation (headline, personalizedSummary, suggestedAction). */\n presenter?: OpportunityPresenter;\n /**\n * When true, use the full home card presentation format (with narratorRemark, action labels, mutualIntentsLabel).\n * This enables rendering the same rich opportunity cards in chat as on the home page.\n */\n useHomeCardFormat?: boolean;\n /**\n * When true, skip the LLM presenter and return minimal card data only (faster for chat).\n * Sets homeCardPresentation and narratorChip from static labels and match reason.\n */\n minimalForChat?: boolean;\n /** When set (e.g. from chat), create opportunities as draft with context.conversationId = chatSessionId. */\n chatSessionId?: string;\n /** Redis cache for discovery pagination. When provided, remaining candidates are cached for continuation. */\n cache?: Cache;\n /**\n * Which flow is invoking discovery. Drives the graph's trigger-aware branches\n * in persist (initial status) and negotiate (park window + streaming). When\n * omitted, the graph defaults to 'ambient'. Pass 'orchestrator' from the\n * chat `discover_opportunities` tool so users see drafts stream in and the\n * accepted-pair lookup surfaces existing connections.\n */\n trigger?: 'ambient' | 'orchestrator';\n /**\n * MCP-only. When set, the opportunity graph's negotiate phase is capped at\n * this many milliseconds; on timeout the caller gets whichever candidates\n * finished, the rest stay in `negotiating` and finalize in the background.\n * Chat, ambient queue, and all other callers omit this — existing behavior.\n */\n negotiateTimeoutMs?: number;\n /** Optional read-through chat-session digest reader. Required for chatContext enrichment. */\n chatSummary?: ChatSummaryReader;\n /**\n * Optional negotiation summarizer. When provided, each post-negotiation digest\n * replaces the raw negotiation in the decision-question generator's input,\n * keeping that prompt small and predictable regardless of candidate count.\n * When omitted, a deterministic fallback digest is built per negotiation.\n */\n negotiationSummary?: NegotiationSummaryReader;\n /** Optional decision-question generator. When omitted, no questions are produced. */\n questionGenerator?: QuestionGeneratorReader;\n /**\n * Master switch for decision-question generation. When false, this code path\n * is skipped entirely regardless of trigger. The composition root passes\n * `isDiscoveryQuestionsEnabled()` (QUESTIONER_ENABLED + QUESTIONER_DISCOVERY_ENABLED).\n */\n enableQuestions?: boolean;\n /**\n * Optional async question enqueue callback. When provided, question generation\n * is dispatched asynchronously to the QuestionerQueue instead of running inline\n * via the `questionGenerator`. The callback receives an enqueue payload and\n * returns a promise that resolves when the job is enqueued (not when generation\n * completes).\n */\n questionerEnqueue?: QuestionerEnqueueFn;\n /** Focused request scope type for generated discovery questions. */\n scopeType?: ToolScopeType;\n /** Focused request scope id. When `scopeType === 'network'`, persisted as actor networkId. */\n scopeId?: string;\n}\n\n/** Context used by the minimal (no-LLM) path; only introducerName is needed for narrator chip. */\ntype MinimalPresenterContext = { introducerName?: string };\n\n/** Max chars for bio and matchReason in chat tool results to keep context manageable. */\nconst MAX_FIELD_CHARS = 100;\n\nfunction truncateForChat(\n s: string | undefined,\n max = MAX_FIELD_CHARS,\n): string | undefined {\n if (s == null || s === \"\") return undefined;\n const trimmed = s.trim();\n if (trimmed.length <= max) return trimmed;\n return trimmed.slice(0, max) + \"...\";\n}\n\n/** One formatted opportunity for chat (candidate-facing). */\nexport interface FormattedDiscoveryCandidate {\n opportunityId: string;\n userId: string;\n name?: string;\n avatar?: string | null;\n bio?: string;\n matchReason: string;\n score: number;\n status?: string;\n /** Present when DiscoverInput.presenter was provided (basic presentation). */\n presentation?: OpportunityPresentationResult;\n /** Present when DiscoverInput.useHomeCardFormat is true (full home card contract). */\n homeCardPresentation?: HomeCardPresentationResult;\n /** Viewer's role in this opportunity. */\n viewerRole?: string;\n /** Whether the viewer (as introducer) has approved the introduction. */\n viewerApproved?: boolean;\n /** Timestamp set once this viewer has already acted on the opportunity. */\n viewerActedAt?: string | null;\n /** Full user record for the candidate (needed for socials / Telegram fallback). */\n candidateUser?: UserRecord | null;\n /** Whether the counterpart is a ghost (not yet onboarded) user. */\n isGhost?: boolean;\n /** Narrator chip for home card display (name + remark, with optional avatar/userId for introducer). */\n narratorChip?: {\n name: string;\n text: string;\n avatar?: string | null;\n userId?: string;\n };\n /** Second party in introducer arrow layout (candidate -> secondParty). Present when viewer is introducer. */\n secondParty?: {\n name: string;\n avatar?: string | null;\n userId?: string;\n };\n}\n\n/** One step for debug visibility (subgraph/subtask). */\nexport interface DiscoverDebugStep {\n step: string;\n detail?: string;\n /** Structured data for rich display (e.g., candidate counts, scores). */\n data?: Record<string, unknown>;\n}\n\n/** One existing connection (no new opportunity created; user already has one with this person). */\nexport interface ExistingConnection {\n userId: string;\n name: string;\n status?: string;\n opportunityId?: string;\n}\n\n/** Statuses for which an existing connection may be shown as a card; others (accepted, rejected, expired) are only mentioned in text. */\nconst EXISTING_CONNECTION_CARD_STATUSES = ['draft', 'latent', 'pending'] as const;\n\nexport interface DiscoverResult {\n found: boolean;\n count: number;\n message?: string;\n opportunities?: FormattedDiscoveryCandidate[];\n /** Existing connections eligible for card display (draft, latent, or pending). Others are mention-only. */\n existingConnections?: ExistingConnection[];\n /** All existing connections for mention text (e.g. \"You already have a connection with: X (pending), Y (draft).\"). */\n existingConnectionsForMention?: ExistingConnection[];\n /**\n * Orchestrator-only: accepted opportunities the persist step found between the\n * discoverer and a candidate counterparty (status='accepted'). Populated from\n * OpportunityGraphState.dedupAlreadyAccepted. Used by the discover_opportunities\n * tool to tell the LLM \"this pair is already connected — open the existing\n * chat rather than creating a new draft\". Empty for the ambient trigger.\n */\n alreadyAcceptedPairs?: Array<{ opportunityId: string; counterpartyUserId: string }>;\n /** When true, the chat agent should call create_intent(suggestedIntentDescription) and retry discovery. */\n createIntentSuggested?: boolean;\n /** Description to pass to create_intent when createIntentSuggested is true. */\n suggestedIntentDescription?: string;\n /** Internal steps for copy-debug (select_strategies, opportunity_graph, enrich, etc.). */\n debugSteps?: DiscoverDebugStep[];\n /** Pagination metadata -- present when there are more unevaluated candidates. */\n pagination?: {\n discoveryId: string;\n evaluated: number;\n remaining: number;\n };\n /** 0–3 decision questions produced by the orchestrator path. Omitted when none. */\n questions?: Question[];\n /** Debug metadata for `debugMeta.discoveryQuestions` plumbing. */\n discoveryQuestionsDebug?: {\n inputMode: \"transcripts\" | \"insights\";\n finalCount: number;\n strategies: QuestionStrategy[];\n durationMs: number;\n };\n}\n\n/** Input for the shared enrichment helper. */\ninterface EnrichOpportunitiesInput {\n opportunities: Opportunity[];\n database: ChatGraphCompositeDatabase;\n userId: string;\n chatSessionId?: string;\n minimalForChat?: boolean;\n presenter?: OpportunityPresenter;\n useHomeCardFormat?: boolean;\n debugSteps: DiscoverDebugStep[];\n /** IDs of pre-existing opportunities merged into the list; these preserve their real status. */\n existingOpportunityIds?: Set<string>;\n /** When set, bypass the embedding filter for this specific user (direct connection mode). */\n targetUserId?: string;\n}\n\n/**\n * Enrich raw opportunities with profile data, presentation (LLM or minimal),\n * and narrator chips. Shared by both `runDiscoverFromQuery` and `continueDiscovery`\n * to avoid duplicating the profile-lookup / presenter / card-formatting logic.\n *\n * @param input - Enrichment context (opportunities, database, viewer, presentation options).\n * @returns Formatted discovery candidates ready for chat or home card display.\n */\nasync function enrichOpportunities(\n input: EnrichOpportunitiesInput,\n): Promise<FormattedDiscoveryCandidate[]> {\n const {\n opportunities,\n database,\n userId,\n chatSessionId,\n minimalForChat,\n presenter,\n useHomeCardFormat,\n debugSteps,\n existingOpportunityIds,\n targetUserId,\n } = input;\n\n const baseEnrichedRaw = await Promise.all(\n opportunities.map(async (opp) => {\n const viewerIsIntroducer = opp.actors.some((a) => a.role === 'introducer' && a.userId === userId);\n // When the viewer is the introducer, the \"candidate\" for the card is the agent\n // (the discovered person), not the patient (the intro target / onBehalfOfUserId).\n // For non-introducer views, pick the first non-viewer, non-introducer actor.\n const nonViewerNonIntroducerActors = opp.actors.filter((a) => a.userId !== userId && a.role !== 'introducer');\n const candidateActor = viewerIsIntroducer\n ? (nonViewerNonIntroducerActors.find((a) => a.role === 'agent') ?? nonViewerNonIntroducerActors[0])\n : nonViewerNonIntroducerActors[0];\n const candidateUserId = candidateActor?.userId ?? \"\";\n const viewerActor = opp.actors.find((a) => a.userId === userId);\n const [profile, candidateUser] = candidateUserId\n ? await Promise.all([database.getProfile(candidateUserId), database.getUser(candidateUserId)])\n : [null, null];\n // Skip soft-deleted users (deletedAt is set)\n if (candidateUser && 'deletedAt' in candidateUser && candidateUser.deletedAt) return null;\n const isDirectTarget = targetUserId && candidateUserId === targetUserId;\n if (!isDirectTarget && !candidateUser?.isGhost && !profile) return null;\n const confidence =\n typeof opp.interpretation?.confidence === \"number\"\n ? opp.interpretation.confidence\n : parseFloat(String(opp.interpretation?.confidence ?? 0)) || 0;\n return {\n opportunity: opp,\n candidateUserId,\n viewerRole: viewerActor?.role ?? \"party\",\n viewerApproved: viewerActor?.approved === true,\n viewerActedAt: viewerActor?.actedAt ?? null,\n candidateUser,\n profile,\n confidence,\n };\n }),\n );\n const baseEnriched = baseEnrichedRaw.filter((item): item is NonNullable<typeof item> => item !== null);\n debugSteps.push({\n step: \"enrich_profiles\",\n detail: `${baseEnriched.length} profile(s)`,\n });\n\n // Batch-fetch user records (candidates, introducers, and other party actors) for name/avatar fallback.\n const allActorUserIds = new Set<string>();\n for (const item of baseEnriched) {\n for (const actor of item.opportunity.actors) {\n if (actor.userId && actor.userId !== userId) {\n allActorUserIds.add(actor.userId);\n }\n }\n }\n const candidateUserIds = [...allActorUserIds];\n const [viewerUser, ...userResults] = await Promise.all([\n database.getUser(userId),\n ...candidateUserIds.map((id) => database.getUser(id)),\n ]);\n const avatarByUserId = new Map<string, string | null>();\n const nameByUserId = new Map<string, string | null>();\n const isGhostByUserId = new Map<string, boolean>();\n candidateUserIds.forEach((id, i) => {\n const user = userResults[i] ?? null;\n avatarByUserId.set(id, user?.avatar ?? null);\n nameByUserId.set(id, user?.name ?? null);\n isGhostByUserId.set(id, user?.isGhost ?? false);\n });\n const viewerName = viewerUser?.name ?? undefined;\n\n // Retry name resolution for candidates whose name is still missing.\n // The profile or user record may not have been ready on the first fetch\n // (e.g. profile generation still in flight). One retry covers transient gaps.\n const missingNameIds = baseEnriched\n .map((item) => item.candidateUserId)\n .filter((id) => id && !nameByUserId.get(id) && !baseEnriched.find((b) => b.candidateUserId === id && b.profile?.identity?.name));\n if (missingNameIds.length > 0) {\n const retried = await Promise.all(\n missingNameIds.map(async (id) => {\n const [profile, user] = await Promise.all([\n database.getProfile(id),\n database.getUser(id),\n ]);\n return { id, profile, user };\n }),\n );\n for (const r of retried) {\n const name = r.profile?.identity?.name ?? r.user?.name ?? null;\n if (name) nameByUserId.set(r.id, name);\n // Also update the baseEnriched profile so counterpartName picks it up\n if (r.profile) {\n const item = baseEnriched.find((b) => b.candidateUserId === r.id);\n if (item && !item.profile) item.profile = r.profile;\n }\n if (r.user?.avatar && !avatarByUserId.get(r.id)) {\n avatarByUserId.set(r.id, r.user.avatar);\n }\n }\n enrichLog.verbose(\"Retried name lookup for candidates with missing names\", {\n attempted: missingNameIds.length,\n resolved: retried.filter((r) => r.profile?.identity?.name ?? r.user?.name).length,\n });\n }\n\n let presentations: OpportunityPresentationResult[] | undefined;\n let homeCardPresentations: HomeCardPresentationResult[] | undefined;\n let presenterContexts:\n | (Awaited<ReturnType<typeof gatherPresenterContext>> | MinimalPresenterContext)[]\n | undefined;\n\n if (minimalForChat && baseEnriched.length > 0) {\n // Minimal path: no LLM, viewer-centric card text (introduce counterpart to viewer)\n const counterpartName = (n: {\n profile?: { identity?: { name?: string } } | null;\n candidateUserId: string;\n }) => n.profile?.identity?.name ?? nameByUserId.get(n.candidateUserId) ?? \"\";\n homeCardPresentations = baseEnriched.map((item) => {\n const name = counterpartName(item)?.trim();\n const reasoning = item.opportunity.interpretation?.reasoning ?? \"\";\n const introducerName = item.opportunity.detection?.createdByName ?? undefined;\n const viewerIsIntroducer = item.opportunity.actors.some(\n (a) => a.role === \"introducer\" && a.userId === userId,\n );\n\n // For introducer view, find the second party (target user) name\n let secondPartyName: string | undefined;\n if (viewerIsIntroducer) {\n const otherPartyActors = item.opportunity.actors.filter(\n (a) => a.role !== \"introducer\" && a.userId !== item.candidateUserId,\n );\n if (otherPartyActors.length > 0) {\n const otherUserId = otherPartyActors[0].userId;\n secondPartyName = nameByUserId.get(otherUserId) ?? undefined;\n }\n }\n\n const isCounterpartGhost = isGhostByUserId.get(item.candidateUserId) ?? false;\n // Shared sanitization standard — see opportunity.safe-presentation.ts.\n const personalizedSummary = safeFallbackSummary(reasoning, {\n counterpartName: name,\n viewerName,\n introducerName,\n maxChars: MINIMAL_MAIN_TEXT_MAX_CHARS,\n emptyText: \"A suggested connection.\",\n });\n return {\n headline: viewerIsIntroducer && secondPartyName\n ? `${name} → ${secondPartyName}`\n : (name ? `Connection with ${name}` : \"Suggested connection\"),\n personalizedSummary,\n digestSummary: name\n ? `You might like meeting ${name} based on your current interests.`\n : \"This connection may be relevant to your current interests.\",\n suggestedAction: \"Start a conversation to connect.\",\n narratorRemark: narratorRemarkFromReasoning(reasoning, name, viewerName),\n primaryActionLabel: getPrimaryActionLabel(viewerIsIntroducer ? \"introducer\" : \"party\"),\n secondaryActionLabel: SECONDARY_ACTION_LABEL,\n mutualIntentsLabel: \"Suggested connection\",\n greeting: \"\",\n };\n });\n presenterContexts = baseEnriched.map((item) => ({\n introducerName: item.opportunity.detection.createdByName ?? undefined,\n })) as MinimalPresenterContext[];\n } else if (presenter && baseEnriched.length > 0) {\n try {\n presenterContexts = await Promise.all(\n baseEnriched.map(({ opportunity }) =>\n gatherPresenterContext(database, opportunity, userId),\n ),\n );\n\n if (useHomeCardFormat) {\n // Use full home card format with action labels, narrator remark, etc.\n const fullContexts = presenterContexts as Awaited<\n ReturnType<typeof gatherPresenterContext>\n >[];\n const homeCardInputs: HomeCardPresenterInput[] = fullContexts.map(\n (ctx, idx) => ({\n ...ctx,\n mutualIntentCount: undefined,\n opportunityStatus: baseEnriched[idx].opportunity.status,\n }),\n );\n const llmResults = await presenter.presentHomeCardBatch(\n homeCardInputs,\n { concurrency: 5 },\n );\n // Append hardcoded button labels to LLM results\n homeCardPresentations = llmResults.map((llm, idx) => ({\n ...llm,\n primaryActionLabel: getPrimaryActionLabel(baseEnriched[idx].viewerRole),\n secondaryActionLabel: SECONDARY_ACTION_LABEL,\n }));\n } else {\n // Use basic presentation format\n presentations = await presenter.presentBatch(\n presenterContexts as Awaited<\n ReturnType<typeof gatherPresenterContext>\n >[],\n {\n concurrency: 5,\n },\n );\n }\n } catch (error) {\n logger.warn(\n \"Presenter enrichment failed during opportunity discovery; returning base results without presentations\",\n {\n userId,\n opportunitiesCount: baseEnriched.length,\n useHomeCardFormat,\n error: error instanceof Error ? error.message : String(error),\n },\n );\n presentations = undefined;\n homeCardPresentations = undefined;\n }\n }\n\n const enriched: FormattedDiscoveryCandidate[] = baseEnriched.map(\n (item, idx) => {\n const homeCard = homeCardPresentations?.[idx];\n const ctx = presenterContexts?.[idx];\n\n // Build narrator chip for home card format\n let narratorChip: FormattedDiscoveryCandidate[\"narratorChip\"];\n if (homeCard) {\n const viewerIsIntroducer = item.opportunity.actors.some(\n (a) => a.role === \"introducer\" && a.userId === userId,\n );\n if (viewerIsIntroducer) {\n narratorChip = {\n name: \"You\",\n text: homeCard.narratorRemark,\n userId: userId,\n };\n } else {\n const introducerActor = item.opportunity.actors.find(\n (a) => a.role === \"introducer\" && a.userId !== userId,\n );\n if (introducerActor) {\n const introducerName =\n ctx?.introducerName ??\n nameByUserId.get(introducerActor.userId) ??\n \"Someone\";\n narratorChip = {\n name: introducerName,\n text: homeCard.narratorRemark,\n userId: introducerActor.userId,\n avatar: avatarByUserId.get(introducerActor.userId) ?? null,\n };\n } else {\n narratorChip = {\n name: \"Index\",\n text: homeCard.narratorRemark,\n };\n }\n }\n }\n\n const isGhost = isGhostByUserId.get(item.candidateUserId) ?? false;\n\n // Build secondParty for introducer view (the other non-introducer party)\n let secondParty: FormattedDiscoveryCandidate[\"secondParty\"];\n const viewerIsIntroducerForCard = item.opportunity.actors.some(\n (a) => a.role === \"introducer\" && a.userId === userId,\n );\n if (viewerIsIntroducerForCard) {\n const otherPartyActor = item.opportunity.actors.find(\n (a) => a.role !== \"introducer\" && a.userId !== item.candidateUserId,\n );\n if (otherPartyActor) {\n const otherName = nameByUserId.get(otherPartyActor.userId) ?? undefined;\n if (otherName) {\n secondParty = {\n name: otherName,\n avatar: avatarByUserId.get(otherPartyActor.userId) ?? null,\n userId: otherPartyActor.userId,\n };\n }\n }\n }\n\n return {\n opportunityId: item.opportunity.id,\n userId: item.candidateUserId,\n name: item.profile?.identity?.name ?? nameByUserId.get(item.candidateUserId) ?? undefined,\n avatar: avatarByUserId.get(item.candidateUserId) ?? null,\n bio: truncateForChat(item.profile?.identity?.bio),\n matchReason:\n truncateForChat(\n item.opportunity.interpretation?.reasoning ?? \"\",\n ) ?? \"\",\n score: item.confidence,\n status: chatSessionId && !existingOpportunityIds?.has(item.opportunity.id) ? \"draft\" : item.opportunity.status,\n viewerRole: item.viewerRole,\n viewerApproved: item.viewerApproved,\n viewerActedAt: item.viewerActedAt,\n candidateUser: item.candidateUser,\n isGhost,\n ...(presentations?.[idx] && { presentation: presentations[idx] }),\n ...(homeCard && {\n homeCardPresentation: homeCard,\n }),\n ...(narratorChip && { narratorChip }),\n ...(secondParty && { secondParty }),\n };\n },\n );\n debugSteps.push({\n step: \"format_cards\",\n detail: `${enriched.length} card(s)`,\n });\n\n return enriched;\n}\n\n/** Cached discovery session data stored in Redis. */\ninterface CachedDiscoverySession {\n candidates: CandidateMatch[];\n userId: string;\n onBehalfOfUserId?: string;\n query: string;\n indexScope: string[];\n options: OpportunityGraphOptions;\n /**\n * Carried across pagination so page 2+ stays on the same flow as page 1.\n * Without this, orchestrator runs would fall back to the 'ambient' default\n * mid-search and lose the shorter park window + accepted-pair dedup.\n */\n trigger?: 'ambient' | 'orchestrator';\n}\n\n/**\n * Run discovery from an ad-hoc query (e.g. \"find me a mentor\", \"who needs a React developer\").\n * The HyDE graph's LensInferrer automatically infers search lenses from the query.\n * Invokes the opportunity graph and returns formatted candidates suitable for chat display.\n */\nexport async function runDiscoverFromQuery(\n input: DiscoverInput,\n): Promise<DiscoverResult> {\n const {\n opportunityGraph,\n database,\n userId,\n query,\n indexScope,\n limit = 5,\n triggerIntentId,\n targetUserId,\n onBehalfOfUserId,\n chatSessionId,\n trigger,\n negotiateTimeoutMs,\n } = input;\n\n if (indexScope.length === 0) {\n return {\n found: false,\n count: 0,\n message:\n \"You need to join at least one network (community) to discover opportunities. Use read_networks to see available networks, or create one.\",\n };\n }\n\n const debugSteps: DiscoverDebugStep[] = [];\n\n // When query is empty, the opportunity graph uses the user's intents in scope (indexedIntents[0].payload)\n // Lens inference is handled automatically by the HyDE graph's LensInferrer\n const queryOrEmpty = query?.trim() ?? \"\";\n // Orchestrator discovery defers the initial status to the graph's\n // trigger-aware `resolveInitialStatus`, which opens at 'negotiating' so\n // the accepted-draft streaming flow can run. Ambient chat discovery still\n // wants the legacy 'draft' status so the chat-only lifecycle holds; other\n // ambient callers keep 'latent'.\n const isOrchestrator = trigger === 'orchestrator';\n const options: OpportunityGraphOptions = {\n limit,\n ...(!isOrchestrator && { initialStatus: chatSessionId ? \"draft\" : \"latent\" }),\n ...(chatSessionId ? { conversationId: chatSessionId } : {}),\n ...(negotiateTimeoutMs !== undefined && { negotiateTimeoutMs }),\n };\n\n return withCallLogging(\n logger,\n \"runDiscoverFromQuery\",\n {\n userId,\n queryPreview: queryOrEmpty\n ? queryOrEmpty.substring(0, 50)\n : \"(using user intents in scope)\",\n indexScopeCount: indexScope.length,\n limit,\n },\n async () => {\n const result = await invokeWithAbortSignal(opportunityGraph, {\n userId,\n searchQuery: queryOrEmpty || undefined,\n // A single index resolves to the strict networkId override (membership-\n // validated in the scope node). Multiple indexes (e.g. a network-scoped\n // agent's bound network + personal network) pass through as indexScope so\n // the graph stays bounded instead of falling back to all networks.\n networkId: indexScope.length === 1 ? indexScope[0] : undefined,\n ...(indexScope.length > 1 ? { indexScope } : {}),\n triggerIntentId,\n targetUserId,\n onBehalfOfUserId,\n options,\n ...(trigger && { trigger }),\n });\n\n // Extract trace from graph and append to debugSteps\n const graphTrace = Array.isArray(result.trace) ? result.trace : [];\n for (const t of graphTrace) {\n debugSteps.push({\n step: t.node,\n detail: t.detail,\n ...(t.data ? { data: t.data } : {}),\n });\n }\n\n // Bail early if the graph returned an error\n if (result.error) {\n logger.warn(\"runDiscoverFromQuery graph returned error\", { error: result.error });\n return {\n found: false,\n count: 0,\n message: \"Failed to find opportunities. Please try again.\",\n debugSteps,\n };\n }\n\n // Cache remaining candidates for pagination\n let pagination: DiscoverResult['pagination'] | undefined;\n const remainingCandidates: CandidateMatch[] = result.remainingCandidates || [];\n if (remainingCandidates.length > 0 && input.cache) {\n try {\n const discoveryId = crypto.randomUUID();\n const cacheKey = `discovery:${userId}:${discoveryId}`;\n await input.cache.set(cacheKey, {\n candidates: remainingCandidates,\n userId,\n onBehalfOfUserId,\n query: queryOrEmpty,\n indexScope,\n options,\n ...(trigger && { trigger }),\n } satisfies CachedDiscoverySession, { ttl: 1800 }); // 30 minutes\n pagination = {\n discoveryId,\n evaluated: (result.candidates?.length ?? 0) - remainingCandidates.length,\n remaining: remainingCandidates.length,\n };\n } catch (cacheErr) {\n logger.warn(\"Failed to cache discovery pagination\", {\n userId,\n error: cacheErr instanceof Error ? cacheErr.message : String(cacheErr),\n });\n }\n }\n\n // Refine phase: a sibling of the opportunity graph in the trace tree.\n // Holds the three post-discovery summarization steps. Each step is its\n // own traced agent so it appears as a leaf in the trace UI.\n //\n // Negotiation summary: compress each raw negotiation into a fixed-size\n // structured digest so the question generator's prompt stays small\n // (a 10-candidate turn used to balloon past 60 KB and stall upstream).\n // Decision questions: generate up to 3 clarifying questions from the\n // digests + chat context.\n const { questionPayload } = await tracePhase(\"Refine\", async () => {\n const negotiationDigests = await summarizeNegotiations({\n negotiations: result.discoveryNegotiations ?? [],\n summarizer: input.negotiationSummary,\n enableQuestions: input.enableQuestions ?? false,\n trigger,\n });\n const questionPayload = await maybeBuildQuestions({\n trigger,\n enableQuestions: input.enableQuestions ?? false,\n chatSummary: input.chatSummary,\n questionGenerator: input.questionGenerator,\n chatSessionId,\n graphResult: result,\n negotiationDigests,\n query: queryOrEmpty,\n questionerEnqueue: input.questionerEnqueue,\n userId: input.userId,\n scopeType: input.scopeType,\n scopeId: input.scopeId,\n triggerIntentId,\n userContext: input.userId\n ? ((await input.database.getUserContext(input.userId, null))?.text ?? '')\n : '',\n });\n return { negotiationDigests, questionPayload };\n });\n\n if (result.createIntentSuggested && result.suggestedIntentDescription) {\n if (chatSessionId) {\n return {\n found: false,\n count: 0,\n message: \"No matching opportunities found. Try a different query.\",\n pagination,\n ...(questionPayload.questions !== undefined ? { questions: questionPayload.questions } : {}),\n ...(questionPayload.debug !== undefined ? { discoveryQuestionsDebug: questionPayload.debug } : {}),\n };\n }\n return {\n found: false,\n count: 0,\n createIntentSuggested: true,\n suggestedIntentDescription: result.suggestedIntentDescription,\n message:\n \"No matching opportunities; add an intent with the suggested description to improve discovery.\",\n debugSteps,\n pagination,\n ...(questionPayload.questions !== undefined ? { questions: questionPayload.questions } : {}),\n ...(questionPayload.debug !== undefined ? { discoveryQuestionsDebug: questionPayload.debug } : {}),\n };\n }\n\n let opportunities: Opportunity[] = Array.isArray(result.opportunities)\n ? result.opportunities\n : [];\n let existingOpportunityIds: Set<string> | undefined;\n const rawExistingBetweenActors = Array.isArray(result.existingBetweenActors)\n ? result.existingBetweenActors\n : [];\n // Orchestrator trigger populates this; ambient returns []. Kept as a\n // loosely-typed pass-through because DiscoverResult is consumed by\n // callers (chat tool, tests) that already model the narrower shape.\n const alreadyAcceptedPairs = Array.isArray(\n (result as { dedupAlreadyAccepted?: Array<{ opportunityId: string; counterpartyUserId: string }> })\n .dedupAlreadyAccepted,\n )\n ? (result as { dedupAlreadyAccepted: Array<{ opportunityId: string; counterpartyUserId: string }> })\n .dedupAlreadyAccepted\n : [];\n // Enrich existing-between-actors with names so the tool can say \"You already have a connection with X (pending).\"\n const existingConnections: ExistingConnection[] = await Promise.all(\n rawExistingBetweenActors.map(async (item) => {\n const user = await database.getUser(item.candidateUserId);\n return {\n userId: item.candidateUserId,\n name: user?.name ?? \"Someone\",\n ...(item.existingStatus ? { status: item.existingStatus } : {}),\n ...(item.existingOpportunityId ? { opportunityId: item.existingOpportunityId } : {}),\n };\n }),\n );\n if (existingConnections.length > 0) {\n discoverFromQueryLog.verbose(\"Skipped duplicates; existing connections\", {\n count: existingConnections.length,\n userIds: existingConnections.map((c) => c.userId),\n });\n }\n // Only expose existing connections as cards when status is in EXISTING_CONNECTION_CARD_STATUSES (draft, latent, pending); others are mention-only.\n const existingConnectionsForCards = existingConnections.filter((c) =>\n c.status != null && EXISTING_CONNECTION_CARD_STATUSES.includes(c.status as typeof EXISTING_CONNECTION_CARD_STATUSES[number])\n );\n\n // Fetch full opportunity data for existing connections that should be shown as cards\n // and merge them with the newly created opportunities\n if (existingConnectionsForCards.length > 0) {\n const existingOpps = await Promise.all(\n existingConnectionsForCards\n .filter((c) => c.opportunityId)\n .map((c) => database.getOpportunity(c.opportunityId!))\n );\n const validExistingOpps = existingOpps.filter((o): o is Opportunity => o != null);\n if (validExistingOpps.length > 0) {\n discoverFromQueryLog.verbose(\"Including existing opportunities as cards\", {\n count: validExistingOpps.length,\n ids: validExistingOpps.map((o) => o.id),\n });\n existingOpportunityIds = new Set(validExistingOpps.map((o) => o.id));\n opportunities = [...opportunities, ...validExistingOpps];\n }\n }\n\n // Chat discovery: when we have chatSessionId we just invoked the graph; all result.opportunities\n // were created in this call and belong to this session. Do not filter by status: the enricher\n // may set status to pending/latent when merging with related opportunities, so filtering to\n // \"draft\" would incorrectly drop them.\n if (chatSessionId && (result.opportunities?.length ?? 0) > 0) {\n discoverFromQueryLog.verbose(\"Chat session opportunities from graph\", {\n count: opportunities.length,\n statuses: opportunities.map((o) => o.status),\n });\n }\n debugSteps.push({\n step: \"opportunity_graph\",\n detail: `${opportunities.length} opportunity(ies)${existingConnections.length > 0 ? `, ${existingConnections.length} existing` : \"\"}`,\n });\n\n if (opportunities.length === 0) {\n if (existingConnections.length > 0) {\n return {\n found: true,\n count: 0,\n message:\n \"No new opportunities created; you already have a connection with: \" +\n existingConnections.map((c) => `${c.name}${c.status ? ` (${c.status})` : \"\"}`).join(\", \") +\n \". View on your home page.\",\n existingConnections: existingConnectionsForCards,\n existingConnectionsForMention: existingConnections,\n ...(alreadyAcceptedPairs.length > 0 && { alreadyAcceptedPairs }),\n debugSteps,\n pagination,\n ...(questionPayload.questions !== undefined ? { questions: questionPayload.questions } : {}),\n ...(questionPayload.debug !== undefined ? { discoveryQuestionsDebug: questionPayload.debug } : {}),\n };\n }\n return {\n found: false,\n count: 0,\n message:\n \"No matching opportunities found. Try a different query or create intents to improve matching.\",\n ...(alreadyAcceptedPairs.length > 0 && { alreadyAcceptedPairs }),\n debugSteps,\n pagination,\n ...(questionPayload.questions !== undefined ? { questions: questionPayload.questions } : {}),\n ...(questionPayload.debug !== undefined ? { discoveryQuestionsDebug: questionPayload.debug } : {}),\n };\n }\n\n const enriched = await enrichOpportunities({\n opportunities,\n database,\n userId,\n chatSessionId,\n minimalForChat: input.minimalForChat,\n presenter: input.presenter,\n useHomeCardFormat: input.useHomeCardFormat,\n debugSteps,\n existingOpportunityIds,\n targetUserId,\n });\n\n return {\n found: true,\n count: enriched.length,\n opportunities: enriched,\n ...(existingConnectionsForCards.length > 0 ? { existingConnections: existingConnectionsForCards } : {}),\n ...(existingConnections.length > 0 ? { existingConnectionsForMention: existingConnections } : {}),\n ...(alreadyAcceptedPairs.length > 0 ? { alreadyAcceptedPairs } : {}),\n debugSteps,\n pagination,\n ...(questionPayload.questions !== undefined ? { questions: questionPayload.questions } : {}),\n ...(questionPayload.debug !== undefined ? { discoveryQuestionsDebug: questionPayload.debug } : {}),\n };\n },\n { context: { userId }, logOutput: false },\n ).catch((err) => {\n return {\n found: false,\n count: 0,\n message: \"Failed to find opportunities. Please try again.\",\n };\n });\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// DECISION-QUESTION HELPER\n// ─────────────────────────────────────────────────────────────────────────────\n\ntype GraphResultLike = {\n sourceProfile?: SourceProfileData | null;\n discoveryNegotiations?: DiscoveryNegotiation[];\n discoverySummary?: DiscoverySummary | null;\n};\n\ninterface MaybeBuildQuestionsInput {\n trigger: 'ambient' | 'orchestrator' | undefined;\n enableQuestions: boolean;\n chatSummary: ChatSummaryReader | undefined;\n questionGenerator: QuestionGeneratorReader | undefined;\n chatSessionId: string | undefined;\n graphResult: GraphResultLike;\n /** Pre-built per-negotiation digests. Pass [] when summarization is unavailable or disabled. */\n negotiationDigests: DiscoveryNegotiationDigest[];\n query: string;\n /** Optional async enqueue callback for background question generation. */\n questionerEnqueue?: DiscoverInput['questionerEnqueue'];\n /** User ID needed for the enqueue payload. */\n userId?: string;\n /** Focused request scope type for generated discovery questions. */\n scopeType?: ToolScopeType;\n /** Focused request scope id. When `scopeType === 'network'`, persisted as actor networkId. */\n scopeId?: string;\n /** Intent that triggered this discovery run. Stamped as `detection.triggeredBy` on generated questions. */\n triggerIntentId?: string;\n /** The seeker's global user_context paragraph (profile-replacing identity text). */\n userContext?: string;\n}\n\n/**\n * Run the negotiation summarizer over every negotiation in this discovery turn.\n * Each summarization is independent — run them concurrently via Promise.all.\n * When the summarizer is missing (no LLM available) or fails for an individual\n * negotiation, fall back to a deterministic digest so the downstream generator\n * still has structured input.\n */\nasync function summarizeNegotiations(args: {\n negotiations: DiscoveryNegotiation[];\n summarizer: NegotiationSummaryReader | undefined;\n enableQuestions: boolean;\n trigger: 'ambient' | 'orchestrator' | undefined;\n}): Promise<DiscoveryNegotiationDigest[]> {\n // Skip the LLM round-trip entirely when questions won't be built.\n if (!args.enableQuestions || args.trigger !== 'orchestrator') return [];\n if (args.negotiations.length === 0) return [];\n\n const perNegTimeoutMs = parsePositiveIntEnv(\n \"NEGOTIATION_SUMMARY_TIMEOUT_MS\",\n NEGOTIATION_SUMMARY_TIMEOUT_MS_DEFAULT,\n );\n const callerSignal = requestContext.getStore()?.abortSignal;\n\n return traceAgent(\n `Negotiation summary (${args.negotiations.length})`,\n () =>\n Promise.all(\n args.negotiations.map(async (n) => {\n if (!args.summarizer) return buildFallbackDigest(n);\n // Per-negotiation deadline: one slow OpenRouter route used to\n // dominate the post-discovery tail. With a cap, an aborted\n // summarizer falls back to a deterministic digest so the\n // question generator still has structured input.\n const signal = combineWithDeadline(callerSignal, perNegTimeoutMs);\n try {\n const d = await args.summarizer.summarize(n, { signal });\n return d ?? buildFallbackDigest(n);\n } catch (err) {\n // Attribute cause from err.name (AbortError), not from\n // signal.aborted — the latter is read post-catch and can race a\n // deadline-trip-after-unrelated-error, producing a misleading log.\n const aborted = err instanceof Error && err.name === \"AbortError\";\n logger.warn(\"negotiationSummary.summarize threw — using fallback digest\", {\n counterpartyHint: n.counterpartyHint,\n aborted,\n error: err instanceof Error ? err.message : String(err),\n });\n return buildFallbackDigest(n);\n }\n }),\n ),\n (digests) => `${digests.length} digest${digests.length === 1 ? \"\" : \"s\"}`,\n );\n}\n\nasync function maybeBuildQuestions(args: MaybeBuildQuestionsInput): Promise<{\n questions?: Question[];\n debug?: DiscoverResult[\"discoveryQuestionsDebug\"];\n}> {\n if (!args.enableQuestions) return {};\n if (args.trigger !== 'orchestrator') return {};\n\n // Hardcoded — `insights` mode is planned for a later slice. Warn if the env\n // var is set so operators aren't surprised when reporting still says\n // \"transcripts\".\n if (discoveryQuestionsInputMode() === \"insights\") {\n logger.warn(\"QUESTIONER_DISCOVERY_INPUT_MODE=insights is not yet implemented; falling back to transcripts\");\n }\n const inputMode: \"transcripts\" | \"insights\" = \"transcripts\";\n\n let chatContext: ChatContextDigest | undefined;\n if (args.chatSummary && args.chatSessionId) {\n const sessionId = args.chatSessionId;\n const summary = args.chatSummary;\n chatContext = await traceAgent(\n \"Chat summary\",\n async () => {\n try {\n return (await summary.getDigest(sessionId)) ?? undefined;\n } catch (err) {\n logger.warn(\"chatSummary.getDigest threw — proceeding without digest\", {\n sessionId,\n error: err instanceof Error ? err.message : String(err),\n });\n return undefined;\n }\n },\n (digest) => (digest ? \"loaded\" : \"empty\"),\n );\n }\n\n // ── Async enqueue path ──────────────────────────────────────────────────\n // When questionerEnqueue is provided, dispatch question generation\n // asynchronously to the background QuestionerQueue. This replaces the\n // inline generator path. Questions will be persisted to DB by the queue\n // worker and served via GET /api/questions.\n if (args.questionerEnqueue && args.userId) {\n const summary = args.graphResult.discoverySummary ?? {\n totalCandidates: 0,\n opportunitiesFound: 0,\n noOpportunityCount: 0,\n timeoutCount: 0,\n roleDistribution: {},\n };\n\n const enqueueInput = buildDiscoveryQuestionInput({\n query: args.query,\n userContext: args.userContext ?? '',\n negotiationDigests: args.negotiationDigests,\n summary,\n chatContext,\n now: new Date().toISOString(),\n });\n\n try {\n await args.questionerEnqueue({\n mode: 'discovery',\n userId: args.userId,\n sourceType: 'discovery',\n sourceId: args.chatSessionId ?? crypto.randomUUID(),\n context: enqueueInput,\n ...(args.scopeType && args.scopeId ? { scopeType: args.scopeType, scopeId: args.scopeId } : {}),\n ...(args.triggerIntentId ? { triggeredByIntentId: args.triggerIntentId } : {}),\n conversationId: args.chatSessionId,\n });\n logger.info(\"Question generation enqueued to QuestionerQueue\", {\n userId: args.userId,\n trigger: args.trigger,\n });\n } catch (err) {\n logger.warn(\"Failed to enqueue question generation\", {\n error: err instanceof Error ? err.message : String(err),\n });\n }\n return {};\n }\n\n // ── Inline generator path (backward compat) ────────────────────────────\n if (!args.questionGenerator) return {};\n\n const negotiationDigests = args.negotiationDigests;\n const summary = args.graphResult.discoverySummary ?? {\n totalCandidates: 0,\n opportunitiesFound: 0,\n noOpportunityCount: 0,\n timeoutCount: 0,\n roleDistribution: {},\n };\n\n const input = buildDiscoveryQuestionInput({\n query: args.query,\n userContext: args.userContext ?? '',\n negotiationDigests,\n summary,\n chatContext,\n now: new Date().toISOString(),\n });\n\n const questionGenerator = args.questionGenerator;\n const generatorStart = Date.now();\n const questionsTimeoutMs = discoveryQuestionsTimeoutMs();\n const questionsSignal = combineWithDeadline(\n requestContext.getStore()?.abortSignal,\n questionsTimeoutMs,\n );\n const genResult = await traceAgent(\n \"Decision questions\",\n async () => {\n try {\n return await questionGenerator.generate(input, { signal: questionsSignal });\n } catch (err) {\n logger.warn(\"questionGenerator.generate threw — suppressing questions\", {\n error: err instanceof Error ? err.message : String(err),\n });\n return null;\n }\n },\n (r) => {\n const count = r?.questions?.length ?? 0;\n return `${count} question${count === 1 ? \"\" : \"s\"}`;\n },\n );\n const durationMs = Date.now() - generatorStart;\n\n const finalCount = genResult?.questions?.length ?? 0;\n const strategies: QuestionStrategy[] = genResult?.strategies ?? [];\n\n return {\n ...(genResult && genResult.questions.length > 0 ? { questions: genResult.questions } : {}),\n debug: {\n inputMode,\n finalCount,\n strategies,\n durationMs,\n },\n };\n}\n\n/**\n * Continue a paginated discovery by evaluating the next batch of cached candidates.\n * Loads candidates from Redis, invokes the opportunity graph in continue_discovery mode,\n * then enriches and returns the results with updated pagination metadata.\n *\n * @param input - Continuation context (graph, database, cache, discoveryId, etc.).\n * @returns Discovery result with enriched opportunities and pagination state.\n */\nexport async function continueDiscovery(input: {\n opportunityGraph: CompiledOpportunityGraph;\n database: ChatGraphCompositeDatabase;\n cache: Cache;\n userId: string;\n discoveryId: string;\n /** If provided, validates the cached session's indexScope contains this network. */\n expectedIndexId?: string;\n limit?: number;\n chatSessionId?: string;\n minimalForChat?: boolean;\n presenter?: OpportunityPresenter;\n useHomeCardFormat?: boolean;\n}): Promise<DiscoverResult> {\n const {\n opportunityGraph,\n database,\n cache,\n userId,\n discoveryId,\n expectedIndexId,\n limit = 20,\n chatSessionId,\n } = input;\n const cacheKey = `discovery:${userId}:${discoveryId}`;\n\n const cached = await cache.get<CachedDiscoverySession>(cacheKey);\n\n if (!cached) {\n return {\n found: false,\n count: 0,\n message: \"Discovery session expired or not found. Please start a new search.\",\n };\n }\n\n // Validate that the cached session's scope matches the current chat context\n if (expectedIndexId && !cached.indexScope.includes(expectedIndexId)) {\n return {\n found: false,\n count: 0,\n message: \"Discovery session was created in a different context. Please start a new search.\",\n };\n }\n\n const debugSteps: DiscoverDebugStep[] = [];\n\n const result = await invokeWithAbortSignal(opportunityGraph, {\n userId,\n searchQuery: cached.query || undefined,\n candidates: cached.candidates,\n operationMode: 'continue_discovery' as const,\n onBehalfOfUserId: cached.onBehalfOfUserId,\n // Carry the original trigger so page 2+ stays on the same flow as page\n // 1 (orchestrator negotiations with 60s park window + accepted-pair\n // dedup, or ambient with 5-min park window).\n ...(cached.trigger && { trigger: cached.trigger }),\n options: {\n ...cached.options,\n limit,\n ...(chatSessionId ? { conversationId: chatSessionId } : {}),\n },\n });\n\n // Extract trace from graph and append to debugSteps\n const graphTrace = result.trace || [];\n for (const t of graphTrace) {\n debugSteps.push({\n step: t.node,\n detail: t.detail,\n ...(t.data ? { data: t.data } : {}),\n });\n }\n\n // Bail early if the graph returned an error\n if (result.error) {\n logger.warn(\"continueDiscovery graph returned error\", { error: result.error });\n return {\n found: false,\n count: 0,\n message: \"Discovery continuation failed. Please start a new search.\",\n debugSteps,\n };\n }\n\n // Update cache with remaining candidates or delete if exhausted\n const remaining: CandidateMatch[] = result.remainingCandidates || [];\n let pagination: DiscoverResult['pagination'] | undefined;\n try {\n if (remaining.length > 0) {\n await cache.set(cacheKey, {\n ...cached,\n candidates: remaining,\n } satisfies CachedDiscoverySession, { ttl: 1800 });\n pagination = {\n discoveryId,\n evaluated: cached.candidates.length - remaining.length,\n remaining: remaining.length,\n };\n } else {\n await cache.delete(cacheKey);\n }\n } catch (cacheErr) {\n logger.warn(\"Failed to update discovery pagination cache\", {\n userId,\n discoveryId,\n error: cacheErr instanceof Error ? cacheErr.message : String(cacheErr),\n });\n }\n\n // Check for opportunities in result\n const opportunities: Opportunity[] = Array.isArray(result.opportunities) ? result.opportunities : [];\n\n if (opportunities.length === 0) {\n return {\n found: false,\n count: 0,\n message: \"No more matching opportunities found in the remaining candidates.\",\n debugSteps,\n pagination,\n };\n }\n\n const enriched = await enrichOpportunities({\n opportunities,\n database,\n userId,\n chatSessionId,\n minimalForChat: input.minimalForChat,\n presenter: input.presenter,\n useHomeCardFormat: input.useHomeCardFormat,\n debugSteps,\n });\n\n return {\n found: true,\n count: enriched.length,\n opportunities: enriched,\n debugSteps,\n pagination,\n };\n}\n"]}
1
+ {"version":3,"file":"opportunity.discover.js","sourceRoot":"/","sources":["opportunity/opportunity.discover.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH,OAAO,EAAE,2BAA2B,EAAE,2BAA2B,EAAE,MAAM,iCAAiC,CAAC;AAE3G,OAAO,EAAwB,sBAAsB,EAA4H,MAAM,4BAA4B,CAAC;AACpN,OAAO,EAAE,2BAA2B,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACrH,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AAC5E,OAAO,EAAE,mBAAmB,EAAE,MAAM,oCAAoC,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAM7F,OAAO,EAAE,mBAAmB,EAAE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AAC,OAAO,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC;IAErG,IAAI,aAAa,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC/B,OAAO;YACL,KAAK,EAAE,KAAK;YACZ,KAAK,EAAE,CAAC;YACR,OAAO,EAAE,mEAAmE;YAC5E,UAAU;YACV,UAAU;SACX,CAAC;IACJ,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,mBAAmB,CAAC;QACzC,aAAa;QACb,QAAQ;QACR,MAAM;QACN,aAAa;QACb,cAAc,EAAE,KAAK,CAAC,cAAc;QACpC,SAAS,EAAE,KAAK,CAAC,SAAS;QAC1B,iBAAiB,EAAE,KAAK,CAAC,iBAAiB;QAC1C,UAAU;KACX,CAAC,CAAC;IAEH,OAAO;QACL,KAAK,EAAE,IAAI;QACX,KAAK,EAAE,QAAQ,CAAC,MAAM;QACtB,aAAa,EAAE,QAAQ;QACvB,UAAU;QACV,UAAU;KACX,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Run discovery from an ad-hoc query (e.g. chat \"find me a mentor\", \"who needs a React developer\").\n *\n * Invokes the opportunity graph with the query as sourceText. The HyDE graph's\n * LensInferrer automatically infers search lenses from the query, replacing the\n * old hardcoded strategy selection. Returns formatted candidates (enriched with\n * profile name/bio) for chat display.\n *\n * Used by the discover_opportunities chat tool.\n */\n\nimport type { Opportunity, ChatGraphCompositeDatabase, UserRecord } from \"../shared/interfaces/database.interface.js\";\nimport type { Cache } from \"../shared/interfaces/cache.interface.js\";\nimport type { OpportunityGraphOptions, CandidateMatch, SourceProfileData } from \"./opportunity.state.js\";\nimport type { DiscoveryNegotiation, DiscoverySummary } from \"./question.prompt.js\";\nimport type { QuestionerEnqueueFn } from \"../questioner/questioner.types.js\";\nimport { discoveryQuestionsInputMode, discoveryQuestionsTimeoutMs } from \"../questioner/questioner.env.js\";\nimport type { ToolScopeType } from \"../shared/agent/tool.scope.js\";\nimport { OpportunityPresenter, gatherPresenterContext, type OpportunityPresentationResult, type HomeCardPresentationResult, type HomeCardLLMResult, type HomeCardPresenterInput } from \"./opportunity.presenter.js\";\nimport { MINIMAL_MAIN_TEXT_MAX_CHARS, getPrimaryActionLabel, SECONDARY_ACTION_LABEL } from \"./opportunity.labels.js\";\nimport { narratorRemarkFromReasoning } from \"./opportunity.presentation.js\";\nimport { safeFallbackSummary } from \"./opportunity.safe-presentation.js\";\nimport { protocolLogger, withCallLogging } from \"../shared/observability/protocol.logger.js\";\nimport type { ChatSummaryReader } from \"../shared/interfaces/chat-summary.interface.js\";\nimport type { ChatContextDigest } from \"../shared/schemas/chat-context.schema.js\";\nimport type { QuestionGeneratorReader } from \"../shared/interfaces/question-generator.interface.js\";\nimport type { NegotiationSummaryReader } from \"../shared/interfaces/negotiation-summary.interface.js\";\nimport type { DiscoveryNegotiationDigest } from \"../shared/schemas/negotiation-digest.schema.js\";\nimport { buildFallbackDigest } from \"../negotiation/negotiation.summarizer.js\";\nimport type { Question, QuestionStrategy } from \"../shared/schemas/question.schema.js\";\nimport { traceAgent, tracePhase } from \"../shared/observability/trace.js\";\nimport { requestContext } from \"../shared/observability/request-context.js\";\nimport { buildDiscoveryQuestionInput } from \"./discovery-question.helper.js\";\nimport { invokeWithAbortSignal } from \"../shared/agent/model-signal.js\";\n\nconst logger = protocolLogger(\"OpportunityDiscover\");\nconst discoverFromQueryLog = protocolLogger(\"OpportunityDiscover:runDiscoverFromQuery\");\nconst enrichLog = protocolLogger(\"OpportunityDiscover:enrichOpportunities\");\n\n/**\n * Per-negotiation summarizer budget. The summarizer fires one LLM call per\n * partial-or-full negotiation (concurrently via Promise.all). Without a cap\n * one slow OpenRouter route dominates the post-discovery tail and pushes the\n * whole MCP response past Railway's ~60 s no-upstream-bytes timeout. Falls\n * back to a deterministic digest when the deadline fires, so question\n * generation still has structured input.\n */\nconst NEGOTIATION_SUMMARY_TIMEOUT_MS_DEFAULT = 5_000;\n\n/**\n * Parse a positive integer env var, clamped to the safe-integer range so a\n * malformed env value cannot crash `AbortSignal.timeout` (which throws on\n * values outside `[0, MAX_SAFE_INTEGER]`). Mirrors the precedent in\n * `negotiation.agent.ts` (`isValidTimeoutMs`).\n */\nfunction parsePositiveIntEnv(name: string, fallback: number): number {\n const raw = process.env[name];\n if (!raw) return fallback;\n const n = Number.parseInt(raw, 10);\n if (!Number.isFinite(n) || n <= 0 || n > Number.MAX_SAFE_INTEGER) return fallback;\n return n;\n}\n\nfunction combineWithDeadline(\n callerSignal: AbortSignal | undefined,\n deadlineMs: number,\n): AbortSignal {\n const deadline = AbortSignal.timeout(deadlineMs);\n if (!callerSignal) return deadline;\n return AbortSignal.any([callerSignal, deadline]);\n}\n\n/** Compiled opportunity graph (from OpportunityGraphFactory.createGraph()). */\nexport type CompiledOpportunityGraph = ReturnType<\n import(\"./opportunity.graph.js\").OpportunityGraphFactory[\"createGraph\"]\n>;\n\nexport interface DiscoverInput {\n /** Compiled opportunity graph (already has DB, embedder, cache, HyDE graph). */\n opportunityGraph: CompiledOpportunityGraph;\n /** Database for enriching candidates with profile (getProfile). */\n database: ChatGraphCompositeDatabase;\n userId: string;\n query: string;\n indexScope: string[];\n limit?: number;\n /** Optional intent to use as discovery source and for triggeredBy (e.g. from opportunity queue). */\n triggerIntentId?: string;\n /** When set, filter discovery candidates to this specific user only (direct connection). */\n targetUserId?: string;\n /** When set, discover on behalf of this user (introducer flow). The caller (userId) becomes the introducer. */\n onBehalfOfUserId?: string;\n /** When provided, each opportunity is enriched with personalized presentation (headline, personalizedSummary, suggestedAction). */\n presenter?: OpportunityPresenter;\n /**\n * When true, use the full home card presentation format (with narratorRemark, action labels, mutualIntentsLabel).\n * This enables rendering the same rich opportunity cards in chat as on the home page.\n */\n useHomeCardFormat?: boolean;\n /**\n * When true, skip the LLM presenter and return minimal card data only (faster for chat).\n * Sets homeCardPresentation and narratorChip from static labels and match reason.\n */\n minimalForChat?: boolean;\n /** When set (e.g. from chat), create opportunities as draft with context.conversationId = chatSessionId. */\n chatSessionId?: string;\n /** Redis cache for discovery pagination. When provided, remaining candidates are cached for continuation. */\n cache?: Cache;\n /**\n * Which flow is invoking discovery. Drives the graph's trigger-aware branches\n * in persist (initial status) and negotiate (park window + streaming). When\n * omitted, the graph defaults to 'ambient'. Pass 'orchestrator' from the\n * chat `discover_opportunities` tool so users see drafts stream in and the\n * accepted-pair lookup surfaces existing connections.\n */\n trigger?: 'ambient' | 'orchestrator';\n /**\n * MCP-only. When set, the opportunity graph's negotiate phase is capped at\n * this many milliseconds; on timeout the caller gets whichever candidates\n * finished, the rest stay in `negotiating` and finalize in the background.\n * Chat, ambient queue, and all other callers omit this — existing behavior.\n */\n negotiateTimeoutMs?: number;\n /** Optional read-through chat-session digest reader. Required for chatContext enrichment. */\n chatSummary?: ChatSummaryReader;\n /**\n * Optional negotiation summarizer. When provided, each post-negotiation digest\n * replaces the raw negotiation in the decision-question generator's input,\n * keeping that prompt small and predictable regardless of candidate count.\n * When omitted, a deterministic fallback digest is built per negotiation.\n */\n negotiationSummary?: NegotiationSummaryReader;\n /** Optional decision-question generator. When omitted, no questions are produced. */\n questionGenerator?: QuestionGeneratorReader;\n /**\n * Master switch for decision-question generation. When false, this code path\n * is skipped entirely regardless of trigger. The composition root passes\n * `isDiscoveryQuestionsEnabled()` (QUESTIONER_ENABLED + QUESTIONER_DISCOVERY_ENABLED).\n */\n enableQuestions?: boolean;\n /**\n * Optional async question enqueue callback. When provided, question generation\n * is dispatched asynchronously to the QuestionerQueue instead of running inline\n * via the `questionGenerator`. The callback receives an enqueue payload and\n * returns a promise that resolves when the job is enqueued (not when generation\n * completes).\n */\n questionerEnqueue?: QuestionerEnqueueFn;\n /** Focused request scope type for generated discovery questions. */\n scopeType?: ToolScopeType;\n /** Focused request scope id. When `scopeType === 'network'`, persisted as actor networkId. */\n scopeId?: string;\n}\n\n/** Context used by the minimal (no-LLM) path; only introducerName is needed for narrator chip. */\ntype MinimalPresenterContext = { introducerName?: string };\n\n/** Max chars for bio and matchReason in chat tool results to keep context manageable. */\nconst MAX_FIELD_CHARS = 100;\n\nfunction truncateForChat(\n s: string | undefined,\n max = MAX_FIELD_CHARS,\n): string | undefined {\n if (s == null || s === \"\") return undefined;\n const trimmed = s.trim();\n if (trimmed.length <= max) return trimmed;\n return trimmed.slice(0, max) + \"...\";\n}\n\n/** One formatted opportunity for chat (candidate-facing). */\nexport interface FormattedDiscoveryCandidate {\n opportunityId: string;\n userId: string;\n name?: string;\n avatar?: string | null;\n bio?: string;\n matchReason: string;\n score: number;\n status?: string;\n /** Present when DiscoverInput.presenter was provided (basic presentation). */\n presentation?: OpportunityPresentationResult;\n /** Present when DiscoverInput.useHomeCardFormat is true (full home card contract). */\n homeCardPresentation?: HomeCardPresentationResult;\n /** Viewer's role in this opportunity. */\n viewerRole?: string;\n /** Whether the viewer (as introducer) has approved the introduction. */\n viewerApproved?: boolean;\n /** Timestamp set once this viewer has already acted on the opportunity. */\n viewerActedAt?: string | null;\n /** Full user record for the candidate (needed for socials / Telegram fallback). */\n candidateUser?: UserRecord | null;\n /** Whether the counterpart is a ghost (not yet onboarded) user. */\n isGhost?: boolean;\n /** Narrator chip for home card display (name + remark, with optional avatar/userId for introducer). */\n narratorChip?: {\n name: string;\n text: string;\n avatar?: string | null;\n userId?: string;\n };\n /** Second party in introducer arrow layout (candidate -> secondParty). Present when viewer is introducer. */\n secondParty?: {\n name: string;\n avatar?: string | null;\n userId?: string;\n };\n}\n\n/** One step for debug visibility (subgraph/subtask). */\nexport interface DiscoverDebugStep {\n step: string;\n detail?: string;\n /** Structured data for rich display (e.g., candidate counts, scores). */\n data?: Record<string, unknown>;\n}\n\n/** One existing connection (no new opportunity created; user already has one with this person). */\nexport interface ExistingConnection {\n userId: string;\n name: string;\n status?: string;\n opportunityId?: string;\n}\n\n/** Statuses for which an existing connection may be shown as a card; others (accepted, rejected, expired) are only mentioned in text. */\nconst EXISTING_CONNECTION_CARD_STATUSES = ['draft', 'latent', 'pending'] as const;\n\nexport interface DiscoverResult {\n found: boolean;\n count: number;\n message?: string;\n opportunities?: FormattedDiscoveryCandidate[];\n /** Existing connections eligible for card display (draft, latent, or pending). Others are mention-only. */\n existingConnections?: ExistingConnection[];\n /** All existing connections for mention text (e.g. \"You already have a connection with: X (pending), Y (draft).\"). */\n existingConnectionsForMention?: ExistingConnection[];\n /**\n * Orchestrator-only: accepted opportunities the persist step found between the\n * discoverer and a candidate counterparty (status='accepted'). Populated from\n * OpportunityGraphState.dedupAlreadyAccepted. Used by the discover_opportunities\n * tool to tell the LLM \"this pair is already connected — open the existing\n * chat rather than creating a new draft\". Empty for the ambient trigger.\n */\n alreadyAcceptedPairs?: Array<{ opportunityId: string; counterpartyUserId: string }>;\n /** When true, the chat agent should call create_intent(suggestedIntentDescription) and retry discovery. */\n createIntentSuggested?: boolean;\n /** Description to pass to create_intent when createIntentSuggested is true. */\n suggestedIntentDescription?: string;\n /** Internal steps for copy-debug (select_strategies, opportunity_graph, enrich, etc.). */\n debugSteps?: DiscoverDebugStep[];\n /** Pagination metadata -- present when there are more unevaluated candidates. */\n pagination?: {\n discoveryId: string;\n evaluated: number;\n remaining: number;\n };\n /** 0–3 decision questions produced by the orchestrator path. Omitted when none. */\n questions?: Question[];\n /** Debug metadata for `debugMeta.discoveryQuestions` plumbing. */\n discoveryQuestionsDebug?: {\n inputMode: \"transcripts\" | \"insights\";\n finalCount: number;\n strategies: QuestionStrategy[];\n durationMs: number;\n };\n}\n\n/** Input for the shared enrichment helper. */\ninterface EnrichOpportunitiesInput {\n opportunities: Opportunity[];\n database: ChatGraphCompositeDatabase;\n userId: string;\n chatSessionId?: string;\n minimalForChat?: boolean;\n presenter?: OpportunityPresenter;\n useHomeCardFormat?: boolean;\n debugSteps: DiscoverDebugStep[];\n /** IDs of pre-existing opportunities merged into the list; these preserve their real status. */\n existingOpportunityIds?: Set<string>;\n /** When set, bypass the embedding filter for this specific user (direct connection mode). */\n targetUserId?: string;\n}\n\n/**\n * Enrich raw opportunities with profile data, presentation (LLM or minimal),\n * and narrator chips. Shared by both `runDiscoverFromQuery` and `continueDiscovery`\n * to avoid duplicating the profile-lookup / presenter / card-formatting logic.\n *\n * @param input - Enrichment context (opportunities, database, viewer, presentation options).\n * @returns Formatted discovery candidates ready for chat or home card display.\n */\nasync function enrichOpportunities(\n input: EnrichOpportunitiesInput,\n): Promise<FormattedDiscoveryCandidate[]> {\n const {\n opportunities,\n database,\n userId,\n chatSessionId,\n minimalForChat,\n presenter,\n useHomeCardFormat,\n debugSteps,\n existingOpportunityIds,\n targetUserId,\n } = input;\n\n const baseEnrichedRaw = await Promise.all(\n opportunities.map(async (opp) => {\n const viewerIsIntroducer = opp.actors.some((a) => a.role === 'introducer' && a.userId === userId);\n // When the viewer is the introducer, the \"candidate\" for the card is the agent\n // (the discovered person), not the patient (the intro target / onBehalfOfUserId).\n // For non-introducer views, pick the first non-viewer, non-introducer actor.\n const nonViewerNonIntroducerActors = opp.actors.filter((a) => a.userId !== userId && a.role !== 'introducer');\n const candidateActor = viewerIsIntroducer\n ? (nonViewerNonIntroducerActors.find((a) => a.role === 'agent') ?? nonViewerNonIntroducerActors[0])\n : nonViewerNonIntroducerActors[0];\n const candidateUserId = candidateActor?.userId ?? \"\";\n const viewerActor = opp.actors.find((a) => a.userId === userId);\n const [profile, candidateUser] = candidateUserId\n ? await Promise.all([database.getProfile(candidateUserId), database.getUser(candidateUserId)])\n : [null, null];\n // Skip soft-deleted users (deletedAt is set)\n if (candidateUser && 'deletedAt' in candidateUser && candidateUser.deletedAt) return null;\n const isDirectTarget = targetUserId && candidateUserId === targetUserId;\n if (!isDirectTarget && !candidateUser?.isGhost && !profile) return null;\n const confidence =\n typeof opp.interpretation?.confidence === \"number\"\n ? opp.interpretation.confidence\n : parseFloat(String(opp.interpretation?.confidence ?? 0)) || 0;\n return {\n opportunity: opp,\n candidateUserId,\n viewerRole: viewerActor?.role ?? \"party\",\n viewerApproved: viewerActor?.approved === true,\n viewerActedAt: viewerActor?.actedAt ?? null,\n candidateUser,\n profile,\n confidence,\n };\n }),\n );\n const baseEnriched = baseEnrichedRaw.filter((item): item is NonNullable<typeof item> => item !== null);\n debugSteps.push({\n step: \"enrich_profiles\",\n detail: `${baseEnriched.length} profile(s)`,\n });\n\n // Batch-fetch user records (candidates, introducers, and other party actors) for name/avatar fallback.\n const allActorUserIds = new Set<string>();\n for (const item of baseEnriched) {\n for (const actor of item.opportunity.actors) {\n if (actor.userId && actor.userId !== userId) {\n allActorUserIds.add(actor.userId);\n }\n }\n }\n const candidateUserIds = [...allActorUserIds];\n const [viewerUser, ...userResults] = await Promise.all([\n database.getUser(userId),\n ...candidateUserIds.map((id) => database.getUser(id)),\n ]);\n const avatarByUserId = new Map<string, string | null>();\n const nameByUserId = new Map<string, string | null>();\n const isGhostByUserId = new Map<string, boolean>();\n candidateUserIds.forEach((id, i) => {\n const user = userResults[i] ?? null;\n avatarByUserId.set(id, user?.avatar ?? null);\n nameByUserId.set(id, user?.name ?? null);\n isGhostByUserId.set(id, user?.isGhost ?? false);\n });\n const viewerName = viewerUser?.name ?? undefined;\n\n // Retry name resolution for candidates whose name is still missing.\n // The profile or user record may not have been ready on the first fetch\n // (e.g. profile generation still in flight). One retry covers transient gaps.\n const missingNameIds = baseEnriched\n .map((item) => item.candidateUserId)\n .filter((id) => id && !nameByUserId.get(id) && !baseEnriched.find((b) => b.candidateUserId === id && b.profile?.identity?.name));\n if (missingNameIds.length > 0) {\n const retried = await Promise.all(\n missingNameIds.map(async (id) => {\n const [profile, user] = await Promise.all([\n database.getProfile(id),\n database.getUser(id),\n ]);\n return { id, profile, user };\n }),\n );\n for (const r of retried) {\n const name = r.profile?.identity?.name ?? r.user?.name ?? null;\n if (name) nameByUserId.set(r.id, name);\n // Also update the baseEnriched profile so counterpartName picks it up\n if (r.profile) {\n const item = baseEnriched.find((b) => b.candidateUserId === r.id);\n if (item && !item.profile) item.profile = r.profile;\n }\n if (r.user?.avatar && !avatarByUserId.get(r.id)) {\n avatarByUserId.set(r.id, r.user.avatar);\n }\n }\n enrichLog.verbose(\"Retried name lookup for candidates with missing names\", {\n attempted: missingNameIds.length,\n resolved: retried.filter((r) => r.profile?.identity?.name ?? r.user?.name).length,\n });\n }\n\n let presentations: OpportunityPresentationResult[] | undefined;\n let homeCardPresentations: HomeCardPresentationResult[] | undefined;\n let presenterContexts:\n | (Awaited<ReturnType<typeof gatherPresenterContext>> | MinimalPresenterContext)[]\n | undefined;\n\n if (minimalForChat && baseEnriched.length > 0) {\n // Minimal path: no LLM, viewer-centric card text (introduce counterpart to viewer)\n const counterpartName = (n: {\n profile?: { identity?: { name?: string } } | null;\n candidateUserId: string;\n }) => n.profile?.identity?.name ?? nameByUserId.get(n.candidateUserId) ?? \"\";\n homeCardPresentations = baseEnriched.map((item) => {\n const name = counterpartName(item)?.trim();\n const reasoning = item.opportunity.interpretation?.reasoning ?? \"\";\n const introducerName = item.opportunity.detection?.createdByName ?? undefined;\n const viewerIsIntroducer = item.opportunity.actors.some(\n (a) => a.role === \"introducer\" && a.userId === userId,\n );\n\n // For introducer view, find the second party (target user) name\n let secondPartyName: string | undefined;\n if (viewerIsIntroducer) {\n const otherPartyActors = item.opportunity.actors.filter(\n (a) => a.role !== \"introducer\" && a.userId !== item.candidateUserId,\n );\n if (otherPartyActors.length > 0) {\n const otherUserId = otherPartyActors[0].userId;\n secondPartyName = nameByUserId.get(otherUserId) ?? undefined;\n }\n }\n\n const isCounterpartGhost = isGhostByUserId.get(item.candidateUserId) ?? false;\n // Shared sanitization standard — see opportunity.safe-presentation.ts.\n const personalizedSummary = safeFallbackSummary(reasoning, {\n counterpartName: name,\n viewerName,\n introducerName,\n maxChars: MINIMAL_MAIN_TEXT_MAX_CHARS,\n emptyText: \"A suggested connection.\",\n });\n return {\n headline: viewerIsIntroducer && secondPartyName\n ? `${name} → ${secondPartyName}`\n : (name ? `Connection with ${name}` : \"Suggested connection\"),\n personalizedSummary,\n digestSummary: name\n ? `You might like meeting ${name} based on your current interests.`\n : \"This connection may be relevant to your current interests.\",\n suggestedAction: \"Start a conversation to connect.\",\n narratorRemark: narratorRemarkFromReasoning(reasoning, name, viewerName),\n primaryActionLabel: getPrimaryActionLabel(viewerIsIntroducer ? \"introducer\" : \"party\"),\n secondaryActionLabel: SECONDARY_ACTION_LABEL,\n mutualIntentsLabel: \"Suggested connection\",\n greeting: \"\",\n };\n });\n presenterContexts = baseEnriched.map((item) => ({\n introducerName: item.opportunity.detection.createdByName ?? undefined,\n })) as MinimalPresenterContext[];\n } else if (presenter && baseEnriched.length > 0) {\n try {\n presenterContexts = await Promise.all(\n baseEnriched.map(({ opportunity }) =>\n gatherPresenterContext(database, opportunity, userId),\n ),\n );\n\n if (useHomeCardFormat) {\n // Use full home card format with action labels, narrator remark, etc.\n const fullContexts = presenterContexts as Awaited<\n ReturnType<typeof gatherPresenterContext>\n >[];\n const homeCardInputs: HomeCardPresenterInput[] = fullContexts.map(\n (ctx, idx) => ({\n ...ctx,\n mutualIntentCount: undefined,\n opportunityStatus: baseEnriched[idx].opportunity.status,\n }),\n );\n const llmResults = await presenter.presentHomeCardBatch(\n homeCardInputs,\n { concurrency: 5 },\n );\n // Append hardcoded button labels to LLM results\n homeCardPresentations = llmResults.map((llm, idx) => ({\n ...llm,\n primaryActionLabel: getPrimaryActionLabel(baseEnriched[idx].viewerRole),\n secondaryActionLabel: SECONDARY_ACTION_LABEL,\n }));\n } else {\n // Use basic presentation format\n presentations = await presenter.presentBatch(\n presenterContexts as Awaited<\n ReturnType<typeof gatherPresenterContext>\n >[],\n {\n concurrency: 5,\n },\n );\n }\n } catch (error) {\n logger.warn(\n \"Presenter enrichment failed during opportunity discovery; returning base results without presentations\",\n {\n userId,\n opportunitiesCount: baseEnriched.length,\n useHomeCardFormat,\n error: error instanceof Error ? error.message : String(error),\n },\n );\n presentations = undefined;\n homeCardPresentations = undefined;\n }\n }\n\n const enriched: FormattedDiscoveryCandidate[] = baseEnriched.map(\n (item, idx) => {\n const homeCard = homeCardPresentations?.[idx];\n const ctx = presenterContexts?.[idx];\n\n // Build narrator chip for home card format\n let narratorChip: FormattedDiscoveryCandidate[\"narratorChip\"];\n if (homeCard) {\n const viewerIsIntroducer = item.opportunity.actors.some(\n (a) => a.role === \"introducer\" && a.userId === userId,\n );\n if (viewerIsIntroducer) {\n narratorChip = {\n name: \"You\",\n text: homeCard.narratorRemark,\n userId: userId,\n };\n } else {\n const introducerActor = item.opportunity.actors.find(\n (a) => a.role === \"introducer\" && a.userId !== userId,\n );\n if (introducerActor) {\n const introducerName =\n ctx?.introducerName ??\n nameByUserId.get(introducerActor.userId) ??\n \"Someone\";\n narratorChip = {\n name: introducerName,\n text: homeCard.narratorRemark,\n userId: introducerActor.userId,\n avatar: avatarByUserId.get(introducerActor.userId) ?? null,\n };\n } else {\n narratorChip = {\n name: \"Index\",\n text: homeCard.narratorRemark,\n };\n }\n }\n }\n\n const isGhost = isGhostByUserId.get(item.candidateUserId) ?? false;\n\n // Build secondParty for introducer view (the other non-introducer party)\n let secondParty: FormattedDiscoveryCandidate[\"secondParty\"];\n const viewerIsIntroducerForCard = item.opportunity.actors.some(\n (a) => a.role === \"introducer\" && a.userId === userId,\n );\n if (viewerIsIntroducerForCard) {\n const otherPartyActor = item.opportunity.actors.find(\n (a) => a.role !== \"introducer\" && a.userId !== item.candidateUserId,\n );\n if (otherPartyActor) {\n const otherName = nameByUserId.get(otherPartyActor.userId) ?? undefined;\n if (otherName) {\n secondParty = {\n name: otherName,\n avatar: avatarByUserId.get(otherPartyActor.userId) ?? null,\n userId: otherPartyActor.userId,\n };\n }\n }\n }\n\n return {\n opportunityId: item.opportunity.id,\n userId: item.candidateUserId,\n name: item.profile?.identity?.name ?? nameByUserId.get(item.candidateUserId) ?? undefined,\n avatar: avatarByUserId.get(item.candidateUserId) ?? null,\n bio: truncateForChat(item.profile?.identity?.bio),\n matchReason: safeFallbackSummary(\n item.opportunity.interpretation?.reasoning,\n {\n counterpartName: item.profile?.identity?.name ?? nameByUserId.get(item.candidateUserId) ?? undefined,\n viewerName,\n maxChars: MAX_FIELD_CHARS,\n emptyText: \"A suggested connection.\",\n },\n ),\n score: item.confidence,\n status: chatSessionId && !existingOpportunityIds?.has(item.opportunity.id) ? \"draft\" : item.opportunity.status,\n viewerRole: item.viewerRole,\n viewerApproved: item.viewerApproved,\n viewerActedAt: item.viewerActedAt,\n candidateUser: item.candidateUser,\n isGhost,\n ...(presentations?.[idx] && { presentation: presentations[idx] }),\n ...(homeCard && {\n homeCardPresentation: homeCard,\n }),\n ...(narratorChip && { narratorChip }),\n ...(secondParty && { secondParty }),\n };\n },\n );\n debugSteps.push({\n step: \"format_cards\",\n detail: `${enriched.length} card(s)`,\n });\n\n return enriched;\n}\n\n/** Cached discovery session data stored in Redis. */\ninterface CachedDiscoverySession {\n candidates: CandidateMatch[];\n userId: string;\n onBehalfOfUserId?: string;\n query: string;\n indexScope: string[];\n options: OpportunityGraphOptions;\n /**\n * Carried across pagination so page 2+ stays on the same flow as page 1.\n * Without this, orchestrator runs would fall back to the 'ambient' default\n * mid-search and lose the shorter park window + accepted-pair dedup.\n */\n trigger?: 'ambient' | 'orchestrator';\n}\n\n/**\n * Run discovery from an ad-hoc query (e.g. \"find me a mentor\", \"who needs a React developer\").\n * The HyDE graph's LensInferrer automatically infers search lenses from the query.\n * Invokes the opportunity graph and returns formatted candidates suitable for chat display.\n */\nexport async function runDiscoverFromQuery(\n input: DiscoverInput,\n): Promise<DiscoverResult> {\n const {\n opportunityGraph,\n database,\n userId,\n query,\n indexScope,\n limit = 5,\n triggerIntentId,\n targetUserId,\n onBehalfOfUserId,\n chatSessionId,\n trigger,\n negotiateTimeoutMs,\n } = input;\n\n if (indexScope.length === 0) {\n return {\n found: false,\n count: 0,\n message:\n \"You need to join at least one network (community) to discover opportunities. Use read_networks to see available networks, or create one.\",\n };\n }\n\n const debugSteps: DiscoverDebugStep[] = [];\n\n // When query is empty, the opportunity graph uses the user's intents in scope (indexedIntents[0].payload)\n // Lens inference is handled automatically by the HyDE graph's LensInferrer\n const queryOrEmpty = query?.trim() ?? \"\";\n // Orchestrator discovery defers the initial status to the graph's\n // trigger-aware `resolveInitialStatus`, which opens at 'negotiating' so\n // the accepted-draft streaming flow can run. Ambient chat discovery still\n // wants the legacy 'draft' status so the chat-only lifecycle holds; other\n // ambient callers keep 'latent'.\n const isOrchestrator = trigger === 'orchestrator';\n const options: OpportunityGraphOptions = {\n limit,\n ...(!isOrchestrator && { initialStatus: chatSessionId ? \"draft\" : \"latent\" }),\n ...(chatSessionId ? { conversationId: chatSessionId } : {}),\n ...(negotiateTimeoutMs !== undefined && { negotiateTimeoutMs }),\n };\n\n return withCallLogging(\n logger,\n \"runDiscoverFromQuery\",\n {\n userId,\n queryPreview: queryOrEmpty\n ? queryOrEmpty.substring(0, 50)\n : \"(using user intents in scope)\",\n indexScopeCount: indexScope.length,\n limit,\n },\n async () => {\n const result = await invokeWithAbortSignal(opportunityGraph, {\n userId,\n searchQuery: queryOrEmpty || undefined,\n // A single index resolves to the strict networkId override (membership-\n // validated in the scope node). Multiple indexes (e.g. a network-scoped\n // agent's bound network + personal network) pass through as indexScope so\n // the graph stays bounded instead of falling back to all networks.\n networkId: indexScope.length === 1 ? indexScope[0] : undefined,\n ...(indexScope.length > 1 ? { indexScope } : {}),\n triggerIntentId,\n targetUserId,\n onBehalfOfUserId,\n options,\n ...(trigger && { trigger }),\n });\n\n // Extract trace from graph and append to debugSteps\n const graphTrace = Array.isArray(result.trace) ? result.trace : [];\n for (const t of graphTrace) {\n debugSteps.push({\n step: t.node,\n detail: t.detail,\n ...(t.data ? { data: t.data } : {}),\n });\n }\n\n // Bail early if the graph returned an error\n if (result.error) {\n logger.warn(\"runDiscoverFromQuery graph returned error\", { error: result.error });\n return {\n found: false,\n count: 0,\n message: \"Failed to find opportunities. Please try again.\",\n debugSteps,\n };\n }\n\n // Cache remaining candidates for pagination\n let pagination: DiscoverResult['pagination'] | undefined;\n const remainingCandidates: CandidateMatch[] = result.remainingCandidates || [];\n if (remainingCandidates.length > 0 && input.cache) {\n try {\n const discoveryId = crypto.randomUUID();\n const cacheKey = `discovery:${userId}:${discoveryId}`;\n await input.cache.set(cacheKey, {\n candidates: remainingCandidates,\n userId,\n onBehalfOfUserId,\n query: queryOrEmpty,\n indexScope,\n options,\n ...(trigger && { trigger }),\n } satisfies CachedDiscoverySession, { ttl: 1800 }); // 30 minutes\n pagination = {\n discoveryId,\n evaluated: (result.candidates?.length ?? 0) - remainingCandidates.length,\n remaining: remainingCandidates.length,\n };\n } catch (cacheErr) {\n logger.warn(\"Failed to cache discovery pagination\", {\n userId,\n error: cacheErr instanceof Error ? cacheErr.message : String(cacheErr),\n });\n }\n }\n\n // Refine phase: a sibling of the opportunity graph in the trace tree.\n // Holds the three post-discovery summarization steps. Each step is its\n // own traced agent so it appears as a leaf in the trace UI.\n //\n // Negotiation summary: compress each raw negotiation into a fixed-size\n // structured digest so the question generator's prompt stays small\n // (a 10-candidate turn used to balloon past 60 KB and stall upstream).\n // Decision questions: generate up to 3 clarifying questions from the\n // digests + chat context.\n const { questionPayload } = await tracePhase(\"Refine\", async () => {\n const negotiationDigests = await summarizeNegotiations({\n negotiations: result.discoveryNegotiations ?? [],\n summarizer: input.negotiationSummary,\n enableQuestions: input.enableQuestions ?? false,\n trigger,\n });\n const questionPayload = await maybeBuildQuestions({\n trigger,\n enableQuestions: input.enableQuestions ?? false,\n chatSummary: input.chatSummary,\n questionGenerator: input.questionGenerator,\n chatSessionId,\n graphResult: result,\n negotiationDigests,\n query: queryOrEmpty,\n questionerEnqueue: input.questionerEnqueue,\n userId: input.userId,\n scopeType: input.scopeType,\n scopeId: input.scopeId,\n triggerIntentId,\n userContext: input.userId\n ? ((await input.database.getUserContext(input.userId, null))?.text ?? '')\n : '',\n });\n return { negotiationDigests, questionPayload };\n });\n\n if (result.createIntentSuggested && result.suggestedIntentDescription) {\n if (chatSessionId) {\n return {\n found: false,\n count: 0,\n message: \"No matching opportunities found. Try a different query.\",\n pagination,\n ...(questionPayload.questions !== undefined ? { questions: questionPayload.questions } : {}),\n ...(questionPayload.debug !== undefined ? { discoveryQuestionsDebug: questionPayload.debug } : {}),\n };\n }\n return {\n found: false,\n count: 0,\n createIntentSuggested: true,\n suggestedIntentDescription: result.suggestedIntentDescription,\n message:\n \"No matching opportunities; add an intent with the suggested description to improve discovery.\",\n debugSteps,\n pagination,\n ...(questionPayload.questions !== undefined ? { questions: questionPayload.questions } : {}),\n ...(questionPayload.debug !== undefined ? { discoveryQuestionsDebug: questionPayload.debug } : {}),\n };\n }\n\n let opportunities: Opportunity[] = Array.isArray(result.opportunities)\n ? result.opportunities\n : [];\n let existingOpportunityIds: Set<string> | undefined;\n const rawExistingBetweenActors = Array.isArray(result.existingBetweenActors)\n ? result.existingBetweenActors\n : [];\n // Orchestrator trigger populates this; ambient returns []. Kept as a\n // loosely-typed pass-through because DiscoverResult is consumed by\n // callers (chat tool, tests) that already model the narrower shape.\n const alreadyAcceptedPairs = Array.isArray(\n (result as { dedupAlreadyAccepted?: Array<{ opportunityId: string; counterpartyUserId: string }> })\n .dedupAlreadyAccepted,\n )\n ? (result as { dedupAlreadyAccepted: Array<{ opportunityId: string; counterpartyUserId: string }> })\n .dedupAlreadyAccepted\n : [];\n // Enrich existing-between-actors with names so the tool can say \"You already have a connection with X (pending).\"\n const existingConnections: ExistingConnection[] = await Promise.all(\n rawExistingBetweenActors.map(async (item) => {\n const user = await database.getUser(item.candidateUserId);\n return {\n userId: item.candidateUserId,\n name: user?.name ?? \"Someone\",\n ...(item.existingStatus ? { status: item.existingStatus } : {}),\n ...(item.existingOpportunityId ? { opportunityId: item.existingOpportunityId } : {}),\n };\n }),\n );\n if (existingConnections.length > 0) {\n discoverFromQueryLog.verbose(\"Skipped duplicates; existing connections\", {\n count: existingConnections.length,\n userIds: existingConnections.map((c) => c.userId),\n });\n }\n // Only expose existing connections as cards when status is in EXISTING_CONNECTION_CARD_STATUSES (draft, latent, pending); others are mention-only.\n const existingConnectionsForCards = existingConnections.filter((c) =>\n c.status != null && EXISTING_CONNECTION_CARD_STATUSES.includes(c.status as typeof EXISTING_CONNECTION_CARD_STATUSES[number])\n );\n\n // Fetch full opportunity data for existing connections that should be shown as cards\n // and merge them with the newly created opportunities\n if (existingConnectionsForCards.length > 0) {\n const existingOpps = await Promise.all(\n existingConnectionsForCards\n .filter((c) => c.opportunityId)\n .map((c) => database.getOpportunity(c.opportunityId!))\n );\n const validExistingOpps = existingOpps.filter((o): o is Opportunity => o != null);\n if (validExistingOpps.length > 0) {\n discoverFromQueryLog.verbose(\"Including existing opportunities as cards\", {\n count: validExistingOpps.length,\n ids: validExistingOpps.map((o) => o.id),\n });\n existingOpportunityIds = new Set(validExistingOpps.map((o) => o.id));\n opportunities = [...opportunities, ...validExistingOpps];\n }\n }\n\n // Chat discovery: when we have chatSessionId we just invoked the graph; all result.opportunities\n // were created in this call and belong to this session. Do not filter by status: the enricher\n // may set status to pending/latent when merging with related opportunities, so filtering to\n // \"draft\" would incorrectly drop them.\n if (chatSessionId && (result.opportunities?.length ?? 0) > 0) {\n discoverFromQueryLog.verbose(\"Chat session opportunities from graph\", {\n count: opportunities.length,\n statuses: opportunities.map((o) => o.status),\n });\n }\n debugSteps.push({\n step: \"opportunity_graph\",\n detail: `${opportunities.length} opportunity(ies)${existingConnections.length > 0 ? `, ${existingConnections.length} existing` : \"\"}`,\n });\n\n if (opportunities.length === 0) {\n if (existingConnections.length > 0) {\n return {\n found: true,\n count: 0,\n message:\n \"No new opportunities created; you already have a connection with: \" +\n existingConnections.map((c) => `${c.name}${c.status ? ` (${c.status})` : \"\"}`).join(\", \") +\n \". View on your home page.\",\n existingConnections: existingConnectionsForCards,\n existingConnectionsForMention: existingConnections,\n ...(alreadyAcceptedPairs.length > 0 && { alreadyAcceptedPairs }),\n debugSteps,\n pagination,\n ...(questionPayload.questions !== undefined ? { questions: questionPayload.questions } : {}),\n ...(questionPayload.debug !== undefined ? { discoveryQuestionsDebug: questionPayload.debug } : {}),\n };\n }\n return {\n found: false,\n count: 0,\n message:\n \"No matching opportunities found. Try a different query or create intents to improve matching.\",\n ...(alreadyAcceptedPairs.length > 0 && { alreadyAcceptedPairs }),\n debugSteps,\n pagination,\n ...(questionPayload.questions !== undefined ? { questions: questionPayload.questions } : {}),\n ...(questionPayload.debug !== undefined ? { discoveryQuestionsDebug: questionPayload.debug } : {}),\n };\n }\n\n const enriched = await enrichOpportunities({\n opportunities,\n database,\n userId,\n chatSessionId,\n minimalForChat: input.minimalForChat,\n presenter: input.presenter,\n useHomeCardFormat: input.useHomeCardFormat,\n debugSteps,\n existingOpportunityIds,\n targetUserId,\n });\n\n return {\n found: true,\n count: enriched.length,\n opportunities: enriched,\n ...(existingConnectionsForCards.length > 0 ? { existingConnections: existingConnectionsForCards } : {}),\n ...(existingConnections.length > 0 ? { existingConnectionsForMention: existingConnections } : {}),\n ...(alreadyAcceptedPairs.length > 0 ? { alreadyAcceptedPairs } : {}),\n debugSteps,\n pagination,\n ...(questionPayload.questions !== undefined ? { questions: questionPayload.questions } : {}),\n ...(questionPayload.debug !== undefined ? { discoveryQuestionsDebug: questionPayload.debug } : {}),\n };\n },\n { context: { userId }, logOutput: false },\n ).catch((err) => {\n return {\n found: false,\n count: 0,\n message: \"Failed to find opportunities. Please try again.\",\n };\n });\n}\n\n// ─────────────────────────────────────────────────────────────────────────────\n// DECISION-QUESTION HELPER\n// ─────────────────────────────────────────────────────────────────────────────\n\ntype GraphResultLike = {\n sourceProfile?: SourceProfileData | null;\n discoveryNegotiations?: DiscoveryNegotiation[];\n discoverySummary?: DiscoverySummary | null;\n};\n\ninterface MaybeBuildQuestionsInput {\n trigger: 'ambient' | 'orchestrator' | undefined;\n enableQuestions: boolean;\n chatSummary: ChatSummaryReader | undefined;\n questionGenerator: QuestionGeneratorReader | undefined;\n chatSessionId: string | undefined;\n graphResult: GraphResultLike;\n /** Pre-built per-negotiation digests. Pass [] when summarization is unavailable or disabled. */\n negotiationDigests: DiscoveryNegotiationDigest[];\n query: string;\n /** Optional async enqueue callback for background question generation. */\n questionerEnqueue?: DiscoverInput['questionerEnqueue'];\n /** User ID needed for the enqueue payload. */\n userId?: string;\n /** Focused request scope type for generated discovery questions. */\n scopeType?: ToolScopeType;\n /** Focused request scope id. When `scopeType === 'network'`, persisted as actor networkId. */\n scopeId?: string;\n /** Intent that triggered this discovery run. Stamped as `detection.triggeredBy` on generated questions. */\n triggerIntentId?: string;\n /** The seeker's global user_context paragraph (profile-replacing identity text). */\n userContext?: string;\n}\n\n/**\n * Run the negotiation summarizer over every negotiation in this discovery turn.\n * Each summarization is independent — run them concurrently via Promise.all.\n * When the summarizer is missing (no LLM available) or fails for an individual\n * negotiation, fall back to a deterministic digest so the downstream generator\n * still has structured input.\n */\nasync function summarizeNegotiations(args: {\n negotiations: DiscoveryNegotiation[];\n summarizer: NegotiationSummaryReader | undefined;\n enableQuestions: boolean;\n trigger: 'ambient' | 'orchestrator' | undefined;\n}): Promise<DiscoveryNegotiationDigest[]> {\n // Skip the LLM round-trip entirely when questions won't be built.\n if (!args.enableQuestions || args.trigger !== 'orchestrator') return [];\n if (args.negotiations.length === 0) return [];\n\n const perNegTimeoutMs = parsePositiveIntEnv(\n \"NEGOTIATION_SUMMARY_TIMEOUT_MS\",\n NEGOTIATION_SUMMARY_TIMEOUT_MS_DEFAULT,\n );\n const callerSignal = requestContext.getStore()?.abortSignal;\n\n return traceAgent(\n `Negotiation summary (${args.negotiations.length})`,\n () =>\n Promise.all(\n args.negotiations.map(async (n) => {\n if (!args.summarizer) return buildFallbackDigest(n);\n // Per-negotiation deadline: one slow OpenRouter route used to\n // dominate the post-discovery tail. With a cap, an aborted\n // summarizer falls back to a deterministic digest so the\n // question generator still has structured input.\n const signal = combineWithDeadline(callerSignal, perNegTimeoutMs);\n try {\n const d = await args.summarizer.summarize(n, { signal });\n return d ?? buildFallbackDigest(n);\n } catch (err) {\n // Attribute cause from err.name (AbortError), not from\n // signal.aborted — the latter is read post-catch and can race a\n // deadline-trip-after-unrelated-error, producing a misleading log.\n const aborted = err instanceof Error && err.name === \"AbortError\";\n logger.warn(\"negotiationSummary.summarize threw — using fallback digest\", {\n counterpartyHint: n.counterpartyHint,\n aborted,\n error: err instanceof Error ? err.message : String(err),\n });\n return buildFallbackDigest(n);\n }\n }),\n ),\n (digests) => `${digests.length} digest${digests.length === 1 ? \"\" : \"s\"}`,\n );\n}\n\nasync function maybeBuildQuestions(args: MaybeBuildQuestionsInput): Promise<{\n questions?: Question[];\n debug?: DiscoverResult[\"discoveryQuestionsDebug\"];\n}> {\n if (!args.enableQuestions) return {};\n if (args.trigger !== 'orchestrator') return {};\n\n // Hardcoded — `insights` mode is planned for a later slice. Warn if the env\n // var is set so operators aren't surprised when reporting still says\n // \"transcripts\".\n if (discoveryQuestionsInputMode() === \"insights\") {\n logger.warn(\"QUESTIONER_DISCOVERY_INPUT_MODE=insights is not yet implemented; falling back to transcripts\");\n }\n const inputMode: \"transcripts\" | \"insights\" = \"transcripts\";\n\n let chatContext: ChatContextDigest | undefined;\n if (args.chatSummary && args.chatSessionId) {\n const sessionId = args.chatSessionId;\n const summary = args.chatSummary;\n chatContext = await traceAgent(\n \"Chat summary\",\n async () => {\n try {\n return (await summary.getDigest(sessionId)) ?? undefined;\n } catch (err) {\n logger.warn(\"chatSummary.getDigest threw — proceeding without digest\", {\n sessionId,\n error: err instanceof Error ? err.message : String(err),\n });\n return undefined;\n }\n },\n (digest) => (digest ? \"loaded\" : \"empty\"),\n );\n }\n\n // ── Async enqueue path ──────────────────────────────────────────────────\n // When questionerEnqueue is provided, dispatch question generation\n // asynchronously to the background QuestionerQueue. This replaces the\n // inline generator path. Questions will be persisted to DB by the queue\n // worker and served via GET /api/questions.\n if (args.questionerEnqueue && args.userId) {\n const summary = args.graphResult.discoverySummary ?? {\n totalCandidates: 0,\n opportunitiesFound: 0,\n noOpportunityCount: 0,\n timeoutCount: 0,\n roleDistribution: {},\n };\n\n const enqueueInput = buildDiscoveryQuestionInput({\n query: args.query,\n userContext: args.userContext ?? '',\n negotiationDigests: args.negotiationDigests,\n summary,\n chatContext,\n now: new Date().toISOString(),\n });\n\n try {\n await args.questionerEnqueue({\n mode: 'discovery',\n userId: args.userId,\n sourceType: 'discovery',\n sourceId: args.chatSessionId ?? crypto.randomUUID(),\n context: enqueueInput,\n ...(args.scopeType && args.scopeId ? { scopeType: args.scopeType, scopeId: args.scopeId } : {}),\n ...(args.triggerIntentId ? { triggeredByIntentId: args.triggerIntentId } : {}),\n conversationId: args.chatSessionId,\n });\n logger.info(\"Question generation enqueued to QuestionerQueue\", {\n userId: args.userId,\n trigger: args.trigger,\n });\n } catch (err) {\n logger.warn(\"Failed to enqueue question generation\", {\n error: err instanceof Error ? err.message : String(err),\n });\n }\n return {};\n }\n\n // ── Inline generator path (backward compat) ────────────────────────────\n if (!args.questionGenerator) return {};\n\n const negotiationDigests = args.negotiationDigests;\n const summary = args.graphResult.discoverySummary ?? {\n totalCandidates: 0,\n opportunitiesFound: 0,\n noOpportunityCount: 0,\n timeoutCount: 0,\n roleDistribution: {},\n };\n\n const input = buildDiscoveryQuestionInput({\n query: args.query,\n userContext: args.userContext ?? '',\n negotiationDigests,\n summary,\n chatContext,\n now: new Date().toISOString(),\n });\n\n const questionGenerator = args.questionGenerator;\n const generatorStart = Date.now();\n const questionsTimeoutMs = discoveryQuestionsTimeoutMs();\n const questionsSignal = combineWithDeadline(\n requestContext.getStore()?.abortSignal,\n questionsTimeoutMs,\n );\n const genResult = await traceAgent(\n \"Decision questions\",\n async () => {\n try {\n return await questionGenerator.generate(input, { signal: questionsSignal });\n } catch (err) {\n logger.warn(\"questionGenerator.generate threw — suppressing questions\", {\n error: err instanceof Error ? err.message : String(err),\n });\n return null;\n }\n },\n (r) => {\n const count = r?.questions?.length ?? 0;\n return `${count} question${count === 1 ? \"\" : \"s\"}`;\n },\n );\n const durationMs = Date.now() - generatorStart;\n\n const finalCount = genResult?.questions?.length ?? 0;\n const strategies: QuestionStrategy[] = genResult?.strategies ?? [];\n\n return {\n ...(genResult && genResult.questions.length > 0 ? { questions: genResult.questions } : {}),\n debug: {\n inputMode,\n finalCount,\n strategies,\n durationMs,\n },\n };\n}\n\n/**\n * Continue a paginated discovery by evaluating the next batch of cached candidates.\n * Loads candidates from Redis, invokes the opportunity graph in continue_discovery mode,\n * then enriches and returns the results with updated pagination metadata.\n *\n * @param input - Continuation context (graph, database, cache, discoveryId, etc.).\n * @returns Discovery result with enriched opportunities and pagination state.\n */\nexport async function continueDiscovery(input: {\n opportunityGraph: CompiledOpportunityGraph;\n database: ChatGraphCompositeDatabase;\n cache: Cache;\n userId: string;\n discoveryId: string;\n /** If provided, validates the cached session's indexScope contains this network. */\n expectedIndexId?: string;\n limit?: number;\n chatSessionId?: string;\n minimalForChat?: boolean;\n presenter?: OpportunityPresenter;\n useHomeCardFormat?: boolean;\n}): Promise<DiscoverResult> {\n const {\n opportunityGraph,\n database,\n cache,\n userId,\n discoveryId,\n expectedIndexId,\n limit = 20,\n chatSessionId,\n } = input;\n const cacheKey = `discovery:${userId}:${discoveryId}`;\n\n const cached = await cache.get<CachedDiscoverySession>(cacheKey);\n\n if (!cached) {\n return {\n found: false,\n count: 0,\n message: \"Discovery session expired or not found. Please start a new search.\",\n };\n }\n\n // Validate that the cached session's scope matches the current chat context\n if (expectedIndexId && !cached.indexScope.includes(expectedIndexId)) {\n return {\n found: false,\n count: 0,\n message: \"Discovery session was created in a different context. Please start a new search.\",\n };\n }\n\n const debugSteps: DiscoverDebugStep[] = [];\n\n const result = await invokeWithAbortSignal(opportunityGraph, {\n userId,\n searchQuery: cached.query || undefined,\n candidates: cached.candidates,\n operationMode: 'continue_discovery' as const,\n onBehalfOfUserId: cached.onBehalfOfUserId,\n // Carry the original trigger so page 2+ stays on the same flow as page\n // 1 (orchestrator negotiations with 60s park window + accepted-pair\n // dedup, or ambient with 5-min park window).\n ...(cached.trigger && { trigger: cached.trigger }),\n options: {\n ...cached.options,\n limit,\n ...(chatSessionId ? { conversationId: chatSessionId } : {}),\n },\n });\n\n // Extract trace from graph and append to debugSteps\n const graphTrace = result.trace || [];\n for (const t of graphTrace) {\n debugSteps.push({\n step: t.node,\n detail: t.detail,\n ...(t.data ? { data: t.data } : {}),\n });\n }\n\n // Bail early if the graph returned an error\n if (result.error) {\n logger.warn(\"continueDiscovery graph returned error\", { error: result.error });\n return {\n found: false,\n count: 0,\n message: \"Discovery continuation failed. Please start a new search.\",\n debugSteps,\n };\n }\n\n // Update cache with remaining candidates or delete if exhausted\n const remaining: CandidateMatch[] = result.remainingCandidates || [];\n let pagination: DiscoverResult['pagination'] | undefined;\n try {\n if (remaining.length > 0) {\n await cache.set(cacheKey, {\n ...cached,\n candidates: remaining,\n } satisfies CachedDiscoverySession, { ttl: 1800 });\n pagination = {\n discoveryId,\n evaluated: cached.candidates.length - remaining.length,\n remaining: remaining.length,\n };\n } else {\n await cache.delete(cacheKey);\n }\n } catch (cacheErr) {\n logger.warn(\"Failed to update discovery pagination cache\", {\n userId,\n discoveryId,\n error: cacheErr instanceof Error ? cacheErr.message : String(cacheErr),\n });\n }\n\n // Check for opportunities in result\n const opportunities: Opportunity[] = Array.isArray(result.opportunities) ? result.opportunities : [];\n\n if (opportunities.length === 0) {\n return {\n found: false,\n count: 0,\n message: \"No more matching opportunities found in the remaining candidates.\",\n debugSteps,\n pagination,\n };\n }\n\n const enriched = await enrichOpportunities({\n opportunities,\n database,\n userId,\n chatSessionId,\n minimalForChat: input.minimalForChat,\n presenter: input.presenter,\n useHomeCardFormat: input.useHomeCardFormat,\n debugSteps,\n });\n\n return {\n found: true,\n count: enriched.length,\n opportunities: enriched,\n debugSteps,\n pagination,\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"opportunity.evaluator.d.ts","sourceRoot":"/","sources":["opportunity/opportunity.evaluator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,2BAA2B,CAAC;AAG1D,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OA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AChB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,UAAU,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAChC,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,aAAa,CAAC,EAAE,iBAAiB,CAAC;CACnC;AAMD,oFAAoF;AACpF,MAAM,MAAM,sCAAsC,GAAG;IACnD,iBAAiB,CAAC,EAAE,QAAQ,CAAC;CAC9B,CAAC;AAEF,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,iBAAiB,CAAW;gBAExB,OAAO,CAAC,EAAE,sCAAsC;IAS5D;;;;;;;OAOG;IAEU,MAAM,CACjB,oBAAoB,EAAE,MAAM,EAC5B,UAAU,EAAE,gBAAgB,EAAE,EAC9B,OAAO,EAAE,2BAA2B,GACnC,OAAO,CAAC,WAAW,EAAE,CAAC;IAgCzB;;OAEG;YACW,YAAY;IAgD1B;;OAEG;IAEU,kBAAkB,CAC7B,KAAK,EAAE,cAAc,EACrB,OAAO,GAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,OAAO,CAAA;KAAO,GACvD,OAAO,CAAC,8BAA8B,EAAE,CAAC;IA8I5C;;;;OAIG;WACW,MAAM;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqCrB"}
@@ -16,6 +16,7 @@ import { stripUuids } from "./opportunity.presentation.js";
16
16
  import { createStructuredModel } from "../shared/agent/model.config.js";
17
17
  import { invokeWithAbortSignal } from "../shared/agent/model-signal.js";
18
18
  import { renderOpportunityEvidenceForPrompt } from './opportunity.evidence.js';
19
+ import { hasUnsupportedOpportunityClaim } from './opportunity.claim-safety.js';
19
20
  const logger = protocolLogger("OpportunityEvaluator");
20
21
  const invokeLog = protocolLogger("OpportunityEvaluator:invoke");
21
22
  const invokeEntityBundleLog = protocolLogger("OpportunityEvaluator:invokeEntityBundle");
@@ -71,6 +72,7 @@ const systemPrompt = `
71
72
  5. DEDUPLICATION: Do NOT suggest opportunities that duplicate "Existing Opportunities".
72
73
  6. Do not suggest an opportunity if the source and candidate clearly already know each other (e.g. same company, co-founders, same team).
73
74
  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.
75
+ 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.
74
76
  `;
75
77
  // Entity-bundle system prompt (C2): entities + four match patterns + actors output
76
78
  // NOTE: entityBundleSystemPrompt uses a >= 30 threshold (permissive) while
@@ -151,12 +153,10 @@ Rules:
151
153
  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.
152
154
  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.
153
155
  d. "Remote" or "Global" locations are compatible with any requested location.
154
- 10. EVENT NETWORK AWARENESS: When NETWORK CONTEXTS includes an event-type network (identified by dates, location, schedule, or themes):
155
- a. TEMPORAL RELEVANCE: If the event has start/end dates, factor time into scoring. Intents about meeting at the event, sharing logistics, or collaborating during the event are highly relevant when the event is upcoming or in progress. After the event ends, such intents lose relevance — score lower unless the connection has lasting value beyond the event.
156
- b. THEME ALIGNMENT: Event networks may list themes or tracks. Candidates whose expertise or intents align with event themes should score higher for that network's entities.
157
- c. CO-ATTENDANCE SIGNAL: Two entities found through the same event network share a co-attendance signal they will likely be in the same place at the same time. This is a positive signal for in-person collaboration opportunities.
158
- d. SCHEDULE CONTEXT: If the event network includes upcoming events or sessions, use them as additional matching context. Two people attending the same session or interested in the same topic track are stronger matches.
159
- e. CO-ATTENDANCE ROLE: When two co-attendees express mutual or reciprocal collaboration intent — each seeking to work with the other's type, with no clear one-directional provider/seeker split — assign the "peer" role to both. Symmetric, two-sided collaboration is a peer relationship, not an agent/patient one; default to "peer" rather than "agent" for co-attendance matches.
156
+ 10. EVENT NETWORK CONTEXT: When NETWORK CONTEXTS includes an event-type network (identified by dates, location, schedule, or themes):
157
+ 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.
158
+ 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.
159
+ 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.
160
160
  `;
161
161
  // ──────────────────────────────────────────────────────────────
162
162
  // 2. RESPONSE SCHEMA (Zod)
@@ -381,12 +381,17 @@ ${renderOpportunityEvidenceForPrompt(e.evidence ?? [])}`;
381
381
  op.reasoning = stripUuids(op.reasoning);
382
382
  }
383
383
  parsedTotal = parsed.opportunities.length;
384
+ // Persistence safety is deterministic and precedes every score/returnAll
385
+ // path. Network/context placement is not typed support provenance, so an
386
+ // unsupported affiliation or presence claim rejects the whole result.
387
+ const claimSafe = parsed.opportunities.filter((op) => !hasUnsupportedOpportunityClaim(op.reasoning));
384
388
  const introGuard = input.introductionMode
385
- ? parsed.opportunities.filter((op) => op.actors.length === 2)
386
- : parsed.opportunities;
389
+ ? claimSafe.filter((op) => op.actors.length === 2)
390
+ : claimSafe;
387
391
  const filtered = introGuard.filter((op) => op.score >= minScore);
388
392
  invokeEntityBundleLog.verbose('Done', {
389
393
  total: parsed.opportunities.length,
394
+ afterClaimGuard: claimSafe.length,
390
395
  afterIntroGuard: introGuard.length,
391
396
  accepted: filtered.length,
392
397
  returnAll,