@openai/agents-core
Version:
The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.
46 lines • 2.01 kB
JavaScript
import logger, { getSafeErrorType } from "../logger.mjs";
export const TOOL_APPROVAL_REJECTION_MESSAGE = 'Tool execution was not approved.';
function toErrorMessage(error) {
return error instanceof Error ? error.message : String(error);
}
export async function resolveApprovalRejectionMessage({ runContext, toolType, toolName, approvalToolNames = [toolName], approvalAgent, callId, toolErrorFormatter, }) {
// Per-call message from state.reject(item, { message }) takes precedence over
// the global toolErrorFormatter callback and the SDK default.
const perCallMessage = approvalToolNames
.map((approvalToolName) => approvalAgent
? runContext._getFunctionRejectionMessage(approvalToolName, callId, approvalAgent)
: runContext.getRejectionMessage(approvalToolName, callId, {
functionTool: false,
}))
.find((message) => typeof message === 'string');
if (typeof perCallMessage === 'string') {
return perCallMessage;
}
if (!toolErrorFormatter) {
return TOOL_APPROVAL_REJECTION_MESSAGE;
}
try {
const formattedMessage = await toolErrorFormatter({
kind: 'approval_rejected',
toolType,
toolName,
callId,
defaultMessage: TOOL_APPROVAL_REJECTION_MESSAGE,
runContext,
});
if (typeof formattedMessage === 'string') {
return formattedMessage;
}
if (typeof formattedMessage !== 'undefined') {
logger.warn('toolErrorFormatter returned a non-string value. Falling back to the default tool approval rejection message.');
}
}
catch (error) {
const errorDetails = logger.dontLogToolData
? getSafeErrorType(error)
: toErrorMessage(error);
logger.warn(`toolErrorFormatter threw while formatting approval rejection: ${errorDetails}`);
}
return TOOL_APPROVAL_REJECTION_MESSAGE;
}
//# sourceMappingURL=approvalRejection.mjs.map