@absolutejs/ai 0.0.56 → 0.0.57
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 +17 -0
- package/README.md +42 -0
- package/changelog.json +30 -0
- package/dist/ai/index.js +1261 -778
- package/dist/ai/index.js.map +13 -10
- package/dist/ai/providers/anthropic.js +117 -1
- package/dist/ai/providers/anthropic.js.map +7 -6
- package/dist/ai/providers/gemini.js +97 -4
- package/dist/ai/providers/gemini.js.map +7 -6
- package/dist/ai/providers/ollama.js +3 -1
- package/dist/ai/providers/ollama.js.map +4 -4
- package/dist/ai/providers/openai.js +875 -41
- package/dist/ai/providers/openai.js.map +9 -6
- package/dist/ai/providers/openaiCompatible.js +875 -41
- package/dist/ai/providers/openaiCompatible.js.map +9 -6
- package/dist/ai/providers/openaiResponses.js +297 -3
- package/dist/ai/providers/openaiResponses.js.map +8 -6
- package/dist/ai/providers/openrouter.js +1088 -737
- package/dist/ai/providers/openrouter.js.map +10 -8
- package/dist/src/ai/index.d.ts +4 -0
- package/dist/src/ai/inputCapacity.d.ts +25 -0
- package/dist/src/ai/prepareTextInput.d.ts +21 -0
- package/dist/src/ai/providers/gemini.d.ts +1 -0
- package/dist/src/ai/providers/openai.d.ts +1 -0
- package/dist/src/ai/providers/openaiCapacity.d.ts +11 -0
- package/dist/src/ai/providers/openaiResponses.d.ts +2 -0
- package/dist/src/ai/providers/openrouterClient.d.ts +1 -1
- package/dist/types/ai.d.ts +5 -0
- package/package.json +11 -6
package/dist/src/ai/index.d.ts
CHANGED
|
@@ -37,3 +37,7 @@ export { fetchProviderApiStatus, startProviderStatusMonitor, } from "./providerS
|
|
|
37
37
|
export type { ProviderApiStatus, ProviderStatusMonitorOptions, } from "./providerStatusMonitor";
|
|
38
38
|
export * from "../../types/ai";
|
|
39
39
|
export type { SessionStore } from "../../types/session";
|
|
40
|
+
export { AIInputError, inspectAIInput } from "./inputCapacity";
|
|
41
|
+
export type { AIModelLimits, AIInputCapacity } from "./inputCapacity";
|
|
42
|
+
export { prepareAITextInput } from "./prepareTextInput";
|
|
43
|
+
export type { PreparedAITextInput, PrepareAITextInputOptions, } from "./prepareTextInput";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { AIProviderConfig, AIProviderStreamParams } from "../../types/ai";
|
|
2
|
+
/** Provider-reported limits. Some providers have separate input/output windows. */
|
|
3
|
+
export type AIModelLimits = {
|
|
4
|
+
maxInputTokens: number;
|
|
5
|
+
maxOutputTokens: number;
|
|
6
|
+
contextWindowTokens?: number;
|
|
7
|
+
};
|
|
8
|
+
export type AIInputCapacity = {
|
|
9
|
+
limits: AIModelLimits;
|
|
10
|
+
inputTokens: number;
|
|
11
|
+
outputTokens: number;
|
|
12
|
+
availableInputTokens: number;
|
|
13
|
+
fits: boolean;
|
|
14
|
+
};
|
|
15
|
+
export declare class AIInputError extends Error {
|
|
16
|
+
readonly code: "capacity_unavailable" | "input_too_large" | "unsupported_content";
|
|
17
|
+
constructor(code: "capacity_unavailable" | "input_too_large" | "unsupported_content", message: string);
|
|
18
|
+
}
|
|
19
|
+
export declare const positiveTokenLimit: (value: unknown) => number;
|
|
20
|
+
export declare const inputTokenCount: (value: unknown) => number;
|
|
21
|
+
/** No character/token conversion guesses. Includes the serialized prompt and tools. */
|
|
22
|
+
export declare const inspectAIInput: (provider: AIProviderConfig, params: AIProviderStreamParams) => Promise<AIInputCapacity>;
|
|
23
|
+
/** Cache metadata per provider instance; use a zero TTL with rotating auth/headers. never cache failures. */
|
|
24
|
+
export declare const cacheModelLimits: (load: (params: AIProviderStreamParams) => Promise<AIModelLimits>, ttlMs?: number) => (params: AIProviderStreamParams) => Promise<AIModelLimits>;
|
|
25
|
+
export declare const capacityJson: (response: Response) => Promise<Record<string, unknown>>;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { AIProviderConfig, AIProviderStreamParams, AIUsage } from "../../types/ai";
|
|
2
|
+
export type PreparedAITextInput = {
|
|
3
|
+
params: AIProviderStreamParams;
|
|
4
|
+
compacted: boolean;
|
|
5
|
+
sectionsProcessed: number;
|
|
6
|
+
};
|
|
7
|
+
export type PrepareAITextInputOptions = {
|
|
8
|
+
/** Persist originals BEFORE calling. Returned notes are not a replacement for source storage. */
|
|
9
|
+
onProgress?: (progress: {
|
|
10
|
+
processedCharacters: number;
|
|
11
|
+
totalCharacters: number;
|
|
12
|
+
sectionsProcessed: number;
|
|
13
|
+
}) => void;
|
|
14
|
+
/** Each section is a real model call; applications must meter its usage. */
|
|
15
|
+
onUsage?: (usage: AIUsage) => void;
|
|
16
|
+
};
|
|
17
|
+
/** Fit text using this provider's tokenizer and model capacity. Never truncates source.
|
|
18
|
+
* Oversized conversations are read sequentially into rolling notes, with every section
|
|
19
|
+
* counted before generation. Originals and tool history are never mutated.
|
|
20
|
+
*/
|
|
21
|
+
export declare const prepareAITextInput: (provider: AIProviderConfig, params: AIProviderStreamParams, options?: PrepareAITextInputOptions) => Promise<PreparedAITextInput>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AIProviderConfig, AIProviderStreamParams } from "../../../types/ai";
|
|
2
2
|
export type OpenAIConfig = {
|
|
3
|
+
modelLimits?: (params: AIProviderStreamParams) => Promise<import("../inputCapacity").AIModelLimits>;
|
|
3
4
|
apiKey?: string;
|
|
4
5
|
baseUrl?: string;
|
|
5
6
|
fetch?: typeof globalThis.fetch;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { AIProviderConfig, AIProviderStreamParams } from "../../../types/ai";
|
|
2
|
+
import { type AIModelLimits } from "../inputCapacity";
|
|
3
|
+
export declare const openaiInputCapacity: (config: {
|
|
4
|
+
baseUrl: string;
|
|
5
|
+
fetch: typeof globalThis.fetch;
|
|
6
|
+
key: () => Promise<string>;
|
|
7
|
+
headers: (params: AIProviderStreamParams) => Promise<HeadersInit>;
|
|
8
|
+
body: (params: AIProviderStreamParams) => Record<string, unknown>;
|
|
9
|
+
/** For private deployments or models not yet in the documented catalog. */
|
|
10
|
+
modelLimits?: (params: AIProviderStreamParams) => Promise<AIModelLimits>;
|
|
11
|
+
}) => NonNullable<AIProviderConfig["inputCapacity"]>;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { AIProviderConfig, AIProviderStreamParams } from "../../../types/ai";
|
|
2
2
|
export type OpenAIResponsesConfig = {
|
|
3
|
+
modelLimits?: (params: AIProviderStreamParams) => Promise<import("../inputCapacity").AIModelLimits>;
|
|
3
4
|
apiKey?: string;
|
|
4
5
|
baseUrl?: string;
|
|
5
6
|
fetch?: typeof globalThis.fetch;
|
|
@@ -10,4 +11,5 @@ export type OpenAIResponsesConfig = {
|
|
|
10
11
|
tokenSource?: () => Promise<string> | string;
|
|
11
12
|
transformRequestBody?: (body: Record<string, unknown>, params: AIProviderStreamParams) => Record<string, unknown>;
|
|
12
13
|
};
|
|
14
|
+
export declare const buildResponsesRequestBody: (params: AIProviderStreamParams, isImageModel: boolean, capabilityModel?: string) => Record<string, unknown>;
|
|
13
15
|
export declare const openaiResponses: (config: OpenAIResponsesConfig) => AIProviderConfig;
|
|
@@ -624,7 +624,7 @@ export declare const createOpenRouterClient: (config: OpenRouterClientConfig) =>
|
|
|
624
624
|
request: <T>(path: string, options?: OpenRouterHttpRequestOptions) => Promise<T>;
|
|
625
625
|
requestRaw: (path: string, options?: OpenRouterHttpRequestOptions) => Promise<Response>;
|
|
626
626
|
streamImage: (body: Omit<OpenRouterImageRequest, "stream">, options?: Omit<OpenRouterHttpRequestOptions, "body" | "method">) => AsyncGenerator<OpenRouterImageStreamEvent, void, any>;
|
|
627
|
-
respond: (body: OpenRouterResponsesRequest) => Promise<
|
|
627
|
+
respond: (body: OpenRouterResponsesRequest) => Promise<Record<string, unknown>> | Promise<Response>;
|
|
628
628
|
rerank: (body: OpenRouterRerankRequest) => Promise<OpenRouterRerankResponse>;
|
|
629
629
|
speak: (body: OpenRouterSpeechRequest) => Promise<Response>;
|
|
630
630
|
transcribe: (body: OpenRouterTranscriptionRequest | FormData) => Promise<OpenRouterTranscriptionResponse>;
|
package/dist/types/ai.d.ts
CHANGED
|
@@ -331,6 +331,11 @@ export type AIProviderToolDefinition = {
|
|
|
331
331
|
input_schema: Record<string, unknown>;
|
|
332
332
|
};
|
|
333
333
|
export type AIProviderConfig = {
|
|
334
|
+
inputCapacity?: {
|
|
335
|
+
outputTokens?: (params: AIProviderStreamParams) => number | undefined;
|
|
336
|
+
getLimits: (params: AIProviderStreamParams) => Promise<import("../src/ai/inputCapacity").AIModelLimits>;
|
|
337
|
+
countTokens: (params: AIProviderStreamParams) => Promise<number>;
|
|
338
|
+
};
|
|
334
339
|
stream: (params: AIProviderStreamParams) => AsyncIterable<AIChunk>;
|
|
335
340
|
};
|
|
336
341
|
/** MCP-shaped behavior hints (all optional). Consumers exposing an AIToolMap
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@absolutejs/ai",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.57",
|
|
4
4
|
"homepage": "https://github.com/absolutejs/ai",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/absolutejs/ai/issues"
|
|
@@ -11,8 +11,10 @@
|
|
|
11
11
|
"main": "./dist/ai/index.js",
|
|
12
12
|
"types": "./dist/src/ai/index.d.ts",
|
|
13
13
|
"files": [
|
|
14
|
-
"
|
|
15
|
-
"README.md"
|
|
14
|
+
"CHANGELOG.md",
|
|
15
|
+
"README.md",
|
|
16
|
+
"changelog.json",
|
|
17
|
+
"dist"
|
|
16
18
|
],
|
|
17
19
|
"exports": {
|
|
18
20
|
".": {
|
|
@@ -120,7 +122,9 @@
|
|
|
120
122
|
},
|
|
121
123
|
"devDependencies": {
|
|
122
124
|
"@absolutejs/absolute": "^0.20.0-beta.0",
|
|
125
|
+
"@absolutejs/changelog": "^0.6.0",
|
|
123
126
|
"@absolutejs/isolated-jsc": "0.6.0",
|
|
127
|
+
"@absolutejs/sync": "2.9.1",
|
|
124
128
|
"@angular/core": "^21.0.0",
|
|
125
129
|
"@eslint/js": "^10.0.1",
|
|
126
130
|
"@types/bun": "1.3.9",
|
|
@@ -135,8 +139,7 @@
|
|
|
135
139
|
"svelte": "5.55.0",
|
|
136
140
|
"typescript": "^5.9.3",
|
|
137
141
|
"typescript-eslint": "^8.56.1",
|
|
138
|
-
"vue": "3.5.27"
|
|
139
|
-
"@absolutejs/sync": "2.9.1"
|
|
142
|
+
"vue": "3.5.27"
|
|
140
143
|
},
|
|
141
144
|
"scripts": {
|
|
142
145
|
"build": "bun run scripts/build.ts",
|
|
@@ -144,7 +147,9 @@
|
|
|
144
147
|
"typecheck": "tsc --noEmit --project tsconfig.json",
|
|
145
148
|
"lint": "eslint . --max-warnings 0",
|
|
146
149
|
"format": "prettier --write .",
|
|
147
|
-
"release": "bun run format && bun run build && bun publish"
|
|
150
|
+
"release": "bun run format && bun run build && bun publish",
|
|
151
|
+
"check:package": "absolute-changelog check",
|
|
152
|
+
"prepublishOnly": "bun run check:package"
|
|
148
153
|
},
|
|
149
154
|
"publishConfig": {
|
|
150
155
|
"access": "public"
|