@indexnetwork/protocol 3.13.0-rc.288.1 → 4.0.0-rc.289.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 (92) hide show
  1. package/dist/chat/chat.prompt.js +5 -5
  2. package/dist/chat/chat.prompt.js.map +1 -1
  3. package/dist/chat/tests/chat.graph.mocks.d.ts +1 -7
  4. package/dist/chat/tests/chat.graph.mocks.d.ts.map +1 -1
  5. package/dist/chat/tests/chat.graph.mocks.js +1 -2
  6. package/dist/chat/tests/chat.graph.mocks.js.map +1 -1
  7. package/dist/{profile/profile.enricher.d.ts → enrichment/enrichment.enricher.d.ts} +1 -1
  8. package/dist/enrichment/enrichment.enricher.d.ts.map +1 -0
  9. package/dist/{profile/profile.enricher.js → enrichment/enrichment.enricher.js} +1 -1
  10. package/dist/enrichment/enrichment.enricher.js.map +1 -0
  11. package/dist/{profile/profile.generator.d.ts → enrichment/enrichment.generator.d.ts} +3 -3
  12. package/dist/enrichment/enrichment.generator.d.ts.map +1 -0
  13. package/dist/{profile/profile.generator.js → enrichment/enrichment.generator.js} +6 -6
  14. package/dist/enrichment/enrichment.generator.js.map +1 -0
  15. package/dist/{profile/profile.graph.d.ts → enrichment/enrichment.graph.d.ts} +61 -201
  16. package/dist/enrichment/enrichment.graph.d.ts.map +1 -0
  17. package/dist/{profile/profile.graph.js → enrichment/enrichment.graph.js} +6 -6
  18. package/dist/enrichment/enrichment.graph.js.map +1 -0
  19. package/dist/{profile/profile.state.d.ts → enrichment/enrichment.state.d.ts} +8 -32
  20. package/dist/enrichment/enrichment.state.d.ts.map +1 -0
  21. package/dist/{profile/profile.state.js → enrichment/enrichment.state.js} +2 -2
  22. package/dist/enrichment/enrichment.state.js.map +1 -0
  23. package/dist/enrichment/enrichment.tools.d.ts +3 -0
  24. package/dist/enrichment/enrichment.tools.d.ts.map +1 -0
  25. package/dist/{profile/profile.tools.js → enrichment/enrichment.tools.js} +74 -87
  26. package/dist/enrichment/enrichment.tools.js.map +1 -0
  27. package/dist/index.d.ts +4 -4
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.js +3 -3
  30. package/dist/index.js.map +1 -1
  31. package/dist/intent/intent.tools.js +3 -3
  32. package/dist/intent/intent.tools.js.map +1 -1
  33. package/dist/opportunity/opportunity.graph.d.ts +1 -7
  34. package/dist/opportunity/opportunity.graph.d.ts.map +1 -1
  35. package/dist/opportunity/opportunity.graph.js +5 -22
  36. package/dist/opportunity/opportunity.graph.js.map +1 -1
  37. package/dist/opportunity/opportunity.presenter.d.ts.map +1 -1
  38. package/dist/opportunity/opportunity.presenter.js +3 -11
  39. package/dist/opportunity/opportunity.presenter.js.map +1 -1
  40. package/dist/opportunity/opportunity.state.d.ts +2 -8
  41. package/dist/opportunity/opportunity.state.d.ts.map +1 -1
  42. package/dist/opportunity/opportunity.state.js.map +1 -1
  43. package/dist/questioner/questioner.presets.js +1 -1
  44. package/dist/questioner/questioner.presets.js.map +1 -1
  45. package/dist/questioner/questioner.tools.d.ts +1 -1
  46. package/dist/questioner/questioner.tools.js +2 -2
  47. package/dist/questioner/questioner.tools.js.map +1 -1
  48. package/dist/shared/agent/tool.factory.js +6 -6
  49. package/dist/shared/agent/tool.factory.js.map +1 -1
  50. package/dist/shared/agent/tool.helpers.d.ts +8 -8
  51. package/dist/shared/agent/tool.helpers.d.ts.map +1 -1
  52. package/dist/shared/agent/tool.helpers.js.map +1 -1
  53. package/dist/shared/agent/tool.registry.js +2 -2
  54. package/dist/shared/agent/tool.registry.js.map +1 -1
  55. package/dist/shared/hyde/hyde.graph.d.ts +6 -6
  56. package/dist/shared/hyde/hyde.state.d.ts +2 -2
  57. package/dist/shared/hyde/hyde.state.js.map +1 -1
  58. package/dist/shared/interfaces/database.interface.d.ts +14 -14
  59. package/dist/shared/interfaces/database.interface.d.ts.map +1 -1
  60. package/dist/shared/interfaces/database.interface.js.map +1 -1
  61. package/dist/shared/interfaces/{profile-run.interface.d.ts → enrichment-run.interface.d.ts} +21 -21
  62. package/dist/shared/interfaces/enrichment-run.interface.d.ts.map +1 -0
  63. package/dist/shared/interfaces/enrichment-run.interface.js +2 -0
  64. package/dist/shared/interfaces/enrichment-run.interface.js.map +1 -0
  65. package/dist/shared/schemas/discovery-question.schema.d.ts +2 -2
  66. package/dist/shared/schemas/identity.schema.d.ts +45 -0
  67. package/dist/shared/schemas/identity.schema.d.ts.map +1 -0
  68. package/dist/shared/schemas/identity.schema.js +20 -0
  69. package/dist/shared/schemas/identity.schema.js.map +1 -0
  70. package/dist/shared/schemas/question.schema.d.ts +4 -4
  71. package/dist/shared/schemas/question.schema.d.ts.map +1 -1
  72. package/dist/shared/schemas/question.schema.js +1 -1
  73. package/dist/shared/schemas/question.schema.js.map +1 -1
  74. package/package.json +1 -1
  75. package/dist/profile/profile.enricher.d.ts.map +0 -1
  76. package/dist/profile/profile.enricher.js.map +0 -1
  77. package/dist/profile/profile.generator.d.ts.map +0 -1
  78. package/dist/profile/profile.generator.js.map +0 -1
  79. package/dist/profile/profile.graph.d.ts.map +0 -1
  80. package/dist/profile/profile.graph.js.map +0 -1
  81. package/dist/profile/profile.state.d.ts.map +0 -1
  82. package/dist/profile/profile.state.js.map +0 -1
  83. package/dist/profile/profile.tools.d.ts +0 -3
  84. package/dist/profile/profile.tools.d.ts.map +0 -1
  85. package/dist/profile/profile.tools.js.map +0 -1
  86. package/dist/shared/interfaces/profile-run.interface.d.ts.map +0 -1
  87. package/dist/shared/interfaces/profile-run.interface.js +0 -2
  88. package/dist/shared/interfaces/profile-run.interface.js.map +0 -1
  89. package/dist/shared/schemas/profile.schema.d.ts +0 -100
  90. package/dist/shared/schemas/profile.schema.d.ts.map +0 -1
  91. package/dist/shared/schemas/profile.schema.js +0 -26
  92. package/dist/shared/schemas/profile.schema.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"opportunity.presenter.d.ts","sourceRoot":"/","sources":["opportunity/opportunity.presenter.ts"],"names":[],"mappings":"AAAA;;;;;;;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AC,EAAE,OAAO,CAAC;IACzB,mEAAmE;IACnE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAmID,qBAAa,oBAAoB;IAC/B,OAAO,CAAC,KAAK,CAAW;IACxB,OAAO,CAAC,aAAa,CAAW;;YAWlB,iBAAiB;IA4B/B;;OAEG;IAEU,OAAO,CAClB,KAAK,EAAE,cAAc,GACpB,OAAO,CAAC,6BAA6B,CAAC;IAsDzC;;;;;;;OAOG;IAEU,eAAe,CAC1B,KAAK,EAAE,sBAAsB,GAC5B,OAAO,CAAC,iBAAiB,CAAC;IAwG7B;;OAEG;IAEU,YAAY,CACvB,MAAM,EAAE,cAAc,EAAE,EACxB,OAAO,CAAC,EAAE;QAAE,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,GACjC,OAAO,CAAC,6BAA6B,EAAE,CAAC;IAa3C;;;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,CAkOzB"}
@@ -591,9 +591,7 @@ export async function gatherPresenterContext(database, opportunity, viewerId, di
591
591
  const name = profile?.identity?.name ?? "Unknown";
592
592
  const bio = profile?.identity?.bio ?? "";
593
593
  const location = profile?.identity?.location ?? "";
594
- const skills = profile?.attributes?.skills?.join(", ") ?? "";
595
- const interests = profile?.attributes?.interests?.join(", ") ?? "";
596
- const context = profile?.narrative?.context ?? "";
594
+ const context = profile?.context ?? "";
597
595
  const intents = partyIntentsMap?.get(uid);
598
596
  const intentLines = intents?.length
599
597
  ? intents
@@ -604,8 +602,6 @@ export async function gatherPresenterContext(database, opportunity, viewerId, di
604
602
  `${name}:`,
605
603
  ` Bio: ${bio}`,
606
604
  location ? ` Location: ${location}` : null,
607
- skills ? ` Skills: ${skills}` : null,
608
- interests ? ` Interests: ${interests}` : null,
609
605
  context ? ` Context: ${context}` : null,
610
606
  ` Active intents:`,
611
607
  ...intentLines,
@@ -623,9 +619,7 @@ export async function gatherPresenterContext(database, opportunity, viewerId, di
623
619
  `Name: ${viewerProfile?.identity?.name ?? "Unknown"}`,
624
620
  `Bio: ${viewerProfile?.identity?.bio ?? ""}`,
625
621
  `Location: ${viewerProfile?.identity?.location ?? ""}`,
626
- `Skills: ${viewerProfile?.attributes?.skills?.join(", ") ?? ""}`,
627
- `Interests: ${viewerProfile?.attributes?.interests?.join(", ") ?? ""}`,
628
- `Context: ${viewerProfile?.narrative?.context ?? ""}`,
622
+ `Context: ${viewerProfile?.context ?? ""}`,
629
623
  "Active intents:",
630
624
  ...(viewerIntents?.length
631
625
  ? viewerIntents.map((i) => `- ${i.payload}${i.summary ? ` (${i.summary})` : ""}`)
@@ -636,9 +630,7 @@ export async function gatherPresenterContext(database, opportunity, viewerId, di
636
630
  const profile = otherProfiles[idx];
637
631
  const name = profile?.identity?.name ?? "Unknown";
638
632
  const bio = profile?.identity?.bio ?? "";
639
- const skills = profile?.attributes?.skills?.join(", ") ?? "";
640
- const interests = profile?.attributes?.interests?.join(", ") ?? "";
641
- return `${name}: ${bio}. Skills: ${skills}. Interests: ${interests}`;
633
+ return `${name}: ${bio}`;
642
634
  });
643
635
  otherPartyContext =
644
636
  otherParts.join("\n\n") || "Other party (details not available).";
@@ -1 +1 @@
1
- {"version":3,"file":"opportunity.presenter.js","sourceRoot":"/","sources":["opportunity/opportunity.presenter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;;;;;;;;;;AAGH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK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,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE;QAChF,CAAC,CAAC,SAAS,CAAC;IAChB,MAAM,mBAAmB,GAAG,aAAa,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAClE,MAAM,cAAc,GAClB,eAAe,IAAI,MAAM,CAAC,SAAS;QACjC,CAAC,CAAC,wBAAwB,CACtB,MAAM,CAAC,SAAS,EAChB,eAAe,EACf,GAAG,EACH,mBAAmB,EACnB,cAAc,CACf;QACH,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAEnC,IAAI,oBAAoB,EAAE,CAAC;QACzB,aAAa,IAAI,oBAAoB,CAAC;IACxC,CAAC;IACD,IAAI,mBAAmB,EAAE,CAAC;QACxB,iBAAiB,IAAI,mBAAmB,CAAC;IAC3C,CAAC;IAED,MAAM,MAAM,GAAmB;QAC7B,aAAa;QACb,iBAAiB;QACjB,cAAc;QACd,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,YAAY;QACzC,UAAU,EACR,OAAO,MAAM,CAAC,UAAU,KAAK,QAAQ;YACnC,CAAC,CAAC,MAAM,CAAC,UAAU;YACnB,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;QACrD,cAAc;QACd,SAAS,EAAE,WAAW,EAAE,KAAK,IAAI,cAAc,IAAI,EAAE;QACrD,UAAU,EAAE,OAAO,CAAC,IAAI,IAAI,OAAO;QACnC,cAAc;QACd,cAAc;KACf,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/**\n * Opportunity Presenter Agent\n *\n * Generates personalized, second-person explanations of why an opportunity\n * matters to the viewing user. Uses full opportunity data (interpretation,\n * actors, profiles, intents, index) to produce headline, personalizedSummary,\n * and suggestedAction for chat tools and user-facing surfaces.\n */\n\nimport type { Runnable } from \"@langchain/core/runnables\";\nimport { HumanMessage, SystemMessage } from \"@langchain/core/messages\";\nimport { z } from \"zod\";\n\nimport { Timed } from \"../shared/observability/performance.js\";\n\nimport { protocolLogger } from \"../shared/observability/protocol.logger.js\";\nimport { createModel } from \"../shared/agent/model.config.js\";\nimport { viewerCentricCardSummary } from \"./opportunity.presentation.js\";\nimport type { Opportunity } from \"../shared/interfaces/database.interface.js\";\nimport type { ChatGraphCompositeDatabase } from \"../shared/interfaces/database.interface.js\";\nimport type { NegotiationContext } from \"./negotiation-context.loader.js\";\nimport { stripUuids, stripIntroducerMentions, truncateAtBoundary } from \"./opportunity.presentation.js\";\n\n/**\n * Minimal database interface required by gatherPresenterContext.\n * Any database adapter that implements these three methods can be passed.\n */\nexport type PresenterDatabase = Pick<\n ChatGraphCompositeDatabase,\n \"getProfile\" | \"getActiveIntents\" | \"getNetwork\" | \"getPremisesForUser\"\n>;\n\nconst logger = protocolLogger(\"OpportunityPresenter\");\nconst LLM_TIMEOUT_MS = 20_000;\n\nconst model = createModel(\"opportunityPresenter\");\n\nconst GREETING_DESCRIPTION =\n \"A 2-4 sentence first-person message the viewer could send to the counterpart, in the viewer's voice, referencing what they have in common. Plain prose only — no markdown, no greeting prefix like 'Hey {Name},'. Example body: 'Saw we're both working on regenerative coordination tooling — your post on consent flows resonated. Would love to compare notes if you have time this week.'\";\n\n// ──────────────────────────────────────────────────────────────\n// SCHEMA & TYPES\n// ──────────────────────────────────────────────────────────────\n\nconst PresentationSchema = z.object({\n headline: z\n .string()\n .describe(\n \"Short, compelling headline for this opportunity (e.g., 'A React expert who needs your design skills')\",\n ),\n personalizedSummary: z\n .string()\n .describe(\n \"2-3 sentence explanation using 'you' language, explaining why this opportunity is specifically valuable for the viewer based on their intents and profile\",\n ),\n suggestedAction: z.string().describe(\"Brief suggested next step\"),\n greeting: z.string().max(500).describe(GREETING_DESCRIPTION),\n});\n\nconst responseFormat = z.object({\n presentation: PresentationSchema,\n});\n\nexport type OpportunityPresentationResult = z.infer<typeof PresentationSchema>;\n\n/** Input for home-card presenter call; extends PresenterInput with optional mutual intent count. */\nexport interface HomeCardPresenterInput extends PresenterInput {\n /** Number of overlapping intents (for generating mutualIntentsLabel). */\n mutualIntentCount?: number;\n /**\n * Snapshot of the opportunity's negotiation, if one exists. When status is\n * `negotiating`, the presenter returns a templated chip without invoking\n * the LLM. For `pending`/`stalled`/`accepted`/`rejected`, the full\n * transcript and outcome ground the LLM's explanation.\n */\n negotiationContext?: NegotiationContext;\n}\n\n/** LLM-generated fields for home-card presentation (buttons are hardcoded by callers, not LLM-generated). */\nexport const HomeCardLLMSchema = z.object({\n headline: z\n .string()\n .describe(\"Short, compelling headline for this opportunity\"),\n personalizedSummary: z\n .string()\n .describe(\n \"2-3 sentence explanation in 'you' language for the main card body\",\n ),\n digestSummary: z\n .string()\n .max(220)\n .describe(\n \"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.\",\n ),\n suggestedAction: z\n .string()\n .describe(\"Brief suggested next step (e.g. CTA line)\"),\n narratorRemark: z\n .string()\n .max(80)\n .describe(\n \"One short sentence for the narrator chip, max ~80 chars (e.g. who is suggesting and why)\",\n ),\n mutualIntentsLabel: z\n .string()\n .max(48)\n .describe(\n \"Short line for the subtitle under the other party name (e.g. '3 mutual intents', 'Shared interests', 'Aligned goals'). NEVER output '0 mutual intents' — use a qualitative phrase like 'Shared interests' when no numeric count is available.\",\n ),\n greeting: z.string().max(500).describe(GREETING_DESCRIPTION),\n});\n\n/** LLM-generated result from presentHomeCard (callers append button labels from opportunity.constants). */\nexport type HomeCardLLMResult = z.infer<typeof HomeCardLLMSchema>;\n\n/** Full home-card display contract including hardcoded button labels (assembled by callers). */\nexport type HomeCardPresentationResult = HomeCardLLMResult & {\n primaryActionLabel: string;\n secondaryActionLabel: string;\n};\n\nconst homeCardResponseFormat = z.object({\n presentation: HomeCardLLMSchema,\n});\n\n/** Input for a single presenter call (all context pre-assembled). */\nexport interface PresenterInput {\n viewerContext: string;\n otherPartyContext: string;\n matchReasoning: string;\n category: string;\n confidence: number;\n signalsSummary: string;\n indexName: string;\n viewerRole: string;\n opportunityStatus?: string;\n /** True when this opportunity was created via an explicit introduction (not automatic discovery). */\n isIntroduction?: boolean;\n /** Name of the person who made the introduction, if applicable. */\n introducerName?: string;\n}\n\n// ──────────────────────────────────────────────────────────────\n// SYSTEM PROMPT\n// ──────────────────────────────────────────────────────────────\n\nconst systemPrompt = `\nYou are an expert at presenting connection opportunities to users in a way that feels personal and compelling.\n\nYour goal: Given raw context about the viewer (their profile, intents), the other person(s), and why the system matched them, produce a short headline, a personalized summary, and a suggested action.\n\nRules:\n1. Address the VIEWER directly using \"you\" and \"your\". This is for them.\n2. Be concise and compelling — not analytical or third-party. No \"The source user\" or \"The candidate\"; use names or \"they\" where needed.\n3. Do not leak private or confidential details. Use only the context provided.\n4. Vary user-facing nouns naturally. Do not repeatedly use the same label in one response.\n5. If possible, avoid repeating \"opportunity\" in both headline and summary. Prefer alternatives like \"connection\", \"thought partner\", \"mutual fit\", \"valuable conversation\", or \"peer\".\n6. Prefer first names in user-facing copy. Do not repeatedly use full names unless needed to disambiguate.\n\n**Introduction-originated opportunities:**\nWhen INTRODUCTION CONTEXT is provided, this opportunity was explicitly created by an introducer (a real person who saw value in this connection). This is NOT an automatic system discovery — someone made a deliberate judgment.\n- For ALL roles: acknowledge the introducer's role naturally. E.g., \"[Introducer name] thinks you should meet [other person]\" or \"[Introducer name] connected you because...\"\n- The introduction itself is a strong signal — treat it with the weight of a personal recommendation.\n- If the parties' intents don't obviously overlap, that's fine — the introducer saw something worth connecting. Focus on what the introducer likely saw.\n\n**Role-Specific Presentation:**\n\n**If viewer is \"introducer\":**\n- The viewer suggested this connection between two (or more) OTHER people. The opportunity is NOT about the viewer's own needs.\n- Headline: describe the connection between the parties (e.g., \"Connecting a React expert with a startup founder\").\n- Personalized summary: explain why the people YOU are introducing should meet. Reference THEIR profiles and intents, not yours. Frame it as \"you're connecting X and Y because...\" rather than \"this matches your intent\".\n- Suggested action: guide sharing (e.g., \"Share this with [name] to get things started\").\n- CRITICAL: Do NOT reference the introducer's own intents, skills, or needs. The introducer is the matchmaker, not a party.\n\n**If viewer is \"patient\" or \"party\":**\n- Reference their specific intents, skills, or interests that align with this opportunity.\n- If this is an introduction: mention who introduced them and frame it as a personal recommendation.\n- Headline: one short line that hooks (e.g., \"[Name] thinks you should meet [Other]\" or \"A React expert who needs your design skills\").\n- Personalized summary: 2-3 sentences. Why is this opportunity for *them*? If introduced, lead with the introduction.\n- Suggested action: encourage action (\"Send a message to start the conversation\" or \"Share this intro\").\n\n**If viewer is \"agent\":**\n- They are seeing this because someone already reached out.\n- If this is an introduction: mention who made the introduction.\n- Reference their skills/expertise that make them a match.\n- Headline: what the other person needs that they can provide.\n- Personalized summary: 2-3 sentences. Why someone reached out to them.\n- Suggested action: \"Someone is interested in connecting — check their message\" or \"Review and respond\".\n\n**If viewer is \"peer\":**\n- Mutual opportunity. Reference shared or complementary interests.\n- If this is an introduction: mention who connected them.\n- Headline: the mutual connection angle.\n- Personalized summary: 2-3 sentences. Why this is mutually valuable.\n- Suggested action: \"Send an intro to connect\" or \"Start a conversation\".\n`;\n\nconst homeCardSystemPrompt = `\nYou are an expert at presenting connection opportunities for a home feed card.\n\nGiven context about the viewer, the other person, and why they were matched, produce:\n1. headline: one short hook line.\n2. personalizedSummary: 2-3 sentences in \"you\" language (main body text).\n3. digestSummary: one polished morning-brief sentence that can be printed directly after the person's linked name. No markdown, no field labels.\n4. suggestedAction: one brief suggested next step.\n5. narratorRemark: one short sentence for the narrator chip (who is suggesting and why; max ~80 chars).\n6. greeting: a 2-4 sentence first-person message the viewer could send to the counterpart. Plain prose, no greeting prefix, no markdown.\n7. 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.\n\nRules:\n- Address the viewer with \"you\"/\"your\". Be concise and compelling.\n- narratorRemark should feel like a single sentence from the narrator (Index or a person), not meta-commentary.\n- 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\").\n- Vary wording for the match itself. Do not repeat \"opportunity\" across headline, summary, and narratorRemark when alternatives fit.\n- Prefer first names in user-facing copy. Avoid repeated full names unless disambiguation is necessary.\n- 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.\n- digestSummary must NOT use awkward third-person fragments like \"Name is...\", \"they're ..., and is...\", \"you is...\", or \"the discoverer's query\".\n- digestSummary must be one sentence, MUST fit within 180 characters when possible, and MUST contain no markdown links; the caller will attach links.\n- If you cannot fit every detail, choose one clear reason and stop. Do not rely on downstream truncation.\n\n**Introduction-originated opportunities (ONLY when INTRODUCTION CONTEXT is provided):**\nWhen INTRODUCTION CONTEXT is provided, this opportunity was explicitly created by an introducer. It was NOT automatically discovered.\n- For parties/patients/agents/peers viewing an introduction: keep the introducer signal in narratorRemark (and narrator chip), not in personalizedSummary.\n- For these introduced parties, personalizedSummary must focus ONLY on fit/value between viewer and counterpart. Do NOT mention the introducer there.\n- narratorRemark should carry the introduction signal (e.g., \"saw strong alignment between you two\" or \"thought this connection could be valuable\"), without repeating the narrator name at the start.\n- This is a personal recommendation, not an algorithm match. Frame it accordingly.\n\n**CRITICAL: NEVER include introducer names in personalizedSummary. Examples:**\n❌ WRONG: \"Seref introduced you to Lucy, who is actively seeking a product co-founder...\"\n✅ CORRECT: \"Lucy is actively seeking a product co-founder for a niche APAC marketplace. With your expertise in UX and AI, this could be an ideal collaboration.\"\n\n❌ WRONG: \"Bob thinks you should meet Alice because your React skills align with her needs.\"\n✅ CORRECT: \"Alice is building a React-based platform and needs frontend expertise. Your experience with component architecture makes you a strong fit.\"\n\n❌ WRONG: \"Jane connected you to Mark, who is looking for a designer.\"\n✅ CORRECT: \"Mark is building a consumer app and needs design expertise. Your background in user-centered design aligns well with what he's building.\"\n\nRemember: The introducer's name goes ONLY in narratorRemark, NEVER in personalizedSummary.\n\n**When INTRODUCTION CONTEXT is NOT provided (system-discovered match):**\n- Do NOT use introducer-style wording. Do NOT say \"you suggested\", \"this is an introduction you suggested\", or \"you suggested this connection\". The system found this match; no human introducer was involved.\n- Instead, narratorRemark should describe why the match is relevant (e.g. \"Based on your overlapping intents\", \"Your skills align with what they need\").\n\n**Negotiation-grounded explanations (ONLY when NEGOTIATION CONTEXT is provided):**\nWhen NEGOTIATION CONTEXT is provided, this opportunity passed through an agent-to-agent negotiation. Use the transcript to ground your explanation in the concrete reasoning the agents exchanged.\n- Personalize the summary with *why* the negotiation produced this match — reference the roles the agents agreed on, the specific concerns raised, and how they were resolved.\n- For status \"stalled\" with reason \"turn_cap\": the agents hit the turn limit without reaching agreement. Frame the card as a hedged possibility rather than a confident match; narratorRemark should signal \"agents couldn't fully converge\" without sounding negative.\n- For status \"stalled\" with reason \"timeout\": one side went silent. Suggest the user re-engage if interested.\n- For status \"accepted\": the agents agreed; the card should confidently explain *why* they agreed.\n- For status \"rejected\": the agents declined. The card should explain the reason briefly so the user understands — not dwell on it.\n- Do NOT invent turn content. Only reference what is in the NEGOTIATION CONTEXT block.\n\n- Exception for connector/introducer: if viewer role is \"introducer\" (any status), this is a curation/connector card. Use:\n - suggestedAction: one short line about sharing the intro or confirming the match.\n - mutualIntentsLabel: a short connector label (e.g. \"Connector match\", \"You can bridge this\").\n - headline: describe the connection between the parties (e.g., \"Connecting a PhD researcher with a translator\"). Do NOT reference the introducer's own needs.\n - personalizedSummary: explain why the parties you're introducing should meet, referencing THEIR profiles and intents, not yours.\n\n**CRITICAL for latent introducer cards (opportunity status is \"latent\"):**\nWhen the viewer is the introducer and the opportunity status is \"latent\", the introducer has NOT yet approved this match. They are evaluating whether to make the introduction.\n- narratorRemark MUST use evaluation/curation language (e.g. \"Could be a strong match\", \"Worth introducing?\", \"Interesting overlap here\").\n- Do NOT say \"you suggested\", \"you introduced\", \"you connected\", or any past-tense language implying the introduction was already made.\n- suggestedAction should encourage evaluation (e.g. \"Approve if you see the fit\").\n- Exception for new-connection reveal: if viewer role is \"agent\", status is \"accepted\", and there is an introducer, this is the agent's first time seeing this opportunity. Use:\n - suggestedAction: a short line about joining the conversation.\n`;\n\n// ──────────────────────────────────────────────────────────────\n// CLASS\n// ──────────────────────────────────────────────────────────────\n\nexport class OpportunityPresenter {\n private model: Runnable;\n private homeCardModel: Runnable;\n\n constructor() {\n this.model = model.withStructuredOutput(responseFormat, {\n name: \"opportunity_presenter\",\n });\n this.homeCardModel = model.withStructuredOutput(homeCardResponseFormat, {\n name: \"opportunity_presenter_home_card\",\n });\n }\n\n private async invokeWithTimeout(\n targetModel: Runnable,\n messages: (SystemMessage | HumanMessage)[],\n ): Promise<unknown> {\n const timeoutReason = `LLM invoke timed out after ${LLM_TIMEOUT_MS}ms`;\n const controller = new AbortController();\n let timeoutId: ReturnType<typeof setTimeout> | undefined;\n\n const invokePromise = targetModel.invoke(messages, {\n signal: controller.signal,\n });\n\n const timeoutPromise = new Promise<never>((_, reject) => {\n timeoutId = setTimeout(() => {\n controller.abort(timeoutReason);\n reject(new Error(timeoutReason));\n }, LLM_TIMEOUT_MS);\n });\n\n try {\n return await Promise.race([invokePromise, timeoutPromise]);\n } finally {\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n }\n }\n\n /**\n * Generate personalized presentation for a single opportunity.\n */\n @Timed()\n public async present(\n input: PresenterInput,\n ): Promise<OpportunityPresentationResult> {\n const introContext = input.isIntroduction\n ? `\\nINTRODUCTION CONTEXT: This opportunity was created by an explicit introduction from ${input.introducerName ?? \"someone in the community\"}. It was NOT discovered automatically — a real person made this connection.\\n`\n : \"\";\n const humanContent = `\nVIEWER (the person seeing this opportunity):\n${input.viewerContext}\n\nOTHER PARTY:\n${input.otherPartyContext}\n\nMATCH CONTEXT:\n- Category: ${input.category}\n- Confidence: ${input.confidence}\n- Why we matched: ${input.matchReasoning}\n- Signals: ${input.signalsSummary}\n${introContext}\nCOMMUNITY: ${input.indexName}\nViewer's role in this opportunity: ${input.viewerRole}\n\nProduce headline, personalizedSummary (2-3 sentences in \"you\" language), suggestedAction, and greeting.\n`;\n\n try {\n const messages = [\n new SystemMessage(systemPrompt),\n new HumanMessage(humanContent),\n ];\n const result = await this.invokeWithTimeout(this.model, messages);\n const parsed = responseFormat.parse(result);\n parsed.presentation.personalizedSummary = stripUuids(parsed.presentation.personalizedSummary);\n return parsed.presentation;\n } catch (e) {\n const message = e instanceof Error ? e.message : String(e);\n const timeoutReason = message.includes(\"timed out\") ? message : undefined;\n logger.warn(\n \"[OpportunityPresenter.present] LLM failed, returning fallback\",\n {\n event: \"presenter_fallback\",\n presenter: \"opportunity\",\n reason: timeoutReason ? \"timeout\" : \"parse_error\",\n message,\n timeoutReason,\n },\n );\n return {\n headline: \"A promising connection\",\n personalizedSummary: truncateAtBoundary(stripUuids(input.matchReasoning), 300),\n suggestedAction: \"Take a look and decide whether to reach out.\",\n greeting: \"\",\n };\n }\n }\n\n /**\n * Generate LLM-powered home-card content (headline, body, narrator remark, mutual-intent label).\n * Callers append button labels from opportunity.constants.\n *\n * When `negotiationContext.status === 'negotiating'`, returns a templated\n * chip synchronously without invoking the LLM — the card just reflects\n * \"negotiation in progress\" at that point.\n */\n @Timed()\n public async presentHomeCard(\n input: HomeCardPresenterInput,\n ): Promise<HomeCardLLMResult> {\n if (input.negotiationContext?.status === 'negotiating') {\n return buildNegotiatingChip(input);\n }\n\n const mutualHint =\n input.mutualIntentCount != null && input.mutualIntentCount > 0\n ? `There are ${input.mutualIntentCount} overlapping intent(s) between viewer and other party.`\n : \"Match is based on profile and intent alignment. Do not cite a numeric intent count.\";\n const introContext = input.isIntroduction\n ? `\\nINTRODUCTION CONTEXT: This opportunity was created by an explicit introduction from ${input.introducerName ?? \"someone in the community\"}. It was NOT discovered automatically — a real person made this connection.\\n`\n : \"\";\n const negotiationBlock = buildNegotiationPromptBlock(input.negotiationContext);\n // When negotiation context exists, lead with it — these cards exist\n // *because* the negotiation happened. Trailing the block lets weaker\n // models lean on surface signals and ignore the transcript entirely.\n const negotiationDirective = negotiationBlock\n ? `\\nIMPORTANT: This opportunity surfaced because the agents negotiated and converged. Your personalizedSummary MUST reference at least one specific signal from the NEGOTIATION CONTEXT block below — what concern was raised, what was confirmed, what the agents agreed on. Do not produce a generic skill-complementarity summary; that's what every card looked like before this negotiation happened. Use the transcript to explain *why this specific match* surfaced now.\\n`\n : \"\";\n const humanContent = `\n${negotiationBlock}${negotiationDirective}\nVIEWER (the person seeing this opportunity):\n${input.viewerContext}\n\nOTHER PARTY:\n${input.otherPartyContext}\n\nMATCH CONTEXT:\n- Category: ${input.category}\n- Confidence: ${input.confidence}\n- Why we matched: ${input.matchReasoning}\n- Signals: ${input.signalsSummary}\n- ${mutualHint}\n${introContext}\nCOMMUNITY: ${input.indexName}\nViewer's role in this opportunity: ${input.viewerRole}\nOpportunity status: ${input.opportunityStatus ?? \"pending\"}\n\nProduce headline, personalizedSummary, digestSummary, suggestedAction, narratorRemark, greeting, and mutualIntentsLabel.\n`;\n\n const isIntroducer = input.viewerRole === \"introducer\";\n\n try {\n const messages = [\n new SystemMessage(homeCardSystemPrompt),\n new HumanMessage(humanContent),\n ];\n const result = await this.invokeWithTimeout(this.homeCardModel, messages);\n const parsed = homeCardResponseFormat.parse(result);\n parsed.presentation.personalizedSummary = stripUuids(parsed.presentation.personalizedSummary);\n parsed.presentation.digestSummary = stripUuids(parsed.presentation.digestSummary);\n parsed.presentation.narratorRemark = stripUuids(parsed.presentation.narratorRemark);\n if (/^0\\s+(mutual|overlapping)\\s+intent/i.test(parsed.presentation.mutualIntentsLabel)) {\n parsed.presentation.mutualIntentsLabel = \"Shared interests\";\n }\n if (input.isIntroduction && input.introducerName) {\n parsed.presentation.personalizedSummary = stripIntroducerMentions(\n parsed.presentation.personalizedSummary,\n input.introducerName,\n );\n parsed.presentation.digestSummary = stripIntroducerMentions(\n parsed.presentation.digestSummary,\n input.introducerName,\n );\n }\n return parsed.presentation;\n } catch (e) {\n const message = e instanceof Error ? e.message : String(e);\n const timeoutReason = message.includes(\"timed out\") ? message : undefined;\n logger.warn(\n \"[OpportunityPresenter.presentHomeCard] LLM failed, returning fallback\",\n {\n event: \"presenter_fallback\",\n presenter: \"home_card\",\n reason: timeoutReason ? \"timeout\" : \"parse_error\",\n message,\n timeoutReason,\n },\n );\n let fallbackSummary = truncateAtBoundary(stripUuids(input.matchReasoning), 300);\n if (input.isIntroduction && input.introducerName) {\n fallbackSummary = stripIntroducerMentions(fallbackSummary, input.introducerName);\n }\n return {\n headline: \"A promising connection\",\n personalizedSummary: fallbackSummary,\n digestSummary: isIntroducer\n ? \"You may be able to help make a useful introduction here.\"\n : \"You might like meeting them based on your current interests.\",\n suggestedAction: isIntroducer\n ? \"Share this introduction to get things started.\"\n : \"Take a look and decide whether to reach out.\",\n narratorRemark: \"Worth a look.\",\n mutualIntentsLabel: isIntroducer\n ? \"Connector match\"\n : input.mutualIntentCount != null && input.mutualIntentCount > 0\n ? `${input.mutualIntentCount} mutual intent${input.mutualIntentCount !== 1 ? \"s\" : \"\"}`\n : \"Shared interests\",\n greeting: \"\",\n };\n }\n }\n\n /**\n * Process multiple opportunities in parallel with bounded concurrency.\n */\n @Timed()\n public async presentBatch(\n inputs: PresenterInput[],\n options?: { concurrency?: number },\n ): Promise<OpportunityPresentationResult[]> {\n const concurrency = options?.concurrency ?? 5;\n const results: OpportunityPresentationResult[] = [];\n for (let i = 0; i < inputs.length; i += concurrency) {\n const chunk = inputs.slice(i, i + concurrency);\n const chunkResults = await Promise.all(\n chunk.map((inp) => this.present(inp)),\n );\n results.push(...chunkResults);\n }\n return results;\n }\n\n /**\n * Process multiple opportunities as home cards in parallel with bounded concurrency.\n * Returns full home-card display contracts (headline, body, narrator remark, action labels, mutual-intent label).\n */\n @Timed()\n public async presentHomeCardBatch(\n inputs: HomeCardPresenterInput[],\n options?: { concurrency?: number },\n ): Promise<HomeCardLLMResult[]> {\n const concurrency = options?.concurrency ?? 5;\n const results: HomeCardLLMResult[] = [];\n for (let i = 0; i < inputs.length; i += concurrency) {\n const chunk = inputs.slice(i, i + concurrency);\n const chunkResults = await Promise.all(\n chunk.map((inp) => this.presentHomeCard(inp)),\n );\n results.push(...chunkResults);\n }\n return results;\n }\n}\n\n// ──────────────────────────────────────────────────────────────\n// NEGOTIATION CONTEXT HELPERS\n// ──────────────────────────────────────────────────────────────\n\n/**\n * Builds a \"NEGOTIATION CONTEXT:\" block for the home-card prompt. Returns an\n * empty string when the opportunity has no meaningful negotiation context\n * (draft/latent) or when the opportunity is still negotiating (handled via\n * the templated chip, not the LLM).\n */\nfunction buildNegotiationPromptBlock(context: NegotiationContext | undefined): string {\n if (!context || context.status === 'negotiating') return \"\";\n\n const turnCapLabel = context.turnCap > 0 ? `${context.turnCap}` : \"unlimited\";\n const reason = context.outcome?.reason;\n const reasonLabel = reason === 'turn_cap'\n ? \"agents hit the turn cap without converging\"\n : reason === 'timeout'\n ? \"counterpart went silent before responding\"\n : undefined;\n\n const turnLines = (context.turns ?? []).map((turn, index) => {\n const action = turn.action;\n const reasoning = turn.assessment?.reasoning ?? \"(no reasoning)\";\n const message = turn.message ? ` — said: \"${turn.message}\"` : \"\";\n return `Turn ${index + 1} (${action}): ${reasoning}${message}`;\n });\n\n const outcomeSummary = context.outcome\n ? `Final outcome: ${context.outcome.hasOpportunity ? \"agreed\" : \"declined\"} — ${context.outcome.reasoning}`\n : \"Final outcome: not recorded.\";\n\n return `\nNEGOTIATION CONTEXT:\n- Negotiation status: ${context.status}${reasonLabel ? ` (${reasonLabel})` : \"\"}\n- Turns exchanged: ${context.turnCount} of ${turnCapLabel}\n- Transcript:\n${turnLines.length > 0 ? turnLines.map((l) => ` ${l}`).join(\"\\n\") : \" (no turns recorded)\"}\n- ${outcomeSummary}\n`;\n}\n\n/**\n * Builds a templated home-card result for an opportunity whose negotiation\n * is still in progress. Bypasses the LLM so users see a stable \"currently\n * negotiating\" chip while turns are still being exchanged.\n */\nfunction buildNegotiatingChip(input: HomeCardPresenterInput): HomeCardLLMResult {\n const ctx = input.negotiationContext;\n const turnCount = ctx?.turnCount ?? 0;\n const turnCap = ctx?.turnCap && ctx.turnCap > 0 ? ctx.turnCap : undefined;\n const narratorRemark = turnCap\n ? `Currently negotiating · turn ${turnCount} of ${turnCap}`\n : `Currently negotiating · turn ${turnCount}`;\n\n return {\n headline: \"Negotiation in progress\",\n 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.\",\n digestSummary: \"Your agent is still checking whether this connection makes sense.\",\n suggestedAction: \"Check back shortly — no action needed yet.\",\n narratorRemark,\n mutualIntentsLabel: input.mutualIntentCount && input.mutualIntentCount > 0\n ? `${input.mutualIntentCount} mutual intent${input.mutualIntentCount !== 1 ? \"s\" : \"\"}`\n : \"Shared interests\",\n greeting: \"\",\n };\n}\n\n// ──────────────────────────────────────────────────────────────\n// CONTEXT GATHERER (used by tools)\n// ──────────────────────────────────────────────────────────────\n\n/**\n * Gather all context needed for the presenter from the database.\n * Fetches viewer profile, viewer intents, other party profile(s), and index in parallel.\n *\n * @param displayCounterpartUserId - When set (e.g. for home card), only this counterpart is included in otherPartyContext so the presenter writes about the person on the card. Omitted for introducer view (card shows both parties).\n */\nexport async function gatherPresenterContext(\n database: PresenterDatabase,\n opportunity: Opportunity,\n viewerId: string,\n displayCounterpartUserId?: string,\n): Promise<PresenterInput> {\n const myActor = opportunity.actors.find((a) => a.userId === viewerId);\n if (!myActor) {\n throw new Error(\"Viewer is not an actor in this opportunity\");\n }\n\n const isIntroducer = myActor.role === \"introducer\";\n const otherActors = opportunity.actors.filter((a) => a.userId !== viewerId);\n let otherPartyIds = [...new Set(otherActors.map((a) => a.userId))];\n if (\n displayCounterpartUserId &&\n !isIntroducer &&\n otherPartyIds.includes(displayCounterpartUserId)\n ) {\n otherPartyIds = [displayCounterpartUserId];\n }\n\n const contextIndexId = opportunity.context?.networkId;\n\n // For introducers: fetch profiles + intents for both parties; skip introducer's own intents.\n // For other roles: fetch viewer's profile + intents and other party profiles.\n const [viewerProfile, indexRecord, ...otherProfiles] = await Promise.all([\n database.getProfile(viewerId),\n contextIndexId ? database.getNetwork(contextIndexId) : Promise.resolve(null),\n ...otherPartyIds.map((uid) => database.getProfile(uid)),\n ]);\n\n // Fetch intents: for introducer, fetch each party's intents; otherwise fetch viewer's intents.\n let viewerIntents:\n | Awaited<ReturnType<typeof database.getActiveIntents>>\n | undefined;\n let partyIntentsMap:\n | Map<string, Awaited<ReturnType<typeof database.getActiveIntents>>>\n | undefined;\n\n if (isIntroducer) {\n const partyIntentResults = await Promise.all(\n otherPartyIds.map(async (uid) => ({\n uid,\n intents: await database.getActiveIntents(uid),\n })),\n );\n partyIntentsMap = new Map(\n partyIntentResults.map((r) => [r.uid, r.intents]),\n );\n } else {\n viewerIntents = await database.getActiveIntents(viewerId);\n }\n\n // Fetch premises when any actor is premise-grounded\n const premiseGroundedActors = opportunity.actors.filter((a) => a.premise);\n let viewerPremiseContext = '';\n let otherPremiseContext = '';\n\n if (premiseGroundedActors.length > 0) {\n // Only fetch premises for actors that are actually premise-grounded, not all parties\n const groundedOtherIds = premiseGroundedActors\n .filter((a) => a.userId !== viewerId)\n .map((a) => a.userId);\n const viewerIsGrounded = premiseGroundedActors.some((a) => a.userId === viewerId);\n\n const results = await Promise.all([\n ...(viewerIsGrounded ? [database.getPremisesForUser(viewerId, 'ACTIVE')] : []),\n ...groundedOtherIds.map((uid) => database.getPremisesForUser(uid, 'ACTIVE')),\n ]);\n\n let idx = 0;\n if (viewerIsGrounded) {\n const viewerPremises = results[idx++];\n if (viewerPremises?.length) {\n viewerPremiseContext =\n '\\nPremises (self-descriptions):\\n' +\n viewerPremises\n .slice(0, 5)\n .map((p) => `- ${p.assertion.text}`)\n .join('\\n');\n }\n }\n\n const otherPremiseLines: string[] = [];\n for (let i = 0; i < groundedOtherIds.length; i++) {\n const premises = results[idx++];\n if (premises?.length) {\n for (const p of premises.slice(0, 3)) {\n otherPremiseLines.push(`- ${p.assertion.text}`);\n }\n }\n }\n if (otherPremiseLines.length > 0) {\n otherPremiseContext = '\\nPremises (self-descriptions):\\n' + otherPremiseLines.join('\\n');\n }\n }\n\n let viewerContext: string;\n let otherPartyContext: string;\n\n if (isIntroducer) {\n // Introducer view: minimal viewer context (just name + role), rich other-party context with intents\n const introducerApproved = opportunity.actors.find(a => a.role === 'introducer')?.approved === true;\n const hasApproved = introducerApproved || opportunity.status !== 'latent';\n viewerContext = [\n \"Profile:\",\n `Name: ${viewerProfile?.identity?.name ?? \"Unknown\"}`,\n hasApproved\n ? \"Role: You are the introducer who suggested this connection.\"\n : \"Role: You are being asked whether these two people would benefit from meeting. You have NOT yet approved this introduction.\",\n ].join(\"\\n\");\n\n const otherParts = otherPartyIds.map((uid, idx) => {\n const profile = otherProfiles[idx] as Awaited<\n ReturnType<typeof database.getProfile>\n >;\n const name = profile?.identity?.name ?? \"Unknown\";\n const bio = profile?.identity?.bio ?? \"\";\n const location = profile?.identity?.location ?? \"\";\n const skills = profile?.attributes?.skills?.join(\", \") ?? \"\";\n const interests = profile?.attributes?.interests?.join(\", \") ?? \"\";\n const context = profile?.narrative?.context ?? \"\";\n const intents = partyIntentsMap?.get(uid);\n const intentLines = intents?.length\n ? intents\n .slice(0, 5)\n .map((i) => ` - ${i.payload}${i.summary ? ` (${i.summary})` : \"\"}`)\n : [\" (no active intents)\"];\n return [\n `${name}:`,\n ` Bio: ${bio}`,\n location ? ` Location: ${location}` : null,\n skills ? ` Skills: ${skills}` : null,\n interests ? ` Interests: ${interests}` : null,\n context ? ` Context: ${context}` : null,\n ` Active intents:`,\n ...intentLines,\n ]\n .filter(Boolean)\n .join(\"\\n\");\n });\n otherPartyContext =\n otherParts.join(\"\\n\\n\") || \"Parties (details not available).\";\n } else {\n // Non-introducer view: full viewer profile + intents, other party profiles\n const viewerContextLines = [\n \"Profile:\",\n `Name: ${viewerProfile?.identity?.name ?? \"Unknown\"}`,\n `Bio: ${viewerProfile?.identity?.bio ?? \"\"}`,\n `Location: ${viewerProfile?.identity?.location ?? \"\"}`,\n `Skills: ${viewerProfile?.attributes?.skills?.join(\", \") ?? \"\"}`,\n `Interests: ${viewerProfile?.attributes?.interests?.join(\", \") ?? \"\"}`,\n `Context: ${viewerProfile?.narrative?.context ?? \"\"}`,\n \"Active intents:\",\n ...(viewerIntents?.length\n ? viewerIntents.map(\n (i) => `- ${i.payload}${i.summary ? ` (${i.summary})` : \"\"}`,\n )\n : [\"(none listed)\"]),\n ];\n viewerContext = viewerContextLines.join(\"\\n\");\n\n const otherParts = otherPartyIds.map((uid, idx) => {\n const profile = otherProfiles[idx] as Awaited<\n ReturnType<typeof database.getProfile>\n >;\n const name = profile?.identity?.name ?? \"Unknown\";\n const bio = profile?.identity?.bio ?? \"\";\n const skills = profile?.attributes?.skills?.join(\", \") ?? \"\";\n const interests = profile?.attributes?.interests?.join(\", \") ?? \"\";\n return `${name}: ${bio}. Skills: ${skills}. Interests: ${interests}`;\n });\n otherPartyContext =\n otherParts.join(\"\\n\\n\") || \"Other party (details not available).\";\n }\n\n const interp = opportunity.interpretation;\n const signalsSummary =\n interp.signals?.map((s) => `${s.type}: ${s.detail ?? s.type}`).join(\"; \") ??\n \"Match based on profile and intent alignment.\";\n\n // Detect introduction-originated opportunities: only when there is an explicit introducer actor.\n // Do NOT use detection.source === \"manual\" alone — system-discovered opportunities can have manual source without an introducer.\n const introducerActor = opportunity.actors.find(\n (a) => a.role === \"introducer\",\n );\n const isIntroduction = !!introducerActor;\n let introducerName: string | undefined;\n if (introducerActor) {\n introducerName = opportunity.detection.createdByName;\n if (!introducerName) {\n const introducerProfile = await database.getProfile(\n introducerActor.userId,\n );\n introducerName = introducerProfile?.identity?.name ?? undefined;\n }\n }\n\n const counterpartName =\n otherPartyIds.length === 1 && otherProfiles[0]\n ? (otherProfiles[0] as { identity?: { name?: string } })?.identity?.name?.trim()\n : undefined;\n const viewerNameForFilter = viewerProfile?.identity?.name?.trim();\n const matchReasoning =\n counterpartName && interp.reasoning\n ? viewerCentricCardSummary(\n interp.reasoning,\n counterpartName,\n 400,\n viewerNameForFilter,\n introducerName,\n )\n : stripUuids(interp.reasoning);\n\n if (viewerPremiseContext) {\n viewerContext += viewerPremiseContext;\n }\n if (otherPremiseContext) {\n otherPartyContext += otherPremiseContext;\n }\n\n const result: PresenterInput = {\n viewerContext,\n otherPartyContext,\n matchReasoning,\n category: interp.category ?? \"connection\",\n confidence:\n typeof interp.confidence === \"number\"\n ? interp.confidence\n : parseFloat(String(interp.confidence ?? 0)) || 0,\n signalsSummary,\n indexName: indexRecord?.title ?? contextIndexId ?? \"\",\n viewerRole: myActor.role ?? \"party\",\n isIntroduction,\n introducerName,\n };\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"opportunity.presenter.js","sourceRoot":"/","sources":["opportunity/opportunity.presenter.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;;;;;;;;;;AAGH,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AACvE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,OAAO,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAE/D,OAAO,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAC;AAC5E,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,wBAAwB,EAAE,MAAM,+BAA+B,CAAC;AAIzE,OAAO,EAAE,UAAU,EAAE,uBAAuB,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AAWxG,MAAM,MAAM,GAAG,cAAc,CAAC,sBAAsB,CAAC,CAAC;AACtD,MAAM,cAAc,GAAG,KAAM,CAAC;AAE9B,MAAM,KAAK,GAAG,WAAW,CAAC,sBAAsB,CAAC,CAAC;AAElD,MA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EAAE,IAAI,EAAE,IAAI,EAAE;QAChF,CAAC,CAAC,SAAS,CAAC;IAChB,MAAM,mBAAmB,GAAG,aAAa,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC;IAClE,MAAM,cAAc,GAClB,eAAe,IAAI,MAAM,CAAC,SAAS;QACjC,CAAC,CAAC,wBAAwB,CACtB,MAAM,CAAC,SAAS,EAChB,eAAe,EACf,GAAG,EACH,mBAAmB,EACnB,cAAc,CACf;QACH,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAEnC,IAAI,oBAAoB,EAAE,CAAC;QACzB,aAAa,IAAI,oBAAoB,CAAC;IACxC,CAAC;IACD,IAAI,mBAAmB,EAAE,CAAC;QACxB,iBAAiB,IAAI,mBAAmB,CAAC;IAC3C,CAAC;IAED,MAAM,MAAM,GAAmB;QAC7B,aAAa;QACb,iBAAiB;QACjB,cAAc;QACd,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,YAAY;QACzC,UAAU,EACR,OAAO,MAAM,CAAC,UAAU,KAAK,QAAQ;YACnC,CAAC,CAAC,MAAM,CAAC,UAAU;YACnB,CAAC,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC;QACrD,cAAc;QACd,SAAS,EAAE,WAAW,EAAE,KAAK,IAAI,cAAc,IAAI,EAAE;QACrD,UAAU,EAAE,OAAO,CAAC,IAAI,IAAI,OAAO;QACnC,cAAc;QACd,cAAc;KACf,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/**\n * Opportunity Presenter Agent\n *\n * Generates personalized, second-person explanations of why an opportunity\n * matters to the viewing user. Uses full opportunity data (interpretation,\n * actors, profiles, intents, index) to produce headline, personalizedSummary,\n * and suggestedAction for chat tools and user-facing surfaces.\n */\n\nimport type { Runnable } from \"@langchain/core/runnables\";\nimport { HumanMessage, SystemMessage } from \"@langchain/core/messages\";\nimport { z } from \"zod\";\n\nimport { Timed } from \"../shared/observability/performance.js\";\n\nimport { protocolLogger } from \"../shared/observability/protocol.logger.js\";\nimport { createModel } from \"../shared/agent/model.config.js\";\nimport { viewerCentricCardSummary } from \"./opportunity.presentation.js\";\nimport type { Opportunity } from \"../shared/interfaces/database.interface.js\";\nimport type { ChatGraphCompositeDatabase } from \"../shared/interfaces/database.interface.js\";\nimport type { NegotiationContext } from \"./negotiation-context.loader.js\";\nimport { stripUuids, stripIntroducerMentions, truncateAtBoundary } from \"./opportunity.presentation.js\";\n\n/**\n * Minimal database interface required by gatherPresenterContext.\n * Any database adapter that implements these three methods can be passed.\n */\nexport type PresenterDatabase = Pick<\n ChatGraphCompositeDatabase,\n \"getProfile\" | \"getActiveIntents\" | \"getNetwork\" | \"getPremisesForUser\"\n>;\n\nconst logger = protocolLogger(\"OpportunityPresenter\");\nconst LLM_TIMEOUT_MS = 20_000;\n\nconst model = createModel(\"opportunityPresenter\");\n\nconst GREETING_DESCRIPTION =\n \"A 2-4 sentence first-person message the viewer could send to the counterpart, in the viewer's voice, referencing what they have in common. Plain prose only — no markdown, no greeting prefix like 'Hey {Name},'. Example body: 'Saw we're both working on regenerative coordination tooling — your post on consent flows resonated. Would love to compare notes if you have time this week.'\";\n\n// ──────────────────────────────────────────────────────────────\n// SCHEMA & TYPES\n// ──────────────────────────────────────────────────────────────\n\nconst PresentationSchema = z.object({\n headline: z\n .string()\n .describe(\n \"Short, compelling headline for this opportunity (e.g., 'A React expert who needs your design skills')\",\n ),\n personalizedSummary: z\n .string()\n .describe(\n \"2-3 sentence explanation using 'you' language, explaining why this opportunity is specifically valuable for the viewer based on their intents and profile\",\n ),\n suggestedAction: z.string().describe(\"Brief suggested next step\"),\n greeting: z.string().max(500).describe(GREETING_DESCRIPTION),\n});\n\nconst responseFormat = z.object({\n presentation: PresentationSchema,\n});\n\nexport type OpportunityPresentationResult = z.infer<typeof PresentationSchema>;\n\n/** Input for home-card presenter call; extends PresenterInput with optional mutual intent count. */\nexport interface HomeCardPresenterInput extends PresenterInput {\n /** Number of overlapping intents (for generating mutualIntentsLabel). */\n mutualIntentCount?: number;\n /**\n * Snapshot of the opportunity's negotiation, if one exists. When status is\n * `negotiating`, the presenter returns a templated chip without invoking\n * the LLM. For `pending`/`stalled`/`accepted`/`rejected`, the full\n * transcript and outcome ground the LLM's explanation.\n */\n negotiationContext?: NegotiationContext;\n}\n\n/** LLM-generated fields for home-card presentation (buttons are hardcoded by callers, not LLM-generated). */\nexport const HomeCardLLMSchema = z.object({\n headline: z\n .string()\n .describe(\"Short, compelling headline for this opportunity\"),\n personalizedSummary: z\n .string()\n .describe(\n \"2-3 sentence explanation in 'you' language for the main card body\",\n ),\n digestSummary: z\n .string()\n .max(220)\n .describe(\n \"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.\",\n ),\n suggestedAction: z\n .string()\n .describe(\"Brief suggested next step (e.g. CTA line)\"),\n narratorRemark: z\n .string()\n .max(80)\n .describe(\n \"One short sentence for the narrator chip, max ~80 chars (e.g. who is suggesting and why)\",\n ),\n mutualIntentsLabel: z\n .string()\n .max(48)\n .describe(\n \"Short line for the subtitle under the other party name (e.g. '3 mutual intents', 'Shared interests', 'Aligned goals'). NEVER output '0 mutual intents' — use a qualitative phrase like 'Shared interests' when no numeric count is available.\",\n ),\n greeting: z.string().max(500).describe(GREETING_DESCRIPTION),\n});\n\n/** LLM-generated result from presentHomeCard (callers append button labels from opportunity.constants). */\nexport type HomeCardLLMResult = z.infer<typeof HomeCardLLMSchema>;\n\n/** Full home-card display contract including hardcoded button labels (assembled by callers). */\nexport type HomeCardPresentationResult = HomeCardLLMResult & {\n primaryActionLabel: string;\n secondaryActionLabel: string;\n};\n\nconst homeCardResponseFormat = z.object({\n presentation: HomeCardLLMSchema,\n});\n\n/** Input for a single presenter call (all context pre-assembled). */\nexport interface PresenterInput {\n viewerContext: string;\n otherPartyContext: string;\n matchReasoning: string;\n category: string;\n confidence: number;\n signalsSummary: string;\n indexName: string;\n viewerRole: string;\n opportunityStatus?: string;\n /** True when this opportunity was created via an explicit introduction (not automatic discovery). */\n isIntroduction?: boolean;\n /** Name of the person who made the introduction, if applicable. */\n introducerName?: string;\n}\n\n// ──────────────────────────────────────────────────────────────\n// SYSTEM PROMPT\n// ──────────────────────────────────────────────────────────────\n\nconst systemPrompt = `\nYou are an expert at presenting connection opportunities to users in a way that feels personal and compelling.\n\nYour goal: Given raw context about the viewer (their profile, intents), the other person(s), and why the system matched them, produce a short headline, a personalized summary, and a suggested action.\n\nRules:\n1. Address the VIEWER directly using \"you\" and \"your\". This is for them.\n2. Be concise and compelling — not analytical or third-party. No \"The source user\" or \"The candidate\"; use names or \"they\" where needed.\n3. Do not leak private or confidential details. Use only the context provided.\n4. Vary user-facing nouns naturally. Do not repeatedly use the same label in one response.\n5. If possible, avoid repeating \"opportunity\" in both headline and summary. Prefer alternatives like \"connection\", \"thought partner\", \"mutual fit\", \"valuable conversation\", or \"peer\".\n6. Prefer first names in user-facing copy. Do not repeatedly use full names unless needed to disambiguate.\n\n**Introduction-originated opportunities:**\nWhen INTRODUCTION CONTEXT is provided, this opportunity was explicitly created by an introducer (a real person who saw value in this connection). This is NOT an automatic system discovery — someone made a deliberate judgment.\n- For ALL roles: acknowledge the introducer's role naturally. E.g., \"[Introducer name] thinks you should meet [other person]\" or \"[Introducer name] connected you because...\"\n- The introduction itself is a strong signal — treat it with the weight of a personal recommendation.\n- If the parties' intents don't obviously overlap, that's fine — the introducer saw something worth connecting. Focus on what the introducer likely saw.\n\n**Role-Specific Presentation:**\n\n**If viewer is \"introducer\":**\n- The viewer suggested this connection between two (or more) OTHER people. The opportunity is NOT about the viewer's own needs.\n- Headline: describe the connection between the parties (e.g., \"Connecting a React expert with a startup founder\").\n- Personalized summary: explain why the people YOU are introducing should meet. Reference THEIR profiles and intents, not yours. Frame it as \"you're connecting X and Y because...\" rather than \"this matches your intent\".\n- Suggested action: guide sharing (e.g., \"Share this with [name] to get things started\").\n- CRITICAL: Do NOT reference the introducer's own intents, skills, or needs. The introducer is the matchmaker, not a party.\n\n**If viewer is \"patient\" or \"party\":**\n- Reference their specific intents, skills, or interests that align with this opportunity.\n- If this is an introduction: mention who introduced them and frame it as a personal recommendation.\n- Headline: one short line that hooks (e.g., \"[Name] thinks you should meet [Other]\" or \"A React expert who needs your design skills\").\n- Personalized summary: 2-3 sentences. Why is this opportunity for *them*? If introduced, lead with the introduction.\n- Suggested action: encourage action (\"Send a message to start the conversation\" or \"Share this intro\").\n\n**If viewer is \"agent\":**\n- They are seeing this because someone already reached out.\n- If this is an introduction: mention who made the introduction.\n- Reference their skills/expertise that make them a match.\n- Headline: what the other person needs that they can provide.\n- Personalized summary: 2-3 sentences. Why someone reached out to them.\n- Suggested action: \"Someone is interested in connecting — check their message\" or \"Review and respond\".\n\n**If viewer is \"peer\":**\n- Mutual opportunity. Reference shared or complementary interests.\n- If this is an introduction: mention who connected them.\n- Headline: the mutual connection angle.\n- Personalized summary: 2-3 sentences. Why this is mutually valuable.\n- Suggested action: \"Send an intro to connect\" or \"Start a conversation\".\n`;\n\nconst homeCardSystemPrompt = `\nYou are an expert at presenting connection opportunities for a home feed card.\n\nGiven context about the viewer, the other person, and why they were matched, produce:\n1. headline: one short hook line.\n2. personalizedSummary: 2-3 sentences in \"you\" language (main body text).\n3. digestSummary: one polished morning-brief sentence that can be printed directly after the person's linked name. No markdown, no field labels.\n4. suggestedAction: one brief suggested next step.\n5. narratorRemark: one short sentence for the narrator chip (who is suggesting and why; max ~80 chars).\n6. greeting: a 2-4 sentence first-person message the viewer could send to the counterpart. Plain prose, no greeting prefix, no markdown.\n7. 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.\n\nRules:\n- Address the viewer with \"you\"/\"your\". Be concise and compelling.\n- narratorRemark should feel like a single sentence from the narrator (Index or a person), not meta-commentary.\n- 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\").\n- Vary wording for the match itself. Do not repeat \"opportunity\" across headline, summary, and narratorRemark when alternatives fit.\n- Prefer first names in user-facing copy. Avoid repeated full names unless disambiguation is necessary.\n- 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.\n- digestSummary must NOT use awkward third-person fragments like \"Name is...\", \"they're ..., and is...\", \"you is...\", or \"the discoverer's query\".\n- digestSummary must be one sentence, MUST fit within 180 characters when possible, and MUST contain no markdown links; the caller will attach links.\n- If you cannot fit every detail, choose one clear reason and stop. Do not rely on downstream truncation.\n\n**Introduction-originated opportunities (ONLY when INTRODUCTION CONTEXT is provided):**\nWhen INTRODUCTION CONTEXT is provided, this opportunity was explicitly created by an introducer. It was NOT automatically discovered.\n- For parties/patients/agents/peers viewing an introduction: keep the introducer signal in narratorRemark (and narrator chip), not in personalizedSummary.\n- For these introduced parties, personalizedSummary must focus ONLY on fit/value between viewer and counterpart. Do NOT mention the introducer there.\n- narratorRemark should carry the introduction signal (e.g., \"saw strong alignment between you two\" or \"thought this connection could be valuable\"), without repeating the narrator name at the start.\n- This is a personal recommendation, not an algorithm match. Frame it accordingly.\n\n**CRITICAL: NEVER include introducer names in personalizedSummary. Examples:**\n❌ WRONG: \"Seref introduced you to Lucy, who is actively seeking a product co-founder...\"\n✅ CORRECT: \"Lucy is actively seeking a product co-founder for a niche APAC marketplace. With your expertise in UX and AI, this could be an ideal collaboration.\"\n\n❌ WRONG: \"Bob thinks you should meet Alice because your React skills align with her needs.\"\n✅ CORRECT: \"Alice is building a React-based platform and needs frontend expertise. Your experience with component architecture makes you a strong fit.\"\n\n❌ WRONG: \"Jane connected you to Mark, who is looking for a designer.\"\n✅ CORRECT: \"Mark is building a consumer app and needs design expertise. Your background in user-centered design aligns well with what he's building.\"\n\nRemember: The introducer's name goes ONLY in narratorRemark, NEVER in personalizedSummary.\n\n**When INTRODUCTION CONTEXT is NOT provided (system-discovered match):**\n- Do NOT use introducer-style wording. Do NOT say \"you suggested\", \"this is an introduction you suggested\", or \"you suggested this connection\". The system found this match; no human introducer was involved.\n- Instead, narratorRemark should describe why the match is relevant (e.g. \"Based on your overlapping intents\", \"Your skills align with what they need\").\n\n**Negotiation-grounded explanations (ONLY when NEGOTIATION CONTEXT is provided):**\nWhen NEGOTIATION CONTEXT is provided, this opportunity passed through an agent-to-agent negotiation. Use the transcript to ground your explanation in the concrete reasoning the agents exchanged.\n- Personalize the summary with *why* the negotiation produced this match — reference the roles the agents agreed on, the specific concerns raised, and how they were resolved.\n- For status \"stalled\" with reason \"turn_cap\": the agents hit the turn limit without reaching agreement. Frame the card as a hedged possibility rather than a confident match; narratorRemark should signal \"agents couldn't fully converge\" without sounding negative.\n- For status \"stalled\" with reason \"timeout\": one side went silent. Suggest the user re-engage if interested.\n- For status \"accepted\": the agents agreed; the card should confidently explain *why* they agreed.\n- For status \"rejected\": the agents declined. The card should explain the reason briefly so the user understands — not dwell on it.\n- Do NOT invent turn content. Only reference what is in the NEGOTIATION CONTEXT block.\n\n- Exception for connector/introducer: if viewer role is \"introducer\" (any status), this is a curation/connector card. Use:\n - suggestedAction: one short line about sharing the intro or confirming the match.\n - mutualIntentsLabel: a short connector label (e.g. \"Connector match\", \"You can bridge this\").\n - headline: describe the connection between the parties (e.g., \"Connecting a PhD researcher with a translator\"). Do NOT reference the introducer's own needs.\n - personalizedSummary: explain why the parties you're introducing should meet, referencing THEIR profiles and intents, not yours.\n\n**CRITICAL for latent introducer cards (opportunity status is \"latent\"):**\nWhen the viewer is the introducer and the opportunity status is \"latent\", the introducer has NOT yet approved this match. They are evaluating whether to make the introduction.\n- narratorRemark MUST use evaluation/curation language (e.g. \"Could be a strong match\", \"Worth introducing?\", \"Interesting overlap here\").\n- Do NOT say \"you suggested\", \"you introduced\", \"you connected\", or any past-tense language implying the introduction was already made.\n- suggestedAction should encourage evaluation (e.g. \"Approve if you see the fit\").\n- Exception for new-connection reveal: if viewer role is \"agent\", status is \"accepted\", and there is an introducer, this is the agent's first time seeing this opportunity. Use:\n - suggestedAction: a short line about joining the conversation.\n`;\n\n// ──────────────────────────────────────────────────────────────\n// CLASS\n// ──────────────────────────────────────────────────────────────\n\nexport class OpportunityPresenter {\n private model: Runnable;\n private homeCardModel: Runnable;\n\n constructor() {\n this.model = model.withStructuredOutput(responseFormat, {\n name: \"opportunity_presenter\",\n });\n this.homeCardModel = model.withStructuredOutput(homeCardResponseFormat, {\n name: \"opportunity_presenter_home_card\",\n });\n }\n\n private async invokeWithTimeout(\n targetModel: Runnable,\n messages: (SystemMessage | HumanMessage)[],\n ): Promise<unknown> {\n const timeoutReason = `LLM invoke timed out after ${LLM_TIMEOUT_MS}ms`;\n const controller = new AbortController();\n let timeoutId: ReturnType<typeof setTimeout> | undefined;\n\n const invokePromise = targetModel.invoke(messages, {\n signal: controller.signal,\n });\n\n const timeoutPromise = new Promise<never>((_, reject) => {\n timeoutId = setTimeout(() => {\n controller.abort(timeoutReason);\n reject(new Error(timeoutReason));\n }, LLM_TIMEOUT_MS);\n });\n\n try {\n return await Promise.race([invokePromise, timeoutPromise]);\n } finally {\n if (timeoutId) {\n clearTimeout(timeoutId);\n }\n }\n }\n\n /**\n * Generate personalized presentation for a single opportunity.\n */\n @Timed()\n public async present(\n input: PresenterInput,\n ): Promise<OpportunityPresentationResult> {\n const introContext = input.isIntroduction\n ? `\\nINTRODUCTION CONTEXT: This opportunity was created by an explicit introduction from ${input.introducerName ?? \"someone in the community\"}. It was NOT discovered automatically — a real person made this connection.\\n`\n : \"\";\n const humanContent = `\nVIEWER (the person seeing this opportunity):\n${input.viewerContext}\n\nOTHER PARTY:\n${input.otherPartyContext}\n\nMATCH CONTEXT:\n- Category: ${input.category}\n- Confidence: ${input.confidence}\n- Why we matched: ${input.matchReasoning}\n- Signals: ${input.signalsSummary}\n${introContext}\nCOMMUNITY: ${input.indexName}\nViewer's role in this opportunity: ${input.viewerRole}\n\nProduce headline, personalizedSummary (2-3 sentences in \"you\" language), suggestedAction, and greeting.\n`;\n\n try {\n const messages = [\n new SystemMessage(systemPrompt),\n new HumanMessage(humanContent),\n ];\n const result = await this.invokeWithTimeout(this.model, messages);\n const parsed = responseFormat.parse(result);\n parsed.presentation.personalizedSummary = stripUuids(parsed.presentation.personalizedSummary);\n return parsed.presentation;\n } catch (e) {\n const message = e instanceof Error ? e.message : String(e);\n const timeoutReason = message.includes(\"timed out\") ? message : undefined;\n logger.warn(\n \"[OpportunityPresenter.present] LLM failed, returning fallback\",\n {\n event: \"presenter_fallback\",\n presenter: \"opportunity\",\n reason: timeoutReason ? \"timeout\" : \"parse_error\",\n message,\n timeoutReason,\n },\n );\n return {\n headline: \"A promising connection\",\n personalizedSummary: truncateAtBoundary(stripUuids(input.matchReasoning), 300),\n suggestedAction: \"Take a look and decide whether to reach out.\",\n greeting: \"\",\n };\n }\n }\n\n /**\n * Generate LLM-powered home-card content (headline, body, narrator remark, mutual-intent label).\n * Callers append button labels from opportunity.constants.\n *\n * When `negotiationContext.status === 'negotiating'`, returns a templated\n * chip synchronously without invoking the LLM — the card just reflects\n * \"negotiation in progress\" at that point.\n */\n @Timed()\n public async presentHomeCard(\n input: HomeCardPresenterInput,\n ): Promise<HomeCardLLMResult> {\n if (input.negotiationContext?.status === 'negotiating') {\n return buildNegotiatingChip(input);\n }\n\n const mutualHint =\n input.mutualIntentCount != null && input.mutualIntentCount > 0\n ? `There are ${input.mutualIntentCount} overlapping intent(s) between viewer and other party.`\n : \"Match is based on profile and intent alignment. Do not cite a numeric intent count.\";\n const introContext = input.isIntroduction\n ? `\\nINTRODUCTION CONTEXT: This opportunity was created by an explicit introduction from ${input.introducerName ?? \"someone in the community\"}. It was NOT discovered automatically — a real person made this connection.\\n`\n : \"\";\n const negotiationBlock = buildNegotiationPromptBlock(input.negotiationContext);\n // When negotiation context exists, lead with it — these cards exist\n // *because* the negotiation happened. Trailing the block lets weaker\n // models lean on surface signals and ignore the transcript entirely.\n const negotiationDirective = negotiationBlock\n ? `\\nIMPORTANT: This opportunity surfaced because the agents negotiated and converged. Your personalizedSummary MUST reference at least one specific signal from the NEGOTIATION CONTEXT block below — what concern was raised, what was confirmed, what the agents agreed on. Do not produce a generic skill-complementarity summary; that's what every card looked like before this negotiation happened. Use the transcript to explain *why this specific match* surfaced now.\\n`\n : \"\";\n const humanContent = `\n${negotiationBlock}${negotiationDirective}\nVIEWER (the person seeing this opportunity):\n${input.viewerContext}\n\nOTHER PARTY:\n${input.otherPartyContext}\n\nMATCH CONTEXT:\n- Category: ${input.category}\n- Confidence: ${input.confidence}\n- Why we matched: ${input.matchReasoning}\n- Signals: ${input.signalsSummary}\n- ${mutualHint}\n${introContext}\nCOMMUNITY: ${input.indexName}\nViewer's role in this opportunity: ${input.viewerRole}\nOpportunity status: ${input.opportunityStatus ?? \"pending\"}\n\nProduce headline, personalizedSummary, digestSummary, suggestedAction, narratorRemark, greeting, and mutualIntentsLabel.\n`;\n\n const isIntroducer = input.viewerRole === \"introducer\";\n\n try {\n const messages = [\n new SystemMessage(homeCardSystemPrompt),\n new HumanMessage(humanContent),\n ];\n const result = await this.invokeWithTimeout(this.homeCardModel, messages);\n const parsed = homeCardResponseFormat.parse(result);\n parsed.presentation.personalizedSummary = stripUuids(parsed.presentation.personalizedSummary);\n parsed.presentation.digestSummary = stripUuids(parsed.presentation.digestSummary);\n parsed.presentation.narratorRemark = stripUuids(parsed.presentation.narratorRemark);\n if (/^0\\s+(mutual|overlapping)\\s+intent/i.test(parsed.presentation.mutualIntentsLabel)) {\n parsed.presentation.mutualIntentsLabel = \"Shared interests\";\n }\n if (input.isIntroduction && input.introducerName) {\n parsed.presentation.personalizedSummary = stripIntroducerMentions(\n parsed.presentation.personalizedSummary,\n input.introducerName,\n );\n parsed.presentation.digestSummary = stripIntroducerMentions(\n parsed.presentation.digestSummary,\n input.introducerName,\n );\n }\n return parsed.presentation;\n } catch (e) {\n const message = e instanceof Error ? e.message : String(e);\n const timeoutReason = message.includes(\"timed out\") ? message : undefined;\n logger.warn(\n \"[OpportunityPresenter.presentHomeCard] LLM failed, returning fallback\",\n {\n event: \"presenter_fallback\",\n presenter: \"home_card\",\n reason: timeoutReason ? \"timeout\" : \"parse_error\",\n message,\n timeoutReason,\n },\n );\n let fallbackSummary = truncateAtBoundary(stripUuids(input.matchReasoning), 300);\n if (input.isIntroduction && input.introducerName) {\n fallbackSummary = stripIntroducerMentions(fallbackSummary, input.introducerName);\n }\n return {\n headline: \"A promising connection\",\n personalizedSummary: fallbackSummary,\n digestSummary: isIntroducer\n ? \"You may be able to help make a useful introduction here.\"\n : \"You might like meeting them based on your current interests.\",\n suggestedAction: isIntroducer\n ? \"Share this introduction to get things started.\"\n : \"Take a look and decide whether to reach out.\",\n narratorRemark: \"Worth a look.\",\n mutualIntentsLabel: isIntroducer\n ? \"Connector match\"\n : input.mutualIntentCount != null && input.mutualIntentCount > 0\n ? `${input.mutualIntentCount} mutual intent${input.mutualIntentCount !== 1 ? \"s\" : \"\"}`\n : \"Shared interests\",\n greeting: \"\",\n };\n }\n }\n\n /**\n * Process multiple opportunities in parallel with bounded concurrency.\n */\n @Timed()\n public async presentBatch(\n inputs: PresenterInput[],\n options?: { concurrency?: number },\n ): Promise<OpportunityPresentationResult[]> {\n const concurrency = options?.concurrency ?? 5;\n const results: OpportunityPresentationResult[] = [];\n for (let i = 0; i < inputs.length; i += concurrency) {\n const chunk = inputs.slice(i, i + concurrency);\n const chunkResults = await Promise.all(\n chunk.map((inp) => this.present(inp)),\n );\n results.push(...chunkResults);\n }\n return results;\n }\n\n /**\n * Process multiple opportunities as home cards in parallel with bounded concurrency.\n * Returns full home-card display contracts (headline, body, narrator remark, action labels, mutual-intent label).\n */\n @Timed()\n public async presentHomeCardBatch(\n inputs: HomeCardPresenterInput[],\n options?: { concurrency?: number },\n ): Promise<HomeCardLLMResult[]> {\n const concurrency = options?.concurrency ?? 5;\n const results: HomeCardLLMResult[] = [];\n for (let i = 0; i < inputs.length; i += concurrency) {\n const chunk = inputs.slice(i, i + concurrency);\n const chunkResults = await Promise.all(\n chunk.map((inp) => this.presentHomeCard(inp)),\n );\n results.push(...chunkResults);\n }\n return results;\n }\n}\n\n// ──────────────────────────────────────────────────────────────\n// NEGOTIATION CONTEXT HELPERS\n// ──────────────────────────────────────────────────────────────\n\n/**\n * Builds a \"NEGOTIATION CONTEXT:\" block for the home-card prompt. Returns an\n * empty string when the opportunity has no meaningful negotiation context\n * (draft/latent) or when the opportunity is still negotiating (handled via\n * the templated chip, not the LLM).\n */\nfunction buildNegotiationPromptBlock(context: NegotiationContext | undefined): string {\n if (!context || context.status === 'negotiating') return \"\";\n\n const turnCapLabel = context.turnCap > 0 ? `${context.turnCap}` : \"unlimited\";\n const reason = context.outcome?.reason;\n const reasonLabel = reason === 'turn_cap'\n ? \"agents hit the turn cap without converging\"\n : reason === 'timeout'\n ? \"counterpart went silent before responding\"\n : undefined;\n\n const turnLines = (context.turns ?? []).map((turn, index) => {\n const action = turn.action;\n const reasoning = turn.assessment?.reasoning ?? \"(no reasoning)\";\n const message = turn.message ? ` — said: \"${turn.message}\"` : \"\";\n return `Turn ${index + 1} (${action}): ${reasoning}${message}`;\n });\n\n const outcomeSummary = context.outcome\n ? `Final outcome: ${context.outcome.hasOpportunity ? \"agreed\" : \"declined\"} — ${context.outcome.reasoning}`\n : \"Final outcome: not recorded.\";\n\n return `\nNEGOTIATION CONTEXT:\n- Negotiation status: ${context.status}${reasonLabel ? ` (${reasonLabel})` : \"\"}\n- Turns exchanged: ${context.turnCount} of ${turnCapLabel}\n- Transcript:\n${turnLines.length > 0 ? turnLines.map((l) => ` ${l}`).join(\"\\n\") : \" (no turns recorded)\"}\n- ${outcomeSummary}\n`;\n}\n\n/**\n * Builds a templated home-card result for an opportunity whose negotiation\n * is still in progress. Bypasses the LLM so users see a stable \"currently\n * negotiating\" chip while turns are still being exchanged.\n */\nfunction buildNegotiatingChip(input: HomeCardPresenterInput): HomeCardLLMResult {\n const ctx = input.negotiationContext;\n const turnCount = ctx?.turnCount ?? 0;\n const turnCap = ctx?.turnCap && ctx.turnCap > 0 ? ctx.turnCap : undefined;\n const narratorRemark = turnCap\n ? `Currently negotiating · turn ${turnCount} of ${turnCap}`\n : `Currently negotiating · turn ${turnCount}`;\n\n return {\n headline: \"Negotiation in progress\",\n 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.\",\n digestSummary: \"Your agent is still checking whether this connection makes sense.\",\n suggestedAction: \"Check back shortly — no action needed yet.\",\n narratorRemark,\n mutualIntentsLabel: input.mutualIntentCount && input.mutualIntentCount > 0\n ? `${input.mutualIntentCount} mutual intent${input.mutualIntentCount !== 1 ? \"s\" : \"\"}`\n : \"Shared interests\",\n greeting: \"\",\n };\n}\n\n// ──────────────────────────────────────────────────────────────\n// CONTEXT GATHERER (used by tools)\n// ──────────────────────────────────────────────────────────────\n\n/**\n * Gather all context needed for the presenter from the database.\n * Fetches viewer profile, viewer intents, other party profile(s), and index in parallel.\n *\n * @param displayCounterpartUserId - When set (e.g. for home card), only this counterpart is included in otherPartyContext so the presenter writes about the person on the card. Omitted for introducer view (card shows both parties).\n */\nexport async function gatherPresenterContext(\n database: PresenterDatabase,\n opportunity: Opportunity,\n viewerId: string,\n displayCounterpartUserId?: string,\n): Promise<PresenterInput> {\n const myActor = opportunity.actors.find((a) => a.userId === viewerId);\n if (!myActor) {\n throw new Error(\"Viewer is not an actor in this opportunity\");\n }\n\n const isIntroducer = myActor.role === \"introducer\";\n const otherActors = opportunity.actors.filter((a) => a.userId !== viewerId);\n let otherPartyIds = [...new Set(otherActors.map((a) => a.userId))];\n if (\n displayCounterpartUserId &&\n !isIntroducer &&\n otherPartyIds.includes(displayCounterpartUserId)\n ) {\n otherPartyIds = [displayCounterpartUserId];\n }\n\n const contextIndexId = opportunity.context?.networkId;\n\n // For introducers: fetch profiles + intents for both parties; skip introducer's own intents.\n // For other roles: fetch viewer's profile + intents and other party profiles.\n const [viewerProfile, indexRecord, ...otherProfiles] = await Promise.all([\n database.getProfile(viewerId),\n contextIndexId ? database.getNetwork(contextIndexId) : Promise.resolve(null),\n ...otherPartyIds.map((uid) => database.getProfile(uid)),\n ]);\n\n // Fetch intents: for introducer, fetch each party's intents; otherwise fetch viewer's intents.\n let viewerIntents:\n | Awaited<ReturnType<typeof database.getActiveIntents>>\n | undefined;\n let partyIntentsMap:\n | Map<string, Awaited<ReturnType<typeof database.getActiveIntents>>>\n | undefined;\n\n if (isIntroducer) {\n const partyIntentResults = await Promise.all(\n otherPartyIds.map(async (uid) => ({\n uid,\n intents: await database.getActiveIntents(uid),\n })),\n );\n partyIntentsMap = new Map(\n partyIntentResults.map((r) => [r.uid, r.intents]),\n );\n } else {\n viewerIntents = await database.getActiveIntents(viewerId);\n }\n\n // Fetch premises when any actor is premise-grounded\n const premiseGroundedActors = opportunity.actors.filter((a) => a.premise);\n let viewerPremiseContext = '';\n let otherPremiseContext = '';\n\n if (premiseGroundedActors.length > 0) {\n // Only fetch premises for actors that are actually premise-grounded, not all parties\n const groundedOtherIds = premiseGroundedActors\n .filter((a) => a.userId !== viewerId)\n .map((a) => a.userId);\n const viewerIsGrounded = premiseGroundedActors.some((a) => a.userId === viewerId);\n\n const results = await Promise.all([\n ...(viewerIsGrounded ? [database.getPremisesForUser(viewerId, 'ACTIVE')] : []),\n ...groundedOtherIds.map((uid) => database.getPremisesForUser(uid, 'ACTIVE')),\n ]);\n\n let idx = 0;\n if (viewerIsGrounded) {\n const viewerPremises = results[idx++];\n if (viewerPremises?.length) {\n viewerPremiseContext =\n '\\nPremises (self-descriptions):\\n' +\n viewerPremises\n .slice(0, 5)\n .map((p) => `- ${p.assertion.text}`)\n .join('\\n');\n }\n }\n\n const otherPremiseLines: string[] = [];\n for (let i = 0; i < groundedOtherIds.length; i++) {\n const premises = results[idx++];\n if (premises?.length) {\n for (const p of premises.slice(0, 3)) {\n otherPremiseLines.push(`- ${p.assertion.text}`);\n }\n }\n }\n if (otherPremiseLines.length > 0) {\n otherPremiseContext = '\\nPremises (self-descriptions):\\n' + otherPremiseLines.join('\\n');\n }\n }\n\n let viewerContext: string;\n let otherPartyContext: string;\n\n if (isIntroducer) {\n // Introducer view: minimal viewer context (just name + role), rich other-party context with intents\n const introducerApproved = opportunity.actors.find(a => a.role === 'introducer')?.approved === true;\n const hasApproved = introducerApproved || opportunity.status !== 'latent';\n viewerContext = [\n \"Profile:\",\n `Name: ${viewerProfile?.identity?.name ?? \"Unknown\"}`,\n hasApproved\n ? \"Role: You are the introducer who suggested this connection.\"\n : \"Role: You are being asked whether these two people would benefit from meeting. You have NOT yet approved this introduction.\",\n ].join(\"\\n\");\n\n const otherParts = otherPartyIds.map((uid, idx) => {\n const profile = otherProfiles[idx] as Awaited<\n ReturnType<typeof database.getProfile>\n >;\n const name = profile?.identity?.name ?? \"Unknown\";\n const bio = profile?.identity?.bio ?? \"\";\n const location = profile?.identity?.location ?? \"\";\n const context = profile?.context ?? \"\";\n const intents = partyIntentsMap?.get(uid);\n const intentLines = intents?.length\n ? intents\n .slice(0, 5)\n .map((i) => ` - ${i.payload}${i.summary ? ` (${i.summary})` : \"\"}`)\n : [\" (no active intents)\"];\n return [\n `${name}:`,\n ` Bio: ${bio}`,\n location ? ` Location: ${location}` : null,\n context ? ` Context: ${context}` : null,\n ` Active intents:`,\n ...intentLines,\n ]\n .filter(Boolean)\n .join(\"\\n\");\n });\n otherPartyContext =\n otherParts.join(\"\\n\\n\") || \"Parties (details not available).\";\n } else {\n // Non-introducer view: full viewer profile + intents, other party profiles\n const viewerContextLines = [\n \"Profile:\",\n `Name: ${viewerProfile?.identity?.name ?? \"Unknown\"}`,\n `Bio: ${viewerProfile?.identity?.bio ?? \"\"}`,\n `Location: ${viewerProfile?.identity?.location ?? \"\"}`,\n `Context: ${viewerProfile?.context ?? \"\"}`,\n \"Active intents:\",\n ...(viewerIntents?.length\n ? viewerIntents.map(\n (i) => `- ${i.payload}${i.summary ? ` (${i.summary})` : \"\"}`,\n )\n : [\"(none listed)\"]),\n ];\n viewerContext = viewerContextLines.join(\"\\n\");\n\n const otherParts = otherPartyIds.map((uid, idx) => {\n const profile = otherProfiles[idx] as Awaited<\n ReturnType<typeof database.getProfile>\n >;\n const name = profile?.identity?.name ?? \"Unknown\";\n const bio = profile?.identity?.bio ?? \"\";\n return `${name}: ${bio}`;\n });\n otherPartyContext =\n otherParts.join(\"\\n\\n\") || \"Other party (details not available).\";\n }\n\n const interp = opportunity.interpretation;\n const signalsSummary =\n interp.signals?.map((s) => `${s.type}: ${s.detail ?? s.type}`).join(\"; \") ??\n \"Match based on profile and intent alignment.\";\n\n // Detect introduction-originated opportunities: only when there is an explicit introducer actor.\n // Do NOT use detection.source === \"manual\" alone — system-discovered opportunities can have manual source without an introducer.\n const introducerActor = opportunity.actors.find(\n (a) => a.role === \"introducer\",\n );\n const isIntroduction = !!introducerActor;\n let introducerName: string | undefined;\n if (introducerActor) {\n introducerName = opportunity.detection.createdByName;\n if (!introducerName) {\n const introducerProfile = await database.getProfile(\n introducerActor.userId,\n );\n introducerName = introducerProfile?.identity?.name ?? undefined;\n }\n }\n\n const counterpartName =\n otherPartyIds.length === 1 && otherProfiles[0]\n ? (otherProfiles[0] as { identity?: { name?: string } })?.identity?.name?.trim()\n : undefined;\n const viewerNameForFilter = viewerProfile?.identity?.name?.trim();\n const matchReasoning =\n counterpartName && interp.reasoning\n ? viewerCentricCardSummary(\n interp.reasoning,\n counterpartName,\n 400,\n viewerNameForFilter,\n introducerName,\n )\n : stripUuids(interp.reasoning);\n\n if (viewerPremiseContext) {\n viewerContext += viewerPremiseContext;\n }\n if (otherPremiseContext) {\n otherPartyContext += otherPremiseContext;\n }\n\n const result: PresenterInput = {\n viewerContext,\n otherPartyContext,\n matchReasoning,\n category: interp.category ?? \"connection\",\n confidence:\n typeof interp.confidence === \"number\"\n ? interp.confidence\n : parseFloat(String(interp.confidence ?? 0)) || 0,\n signalsSummary,\n indexName: indexRecord?.title ?? contextIndexId ?? \"\",\n viewerRole: myActor.role ?? \"party\",\n isIntroduction,\n introducerName,\n };\n\n return result;\n}\n"]}
@@ -12,20 +12,14 @@ import type { DiscoveryNegotiation, DiscoverySummary } from "./question.prompt.j
12
12
  *
13
13
  * Following the intent graph pattern with Annotation-based state management.
14
14
  */
15
- /** Asker's profile shape (identity/narrative/attributes). Used by sourceProfile annotation. */
15
+ /** Asker's profile shape (identity + context). Used by sourceProfile annotation. */
16
16
  export interface SourceProfileData {
17
17
  identity?: {
18
18
  name?: string;
19
19
  bio?: string;
20
20
  location?: string;
21
21
  };
22
- narrative?: {
23
- context?: string;
24
- };
25
- attributes?: {
26
- skills?: string[];
27
- interests?: string[];
28
- };
22
+ context?: string;
29
23
  }
30
24
  /**
31
25
  * Indexed intent with hyde document (from prep node)
@@ -1 +1 @@
1
- {"version":3,"file":"opportunity.state.d.ts","sourceRoot":"/","sources":["opportunity/opportunity.state.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,4CAA4C,CAAC;AACrE,OAAO,KAAK,EAAE,iBAAiB,EAAE,WAAW,EAAE,MAAM,4CAA4C,CAAC;AACjG,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,4CAA4C,CAAC;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAClE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACtE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,gDAAgD,CAAC;AAC1F,OAAO,KAAK,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAEnF;;;;;;GAMG;AAEH,+FAA+F;AAC/F,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,EAAE;Q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QACvC,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE;KAClB,CAAC;IAEF;;;;;;;;OAQG;IACH,qBAAqB,EAAE,UAAU,CAAyB;QACxD,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QACnD,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE;KAClB,CAAC;IAEF,sFAAsF;IACtF,gBAAgB,EAAE,UAAU,CAA0B;QACpD,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,IAAI;QACtC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI;KACpB,CAAC;CACH,CAAC,CAAC","sourcesContent":["import { Annotation } from \"@langchain/langgraph\";\nimport type { Id } from '../shared/interfaces/database.interface.js';\nimport type { OpportunityStatus, Opportunity } from '../shared/interfaces/database.interface.js';\nimport type { Lens } from '../shared/interfaces/embedder.interface.js';\nimport type { EvaluatorEntity } from './opportunity.evaluator.js';\nimport type { DebugMetaAgent } from '../chat/chat-streaming.types.js';\nimport type { OpportunityEvidence } from '../shared/schemas/network-assignment.schema.js';\nimport type { DiscoveryNegotiation, DiscoverySummary } from \"./question.prompt.js\";\n\n/**\n * Opportunity Graph State (Linear Multi-Step Workflow)\n * \n * Flow: Prep → Scope → Discovery → Evaluation → Ranking → Persist → END\n * \n * Following the intent graph pattern with Annotation-based state management.\n */\n\n/** Asker's profile shape (identity/narrative/attributes). Used by sourceProfile annotation. */\nexport interface SourceProfileData {\n identity?: { name?: string; bio?: string; location?: string };\n narrative?: { context?: string };\n attributes?: { skills?: string[]; interests?: string[] };\n}\n\n/**\n * Indexed intent with hyde document (from prep node)\n */\nexport interface IndexedIntent {\n intentId: Id<'intents'>;\n payload: string;\n summary?: string;\n hydeDocumentId?: string;\n hydeEmbedding?: number[];\n indexes: Id<'networks'>[];\n}\n\n/**\n * Target index for search (from scope node)\n */\nexport interface TargetNetwork {\n networkId: Id<'networks'>;\n title: string;\n memberCount: number;\n}\n\n/**\n * Candidate match from discovery (semantic search).\n */\nexport interface CandidateMatch {\n candidateUserId: Id<'users'>;\n candidateIntentId?: Id<'intents'>;\n /** Source premise that produced this candidate (set when discoverySource is 'premise-similarity'). */\n sourcePremiseId?: Id<'premises'>;\n /** Candidate premise that matched this candidate (set for premise-based matches). */\n candidatePremiseId?: Id<'premises'>;\n /** Source context that produced this candidate (set when discoverySource is 'context-to-intent'). */\n sourceContextId?: string;\n networkId: Id<'networks'>;\n similarity: number;\n /** Free-text lens label that produced this match. */\n lens: string;\n candidatePayload: string;\n candidateSummary?: string;\n /** How this candidate was found: 'query' (HyDE from search text), 'premise-similarity', or 'context-to-intent'. */\n discoverySource?: 'query' | 'premise-similarity' | 'context-to-intent';\n /** Which discovery strategies found this candidate (set by mergeStrategyCandidates). */\n matchedStrategies?: string[];\n /** Typed evidence that explains why this candidate entered evaluation. */\n evidence?: OpportunityEvidence[];\n}\n\n/**\n * Evaluated candidate with LLM scoring (legacy; used when evaluator returns source/candidate pair).\n * candidateIntentId is set for intent matches; omitted for profile-only matches.\n */\nexport interface EvaluatedCandidate {\n sourceUserId: Id<'users'>;\n candidateUserId: Id<'users'>;\n sourceIntentId?: Id<'intents'>;\n candidateIntentId?: Id<'intents'>;\n networkId: Id<'networks'>;\n score: number; // 0-100\n reasoning: string; // Third-party analytical explanation of the match (for LLM agents)\n valencyRole: 'Agent' | 'Patient' | 'Peer';\n /** Free-text lens label that produced this match. */\n lens: string;\n}\n\n/**\n * Actor in an evaluated opportunity (from entity-bundle evaluator).\n * networkId is filled from the entity bundle in the graph, not by the evaluator.\n */\nexport interface EvaluatedOpportunityActor {\n userId: Id<'users'>;\n role: 'agent' | 'patient' | 'peer';\n intentId?: Id<'intents'>;\n networkId: Id<'networks'>;\n}\n\n/**\n * Evaluated opportunity with multi-actor output (entity-bundle evaluator).\n */\nexport interface EvaluatedOpportunity {\n actors: EvaluatedOpportunityActor[];\n score: number;\n reasoning: string;\n evidence?: OpportunityEvidence[];\n}\n\n/**\n * Which flow triggered this graph invocation. Determines initial persist status,\n * park-window timeout, streaming behavior, and whether AbortSignal is honored.\n *\n * - 'ambient' (default): queue-driven. Persists at the trigger default of\n * `pending` unless `options.initialStatus` overrides (the queue worker\n * passes `'latent'`, chat-bound ambient discovery passes `'draft'`). 5-min\n * park window, no streaming, ignores abort.\n * - 'orchestrator': chat-driven. Persists at the trigger default of\n * `negotiating` unless `options.initialStatus` overrides. 60s park window,\n * streams `opportunity_draft_ready` events, honors abort.\n *\n * See {@link resolveInitialStatus} for the exact fallback used when\n * `options.initialStatus` is undefined.\n */\nexport type OpportunityTrigger = 'ambient' | 'orchestrator';\n\n/**\n * Resolves the initial status for opportunities created in the persist node.\n *\n * Explicit `options.initialStatus` always wins (callers like the chat tool or\n * maintenance scripts override per-call). When the caller leaves it\n * undefined, the trigger drives the default:\n * - 'orchestrator' → 'negotiating' (chat-driven; negotiations run before the\n * user sees a draft card).\n * - 'ambient' (or any other trigger) → 'pending' (long-standing default for\n * queue- and intent-driven discovery).\n *\n * Lives here rather than in opportunity.graph.ts so unit tests can exercise\n * it without pulling in the full graph (and the evaluator's LLM requirements).\n *\n * @param trigger - The graph invocation's trigger\n * @param explicit - Caller-supplied initial status from options.initialStatus\n */\nexport function resolveInitialStatus(\n trigger: OpportunityTrigger,\n explicit: OpportunityStatus | undefined,\n): OpportunityStatus {\n if (explicit !== undefined) return explicit;\n return trigger === 'orchestrator' ? 'negotiating' : 'pending';\n}\n\n/**\n * Options passed to the graph\n */\nexport interface OpportunityGraphOptions {\n /** Initial status for created opportunities (default: 'pending') */\n initialStatus?: OpportunityStatus;\n /** Minimum score threshold (default: 50) */\n minScore?: number;\n /** Maximum opportunities to return (default: 20) */\n limit?: number;\n /** Pre-inferred lenses (if not provided, lens inference runs automatically in HyDE graph) */\n lenses?: Lens[];\n /** User's search query for HyDE generation */\n hydeDescription?: string;\n /** Existing opportunities summary for evaluator deduplication */\n existingOpportunities?: string;\n /** Chat session ID for draft opportunities; stored as context.conversationId for visibility filtering. */\n conversationId?: string;\n /**\n * MCP-only: cap the negotiate-phase wall-clock at this many milliseconds.\n * When set, `negotiateNode` races `negotiateCandidates(...)` against a timer;\n * if the timer wins, the node returns early with a `timed_out` trace and the\n * unawaited negotiation chains finalize each opp's DB status in the\n * background. Set to 20_000 by the MCP `discover_opportunities` handler.\n * Chat, ambient queue, and all other callers omit this — existing behavior.\n */\n negotiateTimeoutMs?: number;\n}\n\n/**\n * Opportunity Graph State Annotation\n */\nexport const OpportunityGraphState = Annotation.Root({\n // ─── Input Fields (Required) ───\n userId: Annotation<Id<'users'>>({\n reducer: (curr, next) => next ?? curr,\n default: () => '' as Id<'users'>,\n }),\n \n searchQuery: Annotation<string | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n \n networkId: Annotation<Id<'networks'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /**\n * Optional set of indexes discovery may search within (e.g. a network-scoped\n * agent's reachable indexes: the bound network plus the user's personal index).\n * The scope node intersects this with the user's actual memberships. Ignored\n * when `networkId` is set (single-network override). When unset, discovery\n * spans all of the user's networks.\n */\n indexScope: Annotation<Id<'networks'>[] | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Optional intent to use as discovery source and for triggeredBy. When set, used for search text (if query empty) and persist. */\n triggerIntentId: Annotation<Id<'intents'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Optional: restrict discovery to this specific user ID only (direct connection). */\n targetUserId: Annotation<Id<'users'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Optional: discover on behalf of this user (introducer flow). When set, prep/eval use this user's profile/intents; userId becomes the introducer. */\n onBehalfOfUserId: Annotation<Id<'users'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n options: Annotation<OpportunityGraphOptions>({\n reducer: (curr, next) => next ?? curr,\n default: () => ({}),\n }),\n\n /**\n * Which flow triggered this graph invocation. See {@link OpportunityTrigger}\n * for the exact branch behavior and {@link resolveInitialStatus} for the\n * persist default when `options.initialStatus` is unset.\n *\n * - 'ambient' (default): queue-driven, persist default `pending`, 5-min\n * park window, no streaming, ignores abort.\n * - 'orchestrator': chat-driven, persist default `negotiating`, 60s park\n * window, streams `opportunity_draft_ready` events, honors abort.\n */\n trigger: Annotation<OpportunityTrigger>({\n reducer: (curr, next) => next ?? curr,\n default: () => 'ambient',\n }),\n\n /**\n * Accepted opportunities the persist node discovered between the discoverer\n * and a candidate actor (same pair, status='accepted'). The orchestrator\n * branch populates this so the discover_opportunities tool (Task 7) can tell\n * the LLM \"these pairs are already connected, surface the existing chat\n * rather than creating a new draft\". Always empty for the ambient trigger.\n *\n * Left intentionally minimal — conversationId/URL resolution happens at\n * Start Chat time (Task 8), not here.\n */\n dedupAlreadyAccepted: Annotation<Array<{\n opportunityId: string;\n counterpartyUserId: string;\n }>>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /**\n * Operation mode controls graph flow:\n * - 'create': Existing discover pipeline (Prep → Scope → Discovery → Evaluation → Ranking → Persist)\n * - 'create_introduction': Introduction path (validation → evaluation → persist) for chat-driven intros\n * - 'continue_discovery': Pagination path (Prep → Evaluation → Ranking → Persist) using pre-loaded candidates\n * - 'read': List opportunities filtered by userId and optionally networkId (fast path)\n * - 'update': Change opportunity status (accept, reject, etc.)\n * - 'delete': Expire/archive an opportunity\n * - 'send': Promote latent opportunity to pending + queue notification\n * - 'negotiate_existing': Load an existing opportunity by opportunityId and run bilateral negotiation.\n * Used after introducer approval to trigger the normal negotiation flow.\n * - 'approve_introduction': Mark the caller as having approved a latent introducer opportunity,\n * then enqueue a negotiate_existing job for that opportunity.\n *\n * Defaults to 'create' for backward compatibility.\n */\n operationMode: Annotation<'create' | 'create_introduction' | 'continue_discovery' | 'read' | 'update' | 'delete' | 'send' | 'negotiate_existing' | 'approve_introduction'>({\n reducer: (curr, next) => next ?? curr,\n default: () => 'create' as const,\n }),\n\n /** Introduction mode: pre-gathered entities (profiles + intents per party). */\n introductionEntities: Annotation<EvaluatorEntity[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Introduction mode: optional hint from the introducer. */\n introductionHint: Annotation<string | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** When set (e.g. chat scope), networkId must match this. */\n requiredNetworkId: Annotation<Id<'networks'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Set by intro_evaluation; used by persist to build manual detection and introducer actor. */\n introductionContext: Annotation<{ createdByName?: string } | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Target opportunity ID for update/delete/send modes. */\n opportunityId: Annotation<string | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** New status for update mode (e.g. 'accepted', 'rejected'). */\n newStatus: Annotation<string | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n \n // ─── Intermediate Fields (Accumulated) ───\n \n /** User's indexed intents with hyde documents (from prep) */\n indexedIntents: Annotation<IndexedIntent[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n \n /** User's network memberships (from prep) */\n userNetworks: Annotation<Id<'networks'>[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n \n /** Target indexes to search within (from scope) */\n targetNetworks: Annotation<TargetNetwork[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Per-index relevancy scores for dedup tie-breaking. Background path: from intent_indexes. Chat path: transient from IntentIndexer. */\n indexRelevancyScores: Annotation<Record<string, number>>({\n reducer: (curr, next) => next ?? curr,\n default: () => ({}),\n }),\n\n /** Whether discovery used intent (path A) or profile (path B/C). Used by persist for triggeredBy. */\n discoverySource: Annotation<'intent' | 'profile'>({\n reducer: (curr, next) => next ?? curr,\n default: () => 'intent',\n }),\n\n /** Resolved intent ID used for this discovery run (when discoverySource is 'intent'). Set by intent-resolution. */\n resolvedTriggerIntentId: Annotation<Id<'intents'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Asker's profile (from prep). Used for profile-as-source discovery and evaluation. */\n sourceProfile: Annotation<SourceProfileData | null>({\n reducer: (curr, next) => next ?? curr,\n default: () => null,\n }),\n\n /** User's active premises with embeddings (from prep). Used for premise-to-premise discovery path D. */\n sourcePremises: Annotation<Array<{ premiseId: Id<'premises'>; embedding: number[] }>>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** User context embeddings per network (from prep). Used for context-to-intent discovery. */\n sourceContexts: Annotation<Array<{ contextId: string; networkId: Id<'networks'>; embedding: number[] }>>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Resolved intent is in at least one target index (path A vs C). */\n resolvedIntentInIndex: Annotation<boolean>({\n reducer: (curr, next) => next ?? curr,\n default: () => false,\n }),\n\n /** Create-intent signal: when true, tool should return createIntentSuggested so agent can auto-call create_intent. */\n createIntentSuggested: Annotation<boolean>({\n reducer: (curr, next) => next ?? curr,\n default: () => false,\n }),\n\n /** Suggested description for create_intent when createIntentSuggested is true. */\n suggestedIntentDescription: Annotation<string | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** HyDE embeddings per lens label (from discovery) */\n hydeEmbeddings: Annotation<Record<string, number[]>>({\n reducer: (curr, next) => next ?? curr,\n default: () => ({}),\n }),\n \n /** Candidate matches from semantic search (from discovery) */\n candidates: Annotation<CandidateMatch[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Candidates not yet evaluated (for pagination -- cached in Redis by caller). */\n remainingCandidates: Annotation<CandidateMatch[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Discovery session ID for pagination (maps to Redis cache key). */\n discoveryId: Annotation<string | null>({\n reducer: (curr, next) => next ?? curr,\n default: () => null,\n }),\n\n /** Evaluated candidates with scores (from evaluation; legacy) */\n evaluatedCandidates: Annotation<EvaluatedCandidate[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Evaluated opportunities with actors (from entity-bundle evaluator) */\n evaluatedOpportunities: Annotation<EvaluatedOpportunity[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n \n // ─── Output Fields (Overwrite per turn) ───\n \n /** Final ranked and persisted opportunities */\n opportunities: Annotation<Opportunity[]>({\n reducer: (curr, next) => next,\n default: () => [],\n }),\n\n /** Discovery path: pairs skipped because an opportunity already exists between viewer and candidate (no duplicate created). */\n existingBetweenActors: Annotation<Array<{\n candidateUserId: Id<'users'>;\n networkId: Id<'networks'>;\n existingOpportunityId?: Id<'opportunities'>;\n existingStatus?: OpportunityStatus;\n }>>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n \n /** Error message if any step fails */\n error: Annotation<string | undefined>({\n reducer: (curr, next) => next,\n default: () => undefined,\n }),\n\n /** Output for read mode: enriched list of opportunities. */\n readResult: Annotation<{\n count: number;\n message?: string;\n opportunities: Array<{\n id: string;\n indexName: string;\n connectedWith: string[];\n suggestedBy: string | null;\n reasoning: string;\n status: string;\n category: string;\n confidence: number | null;\n source: string | null;\n }>;\n } | undefined>({\n reducer: (curr, next) => next,\n default: () => undefined,\n }),\n\n /** Output for update/delete/send modes. */\n mutationResult: Annotation<{\n success: boolean;\n message?: string;\n opportunityId?: string;\n notified?: string[];\n conversationId?: string;\n error?: string;\n } | undefined>({\n reducer: (curr, next) => next,\n default: () => undefined,\n }),\n\n // ─── Trace Output ───\n\n /**\n * Accumulated trace entries from each graph node.\n * Used for observability: surfaces internal processing steps (search query, HyDE strategies,\n * candidates found, evaluation results) to the frontend.\n */\n trace: Annotation<Array<{ node: string; detail?: string; data?: Record<string, unknown> }>>({\n reducer: (curr, next) => [...curr, ...(next || [])],\n default: () => [],\n }),\n\n /** Timing records for each agent invocation within this graph run. */\n agentTimings: Annotation<DebugMetaAgent[]>({\n reducer: (acc, val) => [...acc, ...val],\n default: () => [],\n }),\n\n /**\n * Per-candidate negotiation records captured by `negotiateNode`. Populated\n * regardless of accept/reject so the question generator sees a complete\n * picture. Populated for ALL triggers (ambient + orchestrator) since the\n * negotiate node's `onCandidateResolved` hook is unconditional; only the\n * orchestrator streaming side-effects (opportunity_draft_ready emission)\n * are trigger-gated. Empty when the negotiate node was skipped (no\n * opportunities to negotiate).\n */\n discoveryNegotiations: Annotation<DiscoveryNegotiation[]>({\n reducer: (curr, next) => [...curr, ...(next || [])],\n default: () => [],\n }),\n\n /** Aggregate counters across `discoveryNegotiations`. Built in the negotiate node. */\n discoverySummary: Annotation<DiscoverySummary | null>({\n reducer: (_curr, next) => next ?? null,\n default: () => null,\n }),\n});\n"]}
1
+ {"version":3,"file":"opportunity.state.js","sourceRoot":"/","sources":["opportunity/opportunity.state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AA6HlD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,oBAAoB,CAClC,OAA2B,EAC3B,QAAuC;IAEvC,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC;IAC5C,OAAO,OAAO,KAAK,cAAc,CAAC,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC;AAChE,CAAC;AA+BD;;GAEG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,UAAU,CAAC,IAAI,CAAC;IACnD,kCAAkC;IAClC,MAAM,EAAE,UAAU,CAAc;QAC9B,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,IAAI;QACrC,OAAO,EAAE,GAAG,EAAE,CAAC,EAAiB;KACjC,CAAC;IAEF,WAAW,EAAE,UAAU,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GAAG,EAAE,CAAC,EAAE;KAClB,CAAC;IAEF;;;;;;;;OAQG;IACH,qBAAqB,EAAE,UAAU,CAAyB;QACxD,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAC,GAAG,IAAI,EAAE,GAAG,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC;QACnD,OAAO,EAAE,GAAG,EAAE,CAAC,EAAE;KAClB,CAAC;IAEF,sFAAsF;IACtF,gBAAgB,EAAE,UAAU,CAA0B;QACpD,OAAO,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,IAAI;QACtC,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI;KACpB,CAAC;CACH,CAAC,CAAC","sourcesContent":["import { Annotation } from \"@langchain/langgraph\";\nimport type { Id } from '../shared/interfaces/database.interface.js';\nimport type { OpportunityStatus, Opportunity } from '../shared/interfaces/database.interface.js';\nimport type { Lens } from '../shared/interfaces/embedder.interface.js';\nimport type { EvaluatorEntity } from './opportunity.evaluator.js';\nimport type { DebugMetaAgent } from '../chat/chat-streaming.types.js';\nimport type { OpportunityEvidence } from '../shared/schemas/network-assignment.schema.js';\nimport type { DiscoveryNegotiation, DiscoverySummary } from \"./question.prompt.js\";\n\n/**\n * Opportunity Graph State (Linear Multi-Step Workflow)\n * \n * Flow: Prep → Scope → Discovery → Evaluation → Ranking → Persist → END\n * \n * Following the intent graph pattern with Annotation-based state management.\n */\n\n/** Asker's profile shape (identity + context). Used by sourceProfile annotation. */\nexport interface SourceProfileData {\n identity?: { name?: string; bio?: string; location?: string };\n context?: string;\n}\n\n/**\n * Indexed intent with hyde document (from prep node)\n */\nexport interface IndexedIntent {\n intentId: Id<'intents'>;\n payload: string;\n summary?: string;\n hydeDocumentId?: string;\n hydeEmbedding?: number[];\n indexes: Id<'networks'>[];\n}\n\n/**\n * Target index for search (from scope node)\n */\nexport interface TargetNetwork {\n networkId: Id<'networks'>;\n title: string;\n memberCount: number;\n}\n\n/**\n * Candidate match from discovery (semantic search).\n */\nexport interface CandidateMatch {\n candidateUserId: Id<'users'>;\n candidateIntentId?: Id<'intents'>;\n /** Source premise that produced this candidate (set when discoverySource is 'premise-similarity'). */\n sourcePremiseId?: Id<'premises'>;\n /** Candidate premise that matched this candidate (set for premise-based matches). */\n candidatePremiseId?: Id<'premises'>;\n /** Source context that produced this candidate (set when discoverySource is 'context-to-intent'). */\n sourceContextId?: string;\n networkId: Id<'networks'>;\n similarity: number;\n /** Free-text lens label that produced this match. */\n lens: string;\n candidatePayload: string;\n candidateSummary?: string;\n /** How this candidate was found: 'query' (HyDE from search text), 'premise-similarity', or 'context-to-intent'. */\n discoverySource?: 'query' | 'premise-similarity' | 'context-to-intent';\n /** Which discovery strategies found this candidate (set by mergeStrategyCandidates). */\n matchedStrategies?: string[];\n /** Typed evidence that explains why this candidate entered evaluation. */\n evidence?: OpportunityEvidence[];\n}\n\n/**\n * Evaluated candidate with LLM scoring (legacy; used when evaluator returns source/candidate pair).\n * candidateIntentId is set for intent matches; omitted for profile-only matches.\n */\nexport interface EvaluatedCandidate {\n sourceUserId: Id<'users'>;\n candidateUserId: Id<'users'>;\n sourceIntentId?: Id<'intents'>;\n candidateIntentId?: Id<'intents'>;\n networkId: Id<'networks'>;\n score: number; // 0-100\n reasoning: string; // Third-party analytical explanation of the match (for LLM agents)\n valencyRole: 'Agent' | 'Patient' | 'Peer';\n /** Free-text lens label that produced this match. */\n lens: string;\n}\n\n/**\n * Actor in an evaluated opportunity (from entity-bundle evaluator).\n * networkId is filled from the entity bundle in the graph, not by the evaluator.\n */\nexport interface EvaluatedOpportunityActor {\n userId: Id<'users'>;\n role: 'agent' | 'patient' | 'peer';\n intentId?: Id<'intents'>;\n networkId: Id<'networks'>;\n}\n\n/**\n * Evaluated opportunity with multi-actor output (entity-bundle evaluator).\n */\nexport interface EvaluatedOpportunity {\n actors: EvaluatedOpportunityActor[];\n score: number;\n reasoning: string;\n evidence?: OpportunityEvidence[];\n}\n\n/**\n * Which flow triggered this graph invocation. Determines initial persist status,\n * park-window timeout, streaming behavior, and whether AbortSignal is honored.\n *\n * - 'ambient' (default): queue-driven. Persists at the trigger default of\n * `pending` unless `options.initialStatus` overrides (the queue worker\n * passes `'latent'`, chat-bound ambient discovery passes `'draft'`). 5-min\n * park window, no streaming, ignores abort.\n * - 'orchestrator': chat-driven. Persists at the trigger default of\n * `negotiating` unless `options.initialStatus` overrides. 60s park window,\n * streams `opportunity_draft_ready` events, honors abort.\n *\n * See {@link resolveInitialStatus} for the exact fallback used when\n * `options.initialStatus` is undefined.\n */\nexport type OpportunityTrigger = 'ambient' | 'orchestrator';\n\n/**\n * Resolves the initial status for opportunities created in the persist node.\n *\n * Explicit `options.initialStatus` always wins (callers like the chat tool or\n * maintenance scripts override per-call). When the caller leaves it\n * undefined, the trigger drives the default:\n * - 'orchestrator' → 'negotiating' (chat-driven; negotiations run before the\n * user sees a draft card).\n * - 'ambient' (or any other trigger) → 'pending' (long-standing default for\n * queue- and intent-driven discovery).\n *\n * Lives here rather than in opportunity.graph.ts so unit tests can exercise\n * it without pulling in the full graph (and the evaluator's LLM requirements).\n *\n * @param trigger - The graph invocation's trigger\n * @param explicit - Caller-supplied initial status from options.initialStatus\n */\nexport function resolveInitialStatus(\n trigger: OpportunityTrigger,\n explicit: OpportunityStatus | undefined,\n): OpportunityStatus {\n if (explicit !== undefined) return explicit;\n return trigger === 'orchestrator' ? 'negotiating' : 'pending';\n}\n\n/**\n * Options passed to the graph\n */\nexport interface OpportunityGraphOptions {\n /** Initial status for created opportunities (default: 'pending') */\n initialStatus?: OpportunityStatus;\n /** Minimum score threshold (default: 50) */\n minScore?: number;\n /** Maximum opportunities to return (default: 20) */\n limit?: number;\n /** Pre-inferred lenses (if not provided, lens inference runs automatically in HyDE graph) */\n lenses?: Lens[];\n /** User's search query for HyDE generation */\n hydeDescription?: string;\n /** Existing opportunities summary for evaluator deduplication */\n existingOpportunities?: string;\n /** Chat session ID for draft opportunities; stored as context.conversationId for visibility filtering. */\n conversationId?: string;\n /**\n * MCP-only: cap the negotiate-phase wall-clock at this many milliseconds.\n * When set, `negotiateNode` races `negotiateCandidates(...)` against a timer;\n * if the timer wins, the node returns early with a `timed_out` trace and the\n * unawaited negotiation chains finalize each opp's DB status in the\n * background. Set to 20_000 by the MCP `discover_opportunities` handler.\n * Chat, ambient queue, and all other callers omit this — existing behavior.\n */\n negotiateTimeoutMs?: number;\n}\n\n/**\n * Opportunity Graph State Annotation\n */\nexport const OpportunityGraphState = Annotation.Root({\n // ─── Input Fields (Required) ───\n userId: Annotation<Id<'users'>>({\n reducer: (curr, next) => next ?? curr,\n default: () => '' as Id<'users'>,\n }),\n \n searchQuery: Annotation<string | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n \n networkId: Annotation<Id<'networks'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /**\n * Optional set of indexes discovery may search within (e.g. a network-scoped\n * agent's reachable indexes: the bound network plus the user's personal index).\n * The scope node intersects this with the user's actual memberships. Ignored\n * when `networkId` is set (single-network override). When unset, discovery\n * spans all of the user's networks.\n */\n indexScope: Annotation<Id<'networks'>[] | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Optional intent to use as discovery source and for triggeredBy. When set, used for search text (if query empty) and persist. */\n triggerIntentId: Annotation<Id<'intents'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Optional: restrict discovery to this specific user ID only (direct connection). */\n targetUserId: Annotation<Id<'users'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Optional: discover on behalf of this user (introducer flow). When set, prep/eval use this user's profile/intents; userId becomes the introducer. */\n onBehalfOfUserId: Annotation<Id<'users'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n options: Annotation<OpportunityGraphOptions>({\n reducer: (curr, next) => next ?? curr,\n default: () => ({}),\n }),\n\n /**\n * Which flow triggered this graph invocation. See {@link OpportunityTrigger}\n * for the exact branch behavior and {@link resolveInitialStatus} for the\n * persist default when `options.initialStatus` is unset.\n *\n * - 'ambient' (default): queue-driven, persist default `pending`, 5-min\n * park window, no streaming, ignores abort.\n * - 'orchestrator': chat-driven, persist default `negotiating`, 60s park\n * window, streams `opportunity_draft_ready` events, honors abort.\n */\n trigger: Annotation<OpportunityTrigger>({\n reducer: (curr, next) => next ?? curr,\n default: () => 'ambient',\n }),\n\n /**\n * Accepted opportunities the persist node discovered between the discoverer\n * and a candidate actor (same pair, status='accepted'). The orchestrator\n * branch populates this so the discover_opportunities tool (Task 7) can tell\n * the LLM \"these pairs are already connected, surface the existing chat\n * rather than creating a new draft\". Always empty for the ambient trigger.\n *\n * Left intentionally minimal — conversationId/URL resolution happens at\n * Start Chat time (Task 8), not here.\n */\n dedupAlreadyAccepted: Annotation<Array<{\n opportunityId: string;\n counterpartyUserId: string;\n }>>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /**\n * Operation mode controls graph flow:\n * - 'create': Existing discover pipeline (Prep → Scope → Discovery → Evaluation → Ranking → Persist)\n * - 'create_introduction': Introduction path (validation → evaluation → persist) for chat-driven intros\n * - 'continue_discovery': Pagination path (Prep → Evaluation → Ranking → Persist) using pre-loaded candidates\n * - 'read': List opportunities filtered by userId and optionally networkId (fast path)\n * - 'update': Change opportunity status (accept, reject, etc.)\n * - 'delete': Expire/archive an opportunity\n * - 'send': Promote latent opportunity to pending + queue notification\n * - 'negotiate_existing': Load an existing opportunity by opportunityId and run bilateral negotiation.\n * Used after introducer approval to trigger the normal negotiation flow.\n * - 'approve_introduction': Mark the caller as having approved a latent introducer opportunity,\n * then enqueue a negotiate_existing job for that opportunity.\n *\n * Defaults to 'create' for backward compatibility.\n */\n operationMode: Annotation<'create' | 'create_introduction' | 'continue_discovery' | 'read' | 'update' | 'delete' | 'send' | 'negotiate_existing' | 'approve_introduction'>({\n reducer: (curr, next) => next ?? curr,\n default: () => 'create' as const,\n }),\n\n /** Introduction mode: pre-gathered entities (profiles + intents per party). */\n introductionEntities: Annotation<EvaluatorEntity[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Introduction mode: optional hint from the introducer. */\n introductionHint: Annotation<string | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** When set (e.g. chat scope), networkId must match this. */\n requiredNetworkId: Annotation<Id<'networks'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Set by intro_evaluation; used by persist to build manual detection and introducer actor. */\n introductionContext: Annotation<{ createdByName?: string } | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Target opportunity ID for update/delete/send modes. */\n opportunityId: Annotation<string | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** New status for update mode (e.g. 'accepted', 'rejected'). */\n newStatus: Annotation<string | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n \n // ─── Intermediate Fields (Accumulated) ───\n \n /** User's indexed intents with hyde documents (from prep) */\n indexedIntents: Annotation<IndexedIntent[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n \n /** User's network memberships (from prep) */\n userNetworks: Annotation<Id<'networks'>[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n \n /** Target indexes to search within (from scope) */\n targetNetworks: Annotation<TargetNetwork[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Per-index relevancy scores for dedup tie-breaking. Background path: from intent_indexes. Chat path: transient from IntentIndexer. */\n indexRelevancyScores: Annotation<Record<string, number>>({\n reducer: (curr, next) => next ?? curr,\n default: () => ({}),\n }),\n\n /** Whether discovery used intent (path A) or profile (path B/C). Used by persist for triggeredBy. */\n discoverySource: Annotation<'intent' | 'profile'>({\n reducer: (curr, next) => next ?? curr,\n default: () => 'intent',\n }),\n\n /** Resolved intent ID used for this discovery run (when discoverySource is 'intent'). Set by intent-resolution. */\n resolvedTriggerIntentId: Annotation<Id<'intents'> | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** Asker's profile (from prep). Used for profile-as-source discovery and evaluation. */\n sourceProfile: Annotation<SourceProfileData | null>({\n reducer: (curr, next) => next ?? curr,\n default: () => null,\n }),\n\n /** User's active premises with embeddings (from prep). Used for premise-to-premise discovery path D. */\n sourcePremises: Annotation<Array<{ premiseId: Id<'premises'>; embedding: number[] }>>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** User context embeddings per network (from prep). Used for context-to-intent discovery. */\n sourceContexts: Annotation<Array<{ contextId: string; networkId: Id<'networks'>; embedding: number[] }>>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Resolved intent is in at least one target index (path A vs C). */\n resolvedIntentInIndex: Annotation<boolean>({\n reducer: (curr, next) => next ?? curr,\n default: () => false,\n }),\n\n /** Create-intent signal: when true, tool should return createIntentSuggested so agent can auto-call create_intent. */\n createIntentSuggested: Annotation<boolean>({\n reducer: (curr, next) => next ?? curr,\n default: () => false,\n }),\n\n /** Suggested description for create_intent when createIntentSuggested is true. */\n suggestedIntentDescription: Annotation<string | undefined>({\n reducer: (curr, next) => next ?? curr,\n default: () => undefined,\n }),\n\n /** HyDE embeddings per lens label (from discovery) */\n hydeEmbeddings: Annotation<Record<string, number[]>>({\n reducer: (curr, next) => next ?? curr,\n default: () => ({}),\n }),\n \n /** Candidate matches from semantic search (from discovery) */\n candidates: Annotation<CandidateMatch[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Candidates not yet evaluated (for pagination -- cached in Redis by caller). */\n remainingCandidates: Annotation<CandidateMatch[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Discovery session ID for pagination (maps to Redis cache key). */\n discoveryId: Annotation<string | null>({\n reducer: (curr, next) => next ?? curr,\n default: () => null,\n }),\n\n /** Evaluated candidates with scores (from evaluation; legacy) */\n evaluatedCandidates: Annotation<EvaluatedCandidate[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n\n /** Evaluated opportunities with actors (from entity-bundle evaluator) */\n evaluatedOpportunities: Annotation<EvaluatedOpportunity[]>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n \n // ─── Output Fields (Overwrite per turn) ───\n \n /** Final ranked and persisted opportunities */\n opportunities: Annotation<Opportunity[]>({\n reducer: (curr, next) => next,\n default: () => [],\n }),\n\n /** Discovery path: pairs skipped because an opportunity already exists between viewer and candidate (no duplicate created). */\n existingBetweenActors: Annotation<Array<{\n candidateUserId: Id<'users'>;\n networkId: Id<'networks'>;\n existingOpportunityId?: Id<'opportunities'>;\n existingStatus?: OpportunityStatus;\n }>>({\n reducer: (curr, next) => next ?? curr,\n default: () => [],\n }),\n \n /** Error message if any step fails */\n error: Annotation<string | undefined>({\n reducer: (curr, next) => next,\n default: () => undefined,\n }),\n\n /** Output for read mode: enriched list of opportunities. */\n readResult: Annotation<{\n count: number;\n message?: string;\n opportunities: Array<{\n id: string;\n indexName: string;\n connectedWith: string[];\n suggestedBy: string | null;\n reasoning: string;\n status: string;\n category: string;\n confidence: number | null;\n source: string | null;\n }>;\n } | undefined>({\n reducer: (curr, next) => next,\n default: () => undefined,\n }),\n\n /** Output for update/delete/send modes. */\n mutationResult: Annotation<{\n success: boolean;\n message?: string;\n opportunityId?: string;\n notified?: string[];\n conversationId?: string;\n error?: string;\n } | undefined>({\n reducer: (curr, next) => next,\n default: () => undefined,\n }),\n\n // ─── Trace Output ───\n\n /**\n * Accumulated trace entries from each graph node.\n * Used for observability: surfaces internal processing steps (search query, HyDE strategies,\n * candidates found, evaluation results) to the frontend.\n */\n trace: Annotation<Array<{ node: string; detail?: string; data?: Record<string, unknown> }>>({\n reducer: (curr, next) => [...curr, ...(next || [])],\n default: () => [],\n }),\n\n /** Timing records for each agent invocation within this graph run. */\n agentTimings: Annotation<DebugMetaAgent[]>({\n reducer: (acc, val) => [...acc, ...val],\n default: () => [],\n }),\n\n /**\n * Per-candidate negotiation records captured by `negotiateNode`. Populated\n * regardless of accept/reject so the question generator sees a complete\n * picture. Populated for ALL triggers (ambient + orchestrator) since the\n * negotiate node's `onCandidateResolved` hook is unconditional; only the\n * orchestrator streaming side-effects (opportunity_draft_ready emission)\n * are trigger-gated. Empty when the negotiate node was skipped (no\n * opportunities to negotiate).\n */\n discoveryNegotiations: Annotation<DiscoveryNegotiation[]>({\n reducer: (curr, next) => [...curr, ...(next || [])],\n default: () => [],\n }),\n\n /** Aggregate counters across `discoveryNegotiations`. Built in the negotiate node. */\n discoverySummary: Annotation<DiscoverySummary | null>({\n reducer: (_curr, next) => next ?? null,\n default: () => null,\n }),\n});\n"]}
@@ -205,7 +205,7 @@ const presets = {
205
205
  systemPrompt: INTENT_SYSTEM_PROMPT,
206
206
  buildPrompt: (context) => buildIntentPrompt(context),
207
207
  },
208
- profile: {
208
+ enrichment: {
209
209
  systemPrompt: PROFILE_SYSTEM_PROMPT,
210
210
  buildPrompt: (context) => buildProfilePrompt(context),
211
211
  },