quantum-ai-sdk 0.2.0 → 0.2.1
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/dist/account.d.ts +22 -0
- package/dist/account.js +47 -0
- package/dist/agent.d.ts +12 -0
- package/dist/agent.js +114 -0
- package/dist/audio.d.ts +82 -0
- package/dist/audio.js +140 -0
- package/dist/auth.d.ts +7 -0
- package/dist/auth.js +8 -0
- package/dist/batch.d.ts +22 -0
- package/dist/batch.js +32 -0
- package/dist/chat.d.ts +27 -0
- package/dist/chat.js +122 -0
- package/dist/client.d.ts +251 -0
- package/dist/client.js +479 -0
- package/dist/compute.d.ts +37 -0
- package/dist/compute.js +56 -0
- package/dist/contact.d.ts +12 -0
- package/dist/contact.js +26 -0
- package/dist/credits.d.ts +27 -0
- package/dist/credits.js +40 -0
- package/dist/documents.d.ts +17 -0
- package/dist/documents.js +42 -0
- package/dist/embeddings.d.ts +7 -0
- package/dist/embeddings.js +14 -0
- package/dist/errors.d.ts +29 -0
- package/dist/errors.js +70 -0
- package/dist/image.d.ts +12 -0
- package/dist/image.js +28 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.js +33 -0
- package/dist/jobs.d.ts +28 -0
- package/dist/jobs.js +56 -0
- package/dist/keys.d.ts +17 -0
- package/dist/keys.js +24 -0
- package/dist/models.d.ts +12 -0
- package/dist/models.js +16 -0
- package/dist/rag.d.ts +22 -0
- package/dist/rag.js +44 -0
- package/dist/realtime.d.ts +121 -0
- package/dist/realtime.js +259 -0
- package/dist/session.d.ts +7 -0
- package/dist/session.js +17 -0
- package/dist/types.d.ts +1008 -0
- package/dist/types.js +5 -0
- package/dist/video.d.ts +46 -0
- package/dist/video.js +74 -0
- package/dist/voices.d.ts +27 -0
- package/dist/voices.js +55 -0
- package/package.json +3 -3
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { QuantumClient } from "./client.js";
|
|
2
|
+
import type { ChunkDocumentRequest, ChunkDocumentResponse, DocumentRequest, DocumentResponse, ProcessDocumentRequest, ProcessDocumentResponse } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Extract text content from a document (PDF, image, etc.).
|
|
5
|
+
* @internal — called by QuantumClient.extractDocument()
|
|
6
|
+
*/
|
|
7
|
+
export declare function extractDocument(client: QuantumClient, req: DocumentRequest): Promise<DocumentResponse>;
|
|
8
|
+
/**
|
|
9
|
+
* Chunk a document into smaller pieces for embedding or processing.
|
|
10
|
+
* @internal — called by QuantumClient.chunkDocument()
|
|
11
|
+
*/
|
|
12
|
+
export declare function chunkDocument(client: QuantumClient, req: ChunkDocumentRequest): Promise<ChunkDocumentResponse>;
|
|
13
|
+
/**
|
|
14
|
+
* Process a document with extraction + optional instructions.
|
|
15
|
+
* @internal — called by QuantumClient.processDocument()
|
|
16
|
+
*/
|
|
17
|
+
export declare function processDocument(client: QuantumClient, req: ProcessDocumentRequest): Promise<ProcessDocumentResponse>;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extract text content from a document (PDF, image, etc.).
|
|
3
|
+
* @internal — called by QuantumClient.extractDocument()
|
|
4
|
+
*/
|
|
5
|
+
export async function extractDocument(client, req) {
|
|
6
|
+
const { data, meta } = await client._doJSON("POST", "/qai/v1/documents/extract", req);
|
|
7
|
+
if (!data.cost_ticks) {
|
|
8
|
+
data.cost_ticks = meta.costTicks;
|
|
9
|
+
}
|
|
10
|
+
if (!data.request_id) {
|
|
11
|
+
data.request_id = meta.requestId;
|
|
12
|
+
}
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Chunk a document into smaller pieces for embedding or processing.
|
|
17
|
+
* @internal — called by QuantumClient.chunkDocument()
|
|
18
|
+
*/
|
|
19
|
+
export async function chunkDocument(client, req) {
|
|
20
|
+
const { data, meta } = await client._doJSON("POST", "/qai/v1/documents/chunk", req);
|
|
21
|
+
if (!data.cost_ticks) {
|
|
22
|
+
data.cost_ticks = meta.costTicks;
|
|
23
|
+
}
|
|
24
|
+
if (!data.request_id) {
|
|
25
|
+
data.request_id = meta.requestId;
|
|
26
|
+
}
|
|
27
|
+
return data;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Process a document with extraction + optional instructions.
|
|
31
|
+
* @internal — called by QuantumClient.processDocument()
|
|
32
|
+
*/
|
|
33
|
+
export async function processDocument(client, req) {
|
|
34
|
+
const { data, meta } = await client._doJSON("POST", "/qai/v1/documents/process", req);
|
|
35
|
+
if (!data.cost_ticks) {
|
|
36
|
+
data.cost_ticks = meta.costTicks;
|
|
37
|
+
}
|
|
38
|
+
if (!data.request_id) {
|
|
39
|
+
data.request_id = meta.requestId;
|
|
40
|
+
}
|
|
41
|
+
return data;
|
|
42
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { QuantumClient } from "./client.js";
|
|
2
|
+
import type { EmbedRequest, EmbedResponse } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Generate text embeddings for the given inputs.
|
|
5
|
+
* @internal — called by QuantumClient.embed()
|
|
6
|
+
*/
|
|
7
|
+
export declare function embed(client: QuantumClient, req: EmbedRequest): Promise<EmbedResponse>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate text embeddings for the given inputs.
|
|
3
|
+
* @internal — called by QuantumClient.embed()
|
|
4
|
+
*/
|
|
5
|
+
export async function embed(client, req) {
|
|
6
|
+
const { data, meta } = await client._doJSON("POST", "/qai/v1/embeddings", req);
|
|
7
|
+
if (!data.cost_ticks) {
|
|
8
|
+
data.cost_ticks = meta.costTicks;
|
|
9
|
+
}
|
|
10
|
+
if (!data.request_id) {
|
|
11
|
+
data.request_id = meta.requestId;
|
|
12
|
+
}
|
|
13
|
+
return data;
|
|
14
|
+
}
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* APIError is thrown when the API responds with a non-2xx status code.
|
|
3
|
+
*/
|
|
4
|
+
export declare class APIError extends Error {
|
|
5
|
+
/** HTTP status code from the response. */
|
|
6
|
+
readonly statusCode: number;
|
|
7
|
+
/** Error type from the API (e.g. "invalid_request", "rate_limit"). */
|
|
8
|
+
readonly code: string;
|
|
9
|
+
/** Unique request identifier from the X-QAI-Request-Id header. */
|
|
10
|
+
readonly requestId: string | undefined;
|
|
11
|
+
constructor(statusCode: number, code: string, message: string, requestId?: string);
|
|
12
|
+
/** True if the error is a 429 rate limit response. */
|
|
13
|
+
isRateLimit(): boolean;
|
|
14
|
+
/** True if the error is a 401 or 403 authentication/authorization failure. */
|
|
15
|
+
isAuth(): boolean;
|
|
16
|
+
/** True if the error is a 404 not found response. */
|
|
17
|
+
isNotFound(): boolean;
|
|
18
|
+
}
|
|
19
|
+
/** Check whether an error is a rate limit APIError. */
|
|
20
|
+
export declare function isRateLimitError(err: unknown): err is APIError;
|
|
21
|
+
/** Check whether an error is an authentication APIError. */
|
|
22
|
+
export declare function isAuthError(err: unknown): err is APIError;
|
|
23
|
+
/** Check whether an error is a not found APIError. */
|
|
24
|
+
export declare function isNotFoundError(err: unknown): err is APIError;
|
|
25
|
+
/**
|
|
26
|
+
* Parse an API error response into an APIError.
|
|
27
|
+
* @internal
|
|
28
|
+
*/
|
|
29
|
+
export declare function parseAPIError(response: Response, requestId: string): Promise<APIError>;
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* APIError is thrown when the API responds with a non-2xx status code.
|
|
3
|
+
*/
|
|
4
|
+
export class APIError extends Error {
|
|
5
|
+
/** HTTP status code from the response. */
|
|
6
|
+
statusCode;
|
|
7
|
+
/** Error type from the API (e.g. "invalid_request", "rate_limit"). */
|
|
8
|
+
code;
|
|
9
|
+
/** Unique request identifier from the X-QAI-Request-Id header. */
|
|
10
|
+
requestId;
|
|
11
|
+
constructor(statusCode, code, message, requestId) {
|
|
12
|
+
const msg = requestId
|
|
13
|
+
? `qai: ${statusCode} ${code}: ${message} (request_id=${requestId})`
|
|
14
|
+
: `qai: ${statusCode} ${code}: ${message}`;
|
|
15
|
+
super(msg);
|
|
16
|
+
this.name = "APIError";
|
|
17
|
+
this.statusCode = statusCode;
|
|
18
|
+
this.code = code;
|
|
19
|
+
this.requestId = requestId;
|
|
20
|
+
}
|
|
21
|
+
/** True if the error is a 429 rate limit response. */
|
|
22
|
+
isRateLimit() {
|
|
23
|
+
return this.statusCode === 429;
|
|
24
|
+
}
|
|
25
|
+
/** True if the error is a 401 or 403 authentication/authorization failure. */
|
|
26
|
+
isAuth() {
|
|
27
|
+
return this.statusCode === 401 || this.statusCode === 403;
|
|
28
|
+
}
|
|
29
|
+
/** True if the error is a 404 not found response. */
|
|
30
|
+
isNotFound() {
|
|
31
|
+
return this.statusCode === 404;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
/** Check whether an error is a rate limit APIError. */
|
|
35
|
+
export function isRateLimitError(err) {
|
|
36
|
+
return err instanceof APIError && err.isRateLimit();
|
|
37
|
+
}
|
|
38
|
+
/** Check whether an error is an authentication APIError. */
|
|
39
|
+
export function isAuthError(err) {
|
|
40
|
+
return err instanceof APIError && err.isAuth();
|
|
41
|
+
}
|
|
42
|
+
/** Check whether an error is a not found APIError. */
|
|
43
|
+
export function isNotFoundError(err) {
|
|
44
|
+
return err instanceof APIError && err.isNotFound();
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Parse an API error response into an APIError.
|
|
48
|
+
* @internal
|
|
49
|
+
*/
|
|
50
|
+
export async function parseAPIError(response, requestId) {
|
|
51
|
+
const bodyText = await response.text();
|
|
52
|
+
let code = response.statusText || "Unknown";
|
|
53
|
+
let message = bodyText;
|
|
54
|
+
try {
|
|
55
|
+
const parsed = JSON.parse(bodyText);
|
|
56
|
+
if (parsed.error?.message) {
|
|
57
|
+
message = parsed.error.message;
|
|
58
|
+
if (parsed.error.code) {
|
|
59
|
+
code = parsed.error.code;
|
|
60
|
+
}
|
|
61
|
+
else if (parsed.error.type) {
|
|
62
|
+
code = parsed.error.type;
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
// Body is not JSON — use raw text as message.
|
|
68
|
+
}
|
|
69
|
+
return new APIError(response.status, code, message, requestId || undefined);
|
|
70
|
+
}
|
package/dist/image.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { QuantumClient } from "./client.js";
|
|
2
|
+
import type { ImageEditRequest, ImageEditResponse, ImageRequest, ImageResponse } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Generate images from a text prompt.
|
|
5
|
+
* @internal — called by QuantumClient.generateImage()
|
|
6
|
+
*/
|
|
7
|
+
export declare function generateImage(client: QuantumClient, req: ImageRequest): Promise<ImageResponse>;
|
|
8
|
+
/**
|
|
9
|
+
* Edit images using an AI model.
|
|
10
|
+
* @internal — called by QuantumClient.editImage()
|
|
11
|
+
*/
|
|
12
|
+
export declare function editImage(client: QuantumClient, req: ImageEditRequest): Promise<ImageEditResponse>;
|
package/dist/image.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generate images from a text prompt.
|
|
3
|
+
* @internal — called by QuantumClient.generateImage()
|
|
4
|
+
*/
|
|
5
|
+
export async function generateImage(client, req) {
|
|
6
|
+
const { data, meta } = await client._doJSON("POST", "/qai/v1/images/generate", req);
|
|
7
|
+
if (!data.cost_ticks) {
|
|
8
|
+
data.cost_ticks = meta.costTicks;
|
|
9
|
+
}
|
|
10
|
+
if (!data.request_id) {
|
|
11
|
+
data.request_id = meta.requestId;
|
|
12
|
+
}
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Edit images using an AI model.
|
|
17
|
+
* @internal — called by QuantumClient.editImage()
|
|
18
|
+
*/
|
|
19
|
+
export async function editImage(client, req) {
|
|
20
|
+
const { data, meta } = await client._doJSON("POST", "/qai/v1/images/edit", req);
|
|
21
|
+
if (!data.cost_ticks) {
|
|
22
|
+
data.cost_ticks = meta.costTicks;
|
|
23
|
+
}
|
|
24
|
+
if (!data.request_id) {
|
|
25
|
+
data.request_id = meta.requestId;
|
|
26
|
+
}
|
|
27
|
+
return data;
|
|
28
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { QuantumClient } from "./client.js";
|
|
2
|
+
export { APIError, isRateLimitError, isAuthError, isNotFoundError, } from "./errors.js";
|
|
3
|
+
export { responseText, responseThinking, responseToolCalls } from "./chat.js";
|
|
4
|
+
export { realtimeConnect, realtimeConnectDirect, realtimeSession, realtimeEnd, realtimeRefresh, RealtimeSender, RealtimeReceiver } from "./realtime.js";
|
|
5
|
+
export type { RealtimeConfig, RealtimeEvent, RealtimeSession } from "./realtime.js";
|
|
6
|
+
export { contact } from "./contact.js";
|
|
7
|
+
export type { ClientOptions, ResponseMeta, ChatRequest, ChatMessage, ChatTool, ContentBlock, ChatUsage, ChatResponse, StreamEvent, StreamDelta, StreamToolUse, SessionChatRequest, SessionChatResponse, SessionToolResult, ContextConfig, ContextMetadata, AgentRequest, AgentWorkerConfig, AgentEvent, MissionRequest, MissionWorkerConfig, MissionEvent, ImageRequest, ImageResponse, GeneratedImage, ImageEditRequest, ImageEditResponse, TTSRequest, TTSResponse, STTRequest, STTResponse, MusicRequest, MusicClip, MusicResponse, SoundEffectRequest, SoundEffectResponse, DialogueRequest, DialogueResponse, DialogueVoice, SpeechToSpeechRequest, SpeechToSpeechResponse, IsolateVoiceRequest, IsolateVoiceResponse, RemixVoiceRequest, RemixVoiceResponse, DubRequest, DubResponse, AlignRequest, AlignResponse, AlignedWord, VoiceDesignRequest, VoiceDesignResponse, VoicePreview, StarfishTTSRequest, StarfishTTSResponse, VideoRequest, VideoResponse, GeneratedVideo, VideoStudioRequest, VideoTranslateRequest, PhotoAvatarRequest, DigitalTwinRequest, AsyncJobResponse, AvatarsResponse, HeyGenAvatar, HeyGenTemplatesResponse, HeyGenTemplate, HeyGenVoicesResponse, HeyGenVoice, EmbedRequest, EmbedResponse, DocumentRequest, DocumentResponse, ChunkDocumentRequest, ChunkDocumentResponse, DocumentChunk, ProcessDocumentRequest, ProcessDocumentResponse, RAGSearchRequest, RAGSearchResponse, RAGResult, RAGCorpus, SurrealRAGSearchRequest, SurrealRAGSearchResponse, SurrealRAGResult, SurrealRAGProvidersResponse, SurrealRAGProviderInfo, ModelInfo, PricingInfo, BalanceResponse, UsageEntry, UsageResponse, UsageQuery, UsageSummaryMonth, UsageSummaryResponse, PricingEntry, AccountPricingResponse, JobCreateRequest, JobCreateResponse, JobStatusResponse, JobListResponse, JobListItem, CreateKeyRequest, CreateKeyResponse, KeyDetails, ListKeysResponse, ComputeTemplate, TemplatesResponse, ProvisionRequest, ProvisionResponse, ComputeInstanceInfo, InstancesResponse, InstanceDetailInfo, InstanceResponse, SSHKeyRequest, DeleteResponse, VoiceInfo, VoicesResponse, CloneVoiceRequest, CloneVoiceResponse, ContactRequest, BatchJobInput, BatchSubmitRequest, BatchSubmitResponse, BatchJsonlResponse, BatchJobInfo, BatchJobsResponse, CreditPack, CreditPacksResponse, CreditPurchaseRequest, CreditPurchaseResponse, CreditBalanceResponse, CreditTier, CreditTiersResponse, DevProgramApplyRequest, DevProgramApplyResponse, AuthUser, AuthResponse, AuthAppleRequest, StatusResponse, } from "./types.js";
|
|
8
|
+
export { DEFAULT_BASE_URL, TICKS_PER_USD } from "./types.js";
|
|
9
|
+
import type { ChatMessage } from "./types.js";
|
|
10
|
+
/** Create a user message. */
|
|
11
|
+
export declare function userMessage(content: string): ChatMessage;
|
|
12
|
+
/** Create an assistant message. */
|
|
13
|
+
export declare function assistantMessage(content: string): ChatMessage;
|
|
14
|
+
/** Create a system message. */
|
|
15
|
+
export declare function systemMessage(content: string): ChatMessage;
|
|
16
|
+
/** Create a tool result message. */
|
|
17
|
+
export declare function toolMessage(toolCallId: string, content: string, isError?: boolean): ChatMessage;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
// ── Client ──────────────────────────────────────────────────────────
|
|
2
|
+
export { QuantumClient } from "./client.js";
|
|
3
|
+
// ── Errors ──────────────────────────────────────────────────────────
|
|
4
|
+
export { APIError, isRateLimitError, isAuthError, isNotFoundError, } from "./errors.js";
|
|
5
|
+
// ── Chat helpers ────────────────────────────────────────────────────
|
|
6
|
+
export { responseText, responseThinking, responseToolCalls } from "./chat.js";
|
|
7
|
+
// ── Realtime Voice ──────────────────────────────────────────────────
|
|
8
|
+
export { realtimeConnect, realtimeConnectDirect, realtimeSession, realtimeEnd, realtimeRefresh, RealtimeSender, RealtimeReceiver } from "./realtime.js";
|
|
9
|
+
// ── Contact (standalone, no auth required) ──────────────────────────
|
|
10
|
+
export { contact } from "./contact.js";
|
|
11
|
+
// ── Constants ───────────────────────────────────────────────────────
|
|
12
|
+
export { DEFAULT_BASE_URL, TICKS_PER_USD } from "./types.js";
|
|
13
|
+
/** Create a user message. */
|
|
14
|
+
export function userMessage(content) {
|
|
15
|
+
return { role: "user", content };
|
|
16
|
+
}
|
|
17
|
+
/** Create an assistant message. */
|
|
18
|
+
export function assistantMessage(content) {
|
|
19
|
+
return { role: "assistant", content };
|
|
20
|
+
}
|
|
21
|
+
/** Create a system message. */
|
|
22
|
+
export function systemMessage(content) {
|
|
23
|
+
return { role: "system", content };
|
|
24
|
+
}
|
|
25
|
+
/** Create a tool result message. */
|
|
26
|
+
export function toolMessage(toolCallId, content, isError) {
|
|
27
|
+
return {
|
|
28
|
+
role: "tool",
|
|
29
|
+
tool_call_id: toolCallId,
|
|
30
|
+
content,
|
|
31
|
+
is_error: isError,
|
|
32
|
+
};
|
|
33
|
+
}
|
package/dist/jobs.d.ts
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { QuantumClient } from "./client.js";
|
|
2
|
+
import type { JobCreateRequest, JobCreateResponse, JobListResponse, JobStatusResponse } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Create an async job. Returns the job ID for polling.
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
export declare function createJob(client: QuantumClient, req: JobCreateRequest): Promise<JobCreateResponse>;
|
|
8
|
+
/**
|
|
9
|
+
* Check the status of an async job.
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export declare function getJob(client: QuantumClient, jobId: string): Promise<JobStatusResponse>;
|
|
13
|
+
/**
|
|
14
|
+
* Poll a job until completion or timeout.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export declare function pollJob(client: QuantumClient, jobId: string, intervalMs?: number, maxAttempts?: number): Promise<JobStatusResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* List all jobs for the authenticated user.
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
export declare function listJobs(client: QuantumClient): Promise<JobListResponse>;
|
|
23
|
+
/**
|
|
24
|
+
* Convenience method for 3D model generation via the async jobs system.
|
|
25
|
+
* Submits a job with type "3d/generate" and the given parameters.
|
|
26
|
+
* @internal
|
|
27
|
+
*/
|
|
28
|
+
export declare function generate3D(client: QuantumClient, model: string, prompt?: string, imageUrl?: string): Promise<JobCreateResponse>;
|
package/dist/jobs.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create an async job. Returns the job ID for polling.
|
|
3
|
+
* @internal
|
|
4
|
+
*/
|
|
5
|
+
export async function createJob(client, req) {
|
|
6
|
+
const { data } = await client._doJSON("POST", "/qai/v1/jobs", req);
|
|
7
|
+
return data;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Check the status of an async job.
|
|
11
|
+
* @internal
|
|
12
|
+
*/
|
|
13
|
+
export async function getJob(client, jobId) {
|
|
14
|
+
const { data } = await client._doJSON("GET", `/qai/v1/jobs/${jobId}`, undefined);
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Poll a job until completion or timeout.
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
export async function pollJob(client, jobId, intervalMs = 2000, maxAttempts = 150) {
|
|
22
|
+
for (let i = 0; i < maxAttempts; i++) {
|
|
23
|
+
await new Promise((resolve) => setTimeout(resolve, intervalMs));
|
|
24
|
+
const status = await getJob(client, jobId);
|
|
25
|
+
if (status.status === "completed" || status.status === "failed") {
|
|
26
|
+
return status;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
job_id: jobId,
|
|
31
|
+
status: "timeout",
|
|
32
|
+
error: `Job polling timed out after ${maxAttempts} attempts`,
|
|
33
|
+
cost_ticks: 0,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* List all jobs for the authenticated user.
|
|
38
|
+
* @internal
|
|
39
|
+
*/
|
|
40
|
+
export async function listJobs(client) {
|
|
41
|
+
const { data } = await client._doJSON("GET", "/qai/v1/jobs", undefined);
|
|
42
|
+
return data;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Convenience method for 3D model generation via the async jobs system.
|
|
46
|
+
* Submits a job with type "3d/generate" and the given parameters.
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
export async function generate3D(client, model, prompt, imageUrl) {
|
|
50
|
+
const params = { model };
|
|
51
|
+
if (prompt)
|
|
52
|
+
params.prompt = prompt;
|
|
53
|
+
if (imageUrl)
|
|
54
|
+
params.image_url = imageUrl;
|
|
55
|
+
return createJob(client, { type: "3d/generate", params });
|
|
56
|
+
}
|
package/dist/keys.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { QuantumClient } from "./client.js";
|
|
2
|
+
import type { CreateKeyRequest, CreateKeyResponse, ListKeysResponse, StatusResponse } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Create a scoped API key.
|
|
5
|
+
* @internal — called by QuantumClient.createKey()
|
|
6
|
+
*/
|
|
7
|
+
export declare function createKey(client: QuantumClient, req: CreateKeyRequest): Promise<CreateKeyResponse>;
|
|
8
|
+
/**
|
|
9
|
+
* List all API keys for the authenticated user.
|
|
10
|
+
* @internal — called by QuantumClient.listKeys()
|
|
11
|
+
*/
|
|
12
|
+
export declare function listKeys(client: QuantumClient): Promise<ListKeysResponse>;
|
|
13
|
+
/**
|
|
14
|
+
* Revoke an API key.
|
|
15
|
+
* @internal — called by QuantumClient.revokeKey()
|
|
16
|
+
*/
|
|
17
|
+
export declare function revokeKey(client: QuantumClient, id: string): Promise<StatusResponse>;
|
package/dist/keys.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a scoped API key.
|
|
3
|
+
* @internal — called by QuantumClient.createKey()
|
|
4
|
+
*/
|
|
5
|
+
export async function createKey(client, req) {
|
|
6
|
+
const { data } = await client._doJSON("POST", "/qai/v1/keys", req);
|
|
7
|
+
return data;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* List all API keys for the authenticated user.
|
|
11
|
+
* @internal — called by QuantumClient.listKeys()
|
|
12
|
+
*/
|
|
13
|
+
export async function listKeys(client) {
|
|
14
|
+
const { data } = await client._doJSON("GET", "/qai/v1/keys", undefined);
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Revoke an API key.
|
|
19
|
+
* @internal — called by QuantumClient.revokeKey()
|
|
20
|
+
*/
|
|
21
|
+
export async function revokeKey(client, id) {
|
|
22
|
+
const { data } = await client._doJSON("DELETE", `/qai/v1/keys/${id}`, undefined);
|
|
23
|
+
return data;
|
|
24
|
+
}
|
package/dist/models.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { QuantumClient } from "./client.js";
|
|
2
|
+
import type { ModelInfo, PricingInfo } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* List all available models with provider and pricing information.
|
|
5
|
+
* @internal — called by QuantumClient.listModels()
|
|
6
|
+
*/
|
|
7
|
+
export declare function listModels(client: QuantumClient): Promise<ModelInfo[]>;
|
|
8
|
+
/**
|
|
9
|
+
* Get the complete pricing table for all models.
|
|
10
|
+
* @internal — called by QuantumClient.getPricing()
|
|
11
|
+
*/
|
|
12
|
+
export declare function getPricing(client: QuantumClient): Promise<PricingInfo[]>;
|
package/dist/models.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List all available models with provider and pricing information.
|
|
3
|
+
* @internal — called by QuantumClient.listModels()
|
|
4
|
+
*/
|
|
5
|
+
export async function listModels(client) {
|
|
6
|
+
const { data } = await client._doJSON("GET", "/qai/v1/models", undefined);
|
|
7
|
+
return data.models;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Get the complete pricing table for all models.
|
|
11
|
+
* @internal — called by QuantumClient.getPricing()
|
|
12
|
+
*/
|
|
13
|
+
export async function getPricing(client) {
|
|
14
|
+
const { data } = await client._doJSON("GET", "/qai/v1/pricing", undefined);
|
|
15
|
+
return data.pricing;
|
|
16
|
+
}
|
package/dist/rag.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { QuantumClient } from "./client.js";
|
|
2
|
+
import type { RAGCorpus, RAGSearchRequest, RAGSearchResponse, SurrealRAGProvidersResponse, SurrealRAGSearchRequest, SurrealRAGSearchResponse } from "./types.js";
|
|
3
|
+
/**
|
|
4
|
+
* Search Vertex AI RAG corpora for relevant documentation.
|
|
5
|
+
* @internal — called by QuantumClient.ragSearch()
|
|
6
|
+
*/
|
|
7
|
+
export declare function ragSearch(client: QuantumClient, req: RAGSearchRequest): Promise<RAGSearchResponse>;
|
|
8
|
+
/**
|
|
9
|
+
* List available Vertex AI RAG corpora.
|
|
10
|
+
* @internal — called by QuantumClient.ragCorpora()
|
|
11
|
+
*/
|
|
12
|
+
export declare function ragCorpora(client: QuantumClient): Promise<RAGCorpus[]>;
|
|
13
|
+
/**
|
|
14
|
+
* Search provider API documentation via SurrealDB vector search.
|
|
15
|
+
* @internal — called by QuantumClient.surrealRagSearch()
|
|
16
|
+
*/
|
|
17
|
+
export declare function surrealRagSearch(client: QuantumClient, req: SurrealRAGSearchRequest): Promise<SurrealRAGSearchResponse>;
|
|
18
|
+
/**
|
|
19
|
+
* List available documentation providers in SurrealDB RAG.
|
|
20
|
+
* @internal — called by QuantumClient.surrealRagProviders()
|
|
21
|
+
*/
|
|
22
|
+
export declare function surrealRagProviders(client: QuantumClient): Promise<SurrealRAGProvidersResponse>;
|
package/dist/rag.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Search Vertex AI RAG corpora for relevant documentation.
|
|
3
|
+
* @internal — called by QuantumClient.ragSearch()
|
|
4
|
+
*/
|
|
5
|
+
export async function ragSearch(client, req) {
|
|
6
|
+
const { data, meta } = await client._doJSON("POST", "/qai/v1/rag/search", req);
|
|
7
|
+
if (!data.cost_ticks) {
|
|
8
|
+
data.cost_ticks = meta.costTicks;
|
|
9
|
+
}
|
|
10
|
+
if (!data.request_id) {
|
|
11
|
+
data.request_id = meta.requestId;
|
|
12
|
+
}
|
|
13
|
+
return data;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* List available Vertex AI RAG corpora.
|
|
17
|
+
* @internal — called by QuantumClient.ragCorpora()
|
|
18
|
+
*/
|
|
19
|
+
export async function ragCorpora(client) {
|
|
20
|
+
const { data } = await client._doJSON("GET", "/qai/v1/rag/corpora", undefined);
|
|
21
|
+
return data.corpora;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Search provider API documentation via SurrealDB vector search.
|
|
25
|
+
* @internal — called by QuantumClient.surrealRagSearch()
|
|
26
|
+
*/
|
|
27
|
+
export async function surrealRagSearch(client, req) {
|
|
28
|
+
const { data, meta } = await client._doJSON("POST", "/qai/v1/rag/surreal/search", req);
|
|
29
|
+
if (!data.cost_ticks) {
|
|
30
|
+
data.cost_ticks = meta.costTicks;
|
|
31
|
+
}
|
|
32
|
+
if (!data.request_id) {
|
|
33
|
+
data.request_id = meta.requestId;
|
|
34
|
+
}
|
|
35
|
+
return data;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* List available documentation providers in SurrealDB RAG.
|
|
39
|
+
* @internal — called by QuantumClient.surrealRagProviders()
|
|
40
|
+
*/
|
|
41
|
+
export async function surrealRagProviders(client) {
|
|
42
|
+
const { data } = await client._doJSON("GET", "/qai/v1/rag/surreal/providers", undefined);
|
|
43
|
+
return data;
|
|
44
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Realtime voice sessions via WebSocket.
|
|
3
|
+
*
|
|
4
|
+
* Connects to the QAI Realtime API for bidirectional audio streaming
|
|
5
|
+
* with voice activity detection, transcription, and tool calling.
|
|
6
|
+
*/
|
|
7
|
+
import type { QuantumClient } from "./client.js";
|
|
8
|
+
/** Configuration for a realtime voice session. */
|
|
9
|
+
export interface RealtimeConfig {
|
|
10
|
+
/** Voice to use (e.g. "Sal", "Eve", "Vesper"). Default: "Sal". */
|
|
11
|
+
voice?: string;
|
|
12
|
+
/** System instructions for the AI. */
|
|
13
|
+
instructions?: string;
|
|
14
|
+
/** PCM sample rate in Hz. Default: 24000. */
|
|
15
|
+
sampleRate?: number;
|
|
16
|
+
/** Tool definitions (xAI Realtime API format). */
|
|
17
|
+
tools?: Record<string, unknown>[];
|
|
18
|
+
}
|
|
19
|
+
/** Parsed incoming event from the realtime API. */
|
|
20
|
+
export type RealtimeEvent = {
|
|
21
|
+
type: "session_ready";
|
|
22
|
+
} | {
|
|
23
|
+
type: "audio_delta";
|
|
24
|
+
delta: string;
|
|
25
|
+
} | {
|
|
26
|
+
type: "transcript_delta";
|
|
27
|
+
delta: string;
|
|
28
|
+
source: "input" | "output";
|
|
29
|
+
} | {
|
|
30
|
+
type: "transcript_done";
|
|
31
|
+
transcript: string;
|
|
32
|
+
source: "input" | "output";
|
|
33
|
+
} | {
|
|
34
|
+
type: "speech_started";
|
|
35
|
+
} | {
|
|
36
|
+
type: "speech_stopped";
|
|
37
|
+
} | {
|
|
38
|
+
type: "function_call";
|
|
39
|
+
name: string;
|
|
40
|
+
callId: string;
|
|
41
|
+
arguments: string;
|
|
42
|
+
} | {
|
|
43
|
+
type: "response_done";
|
|
44
|
+
} | {
|
|
45
|
+
type: "error";
|
|
46
|
+
message: string;
|
|
47
|
+
} | {
|
|
48
|
+
type: "unknown";
|
|
49
|
+
raw: unknown;
|
|
50
|
+
};
|
|
51
|
+
/** Write half of a realtime session. */
|
|
52
|
+
export declare class RealtimeSender {
|
|
53
|
+
private ws;
|
|
54
|
+
/** @internal */
|
|
55
|
+
constructor(ws: WebSocket);
|
|
56
|
+
/** Send a base64-encoded PCM audio chunk. */
|
|
57
|
+
sendAudio(base64Pcm: string): void;
|
|
58
|
+
/** Send a text message and request a response. */
|
|
59
|
+
sendText(text: string): void;
|
|
60
|
+
/** Send a function/tool call result back to the model. */
|
|
61
|
+
sendFunctionResult(callId: string, output: string): void;
|
|
62
|
+
/** Cancel the current response (interrupt). */
|
|
63
|
+
cancelResponse(): void;
|
|
64
|
+
/** Close the session gracefully. */
|
|
65
|
+
close(): void;
|
|
66
|
+
}
|
|
67
|
+
/** Read half of a realtime session. */
|
|
68
|
+
export declare class RealtimeReceiver {
|
|
69
|
+
private queue;
|
|
70
|
+
private resolve;
|
|
71
|
+
private closed;
|
|
72
|
+
/** @internal */
|
|
73
|
+
constructor(ws: WebSocket);
|
|
74
|
+
/** Receive the next event. Returns null when the connection closes. */
|
|
75
|
+
recv(): Promise<RealtimeEvent | null>;
|
|
76
|
+
/** Async iterator support. */
|
|
77
|
+
[Symbol.asyncIterator](): AsyncIterableIterator<RealtimeEvent>;
|
|
78
|
+
}
|
|
79
|
+
/** Response from POST /qai/v1/realtime/session. */
|
|
80
|
+
export interface RealtimeSession {
|
|
81
|
+
/** Ephemeral token for direct WebSocket connection (xAI/OpenAI). */
|
|
82
|
+
ephemeral_token: string;
|
|
83
|
+
/** WebSocket URL to connect to. */
|
|
84
|
+
url: string;
|
|
85
|
+
/** Signed WebSocket URL (ElevenLabs returns this field). */
|
|
86
|
+
signed_url?: string;
|
|
87
|
+
/** Session ID for billing (pass to realtimeEnd on disconnect). */
|
|
88
|
+
session_id: string;
|
|
89
|
+
/** Provider name (e.g. "xai", "elevenlabs"). */
|
|
90
|
+
provider?: string;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Request an ephemeral token from the QAI proxy for direct voice connection.
|
|
94
|
+
* Call this before `realtimeConnectDirect` to get a scoped token.
|
|
95
|
+
*
|
|
96
|
+
* @param provider - Optional provider ("xai" default, "elevenlabs"). When
|
|
97
|
+
* provider is "elevenlabs", the response contains a WebSocket proxy URL
|
|
98
|
+
* (signed_url) instead of an ephemeral token.
|
|
99
|
+
*/
|
|
100
|
+
export declare function realtimeSession(client: QuantumClient, provider?: string): Promise<RealtimeSession>;
|
|
101
|
+
/**
|
|
102
|
+
* End a realtime session and finalize billing.
|
|
103
|
+
* Call after disconnecting from the direct xAI WebSocket.
|
|
104
|
+
*/
|
|
105
|
+
export declare function realtimeEnd(client: QuantumClient, sessionId: string, durationSeconds: number): Promise<void>;
|
|
106
|
+
/**
|
|
107
|
+
* Refresh an ephemeral token for long sessions (>4 min).
|
|
108
|
+
* Returns a new ephemeral token string.
|
|
109
|
+
*/
|
|
110
|
+
export declare function realtimeRefresh(client: QuantumClient, sessionId: string): Promise<string>;
|
|
111
|
+
/**
|
|
112
|
+
* Connect directly to xAI's realtime API with an ephemeral token.
|
|
113
|
+
* Much lower latency than the proxy path -- no extra hop.
|
|
114
|
+
* Use `realtimeSession()` first to get the token.
|
|
115
|
+
*/
|
|
116
|
+
export declare function realtimeConnectDirect(ephemeralToken: string, config?: RealtimeConfig, wsUrl?: string): Promise<[RealtimeSender, RealtimeReceiver]>;
|
|
117
|
+
/**
|
|
118
|
+
* Open a realtime voice session via the QAI proxy.
|
|
119
|
+
* Returns [sender, receiver] for bidirectional communication.
|
|
120
|
+
*/
|
|
121
|
+
export declare function realtimeConnect(client: QuantumClient, config?: RealtimeConfig): Promise<[RealtimeSender, RealtimeReceiver]>;
|