@ai.ntellect/core 0.8.3 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mocharc.json +2 -1
- package/AGENTS.md +50 -0
- package/ARCHITECTURE.md +58 -0
- package/BENCHMARK.md +38 -0
- package/CHANGELOG.md +224 -0
- package/README.md +413 -199
- package/agent/agent-workflow.ts +569 -0
- package/agent/agent.ts +183 -0
- package/{modules/agent → agent}/base/executor.ts +11 -8
- package/{modules/agent → agent}/base/index.ts +2 -14
- package/agent/entity-resolver/confidence.ts +54 -0
- package/agent/entity-resolver/entity-index.ts +241 -0
- package/agent/entity-resolver/explore-strategy.ts +82 -0
- package/agent/entity-resolver/index.ts +22 -0
- package/agent/entity-resolver/resolver.ts +193 -0
- package/agent/entity-resolver/scorer.ts +211 -0
- package/agent/entity-resolver/types.ts +98 -0
- package/agent/generic-executor.ts +713 -0
- package/agent/handlers/cognitive-handler.ts +197 -0
- package/agent/handlers/index.ts +1 -0
- package/agent/handoff.ts +58 -0
- package/agent/llm-factory.ts +343 -0
- package/agent/orchestrator.ts +45 -0
- package/{modules/agent → agent}/prompt-builder.ts +1 -1
- package/agent/registry.ts +64 -0
- package/agent/tools/file-system.ts +471 -0
- package/agent/tools/index.ts +23 -0
- package/agent/tools/logger.ts +105 -0
- package/agent/tools/tool-resolver.ts +104 -0
- package/benchmark/cortexflow-workflow.ts +182 -0
- package/benchmark/langgraph-workflow.ts +201 -0
- package/benchmark/llm-client.ts +76 -0
- package/benchmark/run-benchmark.ts +222 -0
- package/cli-dev.ts +419 -0
- package/dist/agent/agent-workflow.d.ts +41 -0
- package/dist/agent/agent-workflow.d.ts.map +1 -0
- package/dist/agent/agent-workflow.js +560 -0
- package/dist/agent/agent-workflow.js.map +1 -0
- package/dist/agent/agent.d.ts +38 -0
- package/dist/agent/agent.d.ts.map +1 -0
- package/dist/agent/agent.js +149 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/{modules/agent → agent}/base/executor.d.ts +3 -3
- package/dist/agent/base/executor.d.ts.map +1 -0
- package/dist/{modules/agent → agent}/base/executor.js +8 -5
- package/dist/agent/base/executor.js.map +1 -0
- package/dist/{modules/agent → agent}/base/index.d.ts +1 -1
- package/dist/agent/base/index.d.ts.map +1 -0
- package/dist/{modules/agent → agent}/base/index.js +0 -12
- package/dist/agent/base/index.js.map +1 -0
- package/dist/agent/entity-resolver/confidence.d.ts +4 -0
- package/dist/agent/entity-resolver/confidence.d.ts.map +1 -0
- package/dist/agent/entity-resolver/confidence.js +47 -0
- package/dist/agent/entity-resolver/confidence.js.map +1 -0
- package/dist/agent/entity-resolver/entity-index.d.ts +40 -0
- package/dist/agent/entity-resolver/entity-index.d.ts.map +1 -0
- package/dist/agent/entity-resolver/entity-index.js +244 -0
- package/dist/agent/entity-resolver/entity-index.js.map +1 -0
- package/dist/agent/entity-resolver/explore-strategy.d.ts +13 -0
- package/dist/agent/entity-resolver/explore-strategy.d.ts.map +1 -0
- package/dist/agent/entity-resolver/explore-strategy.js +109 -0
- package/dist/agent/entity-resolver/explore-strategy.js.map +1 -0
- package/dist/agent/entity-resolver/index.d.ts +8 -0
- package/dist/agent/entity-resolver/index.d.ts.map +1 -0
- package/dist/agent/entity-resolver/index.js +16 -0
- package/dist/agent/entity-resolver/index.js.map +1 -0
- package/dist/agent/entity-resolver/resolver.d.ts +18 -0
- package/dist/agent/entity-resolver/resolver.d.ts.map +1 -0
- package/dist/agent/entity-resolver/resolver.js +158 -0
- package/dist/agent/entity-resolver/resolver.js.map +1 -0
- package/dist/agent/entity-resolver/scorer.d.ts +3 -0
- package/dist/agent/entity-resolver/scorer.d.ts.map +1 -0
- package/dist/agent/entity-resolver/scorer.js +182 -0
- package/dist/agent/entity-resolver/scorer.js.map +1 -0
- package/dist/agent/entity-resolver/types.d.ts +89 -0
- package/dist/agent/entity-resolver/types.d.ts.map +1 -0
- package/dist/agent/entity-resolver/types.js +3 -0
- package/dist/agent/entity-resolver/types.js.map +1 -0
- package/dist/{modules/agent → agent}/generic-executor.d.ts +37 -27
- package/dist/agent/generic-executor.d.ts.map +1 -0
- package/dist/agent/generic-executor.js +620 -0
- package/dist/agent/generic-executor.js.map +1 -0
- package/dist/agent/handlers/cognitive-handler.d.ts +44 -0
- package/dist/agent/handlers/cognitive-handler.d.ts.map +1 -0
- package/dist/agent/handlers/cognitive-handler.js +172 -0
- package/dist/agent/handlers/cognitive-handler.js.map +1 -0
- package/dist/agent/handlers/index.d.ts +2 -0
- package/dist/agent/handlers/index.d.ts.map +1 -0
- package/dist/agent/handlers/index.js +7 -0
- package/dist/agent/handlers/index.js.map +1 -0
- package/dist/agent/handoff.d.ts +12 -0
- package/dist/agent/handoff.d.ts.map +1 -0
- package/dist/agent/handoff.js +62 -0
- package/dist/agent/handoff.js.map +1 -0
- package/dist/agent/llm-factory.d.ts.map +1 -0
- package/dist/agent/llm-factory.js +297 -0
- package/dist/agent/llm-factory.js.map +1 -0
- package/dist/agent/orchestrator.d.ts +18 -0
- package/dist/agent/orchestrator.d.ts.map +1 -0
- package/dist/agent/orchestrator.js +44 -0
- package/dist/agent/orchestrator.js.map +1 -0
- package/dist/{modules/agent → agent}/prompt-builder.d.ts +1 -1
- package/dist/agent/prompt-builder.d.ts.map +1 -0
- package/dist/agent/prompt-builder.js.map +1 -0
- package/dist/agent/registry.d.ts +19 -0
- package/dist/agent/registry.d.ts.map +1 -0
- package/dist/agent/registry.js +48 -0
- package/dist/agent/registry.js.map +1 -0
- package/dist/agent/tools/file-system.d.ts +11 -0
- package/dist/agent/tools/file-system.d.ts.map +1 -0
- package/dist/agent/tools/file-system.js +528 -0
- package/dist/agent/tools/file-system.js.map +1 -0
- package/dist/agent/tools/index.d.ts +4 -0
- package/dist/agent/tools/index.d.ts.map +1 -0
- package/dist/agent/tools/index.js +20 -0
- package/dist/agent/tools/index.js.map +1 -0
- package/dist/agent/tools/logger.d.ts +33 -0
- package/dist/agent/tools/logger.d.ts.map +1 -0
- package/dist/agent/tools/logger.js +86 -0
- package/dist/agent/tools/logger.js.map +1 -0
- package/dist/agent/tools/tool-resolver.d.ts +7 -0
- package/dist/agent/tools/tool-resolver.d.ts.map +1 -0
- package/dist/agent/tools/tool-resolver.js +122 -0
- package/dist/agent/tools/tool-resolver.js.map +1 -0
- package/dist/execution/adapters/in-memory-checkpoint.d.ts +11 -0
- package/dist/execution/adapters/in-memory-checkpoint.d.ts.map +1 -0
- package/dist/execution/adapters/in-memory-checkpoint.js +54 -0
- package/dist/execution/adapters/in-memory-checkpoint.js.map +1 -0
- package/dist/execution/compiler.d.ts +8 -0
- package/dist/execution/compiler.d.ts.map +1 -0
- package/dist/execution/compiler.js +50 -0
- package/dist/execution/compiler.js.map +1 -0
- package/dist/execution/controller.d.ts.map +1 -0
- package/dist/execution/controller.js.map +1 -0
- package/dist/execution/event-manager.d.ts +29 -0
- package/dist/execution/event-manager.d.ts.map +1 -0
- package/dist/{graph → execution}/event-manager.js +4 -114
- package/dist/execution/event-manager.js.map +1 -0
- package/dist/{graph → execution}/index.d.ts +50 -2
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +638 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/execution/logger.d.ts.map +1 -0
- package/dist/execution/logger.js.map +1 -0
- package/dist/{graph → execution}/node.d.ts +6 -1
- package/dist/execution/node.d.ts.map +1 -0
- package/dist/{graph → execution}/node.js +83 -10
- package/dist/execution/node.js.map +1 -0
- package/dist/execution/observer.d.ts.map +1 -0
- package/dist/execution/observer.js.map +1 -0
- package/dist/execution/planner.d.ts +14 -0
- package/dist/execution/planner.d.ts.map +1 -0
- package/dist/execution/planner.js +43 -0
- package/dist/execution/planner.js.map +1 -0
- package/dist/execution/reducer.d.ts +19 -0
- package/dist/execution/reducer.d.ts.map +1 -0
- package/dist/execution/reducer.js +61 -0
- package/dist/execution/reducer.js.map +1 -0
- package/dist/execution/registry.d.ts +38 -0
- package/dist/execution/registry.d.ts.map +1 -0
- package/dist/execution/registry.js +63 -0
- package/dist/execution/registry.js.map +1 -0
- package/dist/execution/send-api.d.ts +24 -0
- package/dist/execution/send-api.d.ts.map +1 -0
- package/dist/execution/send-api.js +52 -0
- package/dist/execution/send-api.js.map +1 -0
- package/dist/execution/types.parallel.d.ts +61 -0
- package/dist/execution/types.parallel.d.ts.map +1 -0
- package/dist/execution/types.parallel.js +3 -0
- package/dist/execution/types.parallel.js.map +1 -0
- package/dist/execution/visualizer.d.ts.map +1 -0
- package/dist/execution/visualizer.js.map +1 -0
- package/dist/index.d.ts +27 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -8
- package/dist/index.js.map +1 -1
- package/dist/interfaces/index.d.ts +32 -1
- package/dist/interfaces/index.d.ts.map +1 -1
- package/dist/interfaces/index.js.map +1 -1
- package/dist/modules/cli/index.d.ts +13 -0
- package/dist/modules/cli/index.d.ts.map +1 -0
- package/dist/modules/cli/index.js +672 -0
- package/dist/modules/cli/index.js.map +1 -0
- package/dist/modules/nlp/engine.d.ts.map +1 -1
- package/dist/modules/nlp/engine.js +0 -1
- package/dist/modules/nlp/engine.js.map +1 -1
- package/dist/persistence/index.d.ts +12 -0
- package/dist/persistence/index.d.ts.map +1 -0
- package/dist/persistence/index.js +24 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/persistence/neo4j/driver.d.ts +26 -0
- package/dist/persistence/neo4j/driver.d.ts.map +1 -0
- package/dist/persistence/neo4j/driver.js +64 -0
- package/dist/persistence/neo4j/driver.js.map +1 -0
- package/dist/persistence/neo4j/entity-store.d.ts +15 -0
- package/dist/persistence/neo4j/entity-store.d.ts.map +1 -0
- package/dist/persistence/neo4j/entity-store.js +136 -0
- package/dist/persistence/neo4j/entity-store.js.map +1 -0
- package/dist/persistence/neo4j/execution-tracer.d.ts +19 -0
- package/dist/persistence/neo4j/execution-tracer.d.ts.map +1 -0
- package/dist/persistence/neo4j/execution-tracer.js +166 -0
- package/dist/persistence/neo4j/execution-tracer.js.map +1 -0
- package/dist/persistence/neo4j/memory-adapter.d.ts +35 -0
- package/dist/persistence/neo4j/memory-adapter.d.ts.map +1 -0
- package/dist/persistence/neo4j/memory-adapter.js +252 -0
- package/dist/persistence/neo4j/memory-adapter.js.map +1 -0
- package/dist/persistence/neo4j/petri-checkpoint-adapter.d.ts +22 -0
- package/dist/persistence/neo4j/petri-checkpoint-adapter.d.ts.map +1 -0
- package/dist/persistence/neo4j/petri-checkpoint-adapter.js +141 -0
- package/dist/persistence/neo4j/petri-checkpoint-adapter.js.map +1 -0
- package/dist/pipeline/agent-pipeline.d.ts +99 -0
- package/dist/pipeline/agent-pipeline.d.ts.map +1 -0
- package/dist/pipeline/agent-pipeline.js +356 -0
- package/dist/pipeline/agent-pipeline.js.map +1 -0
- package/dist/routing/checkpoint-adapter.d.ts +30 -0
- package/dist/routing/checkpoint-adapter.d.ts.map +1 -0
- package/dist/routing/checkpoint-adapter.js +83 -0
- package/dist/routing/checkpoint-adapter.js.map +1 -0
- package/dist/routing/documentation-generator.d.ts +47 -0
- package/dist/routing/documentation-generator.d.ts.map +1 -0
- package/dist/routing/documentation-generator.js +320 -0
- package/dist/routing/documentation-generator.js.map +1 -0
- package/dist/routing/index.d.ts +38 -0
- package/dist/routing/index.d.ts.map +1 -0
- package/dist/routing/index.js +375 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/routing/intent-classifier.d.ts +206 -0
- package/dist/routing/intent-classifier.d.ts.map +1 -0
- package/dist/routing/intent-classifier.js +267 -0
- package/dist/routing/intent-classifier.js.map +1 -0
- package/dist/routing/matrix.d.ts +6 -0
- package/dist/routing/matrix.d.ts.map +1 -0
- package/dist/routing/matrix.js +131 -0
- package/dist/routing/matrix.js.map +1 -0
- package/dist/routing/orchestrator.d.ts +87 -0
- package/dist/routing/orchestrator.d.ts.map +1 -0
- package/dist/routing/orchestrator.js +425 -0
- package/dist/routing/orchestrator.js.map +1 -0
- package/dist/routing/postgres-checkpoint-adapter.d.ts +32 -0
- package/dist/routing/postgres-checkpoint-adapter.d.ts.map +1 -0
- package/dist/routing/postgres-checkpoint-adapter.js +167 -0
- package/dist/routing/postgres-checkpoint-adapter.js.map +1 -0
- package/dist/routing/redis-checkpoint-adapter.d.ts +34 -0
- package/dist/routing/redis-checkpoint-adapter.d.ts.map +1 -0
- package/dist/routing/redis-checkpoint-adapter.js +170 -0
- package/dist/routing/redis-checkpoint-adapter.js.map +1 -0
- package/dist/routing/types.d.ts +49 -0
- package/dist/routing/types.d.ts.map +1 -0
- package/dist/routing/types.js +3 -0
- package/dist/routing/types.js.map +1 -0
- package/dist/types/agent.d.ts +144 -88
- package/dist/types/agent.d.ts.map +1 -1
- package/dist/types/agent.js +49 -0
- package/dist/types/agent.js.map +1 -1
- package/dist/types/index.d.ts +46 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/generate-action-schema.d.ts +2 -3
- package/dist/utils/generate-action-schema.d.ts.map +1 -1
- package/dist/utils/generate-action-schema.js +3 -1
- package/dist/utils/generate-action-schema.js.map +1 -1
- package/dist/utils/logger.d.ts +27 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +45 -0
- package/dist/utils/logger.js.map +1 -0
- package/docs/.gitbook/assets/image (1).png +0 -0
- package/docs/.gitbook/assets/image (2).png +0 -0
- package/docs/.gitbook/assets/image (3).png +0 -0
- package/docs/.gitbook/assets/image (4).png +0 -0
- package/docs/.gitbook/assets/image (5).png +0 -0
- package/docs/.gitbook/assets/image (6).png +0 -0
- package/docs/.gitbook/assets/image.png +0 -0
- package/docs/README.md +57 -0
- package/docs/SUMMARY.md +34 -0
- package/docs/cas-dusages.md +69 -0
- package/docs/cli/README.md +65 -0
- package/docs/concepts-cles.md +50 -0
- package/docs/core/architecture.md +87 -0
- package/docs/core/benchmark.md +59 -0
- package/docs/core/checkpoint.md +72 -0
- package/docs/core/documentation.md +55 -0
- package/docs/core/graphcontroller.md +63 -0
- package/docs/core/graphflow.md +137 -0
- package/docs/core/introduction.md +41 -0
- package/docs/core/les-evenements.md +95 -0
- package/docs/modules/agenda/README.md +63 -0
- package/docs/modules/agenda/interface-iagenda.md +170 -0
- package/docs/modules/agenda/les-adaptateurs/README.md +237 -0
- package/docs/modules/agenda/les-adaptateurs/nodecronadapter.md +91 -0
- package/docs/modules/introduction.md +55 -0
- package/docs/modules/les-adaptateurs.md +52 -0
- package/docs/modules/memoire/README.md +68 -0
- package/docs/modules/memoire/interface-imemory.md +183 -0
- package/docs/modules/memoire/les-adaptateurs/README.md +209 -0
- package/docs/modules/memoire/les-adaptateurs/inmemoryadapter.md +110 -0
- package/docs/modules/memoire/les-adaptateurs/meilisearchadapter.md +147 -0
- package/docs/modules/memoire/les-adaptateurs/redisadapter.md +212 -0
- package/docs/modules/nlp/README.md +44 -0
- package/docs/philosophie.md +51 -0
- package/docs/tutoriels/ajouter-des-conditions.md +150 -0
- package/docs/tutoriels/branching.md +194 -0
- package/docs/tutoriels/checkpoint-usage.md +99 -0
- package/docs/tutoriels/creer-agent-onchain.md +1041 -0
- package/docs/tutoriels/creer-un-agent.md +108 -0
- package/docs/tutoriels/creer-un-graphe-simple.md +92 -0
- package/docs/tutoriels/gerer-les-erreurs.md +124 -0
- package/docs/tutoriels/pour-commencer.md +73 -0
- package/docs/tutoriels/retry.md +166 -0
- package/execution/adapters/in-memory-checkpoint.ts +35 -0
- package/execution/compiler.ts +47 -0
- package/{graph → execution}/event-manager.ts +4 -117
- package/{graph → execution}/index.ts +376 -8
- package/{graph → execution}/node.ts +116 -12
- package/execution/planner.ts +40 -0
- package/execution/reducer.ts +73 -0
- package/execution/registry.ts +86 -0
- package/execution/send-api.ts +58 -0
- package/execution/types.parallel.ts +81 -0
- package/index.ts +35 -8
- package/interfaces/index.ts +37 -0
- package/modules/cli/index.ts +580 -0
- package/modules/nlp/engine.ts +0 -1
- package/package.json +50 -16
- package/persistence/index.ts +27 -0
- package/persistence/neo4j/driver.ts +34 -0
- package/persistence/neo4j/entity-store.ts +141 -0
- package/persistence/neo4j/execution-tracer.ts +194 -0
- package/persistence/neo4j/memory-adapter.ts +281 -0
- package/persistence/neo4j/petri-checkpoint-adapter.ts +153 -0
- package/pipeline/agent-pipeline.ts +426 -0
- package/routing/checkpoint-adapter.ts +79 -0
- package/routing/documentation-generator.ts +358 -0
- package/routing/index.ts +459 -0
- package/routing/intent-classifier.ts +360 -0
- package/routing/matrix.ts +138 -0
- package/routing/orchestrator.ts +498 -0
- package/routing/patterns/data-extraction.json +79 -0
- package/routing/patterns/human-approval.json +64 -0
- package/routing/patterns/rag-search.json +68 -0
- package/routing/postgres-checkpoint-adapter.ts +172 -0
- package/routing/redis-checkpoint-adapter.ts +187 -0
- package/routing/types.ts +59 -0
- package/routing/web-server.ts +260 -0
- package/scripts/generate-petri-docs.ts +70 -0
- package/scripts/get-gmail-token.js +65 -0
- package/scripts/get-gmail-token.ts +65 -0
- package/test/agent/agent.test.ts +92 -0
- package/test/agent/clone.test.ts +143 -0
- package/test/agent/cognitive-handler.test.ts +78 -0
- package/test/agent/entity-store.test.ts +80 -0
- package/test/agent/generic-executor.test.ts +230 -0
- package/test/agent/handoff.test.ts +163 -0
- package/test/agent/llm-factory.test.ts +40 -0
- package/test/agent/orchestrator.test.ts +156 -0
- package/test/agent/registry.test.ts +97 -0
- package/test/agent/tools.test.ts +267 -0
- package/test/execution/checkpoint.test.ts +811 -0
- package/test/{graph → execution}/controller.test.ts +2 -2
- package/test/{graph → execution}/event-manager.test.ts +1 -1
- package/test/{graph → execution}/index.test.ts +24 -15
- package/test/{graph → execution}/node.test.ts +3 -3
- package/test/{graph → execution}/observer.test.ts +2 -2
- package/test/execution/parallel.test.ts +135 -0
- package/test/execution/plan-llm-integration.test.ts +290 -0
- package/test/execution/plan-real-onchain.test.ts +226 -0
- package/test/execution/send-api.test.ts +121 -0
- package/test/modules/cli/index.test.ts +125 -0
- package/test/persistence/neo4j-execution-tracer.test.ts +96 -0
- package/test/persistence/neo4j-memory-adapter.test.ts +107 -0
- package/test/persistence/neo4j-petri-checkpoint.test.ts +89 -0
- package/test/pipeline/agent-pipeline.test.ts +118 -0
- package/test/routing/checkpoint-persistence.test.ts +58 -0
- package/test/routing/documentation-generator.test.ts +76 -0
- package/test/routing/integration.test.ts +261 -0
- package/test/routing/intent-classifier.test.ts +102 -0
- package/test/routing/petri.test.ts +156 -0
- package/test/routing/real-llm.test.ts +260 -0
- package/test-petri-features.ts +218 -0
- package/test-pipeline-api.ts +163 -0
- package/tsconfig.json +5 -2
- package/types/agent.ts +126 -4
- package/types/index.ts +66 -5
- package/utils/generate-action-schema.ts +5 -4
- package/utils/logger.ts +40 -0
- package/dist/graph/controller.d.ts.map +0 -1
- package/dist/graph/controller.js.map +0 -1
- package/dist/graph/event-manager.d.ts +0 -101
- package/dist/graph/event-manager.d.ts.map +0 -1
- package/dist/graph/event-manager.js.map +0 -1
- package/dist/graph/index.d.ts.map +0 -1
- package/dist/graph/index.js +0 -340
- package/dist/graph/index.js.map +0 -1
- package/dist/graph/logger.d.ts.map +0 -1
- package/dist/graph/logger.js.map +0 -1
- package/dist/graph/node.d.ts.map +0 -1
- package/dist/graph/node.js.map +0 -1
- package/dist/graph/observer.d.ts.map +0 -1
- package/dist/graph/observer.js.map +0 -1
- package/dist/graph/visualizer.d.ts.map +0 -1
- package/dist/graph/visualizer.js.map +0 -1
- package/dist/modules/agent/agent.d.ts +0 -35
- package/dist/modules/agent/agent.d.ts.map +0 -1
- package/dist/modules/agent/agent.js +0 -103
- package/dist/modules/agent/agent.js.map +0 -1
- package/dist/modules/agent/base/executor.d.ts.map +0 -1
- package/dist/modules/agent/base/executor.js.map +0 -1
- package/dist/modules/agent/base/index.d.ts.map +0 -1
- package/dist/modules/agent/base/index.js.map +0 -1
- package/dist/modules/agent/generic-assistant.d.ts +0 -20
- package/dist/modules/agent/generic-assistant.d.ts.map +0 -1
- package/dist/modules/agent/generic-assistant.js +0 -89
- package/dist/modules/agent/generic-assistant.js.map +0 -1
- package/dist/modules/agent/generic-executor.d.ts.map +0 -1
- package/dist/modules/agent/generic-executor.js +0 -189
- package/dist/modules/agent/generic-executor.js.map +0 -1
- package/dist/modules/agent/llm-factory.d.ts.map +0 -1
- package/dist/modules/agent/llm-factory.js +0 -56
- package/dist/modules/agent/llm-factory.js.map +0 -1
- package/dist/modules/agent/prompt-builder.d.ts.map +0 -1
- package/dist/modules/agent/prompt-builder.js.map +0 -1
- package/dist/modules/memory/adapters/in-memory/index.d.ts +0 -120
- package/dist/modules/memory/adapters/in-memory/index.d.ts.map +0 -1
- package/dist/modules/memory/adapters/in-memory/index.js +0 -212
- package/dist/modules/memory/adapters/in-memory/index.js.map +0 -1
- package/dist/modules/memory/adapters/meilisearch/index.d.ts +0 -110
- package/dist/modules/memory/adapters/meilisearch/index.d.ts.map +0 -1
- package/dist/modules/memory/adapters/meilisearch/index.js +0 -324
- package/dist/modules/memory/adapters/meilisearch/index.js.map +0 -1
- package/dist/modules/memory/adapters/redis/index.d.ts +0 -82
- package/dist/modules/memory/adapters/redis/index.d.ts.map +0 -1
- package/dist/modules/memory/adapters/redis/index.js +0 -160
- package/dist/modules/memory/adapters/redis/index.js.map +0 -1
- package/dist/modules/memory/index.d.ts +0 -67
- package/dist/modules/memory/index.d.ts.map +0 -1
- package/dist/modules/memory/index.js +0 -104
- package/dist/modules/memory/index.js.map +0 -1
- package/modules/agent/agent.ts +0 -107
- package/modules/agent/generic-assistant.ts +0 -92
- package/modules/agent/generic-executor.ts +0 -252
- package/modules/agent/llm-factory.ts +0 -47
- package/modules/memory/adapters/in-memory/index.ts +0 -208
- package/modules/memory/adapters/meilisearch/index.ts +0 -364
- package/modules/memory/adapters/redis/index.ts +0 -165
- package/modules/memory/index.ts +0 -93
- package/test/modules/memory/adapters/in-memory.test.ts +0 -153
- package/test/modules/memory/adapters/meilisearch.test.ts +0 -287
- package/test/modules/memory/base.test.ts +0 -230
- /package/dist/{modules/agent → agent}/llm-factory.d.ts +0 -0
- /package/dist/{modules/agent → agent}/prompt-builder.js +0 -0
- /package/dist/{graph → execution}/controller.d.ts +0 -0
- /package/dist/{graph → execution}/controller.js +0 -0
- /package/dist/{graph → execution}/logger.d.ts +0 -0
- /package/dist/{graph → execution}/logger.js +0 -0
- /package/dist/{graph → execution}/observer.d.ts +0 -0
- /package/dist/{graph → execution}/observer.js +0 -0
- /package/dist/{graph → execution}/visualizer.d.ts +0 -0
- /package/dist/{graph → execution}/visualizer.js +0 -0
- /package/{graph → execution}/controller.ts +0 -0
- /package/{graph → execution}/logger.ts +0 -0
- /package/{graph → execution}/observer.ts +0 -0
- /package/{graph → execution}/visualizer.ts +0 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { createPublicClient, createWalletClient, http, parseEther, formatEther } from 'viem';
|
|
4
|
+
import { sepolia } from 'viem/chains';
|
|
5
|
+
import { privateKeyToAccount } from 'viem/accounts';
|
|
6
|
+
import { GraphFlow } from '../../execution/index';
|
|
7
|
+
import { ToolRegistry } from '../../execution/registry';
|
|
8
|
+
import { generatePlan, PlanSchema, renderPlan } from '../../execution/planner';
|
|
9
|
+
import { compilePlan } from '../../execution/compiler';
|
|
10
|
+
|
|
11
|
+
// Load env
|
|
12
|
+
function loadEnv() {
|
|
13
|
+
const fs = require('fs');
|
|
14
|
+
const content = fs.readFileSync('.env', 'utf-8');
|
|
15
|
+
const env: Record<string, string> = {};
|
|
16
|
+
content.split('\n').forEach((line: string) => {
|
|
17
|
+
const idx = line.indexOf('=');
|
|
18
|
+
if (idx > 0) env[line.slice(0, idx).trim()] = line.slice(idx + 1).trim();
|
|
19
|
+
});
|
|
20
|
+
return env;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const env = loadEnv();
|
|
24
|
+
const RPC_URL = env['RPC_URL'];
|
|
25
|
+
const PRIVATE_KEY_1 = env['PRIVATE_KEY_1'];
|
|
26
|
+
|
|
27
|
+
// Real viem clients
|
|
28
|
+
const publicClient = createPublicClient({ chain: sepolia, transport: http(RPC_URL) });
|
|
29
|
+
const account = privateKeyToAccount(PRIVATE_KEY_1 as `0x${string}`);
|
|
30
|
+
const walletClient = createWalletClient({ account, chain: sepolia, transport: http(RPC_URL) });
|
|
31
|
+
|
|
32
|
+
// Real LLM call via Groq
|
|
33
|
+
async function callGroq(prompt: string): Promise<string> {
|
|
34
|
+
const response = await fetch('https://api.groq.com/openai/v1/chat/completions', {
|
|
35
|
+
method: 'POST',
|
|
36
|
+
headers: {
|
|
37
|
+
'Content-Type': 'application/json',
|
|
38
|
+
'Authorization': `Bearer ${env['GROQ_API_KEY']}`,
|
|
39
|
+
},
|
|
40
|
+
body: JSON.stringify({
|
|
41
|
+
model: 'llama-3.1-8b-instant',
|
|
42
|
+
messages: [
|
|
43
|
+
{ role: 'system', content: 'You are a workflow planner. Output valid JSON only.' },
|
|
44
|
+
{ role: 'user', content: prompt },
|
|
45
|
+
],
|
|
46
|
+
temperature: 0.1,
|
|
47
|
+
response_format: { type: 'json_object' },
|
|
48
|
+
}),
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
if (!response.ok) throw new Error(`Groq API error: ${await response.text()}`);
|
|
52
|
+
return (await response.json()).choices[0].message.content;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// Real onchain tools
|
|
56
|
+
function createRealCheckBalanceTool() {
|
|
57
|
+
const g = new GraphFlow<any>({
|
|
58
|
+
name: 'check_balance',
|
|
59
|
+
context: { balance: '', address: '' },
|
|
60
|
+
schema: z.object({ balance: z.string(), address: z.string() }).passthrough(),
|
|
61
|
+
nodes: [{
|
|
62
|
+
name: 'run',
|
|
63
|
+
execute: async (ctx: any) => {
|
|
64
|
+
const address = ctx.address || account.address;
|
|
65
|
+
console.log(` [check_balance] Checking real balance for ${address}`);
|
|
66
|
+
const balance = await publicClient.getBalance({ address });
|
|
67
|
+
ctx.balance = formatEther(balance);
|
|
68
|
+
ctx.address = address;
|
|
69
|
+
console.log(` [check_balance] Balance: ${ctx.balance} ETH`);
|
|
70
|
+
return ctx;
|
|
71
|
+
},
|
|
72
|
+
}],
|
|
73
|
+
entryNode: 'run',
|
|
74
|
+
});
|
|
75
|
+
return g;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function createRealEstimateGasTool() {
|
|
79
|
+
const g = new GraphFlow<any>({
|
|
80
|
+
name: 'estimate_gas',
|
|
81
|
+
context: { gas: 0, to: '', amount: '' },
|
|
82
|
+
schema: z.object({ gas: z.number(), to: z.string(), amount: z.string() }).passthrough(),
|
|
83
|
+
nodes: [{
|
|
84
|
+
name: 'run',
|
|
85
|
+
execute: async (ctx: any) => {
|
|
86
|
+
console.log(` [estimate_gas] Estimating gas for ${ctx.amount} ETH to ${ctx.to}`);
|
|
87
|
+
const gas = await publicClient.estimateGas({
|
|
88
|
+
account,
|
|
89
|
+
to: ctx.to,
|
|
90
|
+
value: parseEther(ctx.amount || '0.001'),
|
|
91
|
+
});
|
|
92
|
+
ctx.gas = Number(gas);
|
|
93
|
+
console.log(` [estimate_gas] Estimated gas: ${ctx.gas}`);
|
|
94
|
+
return ctx;
|
|
95
|
+
},
|
|
96
|
+
}],
|
|
97
|
+
entryNode: 'run',
|
|
98
|
+
});
|
|
99
|
+
return g;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function createRealSendEthTool() {
|
|
103
|
+
const g = new GraphFlow<any>({
|
|
104
|
+
name: 'send_eth',
|
|
105
|
+
context: { txHash: '', to: '', amount: '', balance: '' },
|
|
106
|
+
schema: z.object({ txHash: z.string(), to: z.string(), amount: z.string(), balance: z.string() }).passthrough(),
|
|
107
|
+
nodes: [{
|
|
108
|
+
name: 'run',
|
|
109
|
+
execute: async (ctx: any) => {
|
|
110
|
+
console.log(` [send_eth] Sending REAL ${ctx.amount} ETH to ${ctx.to}`);
|
|
111
|
+
const hash = await walletClient.sendTransaction({
|
|
112
|
+
to: ctx.to,
|
|
113
|
+
value: parseEther(ctx.amount || '0.001'),
|
|
114
|
+
});
|
|
115
|
+
ctx.txHash = hash;
|
|
116
|
+
console.log(` [send_eth] TX sent: ${hash}`);
|
|
117
|
+
console.log(` [send_eth] View: https://sepolia.etherscan.io/tx/${hash}`);
|
|
118
|
+
|
|
119
|
+
// Wait for confirmation
|
|
120
|
+
const receipt = await publicClient.waitForTransactionReceipt({ hash });
|
|
121
|
+
console.log(` [send_eth] Confirmed! Block: ${receipt.blockNumber}`);
|
|
122
|
+
return ctx;
|
|
123
|
+
},
|
|
124
|
+
}],
|
|
125
|
+
entryNode: 'run',
|
|
126
|
+
});
|
|
127
|
+
return g;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
describe('Plan → Compile → Execute (REAL Onchain + LLM)', function () {
|
|
131
|
+
this.timeout(120000); // Onchain + LLM calls take time
|
|
132
|
+
|
|
133
|
+
let registry: ToolRegistry;
|
|
134
|
+
|
|
135
|
+
beforeEach(() => {
|
|
136
|
+
registry = new ToolRegistry();
|
|
137
|
+
registry.register({
|
|
138
|
+
name: 'check_balance',
|
|
139
|
+
description: 'Check wallet ETH balance on Sepolia',
|
|
140
|
+
graph: createRealCheckBalanceTool(),
|
|
141
|
+
startNode: 'run',
|
|
142
|
+
});
|
|
143
|
+
registry.register({
|
|
144
|
+
name: 'estimate_gas',
|
|
145
|
+
description: 'Estimate gas for a transaction on Sepolia',
|
|
146
|
+
graph: createRealEstimateGasTool(),
|
|
147
|
+
startNode: 'run',
|
|
148
|
+
});
|
|
149
|
+
registry.register({
|
|
150
|
+
name: 'send_eth',
|
|
151
|
+
description: 'Send ETH to an address on Sepolia',
|
|
152
|
+
graph: createRealSendEthTool(),
|
|
153
|
+
startNode: 'run',
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
it('USE CASE 1 (REAL): Check balance + Send 0.001 ETH to another wallet', async () => {
|
|
158
|
+
console.log('\n=== USE CASE 1 (REAL): Send 0.001 ETH to STUDENT_2 ===\n');
|
|
159
|
+
|
|
160
|
+
const plan = await generatePlan(
|
|
161
|
+
`Check my balance, estimate gas, then send 0.001 ETH to ${env['STUDENT_2']}`,
|
|
162
|
+
registry,
|
|
163
|
+
callGroq
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
console.log('Generated plan:', JSON.stringify(plan, null, 2));
|
|
167
|
+
console.log('\n' + renderPlan(plan));
|
|
168
|
+
|
|
169
|
+
// Validate
|
|
170
|
+
const validated = PlanSchema.parse(plan);
|
|
171
|
+
expect(validated.steps).to.be.an('array').that.is.not.empty;
|
|
172
|
+
|
|
173
|
+
const validation = registry.validateSteps(validated.steps);
|
|
174
|
+
expect(validation.valid).to.be.true;
|
|
175
|
+
|
|
176
|
+
// Execute REAL onchain
|
|
177
|
+
const { graph, startNode } = compilePlan(plan, registry);
|
|
178
|
+
console.log(`\nExecuting REAL onchain plan from node: ${startNode}`);
|
|
179
|
+
|
|
180
|
+
const ctx = await graph.execute(startNode, {});
|
|
181
|
+
console.log('\nFinal context:', JSON.stringify(ctx, null, 2));
|
|
182
|
+
|
|
183
|
+
expect(ctx.txHash).to.be.a('string');
|
|
184
|
+
expect(ctx.txHash).to.include('0x');
|
|
185
|
+
console.log('\n✅ USE CASE 1 COMPLETED - REAL TX SENT!\n');
|
|
186
|
+
console.log(` TX: https://sepolia.etherscan.io/tx/${ctx.txHash}`);
|
|
187
|
+
});
|
|
188
|
+
|
|
189
|
+
it('USE CASE 2 (REAL): Just check balance', async () => {
|
|
190
|
+
console.log('\n=== USE CASE 2 (REAL): Check balance ===\n');
|
|
191
|
+
|
|
192
|
+
const plan = await generatePlan(
|
|
193
|
+
'Check my wallet balance on Sepolia',
|
|
194
|
+
registry,
|
|
195
|
+
callGroq
|
|
196
|
+
);
|
|
197
|
+
|
|
198
|
+
console.log('Generated plan:', JSON.stringify(plan, null, 2));
|
|
199
|
+
|
|
200
|
+
const { graph, startNode } = compilePlan(plan, registry);
|
|
201
|
+
const ctx = await graph.execute(startNode, {});
|
|
202
|
+
|
|
203
|
+
console.log('\nBalance:', ctx.balance, 'ETH');
|
|
204
|
+
expect(ctx.balance).to.be.a('string');
|
|
205
|
+
console.log('\n✅ USE CASE 2 COMPLETED\n');
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it('USE CASE 3 (REAL): Estimate gas without sending', async () => {
|
|
209
|
+
console.log('\n=== USE CASE 3 (REAL): Estimate gas ===\n');
|
|
210
|
+
|
|
211
|
+
const plan = await generatePlan(
|
|
212
|
+
`Estimate gas to send 0.001 ETH to ${env['STUDENT_3']}`,
|
|
213
|
+
registry,
|
|
214
|
+
callGroq
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
console.log('Generated plan:', JSON.stringify(plan, null, 2));
|
|
218
|
+
|
|
219
|
+
const { graph, startNode } = compilePlan(plan, registry);
|
|
220
|
+
const ctx = await graph.execute(startNode, {});
|
|
221
|
+
|
|
222
|
+
console.log('\nEstimated gas:', ctx.gas);
|
|
223
|
+
expect(ctx.gas).to.be.a('number').above(21000);
|
|
224
|
+
console.log('\n✅ USE CASE 3 COMPLETED\n');
|
|
225
|
+
});
|
|
226
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { GraphFlow } from "../../execution";
|
|
3
|
+
import { nodeRegistry } from "../../execution/registry";
|
|
4
|
+
import { ParallelNodeConfig } from "../../execution/types.parallel";
|
|
5
|
+
|
|
6
|
+
describe("Send API (Fan-out dynamique)", () => {
|
|
7
|
+
beforeEach(() => {
|
|
8
|
+
(nodeRegistry as any).executeFunctions.clear();
|
|
9
|
+
(nodeRegistry as any).nodeConfigs.clear();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("should fan-out to dynamic number of branches", async () => {
|
|
13
|
+
const items = ["item1", "item2", "item3"];
|
|
14
|
+
let processedCount = 0;
|
|
15
|
+
|
|
16
|
+
const nodes: ParallelNodeConfig<any>[] = [
|
|
17
|
+
{
|
|
18
|
+
name: "start",
|
|
19
|
+
execute: async (ctx: any) => {
|
|
20
|
+
ctx.processed = [];
|
|
21
|
+
},
|
|
22
|
+
send: (ctx: any) => {
|
|
23
|
+
return ctx.items.map((item: string, i: number) => ({
|
|
24
|
+
to: "processItem",
|
|
25
|
+
input: { currentItem: item, index: i },
|
|
26
|
+
branchId: `item_${i}`,
|
|
27
|
+
}));
|
|
28
|
+
},
|
|
29
|
+
parallel: { enabled: true, joinNode: "done" },
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "processItem",
|
|
33
|
+
execute: async (ctx: any) => {
|
|
34
|
+
ctx.processed.push(`Processed: ${ctx.currentItem}`);
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "done",
|
|
39
|
+
execute: async (ctx: any) => {
|
|
40
|
+
ctx.finished = true;
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
];
|
|
44
|
+
|
|
45
|
+
const graph = new GraphFlow({
|
|
46
|
+
name: "send-api-test",
|
|
47
|
+
schema: { parse: (ctx: any) => ctx } as any,
|
|
48
|
+
context: { items, processed: [] as string[] },
|
|
49
|
+
nodes: nodes,
|
|
50
|
+
entryNode: "start",
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
nodes.forEach(node => nodeRegistry.registerParallel(node));
|
|
54
|
+
|
|
55
|
+
const context = await graph.execute("start");
|
|
56
|
+
|
|
57
|
+
expect(context.processed).to.have.length(3);
|
|
58
|
+
expect(context.finished).to.be.true;
|
|
59
|
+
expect(context.processed[0]).to.include("item1");
|
|
60
|
+
expect(context.processed[1]).to.include("item2");
|
|
61
|
+
expect(context.processed[2]).to.include("item3");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should use reducers for state merge", async () => {
|
|
65
|
+
const nodes: ParallelNodeConfig<any>[] = [
|
|
66
|
+
{
|
|
67
|
+
name: "start",
|
|
68
|
+
execute: async (ctx: any) => {
|
|
69
|
+
ctx.results = [];
|
|
70
|
+
},
|
|
71
|
+
send: (ctx: any) => {
|
|
72
|
+
return [
|
|
73
|
+
{ to: "addOne", input: { value: "A" } },
|
|
74
|
+
{ to: "addTwo", input: { value: "B" } },
|
|
75
|
+
];
|
|
76
|
+
},
|
|
77
|
+
parallel: { enabled: true, joinNode: "merge" },
|
|
78
|
+
reducers: [
|
|
79
|
+
{
|
|
80
|
+
key: "results",
|
|
81
|
+
reducer: (acc: string[], val: string) => [...acc, val],
|
|
82
|
+
initial: [],
|
|
83
|
+
},
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
{
|
|
87
|
+
name: "addOne",
|
|
88
|
+
execute: async (ctx: any) => {
|
|
89
|
+
ctx.results.push(ctx.value);
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: "addTwo",
|
|
94
|
+
execute: async (ctx: any) => {
|
|
95
|
+
ctx.results.push(ctx.value);
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: "merge",
|
|
100
|
+
execute: async (ctx: any) => {
|
|
101
|
+
ctx.merged = true;
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
];
|
|
105
|
+
|
|
106
|
+
const graph = new GraphFlow({
|
|
107
|
+
name: "reducer-test",
|
|
108
|
+
schema: { parse: (ctx: any) => ctx } as any,
|
|
109
|
+
context: {} as any,
|
|
110
|
+
nodes: nodes,
|
|
111
|
+
entryNode: "start",
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
nodes.forEach(node => nodeRegistry.registerParallel(node));
|
|
115
|
+
|
|
116
|
+
const context = await graph.execute("start");
|
|
117
|
+
|
|
118
|
+
expect(context.results).to.have.length(2);
|
|
119
|
+
expect(context.merged).to.be.true;
|
|
120
|
+
});
|
|
121
|
+
});
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import { expect, use } from "chai";
|
|
2
|
+
import chaiAsPromised from "chai-as-promised";
|
|
3
|
+
import { runCLI, CLIConfig } from "../../../modules/cli/index";
|
|
4
|
+
import { Agent, Memory } from "../../../index";
|
|
5
|
+
import { InMemoryAdapter } from "../../../modules/memory/adapters/in-memory";
|
|
6
|
+
import { LLMProvider } from "../../../types/agent";
|
|
7
|
+
|
|
8
|
+
use(chaiAsPromised);
|
|
9
|
+
|
|
10
|
+
describe("CLI Module", function () {
|
|
11
|
+
describe("runCLI", function () {
|
|
12
|
+
it("should create an agent with ollama provider", async function () {
|
|
13
|
+
const config: CLIConfig = {
|
|
14
|
+
provider: "ollama" as LLMProvider,
|
|
15
|
+
model: "llama3.2:1b",
|
|
16
|
+
baseUrl: "http://localhost:11434",
|
|
17
|
+
role: "Test Assistant",
|
|
18
|
+
goal: "Test the CLI",
|
|
19
|
+
verbose: false,
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
const memory = new Memory(new InMemoryAdapter());
|
|
23
|
+
await memory.init();
|
|
24
|
+
|
|
25
|
+
const agent = new Agent({
|
|
26
|
+
role: config.role || "Helpful Assistant",
|
|
27
|
+
goal: config.goal || "Assist the user",
|
|
28
|
+
backstory: `You are a ${config.role || "assistant"}. Be concise.`,
|
|
29
|
+
tools: [],
|
|
30
|
+
llmConfig: {
|
|
31
|
+
provider: config.provider,
|
|
32
|
+
model: config.model,
|
|
33
|
+
baseUrl: config.baseUrl,
|
|
34
|
+
},
|
|
35
|
+
memory,
|
|
36
|
+
verbose: config.verbose,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
expect(agent).to.exist;
|
|
40
|
+
expect(agent.constructor.name).to.equal("Agent");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("should create an agent with openai provider", async function () {
|
|
44
|
+
const config: CLIConfig = {
|
|
45
|
+
provider: "openai" as LLMProvider,
|
|
46
|
+
model: "gpt-4o-mini",
|
|
47
|
+
apiKey: process.env.OPENAI_API_KEY || "test-key",
|
|
48
|
+
role: "OpenAI Assistant",
|
|
49
|
+
goal: "Test OpenAI provider",
|
|
50
|
+
verbose: false,
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
const memory = new Memory(new InMemoryAdapter());
|
|
54
|
+
await memory.init();
|
|
55
|
+
|
|
56
|
+
const agent = new Agent({
|
|
57
|
+
role: config.role!,
|
|
58
|
+
goal: config.goal!,
|
|
59
|
+
backstory: `You are a ${config.role}. Be concise.`,
|
|
60
|
+
tools: [],
|
|
61
|
+
llmConfig: {
|
|
62
|
+
provider: config.provider,
|
|
63
|
+
model: config.model,
|
|
64
|
+
apiKey: config.apiKey,
|
|
65
|
+
},
|
|
66
|
+
memory,
|
|
67
|
+
verbose: config.verbose,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
expect(agent).to.exist;
|
|
71
|
+
expect(agent.constructor.name).to.equal("Agent");
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it("should handle missing API key for OpenAI", function () {
|
|
75
|
+
const originalKey = process.env.OPENAI_API_KEY;
|
|
76
|
+
delete process.env.OPENAI_API_KEY;
|
|
77
|
+
|
|
78
|
+
const config: CLIConfig = {
|
|
79
|
+
provider: "openai" as LLMProvider,
|
|
80
|
+
model: "gpt-4o-mini",
|
|
81
|
+
role: "Test",
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
let errorThrown = false;
|
|
85
|
+
try {
|
|
86
|
+
if (!process.env.OPENAI_API_KEY && config.provider === "openai" && !config.apiKey) {
|
|
87
|
+
errorThrown = true;
|
|
88
|
+
}
|
|
89
|
+
} finally {
|
|
90
|
+
if (originalKey) {
|
|
91
|
+
process.env.OPENAI_API_KEY = originalKey;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
expect(errorThrown).to.be.true;
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe("CLIConfig interface", function () {
|
|
100
|
+
it("should accept valid provider types", function () {
|
|
101
|
+
const providers: LLMProvider[] = ["openai", "anthropic", "ollama", "custom"];
|
|
102
|
+
|
|
103
|
+
providers.forEach((provider) => {
|
|
104
|
+
const config: CLIConfig = {
|
|
105
|
+
provider,
|
|
106
|
+
model: "test-model",
|
|
107
|
+
};
|
|
108
|
+
expect(config.provider).to.equal(provider);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it("should have optional fields", function () {
|
|
113
|
+
const config: CLIConfig = {
|
|
114
|
+
provider: "ollama" as LLMProvider,
|
|
115
|
+
model: "test-model",
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
expect(config.apiKey).to.be.undefined;
|
|
119
|
+
expect(config.baseUrl).to.be.undefined;
|
|
120
|
+
expect(config.role).to.be.undefined;
|
|
121
|
+
expect(config.goal).to.be.undefined;
|
|
122
|
+
expect(config.verbose).to.be.undefined;
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
});
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { EventEmitter } from "events";
|
|
3
|
+
import { Neo4jExecutionTracer } from "../../persistence/neo4j/execution-tracer";
|
|
4
|
+
|
|
5
|
+
class MockSession {
|
|
6
|
+
queries: { query: string; params: any }[] = [];
|
|
7
|
+
records: any[] = [];
|
|
8
|
+
async run(query: string, params?: Record<string, any>): Promise<{ records: any[] }> {
|
|
9
|
+
this.queries.push({ query, params });
|
|
10
|
+
return { records: this.records };
|
|
11
|
+
}
|
|
12
|
+
async close(): Promise<void> {}
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
class MockDriver {
|
|
16
|
+
lastSession?: MockSession;
|
|
17
|
+
session() {
|
|
18
|
+
this.lastSession = new MockSession();
|
|
19
|
+
return this.lastSession;
|
|
20
|
+
}
|
|
21
|
+
async close() {}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
class MockGraph extends EventEmitter {}
|
|
25
|
+
|
|
26
|
+
describe("Neo4jExecutionTracer", () => {
|
|
27
|
+
let driver: MockDriver;
|
|
28
|
+
let graph: MockGraph;
|
|
29
|
+
let tracer: Neo4jExecutionTracer;
|
|
30
|
+
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
driver = new MockDriver();
|
|
33
|
+
graph = new MockGraph();
|
|
34
|
+
tracer = Neo4jExecutionTracer.attach(graph as any, driver as any, "exec-1");
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
afterEach(() => {
|
|
38
|
+
tracer.detach();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("should initialize execution", async () => {
|
|
42
|
+
await tracer.initExecution("my-graph");
|
|
43
|
+
expect(driver.lastSession?.queries.length).to.equal(1);
|
|
44
|
+
expect(driver.lastSession?.queries[0].query).to.include("MERGE (e:Execution {id: $id})");
|
|
45
|
+
expect(driver.lastSession?.queries[0].params.graphName).to.equal("my-graph");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("should complete execution", async () => {
|
|
49
|
+
await tracer.completeExecution("completed");
|
|
50
|
+
expect(driver.lastSession?.queries.length).to.equal(1);
|
|
51
|
+
expect(driver.lastSession?.queries[0].query).to.include("SET e.status = $status");
|
|
52
|
+
expect(driver.lastSession?.queries[0].params.status).to.equal("completed");
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it("should trace node started event", async () => {
|
|
56
|
+
// We mock driver session explicitly before emitting
|
|
57
|
+
const mockSession = new MockSession();
|
|
58
|
+
driver.session = () => { driver.lastSession = mockSession; return mockSession; };
|
|
59
|
+
|
|
60
|
+
graph.emit("nodeStarted", { name: "node-1" });
|
|
61
|
+
|
|
62
|
+
// give time for async handler
|
|
63
|
+
await new Promise(r => setTimeout(r, 10));
|
|
64
|
+
|
|
65
|
+
expect(mockSession.queries.length).to.equal(1);
|
|
66
|
+
expect(mockSession.queries[0].query).to.include("MERGE (n:NodeRun {id: $nodeRunId})");
|
|
67
|
+
expect(mockSession.queries[0].params.name).to.equal("node-1");
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("should trace node completed event", async () => {
|
|
71
|
+
const mockSession = new MockSession();
|
|
72
|
+
driver.session = () => { driver.lastSession = mockSession; return mockSession; };
|
|
73
|
+
|
|
74
|
+
graph.emit("nodeCompleted", { name: "node-1" });
|
|
75
|
+
|
|
76
|
+
await new Promise(r => setTimeout(r, 10));
|
|
77
|
+
|
|
78
|
+
expect(mockSession.queries.length).to.equal(1);
|
|
79
|
+
expect(mockSession.queries[0].query).to.include("SET n.status = \"completed\"");
|
|
80
|
+
expect(mockSession.queries[0].params.nodeRunId).to.equal("exec-1-node-1");
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("should trace node error event", async () => {
|
|
84
|
+
const mockSession = new MockSession();
|
|
85
|
+
driver.session = () => { driver.lastSession = mockSession; return mockSession; };
|
|
86
|
+
|
|
87
|
+
graph.emit("nodeError", { payload: { name: "node-2", error: new Error("Test err") } });
|
|
88
|
+
|
|
89
|
+
await new Promise(r => setTimeout(r, 10));
|
|
90
|
+
|
|
91
|
+
expect(mockSession.queries.length).to.equal(1);
|
|
92
|
+
expect(mockSession.queries[0].query).to.include("SET n.status = \"error\"");
|
|
93
|
+
expect(mockSession.queries[0].params.nodeRunId).to.equal("exec-1-node-2");
|
|
94
|
+
expect(mockSession.queries[0].params.error).to.equal("Test err");
|
|
95
|
+
});
|
|
96
|
+
});
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { Neo4jMemoryAdapter } from "../../persistence/neo4j/memory-adapter";
|
|
3
|
+
|
|
4
|
+
class MockSession {
|
|
5
|
+
queries: { query: string; params: any }[] = [];
|
|
6
|
+
records: any[] = [];
|
|
7
|
+
shouldFail: boolean = false;
|
|
8
|
+
|
|
9
|
+
async run(query: string, params?: Record<string, any>): Promise<{ records: any[] }> {
|
|
10
|
+
this.queries.push({ query, params });
|
|
11
|
+
if (this.shouldFail) throw new Error("Mocked failure");
|
|
12
|
+
return { records: this.records };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
async close(): Promise<void> {}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
class MockDriver {
|
|
19
|
+
lastSession?: MockSession;
|
|
20
|
+
session(config?: { database?: string }) {
|
|
21
|
+
this.lastSession = new MockSession();
|
|
22
|
+
return this.lastSession;
|
|
23
|
+
}
|
|
24
|
+
async close() {}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe("Neo4jMemoryAdapter", () => {
|
|
28
|
+
let driver: MockDriver;
|
|
29
|
+
let adapter: Neo4jMemoryAdapter;
|
|
30
|
+
|
|
31
|
+
beforeEach(() => {
|
|
32
|
+
driver = new MockDriver();
|
|
33
|
+
adapter = new Neo4jMemoryAdapter(driver as any);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("should initialize and create a room", async () => {
|
|
37
|
+
await adapter.init("room1");
|
|
38
|
+
expect(driver.lastSession?.queries.length).to.equal(1);
|
|
39
|
+
expect(driver.lastSession?.queries[0].query).to.include("MERGE (:Room {id: $roomId})");
|
|
40
|
+
expect(driver.lastSession?.queries[0].params.roomId).to.equal("room1");
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("should create memory without embedding", async () => {
|
|
44
|
+
const memory = await adapter.createMemory({
|
|
45
|
+
id: "mem1",
|
|
46
|
+
content: "hello",
|
|
47
|
+
roomId: "room1",
|
|
48
|
+
metadata: { source: "test" }
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
expect(memory?.id).to.equal("mem1");
|
|
52
|
+
expect(driver.lastSession?.queries.length).to.equal(1);
|
|
53
|
+
expect(driver.lastSession?.queries[0].query).to.include("CREATE (m:Memory");
|
|
54
|
+
expect(driver.lastSession?.queries[0].params.roomId).to.equal("room1");
|
|
55
|
+
expect(driver.lastSession?.queries[0].params.metadata).to.equal('{"source":"test"}');
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("should create memory with embedding", async () => {
|
|
59
|
+
const memory = await adapter.createMemory({
|
|
60
|
+
id: "mem2",
|
|
61
|
+
content: "hello",
|
|
62
|
+
roomId: "room1",
|
|
63
|
+
embedding: [0.1, 0.2]
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
expect(memory?.embedding).to.deep.equal([0.1, 0.2]);
|
|
67
|
+
expect(driver.lastSession?.queries.length).to.equal(2);
|
|
68
|
+
expect(driver.lastSession?.queries[1].query).to.include("SET m.embedding = $embedding");
|
|
69
|
+
expect(driver.lastSession?.queries[1].params.embedding).to.deep.equal([0.1, 0.2]);
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("should get memory by ID", async () => {
|
|
73
|
+
if (driver.lastSession) {
|
|
74
|
+
driver.lastSession.records = [{
|
|
75
|
+
get: () => ({ properties: { id: "mem1", content: "hello", roomId: "room1", createdAt: new Date().toISOString() } })
|
|
76
|
+
}];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Workaround to prepopulate session for the next call
|
|
80
|
+
const mockSession = new MockSession();
|
|
81
|
+
mockSession.records = [{
|
|
82
|
+
get: () => ({ properties: { id: "mem1", content: "hello", roomId: "room1", createdAt: new Date().toISOString() } })
|
|
83
|
+
}];
|
|
84
|
+
driver.session = () => mockSession;
|
|
85
|
+
|
|
86
|
+
const memory = await adapter.getMemoryById("mem1", "room1");
|
|
87
|
+
expect(memory?.content).to.equal("hello");
|
|
88
|
+
expect(mockSession.queries.length).to.equal(1);
|
|
89
|
+
expect(mockSession.queries[0].query).to.include("MATCH (m:Memory {id: $id})-[:IN_ROOM]->(:Room {id: $roomId})");
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("should add relation", async () => {
|
|
93
|
+
await adapter.addRelation({
|
|
94
|
+
fromId: "m1",
|
|
95
|
+
toId: "m2",
|
|
96
|
+
type: "SIMILAR",
|
|
97
|
+
roomId: "room1",
|
|
98
|
+
properties: { weight: 0.8 }
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
expect(driver.lastSession?.queries.length).to.equal(1);
|
|
102
|
+
expect(driver.lastSession?.queries[0].query).to.include("MERGE (from)-[r:RELATES_TO {type: $type}]->(to)");
|
|
103
|
+
expect(driver.lastSession?.queries[0].params.fromId).to.equal("m1");
|
|
104
|
+
expect(driver.lastSession?.queries[0].params.toId).to.equal("m2");
|
|
105
|
+
expect(driver.lastSession?.queries[0].params.weight).to.equal(0.8);
|
|
106
|
+
});
|
|
107
|
+
});
|