Elffuss BraidHub

kikocis/continue public

main · 918 BRawPermalink
1import { streamResponse } from "@continuedev/fetch";
2import { SlashCommand } from "../../../index.js";
3import { removeQuotesAndEscapes } from "../../../util/index.js";
4
5const HttpSlashCommand: SlashCommand = {
6 name: "http",
7 description: "Call an HTTP endpoint to serve response",
8 run: async function* ({ ide, llm, input, params, fetch }) {
9 const url = params?.url;
10 if (!url) {
11 throw new Error("URL is not defined in params");
12 }
13 const response = await fetch(url, {
14 method: "POST",
15 headers: {
16 "Content-Type": "application/json",
17 },
18 body: JSON.stringify({
19 input: removeQuotesAndEscapes(input),
20 }),
21 });
22
23 // Stream the response
24 if (response.body === null) {
25 throw new Error("Response body is null");
26 }
27 for await (const chunk of streamResponse(response)) {
28 yield chunk;
29 }
30 },
31};
32
33export default HttpSlashCommand;