@ai.ntellect/core 1.0.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mocharc.json +6 -0
- package/AGENTS.md +50 -0
- package/ARCHITECTURE.md +58 -0
- package/BENCHMARK.md +38 -0
- package/CHANGELOG.md +224 -0
- package/README.md +363 -142
- package/agent/agent-workflow.ts +569 -0
- package/agent/agent.ts +183 -0
- package/agent/base/executor.ts +103 -0
- package/agent/base/index.ts +87 -0
- package/agent/entity-resolver/confidence.ts +54 -0
- package/agent/entity-resolver/entity-index.ts +241 -0
- package/agent/entity-resolver/explore-strategy.ts +82 -0
- package/agent/entity-resolver/index.ts +22 -0
- package/agent/entity-resolver/resolver.ts +193 -0
- package/agent/entity-resolver/scorer.ts +211 -0
- package/agent/entity-resolver/types.ts +98 -0
- package/agent/generic-executor.ts +713 -0
- package/agent/handlers/cognitive-handler.ts +197 -0
- package/agent/handlers/index.ts +1 -0
- package/agent/handoff.ts +58 -0
- package/agent/llm-factory.ts +343 -0
- package/agent/orchestrator.ts +45 -0
- package/agent/prompt-builder.ts +78 -0
- package/agent/registry.ts +64 -0
- package/agent/tools/file-system.ts +471 -0
- package/agent/tools/index.ts +23 -0
- package/agent/tools/logger.ts +105 -0
- package/agent/tools/tool-resolver.ts +104 -0
- package/benchmark/cortexflow-workflow.ts +182 -0
- package/benchmark/langgraph-workflow.ts +201 -0
- package/benchmark/llm-client.ts +76 -0
- package/benchmark/run-benchmark.ts +222 -0
- package/cli-dev.ts +419 -0
- package/dist/agent/agent-workflow.d.ts +41 -0
- package/dist/agent/agent-workflow.d.ts.map +1 -0
- package/dist/agent/agent-workflow.js +560 -0
- package/dist/agent/agent-workflow.js.map +1 -0
- package/dist/agent/agent.d.ts +38 -0
- package/dist/agent/agent.d.ts.map +1 -0
- package/dist/agent/agent.js +149 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/agent/base/executor.d.ts +51 -0
- package/dist/agent/base/executor.d.ts.map +1 -0
- package/dist/agent/base/executor.js +69 -0
- package/dist/agent/base/executor.js.map +1 -0
- package/dist/agent/base/index.d.ts +30 -0
- package/dist/agent/base/index.d.ts.map +1 -0
- package/dist/agent/base/index.js +88 -0
- package/dist/agent/base/index.js.map +1 -0
- package/dist/agent/entity-resolver/confidence.d.ts +4 -0
- package/dist/agent/entity-resolver/confidence.d.ts.map +1 -0
- package/dist/agent/entity-resolver/confidence.js +47 -0
- package/dist/agent/entity-resolver/confidence.js.map +1 -0
- package/dist/agent/entity-resolver/entity-index.d.ts +40 -0
- package/dist/agent/entity-resolver/entity-index.d.ts.map +1 -0
- package/dist/agent/entity-resolver/entity-index.js +244 -0
- package/dist/agent/entity-resolver/entity-index.js.map +1 -0
- package/dist/agent/entity-resolver/explore-strategy.d.ts +13 -0
- package/dist/agent/entity-resolver/explore-strategy.d.ts.map +1 -0
- package/dist/agent/entity-resolver/explore-strategy.js +109 -0
- package/dist/agent/entity-resolver/explore-strategy.js.map +1 -0
- package/dist/agent/entity-resolver/index.d.ts +8 -0
- package/dist/agent/entity-resolver/index.d.ts.map +1 -0
- package/dist/agent/entity-resolver/index.js +16 -0
- package/dist/agent/entity-resolver/index.js.map +1 -0
- package/dist/agent/entity-resolver/resolver.d.ts +18 -0
- package/dist/agent/entity-resolver/resolver.d.ts.map +1 -0
- package/dist/agent/entity-resolver/resolver.js +158 -0
- package/dist/agent/entity-resolver/resolver.js.map +1 -0
- package/dist/agent/entity-resolver/scorer.d.ts +3 -0
- package/dist/agent/entity-resolver/scorer.d.ts.map +1 -0
- package/dist/agent/entity-resolver/scorer.js +182 -0
- package/dist/agent/entity-resolver/scorer.js.map +1 -0
- package/dist/agent/entity-resolver/types.d.ts +89 -0
- package/dist/agent/entity-resolver/types.d.ts.map +1 -0
- package/dist/agent/entity-resolver/types.js +3 -0
- package/dist/agent/entity-resolver/types.js.map +1 -0
- package/dist/agent/generic-executor.d.ts +68 -0
- package/dist/agent/generic-executor.d.ts.map +1 -0
- package/dist/agent/generic-executor.js +620 -0
- package/dist/agent/generic-executor.js.map +1 -0
- package/dist/agent/handlers/cognitive-handler.d.ts +44 -0
- package/dist/agent/handlers/cognitive-handler.d.ts.map +1 -0
- package/dist/agent/handlers/cognitive-handler.js +172 -0
- package/dist/agent/handlers/cognitive-handler.js.map +1 -0
- package/dist/agent/handlers/index.d.ts +2 -0
- package/dist/agent/handlers/index.d.ts.map +1 -0
- package/dist/agent/handlers/index.js +7 -0
- package/dist/agent/handlers/index.js.map +1 -0
- package/dist/agent/handoff.d.ts +12 -0
- package/dist/agent/handoff.d.ts.map +1 -0
- package/dist/agent/handoff.js +62 -0
- package/dist/agent/handoff.js.map +1 -0
- package/dist/agent/llm-factory.d.ts +19 -0
- package/dist/agent/llm-factory.d.ts.map +1 -0
- package/dist/agent/llm-factory.js +297 -0
- package/dist/agent/llm-factory.js.map +1 -0
- package/dist/agent/orchestrator.d.ts +18 -0
- package/dist/agent/orchestrator.d.ts.map +1 -0
- package/dist/agent/orchestrator.js +44 -0
- package/dist/agent/orchestrator.js.map +1 -0
- package/dist/agent/prompt-builder.d.ts +35 -0
- package/dist/agent/prompt-builder.d.ts.map +1 -0
- package/dist/agent/prompt-builder.js +76 -0
- package/dist/agent/prompt-builder.js.map +1 -0
- package/dist/agent/registry.d.ts +19 -0
- package/dist/agent/registry.d.ts.map +1 -0
- package/dist/agent/registry.js +48 -0
- package/dist/agent/registry.js.map +1 -0
- package/dist/agent/tools/file-system.d.ts +11 -0
- package/dist/agent/tools/file-system.d.ts.map +1 -0
- package/dist/agent/tools/file-system.js +528 -0
- package/dist/agent/tools/file-system.js.map +1 -0
- package/dist/agent/tools/index.d.ts +4 -0
- package/dist/agent/tools/index.d.ts.map +1 -0
- package/dist/agent/tools/index.js +20 -0
- package/dist/agent/tools/index.js.map +1 -0
- package/dist/agent/tools/logger.d.ts +33 -0
- package/dist/agent/tools/logger.d.ts.map +1 -0
- package/dist/agent/tools/logger.js +86 -0
- package/dist/agent/tools/logger.js.map +1 -0
- package/dist/agent/tools/tool-resolver.d.ts +7 -0
- package/dist/agent/tools/tool-resolver.d.ts.map +1 -0
- package/dist/agent/tools/tool-resolver.js +122 -0
- package/dist/agent/tools/tool-resolver.js.map +1 -0
- package/dist/execution/adapters/in-memory-checkpoint.d.ts +11 -0
- package/dist/execution/adapters/in-memory-checkpoint.d.ts.map +1 -0
- package/dist/execution/adapters/in-memory-checkpoint.js +54 -0
- package/dist/execution/adapters/in-memory-checkpoint.js.map +1 -0
- package/dist/execution/compiler.d.ts +8 -0
- package/dist/execution/compiler.d.ts.map +1 -0
- package/dist/execution/compiler.js +50 -0
- package/dist/execution/compiler.js.map +1 -0
- package/dist/execution/controller.d.ts +30 -0
- package/dist/execution/controller.d.ts.map +1 -0
- package/dist/execution/controller.js +80 -0
- package/dist/execution/controller.js.map +1 -0
- package/dist/execution/event-manager.d.ts +29 -0
- package/dist/execution/event-manager.d.ts.map +1 -0
- package/dist/execution/event-manager.js +264 -0
- package/dist/execution/event-manager.js.map +1 -0
- package/dist/execution/index.d.ts +221 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +638 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/execution/logger.d.ts +46 -0
- package/dist/execution/logger.d.ts.map +1 -0
- package/dist/execution/logger.js +69 -0
- package/dist/execution/logger.js.map +1 -0
- package/dist/execution/node.d.ts +65 -0
- package/dist/execution/node.d.ts.map +1 -0
- package/dist/execution/node.js +250 -0
- package/dist/execution/node.js.map +1 -0
- package/dist/execution/observer.d.ts +38 -0
- package/dist/execution/observer.d.ts.map +1 -0
- package/dist/execution/observer.js +111 -0
- package/dist/execution/observer.js.map +1 -0
- package/dist/execution/planner.d.ts +14 -0
- package/dist/execution/planner.d.ts.map +1 -0
- package/dist/execution/planner.js +43 -0
- package/dist/execution/planner.js.map +1 -0
- package/dist/execution/reducer.d.ts +19 -0
- package/dist/execution/reducer.d.ts.map +1 -0
- package/dist/execution/reducer.js +61 -0
- package/dist/execution/reducer.js.map +1 -0
- package/dist/execution/registry.d.ts +38 -0
- package/dist/execution/registry.d.ts.map +1 -0
- package/dist/execution/registry.js +63 -0
- package/dist/execution/registry.js.map +1 -0
- package/dist/execution/send-api.d.ts +24 -0
- package/dist/execution/send-api.d.ts.map +1 -0
- package/dist/execution/send-api.js +52 -0
- package/dist/execution/send-api.js.map +1 -0
- package/dist/execution/types.parallel.d.ts +61 -0
- package/dist/execution/types.parallel.d.ts.map +1 -0
- package/dist/execution/types.parallel.js +3 -0
- package/dist/execution/types.parallel.js.map +1 -0
- package/dist/execution/visualizer.d.ts +35 -0
- package/dist/execution/visualizer.d.ts.map +1 -0
- package/dist/execution/visualizer.js +131 -0
- package/dist/execution/visualizer.js.map +1 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/index.d.ts +487 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/index.js +75 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/modules/agenda/adapters/node-cron/index.d.ts +17 -0
- package/dist/modules/agenda/adapters/node-cron/index.d.ts.map +1 -0
- package/dist/modules/agenda/adapters/node-cron/index.js +30 -0
- package/dist/modules/agenda/adapters/node-cron/index.js.map +1 -0
- package/dist/modules/agenda/index.d.ts +63 -0
- package/dist/modules/agenda/index.d.ts.map +1 -0
- package/dist/modules/agenda/index.js +141 -0
- package/dist/modules/agenda/index.js.map +1 -0
- package/dist/modules/cli/index.d.ts +13 -0
- package/dist/modules/cli/index.d.ts.map +1 -0
- package/dist/modules/cli/index.js +672 -0
- package/dist/modules/cli/index.js.map +1 -0
- package/dist/modules/embedding/adapters/ai/index.d.ts +29 -0
- package/dist/modules/embedding/adapters/ai/index.d.ts.map +1 -0
- package/dist/modules/embedding/adapters/ai/index.js +58 -0
- package/dist/modules/embedding/adapters/ai/index.js.map +1 -0
- package/dist/modules/embedding/index.d.ts +36 -0
- package/dist/modules/embedding/index.d.ts.map +1 -0
- package/dist/modules/embedding/index.js +60 -0
- package/dist/modules/embedding/index.js.map +1 -0
- package/dist/modules/nlp/engine.d.ts +126 -0
- package/dist/modules/nlp/engine.d.ts.map +1 -0
- package/dist/modules/nlp/engine.js +299 -0
- package/dist/modules/nlp/engine.js.map +1 -0
- package/dist/modules/nlp/index.d.ts +27 -0
- package/dist/modules/nlp/index.d.ts.map +1 -0
- package/dist/modules/nlp/index.js +56 -0
- package/dist/modules/nlp/index.js.map +1 -0
- package/dist/persistence/index.d.ts +12 -0
- package/dist/persistence/index.d.ts.map +1 -0
- package/dist/persistence/index.js +24 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/persistence/neo4j/driver.d.ts +26 -0
- package/dist/persistence/neo4j/driver.d.ts.map +1 -0
- package/dist/persistence/neo4j/driver.js +64 -0
- package/dist/persistence/neo4j/driver.js.map +1 -0
- package/dist/persistence/neo4j/entity-store.d.ts +15 -0
- package/dist/persistence/neo4j/entity-store.d.ts.map +1 -0
- package/dist/persistence/neo4j/entity-store.js +136 -0
- package/dist/persistence/neo4j/entity-store.js.map +1 -0
- package/dist/persistence/neo4j/execution-tracer.d.ts +19 -0
- package/dist/persistence/neo4j/execution-tracer.d.ts.map +1 -0
- package/dist/persistence/neo4j/execution-tracer.js +166 -0
- package/dist/persistence/neo4j/execution-tracer.js.map +1 -0
- package/dist/persistence/neo4j/memory-adapter.d.ts +35 -0
- package/dist/persistence/neo4j/memory-adapter.d.ts.map +1 -0
- package/dist/persistence/neo4j/memory-adapter.js +252 -0
- package/dist/persistence/neo4j/memory-adapter.js.map +1 -0
- package/dist/persistence/neo4j/petri-checkpoint-adapter.d.ts +22 -0
- package/dist/persistence/neo4j/petri-checkpoint-adapter.d.ts.map +1 -0
- package/dist/persistence/neo4j/petri-checkpoint-adapter.js +141 -0
- package/dist/persistence/neo4j/petri-checkpoint-adapter.js.map +1 -0
- package/dist/pipeline/agent-pipeline.d.ts +99 -0
- package/dist/pipeline/agent-pipeline.d.ts.map +1 -0
- package/dist/pipeline/agent-pipeline.js +356 -0
- package/dist/pipeline/agent-pipeline.js.map +1 -0
- package/dist/routing/checkpoint-adapter.d.ts +30 -0
- package/dist/routing/checkpoint-adapter.d.ts.map +1 -0
- package/dist/routing/checkpoint-adapter.js +83 -0
- package/dist/routing/checkpoint-adapter.js.map +1 -0
- package/dist/routing/documentation-generator.d.ts +47 -0
- package/dist/routing/documentation-generator.d.ts.map +1 -0
- package/dist/routing/documentation-generator.js +320 -0
- package/dist/routing/documentation-generator.js.map +1 -0
- package/dist/routing/index.d.ts +38 -0
- package/dist/routing/index.d.ts.map +1 -0
- package/dist/routing/index.js +375 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/routing/intent-classifier.d.ts +206 -0
- package/dist/routing/intent-classifier.d.ts.map +1 -0
- package/dist/routing/intent-classifier.js +267 -0
- package/dist/routing/intent-classifier.js.map +1 -0
- package/dist/routing/matrix.d.ts +6 -0
- package/dist/routing/matrix.d.ts.map +1 -0
- package/dist/routing/matrix.js +131 -0
- package/dist/routing/matrix.js.map +1 -0
- package/dist/routing/orchestrator.d.ts +87 -0
- package/dist/routing/orchestrator.d.ts.map +1 -0
- package/dist/routing/orchestrator.js +425 -0
- package/dist/routing/orchestrator.js.map +1 -0
- package/dist/routing/postgres-checkpoint-adapter.d.ts +32 -0
- package/dist/routing/postgres-checkpoint-adapter.d.ts.map +1 -0
- package/dist/routing/postgres-checkpoint-adapter.js +167 -0
- package/dist/routing/postgres-checkpoint-adapter.js.map +1 -0
- package/dist/routing/redis-checkpoint-adapter.d.ts +34 -0
- package/dist/routing/redis-checkpoint-adapter.d.ts.map +1 -0
- package/dist/routing/redis-checkpoint-adapter.js +170 -0
- package/dist/routing/redis-checkpoint-adapter.js.map +1 -0
- package/dist/routing/types.d.ts +49 -0
- package/dist/routing/types.d.ts.map +1 -0
- package/dist/routing/types.js +3 -0
- package/dist/routing/types.js.map +1 -0
- package/dist/types/agent.d.ts +289 -0
- package/dist/types/agent.d.ts.map +1 -0
- package/dist/types/agent.js +78 -0
- package/dist/types/agent.js.map +1 -0
- package/dist/types/index.d.ts +343 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/generate-action-schema.d.ts +4 -0
- package/dist/utils/generate-action-schema.d.ts.map +1 -0
- package/dist/utils/generate-action-schema.js +46 -0
- package/dist/utils/generate-action-schema.js.map +1 -0
- package/dist/utils/header-builder.d.ts +12 -0
- package/dist/utils/header-builder.d.ts.map +1 -0
- package/dist/utils/header-builder.js +35 -0
- package/dist/utils/header-builder.js.map +1 -0
- package/dist/utils/logger.d.ts +27 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +45 -0
- package/dist/utils/logger.js.map +1 -0
- package/docs/.gitbook/assets/image (1).png +0 -0
- package/docs/.gitbook/assets/image (2).png +0 -0
- package/docs/.gitbook/assets/image (3).png +0 -0
- package/docs/.gitbook/assets/image (4).png +0 -0
- package/docs/.gitbook/assets/image (5).png +0 -0
- package/docs/.gitbook/assets/image (6).png +0 -0
- package/docs/.gitbook/assets/image.png +0 -0
- package/docs/README.md +57 -0
- package/docs/SUMMARY.md +34 -0
- package/docs/cas-dusages.md +69 -0
- package/docs/cli/README.md +65 -0
- package/docs/concepts-cles.md +50 -0
- package/docs/core/architecture.md +87 -0
- package/docs/core/benchmark.md +59 -0
- package/docs/core/checkpoint.md +72 -0
- package/docs/core/documentation.md +55 -0
- package/docs/core/graphcontroller.md +63 -0
- package/docs/core/graphflow.md +137 -0
- package/docs/core/introduction.md +41 -0
- package/docs/core/les-evenements.md +95 -0
- package/docs/modules/agenda/README.md +63 -0
- package/docs/modules/agenda/interface-iagenda.md +170 -0
- package/docs/modules/agenda/les-adaptateurs/README.md +237 -0
- package/docs/modules/agenda/les-adaptateurs/nodecronadapter.md +91 -0
- package/docs/modules/introduction.md +55 -0
- package/docs/modules/les-adaptateurs.md +52 -0
- package/docs/modules/memoire/README.md +68 -0
- package/docs/modules/memoire/interface-imemory.md +183 -0
- package/docs/modules/memoire/les-adaptateurs/README.md +209 -0
- package/docs/modules/memoire/les-adaptateurs/inmemoryadapter.md +110 -0
- package/docs/modules/memoire/les-adaptateurs/meilisearchadapter.md +147 -0
- package/docs/modules/memoire/les-adaptateurs/redisadapter.md +212 -0
- package/docs/modules/nlp/README.md +44 -0
- package/docs/philosophie.md +51 -0
- package/docs/tutoriels/ajouter-des-conditions.md +150 -0
- package/docs/tutoriels/branching.md +194 -0
- package/docs/tutoriels/checkpoint-usage.md +99 -0
- package/docs/tutoriels/creer-agent-onchain.md +1041 -0
- package/docs/tutoriels/creer-un-agent.md +108 -0
- package/docs/tutoriels/creer-un-graphe-simple.md +92 -0
- package/docs/tutoriels/gerer-les-erreurs.md +124 -0
- package/docs/tutoriels/pour-commencer.md +73 -0
- package/docs/tutoriels/retry.md +166 -0
- package/execution/adapters/in-memory-checkpoint.ts +35 -0
- package/execution/compiler.ts +47 -0
- package/execution/controller.ts +84 -0
- package/execution/event-manager.ts +331 -0
- package/execution/index.ts +800 -0
- package/execution/logger.ts +70 -0
- package/execution/node.ts +315 -0
- package/execution/observer.ts +192 -0
- package/execution/planner.ts +40 -0
- package/execution/reducer.ts +73 -0
- package/execution/registry.ts +86 -0
- package/execution/send-api.ts +58 -0
- package/execution/types.parallel.ts +81 -0
- package/execution/visualizer.ts +158 -0
- package/index.ts +55 -465
- package/interfaces/index.ts +597 -0
- package/modules/agenda/adapters/node-cron/index.ts +25 -0
- package/modules/agenda/index.ts +146 -0
- package/modules/cli/index.ts +580 -0
- package/modules/embedding/adapters/ai/index.ts +42 -0
- package/modules/embedding/index.ts +45 -0
- package/modules/nlp/engine.ts +324 -0
- package/modules/nlp/index.ts +45 -0
- package/package.json +81 -9
- package/persistence/index.ts +27 -0
- package/persistence/neo4j/driver.ts +34 -0
- package/persistence/neo4j/entity-store.ts +141 -0
- package/persistence/neo4j/execution-tracer.ts +194 -0
- package/persistence/neo4j/memory-adapter.ts +281 -0
- package/persistence/neo4j/petri-checkpoint-adapter.ts +153 -0
- package/pipeline/agent-pipeline.ts +426 -0
- package/routing/checkpoint-adapter.ts +79 -0
- package/routing/documentation-generator.ts +358 -0
- package/routing/index.ts +459 -0
- package/routing/intent-classifier.ts +360 -0
- package/routing/matrix.ts +138 -0
- package/routing/orchestrator.ts +498 -0
- package/routing/patterns/data-extraction.json +79 -0
- package/routing/patterns/human-approval.json +64 -0
- package/routing/patterns/rag-search.json +68 -0
- package/routing/postgres-checkpoint-adapter.ts +172 -0
- package/routing/redis-checkpoint-adapter.ts +187 -0
- package/routing/types.ts +59 -0
- package/routing/web-server.ts +260 -0
- package/scripts/generate-petri-docs.ts +70 -0
- package/scripts/get-gmail-token.js +65 -0
- package/scripts/get-gmail-token.ts +65 -0
- package/test/agent/agent.test.ts +92 -0
- package/test/agent/clone.test.ts +143 -0
- package/test/agent/cognitive-handler.test.ts +78 -0
- package/test/agent/entity-store.test.ts +80 -0
- package/test/agent/generic-executor.test.ts +230 -0
- package/test/agent/handoff.test.ts +163 -0
- package/test/agent/llm-factory.test.ts +40 -0
- package/test/agent/orchestrator.test.ts +156 -0
- package/test/agent/registry.test.ts +97 -0
- package/test/agent/tools.test.ts +267 -0
- package/test/execution/checkpoint.test.ts +811 -0
- package/test/execution/controller.test.ts +236 -0
- package/test/execution/event-manager.test.ts +118 -0
- package/test/execution/index.test.ts +690 -0
- package/test/execution/node.test.ts +464 -0
- package/test/execution/observer.test.ts +393 -0
- package/test/execution/parallel.test.ts +135 -0
- package/test/execution/plan-llm-integration.test.ts +290 -0
- package/test/execution/plan-real-onchain.test.ts +226 -0
- package/test/execution/send-api.test.ts +121 -0
- package/test/modules/agenda/node-cron.test.ts +307 -0
- package/test/modules/cli/index.test.ts +125 -0
- package/test/persistence/neo4j-execution-tracer.test.ts +96 -0
- package/test/persistence/neo4j-memory-adapter.test.ts +107 -0
- package/test/persistence/neo4j-petri-checkpoint.test.ts +89 -0
- package/test/pipeline/agent-pipeline.test.ts +118 -0
- package/test/routing/checkpoint-persistence.test.ts +58 -0
- package/test/routing/documentation-generator.test.ts +76 -0
- package/test/routing/integration.test.ts +261 -0
- package/test/routing/intent-classifier.test.ts +102 -0
- package/test/routing/petri.test.ts +156 -0
- package/test/routing/real-llm.test.ts +260 -0
- package/test-petri-features.ts +218 -0
- package/test-pipeline-api.ts +163 -0
- package/tsconfig.json +30 -108
- package/types/agent.ts +296 -0
- package/types/index.ts +387 -0
- package/utils/generate-action-schema.ts +47 -0
- package/utils/header-builder.ts +40 -0
- package/utils/logger.ts +40 -0
- package/package copy.json +0 -21
- package/types.ts +0 -62
- package/utils/executor.ts +0 -42
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import { describe, it } from 'mocha';
|
|
3
|
+
import { IntentClassifier, IntentClassifierFn } from '../../routing/intent-classifier';
|
|
4
|
+
|
|
5
|
+
describe('IntentClassifier', () => {
|
|
6
|
+
it('should classify a simple intent', async () => {
|
|
7
|
+
const mockLLM = async (prompt: string) => {
|
|
8
|
+
return JSON.stringify({
|
|
9
|
+
intent: 'APPROVE',
|
|
10
|
+
confidence: 0.95,
|
|
11
|
+
entities: { id: 'task_123' },
|
|
12
|
+
});
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const classifier = new IntentClassifier(mockLLM);
|
|
16
|
+
const result = await classifier.classify('Approve task T-123');
|
|
17
|
+
|
|
18
|
+
expect(result.intent).to.equal('APPROVE');
|
|
19
|
+
expect(result.confidence).to.be.above(0.9);
|
|
20
|
+
expect(result.entities).to.deep.equal({ id: 'task_123' });
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should return UNKNOWN on LLM failure', async () => {
|
|
24
|
+
const mockLLM = async (prompt: string) => {
|
|
25
|
+
throw new Error('LLM unavailable');
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
const classifier = new IntentClassifier(mockLLM);
|
|
29
|
+
const result = await classifier.classify('Some message');
|
|
30
|
+
|
|
31
|
+
expect(result.intent).to.equal('UNKNOWN');
|
|
32
|
+
expect(result.confidence).to.equal(0);
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should handle low confidence (ambiguity)', async () => {
|
|
36
|
+
const mockLLM = async (prompt: string) => {
|
|
37
|
+
return JSON.stringify({
|
|
38
|
+
intent: 'QUERY',
|
|
39
|
+
confidence: 0.4,
|
|
40
|
+
entities: {},
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
const classifier = new IntentClassifier(mockLLM, {
|
|
45
|
+
confidenceThreshold: 0.6,
|
|
46
|
+
});
|
|
47
|
+
const result = await classifier.classify('What is the status?');
|
|
48
|
+
expect(result.confidence).to.be.below(0.6);
|
|
49
|
+
expect(classifier.getConfidenceThreshold()).to.equal(0.6);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('should include turn history in context', async () => {
|
|
53
|
+
let capturedPrompt = '';
|
|
54
|
+
const mockLLM = async (prompt: string) => {
|
|
55
|
+
capturedPrompt = prompt;
|
|
56
|
+
return JSON.stringify({
|
|
57
|
+
intent: 'CANCEL',
|
|
58
|
+
confidence: 0.85,
|
|
59
|
+
entities: {},
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const classifier = new IntentClassifier(mockLLM);
|
|
64
|
+
await classifier.classify('Cancel my order', {
|
|
65
|
+
turnHistory: ['I want to order', 'Here is your order #456'],
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
expect(capturedPrompt).to.include('order #456');
|
|
69
|
+
expect(capturedPrompt).to.include('Recent history');
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('should use custom intents list', async () => {
|
|
73
|
+
const mockLLM = async (prompt: string) => {
|
|
74
|
+
return JSON.stringify({
|
|
75
|
+
intent: 'GREETING',
|
|
76
|
+
confidence: 0.9,
|
|
77
|
+
entities: {},
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const classifier = new IntentClassifier(mockLLM, {
|
|
82
|
+
intents: ['GREETING', 'FAREWELL', 'UNKNOWN'],
|
|
83
|
+
});
|
|
84
|
+
const result = await classifier.classify('Hello there!');
|
|
85
|
+
expect(result.intent).to.equal('GREETING');
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it('should work as IntentClassifierFn', async () => {
|
|
89
|
+
const mockLLM = async (prompt: string) => {
|
|
90
|
+
return JSON.stringify({
|
|
91
|
+
intent: 'APPROVE',
|
|
92
|
+
confidence: 0.9,
|
|
93
|
+
entities: {},
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
const classifier = new IntentClassifier(mockLLM);
|
|
98
|
+
const fn: IntentClassifierFn = IntentClassifier.toFn(classifier);
|
|
99
|
+
const result = await fn('Approve this', { turnHistory: ['Previous message'] });
|
|
100
|
+
expect(result.intent).to.equal('APPROVE');
|
|
101
|
+
});
|
|
102
|
+
});
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import { describe, it, beforeEach } from 'mocha';
|
|
3
|
+
import { PetriNet } from '../../routing/index';
|
|
4
|
+
import { Transition, Token } from '../../routing/types';
|
|
5
|
+
|
|
6
|
+
describe('PetriNet', () => {
|
|
7
|
+
let net: PetriNet;
|
|
8
|
+
|
|
9
|
+
beforeEach(() => {
|
|
10
|
+
net = new PetriNet('test');
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
it('should create an empty net', () => {
|
|
14
|
+
expect(net.name).to.equal('test');
|
|
15
|
+
expect(net.places.size).to.equal(0);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
it('should add places and initial tokens', () => {
|
|
19
|
+
net.addPlace({ id: 'start', type: 'initial', tokens: [] });
|
|
20
|
+
net.addPlace({
|
|
21
|
+
id: 'p1',
|
|
22
|
+
type: 'normal',
|
|
23
|
+
tokens: [{ id: 't1', data: {}, createdAt: Date.now() }],
|
|
24
|
+
});
|
|
25
|
+
expect(net.places.get('start')!.tokens).to.be.empty;
|
|
26
|
+
expect(net.places.get('p1')!.tokens).to.have.lengthOf(1);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should fire a transition and move tokens', async () => {
|
|
30
|
+
net.addPlace({
|
|
31
|
+
id: 'start',
|
|
32
|
+
type: 'initial',
|
|
33
|
+
tokens: [{ id: 't0', data: { value: 10 }, createdAt: 0 }],
|
|
34
|
+
});
|
|
35
|
+
net.addPlace({ id: 'end', type: 'final', tokens: [] });
|
|
36
|
+
net.addTransition({ id: 't1', from: ['start'], to: 'end' });
|
|
37
|
+
|
|
38
|
+
const res = await net.fireTransition('t1');
|
|
39
|
+
expect(res.success).to.be.true;
|
|
40
|
+
expect(res.consumedTokens).to.have.lengthOf(1);
|
|
41
|
+
expect(res.producedTokens).to.have.lengthOf(1);
|
|
42
|
+
expect(res.producedTokens[0].data).to.deep.equal({ value: 10 });
|
|
43
|
+
expect(net.state.marking.get('start')!).to.be.empty;
|
|
44
|
+
expect(net.state.marking.get('end')!).to.have.lengthOf(1);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should detect deadlock when no transition enabled', () => {
|
|
48
|
+
const net2 = new PetriNet('dead');
|
|
49
|
+
net2.addPlace({
|
|
50
|
+
id: 'p',
|
|
51
|
+
type: 'initial',
|
|
52
|
+
tokens: [{ id: 't', data: {}, createdAt: 0 }],
|
|
53
|
+
});
|
|
54
|
+
expect(net2.detectDeadlock()).to.be.true;
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should pass boundedness for a safe workflow', () => {
|
|
58
|
+
net.addPlace({ id: 'start', type: 'initial', tokens: [] });
|
|
59
|
+
net.addPlace({ id: 'p1', type: 'normal', tokens: [] });
|
|
60
|
+
net.addPlace({ id: 'p2', type: 'normal', tokens: [] });
|
|
61
|
+
net.addPlace({ id: 'end', type: 'final', tokens: [] });
|
|
62
|
+
|
|
63
|
+
net.addTransition({ id: 't1', from: ['start'], to: ['p1', 'p2'] });
|
|
64
|
+
net.addTransition({ id: 't2', from: ['p1', 'p2'], to: 'end' });
|
|
65
|
+
|
|
66
|
+
const result = net.validateBoundedness();
|
|
67
|
+
expect(result.bounded).to.be.true;
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
it('should detect unboundedness for a token generator', () => {
|
|
71
|
+
const net2 = new PetriNet('unbounded');
|
|
72
|
+
net2.addPlace({
|
|
73
|
+
id: 'p',
|
|
74
|
+
type: 'normal',
|
|
75
|
+
tokens: [{ id: 't0', data: {}, createdAt: 0 }],
|
|
76
|
+
});
|
|
77
|
+
net2.addTransition({ id: 't1', from: [], to: 'p' });
|
|
78
|
+
|
|
79
|
+
const result = net2.validateBoundedness();
|
|
80
|
+
expect(result.bounded).to.be.false;
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('should evaluate deterministic guard', async () => {
|
|
84
|
+
net.addPlace({
|
|
85
|
+
id: 'start',
|
|
86
|
+
type: 'initial',
|
|
87
|
+
tokens: [{ id: 't0', data: { amount: 500 }, createdAt: 0 }],
|
|
88
|
+
});
|
|
89
|
+
net.addPlace({ id: 'ok', type: 'normal', tokens: [] });
|
|
90
|
+
net.addTransition({
|
|
91
|
+
id: 'check',
|
|
92
|
+
from: ['start'],
|
|
93
|
+
to: 'ok',
|
|
94
|
+
guard: { type: 'deterministic', condition: 'amount > 1000' },
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
const res = await net.fireTransition('check');
|
|
98
|
+
expect(res.success).to.be.false;
|
|
99
|
+
|
|
100
|
+
net.state.marking.get('start')![0].data.amount = 1500;
|
|
101
|
+
const res2 = await net.fireTransition('check');
|
|
102
|
+
expect(res2.success).to.be.true;
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it('should distribute tokens to multiple output places', async () => {
|
|
106
|
+
net.addPlace({
|
|
107
|
+
id: 'in',
|
|
108
|
+
type: 'initial',
|
|
109
|
+
tokens: [{ id: 't0', data: {}, createdAt: 0 }],
|
|
110
|
+
});
|
|
111
|
+
net.addPlace({ id: 'out1', type: 'normal', tokens: [] });
|
|
112
|
+
net.addPlace({ id: 'out2', type: 'normal', tokens: [] });
|
|
113
|
+
net.addTransition({ id: 'fork', from: ['in'], to: ['out1', 'out2'] });
|
|
114
|
+
|
|
115
|
+
await net.fireTransition('fork');
|
|
116
|
+
expect(net.state.marking.get('in')!).to.be.empty;
|
|
117
|
+
expect(net.state.marking.get('out1')!).to.have.lengthOf(1);
|
|
118
|
+
expect(net.state.marking.get('out2')!).to.have.lengthOf(1);
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('should fire transition with LLM guard and action', async () => {
|
|
122
|
+
net.addPlace({
|
|
123
|
+
id: 'start',
|
|
124
|
+
type: 'initial',
|
|
125
|
+
tokens: [{ id: 't0', data: { msg: 'hello' }, createdAt: 0 }],
|
|
126
|
+
});
|
|
127
|
+
net.addPlace({ id: 'end', type: 'final', tokens: [] });
|
|
128
|
+
|
|
129
|
+
const transition: Transition = {
|
|
130
|
+
id: 'process',
|
|
131
|
+
from: ['start'],
|
|
132
|
+
to: 'end',
|
|
133
|
+
guard: { type: 'llm_evaluated', condition: 'Is this valid?' },
|
|
134
|
+
action: { type: 'graphflow', name: 'echo' },
|
|
135
|
+
};
|
|
136
|
+
net.addTransition(transition);
|
|
137
|
+
|
|
138
|
+
let actionCalled = false;
|
|
139
|
+
net.setActionExecutor(async (action, ctx) => {
|
|
140
|
+
actionCalled = true;
|
|
141
|
+
expect(action.type).to.equal('graphflow');
|
|
142
|
+
expect(ctx.msg).to.equal('hello');
|
|
143
|
+
return { echoed: ctx.msg };
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
net.setLLMExecutor(async (prompt, ctx) => {
|
|
147
|
+
expect(prompt).to.equal('Is this valid?');
|
|
148
|
+
return true;
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
const res = await net.fireTransitionWithAction('process');
|
|
152
|
+
expect(res.success).to.be.true;
|
|
153
|
+
expect(actionCalled).to.be.true;
|
|
154
|
+
expect(res.actionResult).to.deep.equal({ echoed: 'hello' });
|
|
155
|
+
});
|
|
156
|
+
});
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { expect } from 'chai';
|
|
2
|
+
import { describe, it, beforeEach } from 'mocha';
|
|
3
|
+
import { CortexFlowOrchestrator } from '../../routing/orchestrator';
|
|
4
|
+
import { PetriNet, TransitionAction } from '../../routing/index';
|
|
5
|
+
import { ToolRegistry } from '../../execution/registry';
|
|
6
|
+
import { GraphFlow } from '../../execution/index';
|
|
7
|
+
import { z } from 'zod';
|
|
8
|
+
import { IntentClassifier, IntentClassifierFn } from '../../routing/intent-classifier';
|
|
9
|
+
import { google } from 'googleapis';
|
|
10
|
+
import fs from 'fs';
|
|
11
|
+
import path from 'path';
|
|
12
|
+
|
|
13
|
+
// Helper: create LLM call using Ollama
|
|
14
|
+
function createOllamaCall(model = 'llama3:latest') {
|
|
15
|
+
return async (prompt: string) => {
|
|
16
|
+
const response = await fetch('http://localhost:11434/api/generate', {
|
|
17
|
+
method: 'POST',
|
|
18
|
+
headers: { 'Content-Type': 'application/json' },
|
|
19
|
+
body: JSON.stringify({
|
|
20
|
+
model,
|
|
21
|
+
prompt,
|
|
22
|
+
stream: false,
|
|
23
|
+
format: 'json',
|
|
24
|
+
}),
|
|
25
|
+
signal: AbortSignal.timeout(30000),
|
|
26
|
+
});
|
|
27
|
+
if (!response.ok) throw new Error(`HTTP ${response.status}`);
|
|
28
|
+
const data = await response.json();
|
|
29
|
+
return data.response;
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Helper: create Gmail client using token
|
|
34
|
+
function createGmailClient() {
|
|
35
|
+
const tokenPath = path.join(__dirname, '../../gmail_token.json');
|
|
36
|
+
if (!fs.existsSync(tokenPath)) {
|
|
37
|
+
throw new Error('gmail_token.json not found. Run: node scripts/get-gmail-token.js');
|
|
38
|
+
}
|
|
39
|
+
const credentials = JSON.parse(fs.readFileSync(path.join(__dirname, '../../client_secret.json'), 'utf8'));
|
|
40
|
+
const token = JSON.parse(fs.readFileSync(tokenPath, 'utf8'));
|
|
41
|
+
|
|
42
|
+
const oauth2Client = new google.auth.OAuth2(
|
|
43
|
+
credentials.web.client_id,
|
|
44
|
+
credentials.web.client_secret,
|
|
45
|
+
'http://localhost:3000/oauth2callback'
|
|
46
|
+
);
|
|
47
|
+
oauth2Client.setCredentials(token);
|
|
48
|
+
return google.gmail({ version: 'v1', auth: oauth2Client });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
describe('CortexFlow Real LLM Test (Ollama/Llama 3)', function() {
|
|
52
|
+
this.timeout(120000);
|
|
53
|
+
|
|
54
|
+
let orchestrator: CortexFlowOrchestrator;
|
|
55
|
+
let toolRegistry: ToolRegistry;
|
|
56
|
+
|
|
57
|
+
beforeEach(() => {
|
|
58
|
+
toolRegistry = new ToolRegistry();
|
|
59
|
+
orchestrator = new CortexFlowOrchestrator('mail_assistant', toolRegistry);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
it('should classify intent with real LLM', async function() {
|
|
63
|
+
try {
|
|
64
|
+
const checkResp = await fetch('http://localhost:11434/api/tags', { signal: AbortSignal.timeout(3000) });
|
|
65
|
+
if (!checkResp.ok) throw new Error('Ollama not accessible');
|
|
66
|
+
} catch (e) {
|
|
67
|
+
console.log('⚠️ Ollama API not accessible, skipping real LLM test');
|
|
68
|
+
this.skip();
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const llmCall = createOllamaCall();
|
|
73
|
+
const classifier = new IntentClassifier(llmCall, {
|
|
74
|
+
intents: ['FETCH_MAILS', 'SUMMARIZE', 'APPROVE', 'REJECT', 'UNKNOWN'],
|
|
75
|
+
confidenceThreshold: 0.6,
|
|
76
|
+
});
|
|
77
|
+
orchestrator.setIntentClassifier(IntentClassifier.toFn(classifier), classifier);
|
|
78
|
+
|
|
79
|
+
const result = await orchestrator.orchestrate('Please summarize my 5 latest mails');
|
|
80
|
+
expect(result.intent.intent).to.not.equal('UNKNOWN');
|
|
81
|
+
expect(result.intent.confidence).to.be.above(0.5);
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
it('should handle low confidence with real LLM', async function() {
|
|
85
|
+
try {
|
|
86
|
+
const checkResp = await fetch('http://localhost:11434/api/tags', { signal: AbortSignal.timeout(3000) });
|
|
87
|
+
if (!checkResp.ok) throw new Error('Ollama not accessible');
|
|
88
|
+
} catch (e) {
|
|
89
|
+
console.log('⚠️ Ollama not available, skipping');
|
|
90
|
+
this.skip();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
const llmCall = createOllamaCall();
|
|
95
|
+
const classifier = new IntentClassifier(llmCall, {
|
|
96
|
+
confidenceThreshold: 0.9,
|
|
97
|
+
});
|
|
98
|
+
orchestrator.setIntentClassifier(IntentClassifier.toFn(classifier), classifier);
|
|
99
|
+
|
|
100
|
+
console.log('\n🚀 Testing low confidence handling with Ollama...');
|
|
101
|
+
const sessionId = orchestrator.startSession();
|
|
102
|
+
|
|
103
|
+
const result = await orchestrator.orchestrate(
|
|
104
|
+
'asdfghjkl qwertyuiop', // Nonsense input
|
|
105
|
+
sessionId
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
console.log('\n📊 Result:', {
|
|
109
|
+
intent: result.intent,
|
|
110
|
+
confidence: result.intent.confidence,
|
|
111
|
+
needsClarification: result.needsClarification,
|
|
112
|
+
clarificationQuestion: result.clarificationQuestion,
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
expect(result.needsClarification).to.be.true;
|
|
116
|
+
expect(result.clarificationQuestion).to.be.a('string').and.not.empty;
|
|
117
|
+
|
|
118
|
+
console.log('✅ Low confidence handling works!\n');
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it('should fetch 5 real mails and summarize with LLM', async function() {
|
|
122
|
+
// Check Ollama
|
|
123
|
+
try {
|
|
124
|
+
const checkResp = await fetch('http://localhost:11434/api/tags', { signal: AbortSignal.timeout(3000) });
|
|
125
|
+
if (!checkResp.ok) throw new Error('Ollama not accessible');
|
|
126
|
+
} catch (e) {
|
|
127
|
+
console.log('⚠️ Ollama not available, skipping');
|
|
128
|
+
this.skip();
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// Check Gmail token
|
|
133
|
+
if (!fs.existsSync(path.join(__dirname, '../../gmail_token.json'))) {
|
|
134
|
+
console.log('⚠️ gmail_token.json not found, skipping');
|
|
135
|
+
this.skip();
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// Check if Gmail API is enabled
|
|
140
|
+
try {
|
|
141
|
+
const gmail = createGmailClient();
|
|
142
|
+
await gmail.users.getProfile({ userId: 'me' });
|
|
143
|
+
} catch (error: any) {
|
|
144
|
+
if (error.code === 403) {
|
|
145
|
+
console.log('⚠️ Gmail API not enabled. Enable at: https://console.developers.google.com/apis/api/gmail.googleapis.com/overview?project=266761775636');
|
|
146
|
+
this.skip();
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const llmCall = createOllamaCall();
|
|
152
|
+
const gmail = createGmailClient();
|
|
153
|
+
const classifier = new IntentClassifier(llmCall, {
|
|
154
|
+
intents: ['FETCH_MAILS', 'SUMMARIZE', 'UNKNOWN'],
|
|
155
|
+
confidenceThreshold: 0.6,
|
|
156
|
+
});
|
|
157
|
+
orchestrator.setIntentClassifier(IntentClassifier.toFn(classifier), classifier);
|
|
158
|
+
orchestrator.setLLMCall(llmCall);
|
|
159
|
+
|
|
160
|
+
// Setup Petri net
|
|
161
|
+
const net = orchestrator.petri;
|
|
162
|
+
net.addPlace({ id: 'idle', type: 'initial', tokens: [{ id: 'start', data: {}, createdAt: 0 }] });
|
|
163
|
+
net.addPlace({ id: 'processing', type: 'normal', tokens: [] });
|
|
164
|
+
net.addPlace({ id: 'done', type: 'final', tokens: [] });
|
|
165
|
+
|
|
166
|
+
// Create GraphFlow that fetches real mails and summarizes
|
|
167
|
+
const mailGraph = new GraphFlow<any>({
|
|
168
|
+
name: 'mail_fetch_summarize',
|
|
169
|
+
context: { maxMails: 5 },
|
|
170
|
+
schema: z.object({ maxMails: z.number() }).passthrough(),
|
|
171
|
+
nodes: [
|
|
172
|
+
{
|
|
173
|
+
name: 'fetch_mails',
|
|
174
|
+
execute: async (ctx: any) => {
|
|
175
|
+
console.log(' [fetch_mails] Fetching mails from Gmail API...');
|
|
176
|
+
const res = await gmail.users.messages.list({
|
|
177
|
+
userId: 'me',
|
|
178
|
+
maxResults: ctx.maxMails || 5,
|
|
179
|
+
q: '',
|
|
180
|
+
});
|
|
181
|
+
const messages = res.data.messages || [];
|
|
182
|
+
ctx.fetchedMails = [];
|
|
183
|
+
for (const msg of messages) {
|
|
184
|
+
const detail = await gmail.users.messages.get({
|
|
185
|
+
userId: 'me',
|
|
186
|
+
id: msg.id!,
|
|
187
|
+
format: 'metadata',
|
|
188
|
+
metadataHeaders: ['Subject', 'From'],
|
|
189
|
+
});
|
|
190
|
+
const headers = detail.data.payload?.headers || [];
|
|
191
|
+
ctx.fetchedMails.push({
|
|
192
|
+
id: msg.id,
|
|
193
|
+
subject: headers.find(h => h.name === 'Subject')?.value || '(no subject)',
|
|
194
|
+
from: headers.find(h => h.name === 'From')?.value || '(unknown)',
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
console.log(` [fetch_mails] Fetched ${ctx.fetchedMails.length} mails`);
|
|
198
|
+
},
|
|
199
|
+
next: 'summarize',
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
name: 'summarize',
|
|
203
|
+
execute: async (ctx: any) => {
|
|
204
|
+
console.log(' [summarize] Summarizing with LLM...');
|
|
205
|
+
const mailText = ctx.fetchedMails.map((m: any) => `From: ${m.from}\nSubject: ${m.subject}`).join('\n\n');
|
|
206
|
+
const prompt = `Summarize these emails in 3 bullet points max:\n\n${mailText}\n\nRespond in JSON: {"summary": "..."}`;
|
|
207
|
+
const response = await llmCall(prompt);
|
|
208
|
+
const parsed = JSON.parse(response);
|
|
209
|
+
ctx.summary = parsed.summary;
|
|
210
|
+
console.log(` [summarize] Summary: ${ctx.summary}`);
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
],
|
|
214
|
+
entryNode: 'fetch_mails',
|
|
215
|
+
});
|
|
216
|
+
|
|
217
|
+
toolRegistry.register({
|
|
218
|
+
name: 'mail_fetch_summarize',
|
|
219
|
+
description: 'Fetch and summarize mails from Gmail',
|
|
220
|
+
graph: mailGraph,
|
|
221
|
+
startNode: 'fetch_mails',
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
net.addTransition({
|
|
225
|
+
id: 'process_mails',
|
|
226
|
+
from: ['idle'],
|
|
227
|
+
to: 'processing',
|
|
228
|
+
action: {
|
|
229
|
+
type: 'graphflow',
|
|
230
|
+
name: 'mail_fetch_summarize',
|
|
231
|
+
contextMapper: (ctx) => ({ maxMails: ctx.maxMails || 5 }),
|
|
232
|
+
} as TransitionAction,
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
net.addTransition({
|
|
236
|
+
id: 'complete',
|
|
237
|
+
from: ['processing'],
|
|
238
|
+
to: 'done',
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
console.log('\n🚀 Starting real Gmail + LLM test...');
|
|
242
|
+
const sessionId = orchestrator.startSession();
|
|
243
|
+
|
|
244
|
+
const result = await orchestrator.orchestrate(
|
|
245
|
+
'Please fetch my 5 latest mails and summarize them',
|
|
246
|
+
sessionId
|
|
247
|
+
);
|
|
248
|
+
|
|
249
|
+
console.log('\n📊 Result:', {
|
|
250
|
+
intent: result.intent,
|
|
251
|
+
needsClarification: result.needsClarification,
|
|
252
|
+
});
|
|
253
|
+
|
|
254
|
+
expect(result.intent.intent).to.not.equal('UNKNOWN');
|
|
255
|
+
expect(result.needsClarification).to.be.false;
|
|
256
|
+
expect((result as any).transitionResult).to.exist;
|
|
257
|
+
|
|
258
|
+
console.log('✅ Real Gmail + LLM test passed!\n');
|
|
259
|
+
});
|
|
260
|
+
});
|