@indexnetwork/protocol 3.5.0-rc.255.1 → 3.6.0-rc.258.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.
@@ -155,4 +155,60 @@ export declare function deduplicateByPerson<T extends {
155
155
  confidence?: number;
156
156
  } | null;
157
157
  }>(opportunities: T[], viewerId: string): T[];
158
+ /**
159
+ * Days a digest-delivered opportunity stays suppressed before it becomes
160
+ * eligible for a "still open" reminder re-show (when nothing fresh exists).
161
+ */
162
+ export declare const DIGEST_REDELIVERY_COOLDOWN_DAYS = 5;
163
+ /** Committed delivery row shape consumed by {@link selectDigestCandidates}. */
164
+ export interface DigestDeliveredRow {
165
+ opportunityId: string;
166
+ deliveredAtStatus: string;
167
+ deliveredAt: Date;
168
+ }
169
+ /**
170
+ * Cross-day digest suppression for scheduled-brief candidates.
171
+ *
172
+ * Three rules, applied in order:
173
+ * 1. **Accepted-counterpart suppression** — a direct-connection candidate whose
174
+ * counterpart the viewer has already connected with (an `accepted`
175
+ * opportunity exists with that person) is dropped permanently. A new
176
+ * discovery run re-minting the same person must not resurface them.
177
+ * Connector-flow candidates (viewer is the introducer) are exempt: being
178
+ * connected with someone doesn't make an intro ask on their behalf stale.
179
+ * 2. **Delivery-ledger dedup** — candidates with a committed delivery row at
180
+ * the same `(opportunityId, status)` key have already been shown. While any
181
+ * fresh (never-shown) candidate exists, shown ones are dropped entirely.
182
+ * 3. **Cooldown re-show** — when *no* fresh candidate survives, already-shown
183
+ * candidates whose latest delivery is at least `cooldownDays` old are
184
+ * returned instead, least-recently-shown first, flagged via
185
+ * `redeliveryIds` so the digest can frame them as reminders.
186
+ *
187
+ * Pure function — callers fetch accepted counterparts and ledger rows.
188
+ *
189
+ * @param candidates - Deduped, confidence-ordered digest candidates.
190
+ * @param opts.viewerId - The digest recipient.
191
+ * @param opts.acceptedCounterpartIds - userIds the viewer already connected with.
192
+ * @param opts.deliveredRows - Committed ledger rows for the candidate ids.
193
+ * @param opts.now - Clock override for tests.
194
+ * @param opts.cooldownDays - Cooldown override (default {@link DIGEST_REDELIVERY_COOLDOWN_DAYS}).
195
+ * @returns Surviving pool plus the set of candidate ids that are cooldown re-shows.
196
+ */
197
+ export declare function selectDigestCandidates<T extends {
198
+ id: string;
199
+ status: string;
200
+ actors: Array<{
201
+ userId: string;
202
+ role: string;
203
+ }>;
204
+ }>(candidates: T[], opts: {
205
+ viewerId: string;
206
+ acceptedCounterpartIds: ReadonlySet<string>;
207
+ deliveredRows: DigestDeliveredRow[];
208
+ now?: Date;
209
+ cooldownDays?: number;
210
+ }): {
211
+ pool: T[];
212
+ redeliveryIds: Set<string>;
213
+ };
158
214
  //# sourceMappingURL=opportunity.utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"opportunity.utils.d.ts","sourceRoot":"/","sources":["opportunity/opportunity.utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAC;AAKxE,qEAAqE;AACrE,MAAM,MAAM,oBAAoB,GAAG,OAAO,GAAG,SAAS,GAAG,MAAM,CAAC;AAEhE,gEAAgE;AAChE,MAAM,WAAW,YAAY;IAC3B,UAAU,EAAE,oBAAoB,CAAC;IACjC,aAAa,EAAE,oBAAoB,CAAC;CACrC;AAED;;;;;;;;;GASG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,gBAAgB,GAAG,YAAY,CAe5E;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,KAAK,CAAC;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC,GAAG,IAAI,CA+BhG;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,CACnC,MAAM,EAAE,KAAK,CAAC;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MA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;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,sBAAsB,CAAC,CAAC,SAAS;IAC/C,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,KAAK,CAAC;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACjD,EACC,UAAU,EAAE,CAAC,EAAE,EACf,IAAI,EAAE;IACJ,QAAQ,EAAE,MAAM,CAAC;IACjB,sBAAsB,EAAE,WAAW,CAAC,MAAM,CAAC,CAAC;IAC5C,aAAa,EAAE,kBAAkB,EAAE,CAAC;IACpC,GAAG,CAAC,EAAE,IAAI,CAAC;IACX,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,GACA;IAAE,IAAI,EAAE,CAAC,EAAE,CAAC;IAAC,aAAa,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;CAAE,CA4D3C"}
@@ -280,4 +280,84 @@ export function deduplicateByPerson(opportunities, viewerId) {
280
280
  }
281
281
  return result;
282
282
  }
283
+ /**
284
+ * Days a digest-delivered opportunity stays suppressed before it becomes
285
+ * eligible for a "still open" reminder re-show (when nothing fresh exists).
286
+ */
287
+ export const DIGEST_REDELIVERY_COOLDOWN_DAYS = 5;
288
+ /**
289
+ * Cross-day digest suppression for scheduled-brief candidates.
290
+ *
291
+ * Three rules, applied in order:
292
+ * 1. **Accepted-counterpart suppression** — a direct-connection candidate whose
293
+ * counterpart the viewer has already connected with (an `accepted`
294
+ * opportunity exists with that person) is dropped permanently. A new
295
+ * discovery run re-minting the same person must not resurface them.
296
+ * Connector-flow candidates (viewer is the introducer) are exempt: being
297
+ * connected with someone doesn't make an intro ask on their behalf stale.
298
+ * 2. **Delivery-ledger dedup** — candidates with a committed delivery row at
299
+ * the same `(opportunityId, status)` key have already been shown. While any
300
+ * fresh (never-shown) candidate exists, shown ones are dropped entirely.
301
+ * 3. **Cooldown re-show** — when *no* fresh candidate survives, already-shown
302
+ * candidates whose latest delivery is at least `cooldownDays` old are
303
+ * returned instead, least-recently-shown first, flagged via
304
+ * `redeliveryIds` so the digest can frame them as reminders.
305
+ *
306
+ * Pure function — callers fetch accepted counterparts and ledger rows.
307
+ *
308
+ * @param candidates - Deduped, confidence-ordered digest candidates.
309
+ * @param opts.viewerId - The digest recipient.
310
+ * @param opts.acceptedCounterpartIds - userIds the viewer already connected with.
311
+ * @param opts.deliveredRows - Committed ledger rows for the candidate ids.
312
+ * @param opts.now - Clock override for tests.
313
+ * @param opts.cooldownDays - Cooldown override (default {@link DIGEST_REDELIVERY_COOLDOWN_DAYS}).
314
+ * @returns Surviving pool plus the set of candidate ids that are cooldown re-shows.
315
+ */
316
+ export function selectDigestCandidates(candidates, opts) {
317
+ const { viewerId, acceptedCounterpartIds } = opts;
318
+ // Rule 1: accepted-counterpart suppression (direct connections only).
319
+ const afterAccepted = candidates.filter((opp) => {
320
+ const viewerIsIntroducer = opp.actors.some((a) => a.role === 'introducer' && a.userId === viewerId);
321
+ if (viewerIsIntroducer)
322
+ return true;
323
+ const counterpart = opp.actors.find((a) => a.userId !== viewerId && a.role !== 'introducer');
324
+ return !counterpart || !acceptedCounterpartIds.has(counterpart.userId);
325
+ });
326
+ if (afterAccepted.length < candidates.length) {
327
+ logger.info(`[selectDigestCandidates] accepted-counterpart suppression dropped ${candidates.length - afterAccepted.length} of ${candidates.length} candidates`);
328
+ }
329
+ // Rule 2: delivery-ledger dedup keyed (opportunityId, deliveredAtStatus).
330
+ // Keep the LATEST committed delivery per key — cooldown measures time since
331
+ // the user last saw the card, not since they first saw it.
332
+ const lastDeliveredByKey = new Map();
333
+ for (const row of opts.deliveredRows) {
334
+ if (!(row.deliveredAt instanceof Date) || Number.isNaN(row.deliveredAt.getTime()))
335
+ continue;
336
+ const key = `${row.opportunityId}:${row.deliveredAtStatus}`;
337
+ const existing = lastDeliveredByKey.get(key);
338
+ if (!existing || row.deliveredAt > existing)
339
+ lastDeliveredByKey.set(key, row.deliveredAt);
340
+ }
341
+ const fresh = afterAccepted.filter((opp) => !lastDeliveredByKey.has(`${opp.id}:${opp.status}`));
342
+ if (fresh.length > 0) {
343
+ if (fresh.length < afterAccepted.length) {
344
+ logger.info(`[selectDigestCandidates] ledger dedup dropped ${afterAccepted.length - fresh.length} already-shown candidates`);
345
+ }
346
+ return { pool: fresh, redeliveryIds: new Set() };
347
+ }
348
+ // Rule 3: nothing fresh — re-show the least-recently-shown candidates past cooldown.
349
+ const cooldownMs = (opts.cooldownDays ?? DIGEST_REDELIVERY_COOLDOWN_DAYS) * 86400000;
350
+ const now = opts.now ?? new Date();
351
+ const cooled = afterAccepted
352
+ .map((opp) => ({ opp, at: lastDeliveredByKey.get(`${opp.id}:${opp.status}`) }))
353
+ .filter((entry) => entry.at instanceof Date && now.getTime() - entry.at.getTime() >= cooldownMs)
354
+ .sort((a, b) => a.at.getTime() - b.at.getTime());
355
+ if (cooled.length > 0) {
356
+ logger.info(`[selectDigestCandidates] no fresh candidates — re-showing ${cooled.length} past-cooldown candidate(s)`);
357
+ }
358
+ return {
359
+ pool: cooled.map((entry) => entry.opp),
360
+ redeliveryIds: new Set(cooled.map((entry) => entry.opp.id)),
361
+ };
362
+ }
283
363
  //# sourceMappingURL=opportunity.utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"opportunity.utils.js","sourceRoot":"/","sources":["opportunity/opportunity.utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,GAAG,EAAE,MAAM,gCAAgC,CAAC;AAErD,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;AAWrD;;;;;;;;;GASG;AACH,MAAM,UAAU,qBAAqB,CAAC,MAAwB;IAC5D,QAAQ,MAAM,EAAE,CAAC;QACf,KAAK,UAAU;YACb,oFAAoF;YACpF,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,aAAa,EAAE,OAAO,EAAE,CAAC;QA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,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAC7C,IAAI,MAAM,CAAC,MAAM,GAAG,aAAa,CAAC,MAAM,EAAE,CAAC;QACzC,MAAM,CAAC,IAAI,CACT,iCAAiC,aAAa,CAAC,MAAM,MAAM,MAAM,CAAC,MAAM,gBAAgB,CACzF,CAAC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["/**\n * Opportunity graph utilities: role derivation from corpus type.\n * Used by the opportunity graph to map lens corpus to opportunity actor roles.\n *\n * With lens-based HyDE, strategy selection is handled automatically by the\n * LensInferrer agent. This file provides corpus-to-role mapping for opportunity actors.\n */\n\nimport type { HydeTargetCorpus } from '../shared/hyde/lens.inferrer.js';\nimport { log } from '../shared/observability/log.js';\n\nconst logger = log.graph.from('SelectByComposition');\n\n/** Actor roles in the opportunity model (agent / patient / peer). */\nexport type OpportunityActorRole = 'agent' | 'patient' | 'peer';\n\n/** Result of mapping a corpus to source and candidate roles. */\nexport interface DerivedRoles {\n sourceRole: OpportunityActorRole;\n candidateRole: OpportunityActorRole;\n}\n\n/**\n * Derive actor roles from the corpus type of a lens match.\n *\n * When a candidate is found via:\n * - \"profiles\" corpus → found by who they are → candidate can help → agent\n * - \"intents\" corpus → found by what they need → candidate needs something → patient\n *\n * @param corpus - The target corpus that produced the match ('profiles' | 'intents')\n * @returns Roles for the source (intent owner) and the candidate (matched user/intent)\n */\nexport function deriveRolesFromCorpus(corpus: HydeTargetCorpus): DerivedRoles {\n switch (corpus) {\n case 'profiles':\n // Source seeks someone who can help → source is patient, candidate can help → agent\n return { sourceRole: 'patient', candidateRole: 'agent' };\n case 'intents':\n // Source offers or needs; candidate has complementary goal → source is agent, candidate is patient\n return { sourceRole: 'agent', candidateRole: 'patient' };\n case 'premises':\n // Premise matches are symmetric: two people whose self-descriptions align.\n // Unlike intents (directional roles), premises express stable identity truths.\n return { sourceRole: 'peer', candidateRole: 'peer' };\n default:\n return { sourceRole: 'peer', candidateRole: 'peer' };\n }\n}\n\n/**\n * Validates opportunity actors: if an opportunity has an introducer, it must have\n * one or two non-introducer actors (1 = 1:1 intro e.g. \"I want to connect with X\";\n * 2 = introducer connecting two others).\n *\n * Also rejects self-matches — the same person occupying both sides of a\n * connection. The discovery/persist pipeline trusts the LLM evaluator's actor\n * list, which can collapse onto a single user; downstream readers then garble\n * identity (e.g. a connect link/greeting rendered in one party's voice while the\n * card shows the viewer \"matched with themselves\"). Two degenerate shapes are\n * blocked here, at the single persist chokepoint:\n * - every userId-bearing non-introducer actor collapses to the same user,\n * e.g. `[X(agent), X(patient)]`\n * - an introducer who is also a participant (\"Amina introduced you to Amina\")\n * Only `userId`-bearing actors are checked; role-only actors (legacy/tests) pass.\n * Duplicate rows for one participant are allowed when at least one other distinct\n * participant is present (some callers model multiple intents as multiple actor rows).\n *\n * @param actors - Array of actors with at least a role and optional userId\n * @throws Error when the actor set is invalid\n */\nexport function validateOpportunityActors(actors: Array<{ userId?: string; role: string }>): void {\n const introducerCount = actors.filter((a) => a.role === 'introducer').length;\n const nonIntroducerCount = actors.filter((a) => a.role !== 'introducer').length;\n\n if (introducerCount > 0 && (nonIntroducerCount < 1 || nonIntroducerCount > 2)) {\n throw new Error(\n 'An opportunity with an introducer must have one or two other actors.'\n );\n }\n\n // Self-match guard. Compare only actors that carry a userId so role-only\n // shapes (used by some callers/tests) are unaffected.\n const introducerUserIds = new Set(\n actors.filter((a) => a.role === 'introducer' && a.userId).map((a) => a.userId as string),\n );\n const nonIntroducerUserIds = actors\n .filter((a) => a.role !== 'introducer' && a.userId)\n .map((a) => a.userId as string);\n\n for (const userId of nonIntroducerUserIds) {\n if (introducerUserIds.has(userId)) {\n throw new Error(\n 'An opportunity actor cannot be both the introducer and a participant (self-match).'\n );\n }\n }\n\n const uniqueNonIntroducerUserIds = new Set(nonIntroducerUserIds);\n if (nonIntroducerUserIds.length > 1 && uniqueNonIntroducerUserIds.size === 1) {\n throw new Error('An opportunity cannot match a user with themselves (duplicate participant).');\n }\n}\n\n/**\n * Read-level ACL: whether a user is an actor on the opportunity and may fetch\n * its details. Intentionally broader than `isActionableForViewer` — a user can\n * read an opportunity they are not currently expected to act on (e.g. an agent\n * viewing an accepted opportunity).\n *\n * The feed graph and debug controller chain both predicates: an opportunity only\n * reaches the home feed if it passes `canUserSeeOpportunity` first, then\n * `isActionableForViewer`. For `agent with introducer at pending`,\n * `canUserSeeOpportunity` returns false (read gate blocks it), so the opportunity\n * never surfaces even though `isActionableForViewer` Rule 4 would return true in\n * isolation. This is by design — the agent is not granted read access through the\n * home path until the introducer path completes (negotiation → accepted).\n *\n * Compact Visibility Rule (from lifecycle doc):\n * - Introducer or peer: always see.\n * - Patient or party: see if (status is not latent, or there is no introducer).\n * - Agent: see if (status is accepted/rejected/expired, or (status is not latent and there is no introducer)).\n */\nexport function canUserSeeOpportunity(\n actors: Array<{ userId: string; role: string }>,\n status: string,\n userId: string\n): boolean {\n const hasIntroducer = actors.some((a) => a.role === 'introducer');\n const userRoles = actors.filter((a) => a.userId === userId).map((a) => a.role);\n if (userRoles.length === 0) return false;\n\n return userRoles.some((role) => {\n if (role === 'introducer') return true;\n if (role === 'peer') return true;\n if (role === 'patient' || role === 'party')\n return status !== 'latent' || !hasIntroducer;\n if (role === 'agent')\n return (\n ['accepted', 'rejected', 'expired'].includes(status) ||\n (status !== 'latent' && !hasIntroducer)\n );\n return false;\n });\n}\n\n/**\n * Whether an opportunity should appear on the viewer's home feed (actionable =\n * has a pending action for this user).\n *\n * Rules (see `docs/Latent Opportunity Lifecycle.md` — Role-Visibility Matrix):\n *\n * (1) `latent`, no introducer → all actors actionable\n * (2) `latent`, introducer `approved !== true` → introducer only\n * (3) `latent`, introducer `approved === true` → all non-introducer actors\n * (4) `pending` (any introducer config) → all non-introducer actors\n * (5) `accepted`/`rejected`/`expired`/`stalled`/`draft`/`negotiating`\n * → never actionable\n *\n * The introducer approval signal is stored on the `introducer`-roled actor's\n * `approved: boolean` field within the opportunity's `actors` JSONB. It flips\n * from `false` to `true` when the introducer approves; status stays `latent`\n * across the flip while a background negotiation runs.\n */\nexport function isActionableForViewer(\n actors: Array<{ userId: string; role: string; approved?: boolean }>,\n status: string,\n viewerId: string\n): boolean {\n const viewerActors = actors.filter((a) => a.userId === viewerId);\n if (viewerActors.length === 0) return false;\n\n const introducer = actors.find((a) => a.role === 'introducer');\n const hasIntroducer = !!introducer;\n const introducerApproved = introducer?.approved === true;\n\n return viewerActors.some(({ role }) => {\n if (role === 'introducer') {\n // Rule 2: introducer sees own latent opp only while not yet approved.\n return status === 'latent' && !introducerApproved;\n }\n\n // Non-introducer actors: patient / party / agent / peer.\n if (status === 'latent') {\n // Rule 1: no introducer → visible.\n // Rule 3: introducer approved → visible.\n return !hasIntroducer || introducerApproved;\n }\n if (status === 'pending') {\n // Rule 4: visible to all non-introducer actors.\n return true;\n }\n // Rule 5: never actionable at terminal or internal statuses.\n return false;\n });\n}\n\n/** Feed category for home composition. */\nexport type FeedCategory = 'connection' | 'connector-flow' | 'expired';\n\n/** Soft targets for home feed composition. */\nexport const FEED_SOFT_TARGETS = {\n connection: 3,\n connectorFlow: 2,\n expired: 2,\n} as const;\n\n/**\n * Classify an actionable opportunity into a feed category.\n * Assumes the opportunity already passed isActionableForViewer or is expired.\n *\n * @param opp - Opportunity with actors and status\n * @param viewerId - The viewing user's ID\n * @returns Feed category\n */\nexport function classifyOpportunity(\n opp: { actors: Array<{ userId: string; role: string }>; status: string },\n viewerId: string\n): FeedCategory {\n if (opp.status === 'expired') return 'expired';\n const viewerIsIntroducer = opp.actors.some((a) => a.userId === viewerId && a.role === 'introducer');\n if (viewerIsIntroducer) return 'connector-flow';\n return 'connection';\n}\n\n/**\n * Select opportunities for the home feed using soft composition targets.\n * Fills each category up to its target, then redistributes unused slots\n * to categories that have more items available. Preserves input order.\n *\n * @param opportunities - Pre-sorted opportunities (by confidence/recency)\n * @param viewerId - The viewing user's ID\n * @returns Composition-balanced subset\n */\nexport function selectByComposition<T extends { actors: Array<{ userId: string; role: string }>; status: string }>(\n opportunities: T[],\n viewerId: string\n): T[] {\n const buckets: Record<FeedCategory, T[]> = {\n connection: [],\n 'connector-flow': [],\n expired: [],\n };\n\n for (const opp of opportunities) {\n const category = classifyOpportunity(opp, viewerId);\n buckets[category].push(opp);\n }\n\n const targets: Record<FeedCategory, number> = {\n connection: FEED_SOFT_TARGETS.connection,\n 'connector-flow': FEED_SOFT_TARGETS.connectorFlow,\n expired: FEED_SOFT_TARGETS.expired,\n };\n\n // First pass: fill each category up to its target\n const selected: Record<FeedCategory, T[]> = {\n connection: buckets.connection.slice(0, targets.connection),\n 'connector-flow': buckets['connector-flow'].slice(0, targets['connector-flow']),\n expired: buckets.expired.slice(0, targets.expired),\n };\n\n // Calculate unused slots and remaining items\n const totalTarget = targets.connection + targets['connector-flow'] + targets.expired;\n const usedSlots = selected.connection.length + selected['connector-flow'].length + selected.expired.length;\n let unusedSlots = totalTarget - usedSlots;\n\n // Second pass: redistribute unused slots to categories with remaining items\n // Priority: connection > connector-flow > expired\n const redistOrder: FeedCategory[] = ['connection', 'connector-flow', 'expired'];\n for (const category of redistOrder) {\n if (unusedSlots <= 0) break;\n const remaining = buckets[category].slice(selected[category].length);\n const take = Math.min(remaining.length, unusedSlots);\n selected[category].push(...remaining.slice(0, take));\n unusedSlots -= take;\n }\n\n // Merge in category priority order: connection > connector-flow > expired\n // Within each category, preserve original input order\n const indexMap = new Map(opportunities.map((opp, i) => [opp, i]));\n const sortByOriginal = (a: T, b: T) => (indexMap.get(a) ?? 0) - (indexMap.get(b) ?? 0);\n selected.connection.sort(sortByOriginal);\n selected['connector-flow'].sort(sortByOriginal);\n selected.expired.sort(sortByOriginal);\n\n logger.info(`[selectByComposition] input=${opportunities.length} buckets: connection=${buckets.connection.length} connector-flow=${buckets['connector-flow'].length} expired=${buckets.expired.length} → selected: connection=${selected.connection.length} connector-flow=${selected['connector-flow'].length} expired=${selected.expired.length}`);\n\n return [\n ...selected.connection,\n ...selected['connector-flow'],\n ...selected.expired,\n ];\n}\n\n/**\n * Deduplicate opportunities so each counterpart appears at most once.\n * Keeps the opportunity with the highest interpretation.confidence per\n * counterpart userId. On ties, the first encountered wins (stable).\n *\n * Counterpart = first actor whose userId !== viewerId and role !== 'introducer'.\n * Opportunities without a derivable counterpart pass through undeduped.\n *\n * @param opportunities - Pre-sorted opportunities (e.g. by confidence/recency)\n * @param viewerId - The viewing user's ID\n * @returns Deduped subset preserving original input order among winners\n */\nexport function deduplicateByPerson<T extends {\n actors: Array<{ userId: string; role: string }>;\n interpretation?: { confidence?: number } | null;\n}>(opportunities: T[], viewerId: string): T[] {\n const bestByCounterpart = new Map<string, { opp: T; index: number }>();\n const noCounterpart: Array<{ opp: T; index: number }> = [];\n\n for (let i = 0; i < opportunities.length; i++) {\n const opp = opportunities[i];\n const counterpart = opp.actors.find(\n (a) => a.userId !== viewerId && a.role !== 'introducer',\n );\n\n if (!counterpart) {\n noCounterpart.push({ opp, index: i });\n continue;\n }\n\n const key = counterpart.userId;\n const existing = bestByCounterpart.get(key);\n\n if (!existing) {\n bestByCounterpart.set(key, { opp, index: i });\n continue;\n }\n\n const newConf = opp.interpretation?.confidence ?? -1;\n const oldConf = existing.opp.interpretation?.confidence ?? -1;\n if (newConf > oldConf) {\n bestByCounterpart.set(key, { opp, index: i });\n }\n }\n\n const all = [...bestByCounterpart.values(), ...noCounterpart];\n all.sort((a, b) => a.index - b.index);\n\n const result = all.map((entry) => entry.opp);\n if (result.length < opportunities.length) {\n logger.info(\n `[deduplicateByPerson] deduped ${opportunities.length} → ${result.length} opportunities`,\n );\n }\n return result;\n}\n"]}
1
+ {"version":3,"file":"opportunity.utils.js","sourceRoot":"/","sources":["opportunity/opportunity.utils.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,OAAO,EAAE,GAAG,EAAE,MAAM,gCAAgC,CAAC;AAErD,MAAM,MAAM,GAAG,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC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GAAG,CAAC,EAAE,CAAC,CAAC;KAC5D,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Opportunity graph utilities: role derivation from corpus type.\n * Used by the opportunity graph to map lens corpus to opportunity actor roles.\n *\n * With lens-based HyDE, strategy selection is handled automatically by the\n * LensInferrer agent. This file provides corpus-to-role mapping for opportunity actors.\n */\n\nimport type { HydeTargetCorpus } from '../shared/hyde/lens.inferrer.js';\nimport { log } from '../shared/observability/log.js';\n\nconst logger = log.graph.from('SelectByComposition');\n\n/** Actor roles in the opportunity model (agent / patient / peer). */\nexport type OpportunityActorRole = 'agent' | 'patient' | 'peer';\n\n/** Result of mapping a corpus to source and candidate roles. */\nexport interface DerivedRoles {\n sourceRole: OpportunityActorRole;\n candidateRole: OpportunityActorRole;\n}\n\n/**\n * Derive actor roles from the corpus type of a lens match.\n *\n * When a candidate is found via:\n * - \"profiles\" corpus → found by who they are → candidate can help → agent\n * - \"intents\" corpus → found by what they need → candidate needs something → patient\n *\n * @param corpus - The target corpus that produced the match ('profiles' | 'intents')\n * @returns Roles for the source (intent owner) and the candidate (matched user/intent)\n */\nexport function deriveRolesFromCorpus(corpus: HydeTargetCorpus): DerivedRoles {\n switch (corpus) {\n case 'profiles':\n // Source seeks someone who can help → source is patient, candidate can help → agent\n return { sourceRole: 'patient', candidateRole: 'agent' };\n case 'intents':\n // Source offers or needs; candidate has complementary goal → source is agent, candidate is patient\n return { sourceRole: 'agent', candidateRole: 'patient' };\n case 'premises':\n // Premise matches are symmetric: two people whose self-descriptions align.\n // Unlike intents (directional roles), premises express stable identity truths.\n return { sourceRole: 'peer', candidateRole: 'peer' };\n default:\n return { sourceRole: 'peer', candidateRole: 'peer' };\n }\n}\n\n/**\n * Validates opportunity actors: if an opportunity has an introducer, it must have\n * one or two non-introducer actors (1 = 1:1 intro e.g. \"I want to connect with X\";\n * 2 = introducer connecting two others).\n *\n * Also rejects self-matches — the same person occupying both sides of a\n * connection. The discovery/persist pipeline trusts the LLM evaluator's actor\n * list, which can collapse onto a single user; downstream readers then garble\n * identity (e.g. a connect link/greeting rendered in one party's voice while the\n * card shows the viewer \"matched with themselves\"). Two degenerate shapes are\n * blocked here, at the single persist chokepoint:\n * - every userId-bearing non-introducer actor collapses to the same user,\n * e.g. `[X(agent), X(patient)]`\n * - an introducer who is also a participant (\"Amina introduced you to Amina\")\n * Only `userId`-bearing actors are checked; role-only actors (legacy/tests) pass.\n * Duplicate rows for one participant are allowed when at least one other distinct\n * participant is present (some callers model multiple intents as multiple actor rows).\n *\n * @param actors - Array of actors with at least a role and optional userId\n * @throws Error when the actor set is invalid\n */\nexport function validateOpportunityActors(actors: Array<{ userId?: string; role: string }>): void {\n const introducerCount = actors.filter((a) => a.role === 'introducer').length;\n const nonIntroducerCount = actors.filter((a) => a.role !== 'introducer').length;\n\n if (introducerCount > 0 && (nonIntroducerCount < 1 || nonIntroducerCount > 2)) {\n throw new Error(\n 'An opportunity with an introducer must have one or two other actors.'\n );\n }\n\n // Self-match guard. Compare only actors that carry a userId so role-only\n // shapes (used by some callers/tests) are unaffected.\n const introducerUserIds = new Set(\n actors.filter((a) => a.role === 'introducer' && a.userId).map((a) => a.userId as string),\n );\n const nonIntroducerUserIds = actors\n .filter((a) => a.role !== 'introducer' && a.userId)\n .map((a) => a.userId as string);\n\n for (const userId of nonIntroducerUserIds) {\n if (introducerUserIds.has(userId)) {\n throw new Error(\n 'An opportunity actor cannot be both the introducer and a participant (self-match).'\n );\n }\n }\n\n const uniqueNonIntroducerUserIds = new Set(nonIntroducerUserIds);\n if (nonIntroducerUserIds.length > 1 && uniqueNonIntroducerUserIds.size === 1) {\n throw new Error('An opportunity cannot match a user with themselves (duplicate participant).');\n }\n}\n\n/**\n * Read-level ACL: whether a user is an actor on the opportunity and may fetch\n * its details. Intentionally broader than `isActionableForViewer` — a user can\n * read an opportunity they are not currently expected to act on (e.g. an agent\n * viewing an accepted opportunity).\n *\n * The feed graph and debug controller chain both predicates: an opportunity only\n * reaches the home feed if it passes `canUserSeeOpportunity` first, then\n * `isActionableForViewer`. For `agent with introducer at pending`,\n * `canUserSeeOpportunity` returns false (read gate blocks it), so the opportunity\n * never surfaces even though `isActionableForViewer` Rule 4 would return true in\n * isolation. This is by design — the agent is not granted read access through the\n * home path until the introducer path completes (negotiation → accepted).\n *\n * Compact Visibility Rule (from lifecycle doc):\n * - Introducer or peer: always see.\n * - Patient or party: see if (status is not latent, or there is no introducer).\n * - Agent: see if (status is accepted/rejected/expired, or (status is not latent and there is no introducer)).\n */\nexport function canUserSeeOpportunity(\n actors: Array<{ userId: string; role: string }>,\n status: string,\n userId: string\n): boolean {\n const hasIntroducer = actors.some((a) => a.role === 'introducer');\n const userRoles = actors.filter((a) => a.userId === userId).map((a) => a.role);\n if (userRoles.length === 0) return false;\n\n return userRoles.some((role) => {\n if (role === 'introducer') return true;\n if (role === 'peer') return true;\n if (role === 'patient' || role === 'party')\n return status !== 'latent' || !hasIntroducer;\n if (role === 'agent')\n return (\n ['accepted', 'rejected', 'expired'].includes(status) ||\n (status !== 'latent' && !hasIntroducer)\n );\n return false;\n });\n}\n\n/**\n * Whether an opportunity should appear on the viewer's home feed (actionable =\n * has a pending action for this user).\n *\n * Rules (see `docs/Latent Opportunity Lifecycle.md` — Role-Visibility Matrix):\n *\n * (1) `latent`, no introducer → all actors actionable\n * (2) `latent`, introducer `approved !== true` → introducer only\n * (3) `latent`, introducer `approved === true` → all non-introducer actors\n * (4) `pending` (any introducer config) → all non-introducer actors\n * (5) `accepted`/`rejected`/`expired`/`stalled`/`draft`/`negotiating`\n * → never actionable\n *\n * The introducer approval signal is stored on the `introducer`-roled actor's\n * `approved: boolean` field within the opportunity's `actors` JSONB. It flips\n * from `false` to `true` when the introducer approves; status stays `latent`\n * across the flip while a background negotiation runs.\n */\nexport function isActionableForViewer(\n actors: Array<{ userId: string; role: string; approved?: boolean }>,\n status: string,\n viewerId: string\n): boolean {\n const viewerActors = actors.filter((a) => a.userId === viewerId);\n if (viewerActors.length === 0) return false;\n\n const introducer = actors.find((a) => a.role === 'introducer');\n const hasIntroducer = !!introducer;\n const introducerApproved = introducer?.approved === true;\n\n return viewerActors.some(({ role }) => {\n if (role === 'introducer') {\n // Rule 2: introducer sees own latent opp only while not yet approved.\n return status === 'latent' && !introducerApproved;\n }\n\n // Non-introducer actors: patient / party / agent / peer.\n if (status === 'latent') {\n // Rule 1: no introducer → visible.\n // Rule 3: introducer approved → visible.\n return !hasIntroducer || introducerApproved;\n }\n if (status === 'pending') {\n // Rule 4: visible to all non-introducer actors.\n return true;\n }\n // Rule 5: never actionable at terminal or internal statuses.\n return false;\n });\n}\n\n/** Feed category for home composition. */\nexport type FeedCategory = 'connection' | 'connector-flow' | 'expired';\n\n/** Soft targets for home feed composition. */\nexport const FEED_SOFT_TARGETS = {\n connection: 3,\n connectorFlow: 2,\n expired: 2,\n} as const;\n\n/**\n * Classify an actionable opportunity into a feed category.\n * Assumes the opportunity already passed isActionableForViewer or is expired.\n *\n * @param opp - Opportunity with actors and status\n * @param viewerId - The viewing user's ID\n * @returns Feed category\n */\nexport function classifyOpportunity(\n opp: { actors: Array<{ userId: string; role: string }>; status: string },\n viewerId: string\n): FeedCategory {\n if (opp.status === 'expired') return 'expired';\n const viewerIsIntroducer = opp.actors.some((a) => a.userId === viewerId && a.role === 'introducer');\n if (viewerIsIntroducer) return 'connector-flow';\n return 'connection';\n}\n\n/**\n * Select opportunities for the home feed using soft composition targets.\n * Fills each category up to its target, then redistributes unused slots\n * to categories that have more items available. Preserves input order.\n *\n * @param opportunities - Pre-sorted opportunities (by confidence/recency)\n * @param viewerId - The viewing user's ID\n * @returns Composition-balanced subset\n */\nexport function selectByComposition<T extends { actors: Array<{ userId: string; role: string }>; status: string }>(\n opportunities: T[],\n viewerId: string\n): T[] {\n const buckets: Record<FeedCategory, T[]> = {\n connection: [],\n 'connector-flow': [],\n expired: [],\n };\n\n for (const opp of opportunities) {\n const category = classifyOpportunity(opp, viewerId);\n buckets[category].push(opp);\n }\n\n const targets: Record<FeedCategory, number> = {\n connection: FEED_SOFT_TARGETS.connection,\n 'connector-flow': FEED_SOFT_TARGETS.connectorFlow,\n expired: FEED_SOFT_TARGETS.expired,\n };\n\n // First pass: fill each category up to its target\n const selected: Record<FeedCategory, T[]> = {\n connection: buckets.connection.slice(0, targets.connection),\n 'connector-flow': buckets['connector-flow'].slice(0, targets['connector-flow']),\n expired: buckets.expired.slice(0, targets.expired),\n };\n\n // Calculate unused slots and remaining items\n const totalTarget = targets.connection + targets['connector-flow'] + targets.expired;\n const usedSlots = selected.connection.length + selected['connector-flow'].length + selected.expired.length;\n let unusedSlots = totalTarget - usedSlots;\n\n // Second pass: redistribute unused slots to categories with remaining items\n // Priority: connection > connector-flow > expired\n const redistOrder: FeedCategory[] = ['connection', 'connector-flow', 'expired'];\n for (const category of redistOrder) {\n if (unusedSlots <= 0) break;\n const remaining = buckets[category].slice(selected[category].length);\n const take = Math.min(remaining.length, unusedSlots);\n selected[category].push(...remaining.slice(0, take));\n unusedSlots -= take;\n }\n\n // Merge in category priority order: connection > connector-flow > expired\n // Within each category, preserve original input order\n const indexMap = new Map(opportunities.map((opp, i) => [opp, i]));\n const sortByOriginal = (a: T, b: T) => (indexMap.get(a) ?? 0) - (indexMap.get(b) ?? 0);\n selected.connection.sort(sortByOriginal);\n selected['connector-flow'].sort(sortByOriginal);\n selected.expired.sort(sortByOriginal);\n\n logger.info(`[selectByComposition] input=${opportunities.length} buckets: connection=${buckets.connection.length} connector-flow=${buckets['connector-flow'].length} expired=${buckets.expired.length} → selected: connection=${selected.connection.length} connector-flow=${selected['connector-flow'].length} expired=${selected.expired.length}`);\n\n return [\n ...selected.connection,\n ...selected['connector-flow'],\n ...selected.expired,\n ];\n}\n\n/**\n * Deduplicate opportunities so each counterpart appears at most once.\n * Keeps the opportunity with the highest interpretation.confidence per\n * counterpart userId. On ties, the first encountered wins (stable).\n *\n * Counterpart = first actor whose userId !== viewerId and role !== 'introducer'.\n * Opportunities without a derivable counterpart pass through undeduped.\n *\n * @param opportunities - Pre-sorted opportunities (e.g. by confidence/recency)\n * @param viewerId - The viewing user's ID\n * @returns Deduped subset preserving original input order among winners\n */\nexport function deduplicateByPerson<T extends {\n actors: Array<{ userId: string; role: string }>;\n interpretation?: { confidence?: number } | null;\n}>(opportunities: T[], viewerId: string): T[] {\n const bestByCounterpart = new Map<string, { opp: T; index: number }>();\n const noCounterpart: Array<{ opp: T; index: number }> = [];\n\n for (let i = 0; i < opportunities.length; i++) {\n const opp = opportunities[i];\n const counterpart = opp.actors.find(\n (a) => a.userId !== viewerId && a.role !== 'introducer',\n );\n\n if (!counterpart) {\n noCounterpart.push({ opp, index: i });\n continue;\n }\n\n const key = counterpart.userId;\n const existing = bestByCounterpart.get(key);\n\n if (!existing) {\n bestByCounterpart.set(key, { opp, index: i });\n continue;\n }\n\n const newConf = opp.interpretation?.confidence ?? -1;\n const oldConf = existing.opp.interpretation?.confidence ?? -1;\n if (newConf > oldConf) {\n bestByCounterpart.set(key, { opp, index: i });\n }\n }\n\n const all = [...bestByCounterpart.values(), ...noCounterpart];\n all.sort((a, b) => a.index - b.index);\n\n const result = all.map((entry) => entry.opp);\n if (result.length < opportunities.length) {\n logger.info(\n `[deduplicateByPerson] deduped ${opportunities.length} → ${result.length} opportunities`,\n );\n }\n return result;\n}\n\n/**\n * Days a digest-delivered opportunity stays suppressed before it becomes\n * eligible for a \"still open\" reminder re-show (when nothing fresh exists).\n */\nexport const DIGEST_REDELIVERY_COOLDOWN_DAYS = 5;\n\n/** Committed delivery row shape consumed by {@link selectDigestCandidates}. */\nexport interface DigestDeliveredRow {\n opportunityId: string;\n deliveredAtStatus: string;\n deliveredAt: Date;\n}\n\n/**\n * Cross-day digest suppression for scheduled-brief candidates.\n *\n * Three rules, applied in order:\n * 1. **Accepted-counterpart suppression** — a direct-connection candidate whose\n * counterpart the viewer has already connected with (an `accepted`\n * opportunity exists with that person) is dropped permanently. A new\n * discovery run re-minting the same person must not resurface them.\n * Connector-flow candidates (viewer is the introducer) are exempt: being\n * connected with someone doesn't make an intro ask on their behalf stale.\n * 2. **Delivery-ledger dedup** — candidates with a committed delivery row at\n * the same `(opportunityId, status)` key have already been shown. While any\n * fresh (never-shown) candidate exists, shown ones are dropped entirely.\n * 3. **Cooldown re-show** — when *no* fresh candidate survives, already-shown\n * candidates whose latest delivery is at least `cooldownDays` old are\n * returned instead, least-recently-shown first, flagged via\n * `redeliveryIds` so the digest can frame them as reminders.\n *\n * Pure function — callers fetch accepted counterparts and ledger rows.\n *\n * @param candidates - Deduped, confidence-ordered digest candidates.\n * @param opts.viewerId - The digest recipient.\n * @param opts.acceptedCounterpartIds - userIds the viewer already connected with.\n * @param opts.deliveredRows - Committed ledger rows for the candidate ids.\n * @param opts.now - Clock override for tests.\n * @param opts.cooldownDays - Cooldown override (default {@link DIGEST_REDELIVERY_COOLDOWN_DAYS}).\n * @returns Surviving pool plus the set of candidate ids that are cooldown re-shows.\n */\nexport function selectDigestCandidates<T extends {\n id: string;\n status: string;\n actors: Array<{ userId: string; role: string }>;\n}>(\n candidates: T[],\n opts: {\n viewerId: string;\n acceptedCounterpartIds: ReadonlySet<string>;\n deliveredRows: DigestDeliveredRow[];\n now?: Date;\n cooldownDays?: number;\n },\n): { pool: T[]; redeliveryIds: Set<string> } {\n const { viewerId, acceptedCounterpartIds } = opts;\n\n // Rule 1: accepted-counterpart suppression (direct connections only).\n const afterAccepted = candidates.filter((opp) => {\n const viewerIsIntroducer = opp.actors.some(\n (a) => a.role === 'introducer' && a.userId === viewerId,\n );\n if (viewerIsIntroducer) return true;\n const counterpart = opp.actors.find(\n (a) => a.userId !== viewerId && a.role !== 'introducer',\n );\n return !counterpart || !acceptedCounterpartIds.has(counterpart.userId);\n });\n if (afterAccepted.length < candidates.length) {\n logger.info(\n `[selectDigestCandidates] accepted-counterpart suppression dropped ${candidates.length - afterAccepted.length} of ${candidates.length} candidates`,\n );\n }\n\n // Rule 2: delivery-ledger dedup keyed (opportunityId, deliveredAtStatus).\n // Keep the LATEST committed delivery per key — cooldown measures time since\n // the user last saw the card, not since they first saw it.\n const lastDeliveredByKey = new Map<string, Date>();\n for (const row of opts.deliveredRows) {\n if (!(row.deliveredAt instanceof Date) || Number.isNaN(row.deliveredAt.getTime())) continue;\n const key = `${row.opportunityId}:${row.deliveredAtStatus}`;\n const existing = lastDeliveredByKey.get(key);\n if (!existing || row.deliveredAt > existing) lastDeliveredByKey.set(key, row.deliveredAt);\n }\n\n const fresh = afterAccepted.filter((opp) => !lastDeliveredByKey.has(`${opp.id}:${opp.status}`));\n if (fresh.length > 0) {\n if (fresh.length < afterAccepted.length) {\n logger.info(\n `[selectDigestCandidates] ledger dedup dropped ${afterAccepted.length - fresh.length} already-shown candidates`,\n );\n }\n return { pool: fresh, redeliveryIds: new Set<string>() };\n }\n\n // Rule 3: nothing fresh — re-show the least-recently-shown candidates past cooldown.\n const cooldownMs = (opts.cooldownDays ?? DIGEST_REDELIVERY_COOLDOWN_DAYS) * 86_400_000;\n const now = opts.now ?? new Date();\n const cooled = afterAccepted\n .map((opp) => ({ opp, at: lastDeliveredByKey.get(`${opp.id}:${opp.status}`) }))\n .filter((entry): entry is { opp: T; at: Date } =>\n entry.at instanceof Date && now.getTime() - entry.at.getTime() >= cooldownMs,\n )\n .sort((a, b) => a.at.getTime() - b.at.getTime());\n\n if (cooled.length > 0) {\n logger.info(\n `[selectDigestCandidates] no fresh candidates — re-showing ${cooled.length} past-cooldown candidate(s)`,\n );\n }\n return {\n pool: cooled.map((entry) => entry.opp),\n redeliveryIds: new Set(cooled.map((entry) => entry.opp.id)),\n };\n}\n"]}
@@ -0,0 +1,16 @@
1
+ import type { DefineTool, ToolDeps } from "../shared/agent/tool.helpers.js";
2
+ /**
3
+ * Creates MCP tool definitions for the questioner domain.
4
+ * Exposes `read_pending_questions` for retrieving the caller's pending
5
+ * questions generated by QuestionerAgent (profile, intent, negotiation, discovery modes).
6
+ *
7
+ * Network-scoped agent keys (context.networkId set via applyNetworkScopeToContext)
8
+ * are clamped to self-owned modes; the result then carries a `scopeRestriction`
9
+ * block mirroring the network-tools convention.
10
+ *
11
+ * @param defineTool - Tool factory provided by the composition root.
12
+ * @param deps - Shared tool dependencies; `findPendingQuestions` is optional
13
+ * and the tool fails gracefully when absent.
14
+ */
15
+ export declare function createQuestionerTools(defineTool: DefineTool, deps: ToolDeps): readonly [any];
16
+ //# sourceMappingURL=questioner.tools.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"questioner.tools.d.ts","sourceRoot":"/","sources":["questioner/questioner.tools.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAa5E;;;;;;;;;;;;GAYG;AACH,wBAAgB,qBAAqB,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,kBAuE3E"}
@@ -0,0 +1,90 @@
1
+ import { z } from "zod";
2
+ import { error, success } from "../shared/agent/tool.helpers.js";
3
+ /**
4
+ * Detection modes whose questions derive solely from the caller's own data
5
+ * (profile gaps, own intents, own discovery sessions). Negotiation-mode
6
+ * questions are excluded for network-scoped agents: their prompts are seeded
7
+ * from opportunity metadata that can reference out-of-scope networks and
8
+ * other users' content (same leak class as the getOpportunitiesForUser fix).
9
+ */
10
+ const SELF_OWNED_MODES = ["profile", "intent", "discovery"];
11
+ /**
12
+ * Creates MCP tool definitions for the questioner domain.
13
+ * Exposes `read_pending_questions` for retrieving the caller's pending
14
+ * questions generated by QuestionerAgent (profile, intent, negotiation, discovery modes).
15
+ *
16
+ * Network-scoped agent keys (context.networkId set via applyNetworkScopeToContext)
17
+ * are clamped to self-owned modes; the result then carries a `scopeRestriction`
18
+ * block mirroring the network-tools convention.
19
+ *
20
+ * @param defineTool - Tool factory provided by the composition root.
21
+ * @param deps - Shared tool dependencies; `findPendingQuestions` is optional
22
+ * and the tool fails gracefully when absent.
23
+ */
24
+ export function createQuestionerTools(defineTool, deps) {
25
+ const readPendingQuestions = defineTool({
26
+ name: "read_pending_questions",
27
+ description: "Returns pending questions generated for the authenticated user across all modes " +
28
+ "(profile, intent, negotiation, discovery). These are questions generated by the " +
29
+ "system to help surface missing signals, refine intents, or capture engagement context.\n\n" +
30
+ "**Returns:** List of pending questions, each with `id`, `title`, `prompt`, `options`, " +
31
+ "`multiSelect`, `mode`, `sourceType`, `sourceId`, `createdAt`, and optional `expiresAt`. " +
32
+ "Network-scoped agents receive only profile/intent/discovery questions plus a " +
33
+ "`scopeRestriction` note.\n\n" +
34
+ "**Use:** Call with no arguments to get all pending questions, or pass `limit` to cap the " +
35
+ "count. For the daily brief the script calls with a small `limit` and renders the first " +
36
+ "question that has not been delivered yet.",
37
+ querySchema: z.object({
38
+ limit: z
39
+ .number()
40
+ .int()
41
+ .min(1)
42
+ .max(10)
43
+ .optional()
44
+ .describe("Maximum number of questions to return (1-10, default 10)."),
45
+ }),
46
+ handler: async ({ context, query }) => {
47
+ if (!deps.findPendingQuestions) {
48
+ return error("Question lookup is not available.");
49
+ }
50
+ const limit = query.limit ?? 10;
51
+ // Scoped-key discriminator: applyNetworkScopeToContext sets networkId
52
+ // only for network-scoped agent keys (mcp.server.ts:558).
53
+ const isScoped = Boolean(context.networkId);
54
+ try {
55
+ const fetched = await deps.findPendingQuestions(context.userId, {
56
+ ...(isScoped ? { modes: SELF_OWNED_MODES } : {}),
57
+ limit,
58
+ });
59
+ // Defense-in-depth: hosts apply `modes`/`limit` SQL-side; re-apply both
60
+ // here so the clamp holds even when a custom dep ignores the filters.
61
+ const visible = isScoped
62
+ ? fetched.filter((q) => SELF_OWNED_MODES.includes(q.mode))
63
+ : fetched;
64
+ const limited = visible.slice(0, limit);
65
+ if (isScoped) {
66
+ return success({
67
+ questions: limited,
68
+ scopeRestriction: {
69
+ isScoped: true,
70
+ scopedToIndex: context.indexName ?? context.networkId,
71
+ message: `Results exclude negotiation questions because this agent is scoped to ` +
72
+ `"${context.indexName ?? "this index"}".`,
73
+ },
74
+ });
75
+ }
76
+ return success({ questions: limited });
77
+ }
78
+ catch (err) {
79
+ deps.reportToolError?.(err, {
80
+ operation: "read-pending-questions",
81
+ toolName: "read_pending_questions",
82
+ userId: context.userId,
83
+ });
84
+ return error("Failed to read pending questions.");
85
+ }
86
+ },
87
+ });
88
+ return [readPendingQuestions];
89
+ }
90
+ //# sourceMappingURL=questioner.tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"questioner.tools.js","sourceRoot":"/","sources":["questioner/questioner.tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,iCAAiC,CAAC;AAGjE;;;;;;GAMG;AACH,MAAM,gBAAgB,GAAmB,CAAC,SAAS,EAAE,QAAQ,EAAE,WAAW,CAAC,CAAC;AAE5E;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,qBAAqB,CAAC,UAAsB,EAAE,IAAc;IAC1E,MAAM,oBAAoB,GAAG,UAAU,CAAC;QACtC,IAAI,EAAE,wBAAwB;QAC9B,WAAW,EACT,kFAAkF;YAClF,kFAAkF;YAClF,4FAA4F;YAC5F,wFAAwF;YACxF,0FAA0F;YAC1F,+EAA+E;YAC/E,8BAA8B;YAC9B,2FAA2F;YAC3F,yFAAyF;YACzF,2CAA2C;QAC7C,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC;YACpB,KAAK,EAAE,CAAC;iBACL,MAAM,EAAE;iBACR,GAAG,EAAE;iBACL,GAAG,CAAC,CAAC,CAAC;iBACN,GAAG,CAAC,EAAE,CAAC;iBACP,QAAQ,EAAE;iBACV,QAAQ,CAAC,2DAA2D,CAAC;SACzE,CAAC;QACF,OAAO,EAAE,KAAK,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE;YACpC,IAAI,CAAC,IAAI,CAAC,oBAAoB,EAAE,CAAC;gBAC/B,OAAO,KAAK,CAAC,mCAAmC,CAAC,CAAC;YACpD,CAAC;YAED,MAAM,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CAAC,MAAM;iBACvB,CAAC,CAAC;gBACH,OAAO,KAAK,CAAC,mCAAmC,CAAC,CAAC;YACpD,CAAC;QACH,CAAC;KACF,CAAC,CAAC;IAEH,OAAO,CAAC,oBAAoB,CAAU,CAAC;AACzC,CAAC","sourcesContent":["import { z } from \"zod\";\n\nimport type { DefineTool, ToolDeps } from \"../shared/agent/tool.helpers.js\";\nimport { error, success } from \"../shared/agent/tool.helpers.js\";\nimport type { QuestionMode } from \"../shared/schemas/question.schema.js\";\n\n/**\n * Detection modes whose questions derive solely from the caller's own data\n * (profile gaps, own intents, own discovery sessions). Negotiation-mode\n * questions are excluded for network-scoped agents: their prompts are seeded\n * from opportunity metadata that can reference out-of-scope networks and\n * other users' content (same leak class as the getOpportunitiesForUser fix).\n */\nconst SELF_OWNED_MODES: QuestionMode[] = [\"profile\", \"intent\", \"discovery\"];\n\n/**\n * Creates MCP tool definitions for the questioner domain.\n * Exposes `read_pending_questions` for retrieving the caller's pending\n * questions generated by QuestionerAgent (profile, intent, negotiation, discovery modes).\n *\n * Network-scoped agent keys (context.networkId set via applyNetworkScopeToContext)\n * are clamped to self-owned modes; the result then carries a `scopeRestriction`\n * block mirroring the network-tools convention.\n *\n * @param defineTool - Tool factory provided by the composition root.\n * @param deps - Shared tool dependencies; `findPendingQuestions` is optional\n * and the tool fails gracefully when absent.\n */\nexport function createQuestionerTools(defineTool: DefineTool, deps: ToolDeps) {\n const readPendingQuestions = defineTool({\n name: \"read_pending_questions\",\n description:\n \"Returns pending questions generated for the authenticated user across all modes \" +\n \"(profile, intent, negotiation, discovery). These are questions generated by the \" +\n \"system to help surface missing signals, refine intents, or capture engagement context.\\n\\n\" +\n \"**Returns:** List of pending questions, each with `id`, `title`, `prompt`, `options`, \" +\n \"`multiSelect`, `mode`, `sourceType`, `sourceId`, `createdAt`, and optional `expiresAt`. \" +\n \"Network-scoped agents receive only profile/intent/discovery questions plus a \" +\n \"`scopeRestriction` note.\\n\\n\" +\n \"**Use:** Call with no arguments to get all pending questions, or pass `limit` to cap the \" +\n \"count. For the daily brief the script calls with a small `limit` and renders the first \" +\n \"question that has not been delivered yet.\",\n querySchema: z.object({\n limit: z\n .number()\n .int()\n .min(1)\n .max(10)\n .optional()\n .describe(\"Maximum number of questions to return (1-10, default 10).\"),\n }),\n handler: async ({ context, query }) => {\n if (!deps.findPendingQuestions) {\n return error(\"Question lookup is not available.\");\n }\n\n const limit = query.limit ?? 10;\n // Scoped-key discriminator: applyNetworkScopeToContext sets networkId\n // only for network-scoped agent keys (mcp.server.ts:558).\n const isScoped = Boolean(context.networkId);\n\n try {\n const fetched = await deps.findPendingQuestions(context.userId, {\n ...(isScoped ? { modes: SELF_OWNED_MODES } : {}),\n limit,\n });\n // Defense-in-depth: hosts apply `modes`/`limit` SQL-side; re-apply both\n // here so the clamp holds even when a custom dep ignores the filters.\n const visible = isScoped\n ? fetched.filter((q) => (SELF_OWNED_MODES as string[]).includes(q.mode))\n : fetched;\n const limited = visible.slice(0, limit);\n\n if (isScoped) {\n return success({\n questions: limited,\n scopeRestriction: {\n isScoped: true,\n scopedToIndex: context.indexName ?? context.networkId,\n message:\n `Results exclude negotiation questions because this agent is scoped to ` +\n `\"${context.indexName ?? \"this index\"}\".`,\n },\n });\n }\n\n return success({ questions: limited });\n } catch (err) {\n deps.reportToolError?.(err, {\n operation: \"read-pending-questions\",\n toolName: \"read_pending_questions\",\n userId: context.userId,\n });\n return error(\"Failed to read pending questions.\");\n }\n },\n });\n\n return [readPendingQuestions] as const;\n}\n"]}
@@ -23,6 +23,7 @@ import type { MintConnectLink } from "../interfaces/connect-link.interface.js";
23
23
  import type { QuestionerDatabase } from "../interfaces/questioner.interface.js";
24
24
  import type { QuestionerEnqueueFn } from "../../questioner/questioner.types.js";
25
25
  import type { PendingQuestionSummary } from "../schemas/pending-question.schema.js";
26
+ import type { QuestionMode } from "../schemas/question.schema.js";
26
27
  import type { DiscoveryRunQueue, DiscoveryRunStore } from "../interfaces/discovery-run.interface.js";
27
28
  import type { ProfileRunQueue, ProfileRunStore } from "../interfaces/profile-run.interface.js";
28
29
  export type ProfileContext = ProfileDocument | null;
@@ -323,13 +324,18 @@ export interface ToolDeps {
323
324
  */
324
325
  questionerEnqueue?: QuestionerEnqueueFn;
325
326
  /**
326
- * Lookup pending questions for a user, optionally filtered by source.
327
+ * Lookup pending questions for a user, optionally filtered by source,
328
+ * detection mode, or capped by count (hosts apply `limit` SQL-side).
327
329
  * Used by tools to attach contextually relevant questions to their results.
328
330
  * Injected by the composition root — absent when question delivery is disabled.
329
331
  */
330
332
  findPendingQuestions?: (userId: string, filters?: {
331
333
  sourceType?: string;
332
334
  sourceId?: string;
335
+ /** Restrict to questions whose detection mode is in this set. */
336
+ modes?: QuestionMode[];
337
+ /** Maximum rows to return; hosts should apply this in the query. */
338
+ limit?: number;
333
339
  }) => Promise<PendingQuestionSummary[]>;
334
340
  /** Negotiation-digest summarizer. Optional; consumers fall back to deterministic digests. */
335
341
  negotiationSummary?: NegotiationSummaryReader;
@@ -1 +1 @@
1
- {"version":3,"file":"tool.helpers.d.ts","sourceRoot":"/","sources":["shared/agent/tool.helpers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,KAAK,EACV,0BAA0B,EAC1B,iBAAiB,EACjB,UAAU,EACV,YAAY,EACZ,cAAc,EACd,wBAAwB,EACzB,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,oCAAoC,CAAC;AAClE,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AACzE,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,2CAA2C,CAAC;AAC1F,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wCA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