@gradio/client 2.7.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 +6 -0
- package/dist/browser.js +360 -356
- package/dist/index.cjs +8 -2
- package/dist/index.js +8 -2
- package/dist/index.min.js +161 -157
- package/dist/utils/submit.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/test/submit.test.ts +40 -1
- package/src/utils/submit.ts +16 -9
|
@@ -1 +1 @@
|
|
|
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;AAyBlB,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAQnC,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":"AAAA,OAAO,KAAK,EAGX,WAAW,EAMX,cAAc,EACd,MAAM,UAAU,CAAC;AAyBlB,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAQnC,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,CAiwB7B"}
|
package/package.json
CHANGED
package/src/test/submit.test.ts
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
describe,
|
|
3
|
+
beforeAll,
|
|
4
|
+
afterEach,
|
|
5
|
+
afterAll,
|
|
6
|
+
test,
|
|
7
|
+
expect,
|
|
8
|
+
vi
|
|
9
|
+
} from "vitest";
|
|
2
10
|
import { HttpResponse, http } from "msw";
|
|
3
11
|
|
|
4
12
|
import { Client } from "../client";
|
|
@@ -119,6 +127,37 @@ describe("submit iterator", () => {
|
|
|
119
127
|
expect(result).toEqual({ value: undefined, done: true });
|
|
120
128
|
});
|
|
121
129
|
|
|
130
|
+
test("send_chunk() and close_stream() called before queue/join responds reach the event in order", async () => {
|
|
131
|
+
const app = await Client.connect("hmb/hello_world");
|
|
132
|
+
app.stream_status.open = true;
|
|
133
|
+
|
|
134
|
+
let respond_to_join: () => void = () => {};
|
|
135
|
+
const join_released = new Promise<void>((r) => (respond_to_join = r));
|
|
136
|
+
const stream_paths: string[] = [];
|
|
137
|
+
server.use(
|
|
138
|
+
http.post(`${direct_space_url}/queue/join`, async () => {
|
|
139
|
+
await join_released;
|
|
140
|
+
return HttpResponse.json({ event_id: "slow-event" });
|
|
141
|
+
}),
|
|
142
|
+
http.post(/\/stream\//, ({ request }) => {
|
|
143
|
+
stream_paths.push(new URL(request.url).pathname);
|
|
144
|
+
return HttpResponse.json({ msg: "success" });
|
|
145
|
+
})
|
|
146
|
+
);
|
|
147
|
+
|
|
148
|
+
const iterator = app.submit("/predict", ["hi"]);
|
|
149
|
+
iterator.send_chunk({ data: ["chunk"] });
|
|
150
|
+
iterator.close_stream();
|
|
151
|
+
respond_to_join();
|
|
152
|
+
|
|
153
|
+
await vi.waitFor(() =>
|
|
154
|
+
expect(stream_paths).toEqual([
|
|
155
|
+
"/stream/slow-event",
|
|
156
|
+
"/stream/slow-event/close"
|
|
157
|
+
])
|
|
158
|
+
);
|
|
159
|
+
});
|
|
160
|
+
|
|
122
161
|
test("for-await loop terminates when data and complete arrive in the same SSE callback", async () => {
|
|
123
162
|
const app = await Client.connect("hmb/hello_world", {
|
|
124
163
|
events: ["data", "status"]
|
package/src/utils/submit.ts
CHANGED
|
@@ -773,6 +773,20 @@ export function submit(
|
|
|
773
773
|
return new Promise((resolve) => resolvers.push(resolve));
|
|
774
774
|
}
|
|
775
775
|
|
|
776
|
+
// The event id is only known once queue/join has responded.
|
|
777
|
+
const post_to_event = (suffix: string, body: unknown): void => {
|
|
778
|
+
job.then(
|
|
779
|
+
() => {
|
|
780
|
+
if (!event_id_final) return;
|
|
781
|
+
this.post_data(
|
|
782
|
+
`${config.root}${api_prefix}/stream/${event_id_final}${suffix}`,
|
|
783
|
+
body
|
|
784
|
+
);
|
|
785
|
+
},
|
|
786
|
+
() => {}
|
|
787
|
+
);
|
|
788
|
+
};
|
|
789
|
+
|
|
776
790
|
const iterator: SubmitIterable<GradioEvent> = {
|
|
777
791
|
[Symbol.asyncIterator]: () => iterator,
|
|
778
792
|
next,
|
|
@@ -786,18 +800,11 @@ export function submit(
|
|
|
786
800
|
},
|
|
787
801
|
cancel,
|
|
788
802
|
send_chunk: (payload: Record<string, unknown>) => {
|
|
789
|
-
|
|
790
|
-
...payload,
|
|
791
|
-
session_hash: this.session_hash
|
|
792
|
-
});
|
|
803
|
+
post_to_event("", { ...payload, session_hash: this.session_hash });
|
|
793
804
|
},
|
|
794
805
|
close_stream: () => {
|
|
795
|
-
this.post_data(
|
|
796
|
-
`${config.root}${api_prefix}/stream/${event_id_final}/close`,
|
|
797
|
-
{}
|
|
798
|
-
);
|
|
799
|
-
|
|
800
806
|
close();
|
|
807
|
+
post_to_event("/close", {});
|
|
801
808
|
},
|
|
802
809
|
event_id: () => event_id_final,
|
|
803
810
|
wait_for_id: async () => {
|