@indexnetwork/protocol 3.6.3 → 3.6.4
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.
- package/README.md +90 -26
- package/dist/agent/tests/fakes.d.ts.map +1 -1
- package/dist/agent/tests/fakes.js.map +1 -1
- package/dist/chat/chat.agent.d.ts.map +1 -1
- package/dist/chat/chat.agent.js +3 -3
- package/dist/chat/chat.agent.js.map +1 -1
- package/dist/chat/chat.streamer.d.ts.map +1 -1
- package/dist/chat/chat.streamer.js +1 -1
- package/dist/chat/chat.streamer.js.map +1 -1
- package/dist/chat/chat.summarizer.d.ts.map +1 -1
- package/dist/chat/chat.summarizer.js +1 -1
- package/dist/chat/chat.summarizer.js.map +1 -1
- package/dist/chat/tests/chat.graph.mocks.d.ts.map +1 -1
- package/dist/chat/tests/chat.graph.mocks.js +0 -1
- package/dist/chat/tests/chat.graph.mocks.js.map +1 -1
- package/dist/index.d.ts +21 -21
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -10
- package/dist/index.js.map +1 -1
- package/dist/intent/intent.graph.js +1 -1
- package/dist/intent/intent.graph.js.map +1 -1
- package/dist/maintenance/maintenance.graph.d.ts.map +1 -1
- package/dist/maintenance/maintenance.graph.js +1 -1
- package/dist/maintenance/maintenance.graph.js.map +1 -1
- package/dist/negotiation/negotiation.agent.d.ts.map +1 -1
- package/dist/negotiation/negotiation.agent.js +1 -1
- package/dist/negotiation/negotiation.agent.js.map +1 -1
- package/dist/negotiation/negotiation.summarizer.d.ts.map +1 -1
- package/dist/negotiation/negotiation.summarizer.js +1 -1
- package/dist/negotiation/negotiation.summarizer.js.map +1 -1
- package/dist/network/indexer/indexer.graph.d.ts.map +1 -1
- package/dist/network/indexer/indexer.graph.js +2 -2
- package/dist/network/indexer/indexer.graph.js.map +1 -1
- package/dist/opportunity/discovery-question.helper.d.ts.map +1 -1
- package/dist/opportunity/discovery-question.helper.js.map +1 -1
- package/dist/opportunity/feed/feed.graph.d.ts.map +1 -1
- package/dist/opportunity/feed/feed.graph.js +1 -1
- package/dist/opportunity/feed/feed.graph.js.map +1 -1
- package/dist/opportunity/negotiation-summary.builder.d.ts.map +1 -1
- package/dist/opportunity/negotiation-summary.builder.js.map +1 -1
- package/dist/opportunity/opportunity.discover.d.ts.map +1 -1
- package/dist/opportunity/opportunity.discover.js +1 -1
- package/dist/opportunity/opportunity.discover.js.map +1 -1
- package/dist/opportunity/opportunity.enricher.d.ts.map +1 -1
- package/dist/opportunity/opportunity.enricher.js.map +1 -1
- package/dist/opportunity/opportunity.graph.d.ts.map +1 -1
- package/dist/opportunity/opportunity.graph.js +5 -5
- package/dist/opportunity/opportunity.graph.js.map +1 -1
- package/dist/opportunity/opportunity.persist.d.ts.map +1 -1
- package/dist/opportunity/opportunity.persist.js.map +1 -1
- package/dist/opportunity/opportunity.presentation.d.ts +9 -0
- package/dist/opportunity/opportunity.presentation.d.ts.map +1 -1
- package/dist/opportunity/opportunity.presentation.js +23 -0
- package/dist/opportunity/opportunity.presentation.js.map +1 -1
- package/dist/opportunity/opportunity.presenter.d.ts.map +1 -1
- package/dist/opportunity/opportunity.presenter.js +9 -3
- package/dist/opportunity/opportunity.presenter.js.map +1 -1
- package/dist/opportunity/question.generator.d.ts.map +1 -1
- package/dist/opportunity/question.generator.js +2 -2
- package/dist/opportunity/question.generator.js.map +1 -1
- package/dist/premise/premise.graph.d.ts.map +1 -1
- package/dist/premise/premise.graph.js +1 -1
- package/dist/premise/premise.graph.js.map +1 -1
- package/dist/profile/profile.graph.js +1 -1
- package/dist/profile/profile.graph.js.map +1 -1
- package/dist/questioner/questioner.agent.d.ts.map +1 -1
- package/dist/questioner/questioner.agent.js +1 -1
- package/dist/questioner/questioner.agent.js.map +1 -1
- package/dist/questioner/questioner.presets.d.ts.map +1 -1
- package/dist/questioner/questioner.presets.js +1 -1
- package/dist/questioner/questioner.presets.js.map +1 -1
- package/dist/shared/agent/response.streamer.d.ts.map +1 -1
- package/dist/shared/agent/response.streamer.js +1 -1
- package/dist/shared/agent/response.streamer.js.map +1 -1
- package/dist/shared/agent/tool.factory.d.ts.map +1 -1
- package/dist/shared/agent/tool.factory.js +1 -1
- package/dist/shared/agent/tool.factory.js.map +1 -1
- package/dist/shared/agent/tool.helpers.d.ts.map +1 -1
- package/dist/shared/agent/tool.helpers.js.map +1 -1
- package/dist/shared/assignment/network-assignment.policy.d.ts.map +1 -1
- package/dist/shared/assignment/network-assignment.policy.js.map +1 -1
- package/dist/shared/interfaces/questioner.interface.d.ts.map +1 -1
- package/dist/shared/interfaces/questioner.interface.js.map +1 -1
- package/package.json +1 -1
|
@@ -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,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,MAAM,+BAA+B,CAAC;AAWpF,MAAM,MAAM,GAAG,cAAc,CAAC,sBAAsB,CAAC,CAAC;AACtD,MAAM,cAAc,GAAG,KAAM,CAAC;AAE9B,MAAM,KAAK,GAAG,WAAW,CAAC,sBAAsB,CAAC,CAAC;AAElD,MAAM,oBAAoB,GACxB,+XAA+X,CAAC;AAElY,iEAAiE;AACjE,iBAAiB;AACjB,iEAAiE;AAEjE,MAAM,kBAAkB,GAAG,CAAC,CAAC,MAAM,CAAC;IAClC,QAAQ,EAAE,CAAC;SACR,MAA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AAE,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 } 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 message,\n timeoutReason,\n },\n );\n return {\n headline: \"A promising connection\",\n personalizedSummary: stripUuids(input.matchReasoning.slice(0, 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 message,\n timeoutReason,\n },\n );\n let fallbackSummary = stripUuids(input.matchReasoning.slice(0, 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,EA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AAwB,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"question.generator.d.ts","sourceRoot":"/","sources":["opportunity/question.generator.ts"],"names":[],"mappings":"AAkBA,OAAO,
|
|
1
|
+
{"version":3,"file":"question.generator.d.ts","sourceRoot":"/","sources":["opportunity/question.generator.ts"],"names":[],"mappings":"AAkBA,OAAO,EAAkD,KAAK,wBAAwB,EAAoD,MAAM,sCAAsC,CAAC;AAKvL,OAAO,EAAsC,KAAK,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAOvG,oFAAoF;AACpF,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,KAAK,CAAiD;;IAS9D;;;;;;;;;;OAUG;IAEG,QAAQ,CACZ,KAAK,EAAE,sBAAsB,EAC7B,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE,GACjC,OAAO,CAAC,wBAAwB,GAAG,IAAI,CAAC;CAyC5C"}
|
|
@@ -8,12 +8,12 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { HumanMessage, SystemMessage } from "@langchain/core/messages";
|
|
11
|
-
import { QuestionGeneratorResponseSchema
|
|
11
|
+
import { QuestionGeneratorResponseSchema } from "../shared/schemas/question.schema.js";
|
|
12
12
|
import { createModel } from "../shared/agent/model.config.js";
|
|
13
13
|
import { invokeWithAbortSignal } from "../shared/agent/model-signal.js";
|
|
14
14
|
import { protocolLogger } from "../shared/observability/protocol.logger.js";
|
|
15
15
|
import { Timed } from "../shared/observability/performance.js";
|
|
16
|
-
import { SYSTEM_PROMPT, buildQuestionPrompt
|
|
16
|
+
import { SYSTEM_PROMPT, buildQuestionPrompt } from "./question.prompt.js";
|
|
17
17
|
const logger = protocolLogger("QuestionGenerator");
|
|
18
18
|
/** Maximum same-strategy questions allowed in a single emission. */
|
|
19
19
|
const MAX_SAME_STRATEGY = 2;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"question.generator.js","sourceRoot":"/","sources":["opportunity/question.generator.ts"],"names":[],"mappings":";;;;;;;;;AAgBA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEvE,OAAO,
|
|
1
|
+
{"version":3,"file":"question.generator.js","sourceRoot":"/","sources":["opportunity/question.generator.ts"],"names":[],"mappings":";;;;;;;;;AAgBA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEvE,OAAO,EAAE,+BAA+B,EAAkG,MAAM,sCAAsC,CAAC;AACvL,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAC9D,OAAO,EAAE,qBAAqB,EAAE,MAAM,iCAAiC,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAC;AAC5E,OAAO,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAC/D,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAA+B,MAAM,sBAAsB,CAAC;AAEvG,MAAM,MAAM,GAAG,cAAc,CAAC,mBAAmB,CAAC,CAAC;AAEnD,oEAAoE;AACpE,MAAM,iBAAiB,GAAG,CAAC,CAAC;AAE5B,oFAAoF;AACpF,MAAM,OAAO,iBAAiB;IAG5B;QACE,MAAM,GAAG,GAAG,WAAW,CAAC,4BAA4B,CAAC,CAAC;QACtD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4B,CAAC;IACnD,MAAM,GAAG,GAA2B,EAAE,CAAC;IACvC,KAAK,MAAM,CAAC,IAAI,SAAS,EAAE,CAAC;QAC1B,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,IAAI,iBAAiB;YAAE,SAAS;QACrC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;QAC9B,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;IACd,CAAC;IACD,OAAO,GAAG,CAAC;AACb,CAAC;AAED,SAAS,aAAa,CAAC,CAAuB;IAC5C,MAAM,EAAE,QAAQ,EAAE,SAAS,EAAE,GAAG,WAAW,EAAE,GAAG,CAAC,CAAC;IAClD,OAAO,WAAW,CAAC;AACrB,CAAC","sourcesContent":["/**\n * @deprecated Use QuestionerAgent instead. Will be removed in a future version.\n *\n * QuestionGenerator — pure LLM pass that turns a structured DiscoveryQuestionInput\n * into 0–3 decision questions. No DB, no events, no caller wired here; Slice 3\n * (opportunity.discover.ts) is the first consumer.\n *\n * Flow:\n * 1. buildQuestionPrompt(input) → user message string.\n * 2. model.invoke([system, user]) returns a structured payload.\n * 3. safeParse via QuestionGeneratorResponseSchema → null on failure.\n * 4. Guardrails: dedup by title, then strategy-diversity (never 3 same).\n * 5. If empty, return null. Otherwise split into public Question[] + parallel\n * QuestionStrategy[] (debug-only; strategy is NEVER on the public shape).\n */\nimport type { ChatOpenAI } from \"@langchain/openai\";\nimport { HumanMessage, SystemMessage } from \"@langchain/core/messages\";\n\nimport { QuestionGeneratorResponseSchema, type Question, type QuestionGenerationResult, type QuestionStrategy, type QuestionWithStrategy } from \"../shared/schemas/question.schema.js\";\nimport { createModel } from \"../shared/agent/model.config.js\";\nimport { invokeWithAbortSignal } from \"../shared/agent/model-signal.js\";\nimport { protocolLogger } from \"../shared/observability/protocol.logger.js\";\nimport { Timed } from \"../shared/observability/performance.js\";\nimport { SYSTEM_PROMPT, buildQuestionPrompt, type DiscoveryQuestionInput } from \"./question.prompt.js\";\n\nconst logger = protocolLogger(\"QuestionGenerator\");\n\n/** Maximum same-strategy questions allowed in a single emission. */\nconst MAX_SAME_STRATEGY = 2;\n\n/** @deprecated Use QuestionerAgent instead. Will be removed in a future version. */\nexport class QuestionGenerator {\n private model: ReturnType<ChatOpenAI[\"withStructuredOutput\"]>;\n\n constructor() {\n const llm = createModel(\"discoveryQuestionGenerator\");\n this.model = llm.withStructuredOutput(QuestionGeneratorResponseSchema, {\n name: \"clarifying_questions\",\n });\n }\n\n /**\n * Generate up to 3 decision questions from the given discovery turn.\n *\n * @param input Discovery turn payload.\n * @param options.signal Optional AbortSignal. Passed to LangChain so an\n * aborted call cancels the underlying HTTP fetch instead of leaving a\n * floating promise burning OpenRouter capacity.\n * @returns A result with parallel questions[] and strategies[] arrays,\n * or null when the LLM fails, the output is malformed, the call was\n * aborted, or the guardrails leave zero questions standing.\n */\n @Timed()\n async generate(\n input: DiscoveryQuestionInput,\n options?: { signal?: AbortSignal },\n ): Promise<QuestionGenerationResult | null> {\n const user = buildQuestionPrompt(input);\n\n let raw: unknown;\n try {\n raw = await invokeWithAbortSignal(\n this.model,\n [new SystemMessage(SYSTEM_PROMPT), new HumanMessage(user)],\n options?.signal,\n );\n } catch (err) {\n // AbortError is the expected outcome under deadline pressure — caller\n // already wants to skip questions in that case, so log at info rather\n // than warn to keep dashboards clean.\n const aborted = options?.signal?.aborted ?? false;\n if (aborted) {\n logger.info(\"QuestionGenerator aborted by signal\", {\n reason: options?.signal?.reason instanceof Error ? options.signal.reason.message : String(options?.signal?.reason ?? \"unknown\"),\n });\n } else {\n logger.warn(\"QuestionGenerator LLM call failed\", {\n error: err instanceof Error ? err.message : String(err),\n });\n }\n return null;\n }\n\n const parsed = QuestionGeneratorResponseSchema.safeParse(raw);\n if (!parsed.success) {\n logger.warn(\"QuestionGenerator parse failed\", { error: parsed.error.message });\n return null;\n }\n\n const filtered = applyGuardrails(parsed.data.questions);\n if (filtered.length === 0) return null;\n\n return {\n questions: filtered.map(stripStrategy),\n strategies: filtered.map((q) => q.strategy),\n };\n }\n}\n\n/**\n * Guardrail pipeline. Order matters:\n * 1. Dedup by title (keep first occurrence). Title uniqueness is a hard UX\n * requirement for the renderer — two questions cannot share a chip label.\n * 2. Strategy diversity: cap same-strategy entries at MAX_SAME_STRATEGY,\n * dropping overflow unconditionally (does NOT depend on whether a\n * distinct-strategy alternative exists in the batch). The cap exists to\n * enforce the \"never 3 of the same kind\" guidance from the spec.\n */\nfunction applyGuardrails(questions: QuestionWithStrategy[]): QuestionWithStrategy[] {\n const dedupedByTitle = dedupByTitle(questions);\n return enforceStrategyDiversity(dedupedByTitle);\n}\n\nfunction dedupByTitle(questions: QuestionWithStrategy[]): QuestionWithStrategy[] {\n const seen = new Set<string>();\n const out: QuestionWithStrategy[] = [];\n for (const q of questions) {\n if (seen.has(q.title)) continue;\n seen.add(q.title);\n out.push(q);\n }\n return out;\n}\n\n/**\n * Enforce the \"never 3 same-strategy\" rule. Walks the array in order; once a\n * given strategy has appeared MAX_SAME_STRATEGY times, subsequent entries with\n * the same strategy are dropped. Distinct-strategy entries are always kept\n * (subject to the schema's overall 3-question cap, which has already applied).\n */\nfunction enforceStrategyDiversity(\n questions: QuestionWithStrategy[],\n): QuestionWithStrategy[] {\n const counts = new Map<QuestionStrategy, number>();\n const out: QuestionWithStrategy[] = [];\n for (const q of questions) {\n const n = counts.get(q.strategy) ?? 0;\n if (n >= MAX_SAME_STRATEGY) continue;\n counts.set(q.strategy, n + 1);\n out.push(q);\n }\n return out;\n}\n\nfunction stripStrategy(q: QuestionWithStrategy): Question {\n const { strategy: _strategy, ...publicShape } = q;\n return publicShape;\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"premise.graph.d.ts","sourceRoot":"/","sources":["premise/premise.graph.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"premise.graph.d.ts","sourceRoot":"/","sources":["premise/premise.graph.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAItD,OAAO,KAAK,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,4CAA4C,CAAC;AACxG,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,4CAA4C,CAAC;AAG3E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AAItE;;GAEG;AACH,qBAAa,mBAAmB;IAE5B,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,QAAQ;IAChB,OAAO,CAAC,cAAc;gBAFd,QAAQ,EAAE,oBAAoB,EAC9B,QAAQ,EAAE,QAAQ,EAClB,cAAc,GAAE,cAAqC;IAG/D;;;;OAIG;IACI,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;2BA6H0B,MAAM;gCAAkB,MAAM;;;;;CAuF3E"}
|
|
@@ -2,7 +2,7 @@ import { StateGraph, START, END } from "@langchain/langgraph";
|
|
|
2
2
|
import { PremiseGraphState } from "./premise.state.js";
|
|
3
3
|
import { PremiseAnalyzer } from "./premise.analyzer.js";
|
|
4
4
|
import { PremiseIndexer } from "./premise.indexer.js";
|
|
5
|
-
import { buildNetworkAssignmentDecision, resolveAssignmentNetworkScope
|
|
5
|
+
import { buildNetworkAssignmentDecision, resolveAssignmentNetworkScope } from "../shared/assignment/network-assignment.policy.js";
|
|
6
6
|
import { getAbortSignalConfig } from "../shared/agent/model-signal.js";
|
|
7
7
|
import { protocolLogger } from "../shared/observability/protocol.logger.js";
|
|
8
8
|
import { timed } from "../shared/observability/performance.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"premise.graph.js","sourceRoot":"/","sources":["premise/premise.graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAE9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EACL,8BAA8B,EAC9B,6BAA6B,GAC9B,MAAM,mDAAmD,CAAC;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAGvE,OAAO,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAC;AAC5E,OAAO,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAG/D,MAAM,MAAM,GAAG,cAAc,CAAC,qBAAqB,CAAC,CAAC;AAErD;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAC9B,YACU,QAA8B,EAC9B,QAAkB,EAClB,iBAAiC,IAAI,cAAc,EAAE;QAFrD,aAAQ,GAAR,QAAQ,CAAsB;QAC9B,aAAQ,GAAR,QAAQ,CAAU;QAClB,mBAAc,GAAd,cAAc,CAAuC;IAC5D,CAAC;IAEJ;;;;OAIG;IACI,WAAW;QAChB,MAAM,QAAQ,GAAG,IAAI,eAAe,EAAE,CAAC;QACvC,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC;QAEpC,MAAM,SAAS,GAAG,KAAK,EAAE,KAAqC,EAAE,EAAE;YAChE,OAAO,KAAK,CAAC,oBAAoB,EAAE,KAAK,IAAI,EAAE;gBAC5C,MAAM,CAAC,OAAO,CAAC,mDAAmD,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC;gBAClF,MAAM,QAAQ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O,EAAE,kBAAkB,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC;YAC3D,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;QAEF,MAAM,WAAW,GAAG,CAAC,KAAqC,EAAE,EAAE;YAC5D,IAAI,KAAK,CAAC,KAAK;gBAAE,OAAO,KAAK,CAAC;YAC9B,IAAI,KAAK,CAAC,aAAa,KAAK,OAAO;gBAAE,OAAO,OAAO,CAAC;YACpD,OAAO,SAAS,CAAC;QACnB,CAAC,CAAC;QAEF,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,iBAAiB,CAAC;aAC5C,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC;aAC3B,OAAO,CAAC,SAAS,EAAE,WAAW,CAAC;aAC/B,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC;aAC3B,OAAO,CAAC,SAAS,EAAE,WAAW,CAAC;aAC/B,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC;aAC3B,mBAAmB,CAAC,KAAK,EAAE,WAAW,EAAE;YACvC,KAAK,EAAE,OAAO;YACd,OAAO,EAAE,SAAS;YAClB,GAAG,EAAE,GAAG;SACT,CAAC;aACD,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC;aACrB,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC;aAC3B,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC;aAC3B,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC;aAC3B,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAEzB,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;CACF","sourcesContent":["import { StateGraph, START, END } from \"@langchain/langgraph\";\n\nimport { PremiseGraphState } from \"./premise.state.js\";\nimport { PremiseAnalyzer } from \"./premise.analyzer.js\";\nimport { PremiseIndexer } from \"./premise.indexer.js\";\n\nimport {\n buildNetworkAssignmentDecision,\n resolveAssignmentNetworkScope,\n} from \"../shared/assignment/network-assignment.policy.js\";\nimport { getAbortSignalConfig } from \"../shared/agent/model-signal.js\";\nimport type { PremiseGraphDatabase, PremiseAnalysis } from \"../shared/interfaces/database.interface.js\";\nimport type { Embedder } from \"../shared/interfaces/embedder.interface.js\";\nimport { protocolLogger } from \"../shared/observability/protocol.logger.js\";\nimport { timed } from \"../shared/observability/performance.js\";\nimport type { DebugMetaAgent } from \"../chat/chat-streaming.types.js\";\n\nconst logger = protocolLogger(\"PremiseGraphFactory\");\n\n/**\n * Graph factory for premise lifecycle: create, update, and query modes.\n */\nexport class PremiseGraphFactory {\n constructor(\n private database: PremiseGraphDatabase,\n private embedder: Embedder,\n private premiseIndexer: PremiseIndexer = new PremiseIndexer(),\n ) {}\n\n /**\n * Compiles and returns the premise lifecycle graph.\n *\n * @returns A compiled LangGraph graph handling create, update, and query modes.\n */\n public createGraph() {\n const analyzer = new PremiseAnalyzer();\n const indexer = this.premiseIndexer;\n\n const queryNode = async (state: typeof PremiseGraphState.State) => {\n return timed(\"PremiseGraph.query\", async () => {\n logger.verbose(`[PremiseGraph.query] Fetching premises for user ${state.userId}`);\n const premises = await this.database.getPremisesForUser(state.userId, 'ACTIVE');\n return {\n readResult: {\n premises,\n count: premises.length,\n },\n };\n });\n };\n\n const analyzeNode = async (state: typeof PremiseGraphState.State) => {\n return timed(\"PremiseGraph.analyze\", async () => {\n if (!state.assertionText) {\n return { error: \"assertionText is required for create/update mode\" };\n }\n\n logger.verbose(`[PremiseGraph.analyze] Analyzing: \"${state.assertionText.substring(0, 50)}...\"`);\n\n const start = Date.now();\n const result = await analyzer.invoke(state.assertionText);\n const timing: DebugMetaAgent = {\n name: \"premise-analyzer\",\n durationMs: Date.now() - start,\n };\n\n const analysis: PremiseAnalysis = {\n speechActType: result.speechActType,\n felicityAuthority: result.felicityAuthority,\n felicitySincerity: result.felicitySincerity,\n felicityClarity: result.felicityClarity,\n semanticEntropy: result.semanticEntropy,\n };\n\n return { analysis, agentTimings: [timing] };\n });\n };\n\n const embedNode = async (state: typeof PremiseGraphState.State) => {\n return timed(\"PremiseGraph.embed\", async () => {\n if (state.error) return {};\n\n if (!state.assertionText) {\n return { error: \"assertionText is required for embedding\" };\n }\n\n logger.verbose(`[PremiseGraph.embed] Generating embedding for premise`);\n\n // Embedder.generate returns number[] | number[][], cast for single string input\n const embedding = await this.embedder.generate(state.assertionText, undefined, getAbortSignalConfig()) as number[];\n return { embedding };\n });\n };\n\n const persistNode = async (state: typeof PremiseGraphState.State) => {\n return timed(\"PremiseGraph.persist\", async () => {\n if (state.error) return {};\n\n if (state.operationMode === 'update' && !state.targetPremiseId) {\n return { error: \"targetPremiseId is required for update mode\" };\n }\n\n if (state.operationMode === 'update' && state.targetPremiseId) {\n logger.verbose(`[PremiseGraph.persist] Updating premise ${state.targetPremiseId}`);\n\n const updated = await this.database.updatePremise(state.targetPremiseId, {\n assertion: {\n text: state.assertionText!,\n tier: state.tier,\n },\n analysis: state.analysis ?? undefined,\n validity: {\n validFrom: state.validFrom,\n validUntil: state.validUntil,\n volatile: state.volatile,\n },\n embedding: state.embedding,\n });\n return { premise: updated };\n }\n\n logger.verbose(`[PremiseGraph.persist] Creating new premise for user ${state.userId}`);\n\n const premise = await this.database.createPremise({\n userId: state.userId,\n assertion: {\n text: state.assertionText!,\n tier: state.tier,\n },\n provenance: {\n source: state.provenanceSource ?? 'explicit',\n sourceId: state.provenanceSourceId,\n confidence: state.provenanceConfidence ?? 1.0,\n timestamp: new Date().toISOString(),\n },\n analysis: state.analysis ?? undefined,\n validity: {\n validFrom: state.validFrom,\n validUntil: state.validUntil,\n volatile: state.volatile,\n },\n embedding: state.embedding,\n });\n return { premise };\n });\n };\n\n const indexNode = async (state: typeof PremiseGraphState.State) => {\n return timed(\"PremiseGraph.index\", async () => {\n if (!state.premise) return {};\n\n logger.verbose(`[PremiseGraph.index] Scoring premise against user networks`);\n\n const membershipNetworkIds = await this.database.getAssignmentNetworkIdsForUser(state.userId);\n const indexIds = resolveAssignmentNetworkScope({\n memberships: membershipNetworkIds,\n networkScopeId: state.networkScopeId,\n });\n const scope = state.networkScopeId ? \"network\" : \"global\";\n const assignments: Array<{ networkId: string; relevancyScore: number }> = [];\n const agentTimings: DebugMetaAgent[] = [];\n\n for (const networkId of indexIds) {\n try {\n const assignmentContext = await this.database.getNetworkAssignmentContext(networkId, state.userId);\n if (!assignmentContext) continue;\n const indexPrompt = assignmentContext.indexPrompt;\n const memberPrompt = assignmentContext.memberPrompt;\n const hasPrompts = !!indexPrompt?.trim() || !!memberPrompt?.trim();\n let rawScores: { indexScore?: number; memberScore?: number } | undefined;\n let reason: string | undefined;\n\n if (hasPrompts) {\n const start = Date.now();\n const result = await indexer.invoke({\n premiseText: state.assertionText!,\n indexPrompt: indexPrompt ?? \"\",\n memberPrompt: memberPrompt ?? undefined,\n });\n const timing: DebugMetaAgent = {\n name: \"premise-indexer\",\n durationMs: Date.now() - start,\n };\n rawScores = { indexScore: result.indexScore, memberScore: result.memberScore };\n reason = result.reasoning;\n agentTimings.push(timing);\n }\n\n const decision = buildNetworkAssignmentDecision({\n resourceType: \"premise\",\n mode: \"automatic\",\n scope,\n indexPrompt,\n memberPrompt,\n rawScores,\n evaluator: \"premise-indexer\",\n source: \"premise-graph\",\n reason,\n createdAt: new Date().toISOString(),\n });\n\n if (decision.assigned) {\n await this.database.assignPremiseToNetwork(\n state.premise.id,\n networkId,\n decision.finalScore,\n decision.metadata,\n );\n assignments.push({ networkId, relevancyScore: decision.finalScore });\n }\n } catch (err) {\n logger.verbose(`[PremiseGraph.index] Failed to score network ${networkId}, skipping: ${err}`);\n }\n }\n\n logger.verbose(`[PremiseGraph.index] Assigned to ${assignments.length} networks`);\n\n return { networkAssignments: assignments, agentTimings };\n });\n };\n\n const routeByMode = (state: typeof PremiseGraphState.State) => {\n if (state.error) return \"end\";\n if (state.operationMode === 'query') return \"query\";\n return \"analyze\";\n };\n\n const graph = new StateGraph(PremiseGraphState)\n .addNode(\"query\", queryNode)\n .addNode(\"analyze\", analyzeNode)\n .addNode(\"embed\", embedNode)\n .addNode(\"persist\", persistNode)\n .addNode(\"index\", indexNode)\n .addConditionalEdges(START, routeByMode, {\n query: \"query\",\n analyze: \"analyze\",\n end: END,\n })\n .addEdge(\"query\", END)\n .addEdge(\"analyze\", \"embed\")\n .addEdge(\"embed\", \"persist\")\n .addEdge(\"persist\", \"index\")\n .addEdge(\"index\", END);\n\n return graph.compile();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"premise.graph.js","sourceRoot":"/","sources":["premise/premise.graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAE9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,OAAO,EAAE,8BAA8B,EAAE,6BAA6B,EAAE,MAAM,mDAAmD,CAAC;AAClI,OAAO,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAGvE,OAAO,EAAE,cAAc,EAAE,MAAM,4CAA4C,CAAC;AAC5E,OAAO,EAAE,KAAK,EAAE,MAAM,wCAAwC,CAAC;AAG/D,MAAM,MAAM,GAAG,cAAc,CAAC,qBAAqB,CAAC,CAAC;AAErD;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAC9B,YACU,QAA8B,EAC9B,QAAkB,EAClB,iBAAiC,IAAI,cAAc,EAAE;QAFrD,aAAQ,GAAR,QAAQ,CAAsB;QAC9B,aAAQ,GAAR,QAAQ,CAAU;QAClB,mBAAc,GAAd,cAAc,CAAuC;IAC5D,CAAC;IAEJ;;;;OAIG;IACI,WAAW;QAChB,MAAM,QAAQ,GAAG,IAAI,eAAe,EAAE,CAAC;QACvC,MAAM,OAAO,GAAG,IAAI,CAAC,cAAc,CAAC;QAEpC,MAAM,SAAS,GAAG,KAAK,EAAE,KAAqC,EAAE,EAAE;YAChE,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AAS,eAAe,GAAG,EAAE,CAAC,CAAC;oBAChG,CAAC;gBACH,CAAC;gBAED,MAAM,CAAC,OAAO,CAAC,oCAAoC,WAAW,CAAC,MAAM,WAAW,CAAC,CAAC;gBAElF,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,YAAY,EAAE,CAAC;YAC3D,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;QAEF,MAAM,WAAW,GAAG,CAAC,KAAqC,EAAE,EAAE;YAC5D,IAAI,KAAK,CAAC,KAAK;gBAAE,OAAO,KAAK,CAAC;YAC9B,IAAI,KAAK,CAAC,aAAa,KAAK,OAAO;gBAAE,OAAO,OAAO,CAAC;YACpD,OAAO,SAAS,CAAC;QACnB,CAAC,CAAC;QAEF,MAAM,KAAK,GAAG,IAAI,UAAU,CAAC,iBAAiB,CAAC;aAC5C,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC;aAC3B,OAAO,CAAC,SAAS,EAAE,WAAW,CAAC;aAC/B,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC;aAC3B,OAAO,CAAC,SAAS,EAAE,WAAW,CAAC;aAC/B,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC;aAC3B,mBAAmB,CAAC,KAAK,EAAE,WAAW,EAAE;YACvC,KAAK,EAAE,OAAO;YACd,OAAO,EAAE,SAAS;YAClB,GAAG,EAAE,GAAG;SACT,CAAC;aACD,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC;aACrB,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC;aAC3B,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC;aAC3B,OAAO,CAAC,SAAS,EAAE,OAAO,CAAC;aAC3B,OAAO,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;QAEzB,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC;IACzB,CAAC;CACF","sourcesContent":["import { StateGraph, START, END } from \"@langchain/langgraph\";\n\nimport { PremiseGraphState } from \"./premise.state.js\";\nimport { PremiseAnalyzer } from \"./premise.analyzer.js\";\nimport { PremiseIndexer } from \"./premise.indexer.js\";\n\nimport { buildNetworkAssignmentDecision, resolveAssignmentNetworkScope } from \"../shared/assignment/network-assignment.policy.js\";\nimport { getAbortSignalConfig } from \"../shared/agent/model-signal.js\";\nimport type { PremiseGraphDatabase, PremiseAnalysis } from \"../shared/interfaces/database.interface.js\";\nimport type { Embedder } from \"../shared/interfaces/embedder.interface.js\";\nimport { protocolLogger } from \"../shared/observability/protocol.logger.js\";\nimport { timed } from \"../shared/observability/performance.js\";\nimport type { DebugMetaAgent } from \"../chat/chat-streaming.types.js\";\n\nconst logger = protocolLogger(\"PremiseGraphFactory\");\n\n/**\n * Graph factory for premise lifecycle: create, update, and query modes.\n */\nexport class PremiseGraphFactory {\n constructor(\n private database: PremiseGraphDatabase,\n private embedder: Embedder,\n private premiseIndexer: PremiseIndexer = new PremiseIndexer(),\n ) {}\n\n /**\n * Compiles and returns the premise lifecycle graph.\n *\n * @returns A compiled LangGraph graph handling create, update, and query modes.\n */\n public createGraph() {\n const analyzer = new PremiseAnalyzer();\n const indexer = this.premiseIndexer;\n\n const queryNode = async (state: typeof PremiseGraphState.State) => {\n return timed(\"PremiseGraph.query\", async () => {\n logger.verbose(`[PremiseGraph.query] Fetching premises for user ${state.userId}`);\n const premises = await this.database.getPremisesForUser(state.userId, 'ACTIVE');\n return {\n readResult: {\n premises,\n count: premises.length,\n },\n };\n });\n };\n\n const analyzeNode = async (state: typeof PremiseGraphState.State) => {\n return timed(\"PremiseGraph.analyze\", async () => {\n if (!state.assertionText) {\n return { error: \"assertionText is required for create/update mode\" };\n }\n\n logger.verbose(`[PremiseGraph.analyze] Analyzing: \"${state.assertionText.substring(0, 50)}...\"`);\n\n const start = Date.now();\n const result = await analyzer.invoke(state.assertionText);\n const timing: DebugMetaAgent = {\n name: \"premise-analyzer\",\n durationMs: Date.now() - start,\n };\n\n const analysis: PremiseAnalysis = {\n speechActType: result.speechActType,\n felicityAuthority: result.felicityAuthority,\n felicitySincerity: result.felicitySincerity,\n felicityClarity: result.felicityClarity,\n semanticEntropy: result.semanticEntropy,\n };\n\n return { analysis, agentTimings: [timing] };\n });\n };\n\n const embedNode = async (state: typeof PremiseGraphState.State) => {\n return timed(\"PremiseGraph.embed\", async () => {\n if (state.error) return {};\n\n if (!state.assertionText) {\n return { error: \"assertionText is required for embedding\" };\n }\n\n logger.verbose(`[PremiseGraph.embed] Generating embedding for premise`);\n\n // Embedder.generate returns number[] | number[][], cast for single string input\n const embedding = await this.embedder.generate(state.assertionText, undefined, getAbortSignalConfig()) as number[];\n return { embedding };\n });\n };\n\n const persistNode = async (state: typeof PremiseGraphState.State) => {\n return timed(\"PremiseGraph.persist\", async () => {\n if (state.error) return {};\n\n if (state.operationMode === 'update' && !state.targetPremiseId) {\n return { error: \"targetPremiseId is required for update mode\" };\n }\n\n if (state.operationMode === 'update' && state.targetPremiseId) {\n logger.verbose(`[PremiseGraph.persist] Updating premise ${state.targetPremiseId}`);\n\n const updated = await this.database.updatePremise(state.targetPremiseId, {\n assertion: {\n text: state.assertionText!,\n tier: state.tier,\n },\n analysis: state.analysis ?? undefined,\n validity: {\n validFrom: state.validFrom,\n validUntil: state.validUntil,\n volatile: state.volatile,\n },\n embedding: state.embedding,\n });\n return { premise: updated };\n }\n\n logger.verbose(`[PremiseGraph.persist] Creating new premise for user ${state.userId}`);\n\n const premise = await this.database.createPremise({\n userId: state.userId,\n assertion: {\n text: state.assertionText!,\n tier: state.tier,\n },\n provenance: {\n source: state.provenanceSource ?? 'explicit',\n sourceId: state.provenanceSourceId,\n confidence: state.provenanceConfidence ?? 1.0,\n timestamp: new Date().toISOString(),\n },\n analysis: state.analysis ?? undefined,\n validity: {\n validFrom: state.validFrom,\n validUntil: state.validUntil,\n volatile: state.volatile,\n },\n embedding: state.embedding,\n });\n return { premise };\n });\n };\n\n const indexNode = async (state: typeof PremiseGraphState.State) => {\n return timed(\"PremiseGraph.index\", async () => {\n if (!state.premise) return {};\n\n logger.verbose(`[PremiseGraph.index] Scoring premise against user networks`);\n\n const membershipNetworkIds = await this.database.getAssignmentNetworkIdsForUser(state.userId);\n const indexIds = resolveAssignmentNetworkScope({\n memberships: membershipNetworkIds,\n networkScopeId: state.networkScopeId,\n });\n const scope = state.networkScopeId ? \"network\" : \"global\";\n const assignments: Array<{ networkId: string; relevancyScore: number }> = [];\n const agentTimings: DebugMetaAgent[] = [];\n\n for (const networkId of indexIds) {\n try {\n const assignmentContext = await this.database.getNetworkAssignmentContext(networkId, state.userId);\n if (!assignmentContext) continue;\n const indexPrompt = assignmentContext.indexPrompt;\n const memberPrompt = assignmentContext.memberPrompt;\n const hasPrompts = !!indexPrompt?.trim() || !!memberPrompt?.trim();\n let rawScores: { indexScore?: number; memberScore?: number } | undefined;\n let reason: string | undefined;\n\n if (hasPrompts) {\n const start = Date.now();\n const result = await indexer.invoke({\n premiseText: state.assertionText!,\n indexPrompt: indexPrompt ?? \"\",\n memberPrompt: memberPrompt ?? undefined,\n });\n const timing: DebugMetaAgent = {\n name: \"premise-indexer\",\n durationMs: Date.now() - start,\n };\n rawScores = { indexScore: result.indexScore, memberScore: result.memberScore };\n reason = result.reasoning;\n agentTimings.push(timing);\n }\n\n const decision = buildNetworkAssignmentDecision({\n resourceType: \"premise\",\n mode: \"automatic\",\n scope,\n indexPrompt,\n memberPrompt,\n rawScores,\n evaluator: \"premise-indexer\",\n source: \"premise-graph\",\n reason,\n createdAt: new Date().toISOString(),\n });\n\n if (decision.assigned) {\n await this.database.assignPremiseToNetwork(\n state.premise.id,\n networkId,\n decision.finalScore,\n decision.metadata,\n );\n assignments.push({ networkId, relevancyScore: decision.finalScore });\n }\n } catch (err) {\n logger.verbose(`[PremiseGraph.index] Failed to score network ${networkId}, skipping: ${err}`);\n }\n }\n\n logger.verbose(`[PremiseGraph.index] Assigned to ${assignments.length} networks`);\n\n return { networkAssignments: assignments, agentTimings };\n });\n };\n\n const routeByMode = (state: typeof PremiseGraphState.State) => {\n if (state.error) return \"end\";\n if (state.operationMode === 'query') return \"query\";\n return \"analyze\";\n };\n\n const graph = new StateGraph(PremiseGraphState)\n .addNode(\"query\", queryNode)\n .addNode(\"analyze\", analyzeNode)\n .addNode(\"embed\", embedNode)\n .addNode(\"persist\", persistNode)\n .addNode(\"index\", indexNode)\n .addConditionalEdges(START, routeByMode, {\n query: \"query\",\n analyze: \"analyze\",\n end: END,\n })\n .addEdge(\"query\", END)\n .addEdge(\"analyze\", \"embed\")\n .addEdge(\"embed\", \"persist\")\n .addEdge(\"persist\", \"index\")\n .addEdge(\"index\", END);\n\n return graph.compile();\n }\n}\n"]}
|
|
@@ -117,7 +117,7 @@ export class ProfileGraphFactory {
|
|
|
117
117
|
const willNeedScraping = needsProfileGeneration && !hasMeaningfulInput;
|
|
118
118
|
// If we need to scrape, check if we have sufficient user information
|
|
119
119
|
let needsUserInfo = false;
|
|
120
|
-
|
|
120
|
+
const missingUserInfo = [];
|
|
121
121
|
if (willNeedScraping) {
|
|
122
122
|
logger.verbose("Will need scraping - checking user information...");
|
|
123
123
|
const user = await this.database.getUser(state.userId);
|