@ai.ntellect/core 1.0.0 → 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 +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 +411 -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,811 @@
|
|
|
1
|
+
import { expect, use } from "chai";
|
|
2
|
+
import chaiAsPromised from "chai-as-promised";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
import { InMemoryCheckpointAdapter } from "../../execution/adapters/in-memory-checkpoint";
|
|
5
|
+
import { CheckpointAwaitApprovalError, CheckpointInterruptError, GraphFlow } from "../../execution/index";
|
|
6
|
+
import { GraphNodeConfig } from "../../types";
|
|
7
|
+
|
|
8
|
+
use(chaiAsPromised);
|
|
9
|
+
|
|
10
|
+
const TestSchema = z.object({
|
|
11
|
+
value: z.number().min(0).default(0),
|
|
12
|
+
counter: z.number().default(0),
|
|
13
|
+
message: z.string().default(""),
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
type TestSchema = typeof TestSchema;
|
|
17
|
+
|
|
18
|
+
describe("InMemoryCheckpointAdapter", () => {
|
|
19
|
+
let adapter: InMemoryCheckpointAdapter;
|
|
20
|
+
|
|
21
|
+
beforeEach(() => {
|
|
22
|
+
adapter = new InMemoryCheckpointAdapter();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("should save and load a checkpoint", async () => {
|
|
26
|
+
const cp = {
|
|
27
|
+
id: "cp1",
|
|
28
|
+
graphName: "TestGraph",
|
|
29
|
+
nodeName: "nodeA",
|
|
30
|
+
nextNodes: ["nodeB"],
|
|
31
|
+
context: { value: 10 },
|
|
32
|
+
metadata: { createdAt: Date.now() },
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
await adapter.save(cp);
|
|
36
|
+
const loaded = await adapter.load("cp1");
|
|
37
|
+
|
|
38
|
+
expect(loaded).to.not.be.null;
|
|
39
|
+
expect(loaded!.id).to.equal("cp1");
|
|
40
|
+
expect(loaded!.context.value).to.equal(10);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("should return null for non-existent checkpoint", async () => {
|
|
44
|
+
const loaded = await adapter.load("nonexistent");
|
|
45
|
+
expect(loaded).to.be.null;
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("should list checkpoints by graph name sorted by date", async () => {
|
|
49
|
+
await adapter.save({
|
|
50
|
+
id: "cp1",
|
|
51
|
+
graphName: "GraphA",
|
|
52
|
+
nodeName: "n1",
|
|
53
|
+
nextNodes: [],
|
|
54
|
+
context: {},
|
|
55
|
+
metadata: { createdAt: 1000 },
|
|
56
|
+
});
|
|
57
|
+
await adapter.save({
|
|
58
|
+
id: "cp2",
|
|
59
|
+
graphName: "GraphA",
|
|
60
|
+
nodeName: "n2",
|
|
61
|
+
nextNodes: [],
|
|
62
|
+
context: {},
|
|
63
|
+
metadata: { createdAt: 2000 },
|
|
64
|
+
});
|
|
65
|
+
await adapter.save({
|
|
66
|
+
id: "cp3",
|
|
67
|
+
graphName: "GraphB",
|
|
68
|
+
nodeName: "n3",
|
|
69
|
+
nextNodes: [],
|
|
70
|
+
context: {},
|
|
71
|
+
metadata: { createdAt: 3000 },
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
const listA = await adapter.list("GraphA");
|
|
75
|
+
expect(listA.length).to.equal(2);
|
|
76
|
+
expect(listA[0].id).to.equal("cp2");
|
|
77
|
+
expect(listA[1].id).to.equal("cp1");
|
|
78
|
+
|
|
79
|
+
const listB = await adapter.list("GraphB");
|
|
80
|
+
expect(listB.length).to.equal(1);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it("should delete a checkpoint", async () => {
|
|
84
|
+
await adapter.save({
|
|
85
|
+
id: "cp1",
|
|
86
|
+
graphName: "TestGraph",
|
|
87
|
+
nodeName: "n1",
|
|
88
|
+
nextNodes: [],
|
|
89
|
+
context: {},
|
|
90
|
+
metadata: { createdAt: Date.now() },
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
await adapter.delete("cp1");
|
|
94
|
+
const loaded = await adapter.load("cp1");
|
|
95
|
+
expect(loaded).to.be.null;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("should clear checkpoints by graph name", async () => {
|
|
99
|
+
await adapter.save({
|
|
100
|
+
id: "cp1",
|
|
101
|
+
graphName: "GraphA",
|
|
102
|
+
nodeName: "n1",
|
|
103
|
+
nextNodes: [],
|
|
104
|
+
context: {},
|
|
105
|
+
metadata: { createdAt: Date.now() },
|
|
106
|
+
});
|
|
107
|
+
await adapter.save({
|
|
108
|
+
id: "cp2",
|
|
109
|
+
graphName: "GraphB",
|
|
110
|
+
nodeName: "n2",
|
|
111
|
+
nextNodes: [],
|
|
112
|
+
context: {},
|
|
113
|
+
metadata: { createdAt: Date.now() },
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
await adapter.clear("GraphA");
|
|
117
|
+
expect(await adapter.list("GraphA")).to.have.length(0);
|
|
118
|
+
expect(await adapter.list("GraphB")).to.have.length(1);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("should clear all checkpoints", async () => {
|
|
122
|
+
await adapter.save({
|
|
123
|
+
id: "cp1",
|
|
124
|
+
graphName: "GraphA",
|
|
125
|
+
nodeName: "n1",
|
|
126
|
+
nextNodes: [],
|
|
127
|
+
context: {},
|
|
128
|
+
metadata: { createdAt: Date.now() },
|
|
129
|
+
});
|
|
130
|
+
await adapter.save({
|
|
131
|
+
id: "cp2",
|
|
132
|
+
graphName: "GraphB",
|
|
133
|
+
nodeName: "n2",
|
|
134
|
+
nextNodes: [],
|
|
135
|
+
context: {},
|
|
136
|
+
metadata: { createdAt: Date.now() },
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
await adapter.clear();
|
|
140
|
+
expect(await adapter.list("GraphA")).to.have.length(0);
|
|
141
|
+
expect(await adapter.list("GraphB")).to.have.length(0);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("should return a deep clone on load (no mutation)", async () => {
|
|
145
|
+
const original = {
|
|
146
|
+
id: "cp1",
|
|
147
|
+
graphName: "TestGraph",
|
|
148
|
+
nodeName: "n1",
|
|
149
|
+
nextNodes: [],
|
|
150
|
+
context: { value: 10 },
|
|
151
|
+
metadata: { createdAt: Date.now() },
|
|
152
|
+
};
|
|
153
|
+
await adapter.save(original);
|
|
154
|
+
|
|
155
|
+
const loaded = await adapter.load("cp1");
|
|
156
|
+
loaded!.context.value = 999;
|
|
157
|
+
|
|
158
|
+
const reloaded = await adapter.load("cp1");
|
|
159
|
+
expect(reloaded!.context.value).to.equal(10);
|
|
160
|
+
});
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
describe("CheckpointInterruptError", () => {
|
|
164
|
+
it("should have correct name and checkpointId", () => {
|
|
165
|
+
const err = new CheckpointInterruptError("test", "cp123");
|
|
166
|
+
expect(err.name).to.equal("CheckpointInterruptError");
|
|
167
|
+
expect(err.checkpointId).to.equal("cp123");
|
|
168
|
+
expect(err.message).to.equal("test");
|
|
169
|
+
});
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
describe("GraphFlow with Checkpoints", () => {
|
|
173
|
+
let graph: GraphFlow<TestSchema>;
|
|
174
|
+
let adapter: InMemoryCheckpointAdapter;
|
|
175
|
+
|
|
176
|
+
beforeEach(() => {
|
|
177
|
+
adapter = new InMemoryCheckpointAdapter();
|
|
178
|
+
graph = new GraphFlow({
|
|
179
|
+
name: "TestGraph",
|
|
180
|
+
schema: TestSchema,
|
|
181
|
+
nodes: [],
|
|
182
|
+
context: { value: 0, counter: 0, message: "" },
|
|
183
|
+
});
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
it("should save checkpoint after each node", async () => {
|
|
187
|
+
graph.addNode({
|
|
188
|
+
name: "nodeA",
|
|
189
|
+
execute: async (ctx) => {
|
|
190
|
+
ctx.value = 1;
|
|
191
|
+
},
|
|
192
|
+
next: ["nodeB"],
|
|
193
|
+
});
|
|
194
|
+
graph.addNode({
|
|
195
|
+
name: "nodeB",
|
|
196
|
+
execute: async (ctx) => {
|
|
197
|
+
ctx.value = 2;
|
|
198
|
+
},
|
|
199
|
+
next: ["nodeC"],
|
|
200
|
+
});
|
|
201
|
+
graph.addNode({
|
|
202
|
+
name: "nodeC",
|
|
203
|
+
execute: async (ctx) => {
|
|
204
|
+
ctx.value = 3;
|
|
205
|
+
},
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
const result = await graph.executeWithCheckpoint("nodeA", adapter);
|
|
209
|
+
|
|
210
|
+
const checkpoints = await adapter.list("TestGraph");
|
|
211
|
+
const nodeCheckpoints = checkpoints.filter(
|
|
212
|
+
(c) => !c.nodeName.startsWith("__")
|
|
213
|
+
);
|
|
214
|
+
expect(nodeCheckpoints.length).to.be.greaterThanOrEqual(2);
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
it("should save final checkpoint on complete", async () => {
|
|
218
|
+
graph.addNode({
|
|
219
|
+
name: "nodeA",
|
|
220
|
+
execute: async (ctx) => {
|
|
221
|
+
ctx.value = 42;
|
|
222
|
+
},
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
await graph.executeWithCheckpoint("nodeA", adapter, {
|
|
226
|
+
saveOnComplete: true,
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
const checkpoints = await adapter.list("TestGraph");
|
|
230
|
+
const final = checkpoints.find((c) => c.nodeName === "__completed__");
|
|
231
|
+
expect(final).to.not.be.undefined;
|
|
232
|
+
expect(final!.context.value).to.equal(42);
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
it("should resume from checkpoint and continue execution", async () => {
|
|
236
|
+
graph.addNode({
|
|
237
|
+
name: "nodeA",
|
|
238
|
+
execute: async (ctx) => {
|
|
239
|
+
ctx.value = 10;
|
|
240
|
+
},
|
|
241
|
+
next: ["nodeB"],
|
|
242
|
+
});
|
|
243
|
+
graph.addNode({
|
|
244
|
+
name: "nodeB",
|
|
245
|
+
execute: async (ctx) => {
|
|
246
|
+
ctx.value = (ctx.value ?? 0) + 20;
|
|
247
|
+
},
|
|
248
|
+
next: ["nodeC"],
|
|
249
|
+
});
|
|
250
|
+
graph.addNode({
|
|
251
|
+
name: "nodeC",
|
|
252
|
+
execute: async (ctx) => {
|
|
253
|
+
ctx.value = (ctx.value ?? 0) + 30;
|
|
254
|
+
},
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
const cpId = "resume-test";
|
|
258
|
+
await graph.executeWithCheckpoint("nodeA", adapter, { checkpointId: cpId });
|
|
259
|
+
|
|
260
|
+
const checkpoints = await adapter.list("TestGraph");
|
|
261
|
+
const beforeB = checkpoints.find(
|
|
262
|
+
(c) => c.nodeName === "nodeA" && c.nextNodes.includes("nodeB")
|
|
263
|
+
);
|
|
264
|
+
expect(beforeB).to.not.be.undefined;
|
|
265
|
+
|
|
266
|
+
const freshGraph = new GraphFlow({
|
|
267
|
+
name: "TestGraph",
|
|
268
|
+
schema: TestSchema,
|
|
269
|
+
nodes: graph.getNodes(),
|
|
270
|
+
context: { value: 0, counter: 0, message: "" },
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
const result = await freshGraph.resumeFromCheckpoint(
|
|
274
|
+
beforeB!.id,
|
|
275
|
+
adapter
|
|
276
|
+
);
|
|
277
|
+
expect(result.value).to.equal(60);
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
it("should interrupt execution and save checkpoint", async () => {
|
|
281
|
+
graph.addNode({
|
|
282
|
+
name: "nodeA",
|
|
283
|
+
execute: async (ctx) => {
|
|
284
|
+
ctx.value = 1;
|
|
285
|
+
},
|
|
286
|
+
next: ["nodeB"],
|
|
287
|
+
});
|
|
288
|
+
graph.addNode({
|
|
289
|
+
name: "nodeB",
|
|
290
|
+
execute: async (ctx) => {
|
|
291
|
+
ctx.value = (ctx.value ?? 0) + 2;
|
|
292
|
+
graph.interrupt();
|
|
293
|
+
},
|
|
294
|
+
next: ["nodeC"],
|
|
295
|
+
});
|
|
296
|
+
graph.addNode({
|
|
297
|
+
name: "nodeC",
|
|
298
|
+
execute: async (ctx) => {
|
|
299
|
+
ctx.value = (ctx.value ?? 0) + 3;
|
|
300
|
+
},
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
const cpId = "interrupt-test";
|
|
304
|
+
|
|
305
|
+
try {
|
|
306
|
+
await graph.executeWithCheckpoint("nodeA", adapter, {
|
|
307
|
+
checkpointId: cpId,
|
|
308
|
+
});
|
|
309
|
+
expect.fail("Should have thrown CheckpointInterruptError");
|
|
310
|
+
} catch (error) {
|
|
311
|
+
expect(error).to.be.instanceOf(CheckpointInterruptError);
|
|
312
|
+
const cpError = error as CheckpointInterruptError;
|
|
313
|
+
expect(cpError.checkpointId.startsWith(cpId)).to.be.true;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
const checkpoints = await adapter.list("TestGraph");
|
|
317
|
+
const interrupted = checkpoints.find((c) => c.metadata.interrupted);
|
|
318
|
+
expect(interrupted).to.not.be.undefined;
|
|
319
|
+
expect(interrupted!.context.value).to.equal(3);
|
|
320
|
+
expect(interrupted!.nextNodes).to.include("nodeC");
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
it("should resume after interrupt and complete execution", async () => {
|
|
324
|
+
const executeSteps: string[] = [];
|
|
325
|
+
|
|
326
|
+
graph.addNode({
|
|
327
|
+
name: "nodeA",
|
|
328
|
+
execute: async (ctx) => {
|
|
329
|
+
executeSteps.push("A");
|
|
330
|
+
ctx.value = 1;
|
|
331
|
+
},
|
|
332
|
+
next: ["nodeB"],
|
|
333
|
+
});
|
|
334
|
+
graph.addNode({
|
|
335
|
+
name: "nodeB",
|
|
336
|
+
execute: async (ctx) => {
|
|
337
|
+
executeSteps.push("B");
|
|
338
|
+
ctx.value = (ctx.value ?? 0) + 2;
|
|
339
|
+
graph.interrupt();
|
|
340
|
+
},
|
|
341
|
+
next: ["nodeC"],
|
|
342
|
+
});
|
|
343
|
+
graph.addNode({
|
|
344
|
+
name: "nodeC",
|
|
345
|
+
execute: async (ctx) => {
|
|
346
|
+
executeSteps.push("C");
|
|
347
|
+
ctx.value = (ctx.value ?? 0) + 3;
|
|
348
|
+
},
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
const cpId = "interrupt-resume-test";
|
|
352
|
+
|
|
353
|
+
try {
|
|
354
|
+
await graph.executeWithCheckpoint("nodeA", adapter, { checkpointId: cpId });
|
|
355
|
+
} catch (e) {
|
|
356
|
+
if (!(e instanceof CheckpointInterruptError)) throw e;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
const checkpoints = await adapter.list("TestGraph");
|
|
360
|
+
const interrupted = checkpoints.find((c) => c.metadata.interrupted);
|
|
361
|
+
expect(interrupted).to.not.be.undefined;
|
|
362
|
+
expect(interrupted!.context.value).to.equal(3);
|
|
363
|
+
|
|
364
|
+
const resumedGraph = new GraphFlow({
|
|
365
|
+
name: "TestGraph",
|
|
366
|
+
schema: TestSchema,
|
|
367
|
+
nodes: graph.getNodes(),
|
|
368
|
+
context: { value: 0, counter: 0, message: "" },
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
const result = await resumedGraph.resumeFromCheckpoint(interrupted!.id, adapter);
|
|
372
|
+
expect(result.value).to.equal(6);
|
|
373
|
+
expect(executeSteps).to.deep.equal(["A", "B", "C"]);
|
|
374
|
+
});
|
|
375
|
+
|
|
376
|
+
it("should save error checkpoint on failure", async () => {
|
|
377
|
+
graph.addNode({
|
|
378
|
+
name: "nodeA",
|
|
379
|
+
execute: async (ctx) => {
|
|
380
|
+
ctx.value = 5;
|
|
381
|
+
},
|
|
382
|
+
next: ["nodeB"],
|
|
383
|
+
});
|
|
384
|
+
graph.addNode({
|
|
385
|
+
name: "nodeB",
|
|
386
|
+
execute: async () => {
|
|
387
|
+
throw new Error("boom");
|
|
388
|
+
},
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
const cpId = "error-test";
|
|
392
|
+
|
|
393
|
+
try {
|
|
394
|
+
await graph.executeWithCheckpoint("nodeA", adapter, { checkpointId: cpId });
|
|
395
|
+
expect.fail("Should have thrown");
|
|
396
|
+
} catch (error) {
|
|
397
|
+
expect((error as Error).message).to.equal("boom");
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
const checkpoints = await adapter.list("TestGraph");
|
|
401
|
+
const errorCp = checkpoints.find((c) => c.metadata.error);
|
|
402
|
+
expect(errorCp).to.not.be.undefined;
|
|
403
|
+
expect(errorCp!.metadata.error).to.equal("boom");
|
|
404
|
+
});
|
|
405
|
+
|
|
406
|
+
it("should support custom checkpoint ID prefix", async () => {
|
|
407
|
+
graph.addNode({
|
|
408
|
+
name: "nodeA",
|
|
409
|
+
execute: async (ctx) => {
|
|
410
|
+
ctx.value = 1;
|
|
411
|
+
},
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
await graph.executeWithCheckpoint("nodeA", adapter, {
|
|
415
|
+
checkpointId: "my-custom-id",
|
|
416
|
+
});
|
|
417
|
+
|
|
418
|
+
const checkpoints = await adapter.list("TestGraph");
|
|
419
|
+
const custom = checkpoints.find((c) => c.id.startsWith("my-custom-id"));
|
|
420
|
+
expect(custom).to.not.be.null;
|
|
421
|
+
});
|
|
422
|
+
|
|
423
|
+
it("should not save checkpoints when saveEveryNode is false", async () => {
|
|
424
|
+
graph.addNode({
|
|
425
|
+
name: "nodeA",
|
|
426
|
+
execute: async (ctx) => {
|
|
427
|
+
ctx.value = 1;
|
|
428
|
+
},
|
|
429
|
+
next: ["nodeB"],
|
|
430
|
+
});
|
|
431
|
+
graph.addNode({
|
|
432
|
+
name: "nodeB",
|
|
433
|
+
execute: async (ctx) => {
|
|
434
|
+
ctx.value = 2;
|
|
435
|
+
},
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
await graph.executeWithCheckpoint("nodeA", adapter, {
|
|
439
|
+
saveEveryNode: false,
|
|
440
|
+
saveOnComplete: true,
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
const checkpoints = await adapter.list("TestGraph");
|
|
444
|
+
const nodeCheckpoints = checkpoints.filter(
|
|
445
|
+
(c) => !c.nodeName.startsWith("__")
|
|
446
|
+
);
|
|
447
|
+
expect(nodeCheckpoints).to.have.length(0);
|
|
448
|
+
});
|
|
449
|
+
|
|
450
|
+
it("should not save final checkpoint when saveOnComplete is false", async () => {
|
|
451
|
+
graph.addNode({
|
|
452
|
+
name: "nodeA",
|
|
453
|
+
execute: async (ctx) => {
|
|
454
|
+
ctx.value = 1;
|
|
455
|
+
},
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
await graph.executeWithCheckpoint("nodeA", adapter, {
|
|
459
|
+
saveOnComplete: false,
|
|
460
|
+
});
|
|
461
|
+
|
|
462
|
+
const checkpoints = await adapter.list("TestGraph");
|
|
463
|
+
const final = checkpoints.find((c) => c.nodeName === "__completed__");
|
|
464
|
+
expect(final).to.be.undefined;
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
it("should throw when resuming from non-existent checkpoint", async () => {
|
|
468
|
+
graph.addNode({
|
|
469
|
+
name: "nodeA",
|
|
470
|
+
execute: async () => {},
|
|
471
|
+
});
|
|
472
|
+
|
|
473
|
+
await expect(
|
|
474
|
+
graph.resumeFromCheckpoint("does-not-exist", adapter)
|
|
475
|
+
).to.be.rejectedWith('Checkpoint "does-not-exist" not found');
|
|
476
|
+
});
|
|
477
|
+
|
|
478
|
+
it("should return context immediately when resuming from completed checkpoint", async () => {
|
|
479
|
+
graph.addNode({
|
|
480
|
+
name: "nodeA",
|
|
481
|
+
execute: async (ctx) => {
|
|
482
|
+
ctx.value = 99;
|
|
483
|
+
},
|
|
484
|
+
});
|
|
485
|
+
|
|
486
|
+
await graph.executeWithCheckpoint("nodeA", adapter, {
|
|
487
|
+
checkpointId: "done-cp",
|
|
488
|
+
});
|
|
489
|
+
|
|
490
|
+
const checkpoints = await adapter.list("TestGraph");
|
|
491
|
+
const completed = checkpoints.find((c) => c.nodeName === "__completed__");
|
|
492
|
+
|
|
493
|
+
const freshGraph = new GraphFlow({
|
|
494
|
+
name: "TestGraph",
|
|
495
|
+
schema: TestSchema,
|
|
496
|
+
nodes: graph.getNodes(),
|
|
497
|
+
context: { value: 0, counter: 0, message: "" },
|
|
498
|
+
});
|
|
499
|
+
|
|
500
|
+
const result = await freshGraph.resumeFromCheckpoint(completed!.id, adapter);
|
|
501
|
+
expect(result.value).to.equal(99);
|
|
502
|
+
});
|
|
503
|
+
|
|
504
|
+
it("should list checkpoints for the graph", async () => {
|
|
505
|
+
graph.addNode({
|
|
506
|
+
name: "nodeA",
|
|
507
|
+
execute: async (ctx) => {
|
|
508
|
+
ctx.value = 1;
|
|
509
|
+
},
|
|
510
|
+
next: ["nodeB"],
|
|
511
|
+
});
|
|
512
|
+
graph.addNode({
|
|
513
|
+
name: "nodeB",
|
|
514
|
+
execute: async (ctx) => {
|
|
515
|
+
ctx.value = 2;
|
|
516
|
+
},
|
|
517
|
+
});
|
|
518
|
+
|
|
519
|
+
await graph.executeWithCheckpoint("nodeA", adapter, {
|
|
520
|
+
checkpointId: "list-cp",
|
|
521
|
+
});
|
|
522
|
+
|
|
523
|
+
const list = await graph.listCheckpoints(adapter);
|
|
524
|
+
expect(list.length).to.be.greaterThan(0);
|
|
525
|
+
expect(list.every((c) => c.graphName === "TestGraph")).to.be.true;
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
it("should handle branching workflow with checkpoints", async () => {
|
|
529
|
+
graph.addNode({
|
|
530
|
+
name: "start",
|
|
531
|
+
execute: async (ctx) => {
|
|
532
|
+
ctx.value = 5;
|
|
533
|
+
},
|
|
534
|
+
next: ["branchA", "branchB"],
|
|
535
|
+
});
|
|
536
|
+
graph.addNode({
|
|
537
|
+
name: "branchA",
|
|
538
|
+
execute: async (ctx) => {
|
|
539
|
+
ctx.value = (ctx.value ?? 0) * 2;
|
|
540
|
+
},
|
|
541
|
+
});
|
|
542
|
+
graph.addNode({
|
|
543
|
+
name: "branchB",
|
|
544
|
+
execute: async (ctx) => {
|
|
545
|
+
ctx.value = (ctx.value ?? 0) + 10;
|
|
546
|
+
},
|
|
547
|
+
});
|
|
548
|
+
|
|
549
|
+
await graph.executeWithCheckpoint("start", adapter);
|
|
550
|
+
expect(graph.getContext().value).to.equal(20);
|
|
551
|
+
|
|
552
|
+
const checkpoints = await adapter.list("TestGraph");
|
|
553
|
+
const startCp = checkpoints.find((c) => c.nodeName === "start");
|
|
554
|
+
expect(startCp).to.not.be.undefined;
|
|
555
|
+
expect(startCp!.nextNodes).to.include.members(["branchA", "branchB"]);
|
|
556
|
+
});
|
|
557
|
+
|
|
558
|
+
it("should pause at breakpoint and await approval", async () => {
|
|
559
|
+
graph.addNode({
|
|
560
|
+
name: "nodeA",
|
|
561
|
+
execute: async (ctx) => {
|
|
562
|
+
ctx.value = 1;
|
|
563
|
+
},
|
|
564
|
+
next: ["nodeB"],
|
|
565
|
+
});
|
|
566
|
+
graph.addNode({
|
|
567
|
+
name: "nodeB",
|
|
568
|
+
execute: async (ctx) => {
|
|
569
|
+
ctx.value = (ctx.value ?? 0) + 2;
|
|
570
|
+
},
|
|
571
|
+
next: ["nodeC"],
|
|
572
|
+
});
|
|
573
|
+
graph.addNode({
|
|
574
|
+
name: "nodeC",
|
|
575
|
+
execute: async (ctx) => {
|
|
576
|
+
ctx.value = (ctx.value ?? 0) + 3;
|
|
577
|
+
},
|
|
578
|
+
});
|
|
579
|
+
|
|
580
|
+
try {
|
|
581
|
+
await graph.executeWithCheckpoint("nodeA", adapter, {
|
|
582
|
+
breakpoints: ["nodeB"],
|
|
583
|
+
});
|
|
584
|
+
expect.fail("Should have thrown CheckpointAwaitApprovalError");
|
|
585
|
+
} catch (error) {
|
|
586
|
+
expect(error).to.be.instanceOf(CheckpointAwaitApprovalError);
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
const checkpoints = await adapter.list("TestGraph");
|
|
590
|
+
const approvalCp = checkpoints.find((c) => c.metadata.awaitingApproval);
|
|
591
|
+
expect(approvalCp).to.not.be.undefined;
|
|
592
|
+
expect(approvalCp!.nodeName).to.equal("nodeB");
|
|
593
|
+
expect(approvalCp!.context.value).to.equal(1);
|
|
594
|
+
});
|
|
595
|
+
|
|
596
|
+
it("should resume from breakpoint with context modifications", async () => {
|
|
597
|
+
graph.addNode({
|
|
598
|
+
name: "nodeA",
|
|
599
|
+
execute: async (ctx) => {
|
|
600
|
+
ctx.value = 10;
|
|
601
|
+
},
|
|
602
|
+
next: ["nodeB"],
|
|
603
|
+
});
|
|
604
|
+
graph.addNode({
|
|
605
|
+
name: "nodeB",
|
|
606
|
+
execute: async (ctx) => {
|
|
607
|
+
ctx.value = (ctx.value ?? 0) + 20;
|
|
608
|
+
},
|
|
609
|
+
next: ["nodeC"],
|
|
610
|
+
});
|
|
611
|
+
graph.addNode({
|
|
612
|
+
name: "nodeC",
|
|
613
|
+
execute: async (ctx) => {
|
|
614
|
+
ctx.value = (ctx.value ?? 0) + 30;
|
|
615
|
+
},
|
|
616
|
+
});
|
|
617
|
+
|
|
618
|
+
try {
|
|
619
|
+
await graph.executeWithCheckpoint("nodeA", adapter, {
|
|
620
|
+
breakpoints: ["nodeB"],
|
|
621
|
+
});
|
|
622
|
+
} catch (error) {
|
|
623
|
+
if (!(error instanceof CheckpointAwaitApprovalError)) throw error;
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
const checkpoints = await adapter.list("TestGraph");
|
|
627
|
+
const approvalCp = checkpoints.find((c) => c.metadata.awaitingApproval);
|
|
628
|
+
|
|
629
|
+
const freshGraph = new GraphFlow({
|
|
630
|
+
name: "TestGraph",
|
|
631
|
+
schema: TestSchema,
|
|
632
|
+
nodes: graph.getNodes(),
|
|
633
|
+
context: { value: 0, counter: 0, message: "" },
|
|
634
|
+
});
|
|
635
|
+
|
|
636
|
+
const result = await freshGraph.resumeFromCheckpoint(
|
|
637
|
+
approvalCp!.id,
|
|
638
|
+
adapter,
|
|
639
|
+
{ value: 100 }
|
|
640
|
+
);
|
|
641
|
+
expect(result.value).to.equal(150);
|
|
642
|
+
});
|
|
643
|
+
|
|
644
|
+
it("should track checkpoints by runId", async () => {
|
|
645
|
+
graph.addNode({
|
|
646
|
+
name: "nodeA",
|
|
647
|
+
execute: async (ctx) => {
|
|
648
|
+
ctx.value = 1;
|
|
649
|
+
},
|
|
650
|
+
next: ["nodeB"],
|
|
651
|
+
});
|
|
652
|
+
graph.addNode({
|
|
653
|
+
name: "nodeB",
|
|
654
|
+
execute: async (ctx) => {
|
|
655
|
+
ctx.value = (ctx.value ?? 0) + 2;
|
|
656
|
+
},
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
await graph.executeWithCheckpoint("nodeA", adapter, {
|
|
660
|
+
runId: "run-123",
|
|
661
|
+
});
|
|
662
|
+
|
|
663
|
+
const checkpoints = await adapter.list("TestGraph");
|
|
664
|
+
const runCheckpoints = checkpoints.filter((c) => c.runId === "run-123");
|
|
665
|
+
expect(runCheckpoints.length).to.be.greaterThan(0);
|
|
666
|
+
});
|
|
667
|
+
|
|
668
|
+
it("should time travel: resume from any checkpoint in history", async () => {
|
|
669
|
+
graph.addNode({
|
|
670
|
+
name: "nodeA",
|
|
671
|
+
execute: async (ctx) => {
|
|
672
|
+
ctx.value = 10;
|
|
673
|
+
},
|
|
674
|
+
next: ["nodeB"],
|
|
675
|
+
});
|
|
676
|
+
graph.addNode({
|
|
677
|
+
name: "nodeB",
|
|
678
|
+
execute: async (ctx) => {
|
|
679
|
+
ctx.value = (ctx.value ?? 0) + 20;
|
|
680
|
+
},
|
|
681
|
+
next: ["nodeC"],
|
|
682
|
+
});
|
|
683
|
+
graph.addNode({
|
|
684
|
+
name: "nodeC",
|
|
685
|
+
execute: async (ctx) => {
|
|
686
|
+
ctx.value = (ctx.value ?? 0) + 30;
|
|
687
|
+
},
|
|
688
|
+
});
|
|
689
|
+
|
|
690
|
+
await graph.executeWithCheckpoint("nodeA", adapter, { runId: "travel-run" });
|
|
691
|
+
|
|
692
|
+
const allCheckpoints = await adapter.list("TestGraph");
|
|
693
|
+
const runCheckpoints = allCheckpoints.filter(
|
|
694
|
+
(c) => c.runId === "travel-run" && !c.nodeName.startsWith("__")
|
|
695
|
+
);
|
|
696
|
+
expect(runCheckpoints.length).to.be.greaterThanOrEqual(1);
|
|
697
|
+
|
|
698
|
+
const firstCp = runCheckpoints.find((c) => c.nodeName === "nodeA");
|
|
699
|
+
expect(firstCp).to.not.be.undefined;
|
|
700
|
+
expect(firstCp!.context.value).to.equal(10);
|
|
701
|
+
|
|
702
|
+
const travelGraph = new GraphFlow({
|
|
703
|
+
name: "TestGraph",
|
|
704
|
+
schema: TestSchema,
|
|
705
|
+
nodes: graph.getNodes(),
|
|
706
|
+
context: { value: 0, counter: 0, message: "" },
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
const result = await travelGraph.resumeFromCheckpoint(firstCp!.id, adapter);
|
|
710
|
+
expect(result.value).to.equal(60);
|
|
711
|
+
});
|
|
712
|
+
|
|
713
|
+
it("should time travel: rewind and modify state", async () => {
|
|
714
|
+
graph.addNode({
|
|
715
|
+
name: "nodeA",
|
|
716
|
+
execute: async (ctx) => {
|
|
717
|
+
ctx.message = "started";
|
|
718
|
+
},
|
|
719
|
+
next: ["nodeB"],
|
|
720
|
+
});
|
|
721
|
+
graph.addNode({
|
|
722
|
+
name: "nodeB",
|
|
723
|
+
execute: async (ctx) => {
|
|
724
|
+
ctx.value = (ctx.value ?? 0) + 5;
|
|
725
|
+
},
|
|
726
|
+
next: ["nodeC"],
|
|
727
|
+
});
|
|
728
|
+
graph.addNode({
|
|
729
|
+
name: "nodeC",
|
|
730
|
+
execute: async (ctx) => {
|
|
731
|
+
ctx.value = (ctx.value ?? 0) * 2;
|
|
732
|
+
ctx.message = "done";
|
|
733
|
+
},
|
|
734
|
+
});
|
|
735
|
+
|
|
736
|
+
await graph.executeWithCheckpoint("nodeA", adapter, { runId: "rewind-run" });
|
|
737
|
+
|
|
738
|
+
const allCheckpoints = await adapter.list("TestGraph");
|
|
739
|
+
const rewindCheckpoints = allCheckpoints.filter(
|
|
740
|
+
(c) => c.runId === "rewind-run" && !c.nodeName.startsWith("__")
|
|
741
|
+
);
|
|
742
|
+
|
|
743
|
+
const nodeACp = rewindCheckpoints.find((c) => c.nodeName === "nodeA");
|
|
744
|
+
expect(nodeACp).to.not.be.undefined;
|
|
745
|
+
|
|
746
|
+
const rewindGraph = new GraphFlow({
|
|
747
|
+
name: "TestGraph",
|
|
748
|
+
schema: TestSchema,
|
|
749
|
+
nodes: graph.getNodes(),
|
|
750
|
+
context: { value: 0, counter: 0, message: "" },
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
const result = await rewindGraph.resumeFromCheckpoint(
|
|
754
|
+
nodeACp!.id,
|
|
755
|
+
adapter,
|
|
756
|
+
{ value: 100 }
|
|
757
|
+
);
|
|
758
|
+
expect(result.value).to.equal(210);
|
|
759
|
+
expect(result.message).to.equal("done");
|
|
760
|
+
});
|
|
761
|
+
|
|
762
|
+
it("should get checkpoint history by runId", async () => {
|
|
763
|
+
graph.addNode({
|
|
764
|
+
name: "nodeA",
|
|
765
|
+
execute: async (ctx) => {
|
|
766
|
+
ctx.value = 1;
|
|
767
|
+
},
|
|
768
|
+
next: ["nodeB"],
|
|
769
|
+
});
|
|
770
|
+
graph.addNode({
|
|
771
|
+
name: "nodeB",
|
|
772
|
+
execute: async (ctx) => {
|
|
773
|
+
ctx.value = 2;
|
|
774
|
+
},
|
|
775
|
+
});
|
|
776
|
+
|
|
777
|
+
await graph.executeWithCheckpoint("nodeA", adapter, { runId: "history-1" });
|
|
778
|
+
await graph.executeWithCheckpoint("nodeA", adapter, { runId: "history-2" });
|
|
779
|
+
|
|
780
|
+
const allCheckpoints = await adapter.list("TestGraph");
|
|
781
|
+
const history1 = allCheckpoints.filter((c) => c.runId === "history-1");
|
|
782
|
+
const history2 = allCheckpoints.filter((c) => c.runId === "history-2");
|
|
783
|
+
|
|
784
|
+
expect(history1.length).to.be.greaterThan(0);
|
|
785
|
+
expect(history2.length).to.be.greaterThan(0);
|
|
786
|
+
expect(history1.every((c) => c.runId === "history-1")).to.be.true;
|
|
787
|
+
expect(history2.every((c) => c.runId === "history-2")).to.be.true;
|
|
788
|
+
});
|
|
789
|
+
|
|
790
|
+
it("should get checkpoint history via getCheckpointHistory method", async () => {
|
|
791
|
+
graph.addNode({
|
|
792
|
+
name: "nodeA",
|
|
793
|
+
execute: async (ctx) => {
|
|
794
|
+
ctx.value = 1;
|
|
795
|
+
},
|
|
796
|
+
next: ["nodeB"],
|
|
797
|
+
});
|
|
798
|
+
graph.addNode({
|
|
799
|
+
name: "nodeB",
|
|
800
|
+
execute: async (ctx) => {
|
|
801
|
+
ctx.value = 2;
|
|
802
|
+
},
|
|
803
|
+
});
|
|
804
|
+
|
|
805
|
+
await graph.executeWithCheckpoint("nodeA", adapter, { runId: "method-run" });
|
|
806
|
+
|
|
807
|
+
const history = await graph.getCheckpointHistory("method-run", adapter);
|
|
808
|
+
expect(history.length).to.be.greaterThan(0);
|
|
809
|
+
expect(history.every((c) => c.runId === "method-run")).to.be.true;
|
|
810
|
+
});
|
|
811
|
+
});
|