continue-custom/core/commands/slash/http.ts
LangLangBart 014122957f
fix: handle optional params in EditSlashCommand (#745)
* fix: handle optional params in EditSlashCommand

* fix: handle undefined URL in http slash command
2024-01-12 11:36:45 -08:00

36 lines
979 B
TypeScript

import { SlashCommand } from "../..";
import { removeQuotesAndEscapes } from "../../util";
const HttpSlashCommand: SlashCommand = {
name: "http",
description: "Call an HTTP endpoint to serve response",
run: async function* ({ ide, llm, input, params }) {
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;