@ai.ntellect/core 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mocharc.json +6 -0
- package/AGENTS.md +50 -0
- package/ARCHITECTURE.md +58 -0
- package/BENCHMARK.md +38 -0
- package/CHANGELOG.md +224 -0
- package/README.md +363 -142
- package/agent/agent-workflow.ts +569 -0
- package/agent/agent.ts +183 -0
- package/agent/base/executor.ts +103 -0
- package/agent/base/index.ts +87 -0
- 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/agent/prompt-builder.ts +78 -0
- 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/agent/base/executor.d.ts +51 -0
- package/dist/agent/base/executor.d.ts.map +1 -0
- package/dist/agent/base/executor.js +69 -0
- package/dist/agent/base/executor.js.map +1 -0
- package/dist/agent/base/index.d.ts +30 -0
- package/dist/agent/base/index.d.ts.map +1 -0
- package/dist/agent/base/index.js +88 -0
- 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/agent/generic-executor.d.ts +68 -0
- 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 +19 -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/agent/prompt-builder.d.ts +35 -0
- package/dist/agent/prompt-builder.d.ts.map +1 -0
- package/dist/agent/prompt-builder.js +76 -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 +30 -0
- package/dist/execution/controller.d.ts.map +1 -0
- package/dist/execution/controller.js +80 -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/execution/event-manager.js +264 -0
- package/dist/execution/event-manager.js.map +1 -0
- package/dist/execution/index.d.ts +221 -0
- 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 +46 -0
- package/dist/execution/logger.d.ts.map +1 -0
- package/dist/execution/logger.js +69 -0
- package/dist/execution/logger.js.map +1 -0
- package/dist/execution/node.d.ts +65 -0
- package/dist/execution/node.d.ts.map +1 -0
- package/dist/execution/node.js +250 -0
- package/dist/execution/node.js.map +1 -0
- package/dist/execution/observer.d.ts +38 -0
- package/dist/execution/observer.d.ts.map +1 -0
- package/dist/execution/observer.js +111 -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 +35 -0
- package/dist/execution/visualizer.d.ts.map +1 -0
- package/dist/execution/visualizer.js +131 -0
- package/dist/execution/visualizer.js.map +1 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/index.d.ts +487 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/index.js +75 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/modules/agenda/adapters/node-cron/index.d.ts +17 -0
- package/dist/modules/agenda/adapters/node-cron/index.d.ts.map +1 -0
- package/dist/modules/agenda/adapters/node-cron/index.js +30 -0
- package/dist/modules/agenda/adapters/node-cron/index.js.map +1 -0
- package/dist/modules/agenda/index.d.ts +63 -0
- package/dist/modules/agenda/index.d.ts.map +1 -0
- package/dist/modules/agenda/index.js +141 -0
- package/dist/modules/agenda/index.js.map +1 -0
- 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/embedding/adapters/ai/index.d.ts +29 -0
- package/dist/modules/embedding/adapters/ai/index.d.ts.map +1 -0
- package/dist/modules/embedding/adapters/ai/index.js +58 -0
- package/dist/modules/embedding/adapters/ai/index.js.map +1 -0
- package/dist/modules/embedding/index.d.ts +36 -0
- package/dist/modules/embedding/index.d.ts.map +1 -0
- package/dist/modules/embedding/index.js +60 -0
- package/dist/modules/embedding/index.js.map +1 -0
- package/dist/modules/nlp/engine.d.ts +126 -0
- package/dist/modules/nlp/engine.d.ts.map +1 -0
- package/dist/modules/nlp/engine.js +299 -0
- package/dist/modules/nlp/engine.js.map +1 -0
- package/dist/modules/nlp/index.d.ts +27 -0
- package/dist/modules/nlp/index.d.ts.map +1 -0
- package/dist/modules/nlp/index.js +56 -0
- package/dist/modules/nlp/index.js.map +1 -0
- 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 +289 -0
- package/dist/types/agent.d.ts.map +1 -0
- package/dist/types/agent.js +78 -0
- package/dist/types/agent.js.map +1 -0
- package/dist/types/index.d.ts +343 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/generate-action-schema.d.ts +4 -0
- package/dist/utils/generate-action-schema.d.ts.map +1 -0
- package/dist/utils/generate-action-schema.js +46 -0
- package/dist/utils/generate-action-schema.js.map +1 -0
- package/dist/utils/header-builder.d.ts +12 -0
- package/dist/utils/header-builder.d.ts.map +1 -0
- package/dist/utils/header-builder.js +35 -0
- package/dist/utils/header-builder.js.map +1 -0
- 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/execution/controller.ts +84 -0
- package/execution/event-manager.ts +331 -0
- package/execution/index.ts +800 -0
- package/execution/logger.ts +70 -0
- package/execution/node.ts +315 -0
- package/execution/observer.ts +192 -0
- 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/execution/visualizer.ts +158 -0
- package/index.ts +55 -465
- package/interfaces/index.ts +597 -0
- package/modules/agenda/adapters/node-cron/index.ts +25 -0
- package/modules/agenda/index.ts +146 -0
- package/modules/cli/index.ts +580 -0
- package/modules/embedding/adapters/ai/index.ts +42 -0
- package/modules/embedding/index.ts +45 -0
- package/modules/nlp/engine.ts +324 -0
- package/modules/nlp/index.ts +45 -0
- package/package.json +81 -9
- 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/execution/controller.test.ts +236 -0
- package/test/execution/event-manager.test.ts +118 -0
- package/test/execution/index.test.ts +690 -0
- package/test/execution/node.test.ts +464 -0
- package/test/execution/observer.test.ts +393 -0
- 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/agenda/node-cron.test.ts +307 -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 +30 -108
- package/types/agent.ts +296 -0
- package/types/index.ts +387 -0
- package/utils/generate-action-schema.ts +47 -0
- package/utils/header-builder.ts +40 -0
- package/utils/logger.ts +40 -0
- package/package copy.json +0 -21
- package/types.ts +0 -62
- package/utils/executor.ts +0 -42
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { Neo4jPetriCheckpointAdapter } from "../../persistence/neo4j/petri-checkpoint-adapter";
|
|
3
|
+
import { PetriNet } from "../../routing/index";
|
|
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
|
+
describe("Neo4jPetriCheckpointAdapter", () => {
|
|
25
|
+
let driver: MockDriver;
|
|
26
|
+
let adapter: Neo4jPetriCheckpointAdapter;
|
|
27
|
+
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
driver = new MockDriver();
|
|
30
|
+
adapter = new Neo4jPetriCheckpointAdapter(driver as any);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("should save checkpoint", async () => {
|
|
34
|
+
const net = new PetriNet("test-net");
|
|
35
|
+
net.addPlace({ id: "p1", type: "normal", tokens: [] });
|
|
36
|
+
net.state.marking.set("p1", [{ id: "t1", data: {}, createdAt: Date.now() }]);
|
|
37
|
+
|
|
38
|
+
const session: any = { id: "session1", createdAt: Date.now() };
|
|
39
|
+
|
|
40
|
+
const cpId = await adapter.save(net as any, session);
|
|
41
|
+
|
|
42
|
+
expect(cpId).to.include("petri-cp-");
|
|
43
|
+
expect(driver.lastSession?.queries.length).to.equal(1);
|
|
44
|
+
expect(driver.lastSession?.queries[0].query).to.include("CREATE (c:Checkpoint {id: $checkpointId");
|
|
45
|
+
expect(driver.lastSession?.queries[0].params.sessionId).to.equal("session1");
|
|
46
|
+
expect(driver.lastSession?.queries[0].params.marking).to.include("p1");
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("should load checkpoint", async () => {
|
|
50
|
+
const mockSession = new MockSession();
|
|
51
|
+
mockSession.records = [{
|
|
52
|
+
get: (key: string) => {
|
|
53
|
+
if (key === "c") return { properties: { id: "cp1", marking: '[{"placeId":"p1","tokens":[{"id":"t1","data":{},"createdAt":123}]}]' } };
|
|
54
|
+
if (key === "sess") return { properties: { id: "session1", createdAt: 123 } };
|
|
55
|
+
}
|
|
56
|
+
}];
|
|
57
|
+
driver.session = () => mockSession;
|
|
58
|
+
|
|
59
|
+
const result = await adapter.load("cp1");
|
|
60
|
+
|
|
61
|
+
expect(result).to.not.be.null;
|
|
62
|
+
expect(result?.net.state.marking.has("p1")).to.be.true;
|
|
63
|
+
expect(result?.session?.id).to.equal("session1");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("should list checkpoints", async () => {
|
|
67
|
+
const mockSession = new MockSession();
|
|
68
|
+
mockSession.records = [{
|
|
69
|
+
get: (key: string) => {
|
|
70
|
+
if (key === "id") return "cp1";
|
|
71
|
+
if (key === "timestamp") return 123456;
|
|
72
|
+
if (key === "sessionId") return "session1";
|
|
73
|
+
}
|
|
74
|
+
}];
|
|
75
|
+
driver.session = () => mockSession;
|
|
76
|
+
|
|
77
|
+
const list = await adapter.list();
|
|
78
|
+
expect(list.length).to.equal(1);
|
|
79
|
+
expect(list[0].id).to.equal("cp1");
|
|
80
|
+
expect(list[0].timestamp).to.equal(123456);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("should delete checkpoint", async () => {
|
|
84
|
+
await adapter.delete("cp1");
|
|
85
|
+
expect(driver.lastSession?.queries.length).to.equal(1);
|
|
86
|
+
expect(driver.lastSession?.queries[0].query).to.include("DETACH DELETE c");
|
|
87
|
+
expect(driver.lastSession?.queries[0].params.checkpointId).to.equal("cp1");
|
|
88
|
+
});
|
|
89
|
+
});
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import sinon from "sinon";
|
|
3
|
+
import { AgentPipeline, Stage, PricePollingTrigger } from "../../pipeline/agent-pipeline";
|
|
4
|
+
import { InMemoryPetriCheckpointAdapter } from "../../routing/checkpoint-adapter";
|
|
5
|
+
|
|
6
|
+
describe("AgentPipeline", () => {
|
|
7
|
+
let pipeline: AgentPipeline;
|
|
8
|
+
let stages: Stage[];
|
|
9
|
+
let trigger: { type: string; start: sinon.SinonSpy; stop: sinon.SinonSpy };
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
stages = [
|
|
13
|
+
{
|
|
14
|
+
id: "fetch",
|
|
15
|
+
run: async (ctx: any) => ({ data: "fetched" }),
|
|
16
|
+
description: "Fetch data",
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
id: "process",
|
|
20
|
+
run: async (ctx: any) => ({ result: "processed" }),
|
|
21
|
+
description: "Process data",
|
|
22
|
+
},
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
trigger = { type: "test", start: sinon.spy(), stop: sinon.spy() };
|
|
26
|
+
|
|
27
|
+
pipeline = new AgentPipeline({
|
|
28
|
+
name: "test-pipeline",
|
|
29
|
+
stages,
|
|
30
|
+
trigger: trigger as any,
|
|
31
|
+
sessionId: "test-session",
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
afterEach(() => {
|
|
36
|
+
pipeline.stop();
|
|
37
|
+
sinon.restore();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe("constructor", () => {
|
|
41
|
+
it("should initialize with stages and session", () => {
|
|
42
|
+
expect(pipeline).to.exist;
|
|
43
|
+
expect(pipeline.getSessionId()).to.equal("test-session");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("should set up checkpoint adapter if provided", () => {
|
|
47
|
+
const checkpointAdapter = new InMemoryPetriCheckpointAdapter();
|
|
48
|
+
const pipelineWithCheckpoint = new AgentPipeline({
|
|
49
|
+
name: "test-pipeline",
|
|
50
|
+
stages,
|
|
51
|
+
trigger: trigger as any,
|
|
52
|
+
checkpointAdapter,
|
|
53
|
+
});
|
|
54
|
+
expect(pipelineWithCheckpoint).to.exist;
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
describe("trigger handling", () => {
|
|
59
|
+
it("should start trigger when pipeline starts", () => {
|
|
60
|
+
pipeline.start();
|
|
61
|
+
expect(trigger.start.calledOnce).to.be.true;
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should stop trigger when pipeline stops", () => {
|
|
65
|
+
pipeline.start();
|
|
66
|
+
pipeline.stop();
|
|
67
|
+
expect(trigger.stop.calledOnce).to.be.true;
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it("should use PricePollingTrigger correctly", (done) => {
|
|
71
|
+
const priceTrigger = new PricePollingTrigger("BTC", 50000, 60000, 100);
|
|
72
|
+
expect(priceTrigger.type).to.equal("price");
|
|
73
|
+
|
|
74
|
+
priceTrigger.start(async (data) => {
|
|
75
|
+
expect(data.asset).to.equal("BTC");
|
|
76
|
+
priceTrigger.stop();
|
|
77
|
+
done();
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
describe("events", () => {
|
|
83
|
+
it("should emit pipeline_started event", async () => {
|
|
84
|
+
let eventFired = false;
|
|
85
|
+
|
|
86
|
+
pipeline.on("pipeline_started", (data) => {
|
|
87
|
+
expect(data.sessionId).to.equal("test-session");
|
|
88
|
+
eventFired = true;
|
|
89
|
+
pipeline.stop();
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
await pipeline.start();
|
|
93
|
+
|
|
94
|
+
await new Promise(resolve => setTimeout(resolve, 50));
|
|
95
|
+
expect(eventFired).to.be.true;
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
describe("static resume", () => {
|
|
100
|
+
it("should have resume method", () => {
|
|
101
|
+
expect(AgentPipeline.resume).to.be.a("function");
|
|
102
|
+
});
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
describe("PricePollingTrigger", () => {
|
|
106
|
+
it("should expose pollMsValue getter", () => {
|
|
107
|
+
const trigger = new PricePollingTrigger("ETH", 2000, 3000, 5000);
|
|
108
|
+
expect(trigger.pollMsValue).to.equal(5000);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it("should stop timer on stop()", () => {
|
|
112
|
+
const priceTrigger = new PricePollingTrigger("BTC", 50000, 60000, 100);
|
|
113
|
+
priceTrigger.start(async () => {});
|
|
114
|
+
priceTrigger.stop();
|
|
115
|
+
expect(true).to.be.true;
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { PetriNet } from '../../routing/index';
|
|
2
|
+
import { CortexFlowOrchestrator } from '../../routing/orchestrator';
|
|
3
|
+
import { ToolRegistry } from '../../execution/registry';
|
|
4
|
+
import { InMemoryPetriCheckpointAdapter } from '../../routing/checkpoint-adapter';
|
|
5
|
+
|
|
6
|
+
async function testCheckpoint() {
|
|
7
|
+
console.log('🚀 Testing Petri Checkpoint Persistence...\n');
|
|
8
|
+
|
|
9
|
+
const toolRegistry = new ToolRegistry();
|
|
10
|
+
const orchestrator = new CortexFlowOrchestrator('test_net', toolRegistry);
|
|
11
|
+
|
|
12
|
+
// Setup Petri net
|
|
13
|
+
const net = orchestrator.petri;
|
|
14
|
+
net.addPlace({ id: 'idle', type: 'initial', tokens: [{ id: 'start', data: {}, createdAt: 0 }] });
|
|
15
|
+
net.addPlace({ id: 'processing', type: 'normal', tokens: [] });
|
|
16
|
+
net.addPlace({ id: 'done', type: 'final', tokens: [] });
|
|
17
|
+
|
|
18
|
+
net.addTransition({ id: 'process', from: ['idle'], to: 'processing' });
|
|
19
|
+
net.addTransition({ id: 'complete', from: ['processing'], to: 'done' });
|
|
20
|
+
|
|
21
|
+
// Set checkpoint adapter
|
|
22
|
+
const adapter = new InMemoryPetriCheckpointAdapter();
|
|
23
|
+
orchestrator.setPetriCheckpointAdapter(adapter);
|
|
24
|
+
|
|
25
|
+
// Start session
|
|
26
|
+
const sessionId = orchestrator.startSession();
|
|
27
|
+
console.log(`Session started: ${sessionId}`);
|
|
28
|
+
|
|
29
|
+
// Save initial state
|
|
30
|
+
const cpId1 = await orchestrator.savePetriState(sessionId);
|
|
31
|
+
console.log(`✅ Checkpoint 1 saved: ${cpId1}`);
|
|
32
|
+
|
|
33
|
+
// Fire a transition
|
|
34
|
+
const result = await orchestrator.fire('process', sessionId);
|
|
35
|
+
console.log(`✅ Transition "process" fired: ${result.success}`);
|
|
36
|
+
console.log(` Marking after fire: idle=${net.state.marking.get('idle')?.length}, processing=${net.state.marking.get('processing')?.length}`);
|
|
37
|
+
|
|
38
|
+
// Save state after transition
|
|
39
|
+
const cpId2 = await orchestrator.savePetriState(sessionId);
|
|
40
|
+
console.log(`✅ Checkpoint 2 saved: ${cpId2}`);
|
|
41
|
+
|
|
42
|
+
// List checkpoints
|
|
43
|
+
const checkpoints = await orchestrator.listPetriCheckpoints();
|
|
44
|
+
console.log(`✅ Found ${checkpoints.length} checkpoints`);
|
|
45
|
+
|
|
46
|
+
// Restore from checkpoint 1 (initial state)
|
|
47
|
+
const restoredSessionId = await orchestrator.restorePetriState(cpId1!);
|
|
48
|
+
if (restoredSessionId) {
|
|
49
|
+
const restoredSession = orchestrator.getSession(restoredSessionId);
|
|
50
|
+
const restoredNet = restoredSession!.petriNet;
|
|
51
|
+
console.log(`✅ Restored session: ${restoredSessionId}`);
|
|
52
|
+
console.log(` Marking after restore: idle=${restoredNet.state.marking.get('idle')?.length}, processing=${restoredNet.state.marking.get('processing')?.length}`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
console.log('\n✅ Petri Checkpoint Persistence test passed!\n');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
testCheckpoint().catch(console.error);
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import { PetriNet, Place, Transition } from '../../routing/index';
|
|
3
|
+
import { PetriDocumentationGenerator } from '../../routing/documentation-generator';
|
|
4
|
+
|
|
5
|
+
describe('Petri Documentation Generator', () => {
|
|
6
|
+
let net: PetriNet;
|
|
7
|
+
let generator: PetriDocumentationGenerator;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
net = new PetriNet('test-doc-net');
|
|
11
|
+
|
|
12
|
+
const idlePlace: Place = { id: 'idle', type: 'initial', tokens: [] };
|
|
13
|
+
const processingPlace: Place = { id: 'processing', type: 'normal', tokens: [] };
|
|
14
|
+
const donePlace: Place = { id: 'done', type: 'final', tokens: [] };
|
|
15
|
+
|
|
16
|
+
net.addPlace(idlePlace);
|
|
17
|
+
net.addPlace(processingPlace);
|
|
18
|
+
net.addPlace(donePlace);
|
|
19
|
+
|
|
20
|
+
const startTrans: Transition = {
|
|
21
|
+
id: 'start',
|
|
22
|
+
from: ['idle'],
|
|
23
|
+
to: ['processing'],
|
|
24
|
+
description: 'Start processing'
|
|
25
|
+
};
|
|
26
|
+
const completeTrans: Transition = {
|
|
27
|
+
id: 'complete',
|
|
28
|
+
from: ['processing'],
|
|
29
|
+
to: ['done'],
|
|
30
|
+
description: 'Complete task'
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
net.addTransition(startTrans);
|
|
34
|
+
net.addTransition(completeTrans);
|
|
35
|
+
|
|
36
|
+
// Use internal state to add tokens
|
|
37
|
+
const marking = (net as any).state.marking as Map<string, any[]>;
|
|
38
|
+
marking.set('idle', [{ id: 't1', data: { task: 'test' }, createdAt: Date.now() }]);
|
|
39
|
+
|
|
40
|
+
generator = new PetriDocumentationGenerator();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('should generate Mermaid diagram via public generateForPetri', async () => {
|
|
44
|
+
const outputDir = '/tmp/test-doc';
|
|
45
|
+
await generator.generateForPetri(net, { outputDir, format: 'markdown' });
|
|
46
|
+
|
|
47
|
+
// Read generated file
|
|
48
|
+
const fs = require('fs');
|
|
49
|
+
const files = fs.readdirSync(outputDir);
|
|
50
|
+
|
|
51
|
+
expect(files).to.include('test-doc-net.md');
|
|
52
|
+
expect(files).to.include('test-doc-net-diagram.mmd');
|
|
53
|
+
|
|
54
|
+
const markdown = fs.readFileSync(`${outputDir}/test-doc-net.md`, 'utf8');
|
|
55
|
+
expect(markdown).to.include('# Petri Net: test-doc-net');
|
|
56
|
+
expect(markdown).to.include('Start processing');
|
|
57
|
+
|
|
58
|
+
const mermaid = fs.readFileSync(`${outputDir}/test-doc-net-diagram.mmd`, 'utf8');
|
|
59
|
+
expect(mermaid).to.include('graph TD');
|
|
60
|
+
expect(mermaid).to.include('idle((idle');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('should generate HTML when format is all', async () => {
|
|
64
|
+
const outputDir = '/tmp/test-doc-html';
|
|
65
|
+
await generator.generateForPetri(net, { outputDir, format: 'all' });
|
|
66
|
+
|
|
67
|
+
const fs = require('fs');
|
|
68
|
+
const files = fs.readdirSync(outputDir);
|
|
69
|
+
|
|
70
|
+
expect(files).to.include('test-doc-net.html');
|
|
71
|
+
|
|
72
|
+
const html = fs.readFileSync(`${outputDir}/test-doc-net.html`, 'utf8');
|
|
73
|
+
expect(html).to.include('<!DOCTYPE html>');
|
|
74
|
+
expect(html).to.include('mermaid.initialize');
|
|
75
|
+
});
|
|
76
|
+
});
|
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import { describe, it, beforeEach } from 'mocha';
|
|
3
|
+
import { PetriNet, TransitionAction } from '../../routing/index';
|
|
4
|
+
import { CortexFlowOrchestrator } from '../../routing/orchestrator';
|
|
5
|
+
import { ToolRegistry } from '../../execution/registry';
|
|
6
|
+
import { GraphFlow } from '../../execution/index';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
|
|
9
|
+
describe('CortexFlow Integration - Mail Assistant', () => {
|
|
10
|
+
let orchestrator: CortexFlowOrchestrator;
|
|
11
|
+
let toolRegistry: ToolRegistry;
|
|
12
|
+
let net: PetriNet;
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
toolRegistry = new ToolRegistry();
|
|
16
|
+
orchestrator = new CortexFlowOrchestrator('mail_assistant', toolRegistry);
|
|
17
|
+
|
|
18
|
+
net = orchestrator.petri;
|
|
19
|
+
net.addPlace({ id: 'idle', type: 'initial', tokens: [{ id: 'start', data: {}, createdAt: 0 }] });
|
|
20
|
+
net.addPlace({ id: 'fetched', type: 'normal', tokens: [] });
|
|
21
|
+
net.addPlace({ id: 'summarized', type: 'normal', tokens: [] });
|
|
22
|
+
net.addPlace({ id: 'done', type: 'final', tokens: [] });
|
|
23
|
+
net.addPlace({ id: 'error', type: 'final', tokens: [] });
|
|
24
|
+
|
|
25
|
+
net.addTransition({
|
|
26
|
+
id: 'fetch',
|
|
27
|
+
from: ['idle'],
|
|
28
|
+
to: 'fetched',
|
|
29
|
+
action: {
|
|
30
|
+
type: 'graphflow',
|
|
31
|
+
name: 'fetch_and_summarize',
|
|
32
|
+
contextMapper: (ctx) => ({ maxMails: ctx.maxMails || 5 }),
|
|
33
|
+
} as TransitionAction,
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
net.addTransition({
|
|
37
|
+
id: 'summarize',
|
|
38
|
+
from: ['fetched'],
|
|
39
|
+
to: 'summarized',
|
|
40
|
+
action: {
|
|
41
|
+
type: 'graphflow',
|
|
42
|
+
name: 'fetch_and_summarize',
|
|
43
|
+
contextMapper: (ctx) => ({ mails: ctx.fetchedMails }),
|
|
44
|
+
} as TransitionAction,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
net.addTransition({
|
|
48
|
+
id: 'complete',
|
|
49
|
+
from: ['summarized'],
|
|
50
|
+
to: 'done',
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
net.addTransition({
|
|
54
|
+
id: 'fail',
|
|
55
|
+
from: ['fetched', 'summarized'],
|
|
56
|
+
to: 'error',
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it('should execute a simple GraphFlow action via Petri transition', async () => {
|
|
61
|
+
let mailsFetched = false;
|
|
62
|
+
let summaryGenerated = false;
|
|
63
|
+
|
|
64
|
+
const fetchGraph = new GraphFlow<any>({
|
|
65
|
+
name: 'fetch_mails',
|
|
66
|
+
context: { maxMails: 5 },
|
|
67
|
+
schema: z.object({ maxMails: z.number() }).passthrough(),
|
|
68
|
+
nodes: [
|
|
69
|
+
{
|
|
70
|
+
name: 'fetch_mails',
|
|
71
|
+
execute: async (ctx: any) => {
|
|
72
|
+
mailsFetched = true;
|
|
73
|
+
ctx.fetchedMails = [
|
|
74
|
+
{ id: 1, subject: 'Hello', body: 'World' },
|
|
75
|
+
{ id: 2, subject: 'Test', body: 'Content' },
|
|
76
|
+
];
|
|
77
|
+
},
|
|
78
|
+
next: 'summarize_mail',
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
name: 'summarize_mail',
|
|
82
|
+
execute: async (ctx: any) => {
|
|
83
|
+
summaryGenerated = true;
|
|
84
|
+
ctx.summary = `Summary of ${ctx.fetchedMails.length} mails`;
|
|
85
|
+
},
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
entryNode: 'fetch_mails',
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
toolRegistry.register({
|
|
92
|
+
name: 'fetch_and_summarize',
|
|
93
|
+
description: 'Fetch and summarize mails',
|
|
94
|
+
graph: fetchGraph,
|
|
95
|
+
startNode: 'fetch_mails',
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const sessionId = orchestrator.startSession();
|
|
99
|
+
const result = await orchestrator.fire('fetch', sessionId, { maxMails: 5 });
|
|
100
|
+
|
|
101
|
+
expect(result.success).to.be.true;
|
|
102
|
+
expect(mailsFetched).to.be.true;
|
|
103
|
+
expect(summaryGenerated).to.be.true;
|
|
104
|
+
expect(result.actionResult).to.have.property('summary');
|
|
105
|
+
|
|
106
|
+
// Check the session's PetriNet (not the original)
|
|
107
|
+
const session = orchestrator.getSession(sessionId)!;
|
|
108
|
+
expect(session.petriNet.state.marking.get('fetched')).to.have.lengthOf(1);
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('should handle GraphFlow timeout', async () => {
|
|
112
|
+
const slowGraph = new GraphFlow<any>({
|
|
113
|
+
name: 'slow_graph',
|
|
114
|
+
context: {},
|
|
115
|
+
schema: z.object({}).passthrough(),
|
|
116
|
+
nodes: [
|
|
117
|
+
{
|
|
118
|
+
name: 'slow_node',
|
|
119
|
+
execute: async () => {
|
|
120
|
+
await new Promise(resolve => setTimeout(resolve, 5000));
|
|
121
|
+
},
|
|
122
|
+
},
|
|
123
|
+
],
|
|
124
|
+
entryNode: 'slow_node',
|
|
125
|
+
});
|
|
126
|
+
|
|
127
|
+
toolRegistry.register({
|
|
128
|
+
name: 'slow_action',
|
|
129
|
+
description: 'A slow action',
|
|
130
|
+
graph: slowGraph,
|
|
131
|
+
startNode: 'slow_node',
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
net.addTransition({
|
|
135
|
+
id: 'slow_transition',
|
|
136
|
+
from: ['idle'],
|
|
137
|
+
to: 'done',
|
|
138
|
+
action: {
|
|
139
|
+
type: 'graphflow',
|
|
140
|
+
name: 'slow_action',
|
|
141
|
+
timeout: 100,
|
|
142
|
+
} as any,
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
const sessionId = orchestrator.startSession();
|
|
146
|
+
try {
|
|
147
|
+
await orchestrator.fire('slow_transition', sessionId);
|
|
148
|
+
expect.fail('Should have thrown timeout error');
|
|
149
|
+
} catch (error: any) {
|
|
150
|
+
expect(error.message).to.include('timeout');
|
|
151
|
+
}
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
it('should handle GraphFlow execution error', async () => {
|
|
155
|
+
const errorGraph = new GraphFlow<any>({
|
|
156
|
+
name: 'error_graph',
|
|
157
|
+
context: {},
|
|
158
|
+
schema: z.object({}).passthrough(),
|
|
159
|
+
nodes: [
|
|
160
|
+
{
|
|
161
|
+
name: 'error_node',
|
|
162
|
+
execute: async () => {
|
|
163
|
+
throw new Error('Simulated failure');
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
entryNode: 'error_node',
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
toolRegistry.register({
|
|
171
|
+
name: 'error_action',
|
|
172
|
+
description: 'An action that fails',
|
|
173
|
+
graph: errorGraph,
|
|
174
|
+
startNode: 'error_node',
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
net.addTransition({
|
|
178
|
+
id: 'error_transition',
|
|
179
|
+
from: ['idle'],
|
|
180
|
+
to: 'done',
|
|
181
|
+
action: {
|
|
182
|
+
type: 'graphflow',
|
|
183
|
+
name: 'error_action',
|
|
184
|
+
} as TransitionAction,
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
const sessionId = orchestrator.startSession();
|
|
188
|
+
const result = await orchestrator.fire('error_transition', sessionId);
|
|
189
|
+
|
|
190
|
+
expect(result.success).to.be.false;
|
|
191
|
+
expect(result.error).to.include('Simulated failure');
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('should not detect deadlock with event-driven transitions', () => {
|
|
195
|
+
const eventNet = new PetriNet('event_test');
|
|
196
|
+
eventNet.addPlace({ id: 'start', type: 'initial', tokens: [{ id: 't0', data: {}, createdAt: 0 }] });
|
|
197
|
+
eventNet.addPlace({ id: 'waiting', type: 'normal', tokens: [] });
|
|
198
|
+
|
|
199
|
+
eventNet.addTransition({
|
|
200
|
+
id: 'wait_for_approval',
|
|
201
|
+
from: ['start'],
|
|
202
|
+
to: 'waiting',
|
|
203
|
+
when: { events: ['human_approved'], timeout: 30000 },
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
expect(eventNet.detectDeadlock()).to.be.false;
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('should execute dynamic action with LLM mock', async () => {
|
|
210
|
+
let llmCalled = false;
|
|
211
|
+
|
|
212
|
+
orchestrator.setLLMCall(async (prompt: string) => {
|
|
213
|
+
llmCalled = true;
|
|
214
|
+
return JSON.stringify({
|
|
215
|
+
goal: 'Process request',
|
|
216
|
+
steps: [{ node: 'echo', params: { message: 'processed' } }],
|
|
217
|
+
});
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
const echoGraph = new GraphFlow<any>({
|
|
221
|
+
name: 'echo_graph',
|
|
222
|
+
context: {},
|
|
223
|
+
schema: z.object({}).passthrough(),
|
|
224
|
+
nodes: [
|
|
225
|
+
{
|
|
226
|
+
name: 'echo',
|
|
227
|
+
execute: async (ctx: any) => {
|
|
228
|
+
ctx.result = ctx.message;
|
|
229
|
+
},
|
|
230
|
+
},
|
|
231
|
+
],
|
|
232
|
+
entryNode: 'echo',
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
toolRegistry.register({
|
|
236
|
+
name: 'echo',
|
|
237
|
+
description: 'Echo action',
|
|
238
|
+
graph: echoGraph,
|
|
239
|
+
startNode: 'echo',
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
net.addTransition({
|
|
243
|
+
id: 'dynamic_transition',
|
|
244
|
+
from: ['idle'],
|
|
245
|
+
to: 'done',
|
|
246
|
+
action: {
|
|
247
|
+
type: 'dynamic',
|
|
248
|
+
prompt: 'Process this request',
|
|
249
|
+
maxSteps: 1,
|
|
250
|
+
timeout: 5000,
|
|
251
|
+
} as TransitionAction,
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
const sessionId = orchestrator.startSession();
|
|
255
|
+
const result = await orchestrator.fire('dynamic_transition', sessionId);
|
|
256
|
+
|
|
257
|
+
expect(result.success).to.be.true;
|
|
258
|
+
expect(llmCalled).to.be.true;
|
|
259
|
+
expect(result.actionResult).to.have.property('result', 'processed');
|
|
260
|
+
});
|
|
261
|
+
});
|