@xsai-ext/providers 0.4.0-beta.12 → 0.4.0-beta.13

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/dist/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import process from 'node:process';
2
- import { c as createAlibaba, a as createAlibabaCn, b as createBailing, d as createBaseten, e as createCerebras, f as createChutes, g as createCortecs, h as createDeepinfra, i as createDeepSeek, j as createFastrouter, k as createFireworks, l as createGithubCopilot, m as createGithubModels, n as createGoogleGenerativeAI, o as createGroq, p as createHelicone, q as createHuggingface, r as createIflowcn, s as createInception, t as createInference, u as createIoNet, v as createKimiForCoding, w as createLlama, x as createLmstudio, y as createLucidquery, z as createMinimax, A as createMinimaxCn, B as createMistral, C as createModelscope, D as createMoonshotai, E as createMoonshotaiCn, F as createMorph, G as createNebius, H as createNvidia, I as createOllamaCloud, J as createOpenAI, K as createOpencode, L as createOvhcloud, M as createPerplexity, N as createPoe, O as createRequesty, P as createScaleway, Q as createSiliconFlow, R as createSiliconflowCn, S as createSubmodel, T as createSynthetic, U as createUpstage, V as createVenice, W as createVultr, X as createWandb, Y as createXai, Z as createXiaomi, _ as createZai, $ as createZaiCodingPlan, a0 as createZenmux, a1 as createZhipuai, a2 as createZhipuaiCodingPlan, a3 as createNovita, a4 as createStepfun, a5 as createTencentHunyuan, a6 as createOllama, a7 as createLitellm, a8 as createAnthropic, a9 as createFeatherless, aa as createOpenRouter, ab as createTogetherAI } from './together-ai-BNlmR9ei.js';
3
- import '@xsai-ext/shared-providers';
2
+ import { e as createAlibaba, a as createAlibabaCn, f as createBailing, g as createBaseten, h as createCerebras, i as createChutes, j as createCortecs, k as createDeepinfra, l as createDeepSeek, m as createFastrouter, n as createFireworks, o as createGithubCopilot, p as createGithubModels, q as createGoogleGenerativeAI, r as createGroq, s as createHelicone, t as createHuggingface, u as createIflowcn, v as createInception, w as createInference, x as createIoNet, y as createKimiForCoding, z as createLlama, A as createLmstudio, B as createLucidquery, C as createMinimax, d as createMinimaxCn, D as createMistral, E as createModelscope, F as createMoonshotai, G as createMoonshotaiCn, H as createMorph, I as createNebius, J as createNvidia, K as createOllamaCloud, L as createOpenAI, M as createOpencode, N as createOvhcloud, O as createPerplexity, P as createPoe, Q as createRequesty, R as createScaleway, S as createSiliconFlow, T as createSiliconflowCn, U as createSubmodel, V as createSynthetic, W as createUpstage, X as createVenice, Y as createVultr, Z as createWandb, b as createXai, _ as createXiaomi, $ as createZai, a0 as createZaiCodingPlan, a1 as createZenmux, a2 as createZhipuai, a3 as createZhipuaiCodingPlan, a4 as createNovita, a5 as createStepfun, a6 as createTencentHunyuan, a7 as createOllama, a8 as createLitellm, a9 as createAnthropic, c as createFeatherless, aa as createOpenRouter, ab as createTogetherAI } from './together-ai-D5anbRie.js';
3
+ import './utils/index.js';
4
4
  import '@xsai/shared';
5
5
 
6
6
  const alibaba = createAlibaba(process.env.DASHSCOPE_API_KEY ?? "");
@@ -0,0 +1,47 @@
1
+ import { merge, createSpeechProvider, createChatProvider } from './utils/index.js';
2
+
3
+ const createPlayer2 = (baseURL = "http://localhost:4315/v1/", gameKey = "xsai") => merge(
4
+ createChatProvider({ baseURL, headers: { "player2-game-key": gameKey } }),
5
+ createSpeechProvider({
6
+ baseURL,
7
+ fetch: async (input, reqInit) => {
8
+ const newUrl = `${input.toString().slice(0, -"audio/speech".length)}tts/speak`;
9
+ try {
10
+ const { input: input2, response_format, speed, voice, ...rest } = JSON.parse(reqInit?.body);
11
+ const modified = {
12
+ audio_format: response_format,
13
+ play_in_app: false,
14
+ speed: speed ?? 1,
15
+ text: input2,
16
+ voice_ids: voice != null ? [voice] : [],
17
+ ...rest
18
+ };
19
+ if (reqInit) {
20
+ reqInit.body = JSON.stringify(modified);
21
+ }
22
+ } catch (err) {
23
+ console.warn("Could not parse body as JSON:", err);
24
+ }
25
+ return globalThis.fetch(newUrl, reqInit).then(async (res) => res.json()).then((json) => {
26
+ const base64 = json.data ?? "";
27
+ const bytes = Uint8Array.fromBase64(base64);
28
+ const body = new ReadableStream({
29
+ start: (controller) => {
30
+ controller.enqueue(bytes);
31
+ controller.close();
32
+ }
33
+ });
34
+ return new Response(body, {
35
+ headers: {
36
+ "Content-Type": "audio/mpeg"
37
+ // adjust if needed
38
+ },
39
+ status: 200
40
+ });
41
+ });
42
+ },
43
+ headers: { "player2-game-key": gameKey }
44
+ })
45
+ );
46
+
47
+ export { createPlayer2 as c };
@@ -0,0 +1,66 @@
1
+ import { S as SpeechProvider, C as ChatProvider, E as EmbedProvider, T as TranscriptionProvider, M as ModelProvider } from '../types-DW1hvH0W.js';
2
+ import { a as AzureModels, C as CloudflareWorkersAiModels } from '../types-Czo87gCh.js';
3
+ import '@xsai/shared';
4
+
5
+ interface CreateAzureOptions {
6
+ /**
7
+ * The static API key or AD access token fetcher for authorization.
8
+ *
9
+ * If passed in as a function, it is treated as an accessTokenFetcher.
10
+ *
11
+ * @see {@link https://learn.microsoft.com/en-us/azure/api-management/api-management-authenticate-authorize-azure-openai}
12
+ */
13
+ apiKey: (() => Promise<string> | string) | string;
14
+ /**
15
+ * The Azure API version to use (`api-version` param).
16
+ *
17
+ * Notice: Different deployment over different time may have different API versions, please
18
+ * follow the exact prompt from either [Azure AI Foundry](https://ai.azure.com/) or Azure OpenAI service
19
+ * to get the correct API version from the Azure OpenAI Service endpoint.
20
+ *
21
+ * On Azure AI Foundry portal, you can go to https://ai.azure.com/build/overview > Choose the project >
22
+ * Overview > Endpoints and keys > Included capabilities > Azure OpenAI Service to get the correct endpoint.
23
+ *
24
+ * @see {@link https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#rest-api-versioning}
25
+ */
26
+ apiVersion?: string;
27
+ /**
28
+ * Azure resource name.
29
+ *
30
+ * On Azure AI Foundry portal, you can go to https://ai.azure.com/build/overview > Choose the project >
31
+ * Overview > Endpoints and keys > Included capabilities > Azure OpenAI Service to get the correct endpoint.
32
+ *
33
+ * @see {@link https://learn.microsoft.com/en-us/azure/ai-services/openai/reference#uri-parameters}
34
+ */
35
+ resourceName: string;
36
+ }
37
+ /**
38
+ * Create a Azure Provider
39
+ * @see {@link https://ai.azure.com/explore/models}
40
+ * @see {@link https://learn.microsoft.com/en-us/azure/ai-foundry/model-inference/concepts/endpoints?tabs=rest#routing}
41
+ * @remarks
42
+ * For Azure AI services, you can have multiple deployments of the same model with different names.
43
+ *
44
+ * Please pass your deployment name as the `model` parameter. By default, Azure will use the model name
45
+ * as the deployment name when deploying a model.
46
+ */
47
+ declare const createAzure: (options: CreateAzureOptions) => Promise<SpeechProvider<string> & ChatProvider<AzureModels> & EmbedProvider<string> & TranscriptionProvider<string> & ModelProvider>;
48
+
49
+ declare global {
50
+ interface Uint8ArrayConstructor {
51
+ fromBase64: (base64: string) => Uint8Array;
52
+ }
53
+ }
54
+ /**
55
+ * Create a Player2 Provider
56
+ * @see {@link https://player2.game}
57
+ */
58
+ declare const createPlayer2: (baseURL?: string, gameKey?: string) => ChatProvider<string> & SpeechProvider<string>;
59
+
60
+ /**
61
+ * Create a Workers AI Provider
62
+ * @see {@link https://developers.cloudflare.com/workers-ai}
63
+ */
64
+ declare const createWorkersAI: (apiKey: string, accountId: string) => EmbedProvider<string> & ChatProvider<CloudflareWorkersAiModels>;
65
+
66
+ export { createAzure, createPlayer2, createWorkersAI };
@@ -0,0 +1,37 @@
1
+ import { merge, createModelProvider, createTranscriptionProvider, createSpeechProvider, createEmbedProvider, createChatProvider } from '../utils/index.js';
2
+ export { c as createPlayer2 } from '../player2-D788vRq_.js';
3
+
4
+ const createAzure = async (options) => {
5
+ const headers = typeof options.apiKey === "string" ? { "api-key": options.apiKey } : void 0;
6
+ const baseURL = `https://${options.resourceName}.services.ai.azure.com/models/`;
7
+ const fetch = async (input, init) => {
8
+ if (options.apiVersion != null)
9
+ input.searchParams.set("api-version", options.apiVersion);
10
+ const token = `Bearer ${typeof options.apiKey === "function" ? await options.apiKey() : options.apiKey}`;
11
+ init.headers ??= {};
12
+ if (Array.isArray(init.headers))
13
+ init.headers.push(["Authorization", token]);
14
+ else if (init.headers instanceof Headers)
15
+ init.headers.append("Authorization", token);
16
+ else
17
+ init.headers.Authorization = token;
18
+ return globalThis.fetch(input, init);
19
+ };
20
+ return merge(
21
+ createChatProvider({ baseURL, fetch, headers }),
22
+ createEmbedProvider({ baseURL, fetch, headers }),
23
+ createSpeechProvider({ baseURL, fetch, headers }),
24
+ createTranscriptionProvider({ baseURL, fetch, headers }),
25
+ createModelProvider({ baseURL, fetch, headers })
26
+ );
27
+ };
28
+
29
+ const createWorkersAI = (apiKey, accountId) => {
30
+ const baseURL = `https://api.cloudflare.com/client/v4/accounts/${accountId}/ai/v1/`;
31
+ return merge(
32
+ createChatProvider({ apiKey, baseURL }),
33
+ createEmbedProvider({ apiKey, baseURL })
34
+ );
35
+ };
36
+
37
+ export { createAzure, createWorkersAI };
@@ -0,0 +1,12 @@
1
+ import { C as ChatProvider, S as SpeechProvider } from '../types-DW1hvH0W.js';
2
+ import '@xsai/shared';
3
+
4
+ /**
5
+ * Create a Player2 Provider
6
+ * @see {@link https://player2.game}
7
+ * @remarks
8
+ * - baseURL - `http://localhost:4315/v1/`
9
+ */
10
+ declare const player2: ChatProvider<string> & SpeechProvider<string>;
11
+
12
+ export { player2 };
@@ -0,0 +1,6 @@
1
+ import { c as createPlayer2 } from '../player2-D788vRq_.js';
2
+ import '../utils/index.js';
3
+
4
+ const player2 = createPlayer2();
5
+
6
+ export { player2 };
@@ -1,4 +1,4 @@
1
- import { merge, createChatProvider, createModelProvider, createEmbedProvider, createImageProvider, createSpeechProvider, createTranscriptionProvider, createChatProviderWithExtraOptions } from '@xsai-ext/shared-providers';
1
+ import { merge, createModelProvider, createChatProvider, createEmbedProvider, createTranscriptionProvider, createSpeechProvider, createImageProvider, createChatProviderWithExtraOptions } from './utils/index.js';
2
2
  import { objCamelToSnake } from '@xsai/shared';
3
3
 
4
4
  const createAlibaba = (apiKey, baseURL = "https://dashscope-intl.aliyuncs.com/compatible-mode/v1") => merge(
@@ -321,4 +321,4 @@ const createTogetherAI = (apiKey, baseURL = "https://api.together.xyz/v1/") => m
321
321
  })
322
322
  );
323
323
 
324
- export { createZaiCodingPlan as $, createMinimaxCn as A, createMistral as B, createModelscope as C, createMoonshotai as D, createMoonshotaiCn as E, createMorph as F, createNebius as G, createNvidia as H, createOllamaCloud as I, createOpenAI as J, createOpencode as K, createOvhcloud as L, createPerplexity as M, createPoe as N, createRequesty as O, createScaleway as P, createSiliconFlow as Q, createSiliconflowCn as R, createSubmodel as S, createSynthetic as T, createUpstage as U, createVenice as V, createVultr as W, createWandb as X, createXai as Y, createXiaomi as Z, createZai as _, createAlibabaCn as a, createZenmux as a0, createZhipuai as a1, createZhipuaiCodingPlan as a2, createNovita as a3, createStepfun as a4, createTencentHunyuan as a5, createOllama as a6, createLitellm as a7, createAnthropic as a8, createFeatherless as a9, createOpenRouter as aa, createTogetherAI as ab, createBailing as b, createAlibaba as c, createBaseten as d, createCerebras as e, createChutes as f, createCortecs as g, createDeepinfra as h, createDeepSeek as i, createFastrouter as j, createFireworks as k, createGithubCopilot as l, createGithubModels as m, createGoogleGenerativeAI as n, createGroq as o, createHelicone as p, createHuggingface as q, createIflowcn as r, createInception as s, createInference as t, createIoNet as u, createKimiForCoding as v, createLlama as w, createLmstudio as x, createLucidquery as y, createMinimax as z };
324
+ export { createZai as $, createLmstudio as A, createLucidquery as B, createMinimax as C, createMistral as D, createModelscope as E, createMoonshotai as F, createMoonshotaiCn as G, createMorph as H, createNebius as I, createNvidia as J, createOllamaCloud as K, createOpenAI as L, createOpencode as M, createOvhcloud as N, createPerplexity as O, createPoe as P, createRequesty as Q, createScaleway as R, createSiliconFlow as S, createSiliconflowCn as T, createSubmodel as U, createSynthetic as V, createUpstage as W, createVenice as X, createVultr as Y, createWandb as Z, createXiaomi as _, createAlibabaCn as a, createZaiCodingPlan as a0, createZenmux as a1, createZhipuai as a2, createZhipuaiCodingPlan as a3, createNovita as a4, createStepfun as a5, createTencentHunyuan as a6, createOllama as a7, createLitellm as a8, createAnthropic as a9, createOpenRouter as aa, createTogetherAI as ab, createXai as b, createFeatherless as c, createMinimaxCn as d, createAlibaba as e, createBailing as f, createBaseten as g, createCerebras as h, createChutes as i, createCortecs as j, createDeepinfra as k, createDeepSeek as l, createFastrouter as m, createFireworks as n, createGithubCopilot as o, createGithubModels as p, createGoogleGenerativeAI as q, createGroq as r, createHelicone as s, createHuggingface as t, createIflowcn as u, createInception as v, createInference as w, createIoNet as x, createKimiForCoding as y, createLlama as z };
@@ -1,117 +1,7 @@
1
- import * as _xsai_ext_shared_providers from '@xsai-ext/shared-providers';
2
- import { ChatProviderWithExtraOptions } from '@xsai-ext/shared-providers';
3
-
4
1
  type OpenrouterModels = 'moonshotai/kimi-k2' | 'moonshotai/kimi-k2-0905' | 'moonshotai/kimi-dev-72b:free' | 'moonshotai/kimi-k2-thinking' | 'moonshotai/kimi-k2-0905:exacto' | 'moonshotai/kimi-k2:free' | 'thudm/glm-z1-32b:free' | 'nousresearch/hermes-4-70b' | 'nousresearch/hermes-4-405b' | 'nousresearch/deephermes-3-llama-3-8b-preview' | 'nvidia/nemotron-nano-9b-v2' | 'x-ai/grok-4' | 'x-ai/grok-code-fast-1' | 'x-ai/grok-3' | 'x-ai/grok-4-fast' | 'x-ai/grok-3-beta' | 'x-ai/grok-3-mini-beta' | 'x-ai/grok-3-mini' | 'x-ai/grok-4.1-fast' | 'kwaipilot/kat-coder-pro:free' | 'cognitivecomputations/dolphin3.0-mistral-24b' | 'cognitivecomputations/dolphin3.0-r1-mistral-24b' | 'deepseek/deepseek-chat-v3.1' | 'deepseek/deepseek-r1:free' | 'deepseek/deepseek-v3.2-speciale' | 'deepseek/deepseek-v3-base:free' | 'deepseek/deepseek-v3.1-terminus' | 'deepseek/deepseek-r1-0528-qwen3-8b:free' | 'deepseek/deepseek-chat-v3-0324' | 'deepseek/deepseek-r1-0528:free' | 'deepseek/deepseek-r1-distill-llama-70b' | 'deepseek/deepseek-r1-distill-qwen-14b' | 'deepseek/deepseek-v3.1-terminus:exacto' | 'deepseek/deepseek-v3.2' | 'featherless/qwerky-72b' | 'tngtech/deepseek-r1t2-chimera:free' | 'minimax/minimax-m1' | 'minimax/minimax-m2' | 'minimax/minimax-01' | 'google/gemini-2.0-flash-001' | 'google/gemma-2-9b-it:free' | 'google/gemini-3-flash-preview' | 'google/gemini-3-pro-preview' | 'google/gemini-2.5-flash' | 'google/gemini-2.5-pro-preview-05-06' | 'google/gemma-3n-e4b-it' | 'google/gemini-2.5-flash-lite' | 'google/gemini-2.5-pro-preview-06-05' | 'google/gemini-2.5-flash-preview-09-2025' | 'google/gemini-2.5-pro' | 'google/gemma-3-12b-it' | 'google/gemma-3n-e4b-it:free' | 'google/gemini-2.5-flash-lite-preview-09-2025' | 'google/gemini-2.0-flash-exp:free' | 'google/gemma-3-27b-it' | 'microsoft/mai-ds-r1:free' | 'openai/gpt-oss-safeguard-20b' | 'openai/gpt-5.1-codex' | 'openai/gpt-4.1-mini' | 'openai/gpt-5-chat' | 'openai/gpt-5.2-pro' | 'openai/gpt-5.1-codex-mini' | 'openai/gpt-5.2-chat-latest' | 'openai/gpt-5.1' | 'openai/gpt-5-nano' | 'openai/gpt-5-codex' | 'openai/gpt-4.1' | 'openai/gpt-oss-120b:exacto' | 'openai/o4-mini' | 'openai/gpt-5.1-chat' | 'openai/gpt-5-mini' | 'openai/gpt-5-image' | 'openai/gpt-oss-20b' | 'openai/gpt-oss-120b' | 'openai/gpt-4o-mini' | 'openai/gpt-5' | 'openai/gpt-5-pro' | 'openai/gpt-5.2' | 'openrouter/sherlock-think-alpha' | 'openrouter/sherlock-dash-alpha' | 'z-ai/glm-4.5' | 'z-ai/glm-4.5-air' | 'z-ai/glm-4.5v' | 'z-ai/glm-4.6' | 'z-ai/glm-4.6:exacto' | 'z-ai/glm-4.5-air:free' | 'qwen/qwen3-coder' | 'qwen/qwen3-32b:free' | 'qwen/qwen3-next-80b-a3b-instruct' | 'qwen/qwen-2.5-coder-32b-instruct' | 'qwen/qwen3-235b-a22b:free' | 'qwen/qwen3-coder-flash' | 'qwen/qwq-32b:free' | 'qwen/qwen3-30b-a3b-thinking-2507' | 'qwen/qwen3-30b-a3b:free' | 'qwen/qwen2.5-vl-72b-instruct' | 'qwen/qwen3-14b:free' | 'qwen/qwen3-30b-a3b-instruct-2507' | 'qwen/qwen3-235b-a22b-thinking-2507' | 'qwen/qwen2.5-vl-32b-instruct:free' | 'qwen/qwen2.5-vl-72b-instruct:free' | 'qwen/qwen3-235b-a22b-07-25:free' | 'qwen/qwen3-coder:free' | 'qwen/qwen3-235b-a22b-07-25' | 'qwen/qwen3-8b:free' | 'qwen/qwen3-max' | 'qwen/qwen3-next-80b-a3b-thinking' | 'qwen/qwen3-coder:exacto' | 'mistralai/devstral-medium-2507' | 'mistralai/devstral-2512:free' | 'mistralai/devstral-2512' | 'mistralai/codestral-2508' | 'mistralai/mistral-7b-instruct:free' | 'mistralai/devstral-small-2505' | 'mistralai/mistral-small-3.2-24b-instruct' | 'mistralai/devstral-small-2505:free' | 'mistralai/mistral-small-3.2-24b-instruct:free' | 'mistralai/mistral-medium-3' | 'mistralai/mistral-small-3.1-24b-instruct' | 'mistralai/devstral-small-2507' | 'mistralai/mistral-medium-3.1' | 'mistralai/mistral-nemo:free' | 'rekaai/reka-flash-3' | 'meta-llama/llama-3.2-11b-vision-instruct' | 'meta-llama/llama-3.3-70b-instruct:free' | 'meta-llama/llama-4-scout:free' | 'anthropic/claude-opus-4' | 'anthropic/claude-haiku-4.5' | 'anthropic/claude-opus-4.1' | 'anthropic/claude-3.7-sonnet' | 'anthropic/claude-3.5-haiku' | 'anthropic/claude-sonnet-4' | 'anthropic/claude-opus-4.5' | 'anthropic/claude-sonnet-4.5' | 'sarvamai/sarvam-m:free';
5
2
  type AnthropicModels = 'claude-opus-4-0' | 'claude-3-5-sonnet-20241022' | 'claude-opus-4-1' | 'claude-haiku-4-5' | 'claude-3-5-sonnet-20240620' | 'claude-3-5-haiku-latest' | 'claude-opus-4-5' | 'claude-3-opus-20240229' | 'claude-opus-4-5-20251101' | 'claude-sonnet-4-5' | 'claude-sonnet-4-5-20250929' | 'claude-sonnet-4-20250514' | 'claude-opus-4-20250514' | 'claude-3-5-haiku-20241022' | 'claude-3-haiku-20240307' | 'claude-3-7-sonnet-20250219' | 'claude-3-7-sonnet-latest' | 'claude-sonnet-4-0' | 'claude-opus-4-1-20250805' | 'claude-3-sonnet-20240229' | 'claude-haiku-4-5-20251001';
6
3
  type AzureModels = 'gpt-4.1-nano' | 'text-embedding-3-small' | 'grok-4-fast-non-reasoning' | 'deepseek-r1-0528' | 'grok-4-fast-reasoning' | 'phi-3-medium-128k-instruct' | 'gpt-4' | 'claude-opus-4-1' | 'gpt-5.2-chat' | 'llama-3.2-11b-vision-instruct' | 'cohere-embed-v-4-0' | 'cohere-command-r-08-2024' | 'grok-4' | 'cohere-embed-v3-multilingual' | 'phi-4-mini' | 'gpt-4-32k' | 'meta-llama-3.1-405b-instruct' | 'deepseek-r1' | 'grok-code-fast-1' | 'gpt-5.1-codex' | 'phi-3-mini-4k-instruct' | 'claude-haiku-4-5' | 'deepseek-v3.2-speciale' | 'mistral-medium-2505' | 'claude-opus-4-5' | 'phi-3-small-128k-instruct' | 'cohere-command-a' | 'cohere-command-r-plus-08-2024' | 'llama-4-maverick-17b-128e-instruct-fp8' | 'gpt-4.1-mini' | 'gpt-5-chat' | 'deepseek-v3.1' | 'phi-4' | 'phi-4-mini-reasoning' | 'claude-sonnet-4-5' | 'gpt-3.5-turbo-0125' | 'grok-3' | 'text-embedding-3-large' | 'meta-llama-3-70b-instruct' | 'deepseek-v3-0324' | 'phi-3-small-8k-instruct' | 'meta-llama-3.1-70b-instruct' | 'gpt-4-turbo' | 'gpt-3.5-turbo-0613' | 'phi-3.5-mini-instruct' | 'o1-preview' | 'llama-3.3-70b-instruct' | 'gpt-5.1-codex-mini' | 'kimi-k2-thinking' | 'model-router' | 'o3-mini' | 'gpt-5.1' | 'gpt-5-nano' | 'gpt-5-codex' | 'llama-3.2-90b-vision-instruct' | 'phi-3-mini-128k-instruct' | 'gpt-4o' | 'gpt-3.5-turbo-0301' | 'ministral-3b' | 'gpt-4.1' | 'o4-mini' | 'phi-4-multimodal' | 'meta-llama-3-8b-instruct' | 'o1' | 'grok-3-mini' | 'gpt-5.1-chat' | 'phi-3.5-moe-instruct' | 'gpt-5-mini' | 'o1-mini' | 'llama-4-scout-17b-16e-instruct' | 'cohere-embed-v3-english' | 'text-embedding-ada-002' | 'meta-llama-3.1-8b-instruct' | 'gpt-5.1-codex-max' | 'gpt-3.5-turbo-instruct' | 'mistral-nemo' | 'o3' | 'codex-mini' | 'phi-3-medium-4k-instruct' | 'phi-4-reasoning' | 'gpt-4-turbo-vision' | 'phi-4-reasoning-plus' | 'gpt-4o-mini' | 'gpt-5' | 'mai-ds-r1' | 'deepseek-v3.2' | 'gpt-5-pro' | 'mistral-large-2411' | 'gpt-5.2' | 'codestral-2501' | 'mistral-small-2503' | 'gpt-3.5-turbo-1106';
7
4
  type CloudflareWorkersAiModels = 'mistral-7b-instruct-v0.1-awq' | 'aura-1' | 'mistral-7b-instruct-v0.2' | 'tinyllama-1.1b-chat-v1.0' | 'qwen1.5-0.5b-chat' | 'llama-3.2-11b-vision-instruct' | 'llama-2-13b-chat-awq' | 'llama-3.1-8b-instruct-fp8' | 'whisper' | 'stable-diffusion-xl-base-1.0' | 'llama-2-7b-chat-fp16' | 'resnet-50' | 'stable-diffusion-v1-5-inpainting' | 'sqlcoder-7b-2' | 'llama-3-8b-instruct' | 'llama-2-7b-chat-hf-lora' | 'llama-3.1-8b-instruct' | 'openchat-3.5-0106' | 'openhermes-2.5-mistral-7b-awq' | 'lucid-origin' | 'bart-large-cnn' | 'flux-1-schnell' | 'deepseek-r1-distill-qwen-32b' | 'gemma-2b-it-lora' | 'una-cybertron-7b-v2-bf16' | 'gemma-sea-lion-v4-27b-it' | 'm2m100-1.2b' | 'llama-3.2-3b-instruct' | 'qwen2.5-coder-32b-instruct' | 'stable-diffusion-v1-5-img2img' | 'gemma-7b-it-lora' | 'qwen1.5-14b-chat-awq' | 'qwen1.5-1.8b-chat' | 'mistral-small-3.1-24b-instruct' | 'gemma-7b-it' | 'qwen3-30b-a3b-fp8' | 'llamaguard-7b-awq' | 'hermes-2-pro-mistral-7b' | 'granite-4.0-h-micro' | 'falcon-7b-instruct' | 'llama-3.3-70b-instruct-fp8-fast' | 'llama-3-8b-instruct-awq' | 'phoenix-1.0' | 'phi-2' | 'dreamshaper-8-lcm' | 'discolm-german-7b-v1-awq' | 'llama-2-7b-chat-int8' | 'llama-3.2-1b-instruct' | 'whisper-large-v3-turbo' | 'llama-4-scout-17b-16e-instruct' | 'starling-lm-7b-beta' | 'deepseek-coder-6.7b-base-awq' | 'gemma-3-12b-it' | 'llama-guard-3-8b' | 'neural-chat-7b-v3-1-awq' | 'whisper-tiny-en' | 'stable-diffusion-xl-lightning' | 'mistral-7b-instruct-v0.1' | 'llava-1.5-7b-hf' | 'gpt-oss-20b' | 'deepseek-math-7b-instruct' | 'gpt-oss-120b' | 'melotts' | 'qwen1.5-7b-chat-awq' | 'llama-3.1-8b-instruct-fast' | 'nova-3' | 'llama-3.1-70b-instruct' | 'qwq-32b' | 'zephyr-7b-beta-awq' | 'deepseek-coder-6.7b-instruct-awq' | 'llama-3.1-8b-instruct-awq' | 'mistral-7b-instruct-v0.2-lora' | 'uform-gen2-qwen-500m';
8
5
  type TogetheraiModels = 'moonshotai/Kimi-K2-Instruct' | 'moonshotai/Kimi-K2-Thinking' | 'essentialai/Rnj-1-Instruct' | 'openai/gpt-oss-120b' | 'meta-llama/Llama-3.3-70B-Instruct-Turbo' | 'Qwen/Qwen3-Coder-480B-A35B-Instruct-FP8' | 'zai-org/GLM-4.6' | 'deepseek-ai/DeepSeek-R1' | 'deepseek-ai/DeepSeek-V3' | 'deepseek-ai/DeepSeek-V3-1';
9
6
 
10
- interface OpenRouterOptions {
11
- extraHeaders?: (Headers | Record<string, string>) & {
12
- 'HTTP-Referer'?: string;
13
- 'X-Title'?: string;
14
- };
15
- /**
16
- * Model routing
17
- *
18
- * @see {@link https://openrouter.ai/docs/features/model-routing}
19
- * @example
20
- * ```
21
- * {
22
- * model: [ 'openai/gpt-1o' ],
23
- * models: [ 'openai/gpt-4o', 'google/gemini-2.0-flash-001' ],
24
- * messages: [
25
- * { role: 'user', content: 'Hello, world!' },
26
- * ]
27
- * }
28
- * ```
29
- */
30
- models?: string[];
31
- /**
32
- * Provider routing
33
- *
34
- * @see {@link https://openrouter.ai/docs/features/provider-routing}
35
- */
36
- provider?: {
37
- /**
38
- * Whether to allow backup providers when the primary is unavailable.
39
- *
40
- * @see {@link https://openrouter.ai/docs/features/provider-routing#disabling-fallbacks}
41
- * @default true
42
- * @example false
43
- */
44
- allowFallbacks?: boolean;
45
- /**
46
- * Control whether to use providers that may store data.
47
- *
48
- * @see {@link https://openrouter.ai/docs/features/provider-routing#requiring-providers-to-comply-with-data-policies}
49
- * @default 'allow'
50
- */
51
- dataCollection?: 'allow' | 'deny';
52
- /**
53
- * List of provider names to skip for this request.
54
- *
55
- * @see {@link https://openrouter.ai/docs/features/provider-routing#ignoring-providers}
56
- */
57
- ignore?: string[];
58
- /**
59
- * List of provider names to try in order (e.g. ["Anthropic", "OpenAI"]).
60
- *
61
- * @see {@link https://openrouter.ai/docs/features/provider-routing#ordering-specific-providers}
62
- * @example [ 'Anthropic', 'OpenAI' ]
63
- */
64
- order?: string[];
65
- /**
66
- * List of quantization levels to filter by (e.g. ["int4", "int8"]).
67
- *
68
- * @see {@link https://openrouter.ai/docs/features/provider-routing#quantization}
69
- * @example [ 'int4', 'int8' ]
70
- */
71
- quantizations?: string[];
72
- /**
73
- * Only use providers that support all parameters in your request.
74
- *
75
- * @see {@link https://openrouter.ai/docs/features/provider-routing#requiring-providers-to-support-all-parameters-beta}
76
- */
77
- requireParameters?: boolean;
78
- /**
79
- * Sort providers by price or throughput. (e.g. "price" or "throughput").
80
- *
81
- * @see {@link https://openrouter.ai/docs/features/provider-routing#provider-sorting}
82
- * @example 'price'
83
- */
84
- sort?: string;
85
- };
86
- /**
87
- * To help with prompts that exceed the maximum context size of a model.
88
- *
89
- * All OpenRouter endpoints with 8k or less context length will default to using middle-out.
90
- * To disable this, set `transforms: []` in the request body.
91
- *
92
- * @see {@link https://openrouter.ai/docs/features/message-transforms}
93
- * @default 'middle-out'
94
- */
95
- transforms?: string[];
96
- }
97
- /**
98
- * Create a OpenRouter Provider
99
- * @see {@link https://openrouter.ai/models}
100
- */
101
- declare const createOpenRouter: (apiKey: string, baseURL?: string) => _xsai_ext_shared_providers.ModelProvider & ChatProviderWithExtraOptions<OpenrouterModels, OpenRouterOptions>;
102
-
103
- interface AnthropicOptions {
104
- /** @see {@link https://docs.claude.com/en/api/openai-sdk#extended-thinking-support} */
105
- thinking?: {
106
- budget_tokens: number;
107
- type: 'enabled';
108
- };
109
- }
110
- /**
111
- * Create a Anthropic Provider
112
- * @see {@link https://docs.claude.com/en/api/openai-sdk}
113
- */
114
- declare const createAnthropic: (apiKey: string, baseURL?: string) => _xsai_ext_shared_providers.ModelProvider & _xsai_ext_shared_providers.ChatProviderWithExtraOptions<AnthropicModels, AnthropicOptions>;
115
-
116
- export { createAnthropic as d, createOpenRouter as e };
117
- export type { AnthropicModels as A, CloudflareWorkersAiModels as C, OpenrouterModels as O, TogetheraiModels as T, AnthropicOptions as a, OpenRouterOptions as b, AzureModels as c };
7
+ export type { AnthropicModels as A, CloudflareWorkersAiModels as C, OpenrouterModels as O, TogetheraiModels as T, AzureModels as a };
@@ -0,0 +1,38 @@
1
+ import { CommonRequestOptions } from '@xsai/shared';
2
+
3
+ interface ChatProvider<T = string> {
4
+ chat: (model: (string & {}) | T) => CommonRequestOptions;
5
+ }
6
+ interface ChatProviderWithExtraOptions<T = string, T2 = undefined> {
7
+ chat: (model: (string & {}) | T, extraOptions?: T2) => CommonRequestOptions & Partial<T2>;
8
+ }
9
+ type CreateProviderOptions = Omit<CommonRequestOptions, 'model'>;
10
+ interface EmbedProvider<T = string> {
11
+ embed: (model: (string & {}) | T) => CommonRequestOptions;
12
+ }
13
+ interface EmbedProviderWithExtraOptions<T = string, T2 = undefined> {
14
+ embed: (model: (string & {}) | T, extraOptions?: T2) => CommonRequestOptions & Partial<T2>;
15
+ }
16
+ interface ImageProvider<T = string> {
17
+ image: (model: (string & {}) | T) => CommonRequestOptions;
18
+ }
19
+ interface ModelProvider {
20
+ model: () => CreateProviderOptions;
21
+ }
22
+ interface ModelProviderWithExtraOptions<T = undefined> {
23
+ model: (options?: T) => CreateProviderOptions & Partial<T>;
24
+ }
25
+ interface SpeechProvider<T = string> {
26
+ speech: (model: (string & {}) | T) => CommonRequestOptions;
27
+ }
28
+ interface SpeechProviderWithExtraOptions<T = string, T2 = undefined> {
29
+ speech: (model: (string & {}) | T, extraOptions?: T2) => CommonRequestOptions & Partial<T2>;
30
+ }
31
+ interface TranscriptionProvider<T = string> {
32
+ transcription: (model: (string & {}) | T) => CommonRequestOptions;
33
+ }
34
+ interface TranscriptionProviderWithExtraOptions<T = string, T2 = undefined> {
35
+ transcription: (model: (string & {}) | T, extraOptions?: T2) => CommonRequestOptions & Partial<T2>;
36
+ }
37
+
38
+ export type { ChatProvider as C, EmbedProvider as E, ImageProvider as I, ModelProvider as M, SpeechProvider as S, TranscriptionProvider as T, ChatProviderWithExtraOptions as a, CreateProviderOptions as b, EmbedProviderWithExtraOptions as c, ModelProviderWithExtraOptions as d, SpeechProviderWithExtraOptions as e, TranscriptionProviderWithExtraOptions as f };
@@ -0,0 +1,52 @@
1
+ import { b as CreateProviderOptions, C as ChatProvider, a as ChatProviderWithExtraOptions, E as EmbedProvider, c as EmbedProviderWithExtraOptions, I as ImageProvider, M as ModelProvider, d as ModelProviderWithExtraOptions, S as SpeechProvider, e as SpeechProviderWithExtraOptions, T as TranscriptionProvider, f as TranscriptionProviderWithExtraOptions } from '../types-DW1hvH0W.js';
2
+ import '@xsai/shared';
3
+
4
+ declare const createChatProvider: <T extends string = string>(options: CreateProviderOptions) => ChatProvider<T>;
5
+ declare const createChatProviderWithExtraOptions: <T extends string = string, T2 = undefined>(options: CreateProviderOptions) => ChatProviderWithExtraOptions<T, T2>;
6
+ declare const createEmbedProvider: <T extends string = string>(options: CreateProviderOptions) => EmbedProvider<T>;
7
+ declare const createEmbedProviderWithExtraOptions: <T extends string = string, T2 = undefined>(options: CreateProviderOptions) => EmbedProviderWithExtraOptions<T, T2>;
8
+ declare const createImageProvider: <T extends string = string>(options: CreateProviderOptions) => ImageProvider<T>;
9
+ declare const createModelProvider: (options: CreateProviderOptions) => ModelProvider;
10
+ declare const createModelProviderWithExtraOptions: <T = undefined>(options: Omit<CreateProviderOptions, "model">) => ModelProviderWithExtraOptions<T>;
11
+ declare const createSpeechProvider: <T extends string = string>(options: CreateProviderOptions) => SpeechProvider<T>;
12
+ declare const createSpeechProviderWithExtraOptions: <T extends string = string, T2 = undefined>(options: CreateProviderOptions) => SpeechProviderWithExtraOptions<T, T2>;
13
+ declare const createTranscriptionProvider: <T extends string = string>(options: CreateProviderOptions) => TranscriptionProvider<T>;
14
+ declare const createTranscriptionProviderWithExtraOptions: <T extends string = string, T2 = undefined>(options: CreateProviderOptions) => TranscriptionProviderWithExtraOptions<T, T2>;
15
+
16
+ /**
17
+ Convert a union type to an intersection type using [distributive conditional types](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
18
+
19
+ Inspired by [this Stack Overflow answer](https://stackoverflow.com/a/50375286/2172153).
20
+
21
+ @example
22
+ ```
23
+ import type {UnionToIntersection} from 'type-fest';
24
+
25
+ type Union = {the(): void} | {great(arg: string): void} | {escape: boolean};
26
+
27
+ type Intersection = UnionToIntersection<Union>;
28
+ //=> {the(): void; great(arg: string): void; escape: boolean};
29
+ ```
30
+
31
+ @category Type
32
+ */
33
+ type UnionToIntersection<Union> = (
34
+ // `extends unknown` is always going to be the case and is used to convert the
35
+ // `Union` into a [distributive conditional
36
+ // type](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-2-8.html#distributive-conditional-types).
37
+ Union extends unknown
38
+ // The union type is used as the only argument to a function since the union
39
+ // of function arguments is an intersection.
40
+ ? (distributedUnion: Union) => void
41
+ // This won't happen.
42
+ : never
43
+ // Infer the `Intersection` type since TypeScript represents the positional
44
+ // arguments of unions of functions as an intersection of the union.
45
+ ) extends ((mergedIntersection: infer Intersection) => void)
46
+ // The `& Union` is to ensure result of `UnionToIntersection<A | B>` is always assignable to `A | B`
47
+ ? Intersection & Union
48
+ : never;
49
+
50
+ declare const merge: <T extends object[]>(...arr: T) => UnionToIntersection<T[number]>;
51
+
52
+ export { ChatProvider, ChatProviderWithExtraOptions, CreateProviderOptions, EmbedProvider, EmbedProviderWithExtraOptions, ImageProvider, ModelProvider, ModelProviderWithExtraOptions, SpeechProvider, SpeechProviderWithExtraOptions, TranscriptionProvider, TranscriptionProviderWithExtraOptions, createChatProvider, createChatProviderWithExtraOptions, createEmbedProvider, createEmbedProviderWithExtraOptions, createImageProvider, createModelProvider, createModelProviderWithExtraOptions, createSpeechProvider, createSpeechProviderWithExtraOptions, createTranscriptionProvider, createTranscriptionProviderWithExtraOptions, merge };
@@ -0,0 +1,37 @@
1
+ const createChatProvider = (options) => ({
2
+ chat: (model) => Object.assign(options, { model })
3
+ });
4
+ const createChatProviderWithExtraOptions = (options) => ({
5
+ chat: (model, extraOptions) => Object.assign(options, { model }, extraOptions)
6
+ });
7
+ const createEmbedProvider = (options) => ({
8
+ embed: (model) => Object.assign(options, { model })
9
+ });
10
+ const createEmbedProviderWithExtraOptions = (options) => ({
11
+ embed: (model, extraOptions) => Object.assign(options, { model }, extraOptions)
12
+ });
13
+ const createImageProvider = (options) => ({
14
+ image: (model) => Object.assign(options, { model })
15
+ });
16
+ const createModelProvider = (options) => ({
17
+ model: () => options
18
+ });
19
+ const createModelProviderWithExtraOptions = (options) => ({
20
+ model: (extraOptions) => Object.assign(options, extraOptions)
21
+ });
22
+ const createSpeechProvider = (options) => ({
23
+ speech: (model) => Object.assign(options, { model })
24
+ });
25
+ const createSpeechProviderWithExtraOptions = (options) => ({
26
+ speech: (model, extraOptions) => Object.assign(options, { model }, extraOptions)
27
+ });
28
+ const createTranscriptionProvider = (options) => ({
29
+ transcription: (model) => Object.assign(options, { model })
30
+ });
31
+ const createTranscriptionProviderWithExtraOptions = (options) => ({
32
+ transcription: (model, extraOptions) => Object.assign(options, { model }, extraOptions)
33
+ });
34
+
35
+ const merge = (...arr) => Object.assign(arr[0], ...arr.slice(1));
36
+
37
+ export { createChatProvider, createChatProviderWithExtraOptions, createEmbedProvider, createEmbedProviderWithExtraOptions, createImageProvider, createModelProvider, createModelProviderWithExtraOptions, createSpeechProvider, createSpeechProviderWithExtraOptions, createTranscriptionProvider, createTranscriptionProviderWithExtraOptions, merge };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@xsai-ext/providers",
3
3
  "type": "module",
4
- "version": "0.4.0-beta.12",
4
+ "version": "0.4.0-beta.13",
5
5
  "description": "extra-small AI SDK.",
6
6
  "author": "Moeru AI",
7
7
  "license": "MIT",
@@ -27,17 +27,29 @@
27
27
  "types": "./dist/create.d.ts",
28
28
  "default": "./dist/create.js"
29
29
  },
30
+ "./special": {
31
+ "types": "./dist/special/index.d.ts",
32
+ "default": "./dist/special/index.js"
33
+ },
34
+ "./special/create": {
35
+ "types": "./dist/special/create.d.ts",
36
+ "default": "./dist/special/create.js"
37
+ },
38
+ "./utils": {
39
+ "types": "./dist/utils/index.d.ts",
40
+ "default": "./dist/utils/index.js"
41
+ },
30
42
  "./package.json": "./package.json"
31
43
  },
32
44
  "files": [
33
45
  "dist"
34
46
  ],
35
47
  "dependencies": {
36
- "@xsai-ext/shared-providers": "~0.4.0-beta.12",
37
- "@xsai/shared": "~0.4.0-beta.12"
48
+ "@xsai/shared": "~0.4.0-beta.13"
38
49
  },
39
50
  "devDependencies": {
40
- "scule": "^1.3.0"
51
+ "scule": "^1.3.0",
52
+ "type-fest": "^5.3.1"
41
53
  },
42
54
  "scripts": {
43
55
  "build": "pkgroll",