forked from continuedev/continue
-
Notifications
You must be signed in to change notification settings - Fork 1
/
http.ts
38 lines (35 loc) · 1022 Bytes
/
http.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { SlashCommand } from "../../index.js";
import { removeQuotesAndEscapes } from "../../util/index.js";
const HttpSlashCommand: SlashCommand = {
name: "http",
description: "Call an HTTP endpoint to serve response",
run: async function* ({ ide, llm, input, params, fetch }) {
const url = params?.url;
if (!url) {
throw new Error("URL is not defined in params");
}
const response = await fetch(url, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
input: removeQuotesAndEscapes(input),
}),
});
// Stream the response
if (response.body === null) {
throw new Error("Response body is null");
}
const reader = response.body.getReader();
while (true) {
const { done, value } = await reader.read();
if (done) {
break;
}
const decoded = new TextDecoder("utf-8").decode(value);
yield decoded;
}
},
};
export default HttpSlashCommand;