@gradio/client 2.2.1 → 2.3.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 +12 -0
- package/dist/browser.js +3 -3
- package/dist/helpers/api_info.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/utils/submit.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/helpers/api_info.ts +0 -2
- package/src/test/submit.test.ts +61 -0
- package/src/utils/submit.ts +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @gradio/client
|
|
2
2
|
|
|
3
|
+
## 2.3.0
|
|
4
|
+
|
|
5
|
+
### Features
|
|
6
|
+
|
|
7
|
+
- [#13526](https://github.com/gradio-app/gradio/pull/13526) [`53cb4ca`](https://github.com/gradio-app/gradio/commit/53cb4cae1ec3521e9170d12867253516413ba37a) - Run `pnpm lint` and `pnpm ts:check` on CI. Thanks @abidlabs!
|
|
8
|
+
|
|
9
|
+
## 2.2.2
|
|
10
|
+
|
|
11
|
+
### Fixes
|
|
12
|
+
|
|
13
|
+
- [#13500](https://github.com/gradio-app/gradio/pull/13500) [`751a397`](https://github.com/gradio-app/gradio/commit/751a397ce519732526863ee84e311f7f64195f9d) - Close iterator on terminal error in JS client. Thanks @hysts!
|
|
14
|
+
|
|
3
15
|
## 2.2.1
|
|
4
16
|
|
|
5
17
|
### Fixes
|
package/dist/browser.js
CHANGED
|
@@ -1532,7 +1532,7 @@ function Xt(e, s = {}, t, n, o, r) {
|
|
|
1532
1532
|
fn_index: d,
|
|
1533
1533
|
time: /* @__PURE__ */ new Date(),
|
|
1534
1534
|
visible: !0
|
|
1535
|
-
});
|
|
1535
|
+
}), a();
|
|
1536
1536
|
else if (q === 422)
|
|
1537
1537
|
i({
|
|
1538
1538
|
type: "status",
|
|
@@ -1557,7 +1557,7 @@ function Xt(e, s = {}, t, n, o, r) {
|
|
|
1557
1557
|
fn_index: d,
|
|
1558
1558
|
time: /* @__PURE__ */ new Date(),
|
|
1559
1559
|
visible: !0
|
|
1560
|
-
});
|
|
1560
|
+
}), a();
|
|
1561
1561
|
} else {
|
|
1562
1562
|
v = b.event_id, I = v;
|
|
1563
1563
|
let P = async function(ie) {
|
|
@@ -1634,7 +1634,7 @@ function Xt(e, s = {}, t, n, o, r) {
|
|
|
1634
1634
|
queue: !0,
|
|
1635
1635
|
endpoint: _,
|
|
1636
1636
|
fn_index: d
|
|
1637
|
-
}), a())), ($?.stage === "complete" || $?.stage === "error") && (se[v] && delete se[v], v in te && delete te[v]);
|
|
1637
|
+
}), a())), ($?.stage === "complete" || $?.stage === "error") && (se[v] && delete se[v], v in te && delete te[v], a());
|
|
1638
1638
|
} catch (S) {
|
|
1639
1639
|
console.error("Unexpected client exception", S), i({
|
|
1640
1640
|
type: "status",
|
|
@@ -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,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,GAAI,GAAG,MAAM,MAAM,EAAE,KAAG,MAU7C,CAAC;AAEF,wBAAgB,kBAAkB,CACjC,QAAQ,EAAE,OAAO,CAAC,OAAO,CAA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,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;AAED,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,CAuJA;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,eAAO,MAAM,kBAAkB,GAC9B,OAAM,OAAO,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,aAAK,EAC9C,eAAe,YAAY,CAAC,SAAS,GAAG,OAAO,CAAC,KAC9C,OAAO,EAgDT,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1940,6 +1940,7 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events, additio
|
|
|
1940
1940
|
time: /* @__PURE__ */ new Date(),
|
|
1941
1941
|
visible: true
|
|
1942
1942
|
});
|
|
1943
|
+
close();
|
|
1943
1944
|
} else if (status === 422) {
|
|
1944
1945
|
fire_event({
|
|
1945
1946
|
type: "status",
|
|
@@ -1966,6 +1967,7 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events, additio
|
|
|
1966
1967
|
time: /* @__PURE__ */ new Date(),
|
|
1967
1968
|
visible: true
|
|
1968
1969
|
});
|
|
1970
|
+
close();
|
|
1969
1971
|
} else {
|
|
1970
1972
|
event_id = response.event_id;
|
|
1971
1973
|
event_id_final = event_id;
|
|
@@ -2066,6 +2068,7 @@ function submit(endpoint, data = {}, event_data, trigger_id, all_events, additio
|
|
|
2066
2068
|
if (event_id in pending_diff_streams) {
|
|
2067
2069
|
delete pending_diff_streams[event_id];
|
|
2068
2070
|
}
|
|
2071
|
+
close();
|
|
2069
2072
|
}
|
|
2070
2073
|
} catch (e) {
|
|
2071
2074
|
console.error("Unexpected client exception", e);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"submit.d.ts","sourceRoot":"","sources":["../../src/utils/submit.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"submit.d.ts","sourceRoot":"","sources":["../../src/utils/submit.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAGX,WAAW,EAMX,cAAc,EACd,MAAM,UAAU,CAAC;AAkBlB,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,EACpB,kBAAkB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GACzC,cAAc,CAAC,WAAW,CAAC,CAoqB7B"}
|
package/package.json
CHANGED
package/src/helpers/api_info.ts
CHANGED
|
@@ -230,7 +230,6 @@ export function get_description(
|
|
|
230
230
|
return type?.description;
|
|
231
231
|
}
|
|
232
232
|
|
|
233
|
-
/* eslint-disable complexity */
|
|
234
233
|
export function handle_message(
|
|
235
234
|
data: any,
|
|
236
235
|
last_status: Status["stage"]
|
|
@@ -402,7 +401,6 @@ export function handle_message(
|
|
|
402
401
|
|
|
403
402
|
return { type: "none", status: { stage: "error", queue } };
|
|
404
403
|
}
|
|
405
|
-
/* eslint-enable complexity */
|
|
406
404
|
|
|
407
405
|
/**
|
|
408
406
|
* Maps the provided `data` to the parameters defined by the `/info` endpoint response.
|
package/src/test/submit.test.ts
CHANGED
|
@@ -89,4 +89,65 @@ describe("submit iterator", () => {
|
|
|
89
89
|
expect(types).toContain("data");
|
|
90
90
|
expect(types).toContain("status");
|
|
91
91
|
});
|
|
92
|
+
|
|
93
|
+
test("for-await loop terminates when the server raises an error mid-stream", async () => {
|
|
94
|
+
const app = await Client.connect("hmb/hello_world", {
|
|
95
|
+
events: ["data", "status"]
|
|
96
|
+
});
|
|
97
|
+
app.stream_status.open = true;
|
|
98
|
+
|
|
99
|
+
const iterator = app.submit("/predict", ["hi"]);
|
|
100
|
+
const event_id = await iterator.wait_for_id();
|
|
101
|
+
expect(event_id).toBeTruthy();
|
|
102
|
+
|
|
103
|
+
const callback = app.event_callbacks[event_id as string];
|
|
104
|
+
expect(callback).toBeDefined();
|
|
105
|
+
|
|
106
|
+
const events: { type: string; stage?: string }[] = [];
|
|
107
|
+
const consumer = (async () => {
|
|
108
|
+
for await (const event of iterator) {
|
|
109
|
+
events.push(event as { type: string; stage?: string });
|
|
110
|
+
}
|
|
111
|
+
})();
|
|
112
|
+
|
|
113
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
114
|
+
|
|
115
|
+
// Stream a partial result first, so the error below genuinely arrives
|
|
116
|
+
// mid-stream rather than as the very first message.
|
|
117
|
+
await callback({
|
|
118
|
+
msg: "process_generating",
|
|
119
|
+
output: { data: ["partial"] },
|
|
120
|
+
success: true
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// A server-side exception then arrives as process_completed with
|
|
124
|
+
// success:false and an `error` field in the output. This must fire an
|
|
125
|
+
// "error" status and terminate the iterator rather than hang the
|
|
126
|
+
// consumer. handle_message() reads title/visible/duration from
|
|
127
|
+
// `output`, so mirror a real payload's shape here.
|
|
128
|
+
await callback({
|
|
129
|
+
msg: "process_completed",
|
|
130
|
+
output: {
|
|
131
|
+
error: "boom mid-stream",
|
|
132
|
+
title: "Error",
|
|
133
|
+
visible: true,
|
|
134
|
+
duration: 0
|
|
135
|
+
},
|
|
136
|
+
success: false
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
await race_with_timeout(
|
|
140
|
+
consumer,
|
|
141
|
+
1000,
|
|
142
|
+
"submit iterator did not terminate after a server-side error"
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
// The partial result should have been delivered before the error.
|
|
146
|
+
expect(events.some((e) => e.type === "data")).toBe(true);
|
|
147
|
+
|
|
148
|
+
const error_event = events.find(
|
|
149
|
+
(e) => e.type === "status" && e.stage === "error"
|
|
150
|
+
);
|
|
151
|
+
expect(error_event).toBeDefined();
|
|
152
|
+
});
|
|
92
153
|
});
|
package/src/utils/submit.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable complexity */
|
|
2
1
|
import type {
|
|
3
2
|
Status,
|
|
4
3
|
Payload,
|
|
@@ -452,6 +451,7 @@ export function submit(
|
|
|
452
451
|
time: new Date(),
|
|
453
452
|
visible: true
|
|
454
453
|
});
|
|
454
|
+
close();
|
|
455
455
|
} else if (status === 422) {
|
|
456
456
|
fire_event({
|
|
457
457
|
type: "status",
|
|
@@ -481,6 +481,7 @@ export function submit(
|
|
|
481
481
|
time: new Date(),
|
|
482
482
|
visible: true
|
|
483
483
|
});
|
|
484
|
+
close();
|
|
484
485
|
} else {
|
|
485
486
|
event_id = response.event_id as string;
|
|
486
487
|
event_id_final = event_id;
|
|
@@ -593,6 +594,7 @@ export function submit(
|
|
|
593
594
|
if (event_id! in pending_diff_streams) {
|
|
594
595
|
delete pending_diff_streams[event_id!];
|
|
595
596
|
}
|
|
597
|
+
close();
|
|
596
598
|
}
|
|
597
599
|
} catch (e) {
|
|
598
600
|
console.error("Unexpected client exception", e);
|