@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,260 @@
|
|
|
1
|
+
import express from 'express';
|
|
2
|
+
import { createServer } from 'http';
|
|
3
|
+
import { Server } from 'socket.io';
|
|
4
|
+
import * as path from 'path';
|
|
5
|
+
import { PetriNet } from '../routing/index';
|
|
6
|
+
import { CortexFlowOrchestrator } from '../routing/orchestrator';
|
|
7
|
+
import { ToolRegistry } from '../execution/registry';
|
|
8
|
+
|
|
9
|
+
export class PetriWebServer {
|
|
10
|
+
private app: express.Application;
|
|
11
|
+
private server: any;
|
|
12
|
+
private io: any;
|
|
13
|
+
private orchestrator?: CortexFlowOrchestrator;
|
|
14
|
+
private sessionId?: string;
|
|
15
|
+
|
|
16
|
+
constructor(private port: number = 3001) {
|
|
17
|
+
this.app = express();
|
|
18
|
+
this.server = createServer(this.app);
|
|
19
|
+
this.io = new Server(this.server);
|
|
20
|
+
this.setupRoutes();
|
|
21
|
+
this.setupSocket();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
setOrchestrator(orchestrator: CortexFlowOrchestrator, sessionId?: string) {
|
|
25
|
+
this.orchestrator = orchestrator;
|
|
26
|
+
this.sessionId = sessionId;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
private setupRoutes() {
|
|
30
|
+
// Serve static HTML
|
|
31
|
+
this.app.get('/', (_req, res) => {
|
|
32
|
+
res.send(this.getHTML());
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
// API: Get current state
|
|
36
|
+
this.app.get('/api/state', (_req, res) => {
|
|
37
|
+
if (!this.orchestrator) {
|
|
38
|
+
res.json({ error: 'No orchestrator set' });
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const net = this.orchestrator.petri;
|
|
42
|
+
const marking = (net as any).state.marking as Map<string, any[]>;
|
|
43
|
+
const places = Array.from(net.places.entries()).map(([id, place]) => ({
|
|
44
|
+
id,
|
|
45
|
+
type: place.type,
|
|
46
|
+
tokens: marking.get(id)?.length || 0,
|
|
47
|
+
tokenDetails: marking.get(id) || [],
|
|
48
|
+
}));
|
|
49
|
+
const transitions = Array.from(net.transitions.entries()).map(([id, trans]) => ({
|
|
50
|
+
id,
|
|
51
|
+
from: trans.from,
|
|
52
|
+
to: trans.to,
|
|
53
|
+
description: (trans as any).description || id,
|
|
54
|
+
}));
|
|
55
|
+
const enabled = net.getEnabledTransitions();
|
|
56
|
+
|
|
57
|
+
res.json({
|
|
58
|
+
name: net.name,
|
|
59
|
+
places,
|
|
60
|
+
transitions,
|
|
61
|
+
enabledTransitions: enabled,
|
|
62
|
+
history: (net as any).state.history || [],
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// API: Fire transition
|
|
67
|
+
this.app.post('/api/fire/:transitionId', async (req, res) => {
|
|
68
|
+
if (!this.orchestrator || !this.sessionId) {
|
|
69
|
+
res.json({ error: 'No orchestrator/session' });
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
const result = await this.orchestrator.fire(req.params.transitionId, this.sessionId);
|
|
74
|
+
this.io.emit('stateUpdate', await this.getState());
|
|
75
|
+
res.json(result);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
res.json({ error: (error as Error).message });
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
// API: Get DOT
|
|
82
|
+
this.app.get('/api/dot', (_req, res) => {
|
|
83
|
+
if (!this.orchestrator) {
|
|
84
|
+
res.json({ error: 'No orchestrator set' });
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
res.type('text/vnd.graphviz').send(this.orchestrator.petri.toDot());
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private setupSocket() {
|
|
92
|
+
this.io.on('connection', (socket: any) => {
|
|
93
|
+
console.log('Web client connected');
|
|
94
|
+
socket.emit('stateUpdate', this.getState());
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
private async getState() {
|
|
99
|
+
if (!this.orchestrator) return { error: 'No orchestrator set' };
|
|
100
|
+
const net = this.orchestrator.petri;
|
|
101
|
+
const marking = (net as any).state.marking as Map<string, any[]>;
|
|
102
|
+
const places = Array.from(net.places.entries()).map(([id, place]) => ({
|
|
103
|
+
id,
|
|
104
|
+
type: place.type,
|
|
105
|
+
tokens: marking.get(id)?.length || 0,
|
|
106
|
+
tokenDetails: marking.get(id) || [],
|
|
107
|
+
}));
|
|
108
|
+
const transitions = Array.from(net.transitions.entries()).map(([id, trans]) => ({
|
|
109
|
+
id,
|
|
110
|
+
from: trans.from,
|
|
111
|
+
to: trans.to,
|
|
112
|
+
description: (trans as any).description || id,
|
|
113
|
+
}));
|
|
114
|
+
const enabled = net.getEnabledTransitions();
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
name: net.name,
|
|
118
|
+
places,
|
|
119
|
+
transitions,
|
|
120
|
+
enabledTransitions: enabled,
|
|
121
|
+
history: (net as any).state.history || [],
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
start() {
|
|
126
|
+
this.server.listen(this.port, () => {
|
|
127
|
+
console.log(`🌐 Petri Web Interface running at http://localhost:${this.port}`);
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
stop() {
|
|
132
|
+
this.server.close();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
private getHTML(): string {
|
|
136
|
+
return `<!DOCTYPE html>
|
|
137
|
+
<html>
|
|
138
|
+
<head>
|
|
139
|
+
<title>CortexFlow Petri Visualizer</title>
|
|
140
|
+
<script src="https://cdn.socket.io/4.7.2/socket.io.min.js"></script>
|
|
141
|
+
<script src="https://cdn.jsdelivr.net/npm/viz.js@2.1.2/viz.js"></script>
|
|
142
|
+
<script src="https://cdn.jsdelivr.net/npm/viz.js@2.1.2/full.render.js"></script>
|
|
143
|
+
<style>
|
|
144
|
+
body { font-family: Arial, sans-serif; margin: 20px; background: #f5f5f5; }
|
|
145
|
+
.container { display: flex; gap: 20px; }
|
|
146
|
+
.panel { background: white; padding: 20px; border-radius: 8px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
|
|
147
|
+
.left { flex: 1; }
|
|
148
|
+
.right { flex: 2; }
|
|
149
|
+
h2 { margin-top: 0; color: #333; }
|
|
150
|
+
.place { padding: 10px; margin: 5px 0; background: #e3f2fd; border-left: 4px solid #2196F3; }
|
|
151
|
+
.place.initial { border-left-color: #4CAF50; }
|
|
152
|
+
.place.final { border-left-color: #F44336; }
|
|
153
|
+
.token-count { display: inline-block; background: #2196F3; color: white; border-radius: 50%; width: 24px; height: 24px; text-align: center; line-height: 24px; margin-left: 10px; }
|
|
154
|
+
.transition { padding: 10px; margin: 5px 0; background: #fff3e0; border-left: 4px solid #FF9800; cursor: pointer; }
|
|
155
|
+
.transition.enabled { background: #e8f5e9; border-left-color: #4CAF50; }
|
|
156
|
+
.dot-container { background: white; padding: 10px; border: 1px solid #ddd; min-height: 400px; }
|
|
157
|
+
button { padding: 8px 16px; margin: 5px; cursor: pointer; background: #2196F3; color: white; border: none; border-radius: 4px; }
|
|
158
|
+
button:hover { background: #1976D2; }
|
|
159
|
+
.history { font-size: 12px; color: #666; max-height: 200px; overflow-y: auto; }
|
|
160
|
+
</style>
|
|
161
|
+
</head>
|
|
162
|
+
<body>
|
|
163
|
+
<h1>🕸 CortexFlow Petri Visualizer</h1>
|
|
164
|
+
<div class="container">
|
|
165
|
+
<div class="panel left">
|
|
166
|
+
<h2>Places & Tokens</h2>
|
|
167
|
+
<div id="places"></div>
|
|
168
|
+
<h2>Transitions</h2>
|
|
169
|
+
<div id="transitions"></div>
|
|
170
|
+
<h2>History</h2>
|
|
171
|
+
<div id="history" class="history"></div>
|
|
172
|
+
</div>
|
|
173
|
+
<div class="panel right">
|
|
174
|
+
<h2>Graph Visualization (DOT)</h2>
|
|
175
|
+
<div>
|
|
176
|
+
<button onclick="refreshDot()">Refresh DOT</button>
|
|
177
|
+
<button onclick="fireTransition(prompt('Transition ID?'))">Fire Transition</button>
|
|
178
|
+
</div>
|
|
179
|
+
<div id="dot" class="dot-container"></div>
|
|
180
|
+
</div>
|
|
181
|
+
</div>
|
|
182
|
+
|
|
183
|
+
<script>
|
|
184
|
+
const socket = io();
|
|
185
|
+
let currentState = {};
|
|
186
|
+
|
|
187
|
+
socket.on('stateUpdate', (state) => {
|
|
188
|
+
currentState = state;
|
|
189
|
+
updatePlaces(state.places || []);
|
|
190
|
+
updateTransitions(state.transitions || [], state.enabledTransitions || []);
|
|
191
|
+
updateHistory(state.history || []);
|
|
192
|
+
updateDot();
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
function updatePlaces(places) {
|
|
196
|
+
const div = document.getElementById('places');
|
|
197
|
+
div.innerHTML = places.map(p => {
|
|
198
|
+
const cls = p.type === 'initial' ? 'initial' : p.type === 'final' ? 'final' : '';
|
|
199
|
+
return '<div class="place ' + cls + '">' +
|
|
200
|
+
'<strong>' + p.id + '</strong> (' + p.type + ')' +
|
|
201
|
+
'<span class="token-count">' + p.tokens + '</span>' +
|
|
202
|
+
'</div>';
|
|
203
|
+
}).join('');
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
function updateTransitions(transitions, enabled) {
|
|
207
|
+
const div = document.getElementById('transitions');
|
|
208
|
+
div.innerHTML = transitions.map(t => {
|
|
209
|
+
const isEnabled = enabled.includes(t.id);
|
|
210
|
+
return '<div class="transition ' + (isEnabled ? 'enabled' : '') + '" onclick="fireTransition(\'' + t.id + '\')">' +
|
|
211
|
+
'<strong>' + t.description + '</strong> (' + t.id + ')' +
|
|
212
|
+
(isEnabled ? ' ✅ ENABLED' : '') +
|
|
213
|
+
'</div>';
|
|
214
|
+
}).join('');
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
function updateHistory(history) {
|
|
218
|
+
const div = document.getElementById('history');
|
|
219
|
+
div.innerHTML = history.slice(-10).map((h, i) => (history.length - 10 + i) + ': ' + h).join('<br>');
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
function updateDot() {
|
|
223
|
+
fetch('/api/dot')
|
|
224
|
+
.then(r => r.text())
|
|
225
|
+
.then(dot => {
|
|
226
|
+
try {
|
|
227
|
+
const result = Viz(dot, { format: 'svg', engine: 'dot' });
|
|
228
|
+
document.getElementById('dot').innerHTML = result;
|
|
229
|
+
} catch (e) {
|
|
230
|
+
document.getElementById('dot').innerHTML = '<pre>' + dot + '</pre><p>Error rendering: ' + e + '</p>';
|
|
231
|
+
}
|
|
232
|
+
});
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
function fireTransition(id) {
|
|
236
|
+
if (!id) return;
|
|
237
|
+
fetch('/api/fire/' + id, { method: 'POST' })
|
|
238
|
+
.then(() => console.log('Fired:', id))
|
|
239
|
+
.catch(e => alert('Error: ' + e));
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
function refreshDot() {
|
|
243
|
+
updateDot();
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
// Initial load
|
|
247
|
+
fetch('/api/state')
|
|
248
|
+
.then(r => r.json())
|
|
249
|
+
.then(state => {
|
|
250
|
+
currentState = state;
|
|
251
|
+
updatePlaces(state.places || []);
|
|
252
|
+
updateTransitions(state.transitions || [], state.enabledTransitions || []);
|
|
253
|
+
updateHistory(state.history || []);
|
|
254
|
+
updateDot();
|
|
255
|
+
});
|
|
256
|
+
</script>
|
|
257
|
+
</body>
|
|
258
|
+
</html>`;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Generate living documentation for CortexFlow Petri nets
|
|
5
|
+
* Usage: npx ts-node scripts/generate-petri-docs.ts [petri-net.json] [output-dir]
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { PetriNet } from '../routing/index';
|
|
9
|
+
import { PetriDocumentationGenerator } from '../routing/documentation-generator';
|
|
10
|
+
import * as fs from 'fs';
|
|
11
|
+
import * as path from 'path';
|
|
12
|
+
|
|
13
|
+
async function main() {
|
|
14
|
+
const args = process.argv.slice(2);
|
|
15
|
+
|
|
16
|
+
if (args.length === 0) {
|
|
17
|
+
console.log('Usage: npx ts-node scripts/generate-petri-docs.ts <petri-net.json> [output-dir]');
|
|
18
|
+
console.log('');
|
|
19
|
+
console.log('Examples:');
|
|
20
|
+
console.log(' npx ts-node scripts/generate-petri-docs.ts examples/my-net.json');
|
|
21
|
+
console.log(' npx ts-node scripts/generate-petri-docs.ts examples/my-net.json ./docs');
|
|
22
|
+
process.exit(1);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const inputFile = args[0];
|
|
26
|
+
const outputDir = args[1] || './docs/petri';
|
|
27
|
+
|
|
28
|
+
if (!fs.existsSync(inputFile)) {
|
|
29
|
+
console.error(`Error: File not found: ${inputFile}`);
|
|
30
|
+
process.exit(1);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
console.log(`📖 Generating documentation for ${inputFile}...`);
|
|
34
|
+
|
|
35
|
+
// Load Petri net from JSON
|
|
36
|
+
const json = JSON.parse(fs.readFileSync(inputFile, 'utf8'));
|
|
37
|
+
|
|
38
|
+
const net = new PetriNet(json.name || path.basename(inputFile, '.json'));
|
|
39
|
+
|
|
40
|
+
// Add places
|
|
41
|
+
for (const place of json.places || []) {
|
|
42
|
+
net.addPlace(place);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Add transitions
|
|
46
|
+
for (const trans of json.transitions || []) {
|
|
47
|
+
net.addTransition(trans);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// Generate documentation
|
|
51
|
+
const generator = new PetriDocumentationGenerator();
|
|
52
|
+
await generator.generateForPetri(net, {
|
|
53
|
+
outputDir,
|
|
54
|
+
format: 'all', // Generate markdown + mermaid + html
|
|
55
|
+
includeHistory: true,
|
|
56
|
+
includeState: true,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
console.log(`✅ Documentation generated in ${outputDir}`);
|
|
60
|
+
console.log('');
|
|
61
|
+
console.log('Generated files:');
|
|
62
|
+
console.log(` - ${outputDir}/${net.name}.md`);
|
|
63
|
+
console.log(` - ${outputDir}/${net.name}-diagram.mmd`);
|
|
64
|
+
console.log(` - ${outputDir}/${net.name}.html`);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
main().catch(err => {
|
|
68
|
+
console.error('Error:', err.message);
|
|
69
|
+
process.exit(1);
|
|
70
|
+
});
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
const { google } = require('googleapis');
|
|
2
|
+
const http = require('http');
|
|
3
|
+
const { parse } = require('url');
|
|
4
|
+
const fs = require('fs');
|
|
5
|
+
const open = require('open').default || require('open');
|
|
6
|
+
|
|
7
|
+
const CLIENT_SECRET_PATH = './client_secret.json';
|
|
8
|
+
const TOKEN_PATH = './gmail_token.json';
|
|
9
|
+
|
|
10
|
+
async function getToken() {
|
|
11
|
+
const credentials = JSON.parse(fs.readFileSync(CLIENT_SECRET_PATH, 'utf8'));
|
|
12
|
+
const { client_id, client_secret } = credentials.web;
|
|
13
|
+
|
|
14
|
+
const oauth2Client = new google.auth.OAuth2(
|
|
15
|
+
client_id,
|
|
16
|
+
client_secret,
|
|
17
|
+
'http://localhost:3000/oauth2callback'
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const scopes = [
|
|
21
|
+
'https://www.googleapis.com/auth/gmail.readonly',
|
|
22
|
+
'https://www.googleapis.com/auth/gmail.modify',
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const authorizeUrl = oauth2Client.generateAuthUrl({
|
|
26
|
+
access_type: 'offline',
|
|
27
|
+
scope: scopes,
|
|
28
|
+
prompt: 'consent',
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
console.log('Opening browser for authorization...');
|
|
32
|
+
console.log('URL:', authorizeUrl);
|
|
33
|
+
|
|
34
|
+
await open(authorizeUrl);
|
|
35
|
+
|
|
36
|
+
const server = http.createServer(async (req, res) => {
|
|
37
|
+
const queryParams = parse(req.url, true).query;
|
|
38
|
+
const code = queryParams.code;
|
|
39
|
+
|
|
40
|
+
if (code) {
|
|
41
|
+
try {
|
|
42
|
+
const { tokens } = await oauth2Client.getToken(code);
|
|
43
|
+
fs.writeFileSync(TOKEN_PATH, JSON.stringify(tokens, null, 2));
|
|
44
|
+
|
|
45
|
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
46
|
+
res.end('<h1>Authorization successful!</h1><p>You can close this window.</p>');
|
|
47
|
+
|
|
48
|
+
console.log('Token saved to', TOKEN_PATH);
|
|
49
|
+
server.close();
|
|
50
|
+
process.exit(0);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error('Error getting tokens:', error);
|
|
53
|
+
res.writeHead(500);
|
|
54
|
+
res.end('Error');
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
server.listen(3000, () => {
|
|
61
|
+
console.log('Listening on http://localhost:3000');
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
getToken().catch(console.error);
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { google } from 'googleapis';
|
|
2
|
+
import http from 'http';
|
|
3
|
+
import { parse } from 'url';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import open from 'open';
|
|
6
|
+
|
|
7
|
+
const CLIENT_SECRET_PATH = './client_secret.json';
|
|
8
|
+
const TOKEN_PATH = './gmail_token.json';
|
|
9
|
+
|
|
10
|
+
async function getToken() {
|
|
11
|
+
const credentials = JSON.parse(fs.readFileSync(CLIENT_SECRET_PATH, 'utf8'));
|
|
12
|
+
const { client_id, client_secret } = credentials.web;
|
|
13
|
+
|
|
14
|
+
const oauth2Client = new google.auth.OAuth2(
|
|
15
|
+
client_id,
|
|
16
|
+
client_secret,
|
|
17
|
+
'http://localhost:3000/oauth2callback'
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const scopes = [
|
|
21
|
+
'https://www.googleapis.com/auth/gmail.readonly',
|
|
22
|
+
'https://www.googleapis.com/auth/gmail.modify',
|
|
23
|
+
];
|
|
24
|
+
|
|
25
|
+
const authorizeUrl = oauth2Client.generateAuthUrl({
|
|
26
|
+
access_type: 'offline',
|
|
27
|
+
scope: scopes,
|
|
28
|
+
prompt: 'consent',
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
console.log('Opening browser for authorization...');
|
|
32
|
+
console.log('URL:', authorizeUrl);
|
|
33
|
+
|
|
34
|
+
await open(authorizeUrl);
|
|
35
|
+
|
|
36
|
+
const server = http.createServer(async (req, res) => {
|
|
37
|
+
const queryParams = parse(req.url!, true).query;
|
|
38
|
+
const code = queryParams.code as string;
|
|
39
|
+
|
|
40
|
+
if (code) {
|
|
41
|
+
try {
|
|
42
|
+
const { tokens } = await oauth2Client.getToken(code);
|
|
43
|
+
fs.writeFileSync(TOKEN_PATH, JSON.stringify(tokens, null, 2));
|
|
44
|
+
|
|
45
|
+
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
46
|
+
res.end('<h1>Authorization successful!</h1><p>You can close this window.</p>');
|
|
47
|
+
|
|
48
|
+
console.log('Token saved to', TOKEN_PATH);
|
|
49
|
+
server.close();
|
|
50
|
+
process.exit(0);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error('Error getting tokens:', error);
|
|
53
|
+
res.writeHead(500);
|
|
54
|
+
res.end('Error');
|
|
55
|
+
process.exit(1);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
server.listen(3000, () => {
|
|
61
|
+
console.log('Listening on http://localhost:3000');
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
getToken().catch(console.error);
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { GraphFlow } from "../../execution/index";
|
|
4
|
+
import { Agent } from "../../agent/agent";
|
|
5
|
+
|
|
6
|
+
describe("Agent", () => {
|
|
7
|
+
it("process completes when LLM returns no actions", async () => {
|
|
8
|
+
const agent = new Agent({
|
|
9
|
+
role: "Echo",
|
|
10
|
+
goal: "Reply only",
|
|
11
|
+
backstory: "Minimal",
|
|
12
|
+
tools: [],
|
|
13
|
+
verbose: false,
|
|
14
|
+
llmConfig: {
|
|
15
|
+
provider: "custom",
|
|
16
|
+
model: "mock",
|
|
17
|
+
apiKey: "unused",
|
|
18
|
+
customCall: async () => ({
|
|
19
|
+
object: { actions: [], response: "Hello back." },
|
|
20
|
+
}),
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
const ctx = await agent.process("hi");
|
|
25
|
+
expect(ctx.response).to.equal("Hello back.");
|
|
26
|
+
expect(ctx.actions).to.be.an("array").that.is.empty;
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it("process runs tool graph when LLM requests an action", async () => {
|
|
30
|
+
const ToolSchema = z.object({
|
|
31
|
+
message: z.string(),
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const tool = new GraphFlow({
|
|
35
|
+
name: "setMessage",
|
|
36
|
+
schema: ToolSchema,
|
|
37
|
+
context: { message: "" },
|
|
38
|
+
nodes: [
|
|
39
|
+
{
|
|
40
|
+
name: "write",
|
|
41
|
+
execute: async (c) => {
|
|
42
|
+
c.message = "from-tool";
|
|
43
|
+
},
|
|
44
|
+
next: [],
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
let callCount = 0;
|
|
50
|
+
const agent = new Agent({
|
|
51
|
+
role: "Writer",
|
|
52
|
+
goal: "Use tool",
|
|
53
|
+
backstory: "Test",
|
|
54
|
+
tools: [tool],
|
|
55
|
+
verbose: false,
|
|
56
|
+
maxIterations: 3,
|
|
57
|
+
llmConfig: {
|
|
58
|
+
provider: "custom",
|
|
59
|
+
model: "mock",
|
|
60
|
+
apiKey: "unused",
|
|
61
|
+
customCall: async () => {
|
|
62
|
+
callCount++;
|
|
63
|
+
if (callCount === 1) {
|
|
64
|
+
return {
|
|
65
|
+
object: {
|
|
66
|
+
actions: [
|
|
67
|
+
{
|
|
68
|
+
name: "setMessage",
|
|
69
|
+
parameters: { message: "ignored" },
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
response: "Used tool.",
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
return {
|
|
77
|
+
object: {
|
|
78
|
+
actions: [],
|
|
79
|
+
response: "Done.",
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
const ctx = await agent.process("run tool");
|
|
87
|
+
expect(ctx.response).to.equal("Done.");
|
|
88
|
+
expect(ctx.knowledge).to.be.a("string");
|
|
89
|
+
expect(ctx.executedActions).to.have.length(1);
|
|
90
|
+
expect(ctx.executedActions[0].name).to.equal("setMessage");
|
|
91
|
+
});
|
|
92
|
+
});
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { GraphFlow } from "../../execution/index";
|
|
4
|
+
import { Agent } from "../../agent/agent";
|
|
5
|
+
|
|
6
|
+
describe("Clone / Decompose", () => {
|
|
7
|
+
it("with enableClone, actions decompose into parallel groups", async () => {
|
|
8
|
+
const toolA = new GraphFlow({
|
|
9
|
+
name: "toolA",
|
|
10
|
+
schema: z.object({ msg: z.string() }),
|
|
11
|
+
context: { msg: "" },
|
|
12
|
+
nodes: [{ name: "run", execute: async (c) => { c.msg = "A"; }, next: [] }],
|
|
13
|
+
});
|
|
14
|
+
const toolB = new GraphFlow({
|
|
15
|
+
name: "toolB",
|
|
16
|
+
schema: z.object({ msg: z.string() }),
|
|
17
|
+
context: { msg: "" },
|
|
18
|
+
nodes: [{ name: "run", execute: async (c) => { c.msg = "B"; }, next: [] }],
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
let callCount = 0;
|
|
22
|
+
const agent = new Agent({
|
|
23
|
+
role: "CloneAgent",
|
|
24
|
+
goal: "Use both tools in parallel",
|
|
25
|
+
backstory: "I parallelize",
|
|
26
|
+
tools: [toolA, toolB],
|
|
27
|
+
verbose: false,
|
|
28
|
+
maxIterations: 2,
|
|
29
|
+
enableClone: true,
|
|
30
|
+
llmConfig: {
|
|
31
|
+
provider: "custom",
|
|
32
|
+
model: "mock",
|
|
33
|
+
apiKey: "unused",
|
|
34
|
+
customCall: async () => {
|
|
35
|
+
callCount++;
|
|
36
|
+
if (callCount === 1) {
|
|
37
|
+
return {
|
|
38
|
+
object: {
|
|
39
|
+
actions: [
|
|
40
|
+
{ name: "toolA", parameters: { msg: "doA" } },
|
|
41
|
+
{ name: "toolB", parameters: { msg: "doB" } },
|
|
42
|
+
],
|
|
43
|
+
response: "Using both tools.",
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
if (callCount === 2) {
|
|
48
|
+
return {
|
|
49
|
+
object: {
|
|
50
|
+
groups: [
|
|
51
|
+
[{ name: "toolA", parameters: { msg: "doA" } }],
|
|
52
|
+
[{ name: "toolB", parameters: { msg: "doB" } }],
|
|
53
|
+
],
|
|
54
|
+
reasoning: "These tools are independent",
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
return {
|
|
59
|
+
object: { actions: [], response: "Done." },
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const ctx = await agent.process("run both tools");
|
|
66
|
+
expect(ctx.executedActions).to.have.length(2);
|
|
67
|
+
const names = ctx.executedActions.map((a: any) => a.name);
|
|
68
|
+
expect(names).to.include("toolA");
|
|
69
|
+
expect(names).to.include("toolB");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("without enableClone, actions run sequentially (default behavior)", async () => {
|
|
73
|
+
const toolA = new GraphFlow({
|
|
74
|
+
name: "toolA",
|
|
75
|
+
schema: z.object({ msg: z.string() }),
|
|
76
|
+
context: { msg: "" },
|
|
77
|
+
nodes: [{ name: "run", execute: async (c) => { c.msg = "A"; }, next: [] }],
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
let callCount = 0;
|
|
81
|
+
const agent = new Agent({
|
|
82
|
+
role: "SeqAgent",
|
|
83
|
+
goal: "Use tool",
|
|
84
|
+
backstory: "Sequential",
|
|
85
|
+
tools: [toolA],
|
|
86
|
+
verbose: false,
|
|
87
|
+
maxIterations: 2,
|
|
88
|
+
llmConfig: {
|
|
89
|
+
provider: "custom",
|
|
90
|
+
model: "mock",
|
|
91
|
+
apiKey: "unused",
|
|
92
|
+
customCall: async () => {
|
|
93
|
+
callCount++;
|
|
94
|
+
if (callCount === 1) {
|
|
95
|
+
return {
|
|
96
|
+
object: {
|
|
97
|
+
actions: [{ name: "toolA", parameters: { msg: "test" } }],
|
|
98
|
+
response: "Using tool.",
|
|
99
|
+
},
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
return {
|
|
103
|
+
object: { actions: [], response: "Done." },
|
|
104
|
+
};
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
const ctx = await agent.process("run tool");
|
|
110
|
+
expect(ctx.executedActions).to.have.length(1);
|
|
111
|
+
expect(ctx.executedActions[0].name).to.equal("toolA");
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
it("decompose can work with registered tools", async () => {
|
|
115
|
+
let callCount = 0;
|
|
116
|
+
const agent = new Agent({
|
|
117
|
+
role: "Helper",
|
|
118
|
+
goal: "Task",
|
|
119
|
+
backstory: "Helper",
|
|
120
|
+
tools: [],
|
|
121
|
+
verbose: false,
|
|
122
|
+
maxIterations: 2,
|
|
123
|
+
enableClone: true,
|
|
124
|
+
llmConfig: {
|
|
125
|
+
provider: "custom",
|
|
126
|
+
model: "mock",
|
|
127
|
+
apiKey: "unused",
|
|
128
|
+
customCall: async () => {
|
|
129
|
+
callCount++;
|
|
130
|
+
return {
|
|
131
|
+
object: {
|
|
132
|
+
actions: [],
|
|
133
|
+
response: callCount === 1 ? "Thinking..." : "Done.",
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
const ctx = await agent.process("simple task");
|
|
141
|
+
expect(ctx.response).to.equal("Done.");
|
|
142
|
+
});
|
|
143
|
+
});
|