@umituz/web-ai 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/README.md +98 -2
- package/dist/AIErrors-B2ogd1PB.d.ts +197 -0
- package/dist/AIErrors-C5EasV_c.d.cts +197 -0
- package/dist/ContentGeneration-B6iK2B33.d.cts +93 -0
- package/dist/ContentGeneration-B6iK2B33.d.ts +93 -0
- package/dist/ProviderConfig-DIFa9nmG.d.cts +108 -0
- package/dist/ProviderConfig-DIFa9nmG.d.ts +108 -0
- package/dist/cache-manager-Df9LLYGA.d.cts +31 -0
- package/dist/cache-manager-Df9LLYGA.d.ts +31 -0
- package/dist/chat/index.cjs +625 -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 +618 -0
- package/dist/chat/index.js.map +1 -0
- package/dist/chat.service-CL1qtYxe.d.cts +124 -0
- package/dist/chat.service-q05GnhEm.d.ts +124 -0
- package/dist/content/index.cjs +3976 -0
- package/dist/content/index.cjs.map +1 -0
- package/dist/content/index.d.cts +224 -0
- package/dist/content/index.d.ts +224 -0
- package/dist/content/index.js +3945 -0
- package/dist/content/index.js.map +1 -0
- package/dist/core/index.cjs +1137 -0
- package/dist/core/index.cjs.map +1 -0
- package/dist/core/index.d.cts +204 -0
- package/dist/core/index.d.ts +204 -0
- package/dist/core/index.js +1064 -0
- package/dist/core/index.js.map +1 -0
- package/dist/create-ai-DOI9jD3v.d.cts +251 -0
- package/dist/create-ai-DXEoke8-.d.ts +251 -0
- package/dist/hooks/index.cjs +5246 -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 +5235 -0
- package/dist/hooks/index.js.map +1 -0
- package/dist/index-DIHz8_OJ.d.ts +48 -0
- package/dist/index-DKHNcMbl.d.cts +48 -0
- package/dist/index-fXjxTR5W.d.cts +66 -0
- package/dist/index-fXjxTR5W.d.ts +66 -0
- package/dist/index.cjs +3309 -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 +3197 -0
- package/dist/index.js.map +1 -0
- package/dist/provider.factory-BxsfK4WW.d.cts +110 -0
- package/dist/provider.factory-DfDfk0dK.d.ts +110 -0
- package/dist/providers/index.cjs +2567 -0
- package/dist/providers/index.cjs.map +1 -0
- package/dist/providers/index.d.cts +332 -0
- package/dist/providers/index.d.ts +332 -0
- package/dist/providers/index.js +2533 -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 +114 -4
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { c as TextTier } from './index-fXjxTR5W.js';
|
|
2
|
+
|
|
3
|
+
declare enum AIErrorType {
|
|
4
|
+
INVALID_API_KEY = "INVALID_API_KEY",
|
|
5
|
+
MISSING_CONFIG = "MISSING_CONFIG",
|
|
6
|
+
NETWORK_ERROR = "NETWORK_ERROR",
|
|
7
|
+
ABORT_ERROR = "ABORT_ERROR",
|
|
8
|
+
RATE_LIMIT_ERROR = "RATE_LIMIT_ERROR",
|
|
9
|
+
SERVER_ERROR = "SERVER_ERROR",
|
|
10
|
+
CLIENT_ERROR = "CLIENT_ERROR",
|
|
11
|
+
UNKNOWN_ERROR = "UNKNOWN_ERROR"
|
|
12
|
+
}
|
|
13
|
+
declare const USER_FRIENDLY_ERROR_MESSAGES: Readonly<Record<AIErrorType, string>>;
|
|
14
|
+
|
|
15
|
+
interface AIErrorMetadata {
|
|
16
|
+
readonly status?: number;
|
|
17
|
+
readonly url?: string;
|
|
18
|
+
readonly [key: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
declare class AIError extends Error {
|
|
21
|
+
readonly type: AIErrorType;
|
|
22
|
+
readonly code: string;
|
|
23
|
+
readonly cause?: unknown;
|
|
24
|
+
readonly metadata: AIErrorMetadata;
|
|
25
|
+
constructor(typeOrMessage: AIErrorType | string, messageOrCode?: string, cause?: unknown, metadata?: AIErrorMetadata);
|
|
26
|
+
static from(error: unknown, fallbackCode?: string): AIError;
|
|
27
|
+
toString(): string;
|
|
28
|
+
toJSON(): {
|
|
29
|
+
name: string;
|
|
30
|
+
type: AIErrorType;
|
|
31
|
+
code: string;
|
|
32
|
+
message: string;
|
|
33
|
+
metadata: AIErrorMetadata;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Per-provider default model per tier. Config can override any slot; an
|
|
39
|
+
* explicit `model` on a request overrides everything. This table is the knob
|
|
40
|
+
* that turns "switch from Claude to Groq" into a config edit.
|
|
41
|
+
*/
|
|
42
|
+
type TierModelMap = Readonly<Partial<Record<TextTier, string>>>;
|
|
43
|
+
declare const TEXT_TIERS: ReadonlyArray<TextTier>;
|
|
44
|
+
declare function isTextTier(value: unknown): value is TextTier;
|
|
45
|
+
declare function resolveModel(tiers: TierModelMap, tier: TextTier, providerId: string): string;
|
|
46
|
+
declare function mergeTierOverrides(defaults: TierModelMap, overrides?: TierModelMap): TierModelMap;
|
|
47
|
+
|
|
48
|
+
export { AIError as A, TEXT_TIERS as T, USER_FRIENDLY_ERROR_MESSAGES as U, type AIErrorMetadata as a, AIErrorType as b, type TierModelMap as c, isTextTier as i, mergeTierOverrides as m, resolveModel as r };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { c as TextTier } from './index-fXjxTR5W.cjs';
|
|
2
|
+
|
|
3
|
+
declare enum AIErrorType {
|
|
4
|
+
INVALID_API_KEY = "INVALID_API_KEY",
|
|
5
|
+
MISSING_CONFIG = "MISSING_CONFIG",
|
|
6
|
+
NETWORK_ERROR = "NETWORK_ERROR",
|
|
7
|
+
ABORT_ERROR = "ABORT_ERROR",
|
|
8
|
+
RATE_LIMIT_ERROR = "RATE_LIMIT_ERROR",
|
|
9
|
+
SERVER_ERROR = "SERVER_ERROR",
|
|
10
|
+
CLIENT_ERROR = "CLIENT_ERROR",
|
|
11
|
+
UNKNOWN_ERROR = "UNKNOWN_ERROR"
|
|
12
|
+
}
|
|
13
|
+
declare const USER_FRIENDLY_ERROR_MESSAGES: Readonly<Record<AIErrorType, string>>;
|
|
14
|
+
|
|
15
|
+
interface AIErrorMetadata {
|
|
16
|
+
readonly status?: number;
|
|
17
|
+
readonly url?: string;
|
|
18
|
+
readonly [key: string]: unknown;
|
|
19
|
+
}
|
|
20
|
+
declare class AIError extends Error {
|
|
21
|
+
readonly type: AIErrorType;
|
|
22
|
+
readonly code: string;
|
|
23
|
+
readonly cause?: unknown;
|
|
24
|
+
readonly metadata: AIErrorMetadata;
|
|
25
|
+
constructor(typeOrMessage: AIErrorType | string, messageOrCode?: string, cause?: unknown, metadata?: AIErrorMetadata);
|
|
26
|
+
static from(error: unknown, fallbackCode?: string): AIError;
|
|
27
|
+
toString(): string;
|
|
28
|
+
toJSON(): {
|
|
29
|
+
name: string;
|
|
30
|
+
type: AIErrorType;
|
|
31
|
+
code: string;
|
|
32
|
+
message: string;
|
|
33
|
+
metadata: AIErrorMetadata;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Per-provider default model per tier. Config can override any slot; an
|
|
39
|
+
* explicit `model` on a request overrides everything. This table is the knob
|
|
40
|
+
* that turns "switch from Claude to Groq" into a config edit.
|
|
41
|
+
*/
|
|
42
|
+
type TierModelMap = Readonly<Partial<Record<TextTier, string>>>;
|
|
43
|
+
declare const TEXT_TIERS: ReadonlyArray<TextTier>;
|
|
44
|
+
declare function isTextTier(value: unknown): value is TextTier;
|
|
45
|
+
declare function resolveModel(tiers: TierModelMap, tier: TextTier, providerId: string): string;
|
|
46
|
+
declare function mergeTierOverrides(defaults: TierModelMap, overrides?: TierModelMap): TierModelMap;
|
|
47
|
+
|
|
48
|
+
export { AIError as A, TEXT_TIERS as T, USER_FRIENDLY_ERROR_MESSAGES as U, type AIErrorMetadata as a, AIErrorType as b, type TierModelMap as c, isTextTier as i, mergeTierOverrides as m, resolveModel as r };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider-neutral types shared by every layer of @umituz/web-ai.
|
|
3
|
+
* Nothing in this file imports a provider — the whole point of the package
|
|
4
|
+
* is that swapping Groq for Claude (or vice versa) is a config change, and
|
|
5
|
+
* these types are the vocabulary that makes that possible.
|
|
6
|
+
*/
|
|
7
|
+
/** Neutral quality tier — providers map it onto their own concrete models. */
|
|
8
|
+
type TextTier = "fast" | "balanced" | "powerful";
|
|
9
|
+
/** Why the model stopped generating, normalized across providers. */
|
|
10
|
+
type FinishReason = "stop" | "length" | "content_filter" | "refusal";
|
|
11
|
+
/** Token accounting, normalized from each provider's native usage shape. */
|
|
12
|
+
interface TokenUsage {
|
|
13
|
+
readonly inputTokens: number;
|
|
14
|
+
readonly outputTokens: number;
|
|
15
|
+
readonly totalTokens?: number;
|
|
16
|
+
}
|
|
17
|
+
/** What every text-generating method returns — usage is never discarded. */
|
|
18
|
+
interface GenerationResult {
|
|
19
|
+
readonly text: string;
|
|
20
|
+
readonly usage?: TokenUsage;
|
|
21
|
+
readonly model: string;
|
|
22
|
+
readonly providerId: string;
|
|
23
|
+
readonly finishReason?: FinishReason;
|
|
24
|
+
}
|
|
25
|
+
/** Universal chat message shape; providers translate to their own wire format. */
|
|
26
|
+
interface ChatMessage {
|
|
27
|
+
readonly role: "system" | "user" | "assistant";
|
|
28
|
+
readonly content: string;
|
|
29
|
+
}
|
|
30
|
+
interface TextRequest {
|
|
31
|
+
/** Full conversation, oldest first. systemPrompt is preferred over system roles here. */
|
|
32
|
+
readonly messages: ReadonlyArray<ChatMessage>;
|
|
33
|
+
/** Top-level system instruction; providers that need it in-band map it themselves. */
|
|
34
|
+
readonly systemPrompt?: string;
|
|
35
|
+
/** Explicit model id — always wins over tier resolution. */
|
|
36
|
+
readonly model?: string;
|
|
37
|
+
/** Neutral quality tier; resolved against the serving provider's model map. */
|
|
38
|
+
readonly tier?: TextTier;
|
|
39
|
+
readonly maxTokens?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Sampling hints. Honored by providers whose API still supports sampling
|
|
42
|
+
* parameters (Groq, Gemini); ignored by Anthropic — its current API version
|
|
43
|
+
* rejects temperature/top_p outright, so the Anthropic provider never puts
|
|
44
|
+
* them on the wire.
|
|
45
|
+
*/
|
|
46
|
+
readonly temperature?: number;
|
|
47
|
+
readonly topP?: number;
|
|
48
|
+
readonly stopSequences?: ReadonlyArray<string>;
|
|
49
|
+
readonly signal?: AbortSignal;
|
|
50
|
+
}
|
|
51
|
+
interface StreamCallbacks {
|
|
52
|
+
readonly onChunk?: (text: string) => void;
|
|
53
|
+
readonly onComplete?: (result: GenerationResult) => void;
|
|
54
|
+
readonly onError?: (error: Error) => void;
|
|
55
|
+
}
|
|
56
|
+
interface StructuredTextRequest extends TextRequest {
|
|
57
|
+
/** JSON schema describing the expected object; embedded into the prompt. */
|
|
58
|
+
readonly schema: Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
interface StructuredGeneration<T> {
|
|
61
|
+
readonly value: T;
|
|
62
|
+
readonly result: GenerationResult;
|
|
63
|
+
}
|
|
64
|
+
type ProviderHealth = "healthy" | "degraded" | "exhausted" | "unavailable";
|
|
65
|
+
|
|
66
|
+
export type { ChatMessage as C, FinishReason as F, GenerationResult as G, ProviderHealth as P, StreamCallbacks as S, TextRequest as T, StructuredGeneration as a, StructuredTextRequest as b, TextTier as c, TokenUsage as d };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider-neutral types shared by every layer of @umituz/web-ai.
|
|
3
|
+
* Nothing in this file imports a provider — the whole point of the package
|
|
4
|
+
* is that swapping Groq for Claude (or vice versa) is a config change, and
|
|
5
|
+
* these types are the vocabulary that makes that possible.
|
|
6
|
+
*/
|
|
7
|
+
/** Neutral quality tier — providers map it onto their own concrete models. */
|
|
8
|
+
type TextTier = "fast" | "balanced" | "powerful";
|
|
9
|
+
/** Why the model stopped generating, normalized across providers. */
|
|
10
|
+
type FinishReason = "stop" | "length" | "content_filter" | "refusal";
|
|
11
|
+
/** Token accounting, normalized from each provider's native usage shape. */
|
|
12
|
+
interface TokenUsage {
|
|
13
|
+
readonly inputTokens: number;
|
|
14
|
+
readonly outputTokens: number;
|
|
15
|
+
readonly totalTokens?: number;
|
|
16
|
+
}
|
|
17
|
+
/** What every text-generating method returns — usage is never discarded. */
|
|
18
|
+
interface GenerationResult {
|
|
19
|
+
readonly text: string;
|
|
20
|
+
readonly usage?: TokenUsage;
|
|
21
|
+
readonly model: string;
|
|
22
|
+
readonly providerId: string;
|
|
23
|
+
readonly finishReason?: FinishReason;
|
|
24
|
+
}
|
|
25
|
+
/** Universal chat message shape; providers translate to their own wire format. */
|
|
26
|
+
interface ChatMessage {
|
|
27
|
+
readonly role: "system" | "user" | "assistant";
|
|
28
|
+
readonly content: string;
|
|
29
|
+
}
|
|
30
|
+
interface TextRequest {
|
|
31
|
+
/** Full conversation, oldest first. systemPrompt is preferred over system roles here. */
|
|
32
|
+
readonly messages: ReadonlyArray<ChatMessage>;
|
|
33
|
+
/** Top-level system instruction; providers that need it in-band map it themselves. */
|
|
34
|
+
readonly systemPrompt?: string;
|
|
35
|
+
/** Explicit model id — always wins over tier resolution. */
|
|
36
|
+
readonly model?: string;
|
|
37
|
+
/** Neutral quality tier; resolved against the serving provider's model map. */
|
|
38
|
+
readonly tier?: TextTier;
|
|
39
|
+
readonly maxTokens?: number;
|
|
40
|
+
/**
|
|
41
|
+
* Sampling hints. Honored by providers whose API still supports sampling
|
|
42
|
+
* parameters (Groq, Gemini); ignored by Anthropic — its current API version
|
|
43
|
+
* rejects temperature/top_p outright, so the Anthropic provider never puts
|
|
44
|
+
* them on the wire.
|
|
45
|
+
*/
|
|
46
|
+
readonly temperature?: number;
|
|
47
|
+
readonly topP?: number;
|
|
48
|
+
readonly stopSequences?: ReadonlyArray<string>;
|
|
49
|
+
readonly signal?: AbortSignal;
|
|
50
|
+
}
|
|
51
|
+
interface StreamCallbacks {
|
|
52
|
+
readonly onChunk?: (text: string) => void;
|
|
53
|
+
readonly onComplete?: (result: GenerationResult) => void;
|
|
54
|
+
readonly onError?: (error: Error) => void;
|
|
55
|
+
}
|
|
56
|
+
interface StructuredTextRequest extends TextRequest {
|
|
57
|
+
/** JSON schema describing the expected object; embedded into the prompt. */
|
|
58
|
+
readonly schema: Record<string, unknown>;
|
|
59
|
+
}
|
|
60
|
+
interface StructuredGeneration<T> {
|
|
61
|
+
readonly value: T;
|
|
62
|
+
readonly result: GenerationResult;
|
|
63
|
+
}
|
|
64
|
+
type ProviderHealth = "healthy" | "degraded" | "exhausted" | "unavailable";
|
|
65
|
+
|
|
66
|
+
export type { ChatMessage as C, FinishReason as F, GenerationResult as G, ProviderHealth as P, StreamCallbacks as S, TextRequest as T, StructuredGeneration as a, StructuredTextRequest as b, TextTier as c, TokenUsage as d };
|