@lanonasis/ai-sdk 0.1.0 → 0.2.2

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.
@@ -0,0 +1,243 @@
1
+ /**
2
+ * Browser-safe HTTP Client for Lanonasis AI API
3
+ * Handles chat completions and orchestration endpoints
4
+ * Memory operations are handled by @lanonasis/memory-sdk
5
+ */
6
+ import { LanonasisError, AuthenticationError, RateLimitError, NetworkError, ValidationError, } from '../types/index.js';
7
+ export class HttpClient {
8
+ config;
9
+ rateLimitRemaining = Infinity;
10
+ rateLimitReset = 0;
11
+ constructor(config) {
12
+ this.config = config;
13
+ this.validateApiKey(config.apiKey);
14
+ }
15
+ /**
16
+ * Validate API key format
17
+ * Supports lano_ (primary), lnss_, vx_, and onasis_ (legacy) prefixes
18
+ * Aligned with auth-gateway api-key.service.ts
19
+ */
20
+ validateApiKey(apiKey) {
21
+ if (!apiKey) {
22
+ throw new AuthenticationError('API key is required');
23
+ }
24
+ // Support all key formats (aligned with auth-gateway)
25
+ // lano_ = primary format
26
+ // lnss_, vx_, onasis_ = legacy formats (deprecated but still supported)
27
+ const validPrefixes = ['lano_', 'lnss_', 'vx_', 'onasis_'];
28
+ const hasValidPrefix = validPrefixes.some(prefix => apiKey.startsWith(prefix));
29
+ if (!hasValidPrefix) {
30
+ // During migration period, allow keys without recognized prefix
31
+ // but log a warning in debug mode
32
+ if (this.config.debug) {
33
+ console.warn(`[Lanonasis AI SDK] API key with unknown prefix. Expected "lano_" prefix.`);
34
+ }
35
+ }
36
+ if (apiKey.length < 20) {
37
+ throw new AuthenticationError('API key appears to be too short');
38
+ }
39
+ }
40
+ /**
41
+ * Build request headers
42
+ */
43
+ buildHeaders(customHeaders) {
44
+ const headers = {
45
+ 'Content-Type': 'application/json',
46
+ 'Authorization': `Bearer ${this.config.apiKey}`,
47
+ 'X-Lanonasis-Client': '@lanonasis/ai-sdk',
48
+ 'X-Lanonasis-Version': '0.2.0',
49
+ ...this.config.headers,
50
+ ...customHeaders,
51
+ };
52
+ if (this.config.organizationId) {
53
+ headers['X-Lanonasis-Org'] = this.config.organizationId;
54
+ }
55
+ return headers;
56
+ }
57
+ sleep(ms) {
58
+ return new Promise(resolve => setTimeout(resolve, ms));
59
+ }
60
+ getRetryDelay(attempt, retryAfter) {
61
+ if (retryAfter) {
62
+ return retryAfter * 1000;
63
+ }
64
+ return Math.min(1000 * Math.pow(2, attempt), 30000);
65
+ }
66
+ isRetryable(status) {
67
+ return status === 429 || status >= 500;
68
+ }
69
+ async parseError(response) {
70
+ let errorData = {};
71
+ try {
72
+ errorData = await response.json();
73
+ }
74
+ catch {
75
+ errorData = { message: response.statusText };
76
+ }
77
+ const error = errorData.error;
78
+ const message = (error?.message || errorData.message || 'Request failed');
79
+ const code = (error?.code || 'UNKNOWN_ERROR');
80
+ switch (response.status) {
81
+ case 401:
82
+ return new AuthenticationError(message);
83
+ case 429:
84
+ const retryAfter = parseInt(response.headers.get('Retry-After') || '60', 10);
85
+ return new RateLimitError(message, retryAfter);
86
+ case 400:
87
+ return new ValidationError(message, error?.details);
88
+ default:
89
+ return new LanonasisError(message, code, response.status, errorData);
90
+ }
91
+ }
92
+ updateRateLimitInfo(headers) {
93
+ const remaining = headers.get('X-RateLimit-Remaining');
94
+ const reset = headers.get('X-RateLimit-Reset');
95
+ if (remaining) {
96
+ this.rateLimitRemaining = parseInt(remaining, 10);
97
+ }
98
+ if (reset) {
99
+ this.rateLimitReset = parseInt(reset, 10);
100
+ }
101
+ }
102
+ debug(message, data) {
103
+ if (this.config.debug) {
104
+ console.log(`[Lanonasis AI SDK] ${message}`, data || '');
105
+ }
106
+ }
107
+ /**
108
+ * Make HTTP request with retries
109
+ */
110
+ async request(options) {
111
+ const url = `${this.config.baseUrl}${options.path}`;
112
+ const headers = this.buildHeaders(options.headers);
113
+ const timeout = options.timeout || this.config.timeout;
114
+ let lastError = null;
115
+ for (let attempt = 0; attempt <= this.config.maxRetries; attempt++) {
116
+ try {
117
+ this.debug(`Request attempt ${attempt + 1}`, { method: options.method, url });
118
+ const controller = new AbortController();
119
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
120
+ const fetchOptions = {
121
+ method: options.method,
122
+ headers,
123
+ signal: controller.signal,
124
+ };
125
+ if (options.body && options.method !== 'GET') {
126
+ fetchOptions.body = JSON.stringify(options.body);
127
+ }
128
+ const response = await fetch(url, fetchOptions);
129
+ clearTimeout(timeoutId);
130
+ this.updateRateLimitInfo(response.headers);
131
+ if (response.ok) {
132
+ const data = await response.json();
133
+ this.debug('Request successful', { status: response.status });
134
+ // Convert headers to object (compatible with older TS targets)
135
+ const responseHeaders = {};
136
+ response.headers.forEach((value, key) => {
137
+ responseHeaders[key] = value;
138
+ });
139
+ return {
140
+ data,
141
+ status: response.status,
142
+ headers: responseHeaders,
143
+ };
144
+ }
145
+ const error = await this.parseError(response);
146
+ if (this.isRetryable(response.status) && attempt < this.config.maxRetries) {
147
+ const retryAfter = error instanceof RateLimitError ? error.retryAfter : undefined;
148
+ const delay = this.getRetryDelay(attempt, retryAfter);
149
+ this.debug(`Retrying after ${delay}ms`, { attempt, status: response.status });
150
+ await this.sleep(delay);
151
+ continue;
152
+ }
153
+ throw error;
154
+ }
155
+ catch (error) {
156
+ if (error instanceof LanonasisError) {
157
+ throw error;
158
+ }
159
+ if (error instanceof Error) {
160
+ if (error.name === 'AbortError') {
161
+ lastError = new NetworkError('Request timeout');
162
+ }
163
+ else {
164
+ lastError = new NetworkError(error.message);
165
+ }
166
+ }
167
+ if (attempt < this.config.maxRetries) {
168
+ const delay = this.getRetryDelay(attempt);
169
+ this.debug(`Network error, retrying after ${delay}ms`, { attempt });
170
+ await this.sleep(delay);
171
+ continue;
172
+ }
173
+ }
174
+ }
175
+ throw lastError || new NetworkError('Request failed after retries');
176
+ }
177
+ /**
178
+ * Make streaming request (for chat completions)
179
+ */
180
+ async *stream(options) {
181
+ const url = `${this.config.baseUrl}${options.path}`;
182
+ const headers = this.buildHeaders(options.headers);
183
+ const controller = new AbortController();
184
+ const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
185
+ try {
186
+ const response = await fetch(url, {
187
+ method: options.method,
188
+ headers: {
189
+ ...headers,
190
+ 'Accept': 'text/event-stream',
191
+ },
192
+ body: options.body ? JSON.stringify(options.body) : undefined,
193
+ signal: controller.signal,
194
+ });
195
+ clearTimeout(timeoutId);
196
+ if (!response.ok) {
197
+ throw await this.parseError(response);
198
+ }
199
+ if (!response.body) {
200
+ throw new NetworkError('No response body for streaming');
201
+ }
202
+ const reader = response.body.getReader();
203
+ const decoder = new TextDecoder();
204
+ while (true) {
205
+ const { done, value } = await reader.read();
206
+ if (done)
207
+ break;
208
+ const chunk = decoder.decode(value, { stream: true });
209
+ const lines = chunk.split('\n');
210
+ for (const line of lines) {
211
+ if (line.startsWith('data: ')) {
212
+ const data = line.slice(6);
213
+ if (data === '[DONE]')
214
+ return;
215
+ yield data;
216
+ }
217
+ }
218
+ }
219
+ }
220
+ finally {
221
+ clearTimeout(timeoutId);
222
+ }
223
+ }
224
+ get(path, headers) {
225
+ return this.request({ method: 'GET', path, headers });
226
+ }
227
+ post(path, body, headers) {
228
+ return this.request({ method: 'POST', path, body, headers });
229
+ }
230
+ put(path, body, headers) {
231
+ return this.request({ method: 'PUT', path, body, headers });
232
+ }
233
+ delete(path, headers) {
234
+ return this.request({ method: 'DELETE', path, headers });
235
+ }
236
+ getRateLimitStatus() {
237
+ return {
238
+ remaining: this.rateLimitRemaining,
239
+ reset: this.rateLimitReset,
240
+ };
241
+ }
242
+ }
243
+ //# sourceMappingURL=client.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/http/client.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,cAAc,EACd,mBAAmB,EACnB,cAAc,EACd,YAAY,EACZ,eAAe,GAChB,MAAM,mBAAmB,CAAC;AA2B3B,MAAM,OAAO,UAAU;IACb,MAAM,CAAmB;IACzB,k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AAI,EAAE,OAAO,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED,IAAI,CAAc,IAAY,EAAE,IAAc,EAAE,OAAgC;QAC9E,OAAO,IAAI,CAAC,OAAO,CAAI,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IAClE,CAAC;IAED,GAAG,CAAc,IAAY,EAAE,IAAc,EAAE,OAAgC;QAC7E,OAAO,IAAI,CAAC,OAAO,CAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IACjE,CAAC;IAED,MAAM,CAAc,IAAY,EAAE,OAAgC;QAChE,OAAO,IAAI,CAAC,OAAO,CAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC;IAC9D,CAAC;IAED,kBAAkB;QAChB,OAAO;YACL,SAAS,EAAE,IAAI,CAAC,kBAAkB;YAClC,KAAK,EAAE,IAAI,CAAC,cAAc;SAC3B,CAAC;IACJ,CAAC;CACF"}
package/dist/index.d.ts CHANGED
@@ -1,20 +1,53 @@
1
- import { L0Orchestrator, type L0QueryOptions, type L0Response, pluginManager, createPluginManager, type PluginManager } from 'vortexai-l0';
2
- export interface AiSDKOptions {
3
- /** Optional plugin manager for custom workflows */
4
- plugins?: PluginManager;
5
- }
6
1
  /**
7
- * Unified AI SDK facade for browser and Node.
8
- * Wraps the VortexAI L0 orchestrator and exposes a simple API surface.
2
+ * @lanonasis/ai-sdk v0.2.0
3
+ *
4
+ * Drop-in AI SDK for browser and Node.js applications
5
+ *
6
+ * Features:
7
+ * - API Key authentication (lnss_xxx... / onasis_xxx...)
8
+ * - Persistent memory via @lanonasis/memory-sdk
9
+ * - Chat completions with streaming
10
+ * - vortexai-l0 orchestration (local or remote)
11
+ * - Full TypeScript support
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { LanonasisAI } from '@lanonasis/ai-sdk';
16
+ *
17
+ * const ai = new LanonasisAI({ apiKey: 'lnss_your_key_here' });
18
+ *
19
+ * // Simple chat
20
+ * const response = await ai.send('Hello!');
21
+ * console.log(response);
22
+ *
23
+ * // With memory persistence
24
+ * const response = await ai.chat({
25
+ * messages: [{ role: 'user', content: 'Remember my name is Alex' }],
26
+ * conversationId: 'my-session',
27
+ * });
28
+ *
29
+ * // Use memory-sdk directly for advanced operations
30
+ * const context = await ai.memory.searchWithContext('my previous conversations');
31
+ * ```
32
+ */
33
+ export { LanonasisAI, createClient } from './client.js';
34
+ export { HttpClient } from './http/client.js';
35
+ export type { HttpClientConfig, RequestOptions, HttpResponse } from './http/client.js';
36
+ export * from './types/index.js';
37
+ export { default as MemoryClient } from '@lanonasis/memory-sdk-standalone';
38
+ export type { MaaSClientConfig as MemoryClientConfig, ApiResponse } from '@lanonasis/memory-sdk-standalone';
39
+ export { L0Orchestrator } from 'vortexai-l0/orchestrator';
40
+ export type { L0QueryOptions, L0Response } from 'vortexai-l0/orchestrator';
41
+ export { pluginManager, createPluginManager } from 'vortexai-l0/plugins';
42
+ export type { PluginManager } from 'vortexai-l0/plugins';
43
+ import { LanonasisAI } from './client.js';
44
+ /**
45
+ * @deprecated Use LanonasisAI instead
9
46
  */
10
- export declare class AiSDK {
11
- private orchestrator;
12
- constructor(options?: AiSDKOptions);
13
- /** Run an orchestration query */
14
- orchestrate(query: string, options?: L0QueryOptions): Promise<L0Response>;
15
- /** Direct access to underlying orchestrator */
16
- getOrchestrator(): L0Orchestrator;
47
+ export declare class AiSDK extends LanonasisAI {
48
+ constructor(config?: {
49
+ apiKey?: string;
50
+ });
17
51
  }
18
- export { L0Orchestrator, pluginManager, createPluginManager };
19
- export type { L0QueryOptions, L0Response, PluginManager };
52
+ export default LanonasisAI;
20
53
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,c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;AACzE,YAAY,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAGzD,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;GAEG;AACH,qBAAa,KAAM,SAAQ,WAAW;gBACxB,MAAM,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE;CAOzC;AAGD,eAAe,WAAW,CAAC"}
package/dist/index.js CHANGED
@@ -1,22 +1,60 @@
1
- import { L0Orchestrator, pluginManager, createPluginManager } from 'vortexai-l0';
2
1
  /**
3
- * Unified AI SDK facade for browser and Node.
4
- * Wraps the VortexAI L0 orchestrator and exposes a simple API surface.
2
+ * @lanonasis/ai-sdk v0.2.0
3
+ *
4
+ * Drop-in AI SDK for browser and Node.js applications
5
+ *
6
+ * Features:
7
+ * - API Key authentication (lnss_xxx... / onasis_xxx...)
8
+ * - Persistent memory via @lanonasis/memory-sdk
9
+ * - Chat completions with streaming
10
+ * - vortexai-l0 orchestration (local or remote)
11
+ * - Full TypeScript support
12
+ *
13
+ * @example
14
+ * ```ts
15
+ * import { LanonasisAI } from '@lanonasis/ai-sdk';
16
+ *
17
+ * const ai = new LanonasisAI({ apiKey: 'lnss_your_key_here' });
18
+ *
19
+ * // Simple chat
20
+ * const response = await ai.send('Hello!');
21
+ * console.log(response);
22
+ *
23
+ * // With memory persistence
24
+ * const response = await ai.chat({
25
+ * messages: [{ role: 'user', content: 'Remember my name is Alex' }],
26
+ * conversationId: 'my-session',
27
+ * });
28
+ *
29
+ * // Use memory-sdk directly for advanced operations
30
+ * const context = await ai.memory.searchWithContext('my previous conversations');
31
+ * ```
5
32
  */
6
- export class AiSDK {
7
- orchestrator;
8
- constructor(options) {
9
- this.orchestrator = new L0Orchestrator(options?.plugins);
10
- }
11
- /** Run an orchestration query */
12
- async orchestrate(query, options) {
13
- return this.orchestrator.query(query, options);
14
- }
15
- /** Direct access to underlying orchestrator */
16
- getOrchestrator() {
17
- return this.orchestrator;
33
+ // Main client
34
+ export { LanonasisAI, createClient } from './client.js';
35
+ // HTTP client (for advanced usage)
36
+ export { HttpClient } from './http/client.js';
37
+ // All types
38
+ export * from './types/index.js';
39
+ // Re-export memory-sdk for convenience
40
+ export { default as MemoryClient } from '@lanonasis/memory-sdk-standalone';
41
+ // Re-export vortexai-l0 primitives for power users (browser-safe imports)
42
+ export { L0Orchestrator } from 'vortexai-l0/orchestrator';
43
+ export { pluginManager, createPluginManager } from 'vortexai-l0/plugins';
44
+ // Legacy compatibility - AiSDK alias
45
+ import { LanonasisAI } from './client.js';
46
+ /**
47
+ * @deprecated Use LanonasisAI instead
48
+ */
49
+ export class AiSDK extends LanonasisAI {
50
+ constructor(config) {
51
+ super({
52
+ apiKey: config?.apiKey || process.env.LANONASIS_API_KEY || '',
53
+ baseUrl: process.env.LANONASIS_BASE_URL,
54
+ useLocalOrchestration: true, // Legacy behavior
55
+ });
18
56
  }
19
57
  }
20
- // Re-export orchestrator primitives for power users
21
- export { L0Orchestrator, pluginManager, createPluginManager };
58
+ // Default export
59
+ export default LanonasisAI;
22
60
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAwC,aAAa,EAAE,mBAAmB,EAAsB,MAAM,aAAa,CAAC;AAO3I;;;GAGG;AACH,MAAM,OAAO,KAAK;IACR,YAAY,CAAiB;IAErC,YAAY,OAAsB;QAChC,IAAI,CAAC,YAAY,GAAG,IAAI,cAAc,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IAC3D,CAAC;IAED,iCAAiC;IACjC,KAAK,CAAC,WAAW,CAAC,KAAa,EAAE,OAAwB;QACvD,OAAO,IAAI,CAAC,YAAY,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACjD,CAAC;IAED,+CAA+C;IAC/C,eAAe;QACb,OAAO,IAAI,CAAC,YAAY,CAAC;IAC3B,CAAC;CACF;AAED,oDAAoD;AACpD,OAAO,EAAE,cAAc,EAAE,aAAa,EAAE,mBAAmB,EAAE,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,cAAc;AACd,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAExD,mCAAmC;AACnC,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG9C,YAAY;AACZ,cAAc,kBAAkB,CAAC;AAEjC,uCAAuC;AACvC,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAG3E,0EAA0E;AAC1E,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAGzE,qCAAqC;AACrC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;GAEG;AACH,MAAM,OAAO,KAAM,SAAQ,WAAW;IACpC,YAAY,MAA4B;QACtC,KAAK,CAAC;YACJ,MAAM,EAAE,MAAM,EAAE,MAAM,IAAI,OAAO,CAAC,GAAG,CAAC,iBAAiB,IAAI,EAAE;YAC7D,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,kBAAkB;YACvC,qBAAqB,EAAE,IAAI,EAAE,kBAAkB;SAChD,CAAC,CAAC;IACL,CAAC;CACF;AAED,iBAAiB;AACjB,eAAe,WAAW,CAAC"}
@@ -0,0 +1,64 @@
1
+ /**
2
+ * React Hooks for @lanonasis/ai-sdk
3
+ * Optional: Only import if using React
4
+ *
5
+ * @example
6
+ * ```tsx
7
+ * import { useLanonasis, useChat } from '@lanonasis/ai-sdk/react';
8
+ *
9
+ * function ChatComponent() {
10
+ * const { client, isReady } = useLanonasis({ apiKey: 'lnss_xxx' });
11
+ * const { messages, send, isLoading } = useChat({ client });
12
+ *
13
+ * return <div>...</div>;
14
+ * }
15
+ * ```
16
+ */
17
+ import type { LanonasisConfig, Message } from '../types/index.js';
18
+ import { LanonasisAI } from '../client.js';
19
+ export interface UseLanonasisOptions extends LanonasisConfig {
20
+ }
21
+ export interface UseLanonasisReturn {
22
+ client: LanonasisAI | null;
23
+ isReady: boolean;
24
+ error: Error | null;
25
+ }
26
+ export declare function useLanonasis(options: UseLanonasisOptions): UseLanonasisReturn;
27
+ export interface UseChatOptions {
28
+ client: LanonasisAI | null;
29
+ conversationId?: string;
30
+ systemPrompt?: string;
31
+ onError?: (error: Error) => void;
32
+ }
33
+ export interface UseChatReturn {
34
+ messages: Message[];
35
+ isLoading: boolean;
36
+ error: Error | null;
37
+ send: (content: string) => Promise<void>;
38
+ sendWithStream: (content: string) => Promise<void>;
39
+ clear: () => void;
40
+ conversationId: string | undefined;
41
+ }
42
+ export declare function useChat(options: UseChatOptions): UseChatReturn;
43
+ export interface UseMemoryOptions {
44
+ client: LanonasisAI | null;
45
+ }
46
+ export interface UseMemoryReturn {
47
+ search: (query: string, limit?: number) => Promise<unknown[]>;
48
+ save: (title: string, content: string, tags?: string[]) => Promise<void>;
49
+ buildContext: (query: string) => Promise<string | null>;
50
+ isLoading: boolean;
51
+ error: Error | null;
52
+ }
53
+ export declare function useMemory(options: UseMemoryOptions): UseMemoryReturn;
54
+ export interface UseOrchestrateOptions {
55
+ client: LanonasisAI | null;
56
+ }
57
+ export interface UseOrchestrateReturn {
58
+ orchestrate: (query: string) => Promise<unknown>;
59
+ result: unknown;
60
+ isLoading: boolean;
61
+ error: Error | null;
62
+ }
63
+ export declare function useOrchestrate(options: UseOrchestrateOptions): UseOrchestrateReturn;
64
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/react/hooks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAA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