@zdrops/ai-assistants-sdk 1.1.0 → 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.
- package/CHANGELOG.md +8 -0
- package/dist/index.cjs +16 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +17 -4
- package/dist/index.d.ts +17 -4
- package/dist/index.js +16 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.2.0](https://github.com/ZDrops/ai-assistants-sdk/compare/ai-assistants-sdk-v1.1.0...ai-assistants-sdk-v1.2.0) (2026-05-07)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **api:** add public endpoint for listing active plans and update plans resource method ([053da47](https://github.com/ZDrops/ai-assistants-sdk/commit/053da47f797439791f079c6c3f260b83946f7f91))
|
|
9
|
+
* **tenants:** add TenantPublicInfo endpoint and integrate TenantsResource into client ([31bc7e6](https://github.com/ZDrops/ai-assistants-sdk/commit/31bc7e6c3b4237f57af04a2efb19a5bee2cd6bd4))
|
|
10
|
+
|
|
3
11
|
## [1.1.0](https://github.com/ZDrops/ai-assistants-sdk/compare/ai-assistants-sdk-v1.0.0...ai-assistants-sdk-v1.1.0) (2026-05-01)
|
|
4
12
|
|
|
5
13
|
|
package/dist/index.cjs
CHANGED
|
@@ -200,8 +200,8 @@ var PlansResource = class {
|
|
|
200
200
|
constructor(http) {
|
|
201
201
|
this.http = http;
|
|
202
202
|
}
|
|
203
|
-
list(
|
|
204
|
-
return this.http.get("/api/v1/public/plans", {
|
|
203
|
+
list() {
|
|
204
|
+
return this.http.get("/api/v1/public/plans", { authenticated: false });
|
|
205
205
|
}
|
|
206
206
|
};
|
|
207
207
|
|
|
@@ -359,6 +359,19 @@ var PaymentsResource = class {
|
|
|
359
359
|
}
|
|
360
360
|
};
|
|
361
361
|
|
|
362
|
+
// src/resources/tenants.ts
|
|
363
|
+
var TenantsResource = class {
|
|
364
|
+
constructor(http) {
|
|
365
|
+
this.http = http;
|
|
366
|
+
}
|
|
367
|
+
getPublicInfo(tenantId) {
|
|
368
|
+
return this.http.get("/api/v1/tenants/public-info", {
|
|
369
|
+
authenticated: false,
|
|
370
|
+
query: { tenantId }
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
};
|
|
374
|
+
|
|
362
375
|
// src/client.ts
|
|
363
376
|
function createClient(options) {
|
|
364
377
|
let accessToken = options.accessToken ?? null;
|
|
@@ -385,6 +398,7 @@ function createClient(options) {
|
|
|
385
398
|
generation: new GenerationResource(http),
|
|
386
399
|
images: new ImagesResource(http),
|
|
387
400
|
payments: new PaymentsResource(http),
|
|
401
|
+
tenants: new TenantsResource(http),
|
|
388
402
|
setAccessToken(token) {
|
|
389
403
|
accessToken = token;
|
|
390
404
|
},
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/http.ts","../src/resources/auth.ts","../src/resources/plans.ts","../src/resources/credits.ts","../src/resources/billing.ts","../src/resources/preferences.ts","../src/resources/conversations.ts","../src/resources/generation.ts","../src/resources/images.ts","../src/resources/payments.ts","../src/client.ts"],"sourcesContent":["export { createClient } from \"./client\";\nexport type { ClientOptions, AiAssistantsClient } from \"./client\";\n\nexport type {\n RegisterDto,\n LoginDto,\n VerifyOtpDto,\n RefreshTokenDto,\n UpdateProfileDto,\n RequestEmailChangeDto,\n ConfirmEmailChangeDto,\n PurchaseCreditsDto,\n UpsertBillingDto,\n UpdatePreferencesDto,\n CreateConversationDto,\n AddMessageDto,\n GenerateDto,\n TriggerImageDto,\n CreateCheckoutDto,\n MessageResponseDto,\n AuthResponseDto,\n TokensResponseDto,\n UserResponseDto,\n PlanResponseDto,\n CreditBalanceResponseDto,\n CreditTransactionResponseDto,\n PurchaseCreditsResponseDto,\n CreditBalanceEntityResponseDto,\n BillingResponseDto,\n PreferenceResponseDto,\n ConversationResponseDto,\n ConversationMessageResponseDto,\n ImageStatusResponseDto,\n CheckoutResponseDto,\n StartAuthResponseDto,\n\n OtpType,\n UserRole,\n PlanType,\n CreditTransactionType,\n ConversationStatus,\n MessageRole,\n ImageGenerationStatus,\n} from \"./types\";\n\nexport type { SseStreamOptions, GenerationDoneData } from \"./resources/generation\";\n\nexport { ApiError } from \"./errors\";\n","export class ApiError extends Error {\n constructor(\n public readonly statusCode: number,\n public readonly code: string,\n message: string | string[],\n public readonly requestId?: string,\n ) {\n super(Array.isArray(message) ? message.join(\", \") : message);\n this.name = \"ApiError\";\n }\n}\n","import { ApiError } from \"./errors\";\nimport type { TokensResponseDto } from \"./types\";\n\nexport interface HttpClientConfig {\n baseUrl: string;\n tenantKey: string;\n getAccessToken: () => string | null;\n getRefreshToken: () => string | null;\n onTokenRefreshed: (tokens: TokensResponseDto) => void | Promise<void>;\n fetch?: typeof globalThis.fetch;\n}\n\ntype HttpMethod = \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\n\ninterface RequestOptions {\n body?: unknown;\n query?: Record<string, string | number | boolean | undefined | null>;\n authenticated?: boolean;\n}\n\ninterface InternalRequestOptions extends RequestOptions {\n isRetry?: boolean;\n}\n\nexport class HttpClient {\n private refreshPromise: Promise<boolean> | null = null;\n private readonly baseUrl: URL;\n private readonly fetchFn: typeof globalThis.fetch;\n\n constructor(private config: HttpClientConfig) {\n this.baseUrl = new URL(config.baseUrl);\n this.fetchFn = config.fetch ?? globalThis.fetch;\n }\n\n private buildAndFetch(\n method: HttpMethod,\n path: string,\n options: RequestOptions = {},\n ): Promise<Response> {\n const { body, query, authenticated = true } = options;\n\n const url = new URL(path, this.baseUrl);\n if (query) {\n for (const [key, value] of Object.entries(query)) {\n if (value !== undefined && value !== null) {\n url.searchParams.set(key, String(value));\n }\n }\n }\n\n const headers: Record<string, string> = {\n \"X-Tenant-Key\": this.config.tenantKey,\n };\n if (body !== undefined) {\n headers[\"Content-Type\"] = \"application/json\";\n }\n if (authenticated) {\n const token = this.config.getAccessToken();\n if (token) {\n headers[\"Authorization\"] = `Bearer ${token}`;\n }\n }\n\n return this.fetchFn(url.toString(), {\n method,\n headers,\n body: body !== undefined ? JSON.stringify(body) : undefined,\n });\n }\n\n private async throwIfError(response: Response): Promise<void> {\n if (!response.ok) {\n const errorBody = await response.json().catch(() => null);\n throw new ApiError(\n response.status,\n errorBody?.error?.code ?? \"UNKNOWN_ERROR\",\n errorBody?.error?.message ?? response.statusText,\n errorBody?.meta?.requestId,\n );\n }\n }\n\n private async request<T>(\n method: HttpMethod,\n path: string,\n options: InternalRequestOptions = {},\n ): Promise<T> {\n const { isRetry = false, authenticated = true } = options;\n\n const response = await this.buildAndFetch(method, path, options);\n\n if (response.status === 401 && !isRetry && authenticated) {\n const refreshed = await this.attemptTokenRefresh();\n if (refreshed) {\n return this.request<T>(method, path, { ...options, isRetry: true });\n }\n }\n\n await this.throwIfError(response);\n\n const contentType = response.headers.get(\"content-type\");\n if (!contentType?.includes(\"application/json\")) {\n return undefined as T;\n }\n\n const json = await response.json();\n return (json && \"data\" in json && \"meta\" in json ? json.data : json) as T;\n }\n\n private attemptTokenRefresh(): Promise<boolean> {\n if (this.refreshPromise) return this.refreshPromise;\n this.refreshPromise = this.doRefresh().finally(() => {\n this.refreshPromise = null;\n });\n return this.refreshPromise;\n }\n\n private async doRefresh(): Promise<boolean> {\n const refreshToken = this.config.getRefreshToken();\n if (!refreshToken) return false;\n\n try {\n const tokens = await this.request<TokensResponseDto>(\n \"POST\",\n \"/api/v1/auth/refresh\",\n {\n body: { refreshToken },\n authenticated: false,\n isRetry: true,\n },\n );\n await this.config.onTokenRefreshed(tokens);\n return true;\n } catch {\n return false;\n }\n }\n\n get<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>(\"GET\", path, options);\n }\n\n post<T>(path: string, body?: unknown, options?: Omit<RequestOptions, \"body\">): Promise<T> {\n return this.request<T>(\"POST\", path, { ...options, body });\n }\n\n patch<T>(path: string, body?: unknown, options?: Omit<RequestOptions, \"body\">): Promise<T> {\n return this.request<T>(\"PATCH\", path, { ...options, body });\n }\n\n put<T>(path: string, body?: unknown, options?: Omit<RequestOptions, \"body\">): Promise<T> {\n return this.request<T>(\"PUT\", path, { ...options, body });\n }\n\n delete<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>(\"DELETE\", path, options);\n }\n\n async rawRequest(method: HttpMethod, path: string, options: RequestOptions = {}): Promise<Response> {\n const { authenticated = true } = options;\n\n let response = await this.buildAndFetch(method, path, options);\n\n if (response.status === 401 && authenticated) {\n const refreshed = await this.attemptTokenRefresh();\n if (refreshed) {\n response = await this.buildAndFetch(method, path, options);\n }\n }\n\n await this.throwIfError(response);\n\n return response;\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type {\n RegisterDto,\n LoginDto,\n VerifyOtpDto,\n RefreshTokenDto,\n UpdateProfileDto,\n RequestEmailChangeDto,\n ConfirmEmailChangeDto,\n MessageResponseDto,\n AuthResponseDto,\n TokensResponseDto,\n UserResponseDto,\n StartAuthResponseDto,\n} from \"../types\";\n\nexport class AuthResource {\n constructor(private http: HttpClient) {}\n\n register(data: RegisterDto): Promise<MessageResponseDto> {\n return this.http.post(\"/api/v1/auth/register\", data, { authenticated: false });\n }\n\n login(data: LoginDto): Promise<MessageResponseDto> {\n return this.http.post(\"/api/v1/auth/login\", data, { authenticated: false });\n }\n\n startAuth(data: LoginDto): Promise<StartAuthResponseDto> {\n return this.http.post(\"/api/v1/auth/start\", data, { authenticated: false });\n }\n\n verifyOtp(data: VerifyOtpDto): Promise<AuthResponseDto> {\n return this.http.post(\"/api/v1/auth/verify-otp\", data, { authenticated: false });\n }\n\n refresh(data: RefreshTokenDto): Promise<TokensResponseDto> {\n return this.http.post(\"/api/v1/auth/refresh\", data, { authenticated: false });\n }\n\n logout(): Promise<void> {\n return this.http.post(\"/api/v1/auth/logout\");\n }\n\n getProfile(): Promise<UserResponseDto> {\n return this.http.get(\"/api/v1/auth/me\");\n }\n\n updateProfile(data: UpdateProfileDto): Promise<UserResponseDto> {\n return this.http.patch(\"/api/v1/auth/me\", data);\n }\n\n deleteAccount(): Promise<void> {\n return this.http.delete(\"/api/v1/auth/me\");\n }\n\n requestEmailChange(data: RequestEmailChangeDto): Promise<MessageResponseDto> {\n return this.http.post(\"/api/v1/auth/request-email-change\", data);\n }\n\n confirmEmailChange(data: ConfirmEmailChangeDto): Promise<MessageResponseDto> {\n return this.http.post(\"/api/v1/auth/confirm-email-change\", data);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type { PlanResponseDto, PlanType } from \"../types\";\n\nexport class PlansResource {\n constructor(private http: HttpClient) {}\n\n list(query?: { type?: PlanType }): Promise<PlanResponseDto[]> {\n return this.http.get(\"/api/v1/public/plans\", { query, authenticated: false });\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type {\n CreditBalanceResponseDto,\n CreditTransactionResponseDto,\n CreditTransactionType,\n PurchaseCreditsDto,\n PurchaseCreditsResponseDto,\n} from \"../types\";\n\nexport class CreditsResource {\n constructor(private http: HttpClient) {}\n\n getBalance(): Promise<CreditBalanceResponseDto> {\n return this.http.get(\"/api/v1/credits/balance\");\n }\n\n getTransactions(query?: {\n cursor?: string;\n limit?: number;\n type?: CreditTransactionType;\n }): Promise<CreditTransactionResponseDto[]> {\n return this.http.get(\"/api/v1/credits/transactions\", { query });\n }\n\n purchase(data: PurchaseCreditsDto): Promise<PurchaseCreditsResponseDto> {\n return this.http.post(\"/api/v1/credits/purchase\", data);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type { BillingResponseDto, UpsertBillingDto } from \"../types\";\n\nexport class BillingResource {\n constructor(private http: HttpClient) {}\n\n get(): Promise<BillingResponseDto> {\n return this.http.get(\"/api/v1/billing\");\n }\n\n upsert(data: UpsertBillingDto): Promise<BillingResponseDto> {\n return this.http.put(\"/api/v1/billing\", data);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type {\n PreferenceResponseDto,\n UpdatePreferencesDto,\n} from \"../types\";\n\nexport class PreferencesResource {\n constructor(private http: HttpClient) {}\n\n getAll(): Promise<PreferenceResponseDto[]> {\n return this.http.get(\"/api/v1/preferences\");\n }\n\n getByAppKey(appKey: string): Promise<PreferenceResponseDto> {\n return this.http.get(`/api/v1/preferences/${appKey}`);\n }\n\n upsert(appKey: string, data: UpdatePreferencesDto): Promise<PreferenceResponseDto> {\n return this.http.put(`/api/v1/preferences/${appKey}`, data);\n }\n\n remove(appKey: string): Promise<void> {\n return this.http.delete(`/api/v1/preferences/${appKey}`);\n }\n\n merge(appKey: string, data: UpdatePreferencesDto): Promise<PreferenceResponseDto> {\n return this.http.patch(`/api/v1/preferences/${appKey}`, data);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type {\n CreateConversationDto,\n ConversationResponseDto,\n ConversationMessageResponseDto,\n AddMessageDto,\n ConversationStatus,\n} from \"../types\";\n\nexport class ConversationsResource {\n constructor(private http: HttpClient) {}\n\n create(data: CreateConversationDto): Promise<ConversationResponseDto> {\n return this.http.post(\"/api/v1/conversations\", data);\n }\n\n list(query?: {\n cursor?: string;\n limit?: number;\n status?: ConversationStatus;\n appKey?: string;\n }): Promise<ConversationResponseDto[]> {\n return this.http.get(\"/api/v1/conversations\", { query });\n }\n\n get(id: string): Promise<ConversationResponseDto> {\n return this.http.get(`/api/v1/conversations/${id}`);\n }\n\n archive(id: string): Promise<ConversationResponseDto> {\n return this.http.patch(`/api/v1/conversations/${id}/archive`);\n }\n\n listMessages(conversationId: string, query?: {\n cursor?: string;\n limit?: number;\n }): Promise<ConversationMessageResponseDto[]> {\n return this.http.get(`/api/v1/conversations/${conversationId}/messages`, { query });\n }\n\n addMessage(conversationId: string, data: AddMessageDto): Promise<ConversationMessageResponseDto> {\n return this.http.post(`/api/v1/conversations/${conversationId}/messages`, data);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type { GenerateDto } from \"../types\";\n\nexport interface GenerationDoneData {\n messageId: string;\n usage?: { inputTokens: number; outputTokens: number };\n structuredOutput?: Record<string, unknown>;\n}\n\nexport interface SseStreamOptions {\n onTextDelta?: (text: string) => void;\n onDone?: (data: GenerationDoneData) => void;\n onError?: (error: string) => void;\n signal?: AbortSignal;\n}\n\ntype SseEvent =\n | { type: \"text_delta\"; text: string }\n | { type: \"done\"; messageId: string; usage?: { inputTokens: number; outputTokens: number }; structuredOutput?: Record<string, unknown> }\n | { type: \"error\"; error: string };\n\nexport class GenerationResource {\n constructor(private http: HttpClient) {}\n\n async generate(conversationId: string, data: GenerateDto, options?: SseStreamOptions): Promise<string> {\n const response = await this.http.rawRequest(\"POST\", `/api/v1/conversations/${conversationId}/generate`, {\n body: data,\n });\n\n const reader = response.body?.getReader();\n if (!reader) throw new Error(\"No response body\");\n\n const decoder = new TextDecoder();\n const parts: string[] = [];\n let buffer = \"\";\n\n try {\n while (true) {\n if (options?.signal?.aborted) {\n reader.cancel();\n break;\n }\n\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (!line.startsWith(\"data: \")) continue;\n const jsonStr = line.slice(6).trim();\n if (!jsonStr) continue;\n\n let event: SseEvent;\n try {\n event = JSON.parse(jsonStr);\n } catch {\n continue;\n }\n\n if (event.type === \"text_delta\") {\n parts.push(event.text);\n options?.onTextDelta?.(event.text);\n } else if (event.type === \"done\") {\n options?.onDone?.(event);\n } else if (event.type === \"error\") {\n options?.onError?.(event.error);\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n\n return parts.join(\"\");\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type {\n TriggerImageDto,\n ImageStatusResponseDto,\n} from \"../types\";\n\nexport class ImagesResource {\n constructor(private http: HttpClient) {}\n\n trigger(messageId: string, data: TriggerImageDto): Promise<ImageStatusResponseDto> {\n return this.http.post(`/api/v1/messages/${messageId}/images`, data);\n }\n\n getAll(messageId: string): Promise<ImageStatusResponseDto[]> {\n return this.http.get(`/api/v1/messages/${messageId}/images`);\n }\n\n getBySlot(messageId: string, slot: string): Promise<ImageStatusResponseDto> {\n return this.http.get(`/api/v1/messages/${messageId}/images/${slot}`);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type { CreateCheckoutDto, CheckoutResponseDto } from \"../types\";\n\nexport class PaymentsResource {\n constructor(private http: HttpClient) {}\n\n checkout(data: CreateCheckoutDto): Promise<CheckoutResponseDto> {\n return this.http.post(\"/api/v1/payments/checkout\", data);\n }\n}\n","import { HttpClient } from \"./http\";\nimport type { TokensResponseDto } from \"./types\";\nimport { AuthResource } from \"./resources/auth\";\nimport { PlansResource } from \"./resources/plans\";\nimport { CreditsResource } from \"./resources/credits\";\nimport { BillingResource } from \"./resources/billing\";\nimport { PreferencesResource } from \"./resources/preferences\";\nimport { ConversationsResource } from \"./resources/conversations\";\nimport { GenerationResource } from \"./resources/generation\";\nimport { ImagesResource } from \"./resources/images\";\nimport { PaymentsResource } from \"./resources/payments\";\n\nexport interface ClientOptions {\n baseUrl: string;\n tenantKey: string;\n accessToken?: string;\n refreshToken?: string;\n onTokenRefreshed?: (tokens: TokensResponseDto) => void | Promise<void>;\n fetch?: typeof globalThis.fetch;\n}\n\nexport interface AiAssistantsClient {\n auth: AuthResource;\n plans: PlansResource;\n credits: CreditsResource;\n billing: BillingResource;\n preferences: PreferencesResource;\n conversations: ConversationsResource;\n generation: GenerationResource;\n images: ImagesResource;\n payments: PaymentsResource;\n setAccessToken(token: string): void;\n setRefreshToken(token: string): void;\n}\n\nexport function createClient(options: ClientOptions): AiAssistantsClient {\n let accessToken = options.accessToken ?? null;\n let refreshToken = options.refreshToken ?? null;\n\n const http = new HttpClient({\n baseUrl: options.baseUrl,\n tenantKey: options.tenantKey,\n fetch: options.fetch,\n getAccessToken: () => accessToken,\n getRefreshToken: () => refreshToken,\n onTokenRefreshed: async (tokens) => {\n accessToken = tokens.accessToken;\n refreshToken = tokens.refreshToken;\n await options.onTokenRefreshed?.(tokens);\n },\n });\n\n return {\n auth: new AuthResource(http),\n plans: new PlansResource(http),\n credits: new CreditsResource(http),\n billing: new BillingResource(http),\n preferences: new PreferencesResource(http),\n conversations: new ConversationsResource(http),\n generation: new GenerationResource(http),\n images: new ImagesResource(http),\n payments: new PaymentsResource(http),\n setAccessToken(token: string) {\n accessToken = token;\n },\n setRefreshToken(token: string) {\n refreshToken = token;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,WAAN,cAAuB,MAAM;AAAA,EAClC,YACkB,YACA,MAChB,SACgB,WAChB;AACA,UAAM,MAAM,QAAQ,OAAO,IAAI,QAAQ,KAAK,IAAI,IAAI,OAAO;AAL3C;AACA;AAEA;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;;;ACcO,IAAM,aAAN,MAAiB;AAAA,EAKtB,YAAoB,QAA0B;AAA1B;AAJpB,SAAQ,iBAA0C;AAKhD,SAAK,UAAU,IAAI,IAAI,OAAO,OAAO;AACrC,SAAK,UAAU,OAAO,SAAS,WAAW;AAAA,EAC5C;AAAA,EAEQ,cACN,QACA,MACA,UAA0B,CAAC,GACR;AACnB,UAAM,EAAE,MAAM,OAAO,gBAAgB,KAAK,IAAI;AAE9C,UAAM,MAAM,IAAI,IAAI,MAAM,KAAK,OAAO;AACtC,QAAI,OAAO;AACT,iBAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,KAAK,GAAG;AAChD,YAAI,UAAU,UAAa,UAAU,MAAM;AACzC,cAAI,aAAa,IAAI,KAAK,OAAO,KAAK,CAAC;AAAA,QACzC;AAAA,MACF;AAAA,IACF;AAEA,UAAM,UAAkC;AAAA,MACtC,gBAAgB,KAAK,OAAO;AAAA,IAC9B;AACA,QAAI,SAAS,QAAW;AACtB,cAAQ,cAAc,IAAI;AAAA,IAC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AmB;AAAA,EAEvC,SAAS,MAAuD;AAC9D,WAAO,KAAK,KAAK,KAAK,6BAA6B,IAAI;AAAA,EACzD;AACF;;;AC0BO,SAAS,aAAa,SAA4C;AACvE,MAAI,cAAc,QAAQ,eAAe;AACzC,MAAI,eAAe,QAAQ,gBAAgB;AAE3C,QAAM,OAAO,IAAI,WAAW;AAAA,IAC1B,SAAS,QAAQ;AAAA,IACjB,WAAW,QAAQ;AAAA,IACnB,OAAO,QAAQ;AAAA,IACf,gBAAgB,MAAM;AAAA,IACtB,iBAAiB,MAAM;AAAA,IACvB,kBAAkB,OAAO,WAAW;AAClC,oBAAc,OAAO;AACrB,qBAAe,OAAO;AACtB,YAAM,QAAQ,mBAAmB,MAAM;AAAA,IACzC;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL,MAAM,IAAI,aAAa,IAAI;AAAA,IAC3B,OAAO,IAAI,cAAc,IAAI;AAAA,IAC7B,SAAS,IAAI,gBAAgB,IAAI;AAAA,IACjC,SAAS,IAAI,gBAAgB,IAAI;AAAA,IACjC,aAAa,IAAI,oBAAoB,IAAI;AAAA,IACzC,eAAe,IAAI,sBAAsB,IAAI;AAAA,IAC7C,YAAY,IAAI,mBAAmB,IAAI;AAAA,IACvC,QAAQ,IAAI,eAAe,IAAI;AAAA,IAC/B,UAAU,IAAI,iBAAiB,IAAI;AAAA,IACnC,eAAe,OAAe;AAC5B,oBAAc;AAAA,IAChB;AAAA,IACA,gBAAgB,OAAe;AAC7B,qBAAe;AAAA,IACjB;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/errors.ts","../src/http.ts","../src/resources/auth.ts","../src/resources/plans.ts","../src/resources/credits.ts","../src/resources/billing.ts","../src/resources/preferences.ts","../src/resources/conversations.ts","../src/resources/generation.ts","../src/resources/images.ts","../src/resources/payments.ts","../src/resources/tenants.ts","../src/client.ts"],"sourcesContent":["export { createClient } from \"./client\";\nexport type { ClientOptions, AiAssistantsClient } from \"./client\";\n\nexport type {\n RegisterDto,\n LoginDto,\n VerifyOtpDto,\n RefreshTokenDto,\n UpdateProfileDto,\n RequestEmailChangeDto,\n ConfirmEmailChangeDto,\n PurchaseCreditsDto,\n UpsertBillingDto,\n UpdatePreferencesDto,\n CreateConversationDto,\n AddMessageDto,\n GenerateDto,\n TriggerImageDto,\n CreateCheckoutDto,\n MessageResponseDto,\n AuthResponseDto,\n TokensResponseDto,\n UserResponseDto,\n PlanResponseDto,\n CreditBalanceResponseDto,\n CreditTransactionResponseDto,\n PurchaseCreditsResponseDto,\n CreditBalanceEntityResponseDto,\n BillingResponseDto,\n PreferenceResponseDto,\n ConversationResponseDto,\n ConversationMessageResponseDto,\n ImageStatusResponseDto,\n CheckoutResponseDto,\n TenantPublicInfoDto,\n StartAuthResponseDto,\n\n OtpType,\n UserRole,\n PlanType,\n CreditTransactionType,\n ConversationStatus,\n MessageRole,\n ImageGenerationStatus,\n} from \"./types\";\n\nexport type { SseStreamOptions, GenerationDoneData } from \"./resources/generation\";\n\nexport { ApiError } from \"./errors\";\n","export class ApiError extends Error {\n constructor(\n public readonly statusCode: number,\n public readonly code: string,\n message: string | string[],\n public readonly requestId?: string,\n ) {\n super(Array.isArray(message) ? message.join(\", \") : message);\n this.name = \"ApiError\";\n }\n}\n","import { ApiError } from \"./errors\";\nimport type { TokensResponseDto } from \"./types\";\n\nexport interface HttpClientConfig {\n baseUrl: string;\n tenantKey: string;\n getAccessToken: () => string | null;\n getRefreshToken: () => string | null;\n onTokenRefreshed: (tokens: TokensResponseDto) => void | Promise<void>;\n fetch?: typeof globalThis.fetch;\n}\n\ntype HttpMethod = \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\n\ninterface RequestOptions {\n body?: unknown;\n query?: Record<string, string | number | boolean | undefined | null>;\n authenticated?: boolean;\n}\n\ninterface InternalRequestOptions extends RequestOptions {\n isRetry?: boolean;\n}\n\nexport class HttpClient {\n private refreshPromise: Promise<boolean> | null = null;\n private readonly baseUrl: URL;\n private readonly fetchFn: typeof globalThis.fetch;\n\n constructor(private config: HttpClientConfig) {\n this.baseUrl = new URL(config.baseUrl);\n this.fetchFn = config.fetch ?? globalThis.fetch;\n }\n\n private buildAndFetch(\n method: HttpMethod,\n path: string,\n options: RequestOptions = {},\n ): Promise<Response> {\n const { body, query, authenticated = true } = options;\n\n const url = new URL(path, this.baseUrl);\n if (query) {\n for (const [key, value] of Object.entries(query)) {\n if (value !== undefined && value !== null) {\n url.searchParams.set(key, String(value));\n }\n }\n }\n\n const headers: Record<string, string> = {\n \"X-Tenant-Key\": this.config.tenantKey,\n };\n if (body !== undefined) {\n headers[\"Content-Type\"] = \"application/json\";\n }\n if (authenticated) {\n const token = this.config.getAccessToken();\n if (token) {\n headers[\"Authorization\"] = `Bearer ${token}`;\n }\n }\n\n return this.fetchFn(url.toString(), {\n method,\n headers,\n body: body !== undefined ? JSON.stringify(body) : undefined,\n });\n }\n\n private async throwIfError(response: Response): Promise<void> {\n if (!response.ok) {\n const errorBody = await response.json().catch(() => null);\n throw new ApiError(\n response.status,\n errorBody?.error?.code ?? \"UNKNOWN_ERROR\",\n errorBody?.error?.message ?? response.statusText,\n errorBody?.meta?.requestId,\n );\n }\n }\n\n private async request<T>(\n method: HttpMethod,\n path: string,\n options: InternalRequestOptions = {},\n ): Promise<T> {\n const { isRetry = false, authenticated = true } = options;\n\n const response = await this.buildAndFetch(method, path, options);\n\n if (response.status === 401 && !isRetry && authenticated) {\n const refreshed = await this.attemptTokenRefresh();\n if (refreshed) {\n return this.request<T>(method, path, { ...options, isRetry: true });\n }\n }\n\n await this.throwIfError(response);\n\n const contentType = response.headers.get(\"content-type\");\n if (!contentType?.includes(\"application/json\")) {\n return undefined as T;\n }\n\n const json = await response.json();\n return (json && \"data\" in json && \"meta\" in json ? json.data : json) as T;\n }\n\n private attemptTokenRefresh(): Promise<boolean> {\n if (this.refreshPromise) return this.refreshPromise;\n this.refreshPromise = this.doRefresh().finally(() => {\n this.refreshPromise = null;\n });\n return this.refreshPromise;\n }\n\n private async doRefresh(): Promise<boolean> {\n const refreshToken = this.config.getRefreshToken();\n if (!refreshToken) return false;\n\n try {\n const tokens = await this.request<TokensResponseDto>(\n \"POST\",\n \"/api/v1/auth/refresh\",\n {\n body: { refreshToken },\n authenticated: false,\n isRetry: true,\n },\n );\n await this.config.onTokenRefreshed(tokens);\n return true;\n } catch {\n return false;\n }\n }\n\n get<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>(\"GET\", path, options);\n }\n\n post<T>(path: string, body?: unknown, options?: Omit<RequestOptions, \"body\">): Promise<T> {\n return this.request<T>(\"POST\", path, { ...options, body });\n }\n\n patch<T>(path: string, body?: unknown, options?: Omit<RequestOptions, \"body\">): Promise<T> {\n return this.request<T>(\"PATCH\", path, { ...options, body });\n }\n\n put<T>(path: string, body?: unknown, options?: Omit<RequestOptions, \"body\">): Promise<T> {\n return this.request<T>(\"PUT\", path, { ...options, body });\n }\n\n delete<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>(\"DELETE\", path, options);\n }\n\n async rawRequest(method: HttpMethod, path: string, options: RequestOptions = {}): Promise<Response> {\n const { authenticated = true } = options;\n\n let response = await this.buildAndFetch(method, path, options);\n\n if (response.status === 401 && authenticated) {\n const refreshed = await this.attemptTokenRefresh();\n if (refreshed) {\n response = await this.buildAndFetch(method, path, options);\n }\n }\n\n await this.throwIfError(response);\n\n return response;\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type {\n RegisterDto,\n LoginDto,\n VerifyOtpDto,\n RefreshTokenDto,\n UpdateProfileDto,\n RequestEmailChangeDto,\n ConfirmEmailChangeDto,\n MessageResponseDto,\n AuthResponseDto,\n TokensResponseDto,\n UserResponseDto,\n StartAuthResponseDto,\n} from \"../types\";\n\nexport class AuthResource {\n constructor(private http: HttpClient) {}\n\n register(data: RegisterDto): Promise<MessageResponseDto> {\n return this.http.post(\"/api/v1/auth/register\", data, { authenticated: false });\n }\n\n login(data: LoginDto): Promise<MessageResponseDto> {\n return this.http.post(\"/api/v1/auth/login\", data, { authenticated: false });\n }\n\n startAuth(data: LoginDto): Promise<StartAuthResponseDto> {\n return this.http.post(\"/api/v1/auth/start\", data, { authenticated: false });\n }\n\n verifyOtp(data: VerifyOtpDto): Promise<AuthResponseDto> {\n return this.http.post(\"/api/v1/auth/verify-otp\", data, { authenticated: false });\n }\n\n refresh(data: RefreshTokenDto): Promise<TokensResponseDto> {\n return this.http.post(\"/api/v1/auth/refresh\", data, { authenticated: false });\n }\n\n logout(): Promise<void> {\n return this.http.post(\"/api/v1/auth/logout\");\n }\n\n getProfile(): Promise<UserResponseDto> {\n return this.http.get(\"/api/v1/auth/me\");\n }\n\n updateProfile(data: UpdateProfileDto): Promise<UserResponseDto> {\n return this.http.patch(\"/api/v1/auth/me\", data);\n }\n\n deleteAccount(): Promise<void> {\n return this.http.delete(\"/api/v1/auth/me\");\n }\n\n requestEmailChange(data: RequestEmailChangeDto): Promise<MessageResponseDto> {\n return this.http.post(\"/api/v1/auth/request-email-change\", data);\n }\n\n confirmEmailChange(data: ConfirmEmailChangeDto): Promise<MessageResponseDto> {\n return this.http.post(\"/api/v1/auth/confirm-email-change\", data);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type { PlanResponseDto } from \"../types\";\n\nexport class PlansResource {\n constructor(private http: HttpClient) {}\n\n list(): Promise<PlanResponseDto[]> {\n return this.http.get(\"/api/v1/public/plans\", { authenticated: false });\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type {\n CreditBalanceResponseDto,\n CreditTransactionResponseDto,\n CreditTransactionType,\n PurchaseCreditsDto,\n PurchaseCreditsResponseDto,\n} from \"../types\";\n\nexport class CreditsResource {\n constructor(private http: HttpClient) {}\n\n getBalance(): Promise<CreditBalanceResponseDto> {\n return this.http.get(\"/api/v1/credits/balance\");\n }\n\n getTransactions(query?: {\n cursor?: string;\n limit?: number;\n type?: CreditTransactionType;\n }): Promise<CreditTransactionResponseDto[]> {\n return this.http.get(\"/api/v1/credits/transactions\", { query });\n }\n\n purchase(data: PurchaseCreditsDto): Promise<PurchaseCreditsResponseDto> {\n return this.http.post(\"/api/v1/credits/purchase\", data);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type { BillingResponseDto, UpsertBillingDto } from \"../types\";\n\nexport class BillingResource {\n constructor(private http: HttpClient) {}\n\n get(): Promise<BillingResponseDto> {\n return this.http.get(\"/api/v1/billing\");\n }\n\n upsert(data: UpsertBillingDto): Promise<BillingResponseDto> {\n return this.http.put(\"/api/v1/billing\", data);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type {\n PreferenceResponseDto,\n UpdatePreferencesDto,\n} from \"../types\";\n\nexport class PreferencesResource {\n constructor(private http: HttpClient) {}\n\n getAll(): Promise<PreferenceResponseDto[]> {\n return this.http.get(\"/api/v1/preferences\");\n }\n\n getByAppKey(appKey: string): Promise<PreferenceResponseDto> {\n return this.http.get(`/api/v1/preferences/${appKey}`);\n }\n\n upsert(appKey: string, data: UpdatePreferencesDto): Promise<PreferenceResponseDto> {\n return this.http.put(`/api/v1/preferences/${appKey}`, data);\n }\n\n remove(appKey: string): Promise<void> {\n return this.http.delete(`/api/v1/preferences/${appKey}`);\n }\n\n merge(appKey: string, data: UpdatePreferencesDto): Promise<PreferenceResponseDto> {\n return this.http.patch(`/api/v1/preferences/${appKey}`, data);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type {\n CreateConversationDto,\n ConversationResponseDto,\n ConversationMessageResponseDto,\n AddMessageDto,\n ConversationStatus,\n} from \"../types\";\n\nexport class ConversationsResource {\n constructor(private http: HttpClient) {}\n\n create(data: CreateConversationDto): Promise<ConversationResponseDto> {\n return this.http.post(\"/api/v1/conversations\", data);\n }\n\n list(query?: {\n cursor?: string;\n limit?: number;\n status?: ConversationStatus;\n appKey?: string;\n }): Promise<ConversationResponseDto[]> {\n return this.http.get(\"/api/v1/conversations\", { query });\n }\n\n get(id: string): Promise<ConversationResponseDto> {\n return this.http.get(`/api/v1/conversations/${id}`);\n }\n\n archive(id: string): Promise<ConversationResponseDto> {\n return this.http.patch(`/api/v1/conversations/${id}/archive`);\n }\n\n listMessages(conversationId: string, query?: {\n cursor?: string;\n limit?: number;\n }): Promise<ConversationMessageResponseDto[]> {\n return this.http.get(`/api/v1/conversations/${conversationId}/messages`, { query });\n }\n\n addMessage(conversationId: string, data: AddMessageDto): Promise<ConversationMessageResponseDto> {\n return this.http.post(`/api/v1/conversations/${conversationId}/messages`, data);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type { GenerateDto } from \"../types\";\n\nexport interface GenerationDoneData {\n messageId: string;\n usage?: { inputTokens: number; outputTokens: number };\n structuredOutput?: Record<string, unknown>;\n}\n\nexport interface SseStreamOptions {\n onTextDelta?: (text: string) => void;\n onDone?: (data: GenerationDoneData) => void;\n onError?: (error: string) => void;\n signal?: AbortSignal;\n}\n\ntype SseEvent =\n | { type: \"text_delta\"; text: string }\n | { type: \"done\"; messageId: string; usage?: { inputTokens: number; outputTokens: number }; structuredOutput?: Record<string, unknown> }\n | { type: \"error\"; error: string };\n\nexport class GenerationResource {\n constructor(private http: HttpClient) {}\n\n async generate(conversationId: string, data: GenerateDto, options?: SseStreamOptions): Promise<string> {\n const response = await this.http.rawRequest(\"POST\", `/api/v1/conversations/${conversationId}/generate`, {\n body: data,\n });\n\n const reader = response.body?.getReader();\n if (!reader) throw new Error(\"No response body\");\n\n const decoder = new TextDecoder();\n const parts: string[] = [];\n let buffer = \"\";\n\n try {\n while (true) {\n if (options?.signal?.aborted) {\n reader.cancel();\n break;\n }\n\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (!line.startsWith(\"data: \")) continue;\n const jsonStr = line.slice(6).trim();\n if (!jsonStr) continue;\n\n let event: SseEvent;\n try {\n event = JSON.parse(jsonStr);\n } catch {\n continue;\n }\n\n if (event.type === \"text_delta\") {\n parts.push(event.text);\n options?.onTextDelta?.(event.text);\n } else if (event.type === \"done\") {\n options?.onDone?.(event);\n } else if (event.type === \"error\") {\n options?.onError?.(event.error);\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n\n return parts.join(\"\");\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type {\n TriggerImageDto,\n ImageStatusResponseDto,\n} from \"../types\";\n\nexport class ImagesResource {\n constructor(private http: HttpClient) {}\n\n trigger(messageId: string, data: TriggerImageDto): Promise<ImageStatusResponseDto> {\n return this.http.post(`/api/v1/messages/${messageId}/images`, data);\n }\n\n getAll(messageId: string): Promise<ImageStatusResponseDto[]> {\n return this.http.get(`/api/v1/messages/${messageId}/images`);\n }\n\n getBySlot(messageId: string, slot: string): Promise<ImageStatusResponseDto> {\n return this.http.get(`/api/v1/messages/${messageId}/images/${slot}`);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type { CreateCheckoutDto, CheckoutResponseDto } from \"../types\";\n\nexport class PaymentsResource {\n constructor(private http: HttpClient) {}\n\n checkout(data: CreateCheckoutDto): Promise<CheckoutResponseDto> {\n return this.http.post(\"/api/v1/payments/checkout\", data);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type { TenantPublicInfoDto } from \"../types\";\n\nexport class TenantsResource {\n constructor(private http: HttpClient) {}\n\n getPublicInfo(tenantId: string): Promise<TenantPublicInfoDto> {\n return this.http.get(\"/api/v1/tenants/public-info\", {\n authenticated: false,\n query: { tenantId },\n });\n }\n}\n","import { HttpClient } from \"./http\";\nimport type { TokensResponseDto } from \"./types\";\nimport { AuthResource } from \"./resources/auth\";\nimport { PlansResource } from \"./resources/plans\";\nimport { CreditsResource } from \"./resources/credits\";\nimport { BillingResource } from \"./resources/billing\";\nimport { PreferencesResource } from \"./resources/preferences\";\nimport { ConversationsResource } from \"./resources/conversations\";\nimport { GenerationResource } from \"./resources/generation\";\nimport { ImagesResource } from \"./resources/images\";\nimport { PaymentsResource } from \"./resources/payments\";\nimport { TenantsResource } from \"./resources/tenants\";\n\nexport interface ClientOptions {\n baseUrl: string;\n tenantKey: string;\n accessToken?: string;\n refreshToken?: string;\n onTokenRefreshed?: (tokens: TokensResponseDto) => void | Promise<void>;\n fetch?: typeof globalThis.fetch;\n}\n\nexport interface AiAssistantsClient {\n auth: AuthResource;\n plans: PlansResource;\n credits: CreditsResource;\n billing: BillingResource;\n preferences: PreferencesResource;\n conversations: ConversationsResource;\n generation: GenerationResource;\n images: ImagesResource;\n payments: PaymentsResource;\n tenants: TenantsResource;\n setAccessToken(token: string): void;\n setRefreshToken(token: string): void;\n}\n\nexport function createClient(options: ClientOptions): AiAssistantsClient {\n let accessToken = options.accessToken ?? null;\n let refreshToken = options.refreshToken ?? null;\n\n const http = new HttpClient({\n baseUrl: options.baseUrl,\n tenantKey: options.tenantKey,\n fetch: options.fetch,\n getAccessToken: () => accessToken,\n getRefreshToken: () => refreshToken,\n onTokenRefreshed: async (tokens) => {\n accessToken = tokens.accessToken;\n refreshToken = tokens.refreshToken;\n await options.onTokenRefreshed?.(tokens);\n },\n });\n\n return {\n auth: new AuthResource(http),\n plans: new PlansResource(http),\n credits: new CreditsResource(http),\n billing: new BillingResource(http),\n preferences: new PreferencesResource(http),\n conversations: new ConversationsResource(http),\n generation: new GenerationResource(http),\n images: new ImagesResource(http),\n payments: new PaymentsResource(http),\n tenants: new TenantsResource(http),\n setAccessToken(token: string) {\n accessToken = token;\n },\n setRefreshToken(token: string) {\n refreshToken = token;\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,WAAN,cAAuB,MAAM;AAAA,EAClC,YACkB,YACA,MAChB,SACgB,WAChB;AACA,UAAM,MAAM,QAAQ,OAAO,IAAI,QAAQ,KAAK,IAAI,IAAI,OAAO;AAL3C;AACA;AAEA;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;;;ACcO,IAAM,aAAN,MAAiB;AAAA,EAKtB,YAAoB,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AM,QAAQ,mBAAmB,MAAM;AAAA,IACzC;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL,MAAM,IAAI,aAAa,IAAI;AAAA,IAC3B,OAAO,IAAI,cAAc,IAAI;AAAA,IAC7B,SAAS,IAAI,gBAAgB,IAAI;AAAA,IACjC,SAAS,IAAI,gBAAgB,IAAI;AAAA,IACjC,aAAa,IAAI,oBAAoB,IAAI;AAAA,IACzC,eAAe,IAAI,sBAAsB,IAAI;AAAA,IAC7C,YAAY,IAAI,mBAAmB,IAAI;AAAA,IACvC,QAAQ,IAAI,eAAe,IAAI;AAAA,IAC/B,UAAU,IAAI,iBAAiB,IAAI;AAAA,IACnC,SAAS,IAAI,gBAAgB,IAAI;AAAA,IACjC,eAAe,OAAe;AAC5B,oBAAc;AAAA,IAChB;AAAA,IACA,gBAAgB,OAAe;AAC7B,qBAAe;AAAA,IACjB;AAAA,EACF;AACF;","names":[]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
interface components {
|
|
2
2
|
schemas: {
|
|
3
|
+
TenantPublicInfoDto: {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
slug: string;
|
|
7
|
+
publicApiKey: string;
|
|
8
|
+
frontendUrl: string;
|
|
9
|
+
};
|
|
3
10
|
RegisterDto: {
|
|
4
11
|
/** @example user@example.com */
|
|
5
12
|
email: string;
|
|
@@ -371,6 +378,7 @@ type ConversationResponseDto = components["schemas"]["ConversationResponseDto"]
|
|
|
371
378
|
type ConversationMessageResponseDto = components["schemas"]["ConversationMessageResponseDto"];
|
|
372
379
|
type ImageStatusResponseDto = components["schemas"]["ImageStatusResponseDto"];
|
|
373
380
|
type CheckoutResponseDto = components["schemas"]["CheckoutResponseDto"];
|
|
381
|
+
type TenantPublicInfoDto = components["schemas"]["TenantPublicInfoDto"];
|
|
374
382
|
type OtpType = components["schemas"]["OtpType"];
|
|
375
383
|
type UserRole = components["schemas"]["UserRole"];
|
|
376
384
|
type PlanType = components["schemas"]["PlanType"];
|
|
@@ -431,9 +439,7 @@ declare class AuthResource {
|
|
|
431
439
|
declare class PlansResource {
|
|
432
440
|
private http;
|
|
433
441
|
constructor(http: HttpClient);
|
|
434
|
-
list(
|
|
435
|
-
type?: PlanType;
|
|
436
|
-
}): Promise<PlanResponseDto[]>;
|
|
442
|
+
list(): Promise<PlanResponseDto[]>;
|
|
437
443
|
}
|
|
438
444
|
|
|
439
445
|
declare class CreditsResource {
|
|
@@ -518,6 +524,12 @@ declare class PaymentsResource {
|
|
|
518
524
|
checkout(data: CreateCheckoutDto): Promise<CheckoutResponseDto>;
|
|
519
525
|
}
|
|
520
526
|
|
|
527
|
+
declare class TenantsResource {
|
|
528
|
+
private http;
|
|
529
|
+
constructor(http: HttpClient);
|
|
530
|
+
getPublicInfo(tenantId: string): Promise<TenantPublicInfoDto>;
|
|
531
|
+
}
|
|
532
|
+
|
|
521
533
|
interface ClientOptions {
|
|
522
534
|
baseUrl: string;
|
|
523
535
|
tenantKey: string;
|
|
@@ -536,6 +548,7 @@ interface AiAssistantsClient {
|
|
|
536
548
|
generation: GenerationResource;
|
|
537
549
|
images: ImagesResource;
|
|
538
550
|
payments: PaymentsResource;
|
|
551
|
+
tenants: TenantsResource;
|
|
539
552
|
setAccessToken(token: string): void;
|
|
540
553
|
setRefreshToken(token: string): void;
|
|
541
554
|
}
|
|
@@ -548,4 +561,4 @@ declare class ApiError extends Error {
|
|
|
548
561
|
constructor(statusCode: number, code: string, message: string | string[], requestId?: string | undefined);
|
|
549
562
|
}
|
|
550
563
|
|
|
551
|
-
export { type AddMessageDto, type AiAssistantsClient, ApiError, type AuthResponseDto, type BillingResponseDto, type CheckoutResponseDto, type ClientOptions, type ConfirmEmailChangeDto, type ConversationMessageResponseDto, type ConversationResponseDto, type ConversationStatus, type CreateCheckoutDto, type CreateConversationDto, type CreditBalanceEntityResponseDto, type CreditBalanceResponseDto, type CreditTransactionResponseDto, type CreditTransactionType, type GenerateDto, type GenerationDoneData, type ImageGenerationStatus, type ImageStatusResponseDto, type LoginDto, type MessageResponseDto, type MessageRole, type OtpType, type PlanResponseDto, type PlanType, type PreferenceResponseDto, type PurchaseCreditsDto, type PurchaseCreditsResponseDto, type RefreshTokenDto, type RegisterDto, type RequestEmailChangeDto, type SseStreamOptions, type StartAuthResponseDto, type TokensResponseDto, type TriggerImageDto, type UpdatePreferencesDto, type UpdateProfileDto, type UpsertBillingDto, type UserResponseDto, type UserRole, type VerifyOtpDto, createClient };
|
|
564
|
+
export { type AddMessageDto, type AiAssistantsClient, ApiError, type AuthResponseDto, type BillingResponseDto, type CheckoutResponseDto, type ClientOptions, type ConfirmEmailChangeDto, type ConversationMessageResponseDto, type ConversationResponseDto, type ConversationStatus, type CreateCheckoutDto, type CreateConversationDto, type CreditBalanceEntityResponseDto, type CreditBalanceResponseDto, type CreditTransactionResponseDto, type CreditTransactionType, type GenerateDto, type GenerationDoneData, type ImageGenerationStatus, type ImageStatusResponseDto, type LoginDto, type MessageResponseDto, type MessageRole, type OtpType, type PlanResponseDto, type PlanType, type PreferenceResponseDto, type PurchaseCreditsDto, type PurchaseCreditsResponseDto, type RefreshTokenDto, type RegisterDto, type RequestEmailChangeDto, type SseStreamOptions, type StartAuthResponseDto, type TenantPublicInfoDto, type TokensResponseDto, type TriggerImageDto, type UpdatePreferencesDto, type UpdateProfileDto, type UpsertBillingDto, type UserResponseDto, type UserRole, type VerifyOtpDto, createClient };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
interface components {
|
|
2
2
|
schemas: {
|
|
3
|
+
TenantPublicInfoDto: {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
slug: string;
|
|
7
|
+
publicApiKey: string;
|
|
8
|
+
frontendUrl: string;
|
|
9
|
+
};
|
|
3
10
|
RegisterDto: {
|
|
4
11
|
/** @example user@example.com */
|
|
5
12
|
email: string;
|
|
@@ -371,6 +378,7 @@ type ConversationResponseDto = components["schemas"]["ConversationResponseDto"]
|
|
|
371
378
|
type ConversationMessageResponseDto = components["schemas"]["ConversationMessageResponseDto"];
|
|
372
379
|
type ImageStatusResponseDto = components["schemas"]["ImageStatusResponseDto"];
|
|
373
380
|
type CheckoutResponseDto = components["schemas"]["CheckoutResponseDto"];
|
|
381
|
+
type TenantPublicInfoDto = components["schemas"]["TenantPublicInfoDto"];
|
|
374
382
|
type OtpType = components["schemas"]["OtpType"];
|
|
375
383
|
type UserRole = components["schemas"]["UserRole"];
|
|
376
384
|
type PlanType = components["schemas"]["PlanType"];
|
|
@@ -431,9 +439,7 @@ declare class AuthResource {
|
|
|
431
439
|
declare class PlansResource {
|
|
432
440
|
private http;
|
|
433
441
|
constructor(http: HttpClient);
|
|
434
|
-
list(
|
|
435
|
-
type?: PlanType;
|
|
436
|
-
}): Promise<PlanResponseDto[]>;
|
|
442
|
+
list(): Promise<PlanResponseDto[]>;
|
|
437
443
|
}
|
|
438
444
|
|
|
439
445
|
declare class CreditsResource {
|
|
@@ -518,6 +524,12 @@ declare class PaymentsResource {
|
|
|
518
524
|
checkout(data: CreateCheckoutDto): Promise<CheckoutResponseDto>;
|
|
519
525
|
}
|
|
520
526
|
|
|
527
|
+
declare class TenantsResource {
|
|
528
|
+
private http;
|
|
529
|
+
constructor(http: HttpClient);
|
|
530
|
+
getPublicInfo(tenantId: string): Promise<TenantPublicInfoDto>;
|
|
531
|
+
}
|
|
532
|
+
|
|
521
533
|
interface ClientOptions {
|
|
522
534
|
baseUrl: string;
|
|
523
535
|
tenantKey: string;
|
|
@@ -536,6 +548,7 @@ interface AiAssistantsClient {
|
|
|
536
548
|
generation: GenerationResource;
|
|
537
549
|
images: ImagesResource;
|
|
538
550
|
payments: PaymentsResource;
|
|
551
|
+
tenants: TenantsResource;
|
|
539
552
|
setAccessToken(token: string): void;
|
|
540
553
|
setRefreshToken(token: string): void;
|
|
541
554
|
}
|
|
@@ -548,4 +561,4 @@ declare class ApiError extends Error {
|
|
|
548
561
|
constructor(statusCode: number, code: string, message: string | string[], requestId?: string | undefined);
|
|
549
562
|
}
|
|
550
563
|
|
|
551
|
-
export { type AddMessageDto, type AiAssistantsClient, ApiError, type AuthResponseDto, type BillingResponseDto, type CheckoutResponseDto, type ClientOptions, type ConfirmEmailChangeDto, type ConversationMessageResponseDto, type ConversationResponseDto, type ConversationStatus, type CreateCheckoutDto, type CreateConversationDto, type CreditBalanceEntityResponseDto, type CreditBalanceResponseDto, type CreditTransactionResponseDto, type CreditTransactionType, type GenerateDto, type GenerationDoneData, type ImageGenerationStatus, type ImageStatusResponseDto, type LoginDto, type MessageResponseDto, type MessageRole, type OtpType, type PlanResponseDto, type PlanType, type PreferenceResponseDto, type PurchaseCreditsDto, type PurchaseCreditsResponseDto, type RefreshTokenDto, type RegisterDto, type RequestEmailChangeDto, type SseStreamOptions, type StartAuthResponseDto, type TokensResponseDto, type TriggerImageDto, type UpdatePreferencesDto, type UpdateProfileDto, type UpsertBillingDto, type UserResponseDto, type UserRole, type VerifyOtpDto, createClient };
|
|
564
|
+
export { type AddMessageDto, type AiAssistantsClient, ApiError, type AuthResponseDto, type BillingResponseDto, type CheckoutResponseDto, type ClientOptions, type ConfirmEmailChangeDto, type ConversationMessageResponseDto, type ConversationResponseDto, type ConversationStatus, type CreateCheckoutDto, type CreateConversationDto, type CreditBalanceEntityResponseDto, type CreditBalanceResponseDto, type CreditTransactionResponseDto, type CreditTransactionType, type GenerateDto, type GenerationDoneData, type ImageGenerationStatus, type ImageStatusResponseDto, type LoginDto, type MessageResponseDto, type MessageRole, type OtpType, type PlanResponseDto, type PlanType, type PreferenceResponseDto, type PurchaseCreditsDto, type PurchaseCreditsResponseDto, type RefreshTokenDto, type RegisterDto, type RequestEmailChangeDto, type SseStreamOptions, type StartAuthResponseDto, type TenantPublicInfoDto, type TokensResponseDto, type TriggerImageDto, type UpdatePreferencesDto, type UpdateProfileDto, type UpsertBillingDto, type UserResponseDto, type UserRole, type VerifyOtpDto, createClient };
|
package/dist/index.js
CHANGED
|
@@ -173,8 +173,8 @@ var PlansResource = class {
|
|
|
173
173
|
constructor(http) {
|
|
174
174
|
this.http = http;
|
|
175
175
|
}
|
|
176
|
-
list(
|
|
177
|
-
return this.http.get("/api/v1/public/plans", {
|
|
176
|
+
list() {
|
|
177
|
+
return this.http.get("/api/v1/public/plans", { authenticated: false });
|
|
178
178
|
}
|
|
179
179
|
};
|
|
180
180
|
|
|
@@ -332,6 +332,19 @@ var PaymentsResource = class {
|
|
|
332
332
|
}
|
|
333
333
|
};
|
|
334
334
|
|
|
335
|
+
// src/resources/tenants.ts
|
|
336
|
+
var TenantsResource = class {
|
|
337
|
+
constructor(http) {
|
|
338
|
+
this.http = http;
|
|
339
|
+
}
|
|
340
|
+
getPublicInfo(tenantId) {
|
|
341
|
+
return this.http.get("/api/v1/tenants/public-info", {
|
|
342
|
+
authenticated: false,
|
|
343
|
+
query: { tenantId }
|
|
344
|
+
});
|
|
345
|
+
}
|
|
346
|
+
};
|
|
347
|
+
|
|
335
348
|
// src/client.ts
|
|
336
349
|
function createClient(options) {
|
|
337
350
|
let accessToken = options.accessToken ?? null;
|
|
@@ -358,6 +371,7 @@ function createClient(options) {
|
|
|
358
371
|
generation: new GenerationResource(http),
|
|
359
372
|
images: new ImagesResource(http),
|
|
360
373
|
payments: new PaymentsResource(http),
|
|
374
|
+
tenants: new TenantsResource(http),
|
|
361
375
|
setAccessToken(token) {
|
|
362
376
|
accessToken = token;
|
|
363
377
|
},
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/errors.ts","../src/http.ts","../src/resources/auth.ts","../src/resources/plans.ts","../src/resources/credits.ts","../src/resources/billing.ts","../src/resources/preferences.ts","../src/resources/conversations.ts","../src/resources/generation.ts","../src/resources/images.ts","../src/resources/payments.ts","../src/client.ts"],"sourcesContent":["export class ApiError extends Error {\n constructor(\n public readonly statusCode: number,\n public readonly code: string,\n message: string | string[],\n public readonly requestId?: string,\n ) {\n super(Array.isArray(message) ? message.join(\", \") : message);\n this.name = \"ApiError\";\n }\n}\n","import { ApiError } from \"./errors\";\nimport type { TokensResponseDto } from \"./types\";\n\nexport interface HttpClientConfig {\n baseUrl: string;\n tenantKey: string;\n getAccessToken: () => string | null;\n getRefreshToken: () => string | null;\n onTokenRefreshed: (tokens: TokensResponseDto) => void | Promise<void>;\n fetch?: typeof globalThis.fetch;\n}\n\ntype HttpMethod = \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\n\ninterface RequestOptions {\n body?: unknown;\n query?: Record<string, string | number | boolean | undefined | null>;\n authenticated?: boolean;\n}\n\ninterface InternalRequestOptions extends RequestOptions {\n isRetry?: boolean;\n}\n\nexport class HttpClient {\n private refreshPromise: Promise<boolean> | null = null;\n private readonly baseUrl: URL;\n private readonly fetchFn: typeof globalThis.fetch;\n\n constructor(private config: HttpClientConfig) {\n this.baseUrl = new URL(config.baseUrl);\n this.fetchFn = config.fetch ?? globalThis.fetch;\n }\n\n private buildAndFetch(\n method: HttpMethod,\n path: string,\n options: RequestOptions = {},\n ): Promise<Response> {\n const { body, query, authenticated = true } = options;\n\n const url = new URL(path, this.baseUrl);\n if (query) {\n for (const [key, value] of Object.entries(query)) {\n if (value !== undefined && value !== null) {\n url.searchParams.set(key, String(value));\n }\n }\n }\n\n const headers: Record<string, string> = {\n \"X-Tenant-Key\": this.config.tenantKey,\n };\n if (body !== undefined) {\n headers[\"Content-Type\"] = \"application/json\";\n }\n if (authenticated) {\n const token = this.config.getAccessToken();\n if (token) {\n headers[\"Authorization\"] = `Bearer ${token}`;\n }\n }\n\n return this.fetchFn(url.toString(), {\n method,\n headers,\n body: body !== undefined ? JSON.stringify(body) : undefined,\n });\n }\n\n private async throwIfError(response: Response): Promise<void> {\n if (!response.ok) {\n const errorBody = await response.json().catch(() => null);\n throw new ApiError(\n response.status,\n errorBody?.error?.code ?? \"UNKNOWN_ERROR\",\n errorBody?.error?.message ?? response.statusText,\n errorBody?.meta?.requestId,\n );\n }\n }\n\n private async request<T>(\n method: HttpMethod,\n path: string,\n options: InternalRequestOptions = {},\n ): Promise<T> {\n const { isRetry = false, authenticated = true } = options;\n\n const response = await this.buildAndFetch(method, path, options);\n\n if (response.status === 401 && !isRetry && authenticated) {\n const refreshed = await this.attemptTokenRefresh();\n if (refreshed) {\n return this.request<T>(method, path, { ...options, isRetry: true });\n }\n }\n\n await this.throwIfError(response);\n\n const contentType = response.headers.get(\"content-type\");\n if (!contentType?.includes(\"application/json\")) {\n return undefined as T;\n }\n\n const json = await response.json();\n return (json && \"data\" in json && \"meta\" in json ? json.data : json) as T;\n }\n\n private attemptTokenRefresh(): Promise<boolean> {\n if (this.refreshPromise) return this.refreshPromise;\n this.refreshPromise = this.doRefresh().finally(() => {\n this.refreshPromise = null;\n });\n return this.refreshPromise;\n }\n\n private async doRefresh(): Promise<boolean> {\n const refreshToken = this.config.getRefreshToken();\n if (!refreshToken) return false;\n\n try {\n const tokens = await this.request<TokensResponseDto>(\n \"POST\",\n \"/api/v1/auth/refresh\",\n {\n body: { refreshToken },\n authenticated: false,\n isRetry: true,\n },\n );\n await this.config.onTokenRefreshed(tokens);\n return true;\n } catch {\n return false;\n }\n }\n\n get<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>(\"GET\", path, options);\n }\n\n post<T>(path: string, body?: unknown, options?: Omit<RequestOptions, \"body\">): Promise<T> {\n return this.request<T>(\"POST\", path, { ...options, body });\n }\n\n patch<T>(path: string, body?: unknown, options?: Omit<RequestOptions, \"body\">): Promise<T> {\n return this.request<T>(\"PATCH\", path, { ...options, body });\n }\n\n put<T>(path: string, body?: unknown, options?: Omit<RequestOptions, \"body\">): Promise<T> {\n return this.request<T>(\"PUT\", path, { ...options, body });\n }\n\n delete<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>(\"DELETE\", path, options);\n }\n\n async rawRequest(method: HttpMethod, path: string, options: RequestOptions = {}): Promise<Response> {\n const { authenticated = true } = options;\n\n let response = await this.buildAndFetch(method, path, options);\n\n if (response.status === 401 && authenticated) {\n const refreshed = await this.attemptTokenRefresh();\n if (refreshed) {\n response = await this.buildAndFetch(method, path, options);\n }\n }\n\n await this.throwIfError(response);\n\n return response;\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type {\n RegisterDto,\n LoginDto,\n VerifyOtpDto,\n RefreshTokenDto,\n UpdateProfileDto,\n RequestEmailChangeDto,\n ConfirmEmailChangeDto,\n MessageResponseDto,\n AuthResponseDto,\n TokensResponseDto,\n UserResponseDto,\n StartAuthResponseDto,\n} from \"../types\";\n\nexport class AuthResource {\n constructor(private http: HttpClient) {}\n\n register(data: RegisterDto): Promise<MessageResponseDto> {\n return this.http.post(\"/api/v1/auth/register\", data, { authenticated: false });\n }\n\n login(data: LoginDto): Promise<MessageResponseDto> {\n return this.http.post(\"/api/v1/auth/login\", data, { authenticated: false });\n }\n\n startAuth(data: LoginDto): Promise<StartAuthResponseDto> {\n return this.http.post(\"/api/v1/auth/start\", data, { authenticated: false });\n }\n\n verifyOtp(data: VerifyOtpDto): Promise<AuthResponseDto> {\n return this.http.post(\"/api/v1/auth/verify-otp\", data, { authenticated: false });\n }\n\n refresh(data: RefreshTokenDto): Promise<TokensResponseDto> {\n return this.http.post(\"/api/v1/auth/refresh\", data, { authenticated: false });\n }\n\n logout(): Promise<void> {\n return this.http.post(\"/api/v1/auth/logout\");\n }\n\n getProfile(): Promise<UserResponseDto> {\n return this.http.get(\"/api/v1/auth/me\");\n }\n\n updateProfile(data: UpdateProfileDto): Promise<UserResponseDto> {\n return this.http.patch(\"/api/v1/auth/me\", data);\n }\n\n deleteAccount(): Promise<void> {\n return this.http.delete(\"/api/v1/auth/me\");\n }\n\n requestEmailChange(data: RequestEmailChangeDto): Promise<MessageResponseDto> {\n return this.http.post(\"/api/v1/auth/request-email-change\", data);\n }\n\n confirmEmailChange(data: ConfirmEmailChangeDto): Promise<MessageResponseDto> {\n return this.http.post(\"/api/v1/auth/confirm-email-change\", data);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type { PlanResponseDto, PlanType } from \"../types\";\n\nexport class PlansResource {\n constructor(private http: HttpClient) {}\n\n list(query?: { type?: PlanType }): Promise<PlanResponseDto[]> {\n return this.http.get(\"/api/v1/public/plans\", { query, authenticated: false });\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type {\n CreditBalanceResponseDto,\n CreditTransactionResponseDto,\n CreditTransactionType,\n PurchaseCreditsDto,\n PurchaseCreditsResponseDto,\n} from \"../types\";\n\nexport class CreditsResource {\n constructor(private http: HttpClient) {}\n\n getBalance(): Promise<CreditBalanceResponseDto> {\n return this.http.get(\"/api/v1/credits/balance\");\n }\n\n getTransactions(query?: {\n cursor?: string;\n limit?: number;\n type?: CreditTransactionType;\n }): Promise<CreditTransactionResponseDto[]> {\n return this.http.get(\"/api/v1/credits/transactions\", { query });\n }\n\n purchase(data: PurchaseCreditsDto): Promise<PurchaseCreditsResponseDto> {\n return this.http.post(\"/api/v1/credits/purchase\", data);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type { BillingResponseDto, UpsertBillingDto } from \"../types\";\n\nexport class BillingResource {\n constructor(private http: HttpClient) {}\n\n get(): Promise<BillingResponseDto> {\n return this.http.get(\"/api/v1/billing\");\n }\n\n upsert(data: UpsertBillingDto): Promise<BillingResponseDto> {\n return this.http.put(\"/api/v1/billing\", data);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type {\n PreferenceResponseDto,\n UpdatePreferencesDto,\n} from \"../types\";\n\nexport class PreferencesResource {\n constructor(private http: HttpClient) {}\n\n getAll(): Promise<PreferenceResponseDto[]> {\n return this.http.get(\"/api/v1/preferences\");\n }\n\n getByAppKey(appKey: string): Promise<PreferenceResponseDto> {\n return this.http.get(`/api/v1/preferences/${appKey}`);\n }\n\n upsert(appKey: string, data: UpdatePreferencesDto): Promise<PreferenceResponseDto> {\n return this.http.put(`/api/v1/preferences/${appKey}`, data);\n }\n\n remove(appKey: string): Promise<void> {\n return this.http.delete(`/api/v1/preferences/${appKey}`);\n }\n\n merge(appKey: string, data: UpdatePreferencesDto): Promise<PreferenceResponseDto> {\n return this.http.patch(`/api/v1/preferences/${appKey}`, data);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type {\n CreateConversationDto,\n ConversationResponseDto,\n ConversationMessageResponseDto,\n AddMessageDto,\n ConversationStatus,\n} from \"../types\";\n\nexport class ConversationsResource {\n constructor(private http: HttpClient) {}\n\n create(data: CreateConversationDto): Promise<ConversationResponseDto> {\n return this.http.post(\"/api/v1/conversations\", data);\n }\n\n list(query?: {\n cursor?: string;\n limit?: number;\n status?: ConversationStatus;\n appKey?: string;\n }): Promise<ConversationResponseDto[]> {\n return this.http.get(\"/api/v1/conversations\", { query });\n }\n\n get(id: string): Promise<ConversationResponseDto> {\n return this.http.get(`/api/v1/conversations/${id}`);\n }\n\n archive(id: string): Promise<ConversationResponseDto> {\n return this.http.patch(`/api/v1/conversations/${id}/archive`);\n }\n\n listMessages(conversationId: string, query?: {\n cursor?: string;\n limit?: number;\n }): Promise<ConversationMessageResponseDto[]> {\n return this.http.get(`/api/v1/conversations/${conversationId}/messages`, { query });\n }\n\n addMessage(conversationId: string, data: AddMessageDto): Promise<ConversationMessageResponseDto> {\n return this.http.post(`/api/v1/conversations/${conversationId}/messages`, data);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type { GenerateDto } from \"../types\";\n\nexport interface GenerationDoneData {\n messageId: string;\n usage?: { inputTokens: number; outputTokens: number };\n structuredOutput?: Record<string, unknown>;\n}\n\nexport interface SseStreamOptions {\n onTextDelta?: (text: string) => void;\n onDone?: (data: GenerationDoneData) => void;\n onError?: (error: string) => void;\n signal?: AbortSignal;\n}\n\ntype SseEvent =\n | { type: \"text_delta\"; text: string }\n | { type: \"done\"; messageId: string; usage?: { inputTokens: number; outputTokens: number }; structuredOutput?: Record<string, unknown> }\n | { type: \"error\"; error: string };\n\nexport class GenerationResource {\n constructor(private http: HttpClient) {}\n\n async generate(conversationId: string, data: GenerateDto, options?: SseStreamOptions): Promise<string> {\n const response = await this.http.rawRequest(\"POST\", `/api/v1/conversations/${conversationId}/generate`, {\n body: data,\n });\n\n const reader = response.body?.getReader();\n if (!reader) throw new Error(\"No response body\");\n\n const decoder = new TextDecoder();\n const parts: string[] = [];\n let buffer = \"\";\n\n try {\n while (true) {\n if (options?.signal?.aborted) {\n reader.cancel();\n break;\n }\n\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (!line.startsWith(\"data: \")) continue;\n const jsonStr = line.slice(6).trim();\n if (!jsonStr) continue;\n\n let event: SseEvent;\n try {\n event = JSON.parse(jsonStr);\n } catch {\n continue;\n }\n\n if (event.type === \"text_delta\") {\n parts.push(event.text);\n options?.onTextDelta?.(event.text);\n } else if (event.type === \"done\") {\n options?.onDone?.(event);\n } else if (event.type === \"error\") {\n options?.onError?.(event.error);\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n\n return parts.join(\"\");\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type {\n TriggerImageDto,\n ImageStatusResponseDto,\n} from \"../types\";\n\nexport class ImagesResource {\n constructor(private http: HttpClient) {}\n\n trigger(messageId: string, data: TriggerImageDto): Promise<ImageStatusResponseDto> {\n return this.http.post(`/api/v1/messages/${messageId}/images`, data);\n }\n\n getAll(messageId: string): Promise<ImageStatusResponseDto[]> {\n return this.http.get(`/api/v1/messages/${messageId}/images`);\n }\n\n getBySlot(messageId: string, slot: string): Promise<ImageStatusResponseDto> {\n return this.http.get(`/api/v1/messages/${messageId}/images/${slot}`);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type { CreateCheckoutDto, CheckoutResponseDto } from \"../types\";\n\nexport class PaymentsResource {\n constructor(private http: HttpClient) {}\n\n checkout(data: CreateCheckoutDto): Promise<CheckoutResponseDto> {\n return this.http.post(\"/api/v1/payments/checkout\", data);\n }\n}\n","import { HttpClient } from \"./http\";\nimport type { TokensResponseDto } from \"./types\";\nimport { AuthResource } from \"./resources/auth\";\nimport { PlansResource } from \"./resources/plans\";\nimport { CreditsResource } from \"./resources/credits\";\nimport { BillingResource } from \"./resources/billing\";\nimport { PreferencesResource } from \"./resources/preferences\";\nimport { ConversationsResource } from \"./resources/conversations\";\nimport { GenerationResource } from \"./resources/generation\";\nimport { ImagesResource } from \"./resources/images\";\nimport { PaymentsResource } from \"./resources/payments\";\n\nexport interface ClientOptions {\n baseUrl: string;\n tenantKey: string;\n accessToken?: string;\n refreshToken?: string;\n onTokenRefreshed?: (tokens: TokensResponseDto) => void | Promise<void>;\n fetch?: typeof globalThis.fetch;\n}\n\nexport interface AiAssistantsClient {\n auth: AuthResource;\n plans: PlansResource;\n credits: CreditsResource;\n billing: BillingResource;\n preferences: PreferencesResource;\n conversations: ConversationsResource;\n generation: GenerationResource;\n images: ImagesResource;\n payments: PaymentsResource;\n setAccessToken(token: string): void;\n setRefreshToken(token: string): void;\n}\n\nexport function createClient(options: ClientOptions): AiAssistantsClient {\n let accessToken = options.accessToken ?? null;\n let refreshToken = options.refreshToken ?? null;\n\n const http = new HttpClient({\n baseUrl: options.baseUrl,\n tenantKey: options.tenantKey,\n fetch: options.fetch,\n getAccessToken: () => accessToken,\n getRefreshToken: () => refreshToken,\n onTokenRefreshed: async (tokens) => {\n accessToken = tokens.accessToken;\n refreshToken = tokens.refreshToken;\n await options.onTokenRefreshed?.(tokens);\n },\n });\n\n return {\n auth: new AuthResource(http),\n plans: new PlansResource(http),\n credits: new CreditsResource(http),\n billing: new BillingResource(http),\n preferences: new PreferencesResource(http),\n conversations: new ConversationsResource(http),\n generation: new GenerationResource(http),\n images: new ImagesResource(http),\n payments: new PaymentsResource(http),\n setAccessToken(token: string) {\n accessToken = token;\n },\n setRefreshToken(token: string) {\n refreshToken = token;\n },\n };\n}\n"],"mappings":";AAAO,IAAM,WAAN,cAAuB,MAAM;AAAA,EAClC,YACk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mB,MAAM;AAAA,IACzC;AAAA,EACF,CAAC;AAED,SAAO;AAAA,IACL,MAAM,IAAI,aAAa,IAAI;AAAA,IAC3B,OAAO,IAAI,cAAc,IAAI;AAAA,IAC7B,SAAS,IAAI,gBAAgB,IAAI;AAAA,IACjC,SAAS,IAAI,gBAAgB,IAAI;AAAA,IACjC,aAAa,IAAI,oBAAoB,IAAI;AAAA,IACzC,eAAe,IAAI,sBAAsB,IAAI;AAAA,IAC7C,YAAY,IAAI,mBAAmB,IAAI;AAAA,IACvC,QAAQ,IAAI,eAAe,IAAI;AAAA,IAC/B,UAAU,IAAI,iBAAiB,IAAI;AAAA,IACnC,eAAe,OAAe;AAC5B,oBAAc;AAAA,IAChB;AAAA,IACA,gBAAgB,OAAe;AAC7B,qBAAe;AAAA,IACjB;AAAA,EACF;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/errors.ts","../src/http.ts","../src/resources/auth.ts","../src/resources/plans.ts","../src/resources/credits.ts","../src/resources/billing.ts","../src/resources/preferences.ts","../src/resources/conversations.ts","../src/resources/generation.ts","../src/resources/images.ts","../src/resources/payments.ts","../src/resources/tenants.ts","../src/client.ts"],"sourcesContent":["export class ApiError extends Error {\n constructor(\n public readonly statusCode: number,\n public readonly code: string,\n message: string | string[],\n public readonly requestId?: string,\n ) {\n super(Array.isArray(message) ? message.join(\", \") : message);\n this.name = \"ApiError\";\n }\n}\n","import { ApiError } from \"./errors\";\nimport type { TokensResponseDto } from \"./types\";\n\nexport interface HttpClientConfig {\n baseUrl: string;\n tenantKey: string;\n getAccessToken: () => string | null;\n getRefreshToken: () => string | null;\n onTokenRefreshed: (tokens: TokensResponseDto) => void | Promise<void>;\n fetch?: typeof globalThis.fetch;\n}\n\ntype HttpMethod = \"GET\" | \"POST\" | \"PUT\" | \"PATCH\" | \"DELETE\";\n\ninterface RequestOptions {\n body?: unknown;\n query?: Record<string, string | number | boolean | undefined | null>;\n authenticated?: boolean;\n}\n\ninterface InternalRequestOptions extends RequestOptions {\n isRetry?: boolean;\n}\n\nexport class HttpClient {\n private refreshPromise: Promise<boolean> | null = null;\n private readonly baseUrl: URL;\n private readonly fetchFn: typeof globalThis.fetch;\n\n constructor(private config: HttpClientConfig) {\n this.baseUrl = new URL(config.baseUrl);\n this.fetchFn = config.fetch ?? globalThis.fetch;\n }\n\n private buildAndFetch(\n method: HttpMethod,\n path: string,\n options: RequestOptions = {},\n ): Promise<Response> {\n const { body, query, authenticated = true } = options;\n\n const url = new URL(path, this.baseUrl);\n if (query) {\n for (const [key, value] of Object.entries(query)) {\n if (value !== undefined && value !== null) {\n url.searchParams.set(key, String(value));\n }\n }\n }\n\n const headers: Record<string, string> = {\n \"X-Tenant-Key\": this.config.tenantKey,\n };\n if (body !== undefined) {\n headers[\"Content-Type\"] = \"application/json\";\n }\n if (authenticated) {\n const token = this.config.getAccessToken();\n if (token) {\n headers[\"Authorization\"] = `Bearer ${token}`;\n }\n }\n\n return this.fetchFn(url.toString(), {\n method,\n headers,\n body: body !== undefined ? JSON.stringify(body) : undefined,\n });\n }\n\n private async throwIfError(response: Response): Promise<void> {\n if (!response.ok) {\n const errorBody = await response.json().catch(() => null);\n throw new ApiError(\n response.status,\n errorBody?.error?.code ?? \"UNKNOWN_ERROR\",\n errorBody?.error?.message ?? response.statusText,\n errorBody?.meta?.requestId,\n );\n }\n }\n\n private async request<T>(\n method: HttpMethod,\n path: string,\n options: InternalRequestOptions = {},\n ): Promise<T> {\n const { isRetry = false, authenticated = true } = options;\n\n const response = await this.buildAndFetch(method, path, options);\n\n if (response.status === 401 && !isRetry && authenticated) {\n const refreshed = await this.attemptTokenRefresh();\n if (refreshed) {\n return this.request<T>(method, path, { ...options, isRetry: true });\n }\n }\n\n await this.throwIfError(response);\n\n const contentType = response.headers.get(\"content-type\");\n if (!contentType?.includes(\"application/json\")) {\n return undefined as T;\n }\n\n const json = await response.json();\n return (json && \"data\" in json && \"meta\" in json ? json.data : json) as T;\n }\n\n private attemptTokenRefresh(): Promise<boolean> {\n if (this.refreshPromise) return this.refreshPromise;\n this.refreshPromise = this.doRefresh().finally(() => {\n this.refreshPromise = null;\n });\n return this.refreshPromise;\n }\n\n private async doRefresh(): Promise<boolean> {\n const refreshToken = this.config.getRefreshToken();\n if (!refreshToken) return false;\n\n try {\n const tokens = await this.request<TokensResponseDto>(\n \"POST\",\n \"/api/v1/auth/refresh\",\n {\n body: { refreshToken },\n authenticated: false,\n isRetry: true,\n },\n );\n await this.config.onTokenRefreshed(tokens);\n return true;\n } catch {\n return false;\n }\n }\n\n get<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>(\"GET\", path, options);\n }\n\n post<T>(path: string, body?: unknown, options?: Omit<RequestOptions, \"body\">): Promise<T> {\n return this.request<T>(\"POST\", path, { ...options, body });\n }\n\n patch<T>(path: string, body?: unknown, options?: Omit<RequestOptions, \"body\">): Promise<T> {\n return this.request<T>(\"PATCH\", path, { ...options, body });\n }\n\n put<T>(path: string, body?: unknown, options?: Omit<RequestOptions, \"body\">): Promise<T> {\n return this.request<T>(\"PUT\", path, { ...options, body });\n }\n\n delete<T>(path: string, options?: RequestOptions): Promise<T> {\n return this.request<T>(\"DELETE\", path, options);\n }\n\n async rawRequest(method: HttpMethod, path: string, options: RequestOptions = {}): Promise<Response> {\n const { authenticated = true } = options;\n\n let response = await this.buildAndFetch(method, path, options);\n\n if (response.status === 401 && authenticated) {\n const refreshed = await this.attemptTokenRefresh();\n if (refreshed) {\n response = await this.buildAndFetch(method, path, options);\n }\n }\n\n await this.throwIfError(response);\n\n return response;\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type {\n RegisterDto,\n LoginDto,\n VerifyOtpDto,\n RefreshTokenDto,\n UpdateProfileDto,\n RequestEmailChangeDto,\n ConfirmEmailChangeDto,\n MessageResponseDto,\n AuthResponseDto,\n TokensResponseDto,\n UserResponseDto,\n StartAuthResponseDto,\n} from \"../types\";\n\nexport class AuthResource {\n constructor(private http: HttpClient) {}\n\n register(data: RegisterDto): Promise<MessageResponseDto> {\n return this.http.post(\"/api/v1/auth/register\", data, { authenticated: false });\n }\n\n login(data: LoginDto): Promise<MessageResponseDto> {\n return this.http.post(\"/api/v1/auth/login\", data, { authenticated: false });\n }\n\n startAuth(data: LoginDto): Promise<StartAuthResponseDto> {\n return this.http.post(\"/api/v1/auth/start\", data, { authenticated: false });\n }\n\n verifyOtp(data: VerifyOtpDto): Promise<AuthResponseDto> {\n return this.http.post(\"/api/v1/auth/verify-otp\", data, { authenticated: false });\n }\n\n refresh(data: RefreshTokenDto): Promise<TokensResponseDto> {\n return this.http.post(\"/api/v1/auth/refresh\", data, { authenticated: false });\n }\n\n logout(): Promise<void> {\n return this.http.post(\"/api/v1/auth/logout\");\n }\n\n getProfile(): Promise<UserResponseDto> {\n return this.http.get(\"/api/v1/auth/me\");\n }\n\n updateProfile(data: UpdateProfileDto): Promise<UserResponseDto> {\n return this.http.patch(\"/api/v1/auth/me\", data);\n }\n\n deleteAccount(): Promise<void> {\n return this.http.delete(\"/api/v1/auth/me\");\n }\n\n requestEmailChange(data: RequestEmailChangeDto): Promise<MessageResponseDto> {\n return this.http.post(\"/api/v1/auth/request-email-change\", data);\n }\n\n confirmEmailChange(data: ConfirmEmailChangeDto): Promise<MessageResponseDto> {\n return this.http.post(\"/api/v1/auth/confirm-email-change\", data);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type { PlanResponseDto } from \"../types\";\n\nexport class PlansResource {\n constructor(private http: HttpClient) {}\n\n list(): Promise<PlanResponseDto[]> {\n return this.http.get(\"/api/v1/public/plans\", { authenticated: false });\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type {\n CreditBalanceResponseDto,\n CreditTransactionResponseDto,\n CreditTransactionType,\n PurchaseCreditsDto,\n PurchaseCreditsResponseDto,\n} from \"../types\";\n\nexport class CreditsResource {\n constructor(private http: HttpClient) {}\n\n getBalance(): Promise<CreditBalanceResponseDto> {\n return this.http.get(\"/api/v1/credits/balance\");\n }\n\n getTransactions(query?: {\n cursor?: string;\n limit?: number;\n type?: CreditTransactionType;\n }): Promise<CreditTransactionResponseDto[]> {\n return this.http.get(\"/api/v1/credits/transactions\", { query });\n }\n\n purchase(data: PurchaseCreditsDto): Promise<PurchaseCreditsResponseDto> {\n return this.http.post(\"/api/v1/credits/purchase\", data);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type { BillingResponseDto, UpsertBillingDto } from \"../types\";\n\nexport class BillingResource {\n constructor(private http: HttpClient) {}\n\n get(): Promise<BillingResponseDto> {\n return this.http.get(\"/api/v1/billing\");\n }\n\n upsert(data: UpsertBillingDto): Promise<BillingResponseDto> {\n return this.http.put(\"/api/v1/billing\", data);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type {\n PreferenceResponseDto,\n UpdatePreferencesDto,\n} from \"../types\";\n\nexport class PreferencesResource {\n constructor(private http: HttpClient) {}\n\n getAll(): Promise<PreferenceResponseDto[]> {\n return this.http.get(\"/api/v1/preferences\");\n }\n\n getByAppKey(appKey: string): Promise<PreferenceResponseDto> {\n return this.http.get(`/api/v1/preferences/${appKey}`);\n }\n\n upsert(appKey: string, data: UpdatePreferencesDto): Promise<PreferenceResponseDto> {\n return this.http.put(`/api/v1/preferences/${appKey}`, data);\n }\n\n remove(appKey: string): Promise<void> {\n return this.http.delete(`/api/v1/preferences/${appKey}`);\n }\n\n merge(appKey: string, data: UpdatePreferencesDto): Promise<PreferenceResponseDto> {\n return this.http.patch(`/api/v1/preferences/${appKey}`, data);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type {\n CreateConversationDto,\n ConversationResponseDto,\n ConversationMessageResponseDto,\n AddMessageDto,\n ConversationStatus,\n} from \"../types\";\n\nexport class ConversationsResource {\n constructor(private http: HttpClient) {}\n\n create(data: CreateConversationDto): Promise<ConversationResponseDto> {\n return this.http.post(\"/api/v1/conversations\", data);\n }\n\n list(query?: {\n cursor?: string;\n limit?: number;\n status?: ConversationStatus;\n appKey?: string;\n }): Promise<ConversationResponseDto[]> {\n return this.http.get(\"/api/v1/conversations\", { query });\n }\n\n get(id: string): Promise<ConversationResponseDto> {\n return this.http.get(`/api/v1/conversations/${id}`);\n }\n\n archive(id: string): Promise<ConversationResponseDto> {\n return this.http.patch(`/api/v1/conversations/${id}/archive`);\n }\n\n listMessages(conversationId: string, query?: {\n cursor?: string;\n limit?: number;\n }): Promise<ConversationMessageResponseDto[]> {\n return this.http.get(`/api/v1/conversations/${conversationId}/messages`, { query });\n }\n\n addMessage(conversationId: string, data: AddMessageDto): Promise<ConversationMessageResponseDto> {\n return this.http.post(`/api/v1/conversations/${conversationId}/messages`, data);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type { GenerateDto } from \"../types\";\n\nexport interface GenerationDoneData {\n messageId: string;\n usage?: { inputTokens: number; outputTokens: number };\n structuredOutput?: Record<string, unknown>;\n}\n\nexport interface SseStreamOptions {\n onTextDelta?: (text: string) => void;\n onDone?: (data: GenerationDoneData) => void;\n onError?: (error: string) => void;\n signal?: AbortSignal;\n}\n\ntype SseEvent =\n | { type: \"text_delta\"; text: string }\n | { type: \"done\"; messageId: string; usage?: { inputTokens: number; outputTokens: number }; structuredOutput?: Record<string, unknown> }\n | { type: \"error\"; error: string };\n\nexport class GenerationResource {\n constructor(private http: HttpClient) {}\n\n async generate(conversationId: string, data: GenerateDto, options?: SseStreamOptions): Promise<string> {\n const response = await this.http.rawRequest(\"POST\", `/api/v1/conversations/${conversationId}/generate`, {\n body: data,\n });\n\n const reader = response.body?.getReader();\n if (!reader) throw new Error(\"No response body\");\n\n const decoder = new TextDecoder();\n const parts: string[] = [];\n let buffer = \"\";\n\n try {\n while (true) {\n if (options?.signal?.aborted) {\n reader.cancel();\n break;\n }\n\n const { done, value } = await reader.read();\n if (done) break;\n\n buffer += decoder.decode(value, { stream: true });\n const lines = buffer.split(\"\\n\");\n buffer = lines.pop() ?? \"\";\n\n for (const line of lines) {\n if (!line.startsWith(\"data: \")) continue;\n const jsonStr = line.slice(6).trim();\n if (!jsonStr) continue;\n\n let event: SseEvent;\n try {\n event = JSON.parse(jsonStr);\n } catch {\n continue;\n }\n\n if (event.type === \"text_delta\") {\n parts.push(event.text);\n options?.onTextDelta?.(event.text);\n } else if (event.type === \"done\") {\n options?.onDone?.(event);\n } else if (event.type === \"error\") {\n options?.onError?.(event.error);\n }\n }\n }\n } finally {\n reader.releaseLock();\n }\n\n return parts.join(\"\");\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type {\n TriggerImageDto,\n ImageStatusResponseDto,\n} from \"../types\";\n\nexport class ImagesResource {\n constructor(private http: HttpClient) {}\n\n trigger(messageId: string, data: TriggerImageDto): Promise<ImageStatusResponseDto> {\n return this.http.post(`/api/v1/messages/${messageId}/images`, data);\n }\n\n getAll(messageId: string): Promise<ImageStatusResponseDto[]> {\n return this.http.get(`/api/v1/messages/${messageId}/images`);\n }\n\n getBySlot(messageId: string, slot: string): Promise<ImageStatusResponseDto> {\n return this.http.get(`/api/v1/messages/${messageId}/images/${slot}`);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type { CreateCheckoutDto, CheckoutResponseDto } from \"../types\";\n\nexport class PaymentsResource {\n constructor(private http: HttpClient) {}\n\n checkout(data: CreateCheckoutDto): Promise<CheckoutResponseDto> {\n return this.http.post(\"/api/v1/payments/checkout\", data);\n }\n}\n","import type { HttpClient } from \"../http\";\nimport type { TenantPublicInfoDto } from \"../types\";\n\nexport class TenantsResource {\n constructor(private http: HttpClient) {}\n\n getPublicInfo(tenantId: string): Promise<TenantPublicInfoDto> {\n return this.http.get(\"/api/v1/tenants/public-info\", {\n authenticated: false,\n query: { tenantId },\n });\n }\n}\n","import { HttpClient } from \"./http\";\nimport type { TokensResponseDto } from \"./types\";\nimport { AuthResource } from \"./resources/auth\";\nimport { PlansResource } from \"./resources/plans\";\nimport { CreditsResource } from \"./resources/credits\";\nimport { BillingResource } from \"./resources/billing\";\nimport { PreferencesResource } from \"./resources/preferences\";\nimport { ConversationsResource } from \"./resources/conversations\";\nimport { GenerationResource } from \"./resources/generation\";\nimport { ImagesResource } from \"./resources/images\";\nimport { PaymentsResource } from \"./resources/payments\";\nimport { TenantsResource } from \"./resources/tenants\";\n\nexport interface ClientOptions {\n baseUrl: string;\n tenantKey: string;\n accessToken?: string;\n refreshToken?: string;\n onTokenRefreshed?: (tokens: TokensResponseDto) => void | Promise<void>;\n fetch?: typeof globalThis.fetch;\n}\n\nexport interface AiAssistantsClient {\n auth: AuthResource;\n plans: PlansResource;\n credits: CreditsResource;\n billing: BillingResource;\n preferences: PreferencesResource;\n conversations: ConversationsResource;\n generation: GenerationResource;\n images: ImagesResource;\n payments: PaymentsResource;\n tenants: TenantsResource;\n setAccessToken(token: string): void;\n setRefreshToken(token: string): void;\n}\n\nexport function createClient(options: ClientOptions): AiAssistantsClient {\n let accessToken = options.accessToken ?? null;\n let refreshToken = options.refreshToken ?? null;\n\n const http = new HttpClient({\n baseUrl: options.baseUrl,\n tenantKey: options.tenantKey,\n fetch: options.fetch,\n getAccessToken: () => accessToken,\n getRefreshToken: () => refreshToken,\n onTokenRefreshed: async (tokens) => {\n accessToken = tokens.accessToken;\n refreshToken = tokens.refreshToken;\n await options.onTokenRefreshed?.(tokens);\n },\n });\n\n return {\n auth: new AuthResource(http),\n plans: new PlansResource(http),\n credits: new CreditsResource(http),\n billing: new BillingResource(http),\n preferences: new PreferencesResource(http),\n conversations: new ConversationsResource(http),\n generation: new GenerationResource(http),\n images: new ImagesResource(http),\n payments: new PaymentsResource(http),\n tenants: new TenantsResource(http),\n setAccessToken(token: string) {\n accessToken = token;\n },\n setRefreshToken(token: string) {\n refreshToken = token;\n },\n };\n}\n"],"mappings":";AAAO,IAAM,WAAN,cAAuB,MAAM;AAAA,EAClC,YACkB,YACA,MAChB,SACgB,WAChB;AACA,UAAM,MAAM,QAAQ,OAAO,IAAI,QAAQ,KAAK,IAAI,IAAI,OAAO;AAL3C;AACA;AAEA;AAGhB,SAAK,OAAO;AAAA,EACd;AACF;;;ACcO,IAAM,aAAN,MAAiB;AAAA,EA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