quantum-ai-sdk 0.2.0 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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 +264 -0
- package/dist/client.js +498 -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 +46 -0
- package/dist/jobs.js +128 -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 +1018 -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
package/dist/credits.js
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* List available credit packs. No authentication required.
|
|
3
|
+
* @internal — called by QuantumClient.creditPacks()
|
|
4
|
+
*/
|
|
5
|
+
export async function creditPacks(client) {
|
|
6
|
+
const { data } = await client._doJSON("GET", "/qai/v1/credits/packs", undefined);
|
|
7
|
+
return data;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Purchase a credit pack. Returns a checkout URL for payment.
|
|
11
|
+
* @internal — called by QuantumClient.creditPurchase()
|
|
12
|
+
*/
|
|
13
|
+
export async function creditPurchase(client, req) {
|
|
14
|
+
const { data } = await client._doJSON("POST", "/qai/v1/credits/purchase", req);
|
|
15
|
+
return data;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get the current credit balance.
|
|
19
|
+
* @internal — called by QuantumClient.creditBalance()
|
|
20
|
+
*/
|
|
21
|
+
export async function creditBalance(client) {
|
|
22
|
+
const { data } = await client._doJSON("GET", "/qai/v1/credits/balance", undefined);
|
|
23
|
+
return data;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* List available credit tiers. No authentication required.
|
|
27
|
+
* @internal — called by QuantumClient.creditTiers()
|
|
28
|
+
*/
|
|
29
|
+
export async function creditTiers(client) {
|
|
30
|
+
const { data } = await client._doJSON("GET", "/qai/v1/credits/tiers", undefined);
|
|
31
|
+
return data;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Apply for the developer program.
|
|
35
|
+
* @internal — called by QuantumClient.devProgramApply()
|
|
36
|
+
*/
|
|
37
|
+
export async function devProgramApply(client, req) {
|
|
38
|
+
const { data } = await client._doJSON("POST", "/qai/v1/credits/dev-program", req);
|
|
39
|
+
return data;
|
|
40
|
+
}
|
|
@@ -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, JobStreamEvent, 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,46 @@
|
|
|
1
|
+
import type { QuantumClient } from "./client.js";
|
|
2
|
+
import type { ChatRequest, JobCreateRequest, JobCreateResponse, JobListResponse, JobStatusResponse, JobStreamEvent } 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>;
|
|
29
|
+
/**
|
|
30
|
+
* Submit a chat completion as an async job. Useful for long-running
|
|
31
|
+
* models (e.g. Opus) where synchronous /qai/v1/chat may time out.
|
|
32
|
+
*
|
|
33
|
+
* Params are the same shape as ChatRequest (model, messages, tools, etc.)
|
|
34
|
+
* Use streamJob() or pollJob() to get the result.
|
|
35
|
+
* @internal
|
|
36
|
+
*/
|
|
37
|
+
export declare function chatJob(client: QuantumClient, req: Omit<ChatRequest, "stream">): Promise<JobCreateResponse>;
|
|
38
|
+
/**
|
|
39
|
+
* Stream job progress via SSE. Yields events as the job runs.
|
|
40
|
+
*
|
|
41
|
+
* Events: { type: "progress", status } | { type: "complete", result, cost_ticks } | { type: "error", error }
|
|
42
|
+
*
|
|
43
|
+
* If the job is already terminal, yields one event and returns.
|
|
44
|
+
* @internal
|
|
45
|
+
*/
|
|
46
|
+
export declare function streamJob(client: QuantumClient, jobId: string, signal?: AbortSignal): AsyncIterableIterator<JobStreamEvent>;
|
package/dist/jobs.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
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
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Submit a chat completion as an async job. Useful for long-running
|
|
59
|
+
* models (e.g. Opus) where synchronous /qai/v1/chat may time out.
|
|
60
|
+
*
|
|
61
|
+
* Params are the same shape as ChatRequest (model, messages, tools, etc.)
|
|
62
|
+
* Use streamJob() or pollJob() to get the result.
|
|
63
|
+
* @internal
|
|
64
|
+
*/
|
|
65
|
+
export async function chatJob(client, req) {
|
|
66
|
+
return createJob(client, {
|
|
67
|
+
type: "chat",
|
|
68
|
+
params: req,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Stream job progress via SSE. Yields events as the job runs.
|
|
73
|
+
*
|
|
74
|
+
* Events: { type: "progress", status } | { type: "complete", result, cost_ticks } | { type: "error", error }
|
|
75
|
+
*
|
|
76
|
+
* If the job is already terminal, yields one event and returns.
|
|
77
|
+
* @internal
|
|
78
|
+
*/
|
|
79
|
+
export async function* streamJob(client, jobId, signal) {
|
|
80
|
+
// Job stream is GET, not POST — use _doJSON's fetch directly.
|
|
81
|
+
const headers = {
|
|
82
|
+
Authorization: `Bearer ${client._apiKey}`,
|
|
83
|
+
Accept: "text/event-stream",
|
|
84
|
+
};
|
|
85
|
+
const response = await client._fetch(`${client._baseUrl}/qai/v1/jobs/${jobId}/stream`, { method: "GET", headers, signal });
|
|
86
|
+
if (!response.ok) {
|
|
87
|
+
throw new Error(`Job stream error (${response.status})`);
|
|
88
|
+
}
|
|
89
|
+
const reader = response.body;
|
|
90
|
+
if (!reader) {
|
|
91
|
+
throw new Error("qai: response body is null");
|
|
92
|
+
}
|
|
93
|
+
const decoder = new TextDecoder();
|
|
94
|
+
const streamReader = reader.getReader();
|
|
95
|
+
let buffer = "";
|
|
96
|
+
try {
|
|
97
|
+
while (true) {
|
|
98
|
+
const { done, value } = await streamReader.read();
|
|
99
|
+
if (done)
|
|
100
|
+
break;
|
|
101
|
+
buffer += decoder.decode(value, { stream: true });
|
|
102
|
+
const lines = buffer.split("\n");
|
|
103
|
+
buffer = lines.pop() ?? "";
|
|
104
|
+
for (const line of lines) {
|
|
105
|
+
if (!line.startsWith("data: "))
|
|
106
|
+
continue;
|
|
107
|
+
const payload = line.slice(6);
|
|
108
|
+
if (payload === "[DONE]")
|
|
109
|
+
return;
|
|
110
|
+
let event;
|
|
111
|
+
try {
|
|
112
|
+
event = JSON.parse(payload);
|
|
113
|
+
}
|
|
114
|
+
catch {
|
|
115
|
+
yield { type: "error", error: "parse SSE: invalid JSON" };
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
yield event;
|
|
119
|
+
if (event.type === "complete" || event.type === "error") {
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
streamReader.releaseLock();
|
|
127
|
+
}
|
|
128
|
+
}
|
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
|
+
}
|