@yetter/client 0.0.2 → 0.0.4
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/README.md +15 -1
- package/dist/client.d.ts +4 -1
- package/dist/client.js +31 -16
- package/package.json +1 -1
- package/src/client.ts +34 -16
package/README.md
CHANGED
|
@@ -10,12 +10,26 @@ npm install @yetter/client
|
|
|
10
10
|
|
|
11
11
|
## Authentication
|
|
12
12
|
|
|
13
|
-
The client requires a Yetter API key for authentication. Ensure you have the `YTR_API_KEY` environment variable set:
|
|
13
|
+
The client requires a Yetter API key for authentication. Ensure you have the `YTR_API_KEY` or `REACT_APP_YTR_API_KEY` environment variable set:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
16
|
export YTR_API_KEY="your_api_key_here"
|
|
17
|
+
export REACT_APP_YTR_API_KEY="your_api_key_here"
|
|
17
18
|
```
|
|
18
19
|
|
|
20
|
+
Alternatively, you can configure the API key (and optionally the API endpoint) programmatically using the `yetter.configure()` method. This is useful if you prefer not to use environment variables or need to set the key at runtime.
|
|
21
|
+
|
|
22
|
+
```typescript
|
|
23
|
+
import { yetter } from "@yetter/client";
|
|
24
|
+
|
|
25
|
+
yetter.configure({
|
|
26
|
+
apiKey: "your_api_key_here",
|
|
27
|
+
// endpoint: "https://custom.api.yetter.ai" // if you need to override the default endpoint
|
|
28
|
+
});
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
If `yetter.configure()` is used, it will override any API key found in environment variables for subsequent API calls. If neither environment variables are set nor `yetter.configure()` is called with an API key, an error will be thrown when attempting to make an API call.
|
|
32
|
+
|
|
19
33
|
## Core Functionalities
|
|
20
34
|
|
|
21
35
|
The client is available via the `yetter` object imported from `yetter-js` (or the relevant path to `client.js`/`client.ts` if used directly).
|
package/dist/client.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { GetResponseResponse, SubscribeOptions, GenerateImageResponse, SubmitQueueOptions, GetResultOptions, GetResultResponse, StatusOptions, StatusResponse, StreamOptions, YetterStream } from "./types.js";
|
|
1
|
+
import { ClientOptions, GetResponseResponse, SubscribeOptions, GenerateImageResponse, SubmitQueueOptions, GetResultOptions, GetResultResponse, StatusOptions, StatusResponse, StreamOptions, YetterStream } from "./types.js";
|
|
2
2
|
export declare class yetter {
|
|
3
|
+
private static apiKey;
|
|
4
|
+
private static endpoint;
|
|
5
|
+
static configure(options: ClientOptions): void;
|
|
3
6
|
static subscribe(model: string, options: SubscribeOptions): Promise<GetResponseResponse>;
|
|
4
7
|
static queue: {
|
|
5
8
|
submit: (model: string, options: SubmitQueueOptions) => Promise<GenerateImageResponse>;
|
package/dist/client.js
CHANGED
|
@@ -2,13 +2,22 @@ var _a;
|
|
|
2
2
|
import { YetterImageClient } from "./api.js";
|
|
3
3
|
import { EventSourcePolyfill } from 'event-source-polyfill';
|
|
4
4
|
export class yetter {
|
|
5
|
+
static configure(options) {
|
|
6
|
+
if (options.apiKey) {
|
|
7
|
+
_a.apiKey = options.apiKey;
|
|
8
|
+
}
|
|
9
|
+
if (options.endpoint) {
|
|
10
|
+
_a.endpoint = options.endpoint;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
5
13
|
static async subscribe(model, options) {
|
|
6
14
|
var _b;
|
|
7
|
-
if (!
|
|
8
|
-
throw new Error("
|
|
15
|
+
if (!_a.apiKey) {
|
|
16
|
+
throw new Error("API key is not configured. Call yetter.configure({ apiKey: 'your_key' }) or set YTR_API_KEY.");
|
|
9
17
|
}
|
|
10
18
|
const client = new YetterImageClient({
|
|
11
|
-
apiKey:
|
|
19
|
+
apiKey: _a.apiKey,
|
|
20
|
+
endpoint: _a.endpoint,
|
|
12
21
|
});
|
|
13
22
|
const generateResponse = await client.generateImage({
|
|
14
23
|
model: model,
|
|
@@ -55,11 +64,12 @@ export class yetter {
|
|
|
55
64
|
return finalResponse;
|
|
56
65
|
}
|
|
57
66
|
static async stream(model, options) {
|
|
58
|
-
if (!
|
|
59
|
-
throw new Error("
|
|
67
|
+
if (!_a.apiKey) {
|
|
68
|
+
throw new Error("API key is not configured. Call yetter.configure({ apiKey: 'your_key' }) or set YTR_API_KEY.");
|
|
60
69
|
}
|
|
61
70
|
const apiClient = new YetterImageClient({
|
|
62
|
-
apiKey:
|
|
71
|
+
apiKey: _a.apiKey,
|
|
72
|
+
endpoint: _a.endpoint,
|
|
63
73
|
});
|
|
64
74
|
const initialApiResponse = await apiClient.generateImage({
|
|
65
75
|
model: model,
|
|
@@ -154,7 +164,7 @@ export class yetter {
|
|
|
154
164
|
}
|
|
155
165
|
};
|
|
156
166
|
eventSource = new EventSourcePolyfill(sseStreamUrl, {
|
|
157
|
-
headers: { 'Authorization': `${
|
|
167
|
+
headers: { 'Authorization': `${_a.apiKey}` }
|
|
158
168
|
});
|
|
159
169
|
eventSource.onopen = (event) => {
|
|
160
170
|
console.log("SSE Connection Opened:", event);
|
|
@@ -214,13 +224,16 @@ export class yetter {
|
|
|
214
224
|
}
|
|
215
225
|
}
|
|
216
226
|
_a = yetter;
|
|
227
|
+
yetter.apiKey = process.env.YTR_API_KEY || process.env.REACT_APP_YTR_API_KEY || "";
|
|
228
|
+
yetter.endpoint = "https://api.yetter.ai";
|
|
217
229
|
yetter.queue = {
|
|
218
230
|
submit: async (model, options) => {
|
|
219
|
-
if (!
|
|
220
|
-
throw new Error("
|
|
231
|
+
if (!_a.apiKey) {
|
|
232
|
+
throw new Error("API key is not configured. Call yetter.configure({ apiKey: 'your_key' }) or set YTR_API_KEY.");
|
|
221
233
|
}
|
|
222
234
|
const client = new YetterImageClient({
|
|
223
|
-
apiKey:
|
|
235
|
+
apiKey: _a.apiKey,
|
|
236
|
+
endpoint: _a.endpoint,
|
|
224
237
|
});
|
|
225
238
|
const generateResponse = await client.generateImage({
|
|
226
239
|
model: model,
|
|
@@ -229,11 +242,12 @@ yetter.queue = {
|
|
|
229
242
|
return generateResponse;
|
|
230
243
|
},
|
|
231
244
|
status: async (model, options) => {
|
|
232
|
-
if (!
|
|
233
|
-
throw new Error("
|
|
245
|
+
if (!_a.apiKey) {
|
|
246
|
+
throw new Error("API key is not configured. Call yetter.configure({ apiKey: 'your_key' }) or set YTR_API_KEY.");
|
|
234
247
|
}
|
|
235
248
|
const client = new YetterImageClient({
|
|
236
|
-
apiKey:
|
|
249
|
+
apiKey: _a.apiKey,
|
|
250
|
+
endpoint: _a.endpoint,
|
|
237
251
|
});
|
|
238
252
|
const endpoint = client.getApiEndpoint();
|
|
239
253
|
const statusUrl = `${endpoint}/${model}/requests/${options.requestId}/status`;
|
|
@@ -244,11 +258,12 @@ yetter.queue = {
|
|
|
244
258
|
};
|
|
245
259
|
},
|
|
246
260
|
result: async (model, options) => {
|
|
247
|
-
if (!
|
|
248
|
-
throw new Error("
|
|
261
|
+
if (!_a.apiKey) {
|
|
262
|
+
throw new Error("API key is not configured. Call yetter.configure({ apiKey: 'your_key' }) or set YTR_API_KEY.");
|
|
249
263
|
}
|
|
250
264
|
const client = new YetterImageClient({
|
|
251
|
-
apiKey:
|
|
265
|
+
apiKey: _a.apiKey,
|
|
266
|
+
endpoint: _a.endpoint,
|
|
252
267
|
});
|
|
253
268
|
const endpoint = client.getApiEndpoint();
|
|
254
269
|
const responseUrl = `${endpoint}/${model}/requests/${options.requestId}`;
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { YetterImageClient } from "./api.js";
|
|
2
2
|
import { EventSourcePolyfill } from 'event-source-polyfill';
|
|
3
3
|
import {
|
|
4
|
+
ClientOptions,
|
|
4
5
|
GetStatusResponse,
|
|
5
6
|
GetResponseResponse,
|
|
6
7
|
SubscribeOptions,
|
|
@@ -16,15 +17,28 @@ import {
|
|
|
16
17
|
} from "./types.js";
|
|
17
18
|
|
|
18
19
|
export class yetter {
|
|
20
|
+
private static apiKey: string = process.env.YTR_API_KEY || process.env.REACT_APP_YTR_API_KEY || "";
|
|
21
|
+
private static endpoint: string = "https://api.yetter.ai";
|
|
22
|
+
|
|
23
|
+
public static configure(options: ClientOptions) {
|
|
24
|
+
if (options.apiKey) {
|
|
25
|
+
yetter.apiKey = options.apiKey;
|
|
26
|
+
}
|
|
27
|
+
if (options.endpoint) {
|
|
28
|
+
yetter.endpoint = options.endpoint;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
19
32
|
public static async subscribe(
|
|
20
33
|
model: string,
|
|
21
34
|
options: SubscribeOptions
|
|
22
35
|
): Promise<GetResponseResponse> {
|
|
23
|
-
if (!
|
|
24
|
-
throw new Error("
|
|
36
|
+
if (!yetter.apiKey) {
|
|
37
|
+
throw new Error("API key is not configured. Call yetter.configure({ apiKey: 'your_key' }) or set YTR_API_KEY.");
|
|
25
38
|
}
|
|
26
39
|
const client = new YetterImageClient({
|
|
27
|
-
apiKey:
|
|
40
|
+
apiKey: yetter.apiKey,
|
|
41
|
+
endpoint: yetter.endpoint,
|
|
28
42
|
});
|
|
29
43
|
|
|
30
44
|
const generateResponse = await client.generateImage({
|
|
@@ -83,11 +97,12 @@ export class yetter {
|
|
|
83
97
|
model: string,
|
|
84
98
|
options: SubmitQueueOptions
|
|
85
99
|
): Promise<GenerateImageResponse> => {
|
|
86
|
-
if (!
|
|
87
|
-
throw new Error("
|
|
100
|
+
if (!yetter.apiKey) {
|
|
101
|
+
throw new Error("API key is not configured. Call yetter.configure({ apiKey: 'your_key' }) or set YTR_API_KEY.");
|
|
88
102
|
}
|
|
89
103
|
const client = new YetterImageClient({
|
|
90
|
-
apiKey:
|
|
104
|
+
apiKey: yetter.apiKey,
|
|
105
|
+
endpoint: yetter.endpoint,
|
|
91
106
|
});
|
|
92
107
|
|
|
93
108
|
const generateResponse = await client.generateImage({
|
|
@@ -102,11 +117,12 @@ export class yetter {
|
|
|
102
117
|
model: string,
|
|
103
118
|
options: StatusOptions
|
|
104
119
|
): Promise<StatusResponse> => {
|
|
105
|
-
if (!
|
|
106
|
-
throw new Error("
|
|
120
|
+
if (!yetter.apiKey) {
|
|
121
|
+
throw new Error("API key is not configured. Call yetter.configure({ apiKey: 'your_key' }) or set YTR_API_KEY.");
|
|
107
122
|
}
|
|
108
123
|
const client = new YetterImageClient({
|
|
109
|
-
apiKey:
|
|
124
|
+
apiKey: yetter.apiKey,
|
|
125
|
+
endpoint: yetter.endpoint,
|
|
110
126
|
});
|
|
111
127
|
|
|
112
128
|
const endpoint = client.getApiEndpoint();
|
|
@@ -125,11 +141,12 @@ export class yetter {
|
|
|
125
141
|
model: string,
|
|
126
142
|
options: GetResultOptions
|
|
127
143
|
): Promise<GetResultResponse> => {
|
|
128
|
-
if (!
|
|
129
|
-
throw new Error("
|
|
144
|
+
if (!yetter.apiKey) {
|
|
145
|
+
throw new Error("API key is not configured. Call yetter.configure({ apiKey: 'your_key' }) or set YTR_API_KEY.");
|
|
130
146
|
}
|
|
131
147
|
const client = new YetterImageClient({
|
|
132
|
-
apiKey:
|
|
148
|
+
apiKey: yetter.apiKey,
|
|
149
|
+
endpoint: yetter.endpoint,
|
|
133
150
|
});
|
|
134
151
|
|
|
135
152
|
const endpoint = client.getApiEndpoint();
|
|
@@ -149,11 +166,12 @@ export class yetter {
|
|
|
149
166
|
model: string,
|
|
150
167
|
options: StreamOptions
|
|
151
168
|
): Promise<YetterStream> {
|
|
152
|
-
if (!
|
|
153
|
-
throw new Error("
|
|
169
|
+
if (!yetter.apiKey) {
|
|
170
|
+
throw new Error("API key is not configured. Call yetter.configure({ apiKey: 'your_key' }) or set YTR_API_KEY.");
|
|
154
171
|
}
|
|
155
172
|
const apiClient = new YetterImageClient({
|
|
156
|
-
apiKey:
|
|
173
|
+
apiKey: yetter.apiKey,
|
|
174
|
+
endpoint: yetter.endpoint,
|
|
157
175
|
});
|
|
158
176
|
|
|
159
177
|
const initialApiResponse = await apiClient.generateImage({
|
|
@@ -249,7 +267,7 @@ export class yetter {
|
|
|
249
267
|
};
|
|
250
268
|
|
|
251
269
|
eventSource = new EventSourcePolyfill(sseStreamUrl, {
|
|
252
|
-
headers: { 'Authorization': `${
|
|
270
|
+
headers: { 'Authorization': `${yetter.apiKey}` }
|
|
253
271
|
} as any);
|
|
254
272
|
|
|
255
273
|
eventSource.onopen = (event: Event) => {
|