@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.
Files changed (140) hide show
  1. package/CHANGELOG.md +107 -0
  2. package/IMPLEMENTATION.md +50 -52
  3. package/STABILITY.md +3 -3
  4. package/dist/chat/chat.agent.js +2 -2
  5. package/dist/chat/chat.graph.d.ts +41 -1
  6. package/dist/chat/chat.graph.js +108 -127
  7. package/dist/discovery/hyde.frame.d.ts +4 -4
  8. package/dist/discovery/hyde.graph.d.ts +71 -12
  9. package/dist/discovery/hyde.graph.js +337 -335
  10. package/dist/discovery/lens.inferrer.d.ts +6 -6
  11. package/dist/enrichment/enrichment.graph.d.ts +127 -9
  12. package/dist/enrichment/enrichment.graph.js +633 -655
  13. package/dist/enrichment/enrichment.state.d.ts +1 -1
  14. package/dist/enrichment/enrichment.tools.context-read.d.ts +10 -0
  15. package/dist/enrichment/enrichment.tools.context-read.js +353 -0
  16. package/dist/enrichment/enrichment.tools.context-write.d.ts +9 -0
  17. package/dist/enrichment/enrichment.tools.context-write.js +417 -0
  18. package/dist/enrichment/enrichment.tools.d.ts +11 -1
  19. package/dist/enrichment/enrichment.tools.helpers.d.ts +139 -0
  20. package/dist/enrichment/enrichment.tools.helpers.js +234 -0
  21. package/dist/enrichment/enrichment.tools.js +16 -975
  22. package/dist/index.d.ts +27 -48
  23. package/dist/index.js +17 -27
  24. package/dist/intents/application/intent.graph.d.ts +71 -67
  25. package/dist/intents/application/intent.graph.execute.d.ts +59 -0
  26. package/dist/intents/application/intent.graph.execute.js +301 -0
  27. package/dist/intents/application/intent.graph.infer.d.ts +44 -0
  28. package/dist/intents/application/intent.graph.infer.js +97 -0
  29. package/dist/intents/application/intent.graph.js +96 -888
  30. package/dist/intents/application/intent.graph.reconcile.d.ts +71 -0
  31. package/dist/intents/application/intent.graph.reconcile.js +274 -0
  32. package/dist/intents/application/intent.graph.shared.d.ts +70 -0
  33. package/dist/intents/application/intent.graph.shared.js +153 -0
  34. package/dist/intents/domain/intent.state.d.ts +1 -1
  35. package/dist/maintenance/maintenance.graph.d.ts +66 -3
  36. package/dist/maintenance/maintenance.graph.js +155 -156
  37. package/dist/mcp/mcp.authorization-policy.d.ts +24 -28
  38. package/dist/mcp/mcp.authorization-policy.js +14 -34
  39. package/dist/mcp/mcp.server.d.ts +3 -3
  40. package/dist/mcp/mcp.server.js +12 -16
  41. package/dist/negotiations/application/negotiation.candidates.d.ts +83 -0
  42. package/dist/negotiations/application/negotiation.candidates.js +162 -0
  43. package/dist/negotiations/application/negotiation.graph.d.ts +91 -157
  44. package/dist/negotiations/application/negotiation.graph.finalize.d.ts +5 -0
  45. package/dist/negotiations/application/negotiation.graph.finalize.js +280 -0
  46. package/dist/negotiations/application/negotiation.graph.init.d.ts +54 -0
  47. package/dist/negotiations/application/negotiation.graph.init.js +227 -0
  48. package/dist/negotiations/application/negotiation.graph.js +69 -1388
  49. package/dist/negotiations/application/negotiation.graph.screen.d.ts +23 -0
  50. package/dist/negotiations/application/negotiation.graph.screen.js +108 -0
  51. package/dist/negotiations/application/negotiation.graph.shared.d.ts +75 -0
  52. package/dist/negotiations/application/negotiation.graph.shared.js +125 -0
  53. package/dist/negotiations/application/negotiation.graph.turn.d.ts +105 -0
  54. package/dist/negotiations/application/negotiation.graph.turn.js +484 -0
  55. package/dist/negotiations/domain/negotiation.state.d.ts +1 -1
  56. package/dist/negotiations/domain/negotiation.state.js +0 -1
  57. package/dist/networks/application/indexer.graph.d.ts +165 -7
  58. package/dist/networks/application/indexer.graph.js +339 -388
  59. package/dist/networks/application/indexer.state.d.ts +1 -1
  60. package/dist/networks/application/membership.graph.d.ts +83 -5
  61. package/dist/networks/application/membership.graph.js +177 -207
  62. package/dist/networks/application/network.graph.d.ts +148 -5
  63. package/dist/networks/application/network.graph.js +249 -278
  64. package/dist/networks/domain/membership.state.d.ts +1 -1
  65. package/dist/networks/domain/network.state.d.ts +1 -1
  66. package/dist/opportunities/application/delivery-card.cache.d.ts +1 -1
  67. package/dist/opportunities/application/delivery-card.cache.js +2 -2
  68. package/dist/opportunities/application/index.d.ts +2 -2
  69. package/dist/opportunities/application/index.js +2 -2
  70. package/dist/opportunities/application/opportunity.evaluator.js +1 -1
  71. package/dist/opportunities/application/opportunity.graph.d.ts +686 -473
  72. package/dist/opportunities/application/opportunity.graph.discovery-strategies.d.ts +109 -0
  73. package/dist/opportunities/application/opportunity.graph.discovery-strategies.js +451 -0
  74. package/dist/opportunities/application/opportunity.graph.discovery.d.ts +69 -0
  75. package/dist/opportunities/application/opportunity.graph.discovery.js +397 -0
  76. package/dist/opportunities/application/opportunity.graph.evaluation.d.ts +82 -0
  77. package/dist/opportunities/application/opportunity.graph.evaluation.js +608 -0
  78. package/dist/opportunities/application/opportunity.graph.js +120 -3690
  79. package/dist/opportunities/application/opportunity.graph.modes.d.ts +538 -0
  80. package/dist/opportunities/application/opportunity.graph.modes.js +538 -0
  81. package/dist/opportunities/application/opportunity.graph.negotiate.d.ts +109 -0
  82. package/dist/opportunities/application/opportunity.graph.negotiate.js +392 -0
  83. package/dist/opportunities/application/opportunity.graph.persist-node.d.ts +93 -0
  84. package/dist/opportunities/application/opportunity.graph.persist-node.js +765 -0
  85. package/dist/opportunities/application/opportunity.graph.prep.d.ts +150 -0
  86. package/dist/opportunities/application/opportunity.graph.prep.js +381 -0
  87. package/dist/opportunities/application/opportunity.graph.shared.d.ts +173 -0
  88. package/dist/opportunities/application/opportunity.graph.shared.js +199 -0
  89. package/dist/opportunities/application/opportunity.presentation.d.ts +399 -0
  90. package/dist/opportunities/application/{opportunity.presenter.js → opportunity.presentation.js} +735 -9
  91. package/dist/opportunities/application/opportunity.tools.cards.d.ts +152 -0
  92. package/dist/opportunities/application/opportunity.tools.cards.js +235 -0
  93. package/dist/opportunities/application/opportunity.tools.d.ts +8 -114
  94. package/dist/opportunities/application/opportunity.tools.js +28 -711
  95. package/dist/opportunities/application/opportunity.tools.list.d.ts +10 -0
  96. package/dist/opportunities/application/opportunity.tools.list.js +493 -0
  97. package/dist/opportunities/domain/index.d.ts +3 -3
  98. package/dist/opportunities/domain/index.js +3 -3
  99. package/dist/opportunities/domain/opportunity.state.d.ts +19 -19
  100. package/dist/opportunities/index.d.ts +6 -6
  101. package/dist/opportunities/index.js +4 -4
  102. package/dist/opportunities/ports/opportunity.tools.port.d.ts +1 -1
  103. package/dist/opportunities/radar/radar.graph.d.ts +57 -13
  104. package/dist/opportunities/radar/radar.graph.js +470 -471
  105. package/dist/premises/premise.graph.d.ts +88 -20
  106. package/dist/premises/premise.graph.js +207 -218
  107. package/dist/questions/domain/question.schema.d.ts +40 -40
  108. package/dist/shared/agent/tool.helpers.d.ts +21 -0
  109. package/dist/shared/agent/tool.registry.d.ts +4 -3
  110. package/dist/shared/agent/tool.registry.js +1 -1
  111. package/dist/shared/interfaces/database.capabilities.d.ts +100 -0
  112. package/dist/shared/interfaces/database.capabilities.js +7 -0
  113. package/dist/shared/interfaces/database.entities.d.ts +533 -0
  114. package/dist/shared/interfaces/database.entities.js +10 -0
  115. package/dist/shared/interfaces/database.identity-queries.d.ts +294 -0
  116. package/dist/shared/interfaces/database.identity-queries.js +4 -0
  117. package/dist/shared/interfaces/database.interface.d.ts +15 -2277
  118. package/dist/shared/interfaces/database.interface.js +8 -0
  119. package/dist/shared/interfaces/database.member-queries.d.ts +228 -0
  120. package/dist/shared/interfaces/database.member-queries.js +4 -0
  121. package/dist/shared/interfaces/database.negotiation.d.ts +305 -0
  122. package/dist/shared/interfaces/database.negotiation.js +26 -0
  123. package/dist/shared/interfaces/database.network-queries.d.ts +277 -0
  124. package/dist/shared/interfaces/database.network-queries.js +4 -0
  125. package/dist/shared/interfaces/database.opportunity-queries.d.ts +285 -0
  126. package/dist/shared/interfaces/database.opportunity-queries.js +4 -0
  127. package/dist/shared/interfaces/database.port.d.ts +322 -0
  128. package/dist/shared/interfaces/database.port.js +29 -0
  129. package/dist/shared/schemas/discovery-question.schema.d.ts +14 -14
  130. package/dist/shared/schemas/negotiation-digest.schema.d.ts +2 -2
  131. package/package.json +2 -15
  132. package/dist/opportunities/application/opportunity.card-presentation.d.ts +0 -44
  133. package/dist/opportunities/application/opportunity.card-presentation.js +0 -93
  134. package/dist/opportunities/application/opportunity.presenter.d.ts +0 -156
  135. package/dist/opportunities/domain/opportunity.presentation-cache.d.ts +0 -5
  136. package/dist/opportunities/domain/opportunity.presentation-cache.js +0 -11
  137. package/dist/opportunities/domain/opportunity.presentation.d.ts +0 -76
  138. package/dist/opportunities/domain/opportunity.presentation.js +0 -516
  139. package/dist/opportunities/domain/opportunity.safe-presentation.d.ts +0 -104
  140. package/dist/opportunities/domain/opportunity.safe-presentation.js +0 -102
@@ -1,156 +0,0 @@
1
- /**
2
- * Opportunity Presenter Agent
3
- *
4
- * Generates personalized, second-person explanations of why an opportunity
5
- * matters to the viewing user. Uses full opportunity data (interpretation,
6
- * actors, profiles, intents, index) to produce headline, personalizedSummary,
7
- * and suggestedAction for chat tools and user-facing surfaces.
8
- */
9
- import { z } from "zod";
10
- import type { Opportunity } from "../../shared/interfaces/database.interface.js";
11
- import type { ChatGraphCompositeDatabase } from "../../shared/interfaces/database.interface.js";
12
- import type { NegotiationContext } from "./negotiation-context.loader.js";
13
- /**
14
- * Minimal database interface required by gatherPresenterContext.
15
- * Any database adapter that implements these three methods can be passed.
16
- */
17
- export type PresenterDatabase = Pick<ChatGraphCompositeDatabase, "getProfile" | "getActiveIntents" | "getNetwork" | "getPremisesForUser">;
18
- declare const PresentationSchema: z.ZodObject<{
19
- headline: z.ZodString;
20
- personalizedSummary: z.ZodString;
21
- suggestedAction: z.ZodString;
22
- greeting: z.ZodString;
23
- }, "strip", z.ZodTypeAny, {
24
- personalizedSummary: string;
25
- headline: string;
26
- suggestedAction: string;
27
- greeting: string;
28
- }, {
29
- personalizedSummary: string;
30
- headline: string;
31
- suggestedAction: string;
32
- greeting: string;
33
- }>;
34
- export type OpportunityPresentationResult = z.infer<typeof PresentationSchema> & {
35
- /** True when any output field used resilience fallback copy. */
36
- isFallback?: boolean;
37
- /** Diagnostic category; never changes production fallback policy. */
38
- fallbackReason?: "timeout" | "error" | "sanitization";
39
- };
40
- /** Input for card presenter call; extends PresenterInput with optional mutual intent count. */
41
- export interface CardPresenterInput extends PresenterInput {
42
- /** Number of overlapping intents (for generating mutualIntentsLabel). */
43
- mutualIntentCount?: number;
44
- /**
45
- * Snapshot of the opportunity's negotiation, if one exists. When status is
46
- * `negotiating`, the presenter returns a templated chip without invoking
47
- * the LLM. For `pending`/`stalled`/`accepted`/`rejected`, the full
48
- * transcript and outcome ground the LLM's explanation.
49
- */
50
- negotiationContext?: NegotiationContext;
51
- }
52
- /** LLM-generated fields for card presentation (buttons are hardcoded by callers, not LLM-generated). */
53
- export declare const CardLLMSchema: z.ZodObject<{
54
- headline: z.ZodString;
55
- personalizedSummary: z.ZodString;
56
- digestSummary: z.ZodString;
57
- suggestedAction: z.ZodString;
58
- narratorRemark: z.ZodString;
59
- mutualIntentsLabel: z.ZodString;
60
- greeting: z.ZodString;
61
- }, "strip", z.ZodTypeAny, {
62
- personalizedSummary: string;
63
- headline: string;
64
- suggestedAction: string;
65
- greeting: string;
66
- digestSummary: string;
67
- narratorRemark: string;
68
- mutualIntentsLabel: string;
69
- }, {
70
- personalizedSummary: string;
71
- headline: string;
72
- suggestedAction: string;
73
- greeting: string;
74
- digestSummary: string;
75
- narratorRemark: string;
76
- mutualIntentsLabel: string;
77
- }>;
78
- /** LLM-generated result from presentCard (callers append button labels from opportunity.constants). */
79
- export type CardLLMResult = z.infer<typeof CardLLMSchema> & {
80
- /**
81
- * True when the LLM call failed and this is fallback-shaped copy built from
82
- * raw match reasoning. Callers with strict quality requirements (digests,
83
- * long-lived caches) should check this before sending/persisting — fallback
84
- * output is otherwise indistinguishable from genuine LLM output.
85
- */
86
- isFallback?: boolean;
87
- };
88
- /** Full card display contract including hardcoded button labels (assembled by callers). */
89
- export type CardPresentationResult = CardLLMResult & {
90
- primaryActionLabel: string;
91
- secondaryActionLabel: string;
92
- };
93
- /** Input for a single presenter call (all context pre-assembled). */
94
- export interface PresenterInput {
95
- viewerContext: string;
96
- otherPartyContext: string;
97
- matchReasoning: string;
98
- category: string;
99
- confidence: number;
100
- signalsSummary: string;
101
- indexName: string;
102
- viewerRole: string;
103
- opportunityStatus?: string;
104
- /** True when this opportunity was created via an explicit introduction (not automatic discovery). */
105
- isIntroduction?: boolean;
106
- /** Name of the person who made the introduction, if applicable. */
107
- introducerName?: string;
108
- }
109
- export declare class OpportunityPresenter {
110
- private model;
111
- private homeCardModel;
112
- constructor();
113
- private invokeWithTimeout;
114
- /**
115
- * Generate personalized presentation for a single opportunity.
116
- */
117
- present(input: PresenterInput, options?: {
118
- signal?: AbortSignal;
119
- }): Promise<OpportunityPresentationResult>;
120
- /**
121
- * Generate LLM-powered card content (headline, body, narrator remark, mutual-intent label).
122
- * Callers append button labels from opportunity.constants.
123
- *
124
- * When `negotiationContext.status === 'negotiating'`, returns a templated
125
- * chip synchronously without invoking the LLM — the card just reflects
126
- * "negotiation in progress" at that point.
127
- */
128
- presentCard(input: CardPresenterInput): Promise<CardLLMResult>;
129
- /**
130
- * Process multiple opportunities in parallel with bounded concurrency.
131
- */
132
- presentBatch(inputs: PresenterInput[], options?: {
133
- concurrency?: number;
134
- }): Promise<OpportunityPresentationResult[]>;
135
- /**
136
- * Process multiple opportunities as cards in parallel with bounded concurrency.
137
- * Returns full card display contracts (headline, body, narrator remark, action labels, mutual-intent label).
138
- */
139
- presentCardBatch(inputs: CardPresenterInput[], options?: {
140
- concurrency?: number;
141
- }): Promise<CardLLMResult[]>;
142
- }
143
- /**
144
- * Build the LLM-facing signal summary while excluding pool adjustments. Pool
145
- * disposition is rendered deterministically by the card chip; asking the
146
- * presenter to interpret it could turn a demotion into a positive rationale.
147
- */
148
- export declare function summarizeSignalsForPresenter(signals: Opportunity['interpretation']['signals']): string;
149
- /**
150
- * Gather all context needed for the presenter from the database.
151
- * Fetches viewer profile, viewer intents, other party profile(s), and index in parallel.
152
- *
153
- * @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).
154
- */
155
- export declare function gatherPresenterContext(database: PresenterDatabase, opportunity: Opportunity, viewerId: string, displayCounterpartUserId?: string): Promise<PresenterInput>;
156
- export {};
@@ -1,5 +0,0 @@
1
- /** Cache namespace for opportunity presentation copy. Bump to invalidate copy safety changes. */
2
- export declare const OPPORTUNITY_PRESENTATION_CACHE_VERSION = "v2";
3
- export declare function buildRadarCardPresentationCacheKey(opportunityId: string, status: string, viewerId: string): string;
4
- export declare function buildDeliveryCardPresentationCacheKey(opportunityId: string, status: string, viewerId: string): string;
5
- export declare function buildApiChatCardPresentationCacheKey(opportunityId: string, viewerId: string): string;
@@ -1,11 +0,0 @@
1
- /** Cache namespace for opportunity presentation copy. Bump to invalidate copy safety changes. */
2
- export const OPPORTUNITY_PRESENTATION_CACHE_VERSION = "v2";
3
- export function buildRadarCardPresentationCacheKey(opportunityId, status, viewerId) {
4
- return `radar:${OPPORTUNITY_PRESENTATION_CACHE_VERSION}:card:${opportunityId}:${status}:${viewerId}`;
5
- }
6
- export function buildDeliveryCardPresentationCacheKey(opportunityId, status, viewerId) {
7
- return `delivery:${OPPORTUNITY_PRESENTATION_CACHE_VERSION}:card:${opportunityId}:${status}:${viewerId}`;
8
- }
9
- export function buildApiChatCardPresentationCacheKey(opportunityId, viewerId) {
10
- return `chat:${OPPORTUNITY_PRESENTATION_CACHE_VERSION}:card:${opportunityId}:${viewerId}`;
11
- }
@@ -1,76 +0,0 @@
1
- /**
2
- * Pure presentation layer for opportunities.
3
- * Generates title, description, and CTA based on viewer context — no DB access.
4
- */
5
- import type { Opportunity } from '../../shared/interfaces/database.interface.js';
6
- export interface OpportunityPresentation {
7
- title: string;
8
- description: string;
9
- callToAction: string;
10
- }
11
- export interface UserInfo {
12
- id: string;
13
- name: string;
14
- avatar: string | null;
15
- }
16
- /**
17
- * Generate presentation copy for an opportunity based on viewer context.
18
- * Pure function — no side effects, no database access.
19
- */
20
- export declare function presentOpportunity(opp: Opportunity, viewerId: string, otherPartyInfo: UserInfo, introducerInfo: UserInfo | null, format: 'card' | 'email' | 'notification'): OpportunityPresentation;
21
- export declare function stripUuids(text: string): string;
22
- /**
23
- * Truncate user-facing text to at most `maxChars` without cutting mid-word.
24
- *
25
- * Prefers a sentence boundary, then a word boundary, and only falls back to a
26
- * hard slice if no boundary exists within the limit. An ellipsis is appended
27
- * when the text is actually shortened. Used by presenter fallbacks so a degraded
28
- * card never shows a sentence chopped mid-word (e.g. "His focus on 'indiv").
29
- */
30
- export declare function truncateAtBoundary(text: string, maxChars: number): string;
31
- /**
32
- * Strips introducer mentions from opportunity summary text.
33
- * Removes patterns like:
34
- * - "[Introducer] introduced you to [Counterpart]"
35
- * - "[Introducer] thinks you should meet [Counterpart]"
36
- * - "[Introducer] connected you to [Counterpart]"
37
- * - "[Introducer] suggested you meet [Counterpart]"
38
- *
39
- * @param text - The text to clean (personalizedSummary)
40
- * @param introducerName - Full name of the introducer to strip
41
- * @returns Text with introducer mentions removed, counterpart preserved
42
- */
43
- export declare function stripIntroducerMentions(text: string, introducerName: string | undefined): string;
44
- /**
45
- * Returns viewer-centric main text for an opportunity card.
46
- * Prefers the part of the reasoning that describes the counterpart (the person
47
- * on the card), so the viewer sees an introduction to the counterpart rather
48
- * than a description of themselves.
49
- *
50
- * @param reasoning - Raw interpretation.reasoning (may describe both parties).
51
- * @param counterpartName - Display name of the suggested connection (e.g. "Alex Chen").
52
- * @param maxChars - Max length of returned string (default MINIMAL_MAIN_TEXT_MAX_CHARS).
53
- * @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.
54
- * @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.
55
- * @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.
56
- */
57
- export declare function viewerCentricCardSummary(reasoning: string, counterpartName: string, maxChars?: number, viewerName?: string, introducerName?: string): string;
58
- /**
59
- * Generates a short narrator remark from opportunity reasoning for the narrator chip.
60
- * Used by the minimal (no-LLM) card path so each card gets a unique remark
61
- * instead of the same static text.
62
- *
63
- * Extracts domain keywords (e.g. "AI", "design", "machine learning") from the
64
- * reasoning and frames them in a short template like "Shared interest in AI and design."
65
- *
66
- * This is a regex-based heuristic — an alternative is OpportunityPresenter.presentCard()
67
- * which generates narratorRemark via LLM with much higher quality (already used by
68
- * home.graph.ts and opportunity.discover.ts). See buildMinimalOpportunityCard() in
69
- * opportunity.tools.ts for the trade-off discussion.
70
- *
71
- * @param reasoning - Raw interpretation.reasoning text.
72
- * @param counterpartName - Display name of the counterpart (stripped from output).
73
- * @param viewerName - Optional display name of the viewer (stripped from output).
74
- * @returns A short remark (max ~80 chars) suitable for the narrator chip. Never truncated with "...".
75
- */
76
- export declare function narratorRemarkFromReasoning(reasoning: string, counterpartName: string, viewerName?: string): string;