@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
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { expect } from "chai";
|
|
2
2
|
import { z } from "zod";
|
|
3
|
-
import { GraphController } from "../../
|
|
4
|
-
import { GraphFlow } from "../../
|
|
3
|
+
import { GraphController } from "../../execution/controller";
|
|
4
|
+
import { GraphFlow } from "../../execution/index";
|
|
5
5
|
import { GraphContext, GraphNodeConfig } from "../../types";
|
|
6
6
|
|
|
7
7
|
describe("GraphController", () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { expect } from "chai";
|
|
2
2
|
import { EventEmitter } from "events";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import { GraphEventManager } from "../../
|
|
4
|
+
import { GraphEventManager } from "../../execution/event-manager";
|
|
5
5
|
|
|
6
6
|
describe("GraphEventManager", () => {
|
|
7
7
|
const TestSchema = z.object({
|
|
@@ -3,8 +3,8 @@ import chaiAsPromised from "chai-as-promised";
|
|
|
3
3
|
import EventEmitter from "events";
|
|
4
4
|
import sinon from "sinon";
|
|
5
5
|
import { z } from "zod";
|
|
6
|
-
import { GraphController } from "../../
|
|
7
|
-
import { GraphFlow } from "../../
|
|
6
|
+
import { GraphController } from "../../execution/controller";
|
|
7
|
+
import { GraphFlow } from "../../execution/index";
|
|
8
8
|
import { GraphConfig, GraphContext, GraphNodeConfig } from "../../types";
|
|
9
9
|
|
|
10
10
|
use(chaiAsPromised);
|
|
@@ -54,7 +54,7 @@ describe("GraphFlow", function () {
|
|
|
54
54
|
name: "TestGraph",
|
|
55
55
|
schema: TestSchema,
|
|
56
56
|
nodes: [],
|
|
57
|
-
context: { value: 0 },
|
|
57
|
+
context: { value: 0, counter: 0, message: "" },
|
|
58
58
|
eventEmitter: eventEmitter,
|
|
59
59
|
});
|
|
60
60
|
});
|
|
@@ -166,7 +166,10 @@ describe("GraphFlow", function () {
|
|
|
166
166
|
await graph.execute("simpleNode", invalidContext as any);
|
|
167
167
|
expect.fail("Should have thrown an error");
|
|
168
168
|
} catch (error: any) {
|
|
169
|
-
|
|
169
|
+
// Zod v4 changed validation error wording
|
|
170
|
+
expect(error.message).to.satisfy(
|
|
171
|
+
(msg: string) => msg.includes("Expected number") || msg.includes("Invalid input")
|
|
172
|
+
);
|
|
170
173
|
}
|
|
171
174
|
});
|
|
172
175
|
|
|
@@ -251,7 +254,7 @@ describe("GraphFlow", function () {
|
|
|
251
254
|
const graph = new GraphFlow({
|
|
252
255
|
name: "retryGraph",
|
|
253
256
|
schema: TestSchema,
|
|
254
|
-
context: { value: 0 },
|
|
257
|
+
context: { value: 0, counter: 0, message: "" },
|
|
255
258
|
nodes: [retryNode],
|
|
256
259
|
});
|
|
257
260
|
|
|
@@ -291,7 +294,7 @@ describe("GraphFlow", function () {
|
|
|
291
294
|
name: "TestGraph",
|
|
292
295
|
schema: TestSchema,
|
|
293
296
|
nodes: [nodeA, nodeB],
|
|
294
|
-
context: { value: 0 },
|
|
297
|
+
context: { value: 0, counter: 0, message: "" },
|
|
295
298
|
entryNode: "A",
|
|
296
299
|
};
|
|
297
300
|
|
|
@@ -322,8 +325,11 @@ describe("GraphFlow", function () {
|
|
|
322
325
|
await graph.execute("test", { value: -1 });
|
|
323
326
|
expect.fail("Should have thrown an error");
|
|
324
327
|
} catch (error: any) {
|
|
325
|
-
|
|
326
|
-
|
|
328
|
+
// Zod v4 changed validation error wording
|
|
329
|
+
expect(error.message).to.satisfy(
|
|
330
|
+
(msg: string) =>
|
|
331
|
+
msg.includes("Number must be greater than or equal to 0") ||
|
|
332
|
+
msg.includes("Too small")
|
|
327
333
|
);
|
|
328
334
|
}
|
|
329
335
|
});
|
|
@@ -388,7 +394,7 @@ describe("GraphFlow", function () {
|
|
|
388
394
|
const newContext = { ...context, value: -1 };
|
|
389
395
|
const validationResult = TestSchema.safeParse(newContext);
|
|
390
396
|
if (!validationResult.success) {
|
|
391
|
-
throw new Error(validationResult.error.
|
|
397
|
+
throw new Error(validationResult.error.issues[0].message);
|
|
392
398
|
}
|
|
393
399
|
graph["context"] = newContext;
|
|
394
400
|
},
|
|
@@ -401,8 +407,11 @@ describe("GraphFlow", function () {
|
|
|
401
407
|
await graph.execute("validationNode");
|
|
402
408
|
throw new Error("Should have thrown an error");
|
|
403
409
|
} catch (error: any) {
|
|
404
|
-
|
|
405
|
-
|
|
410
|
+
// Zod v4 changed validation error wording
|
|
411
|
+
expect(error.message).to.satisfy(
|
|
412
|
+
(msg: string) =>
|
|
413
|
+
msg.includes("Number must be greater than or equal to 0") ||
|
|
414
|
+
msg.includes("Too small")
|
|
406
415
|
);
|
|
407
416
|
}
|
|
408
417
|
});
|
|
@@ -497,7 +506,7 @@ describe("GraphFlow", function () {
|
|
|
497
506
|
const graph1 = new GraphFlow({
|
|
498
507
|
name: "Graph1",
|
|
499
508
|
schema: TestSchema,
|
|
500
|
-
context: { value: 0 },
|
|
509
|
+
context: { value: 0, counter: 0, message: "" },
|
|
501
510
|
nodes: [],
|
|
502
511
|
});
|
|
503
512
|
|
|
@@ -520,7 +529,7 @@ describe("GraphFlow", function () {
|
|
|
520
529
|
const graph2 = new GraphFlow({
|
|
521
530
|
name: "Graph2",
|
|
522
531
|
schema: TestSchema,
|
|
523
|
-
context: { value: 0 },
|
|
532
|
+
context: { value: 0, counter: 0, message: "" },
|
|
524
533
|
nodes: [],
|
|
525
534
|
});
|
|
526
535
|
|
|
@@ -563,7 +572,7 @@ describe("GraphFlow", function () {
|
|
|
563
572
|
const graph1 = new GraphFlow({
|
|
564
573
|
name: "Graph1",
|
|
565
574
|
schema: TestSchema,
|
|
566
|
-
context: { value: 1 },
|
|
575
|
+
context: { value: 1, counter: 0, message: "" },
|
|
567
576
|
nodes: [],
|
|
568
577
|
});
|
|
569
578
|
|
|
@@ -578,7 +587,7 @@ describe("GraphFlow", function () {
|
|
|
578
587
|
const graph2 = new GraphFlow({
|
|
579
588
|
name: "Graph2",
|
|
580
589
|
schema: TestSchema,
|
|
581
|
-
context: { value: 3 },
|
|
590
|
+
context: { value: 3, counter: 0, message: "" },
|
|
582
591
|
nodes: [],
|
|
583
592
|
});
|
|
584
593
|
|
|
@@ -3,9 +3,9 @@ import chaiAsPromised from "chai-as-promised";
|
|
|
3
3
|
import { EventEmitter } from "events";
|
|
4
4
|
import { BehaviorSubject, Subject } from "rxjs";
|
|
5
5
|
import { z } from "zod";
|
|
6
|
-
import { GraphEventManager } from "../../
|
|
7
|
-
import { GraphLogger } from "../../
|
|
8
|
-
import { GraphNode } from "../../
|
|
6
|
+
import { GraphEventManager } from "../../execution/event-manager";
|
|
7
|
+
import { GraphLogger } from "../../execution/logger";
|
|
8
|
+
import { GraphNode } from "../../execution/node";
|
|
9
9
|
import { IEventEmitter } from "../../interfaces";
|
|
10
10
|
import { GraphContext } from "../../types";
|
|
11
11
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { expect } from "chai";
|
|
2
2
|
import { BehaviorSubject, Subject } from "rxjs";
|
|
3
3
|
import { z } from "zod";
|
|
4
|
-
import { GraphFlow } from "../../
|
|
5
|
-
import { GraphObserver } from "../../
|
|
4
|
+
import { GraphFlow } from "../../execution";
|
|
5
|
+
import { GraphObserver } from "../../execution/observer";
|
|
6
6
|
import { GraphContext, GraphEvent, GraphNodeConfig } from "../../types";
|
|
7
7
|
|
|
8
8
|
/**
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { GraphFlow } from "../../execution";
|
|
3
|
+
import { nodeRegistry } from "../../execution/registry";
|
|
4
|
+
import { ParallelNodeConfig } from "../../execution/types.parallel";
|
|
5
|
+
import { GraphContext } from "../../types";
|
|
6
|
+
|
|
7
|
+
describe("Fork-Join Parallelism", () => {
|
|
8
|
+
beforeEach(() => {
|
|
9
|
+
// Nettoyer le registry avant chaque test
|
|
10
|
+
(nodeRegistry as any).executeFunctions.clear();
|
|
11
|
+
(nodeRegistry as any).nodeConfigs.clear();
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
it("should execute branches in parallel with Promise.all", async () => {
|
|
15
|
+
const executionTimes: number[] = [];
|
|
16
|
+
const startTime = Date.now();
|
|
17
|
+
|
|
18
|
+
const nodes: ParallelNodeConfig<any>[] = [
|
|
19
|
+
{
|
|
20
|
+
name: "A",
|
|
21
|
+
execute: async (ctx: any) => {
|
|
22
|
+
ctx.value = 1;
|
|
23
|
+
},
|
|
24
|
+
parallel: { enabled: true, joinNode: "C" },
|
|
25
|
+
next: ["B1", "B2", "B3"],
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
name: "B1",
|
|
29
|
+
execute: async (ctx: any) => {
|
|
30
|
+
const start = Date.now();
|
|
31
|
+
await new Promise(r => setTimeout(r, 100));
|
|
32
|
+
executionTimes.push(Date.now() - start);
|
|
33
|
+
ctx.results = [...(ctx.results || []), "B1"];
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
name: "B2",
|
|
38
|
+
execute: async (ctx: any) => {
|
|
39
|
+
const start = Date.now();
|
|
40
|
+
await new Promise(r => setTimeout(r, 50));
|
|
41
|
+
executionTimes.push(Date.now() - start);
|
|
42
|
+
ctx.results = [...(ctx.results || []), "B2"];
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "B3",
|
|
47
|
+
execute: async (ctx: any) => {
|
|
48
|
+
const start = Date.now();
|
|
49
|
+
await new Promise(r => setTimeout(r, 150));
|
|
50
|
+
executionTimes.push(Date.now() - start);
|
|
51
|
+
ctx.results = [...(ctx.results || []), "B3"];
|
|
52
|
+
},
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
name: "C",
|
|
56
|
+
execute: async (ctx: any) => {
|
|
57
|
+
ctx.value = 2;
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
];
|
|
61
|
+
|
|
62
|
+
const graph = new GraphFlow({
|
|
63
|
+
name: "fork-join-test",
|
|
64
|
+
schema: { parse: (ctx: any) => ctx } as any,
|
|
65
|
+
context: { value: 0, results: [] as string[] },
|
|
66
|
+
nodes: nodes,
|
|
67
|
+
entryNode: "A",
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
// Enregistrer les nodes
|
|
71
|
+
nodes.forEach(node => nodeRegistry.registerParallel(node));
|
|
72
|
+
|
|
73
|
+
const context = await graph.execute("A");
|
|
74
|
+
|
|
75
|
+
const totalTime = Date.now() - startTime;
|
|
76
|
+
|
|
77
|
+
expect(context.value).to.equal(2);
|
|
78
|
+
expect(context.results).to.have.length(3);
|
|
79
|
+
expect(context.results).to.include("B1");
|
|
80
|
+
expect(context.results).to.include("B2");
|
|
81
|
+
expect(context.results).to.include("B3");
|
|
82
|
+
|
|
83
|
+
// Le temps total devrait être proche du max(100, 50, 150) = 150ms
|
|
84
|
+
// et non 100+50+150 = 300ms (séquentiel)
|
|
85
|
+
expect(totalTime).to.be.lessThan(250); // Marge de manœuvre
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("should merge contexts with deep-merge by default", async () => {
|
|
89
|
+
const nodes: ParallelNodeConfig<any>[] = [
|
|
90
|
+
{
|
|
91
|
+
name: "start",
|
|
92
|
+
execute: async (ctx: any) => {
|
|
93
|
+
ctx.base = "base";
|
|
94
|
+
},
|
|
95
|
+
parallel: { enabled: true, joinNode: "merge" },
|
|
96
|
+
next: ["branch1", "branch2"],
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: "branch1",
|
|
100
|
+
execute: async (ctx: any) => {
|
|
101
|
+
ctx.fromBranch1 = "value1";
|
|
102
|
+
},
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
name: "branch2",
|
|
106
|
+
execute: async (ctx: any) => {
|
|
107
|
+
ctx.fromBranch2 = "value2";
|
|
108
|
+
},
|
|
109
|
+
},
|
|
110
|
+
{
|
|
111
|
+
name: "merge",
|
|
112
|
+
execute: async (ctx: any) => {
|
|
113
|
+
ctx.merged = true;
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
];
|
|
117
|
+
|
|
118
|
+
const graph = new GraphFlow({
|
|
119
|
+
name: "merge-test",
|
|
120
|
+
schema: { parse: (ctx: any) => ctx } as any,
|
|
121
|
+
context: {} as any,
|
|
122
|
+
nodes: nodes,
|
|
123
|
+
entryNode: "start",
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
nodes.forEach(node => nodeRegistry.registerParallel(node));
|
|
127
|
+
|
|
128
|
+
const context = await graph.execute("start");
|
|
129
|
+
|
|
130
|
+
expect(context.base).to.equal("base");
|
|
131
|
+
expect(context.fromBranch1).to.equal("value1");
|
|
132
|
+
expect(context.fromBranch2).to.equal("value2");
|
|
133
|
+
expect(context.merged).to.be.true;
|
|
134
|
+
});
|
|
135
|
+
});
|
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { GraphFlow } from '../../execution/index';
|
|
4
|
+
import { ToolRegistry } from '../../execution/registry';
|
|
5
|
+
import { generatePlan, PlanSchema, renderPlan } from '../../execution/planner';
|
|
6
|
+
import { compilePlan } from '../../execution/compiler';
|
|
7
|
+
|
|
8
|
+
// Read .env manually
|
|
9
|
+
function loadEnv(): Record<string, string> {
|
|
10
|
+
try {
|
|
11
|
+
const fs = require('fs');
|
|
12
|
+
const content = fs.readFileSync('.env', 'utf-8');
|
|
13
|
+
const env: Record<string, string> = {};
|
|
14
|
+
content.split('\n').forEach((line: string) => {
|
|
15
|
+
const idx = line.indexOf('=');
|
|
16
|
+
if (idx > 0) env[line.slice(0, idx).trim()] = line.slice(idx + 1).trim();
|
|
17
|
+
});
|
|
18
|
+
return env;
|
|
19
|
+
} catch {
|
|
20
|
+
return {};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Real LLM call via Groq
|
|
25
|
+
async function callGroq(prompt: string): Promise<string> {
|
|
26
|
+
const env = loadEnv();
|
|
27
|
+
const apiKey = env['GROQ_API_KEY'];
|
|
28
|
+
if (!apiKey) throw new Error('GROQ_API_KEY not found in .env');
|
|
29
|
+
|
|
30
|
+
const response = await fetch('https://api.groq.com/openai/v1/chat/completions', {
|
|
31
|
+
method: 'POST',
|
|
32
|
+
headers: {
|
|
33
|
+
'Content-Type': 'application/json',
|
|
34
|
+
'Authorization': `Bearer ${apiKey}`,
|
|
35
|
+
},
|
|
36
|
+
body: JSON.stringify({
|
|
37
|
+
model: 'llama-3.1-8b-instant',
|
|
38
|
+
messages: [
|
|
39
|
+
{ role: 'system', content: 'You are a workflow planner. Output valid JSON only.' },
|
|
40
|
+
{ role: 'user', content: prompt },
|
|
41
|
+
],
|
|
42
|
+
temperature: 0.1,
|
|
43
|
+
response_format: { type: 'json_object' },
|
|
44
|
+
}),
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (!response.ok) {
|
|
48
|
+
const err = await response.text();
|
|
49
|
+
throw new Error(`Groq API error: ${err}`);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const data = await response.json();
|
|
53
|
+
return data.choices[0].message.content;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// Real onchain tools using GraphFlow
|
|
57
|
+
function createCheckBalanceTool() {
|
|
58
|
+
const g = new GraphFlow<any>({
|
|
59
|
+
name: 'check_balance',
|
|
60
|
+
context: { balance: 0, address: '' },
|
|
61
|
+
schema: z.object({ balance: z.number(), address: z.string() }).passthrough(),
|
|
62
|
+
nodes: [{
|
|
63
|
+
name: 'run',
|
|
64
|
+
execute: async (ctx: any) => {
|
|
65
|
+
console.log(` [check_balance] Checking balance for ${ctx.address || 'default wallet'}`);
|
|
66
|
+
ctx.balance = 1.5; // Mock: 1.5 ETH
|
|
67
|
+
return ctx;
|
|
68
|
+
},
|
|
69
|
+
}],
|
|
70
|
+
entryNode: 'run',
|
|
71
|
+
});
|
|
72
|
+
return g;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function createEstimateGasTool() {
|
|
76
|
+
const g = new GraphFlow<any>({
|
|
77
|
+
name: 'estimate_gas',
|
|
78
|
+
context: { gas: 0, to: '', amount: '' },
|
|
79
|
+
schema: z.object({ gas: z.number(), to: z.union([z.string(), z.number()]), amount: z.union([z.string(), z.number()]) }).passthrough(),
|
|
80
|
+
nodes: [{
|
|
81
|
+
name: 'run',
|
|
82
|
+
execute: async (ctx: any) => {
|
|
83
|
+
console.log(` [estimate_gas] Estimating gas for ${ctx.amount} ETH to ${ctx.to}`);
|
|
84
|
+
ctx.gas = 21000;
|
|
85
|
+
return ctx;
|
|
86
|
+
},
|
|
87
|
+
}],
|
|
88
|
+
entryNode: 'run',
|
|
89
|
+
});
|
|
90
|
+
return g;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function createSendEthTool() {
|
|
94
|
+
const g = new GraphFlow<any>({
|
|
95
|
+
name: 'send_eth',
|
|
96
|
+
context: { txHash: '', to: '', amount: '' },
|
|
97
|
+
schema: z.object({ txHash: z.string(), to: z.union([z.string(), z.number()]), amount: z.union([z.string(), z.number()]) }).passthrough(),
|
|
98
|
+
nodes: [{
|
|
99
|
+
name: 'run',
|
|
100
|
+
execute: async (ctx: any) => {
|
|
101
|
+
console.log(` [send_eth] Sending ${ctx.amount} ETH to ${ctx.to}`);
|
|
102
|
+
ctx.txHash = '0xabc123...'; // Mock tx hash
|
|
103
|
+
return ctx;
|
|
104
|
+
},
|
|
105
|
+
}],
|
|
106
|
+
entryNode: 'run',
|
|
107
|
+
});
|
|
108
|
+
return g;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function createGetTokenPriceTool() {
|
|
112
|
+
const g = new GraphFlow<any>({
|
|
113
|
+
name: 'get_token_price',
|
|
114
|
+
context: { price: 0, symbol: '' },
|
|
115
|
+
schema: z.object({ price: z.number(), symbol: z.string() }).passthrough(),
|
|
116
|
+
nodes: [{
|
|
117
|
+
name: 'run',
|
|
118
|
+
execute: async (ctx: any) => {
|
|
119
|
+
console.log(` [get_token_price] Getting price for ${ctx.symbol}`);
|
|
120
|
+
ctx.price = 2500; // Mock: ETH price
|
|
121
|
+
return ctx;
|
|
122
|
+
},
|
|
123
|
+
}],
|
|
124
|
+
entryNode: 'run',
|
|
125
|
+
});
|
|
126
|
+
return g;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function createSwapTokensTool() {
|
|
130
|
+
const g = new GraphFlow<any>({
|
|
131
|
+
name: 'swap_tokens',
|
|
132
|
+
context: { swapHash: '', from: '', to: '', amount: '' },
|
|
133
|
+
schema: z.object({ swapHash: z.string(), from: z.string(), to: z.string(), amount: z.union([z.string(), z.number()]) }).passthrough(),
|
|
134
|
+
nodes: [{
|
|
135
|
+
name: 'run',
|
|
136
|
+
execute: async (ctx: any) => {
|
|
137
|
+
console.log(` [swap_tokens] Swapping ${ctx.amount} ${ctx.from} to ${ctx.to}`);
|
|
138
|
+
ctx.swapHash = '0xdef456...';
|
|
139
|
+
return ctx;
|
|
140
|
+
},
|
|
141
|
+
}],
|
|
142
|
+
entryNode: 'run',
|
|
143
|
+
});
|
|
144
|
+
return g;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
describe('Plan → Compile → Execute (Real LLM + Onchain Use Cases)', function () {
|
|
148
|
+
this.timeout(60000); // LLM calls can take time
|
|
149
|
+
|
|
150
|
+
let registry: ToolRegistry;
|
|
151
|
+
|
|
152
|
+
beforeEach(() => {
|
|
153
|
+
registry = new ToolRegistry();
|
|
154
|
+
registry.register({
|
|
155
|
+
name: 'check_balance',
|
|
156
|
+
description: 'Check wallet ETH balance',
|
|
157
|
+
graph: createCheckBalanceTool(),
|
|
158
|
+
startNode: 'run',
|
|
159
|
+
});
|
|
160
|
+
registry.register({
|
|
161
|
+
name: 'estimate_gas',
|
|
162
|
+
description: 'Estimate gas for a transaction',
|
|
163
|
+
graph: createEstimateGasTool(),
|
|
164
|
+
startNode: 'run',
|
|
165
|
+
});
|
|
166
|
+
registry.register({
|
|
167
|
+
name: 'send_eth',
|
|
168
|
+
description: 'Send ETH to an address',
|
|
169
|
+
graph: createSendEthTool(),
|
|
170
|
+
startNode: 'run',
|
|
171
|
+
});
|
|
172
|
+
registry.register({
|
|
173
|
+
name: 'get_token_price',
|
|
174
|
+
description: 'Get current token price',
|
|
175
|
+
graph: createGetTokenPriceTool(),
|
|
176
|
+
startNode: 'run',
|
|
177
|
+
});
|
|
178
|
+
registry.register({
|
|
179
|
+
name: 'swap_tokens',
|
|
180
|
+
description: 'Swap tokens on DEX',
|
|
181
|
+
graph: createSwapTokensTool(),
|
|
182
|
+
startNode: 'run',
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it('USE CASE 1: Send ETH - should generate a valid plan and execute it', async () => {
|
|
187
|
+
console.log('\n=== USE CASE 1: Send 0.5 ETH to an address ===\n');
|
|
188
|
+
|
|
189
|
+
const plan = await generatePlan(
|
|
190
|
+
'Check my balance, estimate gas, then send 0.5 ETH to 0x1234567890abcdef',
|
|
191
|
+
registry,
|
|
192
|
+
callGroq
|
|
193
|
+
);
|
|
194
|
+
|
|
195
|
+
console.log('Generated plan:', JSON.stringify(plan, null, 2));
|
|
196
|
+
console.log('\n' + renderPlan(plan));
|
|
197
|
+
|
|
198
|
+
// Validate plan
|
|
199
|
+
const validated = PlanSchema.parse(plan);
|
|
200
|
+
expect(validated.goal).to.be.a('string');
|
|
201
|
+
expect(validated.steps.length).to.be.at.least(2);
|
|
202
|
+
|
|
203
|
+
// Validate against registry
|
|
204
|
+
const validation = registry.validateSteps(validated.steps);
|
|
205
|
+
expect(validation.valid).to.be.true;
|
|
206
|
+
|
|
207
|
+
// Compile and execute
|
|
208
|
+
const { graph, startNode } = compilePlan(plan, registry);
|
|
209
|
+
console.log(`\nExecuting from node: ${startNode}`);
|
|
210
|
+
|
|
211
|
+
const ctx = await graph.execute(startNode, {});
|
|
212
|
+
console.log('\nFinal context:', JSON.stringify(ctx, null, 2));
|
|
213
|
+
|
|
214
|
+
expect(ctx).to.be.an('object');
|
|
215
|
+
console.log('\n✅ USE CASE 1 COMPLETED\n');
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it('USE CASE 2: Swap tokens - should generate a plan with price check', async () => {
|
|
219
|
+
console.log('\n=== USE CASE 2: Swap tokens with price check ===\n');
|
|
220
|
+
|
|
221
|
+
const plan = await generatePlan(
|
|
222
|
+
'Get ETH price, then swap 100 USDC to ETH',
|
|
223
|
+
registry,
|
|
224
|
+
callGroq
|
|
225
|
+
);
|
|
226
|
+
|
|
227
|
+
console.log('Generated plan:', JSON.stringify(plan, null, 2));
|
|
228
|
+
console.log('\n' + renderPlan(plan));
|
|
229
|
+
|
|
230
|
+
// Validate
|
|
231
|
+
const validated = PlanSchema.parse(plan);
|
|
232
|
+
expect(validated.steps).to.be.an('array').that.is.not.empty;
|
|
233
|
+
|
|
234
|
+
const validation = registry.validateSteps(validated.steps);
|
|
235
|
+
expect(validation.valid).to.be.true;
|
|
236
|
+
|
|
237
|
+
// Execute
|
|
238
|
+
const { graph, startNode } = compilePlan(plan, registry);
|
|
239
|
+
console.log(`\nExecuting from node: ${startNode}`);
|
|
240
|
+
|
|
241
|
+
const ctx = await graph.execute(startNode, {});
|
|
242
|
+
console.log('\nFinal context:', JSON.stringify(ctx, null, 2));
|
|
243
|
+
|
|
244
|
+
expect(ctx).to.be.an('object');
|
|
245
|
+
console.log('\n✅ USE CASE 2 COMPLETED\n');
|
|
246
|
+
});
|
|
247
|
+
|
|
248
|
+
it('USE CASE 3: Complex workflow - should handle multi-step onchain operations', async () => {
|
|
249
|
+
console.log('\n=== USE CASE 3: Complex workflow ===\n');
|
|
250
|
+
|
|
251
|
+
const plan = await generatePlan(
|
|
252
|
+
'Check balance, get ETH price, estimate gas, then send 0.1 ETH to 0xabc',
|
|
253
|
+
registry,
|
|
254
|
+
callGroq
|
|
255
|
+
);
|
|
256
|
+
|
|
257
|
+
console.log('Generated plan:', JSON.stringify(plan, null, 2));
|
|
258
|
+
console.log('\n' + renderPlan(plan));
|
|
259
|
+
|
|
260
|
+
// Validate
|
|
261
|
+
const validated = PlanSchema.parse(plan);
|
|
262
|
+
expect(validated.steps.length).to.be.at.least(3);
|
|
263
|
+
|
|
264
|
+
const validation = registry.validateSteps(validated.steps);
|
|
265
|
+
expect(validation.valid).to.be.true;
|
|
266
|
+
|
|
267
|
+
// Execute
|
|
268
|
+
const { graph, startNode } = compilePlan(plan, registry);
|
|
269
|
+
console.log(`\nExecuting from node: ${startNode}`);
|
|
270
|
+
|
|
271
|
+
const ctx = await graph.execute(startNode, {});
|
|
272
|
+
console.log('\nFinal context:', JSON.stringify(ctx, null, 2));
|
|
273
|
+
|
|
274
|
+
expect(ctx).to.be.an('object');
|
|
275
|
+
console.log('\n✅ USE CASE 3 COMPLETED\n');
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it('Should reject plans with unknown tools', async () => {
|
|
279
|
+
const plan = {
|
|
280
|
+
goal: 'Hack something',
|
|
281
|
+
steps: [
|
|
282
|
+
{ node: 'hack_the_planet', description: 'Unknown tool' },
|
|
283
|
+
],
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
const validation = registry.validateSteps(plan.steps);
|
|
287
|
+
expect(validation.valid).to.be.false;
|
|
288
|
+
expect(validation.errors[0]).to.include('hack_the_planet');
|
|
289
|
+
});
|
|
290
|
+
});
|