@indexnetwork/protocol 14.3.2-rc.477.1 → 17.0.0-rc.479.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/CHANGELOG.md +141 -0
- package/IMPLEMENTATION.md +50 -52
- package/STABILITY.md +3 -3
- package/dist/chat/chat.agent.js +2 -3
- package/dist/chat/chat.graph.d.ts +41 -1
- package/dist/chat/chat.graph.js +108 -127
- package/dist/chat/negotiator.persona.d.ts +1 -1
- package/dist/chat/negotiator.persona.js +1 -4
- package/dist/chat/negotiator.prompt.js +1 -2
- package/dist/chat/onboarding.persona.js +0 -1
- package/dist/chat/reporter.persona.js +0 -1
- package/dist/chat/signal.persona.js +0 -1
- package/dist/contacts/application/contact.tools.d.ts +6 -9
- package/dist/contacts/application/contact.tools.js +11 -92
- package/dist/contacts/application/index.d.ts +2 -14
- package/dist/contacts/application/index.js +2 -13
- package/dist/contacts/domain/contact.types.d.ts +0 -23
- package/dist/contacts/domain/index.d.ts +2 -6
- package/dist/contacts/index.d.ts +1 -1
- package/dist/contacts/index.js +1 -1
- package/dist/contacts/ports/contact.repository.port.d.ts +5 -12
- package/dist/contacts/ports/contact.repository.port.js +4 -6
- package/dist/contacts/ports/contact.tools.port.d.ts +1 -3
- package/dist/contacts/ports/contact.tools.port.js +1 -2
- package/dist/contacts/ports/index.d.ts +1 -1
- package/dist/contacts/ports/index.js +1 -1
- package/dist/discovery/hyde.frame.d.ts +4 -4
- package/dist/discovery/hyde.graph.d.ts +71 -12
- package/dist/discovery/hyde.graph.js +337 -335
- package/dist/discovery/lens.inferrer.d.ts +6 -6
- package/dist/enrichment/enrichment.graph.d.ts +127 -9
- package/dist/enrichment/enrichment.graph.js +633 -655
- package/dist/enrichment/enrichment.state.d.ts +1 -1
- package/dist/enrichment/enrichment.tools.context-read.d.ts +10 -0
- package/dist/enrichment/enrichment.tools.context-read.js +353 -0
- package/dist/enrichment/enrichment.tools.context-write.d.ts +9 -0
- package/dist/enrichment/enrichment.tools.context-write.js +417 -0
- package/dist/enrichment/enrichment.tools.d.ts +11 -1
- package/dist/enrichment/enrichment.tools.helpers.d.ts +139 -0
- package/dist/enrichment/enrichment.tools.helpers.js +234 -0
- package/dist/enrichment/enrichment.tools.js +16 -975
- package/dist/index.d.ts +27 -50
- package/dist/index.js +17 -28
- package/dist/intents/application/intent.graph.d.ts +71 -67
- package/dist/intents/application/intent.graph.execute.d.ts +59 -0
- package/dist/intents/application/intent.graph.execute.js +301 -0
- package/dist/intents/application/intent.graph.infer.d.ts +44 -0
- package/dist/intents/application/intent.graph.infer.js +97 -0
- package/dist/intents/application/intent.graph.js +96 -888
- package/dist/intents/application/intent.graph.reconcile.d.ts +71 -0
- package/dist/intents/application/intent.graph.reconcile.js +274 -0
- package/dist/intents/application/intent.graph.shared.d.ts +70 -0
- package/dist/intents/application/intent.graph.shared.js +153 -0
- package/dist/intents/domain/intent.state.d.ts +1 -1
- package/dist/maintenance/maintenance.graph.d.ts +66 -3
- package/dist/maintenance/maintenance.graph.js +155 -156
- package/dist/mcp/mcp.authorization-policy.d.ts +24 -28
- package/dist/mcp/mcp.authorization-policy.js +14 -34
- package/dist/mcp/mcp.server.d.ts +3 -3
- package/dist/mcp/mcp.server.js +14 -20
- package/dist/negotiations/application/negotiation.candidates.d.ts +83 -0
- package/dist/negotiations/application/negotiation.candidates.js +162 -0
- package/dist/negotiations/application/negotiation.graph.d.ts +91 -157
- package/dist/negotiations/application/negotiation.graph.finalize.d.ts +5 -0
- package/dist/negotiations/application/negotiation.graph.finalize.js +280 -0
- package/dist/negotiations/application/negotiation.graph.init.d.ts +54 -0
- package/dist/negotiations/application/negotiation.graph.init.js +227 -0
- package/dist/negotiations/application/negotiation.graph.js +69 -1388
- package/dist/negotiations/application/negotiation.graph.screen.d.ts +23 -0
- package/dist/negotiations/application/negotiation.graph.screen.js +108 -0
- package/dist/negotiations/application/negotiation.graph.shared.d.ts +75 -0
- package/dist/negotiations/application/negotiation.graph.shared.js +125 -0
- package/dist/negotiations/application/negotiation.graph.turn.d.ts +105 -0
- package/dist/negotiations/application/negotiation.graph.turn.js +484 -0
- package/dist/negotiations/domain/negotiation.state.d.ts +1 -1
- package/dist/negotiations/domain/negotiation.state.js +0 -1
- package/dist/networks/application/indexer.graph.d.ts +165 -7
- package/dist/networks/application/indexer.graph.js +339 -388
- package/dist/networks/application/indexer.state.d.ts +1 -1
- package/dist/networks/application/membership.graph.d.ts +83 -5
- package/dist/networks/application/membership.graph.js +177 -207
- package/dist/networks/application/network.graph.d.ts +148 -5
- package/dist/networks/application/network.graph.js +249 -278
- package/dist/networks/domain/membership.state.d.ts +1 -1
- package/dist/networks/domain/network.state.d.ts +1 -1
- package/dist/opportunities/application/delivery-card.cache.d.ts +1 -1
- package/dist/opportunities/application/delivery-card.cache.js +2 -2
- package/dist/opportunities/application/index.d.ts +2 -2
- package/dist/opportunities/application/index.js +2 -2
- package/dist/opportunities/application/opportunity.evaluator.js +1 -1
- package/dist/opportunities/application/opportunity.graph.d.ts +686 -473
- package/dist/opportunities/application/opportunity.graph.discovery-strategies.d.ts +109 -0
- package/dist/opportunities/application/opportunity.graph.discovery-strategies.js +451 -0
- package/dist/opportunities/application/opportunity.graph.discovery.d.ts +69 -0
- package/dist/opportunities/application/opportunity.graph.discovery.js +397 -0
- package/dist/opportunities/application/opportunity.graph.evaluation.d.ts +82 -0
- package/dist/opportunities/application/opportunity.graph.evaluation.js +608 -0
- package/dist/opportunities/application/opportunity.graph.js +120 -3690
- package/dist/opportunities/application/opportunity.graph.modes.d.ts +538 -0
- package/dist/opportunities/application/opportunity.graph.modes.js +538 -0
- package/dist/opportunities/application/opportunity.graph.negotiate.d.ts +109 -0
- package/dist/opportunities/application/opportunity.graph.negotiate.js +392 -0
- package/dist/opportunities/application/opportunity.graph.persist-node.d.ts +93 -0
- package/dist/opportunities/application/opportunity.graph.persist-node.js +765 -0
- package/dist/opportunities/application/opportunity.graph.prep.d.ts +150 -0
- package/dist/opportunities/application/opportunity.graph.prep.js +381 -0
- package/dist/opportunities/application/opportunity.graph.shared.d.ts +173 -0
- package/dist/opportunities/application/opportunity.graph.shared.js +199 -0
- package/dist/opportunities/application/opportunity.presentation.d.ts +399 -0
- package/dist/opportunities/application/{opportunity.presenter.js → opportunity.presentation.js} +735 -9
- package/dist/opportunities/application/opportunity.tools.cards.d.ts +152 -0
- package/dist/opportunities/application/opportunity.tools.cards.js +235 -0
- package/dist/opportunities/application/opportunity.tools.d.ts +8 -114
- package/dist/opportunities/application/opportunity.tools.js +28 -711
- package/dist/opportunities/application/opportunity.tools.list.d.ts +10 -0
- package/dist/opportunities/application/opportunity.tools.list.js +493 -0
- package/dist/opportunities/domain/index.d.ts +3 -3
- package/dist/opportunities/domain/index.js +3 -3
- package/dist/opportunities/domain/opportunity.state.d.ts +19 -19
- package/dist/opportunities/index.d.ts +6 -6
- package/dist/opportunities/index.js +4 -4
- package/dist/opportunities/ports/opportunity.tools.port.d.ts +1 -1
- package/dist/opportunities/radar/radar.graph.d.ts +57 -13
- package/dist/opportunities/radar/radar.graph.js +470 -471
- package/dist/premises/premise.graph.d.ts +88 -20
- package/dist/premises/premise.graph.js +207 -218
- package/dist/questions/domain/question.schema.d.ts +40 -40
- package/dist/shared/agent/tool.factory.js +0 -8
- package/dist/shared/agent/tool.helpers.d.ts +21 -45
- package/dist/shared/agent/tool.helpers.js +1 -2
- package/dist/shared/agent/tool.registry.d.ts +4 -3
- package/dist/shared/agent/tool.registry.js +2 -4
- package/dist/shared/agent/tool.runtime.js +0 -2
- package/dist/shared/agent/utility.tools.js +9 -13
- package/dist/shared/interfaces/database.capabilities.d.ts +100 -0
- package/dist/shared/interfaces/database.capabilities.js +7 -0
- package/dist/shared/interfaces/database.entities.d.ts +533 -0
- package/dist/shared/interfaces/database.entities.js +10 -0
- package/dist/shared/interfaces/database.identity-queries.d.ts +294 -0
- package/dist/shared/interfaces/database.identity-queries.js +4 -0
- package/dist/shared/interfaces/database.interface.d.ts +15 -2277
- package/dist/shared/interfaces/database.interface.js +8 -0
- package/dist/shared/interfaces/database.member-queries.d.ts +221 -0
- package/dist/shared/interfaces/database.member-queries.js +4 -0
- package/dist/shared/interfaces/database.negotiation.d.ts +305 -0
- package/dist/shared/interfaces/database.negotiation.js +26 -0
- package/dist/shared/interfaces/database.network-queries.d.ts +277 -0
- package/dist/shared/interfaces/database.network-queries.js +4 -0
- package/dist/shared/interfaces/database.opportunity-queries.d.ts +285 -0
- package/dist/shared/interfaces/database.opportunity-queries.js +4 -0
- package/dist/shared/interfaces/database.port.d.ts +322 -0
- package/dist/shared/interfaces/database.port.js +29 -0
- package/dist/shared/schemas/discovery-question.schema.d.ts +14 -14
- package/dist/shared/schemas/negotiation-digest.schema.d.ts +2 -2
- package/package.json +2 -15
- package/dist/contacts/application/contact.inviter.d.ts +0 -49
- package/dist/contacts/application/contact.inviter.js +0 -64
- package/dist/integrations/application/index.d.ts +0 -14
- package/dist/integrations/application/index.js +0 -14
- package/dist/integrations/application/integration.tools.d.ts +0 -27
- package/dist/integrations/application/integration.tools.js +0 -98
- package/dist/integrations/domain/index.d.ts +0 -16
- package/dist/integrations/domain/index.js +0 -1
- package/dist/integrations/domain/integration.types.d.ts +0 -51
- package/dist/integrations/domain/integration.types.js +0 -9
- package/dist/integrations/index.d.ts +0 -10
- package/dist/integrations/index.js +0 -8
- package/dist/integrations/ports/index.d.ts +0 -25
- package/dist/integrations/ports/index.js +0 -23
- package/dist/integrations/ports/integration.adapter.port.d.ts +0 -62
- package/dist/integrations/ports/integration.adapter.port.js +0 -15
- package/dist/integrations/ports/integration.importer.port.d.ts +0 -31
- package/dist/integrations/ports/integration.importer.port.js +0 -15
- package/dist/integrations/ports/integration.tools.port.d.ts +0 -25
- package/dist/integrations/ports/integration.tools.port.js +0 -18
- package/dist/opportunities/application/opportunity.card-presentation.d.ts +0 -44
- package/dist/opportunities/application/opportunity.card-presentation.js +0 -93
- package/dist/opportunities/application/opportunity.presenter.d.ts +0 -156
- package/dist/opportunities/domain/opportunity.presentation-cache.d.ts +0 -5
- package/dist/opportunities/domain/opportunity.presentation-cache.js +0 -11
- package/dist/opportunities/domain/opportunity.presentation.d.ts +0 -76
- package/dist/opportunities/domain/opportunity.presentation.js +0 -516
- package/dist/opportunities/domain/opportunity.safe-presentation.d.ts +0 -104
- package/dist/opportunities/domain/opportunity.safe-presentation.js +0 -102
|
@@ -1,16 +1,29 @@
|
|
|
1
|
+
import { PremiseGraphState } from "./premise.state.js";
|
|
1
2
|
import type { PremiseAnalyzerOutput } from "./premise.analyzer.js";
|
|
2
3
|
import { PremiseIndexer } from "./premise.indexer.js";
|
|
3
4
|
import type { PremiseGraphDatabase, PremiseAnalysis } from "../shared/interfaces/database.interface.js";
|
|
4
5
|
import type { Embedder } from "../shared/interfaces/embedder.interface.js";
|
|
5
6
|
import type { DebugMetaAgent } from "../agents/index.js";
|
|
7
|
+
/**
|
|
8
|
+
* Graph factory for premise lifecycle: create, update, and query modes.
|
|
9
|
+
*/
|
|
10
|
+
/** The graph's channel state, as every node sees it. */
|
|
11
|
+
export type PremiseState = typeof PremiseGraphState.State;
|
|
12
|
+
/** Everything the premise nodes reach for. */
|
|
13
|
+
export interface PremiseGraphDeps {
|
|
14
|
+
database: PremiseGraphDatabase;
|
|
15
|
+
embedder: Embedder;
|
|
16
|
+
premiseIndexer: PremiseIndexer;
|
|
17
|
+
premiseAnalyzer: {
|
|
18
|
+
invoke(premiseText: string, profileContext?: string): Promise<PremiseAnalyzerOutput>;
|
|
19
|
+
};
|
|
20
|
+
}
|
|
6
21
|
/**
|
|
7
22
|
* Graph factory for premise lifecycle: create, update, and query modes.
|
|
8
23
|
*/
|
|
9
24
|
export declare class PremiseGraphFactory {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
private premiseIndexer;
|
|
13
|
-
private premiseAnalyzer;
|
|
25
|
+
/** Resolved dependency bag shared by every node. */
|
|
26
|
+
readonly deps: PremiseGraphDeps;
|
|
14
27
|
constructor(database: PremiseGraphDatabase, embedder: Embedder, premiseIndexer?: PremiseIndexer, premiseAnalyzer?: {
|
|
15
28
|
invoke(premiseText: string, profileContext?: string): Promise<PremiseAnalyzerOutput>;
|
|
16
29
|
});
|
|
@@ -36,7 +49,7 @@ export declare class PremiseGraphFactory {
|
|
|
36
49
|
targetPremiseId: string | undefined;
|
|
37
50
|
analysis: PremiseAnalysis | undefined;
|
|
38
51
|
embedding: number[] | undefined;
|
|
39
|
-
premise: import("../shared/interfaces/database.
|
|
52
|
+
premise: import("../shared/interfaces/database.entities.js").PremiseRecord | undefined;
|
|
40
53
|
duplicateOf: {
|
|
41
54
|
premiseId: string;
|
|
42
55
|
assertionText: string;
|
|
@@ -48,7 +61,7 @@ export declare class PremiseGraphFactory {
|
|
|
48
61
|
}[];
|
|
49
62
|
error: string | undefined;
|
|
50
63
|
readResult: {
|
|
51
|
-
premises: import("../shared/interfaces/database.
|
|
64
|
+
premises: import("../shared/interfaces/database.entities.js").PremiseRecord[];
|
|
52
65
|
count: number;
|
|
53
66
|
message?: string;
|
|
54
67
|
} | undefined;
|
|
@@ -70,7 +83,7 @@ export declare class PremiseGraphFactory {
|
|
|
70
83
|
targetPremiseId?: string | import("@langchain/langgraph").OverwriteValue<string | undefined> | undefined;
|
|
71
84
|
analysis?: PremiseAnalysis | import("@langchain/langgraph").OverwriteValue<PremiseAnalysis | undefined> | undefined;
|
|
72
85
|
embedding?: number[] | import("@langchain/langgraph").OverwriteValue<number[] | undefined> | undefined;
|
|
73
|
-
premise?: import("../shared/interfaces/database.
|
|
86
|
+
premise?: import("../shared/interfaces/database.entities.js").PremiseRecord | import("@langchain/langgraph").OverwriteValue<import("../shared/interfaces/database.entities.js").PremiseRecord | undefined> | undefined;
|
|
74
87
|
duplicateOf?: {
|
|
75
88
|
premiseId: string;
|
|
76
89
|
assertionText: string;
|
|
@@ -89,16 +102,16 @@ export declare class PremiseGraphFactory {
|
|
|
89
102
|
}[]> | undefined;
|
|
90
103
|
error?: string | import("@langchain/langgraph").OverwriteValue<string | undefined> | undefined;
|
|
91
104
|
readResult?: {
|
|
92
|
-
premises: import("../shared/interfaces/database.
|
|
105
|
+
premises: import("../shared/interfaces/database.entities.js").PremiseRecord[];
|
|
93
106
|
count: number;
|
|
94
107
|
message?: string;
|
|
95
108
|
} | import("@langchain/langgraph").OverwriteValue<{
|
|
96
|
-
premises: import("../shared/interfaces/database.
|
|
109
|
+
premises: import("../shared/interfaces/database.entities.js").PremiseRecord[];
|
|
97
110
|
count: number;
|
|
98
111
|
message?: string;
|
|
99
112
|
} | undefined> | undefined;
|
|
100
113
|
agentTimings?: DebugMetaAgent[] | import("@langchain/langgraph").OverwriteValue<DebugMetaAgent[]> | undefined;
|
|
101
|
-
}, "index" | "query" | "__start__" | "
|
|
114
|
+
}, "index" | "query" | "__start__" | "persist" | "analyze" | "embed" | "dedupe", {
|
|
102
115
|
userId: {
|
|
103
116
|
(annotation: import("@langchain/langgraph").SingleReducer<string, string>): import("@langchain/langgraph").BaseChannel<string, string | import("@langchain/langgraph").OverwriteValue<string>, unknown>;
|
|
104
117
|
(): import("@langchain/langgraph").LastValue<string>;
|
|
@@ -119,7 +132,7 @@ export declare class PremiseGraphFactory {
|
|
|
119
132
|
targetPremiseId: import("@langchain/langgraph").BaseChannel<string | undefined, string | import("@langchain/langgraph").OverwriteValue<string | undefined> | undefined, unknown>;
|
|
120
133
|
analysis: import("@langchain/langgraph").BaseChannel<PremiseAnalysis | undefined, PremiseAnalysis | import("@langchain/langgraph").OverwriteValue<PremiseAnalysis | undefined> | undefined, unknown>;
|
|
121
134
|
embedding: import("@langchain/langgraph").BaseChannel<number[] | undefined, number[] | import("@langchain/langgraph").OverwriteValue<number[] | undefined> | undefined, unknown>;
|
|
122
|
-
premise: import("@langchain/langgraph").BaseChannel<import("../shared/interfaces/database.
|
|
135
|
+
premise: import("@langchain/langgraph").BaseChannel<import("../shared/interfaces/database.entities.js").PremiseRecord | undefined, import("../shared/interfaces/database.entities.js").PremiseRecord | import("@langchain/langgraph").OverwriteValue<import("../shared/interfaces/database.entities.js").PremiseRecord | undefined> | undefined, unknown>;
|
|
123
136
|
duplicateOf: import("@langchain/langgraph").BaseChannel<{
|
|
124
137
|
premiseId: string;
|
|
125
138
|
assertionText: string;
|
|
@@ -145,15 +158,15 @@ export declare class PremiseGraphFactory {
|
|
|
145
158
|
}[]>, unknown>;
|
|
146
159
|
error: import("@langchain/langgraph").BaseChannel<string | undefined, string | import("@langchain/langgraph").OverwriteValue<string | undefined> | undefined, unknown>;
|
|
147
160
|
readResult: import("@langchain/langgraph").BaseChannel<{
|
|
148
|
-
premises: import("../shared/interfaces/database.
|
|
161
|
+
premises: import("../shared/interfaces/database.entities.js").PremiseRecord[];
|
|
149
162
|
count: number;
|
|
150
163
|
message?: string;
|
|
151
164
|
} | undefined, {
|
|
152
|
-
premises: import("../shared/interfaces/database.
|
|
165
|
+
premises: import("../shared/interfaces/database.entities.js").PremiseRecord[];
|
|
153
166
|
count: number;
|
|
154
167
|
message?: string;
|
|
155
168
|
} | import("@langchain/langgraph").OverwriteValue<{
|
|
156
|
-
premises: import("../shared/interfaces/database.
|
|
169
|
+
premises: import("../shared/interfaces/database.entities.js").PremiseRecord[];
|
|
157
170
|
count: number;
|
|
158
171
|
message?: string;
|
|
159
172
|
} | undefined> | undefined, unknown>;
|
|
@@ -179,7 +192,7 @@ export declare class PremiseGraphFactory {
|
|
|
179
192
|
targetPremiseId: import("@langchain/langgraph").BaseChannel<string | undefined, string | import("@langchain/langgraph").OverwriteValue<string | undefined> | undefined, unknown>;
|
|
180
193
|
analysis: import("@langchain/langgraph").BaseChannel<PremiseAnalysis | undefined, PremiseAnalysis | import("@langchain/langgraph").OverwriteValue<PremiseAnalysis | undefined> | undefined, unknown>;
|
|
181
194
|
embedding: import("@langchain/langgraph").BaseChannel<number[] | undefined, number[] | import("@langchain/langgraph").OverwriteValue<number[] | undefined> | undefined, unknown>;
|
|
182
|
-
premise: import("@langchain/langgraph").BaseChannel<import("../shared/interfaces/database.
|
|
195
|
+
premise: import("@langchain/langgraph").BaseChannel<import("../shared/interfaces/database.entities.js").PremiseRecord | undefined, import("../shared/interfaces/database.entities.js").PremiseRecord | import("@langchain/langgraph").OverwriteValue<import("../shared/interfaces/database.entities.js").PremiseRecord | undefined> | undefined, unknown>;
|
|
183
196
|
duplicateOf: import("@langchain/langgraph").BaseChannel<{
|
|
184
197
|
premiseId: string;
|
|
185
198
|
assertionText: string;
|
|
@@ -205,15 +218,15 @@ export declare class PremiseGraphFactory {
|
|
|
205
218
|
}[]>, unknown>;
|
|
206
219
|
error: import("@langchain/langgraph").BaseChannel<string | undefined, string | import("@langchain/langgraph").OverwriteValue<string | undefined> | undefined, unknown>;
|
|
207
220
|
readResult: import("@langchain/langgraph").BaseChannel<{
|
|
208
|
-
premises: import("../shared/interfaces/database.
|
|
221
|
+
premises: import("../shared/interfaces/database.entities.js").PremiseRecord[];
|
|
209
222
|
count: number;
|
|
210
223
|
message?: string;
|
|
211
224
|
} | undefined, {
|
|
212
|
-
premises: import("../shared/interfaces/database.
|
|
225
|
+
premises: import("../shared/interfaces/database.entities.js").PremiseRecord[];
|
|
213
226
|
count: number;
|
|
214
227
|
message?: string;
|
|
215
228
|
} | import("@langchain/langgraph").OverwriteValue<{
|
|
216
|
-
premises: import("../shared/interfaces/database.
|
|
229
|
+
premises: import("../shared/interfaces/database.entities.js").PremiseRecord[];
|
|
217
230
|
count: number;
|
|
218
231
|
message?: string;
|
|
219
232
|
} | undefined> | undefined, unknown>;
|
|
@@ -221,7 +234,7 @@ export declare class PremiseGraphFactory {
|
|
|
221
234
|
}, import("@langchain/langgraph").StateDefinition, {
|
|
222
235
|
query: {
|
|
223
236
|
readResult: {
|
|
224
|
-
premises: import("../shared/interfaces/database.
|
|
237
|
+
premises: import("../shared/interfaces/database.entities.js").PremiseRecord[];
|
|
225
238
|
count: number;
|
|
226
239
|
};
|
|
227
240
|
};
|
|
@@ -260,7 +273,7 @@ export declare class PremiseGraphFactory {
|
|
|
260
273
|
error: string;
|
|
261
274
|
premise?: undefined;
|
|
262
275
|
} | {
|
|
263
|
-
premise: import("../shared/interfaces/database.
|
|
276
|
+
premise: import("../shared/interfaces/database.entities.js").PremiseRecord;
|
|
264
277
|
error?: undefined;
|
|
265
278
|
};
|
|
266
279
|
index: {
|
|
@@ -275,3 +288,58 @@ export declare class PremiseGraphFactory {
|
|
|
275
288
|
};
|
|
276
289
|
}, unknown, unknown, []>;
|
|
277
290
|
}
|
|
291
|
+
export declare function queryNode(state: PremiseState, deps: PremiseGraphDeps): Promise<{
|
|
292
|
+
readResult: {
|
|
293
|
+
premises: import("../shared/interfaces/database.entities.js").PremiseRecord[];
|
|
294
|
+
count: number;
|
|
295
|
+
};
|
|
296
|
+
}>;
|
|
297
|
+
export declare function analyzeNode(state: PremiseState, deps: PremiseGraphDeps): Promise<{
|
|
298
|
+
error: string;
|
|
299
|
+
analysis?: undefined;
|
|
300
|
+
agentTimings?: undefined;
|
|
301
|
+
} | {
|
|
302
|
+
analysis: PremiseAnalysis;
|
|
303
|
+
agentTimings: DebugMetaAgent[];
|
|
304
|
+
error?: undefined;
|
|
305
|
+
}>;
|
|
306
|
+
export declare function embedNode(state: PremiseState, deps: PremiseGraphDeps): Promise<{
|
|
307
|
+
error?: undefined;
|
|
308
|
+
embedding?: undefined;
|
|
309
|
+
} | {
|
|
310
|
+
error: string;
|
|
311
|
+
embedding?: undefined;
|
|
312
|
+
} | {
|
|
313
|
+
embedding: number[];
|
|
314
|
+
error?: undefined;
|
|
315
|
+
}>;
|
|
316
|
+
export declare function dedupeNode(state: PremiseState, deps: PremiseGraphDeps): Promise<{
|
|
317
|
+
duplicateOf?: undefined;
|
|
318
|
+
} | {
|
|
319
|
+
duplicateOf: {
|
|
320
|
+
premiseId: string;
|
|
321
|
+
assertionText: string;
|
|
322
|
+
similarity: number;
|
|
323
|
+
};
|
|
324
|
+
}>;
|
|
325
|
+
export declare function persistNode(state: PremiseState, deps: PremiseGraphDeps): Promise<{
|
|
326
|
+
error?: undefined;
|
|
327
|
+
premise?: undefined;
|
|
328
|
+
} | {
|
|
329
|
+
error: string;
|
|
330
|
+
premise?: undefined;
|
|
331
|
+
} | {
|
|
332
|
+
premise: import("../shared/interfaces/database.entities.js").PremiseRecord;
|
|
333
|
+
error?: undefined;
|
|
334
|
+
}>;
|
|
335
|
+
export declare function indexNode(state: PremiseState, deps: PremiseGraphDeps): Promise<{
|
|
336
|
+
networkAssignments?: undefined;
|
|
337
|
+
agentTimings?: undefined;
|
|
338
|
+
} | {
|
|
339
|
+
networkAssignments: {
|
|
340
|
+
networkId: string;
|
|
341
|
+
relevancyScore: number;
|
|
342
|
+
}[];
|
|
343
|
+
agentTimings: DebugMetaAgent[];
|
|
344
|
+
}>;
|
|
345
|
+
export declare function routeByMode(state: PremiseState): "query" | "end" | "analyze";
|
|
@@ -43,10 +43,7 @@ function deriveProvenanceConfidence(analysis) {
|
|
|
43
43
|
*/
|
|
44
44
|
export class PremiseGraphFactory {
|
|
45
45
|
constructor(database, embedder, premiseIndexer = new PremiseIndexer(), premiseAnalyzer = new PremiseAnalyzer()) {
|
|
46
|
-
this.
|
|
47
|
-
this.embedder = embedder;
|
|
48
|
-
this.premiseIndexer = premiseIndexer;
|
|
49
|
-
this.premiseAnalyzer = premiseAnalyzer;
|
|
46
|
+
this.deps = { database, embedder, premiseIndexer, premiseAnalyzer };
|
|
50
47
|
}
|
|
51
48
|
/**
|
|
52
49
|
* Compiles and returns the premise lifecycle graph.
|
|
@@ -54,221 +51,14 @@ export class PremiseGraphFactory {
|
|
|
54
51
|
* @returns A compiled LangGraph graph handling create, update, and query modes.
|
|
55
52
|
*/
|
|
56
53
|
createGraph() {
|
|
57
|
-
const
|
|
58
|
-
const indexer = this.premiseIndexer;
|
|
59
|
-
const queryNode = async (state) => {
|
|
60
|
-
return timed("PremiseGraph.query", async () => {
|
|
61
|
-
queryLog.verbose('Fetching premises for user', { userId: state.userId });
|
|
62
|
-
const premises = await this.database.getPremisesForUser(state.userId, 'ACTIVE');
|
|
63
|
-
return {
|
|
64
|
-
readResult: {
|
|
65
|
-
premises,
|
|
66
|
-
count: premises.length,
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
});
|
|
70
|
-
};
|
|
71
|
-
const analyzeNode = async (state) => {
|
|
72
|
-
return timed("PremiseGraph.analyze", async () => {
|
|
73
|
-
if (!state.assertionText) {
|
|
74
|
-
return { error: "assertionText is required for create/update mode" };
|
|
75
|
-
}
|
|
76
|
-
analyzeLog.verbose('Analyzing assertion text', { preview: state.assertionText.substring(0, 50) });
|
|
77
|
-
const start = Date.now();
|
|
78
|
-
const result = await analyzer.invoke(state.assertionText);
|
|
79
|
-
const timing = {
|
|
80
|
-
name: "premise-analyzer",
|
|
81
|
-
durationMs: Date.now() - start,
|
|
82
|
-
};
|
|
83
|
-
const analysis = {
|
|
84
|
-
speechActType: result.speechActType,
|
|
85
|
-
felicityAuthority: result.felicityAuthority,
|
|
86
|
-
felicitySincerity: result.felicitySincerity,
|
|
87
|
-
felicityClarity: result.felicityClarity,
|
|
88
|
-
semanticEntropy: result.semanticEntropy,
|
|
89
|
-
};
|
|
90
|
-
return { analysis, agentTimings: [timing] };
|
|
91
|
-
});
|
|
92
|
-
};
|
|
93
|
-
const embedNode = async (state) => {
|
|
94
|
-
return timed("PremiseGraph.embed", async () => {
|
|
95
|
-
if (state.error)
|
|
96
|
-
return {};
|
|
97
|
-
if (!state.assertionText) {
|
|
98
|
-
return { error: "assertionText is required for embedding" };
|
|
99
|
-
}
|
|
100
|
-
embedLog.verbose(`Generating embedding for premise`);
|
|
101
|
-
// Embedder.generate returns number[] | number[][], cast for single string input
|
|
102
|
-
const embedding = await this.embedder.generate(state.assertionText, undefined, getAbortSignalConfig());
|
|
103
|
-
return { embedding };
|
|
104
|
-
});
|
|
105
|
-
};
|
|
106
|
-
// ─────────────────────────────────────────────────────────
|
|
107
|
-
// NODE: Dedupe (create mode only)
|
|
108
|
-
// Skips persisting a near-duplicate of an existing ACTIVE premise for the same
|
|
109
|
-
// user. Re-running similar input (e.g. repeated enrichment) therefore does not
|
|
110
|
-
// accumulate near-identical premises. No-op for update mode, when no embedding
|
|
111
|
-
// is available, or when the adapter does not implement findSimilarActivePremise.
|
|
112
|
-
// ─────────────────────────────────────────────────────────
|
|
113
|
-
const dedupeNode = async (state) => {
|
|
114
|
-
return timed("PremiseGraph.dedupe", async () => {
|
|
115
|
-
if (state.error)
|
|
116
|
-
return {};
|
|
117
|
-
if (state.operationMode === 'update')
|
|
118
|
-
return {};
|
|
119
|
-
if (!state.embedding || state.embedding.length === 0)
|
|
120
|
-
return {};
|
|
121
|
-
if (typeof this.database.findSimilarActivePremise !== 'function')
|
|
122
|
-
return {};
|
|
123
|
-
const match = await this.database.findSimilarActivePremise({
|
|
124
|
-
userId: state.userId,
|
|
125
|
-
embedding: state.embedding,
|
|
126
|
-
threshold: DEDUP_SIMILARITY_THRESHOLD,
|
|
127
|
-
});
|
|
128
|
-
if (match) {
|
|
129
|
-
dedupeLog.verbose('Skipping near-duplicate premise', {
|
|
130
|
-
similarity: Number(match.similarity.toFixed(3)),
|
|
131
|
-
threshold: DEDUP_SIMILARITY_THRESHOLD,
|
|
132
|
-
premiseId: match.premiseId,
|
|
133
|
-
});
|
|
134
|
-
return { duplicateOf: match };
|
|
135
|
-
}
|
|
136
|
-
return {};
|
|
137
|
-
});
|
|
138
|
-
};
|
|
139
|
-
const persistNode = async (state) => {
|
|
140
|
-
return timed("PremiseGraph.persist", async () => {
|
|
141
|
-
if (state.error)
|
|
142
|
-
return {};
|
|
143
|
-
if (state.operationMode === 'update' && !state.targetPremiseId) {
|
|
144
|
-
return { error: "targetPremiseId is required for update mode" };
|
|
145
|
-
}
|
|
146
|
-
if (state.operationMode === 'update' && state.targetPremiseId) {
|
|
147
|
-
persistLog.verbose('Updating premise', { premiseId: state.targetPremiseId });
|
|
148
|
-
const updated = await this.database.updatePremise(state.targetPremiseId, {
|
|
149
|
-
assertion: {
|
|
150
|
-
text: state.assertionText,
|
|
151
|
-
tier: state.tier,
|
|
152
|
-
},
|
|
153
|
-
analysis: state.analysis ?? undefined,
|
|
154
|
-
validity: {
|
|
155
|
-
validFrom: state.validFrom,
|
|
156
|
-
validUntil: state.validUntil,
|
|
157
|
-
volatile: state.volatile,
|
|
158
|
-
},
|
|
159
|
-
embedding: state.embedding,
|
|
160
|
-
});
|
|
161
|
-
return { premise: updated };
|
|
162
|
-
}
|
|
163
|
-
persistLog.verbose('Creating new premise for user', { userId: state.userId });
|
|
164
|
-
// Provenance confidence: prefer an explicit caller-supplied value; otherwise
|
|
165
|
-
// derive it from the analyzer's felicity scores (how authoritative, sincere,
|
|
166
|
-
// and clear the assertion is) rather than a blanket 1.0, so the stored
|
|
167
|
-
// provenance reflects per-premise signal quality.
|
|
168
|
-
const derivedConfidence = deriveProvenanceConfidence(state.analysis);
|
|
169
|
-
const premise = await this.database.createPremise({
|
|
170
|
-
userId: state.userId,
|
|
171
|
-
assertion: {
|
|
172
|
-
text: state.assertionText,
|
|
173
|
-
tier: state.tier,
|
|
174
|
-
},
|
|
175
|
-
provenance: {
|
|
176
|
-
source: state.provenanceSource ?? 'explicit',
|
|
177
|
-
sourceId: state.provenanceSourceId,
|
|
178
|
-
confidence: state.provenanceConfidence ?? derivedConfidence,
|
|
179
|
-
timestamp: new Date().toISOString(),
|
|
180
|
-
},
|
|
181
|
-
analysis: state.analysis ?? undefined,
|
|
182
|
-
validity: {
|
|
183
|
-
validFrom: state.validFrom,
|
|
184
|
-
validUntil: state.validUntil,
|
|
185
|
-
volatile: state.volatile,
|
|
186
|
-
},
|
|
187
|
-
embedding: state.embedding,
|
|
188
|
-
});
|
|
189
|
-
return { premise };
|
|
190
|
-
});
|
|
191
|
-
};
|
|
192
|
-
const indexNode = async (state) => {
|
|
193
|
-
return timed("PremiseGraph.index", async () => {
|
|
194
|
-
if (!state.premise)
|
|
195
|
-
return {};
|
|
196
|
-
indexLog.verbose(`Scoring premise against user networks`);
|
|
197
|
-
const assignmentMemberships = await this.database.getAssignmentNetworkMembershipsForUser(state.userId);
|
|
198
|
-
const requestScope = state.scopeType && state.scopeId
|
|
199
|
-
? { scopeType: state.scopeType, scopeId: state.scopeId }
|
|
200
|
-
: scopeFromNetworkId(state.networkScopeId);
|
|
201
|
-
const indexIds = resolveAssignmentNetworkScope({
|
|
202
|
-
memberships: assignmentMemberships,
|
|
203
|
-
...requestScope,
|
|
204
|
-
});
|
|
205
|
-
const scope = requestScope.scopeType ? "network" : "global";
|
|
206
|
-
const assignments = [];
|
|
207
|
-
const agentTimings = [];
|
|
208
|
-
for (const networkId of indexIds) {
|
|
209
|
-
try {
|
|
210
|
-
const assignmentContext = await this.database.getNetworkAssignmentContext(networkId, state.userId);
|
|
211
|
-
if (!assignmentContext)
|
|
212
|
-
continue;
|
|
213
|
-
const indexPrompt = assignmentContext.indexPrompt;
|
|
214
|
-
const memberPrompt = assignmentContext.memberPrompt;
|
|
215
|
-
const hasPrompts = !!indexPrompt?.trim() || !!memberPrompt?.trim();
|
|
216
|
-
let rawScores;
|
|
217
|
-
let reason;
|
|
218
|
-
if (hasPrompts) {
|
|
219
|
-
const start = Date.now();
|
|
220
|
-
const result = await indexer.invoke({
|
|
221
|
-
premiseText: state.assertionText,
|
|
222
|
-
indexPrompt: indexPrompt ?? "",
|
|
223
|
-
memberPrompt: memberPrompt ?? undefined,
|
|
224
|
-
});
|
|
225
|
-
const timing = {
|
|
226
|
-
name: "premise-indexer",
|
|
227
|
-
durationMs: Date.now() - start,
|
|
228
|
-
};
|
|
229
|
-
rawScores = { indexScore: result.indexScore, memberScore: result.memberScore };
|
|
230
|
-
reason = result.reasoning;
|
|
231
|
-
agentTimings.push(timing);
|
|
232
|
-
}
|
|
233
|
-
const decision = buildNetworkAssignmentDecision({
|
|
234
|
-
resourceType: "premise",
|
|
235
|
-
mode: "automatic",
|
|
236
|
-
scope,
|
|
237
|
-
indexPrompt,
|
|
238
|
-
memberPrompt,
|
|
239
|
-
rawScores,
|
|
240
|
-
evaluator: "premise-indexer",
|
|
241
|
-
source: "premise-graph",
|
|
242
|
-
reason,
|
|
243
|
-
createdAt: new Date().toISOString(),
|
|
244
|
-
});
|
|
245
|
-
if (decision.assigned) {
|
|
246
|
-
await this.database.assignPremiseToNetwork(state.premise.id, networkId, decision.finalScore, decision.metadata);
|
|
247
|
-
assignments.push({ networkId, relevancyScore: decision.finalScore });
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
catch (err) {
|
|
251
|
-
indexLog.verbose('Failed to score network, skipping', { networkId, error: err });
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
indexLog.verbose('Assigned to networks', { count: assignments.length });
|
|
255
|
-
return { networkAssignments: assignments, agentTimings };
|
|
256
|
-
});
|
|
257
|
-
};
|
|
258
|
-
const routeByMode = (state) => {
|
|
259
|
-
if (state.error)
|
|
260
|
-
return "end";
|
|
261
|
-
if (state.operationMode === 'query')
|
|
262
|
-
return "query";
|
|
263
|
-
return "analyze";
|
|
264
|
-
};
|
|
54
|
+
const deps = this.deps;
|
|
265
55
|
const graph = new StateGraph(PremiseGraphState)
|
|
266
|
-
.addNode("query", queryNode)
|
|
267
|
-
.addNode("analyze", analyzeNode)
|
|
268
|
-
.addNode("embed", embedNode)
|
|
269
|
-
.addNode("dedupe", dedupeNode)
|
|
270
|
-
.addNode("persist", persistNode)
|
|
271
|
-
.addNode("index", indexNode)
|
|
56
|
+
.addNode("query", (state) => queryNode(state, deps))
|
|
57
|
+
.addNode("analyze", (state) => analyzeNode(state, deps))
|
|
58
|
+
.addNode("embed", (state) => embedNode(state, deps))
|
|
59
|
+
.addNode("dedupe", (state) => dedupeNode(state, deps))
|
|
60
|
+
.addNode("persist", (state) => persistNode(state, deps))
|
|
61
|
+
.addNode("index", (state) => indexNode(state, deps))
|
|
272
62
|
.addConditionalEdges(START, routeByMode, {
|
|
273
63
|
query: "query",
|
|
274
64
|
analyze: "analyze",
|
|
@@ -287,3 +77,202 @@ export class PremiseGraphFactory {
|
|
|
287
77
|
return graph.compile();
|
|
288
78
|
}
|
|
289
79
|
}
|
|
80
|
+
export async function queryNode(state, deps) {
|
|
81
|
+
return timed("PremiseGraph.query", async () => {
|
|
82
|
+
queryLog.verbose('Fetching premises for user', { userId: state.userId });
|
|
83
|
+
const premises = await deps.database.getPremisesForUser(state.userId, 'ACTIVE');
|
|
84
|
+
return {
|
|
85
|
+
readResult: {
|
|
86
|
+
premises,
|
|
87
|
+
count: premises.length,
|
|
88
|
+
},
|
|
89
|
+
};
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
export async function analyzeNode(state, deps) {
|
|
93
|
+
return timed("PremiseGraph.analyze", async () => {
|
|
94
|
+
if (!state.assertionText) {
|
|
95
|
+
return { error: "assertionText is required for create/update mode" };
|
|
96
|
+
}
|
|
97
|
+
analyzeLog.verbose('Analyzing assertion text', { preview: state.assertionText.substring(0, 50) });
|
|
98
|
+
const start = Date.now();
|
|
99
|
+
const result = await deps.premiseAnalyzer.invoke(state.assertionText);
|
|
100
|
+
const timing = {
|
|
101
|
+
name: "premise-analyzer",
|
|
102
|
+
durationMs: Date.now() - start,
|
|
103
|
+
};
|
|
104
|
+
const analysis = {
|
|
105
|
+
speechActType: result.speechActType,
|
|
106
|
+
felicityAuthority: result.felicityAuthority,
|
|
107
|
+
felicitySincerity: result.felicitySincerity,
|
|
108
|
+
felicityClarity: result.felicityClarity,
|
|
109
|
+
semanticEntropy: result.semanticEntropy,
|
|
110
|
+
};
|
|
111
|
+
return { analysis, agentTimings: [timing] };
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
export async function embedNode(state, deps) {
|
|
115
|
+
return timed("PremiseGraph.embed", async () => {
|
|
116
|
+
if (state.error)
|
|
117
|
+
return {};
|
|
118
|
+
if (!state.assertionText) {
|
|
119
|
+
return { error: "assertionText is required for embedding" };
|
|
120
|
+
}
|
|
121
|
+
embedLog.verbose(`Generating embedding for premise`);
|
|
122
|
+
// Embedder.generate returns number[] | number[][], cast for single string input
|
|
123
|
+
const embedding = await deps.embedder.generate(state.assertionText, undefined, getAbortSignalConfig());
|
|
124
|
+
return { embedding };
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
export async function dedupeNode(state, deps) {
|
|
128
|
+
return timed("PremiseGraph.dedupe", async () => {
|
|
129
|
+
if (state.error)
|
|
130
|
+
return {};
|
|
131
|
+
if (state.operationMode === 'update')
|
|
132
|
+
return {};
|
|
133
|
+
if (!state.embedding || state.embedding.length === 0)
|
|
134
|
+
return {};
|
|
135
|
+
if (typeof deps.database.findSimilarActivePremise !== 'function')
|
|
136
|
+
return {};
|
|
137
|
+
const match = await deps.database.findSimilarActivePremise({
|
|
138
|
+
userId: state.userId,
|
|
139
|
+
embedding: state.embedding,
|
|
140
|
+
threshold: DEDUP_SIMILARITY_THRESHOLD,
|
|
141
|
+
});
|
|
142
|
+
if (match) {
|
|
143
|
+
dedupeLog.verbose('Skipping near-duplicate premise', {
|
|
144
|
+
similarity: Number(match.similarity.toFixed(3)),
|
|
145
|
+
threshold: DEDUP_SIMILARITY_THRESHOLD,
|
|
146
|
+
premiseId: match.premiseId,
|
|
147
|
+
});
|
|
148
|
+
return { duplicateOf: match };
|
|
149
|
+
}
|
|
150
|
+
return {};
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
export async function persistNode(state, deps) {
|
|
154
|
+
return timed("PremiseGraph.persist", async () => {
|
|
155
|
+
if (state.error)
|
|
156
|
+
return {};
|
|
157
|
+
if (state.operationMode === 'update' && !state.targetPremiseId) {
|
|
158
|
+
return { error: "targetPremiseId is required for update mode" };
|
|
159
|
+
}
|
|
160
|
+
if (state.operationMode === 'update' && state.targetPremiseId) {
|
|
161
|
+
persistLog.verbose('Updating premise', { premiseId: state.targetPremiseId });
|
|
162
|
+
const updated = await deps.database.updatePremise(state.targetPremiseId, {
|
|
163
|
+
assertion: {
|
|
164
|
+
text: state.assertionText,
|
|
165
|
+
tier: state.tier,
|
|
166
|
+
},
|
|
167
|
+
analysis: state.analysis ?? undefined,
|
|
168
|
+
validity: {
|
|
169
|
+
validFrom: state.validFrom,
|
|
170
|
+
validUntil: state.validUntil,
|
|
171
|
+
volatile: state.volatile,
|
|
172
|
+
},
|
|
173
|
+
embedding: state.embedding,
|
|
174
|
+
});
|
|
175
|
+
return { premise: updated };
|
|
176
|
+
}
|
|
177
|
+
persistLog.verbose('Creating new premise for user', { userId: state.userId });
|
|
178
|
+
// Provenance confidence: prefer an explicit caller-supplied value; otherwise
|
|
179
|
+
// derive it from the deps.premiseAnalyzer's felicity scores (how authoritative, sincere,
|
|
180
|
+
// and clear the assertion is) rather than a blanket 1.0, so the stored
|
|
181
|
+
// provenance reflects per-premise signal quality.
|
|
182
|
+
const derivedConfidence = deriveProvenanceConfidence(state.analysis);
|
|
183
|
+
const premise = await deps.database.createPremise({
|
|
184
|
+
userId: state.userId,
|
|
185
|
+
assertion: {
|
|
186
|
+
text: state.assertionText,
|
|
187
|
+
tier: state.tier,
|
|
188
|
+
},
|
|
189
|
+
provenance: {
|
|
190
|
+
source: state.provenanceSource ?? 'explicit',
|
|
191
|
+
sourceId: state.provenanceSourceId,
|
|
192
|
+
confidence: state.provenanceConfidence ?? derivedConfidence,
|
|
193
|
+
timestamp: new Date().toISOString(),
|
|
194
|
+
},
|
|
195
|
+
analysis: state.analysis ?? undefined,
|
|
196
|
+
validity: {
|
|
197
|
+
validFrom: state.validFrom,
|
|
198
|
+
validUntil: state.validUntil,
|
|
199
|
+
volatile: state.volatile,
|
|
200
|
+
},
|
|
201
|
+
embedding: state.embedding,
|
|
202
|
+
});
|
|
203
|
+
return { premise };
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
export async function indexNode(state, deps) {
|
|
207
|
+
return timed("PremiseGraph.index", async () => {
|
|
208
|
+
if (!state.premise)
|
|
209
|
+
return {};
|
|
210
|
+
indexLog.verbose(`Scoring premise against user networks`);
|
|
211
|
+
const assignmentMemberships = await deps.database.getAssignmentNetworkMembershipsForUser(state.userId);
|
|
212
|
+
const requestScope = state.scopeType && state.scopeId
|
|
213
|
+
? { scopeType: state.scopeType, scopeId: state.scopeId }
|
|
214
|
+
: scopeFromNetworkId(state.networkScopeId);
|
|
215
|
+
const indexIds = resolveAssignmentNetworkScope({
|
|
216
|
+
memberships: assignmentMemberships,
|
|
217
|
+
...requestScope,
|
|
218
|
+
});
|
|
219
|
+
const scope = requestScope.scopeType ? "network" : "global";
|
|
220
|
+
const assignments = [];
|
|
221
|
+
const agentTimings = [];
|
|
222
|
+
for (const networkId of indexIds) {
|
|
223
|
+
try {
|
|
224
|
+
const assignmentContext = await deps.database.getNetworkAssignmentContext(networkId, state.userId);
|
|
225
|
+
if (!assignmentContext)
|
|
226
|
+
continue;
|
|
227
|
+
const indexPrompt = assignmentContext.indexPrompt;
|
|
228
|
+
const memberPrompt = assignmentContext.memberPrompt;
|
|
229
|
+
const hasPrompts = !!indexPrompt?.trim() || !!memberPrompt?.trim();
|
|
230
|
+
let rawScores;
|
|
231
|
+
let reason;
|
|
232
|
+
if (hasPrompts) {
|
|
233
|
+
const start = Date.now();
|
|
234
|
+
const result = await deps.premiseIndexer.invoke({
|
|
235
|
+
premiseText: state.assertionText,
|
|
236
|
+
indexPrompt: indexPrompt ?? "",
|
|
237
|
+
memberPrompt: memberPrompt ?? undefined,
|
|
238
|
+
});
|
|
239
|
+
const timing = {
|
|
240
|
+
name: "premise-indexer",
|
|
241
|
+
durationMs: Date.now() - start,
|
|
242
|
+
};
|
|
243
|
+
rawScores = { indexScore: result.indexScore, memberScore: result.memberScore };
|
|
244
|
+
reason = result.reasoning;
|
|
245
|
+
agentTimings.push(timing);
|
|
246
|
+
}
|
|
247
|
+
const decision = buildNetworkAssignmentDecision({
|
|
248
|
+
resourceType: "premise",
|
|
249
|
+
mode: "automatic",
|
|
250
|
+
scope,
|
|
251
|
+
indexPrompt,
|
|
252
|
+
memberPrompt,
|
|
253
|
+
rawScores,
|
|
254
|
+
evaluator: "premise-indexer",
|
|
255
|
+
source: "premise-graph",
|
|
256
|
+
reason,
|
|
257
|
+
createdAt: new Date().toISOString(),
|
|
258
|
+
});
|
|
259
|
+
if (decision.assigned) {
|
|
260
|
+
await deps.database.assignPremiseToNetwork(state.premise.id, networkId, decision.finalScore, decision.metadata);
|
|
261
|
+
assignments.push({ networkId, relevancyScore: decision.finalScore });
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
catch (err) {
|
|
265
|
+
indexLog.verbose('Failed to score network, skipping', { networkId, error: err });
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
indexLog.verbose('Assigned to networks', { count: assignments.length });
|
|
269
|
+
return { networkAssignments: assignments, agentTimings };
|
|
270
|
+
});
|
|
271
|
+
}
|
|
272
|
+
export function routeByMode(state) {
|
|
273
|
+
if (state.error)
|
|
274
|
+
return "end";
|
|
275
|
+
if (state.operationMode === 'query')
|
|
276
|
+
return "query";
|
|
277
|
+
return "analyze";
|
|
278
|
+
}
|