@zdrops/ai-assistants-sdk 1.2.0 → 1.3.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 +7 -0
- package/dist/index.cjs +6 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +32 -1
- package/dist/index.d.ts +32 -1
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [1.3.0](https://github.com/ZDrops/ai-assistants-sdk/compare/ai-assistants-sdk-v1.2.0...ai-assistants-sdk-v1.3.0) (2026-05-09)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **payments:** add custom checkout and credit pricing endpoints with corresponding DTOs ([605ef68](https://github.com/ZDrops/ai-assistants-sdk/commit/605ef6801bde016b2613330eac4e1879d052b35c))
|
|
9
|
+
|
|
3
10
|
## [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
11
|
|
|
5
12
|
|
package/dist/index.cjs
CHANGED
|
@@ -357,6 +357,12 @@ var PaymentsResource = class {
|
|
|
357
357
|
checkout(data) {
|
|
358
358
|
return this.http.post("/api/v1/payments/checkout", data);
|
|
359
359
|
}
|
|
360
|
+
checkoutCustom(data) {
|
|
361
|
+
return this.http.post("/api/v1/payments/checkout/custom", data);
|
|
362
|
+
}
|
|
363
|
+
creditPricing() {
|
|
364
|
+
return this.http.get("/api/v1/payments/credit-pricing");
|
|
365
|
+
}
|
|
360
366
|
};
|
|
361
367
|
|
|
362
368
|
// src/resources/tenants.ts
|
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/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,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,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,SAAS,IAAI,gBAAgB,IAAI;AAAA,IACjC,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 CreateCustomCheckoutDto,\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 CreditPricingResponseDto,\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 {\n CreateCheckoutDto,\n CreateCustomCheckoutDto,\n CheckoutResponseDto,\n CreditPricingResponseDto,\n} 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 checkoutCustom(data: CreateCustomCheckoutDto): Promise<CheckoutResponseDto> {\n return this.http.post(\"/api/v1/payments/checkout/custom\", data);\n }\n\n creditPricing(): Promise<CreditPricingResponseDto> {\n return this.http.get(\"/api/v1/payments/credit-pricing\");\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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AAO,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,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
|
@@ -334,6 +334,33 @@ interface components {
|
|
|
334
334
|
/** @example https://pay.whitegallo.com/session/xyz */
|
|
335
335
|
redirectUrl: string;
|
|
336
336
|
};
|
|
337
|
+
CreditPricingResponseDto: {
|
|
338
|
+
/**
|
|
339
|
+
* @description Price per credit in cents
|
|
340
|
+
* @example 5
|
|
341
|
+
*/
|
|
342
|
+
priceCents: number;
|
|
343
|
+
/** @example EUR */
|
|
344
|
+
currency: string;
|
|
345
|
+
/**
|
|
346
|
+
* @description Minimum credits per custom purchase
|
|
347
|
+
* @example 1
|
|
348
|
+
*/
|
|
349
|
+
min: number;
|
|
350
|
+
/** @description Maximum credits per custom purchase, or null if unbounded */
|
|
351
|
+
max?: number | null;
|
|
352
|
+
};
|
|
353
|
+
CreateCustomCheckoutDto: {
|
|
354
|
+
/**
|
|
355
|
+
* @description Number of credits to purchase
|
|
356
|
+
* @example 250
|
|
357
|
+
*/
|
|
358
|
+
credits: number;
|
|
359
|
+
/** @example https://app.example.com/payment/success */
|
|
360
|
+
returnUrl: string;
|
|
361
|
+
/** @example https://app.example.com/payment/cancel */
|
|
362
|
+
cancelUrl: string;
|
|
363
|
+
};
|
|
337
364
|
};
|
|
338
365
|
responses: never;
|
|
339
366
|
parameters: never;
|
|
@@ -357,6 +384,7 @@ type AddMessageDto = components["schemas"]["AddMessageDto"];
|
|
|
357
384
|
type GenerateDto = components["schemas"]["GenerateDto"];
|
|
358
385
|
type TriggerImageDto = components["schemas"]["TriggerImageDto"];
|
|
359
386
|
type CreateCheckoutDto = components["schemas"]["CreateCheckoutDto"];
|
|
387
|
+
type CreateCustomCheckoutDto = components["schemas"]["CreateCustomCheckoutDto"];
|
|
360
388
|
type MessageResponseDto = components["schemas"]["MessageResponseDto"];
|
|
361
389
|
type StartAuthResponseDto = MessageResponseDto & {
|
|
362
390
|
type: OtpType;
|
|
@@ -378,6 +406,7 @@ type ConversationResponseDto = components["schemas"]["ConversationResponseDto"]
|
|
|
378
406
|
type ConversationMessageResponseDto = components["schemas"]["ConversationMessageResponseDto"];
|
|
379
407
|
type ImageStatusResponseDto = components["schemas"]["ImageStatusResponseDto"];
|
|
380
408
|
type CheckoutResponseDto = components["schemas"]["CheckoutResponseDto"];
|
|
409
|
+
type CreditPricingResponseDto = components["schemas"]["CreditPricingResponseDto"];
|
|
381
410
|
type TenantPublicInfoDto = components["schemas"]["TenantPublicInfoDto"];
|
|
382
411
|
type OtpType = components["schemas"]["OtpType"];
|
|
383
412
|
type UserRole = components["schemas"]["UserRole"];
|
|
@@ -522,6 +551,8 @@ declare class PaymentsResource {
|
|
|
522
551
|
private http;
|
|
523
552
|
constructor(http: HttpClient);
|
|
524
553
|
checkout(data: CreateCheckoutDto): Promise<CheckoutResponseDto>;
|
|
554
|
+
checkoutCustom(data: CreateCustomCheckoutDto): Promise<CheckoutResponseDto>;
|
|
555
|
+
creditPricing(): Promise<CreditPricingResponseDto>;
|
|
525
556
|
}
|
|
526
557
|
|
|
527
558
|
declare class TenantsResource {
|
|
@@ -561,4 +592,4 @@ declare class ApiError extends Error {
|
|
|
561
592
|
constructor(statusCode: number, code: string, message: string | string[], requestId?: string | undefined);
|
|
562
593
|
}
|
|
563
594
|
|
|
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 };
|
|
595
|
+
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 CreateCustomCheckoutDto, type CreditBalanceEntityResponseDto, type CreditBalanceResponseDto, type CreditPricingResponseDto, 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
|
@@ -334,6 +334,33 @@ interface components {
|
|
|
334
334
|
/** @example https://pay.whitegallo.com/session/xyz */
|
|
335
335
|
redirectUrl: string;
|
|
336
336
|
};
|
|
337
|
+
CreditPricingResponseDto: {
|
|
338
|
+
/**
|
|
339
|
+
* @description Price per credit in cents
|
|
340
|
+
* @example 5
|
|
341
|
+
*/
|
|
342
|
+
priceCents: number;
|
|
343
|
+
/** @example EUR */
|
|
344
|
+
currency: string;
|
|
345
|
+
/**
|
|
346
|
+
* @description Minimum credits per custom purchase
|
|
347
|
+
* @example 1
|
|
348
|
+
*/
|
|
349
|
+
min: number;
|
|
350
|
+
/** @description Maximum credits per custom purchase, or null if unbounded */
|
|
351
|
+
max?: number | null;
|
|
352
|
+
};
|
|
353
|
+
CreateCustomCheckoutDto: {
|
|
354
|
+
/**
|
|
355
|
+
* @description Number of credits to purchase
|
|
356
|
+
* @example 250
|
|
357
|
+
*/
|
|
358
|
+
credits: number;
|
|
359
|
+
/** @example https://app.example.com/payment/success */
|
|
360
|
+
returnUrl: string;
|
|
361
|
+
/** @example https://app.example.com/payment/cancel */
|
|
362
|
+
cancelUrl: string;
|
|
363
|
+
};
|
|
337
364
|
};
|
|
338
365
|
responses: never;
|
|
339
366
|
parameters: never;
|
|
@@ -357,6 +384,7 @@ type AddMessageDto = components["schemas"]["AddMessageDto"];
|
|
|
357
384
|
type GenerateDto = components["schemas"]["GenerateDto"];
|
|
358
385
|
type TriggerImageDto = components["schemas"]["TriggerImageDto"];
|
|
359
386
|
type CreateCheckoutDto = components["schemas"]["CreateCheckoutDto"];
|
|
387
|
+
type CreateCustomCheckoutDto = components["schemas"]["CreateCustomCheckoutDto"];
|
|
360
388
|
type MessageResponseDto = components["schemas"]["MessageResponseDto"];
|
|
361
389
|
type StartAuthResponseDto = MessageResponseDto & {
|
|
362
390
|
type: OtpType;
|
|
@@ -378,6 +406,7 @@ type ConversationResponseDto = components["schemas"]["ConversationResponseDto"]
|
|
|
378
406
|
type ConversationMessageResponseDto = components["schemas"]["ConversationMessageResponseDto"];
|
|
379
407
|
type ImageStatusResponseDto = components["schemas"]["ImageStatusResponseDto"];
|
|
380
408
|
type CheckoutResponseDto = components["schemas"]["CheckoutResponseDto"];
|
|
409
|
+
type CreditPricingResponseDto = components["schemas"]["CreditPricingResponseDto"];
|
|
381
410
|
type TenantPublicInfoDto = components["schemas"]["TenantPublicInfoDto"];
|
|
382
411
|
type OtpType = components["schemas"]["OtpType"];
|
|
383
412
|
type UserRole = components["schemas"]["UserRole"];
|
|
@@ -522,6 +551,8 @@ declare class PaymentsResource {
|
|
|
522
551
|
private http;
|
|
523
552
|
constructor(http: HttpClient);
|
|
524
553
|
checkout(data: CreateCheckoutDto): Promise<CheckoutResponseDto>;
|
|
554
|
+
checkoutCustom(data: CreateCustomCheckoutDto): Promise<CheckoutResponseDto>;
|
|
555
|
+
creditPricing(): Promise<CreditPricingResponseDto>;
|
|
525
556
|
}
|
|
526
557
|
|
|
527
558
|
declare class TenantsResource {
|
|
@@ -561,4 +592,4 @@ declare class ApiError extends Error {
|
|
|
561
592
|
constructor(statusCode: number, code: string, message: string | string[], requestId?: string | undefined);
|
|
562
593
|
}
|
|
563
594
|
|
|
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 };
|
|
595
|
+
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 CreateCustomCheckoutDto, type CreditBalanceEntityResponseDto, type CreditBalanceResponseDto, type CreditPricingResponseDto, 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
|
@@ -330,6 +330,12 @@ var PaymentsResource = class {
|
|
|
330
330
|
checkout(data) {
|
|
331
331
|
return this.http.post("/api/v1/payments/checkout", data);
|
|
332
332
|
}
|
|
333
|
+
checkoutCustom(data) {
|
|
334
|
+
return this.http.post("/api/v1/payments/checkout/custom", data);
|
|
335
|
+
}
|
|
336
|
+
creditPricing() {
|
|
337
|
+
return this.http.get("/api/v1/payments/credit-pricing");
|
|
338
|
+
}
|
|
333
339
|
};
|
|
334
340
|
|
|
335
341
|
// src/resources/tenants.ts
|
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/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,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,KAA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AAI;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":[]}
|
|
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 {\n CreateCheckoutDto,\n CreateCustomCheckoutDto,\n CheckoutResponseDto,\n CreditPricingResponseDto,\n} 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 checkoutCustom(data: CreateCustomCheckoutDto): Promise<CheckoutResponseDto> {\n return this.http.post(\"/api/v1/payments/checkout/custom\", data);\n }\n\n creditPricing(): Promise<CreditPricingResponseDto> {\n return this.http.get(\"/api/v1/payments/credit-pricing\");\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,EAKtB,YAAoB,QAA0B;AAA1B;AAJpB,SAAQ,iBAA0C;AAKhD,SAAK,UA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