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,681 lines 1.53 MB
var ka = Object.defineProperty; var Mr = (n) => { throw TypeError(n); }; var Ia = (n, e, t) => e in n ? ka(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t; var _ = (n, e, t) => Ia(n, typeof e != "symbol" ? e + "" : e, t), Un = (n, e, t) => e.has(n) || Mr("Cannot " + t); var u = (n, e, t) => (Un(n, e, "read from private field"), t ? t.call(n) : e.get(n)), T = (n, e, t) => e.has(n) ? Mr("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(n) : e.set(n, t), y = (n, e, t, r) => (Un(n, e, "write to private field"), r ? r.call(n, t) : e.set(n, t), t), $ = (n, e, t) => (Un(n, e, "access private method"), t); const Qn = { version: "0.0.9" }; function Os(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 Es(n) { const e = String.fromCharCode(...new Uint8Array(n)); return btoa(e); } function Ns(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 Aa(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 Ca() { return typeof window > "u" ? !1 : typeof window.RTCPeerConnection < "u"; } function $r(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 Oa(n, e, t) { const r = !t && e.type === "message" ? $r(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" ? $r(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 Ea = { "User-Agent": `Agents/JavaScript ${Qn.version}`, "X-OpenAI-Agents-SDK": `openai-agents-sdk.${Qn.version}` }, Na = `openai-agents-sdk.${Qn.version}`; async function vr(n) { try { return [null, await n()]; } catch (e) { return [e, null]; } } function Ra(n, e) { const t = { ...n }; return Object.defineProperties(t, { $brand: { value: "auto-parseable-response-format", enumerable: !1 }, $parseRaw: { value: e, enumerable: !1 } }), t; } const Da = Symbol("Let zodToJsonSchema decide on which parser to use"), Fr = { 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" }, Pa = (n) => typeof n == "string" ? { ...Fr, basePath: ["#"], definitions: {}, name: n } : { ...Fr, basePath: ["#"], definitions: {}, ...n }, Kn = (n) => "_def" in n ? n._def : n; function ja(n) { if (!n) return !0; for (const e in n) return !1; return !0; } const Za = (n) => { const e = Pa(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]) => [ Kn(s), { def: Kn(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 Rs(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, Rs(n, e, r, s); } var Nt; (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; })(Nt || (Nt = {})); var Lr; (function(n) { n.mergeShapes = (e, t) => ({ ...e, ...t // second overwrites first }); })(Lr || (Lr = {})); Nt.arrayToEnum([ "string", "nan", "number", "integer", "float", "boolean", "date", "bigint", "symbol", "function", "undefined", "null", "array", "object", "unknown", "promise", "void", "never", "map", "set" ]); Nt.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 Ur = class Ds 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, c = 0; for (; c < i.path.length; ) { const l = i.path[c]; c === i.path.length - 1 ? (o[l] = o[l] || { _errors: [] }, o[l]._errors.push(t(i))) : o[l] = o[l] || { _errors: [] }, o = o[l], c++; } } }; return s(this), r; } static assert(e) { if (!(e instanceof Ds)) throw new Error(`Not a ZodError: ${e}`); } toString() { return this.message; } get message() { return JSON.stringify(this.issues, Nt.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(); } }; Ur.create = (n) => new Ur(n); var Jr; (function(n) { n.errToObj = (e) => typeof e == "string" ? { message: e } : e || {}, n.toString = (e) => typeof e == "string" ? e : e == null ? void 0 : e.message; })(Jr || (Jr = {})); var D; (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"; })(D || (D = {})); function Ma() { return {}; } function $a(n, e) { var r, s; const t = { type: "array" }; return ((s = (r = n.type) == null ? void 0 : r._def) == null ? void 0 : s.typeName) !== D.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 Fa(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 La() { return { type: "boolean" }; } function Ua(n, e) { return J(n.type._def, e); } const Ja = (n, e) => J(n.innerType._def, e); function Ps(n, e, t) { const r = t ?? e.dateStrategy; if (Array.isArray(r)) return { anyOf: r.map((s, a) => Ps(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 Ba(n, e); } } const Ba = (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 qa(n, e) { return { ...J(n.innerType._def, e), default: n.defaultValue() }; } function Ga(n, e, t) { return e.effectStrategy === "input" ? J(n.schema._def, e, t) : {}; } function Va(n) { return { type: "string", enum: [...n.values] }; } const za = (n) => "type" in n && n.type === "string" ? !1 : "allOf" in n; function Wa(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 (za(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, ...c } = a; i = c; } else r = void 0; s.push(i); } }), s.length ? { allOf: s, ...r } : void 0; } function Ha(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 Jn; const Be = { /** * `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: () => (Jn === void 0 && (Jn = RegExp("^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$", "u")), Jn), 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" ? Ya(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, Be.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, Be.cuid, s.message, e); break; case "cuid2": ge(t, Be.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, Be.emoji, s.message, e); break; case "ulid": { ge(t, Be.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, Be.base64, s.message, e); break; } } break; } case "nanoid": ge(t, Be.nanoid, s.message, e); } return t; } const Ya = (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: Br(e, r), ...t && r.errorMessages && { errorMessage: { pattern: t } } })) : q(n, "pattern", Br(e, r), t, r); }, Br = (n, e) => { var l; 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, c = !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]/)) { c ? (a += s[p], a += `${s[p - 2]}-${s[p]}`.toUpperCase(), c = !1) : s[p + 1] === "-" && ((l = s[p + 2]) != null && l.match(/[a-z]/)) ? (a += s[p], c = !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 Zs(n, e) { var r, s, a, i; if (e.target === "openApi3" && ((r = n.keyType) == null ? void 0 : r._def.typeName) === D.ZodEnum) return { type: "object", required: n.keyType._def.values, properties: n.keyType._def.values.reduce((o, c) => ({ ...o, [c]: J(n.valueType._def, { ...e, currentPath: [...e.currentPath, "properties", c] }) ?? {} }), {}), 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) === D.ZodString && ((a = n.keyType._def.checks) != null && a.length)) { const o = Object.entries(js(n.keyType._def, e)).reduce((c, [l, p]) => l === "type" ? c : { ...c, [l]: p }, {}); return { ...t, propertyNames: o }; } else if (((i = n.keyType) == null ? void 0 : i._def.typeName) === D.ZodEnum) return { ...t, propertyNames: { enum: n.keyType._def.values } }; return t; } function Xa(n, e) { if (e.mapStrategy === "record") return Zs(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 Qa(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 Ka() { return { not: {} }; } function ei(n) { return n.target === "openApi3" ? { enum: ["null"], nullable: !0 } : { type: "null" }; } const gn = { ZodString: "string", ZodNumber: "number", ZodBigInt: "integer", ZodBoolean: "boolean", ZodNull: "null" }; function ti(n, e) { if (e.target === "openApi3") return qr(n, e); const t = n.options instanceof Map ? Array.from(n.options.values()) : n.options; if (t.every((r) => r._def.typeName in gn && (!r._def.checks || !r._def.checks.length))) { const r = t.reduce((s, a) => { const i = gn[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 qr(n, e); } const qr = (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 ni(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: gn[n.innerType._def.typeName], nullable: !0 } : { type: [gn[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 ri(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", Rs(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 si(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 ai(n, e) { const t = { type: "object", ...Object.entries(n.shape()).reduce((r, [s, a]) => { var c; 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 ((c = a._def) == null ? void 0 : c.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: si(n, e) }; return t.required.length || delete t.required, t; } const ii = (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 ] } : {}; }, oi = (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 ui(n, e) { return J(n.type._def, e); } function ci(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 di(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 li() { return { not: {} }; } function pi() { return {}; } const fi = (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 !== Da) return o; } if (r && !t) { const o = hi(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 = gi(n, n.typeName, e, t); return a && _i(n, e, a), s.jsonSchema = a, a; } const hi = (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: mi(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; } }, mi = (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("/"); }, gi = (n, e, t, r) => { switch (e) { case D.ZodString: return js(n, t); case D.ZodNumber: return ri(n, t); case D.ZodObject: return ai(n, t); case D.ZodBigInt: return Fa(n, t); case D.ZodBoolean: return La(); case D.ZodDate: return Ps(n, t); case D.ZodUndefined: return li(); case D.ZodNull: return ei(t); case D.ZodArray: return $a(n, t); case D.ZodUnion: case D.ZodDiscriminatedUnion: return ti(n, t); case D.ZodIntersection: return Wa(n, t); case D.ZodTuple: return di(n, t); case D.ZodRecord: return Zs(n, t); case D.ZodLiteral: return Ha(n, t); case D.ZodEnum: return Va(n); case D.ZodNativeEnum: return Qa(n); case D.ZodNullable: return ni(n, t); case D.ZodOptional: return ii(n, t); case D.ZodMap: return Xa(n, t); case D.ZodSet: return ci(n, t); case D.ZodLazy: return J(n.getter()._def, t); case D.ZodPromise: return ui(n, t); case D.ZodNaN: case D.ZodNever: return Ka(); case D.ZodEffects: return Ga(n, t, r); case D.ZodAny: return Ma(); case D.ZodUnknown: return pi(); case D.ZodDefault: return qa(n, t); case D.ZodBranded: return Ua(n, t); case D.ZodReadonly: return fi(n, t); case D.ZodCatch: return Ja(n, t); case D.ZodPipeline: return oi(n, t); case D.ZodFunction: case D.ZodVoid: case D.ZodSymbol: return; default: return /* @__PURE__ */ ((s) => { })(); } }, _i = (n, e, t) => (n.description && (t.description = n.description, e.markdownDescription && (t.markdownDescription = n.description)), t), yi = (n, e) => { const t = Za(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 (ja(t.definitions)) return; const c = {}, l = /* @__PURE__ */ new Set(); for (let p = 0; p < 500; p++) { const f = Object.entries(t.definitions).filter(([h]) => !l.has(h)); if (f.length === 0) break; for (const [h, S] of f) c[h] = J(Kn(S), { ...t, currentPath: [...t.basePath, t.definitionPath, h] }, !0) ?? {}, l.add(h); } return c; })(), 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 vi(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 Ms(n, e) { return yi(n, { openaiStrictMode: !0, name: e.name, nameStrategy: "duplicate-ref", $refStrategy: "extract-to-root", nullableStrategy: "property" }); } function wi(n, e, t) { return Ra({ type: "json_schema", ...t, name: e, strict: !0, schema: Ms(n, { name: e }) }, (r) => n.parse(JSON.parse(r))); } function xi(n) { return vi({ type: "function", name: n.name, parameters: Ms(n.parameters, { name: n.name }), strict: !0 }, { callback: n.function, parser: (e) => n.parameters.parse(JSON.parse(e)) }); } class Je extends Error { constructor(t, r) { super(t); _(this, "state"); this.state = r; } } class bi extends Je { } class Gr extends Je { } class fe extends Je { } class Q extends Je { } class Vr extends Je { constructor(t, r, s) { super(t, s); _(this, "error"); this.error = r; } } class Si extends Je { constructor(t, r, s) { super(t, s); _(this, "error"); this.error = r; } } class zr extends Je { constructor(t, r, s) { super(t, s); _(this, "result"); this.result = r; } } class er extends Je { constructor(t, r, s) { super(t, s); _(this, "result"); this.result = r; } } function et(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 Ti(n) { return typeof n == "object" && n !== null && "input" in n && typeof n.input == "string"; } function _n(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 wr(n, e) { const t = (r) => JSON.parse(r); if (et(n)) { const r = xi({ 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 Wr(n) { if (n === "text") return "text"; if (et(n)) { const e = wi(n, "output"); return { type: e.type, name: e.name, strict: e.strict || !1, schema: e.schema }; } return n; } function ki(n) { return n && n.__esModule && Object.prototype.hasOwnProperty.call(n, "default") ? n.default : n; } var cn = { exports: {} }, Bn, Hr; function Ii() { if (Hr) return Bn; Hr = 1; var n = 1e3, e = n * 60, t = e * 60, r = t * 24, s = r * 7, a = r * 365.25; Bn = 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 ? c(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]), S = (f[2] || "ms").toLowerCase(); switch (S) { 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 c(p) { var f = Math.abs(p); return f >= r ? l(p, f, r, "day") : f >= t ? l(p, f, t, "hour") : f >= e ? l(p, f, e, "minute") : f >= n ? l(p, f, n, "second") : p + " ms"; } function l(p, f, h, S) { var x = f >= h * 1.5; return Math.round(p / h) + " " + S + (x ? "s" : ""); } return Bn; } var qn, Yr; function Ai() { if (Yr) return qn; Yr = 1; function n(e) { r.debug = r, r.default = r, r.coerce = l, r.disable = o, r.enable = a, r.enabled = c, r.humanize = Ii(), 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 S = 0; S < f.length; S++) h = (h << 5) - h + f.charCodeAt(S), h |= 0; return r.colors[Math.abs(h) % r.colors.length]; } r.selectColor = t; function r(f) { let h, S = null, x, w; function O(...R) { if (!O.enabled) return; const V = O, Y = Number(/* @__PURE__ */ new Date()), oe = Y - (h || Y); V.diff = oe, V.prev = h, V.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, (Ln, Sa) => { if (Ln === "%%") return "%"; ue++; const Zr = r.formatters[Sa]; if (typeof Zr == "function") { const Ta = R[ue]; Ln = Zr.call(V, Ta), R.splice(ue, 1), ue--; } return Ln; }), r.formatArgs.call(V, R), (V.log || r.log).apply(V, R); } return O.namespace = f, O.useColors = r.useColors(), O.color = r.selectColor(f), O.extend = s, O.destroy = r.destroy, Object.defineProperty(O, "enabled", { enumerable: !0, configurable: !1, get: () => S !== null ? S : (x !== r.namespaces && (x = r.namespaces, w = r.enabled(f)), w), set: (R) => { S = R; } }), typeof r.init == "function" && r.init(O), O; } function s(f, h) { const S = r(this.namespace + (typeof h > "u" ? ":" : h) + f); return S.log = this.log, S; } 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 S of h) S[0] === "-" ? r.skips.push(S.slice(1)) : r.names.push(S); } function i(f, h) { let S = 0, x = 0, w = -1, O = 0; for (; S < f.length; ) if (x < h.length && (h[x] === f[S] || h[x] === "*")) h[x] === "*" ? (w = x, O = S, x++) : (S++, x++); else if (w !== -1) x = w + 1, O++, S = O; else return !1; for (; x < h.length && h[x] === "*"; ) x++; return x === h.length; } function o() { const f = [ ...r.names, ...r.skips.map((h) => "-" + h) ].join(","); return r.enable(""), f; } function c(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 l(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 qn = n, qn; } var Xr; function Ci() { return Xr || (Xr = 1, function(n, e) { e.formatArgs = r, e.save = s, e.load = a, e.useColors = t, e.storage = i(), e.destroy = /* @__PURE__ */ (() => { let c = !1; return () => { c || (c = !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 c; 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 && (c = navigator.userAgent.toLowerCase().match(/firefox\/(\d+)/)) && parseInt(c[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(c) { if (c[0] = (this.useColors ? "%c" : "") + this.namespace + (this.useColors ? " %c" : " ") + c[0] + (this.useColors ? "%c " : " ") + "+" + n.exports.humanize(this.diff), !this.useColors) return; const l = "color: " + this.color; c.splice(1, 0, l, "color: inherit"); let p = 0, f = 0; c[0].replace(/%[a-zA-Z%]/g, (h) => { h !== "%%" && (p++, h === "%c" && (f = p)); }), c.splice(f, 0, l); } e.log = console.debug || console.log || (() => { }); function s(c) { try { c ? e.storage.setItem("debug", c) : e.storage.removeItem("debug"); } catch { } } function a() { let c; try { c = e.storage.getItem("debug") || e.storage.getItem("DEBUG"); } catch { } return !c && typeof process < "u" && "env" in process && (c = process.env.DEBUG), c; } function i() { try { return localStorage; } catch { } } n.exports = Ai()(e); const { formatters: o } = n.exports; o.j = function(c) { try { return JSON.stringify(c); } catch (l) { return "[UnexpectedJSONParseError]: " + l.message; } }; }(cn, cn.exports)), cn.exports; } var Oi = Ci(); const Ei = /* @__PURE__ */ ki(Oi); function Ni() { return fo(); } function Qr(n) { const e = Ni(); return typeof e < "u" && (e[n] === "true" || e[n] === "1"); } const $s = { get disabled() { return !0; } }, Fs = { get dontLogModelData() { return Qr("OPENAI_AGENTS_DONT_LOG_MODEL_DATA"); }, get dontLogToolData() { return Qr("OPENAI_AGENTS_DONT_LOG_TOOL_DATA"); } }, Ri = Fs.dontLogModelData, Di = Fs.dontLogToolData; function Ls(n = "openai-agents") { return { namespace: n, debug: Ei(n), error: console.error, warn: console.warn, dontLogModelData: Ri, dontLogToolData: Di }; } const C = Ls("openai-agents:core"); function tt(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 Pi(n, e) { return `An error occurred while running the tool. Please try again. Error: ${e instanceof Error ? e.toString() : String(e)}`; } function tr(n) { const e = n.name ? _n(n.name) : _n(n.execute.name), t = typeof n.errorFunction > "u" ? Pi : 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 && et(n.parameters)) throw new Q("Strict mode is required for Zod parameters"); const { parser: s, schema: a } = wr(n.parameters, e); async function i(l, p) { const [f, h] = await vr(() => 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 S = await n.execute(h, l), x = tt(S); return C.dontLogToolData ? C.debug(`Tool ${e} completed`) : C.debug(`Tool ${e} returned: ${x}`), S; } async function o(l, p) { return i(l, p).catch((f) => { if (t) { const h = jt(); return h == null || h.setError({ message: "Error running tool (non-fatal)", data: { tool_name: e, error: f.toString() } }), t(l, f); } throw f; }); } const c = typeof n.needsApproval == "function" ? n.needsApproval : async () => typeof n.needsApproval == "boolean" ? n.needsApproval : !1; return { type: "function", name: e, description: n.description, parameters: a, strict: r, invoke: o, needsApproval: c }; } var L; (function(n) { n.assertEqual = (s) => { }; function e(s) { } n.assertIs = e; functi