Tweak plugins

This commit is contained in:
Gregory Schier
2024-10-15 07:45:45 -07:00
parent 61543fb10f
commit 17a429525f
8 changed files with 50 additions and 69 deletions

View File

@@ -61,6 +61,7 @@ export const plugin: PluginDefinition = {
},
{
name: 'response.body.path',
description: 'Access a field of the response body using JsonPath or XPath',
aliases: ['response'],
args: [
requestArg,
@@ -108,6 +109,38 @@ export const plugin: PluginDefinition = {
return null; // Bail out
},
},
{
name: 'response.body.raw',
description: 'Access the entire response body, as text',
aliases: ['response'],
args: [
requestArg,
behaviorArg,
],
async onRender(ctx: Context, args: CallTemplateFunctionArgs): Promise<string | null> {
if (!args.values.request) return null;
const response = await getResponse(ctx, {
requestId: args.values.request,
purpose: args.purpose,
behavior: args.values.behavior ?? null,
});
if (response == null) return null;
if (response.bodyPath == null) {
return null;
}
let body;
try {
body = readFileSync(response.bodyPath, 'utf-8');
} catch (_) {
return null;
}
return body;
},
},
],
};