@gradio/client 0.1.1 → 0.1.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 CHANGED
@@ -1,5 +1,15 @@
1
1
  # @gradio/client
2
2
 
3
+ ## 0.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [#4273](https://github.com/gradio-app/gradio/pull/4273) [`1d0f0a9d`](https://github.com/gradio-app/gradio/commit/1d0f0a9db096552e67eb2197c932342587e9e61e) Thanks [@pngwn](https://github.com/pngwn)! - Ensure websocket error messages are correctly handled.
8
+
9
+ - [#4315](https://github.com/gradio-app/gradio/pull/4315) [`b525b122`](https://github.com/gradio-app/gradio/commit/b525b122dd8569bbaf7e06db5b90d622d2e9073d) Thanks [@whitphx](https://github.com/whitphx)! - Refacor types.
10
+
11
+ - [#4271](https://github.com/gradio-app/gradio/pull/4271) [`1151c525`](https://github.com/gradio-app/gradio/commit/1151c5253554cb87ebd4a44a8a470ac215ff782b) Thanks [@pngwn](https://github.com/pngwn)! - Ensure the full root path is always respected when making requests to a gradio app server.
12
+
3
13
  ## 0.1.1
4
14
 
5
15
  ### Patch Changes
package/README.md CHANGED
@@ -206,7 +206,7 @@ submission.off("/predict", handle_data);
206
206
 
207
207
  ##### `destroy`
208
208
 
209
- The `destroy` method will remove all subscriptions to a job, regardless of whether or not they are `"data"` or `"status"` events. This is a convenience method for when you do not wnat to unsubscribe use the `off` method.
209
+ The `destroy` method will remove all subscriptions to a job, regardless of whether or not they are `"data"` or `"status"` events. This is a convenience method for when you do not want to unsubscribe use the `off` method.
210
210
 
211
211
  ```js
212
212
  import { client } from "@gradio/client";
@@ -239,7 +239,7 @@ submission.cancel();
239
239
 
240
240
  #### `view_api`
241
241
 
242
- The `view_api` method provides details about the API you are connected too. It returns a JavaScript object of all named endpoints, unnamed endpoints and what values they accept and return. This method does not accept arguments.
242
+ The `view_api` method provides details about the API you are connected to. It returns a JavaScript object of all named endpoints, unnamed endpoints and what values they accept and return. This method does not accept arguments.
243
243
 
244
244
  ```ts
245
245
  import { client } from "@gradio/client";
package/dist/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { hardware_types } from "./utils.js";
2
- import type { EventType, EventListener, PostResponse, UploadResponse, SpaceStatusCallback, FileData } from "./types.js";
2
+ import type { EventType, EventListener, PostResponse, UploadResponse, SpaceStatusCallback } from "./types.js";
3
3
  import type { Config } from "./types.js";
4
4
  declare type event = <K extends EventType>(eventType: K, listener: EventListener<K>) => SubmitReturn;
5
5
  declare type predict = (endpoint: string | number, data?: unknown[], event_data?: unknown) => Promise<unknown>;
@@ -30,7 +30,6 @@ export declare function client(app_reference: string, options?: {
30
30
  status_callback?: SpaceStatusCallback;
31
31
  normalise_files?: boolean;
32
32
  }): Promise<client_return>;
33
- export declare function normalise_file(file: Array<FileData> | FileData | string | null, root: string, root_url: string | null): Array<FileData> | FileData | null;
34
33
  export declare function handle_blob(endpoint: string, data: unknown[], api_info: any, token?: `hf_${string}`): Promise<unknown[]>;
35
34
  export declare function walk_and_store_blobs(param: any, type?: any, path?: any[], root?: boolean, api_info?: any): Promise<any[]>;
36
35
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAEA,OAAO,EAQN,cAAc,EACd,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EACX,SAAS,EACT,aAAa,EAIb,YAAY,EACZ,cAAc,EAGd,mBAAmB,EACnB,QAAQ,EACR,MAAM,YAAY,CAAC;AAEpB,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEzC,aAAK,KAAK,GAAG,CAAC,CAAC,SAAS,SAAS,EAChC,SAAS,EAAE,CAAC,EACZ,QAAQ,EAAE,aAAa,CAAC,CAAC,CAAC,KACtB,YAAY,CAAC;AAClB,aAAK,OAAO,GAAG,CACd,QAAQ,EAAE,MAAM,GAAG,MAAM,EACzB,IAAI,CAAC,E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AC;IACrC,QAAQ,CAAC,EAAE,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC;IACzC,OAAO,CAAC,EAAE,MAAM,CAAC;CACjB,0BAyED;AAED,wBAAsB,MAAM,CAC3B,aAAa,EAAE,MAAM,EACrB,OAAO,GAAE;IACR,QAAQ,CAAC,EAAE,MAAM,MAAM,EAAE,CAAC;IAC1B,eAAe,CAAC,EAAE,mBAAmB,CAAC;IACtC,eAAe,CAAC,EAAE,OAAO,CAAC;CACE,GAC3B,OAAO,CAAC,aAAa,CAAC,CA6dxB;AAkOD,wBAAsB,WAAW,CAChC,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,OAAO,EAAE,EACf,QAAQ,KAAA,EACR,KAAK,CAAC,EAAE,MAAM,MAAM,EAAE,GACpB,OAAO,CAAC,OAAO,EAAE,CAAC,CA0CpB;AAUD,wBAAsB,oBAAoB,CACzC,KAAK,KAAA,EACL,IAAI,MAAY,EAChB,IAAI,QAAK,EACT,IAAI,UAAQ,EACZ,QAAQ,MAAY,kBAyEpB"}
package/dist/index.js CHANGED
@@ -400,7 +400,7 @@ async function client(app_reference, options = { normalise_files: true }) {
400
400
  },
401
401
  hf_token
402
402
  ).then(([output, status_code]) => {
403
- transform_files ? transform_output(
403
+ const data2 = transform_files ? transform_output(
404
404
  output.data,
405
405
  api_info,
406
406
  config.root,
@@ -411,7 +411,7 @@ async function client(app_reference, options = { normalise_files: true }) {
411
411
  type: "data",
412
412
  endpoint: _endpoint,
413
413
  fn_index,
414
- data: output.data,
414
+ data: data2,
415
415
  time: /* @__PURE__ */ new Date()
416
416
  });
417
417
  fire_event({
@@ -630,7 +630,7 @@ async function client(app_reference, options = { normalise_files: true }) {
630
630
  }
631
631
  );
632
632
  } else {
633
- response = await fetch(`${http_protocol}//${host}/info`, {
633
+ response = await fetch(`${config2.root}/info`, {
634
634
  headers
635
635
  });
636
636
  }
@@ -1045,18 +1045,31 @@ function handle_message(data, last_status) {
1045
1045
  data: data.success ? data.output : null
1046
1046
  };
1047
1047
  case "process_completed":
1048
- return {
1049
- type: "complete",
1050
- status: {
1051
- queue,
1052
- message: !data.success ? data.output.error : void 0,
1053
- stage: data.success ? "complete" : "error",
1054
- code: data.code,
1055
- progress_data: data.progress_data,
1056
- eta: data.output.average_duration
1057
- },
1058
- data: data.success ? data.output : null
1059
- };
1048
+ if ("error" in data.output) {
1049
+ return {
1050
+ type: "update",
1051
+ status: {
1052
+ queue,
1053
+ message: data.output.error,
1054
+ stage: "error",
1055
+ code: data.code,
1056
+ success: data.success
1057
+ }
1058
+ };
1059
+ } else {
1060
+ return {
1061
+ type: "complete",
1062
+ status: {
1063
+ queue,
1064
+ message: !data.success ? data.output.error : void 0,
1065
+ stage: data.success ? "complete" : "error",
1066
+ code: data.code,
1067
+ progress_data: data.progress_data,
1068
+ eta: data.output.average_duration
1069
+ },
1070
+ data: data.success ? data.output : null
1071
+ };
1072
+ }
1060
1073
  case "process_starts":
1061
1074
  return {
1062
1075
  type: "update",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gradio/client",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Gradio UI packages",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
package/src/client.ts CHANGED
@@ -399,7 +399,7 @@ export async function client(
399
399
  type: "data",
400
400
  endpoint: _endpoint,
401
401
  fn_index,
402
- data: output.data,
402
+ data: data,
403
403
  time: new Date()
404
404
  });
405
405
 
@@ -655,7 +655,7 @@ export async function client(
655
655
  }
656
656
  );
657
657
  } else {
658
- response = await fetch(`${http_protocol}//${host}/info`, {
658
+ response = await fetch(`${config.root}/info`, {
659
659
  headers
660
660
  });
661
661
  }
@@ -708,10 +708,25 @@ function transform_output(
708
708
  return transformed_data;
709
709
  }
710
710
 
711
- export function normalise_file(
712
- file: Array<FileData> | FileData | string | null,
711
+ function normalise_file(
712
+ file: Array<FileData>,
713
713
  root: string,
714
714
  root_url: string | null
715
+ ): Array<FileData>;
716
+ function normalise_file(
717
+ file: FileData | string,
718
+ root: string,
719
+ root_url: string | null
720
+ ): FileData;
721
+ function normalise_file(
722
+ file: null,
723
+ root: string,
724
+ root_url: string | null
725
+ ): null;
726
+ function normalise_file(
727
+ file,
728
+ root,
729
+ root_url
715
730
  ): Array<FileData> | FileData | null {
716
731
  if (file == null) return null;
717
732
  if (typeof file === "string") {
@@ -726,7 +741,6 @@ export function normalise_file(
726
741
  if (x === null) {
727
742
  normalized_file.push(null);
728
743
  } else {
729
- //@ts-ignore
730
744
  normalized_file.push(normalise_file(x, root, root_url));
731
745
  }
732
746
  }
@@ -1226,18 +1240,32 @@ function handle_message(
1226
1240
  data: data.success ? data.output : null
1227
1241
  };
1228
1242
  case "process_completed":
1229
- return {
1230
- type: "complete",
1231
- status: {
1232
- queue,
1233
- message: !data.success ? data.output.error : undefined,
1234
- stage: data.success ? "complete" : "error",
1235
- code: data.code,
1236
- progress_data: data.progress_data,
1237
- eta: data.output.average_duration
1238
- },
1239
- data: data.success ? data.output : null
1240
- };
1243
+ if ("error" in data.output) {
1244
+ return {
1245
+ type: "update",
1246
+ status: {
1247
+ queue,
1248
+ message: data.output.error as string,
1249
+ stage: "error",
1250
+ code: data.code,
1251
+ success: data.success
1252
+ }
1253
+ };
1254
+ } else {
1255
+ return {
1256
+ type: "complete",
1257
+ status: {
1258
+ queue,
1259
+ message: !data.success ? data.output.error : undefined,
1260
+ stage: data.success ? "complete" : "error",
1261
+ code: data.code,
1262
+ progress_data: data.progress_data,
1263
+ eta: data.output.average_duration
1264
+ },
1265
+ data: data.success ? data.output : null
1266
+ };
1267
+ }
1268
+
1241
1269
  case "process_starts":
1242
1270
  return {
1243
1271
  type: "update",