From 7ad086a0fe906046b9875feedd7eea7a2eaef599 Mon Sep 17 00:00:00 2001 From: Nate Sesti Date: Thu, 15 Feb 2024 09:56:44 -0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20extraBodyProperties?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/index.d.ts | 1 + docs/static/schemas/config.json | 11 ++++++++++- extensions/vscode/config_schema.json | 11 ++++++++++- extensions/vscode/continue_rc_schema.json | 11 ++++++++++- extensions/vscode/src/loadConfig.ts | 17 +++++++++++++++++ 5 files changed, 48 insertions(+), 3 deletions(-) diff --git a/core/index.d.ts b/core/index.d.ts index 1a1407d52..ea85bac36 100644 --- a/core/index.d.ts +++ b/core/index.d.ts @@ -503,6 +503,7 @@ export interface RequestOptions { caBundlePath?: string | string[]; proxy?: string; headers?: { [key: string]: string }; + extraBodyProperties?: { [key: string]: string }; } export interface StepWithParams { diff --git a/docs/static/schemas/config.json b/docs/static/schemas/config.json index 746737b6a..d4ab00298 100644 --- a/docs/static/schemas/config.json +++ b/docs/static/schemas/config.json @@ -87,6 +87,14 @@ "additionalProperties": { "type": "string" } + }, + "extraBodyProperties": { + "title": "Extra Body Properties", + "description": "This object will be merged with the body when making the HTTP requests", + "type": "object", + "additionalProperties": { + "type": "string" + } } } }, @@ -216,7 +224,8 @@ "verifySsl": null, "caBundlePath": null, "proxy": null, - "headers": null + "headers": null, + "extraBodyProperties": null }, "allOf": [ { diff --git a/extensions/vscode/config_schema.json b/extensions/vscode/config_schema.json index 746737b6a..d4ab00298 100644 --- a/extensions/vscode/config_schema.json +++ b/extensions/vscode/config_schema.json @@ -87,6 +87,14 @@ "additionalProperties": { "type": "string" } + }, + "extraBodyProperties": { + "title": "Extra Body Properties", + "description": "This object will be merged with the body when making the HTTP requests", + "type": "object", + "additionalProperties": { + "type": "string" + } } } }, @@ -216,7 +224,8 @@ "verifySsl": null, "caBundlePath": null, "proxy": null, - "headers": null + "headers": null, + "extraBodyProperties": null }, "allOf": [ { diff --git a/extensions/vscode/continue_rc_schema.json b/extensions/vscode/continue_rc_schema.json index ea2a834e5..7c2643f0d 100644 --- a/extensions/vscode/continue_rc_schema.json +++ b/extensions/vscode/continue_rc_schema.json @@ -94,6 +94,14 @@ "additionalProperties": { "type": "string" } + }, + "extraBodyProperties": { + "title": "Extra Body Properties", + "description": "This object will be merged with the body when making the HTTP requests", + "type": "object", + "additionalProperties": { + "type": "string" + } } } }, @@ -223,7 +231,8 @@ "verifySsl": null, "caBundlePath": null, "proxy": null, - "headers": null + "headers": null, + "extraBodyProperties": null }, "allOf": [ { diff --git a/extensions/vscode/src/loadConfig.ts b/extensions/vscode/src/loadConfig.ts index 4f2ddc502..708f9e1b5 100644 --- a/extensions/vscode/src/loadConfig.ts +++ b/extensions/vscode/src/loadConfig.ts @@ -148,8 +148,25 @@ function setupLlm(llm: ILLM): ILLM { headers[key] = value as string; } + let updatedBody: string | undefined = undefined; + try { + if ( + llm.requestOptions?.extraBodyProperties && + typeof init.body === "string" + ) { + const parsedBody = JSON.parse(init.body); + updatedBody = JSON.stringify({ + ...parsedBody, + ...llm.requestOptions.extraBodyProperties, + }); + } + } catch (e) { + console.log("Unable to parse HTTP request body: ", e); + } + const resp = await fetch(input, { ...init, + body: updatedBody ?? init.body, headers, agent, });