@indexnetwork/protocol 3.7.0-rc.277.1 → 3.7.1-rc.279.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (96) hide show
  1. package/dist/agent/agent.tools.js +1 -1
  2. package/dist/agent/agent.tools.js.map +1 -1
  3. package/dist/chat/chat.agent.d.ts +6 -6
  4. package/dist/chat/chat.agent.d.ts.map +1 -1
  5. package/dist/chat/chat.agent.js +10 -9
  6. package/dist/chat/chat.agent.js.map +1 -1
  7. package/dist/chat/chat.graph.d.ts.map +1 -1
  8. package/dist/chat/chat.graph.js +3 -12
  9. package/dist/chat/chat.graph.js.map +1 -1
  10. package/dist/chat/chat.interrupt.classifier.d.ts.map +1 -1
  11. package/dist/chat/chat.interrupt.classifier.js +1 -3
  12. package/dist/chat/chat.interrupt.classifier.js.map +1 -1
  13. package/dist/chat/chat.prompt.d.ts.map +1 -1
  14. package/dist/chat/chat.prompt.js +8 -7
  15. package/dist/chat/chat.prompt.js.map +1 -1
  16. package/dist/chat/chat.prompt.modules.d.ts.map +1 -1
  17. package/dist/chat/chat.prompt.modules.js +5 -0
  18. package/dist/chat/chat.prompt.modules.js.map +1 -1
  19. package/dist/chat/chat.suggester.js.map +1 -1
  20. package/dist/context/context.generator.d.ts +2 -0
  21. package/dist/context/context.generator.d.ts.map +1 -1
  22. package/dist/context/context.generator.js +8 -6
  23. package/dist/context/context.generator.js.map +1 -1
  24. package/dist/intent/intent.clarifier.d.ts +2 -0
  25. package/dist/intent/intent.clarifier.d.ts.map +1 -1
  26. package/dist/intent/intent.clarifier.js +9 -23
  27. package/dist/intent/intent.clarifier.js.map +1 -1
  28. package/dist/intent/intent.graph.d.ts.map +1 -1
  29. package/dist/intent/intent.graph.js +29 -26
  30. package/dist/intent/intent.graph.js.map +1 -1
  31. package/dist/intent/intent.tools.d.ts.map +1 -1
  32. package/dist/intent/intent.tools.js +18 -48
  33. package/dist/intent/intent.tools.js.map +1 -1
  34. package/dist/maintenance/maintenance.graph.d.ts.map +1 -1
  35. package/dist/maintenance/maintenance.graph.js +1 -2
  36. package/dist/maintenance/maintenance.graph.js.map +1 -1
  37. package/dist/mcp/mcp.server.d.ts.map +1 -1
  38. package/dist/mcp/mcp.server.js +3 -5
  39. package/dist/mcp/mcp.server.js.map +1 -1
  40. package/dist/negotiation/negotiation.graph.d.ts.map +1 -1
  41. package/dist/negotiation/negotiation.graph.js +13 -20
  42. package/dist/negotiation/negotiation.graph.js.map +1 -1
  43. package/dist/negotiation/negotiation.tools.d.ts.map +1 -1
  44. package/dist/negotiation/negotiation.tools.js +12 -12
  45. package/dist/negotiation/negotiation.tools.js.map +1 -1
  46. package/dist/network/indexer/indexer.graph.d.ts +9 -9
  47. package/dist/network/indexer/indexer.graph.d.ts.map +1 -1
  48. package/dist/network/indexer/indexer.graph.js.map +1 -1
  49. package/dist/network/network.graph.d.ts.map +1 -1
  50. package/dist/network/network.graph.js +19 -25
  51. package/dist/network/network.graph.js.map +1 -1
  52. package/dist/opportunity/feed/feed.categorizer.d.ts.map +1 -1
  53. package/dist/opportunity/feed/feed.categorizer.js +15 -20
  54. package/dist/opportunity/feed/feed.categorizer.js.map +1 -1
  55. package/dist/opportunity/feed/feed.graph.d.ts.map +1 -1
  56. package/dist/opportunity/feed/feed.graph.js +8 -10
  57. package/dist/opportunity/feed/feed.graph.js.map +1 -1
  58. package/dist/opportunity/opportunity.introducer.d.ts.map +1 -1
  59. package/dist/opportunity/opportunity.introducer.js +1 -2
  60. package/dist/opportunity/opportunity.introducer.js.map +1 -1
  61. package/dist/opportunity/opportunity.tools.d.ts.map +1 -1
  62. package/dist/opportunity/opportunity.tools.js +3 -2
  63. package/dist/opportunity/opportunity.tools.js.map +1 -1
  64. package/dist/profile/profile.enricher.d.ts +5 -7
  65. package/dist/profile/profile.enricher.d.ts.map +1 -1
  66. package/dist/profile/profile.enricher.js +8 -10
  67. package/dist/profile/profile.enricher.js.map +1 -1
  68. package/dist/profile/profile.generator.d.ts.map +1 -1
  69. package/dist/profile/profile.generator.js +1 -2
  70. package/dist/profile/profile.generator.js.map +1 -1
  71. package/dist/profile/profile.tools.js +1 -1
  72. package/dist/profile/profile.tools.js.map +1 -1
  73. package/dist/questioner/questioner.presets.d.ts.map +1 -1
  74. package/dist/questioner/questioner.presets.js +24 -38
  75. package/dist/questioner/questioner.presets.js.map +1 -1
  76. package/dist/shared/agent/tool.factory.d.ts.map +1 -1
  77. package/dist/shared/agent/tool.factory.js +2 -2
  78. package/dist/shared/agent/tool.factory.js.map +1 -1
  79. package/dist/shared/agent/tool.helpers.d.ts +10 -0
  80. package/dist/shared/agent/tool.helpers.d.ts.map +1 -1
  81. package/dist/shared/agent/tool.helpers.js +2 -1
  82. package/dist/shared/agent/tool.helpers.js.map +1 -1
  83. package/dist/shared/agent/tool.runtime.d.ts.map +1 -1
  84. package/dist/shared/agent/tool.runtime.js +20 -13
  85. package/dist/shared/agent/tool.runtime.js.map +1 -1
  86. package/dist/shared/hyde/hyde.graph.d.ts.map +1 -1
  87. package/dist/shared/hyde/hyde.graph.js +3 -2
  88. package/dist/shared/hyde/hyde.graph.js.map +1 -1
  89. package/dist/shared/hyde/hyde.strategies.d.ts +2 -1
  90. package/dist/shared/hyde/hyde.strategies.d.ts.map +1 -1
  91. package/dist/shared/hyde/hyde.strategies.js.map +1 -1
  92. package/dist/shared/observability/trace.d.ts +3 -3
  93. package/dist/shared/observability/trace.d.ts.map +1 -1
  94. package/dist/shared/observability/trace.js +19 -33
  95. package/dist/shared/observability/trace.js.map +1 -1
  96. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"feed.graph.js","sourceRoot":"/","sources":["opportunity/feed/feed.graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAI9D,OAAO,EA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D,OAAO,CAAC,kBAAkB,EAAE,uBAAuB,CAAC;aACpD,OAAO,CAAC,uBAAuB,EAAE,uBAAuB,CAAC;aACzD,mBAAmB,CAAC,uBAAuB,EAAE,gBAAgB,EAAE;YAC9D,UAAU,EAAE,uBAAuB;YACnC,IAAI,EAAE,kBAAkB;SACzB,CAAC;aACD,OAAO,CAAC,uBAAuB,EAAE,yBAAyB,CAAC;aAC3D,OAAO,CAAC,yBAAyB,EAAE,kBAAkB,CAAC;aACtD,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC;QAEpC,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;CACF","sourcesContent":["/**\n * Home Graph: Build the opportunity home view with dynamic sections.\n *\n * Independent of ChatGraph. Flow:\n * loadOpportunities → checkPresenterCache → [generateCardText if misses] → cachePresenterResults\n * → checkCategorizerCache → [categorizeDynamically if miss] → cacheCategorizerResults → normalizeAndSort\n *\n * Uses OpportunityPresenter for card text and an LLM to categorize cards into dynamic sections\n * with titles and Lucide icon names. Caches presenter and categorizer results via OpportunityCache.\n */\n\nimport { createHash } from 'crypto';\n\nimport { StateGraph, START, END } from '@langchain/langgraph';\n\nimport type { HomeGraphDatabase, OpportunityStatus } from '../../shared/interfaces/database.interface.js';\nimport type { OpportunityCache } from '../../shared/interfaces/cache.interface.js';\nimport { HomeGraphState, type HomeCardItem, type HomeSection, type HomeSectionProposal, type HomeSectionItem } from './feed.state.js';\nimport { OpportunityPresenter, gatherPresenterContext, type PresenterDatabase } from '../opportunity.presenter.js';\nimport { loadNegotiationContext } from '../negotiation-context.loader.js';\nimport { HomeCategorizerAgent } from './feed.categorizer.js';\nimport { canUserSeeOpportunity, isActionableForViewer, selectByComposition } from '../opportunity.utils.js';\nimport { resolveHomeSectionIcon, DEFAULT_HOME_SECTION_ICON } from '../../shared/ui/lucide.icon-catalog.js';\nimport { getPrimaryActionLabel, SECONDARY_ACTION_LABEL } from '../opportunity.labels.js';\nimport type { DebugMetaAgent } from '../../chat/chat-streaming.types.js';\nimport { protocolLogger } from '../../shared/observability/protocol.logger.js';\nimport { timed } from '../../shared/observability/performance.js';\nimport { requestContext } from \"../../shared/observability/request-context.js\";\n\nconst logger = protocolLogger('HomeGraph');\n\n/** Database must satisfy both HomeGraphDatabase and presenter context (getProfile, getActiveIntents, getNetwork, getUser). */\ntype HomeGraphDb = HomeGraphDatabase;\n\nexport type HomeGraphInvokeInput = {\n userId: string;\n networkId?: string;\n limit?: number;\n noCache?: boolean;\n /** When set, filter loaded opportunities to these lifecycle statuses. Defaults to `DEFAULT_HOME_STATUSES`. */\n statuses?: OpportunityStatus[];\n};\n\nexport type HomeGraphInvokeResult = {\n sections: HomeSection[];\n meta: { totalOpportunities: number; totalSections: number };\n error?: string;\n};\n\n/** Default home-feed statuses: the lifecycle stages a viewer can act on today. */\nexport const DEFAULT_HOME_STATUSES: OpportunityStatus[] = ['latent', 'pending'];\n\n// Exhaustive registry — keys must cover every OpportunityStatus union member.\n// Adding a new status to OpportunityStatus without adding a key here is a TS error,\n// which is the whole point: prevents ALL_OPPORTUNITY_STATUSES from silently drifting.\nconst OPPORTUNITY_STATUS_REGISTRY: Record<OpportunityStatus, true> = {\n latent: true,\n draft: true,\n negotiating: true,\n pending: true,\n stalled: true,\n accepted: true,\n rejected: true,\n expired: true,\n};\n\n/** Full status enumeration. Pass this to `HomeGraphInvokeInput.statuses` to restore pre-Issue-3 (unfiltered) behavior. */\nexport const ALL_OPPORTUNITY_STATUSES: OpportunityStatus[] = Object.keys(\n OPPORTUNITY_STATUS_REGISTRY,\n) as OpportunityStatus[];\n\nconst MAX_ITEMS_PER_SECTION = 20;\nconst PRESENTATION_CONCURRENCY = 50;\nconst MAX_REASONING_SNIPPET_LENGTH = 240;\nconst HOME_CACHE_TTL = 24 * 60 * 60; // 24 hours in seconds\n\n/**\n * Strip leading narrator name from remark when the UI already prepends \"Name: \" to the chip.\n * Avoids duplication like \"Yankı Ekin Yüksel: Yankı Ekin Yüksel introduced you two...\"\n * Repeats until no leading name (handles \"Name: Name rest\").\n */\nexport function stripLeadingNarratorName(remark: string, narratorName: string): string {\n let t = remark.trim();\n if (!t || !narratorName.trim()) return remark;\n const name = narratorName.trim();\n const nameLower = name.toLowerCase();\n for (;;) {\n const lower = t.toLowerCase();\n if (!lower.startsWith(nameLower)) break;\n const rest = t.slice(name.length).replace(/^\\s*[:,\\-–—]\\s*/i, '').trim();\n if (rest.length === 0 || rest === t) break;\n t = rest;\n }\n return t;\n}\n\n/** Normalize timestamp for sorting; returns numeric ms or 0 for invalid/missing. */\nconst safeParseDate = (value: unknown): number => {\n if (value == null) return 0;\n if (value instanceof Date) {\n const t = value.getTime();\n return Number.isFinite(t) ? t : 0;\n }\n if (typeof value === 'number' && Number.isFinite(value)) return value;\n if (typeof value === 'string') {\n const t = new Date(value).getTime();\n return Number.isFinite(t) ? t : 0;\n }\n return 0;\n};\n\n/** Confidence score for sorting (interpretation.confidence or opportunity.confidence). */\nconst getConfidence = (opp: typeof HomeGraphState.State['opportunities'][number]): number => {\n const fromInterp = opp.interpretation?.confidence;\n if (typeof fromInterp === 'number' && !Number.isNaN(fromInterp)) return fromInterp;\n if (typeof fromInterp === 'string') {\n const n = parseFloat(fromInterp);\n if (!Number.isNaN(n)) return n;\n }\n const fromRow = opp.confidence;\n if (typeof fromRow === 'number' && !Number.isNaN(fromRow)) return fromRow;\n if (typeof fromRow === 'string') {\n const n = parseFloat(fromRow);\n if (!Number.isNaN(n)) return n;\n }\n return 0;\n};\n\n/** Unique non-introducer, non-viewer userIds for an opportunity (actors can repeat). */\nconst getUniqueCounterpartUserIds = (\n opp: typeof HomeGraphState.State['opportunities'][number],\n viewerId: string\n): Set<string> => {\n const ids = new Set<string>();\n for (const a of opp.actors) {\n if (a.role !== 'introducer' && a.userId !== viewerId && a.userId) {\n ids.add(a.userId);\n }\n }\n return ids;\n};\n\nconst pickDisplayCounterpartActor = (\n opportunity: typeof HomeGraphState.State['opportunities'][number],\n viewerId: string\n): { userId: string; role: string } | null => {\n const candidates = opportunity.actors.filter(\n (actor) => actor.userId !== viewerId && actor.role !== 'introducer'\n );\n if (candidates.length === 0) {\n return null;\n }\n\n // Prefer direct counterpart roles when available, then stable sort by user id.\n const rolePriority = new Map<string, number>([\n ['patient', 0],\n ['party', 1],\n ['agent', 2],\n ['peer', 3],\n ]);\n\n const sorted = [...candidates].sort((a, b) => {\n const aPriority = rolePriority.get(a.role) ?? 99;\n const bPriority = rolePriority.get(b.role) ?? 99;\n if (aPriority !== bPriority) return aPriority - bPriority;\n return a.userId.localeCompare(b.userId);\n });\n return sorted[0] ?? null;\n};\n\nexport class HomeGraphFactory {\n constructor(private database: HomeGraphDb, private cache: OpportunityCache) {}\n\n createGraph() {\n const presenter = new OpportunityPresenter();\n const categorizer = new HomeCategorizerAgent();\n\n const loadOpportunitiesNode = async (state: typeof HomeGraphState.State) => {\n return timed(\"HomeGraph.loadOpportunities\", async () => {\n if (!state.userId) {\n return { error: 'userId is required' };\n }\n try {\n // Minimum of 50 ensures enough candidates across all feed categories\n // (connection, connector-flow, expired) for selectByComposition to fill\n // its soft targets, even after visibility filtering and dedup.\n const fetchLimit = Math.min(150, Math.max(50, state.limit * 3));\n const statuses = state.statuses ?? DEFAULT_HOME_STATUSES;\n const options: { limit?: number; networkId?: string; statuses?: OpportunityStatus[] } = {\n limit: fetchLimit,\n statuses,\n };\n if (state.networkId) options.networkId = state.networkId;\n // Do not pass conversationId: home view excludes draft opportunities (chat-only drafts).\n const raw = await this.database.getOpportunitiesForUser(state.userId, options);\n const visible = raw.filter((opp) =>\n canUserSeeOpportunity(opp.actors, opp.status, state.userId)\n );\n const visibleForFeed = visible.filter((opp) =>\n isActionableForViewer(opp.actors, opp.status, state.userId)\n );\n const sorted = [...visibleForFeed].sort((a, b) => {\n // Connections before connector-flow so dedup claims counterpart IDs\n // for direct connections first — prevents introducer cards from\n // shadowing a user's own connection opportunities.\n const aIsIntroducer = a.actors.some((ac) => ac.userId === state.userId && ac.role === 'introducer');\n const bIsIntroducer = b.actors.some((ac) => ac.userId === state.userId && ac.role === 'introducer');\n if (aIsIntroducer !== bIsIntroducer) return aIsIntroducer ? 1 : -1;\n const confA = getConfidence(a);\n const confB = getConfidence(b);\n if (confB !== confA) return confB - confA;\n const aTime = safeParseDate(a.updatedAt);\n const bTime = safeParseDate(b.updatedAt);\n return bTime - aTime;\n });\n const seenUserIds = new Set<string>();\n const deduped = sorted.filter((opp) => {\n const counterpartIds = getUniqueCounterpartUserIds(opp, state.userId);\n const hasOverlap = [...counterpartIds].some((id) => seenUserIds.has(id));\n if (hasOverlap) return false;\n for (const id of counterpartIds) seenUserIds.add(id);\n return true;\n });\n const opportunities = selectByComposition(deduped, state.userId);\n return { opportunities };\n } catch (e) {\n logger.error('HomeGraph loadOpportunities failed', { error: e });\n return { error: 'Failed to load opportunities', opportunities: [] };\n }\n });\n };\n\n const checkPresenterCacheNode = async (state: typeof HomeGraphState.State) => {\n return timed(\"HomeGraph.checkPresenterCache\", async () => {\n const { opportunities, userId } = state;\n if (opportunities.length === 0) {\n return { cachedCards: new Map(), uncachedOpportunities: [] };\n }\n\n if (state.noCache) {\n logger.verbose('[HomeGraph:checkPresenterCache] noCache=true, skipping cache');\n return { cachedCards: new Map(), uncachedOpportunities: opportunities };\n }\n\n try {\n // Negotiating cards are templated (no LLM call) and their text\n // depends on the live turn count, which changes between requests\n // without changing the opportunity status. Skip cache entirely\n // for them so each render reflects the current turn.\n //\n // For all other statuses, include status in the key so status\n // transitions (e.g. negotiating → pending) don't serve stale cards.\n const cacheable = opportunities.filter((opp) => opp.status !== 'negotiating');\n const liveNegotiating = opportunities.filter((opp) => opp.status === 'negotiating');\n\n const keys = cacheable.map(\n (opp) => `home:card:${opp.id}:${opp.status}:${userId}`\n );\n const results = keys.length > 0 ? await this.cache.mget<HomeCardItem>(keys) : [];\n\n const cachedCards = new Map<string, HomeCardItem>();\n const uncachedOpportunities: typeof opportunities = [...liveNegotiating];\n\n for (let i = 0; i < cacheable.length; i++) {\n const cached = results[i];\n if (cached) {\n const originalIndex = opportunities.indexOf(cacheable[i]);\n cachedCards.set(cacheable[i].id, { ...cached, _cardIndex: originalIndex });\n } else {\n uncachedOpportunities.push(cacheable[i]);\n }\n }\n\n logger.verbose('[HomeGraph:checkPresenterCache]', {\n total: opportunities.length,\n cacheHits: cachedCards.size,\n cacheMisses: uncachedOpportunities.length,\n });\n\n return { cachedCards, uncachedOpportunities };\n } catch (e) {\n logger.warn('[HomeGraph:checkPresenterCache] cache unavailable, skipping', { error: e });\n return { cachedCards: new Map(), uncachedOpportunities: opportunities };\n }\n });\n };\n\n const shouldGenerateCards = (state: typeof HomeGraphState.State): string => {\n if (state.uncachedOpportunities.length > 0) {\n return 'generate';\n }\n logger.verbose('[HomeGraph] All presenter results cached, skipping generation');\n return 'skip';\n };\n\n const generateCardTextNode = async (state: typeof HomeGraphState.State) => {\n return timed(\"HomeGraph.generateCardText\", async () => {\n const opportunities = state.uncachedOpportunities.length > 0\n ? state.uncachedOpportunities\n : state.opportunities;\n logger.verbose('[HomeGraph:generateCardText] entry', { opportunitiesLength: opportunities.length, userId: state.userId });\n if (opportunities.length === 0) {\n logger.verbose('[HomeGraph:generateCardText] exit', { totalOpportunities: 0, totalSections: 0 });\n return { cards: [], agentTimings: [], meta: { totalOpportunities: 0, totalSections: 0 } };\n }\n const db = this.database as PresenterDatabase & HomeGraphDb;\n const cards: HomeCardItem[] = [];\n const relevantActorIds = new Set<string>();\n for (const opp of opportunities) {\n for (const a of opp.actors) {\n if (a.userId) relevantActorIds.add(a.userId);\n }\n }\n\n const userEntries = await Promise.all(\n Array.from(relevantActorIds).map(async (userId) => {\n try {\n const user = await this.database.getUser(userId);\n return [userId, user ?? null] as const;\n } catch {\n return [userId, null] as const;\n }\n })\n );\n const userMap = new Map(userEntries);\n\n const oppIndexMap = new Map(\n state.opportunities.map((opp, idx) => [opp.id, idx])\n );\n\n const agentTimingsAccum: DebugMetaAgent[] = [];\n\n for (let i = 0; i < opportunities.length; i += PRESENTATION_CONCURRENCY) {\n const chunk = opportunities.slice(i, i + PRESENTATION_CONCURRENCY);\n const chunkCards = await Promise.all(\n chunk.map(async (opportunity, offset) => {\n const cardIndex = oppIndexMap.get(opportunity.id) ?? (i + offset);\n const viewerActor = opportunity.actors.find((a) => a.userId === state.userId);\n const viewerRole = viewerActor?.role ?? 'party';\n const isIntroducer = viewerRole === 'introducer';\n const isPendingIntroducer = isIntroducer && opportunity.status === 'pending';\n const preferredActor = pickDisplayCounterpartActor(opportunity, state.userId)\n ?? opportunity.actors.find((a) => a.userId !== state.userId && a.role !== 'introducer');\n const actorWithProfile = opportunity.actors.find(\n (a) => a.userId !== state.userId && a.role !== 'introducer' && !!userMap.get(a.userId)\n );\n const introducer = opportunity.actors.find((a) => a.role === 'introducer');\n let otherActor = (preferredActor && userMap.get(preferredActor.userId))\n ? preferredActor\n : (actorWithProfile ?? preferredActor);\n // When the only other participant is the introducer (no separate party), use introducer as display counterpart so the card shows a name instead of \"Unknown\"\n if (!otherActor && introducer && introducer.userId !== state.userId && introducer.userId) {\n otherActor = { userId: introducer.userId, role: introducer.role };\n }\n const otherUser = otherActor ? userMap.get(otherActor.userId) ?? null : null;\n const introducerCounterparts = opportunity.actors.filter(\n (a) => a.userId !== state.userId && a.role !== 'introducer'\n );\n // Deduplicate by userId — actors array can contain multiple rows per user\n // (e.g. from different intents), which would produce repeated names.\n const uniqueCounterpartIds = [...new Set(introducerCounterparts.map((a) => a.userId))];\n const participantNames = uniqueCounterpartIds\n .map((uid) => userMap.get(uid)?.name ?? 'Unknown')\n .sort();\n // When secondPartyData will be present (2+ counterparts), use single counterpart name\n // because the frontend arrow layout renders \"card.name → secondParty.name\".\n // Using the joined \"A ↔ B\" format here would produce redundant \"A ↔ B → B\".\n // Only use the joined format when there is a single counterpart (no arrow layout).\n const willHaveSecondParty = isIntroducer && uniqueCounterpartIds.length > 1;\n let userName = isIntroducer && participantNames.length > 0 && !willHaveSecondParty\n ? participantNames.join(' ↔ ')\n : (otherUser?.name ?? 'Unknown');\n // Fallback to profile identity name when users.name is missing (e.g. profile has display name, users row does not)\n if ((userName === 'Unknown' || !userName?.trim()) && otherActor?.userId && db.getProfile) {\n const profile = await db.getProfile(otherActor.userId).catch((err) => {\n logger.debug('[HomeGraph] getProfile fallback failed', { otherActorUserId: otherActor.userId, error: err });\n return null;\n });\n const profileName = profile?.identity?.name?.trim();\n if (profileName) userName = profileName;\n }\n const userAvatar = otherUser?.avatar ?? null;\n const reasoningSnippet =\n (typeof opportunity.interpretation?.reasoning === 'string'\n ? opportunity.interpretation.reasoning.replace(/\\s+/g, ' ').trim().slice(0, MAX_REASONING_SNIPPET_LENGTH)\n : '') || 'A promising connection.';\n\n // Build secondParty for introducer arrow layout (the party that isn't the display counterpart)\n let secondPartyData: { name: string; avatar?: string | null; userId?: string } | undefined;\n if (isIntroducer && introducerCounterparts.length > 1 && otherActor) {\n const secondActor = introducerCounterparts.find((a) => a.userId !== otherActor.userId);\n if (secondActor) {\n const secondUser = userMap.get(secondActor.userId) ?? null;\n secondPartyData = {\n name: secondUser?.name ?? 'Unknown',\n avatar: secondUser?.avatar ?? null,\n userId: secondActor.userId,\n };\n }\n }\n\n const isCounterpartGhost = otherUser?.isGhost ?? false;\n const isPendingIntroducerFallback = isIntroducer && opportunity.status !== 'latent';\n const fallbackCard = (): HomeCardItem => ({\n opportunityId: opportunity.id,\n userId: otherActor?.userId ?? '',\n name: userName,\n avatar: userAvatar,\n mainText: reasoningSnippet.slice(0, 300),\n cta: isIntroducer\n ? (isPendingIntroducerFallback ? 'Share this introduction to get things started.' : 'Take a look and decide if this is a good match.')\n : 'Take a look and decide whether to reach out.',\n primaryActionLabel: getPrimaryActionLabel(viewerRole),\n secondaryActionLabel: SECONDARY_ACTION_LABEL,\n mutualIntentsLabel: isIntroducer ? 'Connector match' : 'Shared interests',\n narratorChip: isIntroducer\n ? { name: 'You', text: 'Worth a look.', userId: state.userId }\n : { name: 'Index', text: 'Worth a look.' },\n viewerRole,\n isGhost: isCounterpartGhost,\n ...(secondPartyData ? { secondParty: secondPartyData } : {}),\n _cardIndex: cardIndex,\n });\n\n try {\n const [ctx, negotiationContext] = await Promise.all([\n gatherPresenterContext(\n db,\n opportunity,\n state.userId,\n otherActor?.userId,\n ),\n loadNegotiationContext(db, opportunity.id, opportunity.status),\n ]);\n const homeInput = {\n ...ctx,\n mutualIntentCount: undefined,\n opportunityStatus: opportunity.status,\n ...(negotiationContext ? { negotiationContext } : {}),\n };\n const _traceEmitterPresenter = requestContext.getStore()?.traceEmitter;\n const presenterStart = Date.now();\n _traceEmitterPresenter?.({ type: \"agent_start\", name: \"opportunity-presenter\" });\n const presentation = await presenter.presentHomeCard(homeInput);\n const _presenterDuration = Date.now() - presenterStart;\n agentTimingsAccum.push({ name: 'opportunity.presenter', durationMs: _presenterDuration });\n _traceEmitterPresenter?.({ type: \"agent_end\", name: \"opportunity-presenter\", durationMs: _presenterDuration, summary: `Presented: ${userName}` });\n let narratorChip: { name: string; text: string; avatar?: string | null; userId?: string } | undefined;\n // Only show a person as narrator when they are the introducer and not the display counterpart\n // (bad data can have same user as introducer and party, e.g. \"Amina introduced you to Amina\")\n const introducerIsCounterpart = introducer && otherActor && introducer.userId === otherActor.userId;\n if (introducer && introducer.userId !== state.userId && !introducerIsCounterpart) {\n const introUser = userMap.get(introducer.userId) ?? null;\n const narratorName = introUser?.name ?? 'Someone';\n narratorChip = {\n name: narratorName,\n text: stripLeadingNarratorName(presentation.narratorRemark, narratorName),\n avatar: introUser?.avatar ?? null,\n userId: introducer.userId,\n };\n } else if (introducer?.userId === state.userId) {\n narratorChip = { name: 'You', text: presentation.narratorRemark, userId: state.userId };\n } else {\n narratorChip = { name: 'Index', text: presentation.narratorRemark };\n }\n return {\n opportunityId: opportunity.id,\n userId: otherActor?.userId ?? '',\n name: userName,\n avatar: userAvatar,\n mainText: presentation.personalizedSummary,\n cta: presentation.suggestedAction,\n headline: presentation.headline,\n primaryActionLabel: getPrimaryActionLabel(viewerRole),\n secondaryActionLabel: SECONDARY_ACTION_LABEL,\n mutualIntentsLabel: presentation.mutualIntentsLabel,\n narratorChip,\n viewerRole,\n isGhost: isCounterpartGhost,\n ...(secondPartyData ? { secondParty: secondPartyData } : {}),\n _cardIndex: cardIndex,\n } satisfies HomeCardItem;\n } catch (e) {\n logger.warn('HomeGraph presenter failed for opportunity', { opportunityId: opportunity.id, error: e });\n return fallbackCard();\n }\n })\n );\n cards.push(...chunkCards);\n }\n logger.verbose('[HomeGraph:generateCardText] exit', { totalOpportunities: state.opportunities.length, totalSections: 0 });\n return {\n cards,\n agentTimings: agentTimingsAccum,\n meta: { totalOpportunities: state.opportunities.length, totalSections: 0 },\n };\n });\n };\n\n const cachePresenterResultsNode = async (state: typeof HomeGraphState.State) => {\n return timed(\"HomeGraph.cachePresenterResults\", async () => {\n const { cards, cachedCards, userId, opportunities } = state;\n\n // Only cache cards that weren't already from cache\n const newCards = cards.filter((card) => !cachedCards.has(card.opportunityId));\n const statusById = new Map(opportunities.map((opp) => [opp.id, opp.status]));\n\n try {\n await Promise.all(\n newCards.map((card) => {\n const status = statusById.get(card.opportunityId);\n // Skip persisting negotiating cards — see read-side note.\n if (!status || status === 'negotiating') return Promise.resolve();\n // Skip caching cards with unresolved names — transient DB failures\n // would persist \"Unknown\" placeholders for the full TTL.\n if (!card.name || card.name === 'Unknown') return Promise.resolve();\n return this.cache.set(\n `home:card:${card.opportunityId}:${status}:${userId}`,\n card,\n { ttl: HOME_CACHE_TTL }\n );\n })\n );\n } catch (e) {\n logger.warn('[HomeGraph:cachePresenterResults] cache write failed, continuing', { error: e });\n }\n\n // Merge cached cards into full card list\n const allCards: HomeCardItem[] = [...cards];\n for (const [oppId, cachedCard] of cachedCards) {\n if (!cards.some((c) => c.opportunityId === oppId)) {\n allCards.push(cachedCard);\n }\n }\n\n // Re-sort by _cardIndex to maintain original ordering\n allCards.sort((a, b) => a._cardIndex - b._cardIndex);\n\n logger.verbose('[HomeGraph:cachePresenterResults]', {\n newlyCached: newCards.length,\n totalCards: allCards.length,\n });\n\n return {\n cards: allCards,\n meta: { totalOpportunities: state.opportunities.length, totalSections: 0 },\n };\n });\n };\n\n const checkCategorizerCacheNode = async (state: typeof HomeGraphState.State) => {\n return timed(\"HomeGraph.checkCategorizerCache\", async () => {\n if (state.cards.length === 0) {\n return { categoryCacheHit: false };\n }\n\n if (state.noCache) {\n logger.verbose('[HomeGraph:checkCategorizerCache] noCache=true, skipping cache');\n return { categoryCacheHit: false };\n }\n\n try {\n const oppIds = state.cards\n .map((c) => c.opportunityId)\n .join(',');\n const hash = createHash('sha256').update(oppIds).digest('hex').slice(0, 16);\n const key = `home:categories:${state.userId}:${hash}`;\n\n const cached = await this.cache.get<HomeSectionProposal[]>(key);\n if (cached) {\n logger.verbose('[HomeGraph:checkCategorizerCache] cache hit');\n return { sectionProposals: cached, categoryCacheHit: true };\n }\n\n logger.verbose('[HomeGraph:checkCategorizerCache] cache miss');\n } catch (e) {\n logger.warn('[HomeGraph:checkCategorizerCache] cache unavailable, skipping', { error: e });\n }\n return { categoryCacheHit: false };\n });\n };\n\n const shouldCategorize = (state: typeof HomeGraphState.State): string => {\n if (state.categoryCacheHit) {\n logger.verbose('[HomeGraph] Categorizer results cached, skipping');\n return 'skip';\n }\n return 'categorize';\n };\n\n const categorizeDynamicallyNode = async (state: typeof HomeGraphState.State) => {\n return timed(\"HomeGraph.categorizeDynamically\", async () => {\n logger.verbose('[HomeGraph:categorizeDynamically] entry', { cardsLength: state.cards.length });\n if (state.cards.length === 0) {\n logger.verbose('[HomeGraph:categorizeDynamically] exit', { sectionProposalsCount: 0 });\n return { sectionProposals: [], agentTimings: [] };\n }\n const agentTimingsAccum: DebugMetaAgent[] = [];\n const categorizerInput = state.cards.map((c) => ({\n index: c._cardIndex,\n headline: c.headline,\n mainText: c.mainText,\n name: c.name,\n viewerRole: c.viewerRole === 'introducer' ? 'introducer' : undefined,\n opportunityStatus: c.viewerRole === 'introducer' ? 'pending' : undefined,\n }));\n const _traceEmitterCategorizer = requestContext.getStore()?.traceEmitter;\n const categorizerStart = Date.now();\n _traceEmitterCategorizer?.({ type: \"agent_start\", name: \"home-categorizer\" });\n const { sections } = await categorizer.categorize(categorizerInput);\n const _categorizerDuration = Date.now() - categorizerStart;\n agentTimingsAccum.push({ name: 'home.categorizer', durationMs: _categorizerDuration });\n _traceEmitterCategorizer?.({ type: \"agent_end\", name: \"home-categorizer\", durationMs: _categorizerDuration, summary: `Categorized into ${sections.length} section(s)` });\n const proposals: HomeSectionProposal[] = sections.map((s) => ({\n ...s,\n itemIndices: s.itemIndices.filter((i) => i >= 0 && i < state.cards.length),\n }));\n logger.verbose('[HomeGraph:categorizeDynamically] exit', { sectionProposalsCount: proposals.length });\n return { sectionProposals: proposals, agentTimings: agentTimingsAccum };\n });\n };\n\n const cacheCategorizerResultsNode = async (state: typeof HomeGraphState.State) => {\n return timed(\"HomeGraph.cacheCategorizerResults\", async () => {\n if (state.categoryCacheHit || state.sectionProposals.length === 0) {\n return {};\n }\n\n try {\n const oppIds = state.cards\n .map((c) => c.opportunityId)\n .join(',');\n const hash = createHash('sha256').update(oppIds).digest('hex').slice(0, 16);\n const key = `home:categories:${state.userId}:${hash}`;\n\n await this.cache.set(key, state.sectionProposals, { ttl: HOME_CACHE_TTL });\n\n logger.verbose('[HomeGraph:cacheCategorizerResults] cached', {\n sectionCount: state.sectionProposals.length,\n });\n } catch (e) {\n logger.warn('[HomeGraph:cacheCategorizerResults] cache write failed, continuing', { error: e });\n }\n\n return {};\n });\n };\n\n const normalizeAndSortNode = async (state: typeof HomeGraphState.State) => {\n return timed(\"HomeGraph.normalizeAndSort\", async () => {\n const cards = state.cards;\n const proposals = state.sectionProposals;\n logger.verbose('[HomeGraph:normalizeAndSort] entry', { cardsLength: cards.length, proposalsLength: proposals.length });\n if (cards.length === 0) {\n logger.verbose('[HomeGraph:normalizeAndSort] exit', { totalOpportunities: 0, totalSections: 0 });\n return { sections: [], meta: { totalOpportunities: 0, totalSections: 0 } };\n }\n const usedIndices = new Set<number>();\n const sections: HomeSection[] = proposals.map((p) => {\n const iconName = resolveHomeSectionIcon(p.iconName);\n const items: HomeSectionItem[] = p.itemIndices\n .filter((i) => i >= 0 && i < cards.length && !usedIndices.has(i))\n .slice(0, MAX_ITEMS_PER_SECTION)\n .map((i) => {\n usedIndices.add(i);\n const card = cards[i];\n const { _cardIndex, ...rest } = card;\n return rest;\n });\n return {\n id: p.id,\n title: p.title,\n subtitle: p.subtitle,\n iconName,\n items,\n };\n });\n\n // Enforce category ordering: sections with connections first, then\n // connector-flow only, then expired only. This prevents the LLM\n // categorizer from placing introducer sections before connection sections.\n const sectionCategoryPriority = (section: HomeSection): number => {\n const hasConnection = section.items.some((item) => item.viewerRole !== 'introducer');\n if (hasConnection) return 0; // mixed or connection-only sections first\n const hasConnectorFlow = section.items.some((item) => item.viewerRole === 'introducer');\n if (hasConnectorFlow) return 1; // connector-flow only sections next\n return 2; // empty or expired sections last\n };\n sections.sort((a, b) => sectionCategoryPriority(a) - sectionCategoryPriority(b));\n const meta = {\n totalOpportunities: state.opportunities.length,\n totalSections: sections.length,\n };\n logger.verbose('[HomeGraph:normalizeAndSort] exit', { totalOpportunities: meta.totalOpportunities, totalSections: meta.totalSections });\n return { sections, meta };\n });\n };\n\n const graph = new StateGraph(HomeGraphState)\n .addNode('loadOpportunities', loadOpportunitiesNode)\n .addNode('checkPresenterCache', checkPresenterCacheNode)\n .addNode('generateCardText', generateCardTextNode)\n .addNode('cachePresenterResults', cachePresenterResultsNode)\n .addNode('checkCategorizerCache', checkCategorizerCacheNode)\n .addNode('categorizeDynamically', categorizeDynamicallyNode)\n .addNode('cacheCategorizerResults', cacheCategorizerResultsNode)\n .addNode('normalizeAndSort', normalizeAndSortNode)\n .addEdge(START, 'loadOpportunities')\n .addEdge('loadOpportunities', 'checkPresenterCache')\n .addConditionalEdges('checkPresenterCache', shouldGenerateCards, {\n generate: 'generateCardText',\n skip: 'cachePresenterResults',\n })\n .addEdge('generateCardText', 'cachePresenterResults')\n .addEdge('cachePresenterResults', 'checkCategorizerCache')\n .addConditionalEdges('checkCategorizerCache', shouldCategorize, {\n categorize: 'categorizeDynamically',\n skip: 'normalizeAndSort',\n })\n .addEdge('categorizeDynamically', 'cacheCategorizerResults')\n .addEdge('cacheCategorizerResults', 'normalizeAndSort')\n .addEdge('normalizeAndSort', END);\n\n return graph.compile();\n }\n}\n"]}
1
+ {"version":3,"file":"feed.graph.js","sourceRoot":"/","sources":["opportunity/feed/feed.graph.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAC;AAEpC,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAI9D,OAAO,EAAE,cAAc,EAAuF,MAAM,iBAAiB,CAAC;AACtI,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAA0B,MAAM,6BAA6B,CAAC;AACnH,OAAO,EAAE,sBAAsB,EAAE,MAAM,kCAAkC,CAAC;AAC1E,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAC7D,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAC5G,OAAO,EAAE,sBAAsB,EAA6B,MAAM,wCAAwC,CAAC;AAC3G,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAEzF,OAAO,EAAE,cAAc,EAAE,MAAM,+CAA+C,CAAC;AAC/E,OAAO,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,+CAA+C,CAAC;AAE/E,MAAM,MAAM,GAAG,cAAc,CAAC,WAAW,CAAC,CAAC;AAoB3C,kFAAkF;AAClF,MAAM,CAAC,MAAM,qBAAqB,GAAwB,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;AAEhF,8E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AAE,yBAAyB,CAAC;aAC3D,OAAO,CAAC,yBAAyB,EAAE,2BAA2B,CAAC;aAC/D,OAAO,CAAC,kBAAkB,EAAE,oBAAoB,CAAC;aACjD,OAAO,CAAC,KAAK,EAAE,mBAAmB,CAAC;aACnC,OAAO,CAAC,mBAAmB,EAAE,qBAAqB,CAAC;aACnD,mBAAmB,CAAC,qBAAqB,EAAE,mBAAmB,EAAE;YAC/D,QAAQ,EAAE,kBAAkB;YAC5B,IAAI,EAAE,uBAAuB;SAC9B,CAAC;aACD,OAAO,CAAC,kBAAkB,EAAE,uBAAuB,CAAC;aACpD,OAAO,CAAC,uBAAuB,EAAE,uBAAuB,CAAC;aACzD,mBAAmB,CAAC,uBAAuB,EAAE,gBAAgB,EAAE;YAC9D,UAAU,EAAE,uBAAuB;YACnC,IAAI,EAAE,kBAAkB;SACzB,CAAC;aACD,OAAO,CAAC,uBAAuB,EAAE,yBAAyB,CAAC;aAC3D,OAAO,CAAC,yBAAyB,EAAE,kBAAkB,CAAC;aACtD,OAAO,CAAC,kBAAkB,EAAE,GAAG,CAAC,CAAC;QAEpC,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;CACF","sourcesContent":["/**\n * Home Graph: Build the opportunity home view with dynamic sections.\n *\n * Independent of ChatGraph. Flow:\n * loadOpportunities → checkPresenterCache → [generateCardText if misses] → cachePresenterResults\n * → checkCategorizerCache → [categorizeDynamically if miss] → cacheCategorizerResults → normalizeAndSort\n *\n * Uses OpportunityPresenter for card text and an LLM to categorize cards into dynamic sections\n * with titles and Lucide icon names. Caches presenter and categorizer results via OpportunityCache.\n */\n\nimport { createHash } from 'crypto';\n\nimport { StateGraph, START, END } from '@langchain/langgraph';\n\nimport type { HomeGraphDatabase, OpportunityStatus } from '../../shared/interfaces/database.interface.js';\nimport type { OpportunityCache } from '../../shared/interfaces/cache.interface.js';\nimport { HomeGraphState, type HomeCardItem, type HomeSection, type HomeSectionProposal, type HomeSectionItem } from './feed.state.js';\nimport { OpportunityPresenter, gatherPresenterContext, type PresenterDatabase } from '../opportunity.presenter.js';\nimport { loadNegotiationContext } from '../negotiation-context.loader.js';\nimport { HomeCategorizerAgent } from './feed.categorizer.js';\nimport { canUserSeeOpportunity, isActionableForViewer, selectByComposition } from '../opportunity.utils.js';\nimport { resolveHomeSectionIcon, DEFAULT_HOME_SECTION_ICON } from '../../shared/ui/lucide.icon-catalog.js';\nimport { getPrimaryActionLabel, SECONDARY_ACTION_LABEL } from '../opportunity.labels.js';\nimport type { DebugMetaAgent } from '../../chat/chat-streaming.types.js';\nimport { protocolLogger } from '../../shared/observability/protocol.logger.js';\nimport { timed } from '../../shared/observability/performance.js';\nimport { requestContext } from \"../../shared/observability/request-context.js\";\n\nconst logger = protocolLogger('HomeGraph');\n\n/** Database must satisfy both HomeGraphDatabase and presenter context (getProfile, getActiveIntents, getNetwork, getUser). */\ntype HomeGraphDb = HomeGraphDatabase;\n\nexport type HomeGraphInvokeInput = {\n userId: string;\n networkId?: string;\n limit?: number;\n noCache?: boolean;\n /** When set, filter loaded opportunities to these lifecycle statuses. Defaults to `DEFAULT_HOME_STATUSES`. */\n statuses?: OpportunityStatus[];\n};\n\nexport type HomeGraphInvokeResult = {\n sections: HomeSection[];\n meta: { totalOpportunities: number; totalSections: number };\n error?: string;\n};\n\n/** Default home-feed statuses: the lifecycle stages a viewer can act on today. */\nexport const DEFAULT_HOME_STATUSES: OpportunityStatus[] = ['latent', 'pending'];\n\n// Exhaustive registry — keys must cover every OpportunityStatus union member.\n// Adding a new status to OpportunityStatus without adding a key here is a TS error,\n// which is the whole point: prevents ALL_OPPORTUNITY_STATUSES from silently drifting.\nconst OPPORTUNITY_STATUS_REGISTRY: Record<OpportunityStatus, true> = {\n latent: true,\n draft: true,\n negotiating: true,\n pending: true,\n stalled: true,\n accepted: true,\n rejected: true,\n expired: true,\n};\n\n/** Full status enumeration. Pass this to `HomeGraphInvokeInput.statuses` to restore pre-Issue-3 (unfiltered) behavior. */\nexport const ALL_OPPORTUNITY_STATUSES: OpportunityStatus[] = Object.keys(\n OPPORTUNITY_STATUS_REGISTRY,\n) as OpportunityStatus[];\n\nconst MAX_ITEMS_PER_SECTION = 20;\nconst PRESENTATION_CONCURRENCY = 50;\nconst MAX_REASONING_SNIPPET_LENGTH = 240;\nconst HOME_CACHE_TTL = 24 * 60 * 60; // 24 hours in seconds\n\n/** Redis key for the categorizer cache, derived from the user and the ordered opportunity-id set. */\nfunction buildCategorizerCacheKey(userId: string, cards: HomeCardItem[]): string {\n const oppIds = cards.map((c) => c.opportunityId).join(',');\n const hash = createHash('sha256').update(oppIds).digest('hex').slice(0, 16);\n return `home:categories:${userId}:${hash}`;\n}\n\n/**\n * Strip leading narrator name from remark when the UI already prepends \"Name: \" to the chip.\n * Avoids duplication like \"Yankı Ekin Yüksel: Yankı Ekin Yüksel introduced you two...\"\n * Repeats until no leading name (handles \"Name: Name rest\").\n */\nexport function stripLeadingNarratorName(remark: string, narratorName: string): string {\n let t = remark.trim();\n if (!t || !narratorName.trim()) return remark;\n const name = narratorName.trim();\n const nameLower = name.toLowerCase();\n for (;;) {\n const lower = t.toLowerCase();\n if (!lower.startsWith(nameLower)) break;\n const rest = t.slice(name.length).replace(/^\\s*[:,\\-–—]\\s*/i, '').trim();\n if (rest.length === 0 || rest === t) break;\n t = rest;\n }\n return t;\n}\n\n/** Normalize timestamp for sorting; returns numeric ms or 0 for invalid/missing. */\nconst safeParseDate = (value: unknown): number => {\n if (value == null) return 0;\n if (value instanceof Date) {\n const t = value.getTime();\n return Number.isFinite(t) ? t : 0;\n }\n if (typeof value === 'number' && Number.isFinite(value)) return value;\n if (typeof value === 'string') {\n const t = new Date(value).getTime();\n return Number.isFinite(t) ? t : 0;\n }\n return 0;\n};\n\n/** Confidence score for sorting (interpretation.confidence or opportunity.confidence). */\nconst getConfidence = (opp: typeof HomeGraphState.State['opportunities'][number]): number => {\n const fromInterp = opp.interpretation?.confidence;\n if (typeof fromInterp === 'number' && !Number.isNaN(fromInterp)) return fromInterp;\n if (typeof fromInterp === 'string') {\n const n = parseFloat(fromInterp);\n if (!Number.isNaN(n)) return n;\n }\n const fromRow = opp.confidence;\n if (typeof fromRow === 'number' && !Number.isNaN(fromRow)) return fromRow;\n if (typeof fromRow === 'string') {\n const n = parseFloat(fromRow);\n if (!Number.isNaN(n)) return n;\n }\n return 0;\n};\n\n/** Unique non-introducer, non-viewer userIds for an opportunity (actors can repeat). */\nconst getUniqueCounterpartUserIds = (\n opp: typeof HomeGraphState.State['opportunities'][number],\n viewerId: string\n): Set<string> => {\n const ids = new Set<string>();\n for (const a of opp.actors) {\n if (a.role !== 'introducer' && a.userId !== viewerId && a.userId) {\n ids.add(a.userId);\n }\n }\n return ids;\n};\n\nconst pickDisplayCounterpartActor = (\n opportunity: typeof HomeGraphState.State['opportunities'][number],\n viewerId: string\n): { userId: string; role: string } | null => {\n const candidates = opportunity.actors.filter(\n (actor) => actor.userId !== viewerId && actor.role !== 'introducer'\n );\n if (candidates.length === 0) {\n return null;\n }\n\n // Prefer direct counterpart roles when available, then stable sort by user id.\n const rolePriority = new Map<string, number>([\n ['patient', 0],\n ['party', 1],\n ['agent', 2],\n ['peer', 3],\n ]);\n\n const sorted = [...candidates].sort((a, b) => {\n const aPriority = rolePriority.get(a.role) ?? 99;\n const bPriority = rolePriority.get(b.role) ?? 99;\n if (aPriority !== bPriority) return aPriority - bPriority;\n return a.userId.localeCompare(b.userId);\n });\n return sorted[0] ?? null;\n};\n\nexport class HomeGraphFactory {\n constructor(private database: HomeGraphDb, private cache: OpportunityCache) {}\n\n createGraph() {\n const presenter = new OpportunityPresenter();\n const categorizer = new HomeCategorizerAgent();\n\n const loadOpportunitiesNode = async (state: typeof HomeGraphState.State) => {\n return timed(\"HomeGraph.loadOpportunities\", async () => {\n if (!state.userId) {\n return { error: 'userId is required' };\n }\n try {\n // Minimum of 50 ensures enough candidates across all feed categories\n // (connection, connector-flow, expired) for selectByComposition to fill\n // its soft targets, even after visibility filtering and dedup.\n const fetchLimit = Math.min(150, Math.max(50, state.limit * 3));\n const statuses = state.statuses ?? DEFAULT_HOME_STATUSES;\n const options: { limit?: number; networkId?: string; statuses?: OpportunityStatus[] } = {\n limit: fetchLimit,\n statuses,\n };\n if (state.networkId) options.networkId = state.networkId;\n // Do not pass conversationId: home view excludes draft opportunities (chat-only drafts).\n const raw = await this.database.getOpportunitiesForUser(state.userId, options);\n const visible = raw.filter((opp) =>\n canUserSeeOpportunity(opp.actors, opp.status, state.userId)\n );\n const visibleForFeed = visible.filter((opp) =>\n isActionableForViewer(opp.actors, opp.status, state.userId)\n );\n const sorted = [...visibleForFeed].sort((a, b) => {\n // Connections before connector-flow so dedup claims counterpart IDs\n // for direct connections first — prevents introducer cards from\n // shadowing a user's own connection opportunities.\n const aIsIntroducer = a.actors.some((ac) => ac.userId === state.userId && ac.role === 'introducer');\n const bIsIntroducer = b.actors.some((ac) => ac.userId === state.userId && ac.role === 'introducer');\n if (aIsIntroducer !== bIsIntroducer) return aIsIntroducer ? 1 : -1;\n const confA = getConfidence(a);\n const confB = getConfidence(b);\n if (confB !== confA) return confB - confA;\n const aTime = safeParseDate(a.updatedAt);\n const bTime = safeParseDate(b.updatedAt);\n return bTime - aTime;\n });\n const seenUserIds = new Set<string>();\n const deduped = sorted.filter((opp) => {\n const counterpartIds = getUniqueCounterpartUserIds(opp, state.userId);\n const hasOverlap = [...counterpartIds].some((id) => seenUserIds.has(id));\n if (hasOverlap) return false;\n for (const id of counterpartIds) seenUserIds.add(id);\n return true;\n });\n const opportunities = selectByComposition(deduped, state.userId);\n return { opportunities };\n } catch (e) {\n logger.error('HomeGraph loadOpportunities failed', { error: e });\n return { error: 'Failed to load opportunities', opportunities: [] };\n }\n });\n };\n\n const checkPresenterCacheNode = async (state: typeof HomeGraphState.State) => {\n return timed(\"HomeGraph.checkPresenterCache\", async () => {\n const { opportunities, userId } = state;\n if (opportunities.length === 0) {\n return { cachedCards: new Map(), uncachedOpportunities: [] };\n }\n\n if (state.noCache) {\n logger.verbose('[HomeGraph:checkPresenterCache] noCache=true, skipping cache');\n return { cachedCards: new Map(), uncachedOpportunities: opportunities };\n }\n\n try {\n // Negotiating cards are templated (no LLM call) and their text\n // depends on the live turn count, which changes between requests\n // without changing the opportunity status. Skip cache entirely\n // for them so each render reflects the current turn.\n //\n // For all other statuses, include status in the key so status\n // transitions (e.g. negotiating → pending) don't serve stale cards.\n const cacheable = opportunities.filter((opp) => opp.status !== 'negotiating');\n const liveNegotiating = opportunities.filter((opp) => opp.status === 'negotiating');\n\n const keys = cacheable.map(\n (opp) => `home:card:${opp.id}:${opp.status}:${userId}`\n );\n const results = keys.length > 0 ? await this.cache.mget<HomeCardItem>(keys) : [];\n\n const cachedCards = new Map<string, HomeCardItem>();\n const uncachedOpportunities: typeof opportunities = [...liveNegotiating];\n\n for (let i = 0; i < cacheable.length; i++) {\n const cached = results[i];\n if (cached) {\n const originalIndex = opportunities.indexOf(cacheable[i]);\n cachedCards.set(cacheable[i].id, { ...cached, _cardIndex: originalIndex });\n } else {\n uncachedOpportunities.push(cacheable[i]);\n }\n }\n\n logger.verbose('[HomeGraph:checkPresenterCache]', {\n total: opportunities.length,\n cacheHits: cachedCards.size,\n cacheMisses: uncachedOpportunities.length,\n });\n\n return { cachedCards, uncachedOpportunities };\n } catch (e) {\n logger.warn('[HomeGraph:checkPresenterCache] cache unavailable, skipping', { error: e });\n return { cachedCards: new Map(), uncachedOpportunities: opportunities };\n }\n });\n };\n\n const shouldGenerateCards = (state: typeof HomeGraphState.State): string => {\n if (state.uncachedOpportunities.length > 0) {\n return 'generate';\n }\n logger.verbose('[HomeGraph] All presenter results cached, skipping generation');\n return 'skip';\n };\n\n const generateCardTextNode = async (state: typeof HomeGraphState.State) => {\n return timed(\"HomeGraph.generateCardText\", async () => {\n const opportunities = state.uncachedOpportunities.length > 0\n ? state.uncachedOpportunities\n : state.opportunities;\n logger.verbose('[HomeGraph:generateCardText] entry', { opportunitiesLength: opportunities.length, userId: state.userId });\n if (opportunities.length === 0) {\n logger.verbose('[HomeGraph:generateCardText] exit', { totalOpportunities: 0, totalSections: 0 });\n return { cards: [], agentTimings: [], meta: { totalOpportunities: 0, totalSections: 0 } };\n }\n const db = this.database as PresenterDatabase & HomeGraphDb;\n const cards: HomeCardItem[] = [];\n const relevantActorIds = new Set<string>();\n for (const opp of opportunities) {\n for (const a of opp.actors) {\n if (a.userId) relevantActorIds.add(a.userId);\n }\n }\n\n const userEntries = await Promise.all(\n Array.from(relevantActorIds).map(async (userId) => {\n try {\n const user = await this.database.getUser(userId);\n return [userId, user ?? null] as const;\n } catch {\n return [userId, null] as const;\n }\n })\n );\n const userMap = new Map(userEntries);\n\n const oppIndexMap = new Map(\n state.opportunities.map((opp, idx) => [opp.id, idx])\n );\n\n const agentTimingsAccum: DebugMetaAgent[] = [];\n\n for (let i = 0; i < opportunities.length; i += PRESENTATION_CONCURRENCY) {\n const chunk = opportunities.slice(i, i + PRESENTATION_CONCURRENCY);\n const chunkCards = await Promise.all(\n chunk.map(async (opportunity, offset) => {\n const cardIndex = oppIndexMap.get(opportunity.id) ?? (i + offset);\n const viewerActor = opportunity.actors.find((a) => a.userId === state.userId);\n const viewerRole = viewerActor?.role ?? 'party';\n const isIntroducer = viewerRole === 'introducer';\n const isPendingIntroducer = isIntroducer && opportunity.status === 'pending';\n const preferredActor = pickDisplayCounterpartActor(opportunity, state.userId)\n ?? opportunity.actors.find((a) => a.userId !== state.userId && a.role !== 'introducer');\n const actorWithProfile = opportunity.actors.find(\n (a) => a.userId !== state.userId && a.role !== 'introducer' && !!userMap.get(a.userId)\n );\n const introducer = opportunity.actors.find((a) => a.role === 'introducer');\n let otherActor = (preferredActor && userMap.get(preferredActor.userId))\n ? preferredActor\n : (actorWithProfile ?? preferredActor);\n // When the only other participant is the introducer (no separate party), use introducer as display counterpart so the card shows a name instead of \"Unknown\"\n if (!otherActor && introducer && introducer.userId !== state.userId && introducer.userId) {\n otherActor = { userId: introducer.userId, role: introducer.role };\n }\n const otherUser = otherActor ? userMap.get(otherActor.userId) ?? null : null;\n const introducerCounterparts = opportunity.actors.filter(\n (a) => a.userId !== state.userId && a.role !== 'introducer'\n );\n // Deduplicate by userId — actors array can contain multiple rows per user\n // (e.g. from different intents), which would produce repeated names.\n const uniqueCounterpartIds = [...new Set(introducerCounterparts.map((a) => a.userId))];\n const participantNames = uniqueCounterpartIds\n .map((uid) => userMap.get(uid)?.name ?? 'Unknown')\n .sort();\n // When secondPartyData will be present (2+ counterparts), use single counterpart name\n // because the frontend arrow layout renders \"card.name → secondParty.name\".\n // Using the joined \"A ↔ B\" format here would produce redundant \"A ↔ B → B\".\n // Only use the joined format when there is a single counterpart (no arrow layout).\n const willHaveSecondParty = isIntroducer && uniqueCounterpartIds.length > 1;\n let userName = isIntroducer && participantNames.length > 0 && !willHaveSecondParty\n ? participantNames.join(' ↔ ')\n : (otherUser?.name ?? 'Unknown');\n // Fallback to profile identity name when users.name is missing (e.g. profile has display name, users row does not)\n if ((userName === 'Unknown' || !userName?.trim()) && otherActor?.userId && db.getProfile) {\n const profile = await db.getProfile(otherActor.userId).catch((err) => {\n logger.debug('[HomeGraph] getProfile fallback failed', { otherActorUserId: otherActor.userId, error: err });\n return null;\n });\n const profileName = profile?.identity?.name?.trim();\n if (profileName) userName = profileName;\n }\n const userAvatar = otherUser?.avatar ?? null;\n const reasoningSnippet =\n (typeof opportunity.interpretation?.reasoning === 'string'\n ? opportunity.interpretation.reasoning.replace(/\\s+/g, ' ').trim().slice(0, MAX_REASONING_SNIPPET_LENGTH)\n : '') || 'A promising connection.';\n\n // Build secondParty for introducer arrow layout (the party that isn't the display counterpart)\n let secondPartyData: { name: string; avatar?: string | null; userId?: string } | undefined;\n if (isIntroducer && introducerCounterparts.length > 1 && otherActor) {\n const secondActor = introducerCounterparts.find((a) => a.userId !== otherActor.userId);\n if (secondActor) {\n const secondUser = userMap.get(secondActor.userId) ?? null;\n secondPartyData = {\n name: secondUser?.name ?? 'Unknown',\n avatar: secondUser?.avatar ?? null,\n userId: secondActor.userId,\n };\n }\n }\n\n const isCounterpartGhost = otherUser?.isGhost ?? false;\n const isPendingIntroducerFallback = isIntroducer && opportunity.status !== 'latent';\n const fallbackCard = (): HomeCardItem => ({\n opportunityId: opportunity.id,\n userId: otherActor?.userId ?? '',\n name: userName,\n avatar: userAvatar,\n mainText: reasoningSnippet.slice(0, 300),\n cta: isIntroducer\n ? (isPendingIntroducerFallback ? 'Share this introduction to get things started.' : 'Take a look and decide if this is a good match.')\n : 'Take a look and decide whether to reach out.',\n primaryActionLabel: getPrimaryActionLabel(viewerRole),\n secondaryActionLabel: SECONDARY_ACTION_LABEL,\n mutualIntentsLabel: isIntroducer ? 'Connector match' : 'Shared interests',\n narratorChip: isIntroducer\n ? { name: 'You', text: 'Worth a look.', userId: state.userId }\n : { name: 'Index', text: 'Worth a look.' },\n viewerRole,\n isGhost: isCounterpartGhost,\n ...(secondPartyData ? { secondParty: secondPartyData } : {}),\n _cardIndex: cardIndex,\n });\n\n try {\n const [ctx, negotiationContext] = await Promise.all([\n gatherPresenterContext(\n db,\n opportunity,\n state.userId,\n otherActor?.userId,\n ),\n loadNegotiationContext(db, opportunity.id, opportunity.status),\n ]);\n const homeInput = {\n ...ctx,\n mutualIntentCount: undefined,\n opportunityStatus: opportunity.status,\n ...(negotiationContext ? { negotiationContext } : {}),\n };\n const _traceEmitterPresenter = requestContext.getStore()?.traceEmitter;\n const presenterStart = Date.now();\n _traceEmitterPresenter?.({ type: \"agent_start\", name: \"opportunity-presenter\" });\n const presentation = await presenter.presentHomeCard(homeInput);\n const _presenterDuration = Date.now() - presenterStart;\n agentTimingsAccum.push({ name: 'opportunity.presenter', durationMs: _presenterDuration });\n _traceEmitterPresenter?.({ type: \"agent_end\", name: \"opportunity-presenter\", durationMs: _presenterDuration, summary: `Presented: ${userName}` });\n let narratorChip: { name: string; text: string; avatar?: string | null; userId?: string } | undefined;\n // Only show a person as narrator when they are the introducer and not the display counterpart\n // (bad data can have same user as introducer and party, e.g. \"Amina introduced you to Amina\")\n const introducerIsCounterpart = introducer && otherActor && introducer.userId === otherActor.userId;\n if (introducer && introducer.userId !== state.userId && !introducerIsCounterpart) {\n const introUser = userMap.get(introducer.userId) ?? null;\n const narratorName = introUser?.name ?? 'Someone';\n narratorChip = {\n name: narratorName,\n text: stripLeadingNarratorName(presentation.narratorRemark, narratorName),\n avatar: introUser?.avatar ?? null,\n userId: introducer.userId,\n };\n } else if (introducer?.userId === state.userId) {\n narratorChip = { name: 'You', text: presentation.narratorRemark, userId: state.userId };\n } else {\n narratorChip = { name: 'Index', text: presentation.narratorRemark };\n }\n return {\n opportunityId: opportunity.id,\n userId: otherActor?.userId ?? '',\n name: userName,\n avatar: userAvatar,\n mainText: presentation.personalizedSummary,\n cta: presentation.suggestedAction,\n headline: presentation.headline,\n primaryActionLabel: getPrimaryActionLabel(viewerRole),\n secondaryActionLabel: SECONDARY_ACTION_LABEL,\n mutualIntentsLabel: presentation.mutualIntentsLabel,\n narratorChip,\n viewerRole,\n isGhost: isCounterpartGhost,\n ...(secondPartyData ? { secondParty: secondPartyData } : {}),\n _cardIndex: cardIndex,\n } satisfies HomeCardItem;\n } catch (e) {\n logger.warn('HomeGraph presenter failed for opportunity', { opportunityId: opportunity.id, error: e });\n return fallbackCard();\n }\n })\n );\n cards.push(...chunkCards);\n }\n logger.verbose('[HomeGraph:generateCardText] exit', { totalOpportunities: state.opportunities.length, totalSections: 0 });\n return {\n cards,\n agentTimings: agentTimingsAccum,\n meta: { totalOpportunities: state.opportunities.length, totalSections: 0 },\n };\n });\n };\n\n const cachePresenterResultsNode = async (state: typeof HomeGraphState.State) => {\n return timed(\"HomeGraph.cachePresenterResults\", async () => {\n const { cards, cachedCards, userId, opportunities } = state;\n\n // Only cache cards that weren't already from cache\n const newCards = cards.filter((card) => !cachedCards.has(card.opportunityId));\n const statusById = new Map(opportunities.map((opp) => [opp.id, opp.status]));\n\n try {\n await Promise.all(\n newCards.map((card) => {\n const status = statusById.get(card.opportunityId);\n // Skip persisting negotiating cards — see read-side note.\n if (!status || status === 'negotiating') return Promise.resolve();\n // Skip caching cards with unresolved names — transient DB failures\n // would persist \"Unknown\" placeholders for the full TTL.\n if (!card.name || card.name === 'Unknown') return Promise.resolve();\n return this.cache.set(\n `home:card:${card.opportunityId}:${status}:${userId}`,\n card,\n { ttl: HOME_CACHE_TTL }\n );\n })\n );\n } catch (e) {\n logger.warn('[HomeGraph:cachePresenterResults] cache write failed, continuing', { error: e });\n }\n\n // Merge cached cards into full card list\n const allCards: HomeCardItem[] = [...cards];\n for (const [oppId, cachedCard] of cachedCards) {\n if (!cards.some((c) => c.opportunityId === oppId)) {\n allCards.push(cachedCard);\n }\n }\n\n // Re-sort by _cardIndex to maintain original ordering\n allCards.sort((a, b) => a._cardIndex - b._cardIndex);\n\n logger.verbose('[HomeGraph:cachePresenterResults]', {\n newlyCached: newCards.length,\n totalCards: allCards.length,\n });\n\n return {\n cards: allCards,\n meta: { totalOpportunities: state.opportunities.length, totalSections: 0 },\n };\n });\n };\n\n const checkCategorizerCacheNode = async (state: typeof HomeGraphState.State) => {\n return timed(\"HomeGraph.checkCategorizerCache\", async () => {\n if (state.cards.length === 0) {\n return { categoryCacheHit: false };\n }\n\n if (state.noCache) {\n logger.verbose('[HomeGraph:checkCategorizerCache] noCache=true, skipping cache');\n return { categoryCacheHit: false };\n }\n\n try {\n const key = buildCategorizerCacheKey(state.userId, state.cards);\n\n const cached = await this.cache.get<HomeSectionProposal[]>(key);\n if (cached) {\n logger.verbose('[HomeGraph:checkCategorizerCache] cache hit');\n return { sectionProposals: cached, categoryCacheHit: true };\n }\n\n logger.verbose('[HomeGraph:checkCategorizerCache] cache miss');\n } catch (e) {\n logger.warn('[HomeGraph:checkCategorizerCache] cache unavailable, skipping', { error: e });\n }\n return { categoryCacheHit: false };\n });\n };\n\n const shouldCategorize = (state: typeof HomeGraphState.State): string => {\n if (state.categoryCacheHit) {\n logger.verbose('[HomeGraph] Categorizer results cached, skipping');\n return 'skip';\n }\n return 'categorize';\n };\n\n const categorizeDynamicallyNode = async (state: typeof HomeGraphState.State) => {\n return timed(\"HomeGraph.categorizeDynamically\", async () => {\n logger.verbose('[HomeGraph:categorizeDynamically] entry', { cardsLength: state.cards.length });\n if (state.cards.length === 0) {\n logger.verbose('[HomeGraph:categorizeDynamically] exit', { sectionProposalsCount: 0 });\n return { sectionProposals: [], agentTimings: [] };\n }\n const agentTimingsAccum: DebugMetaAgent[] = [];\n const categorizerInput = state.cards.map((c) => ({\n index: c._cardIndex,\n headline: c.headline,\n mainText: c.mainText,\n name: c.name,\n viewerRole: c.viewerRole === 'introducer' ? 'introducer' : undefined,\n opportunityStatus: c.viewerRole === 'introducer' ? 'pending' : undefined,\n }));\n const _traceEmitterCategorizer = requestContext.getStore()?.traceEmitter;\n const categorizerStart = Date.now();\n _traceEmitterCategorizer?.({ type: \"agent_start\", name: \"home-categorizer\" });\n const { sections } = await categorizer.categorize(categorizerInput);\n const _categorizerDuration = Date.now() - categorizerStart;\n agentTimingsAccum.push({ name: 'home.categorizer', durationMs: _categorizerDuration });\n _traceEmitterCategorizer?.({ type: \"agent_end\", name: \"home-categorizer\", durationMs: _categorizerDuration, summary: `Categorized into ${sections.length} section(s)` });\n const proposals: HomeSectionProposal[] = sections.map((s) => ({\n ...s,\n itemIndices: s.itemIndices.filter((i) => i >= 0 && i < state.cards.length),\n }));\n logger.verbose('[HomeGraph:categorizeDynamically] exit', { sectionProposalsCount: proposals.length });\n return { sectionProposals: proposals, agentTimings: agentTimingsAccum };\n });\n };\n\n const cacheCategorizerResultsNode = async (state: typeof HomeGraphState.State) => {\n return timed(\"HomeGraph.cacheCategorizerResults\", async () => {\n if (state.categoryCacheHit || state.sectionProposals.length === 0) {\n return {};\n }\n\n try {\n const key = buildCategorizerCacheKey(state.userId, state.cards);\n\n await this.cache.set(key, state.sectionProposals, { ttl: HOME_CACHE_TTL });\n\n logger.verbose('[HomeGraph:cacheCategorizerResults] cached', {\n sectionCount: state.sectionProposals.length,\n });\n } catch (e) {\n logger.warn('[HomeGraph:cacheCategorizerResults] cache write failed, continuing', { error: e });\n }\n\n return {};\n });\n };\n\n const normalizeAndSortNode = async (state: typeof HomeGraphState.State) => {\n return timed(\"HomeGraph.normalizeAndSort\", async () => {\n const cards = state.cards;\n const proposals = state.sectionProposals;\n logger.verbose('[HomeGraph:normalizeAndSort] entry', { cardsLength: cards.length, proposalsLength: proposals.length });\n if (cards.length === 0) {\n logger.verbose('[HomeGraph:normalizeAndSort] exit', { totalOpportunities: 0, totalSections: 0 });\n return { sections: [], meta: { totalOpportunities: 0, totalSections: 0 } };\n }\n const usedIndices = new Set<number>();\n const sections: HomeSection[] = proposals.map((p) => {\n const iconName = resolveHomeSectionIcon(p.iconName);\n const items: HomeSectionItem[] = p.itemIndices\n .filter((i) => i >= 0 && i < cards.length && !usedIndices.has(i))\n .slice(0, MAX_ITEMS_PER_SECTION)\n .map((i) => {\n usedIndices.add(i);\n const card = cards[i];\n const { _cardIndex, ...rest } = card;\n return rest;\n });\n return {\n id: p.id,\n title: p.title,\n subtitle: p.subtitle,\n iconName,\n items,\n };\n });\n\n // Enforce category ordering: sections with connections first, then\n // connector-flow only, then expired only. This prevents the LLM\n // categorizer from placing introducer sections before connection sections.\n const sectionCategoryPriority = (section: HomeSection): number => {\n const hasConnection = section.items.some((item) => item.viewerRole !== 'introducer');\n if (hasConnection) return 0; // mixed or connection-only sections first\n const hasConnectorFlow = section.items.some((item) => item.viewerRole === 'introducer');\n if (hasConnectorFlow) return 1; // connector-flow only sections next\n return 2; // empty or expired sections last\n };\n sections.sort((a, b) => sectionCategoryPriority(a) - sectionCategoryPriority(b));\n const meta = {\n totalOpportunities: state.opportunities.length,\n totalSections: sections.length,\n };\n logger.verbose('[HomeGraph:normalizeAndSort] exit', { totalOpportunities: meta.totalOpportunities, totalSections: meta.totalSections });\n return { sections, meta };\n });\n };\n\n const graph = new StateGraph(HomeGraphState)\n .addNode('loadOpportunities', loadOpportunitiesNode)\n .addNode('checkPresenterCache', checkPresenterCacheNode)\n .addNode('generateCardText', generateCardTextNode)\n .addNode('cachePresenterResults', cachePresenterResultsNode)\n .addNode('checkCategorizerCache', checkCategorizerCacheNode)\n .addNode('categorizeDynamically', categorizeDynamicallyNode)\n .addNode('cacheCategorizerResults', cacheCategorizerResultsNode)\n .addNode('normalizeAndSort', normalizeAndSortNode)\n .addEdge(START, 'loadOpportunities')\n .addEdge('loadOpportunities', 'checkPresenterCache')\n .addConditionalEdges('checkPresenterCache', shouldGenerateCards, {\n generate: 'generateCardText',\n skip: 'cachePresenterResults',\n })\n .addEdge('generateCardText', 'cachePresenterResults')\n .addEdge('cachePresenterResults', 'checkCategorizerCache')\n .addConditionalEdges('checkCategorizerCache', shouldCategorize, {\n categorize: 'categorizeDynamically',\n skip: 'normalizeAndSort',\n })\n .addEdge('categorizeDynamically', 'cacheCategorizerResults')\n .addEdge('cacheCategorizerResults', 'normalizeAndSort')\n .addEdge('normalizeAndSort', END);\n\n return graph.compile();\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"opportunity.introducer.d.ts","sourceRoot":"/","sources":["opportunity/opportunity.introducer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,0DAA0D;AAC1D,eAAO,MAAM,sBAAsB,IAAI,CAAC;AAExC,mDAAmD;AACnD,eAAO,MAAM,0BAA0B,IAAI,CAAC;AAE5C,sEAAsE;AACtE,eAAO,MAAM,2BAA2B,EAAG,sBAA+B,CAAC;AAE3E,oFAAoF;AACpF,MAAM,WAAW,kBAAkB;IACjC,MAAM,EAAE,MAAM,CAAC;IACf,mEAAmE;IACnE,cAAc,EAAE,MAAM,GAAG,IAAI,CAAC;IAC9B,iDAAiD;IACjD,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,0EAA0E;AAC1E,MAAM,WAAW,2BAA2B;IAC1C,wCAAwC;IACxC,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAA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EACd,KAAK,GAAE,MAA+B,GACrC,OAAO,CAAC,kBAAkB,EAAE,CAAC,CAgB/B;AAED;;;;;;;;GAQG;AACH,wBAAgB,4BAA4B,CAC1C,kBAAkB,EAAE,MAAM,EAC1B,mBAAmB,GAAE,MAAU,GAC9B,OAAO,CAET;AAED;;;;;;;;GAQG;AACH,wBAAsB,sBAAsB,CAC1C,QAAQ,EAAE,2BAA2B,EACrC,KAAK,EAAE,wBAAwB,EAC/B,MAAM,EAAE,MAAM,GACb,OAAO,CAAC,yBAAyB,CAAC,CAoDpC"}
@@ -64,7 +64,6 @@ export async function runIntroducerDiscovery(database, queue, userId) {
64
64
  return { contactsEvaluated: 0, jobsEnqueued: 0, skippedReason: 'no_contacts' };
65
65
  }
66
66
  const bucket = Math.floor(Date.now() / (12 * 60 * 60 * 1000)); // 12h dedup bucket
67
- let jobsEnqueued = 0;
68
67
  const results = await Promise.allSettled(contacts.map(async (contact) => {
69
68
  // For each contact, we enqueue a discovery job using one of their intents
70
69
  // The opportunity graph will use onBehalfOfUserId to discover on behalf of the contact
@@ -94,7 +93,7 @@ export async function runIntroducerDiscovery(database, queue, userId) {
94
93
  logger.error(`[IntroducerDiscovery] Job enqueue failed: ${errMsg}`);
95
94
  }
96
95
  }
97
- jobsEnqueued = results.filter((r) => r.status === 'fulfilled' && r.value).length;
96
+ const jobsEnqueued = results.filter((r) => r.status === 'fulfilled' && r.value).length;
98
97
  logger.info(`[IntroducerDiscovery] Discovery cycle complete — userId=${userId} contactsEvaluated=${contacts.length} jobsEnqueued=${jobsEnqueued}`);
99
98
  return { contactsEvaluated: contacts.length, jobsEnqueued };
100
99
  }
@@ -1 +1 @@
1
- {"version":3,"file":"opportunity.introducer.js","sourceRoot":"/","sources":["opportunity/opportunity.introducer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAC;AAE5E,MAAM,MAAM,GAAG,cAAc,CAAC,qBAAqB,CAAC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B,OAAO,CAAC,MAAM,UAAU,OAAO,EAAE,CAAC,CAAC;gBACpI,OAAO,KAAK,CAAC;YACf,CAAC;YACD,MAAM,GAAG,CAAC;QACZ,CAAC;IACH,CAAC,CAAC,CACH,CAAC;IAEF,KAAK,MAAM,CAAC,IAAI,OAAO,EAAE,CAAC;QACxB,IAAI,CAAC,CAAC,MAAM,KAAK,UAAU,EAAE,CAAC;YAC5B,MAAM,MAAM,GAAG,CAAC,CAAC,MAAM,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;YAC/E,MAAM,CAAC,KAAK,CAAC,6CAA6C,MAAM,EAAE,CAAC,CAAC;QACtE,CAAC;IACH,CAAC;IACD,YAAY,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,WAAW,IAAI,CAAC,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC;IAEjF,MAAM,CAAC,IAAI,CAAC,2DAA2D,MAAM,sBAAsB,QAAQ,CAAC,MAAM,iBAAiB,YAAY,EAAE,CAAC,CAAC;IAEnJ,OAAO,EAAE,iBAAiB,EAAE,QAAQ,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC;AAC9D,CAAC","sourcesContent":["/**\n * Introducer Discovery: proactive discovery of connector-flow opportunities\n * between a user's contacts.\n *\n * Selects top-N contacts from the user's personal index and runs scoped\n * HyDE discovery for each, creating latent introducer opportunities that\n * the user (as introducer) must approve before parties see them.\n */\n\nimport { protocolLogger } from '../shared/observability/protocol.logger.js';\n\nconst logger = protocolLogger('IntroducerDiscovery');\n\n/** Maximum contacts to evaluate per maintenance cycle. */\nexport const MAX_CONTACTS_PER_CYCLE = 5;\n\n/** Maximum candidate opportunities per contact. */\nexport const MAX_CANDIDATES_PER_CONTACT = 3;\n\n/** Detection source value for introducer-discovered opportunities. */\nexport const INTRODUCER_DISCOVERY_SOURCE = 'introducer_discovery' as const;\n\n/** A contact with their active intents, used for introducer discovery selection. */\nexport interface ContactWithIntents {\n userId: string;\n /** Most recent intent updatedAt timestamp (ISO string or null). */\n latestIntentAt: string | null;\n /** Number of active intents this contact has. */\n intentCount: number;\n}\n\n/** Database methods needed for introducer discovery contact selection. */\nexport interface IntroducerDiscoveryDatabase {\n /** Get the user's personal index ID. */\n getPersonalIndexId(userId: string): Promise<string | null>;\n /** Get contacts from a personal index with their intent freshness data. */\n getContactsWithIntentFreshness(\n personalIndexId: string,\n ownerId: string,\n limit: number,\n ): Promise<ContactWithIntents[]>;\n}\n\n/** Queue interface for enqueuing introducer discovery jobs. */\nexport interface IntroducerDiscoveryQueue {\n addJob(\n data: { intentId: string; userId: string; indexIds?: string[]; contactUserId?: string },\n options?: { priority?: number; jobId?: string },\n ): Promise<unknown>;\n}\n\n/** Result of a single introducer discovery cycle. */\nexport interface IntroducerDiscoveryResult {\n contactsEvaluated: number;\n jobsEnqueued: number;\n skippedReason?: string;\n}\n\n/**\n * Select top-N contacts for introducer discovery, sorted by intent freshness.\n * Contacts with no active intents are excluded.\n *\n * @param database - Database adapter with contact/intent queries\n * @param userId - The introducer user\n * @param limit - Max contacts to return (default MAX_CONTACTS_PER_CYCLE)\n * @returns Sorted contacts with intent data\n */\nexport async function selectContactsForDiscovery(\n database: IntroducerDiscoveryDatabase,\n userId: string,\n limit: number = MAX_CONTACTS_PER_CYCLE,\n): Promise<ContactWithIntents[]> {\n const personalIndexId = await database.getPersonalIndexId(userId);\n if (!personalIndexId) {\n logger.verbose(`[IntroducerDiscovery] No personal index found — userId=${userId}`);\n return [];\n }\n\n const contacts = await database.getContactsWithIntentFreshness(\n personalIndexId,\n userId,\n limit,\n );\n\n logger.verbose(`[IntroducerDiscovery] Selected contacts for discovery — userId=${userId} totalContacts=${contacts.length} limit=${limit}`);\n\n return contacts;\n}\n\n/**\n * Determine whether introducer discovery should run based on the current\n * connector-flow composition. Triggers when connector-flow count is below\n * the soft target.\n *\n * @param connectorFlowCount - Current number of connector-flow opportunities\n * @param connectorFlowTarget - Soft target (default 2)\n * @returns Whether introducer discovery should run\n */\nexport function shouldRunIntroducerDiscovery(\n connectorFlowCount: number,\n connectorFlowTarget: number = 2,\n): boolean {\n return connectorFlowCount < connectorFlowTarget;\n}\n\n/**\n * Run introducer discovery for a user: select contacts, enqueue discovery jobs.\n * Each job uses onBehalfOfUserId so the opportunity graph treats the user as introducer.\n *\n * @param database - Database adapter for contact queries\n * @param queue - Queue for enqueuing discovery jobs\n * @param userId - The introducer user\n * @returns Summary of the discovery cycle\n */\nexport async function runIntroducerDiscovery(\n database: IntroducerDiscoveryDatabase,\n queue: IntroducerDiscoveryQueue,\n userId: string,\n): Promise<IntroducerDiscoveryResult> {\n const personalIndexId = await database.getPersonalIndexId(userId);\n if (!personalIndexId) {\n return { contactsEvaluated: 0, jobsEnqueued: 0, skippedReason: 'no_personal_index' };\n }\n\n const contacts = await selectContactsForDiscovery(database, userId);\n if (contacts.length === 0) {\n return { contactsEvaluated: 0, jobsEnqueued: 0, skippedReason: 'no_contacts' };\n }\n\n const bucket = Math.floor(Date.now() / (12 * 60 * 60 * 1000)); // 12h dedup bucket\n let jobsEnqueued = 0;\n\n const results = await Promise.allSettled(\n contacts.map(async (contact) => {\n // For each contact, we enqueue a discovery job using one of their intents\n // The opportunity graph will use onBehalfOfUserId to discover on behalf of the contact\n // while the userId (introducer) gets the introducer role\n const jobId = `introducer-discovery-${userId}-${contact.userId}-${bucket}`;\n try {\n await queue.addJob(\n {\n intentId: `introducer:${contact.userId}`,\n userId,\n indexIds: [personalIndexId],\n contactUserId: contact.userId,\n },\n { priority: 15, jobId }, // Lower priority than regular rediscovery (10)\n );\n return true;\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n if (/duplicate|already exists|job.*id/i.test(message)) {\n logger.verbose(`[IntroducerDiscovery] Job skipped (duplicate) — userId=${userId} contactUserId=${contact.userId} error=${message}`);\n return false;\n }\n throw err;\n }\n }),\n );\n\n for (const r of results) {\n if (r.status === 'rejected') {\n const errMsg = r.reason instanceof Error ? r.reason.message : String(r.reason);\n logger.error(`[IntroducerDiscovery] Job enqueue failed: ${errMsg}`);\n }\n }\n jobsEnqueued = results.filter((r) => r.status === 'fulfilled' && r.value).length;\n\n logger.info(`[IntroducerDiscovery] Discovery cycle complete — userId=${userId} contactsEvaluated=${contacts.length} jobsEnqueued=${jobsEnqueued}`);\n\n return { contactsEvaluated: contacts.length, jobsEnqueued };\n}\n"]}
1
+ {"version":3,"file":"opportunity.introducer.js","sourceRoot":"/","sources":["opportunity/opportunity.introducer.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAC;AAE5E,MAAM,MAAM,GAAG,cAAc,CAAC,qBAAqB,CAAC,CAAC;AAErD,0DAA0D;AAC1D,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,CAAC;AAExC,mDAAmD;AACnD,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAC;AAE5C,sEAAsE;AACtE,MAAM,CAAC,MAAM,2BAA2B,GAAG,sBAA+B,CAAC;AAsC3E;;;;;;;;GAQG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,QAAqC,EACrC,MAAc,EACd,QAAgB,sBAAsB;IAEtC,MAAM,eAAe,GAAG,MAAM,QAAQ,CAAC,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAClE,IAAI,CAAC,eAAe,EAAE,CAAC;QACrB,MAAM,CAAC,OAAO,CAAC,0DAA0D,MAAM,EAAE,CAAC,CAAC;QACnF,OAAO,EAAE,CAAC;IACZ,CAAC;IAED,MAAM,QAAQ,GAAG,MAAM,QAAQ,CAAC,8BAA8B,CAC5D,eAAe,EACf,MAAM,EACN,KAAK,CACN,CAAC;IAEF,MAAM,CAAC,OAAO,CAAC,kEAAkE,MAAM,kBAAkB,QAAQ,CAAC,M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AM,iBAAiB,YAAY,EAAE,CAAC,CAAC;IAEnJ,OAAO,EAAE,iBAAiB,EAAE,QAAQ,CAAC,MAAM,EAAE,YAAY,EAAE,CAAC;AAC9D,CAAC","sourcesContent":["/**\n * Introducer Discovery: proactive discovery of connector-flow opportunities\n * between a user's contacts.\n *\n * Selects top-N contacts from the user's personal index and runs scoped\n * HyDE discovery for each, creating latent introducer opportunities that\n * the user (as introducer) must approve before parties see them.\n */\n\nimport { protocolLogger } from '../shared/observability/protocol.logger.js';\n\nconst logger = protocolLogger('IntroducerDiscovery');\n\n/** Maximum contacts to evaluate per maintenance cycle. */\nexport const MAX_CONTACTS_PER_CYCLE = 5;\n\n/** Maximum candidate opportunities per contact. */\nexport const MAX_CANDIDATES_PER_CONTACT = 3;\n\n/** Detection source value for introducer-discovered opportunities. */\nexport const INTRODUCER_DISCOVERY_SOURCE = 'introducer_discovery' as const;\n\n/** A contact with their active intents, used for introducer discovery selection. */\nexport interface ContactWithIntents {\n userId: string;\n /** Most recent intent updatedAt timestamp (ISO string or null). */\n latestIntentAt: string | null;\n /** Number of active intents this contact has. */\n intentCount: number;\n}\n\n/** Database methods needed for introducer discovery contact selection. */\nexport interface IntroducerDiscoveryDatabase {\n /** Get the user's personal index ID. */\n getPersonalIndexId(userId: string): Promise<string | null>;\n /** Get contacts from a personal index with their intent freshness data. */\n getContactsWithIntentFreshness(\n personalIndexId: string,\n ownerId: string,\n limit: number,\n ): Promise<ContactWithIntents[]>;\n}\n\n/** Queue interface for enqueuing introducer discovery jobs. */\nexport interface IntroducerDiscoveryQueue {\n addJob(\n data: { intentId: string; userId: string; indexIds?: string[]; contactUserId?: string },\n options?: { priority?: number; jobId?: string },\n ): Promise<unknown>;\n}\n\n/** Result of a single introducer discovery cycle. */\nexport interface IntroducerDiscoveryResult {\n contactsEvaluated: number;\n jobsEnqueued: number;\n skippedReason?: string;\n}\n\n/**\n * Select top-N contacts for introducer discovery, sorted by intent freshness.\n * Contacts with no active intents are excluded.\n *\n * @param database - Database adapter with contact/intent queries\n * @param userId - The introducer user\n * @param limit - Max contacts to return (default MAX_CONTACTS_PER_CYCLE)\n * @returns Sorted contacts with intent data\n */\nexport async function selectContactsForDiscovery(\n database: IntroducerDiscoveryDatabase,\n userId: string,\n limit: number = MAX_CONTACTS_PER_CYCLE,\n): Promise<ContactWithIntents[]> {\n const personalIndexId = await database.getPersonalIndexId(userId);\n if (!personalIndexId) {\n logger.verbose(`[IntroducerDiscovery] No personal index found — userId=${userId}`);\n return [];\n }\n\n const contacts = await database.getContactsWithIntentFreshness(\n personalIndexId,\n userId,\n limit,\n );\n\n logger.verbose(`[IntroducerDiscovery] Selected contacts for discovery — userId=${userId} totalContacts=${contacts.length} limit=${limit}`);\n\n return contacts;\n}\n\n/**\n * Determine whether introducer discovery should run based on the current\n * connector-flow composition. Triggers when connector-flow count is below\n * the soft target.\n *\n * @param connectorFlowCount - Current number of connector-flow opportunities\n * @param connectorFlowTarget - Soft target (default 2)\n * @returns Whether introducer discovery should run\n */\nexport function shouldRunIntroducerDiscovery(\n connectorFlowCount: number,\n connectorFlowTarget: number = 2,\n): boolean {\n return connectorFlowCount < connectorFlowTarget;\n}\n\n/**\n * Run introducer discovery for a user: select contacts, enqueue discovery jobs.\n * Each job uses onBehalfOfUserId so the opportunity graph treats the user as introducer.\n *\n * @param database - Database adapter for contact queries\n * @param queue - Queue for enqueuing discovery jobs\n * @param userId - The introducer user\n * @returns Summary of the discovery cycle\n */\nexport async function runIntroducerDiscovery(\n database: IntroducerDiscoveryDatabase,\n queue: IntroducerDiscoveryQueue,\n userId: string,\n): Promise<IntroducerDiscoveryResult> {\n const personalIndexId = await database.getPersonalIndexId(userId);\n if (!personalIndexId) {\n return { contactsEvaluated: 0, jobsEnqueued: 0, skippedReason: 'no_personal_index' };\n }\n\n const contacts = await selectContactsForDiscovery(database, userId);\n if (contacts.length === 0) {\n return { contactsEvaluated: 0, jobsEnqueued: 0, skippedReason: 'no_contacts' };\n }\n\n const bucket = Math.floor(Date.now() / (12 * 60 * 60 * 1000)); // 12h dedup bucket\n\n const results = await Promise.allSettled(\n contacts.map(async (contact) => {\n // For each contact, we enqueue a discovery job using one of their intents\n // The opportunity graph will use onBehalfOfUserId to discover on behalf of the contact\n // while the userId (introducer) gets the introducer role\n const jobId = `introducer-discovery-${userId}-${contact.userId}-${bucket}`;\n try {\n await queue.addJob(\n {\n intentId: `introducer:${contact.userId}`,\n userId,\n indexIds: [personalIndexId],\n contactUserId: contact.userId,\n },\n { priority: 15, jobId }, // Lower priority than regular rediscovery (10)\n );\n return true;\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err);\n if (/duplicate|already exists|job.*id/i.test(message)) {\n logger.verbose(`[IntroducerDiscovery] Job skipped (duplicate) — userId=${userId} contactUserId=${contact.userId} error=${message}`);\n return false;\n }\n throw err;\n }\n }),\n );\n\n for (const r of results) {\n if (r.status === 'rejected') {\n const errMsg = r.reason instanceof Error ? r.reason.message : String(r.reason);\n logger.error(`[IntroducerDiscovery] Job enqueue failed: ${errMsg}`);\n }\n }\n const jobsEnqueued = results.filter((r) => r.status === 'fulfilled' && r.value).length;\n\n logger.info(`[IntroducerDiscovery] Discovery cycle complete — userId=${userId} contactsEvaluated=${contacts.length} jobsEnqueued=${jobsEnqueued}`);\n\n return { contactsEvaluated: contacts.length, jobsEnqueued };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"opportunity.tools.d.ts","sourceRoot":"/","sources":["opportunity/opportunity.tools.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AA6B5E,OAAO,KAAK,EAAE,WAAW,EAAqB,MAAM,4CAA4C,CAAC;AAEjG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gDAAgD,CAAC;AAOtF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE;IAC/C,MAAM,EAAE,MAAM,CAAC;IAC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C;AAEF;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,4BAA4B,CAC1C,KAAK,EAAE,mBAAmB,EAAE,EAC5B,IAAI,EAAE;IACJ,KAAK,EAAE,OAAO,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,CAAC,EAAE,aAAa,GAAG,eAAe,CAAC;IACxC,8FAA8F;IAC9F,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC,GACA,MAAM,CA0DR;AAuDD;;;;;;;;;GASG;AACH,MAAM,MAAM,wBAAwB,GAChC,iBAAiB,GACjB,oBAAoB,GACpB,wBAAwB,GACxB,uBAAuB,GACvB,gBAAgB,GAChB,gBAAgB,CAAC;AAUrB,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,2CAktD5E"}
@@ -743,14 +743,15 @@ export function createOpportunityTools(defineTool, deps) {
743
743
  const viewerRole = viewerIsParty ? "party" : "introducer";
744
744
  const isCounterpartGhost = counterpartUser?.isGhost ?? false;
745
745
  const primaryActionLabel = getPrimaryActionLabel(viewerRole);
746
+ const narratorText = narratorRemarkFromReasoning(reasoning, counterpartName, introducerUser?.name ?? undefined);
746
747
  const narratorChip = viewerIsParty
747
748
  ? {
748
749
  name: "Index",
749
- text: narratorRemarkFromReasoning(reasoning, counterpartName, introducerUser?.name ?? undefined),
750
+ text: narratorText,
750
751
  }
751
752
  : {
752
753
  name: "You",
753
- text: narratorRemarkFromReasoning(reasoning, counterpartName, introducerUser?.name ?? undefined),
754
+ text: narratorText,
754
755
  userId: context.userId,
755
756
  };
756
757
  const headline = !viewerIsParty && secondPartyName