@absolutejs/ai 0.3.0 → 0.3.1
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/CHANGELOG.md +6 -0
- package/changelog.json +13 -0
- package/dist/ai/client/index.js +3 -1
- package/dist/ai/client/index.js.map +2 -2
- package/dist/ai/index.js +7740 -7712
- package/dist/ai/index.js.map +18 -18
- package/dist/ai/models/index.js +71 -1
- package/dist/ai/models/index.js.map +2 -2
- package/dist/ai/providers/anthropic.js +27 -25
- package/dist/ai/providers/anthropic.js.map +2 -2
- package/dist/ai/providers/gemini.js +13 -11
- package/dist/ai/providers/gemini.js.map +2 -2
- package/dist/ai/providers/ollama.js +5 -3
- package/dist/ai/providers/ollama.js.map +2 -2
- package/dist/ai/providers/openai.js +64 -41
- package/dist/ai/providers/openai.js.map +3 -3
- package/dist/ai/providers/openaiCompatible.js +82 -59
- package/dist/ai/providers/openaiCompatible.js.map +3 -3
- package/dist/ai/providers/openaiResponses.js +44 -21
- package/dist/ai/providers/openaiResponses.js.map +3 -3
- package/dist/ai/providers/openrouter.js +148 -125
- package/dist/ai/providers/openrouter.js.map +3 -3
- package/dist/ai/providers/openrouterSDK.js +3 -1
- package/dist/ai/providers/openrouterSDK.js.map +2 -2
- package/dist/ai/research.js +4 -2
- package/dist/ai/research.js.map +2 -2
- package/dist/ai/tools/index.js +58 -55
- package/dist/ai/tools/index.js.map +5 -5
- package/dist/ai/tools/untrusted.js +3 -1
- package/dist/ai/tools/untrusted.js.map +2 -2
- package/dist/ai/ui/index.js +72 -2
- package/dist/ai/ui/index.js.map +2 -2
- package/dist/angular/ai/index.js +1 -1
- package/dist/angular/ai/index.js.map +1 -1
- package/dist/react/ai/index.js +74 -4
- package/dist/react/ai/index.js.map +2 -2
- package/dist/svelte/ai/index.js +71 -1
- package/dist/svelte/ai/index.js.map +2 -2
- package/dist/vue/ai/index.js +71 -1
- package/dist/vue/ai/index.js.map +2 -2
- package/package.json +1 -1
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
// @bun
|
|
2
|
+
var __require = import.meta.require;
|
|
3
|
+
|
|
2
4
|
// src/ai/inputCapacity.ts
|
|
3
5
|
class AIInputError extends Error {
|
|
4
6
|
code;
|
|
@@ -789,13 +791,13 @@ var compatibleReasoningBody = (provider, model, reasoning) => {
|
|
|
789
791
|
var geminiThinkingConfig = (model, reasoning) => {
|
|
790
792
|
if (!reasoning)
|
|
791
793
|
return;
|
|
792
|
-
const
|
|
794
|
+
const profile2 = getModelReasoning("google", model);
|
|
793
795
|
const effort = resolveEffort(reasoning);
|
|
794
|
-
if (!
|
|
796
|
+
if (!profile2 || !effort)
|
|
795
797
|
return;
|
|
796
|
-
if (!
|
|
798
|
+
if (!profile2.efforts.includes(effort))
|
|
797
799
|
throw new Error(`Unsupported reasoning effort ${effort} for ${model}`);
|
|
798
|
-
if (
|
|
800
|
+
if (profile2.kind === "effort")
|
|
799
801
|
return { thinkingLevel: effort };
|
|
800
802
|
const budgets = {
|
|
801
803
|
none: 0,
|
|
@@ -859,7 +861,7 @@ var convertToolBlock = (block) => {
|
|
|
859
861
|
}
|
|
860
862
|
if (block.type === "tool_use") {
|
|
861
863
|
if (block.providerData)
|
|
862
|
-
return
|
|
864
|
+
return Object.fromEntries(Object.entries(block.providerData).filter(([key]) => key !== "id"));
|
|
863
865
|
return {
|
|
864
866
|
arguments: typeof block.input === "string" ? block.input : JSON.stringify(block.input),
|
|
865
867
|
call_id: block.id,
|
|
@@ -897,10 +899,30 @@ var buildInput = (messages) => {
|
|
|
897
899
|
}
|
|
898
900
|
return input;
|
|
899
901
|
};
|
|
902
|
+
var isStrictCompatible = (schema) => {
|
|
903
|
+
if (Array.isArray(schema))
|
|
904
|
+
return schema.every(isStrictCompatible);
|
|
905
|
+
if (!isRecord(schema))
|
|
906
|
+
return true;
|
|
907
|
+
const { properties } = schema;
|
|
908
|
+
if (isRecord(properties)) {
|
|
909
|
+
const required = Array.isArray(schema.required) ? schema.required : [];
|
|
910
|
+
if (schema.additionalProperties !== false)
|
|
911
|
+
return false;
|
|
912
|
+
if (!Object.keys(properties).every((key) => required.includes(key)))
|
|
913
|
+
return false;
|
|
914
|
+
}
|
|
915
|
+
const nested = [schema.items, schema.anyOf];
|
|
916
|
+
for (const map of [properties, schema.$defs, schema.definitions])
|
|
917
|
+
if (isRecord(map))
|
|
918
|
+
nested.push(...Object.values(map));
|
|
919
|
+
return nested.every(isStrictCompatible);
|
|
920
|
+
};
|
|
900
921
|
var mapToolDefinition = (tool) => ({
|
|
901
922
|
description: tool.description,
|
|
902
923
|
name: tool.name,
|
|
903
924
|
parameters: tool.input_schema,
|
|
925
|
+
strict: isStrictCompatible(tool.input_schema),
|
|
904
926
|
type: "function"
|
|
905
927
|
});
|
|
906
928
|
var buildTools = (tools, isImageModel) => {
|
|
@@ -935,9 +957,10 @@ var buildResponsesRequestBody = (params, isImageModel, capabilityModel = params.
|
|
|
935
957
|
body.parallel_tool_calls = params.parallelToolCalls;
|
|
936
958
|
}
|
|
937
959
|
}
|
|
938
|
-
|
|
960
|
+
const samples = !isOpenAIReasoningModel(capabilityModel);
|
|
961
|
+
if (samples && typeof params.temperature === "number")
|
|
939
962
|
body.temperature = params.temperature;
|
|
940
|
-
if (typeof params.topP === "number")
|
|
963
|
+
if (samples && typeof params.topP === "number")
|
|
941
964
|
body.top_p = params.topP;
|
|
942
965
|
if (typeof params.maxTokens === "number")
|
|
943
966
|
body.max_output_tokens = params.maxTokens;
|
|
@@ -1312,31 +1335,31 @@ var resolveImageModels = (imageModels) => {
|
|
|
1312
1335
|
}
|
|
1313
1336
|
return new Set(imageModels);
|
|
1314
1337
|
};
|
|
1315
|
-
var openaiResponses = (
|
|
1316
|
-
if (!
|
|
1338
|
+
var openaiResponses = (config2) => {
|
|
1339
|
+
if (!config2.apiKey && !config2.tokenSource)
|
|
1317
1340
|
throw new Error("openaiResponses() requires either apiKey or tokenSource");
|
|
1318
|
-
const baseUrl =
|
|
1319
|
-
const fetchImpl =
|
|
1320
|
-
const imageModels = resolveImageModels(
|
|
1321
|
-
const providerName =
|
|
1322
|
-
const resolveKey = async () =>
|
|
1323
|
-
const resolveHeaders = async (params) => typeof
|
|
1341
|
+
const baseUrl = config2.baseUrl ?? DEFAULT_BASE_URL;
|
|
1342
|
+
const fetchImpl = config2.fetch ?? globalThis.fetch;
|
|
1343
|
+
const imageModels = resolveImageModels(config2.imageModels);
|
|
1344
|
+
const providerName = config2.providerName ?? "openai-responses";
|
|
1345
|
+
const resolveKey = async () => config2.tokenSource ? await Promise.resolve(config2.tokenSource()) : config2.apiKey;
|
|
1346
|
+
const resolveHeaders = async (params) => typeof config2.headers === "function" ? await config2.headers(params) : config2.headers ?? {};
|
|
1324
1347
|
return instrumentAIProvider({
|
|
1325
1348
|
inputCapacity: openaiInputCapacity({
|
|
1326
1349
|
baseUrl,
|
|
1327
1350
|
fetch: fetchImpl,
|
|
1328
1351
|
key: resolveKey,
|
|
1329
1352
|
headers: resolveHeaders,
|
|
1330
|
-
modelLimits:
|
|
1353
|
+
modelLimits: config2.modelLimits,
|
|
1331
1354
|
body: (params) => {
|
|
1332
|
-
const built = buildResponsesRequestBody(params, imageModels.has(params.model),
|
|
1333
|
-
return
|
|
1355
|
+
const built = buildResponsesRequestBody(params, imageModels.has(params.model), config2.modelForCapabilities?.(params.model) ?? params.model);
|
|
1356
|
+
return config2.transformRequestBody ? config2.transformRequestBody(built, params) : built;
|
|
1334
1357
|
}
|
|
1335
1358
|
}),
|
|
1336
1359
|
stream: (params) => {
|
|
1337
1360
|
const isImageModel = imageModels.has(params.model);
|
|
1338
|
-
const builtBody = buildResponsesRequestBody(params, isImageModel,
|
|
1339
|
-
const body =
|
|
1361
|
+
const builtBody = buildResponsesRequestBody(params, isImageModel, config2.modelForCapabilities?.(params.model) ?? params.model);
|
|
1362
|
+
const body = config2.transformRequestBody ? config2.transformRequestBody(builtBody, params) : builtBody;
|
|
1340
1363
|
return async function* () {
|
|
1341
1364
|
const [apiKey, headers] = await Promise.all([
|
|
1342
1365
|
resolveKey(),
|
|
@@ -1720,12 +1743,12 @@ var processSSELine2 = function* (line, pendingToolCalls, providerName) {
|
|
|
1720
1743
|
}
|
|
1721
1744
|
if (isRecord2(parsed.error)) {
|
|
1722
1745
|
const error = parsed.error;
|
|
1723
|
-
const
|
|
1746
|
+
const metadata2 = isRecord2(error.metadata) ? error.metadata : undefined;
|
|
1724
1747
|
const status = typeof error.code === "number" ? error.code : null;
|
|
1725
|
-
const type =
|
|
1748
|
+
const type = metadata2 && typeof metadata2.error_type === "string" ? metadata2.error_type : typeof error.error_type === "string" ? error.error_type : null;
|
|
1726
1749
|
throw new ProviderError({
|
|
1727
1750
|
message: typeof error.message === "string" ? error.message : "OpenRouter stream failed",
|
|
1728
|
-
metadata,
|
|
1751
|
+
metadata: metadata2,
|
|
1729
1752
|
provider: providerName,
|
|
1730
1753
|
retryable: status === 408 || status === 409 || status === 425 || status === 429 || status !== null && status >= 500,
|
|
1731
1754
|
status,
|
|
@@ -1750,15 +1773,15 @@ var processSSELine2 = function* (line, pendingToolCalls, providerName) {
|
|
|
1750
1773
|
}
|
|
1751
1774
|
if (isRecord2(firstChoice.error)) {
|
|
1752
1775
|
const error = firstChoice.error;
|
|
1753
|
-
const
|
|
1776
|
+
const metadata2 = isRecord2(error.metadata) ? error.metadata : undefined;
|
|
1754
1777
|
const status = typeof error.code === "number" ? error.code : null;
|
|
1755
1778
|
throw new ProviderError({
|
|
1756
1779
|
message: typeof error.message === "string" ? error.message : "OpenRouter stream failed",
|
|
1757
|
-
metadata,
|
|
1780
|
+
metadata: metadata2,
|
|
1758
1781
|
provider: providerName,
|
|
1759
1782
|
retryable: status === 429 || status !== null && status >= 500,
|
|
1760
1783
|
status,
|
|
1761
|
-
type:
|
|
1784
|
+
type: metadata2 && typeof metadata2.error_type === "string" ? metadata2.error_type : null
|
|
1762
1785
|
});
|
|
1763
1786
|
}
|
|
1764
1787
|
yield* processChoice(firstChoice, pendingToolCalls);
|
|
@@ -1857,32 +1880,32 @@ var fetchOpenAIStream = async function* (baseUrl, apiKey, body, fetchImpl, heade
|
|
|
1857
1880
|
}
|
|
1858
1881
|
}, providerName, signal);
|
|
1859
1882
|
};
|
|
1860
|
-
var openai = (
|
|
1861
|
-
const baseUrl =
|
|
1862
|
-
const fetchImpl =
|
|
1863
|
-
const providerName =
|
|
1864
|
-
if (!
|
|
1883
|
+
var openai = (config2) => {
|
|
1884
|
+
const baseUrl = config2.baseUrl ?? DEFAULT_BASE_URL2;
|
|
1885
|
+
const fetchImpl = config2.fetch ?? globalThis.fetch;
|
|
1886
|
+
const providerName = config2.providerName ?? "openai";
|
|
1887
|
+
if (!config2.apiKey && !config2.tokenSource) {
|
|
1865
1888
|
throw new Error("openai() requires either apiKey or tokenSource");
|
|
1866
1889
|
}
|
|
1867
1890
|
const resolveKey = async () => {
|
|
1868
|
-
if (
|
|
1869
|
-
return await Promise.resolve(
|
|
1891
|
+
if (config2.tokenSource) {
|
|
1892
|
+
return await Promise.resolve(config2.tokenSource());
|
|
1870
1893
|
}
|
|
1871
|
-
return
|
|
1894
|
+
return config2.apiKey;
|
|
1872
1895
|
};
|
|
1873
|
-
const resolveHeaders = async (params) => typeof
|
|
1896
|
+
const resolveHeaders = async (params) => typeof config2.headers === "function" ? await config2.headers(params) : config2.headers ?? {};
|
|
1874
1897
|
return instrumentAIProvider({
|
|
1875
|
-
inputCapacity:
|
|
1898
|
+
inputCapacity: config2.transformRequestBody ? undefined : openaiInputCapacity({
|
|
1876
1899
|
baseUrl,
|
|
1877
1900
|
fetch: fetchImpl,
|
|
1878
1901
|
key: resolveKey,
|
|
1879
1902
|
headers: resolveHeaders,
|
|
1880
|
-
modelLimits:
|
|
1881
|
-
body: (params) => buildResponsesRequestBody(params, false,
|
|
1903
|
+
modelLimits: config2.modelLimits,
|
|
1904
|
+
body: (params) => buildResponsesRequestBody(params, false, config2.modelForCapabilities?.(params.model) ?? params.model)
|
|
1882
1905
|
}),
|
|
1883
1906
|
stream: (params) => {
|
|
1884
|
-
const openaiBody = buildRequestBody(params,
|
|
1885
|
-
const body =
|
|
1907
|
+
const openaiBody = buildRequestBody(params, config2.modelForCapabilities?.(params.model) ?? params.model, providerName);
|
|
1908
|
+
const body = config2.transformRequestBody ? config2.transformRequestBody(openaiBody, params) : openaiBody;
|
|
1886
1909
|
return async function* () {
|
|
1887
1910
|
const [apiKey, headers] = await Promise.all([
|
|
1888
1911
|
resolveKey(),
|
|
@@ -1895,37 +1918,37 @@ var openai = (config) => {
|
|
|
1895
1918
|
};
|
|
1896
1919
|
|
|
1897
1920
|
// src/ai/providers/openaiCompatible.ts
|
|
1898
|
-
var alibaba = (
|
|
1899
|
-
apiKey:
|
|
1921
|
+
var alibaba = (config2) => openaiCompatible({
|
|
1922
|
+
apiKey: config2.apiKey,
|
|
1900
1923
|
baseUrl: "https://dashscope-intl.aliyuncs.com/compatible-mode"
|
|
1901
1924
|
});
|
|
1902
|
-
var deepseek2 = (
|
|
1903
|
-
apiKey:
|
|
1925
|
+
var deepseek2 = (config2) => openaiCompatible({
|
|
1926
|
+
apiKey: config2.apiKey,
|
|
1904
1927
|
baseUrl: "https://api.deepseek.com"
|
|
1905
1928
|
});
|
|
1906
|
-
var google = (
|
|
1907
|
-
apiKey:
|
|
1929
|
+
var google = (config2) => openaiCompatible({
|
|
1930
|
+
apiKey: config2.apiKey,
|
|
1908
1931
|
baseUrl: "https://generativelanguage.googleapis.com/v1beta/openai"
|
|
1909
1932
|
});
|
|
1910
|
-
var meta = (
|
|
1911
|
-
apiKey:
|
|
1933
|
+
var meta = (config2) => openaiCompatible({
|
|
1934
|
+
apiKey: config2.apiKey,
|
|
1912
1935
|
baseUrl: "https://api.llama.com/compat/v1"
|
|
1913
1936
|
});
|
|
1914
|
-
var mistralai = (
|
|
1915
|
-
apiKey:
|
|
1937
|
+
var mistralai = (config2) => openaiCompatible({
|
|
1938
|
+
apiKey: config2.apiKey,
|
|
1916
1939
|
baseUrl: "https://api.mistral.ai"
|
|
1917
1940
|
});
|
|
1918
|
-
var moonshot = (
|
|
1919
|
-
apiKey:
|
|
1941
|
+
var moonshot = (config2) => openaiCompatible({
|
|
1942
|
+
apiKey: config2.apiKey,
|
|
1920
1943
|
baseUrl: "https://api.moonshot.ai"
|
|
1921
1944
|
});
|
|
1922
|
-
var openaiCompatible = (
|
|
1923
|
-
apiKey:
|
|
1924
|
-
baseUrl:
|
|
1925
|
-
tokenSource:
|
|
1945
|
+
var openaiCompatible = (config2) => openai({
|
|
1946
|
+
apiKey: config2.apiKey,
|
|
1947
|
+
baseUrl: config2.baseUrl,
|
|
1948
|
+
tokenSource: config2.tokenSource
|
|
1926
1949
|
});
|
|
1927
|
-
var xai = (
|
|
1928
|
-
apiKey:
|
|
1950
|
+
var xai = (config2) => openaiCompatible({
|
|
1951
|
+
apiKey: config2.apiKey,
|
|
1929
1952
|
baseUrl: "https://api.x.ai"
|
|
1930
1953
|
});
|
|
1931
1954
|
export {
|
|
@@ -1939,5 +1962,5 @@ export {
|
|
|
1939
1962
|
xai
|
|
1940
1963
|
};
|
|
1941
1964
|
|
|
1942
|
-
//# debugId=
|
|
1965
|
+
//# debugId=75857A2215203E8264756E2164756E21
|
|
1943
1966
|
//# sourceMappingURL=openaiCompatible.js.map
|