✨ extraBodyProperties

This commit is contained in:
Nate Sesti 2024-02-15 09:56:44 -08:00
parent c8d793ec45
commit 7ad086a0fe
5 changed files with 48 additions and 3 deletions

1
core/index.d.ts vendored
View file

@ -503,6 +503,7 @@ export interface RequestOptions {
caBundlePath?: string | string[];
proxy?: string;
headers?: { [key: string]: string };
extraBodyProperties?: { [key: string]: string };
}
export interface StepWithParams {

View file

@ -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": [
{

View file

@ -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": [
{

View file

@ -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": [
{

View file

@ -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,
});