@dexto/core 1.3.0 → 1.4.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/README.md +17 -9
- package/dist/agent/DextoAgent.cjs +548 -207
- package/dist/agent/DextoAgent.d.ts +156 -33
- package/dist/agent/DextoAgent.d.ts.map +1 -1
- package/dist/agent/DextoAgent.js +545 -204
- package/dist/agent/agentCard.js +1 -1
- package/dist/agent/error-codes.cjs +1 -0
- package/dist/agent/error-codes.d.ts +2 -1
- package/dist/agent/error-codes.d.ts.map +1 -1
- package/dist/agent/error-codes.js +2 -1
- package/dist/agent/errors.cjs +13 -0
- package/dist/agent/errors.d.ts +4 -0
- package/dist/agent/errors.d.ts.map +1 -1
- package/dist/agent/errors.js +14 -1
- package/dist/agent/index.d.ts +1 -1
- package/dist/agent/index.d.ts.map +1 -1
- package/dist/agent/index.js +1 -1
- package/dist/agent/schemas.cjs +3 -0
- package/dist/agent/schemas.d.ts +92 -55
- package/dist/agent/schemas.d.ts.map +1 -1
- package/dist/agent/schemas.js +6 -2
- package/dist/agent/state-manager.cjs +5 -5
- package/dist/agent/state-manager.d.ts +4 -4
- package/dist/agent/state-manager.js +6 -6
- package/dist/agent/types.d.ts +24 -10
- package/dist/agent/types.d.ts.map +1 -1
- package/dist/approval/error-codes.js +1 -1
- package/dist/approval/errors.js +1 -1
- package/dist/approval/factory.js +1 -1
- package/dist/approval/index.js +1 -1
- package/dist/approval/manager.cjs +69 -3
- package/dist/approval/manager.d.ts +41 -3
- package/dist/approval/manager.d.ts.map +1 -1
- package/dist/approval/manager.js +70 -4
- package/dist/approval/schemas.cjs +18 -4
- package/dist/approval/schemas.d.ts +106 -32
- package/dist/approval/schemas.d.ts.map +1 -1
- package/dist/approval/schemas.js +19 -5
- package/dist/approval/types.d.ts +6 -0
- package/dist/approval/types.d.ts.map +1 -1
- package/dist/approval/types.js +1 -1
- package/dist/{chunk-C6A6W6XS.js → chunk-PTJYTZNU.js} +44 -1
- package/dist/{llm/tokenizer/default.cjs → context/compression/overflow.cjs} +20 -18
- package/dist/context/compression/overflow.d.ts +33 -0
- package/dist/context/compression/overflow.d.ts.map +1 -0
- package/dist/context/compression/overflow.js +19 -0
- package/dist/context/compression/reactive-overflow.cjs +201 -0
- package/dist/context/compression/reactive-overflow.d.ts +81 -0
- package/dist/context/compression/reactive-overflow.d.ts.map +1 -0
- package/dist/context/compression/reactive-overflow.js +178 -0
- package/dist/context/compression/types.d.ts +9 -7
- package/dist/context/compression/types.d.ts.map +1 -1
- package/dist/context/error-codes.cjs +3 -0
- package/dist/context/error-codes.d.ts +4 -1
- package/dist/context/error-codes.d.ts.map +1 -1
- package/dist/context/error-codes.js +4 -1
- package/dist/context/errors.cjs +28 -0
- package/dist/context/errors.d.ts +7 -0
- package/dist/context/errors.d.ts.map +1 -1
- package/dist/context/errors.js +29 -1
- package/dist/context/index.js +1 -1
- package/dist/context/manager.cjs +280 -323
- package/dist/context/manager.d.ts +65 -111
- package/dist/context/manager.d.ts.map +1 -1
- package/dist/context/manager.js +280 -328
- package/dist/context/media-helpers.js +1 -1
- package/dist/context/types.cjs +49 -0
- package/dist/context/types.d.ts +181 -72
- package/dist/context/types.d.ts.map +1 -1
- package/dist/context/types.js +35 -0
- package/dist/context/utils.cjs +266 -283
- package/dist/context/utils.d.ts +32 -18
- package/dist/context/utils.d.ts.map +1 -1
- package/dist/context/utils.js +266 -283
- package/dist/errors/DextoBaseError.js +1 -1
- package/dist/errors/DextoRuntimeError.js +1 -1
- package/dist/errors/DextoValidationError.js +1 -1
- package/dist/errors/index.js +1 -1
- package/dist/errors/result-bridge.js +1 -1
- package/dist/errors/types.js +1 -1
- package/dist/events/index.cjs +18 -1
- package/dist/events/index.d.ts +149 -12
- package/dist/events/index.d.ts.map +1 -1
- package/dist/events/index.js +19 -2
- package/dist/filesystem/error-codes.js +1 -1
- package/dist/filesystem/errors.js +1 -1
- package/dist/filesystem/filesystem-service.js +1 -1
- package/dist/filesystem/index.js +1 -1
- package/dist/filesystem/path-validator.js +1 -1
- package/dist/index.browser.cjs +23 -8
- package/dist/index.browser.d.ts +4 -3
- package/dist/index.browser.d.ts.map +1 -1
- package/dist/index.browser.js +20 -3
- package/dist/index.js +1 -1
- package/dist/llm/error-codes.cjs +0 -1
- package/dist/llm/error-codes.d.ts +0 -1
- package/dist/llm/error-codes.d.ts.map +1 -1
- package/dist/llm/error-codes.js +1 -2
- package/dist/llm/errors.cjs +10 -10
- package/dist/llm/errors.d.ts +5 -6
- package/dist/llm/errors.d.ts.map +1 -1
- package/dist/llm/errors.js +12 -12
- package/dist/llm/executor/stream-processor.cjs +367 -0
- package/dist/llm/executor/stream-processor.d.ts +55 -0
- package/dist/llm/executor/stream-processor.d.ts.map +1 -0
- package/dist/llm/executor/stream-processor.js +344 -0
- package/dist/llm/executor/tool-output-truncator.cjs +75 -0
- package/dist/llm/executor/tool-output-truncator.d.ts +27 -0
- package/dist/llm/executor/tool-output-truncator.d.ts.map +1 -0
- package/dist/llm/executor/tool-output-truncator.js +48 -0
- package/dist/llm/executor/turn-executor.cjs +753 -0
- package/dist/llm/executor/turn-executor.d.ts +166 -0
- package/dist/llm/executor/turn-executor.d.ts.map +1 -0
- package/dist/llm/executor/turn-executor.js +684 -0
- package/dist/llm/executor/types.d.ts +27 -0
- package/dist/llm/executor/types.d.ts.map +1 -0
- package/dist/llm/formatters/vercel.cjs +20 -186
- package/dist/llm/formatters/vercel.d.ts +2 -14
- package/dist/llm/formatters/vercel.d.ts.map +1 -1
- package/dist/llm/formatters/vercel.js +19 -185
- package/dist/llm/registry.cjs +36 -45
- package/dist/llm/registry.d.ts +53 -39
- package/dist/llm/registry.d.ts.map +1 -1
- package/dist/llm/registry.js +34 -42
- package/dist/llm/resolver.cjs +1 -31
- package/dist/llm/resolver.d.ts.map +1 -1
- package/dist/llm/resolver.js +2 -34
- package/dist/llm/schemas.cjs +2 -17
- package/dist/llm/schemas.d.ts +10 -23
- package/dist/llm/schemas.d.ts.map +1 -1
- package/dist/llm/schemas.js +5 -22
- package/dist/llm/services/factory.cjs +3 -92
- package/dist/llm/services/factory.d.ts +14 -4
- package/dist/llm/services/factory.d.ts.map +1 -1
- package/dist/llm/services/factory.js +4 -83
- package/dist/llm/services/test-utils.integration.cjs +6 -8
- package/dist/llm/services/test-utils.integration.d.ts.map +1 -1
- package/dist/llm/services/test-utils.integration.js +7 -9
- package/dist/llm/services/types.d.ts +1 -28
- package/dist/llm/services/types.d.ts.map +1 -1
- package/dist/llm/services/vercel.cjs +54 -468
- package/dist/llm/services/vercel.d.ts +38 -21
- package/dist/llm/services/vercel.d.ts.map +1 -1
- package/dist/llm/services/vercel.js +56 -475
- package/dist/llm/types.cjs +0 -3
- package/dist/llm/types.d.ts +8 -8
- package/dist/llm/types.d.ts.map +1 -1
- package/dist/llm/types.js +1 -3
- package/dist/llm/validation.js +1 -1
- package/dist/logger/browser.js +1 -1
- package/dist/logger/factory.js +1 -1
- package/dist/logger/index.js +1 -1
- package/dist/logger/logger.js +1 -1
- package/dist/logger/v2/dexto-logger.cjs +34 -6
- package/dist/logger/v2/dexto-logger.d.ts +20 -2
- package/dist/logger/v2/dexto-logger.d.ts.map +1 -1
- package/dist/logger/v2/dexto-logger.js +35 -7
- package/dist/logger/v2/error-codes.js +1 -1
- package/dist/logger/v2/errors.js +1 -1
- package/dist/logger/v2/schemas.js +1 -1
- package/dist/logger/v2/test-utils.cjs +70 -0
- package/dist/logger/v2/test-utils.d.ts +17 -0
- package/dist/logger/v2/test-utils.d.ts.map +1 -0
- package/dist/logger/v2/test-utils.js +46 -0
- package/dist/logger/v2/transport-factory.js +1 -1
- package/dist/logger/v2/transports/console-transport.js +1 -1
- package/dist/logger/v2/transports/file-transport.cjs +6 -0
- package/dist/logger/v2/transports/file-transport.d.ts +4 -0
- package/dist/logger/v2/transports/file-transport.d.ts.map +1 -1
- package/dist/logger/v2/transports/file-transport.js +7 -1
- package/dist/logger/v2/types.cjs +1 -0
- package/dist/logger/v2/types.d.ts +18 -2
- package/dist/logger/v2/types.d.ts.map +1 -1
- package/dist/logger/v2/types.js +2 -1
- package/dist/mcp/error-codes.cjs +1 -0
- package/dist/mcp/error-codes.d.ts +1 -0
- package/dist/mcp/error-codes.d.ts.map +1 -1
- package/dist/mcp/error-codes.js +2 -1
- package/dist/mcp/errors.cjs +13 -0
- package/dist/mcp/errors.d.ts +7 -0
- package/dist/mcp/errors.d.ts.map +1 -1
- package/dist/mcp/errors.js +14 -1
- package/dist/mcp/manager.cjs +4 -0
- package/dist/mcp/manager.d.ts.map +1 -1
- package/dist/mcp/manager.js +5 -1
- package/dist/mcp/mcp-client.js +1 -1
- package/dist/mcp/resolver.js +1 -1
- package/dist/mcp/schemas.cjs +6 -0
- package/dist/mcp/schemas.d.ts +52 -0
- package/dist/mcp/schemas.d.ts.map +1 -1
- package/dist/mcp/schemas.js +6 -1
- package/dist/memory/error-codes.js +1 -1
- package/dist/memory/errors.js +1 -1
- package/dist/memory/index.js +1 -1
- package/dist/memory/manager.js +1 -1
- package/dist/memory/schemas.d.ts +2 -2
- package/dist/memory/schemas.js +1 -1
- package/dist/plugins/builtins/content-policy.js +1 -1
- package/dist/plugins/builtins/response-sanitizer.js +1 -1
- package/dist/plugins/error-codes.js +1 -1
- package/dist/plugins/index.js +1 -1
- package/dist/plugins/loader.js +1 -1
- package/dist/plugins/manager.js +1 -1
- package/dist/plugins/registrations/builtins.js +1 -1
- package/dist/plugins/schemas.d.ts +3 -3
- package/dist/plugins/schemas.js +1 -1
- package/dist/plugins/types.d.ts +0 -1
- package/dist/plugins/types.d.ts.map +1 -1
- package/dist/process/command-validator.js +1 -1
- package/dist/process/error-codes.js +1 -1
- package/dist/process/errors.js +1 -1
- package/dist/process/index.js +1 -1
- package/dist/process/process-service.cjs +78 -26
- package/dist/process/process-service.d.ts +6 -1
- package/dist/process/process-service.d.ts.map +1 -1
- package/dist/process/process-service.js +79 -27
- package/dist/process/types.d.ts +2 -2
- package/dist/process/types.d.ts.map +1 -1
- package/dist/prompts/error-codes.cjs +1 -0
- package/dist/prompts/error-codes.d.ts +2 -1
- package/dist/prompts/error-codes.d.ts.map +1 -1
- package/dist/prompts/error-codes.js +2 -1
- package/dist/prompts/errors.cjs +15 -0
- package/dist/prompts/errors.d.ts +4 -0
- package/dist/prompts/errors.d.ts.map +1 -1
- package/dist/prompts/errors.js +16 -1
- package/dist/prompts/index.js +1 -1
- package/dist/prompts/name-validation.js +1 -1
- package/dist/prompts/prompt-manager.cjs +13 -2
- package/dist/prompts/prompt-manager.d.ts +7 -0
- package/dist/prompts/prompt-manager.d.ts.map +1 -1
- package/dist/prompts/prompt-manager.js +14 -3
- package/dist/prompts/providers/config-prompt-provider.cjs +12 -3
- package/dist/prompts/providers/config-prompt-provider.d.ts +2 -1
- package/dist/prompts/providers/config-prompt-provider.d.ts.map +1 -1
- package/dist/prompts/providers/config-prompt-provider.js +13 -4
- package/dist/prompts/providers/custom-prompt-provider.js +1 -1
- package/dist/prompts/providers/mcp-prompt-provider.js +1 -1
- package/dist/prompts/schemas.d.ts +12 -0
- package/dist/prompts/schemas.d.ts.map +1 -1
- package/dist/prompts/schemas.js +1 -1
- package/dist/prompts/types.d.ts +2 -0
- package/dist/prompts/types.d.ts.map +1 -1
- package/dist/prompts/utils.js +1 -1
- package/dist/resources/error-codes.js +1 -1
- package/dist/resources/errors.js +1 -1
- package/dist/resources/handlers/blob-handler.js +1 -1
- package/dist/resources/handlers/factory.js +1 -1
- package/dist/resources/handlers/filesystem-handler.js +1 -1
- package/dist/resources/index.js +1 -1
- package/dist/resources/internal-provider.js +1 -1
- package/dist/resources/manager.js +1 -1
- package/dist/resources/reference-parser.js +1 -1
- package/dist/resources/schemas.js +1 -1
- package/dist/search/index.js +1 -1
- package/dist/search/search-service.js +1 -1
- package/dist/session/chat-session.cjs +149 -51
- package/dist/session/chat-session.d.ts +69 -29
- package/dist/session/chat-session.d.ts.map +1 -1
- package/dist/session/chat-session.js +150 -52
- package/dist/session/error-codes.js +1 -1
- package/dist/session/errors.js +1 -1
- package/dist/session/history/database.cjs +134 -21
- package/dist/session/history/database.d.ts +37 -8
- package/dist/session/history/database.d.ts.map +1 -1
- package/dist/session/history/database.js +135 -22
- package/dist/session/history/factory.js +1 -1
- package/dist/session/history/memory.cjs +18 -0
- package/dist/session/history/memory.d.ts +8 -0
- package/dist/session/history/memory.d.ts.map +1 -1
- package/dist/session/history/memory.js +19 -1
- package/dist/session/history/types.d.ts +13 -1
- package/dist/session/history/types.d.ts.map +1 -1
- package/dist/session/index.cjs +3 -0
- package/dist/session/index.d.ts +3 -0
- package/dist/session/index.d.ts.map +1 -1
- package/dist/session/index.js +3 -1
- package/dist/session/message-queue.cjs +201 -0
- package/dist/session/message-queue.d.ts +114 -0
- package/dist/session/message-queue.d.ts.map +1 -0
- package/dist/session/message-queue.js +178 -0
- package/dist/session/schemas.js +1 -1
- package/dist/session/session-manager.cjs +57 -7
- package/dist/session/session-manager.d.ts +18 -0
- package/dist/session/session-manager.d.ts.map +1 -1
- package/dist/session/session-manager.js +58 -8
- package/dist/session/title-generator.cjs +4 -8
- package/dist/session/title-generator.d.ts +1 -2
- package/dist/session/title-generator.d.ts.map +1 -1
- package/dist/session/title-generator.js +5 -9
- package/dist/session/types.cjs +16 -0
- package/dist/session/types.d.ts +14 -0
- package/dist/session/types.d.ts.map +1 -0
- package/dist/session/types.js +0 -0
- package/dist/storage/blob/factory.js +1 -1
- package/dist/storage/blob/local-blob-store.js +1 -1
- package/dist/storage/blob/memory-blob-store.js +1 -1
- package/dist/storage/blob/schemas.js +1 -1
- package/dist/storage/cache/factory.js +1 -1
- package/dist/storage/cache/memory-cache-store.js +1 -1
- package/dist/storage/cache/redis-store.js +1 -1
- package/dist/storage/cache/schemas.js +1 -1
- package/dist/storage/database/factory.js +1 -1
- package/dist/storage/database/memory-database-store.js +1 -1
- package/dist/storage/database/postgres-store.cjs +12 -0
- package/dist/storage/database/postgres-store.d.ts.map +1 -1
- package/dist/storage/database/postgres-store.js +13 -1
- package/dist/storage/database/schemas.js +1 -1
- package/dist/storage/database/sqlite-store.js +1 -1
- package/dist/storage/error-codes.js +1 -1
- package/dist/storage/errors.js +1 -1
- package/dist/storage/index.js +1 -1
- package/dist/storage/schemas.js +1 -1
- package/dist/storage/storage-manager.js +1 -1
- package/dist/systemPrompt/contributors.js +1 -1
- package/dist/systemPrompt/error-codes.js +1 -1
- package/dist/systemPrompt/errors.js +1 -1
- package/dist/systemPrompt/in-built-prompts.js +1 -1
- package/dist/systemPrompt/index.js +1 -1
- package/dist/systemPrompt/manager.js +1 -1
- package/dist/systemPrompt/registry.js +1 -1
- package/dist/systemPrompt/schemas.d.ts +5 -5
- package/dist/systemPrompt/schemas.js +1 -1
- package/dist/telemetry/decorators.js +1 -1
- package/dist/telemetry/error-codes.js +1 -1
- package/dist/telemetry/errors.js +1 -1
- package/dist/telemetry/exporters.js +1 -1
- package/dist/telemetry/index.js +1 -1
- package/dist/telemetry/schemas.js +1 -1
- package/dist/telemetry/telemetry.js +1 -1
- package/dist/telemetry/utils.js +1 -1
- package/dist/tools/bash-pattern-utils.cjs +91 -0
- package/dist/tools/bash-pattern-utils.d.ts +58 -0
- package/dist/tools/bash-pattern-utils.d.ts.map +1 -0
- package/dist/tools/bash-pattern-utils.js +64 -0
- package/dist/tools/confirmation/allowed-tools-provider/factory.js +1 -1
- package/dist/tools/confirmation/allowed-tools-provider/in-memory.js +1 -1
- package/dist/tools/confirmation/allowed-tools-provider/storage.js +1 -1
- package/dist/tools/display-types.cjs +60 -0
- package/dist/tools/display-types.d.ts +133 -0
- package/dist/tools/display-types.d.ts.map +1 -0
- package/dist/tools/display-types.js +32 -0
- package/dist/tools/error-codes.cjs +2 -0
- package/dist/tools/error-codes.d.ts +3 -1
- package/dist/tools/error-codes.d.ts.map +1 -1
- package/dist/tools/error-codes.js +3 -1
- package/dist/tools/errors.cjs +30 -0
- package/dist/tools/errors.d.ts +16 -0
- package/dist/tools/errors.d.ts.map +1 -1
- package/dist/tools/errors.js +31 -1
- package/dist/tools/index.cjs +2 -0
- package/dist/tools/index.d.ts +1 -0
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +2 -1
- package/dist/tools/internal-tools/constants.js +1 -1
- package/dist/tools/internal-tools/implementations/ask-user-tool.cjs +1 -1
- package/dist/tools/internal-tools/implementations/ask-user-tool.js +2 -2
- package/dist/tools/internal-tools/implementations/bash-exec-tool.cjs +42 -18
- package/dist/tools/internal-tools/implementations/bash-exec-tool.d.ts +3 -3
- package/dist/tools/internal-tools/implementations/bash-exec-tool.d.ts.map +1 -1
- package/dist/tools/internal-tools/implementations/bash-exec-tool.js +43 -19
- package/dist/tools/internal-tools/implementations/bash-output-tool.js +1 -1
- package/dist/tools/internal-tools/implementations/delegate-to-url-tool.js +1 -1
- package/dist/tools/internal-tools/implementations/edit-file-tool.cjs +66 -1
- package/dist/tools/internal-tools/implementations/edit-file-tool.d.ts.map +1 -1
- package/dist/tools/internal-tools/implementations/edit-file-tool.js +67 -2
- package/dist/tools/internal-tools/implementations/glob-files-tool.cjs +14 -1
- package/dist/tools/internal-tools/implementations/glob-files-tool.d.ts.map +1 -1
- package/dist/tools/internal-tools/implementations/glob-files-tool.js +15 -2
- package/dist/tools/internal-tools/implementations/grep-content-tool.cjs +16 -1
- package/dist/tools/internal-tools/implementations/grep-content-tool.d.ts.map +1 -1
- package/dist/tools/internal-tools/implementations/grep-content-tool.js +17 -2
- package/dist/tools/internal-tools/implementations/kill-process-tool.js +1 -1
- package/dist/tools/internal-tools/implementations/read-file-tool.cjs +9 -1
- package/dist/tools/internal-tools/implementations/read-file-tool.d.ts.map +1 -1
- package/dist/tools/internal-tools/implementations/read-file-tool.js +10 -2
- package/dist/tools/internal-tools/implementations/search-history-tool.js +1 -1
- package/dist/tools/internal-tools/implementations/write-file-tool.cjs +69 -1
- package/dist/tools/internal-tools/implementations/write-file-tool.d.ts.map +1 -1
- package/dist/tools/internal-tools/implementations/write-file-tool.js +72 -2
- package/dist/tools/internal-tools/provider.cjs +27 -10
- package/dist/tools/internal-tools/provider.d.ts +8 -5
- package/dist/tools/internal-tools/provider.d.ts.map +1 -1
- package/dist/tools/internal-tools/provider.js +28 -11
- package/dist/tools/internal-tools/registry.cjs +4 -3
- package/dist/tools/internal-tools/registry.d.ts +28 -7
- package/dist/tools/internal-tools/registry.d.ts.map +1 -1
- package/dist/tools/internal-tools/registry.js +5 -4
- package/dist/tools/schemas.cjs +16 -6
- package/dist/tools/schemas.d.ts +31 -4
- package/dist/tools/schemas.d.ts.map +1 -1
- package/dist/tools/schemas.js +14 -6
- package/dist/tools/tool-manager.cjs +140 -18
- package/dist/tools/tool-manager.d.ts +23 -1
- package/dist/tools/tool-manager.d.ts.map +1 -1
- package/dist/tools/tool-manager.js +145 -19
- package/dist/tools/types.d.ts +20 -0
- package/dist/tools/types.d.ts.map +1 -1
- package/dist/utils/api-key-resolver.js +1 -1
- package/dist/utils/async-context.js +1 -1
- package/dist/utils/debug.js +1 -1
- package/dist/{llm/tokenizer/types.cjs → utils/defer.cjs} +19 -10
- package/dist/utils/defer.d.ts +63 -0
- package/dist/utils/defer.d.ts.map +1 -0
- package/dist/utils/defer.js +19 -0
- package/dist/utils/env-file.js +1 -1
- package/dist/utils/error-conversion.js +1 -1
- package/dist/utils/execution-context.js +1 -1
- package/dist/utils/fs-walk.js +1 -1
- package/dist/utils/index.cjs +3 -1
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -0
- package/dist/utils/path.js +1 -1
- package/dist/utils/redactor.js +1 -1
- package/dist/utils/result.js +1 -1
- package/dist/utils/safe-stringify.js +1 -1
- package/dist/utils/schema-metadata.js +1 -1
- package/dist/utils/schema.js +1 -1
- package/dist/utils/service-initializer.cjs +6 -2
- package/dist/utils/service-initializer.d.ts.map +1 -1
- package/dist/utils/service-initializer.js +7 -3
- package/dist/utils/user-info.js +1 -1
- package/dist/utils/zod-schema-converter.js +1 -1
- package/package.json +6 -7
- package/dist/context/compression/middle-removal.cjs +0 -95
- package/dist/context/compression/middle-removal.d.ts +0 -47
- package/dist/context/compression/middle-removal.d.ts.map +0 -1
- package/dist/context/compression/middle-removal.js +0 -72
- package/dist/context/compression/oldest-removal.cjs +0 -83
- package/dist/context/compression/oldest-removal.d.ts +0 -42
- package/dist/context/compression/oldest-removal.d.ts.map +0 -1
- package/dist/context/compression/oldest-removal.js +0 -60
- package/dist/llm/formatters/anthropic.cjs +0 -257
- package/dist/llm/formatters/anthropic.d.ts +0 -46
- package/dist/llm/formatters/anthropic.d.ts.map +0 -1
- package/dist/llm/formatters/anthropic.js +0 -239
- package/dist/llm/formatters/factory.cjs +0 -50
- package/dist/llm/formatters/factory.d.ts +0 -10
- package/dist/llm/formatters/factory.d.ts.map +0 -1
- package/dist/llm/formatters/factory.js +0 -27
- package/dist/llm/formatters/openai.cjs +0 -203
- package/dist/llm/formatters/openai.d.ts +0 -39
- package/dist/llm/formatters/openai.d.ts.map +0 -1
- package/dist/llm/formatters/openai.js +0 -184
- package/dist/llm/formatters/types.d.ts +0 -41
- package/dist/llm/formatters/types.d.ts.map +0 -1
- package/dist/llm/services/anthropic.cjs +0 -511
- package/dist/llm/services/anthropic.d.ts +0 -48
- package/dist/llm/services/anthropic.d.ts.map +0 -1
- package/dist/llm/services/anthropic.js +0 -447
- package/dist/llm/services/openai.cjs +0 -611
- package/dist/llm/services/openai.d.ts +0 -48
- package/dist/llm/services/openai.d.ts.map +0 -1
- package/dist/llm/services/openai.js +0 -547
- package/dist/llm/tokenizer/anthropic.cjs +0 -43
- package/dist/llm/tokenizer/anthropic.d.ts +0 -19
- package/dist/llm/tokenizer/anthropic.d.ts.map +0 -1
- package/dist/llm/tokenizer/anthropic.js +0 -20
- package/dist/llm/tokenizer/default.d.ts +0 -14
- package/dist/llm/tokenizer/default.d.ts.map +0 -1
- package/dist/llm/tokenizer/default.js +0 -18
- package/dist/llm/tokenizer/factory.cjs +0 -44
- package/dist/llm/tokenizer/factory.d.ts +0 -12
- package/dist/llm/tokenizer/factory.d.ts.map +0 -1
- package/dist/llm/tokenizer/factory.js +0 -21
- package/dist/llm/tokenizer/google.cjs +0 -52
- package/dist/llm/tokenizer/google.d.ts +0 -29
- package/dist/llm/tokenizer/google.d.ts.map +0 -1
- package/dist/llm/tokenizer/google.js +0 -29
- package/dist/llm/tokenizer/openai.cjs +0 -115
- package/dist/llm/tokenizer/openai.d.ts +0 -41
- package/dist/llm/tokenizer/openai.d.ts.map +0 -1
- package/dist/llm/tokenizer/openai.js +0 -91
- package/dist/llm/tokenizer/types.d.ts +0 -18
- package/dist/llm/tokenizer/types.d.ts.map +0 -1
- package/dist/llm/tokenizer/types.js +0 -10
- /package/dist/llm/{formatters → executor}/types.cjs +0 -0
- /package/dist/llm/{formatters → executor}/types.js +0 -0
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var factory_exports = {};
|
|
20
|
-
__export(factory_exports, {
|
|
21
|
-
createTokenizer: () => createTokenizer
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(factory_exports);
|
|
24
|
-
var import_openai = require("./openai.js");
|
|
25
|
-
var import_anthropic = require("./anthropic.js");
|
|
26
|
-
var import_google = require("./google.js");
|
|
27
|
-
var import_default = require("./default.js");
|
|
28
|
-
function createTokenizer(provider, model, logger) {
|
|
29
|
-
switch (provider) {
|
|
30
|
-
case "openai":
|
|
31
|
-
return new import_openai.OpenAITokenizer(model, logger);
|
|
32
|
-
case "anthropic":
|
|
33
|
-
return new import_anthropic.AnthropicTokenizer();
|
|
34
|
-
case "google":
|
|
35
|
-
return new import_google.GoogleTokenizer(model);
|
|
36
|
-
// Add cases for other providers here
|
|
37
|
-
default:
|
|
38
|
-
return new import_default.DefaultTokenizer();
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
42
|
-
0 && (module.exports = {
|
|
43
|
-
createTokenizer
|
|
44
|
-
});
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import { ITokenizer } from './types.js';
|
|
2
|
-
import type { LLMProvider } from '../types.js';
|
|
3
|
-
import type { IDextoLogger } from '../../logger/v2/types.js';
|
|
4
|
-
/**
|
|
5
|
-
* Creates the appropriate tokenizer for the specified provider and model
|
|
6
|
-
* @param provider The LLM provider name (case-insensitive)
|
|
7
|
-
* @param model The specific model name (used by some tokenizers)
|
|
8
|
-
* @param logger The logger instance for logging
|
|
9
|
-
* @returns An appropriate tokenizer implementation, or DefaultTokenizer if no specific implementation exists
|
|
10
|
-
*/
|
|
11
|
-
export declare function createTokenizer(provider: LLMProvider, model: string, logger: IDextoLogger): ITokenizer;
|
|
12
|
-
//# sourceMappingURL=factory.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../src/llm/tokenizer/factory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAKxC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC/C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAE7D;;;;;;GAMG;AACH,wBAAgB,eAAe,CAC3B,QAAQ,EAAE,WAAW,EACrB,KAAK,EAAE,MAAM,EACb,MAAM,EAAE,YAAY,GACrB,UAAU,CAcZ"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import "../../chunk-C6A6W6XS.js";
|
|
2
|
-
import { OpenAITokenizer } from "./openai.js";
|
|
3
|
-
import { AnthropicTokenizer } from "./anthropic.js";
|
|
4
|
-
import { GoogleTokenizer } from "./google.js";
|
|
5
|
-
import { DefaultTokenizer } from "./default.js";
|
|
6
|
-
function createTokenizer(provider, model, logger) {
|
|
7
|
-
switch (provider) {
|
|
8
|
-
case "openai":
|
|
9
|
-
return new OpenAITokenizer(model, logger);
|
|
10
|
-
case "anthropic":
|
|
11
|
-
return new AnthropicTokenizer();
|
|
12
|
-
case "google":
|
|
13
|
-
return new GoogleTokenizer(model);
|
|
14
|
-
// Add cases for other providers here
|
|
15
|
-
default:
|
|
16
|
-
return new DefaultTokenizer();
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
export {
|
|
20
|
-
createTokenizer
|
|
21
|
-
};
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var google_exports = {};
|
|
20
|
-
__export(google_exports, {
|
|
21
|
-
GoogleTokenizer: () => GoogleTokenizer
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(google_exports);
|
|
24
|
-
class GoogleTokenizer {
|
|
25
|
-
modelName;
|
|
26
|
-
/**
|
|
27
|
-
* Initializes the tokenizer for a specific Google Gemini model.
|
|
28
|
-
* Currently, the model name is not used due to the approximation.
|
|
29
|
-
* @param model The Google model name (e.g., 'gemini-pro')
|
|
30
|
-
*/
|
|
31
|
-
constructor(model) {
|
|
32
|
-
this.modelName = model;
|
|
33
|
-
}
|
|
34
|
-
/**
|
|
35
|
-
* Approximates the token count for Google Gemini models.
|
|
36
|
-
* Uses a rough guess based on character count (similar to Anthropic's approximation).
|
|
37
|
-
* IMPORTANT: This is NOT accurate for Gemini models.
|
|
38
|
-
* @param text Text content to count tokens for
|
|
39
|
-
* @returns Approximate number of tokens
|
|
40
|
-
*/
|
|
41
|
-
countTokens(text) {
|
|
42
|
-
if (!text) return 0;
|
|
43
|
-
return Math.ceil(text.length / 4);
|
|
44
|
-
}
|
|
45
|
-
getProviderName() {
|
|
46
|
-
return "google";
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
-
0 && (module.exports = {
|
|
51
|
-
GoogleTokenizer
|
|
52
|
-
});
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { ITokenizer } from './types.js';
|
|
2
|
-
/**
|
|
3
|
-
* Tokenizer for Google Gemini models - CURRENTLY USING APPROXIMATION.
|
|
4
|
-
*
|
|
5
|
-
* TODO: Replace this with a proper token counting implementation.
|
|
6
|
-
* The official `@google/generative-ai` library's `countTokens` function
|
|
7
|
-
* is asynchronous, which complicates synchronous use cases.
|
|
8
|
-
* Consider using a WASM-based tokenizer or re-evaluating the need
|
|
9
|
-
* for synchronous counting if a more accurate method is required.
|
|
10
|
-
*/
|
|
11
|
-
export declare class GoogleTokenizer implements ITokenizer {
|
|
12
|
-
private modelName;
|
|
13
|
-
/**
|
|
14
|
-
* Initializes the tokenizer for a specific Google Gemini model.
|
|
15
|
-
* Currently, the model name is not used due to the approximation.
|
|
16
|
-
* @param model The Google model name (e.g., 'gemini-pro')
|
|
17
|
-
*/
|
|
18
|
-
constructor(model: string);
|
|
19
|
-
/**
|
|
20
|
-
* Approximates the token count for Google Gemini models.
|
|
21
|
-
* Uses a rough guess based on character count (similar to Anthropic's approximation).
|
|
22
|
-
* IMPORTANT: This is NOT accurate for Gemini models.
|
|
23
|
-
* @param text Text content to count tokens for
|
|
24
|
-
* @returns Approximate number of tokens
|
|
25
|
-
*/
|
|
26
|
-
countTokens(text: string): number;
|
|
27
|
-
getProviderName(): string;
|
|
28
|
-
}
|
|
29
|
-
//# sourceMappingURL=google.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"google.d.ts","sourceRoot":"","sources":["../../../src/llm/tokenizer/google.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAExC;;;;;;;;GAQG;AACH,qBAAa,eAAgB,YAAW,UAAU;IAC9C,OAAO,CAAC,SAAS,CAAS;IAE1B;;;;OAIG;gBACS,KAAK,EAAE,MAAM;IAMzB;;;;;;OAMG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAOjC,eAAe,IAAI,MAAM;CAG5B"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import "../../chunk-C6A6W6XS.js";
|
|
2
|
-
class GoogleTokenizer {
|
|
3
|
-
modelName;
|
|
4
|
-
/**
|
|
5
|
-
* Initializes the tokenizer for a specific Google Gemini model.
|
|
6
|
-
* Currently, the model name is not used due to the approximation.
|
|
7
|
-
* @param model The Google model name (e.g., 'gemini-pro')
|
|
8
|
-
*/
|
|
9
|
-
constructor(model) {
|
|
10
|
-
this.modelName = model;
|
|
11
|
-
}
|
|
12
|
-
/**
|
|
13
|
-
* Approximates the token count for Google Gemini models.
|
|
14
|
-
* Uses a rough guess based on character count (similar to Anthropic's approximation).
|
|
15
|
-
* IMPORTANT: This is NOT accurate for Gemini models.
|
|
16
|
-
* @param text Text content to count tokens for
|
|
17
|
-
* @returns Approximate number of tokens
|
|
18
|
-
*/
|
|
19
|
-
countTokens(text) {
|
|
20
|
-
if (!text) return 0;
|
|
21
|
-
return Math.ceil(text.length / 4);
|
|
22
|
-
}
|
|
23
|
-
getProviderName() {
|
|
24
|
-
return "google";
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
export {
|
|
28
|
-
GoogleTokenizer
|
|
29
|
-
};
|
|
@@ -1,115 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
var openai_exports = {};
|
|
20
|
-
__export(openai_exports, {
|
|
21
|
-
OpenAITokenizer: () => OpenAITokenizer
|
|
22
|
-
});
|
|
23
|
-
module.exports = __toCommonJS(openai_exports);
|
|
24
|
-
var import_types = require("./types.js");
|
|
25
|
-
var import_module = require("module");
|
|
26
|
-
var import_types2 = require("../../logger/v2/types.js");
|
|
27
|
-
const import_meta = {};
|
|
28
|
-
const FALLBACK_ENCODING = "cl100k_base";
|
|
29
|
-
class OpenAITokenizer {
|
|
30
|
-
modelName;
|
|
31
|
-
// Store original model name for context/logging
|
|
32
|
-
encoding;
|
|
33
|
-
// Tiktoken encoding instance
|
|
34
|
-
logger;
|
|
35
|
-
/**
|
|
36
|
-
* Initializes the tokenizer for a specific OpenAI model or compatible model.
|
|
37
|
-
* @param model The OpenAI model name (e.g., 'gpt-5') or a custom model name.
|
|
38
|
-
* @param logger The logger instance for logging.
|
|
39
|
-
* @throws TokenizationError if tiktoken initialization fails for both specific model and fallback.
|
|
40
|
-
*/
|
|
41
|
-
constructor(model, logger) {
|
|
42
|
-
this.modelName = model;
|
|
43
|
-
this.logger = logger.createChild(import_types2.DextoLogComponent.LLM);
|
|
44
|
-
try {
|
|
45
|
-
const { encoding_for_model } = loadTiktoken();
|
|
46
|
-
this.encoding = encoding_for_model(model);
|
|
47
|
-
this.logger.debug(`Initialized tiktoken with specific encoding for model: ${model}`);
|
|
48
|
-
} catch (error) {
|
|
49
|
-
this.logger.warn(
|
|
50
|
-
`Could not get specific encoding for model '${this.modelName}'. Falling back to '${FALLBACK_ENCODING}'. Error: ${error instanceof Error ? error.message : String(error)}`
|
|
51
|
-
);
|
|
52
|
-
try {
|
|
53
|
-
const { get_encoding } = loadTiktoken();
|
|
54
|
-
this.encoding = get_encoding(FALLBACK_ENCODING);
|
|
55
|
-
this.logger.debug(
|
|
56
|
-
`Initialized tiktoken with fallback encoding: ${FALLBACK_ENCODING}`
|
|
57
|
-
);
|
|
58
|
-
} catch (fallbackError) {
|
|
59
|
-
this.logger.error(
|
|
60
|
-
`Failed to initialize tiktoken with specific model '${this.modelName}' or fallback '${FALLBACK_ENCODING}'.`,
|
|
61
|
-
{
|
|
62
|
-
error: fallbackError instanceof Error ? fallbackError.message : String(fallbackError)
|
|
63
|
-
}
|
|
64
|
-
);
|
|
65
|
-
throw new import_types.TokenizationError(
|
|
66
|
-
`Failed to initialize tiktoken for model '${this.modelName}' using specific or fallback encoding ('${FALLBACK_ENCODING}'): ${fallbackError instanceof Error ? fallbackError.message : String(fallbackError)}`
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
/**
|
|
72
|
-
* Counts the tokens in the text using the determined encoding.
|
|
73
|
-
* @param text Text content to count tokens for
|
|
74
|
-
* @returns Number of tokens
|
|
75
|
-
* @throws TokenizationError if encoding fails during counting.
|
|
76
|
-
*/
|
|
77
|
-
countTokens(text) {
|
|
78
|
-
if (!text) return 0;
|
|
79
|
-
try {
|
|
80
|
-
const tokens = this.encoding.encode(text);
|
|
81
|
-
return tokens.length;
|
|
82
|
-
} catch (error) {
|
|
83
|
-
this.logger.error(
|
|
84
|
-
`Tiktoken encoding failed for model ${this.modelName} (using encoding: ${this.encoding.name}):`,
|
|
85
|
-
{ error: error instanceof Error ? error.message : String(error) }
|
|
86
|
-
);
|
|
87
|
-
throw new import_types.TokenizationError(
|
|
88
|
-
`Encoding failed for text snippet using model ${this.modelName}.`
|
|
89
|
-
);
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Cleans up the tiktoken encoding instance when done.
|
|
94
|
-
* Recommended by tiktoken library.
|
|
95
|
-
*/
|
|
96
|
-
free() {
|
|
97
|
-
if (this.encoding) {
|
|
98
|
-
this.encoding.free();
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
getProviderName() {
|
|
102
|
-
return "openai";
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
let _tiktoken = null;
|
|
106
|
-
function loadTiktoken() {
|
|
107
|
-
if (_tiktoken) return _tiktoken;
|
|
108
|
-
const req = (0, import_module.createRequire)(import_meta.url);
|
|
109
|
-
_tiktoken = req("tiktoken");
|
|
110
|
-
return _tiktoken;
|
|
111
|
-
}
|
|
112
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
113
|
-
0 && (module.exports = {
|
|
114
|
-
OpenAITokenizer
|
|
115
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
import { ITokenizer } from './types.js';
|
|
2
|
-
import type { IDextoLogger } from '../../logger/v2/types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Tokenizer for OpenAI models using the tiktoken library.
|
|
5
|
-
*
|
|
6
|
-
* TODO: Make tiktoken an optional peer dependency to reduce package size by ~23MB
|
|
7
|
-
* tiktoken includes WASM binaries (5.3MB) and encoder data files (16MB).
|
|
8
|
-
* It's only needed for accurate pre-request token estimation for OpenAI models.
|
|
9
|
-
* - All providers return actual token counts in API responses
|
|
10
|
-
* - Anthropic/Google/others already use simple text.length/4 approximation
|
|
11
|
-
* - Consider falling back to DefaultTokenizer if tiktoken is not installed
|
|
12
|
-
* See: packages/core/src/llm/tokenizer/factory.ts
|
|
13
|
-
* Attempts to use the specific model's encoding, falls back to a common base encoding ('cl100k_base')
|
|
14
|
-
* for unknown or custom model names (often used with custom baseURLs).
|
|
15
|
-
*/
|
|
16
|
-
export declare class OpenAITokenizer implements ITokenizer {
|
|
17
|
-
private modelName;
|
|
18
|
-
private encoding;
|
|
19
|
-
private logger;
|
|
20
|
-
/**
|
|
21
|
-
* Initializes the tokenizer for a specific OpenAI model or compatible model.
|
|
22
|
-
* @param model The OpenAI model name (e.g., 'gpt-5') or a custom model name.
|
|
23
|
-
* @param logger The logger instance for logging.
|
|
24
|
-
* @throws TokenizationError if tiktoken initialization fails for both specific model and fallback.
|
|
25
|
-
*/
|
|
26
|
-
constructor(model: string, logger: IDextoLogger);
|
|
27
|
-
/**
|
|
28
|
-
* Counts the tokens in the text using the determined encoding.
|
|
29
|
-
* @param text Text content to count tokens for
|
|
30
|
-
* @returns Number of tokens
|
|
31
|
-
* @throws TokenizationError if encoding fails during counting.
|
|
32
|
-
*/
|
|
33
|
-
countTokens(text: string): number;
|
|
34
|
-
/**
|
|
35
|
-
* Cleans up the tiktoken encoding instance when done.
|
|
36
|
-
* Recommended by tiktoken library.
|
|
37
|
-
*/
|
|
38
|
-
free(): void;
|
|
39
|
-
getProviderName(): string;
|
|
40
|
-
}
|
|
41
|
-
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../../../src/llm/tokenizer/openai.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAqB,MAAM,YAAY,CAAC;AAG3D,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAM7D;;;;;;;;;;;;GAYG;AACH,qBAAa,eAAgB,YAAW,UAAU;IAC9C,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,QAAQ,CAAW;IAC3B,OAAO,CAAC,MAAM,CAAe;IAE7B;;;;;OAKG;gBACS,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY;IAqC/C;;;;;OAKG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAgBjC;;;OAGG;IACH,IAAI,IAAI,IAAI;IAMZ,eAAe,IAAI,MAAM;CAG5B"}
|
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import "../../chunk-C6A6W6XS.js";
|
|
2
|
-
import { TokenizationError } from "./types.js";
|
|
3
|
-
import { createRequire } from "module";
|
|
4
|
-
import { DextoLogComponent } from "../../logger/v2/types.js";
|
|
5
|
-
const FALLBACK_ENCODING = "cl100k_base";
|
|
6
|
-
class OpenAITokenizer {
|
|
7
|
-
modelName;
|
|
8
|
-
// Store original model name for context/logging
|
|
9
|
-
encoding;
|
|
10
|
-
// Tiktoken encoding instance
|
|
11
|
-
logger;
|
|
12
|
-
/**
|
|
13
|
-
* Initializes the tokenizer for a specific OpenAI model or compatible model.
|
|
14
|
-
* @param model The OpenAI model name (e.g., 'gpt-5') or a custom model name.
|
|
15
|
-
* @param logger The logger instance for logging.
|
|
16
|
-
* @throws TokenizationError if tiktoken initialization fails for both specific model and fallback.
|
|
17
|
-
*/
|
|
18
|
-
constructor(model, logger) {
|
|
19
|
-
this.modelName = model;
|
|
20
|
-
this.logger = logger.createChild(DextoLogComponent.LLM);
|
|
21
|
-
try {
|
|
22
|
-
const { encoding_for_model } = loadTiktoken();
|
|
23
|
-
this.encoding = encoding_for_model(model);
|
|
24
|
-
this.logger.debug(`Initialized tiktoken with specific encoding for model: ${model}`);
|
|
25
|
-
} catch (error) {
|
|
26
|
-
this.logger.warn(
|
|
27
|
-
`Could not get specific encoding for model '${this.modelName}'. Falling back to '${FALLBACK_ENCODING}'. Error: ${error instanceof Error ? error.message : String(error)}`
|
|
28
|
-
);
|
|
29
|
-
try {
|
|
30
|
-
const { get_encoding } = loadTiktoken();
|
|
31
|
-
this.encoding = get_encoding(FALLBACK_ENCODING);
|
|
32
|
-
this.logger.debug(
|
|
33
|
-
`Initialized tiktoken with fallback encoding: ${FALLBACK_ENCODING}`
|
|
34
|
-
);
|
|
35
|
-
} catch (fallbackError) {
|
|
36
|
-
this.logger.error(
|
|
37
|
-
`Failed to initialize tiktoken with specific model '${this.modelName}' or fallback '${FALLBACK_ENCODING}'.`,
|
|
38
|
-
{
|
|
39
|
-
error: fallbackError instanceof Error ? fallbackError.message : String(fallbackError)
|
|
40
|
-
}
|
|
41
|
-
);
|
|
42
|
-
throw new TokenizationError(
|
|
43
|
-
`Failed to initialize tiktoken for model '${this.modelName}' using specific or fallback encoding ('${FALLBACK_ENCODING}'): ${fallbackError instanceof Error ? fallbackError.message : String(fallbackError)}`
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Counts the tokens in the text using the determined encoding.
|
|
50
|
-
* @param text Text content to count tokens for
|
|
51
|
-
* @returns Number of tokens
|
|
52
|
-
* @throws TokenizationError if encoding fails during counting.
|
|
53
|
-
*/
|
|
54
|
-
countTokens(text) {
|
|
55
|
-
if (!text) return 0;
|
|
56
|
-
try {
|
|
57
|
-
const tokens = this.encoding.encode(text);
|
|
58
|
-
return tokens.length;
|
|
59
|
-
} catch (error) {
|
|
60
|
-
this.logger.error(
|
|
61
|
-
`Tiktoken encoding failed for model ${this.modelName} (using encoding: ${this.encoding.name}):`,
|
|
62
|
-
{ error: error instanceof Error ? error.message : String(error) }
|
|
63
|
-
);
|
|
64
|
-
throw new TokenizationError(
|
|
65
|
-
`Encoding failed for text snippet using model ${this.modelName}.`
|
|
66
|
-
);
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Cleans up the tiktoken encoding instance when done.
|
|
71
|
-
* Recommended by tiktoken library.
|
|
72
|
-
*/
|
|
73
|
-
free() {
|
|
74
|
-
if (this.encoding) {
|
|
75
|
-
this.encoding.free();
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
getProviderName() {
|
|
79
|
-
return "openai";
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
let _tiktoken = null;
|
|
83
|
-
function loadTiktoken() {
|
|
84
|
-
if (_tiktoken) return _tiktoken;
|
|
85
|
-
const req = createRequire(import.meta.url);
|
|
86
|
-
_tiktoken = req("tiktoken");
|
|
87
|
-
return _tiktoken;
|
|
88
|
-
}
|
|
89
|
-
export {
|
|
90
|
-
OpenAITokenizer
|
|
91
|
-
};
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
export interface ITokenizer {
|
|
2
|
-
/**
|
|
3
|
-
* Counts the number of tokens in the provided text according
|
|
4
|
-
* to the specific LLM provider's tokenization rules
|
|
5
|
-
* @param text Text content to count tokens for
|
|
6
|
-
* @returns Number of tokens in the text
|
|
7
|
-
*/
|
|
8
|
-
countTokens(text: string): number;
|
|
9
|
-
/**
|
|
10
|
-
* Gets the name of the LLM provider this tokenizer is for
|
|
11
|
-
* @returns Provider name (e.g., "openai", "anthropic")
|
|
12
|
-
*/
|
|
13
|
-
getProviderName(): string;
|
|
14
|
-
}
|
|
15
|
-
export declare class TokenizationError extends Error {
|
|
16
|
-
constructor(message: string);
|
|
17
|
-
}
|
|
18
|
-
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/llm/tokenizer/types.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,UAAU;IACvB;;;;;OAKG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC;IAElC;;;OAGG;IACH,eAAe,IAAI,MAAM,CAAC;CAC7B;AAED,qBAAa,iBAAkB,SAAQ,KAAK;gBAC5B,OAAO,EAAE,MAAM;CAI9B"}
|
|
File without changes
|
|
File without changes
|