@absolutejs/ai 0.0.56 → 0.0.58
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 +23 -0
- package/README.md +74 -0
- package/changelog.json +47 -0
- package/dist/ai/index.js +1419 -778
- package/dist/ai/index.js.map +15 -11
- 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 +7 -0
- package/dist/src/ai/inputCapacity.d.ts +25 -0
- package/dist/src/ai/prepareTextInput.d.ts +33 -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/src/ai/streamAIWithTools.d.ts +4 -0
- package/dist/src/ai/textSource.d.ts +19 -0
- package/dist/types/ai.d.ts +5 -0
- package/package.json +11 -6
package/dist/src/ai/index.d.ts
CHANGED
|
@@ -37,3 +37,10 @@ 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";
|
|
44
|
+
export { createAITextSource } from "./textSource";
|
|
45
|
+
export type { AITextPassage, AITextSource } from "./textSource";
|
|
46
|
+
export type { AITextPreparationCheckpoint } 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,33 @@
|
|
|
1
|
+
import type { AIProviderConfig, AIProviderStreamParams, AIUsage } from "../../types/ai";
|
|
2
|
+
export type AITextPreparationCheckpoint = {
|
|
3
|
+
version: 1;
|
|
4
|
+
taskHash: string;
|
|
5
|
+
prefixHash: string;
|
|
6
|
+
processedCharacters: number;
|
|
7
|
+
sectionsProcessed: number;
|
|
8
|
+
notes: string;
|
|
9
|
+
};
|
|
10
|
+
export type PreparedAITextInput = {
|
|
11
|
+
params: AIProviderStreamParams;
|
|
12
|
+
compacted: boolean;
|
|
13
|
+
sectionsProcessed: number;
|
|
14
|
+
};
|
|
15
|
+
export type PrepareAITextInputOptions = {
|
|
16
|
+
/** Reuse only a server-owned checkpoint. Originals and task fingerprints are validated. */
|
|
17
|
+
checkpoint?: AITextPreparationCheckpoint;
|
|
18
|
+
/** Save after each finished section, before the next model call. Never accept client-supplied notes. */
|
|
19
|
+
onCheckpoint?: (checkpoint: AITextPreparationCheckpoint) => void | Promise<void>;
|
|
20
|
+
/** Persist originals BEFORE calling. Returned notes are not a replacement for source storage. */
|
|
21
|
+
onProgress?: (progress: {
|
|
22
|
+
processedCharacters: number;
|
|
23
|
+
totalCharacters: number;
|
|
24
|
+
sectionsProcessed: number;
|
|
25
|
+
}) => void;
|
|
26
|
+
/** Each section is a real model call; applications must meter its usage. */
|
|
27
|
+
onUsage?: (usage: AIUsage) => void;
|
|
28
|
+
};
|
|
29
|
+
/** Fit text using this provider's tokenizer and model capacity. Never truncates source.
|
|
30
|
+
* Oversized conversations are read sequentially into rolling notes, with every section
|
|
31
|
+
* counted before generation. Originals and tool history are never mutated.
|
|
32
|
+
*/
|
|
33
|
+
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>;
|
|
@@ -3,6 +3,10 @@ import { type GenerateAIOptions, type GenerateAIToolCall } from "./generateAI";
|
|
|
3
3
|
export type StreamAIWithToolsOptions = Omit<GenerateAIOptions, "tools" | "toolChoice"> & {
|
|
4
4
|
/** Tools the model may call — each with a `handler` the loop runs on its behalf. */
|
|
5
5
|
tools: AIToolMap;
|
|
6
|
+
/** Stop immediately after one of these tools executes successfully; do not generate an extra reply. */
|
|
7
|
+
stopAfterTools?: string[];
|
|
8
|
+
/** Count every model request, including added tool results, against provider capacity. */
|
|
9
|
+
validateInput?: boolean;
|
|
6
10
|
/** Max model⇄tool round-trips before forcing a final answer. Default 8. */
|
|
7
11
|
maxTurns?: number;
|
|
8
12
|
toolChoice?: AIProviderToolChoice;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { AIProviderMessage, AIToolMap } from "../../types/ai";
|
|
2
|
+
export type AITextPassage = {
|
|
3
|
+
sourceId: string;
|
|
4
|
+
role: AIProviderMessage["role"];
|
|
5
|
+
start: number;
|
|
6
|
+
end: number;
|
|
7
|
+
totalCharacters: number;
|
|
8
|
+
text: string;
|
|
9
|
+
};
|
|
10
|
+
/** Session-scoped, read-only access to original text. No network or model calls.
|
|
11
|
+
* IDs/UTF-16 offsets stay stable when later messages are appended. Results carry
|
|
12
|
+
* verbatim source, not generated summaries. Persist originals separately.
|
|
13
|
+
*/
|
|
14
|
+
export declare const createAITextSource: (messages: readonly AIProviderMessage[]) => {
|
|
15
|
+
search: (query: string, sourceId?: string) => AITextPassage[];
|
|
16
|
+
read: (sourceId: string, start?: number, length?: number) => AITextPassage;
|
|
17
|
+
tools: AIToolMap;
|
|
18
|
+
};
|
|
19
|
+
export type AITextSource = ReturnType<typeof createAITextSource>;
|
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.58",
|
|
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"
|