@indexnetwork/protocol 0.2.1 → 0.3.0
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/agents/opportunity.presenter.d.ts +1 -1
- package/dist/agents/opportunity.presenter.d.ts.map +1 -1
- package/dist/agents/opportunity.presenter.js +1 -1
- package/dist/agents/opportunity.presenter.js.map +1 -1
- package/dist/graphs/home.graph.d.ts +1 -1
- package/dist/graphs/home.graph.d.ts.map +1 -1
- package/dist/graphs/intent.graph.js +1 -1
- package/dist/graphs/intent.graph.js.map +1 -1
- package/dist/graphs/intent_network.graph.js +2 -2
- package/dist/graphs/intent_network.graph.js.map +1 -1
- package/dist/graphs/network.graph.js +1 -1
- package/dist/graphs/network.graph.js.map +1 -1
- package/dist/graphs/network_membership.graph.js +2 -2
- package/dist/graphs/network_membership.graph.js.map +1 -1
- package/dist/graphs/opportunity.graph.d.ts +11 -11
- package/dist/graphs/opportunity.graph.d.ts.map +1 -1
- package/dist/graphs/opportunity.graph.js +28 -28
- package/dist/graphs/opportunity.graph.js.map +1 -1
- package/dist/graphs/tests/chat.graph.mocks.d.ts +1 -1
- package/dist/graphs/tests/chat.graph.mocks.d.ts.map +1 -1
- package/dist/graphs/tests/chat.graph.mocks.js +10 -10
- package/dist/graphs/tests/chat.graph.mocks.js.map +1 -1
- package/dist/interfaces/database.interface.d.ts +22 -22
- package/dist/interfaces/database.interface.d.ts.map +1 -1
- package/dist/states/opportunity.state.d.ts +2 -2
- package/dist/states/opportunity.state.d.ts.map +1 -1
- package/dist/states/opportunity.state.js +1 -1
- package/dist/states/opportunity.state.js.map +1 -1
- package/dist/tools/profile.tools.js +2 -2
- package/dist/tools/profile.tools.js.map +1 -1
- package/dist/tools/tool.helpers.d.ts +2 -2
- package/dist/tools/tool.helpers.d.ts.map +1 -1
- package/dist/tools/tool.helpers.js +2 -2
- package/dist/tools/tool.helpers.js.map +1 -1
- package/package.json +1 -1
|
@@ -197,7 +197,7 @@ export class OpportunityGraphFactory {
|
|
|
197
197
|
networkId: state.networkId,
|
|
198
198
|
});
|
|
199
199
|
return {
|
|
200
|
-
|
|
200
|
+
targetNetworks: [],
|
|
201
201
|
error: 'You are not a member of that network.',
|
|
202
202
|
};
|
|
203
203
|
}
|
|
@@ -208,9 +208,9 @@ export class OpportunityGraphFactory {
|
|
|
208
208
|
targetIndexIds = state.userNetworks;
|
|
209
209
|
}
|
|
210
210
|
// Fetch index details
|
|
211
|
-
const
|
|
212
|
-
const index = await this.database.
|
|
213
|
-
const memberCount = await this.database.
|
|
211
|
+
const targetNetworks = await Promise.all(targetIndexIds.map(async (networkId) => {
|
|
212
|
+
const index = await this.database.getNetwork(networkId);
|
|
213
|
+
const memberCount = await this.database.getNetworkMemberCount(networkId);
|
|
214
214
|
return {
|
|
215
215
|
networkId,
|
|
216
216
|
title: index?.title ?? 'Unknown',
|
|
@@ -218,8 +218,8 @@ export class OpportunityGraphFactory {
|
|
|
218
218
|
};
|
|
219
219
|
}));
|
|
220
220
|
logger.verbose('[Graph:Scope] Scope determined', {
|
|
221
|
-
targetIndexesCount:
|
|
222
|
-
indexes:
|
|
221
|
+
targetIndexesCount: targetNetworks.length,
|
|
222
|
+
indexes: targetNetworks.map(i => i.title),
|
|
223
223
|
});
|
|
224
224
|
// ── Populate index relevancy scores for dedup tie-breaking ──
|
|
225
225
|
let indexRelevancyScores = {};
|
|
@@ -242,9 +242,9 @@ export class OpportunityGraphFactory {
|
|
|
242
242
|
try {
|
|
243
243
|
const indexer = new IntentIndexer();
|
|
244
244
|
const scopeAgentTimings = [];
|
|
245
|
-
const scorableIndexes =
|
|
245
|
+
const scorableIndexes = targetNetworks.filter(ti => ti.title !== 'Unknown');
|
|
246
246
|
const scoringPromises = scorableIndexes.map(async (ti) => {
|
|
247
|
-
const ctx = await this.database.
|
|
247
|
+
const ctx = await this.database.getNetworkMemberContext(ti.networkId, state.userId);
|
|
248
248
|
if (!ctx?.indexPrompt?.trim() && !ctx?.memberPrompt?.trim()) {
|
|
249
249
|
return { networkId: ti.networkId, score: 1.0 };
|
|
250
250
|
}
|
|
@@ -277,13 +277,13 @@ export class OpportunityGraphFactory {
|
|
|
277
277
|
// Accumulate indexer timings into graph state
|
|
278
278
|
if (scopeAgentTimings.length > 0) {
|
|
279
279
|
return {
|
|
280
|
-
|
|
280
|
+
targetNetworks,
|
|
281
281
|
indexRelevancyScores,
|
|
282
282
|
agentTimings: scopeAgentTimings,
|
|
283
283
|
trace: [{
|
|
284
284
|
node: "scope",
|
|
285
|
-
detail: `Searching ${
|
|
286
|
-
data: { totalMembers:
|
|
285
|
+
detail: `Searching ${targetNetworks.length} index(es): ${targetNetworks.map(i => `${i.title} (${i.memberCount})`).join(', ')}`,
|
|
286
|
+
data: { totalMembers: targetNetworks.reduce((sum, i) => sum + i.memberCount, 0) },
|
|
287
287
|
}],
|
|
288
288
|
};
|
|
289
289
|
}
|
|
@@ -292,13 +292,13 @@ export class OpportunityGraphFactory {
|
|
|
292
292
|
logger.warn('[Graph:Scope] Failed to score query against indexes', { error: err });
|
|
293
293
|
}
|
|
294
294
|
}
|
|
295
|
-
const totalMembers =
|
|
295
|
+
const totalMembers = targetNetworks.reduce((sum, i) => sum + i.memberCount, 0);
|
|
296
296
|
return {
|
|
297
|
-
|
|
297
|
+
targetNetworks,
|
|
298
298
|
indexRelevancyScores,
|
|
299
299
|
trace: [{
|
|
300
300
|
node: "scope",
|
|
301
|
-
detail: `Searching ${
|
|
301
|
+
detail: `Searching ${targetNetworks.length} index(es): ${targetNetworks.map(i => `${i.title} (${i.memberCount})`).join(', ')}`,
|
|
302
302
|
data: { totalMembers },
|
|
303
303
|
}],
|
|
304
304
|
};
|
|
@@ -307,7 +307,7 @@ export class OpportunityGraphFactory {
|
|
|
307
307
|
const errMsg = error instanceof Error ? error.message : String(error);
|
|
308
308
|
logger.error('[Graph:Scope] Failed', { error });
|
|
309
309
|
return {
|
|
310
|
-
|
|
310
|
+
targetNetworks: [],
|
|
311
311
|
error: 'Failed to determine search scope.',
|
|
312
312
|
trace: [{
|
|
313
313
|
node: "scope_fatal",
|
|
@@ -321,7 +321,7 @@ export class OpportunityGraphFactory {
|
|
|
321
321
|
const r = result;
|
|
322
322
|
if (r?.error)
|
|
323
323
|
return `error: ${r.error}`;
|
|
324
|
-
const indexes = r?.
|
|
324
|
+
const indexes = r?.targetNetworks;
|
|
325
325
|
return indexes ? `${indexes.length} index(es) in scope` : undefined;
|
|
326
326
|
});
|
|
327
327
|
/**
|
|
@@ -336,7 +336,7 @@ export class OpportunityGraphFactory {
|
|
|
336
336
|
hasSearchQuery: !!state.searchQuery,
|
|
337
337
|
indexedIntentsCount: state.indexedIntents.length,
|
|
338
338
|
});
|
|
339
|
-
const targetIndexIds = state.
|
|
339
|
+
const targetIndexIds = state.targetNetworks.map((t) => t.networkId);
|
|
340
340
|
try {
|
|
341
341
|
let resolvedIntentId;
|
|
342
342
|
if (state.triggerIntentId) {
|
|
@@ -428,12 +428,12 @@ export class OpportunityGraphFactory {
|
|
|
428
428
|
// Shared variable to capture HyDE output (lenses + documents) for trace entries
|
|
429
429
|
let discoveryHydeOutput;
|
|
430
430
|
logger.verbose('[Graph:Discovery] Starting semantic search', {
|
|
431
|
-
targetIndexesCount: state.
|
|
431
|
+
targetIndexesCount: state.targetNetworks.length,
|
|
432
432
|
discoverySource: state.discoverySource,
|
|
433
433
|
searchQueryPreview: state.searchQuery?.trim().slice(0, 60) ?? '(none)',
|
|
434
434
|
});
|
|
435
435
|
try {
|
|
436
|
-
if (state.
|
|
436
|
+
if (state.targetNetworks.length === 0) {
|
|
437
437
|
logger.warn('[Graph:Discovery] No target indexes for search');
|
|
438
438
|
return { candidates: [] };
|
|
439
439
|
}
|
|
@@ -459,13 +459,13 @@ export class OpportunityGraphFactory {
|
|
|
459
459
|
});
|
|
460
460
|
const targetMemberships = await this.database.getNetworkMemberships(state.targetUserId);
|
|
461
461
|
const targetUserIndexIds = targetMemberships.map(m => m.networkId);
|
|
462
|
-
const sharedIndexIds = state.
|
|
462
|
+
const sharedIndexIds = state.targetNetworks
|
|
463
463
|
.filter(ti => targetUserIndexIds.includes(ti.networkId))
|
|
464
464
|
.map(ti => ti.networkId);
|
|
465
465
|
if (sharedIndexIds.length === 0) {
|
|
466
466
|
logger.warn('[Graph:Discovery] Target user shares no indexes with discoverer', {
|
|
467
467
|
targetUserId: state.targetUserId,
|
|
468
|
-
discovererIndexes: state.
|
|
468
|
+
discovererIndexes: state.targetNetworks.map(ti => ti.networkId),
|
|
469
469
|
});
|
|
470
470
|
return {
|
|
471
471
|
candidates: [],
|
|
@@ -607,7 +607,7 @@ export class OpportunityGraphFactory {
|
|
|
607
607
|
// If we also have a profile vector, merge with profile-based results
|
|
608
608
|
if (vector && vector.length > 0) {
|
|
609
609
|
const profileCandidates = [];
|
|
610
|
-
for (const targetIndex of state.
|
|
610
|
+
for (const targetIndex of state.targetNetworks) {
|
|
611
611
|
const results = await this.embedder.searchWithProfileEmbedding(vector, {
|
|
612
612
|
indexScope: [targetIndex.networkId],
|
|
613
613
|
excludeUserId: discoveryUserId,
|
|
@@ -659,7 +659,7 @@ export class OpportunityGraphFactory {
|
|
|
659
659
|
return { candidates: [] };
|
|
660
660
|
}
|
|
661
661
|
const allCandidates = [];
|
|
662
|
-
for (const targetIndex of state.
|
|
662
|
+
for (const targetIndex of state.targetNetworks) {
|
|
663
663
|
const results = await this.embedder.searchWithProfileEmbedding(vector, {
|
|
664
664
|
indexScope: [targetIndex.networkId],
|
|
665
665
|
excludeUserId: discoveryUserId,
|
|
@@ -796,7 +796,7 @@ export class OpportunityGraphFactory {
|
|
|
796
796
|
}
|
|
797
797
|
}
|
|
798
798
|
const all = [];
|
|
799
|
-
await Promise.all(state.
|
|
799
|
+
await Promise.all(state.targetNetworks.map(async (targetIndex) => {
|
|
800
800
|
const results = await self.embedder.searchWithHydeEmbeddings(lensEmbeddings, {
|
|
801
801
|
indexScope: [targetIndex.networkId],
|
|
802
802
|
excludeUserId: discoveryUserId,
|
|
@@ -879,7 +879,7 @@ export class OpportunityGraphFactory {
|
|
|
879
879
|
}
|
|
880
880
|
}
|
|
881
881
|
const allCandidates = [];
|
|
882
|
-
await Promise.all(state.
|
|
882
|
+
await Promise.all(state.targetNetworks.map(async (targetIndex) => {
|
|
883
883
|
const results = await this.embedder.searchWithHydeEmbeddings(lensEmbeddings, {
|
|
884
884
|
indexScope: [targetIndex.networkId],
|
|
885
885
|
excludeUserId: discoveryUserId,
|
|
@@ -1522,7 +1522,7 @@ export class OpportunityGraphFactory {
|
|
|
1522
1522
|
const uniqueIndexIds = [...new Set(candidates.map(c => c.networkId).filter((id) => !!id))];
|
|
1523
1523
|
const indexContextMap = new Map();
|
|
1524
1524
|
await Promise.all(uniqueIndexIds.map(async (networkId) => {
|
|
1525
|
-
const ctx = await this.database.
|
|
1525
|
+
const ctx = await this.database.getNetworkMemberContext(networkId, discoveryUserId).catch(() => null);
|
|
1526
1526
|
const prompt = [ctx?.indexPrompt, ctx?.memberPrompt]
|
|
1527
1527
|
.filter((v) => !!v?.trim())
|
|
1528
1528
|
.join('\n\n');
|
|
@@ -2215,7 +2215,7 @@ export class OpportunityGraphFactory {
|
|
|
2215
2215
|
const counterpartActor = opp.actors.find((a) => a.userId !== state.userId);
|
|
2216
2216
|
const actorIndexId = counterpartActor?.networkId ?? opp.actors[0]?.networkId;
|
|
2217
2217
|
const [indexRecord, ...profileAndUserPairs] = await Promise.all([
|
|
2218
|
-
actorIndexId ? this.database.
|
|
2218
|
+
actorIndexId ? this.database.getNetwork(actorIndexId) : Promise.resolve(null),
|
|
2219
2219
|
...idsToResolve.map(async (uid) => {
|
|
2220
2220
|
const [profile, user] = await Promise.all([
|
|
2221
2221
|
this.database.getProfile(uid),
|
|
@@ -2450,7 +2450,7 @@ export class OpportunityGraphFactory {
|
|
|
2450
2450
|
* After scope: check if we have target indexes.
|
|
2451
2451
|
*/
|
|
2452
2452
|
const shouldContinueAfterScope = (state) => {
|
|
2453
|
-
if (state.error || state.
|
|
2453
|
+
if (state.error || state.targetNetworks.length === 0) {
|
|
2454
2454
|
logger.verbose('[Graph:Routing] No target indexes - ending early');
|
|
2455
2455
|
return END;
|
|
2456
2456
|
}
|