@indexnetwork/protocol 4.3.2 → 4.3.3-rc.308.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 (84) hide show
  1. package/dist/chat/chat.prompt.js +1 -1
  2. package/dist/chat/chat.prompt.js.map +1 -1
  3. package/dist/index.d.ts +5 -3
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +2 -1
  6. package/dist/index.js.map +1 -1
  7. package/dist/intent/intent.graph.d.ts +10 -0
  8. package/dist/intent/intent.graph.d.ts.map +1 -1
  9. package/dist/intent/intent.graph.js +6 -2
  10. package/dist/intent/intent.graph.js.map +1 -1
  11. package/dist/intent/intent.state.d.ts +4 -0
  12. package/dist/intent/intent.state.d.ts.map +1 -1
  13. package/dist/intent/intent.state.js +10 -0
  14. package/dist/intent/intent.state.js.map +1 -1
  15. package/dist/intent/intent.tools.d.ts.map +1 -1
  16. package/dist/intent/intent.tools.js +7 -0
  17. package/dist/intent/intent.tools.js.map +1 -1
  18. package/dist/mcp/mcp.server.d.ts +44 -15
  19. package/dist/mcp/mcp.server.d.ts.map +1 -1
  20. package/dist/mcp/mcp.server.js +88 -38
  21. package/dist/mcp/mcp.server.js.map +1 -1
  22. package/dist/network/network.graph.js +2 -2
  23. package/dist/network/network.graph.js.map +1 -1
  24. package/dist/opportunity/opportunity.discover.d.ts +5 -0
  25. package/dist/opportunity/opportunity.discover.d.ts.map +1 -1
  26. package/dist/opportunity/opportunity.discover.js +3 -0
  27. package/dist/opportunity/opportunity.discover.js.map +1 -1
  28. package/dist/opportunity/opportunity.graph.d.ts +6 -6
  29. package/dist/opportunity/opportunity.pending-questions.d.ts +3 -0
  30. package/dist/opportunity/opportunity.pending-questions.d.ts.map +1 -1
  31. package/dist/opportunity/opportunity.pending-questions.js +7 -2
  32. package/dist/opportunity/opportunity.pending-questions.js.map +1 -1
  33. package/dist/opportunity/opportunity.state.d.ts +1 -1
  34. package/dist/opportunity/opportunity.tools.d.ts.map +1 -1
  35. package/dist/opportunity/opportunity.tools.js +31 -17
  36. package/dist/opportunity/opportunity.tools.js.map +1 -1
  37. package/dist/premise/premise.graph.d.ts +13 -1
  38. package/dist/premise/premise.graph.d.ts.map +1 -1
  39. package/dist/premise/premise.graph.js +11 -6
  40. package/dist/premise/premise.graph.js.map +1 -1
  41. package/dist/premise/premise.state.d.ts +5 -0
  42. package/dist/premise/premise.state.d.ts.map +1 -1
  43. package/dist/premise/premise.state.js +11 -0
  44. package/dist/premise/premise.state.js.map +1 -1
  45. package/dist/premise/premise.tools.d.ts.map +1 -1
  46. package/dist/premise/premise.tools.js +5 -0
  47. package/dist/premise/premise.tools.js.map +1 -1
  48. package/dist/questioner/questioner.tools.d.ts.map +1 -1
  49. package/dist/questioner/questioner.tools.js +23 -11
  50. package/dist/questioner/questioner.tools.js.map +1 -1
  51. package/dist/questioner/questioner.types.d.ts +5 -0
  52. package/dist/questioner/questioner.types.d.ts.map +1 -1
  53. package/dist/questioner/questioner.types.js.map +1 -1
  54. package/dist/shared/agent/tool.factory.d.ts.map +1 -1
  55. package/dist/shared/agent/tool.factory.js +24 -14
  56. package/dist/shared/agent/tool.factory.js.map +1 -1
  57. package/dist/shared/agent/tool.helpers.d.ts +17 -18
  58. package/dist/shared/agent/tool.helpers.d.ts.map +1 -1
  59. package/dist/shared/agent/tool.helpers.js +10 -11
  60. package/dist/shared/agent/tool.helpers.js.map +1 -1
  61. package/dist/shared/agent/tool.scope.d.ts +27 -0
  62. package/dist/shared/agent/tool.scope.d.ts.map +1 -0
  63. package/dist/shared/agent/tool.scope.js +27 -0
  64. package/dist/shared/agent/tool.scope.js.map +1 -0
  65. package/dist/shared/assignment/network-assignment.policy.d.ts +8 -5
  66. package/dist/shared/assignment/network-assignment.policy.d.ts.map +1 -1
  67. package/dist/shared/assignment/network-assignment.policy.js +11 -6
  68. package/dist/shared/assignment/network-assignment.policy.js.map +1 -1
  69. package/dist/shared/hyde/hyde.graph.d.ts +6 -6
  70. package/dist/shared/hyde/hyde.state.d.ts +2 -2
  71. package/dist/shared/interfaces/database.interface.d.ts +15 -3
  72. package/dist/shared/interfaces/database.interface.d.ts.map +1 -1
  73. package/dist/shared/interfaces/database.interface.js.map +1 -1
  74. package/dist/shared/interfaces/discovery-run.interface.d.ts +1 -1
  75. package/dist/shared/interfaces/discovery-run.interface.d.ts.map +1 -1
  76. package/dist/shared/interfaces/discovery-run.interface.js.map +1 -1
  77. package/dist/shared/interfaces/queue.interface.d.ts +8 -2
  78. package/dist/shared/interfaces/queue.interface.d.ts.map +1 -1
  79. package/dist/shared/interfaces/queue.interface.js.map +1 -1
  80. package/dist/shared/schemas/network-assignment.schema.d.ts +2 -2
  81. package/dist/shared/schemas/pending-question.schema.d.ts +5 -0
  82. package/dist/shared/schemas/pending-question.schema.d.ts.map +1 -1
  83. package/dist/shared/schemas/pending-question.schema.js.map +1 -1
  84. package/package.json +1 -1
@@ -259,7 +259,7 @@ export declare const OpportunityGraphState: import("@langchain/langgraph").Annot
259
259
  /** Per-index relevancy scores for dedup tie-breaking. Background path: from intent_indexes. Chat path: transient from IntentIndexer. */
260
260
  indexRelevancyScores: import("@langchain/langgraph").BaseChannel<Record<string, number>, Record<string, number> | import("@langchain/langgraph").OverwriteValue<Record<string, number>>, unknown>;
261
261
  /** Whether discovery used intent (path A) or user context (path B/C). Used by persist for triggeredBy. In-memory routing state only; never persisted. */
262
- discoverySource: import("@langchain/langgraph").BaseChannel<"intent" | "context", "intent" | "context" | import("@langchain/langgraph").OverwriteValue<"intent" | "context">, unknown>;
262
+ discoverySource: import("@langchain/langgraph").BaseChannel<"context" | "intent", "context" | "intent" | import("@langchain/langgraph").OverwriteValue<"context" | "intent">, unknown>;
263
263
  /** Resolved intent ID used for this discovery run (when discoverySource is 'intent'). Set by intent-resolution. */
264
264
  resolvedTriggerIntentId: import("@langchain/langgraph").BaseChannel<Id<"intents"> | undefined, Id<"intents"> | import("@langchain/langgraph").OverwriteValue<Id<"intents"> | undefined> | undefined, unknown>;
265
265
  /** Asker's profile (from prep). Used for profile-as-source discovery and evaluation. */
@@ -1 +1 @@
1
- {"version":3,"file":"opportunity.tools.d.ts","sourceRoot":"/","sources":["opportunity/opportunity.tools.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AA8B5E,OAAO,KAAK,EAAE,WAAW,EAAqB,MAAM,4CAA4C,CAAC;AAEjG,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gDAAgD,CAAC;AAOtF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,yBAAyB,CAAC,KAAK,EAAE;IAC/C,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,GAAG,eAAe,GAAG,IAAI,CAczB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,eAAe,CAC7B,iBAAiB,EAAE,MAAM,EACzB,WAAW,EAAE,MAAM,GAAG,SAAS,GAC9B,MAAM,GAAG,SAAS,CAQpB;AAED;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CACjC,cAAc,EAAE,MAAM,GAAG,SAAS,EAClC,WAAW,EAAE,MAAM,GAAG,SAAS,GAC9B,MAAM,GAAG,SAAS,CAIpB;AAED;;;;;;;GAOG;AACH,wBAAsB,qBAAqB,CACzC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAC9B,aAAa,EAAE,MAAM,CAAC;IACtB,UAAU,EAAE,MAAM,CAAC;IACnB,MAAM,EAAE,MAAM,CAAC;CAChB,EACD,IAAI,EAAE;IACJ,QAAQ,EAAE,MAAM,CAAC;IACjB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,WAAW,CAAC,QAAQ,CAAC,iBAAiB,CAAC,CAAC,CAAC;IAC1D,WAA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AAoB,GACpB,wBAAwB,GACxB,uBAAuB,GACvB,gBAAgB,GAChB,gBAAgB,CAAC;AAUrB,wBAAgB,sBAAsB,CAAC,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,2CA4uD5E"}
@@ -1,6 +1,7 @@
1
1
  import { z } from "zod";
2
2
  import { requestContext } from "../shared/observability/request-context.js";
3
3
  import { success, error, UUID_REGEX } from "../shared/agent/tool.helpers.js";
4
+ import { deriveDiscoveryNetworkIds } from "../shared/agent/tool.scope.js";
4
5
  import { MINIMAL_MAIN_TEXT_MAX_CHARS, getPrimaryActionLabel, SECONDARY_ACTION_LABEL } from "./opportunity.labels.js";
5
6
  import { viewerCentricCardSummary, narratorRemarkFromReasoning, stripUuids } from "./opportunity.presentation.js";
6
7
  import { runDiscoverFromQuery, continueDiscovery } from "./opportunity.discover.js";
@@ -382,16 +383,20 @@ function discoveryRunSignature(input, scopeKey) {
382
383
  }
383
384
  /**
384
385
  * Stable key for the resolved discovery scope of a request. Two requests
385
- * coalesce only when they resolve to the same reach the focus index
386
- * (`networkId`) and the full reachable `indexScope` set. When `query.networkId`
387
- * is omitted, scope comes from context (network-scoped agent vs unscoped
388
- * session), so folding it into the signature prevents a scoped caller from
389
- * coalescing onto an unscoped run and receiving out-of-scope opportunities.
386
+ * coalesce only when they resolve to the same focused discovery boundary. For
387
+ * scoped contexts, that boundary is the scope envelope (`scopeType`/`scopeId`),
388
+ * not the personal-inclusive allowed network reach used for self-owned writes.
389
+ * When no scope envelope is present, legacy `indexScope` remains part of the
390
+ * key so older contexts with different unscoped reach do not coalesce.
390
391
  */
391
392
  function discoveryScopeKey(ctx) {
392
393
  return JSON.stringify({
393
394
  networkId: (ctx.networkId ?? "").trim(),
394
- indexScope: [...(ctx.indexScope ?? [])].map((s) => s.trim()).sort(),
395
+ scopeType: (ctx.scopeType ?? "").trim(),
396
+ scopeId: (ctx.scopeId ?? "").trim(),
397
+ indexScope: ctx.scopeType && ctx.scopeId
398
+ ? []
399
+ : [...(ctx.indexScope ?? [])].map((s) => s.trim()).sort(),
395
400
  });
396
401
  }
397
402
  function confirmDeliveryError(code, retryable, message) {
@@ -458,7 +463,7 @@ export function createOpportunityTools(defineTool, deps) {
458
463
  networkId: z
459
464
  .string()
460
465
  .optional()
461
- .describe("Index UUID to scope discovery to a specific community. Get from read_networks. In an index-scoped chat, omitting this runs discovery across the full reachable scope (the bound community plus the user's personal index); pass an explicit networkId to force single-index discovery. Pass the personal index ID (from read_networks, isPersonal=true) to scope to the user's contacts only."),
466
+ .describe("Index UUID to scope discovery to a specific community. Get from read_networks. In an index-scoped chat, omitting this runs discovery only in the scoped community; pass the personal index ID (from read_networks, isPersonal=true) only when the user explicitly asks to discover among contacts."),
462
467
  intentId: z
463
468
  .string()
464
469
  .optional()
@@ -521,11 +526,9 @@ export function createOpportunityTools(defineTool, deps) {
521
526
  return error(`This chat is scoped to ${context.indexName ?? "this index"}. You can only create opportunities in this community.`);
522
527
  }
523
528
  // Distinguish an explicit `query.networkId` override (caller wants discovery
524
- // scoped to one specific index) from an implicit scoped-chat context
525
- // (caller is in a scoped chat with no explicit override — discovery should
526
- // span the chat's reach, i.e. context.indexScope = [bound, personal]).
527
- // Conflating them via `context.networkId || query.networkId` made the
528
- // implicit branch unreachable.
529
+ // scoped to one specific index) from an implicit scoped-chat context.
530
+ // Scoped-chat discovery stays focused to the scoped community only; the
531
+ // personal-inclusive allowed reach is reserved for self-owned writes.
529
532
  const explicitIndexId = query.networkId?.trim() || undefined;
530
533
  const effectiveIndexId = explicitIndexId;
531
534
  if (effectiveIndexId && !UUID_REGEX.test(effectiveIndexId)) {
@@ -566,6 +569,7 @@ export function createOpportunityTools(defineTool, deps) {
566
569
  userName: context.userName,
567
570
  userEmail: context.userEmail,
568
571
  ...(context.networkId ? { networkId: context.networkId } : {}),
572
+ ...(context.scopeType && context.scopeId ? { scopeType: context.scopeType, scopeId: context.scopeId } : {}),
569
573
  ...(context.indexName ? { indexName: context.indexName } : {}),
570
574
  indexScope: context.indexScope,
571
575
  ...(context.sessionId ? { sessionId: context.sessionId } : {}),
@@ -863,12 +867,20 @@ export function createOpportunityTools(defineTool, deps) {
863
867
  }
864
868
  indexScope = [effectiveIndexId];
865
869
  }
870
+ else if (context.scopeType === 'network' && context.scopeId) {
871
+ // Scoped chat: discovery is focused-network only. Self-owned writes may
872
+ // include personal indexes, but opportunity visibility must not.
873
+ const scopedDiscoveryIds = deriveDiscoveryNetworkIds({
874
+ memberships: context.userNetworks,
875
+ scopeType: context.scopeType,
876
+ scopeId: context.scopeId,
877
+ });
878
+ indexScope = scopedDiscoveryIds;
879
+ }
866
880
  else if (context.networkId) {
867
- // Scoped chat: use the agent's full reach so personal-index
868
- // signals participate in opportunity discovery. See IND-306.
869
- indexScope = context.indexScope.length > 0
870
- ? [...context.indexScope]
871
- : [context.networkId];
881
+ // Legacy scoped context without a scope envelope: preserve focused-only
882
+ // discovery using the focused network id.
883
+ indexScope = [context.networkId];
872
884
  }
873
885
  else {
874
886
  // No scope - use all indexes (only in unscoped chat)
@@ -933,6 +945,7 @@ export function createOpportunityTools(defineTool, deps) {
933
945
  ...(deps.chatSummary && { chatSummary: deps.chatSummary }),
934
946
  ...(deps.questionGenerator && { questionGenerator: deps.questionGenerator }),
935
947
  ...(deps.questionerEnqueue && { questionerEnqueue: deps.questionerEnqueue }),
948
+ ...(context.scopeType && context.scopeId ? { scopeType: context.scopeType, scopeId: context.scopeId } : {}),
936
949
  ...(deps.negotiationSummary && { negotiationSummary: deps.negotiationSummary }),
937
950
  // Decision questions add an LLM call after the negotiation phase.
938
951
  // Capped at DISCOVERY_QUESTIONS_TIMEOUT_MS (12 s default,
@@ -956,6 +969,7 @@ export function createOpportunityTools(defineTool, deps) {
956
969
  findPendingQuestions: deps.findPendingQuestions,
957
970
  userId: context.userId,
958
971
  sourceType: 'discovery',
972
+ ...(context.scopeType === 'network' && context.scopeId ? { networkId: context.scopeId } : {}),
959
973
  surfacedQuestionIds: new Set(), // Dedup handled at chat.agent level
960
974
  });
961
975
  const pendingQuestions = pendingQuestionResult.questions;