@ai.ntellect/core 1.0.0 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mocharc.json +6 -0
- package/AGENTS.md +50 -0
- package/ARCHITECTURE.md +58 -0
- package/BENCHMARK.md +38 -0
- package/CHANGELOG.md +224 -0
- package/README.md +411 -142
- package/agent/agent-workflow.ts +569 -0
- package/agent/agent.ts +183 -0
- package/agent/base/executor.ts +103 -0
- package/agent/base/index.ts +87 -0
- package/agent/entity-resolver/confidence.ts +54 -0
- package/agent/entity-resolver/entity-index.ts +241 -0
- package/agent/entity-resolver/explore-strategy.ts +82 -0
- package/agent/entity-resolver/index.ts +22 -0
- package/agent/entity-resolver/resolver.ts +193 -0
- package/agent/entity-resolver/scorer.ts +211 -0
- package/agent/entity-resolver/types.ts +98 -0
- package/agent/generic-executor.ts +713 -0
- package/agent/handlers/cognitive-handler.ts +197 -0
- package/agent/handlers/index.ts +1 -0
- package/agent/handoff.ts +58 -0
- package/agent/llm-factory.ts +343 -0
- package/agent/orchestrator.ts +45 -0
- package/agent/prompt-builder.ts +78 -0
- package/agent/registry.ts +64 -0
- package/agent/tools/file-system.ts +471 -0
- package/agent/tools/index.ts +23 -0
- package/agent/tools/logger.ts +105 -0
- package/agent/tools/tool-resolver.ts +104 -0
- package/benchmark/cortexflow-workflow.ts +182 -0
- package/benchmark/langgraph-workflow.ts +201 -0
- package/benchmark/llm-client.ts +76 -0
- package/benchmark/run-benchmark.ts +222 -0
- package/cli-dev.ts +419 -0
- package/dist/agent/agent-workflow.d.ts +41 -0
- package/dist/agent/agent-workflow.d.ts.map +1 -0
- package/dist/agent/agent-workflow.js +560 -0
- package/dist/agent/agent-workflow.js.map +1 -0
- package/dist/agent/agent.d.ts +38 -0
- package/dist/agent/agent.d.ts.map +1 -0
- package/dist/agent/agent.js +149 -0
- package/dist/agent/agent.js.map +1 -0
- package/dist/agent/base/executor.d.ts +51 -0
- package/dist/agent/base/executor.d.ts.map +1 -0
- package/dist/agent/base/executor.js +69 -0
- package/dist/agent/base/executor.js.map +1 -0
- package/dist/agent/base/index.d.ts +30 -0
- package/dist/agent/base/index.d.ts.map +1 -0
- package/dist/agent/base/index.js +88 -0
- package/dist/agent/base/index.js.map +1 -0
- package/dist/agent/entity-resolver/confidence.d.ts +4 -0
- package/dist/agent/entity-resolver/confidence.d.ts.map +1 -0
- package/dist/agent/entity-resolver/confidence.js +47 -0
- package/dist/agent/entity-resolver/confidence.js.map +1 -0
- package/dist/agent/entity-resolver/entity-index.d.ts +40 -0
- package/dist/agent/entity-resolver/entity-index.d.ts.map +1 -0
- package/dist/agent/entity-resolver/entity-index.js +244 -0
- package/dist/agent/entity-resolver/entity-index.js.map +1 -0
- package/dist/agent/entity-resolver/explore-strategy.d.ts +13 -0
- package/dist/agent/entity-resolver/explore-strategy.d.ts.map +1 -0
- package/dist/agent/entity-resolver/explore-strategy.js +109 -0
- package/dist/agent/entity-resolver/explore-strategy.js.map +1 -0
- package/dist/agent/entity-resolver/index.d.ts +8 -0
- package/dist/agent/entity-resolver/index.d.ts.map +1 -0
- package/dist/agent/entity-resolver/index.js +16 -0
- package/dist/agent/entity-resolver/index.js.map +1 -0
- package/dist/agent/entity-resolver/resolver.d.ts +18 -0
- package/dist/agent/entity-resolver/resolver.d.ts.map +1 -0
- package/dist/agent/entity-resolver/resolver.js +158 -0
- package/dist/agent/entity-resolver/resolver.js.map +1 -0
- package/dist/agent/entity-resolver/scorer.d.ts +3 -0
- package/dist/agent/entity-resolver/scorer.d.ts.map +1 -0
- package/dist/agent/entity-resolver/scorer.js +182 -0
- package/dist/agent/entity-resolver/scorer.js.map +1 -0
- package/dist/agent/entity-resolver/types.d.ts +89 -0
- package/dist/agent/entity-resolver/types.d.ts.map +1 -0
- package/dist/agent/entity-resolver/types.js +3 -0
- package/dist/agent/entity-resolver/types.js.map +1 -0
- package/dist/agent/generic-executor.d.ts +68 -0
- package/dist/agent/generic-executor.d.ts.map +1 -0
- package/dist/agent/generic-executor.js +620 -0
- package/dist/agent/generic-executor.js.map +1 -0
- package/dist/agent/handlers/cognitive-handler.d.ts +44 -0
- package/dist/agent/handlers/cognitive-handler.d.ts.map +1 -0
- package/dist/agent/handlers/cognitive-handler.js +172 -0
- package/dist/agent/handlers/cognitive-handler.js.map +1 -0
- package/dist/agent/handlers/index.d.ts +2 -0
- package/dist/agent/handlers/index.d.ts.map +1 -0
- package/dist/agent/handlers/index.js +7 -0
- package/dist/agent/handlers/index.js.map +1 -0
- package/dist/agent/handoff.d.ts +12 -0
- package/dist/agent/handoff.d.ts.map +1 -0
- package/dist/agent/handoff.js +62 -0
- package/dist/agent/handoff.js.map +1 -0
- package/dist/agent/llm-factory.d.ts +19 -0
- package/dist/agent/llm-factory.d.ts.map +1 -0
- package/dist/agent/llm-factory.js +297 -0
- package/dist/agent/llm-factory.js.map +1 -0
- package/dist/agent/orchestrator.d.ts +18 -0
- package/dist/agent/orchestrator.d.ts.map +1 -0
- package/dist/agent/orchestrator.js +44 -0
- package/dist/agent/orchestrator.js.map +1 -0
- package/dist/agent/prompt-builder.d.ts +35 -0
- package/dist/agent/prompt-builder.d.ts.map +1 -0
- package/dist/agent/prompt-builder.js +76 -0
- package/dist/agent/prompt-builder.js.map +1 -0
- package/dist/agent/registry.d.ts +19 -0
- package/dist/agent/registry.d.ts.map +1 -0
- package/dist/agent/registry.js +48 -0
- package/dist/agent/registry.js.map +1 -0
- package/dist/agent/tools/file-system.d.ts +11 -0
- package/dist/agent/tools/file-system.d.ts.map +1 -0
- package/dist/agent/tools/file-system.js +528 -0
- package/dist/agent/tools/file-system.js.map +1 -0
- package/dist/agent/tools/index.d.ts +4 -0
- package/dist/agent/tools/index.d.ts.map +1 -0
- package/dist/agent/tools/index.js +20 -0
- package/dist/agent/tools/index.js.map +1 -0
- package/dist/agent/tools/logger.d.ts +33 -0
- package/dist/agent/tools/logger.d.ts.map +1 -0
- package/dist/agent/tools/logger.js +86 -0
- package/dist/agent/tools/logger.js.map +1 -0
- package/dist/agent/tools/tool-resolver.d.ts +7 -0
- package/dist/agent/tools/tool-resolver.d.ts.map +1 -0
- package/dist/agent/tools/tool-resolver.js +122 -0
- package/dist/agent/tools/tool-resolver.js.map +1 -0
- package/dist/execution/adapters/in-memory-checkpoint.d.ts +11 -0
- package/dist/execution/adapters/in-memory-checkpoint.d.ts.map +1 -0
- package/dist/execution/adapters/in-memory-checkpoint.js +54 -0
- package/dist/execution/adapters/in-memory-checkpoint.js.map +1 -0
- package/dist/execution/compiler.d.ts +8 -0
- package/dist/execution/compiler.d.ts.map +1 -0
- package/dist/execution/compiler.js +50 -0
- package/dist/execution/compiler.js.map +1 -0
- package/dist/execution/controller.d.ts +30 -0
- package/dist/execution/controller.d.ts.map +1 -0
- package/dist/execution/controller.js +80 -0
- package/dist/execution/controller.js.map +1 -0
- package/dist/execution/event-manager.d.ts +29 -0
- package/dist/execution/event-manager.d.ts.map +1 -0
- package/dist/execution/event-manager.js +264 -0
- package/dist/execution/event-manager.js.map +1 -0
- package/dist/execution/index.d.ts +221 -0
- package/dist/execution/index.d.ts.map +1 -0
- package/dist/execution/index.js +638 -0
- package/dist/execution/index.js.map +1 -0
- package/dist/execution/logger.d.ts +46 -0
- package/dist/execution/logger.d.ts.map +1 -0
- package/dist/execution/logger.js +69 -0
- package/dist/execution/logger.js.map +1 -0
- package/dist/execution/node.d.ts +65 -0
- package/dist/execution/node.d.ts.map +1 -0
- package/dist/execution/node.js +250 -0
- package/dist/execution/node.js.map +1 -0
- package/dist/execution/observer.d.ts +38 -0
- package/dist/execution/observer.d.ts.map +1 -0
- package/dist/execution/observer.js +111 -0
- package/dist/execution/observer.js.map +1 -0
- package/dist/execution/planner.d.ts +14 -0
- package/dist/execution/planner.d.ts.map +1 -0
- package/dist/execution/planner.js +43 -0
- package/dist/execution/planner.js.map +1 -0
- package/dist/execution/reducer.d.ts +19 -0
- package/dist/execution/reducer.d.ts.map +1 -0
- package/dist/execution/reducer.js +61 -0
- package/dist/execution/reducer.js.map +1 -0
- package/dist/execution/registry.d.ts +38 -0
- package/dist/execution/registry.d.ts.map +1 -0
- package/dist/execution/registry.js +63 -0
- package/dist/execution/registry.js.map +1 -0
- package/dist/execution/send-api.d.ts +24 -0
- package/dist/execution/send-api.d.ts.map +1 -0
- package/dist/execution/send-api.js +52 -0
- package/dist/execution/send-api.js.map +1 -0
- package/dist/execution/types.parallel.d.ts +61 -0
- package/dist/execution/types.parallel.d.ts.map +1 -0
- package/dist/execution/types.parallel.js +3 -0
- package/dist/execution/types.parallel.js.map +1 -0
- package/dist/execution/visualizer.d.ts +35 -0
- package/dist/execution/visualizer.d.ts.map +1 -0
- package/dist/execution/visualizer.js +131 -0
- package/dist/execution/visualizer.js.map +1 -0
- package/dist/index.d.ts +47 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +78 -0
- package/dist/index.js.map +1 -0
- package/dist/interfaces/index.d.ts +487 -0
- package/dist/interfaces/index.d.ts.map +1 -0
- package/dist/interfaces/index.js +75 -0
- package/dist/interfaces/index.js.map +1 -0
- package/dist/modules/agenda/adapters/node-cron/index.d.ts +17 -0
- package/dist/modules/agenda/adapters/node-cron/index.d.ts.map +1 -0
- package/dist/modules/agenda/adapters/node-cron/index.js +30 -0
- package/dist/modules/agenda/adapters/node-cron/index.js.map +1 -0
- package/dist/modules/agenda/index.d.ts +63 -0
- package/dist/modules/agenda/index.d.ts.map +1 -0
- package/dist/modules/agenda/index.js +141 -0
- package/dist/modules/agenda/index.js.map +1 -0
- package/dist/modules/cli/index.d.ts +13 -0
- package/dist/modules/cli/index.d.ts.map +1 -0
- package/dist/modules/cli/index.js +672 -0
- package/dist/modules/cli/index.js.map +1 -0
- package/dist/modules/embedding/adapters/ai/index.d.ts +29 -0
- package/dist/modules/embedding/adapters/ai/index.d.ts.map +1 -0
- package/dist/modules/embedding/adapters/ai/index.js +58 -0
- package/dist/modules/embedding/adapters/ai/index.js.map +1 -0
- package/dist/modules/embedding/index.d.ts +36 -0
- package/dist/modules/embedding/index.d.ts.map +1 -0
- package/dist/modules/embedding/index.js +60 -0
- package/dist/modules/embedding/index.js.map +1 -0
- package/dist/modules/nlp/engine.d.ts +126 -0
- package/dist/modules/nlp/engine.d.ts.map +1 -0
- package/dist/modules/nlp/engine.js +299 -0
- package/dist/modules/nlp/engine.js.map +1 -0
- package/dist/modules/nlp/index.d.ts +27 -0
- package/dist/modules/nlp/index.d.ts.map +1 -0
- package/dist/modules/nlp/index.js +56 -0
- package/dist/modules/nlp/index.js.map +1 -0
- package/dist/persistence/index.d.ts +12 -0
- package/dist/persistence/index.d.ts.map +1 -0
- package/dist/persistence/index.js +24 -0
- package/dist/persistence/index.js.map +1 -0
- package/dist/persistence/neo4j/driver.d.ts +26 -0
- package/dist/persistence/neo4j/driver.d.ts.map +1 -0
- package/dist/persistence/neo4j/driver.js +64 -0
- package/dist/persistence/neo4j/driver.js.map +1 -0
- package/dist/persistence/neo4j/entity-store.d.ts +15 -0
- package/dist/persistence/neo4j/entity-store.d.ts.map +1 -0
- package/dist/persistence/neo4j/entity-store.js +136 -0
- package/dist/persistence/neo4j/entity-store.js.map +1 -0
- package/dist/persistence/neo4j/execution-tracer.d.ts +19 -0
- package/dist/persistence/neo4j/execution-tracer.d.ts.map +1 -0
- package/dist/persistence/neo4j/execution-tracer.js +166 -0
- package/dist/persistence/neo4j/execution-tracer.js.map +1 -0
- package/dist/persistence/neo4j/memory-adapter.d.ts +35 -0
- package/dist/persistence/neo4j/memory-adapter.d.ts.map +1 -0
- package/dist/persistence/neo4j/memory-adapter.js +252 -0
- package/dist/persistence/neo4j/memory-adapter.js.map +1 -0
- package/dist/persistence/neo4j/petri-checkpoint-adapter.d.ts +22 -0
- package/dist/persistence/neo4j/petri-checkpoint-adapter.d.ts.map +1 -0
- package/dist/persistence/neo4j/petri-checkpoint-adapter.js +141 -0
- package/dist/persistence/neo4j/petri-checkpoint-adapter.js.map +1 -0
- package/dist/pipeline/agent-pipeline.d.ts +99 -0
- package/dist/pipeline/agent-pipeline.d.ts.map +1 -0
- package/dist/pipeline/agent-pipeline.js +356 -0
- package/dist/pipeline/agent-pipeline.js.map +1 -0
- package/dist/routing/checkpoint-adapter.d.ts +30 -0
- package/dist/routing/checkpoint-adapter.d.ts.map +1 -0
- package/dist/routing/checkpoint-adapter.js +83 -0
- package/dist/routing/checkpoint-adapter.js.map +1 -0
- package/dist/routing/documentation-generator.d.ts +47 -0
- package/dist/routing/documentation-generator.d.ts.map +1 -0
- package/dist/routing/documentation-generator.js +320 -0
- package/dist/routing/documentation-generator.js.map +1 -0
- package/dist/routing/index.d.ts +38 -0
- package/dist/routing/index.d.ts.map +1 -0
- package/dist/routing/index.js +375 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/routing/intent-classifier.d.ts +206 -0
- package/dist/routing/intent-classifier.d.ts.map +1 -0
- package/dist/routing/intent-classifier.js +267 -0
- package/dist/routing/intent-classifier.js.map +1 -0
- package/dist/routing/matrix.d.ts +6 -0
- package/dist/routing/matrix.d.ts.map +1 -0
- package/dist/routing/matrix.js +131 -0
- package/dist/routing/matrix.js.map +1 -0
- package/dist/routing/orchestrator.d.ts +87 -0
- package/dist/routing/orchestrator.d.ts.map +1 -0
- package/dist/routing/orchestrator.js +425 -0
- package/dist/routing/orchestrator.js.map +1 -0
- package/dist/routing/postgres-checkpoint-adapter.d.ts +32 -0
- package/dist/routing/postgres-checkpoint-adapter.d.ts.map +1 -0
- package/dist/routing/postgres-checkpoint-adapter.js +167 -0
- package/dist/routing/postgres-checkpoint-adapter.js.map +1 -0
- package/dist/routing/redis-checkpoint-adapter.d.ts +34 -0
- package/dist/routing/redis-checkpoint-adapter.d.ts.map +1 -0
- package/dist/routing/redis-checkpoint-adapter.js +170 -0
- package/dist/routing/redis-checkpoint-adapter.js.map +1 -0
- package/dist/routing/types.d.ts +49 -0
- package/dist/routing/types.d.ts.map +1 -0
- package/dist/routing/types.js +3 -0
- package/dist/routing/types.js.map +1 -0
- package/dist/types/agent.d.ts +289 -0
- package/dist/types/agent.d.ts.map +1 -0
- package/dist/types/agent.js +78 -0
- package/dist/types/agent.js.map +1 -0
- package/dist/types/index.d.ts +343 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +3 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/generate-action-schema.d.ts +4 -0
- package/dist/utils/generate-action-schema.d.ts.map +1 -0
- package/dist/utils/generate-action-schema.js +46 -0
- package/dist/utils/generate-action-schema.js.map +1 -0
- package/dist/utils/header-builder.d.ts +12 -0
- package/dist/utils/header-builder.d.ts.map +1 -0
- package/dist/utils/header-builder.js +35 -0
- package/dist/utils/header-builder.js.map +1 -0
- package/dist/utils/logger.d.ts +27 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +45 -0
- package/dist/utils/logger.js.map +1 -0
- package/docs/.gitbook/assets/image (1).png +0 -0
- package/docs/.gitbook/assets/image (2).png +0 -0
- package/docs/.gitbook/assets/image (3).png +0 -0
- package/docs/.gitbook/assets/image (4).png +0 -0
- package/docs/.gitbook/assets/image (5).png +0 -0
- package/docs/.gitbook/assets/image (6).png +0 -0
- package/docs/.gitbook/assets/image.png +0 -0
- package/docs/README.md +57 -0
- package/docs/SUMMARY.md +34 -0
- package/docs/cas-dusages.md +69 -0
- package/docs/cli/README.md +65 -0
- package/docs/concepts-cles.md +50 -0
- package/docs/core/architecture.md +87 -0
- package/docs/core/benchmark.md +59 -0
- package/docs/core/checkpoint.md +72 -0
- package/docs/core/documentation.md +55 -0
- package/docs/core/graphcontroller.md +63 -0
- package/docs/core/graphflow.md +137 -0
- package/docs/core/introduction.md +41 -0
- package/docs/core/les-evenements.md +95 -0
- package/docs/modules/agenda/README.md +63 -0
- package/docs/modules/agenda/interface-iagenda.md +170 -0
- package/docs/modules/agenda/les-adaptateurs/README.md +237 -0
- package/docs/modules/agenda/les-adaptateurs/nodecronadapter.md +91 -0
- package/docs/modules/introduction.md +55 -0
- package/docs/modules/les-adaptateurs.md +52 -0
- package/docs/modules/memoire/README.md +68 -0
- package/docs/modules/memoire/interface-imemory.md +183 -0
- package/docs/modules/memoire/les-adaptateurs/README.md +209 -0
- package/docs/modules/memoire/les-adaptateurs/inmemoryadapter.md +110 -0
- package/docs/modules/memoire/les-adaptateurs/meilisearchadapter.md +147 -0
- package/docs/modules/memoire/les-adaptateurs/redisadapter.md +212 -0
- package/docs/modules/nlp/README.md +44 -0
- package/docs/philosophie.md +51 -0
- package/docs/tutoriels/ajouter-des-conditions.md +150 -0
- package/docs/tutoriels/branching.md +194 -0
- package/docs/tutoriels/checkpoint-usage.md +99 -0
- package/docs/tutoriels/creer-agent-onchain.md +1041 -0
- package/docs/tutoriels/creer-un-agent.md +108 -0
- package/docs/tutoriels/creer-un-graphe-simple.md +92 -0
- package/docs/tutoriels/gerer-les-erreurs.md +124 -0
- package/docs/tutoriels/pour-commencer.md +73 -0
- package/docs/tutoriels/retry.md +166 -0
- package/execution/adapters/in-memory-checkpoint.ts +35 -0
- package/execution/compiler.ts +47 -0
- package/execution/controller.ts +84 -0
- package/execution/event-manager.ts +331 -0
- package/execution/index.ts +800 -0
- package/execution/logger.ts +70 -0
- package/execution/node.ts +315 -0
- package/execution/observer.ts +192 -0
- package/execution/planner.ts +40 -0
- package/execution/reducer.ts +73 -0
- package/execution/registry.ts +86 -0
- package/execution/send-api.ts +58 -0
- package/execution/types.parallel.ts +81 -0
- package/execution/visualizer.ts +158 -0
- package/index.ts +55 -465
- package/interfaces/index.ts +597 -0
- package/modules/agenda/adapters/node-cron/index.ts +25 -0
- package/modules/agenda/index.ts +146 -0
- package/modules/cli/index.ts +580 -0
- package/modules/embedding/adapters/ai/index.ts +42 -0
- package/modules/embedding/index.ts +45 -0
- package/modules/nlp/engine.ts +324 -0
- package/modules/nlp/index.ts +45 -0
- package/package.json +81 -9
- package/persistence/index.ts +27 -0
- package/persistence/neo4j/driver.ts +34 -0
- package/persistence/neo4j/entity-store.ts +141 -0
- package/persistence/neo4j/execution-tracer.ts +194 -0
- package/persistence/neo4j/memory-adapter.ts +281 -0
- package/persistence/neo4j/petri-checkpoint-adapter.ts +153 -0
- package/pipeline/agent-pipeline.ts +426 -0
- package/routing/checkpoint-adapter.ts +79 -0
- package/routing/documentation-generator.ts +358 -0
- package/routing/index.ts +459 -0
- package/routing/intent-classifier.ts +360 -0
- package/routing/matrix.ts +138 -0
- package/routing/orchestrator.ts +498 -0
- package/routing/patterns/data-extraction.json +79 -0
- package/routing/patterns/human-approval.json +64 -0
- package/routing/patterns/rag-search.json +68 -0
- package/routing/postgres-checkpoint-adapter.ts +172 -0
- package/routing/redis-checkpoint-adapter.ts +187 -0
- package/routing/types.ts +59 -0
- package/routing/web-server.ts +260 -0
- package/scripts/generate-petri-docs.ts +70 -0
- package/scripts/get-gmail-token.js +65 -0
- package/scripts/get-gmail-token.ts +65 -0
- package/test/agent/agent.test.ts +92 -0
- package/test/agent/clone.test.ts +143 -0
- package/test/agent/cognitive-handler.test.ts +78 -0
- package/test/agent/entity-store.test.ts +80 -0
- package/test/agent/generic-executor.test.ts +230 -0
- package/test/agent/handoff.test.ts +163 -0
- package/test/agent/llm-factory.test.ts +40 -0
- package/test/agent/orchestrator.test.ts +156 -0
- package/test/agent/registry.test.ts +97 -0
- package/test/agent/tools.test.ts +267 -0
- package/test/execution/checkpoint.test.ts +811 -0
- package/test/execution/controller.test.ts +236 -0
- package/test/execution/event-manager.test.ts +118 -0
- package/test/execution/index.test.ts +690 -0
- package/test/execution/node.test.ts +464 -0
- package/test/execution/observer.test.ts +393 -0
- package/test/execution/parallel.test.ts +135 -0
- package/test/execution/plan-llm-integration.test.ts +290 -0
- package/test/execution/plan-real-onchain.test.ts +226 -0
- package/test/execution/send-api.test.ts +121 -0
- package/test/modules/agenda/node-cron.test.ts +307 -0
- package/test/modules/cli/index.test.ts +125 -0
- package/test/persistence/neo4j-execution-tracer.test.ts +96 -0
- package/test/persistence/neo4j-memory-adapter.test.ts +107 -0
- package/test/persistence/neo4j-petri-checkpoint.test.ts +89 -0
- package/test/pipeline/agent-pipeline.test.ts +118 -0
- package/test/routing/checkpoint-persistence.test.ts +58 -0
- package/test/routing/documentation-generator.test.ts +76 -0
- package/test/routing/integration.test.ts +261 -0
- package/test/routing/intent-classifier.test.ts +102 -0
- package/test/routing/petri.test.ts +156 -0
- package/test/routing/real-llm.test.ts +260 -0
- package/test-petri-features.ts +218 -0
- package/test-pipeline-api.ts +163 -0
- package/tsconfig.json +30 -108
- package/types/agent.ts +296 -0
- package/types/index.ts +387 -0
- package/utils/generate-action-schema.ts +47 -0
- package/utils/header-builder.ts +40 -0
- package/utils/logger.ts +40 -0
- package/package copy.json +0 -21
- package/types.ts +0 -62
- package/utils/executor.ts +0 -42
|
@@ -0,0 +1,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";
|
|
@@ -0,0 +1,193 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EntityReference,
|
|
3
|
+
EntityResolution,
|
|
4
|
+
ResolverContext,
|
|
5
|
+
Entity,
|
|
6
|
+
ScoredCandidate,
|
|
7
|
+
Confidence,
|
|
8
|
+
ResolutionTraceEntry,
|
|
9
|
+
EntityHandle,
|
|
10
|
+
} from "./types";
|
|
11
|
+
import { EntityIndex } from "./entity-index";
|
|
12
|
+
import { scoreEntities } from "./scorer";
|
|
13
|
+
import { computeConfidence } from "./confidence";
|
|
14
|
+
|
|
15
|
+
const TYPE_HINT_WORDS: Record<string, string[]> = {
|
|
16
|
+
file: ["fichier", "file", "read", "lis", "lecture", "ouvre", "contenu", "md", "markdown"],
|
|
17
|
+
dir: ["dossier", "dir", "folder", "list", "lister", "répertoire", "repertoire"],
|
|
18
|
+
command: ["commande", "run", "execute", "exec", "lance"],
|
|
19
|
+
test: ["test", "spec", "tests"],
|
|
20
|
+
workflow: ["workflow", "pipeline"],
|
|
21
|
+
service: ["service", "daemon", "api"],
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function extractCategoryHint(message: string): string | null {
|
|
25
|
+
const lower = message.toLowerCase();
|
|
26
|
+
for (const [cat, words] of Object.entries(TYPE_HINT_WORDS)) {
|
|
27
|
+
if (words.some(w => lower.includes(w))) return cat;
|
|
28
|
+
}
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function extractReferences(message: string): string[] {
|
|
33
|
+
const normalized = message
|
|
34
|
+
.normalize("NFD")
|
|
35
|
+
.replace(/[\u0300-\u036f]/g, "");
|
|
36
|
+
|
|
37
|
+
const candidates = new Set<string>();
|
|
38
|
+
|
|
39
|
+
const clean = normalized.replace(/[?.,!;:()"']/g, " ");
|
|
40
|
+
|
|
41
|
+
const tokens = clean.split(/\s+/).filter(t => t.length > 0);
|
|
42
|
+
|
|
43
|
+
for (const token of tokens) {
|
|
44
|
+
const lower = token.toLowerCase();
|
|
45
|
+
if (["le", "la", "les", "un", "une", "des", "du", "de", "et", "ou",
|
|
46
|
+
"est", "sont", "dans", "pour", "sur", "avec", "sans", "pas",
|
|
47
|
+
"tu", "je", "il", "elle", "on", "nous", "vous", "ils", "elles",
|
|
48
|
+
"me", "te", "se", "lui", "leur", "moi", "toi", "qui", "que",
|
|
49
|
+
"quoi", "dont", "ou", "ce", "cet", "cette", "ces", "mon", "ton",
|
|
50
|
+
"son", "ma", "ta", "sa", "mes", "tes", "ses", "nos", "vos",
|
|
51
|
+
"leurs", "lui", "leur", "eux", "ca", "ça", "cela", "ceci",
|
|
52
|
+
"elle", "lui", "moi", "nous", "vous", "eux", "elles",
|
|
53
|
+
"fichier", "dossier", "contenu", "lister", "repertoire",
|
|
54
|
+
"stp", "svp", "merci", "bonjour", "salut", "bonsoir",
|
|
55
|
+
"peux", "peut", "veux", "veut", "vas", "va", "vais",
|
|
56
|
+
"faire", "fais", "fait", "donne", "donner",
|
|
57
|
+
"vois", "voir", "regarde", "regarder",
|
|
58
|
+
"dis", "dire", "dites", "lis", "lit", "lire",
|
|
59
|
+
"ouvre", "ouvrir", "ouvres",
|
|
60
|
+
"montre", "montrer", "trouve", "trouver",
|
|
61
|
+
"cherche", "chercher", "affiche", "afficher",
|
|
62
|
+
"ajoute", "ajouter", "modifie", "modifier",
|
|
63
|
+
"supprime", "supprimer", "efface", "effacer",
|
|
64
|
+
].includes(lower)) continue;
|
|
65
|
+
|
|
66
|
+
if (/[\d]{4,}/.test(token)) continue;
|
|
67
|
+
|
|
68
|
+
const parts = token.split(/[-._]/).filter(p => p.length > 0 && p.length < 40);
|
|
69
|
+
for (const part of parts) {
|
|
70
|
+
if (part.length >= 2 && !/^\d+$/.test(part)) {
|
|
71
|
+
candidates.add(part);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return Array.from(candidates);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export type ResolveResult = {
|
|
80
|
+
resolution: EntityResolution;
|
|
81
|
+
trace: ResolutionTraceEntry[];
|
|
82
|
+
confidence: Confidence;
|
|
83
|
+
shouldExplore: boolean;
|
|
84
|
+
handles: Record<string, EntityHandle>;
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
export class EntityResolver {
|
|
88
|
+
constructor(
|
|
89
|
+
private index: EntityIndex,
|
|
90
|
+
private threshold: number = 0.25
|
|
91
|
+
) {}
|
|
92
|
+
|
|
93
|
+
resolve(ctx: ResolverContext): ResolveResult {
|
|
94
|
+
const trace: ResolutionTraceEntry[] = [];
|
|
95
|
+
const refs = extractReferences(ctx.userMessage);
|
|
96
|
+
const references: EntityReference[] = [];
|
|
97
|
+
|
|
98
|
+
for (const ref of refs) {
|
|
99
|
+
const entities = this.index.lookup(ref);
|
|
100
|
+
const candidates = scoreEntities(ref, entities, ctx);
|
|
101
|
+
const confidence = computeConfidence(candidates);
|
|
102
|
+
|
|
103
|
+
let resolved: Entity | null = null;
|
|
104
|
+
if (confidence.level === "high") {
|
|
105
|
+
resolved = candidates[0]?.entity || null;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const refEntry: EntityReference = {
|
|
109
|
+
raw: ref,
|
|
110
|
+
resolved,
|
|
111
|
+
candidates,
|
|
112
|
+
confidence,
|
|
113
|
+
};
|
|
114
|
+
references.push(refEntry);
|
|
115
|
+
|
|
116
|
+
trace.push({
|
|
117
|
+
query: ref,
|
|
118
|
+
candidates,
|
|
119
|
+
confidence: confidence.score,
|
|
120
|
+
action: resolved ? "auto_resolved" : candidates.length > 0 ? "injected" : "failed",
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const resolved = references.filter(r => r.resolved !== null);
|
|
125
|
+
const ambiguous = references.filter(r => r.resolved === null && r.candidates.length > 0);
|
|
126
|
+
|
|
127
|
+
const resolution: EntityResolution = {
|
|
128
|
+
references,
|
|
129
|
+
resolved,
|
|
130
|
+
ambiguous,
|
|
131
|
+
modifiedInput: ctx.userMessage,
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
const handles: Record<string, EntityHandle> = {};
|
|
135
|
+
let handleIdx = 0;
|
|
136
|
+
for (const ref of references) {
|
|
137
|
+
for (const c of ref.candidates) {
|
|
138
|
+
const eid = `ent_${handleIdx++}`;
|
|
139
|
+
handles[eid] = {
|
|
140
|
+
id: eid,
|
|
141
|
+
label: c.entity.filename,
|
|
142
|
+
path: c.entity.path,
|
|
143
|
+
category: c.entity.category,
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
const overallConfidence = this.overallConfidence(references);
|
|
149
|
+
|
|
150
|
+
return {
|
|
151
|
+
resolution,
|
|
152
|
+
trace,
|
|
153
|
+
confidence: overallConfidence,
|
|
154
|
+
shouldExplore: overallConfidence.level === "low" && ambiguous.length > 0,
|
|
155
|
+
handles,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
private overallConfidence(references: EntityReference[]): Confidence {
|
|
160
|
+
const withCandidates = references.filter(r => r.candidates.length > 0);
|
|
161
|
+
|
|
162
|
+
if (withCandidates.length === 0) {
|
|
163
|
+
return { level: "high", score: 1, gap: 1, reason: "no entity references found" };
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
let totalScore = 0;
|
|
167
|
+
let minGap = 1;
|
|
168
|
+
let allHigh = true;
|
|
169
|
+
let anyLow = false;
|
|
170
|
+
|
|
171
|
+
for (const ref of withCandidates) {
|
|
172
|
+
totalScore += ref.confidence.score;
|
|
173
|
+
minGap = Math.min(minGap, ref.confidence.gap);
|
|
174
|
+
if (ref.confidence.level !== "high") allHigh = false;
|
|
175
|
+
if (ref.confidence.level === "low") anyLow = true;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const avgScore = totalScore / withCandidates.length;
|
|
179
|
+
|
|
180
|
+
if (allHigh) {
|
|
181
|
+
return { level: "high", score: avgScore, gap: minGap, reason: "all references resolved with high confidence" };
|
|
182
|
+
}
|
|
183
|
+
if (anyLow) {
|
|
184
|
+
return { level: "low", score: avgScore, gap: minGap, reason: "some references have low confidence" };
|
|
185
|
+
}
|
|
186
|
+
return { level: "medium", score: avgScore, gap: minGap, reason: "mixed confidence across references" };
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
export function findEntityInInput(message: string): string | null {
|
|
191
|
+
const refs = extractReferences(message);
|
|
192
|
+
return refs.length > 0 ? refs[0] : null;
|
|
193
|
+
}
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import { Entity, ScoreBreakdown, ScoredCandidate, ResolverContext } from "./types";
|
|
2
|
+
|
|
3
|
+
const WEIGHTS = {
|
|
4
|
+
lexical: 0.25,
|
|
5
|
+
exact: 0.20,
|
|
6
|
+
stem: 0.15,
|
|
7
|
+
typeHint: 0.15,
|
|
8
|
+
context: 0.15,
|
|
9
|
+
recency: 0.10,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
function scoreLexical(query: string, entity: Entity): { score: number; reasons: string[] } {
|
|
13
|
+
const reasons: string[] = [];
|
|
14
|
+
const qLower = query.toLowerCase();
|
|
15
|
+
const tokens = qLower.split(/[-._\s]+/).filter(Boolean);
|
|
16
|
+
const entityTokens = entity.tokens;
|
|
17
|
+
|
|
18
|
+
if (tokens.length === 0) return { score: 0, reasons: [] };
|
|
19
|
+
|
|
20
|
+
let matchCount = 0;
|
|
21
|
+
for (const qt of tokens) {
|
|
22
|
+
if (entityTokens.some(et => et === qt || et.startsWith(qt) || qt.startsWith(et))) {
|
|
23
|
+
matchCount++;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
let overlap = matchCount / Math.max(tokens.length, entityTokens.length);
|
|
28
|
+
overlap = Math.min(1, overlap);
|
|
29
|
+
|
|
30
|
+
if (overlap > 0) reasons.push(`token overlap ${(overlap * 100).toFixed(0)}%`);
|
|
31
|
+
return { score: overlap, reasons };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function scoreExact(query: string, entity: Entity): { score: number; reasons: string[] } {
|
|
35
|
+
const qLower = query.toLowerCase();
|
|
36
|
+
const reasons: string[] = [];
|
|
37
|
+
|
|
38
|
+
if (entity.filename.toLowerCase() === qLower) {
|
|
39
|
+
reasons.push(`filename exact match: ${entity.filename}`);
|
|
40
|
+
return { score: 1, reasons };
|
|
41
|
+
}
|
|
42
|
+
if (entity.stem.toLowerCase() === qLower) {
|
|
43
|
+
reasons.push(`stem exact match: ${entity.stem}`);
|
|
44
|
+
return { score: 0.9, reasons };
|
|
45
|
+
}
|
|
46
|
+
if (entity.filename.toLowerCase().includes(qLower)) {
|
|
47
|
+
reasons.push(`filename contains query`);
|
|
48
|
+
return { score: 0.6, reasons };
|
|
49
|
+
}
|
|
50
|
+
return { score: 0, reasons };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
function scoreStem(query: string, entity: Entity): { score: number; reasons: string[] } {
|
|
54
|
+
const qLower = query.toLowerCase();
|
|
55
|
+
const reasons: string[] = [];
|
|
56
|
+
|
|
57
|
+
if (entity.stem.toLowerCase() === qLower) {
|
|
58
|
+
reasons.push(`stem match: ${entity.stem}`);
|
|
59
|
+
return { score: 1, reasons };
|
|
60
|
+
}
|
|
61
|
+
if (entity.stem.toLowerCase().includes(qLower) || qLower.includes(entity.stem.toLowerCase())) {
|
|
62
|
+
reasons.push(`stem partial match`);
|
|
63
|
+
return { score: 0.7, reasons };
|
|
64
|
+
}
|
|
65
|
+
return { score: 0, reasons };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function scoreTypeHint(query: string, entity: Entity): { score: number; reasons: string[] } {
|
|
69
|
+
const reasons: string[] = [];
|
|
70
|
+
const qLower = query.toLowerCase();
|
|
71
|
+
let score = 0;
|
|
72
|
+
|
|
73
|
+
const fileHints = /\b(fichier|file|read|lis|lecture|ouvre|contenu)\b/i;
|
|
74
|
+
const dirHints = /\b(dossier|dir|folder|list|lister|répertoire)\b/i;
|
|
75
|
+
|
|
76
|
+
const isFileHint = fileHints.test(qLower);
|
|
77
|
+
const isDirHint = dirHints.test(qLower);
|
|
78
|
+
|
|
79
|
+
if (isFileHint && entity.category === "file") {
|
|
80
|
+
score = 1;
|
|
81
|
+
reasons.push("user said 'fichier'/'file' → entity is file");
|
|
82
|
+
} else if (isDirHint && entity.category === "dir") {
|
|
83
|
+
score = 1;
|
|
84
|
+
reasons.push("user said 'dossier'/'dir' → entity is dir");
|
|
85
|
+
} else if (isFileHint && entity.category !== "file") {
|
|
86
|
+
score = 0.1;
|
|
87
|
+
} else if (isDirHint && entity.category !== "dir") {
|
|
88
|
+
score = 0.1;
|
|
89
|
+
} else {
|
|
90
|
+
score = 0.5;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return { score, reasons };
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function scoreContext(query: string, entity: Entity, ctx: ResolverContext): { score: number; reasons: string[] } {
|
|
97
|
+
const reasons: string[] = [];
|
|
98
|
+
const qLower = query.toLowerCase();
|
|
99
|
+
const lastTarget = ctx.conversationState.lastResolvedEntity;
|
|
100
|
+
const lastType = ctx.conversationState.lastResolvedType;
|
|
101
|
+
const pending = ctx.conversationState.pendingIntent;
|
|
102
|
+
|
|
103
|
+
let score = 0;
|
|
104
|
+
|
|
105
|
+
if (lastTarget) {
|
|
106
|
+
const lastFile = lastTarget.split("/").pop() || "";
|
|
107
|
+
const lastStem = lastFile.includes(".") ? lastFile.slice(0, lastFile.lastIndexOf(".")) : lastFile;
|
|
108
|
+
|
|
109
|
+
if (lastStem.toLowerCase() === qLower) {
|
|
110
|
+
score = 1;
|
|
111
|
+
reasons.push(`continues from last entity: ${lastTarget}`);
|
|
112
|
+
return { score, reasons };
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const lastTokens = lastStem.split(/[-._\s]+/).filter(Boolean).map(t => t.toLowerCase());
|
|
116
|
+
const queryTokens = qLower.split(/[-._\s]+/).filter(Boolean);
|
|
117
|
+
|
|
118
|
+
if (lastTokens.some(lt => queryTokens.includes(lt)) || queryTokens.some(qt => lastTokens.includes(qt))) {
|
|
119
|
+
score = 0.6;
|
|
120
|
+
reasons.push(`token overlap with last entity: ${lastTarget}`);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (lastType && entity.category === lastType) {
|
|
124
|
+
score = Math.max(score, 0.4);
|
|
125
|
+
reasons.push(`same type as last entity: ${lastType}`);
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
const lastDir = lastTarget.includes("/") ? lastTarget.split("/").slice(0, -1).join("/") : "";
|
|
129
|
+
if (lastDir && entity.id.startsWith(lastDir + "/")) {
|
|
130
|
+
score = Math.max(score, 0.5);
|
|
131
|
+
reasons.push(`same directory as last entity`);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
if (pending && pending.unresolvedEntity) {
|
|
136
|
+
const pendingLower = pending.unresolvedEntity.toLowerCase();
|
|
137
|
+
if (entity.stem.toLowerCase() === pendingLower || entity.filename.toLowerCase().includes(pendingLower)) {
|
|
138
|
+
score = Math.max(score, 0.7);
|
|
139
|
+
reasons.push(`matches pending unresolved entity: ${pending.unresolvedEntity}`);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (score === 0) {
|
|
144
|
+
reasons.push("no contextual match");
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return { score: Math.min(1, score), reasons };
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function scoreRecency(query: string, entity: Entity, ctx: ResolverContext): { score: number; reasons: string[] } {
|
|
151
|
+
const reasons: string[] = [];
|
|
152
|
+
const msgs = ctx.conversationHistory.slice(-6);
|
|
153
|
+
|
|
154
|
+
for (const msg of msgs) {
|
|
155
|
+
const content = msg.content.toLowerCase();
|
|
156
|
+
if (content.includes(entity.filename.toLowerCase()) || content.includes(entity.stem.toLowerCase())) {
|
|
157
|
+
reasons.push(`mentioned in recent conversation: ${entity.filename}`);
|
|
158
|
+
return { score: 1, reasons };
|
|
159
|
+
}
|
|
160
|
+
for (const token of entity.tokens) {
|
|
161
|
+
if (content.includes(token)) {
|
|
162
|
+
reasons.push(`token "${token}" in recent conversation`);
|
|
163
|
+
return { score: 0.8, reasons };
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return { score: 0, reasons: ["not recently mentioned"] };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
export function scoreEntities(
|
|
172
|
+
query: string,
|
|
173
|
+
entities: Entity[],
|
|
174
|
+
ctx: ResolverContext
|
|
175
|
+
): ScoredCandidate[] {
|
|
176
|
+
return entities.map(entity => {
|
|
177
|
+
const lex = scoreLexical(query, entity);
|
|
178
|
+
const exact = scoreExact(query, entity);
|
|
179
|
+
const stem = scoreStem(query, entity);
|
|
180
|
+
const type = scoreTypeHint(query, entity);
|
|
181
|
+
const context = scoreContext(query, entity, ctx);
|
|
182
|
+
const recency = scoreRecency(query, entity, ctx);
|
|
183
|
+
|
|
184
|
+
const breakdown: ScoreBreakdown = {
|
|
185
|
+
lexical: lex.score,
|
|
186
|
+
typeHint: type.score,
|
|
187
|
+
context: context.score,
|
|
188
|
+
recency: recency.score,
|
|
189
|
+
total: 0,
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
breakdown.total =
|
|
193
|
+
WEIGHTS.lexical * lex.score +
|
|
194
|
+
WEIGHTS.exact * exact.score +
|
|
195
|
+
WEIGHTS.stem * stem.score +
|
|
196
|
+
WEIGHTS.typeHint * type.score +
|
|
197
|
+
WEIGHTS.context * context.score +
|
|
198
|
+
WEIGHTS.recency * recency.score;
|
|
199
|
+
|
|
200
|
+
const reasons = [
|
|
201
|
+
...lex.reasons,
|
|
202
|
+
...exact.reasons,
|
|
203
|
+
...stem.reasons,
|
|
204
|
+
...type.reasons,
|
|
205
|
+
...context.reasons,
|
|
206
|
+
...recency.reasons,
|
|
207
|
+
];
|
|
208
|
+
|
|
209
|
+
return { entity, breakdown, reasons };
|
|
210
|
+
}).sort((a, b) => b.breakdown.total - a.breakdown.total);
|
|
211
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export type EntityCategory = "file" | "dir" | "command" | "workflow" | "test" | "service";
|
|
2
|
+
|
|
3
|
+
export type Entity = {
|
|
4
|
+
id: string;
|
|
5
|
+
category: EntityCategory;
|
|
6
|
+
filename: string;
|
|
7
|
+
stem: string;
|
|
8
|
+
extension: string | null;
|
|
9
|
+
tokens: string[];
|
|
10
|
+
path: string;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export type ScoredCandidate = {
|
|
14
|
+
entity: Entity;
|
|
15
|
+
breakdown: ScoreBreakdown;
|
|
16
|
+
reasons: string[];
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export type ScoreBreakdown = {
|
|
20
|
+
lexical: number;
|
|
21
|
+
typeHint: number;
|
|
22
|
+
context: number;
|
|
23
|
+
recency: number;
|
|
24
|
+
total: number;
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
export type ConfidenceLevel = "high" | "medium" | "low";
|
|
28
|
+
|
|
29
|
+
export type Confidence = {
|
|
30
|
+
level: ConfidenceLevel;
|
|
31
|
+
score: number;
|
|
32
|
+
gap: number;
|
|
33
|
+
reason: string;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type EntityReference = {
|
|
37
|
+
raw: string;
|
|
38
|
+
resolved: Entity | null;
|
|
39
|
+
candidates: ScoredCandidate[];
|
|
40
|
+
confidence: Confidence;
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export type EntityResolution = {
|
|
44
|
+
references: EntityReference[];
|
|
45
|
+
resolved: EntityReference[];
|
|
46
|
+
ambiguous: EntityReference[];
|
|
47
|
+
modifiedInput: string;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type ExplorationBudget = {
|
|
51
|
+
maxSteps: number;
|
|
52
|
+
maxExplorations: number;
|
|
53
|
+
maxToolCalls: number;
|
|
54
|
+
stepsUsed: number;
|
|
55
|
+
explorationsUsed: number;
|
|
56
|
+
toolCallsUsed: number;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
export type PendingIntent = {
|
|
60
|
+
action: string | null;
|
|
61
|
+
unresolvedEntity: string | null;
|
|
62
|
+
originalInput: string;
|
|
63
|
+
turn: number;
|
|
64
|
+
failed: boolean;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
export type ConversationState = {
|
|
68
|
+
currentGoal: string;
|
|
69
|
+
currentTarget: string | null;
|
|
70
|
+
lastResolvedEntity: string | null;
|
|
71
|
+
lastResolvedType: EntityCategory | null;
|
|
72
|
+
pendingTask: string | null;
|
|
73
|
+
turnCount: number;
|
|
74
|
+
pendingIntent: PendingIntent | null;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
export type EntityHandle = {
|
|
78
|
+
id: string;
|
|
79
|
+
label: string;
|
|
80
|
+
path: string;
|
|
81
|
+
category: EntityCategory;
|
|
82
|
+
};
|
|
83
|
+
|
|
84
|
+
export type ResolutionTraceEntry = {
|
|
85
|
+
query: string;
|
|
86
|
+
candidates: ScoredCandidate[];
|
|
87
|
+
confidence: number;
|
|
88
|
+
action: "auto_resolved" | "injected" | "explored" | "failed";
|
|
89
|
+
exploration?: string;
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
export type ResolverContext = {
|
|
93
|
+
userMessage: string;
|
|
94
|
+
conversationHistory: { role: string; content: string }[];
|
|
95
|
+
conversationState: ConversationState;
|
|
96
|
+
cwd: string;
|
|
97
|
+
entityIndex: any;
|
|
98
|
+
};
|