@indexnetwork/protocol 4.3.3-rc.308.1 → 4.3.4-rc.310.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/IMPLEMENTATION.md +2 -2
- package/dist/chat/chat.agent.d.ts +1 -1
- package/dist/chat/chat.agent.d.ts.map +1 -1
- package/dist/chat/chat.agent.js +12 -2
- package/dist/chat/chat.agent.js.map +1 -1
- package/dist/chat/chat.graph.d.ts +16 -0
- package/dist/chat/chat.graph.d.ts.map +1 -1
- package/dist/chat/chat.graph.js +5 -2
- package/dist/chat/chat.graph.js.map +1 -1
- package/dist/chat/chat.prompt.d.ts.map +1 -1
- package/dist/chat/chat.prompt.js +44 -37
- package/dist/chat/chat.prompt.js.map +1 -1
- package/dist/chat/chat.prompt.modules.js +8 -8
- package/dist/chat/chat.prompt.modules.js.map +1 -1
- package/dist/chat/chat.state.d.ts +7 -4
- package/dist/chat/chat.state.d.ts.map +1 -1
- package/dist/chat/chat.state.js +12 -3
- package/dist/chat/chat.state.js.map +1 -1
- package/dist/chat/chat.streamer.d.ts +5 -0
- package/dist/chat/chat.streamer.d.ts.map +1 -1
- package/dist/chat/chat.streamer.js +13 -4
- package/dist/chat/chat.streamer.js.map +1 -1
- package/dist/chat/tests/chat.graph.mocks.d.ts +1 -1
- package/dist/chat/tests/chat.graph.mocks.js +1 -1
- package/dist/chat/tests/chat.graph.mocks.js.map +1 -1
- package/dist/contact/contact.tools.js +6 -6
- package/dist/contact/contact.tools.js.map +1 -1
- package/dist/enrichment/enrichment.tools.d.ts.map +1 -1
- package/dist/enrichment/enrichment.tools.js +23 -26
- package/dist/enrichment/enrichment.tools.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/integration/integration.tools.js +1 -1
- package/dist/integration/integration.tools.js.map +1 -1
- package/dist/intent/intent.graph.d.ts.map +1 -1
- package/dist/intent/intent.graph.js +9 -9
- package/dist/intent/intent.graph.js.map +1 -1
- package/dist/intent/intent.indexer.d.ts +1 -1
- package/dist/intent/intent.indexer.js +4 -4
- package/dist/intent/intent.indexer.js.map +1 -1
- package/dist/intent/intent.state.d.ts +8 -8
- package/dist/intent/intent.state.js +8 -8
- package/dist/intent/intent.state.js.map +1 -1
- package/dist/intent/intent.tools.d.ts.map +1 -1
- package/dist/intent/intent.tools.js +87 -70
- package/dist/intent/intent.tools.js.map +1 -1
- package/dist/maintenance/maintenance.graph.d.ts +2 -2
- package/dist/maintenance/maintenance.graph.d.ts.map +1 -1
- package/dist/maintenance/maintenance.graph.js.map +1 -1
- package/dist/mcp/mcp.server.d.ts +5 -7
- package/dist/mcp/mcp.server.d.ts.map +1 -1
- package/dist/mcp/mcp.server.js +11 -20
- package/dist/mcp/mcp.server.js.map +1 -1
- package/dist/negotiation/negotiation.tools.d.ts.map +1 -1
- package/dist/negotiation/negotiation.tools.js +11 -7
- package/dist/negotiation/negotiation.tools.js.map +1 -1
- package/dist/network/indexer/indexer.graph.d.ts +2 -2
- package/dist/network/indexer/indexer.graph.d.ts.map +1 -1
- package/dist/network/indexer/indexer.graph.js +13 -13
- package/dist/network/indexer/indexer.graph.js.map +1 -1
- package/dist/network/indexer/indexer.state.d.ts +3 -3
- package/dist/network/indexer/indexer.state.d.ts.map +1 -1
- package/dist/network/indexer/indexer.state.js +4 -4
- package/dist/network/indexer/indexer.state.js.map +1 -1
- package/dist/network/membership/membership.graph.d.ts +1 -1
- package/dist/network/membership/membership.graph.js +21 -21
- package/dist/network/membership/membership.graph.js.map +1 -1
- package/dist/network/membership/membership.state.d.ts +2 -2
- package/dist/network/membership/membership.state.js +2 -2
- package/dist/network/membership/membership.state.js.map +1 -1
- package/dist/network/network.graph.d.ts +1 -1
- package/dist/network/network.graph.d.ts.map +1 -1
- package/dist/network/network.graph.js +13 -13
- package/dist/network/network.graph.js.map +1 -1
- package/dist/network/network.state.d.ts +3 -3
- package/dist/network/network.state.d.ts.map +1 -1
- package/dist/network/network.state.js +3 -3
- package/dist/network/network.state.js.map +1 -1
- package/dist/network/network.tools.js +68 -68
- package/dist/network/network.tools.js.map +1 -1
- package/dist/opportunity/opportunity.discover.d.ts +1 -1
- package/dist/opportunity/opportunity.discover.d.ts.map +1 -1
- package/dist/opportunity/opportunity.discover.js +1 -1
- package/dist/opportunity/opportunity.discover.js.map +1 -1
- package/dist/opportunity/opportunity.graph.js +11 -11
- package/dist/opportunity/opportunity.graph.js.map +1 -1
- package/dist/opportunity/opportunity.introducer.d.ts +3 -3
- package/dist/opportunity/opportunity.introducer.d.ts.map +1 -1
- package/dist/opportunity/opportunity.introducer.js +2 -2
- package/dist/opportunity/opportunity.introducer.js.map +1 -1
- package/dist/opportunity/opportunity.state.d.ts +1 -1
- package/dist/opportunity/opportunity.state.js +1 -1
- package/dist/opportunity/opportunity.state.js.map +1 -1
- package/dist/opportunity/opportunity.tools.d.ts.map +1 -1
- package/dist/opportunity/opportunity.tools.js +43 -47
- package/dist/opportunity/opportunity.tools.js.map +1 -1
- package/dist/premise/premise.indexer.d.ts +1 -1
- package/dist/premise/premise.indexer.js +5 -5
- package/dist/premise/premise.indexer.js.map +1 -1
- package/dist/questioner/questioner.tools.d.ts +1 -1
- package/dist/questioner/questioner.tools.d.ts.map +1 -1
- package/dist/questioner/questioner.tools.js +5 -6
- package/dist/questioner/questioner.tools.js.map +1 -1
- package/dist/shared/agent/tool.factory.d.ts +1 -1
- package/dist/shared/agent/tool.factory.d.ts.map +1 -1
- package/dist/shared/agent/tool.factory.js +10 -11
- package/dist/shared/agent/tool.factory.js.map +1 -1
- package/dist/shared/agent/tool.helpers.d.ts +6 -6
- package/dist/shared/agent/tool.helpers.d.ts.map +1 -1
- package/dist/shared/agent/tool.helpers.js +2 -2
- package/dist/shared/agent/tool.helpers.js.map +1 -1
- package/dist/shared/agent/tool.registry.js +1 -1
- package/dist/shared/agent/tool.registry.js.map +1 -1
- package/dist/shared/agent/tool.scope.d.ts +12 -0
- package/dist/shared/agent/tool.scope.d.ts.map +1 -1
- package/dist/shared/agent/tool.scope.js +14 -0
- package/dist/shared/agent/tool.scope.js.map +1 -1
- package/dist/shared/agent/utility.tools.js +20 -20
- package/dist/shared/agent/utility.tools.js.map +1 -1
- package/dist/shared/interfaces/auth.interface.d.ts +3 -3
- package/dist/shared/interfaces/auth.interface.js.map +1 -1
- package/dist/shared/interfaces/database.interface.d.ts +59 -59
- package/dist/shared/interfaces/database.interface.d.ts.map +1 -1
- package/dist/shared/interfaces/database.interface.js.map +1 -1
- package/dist/shared/interfaces/discovery-run.interface.d.ts +1 -1
- package/dist/shared/interfaces/discovery-run.interface.d.ts.map +1 -1
- package/dist/shared/interfaces/discovery-run.interface.js.map +1 -1
- package/dist/shared/interfaces/embedder.interface.d.ts +2 -2
- package/dist/shared/interfaces/embedder.interface.d.ts.map +1 -1
- package/dist/shared/interfaces/embedder.interface.js.map +1 -1
- package/dist/shared/interfaces/enrichment-run.interface.d.ts +1 -1
- package/dist/shared/interfaces/enrichment-run.interface.d.ts.map +1 -1
- package/dist/shared/interfaces/enrichment-run.interface.js.map +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indexer.graph.js","sourceRoot":"/","sources":["network/indexer/indexer.graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAG9D,OAAO,EAAE,8BAA8B,EAAE,MAAM,sDAAsD,CAAC;AAEtG,OAAO,EAAE,cAAc,EAAE,MAAM,+CAA+C,CAAC;AAC/E,OAAO,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,+CAA+C,CAAC;AAE/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEjF,OAAO,EAAE,uBAAuB,EAAyB,MAAM,oBAAoB,CAAC;AAEpF,MAAM,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AAO,CAAC,CAAC,OAAO,MAAM,CAAC;YACzB,CAAC;QACH,CAAC,CAAC;QAEF,yBAAyB;QAEzB,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,uBAAuB,CAAC;aACrD,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC;aAC7B,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC;aACzB,OAAO,CAAC,UAAU,EAAE,YAAY,CAAC;aACjC,mBAAmB,CAAC,KAAK,EAAE,WAAW,EAAE;YACvC,MAAM,EAAE,QAAQ;YAChB,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE,UAAU;SACrB,CAAC;aACD,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC;aACtB,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;aACpB,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QAE5B,OAAO,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC5B,CAAC;CACF","sourcesContent":["import { StateGraph, START, END } from \"@langchain/langgraph\";\n\nimport { IntentIndexer } from \"../../intent/intent.indexer.js\";\nimport { buildNetworkAssignmentDecision } from \"../../shared/assignment/network-assignment.policy.js\";\nimport type { IntentNetworkGraphDatabase } from \"../../shared/interfaces/database.interface.js\";\nimport { protocolLogger } from \"../../shared/observability/protocol.logger.js\";\nimport { timed } from \"../../shared/observability/performance.js\";\nimport { requestContext } from \"../../shared/observability/request-context.js\";\nimport type { DebugMetaAgent } from \"../../chat/chat-streaming.types.js\";\nimport { renderNetworkContext } from \"../../shared/network/metadata.renderer.js\";\n\nimport { IntentNetworkGraphState, type AssignmentResult } from \"./indexer.state.js\";\n\nconst logger = protocolLogger(\"IntentNetworkGraphFactory\");\n\n/**\n * Factory class to build and compile the Intent Index Graph.\n *\n * Handles CRUD for the intent_indexes junction table:\n * - create: Assign an intent to an index (direct or evaluated via IntentIndexer agent)\n * - read: List intent-index links (by intentId or by networkId)\n * - delete: Unassign an intent from an index\n *\n * The evaluate-based assignment flow is migrated from the old Index Graph.\n */\nexport class IntentNetworkGraphFactory {\n constructor(\n private database: IntentNetworkGraphDatabase,\n private intentNetworker: IntentIndexer,\n ) {}\n\n public createGraph() {\n const indexer = this.intentNetworker;\n\n // --- NODE DEFINITIONS ---\n\n /**\n * Assign Node: Assign an intent to an index.\n * Two sub-paths:\n * - Direct assignment (skipEvaluation=true): assign immediately\n * - Evaluated assignment (skipEvaluation=false): load intent + index context, evaluate via IntentIndexer\n */\n const assignNode = async (state: typeof IntentNetworkGraphState.State) => {\n return timed(\"IntentNetworkGraph.assign\", async () => {\n const intentId = state.intentId;\n const networkId = state.networkId;\n logger.verbose(\"Assign intent to index\", { userId: state.userId, intentId, networkId, skipEvaluation: state.skipEvaluation });\n\n const agentTimingsAccum: DebugMetaAgent[] = [];\n\n if (!intentId || !networkId) {\n return { agentTimings: agentTimingsAccum, mutationResult: { success: false, error: \"Both intentId and networkId are required.\" } };\n }\n\n try {\n // Validate ownership and membership\n const intent = await this.database.getIntent(intentId);\n if (!intent) {\n return { agentTimings: agentTimingsAccum, mutationResult: { success: false, error: \"Intent not found.\" } };\n }\n if (intent.userId !== state.userId) {\n return { agentTimings: agentTimingsAccum, mutationResult: { success: false, error: \"You can only add your own intents to a network.\" } };\n }\n const [isMember, isOwner] = await Promise.all([\n this.database.isNetworkMember(networkId, state.userId),\n this.database.isIndexOwner(networkId, state.userId),\n ]);\n if (!isMember && !isOwner) {\n return { agentTimings: agentTimingsAccum, mutationResult: { success: false, error: \"You are not a member of that network.\" } };\n }\n\n // Check if already assigned\n const alreadyAssigned = await this.database.isIntentAssignedToIndex(intentId, networkId);\n if (alreadyAssigned) {\n return { agentTimings: agentTimingsAccum, mutationResult: { success: true, message: \"That intent is already in this network.\" } };\n }\n\n // Direct assignment (skip evaluation)\n if (state.skipEvaluation) {\n const decision = buildNetworkAssignmentDecision({\n resourceType: \"intent\",\n mode: \"manual_override\",\n scope: \"network\",\n evaluator: \"intent-network-graph\",\n source: \"manual-index-assignment\",\n createdAt: new Date().toISOString(),\n });\n await this.database.assignIntentToNetwork(intentId, networkId, decision.finalScore, decision.metadata);\n return {\n agentTimings: agentTimingsAccum,\n assignmentResult: { networkId, assigned: true, success: true } as AssignmentResult,\n mutationResult: { success: true, message: \"Intent saved to the network.\" },\n };\n }\n\n // Evaluated assignment (migrated from old Index Graph)\n const intentForIndexing = await this.database.getIntentForIndexing(intentId);\n if (!intentForIndexing) {\n return { agentTimings: agentTimingsAccum, mutationResult: { success: false, error: \"Intent not found for networking.\" } };\n }\n\n const indexContext = await this.database.getNetworkAssignmentContext(networkId, intentForIndexing.userId);\n if (!indexContext) {\n return {\n agentTimings: agentTimingsAccum,\n assignmentResult: { networkId, assigned: false, success: false } as AssignmentResult,\n mutationResult: { success: false, error: \"Network assignment context not found.\" },\n };\n }\n const indexPrompt = indexContext.indexPrompt ?? null;\n const memberPrompt = indexContext.memberPrompt ?? null;\n const hasNoPrompts = !indexPrompt?.trim() && !memberPrompt?.trim();\n if (hasNoPrompts) {\n const decision = buildNetworkAssignmentDecision({\n resourceType: \"intent\",\n mode: \"automatic\",\n scope: \"network\",\n indexPrompt,\n memberPrompt,\n evaluator: \"intent-indexer\",\n source: \"intent-network-graph\",\n createdAt: new Date().toISOString(),\n });\n await this.database.assignIntentToNetwork(intentId, networkId, decision.finalScore, decision.metadata);\n return {\n agentTimings: agentTimingsAccum,\n assignmentResult: { networkId, assigned: true, success: true } as AssignmentResult,\n mutationResult: { success: true, message: \"Intent assigned to network (no prompts).\" },\n };\n }\n\n // Run IntentIndexer evaluation\n const sourceName = intentForIndexing.sourceType\n ? `${intentForIndexing.sourceType}:${intentForIndexing.sourceId ?? \"\"}`\n : undefined;\n\n // Render network context (type, metadata) for the evaluator\n const network = await this.database.getNetwork(networkId);\n const renderedContext = network\n ? renderNetworkContext({\n type: network.type ?? 'community',\n title: network.title,\n prompt: network.prompt,\n metadata: network.metadata ?? {},\n })\n : null;\n\n const _traceEmitterIndexer = requestContext.getStore()?.traceEmitter;\n const _indexerStart = Date.now();\n _traceEmitterIndexer?.({ type: \"agent_start\", name: \"intent-indexer\" });\n let result: Awaited<ReturnType<typeof indexer.evaluate>> | null = null;\n try {\n result = await indexer.evaluate(\n intentForIndexing.payload,\n indexPrompt,\n memberPrompt,\n sourceName,\n renderedContext\n );\n } finally {\n const _indexerMs = Date.now() - _indexerStart;\n agentTimingsAccum.push({ name: 'intent.indexer', durationMs: _indexerMs });\n _traceEmitterIndexer?.({ type: \"agent_end\", name: \"intent-indexer\", durationMs: _indexerMs, summary: result ? `Scored: index=${result.indexScore.toFixed(2)}, member=${result.memberScore.toFixed(2)}` : \"intent-indexer failed\" });\n }\n\n if (!result) {\n return {\n agentTimings: agentTimingsAccum,\n evaluation: null,\n shouldAssign: false,\n finalScore: 0,\n mutationResult: { success: false, error: \"Evaluation returned no result.\" },\n };\n }\n\n const decision = buildNetworkAssignmentDecision({\n resourceType: \"intent\",\n mode: \"automatic\",\n scope: \"network\",\n indexPrompt,\n memberPrompt,\n rawScores: { indexScore: result.indexScore, memberScore: result.memberScore },\n evaluator: \"intent-indexer\",\n source: \"intent-network-graph\",\n reason: result.reasoning,\n createdAt: new Date().toISOString(),\n });\n\n if (decision.assigned) {\n await this.database.assignIntentToNetwork(intentId, networkId, decision.finalScore, decision.metadata);\n return {\n agentTimings: agentTimingsAccum,\n evaluation: result,\n shouldAssign: true,\n finalScore: decision.finalScore,\n assignmentResult: { networkId, assigned: true, success: true } as AssignmentResult,\n mutationResult: { success: true, message: `Intent assigned to network (score: ${decision.finalScore.toFixed(2)}).` },\n };\n }\n\n return {\n agentTimings: agentTimingsAccum,\n evaluation: result,\n shouldAssign: false,\n finalScore: decision.finalScore,\n assignmentResult: { networkId, assigned: false, success: true } as AssignmentResult,\n mutationResult: { success: false, error: `Intent did not qualify for this network (score: ${decision.finalScore.toFixed(2)}).` },\n };\n } catch (err) {\n logger.error(\"Assign failed\", { error: err });\n return { agentTimings: agentTimingsAccum, mutationResult: { success: false, error: \"Failed to assign intent to network.\" } };\n }\n });\n };\n\n /**\n * Read Node: Query intent-index relationships.\n * - By intentId only: list all indexes the intent is in (owner only)\n * - By networkId only: list intents in the index (member only)\n * - By both intentId and networkId: check if specific link exists (owner only)\n */\n const readNode = async (state: typeof IntentNetworkGraphState.State) => {\n return timed(\"IntentNetworkGraph.read\", async () => {\n const intentId = state.intentId;\n const networkId = state.networkId;\n logger.verbose(\"Read intent-index links\", { userId: state.userId, intentId, networkId, queryUserId: state.queryUserId });\n\n try {\n // By both: check if specific intent-index link exists\n if (intentId && networkId) {\n const intent = await this.database.getIntent(intentId);\n if (!intent) {\n return { readResult: { links: [], count: 0, mode: \"check_link\" }, error: \"Intent not found.\" };\n }\n if (intent.userId !== state.userId) {\n return { readResult: { links: [], count: 0, mode: \"check_link\" }, error: \"You can only check links for your own intents.\" };\n }\n const isLinked = await this.database.isIntentAssignedToIndex(intentId, networkId);\n return {\n readResult: {\n links: isLinked ? [{ intentId, networkId }] : [],\n count: isLinked ? 1 : 0,\n mode: \"check_link\",\n note: isLinked ? \"Intent is linked to this network.\" : \"Intent is not linked to this network.\",\n },\n };\n }\n\n // By intent only: list all indexes for this intent\n if (intentId) {\n const intent = await this.database.getIntent(intentId);\n if (!intent) {\n return { readResult: { links: [], count: 0, mode: \"networks_for_intent\" }, error: \"Intent not found.\" };\n }\n if (intent.userId !== state.userId) {\n return { readResult: { links: [], count: 0, mode: \"networks_for_intent\" }, error: \"You can only list networks for your own intents.\" };\n }\n const networkIds = await this.database.getNetworkIdsForIntent(intentId);\n return {\n readResult: {\n links: networkIds.map((id) => ({ intentId, networkId: id })),\n count: networkIds.length,\n mode: \"networks_for_intent\",\n note: \"To show network titles, use read_networks.\",\n },\n };\n }\n\n // By index: list intents in the index\n if (!networkId) {\n return {\n readResult: { links: [], count: 0, mode: \"unknown\" },\n error: \"Provide networkId or intentId.\",\n };\n }\n\n const [isMember, isOwner] = await Promise.all([\n this.database.isNetworkMember(networkId, state.userId),\n this.database.isIndexOwner(networkId, state.userId),\n ]);\n if (!isMember && !isOwner) {\n return {\n readResult: { links: [], count: 0, mode: \"intents_in_network\" },\n error: \"Network not found or you are not a member.\",\n };\n }\n\n // All intents or filtered by user\n if (!state.queryUserId) {\n const intents = await this.database.getNetworkIntentsForMember(networkId, state.userId, { limit: 50, offset: 0 });\n return {\n readResult: {\n links: intents.map((i) => ({\n intentId: i.id,\n networkId,\n intentTitle: i.payload,\n userId: i.userId,\n userName: i.userName,\n createdAt: i.createdAt,\n relevancyScore: i.relevancyScore,\n })),\n count: intents.length,\n mode: \"intents_in_network\",\n note: \"To show network title and full intent details, use read_networks and read_intents.\",\n },\n };\n }\n\n // Specific user's intents\n const intents = await this.database.getIntentsInIndexForMember(state.queryUserId, networkId);\n return {\n readResult: {\n links: intents.map((i) => ({\n intentId: i.id,\n networkId,\n intentTitle: i.payload,\n createdAt: i.createdAt,\n relevancyScore: i.relevancyScore,\n })),\n count: intents.length,\n mode: \"intents_in_network\",\n note: \"To show network title and full intent details, use read_networks and read_intents.\",\n },\n };\n } catch (err) {\n logger.error(\"Read intent-index failed\", { error: err });\n return { error: \"Failed to fetch intent-network links.\" };\n }\n });\n };\n\n /**\n * Unassign Node: Remove an intent from an index.\n */\n const unassignNode = async (state: typeof IntentNetworkGraphState.State) => {\n return timed(\"IntentNetworkGraph.unassign\", async () => {\n const intentId = state.intentId;\n const networkId = state.networkId;\n logger.verbose(\"Unassign intent from index\", { userId: state.userId, intentId, networkId });\n\n if (!intentId || !networkId) {\n return { mutationResult: { success: false, error: \"Both intentId and networkId are required.\" } };\n }\n\n try {\n const intent = await this.database.getIntent(intentId);\n if (!intent) {\n return { mutationResult: { success: false, error: \"Intent not found.\" } };\n }\n if (intent.userId !== state.userId) {\n return { mutationResult: { success: false, error: \"You can only remove your own intents from a network.\" } };\n }\n const [isMember, isOwner] = await Promise.all([\n this.database.isNetworkMember(networkId, state.userId),\n this.database.isIndexOwner(networkId, state.userId),\n ]);\n if (!isMember && !isOwner) {\n return { mutationResult: { success: false, error: \"You are not a member of that network.\" } };\n }\n\n const assigned = await this.database.isIntentAssignedToIndex(intentId, networkId);\n if (!assigned) {\n return { mutationResult: { success: true, message: \"That intent is not in this network.\" } };\n }\n\n await this.database.unassignIntentFromIndex(intentId, networkId);\n return { mutationResult: { success: true, message: \"Intent removed from the index.\" } };\n } catch (err) {\n logger.error(\"Unassign failed\", { error: err });\n return { mutationResult: { success: false, error: \"Failed to remove intent from network.\" } };\n }\n });\n };\n\n // --- CONDITIONAL ROUTING ---\n\n const routeByMode = (state: typeof IntentNetworkGraphState.State): string => {\n switch (state.operationMode) {\n case 'create': return 'assign';\n case 'read': return 'read';\n case 'delete': return 'unassign';\n default: return 'read';\n }\n };\n\n // --- GRAPH ASSEMBLY ---\n\n const workflow = new StateGraph(IntentNetworkGraphState)\n .addNode(\"assign\", assignNode)\n .addNode(\"read\", readNode)\n .addNode(\"unassign\", unassignNode)\n .addConditionalEdges(START, routeByMode, {\n assign: \"assign\",\n read: \"read\",\n unassign: \"unassign\",\n })\n .addEdge(\"assign\", END)\n .addEdge(\"read\", END)\n .addEdge(\"unassign\", END);\n\n return workflow.compile();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"indexer.graph.js","sourceRoot":"/","sources":["network/indexer/indexer.graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAG9D,OAAO,EAAE,8BAA8B,EAAE,MAAM,sDAAsD,CAAC;AAEtG,OAAO,EAAE,cAAc,EAAE,MAAM,+CAA+C,CAAC;AAC/E,OAAO,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,+CAA+C,CAAC;AAE/E,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AAEjF,OAAO,EAAE,uBAAuB,EAAyB,MAAM,oBAAoB,CAAC;AAEpF,MAAM,MAAM,GAAG,cAAc,CAAC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AO,MAAM,CAAC;YACzB,CAAC;QACH,CAAC,CAAC;QAEF,yBAAyB;QAEzB,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,uBAAuB,CAAC;aACrD,OAAO,CAAC,QAAQ,EAAE,UAAU,CAAC;aAC7B,OAAO,CAAC,MAAM,EAAE,QAAQ,CAAC;aACzB,OAAO,CAAC,UAAU,EAAE,YAAY,CAAC;aACjC,mBAAmB,CAAC,KAAK,EAAE,WAAW,EAAE;YACvC,MAAM,EAAE,QAAQ;YAChB,IAAI,EAAE,MAAM;YACZ,QAAQ,EAAE,UAAU;SACrB,CAAC;aACD,OAAO,CAAC,QAAQ,EAAE,GAAG,CAAC;aACtB,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;aACpB,OAAO,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC;QAE5B,OAAO,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC5B,CAAC;CACF","sourcesContent":["import { StateGraph, START, END } from \"@langchain/langgraph\";\n\nimport { IntentIndexer } from \"../../intent/intent.indexer.js\";\nimport { buildNetworkAssignmentDecision } from \"../../shared/assignment/network-assignment.policy.js\";\nimport type { IntentNetworkGraphDatabase } from \"../../shared/interfaces/database.interface.js\";\nimport { protocolLogger } from \"../../shared/observability/protocol.logger.js\";\nimport { timed } from \"../../shared/observability/performance.js\";\nimport { requestContext } from \"../../shared/observability/request-context.js\";\nimport type { DebugMetaAgent } from \"../../chat/chat-streaming.types.js\";\nimport { renderNetworkContext } from \"../../shared/network/metadata.renderer.js\";\n\nimport { IntentNetworkGraphState, type AssignmentResult } from \"./indexer.state.js\";\n\nconst logger = protocolLogger(\"IntentNetworkGraphFactory\");\n\n/**\n * Factory class to build and compile the Intent Index Graph.\n *\n * Handles CRUD for the intent_indexes junction table:\n * - create: Assign an intent to an index (direct or evaluated via IntentIndexer agent)\n * - read: List intent-network links (by intentId or by networkId)\n * - delete: Unassign an intent from an index\n *\n * The evaluate-based assignment flow is migrated from the old Network Graph.\n */\nexport class IntentNetworkGraphFactory {\n constructor(\n private database: IntentNetworkGraphDatabase,\n private intentNetworker: IntentIndexer,\n ) {}\n\n public createGraph() {\n const indexer = this.intentNetworker;\n\n // --- NODE DEFINITIONS ---\n\n /**\n * Assign Node: Assign an intent to an index.\n * Two sub-paths:\n * - Direct assignment (skipEvaluation=true): assign immediately\n * - Evaluated assignment (skipEvaluation=false): load intent + index context, evaluate via IntentIndexer\n */\n const assignNode = async (state: typeof IntentNetworkGraphState.State) => {\n return timed(\"IntentNetworkGraph.assign\", async () => {\n const intentId = state.intentId;\n const networkId = state.networkId;\n logger.verbose(\"Assign intent to index\", { userId: state.userId, intentId, networkId, skipEvaluation: state.skipEvaluation });\n\n const agentTimingsAccum: DebugMetaAgent[] = [];\n\n if (!intentId || !networkId) {\n return { agentTimings: agentTimingsAccum, mutationResult: { success: false, error: \"Both intentId and networkId are required.\" } };\n }\n\n try {\n // Validate ownership and membership\n const intent = await this.database.getIntent(intentId);\n if (!intent) {\n return { agentTimings: agentTimingsAccum, mutationResult: { success: false, error: \"Intent not found.\" } };\n }\n if (intent.userId !== state.userId) {\n return { agentTimings: agentTimingsAccum, mutationResult: { success: false, error: \"You can only add your own intents to a network.\" } };\n }\n const [isMember, isOwner] = await Promise.all([\n this.database.isNetworkMember(networkId, state.userId),\n this.database.isIndexOwner(networkId, state.userId),\n ]);\n if (!isMember && !isOwner) {\n return { agentTimings: agentTimingsAccum, mutationResult: { success: false, error: \"You are not a member of that network.\" } };\n }\n\n // Check if already assigned\n const alreadyAssigned = await this.database.isIntentAssignedToIndex(intentId, networkId);\n if (alreadyAssigned) {\n return { agentTimings: agentTimingsAccum, mutationResult: { success: true, message: \"That intent is already in this network.\" } };\n }\n\n // Direct assignment (skip evaluation)\n if (state.skipEvaluation) {\n const decision = buildNetworkAssignmentDecision({\n resourceType: \"intent\",\n mode: \"manual_override\",\n scope: \"network\",\n evaluator: \"intent-network-graph\",\n source: \"manual-index-assignment\",\n createdAt: new Date().toISOString(),\n });\n await this.database.assignIntentToNetwork(intentId, networkId, decision.finalScore, decision.metadata);\n return {\n agentTimings: agentTimingsAccum,\n assignmentResult: { networkId, assigned: true, success: true } as AssignmentResult,\n mutationResult: { success: true, message: \"Intent saved to the network.\" },\n };\n }\n\n // Evaluated assignment (migrated from old Network Graph)\n const intentForIndexing = await this.database.getIntentForIndexing(intentId);\n if (!intentForIndexing) {\n return { agentTimings: agentTimingsAccum, mutationResult: { success: false, error: \"Intent not found for networking.\" } };\n }\n\n const indexContext = await this.database.getNetworkAssignmentContext(networkId, intentForIndexing.userId);\n if (!indexContext) {\n return {\n agentTimings: agentTimingsAccum,\n assignmentResult: { networkId, assigned: false, success: false } as AssignmentResult,\n mutationResult: { success: false, error: \"Network assignment context not found.\" },\n };\n }\n const indexPrompt = indexContext.indexPrompt ?? null;\n const memberPrompt = indexContext.memberPrompt ?? null;\n const hasNoPrompts = !indexPrompt?.trim() && !memberPrompt?.trim();\n if (hasNoPrompts) {\n const decision = buildNetworkAssignmentDecision({\n resourceType: \"intent\",\n mode: \"automatic\",\n scope: \"network\",\n indexPrompt,\n memberPrompt,\n evaluator: \"intent-networker\",\n source: \"intent-network-graph\",\n createdAt: new Date().toISOString(),\n });\n await this.database.assignIntentToNetwork(intentId, networkId, decision.finalScore, decision.metadata);\n return {\n agentTimings: agentTimingsAccum,\n assignmentResult: { networkId, assigned: true, success: true } as AssignmentResult,\n mutationResult: { success: true, message: \"Intent assigned to network (no prompts).\" },\n };\n }\n\n // Run IntentIndexer evaluation\n const sourceName = intentForIndexing.sourceType\n ? `${intentForIndexing.sourceType}:${intentForIndexing.sourceId ?? \"\"}`\n : undefined;\n\n // Render network context (type, metadata) for the evaluator\n const network = await this.database.getNetwork(networkId);\n const renderedContext = network\n ? renderNetworkContext({\n type: network.type ?? 'community',\n title: network.title,\n prompt: network.prompt,\n metadata: network.metadata ?? {},\n })\n : null;\n\n const _traceEmitterIndexer = requestContext.getStore()?.traceEmitter;\n const _indexerStart = Date.now();\n _traceEmitterIndexer?.({ type: \"agent_start\", name: \"intent-networker\" });\n let result: Awaited<ReturnType<typeof indexer.evaluate>> | null = null;\n try {\n result = await indexer.evaluate(\n intentForIndexing.payload,\n indexPrompt,\n memberPrompt,\n sourceName,\n renderedContext\n );\n } finally {\n const _indexerMs = Date.now() - _indexerStart;\n agentTimingsAccum.push({ name: 'intent.indexer', durationMs: _indexerMs });\n _traceEmitterIndexer?.({ type: \"agent_end\", name: \"intent-networker\", durationMs: _indexerMs, summary: result ? `Scored: index=${result.indexScore.toFixed(2)}, member=${result.memberScore.toFixed(2)}` : \"intent-networker failed\" });\n }\n\n if (!result) {\n return {\n agentTimings: agentTimingsAccum,\n evaluation: null,\n shouldAssign: false,\n finalScore: 0,\n mutationResult: { success: false, error: \"Evaluation returned no result.\" },\n };\n }\n\n const decision = buildNetworkAssignmentDecision({\n resourceType: \"intent\",\n mode: \"automatic\",\n scope: \"network\",\n indexPrompt,\n memberPrompt,\n rawScores: { indexScore: result.indexScore, memberScore: result.memberScore },\n evaluator: \"intent-networker\",\n source: \"intent-network-graph\",\n reason: result.reasoning,\n createdAt: new Date().toISOString(),\n });\n\n if (decision.assigned) {\n await this.database.assignIntentToNetwork(intentId, networkId, decision.finalScore, decision.metadata);\n return {\n agentTimings: agentTimingsAccum,\n evaluation: result,\n shouldAssign: true,\n finalScore: decision.finalScore,\n assignmentResult: { networkId, assigned: true, success: true } as AssignmentResult,\n mutationResult: { success: true, message: `Intent assigned to network (score: ${decision.finalScore.toFixed(2)}).` },\n };\n }\n\n return {\n agentTimings: agentTimingsAccum,\n evaluation: result,\n shouldAssign: false,\n finalScore: decision.finalScore,\n assignmentResult: { networkId, assigned: false, success: true } as AssignmentResult,\n mutationResult: { success: false, error: `Intent did not qualify for this network (score: ${decision.finalScore.toFixed(2)}).` },\n };\n } catch (err) {\n logger.error(\"Assign failed\", { error: err });\n return { agentTimings: agentTimingsAccum, mutationResult: { success: false, error: \"Failed to assign intent to network.\" } };\n }\n });\n };\n\n /**\n * Read Node: Query intent-network relationships.\n * - By intentId only: list all networks the intent is in (owner only)\n * - By networkId only: list intents in the index (member only)\n * - By both intentId and networkId: check if specific link exists (owner only)\n */\n const readNode = async (state: typeof IntentNetworkGraphState.State) => {\n return timed(\"IntentNetworkGraph.read\", async () => {\n const intentId = state.intentId;\n const networkId = state.networkId;\n logger.verbose(\"Read intent-network links\", { userId: state.userId, intentId, networkId, queryUserId: state.queryUserId });\n\n try {\n // By both: check if specific intent-network link exists\n if (intentId && networkId) {\n const intent = await this.database.getIntent(intentId);\n if (!intent) {\n return { readResult: { links: [], count: 0, mode: \"check_link\" }, error: \"Intent not found.\" };\n }\n if (intent.userId !== state.userId) {\n return { readResult: { links: [], count: 0, mode: \"check_link\" }, error: \"You can only check links for your own intents.\" };\n }\n const isLinked = await this.database.isIntentAssignedToIndex(intentId, networkId);\n return {\n readResult: {\n links: isLinked ? [{ intentId, networkId }] : [],\n count: isLinked ? 1 : 0,\n mode: \"check_link\",\n note: isLinked ? \"Intent is linked to this network.\" : \"Intent is not linked to this network.\",\n },\n };\n }\n\n // By intent only: list all networks for this intent\n if (intentId) {\n const intent = await this.database.getIntent(intentId);\n if (!intent) {\n return { readResult: { links: [], count: 0, mode: \"networks_for_intent\" }, error: \"Intent not found.\" };\n }\n if (intent.userId !== state.userId) {\n return { readResult: { links: [], count: 0, mode: \"networks_for_intent\" }, error: \"You can only list networks for your own intents.\" };\n }\n const networkIds = await this.database.getNetworkIdsForIntent(intentId);\n return {\n readResult: {\n links: networkIds.map((id) => ({ intentId, networkId: id })),\n count: networkIds.length,\n mode: \"networks_for_intent\",\n note: \"To show network titles, use read_networks.\",\n },\n };\n }\n\n // By index: list intents in the index\n if (!networkId) {\n return {\n readResult: { links: [], count: 0, mode: \"unknown\" },\n error: \"Provide networkId or intentId.\",\n };\n }\n\n const [isMember, isOwner] = await Promise.all([\n this.database.isNetworkMember(networkId, state.userId),\n this.database.isIndexOwner(networkId, state.userId),\n ]);\n if (!isMember && !isOwner) {\n return {\n readResult: { links: [], count: 0, mode: \"intents_in_network\" },\n error: \"Network not found or you are not a member.\",\n };\n }\n\n // All intents or filtered by user\n if (!state.queryUserId) {\n const intents = await this.database.getNetworkIntentsForMember(networkId, state.userId, { limit: 50, offset: 0 });\n return {\n readResult: {\n links: intents.map((i) => ({\n intentId: i.id,\n networkId,\n intentTitle: i.payload,\n userId: i.userId,\n userName: i.userName,\n createdAt: i.createdAt,\n relevancyScore: i.relevancyScore,\n })),\n count: intents.length,\n mode: \"intents_in_network\",\n note: \"To show network title and full intent details, use read_networks and read_intents.\",\n },\n };\n }\n\n // Specific user's intents\n const intents = await this.database.getIntentsInIndexForMember(state.queryUserId, networkId);\n return {\n readResult: {\n links: intents.map((i) => ({\n intentId: i.id,\n networkId,\n intentTitle: i.payload,\n createdAt: i.createdAt,\n relevancyScore: i.relevancyScore,\n })),\n count: intents.length,\n mode: \"intents_in_network\",\n note: \"To show network title and full intent details, use read_networks and read_intents.\",\n },\n };\n } catch (err) {\n logger.error(\"Read intent-network failed\", { error: err });\n return { error: \"Failed to fetch intent-network links.\" };\n }\n });\n };\n\n /**\n * Unassign Node: Remove an intent from an index.\n */\n const unassignNode = async (state: typeof IntentNetworkGraphState.State) => {\n return timed(\"IntentNetworkGraph.unassign\", async () => {\n const intentId = state.intentId;\n const networkId = state.networkId;\n logger.verbose(\"Unassign intent from index\", { userId: state.userId, intentId, networkId });\n\n if (!intentId || !networkId) {\n return { mutationResult: { success: false, error: \"Both intentId and networkId are required.\" } };\n }\n\n try {\n const intent = await this.database.getIntent(intentId);\n if (!intent) {\n return { mutationResult: { success: false, error: \"Intent not found.\" } };\n }\n if (intent.userId !== state.userId) {\n return { mutationResult: { success: false, error: \"You can only remove your own intents from a network.\" } };\n }\n const [isMember, isOwner] = await Promise.all([\n this.database.isNetworkMember(networkId, state.userId),\n this.database.isIndexOwner(networkId, state.userId),\n ]);\n if (!isMember && !isOwner) {\n return { mutationResult: { success: false, error: \"You are not a member of that network.\" } };\n }\n\n const assigned = await this.database.isIntentAssignedToIndex(intentId, networkId);\n if (!assigned) {\n return { mutationResult: { success: true, message: \"That intent is not in this network.\" } };\n }\n\n await this.database.unassignIntentFromIndex(intentId, networkId);\n return { mutationResult: { success: true, message: \"Intent removed from the index.\" } };\n } catch (err) {\n logger.error(\"Unassign failed\", { error: err });\n return { mutationResult: { success: false, error: \"Failed to remove intent from network.\" } };\n }\n });\n };\n\n // --- CONDITIONAL ROUTING ---\n\n const routeByMode = (state: typeof IntentNetworkGraphState.State): string => {\n switch (state.operationMode) {\n case 'create': return 'assign';\n case 'read': return 'read';\n case 'delete': return 'unassign';\n default: return 'read';\n }\n };\n\n // --- GRAPH ASSEMBLY ---\n\n const workflow = new StateGraph(IntentNetworkGraphState)\n .addNode(\"assign\", assignNode)\n .addNode(\"read\", readNode)\n .addNode(\"unassign\", unassignNode)\n .addConditionalEdges(START, routeByMode, {\n assign: \"assign\",\n read: \"read\",\n unassign: \"unassign\",\n })\n .addEdge(\"assign\", END)\n .addEdge(\"read\", END)\n .addEdge(\"unassign\", END);\n\n return workflow.compile();\n }\n}\n"]}
|
|
@@ -32,7 +32,7 @@ export interface AssignmentResult {
|
|
|
32
32
|
/**
|
|
33
33
|
* Intent Index Graph State.
|
|
34
34
|
* Handles CRUD for the intent_indexes junction table (linking intents to indexes).
|
|
35
|
-
* Absorbs the old
|
|
35
|
+
* Absorbs the old Network Graph's evaluate-based assignment flow.
|
|
36
36
|
*
|
|
37
37
|
* Flow:
|
|
38
38
|
* START → router → {
|
|
@@ -56,7 +56,7 @@ export declare const IntentNetworkGraphState: import("@langchain/langgraph").Ann
|
|
|
56
56
|
operationMode: import("@langchain/langgraph").BaseChannel<"create" | "delete" | "read", "create" | "delete" | "read" | import("@langchain/langgraph").OverwriteValue<"create" | "delete" | "read">, unknown>;
|
|
57
57
|
/**
|
|
58
58
|
* When true, skip LLM evaluation and assign directly.
|
|
59
|
-
* (Migrated from old
|
|
59
|
+
* (Migrated from old Network Graph.)
|
|
60
60
|
*/
|
|
61
61
|
skipEvaluation: import("@langchain/langgraph").BaseChannel<boolean, boolean | import("@langchain/langgraph").OverwriteValue<boolean>, unknown>;
|
|
62
62
|
/** Intent payload and metadata. Null if intent not found. */
|
|
@@ -77,7 +77,7 @@ export declare const IntentNetworkGraphState: import("@langchain/langgraph").Ann
|
|
|
77
77
|
memberScore: number;
|
|
78
78
|
reasoning: string;
|
|
79
79
|
} | null> | null, unknown>;
|
|
80
|
-
/** Final decision: should intent be in this
|
|
80
|
+
/** Final decision: should intent be in this network? */
|
|
81
81
|
shouldAssign: import("@langchain/langgraph").BaseChannel<boolean | undefined, boolean | import("@langchain/langgraph").OverwriteValue<boolean | undefined> | undefined, unknown>;
|
|
82
82
|
/** Final score used for decision (0–1). */
|
|
83
83
|
finalScore: import("@langchain/langgraph").BaseChannel<number | undefined, number | import("@langchain/langgraph").OverwriteValue<number | undefined> | undefined, unknown>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indexer.state.d.ts","sourceRoot":"/","sources":["network/indexer/indexer.state.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEzE;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IACjC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,GAAG,IAAI,CAAC;IAC3B,YAAY,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED;;;GAGG;AACH,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,OAAO,CAAC;IAClB,OAA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qB;;IAMrB,sEAAsE;;EAKtE,CAAC"}
|
|
@@ -2,7 +2,7 @@ import { Annotation } from "@langchain/langgraph";
|
|
|
2
2
|
/**
|
|
3
3
|
* Intent Index Graph State.
|
|
4
4
|
* Handles CRUD for the intent_indexes junction table (linking intents to indexes).
|
|
5
|
-
* Absorbs the old
|
|
5
|
+
* Absorbs the old Network Graph's evaluate-based assignment flow.
|
|
6
6
|
*
|
|
7
7
|
* Flow:
|
|
8
8
|
* START → router → {
|
|
@@ -33,13 +33,13 @@ export const IntentNetworkGraphState = Annotation.Root({
|
|
|
33
33
|
// --- Create Mode Controls ---
|
|
34
34
|
/**
|
|
35
35
|
* When true, skip LLM evaluation and assign directly.
|
|
36
|
-
* (Migrated from old
|
|
36
|
+
* (Migrated from old Network Graph.)
|
|
37
37
|
*/
|
|
38
38
|
skipEvaluation: Annotation({
|
|
39
39
|
reducer: (_, next) => next,
|
|
40
40
|
default: () => true,
|
|
41
41
|
}),
|
|
42
|
-
// --- Intermediate State (populated by nodes, migrated from old
|
|
42
|
+
// --- Intermediate State (populated by nodes, migrated from old Network Graph) ---
|
|
43
43
|
/** Intent payload and metadata. Null if intent not found. */
|
|
44
44
|
intent: Annotation({
|
|
45
45
|
reducer: (_, next) => next,
|
|
@@ -55,7 +55,7 @@ export const IntentNetworkGraphState = Annotation.Root({
|
|
|
55
55
|
reducer: (_, next) => next,
|
|
56
56
|
default: () => null,
|
|
57
57
|
}),
|
|
58
|
-
/** Final decision: should intent be in this
|
|
58
|
+
/** Final decision: should intent be in this network? */
|
|
59
59
|
shouldAssign: Annotation({
|
|
60
60
|
reducer: (_, next) => next,
|
|
61
61
|
default: () => undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indexer.state.js","sourceRoot":"/","sources":["network/indexer/indexer.state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAqClD;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MA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EAAE;KAClB,CAAC;CACH,CAAC,CAAC","sourcesContent":["import { Annotation } from \"@langchain/langgraph\";\nimport type { IntentIndexerOutput } from \"../../intent/intent.indexer.js\";\nimport type { DebugMetaAgent } from '../../chat/chat-streaming.types.js';\n\n/**\n * Intent payload and metadata loaded for index evaluation.\n * (Migrated from the old index.graph.state.ts)\n */\nexport interface IntentForIndexing {\n id: string;\n payload: string;\n userId: string;\n sourceType: string | null;\n sourceId: string | null;\n}\n\n/**\n * Index and member prompts for a single index (user must be member with autoAssign).\n * (Migrated from the old index.graph.state.ts)\n */\nexport interface IndexMemberContext {\n networkId: string;\n indexPrompt: string | null;\n memberPrompt: string | null;\n}\n\n/**\n * Result of executing an assignment decision.\n * (Migrated from the old index.graph.state.ts)\n */\nexport interface AssignmentResult {\n networkId: string;\n assigned: boolean;\n success: boolean;\n error?: string;\n}\n\n/**\n * Intent Index Graph State.\n * Handles CRUD for the intent_indexes junction table (linking intents to indexes).\n * Absorbs the old Network Graph's evaluate-based assignment flow.\n *\n * Flow:\n * START → router → {\n * create: assignNode (direct or evaluated) → END\n * read: readNode → END\n * delete: unassignNode → END\n * }\n */\nexport const IntentNetworkGraphState = Annotation.Root({\n // --- Core Inputs (from ChatGraph via ToolContext) ---\n\n /** User performing the action. Always required. */\n userId: Annotation<string>,\n\n /** Target index for assign/read-by-index. From ChatGraph or tool arg. */\n networkId: Annotation<string | undefined>({\n reducer: (_, next) => next,\n default: () => undefined,\n }),\n\n /** Target intent for assign/read-by-intent. From tool arg. */\n intentId: Annotation<string | undefined>({\n reducer: (_, next) => next,\n default: () => undefined,\n }),\n\n /** Operation mode. */\n operationMode: Annotation<'create' | 'read' | 'delete'>({\n reducer: (curr, next) => next ?? curr,\n default: () => 'read' as const,\n }),\n\n // --- Create Mode Controls ---\n\n /**\n * When true, skip LLM evaluation and assign directly.\n * (Migrated from old Network Graph.)\n */\n skipEvaluation: Annotation<boolean>({\n reducer: (_, next) => next,\n default: () => true,\n }),\n\n // --- Intermediate State (populated by nodes, migrated from old Network Graph) ---\n\n /** Intent payload and metadata. Null if intent not found. */\n intent: Annotation<IntentForIndexing | null>({\n reducer: (_, next) => next,\n default: () => null,\n }),\n\n /** Index + member context. Null if user not eligible. */\n indexContext: Annotation<IndexMemberContext | null>({\n reducer: (_, next) => next,\n default: () => null,\n }),\n\n /** LLM evaluation result. Null if skipped. */\n evaluation: Annotation<IntentIndexerOutput | null>({\n reducer: (_, next) => next,\n default: () => null,\n }),\n\n /** Final decision: should intent be in this network? */\n shouldAssign: Annotation<boolean | undefined>({\n reducer: (_, next) => next,\n default: () => undefined,\n }),\n\n /** Final score used for decision (0–1). */\n finalScore: Annotation<number | undefined>({\n reducer: (_, next) => next,\n default: () => undefined,\n }),\n\n /** Result of the assignment operation. */\n assignmentResult: Annotation<AssignmentResult | null>({\n reducer: (_, next) => next,\n default: () => null,\n }),\n\n // --- Read Mode Outputs ---\n\n /** For read-by-intent: pass userId when listing an intent's indexes (omit for read-by-index). */\n queryUserId: Annotation<string | undefined>({\n reducer: (_, next) => next,\n default: () => undefined,\n }),\n\n /** Output for read mode. */\n readResult: Annotation<{\n links: Array<{\n intentId: string;\n networkId: string;\n intentTitle?: string;\n networkTitle?: string;\n userId?: string;\n userName?: string;\n createdAt?: Date;\n relevancyScore?: number | null;\n }>;\n count: number;\n mode: string;\n note?: string;\n } | undefined>({\n reducer: (_, next) => next,\n default: () => undefined,\n }),\n\n /** Output for create/delete modes. */\n mutationResult: Annotation<{\n success: boolean;\n message?: string;\n error?: string;\n } | undefined>({\n reducer: (_, next) => next,\n default: () => undefined,\n }),\n\n /** Error message. */\n error: Annotation<string | null>({\n reducer: (_, next) => next,\n default: () => null,\n }),\n\n /** Timing records for each agent invocation within this graph run. */\n agentTimings: Annotation<DebugMetaAgent[]>({\n reducer: (acc, val) => [...acc, ...val],\n default: () => [],\n }),\n});\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { NetworkMembershipGraphDatabase } from "../../shared/interfaces/database.interface.js";
|
|
2
2
|
/**
|
|
3
|
-
* Factory class to build and compile the
|
|
3
|
+
* Factory class to build and compile the Network Membership Graph.
|
|
4
4
|
*
|
|
5
5
|
* Handles CRUD operations for the index_members table:
|
|
6
6
|
* - create: Add a member to an index (validates join policy and ownership)
|
|
@@ -4,7 +4,7 @@ import { timed } from "../../shared/observability/performance.js";
|
|
|
4
4
|
import { NetworkMembershipGraphState } from "./membership.state.js";
|
|
5
5
|
const logger = protocolLogger("NetworkMembershipGraphFactory");
|
|
6
6
|
/**
|
|
7
|
-
* Factory class to build and compile the
|
|
7
|
+
* Factory class to build and compile the Network Membership Graph.
|
|
8
8
|
*
|
|
9
9
|
* Handles CRUD operations for the index_members table:
|
|
10
10
|
* - create: Add a member to an index (validates join policy and ownership)
|
|
@@ -20,7 +20,7 @@ export class NetworkMembershipGraphFactory {
|
|
|
20
20
|
/**
|
|
21
21
|
* Add Member Node: Add a user as a member of an index.
|
|
22
22
|
* Handles two cases:
|
|
23
|
-
* 1. Self-join (targetUserId === userId): Only allowed for public
|
|
23
|
+
* 1. Self-join (targetUserId === userId): Only allowed for public networks (joinPolicy 'anyone')
|
|
24
24
|
* 2. Invite others (targetUserId !== userId): Requires caller to be member; owner-only for invite_only
|
|
25
25
|
*/
|
|
26
26
|
const addMemberNode = async (state) => {
|
|
@@ -41,37 +41,37 @@ export class NetworkMembershipGraphFactory {
|
|
|
41
41
|
const joinPolicy = indexRecord.permissions.joinPolicy;
|
|
42
42
|
const isSelfJoin = state.targetUserId === state.userId;
|
|
43
43
|
if (isSelfJoin) {
|
|
44
|
-
// Self-join: only allowed for public
|
|
44
|
+
// Self-join: only allowed for public networks
|
|
45
45
|
if (joinPolicy !== 'anyone') {
|
|
46
46
|
return {
|
|
47
47
|
mutationResult: {
|
|
48
48
|
success: false,
|
|
49
|
-
error: "This
|
|
49
|
+
error: "This network is invite-only. You cannot join without an invitation from an existing member.",
|
|
50
50
|
},
|
|
51
51
|
};
|
|
52
52
|
}
|
|
53
53
|
const result = await this.database.addMemberToNetwork(state.networkId, state.targetUserId, 'member');
|
|
54
54
|
if (result.alreadyMember) {
|
|
55
|
-
return { mutationResult: { success: true, message: "You are already a member of this
|
|
55
|
+
return { mutationResult: { success: true, message: "You are already a member of this network." } };
|
|
56
56
|
}
|
|
57
57
|
return { mutationResult: { success: true, message: `You have joined "${indexRecord.title}".` } };
|
|
58
58
|
}
|
|
59
59
|
// Inviting others: must be a member first
|
|
60
60
|
const isMember = await this.database.isNetworkMember(state.networkId, state.userId);
|
|
61
61
|
if (!isMember) {
|
|
62
|
-
return { mutationResult: { success: false, error: "You must be a member of that
|
|
62
|
+
return { mutationResult: { success: false, error: "You must be a member of that network to add others." } };
|
|
63
63
|
}
|
|
64
64
|
if (joinPolicy === 'invite_only') {
|
|
65
65
|
const isOwner = await this.database.isIndexOwner(state.networkId, state.userId);
|
|
66
66
|
if (!isOwner) {
|
|
67
|
-
return { mutationResult: { success: false, error: "Only the
|
|
67
|
+
return { mutationResult: { success: false, error: "Only the network owner can add members when the network is invite-only." } };
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
const result = await this.database.addMemberToNetwork(state.networkId, state.targetUserId, 'member');
|
|
71
71
|
if (result.alreadyMember) {
|
|
72
|
-
return { mutationResult: { success: true, message: "That user is already a member of this
|
|
72
|
+
return { mutationResult: { success: true, message: "That user is already a member of this network." } };
|
|
73
73
|
}
|
|
74
|
-
return { mutationResult: { success: true, message: "Member added to the
|
|
74
|
+
return { mutationResult: { success: true, message: "Member added to the network." } };
|
|
75
75
|
}
|
|
76
76
|
catch (err) {
|
|
77
77
|
logger.error("Add member failed", { error: err });
|
|
@@ -85,12 +85,12 @@ export class NetworkMembershipGraphFactory {
|
|
|
85
85
|
});
|
|
86
86
|
};
|
|
87
87
|
/**
|
|
88
|
-
* List Members Node: List all members of
|
|
88
|
+
* List Members Node: List all members of a network.
|
|
89
89
|
* Validates caller is a member.
|
|
90
90
|
*/
|
|
91
91
|
const listMembersNode = async (state) => {
|
|
92
92
|
return timed("NetworkMembershipGraph.listMembers", async () => {
|
|
93
|
-
logger.verbose("List
|
|
93
|
+
logger.verbose("List network members", {
|
|
94
94
|
userId: state.userId,
|
|
95
95
|
networkId: state.networkId,
|
|
96
96
|
});
|
|
@@ -103,7 +103,7 @@ export class NetworkMembershipGraphFactory {
|
|
|
103
103
|
count: 0,
|
|
104
104
|
members: [],
|
|
105
105
|
},
|
|
106
|
-
error: "
|
|
106
|
+
error: "Network not found or you are not a member.",
|
|
107
107
|
};
|
|
108
108
|
}
|
|
109
109
|
const members = await this.database.getNetworkMembersForMember(state.networkId, state.userId);
|
|
@@ -124,19 +124,19 @@ export class NetworkMembershipGraphFactory {
|
|
|
124
124
|
}
|
|
125
125
|
catch (err) {
|
|
126
126
|
logger.error("List members failed", { error: err });
|
|
127
|
-
if (err instanceof Error && err.message === "Access denied: Not a member of this
|
|
128
|
-
return { error: "You must be a member of that
|
|
127
|
+
if (err instanceof Error && err.message === "Access denied: Not a member of this network") {
|
|
128
|
+
return { error: "You must be a member of that network." };
|
|
129
129
|
}
|
|
130
|
-
return { error: "Failed to fetch
|
|
130
|
+
return { error: "Failed to fetch network members." };
|
|
131
131
|
}
|
|
132
132
|
});
|
|
133
133
|
};
|
|
134
134
|
/**
|
|
135
|
-
* Remove Member Node: Remove a member from
|
|
135
|
+
* Remove Member Node: Remove a member from a network (owner only).
|
|
136
136
|
*/
|
|
137
137
|
const removeMemberNode = async (state) => {
|
|
138
138
|
return timed("NetworkMembershipGraph.removeMember", async () => {
|
|
139
|
-
logger.verbose("Remove member from
|
|
139
|
+
logger.verbose("Remove member from network", {
|
|
140
140
|
userId: state.userId,
|
|
141
141
|
networkId: state.networkId,
|
|
142
142
|
targetUserId: state.targetUserId,
|
|
@@ -146,19 +146,19 @@ export class NetworkMembershipGraphFactory {
|
|
|
146
146
|
}
|
|
147
147
|
// Cannot remove yourself via this flow
|
|
148
148
|
if (state.targetUserId === state.userId) {
|
|
149
|
-
return { mutationResult: { success: false, error: "You cannot remove yourself. Use 'leave
|
|
149
|
+
return { mutationResult: { success: false, error: "You cannot remove yourself. Use 'leave network' instead." } };
|
|
150
150
|
}
|
|
151
151
|
try {
|
|
152
152
|
const isOwner = await this.database.isIndexOwner(state.networkId, state.userId);
|
|
153
153
|
if (!isOwner) {
|
|
154
|
-
return { mutationResult: { success: false, error: "Only the
|
|
154
|
+
return { mutationResult: { success: false, error: "Only the network owner can remove members." } };
|
|
155
155
|
}
|
|
156
156
|
const result = await this.database.removeMemberFromIndex(state.networkId, state.targetUserId);
|
|
157
157
|
if (result.wasOwner) {
|
|
158
|
-
return { mutationResult: { success: false, error: "Cannot remove the
|
|
158
|
+
return { mutationResult: { success: false, error: "Cannot remove the network owner." } };
|
|
159
159
|
}
|
|
160
160
|
if (result.notMember) {
|
|
161
|
-
return { mutationResult: { success: false, error: "User is not a member of this
|
|
161
|
+
return { mutationResult: { success: false, error: "User is not a member of this network." } };
|
|
162
162
|
}
|
|
163
163
|
if (!result.success) {
|
|
164
164
|
return { mutationResult: { success: false, error: "Failed to remove member." } };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"membership.graph.js","sourceRoot":"/","sources":["network/membership/membership.graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,sBAAsB,CAAC;AAE9D,OAAO,EAAE,cAAc,EAAE,MAAM,+CAA+C,CAAC;AAC/E,OAAO,EAAE,KAAK,EAAE,MAAM,2CAA2C,CAAC;AAClE,OAAO,EAAE,2BAA2B,EAAE,MAAM,uBAAuB,CAAC;AAEpE,MAAM,MAAM,GAAG,cAAc,CAAC,+BAA+B,CAAC,CAAC;AAE/D;;;;;;;GAOG;AACH,MAAM,OAAO,6BAA6B;IACxC,YAAoB,QAAwC;QAAxC,aAAQ,GAAR,QAAQ,CAAgC;IAAG,CAAC;IAEzD,WAAW;QAChB,2BAA2B;QAE3B;;;;;WAKG;QACH,MAAM,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AAC,sBAAsB,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;oBACrD,OAAO,EAAE,cAAc,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,0BAA0B,EAAE,EAAE,CAAC;gBACnF,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;QAEF,8BAA8B;QAE9B,MAAM,WAAW,GAAG,CAAC,KAA+C,EAAU,EAAE;YAC9E,QAAQ,KAAK,CAAC,aAAa,EAAE,CAAC;gBAC5B,KAAK,QAAQ,CAAC,CAAC,OAAO,YAAY,CAAC;gBACnC,KAAK,MAAM,CAAC,CAAC,OAAO,cAAc,CAAC;gBACnC,KAAK,QAAQ,CAAC,CAAC,OAAO,eAAe,CAAC;gBACtC,OAAO,CAAC,CAAC,OAAO,cAAc,CAAC;YACjC,CAAC;QACH,CAAC,CAAC;QAEF,yBAAyB;QAEzB,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,2BAA2B,CAAC;aACzD,OAAO,CAAC,YAAY,EAAE,aAAa,CAAC;aACpC,OAAO,CAAC,cAAc,EAAE,eAAe,CAAC;aACxC,OAAO,CAAC,eAAe,EAAE,gBAAgB,CAAC;aAC1C,mBAAmB,CAAC,KAAK,EAAE,WAAW,EAAE;YACvC,UAAU,EAAE,YAAY;YACxB,YAAY,EAAE,cAAc;YAC5B,aAAa,EAAE,eAAe;SAC/B,CAAC;aACD,OAAO,CAAC,YAAY,EAAE,GAAG,CAAC;aAC1B,OAAO,CAAC,cAAc,EAAE,GAAG,CAAC;aAC5B,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC;QAEjC,OAAO,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC5B,CAAC;CACF","sourcesContent":["import { StateGraph, START, END } from \"@langchain/langgraph\";\nimport type { NetworkMembershipGraphDatabase } from \"../../shared/interfaces/database.interface.js\";\nimport { protocolLogger } from \"../../shared/observability/protocol.logger.js\";\nimport { timed } from \"../../shared/observability/performance.js\";\nimport { NetworkMembershipGraphState } from \"./membership.state.js\";\n\nconst logger = protocolLogger(\"NetworkMembershipGraphFactory\");\n\n/**\n * Factory class to build and compile the Index Membership Graph.\n *\n * Handles CRUD operations for the index_members table:\n * - create: Add a member to an index (validates join policy and ownership)\n * - read: List members of an index (validates caller is member)\n * - delete: Remove a member from an index (future, validates ownership)\n */\nexport class NetworkMembershipGraphFactory {\n constructor(private database: NetworkMembershipGraphDatabase) {}\n\n public createGraph() {\n // --- NODE DEFINITIONS ---\n\n /**\n * Add Member Node: Add a user as a member of an index.\n * Handles two cases:\n * 1. Self-join (targetUserId === userId): Only allowed for public indexes (joinPolicy 'anyone')\n * 2. Invite others (targetUserId !== userId): Requires caller to be member; owner-only for invite_only\n */\n const addMemberNode = async (state: typeof NetworkMembershipGraphState.State) => {\n return timed(\"NetworkMembershipGraph.addMember\", async () => {\n logger.verbose(\"Add member to index\", {\n userId: state.userId,\n networkId: state.networkId,\n targetUserId: state.targetUserId,\n });\n\n if (!state.targetUserId) {\n return { mutationResult: { success: false, error: \"targetUserId is required.\" } };\n }\n\n try {\n const indexRecord = await this.database.getNetworkWithPermissions(state.networkId);\n if (!indexRecord) {\n return { mutationResult: { success: false, error: \"Index not found.\" } };\n }\n\n const joinPolicy = indexRecord.permissions.joinPolicy;\n const isSelfJoin = state.targetUserId === state.userId;\n\n if (isSelfJoin) {\n // Self-join: only allowed for public indexes\n if (joinPolicy !== 'anyone') {\n return {\n mutationResult: {\n success: false,\n error: \"This index is invite-only. You cannot join without an invitation from an existing member.\",\n },\n };\n }\n\n const result = await this.database.addMemberToNetwork(state.networkId, state.targetUserId, 'member');\n if (result.alreadyMember) {\n return { mutationResult: { success: true, message: \"You are already a member of this index.\" } };\n }\n\n return { mutationResult: { success: true, message: `You have joined \"${indexRecord.title}\".` } };\n }\n\n // Inviting others: must be a member first\n const isMember = await this.database.isNetworkMember(state.networkId, state.userId);\n if (!isMember) {\n return { mutationResult: { success: false, error: \"You must be a member of that index to add others.\" } };\n }\n\n if (joinPolicy === 'invite_only') {\n const isOwner = await this.database.isIndexOwner(state.networkId, state.userId);\n if (!isOwner) {\n return { mutationResult: { success: false, error: \"Only the index owner can add members when the index is invite-only.\" } };\n }\n }\n\n const result = await this.database.addMemberToNetwork(state.networkId, state.targetUserId, 'member');\n if (result.alreadyMember) {\n return { mutationResult: { success: true, message: \"That user is already a member of this index.\" } };\n }\n\n return { mutationResult: { success: true, message: \"Member added to the index.\" } };\n } catch (err) {\n logger.error(\"Add member failed\", { error: err });\n return {\n mutationResult: {\n success: false,\n error: err instanceof Error ? err.message : \"Failed to add member.\",\n },\n };\n }\n });\n };\n\n /**\n * List Members Node: List all members of an index.\n * Validates caller is a member.\n */\n const listMembersNode = async (state: typeof NetworkMembershipGraphState.State) => {\n return timed(\"NetworkMembershipGraph.listMembers\", async () => {\n logger.verbose(\"List index members\", {\n userId: state.userId,\n networkId: state.networkId,\n });\n\n try {\n const isMember = await this.database.isNetworkMember(state.networkId, state.userId);\n if (!isMember) {\n return {\n readResult: {\n networkId: state.networkId,\n count: 0,\n members: [],\n },\n error: \"Index not found or you are not a member.\",\n };\n }\n\n const members = await this.database.getNetworkMembersForMember(state.networkId, state.userId);\n return {\n readResult: {\n networkId: state.networkId,\n count: members.length,\n members: members.map((m) => ({\n userId: m.userId,\n name: m.name,\n avatar: m.avatar,\n permissions: m.permissions,\n intentCount: m.intentCount,\n joinedAt: m.joinedAt,\n })),\n },\n };\n } catch (err) {\n logger.error(\"List members failed\", { error: err });\n if (err instanceof Error && err.message === \"Access denied: Not a member of this index\") {\n return { error: \"You must be a member of that index.\" };\n }\n return { error: \"Failed to fetch index members.\" };\n }\n });\n };\n\n /**\n * Remove Member Node: Remove a member from an index (owner only).\n */\n const removeMemberNode = async (state: typeof NetworkMembershipGraphState.State) => {\n return timed(\"NetworkMembershipGraph.removeMember\", async () => {\n logger.verbose(\"Remove member from index\", {\n userId: state.userId,\n networkId: state.networkId,\n targetUserId: state.targetUserId,\n });\n\n if (!state.targetUserId) {\n return { mutationResult: { success: false, error: \"targetUserId is required.\" } };\n }\n\n // Cannot remove yourself via this flow\n if (state.targetUserId === state.userId) {\n return { mutationResult: { success: false, error: \"You cannot remove yourself. Use 'leave index' instead.\" } };\n }\n\n try {\n const isOwner = await this.database.isIndexOwner(state.networkId, state.userId);\n if (!isOwner) {\n return { mutationResult: { success: false, error: \"Only the index owner can remove members.\" } };\n }\n\n const result = await this.database.removeMemberFromIndex(state.networkId, state.targetUserId);\n\n if (result.wasOwner) {\n return { mutationResult: { success: false, error: \"Cannot remove the index owner.\" } };\n }\n if (result.notMember) {\n return { mutationResult: { success: false, error: \"User is not a member of this index.\" } };\n }\n if (!result.success) {\n return { mutationResult: { success: false, error: \"Failed to remove member.\" } };\n }\n\n return {\n mutationResult: {\n success: true,\n message: \"Member removed from the index.\",\n },\n };\n } catch (err) {\n logger.error(\"Remove member failed\", { error: err });\n return { mutationResult: { success: false, error: \"Failed to remove member.\" } };\n }\n });\n };\n\n // --- CONDITIONAL ROUTING ---\n\n const routeByMode = (state: typeof NetworkMembershipGraphState.State): string => {\n switch (state.operationMode) {\n case 'create': return 'add_member';\n case 'read': return 'list_members';\n case 'delete': return 'remove_member';\n default: return 'list_members';\n }\n };\n\n // --- GRAPH ASSEMBLY ---\n\n const workflow = new StateGraph(NetworkMembershipGraphState)\n .addNode(\"add_member\", addMemberNode)\n .addNode(\"list_members\", listMembersNode)\n .addNode(\"remove_member\", removeMemberNode)\n .addConditionalEdges(START, routeByMode, {\n add_member: \"add_member\",\n list_members: \"list_members\",\n remove_member: \"remove_member\",\n })\n .addEdge(\"add_member\", END)\n .addEdge(\"list_members\", END)\n .addEdge(\"remove_member\", END);\n\n return workflow.compile();\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"membership.graph.js","sourceRoot":"/","sources":["network/membership/membership.graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,KAAK,EAAE,GAAG,EAAE,MAAM,sBAAsB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AAc;YAC5B,aAAa,EAAE,eAAe;SAC/B,CAAC;aACD,OAAO,CAAC,YAAY,EAAE,GAAG,CAAC;aAC1B,OAAO,CAAC,cAAc,EAAE,GAAG,CAAC;aAC5B,OAAO,CAAC,eAAe,EAAE,GAAG,CAAC,CAAC;QAEjC,OAAO,QAAQ,CAAC,OAAO,EAAE,CAAC;IAC5B,CAAC;CACF","sourcesContent":["import { StateGraph, START, END } from \"@langchain/langgraph\";\nimport type { NetworkMembershipGraphDatabase } from \"../../shared/interfaces/database.interface.js\";\nimport { protocolLogger } from \"../../shared/observability/protocol.logger.js\";\nimport { timed } from \"../../shared/observability/performance.js\";\nimport { NetworkMembershipGraphState } from \"./membership.state.js\";\n\nconst logger = protocolLogger(\"NetworkMembershipGraphFactory\");\n\n/**\n * Factory class to build and compile the Network Membership Graph.\n *\n * Handles CRUD operations for the index_members table:\n * - create: Add a member to an index (validates join policy and ownership)\n * - read: List members of an index (validates caller is member)\n * - delete: Remove a member from an index (future, validates ownership)\n */\nexport class NetworkMembershipGraphFactory {\n constructor(private database: NetworkMembershipGraphDatabase) {}\n\n public createGraph() {\n // --- NODE DEFINITIONS ---\n\n /**\n * Add Member Node: Add a user as a member of an index.\n * Handles two cases:\n * 1. Self-join (targetUserId === userId): Only allowed for public networks (joinPolicy 'anyone')\n * 2. Invite others (targetUserId !== userId): Requires caller to be member; owner-only for invite_only\n */\n const addMemberNode = async (state: typeof NetworkMembershipGraphState.State) => {\n return timed(\"NetworkMembershipGraph.addMember\", async () => {\n logger.verbose(\"Add member to index\", {\n userId: state.userId,\n networkId: state.networkId,\n targetUserId: state.targetUserId,\n });\n\n if (!state.targetUserId) {\n return { mutationResult: { success: false, error: \"targetUserId is required.\" } };\n }\n\n try {\n const indexRecord = await this.database.getNetworkWithPermissions(state.networkId);\n if (!indexRecord) {\n return { mutationResult: { success: false, error: \"Index not found.\" } };\n }\n\n const joinPolicy = indexRecord.permissions.joinPolicy;\n const isSelfJoin = state.targetUserId === state.userId;\n\n if (isSelfJoin) {\n // Self-join: only allowed for public networks\n if (joinPolicy !== 'anyone') {\n return {\n mutationResult: {\n success: false,\n error: \"This network is invite-only. You cannot join without an invitation from an existing member.\",\n },\n };\n }\n\n const result = await this.database.addMemberToNetwork(state.networkId, state.targetUserId, 'member');\n if (result.alreadyMember) {\n return { mutationResult: { success: true, message: \"You are already a member of this network.\" } };\n }\n\n return { mutationResult: { success: true, message: `You have joined \"${indexRecord.title}\".` } };\n }\n\n // Inviting others: must be a member first\n const isMember = await this.database.isNetworkMember(state.networkId, state.userId);\n if (!isMember) {\n return { mutationResult: { success: false, error: \"You must be a member of that network to add others.\" } };\n }\n\n if (joinPolicy === 'invite_only') {\n const isOwner = await this.database.isIndexOwner(state.networkId, state.userId);\n if (!isOwner) {\n return { mutationResult: { success: false, error: \"Only the network owner can add members when the network is invite-only.\" } };\n }\n }\n\n const result = await this.database.addMemberToNetwork(state.networkId, state.targetUserId, 'member');\n if (result.alreadyMember) {\n return { mutationResult: { success: true, message: \"That user is already a member of this network.\" } };\n }\n\n return { mutationResult: { success: true, message: \"Member added to the network.\" } };\n } catch (err) {\n logger.error(\"Add member failed\", { error: err });\n return {\n mutationResult: {\n success: false,\n error: err instanceof Error ? err.message : \"Failed to add member.\",\n },\n };\n }\n });\n };\n\n /**\n * List Members Node: List all members of a network.\n * Validates caller is a member.\n */\n const listMembersNode = async (state: typeof NetworkMembershipGraphState.State) => {\n return timed(\"NetworkMembershipGraph.listMembers\", async () => {\n logger.verbose(\"List network members\", {\n userId: state.userId,\n networkId: state.networkId,\n });\n\n try {\n const isMember = await this.database.isNetworkMember(state.networkId, state.userId);\n if (!isMember) {\n return {\n readResult: {\n networkId: state.networkId,\n count: 0,\n members: [],\n },\n error: \"Network not found or you are not a member.\",\n };\n }\n\n const members = await this.database.getNetworkMembersForMember(state.networkId, state.userId);\n return {\n readResult: {\n networkId: state.networkId,\n count: members.length,\n members: members.map((m) => ({\n userId: m.userId,\n name: m.name,\n avatar: m.avatar,\n permissions: m.permissions,\n intentCount: m.intentCount,\n joinedAt: m.joinedAt,\n })),\n },\n };\n } catch (err) {\n logger.error(\"List members failed\", { error: err });\n if (err instanceof Error && err.message === \"Access denied: Not a member of this network\") {\n return { error: \"You must be a member of that network.\" };\n }\n return { error: \"Failed to fetch network members.\" };\n }\n });\n };\n\n /**\n * Remove Member Node: Remove a member from a network (owner only).\n */\n const removeMemberNode = async (state: typeof NetworkMembershipGraphState.State) => {\n return timed(\"NetworkMembershipGraph.removeMember\", async () => {\n logger.verbose(\"Remove member from network\", {\n userId: state.userId,\n networkId: state.networkId,\n targetUserId: state.targetUserId,\n });\n\n if (!state.targetUserId) {\n return { mutationResult: { success: false, error: \"targetUserId is required.\" } };\n }\n\n // Cannot remove yourself via this flow\n if (state.targetUserId === state.userId) {\n return { mutationResult: { success: false, error: \"You cannot remove yourself. Use 'leave network' instead.\" } };\n }\n\n try {\n const isOwner = await this.database.isIndexOwner(state.networkId, state.userId);\n if (!isOwner) {\n return { mutationResult: { success: false, error: \"Only the network owner can remove members.\" } };\n }\n\n const result = await this.database.removeMemberFromIndex(state.networkId, state.targetUserId);\n\n if (result.wasOwner) {\n return { mutationResult: { success: false, error: \"Cannot remove the network owner.\" } };\n }\n if (result.notMember) {\n return { mutationResult: { success: false, error: \"User is not a member of this network.\" } };\n }\n if (!result.success) {\n return { mutationResult: { success: false, error: \"Failed to remove member.\" } };\n }\n\n return {\n mutationResult: {\n success: true,\n message: \"Member removed from the index.\",\n },\n };\n } catch (err) {\n logger.error(\"Remove member failed\", { error: err });\n return { mutationResult: { success: false, error: \"Failed to remove member.\" } };\n }\n });\n };\n\n // --- CONDITIONAL ROUTING ---\n\n const routeByMode = (state: typeof NetworkMembershipGraphState.State): string => {\n switch (state.operationMode) {\n case 'create': return 'add_member';\n case 'read': return 'list_members';\n case 'delete': return 'remove_member';\n default: return 'list_members';\n }\n };\n\n // --- GRAPH ASSEMBLY ---\n\n const workflow = new StateGraph(NetworkMembershipGraphState)\n .addNode(\"add_member\", addMemberNode)\n .addNode(\"list_members\", listMembersNode)\n .addNode(\"remove_member\", removeMemberNode)\n .addConditionalEdges(START, routeByMode, {\n add_member: \"add_member\",\n list_members: \"list_members\",\n remove_member: \"remove_member\",\n })\n .addEdge(\"add_member\", END)\n .addEdge(\"list_members\", END)\n .addEdge(\"remove_member\", END);\n\n return workflow.compile();\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* Handles CRUD operations for
|
|
2
|
+
* Network Membership Graph State.
|
|
3
|
+
* Handles CRUD operations for network memberships (index_members table).
|
|
4
4
|
*
|
|
5
5
|
* Flow:
|
|
6
6
|
* START → routerNode → {addMemberNode | listMembersNode | removeMemberNode} → END
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Annotation } from "@langchain/langgraph";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* Handles CRUD operations for
|
|
3
|
+
* Network Membership Graph State.
|
|
4
|
+
* Handles CRUD operations for network memberships (index_members table).
|
|
5
5
|
*
|
|
6
6
|
* Flow:
|
|
7
7
|
* START → routerNode → {addMemberNode | listMembersNode | removeMemberNode} → END
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"membership.state.js","sourceRoot":"/","sources":["network/membership/membership.state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,UAAU,CAAC,IAAI,CAAC;IACzD,uDAAuD;IAEvD,+DAA+D;IAC/D,MAAM,EAAE,CAAA,UAAkB,CAAA;IAE1B,iDAAiD;IACjD,SAAS,EAAE,CAAA,UAAkB,CAAA;IAE7B,sBAAsB;IACtB,aAAa,EAAE,UAAU,CAA+B;QACtD,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,IAAI;QACrC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAe;KAC/B,CAAC;IAEF,+BAA+B;IAE/B,uDAAuD;IACvD,YAAY,EAAE,UAAU,CAAqB;QAC3C,OAAO,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI;QAC1B,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS;KACzB,CAAC;IAEF,kBAAkB;IAElB,6CAA6C;IAC7C,UAAU,EAAE,UAAU,CAWP;QACb,OAAO,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI;QAC1B,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS;KACzB,CAAC;IAEF,sCAAsC;IACtC,cAAc,EAAE,UAAU,CAIX;QACb,OAAO,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI;QAC1B,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS;KACzB,CAAC;IAEF,iDAAiD;IACjD,KAAK,EAAE,UAAU,CAAgB;QAC/B,OAAO,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI;QAC1B,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI;KACpB,CAAC;CACH,CAAC,CAAC","sourcesContent":["import { Annotation } from \"@langchain/langgraph\";\n\n/**\n *
|
|
1
|
+
{"version":3,"file":"membership.state.js","sourceRoot":"/","sources":["network/membership/membership.state.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAElD;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,2BAA2B,GAAG,UAAU,CAAC,IAAI,CAAC;IACzD,uDAAuD;IAEvD,+DAA+D;IAC/D,MAAM,EAAE,CAAA,UAAkB,CAAA;IAE1B,iDAAiD;IACjD,SAAS,EAAE,CAAA,UAAkB,CAAA;IAE7B,sBAAsB;IACtB,aAAa,EAAE,UAAU,CAA+B;QACtD,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI,IAAI,IAAI;QACrC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAe;KAC/B,CAAC;IAEF,+BAA+B;IAE/B,uDAAuD;IACvD,YAAY,EAAE,UAAU,CAAqB;QAC3C,OAAO,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI;QAC1B,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS;KACzB,CAAC;IAEF,kBAAkB;IAElB,6CAA6C;IAC7C,UAAU,EAAE,UAAU,CAWP;QACb,OAAO,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI;QAC1B,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS;KACzB,CAAC;IAEF,sCAAsC;IACtC,cAAc,EAAE,UAAU,CAIX;QACb,OAAO,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI;QAC1B,OAAO,EAAE,GAAG,EAAE,CAAC,SAAS;KACzB,CAAC;IAEF,iDAAiD;IACjD,KAAK,EAAE,UAAU,CAAgB;QAC/B,OAAO,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,EAAE,CAAC,IAAI;QAC1B,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI;KACpB,CAAC;CACH,CAAC,CAAC","sourcesContent":["import { Annotation } from \"@langchain/langgraph\";\n\n/**\n * Network Membership Graph State.\n * Handles CRUD operations for network memberships (index_members table).\n *\n * Flow:\n * START → routerNode → {addMemberNode | listMembersNode | removeMemberNode} → END\n */\nexport const NetworkMembershipGraphState = Annotation.Root({\n // --- Core Inputs (from ChatGraph via ToolContext) ---\n\n /** User performing the action (the actor). Always required. */\n userId: Annotation<string>,\n\n /** Target index. Required for all operations. */\n networkId: Annotation<string>,\n\n /** Operation mode. */\n operationMode: Annotation<'create' | 'read' | 'delete'>({\n reducer: (curr, next) => next ?? curr,\n default: () => 'read' as const,\n }),\n\n // --- Mode-Specific Inputs ---\n\n /** For create/delete: the user being added/removed. */\n targetUserId: Annotation<string | undefined>({\n reducer: (_, next) => next,\n default: () => undefined,\n }),\n\n // --- Outputs ---\n\n /** Output for read mode: list of members. */\n readResult: Annotation<{\n networkId: string;\n count: number;\n members: Array<{\n userId: string;\n name: string;\n avatar: string | null;\n permissions: string[];\n intentCount: number;\n joinedAt: Date;\n }>;\n } | undefined>({\n reducer: (_, next) => next,\n default: () => undefined,\n }),\n\n /** Output for create/delete modes. */\n mutationResult: Annotation<{\n success: boolean;\n message?: string;\n error?: string;\n } | undefined>({\n reducer: (_, next) => next,\n default: () => undefined,\n }),\n\n /** Error message if graph could not complete. */\n error: Annotation<string | null>({\n reducer: (_, next) => next,\n default: () => null,\n }),\n});\n"]}
|
|
@@ -3,7 +3,7 @@ import { NetworkGraphDatabase } from "../shared/interfaces/database.interface.js
|
|
|
3
3
|
* Factory class to build and compile the Index (CRUD) Graph.
|
|
4
4
|
*
|
|
5
5
|
* Handles create, read, update, and delete operations for indexes.
|
|
6
|
-
* Membership and intent-
|
|
6
|
+
* Membership and intent-network assignment operations are handled by
|
|
7
7
|
* separate graphs (NetworkMembershipGraph and IntentNetworkGraph).
|
|
8
8
|
*
|
|
9
9
|
* Flow:
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"network.graph.d.ts","sourceRoot":"/","sources":["network/network.graph.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAQlF;;;;;;;;;GASG;AACH,qBAAa,mBAAmB;IAClB,OAAO,CAAC,QAAQ;gBAAR,QAAQ,EAAE,oBAAoB;IAE3C,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"network.graph.d.ts","sourceRoot":"/","sources":["network/network.graph.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAQlF;;;;;;;;;GASG;AACH,qBAAa,mBAAm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