@gradio/client 2.6.0 → 2.7.1
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 +16 -0
- package/dist/browser.js +374 -340
- package/dist/client.d.ts +1 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/helpers/data.d.ts +9 -0
- package/dist/helpers/data.d.ts.map +1 -1
- package/dist/helpers/init_helpers.d.ts.map +1 -1
- package/dist/index.cjs +70 -14
- package/dist/index.js +70 -14
- package/dist/index.min.js +414 -380
- package/dist/utils/submit.d.ts.map +1 -1
- package/dist/utils/view_api.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/client.ts +19 -15
- package/src/helpers/data.ts +77 -0
- package/src/helpers/init_helpers.ts +8 -10
- package/src/test/data.test.ts +95 -0
- package/src/test/init.test.ts +47 -1
- package/src/test/server.ts +3 -0
- package/src/test/submit.test.ts +77 -1
- package/src/utils/submit.ts +26 -10
- package/src/utils/view_api.ts +4 -1
package/dist/client.d.ts
CHANGED
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,WA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AAG,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/helpers/data.d.ts
CHANGED
|
@@ -18,4 +18,13 @@ export declare function handle_file(file_or_url: File | string | Blob | Buffer):
|
|
|
18
18
|
* @returns An array of resolved payload values, filtered based on the dependency and component metadata.
|
|
19
19
|
*/
|
|
20
20
|
export declare function handle_payload(resolved_payload: unknown[], dependency: Dependency, components: ComponentMeta[], type: "input" | "output", with_null_state?: boolean): unknown[];
|
|
21
|
+
/**
|
|
22
|
+
* Add the Space JWT required for browser-managed media requests.
|
|
23
|
+
*
|
|
24
|
+
* This is a bearer credential and must not be logged or persisted. Restrict it
|
|
25
|
+
* to Gradio routes that serve files; the user's Hugging Face token remains in
|
|
26
|
+
* the Authorization header used to obtain this credential.
|
|
27
|
+
*/
|
|
28
|
+
export declare function sign_file_urls(data: unknown, root: string, api_prefix: string, jwt: string | false): void;
|
|
29
|
+
export declare function sign_config_file_urls(config: Config, jwt: string | false): void;
|
|
21
30
|
//# sourceMappingURL=data.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data.d.ts","sourceRoot":"","sources":["../../src/helpers/data.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,KAAK,OAAO,EACZ,KAAK,OAAO,EACZ,KAAK,MAAM,EACX,KAAK,YAAY,EACjB,KAAK,SAAS,EACd,KAAK,QAAQ,EACb,OAAO,EACP,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,MAAM,UAAU,CAAC;AAClB,OAAO,EAA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KAAK,GACjB,IAAI,CA+CN;AAED,wBAAgB,qBAAqB,CACpC,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,GAAG,KAAK,GACjB,IAAI,CASN"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init_helpers.d.ts","sourceRoot":"","sources":["../../src/helpers/init_helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAWtD,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;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,aAAa,GAAG,IAAI,CAOnE;AAED,wBAAgB,gBAAgB,CAC/B,GAAG,EAAE,MAAM,CAAC,cAAc,CAAC,GACzB,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAOxB;AAED,wBAAgB,mBAAmB,CAClC,IAAI,EAAE,MAAM,EACZ,gBAAgB,EAAE,MAAM,EACxB,2BAA2B,UAAQ,GACjC,MAAM,CAqBR;AAED,wBAAsB,cAAc,CACnC,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,MAAM,EAChB,kBAAkB,UAAO,GACvB,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,
|
|
1
|
+
{"version":3,"file":"init_helpers.d.ts","sourceRoot":"","sources":["../../src/helpers/init_helpers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,EAAE,M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ACrD,WAAW,EAAE,IAAI,GAAG,KAAK,CAAC;IAC1B,aAAa,EAAE,OAAO,GAAG,QAAQ,CAAC;IAClC,IAAI,EAAE,MAAM,CAAC;CACb,CAkBA;AAED,eAAO,MAAM,qBAAqB,GAAI,eAAe,MAAM,KAAG,MAAM,EAUnE,CAAC"}
|
package/dist/index.cjs
CHANGED
|
@@ -78,7 +78,9 @@ async function resolve_config(endpoint, strip_current_page = true) {
|
|
|
78
78
|
if (typeof window !== "undefined" && window.gradio_config && location.origin !== "http://localhost:9876") {
|
|
79
79
|
if (strip_current_page && window.gradio_config.current_page) endpoint = endpoint.substring(0, endpoint.lastIndexOf("/"));
|
|
80
80
|
if (window.gradio_config.dev_mode || typeof window !== "undefined" && window?.BUILD_MODE === "dev") {
|
|
81
|
-
let config_url = join_urls(endpoint,
|
|
81
|
+
let config_url = new URL(join_urls(endpoint, CONFIG_URL));
|
|
82
|
+
if (this.deep_link) config_url.searchParams.set("deep_link", this.deep_link);
|
|
83
|
+
if (this.page !== null) config_url.searchParams.set("page", this.page);
|
|
82
84
|
const config = await handleConfigResponse(await this.fetch(config_url, {
|
|
83
85
|
headers,
|
|
84
86
|
credentials: this.options.credentials ?? "same-origin"
|
|
@@ -93,7 +95,9 @@ async function resolve_config(endpoint, strip_current_page = true) {
|
|
|
93
95
|
config.root = resolve_config_root(config.root, location.href, config.is_colab);
|
|
94
96
|
return config;
|
|
95
97
|
} else if (endpoint) {
|
|
96
|
-
let config_url = join_urls(endpoint,
|
|
98
|
+
let config_url = new URL(join_urls(endpoint, CONFIG_URL));
|
|
99
|
+
if (this.deep_link) config_url.searchParams.set("deep_link", this.deep_link);
|
|
100
|
+
if (this.page !== null) config_url.searchParams.set("page", this.page);
|
|
97
101
|
const config = await handleConfigResponse(await this.fetch(config_url, {
|
|
98
102
|
headers,
|
|
99
103
|
credentials: this.options.credentials ?? "same-origin"
|
|
@@ -492,7 +496,8 @@ async function view_api() {
|
|
|
492
496
|
let api_info;
|
|
493
497
|
if (typeof window !== "undefined" && window.gradio_api_info) api_info = window.gradio_api_info;
|
|
494
498
|
else {
|
|
495
|
-
const url = join_urls(config.root, this.api_prefix, API_INFO_URL);
|
|
499
|
+
const url = new URL(join_urls(config.root, this.api_prefix, API_INFO_URL));
|
|
500
|
+
if (this.page !== null) url.searchParams.set("page", this.page);
|
|
496
501
|
response = await this.fetch(url, {
|
|
497
502
|
headers,
|
|
498
503
|
credentials: this.options.credentials ?? "same-origin"
|
|
@@ -778,6 +783,48 @@ function handle_payload(resolved_payload, dependency, components, type, with_nul
|
|
|
778
783
|
}
|
|
779
784
|
return updated_payload;
|
|
780
785
|
}
|
|
786
|
+
var FILE_ROUTE_PREFIXES = [
|
|
787
|
+
"/file=",
|
|
788
|
+
"/file/",
|
|
789
|
+
"/stream/",
|
|
790
|
+
"/proxy="
|
|
791
|
+
];
|
|
792
|
+
/**
|
|
793
|
+
* Add the Space JWT required for browser-managed media requests.
|
|
794
|
+
*
|
|
795
|
+
* This is a bearer credential and must not be logged or persisted. Restrict it
|
|
796
|
+
* to Gradio routes that serve files; the user's Hugging Face token remains in
|
|
797
|
+
* the Authorization header used to obtain this credential.
|
|
798
|
+
*/
|
|
799
|
+
function sign_file_urls(data, root, api_prefix, jwt) {
|
|
800
|
+
if (!jwt || data === null || typeof data !== "object") return;
|
|
801
|
+
const signature = jwt;
|
|
802
|
+
const root_url = new URL(root);
|
|
803
|
+
const root_path = root_url.pathname.replace(/\/+$/, "");
|
|
804
|
+
const normalized_api_prefix = api_prefix ? `/${api_prefix.replace(/^\/+|\/+$/g, "")}` : "";
|
|
805
|
+
const route_bases = new Set([`${root_path}${normalized_api_prefix}`, normalized_api_prefix]);
|
|
806
|
+
if (!normalized_api_prefix) {
|
|
807
|
+
route_bases.add(`${root_path}/gradio_api`);
|
|
808
|
+
route_bases.add("/gradio_api");
|
|
809
|
+
}
|
|
810
|
+
function visit(value) {
|
|
811
|
+
if (value === null || typeof value !== "object") return;
|
|
812
|
+
const object = value;
|
|
813
|
+
if (object.meta?._type === "gradio.FileData" && typeof object.url === "string") {
|
|
814
|
+
const file_url = new URL(object.url, `${root_url.toString().replace(/\/$/, "")}/`);
|
|
815
|
+
const is_file_route = [...route_bases].some((base) => FILE_ROUTE_PREFIXES.some((route) => file_url.pathname.startsWith(`${base}${route}`)));
|
|
816
|
+
if ((file_url.protocol === "http:" || file_url.protocol === "https:") && file_url.origin === root_url.origin && is_file_route) {
|
|
817
|
+
file_url.searchParams.set("__sign", signature);
|
|
818
|
+
object.url = file_url.toString();
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
for (const child of Object.values(object)) visit(child);
|
|
822
|
+
}
|
|
823
|
+
visit(data);
|
|
824
|
+
}
|
|
825
|
+
function sign_config_file_urls(config, jwt) {
|
|
826
|
+
for (const component of config.components || []) sign_file_urls(component.props?.value, config.root, config.api_prefix || "", jwt);
|
|
827
|
+
}
|
|
781
828
|
//#endregion
|
|
782
829
|
//#region src/utils/handle_blob.ts
|
|
783
830
|
async function handle_blob(endpoint, data, api_info) {
|
|
@@ -1778,6 +1825,7 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events, additio
|
|
|
1778
1825
|
const that = this;
|
|
1779
1826
|
if (!api_info) throw new Error(NO_API_INFO_MSG);
|
|
1780
1827
|
if (!config) throw new Error("Could not resolve app config");
|
|
1828
|
+
const root = config.root;
|
|
1781
1829
|
let { fn_index, endpoint_info, dependency } = get_endpoint_info(api_info, endpoint, api_map, config);
|
|
1782
1830
|
let resolved_data = map_data_to_params(data, endpoint_info);
|
|
1783
1831
|
let protocol = config.protocol ?? "ws";
|
|
@@ -1827,6 +1875,7 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events, additio
|
|
|
1827
1875
|
}, {}) || {};
|
|
1828
1876
|
function fire_event(event) {
|
|
1829
1877
|
update_run_history(history_scope, history_run_id, event);
|
|
1878
|
+
if (event.type === "data" || event.type === "render") sign_file_urls(event.data, root, api_prefix, that.jwt);
|
|
1830
1879
|
if (all_events || events_to_publish[event.type]) push_event(event);
|
|
1831
1880
|
}
|
|
1832
1881
|
async function cancel() {
|
|
@@ -2260,6 +2309,12 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events, additio
|
|
|
2260
2309
|
});
|
|
2261
2310
|
return new Promise((resolve) => resolvers.push(resolve));
|
|
2262
2311
|
}
|
|
2312
|
+
const post_to_event = (suffix, body) => {
|
|
2313
|
+
job.then(() => {
|
|
2314
|
+
if (!event_id_final) return;
|
|
2315
|
+
this.post_data(`${config.root}${api_prefix}/stream/${event_id_final}${suffix}`, body);
|
|
2316
|
+
}, () => {});
|
|
2317
|
+
};
|
|
2263
2318
|
const iterator = {
|
|
2264
2319
|
[Symbol.asyncIterator]: () => iterator,
|
|
2265
2320
|
next,
|
|
@@ -2276,14 +2331,14 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events, additio
|
|
|
2276
2331
|
},
|
|
2277
2332
|
cancel,
|
|
2278
2333
|
send_chunk: (payload) => {
|
|
2279
|
-
|
|
2334
|
+
post_to_event("", {
|
|
2280
2335
|
...payload,
|
|
2281
2336
|
session_hash: this.session_hash
|
|
2282
2337
|
});
|
|
2283
2338
|
},
|
|
2284
2339
|
close_stream: () => {
|
|
2285
|
-
this.post_data(`${config.root}${api_prefix}/stream/${event_id_final}/close`, {});
|
|
2286
2340
|
close();
|
|
2341
|
+
post_to_event("/close", {});
|
|
2287
2342
|
},
|
|
2288
2343
|
event_id: () => event_id_final,
|
|
2289
2344
|
wait_for_id: async () => {
|
|
@@ -2330,6 +2385,7 @@ var Client = class {
|
|
|
2330
2385
|
app_reference;
|
|
2331
2386
|
options;
|
|
2332
2387
|
deep_link = null;
|
|
2388
|
+
page = null;
|
|
2333
2389
|
config;
|
|
2334
2390
|
api_prefix = "";
|
|
2335
2391
|
api_info;
|
|
@@ -2410,6 +2466,7 @@ var Client = class {
|
|
|
2410
2466
|
constructor(app_reference, options = { events: ["data"] }) {
|
|
2411
2467
|
this.app_reference = app_reference;
|
|
2412
2468
|
this.deep_link = options.query_params?.deep_link || null;
|
|
2469
|
+
this.page = options.query_params?.page ?? null;
|
|
2413
2470
|
if (!options.events) options.events = ["data"];
|
|
2414
2471
|
normalise_token_option(options);
|
|
2415
2472
|
this.options = options;
|
|
@@ -2441,14 +2498,10 @@ var Client = class {
|
|
|
2441
2498
|
this.api_map = map_names_to_ids(this.config?.dependencies || []);
|
|
2442
2499
|
}
|
|
2443
2500
|
async _resolve_heartbeat(_config) {
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
|
|
2448
|
-
if (this.config.space_id && this.options.token) this.jwt = await get_jwt(this.config.space_id, this.options.token, this.cookies);
|
|
2449
|
-
}
|
|
2450
|
-
}
|
|
2451
|
-
if (_config.space_id && this.options.token) this.jwt = await get_jwt(_config.space_id, this.options.token);
|
|
2501
|
+
this.config = _config;
|
|
2502
|
+
this.api_prefix = _config.api_prefix || "";
|
|
2503
|
+
if (_config.space_id && this.options.token) this.jwt = await get_jwt(_config.space_id, this.options.token, this.cookies);
|
|
2504
|
+
sign_config_file_urls(this.config, this.jwt);
|
|
2452
2505
|
if (this.config && this.config.connect_heartbeat) {
|
|
2453
2506
|
const heartbeat_url = new URL(`${this.config.root}${this.api_prefix}/${HEARTBEAT_URL}/${this.session_hash}`);
|
|
2454
2507
|
if (this.jwt) heartbeat_url.searchParams.set("__sign", this.jwt);
|
|
@@ -2489,6 +2542,7 @@ var Client = class {
|
|
|
2489
2542
|
this.config = config;
|
|
2490
2543
|
this.api_prefix = config.api_prefix || "";
|
|
2491
2544
|
this.api_map = map_names_to_ids(config.dependencies || []);
|
|
2545
|
+
sign_config_file_urls(this.config, this.jwt);
|
|
2492
2546
|
try {
|
|
2493
2547
|
this.api_info = await this.view_api();
|
|
2494
2548
|
} catch (e) {
|
|
@@ -2598,7 +2652,9 @@ var Client = class {
|
|
|
2598
2652
|
credentials: this.options.credentials ?? "same-origin"
|
|
2599
2653
|
});
|
|
2600
2654
|
if (!response.ok) throw new Error("Could not connect to component server: " + response.statusText);
|
|
2601
|
-
|
|
2655
|
+
const output = await response.json();
|
|
2656
|
+
sign_file_urls(output, this.config.root, this.config.api_prefix || "", this.jwt);
|
|
2657
|
+
return output;
|
|
2602
2658
|
} catch (e) {
|
|
2603
2659
|
console.warn(e);
|
|
2604
2660
|
}
|
package/dist/index.js
CHANGED
|
@@ -77,7 +77,9 @@ async function resolve_config(endpoint, strip_current_page = true) {
|
|
|
77
77
|
if (typeof window !== "undefined" && window.gradio_config && location.origin !== "http://localhost:9876") {
|
|
78
78
|
if (strip_current_page && window.gradio_config.current_page) endpoint = endpoint.substring(0, endpoint.lastIndexOf("/"));
|
|
79
79
|
if (window.gradio_config.dev_mode || typeof window !== "undefined" && window?.BUILD_MODE === "dev") {
|
|
80
|
-
let config_url = join_urls(endpoint,
|
|
80
|
+
let config_url = new URL(join_urls(endpoint, CONFIG_URL));
|
|
81
|
+
if (this.deep_link) config_url.searchParams.set("deep_link", this.deep_link);
|
|
82
|
+
if (this.page !== null) config_url.searchParams.set("page", this.page);
|
|
81
83
|
const config = await handleConfigResponse(await this.fetch(config_url, {
|
|
82
84
|
headers,
|
|
83
85
|
credentials: this.options.credentials ?? "same-origin"
|
|
@@ -92,7 +94,9 @@ async function resolve_config(endpoint, strip_current_page = true) {
|
|
|
92
94
|
config.root = resolve_config_root(config.root, location.href, config.is_colab);
|
|
93
95
|
return config;
|
|
94
96
|
} else if (endpoint) {
|
|
95
|
-
let config_url = join_urls(endpoint,
|
|
97
|
+
let config_url = new URL(join_urls(endpoint, CONFIG_URL));
|
|
98
|
+
if (this.deep_link) config_url.searchParams.set("deep_link", this.deep_link);
|
|
99
|
+
if (this.page !== null) config_url.searchParams.set("page", this.page);
|
|
96
100
|
const config = await handleConfigResponse(await this.fetch(config_url, {
|
|
97
101
|
headers,
|
|
98
102
|
credentials: this.options.credentials ?? "same-origin"
|
|
@@ -491,7 +495,8 @@ async function view_api() {
|
|
|
491
495
|
let api_info;
|
|
492
496
|
if (typeof window !== "undefined" && window.gradio_api_info) api_info = window.gradio_api_info;
|
|
493
497
|
else {
|
|
494
|
-
const url = join_urls(config.root, this.api_prefix, API_INFO_URL);
|
|
498
|
+
const url = new URL(join_urls(config.root, this.api_prefix, API_INFO_URL));
|
|
499
|
+
if (this.page !== null) url.searchParams.set("page", this.page);
|
|
495
500
|
response = await this.fetch(url, {
|
|
496
501
|
headers,
|
|
497
502
|
credentials: this.options.credentials ?? "same-origin"
|
|
@@ -777,6 +782,48 @@ function handle_payload(resolved_payload, dependency, components, type, with_nul
|
|
|
777
782
|
}
|
|
778
783
|
return updated_payload;
|
|
779
784
|
}
|
|
785
|
+
var FILE_ROUTE_PREFIXES = [
|
|
786
|
+
"/file=",
|
|
787
|
+
"/file/",
|
|
788
|
+
"/stream/",
|
|
789
|
+
"/proxy="
|
|
790
|
+
];
|
|
791
|
+
/**
|
|
792
|
+
* Add the Space JWT required for browser-managed media requests.
|
|
793
|
+
*
|
|
794
|
+
* This is a bearer credential and must not be logged or persisted. Restrict it
|
|
795
|
+
* to Gradio routes that serve files; the user's Hugging Face token remains in
|
|
796
|
+
* the Authorization header used to obtain this credential.
|
|
797
|
+
*/
|
|
798
|
+
function sign_file_urls(data, root, api_prefix, jwt) {
|
|
799
|
+
if (!jwt || data === null || typeof data !== "object") return;
|
|
800
|
+
const signature = jwt;
|
|
801
|
+
const root_url = new URL(root);
|
|
802
|
+
const root_path = root_url.pathname.replace(/\/+$/, "");
|
|
803
|
+
const normalized_api_prefix = api_prefix ? `/${api_prefix.replace(/^\/+|\/+$/g, "")}` : "";
|
|
804
|
+
const route_bases = new Set([`${root_path}${normalized_api_prefix}`, normalized_api_prefix]);
|
|
805
|
+
if (!normalized_api_prefix) {
|
|
806
|
+
route_bases.add(`${root_path}/gradio_api`);
|
|
807
|
+
route_bases.add("/gradio_api");
|
|
808
|
+
}
|
|
809
|
+
function visit(value) {
|
|
810
|
+
if (value === null || typeof value !== "object") return;
|
|
811
|
+
const object = value;
|
|
812
|
+
if (object.meta?._type === "gradio.FileData" && typeof object.url === "string") {
|
|
813
|
+
const file_url = new URL(object.url, `${root_url.toString().replace(/\/$/, "")}/`);
|
|
814
|
+
const is_file_route = [...route_bases].some((base) => FILE_ROUTE_PREFIXES.some((route) => file_url.pathname.startsWith(`${base}${route}`)));
|
|
815
|
+
if ((file_url.protocol === "http:" || file_url.protocol === "https:") && file_url.origin === root_url.origin && is_file_route) {
|
|
816
|
+
file_url.searchParams.set("__sign", signature);
|
|
817
|
+
object.url = file_url.toString();
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
for (const child of Object.values(object)) visit(child);
|
|
821
|
+
}
|
|
822
|
+
visit(data);
|
|
823
|
+
}
|
|
824
|
+
function sign_config_file_urls(config, jwt) {
|
|
825
|
+
for (const component of config.components || []) sign_file_urls(component.props?.value, config.root, config.api_prefix || "", jwt);
|
|
826
|
+
}
|
|
780
827
|
//#endregion
|
|
781
828
|
//#region src/utils/handle_blob.ts
|
|
782
829
|
async function handle_blob(endpoint, data, api_info) {
|
|
@@ -1777,6 +1824,7 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events, additio
|
|
|
1777
1824
|
const that = this;
|
|
1778
1825
|
if (!api_info) throw new Error(NO_API_INFO_MSG);
|
|
1779
1826
|
if (!config) throw new Error("Could not resolve app config");
|
|
1827
|
+
const root = config.root;
|
|
1780
1828
|
let { fn_index, endpoint_info, dependency } = get_endpoint_info(api_info, endpoint, api_map, config);
|
|
1781
1829
|
let resolved_data = map_data_to_params(data, endpoint_info);
|
|
1782
1830
|
let protocol = config.protocol ?? "ws";
|
|
@@ -1826,6 +1874,7 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events, additio
|
|
|
1826
1874
|
}, {}) || {};
|
|
1827
1875
|
function fire_event(event) {
|
|
1828
1876
|
update_run_history(history_scope, history_run_id, event);
|
|
1877
|
+
if (event.type === "data" || event.type === "render") sign_file_urls(event.data, root, api_prefix, that.jwt);
|
|
1829
1878
|
if (all_events || events_to_publish[event.type]) push_event(event);
|
|
1830
1879
|
}
|
|
1831
1880
|
async function cancel() {
|
|
@@ -2259,6 +2308,12 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events, additio
|
|
|
2259
2308
|
});
|
|
2260
2309
|
return new Promise((resolve) => resolvers.push(resolve));
|
|
2261
2310
|
}
|
|
2311
|
+
const post_to_event = (suffix, body) => {
|
|
2312
|
+
job.then(() => {
|
|
2313
|
+
if (!event_id_final) return;
|
|
2314
|
+
this.post_data(`${config.root}${api_prefix}/stream/${event_id_final}${suffix}`, body);
|
|
2315
|
+
}, () => {});
|
|
2316
|
+
};
|
|
2262
2317
|
const iterator = {
|
|
2263
2318
|
[Symbol.asyncIterator]: () => iterator,
|
|
2264
2319
|
next,
|
|
@@ -2275,14 +2330,14 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events, additio
|
|
|
2275
2330
|
},
|
|
2276
2331
|
cancel,
|
|
2277
2332
|
send_chunk: (payload) => {
|
|
2278
|
-
|
|
2333
|
+
post_to_event("", {
|
|
2279
2334
|
...payload,
|
|
2280
2335
|
session_hash: this.session_hash
|
|
2281
2336
|
});
|
|
2282
2337
|
},
|
|
2283
2338
|
close_stream: () => {
|
|
2284
|
-
this.post_data(`${config.root}${api_prefix}/stream/${event_id_final}/close`, {});
|
|
2285
2339
|
close();
|
|
2340
|
+
post_to_event("/close", {});
|
|
2286
2341
|
},
|
|
2287
2342
|
event_id: () => event_id_final,
|
|
2288
2343
|
wait_for_id: async () => {
|
|
@@ -2329,6 +2384,7 @@ var Client = class {
|
|
|
2329
2384
|
app_reference;
|
|
2330
2385
|
options;
|
|
2331
2386
|
deep_link = null;
|
|
2387
|
+
page = null;
|
|
2332
2388
|
config;
|
|
2333
2389
|
api_prefix = "";
|
|
2334
2390
|
api_info;
|
|
@@ -2409,6 +2465,7 @@ var Client = class {
|
|
|
2409
2465
|
constructor(app_reference, options = { events: ["data"] }) {
|
|
2410
2466
|
this.app_reference = app_reference;
|
|
2411
2467
|
this.deep_link = options.query_params?.deep_link || null;
|
|
2468
|
+
this.page = options.query_params?.page ?? null;
|
|
2412
2469
|
if (!options.events) options.events = ["data"];
|
|
2413
2470
|
normalise_token_option(options);
|
|
2414
2471
|
this.options = options;
|
|
@@ -2440,14 +2497,10 @@ var Client = class {
|
|
|
2440
2497
|
this.api_map = map_names_to_ids(this.config?.dependencies || []);
|
|
2441
2498
|
}
|
|
2442
2499
|
async _resolve_heartbeat(_config) {
|
|
2443
|
-
|
|
2444
|
-
|
|
2445
|
-
|
|
2446
|
-
|
|
2447
|
-
if (this.config.space_id && this.options.token) this.jwt = await get_jwt(this.config.space_id, this.options.token, this.cookies);
|
|
2448
|
-
}
|
|
2449
|
-
}
|
|
2450
|
-
if (_config.space_id && this.options.token) this.jwt = await get_jwt(_config.space_id, this.options.token);
|
|
2500
|
+
this.config = _config;
|
|
2501
|
+
this.api_prefix = _config.api_prefix || "";
|
|
2502
|
+
if (_config.space_id && this.options.token) this.jwt = await get_jwt(_config.space_id, this.options.token, this.cookies);
|
|
2503
|
+
sign_config_file_urls(this.config, this.jwt);
|
|
2451
2504
|
if (this.config && this.config.connect_heartbeat) {
|
|
2452
2505
|
const heartbeat_url = new URL(`${this.config.root}${this.api_prefix}/${HEARTBEAT_URL}/${this.session_hash}`);
|
|
2453
2506
|
if (this.jwt) heartbeat_url.searchParams.set("__sign", this.jwt);
|
|
@@ -2488,6 +2541,7 @@ var Client = class {
|
|
|
2488
2541
|
this.config = config;
|
|
2489
2542
|
this.api_prefix = config.api_prefix || "";
|
|
2490
2543
|
this.api_map = map_names_to_ids(config.dependencies || []);
|
|
2544
|
+
sign_config_file_urls(this.config, this.jwt);
|
|
2491
2545
|
try {
|
|
2492
2546
|
this.api_info = await this.view_api();
|
|
2493
2547
|
} catch (e) {
|
|
@@ -2597,7 +2651,9 @@ var Client = class {
|
|
|
2597
2651
|
credentials: this.options.credentials ?? "same-origin"
|
|
2598
2652
|
});
|
|
2599
2653
|
if (!response.ok) throw new Error("Could not connect to component server: " + response.statusText);
|
|
2600
|
-
|
|
2654
|
+
const output = await response.json();
|
|
2655
|
+
sign_file_urls(output, this.config.root, this.config.api_prefix || "", this.jwt);
|
|
2656
|
+
return output;
|
|
2601
2657
|
} catch (e) {
|
|
2602
2658
|
console.warn(e);
|
|
2603
2659
|
}
|