@openai/agents-core
Version:
The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.
37 lines • 1.42 kB
JavaScript
import { ModelBehaviorError, UserError } from "../errors.mjs";
import logger from "../logger.mjs";
import { isAsyncStandardSchemaValidationError } from "./standardSchema.mjs";
const dataRedactedErrors = new WeakSet();
export const REDACTED_FINAL_OUTPUT_ERROR_MESSAGE = 'Invalid output type: final assistant output did not match the expected schema.';
const REDACTED_ERROR_DETAILS_MESSAGE = 'Error details are redacted.';
function markDataRedacted(error) {
dataRedactedErrors.add(error);
return error;
}
export function createRedactedFinalOutputError() {
return markDataRedacted(new ModelBehaviorError(REDACTED_FINAL_OUTPUT_ERROR_MESSAGE));
}
export function processFinalOutputWithRedaction(callback) {
const redactFromStart = logger.dontLogModelData;
try {
return callback();
}
catch (error) {
if (isAsyncStandardSchemaValidationError(error)) {
throw error;
}
if (!redactFromStart && !logger.dontLogModelData) {
throw error;
}
throw createRedactedFinalOutputError();
}
}
export function createRedactedErrorDetailsError() {
return new UserError(REDACTED_ERROR_DETAILS_MESSAGE);
}
export function isDataRedactedError(error) {
return ((typeof error === 'object' || typeof error === 'function') &&
error !== null &&
dataRedactedErrors.has(error));
}
//# sourceMappingURL=finalOutputError.mjs.map