@particle-academy/prism 0.0.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/LICENSE +21 -0
- package/README.md +155 -0
- package/dist/audio/pending-request.d.ts +37 -0
- package/dist/audio/pending-request.d.ts.map +1 -0
- package/dist/audio/pending-request.js +91 -0
- package/dist/audio/pending-request.js.map +1 -0
- package/dist/audio/request.d.ts +37 -0
- package/dist/audio/request.d.ts.map +1 -0
- package/dist/audio/request.js +50 -0
- package/dist/audio/request.js.map +1 -0
- package/dist/audio/response.d.ts +24 -0
- package/dist/audio/response.d.ts.map +1 -0
- package/dist/audio/response.js +36 -0
- package/dist/audio/response.js.map +1 -0
- package/dist/batch/batch-job.d.ts +91 -0
- package/dist/batch/batch-job.d.ts.map +1 -0
- package/dist/batch/batch-job.js +156 -0
- package/dist/batch/batch-job.js.map +1 -0
- package/dist/batch/pending-request.d.ts +29 -0
- package/dist/batch/pending-request.d.ts.map +1 -0
- package/dist/batch/pending-request.js +73 -0
- package/dist/batch/pending-request.js.map +1 -0
- package/dist/batch/request.d.ts +73 -0
- package/dist/batch/request.d.ts.map +1 -0
- package/dist/batch/request.js +79 -0
- package/dist/batch/request.js.map +1 -0
- package/dist/embeddings/pending-request.d.ts +38 -0
- package/dist/embeddings/pending-request.d.ts.map +1 -0
- package/dist/embeddings/pending-request.js +86 -0
- package/dist/embeddings/pending-request.js.map +1 -0
- package/dist/embeddings/request.d.ts +27 -0
- package/dist/embeddings/request.d.ts.map +1 -0
- package/dist/embeddings/request.js +38 -0
- package/dist/embeddings/request.js.map +1 -0
- package/dist/embeddings/response.d.ts +19 -0
- package/dist/embeddings/response.d.ts.map +1 -0
- package/dist/embeddings/response.js +21 -0
- package/dist/embeddings/response.js.map +1 -0
- package/dist/enums.d.ts +52 -0
- package/dist/enums.d.ts.map +1 -0
- package/dist/enums.js +69 -0
- package/dist/enums.js.map +1 -0
- package/dist/errors.d.ts +119 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +115 -0
- package/dist/errors.js.map +1 -0
- package/dist/files/file-data.d.ts +53 -0
- package/dist/files/file-data.d.ts.map +1 -0
- package/dist/files/file-data.js +79 -0
- package/dist/files/file-data.js.map +1 -0
- package/dist/files/pending-request.d.ts +38 -0
- package/dist/files/pending-request.d.ts.map +1 -0
- package/dist/files/pending-request.js +96 -0
- package/dist/files/pending-request.js.map +1 -0
- package/dist/files/request.d.ts +77 -0
- package/dist/files/request.d.ts.map +1 -0
- package/dist/files/request.js +81 -0
- package/dist/files/request.js.map +1 -0
- package/dist/fim/pending-request.d.ts +31 -0
- package/dist/fim/pending-request.d.ts.map +1 -0
- package/dist/fim/pending-request.js +89 -0
- package/dist/fim/pending-request.js.map +1 -0
- package/dist/fim/request.d.ts +39 -0
- package/dist/fim/request.d.ts.map +1 -0
- package/dist/fim/request.js +65 -0
- package/dist/fim/request.js.map +1 -0
- package/dist/fim/response.d.ts +21 -0
- package/dist/fim/response.d.ts.map +1 -0
- package/dist/fim/response.js +30 -0
- package/dist/fim/response.js.map +1 -0
- package/dist/http/header-names.d.ts +36 -0
- package/dist/http/header-names.d.ts.map +1 -0
- package/dist/http/header-names.js +44 -0
- package/dist/http/header-names.js.map +1 -0
- package/dist/http/transport.d.ts +94 -0
- package/dist/http/transport.d.ts.map +1 -0
- package/dist/http/transport.js +131 -0
- package/dist/http/transport.js.map +1 -0
- package/dist/images/pending-request.d.ts +30 -0
- package/dist/images/pending-request.d.ts.map +1 -0
- package/dist/images/pending-request.js +66 -0
- package/dist/images/pending-request.js.map +1 -0
- package/dist/images/request.d.ts +19 -0
- package/dist/images/request.d.ts.map +1 -0
- package/dist/images/request.js +30 -0
- package/dist/images/request.js.map +1 -0
- package/dist/images/response.d.ts +29 -0
- package/dist/images/response.d.ts.map +1 -0
- package/dist/images/response.js +34 -0
- package/dist/images/response.js.map +1 -0
- package/dist/index.d.ts +108 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +84 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/filters.d.ts +40 -0
- package/dist/internal/filters.d.ts.map +1 -0
- package/dist/internal/filters.js +83 -0
- package/dist/internal/filters.js.map +1 -0
- package/dist/json.d.ts +41 -0
- package/dist/json.d.ts.map +1 -0
- package/dist/json.js +75 -0
- package/dist/json.js.map +1 -0
- package/dist/moderation/pending-request.d.ts +24 -0
- package/dist/moderation/pending-request.d.ts.map +1 -0
- package/dist/moderation/pending-request.js +60 -0
- package/dist/moderation/pending-request.js.map +1 -0
- package/dist/moderation/request.d.ts +20 -0
- package/dist/moderation/request.d.ts.map +1 -0
- package/dist/moderation/request.js +31 -0
- package/dist/moderation/request.js.map +1 -0
- package/dist/moderation/response.d.ts +26 -0
- package/dist/moderation/response.d.ts.map +1 -0
- package/dist/moderation/response.js +34 -0
- package/dist/moderation/response.js.map +1 -0
- package/dist/prism.d.ts +43 -0
- package/dist/prism.d.ts.map +1 -0
- package/dist/prism.js +79 -0
- package/dist/prism.js.map +1 -0
- package/dist/providers/anthropic/anthropic.d.ts +67 -0
- package/dist/providers/anthropic/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic/anthropic.js +172 -0
- package/dist/providers/anthropic/anthropic.js.map +1 -0
- package/dist/providers/anthropic/build-request-body.d.ts +15 -0
- package/dist/providers/anthropic/build-request-body.d.ts.map +1 -0
- package/dist/providers/anthropic/build-request-body.js +51 -0
- package/dist/providers/anthropic/build-request-body.js.map +1 -0
- package/dist/providers/anthropic/maps/finish-reason-map.d.ts +14 -0
- package/dist/providers/anthropic/maps/finish-reason-map.d.ts.map +1 -0
- package/dist/providers/anthropic/maps/finish-reason-map.js +30 -0
- package/dist/providers/anthropic/maps/finish-reason-map.js.map +1 -0
- package/dist/providers/anthropic/maps/media-map.d.ts +25 -0
- package/dist/providers/anthropic/maps/media-map.d.ts.map +1 -0
- package/dist/providers/anthropic/maps/media-map.js +87 -0
- package/dist/providers/anthropic/maps/media-map.js.map +1 -0
- package/dist/providers/anthropic/maps/message-map.d.ts +31 -0
- package/dist/providers/anthropic/maps/message-map.d.ts.map +1 -0
- package/dist/providers/anthropic/maps/message-map.js +121 -0
- package/dist/providers/anthropic/maps/message-map.js.map +1 -0
- package/dist/providers/anthropic/maps/tool-choice-map.d.ts +11 -0
- package/dist/providers/anthropic/maps/tool-choice-map.d.ts.map +1 -0
- package/dist/providers/anthropic/maps/tool-choice-map.js +25 -0
- package/dist/providers/anthropic/maps/tool-choice-map.js.map +1 -0
- package/dist/providers/anthropic/maps/tool-map.d.ts +14 -0
- package/dist/providers/anthropic/maps/tool-map.d.ts.map +1 -0
- package/dist/providers/anthropic/maps/tool-map.js +22 -0
- package/dist/providers/anthropic/maps/tool-map.js.map +1 -0
- package/dist/providers/anthropic/parse-response.d.ts +21 -0
- package/dist/providers/anthropic/parse-response.d.ts.map +1 -0
- package/dist/providers/anthropic/parse-response.js +109 -0
- package/dist/providers/anthropic/parse-response.js.map +1 -0
- package/dist/providers/anthropic/rate-limits.d.ts +4 -0
- package/dist/providers/anthropic/rate-limits.d.ts.map +1 -0
- package/dist/providers/anthropic/rate-limits.js +47 -0
- package/dist/providers/anthropic/rate-limits.js.map +1 -0
- package/dist/providers/anthropic/stream-events.d.ts +27 -0
- package/dist/providers/anthropic/stream-events.d.ts.map +1 -0
- package/dist/providers/anthropic/stream-events.js +147 -0
- package/dist/providers/anthropic/stream-events.js.map +1 -0
- package/dist/providers/mistral/build-request-body.d.ts +32 -0
- package/dist/providers/mistral/build-request-body.d.ts.map +1 -0
- package/dist/providers/mistral/build-request-body.js +69 -0
- package/dist/providers/mistral/build-request-body.js.map +1 -0
- package/dist/providers/mistral/embeddings.d.ts +14 -0
- package/dist/providers/mistral/embeddings.d.ts.map +1 -0
- package/dist/providers/mistral/embeddings.js +41 -0
- package/dist/providers/mistral/embeddings.js.map +1 -0
- package/dist/providers/mistral/fim.d.ts +32 -0
- package/dist/providers/mistral/fim.d.ts.map +1 -0
- package/dist/providers/mistral/fim.js +70 -0
- package/dist/providers/mistral/fim.js.map +1 -0
- package/dist/providers/mistral/maps/finish-reason-map.d.ts +15 -0
- package/dist/providers/mistral/maps/finish-reason-map.d.ts.map +1 -0
- package/dist/providers/mistral/maps/finish-reason-map.js +32 -0
- package/dist/providers/mistral/maps/finish-reason-map.js.map +1 -0
- package/dist/providers/mistral/maps/media-map.d.ts +24 -0
- package/dist/providers/mistral/maps/media-map.d.ts.map +1 -0
- package/dist/providers/mistral/maps/media-map.js +41 -0
- package/dist/providers/mistral/maps/media-map.js.map +1 -0
- package/dist/providers/mistral/maps/message-map.d.ts +20 -0
- package/dist/providers/mistral/maps/message-map.d.ts.map +1 -0
- package/dist/providers/mistral/maps/message-map.js +83 -0
- package/dist/providers/mistral/maps/message-map.js.map +1 -0
- package/dist/providers/mistral/maps/tool-choice-map.d.ts +12 -0
- package/dist/providers/mistral/maps/tool-choice-map.d.ts.map +1 -0
- package/dist/providers/mistral/maps/tool-choice-map.js +25 -0
- package/dist/providers/mistral/maps/tool-choice-map.js.map +1 -0
- package/dist/providers/mistral/maps/tool-map.d.ts +15 -0
- package/dist/providers/mistral/maps/tool-map.d.ts.map +1 -0
- package/dist/providers/mistral/maps/tool-map.js +26 -0
- package/dist/providers/mistral/maps/tool-map.js.map +1 -0
- package/dist/providers/mistral/mistral.d.ts +90 -0
- package/dist/providers/mistral/mistral.d.ts.map +1 -0
- package/dist/providers/mistral/mistral.js +210 -0
- package/dist/providers/mistral/mistral.js.map +1 -0
- package/dist/providers/mistral/parse-response.d.ts +35 -0
- package/dist/providers/mistral/parse-response.d.ts.map +1 -0
- package/dist/providers/mistral/parse-response.js +114 -0
- package/dist/providers/mistral/parse-response.js.map +1 -0
- package/dist/providers/mistral/rate-limits.d.ts +24 -0
- package/dist/providers/mistral/rate-limits.d.ts.map +1 -0
- package/dist/providers/mistral/rate-limits.js +55 -0
- package/dist/providers/mistral/rate-limits.js.map +1 -0
- package/dist/providers/mistral/stream-events.d.ts +29 -0
- package/dist/providers/mistral/stream-events.d.ts.map +1 -0
- package/dist/providers/mistral/stream-events.js +142 -0
- package/dist/providers/mistral/stream-events.js.map +1 -0
- package/dist/providers/openai/audio.d.ts +16 -0
- package/dist/providers/openai/audio.d.ts.map +1 -0
- package/dist/providers/openai/audio.js +105 -0
- package/dist/providers/openai/audio.js.map +1 -0
- package/dist/providers/openai/batch.d.ts +29 -0
- package/dist/providers/openai/batch.d.ts.map +1 -0
- package/dist/providers/openai/batch.js +181 -0
- package/dist/providers/openai/batch.js.map +1 -0
- package/dist/providers/openai/build-request-body.d.ts +25 -0
- package/dist/providers/openai/build-request-body.d.ts.map +1 -0
- package/dist/providers/openai/build-request-body.js +66 -0
- package/dist/providers/openai/build-request-body.js.map +1 -0
- package/dist/providers/openai/build-structured-body.d.ts +16 -0
- package/dist/providers/openai/build-structured-body.d.ts.map +1 -0
- package/dist/providers/openai/build-structured-body.js +47 -0
- package/dist/providers/openai/build-structured-body.js.map +1 -0
- package/dist/providers/openai/embeddings.d.ts +6 -0
- package/dist/providers/openai/embeddings.d.ts.map +1 -0
- package/dist/providers/openai/embeddings.js +61 -0
- package/dist/providers/openai/embeddings.js.map +1 -0
- package/dist/providers/openai/files.d.ts +16 -0
- package/dist/providers/openai/files.d.ts.map +1 -0
- package/dist/providers/openai/files.js +80 -0
- package/dist/providers/openai/files.js.map +1 -0
- package/dist/providers/openai/images.d.ts +6 -0
- package/dist/providers/openai/images.d.ts.map +1 -0
- package/dist/providers/openai/images.js +55 -0
- package/dist/providers/openai/images.js.map +1 -0
- package/dist/providers/openai/maps/finish-reason-map.d.ts +21 -0
- package/dist/providers/openai/maps/finish-reason-map.d.ts.map +1 -0
- package/dist/providers/openai/maps/finish-reason-map.js +56 -0
- package/dist/providers/openai/maps/finish-reason-map.js.map +1 -0
- package/dist/providers/openai/maps/media-map.d.ts +25 -0
- package/dist/providers/openai/maps/media-map.d.ts.map +1 -0
- package/dist/providers/openai/maps/media-map.js +53 -0
- package/dist/providers/openai/maps/media-map.js.map +1 -0
- package/dist/providers/openai/maps/message-map.d.ts +21 -0
- package/dist/providers/openai/maps/message-map.d.ts.map +1 -0
- package/dist/providers/openai/maps/message-map.js +128 -0
- package/dist/providers/openai/maps/message-map.js.map +1 -0
- package/dist/providers/openai/maps/tool-choice-map.d.ts +14 -0
- package/dist/providers/openai/maps/tool-choice-map.d.ts.map +1 -0
- package/dist/providers/openai/maps/tool-choice-map.js +27 -0
- package/dist/providers/openai/maps/tool-choice-map.js.map +1 -0
- package/dist/providers/openai/maps/tool-map.d.ts +16 -0
- package/dist/providers/openai/maps/tool-map.d.ts.map +1 -0
- package/dist/providers/openai/maps/tool-map.js +34 -0
- package/dist/providers/openai/maps/tool-map.js.map +1 -0
- package/dist/providers/openai/moderation.d.ts +6 -0
- package/dist/providers/openai/moderation.d.ts.map +1 -0
- package/dist/providers/openai/moderation.js +26 -0
- package/dist/providers/openai/moderation.js.map +1 -0
- package/dist/providers/openai/openai.d.ts +103 -0
- package/dist/providers/openai/openai.d.ts.map +1 -0
- package/dist/providers/openai/openai.js +385 -0
- package/dist/providers/openai/openai.js.map +1 -0
- package/dist/providers/openai/parse-response.d.ts +21 -0
- package/dist/providers/openai/parse-response.d.ts.map +1 -0
- package/dist/providers/openai/parse-response.js +114 -0
- package/dist/providers/openai/parse-response.js.map +1 -0
- package/dist/providers/openai/rate-limits.d.ts +4 -0
- package/dist/providers/openai/rate-limits.d.ts.map +1 -0
- package/dist/providers/openai/rate-limits.js +47 -0
- package/dist/providers/openai/rate-limits.js.map +1 -0
- package/dist/providers/openai/stream-events.d.ts +13 -0
- package/dist/providers/openai/stream-events.d.ts.map +1 -0
- package/dist/providers/openai/stream-events.js +79 -0
- package/dist/providers/openai/stream-events.js.map +1 -0
- package/dist/providers/openai/structured-mode-resolver.d.ts +3 -0
- package/dist/providers/openai/structured-mode-resolver.d.ts.map +1 -0
- package/dist/providers/openai/structured-mode-resolver.js +41 -0
- package/dist/providers/openai/structured-mode-resolver.js.map +1 -0
- package/dist/providers/provider.d.ts +55 -0
- package/dist/providers/provider.d.ts.map +1 -0
- package/dist/providers/provider.js +73 -0
- package/dist/providers/provider.js.map +1 -0
- package/dist/providers/registry.d.ts +10 -0
- package/dist/providers/registry.d.ts.map +1 -0
- package/dist/providers/registry.js +27 -0
- package/dist/providers/registry.js.map +1 -0
- package/dist/providers/support/media.d.ts +16 -0
- package/dist/providers/support/media.d.ts.map +1 -0
- package/dist/providers/support/media.js +26 -0
- package/dist/providers/support/media.js.map +1 -0
- package/dist/schema/index.d.ts +114 -0
- package/dist/schema/index.d.ts.map +1 -0
- package/dist/schema/index.js +192 -0
- package/dist/schema/index.js.map +1 -0
- package/dist/streaming/events.d.ts +90 -0
- package/dist/streaming/events.d.ts.map +1 -0
- package/dist/streaming/events.js +152 -0
- package/dist/streaming/events.js.map +1 -0
- package/dist/streaming/sse.d.ts +17 -0
- package/dist/streaming/sse.d.ts.map +1 -0
- package/dist/streaming/sse.js +50 -0
- package/dist/streaming/sse.js.map +1 -0
- package/dist/structured/extract.d.ts +23 -0
- package/dist/structured/extract.d.ts.map +1 -0
- package/dist/structured/extract.js +43 -0
- package/dist/structured/extract.js.map +1 -0
- package/dist/structured/from-text.d.ts +16 -0
- package/dist/structured/from-text.d.ts.map +1 -0
- package/dist/structured/from-text.js +27 -0
- package/dist/structured/from-text.js.map +1 -0
- package/dist/structured/pending-request.d.ts +28 -0
- package/dist/structured/pending-request.d.ts.map +1 -0
- package/dist/structured/pending-request.js +48 -0
- package/dist/structured/pending-request.js.map +1 -0
- package/dist/structured/request.d.ts +28 -0
- package/dist/structured/request.d.ts.map +1 -0
- package/dist/structured/request.js +31 -0
- package/dist/structured/request.js.map +1 -0
- package/dist/structured/response.d.ts +44 -0
- package/dist/structured/response.d.ts.map +1 -0
- package/dist/structured/response.js +49 -0
- package/dist/structured/response.js.map +1 -0
- package/dist/text/pending-request.d.ts +77 -0
- package/dist/text/pending-request.d.ts.map +1 -0
- package/dist/text/pending-request.js +189 -0
- package/dist/text/pending-request.js.map +1 -0
- package/dist/text/request.d.ts +62 -0
- package/dist/text/request.d.ts.map +1 -0
- package/dist/text/request.js +117 -0
- package/dist/text/request.js.map +1 -0
- package/dist/text/response-builder.d.ts +16 -0
- package/dist/text/response-builder.d.ts.map +1 -0
- package/dist/text/response-builder.js +52 -0
- package/dist/text/response-builder.js.map +1 -0
- package/dist/text/response.d.ts +36 -0
- package/dist/text/response.d.ts.map +1 -0
- package/dist/text/response.js +40 -0
- package/dist/text/response.js.map +1 -0
- package/dist/text/step.d.ts +41 -0
- package/dist/text/step.d.ts.map +1 -0
- package/dist/text/step.js +46 -0
- package/dist/text/step.js.map +1 -0
- package/dist/tool.d.ts +34 -0
- package/dist/tool.d.ts.map +1 -0
- package/dist/tool.js +86 -0
- package/dist/tool.js.map +1 -0
- package/dist/value-objects/artifact.d.ts +14 -0
- package/dist/value-objects/artifact.d.ts.map +1 -0
- package/dist/value-objects/artifact.js +32 -0
- package/dist/value-objects/artifact.js.map +1 -0
- package/dist/value-objects/embedding.d.ts +24 -0
- package/dist/value-objects/embedding.d.ts.map +1 -0
- package/dist/value-objects/embedding.js +29 -0
- package/dist/value-objects/embedding.js.map +1 -0
- package/dist/value-objects/embeddings-usage.d.ts +16 -0
- package/dist/value-objects/embeddings-usage.d.ts.map +1 -0
- package/dist/value-objects/embeddings-usage.js +19 -0
- package/dist/value-objects/embeddings-usage.js.map +1 -0
- package/dist/value-objects/generated-audio.d.ts +20 -0
- package/dist/value-objects/generated-audio.d.ts.map +1 -0
- package/dist/value-objects/generated-audio.js +23 -0
- package/dist/value-objects/generated-audio.js.map +1 -0
- package/dist/value-objects/generated-image.d.ts +36 -0
- package/dist/value-objects/generated-image.d.ts.map +1 -0
- package/dist/value-objects/generated-image.js +35 -0
- package/dist/value-objects/generated-image.js.map +1 -0
- package/dist/value-objects/index.d.ts +13 -0
- package/dist/value-objects/index.d.ts.map +1 -0
- package/dist/value-objects/index.js +10 -0
- package/dist/value-objects/index.js.map +1 -0
- package/dist/value-objects/media/audio.d.ts +8 -0
- package/dist/value-objects/media/audio.d.ts.map +1 -0
- package/dist/value-objects/media/audio.js +9 -0
- package/dist/value-objects/media/audio.js.map +1 -0
- package/dist/value-objects/media/document.d.ts +44 -0
- package/dist/value-objects/media/document.d.ts.map +1 -0
- package/dist/value-objects/media/document.js +75 -0
- package/dist/value-objects/media/document.js.map +1 -0
- package/dist/value-objects/media/image.d.ts +13 -0
- package/dist/value-objects/media/image.d.ts.map +1 -0
- package/dist/value-objects/media/image.js +14 -0
- package/dist/value-objects/media/image.js.map +1 -0
- package/dist/value-objects/media/media.d.ts +119 -0
- package/dist/value-objects/media/media.d.ts.map +1 -0
- package/dist/value-objects/media/media.js +267 -0
- package/dist/value-objects/media/media.js.map +1 -0
- package/dist/value-objects/media/part.d.ts +25 -0
- package/dist/value-objects/media/part.d.ts.map +1 -0
- package/dist/value-objects/media/part.js +41 -0
- package/dist/value-objects/media/part.js.map +1 -0
- package/dist/value-objects/media/text.d.ts +24 -0
- package/dist/value-objects/media/text.d.ts.map +1 -0
- package/dist/value-objects/media/text.js +33 -0
- package/dist/value-objects/media/text.js.map +1 -0
- package/dist/value-objects/media/video.d.ts +7 -0
- package/dist/value-objects/media/video.d.ts.map +1 -0
- package/dist/value-objects/media/video.js +8 -0
- package/dist/value-objects/media/video.js.map +1 -0
- package/dist/value-objects/messages/assistant-message.d.ts +26 -0
- package/dist/value-objects/messages/assistant-message.d.ts.map +1 -0
- package/dist/value-objects/messages/assistant-message.js +37 -0
- package/dist/value-objects/messages/assistant-message.js.map +1 -0
- package/dist/value-objects/messages/index.d.ts +27 -0
- package/dist/value-objects/messages/index.d.ts.map +1 -0
- package/dist/value-objects/messages/index.js +32 -0
- package/dist/value-objects/messages/index.js.map +1 -0
- package/dist/value-objects/messages/system-message.d.ts +9 -0
- package/dist/value-objects/messages/system-message.d.ts.map +1 -0
- package/dist/value-objects/messages/system-message.js +17 -0
- package/dist/value-objects/messages/system-message.js.map +1 -0
- package/dist/value-objects/messages/tool-result-message.d.ts +14 -0
- package/dist/value-objects/messages/tool-result-message.d.ts.map +1 -0
- package/dist/value-objects/messages/tool-result-message.js +26 -0
- package/dist/value-objects/messages/tool-result-message.js.map +1 -0
- package/dist/value-objects/messages/user-message.d.ts +47 -0
- package/dist/value-objects/messages/user-message.d.ts.map +1 -0
- package/dist/value-objects/messages/user-message.js +87 -0
- package/dist/value-objects/messages/user-message.js.map +1 -0
- package/dist/value-objects/meta.d.ts +12 -0
- package/dist/value-objects/meta.d.ts.map +1 -0
- package/dist/value-objects/meta.js +28 -0
- package/dist/value-objects/meta.js.map +1 -0
- package/dist/value-objects/moderation-result.d.ts +20 -0
- package/dist/value-objects/moderation-result.d.ts.map +1 -0
- package/dist/value-objects/moderation-result.js +64 -0
- package/dist/value-objects/moderation-result.js.map +1 -0
- package/dist/value-objects/provider-rate-limit.d.ts +11 -0
- package/dist/value-objects/provider-rate-limit.d.ts.map +1 -0
- package/dist/value-objects/provider-rate-limit.js +34 -0
- package/dist/value-objects/provider-rate-limit.js.map +1 -0
- package/dist/value-objects/provider-tool.d.ts +19 -0
- package/dist/value-objects/provider-tool.d.ts.map +1 -0
- package/dist/value-objects/provider-tool.js +31 -0
- package/dist/value-objects/provider-tool.js.map +1 -0
- package/dist/value-objects/tool-call.d.ts +29 -0
- package/dist/value-objects/tool-call.d.ts.map +1 -0
- package/dist/value-objects/tool-call.js +112 -0
- package/dist/value-objects/tool-call.js.map +1 -0
- package/dist/value-objects/tool-result.d.ts +25 -0
- package/dist/value-objects/tool-result.d.ts.map +1 -0
- package/dist/value-objects/tool-result.js +45 -0
- package/dist/value-objects/tool-result.js.map +1 -0
- package/dist/value-objects/usage.d.ts +13 -0
- package/dist/value-objects/usage.d.ts.map +1 -0
- package/dist/value-objects/usage.js +31 -0
- package/dist/value-objects/usage.js.map +1 -0
- package/package.json +46 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Map tools onto Mistral's `tools` array.
|
|
3
|
+
*
|
|
4
|
+
* The chat-completions shape: a `function` object nested under a `type`, where
|
|
5
|
+
* the Responses API flattens the same fields to the top level. `parameters` is
|
|
6
|
+
* always sent, even empty — Mistral rejects a function declaration without one,
|
|
7
|
+
* unlike OpenAI which treats it as optional.
|
|
8
|
+
*
|
|
9
|
+
* Declaration order is preserved. Tool order reaches the model and influences
|
|
10
|
+
* which tool it picks.
|
|
11
|
+
*/
|
|
12
|
+
export function mapTools(tools) {
|
|
13
|
+
return tools.map((tool) => ({
|
|
14
|
+
type: 'function',
|
|
15
|
+
function: {
|
|
16
|
+
name: tool.name(),
|
|
17
|
+
description: tool.description(),
|
|
18
|
+
parameters: {
|
|
19
|
+
type: 'object',
|
|
20
|
+
properties: tool.hasParameters() ? tool.parametersAsObject() : {},
|
|
21
|
+
required: [...tool.requiredParameters()],
|
|
22
|
+
},
|
|
23
|
+
},
|
|
24
|
+
}));
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=tool-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tool-map.js","sourceRoot":"","sources":["../../../../src/providers/mistral/maps/tool-map.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;GAUG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAsB;IAC7C,OAAO,KAAK,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;QAC1B,IAAI,EAAE,UAAU;QAChB,QAAQ,EAAE;YACR,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE;YACjB,WAAW,EAAE,IAAI,CAAC,WAAW,EAAE;YAC/B,UAAU,EAAE;gBACV,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE,IAAI,CAAC,aAAa,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,kBAAkB,EAAE,CAAC,CAAC,CAAC,EAAE;gBACjE,QAAQ,EAAE,CAAC,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;aACzC;SACF;KACF,CAAC,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import type { EmbeddingsRequest } from '../../embeddings/request.js';
|
|
2
|
+
import type { EmbeddingsResponse } from '../../embeddings/response.js';
|
|
3
|
+
import type { FimRequest } from '../../fim/request.js';
|
|
4
|
+
import type { FimResponse } from '../../fim/response.js';
|
|
5
|
+
import type { SpeechToTextRequest } from '../../audio/request.js';
|
|
6
|
+
import type { AudioTextResponse } from '../../audio/response.js';
|
|
7
|
+
import type { StructuredRequest } from '../../structured/request.js';
|
|
8
|
+
import type { StructuredResponse } from '../../structured/response.js';
|
|
9
|
+
import type { HttpBinaryTransport, HttpStreamTransport, HttpTransport } from '../../http/transport.js';
|
|
10
|
+
import type { StreamEvent } from '../../streaming/events.js';
|
|
11
|
+
import type { TextRequest } from '../../text/request.js';
|
|
12
|
+
import type { TextResponse } from '../../text/response.js';
|
|
13
|
+
import { Provider } from '../provider.js';
|
|
14
|
+
export interface MistralConfig {
|
|
15
|
+
apiKey?: string;
|
|
16
|
+
url?: string;
|
|
17
|
+
transport?: HttpTransport;
|
|
18
|
+
streamTransport?: HttpStreamTransport;
|
|
19
|
+
binaryTransport?: HttpBinaryTransport;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The Mistral provider.
|
|
23
|
+
*
|
|
24
|
+
* The third provider in this port, and the first that is neither OpenAI's
|
|
25
|
+
* Responses API nor Anthropic's Messages API: Mistral speaks the OpenAI
|
|
26
|
+
* CHAT-COMPLETIONS shape. That is close enough to be worth stating plainly,
|
|
27
|
+
* because the temptation to share the OpenAI mapper is real and wrong — the two
|
|
28
|
+
* disagree on the request envelope (`messages` vs `input`), on where the finish
|
|
29
|
+
* reason lives (the choice vs the root), and on the tool-call argument encoding
|
|
30
|
+
* (a JSON string vs an object). Every one of those fails quietly.
|
|
31
|
+
*
|
|
32
|
+
* It exists because `fim` does. Fill-in-the-middle is a Mistral-only capability
|
|
33
|
+
* in the reference, so the twelfth capability could not land in this port
|
|
34
|
+
* without it — but a provider that served only `fim` would be a provider nobody
|
|
35
|
+
* could use for anything else, so the surface the reference gives Mistral is
|
|
36
|
+
* ported whole: text, structured, stream, embeddings, fim, speechToText.
|
|
37
|
+
*/
|
|
38
|
+
export declare class Mistral extends Provider {
|
|
39
|
+
#private;
|
|
40
|
+
readonly providerName = "Mistral";
|
|
41
|
+
readonly apiKey: string;
|
|
42
|
+
readonly url: string;
|
|
43
|
+
constructor(config?: MistralConfig);
|
|
44
|
+
text(request: TextRequest): Promise<TextResponse>;
|
|
45
|
+
/**
|
|
46
|
+
* Structured output through Mistral's OWN strict schema mode.
|
|
47
|
+
*
|
|
48
|
+
* So this is enforced, not requested — the same guarantee the OpenAI path
|
|
49
|
+
* gives and stronger than the Anthropic one, which can only ask. G-08 records
|
|
50
|
+
* that `structured` means different things per provider; Mistral lands on the
|
|
51
|
+
* strong side of it.
|
|
52
|
+
*/
|
|
53
|
+
structured(request: StructuredRequest): Promise<StructuredResponse>;
|
|
54
|
+
/**
|
|
55
|
+
* Fill in the middle: a prefix, an optional suffix, and the gap between them.
|
|
56
|
+
*
|
|
57
|
+
* A DIFFERENT ENDPOINT from chat, not a mode of it — `fim/completions` takes
|
|
58
|
+
* a prompt and a suffix and has no messages at all. That is why the capability
|
|
59
|
+
* has its own builder rather than a flag on the text one.
|
|
60
|
+
*/
|
|
61
|
+
fim(request: FimRequest): Promise<FimResponse>;
|
|
62
|
+
embeddings(request: EmbeddingsRequest): Promise<EmbeddingsResponse>;
|
|
63
|
+
/**
|
|
64
|
+
* Transcription, sharing the OpenAI multipart form.
|
|
65
|
+
*
|
|
66
|
+
* SHARED DELIBERATELY, unlike the chat mapping. Mistral's
|
|
67
|
+
* `audio/transcriptions` is the Whisper endpoint shape field for field — a
|
|
68
|
+
* `file` part plus `model`, `language`, `prompt`, `response_format` and
|
|
69
|
+
* `temperature` — so a second copy would be a copy, and the two would drift
|
|
70
|
+
* on whichever one someone edited. The chat endpoints are not shared for the
|
|
71
|
+
* opposite reason: they only look alike.
|
|
72
|
+
*/
|
|
73
|
+
speechToText(request: SpeechToTextRequest): Promise<AudioTextResponse>;
|
|
74
|
+
/**
|
|
75
|
+
* The same generation, delivered as it arrives.
|
|
76
|
+
*
|
|
77
|
+
* The mapper is constructed PER CALL. It carries the message id, the
|
|
78
|
+
* accumulated text and half-assembled tool-call arguments for one stream; a
|
|
79
|
+
* shared instance would let two concurrent generations read each other's
|
|
80
|
+
* fragments.
|
|
81
|
+
*
|
|
82
|
+
* A chunk can produce SEVERAL events — the first carries both the stream
|
|
83
|
+
* start and the first token — so the mapper returns a list and this yields
|
|
84
|
+
* every member. Taking only the first would drop tokens silently.
|
|
85
|
+
*/
|
|
86
|
+
stream(request: TextRequest): AsyncGenerator<StreamEvent>;
|
|
87
|
+
/** A bearer token, like OpenAI and unlike Anthropic's `x-api-key`. */
|
|
88
|
+
headers(): Record<string, string>;
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=mistral.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mistral.d.ts","sourceRoot":"","sources":["../../../src/providers/mistral/mistral.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AACvE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,6BAA6B,CAAC;AACrE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAEvE,OAAO,KAAK,EAAE,mBAAmB,EAAE,mBAAmB,EA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,EAAE,MAAM,CAAC;CAmClC"}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
import { canonicalJson, isJsonObject } from '../../json.js';
|
|
2
|
+
import { PrismError } from '../../errors.js';
|
|
3
|
+
import { structuredFromTextResponse } from '../../structured/from-text.js';
|
|
4
|
+
import { fetchBinaryTransport, fetchStreamTransport, fetchTransport } from '../../http/transport.js';
|
|
5
|
+
import { sseData } from '../../streaming/sse.js';
|
|
6
|
+
import { Provider } from '../provider.js';
|
|
7
|
+
import { buildRequestBody, buildStructuredBody } from './build-request-body.js';
|
|
8
|
+
import { buildEmbeddingsBody, parseEmbeddingsResponse } from './embeddings.js';
|
|
9
|
+
import { buildFimBody, parseFimResponse } from './fim.js';
|
|
10
|
+
import { parseTextResponse } from './parse-response.js';
|
|
11
|
+
import { parseRateLimits } from './rate-limits.js';
|
|
12
|
+
import { MistralStreamMapper } from './stream-events.js';
|
|
13
|
+
import { buildTranscriptionForm, parseTranscriptionResponse } from '../openai/audio.js';
|
|
14
|
+
const DEFAULT_URL = 'https://api.mistral.ai/v1';
|
|
15
|
+
/**
|
|
16
|
+
* The Mistral provider.
|
|
17
|
+
*
|
|
18
|
+
* The third provider in this port, and the first that is neither OpenAI's
|
|
19
|
+
* Responses API nor Anthropic's Messages API: Mistral speaks the OpenAI
|
|
20
|
+
* CHAT-COMPLETIONS shape. That is close enough to be worth stating plainly,
|
|
21
|
+
* because the temptation to share the OpenAI mapper is real and wrong — the two
|
|
22
|
+
* disagree on the request envelope (`messages` vs `input`), on where the finish
|
|
23
|
+
* reason lives (the choice vs the root), and on the tool-call argument encoding
|
|
24
|
+
* (a JSON string vs an object). Every one of those fails quietly.
|
|
25
|
+
*
|
|
26
|
+
* It exists because `fim` does. Fill-in-the-middle is a Mistral-only capability
|
|
27
|
+
* in the reference, so the twelfth capability could not land in this port
|
|
28
|
+
* without it — but a provider that served only `fim` would be a provider nobody
|
|
29
|
+
* could use for anything else, so the surface the reference gives Mistral is
|
|
30
|
+
* ported whole: text, structured, stream, embeddings, fim, speechToText.
|
|
31
|
+
*/
|
|
32
|
+
export class Mistral extends Provider {
|
|
33
|
+
providerName = 'Mistral';
|
|
34
|
+
apiKey;
|
|
35
|
+
url;
|
|
36
|
+
#transport;
|
|
37
|
+
#streamTransport;
|
|
38
|
+
#binaryTransport;
|
|
39
|
+
constructor(config = {}) {
|
|
40
|
+
super();
|
|
41
|
+
this.apiKey = config.apiKey ?? readEnv('MISTRAL_API_KEY') ?? '';
|
|
42
|
+
this.url = (config.url ?? readEnv('MISTRAL_URL') ?? DEFAULT_URL).replace(/\/+$/, '');
|
|
43
|
+
this.#transport = config.transport ?? fetchTransport;
|
|
44
|
+
this.#streamTransport = config.streamTransport ?? fetchStreamTransport;
|
|
45
|
+
this.#binaryTransport = config.binaryTransport ?? fetchBinaryTransport;
|
|
46
|
+
}
|
|
47
|
+
async text(request) {
|
|
48
|
+
const response = await this.#post('chat/completions', canonicalJson(buildRequestBody(request)), request.clientOptions());
|
|
49
|
+
return parseTextResponse(request, response.body, { rateLimits: parseRateLimits(response.headers) });
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Structured output through Mistral's OWN strict schema mode.
|
|
53
|
+
*
|
|
54
|
+
* So this is enforced, not requested — the same guarantee the OpenAI path
|
|
55
|
+
* gives and stronger than the Anthropic one, which can only ask. G-08 records
|
|
56
|
+
* that `structured` means different things per provider; Mistral lands on the
|
|
57
|
+
* strong side of it.
|
|
58
|
+
*/
|
|
59
|
+
async structured(request) {
|
|
60
|
+
const response = await this.#post('chat/completions', canonicalJson(buildStructuredBody(request)), request.clientOptions());
|
|
61
|
+
return structuredFromTextResponse(parseTextResponse(request, response.body, { rateLimits: parseRateLimits(response.headers) }));
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Fill in the middle: a prefix, an optional suffix, and the gap between them.
|
|
65
|
+
*
|
|
66
|
+
* A DIFFERENT ENDPOINT from chat, not a mode of it — `fim/completions` takes
|
|
67
|
+
* a prompt and a suffix and has no messages at all. That is why the capability
|
|
68
|
+
* has its own builder rather than a flag on the text one.
|
|
69
|
+
*/
|
|
70
|
+
async fim(request) {
|
|
71
|
+
const response = await this.#post('fim/completions', canonicalJson(buildFimBody(request)), request.clientOptions());
|
|
72
|
+
return parseFimResponse(response.body, request, parseRateLimits(response.headers));
|
|
73
|
+
}
|
|
74
|
+
async embeddings(request) {
|
|
75
|
+
const response = await this.#post('embeddings', canonicalJson(buildEmbeddingsBody(request)), request.clientOptions());
|
|
76
|
+
return parseEmbeddingsResponse(response.body);
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Transcription, sharing the OpenAI multipart form.
|
|
80
|
+
*
|
|
81
|
+
* SHARED DELIBERATELY, unlike the chat mapping. Mistral's
|
|
82
|
+
* `audio/transcriptions` is the Whisper endpoint shape field for field — a
|
|
83
|
+
* `file` part plus `model`, `language`, `prompt`, `response_format` and
|
|
84
|
+
* `temperature` — so a second copy would be a copy, and the two would drift
|
|
85
|
+
* on whichever one someone edited. The chat endpoints are not shared for the
|
|
86
|
+
* opposite reason: they only look alike.
|
|
87
|
+
*/
|
|
88
|
+
async speechToText(request) {
|
|
89
|
+
const response = await this.#binaryTransport({
|
|
90
|
+
url: `${this.url}/audio/transcriptions`,
|
|
91
|
+
method: 'POST',
|
|
92
|
+
headers: this.headers(),
|
|
93
|
+
body: '',
|
|
94
|
+
multipart: buildTranscriptionForm(request),
|
|
95
|
+
clientOptions: request.clientOptions(),
|
|
96
|
+
});
|
|
97
|
+
const decoded = decodeJson(response.bytes);
|
|
98
|
+
if (response.status >= 400) {
|
|
99
|
+
throw PrismError.providerResponseError(describeHttpFailure(this.providerName, response.status, decoded), {
|
|
100
|
+
httpStatus: response.status,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
return parseTranscriptionResponse(decoded);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* The same generation, delivered as it arrives.
|
|
107
|
+
*
|
|
108
|
+
* The mapper is constructed PER CALL. It carries the message id, the
|
|
109
|
+
* accumulated text and half-assembled tool-call arguments for one stream; a
|
|
110
|
+
* shared instance would let two concurrent generations read each other's
|
|
111
|
+
* fragments.
|
|
112
|
+
*
|
|
113
|
+
* A chunk can produce SEVERAL events — the first carries both the stream
|
|
114
|
+
* start and the first token — so the mapper returns a list and this yields
|
|
115
|
+
* every member. Taking only the first would drop tokens silently.
|
|
116
|
+
*/
|
|
117
|
+
async *stream(request) {
|
|
118
|
+
const response = await this.#streamTransport({
|
|
119
|
+
url: `${this.url}/chat/completions`,
|
|
120
|
+
method: 'POST',
|
|
121
|
+
headers: { ...this.headers(), Accept: 'text/event-stream' },
|
|
122
|
+
body: canonicalJson({ ...buildRequestBody(request), stream: true }),
|
|
123
|
+
clientOptions: request.clientOptions(),
|
|
124
|
+
});
|
|
125
|
+
if (response.status >= 400) {
|
|
126
|
+
let raw = '';
|
|
127
|
+
for await (const chunk of response.chunks) {
|
|
128
|
+
raw += chunk;
|
|
129
|
+
}
|
|
130
|
+
throw PrismError.providerResponseError(describeHttpFailure(this.providerName, response.status, parsePayload(raw)), { httpStatus: response.status });
|
|
131
|
+
}
|
|
132
|
+
const mapper = new MistralStreamMapper();
|
|
133
|
+
for await (const payload of sseData(response.chunks)) {
|
|
134
|
+
// Mistral closes with a literal `[DONE]`, which is not JSON. Parsing it
|
|
135
|
+
// yields null and the mapper would read an empty payload as a chunk.
|
|
136
|
+
if (payload === '[DONE]') {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
for (const event of mapper.map(parsePayload(payload))) {
|
|
140
|
+
yield event;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
/** A bearer token, like OpenAI and unlike Anthropic's `x-api-key`. */
|
|
145
|
+
headers() {
|
|
146
|
+
const headers = {
|
|
147
|
+
'Content-Type': 'application/json',
|
|
148
|
+
Accept: 'application/json',
|
|
149
|
+
};
|
|
150
|
+
if (this.apiKey !== '') {
|
|
151
|
+
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
152
|
+
}
|
|
153
|
+
return headers;
|
|
154
|
+
}
|
|
155
|
+
async #post(path, body, clientOptions) {
|
|
156
|
+
const response = await this.#transport({
|
|
157
|
+
url: `${this.url}/${path}`,
|
|
158
|
+
method: 'POST',
|
|
159
|
+
headers: this.headers(),
|
|
160
|
+
body,
|
|
161
|
+
clientOptions,
|
|
162
|
+
});
|
|
163
|
+
if (response.status >= 400) {
|
|
164
|
+
throw PrismError.providerResponseError(describeHttpFailure(this.providerName, response.status, response.body), {
|
|
165
|
+
httpStatus: response.status,
|
|
166
|
+
responseBody: response.rawBody,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
return { body: response.body, headers: response.headers };
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function readEnv(name) {
|
|
173
|
+
const value = process.env[name];
|
|
174
|
+
return value === undefined || value === '' ? undefined : value;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* A message out of either error shape Mistral uses.
|
|
178
|
+
*
|
|
179
|
+
* A nested `error.message` on most failures, and a BARE `message` on validation
|
|
180
|
+
* errors — the second is what a malformed request actually gets, so reading
|
|
181
|
+
* only the first reports "Unknown error" for the most common mistake.
|
|
182
|
+
*/
|
|
183
|
+
function describeHttpFailure(provider, status, body) {
|
|
184
|
+
if (!isJsonObject(body)) {
|
|
185
|
+
return `${provider} error [${status}]: Unknown error`;
|
|
186
|
+
}
|
|
187
|
+
const error = isJsonObject(body.error) ? body.error : null;
|
|
188
|
+
const detail = (error !== null && typeof error.message === 'string' ? error.message : null) ??
|
|
189
|
+
(typeof body.message === 'string' ? body.message : null) ??
|
|
190
|
+
'Unknown error';
|
|
191
|
+
return `${provider} error [${status}]: ${detail}`;
|
|
192
|
+
}
|
|
193
|
+
function parsePayload(payload) {
|
|
194
|
+
try {
|
|
195
|
+
const parsed = JSON.parse(payload);
|
|
196
|
+
return isJsonObject(parsed) ? parsed : {};
|
|
197
|
+
}
|
|
198
|
+
catch {
|
|
199
|
+
return {};
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
function decodeJson(bytes) {
|
|
203
|
+
try {
|
|
204
|
+
return JSON.parse(new TextDecoder().decode(bytes));
|
|
205
|
+
}
|
|
206
|
+
catch {
|
|
207
|
+
return null;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
//# sourceMappingURL=mistral.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mistral.js","sourceRoot":"","sources":["../../../src/providers/mistral/mistral.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAE5D,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAS7C,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAE3E,OAAO,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAErG,OAAO,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAGjD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,gBAAgB,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC;AAChF,OAAO,EAAE,mBAAmB,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC1D,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,0BAA0B,EAAE,MAAM,oBAAoB,CAAC;AAUxF,MAAM,WAAW,GAAG,2BAA2B,CAAC;AAEhD;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,OAAO,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AU,CAAC,KAAiB;IACnC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;IACrD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAC;IACd,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { JsonObject } from '../../json.js';
|
|
2
|
+
import type { TextRequest } from '../../text/request.js';
|
|
3
|
+
import type { TextResponse } from '../../text/response.js';
|
|
4
|
+
import type { ProviderRateLimit } from '../../value-objects/provider-rate-limit.js';
|
|
5
|
+
export interface ParseTextResponseOptions {
|
|
6
|
+
rateLimits?: readonly ProviderRateLimit[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Turn a raw Mistral chat-completions payload into a `TextResponse`.
|
|
10
|
+
*
|
|
11
|
+
* No HTTP happens here, so a stored payload replays through exactly the code
|
|
12
|
+
* path a live call takes.
|
|
13
|
+
*
|
|
14
|
+
* @throws PrismError code `provider_response_error` when the payload is
|
|
15
|
+
* missing, empty, or carries a `message` under an error shape.
|
|
16
|
+
* @throws PrismError code `max_tokens_exceeded` when generation was cut short.
|
|
17
|
+
* @throws PrismError code `tool_loop_not_supported` when the response stopped
|
|
18
|
+
* on tool calls. Running tools is outside this port's slice, and returning a
|
|
19
|
+
* half-formed response would be worse than saying so.
|
|
20
|
+
*/
|
|
21
|
+
export declare function parseTextResponse(request: TextRequest, rawBody: unknown, options?: ParseTextResponseOptions): TextResponse;
|
|
22
|
+
export declare function validateResponse(rawBody: unknown): JsonObject;
|
|
23
|
+
/** The first choice, or an empty object. Mistral returns one unless `n` was set. */
|
|
24
|
+
export declare function firstChoiceMessage(data: JsonObject): JsonObject;
|
|
25
|
+
/**
|
|
26
|
+
* The reply text, from either shape Mistral uses.
|
|
27
|
+
*
|
|
28
|
+
* `content` is usually a string, but reasoning models return an ARRAY of typed
|
|
29
|
+
* chunks — and taking the array's `toString()` yields `[object Object]`, which
|
|
30
|
+
* looks like a model that answered nonsense rather than a parser that failed.
|
|
31
|
+
*/
|
|
32
|
+
export declare function extractText(message: JsonObject): string;
|
|
33
|
+
/** Reasoning chunks joined, or null when the model did not think. */
|
|
34
|
+
export declare function extractThinking(message: JsonObject): string | null;
|
|
35
|
+
//# sourceMappingURL=parse-response.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-response.d.ts","sourceRoot":"","sources":["../../../src/providers/mistral/parse-response.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAKhD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAG3D,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AAKpF,MAAM,WAAW,wBAAwB;IACvC,UAAU,CAAC,EAAE,SAAS,iBAAiB,EAAE,CAAC;CAC3C;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,WAAW,EACpB,OAAO,EAAE,OAAO,EAChB,OAAO,GAAE,wBAA6B,GACrC,YAAY,CAiBd;AAED,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,UAAU,CAwB7D;AAED,oFAAoF;AACpF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAI/D;AA8BD;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,CAUvD;AAED,qEAAqE;AACrE,wBAAgB,eAAe,CAAC,OAAO,EAAE,UAAU,GAAG,MAAM,GAAG,IAAI,CAUlE"}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { isJsonObject } from '../../json.js';
|
|
2
|
+
import { PrismError } from '../../errors.js';
|
|
3
|
+
import { FinishReason } from '../../enums.js';
|
|
4
|
+
import { readArray, readNullableNumber, readNumber, readObject, readString, whereNotNull } from '../../internal/filters.js';
|
|
5
|
+
import { ResponseBuilder } from '../../text/response-builder.js';
|
|
6
|
+
import { TextStep } from '../../text/step.js';
|
|
7
|
+
import { Meta } from '../../value-objects/meta.js';
|
|
8
|
+
import { ToolCall } from '../../value-objects/tool-call.js';
|
|
9
|
+
import { Usage } from '../../value-objects/usage.js';
|
|
10
|
+
import { mapFinishReason } from './maps/finish-reason-map.js';
|
|
11
|
+
/**
|
|
12
|
+
* Turn a raw Mistral chat-completions payload into a `TextResponse`.
|
|
13
|
+
*
|
|
14
|
+
* No HTTP happens here, so a stored payload replays through exactly the code
|
|
15
|
+
* path a live call takes.
|
|
16
|
+
*
|
|
17
|
+
* @throws PrismError code `provider_response_error` when the payload is
|
|
18
|
+
* missing, empty, or carries a `message` under an error shape.
|
|
19
|
+
* @throws PrismError code `max_tokens_exceeded` when generation was cut short.
|
|
20
|
+
* @throws PrismError code `tool_loop_not_supported` when the response stopped
|
|
21
|
+
* on tool calls. Running tools is outside this port's slice, and returning a
|
|
22
|
+
* half-formed response would be worse than saying so.
|
|
23
|
+
*/
|
|
24
|
+
export function parseTextResponse(request, rawBody, options = {}) {
|
|
25
|
+
const data = validateResponse(rawBody);
|
|
26
|
+
const finishReason = mapFinishReason(data);
|
|
27
|
+
if (finishReason === FinishReason.ToolCalls) {
|
|
28
|
+
throw PrismError.toolLoopNotSupported();
|
|
29
|
+
}
|
|
30
|
+
if (finishReason === FinishReason.Length) {
|
|
31
|
+
throw PrismError.maxTokensExceeded('length', 'chat.completion');
|
|
32
|
+
}
|
|
33
|
+
const builder = new ResponseBuilder();
|
|
34
|
+
builder.addStep(buildStep(data, request, finishReason, options.rateLimits ?? []));
|
|
35
|
+
return builder.toResponse();
|
|
36
|
+
}
|
|
37
|
+
export function validateResponse(rawBody) {
|
|
38
|
+
if (!isJsonObject(rawBody) || Object.keys(rawBody).length === 0) {
|
|
39
|
+
throw PrismError.providerResponseError('Mistral returned an empty or non-object response body.');
|
|
40
|
+
}
|
|
41
|
+
// Mistral reports failures two ways: an `object: "error"` envelope, and a
|
|
42
|
+
// bare `{ message, type }` on validation errors. Both are checked, because
|
|
43
|
+
// only the first carries a recognisable marker and the second is what a
|
|
44
|
+
// malformed request actually gets back.
|
|
45
|
+
const error = readObject(rawBody.error);
|
|
46
|
+
if (error !== null) {
|
|
47
|
+
throw PrismError.providerResponseError(`Mistral error [${readString(error.type, 'unknown')}]: ${readString(error.message, 'unknown')}`);
|
|
48
|
+
}
|
|
49
|
+
if (rawBody.object === 'error' || (typeof rawBody.message === 'string' && rawBody.choices === undefined)) {
|
|
50
|
+
throw PrismError.providerResponseError(`Mistral error [${readString(rawBody.type, 'unknown')}]: ${readString(rawBody.message, 'unknown')}`);
|
|
51
|
+
}
|
|
52
|
+
return rawBody;
|
|
53
|
+
}
|
|
54
|
+
/** The first choice, or an empty object. Mistral returns one unless `n` was set. */
|
|
55
|
+
export function firstChoiceMessage(data) {
|
|
56
|
+
const choice = readArray(data.choices)[0];
|
|
57
|
+
return isJsonObject(choice) ? (readObject(choice.message) ?? {}) : {};
|
|
58
|
+
}
|
|
59
|
+
function buildStep(data, request, finishReason, rateLimits) {
|
|
60
|
+
const message = firstChoiceMessage(data);
|
|
61
|
+
const usage = readObject(data.usage) ?? {};
|
|
62
|
+
return new TextStep({
|
|
63
|
+
text: extractText(message),
|
|
64
|
+
finishReason,
|
|
65
|
+
toolCalls: mapToolCalls(message),
|
|
66
|
+
usage: new Usage(readNumber(usage.prompt_tokens, 0), readNumber(usage.completion_tokens, 0), null, null, readNullableNumber(usage.reasoning_tokens)),
|
|
67
|
+
meta: new Meta(readString(data.id, ''), readString(data.model, ''), rateLimits, null),
|
|
68
|
+
messages: request.messages(),
|
|
69
|
+
systemPrompts: request.systemPrompts(),
|
|
70
|
+
additionalContent: whereNotNull({ thinking: extractThinking(message) }),
|
|
71
|
+
raw: data,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* The reply text, from either shape Mistral uses.
|
|
76
|
+
*
|
|
77
|
+
* `content` is usually a string, but reasoning models return an ARRAY of typed
|
|
78
|
+
* chunks — and taking the array's `toString()` yields `[object Object]`, which
|
|
79
|
+
* looks like a model that answered nonsense rather than a parser that failed.
|
|
80
|
+
*/
|
|
81
|
+
export function extractText(message) {
|
|
82
|
+
if (typeof message.content === 'string') {
|
|
83
|
+
return message.content;
|
|
84
|
+
}
|
|
85
|
+
return readArray(message.content)
|
|
86
|
+
.filter(isJsonObject)
|
|
87
|
+
.filter((chunk) => chunk.type === 'text')
|
|
88
|
+
.map((chunk) => readString(chunk.text, ''))
|
|
89
|
+
.join('');
|
|
90
|
+
}
|
|
91
|
+
/** Reasoning chunks joined, or null when the model did not think. */
|
|
92
|
+
export function extractThinking(message) {
|
|
93
|
+
const parts = readArray(message.content)
|
|
94
|
+
.filter(isJsonObject)
|
|
95
|
+
.filter((chunk) => chunk.type === 'thinking')
|
|
96
|
+
.flatMap((chunk) => readArray(chunk.thinking))
|
|
97
|
+
.filter(isJsonObject)
|
|
98
|
+
.map((part) => readString(part.text, ''))
|
|
99
|
+
.filter((text) => text !== '');
|
|
100
|
+
return parts.length > 0 ? parts.join('') : null;
|
|
101
|
+
}
|
|
102
|
+
function mapToolCalls(message) {
|
|
103
|
+
return readArray(message.tool_calls)
|
|
104
|
+
.filter(isJsonObject)
|
|
105
|
+
.map((call) => {
|
|
106
|
+
const fn = readObject(call.function) ?? {};
|
|
107
|
+
return new ToolCall(readString(call.id, ''), readString(fn.name, ''),
|
|
108
|
+
// A JSON STRING on the wire, like OpenAI's chat completions and unlike
|
|
109
|
+
// Anthropic's decoded object. Kept as the string; `parsedArguments()`
|
|
110
|
+
// is the one place it is decoded.
|
|
111
|
+
typeof fn.arguments === 'string' ? fn.arguments : isJsonObject(fn.arguments) ? fn.arguments : '{}', null);
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
//# sourceMappingURL=parse-response.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse-response.js","sourceRoot":"","sources":["../../../src/providers/mistral/parse-response.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAC7C,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE5H,OAAO,EAAE,eAAe,EAAE,MAAM,gCAAgC,CAAC;AAEjE,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAC;AAEnD,OAAO,EAAE,QAAQ,EAAE,MAAM,kCAAkC,CAAC;AAC5D,OAAO,EAAE,KAAK,EAAE,MAAM,8BAA8B,CAAC;AACrD,OAAO,EAAE,eAAe,EAAE,MAAM,6BAA6B,CAAC;AAM9D;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,iBAAiB,CAC/B,OAAoB,EACpB,OAAgB,EAChB,UAAoC,EAAE;IAEtC,MAAM,IAAI,GAAG,gBAAgB,CAAC,OAAO,CAAC,CAAC;IACvC,MAAM,YAAY,GAAG,eAAe,CAAC,IAAI,CAAC,CAAC;IAE3C,IAAI,YAAY,KAAK,YAAY,CAAC,SAAS,EAAE,CAAC;QAC5C,MAAM,UAAU,CAAC,oBAAoB,EAAE,CAAC;IAC1C,CAAC;IAED,IAAI,YAAY,KAAK,YAAY,CAAC,MAAM,EAAE,CAAC;QACzC,MAAM,UAAU,CAAC,iBAAiB,CAAC,QAAQ,EAAE,iBAAiB,CAAC,CAAC;IAClE,CAAC;IAED,MAAM,OAAO,GAAG,IAAI,eAAe,EAAE,CAAC;IAEtC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AC,QAAQ,CAAC,IAAI,EAAE,CAAC;QAE3C,OAAO,IAAI,QAAQ,CACjB,UAAU,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,EACvB,UAAU,CAAC,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC;QACvB,uEAAuE;QACvE,sEAAsE;QACtE,kCAAkC;QAClC,OAAO,EAAE,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,YAAY,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,EAClG,IAAI,CACL,CAAC;IACJ,CAAC,CAAC,CAAC;AACP,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ProviderRateLimit } from '../../value-objects/provider-rate-limit.js';
|
|
2
|
+
/**
|
|
3
|
+
* Read Mistral's rate-limit headers.
|
|
4
|
+
*
|
|
5
|
+
* Mistral uses the `ratelimitbysize-*` family — one word, no separators, which
|
|
6
|
+
* is neither OpenAI's `x-ratelimit-*` nor Anthropic's `anthropic-ratelimit-*`.
|
|
7
|
+
*
|
|
8
|
+
* **And NO BUCKET SEGMENT.** The service sends `ratelimitbysize-limit`, not
|
|
9
|
+
* `ratelimitbysize-limit-tokens`. This reader used to expect the per-bucket
|
|
10
|
+
* suffix for `requests` and `tokens`, so a real Mistral response produced an
|
|
11
|
+
* empty array — indistinguishable from a provider that sent no quota headers at
|
|
12
|
+
* all, and silent for every call. It was caught by `prism-parity`'s
|
|
13
|
+
* `provider-rate-limits` corpus (`prl-0014`), not by this port's own tests,
|
|
14
|
+
* which fed the parser the names the parser expected; register entry G-41.
|
|
15
|
+
*
|
|
16
|
+
* Mistral meters by SIZE, so the single bucket it reports is named `tokens` —
|
|
17
|
+
* which is what the reference names it, what the reference's own `MistralTextTest`
|
|
18
|
+
* asserts against, and what `prism-py` reads.
|
|
19
|
+
*
|
|
20
|
+
* The reset is a DURATION IN SECONDS, not a timestamp and not OpenAI's `1m30s`
|
|
21
|
+
* string, so it is added to now rather than parsed as a date.
|
|
22
|
+
*/
|
|
23
|
+
export declare function parseRateLimits(headers: Readonly<Record<string, string>>): ProviderRateLimit[];
|
|
24
|
+
//# sourceMappingURL=rate-limits.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limits.d.ts","sourceRoot":"","sources":["../../../src/providers/mistral/rate-limits.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,4CAA4C,CAAC;AAG/E;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,iBAAiB,EAAE,CA0B9F"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ProviderRateLimit } from '../../value-objects/provider-rate-limit.js';
|
|
2
|
+
import { foldHeaderNames } from '../../http/header-names.js';
|
|
3
|
+
/**
|
|
4
|
+
* Read Mistral's rate-limit headers.
|
|
5
|
+
*
|
|
6
|
+
* Mistral uses the `ratelimitbysize-*` family — one word, no separators, which
|
|
7
|
+
* is neither OpenAI's `x-ratelimit-*` nor Anthropic's `anthropic-ratelimit-*`.
|
|
8
|
+
*
|
|
9
|
+
* **And NO BUCKET SEGMENT.** The service sends `ratelimitbysize-limit`, not
|
|
10
|
+
* `ratelimitbysize-limit-tokens`. This reader used to expect the per-bucket
|
|
11
|
+
* suffix for `requests` and `tokens`, so a real Mistral response produced an
|
|
12
|
+
* empty array — indistinguishable from a provider that sent no quota headers at
|
|
13
|
+
* all, and silent for every call. It was caught by `prism-parity`'s
|
|
14
|
+
* `provider-rate-limits` corpus (`prl-0014`), not by this port's own tests,
|
|
15
|
+
* which fed the parser the names the parser expected; register entry G-41.
|
|
16
|
+
*
|
|
17
|
+
* Mistral meters by SIZE, so the single bucket it reports is named `tokens` —
|
|
18
|
+
* which is what the reference names it, what the reference's own `MistralTextTest`
|
|
19
|
+
* asserts against, and what `prism-py` reads.
|
|
20
|
+
*
|
|
21
|
+
* The reset is a DURATION IN SECONDS, not a timestamp and not OpenAI's `1m30s`
|
|
22
|
+
* string, so it is added to now rather than parsed as a date.
|
|
23
|
+
*/
|
|
24
|
+
export function parseRateLimits(headers) {
|
|
25
|
+
// Folded first: HTTP field names are case-insensitive (RFC 9110 §5.1) and
|
|
26
|
+
// these are exact key lookups, so a title-casing gateway used to erase every
|
|
27
|
+
// rate limit here without a word.
|
|
28
|
+
const found = foldHeaderNames(headers);
|
|
29
|
+
const limit = found['ratelimitbysize-limit'];
|
|
30
|
+
const remaining = found['ratelimitbysize-remaining'];
|
|
31
|
+
// Only when the provider actually reported one. The reference emits this
|
|
32
|
+
// bucket unconditionally, so a response carrying no rate-limit headers comes
|
|
33
|
+
// back from it saying limit 0, remaining 0, resets now — a provider that said
|
|
34
|
+
// nothing, reported as exhausted. A caller cannot tell that apart from real
|
|
35
|
+
// exhaustion, and both readings of it are wrong.
|
|
36
|
+
if (limit === undefined || remaining === undefined) {
|
|
37
|
+
return [];
|
|
38
|
+
}
|
|
39
|
+
return [
|
|
40
|
+
new ProviderRateLimit('tokens', toInteger(limit), toInteger(remaining), resetAt(found['ratelimitbysize-reset'])),
|
|
41
|
+
];
|
|
42
|
+
}
|
|
43
|
+
function toInteger(value) {
|
|
44
|
+
const parsed = Number.parseInt(value, 10);
|
|
45
|
+
return Number.isNaN(parsed) ? 0 : parsed;
|
|
46
|
+
}
|
|
47
|
+
/** Seconds from now, or null when the header is absent or not a number. */
|
|
48
|
+
function resetAt(value) {
|
|
49
|
+
if (value === undefined) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
const seconds = Number.parseInt(value, 10);
|
|
53
|
+
return Number.isNaN(seconds) ? null : new Date(Date.now() + seconds * 1000);
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=rate-limits.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AAO,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IAE3C,OAAO,MAAM,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,OAAO,GAAG,IAAI,CAAC,CAAC;AAC9E,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { type JsonObject } from '../../json.js';
|
|
2
|
+
import { type StreamEvent } from '../../streaming/events.js';
|
|
3
|
+
/**
|
|
4
|
+
* Mistral's chat-completions stream, which needs MEMORY.
|
|
5
|
+
*
|
|
6
|
+
* Every chunk is a `chat.completion.chunk` carrying a `delta` and nothing else
|
|
7
|
+
* — no message id after the first chunk, no accumulated text, and tool-call
|
|
8
|
+
* arguments arrive SPLIT ACROSS CHUNKS keyed only by an index. So a chunk
|
|
9
|
+
* cannot be mapped in isolation, the way an OpenAI Responses event can.
|
|
10
|
+
*
|
|
11
|
+
* That puts this closer to the Anthropic mapper than to the OpenAI one, for a
|
|
12
|
+
* different provider-side reason, and it carries the same consequence: one
|
|
13
|
+
* instance per stream. A shared mapper would let two concurrent generations
|
|
14
|
+
* read each other's accumulated text, which surfaces under load and looks like
|
|
15
|
+
* the model hallucinating.
|
|
16
|
+
*/
|
|
17
|
+
export declare class MistralStreamMapper {
|
|
18
|
+
#private;
|
|
19
|
+
/**
|
|
20
|
+
* The events for one chunk — zero, one, or several.
|
|
21
|
+
*
|
|
22
|
+
* SEVERAL, unlike the other mappers' one-or-none, because a single Mistral
|
|
23
|
+
* chunk can both start the stream and carry the first token, and the final
|
|
24
|
+
* chunk can complete the text, flush a tool call and end the stream at once.
|
|
25
|
+
* Returning only the first would drop the rest silently.
|
|
26
|
+
*/
|
|
27
|
+
map(payload: JsonObject): StreamEvent[];
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=stream-events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stream-events.d.ts","sourceRoot":"","sources":["../../../src/providers/mistral/stream-events.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,eAAe,CAAC;AAG9D,OAAO,EAEL,KAAK,WAAW,EAMjB,MAAM,2BAA2B,CAAC;AAInC;;;;;;;;;;;;;GAaG;AACH,qBAAa,mBAAmB;;IAgB9B;;;;;;;OAOG;IACH,GAAG,CAAC,OAAO,EAAE,UAAU,GAAG,WAAW,EAAE;CAwFxC"}
|