agent-orcha 0.0.2 → 0.0.4
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/README.md +777 -100
- package/dist/lib/agents/agent-executor.d.ts +6 -1
- package/dist/lib/agents/agent-executor.d.ts.map +1 -1
- package/dist/lib/agents/agent-executor.js +241 -45
- package/dist/lib/agents/agent-executor.js.map +1 -1
- package/dist/lib/agents/agent-loader.d.ts.map +1 -1
- package/dist/lib/agents/agent-loader.js +3 -1
- package/dist/lib/agents/agent-loader.js.map +1 -1
- package/dist/lib/agents/index.d.ts +2 -1
- package/dist/lib/agents/index.d.ts.map +1 -1
- package/dist/lib/agents/index.js +1 -0
- package/dist/lib/agents/index.js.map +1 -1
- package/dist/lib/agents/structured-output-wrapper.d.ts +19 -0
- package/dist/lib/agents/structured-output-wrapper.d.ts.map +1 -0
- package/dist/lib/agents/structured-output-wrapper.js +104 -0
- package/dist/lib/agents/structured-output-wrapper.js.map +1 -0
- package/dist/lib/agents/types.d.ts +17 -10
- package/dist/lib/agents/types.d.ts.map +1 -1
- package/dist/lib/agents/types.js +1 -1
- package/dist/lib/agents/types.js.map +1 -1
- package/dist/lib/index.d.ts +9 -7
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +7 -5
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/knowledge/graph-rag/community-detector.d.ts +16 -0
- package/dist/lib/knowledge/graph-rag/community-detector.d.ts.map +1 -0
- package/dist/lib/knowledge/graph-rag/community-detector.js +81 -0
- package/dist/lib/knowledge/graph-rag/community-detector.js.map +1 -0
- package/dist/lib/knowledge/graph-rag/community-summarizer.d.ts +17 -0
- package/dist/lib/knowledge/graph-rag/community-summarizer.d.ts.map +1 -0
- package/dist/lib/knowledge/graph-rag/community-summarizer.js +87 -0
- package/dist/lib/knowledge/graph-rag/community-summarizer.js.map +1 -0
- package/dist/lib/knowledge/graph-rag/entity-extractor.d.ts +36 -0
- package/dist/lib/knowledge/graph-rag/entity-extractor.d.ts.map +1 -0
- package/dist/lib/knowledge/graph-rag/entity-extractor.js +192 -0
- package/dist/lib/knowledge/graph-rag/entity-extractor.js.map +1 -0
- package/dist/lib/knowledge/graph-rag/extraction-cache.d.ts +30 -0
- package/dist/lib/knowledge/graph-rag/extraction-cache.d.ts.map +1 -0
- package/dist/lib/knowledge/graph-rag/extraction-cache.js +88 -0
- package/dist/lib/knowledge/graph-rag/extraction-cache.js.map +1 -0
- package/dist/lib/knowledge/graph-rag/global-search.d.ts +19 -0
- package/dist/lib/knowledge/graph-rag/global-search.d.ts.map +1 -0
- package/dist/lib/knowledge/graph-rag/global-search.js +96 -0
- package/dist/lib/knowledge/graph-rag/global-search.js.map +1 -0
- package/dist/lib/knowledge/graph-rag/graph-rag-factory.d.ts +24 -0
- package/dist/lib/knowledge/graph-rag/graph-rag-factory.d.ts.map +1 -0
- package/dist/lib/knowledge/graph-rag/graph-rag-factory.js +239 -0
- package/dist/lib/knowledge/graph-rag/graph-rag-factory.js.map +1 -0
- package/dist/lib/knowledge/graph-rag/index.d.ts +14 -0
- package/dist/lib/knowledge/graph-rag/index.d.ts.map +1 -0
- package/dist/lib/knowledge/graph-rag/index.js +12 -0
- package/dist/lib/knowledge/graph-rag/index.js.map +1 -0
- package/dist/lib/knowledge/graph-rag/local-search.d.ts +20 -0
- package/dist/lib/knowledge/graph-rag/local-search.d.ts.map +1 -0
- package/dist/lib/knowledge/graph-rag/local-search.js +110 -0
- package/dist/lib/knowledge/graph-rag/local-search.js.map +1 -0
- package/dist/lib/knowledge/graph-rag/memory-graph-store.d.ts +31 -0
- package/dist/lib/knowledge/graph-rag/memory-graph-store.d.ts.map +1 -0
- package/dist/lib/knowledge/graph-rag/memory-graph-store.js +165 -0
- package/dist/lib/knowledge/graph-rag/memory-graph-store.js.map +1 -0
- package/dist/lib/knowledge/graph-rag/neo4j-graph-store.d.ts +38 -0
- package/dist/lib/knowledge/graph-rag/neo4j-graph-store.d.ts.map +1 -0
- package/dist/lib/knowledge/graph-rag/neo4j-graph-store.js +190 -0
- package/dist/lib/knowledge/graph-rag/neo4j-graph-store.js.map +1 -0
- package/dist/lib/knowledge/graph-rag/search-mode-detector.d.ts +11 -0
- package/dist/lib/knowledge/graph-rag/search-mode-detector.d.ts.map +1 -0
- package/dist/lib/knowledge/graph-rag/search-mode-detector.js +50 -0
- package/dist/lib/knowledge/graph-rag/search-mode-detector.js.map +1 -0
- package/dist/lib/knowledge/graph-rag/types.d.ts +368 -0
- package/dist/lib/knowledge/graph-rag/types.d.ts.map +1 -0
- package/dist/lib/knowledge/graph-rag/types.js +48 -0
- package/dist/lib/knowledge/graph-rag/types.js.map +1 -0
- package/dist/lib/knowledge/index.d.ts +9 -0
- package/dist/lib/knowledge/index.d.ts.map +1 -0
- package/dist/lib/knowledge/index.js +8 -0
- package/dist/lib/knowledge/index.js.map +1 -0
- package/dist/lib/knowledge/knowledge-store-factory.d.ts +16 -0
- package/dist/lib/knowledge/knowledge-store-factory.d.ts.map +1 -0
- package/dist/lib/{vectors/vector-store-factory.js → knowledge/knowledge-store-factory.js} +36 -10
- package/dist/lib/knowledge/knowledge-store-factory.js.map +1 -0
- package/dist/lib/knowledge/knowledge-store-manager.d.ts +18 -0
- package/dist/lib/knowledge/knowledge-store-manager.d.ts.map +1 -0
- package/dist/lib/knowledge/knowledge-store-manager.js +98 -0
- package/dist/lib/knowledge/knowledge-store-manager.js.map +1 -0
- package/dist/lib/knowledge/loaders/database-loader.d.ts +18 -0
- package/dist/lib/knowledge/loaders/database-loader.d.ts.map +1 -0
- package/dist/lib/knowledge/loaders/database-loader.js +115 -0
- package/dist/lib/knowledge/loaders/database-loader.js.map +1 -0
- package/dist/lib/knowledge/loaders/index.d.ts +4 -0
- package/dist/lib/knowledge/loaders/index.d.ts.map +1 -0
- package/dist/lib/knowledge/loaders/index.js +4 -0
- package/dist/lib/knowledge/loaders/index.js.map +1 -0
- package/dist/lib/knowledge/loaders/s3-loader.d.ts +17 -0
- package/dist/lib/knowledge/loaders/s3-loader.d.ts.map +1 -0
- package/dist/lib/knowledge/loaders/s3-loader.js +185 -0
- package/dist/lib/knowledge/loaders/s3-loader.js.map +1 -0
- package/dist/lib/knowledge/loaders/web-loader.d.ts +12 -0
- package/dist/lib/knowledge/loaders/web-loader.d.ts.map +1 -0
- package/dist/lib/knowledge/loaders/web-loader.js +56 -0
- package/dist/lib/knowledge/loaders/web-loader.js.map +1 -0
- package/dist/lib/knowledge/types.d.ts +1839 -0
- package/dist/lib/knowledge/types.d.ts.map +1 -0
- package/dist/lib/knowledge/types.js +111 -0
- package/dist/lib/knowledge/types.js.map +1 -0
- package/dist/lib/knowledge/utils/connection-pool.d.ts +18 -0
- package/dist/lib/knowledge/utils/connection-pool.d.ts.map +1 -0
- package/dist/lib/knowledge/utils/connection-pool.js +77 -0
- package/dist/lib/knowledge/utils/connection-pool.js.map +1 -0
- package/dist/lib/knowledge/utils/file-type-detector.d.ts +10 -0
- package/dist/lib/knowledge/utils/file-type-detector.d.ts.map +1 -0
- package/dist/lib/knowledge/utils/file-type-detector.js +32 -0
- package/dist/lib/knowledge/utils/file-type-detector.js.map +1 -0
- package/dist/lib/knowledge/utils/index.d.ts +3 -0
- package/dist/lib/knowledge/utils/index.d.ts.map +1 -0
- package/dist/lib/knowledge/utils/index.js +3 -0
- package/dist/lib/knowledge/utils/index.js.map +1 -0
- package/dist/lib/mcp/mcp-client.d.ts +9 -1
- package/dist/lib/mcp/mcp-client.d.ts.map +1 -1
- package/dist/lib/mcp/mcp-client.js +33 -0
- package/dist/lib/mcp/mcp-client.js.map +1 -1
- package/dist/lib/memory/conversation-store.d.ts +43 -0
- package/dist/lib/memory/conversation-store.d.ts.map +1 -0
- package/dist/lib/memory/conversation-store.js +109 -0
- package/dist/lib/memory/conversation-store.js.map +1 -0
- package/dist/lib/memory/index.d.ts +3 -0
- package/dist/lib/memory/index.d.ts.map +1 -0
- package/dist/lib/memory/index.js +3 -0
- package/dist/lib/memory/index.js.map +1 -0
- package/dist/lib/memory/types.d.ts +19 -0
- package/dist/lib/memory/types.d.ts.map +1 -0
- package/dist/lib/memory/types.js +6 -0
- package/dist/lib/memory/types.js.map +1 -0
- package/dist/lib/orchestrator.d.ts +56 -14
- package/dist/lib/orchestrator.d.ts.map +1 -1
- package/dist/lib/orchestrator.js +182 -25
- package/dist/lib/orchestrator.js.map +1 -1
- package/dist/lib/tools/agent-tool-wrapper.d.ts +22 -0
- package/dist/lib/tools/agent-tool-wrapper.d.ts.map +1 -0
- package/dist/lib/tools/agent-tool-wrapper.js +56 -0
- package/dist/lib/tools/agent-tool-wrapper.js.map +1 -0
- package/dist/lib/tools/built-in/ask-user.tool.d.ts +7 -0
- package/dist/lib/tools/built-in/ask-user.tool.d.ts.map +1 -0
- package/dist/lib/tools/built-in/ask-user.tool.js +23 -0
- package/dist/lib/tools/built-in/ask-user.tool.js.map +1 -0
- package/dist/lib/tools/built-in/index.d.ts +2 -1
- package/dist/lib/tools/built-in/index.d.ts.map +1 -1
- package/dist/lib/tools/built-in/index.js +2 -1
- package/dist/lib/tools/built-in/index.js.map +1 -1
- package/dist/lib/tools/built-in/knowledge-search.tool.d.ts +4 -0
- package/dist/lib/tools/built-in/knowledge-search.tool.d.ts.map +1 -0
- package/dist/lib/tools/built-in/{vector-search.tool.js → knowledge-search.tool.js} +4 -4
- package/dist/lib/tools/built-in/knowledge-search.tool.js.map +1 -0
- package/dist/lib/tools/index.d.ts +3 -1
- package/dist/lib/tools/index.d.ts.map +1 -1
- package/dist/lib/tools/index.js +3 -1
- package/dist/lib/tools/index.js.map +1 -1
- package/dist/lib/tools/tool-discovery.d.ts +50 -0
- package/dist/lib/tools/tool-discovery.d.ts.map +1 -0
- package/dist/lib/tools/tool-discovery.js +178 -0
- package/dist/lib/tools/tool-discovery.js.map +1 -0
- package/dist/lib/tools/tool-registry.d.ts +19 -3
- package/dist/lib/tools/tool-registry.d.ts.map +1 -1
- package/dist/lib/tools/tool-registry.js +63 -10
- package/dist/lib/tools/tool-registry.js.map +1 -1
- package/dist/lib/workflows/index.d.ts +4 -2
- package/dist/lib/workflows/index.d.ts.map +1 -1
- package/dist/lib/workflows/index.js +3 -1
- package/dist/lib/workflows/index.js.map +1 -1
- package/dist/lib/workflows/interrupt-manager.d.ts +42 -0
- package/dist/lib/workflows/interrupt-manager.d.ts.map +1 -0
- package/dist/lib/workflows/interrupt-manager.js +102 -0
- package/dist/lib/workflows/interrupt-manager.js.map +1 -0
- package/dist/lib/workflows/langgraph-executor.d.ts +51 -0
- package/dist/lib/workflows/langgraph-executor.d.ts.map +1 -0
- package/dist/lib/workflows/langgraph-executor.js +297 -0
- package/dist/lib/workflows/langgraph-executor.js.map +1 -0
- package/dist/lib/workflows/types.d.ts +911 -34
- package/dist/lib/workflows/types.d.ts.map +1 -1
- package/dist/lib/workflows/types.js +51 -2
- package/dist/lib/workflows/types.js.map +1 -1
- package/dist/lib/workflows/workflow-executor.d.ts.map +1 -1
- package/dist/lib/workflows/workflow-executor.js +4 -0
- package/dist/lib/workflows/workflow-executor.js.map +1 -1
- package/dist/lib/workflows/workflow-loader.d.ts.map +1 -1
- package/dist/lib/workflows/workflow-loader.js +3 -1
- package/dist/lib/workflows/workflow-loader.js.map +1 -1
- package/dist/public/index.html +133 -700
- package/dist/public/src/components/AgentsView.js +763 -0
- package/dist/public/src/components/AppRoot.js +76 -0
- package/dist/public/src/components/IdeView.js +330 -0
- package/dist/public/src/components/KnowledgeView.js +133 -0
- package/dist/public/src/components/LlmView.js +127 -0
- package/dist/public/src/components/McpView.js +387 -0
- package/dist/public/src/components/NavBar.js +71 -0
- package/dist/public/src/components/WorkflowsView.js +243 -0
- package/dist/public/src/main.js +9 -0
- package/dist/public/src/services/ApiService.js +142 -0
- package/dist/public/src/store.js +41 -0
- package/dist/public/src/utils/Component.js +23 -0
- package/dist/public/src/utils/markdown.js +82 -0
- package/dist/src/cli/commands/init.js +3 -3
- package/dist/src/cli/commands/init.js.map +1 -1
- package/dist/src/cli/commands/start.d.ts.map +1 -1
- package/dist/src/cli/commands/start.js +3 -2
- package/dist/src/cli/commands/start.js.map +1 -1
- package/dist/src/index.js +46 -12
- package/dist/src/index.js.map +1 -1
- package/dist/src/routes/agents.route.d.ts.map +1 -1
- package/dist/src/routes/agents.route.js +38 -5
- package/dist/src/routes/agents.route.js.map +1 -1
- package/dist/src/routes/files.route.d.ts +3 -0
- package/dist/src/routes/files.route.d.ts.map +1 -0
- package/dist/src/routes/files.route.js +160 -0
- package/dist/src/routes/files.route.js.map +1 -0
- package/dist/src/routes/functions.route.d.ts +3 -0
- package/dist/src/routes/functions.route.d.ts.map +1 -0
- package/dist/src/routes/functions.route.js +83 -0
- package/dist/src/routes/functions.route.js.map +1 -0
- package/dist/src/routes/knowledge.route.d.ts +3 -0
- package/dist/src/routes/knowledge.route.d.ts.map +1 -0
- package/dist/src/routes/knowledge.route.js +153 -0
- package/dist/src/routes/knowledge.route.js.map +1 -0
- package/dist/src/routes/mcp.route.d.ts +3 -0
- package/dist/src/routes/mcp.route.d.ts.map +1 -0
- package/dist/src/routes/mcp.route.js +79 -0
- package/dist/src/routes/mcp.route.js.map +1 -0
- package/dist/src/routes/workflows.route.d.ts.map +1 -1
- package/dist/src/routes/workflows.route.js +2 -1
- package/dist/src/routes/workflows.route.js.map +1 -1
- package/dist/src/server.d.ts.map +1 -1
- package/dist/src/server.js +8 -2
- package/dist/src/server.js.map +1 -1
- package/dist/templates/.env.example +21 -0
- package/dist/templates/README.md +43 -152
- package/dist/templates/agents/call-center-analyst-simple.agent.yaml +36 -0
- package/dist/templates/agents/math.agent.yaml +4 -14
- package/dist/templates/agents/sentiment-structured.agent.yaml +42 -0
- package/dist/templates/functions/calculator.function.js +69 -0
- package/dist/templates/functions/text-formatter.function.js +66 -0
- package/dist/templates/{vectors/example.vector.yaml → knowledge/example.knowledge.yaml} +1 -1
- package/dist/templates/knowledge/transcripts/call-001.txt +40 -0
- package/dist/templates/knowledge/transcripts/call-002.txt +36 -0
- package/dist/templates/knowledge/transcripts/call-003.txt +42 -0
- package/dist/templates/llm.md +1195 -0
- package/dist/templates/workflows/example.workflow.yaml +8 -19
- package/dist/templates/workflows/langgraph-example.workflow.yaml +84 -0
- package/package.json +21 -12
- package/dist/lib/tools/built-in/vector-search.tool.d.ts +0 -4
- package/dist/lib/tools/built-in/vector-search.tool.d.ts.map +0 -1
- package/dist/lib/tools/built-in/vector-search.tool.js.map +0 -1
- package/dist/lib/vectors/index.d.ts +0 -5
- package/dist/lib/vectors/index.d.ts.map +0 -1
- package/dist/lib/vectors/index.js +0 -4
- package/dist/lib/vectors/index.js.map +0 -1
- package/dist/lib/vectors/types.d.ts +0 -212
- package/dist/lib/vectors/types.d.ts.map +0 -1
- package/dist/lib/vectors/types.js +0 -39
- package/dist/lib/vectors/types.js.map +0 -1
- package/dist/lib/vectors/vector-store-factory.d.ts +0 -14
- package/dist/lib/vectors/vector-store-factory.d.ts.map +0 -1
- package/dist/lib/vectors/vector-store-factory.js.map +0 -1
- package/dist/lib/vectors/vector-store-manager.d.ts +0 -18
- package/dist/lib/vectors/vector-store-manager.d.ts.map +0 -1
- package/dist/lib/vectors/vector-store-manager.js +0 -79
- package/dist/lib/vectors/vector-store-manager.js.map +0 -1
- package/dist/src/routes/vectors.route.d.ts +0 -3
- package/dist/src/routes/vectors.route.d.ts.map +0 -1
- package/dist/src/routes/vectors.route.js +0 -74
- package/dist/src/routes/vectors.route.js.map +0 -1
- package/dist/templates/agents/example.agent.yaml +0 -32
- package/dist/templates/agents/knowledge.agent.yaml +0 -36
- package/dist/templates/agents/time.agent.yaml +0 -42
- package/dist/templates/functions/README.md +0 -195
- package/dist/templates/functions/fibonacci.function.js +0 -55
- package/dist/templates/vectors/sample-data/example-document.txt +0 -15
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
export declare const ToolReferenceSchema: z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
3
3
|
name: z.ZodString;
|
|
4
|
-
source: z.ZodEnum<["mcp", "
|
|
4
|
+
source: z.ZodEnum<["mcp", "knowledge", "builtin", "custom"]>;
|
|
5
5
|
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
6
6
|
}, "strip", z.ZodTypeAny, {
|
|
7
7
|
name: string;
|
|
8
|
-
source: "custom" | "mcp" | "
|
|
8
|
+
source: "custom" | "mcp" | "knowledge" | "builtin";
|
|
9
9
|
config?: Record<string, unknown> | undefined;
|
|
10
10
|
}, {
|
|
11
11
|
name: string;
|
|
12
|
-
source: "custom" | "mcp" | "
|
|
12
|
+
source: "custom" | "mcp" | "knowledge" | "builtin";
|
|
13
13
|
config?: Record<string, unknown> | undefined;
|
|
14
14
|
}>]>;
|
|
15
15
|
export declare const OutputConfigSchema: z.ZodObject<{
|
|
@@ -48,15 +48,15 @@ export declare const AgentDefinitionSchema: z.ZodObject<{
|
|
|
48
48
|
}>;
|
|
49
49
|
tools: z.ZodDefault<z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodObject<{
|
|
50
50
|
name: z.ZodString;
|
|
51
|
-
source: z.ZodEnum<["mcp", "
|
|
51
|
+
source: z.ZodEnum<["mcp", "knowledge", "builtin", "custom"]>;
|
|
52
52
|
config: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
|
|
53
53
|
}, "strip", z.ZodTypeAny, {
|
|
54
54
|
name: string;
|
|
55
|
-
source: "custom" | "mcp" | "
|
|
55
|
+
source: "custom" | "mcp" | "knowledge" | "builtin";
|
|
56
56
|
config?: Record<string, unknown> | undefined;
|
|
57
57
|
}, {
|
|
58
58
|
name: string;
|
|
59
|
-
source: "custom" | "mcp" | "
|
|
59
|
+
source: "custom" | "mcp" | "knowledge" | "builtin";
|
|
60
60
|
config?: Record<string, unknown> | undefined;
|
|
61
61
|
}>]>, "many">>;
|
|
62
62
|
output: z.ZodOptional<z.ZodObject<{
|
|
@@ -84,7 +84,7 @@ export declare const AgentDefinitionSchema: z.ZodObject<{
|
|
|
84
84
|
};
|
|
85
85
|
tools: (string | {
|
|
86
86
|
name: string;
|
|
87
|
-
source: "custom" | "mcp" | "
|
|
87
|
+
source: "custom" | "mcp" | "knowledge" | "builtin";
|
|
88
88
|
config?: Record<string, unknown> | undefined;
|
|
89
89
|
})[];
|
|
90
90
|
output?: {
|
|
@@ -106,7 +106,7 @@ export declare const AgentDefinitionSchema: z.ZodObject<{
|
|
|
106
106
|
} | undefined;
|
|
107
107
|
tools?: (string | {
|
|
108
108
|
name: string;
|
|
109
|
-
source: "custom" | "mcp" | "
|
|
109
|
+
source: "custom" | "mcp" | "knowledge" | "builtin";
|
|
110
110
|
config?: Record<string, unknown> | undefined;
|
|
111
111
|
})[] | undefined;
|
|
112
112
|
output?: {
|
|
@@ -130,11 +130,18 @@ export interface AgentResult {
|
|
|
130
130
|
tokensUsed?: number;
|
|
131
131
|
toolCalls?: ToolCallRecord[];
|
|
132
132
|
duration: number;
|
|
133
|
+
sessionId?: string;
|
|
134
|
+
messagesInSession?: number;
|
|
135
|
+
structuredOutputValid?: boolean;
|
|
133
136
|
};
|
|
134
137
|
}
|
|
138
|
+
export interface AgentInvokeOptions {
|
|
139
|
+
input: Record<string, unknown>;
|
|
140
|
+
sessionId?: string;
|
|
141
|
+
}
|
|
135
142
|
export interface AgentInstance {
|
|
136
143
|
definition: AgentDefinition;
|
|
137
|
-
invoke: (input: Record<string, unknown>) => Promise<AgentResult>;
|
|
138
|
-
stream: (input: Record<string, unknown>) => AsyncGenerator<string, void, unknown>;
|
|
144
|
+
invoke: (input: Record<string, unknown> | AgentInvokeOptions) => Promise<AgentResult>;
|
|
145
|
+
stream: (input: Record<string, unknown> | AgentInvokeOptions) => AsyncGenerator<string | Record<string, unknown>, void, unknown>;
|
|
139
146
|
}
|
|
140
147
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../lib/agents/types.ts"],"names":[],"mappings":"AAAA,OAAO,E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AAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC;CAClI"}
|
package/dist/lib/agents/types.js
CHANGED
|
@@ -4,7 +4,7 @@ export const ToolReferenceSchema = z.union([
|
|
|
4
4
|
z.string(),
|
|
5
5
|
z.object({
|
|
6
6
|
name: z.string(),
|
|
7
|
-
source: z.enum(['mcp', '
|
|
7
|
+
source: z.enum(['mcp', 'knowledge', 'builtin', 'custom']),
|
|
8
8
|
config: z.record(z.unknown()).optional(),
|
|
9
9
|
}),
|
|
10
10
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../lib/agents/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC;IACzC,CAAC,CAAC,MAAM,EAAE;IACV,CAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../lib/agents/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAC;AAEpD,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC;IACzC,CAAC,CAAC,MAAM,EAAE;IACV,CAAC,CAAC,MAAM,CAAC;QACP,IAAI,EAAE,CAAC,CAAC,MAAM,EAAE;QAChB,MAAM,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,CAAC,CAAC;QACzD,MA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package/dist/lib/index.d.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
export { Orchestrator } from './orchestrator.js';
|
|
2
2
|
export type { OrchestratorConfig } from './orchestrator.js';
|
|
3
|
-
export { AgentLoader, AgentExecutor } from './agents/index.js';
|
|
4
|
-
export type { AgentDefinition, AgentInstance, AgentResult, ToolReference, OutputConfig, ToolCallRecord, } from './agents/index.js';
|
|
5
|
-
export { WorkflowLoader, WorkflowExecutor } from './workflows/index.js';
|
|
6
|
-
export type { WorkflowDefinition, WorkflowStep, WorkflowResult, WorkflowContext, StepResult, InputMapping, ParallelSteps, } from './workflows/index.js';
|
|
7
|
-
export {
|
|
8
|
-
export type {
|
|
3
|
+
export { AgentLoader, AgentExecutor, StructuredOutputWrapper } from './agents/index.js';
|
|
4
|
+
export type { AgentDefinition, AgentInstance, AgentResult, AgentInvokeOptions, ToolReference, OutputConfig, ToolCallRecord, } from './agents/index.js';
|
|
5
|
+
export { WorkflowLoader, WorkflowExecutor, LangGraphExecutor, InterruptManager, } from './workflows/index.js';
|
|
6
|
+
export type { WorkflowDefinition, WorkflowStep, WorkflowResult, WorkflowContext, StepResult, InputMapping, ParallelSteps, LangGraphWorkflowDefinition, StepBasedWorkflowDefinition, GraphToolConfig, GraphAgentConfig, GraphConfig, WorkflowInterrupt, InterruptState, } from './workflows/index.js';
|
|
7
|
+
export { KnowledgeStoreFactory, KnowledgeStoreManager, GraphRagFactory } from './knowledge/index.js';
|
|
8
|
+
export type { KnowledgeConfig, VectorKnowledgeConfig, GraphRagKnowledgeConfig, KnowledgeStoreInstance, SearchResult, DocumentInput, GraphNode, GraphEdge, Community, GraphStore, GraphConfig as GraphRagGraphConfig, GraphSearchConfig, } from './knowledge/index.js';
|
|
9
9
|
export { LLMFactory } from './llm/index.js';
|
|
10
10
|
export type { ModelConfig, AgentLLMRef } from './llm/index.js';
|
|
11
11
|
export { MCPClientManager } from './mcp/index.js';
|
|
12
12
|
export type { MCPConfig, MCPServerConfig } from './mcp/index.js';
|
|
13
|
-
export { ToolRegistry,
|
|
13
|
+
export { ToolRegistry, ToolDiscovery, AgentToolWrapper, createKnowledgeSearchTool, createAskUserTool, } from './tools/index.js';
|
|
14
14
|
export { FunctionLoader } from './functions/index.js';
|
|
15
15
|
export type { FunctionMetadata, LoadedFunction } from './functions/index.js';
|
|
16
|
+
export { ConversationStore } from './memory/index.js';
|
|
17
|
+
export type { ConversationStoreConfig, ConversationSession } from './memory/index.js';
|
|
16
18
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAG5D,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,YAAY,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAG5D,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AACxF,YAAY,EACV,eAAe,EACf,aAAa,EACb,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,YAAY,EACZ,cAAc,GACf,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAC9B,YAAY,EACV,kBAAkB,EAClB,YAAY,EACZ,cAAc,EACd,eAAe,EACf,UAAU,EACV,YAAY,EACZ,aAAa,EACb,2BAA2B,EAC3B,2BAA2B,EAC3B,eAAe,EACf,gBAAgB,EAChB,WAAW,EACX,iBAAiB,EACjB,cAAc,GACf,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACrG,YAAY,EACV,eAAe,EACf,qBAAqB,EACrB,uBAAuB,EACvB,sBAAsB,EACtB,YAAY,EACZ,aAAa,EACb,SAAS,EACT,SAAS,EACT,SAAS,EACT,UAAU,EACV,WAAW,IAAI,mBAAmB,EAClC,iBAAiB,GAClB,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAG/D,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,YAAY,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAGjE,OAAO,EACL,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,yBAAyB,EACzB,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAG7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AACtD,YAAY,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAC"}
|
package/dist/lib/index.js
CHANGED
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
// Main orchestrator
|
|
2
2
|
export { Orchestrator } from './orchestrator.js';
|
|
3
3
|
// Agents
|
|
4
|
-
export { AgentLoader, AgentExecutor } from './agents/index.js';
|
|
4
|
+
export { AgentLoader, AgentExecutor, StructuredOutputWrapper } from './agents/index.js';
|
|
5
5
|
// Workflows
|
|
6
|
-
export { WorkflowLoader, WorkflowExecutor } from './workflows/index.js';
|
|
7
|
-
//
|
|
8
|
-
export {
|
|
6
|
+
export { WorkflowLoader, WorkflowExecutor, LangGraphExecutor, InterruptManager, } from './workflows/index.js';
|
|
7
|
+
// Knowledge
|
|
8
|
+
export { KnowledgeStoreFactory, KnowledgeStoreManager, GraphRagFactory } from './knowledge/index.js';
|
|
9
9
|
// LLM
|
|
10
10
|
export { LLMFactory } from './llm/index.js';
|
|
11
11
|
// MCP
|
|
12
12
|
export { MCPClientManager } from './mcp/index.js';
|
|
13
13
|
// Tools
|
|
14
|
-
export { ToolRegistry,
|
|
14
|
+
export { ToolRegistry, ToolDiscovery, AgentToolWrapper, createKnowledgeSearchTool, createAskUserTool, } from './tools/index.js';
|
|
15
15
|
// Functions
|
|
16
16
|
export { FunctionLoader } from './functions/index.js';
|
|
17
|
+
// Memory
|
|
18
|
+
export { ConversationStore } from './memory/index.js';
|
|
17
19
|
//# sourceMappingURL=index.js.map
|
package/dist/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,SAAS;AACT,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/index.ts"],"names":[],"mappings":"AAAA,oBAAoB;AACpB,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAGjD,SAAS;AACT,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAWxF,YAAY;AACZ,OAAO,EACL,cAAc,EACd,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAkB9B,YAAY;AACZ,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAgBrG,MAAM;AACN,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAG5C,MAAM;AACN,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGlD,QAAQ;AACR,OAAO,EACL,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,yBAAyB,EACzB,iBAAiB,GAClB,MAAM,kBAAkB,CAAC;AAE1B,YAAY;AACZ,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGtD,SAAS;AACT,OAAO,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { MemoryGraphStore } from './memory-graph-store.js';
|
|
2
|
+
import type { Community, GraphCommunitiesConfig } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Louvain community detection on the in-memory graph.
|
|
5
|
+
* Groups nodes into communities based on graph structure (edge density).
|
|
6
|
+
*/
|
|
7
|
+
export declare class CommunityDetector {
|
|
8
|
+
private config;
|
|
9
|
+
constructor(config: GraphCommunitiesConfig);
|
|
10
|
+
/**
|
|
11
|
+
* Detect communities in the graph store.
|
|
12
|
+
* Only works with MemoryGraphStore (requires graphology instance).
|
|
13
|
+
*/
|
|
14
|
+
detect(store: MemoryGraphStore): Promise<Community[]>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=community-detector.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"community-detector.d.ts","sourceRoot":"","sources":["../../../../lib/knowledge/graph-rag/community-detector.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAChE,OAAO,KAAK,EAAE,SAAS,EAAE,sBAAsB,EAAE,MAAM,YAAY,CAAC;AAKpE;;;GAGG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,MAAM,CAAyB;gBAE3B,MAAM,EAAE,sBAAsB;IAI1C;;;OAGG;IACG,MAAM,CAAC,KAAK,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;CA4E5D"}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { createLogger } from '../../logger.js';
|
|
2
|
+
const logger = createLogger('CommunityDetector');
|
|
3
|
+
/**
|
|
4
|
+
* Louvain community detection on the in-memory graph.
|
|
5
|
+
* Groups nodes into communities based on graph structure (edge density).
|
|
6
|
+
*/
|
|
7
|
+
export class CommunityDetector {
|
|
8
|
+
config;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
this.config = config;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Detect communities in the graph store.
|
|
14
|
+
* Only works with MemoryGraphStore (requires graphology instance).
|
|
15
|
+
*/
|
|
16
|
+
async detect(store) {
|
|
17
|
+
const graph = await store.getGraphologyInstance();
|
|
18
|
+
if (graph.order === 0) {
|
|
19
|
+
logger.warn('Graph is empty, no communities to detect');
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
// Dynamic imports to handle ESM/CJS interop
|
|
23
|
+
const graphology = await import('graphology');
|
|
24
|
+
const GraphClass = graphology.default ?? graphology;
|
|
25
|
+
const louvainModule = await import('graphology-communities-louvain');
|
|
26
|
+
const louvain = louvainModule.default ?? louvainModule;
|
|
27
|
+
// graphology-communities-louvain requires an undirected graph for community detection.
|
|
28
|
+
// Create a temporary undirected copy.
|
|
29
|
+
const undirected = new GraphClass({ type: 'undirected' });
|
|
30
|
+
graph.forEachNode((nodeId, attrs) => {
|
|
31
|
+
undirected.addNode(nodeId, attrs);
|
|
32
|
+
});
|
|
33
|
+
graph.forEachEdge((_edgeKey, attrs, source, target) => {
|
|
34
|
+
if (source === target)
|
|
35
|
+
return; // skip self-loops
|
|
36
|
+
if (!undirected.hasEdge(source, target)) {
|
|
37
|
+
undirected.addEdge(source, target, { weight: attrs.weight ?? 1 });
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
// Merge edge weights
|
|
41
|
+
const existing = undirected.getEdgeAttributes(source, target);
|
|
42
|
+
undirected.setEdgeAttribute(source, target, 'weight', existing.weight + (attrs.weight ?? 1));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
if (undirected.size === 0) {
|
|
46
|
+
logger.warn('No edges in graph, each node becomes its own community');
|
|
47
|
+
const communities = [];
|
|
48
|
+
let i = 0;
|
|
49
|
+
graph.forEachNode((nodeId) => {
|
|
50
|
+
communities.push({ id: `community-${i}`, nodeIds: [nodeId] });
|
|
51
|
+
i++;
|
|
52
|
+
});
|
|
53
|
+
return communities.filter((c) => c.nodeIds.length >= this.config.minSize);
|
|
54
|
+
}
|
|
55
|
+
logger.info(`Running Louvain on ${undirected.order} nodes, ${undirected.size} edges (resolution: ${this.config.resolution})`);
|
|
56
|
+
// Run Louvain algorithm
|
|
57
|
+
const assignments = louvain(undirected, {
|
|
58
|
+
resolution: this.config.resolution,
|
|
59
|
+
});
|
|
60
|
+
// Group nodes by community
|
|
61
|
+
const communityMap = new Map();
|
|
62
|
+
for (const [nodeId, communityId] of Object.entries(assignments)) {
|
|
63
|
+
const existing = communityMap.get(communityId) ?? [];
|
|
64
|
+
existing.push(nodeId);
|
|
65
|
+
communityMap.set(communityId, existing);
|
|
66
|
+
}
|
|
67
|
+
// Filter by minimum size and create Community objects
|
|
68
|
+
const communities = [];
|
|
69
|
+
for (const [id, nodeIds] of communityMap.entries()) {
|
|
70
|
+
if (nodeIds.length >= this.config.minSize) {
|
|
71
|
+
communities.push({
|
|
72
|
+
id: `community-${id}`,
|
|
73
|
+
nodeIds,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
logger.info(`Detected ${communities.length} communities (min size: ${this.config.minSize})`);
|
|
78
|
+
return communities;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=community-detector.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"community-detector.js","sourceRoot":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AAW,GAAI,OAAe,CAAC,UAAU,EAAE;YAC/C,UAAU,EAAE,IAAI,CAAC,MAAM,CAAC,UAAU;SACnC,CAA2B,CAAC;QAE7B,2BAA2B;QAC3B,MAAM,YAAY,GAAG,IAAI,GAAG,EAAoB,CAAC;QACjD,KAAK,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;YAChE,MAAM,QAAQ,GAAG,YAAY,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;YACrD,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACtB,YAAY,CAAC,GAAG,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QAC1C,CAAC;QAED,sDAAsD;QACtD,MAAM,WAAW,GAAgB,EAAE,CAAC;QACpC,KAAK,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,IAAI,YAAY,CAAC,OAAO,EAAE,EAAE,CAAC;YACnD,IAAI,OAAO,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,CAAC;gBAC1C,WAAW,CAAC,IAAI,CAAC;oBACf,EAAE,EAAE,aAAa,EAAE,EAAE;oBACrB,OAAO;iBACR,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QAED,MAAM,CAAC,IAAI,CAAC,YAAY,WAAW,CAAC,MAAM,2BAA2B,IAAI,CAAC,MAAM,CAAC,OAAO,GAAG,CAAC,CAAC;QAC7F,OAAO,WAAW,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
|
+
import type { Community, GraphStore } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* Generates natural language summaries for graph communities using an LLM.
|
|
5
|
+
* Each community summary describes the key entities and relationships within it.
|
|
6
|
+
*/
|
|
7
|
+
export declare class CommunitySummarizer {
|
|
8
|
+
private llm;
|
|
9
|
+
constructor(llm: BaseChatModel);
|
|
10
|
+
/**
|
|
11
|
+
* Generate summaries for all communities.
|
|
12
|
+
*/
|
|
13
|
+
summarize(communities: Community[], store: GraphStore): Promise<Community[]>;
|
|
14
|
+
private summarizeSingle;
|
|
15
|
+
private buildCommunityContext;
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=community-summarizer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"community-summarizer.d.ts","sourceRoot":"","sources":["../../../../lib/knowledge/graph-rag/community-summarizer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAEjF,OAAO,KAAK,EAAE,SAAS,EAAwB,UAAU,EAAE,MAAM,YAAY,CAAC;AAK9E;;;GAGG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,GAAG,CAAgB;gBAEf,GAAG,EAAE,aAAa;IAI9B;;OAEG;IACG,SAAS,CAAC,WAAW,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,UAAU,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;YAuBpE,eAAe;IAqD7B,OAAO,CAAC,qBAAqB;CAQ9B"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
2
|
+
import { createLogger } from '../../logger.js';
|
|
3
|
+
const logger = createLogger('CommunitySummarizer');
|
|
4
|
+
/**
|
|
5
|
+
* Generates natural language summaries for graph communities using an LLM.
|
|
6
|
+
* Each community summary describes the key entities and relationships within it.
|
|
7
|
+
*/
|
|
8
|
+
export class CommunitySummarizer {
|
|
9
|
+
llm;
|
|
10
|
+
constructor(llm) {
|
|
11
|
+
this.llm = llm;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Generate summaries for all communities.
|
|
15
|
+
*/
|
|
16
|
+
async summarize(communities, store) {
|
|
17
|
+
const summarized = [];
|
|
18
|
+
for (let i = 0; i < communities.length; i++) {
|
|
19
|
+
const community = communities[i];
|
|
20
|
+
logger.info(`Summarizing community ${i + 1}/${communities.length} (${community.nodeIds.length} nodes)`);
|
|
21
|
+
try {
|
|
22
|
+
const { title, summary } = await this.summarizeSingle(community, store);
|
|
23
|
+
summarized.push({ ...community, title, summary });
|
|
24
|
+
}
|
|
25
|
+
catch (error) {
|
|
26
|
+
logger.error(`Failed to summarize community ${community.id}: ${error instanceof Error ? error.message : String(error)}`);
|
|
27
|
+
summarized.push({
|
|
28
|
+
...community,
|
|
29
|
+
title: `Community ${community.id}`,
|
|
30
|
+
summary: `Community with ${community.nodeIds.length} entities.`,
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return summarized;
|
|
35
|
+
}
|
|
36
|
+
async summarizeSingle(community, store) {
|
|
37
|
+
// Gather all nodes and their relationships within the community
|
|
38
|
+
const nodes = [];
|
|
39
|
+
for (const nodeId of community.nodeIds) {
|
|
40
|
+
const node = await store.getNode(nodeId);
|
|
41
|
+
if (node)
|
|
42
|
+
nodes.push(node);
|
|
43
|
+
}
|
|
44
|
+
const allEdges = await store.getAllEdges();
|
|
45
|
+
const communityNodeIds = new Set(community.nodeIds);
|
|
46
|
+
const internalEdges = allEdges.filter((e) => communityNodeIds.has(e.sourceId) && communityNodeIds.has(e.targetId));
|
|
47
|
+
const context = this.buildCommunityContext(nodes, internalEdges);
|
|
48
|
+
const response = await this.llm.invoke([
|
|
49
|
+
new SystemMessage(`You are a knowledge graph analyst. Given a set of entities and relationships from a community in a knowledge graph, provide:
|
|
50
|
+
1. A short title (5-10 words) that captures the main theme
|
|
51
|
+
2. A comprehensive summary (2-4 sentences) that describes the key entities, their relationships, and the overall theme
|
|
52
|
+
|
|
53
|
+
Respond ONLY with valid JSON:
|
|
54
|
+
{
|
|
55
|
+
"title": "Short descriptive title",
|
|
56
|
+
"summary": "Comprehensive summary of the community..."
|
|
57
|
+
}`),
|
|
58
|
+
new HumanMessage(`Analyze this community:\n\n${context}`),
|
|
59
|
+
]);
|
|
60
|
+
const responseText = typeof response.content === 'string'
|
|
61
|
+
? response.content
|
|
62
|
+
: Array.isArray(response.content)
|
|
63
|
+
? response.content.map((c) => (typeof c === 'string' ? c : 'text' in c ? c.text : '')).join('')
|
|
64
|
+
: '';
|
|
65
|
+
try {
|
|
66
|
+
const jsonMatch = responseText.match(/```(?:json)?\s*([\s\S]*?)```/) ?? [null, responseText];
|
|
67
|
+
const parsed = JSON.parse((jsonMatch[1] ?? responseText).trim());
|
|
68
|
+
return {
|
|
69
|
+
title: String(parsed.title ?? `Community ${community.id}`),
|
|
70
|
+
summary: String(parsed.summary ?? ''),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
logger.warn(`Failed to parse community summary, using raw response`);
|
|
75
|
+
return {
|
|
76
|
+
title: `Community ${community.id}`,
|
|
77
|
+
summary: responseText.substring(0, 500),
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
buildCommunityContext(nodes, edges) {
|
|
82
|
+
const entityLines = nodes.map((n) => `- ${n.name} (${n.type}): ${n.description}`).join('\n');
|
|
83
|
+
const relLines = edges.map((e) => `- ${e.sourceId} -[${e.type}]-> ${e.targetId}: ${e.description}`).join('\n');
|
|
84
|
+
return `Entities:\n${entityLines}\n\nRelationships:\n${relLines}`;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
//# sourceMappingURL=community-summarizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"community-summarizer.js","sourceRoot":"","sources":["../../../../lib/knowledge/graph-rag/community-summarizer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAC;AAEvE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE/C,MAAM,MAAM,GAAG,YAAY,CAAC,qBAAqB,CAAC,CAAC;AAEnD;;;G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,IAAI,CAAC,IAAI,CAAC,CAAC;QAEb,OAAO,cAAc,WAAW,uBAAuB,QAAQ,EAAE,CAAC;IACpE,CAAC;CACF"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
|
|
2
|
+
import type { EntityTypeConfig, RelationshipTypeConfig, ExtractionResult } from './types.js';
|
|
3
|
+
interface EntityExtractorOptions {
|
|
4
|
+
llm: BaseChatModel;
|
|
5
|
+
entityTypes?: EntityTypeConfig[];
|
|
6
|
+
relationshipTypes?: RelationshipTypeConfig[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* LLM-based entity and relationship extraction from text chunks.
|
|
10
|
+
*/
|
|
11
|
+
export declare class EntityExtractor {
|
|
12
|
+
private llm;
|
|
13
|
+
private entityTypes?;
|
|
14
|
+
private relationshipTypes?;
|
|
15
|
+
constructor(options: EntityExtractorOptions);
|
|
16
|
+
/**
|
|
17
|
+
* Extract entities and relationships from a set of text chunks.
|
|
18
|
+
* Processes chunks sequentially to avoid rate limiting.
|
|
19
|
+
*/
|
|
20
|
+
extractFromChunks(chunks: Array<{
|
|
21
|
+
id: string;
|
|
22
|
+
content: string;
|
|
23
|
+
}>): Promise<ExtractionResult>;
|
|
24
|
+
private extractFromSingleChunk;
|
|
25
|
+
private buildSystemPrompt;
|
|
26
|
+
private buildUserPrompt;
|
|
27
|
+
private parseExtractionResponse;
|
|
28
|
+
/**
|
|
29
|
+
* Deduplicate entities by normalized key (lowercase name + type).
|
|
30
|
+
* Merges descriptions and source chunk IDs.
|
|
31
|
+
* Updates relationship references to use canonical entity names.
|
|
32
|
+
*/
|
|
33
|
+
private deduplicateEntities;
|
|
34
|
+
}
|
|
35
|
+
export {};
|
|
36
|
+
//# sourceMappingURL=entity-extractor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-extractor.d.ts","sourceRoot":"","sources":["../../../../lib/knowledge/graph-rag/entity-extractor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAEjF,OAAO,KAAK,EAAE,gBAAgB,EAAE,sBAAsB,EAA0C,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAKrI,UAAU,sBAAsB;IAC9B,GAAG,EAAE,aAAa,CAAC;IACnB,WAAW,CAAC,EAAE,gBAAgB,EAAE,CAAC;IACjC,iBAAiB,CAAC,EAAE,sBAAsB,EAAE,CAAC;CAC9C;AAED;;GAEG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,GAAG,CAAgB;IAC3B,OAAO,CAAC,WAAW,CAAC,CAAqB;IACzC,OAAO,CAAC,iBAAiB,CAAC,CAA2B;gBAEzC,OAAO,EAAE,sBAAsB;IAM3C;;;OAGG;IACG,iBAAiB,CAAC,MAAM,EAAE,KAAK,CAAC;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC,GAAG,OAAO,CAAC,gBAAgB,CAAC;YA0BpF,sBAAsB;IAkBpC,OAAO,CAAC,iBAAiB;IA2CzB,OAAO,CAAC,eAAe;IAIvB,OAAO,CAAC,uBAAuB;IAgC/B;;;;OAIG;IACH,OAAO,CAAC,mBAAmB;CAmE5B"}
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import { HumanMessage, SystemMessage } from '@langchain/core/messages';
|
|
2
|
+
import { createLogger } from '../../logger.js';
|
|
3
|
+
const logger = createLogger('EntityExtractor');
|
|
4
|
+
/**
|
|
5
|
+
* LLM-based entity and relationship extraction from text chunks.
|
|
6
|
+
*/
|
|
7
|
+
export class EntityExtractor {
|
|
8
|
+
llm;
|
|
9
|
+
entityTypes;
|
|
10
|
+
relationshipTypes;
|
|
11
|
+
constructor(options) {
|
|
12
|
+
this.llm = options.llm;
|
|
13
|
+
this.entityTypes = options.entityTypes;
|
|
14
|
+
this.relationshipTypes = options.relationshipTypes;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Extract entities and relationships from a set of text chunks.
|
|
18
|
+
* Processes chunks sequentially to avoid rate limiting.
|
|
19
|
+
*/
|
|
20
|
+
async extractFromChunks(chunks) {
|
|
21
|
+
const allEntities = [];
|
|
22
|
+
const allRelationships = [];
|
|
23
|
+
for (let i = 0; i < chunks.length; i++) {
|
|
24
|
+
const chunk = chunks[i];
|
|
25
|
+
logger.info(`Extracting from chunk ${i + 1}/${chunks.length} (${chunk.content.length} chars)`);
|
|
26
|
+
try {
|
|
27
|
+
const result = await this.extractFromSingleChunk(chunk.id, chunk.content);
|
|
28
|
+
allEntities.push(...result.entities);
|
|
29
|
+
allRelationships.push(...result.relationships);
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
logger.error(`Failed to extract from chunk ${i + 1}: ${error instanceof Error ? error.message : String(error)}`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
logger.info(`Raw extraction: ${allEntities.length} entities, ${allRelationships.length} relationships`);
|
|
36
|
+
// Deduplicate entities by normalized name + type
|
|
37
|
+
const deduplicated = this.deduplicateEntities(allEntities, allRelationships);
|
|
38
|
+
logger.info(`After dedup: ${deduplicated.entities.length} entities, ${deduplicated.relationships.length} relationships`);
|
|
39
|
+
return deduplicated;
|
|
40
|
+
}
|
|
41
|
+
async extractFromSingleChunk(chunkId, content) {
|
|
42
|
+
const systemPrompt = this.buildSystemPrompt();
|
|
43
|
+
const userPrompt = this.buildUserPrompt(content);
|
|
44
|
+
const response = await this.llm.invoke([
|
|
45
|
+
new SystemMessage(systemPrompt),
|
|
46
|
+
new HumanMessage(userPrompt),
|
|
47
|
+
]);
|
|
48
|
+
const responseText = typeof response.content === 'string'
|
|
49
|
+
? response.content
|
|
50
|
+
: Array.isArray(response.content)
|
|
51
|
+
? response.content.map((c) => (typeof c === 'string' ? c : 'text' in c ? c.text : '')).join('')
|
|
52
|
+
: '';
|
|
53
|
+
return this.parseExtractionResponse(responseText, chunkId);
|
|
54
|
+
}
|
|
55
|
+
buildSystemPrompt() {
|
|
56
|
+
const entityTypesSection = this.entityTypes && this.entityTypes.length > 0
|
|
57
|
+
? `\n\nEntity types to extract:\n${this.entityTypes.map((t) => `- ${t.name}: ${t.description}`).join('\n')}`
|
|
58
|
+
: '\n\nExtract all notable entities (people, organizations, concepts, locations, events, objects, etc.).';
|
|
59
|
+
const relationshipTypesSection = this.relationshipTypes && this.relationshipTypes.length > 0
|
|
60
|
+
? `\n\nRelationship types to extract:\n${this.relationshipTypes.map((t) => `- ${t.name}: ${t.description}`).join('\n')}`
|
|
61
|
+
: '\n\nExtract all meaningful relationships between entities.';
|
|
62
|
+
return `You are an entity and relationship extraction system. Given a text document, extract structured entities and relationships.
|
|
63
|
+
${entityTypesSection}
|
|
64
|
+
${relationshipTypesSection}
|
|
65
|
+
|
|
66
|
+
Respond ONLY with valid JSON in this exact format:
|
|
67
|
+
{
|
|
68
|
+
"entities": [
|
|
69
|
+
{
|
|
70
|
+
"name": "Entity Name",
|
|
71
|
+
"type": "EntityType",
|
|
72
|
+
"description": "Brief description of this entity based on the text"
|
|
73
|
+
}
|
|
74
|
+
],
|
|
75
|
+
"relationships": [
|
|
76
|
+
{
|
|
77
|
+
"sourceName": "Source Entity Name",
|
|
78
|
+
"sourceType": "SourceEntityType",
|
|
79
|
+
"targetName": "Target Entity Name",
|
|
80
|
+
"targetType": "TargetEntityType",
|
|
81
|
+
"type": "RELATIONSHIP_TYPE",
|
|
82
|
+
"description": "Brief description of this relationship",
|
|
83
|
+
"weight": 1.0
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
Rules:
|
|
89
|
+
- Entity names should be normalized (proper case, no extra whitespace)
|
|
90
|
+
- Use consistent naming for the same entity across extractions
|
|
91
|
+
- Relationship weight should be 0.0 to 1.0 (1.0 = very strong relationship)
|
|
92
|
+
- Every entity in a relationship must also appear in the entities array
|
|
93
|
+
- Be thorough but precise - extract real entities, not generic concepts`;
|
|
94
|
+
}
|
|
95
|
+
buildUserPrompt(content) {
|
|
96
|
+
return `Extract entities and relationships from the following text:\n\n---\n${content}\n---`;
|
|
97
|
+
}
|
|
98
|
+
parseExtractionResponse(responseText, chunkId) {
|
|
99
|
+
try {
|
|
100
|
+
// Extract JSON from response (handle markdown code blocks)
|
|
101
|
+
const jsonMatch = responseText.match(/```(?:json)?\s*([\s\S]*?)```/) ?? [null, responseText];
|
|
102
|
+
const jsonStr = (jsonMatch[1] ?? responseText).trim();
|
|
103
|
+
const parsed = JSON.parse(jsonStr);
|
|
104
|
+
const entities = (parsed.entities ?? []).map((e) => ({
|
|
105
|
+
name: String(e.name ?? '').trim(),
|
|
106
|
+
type: String(e.type ?? 'Unknown').trim(),
|
|
107
|
+
description: String(e.description ?? '').trim(),
|
|
108
|
+
properties: { sourceChunkId: chunkId },
|
|
109
|
+
})).filter((e) => e.name.length > 0);
|
|
110
|
+
const relationships = (parsed.relationships ?? []).map((r) => ({
|
|
111
|
+
sourceName: String(r.sourceName ?? '').trim(),
|
|
112
|
+
sourceType: String(r.sourceType ?? 'Unknown').trim(),
|
|
113
|
+
targetName: String(r.targetName ?? '').trim(),
|
|
114
|
+
targetType: String(r.targetType ?? 'Unknown').trim(),
|
|
115
|
+
type: String(r.type ?? 'RELATES_TO').trim(),
|
|
116
|
+
description: String(r.description ?? '').trim(),
|
|
117
|
+
weight: typeof r.weight === 'number' ? Math.max(0, Math.min(1, r.weight)) : 1.0,
|
|
118
|
+
})).filter((r) => r.sourceName.length > 0 && r.targetName.length > 0);
|
|
119
|
+
return { entities, relationships };
|
|
120
|
+
}
|
|
121
|
+
catch (error) {
|
|
122
|
+
logger.warn(`Failed to parse extraction response for chunk ${chunkId}: ${error instanceof Error ? error.message : String(error)}`);
|
|
123
|
+
logger.debug(`Response was: ${responseText.substring(0, 200)}...`);
|
|
124
|
+
return { entities: [], relationships: [] };
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Deduplicate entities by normalized key (lowercase name + type).
|
|
129
|
+
* Merges descriptions and source chunk IDs.
|
|
130
|
+
* Updates relationship references to use canonical entity names.
|
|
131
|
+
*/
|
|
132
|
+
deduplicateEntities(entities, relationships) {
|
|
133
|
+
const entityMap = new Map();
|
|
134
|
+
const nameNormMap = new Map(); // normalizedKey -> canonical name
|
|
135
|
+
for (const entity of entities) {
|
|
136
|
+
const key = `${entity.name.toLowerCase()}::${entity.type.toLowerCase()}`;
|
|
137
|
+
const existing = entityMap.get(key);
|
|
138
|
+
if (existing) {
|
|
139
|
+
// Merge: keep longer description, merge source chunks
|
|
140
|
+
if (entity.description.length > existing.description.length) {
|
|
141
|
+
existing.description = entity.description;
|
|
142
|
+
}
|
|
143
|
+
const existingChunks = existing.properties.sourceChunkIds ?? [];
|
|
144
|
+
const newChunkId = entity.properties.sourceChunkId;
|
|
145
|
+
if (newChunkId && !existingChunks.includes(newChunkId)) {
|
|
146
|
+
existingChunks.push(newChunkId);
|
|
147
|
+
}
|
|
148
|
+
existing.properties.sourceChunkIds = existingChunks;
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
const chunkId = entity.properties.sourceChunkId;
|
|
152
|
+
entityMap.set(key, {
|
|
153
|
+
...entity,
|
|
154
|
+
properties: {
|
|
155
|
+
sourceChunkIds: chunkId ? [chunkId] : [],
|
|
156
|
+
},
|
|
157
|
+
});
|
|
158
|
+
nameNormMap.set(key, entity.name);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
// Deduplicate relationships
|
|
162
|
+
const relMap = new Map();
|
|
163
|
+
for (const rel of relationships) {
|
|
164
|
+
const sourceKey = `${rel.sourceName.toLowerCase()}::${rel.sourceType.toLowerCase()}`;
|
|
165
|
+
const targetKey = `${rel.targetName.toLowerCase()}::${rel.targetType.toLowerCase()}`;
|
|
166
|
+
// Update names to canonical versions
|
|
167
|
+
const canonicalSource = nameNormMap.get(sourceKey) ?? rel.sourceName;
|
|
168
|
+
const canonicalTarget = nameNormMap.get(targetKey) ?? rel.targetName;
|
|
169
|
+
const relKey = `${sourceKey}->${rel.type.toLowerCase()}->${targetKey}`;
|
|
170
|
+
const existing = relMap.get(relKey);
|
|
171
|
+
if (existing) {
|
|
172
|
+
// Merge: average weights, keep longer description
|
|
173
|
+
existing.weight = (existing.weight + rel.weight) / 2;
|
|
174
|
+
if (rel.description.length > existing.description.length) {
|
|
175
|
+
existing.description = rel.description;
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
else {
|
|
179
|
+
relMap.set(relKey, {
|
|
180
|
+
...rel,
|
|
181
|
+
sourceName: canonicalSource,
|
|
182
|
+
targetName: canonicalTarget,
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
return {
|
|
187
|
+
entities: Array.from(entityMap.values()),
|
|
188
|
+
relationships: Array.from(relMap.values()),
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=entity-extractor.js.map
|