@zelailabs/sdk 0.0.0-stage → 0.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/LICENSE +202 -0
- package/README.id.md +304 -0
- package/README.md +313 -2
- package/dist/cjs/account.d.ts +1 -0
- package/dist/cjs/account.js +18 -0
- package/dist/cjs/account.js.map +1 -0
- package/dist/cjs/ban.d.ts +1 -0
- package/dist/cjs/ban.js +18 -0
- package/dist/cjs/ban.js.map +1 -0
- package/dist/cjs/guardrails.d.ts +1 -0
- package/dist/cjs/guardrails.js +18 -0
- package/dist/cjs/guardrails.js.map +1 -0
- package/dist/cjs/index.d.ts +14 -0
- package/dist/cjs/index.js +23 -0
- package/dist/cjs/index.js.map +1 -0
- package/dist/cjs/lib/errors.d.ts +22 -0
- package/dist/cjs/lib/errors.js +43 -0
- package/dist/cjs/lib/errors.js.map +1 -0
- package/dist/cjs/lib/retry.d.ts +24 -0
- package/dist/cjs/lib/retry.js +80 -0
- package/dist/cjs/lib/retry.js.map +1 -0
- package/dist/cjs/lib/stream.d.ts +2 -0
- package/dist/cjs/lib/stream.js +69 -0
- package/dist/cjs/lib/stream.js.map +1 -0
- package/dist/cjs/models/types.d.ts +203 -0
- package/dist/cjs/models/types.js +3 -0
- package/dist/cjs/models/types.js.map +1 -0
- package/dist/cjs/package.json +3 -0
- package/dist/cjs/retry.d.ts +1 -0
- package/dist/cjs/retry.js +18 -0
- package/dist/cjs/retry.js.map +1 -0
- package/dist/cjs/sdk/account.d.ts +1 -0
- package/dist/cjs/sdk/account.js +8 -0
- package/dist/cjs/sdk/account.js.map +1 -0
- package/dist/cjs/sdk/ban.d.ts +96 -0
- package/dist/cjs/sdk/ban.js +209 -0
- package/dist/cjs/sdk/ban.js.map +1 -0
- package/dist/cjs/sdk/client.d.ts +135 -0
- package/dist/cjs/sdk/client.js +357 -0
- package/dist/cjs/sdk/client.js.map +1 -0
- package/dist/cjs/sdk/guardrails.d.ts +58 -0
- package/dist/cjs/sdk/guardrails.js +238 -0
- package/dist/cjs/sdk/guardrails.js.map +1 -0
- package/dist/cjs/sdk/worker.d.ts +80 -0
- package/dist/cjs/sdk/worker.js +251 -0
- package/dist/cjs/sdk/worker.js.map +1 -0
- package/dist/cjs/worker.d.ts +1 -0
- package/dist/cjs/worker.js +18 -0
- package/dist/cjs/worker.js.map +1 -0
- package/dist/esm/account.d.ts +1 -0
- package/dist/esm/account.js +2 -0
- package/dist/esm/account.js.map +1 -0
- package/dist/esm/ban.d.ts +1 -0
- package/dist/esm/ban.js +2 -0
- package/dist/esm/ban.js.map +1 -0
- package/dist/esm/guardrails.d.ts +1 -0
- package/dist/esm/guardrails.js +2 -0
- package/dist/esm/guardrails.js.map +1 -0
- package/dist/esm/index.d.ts +14 -0
- package/dist/esm/index.js +10 -0
- package/dist/esm/index.js.map +1 -0
- package/dist/esm/lib/errors.d.ts +22 -0
- package/dist/esm/lib/errors.js +39 -0
- package/dist/esm/lib/errors.js.map +1 -0
- package/dist/esm/lib/retry.d.ts +24 -0
- package/dist/esm/lib/retry.js +76 -0
- package/dist/esm/lib/retry.js.map +1 -0
- package/dist/esm/lib/stream.d.ts +2 -0
- package/dist/esm/lib/stream.js +66 -0
- package/dist/esm/lib/stream.js.map +1 -0
- package/dist/esm/models/types.d.ts +203 -0
- package/dist/esm/models/types.js +2 -0
- package/dist/esm/models/types.js.map +1 -0
- package/dist/esm/retry.d.ts +1 -0
- package/dist/esm/retry.js +2 -0
- package/dist/esm/retry.js.map +1 -0
- package/dist/esm/sdk/account.d.ts +1 -0
- package/dist/esm/sdk/account.js +2 -0
- package/dist/esm/sdk/account.js.map +1 -0
- package/dist/esm/sdk/ban.d.ts +96 -0
- package/dist/esm/sdk/ban.js +203 -0
- package/dist/esm/sdk/ban.js.map +1 -0
- package/dist/esm/sdk/client.d.ts +135 -0
- package/dist/esm/sdk/client.js +338 -0
- package/dist/esm/sdk/client.js.map +1 -0
- package/dist/esm/sdk/guardrails.d.ts +58 -0
- package/dist/esm/sdk/guardrails.js +234 -0
- package/dist/esm/sdk/guardrails.js.map +1 -0
- package/dist/esm/sdk/worker.d.ts +80 -0
- package/dist/esm/sdk/worker.js +248 -0
- package/dist/esm/sdk/worker.js.map +1 -0
- package/dist/esm/worker.d.ts +1 -0
- package/dist/esm/worker.js +2 -0
- package/dist/esm/worker.js.map +1 -0
- package/package.json +110 -4
- package/zelai-docs.md +179 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import type { AccountCredit, AccountKey, AccountKeyCreateParams, AccountKeyList, AccountLogs, AccountTemplate, AccountTemplateCreateParams, AccountTemplateList, AudioSpeechParams, AudioTranscriptionParams, AudioTranslationParams, ChatCompletion, ChatCompletionChunk, ChatCompletionCreateParams, ImageEditParams, ImageGenerationParams, ModelList, RequestOptions, SystemOneCreateParams, VideoGenerationParams, ZelAIClientOptions } from '../models/types.js';
|
|
2
|
+
export declare class ZelAI {
|
|
3
|
+
readonly apiKey?: string;
|
|
4
|
+
readonly baseURL: string;
|
|
5
|
+
readonly timeoutMs: number;
|
|
6
|
+
readonly fetchImpl: typeof fetch;
|
|
7
|
+
readonly defaultHeaders: Record<string, string>;
|
|
8
|
+
readonly models: ModelsResource;
|
|
9
|
+
readonly chat: ChatResource;
|
|
10
|
+
readonly responses: ResponsesResource;
|
|
11
|
+
readonly messages: MessagesResource;
|
|
12
|
+
readonly systemOne: SystemOneResource;
|
|
13
|
+
readonly images: ImagesResource;
|
|
14
|
+
readonly videos: VideosResource;
|
|
15
|
+
readonly audio: AudioResource;
|
|
16
|
+
readonly account: AccountResource;
|
|
17
|
+
constructor(options?: ZelAIClientOptions);
|
|
18
|
+
request<T>(path: string, init?: {
|
|
19
|
+
method?: string;
|
|
20
|
+
body?: unknown;
|
|
21
|
+
query?: Record<string, string | number | boolean | undefined>;
|
|
22
|
+
headers?: Record<string, string>;
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
timeoutMs?: number;
|
|
25
|
+
raw?: boolean;
|
|
26
|
+
}): Promise<T>;
|
|
27
|
+
requestStream<T>(path: string, init?: {
|
|
28
|
+
body?: unknown;
|
|
29
|
+
headers?: Record<string, string>;
|
|
30
|
+
signal?: AbortSignal;
|
|
31
|
+
timeoutMs?: number;
|
|
32
|
+
}): Promise<AsyncGenerator<T>>;
|
|
33
|
+
}
|
|
34
|
+
export declare class ModelsResource {
|
|
35
|
+
private readonly client;
|
|
36
|
+
constructor(client: ZelAI);
|
|
37
|
+
list(options?: RequestOptions): Promise<ModelList>;
|
|
38
|
+
retrieve(model: string, options?: RequestOptions): Promise<unknown>;
|
|
39
|
+
}
|
|
40
|
+
export declare class ChatCompletionsResource {
|
|
41
|
+
private readonly client;
|
|
42
|
+
constructor(client: ZelAI);
|
|
43
|
+
create(params: ChatCompletionCreateParams & {
|
|
44
|
+
stream: true;
|
|
45
|
+
}, options?: RequestOptions): Promise<AsyncGenerator<ChatCompletionChunk>>;
|
|
46
|
+
create(params: ChatCompletionCreateParams & {
|
|
47
|
+
stream?: false;
|
|
48
|
+
}, options?: RequestOptions): Promise<ChatCompletion>;
|
|
49
|
+
create(params: ChatCompletionCreateParams, options?: RequestOptions): Promise<ChatCompletion | AsyncGenerator<ChatCompletionChunk>>;
|
|
50
|
+
}
|
|
51
|
+
export declare class ChatResource {
|
|
52
|
+
readonly completions: ChatCompletionsResource;
|
|
53
|
+
constructor(client: ZelAI);
|
|
54
|
+
}
|
|
55
|
+
export declare class ResponsesResource {
|
|
56
|
+
private readonly client;
|
|
57
|
+
constructor(client: ZelAI);
|
|
58
|
+
create(params: Record<string, unknown>, options?: RequestOptions): Promise<unknown>;
|
|
59
|
+
}
|
|
60
|
+
export declare class MessagesResource {
|
|
61
|
+
private readonly client;
|
|
62
|
+
constructor(client: ZelAI);
|
|
63
|
+
create(params: Record<string, unknown>, options?: RequestOptions): Promise<unknown>;
|
|
64
|
+
}
|
|
65
|
+
export declare class SystemOneResource {
|
|
66
|
+
private readonly client;
|
|
67
|
+
constructor(client: ZelAI);
|
|
68
|
+
create(params: SystemOneCreateParams, options?: RequestOptions): Promise<unknown>;
|
|
69
|
+
}
|
|
70
|
+
export declare class ImagesResource {
|
|
71
|
+
private readonly client;
|
|
72
|
+
constructor(client: ZelAI);
|
|
73
|
+
generate(params: ImageGenerationParams, options?: RequestOptions): Promise<unknown>;
|
|
74
|
+
edit(params: ImageEditParams, options?: RequestOptions): Promise<unknown>;
|
|
75
|
+
}
|
|
76
|
+
export declare class VideosResource {
|
|
77
|
+
private readonly client;
|
|
78
|
+
constructor(client: ZelAI);
|
|
79
|
+
generate(params: VideoGenerationParams, options?: RequestOptions): Promise<unknown>;
|
|
80
|
+
}
|
|
81
|
+
export declare class AudioResource {
|
|
82
|
+
readonly speech: AudioSpeechResource;
|
|
83
|
+
readonly transcriptions: AudioTranscriptionsResource;
|
|
84
|
+
readonly translations: AudioTranslationsResource;
|
|
85
|
+
constructor(client: ZelAI);
|
|
86
|
+
}
|
|
87
|
+
export declare class AudioSpeechResource {
|
|
88
|
+
private readonly client;
|
|
89
|
+
constructor(client: ZelAI);
|
|
90
|
+
create(params: AudioSpeechParams, options?: RequestOptions): Promise<ArrayBuffer>;
|
|
91
|
+
}
|
|
92
|
+
export declare class AudioTranscriptionsResource {
|
|
93
|
+
private readonly client;
|
|
94
|
+
constructor(client: ZelAI);
|
|
95
|
+
create(params: AudioTranscriptionParams, options?: RequestOptions): Promise<unknown>;
|
|
96
|
+
}
|
|
97
|
+
export declare class AudioTranslationsResource {
|
|
98
|
+
private readonly client;
|
|
99
|
+
constructor(client: ZelAI);
|
|
100
|
+
create(params: AudioTranslationParams, options?: RequestOptions): Promise<unknown>;
|
|
101
|
+
}
|
|
102
|
+
export declare class AccountResource {
|
|
103
|
+
private readonly client;
|
|
104
|
+
readonly keys: AccountKeysResource;
|
|
105
|
+
readonly templates: AccountTemplatesResource;
|
|
106
|
+
constructor(client: ZelAI);
|
|
107
|
+
credit(query?: {
|
|
108
|
+
limit?: number;
|
|
109
|
+
}, options?: RequestOptions): Promise<AccountCredit>;
|
|
110
|
+
logs(query?: {
|
|
111
|
+
days?: number;
|
|
112
|
+
limit?: number;
|
|
113
|
+
offset?: number;
|
|
114
|
+
model?: string;
|
|
115
|
+
status?: string;
|
|
116
|
+
sort?: string;
|
|
117
|
+
order?: string;
|
|
118
|
+
}, options?: RequestOptions): Promise<AccountLogs>;
|
|
119
|
+
}
|
|
120
|
+
export declare class AccountKeysResource {
|
|
121
|
+
private readonly client;
|
|
122
|
+
constructor(client: ZelAI);
|
|
123
|
+
create(params: AccountKeyCreateParams, options?: RequestOptions): Promise<AccountKey>;
|
|
124
|
+
list(query?: {
|
|
125
|
+
workspace?: string;
|
|
126
|
+
}, options?: RequestOptions): Promise<AccountKeyList | AccountKey[]>;
|
|
127
|
+
revoke(id: string, options?: RequestOptions): Promise<unknown>;
|
|
128
|
+
delete(id: string, options?: RequestOptions): Promise<unknown>;
|
|
129
|
+
}
|
|
130
|
+
export declare class AccountTemplatesResource {
|
|
131
|
+
private readonly client;
|
|
132
|
+
constructor(client: ZelAI);
|
|
133
|
+
create(params: AccountTemplateCreateParams, options?: RequestOptions): Promise<AccountTemplate>;
|
|
134
|
+
list(options?: RequestOptions): Promise<AccountTemplateList | AccountTemplate[]>;
|
|
135
|
+
}
|
|
@@ -0,0 +1,357 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AccountTemplatesResource = exports.AccountKeysResource = exports.AccountResource = exports.AudioTranslationsResource = exports.AudioTranscriptionsResource = exports.AudioSpeechResource = exports.AudioResource = exports.VideosResource = exports.ImagesResource = exports.SystemOneResource = exports.MessagesResource = exports.ResponsesResource = exports.ChatResource = exports.ChatCompletionsResource = exports.ModelsResource = exports.ZelAI = void 0;
|
|
4
|
+
const errors_js_1 = require("../lib/errors.js");
|
|
5
|
+
const stream_js_1 = require("../lib/stream.js");
|
|
6
|
+
const DEFAULT_BASE_URL = 'https://zelapi.eu.cc/v1';
|
|
7
|
+
const DEFAULT_TIMEOUT_MS = 60_000;
|
|
8
|
+
class ZelAI {
|
|
9
|
+
apiKey;
|
|
10
|
+
baseURL;
|
|
11
|
+
timeoutMs;
|
|
12
|
+
fetchImpl;
|
|
13
|
+
defaultHeaders;
|
|
14
|
+
models;
|
|
15
|
+
chat;
|
|
16
|
+
responses;
|
|
17
|
+
messages;
|
|
18
|
+
systemOne;
|
|
19
|
+
images;
|
|
20
|
+
videos;
|
|
21
|
+
audio;
|
|
22
|
+
account;
|
|
23
|
+
constructor(options = {}) {
|
|
24
|
+
this.apiKey = options.apiKey ?? readEnvApiKey();
|
|
25
|
+
this.baseURL = normalizeBaseURL(options.baseURL ?? DEFAULT_BASE_URL);
|
|
26
|
+
this.timeoutMs = options.timeoutMs ?? DEFAULT_TIMEOUT_MS;
|
|
27
|
+
this.fetchImpl = options.fetch ?? globalThis.fetch;
|
|
28
|
+
if (!this.fetchImpl)
|
|
29
|
+
throw new errors_js_1.ZelAIError('No fetch implementation found. Use Node 18+ or pass options.fetch.');
|
|
30
|
+
this.defaultHeaders = { ...options.defaultHeaders };
|
|
31
|
+
this.models = new ModelsResource(this);
|
|
32
|
+
this.chat = new ChatResource(this);
|
|
33
|
+
this.responses = new ResponsesResource(this);
|
|
34
|
+
this.messages = new MessagesResource(this);
|
|
35
|
+
this.systemOne = new SystemOneResource(this);
|
|
36
|
+
this.images = new ImagesResource(this);
|
|
37
|
+
this.videos = new VideosResource(this);
|
|
38
|
+
this.audio = new AudioResource(this);
|
|
39
|
+
this.account = new AccountResource(this);
|
|
40
|
+
}
|
|
41
|
+
async request(path, init = {}) {
|
|
42
|
+
const url = buildURL(this.baseURL, path, init.query);
|
|
43
|
+
const headers = {
|
|
44
|
+
Accept: 'application/json',
|
|
45
|
+
...this.defaultHeaders,
|
|
46
|
+
...init.headers,
|
|
47
|
+
};
|
|
48
|
+
if (this.apiKey)
|
|
49
|
+
headers.Authorization = `Bearer ${this.apiKey}`;
|
|
50
|
+
const hasBody = init.body !== undefined;
|
|
51
|
+
if (hasBody && !hasHeader(headers, 'content-type'))
|
|
52
|
+
headers['Content-Type'] = 'application/json';
|
|
53
|
+
const { signal, cleanup } = mergeSignals(init.signal, init.timeoutMs ?? this.timeoutMs);
|
|
54
|
+
try {
|
|
55
|
+
const response = await this.fetchImpl(url, {
|
|
56
|
+
method: init.method ?? (hasBody ? 'POST' : 'GET'),
|
|
57
|
+
headers,
|
|
58
|
+
body: hasBody ? JSON.stringify(init.body) : undefined,
|
|
59
|
+
signal,
|
|
60
|
+
});
|
|
61
|
+
if (!response.ok)
|
|
62
|
+
throw errors_js_1.ZelAIError.fromResponse(response.status, await safeBody(response), response.headers);
|
|
63
|
+
if (init.raw)
|
|
64
|
+
return response;
|
|
65
|
+
if (response.status === 204)
|
|
66
|
+
return undefined;
|
|
67
|
+
return await parseResponseBody(response);
|
|
68
|
+
}
|
|
69
|
+
catch (err) {
|
|
70
|
+
throw toZelAIError(err);
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
cleanup();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
async requestStream(path, init = {}) {
|
|
77
|
+
const response = await this.request(path, {
|
|
78
|
+
method: 'POST',
|
|
79
|
+
body: init.body,
|
|
80
|
+
headers: { Accept: 'text/event-stream', ...init.headers },
|
|
81
|
+
signal: init.signal,
|
|
82
|
+
timeoutMs: init.timeoutMs,
|
|
83
|
+
raw: true,
|
|
84
|
+
});
|
|
85
|
+
return (0, stream_js_1.parseSSE)(response);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.ZelAI = ZelAI;
|
|
89
|
+
class ModelsResource {
|
|
90
|
+
client;
|
|
91
|
+
constructor(client) {
|
|
92
|
+
this.client = client;
|
|
93
|
+
}
|
|
94
|
+
list(options) {
|
|
95
|
+
return this.client.request('/models', { method: 'GET', ...options });
|
|
96
|
+
}
|
|
97
|
+
retrieve(model, options) {
|
|
98
|
+
return this.client.request(`/models/${encodeURIComponent(model)}`, { method: 'GET', ...options });
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
exports.ModelsResource = ModelsResource;
|
|
102
|
+
class ChatCompletionsResource {
|
|
103
|
+
client;
|
|
104
|
+
constructor(client) {
|
|
105
|
+
this.client = client;
|
|
106
|
+
}
|
|
107
|
+
create(params, options) {
|
|
108
|
+
if (params.stream) {
|
|
109
|
+
return this.client.requestStream('/chat/completions', { body: params, ...options });
|
|
110
|
+
}
|
|
111
|
+
return this.client.request('/chat/completions', { method: 'POST', body: params, ...options });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
exports.ChatCompletionsResource = ChatCompletionsResource;
|
|
115
|
+
class ChatResource {
|
|
116
|
+
completions;
|
|
117
|
+
constructor(client) {
|
|
118
|
+
this.completions = new ChatCompletionsResource(client);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
exports.ChatResource = ChatResource;
|
|
122
|
+
class ResponsesResource {
|
|
123
|
+
client;
|
|
124
|
+
constructor(client) {
|
|
125
|
+
this.client = client;
|
|
126
|
+
}
|
|
127
|
+
create(params, options) {
|
|
128
|
+
return this.client.request('/responses', { method: 'POST', body: params, ...options });
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
exports.ResponsesResource = ResponsesResource;
|
|
132
|
+
class MessagesResource {
|
|
133
|
+
client;
|
|
134
|
+
constructor(client) {
|
|
135
|
+
this.client = client;
|
|
136
|
+
}
|
|
137
|
+
create(params, options) {
|
|
138
|
+
return this.client.request('/messages', { method: 'POST', body: params, ...options });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
exports.MessagesResource = MessagesResource;
|
|
142
|
+
class SystemOneResource {
|
|
143
|
+
client;
|
|
144
|
+
constructor(client) {
|
|
145
|
+
this.client = client;
|
|
146
|
+
}
|
|
147
|
+
create(params, options) {
|
|
148
|
+
return this.client.request('/systemone', { method: 'POST', body: params, ...options });
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
exports.SystemOneResource = SystemOneResource;
|
|
152
|
+
class ImagesResource {
|
|
153
|
+
client;
|
|
154
|
+
constructor(client) {
|
|
155
|
+
this.client = client;
|
|
156
|
+
}
|
|
157
|
+
generate(params, options) {
|
|
158
|
+
return this.client.request('/images/generations', { method: 'POST', body: params, ...options });
|
|
159
|
+
}
|
|
160
|
+
edit(params, options) {
|
|
161
|
+
return this.client.request('/images/edits', { method: 'POST', body: params, ...options });
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
exports.ImagesResource = ImagesResource;
|
|
165
|
+
class VideosResource {
|
|
166
|
+
client;
|
|
167
|
+
constructor(client) {
|
|
168
|
+
this.client = client;
|
|
169
|
+
}
|
|
170
|
+
generate(params, options) {
|
|
171
|
+
return this.client.request('/videos/generations', { method: 'POST', body: params, ...options });
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
exports.VideosResource = VideosResource;
|
|
175
|
+
class AudioResource {
|
|
176
|
+
speech;
|
|
177
|
+
transcriptions;
|
|
178
|
+
translations;
|
|
179
|
+
constructor(client) {
|
|
180
|
+
this.speech = new AudioSpeechResource(client);
|
|
181
|
+
this.transcriptions = new AudioTranscriptionsResource(client);
|
|
182
|
+
this.translations = new AudioTranslationsResource(client);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
exports.AudioResource = AudioResource;
|
|
186
|
+
class AudioSpeechResource {
|
|
187
|
+
client;
|
|
188
|
+
constructor(client) {
|
|
189
|
+
this.client = client;
|
|
190
|
+
}
|
|
191
|
+
async create(params, options) {
|
|
192
|
+
const response = await this.client.request('/audio/speech', { method: 'POST', body: params, raw: true, ...options });
|
|
193
|
+
try {
|
|
194
|
+
return await response.arrayBuffer();
|
|
195
|
+
}
|
|
196
|
+
catch (err) {
|
|
197
|
+
throw toZelAIError(err, 'Failed to read audio response');
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
exports.AudioSpeechResource = AudioSpeechResource;
|
|
202
|
+
class AudioTranscriptionsResource {
|
|
203
|
+
client;
|
|
204
|
+
constructor(client) {
|
|
205
|
+
this.client = client;
|
|
206
|
+
}
|
|
207
|
+
create(params, options) {
|
|
208
|
+
return this.client.request('/audio/transcriptions', { method: 'POST', body: params, ...options });
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
exports.AudioTranscriptionsResource = AudioTranscriptionsResource;
|
|
212
|
+
class AudioTranslationsResource {
|
|
213
|
+
client;
|
|
214
|
+
constructor(client) {
|
|
215
|
+
this.client = client;
|
|
216
|
+
}
|
|
217
|
+
create(params, options) {
|
|
218
|
+
return this.client.request('/audio/translations', { method: 'POST', body: params, ...options });
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
exports.AudioTranslationsResource = AudioTranslationsResource;
|
|
222
|
+
function normalizeBaseURL(baseURL) {
|
|
223
|
+
return baseURL.replace(/\/+$/, '');
|
|
224
|
+
}
|
|
225
|
+
class AccountResource {
|
|
226
|
+
client;
|
|
227
|
+
keys;
|
|
228
|
+
templates;
|
|
229
|
+
constructor(client) {
|
|
230
|
+
this.client = client;
|
|
231
|
+
this.keys = new AccountKeysResource(client);
|
|
232
|
+
this.templates = new AccountTemplatesResource(client);
|
|
233
|
+
}
|
|
234
|
+
credit(query, options) {
|
|
235
|
+
return this.client.request('/account/credit', { method: 'GET', query: query, ...options });
|
|
236
|
+
}
|
|
237
|
+
logs(query, options) {
|
|
238
|
+
return this.client.request('/account/logs', { method: 'GET', query: query, ...options });
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
exports.AccountResource = AccountResource;
|
|
242
|
+
class AccountKeysResource {
|
|
243
|
+
client;
|
|
244
|
+
constructor(client) {
|
|
245
|
+
this.client = client;
|
|
246
|
+
}
|
|
247
|
+
create(params, options) {
|
|
248
|
+
return this.client.request('/account/keys', { method: 'POST', body: params, ...options });
|
|
249
|
+
}
|
|
250
|
+
list(query, options) {
|
|
251
|
+
return this.client.request('/account/keys', { method: 'GET', query: query, ...options });
|
|
252
|
+
}
|
|
253
|
+
revoke(id, options) {
|
|
254
|
+
return this.client.request(`/account/keys/${encodeURIComponent(id)}`, { method: 'DELETE', query: { action: 'revoke' }, ...options });
|
|
255
|
+
}
|
|
256
|
+
delete(id, options) {
|
|
257
|
+
return this.client.request(`/account/keys/${encodeURIComponent(id)}`, { method: 'DELETE', query: { action: 'delete' }, ...options });
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
exports.AccountKeysResource = AccountKeysResource;
|
|
261
|
+
class AccountTemplatesResource {
|
|
262
|
+
client;
|
|
263
|
+
constructor(client) {
|
|
264
|
+
this.client = client;
|
|
265
|
+
}
|
|
266
|
+
create(params, options) {
|
|
267
|
+
return this.client.request('/account/templates', { method: 'POST', body: params, ...options });
|
|
268
|
+
}
|
|
269
|
+
list(options) {
|
|
270
|
+
return this.client.request('/account/templates', { method: 'GET', ...options });
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
exports.AccountTemplatesResource = AccountTemplatesResource;
|
|
274
|
+
function buildURL(baseURL, path, query) {
|
|
275
|
+
const url = new URL(baseURL + (path.startsWith('/') ? path : `/${path}`));
|
|
276
|
+
if (query) {
|
|
277
|
+
for (const [k, v] of Object.entries(query)) {
|
|
278
|
+
if (v !== undefined)
|
|
279
|
+
url.searchParams.set(k, String(v));
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return url.toString();
|
|
283
|
+
}
|
|
284
|
+
function hasHeader(headers, name) {
|
|
285
|
+
const lower = name.toLowerCase();
|
|
286
|
+
return Object.keys(headers).some(k => k.toLowerCase() === lower);
|
|
287
|
+
}
|
|
288
|
+
async function safeBody(response) {
|
|
289
|
+
const ct = response.headers.get('content-type') || '';
|
|
290
|
+
if (ct.includes('application/json')) {
|
|
291
|
+
try {
|
|
292
|
+
return await response.json();
|
|
293
|
+
}
|
|
294
|
+
catch {
|
|
295
|
+
return await safeText(response);
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
return await safeText(response);
|
|
299
|
+
}
|
|
300
|
+
async function safeText(response) {
|
|
301
|
+
try {
|
|
302
|
+
return await response.text();
|
|
303
|
+
}
|
|
304
|
+
catch {
|
|
305
|
+
return undefined;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
async function parseResponseBody(response) {
|
|
309
|
+
const ct = response.headers.get('content-type') || '';
|
|
310
|
+
if (ct.includes('application/json')) {
|
|
311
|
+
try {
|
|
312
|
+
return await response.json();
|
|
313
|
+
}
|
|
314
|
+
catch (err) {
|
|
315
|
+
throw new errors_js_1.ZelAIError('Failed to parse JSON response', { status: response.status, headers: response.headers, cause: err });
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
try {
|
|
319
|
+
return await response.text();
|
|
320
|
+
}
|
|
321
|
+
catch (err) {
|
|
322
|
+
throw new errors_js_1.ZelAIError('Failed to read response body', { status: response.status, headers: response.headers, cause: err });
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
function mergeSignals(signal, timeoutMs) {
|
|
326
|
+
const controller = new AbortController();
|
|
327
|
+
const timeout = setTimeout(() => controller.abort(new Error('timeout')), timeoutMs);
|
|
328
|
+
const onAbort = () => controller.abort(signal?.reason);
|
|
329
|
+
if (signal) {
|
|
330
|
+
if (signal.aborted)
|
|
331
|
+
controller.abort(signal.reason);
|
|
332
|
+
else
|
|
333
|
+
signal.addEventListener('abort', onAbort, { once: true });
|
|
334
|
+
}
|
|
335
|
+
return {
|
|
336
|
+
signal: controller.signal,
|
|
337
|
+
cleanup: () => {
|
|
338
|
+
clearTimeout(timeout);
|
|
339
|
+
signal?.removeEventListener('abort', onAbort);
|
|
340
|
+
},
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
function isAbortError(err) {
|
|
344
|
+
return err instanceof Error && (err.name === 'AbortError' || err.message === 'timeout');
|
|
345
|
+
}
|
|
346
|
+
function toZelAIError(err, fallback = 'Request failed') {
|
|
347
|
+
if (err instanceof errors_js_1.ZelAIError)
|
|
348
|
+
return err;
|
|
349
|
+
if (isAbortError(err))
|
|
350
|
+
return new errors_js_1.ZelAIError('Request timed out or was aborted', { cause: err });
|
|
351
|
+
return new errors_js_1.ZelAIError(err instanceof Error ? err.message : fallback, { cause: err });
|
|
352
|
+
}
|
|
353
|
+
function readEnvApiKey() {
|
|
354
|
+
const g = globalThis;
|
|
355
|
+
return g.process?.env?.ZELAI_API_KEY;
|
|
356
|
+
}
|
|
357
|
+
//# sourceMappingURL=client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../../../src/sdk/client.ts"],"names":[],"mappings":";;;AAAA,gDAA8C;AAC9C,gDAA4C;AAyB5C,MAAM,gBAAgB,GAAG,yBAAyB,CAAC;AACnD,MAAM,kBAAkB,GAAG,MAAM,CAAC;AAElC,MAAa,KAAK;IACP,MAAM,CAAU;IAChB,OAAO,CAAS;IAChB,SAAS,CAAS;IAClB,SAAS,CAAe;IACxB,cAAc,CAAyB;IAEvC,MAAM,CAAiB;IACvB,IAAI,CAAe;IACnB,SAAS,CAAoB;IAC7B,QAAQ,CAAmB;IAC3B,SAAS,CAAoB;IAC7B,MAAM,CAAiB;IACvB,MAAM,CAAiB;IACvB,KAAK,CAAgB;IACrB,OAAO,CAAkB;IAElC,YAAY,UAA8B,EAAE;QAC1C,IAAI,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,IAAI,aAAa,EAAE,CAAC;QAChD,IAAI,CAAC,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC,OAAO,IAAI,gBAAgB,CAAC,CAAC;QACrE,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,SAAS,IAAI,kBAAkB,CAAC;QACzD,IAAI,CAAC,SAAS,GAAG,OAAO,CAAC,KAAK,IAAI,UAAU,CAAC,KAAK,CAAC;QACnD,IAAI,CAAC,IAAI,CAAC,SAAS;YAAE,MAAM,IAAI,sBAAU,CAAC,oEAAoE,CAAC,CAAC;QAChH,IAAI,CAAC,cAA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AAC,CAAC;AAC1F,CAAC;AAED,SAAS,YAAY,CAAC,GAAY,EAAE,QAAQ,GAAG,gBAAgB;IAC7D,IAAI,GAAG,YAAY,sBAAU;QAAE,OAAO,GAAG,CAAC;IAC1C,IAAI,YAAY,CAAC,GAAG,CAAC;QAAE,OAAO,IAAI,sBAAU,CAAC,kCAAkC,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;IACjG,OAAO,IAAI,sBAAU,CAAC,GAAG,YAAY,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC;AACvF,CAAC;AAED,SAAS,aAAa;IACpB,MAAM,CAAC,GAAG,UAAmF,CAAC;IAC9F,OAAO,CAAC,CAAC,OAAO,EAAE,GAAG,EAAE,aAAa,CAAC;AACvC,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
export type GuardrailSeverity = 'low' | 'medium' | 'high' | 'critical';
|
|
2
|
+
export type GuardrailAction = 'block' | 'sanitize' | 'flag';
|
|
3
|
+
export interface GuardrailViolation {
|
|
4
|
+
rule: string;
|
|
5
|
+
severity: GuardrailSeverity;
|
|
6
|
+
action: GuardrailAction;
|
|
7
|
+
message: string;
|
|
8
|
+
path?: string;
|
|
9
|
+
details?: Record<string, unknown>;
|
|
10
|
+
}
|
|
11
|
+
export interface GuardrailResult {
|
|
12
|
+
ok: boolean;
|
|
13
|
+
violations: GuardrailViolation[];
|
|
14
|
+
sanitized?: unknown;
|
|
15
|
+
}
|
|
16
|
+
export interface GuardrailContext {
|
|
17
|
+
request?: Request;
|
|
18
|
+
ip?: string;
|
|
19
|
+
userId?: string;
|
|
20
|
+
metadata?: Record<string, unknown>;
|
|
21
|
+
}
|
|
22
|
+
export interface GuardrailRule {
|
|
23
|
+
name: string;
|
|
24
|
+
description?: string;
|
|
25
|
+
severity?: GuardrailSeverity;
|
|
26
|
+
action?: GuardrailAction;
|
|
27
|
+
check: (input: GuardrailInput, ctx: GuardrailContext) => GuardrailViolation[] | Promise<GuardrailViolation[]>;
|
|
28
|
+
}
|
|
29
|
+
export interface GuardrailInput {
|
|
30
|
+
endpoint?: string;
|
|
31
|
+
body?: unknown;
|
|
32
|
+
headers?: Headers;
|
|
33
|
+
}
|
|
34
|
+
export interface GuardrailsOptions {
|
|
35
|
+
rules?: GuardrailRule[];
|
|
36
|
+
maxBodyBytes?: number;
|
|
37
|
+
maxMessages?: number;
|
|
38
|
+
maxContentChars?: number;
|
|
39
|
+
maxRequestChars?: number;
|
|
40
|
+
allowedModels?: string[];
|
|
41
|
+
blockedModels?: string[];
|
|
42
|
+
allowedEndpoints?: string[];
|
|
43
|
+
blockedPatterns?: RegExp[];
|
|
44
|
+
redactPatterns?: RegExp[];
|
|
45
|
+
allowApiKeyPassthrough?: boolean;
|
|
46
|
+
requireUserMessage?: boolean;
|
|
47
|
+
detectPromptInjection?: boolean;
|
|
48
|
+
detectPII?: boolean;
|
|
49
|
+
piiAction?: GuardrailAction;
|
|
50
|
+
injectionAction?: GuardrailAction;
|
|
51
|
+
}
|
|
52
|
+
export declare class Guardrails {
|
|
53
|
+
readonly options: Required<Pick<GuardrailsOptions, 'maxBodyBytes' | 'maxMessages' | 'maxContentChars' | 'maxRequestChars' | 'allowApiKeyPassthrough' | 'requireUserMessage' | 'detectPromptInjection' | 'detectPII' | 'piiAction' | 'injectionAction'>> & GuardrailsOptions;
|
|
54
|
+
readonly rules: GuardrailRule[];
|
|
55
|
+
constructor(options?: GuardrailsOptions);
|
|
56
|
+
evaluate(input: GuardrailInput, ctx?: GuardrailContext): Promise<GuardrailResult>;
|
|
57
|
+
assertSafe(input: GuardrailInput, ctx?: GuardrailContext): Promise<unknown>;
|
|
58
|
+
}
|