@umituz/web-ai 1.0.11 → 1.2.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.
Files changed (48) hide show
  1. package/README.md +29 -3
  2. package/dist/{cancellation-error-_39nYWwz.d.cts → cancellation-error-BWb59Wkj.d.cts} +1 -1
  3. package/dist/{cancellation-error-hYcE9AS9.d.ts → cancellation-error-D9LETLCD.d.ts} +1 -1
  4. package/dist/chat/index.cjs +1 -0
  5. package/dist/chat/index.cjs.map +1 -1
  6. package/dist/chat/index.js +1 -0
  7. package/dist/chat/index.js.map +1 -1
  8. package/dist/content/index.cjs +622 -8
  9. package/dist/content/index.cjs.map +1 -1
  10. package/dist/content/index.d.cts +2 -2
  11. package/dist/content/index.d.ts +2 -2
  12. package/dist/content/index.js +622 -8
  13. package/dist/content/index.js.map +1 -1
  14. package/dist/context-manager-CuZz0vnC.d.cts +104 -0
  15. package/dist/context-manager-CuZz0vnC.d.ts +104 -0
  16. package/dist/core/index.cjs +147 -10
  17. package/dist/core/index.cjs.map +1 -1
  18. package/dist/core/index.d.cts +91 -73
  19. package/dist/core/index.d.ts +91 -73
  20. package/dist/core/index.js +141 -11
  21. package/dist/core/index.js.map +1 -1
  22. package/dist/{create-ai-D-oEWzf9.d.ts → create-ai-Cq3HkJxd.d.ts} +61 -1
  23. package/dist/{create-ai-DRysRImc.d.cts → create-ai-DDyTVzef.d.cts} +61 -1
  24. package/dist/hooks/index.cjs +747 -15
  25. package/dist/hooks/index.cjs.map +1 -1
  26. package/dist/hooks/index.d.cts +57 -4
  27. package/dist/hooks/index.d.ts +57 -4
  28. package/dist/hooks/index.js +746 -16
  29. package/dist/hooks/index.js.map +1 -1
  30. package/dist/index.cjs +1180 -242
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.d.cts +7 -6
  33. package/dist/index.d.ts +7 -6
  34. package/dist/index.js +1140 -243
  35. package/dist/index.js.map +1 -1
  36. package/dist/providers/index.cjs +1212 -362
  37. package/dist/providers/index.cjs.map +1 -1
  38. package/dist/providers/index.d.cts +422 -10
  39. package/dist/providers/index.d.ts +422 -10
  40. package/dist/providers/index.js +1179 -363
  41. package/dist/providers/index.js.map +1 -1
  42. package/dist/remote-chat-client-LrNlew4n.d.cts +70 -0
  43. package/dist/remote-chat-client-LrNlew4n.d.ts +70 -0
  44. package/dist/{requestQueue-D89wx91Q.d.cts → requestQueue--h2uZ-Q3.d.cts} +1 -1
  45. package/dist/{requestQueue-AP6n_bRH.d.ts → requestQueue-BGeCy4Fd.d.ts} +1 -1
  46. package/package.json +1 -1
  47. package/dist/tool-call-accumulator-C7KhaXZA.d.cts +0 -69
  48. package/dist/tool-call-accumulator-C7KhaXZA.d.ts +0 -69
@@ -0,0 +1,70 @@
1
+ interface StreamCallbacks<TToolCall = unknown> {
2
+ onDelta(channel: 'answer' | 'reasoning', text: string): void;
3
+ onUsage?(usage: {
4
+ inputTokens: number;
5
+ outputTokens: number;
6
+ reasoningTokens?: number;
7
+ }): void;
8
+ onToolCall?(toolCall: TToolCall): void;
9
+ onDone?(messageId: string): void;
10
+ onError?(code: string, message: string): void;
11
+ }
12
+ type ParsedSseEvent<TToolCall = unknown> = {
13
+ readonly type: 'delta';
14
+ readonly channel: 'answer' | 'reasoning';
15
+ readonly text: string;
16
+ } | {
17
+ readonly type: 'usage';
18
+ readonly usage: {
19
+ readonly inputTokens: number;
20
+ readonly outputTokens: number;
21
+ readonly reasoningTokens?: number;
22
+ };
23
+ } | {
24
+ readonly type: 'tool_call';
25
+ readonly toolCall: TToolCall;
26
+ } | {
27
+ readonly type: 'done';
28
+ readonly messageId: string;
29
+ } | {
30
+ readonly type: 'error';
31
+ readonly code: string;
32
+ readonly message: string;
33
+ };
34
+ declare function parseSseEvent<TToolCall = unknown>(rawEvent: string): ParsedSseEvent<TToolCall> | null;
35
+ declare function readSseResponse<TToolCall = unknown>(response: Response, callbacks: StreamCallbacks<TToolCall>): Promise<void>;
36
+
37
+ /** Body the backend chat endpoint expects. Kept generic on purpose —
38
+ * `settings` is whatever the app's API contract defines. */
39
+ interface RemoteChatStreamBody {
40
+ readonly mode?: "append" | "regenerate";
41
+ readonly content?: string;
42
+ readonly modelId?: string;
43
+ readonly settings?: Record<string, unknown>;
44
+ }
45
+ /** Endpoint templates; both are required so the client never guesses URL
46
+ * shapes. Example:
47
+ * `{ stream: (id) => \`/api/conversations/${id}/stream\`,
48
+ * resolveToolCall: (id, callId) => \`/api/conversations/${id}/tool-calls/${callId}/resolve\` }` */
49
+ interface RemoteChatUrls {
50
+ readonly stream: (conversationId: string) => string;
51
+ readonly resolveToolCall: (conversationId: string, toolCallId: string) => string;
52
+ }
53
+ interface RemoteChatClientOptions {
54
+ readonly urls: RemoteChatUrls;
55
+ readonly fetchImpl?: typeof fetch;
56
+ }
57
+ interface RemoteStreamHandle {
58
+ readonly promise: Promise<void>;
59
+ abort(): void;
60
+ }
61
+ interface RemoteChatClient {
62
+ /** POST the chat request and dispatch the SSE stream to `callbacks`. */
63
+ streamChat<TToolCall = unknown>(conversationId: string, body: RemoteChatStreamBody, callbacks: StreamCallbacks<TToolCall>): RemoteStreamHandle;
64
+ /** Approve/reject a pending tool call. Resolves true when the server
65
+ * answered with a continuation stream (consumed into `callbacks`). */
66
+ resolveToolCall<TToolCall = unknown>(conversationId: string, toolCallId: string, approved: boolean, callbacks: StreamCallbacks<TToolCall>): Promise<boolean>;
67
+ }
68
+ declare function createRemoteChatClient(options: RemoteChatClientOptions): RemoteChatClient;
69
+
70
+ export { type ParsedSseEvent as P, type RemoteChatClient as R, type StreamCallbacks as S, type RemoteChatClientOptions as a, type RemoteChatStreamBody as b, type RemoteChatUrls as c, type RemoteStreamHandle as d, createRemoteChatClient as e, parseSseEvent as p, readSseResponse as r };
@@ -0,0 +1,70 @@
1
+ interface StreamCallbacks<TToolCall = unknown> {
2
+ onDelta(channel: 'answer' | 'reasoning', text: string): void;
3
+ onUsage?(usage: {
4
+ inputTokens: number;
5
+ outputTokens: number;
6
+ reasoningTokens?: number;
7
+ }): void;
8
+ onToolCall?(toolCall: TToolCall): void;
9
+ onDone?(messageId: string): void;
10
+ onError?(code: string, message: string): void;
11
+ }
12
+ type ParsedSseEvent<TToolCall = unknown> = {
13
+ readonly type: 'delta';
14
+ readonly channel: 'answer' | 'reasoning';
15
+ readonly text: string;
16
+ } | {
17
+ readonly type: 'usage';
18
+ readonly usage: {
19
+ readonly inputTokens: number;
20
+ readonly outputTokens: number;
21
+ readonly reasoningTokens?: number;
22
+ };
23
+ } | {
24
+ readonly type: 'tool_call';
25
+ readonly toolCall: TToolCall;
26
+ } | {
27
+ readonly type: 'done';
28
+ readonly messageId: string;
29
+ } | {
30
+ readonly type: 'error';
31
+ readonly code: string;
32
+ readonly message: string;
33
+ };
34
+ declare function parseSseEvent<TToolCall = unknown>(rawEvent: string): ParsedSseEvent<TToolCall> | null;
35
+ declare function readSseResponse<TToolCall = unknown>(response: Response, callbacks: StreamCallbacks<TToolCall>): Promise<void>;
36
+
37
+ /** Body the backend chat endpoint expects. Kept generic on purpose —
38
+ * `settings` is whatever the app's API contract defines. */
39
+ interface RemoteChatStreamBody {
40
+ readonly mode?: "append" | "regenerate";
41
+ readonly content?: string;
42
+ readonly modelId?: string;
43
+ readonly settings?: Record<string, unknown>;
44
+ }
45
+ /** Endpoint templates; both are required so the client never guesses URL
46
+ * shapes. Example:
47
+ * `{ stream: (id) => \`/api/conversations/${id}/stream\`,
48
+ * resolveToolCall: (id, callId) => \`/api/conversations/${id}/tool-calls/${callId}/resolve\` }` */
49
+ interface RemoteChatUrls {
50
+ readonly stream: (conversationId: string) => string;
51
+ readonly resolveToolCall: (conversationId: string, toolCallId: string) => string;
52
+ }
53
+ interface RemoteChatClientOptions {
54
+ readonly urls: RemoteChatUrls;
55
+ readonly fetchImpl?: typeof fetch;
56
+ }
57
+ interface RemoteStreamHandle {
58
+ readonly promise: Promise<void>;
59
+ abort(): void;
60
+ }
61
+ interface RemoteChatClient {
62
+ /** POST the chat request and dispatch the SSE stream to `callbacks`. */
63
+ streamChat<TToolCall = unknown>(conversationId: string, body: RemoteChatStreamBody, callbacks: StreamCallbacks<TToolCall>): RemoteStreamHandle;
64
+ /** Approve/reject a pending tool call. Resolves true when the server
65
+ * answered with a continuation stream (consumed into `callbacks`). */
66
+ resolveToolCall<TToolCall = unknown>(conversationId: string, toolCallId: string, approved: boolean, callbacks: StreamCallbacks<TToolCall>): Promise<boolean>;
67
+ }
68
+ declare function createRemoteChatClient(options: RemoteChatClientOptions): RemoteChatClient;
69
+
70
+ export { type ParsedSseEvent as P, type RemoteChatClient as R, type StreamCallbacks as S, type RemoteChatClientOptions as a, type RemoteChatStreamBody as b, type RemoteChatUrls as c, type RemoteStreamHandle as d, createRemoteChatClient as e, parseSseEvent as p, readSseResponse as r };
@@ -2,7 +2,7 @@ import { f as AspectRatio, o as ImageQuality, w as VideoQuality, t as SentimentA
2
2
  import { B as BlogGenerationRequest, G as GeneratedBlog, m as SocialContentRequest, h as GeneratedSocialContent, q as VideoScriptRequest, i as GeneratedVideoScript, c as ContentTone, b as ContentCalendarEntry, n as SocialPlatform, E as Emotion } from './index-BulSkB2L.cjs';
3
3
  import { c as ITextGenerator, e as ProviderFactory, T as TextGenerationOptions } from './provider.factory-Ce6Een1G.cjs';
4
4
  import { d as ProviderConfig, I as ImageGenerationRequest, G as GeneratedContent, V as VideoGenerationRequest, a as ImageToVideoRequest, b as VideoToVideoRequest } from './ProviderConfig-DIFa9nmG.cjs';
5
- import { A as AIProviderConfig } from './create-ai-DRysRImc.cjs';
5
+ import { A as AIProviderConfig } from './create-ai-DDyTVzef.cjs';
6
6
  import { T as TextRequest, G as GenerationResult } from './index-OhvYUTXf.cjs';
7
7
 
8
8
  declare function resolveDimensionsForAspectRatio(ratio: AspectRatio): {
@@ -2,7 +2,7 @@ import { f as AspectRatio, o as ImageQuality, w as VideoQuality, t as SentimentA
2
2
  import { B as BlogGenerationRequest, G as GeneratedBlog, m as SocialContentRequest, h as GeneratedSocialContent, q as VideoScriptRequest, i as GeneratedVideoScript, c as ContentTone, b as ContentCalendarEntry, n as SocialPlatform, E as Emotion } from './index-BUVULo3h.js';
3
3
  import { c as ITextGenerator, e as ProviderFactory, T as TextGenerationOptions } from './provider.factory-B9RNUTYj.js';
4
4
  import { d as ProviderConfig, I as ImageGenerationRequest, G as GeneratedContent, V as VideoGenerationRequest, a as ImageToVideoRequest, b as VideoToVideoRequest } from './ProviderConfig-DIFa9nmG.js';
5
- import { A as AIProviderConfig } from './create-ai-D-oEWzf9.js';
5
+ import { A as AIProviderConfig } from './create-ai-Cq3HkJxd.js';
6
6
  import { T as TextRequest, G as GenerationResult } from './index-OhvYUTXf.js';
7
7
 
8
8
  declare function resolveDimensionsForAspectRatio(ratio: AspectRatio): {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/web-ai",
3
- "version": "1.0.11",
3
+ "version": "1.2.0",
4
4
  "description": "Provider-agnostic AI engine for web and edge — text, chat, structured output and streaming over swappable providers (Anthropic, Groq, Gemini, fal, Pruna), plus a content generation suite",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -1,69 +0,0 @@
1
- interface RetryOptions {
2
- readonly maxAttempts?: number;
3
- readonly initialDelay?: number;
4
- readonly maxDelay?: number;
5
- readonly backoffMultiplier?: number;
6
- readonly jitterFactor?: number;
7
- readonly shouldRetry?: (error: Error) => boolean;
8
- }
9
- declare class RetryManager {
10
- private readonly defaults;
11
- constructor();
12
- execute<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
13
- private shouldRetry;
14
- private delay;
15
- }
16
- declare const retryManager: RetryManager;
17
- declare function withRetry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
18
-
19
- interface QueueOptions {
20
- readonly maxConcurrent?: number;
21
- readonly defaultPriority?: number;
22
- readonly requestTimeout?: number;
23
- }
24
- declare class RequestQueue {
25
- private queue;
26
- private readonly activeRequests;
27
- private readonly maxConcurrent;
28
- private readonly defaultPriority;
29
- private readonly requestTimeout;
30
- private requestIdCounter;
31
- constructor(options?: QueueOptions);
32
- add<T>(requestFn: () => Promise<T>, priority?: number): Promise<T>;
33
- cancelAll(): void;
34
- private sortQueue;
35
- private process;
36
- private executeRequest;
37
- }
38
- declare const requestQueue: RequestQueue;
39
-
40
- declare class RequestDeduplicator {
41
- private readonly pendingRequests;
42
- private readonly ttl;
43
- constructor(ttl?: number);
44
- execute<T>(key: string, requestFn: () => Promise<T>): Promise<T>;
45
- cancelAll(): void;
46
- private cleanup;
47
- }
48
- declare const requestDeduplicator: RequestDeduplicator;
49
-
50
- interface WireToolCallDelta {
51
- readonly index?: number;
52
- readonly id?: string;
53
- readonly function?: {
54
- readonly name?: string;
55
- readonly arguments?: string;
56
- };
57
- }
58
- interface AssistantToolCall {
59
- readonly id: string;
60
- readonly name: string;
61
- readonly arguments: string;
62
- }
63
- declare class ToolCallAccumulator {
64
- private readonly slots;
65
- push(delta: WireToolCallDelta): void;
66
- finish(): AssistantToolCall[];
67
- }
68
-
69
- export { type AssistantToolCall as A, type QueueOptions as Q, RequestDeduplicator as R, ToolCallAccumulator as T, type WireToolCallDelta as W, RequestQueue as a, RetryManager as b, type RetryOptions as c, requestQueue as d, retryManager as e, requestDeduplicator as r, withRetry as w };
@@ -1,69 +0,0 @@
1
- interface RetryOptions {
2
- readonly maxAttempts?: number;
3
- readonly initialDelay?: number;
4
- readonly maxDelay?: number;
5
- readonly backoffMultiplier?: number;
6
- readonly jitterFactor?: number;
7
- readonly shouldRetry?: (error: Error) => boolean;
8
- }
9
- declare class RetryManager {
10
- private readonly defaults;
11
- constructor();
12
- execute<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
13
- private shouldRetry;
14
- private delay;
15
- }
16
- declare const retryManager: RetryManager;
17
- declare function withRetry<T>(fn: () => Promise<T>, options?: RetryOptions): Promise<T>;
18
-
19
- interface QueueOptions {
20
- readonly maxConcurrent?: number;
21
- readonly defaultPriority?: number;
22
- readonly requestTimeout?: number;
23
- }
24
- declare class RequestQueue {
25
- private queue;
26
- private readonly activeRequests;
27
- private readonly maxConcurrent;
28
- private readonly defaultPriority;
29
- private readonly requestTimeout;
30
- private requestIdCounter;
31
- constructor(options?: QueueOptions);
32
- add<T>(requestFn: () => Promise<T>, priority?: number): Promise<T>;
33
- cancelAll(): void;
34
- private sortQueue;
35
- private process;
36
- private executeRequest;
37
- }
38
- declare const requestQueue: RequestQueue;
39
-
40
- declare class RequestDeduplicator {
41
- private readonly pendingRequests;
42
- private readonly ttl;
43
- constructor(ttl?: number);
44
- execute<T>(key: string, requestFn: () => Promise<T>): Promise<T>;
45
- cancelAll(): void;
46
- private cleanup;
47
- }
48
- declare const requestDeduplicator: RequestDeduplicator;
49
-
50
- interface WireToolCallDelta {
51
- readonly index?: number;
52
- readonly id?: string;
53
- readonly function?: {
54
- readonly name?: string;
55
- readonly arguments?: string;
56
- };
57
- }
58
- interface AssistantToolCall {
59
- readonly id: string;
60
- readonly name: string;
61
- readonly arguments: string;
62
- }
63
- declare class ToolCallAccumulator {
64
- private readonly slots;
65
- push(delta: WireToolCallDelta): void;
66
- finish(): AssistantToolCall[];
67
- }
68
-
69
- export { type AssistantToolCall as A, type QueueOptions as Q, RequestDeduplicator as R, ToolCallAccumulator as T, type WireToolCallDelta as W, RequestQueue as a, RetryManager as b, type RetryOptions as c, requestQueue as d, retryManager as e, requestDeduplicator as r, withRetry as w };