1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109 | /**
* Asynchronous processing jobs: enqueue, poll for status, then fetch the
* result. Submitted content is never persisted; results are kept for 24
* hours.
*
* Every job type has a payload builder (`domainAvailabilityBulk`,
* `embedding`, `llmChat`, `llmRawCompletion`, `nlpAnalyze`,
* `nlpDetectLanguage`); pass the built payload to `enqueue`, or use `run`
* to enqueue, poll and fetch the result in one call.
*/
import type { Client } from './client.js';
import type { Body } from './types.js';
export type JobSpec = Body<'/jobs', 'post'>;
export type JobType = JobSpec['type'];
type Spec<T extends JobType> = Extract<JobSpec, {
type: T;
}>;
type Options<T extends JobType, K extends keyof Spec<T>> = Readonly<Partial<Omit<Spec<T>, 'type' | K>>>;
/** POST /jobs — Enqueue a job (202 with the queued job). */
export declare const enqueue: (client: Client, spec: JobSpec) => Promise<{
job: {
created_at: string;
id: string;
status: "queued";
type: string;
};
}>;
/** GET /jobs/{id} — Job status: queued/processing/succeeded/failed. */
export declare const get: (client: Client, id: string) => Promise<{
job: {
attempts: number;
bytes_in: number | null;
bytes_out: number | null;
created_at: string;
duration_ms: number | null;
error: string | null;
finished_at: string | null;
id: string;
result_expires_at?: string;
started_at: string | null;
status: "queued" | "processing" | "succeeded" | "failed";
type: string;
};
}>;
/** GET /jobs/{id}/result — Job result. 409 while still running, 410 once expired (24h). */
export declare const getResult: (client: Client, id: string) => Promise<{
"job-id": string;
result: {
[key: string]: unknown;
};
type: string;
}>;
/** Check up to 100 domains in one job. */
export declare const domainAvailabilityBulk: (domains: readonly string[]) => Spec<"domain-availability-bulk">;
/** Embed INPUT text (`model` defaults server-side). */
export declare const embedding: (input: string, options?: Options<"embedding", "input">) => Spec<"embedding">;
export type ChatMessage = Spec<'llm-chat'>['messages'][number];
/** Chat completion over MESSAGES. */
export declare const llmChat: (messages: readonly ChatMessage[], options?: Options<"llm-chat", "messages">) => Spec<"llm-chat">;
/** Raw completion of PROMPT. */
export declare const llmRawCompletion: (prompt: string, options?: Options<"llm-raw-completion", "prompt">) => Spec<"llm-raw-completion">;
/** NLP analysis of INPUT text. */
export declare const nlpAnalyze: (input: string, options?: Options<"nlp-analyze", "input">) => Spec<"nlp-analyze">;
/** Language detection of INPUT text. */
export declare const nlpDetectLanguage: (input: string) => Spec<"nlp-detect-language">;
export type TextPart = Readonly<{
type: 'text';
text: string;
}>;
export type ImagePart = Readonly<{
type: 'image_url';
image_url: Readonly<{
url: string;
}>;
}>;
export type ContentPart = TextPart | ImagePart;
export type MultimodalMessage = Readonly<{
role: 'user';
content: readonly ContentPart[];
}>;
/** OpenAI-style text content part. */
export declare const textPart: (text: string) => TextPart;
/**
* OpenAI-style image_url content part from SOURCE (a file path or bytes),
* embedded as a base64 data URL. The MIME type is sniffed from a path's
* extension (png/jpg/jpeg/webp/gif) or passed explicitly.
*/
export declare const imagePart: (source: string | Uint8Array, mimeType?: string) => Promise<ImagePart>;
/** A user message whose content is TEXT plus any IMAGE-PARTS (from `imagePart`). */
export declare const userMessage: (text: string, ...imageParts: readonly ImagePart[]) => MultimodalMessage;
export type RunOptions = Readonly<{
/** Initial poll interval (default 1000, backing off to an 8 s cap). */
intervalMs?: number;
/** Overall deadline (default 120000). */
timeoutMs?: number;
}>;
/**
* Enqueue SPEC, poll until the job reaches a terminal status, then fetch
* and return the result. Throws a jobFailed error with the failed job, or a
* timeout error when the deadline passes first.
*/
export declare const run: (client: Client, spec: JobSpec, options?: RunOptions) => Promise<{
"job-id": string;
result: {
[key: string]: unknown;
};
type: string;
}>;
export {};
|