@ai.ntellect/core 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mocharc.json +6 -0
- package/AGENTS.md +50 -0
- package/ARCHITECTURE.md +58 -0
- package/BENCHMARK.md +38 -0
- package/CHANGELOG.md +224 -0
- package/README.md +411 -142
- package/agent/agent-workflow.ts +569 -0
- package/agent/agent.ts +183 -0
- package/agent/base/executor.ts +103 -0
- package/agent/base/index.ts +87 -0
- package/agent/entity-resolver/confidence.ts +54 -0
- package/agent/entity-resolver/entity-index.ts +241 -0
- package/agent/entity-resolver/explore-strategy.ts +82 -0
- package/agent/entity-resolver/index.ts +22 -0
- package/agent/entity-resolver/resolver.ts +193 -0
- package/agent/entity-resolver/scorer.ts +211 -0
- package/agent/entity-resolver/types.ts +98 -0
- package/agent/generic-executor.ts +713 -0
- package/agent/handlers/cognitive-handler.ts +197 -0
- package/agent/handlers/index.ts +1 -0
- package/agent/handoff.ts +58 -0
- package/agent/llm-factory.ts +343 -0
- package/agent/orchestrator.ts +45 -0
- package/agent/prompt-builder.ts +78 -0
- package/agent/registry.ts +64 -0
- package/agent/tools/file-system.ts +471 -0
- package/agent/tools/index.ts +23 -0
- package/agent/tools/logger.ts +105 -0
- package/agent/tools/tool-resolver.ts +104 -0
- package/benchmark/cortexflow-workflow.ts +182 -0
- package/benchmark/langgraph-workflow.ts +201 -0
- package/benchmark/llm-client.ts +76 -0
- package/benchmark/run-benchmark.ts +222 -0
- package/cli-dev.ts +419 -0
- package/dist/agent/agent-workflow.d.ts +41 -0
- package/dist/agent/agent-workflow.d.ts.map +1 -0
- package/dist/agent/agent-workflow.js +560 -0
- package/dist/agent/agent-workflow.js.map +1 -0
- package/dist/agent/agent.d.ts +38 -0
- package/dist/agent/agent.d.ts.map +1 -0
- package/dist/agent/agent.js +149 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/agent/base/executor.d.ts +51 -0
- package/dist/agent/base/executor.d.ts.map +1 -0
- package/dist/agent/base/executor.js +69 -0
- package/dist/agent/base/executor.js.map +1 -0
- package/dist/agent/base/index.d.ts +30 -0
- package/dist/agent/base/index.d.ts.map +1 -0
- package/dist/agent/base/index.js +88 -0
- package/dist/agent/base/index.js.map +1 -0
- package/dist/agent/entity-resolver/confidence.d.ts +4 -0
- package/dist/agent/entity-resolver/confidence.d.ts.map +1 -0
- package/dist/agent/entity-resolver/confidence.js +47 -0
- package/dist/agent/entity-resolver/confidence.js.map +1 -0
- package/dist/agent/entity-resolver/entity-index.d.ts +40 -0
- package/dist/agent/entity-resolver/entity-index.d.ts.map +1 -0
- package/dist/agent/entity-resolver/entity-index.js +244 -0
- package/dist/agent/entity-resolver/entity-index.js.map +1 -0
- package/dist/agent/entity-resolver/explore-strategy.d.ts +13 -0
- package/dist/agent/entity-resolver/explore-strategy.d.ts.map +1 -0
- package/dist/agent/entity-resolver/explore-strategy.js +109 -0
- package/dist/agent/entity-resolver/explore-strategy.js.map +1 -0
- package/dist/agent/entity-resolver/index.d.ts +8 -0
- package/dist/agent/entity-resolver/index.d.ts.map +1 -0
- package/dist/agent/entity-resolver/index.js +16 -0
- package/dist/agent/entity-resolver/index.js.map +1 -0
- package/dist/agent/entity-resolver/resolver.d.ts +18 -0
- package/dist/agent/entity-resolver/resolver.d.ts.map +1 -0
- package/dist/agent/entity-resolver/resolver.js +158 -0
- package/dist/agent/entity-resolver/resolver.js.map +1 -0
- package/dist/agent/entity-resolver/scorer.d.ts +3 -0
- package/dist/agent/entity-resolver/scorer.d.ts.map +1 -0
- package/dist/agent/entity-resolver/scorer.js +182 -0
- package/dist/agent/entity-resolver/scorer.js.map +1 -0
- package/dist/agent/entity-resolver/types.d.ts +89 -0
- package/dist/agent/entity-resolver/types.d.ts.map +1 -0
- package/dist/agent/entity-resolver/types.js +3 -0
- package/dist/agent/entity-resolver/types.js.map +1 -0
- package/dist/agent/generic-executor.d.ts +68 -0
- package/dist/agent/generic-executor.d.ts.map +1 -0
- package/dist/agent/generic-executor.js +620 -0
- package/dist/agent/generic-executor.js.map +1 -0
- package/dist/agent/handlers/cognitive-handler.d.ts +44 -0
- package/dist/agent/handlers/cognitive-handler.d.ts.map +1 -0
- package/dist/agent/handlers/cognitive-handler.js +172 -0
- package/dist/agent/handlers/cognitive-handler.js.map +1 -0
- package/dist/agent/handlers/index.d.ts +2 -0
- package/dist/agent/handlers/index.d.ts.map +1 -0
- package/dist/agent/handlers/index.js +7 -0
- package/dist/agent/handlers/index.js.map +1 -0
- package/dist/agent/handoff.d.ts +12 -0
- package/dist/agent/handoff.d.ts.map +1 -0
- package/dist/agent/handoff.js +62 -0
- package/dist/agent/handoff.js.map +1 -0
- package/dist/agent/llm-factory.d.ts +19 -0
- package/dist/agent/llm-factory.d.ts.map +1 -0
- package/dist/agent/llm-factory.js +297 -0
- package/dist/agent/llm-factory.js.map +1 -0
- package/dist/agent/orchestrator.d.ts +18 -0
- package/dist/agent/orchestrator.d.ts.map +1 -0
- package/dist/agent/orchestrator.js +44 -0
- package/dist/agent/orchestrator.js.map +1 -0
- package/dist/agent/prompt-builder.d.ts +35 -0
- package/dist/agent/prompt-builder.d.ts.map +1 -0
- package/dist/agent/prompt-builder.js +76 -0
- package/dist/agent/prompt-builder.js.map +1 -0
- package/dist/agent/registry.d.ts +19 -0
- package/dist/agent/registry.d.ts.map +1 -0
- package/dist/agent/registry.js +48 -0
- package/dist/agent/registry.js.map +1 -0
- package/dist/agent/tools/file-system.d.ts +11 -0
- package/dist/agent/tools/file-system.d.ts.map +1 -0
- package/dist/agent/tools/file-system.js +528 -0
- package/dist/agent/tools/file-system.js.map +1 -0
- package/dist/agent/tools/index.d.ts +4 -0
- package/dist/agent/tools/index.d.ts.map +1 -0
- package/dist/agent/tools/index.js +20 -0
- package/dist/agent/tools/index.js.map +1 -0
- package/dist/agent/tools/logger.d.ts +33 -0
- package/dist/agent/tools/logger.d.ts.map +1 -0
- package/dist/agent/tools/logger.js +86 -0
- package/dist/agent/tools/logger.js.map +1 -0
- package/dist/agent/tools/tool-resolver.d.ts +7 -0
- package/dist/agent/tools/tool-resolver.d.ts.map +1 -0
- package/dist/agent/tools/tool-resolver.js +122 -0
- package/dist/agent/tools/tool-resolver.js.map +1 -0
- package/dist/execution/adapters/in-memory-checkpoint.d.ts +11 -0
- package/dist/execution/adapters/in-memory-checkpoint.d.ts.map +1 -0
- package/dist/execution/adapters/in-memory-checkpoint.js +54 -0
- package/dist/execution/adapters/in-memory-checkpoint.js.map +1 -0
- package/dist/execution/compiler.d.ts +8 -0
- package/dist/execution/compiler.d.ts.map +1 -0
- package/dist/execution/compiler.js +50 -0
- package/dist/execution/compiler.js.map +1 -0
- package/dist/execution/controller.d.ts +30 -0
- package/dist/execution/controller.d.ts.map +1 -0
- package/dist/execution/controller.js +80 -0
- package/dist/execution/controller.js.map +1 -0
- package/dist/execution/event-manager.d.ts +29 -0
- package/dist/execution/event-manager.d.ts.map +1 -0
- package/dist/execution/event-manager.js +264 -0
- package/dist/execution/event-manager.js.map +1 -0
- package/dist/execution/index.d.ts +221 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +638 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/execution/logger.d.ts +46 -0
- package/dist/execution/logger.d.ts.map +1 -0
- package/dist/execution/logger.js +69 -0
- package/dist/execution/logger.js.map +1 -0
- package/dist/execution/node.d.ts +65 -0
- package/dist/execution/node.d.ts.map +1 -0
- package/dist/execution/node.js +250 -0
- package/dist/execution/node.js.map +1 -0
- package/dist/execution/observer.d.ts +38 -0
- package/dist/execution/observer.d.ts.map +1 -0
- package/dist/execution/observer.js +111 -0
- package/dist/execution/observer.js.map +1 -0
- package/dist/execution/planner.d.ts +14 -0
- package/dist/execution/planner.d.ts.map +1 -0
- package/dist/execution/planner.js +43 -0
- package/dist/execution/planner.js.map +1 -0
- package/dist/execution/reducer.d.ts +19 -0
- package/dist/execution/reducer.d.ts.map +1 -0
- package/dist/execution/reducer.js +61 -0
- package/dist/execution/reducer.js.map +1 -0
- package/dist/execution/registry.d.ts +38 -0
- package/dist/execution/registry.d.ts.map +1 -0
- package/dist/execution/registry.js +63 -0
- package/dist/execution/registry.js.map +1 -0
- package/dist/execution/send-api.d.ts +24 -0
- package/dist/execution/send-api.d.ts.map +1 -0
- package/dist/execution/send-api.js +52 -0
- package/dist/execution/send-api.js.map +1 -0
- package/dist/execution/types.parallel.d.ts +61 -0
- package/dist/execution/types.parallel.d.ts.map +1 -0
- package/dist/execution/types.parallel.js +3 -0
- package/dist/execution/types.parallel.js.map +1 -0
- package/dist/execution/visualizer.d.ts +35 -0
- package/dist/execution/visualizer.d.ts.map +1 -0
- package/dist/execution/visualizer.js +131 -0
- package/dist/execution/visualizer.js.map +1 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/index.d.ts +487 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/index.js +75 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/modules/agenda/adapters/node-cron/index.d.ts +17 -0
- package/dist/modules/agenda/adapters/node-cron/index.d.ts.map +1 -0
- package/dist/modules/agenda/adapters/node-cron/index.js +30 -0
- package/dist/modules/agenda/adapters/node-cron/index.js.map +1 -0
- package/dist/modules/agenda/index.d.ts +63 -0
- package/dist/modules/agenda/index.d.ts.map +1 -0
- package/dist/modules/agenda/index.js +141 -0
- package/dist/modules/agenda/index.js.map +1 -0
- package/dist/modules/cli/index.d.ts +13 -0
- package/dist/modules/cli/index.d.ts.map +1 -0
- package/dist/modules/cli/index.js +672 -0
- package/dist/modules/cli/index.js.map +1 -0
- package/dist/modules/embedding/adapters/ai/index.d.ts +29 -0
- package/dist/modules/embedding/adapters/ai/index.d.ts.map +1 -0
- package/dist/modules/embedding/adapters/ai/index.js +58 -0
- package/dist/modules/embedding/adapters/ai/index.js.map +1 -0
- package/dist/modules/embedding/index.d.ts +36 -0
- package/dist/modules/embedding/index.d.ts.map +1 -0
- package/dist/modules/embedding/index.js +60 -0
- package/dist/modules/embedding/index.js.map +1 -0
- package/dist/modules/nlp/engine.d.ts +126 -0
- package/dist/modules/nlp/engine.d.ts.map +1 -0
- package/dist/modules/nlp/engine.js +299 -0
- package/dist/modules/nlp/engine.js.map +1 -0
- package/dist/modules/nlp/index.d.ts +27 -0
- package/dist/modules/nlp/index.d.ts.map +1 -0
- package/dist/modules/nlp/index.js +56 -0
- package/dist/modules/nlp/index.js.map +1 -0
- package/dist/persistence/index.d.ts +12 -0
- package/dist/persistence/index.d.ts.map +1 -0
- package/dist/persistence/index.js +24 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/persistence/neo4j/driver.d.ts +26 -0
- package/dist/persistence/neo4j/driver.d.ts.map +1 -0
- package/dist/persistence/neo4j/driver.js +64 -0
- package/dist/persistence/neo4j/driver.js.map +1 -0
- package/dist/persistence/neo4j/entity-store.d.ts +15 -0
- package/dist/persistence/neo4j/entity-store.d.ts.map +1 -0
- package/dist/persistence/neo4j/entity-store.js +136 -0
- package/dist/persistence/neo4j/entity-store.js.map +1 -0
- package/dist/persistence/neo4j/execution-tracer.d.ts +19 -0
- package/dist/persistence/neo4j/execution-tracer.d.ts.map +1 -0
- package/dist/persistence/neo4j/execution-tracer.js +166 -0
- package/dist/persistence/neo4j/execution-tracer.js.map +1 -0
- package/dist/persistence/neo4j/memory-adapter.d.ts +35 -0
- package/dist/persistence/neo4j/memory-adapter.d.ts.map +1 -0
- package/dist/persistence/neo4j/memory-adapter.js +252 -0
- package/dist/persistence/neo4j/memory-adapter.js.map +1 -0
- package/dist/persistence/neo4j/petri-checkpoint-adapter.d.ts +22 -0
- package/dist/persistence/neo4j/petri-checkpoint-adapter.d.ts.map +1 -0
- package/dist/persistence/neo4j/petri-checkpoint-adapter.js +141 -0
- package/dist/persistence/neo4j/petri-checkpoint-adapter.js.map +1 -0
- package/dist/pipeline/agent-pipeline.d.ts +99 -0
- package/dist/pipeline/agent-pipeline.d.ts.map +1 -0
- package/dist/pipeline/agent-pipeline.js +356 -0
- package/dist/pipeline/agent-pipeline.js.map +1 -0
- package/dist/routing/checkpoint-adapter.d.ts +30 -0
- package/dist/routing/checkpoint-adapter.d.ts.map +1 -0
- package/dist/routing/checkpoint-adapter.js +83 -0
- package/dist/routing/checkpoint-adapter.js.map +1 -0
- package/dist/routing/documentation-generator.d.ts +47 -0
- package/dist/routing/documentation-generator.d.ts.map +1 -0
- package/dist/routing/documentation-generator.js +320 -0
- package/dist/routing/documentation-generator.js.map +1 -0
- package/dist/routing/index.d.ts +38 -0
- package/dist/routing/index.d.ts.map +1 -0
- package/dist/routing/index.js +375 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/routing/intent-classifier.d.ts +206 -0
- package/dist/routing/intent-classifier.d.ts.map +1 -0
- package/dist/routing/intent-classifier.js +267 -0
- package/dist/routing/intent-classifier.js.map +1 -0
- package/dist/routing/matrix.d.ts +6 -0
- package/dist/routing/matrix.d.ts.map +1 -0
- package/dist/routing/matrix.js +131 -0
- package/dist/routing/matrix.js.map +1 -0
- package/dist/routing/orchestrator.d.ts +87 -0
- package/dist/routing/orchestrator.d.ts.map +1 -0
- package/dist/routing/orchestrator.js +425 -0
- package/dist/routing/orchestrator.js.map +1 -0
- package/dist/routing/postgres-checkpoint-adapter.d.ts +32 -0
- package/dist/routing/postgres-checkpoint-adapter.d.ts.map +1 -0
- package/dist/routing/postgres-checkpoint-adapter.js +167 -0
- package/dist/routing/postgres-checkpoint-adapter.js.map +1 -0
- package/dist/routing/redis-checkpoint-adapter.d.ts +34 -0
- package/dist/routing/redis-checkpoint-adapter.d.ts.map +1 -0
- package/dist/routing/redis-checkpoint-adapter.js +170 -0
- package/dist/routing/redis-checkpoint-adapter.js.map +1 -0
- package/dist/routing/types.d.ts +49 -0
- package/dist/routing/types.d.ts.map +1 -0
- package/dist/routing/types.js +3 -0
- package/dist/routing/types.js.map +1 -0
- package/dist/types/agent.d.ts +289 -0
- package/dist/types/agent.d.ts.map +1 -0
- package/dist/types/agent.js +78 -0
- package/dist/types/agent.js.map +1 -0
- package/dist/types/index.d.ts +343 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/generate-action-schema.d.ts +4 -0
- package/dist/utils/generate-action-schema.d.ts.map +1 -0
- package/dist/utils/generate-action-schema.js +46 -0
- package/dist/utils/generate-action-schema.js.map +1 -0
- package/dist/utils/header-builder.d.ts +12 -0
- package/dist/utils/header-builder.d.ts.map +1 -0
- package/dist/utils/header-builder.js +35 -0
- package/dist/utils/header-builder.js.map +1 -0
- package/dist/utils/logger.d.ts +27 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +45 -0
- package/dist/utils/logger.js.map +1 -0
- package/docs/.gitbook/assets/image (1).png +0 -0
- package/docs/.gitbook/assets/image (2).png +0 -0
- package/docs/.gitbook/assets/image (3).png +0 -0
- package/docs/.gitbook/assets/image (4).png +0 -0
- package/docs/.gitbook/assets/image (5).png +0 -0
- package/docs/.gitbook/assets/image (6).png +0 -0
- package/docs/.gitbook/assets/image.png +0 -0
- package/docs/README.md +57 -0
- package/docs/SUMMARY.md +34 -0
- package/docs/cas-dusages.md +69 -0
- package/docs/cli/README.md +65 -0
- package/docs/concepts-cles.md +50 -0
- package/docs/core/architecture.md +87 -0
- package/docs/core/benchmark.md +59 -0
- package/docs/core/checkpoint.md +72 -0
- package/docs/core/documentation.md +55 -0
- package/docs/core/graphcontroller.md +63 -0
- package/docs/core/graphflow.md +137 -0
- package/docs/core/introduction.md +41 -0
- package/docs/core/les-evenements.md +95 -0
- package/docs/modules/agenda/README.md +63 -0
- package/docs/modules/agenda/interface-iagenda.md +170 -0
- package/docs/modules/agenda/les-adaptateurs/README.md +237 -0
- package/docs/modules/agenda/les-adaptateurs/nodecronadapter.md +91 -0
- package/docs/modules/introduction.md +55 -0
- package/docs/modules/les-adaptateurs.md +52 -0
- package/docs/modules/memoire/README.md +68 -0
- package/docs/modules/memoire/interface-imemory.md +183 -0
- package/docs/modules/memoire/les-adaptateurs/README.md +209 -0
- package/docs/modules/memoire/les-adaptateurs/inmemoryadapter.md +110 -0
- package/docs/modules/memoire/les-adaptateurs/meilisearchadapter.md +147 -0
- package/docs/modules/memoire/les-adaptateurs/redisadapter.md +212 -0
- package/docs/modules/nlp/README.md +44 -0
- package/docs/philosophie.md +51 -0
- package/docs/tutoriels/ajouter-des-conditions.md +150 -0
- package/docs/tutoriels/branching.md +194 -0
- package/docs/tutoriels/checkpoint-usage.md +99 -0
- package/docs/tutoriels/creer-agent-onchain.md +1041 -0
- package/docs/tutoriels/creer-un-agent.md +108 -0
- package/docs/tutoriels/creer-un-graphe-simple.md +92 -0
- package/docs/tutoriels/gerer-les-erreurs.md +124 -0
- package/docs/tutoriels/pour-commencer.md +73 -0
- package/docs/tutoriels/retry.md +166 -0
- package/execution/adapters/in-memory-checkpoint.ts +35 -0
- package/execution/compiler.ts +47 -0
- package/execution/controller.ts +84 -0
- package/execution/event-manager.ts +331 -0
- package/execution/index.ts +800 -0
- package/execution/logger.ts +70 -0
- package/execution/node.ts +315 -0
- package/execution/observer.ts +192 -0
- package/execution/planner.ts +40 -0
- package/execution/reducer.ts +73 -0
- package/execution/registry.ts +86 -0
- package/execution/send-api.ts +58 -0
- package/execution/types.parallel.ts +81 -0
- package/execution/visualizer.ts +158 -0
- package/index.ts +55 -465
- package/interfaces/index.ts +597 -0
- package/modules/agenda/adapters/node-cron/index.ts +25 -0
- package/modules/agenda/index.ts +146 -0
- package/modules/cli/index.ts +580 -0
- package/modules/embedding/adapters/ai/index.ts +42 -0
- package/modules/embedding/index.ts +45 -0
- package/modules/nlp/engine.ts +324 -0
- package/modules/nlp/index.ts +45 -0
- package/package.json +81 -9
- package/persistence/index.ts +27 -0
- package/persistence/neo4j/driver.ts +34 -0
- package/persistence/neo4j/entity-store.ts +141 -0
- package/persistence/neo4j/execution-tracer.ts +194 -0
- package/persistence/neo4j/memory-adapter.ts +281 -0
- package/persistence/neo4j/petri-checkpoint-adapter.ts +153 -0
- package/pipeline/agent-pipeline.ts +426 -0
- package/routing/checkpoint-adapter.ts +79 -0
- package/routing/documentation-generator.ts +358 -0
- package/routing/index.ts +459 -0
- package/routing/intent-classifier.ts +360 -0
- package/routing/matrix.ts +138 -0
- package/routing/orchestrator.ts +498 -0
- package/routing/patterns/data-extraction.json +79 -0
- package/routing/patterns/human-approval.json +64 -0
- package/routing/patterns/rag-search.json +68 -0
- package/routing/postgres-checkpoint-adapter.ts +172 -0
- package/routing/redis-checkpoint-adapter.ts +187 -0
- package/routing/types.ts +59 -0
- package/routing/web-server.ts +260 -0
- package/scripts/generate-petri-docs.ts +70 -0
- package/scripts/get-gmail-token.js +65 -0
- package/scripts/get-gmail-token.ts +65 -0
- package/test/agent/agent.test.ts +92 -0
- package/test/agent/clone.test.ts +143 -0
- package/test/agent/cognitive-handler.test.ts +78 -0
- package/test/agent/entity-store.test.ts +80 -0
- package/test/agent/generic-executor.test.ts +230 -0
- package/test/agent/handoff.test.ts +163 -0
- package/test/agent/llm-factory.test.ts +40 -0
- package/test/agent/orchestrator.test.ts +156 -0
- package/test/agent/registry.test.ts +97 -0
- package/test/agent/tools.test.ts +267 -0
- package/test/execution/checkpoint.test.ts +811 -0
- package/test/execution/controller.test.ts +236 -0
- package/test/execution/event-manager.test.ts +118 -0
- package/test/execution/index.test.ts +690 -0
- package/test/execution/node.test.ts +464 -0
- package/test/execution/observer.test.ts +393 -0
- package/test/execution/parallel.test.ts +135 -0
- package/test/execution/plan-llm-integration.test.ts +290 -0
- package/test/execution/plan-real-onchain.test.ts +226 -0
- package/test/execution/send-api.test.ts +121 -0
- package/test/modules/agenda/node-cron.test.ts +307 -0
- package/test/modules/cli/index.test.ts +125 -0
- package/test/persistence/neo4j-execution-tracer.test.ts +96 -0
- package/test/persistence/neo4j-memory-adapter.test.ts +107 -0
- package/test/persistence/neo4j-petri-checkpoint.test.ts +89 -0
- package/test/pipeline/agent-pipeline.test.ts +118 -0
- package/test/routing/checkpoint-persistence.test.ts +58 -0
- package/test/routing/documentation-generator.test.ts +76 -0
- package/test/routing/integration.test.ts +261 -0
- package/test/routing/intent-classifier.test.ts +102 -0
- package/test/routing/petri.test.ts +156 -0
- package/test/routing/real-llm.test.ts +260 -0
- package/test-petri-features.ts +218 -0
- package/test-pipeline-api.ts +163 -0
- package/tsconfig.json +30 -108
- package/types/agent.ts +296 -0
- package/types/index.ts +387 -0
- package/utils/generate-action-schema.ts +47 -0
- package/utils/header-builder.ts +40 -0
- package/utils/logger.ts +40 -0
- package/package copy.json +0 -21
- package/types.ts +0 -62
- package/utils/executor.ts +0 -42
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { AgentContext, PromptSection } from "../types/agent";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Builder class for creating structured prompts with multiple sections
|
|
5
|
+
* @class PromptBuilder
|
|
6
|
+
*/
|
|
7
|
+
export class PromptBuilder {
|
|
8
|
+
private sections: PromptSection[] = [];
|
|
9
|
+
private formatFn?: (
|
|
10
|
+
sections: PromptSection[],
|
|
11
|
+
context: AgentContext
|
|
12
|
+
) => string | Promise<string>;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Adds a new section to the prompt
|
|
16
|
+
* @param {string} title - The title of the section
|
|
17
|
+
* @param {string | ((context: AgentContext) => string | Promise<string>)} content - The content or a function to generate content
|
|
18
|
+
* @returns {this} The builder instance for method chaining
|
|
19
|
+
*/
|
|
20
|
+
addSection(
|
|
21
|
+
title: string,
|
|
22
|
+
content: string | ((context: AgentContext) => string | Promise<string>)
|
|
23
|
+
): this {
|
|
24
|
+
this.sections.push({ title, content });
|
|
25
|
+
return this;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Sets a custom formatter function for the final prompt
|
|
30
|
+
* @param {(sections: PromptSection[], context: AgentContext) => string | Promise<string>} formatter - The formatter function
|
|
31
|
+
* @returns {this} The builder instance for method chaining
|
|
32
|
+
*/
|
|
33
|
+
setFormatter(
|
|
34
|
+
formatter: (
|
|
35
|
+
sections: PromptSection[],
|
|
36
|
+
context: AgentContext
|
|
37
|
+
) => string | Promise<string>
|
|
38
|
+
): this {
|
|
39
|
+
this.formatFn = formatter;
|
|
40
|
+
return this;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Builds the final prompt by resolving all sections and applying formatting
|
|
45
|
+
* @param {AgentContext} context - The context to use when resolving dynamic content
|
|
46
|
+
* @returns {Promise<string>} The formatted prompt string
|
|
47
|
+
*/
|
|
48
|
+
async build(context: AgentContext): Promise<string> {
|
|
49
|
+
const resolvedSections = await Promise.all(
|
|
50
|
+
this.sections.map(async (section) => ({
|
|
51
|
+
title: section.title,
|
|
52
|
+
content:
|
|
53
|
+
typeof section.content === "function"
|
|
54
|
+
? await section.content(context)
|
|
55
|
+
: section.content,
|
|
56
|
+
}))
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
if (this.formatFn) {
|
|
60
|
+
return this.formatFn(resolvedSections, context);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
return resolvedSections
|
|
64
|
+
.map((section) => `## ${section.title}\n${section.content}`)
|
|
65
|
+
.join("\n\n");
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Default formatter function that formats sections with markdown-style headers
|
|
71
|
+
* @param {PromptSection[]} sections - The sections to format
|
|
72
|
+
* @returns {string} The formatted prompt string
|
|
73
|
+
*/
|
|
74
|
+
export const defaultFormatter = (sections: PromptSection[]): string => {
|
|
75
|
+
return sections
|
|
76
|
+
.map((section) => `## ${section.title}\n${section.content}`)
|
|
77
|
+
.join("\n\n");
|
|
78
|
+
};
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { Agent } from "./agent";
|
|
2
|
+
|
|
3
|
+
export type AgentRegistration = {
|
|
4
|
+
agent: Agent;
|
|
5
|
+
role: string;
|
|
6
|
+
description: string;
|
|
7
|
+
capabilities?: string[];
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export class AgentRegistry {
|
|
11
|
+
private agents: Map<string, AgentRegistration> = new Map();
|
|
12
|
+
|
|
13
|
+
register(
|
|
14
|
+
name: string,
|
|
15
|
+
agent: Agent,
|
|
16
|
+
role: string,
|
|
17
|
+
description: string,
|
|
18
|
+
capabilities?: string[]
|
|
19
|
+
): void {
|
|
20
|
+
if (this.agents.has(name)) {
|
|
21
|
+
throw new Error(`Agent "${name}" is already registered`);
|
|
22
|
+
}
|
|
23
|
+
this.agents.set(name, { agent, role, description, capabilities });
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get(name: string): AgentRegistration | undefined {
|
|
27
|
+
return this.agents.get(name);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
getAgent(name: string): Agent | undefined {
|
|
31
|
+
return this.agents.get(name)?.agent;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
find(query: string): AgentRegistration[] {
|
|
35
|
+
const q = query.toLowerCase();
|
|
36
|
+
const results: AgentRegistration[] = [];
|
|
37
|
+
for (const [, reg] of this.agents) {
|
|
38
|
+
if (
|
|
39
|
+
reg.role.toLowerCase().includes(q) ||
|
|
40
|
+
reg.description.toLowerCase().includes(q) ||
|
|
41
|
+
reg.capabilities?.some((c) => c.toLowerCase().includes(q))
|
|
42
|
+
) {
|
|
43
|
+
results.push(reg);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return results;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
list(): AgentRegistration[] {
|
|
50
|
+
return Array.from(this.agents.values());
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
remove(name: string): boolean {
|
|
54
|
+
return this.agents.delete(name);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
has(name: string): boolean {
|
|
58
|
+
return this.agents.has(name);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
get size(): number {
|
|
62
|
+
return this.agents.size;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
@@ -0,0 +1,471 @@
|
|
|
1
|
+
import { GraphFlow } from "../../execution/index";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { spawn, exec } from "child_process";
|
|
4
|
+
import { promisify } from "util";
|
|
5
|
+
import { resolvePath } from "./tool-resolver";
|
|
6
|
+
|
|
7
|
+
const execAsync = promisify(exec);
|
|
8
|
+
|
|
9
|
+
export function createFileReaderTool(): GraphFlow<any> {
|
|
10
|
+
return new GraphFlow({
|
|
11
|
+
name: "file_reader",
|
|
12
|
+
schema: z.object({
|
|
13
|
+
entityId: z.string().describe("Entity handle from AVAILABLE ENTITY HANDLES list (e.g. 'ent_0'). Use ONLY this for target resolution."),
|
|
14
|
+
path: z.string().optional(),
|
|
15
|
+
content: z.any().optional().describe("File content (populated by tool)"),
|
|
16
|
+
encoding: z.enum(["utf-8", "base64"]).optional().default("utf-8").catch("utf-8").describe("File encoding (use utf-8, NOT utf8)"),
|
|
17
|
+
}),
|
|
18
|
+
context: { path: "", encoding: "utf-8", entityId: "" },
|
|
19
|
+
nodes: [{
|
|
20
|
+
name: "read",
|
|
21
|
+
execute: async (ctx: any) => {
|
|
22
|
+
const fs = await import("fs/promises");
|
|
23
|
+
const cwd = process.cwd();
|
|
24
|
+
let targetPath = ctx.path;
|
|
25
|
+
try {
|
|
26
|
+
await fs.access(targetPath);
|
|
27
|
+
} catch {
|
|
28
|
+
const resolved = resolvePath(targetPath, cwd);
|
|
29
|
+
const file = resolved.find(e => e.type === "file");
|
|
30
|
+
if (file) {
|
|
31
|
+
console.log(` [TOOL:file_reader] Resolved "${targetPath}" → "${file.path}"`);
|
|
32
|
+
targetPath = file.path;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
try {
|
|
36
|
+
ctx.content = await fs.readFile(targetPath, ctx.encoding as BufferEncoding);
|
|
37
|
+
console.log(` [TOOL:file_reader] Read ${targetPath}`);
|
|
38
|
+
} catch (e: any) {
|
|
39
|
+
console.log(` [TOOL:file_reader] Error: ${e.message}`);
|
|
40
|
+
ctx.content = `Error: ${e.message}`;
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
next: [],
|
|
44
|
+
}],
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export function createFileWriterTool(): GraphFlow<any> {
|
|
49
|
+
return new GraphFlow({
|
|
50
|
+
name: "file_writer",
|
|
51
|
+
schema: z.object({
|
|
52
|
+
entityId: z.string().describe("Entity handle from AVAILABLE ENTITY HANDLES list. Use ONLY this for target resolution."),
|
|
53
|
+
path: z.string().optional(),
|
|
54
|
+
content: z.string().describe("Content to write"),
|
|
55
|
+
append: z.boolean().optional().default(false).describe("Append instead of overwrite"),
|
|
56
|
+
success: z.any().optional().describe("Write result (populated by tool)"),
|
|
57
|
+
}),
|
|
58
|
+
context: { path: "", content: "", append: false, entityId: "" },
|
|
59
|
+
nodes: [{
|
|
60
|
+
name: "write",
|
|
61
|
+
execute: async (ctx: any) => {
|
|
62
|
+
const fs = await import("fs/promises");
|
|
63
|
+
const cwd = process.cwd();
|
|
64
|
+
let targetPath = ctx.path;
|
|
65
|
+
try {
|
|
66
|
+
await fs.access(targetPath);
|
|
67
|
+
} catch {
|
|
68
|
+
const resolved = resolvePath(targetPath, cwd);
|
|
69
|
+
const file = resolved.find(e => e.type === "file");
|
|
70
|
+
if (file) {
|
|
71
|
+
console.log(` [TOOL:file_writer] Resolved "${targetPath}" → "${file.path}"`);
|
|
72
|
+
targetPath = file.path;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
try {
|
|
76
|
+
const flag = ctx.append ? "a" : "w";
|
|
77
|
+
await fs.writeFile(targetPath, ctx.content, { flag });
|
|
78
|
+
ctx.success = true;
|
|
79
|
+
console.log(` [TOOL:file_writer] ${ctx.append ? "Appended to" : "Wrote"} ${targetPath}`);
|
|
80
|
+
} catch (e: any) {
|
|
81
|
+
console.log(` [TOOL:file_writer] Error: ${e.message}`);
|
|
82
|
+
ctx.success = false;
|
|
83
|
+
}
|
|
84
|
+
},
|
|
85
|
+
next: [],
|
|
86
|
+
}],
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export function createFileDeleterTool(): GraphFlow<any> {
|
|
91
|
+
return new GraphFlow({
|
|
92
|
+
name: "file_deleter",
|
|
93
|
+
schema: z.object({
|
|
94
|
+
entityId: z.string().describe("Entity handle from AVAILABLE ENTITY HANDLES list. Use ONLY this for target resolution."),
|
|
95
|
+
path: z.string().optional(),
|
|
96
|
+
recursive: z.boolean().optional().default(false).describe("Delete directories recursively"),
|
|
97
|
+
success: z.any().optional().describe("Delete result (populated by tool)"),
|
|
98
|
+
}),
|
|
99
|
+
context: { path: "", recursive: false, entityId: "" },
|
|
100
|
+
nodes: [{
|
|
101
|
+
name: "delete",
|
|
102
|
+
execute: async (ctx: any) => {
|
|
103
|
+
const fs = await import("fs/promises");
|
|
104
|
+
const cwd = process.cwd();
|
|
105
|
+
let targetPath = ctx.path;
|
|
106
|
+
try {
|
|
107
|
+
await fs.access(targetPath);
|
|
108
|
+
} catch {
|
|
109
|
+
const resolved = resolvePath(targetPath, cwd);
|
|
110
|
+
const entry = resolved.find(e => e.type === "file" || e.type === "dir");
|
|
111
|
+
if (entry) {
|
|
112
|
+
console.log(` [TOOL:file_deleter] Resolved "${targetPath}" → "${entry.path}"`);
|
|
113
|
+
targetPath = entry.path;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
try {
|
|
117
|
+
const stat = await fs.stat(targetPath);
|
|
118
|
+
if (stat.isDirectory()) {
|
|
119
|
+
await fs.rm(targetPath, { recursive: ctx.recursive });
|
|
120
|
+
} else {
|
|
121
|
+
await fs.unlink(targetPath);
|
|
122
|
+
}
|
|
123
|
+
ctx.success = true;
|
|
124
|
+
console.log(` [TOOL:file_deleter] Deleted ${targetPath}`);
|
|
125
|
+
} catch (e: any) {
|
|
126
|
+
console.log(` [TOOL:file_deleter] Error: ${e.message}`);
|
|
127
|
+
ctx.success = false;
|
|
128
|
+
}
|
|
129
|
+
},
|
|
130
|
+
next: [],
|
|
131
|
+
}],
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function createDirectoryCreatorTool(): GraphFlow<any> {
|
|
136
|
+
return new GraphFlow({
|
|
137
|
+
name: "directory_creator",
|
|
138
|
+
schema: z.object({
|
|
139
|
+
entityId: z.string().describe("Entity handle from AVAILABLE ENTITY HANDLES list. Use ONLY this for target resolution."),
|
|
140
|
+
path: z.string().optional(),
|
|
141
|
+
recursive: z.boolean().optional().default(true).describe("Create parent directories"),
|
|
142
|
+
success: z.any().optional().describe("Create result (populated by tool)"),
|
|
143
|
+
}),
|
|
144
|
+
context: { path: "", recursive: true, entityId: "" },
|
|
145
|
+
nodes: [{
|
|
146
|
+
name: "mkdir",
|
|
147
|
+
execute: async (ctx: any) => {
|
|
148
|
+
const fs = await import("fs/promises");
|
|
149
|
+
const cwd = process.cwd();
|
|
150
|
+
let targetPath = ctx.path;
|
|
151
|
+
try {
|
|
152
|
+
await fs.access(targetPath);
|
|
153
|
+
} catch {
|
|
154
|
+
const resolved = resolvePath(targetPath, cwd);
|
|
155
|
+
const dir = resolved.find(e => e.type === "dir");
|
|
156
|
+
if (dir) {
|
|
157
|
+
console.log(` [TOOL:directory_creator] Resolved "${targetPath}" → "${dir.path}"`);
|
|
158
|
+
targetPath = dir.path;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
try {
|
|
162
|
+
await fs.mkdir(targetPath, { recursive: ctx.recursive });
|
|
163
|
+
ctx.success = true;
|
|
164
|
+
console.log(` [TOOL:directory_creator] Created ${targetPath}`);
|
|
165
|
+
} catch (e: any) {
|
|
166
|
+
console.log(` [TOOL:directory_creator] Error: ${e.message}`);
|
|
167
|
+
ctx.success = false;
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
next: [],
|
|
171
|
+
}],
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
export function createDirectoryListerTool(): GraphFlow<any> {
|
|
176
|
+
return new GraphFlow({
|
|
177
|
+
name: "directory_lister",
|
|
178
|
+
schema: z.object({
|
|
179
|
+
entityId: z.string().describe("Entity handle from AVAILABLE ENTITY HANDLES list. Use ONLY this for target resolution."),
|
|
180
|
+
path: z.string().optional(),
|
|
181
|
+
entries: z.any().optional().describe("Directory entries (populated by tool)"),
|
|
182
|
+
}),
|
|
183
|
+
context: { path: "", entityId: "" },
|
|
184
|
+
nodes: [{
|
|
185
|
+
name: "list",
|
|
186
|
+
execute: async (ctx: any) => {
|
|
187
|
+
const fs = await import("fs/promises");
|
|
188
|
+
const cwd = process.cwd();
|
|
189
|
+
let targetPath = ctx.path;
|
|
190
|
+
try {
|
|
191
|
+
await fs.access(targetPath);
|
|
192
|
+
} catch {
|
|
193
|
+
const resolved = resolvePath(targetPath, cwd);
|
|
194
|
+
const dir = resolved.find(e => e.type === "dir");
|
|
195
|
+
if (dir) {
|
|
196
|
+
console.log(` [TOOL:directory_lister] Resolved "${targetPath}" → "${dir.path}"`);
|
|
197
|
+
targetPath = dir.path;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
try {
|
|
201
|
+
const entries = await fs.readdir(targetPath, { withFileTypes: true });
|
|
202
|
+
ctx.entries = entries.map((e: any) => ({
|
|
203
|
+
name: e.name,
|
|
204
|
+
type: e.isDirectory() ? "directory" : "file",
|
|
205
|
+
}));
|
|
206
|
+
console.log(` [TOOL:directory_lister] Listed ${targetPath}: ${ctx.entries.length} entries`);
|
|
207
|
+
} catch (e: any) {
|
|
208
|
+
console.log(` [TOOL:directory_lister] Error: ${e.message}`);
|
|
209
|
+
ctx.entries = [];
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
next: [],
|
|
213
|
+
}],
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const BLOCKED_COMMANDS = [
|
|
218
|
+
"rm -rf /", "mkfs", "dd if=", "chmod -R 777 /",
|
|
219
|
+
":(){ :|:& };:", "kill -9 -1", "shutdown", "reboot", "init ",
|
|
220
|
+
];
|
|
221
|
+
|
|
222
|
+
function isCommandBlocked(command: string): boolean {
|
|
223
|
+
const normalized = command.toLowerCase().trim();
|
|
224
|
+
return BLOCKED_COMMANDS.some(b => normalized.includes(b));
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
async function isDockerAvailable(): Promise<boolean> {
|
|
228
|
+
try {
|
|
229
|
+
await execAsync("docker info", { timeout: 3000 });
|
|
230
|
+
return true;
|
|
231
|
+
} catch {
|
|
232
|
+
return false;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
async function executeInDocker(command: string, cwd: string, timeout: number): Promise<{
|
|
237
|
+
stdout: string; stderr: string; exitCode: number; method: string
|
|
238
|
+
}> {
|
|
239
|
+
const safeCwd = cwd.replace(/[^a-zA-Z0-9/_.\-]/g, "");
|
|
240
|
+
const dockerCmd = `docker run --rm --network none --memory=256m --cpus=0.5 --security-opt no-new-privileges --timeout ${timeout / 1000}s -v ${safeCwd}:/workspace:ro -w /workspace alpine:3.19 sh -c ${JSON.stringify(command)}`;
|
|
241
|
+
try {
|
|
242
|
+
const { stdout, stderr } = await execAsync(dockerCmd, { timeout, maxBuffer: 1024 * 1024 });
|
|
243
|
+
return { stdout: stdout.toString(), stderr: stderr.toString(), exitCode: 0, method: "docker" };
|
|
244
|
+
} catch (e: any) {
|
|
245
|
+
return {
|
|
246
|
+
stdout: e.stdout || "",
|
|
247
|
+
stderr: e.stderr || e.message || "Docker execution failed",
|
|
248
|
+
exitCode: typeof e.code === 'number' ? e.code : 1,
|
|
249
|
+
method: "docker"
|
|
250
|
+
};
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
async function executeInProcess(command: string, cwd: string, timeout: number): Promise<{
|
|
255
|
+
stdout: string; stderr: string; exitCode: number; method: string
|
|
256
|
+
}> {
|
|
257
|
+
const isWindows = process.platform === "win32";
|
|
258
|
+
const shell = isWindows ? "cmd.exe" : "/bin/sh";
|
|
259
|
+
const args = isWindows ? ["/c", command] : ["-c", command];
|
|
260
|
+
const safeEnv = { PATH: process.env.PATH || "", HOME: process.env.HOME || "", LANG: "en_US.UTF-8" };
|
|
261
|
+
|
|
262
|
+
return new Promise((resolve) => {
|
|
263
|
+
const child = spawn(shell, args, { cwd, env: safeEnv });
|
|
264
|
+
let stdout = "";
|
|
265
|
+
let stderr = "";
|
|
266
|
+
let done = false;
|
|
267
|
+
let timer: ReturnType<typeof setTimeout> | null = null;
|
|
268
|
+
|
|
269
|
+
const finish = (code: number) => {
|
|
270
|
+
if (done) return;
|
|
271
|
+
done = true;
|
|
272
|
+
if (timer) clearTimeout(timer);
|
|
273
|
+
resolve({ stdout, stderr, exitCode: code, method: "process" });
|
|
274
|
+
};
|
|
275
|
+
|
|
276
|
+
timer = setTimeout(() => {
|
|
277
|
+
if (!done) {
|
|
278
|
+
child.kill("SIGKILL");
|
|
279
|
+
finish(124);
|
|
280
|
+
}
|
|
281
|
+
}, timeout);
|
|
282
|
+
|
|
283
|
+
child.stdout?.on("data", (d: Buffer) => { stdout += d.toString(); });
|
|
284
|
+
child.stderr?.on("data", (d: Buffer) => { stderr += d.toString(); });
|
|
285
|
+
child.on("close", (code: number | null) => finish(code ?? 1));
|
|
286
|
+
child.on("error", () => finish(1));
|
|
287
|
+
child.on("exit", (code: number | null, sig: NodeJS.Signals | null) => {
|
|
288
|
+
if (code !== null) finish(code);
|
|
289
|
+
});
|
|
290
|
+
});
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
export function createShellTool(): GraphFlow<any> {
|
|
294
|
+
return new GraphFlow({
|
|
295
|
+
name: "shell",
|
|
296
|
+
schema: z.object({
|
|
297
|
+
command: z.string().describe("Shell command to execute"),
|
|
298
|
+
cwd: z.string().optional().describe("Working directory (host path, only used as context)"),
|
|
299
|
+
timeout: z.number().optional().describe("Timeout in ms (max 60000)"),
|
|
300
|
+
stdout: z.string().optional().describe("Command output"),
|
|
301
|
+
stderr: z.string().optional().describe("Error output"),
|
|
302
|
+
exitCode: z.number().optional().describe("Exit code"),
|
|
303
|
+
isolationMethod: z.string().optional().describe("Isolation method used: docker or process"),
|
|
304
|
+
}),
|
|
305
|
+
context: { command: "", cwd: process.cwd(), timeout: 30000 },
|
|
306
|
+
nodes: [{
|
|
307
|
+
name: "execute",
|
|
308
|
+
execute: async (ctx: any) => {
|
|
309
|
+
if (!ctx.command) { ctx.exitCode = 1; ctx.stderr = "No command provided"; return; }
|
|
310
|
+
if (isCommandBlocked(ctx.command)) {
|
|
311
|
+
ctx.exitCode = 1; ctx.stderr = "Command blocked for security"; ctx.isolationMethod = "blocked";
|
|
312
|
+
console.log(` [TOOL:shell] Blocked: ${ctx.command}`);
|
|
313
|
+
return;
|
|
314
|
+
}
|
|
315
|
+
const timeout = Math.min(ctx.timeout || 30000, 60000);
|
|
316
|
+
const cwd = ctx.cwd || process.cwd();
|
|
317
|
+
const dockerAvailable = await isDockerAvailable();
|
|
318
|
+
console.log(` [TOOL:shell] Running: ${ctx.command} (${dockerAvailable ? "docker" : "process"} isolation)`);
|
|
319
|
+
const result = dockerAvailable
|
|
320
|
+
? await executeInDocker(ctx.command, cwd, timeout)
|
|
321
|
+
: await executeInProcess(ctx.command, cwd, timeout);
|
|
322
|
+
ctx.stdout = result.stdout;
|
|
323
|
+
ctx.stderr = result.stderr;
|
|
324
|
+
ctx.exitCode = result.exitCode;
|
|
325
|
+
ctx.isolationMethod = result.method;
|
|
326
|
+
console.log(` [TOOL:shell] Exit code: ${ctx.exitCode} [${result.method}]`);
|
|
327
|
+
},
|
|
328
|
+
next: [],
|
|
329
|
+
}],
|
|
330
|
+
});
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
export function createNodeCodeTool(): GraphFlow<any> {
|
|
334
|
+
return new GraphFlow({
|
|
335
|
+
name: "node_code",
|
|
336
|
+
schema: z.object({
|
|
337
|
+
code: z.string().describe("JavaScript/TypeScript code to execute"),
|
|
338
|
+
result: z.string().optional().describe("Execution result"),
|
|
339
|
+
error: z.string().optional().describe("Error message"),
|
|
340
|
+
exitCode: z.number().optional().describe("Exit code"),
|
|
341
|
+
isolationMethod: z.string().optional().describe("Isolation method: docker or vm"),
|
|
342
|
+
}),
|
|
343
|
+
context: { code: "", result: "", error: "", exitCode: 0 },
|
|
344
|
+
nodes: [{
|
|
345
|
+
name: "run",
|
|
346
|
+
execute: async (ctx: any) => {
|
|
347
|
+
if (!ctx.code) { ctx.exitCode = 1; ctx.error = "No code provided"; return; }
|
|
348
|
+
const codePreview = ctx.code.length > 80 ? ctx.code.slice(0, 80) + "..." : ctx.code;
|
|
349
|
+
console.log(` [TOOL:node_code] Running: ${codePreview}`);
|
|
350
|
+
const dockerAvailable = await isDockerAvailable();
|
|
351
|
+
|
|
352
|
+
if (dockerAvailable) {
|
|
353
|
+
const result = await executeInDocker(
|
|
354
|
+
`node -e ${JSON.stringify(ctx.code)}`,
|
|
355
|
+
process.cwd(),
|
|
356
|
+
30000
|
|
357
|
+
);
|
|
358
|
+
ctx.result = result.stdout;
|
|
359
|
+
ctx.error = result.stderr;
|
|
360
|
+
ctx.exitCode = result.exitCode;
|
|
361
|
+
ctx.isolationMethod = "docker";
|
|
362
|
+
if (!ctx.result && !ctx.error) ctx.result = "Code executed (no output)";
|
|
363
|
+
} else {
|
|
364
|
+
console.log(` [TOOL:node_code] Docker not available, using vm.Script (limited sandbox)`);
|
|
365
|
+
try {
|
|
366
|
+
const vm = await import("vm");
|
|
367
|
+
const sandbox = {
|
|
368
|
+
ctx,
|
|
369
|
+
result: undefined,
|
|
370
|
+
error: undefined,
|
|
371
|
+
console: {
|
|
372
|
+
log: (...args: any[]) => {
|
|
373
|
+
sandbox._log = (sandbox._log || []).concat(
|
|
374
|
+
args.map(a => typeof a === 'object' ? JSON.stringify(a, null, 2) : String(a))
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
},
|
|
378
|
+
_log: [] as string[]
|
|
379
|
+
};
|
|
380
|
+
const script = new vm.Script(`
|
|
381
|
+
(async () => {
|
|
382
|
+
${ctx.code}
|
|
383
|
+
})()
|
|
384
|
+
`);
|
|
385
|
+
await script.runInNewContext(sandbox);
|
|
386
|
+
const logOutput = sandbox._log?.join('\n') || '';
|
|
387
|
+
const codeResult = sandbox.ctx?.result !== undefined ? String(sandbox.ctx.result) : '';
|
|
388
|
+
ctx.result = logOutput || codeResult;
|
|
389
|
+
ctx.exitCode = 0;
|
|
390
|
+
ctx.isolationMethod = "vm";
|
|
391
|
+
if (!ctx.result) ctx.result = "Code executed (no output)";
|
|
392
|
+
} catch (e: any) {
|
|
393
|
+
ctx.error = e.message;
|
|
394
|
+
ctx.exitCode = 1;
|
|
395
|
+
ctx.isolationMethod = "vm";
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
console.log(` [TOOL:node_code] Exit code: ${ctx.exitCode} [${ctx.isolationMethod}]`);
|
|
399
|
+
if (ctx.result) console.log(` [TOOL:node_code] Result: ${ctx.result.slice(0, 200)}`);
|
|
400
|
+
},
|
|
401
|
+
next: [],
|
|
402
|
+
}],
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
export function createPythonCodeTool(): GraphFlow<any> {
|
|
407
|
+
return new GraphFlow({
|
|
408
|
+
name: "python_code",
|
|
409
|
+
schema: z.object({
|
|
410
|
+
code: z.string().describe("Python code to execute"),
|
|
411
|
+
result: z.string().optional().describe("Execution result (stdout)"),
|
|
412
|
+
error: z.string().optional().describe("Error message (stderr)"),
|
|
413
|
+
exitCode: z.number().optional().describe("Exit code"),
|
|
414
|
+
isolationMethod: z.string().optional().describe("Isolation method: docker or process"),
|
|
415
|
+
}),
|
|
416
|
+
context: { code: "", result: "", error: "", exitCode: 0 },
|
|
417
|
+
nodes: [{
|
|
418
|
+
name: "run",
|
|
419
|
+
execute: async (ctx: any) => {
|
|
420
|
+
if (!ctx.code) {
|
|
421
|
+
ctx.exitCode = 1;
|
|
422
|
+
ctx.error = "No code provided";
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
const codePreview = ctx.code.length > 80 ? ctx.code.slice(0, 80) + "..." : ctx.code;
|
|
426
|
+
console.log(` [TOOL:python_code] Running: ${codePreview}`);
|
|
427
|
+
const timeout = 30000;
|
|
428
|
+
const dockerAvailable = await isDockerAvailable();
|
|
429
|
+
|
|
430
|
+
if (dockerAvailable) {
|
|
431
|
+
const result = await executeInDocker(
|
|
432
|
+
`python3 -c ${JSON.stringify(ctx.code)}`,
|
|
433
|
+
process.cwd(),
|
|
434
|
+
timeout
|
|
435
|
+
);
|
|
436
|
+
ctx.result = result.stdout;
|
|
437
|
+
ctx.error = result.stderr;
|
|
438
|
+
ctx.exitCode = result.exitCode;
|
|
439
|
+
ctx.isolationMethod = "docker";
|
|
440
|
+
} else {
|
|
441
|
+
const result = await executeInProcess(
|
|
442
|
+
`python3 -c ${JSON.stringify(ctx.code)}`,
|
|
443
|
+
process.cwd(),
|
|
444
|
+
timeout
|
|
445
|
+
);
|
|
446
|
+
ctx.result = result.stdout;
|
|
447
|
+
ctx.error = result.stderr;
|
|
448
|
+
ctx.exitCode = result.exitCode;
|
|
449
|
+
ctx.isolationMethod = "process";
|
|
450
|
+
}
|
|
451
|
+
console.log(` [TOOL:python_code] Exit code: ${ctx.exitCode} [${ctx.isolationMethod}]`);
|
|
452
|
+
if (ctx.result) console.log(` [TOOL:python_code] Output: ${ctx.result.slice(0, 300)}`);
|
|
453
|
+
if (ctx.error) console.log(` [TOOL:python_code] Stderr: ${ctx.error.slice(0, 200)}`);
|
|
454
|
+
},
|
|
455
|
+
next: [],
|
|
456
|
+
}],
|
|
457
|
+
});
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
export function createAllAgentTools(): GraphFlow<any>[] {
|
|
461
|
+
return [
|
|
462
|
+
createFileReaderTool(),
|
|
463
|
+
createFileWriterTool(),
|
|
464
|
+
createFileDeleterTool(),
|
|
465
|
+
createDirectoryCreatorTool(),
|
|
466
|
+
createDirectoryListerTool(),
|
|
467
|
+
createShellTool(),
|
|
468
|
+
createNodeCodeTool(),
|
|
469
|
+
createPythonCodeTool(),
|
|
470
|
+
];
|
|
471
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export {
|
|
2
|
+
createFileReaderTool,
|
|
3
|
+
createFileWriterTool,
|
|
4
|
+
createFileDeleterTool,
|
|
5
|
+
createDirectoryCreatorTool,
|
|
6
|
+
createDirectoryListerTool,
|
|
7
|
+
createShellTool,
|
|
8
|
+
createNodeCodeTool,
|
|
9
|
+
createPythonCodeTool,
|
|
10
|
+
createAllAgentTools,
|
|
11
|
+
} from "./file-system";
|
|
12
|
+
|
|
13
|
+
export {
|
|
14
|
+
AgentLogger,
|
|
15
|
+
logger,
|
|
16
|
+
type LogLevel,
|
|
17
|
+
type LogEntry,
|
|
18
|
+
} from "./logger";
|
|
19
|
+
|
|
20
|
+
export {
|
|
21
|
+
resolvePath,
|
|
22
|
+
findInCwd,
|
|
23
|
+
} from "./tool-resolver";
|