@indexnetwork/protocol 66.0.0-rc.665.1 → 66.0.0-rc.668.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/dist/index.d.ts CHANGED
@@ -49,7 +49,7 @@ export type { CreateIntentCounterpartyData, OpenedNegotiation, } from "./interna
49
49
  export { gatherPresenterContext, OpportunityPresenter, } from "./internal/opportunities/opportunity.presentation.js";
50
50
  export type { PresenterDatabase, } from "./internal/opportunities/opportunity.presentation.js";
51
51
  export { getPrimaryActionLabel, } from "./internal/opportunities/opportunity.labels.js";
52
- export { buildApiChatCardPresentationCacheKey, buildOpportunityCardCacheKey, } from "./internal/opportunities/opportunity.presentation.js";
52
+ export { buildApiChatCardPresentationCacheKey, buildApiChatContextCacheKey, buildOpportunityCardCacheKey, } from "./internal/opportunities/opportunity.presentation.js";
53
53
  export type { UserInfo, } from "./internal/opportunities/opportunity.presentation.js";
54
54
  export { canUserSeeOpportunity, classifyOpportunity, isActionableForViewer, validateOpportunityActors, } from "./internal/opportunities/opportunity.utils.js";
55
55
  export { listOpportunityCards, presentOpportunityCard, } from "./internal/opportunities/opportunity.cards.js";
package/dist/index.js CHANGED
@@ -51,7 +51,7 @@ export { normalizeTelegramHandle } from './internal/shared/utils/telegram-handle
51
51
  export { pairKeyOf, } from "./internal/opportunities/opportunity.counterparties.js";
52
52
  export { gatherPresenterContext, OpportunityPresenter, } from "./internal/opportunities/opportunity.presentation.js";
53
53
  export { getPrimaryActionLabel, } from "./internal/opportunities/opportunity.labels.js";
54
- export { buildApiChatCardPresentationCacheKey, buildOpportunityCardCacheKey, } from "./internal/opportunities/opportunity.presentation.js";
54
+ export { buildApiChatCardPresentationCacheKey, buildApiChatContextCacheKey, buildOpportunityCardCacheKey, } from "./internal/opportunities/opportunity.presentation.js";
55
55
  export { canUserSeeOpportunity, classifyOpportunity, isActionableForViewer, validateOpportunityActors, } from "./internal/opportunities/opportunity.utils.js";
56
56
  export { listOpportunityCards, presentOpportunityCard, } from "./internal/opportunities/opportunity.cards.js";
57
57
  export { readOpportunities } from './internal/opportunities/opportunity.graph.modes.js';
@@ -62,7 +62,7 @@ export interface OpportunityCardsDeps {
62
62
  * @param deps - Database, cache, and presenter.
63
63
  * @param opportunity - The opportunity to present.
64
64
  * @param viewerId - The viewing user.
65
- * @param options - `intentId` focuses viewer context on one intent; `skeleton` skips the presenter; `noCache` skips the stored-card read; `peerContext` is the prior opportunity and chat when the caller already loaded them.
65
+ * @param options - `intentId` focuses viewer context on one intent; `skeleton` skips the presenter, so a card not already stored comes back blank with `presentationPending`; `noCache` skips the stored-card read; `peerContext` is the prior opportunity and chat when the caller already loaded them.
66
66
  * @returns The card, or null when the counterpart's name cannot be resolved.
67
67
  * @throws When the presenter fails.
68
68
  */
@@ -76,7 +76,7 @@ async function loadPeerContext(database, viewerId, opportunities) {
76
76
  * @param deps - Database, cache, and presenter.
77
77
  * @param opportunity - The opportunity to present.
78
78
  * @param viewerId - The viewing user.
79
- * @param options - `intentId` focuses viewer context on one intent; `skeleton` skips the presenter; `noCache` skips the stored-card read; `peerContext` is the prior opportunity and chat when the caller already loaded them.
79
+ * @param options - `intentId` focuses viewer context on one intent; `skeleton` skips the presenter, so a card not already stored comes back blank with `presentationPending`; `noCache` skips the stored-card read; `peerContext` is the prior opportunity and chat when the caller already loaded them.
80
80
  * @returns The card, or null when the counterpart's name cannot be resolved.
81
81
  * @throws When the presenter fails.
82
82
  */
@@ -91,7 +91,7 @@ export async function presentOpportunityCard(deps, opportunity, viewerId, option
91
91
  ?? (await loadPeerContext(database, viewerId, [opportunity])).get(opportunity.id);
92
92
  const cacheable = opportunity.status !== 'negotiating';
93
93
  const cacheKey = buildOpportunityCardCacheKey(opportunity.id, viewerId, options.intentId);
94
- if (cacheable && !options.skeleton && !options.noCache) {
94
+ if (cacheable && !options.noCache) {
95
95
  try {
96
96
  const hit = await deps.cache.get(cacheKey);
97
97
  if (hit && (hit.presentedPrior ?? null) === priorKey(peerContext.priorOpportunity)) {
@@ -231,10 +231,11 @@ export async function listOpportunityCards(deps, input) {
231
231
  if (hit)
232
232
  return hit;
233
233
  try {
234
+ // The stored card was already read above, so a miss here doesn't read it again.
234
235
  const card = await presentOpportunityCard(deps, opp, viewerId, {
235
236
  intentId,
236
237
  skeleton: input.skeleton,
237
- noCache: input.noCache,
238
+ noCache: true,
238
239
  peerContext: peerContexts.get(opp.id),
239
240
  });
240
241
  return card;
@@ -21,6 +21,8 @@ export interface UserInfo {
21
21
  /** Cache namespace for opportunity presentation copy. Bump to invalidate copy safety changes. */
22
22
  export declare const OPPORTUNITY_PRESENTATION_CACHE_VERSION = "v3";
23
23
  export declare function buildOpportunityCardCacheKey(opportunityId: string, viewerId: string, focusedViewerIntentId?: string): string;
24
+ /** Cache key for a chat's two-sided context note (one sentence per person). */
25
+ export declare function buildApiChatContextCacheKey(opportunityId: string, viewerId: string): string;
24
26
  export declare function buildApiChatCardPresentationCacheKey(opportunityId: string, viewerId: string): string;
25
27
  /**
26
28
  * Opportunity Presenter Agent
@@ -96,6 +98,22 @@ export type CardPresentationResult = CardLLMResult & {
96
98
  primaryActionLabel: string;
97
99
  secondaryActionLabel: string;
98
100
  };
101
+ /** The note a chat between two matched people opens with: one line per person. */
102
+ export declare const ChatContextLLMSchema: z.ZodObject<{
103
+ headline: z.ZodString;
104
+ viewerSide: z.ZodString;
105
+ otherSide: z.ZodString;
106
+ }, "strip", z.ZodTypeAny, {
107
+ headline: string;
108
+ viewerSide: string;
109
+ otherSide: string;
110
+ }, {
111
+ headline: string;
112
+ viewerSide: string;
113
+ otherSide: string;
114
+ }>;
115
+ /** LLM-generated result from presentChatContext. */
116
+ export type ChatContextLLMResult = z.infer<typeof ChatContextLLMSchema>;
99
117
  /** Input for a single presenter call (all context pre-assembled). */
100
118
  export interface PresenterInput {
101
119
  viewerContext: string;
@@ -111,6 +129,7 @@ export interface PresenterInput {
111
129
  export declare class OpportunityPresenter {
112
130
  private model;
113
131
  private homeCardModel;
132
+ private chatContextModel;
114
133
  constructor();
115
134
  private invokeWithTimeout;
116
135
  /**
@@ -124,6 +143,15 @@ export declare class OpportunityPresenter {
124
143
  present(input: PresenterInput, options?: {
125
144
  signal?: AbortSignal;
126
145
  }): Promise<OpportunityPresentationResult>;
146
+ /**
147
+ * Generate the context note shown inside a chat between two matched people:
148
+ * a headline and one third-person sentence per person.
149
+ *
150
+ * @param input - Pre-assembled presenter context.
151
+ * @returns The headline and the two sentences.
152
+ * @throws When the LLM call fails, times out, or returns invalid output.
153
+ */
154
+ presentChatContext(input: PresenterInput): Promise<ChatContextLLMResult>;
127
155
  /**
128
156
  * Generate LLM-powered card content (headline, body, narrator remark, mutual-intent label).
129
157
  * Callers append button labels from opportunity.constants.
@@ -31,6 +31,10 @@ export function buildOpportunityCardCacheKey(opportunityId, viewerId, focusedVie
31
31
  const scope = focusedViewerIntentId ? `:intent:${focusedViewerIntentId}` : "";
32
32
  return `card:${OPPORTUNITY_PRESENTATION_CACHE_VERSION}:${opportunityId}:${viewerId}${scope}`;
33
33
  }
34
+ /** Cache key for a chat's two-sided context note (one sentence per person). */
35
+ export function buildApiChatContextCacheKey(opportunityId, viewerId) {
36
+ return `chat:${OPPORTUNITY_PRESENTATION_CACHE_VERSION}:context:${opportunityId}:${viewerId}`;
37
+ }
34
38
  export function buildApiChatCardPresentationCacheKey(opportunityId, viewerId) {
35
39
  return `chat:${OPPORTUNITY_PRESENTATION_CACHE_VERSION}:card:${opportunityId}:${viewerId}`;
36
40
  }
@@ -73,6 +77,21 @@ export const CardLLMSchema = z.object({
73
77
  .describe("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."),
74
78
  greeting: z.string().max(500).describe(GREETING_DESCRIPTION),
75
79
  });
80
+ /** The note a chat between two matched people opens with: one line per person. */
81
+ export const ChatContextLLMSchema = z.object({
82
+ headline: z
83
+ .string()
84
+ .describe("A few plain words naming what this connection is about (no names, no 'you')"),
85
+ viewerSide: z
86
+ .string()
87
+ .describe("One sentence in third person that starts with the viewer's first name: what they are doing or looking for that makes this connection relevant now"),
88
+ otherSide: z
89
+ .string()
90
+ .describe("One sentence in third person that starts with the other person's first name: what they are doing or looking for that makes this connection relevant now"),
91
+ });
92
+ const chatContextResponseFormat = z.object({
93
+ presentation: ChatContextLLMSchema,
94
+ });
76
95
  const homeCardResponseFormat = z.object({
77
96
  presentation: CardLLMSchema,
78
97
  });
@@ -150,6 +169,23 @@ When NEGOTIATION CONTEXT is provided, this opportunity passed through an agent-t
150
169
  - For status "rejected": say who ended it. If the negotiation says one agent declined, the agents did; otherwise a person passed. The card should explain the reason briefly so the user understands — not dwell on it.
151
170
  - Do NOT invent turn content. Only reference what is in the NEGOTIATION CONTEXT block.
152
171
 
172
+ `;
173
+ const chatContextSystemPrompt = `
174
+ You write the short context note that sits inside a chat between two people who were matched. It reminds both of them why they are talking.
175
+
176
+ Given context about the viewer, the other person, and why they were matched, produce:
177
+ 1. headline: a few plain words naming what the connection is about.
178
+ 2. viewerSide: one sentence about the viewer.
179
+ 3. otherSide: one sentence about the other person.
180
+
181
+ Rules:
182
+ - Write both sentences in third person and start each with that person's first name. Never use "you" or "your": the note reads the same way for both people.
183
+ - Each sentence says what that person is doing or looking for that makes this connection relevant now (e.g. "Seren will be in SF in March and wants to meet people building agents." / "Xavier hosts a weekly builders dinner there and is looking for new people to invite.").
184
+ - Be concrete and plain. No pitch, no praise, no analysis of the match.
185
+ - Use only the context provided. Do not leak private or confidential details.
186
+ - Network assignment, network title/type, and network/event metadata are retrieval context only. They are NEVER proof that a person attended or will attend, belongs to a group, resides in a place, or shared a session, time, or place with anyone.
187
+ - Never use the words intent or opportunity. Never output internal IDs.
188
+ - At most 30 words per sentence.
153
189
  `;
154
190
  // ──────────────────────────────────────────────────────────────
155
191
  // CLASS
@@ -162,6 +198,9 @@ export class OpportunityPresenter {
162
198
  this.homeCardModel = createStructuredModel("opportunityPresenter", homeCardResponseFormat, {
163
199
  name: "opportunity_presenter_home_card",
164
200
  });
201
+ this.chatContextModel = createStructuredModel("opportunityPresenter", chatContextResponseFormat, {
202
+ name: "opportunity_presenter_chat_context",
203
+ });
165
204
  }
166
205
  async invokeWithTimeout(targetModel, messages, signal) {
167
206
  const timeoutReason = `LLM invoke timed out after ${LLM_TIMEOUT_MS}ms`;
@@ -217,6 +256,37 @@ Produce headline, personalizedSummary (2-3 sentences in "you" language), suggest
217
256
  const result = await this.invokeWithTimeout(this.model, messages, options.signal);
218
257
  return responseFormat.parse(result).presentation;
219
258
  }
259
+ /**
260
+ * Generate the context note shown inside a chat between two matched people:
261
+ * a headline and one third-person sentence per person.
262
+ *
263
+ * @param input - Pre-assembled presenter context.
264
+ * @returns The headline and the two sentences.
265
+ * @throws When the LLM call fails, times out, or returns invalid output.
266
+ */
267
+ async presentChatContext(input) {
268
+ const humanContent = `
269
+ VIEWER:
270
+ ${input.viewerContext}
271
+
272
+ OTHER PERSON:
273
+ ${input.otherPartyContext}
274
+
275
+ MATCH CONTEXT:
276
+ - Why they were matched: ${input.matchReasoning}
277
+ - Intents: ${input.intentsSummary}
278
+ COMMUNITY: ${input.networkName}
279
+ Status: ${input.opportunityStatus ?? "accepted"}
280
+
281
+ Produce headline, viewerSide and otherSide.
282
+ `;
283
+ const messages = [
284
+ new SystemMessage(chatContextSystemPrompt),
285
+ new HumanMessage(humanContent),
286
+ ];
287
+ const result = await this.invokeWithTimeout(this.chatContextModel, messages);
288
+ return chatContextResponseFormat.parse(result).presentation;
289
+ }
220
290
  /**
221
291
  * Generate LLM-powered card content (headline, body, narrator remark, mutual-intent label).
222
292
  * Callers append button labels from opportunity.constants.
@@ -311,6 +381,12 @@ __decorate([
311
381
  __metadata("design:paramtypes", [Object, Object]),
312
382
  __metadata("design:returntype", Promise)
313
383
  ], OpportunityPresenter.prototype, "present", null);
384
+ __decorate([
385
+ Timed(),
386
+ __metadata("design:type", Function),
387
+ __metadata("design:paramtypes", [Object]),
388
+ __metadata("design:returntype", Promise)
389
+ ], OpportunityPresenter.prototype, "presentChatContext", null);
314
390
  __decorate([
315
391
  Timed(),
316
392
  __metadata("design:type", Function),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@indexnetwork/protocol",
3
- "version": "66.0.0-rc.665.1",
3
+ "version": "66.0.0-rc.668.1",
4
4
  "type": "module",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",