@yetter/client 0.0.8 → 0.0.10
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/api.d.ts +2 -2
- package/dist/api.js +1 -1
- package/dist/client.d.ts +2 -2
- package/dist/client.js +16 -8
- package/dist/types.d.ts +6 -5
- package/package.json +1 -1
- package/src/api.ts +6 -6
- package/src/client.ts +18 -12
- package/src/types.ts +6 -5
package/dist/api.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { ClientOptions,
|
|
1
|
+
import { ClientOptions, GenerateRequest, GenerateResponse, GetStatusRequest, GetStatusResponse, CancelRequest, CancelResponse, GetResponseRequest, GetResponseResponse } from "./types";
|
|
2
2
|
export declare class YetterImageClient {
|
|
3
3
|
private apiKey;
|
|
4
4
|
private endpoint;
|
|
5
5
|
constructor(options: ClientOptions);
|
|
6
6
|
getApiEndpoint(): string;
|
|
7
|
-
|
|
7
|
+
generate(body: GenerateRequest): Promise<GenerateResponse>;
|
|
8
8
|
getStatus(body: GetStatusRequest): Promise<GetStatusResponse>;
|
|
9
9
|
cancel(body: CancelRequest): Promise<CancelResponse>;
|
|
10
10
|
getResponse(body: GetResponseRequest): Promise<GetResponseResponse>;
|
package/dist/api.js
CHANGED
package/dist/client.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { ClientOptions, GetResponseResponse, SubscribeOptions,
|
|
1
|
+
import { ClientOptions, GetResponseResponse, SubscribeOptions, GenerateResponse, SubmitQueueOptions, GetResultOptions, GetResultResponse, StatusOptions, StatusResponse, StreamOptions, YetterStream } from "./types.js";
|
|
2
2
|
export declare class yetter {
|
|
3
3
|
private static apiKey;
|
|
4
4
|
private static endpoint;
|
|
5
5
|
static configure(options: ClientOptions): void;
|
|
6
6
|
static subscribe(model: string, options: SubscribeOptions): Promise<GetResponseResponse>;
|
|
7
7
|
static queue: {
|
|
8
|
-
submit: (model: string, options: SubmitQueueOptions) => Promise<
|
|
8
|
+
submit: (model: string, options: SubmitQueueOptions) => Promise<GenerateResponse>;
|
|
9
9
|
status: (model: string, options: StatusOptions) => Promise<StatusResponse>;
|
|
10
10
|
result: (model: string, options: GetResultOptions) => Promise<GetResultResponse>;
|
|
11
11
|
};
|
package/dist/client.js
CHANGED
|
@@ -24,7 +24,7 @@ export class yetter {
|
|
|
24
24
|
apiKey: _a.apiKey,
|
|
25
25
|
endpoint: _a.endpoint
|
|
26
26
|
});
|
|
27
|
-
const generateResponse = await client.
|
|
27
|
+
const generateResponse = await client.generate({
|
|
28
28
|
model: model,
|
|
29
29
|
...options.input,
|
|
30
30
|
});
|
|
@@ -76,10 +76,11 @@ export class yetter {
|
|
|
76
76
|
apiKey: _a.apiKey,
|
|
77
77
|
endpoint: _a.endpoint
|
|
78
78
|
});
|
|
79
|
-
const initialApiResponse = await client.
|
|
79
|
+
const initialApiResponse = await client.generate({
|
|
80
80
|
model: model,
|
|
81
81
|
...options.input,
|
|
82
82
|
});
|
|
83
|
+
console.timeEnd("Initial API Response");
|
|
83
84
|
const requestId = initialApiResponse.request_id;
|
|
84
85
|
const responseUrl = initialApiResponse.response_url;
|
|
85
86
|
const cancelUrl = initialApiResponse.cancel_url;
|
|
@@ -169,13 +170,14 @@ export class yetter {
|
|
|
169
170
|
}
|
|
170
171
|
};
|
|
171
172
|
eventSource = new EventSourcePolyfill(sseStreamUrl, {
|
|
172
|
-
headers: { 'Authorization': `${_a.apiKey}` }
|
|
173
|
+
headers: { 'Authorization': `${_a.apiKey}` },
|
|
174
|
+
heartbeatTimeout: 3000,
|
|
173
175
|
});
|
|
174
176
|
eventSource.onopen = (event) => {
|
|
175
177
|
console.log("SSE Connection Opened:", event);
|
|
176
178
|
};
|
|
177
179
|
eventSource.addEventListener('data', (event) => {
|
|
178
|
-
console.log("SSE 'data' event received, raw data:", event.data);
|
|
180
|
+
// console.log("SSE 'data' event received, raw data:", event.data);
|
|
179
181
|
try {
|
|
180
182
|
const statusData = JSON.parse(event.data);
|
|
181
183
|
controller.push(statusData);
|
|
@@ -186,12 +188,18 @@ export class yetter {
|
|
|
186
188
|
}
|
|
187
189
|
});
|
|
188
190
|
eventSource.addEventListener('done', (event) => {
|
|
189
|
-
console.log("SSE 'done' event received, raw data:", event.data);
|
|
191
|
+
// console.log("SSE 'done' event received, raw data:", event.data);
|
|
190
192
|
controller.close();
|
|
191
193
|
});
|
|
192
194
|
eventSource.onerror = (err) => {
|
|
193
|
-
|
|
194
|
-
|
|
195
|
+
var _b;
|
|
196
|
+
const message = ((_b = err === null || err === void 0 ? void 0 : err.error) === null || _b === void 0 ? void 0 : _b.message) || (err === null || err === void 0 ? void 0 : err.message) || '';
|
|
197
|
+
const isIdleTimeout = typeof message === 'string' && message.includes('No activity within') && message.includes('Reconnecting');
|
|
198
|
+
if (isIdleTimeout) {
|
|
199
|
+
console.warn("SSE idle timeout; letting EventSource auto-reconnect.", err);
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
console.warn("SSE Connection Error (onerror) - will allow auto-reconnect:", err);
|
|
195
203
|
};
|
|
196
204
|
// Handle if API immediately returns a terminal status in initialApiResponse (e.g. already completed/failed)
|
|
197
205
|
if (initialApiResponse.status === "COMPLETED") {
|
|
@@ -240,7 +248,7 @@ yetter.queue = {
|
|
|
240
248
|
apiKey: _a.apiKey,
|
|
241
249
|
endpoint: _a.endpoint
|
|
242
250
|
});
|
|
243
|
-
const generateResponse = await client.
|
|
251
|
+
const generateResponse = await client.generate({
|
|
244
252
|
model: model,
|
|
245
253
|
...options.input,
|
|
246
254
|
});
|
package/dist/types.d.ts
CHANGED
|
@@ -2,15 +2,16 @@ export interface ClientOptions {
|
|
|
2
2
|
apiKey: string;
|
|
3
3
|
endpoint?: string;
|
|
4
4
|
is_bearer?: boolean;
|
|
5
|
+
promptEnhancerModel?: string;
|
|
5
6
|
}
|
|
6
7
|
export interface LoraWeight {
|
|
7
8
|
path: string;
|
|
8
9
|
scale?: number;
|
|
9
10
|
}
|
|
10
|
-
export interface
|
|
11
|
+
export interface GenerateRequest {
|
|
11
12
|
[key: string]: any;
|
|
12
13
|
}
|
|
13
|
-
export interface
|
|
14
|
+
export interface GenerateResponse {
|
|
14
15
|
status: string;
|
|
15
16
|
request_id: string;
|
|
16
17
|
response_url: string;
|
|
@@ -54,12 +55,12 @@ export interface GetResponseResponse {
|
|
|
54
55
|
prompt: string;
|
|
55
56
|
}
|
|
56
57
|
export interface SubscribeOptions {
|
|
57
|
-
input: Omit<
|
|
58
|
+
input: Omit<GenerateRequest, 'model'>;
|
|
58
59
|
logs?: boolean;
|
|
59
60
|
onQueueUpdate?: (update: GetStatusResponse) => void;
|
|
60
61
|
}
|
|
61
62
|
export interface SubmitQueueOptions {
|
|
62
|
-
input: Omit<
|
|
63
|
+
input: Omit<GenerateRequest, 'model'>;
|
|
63
64
|
}
|
|
64
65
|
export interface GetResultOptions {
|
|
65
66
|
requestId: string;
|
|
@@ -76,7 +77,7 @@ export interface StatusResponse {
|
|
|
76
77
|
requestId: string;
|
|
77
78
|
}
|
|
78
79
|
export interface StreamOptions {
|
|
79
|
-
input: Omit<
|
|
80
|
+
input: Omit<GenerateRequest, 'model'>;
|
|
80
81
|
}
|
|
81
82
|
/**
|
|
82
83
|
* Represents an event received from the SSE stream.
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import fetch from "cross-fetch";
|
|
2
2
|
import {
|
|
3
3
|
ClientOptions,
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
GenerateRequest,
|
|
5
|
+
GenerateResponse,
|
|
6
6
|
GetStatusRequest,
|
|
7
7
|
GetStatusResponse,
|
|
8
8
|
CancelRequest,
|
|
@@ -27,9 +27,9 @@ export class YetterImageClient {
|
|
|
27
27
|
return this.endpoint;
|
|
28
28
|
}
|
|
29
29
|
|
|
30
|
-
public async
|
|
31
|
-
body:
|
|
32
|
-
): Promise<
|
|
30
|
+
public async generate(
|
|
31
|
+
body: GenerateRequest
|
|
32
|
+
): Promise<GenerateResponse> {
|
|
33
33
|
const url = `${this.endpoint}/${body.model}`;
|
|
34
34
|
const res = await fetch(url, {
|
|
35
35
|
method: "POST",
|
|
@@ -45,7 +45,7 @@ export class YetterImageClient {
|
|
|
45
45
|
throw new Error(`API error (${res.status}): ${errorText}`);
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
return (await res.json()) as
|
|
48
|
+
return (await res.json()) as GenerateResponse;
|
|
49
49
|
}
|
|
50
50
|
|
|
51
51
|
public async getStatus(body: GetStatusRequest): Promise<GetStatusResponse> {
|
package/src/client.ts
CHANGED
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
GetStatusResponse,
|
|
6
6
|
GetResponseResponse,
|
|
7
7
|
SubscribeOptions,
|
|
8
|
-
|
|
8
|
+
GenerateResponse,
|
|
9
9
|
SubmitQueueOptions,
|
|
10
10
|
GetResultOptions,
|
|
11
11
|
GetResultResponse,
|
|
@@ -45,7 +45,7 @@ export class yetter {
|
|
|
45
45
|
endpoint: yetter.endpoint
|
|
46
46
|
});
|
|
47
47
|
|
|
48
|
-
const generateResponse = await client.
|
|
48
|
+
const generateResponse = await client.generate({
|
|
49
49
|
model: model,
|
|
50
50
|
...options.input,
|
|
51
51
|
});
|
|
@@ -100,7 +100,7 @@ export class yetter {
|
|
|
100
100
|
submit: async (
|
|
101
101
|
model: string,
|
|
102
102
|
options: SubmitQueueOptions
|
|
103
|
-
): Promise<
|
|
103
|
+
): Promise<GenerateResponse> => {
|
|
104
104
|
if (!yetter.apiKey) {
|
|
105
105
|
throw new Error("API key is not configured. Call yetter.configure({ apiKey: 'your_key' }) or set YTR_API_KEY.");
|
|
106
106
|
}
|
|
@@ -109,7 +109,7 @@ export class yetter {
|
|
|
109
109
|
endpoint: yetter.endpoint
|
|
110
110
|
});
|
|
111
111
|
|
|
112
|
-
const generateResponse = await client.
|
|
112
|
+
const generateResponse = await client.generate({
|
|
113
113
|
model: model,
|
|
114
114
|
...options.input,
|
|
115
115
|
});
|
|
@@ -178,11 +178,11 @@ export class yetter {
|
|
|
178
178
|
endpoint: yetter.endpoint
|
|
179
179
|
});
|
|
180
180
|
|
|
181
|
-
const initialApiResponse = await client.
|
|
181
|
+
const initialApiResponse = await client.generate({
|
|
182
182
|
model: model,
|
|
183
183
|
...options.input,
|
|
184
184
|
});
|
|
185
|
-
|
|
185
|
+
console.timeEnd("Initial API Response");
|
|
186
186
|
const requestId = initialApiResponse.request_id;
|
|
187
187
|
const responseUrl = initialApiResponse.response_url;
|
|
188
188
|
const cancelUrl = initialApiResponse.cancel_url;
|
|
@@ -271,7 +271,8 @@ export class yetter {
|
|
|
271
271
|
};
|
|
272
272
|
|
|
273
273
|
eventSource = new EventSourcePolyfill(sseStreamUrl, {
|
|
274
|
-
headers: { 'Authorization': `${yetter.apiKey}` }
|
|
274
|
+
headers: { 'Authorization': `${yetter.apiKey}` },
|
|
275
|
+
heartbeatTimeout: 3000,
|
|
275
276
|
} as any);
|
|
276
277
|
|
|
277
278
|
eventSource.onopen = (event: Event) => {
|
|
@@ -279,7 +280,7 @@ export class yetter {
|
|
|
279
280
|
};
|
|
280
281
|
|
|
281
282
|
eventSource.addEventListener('data', (event: MessageEvent) => {
|
|
282
|
-
console.log("SSE 'data' event received, raw data:", event.data);
|
|
283
|
+
// console.log("SSE 'data' event received, raw data:", event.data);
|
|
283
284
|
try {
|
|
284
285
|
const statusData: GetStatusResponse = JSON.parse(event.data as string);
|
|
285
286
|
controller.push(statusData as StreamEvent);
|
|
@@ -290,15 +291,20 @@ export class yetter {
|
|
|
290
291
|
});
|
|
291
292
|
|
|
292
293
|
eventSource.addEventListener('done', (event: MessageEvent) => {
|
|
293
|
-
console.log("SSE 'done' event received, raw data:", event.data);
|
|
294
|
+
// console.log("SSE 'done' event received, raw data:", event.data);
|
|
294
295
|
controller.close();
|
|
295
296
|
});
|
|
296
297
|
|
|
297
298
|
eventSource.onerror = (err: Event | MessageEvent) => {
|
|
298
|
-
|
|
299
|
-
|
|
299
|
+
const message = (err as any)?.error?.message || (err as any)?.message || '';
|
|
300
|
+
const isIdleTimeout = typeof message === 'string' && message.includes('No activity within') && message.includes('Reconnecting');
|
|
301
|
+
if (isIdleTimeout) {
|
|
302
|
+
console.warn("SSE idle timeout; letting EventSource auto-reconnect.", err);
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
console.warn("SSE Connection Error (onerror) - will allow auto-reconnect:", err);
|
|
300
306
|
};
|
|
301
|
-
|
|
307
|
+
|
|
302
308
|
// Handle if API immediately returns a terminal status in initialApiResponse (e.g. already completed/failed)
|
|
303
309
|
if (initialApiResponse.status === "COMPLETED"){
|
|
304
310
|
controller.push(initialApiResponse as any as StreamEvent);
|
package/src/types.ts
CHANGED
|
@@ -2,6 +2,7 @@ export interface ClientOptions {
|
|
|
2
2
|
apiKey: string;
|
|
3
3
|
endpoint?: string;
|
|
4
4
|
is_bearer?: boolean;
|
|
5
|
+
promptEnhancerModel?: string;
|
|
5
6
|
}
|
|
6
7
|
|
|
7
8
|
export interface LoraWeight {
|
|
@@ -9,11 +10,11 @@ export interface LoraWeight {
|
|
|
9
10
|
scale?: number;
|
|
10
11
|
}
|
|
11
12
|
|
|
12
|
-
export interface
|
|
13
|
+
export interface GenerateRequest {
|
|
13
14
|
[key: string]: any;
|
|
14
15
|
}
|
|
15
16
|
|
|
16
|
-
export interface
|
|
17
|
+
export interface GenerateResponse {
|
|
17
18
|
status: string;
|
|
18
19
|
request_id: string;
|
|
19
20
|
response_url: string;
|
|
@@ -66,13 +67,13 @@ export interface GetResponseResponse {
|
|
|
66
67
|
}
|
|
67
68
|
|
|
68
69
|
export interface SubscribeOptions {
|
|
69
|
-
input: Omit<
|
|
70
|
+
input: Omit<GenerateRequest, 'model'>; // model is a direct param to subscribe
|
|
70
71
|
logs?: boolean;
|
|
71
72
|
onQueueUpdate?: (update: GetStatusResponse) => void;
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
export interface SubmitQueueOptions {
|
|
75
|
-
input: Omit<
|
|
76
|
+
input: Omit<GenerateRequest, 'model'>;
|
|
76
77
|
}
|
|
77
78
|
|
|
78
79
|
export interface GetResultOptions {
|
|
@@ -95,7 +96,7 @@ export interface StatusResponse {
|
|
|
95
96
|
|
|
96
97
|
// --- Stream Types ---
|
|
97
98
|
export interface StreamOptions {
|
|
98
|
-
input: Omit<
|
|
99
|
+
input: Omit<GenerateRequest, 'model'>;
|
|
99
100
|
// logs?: boolean; // Optional: if you want to request logs via stream if API supports it
|
|
100
101
|
}
|
|
101
102
|
|