@indexnetwork/protocol 14.3.2-rc.477.1 → 16.1.1-rc.478.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +107 -0
- package/IMPLEMENTATION.md +50 -52
- package/STABILITY.md +3 -3
- package/dist/chat/chat.agent.js +2 -2
- package/dist/chat/chat.graph.d.ts +41 -1
- package/dist/chat/chat.graph.js +108 -127
- package/dist/discovery/hyde.frame.d.ts +4 -4
- package/dist/discovery/hyde.graph.d.ts +71 -12
- package/dist/discovery/hyde.graph.js +337 -335
- package/dist/discovery/lens.inferrer.d.ts +6 -6
- package/dist/enrichment/enrichment.graph.d.ts +127 -9
- package/dist/enrichment/enrichment.graph.js +633 -655
- package/dist/enrichment/enrichment.state.d.ts +1 -1
- package/dist/enrichment/enrichment.tools.context-read.d.ts +10 -0
- package/dist/enrichment/enrichment.tools.context-read.js +353 -0
- package/dist/enrichment/enrichment.tools.context-write.d.ts +9 -0
- package/dist/enrichment/enrichment.tools.context-write.js +417 -0
- package/dist/enrichment/enrichment.tools.d.ts +11 -1
- package/dist/enrichment/enrichment.tools.helpers.d.ts +139 -0
- package/dist/enrichment/enrichment.tools.helpers.js +234 -0
- package/dist/enrichment/enrichment.tools.js +16 -975
- package/dist/index.d.ts +27 -48
- package/dist/index.js +17 -27
- package/dist/intents/application/intent.graph.d.ts +71 -67
- package/dist/intents/application/intent.graph.execute.d.ts +59 -0
- package/dist/intents/application/intent.graph.execute.js +301 -0
- package/dist/intents/application/intent.graph.infer.d.ts +44 -0
- package/dist/intents/application/intent.graph.infer.js +97 -0
- package/dist/intents/application/intent.graph.js +96 -888
- package/dist/intents/application/intent.graph.reconcile.d.ts +71 -0
- package/dist/intents/application/intent.graph.reconcile.js +274 -0
- package/dist/intents/application/intent.graph.shared.d.ts +70 -0
- package/dist/intents/application/intent.graph.shared.js +153 -0
- package/dist/intents/domain/intent.state.d.ts +1 -1
- package/dist/maintenance/maintenance.graph.d.ts +66 -3
- package/dist/maintenance/maintenance.graph.js +155 -156
- package/dist/mcp/mcp.authorization-policy.d.ts +24 -28
- package/dist/mcp/mcp.authorization-policy.js +14 -34
- package/dist/mcp/mcp.server.d.ts +3 -3
- package/dist/mcp/mcp.server.js +12 -16
- package/dist/negotiations/application/negotiation.candidates.d.ts +83 -0
- package/dist/negotiations/application/negotiation.candidates.js +162 -0
- package/dist/negotiations/application/negotiation.graph.d.ts +91 -157
- package/dist/negotiations/application/negotiation.graph.finalize.d.ts +5 -0
- package/dist/negotiations/application/negotiation.graph.finalize.js +280 -0
- package/dist/negotiations/application/negotiation.graph.init.d.ts +54 -0
- package/dist/negotiations/application/negotiation.graph.init.js +227 -0
- package/dist/negotiations/application/negotiation.graph.js +69 -1388
- package/dist/negotiations/application/negotiation.graph.screen.d.ts +23 -0
- package/dist/negotiations/application/negotiation.graph.screen.js +108 -0
- package/dist/negotiations/application/negotiation.graph.shared.d.ts +75 -0
- package/dist/negotiations/application/negotiation.graph.shared.js +125 -0
- package/dist/negotiations/application/negotiation.graph.turn.d.ts +105 -0
- package/dist/negotiations/application/negotiation.graph.turn.js +484 -0
- package/dist/negotiations/domain/negotiation.state.d.ts +1 -1
- package/dist/negotiations/domain/negotiation.state.js +0 -1
- package/dist/networks/application/indexer.graph.d.ts +165 -7
- package/dist/networks/application/indexer.graph.js +339 -388
- package/dist/networks/application/indexer.state.d.ts +1 -1
- package/dist/networks/application/membership.graph.d.ts +83 -5
- package/dist/networks/application/membership.graph.js +177 -207
- package/dist/networks/application/network.graph.d.ts +148 -5
- package/dist/networks/application/network.graph.js +249 -278
- package/dist/networks/domain/membership.state.d.ts +1 -1
- package/dist/networks/domain/network.state.d.ts +1 -1
- package/dist/opportunities/application/delivery-card.cache.d.ts +1 -1
- package/dist/opportunities/application/delivery-card.cache.js +2 -2
- package/dist/opportunities/application/index.d.ts +2 -2
- package/dist/opportunities/application/index.js +2 -2
- package/dist/opportunities/application/opportunity.evaluator.js +1 -1
- package/dist/opportunities/application/opportunity.graph.d.ts +686 -473
- package/dist/opportunities/application/opportunity.graph.discovery-strategies.d.ts +109 -0
- package/dist/opportunities/application/opportunity.graph.discovery-strategies.js +451 -0
- package/dist/opportunities/application/opportunity.graph.discovery.d.ts +69 -0
- package/dist/opportunities/application/opportunity.graph.discovery.js +397 -0
- package/dist/opportunities/application/opportunity.graph.evaluation.d.ts +82 -0
- package/dist/opportunities/application/opportunity.graph.evaluation.js +608 -0
- package/dist/opportunities/application/opportunity.graph.js +120 -3690
- package/dist/opportunities/application/opportunity.graph.modes.d.ts +538 -0
- package/dist/opportunities/application/opportunity.graph.modes.js +538 -0
- package/dist/opportunities/application/opportunity.graph.negotiate.d.ts +109 -0
- package/dist/opportunities/application/opportunity.graph.negotiate.js +392 -0
- package/dist/opportunities/application/opportunity.graph.persist-node.d.ts +93 -0
- package/dist/opportunities/application/opportunity.graph.persist-node.js +765 -0
- package/dist/opportunities/application/opportunity.graph.prep.d.ts +150 -0
- package/dist/opportunities/application/opportunity.graph.prep.js +381 -0
- package/dist/opportunities/application/opportunity.graph.shared.d.ts +173 -0
- package/dist/opportunities/application/opportunity.graph.shared.js +199 -0
- package/dist/opportunities/application/opportunity.presentation.d.ts +399 -0
- package/dist/opportunities/application/{opportunity.presenter.js → opportunity.presentation.js} +735 -9
- package/dist/opportunities/application/opportunity.tools.cards.d.ts +152 -0
- package/dist/opportunities/application/opportunity.tools.cards.js +235 -0
- package/dist/opportunities/application/opportunity.tools.d.ts +8 -114
- package/dist/opportunities/application/opportunity.tools.js +28 -711
- package/dist/opportunities/application/opportunity.tools.list.d.ts +10 -0
- package/dist/opportunities/application/opportunity.tools.list.js +493 -0
- package/dist/opportunities/domain/index.d.ts +3 -3
- package/dist/opportunities/domain/index.js +3 -3
- package/dist/opportunities/domain/opportunity.state.d.ts +19 -19
- package/dist/opportunities/index.d.ts +6 -6
- package/dist/opportunities/index.js +4 -4
- package/dist/opportunities/ports/opportunity.tools.port.d.ts +1 -1
- package/dist/opportunities/radar/radar.graph.d.ts +57 -13
- package/dist/opportunities/radar/radar.graph.js +470 -471
- package/dist/premises/premise.graph.d.ts +88 -20
- package/dist/premises/premise.graph.js +207 -218
- package/dist/questions/domain/question.schema.d.ts +40 -40
- package/dist/shared/agent/tool.helpers.d.ts +21 -0
- package/dist/shared/agent/tool.registry.d.ts +4 -3
- package/dist/shared/agent/tool.registry.js +1 -1
- package/dist/shared/interfaces/database.capabilities.d.ts +100 -0
- package/dist/shared/interfaces/database.capabilities.js +7 -0
- package/dist/shared/interfaces/database.entities.d.ts +533 -0
- package/dist/shared/interfaces/database.entities.js +10 -0
- package/dist/shared/interfaces/database.identity-queries.d.ts +294 -0
- package/dist/shared/interfaces/database.identity-queries.js +4 -0
- package/dist/shared/interfaces/database.interface.d.ts +15 -2277
- package/dist/shared/interfaces/database.interface.js +8 -0
- package/dist/shared/interfaces/database.member-queries.d.ts +228 -0
- package/dist/shared/interfaces/database.member-queries.js +4 -0
- package/dist/shared/interfaces/database.negotiation.d.ts +305 -0
- package/dist/shared/interfaces/database.negotiation.js +26 -0
- package/dist/shared/interfaces/database.network-queries.d.ts +277 -0
- package/dist/shared/interfaces/database.network-queries.js +4 -0
- package/dist/shared/interfaces/database.opportunity-queries.d.ts +285 -0
- package/dist/shared/interfaces/database.opportunity-queries.js +4 -0
- package/dist/shared/interfaces/database.port.d.ts +322 -0
- package/dist/shared/interfaces/database.port.js +29 -0
- package/dist/shared/schemas/discovery-question.schema.d.ts +14 -14
- package/dist/shared/schemas/negotiation-digest.schema.d.ts +2 -2
- package/package.json +2 -15
- package/dist/opportunities/application/opportunity.card-presentation.d.ts +0 -44
- package/dist/opportunities/application/opportunity.card-presentation.js +0 -93
- package/dist/opportunities/application/opportunity.presenter.d.ts +0 -156
- package/dist/opportunities/domain/opportunity.presentation-cache.d.ts +0 -5
- package/dist/opportunities/domain/opportunity.presentation-cache.js +0 -11
- package/dist/opportunities/domain/opportunity.presentation.d.ts +0 -76
- package/dist/opportunities/domain/opportunity.presentation.js +0 -516
- package/dist/opportunities/domain/opportunity.safe-presentation.d.ts +0 -104
- package/dist/opportunities/domain/opportunity.safe-presentation.js +0 -102
|
@@ -0,0 +1,399 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The opportunity presentation cluster.
|
|
3
|
+
*
|
|
4
|
+
* One file for the whole path from a persisted opportunity to the copy a user
|
|
5
|
+
* reads: the pure text transforms, the cache-key builders, the safe-fallback
|
|
6
|
+
* pipeline, and the LLM presenter itself. They were four modules that only ever
|
|
7
|
+
* called each other in one direction, and following a card's copy meant hopping
|
|
8
|
+
* between them.
|
|
9
|
+
*
|
|
10
|
+
* Sections, in dependency order:
|
|
11
|
+
* 1. Pure presentation transforms
|
|
12
|
+
* 2. Presentation cache keys
|
|
13
|
+
* 3. Safe-presentation pipeline (fallbacks that never leak raw reasoning)
|
|
14
|
+
* 4. OpportunityPresenter (LLM card and chat copy)
|
|
15
|
+
*/
|
|
16
|
+
import { z } from "zod";
|
|
17
|
+
import type { Opportunity } from "../../shared/interfaces/database.interface.js";
|
|
18
|
+
import type { ChatGraphCompositeDatabase } from "../../shared/interfaces/database.interface.js";
|
|
19
|
+
import type { NegotiationContext } from "./negotiation-context.loader.js";
|
|
20
|
+
/**
|
|
21
|
+
* Pure presentation layer for opportunities.
|
|
22
|
+
* Generates title, description, and CTA based on viewer context — no DB access.
|
|
23
|
+
*/
|
|
24
|
+
export interface OpportunityPresentation {
|
|
25
|
+
title: string;
|
|
26
|
+
description: string;
|
|
27
|
+
callToAction: string;
|
|
28
|
+
}
|
|
29
|
+
export interface UserInfo {
|
|
30
|
+
id: string;
|
|
31
|
+
name: string;
|
|
32
|
+
avatar: string | null;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Generate presentation copy for an opportunity based on viewer context.
|
|
36
|
+
* Pure function — no side effects, no database access.
|
|
37
|
+
*/
|
|
38
|
+
export declare function presentOpportunity(opp: Opportunity, viewerId: string, otherPartyInfo: UserInfo, introducerInfo: UserInfo | null, format: 'card' | 'email' | 'notification'): OpportunityPresentation;
|
|
39
|
+
export declare function stripUuids(text: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Truncate user-facing text to at most `maxChars` without cutting mid-word.
|
|
42
|
+
*
|
|
43
|
+
* Prefers a sentence boundary, then a word boundary, and only falls back to a
|
|
44
|
+
* hard slice if no boundary exists within the limit. An ellipsis is appended
|
|
45
|
+
* when the text is actually shortened. Used by presenter fallbacks so a degraded
|
|
46
|
+
* card never shows a sentence chopped mid-word (e.g. "His focus on 'indiv").
|
|
47
|
+
*/
|
|
48
|
+
export declare function truncateAtBoundary(text: string, maxChars: number): string;
|
|
49
|
+
/**
|
|
50
|
+
* Strips introducer mentions from opportunity summary text.
|
|
51
|
+
* Removes patterns like:
|
|
52
|
+
* - "[Introducer] introduced you to [Counterpart]"
|
|
53
|
+
* - "[Introducer] thinks you should meet [Counterpart]"
|
|
54
|
+
* - "[Introducer] connected you to [Counterpart]"
|
|
55
|
+
* - "[Introducer] suggested you meet [Counterpart]"
|
|
56
|
+
*
|
|
57
|
+
* @param text - The text to clean (personalizedSummary)
|
|
58
|
+
* @param introducerName - Full name of the introducer to strip
|
|
59
|
+
* @returns Text with introducer mentions removed, counterpart preserved
|
|
60
|
+
*/
|
|
61
|
+
export declare function stripIntroducerMentions(text: string, introducerName: string | undefined): string;
|
|
62
|
+
/**
|
|
63
|
+
* Returns viewer-centric main text for an opportunity card.
|
|
64
|
+
* Prefers the part of the reasoning that describes the counterpart (the person
|
|
65
|
+
* on the card), so the viewer sees an introduction to the counterpart rather
|
|
66
|
+
* than a description of themselves.
|
|
67
|
+
*
|
|
68
|
+
* @param reasoning - Raw interpretation.reasoning (may describe both parties).
|
|
69
|
+
* @param counterpartName - Display name of the suggested connection (e.g. "Alex Chen").
|
|
70
|
+
* @param maxChars - Max length of returned string (default MINIMAL_MAIN_TEXT_MAX_CHARS).
|
|
71
|
+
* @param viewerName - Optional display name of the viewer (signed-in user). When provided, sentences or prefixes describing the viewer are skipped so the card introduces the counterpart, not the viewer.
|
|
72
|
+
* @param introducerName - Optional display name of the introducer. When provided, introducer phrases (e.g., "X introduced you to...") are stripped from the summary to keep the body text focused on match quality.
|
|
73
|
+
* @returns Viewer-centric snippet mentioning the counterpart when possible; if counterpartName is empty, returns reasoning truncated to maxChars. Never null; may be "A suggested connection." when reasoning is empty.
|
|
74
|
+
*/
|
|
75
|
+
export declare function viewerCentricCardSummary(reasoning: string, counterpartName: string, maxChars?: number, viewerName?: string, introducerName?: string): string;
|
|
76
|
+
/**
|
|
77
|
+
* Generates a short narrator remark from opportunity reasoning for the narrator chip.
|
|
78
|
+
* Used by the minimal (no-LLM) card path so each card gets a unique remark
|
|
79
|
+
* instead of the same static text.
|
|
80
|
+
*
|
|
81
|
+
* Extracts domain keywords (e.g. "AI", "design", "machine learning") from the
|
|
82
|
+
* reasoning and frames them in a short template like "Shared interest in AI and design."
|
|
83
|
+
*
|
|
84
|
+
* This is a regex-based heuristic — an alternative is OpportunityPresenter.presentCard()
|
|
85
|
+
* which generates narratorRemark via LLM with much higher quality (already used by
|
|
86
|
+
* home.graph.ts and opportunity.discover.ts). See buildMinimalOpportunityCard() in
|
|
87
|
+
* opportunity.tools.ts for the trade-off discussion.
|
|
88
|
+
*
|
|
89
|
+
* @param reasoning - Raw interpretation.reasoning text.
|
|
90
|
+
* @param counterpartName - Display name of the counterpart (stripped from output).
|
|
91
|
+
* @param viewerName - Optional display name of the viewer (stripped from output).
|
|
92
|
+
* @returns A short remark (max ~80 chars) suitable for the narrator chip. Never truncated with "...".
|
|
93
|
+
*/
|
|
94
|
+
export declare function narratorRemarkFromReasoning(reasoning: string, counterpartName: string, viewerName?: string): string;
|
|
95
|
+
/** Cache namespace for opportunity presentation copy. Bump to invalidate copy safety changes. */
|
|
96
|
+
export declare const OPPORTUNITY_PRESENTATION_CACHE_VERSION = "v2";
|
|
97
|
+
export declare function buildRadarCardPresentationCacheKey(opportunityId: string, status: string, viewerId: string): string;
|
|
98
|
+
export declare function buildDeliveryCardPresentationCacheKey(opportunityId: string, status: string, viewerId: string): string;
|
|
99
|
+
export declare function buildApiChatCardPresentationCacheKey(opportunityId: string, viewerId: string): string;
|
|
100
|
+
/**
|
|
101
|
+
* Shared safe-presentation primitive for all user-facing opportunity surfaces.
|
|
102
|
+
*
|
|
103
|
+
* Historically every surface (radar, list/discover cards, minimal chat
|
|
104
|
+
* cards, notification emails/Telegram, chat context, delivery cards) invented
|
|
105
|
+
* its own fallback chain for the case where genuine LLM presenter output is
|
|
106
|
+
* unavailable — some sliced raw `interpretation.reasoning` with no
|
|
107
|
+
* sanitization at all. This module is the single standard:
|
|
108
|
+
*
|
|
109
|
+
* raw reasoning
|
|
110
|
+
* → whitespace-normalize
|
|
111
|
+
* → viewer-centric rewrite (incl. UUID stripping + introducer-mention stripping)
|
|
112
|
+
* → boundary-aware truncation
|
|
113
|
+
* → per-surface empty-text default
|
|
114
|
+
*
|
|
115
|
+
* Surfaces choose *policy* (send a sanitized fallback vs skip entirely) via
|
|
116
|
+
* `allowFallback`; they no longer choose (or forget) sanitization steps.
|
|
117
|
+
*
|
|
118
|
+
* See `packages/protocol/src/opportunity/AGENTS.md` for the review checklist this
|
|
119
|
+
* module exists to satisfy.
|
|
120
|
+
*/
|
|
121
|
+
/** Default max length for fallback summaries (matches presenter internal fallback). */
|
|
122
|
+
export declare const SAFE_FALLBACK_MAX_CHARS = 300;
|
|
123
|
+
/** Default copy when no reasoning text is available at all. */
|
|
124
|
+
export declare const DEFAULT_EMPTY_FALLBACK_TEXT = "A promising connection.";
|
|
125
|
+
/** Default headline for fallback presentations (matches presenter internal fallback). */
|
|
126
|
+
export declare const DEFAULT_FALLBACK_HEADLINE = "A promising connection";
|
|
127
|
+
/** Default CTA for fallback presentations (matches presenter internal fallback). */
|
|
128
|
+
export declare const DEFAULT_FALLBACK_ACTION = "Take a look and decide whether to reach out.";
|
|
129
|
+
export interface SafeFallbackOptions {
|
|
130
|
+
/** Display name of the counterpart shown on the card (enables viewer-centric rewrite). */
|
|
131
|
+
counterpartName?: string;
|
|
132
|
+
/** Display name of the viewer; sentences describing the viewer are skipped/rewritten to "you". */
|
|
133
|
+
viewerName?: string;
|
|
134
|
+
/** Introducer display name; introducer mentions are stripped from the summary body. */
|
|
135
|
+
introducerName?: string | null;
|
|
136
|
+
/** Max output length (boundary-aware). Default {@link SAFE_FALLBACK_MAX_CHARS}. */
|
|
137
|
+
maxChars?: number;
|
|
138
|
+
/** Copy returned when reasoning is empty/blank. Default {@link DEFAULT_EMPTY_FALLBACK_TEXT}. */
|
|
139
|
+
emptyText?: string;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Produce safe user-facing fallback copy from raw match reasoning.
|
|
143
|
+
*
|
|
144
|
+
* This is the ONE sanitization standard: UUID stripping, introducer-mention
|
|
145
|
+
* stripping, and viewer-centric rewrite (via {@link viewerCentricCardSummary}),
|
|
146
|
+
* followed by whitespace normalization and boundary-aware truncation (via
|
|
147
|
+
* {@link truncateAtBoundary}). Never returns raw reasoning verbatim beyond
|
|
148
|
+
* these guarantees, and never returns an empty string.
|
|
149
|
+
*
|
|
150
|
+
* @param rawReasoning - Raw `interpretation.reasoning` / `matchReason` text (may be null/undefined).
|
|
151
|
+
* @param opts - Per-surface knobs (names for rewrite, max length, empty-text copy).
|
|
152
|
+
*/
|
|
153
|
+
export declare function safeFallbackSummary(rawReasoning: string | null | undefined, opts?: SafeFallbackOptions): string;
|
|
154
|
+
/** Minimal presenter-output shape the primitive inspects (subset of CardPresentationResult). */
|
|
155
|
+
export interface SafePresentationCandidate {
|
|
156
|
+
headline?: string;
|
|
157
|
+
personalizedSummary?: string;
|
|
158
|
+
suggestedAction?: string;
|
|
159
|
+
/** Set by OpportunityPresenter when its LLM call failed and it returned fallback-shaped copy. */
|
|
160
|
+
isFallback?: boolean;
|
|
161
|
+
}
|
|
162
|
+
/** Opportunity-ish source object accepted by {@link getSafePresentationOrSkip}. */
|
|
163
|
+
export interface SafePresentationSource {
|
|
164
|
+
/** Presenter output attached to the record, when available. */
|
|
165
|
+
homeCardPresentation?: SafePresentationCandidate | null;
|
|
166
|
+
/** Pre-truncated raw reasoning carried on discovery/list card data. */
|
|
167
|
+
matchReason?: string | null;
|
|
168
|
+
/** Full opportunity interpretation, when the caller holds the record. */
|
|
169
|
+
interpretation?: {
|
|
170
|
+
reasoning?: string | null;
|
|
171
|
+
} | null;
|
|
172
|
+
}
|
|
173
|
+
export interface SafePresentationOptions extends SafeFallbackOptions {
|
|
174
|
+
/**
|
|
175
|
+
* Policy switch: when false, return null instead of fallback copy so the
|
|
176
|
+
* surface can skip rendering entirely (e.g. scheduled digests where sending
|
|
177
|
+
* degraded copy is worse than sending nothing). Default true.
|
|
178
|
+
*/
|
|
179
|
+
allowFallback?: boolean;
|
|
180
|
+
}
|
|
181
|
+
/** Resolved safe presentation for a surface to render. */
|
|
182
|
+
export interface SafePresentation {
|
|
183
|
+
headline: string;
|
|
184
|
+
summary: string;
|
|
185
|
+
suggestedAction: string;
|
|
186
|
+
/** True when copy was derived from raw reasoning rather than genuine LLM presenter output. */
|
|
187
|
+
isFallback: boolean;
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Resolve the safe user-facing presentation for an opportunity, or signal skip.
|
|
191
|
+
*
|
|
192
|
+
* Resolution order:
|
|
193
|
+
* 1. Genuine presenter output (`homeCardPresentation` present, non-empty, and
|
|
194
|
+
* NOT tagged `isFallback` by the presenter) — claim-validated before return.
|
|
195
|
+
* 2. Otherwise, if `allowFallback` (default true): sanitized fallback copy
|
|
196
|
+
* built from `matchReason` / `interpretation.reasoning` via
|
|
197
|
+
* {@link safeFallbackSummary}.
|
|
198
|
+
* 3. Otherwise `null` — the surface must skip this opportunity.
|
|
199
|
+
*
|
|
200
|
+
* Raw `interpretation.reasoning` / `matchReason` never reaches the caller
|
|
201
|
+
* unsanitized through this function.
|
|
202
|
+
*/
|
|
203
|
+
export declare function getSafePresentationOrSkip(source: SafePresentationSource, opts?: SafePresentationOptions): SafePresentation | null;
|
|
204
|
+
/**
|
|
205
|
+
* Opportunity Presenter Agent
|
|
206
|
+
*
|
|
207
|
+
* Generates personalized, second-person explanations of why an opportunity
|
|
208
|
+
* matters to the viewing user. Uses full opportunity data (interpretation,
|
|
209
|
+
* actors, profiles, intents, index) to produce headline, personalizedSummary,
|
|
210
|
+
* and suggestedAction for chat tools and user-facing surfaces.
|
|
211
|
+
*/
|
|
212
|
+
/**
|
|
213
|
+
* Minimal database interface required by gatherPresenterContext.
|
|
214
|
+
* Any database adapter that implements these three methods can be passed.
|
|
215
|
+
*/
|
|
216
|
+
export type PresenterDatabase = Pick<ChatGraphCompositeDatabase, "getProfile" | "getActiveIntents" | "getNetwork" | "getPremisesForUser">;
|
|
217
|
+
declare const PresentationSchema: z.ZodObject<{
|
|
218
|
+
headline: z.ZodString;
|
|
219
|
+
personalizedSummary: z.ZodString;
|
|
220
|
+
suggestedAction: z.ZodString;
|
|
221
|
+
greeting: z.ZodString;
|
|
222
|
+
}, "strip", z.ZodTypeAny, {
|
|
223
|
+
personalizedSummary: string;
|
|
224
|
+
headline: string;
|
|
225
|
+
suggestedAction: string;
|
|
226
|
+
greeting: string;
|
|
227
|
+
}, {
|
|
228
|
+
personalizedSummary: string;
|
|
229
|
+
headline: string;
|
|
230
|
+
suggestedAction: string;
|
|
231
|
+
greeting: string;
|
|
232
|
+
}>;
|
|
233
|
+
export type OpportunityPresentationResult = z.infer<typeof PresentationSchema> & {
|
|
234
|
+
/** True when any output field used resilience fallback copy. */
|
|
235
|
+
isFallback?: boolean;
|
|
236
|
+
/** Diagnostic category; never changes production fallback policy. */
|
|
237
|
+
fallbackReason?: "timeout" | "error" | "sanitization";
|
|
238
|
+
};
|
|
239
|
+
/** Input for card presenter call; extends PresenterInput with optional mutual intent count. */
|
|
240
|
+
export interface CardPresenterInput extends PresenterInput {
|
|
241
|
+
/** Number of overlapping intents (for generating mutualIntentsLabel). */
|
|
242
|
+
mutualIntentCount?: number;
|
|
243
|
+
/**
|
|
244
|
+
* Snapshot of the opportunity's negotiation, if one exists. When status is
|
|
245
|
+
* `negotiating`, the presenter returns a templated chip without invoking
|
|
246
|
+
* the LLM. For `pending`/`stalled`/`accepted`/`rejected`, the full
|
|
247
|
+
* transcript and outcome ground the LLM's explanation.
|
|
248
|
+
*/
|
|
249
|
+
negotiationContext?: NegotiationContext;
|
|
250
|
+
}
|
|
251
|
+
/** LLM-generated fields for card presentation (buttons are hardcoded by callers, not LLM-generated). */
|
|
252
|
+
export declare const CardLLMSchema: z.ZodObject<{
|
|
253
|
+
headline: z.ZodString;
|
|
254
|
+
personalizedSummary: z.ZodString;
|
|
255
|
+
digestSummary: z.ZodString;
|
|
256
|
+
suggestedAction: z.ZodString;
|
|
257
|
+
narratorRemark: z.ZodString;
|
|
258
|
+
mutualIntentsLabel: z.ZodString;
|
|
259
|
+
greeting: z.ZodString;
|
|
260
|
+
}, "strip", z.ZodTypeAny, {
|
|
261
|
+
personalizedSummary: string;
|
|
262
|
+
headline: string;
|
|
263
|
+
suggestedAction: string;
|
|
264
|
+
greeting: string;
|
|
265
|
+
digestSummary: string;
|
|
266
|
+
narratorRemark: string;
|
|
267
|
+
mutualIntentsLabel: string;
|
|
268
|
+
}, {
|
|
269
|
+
personalizedSummary: string;
|
|
270
|
+
headline: string;
|
|
271
|
+
suggestedAction: string;
|
|
272
|
+
greeting: string;
|
|
273
|
+
digestSummary: string;
|
|
274
|
+
narratorRemark: string;
|
|
275
|
+
mutualIntentsLabel: string;
|
|
276
|
+
}>;
|
|
277
|
+
/** LLM-generated result from presentCard (callers append button labels from opportunity.constants). */
|
|
278
|
+
export type CardLLMResult = z.infer<typeof CardLLMSchema> & {
|
|
279
|
+
/**
|
|
280
|
+
* True when the LLM call failed and this is fallback-shaped copy built from
|
|
281
|
+
* raw match reasoning. Callers with strict quality requirements (digests,
|
|
282
|
+
* long-lived caches) should check this before sending/persisting — fallback
|
|
283
|
+
* output is otherwise indistinguishable from genuine LLM output.
|
|
284
|
+
*/
|
|
285
|
+
isFallback?: boolean;
|
|
286
|
+
};
|
|
287
|
+
/** Full card display contract including hardcoded button labels (assembled by callers). */
|
|
288
|
+
export type CardPresentationResult = CardLLMResult & {
|
|
289
|
+
primaryActionLabel: string;
|
|
290
|
+
secondaryActionLabel: string;
|
|
291
|
+
};
|
|
292
|
+
/** Input for a single presenter call (all context pre-assembled). */
|
|
293
|
+
export interface PresenterInput {
|
|
294
|
+
viewerContext: string;
|
|
295
|
+
otherPartyContext: string;
|
|
296
|
+
matchReasoning: string;
|
|
297
|
+
category: string;
|
|
298
|
+
confidence: number;
|
|
299
|
+
signalsSummary: string;
|
|
300
|
+
indexName: string;
|
|
301
|
+
viewerRole: string;
|
|
302
|
+
opportunityStatus?: string;
|
|
303
|
+
/** True when this opportunity was created via an explicit introduction (not automatic discovery). */
|
|
304
|
+
isIntroduction?: boolean;
|
|
305
|
+
/** Name of the person who made the introduction, if applicable. */
|
|
306
|
+
introducerName?: string;
|
|
307
|
+
}
|
|
308
|
+
export declare class OpportunityPresenter {
|
|
309
|
+
private model;
|
|
310
|
+
private homeCardModel;
|
|
311
|
+
constructor();
|
|
312
|
+
private invokeWithTimeout;
|
|
313
|
+
/**
|
|
314
|
+
* Generate personalized presentation for a single opportunity.
|
|
315
|
+
*/
|
|
316
|
+
present(input: PresenterInput, options?: {
|
|
317
|
+
signal?: AbortSignal;
|
|
318
|
+
}): Promise<OpportunityPresentationResult>;
|
|
319
|
+
/**
|
|
320
|
+
* Generate LLM-powered card content (headline, body, narrator remark, mutual-intent label).
|
|
321
|
+
* Callers append button labels from opportunity.constants.
|
|
322
|
+
*
|
|
323
|
+
* When `negotiationContext.status === 'negotiating'`, returns a templated
|
|
324
|
+
* chip synchronously without invoking the LLM — the card just reflects
|
|
325
|
+
* "negotiation in progress" at that point.
|
|
326
|
+
*/
|
|
327
|
+
presentCard(input: CardPresenterInput): Promise<CardLLMResult>;
|
|
328
|
+
/**
|
|
329
|
+
* Process multiple opportunities in parallel with bounded concurrency.
|
|
330
|
+
*/
|
|
331
|
+
presentBatch(inputs: PresenterInput[], options?: {
|
|
332
|
+
concurrency?: number;
|
|
333
|
+
}): Promise<OpportunityPresentationResult[]>;
|
|
334
|
+
/**
|
|
335
|
+
* Process multiple opportunities as cards in parallel with bounded concurrency.
|
|
336
|
+
* Returns full card display contracts (headline, body, narrator remark, action labels, mutual-intent label).
|
|
337
|
+
*/
|
|
338
|
+
presentCardBatch(inputs: CardPresenterInput[], options?: {
|
|
339
|
+
concurrency?: number;
|
|
340
|
+
}): Promise<CardLLMResult[]>;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Build the LLM-facing signal summary while excluding pool adjustments. Pool
|
|
344
|
+
* disposition is rendered deterministically by the card chip; asking the
|
|
345
|
+
* presenter to interpret it could turn a demotion into a positive rationale.
|
|
346
|
+
*/
|
|
347
|
+
export declare function summarizeSignalsForPresenter(signals: Opportunity['interpretation']['signals']): string;
|
|
348
|
+
/**
|
|
349
|
+
* Gather all context needed for the presenter from the database.
|
|
350
|
+
* Fetches viewer profile, viewer intents, other party profile(s), and index in parallel.
|
|
351
|
+
*
|
|
352
|
+
* @param displayCounterpartUserId - When set (e.g. for a radar 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).
|
|
353
|
+
*/
|
|
354
|
+
export declare function gatherPresenterContext(database: PresenterDatabase, opportunity: Opportunity, viewerId: string, displayCounterpartUserId?: string): Promise<PresenterInput>;
|
|
355
|
+
/**
|
|
356
|
+
* Minimal shape consumed by buildOpportunityPresentation for prose rendering.
|
|
357
|
+
* Card data objects in the codebase carry additional frontend-only fields;
|
|
358
|
+
* only these are surfaced to MCP agents.
|
|
359
|
+
*/
|
|
360
|
+
export type OpportunityCardLike = Record<string, unknown> & {
|
|
361
|
+
opportunityId: string;
|
|
362
|
+
userId?: string | undefined;
|
|
363
|
+
name?: string | undefined;
|
|
364
|
+
mainText?: string | undefined;
|
|
365
|
+
digestSummary?: string | undefined;
|
|
366
|
+
status?: string | undefined;
|
|
367
|
+
feedCategory?: string | undefined;
|
|
368
|
+
profileUrl?: string | undefined;
|
|
369
|
+
/** Universal link that opens this opportunity's card (`/o/<id>`). */
|
|
370
|
+
appUrl?: string | undefined;
|
|
371
|
+
/** Deep-link to the A2A negotiation trace that produced this opportunity. */
|
|
372
|
+
negotiationUrl?: string | undefined;
|
|
373
|
+
score?: number | undefined;
|
|
374
|
+
/** Digest-mode cooldown re-show — the user has seen this card before. */
|
|
375
|
+
redelivery?: boolean | undefined;
|
|
376
|
+
};
|
|
377
|
+
/**
|
|
378
|
+
* Format opportunity cards into the "opportunities" portion of a tool response.
|
|
379
|
+
*
|
|
380
|
+
* Web chat (`isMcp=false`): emits ```opportunity``` code fences with an
|
|
381
|
+
* "include EXACTLY as-is" directive so the frontend card renderer can parse
|
|
382
|
+
* and render interactive cards.
|
|
383
|
+
*
|
|
384
|
+
* MCP (`isMcp=true`): emits prose (name, reason, status, appUrl and profileUrl
|
|
385
|
+
* when present, feedCategory when present) and includes `opportunityId` for
|
|
386
|
+
* every card so the agent can act via the tools. The trailing instruction
|
|
387
|
+
* reminds the agent to synthesize in natural language, to surface the `appUrl`
|
|
388
|
+
* verbatim as the one link that opens the card, and to fabricate no other URL.
|
|
389
|
+
* MCP clients have no card renderer, so code fences would surface as raw JSON
|
|
390
|
+
* to end users.
|
|
391
|
+
*/
|
|
392
|
+
export declare function buildOpportunityPresentation(inputCards: OpportunityCardLike[], opts: {
|
|
393
|
+
isMcp: boolean;
|
|
394
|
+
leadIn: string;
|
|
395
|
+
label?: 'opportunity' | 'opportunities';
|
|
396
|
+
/** Include hidden digest metadata markers so scheduled brief tooling can confirm delivery. */
|
|
397
|
+
includeDigestMarkers?: boolean;
|
|
398
|
+
}): string;
|
|
399
|
+
export {};
|