@umituz/web-ai 0.0.0-stage → 1.0.0
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/LICENSE +21 -0
- package/README.md +98 -2
- package/dist/ABTesting-DDqNhHtP.d.ts +184 -0
- package/dist/ABTesting-DWBtKTMQ.d.cts +184 -0
- package/dist/ContentGeneration-B6iK2B33.d.cts +93 -0
- package/dist/ContentGeneration-B6iK2B33.d.ts +93 -0
- package/dist/ProviderConfig-a55tLhWT.d.cts +99 -0
- package/dist/ProviderConfig-a55tLhWT.d.ts +99 -0
- package/dist/cache-manager-Df9LLYGA.d.cts +31 -0
- package/dist/cache-manager-Df9LLYGA.d.ts +31 -0
- package/dist/chat/index.cjs +534 -0
- package/dist/chat/index.cjs.map +1 -0
- package/dist/chat/index.d.cts +25 -0
- package/dist/chat/index.d.ts +25 -0
- package/dist/chat/index.js +527 -0
- package/dist/chat/index.js.map +1 -0
- package/dist/chat.service-DBKq9I2c.d.cts +124 -0
- package/dist/chat.service-RQn8UTXD.d.ts +124 -0
- package/dist/content/index.cjs +3769 -0
- package/dist/content/index.cjs.map +1 -0
- package/dist/content/index.d.cts +225 -0
- package/dist/content/index.d.ts +225 -0
- package/dist/content/index.js +3738 -0
- package/dist/content/index.js.map +1 -0
- package/dist/core/index.cjs +1040 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +232 -0
- package/dist/core/index.d.ts +232 -0
- package/dist/core/index.js +969 -0
- package/dist/core/index.js.map +1 -0
- package/dist/create-ai-BhNaz86i.d.ts +268 -0
- package/dist/create-ai-DGZFBOA1.d.cts +268 -0
- package/dist/hooks/index.cjs +5056 -0
- package/dist/hooks/index.cjs.map +1 -0
- package/dist/hooks/index.d.cts +210 -0
- package/dist/hooks/index.d.ts +210 -0
- package/dist/hooks/index.js +5045 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/index-DjX9ZKuM.d.cts +14 -0
- package/dist/index-DxLvE588.d.ts +14 -0
- package/dist/index-fXjxTR5W.d.cts +66 -0
- package/dist/index-fXjxTR5W.d.ts +66 -0
- package/dist/index.cjs +3158 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +11 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.js +3048 -0
- package/dist/index.js.map +1 -0
- package/dist/provider.factory-COsnprLH.d.cts +110 -0
- package/dist/provider.factory-CpWFyjbw.d.ts +110 -0
- package/dist/providers/index.cjs +2410 -0
- package/dist/providers/index.cjs.map +1 -0
- package/dist/providers/index.d.cts +333 -0
- package/dist/providers/index.d.ts +333 -0
- package/dist/providers/index.js +2376 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/request-deduplicator.util-NDo0_n1y.d.cts +50 -0
- package/dist/request-deduplicator.util-NDo0_n1y.d.ts +50 -0
- package/dist/wizard/index.cjs +230 -0
- package/dist/wizard/index.cjs.map +1 -0
- package/dist/wizard/index.d.cts +86 -0
- package/dist/wizard/index.d.ts +86 -0
- package/dist/wizard/index.js +223 -0
- package/dist/wizard/index.js.map +1 -0
- package/package.json +111 -4
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { c as TextTier } from './index-fXjxTR5W.cjs';
|
|
2
|
+
import { c as ProviderFactory } from './provider.factory-COsnprLH.cjs';
|
|
3
|
+
import { a as TierModelMap } from './index-DjX9ZKuM.cjs';
|
|
4
|
+
import { c as GeminiConfig, F as FalConfig, P as PrunaConfig } from './ProviderConfig-a55tLhWT.cjs';
|
|
5
|
+
|
|
6
|
+
type AIErrorCode = 'VALIDATION_ERROR' | 'PROVIDER_UNAVAILABLE' | 'PROVIDER_QUOTA_EXHAUSTED' | 'PROVIDER_ERROR' | 'NETWORK_ERROR' | 'TIMEOUT' | 'ABORTED' | 'PARSE_ERROR' | 'NO_RESULT' | 'UNKNOWN';
|
|
7
|
+
declare class AIError extends Error {
|
|
8
|
+
readonly code: AIErrorCode;
|
|
9
|
+
readonly cause?: unknown;
|
|
10
|
+
constructor(message: string, code: AIErrorCode, cause?: unknown);
|
|
11
|
+
static from(error: unknown, fallbackCode?: AIErrorCode): AIError;
|
|
12
|
+
}
|
|
13
|
+
declare class ValidationError extends AIError {
|
|
14
|
+
constructor(message: string);
|
|
15
|
+
}
|
|
16
|
+
declare class ProviderUnavailableError extends AIError {
|
|
17
|
+
constructor(providerId: string);
|
|
18
|
+
}
|
|
19
|
+
declare class ProviderQuotaExhaustedError extends AIError {
|
|
20
|
+
constructor(providerId: string);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
declare const ANTHROPIC_MODELS: {
|
|
24
|
+
readonly OPUS_5_5: "claude-opus-5-5";
|
|
25
|
+
readonly SONNET_5_5: "claude-sonnet-5-5";
|
|
26
|
+
readonly HAIKU_5_5: "claude-haiku-5-5";
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Neutral tier → Claude model. fast = Haiku for cheap high-volume turns,
|
|
30
|
+
* balanced = Sonnet for everyday quality, powerful = Opus for the heavy
|
|
31
|
+
* lifting. Override per instance via `models` in provider config.
|
|
32
|
+
*/
|
|
33
|
+
declare const ANTHROPIC_TIERS: TierModelMap;
|
|
34
|
+
/**
|
|
35
|
+
* Single bump point for the wire protocol version. Every request sends this
|
|
36
|
+
* as the `anthropic-version` header; the shapes in anthropic.entities.ts are
|
|
37
|
+
* pinned to it.
|
|
38
|
+
*/
|
|
39
|
+
declare const ANTHROPIC_API_VERSION: "2026-10-21";
|
|
40
|
+
/** The Messages API requires max_tokens on every request. */
|
|
41
|
+
declare const ANTHROPIC_DEFAULT_MAX_TOKENS = 16000;
|
|
42
|
+
type AnthropicEffort = "low" | "medium" | "high";
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Anthropic Messages API wire types, pinned to anthropic-version 2026-10-21.
|
|
46
|
+
* Two hard rules live here as types so the builder cannot violate them:
|
|
47
|
+
* - `max_tokens` is required on every request.
|
|
48
|
+
* - sampling parameters (temperature/top_p) are NOT part of this request
|
|
49
|
+
* shape — this API version rejects them with a 400.
|
|
50
|
+
*/
|
|
51
|
+
interface AnthropicProviderConfig {
|
|
52
|
+
readonly apiKey: string;
|
|
53
|
+
readonly baseUrl?: string;
|
|
54
|
+
readonly timeoutMs?: number;
|
|
55
|
+
/** Per-tier model overrides; merged over ANTHROPIC_TIERS. */
|
|
56
|
+
readonly models?: TierModelMap;
|
|
57
|
+
/** Reasoning effort hint; defaults come from ANTHROPIC_DEFAULT_EFFORT per model. */
|
|
58
|
+
readonly effort?: AnthropicEffort;
|
|
59
|
+
}
|
|
60
|
+
type AnthropicMessageRole = "user" | "assistant";
|
|
61
|
+
interface AnthropicMessage {
|
|
62
|
+
readonly role: AnthropicMessageRole;
|
|
63
|
+
readonly content: string;
|
|
64
|
+
}
|
|
65
|
+
interface AnthropicOutputConfig {
|
|
66
|
+
/** Reasoning effort: low | medium | high. Omitted when not specified. */
|
|
67
|
+
readonly effort?: AnthropicEffort;
|
|
68
|
+
}
|
|
69
|
+
interface AnthropicMessagesRequest {
|
|
70
|
+
readonly model: string;
|
|
71
|
+
readonly messages: AnthropicMessage[];
|
|
72
|
+
/** Required — the API rejects requests without it. */
|
|
73
|
+
readonly max_tokens: number;
|
|
74
|
+
/** Top-level system prompt slot; preferred over in-band system messages. */
|
|
75
|
+
readonly system?: string;
|
|
76
|
+
readonly output_config?: AnthropicOutputConfig;
|
|
77
|
+
readonly stop_sequences?: string[];
|
|
78
|
+
readonly stream?: boolean;
|
|
79
|
+
}
|
|
80
|
+
interface AnthropicTextBlock {
|
|
81
|
+
readonly type: "text";
|
|
82
|
+
readonly text: string;
|
|
83
|
+
}
|
|
84
|
+
type AnthropicContentBlock = AnthropicTextBlock;
|
|
85
|
+
type AnthropicStopReason = "end_turn" | "max_tokens" | "stop_sequence" | "refusal";
|
|
86
|
+
interface AnthropicUsage {
|
|
87
|
+
readonly input_tokens: number;
|
|
88
|
+
readonly output_tokens: number;
|
|
89
|
+
}
|
|
90
|
+
interface AnthropicMessagesResponse {
|
|
91
|
+
readonly id: string;
|
|
92
|
+
readonly type: "message";
|
|
93
|
+
readonly role: "assistant";
|
|
94
|
+
readonly model: string;
|
|
95
|
+
readonly content: AnthropicContentBlock[];
|
|
96
|
+
readonly stop_reason: AnthropicStopReason | null;
|
|
97
|
+
readonly stop_sequence: string | null;
|
|
98
|
+
readonly usage: AnthropicUsage;
|
|
99
|
+
}
|
|
100
|
+
interface AnthropicMessageStartEvent {
|
|
101
|
+
readonly type: "message_start";
|
|
102
|
+
readonly message: {
|
|
103
|
+
readonly id: string;
|
|
104
|
+
readonly model: string;
|
|
105
|
+
readonly usage?: AnthropicUsage;
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
interface AnthropicContentBlockDeltaEvent {
|
|
109
|
+
readonly type: "content_block_delta";
|
|
110
|
+
readonly index: number;
|
|
111
|
+
/** text_delta events carry text; other delta kinds (thinking etc.) don't. */
|
|
112
|
+
readonly delta: {
|
|
113
|
+
readonly type: string;
|
|
114
|
+
readonly text?: string;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
interface AnthropicMessageDeltaEvent {
|
|
118
|
+
readonly type: "message_delta";
|
|
119
|
+
readonly delta: {
|
|
120
|
+
readonly stop_reason?: AnthropicStopReason | null;
|
|
121
|
+
};
|
|
122
|
+
readonly usage?: AnthropicUsage;
|
|
123
|
+
}
|
|
124
|
+
interface AnthropicMessageStopEvent {
|
|
125
|
+
readonly type: "message_stop";
|
|
126
|
+
}
|
|
127
|
+
interface AnthropicErrorEvent {
|
|
128
|
+
readonly type: "error";
|
|
129
|
+
readonly error: {
|
|
130
|
+
readonly type: string;
|
|
131
|
+
readonly message: string;
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
type AnthropicStreamEvent = AnthropicMessageStartEvent | AnthropicContentBlockDeltaEvent | AnthropicMessageDeltaEvent | AnthropicMessageStopEvent | AnthropicErrorEvent;
|
|
135
|
+
|
|
136
|
+
/**
|
|
137
|
+
* Groq wire types. The `Groq` prefix is deliberate: these describe Groq's
|
|
138
|
+
* OpenAI-compatible chat/completions wire format and nothing else. Providers
|
|
139
|
+
* translate core `TextRequest`s into these; the rest of the package never
|
|
140
|
+
* sees them.
|
|
141
|
+
*/
|
|
142
|
+
interface GroqProviderConfig {
|
|
143
|
+
readonly apiKey: string;
|
|
144
|
+
readonly baseUrl?: string;
|
|
145
|
+
readonly timeoutMs?: number;
|
|
146
|
+
/** Per-tier model overrides; merged over GROQ_TIERS. */
|
|
147
|
+
readonly models?: TierModelMap;
|
|
148
|
+
}
|
|
149
|
+
type GroqReasoningEffort = "low" | "medium" | "high";
|
|
150
|
+
interface GroqGenerationConfig {
|
|
151
|
+
readonly temperature?: number;
|
|
152
|
+
readonly maxTokens?: number;
|
|
153
|
+
readonly topP?: number;
|
|
154
|
+
readonly n?: number;
|
|
155
|
+
readonly stop?: string[];
|
|
156
|
+
readonly frequencyPenalty?: number;
|
|
157
|
+
readonly presencePenalty?: number;
|
|
158
|
+
readonly reasoningEffort?: GroqReasoningEffort;
|
|
159
|
+
}
|
|
160
|
+
type GroqMessageRole = "system" | "user" | "assistant";
|
|
161
|
+
interface GroqMessage {
|
|
162
|
+
readonly role: GroqMessageRole;
|
|
163
|
+
readonly content: string;
|
|
164
|
+
}
|
|
165
|
+
interface GroqChatRequest {
|
|
166
|
+
readonly model: string;
|
|
167
|
+
readonly messages: GroqMessage[];
|
|
168
|
+
readonly temperature?: number;
|
|
169
|
+
readonly max_tokens?: number;
|
|
170
|
+
readonly top_p?: number;
|
|
171
|
+
readonly n?: number;
|
|
172
|
+
readonly stop?: string[];
|
|
173
|
+
readonly frequency_penalty?: number;
|
|
174
|
+
readonly presence_penalty?: number;
|
|
175
|
+
readonly reasoning_effort?: GroqReasoningEffort;
|
|
176
|
+
readonly response_format?: {
|
|
177
|
+
readonly type: "json_object";
|
|
178
|
+
};
|
|
179
|
+
readonly stream?: boolean;
|
|
180
|
+
}
|
|
181
|
+
type GroqFinishReason = "stop" | "length" | "content_filter";
|
|
182
|
+
interface GroqChoice {
|
|
183
|
+
readonly index: number;
|
|
184
|
+
readonly message: {
|
|
185
|
+
readonly role: "assistant";
|
|
186
|
+
readonly content: string;
|
|
187
|
+
};
|
|
188
|
+
readonly finish_reason: GroqFinishReason;
|
|
189
|
+
readonly logprobs: null | object;
|
|
190
|
+
}
|
|
191
|
+
interface GroqUsage {
|
|
192
|
+
readonly prompt_tokens: number;
|
|
193
|
+
readonly completion_tokens: number;
|
|
194
|
+
readonly total_tokens: number;
|
|
195
|
+
readonly prompt_time?: number;
|
|
196
|
+
readonly completion_time?: number;
|
|
197
|
+
readonly total_time?: number;
|
|
198
|
+
}
|
|
199
|
+
interface GroqChatResponse {
|
|
200
|
+
readonly id: string;
|
|
201
|
+
readonly object: string;
|
|
202
|
+
readonly created: number;
|
|
203
|
+
readonly model: string;
|
|
204
|
+
readonly choices: GroqChoice[];
|
|
205
|
+
readonly usage: GroqUsage;
|
|
206
|
+
readonly system_fingerprint?: string;
|
|
207
|
+
readonly x_groq?: {
|
|
208
|
+
readonly id?: string;
|
|
209
|
+
/** Present on the final chunk of a stream when usage accounting is enabled. */
|
|
210
|
+
readonly usage?: GroqUsage;
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
interface GroqChunkChoice {
|
|
214
|
+
readonly index: number;
|
|
215
|
+
readonly delta: {
|
|
216
|
+
readonly role?: "assistant";
|
|
217
|
+
readonly content?: string;
|
|
218
|
+
};
|
|
219
|
+
readonly finish_reason: GroqFinishReason | null;
|
|
220
|
+
readonly logprobs: null | object;
|
|
221
|
+
}
|
|
222
|
+
interface GroqChatChunk {
|
|
223
|
+
readonly id: string;
|
|
224
|
+
readonly object: string;
|
|
225
|
+
readonly created: number;
|
|
226
|
+
readonly model: string;
|
|
227
|
+
readonly choices: GroqChunkChoice[];
|
|
228
|
+
readonly system_fingerprint?: string;
|
|
229
|
+
readonly x_groq?: {
|
|
230
|
+
readonly id?: string;
|
|
231
|
+
readonly usage?: GroqUsage;
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
interface StreamRequestOptions {
|
|
235
|
+
readonly signal?: AbortSignal;
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* Composition root for the whole package — replaces the old
|
|
240
|
+
* `configureProvider()` singleton. A provider block's presence means the
|
|
241
|
+
* provider is enabled; presence of its apiKey is what actually registers it.
|
|
242
|
+
* `priority` decides who serves first; the fallback walk handles the rest.
|
|
243
|
+
*
|
|
244
|
+
* ```ts
|
|
245
|
+
* const ai = createAI({
|
|
246
|
+
* priority: ['anthropic', 'groq'],
|
|
247
|
+
* defaultTier: 'balanced',
|
|
248
|
+
* anthropic: { apiKey: env.ANTHROPIC_API_KEY },
|
|
249
|
+
* groq: { apiKey: env.GROQ_API_KEY },
|
|
250
|
+
* });
|
|
251
|
+
* const { text, usage } = await ai.chat({ messages, systemPrompt });
|
|
252
|
+
* ```
|
|
253
|
+
*/
|
|
254
|
+
interface AIProviderConfig {
|
|
255
|
+
/** Provider ids in preference order for every capability. */
|
|
256
|
+
priority?: ReadonlyArray<string>;
|
|
257
|
+
fallbackEnabled?: boolean;
|
|
258
|
+
/** Tier used when a request names neither model nor tier. Default 'balanced'. */
|
|
259
|
+
defaultTier?: TextTier;
|
|
260
|
+
anthropic?: AnthropicProviderConfig;
|
|
261
|
+
groq?: GroqProviderConfig;
|
|
262
|
+
gemini?: Omit<GeminiConfig, "enabled">;
|
|
263
|
+
fal?: Omit<FalConfig, "enabled">;
|
|
264
|
+
pruna?: Omit<PrunaConfig, "enabled">;
|
|
265
|
+
}
|
|
266
|
+
declare function createAI(config?: AIProviderConfig): ProviderFactory;
|
|
267
|
+
|
|
268
|
+
export { type AIProviderConfig as A, type GroqChatChunk as G, ProviderQuotaExhaustedError as P, type StreamRequestOptions as S, ValidationError as V, ANTHROPIC_API_VERSION as a, ANTHROPIC_DEFAULT_MAX_TOKENS as b, ANTHROPIC_MODELS as c, ANTHROPIC_TIERS as d, type AnthropicEffort as e, type AnthropicMessagesRequest as f, type AnthropicMessagesResponse as g, type AnthropicProviderConfig as h, type AnthropicStopReason as i, type AnthropicStreamEvent as j, type GroqChatRequest as k, type GroqChatResponse as l, type GroqMessage as m, type GroqProviderConfig as n, createAI as o, type AIErrorCode as p, AIError as q, ProviderUnavailableError as r, type AnthropicMessage as s, type GroqGenerationConfig as t };
|