@gradio/client 1.5.2 → 1.6.0-beta.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/CHANGELOG.md +24 -0
- package/dist/client.d.ts +3 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/constants.d.ts +5 -2
- package/dist/constants.d.ts.map +1 -1
- package/dist/helpers/api_info.d.ts +2 -1
- package/dist/helpers/api_info.d.ts.map +1 -1
- package/dist/helpers/init_helpers.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +89 -47
- package/dist/types.d.ts +12 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/upload.d.ts.map +1 -1
- package/dist/utils/submit.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +34 -19
- package/src/constants.ts +18 -14
- package/src/helpers/api_info.ts +25 -2
- package/src/helpers/init_helpers.ts +3 -1
- package/src/index.ts +2 -1
- package/src/test/api_info.test.ts +1 -0
- package/src/types.ts +12 -1
- package/src/upload.ts +1 -2
- package/src/utils/stream.ts +2 -2
- package/src/utils/submit.ts +33 -17
- package/src/utils/upload_files.ts +2 -2
- package/src/utils/view_api.ts +1 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,29 @@
|
|
1
1
|
# @gradio/client
|
2
2
|
|
3
|
+
## 1.6.0-beta.2
|
4
|
+
|
5
|
+
### Features
|
6
|
+
|
7
|
+
- [#9323](https://github.com/gradio-app/gradio/pull/9323) [`06babda`](https://github.com/gradio-app/gradio/commit/06babda0395fd3fbd323c1c3cb33704ecfd6deb0) - Disable liking user message in chatbot by default but make it configurable. Thanks @freddyaboulton!
|
8
|
+
- [#9339](https://github.com/gradio-app/gradio/pull/9339) [`4c8c6f2`](https://github.com/gradio-app/gradio/commit/4c8c6f2fe603081941c5fdc43f48a0632b9f31ad) - Ssr part 2. Thanks @pngwn!
|
9
|
+
|
10
|
+
### Fixes
|
11
|
+
|
12
|
+
- [#9299](https://github.com/gradio-app/gradio/pull/9299) [`aa35b07`](https://github.com/gradio-app/gradio/commit/aa35b0788e613fdd45446d267513e6f94fa208ea) - Trigger state change event on iterators. Thanks @freddyaboulton!
|
13
|
+
|
14
|
+
## 1.6.0-beta.1
|
15
|
+
|
16
|
+
### Features
|
17
|
+
|
18
|
+
- [#9200](https://github.com/gradio-app/gradio/pull/9200) [`2e179d3`](https://github.com/gradio-app/gradio/commit/2e179d35be6ed60a5a6bfc7303178d63e41781ad) - prefix api routes. Thanks @pngwn!
|
19
|
+
|
20
|
+
## 1.6.0-beta.0
|
21
|
+
|
22
|
+
### Features
|
23
|
+
|
24
|
+
- [#9149](https://github.com/gradio-app/gradio/pull/9149) [`3d7a9b8`](https://github.com/gradio-app/gradio/commit/3d7a9b81f6fef06187eca832471dc1692eb493a0) - Open audio/image input stream only when queue is ready. Thanks @freddyaboulton!
|
25
|
+
- [#8941](https://github.com/gradio-app/gradio/pull/8941) [`97a7bf6`](https://github.com/gradio-app/gradio/commit/97a7bf66a79179d1b91a3199d68e5c11216ca500) - Streaming inputs for 5.0. Thanks @freddyaboulton!
|
26
|
+
|
3
27
|
## 1.5.2
|
4
28
|
|
5
29
|
### Fixes
|
package/dist/client.d.ts
CHANGED
@@ -4,6 +4,7 @@ export declare class Client {
|
|
4
4
|
app_reference: string;
|
5
5
|
options: ClientOptions;
|
6
6
|
config: Config | undefined;
|
7
|
+
api_prefix: string;
|
7
8
|
api_info: ApiInfo<JsApiData> | undefined;
|
8
9
|
api_map: Record<string, number>;
|
9
10
|
session_hash: string;
|
@@ -20,6 +21,7 @@ export declare class Client {
|
|
20
21
|
heartbeat_event: EventSource | null;
|
21
22
|
abort_controller: AbortController | null;
|
22
23
|
stream_instance: EventSource | null;
|
24
|
+
current_payload: any;
|
23
25
|
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
24
26
|
stream(url: URL): EventSource;
|
25
27
|
view_api: () => Promise<ApiInfo<JsApiData>>;
|
@@ -37,6 +39,7 @@ export declare class Client {
|
|
37
39
|
_resolve_hearbeat(_config: Config): Promise<void>;
|
38
40
|
static connect(app_reference: string, options?: ClientOptions): Promise<Client>;
|
39
41
|
close(): void;
|
42
|
+
set_current_payload(payload: any): void;
|
40
43
|
static duplicate(app_reference: string, options?: DuplicateOptions): Promise<Client>;
|
41
44
|
private _resolve_config;
|
42
45
|
private config_success;
|
package/dist/client.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,OAAO,EACP,OAAO,EACP,aAAa,EACb,MAAM,EACN,gBAAgB,EAChB,YAAY,EACZ,SAAS,EACT,aAAa,EACb,WAAW,EACX,MAAM,EACN,cAAc,EAEd,cAAc,EACd,WAAW,EACX,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAU,QAAQ,EAAE,MAAM,UAAU,CAAC;
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,OAAO,EACP,OAAO,EACP,aAAa,EACb,MAAM,EACN,gBAAgB,EAChB,YAAY,EACZ,SAAS,EACT,aAAa,EACb,WAAW,EACX,MAAM,EACN,cAAc,EAEd,cAAc,EACd,WAAW,EACX,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAU,QAAQ,EAAE,MAAM,UAAU,CAAC;AAuB5C,qBAAa,MAAM;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,aAAa,CAAC;IAEvB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,UAAU,SAAM;IAChB,QAAQ,EAAE,OAAO,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;IACzC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAM;IACrC,YAAY,EAAE,MAAM,CAA2C;IAC/D,GAAG,EAAE,MAAM,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rB,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,gBAER,GACC,OAAO,CAAC,MAAM,CAAC;YAIJ,eAAe;YA0Cf,cAAc;IAyBtB,oBAAoB,CAAC,MAAM,EAAE,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAgC1D,gBAAgB,CAC5B,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,OAAO,EAAE,GAAG;QAAE,MAAM,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;KAAE,GAC9D,OAAO,CAAC,OAAO,CAAC;IA6EZ,WAAW,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI;IAI7C,OAAO,CAAC,kBAAkB;CAS1B;AAED;;;;;;;GAOG;AACH,wBAAsB,MAAM,CAC3B,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,aAER,GACC,OAAO,CAAC,MAAM,CAAC,CAEjB;AAED;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACpC,aAAa,EAAE,MAAM,EACrB,OAAO,EAAE,gBAAgB,GACvB,OAAO,CAAC,MAAM,CAAC,CAEjB;AAED,MAAM,MAAM,cAAc,GAAG,MAAM,CAAC"}
|
package/dist/constants.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
export declare const HOST_URL = "host";
|
2
|
-
export declare const API_URL = "
|
2
|
+
export declare const API_URL = "predict/";
|
3
3
|
export declare const SSE_URL_V0 = "queue/join";
|
4
4
|
export declare const SSE_DATA_URL_V0 = "queue/data";
|
5
5
|
export declare const SSE_URL = "queue/data";
|
@@ -10,9 +10,12 @@ export declare const CONFIG_URL = "config";
|
|
10
10
|
export declare const API_INFO_URL = "info";
|
11
11
|
export declare const RUNTIME_URL = "runtime";
|
12
12
|
export declare const SLEEPTIME_URL = "sleeptime";
|
13
|
+
export declare const HEARTBEAT_URL = "heartbeat";
|
14
|
+
export declare const COMPONENT_SERVER_URL = "component_server";
|
15
|
+
export declare const RESET_URL = "reset";
|
16
|
+
export declare const CANCEL_URL = "cancel";
|
13
17
|
export declare const RAW_API_INFO_URL = "info?serialize=False";
|
14
18
|
export declare const SPACE_FETCHER_URL = "https://gradio-space-api-fetcher-v2.hf.space/api";
|
15
|
-
export declare const RESET_URL = "reset";
|
16
19
|
export declare const SPACE_URL = "https://hf.space/{}";
|
17
20
|
export declare const QUEUE_FULL_MSG = "This application is currently busy. Please try again. ";
|
18
21
|
export declare const BROKEN_CONNECTION_MSG = "Connection errored out. ";
|
package/dist/constants.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,QAAQ,SAAS,CAAC;AAC/B,eAAO,MAAM,OAAO,
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,QAAQ,SAAS,CAAC;AAC/B,eAAO,MAAM,OAAO,aAAa,CAAC;AAClC,eAAO,MAAM,UAAU,eAAe,CAAC;AACvC,eAAO,MAAM,eAAe,eAAe,CAAC;AAC5C,eAAO,MAAM,OAAO,eAAe,CAAC;AACpC,eAAO,MAAM,YAAY,eAAe,CAAC;AACzC,eAAO,MAAM,UAAU,WAAW,CAAC;AACnC,eAAO,MAAM,SAAS,UAAU,CAAC;AACjC,eAAO,MAAM,UAAU,WAAW,CAAC;AACnC,eAAO,MAAM,YAAY,SAAS,CAAC;AACnC,eAAO,MAAM,WAAW,YAAY,CAAC;AACrC,eAAO,MAAM,aAAa,cAAc,CAAC;AACzC,eAAO,MAAM,aAAa,cAAc,CAAC;AACzC,eAAO,MAAM,oBAAoB,qBAAqB,CAAC;AACvD,eAAO,MAAM,SAAS,UAAU,CAAC;AACjC,eAAO,MAAM,UAAU,WAAW,CAAC;AAEnC,eAAO,MAAM,gBAAgB,yBAAyB,CAAC;AACvD,eAAO,MAAM,iBAAiB,qDACqB,CAAC;AACpD,eAAO,MAAM,SAAS,wBAAwB,CAAC;AAG/C,eAAO,MAAM,cAAc,2DAC8B,CAAC;AAC1D,eAAO,MAAM,qBAAqB,6BAA6B,CAAC;AAChE,eAAO,MAAM,gBAAgB,mCAAmC,CAAC;AACjE,eAAO,MAAM,sBAAsB,iCAAiC,CAAC;AACrE,eAAO,MAAM,kBAAkB,6BAA6B,CAAC;AAC7D,eAAO,MAAM,wBAAwB,yCAAyC,CAAC;AAC/E,eAAO,MAAM,eAAe,8CAA8C,CAAC;AAC3E,eAAO,MAAM,gBAAgB,0CAA0C,CAAC;AACxE,eAAO,MAAM,uBAAuB,2CAA2C,CAAC;AAChF,eAAO,MAAM,uBAAuB,yDACmB,CAAC;AACxD,eAAO,MAAM,mBAAmB,iEAC+B,CAAC;AAChE,eAAO,MAAM,kBAAkB,wCAAwC,CAAC;AACxE,eAAO,MAAM,yBAAyB,yBAAyB,CAAC"}
|
@@ -18,9 +18,10 @@ export declare function get_description(type: {
|
|
18
18
|
description: string;
|
19
19
|
}, serializer: string): string;
|
20
20
|
export declare function handle_message(data: any, last_status: Status["stage"]): {
|
21
|
-
type: "hash" | "data" | "update" | "complete" | "generating" | "log" | "none" | "heartbeat" | "unexpected_error";
|
21
|
+
type: "hash" | "data" | "update" | "complete" | "generating" | "log" | "none" | "heartbeat" | "streaming" | "unexpected_error";
|
22
22
|
data?: any;
|
23
23
|
status?: Status;
|
24
|
+
original_msg?: string;
|
24
25
|
};
|
25
26
|
/**
|
26
27
|
* Maps the provided `data` to the parameters defined by the `/info` endpoint response.
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"api_info.d.ts","sourceRoot":"","sources":["../../src/helpers/api_info.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACX,OAAO,EACP,OAAO,EACP,MAAM,EACN,SAAS,EACT,YAAY,EACZ,MAAM,EACN,MAAM,UAAU,CAAC;AAGlB,eAAO,MAAM,aAAa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AE,GACvB,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC,CAyBxB;AAED,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG;IACrD,WAAW,EAAE,IAAI,GAAG,KAAK,CAAC;IAC1B,aAAa,EAAE,OAAO,GAAG,QAAQ,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;CACb,CAiCA;AAED,eAAO,MAAM,qBAAqB,kBAAmB,MAAM,KAAG,MAAM,EAUnE,CAAC"}
|
package/dist/index.d.ts
CHANGED
@@ -4,7 +4,7 @@ export { submit } from "./utils/submit";
|
|
4
4
|
export { upload_files } from "./utils/upload_files";
|
5
5
|
export { FileData, upload, prepare_files } from "./upload";
|
6
6
|
export { handle_file } from "./helpers/data";
|
7
|
-
export type { SpaceStatus, StatusMessage, Status, client_return, UploadResponse, RenderMessage, LogMessage, Payload } from "./types";
|
7
|
+
export type { SpaceStatus, StatusMessage, Status, client_return, UploadResponse, RenderMessage, LogMessage, Payload, Config } from "./types";
|
8
8
|
export { client } from "./client";
|
9
9
|
export { duplicate_space as duplicate } from "./client";
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,YAAY,EACX,WAAW,EACX,aAAa,EACb,MAAM,EACN,aAAa,EACb,cAAc,EACd,aAAa,EACb,UAAU,EACV,OAAO,EACP,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,eAAe,IAAI,SAAS,EAAE,MAAM,UAAU,CAAC"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,OAAO,EAAE,OAAO,EAAE,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAC3D,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,YAAY,EACX,WAAW,EACX,aAAa,EACb,MAAM,EACN,aAAa,EACb,cAAc,EACd,aAAa,EACb,UAAU,EACV,OAAO,EACP,MAAM,EACN,MAAM,SAAS,CAAC;AAGjB,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,eAAe,IAAI,SAAS,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/index.js
CHANGED
@@ -29,13 +29,19 @@ function semiver(a, b, bool) {
|
|
29
29
|
b = b.split(".");
|
30
30
|
return fn(a[0], b[0]) || fn(a[1], b[1]) || (b[2] = b.slice(2).join("."), bool = /[.-]/.test(a[2] = a.slice(2).join(".")), bool == /[.-]/.test(b[2]) ? fn(a[2], b[2]) : bool ? -1 : 1);
|
31
31
|
}
|
32
|
-
const HOST_URL =
|
33
|
-
const
|
34
|
-
const
|
35
|
-
const
|
36
|
-
const
|
37
|
-
const
|
38
|
-
const
|
32
|
+
const HOST_URL = `host`;
|
33
|
+
const SSE_URL = `queue/data`;
|
34
|
+
const SSE_DATA_URL = `queue/join`;
|
35
|
+
const UPLOAD_URL = `upload`;
|
36
|
+
const LOGIN_URL = `login`;
|
37
|
+
const CONFIG_URL = `config`;
|
38
|
+
const API_INFO_URL = `info`;
|
39
|
+
const RUNTIME_URL = `runtime`;
|
40
|
+
const SLEEPTIME_URL = `sleeptime`;
|
41
|
+
const HEARTBEAT_URL = `heartbeat`;
|
42
|
+
const COMPONENT_SERVER_URL = `component_server`;
|
43
|
+
const RESET_URL = `reset`;
|
44
|
+
const CANCEL_URL = `cancel`;
|
39
45
|
const SPACE_FETCHER_URL = "https://gradio-space-api-fetcher-v2.hf.space/api";
|
40
46
|
const QUEUE_FULL_MSG = "This application is currently busy. Please try again. ";
|
41
47
|
const BROKEN_CONNECTION_MSG = "Connection errored out. ";
|
@@ -90,6 +96,7 @@ async function resolve_config(endpoint) {
|
|
90
96
|
return { ...config, path };
|
91
97
|
} else if (endpoint) {
|
92
98
|
const config_url = join_urls(endpoint, CONFIG_URL);
|
99
|
+
console.log("config_url", config_url);
|
93
100
|
const response = await this.fetch(config_url, {
|
94
101
|
headers,
|
95
102
|
credentials: "include"
|
@@ -185,7 +192,7 @@ function determine_protocol(endpoint) {
|
|
185
192
|
return {
|
186
193
|
ws_protocol: "wss",
|
187
194
|
http_protocol: "https:",
|
188
|
-
host: endpoint
|
195
|
+
host: new URL(endpoint).host
|
189
196
|
};
|
190
197
|
}
|
191
198
|
const parse_and_set_cookies = (cookie_header) => {
|
@@ -202,6 +209,7 @@ const parse_and_set_cookies = (cookie_header) => {
|
|
202
209
|
const RE_SPACE_NAME = /^[a-zA-Z0-9_\-\.]+\/[a-zA-Z0-9_\-\.]+$/;
|
203
210
|
const RE_SPACE_DOMAIN = /.*hf\.space\/{0,1}$/;
|
204
211
|
async function process_endpoint(app_reference, hf_token) {
|
212
|
+
console.log("app_reference", app_reference);
|
205
213
|
const headers = {};
|
206
214
|
if (hf_token) {
|
207
215
|
headers.Authorization = `Bearer ${hf_token}`;
|
@@ -231,6 +239,7 @@ async function process_endpoint(app_reference, hf_token) {
|
|
231
239
|
host
|
232
240
|
};
|
233
241
|
}
|
242
|
+
console.log("app_reference", _app_reference);
|
234
243
|
return {
|
235
244
|
space_id: false,
|
236
245
|
...determine_protocol(_app_reference)
|
@@ -408,10 +417,25 @@ function handle_message(data, last_status) {
|
|
408
417
|
stage: data.success ? "generating" : "error",
|
409
418
|
code: data.code,
|
410
419
|
progress_data: data.progress_data,
|
411
|
-
eta: data.average_duration
|
420
|
+
eta: data.average_duration,
|
421
|
+
changed_state_ids: data.success ? data.output.changed_state_ids : void 0
|
412
422
|
},
|
413
423
|
data: data.success ? data.output : null
|
414
424
|
};
|
425
|
+
case "process_streaming":
|
426
|
+
return {
|
427
|
+
type: "streaming",
|
428
|
+
status: {
|
429
|
+
queue,
|
430
|
+
message: data.output.error,
|
431
|
+
stage: "streaming",
|
432
|
+
time_limit: data.time_limit,
|
433
|
+
code: data.code,
|
434
|
+
progress_data: data.progress_data,
|
435
|
+
eta: data.eta
|
436
|
+
},
|
437
|
+
data: data.output
|
438
|
+
};
|
415
439
|
case "process_completed":
|
416
440
|
if ("error" in data.output) {
|
417
441
|
return {
|
@@ -450,7 +474,8 @@ function handle_message(data, last_status) {
|
|
450
474
|
position: 0,
|
451
475
|
success: data.success,
|
452
476
|
eta: data.eta
|
453
|
-
}
|
477
|
+
},
|
478
|
+
original_msg: "process_starts"
|
454
479
|
};
|
455
480
|
}
|
456
481
|
return { type: "none", status: { stage: "error", queue } };
|
@@ -521,7 +546,7 @@ async function view_api() {
|
|
521
546
|
credentials: "include"
|
522
547
|
});
|
523
548
|
} else {
|
524
|
-
const url = join_urls(config.root, API_INFO_URL);
|
549
|
+
const url = join_urls(config.root, this.api_prefix, API_INFO_URL);
|
525
550
|
response = await this.fetch(url, {
|
526
551
|
headers,
|
527
552
|
credentials: "include"
|
@@ -559,7 +584,7 @@ async function upload_files(root_url, files, upload_id) {
|
|
559
584
|
formData.append("files", file);
|
560
585
|
});
|
561
586
|
try {
|
562
|
-
const upload_url = upload_id ? `${root_url}/${UPLOAD_URL}?upload_id=${upload_id}` : `${root_url}/${UPLOAD_URL}`;
|
587
|
+
const upload_url = upload_id ? `${root_url}${this.api_prefix}/${UPLOAD_URL}?upload_id=${upload_id}` : `${root_url}${this.api_prefix}/${UPLOAD_URL}`;
|
563
588
|
response = await this.fetch(upload_url, {
|
564
589
|
method: "POST",
|
565
590
|
body: formData,
|
@@ -603,7 +628,7 @@ async function upload(file_data, root_url, upload_id, max_file_size) {
|
|
603
628
|
const file = new FileData({
|
604
629
|
...file_data[i],
|
605
630
|
path: f,
|
606
|
-
url: root_url
|
631
|
+
url: `${root_url}${this.api_prefix}/file=${f}`
|
607
632
|
});
|
608
633
|
return file;
|
609
634
|
});
|
@@ -1356,7 +1381,7 @@ async function open_stream() {
|
|
1356
1381
|
let params = new URLSearchParams({
|
1357
1382
|
session_hash: this.session_hash
|
1358
1383
|
}).toString();
|
1359
|
-
let url = new URL(`${config.root}
|
1384
|
+
let url = new URL(`${config.root}${this.api_prefix}/${SSE_URL}?${params}`);
|
1360
1385
|
if (jwt) {
|
1361
1386
|
url.searchParams.set("__sign", jwt);
|
1362
1387
|
}
|
@@ -1565,7 +1590,8 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events) {
|
|
1565
1590
|
event_callbacks,
|
1566
1591
|
unclosed_events,
|
1567
1592
|
post_data: post_data2,
|
1568
|
-
options
|
1593
|
+
options,
|
1594
|
+
api_prefix
|
1569
1595
|
} = this;
|
1570
1596
|
const that = this;
|
1571
1597
|
if (!api_info)
|
@@ -1582,6 +1608,8 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events) {
|
|
1582
1608
|
let websocket;
|
1583
1609
|
let stream2;
|
1584
1610
|
let protocol = config.protocol ?? "ws";
|
1611
|
+
let event_id_final = "";
|
1612
|
+
let event_id_cb = () => event_id_final;
|
1585
1613
|
const _endpoint = typeof endpoint === "number" ? "/predict" : endpoint;
|
1586
1614
|
let payload;
|
1587
1615
|
let event_id = null;
|
@@ -1630,13 +1658,13 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events) {
|
|
1630
1658
|
throw new Error("Could not resolve app config");
|
1631
1659
|
}
|
1632
1660
|
if ("event_id" in cancel_request) {
|
1633
|
-
await fetch2(`${config.root}
|
1661
|
+
await fetch2(`${config.root}${api_prefix}/${CANCEL_URL}`, {
|
1634
1662
|
headers: { "Content-Type": "application/json" },
|
1635
1663
|
method: "POST",
|
1636
1664
|
body: JSON.stringify(cancel_request)
|
1637
1665
|
});
|
1638
1666
|
}
|
1639
|
-
await fetch2(`${config.root}
|
1667
|
+
await fetch2(`${config.root}${api_prefix}/${RESET_URL}`, {
|
1640
1668
|
headers: { "Content-Type": "application/json" },
|
1641
1669
|
method: "POST",
|
1642
1670
|
body: JSON.stringify(reset_request)
|
@@ -1701,7 +1729,7 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events) {
|
|
1701
1729
|
time: /* @__PURE__ */ new Date()
|
1702
1730
|
});
|
1703
1731
|
post_data2(
|
1704
|
-
`${config.root}/run${_endpoint.startsWith("/") ? _endpoint : `/${_endpoint}`}${url_params ? "?" + url_params : ""}`,
|
1732
|
+
`${config.root}${api_prefix}/run${_endpoint.startsWith("/") ? _endpoint : `/${_endpoint}`}${url_params ? "?" + url_params : ""}`,
|
1705
1733
|
{
|
1706
1734
|
...payload,
|
1707
1735
|
session_hash
|
@@ -1891,7 +1919,7 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events) {
|
|
1891
1919
|
session_hash
|
1892
1920
|
}).toString();
|
1893
1921
|
let url = new URL(
|
1894
|
-
`${config.root}
|
1922
|
+
`${config.root}${api_prefix}/${SSE_URL}?${url_params ? url_params + "&" : ""}${params}`
|
1895
1923
|
);
|
1896
1924
|
if (this.jwt) {
|
1897
1925
|
url.searchParams.set("__sign", this.jwt);
|
@@ -1921,12 +1949,14 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events) {
|
|
1921
1949
|
close();
|
1922
1950
|
}
|
1923
1951
|
} else if (type === "data") {
|
1924
|
-
|
1925
|
-
|
1926
|
-
|
1927
|
-
|
1928
|
-
|
1929
|
-
|
1952
|
+
let [_, status2] = await post_data2(
|
1953
|
+
`${config.root}${api_prefix}/queue/data`,
|
1954
|
+
{
|
1955
|
+
...payload,
|
1956
|
+
session_hash,
|
1957
|
+
event_id
|
1958
|
+
}
|
1959
|
+
);
|
1930
1960
|
if (status2 !== 200) {
|
1931
1961
|
fire_event({
|
1932
1962
|
type: "status",
|
@@ -1952,7 +1982,7 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events) {
|
|
1952
1982
|
visible: data2.visible,
|
1953
1983
|
fn_index
|
1954
1984
|
});
|
1955
|
-
} else if (type === "generating") {
|
1985
|
+
} else if (type === "generating" || type === "streaming") {
|
1956
1986
|
fire_event({
|
1957
1987
|
type: "status",
|
1958
1988
|
time: /* @__PURE__ */ new Date(),
|
@@ -2014,7 +2044,7 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events) {
|
|
2014
2044
|
const zerogpu_auth_promise = is_iframe && is_zerogpu_space ? post_message("zerogpu-headers", origin) : Promise.resolve(null);
|
2015
2045
|
const post_data_promise = zerogpu_auth_promise.then((headers) => {
|
2016
2046
|
return post_data2(
|
2017
|
-
`${config.root}
|
2047
|
+
`${config.root}${api_prefix}/${SSE_DATA_URL}?${url_params}`,
|
2018
2048
|
{
|
2019
2049
|
...payload,
|
2020
2050
|
session_hash
|
@@ -2045,9 +2075,10 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events) {
|
|
2045
2075
|
});
|
2046
2076
|
} else {
|
2047
2077
|
event_id = response.event_id;
|
2078
|
+
event_id_final = event_id;
|
2048
2079
|
let callback = async function(_data) {
|
2049
2080
|
try {
|
2050
|
-
const { type, status: status2, data: data2 } = handle_message(
|
2081
|
+
const { type, status: status2, data: data2, original_msg } = handle_message(
|
2051
2082
|
_data,
|
2052
2083
|
last_status[fn_index]
|
2053
2084
|
);
|
@@ -2060,6 +2091,7 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events) {
|
|
2060
2091
|
endpoint: _endpoint,
|
2061
2092
|
fn_index,
|
2062
2093
|
time: /* @__PURE__ */ new Date(),
|
2094
|
+
original_msg,
|
2063
2095
|
...status2
|
2064
2096
|
});
|
2065
2097
|
} else if (type === "complete") {
|
@@ -2086,7 +2118,7 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events) {
|
|
2086
2118
|
fn_index
|
2087
2119
|
});
|
2088
2120
|
return;
|
2089
|
-
} else if (type === "generating") {
|
2121
|
+
} else if (type === "generating" || type === "streaming") {
|
2090
2122
|
fire_event({
|
2091
2123
|
type: "status",
|
2092
2124
|
time: /* @__PURE__ */ new Date(),
|
@@ -2096,7 +2128,7 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events) {
|
|
2096
2128
|
endpoint: _endpoint,
|
2097
2129
|
fn_index
|
2098
2130
|
});
|
2099
|
-
if (data2 && ["sse_v2", "sse_v2.1", "sse_v3"].includes(protocol)) {
|
2131
|
+
if (data2 && dependency.connection !== "stream" && ["sse_v2", "sse_v2.1", "sse_v3"].includes(protocol)) {
|
2100
2132
|
apply_diff_stream(pending_diff_streams, event_id, data2);
|
2101
2133
|
}
|
2102
2134
|
}
|
@@ -2186,7 +2218,8 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events) {
|
|
2186
2218
|
close();
|
2187
2219
|
return next();
|
2188
2220
|
},
|
2189
|
-
cancel
|
2221
|
+
cancel,
|
2222
|
+
event_id: event_id_cb
|
2190
2223
|
};
|
2191
2224
|
return iterator;
|
2192
2225
|
} catch (error) {
|
@@ -2227,6 +2260,7 @@ class Client {
|
|
2227
2260
|
__publicField(this, "app_reference");
|
2228
2261
|
__publicField(this, "options");
|
2229
2262
|
__publicField(this, "config");
|
2263
|
+
__publicField(this, "api_prefix", "");
|
2230
2264
|
__publicField(this, "api_info");
|
2231
2265
|
__publicField(this, "api_map", {});
|
2232
2266
|
__publicField(this, "session_hash", Math.random().toString(36).substring(2));
|
@@ -2242,6 +2276,7 @@ class Client {
|
|
2242
2276
|
__publicField(this, "heartbeat_event", null);
|
2243
2277
|
__publicField(this, "abort_controller", null);
|
2244
2278
|
__publicField(this, "stream_instance", null);
|
2279
|
+
__publicField(this, "current_payload");
|
2245
2280
|
__publicField(this, "view_api");
|
2246
2281
|
__publicField(this, "upload_files");
|
2247
2282
|
__publicField(this, "upload");
|
@@ -2257,6 +2292,7 @@ class Client {
|
|
2257
2292
|
options.events = ["data"];
|
2258
2293
|
}
|
2259
2294
|
this.options = options;
|
2295
|
+
this.current_payload = {};
|
2260
2296
|
this.view_api = view_api.bind(this);
|
2261
2297
|
this.upload_files = upload_files.bind(this);
|
2262
2298
|
this.handle_blob = handle_blob.bind(this);
|
@@ -2297,22 +2333,19 @@ class Client {
|
|
2297
2333
|
const ws = await import("./wrapper-CviSselG.js");
|
2298
2334
|
global.WebSocket = ws.WebSocket;
|
2299
2335
|
}
|
2300
|
-
|
2301
|
-
|
2302
|
-
await this.resolve_cookies();
|
2303
|
-
}
|
2304
|
-
await this._resolve_config().then(
|
2305
|
-
({ config }) => this._resolve_hearbeat(config)
|
2306
|
-
);
|
2307
|
-
} catch (e) {
|
2308
|
-
throw Error(e);
|
2336
|
+
if (this.options.auth) {
|
2337
|
+
await this.resolve_cookies();
|
2309
2338
|
}
|
2339
|
+
await this._resolve_config().then(
|
2340
|
+
({ config }) => this._resolve_hearbeat(config)
|
2341
|
+
);
|
2310
2342
|
this.api_info = await this.view_api();
|
2311
2343
|
this.api_map = map_names_to_ids(((_a = this.config) == null ? void 0 : _a.dependencies) || []);
|
2312
2344
|
}
|
2313
2345
|
async _resolve_hearbeat(_config) {
|
2314
2346
|
if (_config) {
|
2315
2347
|
this.config = _config;
|
2348
|
+
this.api_prefix = _config.api_prefix || "";
|
2316
2349
|
if (this.config && this.config.connect_heartbeat) {
|
2317
2350
|
if (this.config.space_id && this.options.hf_token) {
|
2318
2351
|
this.jwt = await get_jwt(
|
@@ -2328,7 +2361,7 @@ class Client {
|
|
2328
2361
|
}
|
2329
2362
|
if (this.config && this.config.connect_heartbeat) {
|
2330
2363
|
const heartbeat_url = new URL(
|
2331
|
-
`${this.config.root}
|
2364
|
+
`${this.config.root}${this.api_prefix}/${HEARTBEAT_URL}/${this.session_hash}`
|
2332
2365
|
);
|
2333
2366
|
if (this.jwt) {
|
2334
2367
|
heartbeat_url.searchParams.set("__sign", this.jwt);
|
@@ -2348,6 +2381,9 @@ class Client {
|
|
2348
2381
|
close() {
|
2349
2382
|
close_stream(this.stream_status, this.abort_controller);
|
2350
2383
|
}
|
2384
|
+
set_current_payload(payload) {
|
2385
|
+
this.current_payload = payload;
|
2386
|
+
}
|
2351
2387
|
static async duplicate(app_reference, options = {
|
2352
2388
|
events: ["data"]
|
2353
2389
|
}) {
|
@@ -2390,6 +2426,7 @@ class Client {
|
|
2390
2426
|
}
|
2391
2427
|
async config_success(_config) {
|
2392
2428
|
this.config = _config;
|
2429
|
+
this.api_prefix = _config.api_prefix || "";
|
2393
2430
|
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
2394
2431
|
if (window.location.protocol === "https:") {
|
2395
2432
|
this.config.root = this.config.root.replace("http://", "https://");
|
@@ -2406,6 +2443,7 @@ class Client {
|
|
2406
2443
|
return this.prepare_return_obj();
|
2407
2444
|
}
|
2408
2445
|
async handle_space_success(status) {
|
2446
|
+
var _a;
|
2409
2447
|
if (!this) {
|
2410
2448
|
throw new Error(CONFIG_ERROR_MSG);
|
2411
2449
|
}
|
@@ -2415,6 +2453,7 @@ class Client {
|
|
2415
2453
|
if (status.status === "running") {
|
2416
2454
|
try {
|
2417
2455
|
this.config = await this._resolve_config();
|
2456
|
+
this.api_prefix = ((_a = this == null ? void 0 : this.config) == null ? void 0 : _a.api_prefix) || "";
|
2418
2457
|
if (!this.config) {
|
2419
2458
|
throw new Error(CONFIG_ERROR_MSG);
|
2420
2459
|
}
|
@@ -2477,12 +2516,15 @@ class Client {
|
|
2477
2516
|
headers.Authorization = `Bearer ${hf_token}`;
|
2478
2517
|
}
|
2479
2518
|
try {
|
2480
|
-
const response = await this.fetch(
|
2481
|
-
|
2482
|
-
|
2483
|
-
|
2484
|
-
|
2485
|
-
|
2519
|
+
const response = await this.fetch(
|
2520
|
+
`${root_url}${this.api_prefix}/${COMPONENT_SERVER_URL}/`,
|
2521
|
+
{
|
2522
|
+
method: "POST",
|
2523
|
+
body,
|
2524
|
+
headers,
|
2525
|
+
credentials: "include"
|
2526
|
+
}
|
2527
|
+
);
|
2486
2528
|
if (!response.ok) {
|
2487
2529
|
throw new Error(
|
2488
2530
|
"Could not connect to component server: " + response.statusText
|
package/dist/types.d.ts
CHANGED
@@ -76,6 +76,7 @@ export type client_return = {
|
|
76
76
|
export interface SubmitIterable<T> extends AsyncIterable<T> {
|
77
77
|
[Symbol.asyncIterator](): AsyncIterator<T>;
|
78
78
|
cancel: () => Promise<void>;
|
79
|
+
event_id: () => string;
|
79
80
|
}
|
80
81
|
export type PredictReturn = {
|
81
82
|
type: EventType;
|
@@ -129,6 +130,9 @@ export interface Config {
|
|
129
130
|
max_file_size?: number;
|
130
131
|
theme_hash?: number;
|
131
132
|
username: string | null;
|
133
|
+
api_prefix?: string;
|
134
|
+
fill_height?: boolean;
|
135
|
+
fill_width?: boolean;
|
132
136
|
}
|
133
137
|
export interface ComponentMeta {
|
134
138
|
type: string;
|
@@ -192,6 +196,11 @@ export interface Dependency {
|
|
192
196
|
show_api: boolean;
|
193
197
|
zerogpu?: boolean;
|
194
198
|
rendered_in: number | null;
|
199
|
+
connection: "stream" | "sse";
|
200
|
+
time_limit: number;
|
201
|
+
stream_every: number;
|
202
|
+
like_user_message: boolean;
|
203
|
+
event_specific_args: string[];
|
195
204
|
}
|
196
205
|
export interface DependencyTypes {
|
197
206
|
generator: boolean;
|
@@ -260,7 +269,7 @@ export interface Status {
|
|
260
269
|
queue: boolean;
|
261
270
|
code?: string;
|
262
271
|
success?: boolean;
|
263
|
-
stage: "pending" | "error" | "complete" | "generating";
|
272
|
+
stage: "pending" | "error" | "complete" | "generating" | "streaming";
|
264
273
|
duration?: number;
|
265
274
|
visible?: boolean;
|
266
275
|
broken?: boolean;
|
@@ -277,11 +286,13 @@ export interface Status {
|
|
277
286
|
}[];
|
278
287
|
time?: Date;
|
279
288
|
changed_state_ids?: number[];
|
289
|
+
time_limit?: number;
|
280
290
|
}
|
281
291
|
export interface StatusMessage extends Status {
|
282
292
|
type: "status";
|
283
293
|
endpoint: string;
|
284
294
|
fn_index: number;
|
295
|
+
original_msg?: string;
|
285
296
|
}
|
286
297
|
export interface PayloadMessage extends Payload {
|
287
298
|
type: "data";
|
package/dist/types.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,QAAQ,CAAC;AAC9C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AAE5C,MAAM,WAAW,OAAO;IACvB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,GAAG,CAAC;IACxB,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAChC,IAAI,EAAE;QACL,IAAI,EAAE,GAAG,CAAC;QACV,WAAW,EAAE,MAAM,CAAC;KACpB,CAAC;IACF,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,CAAC,EAAE,GAAG,CAAC;IACpB,WAAW,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,WAAW,EAAE,MAAM,CAAA;KAAE,CAAC;IACnD,UAAU,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,SAAS;IACzB,KAAK,EAAE,MAAM,CAAC;IACd,cAAc,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,GAAG,CAAC;IACxB,qBAAqB,CAA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+1 @@
|
|
1
|
-
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../src/upload.ts"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"upload.d.ts","sourceRoot":"","sources":["../src/upload.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAEvC,wBAAsB,MAAM,CAC3B,IAAI,EAAE,MAAM,EACZ,SAAS,EAAE,QAAQ,EAAE,EACrB,QAAQ,EAAE,MAAM,EAChB,SAAS,CAAC,EAAE,MAAM,EAClB,aAAa,CAAC,EAAE,MAAM,GACpB,OAAO,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,CAsCrC;AAED,wBAAsB,aAAa,CAClC,KAAK,EAAE,IAAI,EAAE,EACb,SAAS,CAAC,EAAE,OAAO,GACjB,OAAO,CAAC,QAAQ,EAAE,CAAC,CAYrB;AAED,qBAAa,QAAQ;IACpB,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,IAAI;;MAAgC;gBAEjC,EACX,IAAI,EACJ,GAAG,EACH,SAAS,EACT,IAAI,EACJ,IAAI,EACJ,SAAS,EACT,SAAS,EACT,QAAQ,EACR,EAAE;QACF,IAAI,EAAE,MAAM,CAAC;QACb,GAAG,CAAC,EAAE,MAAM,CAAC;QACb,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,IAAI,CAAC,EAAE,MAAM,CAAC;QACd,IAAI,CAAC,EAAE,IAAI,CAAC;QACZ,SAAS,CAAC,EAAE,OAAO,CAAC;QACpB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;KAClB;CAUD"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"submit.d.ts","sourceRoot":"","sources":["../../src/utils/submit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGX,WAAW,EAMX,cAAc,EACd,MAAM,UAAU,CAAC;
|
1
|
+
{"version":3,"file":"submit.d.ts","sourceRoot":"","sources":["../../src/utils/submit.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAGX,WAAW,EAMX,cAAc,EACd,MAAM,UAAU,CAAC;AAmBlB,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAEnC,wBAAgB,MAAM,CACrB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GAAG,MAAM,EACzB,IAAI,GAAE,OAAO,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EAC9C,UAAU,CAAC,EAAE,OAAO,EACpB,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,EAC1B,UAAU,CAAC,EAAE,OAAO,GAClB,cAAc,CAAC,WAAW,CAAC,CAywB7B"}
|
package/package.json
CHANGED
package/src/client.ts
CHANGED
@@ -32,13 +32,19 @@ import {
|
|
32
32
|
} from "./helpers/init_helpers";
|
33
33
|
import { check_and_wake_space, check_space_status } from "./helpers/spaces";
|
34
34
|
import { open_stream, readable_stream, close_stream } from "./utils/stream";
|
35
|
-
import {
|
35
|
+
import {
|
36
|
+
API_INFO_ERROR_MSG,
|
37
|
+
CONFIG_ERROR_MSG,
|
38
|
+
HEARTBEAT_URL,
|
39
|
+
COMPONENT_SERVER_URL
|
40
|
+
} from "./constants";
|
36
41
|
|
37
42
|
export class Client {
|
38
43
|
app_reference: string;
|
39
44
|
options: ClientOptions;
|
40
45
|
|
41
46
|
config: Config | undefined;
|
47
|
+
api_prefix = "";
|
42
48
|
api_info: ApiInfo<JsApiData> | undefined;
|
43
49
|
api_map: Record<string, number> = {};
|
44
50
|
session_hash: string = Math.random().toString(36).substring(2);
|
@@ -56,6 +62,7 @@ export class Client {
|
|
56
62
|
heartbeat_event: EventSource | null = null;
|
57
63
|
abort_controller: AbortController | null = null;
|
58
64
|
stream_instance: EventSource | null = null;
|
65
|
+
current_payload: any;
|
59
66
|
|
60
67
|
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response> {
|
61
68
|
const headers = new Headers(init?.headers || {});
|
@@ -130,7 +137,7 @@ export class Client {
|
|
130
137
|
}
|
131
138
|
|
132
139
|
this.options = options;
|
133
|
-
|
140
|
+
this.current_payload = {};
|
134
141
|
this.view_api = view_api.bind(this);
|
135
142
|
this.upload_files = upload_files.bind(this);
|
136
143
|
this.handle_blob = handle_blob.bind(this);
|
@@ -155,18 +162,14 @@ export class Client {
|
|
155
162
|
global.WebSocket = ws.WebSocket as unknown as typeof WebSocket;
|
156
163
|
}
|
157
164
|
|
158
|
-
|
159
|
-
|
160
|
-
await this.resolve_cookies();
|
161
|
-
}
|
162
|
-
|
163
|
-
await this._resolve_config().then(({ config }) =>
|
164
|
-
this._resolve_hearbeat(config)
|
165
|
-
);
|
166
|
-
} catch (e: any) {
|
167
|
-
throw Error(e);
|
165
|
+
if (this.options.auth) {
|
166
|
+
await this.resolve_cookies();
|
168
167
|
}
|
169
168
|
|
169
|
+
await this._resolve_config().then(({ config }) =>
|
170
|
+
this._resolve_hearbeat(config)
|
171
|
+
);
|
172
|
+
|
170
173
|
this.api_info = await this.view_api();
|
171
174
|
this.api_map = map_names_to_ids(this.config?.dependencies || []);
|
172
175
|
}
|
@@ -174,6 +177,8 @@ export class Client {
|
|
174
177
|
async _resolve_hearbeat(_config: Config): Promise<void> {
|
175
178
|
if (_config) {
|
176
179
|
this.config = _config;
|
180
|
+
this.api_prefix = _config.api_prefix || "";
|
181
|
+
|
177
182
|
if (this.config && this.config.connect_heartbeat) {
|
178
183
|
if (this.config.space_id && this.options.hf_token) {
|
179
184
|
this.jwt = await get_jwt(
|
@@ -192,7 +197,7 @@ export class Client {
|
|
192
197
|
if (this.config && this.config.connect_heartbeat) {
|
193
198
|
// connect to the heartbeat endpoint via GET request
|
194
199
|
const heartbeat_url = new URL(
|
195
|
-
`${this.config.root}
|
200
|
+
`${this.config.root}${this.api_prefix}/${HEARTBEAT_URL}/${this.session_hash}`
|
196
201
|
);
|
197
202
|
|
198
203
|
// if the jwt is available, add it to the query params
|
@@ -222,6 +227,10 @@ export class Client {
|
|
222
227
|
close_stream(this.stream_status, this.abort_controller);
|
223
228
|
}
|
224
229
|
|
230
|
+
set_current_payload(payload: any): void {
|
231
|
+
this.current_payload = payload;
|
232
|
+
}
|
233
|
+
|
225
234
|
static async duplicate(
|
226
235
|
app_reference: string,
|
227
236
|
options: DuplicateOptions = {
|
@@ -277,6 +286,7 @@ export class Client {
|
|
277
286
|
_config: Config
|
278
287
|
): Promise<Config | client_return> {
|
279
288
|
this.config = _config;
|
289
|
+
this.api_prefix = _config.api_prefix || "";
|
280
290
|
|
281
291
|
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
282
292
|
if (window.location.protocol === "https:") {
|
@@ -306,6 +316,8 @@ export class Client {
|
|
306
316
|
if (status.status === "running") {
|
307
317
|
try {
|
308
318
|
this.config = await this._resolve_config();
|
319
|
+
this.api_prefix = this?.config?.api_prefix || "";
|
320
|
+
|
309
321
|
if (!this.config) {
|
310
322
|
throw new Error(CONFIG_ERROR_MSG);
|
311
323
|
}
|
@@ -385,12 +397,15 @@ export class Client {
|
|
385
397
|
}
|
386
398
|
|
387
399
|
try {
|
388
|
-
const response = await this.fetch(
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
400
|
+
const response = await this.fetch(
|
401
|
+
`${root_url}${this.api_prefix}/${COMPONENT_SERVER_URL}/`,
|
402
|
+
{
|
403
|
+
method: "POST",
|
404
|
+
body: body,
|
405
|
+
headers,
|
406
|
+
credentials: "include"
|
407
|
+
}
|
408
|
+
);
|
394
409
|
|
395
410
|
if (!response.ok) {
|
396
411
|
throw new Error(
|
package/src/constants.ts
CHANGED
@@ -1,20 +1,24 @@
|
|
1
1
|
// endpoints
|
2
|
-
export const HOST_URL =
|
3
|
-
export const API_URL =
|
4
|
-
export const SSE_URL_V0 =
|
5
|
-
export const SSE_DATA_URL_V0 =
|
6
|
-
export const SSE_URL =
|
7
|
-
export const SSE_DATA_URL =
|
8
|
-
export const UPLOAD_URL =
|
9
|
-
export const LOGIN_URL =
|
10
|
-
export const CONFIG_URL =
|
11
|
-
export const API_INFO_URL =
|
12
|
-
export const RUNTIME_URL =
|
13
|
-
export const SLEEPTIME_URL =
|
14
|
-
export const
|
2
|
+
export const HOST_URL = `host`;
|
3
|
+
export const API_URL = `predict/`;
|
4
|
+
export const SSE_URL_V0 = `queue/join`;
|
5
|
+
export const SSE_DATA_URL_V0 = `queue/data`;
|
6
|
+
export const SSE_URL = `queue/data`;
|
7
|
+
export const SSE_DATA_URL = `queue/join`;
|
8
|
+
export const UPLOAD_URL = `upload`;
|
9
|
+
export const LOGIN_URL = `login`;
|
10
|
+
export const CONFIG_URL = `config`;
|
11
|
+
export const API_INFO_URL = `info`;
|
12
|
+
export const RUNTIME_URL = `runtime`;
|
13
|
+
export const SLEEPTIME_URL = `sleeptime`;
|
14
|
+
export const HEARTBEAT_URL = `heartbeat`;
|
15
|
+
export const COMPONENT_SERVER_URL = `component_server`;
|
16
|
+
export const RESET_URL = `reset`;
|
17
|
+
export const CANCEL_URL = `cancel`;
|
18
|
+
|
19
|
+
export const RAW_API_INFO_URL = `info?serialize=False`;
|
15
20
|
export const SPACE_FETCHER_URL =
|
16
21
|
"https://gradio-space-api-fetcher-v2.hf.space/api";
|
17
|
-
export const RESET_URL = "reset";
|
18
22
|
export const SPACE_URL = "https://hf.space/{}";
|
19
23
|
|
20
24
|
// messages
|
package/src/helpers/api_info.ts
CHANGED
@@ -26,6 +26,7 @@ export async function process_endpoint(
|
|
26
26
|
ws_protocol: "ws" | "wss";
|
27
27
|
http_protocol: "http:" | "https:";
|
28
28
|
}> {
|
29
|
+
console.log("app_reference", app_reference);
|
29
30
|
const headers: { Authorization?: string } = {};
|
30
31
|
if (hf_token) {
|
31
32
|
headers.Authorization = `Bearer ${hf_token}`;
|
@@ -65,6 +66,8 @@ export async function process_endpoint(
|
|
65
66
|
};
|
66
67
|
}
|
67
68
|
|
69
|
+
console.log("app_reference", _app_reference);
|
70
|
+
|
68
71
|
return {
|
69
72
|
space_id: false,
|
70
73
|
...determine_protocol(_app_reference)
|
@@ -243,9 +246,11 @@ export function handle_message(
|
|
243
246
|
| "log"
|
244
247
|
| "none"
|
245
248
|
| "heartbeat"
|
249
|
+
| "streaming"
|
246
250
|
| "unexpected_error";
|
247
251
|
data?: any;
|
248
252
|
status?: Status;
|
253
|
+
original_msg?: string;
|
249
254
|
} {
|
250
255
|
const queue = true;
|
251
256
|
switch (data.msg) {
|
@@ -313,10 +318,27 @@ export function handle_message(
|
|
313
318
|
stage: data.success ? "generating" : "error",
|
314
319
|
code: data.code,
|
315
320
|
progress_data: data.progress_data,
|
316
|
-
eta: data.average_duration
|
321
|
+
eta: data.average_duration,
|
322
|
+
changed_state_ids: data.success
|
323
|
+
? data.output.changed_state_ids
|
324
|
+
: undefined
|
317
325
|
},
|
318
326
|
data: data.success ? data.output : null
|
319
327
|
};
|
328
|
+
case "process_streaming":
|
329
|
+
return {
|
330
|
+
type: "streaming",
|
331
|
+
status: {
|
332
|
+
queue,
|
333
|
+
message: data.output.error,
|
334
|
+
stage: "streaming",
|
335
|
+
time_limit: data.time_limit,
|
336
|
+
code: data.code,
|
337
|
+
progress_data: data.progress_data,
|
338
|
+
eta: data.eta
|
339
|
+
},
|
340
|
+
data: data.output
|
341
|
+
};
|
320
342
|
case "process_completed":
|
321
343
|
if ("error" in data.output) {
|
322
344
|
return {
|
@@ -358,7 +380,8 @@ export function handle_message(
|
|
358
380
|
position: 0,
|
359
381
|
success: data.success,
|
360
382
|
eta: data.eta
|
361
|
-
}
|
383
|
+
},
|
384
|
+
original_msg: "process_starts"
|
362
385
|
};
|
363
386
|
}
|
364
387
|
|
@@ -87,6 +87,7 @@ export async function resolve_config(
|
|
87
87
|
return { ...config, path } as Config;
|
88
88
|
} else if (endpoint) {
|
89
89
|
const config_url = join_urls(endpoint, CONFIG_URL);
|
90
|
+
console.log("config_url", config_url);
|
90
91
|
const response = await this.fetch(config_url, {
|
91
92
|
headers,
|
92
93
|
credentials: "include"
|
@@ -204,10 +205,11 @@ export function determine_protocol(endpoint: string): {
|
|
204
205
|
}
|
205
206
|
|
206
207
|
// default to secure if no protocol is provided
|
208
|
+
|
207
209
|
return {
|
208
210
|
ws_protocol: "wss",
|
209
211
|
http_protocol: "https:",
|
210
|
-
host: endpoint
|
212
|
+
host: new URL(endpoint).host
|
211
213
|
};
|
212
214
|
}
|
213
215
|
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
@@ -102,6 +102,7 @@ export type client_return = {
|
|
102
102
|
export interface SubmitIterable<T> extends AsyncIterable<T> {
|
103
103
|
[Symbol.asyncIterator](): AsyncIterator<T>;
|
104
104
|
cancel: () => Promise<void>;
|
105
|
+
event_id: () => string;
|
105
106
|
}
|
106
107
|
|
107
108
|
export type PredictReturn = {
|
@@ -182,6 +183,9 @@ export interface Config {
|
|
182
183
|
max_file_size?: number;
|
183
184
|
theme_hash?: number;
|
184
185
|
username: string | null;
|
186
|
+
api_prefix?: string;
|
187
|
+
fill_height?: boolean;
|
188
|
+
fill_width?: boolean;
|
185
189
|
}
|
186
190
|
|
187
191
|
// todo: DRY up types
|
@@ -251,6 +255,11 @@ export interface Dependency {
|
|
251
255
|
show_api: boolean;
|
252
256
|
zerogpu?: boolean;
|
253
257
|
rendered_in: number | null;
|
258
|
+
connection: "stream" | "sse";
|
259
|
+
time_limit: number;
|
260
|
+
stream_every: number;
|
261
|
+
like_user_message: boolean;
|
262
|
+
event_specific_args: string[];
|
254
263
|
}
|
255
264
|
|
256
265
|
export interface DependencyTypes {
|
@@ -335,7 +344,7 @@ export interface Status {
|
|
335
344
|
queue: boolean;
|
336
345
|
code?: string;
|
337
346
|
success?: boolean;
|
338
|
-
stage: "pending" | "error" | "complete" | "generating";
|
347
|
+
stage: "pending" | "error" | "complete" | "generating" | "streaming";
|
339
348
|
duration?: number;
|
340
349
|
visible?: boolean;
|
341
350
|
broken?: boolean;
|
@@ -352,12 +361,14 @@ export interface Status {
|
|
352
361
|
}[];
|
353
362
|
time?: Date;
|
354
363
|
changed_state_ids?: number[];
|
364
|
+
time_limit?: number;
|
355
365
|
}
|
356
366
|
|
357
367
|
export interface StatusMessage extends Status {
|
358
368
|
type: "status";
|
359
369
|
endpoint: string;
|
360
370
|
fn_index: number;
|
371
|
+
original_msg?: string;
|
361
372
|
}
|
362
373
|
|
363
374
|
export interface PayloadMessage extends Payload {
|
package/src/upload.ts
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
import type { UploadResponse } from "./types";
|
2
1
|
import type { Client } from "./client";
|
3
2
|
|
4
3
|
export async function upload(
|
@@ -34,7 +33,7 @@ export async function upload(
|
|
34
33
|
const file = new FileData({
|
35
34
|
...file_data[i],
|
36
35
|
path: f,
|
37
|
-
url: root_url
|
36
|
+
url: `${root_url}${this.api_prefix}/file=${f}`
|
38
37
|
});
|
39
38
|
return file;
|
40
39
|
});
|
package/src/utils/stream.ts
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import { BROKEN_CONNECTION_MSG } from "../constants";
|
1
|
+
import { BROKEN_CONNECTION_MSG, SSE_URL } from "../constants";
|
2
2
|
import type { Client } from "../client";
|
3
3
|
import { stream } from "fetch-event-stream";
|
4
4
|
|
@@ -25,7 +25,7 @@ export async function open_stream(this: Client): Promise<void> {
|
|
25
25
|
session_hash: this.session_hash
|
26
26
|
}).toString();
|
27
27
|
|
28
|
-
let url = new URL(`${config.root}
|
28
|
+
let url = new URL(`${config.root}${this.api_prefix}/${SSE_URL}?${params}`);
|
29
29
|
|
30
30
|
if (jwt) {
|
31
31
|
url.searchParams.set("__sign", jwt);
|
package/src/utils/submit.ts
CHANGED
@@ -19,7 +19,14 @@ import {
|
|
19
19
|
process_endpoint
|
20
20
|
} from "../helpers/api_info";
|
21
21
|
import semiver from "semiver";
|
22
|
-
import {
|
22
|
+
import {
|
23
|
+
BROKEN_CONNECTION_MSG,
|
24
|
+
QUEUE_FULL_MSG,
|
25
|
+
SSE_URL,
|
26
|
+
SSE_DATA_URL,
|
27
|
+
RESET_URL,
|
28
|
+
CANCEL_URL
|
29
|
+
} from "../constants";
|
23
30
|
import { apply_diff_stream, close_stream } from "./stream";
|
24
31
|
import { Client } from "../client";
|
25
32
|
|
@@ -46,7 +53,8 @@ export function submit(
|
|
46
53
|
event_callbacks,
|
47
54
|
unclosed_events,
|
48
55
|
post_data,
|
49
|
-
options
|
56
|
+
options,
|
57
|
+
api_prefix
|
50
58
|
} = this;
|
51
59
|
|
52
60
|
const that = this;
|
@@ -66,6 +74,8 @@ export function submit(
|
|
66
74
|
let websocket: WebSocket;
|
67
75
|
let stream: EventSource | null;
|
68
76
|
let protocol = config.protocol ?? "ws";
|
77
|
+
let event_id_final = "";
|
78
|
+
let event_id_cb: () => string = () => event_id_final;
|
69
79
|
|
70
80
|
const _endpoint = typeof endpoint === "number" ? "/predict" : endpoint;
|
71
81
|
let payload: Payload;
|
@@ -131,14 +141,14 @@ export function submit(
|
|
131
141
|
}
|
132
142
|
|
133
143
|
if ("event_id" in cancel_request) {
|
134
|
-
await fetch(`${config.root}
|
144
|
+
await fetch(`${config.root}${api_prefix}/${CANCEL_URL}`, {
|
135
145
|
headers: { "Content-Type": "application/json" },
|
136
146
|
method: "POST",
|
137
147
|
body: JSON.stringify(cancel_request)
|
138
148
|
});
|
139
149
|
}
|
140
150
|
|
141
|
-
await fetch(`${config.root}
|
151
|
+
await fetch(`${config.root}${api_prefix}/${RESET_URL}`, {
|
142
152
|
headers: { "Content-Type": "application/json" },
|
143
153
|
method: "POST",
|
144
154
|
body: JSON.stringify(reset_request)
|
@@ -205,7 +215,7 @@ export function submit(
|
|
205
215
|
});
|
206
216
|
|
207
217
|
post_data(
|
208
|
-
`${config.root}/run${
|
218
|
+
`${config.root}${api_prefix}/run${
|
209
219
|
_endpoint.startsWith("/") ? _endpoint : `/${_endpoint}`
|
210
220
|
}${url_params ? "?" + url_params : ""}`,
|
211
221
|
{
|
@@ -411,7 +421,7 @@ export function submit(
|
|
411
421
|
session_hash: session_hash
|
412
422
|
}).toString();
|
413
423
|
let url = new URL(
|
414
|
-
`${config.root}
|
424
|
+
`${config.root}${api_prefix}/${SSE_URL}?${
|
415
425
|
url_params ? url_params + "&" : ""
|
416
426
|
}${params}`
|
417
427
|
);
|
@@ -449,12 +459,14 @@ export function submit(
|
|
449
459
|
close();
|
450
460
|
}
|
451
461
|
} else if (type === "data") {
|
452
|
-
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
|
462
|
+
let [_, status] = await post_data(
|
463
|
+
`${config.root}${api_prefix}/queue/data`,
|
464
|
+
{
|
465
|
+
...payload,
|
466
|
+
session_hash,
|
467
|
+
event_id
|
468
|
+
}
|
469
|
+
);
|
458
470
|
if (status !== 200) {
|
459
471
|
fire_event({
|
460
472
|
type: "status",
|
@@ -480,7 +492,7 @@ export function submit(
|
|
480
492
|
visible: data.visible,
|
481
493
|
fn_index
|
482
494
|
});
|
483
|
-
} else if (type === "generating") {
|
495
|
+
} else if (type === "generating" || type === "streaming") {
|
484
496
|
fire_event({
|
485
497
|
type: "status",
|
486
498
|
time: new Date(),
|
@@ -563,7 +575,7 @@ export function submit(
|
|
563
575
|
: Promise.resolve(null);
|
564
576
|
const post_data_promise = zerogpu_auth_promise.then((headers) => {
|
565
577
|
return post_data(
|
566
|
-
`${config.root}
|
578
|
+
`${config.root}${api_prefix}/${SSE_DATA_URL}?${url_params}`,
|
567
579
|
{
|
568
580
|
...payload,
|
569
581
|
session_hash
|
@@ -594,9 +606,10 @@ export function submit(
|
|
594
606
|
});
|
595
607
|
} else {
|
596
608
|
event_id = response.event_id as string;
|
609
|
+
event_id_final = event_id;
|
597
610
|
let callback = async function (_data: object): Promise<void> {
|
598
611
|
try {
|
599
|
-
const { type, status, data } = handle_message(
|
612
|
+
const { type, status, data, original_msg } = handle_message(
|
600
613
|
_data,
|
601
614
|
last_status[fn_index]
|
602
615
|
);
|
@@ -612,6 +625,7 @@ export function submit(
|
|
612
625
|
endpoint: _endpoint,
|
613
626
|
fn_index,
|
614
627
|
time: new Date(),
|
628
|
+
original_msg: original_msg,
|
615
629
|
...status
|
616
630
|
});
|
617
631
|
} else if (type === "complete") {
|
@@ -639,7 +653,7 @@ export function submit(
|
|
639
653
|
fn_index
|
640
654
|
});
|
641
655
|
return;
|
642
|
-
} else if (type === "generating") {
|
656
|
+
} else if (type === "generating" || type === "streaming") {
|
643
657
|
fire_event({
|
644
658
|
type: "status",
|
645
659
|
time: new Date(),
|
@@ -651,6 +665,7 @@ export function submit(
|
|
651
665
|
});
|
652
666
|
if (
|
653
667
|
data &&
|
668
|
+
dependency.connection !== "stream" &&
|
654
669
|
["sse_v2", "sse_v2.1", "sse_v3"].includes(protocol)
|
655
670
|
) {
|
656
671
|
apply_diff_stream(pending_diff_streams, event_id!, data);
|
@@ -790,7 +805,8 @@ export function submit(
|
|
790
805
|
close();
|
791
806
|
return next();
|
792
807
|
},
|
793
|
-
cancel
|
808
|
+
cancel,
|
809
|
+
event_id: event_id_cb
|
794
810
|
};
|
795
811
|
|
796
812
|
return iterator;
|
@@ -27,8 +27,8 @@ export async function upload_files(
|
|
27
27
|
});
|
28
28
|
try {
|
29
29
|
const upload_url = upload_id
|
30
|
-
? `${root_url}/${UPLOAD_URL}?upload_id=${upload_id}`
|
31
|
-
: `${root_url}/${UPLOAD_URL}`;
|
30
|
+
? `${root_url}${this.api_prefix}/${UPLOAD_URL}?upload_id=${upload_id}`
|
31
|
+
: `${root_url}${this.api_prefix}/${UPLOAD_URL}`;
|
32
32
|
|
33
33
|
response = await this.fetch(upload_url, {
|
34
34
|
method: "POST",
|
package/src/utils/view_api.ts
CHANGED
@@ -41,7 +41,7 @@ export async function view_api(this: Client): Promise<any> {
|
|
41
41
|
credentials: "include"
|
42
42
|
});
|
43
43
|
} else {
|
44
|
-
const url = join_urls(config.root, API_INFO_URL);
|
44
|
+
const url = join_urls(config.root, this.api_prefix, API_INFO_URL);
|
45
45
|
response = await this.fetch(url, {
|
46
46
|
headers,
|
47
47
|
credentials: "include"
|