@gradio/client 2.2.1 → 2.2.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 +6 -0
- package/dist/browser.js +3 -3
- package/dist/index.js +3 -0
- package/dist/utils/submit.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/test/submit.test.ts +61 -0
- package/src/utils/submit.ts +3 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @gradio/client
|
|
2
2
|
|
|
3
|
+
## 2.2.2
|
|
4
|
+
|
|
5
|
+
### Fixes
|
|
6
|
+
|
|
7
|
+
- [#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!
|
|
8
|
+
|
|
3
9
|
## 2.2.1
|
|
4
10
|
|
|
5
11
|
### 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",
|
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":"AACA,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,
|
|
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;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/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
|
@@ -452,6 +452,7 @@ export function submit(
|
|
|
452
452
|
time: new Date(),
|
|
453
453
|
visible: true
|
|
454
454
|
});
|
|
455
|
+
close();
|
|
455
456
|
} else if (status === 422) {
|
|
456
457
|
fire_event({
|
|
457
458
|
type: "status",
|
|
@@ -481,6 +482,7 @@ export function submit(
|
|
|
481
482
|
time: new Date(),
|
|
482
483
|
visible: true
|
|
483
484
|
});
|
|
485
|
+
close();
|
|
484
486
|
} else {
|
|
485
487
|
event_id = response.event_id as string;
|
|
486
488
|
event_id_final = event_id;
|
|
@@ -593,6 +595,7 @@ export function submit(
|
|
|
593
595
|
if (event_id! in pending_diff_streams) {
|
|
594
596
|
delete pending_diff_streams[event_id!];
|
|
595
597
|
}
|
|
598
|
+
close();
|
|
596
599
|
}
|
|
597
600
|
} catch (e) {
|
|
598
601
|
console.error("Unexpected client exception", e);
|