@ai.ntellect/core 0.8.3 → 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 +2 -1
- package/AGENTS.md +50 -0
- package/ARCHITECTURE.md +58 -0
- package/BENCHMARK.md +38 -0
- package/CHANGELOG.md +224 -0
- package/README.md +413 -199
- package/agent/agent-workflow.ts +569 -0
- package/agent/agent.ts +183 -0
- package/{modules/agent → agent}/base/executor.ts +11 -8
- package/{modules/agent → agent}/base/index.ts +2 -14
- 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/{modules/agent → agent}/prompt-builder.ts +1 -1
- 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/{modules/agent → agent}/base/executor.d.ts +3 -3
- package/dist/agent/base/executor.d.ts.map +1 -0
- package/dist/{modules/agent → agent}/base/executor.js +8 -5
- package/dist/agent/base/executor.js.map +1 -0
- package/dist/{modules/agent → agent}/base/index.d.ts +1 -1
- package/dist/agent/base/index.d.ts.map +1 -0
- package/dist/{modules/agent → agent}/base/index.js +0 -12
- 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/{modules/agent → agent}/generic-executor.d.ts +37 -27
- 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.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/{modules/agent → agent}/prompt-builder.d.ts +1 -1
- package/dist/agent/prompt-builder.d.ts.map +1 -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.map +1 -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/{graph → execution}/event-manager.js +4 -114
- package/dist/execution/event-manager.js.map +1 -0
- package/dist/{graph → execution}/index.d.ts +50 -2
- 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.map +1 -0
- package/dist/execution/logger.js.map +1 -0
- package/dist/{graph → execution}/node.d.ts +6 -1
- package/dist/execution/node.d.ts.map +1 -0
- package/dist/{graph → execution}/node.js +83 -10
- package/dist/execution/node.js.map +1 -0
- package/dist/execution/observer.d.ts.map +1 -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.map +1 -0
- package/dist/execution/visualizer.js.map +1 -0
- package/dist/index.d.ts +27 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +42 -8
- package/dist/index.js.map +1 -1
- package/dist/interfaces/index.d.ts +32 -1
- package/dist/interfaces/index.d.ts.map +1 -1
- package/dist/interfaces/index.js.map +1 -1
- 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/nlp/engine.d.ts.map +1 -1
- package/dist/modules/nlp/engine.js +0 -1
- package/dist/modules/nlp/engine.js.map +1 -1
- 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 +144 -88
- package/dist/types/agent.d.ts.map +1 -1
- package/dist/types/agent.js +49 -0
- package/dist/types/agent.js.map +1 -1
- package/dist/types/index.d.ts +46 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/utils/generate-action-schema.d.ts +2 -3
- package/dist/utils/generate-action-schema.d.ts.map +1 -1
- package/dist/utils/generate-action-schema.js +3 -1
- package/dist/utils/generate-action-schema.js.map +1 -1
- 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/{graph → execution}/event-manager.ts +4 -117
- package/{graph → execution}/index.ts +376 -8
- package/{graph → execution}/node.ts +116 -12
- 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/index.ts +35 -8
- package/interfaces/index.ts +37 -0
- package/modules/cli/index.ts +580 -0
- package/modules/nlp/engine.ts +0 -1
- package/package.json +50 -16
- 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/{graph → execution}/controller.test.ts +2 -2
- package/test/{graph → execution}/event-manager.test.ts +1 -1
- package/test/{graph → execution}/index.test.ts +24 -15
- package/test/{graph → execution}/node.test.ts +3 -3
- package/test/{graph → execution}/observer.test.ts +2 -2
- 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/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 +5 -2
- package/types/agent.ts +126 -4
- package/types/index.ts +66 -5
- package/utils/generate-action-schema.ts +5 -4
- package/utils/logger.ts +40 -0
- package/dist/graph/controller.d.ts.map +0 -1
- package/dist/graph/controller.js.map +0 -1
- package/dist/graph/event-manager.d.ts +0 -101
- package/dist/graph/event-manager.d.ts.map +0 -1
- package/dist/graph/event-manager.js.map +0 -1
- package/dist/graph/index.d.ts.map +0 -1
- package/dist/graph/index.js +0 -340
- package/dist/graph/index.js.map +0 -1
- package/dist/graph/logger.d.ts.map +0 -1
- package/dist/graph/logger.js.map +0 -1
- package/dist/graph/node.d.ts.map +0 -1
- package/dist/graph/node.js.map +0 -1
- package/dist/graph/observer.d.ts.map +0 -1
- package/dist/graph/observer.js.map +0 -1
- package/dist/graph/visualizer.d.ts.map +0 -1
- package/dist/graph/visualizer.js.map +0 -1
- package/dist/modules/agent/agent.d.ts +0 -35
- package/dist/modules/agent/agent.d.ts.map +0 -1
- package/dist/modules/agent/agent.js +0 -103
- package/dist/modules/agent/agent.js.map +0 -1
- package/dist/modules/agent/base/executor.d.ts.map +0 -1
- package/dist/modules/agent/base/executor.js.map +0 -1
- package/dist/modules/agent/base/index.d.ts.map +0 -1
- package/dist/modules/agent/base/index.js.map +0 -1
- package/dist/modules/agent/generic-assistant.d.ts +0 -20
- package/dist/modules/agent/generic-assistant.d.ts.map +0 -1
- package/dist/modules/agent/generic-assistant.js +0 -89
- package/dist/modules/agent/generic-assistant.js.map +0 -1
- package/dist/modules/agent/generic-executor.d.ts.map +0 -1
- package/dist/modules/agent/generic-executor.js +0 -189
- package/dist/modules/agent/generic-executor.js.map +0 -1
- package/dist/modules/agent/llm-factory.d.ts.map +0 -1
- package/dist/modules/agent/llm-factory.js +0 -56
- package/dist/modules/agent/llm-factory.js.map +0 -1
- package/dist/modules/agent/prompt-builder.d.ts.map +0 -1
- package/dist/modules/agent/prompt-builder.js.map +0 -1
- package/dist/modules/memory/adapters/in-memory/index.d.ts +0 -120
- package/dist/modules/memory/adapters/in-memory/index.d.ts.map +0 -1
- package/dist/modules/memory/adapters/in-memory/index.js +0 -212
- package/dist/modules/memory/adapters/in-memory/index.js.map +0 -1
- package/dist/modules/memory/adapters/meilisearch/index.d.ts +0 -110
- package/dist/modules/memory/adapters/meilisearch/index.d.ts.map +0 -1
- package/dist/modules/memory/adapters/meilisearch/index.js +0 -324
- package/dist/modules/memory/adapters/meilisearch/index.js.map +0 -1
- package/dist/modules/memory/adapters/redis/index.d.ts +0 -82
- package/dist/modules/memory/adapters/redis/index.d.ts.map +0 -1
- package/dist/modules/memory/adapters/redis/index.js +0 -160
- package/dist/modules/memory/adapters/redis/index.js.map +0 -1
- package/dist/modules/memory/index.d.ts +0 -67
- package/dist/modules/memory/index.d.ts.map +0 -1
- package/dist/modules/memory/index.js +0 -104
- package/dist/modules/memory/index.js.map +0 -1
- package/modules/agent/agent.ts +0 -107
- package/modules/agent/generic-assistant.ts +0 -92
- package/modules/agent/generic-executor.ts +0 -252
- package/modules/agent/llm-factory.ts +0 -47
- package/modules/memory/adapters/in-memory/index.ts +0 -208
- package/modules/memory/adapters/meilisearch/index.ts +0 -364
- package/modules/memory/adapters/redis/index.ts +0 -165
- package/modules/memory/index.ts +0 -93
- package/test/modules/memory/adapters/in-memory.test.ts +0 -153
- package/test/modules/memory/adapters/meilisearch.test.ts +0 -287
- package/test/modules/memory/base.test.ts +0 -230
- /package/dist/{modules/agent → agent}/llm-factory.d.ts +0 -0
- /package/dist/{modules/agent → agent}/prompt-builder.js +0 -0
- /package/dist/{graph → execution}/controller.d.ts +0 -0
- /package/dist/{graph → execution}/controller.js +0 -0
- /package/dist/{graph → execution}/logger.d.ts +0 -0
- /package/dist/{graph → execution}/logger.js +0 -0
- /package/dist/{graph → execution}/observer.d.ts +0 -0
- /package/dist/{graph → execution}/observer.js +0 -0
- /package/dist/{graph → execution}/visualizer.d.ts +0 -0
- /package/dist/{graph → execution}/visualizer.js +0 -0
- /package/{graph → execution}/controller.ts +0 -0
- /package/{graph → execution}/logger.ts +0 -0
- /package/{graph → execution}/observer.ts +0 -0
- /package/{graph → execution}/visualizer.ts +0 -0
package/agent/agent.ts
ADDED
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { Checkpoint, CheckpointConfig } from "@/types";
|
|
2
|
+
import { GraphFlow } from "../execution/index";
|
|
3
|
+
import { ICheckpointAdapter } from "../interfaces";
|
|
4
|
+
import {
|
|
5
|
+
AgentConfig,
|
|
6
|
+
AgentContext,
|
|
7
|
+
AgentContextSchema,
|
|
8
|
+
} from "../types/agent";
|
|
9
|
+
import { BaseAgent } from "./base";
|
|
10
|
+
import { GenericExecutor } from "./generic-executor";
|
|
11
|
+
import { AgentLogger } from "./tools/logger";
|
|
12
|
+
import { buildAgentWorkflow } from "./agent-workflow";
|
|
13
|
+
import { EntityIndex } from "./entity-resolver/entity-index";
|
|
14
|
+
import { EntityResolver } from "./entity-resolver/resolver";
|
|
15
|
+
import { ExploreStrategy } from "./entity-resolver/explore-strategy";
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* A generic assistant that can be configured with different roles, goals, and personalities
|
|
19
|
+
* @class Agent
|
|
20
|
+
* @example
|
|
21
|
+
* const assistant = new Agent({
|
|
22
|
+
* role: "Email Assistant",
|
|
23
|
+
* goal: "Help users send emails efficiently",
|
|
24
|
+
* backstory: "I am a professional and friendly assistant who specializes in email communication",
|
|
25
|
+
* llmConfig: { provider: "openai", model: "gpt-4" }
|
|
26
|
+
* tools: []
|
|
27
|
+
* });
|
|
28
|
+
*/
|
|
29
|
+
export class Agent {
|
|
30
|
+
private executor: GenericExecutor;
|
|
31
|
+
private workflow: GraphFlow<typeof AgentContextSchema>;
|
|
32
|
+
public logger: AgentLogger;
|
|
33
|
+
|
|
34
|
+
constructor(config: AgentConfig) {
|
|
35
|
+
const agent = new BaseAgent({
|
|
36
|
+
role: config.role,
|
|
37
|
+
goal: config.goal,
|
|
38
|
+
backstory: config.backstory,
|
|
39
|
+
tools: config.tools,
|
|
40
|
+
memory: config.memory,
|
|
41
|
+
llmConfig: config.llmConfig,
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
const maxIterations = config.maxIterations || 5;
|
|
45
|
+
this.logger = new AgentLogger(config.verbose ?? true);
|
|
46
|
+
|
|
47
|
+
this.executor = new GenericExecutor(agent, config.tools, {
|
|
48
|
+
llmConfig: config.llmConfig,
|
|
49
|
+
verbose: config.verbose,
|
|
50
|
+
}, this.logger, {
|
|
51
|
+
dynamicGoal: config.dynamicGoal,
|
|
52
|
+
dynamicGoalPrompt: config.dynamicGoalPrompt,
|
|
53
|
+
dynamicNext: config.dynamicNext,
|
|
54
|
+
dynamicNextPrompt: config.dynamicNextPrompt,
|
|
55
|
+
enableSchedule: config.enableSchedule,
|
|
56
|
+
agenda: config.agenda,
|
|
57
|
+
});
|
|
58
|
+
this.executor.setLogger(this.logger);
|
|
59
|
+
|
|
60
|
+
const entityIndex = new EntityIndex(config.entityStore);
|
|
61
|
+
if (config.entityStore) {
|
|
62
|
+
entityIndex.hydrate().catch((err: any) =>
|
|
63
|
+
this.logger.log("warn", "agent", `Entity store hydration failed: ${err}`)
|
|
64
|
+
);
|
|
65
|
+
}
|
|
66
|
+
const entityResolver = new EntityResolver(entityIndex);
|
|
67
|
+
const exploreStrategy = new ExploreStrategy(entityIndex);
|
|
68
|
+
this.executor.setEntityIndex(entityIndex);
|
|
69
|
+
|
|
70
|
+
this.workflow = buildAgentWorkflow({
|
|
71
|
+
executor: this.executor,
|
|
72
|
+
baseAgent: agent,
|
|
73
|
+
logger: this.logger,
|
|
74
|
+
maxIterations,
|
|
75
|
+
enableClone: config.enableClone ?? false,
|
|
76
|
+
entityResolver: {
|
|
77
|
+
resolve: (ctx: any) => entityResolver.resolve(ctx),
|
|
78
|
+
getIndex: () => entityIndex,
|
|
79
|
+
},
|
|
80
|
+
exploreStrategy: {
|
|
81
|
+
plan: (candidates: any[], cwd: string) => exploreStrategy.plan(candidates, cwd),
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Processes an input string through the agent's workflow
|
|
88
|
+
* @param {string} input - The input string to process
|
|
89
|
+
* @returns {Promise<AgentContext>} The resulting context after processing
|
|
90
|
+
*/
|
|
91
|
+
public async process(input: string): Promise<AgentContext> {
|
|
92
|
+
await this.workflow.execute("defineGoal", {
|
|
93
|
+
input: { raw: input },
|
|
94
|
+
cwd: process.cwd(),
|
|
95
|
+
actions: [],
|
|
96
|
+
response: "",
|
|
97
|
+
scratchpad: [],
|
|
98
|
+
memories: [],
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
return this.workflow.getContext() as unknown as AgentContext;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
public getWorkflow(): GraphFlow<typeof AgentContextSchema> {
|
|
105
|
+
return this.workflow;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
public async processWithCheckpoint(
|
|
109
|
+
input: string,
|
|
110
|
+
adapter: ICheckpointAdapter,
|
|
111
|
+
config: CheckpointConfig = {}
|
|
112
|
+
): Promise<{ context: AgentContext; checkpointId: string }> {
|
|
113
|
+
const result = await this.workflow.executeWithCheckpoint(
|
|
114
|
+
"defineGoal",
|
|
115
|
+
adapter,
|
|
116
|
+
{
|
|
117
|
+
...config,
|
|
118
|
+
breakpoints: config.breakpoints || ["execute"],
|
|
119
|
+
initialContext: {
|
|
120
|
+
input: { raw: input },
|
|
121
|
+
cwd: process.cwd(),
|
|
122
|
+
scratchpad: [],
|
|
123
|
+
memories: [],
|
|
124
|
+
entityState: config.initialContext?.entityState || {
|
|
125
|
+
currentTarget: undefined,
|
|
126
|
+
lastEntityType: null,
|
|
127
|
+
pendingResolutions: [],
|
|
128
|
+
resolutionTrace: [],
|
|
129
|
+
explored: false,
|
|
130
|
+
},
|
|
131
|
+
conversationState: config.initialContext?.conversationState || {
|
|
132
|
+
currentGoal: "",
|
|
133
|
+
currentTarget: null,
|
|
134
|
+
lastResolvedEntity: null,
|
|
135
|
+
lastResolvedType: null,
|
|
136
|
+
pendingTask: null,
|
|
137
|
+
turnCount: 0,
|
|
138
|
+
pendingIntent: null,
|
|
139
|
+
},
|
|
140
|
+
explorationBudget: config.initialContext?.explorationBudget || {
|
|
141
|
+
maxSteps: 12,
|
|
142
|
+
maxExplorations: 2,
|
|
143
|
+
maxToolCalls: 8,
|
|
144
|
+
stepsUsed: 0,
|
|
145
|
+
explorationsUsed: 0,
|
|
146
|
+
toolCallsUsed: 0,
|
|
147
|
+
},
|
|
148
|
+
...config.initialContext,
|
|
149
|
+
},
|
|
150
|
+
}
|
|
151
|
+
);
|
|
152
|
+
return {
|
|
153
|
+
context: result.context as unknown as AgentContext,
|
|
154
|
+
checkpointId: result.checkpointId,
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
public async resumeFromCheckpoint(
|
|
159
|
+
checkpointId: string,
|
|
160
|
+
adapter: ICheckpointAdapter,
|
|
161
|
+
contextModifications?: Record<string, any>
|
|
162
|
+
): Promise<AgentContext> {
|
|
163
|
+
const result = await this.workflow.resumeFromCheckpoint(
|
|
164
|
+
checkpointId,
|
|
165
|
+
adapter,
|
|
166
|
+
contextModifications
|
|
167
|
+
);
|
|
168
|
+
return result as unknown as AgentContext;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
public async listCheckpoints(
|
|
172
|
+
adapter: ICheckpointAdapter
|
|
173
|
+
): Promise<Checkpoint<typeof AgentContextSchema>[]> {
|
|
174
|
+
return this.workflow.listCheckpoints(adapter);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
public async getCheckpointHistory(
|
|
178
|
+
runId: string,
|
|
179
|
+
adapter: ICheckpointAdapter
|
|
180
|
+
): Promise<Checkpoint<typeof AgentContextSchema>[]> {
|
|
181
|
+
return this.workflow.getCheckpointHistory(runId, adapter);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { BaseAgent } from ".";
|
|
2
|
-
import { GraphFlow } from "
|
|
2
|
+
import { GraphFlow } from "../../execution";
|
|
3
3
|
import {
|
|
4
4
|
ActionSchema,
|
|
5
5
|
AgentContext,
|
|
6
6
|
DecisionOutput,
|
|
7
|
-
} from "
|
|
7
|
+
} from "../../types/agent";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Abstract base class for agent executors that handle action execution
|
|
@@ -69,16 +69,19 @@ export abstract class AgentExecutor {
|
|
|
69
69
|
/**
|
|
70
70
|
* Prepares the input parameters for an action
|
|
71
71
|
* @private
|
|
72
|
-
* @param {Array<{name: string, value: any}>} parameters - Array of parameter objects
|
|
72
|
+
* @param {Array<{name: string, value: any}> | Record<string, any>} parameters - Array of parameter objects or direct object
|
|
73
73
|
* @returns {Record<string, any>} Object with parameter names as keys and their values
|
|
74
74
|
*/
|
|
75
75
|
private prepareActionInputs(
|
|
76
|
-
parameters: Array<{ name: string; value: any }>
|
|
76
|
+
parameters: Array<{ name: string; value: any }> | Record<string, any>
|
|
77
77
|
): Record<string, any> {
|
|
78
|
-
|
|
79
|
-
acc
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
if (Array.isArray(parameters)) {
|
|
79
|
+
return parameters.reduce((acc, param) => {
|
|
80
|
+
acc[param.name] = param.value;
|
|
81
|
+
return acc;
|
|
82
|
+
}, {} as Record<string, any>);
|
|
83
|
+
}
|
|
84
|
+
return parameters as Record<string, any>;
|
|
82
85
|
}
|
|
83
86
|
|
|
84
87
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { AgentConfig } from "@/types/agent";
|
|
2
|
-
import { BaseMemoryType } from "
|
|
3
|
-
import { Memory } from "../../memory";
|
|
2
|
+
import { BaseMemoryType } from "../../types";
|
|
3
|
+
import { Memory } from "../../modules/memory";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Base agent class that handles role, goal, and personality management
|
|
@@ -35,18 +35,6 @@ export class BaseAgent {
|
|
|
35
35
|
});
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
// Execute tools if available
|
|
39
|
-
if (this.config.tools) {
|
|
40
|
-
for (const tool of this.config.tools) {
|
|
41
|
-
try {
|
|
42
|
-
const result = await tool.execute(context, inputs);
|
|
43
|
-
context = { ...context, ...result };
|
|
44
|
-
} catch (error) {
|
|
45
|
-
console.error(`Tool execution failed:`, error);
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
38
|
return context;
|
|
51
39
|
}
|
|
52
40
|
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { ScoredCandidate, Confidence } from "./types";
|
|
2
|
+
|
|
3
|
+
const HIGH_GAP = 0.3;
|
|
4
|
+
const MEDIUM_GAP = 0.15;
|
|
5
|
+
|
|
6
|
+
export function computeConfidence(candidates: ScoredCandidate[]): Confidence {
|
|
7
|
+
if (candidates.length === 0) {
|
|
8
|
+
return { level: "low", score: 0, gap: 0, reason: "no candidates found" };
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
if (candidates.length === 1) {
|
|
12
|
+
const score = candidates[0].breakdown.total;
|
|
13
|
+
if (score >= 0.7) {
|
|
14
|
+
return { level: "high", score, gap: 1, reason: "single candidate with high score" };
|
|
15
|
+
}
|
|
16
|
+
return { level: "medium", score, gap: 1, reason: "single candidate but low score" };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const top = candidates[0].breakdown.total;
|
|
20
|
+
const second = candidates[1].breakdown.total;
|
|
21
|
+
const gap = top - second;
|
|
22
|
+
|
|
23
|
+
if (gap >= HIGH_GAP) {
|
|
24
|
+
return {
|
|
25
|
+
level: "high",
|
|
26
|
+
score: top,
|
|
27
|
+
gap,
|
|
28
|
+
reason: `gap ${gap.toFixed(2)} >= ${HIGH_GAP}, clear winner: ${candidates[0].entity.filename}`,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
if (gap >= MEDIUM_GAP) {
|
|
33
|
+
return {
|
|
34
|
+
level: "medium",
|
|
35
|
+
score: top,
|
|
36
|
+
gap,
|
|
37
|
+
reason: `gap ${gap.toFixed(2)} >= ${MEDIUM_GAP}, ambiguous: ${candidates[0].entity.filename} vs ${candidates[1].entity.filename}`,
|
|
38
|
+
};
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
return {
|
|
42
|
+
level: "low",
|
|
43
|
+
score: top,
|
|
44
|
+
gap,
|
|
45
|
+
reason: `gap ${gap.toFixed(2)} < ${MEDIUM_GAP}, too close: ${candidates.map(c => c.entity.filename).join(", ")}`,
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function confidenceImproved(
|
|
50
|
+
before: Confidence,
|
|
51
|
+
after: Confidence
|
|
52
|
+
): boolean {
|
|
53
|
+
return after.score > before.score;
|
|
54
|
+
}
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import { Entity, EntityCategory } from "./types";
|
|
4
|
+
|
|
5
|
+
export interface IEntityStore {
|
|
6
|
+
upsertMany(entities: Entity[]): Promise<void>;
|
|
7
|
+
loadAll(scope?: string): Promise<Entity[]>;
|
|
8
|
+
recordResolution(entityId: string, query: string, confidence: number): Promise<void>;
|
|
9
|
+
clear(scope?: string): Promise<void>;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function computeStem(filename: string): { stem: string; extension: string | null } {
|
|
13
|
+
const dotIdx = filename.lastIndexOf(".");
|
|
14
|
+
if (dotIdx <= 0) return { stem: filename, extension: null };
|
|
15
|
+
return { stem: filename.slice(0, dotIdx), extension: filename.slice(dotIdx) };
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function computeTokens(stem: string): string[] {
|
|
19
|
+
const parts = stem.split(/[-._\s]+/).filter(Boolean);
|
|
20
|
+
return [...new Set(parts.map(p => p.toLowerCase()))];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function determineCategory(
|
|
24
|
+
name: string,
|
|
25
|
+
isDir: boolean,
|
|
26
|
+
_entries?: { name: string; type: string }[]
|
|
27
|
+
): EntityCategory {
|
|
28
|
+
if (isDir) return "dir";
|
|
29
|
+
const ext = name.includes(".") ? name.slice(name.lastIndexOf(".")).toLowerCase() : "";
|
|
30
|
+
if (ext === ".test.ts" || ext === ".spec.ts" || name.includes(".test.") || name.includes(".spec."))
|
|
31
|
+
return "test";
|
|
32
|
+
return "file";
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type TargetResolution = {
|
|
36
|
+
target: string;
|
|
37
|
+
resolvedEntity: Entity | null;
|
|
38
|
+
path: string | null;
|
|
39
|
+
entityId: string | null;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
export type LookupMode = "exact" | "fuzzy";
|
|
43
|
+
|
|
44
|
+
export class EntityIndex {
|
|
45
|
+
private entities = new Map<string, Entity[]>();
|
|
46
|
+
private byId = new Map<string, Entity>();
|
|
47
|
+
private allEntities: Entity[] = [];
|
|
48
|
+
|
|
49
|
+
constructor(private store?: IEntityStore) {}
|
|
50
|
+
|
|
51
|
+
async hydrate(scope?: string): Promise<void> {
|
|
52
|
+
if (!this.store) return;
|
|
53
|
+
const stored = await this.store.loadAll(scope);
|
|
54
|
+
for (const entity of stored) {
|
|
55
|
+
if (!this.allEntities.some(e => e.id === entity.id)) {
|
|
56
|
+
this.addEntity(entity);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private addEntity(entity: Entity): void {
|
|
62
|
+
const dir = path.dirname(entity.path);
|
|
63
|
+
if (!this.entities.has(dir)) this.entities.set(dir, []);
|
|
64
|
+
this.entities.get(dir)!.push(entity);
|
|
65
|
+
|
|
66
|
+
this.byId.set(entity.id, entity);
|
|
67
|
+
this.allEntities.push(entity);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
ingestDirectory(dirPath: string, entries: { name: string; type: string }[]): void {
|
|
71
|
+
const absDir = path.resolve(dirPath);
|
|
72
|
+
const newEntities: Entity[] = [];
|
|
73
|
+
for (const entry of entries) {
|
|
74
|
+
const isDir = entry.type === "directory";
|
|
75
|
+
const fullPath = path.join(absDir, entry.name);
|
|
76
|
+
const { stem, extension } = computeStem(entry.name);
|
|
77
|
+
const id = path.relative(process.cwd(), fullPath);
|
|
78
|
+
|
|
79
|
+
if (this.allEntities.some(e => e.id === id)) continue;
|
|
80
|
+
|
|
81
|
+
const entity: Entity = {
|
|
82
|
+
id,
|
|
83
|
+
category: determineCategory(entry.name, isDir),
|
|
84
|
+
filename: entry.name,
|
|
85
|
+
stem,
|
|
86
|
+
extension,
|
|
87
|
+
tokens: computeTokens(stem),
|
|
88
|
+
path: fullPath,
|
|
89
|
+
};
|
|
90
|
+
this.addEntity(entity);
|
|
91
|
+
newEntities.push(entity);
|
|
92
|
+
}
|
|
93
|
+
if (newEntities.length > 0 && this.store) {
|
|
94
|
+
this.store.upsertMany(newEntities).catch(() => {});
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
ingestFile(filePath: string): void {
|
|
99
|
+
const absPath = path.resolve(filePath);
|
|
100
|
+
const name = path.basename(absPath);
|
|
101
|
+
const { stem, extension } = computeStem(name);
|
|
102
|
+
const isDir = fs.existsSync(absPath) && fs.statSync(absPath).isDirectory();
|
|
103
|
+
const id = path.relative(process.cwd(), absPath);
|
|
104
|
+
|
|
105
|
+
if (this.allEntities.some(e => e.id === id)) return;
|
|
106
|
+
|
|
107
|
+
const entity: Entity = {
|
|
108
|
+
id,
|
|
109
|
+
category: determineCategory(name, isDir),
|
|
110
|
+
filename: name,
|
|
111
|
+
stem,
|
|
112
|
+
extension,
|
|
113
|
+
tokens: computeTokens(stem),
|
|
114
|
+
path: absPath,
|
|
115
|
+
};
|
|
116
|
+
this.addEntity(entity);
|
|
117
|
+
if (this.store) {
|
|
118
|
+
this.store.upsertMany([entity]).catch(() => {});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
lookup(query: string, options: { mode?: LookupMode } = {}): Entity[] {
|
|
123
|
+
const lower = query.toLowerCase();
|
|
124
|
+
const mode = options.mode ?? "fuzzy";
|
|
125
|
+
const results = new Map<string, Entity>();
|
|
126
|
+
|
|
127
|
+
for (const entity of this.allEntities) {
|
|
128
|
+
if (entity.filename.toLowerCase() === lower) {
|
|
129
|
+
results.set(entity.id, entity);
|
|
130
|
+
if (mode === "exact") break;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
if (mode === "exact") continue;
|
|
134
|
+
if (entity.stem.toLowerCase() === lower) {
|
|
135
|
+
results.set(entity.id, entity);
|
|
136
|
+
continue;
|
|
137
|
+
}
|
|
138
|
+
for (const token of entity.tokens) {
|
|
139
|
+
if (token === lower || token.startsWith(lower) || lower.startsWith(token)) {
|
|
140
|
+
results.set(entity.id, entity);
|
|
141
|
+
break;
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return Array.from(results.values());
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
resolveByTarget(target: string): Entity | null {
|
|
149
|
+
const lower = target.toLowerCase();
|
|
150
|
+
const exact = this.allEntities.find(e => e.filename.toLowerCase() === lower);
|
|
151
|
+
if (exact) return exact;
|
|
152
|
+
|
|
153
|
+
const stemMatch = this.allEntities.find(e => e.stem.toLowerCase() === lower);
|
|
154
|
+
if (stemMatch) return stemMatch;
|
|
155
|
+
|
|
156
|
+
const tokenMatch = this.allEntities.find(e => e.tokens.some(t => t === lower));
|
|
157
|
+
if (tokenMatch) return tokenMatch;
|
|
158
|
+
|
|
159
|
+
const anyMatch = this.allEntities.find(e =>
|
|
160
|
+
e.filename.toLowerCase().includes(lower) ||
|
|
161
|
+
e.stem.toLowerCase().includes(lower) ||
|
|
162
|
+
e.tokens.some(t => t.includes(lower) || lower.includes(t))
|
|
163
|
+
);
|
|
164
|
+
return anyMatch || null;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
resolve(target: string, _toolName?: string): TargetResolution {
|
|
168
|
+
const clean = target.trim();
|
|
169
|
+
|
|
170
|
+
if (!clean) {
|
|
171
|
+
return { target: clean, resolvedEntity: null, path: null, entityId: null };
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const resolved = this.resolveByTarget(clean);
|
|
175
|
+
|
|
176
|
+
if (resolved) {
|
|
177
|
+
return {
|
|
178
|
+
target: clean,
|
|
179
|
+
resolvedEntity: resolved,
|
|
180
|
+
path: resolved.path,
|
|
181
|
+
entityId: resolved.id,
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return {
|
|
186
|
+
target: clean,
|
|
187
|
+
resolvedEntity: null,
|
|
188
|
+
path: clean,
|
|
189
|
+
entityId: null,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
resolveToolParams(
|
|
194
|
+
params: Record<string, any>,
|
|
195
|
+
toolName: string
|
|
196
|
+
): Record<string, any> {
|
|
197
|
+
const result = { ...params };
|
|
198
|
+
|
|
199
|
+
if (result.target) {
|
|
200
|
+
const resolution = this.resolve(result.target, toolName);
|
|
201
|
+
result.entityId = resolution.entityId;
|
|
202
|
+
if (resolution.path) {
|
|
203
|
+
result.path = resolution.path;
|
|
204
|
+
}
|
|
205
|
+
result._entityRef = result.target;
|
|
206
|
+
delete result.target;
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
if (!result.path && result.entityId) {
|
|
210
|
+
const entity = this.getById(result.entityId);
|
|
211
|
+
if (entity) {
|
|
212
|
+
result.path = entity.path;
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
return result;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
getByDir(dirPath: string): Entity[] {
|
|
220
|
+
const absDir = path.resolve(dirPath);
|
|
221
|
+
return this.entities.get(absDir) || [];
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
getAll(): Entity[] {
|
|
225
|
+
return [...this.allEntities];
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
getById(id: string): Entity | undefined {
|
|
229
|
+
return this.byId.get(id) || this.allEntities.find(e => e.id === id);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
clear(): void {
|
|
233
|
+
this.entities.clear();
|
|
234
|
+
this.byId.clear();
|
|
235
|
+
this.allEntities = [];
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
size(): number {
|
|
239
|
+
return this.allEntities.length;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
import * as fs from "fs";
|
|
3
|
+
import { ScoredCandidate, Entity } from "./types";
|
|
4
|
+
import { EntityIndex } from "./entity-index";
|
|
5
|
+
|
|
6
|
+
export type ExploreAction = {
|
|
7
|
+
type: "directory_lister";
|
|
8
|
+
path: string;
|
|
9
|
+
reason: string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export class ExploreStrategy {
|
|
13
|
+
constructor(private index: EntityIndex) {}
|
|
14
|
+
|
|
15
|
+
plan(candidates: ScoredCandidate[], cwd: string): ExploreAction[] {
|
|
16
|
+
const actions: ExploreAction[] = [];
|
|
17
|
+
|
|
18
|
+
if (candidates.length === 0) {
|
|
19
|
+
actions.push({ type: "directory_lister", path: cwd, reason: "no candidates, list cwd" });
|
|
20
|
+
return actions;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const topDir = candidates.find(c => c.entity.category === "dir");
|
|
24
|
+
const topFile = candidates.find(c => c.entity.category === "file");
|
|
25
|
+
|
|
26
|
+
if (topDir && topFile) {
|
|
27
|
+
if (topDir.breakdown.total > topFile.breakdown.total) {
|
|
28
|
+
actions.push({
|
|
29
|
+
type: "directory_lister",
|
|
30
|
+
path: cwd,
|
|
31
|
+
reason: `top candidate is dir "${topDir.entity.filename}", list cwd to confirm`,
|
|
32
|
+
});
|
|
33
|
+
} else {
|
|
34
|
+
const dirPath = path.dirname(topFile.entity.path);
|
|
35
|
+
if (dirPath !== cwd && fs.existsSync(dirPath)) {
|
|
36
|
+
actions.push({
|
|
37
|
+
type: "directory_lister",
|
|
38
|
+
path: dirPath,
|
|
39
|
+
reason: `top candidate is file "${topFile.entity.filename}", list its parent`,
|
|
40
|
+
});
|
|
41
|
+
} else {
|
|
42
|
+
actions.push({
|
|
43
|
+
type: "directory_lister",
|
|
44
|
+
path: cwd,
|
|
45
|
+
reason: "list cwd to disambiguate",
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return actions;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (topDir) {
|
|
53
|
+
actions.push({
|
|
54
|
+
type: "directory_lister",
|
|
55
|
+
path: topDir.entity.path,
|
|
56
|
+
reason: `explore dir candidate "${topDir.entity.filename}"`,
|
|
57
|
+
});
|
|
58
|
+
return actions;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (topFile) {
|
|
62
|
+
const dirPath = path.dirname(topFile.entity.path);
|
|
63
|
+
if (dirPath !== cwd && fs.existsSync(dirPath)) {
|
|
64
|
+
actions.push({
|
|
65
|
+
type: "directory_lister",
|
|
66
|
+
path: dirPath,
|
|
67
|
+
reason: `explore parent of file candidate "${topFile.entity.filename}"`,
|
|
68
|
+
});
|
|
69
|
+
} else {
|
|
70
|
+
actions.push({
|
|
71
|
+
type: "directory_lister",
|
|
72
|
+
path: cwd,
|
|
73
|
+
reason: `list cwd for file candidate "${topFile.entity.filename}"`,
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
return actions;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
actions.push({ type: "directory_lister", path: cwd, reason: "fallback: list cwd" });
|
|
80
|
+
return actions;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export { EntityIndex } from "./entity-index";
|
|
2
|
+
export type { TargetResolution, LookupMode } from "./entity-index";
|
|
3
|
+
export { scoreEntities } from "./scorer";
|
|
4
|
+
export { computeConfidence, confidenceImproved } from "./confidence";
|
|
5
|
+
export { EntityResolver, findEntityInInput } from "./resolver";
|
|
6
|
+
export { ExploreStrategy, type ExploreAction } from "./explore-strategy";
|
|
7
|
+
|
|
8
|
+
export type {
|
|
9
|
+
Entity,
|
|
10
|
+
EntityCategory,
|
|
11
|
+
ScoredCandidate,
|
|
12
|
+
ScoreBreakdown,
|
|
13
|
+
Confidence,
|
|
14
|
+
ConfidenceLevel,
|
|
15
|
+
EntityReference,
|
|
16
|
+
EntityResolution,
|
|
17
|
+
ExplorationBudget,
|
|
18
|
+
PendingIntent,
|
|
19
|
+
ConversationState,
|
|
20
|
+
ResolutionTraceEntry,
|
|
21
|
+
ResolverContext,
|
|
22
|
+
} from "./types";
|