@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,580 @@
|
|
|
1
|
+
import * as readline from "readline";
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import * as path from "path";
|
|
4
|
+
import chalk from "chalk";
|
|
5
|
+
import {
|
|
6
|
+
Agent,
|
|
7
|
+
CheckpointAwaitApprovalError,
|
|
8
|
+
CheckpointInterruptError,
|
|
9
|
+
} from "../../index";
|
|
10
|
+
import { InMemoryCheckpointAdapter } from "../../execution/adapters/in-memory-checkpoint";
|
|
11
|
+
import { Memory } from "../../modules/memory";
|
|
12
|
+
import { InMemoryAdapter } from "../memory/adapters/in-memory";
|
|
13
|
+
import { LLMConfig, LLMProvider } from "../../types/agent";
|
|
14
|
+
import { createAllAgentTools } from "../../agent/tools";
|
|
15
|
+
import { Checkpoint } from "../../types";
|
|
16
|
+
|
|
17
|
+
function loadEnv(): void {
|
|
18
|
+
const envPath = path.resolve(process.cwd(), ".env");
|
|
19
|
+
if (fs.existsSync(envPath)) {
|
|
20
|
+
fs.readFileSync(envPath, "utf-8")
|
|
21
|
+
.split("\n")
|
|
22
|
+
.forEach((line) => {
|
|
23
|
+
const trimmed = line.trim();
|
|
24
|
+
if (trimmed && !trimmed.startsWith("#")) {
|
|
25
|
+
const eqIdx = trimmed.indexOf("=");
|
|
26
|
+
if (eqIdx > 0) {
|
|
27
|
+
const key = trimmed.substring(0, eqIdx).trim();
|
|
28
|
+
const value = trimmed.substring(eqIdx + 1).trim();
|
|
29
|
+
if (!process.env[key]) process.env[key] = value;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
loadEnv();
|
|
37
|
+
|
|
38
|
+
export interface CLIConfig {
|
|
39
|
+
provider: LLMProvider;
|
|
40
|
+
model: string;
|
|
41
|
+
apiKey?: string;
|
|
42
|
+
baseUrl?: string;
|
|
43
|
+
role?: string;
|
|
44
|
+
goal?: string;
|
|
45
|
+
verbose?: boolean;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const DEFAULT_ROLE = "Helpful Assistant";
|
|
49
|
+
const DEFAULT_GOAL = "Assist the user with their requests";
|
|
50
|
+
const DEFAULT_MODEL: Record<LLMProvider, string> = {
|
|
51
|
+
openai: "gpt-4o-mini",
|
|
52
|
+
anthropic: "claude-3-haiku-20240307",
|
|
53
|
+
ollama: "llama3",
|
|
54
|
+
groq: "llama-3.1-8b-instant",
|
|
55
|
+
openrouter: "openai/gpt-4o-mini",
|
|
56
|
+
google: "gemini-2.0-flash",
|
|
57
|
+
custom: "custom",
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
function getLLMConfig(config: CLIConfig): LLMConfig {
|
|
61
|
+
return {
|
|
62
|
+
provider: config.provider,
|
|
63
|
+
model: config.model || DEFAULT_MODEL[config.provider],
|
|
64
|
+
apiKey: config.apiKey,
|
|
65
|
+
baseUrl: config.baseUrl,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function createAgent(config: CLIConfig): Agent {
|
|
70
|
+
const llmConfig = getLLMConfig(config);
|
|
71
|
+
const memory = new Memory(new InMemoryAdapter());
|
|
72
|
+
const tools = createAllAgentTools();
|
|
73
|
+
|
|
74
|
+
return new Agent({
|
|
75
|
+
role: config.role || DEFAULT_ROLE,
|
|
76
|
+
goal: config.goal || DEFAULT_GOAL,
|
|
77
|
+
backstory: `You are a ${config.role || DEFAULT_ROLE}. Be concise and helpful.`,
|
|
78
|
+
tools,
|
|
79
|
+
llmConfig,
|
|
80
|
+
memory,
|
|
81
|
+
verbose: false,
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function createInterface(): readline.Interface {
|
|
86
|
+
return readline.createInterface({
|
|
87
|
+
input: process.stdin,
|
|
88
|
+
output: process.stdout,
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
function getInput(rl: readline.Interface | null, inputQueue: string[], promptText: string): Promise<string> {
|
|
93
|
+
if (inputQueue.length > 0) return Promise.resolve(inputQueue.shift()!.trim());
|
|
94
|
+
if (!rl) return Promise.resolve("");
|
|
95
|
+
return new Promise((resolve) => {
|
|
96
|
+
try { rl.question(promptText, (input) => resolve(input.trim())); }
|
|
97
|
+
catch { resolve(""); }
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function formatSummary(ctx: any, totalMs: number): string {
|
|
102
|
+
const llmCalls: any[] = ctx.llmCalls || [];
|
|
103
|
+
const totalPrompt = llmCalls.reduce((s: number, c: any) => s + (c.promptTokens || 0), 0);
|
|
104
|
+
const totalCompletion = llmCalls.reduce((s: number, c: any) => s + (c.completionTokens || 0), 0);
|
|
105
|
+
const actionCount = ctx.executedActions?.length || 0;
|
|
106
|
+
const parts = [`${(totalMs / 1000).toFixed(1)}s`];
|
|
107
|
+
if (totalPrompt) parts.push(`in ${totalPrompt}`);
|
|
108
|
+
if (totalCompletion) parts.push(`out ${totalCompletion}`);
|
|
109
|
+
if (llmCalls.length) parts.push(`${llmCalls.length} call${llmCalls.length > 1 ? 's' : ''}`);
|
|
110
|
+
if (actionCount) parts.push(`${actionCount} action${actionCount > 1 ? 's' : ''}`);
|
|
111
|
+
return parts.join(" ");
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
async function chatLoop(
|
|
115
|
+
agent: Agent,
|
|
116
|
+
provider: string,
|
|
117
|
+
model: string
|
|
118
|
+
): Promise<void> {
|
|
119
|
+
// Pipe mode: buffer all stdin lines upfront
|
|
120
|
+
const inputQueue: string[] = [];
|
|
121
|
+
if (!process.stdin.isTTY) {
|
|
122
|
+
process.stdin.setEncoding("utf-8");
|
|
123
|
+
let data = "";
|
|
124
|
+
for await (const chunk of process.stdin) data += chunk;
|
|
125
|
+
inputQueue.push(...data.split("\n"));
|
|
126
|
+
}
|
|
127
|
+
const rl = process.stdin.isTTY ? createInterface() : null;
|
|
128
|
+
const checkpointAdapter = new InMemoryCheckpointAdapter();
|
|
129
|
+
let currentRunId: string | null = null;
|
|
130
|
+
let lastCheckpointId: string | null = null;
|
|
131
|
+
let pendingApprovalCp: Checkpoint | null = null;
|
|
132
|
+
let exiting = false;
|
|
133
|
+
|
|
134
|
+
const workflow = agent.getWorkflow();
|
|
135
|
+
let activeStep: string | null = null;
|
|
136
|
+
let activeStepStart = 0;
|
|
137
|
+
let listening = false;
|
|
138
|
+
|
|
139
|
+
workflow.on("nodeStarted", (data: any) => {
|
|
140
|
+
if (!listening) return;
|
|
141
|
+
const name = data?.payload?.name;
|
|
142
|
+
if (!name || name.startsWith("__")) return;
|
|
143
|
+
activeStep = name;
|
|
144
|
+
activeStepStart = Date.now();
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
workflow.on("nodeCompleted", (data: any) => {
|
|
148
|
+
if (!listening) return;
|
|
149
|
+
const name = data?.payload?.name;
|
|
150
|
+
if (!name || name.startsWith("__")) return;
|
|
151
|
+
const elapsed = ((Date.now() - activeStepStart) / 1000).toFixed(1);
|
|
152
|
+
console.log(` ${name.padEnd(14)} ${chalk.green(`${elapsed}s`)}`);
|
|
153
|
+
activeStep = null;
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
const execWithObs = async <T>(fn: () => Promise<T>): Promise<T> => {
|
|
157
|
+
console.log(` ${chalk.dim("\u2500\u2500 Execution \u2500\u2500")}`);
|
|
158
|
+
listening = true;
|
|
159
|
+
try { return await fn(); }
|
|
160
|
+
finally {
|
|
161
|
+
listening = false;
|
|
162
|
+
if (activeStep) {
|
|
163
|
+
const elapsed = ((Date.now() - activeStepStart) / 1000).toFixed(1);
|
|
164
|
+
console.log(` ${activeStep.padEnd(14)} ${chalk.dim(`${elapsed}s`)}`);
|
|
165
|
+
activeStep = null;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
const showBanner = () => {
|
|
171
|
+
console.log(chalk.cyan("\n=== @ai.ntellect/core CLI ==="));
|
|
172
|
+
console.log(chalk.gray(`Provider: ${provider} | Model: ${model}`));
|
|
173
|
+
console.log(chalk.gray("Type /help for commands, /exit to quit\n"));
|
|
174
|
+
console.log(chalk.green("Agent: ") + "Hello! How can I help you today?\n");
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
const printCheckpointStatus = (cpId: string, runId: string | null) => {
|
|
178
|
+
console.log(chalk.yellow(` Checkpoint: ${cpId}`));
|
|
179
|
+
if (runId) console.log(chalk.yellow(` Run ID: ${runId}`));
|
|
180
|
+
};
|
|
181
|
+
|
|
182
|
+
const handleCommand = async (cmd: string) => {
|
|
183
|
+
const parts = cmd.split(" ");
|
|
184
|
+
const command = parts[0].toLowerCase();
|
|
185
|
+
|
|
186
|
+
switch (command) {
|
|
187
|
+
case "/help":
|
|
188
|
+
showHelp();
|
|
189
|
+
break;
|
|
190
|
+
case "/exit":
|
|
191
|
+
case "/quit":
|
|
192
|
+
console.log(chalk.cyan("\nGoodbye!\n"));
|
|
193
|
+
exiting = true;
|
|
194
|
+
rl?.close();
|
|
195
|
+
process.exit(0);
|
|
196
|
+
break;
|
|
197
|
+
case "/clear":
|
|
198
|
+
console.clear();
|
|
199
|
+
showBanner();
|
|
200
|
+
break;
|
|
201
|
+
case "/status":
|
|
202
|
+
if (currentRunId) console.log(chalk.yellow("Current Run:"), currentRunId);
|
|
203
|
+
if (pendingApprovalCp) {
|
|
204
|
+
console.log(chalk.red("Pending Approval:"), pendingApprovalCp.nodeName);
|
|
205
|
+
console.log(chalk.gray(" Context:", JSON.stringify(pendingApprovalCp.context, null, 2)));
|
|
206
|
+
}
|
|
207
|
+
if (lastCheckpointId) console.log(chalk.yellow("Last Checkpoint:"), lastCheckpointId);
|
|
208
|
+
break;
|
|
209
|
+
case "/history":
|
|
210
|
+
case "/h": {
|
|
211
|
+
const runId = parts[1] || currentRunId;
|
|
212
|
+
if (!runId) { console.log(chalk.gray("No run ID. Use /history <runId>")); break; }
|
|
213
|
+
const history = await agent.getCheckpointHistory(runId, checkpointAdapter);
|
|
214
|
+
if (history.length === 0) { console.log(chalk.gray("No checkpoints for this run.")); break; }
|
|
215
|
+
console.log(chalk.cyan(`\nCheckpoint History (run: ${runId.slice(0, 8)}...):`));
|
|
216
|
+
history.forEach((cp, i) => {
|
|
217
|
+
const marker = cp.metadata.awaitingApproval
|
|
218
|
+
? chalk.red(" [BREAKPOINT]")
|
|
219
|
+
: cp.nodeName === "__completed__" ? chalk.green(" [COMPLETED]")
|
|
220
|
+
: cp.nodeName === "__error__" ? chalk.red(" [ERROR]") : "";
|
|
221
|
+
console.log(chalk.gray(` ${i + 1}.`) + ` ${cp.nodeName}` + marker + chalk.dim(` (${cp.id})`));
|
|
222
|
+
});
|
|
223
|
+
console.log();
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
case "/list": {
|
|
227
|
+
const allCps = await agent.listCheckpoints(checkpointAdapter);
|
|
228
|
+
if (allCps.length === 0) { console.log(chalk.gray("No checkpoints saved.")); break; }
|
|
229
|
+
console.log(chalk.cyan("\nAll Checkpoints:"));
|
|
230
|
+
allCps.slice(0, 20).forEach((cp, i) => {
|
|
231
|
+
const runLabel = cp.runId ? ` run:${cp.runId.slice(0, 8)}` : "";
|
|
232
|
+
console.log(chalk.gray(` ${i + 1}.`) + ` ${cp.nodeName}` + chalk.dim(`${runLabel} (${cp.id})`));
|
|
233
|
+
});
|
|
234
|
+
console.log();
|
|
235
|
+
break;
|
|
236
|
+
}
|
|
237
|
+
case "/resume": {
|
|
238
|
+
const cpId = parts[1] || lastCheckpointId;
|
|
239
|
+
if (!cpId) { console.log(chalk.red("No checkpoint ID. Use /resume <id> or run first.")); break; }
|
|
240
|
+
const cp = await checkpointAdapter.load(cpId);
|
|
241
|
+
if (!cp) { console.log(chalk.red(`Checkpoint "${cpId}" not found.`)); break; }
|
|
242
|
+
console.log(chalk.yellow(`\nResuming from "${cp.nodeName}"...`));
|
|
243
|
+
try {
|
|
244
|
+
const result = await execWithObs(() => agent.resumeFromCheckpoint(cpId, checkpointAdapter));
|
|
245
|
+
currentRunId = cp.runId || `run-${Date.now()}`;
|
|
246
|
+
if (result.response) console.log(chalk.green("\nAgent: ") + result.response + "\n");
|
|
247
|
+
console.log(chalk.dim(` [Completed]\n`));
|
|
248
|
+
} catch (error: any) {
|
|
249
|
+
if (error instanceof CheckpointAwaitApprovalError) {
|
|
250
|
+
const cp = await checkpointAdapter.load(error.checkpointId);
|
|
251
|
+
if (cp) {
|
|
252
|
+
pendingApprovalCp = cp;
|
|
253
|
+
console.log(chalk.yellow(`\n\u23F8 Paused at "${pendingApprovalCp.nodeName}" for review.`));
|
|
254
|
+
console.log(chalk.gray("Approve (press Enter), /reject, /modify <key>=<value>, or /exit\n"));
|
|
255
|
+
} else console.log(chalk.red("Checkpoint not found."));
|
|
256
|
+
} else console.log(chalk.red("\nError: ") + (error as Error).message + "\n");
|
|
257
|
+
}
|
|
258
|
+
break;
|
|
259
|
+
}
|
|
260
|
+
case "/reject":
|
|
261
|
+
if (!pendingApprovalCp) { console.log(chalk.gray("No pending approval.")); break; }
|
|
262
|
+
console.log(chalk.red("Rejected. Skipping execution.\n"));
|
|
263
|
+
pendingApprovalCp = null;
|
|
264
|
+
break;
|
|
265
|
+
case "/modify": {
|
|
266
|
+
if (!pendingApprovalCp) { console.log(chalk.gray("No pending approval to modify.")); break; }
|
|
267
|
+
const modifications: Record<string, any> = {};
|
|
268
|
+
for (const part of parts.slice(1)) {
|
|
269
|
+
const eqIdx = part.indexOf("=");
|
|
270
|
+
if (eqIdx > 0) modifications[part.substring(0, eqIdx)] = isNaN(Number(part.substring(eqIdx + 1))) ? part.substring(eqIdx + 1) : Number(part.substring(eqIdx + 1));
|
|
271
|
+
}
|
|
272
|
+
if (Object.keys(modifications).length === 0) { console.log(chalk.red("Usage: /modify key=value [key2=value2]")); break; }
|
|
273
|
+
try {
|
|
274
|
+
const result = await execWithObs(() => agent.resumeFromCheckpoint(pendingApprovalCp!.id, checkpointAdapter, modifications));
|
|
275
|
+
currentRunId = pendingApprovalCp!.runId || `run-${Date.now()}`;
|
|
276
|
+
pendingApprovalCp = null;
|
|
277
|
+
if (result.response) console.log(chalk.green("\nAgent: ") + result.response + "\n");
|
|
278
|
+
} catch (error: any) {
|
|
279
|
+
console.log(chalk.red("\nError: ") + (error as Error).message + "\n");
|
|
280
|
+
}
|
|
281
|
+
break;
|
|
282
|
+
}
|
|
283
|
+
case "/approve":
|
|
284
|
+
if (!pendingApprovalCp) { console.log(chalk.gray("No pending approval.")); break; }
|
|
285
|
+
{ const cp = pendingApprovalCp;
|
|
286
|
+
console.log(chalk.green("Approved. Continuing...\n"));
|
|
287
|
+
try {
|
|
288
|
+
const result = await execWithObs(() => agent.resumeFromCheckpoint(cp.id, checkpointAdapter));
|
|
289
|
+
currentRunId = cp.runId || `run-${Date.now()}`;
|
|
290
|
+
pendingApprovalCp = null;
|
|
291
|
+
if (result.response) console.log(chalk.green("\nAgent: ") + result.response + "\n");
|
|
292
|
+
} catch (error: any) {
|
|
293
|
+
console.log(chalk.red("\nError: ") + (error as Error).message + "\n");
|
|
294
|
+
pendingApprovalCp = null;
|
|
295
|
+
} }
|
|
296
|
+
break;
|
|
297
|
+
case "/breakpoints":
|
|
298
|
+
console.log(chalk.cyan("\nBreakpoint nodes (auto-pause before execution):"));
|
|
299
|
+
console.log(chalk.gray(" - execute (before tool execution)"));
|
|
300
|
+
console.log(chalk.gray(" - think (before every LLM decision)\n"));
|
|
301
|
+
break;
|
|
302
|
+
default:
|
|
303
|
+
console.log(chalk.red(`Unknown command: ${command}. Type /help for commands.`));
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
|
|
307
|
+
const handleApproval = async (message: string) => {
|
|
308
|
+
if (message.toLowerCase() === "approve" || message === "") {
|
|
309
|
+
if (!pendingApprovalCp) return;
|
|
310
|
+
const cp = pendingApprovalCp;
|
|
311
|
+
console.log(chalk.green("Approved. Continuing...\n"));
|
|
312
|
+
try {
|
|
313
|
+
const result = await execWithObs(() => agent.resumeFromCheckpoint(cp.id, checkpointAdapter));
|
|
314
|
+
currentRunId = cp.runId || `run-${Date.now()}`;
|
|
315
|
+
pendingApprovalCp = null;
|
|
316
|
+
if (result.response) console.log(chalk.green("\nAgent: ") + result.response + "\n");
|
|
317
|
+
} catch (error: any) {
|
|
318
|
+
console.log(chalk.red("\nError: ") + (error as Error).message + "\n");
|
|
319
|
+
pendingApprovalCp = null;
|
|
320
|
+
}
|
|
321
|
+
} else if (message.toLowerCase().startsWith("/reject")) {
|
|
322
|
+
console.log(chalk.red("Rejected. Skipping execution.\n"));
|
|
323
|
+
pendingApprovalCp = null;
|
|
324
|
+
} else if (message.toLowerCase().startsWith("/modify")) {
|
|
325
|
+
const parts = message.split(" ");
|
|
326
|
+
const modifications: Record<string, any> = {};
|
|
327
|
+
for (const part of parts.slice(1)) {
|
|
328
|
+
const eqIdx = part.indexOf("=");
|
|
329
|
+
if (eqIdx > 0) modifications[part.substring(0, eqIdx)] = isNaN(Number(part.substring(eqIdx + 1))) ? part.substring(eqIdx + 1) : Number(part.substring(eqIdx + 1));
|
|
330
|
+
}
|
|
331
|
+
if (Object.keys(modifications).length === 0) { console.log(chalk.red("Usage: /modify key=value")); return; }
|
|
332
|
+
try {
|
|
333
|
+
const result = await execWithObs(() => agent.resumeFromCheckpoint(pendingApprovalCp!.id, checkpointAdapter, modifications));
|
|
334
|
+
currentRunId = pendingApprovalCp!.runId || `run-${Date.now()}`;
|
|
335
|
+
pendingApprovalCp = null;
|
|
336
|
+
if (result.response) console.log(chalk.green("\nAgent: ") + result.response + "\n");
|
|
337
|
+
} catch (error: any) {
|
|
338
|
+
console.log(chalk.red("\nError: ") + (error as Error).message + "\n");
|
|
339
|
+
pendingApprovalCp = null;
|
|
340
|
+
}
|
|
341
|
+
} else if (message.toLowerCase().startsWith("/exit")) {
|
|
342
|
+
console.log(chalk.cyan("\nGoodbye!\n"));
|
|
343
|
+
exiting = true;
|
|
344
|
+
rl?.close();
|
|
345
|
+
process.exit(0);
|
|
346
|
+
} else if (message.toLowerCase().startsWith("/")) {
|
|
347
|
+
await handleCommand(message);
|
|
348
|
+
} else {
|
|
349
|
+
console.log(chalk.gray("Use /approve, /reject, /modify key=value, or press Enter to continue."));
|
|
350
|
+
}
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
// ─── Main loop ───
|
|
354
|
+
showBanner();
|
|
355
|
+
|
|
356
|
+
while (!exiting) {
|
|
357
|
+
if (inputQueue.length === 0 && !rl) break;
|
|
358
|
+
|
|
359
|
+
const prefix = pendingApprovalCp
|
|
360
|
+
? chalk.red("[AWAITING APPROVAL] ")
|
|
361
|
+
: currentRunId
|
|
362
|
+
? chalk.green("\u276F ")
|
|
363
|
+
: "";
|
|
364
|
+
|
|
365
|
+
const input = await getInput(rl, inputQueue, prefix + chalk.blue("You: "));
|
|
366
|
+
|
|
367
|
+
if (pendingApprovalCp) {
|
|
368
|
+
await handleApproval(input);
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
if (!input) continue;
|
|
373
|
+
|
|
374
|
+
if (input.startsWith("/")) {
|
|
375
|
+
await handleCommand(input);
|
|
376
|
+
continue;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
// ── Process a user message ──
|
|
380
|
+
try {
|
|
381
|
+
currentRunId = `run-${Date.now()}`;
|
|
382
|
+
const t0 = performance.now();
|
|
383
|
+
|
|
384
|
+
const result = await execWithObs(() =>
|
|
385
|
+
agent.processWithCheckpoint(input, checkpointAdapter, {
|
|
386
|
+
runId: currentRunId!,
|
|
387
|
+
saveOnComplete: true,
|
|
388
|
+
})
|
|
389
|
+
);
|
|
390
|
+
|
|
391
|
+
lastCheckpointId = result.checkpointId;
|
|
392
|
+
const ctx = result.context;
|
|
393
|
+
|
|
394
|
+
// ── Agent response ──
|
|
395
|
+
if (ctx.response) {
|
|
396
|
+
console.log(chalk.green("\nAgent: ") + ctx.response + "\n");
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// ── Summary line ──
|
|
400
|
+
console.log(chalk.dim(` ${formatSummary(ctx, performance.now() - t0)}`));
|
|
401
|
+
|
|
402
|
+
// ── Checkpoint save confirmation ──
|
|
403
|
+
const history = await agent.getCheckpointHistory(currentRunId, checkpointAdapter);
|
|
404
|
+
const completed = history.find((c) => c.nodeName === "__completed__");
|
|
405
|
+
if (completed) {
|
|
406
|
+
console.log(chalk.dim(` [Saved: ${completed.id}]\n`));
|
|
407
|
+
lastCheckpointId = completed.id;
|
|
408
|
+
}
|
|
409
|
+
} catch (error) {
|
|
410
|
+
if (error instanceof CheckpointAwaitApprovalError) {
|
|
411
|
+
const cp = await checkpointAdapter.load(error.checkpointId);
|
|
412
|
+
if (cp) {
|
|
413
|
+
pendingApprovalCp = cp;
|
|
414
|
+
const actions = cp.context?.actions || [];
|
|
415
|
+
console.log(chalk.yellow(`\n\u23F8 Paused at "${pendingApprovalCp.nodeName}" for review.`));
|
|
416
|
+
if (actions.length > 0) {
|
|
417
|
+
console.log(chalk.cyan(" Planned actions:"));
|
|
418
|
+
actions.forEach((a: any) => {
|
|
419
|
+
const params = Array.isArray(a.parameters)
|
|
420
|
+
? a.parameters.map((p: any) => `${p.name}=${JSON.stringify(p.value)}`).join(", ")
|
|
421
|
+
: JSON.stringify(a.parameters);
|
|
422
|
+
console.log(chalk.gray(` \u2192 ${a.name}(${params})`));
|
|
423
|
+
});
|
|
424
|
+
}
|
|
425
|
+
console.log(chalk.gray("Approve (press Enter), /reject, /modify <key>=<value>, /resume <cpId>, or /exit\n"));
|
|
426
|
+
lastCheckpointId = error.checkpointId;
|
|
427
|
+
printCheckpointStatus(error.checkpointId, currentRunId);
|
|
428
|
+
} else {
|
|
429
|
+
console.log(chalk.red("Checkpoint not found."));
|
|
430
|
+
}
|
|
431
|
+
} else if (error instanceof CheckpointInterruptError) {
|
|
432
|
+
lastCheckpointId = error.checkpointId;
|
|
433
|
+
console.log(chalk.yellow(`\n\u23F8 Interrupted. Checkpoint: ${error.checkpointId}`));
|
|
434
|
+
console.log(chalk.gray("/resume to continue, /exit to quit\n"));
|
|
435
|
+
} else {
|
|
436
|
+
console.log(chalk.red("\nError: ") + (error as Error).message + "\n");
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
rl?.close();
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
function showHelp(): void {
|
|
445
|
+
console.log(`
|
|
446
|
+
${chalk.cyan("Commands")}
|
|
447
|
+
|
|
448
|
+
${chalk.bold("Chat:")}
|
|
449
|
+
(text) Send a message to the agent
|
|
450
|
+
|
|
451
|
+
${chalk.bold("Checkpoint:")}
|
|
452
|
+
/status Show current run and checkpoint status
|
|
453
|
+
/history [runId] Show checkpoint history for current or specified run
|
|
454
|
+
/list List all saved checkpoints
|
|
455
|
+
/resume [cpId] Resume execution from a checkpoint
|
|
456
|
+
|
|
457
|
+
${chalk.bold("Human-in-the-Loop:")}
|
|
458
|
+
/approve Approve and continue from breakpoint
|
|
459
|
+
/reject Reject and skip current execution
|
|
460
|
+
/modify k=v Modify context and continue (e.g., /modify value=42)
|
|
461
|
+
|
|
462
|
+
${chalk.bold("Other:")}
|
|
463
|
+
/clear Clear screen
|
|
464
|
+
/help Show this help
|
|
465
|
+
/exit Quit the CLI
|
|
466
|
+
|
|
467
|
+
${chalk.bold("Breakpoint Behavior:")}
|
|
468
|
+
Before the agent "thinks" (calls LLM), execution pauses.
|
|
469
|
+
You can review state, modify context, approve, or reject.
|
|
470
|
+
`);
|
|
471
|
+
}
|
|
472
|
+
|
|
473
|
+
export async function runCLI(config: CLIConfig): Promise<void> {
|
|
474
|
+
const llmConfig = getLLMConfig(config);
|
|
475
|
+
|
|
476
|
+
if (
|
|
477
|
+
!process.env.OPENAI_API_KEY &&
|
|
478
|
+
config.provider === "openai" &&
|
|
479
|
+
!config.apiKey
|
|
480
|
+
) {
|
|
481
|
+
console.log(
|
|
482
|
+
chalk.red("Error: OPENAI_API_KEY environment variable is not set.")
|
|
483
|
+
);
|
|
484
|
+
console.log(chalk.gray("Set it with: export OPENAI_API_KEY=your-key"));
|
|
485
|
+
process.exit(1);
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
console.log(chalk.cyan(`Starting ${config.role || DEFAULT_ROLE}...`));
|
|
489
|
+
|
|
490
|
+
const agent = createAgent(config);
|
|
491
|
+
await chatLoop(agent, config.provider, llmConfig.model);
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
export async function startCLI(): Promise<void> {
|
|
495
|
+
const args = process.argv.slice(2);
|
|
496
|
+
const config: CLIConfig = {
|
|
497
|
+
provider: "ollama",
|
|
498
|
+
model: "",
|
|
499
|
+
baseUrl: "http://localhost:11434",
|
|
500
|
+
};
|
|
501
|
+
|
|
502
|
+
for (let i = 0; i < args.length; i++) {
|
|
503
|
+
const arg = args[i];
|
|
504
|
+
switch (arg) {
|
|
505
|
+
case "--provider":
|
|
506
|
+
case "-p":
|
|
507
|
+
config.provider = args[++i] as LLMProvider;
|
|
508
|
+
break;
|
|
509
|
+
case "--model":
|
|
510
|
+
case "-m":
|
|
511
|
+
config.model = args[++i];
|
|
512
|
+
break;
|
|
513
|
+
case "--api-key":
|
|
514
|
+
config.apiKey = args[++i];
|
|
515
|
+
break;
|
|
516
|
+
case "--base-url":
|
|
517
|
+
case "-b":
|
|
518
|
+
config.baseUrl = args[++i];
|
|
519
|
+
break;
|
|
520
|
+
case "--role":
|
|
521
|
+
case "-r":
|
|
522
|
+
config.role = args[++i];
|
|
523
|
+
break;
|
|
524
|
+
case "--goal":
|
|
525
|
+
case "-g":
|
|
526
|
+
config.goal = args[++i];
|
|
527
|
+
break;
|
|
528
|
+
case "--verbose":
|
|
529
|
+
case "-v":
|
|
530
|
+
config.verbose = true;
|
|
531
|
+
break;
|
|
532
|
+
case "--help":
|
|
533
|
+
case "-h":
|
|
534
|
+
showHelp();
|
|
535
|
+
return;
|
|
536
|
+
default:
|
|
537
|
+
if (!arg.startsWith("-")) {
|
|
538
|
+
config.role = arg;
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
// Auto-resolve API keys from .env / environment
|
|
544
|
+
if (config.provider === "openai" && !config.apiKey) {
|
|
545
|
+
config.apiKey = process.env.OPENAI_API_KEY;
|
|
546
|
+
}
|
|
547
|
+
if (config.provider === "groq" && !config.apiKey) {
|
|
548
|
+
config.apiKey = process.env.GROQ_API_KEY;
|
|
549
|
+
}
|
|
550
|
+
if (config.provider === "openrouter" && !config.apiKey) {
|
|
551
|
+
config.apiKey = process.env.OPENROUTER_API_KEY;
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
if (config.provider === "openai" && !config.apiKey) {
|
|
555
|
+
console.log(chalk.red("Error: OpenAI requires an API key."));
|
|
556
|
+
console.log(chalk.gray("Use --api-key, set OPENAI_API_KEY, or add to .env"));
|
|
557
|
+
process.exit(1);
|
|
558
|
+
}
|
|
559
|
+
if (config.provider === "groq" && !config.apiKey) {
|
|
560
|
+
console.log(chalk.red("Error: Groq requires an API key."));
|
|
561
|
+
console.log(chalk.gray("Use --api-key, set GROQ_API_KEY, or add to .env"));
|
|
562
|
+
process.exit(1);
|
|
563
|
+
}
|
|
564
|
+
if (config.provider === "openrouter" && !config.apiKey) {
|
|
565
|
+
console.log(chalk.red("Error: OpenRouter requires an API key."));
|
|
566
|
+
console.log(chalk.gray("Use --api-key, set OPENROUTER_API_KEY, or add to .env"));
|
|
567
|
+
process.exit(1);
|
|
568
|
+
}
|
|
569
|
+
if (config.provider === "google" && !config.apiKey) {
|
|
570
|
+
console.log(chalk.red("Error: Google requires an API key."));
|
|
571
|
+
console.log(chalk.gray("Use --api-key, set GOOGLE_API_KEY, or add to .env"));
|
|
572
|
+
process.exit(1);
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
await runCLI(config);
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
if (require.main === module) {
|
|
579
|
+
startCLI();
|
|
580
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { embed, EmbeddingModel, embedMany } from "ai";
|
|
2
|
+
import { IEmbeddingModel } from "../../../../interfaces";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @module AIEmbeddingAdapter
|
|
6
|
+
* @description Adapter implementation for AI-based embedding service.
|
|
7
|
+
* Provides integration with AI models for text embedding generation.
|
|
8
|
+
* @implements {IEmbeddingModel}
|
|
9
|
+
*/
|
|
10
|
+
export class AIEmbeddingAdapter implements IEmbeddingModel {
|
|
11
|
+
/**
|
|
12
|
+
* Creates an instance of AIEmbeddingAdapter
|
|
13
|
+
* @param {EmbeddingModel<string>} model - The AI embedding model to use
|
|
14
|
+
*/
|
|
15
|
+
constructor(private readonly model: EmbeddingModel<string>) {}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Generates an embedding vector for a single text using the AI model
|
|
19
|
+
* @param {string} text - The text to embed
|
|
20
|
+
* @returns {Promise<number[]>} The generated embedding vector
|
|
21
|
+
*/
|
|
22
|
+
async embed(text: string): Promise<number[]> {
|
|
23
|
+
const { embedding } = await embed({
|
|
24
|
+
model: this.model,
|
|
25
|
+
value: text,
|
|
26
|
+
});
|
|
27
|
+
return embedding;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Generates embedding vectors for multiple texts using the AI model
|
|
32
|
+
* @param {string[]} texts - Array of texts to embed
|
|
33
|
+
* @returns {Promise<number[][]>} Array of generated embedding vectors
|
|
34
|
+
*/
|
|
35
|
+
async embedMany(texts: string[]): Promise<number[][]> {
|
|
36
|
+
const { embeddings } = await embedMany({
|
|
37
|
+
model: this.model,
|
|
38
|
+
values: texts,
|
|
39
|
+
});
|
|
40
|
+
return embeddings;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { cosineSimilarity } from "ai";
|
|
2
|
+
import { IEmbeddingModel, IEmbeddingModule } from "../../interfaces";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* @module EmbeddingManager
|
|
6
|
+
* @description A module for generating and managing text embeddings.
|
|
7
|
+
* Provides functionality for converting text into vector representations
|
|
8
|
+
* and calculating similarities between embeddings.
|
|
9
|
+
* @implements {IEmbeddingModule}
|
|
10
|
+
*/
|
|
11
|
+
export class EmbeddingManager implements IEmbeddingModule {
|
|
12
|
+
/**
|
|
13
|
+
* Creates an instance of EmbeddingManager
|
|
14
|
+
* @param {IEmbeddingModel} embeddingModel - The embedding model implementation to use
|
|
15
|
+
*/
|
|
16
|
+
constructor(private readonly embeddingModel: IEmbeddingModel) {}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Generates an embedding vector for a single text
|
|
20
|
+
* @param {string} text - The text to embed
|
|
21
|
+
* @returns {Promise<number[]>} The embedding vector
|
|
22
|
+
*/
|
|
23
|
+
async embedText(text: string): Promise<number[]> {
|
|
24
|
+
return this.embeddingModel.embed(text);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Generates embedding vectors for multiple texts
|
|
29
|
+
* @param {string[]} texts - Array of texts to embed
|
|
30
|
+
* @returns {Promise<number[][]>} Array of embedding vectors
|
|
31
|
+
*/
|
|
32
|
+
async embedMany(texts: string[]): Promise<number[][]> {
|
|
33
|
+
return this.embeddingModel.embedMany(texts);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Calculates the similarity score between two embeddings
|
|
38
|
+
* @param {number[]} embedding1 - First embedding vector
|
|
39
|
+
* @param {number[]} embedding2 - Second embedding vector
|
|
40
|
+
* @returns {number} Similarity score between 0 and 100
|
|
41
|
+
*/
|
|
42
|
+
calculateSimilarity(embedding1: number[], embedding2: number[]): number {
|
|
43
|
+
return (cosineSimilarity(embedding1, embedding2) + 1) * 50;
|
|
44
|
+
}
|
|
45
|
+
}
|