UNPKG

@openai/agents-realtime

Version:

The OpenAI Agents SDK is a lightweight yet powerful framework for building multi-agent workflows. This package contains the logic for building realtime voice agents on the server or in the browser.

1,672 lines (1,671 loc) 1.55 MB
var Ra = Object.defineProperty; var Fr = (n) => { throw TypeError(n); }; var Da = (n, e, t) => e in n ? Ra(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t; var _ = (n, e, t) => Da(n, typeof e != "symbol" ? e + "" : e, t), qn = (n, e, t) => e.has(n) || Fr("Cannot " + t); var u = (n, e, t) => (qn(n, e, "read from private field"), t ? t.call(n) : e.get(n)), T = (n, e, t) => e.has(n) ? Fr("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(n) : e.set(n, t), y = (n, e, t, r) => (qn(n, e, "write to private field"), r ? r.call(n, t) : e.set(n, t), t), $ = (n, e, t) => (qn(n, e, "access private method"), t); const tr = { version: "0.0.14" }; function js(n) { const e = atob(n), t = e.length, r = new Uint8Array(t); for (let s = 0; s < t; s++) r[s] = e.charCodeAt(s); return r.buffer; } function Zs(n) { const e = String.fromCharCode(...new Uint8Array(n)); return btoa(e); } function $s(n) { if (typeof n > "u" || n === null || typeof n != "object" || !("type" in n) || typeof n.type != "string" || !n.type || n.type !== "message" || !("content" in n) || !Array.isArray(n.content) || n.content.length < 1) return; const e = n.content[n.content.length - 1]; if (!(!("type" in e) || typeof e.type != "string")) { if (e.type === "text") return typeof e.text == "string" ? e.text : void 0; if (e.type === "audio") return typeof e.transcript == "string" ? e.transcript : void 0; } } function Pa(n, e) { const t = n.filter((a) => !e.some((i) => i.itemId === a.itemId)), r = e.filter((a) => !n.some((i) => i.itemId === a.itemId)), s = e.filter((a) => n.some((i) => i.itemId === a.itemId && JSON.stringify(i) !== JSON.stringify(a))); return { removals: t, additions: r, updates: s }; } function Ma() { return typeof window > "u" ? !1 : typeof window.RTCPeerConnection < "u"; } function Ur(n) { return n.role === "system" ? n : n.role === "assistant" ? { ...n, content: n.content.map((e) => e.type === "audio" ? { ...e, audio: null } : e) } : n.role === "user" ? { ...n, content: n.content.map((e) => e.type === "input_audio" ? { ...e, audio: null } : e) } : n; } function Jr(n, e, t) { if (e.type === "conversation.item.input_audio_transcription.completed") return n.map((a) => { if (a.itemId === e.item_id && a.type === "message" && "role" in a && a.role === "user") { const i = a.content.map((o) => o.type === "input_audio" ? { ...o, transcript: e.transcript } : o); return { ...a, content: i, status: "completed" }; } return a; }); const r = !t && e.type === "message" ? Ur(e) : e, s = n.findIndex((a) => a.itemId === e.itemId); if (s !== -1) return n.map((a, i) => i === s ? r : !t && a.type === "message" ? Ur(a) : a); if (e.previousItemId) { const a = n.findIndex((i) => i.itemId === e.previousItemId); return a !== -1 ? [ ...n.slice(0, a + 1), r, ...n.slice(a + 1) ] : [...n, r]; } else return [...n, r]; } const ja = { "User-Agent": `Agents/JavaScript ${tr.version}`, "X-OpenAI-Agents-SDK": `openai-agents-sdk.${tr.version}` }, Za = `openai-agents-sdk.${tr.version}`; async function xr(n) { try { return [null, await n()]; } catch (e) { return [e, null]; } } function $a(n, e) { const t = { ...n }; return Object.defineProperties(t, { $brand: { value: "auto-parseable-response-format", enumerable: !1 }, $parseRaw: { value: e, enumerable: !1 } }), t; } const La = Symbol("Let zodToJsonSchema decide on which parser to use"), Br = { name: void 0, $refStrategy: "root", effectStrategy: "input", pipeStrategy: "all", dateStrategy: "format:date-time", mapStrategy: "entries", nullableStrategy: "from-target", removeAdditionalStrategy: "passthrough", definitionPath: "definitions", target: "jsonSchema7", strictUnions: !1, errorMessages: !1, markdownDescription: !1, patternStrategy: "escape", applyRegexFlags: !1, emailStrategy: "format:email", base64Strategy: "contentEncoding:base64", nameStrategy: "ref" }, Fa = (n) => typeof n == "string" ? { ...Br, basePath: ["#"], definitions: {}, name: n } : { ...Br, basePath: ["#"], definitions: {}, ...n }, nr = (n) => "_def" in n ? n._def : n; function Ua(n) { if (!n) return !0; for (const e in n) return !1; return !0; } const Ja = (n) => { const e = Fa(n), t = e.name !== void 0 ? [...e.basePath, e.definitionPath, e.name] : e.basePath; return { ...e, currentPath: t, propertyPath: void 0, seenRefs: /* @__PURE__ */ new Set(), seen: new Map(Object.entries(e.definitions).map(([r, s]) => [ nr(s), { def: nr(s), path: [...e.basePath, e.definitionPath, r], // Resolution of references will be forced even though seen, so it's ok that the schema is undefined here for now. jsonSchema: void 0 } ])) }; }; function Ls(n, e, t, r) { r != null && r.errorMessages && t && (n.errorMessage = { ...n.errorMessage, [e]: t }); } function q(n, e, t, r, s) { n[e] = t, Ls(n, e, r, s); } var Mt; (function(n) { n.assertEqual = (s) => { }; function e(s) { } n.assertIs = e; function t(s) { throw new Error(); } n.assertNever = t, n.arrayToEnum = (s) => { const a = {}; for (const i of s) a[i] = i; return a; }, n.getValidEnumValues = (s) => { const a = n.objectKeys(s).filter((o) => typeof s[s[o]] != "number"), i = {}; for (const o of a) i[o] = s[o]; return n.objectValues(i); }, n.objectValues = (s) => n.objectKeys(s).map(function(a) { return s[a]; }), n.objectKeys = typeof Object.keys == "function" ? (s) => Object.keys(s) : (s) => { const a = []; for (const i in s) Object.prototype.hasOwnProperty.call(s, i) && a.push(i); return a; }, n.find = (s, a) => { for (const i of s) if (a(i)) return i; }, n.isInteger = typeof Number.isInteger == "function" ? (s) => Number.isInteger(s) : (s) => typeof s == "number" && Number.isFinite(s) && Math.floor(s) === s; function r(s, a = " | ") { return s.map((i) => typeof i == "string" ? `'${i}'` : i).join(a); } n.joinValues = r, n.jsonStringifyReplacer = (s, a) => typeof a == "bigint" ? a.toString() : a; })(Mt || (Mt = {})); var qr; (function(n) { n.mergeShapes = (e, t) => ({ ...e, ...t // second overwrites first }); })(qr || (qr = {})); Mt.arrayToEnum([ "string", "nan", "number", "integer", "float", "boolean", "date", "bigint", "symbol", "function", "undefined", "null", "array", "object", "unknown", "promise", "void", "never", "map", "set" ]); Mt.arrayToEnum([ "invalid_type", "invalid_literal", "custom", "invalid_union", "invalid_union_discriminator", "invalid_enum_value", "unrecognized_keys", "invalid_arguments", "invalid_return_type", "invalid_date", "invalid_string", "too_small", "too_big", "invalid_intersection_types", "not_multiple_of", "not_finite" ]); let Gr = class Fs extends Error { get errors() { return this.issues; } constructor(e) { super(), this.issues = [], this.addIssue = (r) => { this.issues = [...this.issues, r]; }, this.addIssues = (r = []) => { this.issues = [...this.issues, ...r]; }; const t = new.target.prototype; Object.setPrototypeOf ? Object.setPrototypeOf(this, t) : this.__proto__ = t, this.name = "ZodError", this.issues = e; } format(e) { const t = e || function(a) { return a.message; }, r = { _errors: [] }, s = (a) => { for (const i of a.issues) if (i.code === "invalid_union") i.unionErrors.map(s); else if (i.code === "invalid_return_type") s(i.returnTypeError); else if (i.code === "invalid_arguments") s(i.argumentsError); else if (i.path.length === 0) r._errors.push(t(i)); else { let o = r, l = 0; for (; l < i.path.length; ) { const c = i.path[l]; l === i.path.length - 1 ? (o[c] = o[c] || { _errors: [] }, o[c]._errors.push(t(i))) : o[c] = o[c] || { _errors: [] }, o = o[c], l++; } } }; return s(this), r; } static assert(e) { if (!(e instanceof Fs)) throw new Error(`Not a ZodError: ${e}`); } toString() { return this.message; } get message() { return JSON.stringify(this.issues, Mt.jsonStringifyReplacer, 2); } get isEmpty() { return this.issues.length === 0; } flatten(e = (t) => t.message) { const t = {}, r = []; for (const s of this.issues) s.path.length > 0 ? (t[s.path[0]] = t[s.path[0]] || [], t[s.path[0]].push(e(s))) : r.push(e(s)); return { formErrors: r, fieldErrors: t }; } get formErrors() { return this.flatten(); } }; Gr.create = (n) => new Gr(n); var Vr; (function(n) { n.errToObj = (e) => typeof e == "string" ? { message: e } : e || {}, n.toString = (e) => typeof e == "string" ? e : e == null ? void 0 : e.message; })(Vr || (Vr = {})); var P; (function(n) { n.ZodString = "ZodString", n.ZodNumber = "ZodNumber", n.ZodNaN = "ZodNaN", n.ZodBigInt = "ZodBigInt", n.ZodBoolean = "ZodBoolean", n.ZodDate = "ZodDate", n.ZodSymbol = "ZodSymbol", n.ZodUndefined = "ZodUndefined", n.ZodNull = "ZodNull", n.ZodAny = "ZodAny", n.ZodUnknown = "ZodUnknown", n.ZodNever = "ZodNever", n.ZodVoid = "ZodVoid", n.ZodArray = "ZodArray", n.ZodObject = "ZodObject", n.ZodUnion = "ZodUnion", n.ZodDiscriminatedUnion = "ZodDiscriminatedUnion", n.ZodIntersection = "ZodIntersection", n.ZodTuple = "ZodTuple", n.ZodRecord = "ZodRecord", n.ZodMap = "ZodMap", n.ZodSet = "ZodSet", n.ZodFunction = "ZodFunction", n.ZodLazy = "ZodLazy", n.ZodLiteral = "ZodLiteral", n.ZodEnum = "ZodEnum", n.ZodEffects = "ZodEffects", n.ZodNativeEnum = "ZodNativeEnum", n.ZodOptional = "ZodOptional", n.ZodNullable = "ZodNullable", n.ZodDefault = "ZodDefault", n.ZodCatch = "ZodCatch", n.ZodPromise = "ZodPromise", n.ZodBranded = "ZodBranded", n.ZodPipeline = "ZodPipeline", n.ZodReadonly = "ZodReadonly"; })(P || (P = {})); function Ba() { return {}; } function qa(n, e) { var r, s; const t = { type: "array" }; return ((s = (r = n.type) == null ? void 0 : r._def) == null ? void 0 : s.typeName) !== P.ZodAny && (t.items = J(n.type._def, { ...e, currentPath: [...e.currentPath, "items"] })), n.minLength && q(t, "minItems", n.minLength.value, n.minLength.message, e), n.maxLength && q(t, "maxItems", n.maxLength.value, n.maxLength.message, e), n.exactLength && (q(t, "minItems", n.exactLength.value, n.exactLength.message, e), q(t, "maxItems", n.exactLength.value, n.exactLength.message, e)), t; } function Ga(n, e) { const t = { type: "integer", format: "int64" }; if (!n.checks) return t; for (const r of n.checks) switch (r.kind) { case "min": e.target === "jsonSchema7" ? r.inclusive ? q(t, "minimum", r.value, r.message, e) : q(t, "exclusiveMinimum", r.value, r.message, e) : (r.inclusive || (t.exclusiveMinimum = !0), q(t, "minimum", r.value, r.message, e)); break; case "max": e.target === "jsonSchema7" ? r.inclusive ? q(t, "maximum", r.value, r.message, e) : q(t, "exclusiveMaximum", r.value, r.message, e) : (r.inclusive || (t.exclusiveMaximum = !0), q(t, "maximum", r.value, r.message, e)); break; case "multipleOf": q(t, "multipleOf", r.value, r.message, e); break; } return t; } function Va() { return { type: "boolean" }; } function za(n, e) { return J(n.type._def, e); } const Ha = (n, e) => J(n.innerType._def, e); function Us(n, e, t) { const r = t ?? e.dateStrategy; if (Array.isArray(r)) return { anyOf: r.map((s, a) => Us(n, e, s)) }; switch (r) { case "string": case "format:date-time": return { type: "string", format: "date-time" }; case "format:date": return { type: "string", format: "date" }; case "integer": return Wa(n, e); } } const Wa = (n, e) => { const t = { type: "integer", format: "unix-time" }; if (e.target === "openApi3") return t; for (const r of n.checks) switch (r.kind) { case "min": q( t, "minimum", r.value, // This is in milliseconds r.message, e ); break; case "max": q( t, "maximum", r.value, // This is in milliseconds r.message, e ); break; } return t; }; function Ya(n, e) { return { ...J(n.innerType._def, e), default: n.defaultValue() }; } function Xa(n, e, t) { return e.effectStrategy === "input" ? J(n.schema._def, e, t) : {}; } function Qa(n) { return { type: "string", enum: [...n.values] }; } const Ka = (n) => "type" in n && n.type === "string" ? !1 : "allOf" in n; function ei(n, e) { const t = [ J(n.left._def, { ...e, currentPath: [...e.currentPath, "allOf", "0"] }), J(n.right._def, { ...e, currentPath: [...e.currentPath, "allOf", "1"] }) ].filter((a) => !!a); let r = e.target === "jsonSchema2019-09" ? { unevaluatedProperties: !1 } : void 0; const s = []; return t.forEach((a) => { if (Ka(a)) s.push(...a.allOf), a.unevaluatedProperties === void 0 && (r = void 0); else { let i = a; if ("additionalProperties" in a && a.additionalProperties === !1) { const { additionalProperties: o, ...l } = a; i = l; } else r = void 0; s.push(i); } }), s.length ? { allOf: s, ...r } : void 0; } function ti(n, e) { const t = typeof n.value; return t !== "bigint" && t !== "number" && t !== "boolean" && t !== "string" ? { type: Array.isArray(n.value) ? "array" : "object" } : e.target === "openApi3" ? { type: t === "bigint" ? "integer" : t, enum: [n.value] } : { type: t === "bigint" ? "integer" : t, const: n.value }; } let Gn; const qe = { /** * `c` was changed to `[cC]` to replicate /i flag */ cuid: /^[cC][^\s-]{8,}$/, cuid2: /^[0-9a-z]+$/, ulid: /^[0-9A-HJKMNP-TV-Z]{26}$/, /** * `a-z` was added to replicate /i flag */ email: /^(?!\.)(?!.*\.\.)([a-zA-Z0-9_'+\-\.]*)[a-zA-Z0-9_+-]@([a-zA-Z0-9][a-zA-Z0-9\-]*\.)+[a-zA-Z]{2,}$/, /** * Constructed a valid Unicode RegExp * * Lazily instantiate since this type of regex isn't supported * in all envs (e.g. React Native). * * See: * https://github.com/colinhacks/zod/issues/2433 * Fix in Zod: * https://github.com/colinhacks/zod/commit/9340fd51e48576a75adc919bff65dbc4a5d4c99b */ emoji: () => (Gn === void 0 && (Gn = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u")), Gn), base64: /^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/, nanoid: /^[a-zA-Z0-9_-]{21}$/ }; function Js(n, e) { const t = { type: "string" }; function r(s) { return e.patternStrategy === "escape" ? ni(s) : s; } if (n.checks) for (const s of n.checks) switch (s.kind) { case "min": q(t, "minLength", typeof t.minLength == "number" ? Math.max(t.minLength, s.value) : s.value, s.message, e); break; case "max": q(t, "maxLength", typeof t.maxLength == "number" ? Math.min(t.maxLength, s.value) : s.value, s.message, e); break; case "email": switch (e.emailStrategy) { case "format:email": me(t, "email", s.message, e); break; case "format:idn-email": me(t, "idn-email", s.message, e); break; case "pattern:zod": ge(t, qe.email, s.message, e); break; } break; case "url": me(t, "uri", s.message, e); break; case "uuid": me(t, "uuid", s.message, e); break; case "regex": ge(t, s.regex, s.message, e); break; case "cuid": ge(t, qe.cuid, s.message, e); break; case "cuid2": ge(t, qe.cuid2, s.message, e); break; case "startsWith": ge(t, RegExp(`^${r(s.value)}`), s.message, e); break; case "endsWith": ge(t, RegExp(`${r(s.value)}$`), s.message, e); break; case "datetime": me(t, "date-time", s.message, e); break; case "date": me(t, "date", s.message, e); break; case "time": me(t, "time", s.message, e); break; case "duration": me(t, "duration", s.message, e); break; case "length": q(t, "minLength", typeof t.minLength == "number" ? Math.max(t.minLength, s.value) : s.value, s.message, e), q(t, "maxLength", typeof t.maxLength == "number" ? Math.min(t.maxLength, s.value) : s.value, s.message, e); break; case "includes": { ge(t, RegExp(r(s.value)), s.message, e); break; } case "ip": { s.version !== "v6" && me(t, "ipv4", s.message, e), s.version !== "v4" && me(t, "ipv6", s.message, e); break; } case "emoji": ge(t, qe.emoji, s.message, e); break; case "ulid": { ge(t, qe.ulid, s.message, e); break; } case "base64": { switch (e.base64Strategy) { case "format:binary": { me(t, "binary", s.message, e); break; } case "contentEncoding:base64": { q(t, "contentEncoding", "base64", s.message, e); break; } case "pattern:zod": { ge(t, qe.base64, s.message, e); break; } } break; } case "nanoid": ge(t, qe.nanoid, s.message, e); } return t; } const ni = (n) => Array.from(n).map((e) => /[a-zA-Z0-9]/.test(e) ? e : `\\${e}`).join(""), me = (n, e, t, r) => { var s; n.format || (s = n.anyOf) != null && s.some((a) => a.format) ? (n.anyOf || (n.anyOf = []), n.format && (n.anyOf.push({ format: n.format, ...n.errorMessage && r.errorMessages && { errorMessage: { format: n.errorMessage.format } } }), delete n.format, n.errorMessage && (delete n.errorMessage.format, Object.keys(n.errorMessage).length === 0 && delete n.errorMessage)), n.anyOf.push({ format: e, ...t && r.errorMessages && { errorMessage: { format: t } } })) : q(n, "format", e, t, r); }, ge = (n, e, t, r) => { var s; n.pattern || (s = n.allOf) != null && s.some((a) => a.pattern) ? (n.allOf || (n.allOf = []), n.pattern && (n.allOf.push({ pattern: n.pattern, ...n.errorMessage && r.errorMessages && { errorMessage: { pattern: n.errorMessage.pattern } } }), delete n.pattern, n.errorMessage && (delete n.errorMessage.pattern, Object.keys(n.errorMessage).length === 0 && delete n.errorMessage)), n.allOf.push({ pattern: zr(e, r), ...t && r.errorMessages && { errorMessage: { pattern: t } } })) : q(n, "pattern", zr(e, r), t, r); }, zr = (n, e) => { var c; const t = typeof n == "function" ? n() : n; if (!e.applyRegexFlags || !t.flags) return t.source; const r = { i: t.flags.includes("i"), // Case-insensitive m: t.flags.includes("m"), // `^` and `$` matches adjacent to newline characters s: t.flags.includes("s") // `.` matches newlines }, s = r.i ? t.source.toLowerCase() : t.source; let a = "", i = !1, o = !1, l = !1; for (let p = 0; p < s.length; p++) { if (i) { a += s[p], i = !1; continue; } if (r.i) { if (o) { if (s[p].match(/[a-z]/)) { l ? (a += s[p], a += `${s[p - 2]}-${s[p]}`.toUpperCase(), l = !1) : s[p + 1] === "-" && ((c = s[p + 2]) != null && c.match(/[a-z]/)) ? (a += s[p], l = !0) : a += `${s[p]}${s[p].toUpperCase()}`; continue; } } else if (s[p].match(/[a-z]/)) { a += `[${s[p]}${s[p].toUpperCase()}]`; continue; } } if (r.m) { if (s[p] === "^") { a += `(^|(?<=[\r ]))`; continue; } else if (s[p] === "$") { a += `($|(?=[\r ]))`; continue; } } if (r.s && s[p] === ".") { a += o ? `${s[p]}\r ` : `[${s[p]}\r ]`; continue; } a += s[p], s[p] === "\\" ? i = !0 : o && s[p] === "]" ? o = !1 : !o && s[p] === "[" && (o = !0); } try { const p = new RegExp(a); } catch { return console.warn(`Could not convert regex pattern at ${e.currentPath.join("/")} to a flag-independent form! Falling back to the flag-ignorant source`), t.source; } return a; }; function Bs(n, e) { var r, s, a, i; if (e.target === "openApi3" && ((r = n.keyType) == null ? void 0 : r._def.typeName) === P.ZodEnum) return { type: "object", required: n.keyType._def.values, properties: n.keyType._def.values.reduce((o, l) => ({ ...o, [l]: J(n.valueType._def, { ...e, currentPath: [...e.currentPath, "properties", l] }) ?? {} }), {}), additionalProperties: !1 }; const t = { type: "object", additionalProperties: J(n.valueType._def, { ...e, currentPath: [...e.currentPath, "additionalProperties"] }) ?? {} }; if (e.target === "openApi3") return t; if (((s = n.keyType) == null ? void 0 : s._def.typeName) === P.ZodString && ((a = n.keyType._def.checks) != null && a.length)) { const o = Object.entries(Js(n.keyType._def, e)).reduce((l, [c, p]) => c === "type" ? l : { ...l, [c]: p }, {}); return { ...t, propertyNames: o }; } else if (((i = n.keyType) == null ? void 0 : i._def.typeName) === P.ZodEnum) return { ...t, propertyNames: { enum: n.keyType._def.values } }; return t; } function ri(n, e) { if (e.mapStrategy === "record") return Bs(n, e); const t = J(n.keyType._def, { ...e, currentPath: [...e.currentPath, "items", "items", "0"] }) || {}, r = J(n.valueType._def, { ...e, currentPath: [...e.currentPath, "items", "items", "1"] }) || {}; return { type: "array", maxItems: 125, items: { type: "array", items: [t, r], minItems: 2, maxItems: 2 } }; } function si(n) { const e = n.values, r = Object.keys(n.values).filter((a) => typeof e[e[a]] != "number").map((a) => e[a]), s = Array.from(new Set(r.map((a) => typeof a))); return { type: s.length === 1 ? s[0] === "string" ? "string" : "number" : ["string", "number"], enum: r }; } function ai() { return { not: {} }; } function ii(n) { return n.target === "openApi3" ? { enum: ["null"], nullable: !0 } : { type: "null" }; } const vn = { ZodString: "string", ZodNumber: "number", ZodBigInt: "integer", ZodBoolean: "boolean", ZodNull: "null" }; function oi(n, e) { if (e.target === "openApi3") return Hr(n, e); const t = n.options instanceof Map ? Array.from(n.options.values()) : n.options; if (t.every((r) => r._def.typeName in vn && (!r._def.checks || !r._def.checks.length))) { const r = t.reduce((s, a) => { const i = vn[a._def.typeName]; return i && !s.includes(i) ? [...s, i] : s; }, []); return { type: r.length > 1 ? r : r[0] }; } else if (t.every((r) => r._def.typeName === "ZodLiteral" && !r.description)) { const r = t.reduce((s, a) => { const i = typeof a._def.value; switch (i) { case "string": case "number": case "boolean": return [...s, i]; case "bigint": return [...s, "integer"]; case "object": if (a._def.value === null) return [...s, "null"]; case "symbol": case "undefined": case "function": default: return s; } }, []); if (r.length === t.length) { const s = r.filter((a, i, o) => o.indexOf(a) === i); return { type: s.length > 1 ? s : s[0], enum: t.reduce((a, i) => a.includes(i._def.value) ? a : [...a, i._def.value], []) }; } } else if (t.every((r) => r._def.typeName === "ZodEnum")) return { type: "string", enum: t.reduce((r, s) => [...r, ...s._def.values.filter((a) => !r.includes(a))], []) }; return Hr(n, e); } const Hr = (n, e) => { const t = (n.options instanceof Map ? Array.from(n.options.values()) : n.options).map((r, s) => J(r._def, { ...e, currentPath: [...e.currentPath, "anyOf", `${s}`] })).filter((r) => !!r && (!e.strictUnions || typeof r == "object" && Object.keys(r).length > 0)); return t.length ? { anyOf: t } : void 0; }; function ui(n, e) { if (["ZodString", "ZodNumber", "ZodBigInt", "ZodBoolean", "ZodNull"].includes(n.innerType._def.typeName) && (!n.innerType._def.checks || !n.innerType._def.checks.length)) return e.target === "openApi3" || e.nullableStrategy === "property" ? { type: vn[n.innerType._def.typeName], nullable: !0 } : { type: [vn[n.innerType._def.typeName], "null"] }; if (e.target === "openApi3") { const r = J(n.innerType._def, { ...e, currentPath: [...e.currentPath] }); return r && "$ref" in r ? { allOf: [r], nullable: !0 } : r && { ...r, nullable: !0 }; } const t = J(n.innerType._def, { ...e, currentPath: [...e.currentPath, "anyOf", "0"] }); return t && { anyOf: [t, { type: "null" }] }; } function ci(n, e) { const t = { type: "number" }; if (!n.checks) return t; for (const r of n.checks) switch (r.kind) { case "int": t.type = "integer", Ls(t, "type", r.message, e); break; case "min": e.target === "jsonSchema7" ? r.inclusive ? q(t, "minimum", r.value, r.message, e) : q(t, "exclusiveMinimum", r.value, r.message, e) : (r.inclusive || (t.exclusiveMinimum = !0), q(t, "minimum", r.value, r.message, e)); break; case "max": e.target === "jsonSchema7" ? r.inclusive ? q(t, "maximum", r.value, r.message, e) : q(t, "exclusiveMaximum", r.value, r.message, e) : (r.inclusive || (t.exclusiveMaximum = !0), q(t, "maximum", r.value, r.message, e)); break; case "multipleOf": q(t, "multipleOf", r.value, r.message, e); break; } return t; } function di(n, e) { return e.removeAdditionalStrategy === "strict" ? n.catchall._def.typeName === "ZodNever" ? n.unknownKeys !== "strict" : J(n.catchall._def, { ...e, currentPath: [...e.currentPath, "additionalProperties"] }) ?? !0 : n.catchall._def.typeName === "ZodNever" ? n.unknownKeys === "passthrough" : J(n.catchall._def, { ...e, currentPath: [...e.currentPath, "additionalProperties"] }) ?? !0; } function li(n, e) { const t = { type: "object", ...Object.entries(n.shape()).reduce((r, [s, a]) => { var l; if (a === void 0 || a._def === void 0) return r; const i = [...e.currentPath, "properties", s], o = J(a._def, { ...e, currentPath: i, propertyPath: i }); if (o === void 0) return r; if (e.openaiStrictMode && a.isOptional() && !a.isNullable() && typeof ((l = a._def) == null ? void 0 : l.defaultValue) > "u") throw new Error(`Zod field at \`${i.join("/")}\` uses \`.optional()\` without \`.nullable()\` which is not supported by the API. See: https://platform.openai.com/docs/guides/structured-outputs?api-mode=responses#all-fields-must-be-required`); return { properties: { ...r.properties, [s]: o }, required: a.isOptional() && !e.openaiStrictMode ? r.required : [...r.required, s] }; }, { properties: {}, required: [] }), additionalProperties: di(n, e) }; return t.required.length || delete t.required, t; } const pi = (n, e) => { var r; if (e.currentPath.toString() === ((r = e.propertyPath) == null ? void 0 : r.toString())) return J(n.innerType._def, e); const t = J(n.innerType._def, { ...e, currentPath: [...e.currentPath, "anyOf", "1"] }); return t ? { anyOf: [ { not: {} }, t ] } : {}; }, fi = (n, e) => { if (e.pipeStrategy === "input") return J(n.in._def, e); if (e.pipeStrategy === "output") return J(n.out._def, e); const t = J(n.in._def, { ...e, currentPath: [...e.currentPath, "allOf", "0"] }), r = J(n.out._def, { ...e, currentPath: [...e.currentPath, "allOf", t ? "1" : "0"] }); return { allOf: [t, r].filter((s) => s !== void 0) }; }; function hi(n, e) { return J(n.type._def, e); } function mi(n, e) { const r = { type: "array", uniqueItems: !0, items: J(n.valueType._def, { ...e, currentPath: [...e.currentPath, "items"] }) }; return n.minSize && q(r, "minItems", n.minSize.value, n.minSize.message, e), n.maxSize && q(r, "maxItems", n.maxSize.value, n.maxSize.message, e), r; } function gi(n, e) { return n.rest ? { type: "array", minItems: n.items.length, items: n.items.map((t, r) => J(t._def, { ...e, currentPath: [...e.currentPath, "items", `${r}`] })).reduce((t, r) => r === void 0 ? t : [...t, r], []), additionalItems: J(n.rest._def, { ...e, currentPath: [...e.currentPath, "additionalItems"] }) } : { type: "array", minItems: n.items.length, maxItems: n.items.length, items: n.items.map((t, r) => J(t._def, { ...e, currentPath: [...e.currentPath, "items", `${r}`] })).reduce((t, r) => r === void 0 ? t : [...t, r], []) }; } function _i() { return { not: {} }; } function yi() { return {}; } const vi = (n, e) => J(n.innerType._def, e); function J(n, e, t = !1) { var i; const r = e.seen.get(n); if (e.override) { const o = (i = e.override) == null ? void 0 : i.call(e, n, e, r, t); if (o !== La) return o; } if (r && !t) { const o = wi(r, e); if (o !== void 0) return "$ref" in o && e.seenRefs.add(o.$ref), o; } const s = { def: n, path: e.currentPath, jsonSchema: void 0 }; e.seen.set(n, s); const a = xi(n, n.typeName, e, t); return a && Si(n, e, a), s.jsonSchema = a, a; } const wi = (n, e) => { switch (e.$refStrategy) { case "root": return { $ref: n.path.join("/") }; // this case is needed as OpenAI strict mode doesn't support top-level `$ref`s, i.e. // the top-level schema *must* be `{"type": "object", "properties": {...}}` but if we ever // need to define a `$ref`, relative `$ref`s aren't supported, so we need to extract // the schema to `#/definitions/` and reference that. // // e.g. if we need to reference a schema at // `["#","definitions","contactPerson","properties","person1","properties","name"]` // then we'll extract it out to `contactPerson_properties_person1_properties_name` case "extract-to-root": const t = n.path.slice(e.basePath.length + 1).join("_"); return t !== e.name && e.nameStrategy === "duplicate-ref" && (e.definitions[t] = n.def), { $ref: [...e.basePath, e.definitionPath, t].join("/") }; case "relative": return { $ref: bi(e.currentPath, n.path) }; case "none": case "seen": return n.path.length < e.currentPath.length && n.path.every((r, s) => e.currentPath[s] === r) ? (console.warn(`Recursive reference detected at ${e.currentPath.join("/")}! Defaulting to any`), {}) : e.$refStrategy === "seen" ? {} : void 0; } }, bi = (n, e) => { let t = 0; for (; t < n.length && t < e.length && n[t] === e[t]; t++) ; return [(n.length - t).toString(), ...e.slice(t)].join("/"); }, xi = (n, e, t, r) => { switch (e) { case P.ZodString: return Js(n, t); case P.ZodNumber: return ci(n, t); case P.ZodObject: return li(n, t); case P.ZodBigInt: return Ga(n, t); case P.ZodBoolean: return Va(); case P.ZodDate: return Us(n, t); case P.ZodUndefined: return _i(); case P.ZodNull: return ii(t); case P.ZodArray: return qa(n, t); case P.ZodUnion: case P.ZodDiscriminatedUnion: return oi(n, t); case P.ZodIntersection: return ei(n, t); case P.ZodTuple: return gi(n, t); case P.ZodRecord: return Bs(n, t); case P.ZodLiteral: return ti(n, t); case P.ZodEnum: return Qa(n); case P.ZodNativeEnum: return si(n); case P.ZodNullable: return ui(n, t); case P.ZodOptional: return pi(n, t); case P.ZodMap: return ri(n, t); case P.ZodSet: return mi(n, t); case P.ZodLazy: return J(n.getter()._def, t); case P.ZodPromise: return hi(n, t); case P.ZodNaN: case P.ZodNever: return ai(); case P.ZodEffects: return Xa(n, t, r); case P.ZodAny: return Ba(); case P.ZodUnknown: return yi(); case P.ZodDefault: return Ya(n, t); case P.ZodBranded: return za(n, t); case P.ZodReadonly: return vi(n, t); case P.ZodCatch: return Ha(n, t); case P.ZodPipeline: return fi(n, t); case P.ZodFunction: case P.ZodVoid: case P.ZodSymbol: return; default: return /* @__PURE__ */ ((s) => { })(); } }, Si = (n, e, t) => (n.description && (t.description = n.description, e.markdownDescription && (t.markdownDescription = n.description)), t), Ti = (n, e) => { const t = Ja(e), r = typeof e == "string" ? e : (e == null ? void 0 : e.nameStrategy) === "title" || e == null ? void 0 : e.name, s = J(n._def, r === void 0 ? t : { ...t, currentPath: [...t.basePath, t.definitionPath, r] }, !1) ?? {}, a = typeof e == "object" && e.name !== void 0 && e.nameStrategy === "title" ? e.name : void 0; a !== void 0 && (s.title = a); const i = (() => { if (Ua(t.definitions)) return; const l = {}, c = /* @__PURE__ */ new Set(); for (let p = 0; p < 500; p++) { const f = Object.entries(t.definitions).filter(([h]) => !c.has(h)); if (f.length === 0) break; for (const [h, x] of f) l[h] = J(nr(x), { ...t, currentPath: [...t.basePath, t.definitionPath, h] }, !0) ?? {}, c.add(h); } return l; })(), o = r === void 0 ? i ? { ...s, [t.definitionPath]: i } : s : t.nameStrategy === "duplicate-ref" ? { ...s, ...i || t.seenRefs.size ? { [t.definitionPath]: { ...i, // only actually duplicate the schema definition if it was ever referenced // otherwise the duplication is completely pointless ...t.seenRefs.size ? { [r]: s } : void 0 } } : void 0 } : { $ref: [...t.$refStrategy === "relative" ? [] : t.basePath, t.definitionPath, r].join("/"), [t.definitionPath]: { ...i, [r]: s } }; return t.target === "jsonSchema7" ? o.$schema = "http://json-schema.org/draft-07/schema#" : t.target === "jsonSchema2019-09" && (o.$schema = "https://json-schema.org/draft/2019-09/schema#"), o; }; function ki(n, { parser: e, callback: t }) { const r = { ...n }; return Object.defineProperties(r, { $brand: { value: "auto-parseable-tool", enumerable: !1 }, $parseRaw: { value: e, enumerable: !1 }, $callback: { value: t, enumerable: !1 } }), r; } function qs(n, e) { return Ti(n, { openaiStrictMode: !0, name: e.name, nameStrategy: "duplicate-ref", $refStrategy: "extract-to-root", nullableStrategy: "property" }); } function Ii(n, e, t) { return $a({ type: "json_schema", ...t, name: e, strict: !0, schema: qs(n, { name: e }) }, (r) => n.parse(JSON.parse(r))); } function Ai(n) { return ki({ type: "function", name: n.name, parameters: qs(n.parameters, { name: n.name }), strict: !0 }, { callback: n.function, parser: (e) => n.parameters.parse(JSON.parse(e)) }); } class Be extends Error { constructor(t, r) { super(t); _(this, "state"); this.state = r; } } class Ci extends Be { } class Wr extends Be { } class fe extends Be { } class Q extends Be { } class Yr extends Be { constructor(t, r, s) { super(t, s); _(this, "error"); this.error = r; } } class Ei extends Be { constructor(t, r, s) { super(t, s); _(this, "error"); this.error = r; } } class Xr extends Be { constructor(t, r, s) { super(t, s); _(this, "result"); this.result = r; } } class rr extends Be { constructor(t, r, s) { super(t, s); _(this, "result"); this.result = r; } } function nt(n) { return typeof n == "object" && n !== null && "_def" in n && typeof n._def == "object" && n._def !== null && "typeName" in n._def && n._def.typeName === "ZodObject"; } function Oi(n) { return typeof n == "object" && n !== null && "input" in n && typeof n.input == "string"; } function wn(n) { if (n = n.replace(/\s/g, "_"), n = n.replace(/[^a-zA-Z0-9]/g, "_"), n.length === 0) throw new Error("Tool name cannot be empty"); return n; } function Sr(n, e) { const t = (r) => JSON.parse(r); if (nt(n)) { const r = Ai({ name: e, parameters: n, function: () => { } }); return { schema: r.parameters, parser: r.$parseRaw }; } else if (typeof n == "object" && n !== null) return { schema: n, parser: t }; throw new Q("Input type is not a ZodObject or a valid JSON schema"); } function Qr(n) { if (n === "text") return "text"; if (nt(n)) { const e = Ii(n, "output"); return { type: e.type, name: e.name, strict: e.strict || !1, schema: e.schema }; } return n; } function Ni(n) { return n && n.__esModule && Object.prototype.hasOwnProperty.call(n, "default") ? n.default : n; } var pn = { exports: {} }, Vn, Kr; function Ri() { if (Kr) return Vn; Kr = 1; var n = 1e3, e = n * 60, t = e * 60, r = t * 24, s = r * 7, a = r * 365.25; Vn = function(p, f) { f = f || {}; var h = typeof p; if (h === "string" && p.length > 0) return i(p); if (h === "number" && isFinite(p)) return f.long ? l(p) : o(p); throw new Error( "val is not a non-empty string or a valid number. val=" + JSON.stringify(p) ); }; function i(p) { if (p = String(p), !(p.length > 100)) { var f = /^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec( p ); if (f) { var h = parseFloat(f[1]), x = (f[2] || "ms").toLowerCase(); switch (x) { case "years": case "year": case "yrs": case "yr": case "y": return h * a; case "weeks": case "week": case "w": return h * s; case "days": case "day": case "d": return h * r; case "hours": case "hour": case "hrs": case "hr": case "h": return h * t; case "minutes": case "minute": case "mins": case "min": case "m": return h * e; case "seconds": case "second": case "secs": case "sec": case "s": return h * n; case "milliseconds": case "millisecond": case "msecs": case "msec": case "ms": return h; default: return; } } } } function o(p) { var f = Math.abs(p); return f >= r ? Math.round(p / r) + "d" : f >= t ? Math.round(p / t) + "h" : f >= e ? Math.round(p / e) + "m" : f >= n ? Math.round(p / n) + "s" : p + "ms"; } function l(p) { var f = Math.abs(p); return f >= r ? c(p, f, r, "day") : f >= t ? c(p, f, t, "hour") : f >= e ? c(p, f, e, "minute") : f >= n ? c(p, f, n, "second") : p + " ms"; } function c(p, f, h, x) { var b = f >= h * 1.5; return Math.round(p / h) + " " + x + (b ? "s" : ""); } return Vn; } var zn, es; function Di() { if (es) return zn; es = 1; function n(e) { r.debug = r, r.default = r, r.coerce = c, r.disable = o, r.enable = a, r.enabled = l, r.humanize = Ri(), r.destroy = p, Object.keys(e).forEach((f) => { r[f] = e[f]; }), r.names = [], r.skips = [], r.formatters = {}; function t(f) { let h = 0; for (let x = 0; x < f.length; x++) h = (h << 5) - h + f.charCodeAt(x), h |= 0; return r.colors[Math.abs(h) % r.colors.length]; } r.selectColor = t; function r(f) { let h, x = null, b, w; function E(...R) { if (!E.enabled) return; const z = E, Y = Number(/* @__PURE__ */ new Date()), oe = Y - (h || Y); z.diff = oe, z.prev = h, z.curr = Y, h = Y, R[0] = r.coerce(R[0]), typeof R[0] != "string" && R.unshift("%O"); let ue = 0; R[0] = R[0].replace(/%([a-zA-Z%])/g, (Bn, Oa) => { if (Bn === "%%") return "%"; ue++; const Lr = r.formatters[Oa]; if (typeof Lr == "function") { const Na = R[ue]; Bn = Lr.call(z, Na), R.splice(ue, 1), ue--; } return Bn; }), r.formatArgs.call(z, R), (z.log || r.log).apply(z, R); } return E.namespace = f, E.useColors = r.useColors(), E.color = r.selectColor(f), E.extend = s, E.destroy = r.destroy, Object.defineProperty(E, "enabled", { enumerable: !0, configurable: !1, get: () => x !== null ? x : (b !== r.namespaces && (b = r.namespaces, w = r.enabled(f)), w), set: (R) => { x = R; } }), typeof r.init == "function" && r.init(E), E; } function s(f, h) { const x = r(this.namespace + (typeof h > "u" ? ":" : h) + f); return x.log = this.log, x; } function a(f) { r.save(f), r.namespaces = f, r.names = [], r.skips = []; const h = (typeof f == "string" ? f : "").trim().replace(/\s+/g, ",").split(",").filter(Boolean); for (const x of h) x[0] === "-" ? r.skips.push(x.slice(1)) : r.names.push(x); } function i(f, h) { let x = 0, b = 0, w = -1, E = 0; for (; x < f.length; ) if (b < h.length && (h[b] === f[x] || h[b] === "*")) h[b] === "*" ? (w = b, E = x, b++) : (x++, b++); else if (w !== -1) b = w + 1, E++, x = E; else return !1; for (; b < h.length && h[b] === "*"; ) b++; return b === h.length; } function o() { const f = [ ...r.names, ...r.skips.map((h) => "-" + h) ].join(","); return r.enable(""), f; } function l(f) { for (const h of r.skips) if (i(f, h)) return !1; for (const h of r.names) if (i(f, h)) return !0; return !1; } function c(f) { return f instanceof Error ? f.stack || f.message : f; } function p() { console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`."); } return r.enable(r.load()), r; } return zn = n, zn; } var ts; function Pi() { return ts || (ts = 1, function(n, e) { e.formatArgs = r, e.save = s, e.load = a, e.useColors = t, e.storage = i(), e.destroy = /* @__PURE__ */ (() => { let l = !1; return () => { l || (l = !0, console.warn("Instance method `debug.destroy()` is deprecated and no longer does anything. It will be removed in the next major version of `debug`.")); }; })(), e.colors = [ "#0000CC", "#0000FF", "#0033CC", "#0033FF", "#0066CC", "#0066FF", "#0099CC", "#0099FF", "#00CC00", "#00CC33", "#00CC66", "#00CC99", "#00CCCC", "#00CCFF", "#3300CC", "#3300FF", "#3333CC", "#3333FF", "#3366CC", "#3366FF", "#3399CC", "#3399FF", "#33CC00", "#33CC33", "#33CC66", "#33CC99", "#33CCCC", "#33CCFF", "#6600CC", "#6600FF", "#6633CC", "#6633FF", "#66CC00", "#66CC33", "#9900CC", "#9900FF", "#9933CC", "#9933FF", "#99CC00", "#99CC33", "#CC0000", "#CC0033", "#CC0066", "#CC0099", "#CC00CC", "#CC00FF", "#CC3300", "#CC3333", "#CC3366", "#CC3399", "#CC33CC", "#CC33FF", "#CC6600", "#CC6633", "#CC9900", "#CC9933", "#CCCC00", "#CCCC33", "#FF0000", "#FF0033", "#FF0066", "#FF0099", "#FF00CC", "#FF00FF", "#FF3300", "#FF3333", "#FF3366", "#FF3399", "#FF33CC", "#FF33FF", "#FF6600", "#FF6633", "#FF9900", "#FF9933", "#FFCC00", "#FFCC33" ]; function t() { if (typeof window < "u" && window.process && (window.process.type === "renderer" || window.process.__nwjs)) return !0; if (typeof navigator < "u" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/(edge|trident)\/(\d+)/)) return !1; let l; return typeof document < "u" && document.documentElement && document.documentElement.style && document.documentElement.style.WebkitAppearance || // Is firebug? http://stackoverflow.com/a/398120/376773 typeof window < "u" && window.console && (window.console.firebug || window.console.exception && window.console.table) || // Is firefox >= v31? // https://developer.mozilla.org/en-US/docs/Tools/Web_Console#Styling_messages typeof navigator < "u" && navigator.userAgent && (l = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(l[1], 10) >= 31 || // Double check webkit in userAgent just in case we are in a worker typeof navigator < "u" && navigator.userAgent && navigator.userAgent.toLowerCase().match(/applewebkit\/(\d+)/); } function r(l) { if (l[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + l[0] + (this.useColors ? "%c " : " ") + "+" + n.exports.humanize(this.diff), !this.useColors) return; const c = "color: " + this.color; l.splice(1, 0, c, "color: inherit"); let p = 0, f = 0; l[0].replace(/%[a-zA-Z%]/g, (h) => { h !== "%%" && (p++, h === "%c" && (f = p)); }), l.splice(f, 0, c); } e.log = console.debug || console.log || (() => { }); function s(l) { try { l ? e.storage.setItem("debug", l) : e.storage.removeItem("debug"); } catch { } } function a() { let l; try { l = e.storage.getItem("debug") || e.storage.getItem("DEBUG"); } catch { } return !l && typeof process < "u" && "env" in process && (l = process.env.DEBUG), l; } function i() { try { return localStorage; } catch { } } n.exports = Di()(e); const { formatters: o } = n.exports; o.j = function(l) { try { return JSON.stringify(l); } catch (c) { return "[UnexpectedJSONParseError]: " + c.message; } }; }(pn, pn.exports)), pn.exports; } var Mi = Pi(); const ji = /* @__PURE__ */ Ni(Mi); function Zi() { return yo(); } function ns(n) { const e = Zi(); return typeof e < "u" && (e[n] === "true" || e[n] === "1"); } const Gs = { get disabled() { return !0; } }, Vs = { get dontLogModelData() { return ns("OPENAI_AGENTS_DONT_LOG_MODEL_DATA"); }, get dontLogToolData() { return ns("OPENAI_AGENTS_DONT_LOG_TOOL_DATA"); } }, $i = Vs.dontLogModelData, Li = Vs.dontLogToolData; function zs(n = "openai-agents") { return { namespace: n, debug: ji(n), error: console.error, warn: console.warn, dontLogModelData: $i, dontLogToolData: Li }; } const C = zs("openai-agents:core"); function rt(n) { if (n == null) return String(n); if (typeof n == "string") return n; if (typeof n == "object") try { return JSON.stringify(n); } catch { return "[object with circular references]"; } return String(n); } function Fi(n, e) { return `An error occurred while running the tool. Please try again. Error: ${e instanceof Error ? e.toString() : String(e)}`; } function sr(n) { const e = n.name ? wn(n.name) : wn(n.execute.name), t = typeof n.errorFunction > "u" ? Fi : n.errorFunction; if (!e) throw new Error("Tool name cannot be empty. Either name your function or provide a name in the options."); const r = n.strict ?? !0; if (!r && nt(n.parameters)) throw new Q("Strict mode is required for Zod parameters"); const { parser: s, schema: a } = Sr(n.parameters, e); async function i(c, p) { const [f, h] = await xr(() => s(p)); if (f !== null) throw C.dontLogToolData ? C.debug(`Invalid JSON input for tool ${e}`) : C.debug(`Invalid JSON input for tool ${e}: ${p}`), new fe("Invalid JSON input for tool"); C.dontLogToolData ? C.debug(`Invoking tool ${e}`) : C.debug(`Invoking tool ${e} with input ${p}`); const x = await n.execute(h, c), b = rt(x); return C.dontLogToolData ? C.debug(`Tool ${e} completed`) : C.debug(`Tool ${e} returned: ${b}`), x; } async function o(c, p) { return i(c, p).catch((f) => { if (t) { const h = Lt(); return h == null || h.setError({ message: "Error running tool (non-fatal)", data: { tool_name: e, error: f.toString()