@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
package/types/agent.ts
ADDED
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
import { GraphFlow } from "@/execution";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Represents an action that has been executed by the agent
|
|
6
|
+
* @interface ExecutedAction
|
|
7
|
+
* @property {string} name - The name of the executed action
|
|
8
|
+
* @property {boolean} isExecuted - Whether the action was successfully executed
|
|
9
|
+
* @property {string | null} [error] - Optional error message if the action failed
|
|
10
|
+
* @property {any} result - The result of the action execution
|
|
11
|
+
* @property {string} timestamp - When the action was executed
|
|
12
|
+
*/
|
|
13
|
+
export type ExecutedAction = {
|
|
14
|
+
name: string;
|
|
15
|
+
parameters?: Record<string, any>;
|
|
16
|
+
isExecuted: boolean;
|
|
17
|
+
error?: string | null;
|
|
18
|
+
result: any;
|
|
19
|
+
timestamp: string;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export type ChatMessage = {
|
|
23
|
+
role: "user" | "assistant";
|
|
24
|
+
content: string;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type ScratchpadEntry = {
|
|
28
|
+
turn: number;
|
|
29
|
+
thought: string;
|
|
30
|
+
action: string;
|
|
31
|
+
observation: string;
|
|
32
|
+
timestamp: string;
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Represents the context in which an agent operates
|
|
37
|
+
* @interface AgentContext
|
|
38
|
+
* @property {Object} input - The input provided to the agent
|
|
39
|
+
* @property {string} input.raw - The raw input text
|
|
40
|
+
* @property {number[]} [input.embedding] - Optional vector embedding of the input
|
|
41
|
+
* @property {ActionSchema[]} actions - List of actions available to the agent
|
|
42
|
+
* @property {string} response - The agent's response
|
|
43
|
+
* @property {string} [knowledge] - Optional knowledge base or context
|
|
44
|
+
* @property {ExecutedAction[]} executedActions - History of executed actions
|
|
45
|
+
* @property {number} [iteration] - Current iteration count (reset per run)
|
|
46
|
+
* @property {boolean} [progressed] - Whether progress was made in this iteration
|
|
47
|
+
* @property {ChatMessage[]} [messages] - Conversation history
|
|
48
|
+
* @property {ScratchpadEntry[]} scratchpad - Structured journal of thoughts
|
|
49
|
+
* @property {BaseMemoryType[]} memories - Retrieved episodic memories
|
|
50
|
+
*/
|
|
51
|
+
export type AgentContext = {
|
|
52
|
+
input: {
|
|
53
|
+
raw: string;
|
|
54
|
+
embedding?: number[];
|
|
55
|
+
};
|
|
56
|
+
actions: ActionSchema[];
|
|
57
|
+
response: string;
|
|
58
|
+
knowledge?: string;
|
|
59
|
+
executedActions: ExecutedAction[];
|
|
60
|
+
iteration?: number;
|
|
61
|
+
progressed?: boolean;
|
|
62
|
+
messages?: ChatMessage[];
|
|
63
|
+
toolResults?: Record<string, any>;
|
|
64
|
+
scratchpad?: ScratchpadEntry[];
|
|
65
|
+
memories?: any[];
|
|
66
|
+
entityState?: {
|
|
67
|
+
currentTarget?: string;
|
|
68
|
+
lastEntityType?: string | null;
|
|
69
|
+
pendingResolutions?: any[];
|
|
70
|
+
resolutionTrace?: any[];
|
|
71
|
+
explored?: boolean;
|
|
72
|
+
handles?: Record<string, { id: string; label: string; path: string; category: string }>;
|
|
73
|
+
};
|
|
74
|
+
conversationState?: {
|
|
75
|
+
currentGoal: string;
|
|
76
|
+
currentTarget: string | null;
|
|
77
|
+
lastResolvedEntity: string | null;
|
|
78
|
+
lastResolvedType: string | null;
|
|
79
|
+
pendingTask: string | null;
|
|
80
|
+
turnCount: number;
|
|
81
|
+
pendingIntent: { action: string | null; unresolvedEntity: string | null; originalInput: string; turn: number; failed: boolean } | null;
|
|
82
|
+
};
|
|
83
|
+
explorationBudget?: {
|
|
84
|
+
maxSteps: number;
|
|
85
|
+
maxExplorations: number;
|
|
86
|
+
maxToolCalls: number;
|
|
87
|
+
stepsUsed: number;
|
|
88
|
+
explorationsUsed: number;
|
|
89
|
+
toolCallsUsed: number;
|
|
90
|
+
};
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export const AgentContextSchema = z.object({
|
|
94
|
+
input: z.object({
|
|
95
|
+
raw: z.string(),
|
|
96
|
+
embedding: z.array(z.number()).optional(),
|
|
97
|
+
}),
|
|
98
|
+
cwd: z.string().optional(),
|
|
99
|
+
actions: z.array(
|
|
100
|
+
z.object({
|
|
101
|
+
name: z.string(),
|
|
102
|
+
parameters: z.array(
|
|
103
|
+
z.object({
|
|
104
|
+
name: z.string(),
|
|
105
|
+
value: z.any(),
|
|
106
|
+
})
|
|
107
|
+
),
|
|
108
|
+
isExecuted: z.boolean().optional(),
|
|
109
|
+
result: z.any().optional(),
|
|
110
|
+
})
|
|
111
|
+
),
|
|
112
|
+
knowledge: z.string().optional(),
|
|
113
|
+
response: z.string(),
|
|
114
|
+
executedActions: z
|
|
115
|
+
.array(
|
|
116
|
+
z.object({
|
|
117
|
+
name: z.string(),
|
|
118
|
+
result: z.any(),
|
|
119
|
+
timestamp: z.string(),
|
|
120
|
+
})
|
|
121
|
+
)
|
|
122
|
+
.optional(),
|
|
123
|
+
iteration: z.number().optional(),
|
|
124
|
+
progressed: z.boolean().optional(),
|
|
125
|
+
messages: z
|
|
126
|
+
.array(
|
|
127
|
+
z.object({
|
|
128
|
+
role: z.enum(["user", "assistant"]),
|
|
129
|
+
content: z.string(),
|
|
130
|
+
})
|
|
131
|
+
)
|
|
132
|
+
.optional(),
|
|
133
|
+
toolResults: z.record(z.string(), z.unknown()).optional(),
|
|
134
|
+
scratchpad: z.array(z.object({
|
|
135
|
+
turn: z.number(),
|
|
136
|
+
thought: z.string(),
|
|
137
|
+
action: z.string(),
|
|
138
|
+
observation: z.string(),
|
|
139
|
+
timestamp: z.string(),
|
|
140
|
+
})).optional().default([]),
|
|
141
|
+
memories: z.array(z.any()).optional().default([]),
|
|
142
|
+
entityState: z.object({
|
|
143
|
+
currentTarget: z.string().optional(),
|
|
144
|
+
lastEntityType: z.string().nullable().optional(),
|
|
145
|
+
pendingResolutions: z.array(z.any()).optional(),
|
|
146
|
+
resolutionTrace: z.array(z.any()).optional(),
|
|
147
|
+
explored: z.boolean().optional(),
|
|
148
|
+
handles: z.record(z.string(), z.object({ id: z.string(), label: z.string(), path: z.string(), category: z.string() })).optional(),
|
|
149
|
+
}).optional(),
|
|
150
|
+
conversationState: z.object({
|
|
151
|
+
currentGoal: z.string(),
|
|
152
|
+
currentTarget: z.string().nullable(),
|
|
153
|
+
lastResolvedEntity: z.string().nullable(),
|
|
154
|
+
lastResolvedType: z.string().nullable(),
|
|
155
|
+
pendingTask: z.string().nullable(),
|
|
156
|
+
turnCount: z.number(),
|
|
157
|
+
pendingIntent: z.object({
|
|
158
|
+
action: z.string().nullable(),
|
|
159
|
+
unresolvedEntity: z.string().nullable(),
|
|
160
|
+
originalInput: z.string(),
|
|
161
|
+
turn: z.number(),
|
|
162
|
+
failed: z.boolean(),
|
|
163
|
+
}).nullable(),
|
|
164
|
+
}).optional(),
|
|
165
|
+
explorationBudget: z.object({
|
|
166
|
+
maxSteps: z.number(),
|
|
167
|
+
maxExplorations: z.number(),
|
|
168
|
+
maxToolCalls: z.number(),
|
|
169
|
+
stepsUsed: z.number(),
|
|
170
|
+
explorationsUsed: z.number(),
|
|
171
|
+
toolCallsUsed: z.number(),
|
|
172
|
+
}).optional(),
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* Represents a section of the prompt with a title and content
|
|
177
|
+
* @interface PromptSection
|
|
178
|
+
* @property {string} title - The title of the prompt section
|
|
179
|
+
* @property {string | ((context: AgentContext) => string | Promise<string>)} content - The content or a function to generate content
|
|
180
|
+
*/
|
|
181
|
+
export type PromptSection = {
|
|
182
|
+
title: string;
|
|
183
|
+
content: string | ((context: AgentContext) => string | Promise<string>);
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
/**
|
|
187
|
+
* Supported LLM providers
|
|
188
|
+
*/
|
|
189
|
+
export type LLMProvider = "openai" | "anthropic" | "ollama" | "groq" | "openrouter" | "google" | "custom";
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Supported LLM models
|
|
193
|
+
*/
|
|
194
|
+
export type LLMModel = "gpt-4" | "gpt-3.5-turbo" | "claude-2" | string;
|
|
195
|
+
|
|
196
|
+
export type ExecutorConfig = {
|
|
197
|
+
llmConfig: LLMConfig;
|
|
198
|
+
verbose?: boolean;
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Configuration for the Agent
|
|
203
|
+
* @type AssistantConfig
|
|
204
|
+
* @extends {Omit<ExecutorConfig, "verbose">}
|
|
205
|
+
* @property {string} role - The function/job of the assistant (e.g., "Email Assistant")
|
|
206
|
+
* @property {string} goal - The specific objective the assistant tries to achieve
|
|
207
|
+
* @property {string} backstory - The personality and behavioral traits of the assistant
|
|
208
|
+
* @property {any[]} [tools] - Optional tools the assistant can use
|
|
209
|
+
* @property {any} [memory] - Optional memory system
|
|
210
|
+
* @property {boolean} [verbose] - Whether to log detailed information
|
|
211
|
+
*/
|
|
212
|
+
export type AgentConfig = {
|
|
213
|
+
role: string;
|
|
214
|
+
goal: string;
|
|
215
|
+
backstory: string;
|
|
216
|
+
tools: GraphFlow<any>[];
|
|
217
|
+
memory?: any;
|
|
218
|
+
verbose?: boolean;
|
|
219
|
+
maxIterations?: number;
|
|
220
|
+
llmConfig: ExecutorConfig["llmConfig"];
|
|
221
|
+
dynamicGoal?: boolean;
|
|
222
|
+
dynamicGoalPrompt?: string;
|
|
223
|
+
dynamicNext?: boolean;
|
|
224
|
+
dynamicNextPrompt?: string;
|
|
225
|
+
enableSchedule?: boolean;
|
|
226
|
+
enableClone?: boolean;
|
|
227
|
+
enableReflection?: boolean;
|
|
228
|
+
agenda?: any;
|
|
229
|
+
entityStore?: import("../agent/entity-resolver/entity-index").IEntityStore;
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Represents the schema of an action that can be performed by the agent
|
|
234
|
+
* @interface ActionSchema
|
|
235
|
+
* @property {string} name - The name of the action
|
|
236
|
+
* @property {Array<{name: string, value: any}>} parameters - The parameters required for the action
|
|
237
|
+
*/
|
|
238
|
+
export type ActionSchema = {
|
|
239
|
+
name: string;
|
|
240
|
+
parameters: Array<{ name: string; value: any }>;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Represents the output of the agent's decision-making process
|
|
245
|
+
* @interface DecisionOutput
|
|
246
|
+
* @property {ActionSchema[]} actions - The actions to be executed
|
|
247
|
+
* @property {string} response - The agent's response message
|
|
248
|
+
* @property {string} [thought] - The agent's internal reasoning for this turn
|
|
249
|
+
*/
|
|
250
|
+
export type DecisionOutput = {
|
|
251
|
+
actions: ActionSchema[];
|
|
252
|
+
response: string;
|
|
253
|
+
thought?: string;
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
export type LLMCall = {
|
|
257
|
+
promptTokens: number;
|
|
258
|
+
completionTokens: number;
|
|
259
|
+
duration: number;
|
|
260
|
+
timestamp: string;
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
/**
|
|
264
|
+
* Configuration for the Language Model
|
|
265
|
+
* @interface LLMConfig
|
|
266
|
+
* @property {LLMProvider} provider - The LLM provider to use
|
|
267
|
+
* @property {string} [apiKey] - API key for the provider (not required for Ollama)
|
|
268
|
+
* @property {LLMModel} model - The specific model to use
|
|
269
|
+
* @property {number} [temperature] - Optional temperature parameter for response randomness
|
|
270
|
+
* @property {number} [maxTokens] - Optional maximum tokens for the response
|
|
271
|
+
* @property {string} [baseUrl] - Optional base URL for local providers (e.g., Ollama)
|
|
272
|
+
* @property {Function} [customCall] - Optional custom implementation for API calls
|
|
273
|
+
*/
|
|
274
|
+
export type LLMConfig = {
|
|
275
|
+
provider: LLMProvider;
|
|
276
|
+
apiKey?: string;
|
|
277
|
+
model: LLMModel;
|
|
278
|
+
temperature?: number;
|
|
279
|
+
maxTokens?: number;
|
|
280
|
+
baseUrl?: string;
|
|
281
|
+
customCall?: (
|
|
282
|
+
prompt: string | PromptInput,
|
|
283
|
+
schema: z.ZodType<any>
|
|
284
|
+
) => Promise<any>;
|
|
285
|
+
};
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* Structure for prompt input to the LLM
|
|
289
|
+
* @interface PromptInput
|
|
290
|
+
* @property {string} system - The system message/context
|
|
291
|
+
* @property {string} user - The user's input message
|
|
292
|
+
*/
|
|
293
|
+
export type PromptInput = {
|
|
294
|
+
system: string;
|
|
295
|
+
user: string;
|
|
296
|
+
};
|
package/types/index.ts
ADDED
|
@@ -0,0 +1,387 @@
|
|
|
1
|
+
import { EventEmitter } from "events";
|
|
2
|
+
import { ZodSchema } from "zod";
|
|
3
|
+
import { IEventEmitter } from "../interfaces";
|
|
4
|
+
|
|
5
|
+
/* ======================== MEMORY ======================== */
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Represents the input structure for creating a memory entry.
|
|
9
|
+
* @typedef {Object} CreateMemoryInput
|
|
10
|
+
* @property {string} content - The text content to store.
|
|
11
|
+
* @property {string} roomId - The room identifier.
|
|
12
|
+
* @property {string} [id] - Optional stable id.
|
|
13
|
+
* @property {Record<string, any>} [metadata] - Optional metadata.
|
|
14
|
+
* @property {number[]} [embedding] - Optional vector embedding.
|
|
15
|
+
* @property {number} [ttl] - Time-to-live in seconds (optional).
|
|
16
|
+
*/
|
|
17
|
+
export interface CreateMemoryInput {
|
|
18
|
+
id?: string;
|
|
19
|
+
content: string;
|
|
20
|
+
metadata?: Record<string, any>;
|
|
21
|
+
embedding?: number[];
|
|
22
|
+
roomId: string;
|
|
23
|
+
ttl?: number;
|
|
24
|
+
type?: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Represents a stored memory entry.
|
|
29
|
+
* @typedef {Object} BaseMemoryType
|
|
30
|
+
* @property {string} id - Unique identifier of the memory entry.
|
|
31
|
+
* @property {string} content - Stored text content.
|
|
32
|
+
* @property {number[] | null} embedding - Vector representation of the data.
|
|
33
|
+
* @property {string} roomId - The associated room ID.
|
|
34
|
+
* @property {Date} createdAt - Creation date.
|
|
35
|
+
*/
|
|
36
|
+
export interface BaseMemoryType {
|
|
37
|
+
id: string;
|
|
38
|
+
content: string;
|
|
39
|
+
metadata?: Record<string, any>;
|
|
40
|
+
embedding?: number[];
|
|
41
|
+
roomId: string;
|
|
42
|
+
createdAt: Date;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/* ======================== SCHEDULING ======================== */
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Type for scheduled request entries
|
|
49
|
+
* @typedef {Object} ScheduledRequest
|
|
50
|
+
*/
|
|
51
|
+
export type ScheduledRequest = {
|
|
52
|
+
/** Unique identifier for the scheduled request */
|
|
53
|
+
id: string;
|
|
54
|
+
/** The original request string */
|
|
55
|
+
originalRequest: string;
|
|
56
|
+
/** The cron expression for scheduling */
|
|
57
|
+
cronExpression: string;
|
|
58
|
+
/** Whether the request is recurring */
|
|
59
|
+
isRecurring: boolean;
|
|
60
|
+
/** The creation date */
|
|
61
|
+
createdAt: Date;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/* ======================== GRAPH ======================== */
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Utility type for extracting schema type from Zod schema
|
|
68
|
+
* @template T - Zod schema type
|
|
69
|
+
*/
|
|
70
|
+
export type SchemaType<T> = T extends ZodSchema<infer U> ? U : never;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Type for graph context based on schema
|
|
74
|
+
* @template T - Schema type
|
|
75
|
+
*/
|
|
76
|
+
export type GraphContext<T extends ZodSchema> = {
|
|
77
|
+
[key: string]: any;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Configuration for event handling strategies in nodes
|
|
82
|
+
* @typedef {Object} EventStrategy
|
|
83
|
+
* @property {"single" | "all" | "correlate"} type - The type of event handling strategy
|
|
84
|
+
* - single: Waits for any single event from the specified events
|
|
85
|
+
* - all: Waits for all specified events to occur
|
|
86
|
+
* - correlate: Uses a correlation function to match related events
|
|
87
|
+
* @property {(events: any[]) => boolean} [correlation] - Optional correlation function for "correlate" strategy
|
|
88
|
+
*/
|
|
89
|
+
export type EventStrategy = {
|
|
90
|
+
type: "single" | "all" | "correlate";
|
|
91
|
+
correlation?: (events: any[]) => boolean;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Configuration for event handling in nodes
|
|
96
|
+
* @typedef {Object} EventConfig
|
|
97
|
+
* @property {string[]} events - Array of event names to wait for
|
|
98
|
+
* @property {number} [timeout] - Optional timeout in milliseconds
|
|
99
|
+
* @property {EventStrategy} strategy - Strategy for handling multiple events
|
|
100
|
+
* @property {(events: any[]) => Promise<void>} [onSuccess] - Optional callback when events are successfully received
|
|
101
|
+
* @property {() => Promise<void>} [onTimeout] - Optional callback when event waiting times out
|
|
102
|
+
* @example
|
|
103
|
+
* ```typescript
|
|
104
|
+
* const eventConfig: EventConfig = {
|
|
105
|
+
* events: ["payment.received", "order.validated"],
|
|
106
|
+
* timeout: 5000,
|
|
107
|
+
* strategy: {
|
|
108
|
+
* type: "correlate",
|
|
109
|
+
* correlation: (events) => events.every(e => e.transactionId === events[0].transactionId)
|
|
110
|
+
* },
|
|
111
|
+
* onSuccess: async (events) => {
|
|
112
|
+
* console.log("Correlated events received:", events);
|
|
113
|
+
* },
|
|
114
|
+
* onTimeout: async () => {
|
|
115
|
+
* console.log("Event waiting timed out");
|
|
116
|
+
* }
|
|
117
|
+
* };
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
export type EventConfig = {
|
|
121
|
+
events: string[];
|
|
122
|
+
timeout?: number;
|
|
123
|
+
strategy: EventStrategy;
|
|
124
|
+
onSuccess?: (events: any[]) => Promise<void>;
|
|
125
|
+
onTimeout?: () => Promise<void>;
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Represents an event in the graph system
|
|
130
|
+
* @template T - Schema type for context validation
|
|
131
|
+
* @property {string} type - The type/name of the event
|
|
132
|
+
* @property {any} [payload] - Optional payload data
|
|
133
|
+
* @property {number} timestamp - Unix timestamp of when the event occurred
|
|
134
|
+
* @example
|
|
135
|
+
* ```typescript
|
|
136
|
+
* const event: GraphEvent<MySchema> = {
|
|
137
|
+
* type: "payment.received",
|
|
138
|
+
* payload: {
|
|
139
|
+
* transactionId: "tx123",
|
|
140
|
+
* amount: 100,
|
|
141
|
+
* currency: "USD"
|
|
142
|
+
* },
|
|
143
|
+
* timestamp: Date.now()
|
|
144
|
+
* };
|
|
145
|
+
* ```
|
|
146
|
+
*/
|
|
147
|
+
export type GraphEvent<T extends ZodSchema> = {
|
|
148
|
+
type: string;
|
|
149
|
+
payload?: any;
|
|
150
|
+
timestamp: number;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
/**
|
|
154
|
+
* Configuration for waiting on multiple events
|
|
155
|
+
* @template T - Schema type for context validation
|
|
156
|
+
* @property {string[]} events - Array of event names to wait for
|
|
157
|
+
* @property {number} [timeout] - Optional timeout in milliseconds
|
|
158
|
+
* @property {"all" | "any" | "race"} strategy - Strategy for handling multiple events
|
|
159
|
+
* @property {(context: GraphContext<T>) => Promise<void>} [onSuccess] - Optional success callback
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* const config: WaitForEvents<MySchema> = {
|
|
163
|
+
* events: ["event1", "event2"],
|
|
164
|
+
* timeout: 5000,
|
|
165
|
+
* strategy: "all",
|
|
166
|
+
* onSuccess: async (context) => {
|
|
167
|
+
* console.log("All events received");
|
|
168
|
+
* }
|
|
169
|
+
* };
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export type WaitForEvents<T extends ZodSchema> = {
|
|
173
|
+
events: string[];
|
|
174
|
+
timeout?: number;
|
|
175
|
+
strategy: "all" | "any" | "race";
|
|
176
|
+
onSuccess?: <T extends ZodSchema>(context: GraphContext<T>) => Promise<void>;
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* Interface representing a node in the graph
|
|
181
|
+
* @interface
|
|
182
|
+
* @template T - Schema type
|
|
183
|
+
* @template P - Parameters type
|
|
184
|
+
*/
|
|
185
|
+
export interface GraphNodeConfig<T extends ZodSchema, P = any> {
|
|
186
|
+
/** Name of the node */
|
|
187
|
+
name: string;
|
|
188
|
+
/** Description of the node */
|
|
189
|
+
description?: string;
|
|
190
|
+
/** Schema for node inputs */
|
|
191
|
+
params?: P extends void ? never : ZodSchema<P>;
|
|
192
|
+
/** Execute function for the node */
|
|
193
|
+
execute: (
|
|
194
|
+
context: GraphContext<T>,
|
|
195
|
+
tools?: { eventEmitter: IEventEmitter }
|
|
196
|
+
) => Promise<void>;
|
|
197
|
+
/** Optional condition for node execution */
|
|
198
|
+
condition?: (context: GraphContext<T>, params?: P) => boolean;
|
|
199
|
+
/** Array of next node names or objects with conditions */
|
|
200
|
+
next?:
|
|
201
|
+
| Array<
|
|
202
|
+
| string
|
|
203
|
+
| { node: string; condition: (context: GraphContext<T>) => boolean }
|
|
204
|
+
>
|
|
205
|
+
| string
|
|
206
|
+
| ((context: GraphContext<T>) => string[]);
|
|
207
|
+
/** Array of event names that trigger this node */
|
|
208
|
+
events?: string[];
|
|
209
|
+
/** Event handling configuration */
|
|
210
|
+
when?: EventConfig;
|
|
211
|
+
/** Retry configuration */
|
|
212
|
+
retry?: {
|
|
213
|
+
maxAttempts: number;
|
|
214
|
+
delay: number;
|
|
215
|
+
onRetryFailed?: (error: Error, context: GraphContext<T>) => Promise<void>;
|
|
216
|
+
continueOnFailed?: boolean;
|
|
217
|
+
};
|
|
218
|
+
/** Error handler function */
|
|
219
|
+
onError?: (error: Error) => void;
|
|
220
|
+
agent?: string;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Interface for graph definition
|
|
225
|
+
* @interface
|
|
226
|
+
* @template T - Schema type
|
|
227
|
+
*/
|
|
228
|
+
export type GraphConfig<T extends ZodSchema> = {
|
|
229
|
+
/** Name of the graph */
|
|
230
|
+
name: string;
|
|
231
|
+
/** Schema for validation */
|
|
232
|
+
schema: T;
|
|
233
|
+
/** Initial context */
|
|
234
|
+
context: SchemaType<T>;
|
|
235
|
+
/** Array of nodes in the graph */
|
|
236
|
+
nodes: GraphNodeConfig<T, any>[];
|
|
237
|
+
/** Global error handler */
|
|
238
|
+
onError?: (error: Error, context: GraphContext<T>) => void;
|
|
239
|
+
/** Entry node name */
|
|
240
|
+
entryNode?: string;
|
|
241
|
+
/** Event emitter instance */
|
|
242
|
+
eventEmitter?: IEventEmitter | EventEmitter;
|
|
243
|
+
/** Array of events */
|
|
244
|
+
events?: string[];
|
|
245
|
+
};
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* Type for graph execution result
|
|
249
|
+
* @template T - Schema type
|
|
250
|
+
*/
|
|
251
|
+
export type GraphExecutionResult<T extends ZodSchema> = {
|
|
252
|
+
graphName: string;
|
|
253
|
+
nodeName: string;
|
|
254
|
+
context: GraphContext<T>;
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
/* ======================== MEILISEARCH ======================== */
|
|
258
|
+
|
|
259
|
+
/**
|
|
260
|
+
* Configuration type for Meilisearch
|
|
261
|
+
* @typedef {Object} MeilisearchConfig
|
|
262
|
+
*/
|
|
263
|
+
export type MeilisearchConfig = {
|
|
264
|
+
/** Meilisearch host URL */
|
|
265
|
+
host: string;
|
|
266
|
+
/** API key for authentication */
|
|
267
|
+
apiKey: string;
|
|
268
|
+
/** Array of searchable attributes */
|
|
269
|
+
searchableAttributes?: string[];
|
|
270
|
+
/** Array of sortable attributes */
|
|
271
|
+
sortableAttributes?: string[];
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Settings type for Meilisearch
|
|
276
|
+
* @typedef {Object} MeilisearchSettings
|
|
277
|
+
*/
|
|
278
|
+
export type MeilisearchSettings = {
|
|
279
|
+
/** Array of searchable attributes */
|
|
280
|
+
searchableAttributes?: string[];
|
|
281
|
+
/** Array of sortable attributes */
|
|
282
|
+
sortableAttributes?: string[];
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Configuration interface for NLP Engine
|
|
287
|
+
* @interface NLPConfig
|
|
288
|
+
* @property {any} [corpus] - Training corpus data
|
|
289
|
+
* @property {Record<string, any>} [responses] - Response templates
|
|
290
|
+
* @property {Record<string, any>} [entities] - Entity definitions
|
|
291
|
+
* @property {string} [language] - Language code (default: 'en')
|
|
292
|
+
* @property {number} [threshold] - Entity recognition threshold (default: 0.5)
|
|
293
|
+
* @property {string} [path] - Path to save/load model
|
|
294
|
+
*/
|
|
295
|
+
export type NLPConfig = {
|
|
296
|
+
corpus?: any;
|
|
297
|
+
responses?: Record<string, any>;
|
|
298
|
+
entities?: Record<string, any>;
|
|
299
|
+
language?: string;
|
|
300
|
+
threshold?: number;
|
|
301
|
+
path?: string;
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* Type definition for action handlers
|
|
306
|
+
* @callback ActionHandler
|
|
307
|
+
* @param {any} data - Input data for the action
|
|
308
|
+
* @returns {Promise<any>} Result of the action
|
|
309
|
+
*/
|
|
310
|
+
export type ActionHandler = (data: any) => Promise<any>;
|
|
311
|
+
|
|
312
|
+
/**
|
|
313
|
+
* Options for the observer
|
|
314
|
+
* @typedef {Object} ObserverOptions
|
|
315
|
+
* @property {number} [debounce] - Debounce time in milliseconds
|
|
316
|
+
* @property {number} [delay] - Delay time in milliseconds
|
|
317
|
+
* @property {boolean} [stream] - Whether to stream the response
|
|
318
|
+
* @property {(string | number)[]} [properties] - Properties to observe
|
|
319
|
+
*/
|
|
320
|
+
export type ObserverOptions = {
|
|
321
|
+
debounce?: number;
|
|
322
|
+
delay?: number;
|
|
323
|
+
stream?: boolean;
|
|
324
|
+
properties?: (string | number)[];
|
|
325
|
+
onStreamLetter?: (data: { letter: string; property: string }) => void;
|
|
326
|
+
onStreamComplete?: () => void;
|
|
327
|
+
};
|
|
328
|
+
|
|
329
|
+
/* ======================== CHECKPOINT ======================== */
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Checkpoint metadata for tracking execution state
|
|
333
|
+
*/
|
|
334
|
+
export type CheckpointMetadata = {
|
|
335
|
+
createdAt: number;
|
|
336
|
+
interrupted?: boolean;
|
|
337
|
+
awaitingApproval?: boolean;
|
|
338
|
+
rejected?: boolean;
|
|
339
|
+
error?: string;
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
/**
|
|
343
|
+
* Configuration for checkpoint behavior during execution
|
|
344
|
+
*/
|
|
345
|
+
export type CheckpointConfig = {
|
|
346
|
+
saveEveryNode?: boolean;
|
|
347
|
+
saveOnComplete?: boolean;
|
|
348
|
+
checkpointId?: string;
|
|
349
|
+
breakpoints?: string[];
|
|
350
|
+
runId?: string;
|
|
351
|
+
initialContext?: Record<string, any>;
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Result of a human-in-the-loop approval
|
|
356
|
+
*/
|
|
357
|
+
export type ApprovalResult = {
|
|
358
|
+
action: "approved" | "rejected";
|
|
359
|
+
contextModifications?: Record<string, any>;
|
|
360
|
+
};
|
|
361
|
+
|
|
362
|
+
/**
|
|
363
|
+
* Represents a saved execution state of a graph
|
|
364
|
+
*/
|
|
365
|
+
export type Checkpoint<T extends ZodSchema = any> = {
|
|
366
|
+
id: string;
|
|
367
|
+
graphName: string;
|
|
368
|
+
runId?: string;
|
|
369
|
+
nodeName: string;
|
|
370
|
+
nextNodes: string[];
|
|
371
|
+
context: Record<string, any>;
|
|
372
|
+
metadata: CheckpointMetadata;
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
/* ======================== PARALLEL & HANDOFF ======================== */
|
|
376
|
+
|
|
377
|
+
export type {
|
|
378
|
+
ParallelConfig,
|
|
379
|
+
Send,
|
|
380
|
+
SendFunction,
|
|
381
|
+
Command,
|
|
382
|
+
ReducerFunction,
|
|
383
|
+
StateReducer,
|
|
384
|
+
WorkerConfig,
|
|
385
|
+
ParallelNodeConfig,
|
|
386
|
+
} from "../execution/types.parallel";
|
|
387
|
+
|