Files
wehub-resource-sync 3cd11ababe
Check Markdown links / linkChecker (push) Waiting to run
chore: import upstream snapshot with attribution
2026-07-13 13:38:56 +08:00

44 lines
874 B
TypeScript

import {
HookEventType,
PluginContext,
PluginHandler,
PluginParameters,
} from '../types';
import { getText } from '../utils';
import { postPromptfoo } from './globals';
import { HarmResult } from './types';
export const handler: PluginHandler = async (
context: PluginContext,
parameters: PluginParameters,
eventType: HookEventType
) => {
let error = null;
let verdict = true;
let data = null;
try {
const harmObject = {
input: getText(context, eventType),
};
const result = await postPromptfoo<HarmResult>(
'harm',
harmObject,
parameters.timeout
);
// If any harm category is flagged, set verdict to false
if (result.results[0].flagged) {
verdict = false;
}
data = result.results[0];
} catch (e: any) {
delete e.stack;
error = e;
}
return { error, verdict, data };
};