Skip to content

Commit 9f1a89c

Browse files
committed
Extract signal property from the run() options
This prevents it being passed to the backend as part of the body. The backend has recently started validating the body payload so this is now resulting as an API error. Fixes #249
1 parent d555cb1 commit 9f1a89c

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ class Replicate {
129129
* @returns {Promise<object>} - Resolves with the output of running the model
130130
*/
131131
async run(ref, options, progress) {
132-
const { wait, ...data } = options;
132+
const { wait, signal, ...data } = options;
133133

134134
const identifier = ModelVersionIdentifier.parse(ref);
135135

@@ -153,8 +153,6 @@ class Replicate {
153153
progress(prediction);
154154
}
155155

156-
const { signal } = options;
157-
158156
prediction = await this.wait(
159157
prediction,
160158
wait || {},

index.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,11 +1233,14 @@ describe("Replicate client", () => {
12331233
test("Aborts the operation when abort signal is invoked", async () => {
12341234
const controller = new AbortController();
12351235
const { signal } = controller;
1236+
let body: Record<string, unknown> | undefined;
12361237

12371238
const scope = nock(BASE_URL)
1238-
.post("/predictions", (body) => {
1239+
.post("/predictions", (_body) => {
1240+
// Should not pass the signal object in the body.
1241+
body = _body;
12391242
controller.abort();
1240-
return body;
1243+
return _body;
12411244
})
12421245
.reply(201, {
12431246
id: "ufawqhfynnddngldkgtslldrkq",
@@ -1263,7 +1266,10 @@ describe("Replicate client", () => {
12631266
}
12641267
);
12651268

1269+
expect(body).toBeDefined();
1270+
expect(body?.["signal"]).toBeUndefined();
12661271
expect(signal.aborted).toBe(true);
1272+
expect(output).toBeUndefined();
12671273

12681274
scope.done();
12691275
});

0 commit comments

Comments
 (0)