@openai/agents-core
Version:
The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows.
214 lines • 6.84 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ToolOutputGuardrailTripwireTriggered = exports.ToolInputGuardrailTripwireTriggered = exports.OutputGuardrailTripwireTriggered = exports.InputGuardrailTripwireTriggered = exports.ToolTimeoutError = exports.ToolCallError = exports.GuardrailExecutionError = exports.InvalidToolOutputError = exports.UserError = exports.InvalidToolInputError = exports.ModelTimeoutError = exports.ModelBehaviorError = exports.ModelRefusalError = exports.MaxTurnsExceededError = exports.SystemError = exports.AgentsError = void 0;
exports.isToolTimeoutError = isToolTimeoutError;
exports.clearToolErrorState = clearToolErrorState;
/**
* Base class for all errors thrown by the library.
*/
class AgentsError extends Error {
state;
constructor(message, state) {
super(message);
this.name = new.target.name;
this.state = state;
}
}
exports.AgentsError = AgentsError;
/**
* System error thrown when the library encounters an error that is not caused by the user's
* misconfiguration.
*/
class SystemError extends AgentsError {
}
exports.SystemError = SystemError;
/**
* Error thrown when the maximum number of turns is exceeded.
*/
class MaxTurnsExceededError extends AgentsError {
}
exports.MaxTurnsExceededError = MaxTurnsExceededError;
/**
* Error thrown when the model refuses to produce output.
*/
class ModelRefusalError extends AgentsError {
/**
* The refusal text returned by the model.
*/
refusal;
constructor(refusal, state) {
super(`Model refused to produce output: ${refusal}`, state);
this.refusal = refusal;
}
}
exports.ModelRefusalError = ModelRefusalError;
/**
* Error thrown when a model behavior is unexpected.
*/
class ModelBehaviorError extends AgentsError {
}
exports.ModelBehaviorError = ModelBehaviorError;
/**
* Error thrown when a model call exceeds its configured timeout.
*/
class ModelTimeoutError extends AgentsError {
code = 'ETIMEDOUT';
timeoutMs;
/**
* The provider or transport error observed after the timeout signal was sent, if any.
*/
cause;
constructor({ timeoutMs, cause }) {
super(`Model call timed out after ${timeoutMs}ms.`);
this.timeoutMs = timeoutMs;
this.cause = cause;
}
}
exports.ModelTimeoutError = ModelTimeoutError;
/**
* Error thrown when a model produces invalid tool input.
*/
class InvalidToolInputError extends ModelBehaviorError {
/** The original error thrown during validation, if any. */
originalError;
/** Context from the tool invocation that failed. */
toolInvocation;
constructor(message, state, originalError, toolInvocation) {
super(message, state);
this.originalError = originalError;
this.toolInvocation = toolInvocation;
}
}
exports.InvalidToolInputError = InvalidToolInputError;
/**
* Error thrown when the error is caused by the library user's misconfiguration.
*/
class UserError extends AgentsError {
}
exports.UserError = UserError;
/**
* Error thrown when a function tool returns a value that does not match its
* runtime output schema.
*/
class InvalidToolOutputError extends UserError {
/** The original error thrown during validation, if any. */
originalError;
/** Context from the tool output that failed validation. */
toolOutput;
constructor(message, state, originalError, toolOutput) {
super(message, state);
this.originalError = originalError;
this.toolOutput = toolOutput;
}
}
exports.InvalidToolOutputError = InvalidToolOutputError;
/**
* Error thrown when a guardrail execution fails.
*/
class GuardrailExecutionError extends AgentsError {
error;
constructor(message, error, state) {
super(message, state);
this.error = error;
}
}
exports.GuardrailExecutionError = GuardrailExecutionError;
/**
* Error thrown when a tool call fails.
*/
const toolCallErrors = new WeakSet();
const toolTimeoutErrors = new WeakSet();
class ToolCallError extends AgentsError {
error;
constructor(message, error, state) {
super(message, state);
this.error = error;
toolCallErrors.add(this);
}
}
exports.ToolCallError = ToolCallError;
/**
* Error thrown when a function tool invocation exceeds its timeout.
*/
class ToolTimeoutError extends AgentsError {
toolName;
timeoutMs;
constructor({ toolName, timeoutMs, state, }) {
super(`Tool '${toolName}' timed out after ${timeoutMs}ms.`, state);
this.toolName = toolName;
this.timeoutMs = timeoutMs;
toolTimeoutErrors.add(this);
}
}
exports.ToolTimeoutError = ToolTimeoutError;
/** @internal */
function isToolTimeoutError(error) {
return toolTimeoutErrors.has(error);
}
/** @internal */
function clearToolErrorState(error, state) {
const visited = new WeakSet();
let current = error;
while (toolCallErrors.has(current)) {
const toolCallError = current;
if (visited.has(toolCallError)) {
return;
}
visited.add(toolCallError);
if (toolCallError.state === state) {
toolCallError.state = undefined;
}
current = toolCallError.error;
}
if (toolTimeoutErrors.has(current)) {
const timeoutError = current;
if (timeoutError.state === state) {
timeoutError.state = undefined;
}
}
}
/**
* Error thrown when an input guardrail tripwire is triggered.
*/
class InputGuardrailTripwireTriggered extends AgentsError {
result;
constructor(message, result, state) {
super(message, state);
this.result = result;
}
}
exports.InputGuardrailTripwireTriggered = InputGuardrailTripwireTriggered;
/**
* Error thrown when an output guardrail tripwire is triggered.
*/
class OutputGuardrailTripwireTriggered extends AgentsError {
result;
constructor(message, result, state) {
super(message, state);
this.result = result;
}
}
exports.OutputGuardrailTripwireTriggered = OutputGuardrailTripwireTriggered;
/**
* Error thrown when a tool input guardrail tripwire is triggered.
*/
class ToolInputGuardrailTripwireTriggered extends AgentsError {
result;
constructor(message, result, state) {
super(message, state);
this.result = result;
}
}
exports.ToolInputGuardrailTripwireTriggered = ToolInputGuardrailTripwireTriggered;
/**
* Error thrown when a tool output guardrail tripwire is triggered.
*/
class ToolOutputGuardrailTripwireTriggered extends AgentsError {
result;
constructor(message, result, state) {
super(message, state);
this.result = result;
}
}
exports.ToolOutputGuardrailTripwireTriggered = ToolOutputGuardrailTripwireTriggered;
//# sourceMappingURL=errors.js.map