@gradio/client 1.19.1 → 2.0.0-dev.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/CHANGELOG.md +6 -0
- package/README.md +8 -8
- package/dist/browser.js +741 -889
- package/dist/client.d.ts +0 -4
- package/dist/client.d.ts.map +1 -1
- package/dist/helpers/api_info.d.ts +1 -1
- package/dist/helpers/api_info.d.ts.map +1 -1
- package/dist/helpers/init_helpers.d.ts +1 -1
- package/dist/helpers/init_helpers.d.ts.map +1 -1
- package/dist/helpers/spaces.d.ts +2 -2
- package/dist/helpers/spaces.d.ts.map +1 -1
- package/dist/index.js +53 -266
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/duplicate.d.ts.map +1 -1
- package/dist/utils/submit.d.ts.map +1 -1
- package/dist/utils/view_api.d.ts.map +1 -1
- package/package.json +4 -12
- package/src/client.ts +12 -83
- package/src/helpers/api_info.ts +3 -3
- package/src/helpers/init_helpers.ts +7 -7
- package/src/helpers/spaces.ts +6 -6
- package/src/test/api_info.test.ts +4 -4
- package/src/test/init.test.ts +5 -5
- package/src/test/post_data.test.ts +1 -1
- package/src/test/spaces.test.ts +6 -8
- package/src/test/view_api.test.ts +2 -2
- package/src/types.ts +1 -1
- package/src/utils/duplicate.ts +5 -8
- package/src/utils/post_data.ts +2 -2
- package/src/utils/submit.ts +6 -148
- package/src/utils/upload_files.ts +2 -2
- package/src/utils/view_api.ts +8 -22
- package/dist/wrapper-CpGUsf_3.js +0 -3076
package/dist/client.d.ts
CHANGED
|
@@ -24,7 +24,6 @@ export declare class Client {
|
|
|
24
24
|
abort_controller: AbortController | null;
|
|
25
25
|
stream_instance: EventSource | null;
|
|
26
26
|
current_payload: any;
|
|
27
|
-
ws_map: Record<string, WebSocket | "pending" | "failed" | "closed">;
|
|
28
27
|
get_url_config(url?: string | null): Config;
|
|
29
28
|
get_page_config(page: string): Config;
|
|
30
29
|
fetch(input: RequestInfo | URL, init?: RequestInit): Promise<Response>;
|
|
@@ -56,9 +55,6 @@ export declare class Client {
|
|
|
56
55
|
}): Promise<unknown>;
|
|
57
56
|
set_cookies(raw_cookies: string): void;
|
|
58
57
|
private prepare_return_obj;
|
|
59
|
-
private connect_ws;
|
|
60
|
-
send_ws_message(url: string, data: any): Promise<void>;
|
|
61
|
-
close_ws(url: string): Promise<void>;
|
|
62
58
|
}
|
|
63
59
|
/**
|
|
64
60
|
* @deprecated This method will be removed in v1.0. Use `Client.connect()` instead.
|
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;AA0B5C,qBAAa,MAAM;IAClB,aAAa,EAAE,MAAM,CAAC;IACtB,OAAO,EAAE,aAAa,CAAC;IACvB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAQ;IAEhC,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,GAAG,KAAK,CAAS;IAC5B,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,OAAO,CAAC,CAAC,CAAM;IAElD,OAAO,CAAC,OAAO,CAAuB;IAGtC,aAAa;;MAAmB;IAChC,MAAM,UAAS;IACf,uBAAuB,EA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S,CAAC;IAoB9D,KAAK,IAAI,IAAI;IAKb,mBAAmB,CAAC,OAAO,EAAE,GAAG,GAAG,IAAI;WAI1B,SAAS,CACrB,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE,gBAER,GACC,OAAO,CAAC,MAAM,CAAC;YAIJ,eAAe;YA4Cf,cAAc;IAmBtB,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"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ApiData, ApiInfo, Config, JsApiData, EndpointInfo, Status } from "../types";
|
|
2
2
|
export declare const RE_SPACE_NAME: RegExp;
|
|
3
3
|
export declare const RE_SPACE_DOMAIN: RegExp;
|
|
4
|
-
export declare function process_endpoint(app_reference: string,
|
|
4
|
+
export declare function process_endpoint(app_reference: string, token?: `hf_${string}`): Promise<{
|
|
5
5
|
space_id: string | false;
|
|
6
6
|
host: string;
|
|
7
7
|
ws_protocol: "ws" | "wss";
|
|
@@ -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,QAA2C,CAAC;AACtE,eAAO,MAAM,eAAe,QAA0B,CAAC;AAEvD,wBAAsB,gBAAgB,CACrC,aAAa,EAAE,MAAM,EACrB,
|
|
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,QAA2C,CAAC;AACtE,eAAO,MAAM,eAAe,QAA0B,CAAC;AAEvD,wBAAsB,gBAAgB,CACrC,aAAa,EAAE,MAAM,EACrB,KAAK,CAAC,EAAE,MAAM,MAAM,EAAE,GACpB,OAAO,CAAC;IACV,QAAQ,EAAE,MAAM,GAAG,KAAK,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,IAAI,GAAG,KAAK,CAAC;IAC1B,aAAa,EAAE,OAAO,GAAG,QAAQ,CAAC;CAClC,CAAC,CA4CD;AAED,eAAO,MAAM,SAAS,YAAa,MAAM,EAAE,KAAG,MAU7C,CAAC;AAEF,wBAAgB,kBAAkB,CACjC,QAAQ,EAAE,OAAO,CAAC,OAAO,CAAC,EAC1B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAC7B,OAAO,CAAC,SAAS,CAAC,CAsFpB;AAED,wBAAgB,QAAQ,CACvB,IAAI,EAAE;IAAE,IAAI,EAAE,GAAG,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,EACxC,SAAS,EAAE,MAAM,EACjB,UAAU,EAAE,MAAM,EAClB,cAAc,EAAE,QAAQ,GAAG,WAAW,GACpC,MAAM,GAAG,SAAS,CAkCpB;AAED,wBAAgB,eAAe,CAC9B,IAAI,EAAE;IAAE,IAAI,EAAE,GAAG,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,EACxC,UAAU,EAAE,MAAM,GAChB,MAAM,CASR;AAGD,wBAAgB,cAAc,CAC7B,IAAI,EAAE,GAAG,EACT,WAAW,EAAE,MAAM,CAAC,OAAO,CAAC,GAC1B;IACF,IAAI,EACD,MAAM,GACN,MAAM,GACN,QAAQ,GACR,UAAU,GACV,YAAY,GACZ,KAAK,GACL,MAAM,GACN,WAAW,GACX,WAAW,GACX,mBAAmB,GACnB,kBAAkB,CAAC;IACtB,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CACtB,CAmJA;AAGD;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,eAAO,MAAM,kBAAkB,yEAEf,aAAa,SAAS,GAAG,OAAO,CAAC,KAC9C,OAAO,EAgDT,CAAC"}
|
|
@@ -15,7 +15,7 @@ export declare function get_jwt(space: string, token: `hf_${string}`, cookies?:
|
|
|
15
15
|
export declare function map_names_to_ids(fns: Config["dependencies"]): Record<string, number>;
|
|
16
16
|
export declare function resolve_config(this: Client, endpoint: string): Promise<Config | undefined>;
|
|
17
17
|
export declare function resolve_cookies(this: Client): Promise<void>;
|
|
18
|
-
export declare function get_cookie_header(http_protocol: string, host: string, auth: [string, string], _fetch: typeof fetch,
|
|
18
|
+
export declare function get_cookie_header(http_protocol: string, host: string, auth: [string, string], _fetch: typeof fetch, token?: `hf_${string}`): Promise<string | null>;
|
|
19
19
|
export declare function determine_protocol(endpoint: string): {
|
|
20
20
|
ws_protocol: "ws" | "wss";
|
|
21
21
|
http_protocol: "http:" | "https:";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init_helpers.d.ts","sourceRoot":"","sources":["../../src/helpers/init_helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAUvC,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAG5B;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC3B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,OAAO,GACtB,MAAM,CAKR;AAED,wBAAsB,OAAO,CAC5B,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,MAAM,EAAE,EACrB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GACrB,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,CAezB;AAED,wBAAgB,gBAAgB,CAC/B,GAAG,EAAE,MAAM,CAAC,cAAc,CAAC,GACzB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOxB;AAED,wBAAsB,cAAc,CACnC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAuD7B;AA+BD,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqBjE;AAGD,wBAAsB,iBAAiB,CACtC,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EACtB,MAAM,EAAE,OAAO,KAAK,EACpB,
|
|
1
|
+
{"version":3,"file":"init_helpers.d.ts","sourceRoot":"","sources":["../../src/helpers/init_helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAUvC,OAAO,EAAE,MAAM,EAAE,MAAM,IAAI,CAAC;AAG5B;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC3B,QAAQ,EAAE,MAAM,EAChB,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,OAAO,GACtB,MAAM,CAKR;AAED,wBAAsB,OAAO,CAC5B,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,MAAM,EAAE,EACrB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,GACrB,OAAO,CAAC,MAAM,GAAG,KAAK,CAAC,CAezB;AAED,wBAAgB,gBAAgB,CAC/B,GAAG,EAAE,MAAM,CAAC,cAAc,CAAC,GACzB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOxB;AAED,wBAAsB,cAAc,CACnC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,GACd,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAuD7B;AA+BD,wBAAsB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAqBjE;AAGD,wBAAsB,iBAAiB,CACtC,aAAa,EAAE,MAAM,EACrB,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,EACtB,MAAM,EAAE,OAAO,KAAK,EACpB,KAAK,CAAC,EAAE,MAAM,MAAM,EAAE,GACpB,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,CAkBA;AAED,eAAO,MAAM,qBAAqB,kBAAmB,MAAM,KAAG,MAAM,EAUnE,CAAC"}
|
package/dist/helpers/spaces.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ import type { SpaceStatusCallback } from "../types";
|
|
|
2
2
|
export declare function check_space_status(id: string, type: "subdomain" | "space_name", status_callback: SpaceStatusCallback): Promise<void>;
|
|
3
3
|
export declare const check_and_wake_space: (space_id: string, status_callback: SpaceStatusCallback) => Promise<void>;
|
|
4
4
|
export declare function discussions_enabled(space_id: string): Promise<boolean>;
|
|
5
|
-
export declare function get_space_hardware(space_id: string,
|
|
6
|
-
export declare function set_space_timeout(space_id: string, timeout: number,
|
|
5
|
+
export declare function get_space_hardware(space_id: string, token?: `hf_${string}` | undefined): Promise<(typeof hardware_types)[number]>;
|
|
6
|
+
export declare function set_space_timeout(space_id: string, timeout: number, token?: `hf_${string}`): Promise<any>;
|
|
7
7
|
export declare const hardware_types: readonly ["cpu-basic", "cpu-upgrade", "cpu-xl", "t4-small", "t4-medium", "a10g-small", "a10g-large", "a10g-largex2", "a10g-largex4", "a100-large", "zero-a10g", "h100", "h100x8"];
|
|
8
8
|
//# sourceMappingURL=spaces.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"spaces.d.ts","sourceRoot":"","sources":["../../src/helpers/spaces.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEpD,wBAAsB,kBAAkB,CACvC,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,WAAW,GAAG,YAAY,EAChC,eAAe,EAAE,mBAAmB,GAClC,OAAO,CAAC,IAAI,CAAC,CAiGf;AAED,eAAO,MAAM,oBAAoB,aACtB,MAAM,mBACC,mBAAmB,KAClC,QAAQ,IAAI,CAoCd,CAAC;AAIF,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAgB5E;AAED,wBAAsB,kBAAkB,CACvC,QAAQ,EAAE,MAAM,EAChB,
|
|
1
|
+
{"version":3,"file":"spaces.d.ts","sourceRoot":"","sources":["../../src/helpers/spaces.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAEpD,wBAAsB,kBAAkB,CACvC,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,WAAW,GAAG,YAAY,EAChC,eAAe,EAAE,mBAAmB,GAClC,OAAO,CAAC,IAAI,CAAC,CAiGf;AAED,eAAO,MAAM,oBAAoB,aACtB,MAAM,mBACC,mBAAmB,KAClC,QAAQ,IAAI,CAoCd,CAAC;AAIF,wBAAsB,mBAAmB,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAgB5E;AAED,wBAAsB,kBAAkB,CACvC,QAAQ,EAAE,MAAM,EAChB,KAAK,CAAC,EAAE,MAAM,MAAM,EAAE,GAAG,SAAS,GAChC,OAAO,CAAC,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC,CAqB1C;AAED,wBAAsB,iBAAiB,CACtC,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,MAAM,MAAM,EAAE,GACpB,OAAO,CAAC,GAAG,CAAC,CAiCd;AAED,eAAO,MAAM,cAAc,mLAcjB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -9,12 +9,6 @@ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read fr
|
|
|
9
9
|
var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
10
10
|
var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
|
|
11
11
|
var _currentLine;
|
|
12
|
-
var fn = new Intl.Collator(0, { numeric: 1 }).compare;
|
|
13
|
-
function semiver(a, b, bool) {
|
|
14
|
-
a = a.split(".");
|
|
15
|
-
b = b.split(".");
|
|
16
|
-
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);
|
|
17
|
-
}
|
|
18
12
|
const HOST_URL = `host`;
|
|
19
13
|
const SSE_URL = `queue/data`;
|
|
20
14
|
const SSE_DATA_URL = `queue/join`;
|
|
@@ -29,7 +23,6 @@ const COMPONENT_SERVER_URL = `component_server`;
|
|
|
29
23
|
const RESET_URL = `reset`;
|
|
30
24
|
const CANCEL_URL = `cancel`;
|
|
31
25
|
const APP_ID_URL = `app_id`;
|
|
32
|
-
const SPACE_FETCHER_URL = "https://gradio-space-api-fetcher-v2.hf.space/api";
|
|
33
26
|
const QUEUE_FULL_MSG = "This application is currently busy. Please try again. ";
|
|
34
27
|
const BROKEN_CONNECTION_MSG = "Connection errored out. ";
|
|
35
28
|
const CONFIG_ERROR_MSG = "Could not resolve app config. ";
|
|
@@ -43,12 +36,6 @@ const MISSING_CREDENTIALS_MSG = "Login credentials are required to access this s
|
|
|
43
36
|
const NODEJS_FS_ERROR_MSG = "File system access is only available in Node.js environments";
|
|
44
37
|
const ROOT_URL_ERROR_MSG = "Root URL not found in client config";
|
|
45
38
|
const FILE_PROCESSING_ERROR_MSG = "Error uploading file";
|
|
46
|
-
function resolve_root(base_url, root_path, prioritize_base) {
|
|
47
|
-
if (root_path.startsWith("http://") || root_path.startsWith("https://")) {
|
|
48
|
-
return prioritize_base ? base_url : root_path;
|
|
49
|
-
}
|
|
50
|
-
return base_url + root_path;
|
|
51
|
-
}
|
|
52
39
|
async function get_jwt(space, token, cookies) {
|
|
53
40
|
try {
|
|
54
41
|
const r = await fetch(`https://huggingface.co/api/spaces/${space}/jwt`, {
|
|
@@ -71,7 +58,7 @@ function map_names_to_ids(fns) {
|
|
|
71
58
|
return apis;
|
|
72
59
|
}
|
|
73
60
|
async function resolve_config(endpoint) {
|
|
74
|
-
const headers = this.options.
|
|
61
|
+
const headers = this.options.token ? { Authorization: `Bearer ${this.options.token}` } : {};
|
|
75
62
|
headers["Content-Type"] = "application/json";
|
|
76
63
|
if (typeof window !== "undefined" && window.gradio_config && location.origin !== "http://localhost:9876") {
|
|
77
64
|
if (window.gradio_config.current_page) {
|
|
@@ -137,7 +124,7 @@ async function handleConfigResponse(response, endpoint, authorized) {
|
|
|
137
124
|
async function resolve_cookies() {
|
|
138
125
|
const { http_protocol, host } = await process_endpoint(
|
|
139
126
|
this.app_reference,
|
|
140
|
-
this.options.
|
|
127
|
+
this.options.token
|
|
141
128
|
);
|
|
142
129
|
try {
|
|
143
130
|
if (this.options.auth) {
|
|
@@ -146,7 +133,7 @@ async function resolve_cookies() {
|
|
|
146
133
|
host,
|
|
147
134
|
this.options.auth,
|
|
148
135
|
this.fetch,
|
|
149
|
-
this.options.
|
|
136
|
+
this.options.token
|
|
150
137
|
);
|
|
151
138
|
if (cookie_header) this.set_cookies(cookie_header);
|
|
152
139
|
}
|
|
@@ -154,13 +141,13 @@ async function resolve_cookies() {
|
|
|
154
141
|
throw Error(e.message);
|
|
155
142
|
}
|
|
156
143
|
}
|
|
157
|
-
async function get_cookie_header(http_protocol, host, auth, _fetch,
|
|
144
|
+
async function get_cookie_header(http_protocol, host, auth, _fetch, token) {
|
|
158
145
|
const formData = new FormData();
|
|
159
146
|
formData.append("username", auth == null ? void 0 : auth[0]);
|
|
160
147
|
formData.append("password", auth == null ? void 0 : auth[1]);
|
|
161
148
|
let headers = {};
|
|
162
|
-
if (
|
|
163
|
-
headers.Authorization = `Bearer ${
|
|
149
|
+
if (token) {
|
|
150
|
+
headers.Authorization = `Bearer ${token}`;
|
|
164
151
|
}
|
|
165
152
|
const res = await _fetch(`${http_protocol}//${host}/${LOGIN_URL}`, {
|
|
166
153
|
headers,
|
|
@@ -204,10 +191,10 @@ const parse_and_set_cookies = (cookie_header) => {
|
|
|
204
191
|
};
|
|
205
192
|
const RE_SPACE_NAME = /^[a-zA-Z0-9_\-\.]+\/[a-zA-Z0-9_\-\.]+$/;
|
|
206
193
|
const RE_SPACE_DOMAIN = /.*hf\.space\/{0,1}.*$/;
|
|
207
|
-
async function process_endpoint(app_reference,
|
|
194
|
+
async function process_endpoint(app_reference, token) {
|
|
208
195
|
const headers = {};
|
|
209
|
-
if (
|
|
210
|
-
headers.Authorization = `Bearer ${
|
|
196
|
+
if (token) {
|
|
197
|
+
headers.Authorization = `Bearer ${token}`;
|
|
211
198
|
}
|
|
212
199
|
const _app_reference = app_reference.trim().replace(/\/$/, "");
|
|
213
200
|
if (RE_SPACE_NAME.test(_app_reference)) {
|
|
@@ -526,11 +513,11 @@ const map_data_to_params = (data = [], endpoint_info) => {
|
|
|
526
513
|
};
|
|
527
514
|
async function view_api() {
|
|
528
515
|
if (this.api_info) return this.api_info;
|
|
529
|
-
const {
|
|
516
|
+
const { token } = this.options;
|
|
530
517
|
const { config } = this;
|
|
531
518
|
const headers = { "Content-Type": "application/json" };
|
|
532
|
-
if (
|
|
533
|
-
headers.Authorization = `Bearer ${
|
|
519
|
+
if (token) {
|
|
520
|
+
headers.Authorization = `Bearer ${token}`;
|
|
534
521
|
}
|
|
535
522
|
if (!config) {
|
|
536
523
|
return;
|
|
@@ -541,23 +528,11 @@ async function view_api() {
|
|
|
541
528
|
if (typeof window !== "undefined" && window.gradio_api_info) {
|
|
542
529
|
api_info = window.gradio_api_info;
|
|
543
530
|
} else {
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
config: JSON.stringify(config)
|
|
550
|
-
}),
|
|
551
|
-
headers,
|
|
552
|
-
credentials: "include"
|
|
553
|
-
});
|
|
554
|
-
} else {
|
|
555
|
-
const url = join_urls(config.root, this.api_prefix, API_INFO_URL);
|
|
556
|
-
response = await this.fetch(url, {
|
|
557
|
-
headers,
|
|
558
|
-
credentials: "include"
|
|
559
|
-
});
|
|
560
|
-
}
|
|
531
|
+
const url = join_urls(config.root, this.api_prefix, API_INFO_URL);
|
|
532
|
+
response = await this.fetch(url, {
|
|
533
|
+
headers,
|
|
534
|
+
credentials: "include"
|
|
535
|
+
});
|
|
561
536
|
if (!response.ok) {
|
|
562
537
|
throw new Error(BROKEN_CONNECTION_MSG);
|
|
563
538
|
}
|
|
@@ -577,8 +552,8 @@ async function view_api() {
|
|
|
577
552
|
async function upload_files(root_url, files, upload_id) {
|
|
578
553
|
var _a;
|
|
579
554
|
const headers = {};
|
|
580
|
-
if ((_a = this == null ? void 0 : this.options) == null ? void 0 : _a.
|
|
581
|
-
headers.Authorization = `Bearer ${this.options.
|
|
555
|
+
if ((_a = this == null ? void 0 : this.options) == null ? void 0 : _a.token) {
|
|
556
|
+
headers.Authorization = `Bearer ${this.options.token}`;
|
|
582
557
|
}
|
|
583
558
|
const chunkSize = 1e3;
|
|
584
559
|
const uploadResponses = [];
|
|
@@ -929,8 +904,8 @@ async function process_single_command(client2, data, key) {
|
|
|
929
904
|
}
|
|
930
905
|
async function post_data(url, body, additional_headers) {
|
|
931
906
|
const headers = { "Content-Type": "application/json" };
|
|
932
|
-
if (this.options.
|
|
933
|
-
headers.Authorization = `Bearer ${this.options.
|
|
907
|
+
if (this.options.token) {
|
|
908
|
+
headers.Authorization = `Bearer ${this.options.token}`;
|
|
934
909
|
}
|
|
935
910
|
try {
|
|
936
911
|
var response = await this.fetch(url, {
|
|
@@ -1123,10 +1098,10 @@ async function discussions_enabled(space_id) {
|
|
|
1123
1098
|
return false;
|
|
1124
1099
|
}
|
|
1125
1100
|
}
|
|
1126
|
-
async function get_space_hardware(space_id,
|
|
1101
|
+
async function get_space_hardware(space_id, token) {
|
|
1127
1102
|
const headers = {};
|
|
1128
|
-
if (
|
|
1129
|
-
headers.Authorization = `Bearer ${
|
|
1103
|
+
if (token) {
|
|
1104
|
+
headers.Authorization = `Bearer ${token}`;
|
|
1130
1105
|
}
|
|
1131
1106
|
try {
|
|
1132
1107
|
const res = await fetch(
|
|
@@ -1141,10 +1116,10 @@ async function get_space_hardware(space_id, hf_token) {
|
|
|
1141
1116
|
throw new Error(e.message);
|
|
1142
1117
|
}
|
|
1143
1118
|
}
|
|
1144
|
-
async function set_space_timeout(space_id, timeout,
|
|
1119
|
+
async function set_space_timeout(space_id, timeout, token) {
|
|
1145
1120
|
const headers = {};
|
|
1146
|
-
if (
|
|
1147
|
-
headers.Authorization = `Bearer ${
|
|
1121
|
+
if (token) {
|
|
1122
|
+
headers.Authorization = `Bearer ${token}`;
|
|
1148
1123
|
}
|
|
1149
1124
|
const body = {
|
|
1150
1125
|
seconds: timeout
|
|
@@ -1185,16 +1160,13 @@ const hardware_types = [
|
|
|
1185
1160
|
"h100x8"
|
|
1186
1161
|
];
|
|
1187
1162
|
async function duplicate(app_reference, options) {
|
|
1188
|
-
const {
|
|
1163
|
+
const { token, private: _private, hardware, timeout, auth } = options;
|
|
1189
1164
|
if (hardware && !hardware_types.includes(hardware)) {
|
|
1190
1165
|
throw new Error(
|
|
1191
1166
|
`Invalid hardware type provided. Valid types are: ${hardware_types.map((v) => `"${v}"`).join(",")}.`
|
|
1192
1167
|
);
|
|
1193
1168
|
}
|
|
1194
|
-
const { http_protocol, host } = await process_endpoint(
|
|
1195
|
-
app_reference,
|
|
1196
|
-
hf_token
|
|
1197
|
-
);
|
|
1169
|
+
const { http_protocol, host } = await process_endpoint(app_reference, token);
|
|
1198
1170
|
let cookies = null;
|
|
1199
1171
|
if (auth) {
|
|
1200
1172
|
const cookie_header = await get_cookie_header(
|
|
@@ -1206,7 +1178,7 @@ async function duplicate(app_reference, options) {
|
|
|
1206
1178
|
if (cookie_header) cookies = parse_and_set_cookies(cookie_header);
|
|
1207
1179
|
}
|
|
1208
1180
|
const headers = {
|
|
1209
|
-
Authorization: `Bearer ${
|
|
1181
|
+
Authorization: `Bearer ${token}`,
|
|
1210
1182
|
"Content-Type": "application/json",
|
|
1211
1183
|
...cookies ? { Cookie: cookies.join("; ") } : {}
|
|
1212
1184
|
};
|
|
@@ -1223,7 +1195,7 @@ async function duplicate(app_reference, options) {
|
|
|
1223
1195
|
let original_hardware;
|
|
1224
1196
|
try {
|
|
1225
1197
|
if (!hardware) {
|
|
1226
|
-
original_hardware = await get_space_hardware(app_reference,
|
|
1198
|
+
original_hardware = await get_space_hardware(app_reference, token);
|
|
1227
1199
|
}
|
|
1228
1200
|
} catch (e) {
|
|
1229
1201
|
throw Error(SPACE_METADATA_ERROR_MSG + e.message);
|
|
@@ -1251,7 +1223,7 @@ async function duplicate(app_reference, options) {
|
|
|
1251
1223
|
throw new Error(response.statusText);
|
|
1252
1224
|
}
|
|
1253
1225
|
const duplicated_space = await response.json();
|
|
1254
|
-
await set_space_timeout(`${user}/${space_name}`, timeout || 300,
|
|
1226
|
+
await set_space_timeout(`${user}/${space_name}`, timeout || 300, token);
|
|
1255
1227
|
return await Client.connect(
|
|
1256
1228
|
get_space_reference(duplicated_space.url),
|
|
1257
1229
|
options
|
|
@@ -1413,11 +1385,11 @@ async function open_stream() {
|
|
|
1413
1385
|
)) {
|
|
1414
1386
|
unclosed_events.delete(event_id);
|
|
1415
1387
|
}
|
|
1416
|
-
let
|
|
1388
|
+
let fn = event_callbacks[event_id];
|
|
1417
1389
|
if (typeof window !== "undefined" && typeof document !== "undefined") {
|
|
1418
|
-
setTimeout(
|
|
1390
|
+
setTimeout(fn, 0, _data);
|
|
1419
1391
|
} else {
|
|
1420
|
-
|
|
1392
|
+
fn(_data);
|
|
1421
1393
|
}
|
|
1422
1394
|
} else {
|
|
1423
1395
|
if (!pending_stream_messages[event_id]) {
|
|
@@ -1578,7 +1550,7 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events) {
|
|
|
1578
1550
|
}
|
|
1579
1551
|
return new Promise((resolve) => resolvers.push(resolve));
|
|
1580
1552
|
};
|
|
1581
|
-
const {
|
|
1553
|
+
const { token } = this.options;
|
|
1582
1554
|
const {
|
|
1583
1555
|
fetch: fetch2,
|
|
1584
1556
|
app_reference,
|
|
@@ -1605,9 +1577,11 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events) {
|
|
|
1605
1577
|
config
|
|
1606
1578
|
);
|
|
1607
1579
|
let resolved_data = map_data_to_params(data, endpoint_info);
|
|
1608
|
-
let websocket;
|
|
1609
1580
|
let stream2;
|
|
1610
1581
|
let protocol = config.protocol ?? "ws";
|
|
1582
|
+
if (protocol === "ws") {
|
|
1583
|
+
throw new Error("WebSocket protocol is not supported in this version");
|
|
1584
|
+
}
|
|
1611
1585
|
let event_id_final = "";
|
|
1612
1586
|
let event_id_cb = () => event_id_final;
|
|
1613
1587
|
const _endpoint = typeof endpoint === "number" ? "/predict" : endpoint;
|
|
@@ -1626,19 +1600,8 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events) {
|
|
|
1626
1600
|
async function cancel() {
|
|
1627
1601
|
let reset_request = {};
|
|
1628
1602
|
let cancel_request = {};
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
websocket.addEventListener("open", () => {
|
|
1632
|
-
websocket.close();
|
|
1633
|
-
});
|
|
1634
|
-
} else {
|
|
1635
|
-
websocket.close();
|
|
1636
|
-
}
|
|
1637
|
-
reset_request = { fn_index, session_hash };
|
|
1638
|
-
} else {
|
|
1639
|
-
reset_request = { event_id };
|
|
1640
|
-
cancel_request = { event_id, session_hash, fn_index };
|
|
1641
|
-
}
|
|
1603
|
+
reset_request = { event_id };
|
|
1604
|
+
cancel_request = { event_id, session_hash, fn_index };
|
|
1642
1605
|
try {
|
|
1643
1606
|
if (!config) {
|
|
1644
1607
|
throw new Error("Could not resolve app config");
|
|
@@ -1771,126 +1734,6 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events) {
|
|
|
1771
1734
|
time: /* @__PURE__ */ new Date()
|
|
1772
1735
|
});
|
|
1773
1736
|
});
|
|
1774
|
-
} else if (protocol == "ws") {
|
|
1775
|
-
const { ws_protocol, host } = await process_endpoint(
|
|
1776
|
-
app_reference,
|
|
1777
|
-
hf_token
|
|
1778
|
-
);
|
|
1779
|
-
fire_event({
|
|
1780
|
-
type: "status",
|
|
1781
|
-
stage: "pending",
|
|
1782
|
-
queue: true,
|
|
1783
|
-
endpoint: _endpoint,
|
|
1784
|
-
fn_index,
|
|
1785
|
-
time: /* @__PURE__ */ new Date()
|
|
1786
|
-
});
|
|
1787
|
-
let url = new URL(
|
|
1788
|
-
`${ws_protocol}://${resolve_root(
|
|
1789
|
-
host,
|
|
1790
|
-
config.root,
|
|
1791
|
-
true
|
|
1792
|
-
)}/queue/join${url_params ? "?" + url_params : ""}`
|
|
1793
|
-
);
|
|
1794
|
-
if (this.jwt) {
|
|
1795
|
-
url.searchParams.set("__sign", this.jwt);
|
|
1796
|
-
}
|
|
1797
|
-
websocket = new WebSocket(url);
|
|
1798
|
-
websocket.onclose = (evt) => {
|
|
1799
|
-
if (!evt.wasClean) {
|
|
1800
|
-
fire_event({
|
|
1801
|
-
type: "status",
|
|
1802
|
-
stage: "error",
|
|
1803
|
-
broken: true,
|
|
1804
|
-
message: BROKEN_CONNECTION_MSG,
|
|
1805
|
-
queue: true,
|
|
1806
|
-
endpoint: _endpoint,
|
|
1807
|
-
fn_index,
|
|
1808
|
-
time: /* @__PURE__ */ new Date()
|
|
1809
|
-
});
|
|
1810
|
-
}
|
|
1811
|
-
};
|
|
1812
|
-
websocket.onmessage = function(event) {
|
|
1813
|
-
const _data = JSON.parse(event.data);
|
|
1814
|
-
const { type, status, data: data2 } = handle_message(
|
|
1815
|
-
_data,
|
|
1816
|
-
last_status[fn_index]
|
|
1817
|
-
);
|
|
1818
|
-
if (type === "update" && status && !complete) {
|
|
1819
|
-
fire_event({
|
|
1820
|
-
type: "status",
|
|
1821
|
-
endpoint: _endpoint,
|
|
1822
|
-
fn_index,
|
|
1823
|
-
time: /* @__PURE__ */ new Date(),
|
|
1824
|
-
...status
|
|
1825
|
-
});
|
|
1826
|
-
if (status.stage === "error") {
|
|
1827
|
-
websocket.close();
|
|
1828
|
-
}
|
|
1829
|
-
} else if (type === "hash") {
|
|
1830
|
-
websocket.send(JSON.stringify({ fn_index, session_hash }));
|
|
1831
|
-
return;
|
|
1832
|
-
} else if (type === "data") {
|
|
1833
|
-
websocket.send(JSON.stringify({ ...payload, session_hash }));
|
|
1834
|
-
} else if (type === "complete") {
|
|
1835
|
-
complete = status;
|
|
1836
|
-
} else if (type === "log") {
|
|
1837
|
-
fire_event({
|
|
1838
|
-
type: "log",
|
|
1839
|
-
title: data2.title,
|
|
1840
|
-
log: data2.log,
|
|
1841
|
-
level: data2.level,
|
|
1842
|
-
endpoint: _endpoint,
|
|
1843
|
-
duration: data2.duration,
|
|
1844
|
-
visible: data2.visible,
|
|
1845
|
-
fn_index
|
|
1846
|
-
});
|
|
1847
|
-
} else if (type === "generating") {
|
|
1848
|
-
fire_event({
|
|
1849
|
-
type: "status",
|
|
1850
|
-
time: /* @__PURE__ */ new Date(),
|
|
1851
|
-
...status,
|
|
1852
|
-
stage: status == null ? void 0 : status.stage,
|
|
1853
|
-
queue: true,
|
|
1854
|
-
endpoint: _endpoint,
|
|
1855
|
-
fn_index
|
|
1856
|
-
});
|
|
1857
|
-
}
|
|
1858
|
-
if (data2) {
|
|
1859
|
-
fire_event({
|
|
1860
|
-
type: "data",
|
|
1861
|
-
time: /* @__PURE__ */ new Date(),
|
|
1862
|
-
data: handle_payload(
|
|
1863
|
-
data2.data,
|
|
1864
|
-
dependency,
|
|
1865
|
-
config.components,
|
|
1866
|
-
"output",
|
|
1867
|
-
options.with_null_state
|
|
1868
|
-
),
|
|
1869
|
-
endpoint: _endpoint,
|
|
1870
|
-
fn_index,
|
|
1871
|
-
event_data,
|
|
1872
|
-
trigger_id
|
|
1873
|
-
});
|
|
1874
|
-
if (complete) {
|
|
1875
|
-
fire_event({
|
|
1876
|
-
type: "status",
|
|
1877
|
-
time: /* @__PURE__ */ new Date(),
|
|
1878
|
-
...complete,
|
|
1879
|
-
stage: status == null ? void 0 : status.stage,
|
|
1880
|
-
queue: true,
|
|
1881
|
-
endpoint: _endpoint,
|
|
1882
|
-
fn_index
|
|
1883
|
-
});
|
|
1884
|
-
websocket.close();
|
|
1885
|
-
}
|
|
1886
|
-
}
|
|
1887
|
-
};
|
|
1888
|
-
if (semiver(config.version || "2.0.0", "3.6") < 0) {
|
|
1889
|
-
addEventListener(
|
|
1890
|
-
"open",
|
|
1891
|
-
() => websocket.send(JSON.stringify({ hash: session_hash }))
|
|
1892
|
-
);
|
|
1893
|
-
}
|
|
1894
1737
|
} else if (protocol == "sse") {
|
|
1895
1738
|
fire_event({
|
|
1896
1739
|
type: "status",
|
|
@@ -2282,7 +2125,6 @@ class Client {
|
|
|
2282
2125
|
__publicField(this, "abort_controller", null);
|
|
2283
2126
|
__publicField(this, "stream_instance", null);
|
|
2284
2127
|
__publicField(this, "current_payload");
|
|
2285
|
-
__publicField(this, "ws_map", {});
|
|
2286
2128
|
__publicField(this, "view_api");
|
|
2287
2129
|
__publicField(this, "upload_files");
|
|
2288
2130
|
__publicField(this, "upload");
|
|
@@ -2375,8 +2217,8 @@ class Client {
|
|
|
2375
2217
|
headers.append(name, this.options.headers[name]);
|
|
2376
2218
|
}
|
|
2377
2219
|
}
|
|
2378
|
-
if (this && this.options.
|
|
2379
|
-
headers.append("Authorization", `Bearer ${this.options.
|
|
2220
|
+
if (this && this.options.token) {
|
|
2221
|
+
headers.append("Authorization", `Bearer ${this.options.token}`);
|
|
2380
2222
|
}
|
|
2381
2223
|
this.abort_controller = new AbortController();
|
|
2382
2224
|
this.stream_instance = readable_stream(url.toString(), {
|
|
@@ -2388,12 +2230,6 @@ class Client {
|
|
|
2388
2230
|
}
|
|
2389
2231
|
async init() {
|
|
2390
2232
|
var _a;
|
|
2391
|
-
if ((typeof window === "undefined" || !("WebSocket" in window)) && !global.WebSocket) {
|
|
2392
|
-
{
|
|
2393
|
-
const ws = await import("./wrapper-CpGUsf_3.js");
|
|
2394
|
-
global.WebSocket = ws.WebSocket;
|
|
2395
|
-
}
|
|
2396
|
-
}
|
|
2397
2233
|
if (this.options.auth) {
|
|
2398
2234
|
await this.resolve_cookies();
|
|
2399
2235
|
}
|
|
@@ -2408,17 +2244,17 @@ class Client {
|
|
|
2408
2244
|
this.config = _config;
|
|
2409
2245
|
this.api_prefix = _config.api_prefix || "";
|
|
2410
2246
|
if (this.config && this.config.connect_heartbeat) {
|
|
2411
|
-
if (this.config.space_id && this.options.
|
|
2247
|
+
if (this.config.space_id && this.options.token) {
|
|
2412
2248
|
this.jwt = await get_jwt(
|
|
2413
2249
|
this.config.space_id,
|
|
2414
|
-
this.options.
|
|
2250
|
+
this.options.token,
|
|
2415
2251
|
this.cookies
|
|
2416
2252
|
);
|
|
2417
2253
|
}
|
|
2418
2254
|
}
|
|
2419
2255
|
}
|
|
2420
|
-
if (_config.space_id && this.options.
|
|
2421
|
-
this.jwt = await get_jwt(_config.space_id, this.options.
|
|
2256
|
+
if (_config.space_id && this.options.token) {
|
|
2257
|
+
this.jwt = await get_jwt(_config.space_id, this.options.token);
|
|
2422
2258
|
}
|
|
2423
2259
|
if (this.config && this.config.connect_heartbeat) {
|
|
2424
2260
|
const heartbeat_url = new URL(
|
|
@@ -2476,7 +2312,7 @@ class Client {
|
|
|
2476
2312
|
async _resolve_config() {
|
|
2477
2313
|
const { http_protocol, host, space_id } = await process_endpoint(
|
|
2478
2314
|
this.app_reference,
|
|
2479
|
-
this.options.
|
|
2315
|
+
this.options.token
|
|
2480
2316
|
);
|
|
2481
2317
|
const { status_callback } = this.options;
|
|
2482
2318
|
if (space_id && status_callback) {
|
|
@@ -2557,10 +2393,10 @@ class Client {
|
|
|
2557
2393
|
throw new Error(CONFIG_ERROR_MSG);
|
|
2558
2394
|
}
|
|
2559
2395
|
const headers = {};
|
|
2560
|
-
const {
|
|
2396
|
+
const { token } = this.options;
|
|
2561
2397
|
const { session_hash } = this;
|
|
2562
|
-
if (
|
|
2563
|
-
headers.Authorization = `Bearer ${this.options.
|
|
2398
|
+
if (token) {
|
|
2399
|
+
headers.Authorization = `Bearer ${this.options.token}`;
|
|
2564
2400
|
}
|
|
2565
2401
|
let root_url;
|
|
2566
2402
|
let component = this.config.components.find(
|
|
@@ -2590,8 +2426,8 @@ class Client {
|
|
|
2590
2426
|
});
|
|
2591
2427
|
headers["Content-Type"] = "application/json";
|
|
2592
2428
|
}
|
|
2593
|
-
if (
|
|
2594
|
-
headers.Authorization = `Bearer ${
|
|
2429
|
+
if (token) {
|
|
2430
|
+
headers.Authorization = `Bearer ${token}`;
|
|
2595
2431
|
}
|
|
2596
2432
|
try {
|
|
2597
2433
|
const response = await this.fetch(
|
|
@@ -2626,55 +2462,6 @@ class Client {
|
|
|
2626
2462
|
component_server: this.component_server
|
|
2627
2463
|
};
|
|
2628
2464
|
}
|
|
2629
|
-
async connect_ws(url) {
|
|
2630
|
-
return new Promise((resolve, reject) => {
|
|
2631
|
-
let ws;
|
|
2632
|
-
try {
|
|
2633
|
-
ws = new WebSocket(url);
|
|
2634
|
-
} catch (e) {
|
|
2635
|
-
this.ws_map[url] = "failed";
|
|
2636
|
-
return;
|
|
2637
|
-
}
|
|
2638
|
-
this.ws_map[url] = "pending";
|
|
2639
|
-
ws.onopen = () => {
|
|
2640
|
-
this.ws_map[url] = ws;
|
|
2641
|
-
resolve();
|
|
2642
|
-
};
|
|
2643
|
-
ws.onerror = (error) => {
|
|
2644
|
-
console.error("WebSocket error:", error);
|
|
2645
|
-
this.close_ws(url);
|
|
2646
|
-
this.ws_map[url] = "failed";
|
|
2647
|
-
resolve();
|
|
2648
|
-
};
|
|
2649
|
-
ws.onclose = () => {
|
|
2650
|
-
this.ws_map[url] = "closed";
|
|
2651
|
-
};
|
|
2652
|
-
ws.onmessage = (event) => {
|
|
2653
|
-
};
|
|
2654
|
-
});
|
|
2655
|
-
}
|
|
2656
|
-
async send_ws_message(url, data) {
|
|
2657
|
-
if (!(url in this.ws_map)) {
|
|
2658
|
-
await this.connect_ws(url);
|
|
2659
|
-
} else if (this.ws_map[url] === "pending" || this.ws_map[url] === "closed" || this.ws_map[url] === "failed") {
|
|
2660
|
-
return;
|
|
2661
|
-
}
|
|
2662
|
-
const ws = this.ws_map[url];
|
|
2663
|
-
if (ws instanceof WebSocket) {
|
|
2664
|
-
ws.send(JSON.stringify(data));
|
|
2665
|
-
} else {
|
|
2666
|
-
this.post_data(url, data);
|
|
2667
|
-
}
|
|
2668
|
-
}
|
|
2669
|
-
async close_ws(url) {
|
|
2670
|
-
if (url in this.ws_map) {
|
|
2671
|
-
const ws = this.ws_map[url];
|
|
2672
|
-
if (ws instanceof WebSocket) {
|
|
2673
|
-
ws.close();
|
|
2674
|
-
delete this.ws_map[url];
|
|
2675
|
-
}
|
|
2676
|
-
}
|
|
2677
|
-
}
|
|
2678
2465
|
}
|
|
2679
2466
|
async function client(app_reference, options = {
|
|
2680
2467
|
events: ["data"]
|
package/dist/types.d.ts
CHANGED
|
@@ -243,7 +243,7 @@ export interface DuplicateOptions extends ClientOptions {
|
|
|
243
243
|
timeout?: number;
|
|
244
244
|
}
|
|
245
245
|
export interface ClientOptions {
|
|
246
|
-
|
|
246
|
+
token?: `hf_${string}`;
|
|
247
247
|
status_callback?: SpaceStatusCallback | null;
|
|
248
248
|
auth?: [string, string] | null;
|
|
249
249
|
with_null_state?: boolean;
|