@absolutejs/ai 0.2.5 → 0.2.7
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 +12 -0
- package/README.md +13 -0
- package/changelog.json +276 -244
- package/dist/ai/index.js +37 -15
- package/dist/ai/index.js.map +7 -7
- package/dist/ai/providers/anthropic.js +34 -15
- package/dist/ai/providers/anthropic.js.map +5 -5
- package/dist/ai/providers/gemini.js +3 -2
- package/dist/ai/providers/gemini.js.map +4 -4
- package/dist/ai/providers/ollama.js +2 -2
- package/dist/ai/providers/ollama.js.map +3 -3
- package/dist/ai/providers/openai.js +3 -2
- package/dist/ai/providers/openai.js.map +4 -4
- package/dist/ai/providers/openaiCompatible.js +3 -2
- package/dist/ai/providers/openaiCompatible.js.map +4 -4
- package/dist/ai/providers/openaiResponses.js +3 -2
- package/dist/ai/providers/openaiResponses.js.map +4 -4
- package/dist/ai/providers/openrouter.js +34 -15
- package/dist/ai/providers/openrouter.js.map +5 -5
- package/dist/ai/research.js +84 -0
- package/dist/ai/research.js.map +10 -0
- package/dist/src/ai/generateAI.d.ts +2 -0
- package/dist/src/ai/inputCapacity.d.ts +4 -0
- package/dist/src/ai/research.d.ts +33 -0
- package/dist/src/ai/research.test.d.ts +1 -0
- package/dist/types/ai.d.ts +4 -0
- package/package.json +7 -2
package/dist/ai/index.js
CHANGED
|
@@ -40,6 +40,7 @@ var inspectAIInput = async (provider, params) => {
|
|
|
40
40
|
return {
|
|
41
41
|
limits,
|
|
42
42
|
inputTokens,
|
|
43
|
+
inputTokenScope: provider.inputCapacity.countScope?.(params) ?? "request",
|
|
43
44
|
outputTokens,
|
|
44
45
|
availableInputTokens,
|
|
45
46
|
fits: outputTokens <= maxOutputTokens && inputTokens <= availableInputTokens
|
|
@@ -511,7 +512,7 @@ var withResilience = (provider, providerName = "unknown") => {
|
|
|
511
512
|
noteSuccess(providerName);
|
|
512
513
|
} catch (err) {
|
|
513
514
|
const providerError = ProviderError.from(err, providerName);
|
|
514
|
-
const canRetry = !yielded && providerError.retryable && attemptNo < config.maxRetries && !params.signal?.aborted;
|
|
515
|
+
const canRetry = !yielded && providerError.retryable && attemptNo < (params.maxRetries === undefined ? config.maxRetries : Math.max(0, Math.min(config.maxRetries, params.maxRetries))) && !params.signal?.aborted;
|
|
515
516
|
if (canRetry) {
|
|
516
517
|
await sleep(backoffDelay(attemptNo), params.signal);
|
|
517
518
|
yield* attempt(params, attemptNo + 1);
|
|
@@ -2886,6 +2887,35 @@ var anthropic = (config2) => {
|
|
|
2886
2887
|
signal: params.signal ? AbortSignal.any([params.signal, AbortSignal.timeout(15000)]) : AbortSignal.timeout(15000)
|
|
2887
2888
|
}));
|
|
2888
2889
|
};
|
|
2890
|
+
const countingRequest = (params) => {
|
|
2891
|
+
const built = buildRequestBody3(params, configuredMax, promptCaching);
|
|
2892
|
+
const body = config2.transformRequestBody ? config2.transformRequestBody(built, params) : built;
|
|
2893
|
+
const counted = {};
|
|
2894
|
+
for (const key of [
|
|
2895
|
+
"model",
|
|
2896
|
+
"messages",
|
|
2897
|
+
"system",
|
|
2898
|
+
"tools",
|
|
2899
|
+
"tool_choice",
|
|
2900
|
+
"thinking"
|
|
2901
|
+
])
|
|
2902
|
+
if (body[key] !== undefined)
|
|
2903
|
+
counted[key] = body[key];
|
|
2904
|
+
const tools = Array.isArray(body.tools) ? body.tools : [];
|
|
2905
|
+
const hosted = tools.filter((tool) => isRecord4(tool) && typeof tool.type === "string" && /^(web_search_|web_fetch_|code_execution_|bash_code_execution_|text_editor_code_execution_|tool_search_tool_)/u.test(tool.type));
|
|
2906
|
+
const scope = hosted.length > 0 || body.mcp_servers !== undefined ? "caller-input" : "request";
|
|
2907
|
+
if (hosted.length > 0) {
|
|
2908
|
+
const clientTools = tools.filter((tool) => !hosted.includes(tool));
|
|
2909
|
+
if (clientTools.length)
|
|
2910
|
+
counted.tools = clientTools;
|
|
2911
|
+
else
|
|
2912
|
+
delete counted.tools;
|
|
2913
|
+
const choice = counted.tool_choice;
|
|
2914
|
+
if (!clientTools.length || isRecord4(choice) && choice.type === "tool" && hosted.some((tool) => isRecord4(tool) && tool.name === choice.name))
|
|
2915
|
+
delete counted.tool_choice;
|
|
2916
|
+
}
|
|
2917
|
+
return { counted, scope };
|
|
2918
|
+
};
|
|
2889
2919
|
const inputCapacity = {
|
|
2890
2920
|
outputTokens: (params) => {
|
|
2891
2921
|
const built = buildRequestBody3(params, configuredMax, promptCaching);
|
|
@@ -2901,20 +2931,9 @@ var anthropic = (config2) => {
|
|
|
2901
2931
|
maxOutputTokens: positiveTokenLimit(data.max_tokens)
|
|
2902
2932
|
};
|
|
2903
2933
|
}, config2.tokenSource || typeof config2.headers === "function" ? 0 : 300000),
|
|
2934
|
+
countScope: (params) => countingRequest(params).scope,
|
|
2904
2935
|
countTokens: async (params) => {
|
|
2905
|
-
const
|
|
2906
|
-
const body = config2.transformRequestBody ? config2.transformRequestBody(built, params) : built;
|
|
2907
|
-
const counted = {};
|
|
2908
|
-
for (const key of [
|
|
2909
|
-
"model",
|
|
2910
|
-
"messages",
|
|
2911
|
-
"system",
|
|
2912
|
-
"tools",
|
|
2913
|
-
"tool_choice",
|
|
2914
|
-
"thinking"
|
|
2915
|
-
])
|
|
2916
|
-
if (body[key] !== undefined)
|
|
2917
|
-
counted[key] = body[key];
|
|
2936
|
+
const { counted } = countingRequest(params);
|
|
2918
2937
|
return inputTokenCount((await capacityRequest(params, "/v1/messages/count_tokens", counted)).input_tokens);
|
|
2919
2938
|
}
|
|
2920
2939
|
};
|
|
@@ -5631,6 +5650,7 @@ var generateAI = async (options) => {
|
|
|
5631
5650
|
const stream = streamWithAIContext(options.provider, {
|
|
5632
5651
|
cacheSystemPrompt: options.cacheSystemPrompt,
|
|
5633
5652
|
maxTokens: options.maxTokens,
|
|
5653
|
+
maxRetries: options.maxRetries,
|
|
5634
5654
|
messages: options.messages,
|
|
5635
5655
|
model: options.model,
|
|
5636
5656
|
promptCaching: options.promptCaching,
|
|
@@ -5835,6 +5855,7 @@ var generateObjectAI = async (options) => {
|
|
|
5835
5855
|
contextPolicy: options.contextPolicy,
|
|
5836
5856
|
cacheSystemPrompt: options.cacheSystemPrompt,
|
|
5837
5857
|
maxTokens: options.maxTokens,
|
|
5858
|
+
maxRetries: options.maxRetries,
|
|
5838
5859
|
messages,
|
|
5839
5860
|
model: options.model,
|
|
5840
5861
|
promptCaching: options.promptCaching,
|
|
@@ -8765,6 +8786,7 @@ var createAIProviderRouter = (routes) => {
|
|
|
8765
8786
|
outputTokens: (params) => capacity(params).outputTokens?.(params),
|
|
8766
8787
|
isContextError: (error) => [...new Set(providers.values())].some((provider) => provider.inputCapacity?.isContextError?.(error) === true),
|
|
8767
8788
|
getLimits: async (params) => capacity(params).getLimits(params),
|
|
8789
|
+
countScope: (params) => capacity(params).countScope?.(params) ?? "request",
|
|
8768
8790
|
countTokens: async (params) => capacity(params).countTokens(params)
|
|
8769
8791
|
},
|
|
8770
8792
|
stream: (params) => resolve(params).stream(params)
|
|
@@ -8880,5 +8902,5 @@ export {
|
|
|
8880
8902
|
xai
|
|
8881
8903
|
};
|
|
8882
8904
|
|
|
8883
|
-
//# debugId=
|
|
8905
|
+
//# debugId=F8FFC7094E06DA7B64756E2164756E21
|
|
8884
8906
|
//# sourceMappingURL=index.js.map
|