@indexnetwork/protocol 1.26.4 → 1.26.6-rc.231.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.
@@ -1 +1 @@
1
- {"version":3,"file":"opportunity.discover.d.ts","sourceRoot":"/","sources":["opportunity/opportunity.discover.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAe,0BAA0B,EAAE,UAAU,EAAE,MAAM,4CAA4C,CAAC;AACtH,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,yCAAyC,CAAC;AAGrE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,mCAAmC,CAAC;AAC7E,OAAO,EACL,oBAAoB,EAEpB,KAAK,6BAA6B,EAClC,KAAK,0BAA0B,EAGhC,MAAM,4BAA4B,CAAC;AAIpC,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gDAAgD,CAAC;AAExF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sDAAsD,CAAC;AACpG,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,uDAAuD,CAAC;AAGtG,OAAO,KAAK,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;AAqDvF,+EAA+E;AAC/E,MAAM,MAAM,wBAAwB,GAAG,UAAU,CAC/C,OAAO,wBAAwB,EAAE,uBAAuB,CAAC,aAAa,CAAC,CACxE,CAAC;AAEF,MAAM,WAAW,aAAa;IAC5B,gFAAgF;IAChF,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C,mEAAmE;IACnE,QAAQ,EAAE,0BAA0B,CAAC;IACrC,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,EAAE,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,oGAAoG;IACpG,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,4FAA4F;IAC5F,YAAY,CAA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E;IAC/E,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,0FAA0F;IAC1F,UAAU,CAAC,EAAE,iBAAiB,EAAE,CAAC;IACjC,iFAAiF;IACjF,UAAU,CAAC,EAAE;QACX,WAAW,EAAE,MAAM,CAAC;QACpB,SAAS,EAAE,MAAM,CAAC;QAClB,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;IACF,mFAAmF;IACnF,SAAS,CAAC,EAAE,QAAQ,EAAE,CAAC;IACvB,kEAAkE;IAClE,uBAAuB,CAAC,EAAE;QACxB,SAAS,EAAE,aAAa,GAAG,UAAU,CAAC;QACtC,UAAU,EAAE,MAAM,CAAC;QACnB,UAAU,EAAE,gBAAgB,EAAE,CAAC;QAC/B,UAAU,EAAE,MAAM,CAAC;KACpB,CAAC;CACH;AAiXD;;;;GAIG;AACH,wBAAsB,oBAAoB,CACxC,KAAK,EAAE,aAAa,GACnB,OAAO,CAAC,cAAc,CAAC,CA4TzB;AAmOD;;;;;;;GAOG;AACH,wBAAsB,iBAAiB,CAAC,KAAK,EAAE;IAC7C,gBAAgB,EAAE,wBAAwB,CAAC;IAC3C,QAAQ,EAAE,0BAA0B,CAAC;IACrC,KAAK,EAAE,KAAK,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,kFAAkF;IAClF,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,KAAK,CAAC,EAAE,MAAM,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"}
@@ -198,11 +198,15 @@ async function enrichOpportunities(input) {
198
198
  }
199
199
  }
200
200
  const isCounterpartGhost = isGhostByUserId.get(item.candidateUserId) ?? false;
201
+ const personalizedSummary = viewerCentricCardSummary(reasoning, name, MINIMAL_MAIN_TEXT_MAX_CHARS, viewerName, introducerName);
201
202
  return {
202
203
  headline: viewerIsIntroducer && secondPartyName
203
204
  ? `${name} → ${secondPartyName}`
204
205
  : (name ? `Connection with ${name}` : "Suggested connection"),
205
- personalizedSummary: viewerCentricCardSummary(reasoning, name, MINIMAL_MAIN_TEXT_MAX_CHARS, viewerName, introducerName),
206
+ personalizedSummary,
207
+ digestSummary: name
208
+ ? `You might like meeting ${name} based on your current interests.`
209
+ : "This connection may be relevant to your current interests.",
206
210
  suggestedAction: "Start a conversation to connect.",
207
211
  narratorRemark: narratorRemarkFromReasoning(reasoning, name, viewerName),
208
212
  primaryActionLabel: getPrimaryActionLabel(viewerIsIntroducer ? "introducer" : "party"),
@@ -1 +1 @@
1
- {"version":3,"file":"opportunity.discover.js","sourceRoot":"/","sources":["opportunity/opportunity.discover.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAOH,OAAO,EAEL,sBAAsB,GAKvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,2BAA2B,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACrH,OAAO,EAAE,wBAAwB,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AACtG,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAM7F,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAE/E,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAC;AAC5E,OAAO,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAExE,MAAM,MAAM,GAAG,cAAc,CAAC,qBAAqB,CAAC,CAAC;AAErD;;;;;;;GAOG;AACH,MAAM,sCAAsC,GAAG,IAAK,C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AK,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 {\n OpportunityPresenter,\n gatherPresenterContext,\n type OpportunityPresentationResult,\n type HomeCardPresentationResult,\n type HomeCardLLMResult,\n type HomeCardPresenterInput,\n} from \"./opportunity.presenter.js\";\nimport { MINIMAL_MAIN_TEXT_MAX_CHARS, getPrimaryActionLabel, SECONDARY_ACTION_LABEL } from \"./opportunity.labels.js\";\nimport { viewerCentricCardSummary, narratorRemarkFromReasoning } from \"./opportunity.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\");\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 * Question-generator budget. Sized against Railway's ~60 s edge timeout:\n * the discovery + evaluation + negotiate phases consume ~50 s on the slow\n * path, leaving ~10 s of headroom for the tail. 12 s is the larger end of\n * \"fits\"; the question step usually completes in 4-8 s, so most legitimate\n * calls finish well inside. Aborted calls return `null` (no questions);\n * the rest of the discovery payload still ships.\n *\n * Documented at opportunity.tools.ts:912-921 as historically uncapped —\n * this is the cap.\n */\nconst DISCOVERY_QUESTIONS_TIMEOUT_MS_DEFAULT = 12_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 * `process.env.ENABLE_DISCOVERY_QUESTIONS === \"true\"`.\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}\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 /** 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 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 logger.verbose(\"[enrichOpportunities] 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 return {\n headline: viewerIsIntroducer && secondPartyName\n ? `${name} → ${secondPartyName}`\n : (name ? `Connection with ${name}` : \"Suggested connection\"),\n personalizedSummary:\n viewerCentricCardSummary(\n reasoning,\n name,\n MINIMAL_MAIN_TEXT_MAX_CHARS,\n viewerName,\n introducerName,\n ),\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 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 index) 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 });\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 logger.verbose(\"[runDiscoverFromQuery] 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 logger.verbose(\"[runDiscoverFromQuery] 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 logger.verbose(\"[runDiscoverFromQuery] 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}\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 (process.env.DISCOVERY_QUESTIONS_INPUT_MODE === \"insights\") {\n logger.warn(\"DISCOVERY_QUESTIONS_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 sourceProfile: args.graphResult.sourceProfile ?? null,\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 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 sourceProfile: args.graphResult.sourceProfile ?? null,\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 = parsePositiveIntEnv(\n \"DISCOVERY_QUESTIONS_TIMEOUT_MS\",\n DISCOVERY_QUESTIONS_TIMEOUT_MS_DEFAULT,\n );\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 index. */\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,EAEL,sBAAsB,GAKvB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,2BAA2B,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACrH,OAAO,EAAE,wBAAwB,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAC;AACtG,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AAM7F,OAAO,EAAE,mBAAmB,EAAE,MAAM,0CAA0C,CAAC;AAE/E,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAC;AAC5E,OAAO,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAC7E,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AAExE,MAAM,MAAM,GAAG,cAAc,CAAC,qBAAqB,CAAC,CAAC;AAErD;;;;;;;GAOG;AACH,MAAM,sCAAsC,GAAG,IAAK,CAAC;AACrD;;;;;;;;;;GAUG;AACH,MAAM,sCAAsC,GAAG,KAAM,CAAC;AAEtD;;;;;GAKG;AACH,SAAS,mBAAmB,CAAC,IAAY,EAAE,QAAgB;IACzD,MAAM,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,CAAC,GAAG;QAAE,OAAO,QAAQ,CAAC;IAC1B,MAAM,CAAC,GAAG,MAAM,CAAC,QAAQ,CAAC,GAAG,EAAE,EAAE,CAAC,CAA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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 {\n OpportunityPresenter,\n gatherPresenterContext,\n type OpportunityPresentationResult,\n type HomeCardPresentationResult,\n type HomeCardLLMResult,\n type HomeCardPresenterInput,\n} from \"./opportunity.presenter.js\";\nimport { MINIMAL_MAIN_TEXT_MAX_CHARS, getPrimaryActionLabel, SECONDARY_ACTION_LABEL } from \"./opportunity.labels.js\";\nimport { viewerCentricCardSummary, narratorRemarkFromReasoning } from \"./opportunity.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\");\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 * Question-generator budget. Sized against Railway's ~60 s edge timeout:\n * the discovery + evaluation + negotiate phases consume ~50 s on the slow\n * path, leaving ~10 s of headroom for the tail. 12 s is the larger end of\n * \"fits\"; the question step usually completes in 4-8 s, so most legitimate\n * calls finish well inside. Aborted calls return `null` (no questions);\n * the rest of the discovery payload still ships.\n *\n * Documented at opportunity.tools.ts:912-921 as historically uncapped —\n * this is the cap.\n */\nconst DISCOVERY_QUESTIONS_TIMEOUT_MS_DEFAULT = 12_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 * `process.env.ENABLE_DISCOVERY_QUESTIONS === \"true\"`.\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}\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 /** 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 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 logger.verbose(\"[enrichOpportunities] 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 const personalizedSummary = viewerCentricCardSummary(\n reasoning,\n name,\n MINIMAL_MAIN_TEXT_MAX_CHARS,\n viewerName,\n introducerName,\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 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 index) 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 });\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 logger.verbose(\"[runDiscoverFromQuery] 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 logger.verbose(\"[runDiscoverFromQuery] 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 logger.verbose(\"[runDiscoverFromQuery] 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}\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 (process.env.DISCOVERY_QUESTIONS_INPUT_MODE === \"insights\") {\n logger.warn(\"DISCOVERY_QUESTIONS_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 sourceProfile: args.graphResult.sourceProfile ?? null,\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 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 sourceProfile: args.graphResult.sourceProfile ?? null,\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 = parsePositiveIntEnv(\n \"DISCOVERY_QUESTIONS_TIMEOUT_MS\",\n DISCOVERY_QUESTIONS_TIMEOUT_MS_DEFAULT,\n );\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 index. */\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"]}
@@ -48,6 +48,7 @@ export interface HomeCardPresenterInput extends PresenterInput {
48
48
  export declare const HomeCardLLMSchema: z.ZodObject<{
49
49
  headline: z.ZodString;
50
50
  personalizedSummary: z.ZodString;
51
+ digestSummary: z.ZodString;
51
52
  suggestedAction: z.ZodString;
52
53
  narratorRemark: z.ZodString;
53
54
  mutualIntentsLabel: z.ZodString;
@@ -57,6 +58,7 @@ export declare const HomeCardLLMSchema: z.ZodObject<{
57
58
  personalizedSummary: string;
58
59
  suggestedAction: string;
59
60
  greeting: string;
61
+ digestSummary: string;
60
62
  narratorRemark: string;
61
63
  mutualIntentsLabel: string;
62
64
  }, {
@@ -64,6 +66,7 @@ export declare const HomeCardLLMSchema: z.ZodObject<{
64
66
  personalizedSummary: string;
65
67
  suggestedAction: string;
66
68
  greeting: string;
69
+ digestSummary: string;
67
70
  narratorRemark: string;
68
71
  mutualIntentsLabel: string;
69
72
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"opportunity.presenter.d.ts","sourceRoot":"/","sources":["opportunity/opportunity.presenter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAOxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,4CAA4C,CAAC;AAC9E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,4CAA4C,CAAC;AAC7F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,iCAAiC,CAAC;AAG1E;;;GAGG;AACH,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAClC,0BAA0B,EAC1B,YAAY,GAAG,kBAAkB,GAAG,YAAY,GAAG,oBAAoB,CACxE,CAAC;AAcF,QAAA,MAAM,kBAAkB;;;;;;;;;;;;;;;EAatB,CAAC;AAMH,MAAM,MAAM,6BAA6B,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,kBAAkB,CAAC,CAAC;AAE/E,oGAAoG;AAC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;;;OAGG;IAEU,oBAAoB,CAC/B,MAAM,EAAE,sBAAsB,EAAE,EAChC,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GACjC,OAAO,CAAC,iBAAiB,EAAE,CAAC;CAYhC;AA0ED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,iBAAiB,EAC3B,WAAW,EAAE,WAAW,EACxB,QAAQ,EAAE,MAAM,EAChB,wBAAwB,CAAC,EAAE,MAAM,GAChC,OAAO,CAAC,cAAc,CAAC,CA0OzB"}
@@ -50,6 +50,10 @@ export const HomeCardLLMSchema = z.object({
50
50
  personalizedSummary: z
51
51
  .string()
52
52
  .describe("2-3 sentence explanation in 'you' language for the main card body"),
53
+ digestSummary: z
54
+ .string()
55
+ .max(220)
56
+ .describe("One concise digest-ready sentence for a morning brief. It must be addressed to the viewer and mention the counterpart by name, e.g. 'You might like meeting Paul because ...'. No markdown."),
53
57
  suggestedAction: z
54
58
  .string()
55
59
  .describe("Brief suggested next step (e.g. CTA line)"),
@@ -125,10 +129,11 @@ You are an expert at presenting connection opportunities for a home feed card.
125
129
  Given context about the viewer, the other person, and why they were matched, produce:
126
130
  1. headline: one short hook line.
127
131
  2. personalizedSummary: 2-3 sentences in "you" language (main body text).
128
- 3. suggestedAction: one brief suggested next step.
129
- 4. narratorRemark: one short sentence for the narrator chip (who is suggesting and why; max ~80 chars).
130
- 5. greeting: a 2-4 sentence first-person message the viewer could send to the counterpart. Plain prose, no greeting prefix, no markdown.
131
- 6. mutualIntentsLabel: short subtitle under the other party's name. Examples: "3 mutual intents", "Shared interests", "Aligned goals" — keep it brief. NEVER output "0 mutual intents" or any zero-count label; use a qualitative phrase instead.
132
+ 3. digestSummary: one polished morning-brief sentence that can be printed directly after the person's linked name. No markdown, no field labels.
133
+ 4. suggestedAction: one brief suggested next step.
134
+ 5. narratorRemark: one short sentence for the narrator chip (who is suggesting and why; max ~80 chars).
135
+ 6. greeting: a 2-4 sentence first-person message the viewer could send to the counterpart. Plain prose, no greeting prefix, no markdown.
136
+ 7. mutualIntentsLabel: short subtitle under the other party's name. Examples: "3 mutual intents", "Shared interests", "Aligned goals" — keep it brief. NEVER output "0 mutual intents" or any zero-count label; use a qualitative phrase instead.
132
137
 
133
138
  Rules:
134
139
  - Address the viewer with "you"/"your". Be concise and compelling.
@@ -136,6 +141,10 @@ Rules:
136
141
  - narratorRemark is displayed with the narrator name prepended (e.g. "Index: …" or "Alice: …"). Do NOT start narratorRemark with the narrator's name or repeat it; write only the remark (e.g. "Based on your overlapping intents" or "introduced you two, sensing a valuable connection").
137
142
  - Vary wording for the match itself. Do not repeat "opportunity" across headline, summary, and narratorRemark when alternatives fit.
138
143
  - Prefer first names in user-facing copy. Avoid repeated full names unless disambiguation is necessary.
144
+ - digestSummary must be grammatically complete as a standalone sentence. It should usually start with "You might like meeting {Name} because ..." for direct connections, or "You may be able to help {Name} because ..." for connector/introducer cards.
145
+ - digestSummary must NOT use awkward third-person fragments like "Name is...", "they're ..., and is...", "you is...", or "the discoverer's query".
146
+ - digestSummary must be one sentence, MUST fit within 180 characters when possible, and MUST contain no markdown links; the caller will attach links.
147
+ - If you cannot fit every detail, choose one clear reason and stop. Do not rely on downstream truncation.
139
148
 
140
149
  **Introduction-originated opportunities (ONLY when INTRODUCTION CONTEXT is provided):**
141
150
  When INTRODUCTION CONTEXT is provided, this opportunity was explicitly created by an introducer. It was NOT automatically discovered.
@@ -311,7 +320,7 @@ COMMUNITY: ${input.indexName}
311
320
  Viewer's role in this opportunity: ${input.viewerRole}
312
321
  Opportunity status: ${input.opportunityStatus ?? "pending"}
313
322
 
314
- Produce headline, personalizedSummary, suggestedAction, narratorRemark, greeting, and mutualIntentsLabel.
323
+ Produce headline, personalizedSummary, digestSummary, suggestedAction, narratorRemark, greeting, and mutualIntentsLabel.
315
324
  `;
316
325
  const isIntroducer = input.viewerRole === "introducer";
317
326
  try {
@@ -322,12 +331,14 @@ Produce headline, personalizedSummary, suggestedAction, narratorRemark, greeting
322
331
  const result = await this.invokeWithTimeout(this.homeCardModel, messages);
323
332
  const parsed = homeCardResponseFormat.parse(result);
324
333
  parsed.presentation.personalizedSummary = stripUuids(parsed.presentation.personalizedSummary);
334
+ parsed.presentation.digestSummary = stripUuids(parsed.presentation.digestSummary);
325
335
  parsed.presentation.narratorRemark = stripUuids(parsed.presentation.narratorRemark);
326
336
  if (/^0\s+(mutual|overlapping)\s+intent/i.test(parsed.presentation.mutualIntentsLabel)) {
327
337
  parsed.presentation.mutualIntentsLabel = "Shared interests";
328
338
  }
329
339
  if (input.isIntroduction && input.introducerName) {
330
340
  parsed.presentation.personalizedSummary = stripIntroducerMentions(parsed.presentation.personalizedSummary, input.introducerName);
341
+ parsed.presentation.digestSummary = stripIntroducerMentions(parsed.presentation.digestSummary, input.introducerName);
331
342
  }
332
343
  return parsed.presentation;
333
344
  }
@@ -345,6 +356,9 @@ Produce headline, personalizedSummary, suggestedAction, narratorRemark, greeting
345
356
  return {
346
357
  headline: "A promising connection",
347
358
  personalizedSummary: fallbackSummary,
359
+ digestSummary: isIntroducer
360
+ ? "You may be able to help make a useful introduction here."
361
+ : "You might like meeting them based on your current interests.",
348
362
  suggestedAction: isIntroducer
349
363
  ? "Share this introduction to get things started."
350
364
  : "Take a look and decide whether to reach out.",
@@ -462,6 +476,7 @@ function buildNegotiatingChip(input) {
462
476
  return {
463
477
  headline: "Negotiation in progress",
464
478
  personalizedSummary: "Your agent is still talking with theirs to see if this connection makes sense. We'll surface the full match as soon as they converge.",
479
+ digestSummary: "Your agent is still checking whether this connection makes sense.",
465
480
  suggestedAction: "Check back shortly — no action needed yet.",
466
481
  narratorRemark,
467
482
  mutualIntentsLabel: input.mutualIntentCount && input.mutualIntentCount > 0