@openai/agents-core
Version:
The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.
64 lines • 2.48 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FunctionToolApprovalInputError = void 0;
exports.getFunctionToolApprovalInput = getFunctionToolApprovalInput;
const errors_1 = require("../errors.js");
/** Internal configuration failure that must not become a manual approval. */
class FunctionToolApprovalInputError extends errors_1.UserError {
constructor() {
super('Conditional tool approval requires copyable plain normalized input. Return plain data from the schema and resolve application objects inside execute.');
}
}
exports.FunctionToolApprovalInputError = FunctionToolApprovalInputError;
/**
* Copy plain data for approval or execution without exposing retained input.
* Reject other schema outputs before approval; validation must not run again
* merely to obtain a second, potentially different, approval value.
*
* Shared by SDK runners through the internal utilities entry point.
*/
function getFunctionToolApprovalInput(value) {
const unsupported = Symbol('unsupported approval input');
const copies = new Map();
const copy = (input) => {
if (input === null || typeof input !== 'object') {
if (typeof input === 'function' || typeof input === 'symbol') {
throw unsupported;
}
return input;
}
const prototype = Object.getPrototypeOf(input);
const array = Array.isArray(input);
if (array
? prototype !== Array.prototype
: prototype !== Object.prototype && prototype !== null) {
throw unsupported;
}
const existing = copies.get(input);
if (existing) {
return existing;
}
const result = array ? [] : Object.create(prototype);
copies.set(input, result);
for (const key of Reflect.ownKeys(input)) {
const descriptor = Object.getOwnPropertyDescriptor(input, key);
if (!('value' in descriptor)) {
throw unsupported;
}
Object.defineProperty(result, key, {
...descriptor,
value: copy(descriptor.value),
});
}
if (!Object.isExtensible(input))
Object.preventExtensions(result);
return result;
};
try {
return copy(value);
}
catch {
throw new FunctionToolApprovalInputError();
}
}
//# sourceMappingURL=functionToolApproval.js.map