@providerprotocol/ai 0.0.17 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +294 -114
- package/dist/anthropic/index.d.ts +1 -1
- package/dist/anthropic/index.js +5 -3
- package/dist/anthropic/index.js.map +1 -1
- package/dist/{chunk-MOU4U3PO.js → chunk-5FEAOEXV.js} +4 -68
- package/dist/chunk-5FEAOEXV.js.map +1 -0
- package/dist/chunk-DZQHVGNV.js +71 -0
- package/dist/chunk-DZQHVGNV.js.map +1 -0
- package/dist/chunk-SKY2JLA7.js +59 -0
- package/dist/chunk-SKY2JLA7.js.map +1 -0
- package/dist/{chunk-SVYROCLD.js → chunk-UMKWXGO3.js} +1 -1
- package/dist/chunk-UMKWXGO3.js.map +1 -0
- package/dist/chunk-WAKD3OO5.js +224 -0
- package/dist/chunk-WAKD3OO5.js.map +1 -0
- package/dist/content-DEl3z_W2.d.ts +276 -0
- package/dist/google/index.d.ts +3 -1
- package/dist/google/index.js +122 -4
- package/dist/google/index.js.map +1 -1
- package/dist/http/index.d.ts +2 -2
- package/dist/http/index.js +2 -1
- package/dist/image-Dhq-Yuq4.d.ts +456 -0
- package/dist/index.d.ts +59 -1460
- package/dist/index.js +89 -267
- package/dist/index.js.map +1 -1
- package/dist/ollama/index.d.ts +1 -1
- package/dist/ollama/index.js +5 -3
- package/dist/ollama/index.js.map +1 -1
- package/dist/openai/index.d.ts +47 -20
- package/dist/openai/index.js +309 -4
- package/dist/openai/index.js.map +1 -1
- package/dist/openrouter/index.d.ts +1 -1
- package/dist/openrouter/index.js +5 -3
- package/dist/openrouter/index.js.map +1 -1
- package/dist/{provider-D5MO3-pS.d.ts → provider-BBMBZuGn.d.ts} +11 -11
- package/dist/proxy/index.d.ts +652 -0
- package/dist/proxy/index.js +565 -0
- package/dist/proxy/index.js.map +1 -0
- package/dist/{retry-DZ4Sqmxp.d.ts → retry-DR7YRJDz.d.ts} +1 -1
- package/dist/stream-DRHy6q1a.d.ts +1013 -0
- package/dist/xai/index.d.ts +29 -1
- package/dist/xai/index.js +118 -4
- package/dist/xai/index.js.map +1 -1
- package/package.json +6 -1
- package/dist/chunk-MOU4U3PO.js.map +0 -1
- package/dist/chunk-SVYROCLD.js.map +0 -1
package/dist/xai/index.d.ts
CHANGED
|
@@ -1,4 +1,31 @@
|
|
|
1
|
-
import { d as Provider, f as ModelReference, b as LLMHandler } from '../provider-
|
|
1
|
+
import { d as Provider, f as ModelReference, b as LLMHandler } from '../provider-BBMBZuGn.js';
|
|
2
|
+
import { n as ImageHandler } from '../image-Dhq-Yuq4.js';
|
|
3
|
+
import '../content-DEl3z_W2.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @fileoverview xAI Image Generation API Handler
|
|
7
|
+
*
|
|
8
|
+
* This module implements the image handler for xAI's Image Generation API (Aurora).
|
|
9
|
+
* Supports the grok-2-image-1212 model.
|
|
10
|
+
*
|
|
11
|
+
* @see {@link https://docs.x.ai/docs/image-generation xAI Image Generation Reference}
|
|
12
|
+
* @module providers/xai/image
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* xAI image generation parameters.
|
|
17
|
+
* Passed through unchanged to the API.
|
|
18
|
+
*
|
|
19
|
+
* Note: xAI does NOT support negative_prompt or seed parameters.
|
|
20
|
+
*/
|
|
21
|
+
interface XAIImageParams {
|
|
22
|
+
/** Number of images to generate (1-10) */
|
|
23
|
+
n?: number;
|
|
24
|
+
/** Response format */
|
|
25
|
+
response_format?: 'url' | 'b64_json';
|
|
26
|
+
/** User identifier */
|
|
27
|
+
user?: string;
|
|
28
|
+
}
|
|
2
29
|
|
|
3
30
|
/**
|
|
4
31
|
* xAI Chat Completions API parameters (OpenAI-compatible).
|
|
@@ -660,6 +687,7 @@ interface XAIProvider extends Provider<XAIProviderOptions> {
|
|
|
660
687
|
/** Supported modalities */
|
|
661
688
|
readonly modalities: {
|
|
662
689
|
llm: LLMHandler<XAILLMParamsUnion>;
|
|
690
|
+
image: ImageHandler<XAIImageParams>;
|
|
663
691
|
};
|
|
664
692
|
}
|
|
665
693
|
/**
|
package/dist/xai/index.js
CHANGED
|
@@ -1,19 +1,24 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Image
|
|
3
|
+
} from "../chunk-WAKD3OO5.js";
|
|
1
4
|
import {
|
|
2
5
|
AssistantMessage,
|
|
3
6
|
isAssistantMessage,
|
|
4
7
|
isToolResultMessage,
|
|
5
8
|
isUserMessage
|
|
6
|
-
} from "../chunk-
|
|
9
|
+
} from "../chunk-UMKWXGO3.js";
|
|
7
10
|
import {
|
|
8
11
|
parseSSEStream
|
|
9
12
|
} from "../chunk-Z7RBRCRN.js";
|
|
10
13
|
import {
|
|
11
|
-
UPPError,
|
|
12
14
|
doFetch,
|
|
13
15
|
doStreamFetch,
|
|
14
16
|
normalizeHttpError,
|
|
15
17
|
resolveApiKey
|
|
16
|
-
} from "../chunk-
|
|
18
|
+
} from "../chunk-5FEAOEXV.js";
|
|
19
|
+
import {
|
|
20
|
+
UPPError
|
|
21
|
+
} from "../chunk-DZQHVGNV.js";
|
|
17
22
|
|
|
18
23
|
// src/providers/xai/transform.completions.ts
|
|
19
24
|
function transformRequest(request, modelId) {
|
|
@@ -1726,6 +1731,112 @@ function createMessagesLLMHandler() {
|
|
|
1726
1731
|
};
|
|
1727
1732
|
}
|
|
1728
1733
|
|
|
1734
|
+
// src/providers/xai/image.ts
|
|
1735
|
+
var XAI_IMAGES_API_URL = "https://api.x.ai/v1/images/generations";
|
|
1736
|
+
function getCapabilities(modelId) {
|
|
1737
|
+
return {
|
|
1738
|
+
generate: true,
|
|
1739
|
+
streaming: false,
|
|
1740
|
+
edit: false,
|
|
1741
|
+
maxImages: 10
|
|
1742
|
+
};
|
|
1743
|
+
}
|
|
1744
|
+
function createImageHandler() {
|
|
1745
|
+
let providerRef = null;
|
|
1746
|
+
return {
|
|
1747
|
+
_setProvider(provider) {
|
|
1748
|
+
providerRef = provider;
|
|
1749
|
+
},
|
|
1750
|
+
bind(modelId) {
|
|
1751
|
+
if (!providerRef) {
|
|
1752
|
+
throw new UPPError(
|
|
1753
|
+
"Provider reference not set. Handler must be used with createProvider().",
|
|
1754
|
+
"INVALID_REQUEST",
|
|
1755
|
+
"xai",
|
|
1756
|
+
"image"
|
|
1757
|
+
);
|
|
1758
|
+
}
|
|
1759
|
+
const capabilities = getCapabilities(modelId);
|
|
1760
|
+
const model = {
|
|
1761
|
+
modelId,
|
|
1762
|
+
capabilities,
|
|
1763
|
+
get provider() {
|
|
1764
|
+
return providerRef;
|
|
1765
|
+
},
|
|
1766
|
+
async generate(request) {
|
|
1767
|
+
return executeGenerate(modelId, request);
|
|
1768
|
+
}
|
|
1769
|
+
};
|
|
1770
|
+
return model;
|
|
1771
|
+
}
|
|
1772
|
+
};
|
|
1773
|
+
}
|
|
1774
|
+
async function executeGenerate(modelId, request) {
|
|
1775
|
+
const apiKey = await resolveApiKey(
|
|
1776
|
+
request.config,
|
|
1777
|
+
"XAI_API_KEY",
|
|
1778
|
+
"xai",
|
|
1779
|
+
"image"
|
|
1780
|
+
);
|
|
1781
|
+
const baseUrl = request.config.baseUrl ? `${request.config.baseUrl.replace(/\/$/, "")}/v1/images/generations` : XAI_IMAGES_API_URL;
|
|
1782
|
+
const body = {
|
|
1783
|
+
model: modelId,
|
|
1784
|
+
prompt: request.prompt
|
|
1785
|
+
};
|
|
1786
|
+
if (request.params) {
|
|
1787
|
+
const { n, response_format, user } = request.params;
|
|
1788
|
+
if (n !== void 0) body.n = n;
|
|
1789
|
+
if (response_format !== void 0) body.response_format = response_format;
|
|
1790
|
+
if (user !== void 0) body.user = user;
|
|
1791
|
+
}
|
|
1792
|
+
const headers = {
|
|
1793
|
+
"Content-Type": "application/json",
|
|
1794
|
+
Authorization: `Bearer ${apiKey}`
|
|
1795
|
+
};
|
|
1796
|
+
if (request.config.headers) {
|
|
1797
|
+
for (const [key, value] of Object.entries(request.config.headers)) {
|
|
1798
|
+
if (value !== void 0) {
|
|
1799
|
+
headers[key] = value;
|
|
1800
|
+
}
|
|
1801
|
+
}
|
|
1802
|
+
}
|
|
1803
|
+
const response = await doFetch(baseUrl, {
|
|
1804
|
+
method: "POST",
|
|
1805
|
+
headers,
|
|
1806
|
+
body: JSON.stringify(body),
|
|
1807
|
+
signal: request.signal
|
|
1808
|
+
}, request.config, "xai", "image");
|
|
1809
|
+
const data = await response.json();
|
|
1810
|
+
return transformResponse4(data);
|
|
1811
|
+
}
|
|
1812
|
+
function transformResponse4(data) {
|
|
1813
|
+
const images = data.data.map((item) => {
|
|
1814
|
+
let image;
|
|
1815
|
+
if (item.b64_json) {
|
|
1816
|
+
image = Image.fromBase64(item.b64_json, "image/jpeg");
|
|
1817
|
+
} else if (item.url) {
|
|
1818
|
+
image = Image.fromUrl(item.url, "image/jpeg");
|
|
1819
|
+
} else {
|
|
1820
|
+
throw new UPPError(
|
|
1821
|
+
"No image data in response",
|
|
1822
|
+
"PROVIDER_ERROR",
|
|
1823
|
+
"xai",
|
|
1824
|
+
"image"
|
|
1825
|
+
);
|
|
1826
|
+
}
|
|
1827
|
+
return {
|
|
1828
|
+
image,
|
|
1829
|
+
metadata: item.revised_prompt ? { revised_prompt: item.revised_prompt } : void 0
|
|
1830
|
+
};
|
|
1831
|
+
});
|
|
1832
|
+
return {
|
|
1833
|
+
images,
|
|
1834
|
+
usage: {
|
|
1835
|
+
imagesGenerated: images.length
|
|
1836
|
+
}
|
|
1837
|
+
};
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1729
1840
|
// src/providers/xai/types.ts
|
|
1730
1841
|
function webSearchTool(options) {
|
|
1731
1842
|
return {
|
|
@@ -1778,6 +1889,7 @@ function createXAIProvider() {
|
|
|
1778
1889
|
const completionsHandler = createCompletionsLLMHandler();
|
|
1779
1890
|
const responsesHandler = createResponsesLLMHandler();
|
|
1780
1891
|
const messagesHandler = createMessagesLLMHandler();
|
|
1892
|
+
const imageHandler = createImageHandler();
|
|
1781
1893
|
const fn = function(modelId, options) {
|
|
1782
1894
|
const apiMode = options?.api ?? "completions";
|
|
1783
1895
|
currentApiMode = apiMode;
|
|
@@ -1794,7 +1906,8 @@ function createXAIProvider() {
|
|
|
1794
1906
|
default:
|
|
1795
1907
|
return completionsHandler;
|
|
1796
1908
|
}
|
|
1797
|
-
}
|
|
1909
|
+
},
|
|
1910
|
+
image: imageHandler
|
|
1798
1911
|
};
|
|
1799
1912
|
Object.defineProperties(fn, {
|
|
1800
1913
|
name: {
|
|
@@ -1817,6 +1930,7 @@ function createXAIProvider() {
|
|
|
1817
1930
|
completionsHandler._setProvider?.(provider);
|
|
1818
1931
|
responsesHandler._setProvider?.(provider);
|
|
1819
1932
|
messagesHandler._setProvider?.(provider);
|
|
1933
|
+
imageHandler._setProvider?.(provider);
|
|
1820
1934
|
return provider;
|
|
1821
1935
|
}
|
|
1822
1936
|
var xai = createXAIProvider();
|