vly-integrations
Version:
First-order integrations for AI, email, and payments with automatic usage billing
254 lines (246 loc) • 8.41 kB
text/typescript
import * as _ai_sdk_openai_compatible from '@ai-sdk/openai-compatible';
export { CoreMessage } from 'ai';
interface VlyConfig {
deploymentToken: string;
debug?: boolean;
}
interface RequestOptions {
timeout?: number;
retries?: number;
}
interface ApiResponse<T = any> {
success: boolean;
data?: T;
error?: string;
usage?: {
credits: number;
operation: string;
};
}
type AIModel = string;
interface AICompletionRequest {
model?: AIModel;
messages: Array<{
role: 'system' | 'user' | 'assistant';
content: string;
}>;
temperature?: number;
maxTokens?: number;
stream?: boolean;
}
interface AICompletionResponse {
id: string;
choices: Array<{
message: {
role: string;
content: string;
};
finishReason: string;
}>;
usage: {
promptTokens: number;
completionTokens: number;
totalTokens: number;
};
}
interface EmailRequest {
to: string | string[];
from?: string;
subject: string;
html?: string;
text?: string;
attachments?: Array<{
filename: string;
content: string;
encoding?: string;
}>;
replyTo?: string;
cc?: string | string[];
bcc?: string | string[];
}
interface EmailResponse {
id: string;
status: 'sent' | 'queued' | 'failed';
messageId?: string;
error?: string;
}
interface PaymentIntent {
amount: number;
currency?: string;
description?: string;
metadata?: Record<string, any>;
customer?: {
email?: string;
name?: string;
id?: string;
};
}
interface PaymentIntentResponse {
id: string;
clientSecret: string;
amount: number;
currency: string;
status: 'requires_payment_method' | 'requires_confirmation' | 'succeeded' | 'processing' | 'canceled';
paymentMethodTypes: string[];
}
interface Subscription {
customerId: string;
priceId: string;
metadata?: Record<string, any>;
trialPeriodDays?: number;
cancelAtPeriodEnd?: boolean;
}
interface SubscriptionResponse {
id: string;
customerId: string;
status: 'active' | 'past_due' | 'canceled' | 'incomplete' | 'trialing';
currentPeriodEnd: string;
items: Array<{
id: string;
priceId: string;
quantity: number;
}>;
}
interface CustomerPortalSession {
customerId: string;
returnUrl?: string;
}
interface CustomerPortalResponse {
id: string;
url: string;
returnUrl?: string;
created: number;
}
declare class VlyAI {
private provider;
private config;
constructor(config: VlyConfig);
private getModel;
private mapMessages;
completion(request: AICompletionRequest, _options?: RequestOptions): Promise<ApiResponse<AICompletionResponse>>;
streamCompletion(request: AICompletionRequest, onChunk: (chunk: string) => void, _options?: RequestOptions): Promise<ApiResponse<AICompletionResponse>>;
embeddings(input: string | string[], _options?: RequestOptions & {
model?: string;
}): Promise<ApiResponse<{
embeddings: number[][];
usage: any;
}>>;
getProvider(): _ai_sdk_openai_compatible.OpenAICompatibleProvider<string, string, string, string>;
}
declare class VlyClient {
protected config: Required<VlyConfig>;
constructor(config: VlyConfig);
protected request<T = any>(endpoint: string, method: 'GET' | 'POST' | 'PUT' | 'DELETE', data?: any, options?: RequestOptions): Promise<ApiResponse<T>>;
protected log(message: string, data?: any): void;
}
declare class VlyEmail extends VlyClient {
send(email: EmailRequest, options?: RequestOptions): Promise<ApiResponse<EmailResponse>>;
sendBatch(emails: EmailRequest[], options?: RequestOptions): Promise<ApiResponse<EmailResponse[]>>;
getStatus(emailId: string, options?: RequestOptions): Promise<ApiResponse<EmailResponse>>;
verifyDomain(domain: string, options?: RequestOptions): Promise<ApiResponse<{
domain: string;
verified: boolean;
dnsRecords: Array<{
type: string;
name: string;
value: string;
verified: boolean;
}>;
}>>;
listDomains(options?: RequestOptions): Promise<ApiResponse<Array<{
domain: string;
verified: boolean;
createdAt: string;
verifiedAt?: string;
}>>>;
}
declare class VlyPayments extends VlyClient {
createPaymentIntent(intent: PaymentIntent, options?: RequestOptions): Promise<ApiResponse<PaymentIntentResponse>>;
confirmPaymentIntent(intentId: string, paymentMethodId: string, options?: RequestOptions): Promise<ApiResponse<PaymentIntentResponse>>;
getPaymentIntent(intentId: string, options?: RequestOptions): Promise<ApiResponse<PaymentIntentResponse>>;
cancelPaymentIntent(intentId: string, options?: RequestOptions): Promise<ApiResponse<PaymentIntentResponse>>;
createSubscription(subscription: Subscription, options?: RequestOptions): Promise<ApiResponse<SubscriptionResponse>>;
updateSubscription(subscriptionId: string, updates: Partial<Subscription>, options?: RequestOptions): Promise<ApiResponse<SubscriptionResponse>>;
cancelSubscription(subscriptionId: string, immediately?: boolean, options?: RequestOptions): Promise<ApiResponse<SubscriptionResponse>>;
getSubscription(subscriptionId: string, options?: RequestOptions): Promise<ApiResponse<SubscriptionResponse>>;
listSubscriptions(customerId?: string, options?: RequestOptions & {
limit?: number;
offset?: number;
}): Promise<ApiResponse<{
subscriptions: SubscriptionResponse[];
hasMore: boolean;
total: number;
}>>;
createCustomerPortal(session: CustomerPortalSession, options?: RequestOptions): Promise<ApiResponse<CustomerPortalResponse>>;
createCheckoutSession(session: {
customerId?: string;
customerEmail?: string;
lineItems: Array<{
priceId: string;
quantity: number;
}>;
mode: 'payment' | 'subscription';
successUrl: string;
cancelUrl: string;
metadata?: Record<string, any>;
}, options?: RequestOptions): Promise<ApiResponse<{
id: string;
url: string;
}>>;
createCustomer(customer: {
email: string;
name?: string;
metadata?: Record<string, any>;
}, options?: RequestOptions): Promise<ApiResponse<{
id: string;
email: string;
name?: string;
created: number;
}>>;
getCustomer(customerId: string, options?: RequestOptions): Promise<ApiResponse<{
id: string;
email: string;
name?: string;
created: number;
metadata?: Record<string, any>;
}>>;
updateCustomer(customerId: string, updates: {
email?: string;
name?: string;
metadata?: Record<string, any>;
}, options?: RequestOptions): Promise<ApiResponse<{
id: string;
email: string;
name?: string;
created: number;
metadata?: Record<string, any>;
}>>;
listPaymentMethods(customerId: string, options?: RequestOptions): Promise<ApiResponse<Array<{
id: string;
type: string;
card?: {
brand: string;
last4: string;
expMonth: number;
expYear: number;
};
created: number;
}>>>;
attachPaymentMethod(paymentMethodId: string, customerId: string, options?: RequestOptions): Promise<ApiResponse<{
id: string;
customerId: string;
attached: boolean;
}>>;
detachPaymentMethod(paymentMethodId: string, options?: RequestOptions): Promise<ApiResponse<{
id: string;
detached: boolean;
}>>;
}
declare class VlyIntegrations {
ai: VlyAI;
email: VlyEmail;
payments: VlyPayments;
constructor(config: VlyConfig);
}
declare function createVlyIntegrations(config: VlyConfig): VlyIntegrations;
export { type AICompletionRequest, type AICompletionResponse, type AIModel, type ApiResponse, type CustomerPortalResponse, type CustomerPortalSession, type EmailRequest, type EmailResponse, type PaymentIntent, type PaymentIntentResponse, type RequestOptions, type Subscription, type SubscriptionResponse, VlyAI, type VlyConfig, VlyEmail, VlyIntegrations, VlyPayments, createVlyIntegrations };