@babelbeez/sdk 0.1.1 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -3,8 +3,8 @@ var Vr = (n) => {
3
3
  throw TypeError(n);
4
4
  };
5
5
  var So = (n, e, t) => e in n ? Io(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
6
- var S = (n, e, t) => So(n, typeof e != "symbol" ? e + "" : e, t), Ms = (n, e, t) => e.has(n) || Vr("Cannot " + t);
7
- var c = (n, e, t) => (Ms(n, e, "read from private field"), t ? t.call(n) : e.get(n)), R = (n, e, t) => e.has(n) ? Vr("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(n) : e.set(n, t), k = (n, e, t, s) => (Ms(n, e, "write to private field"), s ? s.call(n, t) : e.set(n, t), t), z = (n, e, t) => (Ms(n, e, "access private method"), t);
6
+ var x = (n, e, t) => So(n, typeof e != "symbol" ? e + "" : e, t), Ms = (n, e, t) => e.has(n) || Vr("Cannot " + t);
7
+ var c = (n, e, t) => (Ms(n, e, "read from private field"), t ? t.call(n) : e.get(n)), N = (n, e, t) => e.has(n) ? Vr("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(n) : e.set(n, t), k = (n, e, t, s) => (Ms(n, e, "write to private field"), s ? s.call(n, t) : e.set(n, t), t), z = (n, e, t) => (Ms(n, e, "access private method"), t);
8
8
  const Vs = {
9
9
  version: "0.3.6"
10
10
  };
@@ -79,22 +79,22 @@ class Hr {
79
79
  if (u)
80
80
  a.schema = u;
81
81
  else {
82
- const _ = {
82
+ const v = {
83
83
  ...t,
84
84
  schemaPath: [...t.schemaPath, e],
85
85
  path: t.path
86
- }, T = e._zod.parent;
87
- if (T)
88
- a.ref = T, this.process(T, _), this.seen.get(T).isParent = !0;
86
+ }, S = e._zod.parent;
87
+ if (S)
88
+ a.ref = S, this.process(S, v), this.seen.get(S).isParent = !0;
89
89
  else {
90
90
  const y = a.schema;
91
91
  switch (r.type) {
92
92
  case "string": {
93
93
  const h = y;
94
94
  h.type = "string";
95
- const { minimum: w, maximum: v, format: N, patterns: x, contentEncoding: A } = e._zod.bag;
96
- if (typeof w == "number" && (h.minLength = w), typeof v == "number" && (h.maxLength = v), N && (h.format = i[N] ?? N, h.format === "" && delete h.format), A && (h.contentEncoding = A), x && x.size > 0) {
97
- const D = [...x];
95
+ const { minimum: w, maximum: _, format: R, patterns: T, contentEncoding: A } = e._zod.bag;
96
+ if (typeof w == "number" && (h.minLength = w), typeof _ == "number" && (h.maxLength = _), R && (h.format = i[R] ?? R, h.format === "" && delete h.format), A && (h.contentEncoding = A), T && T.size > 0) {
97
+ const D = [...T];
98
98
  D.length === 1 ? h.pattern = D[0].source : D.length > 1 && (a.schema.allOf = [
99
99
  ...D.map((U) => ({
100
100
  ...this.target === "draft-7" ? { type: "string" } : {},
@@ -105,8 +105,8 @@ class Hr {
105
105
  break;
106
106
  }
107
107
  case "number": {
108
- const h = y, { minimum: w, maximum: v, format: N, multipleOf: x, exclusiveMaximum: A, exclusiveMinimum: D } = e._zod.bag;
109
- typeof N == "string" && N.includes("int") ? h.type = "integer" : h.type = "number", typeof D == "number" && (h.exclusiveMinimum = D), typeof w == "number" && (h.minimum = w, typeof D == "number" && (D >= w ? delete h.minimum : delete h.exclusiveMinimum)), typeof A == "number" && (h.exclusiveMaximum = A), typeof v == "number" && (h.maximum = v, typeof A == "number" && (A <= v ? delete h.maximum : delete h.exclusiveMaximum)), typeof x == "number" && (h.multipleOf = x);
108
+ const h = y, { minimum: w, maximum: _, format: R, multipleOf: T, exclusiveMaximum: A, exclusiveMinimum: D } = e._zod.bag;
109
+ typeof R == "string" && R.includes("int") ? h.type = "integer" : h.type = "number", typeof D == "number" && (h.exclusiveMinimum = D), typeof w == "number" && (h.minimum = w, typeof D == "number" && (D >= w ? delete h.minimum : delete h.exclusiveMinimum)), typeof A == "number" && (h.exclusiveMaximum = A), typeof _ == "number" && (h.maximum = _, typeof A == "number" && (A <= _ ? delete h.maximum : delete h.exclusiveMaximum)), typeof T == "number" && (h.multipleOf = T);
110
110
  break;
111
111
  }
112
112
  case "boolean": {
@@ -152,75 +152,75 @@ class Hr {
152
152
  break;
153
153
  }
154
154
  case "array": {
155
- const h = y, { minimum: w, maximum: v } = e._zod.bag;
156
- typeof w == "number" && (h.minItems = w), typeof v == "number" && (h.maxItems = v), h.type = "array", h.items = this.process(r.element, { ..._, path: [..._.path, "items"] });
155
+ const h = y, { minimum: w, maximum: _ } = e._zod.bag;
156
+ typeof w == "number" && (h.minItems = w), typeof _ == "number" && (h.maxItems = _), h.type = "array", h.items = this.process(r.element, { ...v, path: [...v.path, "items"] });
157
157
  break;
158
158
  }
159
159
  case "object": {
160
160
  const h = y;
161
161
  h.type = "object", h.properties = {};
162
162
  const w = r.shape;
163
- for (const x in w)
164
- h.properties[x] = this.process(w[x], {
165
- ..._,
166
- path: [..._.path, "properties", x]
163
+ for (const T in w)
164
+ h.properties[T] = this.process(w[T], {
165
+ ...v,
166
+ path: [...v.path, "properties", T]
167
167
  });
168
- const v = new Set(Object.keys(w)), N = new Set([...v].filter((x) => {
169
- const A = r.shape[x]._zod;
168
+ const _ = new Set(Object.keys(w)), R = new Set([..._].filter((T) => {
169
+ const A = r.shape[T]._zod;
170
170
  return this.io === "input" ? A.optin === void 0 : A.optout === void 0;
171
171
  }));
172
- N.size > 0 && (h.required = Array.from(N)), ((g = r.catchall) == null ? void 0 : g._zod.def.type) === "never" ? h.additionalProperties = !1 : r.catchall ? r.catchall && (h.additionalProperties = this.process(r.catchall, {
173
- ..._,
174
- path: [..._.path, "additionalProperties"]
172
+ R.size > 0 && (h.required = Array.from(R)), ((g = r.catchall) == null ? void 0 : g._zod.def.type) === "never" ? h.additionalProperties = !1 : r.catchall ? r.catchall && (h.additionalProperties = this.process(r.catchall, {
173
+ ...v,
174
+ path: [...v.path, "additionalProperties"]
175
175
  })) : this.io === "output" && (h.additionalProperties = !1);
176
176
  break;
177
177
  }
178
178
  case "union": {
179
179
  const h = y;
180
- h.anyOf = r.options.map((w, v) => this.process(w, {
181
- ..._,
182
- path: [..._.path, "anyOf", v]
180
+ h.anyOf = r.options.map((w, _) => this.process(w, {
181
+ ...v,
182
+ path: [...v.path, "anyOf", _]
183
183
  }));
184
184
  break;
185
185
  }
186
186
  case "intersection": {
187
187
  const h = y, w = this.process(r.left, {
188
- ..._,
189
- path: [..._.path, "allOf", 0]
190
- }), v = this.process(r.right, {
191
- ..._,
192
- path: [..._.path, "allOf", 1]
193
- }), N = (A) => "allOf" in A && Object.keys(A).length === 1, x = [
194
- ...N(w) ? w.allOf : [w],
195
- ...N(v) ? v.allOf : [v]
188
+ ...v,
189
+ path: [...v.path, "allOf", 0]
190
+ }), _ = this.process(r.right, {
191
+ ...v,
192
+ path: [...v.path, "allOf", 1]
193
+ }), R = (A) => "allOf" in A && Object.keys(A).length === 1, T = [
194
+ ...R(w) ? w.allOf : [w],
195
+ ...R(_) ? _.allOf : [_]
196
196
  ];
197
- h.allOf = x;
197
+ h.allOf = T;
198
198
  break;
199
199
  }
200
200
  case "tuple": {
201
201
  const h = y;
202
202
  h.type = "array";
203
- const w = r.items.map((x, A) => this.process(x, { ..._, path: [..._.path, "prefixItems", A] }));
203
+ const w = r.items.map((T, A) => this.process(T, { ...v, path: [...v.path, "prefixItems", A] }));
204
204
  if (this.target === "draft-2020-12" ? h.prefixItems = w : h.items = w, r.rest) {
205
- const x = this.process(r.rest, {
206
- ..._,
207
- path: [..._.path, "items"]
205
+ const T = this.process(r.rest, {
206
+ ...v,
207
+ path: [...v.path, "items"]
208
208
  });
209
- this.target === "draft-2020-12" ? h.items = x : h.additionalItems = x;
209
+ this.target === "draft-2020-12" ? h.items = T : h.additionalItems = T;
210
210
  }
211
211
  r.rest && (h.items = this.process(r.rest, {
212
- ..._,
213
- path: [..._.path, "items"]
212
+ ...v,
213
+ path: [...v.path, "items"]
214
214
  }));
215
- const { minimum: v, maximum: N } = e._zod.bag;
216
- typeof v == "number" && (h.minItems = v), typeof N == "number" && (h.maxItems = N);
215
+ const { minimum: _, maximum: R } = e._zod.bag;
216
+ typeof _ == "number" && (h.minItems = _), typeof R == "number" && (h.maxItems = R);
217
217
  break;
218
218
  }
219
219
  case "record": {
220
220
  const h = y;
221
- h.type = "object", h.propertyNames = this.process(r.keyType, { ..._, path: [..._.path, "propertyNames"] }), h.additionalProperties = this.process(r.valueType, {
222
- ..._,
223
- path: [..._.path, "additionalProperties"]
221
+ h.type = "object", h.propertyNames = this.process(r.keyType, { ...v, path: [...v.path, "propertyNames"] }), h.additionalProperties = this.process(r.valueType, {
222
+ ...v,
223
+ path: [...v.path, "additionalProperties"]
224
224
  });
225
225
  break;
226
226
  }
@@ -236,26 +236,26 @@ class Hr {
236
236
  }
237
237
  case "enum": {
238
238
  const h = y, w = To(r.entries);
239
- w.every((v) => typeof v == "number") && (h.type = "number"), w.every((v) => typeof v == "string") && (h.type = "string"), h.enum = w;
239
+ w.every((_) => typeof _ == "number") && (h.type = "number"), w.every((_) => typeof _ == "string") && (h.type = "string"), h.enum = w;
240
240
  break;
241
241
  }
242
242
  case "literal": {
243
243
  const h = y, w = [];
244
- for (const v of r.values)
245
- if (v === void 0) {
244
+ for (const _ of r.values)
245
+ if (_ === void 0) {
246
246
  if (this.unrepresentable === "throw")
247
247
  throw new Error("Literal `undefined` cannot be represented in JSON Schema");
248
- } else if (typeof v == "bigint") {
248
+ } else if (typeof _ == "bigint") {
249
249
  if (this.unrepresentable === "throw")
250
250
  throw new Error("BigInt literals cannot be represented in JSON Schema");
251
- w.push(Number(v));
251
+ w.push(Number(_));
252
252
  } else
253
- w.push(v);
253
+ w.push(_);
254
254
  if (w.length !== 0) if (w.length === 1) {
255
- const v = w[0];
256
- h.type = v === null ? "null" : typeof v, h.const = v;
255
+ const _ = w[0];
256
+ h.type = _ === null ? "null" : typeof _, h.const = _;
257
257
  } else
258
- w.every((v) => typeof v == "number") && (h.type = "number"), w.every((v) => typeof v == "string") && (h.type = "string"), w.every((v) => typeof v == "boolean") && (h.type = "string"), w.every((v) => v === null) && (h.type = "null"), h.enum = w;
258
+ w.every((_) => typeof _ == "number") && (h.type = "number"), w.every((_) => typeof _ == "string") && (h.type = "string"), w.every((_) => typeof _ == "boolean") && (h.type = "string"), w.every((_) => _ === null) && (h.type = "null"), h.enum = w;
259
259
  break;
260
260
  }
261
261
  case "file": {
@@ -263,8 +263,8 @@ class Hr {
263
263
  type: "string",
264
264
  format: "binary",
265
265
  contentEncoding: "binary"
266
- }, { minimum: v, maximum: N, mime: x } = e._zod.bag;
267
- v !== void 0 && (w.minLength = v), N !== void 0 && (w.maxLength = N), x ? x.length === 1 ? (w.contentMediaType = x[0], Object.assign(h, w)) : h.anyOf = x.map((A) => ({ ...w, contentMediaType: A })) : Object.assign(h, w);
266
+ }, { minimum: _, maximum: R, mime: T } = e._zod.bag;
267
+ _ !== void 0 && (w.minLength = _), R !== void 0 && (w.maxLength = R), T ? T.length === 1 ? (w.contentMediaType = T[0], Object.assign(h, w)) : h.anyOf = T.map((A) => ({ ...w, contentMediaType: A })) : Object.assign(h, w);
268
268
  break;
269
269
  }
270
270
  case "transform": {
@@ -273,12 +273,12 @@ class Hr {
273
273
  break;
274
274
  }
275
275
  case "nullable": {
276
- const h = this.process(r.innerType, _);
276
+ const h = this.process(r.innerType, v);
277
277
  y.anyOf = [h, { type: "null" }];
278
278
  break;
279
279
  }
280
280
  case "nonoptional": {
281
- this.process(r.innerType, _), a.ref = r.innerType;
281
+ this.process(r.innerType, v), a.ref = r.innerType;
282
282
  break;
283
283
  }
284
284
  case "success": {
@@ -287,15 +287,15 @@ class Hr {
287
287
  break;
288
288
  }
289
289
  case "default": {
290
- this.process(r.innerType, _), a.ref = r.innerType, y.default = JSON.parse(JSON.stringify(r.defaultValue));
290
+ this.process(r.innerType, v), a.ref = r.innerType, y.default = JSON.parse(JSON.stringify(r.defaultValue));
291
291
  break;
292
292
  }
293
293
  case "prefault": {
294
- this.process(r.innerType, _), a.ref = r.innerType, this.io === "input" && (y._prefault = JSON.parse(JSON.stringify(r.defaultValue)));
294
+ this.process(r.innerType, v), a.ref = r.innerType, this.io === "input" && (y._prefault = JSON.parse(JSON.stringify(r.defaultValue)));
295
295
  break;
296
296
  }
297
297
  case "catch": {
298
- this.process(r.innerType, _), a.ref = r.innerType;
298
+ this.process(r.innerType, v), a.ref = r.innerType;
299
299
  let h;
300
300
  try {
301
301
  h = r.catchValue(void 0);
@@ -319,25 +319,25 @@ class Hr {
319
319
  }
320
320
  case "pipe": {
321
321
  const h = this.io === "input" ? r.in._zod.def.type === "transform" ? r.out : r.in : r.out;
322
- this.process(h, _), a.ref = h;
322
+ this.process(h, v), a.ref = h;
323
323
  break;
324
324
  }
325
325
  case "readonly": {
326
- this.process(r.innerType, _), a.ref = r.innerType, y.readOnly = !0;
326
+ this.process(r.innerType, v), a.ref = r.innerType, y.readOnly = !0;
327
327
  break;
328
328
  }
329
329
  // passthrough types
330
330
  case "promise": {
331
- this.process(r.innerType, _), a.ref = r.innerType;
331
+ this.process(r.innerType, v), a.ref = r.innerType;
332
332
  break;
333
333
  }
334
334
  case "optional": {
335
- this.process(r.innerType, _), a.ref = r.innerType;
335
+ this.process(r.innerType, v), a.ref = r.innerType;
336
336
  break;
337
337
  }
338
338
  case "lazy": {
339
339
  const h = e._zod.innerType;
340
- this.process(h, _), a.ref = h;
340
+ this.process(h, v), a.ref = h;
341
341
  break;
342
342
  }
343
343
  case "custom": {
@@ -352,7 +352,7 @@ class Hr {
352
352
  return l && Object.assign(a.schema, l), this.io === "input" && de(e) && (delete a.schema.examples, delete a.schema.default), this.io === "input" && a.schema._prefault && ((s = a.schema).default ?? (s.default = a.schema._prefault)), delete a.schema._prefault, this.seen.get(e).schema;
353
353
  }
354
354
  emit(e, t) {
355
- var p, d, m, g, _, T;
355
+ var p, d, m, g, v, S;
356
356
  const s = {
357
357
  cycles: (t == null ? void 0 : t.cycles) ?? "ref",
358
358
  reused: (t == null ? void 0 : t.reused) ?? "inline",
@@ -363,10 +363,10 @@ class Hr {
363
363
  if (!r)
364
364
  throw new Error("Unprocessed schema. This is a bug in Zod.");
365
365
  const i = (y) => {
366
- var x;
366
+ var T;
367
367
  const h = this.target === "draft-2020-12" ? "$defs" : "definitions";
368
368
  if (s.external) {
369
- const A = (x = s.external.registry.get(y[0])) == null ? void 0 : x.id, D = s.external.uri ?? ((G) => G);
369
+ const A = (T = s.external.registry.get(y[0])) == null ? void 0 : T.id, D = s.external.uri ?? ((G) => G);
370
370
  if (A)
371
371
  return { ref: D(A) };
372
372
  const U = y[1].defId ?? y[1].schema.id ?? `schema${this.counter++}`;
@@ -374,17 +374,17 @@ class Hr {
374
374
  }
375
375
  if (y[1] === r)
376
376
  return { ref: "#" };
377
- const v = `#/${h}/`, N = y[1].schema.id ?? `__schema${this.counter++}`;
378
- return { defId: N, ref: v + N };
377
+ const _ = `#/${h}/`, R = y[1].schema.id ?? `__schema${this.counter++}`;
378
+ return { defId: R, ref: _ + R };
379
379
  }, o = (y) => {
380
380
  if (y[1].schema.$ref)
381
381
  return;
382
- const h = y[1], { ref: w, defId: v } = i(y);
383
- h.def = { ...h.schema }, v && (h.defId = v);
384
- const N = h.schema;
385
- for (const x in N)
386
- delete N[x];
387
- N.$ref = w;
382
+ const h = y[1], { ref: w, defId: _ } = i(y);
383
+ h.def = { ...h.schema }, _ && (h.defId = _);
384
+ const R = h.schema;
385
+ for (const T in R)
386
+ delete R[T];
387
+ R.$ref = w;
388
388
  };
389
389
  if (s.cycles === "throw")
390
390
  for (const y of this.seen.entries()) {
@@ -401,8 +401,8 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
401
401
  continue;
402
402
  }
403
403
  if (s.external) {
404
- const v = (d = s.external.registry.get(y[0])) == null ? void 0 : d.id;
405
- if (e !== y[0] && v) {
404
+ const _ = (d = s.external.registry.get(y[0])) == null ? void 0 : d.id;
405
+ if (e !== y[0] && _) {
406
406
  o(y);
407
407
  continue;
408
408
  }
@@ -421,18 +421,18 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
421
421
  }
422
422
  }
423
423
  const a = (y, h) => {
424
- const w = this.seen.get(y), v = w.def ?? w.schema, N = { ...v };
424
+ const w = this.seen.get(y), _ = w.def ?? w.schema, R = { ..._ };
425
425
  if (w.ref === null)
426
426
  return;
427
- const x = w.ref;
428
- if (w.ref = null, x) {
429
- a(x, h);
430
- const A = this.seen.get(x).schema;
431
- A.$ref && h.target === "draft-7" ? (v.allOf = v.allOf ?? [], v.allOf.push(A)) : (Object.assign(v, A), Object.assign(v, N));
427
+ const T = w.ref;
428
+ if (w.ref = null, T) {
429
+ a(T, h);
430
+ const A = this.seen.get(T).schema;
431
+ A.$ref && h.target === "draft-7" ? (_.allOf = _.allOf ?? [], _.allOf.push(A)) : (Object.assign(_, A), Object.assign(_, R));
432
432
  }
433
433
  w.isParent || this.override({
434
434
  zodSchema: y,
435
- jsonSchema: v,
435
+ jsonSchema: _,
436
436
  path: w.path ?? []
437
437
  });
438
438
  };
@@ -440,13 +440,13 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
440
440
  a(y[0], { target: this.target });
441
441
  const u = {};
442
442
  if (this.target === "draft-2020-12" ? u.$schema = "https://json-schema.org/draft/2020-12/schema" : this.target === "draft-7" ? u.$schema = "http://json-schema.org/draft-07/schema#" : console.warn(`Invalid target: ${this.target}`), (g = s.external) != null && g.uri) {
443
- const y = (_ = s.external.registry.get(e)) == null ? void 0 : _.id;
443
+ const y = (v = s.external.registry.get(e)) == null ? void 0 : v.id;
444
444
  if (!y)
445
445
  throw new Error("Schema is missing an `id` property");
446
446
  u.$id = s.external.uri(y);
447
447
  }
448
448
  Object.assign(u, r.def);
449
- const l = ((T = s.external) == null ? void 0 : T.defs) ?? {};
449
+ const l = ((S = s.external) == null ? void 0 : S.defs) ?? {};
450
450
  for (const y of this.seen.entries()) {
451
451
  const h = y[1];
452
452
  h.def && h.defId && (l[h.defId] = h.def);
@@ -1124,7 +1124,7 @@ class K {
1124
1124
  return this._refinement((s, r) => e(s) ? !0 : (r.addIssue(typeof t == "function" ? t(s, r) : t), !1));
1125
1125
  }
1126
1126
  _refinement(e) {
1127
- return new Ft({
1127
+ return new $t({
1128
1128
  schema: this,
1129
1129
  typeName: O.ZodEffects,
1130
1130
  effect: { type: "refinement", refinement: e }
@@ -1144,7 +1144,7 @@ class K {
1144
1144
  return tt.create(this, this._def);
1145
1145
  }
1146
1146
  nullable() {
1147
- return $t.create(this, this._def);
1147
+ return jt.create(this, this._def);
1148
1148
  }
1149
1149
  nullish() {
1150
1150
  return this.nullable().optional();
@@ -1162,7 +1162,7 @@ class K {
1162
1162
  return ls.create(this, e, this._def);
1163
1163
  }
1164
1164
  transform(e) {
1165
- return new Ft({
1165
+ return new $t({
1166
1166
  ...V(this._def),
1167
1167
  schema: this,
1168
1168
  typeName: O.ZodEffects,
@@ -2217,12 +2217,12 @@ je.create = (n, e) => new je({
2217
2217
  typeName: O.ZodArray,
2218
2218
  ...V(e)
2219
2219
  });
2220
- function zt(n) {
2220
+ function Bt(n) {
2221
2221
  if (n instanceof ce) {
2222
2222
  const e = {};
2223
2223
  for (const t in n.shape) {
2224
2224
  const s = n.shape[t];
2225
- e[t] = tt.create(zt(s));
2225
+ e[t] = tt.create(Bt(s));
2226
2226
  }
2227
2227
  return new ce({
2228
2228
  ...n._def,
@@ -2230,8 +2230,8 @@ function zt(n) {
2230
2230
  });
2231
2231
  } else return n instanceof je ? new je({
2232
2232
  ...n._def,
2233
- type: zt(n.element)
2234
- }) : n instanceof tt ? tt.create(zt(n.unwrap())) : n instanceof $t ? $t.create(zt(n.unwrap())) : n instanceof Dt ? Dt.create(n.items.map((e) => zt(e))) : n;
2233
+ type: Bt(n.element)
2234
+ }) : n instanceof tt ? tt.create(Bt(n.unwrap())) : n instanceof jt ? jt.create(Bt(n.unwrap())) : n instanceof Mt ? Mt.create(n.items.map((e) => Bt(e))) : n;
2235
2235
  }
2236
2236
  class ce extends K {
2237
2237
  constructor() {
@@ -2467,7 +2467,7 @@ class ce extends K {
2467
2467
  * @deprecated
2468
2468
  */
2469
2469
  deepPartial() {
2470
- return zt(this);
2470
+ return Bt(this);
2471
2471
  }
2472
2472
  partial(e) {
2473
2473
  const t = {};
@@ -2594,7 +2594,7 @@ cs.create = (n, e) => new cs({
2594
2594
  typeName: O.ZodUnion,
2595
2595
  ...V(e)
2596
2596
  });
2597
- const Je = (n) => n instanceof ps ? Je(n.schema) : n instanceof Ft ? Je(n.innerType()) : n instanceof fs ? [n.value] : n instanceof Mt ? n.options : n instanceof er ? X.objectValues(n.enum) : n instanceof ms ? Je(n._def.innerType) : n instanceof Ys ? [void 0] : n instanceof Xs ? [null] : n instanceof tt ? [void 0, ...Je(n.unwrap())] : n instanceof $t ? [null, ...Je(n.unwrap())] : n instanceof aa || n instanceof ys ? Je(n.unwrap()) : n instanceof gs ? Je(n._def.innerType) : [];
2597
+ const Je = (n) => n instanceof ps ? Je(n.schema) : n instanceof $t ? Je(n.innerType()) : n instanceof fs ? [n.value] : n instanceof Ft ? n.options : n instanceof er ? X.objectValues(n.enum) : n instanceof ms ? Je(n._def.innerType) : n instanceof Ys ? [void 0] : n instanceof Xs ? [null] : n instanceof tt ? [void 0, ...Je(n.unwrap())] : n instanceof jt ? [null, ...Je(n.unwrap())] : n instanceof aa || n instanceof ys ? Je(n.unwrap()) : n instanceof gs ? Je(n._def.innerType) : [];
2598
2598
  class Sr extends K {
2599
2599
  _parse(e) {
2600
2600
  const { ctx: t } = this._processInputParams(e);
@@ -2721,7 +2721,7 @@ ls.create = (n, e, t) => new ls({
2721
2721
  typeName: O.ZodIntersection,
2722
2722
  ...V(t)
2723
2723
  });
2724
- class Dt extends K {
2724
+ class Mt extends K {
2725
2725
  _parse(e) {
2726
2726
  const { status: t, ctx: s } = this._processInputParams(e);
2727
2727
  if (s.parsedType !== M.array)
@@ -2755,16 +2755,16 @@ class Dt extends K {
2755
2755
  return this._def.items;
2756
2756
  }
2757
2757
  rest(e) {
2758
- return new Dt({
2758
+ return new Mt({
2759
2759
  ...this._def,
2760
2760
  rest: e
2761
2761
  });
2762
2762
  }
2763
2763
  }
2764
- Dt.create = (n, e) => {
2764
+ Mt.create = (n, e) => {
2765
2765
  if (!Array.isArray(n))
2766
2766
  throw new Error("You must pass an array of schemas to z.tuple([ ... ])");
2767
- return new Dt({
2767
+ return new Mt({
2768
2768
  items: n,
2769
2769
  typeName: O.ZodTuple,
2770
2770
  rest: null,
@@ -2960,13 +2960,13 @@ fs.create = (n, e) => new fs({
2960
2960
  ...V(e)
2961
2961
  });
2962
2962
  function ia(n, e) {
2963
- return new Mt({
2963
+ return new Ft({
2964
2964
  values: n,
2965
2965
  typeName: O.ZodEnum,
2966
2966
  ...V(e)
2967
2967
  });
2968
2968
  }
2969
- class Mt extends K {
2969
+ class Ft extends K {
2970
2970
  _parse(e) {
2971
2971
  if (typeof e.data != "string") {
2972
2972
  const t = this._getOrReturnCtx(e), s = this._def.values;
@@ -3008,19 +3008,19 @@ class Mt extends K {
3008
3008
  return e;
3009
3009
  }
3010
3010
  extract(e, t = this._def) {
3011
- return Mt.create(e, {
3011
+ return Ft.create(e, {
3012
3012
  ...this._def,
3013
3013
  ...t
3014
3014
  });
3015
3015
  }
3016
3016
  exclude(e, t = this._def) {
3017
- return Mt.create(this.options.filter((s) => !e.includes(s)), {
3017
+ return Ft.create(this.options.filter((s) => !e.includes(s)), {
3018
3018
  ...this._def,
3019
3019
  ...t
3020
3020
  });
3021
3021
  }
3022
3022
  }
3023
- Mt.create = ia;
3023
+ Ft.create = ia;
3024
3024
  class er extends K {
3025
3025
  _parse(e) {
3026
3026
  const t = X.getValidEnumValues(this._def.values), s = this._getOrReturnCtx(e);
@@ -3075,7 +3075,7 @@ hs.create = (n, e) => new hs({
3075
3075
  typeName: O.ZodPromise,
3076
3076
  ...V(e)
3077
3077
  });
3078
- class Ft extends K {
3078
+ class $t extends K {
3079
3079
  innerType() {
3080
3080
  return this._def.schema;
3081
3081
  }
@@ -3155,13 +3155,13 @@ class Ft extends K {
3155
3155
  X.assertNever(r);
3156
3156
  }
3157
3157
  }
3158
- Ft.create = (n, e, t) => new Ft({
3158
+ $t.create = (n, e, t) => new $t({
3159
3159
  schema: n,
3160
3160
  typeName: O.ZodEffects,
3161
3161
  effect: e,
3162
3162
  ...V(t)
3163
3163
  });
3164
- Ft.createWithPreprocess = (n, e, t) => new Ft({
3164
+ $t.createWithPreprocess = (n, e, t) => new $t({
3165
3165
  schema: e,
3166
3166
  effect: { type: "preprocess", transform: n },
3167
3167
  typeName: O.ZodEffects,
@@ -3180,7 +3180,7 @@ tt.create = (n, e) => new tt({
3180
3180
  typeName: O.ZodOptional,
3181
3181
  ...V(e)
3182
3182
  });
3183
- class $t extends K {
3183
+ class jt extends K {
3184
3184
  _parse(e) {
3185
3185
  return this._getType(e) === M.null ? Ce(null) : this._def.innerType._parse(e);
3186
3186
  }
@@ -3188,7 +3188,7 @@ class $t extends K {
3188
3188
  return this._def.innerType;
3189
3189
  }
3190
3190
  }
3191
- $t.create = (n, e) => new $t({
3191
+ jt.create = (n, e) => new jt({
3192
3192
  innerType: n,
3193
3193
  typeName: O.ZodNullable,
3194
3194
  ...V(e)
@@ -3366,15 +3366,15 @@ var O;
3366
3366
  })(O || (O = {}));
3367
3367
  const oa = (n, e = {
3368
3368
  message: `Input not instance of ${n.name}`
3369
- }) => ru((t) => t instanceof n, e), f = et.create, E = ln.create, Pt = Ks.create, W = Sn.create;
3369
+ }) => ru((t) => t instanceof n, e), f = et.create, E = ln.create, Dt = Ks.create, W = Sn.create;
3370
3370
  ft.create;
3371
3371
  const J = je.create, b = ce.create, nt = cs.create, ye = Sr.create;
3372
3372
  ls.create;
3373
- Dt.create;
3374
- const se = ds.create, iu = ps.create, I = fs.create, le = Mt.create;
3373
+ Mt.create;
3374
+ const se = ds.create, iu = ps.create, I = fs.create, le = Ft.create;
3375
3375
  hs.create;
3376
3376
  tt.create;
3377
- $t.create;
3377
+ jt.create;
3378
3378
  function au() {
3379
3379
  return {};
3380
3380
  }
@@ -4343,7 +4343,7 @@ function Vu(n) {
4343
4343
  class mt extends Error {
4344
4344
  constructor(t, s) {
4345
4345
  super(t);
4346
- S(this, "state");
4346
+ x(this, "state");
4347
4347
  this.state = s;
4348
4348
  }
4349
4349
  }
@@ -4358,28 +4358,28 @@ class ne extends mt {
4358
4358
  class ci extends mt {
4359
4359
  constructor(t, s, r) {
4360
4360
  super(t, r);
4361
- S(this, "error");
4361
+ x(this, "error");
4362
4362
  this.error = s;
4363
4363
  }
4364
4364
  }
4365
4365
  class Wu extends mt {
4366
4366
  constructor(t, s, r) {
4367
4367
  super(t, r);
4368
- S(this, "error");
4368
+ x(this, "error");
4369
4369
  this.error = s;
4370
4370
  }
4371
4371
  }
4372
4372
  class li extends mt {
4373
4373
  constructor(t, s, r) {
4374
4374
  super(t, r);
4375
- S(this, "result");
4375
+ x(this, "result");
4376
4376
  this.result = s;
4377
4377
  }
4378
4378
  }
4379
4379
  class nr extends mt {
4380
4380
  constructor(t, s, r) {
4381
4381
  super(t, r);
4382
- S(this, "result");
4382
+ x(this, "result");
4383
4383
  this.result = s;
4384
4384
  }
4385
4385
  }
@@ -4400,7 +4400,7 @@ function ks(n) {
4400
4400
  const s = t.toLowerCase();
4401
4401
  return s.startsWith("zod") ? s.slice(3) : s;
4402
4402
  }
4403
- function jt(n) {
4403
+ function Ut(n) {
4404
4404
  return pn(n) ? ks(n) === "object" : !1;
4405
4405
  }
4406
4406
  function Ku(n) {
@@ -4607,7 +4607,7 @@ function vs(n) {
4607
4607
  }
4608
4608
  function xr(n, e) {
4609
4609
  const t = (s) => JSON.parse(s);
4610
- if (jt(n)) {
4610
+ if (Ut(n)) {
4611
4611
  const s = (i) => {
4612
4612
  const o = _a(n);
4613
4613
  if (o)
@@ -4645,7 +4645,7 @@ function xr(n, e) {
4645
4645
  function pi(n) {
4646
4646
  if (n === "text")
4647
4647
  return "text";
4648
- if (jt(n)) {
4648
+ if (Ut(n)) {
4649
4649
  const e = (s, r) => {
4650
4650
  const i = _a(n);
4651
4651
  if (i)
@@ -4753,8 +4753,8 @@ function gc() {
4753
4753
  return d >= s ? l(p, d, s, "day") : d >= t ? l(p, d, t, "hour") : d >= e ? l(p, d, e, "minute") : d >= n ? l(p, d, n, "second") : p + " ms";
4754
4754
  }
4755
4755
  function l(p, d, m, g) {
4756
- var _ = d >= m * 1.5;
4757
- return Math.round(p / m) + " " + g + (_ ? "s" : "");
4756
+ var v = d >= m * 1.5;
4757
+ return Math.round(p / m) + " " + g + (v ? "s" : "");
4758
4758
  }
4759
4759
  return js;
4760
4760
  }
@@ -4774,21 +4774,21 @@ function yc() {
4774
4774
  }
4775
4775
  s.selectColor = t;
4776
4776
  function s(d) {
4777
- let m, g = null, _, T;
4777
+ let m, g = null, v, S;
4778
4778
  function y(...h) {
4779
4779
  if (!y.enabled)
4780
4780
  return;
4781
- const w = y, v = Number(/* @__PURE__ */ new Date()), N = v - (m || v);
4782
- w.diff = N, w.prev = m, w.curr = v, m = v, h[0] = s.coerce(h[0]), typeof h[0] != "string" && h.unshift("%O");
4783
- let x = 0;
4781
+ const w = y, _ = Number(/* @__PURE__ */ new Date()), R = _ - (m || _);
4782
+ w.diff = R, w.prev = m, w.curr = _, m = _, h[0] = s.coerce(h[0]), typeof h[0] != "string" && h.unshift("%O");
4783
+ let T = 0;
4784
4784
  h[0] = h[0].replace(/%([a-zA-Z%])/g, (D, U) => {
4785
4785
  if (D === "%%")
4786
4786
  return "%";
4787
- x++;
4787
+ T++;
4788
4788
  const G = s.formatters[U];
4789
4789
  if (typeof G == "function") {
4790
- const L = h[x];
4791
- D = G.call(w, L), h.splice(x, 1), x--;
4790
+ const L = h[T];
4791
+ D = G.call(w, L), h.splice(T, 1), T--;
4792
4792
  }
4793
4793
  return D;
4794
4794
  }), s.formatArgs.call(w, h), (w.log || s.log).apply(w, h);
@@ -4796,7 +4796,7 @@ function yc() {
4796
4796
  return y.namespace = d, y.useColors = s.useColors(), y.color = s.selectColor(d), y.extend = r, y.destroy = s.destroy, Object.defineProperty(y, "enabled", {
4797
4797
  enumerable: !0,
4798
4798
  configurable: !1,
4799
- get: () => g !== null ? g : (_ !== s.namespaces && (_ = s.namespaces, T = s.enabled(d)), T),
4799
+ get: () => g !== null ? g : (v !== s.namespaces && (v = s.namespaces, S = s.enabled(d)), S),
4800
4800
  set: (h) => {
4801
4801
  g = h;
4802
4802
  }
@@ -4813,17 +4813,17 @@ function yc() {
4813
4813
  g[0] === "-" ? s.skips.push(g.slice(1)) : s.names.push(g);
4814
4814
  }
4815
4815
  function o(d, m) {
4816
- let g = 0, _ = 0, T = -1, y = 0;
4816
+ let g = 0, v = 0, S = -1, y = 0;
4817
4817
  for (; g < d.length; )
4818
- if (_ < m.length && (m[_] === d[g] || m[_] === "*"))
4819
- m[_] === "*" ? (T = _, y = g, _++) : (g++, _++);
4820
- else if (T !== -1)
4821
- _ = T + 1, y++, g = y;
4818
+ if (v < m.length && (m[v] === d[g] || m[v] === "*"))
4819
+ m[v] === "*" ? (S = v, y = g, v++) : (g++, v++);
4820
+ else if (S !== -1)
4821
+ v = S + 1, y++, g = y;
4822
4822
  else
4823
4823
  return !1;
4824
- for (; _ < m.length && m[_] === "*"; )
4825
- _++;
4826
- return _ === m.length;
4824
+ for (; v < m.length && m[v] === "*"; )
4825
+ v++;
4826
+ return v === m.length;
4827
4827
  }
4828
4828
  function a() {
4829
4829
  const d = [
@@ -5136,27 +5136,27 @@ async function vi({ runContext: n }) {
5136
5136
  function kc(n, e) {
5137
5137
  return `An error occurred while running the tool. Please try again. Error: ${e instanceof Error ? e.toString() : String(e)}`;
5138
5138
  }
5139
- function Gt(n) {
5139
+ function wt(n) {
5140
5140
  const e = n.name ? vs(n.name) : vs(n.execute.name), t = typeof n.errorFunction > "u" ? kc : n.errorFunction;
5141
5141
  if (!e)
5142
5142
  throw new Error("Tool name cannot be empty. Either name your function or provide a name in the options.");
5143
5143
  const s = n.strict ?? !0;
5144
- if (!s && jt(n.parameters))
5144
+ if (!s && Ut(n.parameters))
5145
5145
  throw new ne("Strict mode is required for Zod parameters");
5146
5146
  const { parser: r, schema: i } = xr(n.parameters, e);
5147
5147
  async function o(p, d, m) {
5148
- const [g, _] = await Ir(() => r(d));
5148
+ const [g, v] = await Ir(() => r(d));
5149
5149
  if (g !== null)
5150
5150
  throw F.dontLogToolData ? F.debug(`Invalid JSON input for tool ${e}`) : F.debug(`Invalid JSON input for tool ${e}: ${d}`), new we("Invalid JSON input for tool");
5151
5151
  F.dontLogToolData ? F.debug(`Invoking tool ${e}`) : F.debug(`Invoking tool ${e} with input ${d}`);
5152
- const T = await n.execute(_, p, m), y = ht(T);
5153
- return F.dontLogToolData ? F.debug(`Tool ${e} completed`) : F.debug(`Tool ${e} returned: ${y}`), T;
5152
+ const S = await n.execute(v, p, m), y = ht(S);
5153
+ return F.dontLogToolData ? F.debug(`Tool ${e} completed`) : F.debug(`Tool ${e} returned: ${y}`), S;
5154
5154
  }
5155
5155
  async function a(p, d, m) {
5156
5156
  return o(p, d, m).catch((g) => {
5157
5157
  if (t) {
5158
- const _ = An();
5159
- return _ == null || _.setError({
5158
+ const v = An();
5159
+ return v == null || v.setError({
5160
5160
  message: "Error running tool (non-fatal)",
5161
5161
  data: {
5162
5162
  tool_name: e,
@@ -5189,7 +5189,7 @@ b({
5189
5189
  type: I("object"),
5190
5190
  properties: se(f(), W()),
5191
5191
  required: J(f()),
5192
- additionalProperties: Pt()
5192
+ additionalProperties: Dt()
5193
5193
  })
5194
5194
  });
5195
5195
  const Ls = {}, zs = {}, Ac = ({ server: n, agent: e }) => n.toolFilter && typeof n.toolFilter == "function" && e ? `${n.name}:${e.name}` : n.name;
@@ -5207,17 +5207,17 @@ async function Cc({ server: n, convertSchemasToStrict: e, runContext: t, agent:
5207
5207
  if (t && s) {
5208
5208
  const d = { runContext: t, agent: s, serverName: n.name }, m = [];
5209
5209
  for (const g of u) {
5210
- const _ = n.toolFilter;
5211
- if (_)
5212
- if (typeof _ == "function") {
5213
- if (!await _(d, g)) {
5210
+ const v = n.toolFilter;
5211
+ if (v)
5212
+ if (typeof v == "function") {
5213
+ if (!await v(d, g)) {
5214
5214
  F.debug(`MCP Tool (server: ${n.name}, tool: ${g.name}) is blocked by the callable filter.`);
5215
5215
  continue;
5216
5216
  }
5217
5217
  } else {
5218
- const T = _.allowedToolNames ?? [], y = _.blockedToolNames ?? [];
5219
- if (T.length > 0 || y.length > 0) {
5220
- const h = T.length > 0 ? T.includes(g.name) : !0, w = y.length > 0 ? y.includes(g.name) : !1;
5218
+ const S = v.allowedToolNames ?? [], y = v.blockedToolNames ?? [];
5219
+ if (S.length > 0 || y.length > 0) {
5220
+ const h = S.length > 0 ? S.includes(g.name) : !0, w = y.length > 0 ? y.includes(g.name) : !1;
5221
5221
  if (!h || w) {
5222
5222
  w ? F.debug(`MCP Tool (server: ${n.name}, tool: ${g.name}) is blocked by the static filter.`) : h || F.debug(`MCP Tool (server: ${n.name}, tool: ${g.name}) is not allowed by the static filter.`);
5223
5223
  continue;
@@ -5250,9 +5250,9 @@ async function Oc(n, e, t, s = !1) {
5250
5250
  runContext: a,
5251
5251
  agent: u,
5252
5252
  generateMCPToolCacheKey: l
5253
- }), T = [...new Set(g.map((y) => y.name))].filter((y) => d.has(y));
5254
- if (T.length > 0)
5255
- throw new ne(`Duplicate tool names found across MCP servers: ${T.join(", ")}`);
5253
+ }), S = [...new Set(g.map((y) => y.name))].filter((y) => d.has(y));
5254
+ if (S.length > 0)
5255
+ throw new ne(`Duplicate tool names found across MCP servers: ${S.join(", ")}`);
5256
5256
  for (const y of g)
5257
5257
  d.add(y.name), p.push(y);
5258
5258
  }
@@ -5265,8 +5265,8 @@ function bi(n, e, t) {
5265
5265
  typeof p == "string" && p ? m = JSON.parse(p) : typeof p == "object" && p != null && (m = p);
5266
5266
  const g = An();
5267
5267
  g && (g.spanData.mcp_data = { server: e.name });
5268
- const _ = await e.callTool(n.name, m);
5269
- return _.length === 1 ? _[0] : _;
5268
+ const v = await e.callTool(n.name, m);
5269
+ return v.length === 1 ? v[0] : v;
5270
5270
  }
5271
5271
  const r = {
5272
5272
  ...n.inputSchema,
@@ -5278,7 +5278,7 @@ function bi(n, e, t) {
5278
5278
  if (t || r.additionalProperties === !0)
5279
5279
  try {
5280
5280
  const p = Ec(r);
5281
- return Gt({
5281
+ return wt({
5282
5282
  name: n.name,
5283
5283
  description: n.description || "",
5284
5284
  parameters: p,
@@ -5292,7 +5292,7 @@ function bi(n, e, t) {
5292
5292
  ...r,
5293
5293
  additionalProperties: !0
5294
5294
  };
5295
- return Gt({
5295
+ return wt({
5296
5296
  name: n.name,
5297
5297
  description: n.description || "",
5298
5298
  parameters: i,
@@ -5310,27 +5310,27 @@ function Ec(n) {
5310
5310
  function Rc() {
5311
5311
  return {};
5312
5312
  }
5313
- var Ht, It;
5313
+ var Ht, St;
5314
5314
  class Cs {
5315
5315
  constructor() {
5316
- R(this, Ht, new EventTarget());
5317
- R(this, It, /* @__PURE__ */ new Map());
5316
+ N(this, Ht, new EventTarget());
5317
+ N(this, St, /* @__PURE__ */ new Map());
5318
5318
  }
5319
5319
  on(e, t) {
5320
5320
  const s = e;
5321
- let r = c(this, It).get(s);
5322
- r || (r = /* @__PURE__ */ new Map(), c(this, It).set(s, r));
5321
+ let r = c(this, St).get(s);
5322
+ r || (r = /* @__PURE__ */ new Map(), c(this, St).set(s, r));
5323
5323
  let i = r.get(t);
5324
5324
  i || (i = /* @__PURE__ */ new Set(), r.set(t, i));
5325
5325
  const o = (a) => t(...a.detail ?? []);
5326
5326
  return i.add(o), c(this, Ht).addEventListener(s, o), this;
5327
5327
  }
5328
5328
  off(e, t) {
5329
- const s = e, r = c(this, It).get(s), i = r == null ? void 0 : r.get(t);
5329
+ const s = e, r = c(this, St).get(s), i = r == null ? void 0 : r.get(t);
5330
5330
  if (i != null && i.size) {
5331
5331
  for (const o of i)
5332
5332
  c(this, Ht).removeEventListener(s, o);
5333
- r == null || r.delete(t), (r == null ? void 0 : r.size) === 0 && c(this, It).delete(s);
5333
+ r == null || r.delete(t), (r == null ? void 0 : r.size) === 0 && c(this, St).delete(s);
5334
5334
  }
5335
5335
  return this;
5336
5336
  }
@@ -5345,7 +5345,7 @@ class Cs {
5345
5345
  return this.on(e, s), this;
5346
5346
  }
5347
5347
  }
5348
- Ht = new WeakMap(), It = new WeakMap();
5348
+ Ht = new WeakMap(), St = new WeakMap();
5349
5349
  const ka = () => typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID() : "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(n) {
5350
5350
  const e = Math.random() * 16 | 0;
5351
5351
  return (n === "x" ? e : e & 3 | 8).toString(16);
@@ -5359,7 +5359,7 @@ const ka = () => typeof crypto < "u" && crypto.randomUUID ? crypto.randomUUID()
5359
5359
  }, Pc = globalThis.ReadableStream, Dc = globalThis.TransformStream;
5360
5360
  class Mc {
5361
5361
  constructor() {
5362
- S(this, "context", null);
5362
+ x(this, "context", null);
5363
5363
  }
5364
5364
  run(e, t) {
5365
5365
  return this.context = e, t();
@@ -5400,13 +5400,13 @@ class Ar {
5400
5400
  class jc extends Ar {
5401
5401
  constructor() {
5402
5402
  super(...arguments);
5403
- S(this, "eventEmitter", new Cs());
5403
+ x(this, "eventEmitter", new Cs());
5404
5404
  }
5405
5405
  }
5406
5406
  class Uc extends Ar {
5407
5407
  constructor() {
5408
5408
  super(...arguments);
5409
- S(this, "eventEmitter", new Cs());
5409
+ x(this, "eventEmitter", new Cs());
5410
5410
  }
5411
5411
  }
5412
5412
  const Lc = "OPENAI_DEFAULT_MODEL";
@@ -5444,15 +5444,15 @@ class Ea {
5444
5444
  /**
5445
5445
  * The name of the tool that represents the handoff.
5446
5446
  */
5447
- S(this, "toolName");
5447
+ x(this, "toolName");
5448
5448
  /**
5449
5449
  * The description of the tool that represents the handoff.
5450
5450
  */
5451
- S(this, "toolDescription");
5451
+ x(this, "toolDescription");
5452
5452
  /**
5453
5453
  * The JSON schema for the handoff input. Can be empty if the handoff does not take an input
5454
5454
  */
5455
- S(this, "inputJsonSchema", {
5455
+ x(this, "inputJsonSchema", {
5456
5456
  type: "object",
5457
5457
  properties: {},
5458
5458
  required: [],
@@ -5462,7 +5462,7 @@ class Ea {
5462
5462
  * Whether the input JSON schema is in strict mode. We **strongly** recommend setting this to
5463
5463
  * true, as it increases the likelihood of correct JSON input.
5464
5464
  */
5465
- S(this, "strictJsonSchema", !0);
5465
+ x(this, "strictJsonSchema", !0);
5466
5466
  /**
5467
5467
  * The function that invokes the handoff. The parameters passed are:
5468
5468
  * 1. The handoff run context
@@ -5470,11 +5470,11 @@ class Ea {
5470
5470
  *
5471
5471
  * Must return an agent
5472
5472
  */
5473
- S(this, "onInvokeHandoff");
5473
+ x(this, "onInvokeHandoff");
5474
5474
  /**
5475
5475
  * The name of the agent that is being handed off to.
5476
5476
  */
5477
- S(this, "agentName");
5477
+ x(this, "agentName");
5478
5478
  /**
5479
5479
  * A function that filters the inputs that are passed to the next agent. By default, the new agent
5480
5480
  * sees the entire conversation history. In some cases, you may want to filter inputs e.g. to
@@ -5486,12 +5486,12 @@ class Ea {
5486
5486
  * You are free to modify the input history or new items as you see fit. The next agent that runs
5487
5487
  * will receive `handoffInputData.allItems
5488
5488
  */
5489
- S(this, "inputFilter");
5489
+ x(this, "inputFilter");
5490
5490
  /**
5491
5491
  * The agent that is being handed off to.
5492
5492
  */
5493
- S(this, "agent");
5494
- S(this, "isEnabled", async () => !0);
5493
+ x(this, "agent");
5494
+ x(this, "isEnabled", async () => !0);
5495
5495
  this.agentName = e.name, this.onInvokeHandoff = t, this.toolName = Bc(e), this.toolDescription = Zc(e), this.agent = e;
5496
5496
  }
5497
5497
  /**
@@ -5567,27 +5567,27 @@ function Vc(n) {
5567
5567
  const e = ar.get(n);
5568
5568
  return e && ar.delete(n), e;
5569
5569
  }
5570
- const Hc = b({ input: f() }), Jt = class Jt extends jc {
5570
+ const Hc = b({ input: f() }), Gt = class Gt extends jc {
5571
5571
  constructor(t) {
5572
5572
  super();
5573
- S(this, "name");
5574
- S(this, "instructions");
5575
- S(this, "prompt");
5576
- S(this, "handoffDescription");
5577
- S(this, "handoffs");
5578
- S(this, "model");
5579
- S(this, "modelSettings");
5580
- S(this, "tools");
5581
- S(this, "mcpServers");
5582
- S(this, "inputGuardrails");
5583
- S(this, "outputGuardrails");
5584
- S(this, "outputType", "text");
5585
- S(this, "toolUseBehavior");
5586
- S(this, "resetToolChoice");
5587
- S(this, "_toolsExplicitlyConfigured");
5573
+ x(this, "name");
5574
+ x(this, "instructions");
5575
+ x(this, "prompt");
5576
+ x(this, "handoffDescription");
5577
+ x(this, "handoffs");
5578
+ x(this, "model");
5579
+ x(this, "modelSettings");
5580
+ x(this, "tools");
5581
+ x(this, "mcpServers");
5582
+ x(this, "inputGuardrails");
5583
+ x(this, "outputGuardrails");
5584
+ x(this, "outputType", "text");
5585
+ x(this, "toolUseBehavior");
5586
+ x(this, "resetToolChoice");
5587
+ x(this, "_toolsExplicitlyConfigured");
5588
5588
  if (typeof t.name != "string" || t.name.trim() === "")
5589
5589
  throw new ne("Agent must have a name.");
5590
- if (this.name = t.name, this.instructions = t.instructions ?? Jt.DEFAULT_MODEL_PLACEHOLDER, this.prompt = t.prompt, this.handoffDescription = t.handoffDescription ?? "", this.handoffs = t.handoffs ?? [], this.model = t.model ?? "", this.modelSettings = t.modelSettings ?? zc(), this.tools = t.tools ?? [], this._toolsExplicitlyConfigured = t.tools !== void 0, this.mcpServers = t.mcpServers ?? [], this.inputGuardrails = t.inputGuardrails ?? [], this.outputGuardrails = t.outputGuardrails ?? [], t.outputType && (this.outputType = t.outputType), this.toolUseBehavior = t.toolUseBehavior ?? "run_llm_again", this.resetToolChoice = t.resetToolChoice ?? !0, // The user sets a non-default model
5590
+ if (this.name = t.name, this.instructions = t.instructions ?? Gt.DEFAULT_MODEL_PLACEHOLDER, this.prompt = t.prompt, this.handoffDescription = t.handoffDescription ?? "", this.handoffs = t.handoffs ?? [], this.model = t.model ?? "", this.modelSettings = t.modelSettings ?? zc(), this.tools = t.tools ?? [], this._toolsExplicitlyConfigured = t.tools !== void 0, this.mcpServers = t.mcpServers ?? [], this.inputGuardrails = t.inputGuardrails ?? [], this.outputGuardrails = t.outputGuardrails ?? [], t.outputType && (this.outputType = t.outputType), this.toolUseBehavior = t.toolUseBehavior ?? "run_llm_again", this.resetToolChoice = t.resetToolChoice ?? !0, // The user sets a non-default model
5591
5591
  t.model !== void 0 && // The default model is gpt-5
5592
5592
  Aa() && // However, the specified model is not a gpt-5 model
5593
5593
  (typeof t.model != "string" || !Os(t.model)) && // The model settings are not customized for the specified model
@@ -5602,7 +5602,7 @@ const Hc = b({ input: f() }), Jt = class Jt extends jc {
5602
5602
  * Create an Agent with handoffs and automatically infer the union type for TOutput from the handoff agents' output types.
5603
5603
  */
5604
5604
  static create(t) {
5605
- return new Jt({
5605
+ return new Gt({
5606
5606
  ...t,
5607
5607
  handoffs: t.handoffs,
5608
5608
  outputType: t.outputType,
@@ -5615,7 +5615,7 @@ const Hc = b({ input: f() }), Jt = class Jt extends jc {
5615
5615
  get outputSchemaName() {
5616
5616
  if (this.outputType === "text")
5617
5617
  return "text";
5618
- if (jt(this.outputType))
5618
+ if (Ut(this.outputType))
5619
5619
  return "ZodOutput";
5620
5620
  if (typeof this.outputType == "object")
5621
5621
  return this.outputType.name;
@@ -5632,7 +5632,7 @@ const Hc = b({ input: f() }), Jt = class Jt extends jc {
5632
5632
  * @returns A new agent with the given changes.
5633
5633
  */
5634
5634
  clone(t) {
5635
- return new Jt({
5635
+ return new Gt({
5636
5636
  ...this,
5637
5637
  ...t
5638
5638
  });
@@ -5650,56 +5650,56 @@ const Hc = b({ input: f() }), Jt = class Jt extends jc {
5650
5650
  * @returns A tool that runs the agent and returns the output text.
5651
5651
  */
5652
5652
  asTool(t) {
5653
- const { toolName: s, toolDescription: r, customOutputExtractor: i, needsApproval: o, runConfig: a, runOptions: u, isEnabled: l, onStream: p } = t, d = /* @__PURE__ */ new Map(), m = async (T) => {
5654
- const y = d.get(T.event.type), h = d.get("*"), w = [
5653
+ const { toolName: s, toolDescription: r, customOutputExtractor: i, needsApproval: o, runConfig: a, runOptions: u, isEnabled: l, onStream: p } = t, d = /* @__PURE__ */ new Map(), m = async (S) => {
5654
+ const y = d.get(S.event.type), h = d.get("*"), w = [
5655
5655
  ...p ? [p] : [],
5656
5656
  ...y ? Array.from(y) : [],
5657
5657
  ...h ? Array.from(h) : []
5658
5658
  ];
5659
- await Promise.allSettled(w.map((v) => Promise.resolve().then(() => v(T))));
5660
- }, _ = {
5661
- ...Gt({
5659
+ await Promise.allSettled(w.map((_) => Promise.resolve().then(() => _(S))));
5660
+ }, v = {
5661
+ ...wt({
5662
5662
  name: s ?? vs(this.name),
5663
5663
  description: r ?? "",
5664
5664
  parameters: Hc,
5665
5665
  strict: !0,
5666
5666
  needsApproval: o,
5667
5667
  isEnabled: l,
5668
- execute: async (T, y, h) => {
5669
- if (!Ku(T))
5668
+ execute: async (S, y, h) => {
5669
+ if (!Ku(S))
5670
5670
  throw new we("Agent tool called with invalid input");
5671
- const w = new xd(a ?? {}), v = typeof p == "function" || d.size > 0, N = v ? await w.run(this, T.input, {
5671
+ const w = new xd(a ?? {}), _ = typeof p == "function" || d.size > 0, R = _ ? await w.run(this, S.input, {
5672
5672
  context: y,
5673
5673
  ...u ?? {},
5674
5674
  stream: !0
5675
- }) : await w.run(this, T.input, {
5675
+ }) : await w.run(this, S.input, {
5676
5676
  context: y,
5677
5677
  ...u ?? {}
5678
- }), x = {
5678
+ }), T = {
5679
5679
  agent: this,
5680
5680
  toolCall: h == null ? void 0 : h.toolCall
5681
5681
  };
5682
- if (v) {
5683
- const G = N;
5682
+ if (_) {
5683
+ const G = R;
5684
5684
  for await (const L of G)
5685
5685
  await m({
5686
5686
  event: L,
5687
- ...x
5687
+ ...T
5688
5688
  });
5689
5689
  await G.completed;
5690
5690
  }
5691
- const A = N, D = typeof this.toolUseBehavior == "object" && this.toolUseBehavior !== null && "stopAtToolNames" in this.toolUseBehavior;
5691
+ const A = R, D = typeof this.toolUseBehavior == "object" && this.toolUseBehavior !== null && "stopAtToolNames" in this.toolUseBehavior;
5692
5692
  typeof i != "function" && D && F.debug(`You're passing the agent (name: ${this.name}) with toolUseBehavior.stopAtToolNames configured as a tool to a different agent; this may not work as you expect. You may want to have a wrapper function tool to consistently return the final output.`);
5693
5693
  const U = typeof i == "function" ? await i(A) : Jc(A.rawResponses[A.rawResponses.length - 1]);
5694
5694
  return h != null && h.toolCall && Gc(h.toolCall, A), U;
5695
5695
  }
5696
5696
  }),
5697
- on: (T, y) => {
5698
- const h = d.get(T) ?? /* @__PURE__ */ new Set();
5699
- return h.add(y), d.set(T, h), _;
5697
+ on: (S, y) => {
5698
+ const h = d.get(S) ?? /* @__PURE__ */ new Set();
5699
+ return h.add(y), d.set(S, h), v;
5700
5700
  }
5701
5701
  };
5702
- return _;
5702
+ return v;
5703
5703
  }
5704
5704
  /**
5705
5705
  * Returns the system prompt for the agent.
@@ -5774,7 +5774,7 @@ const Hc = b({ input: f() }), Jt = class Jt extends jc {
5774
5774
  return t;
5775
5775
  if (typeof this.outputType == "object") {
5776
5776
  const s = JSON.parse(t);
5777
- return jt(this.outputType) ? this.outputType.parse(s) : s;
5777
+ return Ut(this.outputType) ? this.outputType.parse(s) : s;
5778
5778
  }
5779
5779
  throw new Error(`Unknown output type: ${this.outputType}`);
5780
5780
  }
@@ -5789,8 +5789,8 @@ const Hc = b({ input: f() }), Jt = class Jt extends jc {
5789
5789
  };
5790
5790
  }
5791
5791
  };
5792
- S(Jt, "DEFAULT_MODEL_PLACEHOLDER", "");
5793
- let st = Jt;
5792
+ x(Gt, "DEFAULT_MODEL_PLACEHOLDER", "");
5793
+ let st = Gt;
5794
5794
  function wi({ name: n, execute: e, runInParallel: t = !0 }) {
5795
5795
  return {
5796
5796
  type: "input",
@@ -6312,27 +6312,27 @@ class mn {
6312
6312
  /**
6313
6313
  * The number of input tokens used for this request.
6314
6314
  */
6315
- S(this, "inputTokens");
6315
+ x(this, "inputTokens");
6316
6316
  /**
6317
6317
  * The number of output tokens used for this request.
6318
6318
  */
6319
- S(this, "outputTokens");
6319
+ x(this, "outputTokens");
6320
6320
  /**
6321
6321
  * The total number of tokens sent and received for this request.
6322
6322
  */
6323
- S(this, "totalTokens");
6323
+ x(this, "totalTokens");
6324
6324
  /**
6325
6325
  * Details about the input tokens used for this request.
6326
6326
  */
6327
- S(this, "inputTokensDetails");
6327
+ x(this, "inputTokensDetails");
6328
6328
  /**
6329
6329
  * Details about the output tokens used for this request.
6330
6330
  */
6331
- S(this, "outputTokensDetails");
6331
+ x(this, "outputTokensDetails");
6332
6332
  /**
6333
6333
  * The endpoint that produced this usage entry (e.g., responses.create, responses.compact).
6334
6334
  */
6335
- S(this, "endpoint");
6335
+ x(this, "endpoint");
6336
6336
  this.inputTokens = (e == null ? void 0 : e.inputTokens) ?? (e == null ? void 0 : e.input_tokens) ?? 0, this.outputTokens = (e == null ? void 0 : e.outputTokens) ?? (e == null ? void 0 : e.output_tokens) ?? 0, this.totalTokens = (e == null ? void 0 : e.totalTokens) ?? (e == null ? void 0 : e.total_tokens) ?? this.inputTokens + this.outputTokens;
6337
6337
  const t = (e == null ? void 0 : e.inputTokensDetails) ?? (e == null ? void 0 : e.input_tokens_details);
6338
6338
  this.inputTokensDetails = t || {};
@@ -6345,31 +6345,31 @@ class Qn {
6345
6345
  /**
6346
6346
  * The number of requests made to the LLM API.
6347
6347
  */
6348
- S(this, "requests");
6348
+ x(this, "requests");
6349
6349
  /**
6350
6350
  * The number of input tokens used across all requests.
6351
6351
  */
6352
- S(this, "inputTokens");
6352
+ x(this, "inputTokens");
6353
6353
  /**
6354
6354
  * The number of output tokens used across all requests.
6355
6355
  */
6356
- S(this, "outputTokens");
6356
+ x(this, "outputTokens");
6357
6357
  /**
6358
6358
  * The total number of tokens sent and received, across all requests.
6359
6359
  */
6360
- S(this, "totalTokens");
6360
+ x(this, "totalTokens");
6361
6361
  /**
6362
6362
  * Details about the input tokens used across all requests.
6363
6363
  */
6364
- S(this, "inputTokensDetails", []);
6364
+ x(this, "inputTokensDetails", []);
6365
6365
  /**
6366
6366
  * Details about the output tokens used across all requests.
6367
6367
  */
6368
- S(this, "outputTokensDetails", []);
6368
+ x(this, "outputTokensDetails", []);
6369
6369
  /**
6370
6370
  * List of per-request usage entries for detailed cost calculations.
6371
6371
  */
6372
- S(this, "requestUsageEntries");
6372
+ x(this, "requestUsageEntries");
6373
6373
  if (typeof e > "u")
6374
6374
  this.requests = 0, this.inputTokens = 0, this.outputTokens = 0, this.totalTokens = 0, this.inputTokensDetails = [], this.outputTokensDetails = [], this.requestUsageEntries = void 0;
6375
6375
  else {
@@ -6394,20 +6394,20 @@ class Qn {
6394
6394
  }
6395
6395
  }
6396
6396
  var Se;
6397
- class Zt {
6397
+ class qt {
6398
6398
  constructor(e = {}) {
6399
6399
  /**
6400
6400
  * The context object you passed to the `Runner.run()` method.
6401
6401
  */
6402
- S(this, "context");
6402
+ x(this, "context");
6403
6403
  /**
6404
6404
  * The usage of the agent run so far. For streamed responses, the usage will be updated in real-time
6405
6405
  */
6406
- S(this, "usage");
6406
+ x(this, "usage");
6407
6407
  /**
6408
6408
  * A map of tool names to whether they have been approved.
6409
6409
  */
6410
- R(this, Se);
6410
+ N(this, Se);
6411
6411
  this.context = e, this.usage = new Qn(), k(this, Se, /* @__PURE__ */ new Map());
6412
6412
  }
6413
6413
  /**
@@ -6541,10 +6541,10 @@ function Dl(n) {
6541
6541
  strictJsonSchema: n.strictJsonSchema
6542
6542
  };
6543
6543
  }
6544
- class Lt {
6544
+ class zt {
6545
6545
  constructor() {
6546
- S(this, "type", "base_item");
6547
- S(this, "rawItem");
6546
+ x(this, "type", "base_item");
6547
+ x(this, "rawItem");
6548
6548
  }
6549
6549
  toJSON() {
6550
6550
  return {
@@ -6553,12 +6553,12 @@ class Lt {
6553
6553
  };
6554
6554
  }
6555
6555
  }
6556
- class Ps extends Lt {
6556
+ class Ps extends zt {
6557
6557
  constructor(t, s) {
6558
6558
  super();
6559
- S(this, "rawItem");
6560
- S(this, "agent");
6561
- S(this, "type", "message_output_item");
6559
+ x(this, "rawItem");
6560
+ x(this, "agent");
6561
+ x(this, "type", "message_output_item");
6562
6562
  this.rawItem = t, this.agent = s;
6563
6563
  }
6564
6564
  toJSON() {
@@ -6574,12 +6574,12 @@ class Ps extends Lt {
6574
6574
  return t;
6575
6575
  }
6576
6576
  }
6577
- class Xe extends Lt {
6577
+ class Xe extends zt {
6578
6578
  constructor(t, s) {
6579
6579
  super();
6580
- S(this, "rawItem");
6581
- S(this, "agent");
6582
- S(this, "type", "tool_call_item");
6580
+ x(this, "rawItem");
6581
+ x(this, "agent");
6582
+ x(this, "type", "tool_call_item");
6583
6583
  this.rawItem = t, this.agent = s;
6584
6584
  }
6585
6585
  toJSON() {
@@ -6589,13 +6589,13 @@ class Xe extends Lt {
6589
6589
  };
6590
6590
  }
6591
6591
  }
6592
- class Be extends Lt {
6592
+ class Be extends zt {
6593
6593
  constructor(t, s, r) {
6594
6594
  super();
6595
- S(this, "rawItem");
6596
- S(this, "agent");
6597
- S(this, "output");
6598
- S(this, "type", "tool_call_output_item");
6595
+ x(this, "rawItem");
6596
+ x(this, "agent");
6597
+ x(this, "output");
6598
+ x(this, "type", "tool_call_output_item");
6599
6599
  this.rawItem = t, this.agent = s, this.output = r;
6600
6600
  }
6601
6601
  toJSON() {
@@ -6606,12 +6606,12 @@ class Be extends Lt {
6606
6606
  };
6607
6607
  }
6608
6608
  }
6609
- class Pr extends Lt {
6609
+ class Pr extends zt {
6610
6610
  constructor(t, s) {
6611
6611
  super();
6612
- S(this, "rawItem");
6613
- S(this, "agent");
6614
- S(this, "type", "reasoning_item");
6612
+ x(this, "rawItem");
6613
+ x(this, "agent");
6614
+ x(this, "type", "reasoning_item");
6615
6615
  this.rawItem = t, this.agent = s;
6616
6616
  }
6617
6617
  toJSON() {
@@ -6621,12 +6621,12 @@ class Pr extends Lt {
6621
6621
  };
6622
6622
  }
6623
6623
  }
6624
- class Dr extends Lt {
6624
+ class Dr extends zt {
6625
6625
  constructor(t, s) {
6626
6626
  super();
6627
- S(this, "rawItem");
6628
- S(this, "agent");
6629
- S(this, "type", "handoff_call_item");
6627
+ x(this, "rawItem");
6628
+ x(this, "agent");
6629
+ x(this, "type", "handoff_call_item");
6630
6630
  this.rawItem = t, this.agent = s;
6631
6631
  }
6632
6632
  toJSON() {
@@ -6636,13 +6636,13 @@ class Dr extends Lt {
6636
6636
  };
6637
6637
  }
6638
6638
  }
6639
- class Mr extends Lt {
6639
+ class Mr extends zt {
6640
6640
  constructor(t, s, r) {
6641
6641
  super();
6642
- S(this, "rawItem");
6643
- S(this, "sourceAgent");
6644
- S(this, "targetAgent");
6645
- S(this, "type", "handoff_output_item");
6642
+ x(this, "rawItem");
6643
+ x(this, "sourceAgent");
6644
+ x(this, "targetAgent");
6645
+ x(this, "type", "handoff_output_item");
6646
6646
  this.rawItem = t, this.sourceAgent = s, this.targetAgent = r;
6647
6647
  }
6648
6648
  toJSON() {
@@ -6653,13 +6653,13 @@ class Mr extends Lt {
6653
6653
  };
6654
6654
  }
6655
6655
  }
6656
- class _e extends Lt {
6656
+ class _e extends zt {
6657
6657
  constructor(t, s, r) {
6658
6658
  super();
6659
- S(this, "rawItem");
6660
- S(this, "agent");
6661
- S(this, "toolName");
6662
- S(this, "type", "tool_approval_item");
6659
+ x(this, "rawItem");
6660
+ x(this, "agent");
6661
+ x(this, "toolName");
6662
+ x(this, "type", "tool_approval_item");
6663
6663
  this.rawItem = t, this.agent = s, this.toolName = r, this.toolName = r ?? t.name;
6664
6664
  }
6665
6665
  /**
@@ -6775,11 +6775,11 @@ class Bl {
6775
6775
  * @param data The raw responses stream events from the LLM.
6776
6776
  */
6777
6777
  constructor(e) {
6778
- S(this, "data");
6778
+ x(this, "data");
6779
6779
  /**
6780
6780
  * The type of the event.
6781
6781
  */
6782
- S(this, "type", "raw_model_stream_event");
6782
+ x(this, "type", "raw_model_stream_event");
6783
6783
  this.data = e;
6784
6784
  }
6785
6785
  }
@@ -6789,9 +6789,9 @@ class Zl {
6789
6789
  * @param item The item that was created.
6790
6790
  */
6791
6791
  constructor(e, t) {
6792
- S(this, "name");
6793
- S(this, "item");
6794
- S(this, "type", "run_item_stream_event");
6792
+ x(this, "name");
6793
+ x(this, "item");
6794
+ x(this, "type", "run_item_stream_event");
6795
6795
  this.name = e, this.item = t;
6796
6796
  }
6797
6797
  }
@@ -6800,8 +6800,8 @@ class ql {
6800
6800
  * @param agent The new agent
6801
6801
  */
6802
6802
  constructor(e) {
6803
- S(this, "agent");
6804
- S(this, "type", "agent_updated_stream_event");
6803
+ x(this, "agent");
6804
+ x(this, "type", "agent_updated_stream_event");
6805
6805
  this.agent = e;
6806
6806
  }
6807
6807
  }
@@ -6860,18 +6860,18 @@ function xi(n, e = 160) {
6860
6860
  }
6861
6861
  function ki(n, e, t, s) {
6862
6862
  var w;
6863
- const r = [], i = [], o = [], a = [], u = [], l = [], p = [], d = [], m = new Map(s.map((v) => [v.toolName, v])), g = new Map(t.filter((v) => v.type === "function").map((v) => [v.name, v])), _ = t.find((v) => v.type === "computer"), T = t.find((v) => v.type === "shell"), y = t.find((v) => v.type === "apply_patch"), h = new Map(t.filter((v) => {
6864
- var N;
6865
- return v.type === "hosted_tool" && ((N = v.providerData) == null ? void 0 : N.type) === "mcp";
6866
- }).map((v) => v).map((v) => [v.providerData.server_label, v]));
6867
- for (const v of n.output) {
6868
- if (v.type === "message")
6869
- v.role === "assistant" && r.push(new Ps(v, e));
6870
- else if (v.type === "hosted_tool_call") {
6871
- r.push(new Xe(v, e));
6872
- const x = v.name;
6873
- if (d.push(x), ((w = v.providerData) == null ? void 0 : w.type) === "mcp_approval_request" || v.name === "mcp_approval_request") {
6874
- const A = v.providerData, D = A.server_label, U = h.get(D);
6863
+ const r = [], i = [], o = [], a = [], u = [], l = [], p = [], d = [], m = new Map(s.map((_) => [_.toolName, _])), g = new Map(t.filter((_) => _.type === "function").map((_) => [_.name, _])), v = t.find((_) => _.type === "computer"), S = t.find((_) => _.type === "shell"), y = t.find((_) => _.type === "apply_patch"), h = new Map(t.filter((_) => {
6864
+ var R;
6865
+ return _.type === "hosted_tool" && ((R = _.providerData) == null ? void 0 : R.type) === "mcp";
6866
+ }).map((_) => _).map((_) => [_.providerData.server_label, _]));
6867
+ for (const _ of n.output) {
6868
+ if (_.type === "message")
6869
+ _.role === "assistant" && r.push(new Ps(_, e));
6870
+ else if (_.type === "hosted_tool_call") {
6871
+ r.push(new Xe(_, e));
6872
+ const T = _.name;
6873
+ if (d.push(T), ((w = _.providerData) == null ? void 0 : w.type) === "mcp_approval_request" || _.name === "mcp_approval_request") {
6874
+ const A = _.providerData, D = A.server_label, U = h.get(D);
6875
6875
  if (typeof U > "u") {
6876
6876
  const L = `MCP server (${D}) not found in Agent (${e.name})`;
6877
6877
  throw Qe({
@@ -6892,10 +6892,10 @@ function ki(n, e, t, s) {
6892
6892
  mcpTool: U
6893
6893
  }), U.providerData.on_approval || r.push(G);
6894
6894
  }
6895
- } else if (v.type === "reasoning")
6896
- r.push(new Pr(v, e));
6897
- else if (v.type === "computer_call") {
6898
- if (r.push(new Xe(v, e)), d.push("computer_use"), !_)
6895
+ } else if (_.type === "reasoning")
6896
+ r.push(new Pr(_, e));
6897
+ else if (_.type === "computer_call") {
6898
+ if (r.push(new Xe(_, e)), d.push("computer_use"), !v)
6899
6899
  throw Qe({
6900
6900
  message: "Model produced computer action without a computer tool.",
6901
6901
  data: {
@@ -6903,11 +6903,11 @@ function ki(n, e, t, s) {
6903
6903
  }
6904
6904
  }), new we("Model produced computer action without a computer tool.");
6905
6905
  a.push({
6906
- toolCall: v,
6907
- computer: _
6906
+ toolCall: _,
6907
+ computer: v
6908
6908
  });
6909
- } else if (v.type === "shell_call") {
6910
- if (r.push(new Xe(v, e)), d.push("shell"), !T)
6909
+ } else if (_.type === "shell_call") {
6910
+ if (r.push(new Xe(_, e)), d.push("shell"), !S)
6911
6911
  throw Qe({
6912
6912
  message: "Model produced shell action without a shell tool.",
6913
6913
  data: {
@@ -6915,11 +6915,11 @@ function ki(n, e, t, s) {
6915
6915
  }
6916
6916
  }), new we("Model produced shell action without a shell tool.");
6917
6917
  u.push({
6918
- toolCall: v,
6919
- shell: T
6918
+ toolCall: _,
6919
+ shell: S
6920
6920
  });
6921
- } else if (v.type === "apply_patch_call") {
6922
- if (r.push(new Xe(v, e)), d.push("apply_patch"), !y)
6921
+ } else if (_.type === "apply_patch_call") {
6922
+ if (r.push(new Xe(_, e)), d.push("apply_patch"), !y)
6923
6923
  throw Qe({
6924
6924
  message: "Model produced apply_patch action without an apply_patch tool.",
6925
6925
  data: {
@@ -6927,32 +6927,32 @@ function ki(n, e, t, s) {
6927
6927
  }
6928
6928
  }), new we("Model produced apply_patch action without an apply_patch tool.");
6929
6929
  l.push({
6930
- toolCall: v,
6930
+ toolCall: _,
6931
6931
  applyPatch: y
6932
6932
  });
6933
6933
  }
6934
- if (v.type !== "function_call")
6934
+ if (_.type !== "function_call")
6935
6935
  continue;
6936
- d.push(v.name);
6937
- const N = m.get(v.name);
6938
- if (N)
6939
- r.push(new Dr(v, e)), i.push({
6940
- toolCall: v,
6941
- handoff: N
6936
+ d.push(_.name);
6937
+ const R = m.get(_.name);
6938
+ if (R)
6939
+ r.push(new Dr(_, e)), i.push({
6940
+ toolCall: _,
6941
+ handoff: R
6942
6942
  });
6943
6943
  else {
6944
- const x = g.get(v.name);
6945
- if (!x)
6944
+ const T = g.get(_.name);
6945
+ if (!T)
6946
6946
  throw Qe({
6947
- message: `Tool ${v.name} not found in agent ${e.name}.`,
6947
+ message: `Tool ${_.name} not found in agent ${e.name}.`,
6948
6948
  data: {
6949
- tool_name: v.name,
6949
+ tool_name: _.name,
6950
6950
  agent_name: e.name
6951
6951
  }
6952
- }), new we(`Tool ${v.name} not found in agent ${e.name}.`);
6953
- r.push(new Xe(v, e)), o.push({
6954
- toolCall: v,
6955
- tool: x
6952
+ }), new we(`Tool ${_.name} not found in agent ${e.name}.`);
6953
+ r.push(new Xe(_, e)), o.push({
6954
+ toolCall: _,
6955
+ tool: T
6956
6956
  });
6957
6957
  }
6958
6958
  }
@@ -6989,11 +6989,11 @@ const Hl = ye("type", [
6989
6989
  ]);
6990
6990
  class $e {
6991
6991
  constructor(e, t, s, r, i) {
6992
- S(this, "originalInput");
6993
- S(this, "modelResponse");
6994
- S(this, "preStepItems");
6995
- S(this, "newStepItems");
6996
- S(this, "nextStep");
6992
+ x(this, "originalInput");
6993
+ x(this, "modelResponse");
6994
+ x(this, "preStepItems");
6995
+ x(this, "newStepItems");
6996
+ x(this, "nextStep");
6997
6997
  this.originalInput = e, this.modelResponse = t, this.preStepItems = s, this.newStepItems = r, this.nextStep = i;
6998
6998
  }
6999
6999
  /**
@@ -7007,39 +7007,39 @@ function Wl(n, e, t) {
7007
7007
  return n.resetToolChoice && e.hasUsedTools(n) ? { ...t, toolChoice: void 0 } : t;
7008
7008
  }
7009
7009
  async function Ai(n, e, t, s, r, i, o) {
7010
- const a = t.filter((x) => x instanceof _e && "callId" in x.rawItem && x.rawItem.type === "function_call").map((x) => x.rawItem.callId), u = o.getInterruptions().filter(Gl);
7010
+ const a = t.filter((T) => T instanceof _e && "callId" in T.rawItem && T.rawItem.type === "function_call").map((T) => T.rawItem.callId), u = o.getInterruptions().filter(Gl);
7011
7011
  if (u.length > 0) {
7012
- const x = /* @__PURE__ */ new Set();
7012
+ const T = /* @__PURE__ */ new Set();
7013
7013
  for (const A of u) {
7014
7014
  const D = Ti(A);
7015
- D && x.add(D);
7015
+ D && T.add(D);
7016
7016
  }
7017
- if (x.size > 0) {
7017
+ if (T.size > 0) {
7018
7018
  let A = 0;
7019
7019
  for (let D = t.length - 1; D >= 0; D--) {
7020
7020
  const U = t[D];
7021
7021
  if (!(U instanceof _e))
7022
7022
  continue;
7023
7023
  const G = Ti(U);
7024
- if (G && x.has(G) && (A++, x.delete(G), x.size === 0))
7024
+ if (G && T.has(G) && (A++, T.delete(G), T.size === 0))
7025
7025
  break;
7026
7026
  }
7027
7027
  A > 0 && (o._currentTurnPersistedItemCount = Math.max(0, o._currentTurnPersistedItemCount - A));
7028
7028
  }
7029
7029
  }
7030
- const l = r.functions.filter((x) => a.includes(x.toolCall.callId)), p = await Ja(n, l, i, o), d = r.computerActions.length > 0 ? await Va(n, r.computerActions, i, o._context) : [], m = new Set(t), g = [], _ = /* @__PURE__ */ new Set(), T = (x) => {
7031
- m.has(x) || _.has(x) || (g.push(x), _.add(x));
7030
+ const l = r.functions.filter((T) => a.includes(T.toolCall.callId)), p = await Ja(n, l, i, o), d = r.computerActions.length > 0 ? await Va(n, r.computerActions, i, o._context) : [], m = new Set(t), g = [], v = /* @__PURE__ */ new Set(), S = (T) => {
7031
+ m.has(T) || v.has(T) || (g.push(T), v.add(T));
7032
7032
  };
7033
- for (const x of p)
7034
- T(x.runItem);
7035
- for (const x of d)
7036
- T(x);
7037
- const y = r.mcpApprovalRequests.filter((x) => {
7033
+ for (const T of p)
7034
+ S(T.runItem);
7035
+ for (const T of d)
7036
+ S(T);
7037
+ const y = r.mcpApprovalRequests.filter((T) => {
7038
7038
  var A;
7039
- return x.requestItem.type === "tool_approval_item" && x.requestItem.rawItem.type === "hosted_tool_call" && ((A = x.requestItem.rawItem.providerData) == null ? void 0 : A.type) === "mcp_approval_request";
7039
+ return T.requestItem.type === "tool_approval_item" && T.requestItem.rawItem.type === "hosted_tool_call" && ((A = T.requestItem.rawItem.providerData) == null ? void 0 : A.type) === "mcp_approval_request";
7040
7040
  }), h = /* @__PURE__ */ new Set(), w = /* @__PURE__ */ new Set();
7041
- for (const x of y) {
7042
- const A = x.requestItem.rawItem;
7041
+ for (const T of y) {
7042
+ const A = T.requestItem.rawItem;
7043
7043
  if (A.type !== "hosted_tool_call")
7044
7044
  continue;
7045
7045
  const D = A.id, U = o._context.isToolApproved({
@@ -7057,45 +7057,45 @@ async function Ai(n, e, t, s, r, i, o) {
7057
7057
  name: "mcp_approval_response",
7058
7058
  providerData: G
7059
7059
  }, n);
7060
- T(L);
7060
+ S(L);
7061
7061
  } else
7062
- h.add(x.requestItem), w.add(D), p.push({
7062
+ h.add(T.requestItem), w.add(D), p.push({
7063
7063
  type: "hosted_mcp_tool_approval",
7064
- tool: x.mcpTool,
7065
- runItem: x.requestItem
7066
- }), T(x.requestItem);
7064
+ tool: T.mcpTool,
7065
+ runItem: T.requestItem
7066
+ }), S(T.requestItem);
7067
7067
  }
7068
- const v = t.filter((x) => {
7068
+ const _ = t.filter((T) => {
7069
7069
  var A;
7070
- if (!(x instanceof _e))
7070
+ if (!(T instanceof _e))
7071
7071
  return !0;
7072
- if (x.rawItem.type === "hosted_tool_call" && ((A = x.rawItem.providerData) == null ? void 0 : A.type) === "mcp_approval_request") {
7073
- if (h.has(x))
7072
+ if (T.rawItem.type === "hosted_tool_call" && ((A = T.rawItem.providerData) == null ? void 0 : A.type) === "mcp_approval_request") {
7073
+ if (h.has(T))
7074
7074
  return !0;
7075
- const D = x.rawItem.id;
7075
+ const D = T.rawItem.id;
7076
7076
  return D ? w.has(D) : !1;
7077
7077
  }
7078
7078
  return !1;
7079
- }), N = await qa({
7079
+ }), R = await qa({
7080
7080
  agent: n,
7081
7081
  runner: i,
7082
7082
  state: o,
7083
7083
  functionResults: p,
7084
7084
  originalInput: e,
7085
7085
  newResponse: s,
7086
- preStepItems: v,
7086
+ preStepItems: _,
7087
7087
  newItems: g
7088
7088
  });
7089
- return N || new $e(e, s, v, g, { type: "next_step_run_again" });
7089
+ return R || new $e(e, s, _, g, { type: "next_step_run_again" });
7090
7090
  }
7091
7091
  async function Ci(n, e, t, s, r, i, o) {
7092
- var N, x, A, D, U, G;
7092
+ var R, T, A, D, U, G;
7093
7093
  const a = t, u = new Set(t), l = [], p = (L) => {
7094
7094
  u.has(L) || (l.push(L), u.add(L));
7095
7095
  };
7096
7096
  for (const L of r.newItems)
7097
7097
  p(L);
7098
- const [d, m, g, _] = await Promise.all([
7098
+ const [d, m, g, v] = await Promise.all([
7099
7099
  Ja(n, r.functions, i, o),
7100
7100
  Va(n, r.computerActions, i, o._context),
7101
7101
  ed(n, r.shellActions, i, o._context),
@@ -7107,7 +7107,7 @@ async function Ci(n, e, t, s, r, i, o) {
7107
7107
  p(L);
7108
7108
  for (const L of g)
7109
7109
  p(L);
7110
- for (const L of _)
7110
+ for (const L of v)
7111
7111
  p(L);
7112
7112
  if (r.mcpApprovalRequests.length > 0)
7113
7113
  for (const L of r.mcpApprovalRequests) {
@@ -7142,7 +7142,7 @@ async function Ci(n, e, t, s, r, i, o) {
7142
7142
  }
7143
7143
  if (r.handoffs.length > 0)
7144
7144
  return await nd(n, e, a, l, s, r.handoffs, i, o._context);
7145
- const T = await qa({
7145
+ const S = await qa({
7146
7146
  agent: n,
7147
7147
  runner: i,
7148
7148
  state: o,
@@ -7152,9 +7152,9 @@ async function Ci(n, e, t, s, r, i, o) {
7152
7152
  preStepItems: a,
7153
7153
  newItems: l
7154
7154
  });
7155
- if (T)
7156
- return T;
7157
- if ((((N = r.functions) == null ? void 0 : N.length) ?? 0) > 0 || (((x = r.computerActions) == null ? void 0 : x.length) ?? 0) > 0 || (((A = r.shellActions) == null ? void 0 : A.length) ?? 0) > 0 || (((D = r.applyPatchActions) == null ? void 0 : D.length) ?? 0) > 0 || (((U = r.mcpApprovalRequests) == null ? void 0 : U.length) ?? 0) > 0 || (((G = r.handoffs) == null ? void 0 : G.length) ?? 0) > 0)
7155
+ if (S)
7156
+ return S;
7157
+ if ((((R = r.functions) == null ? void 0 : R.length) ?? 0) > 0 || (((T = r.computerActions) == null ? void 0 : T.length) ?? 0) > 0 || (((A = r.shellActions) == null ? void 0 : A.length) ?? 0) > 0 || (((D = r.applyPatchActions) == null ? void 0 : D.length) ?? 0) > 0 || (((U = r.mcpApprovalRequests) == null ? void 0 : U.length) ?? 0) > 0 || (((G = r.handoffs) == null ? void 0 : G.length) ?? 0) > 0)
7158
7158
  return new $e(e, s, a, l, { type: "next_step_run_again" });
7159
7159
  const h = l.filter((L) => L instanceof Ps), w = h.length > 0 ? Na(h[h.length - 1].rawItem) : void 0;
7160
7160
  if (typeof w > "u")
@@ -7272,17 +7272,17 @@ function he(n) {
7272
7272
  }
7273
7273
  function ns(n, e) {
7274
7274
  if (typeof n == "string")
7275
- return e && !n.startsWith("data:") ? qt(n, e) : n;
7275
+ return e && !n.startsWith("data:") ? Jt(n, e) : n;
7276
7276
  const t = Ae(n);
7277
- return qt(t, e);
7277
+ return Jt(t, e);
7278
7278
  }
7279
- function qt(n, e) {
7279
+ function Jt(n, e) {
7280
7280
  return e ? `data:${e};base64,${n}` : n;
7281
7281
  }
7282
7282
  async function Ja(n, e, t, s) {
7283
7283
  async function r(i) {
7284
7284
  let o = i.toolCall.arguments;
7285
- if (i.tool.parameters && (jt(i.tool.parameters) ? o = i.tool.parameters.parse(o) : o = JSON.parse(o)), await i.tool.needsApproval(s._context, o, i.toolCall.callId)) {
7285
+ if (i.tool.parameters && (Ut(i.tool.parameters) ? o = i.tool.parameters.parse(o) : o = JSON.parse(o)), await i.tool.needsApproval(s._context, o, i.toolCall.callId)) {
7286
7286
  const u = s._context.isToolApproved({
7287
7287
  toolName: i.tool.name,
7288
7288
  callId: i.toolCall.callId
@@ -7444,10 +7444,10 @@ async function ed(n, e, t, s, r = void 0) {
7444
7444
  }), typeof n.emit == "function" && n.emit("agent_tool_start", s, u, { toolCall: l });
7445
7445
  let m;
7446
7446
  const g = {};
7447
- let _;
7447
+ let v;
7448
7448
  try {
7449
7449
  const y = await u.shell.run(l.action);
7450
- m = y.output ?? [], y.providerData && Object.assign(g, y.providerData), typeof y.maxOutputLength == "number" && (_ = y.maxOutputLength);
7450
+ m = y.output ?? [], y.providerData && Object.assign(g, y.providerData), typeof y.maxOutputLength == "number" && (v = y.maxOutputLength);
7451
7451
  } catch (y) {
7452
7452
  m = [
7453
7453
  {
@@ -7462,12 +7462,12 @@ async function ed(n, e, t, s, r = void 0) {
7462
7462
  }), typeof n.emit == "function" && n.emit("agent_tool_end", s, u, JSON.stringify(m), {
7463
7463
  toolCall: l
7464
7464
  });
7465
- const T = {
7465
+ const S = {
7466
7466
  type: "shell_call_output",
7467
7467
  callId: l.callId,
7468
7468
  output: m ?? []
7469
7469
  };
7470
- typeof _ == "number" && (T.maxOutputLength = _), Object.keys(g).length > 0 && (T.providerData = g), o.push(new Be(T, n, T.output));
7470
+ typeof v == "number" && (S.maxOutputLength = v), Object.keys(g).length > 0 && (S.providerData = g), o.push(new Be(S, n, S.output));
7471
7471
  }
7472
7472
  return o;
7473
7473
  }
@@ -7480,11 +7480,11 @@ async function td(n, e, t, s, r = void 0) {
7480
7480
  const y = await u.onApproval(s, p);
7481
7481
  y.approve === !0 ? s.approveTool(p) : y.approve === !1 && s.rejectTool(p);
7482
7482
  }
7483
- const T = s.isToolApproved({
7483
+ const S = s.isToolApproved({
7484
7484
  toolName: u.name,
7485
7485
  callId: l.callId
7486
7486
  });
7487
- if (T === !1) {
7487
+ if (S === !1) {
7488
7488
  const y = "Tool execution was not approved.";
7489
7489
  o.push(new Be({
7490
7490
  type: "apply_patch_call_output",
@@ -7494,7 +7494,7 @@ async function td(n, e, t, s, r = void 0) {
7494
7494
  }, n, y));
7495
7495
  continue;
7496
7496
  }
7497
- if (T !== !0) {
7497
+ if (S !== !0) {
7498
7498
  o.push(p);
7499
7499
  continue;
7500
7500
  }
@@ -7506,35 +7506,35 @@ async function td(n, e, t, s, r = void 0) {
7506
7506
  });
7507
7507
  let m = "completed", g = "";
7508
7508
  try {
7509
- let T;
7509
+ let S;
7510
7510
  switch (l.operation.type) {
7511
7511
  case "create_file":
7512
- T = await u.editor.createFile(l.operation);
7512
+ S = await u.editor.createFile(l.operation);
7513
7513
  break;
7514
7514
  case "update_file":
7515
- T = await u.editor.updateFile(l.operation);
7515
+ S = await u.editor.updateFile(l.operation);
7516
7516
  break;
7517
7517
  case "delete_file":
7518
- T = await u.editor.deleteFile(l.operation);
7518
+ S = await u.editor.deleteFile(l.operation);
7519
7519
  break;
7520
7520
  default:
7521
7521
  throw new Error("Unsupported apply_patch operation");
7522
7522
  }
7523
- T && typeof T.status == "string" && (m = T.status), T && typeof T.output == "string" && (g = T.output);
7524
- } catch (T) {
7525
- m = "failed", g = Ga(T), i.error("Failed to execute apply_patch operation:", T);
7523
+ S && typeof S.status == "string" && (m = S.status), S && typeof S.output == "string" && (g = S.output);
7524
+ } catch (S) {
7525
+ m = "failed", g = Ga(S), i.error("Failed to execute apply_patch operation:", S);
7526
7526
  }
7527
7527
  t.emit("agent_tool_end", s, n, u, g, {
7528
7528
  toolCall: l
7529
7529
  }), typeof n.emit == "function" && n.emit("agent_tool_end", s, u, g, {
7530
7530
  toolCall: l
7531
7531
  });
7532
- const _ = {
7532
+ const v = {
7533
7533
  type: "apply_patch_call_output",
7534
7534
  callId: l.callId,
7535
7535
  status: m
7536
7536
  };
7537
- g && (_.output = g), o.push(new Be(_, n, g));
7537
+ g && (v.output = g), o.push(new Be(v, n, g));
7538
7538
  }
7539
7539
  return o;
7540
7540
  }
@@ -7581,7 +7581,7 @@ async function nd(n, e, t, s, r, i, o, a) {
7581
7581
  return jl(async (l) => {
7582
7582
  const p = u.handoff, d = await p.onInvokeHandoff(a, u.toolCall.arguments);
7583
7583
  if (l.spanData.to_agent = d.name, i.length > 1) {
7584
- const g = i.map((_) => _.handoff.agentName);
7584
+ const g = i.map((v) => v.handoff.agentName);
7585
7585
  l.setError({
7586
7586
  message: "Multiple handoffs requested",
7587
7587
  data: {
@@ -7603,8 +7603,8 @@ async function nd(n, e, t, s, r, i, o, a) {
7603
7603
  preHandoffItems: [...t],
7604
7604
  newItems: [...s],
7605
7605
  runContext: a
7606
- }, _ = m(g);
7607
- e = _.inputHistory, t = _.preHandoffItems, s = _.newItems;
7606
+ }, v = m(g);
7607
+ e = v.inputHistory, t = v.preHandoffItems, s = v.newItems;
7608
7608
  }
7609
7609
  return new $e(e, r, t, s, { type: "next_step_handoff", newAgent: d });
7610
7610
  }, {
@@ -7694,7 +7694,7 @@ function Oi(n, e, t) {
7694
7694
  var Wt;
7695
7695
  class Ei {
7696
7696
  constructor() {
7697
- R(this, Wt, /* @__PURE__ */ new Map());
7697
+ N(this, Wt, /* @__PURE__ */ new Map());
7698
7698
  }
7699
7699
  addToolUse(e, t) {
7700
7700
  c(this, Wt).set(e, t);
@@ -7848,34 +7848,34 @@ async function pd(n, e, t, s) {
7848
7848
  const u = o.slice(), l = a.slice(), p = await t(o, a);
7849
7849
  if (!Array.isArray(p))
7850
7850
  throw new ne("Session input callback must return an array of AgentInputItem objects.");
7851
- const d = Pi(u), m = Pi(l), g = Di(u), _ = Di(l), T = [];
7851
+ const d = Pi(u), m = Pi(l), g = Di(u), v = Di(l), S = [];
7852
7852
  for (const h of p) {
7853
7853
  const w = $r(h);
7854
- if (Mi(_, w, h)) {
7855
- Fi(m, w), T.push(h);
7854
+ if (Mi(v, w, h)) {
7855
+ Fi(m, w), S.push(h);
7856
7856
  continue;
7857
7857
  }
7858
7858
  if (Mi(g, w, h)) {
7859
7859
  Fi(d, w);
7860
7860
  continue;
7861
7861
  }
7862
- const v = d.get(w) ?? 0;
7863
- if (v > 0) {
7864
- d.set(w, v - 1);
7862
+ const _ = d.get(w) ?? 0;
7863
+ if (_ > 0) {
7864
+ d.set(w, _ - 1);
7865
7865
  continue;
7866
7866
  }
7867
- const N = m.get(w) ?? 0;
7868
- if (N > 0) {
7869
- m.set(w, N - 1), T.push(h);
7867
+ const R = m.get(w) ?? 0;
7868
+ if (R > 0) {
7869
+ m.set(w, R - 1), S.push(h);
7870
7870
  continue;
7871
7871
  }
7872
- T.push(h);
7872
+ S.push(h);
7873
7873
  }
7874
7874
  return {
7875
- preparedInput: r ? p : T.length > 0 ? T : i ? l : [],
7875
+ preparedInput: r ? p : S.length > 0 ? S : i ? l : [],
7876
7876
  // Respect callbacks that intentionally drop the latest inputs (e.g. to redact sensitive
7877
7877
  // values) by persisting only the items they kept in the combined array.
7878
- sessionItems: T
7878
+ sessionItems: S
7879
7879
  };
7880
7880
  }
7881
7881
  function fd(n) {
@@ -7947,10 +7947,10 @@ function hd(n) {
7947
7947
  if (he(s.url))
7948
7948
  t.image = s.url;
7949
7949
  else if (he(s.data))
7950
- t.image = r && !s.data.startsWith("data:") ? qt(s.data, r) : s.data;
7950
+ t.image = r && !s.data.startsWith("data:") ? Jt(s.data, r) : s.data;
7951
7951
  else if (s.data instanceof Uint8Array && s.data.length > 0) {
7952
7952
  const i = Ae(s.data);
7953
- t.image = qt(i, r);
7953
+ t.image = Jt(i, r);
7954
7954
  } else {
7955
7955
  const i = he(s.fileId) && s.fileId || he(s.id) && s.id || void 0;
7956
7956
  i && (t.image = { id: i });
@@ -7967,10 +7967,10 @@ function hd(n) {
7967
7967
  if ("data" in r && r.data) {
7968
7968
  const i = r.mediaType ?? "text/plain";
7969
7969
  if (typeof r.data == "string")
7970
- t.file = qt(r.data, i);
7970
+ t.file = Jt(r.data, i);
7971
7971
  else {
7972
7972
  const o = Ae(r.data);
7973
- t.file = qt(o, i);
7973
+ t.file = Jt(o, i);
7974
7974
  }
7975
7975
  } else if (typeof r.url == "string" && r.url.length > 0)
7976
7976
  t.file = { url: r.url };
@@ -8164,7 +8164,7 @@ const is = "1.0", gd = I(is), Me = b({
8164
8164
  })
8165
8165
  })).optional()
8166
8166
  }), eo = b({
8167
- tripwireTriggered: Pt(),
8167
+ tripwireTriggered: Dt(),
8168
8168
  outputInfo: W()
8169
8169
  }), wd = b({
8170
8170
  guardrail: b({
@@ -8189,15 +8189,15 @@ const is = "1.0", gd = I(is), Me = b({
8189
8189
  context: b({
8190
8190
  usage: Xa,
8191
8191
  approvals: se(f(), b({
8192
- approved: J(f()).or(Pt()),
8193
- rejected: J(f()).or(Pt())
8192
+ approved: J(f()).or(Dt()),
8193
+ rejected: J(f()).or(Dt())
8194
8194
  })),
8195
8195
  context: se(f(), W())
8196
8196
  }),
8197
8197
  toolUseTracker: se(f(), J(f())),
8198
8198
  maxTurns: E(),
8199
8199
  currentAgentSpan: Ya.nullable().optional(),
8200
- noActiveAgentRun: Pt(),
8200
+ noActiveAgentRun: Dt(),
8201
8201
  inputGuardrailResults: J(wd),
8202
8202
  outputGuardrailResults: J(Id),
8203
8203
  currentStep: Hl.optional(),
@@ -8212,35 +8212,35 @@ class Ve {
8212
8212
  /**
8213
8213
  * Current turn number in the conversation.
8214
8214
  */
8215
- S(this, "_currentTurn", 0);
8215
+ x(this, "_currentTurn", 0);
8216
8216
  /**
8217
8217
  * The agent currently handling the conversation.
8218
8218
  */
8219
- S(this, "_currentAgent");
8219
+ x(this, "_currentAgent");
8220
8220
  /**
8221
8221
  * Original user input prior to any processing.
8222
8222
  */
8223
- S(this, "_originalInput");
8223
+ x(this, "_originalInput");
8224
8224
  /**
8225
8225
  * Responses from the model so far.
8226
8226
  */
8227
- S(this, "_modelResponses");
8227
+ x(this, "_modelResponses");
8228
8228
  /**
8229
8229
  * Active tracing span for the current agent if tracing is enabled.
8230
8230
  */
8231
- S(this, "_currentAgentSpan");
8231
+ x(this, "_currentAgentSpan");
8232
8232
  /**
8233
8233
  * Run context tracking approvals, usage, and other metadata.
8234
8234
  */
8235
- S(this, "_context");
8235
+ x(this, "_context");
8236
8236
  /**
8237
8237
  * Tracks what tools each agent has used.
8238
8238
  */
8239
- S(this, "_toolUseTracker");
8239
+ x(this, "_toolUseTracker");
8240
8240
  /**
8241
8241
  * Items generated by the agent during the run.
8242
8242
  */
8243
- S(this, "_generatedItems");
8243
+ x(this, "_generatedItems");
8244
8244
  /**
8245
8245
  * Number of `_generatedItems` already flushed to session storage for the current turn.
8246
8246
  *
@@ -8251,39 +8251,39 @@ class Ve {
8251
8251
  * approval) and later resumed, we rewind the counter before continuing so the pending tool
8252
8252
  * output still gets stored.
8253
8253
  */
8254
- S(this, "_currentTurnPersistedItemCount");
8254
+ x(this, "_currentTurnPersistedItemCount");
8255
8255
  /**
8256
8256
  * Maximum allowed turns before forcing termination.
8257
8257
  */
8258
- S(this, "_maxTurns");
8258
+ x(this, "_maxTurns");
8259
8259
  /**
8260
8260
  * Whether the run has an active agent step in progress.
8261
8261
  */
8262
- S(this, "_noActiveAgentRun", !0);
8262
+ x(this, "_noActiveAgentRun", !0);
8263
8263
  /**
8264
8264
  * Last model response for the previous turn.
8265
8265
  */
8266
- S(this, "_lastTurnResponse");
8266
+ x(this, "_lastTurnResponse");
8267
8267
  /**
8268
8268
  * Results from input guardrails applied to the run.
8269
8269
  */
8270
- S(this, "_inputGuardrailResults");
8270
+ x(this, "_inputGuardrailResults");
8271
8271
  /**
8272
8272
  * Results from output guardrails applied to the run.
8273
8273
  */
8274
- S(this, "_outputGuardrailResults");
8274
+ x(this, "_outputGuardrailResults");
8275
8275
  /**
8276
8276
  * Next step computed for the agent to take.
8277
8277
  */
8278
- S(this, "_currentStep");
8278
+ x(this, "_currentStep");
8279
8279
  /**
8280
8280
  * Parsed model response after applying guardrails and tools.
8281
8281
  */
8282
- S(this, "_lastProcessedResponse");
8282
+ x(this, "_lastProcessedResponse");
8283
8283
  /**
8284
8284
  * Trace associated with this run if tracing is enabled.
8285
8285
  */
8286
- S(this, "_trace", null);
8286
+ x(this, "_trace", null);
8287
8287
  this._context = e, this._originalInput = structuredClone(t), this._modelResponses = [], this._currentAgentSpan = void 0, this._currentAgent = s, this._toolUseTracker = new Ei(), this._generatedItems = [], this._currentTurnPersistedItemCount = 0, this._maxTurns = r, this._inputGuardrailResults = [], this._outputGuardrailResults = [], this._trace = dn();
8288
8288
  }
8289
8289
  /**
@@ -8416,7 +8416,7 @@ class Ve {
8416
8416
  * `toString` method.
8417
8417
  */
8418
8418
  static async fromString(e, t) {
8419
- var d, m, g, _, T;
8419
+ var d, m, g, v, S;
8420
8420
  const [s, r] = await Ir(() => JSON.parse(t));
8421
8421
  if (s)
8422
8422
  throw new ne(`Failed to parse run state. ${s instanceof Error ? s.message : String(s)}`);
@@ -8425,7 +8425,7 @@ class Ve {
8425
8425
  throw new ne("Run state is missing schema version");
8426
8426
  if (i !== is)
8427
8427
  throw new ne(`Run state schema version ${i} is not supported. Please use version ${is}`);
8428
- const o = ji.parse(JSON.parse(t)), a = Sd(e), u = new Zt(o.context.context);
8428
+ const o = ji.parse(JSON.parse(t)), a = Sd(e), u = new qt(o.context.context);
8429
8429
  u._rebuildApprovals(o.context.approvals);
8430
8430
  const l = a.get(o.currentAgent.name);
8431
8431
  if (!l)
@@ -8440,14 +8440,14 @@ class Ve {
8440
8440
  traceId: (d = o.trace) == null ? void 0 : d.id,
8441
8441
  name: (m = o.trace) == null ? void 0 : m.workflow_name,
8442
8442
  groupId: ((g = o.trace) == null ? void 0 : g.group_id) ?? void 0,
8443
- metadata: (_ = o.trace) == null ? void 0 : _.metadata
8443
+ metadata: (v = o.trace) == null ? void 0 : v.metadata
8444
8444
  });
8445
8445
  p._currentAgentSpan = to(y, o.currentAgentSpan), p._trace = y;
8446
8446
  }
8447
8447
  return p._noActiveAgentRun = o.noActiveAgentRun, p._inputGuardrailResults = o.inputGuardrailResults, p._outputGuardrailResults = o.outputGuardrailResults.map((y) => ({
8448
8448
  ...y,
8449
8449
  agent: a.get(y.agent.name)
8450
- })), p._currentStep = o.currentStep, p._originalInput = o.originalInput, p._modelResponses = o.modelResponses.map(Ui), p._lastTurnResponse = o.lastModelResponse ? Ui(o.lastModelResponse) : void 0, p._generatedItems = o.generatedItems.map((y) => no(y, a)), p._currentTurnPersistedItemCount = o.currentTurnPersistedItemCount ?? 0, p._lastProcessedResponse = o.lastProcessedResponse ? await Td(a, p._currentAgent, p._context, o.lastProcessedResponse) : void 0, ((T = o.currentStep) == null ? void 0 : T.type) === "next_step_handoff" && (p._currentStep = {
8450
+ })), p._currentStep = o.currentStep, p._originalInput = o.originalInput, p._modelResponses = o.modelResponses.map(Ui), p._lastTurnResponse = o.lastModelResponse ? Ui(o.lastModelResponse) : void 0, p._generatedItems = o.generatedItems.map((y) => no(y, a)), p._currentTurnPersistedItemCount = o.currentTurnPersistedItemCount ?? 0, p._lastProcessedResponse = o.lastProcessedResponse ? await Td(a, p._currentAgent, p._context, o.lastProcessedResponse) : void 0, ((S = o.currentStep) == null ? void 0 : S.type) === "next_step_handoff" && (p._currentStep = {
8451
8451
  type: "next_step_handoff",
8452
8452
  newAgent: a.get(o.currentStep.newAgent.name)
8453
8453
  }), p;
@@ -8570,13 +8570,13 @@ class xd extends Uc {
8570
8570
  */
8571
8571
  constructor(t = {}) {
8572
8572
  super();
8573
- R(this, ie);
8574
- S(this, "config");
8573
+ N(this, ie);
8574
+ x(this, "config");
8575
8575
  // --------------------------------------------------------------
8576
8576
  // Internals
8577
8577
  // --------------------------------------------------------------
8578
- S(this, "inputGuardrailDefs");
8579
- S(this, "outputGuardrailDefs");
8578
+ x(this, "inputGuardrailDefs");
8579
+ x(this, "outputGuardrailDefs");
8580
8580
  this.config = {
8581
8581
  modelProvider: t.modelProvider ?? Wc(),
8582
8582
  model: t.model,
@@ -8603,16 +8603,16 @@ class xd extends Uc {
8603
8603
  sessionInputCallback: o,
8604
8604
  callModelInputFilter: a
8605
8605
  }, p = !!l.conversationId || !!l.previousResponseId, d = l.session, m = s instanceof Ve;
8606
- let g = d && m ? [] : void 0, _, T = d && m ? /* @__PURE__ */ new Map() : void 0;
8607
- const y = (x, A) => {
8608
- const D = T;
8606
+ let g = d && m ? [] : void 0, v, S = d && m ? /* @__PURE__ */ new Map() : void 0;
8607
+ const y = (T, A) => {
8608
+ const D = S;
8609
8609
  if (A !== void 0) {
8610
8610
  if (!D) {
8611
- _ = A.map((Y) => structuredClone(Y));
8611
+ v = A.map((Y) => structuredClone(Y));
8612
8612
  return;
8613
8613
  }
8614
8614
  const G = [], L = /* @__PURE__ */ new WeakMap();
8615
- for (const Y of x) {
8615
+ for (const Y of T) {
8616
8616
  if (!Y || typeof Y != "object")
8617
8617
  continue;
8618
8618
  const oe = (L.get(Y) ?? 0) + 1;
@@ -8629,42 +8629,42 @@ class xd extends Uc {
8629
8629
  if (!oe)
8630
8630
  continue;
8631
8631
  let Ee = !1;
8632
- const Pe = x[Y];
8632
+ const Pe = T[Y];
8633
8633
  if (Pe && typeof Pe == "object") {
8634
8634
  const qr = (L.get(Pe) ?? 0) - 1;
8635
8635
  if (L.set(Pe, qr), qr > 0)
8636
8636
  continue;
8637
- const Jr = wt(Pe), Gr = D.get(Jr) ?? 0;
8637
+ const Jr = It(Pe), Gr = D.get(Jr) ?? 0;
8638
8638
  if (Gr > 0) {
8639
8639
  D.set(Jr, Gr - 1), G.push(structuredClone(oe)), Ee = !0;
8640
8640
  continue;
8641
8641
  }
8642
8642
  }
8643
- const hn = wt(oe), es = D.get(hn) ?? 0;
8643
+ const hn = It(oe), es = D.get(hn) ?? 0;
8644
8644
  if (es > 0) {
8645
8645
  D.set(hn, es - 1), G.push(structuredClone(oe)), Ee = !0;
8646
8646
  continue;
8647
8647
  }
8648
- !Pe && ue() && (G.push(structuredClone(oe)), Ee = !0), !Ee && !Pe && _ === void 0 && G.push(structuredClone(oe));
8648
+ !Pe && ue() && (G.push(structuredClone(oe)), Ee = !0), !Ee && !Pe && v === void 0 && G.push(structuredClone(oe));
8649
8649
  }
8650
- (G.length > 0 || _ === void 0) && (_ = G);
8650
+ (G.length > 0 || v === void 0) && (v = G);
8651
8651
  return;
8652
8652
  }
8653
8653
  const U = [];
8654
8654
  if (D)
8655
- for (const G of x) {
8655
+ for (const G of T) {
8656
8656
  if (!G)
8657
8657
  continue;
8658
- const L = wt(G), ue = D.get(L) ?? 0;
8658
+ const L = It(G), ue = D.get(L) ?? 0;
8659
8659
  ue <= 0 || (D.set(L, ue - 1), U.push(structuredClone(G)));
8660
8660
  }
8661
8661
  else
8662
- for (const G of x)
8662
+ for (const G of T)
8663
8663
  G && U.push(structuredClone(G));
8664
- U.length > 0 ? _ = U : _ === void 0 && (_ = []);
8664
+ U.length > 0 ? v = U : v === void 0 && (v = []);
8665
8665
  }, h = () => {
8666
- if (_ !== void 0)
8667
- return _;
8666
+ if (v !== void 0)
8667
+ return v;
8668
8668
  if (!u)
8669
8669
  return g;
8670
8670
  };
@@ -8672,43 +8672,43 @@ class xd extends Uc {
8672
8672
  if (!(w instanceof Ve)) {
8673
8673
  if (d && Array.isArray(w) && !o)
8674
8674
  throw new ne("RunConfig.sessionInputCallback must be provided when using session history with list inputs.");
8675
- const x = await pd(w, d, o, {
8675
+ const T = await pd(w, d, o, {
8676
8676
  // When the server tracks conversation state we only send the new turn inputs;
8677
8677
  // previous messages are recovered via conversationId/previousResponseId.
8678
8678
  includeHistoryInPreparedInput: !p,
8679
8679
  preserveDroppedNewItems: p
8680
8680
  });
8681
8681
  if (p && d) {
8682
- const A = x.sessionItems;
8683
- A && A.length > 0 ? w = A : w = x.preparedInput;
8682
+ const A = T.sessionItems;
8683
+ A && A.length > 0 ? w = A : w = T.preparedInput;
8684
8684
  } else
8685
- w = x.preparedInput;
8685
+ w = T.preparedInput;
8686
8686
  if (d) {
8687
- const A = x.sessionItems ?? [];
8688
- g = A.map((D) => structuredClone(D)), T = /* @__PURE__ */ new Map();
8687
+ const A = T.sessionItems ?? [];
8688
+ g = A.map((D) => structuredClone(D)), S = /* @__PURE__ */ new Map();
8689
8689
  for (const D of A) {
8690
- const U = wt(D);
8691
- T.set(U, (T.get(U) ?? 0) + 1);
8690
+ const U = It(D);
8691
+ S.set(U, (S.get(U) ?? 0) + 1);
8692
8692
  }
8693
8693
  }
8694
8694
  }
8695
- let v;
8695
+ let _;
8696
8696
  if (d && !p) {
8697
- let x = !1;
8698
- v = async () => {
8699
- if (x)
8697
+ let T = !1;
8698
+ _ = async () => {
8699
+ if (T)
8700
8700
  return;
8701
8701
  const A = h();
8702
- !A || A.length === 0 || (x = !0, await dd(d, A));
8702
+ !A || A.length === 0 || (T = !0, await dd(d, A));
8703
8703
  };
8704
8704
  }
8705
- const N = async () => {
8705
+ const R = async () => {
8706
8706
  if (l.stream)
8707
- return await z(this, ie, ao).call(this, t, w, l, v, y);
8708
- const x = await z(this, ie, ro).call(this, t, w, l, y);
8709
- return d && !p && await ld(d, h(), x), x;
8707
+ return await z(this, ie, ao).call(this, t, w, l, _, y);
8708
+ const T = await z(this, ie, ro).call(this, t, w, l, y);
8709
+ return d && !p && await ld(d, h(), T), T;
8710
8710
  };
8711
- return w instanceof Ve && w._trace ? Nd(w._trace, async () => (w._currentAgentSpan && jr(w._currentAgentSpan), N())) : Pd(async () => N(), {
8711
+ return w instanceof Ve && w._trace ? Nd(w._trace, async () => (w._currentAgentSpan && jr(w._currentAgentSpan), R())) : Pd(async () => R(), {
8712
8712
  traceId: this.config.traceId,
8713
8713
  name: this.config.workflowName,
8714
8714
  groupId: this.config.groupId,
@@ -8730,7 +8730,7 @@ ie = new WeakSet(), lr = function(t) {
8730
8730
  }, ro = async function(t, s, r, i) {
8731
8731
  return mr(async () => {
8732
8732
  var p, d, m;
8733
- const o = s instanceof Ve, a = o ? s : new Ve(r.context instanceof Zt ? r.context : new Zt(r.context), s, t, r.maxTurns ?? Li), u = r.conversationId || r.previousResponseId ? new Bi({
8733
+ const o = s instanceof Ve, a = o ? s : new Ve(r.context instanceof qt ? r.context : new qt(r.context), s, t, r.maxTurns ?? Li), u = r.conversationId || r.previousResponseId ? new Bi({
8734
8734
  conversationId: r.conversationId,
8735
8735
  previousResponseId: r.previousResponseId
8736
8736
  }) : void 0;
@@ -8757,17 +8757,17 @@ ie = new WeakSet(), lr = function(t) {
8757
8757
  l = !1, a._currentStep = g.nextStep;
8758
8758
  }
8759
8759
  if (a._currentStep.type === "next_step_run_again") {
8760
- const g = await Zi(a), _ = o && l;
8761
- if (l = !1, _ || (a._currentTurn++, a._currentTurnPersistedItemCount = 0), a._currentTurn > a._maxTurns)
8760
+ const g = await Zi(a), v = o && l;
8761
+ if (l = !1, v || (a._currentTurn++, a._currentTurnPersistedItemCount = 0), a._currentTurn > a._maxTurns)
8762
8762
  throw (p = a._currentAgentSpan) == null || p.setError({
8763
8763
  message: "Max turns exceeded",
8764
8764
  data: { max_turns: a._maxTurns }
8765
8765
  }), new ui(`Max turns (${a._maxTurns}) exceeded`, a);
8766
8766
  F.debug(`Running agent ${a._currentAgent.name} (turn ${a._currentTurn})`);
8767
- let T;
8768
- if (a._currentTurn === 1 && !_) {
8769
- const N = z(this, ie, dr).call(this, a);
8770
- N.blocking.length > 0 && await z(this, ie, yn).call(this, a, N.blocking), N.parallel.length > 0 && (T = z(this, ie, yn).call(this, a, N.parallel), T.catch(() => {
8767
+ let S;
8768
+ if (a._currentTurn === 1 && !v) {
8769
+ const R = z(this, ie, dr).call(this, a);
8770
+ R.blocking.length > 0 && await z(this, ie, yn).call(this, a, R.blocking), R.parallel.length > 0 && (S = z(this, ie, yn).call(this, a, R.parallel), S.catch(() => {
8771
8771
  }));
8772
8772
  }
8773
8773
  const y = u ? u.prepareInput(a._originalInput, a._generatedItems) : Vt(a._originalInput, a._generatedItems);
@@ -8791,8 +8791,8 @@ ie = new WeakSet(), lr = function(t) {
8791
8791
  }), a._modelResponses.push(a._lastTurnResponse), a._context.usage.add(a._lastTurnResponse.usage), a._noActiveAgentRun = !1, u == null || u.trackServerItems(a._lastTurnResponse);
8792
8792
  const w = ki(a._lastTurnResponse, a._currentAgent, h.tools, h.handoffs);
8793
8793
  a._lastProcessedResponse = w;
8794
- const v = await Ci(a._currentAgent, a._originalInput, a._generatedItems, a._lastTurnResponse, a._lastProcessedResponse, this, a);
8795
- a._toolUseTracker.addToolUse(a._currentAgent, a._lastProcessedResponse.toolsUsed), a._originalInput = v.originalInput, a._generatedItems = v.generatedItems, v.nextStep.type === "next_step_run_again" && (a._currentTurnPersistedItemCount = 0), a._currentStep = v.nextStep, T && await T;
8794
+ const _ = await Ci(a._currentAgent, a._originalInput, a._generatedItems, a._lastTurnResponse, a._lastProcessedResponse, this, a);
8795
+ a._toolUseTracker.addToolUse(a._currentAgent, a._lastProcessedResponse.toolsUsed), a._originalInput = _.originalInput, a._generatedItems = _.generatedItems, _.nextStep.type === "next_step_run_again" && (a._currentTurnPersistedItemCount = 0), a._currentStep = _.nextStep, S && await S;
8796
8796
  }
8797
8797
  if (a._currentStep && a._currentStep.type === "next_step_final_output")
8798
8798
  return await z(this, ie, pr).call(this, a, a._currentStep.output), this.emit("agent_end", a._context, a._currentAgent, a._currentStep.output), a._currentAgent.emit("agent_end", a._context, a._currentStep.output), new Bs(a);
@@ -8820,7 +8820,7 @@ ie = new WeakSet(), lr = function(t) {
8820
8820
  }
8821
8821
  });
8822
8822
  }, io = async function(t, s, r, i, o) {
8823
- var g, _, T, y;
8823
+ var g, v, S, y;
8824
8824
  const a = !!s.conversationId || !!s.previousResponseId, u = a ? new Bi({
8825
8825
  conversationId: s.conversationId,
8826
8826
  previousResponseId: s.previousResponseId
@@ -8855,24 +8855,24 @@ ie = new WeakSet(), lr = function(t) {
8855
8855
  m = !1, t.state._currentStep = w.nextStep;
8856
8856
  }
8857
8857
  if (t.state._currentStep.type === "next_step_run_again") {
8858
- const w = await Zi(t.state), v = r && m;
8859
- if (m = !1, v || (t.state._currentTurn++, t.state._currentTurnPersistedItemCount = 0), t.state._currentTurn > t.state._maxTurns)
8858
+ const w = await Zi(t.state), _ = r && m;
8859
+ if (m = !1, _ || (t.state._currentTurn++, t.state._currentTurnPersistedItemCount = 0), t.state._currentTurn > t.state._maxTurns)
8860
8860
  throw (g = t.state._currentAgentSpan) == null || g.setError({
8861
8861
  message: "Max turns exceeded",
8862
8862
  data: { max_turns: t.state._maxTurns }
8863
8863
  }), new ui(`Max turns (${t.state._maxTurns}) exceeded`, t.state);
8864
8864
  F.debug(`Running agent ${h.name} (turn ${t.state._currentTurn})`);
8865
- let N, x;
8866
- if (t.state._currentTurn === 1 && !v) {
8865
+ let R, T;
8866
+ if (t.state._currentTurn === 1 && !_) {
8867
8867
  const Y = z(this, ie, dr).call(this, t.state);
8868
- Y.blocking.length > 0 && await z(this, ie, yn).call(this, t.state, Y.blocking), Y.parallel.length > 0 && (x = z(this, ie, yn).call(this, t.state, Y.parallel).catch((Ee) => (N = Ee, [])));
8868
+ Y.blocking.length > 0 && await z(this, ie, yn).call(this, t.state, Y.blocking), Y.parallel.length > 0 && (T = z(this, ie, yn).call(this, t.state, Y.parallel).catch((Ee) => (R = Ee, [])));
8869
8869
  }
8870
8870
  const A = u ? u.prepareInput(t.input, t.newItems) : Vt(t.input, t.newItems);
8871
8871
  t.state._noActiveAgentRun && (h.emit("agent_start", t.state._context, h, A), this.emit("agent_start", t.state._context, h, A));
8872
8872
  let D;
8873
8873
  const U = await z(this, ie, fr).call(this, t.state, s, w, A, u, o);
8874
- if (N)
8875
- throw N;
8874
+ if (R)
8875
+ throw R;
8876
8876
  l = !0, await d();
8877
8877
  for await (const Y of U.model.getStreamedResponse({
8878
8878
  systemInstructions: U.modelInput.instructions,
@@ -8890,8 +8890,8 @@ ie = new WeakSet(), lr = function(t) {
8890
8890
  tracing: zi(this.config.tracingDisabled, this.config.traceIncludeSensitiveData),
8891
8891
  signal: s.signal
8892
8892
  })) {
8893
- if (N)
8894
- throw N;
8893
+ if (R)
8894
+ throw R;
8895
8895
  if (Y.type === "response_done") {
8896
8896
  const oe = Za.parse(Y);
8897
8897
  D = {
@@ -8904,8 +8904,8 @@ ie = new WeakSet(), lr = function(t) {
8904
8904
  return;
8905
8905
  t._addItem(new Bl(Y));
8906
8906
  }
8907
- if (x && (await x, N))
8908
- throw N;
8907
+ if (T && (await T, R))
8908
+ throw R;
8909
8909
  if (t.state._noActiveAgentRun = !1, !D)
8910
8910
  throw new we("Model did not produce a final response!", t.state);
8911
8911
  t.state._lastTurnResponse = D, u == null || u.trackServerItems(D), t.state._modelResponses.push(t.state._lastTurnResponse);
@@ -8924,7 +8924,7 @@ ie = new WeakSet(), lr = function(t) {
8924
8924
  } else if (t.state._currentStep.type === "next_step_interruption") {
8925
8925
  await d(), a || await Ri(s.session, t);
8926
8926
  return;
8927
- } else t.state._currentStep.type === "next_step_handoff" ? (t.state._currentAgent = (_ = t.state._currentStep) == null ? void 0 : _.newAgent, t.state._currentAgentSpan && (t.state._currentAgentSpan.end(), _n()), t.state._currentAgentSpan = void 0, t._addItem(new ql(t.state._currentAgent)), t.state._noActiveAgentRun = !0, t.state._currentStep = {
8927
+ } else t.state._currentStep.type === "next_step_handoff" ? (t.state._currentAgent = (v = t.state._currentStep) == null ? void 0 : v.newAgent, t.state._currentAgentSpan && (t.state._currentAgentSpan.end(), _n()), t.state._currentAgentSpan = void 0, t._addItem(new ql(t.state._currentAgent)), t.state._noActiveAgentRun = !0, t.state._currentStep = {
8928
8928
  type: "next_step_run_again"
8929
8929
  }) : F.debug("Running next loop");
8930
8930
  }
@@ -8934,7 +8934,7 @@ ie = new WeakSet(), lr = function(t) {
8934
8934
  data: { error: String(h) }
8935
8935
  }), h;
8936
8936
  } finally {
8937
- if (((T = t.state._currentStep) == null ? void 0 : T.type) !== "next_step_interruption")
8937
+ if (((S = t.state._currentStep) == null ? void 0 : S.type) !== "next_step_interruption")
8938
8938
  try {
8939
8939
  await vi({ runContext: t.state._context });
8940
8940
  } catch (h) {
@@ -8944,7 +8944,7 @@ ie = new WeakSet(), lr = function(t) {
8944
8944
  }
8945
8945
  }, ao = async function(t, s, r, i, o) {
8946
8946
  return r = r ?? {}, mr(async () => {
8947
- const a = s instanceof Ve, u = a ? s : new Ve(r.context instanceof Zt ? r.context : new Zt(r.context), s, t, r.maxTurns ?? Li), l = new uo({
8947
+ const a = s instanceof Ve, u = a ? s : new Ve(r.context instanceof qt ? r.context : new qt(r.context), s, t, r.maxTurns ?? Li), l = new uo({
8948
8948
  signal: r.signal,
8949
8949
  state: u
8950
8950
  });
@@ -9016,8 +9016,8 @@ ie = new WeakSet(), lr = function(t) {
9016
9016
  ...t._currentAgent.modelSettings
9017
9017
  };
9018
9018
  p = Cd(l, t._currentAgent.modelSettings, u, p), p = Wl(t._currentAgent, t._toolUseTracker, p);
9019
- const d = await t._currentAgent.getSystemPrompt(t._context), m = await t._currentAgent.getPrompt(t._context), { modelInput: g, sourceItems: _, persistedItems: T, filterApplied: y } = await Ad(t._currentAgent, s.callModelInputFilter, t._context, i, d);
9020
- o == null || o.markInputAsSent(_), a == null || a(_, y ? T : void 0);
9019
+ const d = await t._currentAgent.getSystemPrompt(t._context), m = await t._currentAgent.getPrompt(t._context), { modelInput: g, sourceItems: v, persistedItems: S, filterApplied: y } = await Ad(t._currentAgent, s.callModelInputFilter, t._context, i, d);
9020
+ o == null || o.markInputAsSent(v), a == null || a(v, y ? S : void 0);
9021
9021
  const h = (o == null ? void 0 : o.previousResponseId) ?? s.previousResponseId, w = (o == null ? void 0 : o.conversationId) ?? s.conversationId;
9022
9022
  return {
9023
9023
  ...r,
@@ -9042,17 +9042,17 @@ function zi(n, e) {
9042
9042
  return n ? !1 : e ? !0 : "enabled_without_data";
9043
9043
  }
9044
9044
  async function Ad(n, e, t, s, r) {
9045
- const i = (g, _) => g.map((T) => {
9046
- const y = structuredClone(T);
9047
- return _ && y && typeof y == "object" && _.set(y, T), y;
9045
+ const i = (g, v) => g.map((S) => {
9046
+ const y = structuredClone(S);
9047
+ return v && y && typeof y == "object" && v.set(y, S), y;
9048
9048
  }), o = /* @__PURE__ */ new WeakMap(), a = Od(s), u = [];
9049
9049
  for (const g of s)
9050
9050
  g && typeof g == "object" && u.push(g);
9051
9051
  const l = (g) => {
9052
9052
  if (!g || typeof g != "object")
9053
9053
  return;
9054
- const _ = u.findIndex((T) => T === g);
9055
- _ !== -1 && u.splice(_, 1);
9054
+ const v = u.findIndex((S) => S === g);
9055
+ v !== -1 && u.splice(v, 1);
9056
9056
  }, p = () => {
9057
9057
  const g = u.shift();
9058
9058
  return g && qi(a, g), g;
@@ -9075,26 +9075,26 @@ async function Ad(n, e, t, s, r) {
9075
9075
  });
9076
9076
  if (!g || !Array.isArray(g.input))
9077
9077
  throw new ne("callModelInputFilter must return a ModelInputData object with an input array.");
9078
- const _ = g.input.map((y) => {
9078
+ const v = g.input.map((y) => {
9079
9079
  if (!y || typeof y != "object")
9080
9080
  return;
9081
9081
  const h = o.get(y);
9082
9082
  if (h)
9083
9083
  return l(h), qi(a, h), h;
9084
- const w = wt(y), v = Ed(a, w);
9085
- if (v)
9086
- return l(v), v;
9087
- const N = p();
9088
- if (N)
9089
- return N;
9090
- }), T = i(g.input);
9084
+ const w = It(y), _ = Ed(a, w);
9085
+ if (_)
9086
+ return l(_), _;
9087
+ const R = p();
9088
+ if (R)
9089
+ return R;
9090
+ }), S = i(g.input);
9091
9091
  return {
9092
9092
  modelInput: {
9093
- input: T,
9093
+ input: S,
9094
9094
  instructions: typeof g.instructions > "u" ? r : g.instructions
9095
9095
  },
9096
- sourceItems: _,
9097
- persistedItems: T.map((y) => structuredClone(y)),
9096
+ sourceItems: v,
9097
+ persistedItems: S.map((y) => structuredClone(y)),
9098
9098
  filterApplied: !0
9099
9099
  };
9100
9100
  } catch (g) {
@@ -9109,18 +9109,18 @@ class Bi {
9109
9109
  // Conversation ID:
9110
9110
  // - https://platform.openai.com/docs/guides/conversation-state?api-mode=responses#using-the-conversations-api
9111
9111
  // - https://platform.openai.com/docs/api-reference/conversations/create
9112
- S(this, "conversationId");
9112
+ x(this, "conversationId");
9113
9113
  // Previous Response ID:
9114
9114
  // https://platform.openai.com/docs/guides/conversation-state?api-mode=responses#passing-context-from-the-previous-response
9115
- S(this, "previousResponseId");
9115
+ x(this, "previousResponseId");
9116
9116
  // Using this flag because WeakSet does not provide a way to check its size
9117
- S(this, "sentInitialInput", !1);
9117
+ x(this, "sentInitialInput", !1);
9118
9118
  // The items already sent to the model; using WeakSet for memory efficiency
9119
- S(this, "sentItems", /* @__PURE__ */ new WeakSet());
9119
+ x(this, "sentItems", /* @__PURE__ */ new WeakSet());
9120
9120
  // The items received from the server; using WeakSet for memory efficiency
9121
- S(this, "serverItems", /* @__PURE__ */ new WeakSet());
9121
+ x(this, "serverItems", /* @__PURE__ */ new WeakSet());
9122
9122
  // Track initial input items that have not yet been sent so they can be retried on later turns.
9123
- S(this, "remainingInitialInput", null);
9123
+ x(this, "remainingInitialInput", null);
9124
9124
  this.conversationId = e ?? void 0, this.previousResponseId = t ?? void 0;
9125
9125
  }
9126
9126
  /**
@@ -9225,13 +9225,13 @@ async function Zi(n) {
9225
9225
  toolsExplicitlyProvided: n._currentAgent.hasExplicitToolConfig()
9226
9226
  };
9227
9227
  }
9228
- function wt(n) {
9228
+ function It(n) {
9229
9229
  return JSON.stringify(n, Rd);
9230
9230
  }
9231
9231
  function Od(n) {
9232
9232
  const e = /* @__PURE__ */ new Map();
9233
9233
  for (const t of n) {
9234
- const s = wt(t), r = e.get(s);
9234
+ const s = It(t), r = e.get(s);
9235
9235
  r ? r.push(t) : e.set(s, [t]);
9236
9236
  }
9237
9237
  return e;
@@ -9244,7 +9244,7 @@ function Ed(n, e) {
9244
9244
  return t.shift(), t.length === 0 && n.delete(e), s;
9245
9245
  }
9246
9246
  function qi(n, e) {
9247
- const t = wt(e), s = n.get(t);
9247
+ const t = It(e), s = n.get(t);
9248
9248
  if (!s || s.length === 0)
9249
9249
  return;
9250
9250
  const r = s.findIndex((i) => i === e);
@@ -9280,7 +9280,7 @@ function hr(n) {
9280
9280
  }
9281
9281
  class oo {
9282
9282
  constructor(e) {
9283
- S(this, "state");
9283
+ x(this, "state");
9284
9284
  this.state = e;
9285
9285
  }
9286
9286
  /**
@@ -9371,42 +9371,42 @@ class Bs extends oo {
9371
9371
  super(e);
9372
9372
  }
9373
9373
  }
9374
- var En, at, Te, He, Kt, Yt, Rn, St, Nn;
9374
+ var En, at, Te, He, Kt, Yt, Rn, Tt, Nn;
9375
9375
  class uo extends oo {
9376
9376
  constructor(t = {}) {
9377
9377
  super(t.state);
9378
9378
  /**
9379
9379
  * The current turn number
9380
9380
  */
9381
- S(this, "currentTurn", 0);
9381
+ x(this, "currentTurn", 0);
9382
9382
  /**
9383
9383
  * The maximum number of turns that can be run
9384
9384
  */
9385
- S(this, "maxTurns");
9386
- R(this, En, null);
9387
- R(this, at);
9388
- R(this, Te);
9389
- R(this, He);
9390
- R(this, Kt);
9391
- R(this, Yt);
9392
- R(this, Rn);
9393
- R(this, St, !1);
9394
- R(this, Nn);
9385
+ x(this, "maxTurns");
9386
+ N(this, En, null);
9387
+ N(this, at);
9388
+ N(this, Te);
9389
+ N(this, He);
9390
+ N(this, Kt);
9391
+ N(this, Yt);
9392
+ N(this, Rn);
9393
+ N(this, Tt, !1);
9394
+ N(this, Nn);
9395
9395
  if (k(this, at, t.signal), k(this, He, new Pc({
9396
9396
  start: (s) => {
9397
9397
  k(this, Te, s);
9398
9398
  },
9399
9399
  cancel: () => {
9400
- k(this, St, !0);
9400
+ k(this, Tt, !0);
9401
9401
  }
9402
9402
  })), k(this, Kt, new Promise((s, r) => {
9403
9403
  k(this, Yt, s), k(this, Rn, r);
9404
9404
  })), c(this, at)) {
9405
9405
  const s = () => {
9406
9406
  var i, o;
9407
- if (c(this, St))
9407
+ if (c(this, Tt))
9408
9408
  return;
9409
- k(this, St, !0);
9409
+ k(this, Tt, !0);
9410
9410
  const r = c(this, Te);
9411
9411
  if (k(this, Te, void 0), c(this, He).locked) {
9412
9412
  if (r)
@@ -9460,7 +9460,7 @@ class uo extends oo {
9460
9460
  * Returns true if the stream has been cancelled.
9461
9461
  */
9462
9462
  get cancelled() {
9463
- return c(this, St);
9463
+ return c(this, Tt);
9464
9464
  }
9465
9465
  /**
9466
9466
  * Returns the underlying readable stream.
@@ -9513,7 +9513,7 @@ class uo extends oo {
9513
9513
  return c(this, Nn);
9514
9514
  }
9515
9515
  }
9516
- En = new WeakMap(), at = new WeakMap(), Te = new WeakMap(), He = new WeakMap(), Kt = new WeakMap(), Yt = new WeakMap(), Rn = new WeakMap(), St = new WeakMap(), Nn = new WeakMap();
9516
+ En = new WeakMap(), at = new WeakMap(), Te = new WeakMap(), He = new WeakMap(), Kt = new WeakMap(), Yt = new WeakMap(), Rn = new WeakMap(), Tt = new WeakMap(), Nn = new WeakMap();
9517
9517
  let Ji;
9518
9518
  function Ze() {
9519
9519
  return Ji ?? (Ji = new Mc()), Ji;
@@ -9594,7 +9594,7 @@ class Md {
9594
9594
  t.type === "trace" ? console.log(`[Exporter] Export trace traceId=${t.traceId} name=${t.name}${t.groupId ? ` groupId=${t.groupId}` : ""}`) : console.log(`[Exporter] Export span: ${JSON.stringify(t)}`);
9595
9595
  }
9596
9596
  }
9597
- var Pn, Xt, Dn, Mn, Qt, ge, We, ot, ut, en, Ie, gr, yr, Bt;
9597
+ var Pn, Xt, Dn, Mn, Qt, ge, We, ot, ut, en, Ie, gr, yr, Zt;
9598
9598
  class Fd {
9599
9599
  constructor(e, {
9600
9600
  maxQueueSize: t = 1e3,
@@ -9603,17 +9603,17 @@ class Fd {
9603
9603
  // 5 seconds
9604
9604
  exportTriggerRatio: i = 0.8
9605
9605
  } = {}) {
9606
- R(this, Ie);
9607
- R(this, Pn);
9608
- R(this, Xt);
9609
- R(this, Dn);
9610
- R(this, Mn);
9611
- R(this, Qt);
9612
- R(this, ge, []);
9613
- R(this, We);
9614
- R(this, ot, null);
9615
- R(this, ut, !1);
9616
- R(this, en, null);
9606
+ N(this, Ie);
9607
+ N(this, Pn);
9608
+ N(this, Xt);
9609
+ N(this, Dn);
9610
+ N(this, Mn);
9611
+ N(this, Qt);
9612
+ N(this, ge, []);
9613
+ N(this, We);
9614
+ N(this, ot, null);
9615
+ N(this, ut, !1);
9616
+ N(this, en, null);
9617
9617
  k(this, Pn, t), k(this, Xt, s), k(this, Dn, r), k(this, Mn, t * i), k(this, Qt, e), k(this, We, $c), F.debug("Automatic trace export loop is not supported in this environment. You need to manually call `getGlobalTraceProvider().forceFlush()` to export traces.");
9618
9618
  }
9619
9619
  start() {
@@ -9635,8 +9635,8 @@ class Fd {
9635
9635
  var s;
9636
9636
  (s = c(this, en)) == null || s.abort();
9637
9637
  }, e), F.debug("Shutting down gracefully"); c(this, ge).length > 0; ) {
9638
- if (F.debug(`Waiting for buffer to empty. Items left: ${c(this, ge).length}`), c(this, ut) || await z(this, Ie, Bt).call(this, !0), (t = c(this, en)) != null && t.signal.aborted) {
9639
- F.debug("Timeout reached, force flushing"), await z(this, Ie, Bt).call(this, !0);
9638
+ if (F.debug(`Waiting for buffer to empty. Items left: ${c(this, ge).length}`), c(this, ut) || await z(this, Ie, Zt).call(this, !0), (t = c(this, en)) != null && t.signal.aborted) {
9639
+ F.debug("Timeout reached, force flushing"), await z(this, Ie, Zt).call(this, !0);
9640
9640
  break;
9641
9641
  }
9642
9642
  await new Promise((s) => c(this, We).setTimeout(s, 500));
@@ -9644,7 +9644,7 @@ class Fd {
9644
9644
  F.debug("Buffer empty. Exiting"), c(this, We) && c(this, ot) && c(this, We).clearTimeout(c(this, ot));
9645
9645
  }
9646
9646
  async forceFlush() {
9647
- c(this, ge).length > 0 && await z(this, Ie, Bt).call(this, !0);
9647
+ c(this, ge).length > 0 && await z(this, Ie, Zt).call(this, !0);
9648
9648
  }
9649
9649
  }
9650
9650
  Pn = new WeakMap(), Xt = new WeakMap(), Dn = new WeakMap(), Mn = new WeakMap(), Qt = new WeakMap(), ge = new WeakMap(), We = new WeakMap(), ot = new WeakMap(), ut = new WeakMap(), en = new WeakMap(), Ie = new WeakSet(), gr = async function(e) {
@@ -9652,12 +9652,12 @@ Pn = new WeakMap(), Xt = new WeakMap(), Dn = new WeakMap(), Mn = new WeakMap(),
9652
9652
  F.error("Dropping trace because buffer is full");
9653
9653
  return;
9654
9654
  }
9655
- c(this, ge).push(e), c(this, ge).length > c(this, Mn) && await z(this, Ie, Bt).call(this);
9655
+ c(this, ge).push(e), c(this, ge).length > c(this, Mn) && await z(this, Ie, Zt).call(this);
9656
9656
  }, yr = function() {
9657
9657
  k(this, ot, c(this, We).setTimeout(async () => {
9658
- await z(this, Ie, Bt).call(this), z(this, Ie, yr).call(this);
9658
+ await z(this, Ie, Zt).call(this), z(this, Ie, yr).call(this);
9659
9659
  }, c(this, Dn))), typeof c(this, ot).unref == "function" && c(this, ot).unref();
9660
- }, Bt = async function(e = !1) {
9660
+ }, Zt = async function(e = !1) {
9661
9661
  if (c(this, ge).length !== 0) {
9662
9662
  if (F.debug(`Exporting batches. Force: ${e}. Buffer size: ${c(this, ge).length}`), e || c(this, ge).length < c(this, Xt)) {
9663
9663
  const t = [...c(this, ge)];
@@ -9671,7 +9671,7 @@ Pn = new WeakMap(), Xt = new WeakMap(), Dn = new WeakMap(), Mn = new WeakMap(),
9671
9671
  var xe;
9672
9672
  class $d {
9673
9673
  constructor() {
9674
- R(this, xe, []);
9674
+ N(this, xe, []);
9675
9675
  }
9676
9676
  start() {
9677
9677
  for (const e of c(this, xe))
@@ -9731,20 +9731,20 @@ function Ud() {
9731
9731
  function Ld(n) {
9732
9732
  return Object.fromEntries(Object.entries(n).filter(([e]) => !e.startsWith("_")));
9733
9733
  }
9734
- var Fn, $n, jn, Un, Tt, ct, lt, xt, Ln;
9734
+ var Fn, $n, jn, Un, xt, ct, lt, kt, Ln;
9735
9735
  const Lr = class Lr {
9736
9736
  constructor(e, t) {
9737
- S(this, "type", "trace.span");
9738
- R(this, Fn);
9739
- R(this, $n);
9740
- R(this, jn);
9741
- R(this, Un);
9742
- R(this, Tt);
9743
- R(this, ct);
9744
- R(this, lt);
9745
- R(this, xt);
9746
- R(this, Ln);
9747
- k(this, $n, e.traceId), k(this, jn, e.spanId ?? Ud()), k(this, Fn, e.data), k(this, Tt, t), k(this, Un, e.parentId ?? null), k(this, xt, e.error ?? null), k(this, ct, e.startedAt ?? null), k(this, lt, e.endedAt ?? null);
9737
+ x(this, "type", "trace.span");
9738
+ N(this, Fn);
9739
+ N(this, $n);
9740
+ N(this, jn);
9741
+ N(this, Un);
9742
+ N(this, xt);
9743
+ N(this, ct);
9744
+ N(this, lt);
9745
+ N(this, kt);
9746
+ N(this, Ln);
9747
+ k(this, $n, e.traceId), k(this, jn, e.spanId ?? Ud()), k(this, Fn, e.data), k(this, xt, t), k(this, Un, e.parentId ?? null), k(this, kt, e.error ?? null), k(this, ct, e.startedAt ?? null), k(this, lt, e.endedAt ?? null);
9748
9748
  }
9749
9749
  get traceId() {
9750
9750
  return c(this, $n);
@@ -9769,20 +9769,20 @@ const Lr = class Lr {
9769
9769
  F.warn("Span already started");
9770
9770
  return;
9771
9771
  }
9772
- k(this, ct, Gi()), c(this, Tt).onSpanStart(this);
9772
+ k(this, ct, Gi()), c(this, xt).onSpanStart(this);
9773
9773
  }
9774
9774
  end() {
9775
9775
  if (c(this, lt)) {
9776
9776
  F.debug("Span already finished", this.spanData);
9777
9777
  return;
9778
9778
  }
9779
- k(this, lt, Gi()), c(this, Tt).onSpanEnd(this);
9779
+ k(this, lt, Gi()), c(this, xt).onSpanEnd(this);
9780
9780
  }
9781
9781
  setError(e) {
9782
- k(this, xt, e);
9782
+ k(this, kt, e);
9783
9783
  }
9784
9784
  get error() {
9785
- return c(this, xt);
9785
+ return c(this, kt);
9786
9786
  }
9787
9787
  get startedAt() {
9788
9788
  return c(this, ct);
@@ -9799,8 +9799,8 @@ const Lr = class Lr {
9799
9799
  data: this.spanData,
9800
9800
  startedAt: c(this, ct) ?? void 0,
9801
9801
  endedAt: c(this, lt) ?? void 0,
9802
- error: c(this, xt) ?? void 0
9803
- }, c(this, Tt));
9802
+ error: c(this, kt) ?? void 0
9803
+ }, c(this, xt));
9804
9804
  return e.previousSpan = (t = this.previousSpan) == null ? void 0 : t.clone(), e;
9805
9805
  }
9806
9806
  toJSON() {
@@ -9816,7 +9816,7 @@ const Lr = class Lr {
9816
9816
  };
9817
9817
  }
9818
9818
  };
9819
- Fn = new WeakMap(), $n = new WeakMap(), jn = new WeakMap(), Un = new WeakMap(), Tt = new WeakMap(), ct = new WeakMap(), lt = new WeakMap(), xt = new WeakMap(), Ln = new WeakMap();
9819
+ Fn = new WeakMap(), $n = new WeakMap(), jn = new WeakMap(), Un = new WeakMap(), xt = new WeakMap(), ct = new WeakMap(), lt = new WeakMap(), kt = new WeakMap(), Ln = new WeakMap();
9820
9820
  let Cn = Lr;
9821
9821
  class rt extends Cn {
9822
9822
  constructor(e, t) {
@@ -9835,13 +9835,13 @@ class rt extends Cn {
9835
9835
  var tn, Ke;
9836
9836
  const zr = class zr {
9837
9837
  constructor(e, t) {
9838
- S(this, "type", "trace");
9839
- S(this, "traceId");
9840
- S(this, "name");
9841
- S(this, "groupId", null);
9842
- S(this, "metadata");
9843
- R(this, tn);
9844
- R(this, Ke);
9838
+ x(this, "type", "trace");
9839
+ x(this, "traceId");
9840
+ x(this, "name");
9841
+ x(this, "groupId", null);
9842
+ x(this, "metadata");
9843
+ N(this, tn);
9844
+ N(this, Ke);
9845
9845
  this.traceId = e.traceId ?? po(), this.name = e.name ?? "Agent workflow", this.groupId = e.groupId ?? null, this.metadata = e.metadata ?? {}, k(this, tn, t ?? lo()), k(this, Ke, e.started ?? !1);
9846
9846
  }
9847
9847
  async start() {
@@ -9883,13 +9883,13 @@ class Js extends On {
9883
9883
  return null;
9884
9884
  }
9885
9885
  }
9886
- var me, kt, xs, fo;
9886
+ var me, At, xs, fo;
9887
9887
  class zd {
9888
9888
  constructor() {
9889
- R(this, xs);
9890
- R(this, me);
9891
- R(this, kt);
9892
- k(this, me, new $d()), k(this, kt, ba.disabled), z(this, xs, fo).call(this);
9889
+ N(this, xs);
9890
+ N(this, me);
9891
+ N(this, At);
9892
+ k(this, me, new $d()), k(this, At, ba.disabled), z(this, xs, fo).call(this);
9893
9893
  }
9894
9894
  /**
9895
9895
  * Add a processor to the list of processors. Each processor will receive all traces/spans.
@@ -9919,19 +9919,19 @@ class zd {
9919
9919
  return An();
9920
9920
  }
9921
9921
  setDisabled(e) {
9922
- k(this, kt, e);
9922
+ k(this, At, e);
9923
9923
  }
9924
9924
  startExportLoop() {
9925
9925
  c(this, me).start();
9926
9926
  }
9927
9927
  createTrace(e) {
9928
- if (c(this, kt))
9928
+ if (c(this, At))
9929
9929
  return F.debug("Tracing is disabled, Not creating trace %o", e), new Js();
9930
9930
  const t = e.traceId ?? po(), s = e.name ?? "Agent workflow";
9931
9931
  return F.debug("Creating trace %s with name %s", t, s), new On({ ...e, name: s, traceId: t }, c(this, me));
9932
9932
  }
9933
9933
  createSpan(e, t) {
9934
- if (c(this, kt) || e.disabled)
9934
+ if (c(this, At) || e.disabled)
9935
9935
  return F.debug("Tracing is disabled, Not creating span %o", e), new rt(e.data, c(this, me));
9936
9936
  let s, r;
9937
9937
  if (t) {
@@ -9969,7 +9969,7 @@ class zd {
9969
9969
  await c(this, me).forceFlush();
9970
9970
  }
9971
9971
  }
9972
- me = new WeakMap(), kt = new WeakMap(), xs = new WeakSet(), /** Adds listeners to `process` to ensure `shutdown` occurs before exit. */
9972
+ me = new WeakMap(), At = new WeakMap(), xs = new WeakSet(), /** Adds listeners to `process` to ensure `shutdown` occurs before exit. */
9973
9973
  fo = function() {
9974
9974
  if (typeof process < "u" && typeof process.on == "function") {
9975
9975
  const e = async () => {
@@ -10138,7 +10138,7 @@ class Xd extends st {
10138
10138
  * The voice intended to be used by the agent. If another agent already spoke during the
10139
10139
  * RealtimeSession, changing the voice during a handoff will fail.
10140
10140
  */
10141
- S(this, "voice");
10141
+ x(this, "voice");
10142
10142
  this.voice = t.voice;
10143
10143
  }
10144
10144
  }
@@ -10292,7 +10292,7 @@ const Yi = ye("role", [
10292
10292
  serverLabel: f(),
10293
10293
  name: f(),
10294
10294
  arguments: se(f(), W()),
10295
- approved: Pt().optional().nullable()
10295
+ approved: Dt().optional().nullable()
10296
10296
  }), ke = Ia("openai-agents:realtime"), mo = b({
10297
10297
  id: f().optional().nullable(),
10298
10298
  conversation_id: f().optional().nullable(),
@@ -10349,7 +10349,7 @@ const Yi = ye("role", [
10349
10349
  "mcp_approval_response"
10350
10350
  ]).optional(),
10351
10351
  approval_request_id: f().nullable().optional(),
10352
- approve: Pt().nullable().optional(),
10352
+ approve: Dt().nullable().optional(),
10353
10353
  reason: f().nullable().optional(),
10354
10354
  server_label: f().optional(),
10355
10355
  error: W().nullable().optional(),
@@ -10742,29 +10742,29 @@ const rf = "gpt-realtime", De = {
10742
10742
  }
10743
10743
  }
10744
10744
  };
10745
- var At, zn, be, Bn;
10745
+ var Ct, zn, be, Bn;
10746
10746
  const Br = class Br extends Ar {
10747
10747
  constructor(t = {}) {
10748
10748
  super();
10749
- R(this, At);
10750
- R(this, zn);
10751
- R(this, be, null);
10752
- R(this, Bn, null);
10753
- S(this, "eventEmitter", new Cs());
10754
- k(this, At, t.model ?? rf), k(this, zn, t.apiKey);
10749
+ N(this, Ct);
10750
+ N(this, zn);
10751
+ N(this, be, null);
10752
+ N(this, Bn, null);
10753
+ x(this, "eventEmitter", new Cs());
10754
+ k(this, Ct, t.model ?? rf), k(this, zn, t.apiKey);
10755
10755
  }
10756
10756
  /**
10757
10757
  * The current model that is being used by the transport layer.
10758
10758
  */
10759
10759
  get currentModel() {
10760
- return c(this, At);
10760
+ return c(this, Ct);
10761
10761
  }
10762
10762
  /**
10763
10763
  * The current model that is being used by the transport layer.
10764
10764
  * **Note**: The model cannot be changed mid conversation.
10765
10765
  */
10766
10766
  set currentModel(t) {
10767
- k(this, At, t);
10767
+ k(this, Ct, t);
10768
10768
  }
10769
10769
  /**
10770
10770
  * Hook for subclasses to clean up transport-specific state when audio
@@ -10798,14 +10798,14 @@ const Br = class Br extends Ar {
10798
10798
  ke.error("Error parsing response done event", d.error);
10799
10799
  return;
10800
10800
  }
10801
- const m = ((i = d.data.response.usage) == null ? void 0 : i.input_tokens) ?? 0, g = ((o = d.data.response.usage) == null ? void 0 : o.output_tokens) ?? 0, _ = m + g, T = new Qn({
10801
+ const m = ((i = d.data.response.usage) == null ? void 0 : i.input_tokens) ?? 0, g = ((o = d.data.response.usage) == null ? void 0 : o.output_tokens) ?? 0, v = m + g, S = new Qn({
10802
10802
  inputTokens: m,
10803
10803
  inputTokensDetails: ((a = d.data.response.usage) == null ? void 0 : a.input_token_details) ?? {},
10804
10804
  outputTokens: g,
10805
10805
  outputTokensDetails: ((u = d.data.response.usage) == null ? void 0 : u.output_token_details) ?? {},
10806
- totalTokens: _
10806
+ totalTokens: v
10807
10807
  });
10808
- this.emit("usage_update", T), this.emit("turn_done", {
10808
+ this.emit("usage_update", S), this.emit("turn_done", {
10809
10809
  type: "response_done",
10810
10810
  response: {
10811
10811
  id: d.data.response.id ?? "",
@@ -10815,7 +10815,7 @@ const Br = class Br extends Ar {
10815
10815
  inputTokensDetails: ((l = d.data.response.usage) == null ? void 0 : l.input_token_details) ?? {},
10816
10816
  outputTokens: g,
10817
10817
  outputTokensDetails: ((p = d.data.response.usage) == null ? void 0 : p.output_token_details) ?? {},
10818
- totalTokens: _
10818
+ totalTokens: v
10819
10819
  }
10820
10820
  }
10821
10821
  });
@@ -11011,21 +11011,21 @@ const Br = class Br extends Ar {
11011
11011
  }, {}, { triggerResponse: s });
11012
11012
  }
11013
11013
  _getMergedSessionConfig(t) {
11014
- var i, o, a, u, l, p, d, m, g, _, T, y, h, w, v, N, x, A, D, U, G, L, ue, Y, oe, Ee, Pe, hn;
11014
+ var i, o, a, u, l, p, d, m, g, v, S, y, h, w, _, R, T, A, D, U, G, L, ue, Y, oe, Ee, Pe, hn;
11015
11015
  const s = sp(t), r = {
11016
11016
  type: "realtime",
11017
11017
  instructions: s.instructions,
11018
- model: s.model ?? c(this, At),
11018
+ model: s.model ?? c(this, Ct),
11019
11019
  output_modalities: s.outputModalities ?? De.outputModalities,
11020
11020
  audio: {
11021
11021
  input: {
11022
11022
  format: ((o = (i = s.audio) == null ? void 0 : i.input) == null ? void 0 : o.format) ?? ((u = (a = De.audio) == null ? void 0 : a.input) == null ? void 0 : u.format),
11023
11023
  noise_reduction: ((p = (l = s.audio) == null ? void 0 : l.input) == null ? void 0 : p.noiseReduction) ?? ((m = (d = De.audio) == null ? void 0 : d.input) == null ? void 0 : m.noiseReduction),
11024
- transcription: ((_ = (g = s.audio) == null ? void 0 : g.input) == null ? void 0 : _.transcription) ?? ((y = (T = De.audio) == null ? void 0 : T.input) == null ? void 0 : y.transcription),
11025
- turn_detection: Br.buildTurnDetectionConfig((w = (h = s.audio) == null ? void 0 : h.input) == null ? void 0 : w.turnDetection) ?? ((N = (v = De.audio) == null ? void 0 : v.input) == null ? void 0 : N.turnDetection)
11024
+ transcription: ((v = (g = s.audio) == null ? void 0 : g.input) == null ? void 0 : v.transcription) ?? ((y = (S = De.audio) == null ? void 0 : S.input) == null ? void 0 : y.transcription),
11025
+ turn_detection: Br.buildTurnDetectionConfig((w = (h = s.audio) == null ? void 0 : h.input) == null ? void 0 : w.turnDetection) ?? ((R = (_ = De.audio) == null ? void 0 : _.input) == null ? void 0 : R.turnDetection)
11026
11026
  },
11027
11027
  output: {
11028
- format: ((A = (x = s.audio) == null ? void 0 : x.output) == null ? void 0 : A.format) ?? ((U = (D = De.audio) == null ? void 0 : D.output) == null ? void 0 : U.format),
11028
+ format: ((A = (T = s.audio) == null ? void 0 : T.output) == null ? void 0 : A.format) ?? ((U = (D = De.audio) == null ? void 0 : D.output) == null ? void 0 : U.format),
11029
11029
  voice: ((L = (G = s.audio) == null ? void 0 : G.output) == null ? void 0 : L.voice) ?? ((Y = (ue = De.audio) == null ? void 0 : ue.output) == null ? void 0 : Y.voice),
11030
11030
  speed: ((Ee = (oe = s.audio) == null ? void 0 : oe.output) == null ? void 0 : Ee.speed) ?? ((hn = (Pe = De.audio) == null ? void 0 : Pe.output) == null ? void 0 : hn.speed)
11031
11031
  }
@@ -11059,14 +11059,14 @@ const Br = class Br extends Ar {
11059
11059
  static buildTurnDetectionConfig(t) {
11060
11060
  if (typeof t > "u")
11061
11061
  return;
11062
- const { type: s, createResponse: r, create_response: i, eagerness: o, interruptResponse: a, interrupt_response: u, prefixPaddingMs: l, prefix_padding_ms: p, silenceDurationMs: d, silence_duration_ms: m, threshold: g, idleTimeoutMs: _, idle_timeout_ms: T, ...y } = t, h = {
11062
+ const { type: s, createResponse: r, create_response: i, eagerness: o, interruptResponse: a, interrupt_response: u, prefixPaddingMs: l, prefix_padding_ms: p, silenceDurationMs: d, silence_duration_ms: m, threshold: g, idleTimeoutMs: v, idle_timeout_ms: S, ...y } = t, h = {
11063
11063
  type: s,
11064
11064
  create_response: r || i,
11065
11065
  eagerness: o,
11066
11066
  interrupt_response: a || u,
11067
11067
  prefix_padding_ms: l || p,
11068
11068
  silence_duration_ms: d || m,
11069
- idle_timeout_ms: _ || T,
11069
+ idle_timeout_ms: v || S,
11070
11070
  threshold: g,
11071
11071
  ...y
11072
11072
  };
@@ -11241,7 +11241,7 @@ const Br = class Br extends Ar {
11241
11241
  });
11242
11242
  }
11243
11243
  };
11244
- At = new WeakMap(), zn = new WeakMap(), be = new WeakMap(), Bn = new WeakMap();
11244
+ Ct = new WeakMap(), zn = new WeakMap(), be = new WeakMap(), Bn = new WeakMap();
11245
11245
  let Ts = Br;
11246
11246
  var Zn, te, qn, dt, Jn;
11247
11247
  class af extends Ts {
@@ -11249,17 +11249,17 @@ class af extends Ts {
11249
11249
  if (typeof RTCPeerConnection > "u")
11250
11250
  throw new Error("WebRTC is not supported in this environment");
11251
11251
  super(t);
11252
- S(this, "options");
11253
- R(this, Zn);
11254
- R(this, te, {
11252
+ x(this, "options");
11253
+ N(this, Zn);
11254
+ N(this, te, {
11255
11255
  status: "disconnected",
11256
11256
  peerConnection: void 0,
11257
11257
  dataChannel: void 0,
11258
11258
  callId: void 0
11259
11259
  });
11260
- R(this, qn);
11261
- R(this, dt, !1);
11262
- R(this, Jn, !1);
11260
+ N(this, qn);
11261
+ N(this, dt, !1);
11262
+ N(this, Jn, !1);
11263
11263
  this.options = t, k(this, Zn, t.baseUrl ?? "https://api.openai.com/v1/realtime/calls"), k(this, qn, t.useInsecureApiKey ?? !1);
11264
11264
  }
11265
11265
  /**
@@ -11313,8 +11313,8 @@ class af extends Ts {
11313
11313
  model: this.currentModel
11314
11314
  }, m = new URL(r);
11315
11315
  let g = new RTCPeerConnection();
11316
- const _ = g.createDataChannel("oai-events");
11317
- let T;
11316
+ const v = g.createDataChannel("oai-events");
11317
+ let S;
11318
11318
  const y = (A) => {
11319
11319
  A.onconnectionstatechange = () => {
11320
11320
  switch (A.connectionState) {
@@ -11329,18 +11329,18 @@ class af extends Ts {
11329
11329
  y(g), k(this, te, {
11330
11330
  status: "connecting",
11331
11331
  peerConnection: g,
11332
- dataChannel: _,
11333
- callId: T
11334
- }), this.emit("connection_change", c(this, te).status), _.addEventListener("open", () => {
11332
+ dataChannel: v,
11333
+ callId: S
11334
+ }), this.emit("connection_change", c(this, te).status), v.addEventListener("open", () => {
11335
11335
  k(this, te, {
11336
11336
  status: "connected",
11337
11337
  peerConnection: g,
11338
- dataChannel: _,
11339
- callId: T
11338
+ dataChannel: v,
11339
+ callId: S
11340
11340
  }), this.updateSessionConfig(d), this.emit("connection_change", c(this, te).status), this._onOpen(), a();
11341
- }), _.addEventListener("error", (A) => {
11341
+ }), v.addEventListener("error", (A) => {
11342
11342
  this.close(), this._onError(A), u(A);
11343
- }), _.addEventListener("message", (A) => {
11343
+ }), v.addEventListener("message", (A) => {
11344
11344
  this._onMessage(A);
11345
11345
  const { data: D, isGeneric: U } = Ur(A);
11346
11346
  if (!(!D || U) && (D.type === "response.created" ? k(this, dt, !0) : D.type === "response.done" && k(this, dt, !1), D.type === "session.created")) {
@@ -11360,24 +11360,24 @@ class af extends Ts {
11360
11360
  const A = g;
11361
11361
  g = await this.options.changePeerConnection(g), A !== g && (A.onconnectionstatechange = null), y(g), k(this, te, { ...c(this, te), peerConnection: g });
11362
11362
  }
11363
- const v = await g.createOffer();
11364
- if (await g.setLocalDescription(v), !v.sdp)
11363
+ const _ = await g.createOffer();
11364
+ if (await g.setLocalDescription(_), !_.sdp)
11365
11365
  throw new Error("Failed to create offer");
11366
- const N = await fetch(m, {
11366
+ const R = await fetch(m, {
11367
11367
  method: "POST",
11368
- body: v.sdp,
11368
+ body: _.sdp,
11369
11369
  headers: {
11370
11370
  "Content-Type": "application/sdp",
11371
11371
  Authorization: `Bearer ${i}`,
11372
11372
  "X-OpenAI-Agents-SDK": ho["X-OpenAI-Agents-SDK"]
11373
11373
  }
11374
11374
  });
11375
- T = (p = (l = N.headers) == null ? void 0 : l.get("Location")) == null ? void 0 : p.split("/").pop(), k(this, te, { ...c(this, te), callId: T });
11376
- const x = {
11375
+ S = (p = (l = R.headers) == null ? void 0 : l.get("Location")) == null ? void 0 : p.split("/").pop(), k(this, te, { ...c(this, te), callId: S });
11376
+ const T = {
11377
11377
  type: "answer",
11378
- sdp: await N.text()
11378
+ sdp: await R.text()
11379
11379
  };
11380
- await g.setRemoteDescription(x);
11380
+ await g.setRemoteDescription(T);
11381
11381
  } catch (d) {
11382
11382
  this.close(), this._onError(d), u(d);
11383
11383
  }
@@ -11438,21 +11438,21 @@ class af extends Ts {
11438
11438
  }
11439
11439
  Zn = new WeakMap(), te = new WeakMap(), qn = new WeakMap(), dt = new WeakMap(), Jn = new WeakMap();
11440
11440
  const of = globalThis.WebSocket;
11441
- var pt, Ct, Ot, fe, Gn, Ye, Et, Rt, nn, Vn, Ut, _r, yo;
11441
+ var pt, Ot, Et, fe, Gn, Ye, Rt, Nt, nn, Vn, Lt, _r, yo;
11442
11442
  class uf extends Ts {
11443
11443
  constructor(t = {}) {
11444
11444
  super(t);
11445
- R(this, Ut);
11446
- R(this, pt);
11447
- R(this, Ct);
11448
- R(this, Ot);
11449
- R(this, fe, {
11445
+ N(this, Lt);
11446
+ N(this, pt);
11447
+ N(this, Ot);
11448
+ N(this, Et);
11449
+ N(this, fe, {
11450
11450
  status: "disconnected",
11451
11451
  websocket: void 0
11452
11452
  });
11453
- R(this, Gn);
11454
- R(this, Ye);
11455
- R(this, Et);
11453
+ N(this, Gn);
11454
+ N(this, Ye);
11455
+ N(this, Rt);
11456
11456
  /**
11457
11457
  * Timestamp maintained by the transport layer to aid with the calculation of the elapsed time
11458
11458
  * since the response started to compute the right interruption time.
@@ -11460,12 +11460,12 @@ class uf extends Ts {
11460
11460
  * Mostly internal but might be used by extended transport layers for their interruption
11461
11461
  * calculation.
11462
11462
  */
11463
- S(this, "_firstAudioTimestamp");
11464
- S(this, "_audioLengthMs", 0);
11465
- R(this, Rt, !1);
11466
- R(this, nn);
11467
- R(this, Vn);
11468
- k(this, Ct, t.url), k(this, Ot, t.url), k(this, Gn, t.useInsecureApiKey ?? !1), k(this, nn, t.createWebSocket), k(this, Vn, t.skipOpenEventListeners ?? !1);
11463
+ x(this, "_firstAudioTimestamp");
11464
+ x(this, "_audioLengthMs", 0);
11465
+ N(this, Nt, !1);
11466
+ N(this, nn);
11467
+ N(this, Vn);
11468
+ k(this, Ot, t.url), k(this, Et, t.url), k(this, Gn, t.useInsecureApiKey ?? !1), k(this, nn, t.createWebSocket), k(this, Vn, t.skipOpenEventListeners ?? !1);
11469
11469
  }
11470
11470
  getCommonRequestHeaders() {
11471
11471
  return ho;
@@ -11506,20 +11506,20 @@ class uf extends Ts {
11506
11506
  this.emit("audio", t);
11507
11507
  }
11508
11508
  _afterAudioDoneEvent() {
11509
- z(this, Ut, _r).call(this);
11509
+ z(this, Lt, _r).call(this);
11510
11510
  }
11511
11511
  async connect(t) {
11512
11512
  const s = t.model ?? this.currentModel;
11513
11513
  this.currentModel = s, k(this, pt, await this._getApiKey(t));
11514
11514
  const r = t.callId;
11515
11515
  let i;
11516
- t.url ? (i = t.url, k(this, Ot, t.url)) : r ? i = `wss://api.openai.com/v1/realtime?call_id=${r}` : c(this, Ot) ? i = c(this, Ot) : i = `wss://api.openai.com/v1/realtime?model=${this.currentModel}`, k(this, Ct, i);
11516
+ t.url ? (i = t.url, k(this, Et, t.url)) : r ? i = `wss://api.openai.com/v1/realtime?call_id=${r}` : c(this, Et) ? i = c(this, Et) : i = `wss://api.openai.com/v1/realtime?model=${this.currentModel}`, k(this, Ot, i);
11517
11517
  const o = {
11518
11518
  ...t.initialSessionConfig || {},
11519
11519
  model: this.currentModel
11520
11520
  };
11521
11521
  await new Promise((a, u) => {
11522
- z(this, Ut, yo).call(this, a, u, o).catch(u);
11522
+ z(this, Lt, yo).call(this, a, u, o).catch(u);
11523
11523
  }), await this.updateSessionConfig(o);
11524
11524
  }
11525
11525
  /**
@@ -11540,7 +11540,7 @@ class uf extends Ts {
11540
11540
  */
11541
11541
  close() {
11542
11542
  var t;
11543
- (t = c(this, fe).websocket) == null || t.close(), k(this, Ye, void 0), this._firstAudioTimestamp = void 0, this._audioLengthMs = 0, k(this, Et, void 0);
11543
+ (t = c(this, fe).websocket) == null || t.close(), k(this, Ye, void 0), this._firstAudioTimestamp = void 0, this._audioLengthMs = 0, k(this, Rt, void 0);
11544
11544
  }
11545
11545
  /**
11546
11546
  * Will throw an error as the WebSocket transport layer does not support muting.
@@ -11563,9 +11563,9 @@ class uf extends Ts {
11563
11563
  * response that the model is currently generating.
11564
11564
  */
11565
11565
  _cancelResponse() {
11566
- c(this, Rt) && (this.sendEvent({
11566
+ c(this, Nt) && (this.sendEvent({
11567
11567
  type: "response.cancel"
11568
- }), k(this, Rt, !1));
11568
+ }), k(this, Nt, !1));
11569
11569
  }
11570
11570
  /**
11571
11571
  * Do NOT call this method directly. Call `interrupt()` instead for proper interruption handling.
@@ -11584,7 +11584,7 @@ class uf extends Ts {
11584
11584
  this.emit("audio_interrupted"), this.sendEvent({
11585
11585
  type: "conversation.item.truncate",
11586
11586
  item_id: c(this, Ye),
11587
- content_index: c(this, Et),
11587
+ content_index: c(this, Rt),
11588
11588
  audio_end_ms: i
11589
11589
  });
11590
11590
  }
@@ -11600,11 +11600,11 @@ class uf extends Ts {
11600
11600
  if (!c(this, Ye) || typeof this._firstAudioTimestamp != "number")
11601
11601
  return;
11602
11602
  const s = Date.now() - this._firstAudioTimestamp;
11603
- s >= 0 && this._interrupt(s, t), z(this, Ut, _r).call(this);
11603
+ s >= 0 && this._interrupt(s, t), z(this, Lt, _r).call(this);
11604
11604
  }
11605
11605
  }
11606
- pt = new WeakMap(), Ct = new WeakMap(), Ot = new WeakMap(), fe = new WeakMap(), Gn = new WeakMap(), Ye = new WeakMap(), Et = new WeakMap(), Rt = new WeakMap(), nn = new WeakMap(), Vn = new WeakMap(), Ut = new WeakSet(), _r = function() {
11607
- k(this, Ye, void 0), this._firstAudioTimestamp = void 0, this._audioLengthMs = 0, k(this, Et, void 0);
11606
+ pt = new WeakMap(), Ot = new WeakMap(), Et = new WeakMap(), fe = new WeakMap(), Gn = new WeakMap(), Ye = new WeakMap(), Rt = new WeakMap(), Nt = new WeakMap(), nn = new WeakMap(), Vn = new WeakMap(), Lt = new WeakSet(), _r = function() {
11607
+ k(this, Ye, void 0), this._firstAudioTimestamp = void 0, this._audioLengthMs = 0, k(this, Rt, void 0);
11608
11608
  }, yo = async function(t, s, r) {
11609
11609
  if (c(this, fe).websocket) {
11610
11610
  t();
@@ -11617,7 +11617,7 @@ pt = new WeakMap(), Ct = new WeakMap(), Ot = new WeakMap(), fe = new WeakMap(),
11617
11617
  let i = null;
11618
11618
  if (c(this, nn))
11619
11619
  i = await c(this, nn).call(this, {
11620
- url: c(this, Ct),
11620
+ url: c(this, Ot),
11621
11621
  apiKey: c(this, pt)
11622
11622
  });
11623
11623
  else {
@@ -11628,7 +11628,7 @@ pt = new WeakMap(), Ct = new WeakMap(), Ot = new WeakMap(), fe = new WeakMap(),
11628
11628
  // Version header
11629
11629
  Kd
11630
11630
  ];
11631
- i = new of(c(this, Ct), a);
11631
+ i = new of(c(this, Ot), a);
11632
11632
  }
11633
11633
  k(this, fe, {
11634
11634
  status: "connecting",
@@ -11646,36 +11646,36 @@ pt = new WeakMap(), Ct = new WeakMap(), Ot = new WeakMap(), fe = new WeakMap(),
11646
11646
  websocket: void 0
11647
11647
  }), this.emit("connection_change", c(this, fe).status), s(a);
11648
11648
  }), i.addEventListener("message", (a) => {
11649
- var p, d, m, g, _, T, y;
11649
+ var p, d, m, g, v, S, y;
11650
11650
  this._onMessage(a);
11651
11651
  const { data: u, isGeneric: l } = Ur(a);
11652
11652
  if (!(!u || l)) {
11653
11653
  if (u.type === "response.output_audio.delta") {
11654
- k(this, Et, u.content_index), k(this, Ye, u.item_id), this._firstAudioTimestamp === void 0 && (this._firstAudioTimestamp = Date.now(), this._audioLengthMs = 0);
11654
+ k(this, Rt, u.content_index), k(this, Ye, u.item_id), this._firstAudioTimestamp === void 0 && (this._firstAudioTimestamp = Date.now(), this._audioLengthMs = 0);
11655
11655
  const h = qd(u.delta), w = (m = (d = (p = this._rawSessionConfig) == null ? void 0 : p.audio) == null ? void 0 : d.output) == null ? void 0 : m.format;
11656
11656
  if (w && typeof w == "object") {
11657
- const N = w.type;
11658
- if (N === "audio/pcmu" || N === "audio/pcma")
11657
+ const R = w.type;
11658
+ if (R === "audio/pcmu" || R === "audio/pcma")
11659
11659
  this._audioLengthMs += h.byteLength / 8;
11660
- else if (N === "audio/pcm") {
11661
- const x = w.rate ?? 24e3;
11662
- this._audioLengthMs += h.byteLength / 2 / x * 1e3;
11660
+ else if (R === "audio/pcm") {
11661
+ const T = w.rate ?? 24e3;
11662
+ this._audioLengthMs += h.byteLength / 2 / T * 1e3;
11663
11663
  } else
11664
11664
  this._audioLengthMs += h.byteLength / 24 / 2;
11665
11665
  } else typeof w == "string" ? w.startsWith("g711_") ? this._audioLengthMs += h.byteLength / 8 : this._audioLengthMs += h.byteLength / 24 / 2 : this._audioLengthMs += h.byteLength / 24 / 2;
11666
- const v = {
11666
+ const _ = {
11667
11667
  type: "audio",
11668
11668
  data: h,
11669
11669
  responseId: u.response_id
11670
11670
  };
11671
- this._onAudio(v);
11671
+ this._onAudio(_);
11672
11672
  } else if (u.type === "input_audio_buffer.speech_started") {
11673
- const h = ((y = (T = (_ = (g = this._rawSessionConfig) == null ? void 0 : g.audio) == null ? void 0 : _.input) == null ? void 0 : T.turn_detection) == null ? void 0 : y.interrupt_response) ?? !1;
11673
+ const h = ((y = (S = (v = (g = this._rawSessionConfig) == null ? void 0 : g.audio) == null ? void 0 : v.input) == null ? void 0 : S.turn_detection) == null ? void 0 : y.interrupt_response) ?? !1;
11674
11674
  this.interrupt(!h);
11675
11675
  } else if (u.type === "response.created")
11676
- k(this, Rt, !0);
11676
+ k(this, Nt, !0);
11677
11677
  else if (u.type === "response.done")
11678
- k(this, Rt, !1);
11678
+ k(this, Nt, !1);
11679
11679
  else if (u.type === "session.created") {
11680
11680
  this._tracingConfig = u.session.tracing;
11681
11681
  const h = typeof r.tracing > "u" ? "auto" : r.tracing;
@@ -11715,37 +11715,37 @@ function pf(n) {
11715
11715
  function ff() {
11716
11716
  return JSON.parse(JSON.stringify(De));
11717
11717
  }
11718
- var H, B, sn, Z, rn, an, Hn, ae, on, un, Fe, Wn, Nt, Kn, Yn, re, vn, bn, _o, as, vo, br, bo, wr;
11718
+ var H, B, sn, Z, rn, an, Hn, ae, on, un, Fe, Wn, Pt, Kn, Yn, re, vn, bn, _o, as, vo, br, bo, wr;
11719
11719
  const Zr = class Zr extends Cs {
11720
11720
  constructor(t, s = {}) {
11721
11721
  super();
11722
- R(this, re);
11723
- S(this, "initialAgent");
11724
- S(this, "options");
11725
- R(this, H);
11726
- R(this, B);
11727
- R(this, sn);
11728
- R(this, Z);
11729
- R(this, rn, []);
11730
- R(this, an);
11731
- R(this, Hn, {});
11732
- R(this, ae, []);
11733
- R(this, on);
11734
- R(this, un, {});
11735
- R(this, Fe, !1);
11722
+ N(this, re);
11723
+ x(this, "initialAgent");
11724
+ x(this, "options");
11725
+ N(this, H);
11726
+ N(this, B);
11727
+ N(this, sn);
11728
+ N(this, Z);
11729
+ N(this, rn, []);
11730
+ N(this, an);
11731
+ N(this, Hn, {});
11732
+ N(this, ae, []);
11733
+ N(this, on);
11734
+ N(this, un, {});
11735
+ N(this, Fe, !1);
11736
11736
  // Tracks all MCP tools fetched per server label (from mcp_list_tools results).
11737
- R(this, Wn, /* @__PURE__ */ new Map());
11737
+ N(this, Wn, /* @__PURE__ */ new Map());
11738
11738
  // Tracks currently available MCP tools based on the active agent's configured server_labels.
11739
- R(this, Nt, []);
11739
+ N(this, Pt, []);
11740
11740
  // Keeps track of the last full session config we sent (camelCase keys) so that
11741
11741
  // subsequent updates (e.g. during agent handoffs) preserve properties that are
11742
11742
  // not explicitly recalculated here (such as inputAudioFormat, outputAudioFormat,
11743
11743
  // modalities, speed, toolChoice, turnDetection, etc.). Without this, updating
11744
11744
  // the agent would drop audio format overrides (e.g. g711_ulaw) and revert to
11745
11745
  // transport defaults causing issues for integrations like Twilio.
11746
- R(this, Kn, ff());
11747
- R(this, Yn, !0);
11748
- this.initialAgent = t, this.options = s, typeof s.transport > "u" && Hd() || s.transport === "webrtc" ? k(this, H, new af()) : s.transport === "websocket" || typeof s.transport > "u" ? k(this, H, new uf()) : k(this, H, s.transport), k(this, B, t), k(this, Z, new Zt({
11746
+ N(this, Kn, ff());
11747
+ N(this, Yn, !0);
11748
+ this.initialAgent = t, this.options = s, typeof s.transport > "u" && Hd() || s.transport === "webrtc" ? k(this, H, new af()) : s.transport === "websocket" || typeof s.transport > "u" ? k(this, H, new uf()) : k(this, H, s.transport), k(this, B, t), k(this, Z, new qt({
11749
11749
  ...s.context ?? {},
11750
11750
  history: c(this, ae)
11751
11751
  })), k(this, rn, (s.outputGuardrails ?? []).map(ep)), k(this, an, Qd(s.outputGuardrailSettings ?? {})), k(this, on, s.historyStoreAudio ?? !1), k(this, Yn, s.automaticallyTriggerResponseForMcpToolCalls ?? !0);
@@ -11788,7 +11788,7 @@ const Zr = class Zr extends Cs {
11788
11788
  return c(this, ae);
11789
11789
  }
11790
11790
  get availableMcpTools() {
11791
- return c(this, Nt);
11791
+ return c(this, Pt);
11792
11792
  }
11793
11793
  /**
11794
11794
  * Compute the initial session config that the current session will use when connecting.
@@ -11935,15 +11935,15 @@ const Zr = class Zr extends Cs {
11935
11935
  throw new we(`Tool ${r ?? "unknown"} not found`);
11936
11936
  }
11937
11937
  };
11938
- H = new WeakMap(), B = new WeakMap(), sn = new WeakMap(), Z = new WeakMap(), rn = new WeakMap(), an = new WeakMap(), Hn = new WeakMap(), ae = new WeakMap(), on = new WeakMap(), un = new WeakMap(), Fe = new WeakMap(), Wn = new WeakMap(), Nt = new WeakMap(), Kn = new WeakMap(), Yn = new WeakMap(), re = new WeakSet(), vn = async function(t) {
11938
+ H = new WeakMap(), B = new WeakMap(), sn = new WeakMap(), Z = new WeakMap(), rn = new WeakMap(), an = new WeakMap(), Hn = new WeakMap(), ae = new WeakMap(), on = new WeakMap(), un = new WeakMap(), Fe = new WeakMap(), Wn = new WeakMap(), Pt = new WeakMap(), Kn = new WeakMap(), Yn = new WeakMap(), re = new WeakSet(), vn = async function(t) {
11939
11939
  k(this, B, t);
11940
11940
  const s = await c(this, B).getEnabledHandoffs(c(this, Z)), r = s.map((u) => u.getHandoffAsFunctionTool()), i = (await c(this, B).getAllTools(c(this, Z))).filter(df).map(pf), o = typeof c(this, B).tools < "u" || typeof c(this, B).mcpServers < "u", a = s.length > 0;
11941
11941
  k(this, sn, o || a ? [...i, ...r] : void 0), z(this, re, wr).call(this);
11942
11942
  }, bn = async function(t = {}) {
11943
11943
  const s = t ?? {}, r = this.options.config ?? {}, i = await c(this, B).getSystemPrompt(c(this, Z)), o = (g) => {
11944
- var T;
11945
- const _ = g.audio;
11946
- return (T = _ == null ? void 0 : _.output) == null ? void 0 : T.voice;
11944
+ var S;
11945
+ const v = g.audio;
11946
+ return (S = v == null ? void 0 : v.output) == null ? void 0 : S.voice;
11947
11947
  }, a = this.options.tracingDisabled ? null : this.options.workflowName ? {
11948
11948
  workflow_name: this.options.workflowName
11949
11949
  } : "auto";
@@ -11970,7 +11970,7 @@ H = new WeakMap(), B = new WeakMap(), sn = new WeakMap(), Z = new WeakMap(), rn
11970
11970
  }, as = async function(t, s) {
11971
11971
  c(this, Z).context.history = JSON.parse(JSON.stringify(c(this, ae)));
11972
11972
  let r = t.arguments;
11973
- if (s.parameters && (jt(s.parameters) ? r = s.parameters.parse(r) : r = JSON.parse(r)), await s.needsApproval(c(this, Z), r, t.callId)) {
11973
+ if (s.parameters && (Ut(s.parameters) ? r = s.parameters.parse(r) : r = JSON.parse(r)), await s.needsApproval(c(this, Z), r, t.callId)) {
11974
11974
  const u = this.context.isToolApproved({
11975
11975
  toolName: s.name,
11976
11976
  callId: t.callId
@@ -12149,8 +12149,8 @@ wr = function() {
12149
12149
  for (const m of p)
12150
12150
  d && !d.includes(m.name) || r.has(m.name) || r.set(m.name, m);
12151
12151
  }
12152
- const i = Array.from(r.values()), o = c(this, Nt);
12153
- (o.length !== i.length || JSON.stringify(o.map((l) => l.name).sort()) !== JSON.stringify(i.map((l) => l.name).sort())) && (k(this, Nt, i), this.emit("mcp_tools_changed", c(this, Nt)));
12152
+ const i = Array.from(r.values()), o = c(this, Pt);
12153
+ (o.length !== i.length || JSON.stringify(o.map((l) => l.name).sort()) !== JSON.stringify(i.map((l) => l.name).sort())) && (k(this, Pt, i), this.emit("mcp_tools_changed", c(this, Pt)));
12154
12154
  };
12155
12155
  let vr = Zr;
12156
12156
  class hf {
@@ -12237,7 +12237,7 @@ class wf extends hf {
12237
12237
  throw new Error("BabelbeezClient: publicChatbotId is required.");
12238
12238
  this.publicChatbotId = e.publicChatbotId;
12239
12239
  const t = e.proxyInitializeUrl || _f;
12240
- this.proxyInitializeUrl = t, this.apiBaseUrl = e.apiBaseUrl || new URL(t).origin, this.agent = null, this.session = null, this.currentSystemSettings = null, this.currentChatbotSettings = null, this.currentSessionId = null, this.currentRagSearchUrl = null, this.sessionStartTime = null, this.accumulatedUsage = null, this.hasEndConversationBeenHandled = !1, this.isTerminating = !1, this.isUserSpeaking = !1, this.isAssistantSpeaking = !1, this.isHandoffFormOpen = !1, this.inactivityStage = 0, this.inactivityStage1TimeoutId = null, this.inactivityStage2TimeoutId = null, this.shouldScheduleStage2OnNextAssistantSilence = !1, this.pendingGoodbyeResolve = null, this.handoffPromiseResolve = null, this.currentHandoffSummaryText = null, this.heartbeatIntervalId = null, this.heartbeatFrequencySeconds = null, this._lastInitData = null, this._lastAssistantMessageId = null, this._lastAssistantTranscript = "", this._currentAssistantTranscript = "", this._currentUserTranscript = "";
12240
+ this.proxyInitializeUrl = t, this.apiBaseUrl = e.apiBaseUrl || new URL(t).origin, this.agent = null, this.session = null, this.currentSystemSettings = null, this.currentChatbotSettings = null, this.currentSessionId = null, this.currentRagSearchUrl = null, this.sessionStartTime = null, this.accumulatedUsage = null, this.hasEndConversationBeenHandled = !1, this.isTerminating = !1, this.sessionEntities = {}, this.isUserSpeaking = !1, this.isAssistantSpeaking = !1, this.isHandoffFormOpen = !1, this.inactivityStage = 0, this.inactivityStage1TimeoutId = null, this.inactivityStage2TimeoutId = null, this.shouldScheduleStage2OnNextAssistantSilence = !1, this.pendingGoodbyeResolve = null, this.handoffPromiseResolve = null, this.currentHandoffSummaryText = null, this.heartbeatIntervalId = null, this.heartbeatFrequencySeconds = null, this._lastInitData = null, this._lastAssistantMessageId = null, this._lastAssistantTranscript = "", this._currentAssistantTranscript = "", this._currentUserTranscript = "";
12241
12241
  }
12242
12242
  // --- Public API ---
12243
12243
  /**
@@ -12258,7 +12258,7 @@ class wf extends hf {
12258
12258
  session_id: i,
12259
12259
  heartbeat_frequency_seconds: o
12260
12260
  } = e;
12261
- this.currentSystemSettings = s, this.currentChatbotSettings = r, this.currentSessionId = i, this.heartbeatFrequencySeconds = o, this.currentRagSearchUrl = `${this.apiBaseUrl}/api/perform-rag-search`, $("DEBUG", "BabelbeezClient: using RAG search URL", this.currentRagSearchUrl), this._resetAccumulatedUsage(), this._resetInactivityState(), this.isUserSpeaking = !1, this.isAssistantSpeaking = !1, this.isTerminating = !1, this.hasEndConversationBeenHandled = !1;
12261
+ this.currentSystemSettings = s, this.currentChatbotSettings = r, this.currentSessionId = i, this.heartbeatFrequencySeconds = o, this.currentRagSearchUrl = `${this.apiBaseUrl}/api/perform-rag-search`, $("DEBUG", "BabelbeezClient: using RAG search URL", this.currentRagSearchUrl), this._resetAccumulatedUsage(), this._resetInactivityState(), this.isUserSpeaking = !1, this.isAssistantSpeaking = !1, this.isTerminating = !1, this.hasEndConversationBeenHandled = !1, this.sessionEntities = {};
12262
12262
  try {
12263
12263
  this.emit("buttonState", "loading"), this.agent = this._createVoiceAgent(), this.session = this._createVoiceSession(s, r), await this.session.connect({ apiKey: t }), this._attachTransportListeners(), this.sessionStartTime = Date.now(), this.emit("buttonState", "active"), this.emit("session:start", {
12264
12264
  chatbotId: this.publicChatbotId,
@@ -12552,77 +12552,77 @@ class wf extends hf {
12552
12552
  await Promise.race([s, i]), this.pendingGoodbyeResolve = null, this._setSessionMuted(!1, "goodbye"), await this._finalizeSession(e);
12553
12553
  }
12554
12554
  _createVoiceAgent() {
12555
- var a, u, l, p;
12556
- const e = (a = this.currentSystemSettings) != null && a.system_prompt ? `${this.currentSystemSettings.system_prompt}
12555
+ var p, d, m, g, v;
12556
+ const e = (p = this.currentSystemSettings) != null && p.system_prompt ? `${this.currentSystemSettings.system_prompt}
12557
12557
 
12558
- ${((u = this.currentChatbotSettings) == null ? void 0 : u.instructions) || ""}`.trim() : ((l = this.currentChatbotSettings) == null ? void 0 : l.instructions) || "", t = this, s = Gt({
12558
+ ${((d = this.currentChatbotSettings) == null ? void 0 : d.instructions) || ""}`.trim() : ((m = this.currentChatbotSettings) == null ? void 0 : m.instructions) || "", t = this, s = wt({
12559
12559
  name: "perform_rag_search",
12560
- description: ((p = this.currentSystemSettings) == null ? void 0 : p.rag_search_description) || "Searches the knowledge base for relevant context.",
12560
+ description: ((g = this.currentSystemSettings) == null ? void 0 : g.rag_search_description) || "Searches the knowledge base for relevant context.",
12561
12561
  parameters: b({
12562
12562
  query: f()
12563
12563
  }),
12564
- async execute({ query: d }) {
12565
- if ($("INFO", `Tool perform_rag_search called with query: "${d}"`), t._resetInactivityState(), !t.currentRagSearchUrl || !t.publicChatbotId)
12564
+ async execute({ query: S }) {
12565
+ if ($("INFO", `Tool perform_rag_search called with query: "${S}"`), t._resetInactivityState(), !t.currentRagSearchUrl || !t.publicChatbotId)
12566
12566
  return $(
12567
12567
  "ERROR",
12568
12568
  "RAG search URL or publicChatbotId not configured; returning fallback context."
12569
12569
  ), "Knowledge search is temporarily unavailable.";
12570
- const m = t.isAssistantSpeaking;
12570
+ const y = t.isAssistantSpeaking;
12571
12571
  t.isAssistantSpeaking = !0, t.emit("buttonState", "rag-retrieval");
12572
12572
  try {
12573
- const g = await fetch(t.currentRagSearchUrl, {
12573
+ const h = await fetch(t.currentRagSearchUrl, {
12574
12574
  method: "POST",
12575
12575
  headers: { "Content-Type": "application/json" },
12576
- body: JSON.stringify({ query: d, public_chatbot_id: t.publicChatbotId })
12576
+ body: JSON.stringify({ query: S, public_chatbot_id: t.publicChatbotId })
12577
12577
  });
12578
- if (!g.ok) {
12579
- let y = `RAG search failed: ${g.status} ${g.statusText}`;
12578
+ if (!h.ok) {
12579
+ let R = `RAG search failed: ${h.status} ${h.statusText}`;
12580
12580
  try {
12581
- const h = await g.json();
12582
- h && h.detail && (y = h.detail);
12581
+ const T = await h.json();
12582
+ T && T.detail && (R = T.detail);
12583
12583
  } catch {
12584
12584
  }
12585
- return $("ERROR", y), "Knowledge search failed; please answer based on your existing knowledge.";
12585
+ return $("ERROR", R), "Knowledge search failed; please answer based on your existing knowledge.";
12586
12586
  }
12587
- const T = (await g.json()).context || "";
12588
- return $("INFO", `RAG search succeeded. Context length: ${T.length}`), T || "No additional knowledge was found.";
12589
- } catch (g) {
12590
- return $("ERROR", "Network or unexpected error during RAG search.", g), "Knowledge search failed due to a network error.";
12587
+ const _ = (await h.json()).context || "";
12588
+ return $("INFO", `RAG search succeeded. Context length: ${_.length}`), _ || "No additional knowledge was found.";
12589
+ } catch (h) {
12590
+ return $("ERROR", "Network or unexpected error during RAG search.", h), "Knowledge search failed due to a network error.";
12591
12591
  } finally {
12592
- t.isAssistantSpeaking = m, t.emit("buttonState", "active");
12592
+ t.isAssistantSpeaking = y, t.emit("buttonState", "active");
12593
12593
  }
12594
12594
  }
12595
- }), r = Gt({
12595
+ }), r = wt({
12596
12596
  name: "request_human_handoff",
12597
12597
  description: "Escalate to a human staff member via contact form. Provide a concise summary_text.",
12598
12598
  parameters: b({
12599
12599
  summary_text: f(),
12600
12600
  announcement: f()
12601
12601
  }),
12602
- async execute({ summary_text: d, announcement: m }) {
12603
- var y;
12602
+ async execute({ summary_text: S, announcement: y }) {
12603
+ var R;
12604
12604
  $("INFO", "Tool request_human_handoff called."), t._resetInactivityState();
12605
- const g = m || "Please fill out the form so that I can connect you to a staff member to follow up";
12605
+ const h = y || "Please fill out the form so that I can connect you to a staff member to follow up";
12606
12606
  try {
12607
- t.session && await t.session.sendMessage(g);
12608
- } catch (h) {
12609
- $("WARN", "Failed to send handoff announcement message.", h);
12607
+ t.session && await t.session.sendMessage(h);
12608
+ } catch (T) {
12609
+ $("WARN", "Failed to send handoff announcement message.", T);
12610
12610
  }
12611
12611
  t.isHandoffFormOpen = !0, t._setSessionMuted(!0, "handoff_form");
12612
- let _ = null;
12613
- const T = (y = t.currentChatbotSettings) == null ? void 0 : y.handoff_whatsapp_number;
12614
- if (T) {
12615
- const h = String(T).replace(/\D+/g, "");
12616
- h && (_ = `https://wa.me/${h}?text=${encodeURIComponent(d || "Summary not available.")}`);
12612
+ let w = null;
12613
+ const _ = (R = t.currentChatbotSettings) == null ? void 0 : R.handoff_whatsapp_number;
12614
+ if (_) {
12615
+ const T = String(_).replace(/\D+/g, "");
12616
+ T && (w = `https://wa.me/${T}?text=${encodeURIComponent(S || "Summary not available.")}`);
12617
12617
  }
12618
- return t.currentHandoffSummaryText = d || "Summary not available.", t.emit("handoff:show", {
12618
+ return t.currentHandoffSummaryText = S || "Summary not available.", t.emit("handoff:show", {
12619
12619
  summaryText: t.currentHandoffSummaryText,
12620
- waLink: _
12621
- }), await new Promise((h) => {
12622
- t.handoffPromiseResolve = h;
12623
- }).then((h) => h === "whatsapp_submitted" ? "User chose WhatsApp handoff." : h === "email_submitted" ? "Handoff request submitted successfully." : "Handoff flow completed or cancelled by the user.");
12620
+ waLink: w
12621
+ }), await new Promise((T) => {
12622
+ t.handoffPromiseResolve = T;
12623
+ }).then((T) => T === "whatsapp_submitted" ? "User chose WhatsApp handoff." : T === "email_submitted" ? "Handoff request submitted successfully." : "Handoff flow completed or cancelled by the user.");
12624
12624
  }
12625
- }), i = Gt({
12625
+ }), i = wt({
12626
12626
  name: "end_conversation",
12627
12627
  description: "End the conversation when the user clearly wants to stop. The model should call this tool instead of saying goodbye itself.",
12628
12628
  parameters: b({}),
@@ -12630,21 +12630,29 @@ ${((u = this.currentChatbotSettings) == null ? void 0 : u.instructions) || ""}`.
12630
12630
  return $("INFO", "Tool end_conversation called by AI."), t._resetInactivityState(), t.hasEndConversationBeenHandled ? ($("DEBUG", "end_conversation already handled; ignoring subsequent call."), "Conversation is already ending.") : (t.hasEndConversationBeenHandled = !0, (async () => {
12631
12631
  try {
12632
12632
  t.session && (await t.session.interrupt(), $("INFO", "Session interrupted by AI end_conversation before goodbye."));
12633
- } catch (d) {
12633
+ } catch (S) {
12634
12634
  $(
12635
12635
  "WARN",
12636
12636
  "Error interrupting session during AI end_conversation; proceeding anyway.",
12637
- d
12637
+ S
12638
12638
  );
12639
12639
  }
12640
12640
  await t._playGoodbyeThenFinalize("ai_end_conversation_tool");
12641
12641
  })(), "Conversation ended.");
12642
12642
  }
12643
- });
12644
- return new Xd({
12643
+ }), o = wt({
12644
+ name: "update_session_entities",
12645
+ description: "Silently update structured user information (e.g. email, name, appointment time).",
12646
+ parameters: b({}).passthrough(),
12647
+ // accept any key:value pairs
12648
+ async execute(S) {
12649
+ return $("INFO", "Tool update_session_entities called", S), t.sessionEntities = { ...t.sessionEntities, ...S }, t.emit("entities:updated", { entities: t.sessionEntities }), "Information updated.";
12650
+ }
12651
+ }), a = [s, r, i], u = (v = this.currentChatbotSettings) == null ? void 0 : v.monitored_entities;
12652
+ return Array.isArray(u) && u.length > 0 && a.push(o), new Xd({
12645
12653
  name: "Assistant",
12646
12654
  instructions: e,
12647
- tools: [s, r, i]
12655
+ tools: a
12648
12656
  });
12649
12657
  }
12650
12658
  _createVoiceSession(e, t) {
@@ -12816,10 +12824,15 @@ ${((u = this.currentChatbotSettings) == null ? void 0 : u.instructions) || ""}`.
12816
12824
  $("DEBUG", "BabelbeezClient: Sending heartbeat", {
12817
12825
  session_id: this.currentSessionId,
12818
12826
  heartbeatUrl: e
12819
- }), (await fetch(e, {
12827
+ });
12828
+ const t = {
12829
+ session_id: this.currentSessionId,
12830
+ extracted_data: this.sessionEntities && Object.keys(this.sessionEntities).length ? this.sessionEntities : void 0
12831
+ };
12832
+ (await fetch(e, {
12820
12833
  method: "POST",
12821
12834
  headers: { "Content-Type": "application/json" },
12822
- body: JSON.stringify({ session_id: this.currentSessionId })
12835
+ body: JSON.stringify(t)
12823
12836
  })).ok;
12824
12837
  } catch (e) {
12825
12838
  $("ERROR", "BabelbeezClient: Error sending heartbeat.", e);
@@ -12849,7 +12862,8 @@ ${((u = this.currentChatbotSettings) == null ? void 0 : u.instructions) || ""}`.
12849
12862
  session_id: this.currentSessionId,
12850
12863
  token_usage: s.usage || void 0,
12851
12864
  raw_history: s.raw_history || void 0,
12852
- client_reason: s.client_reason || void 0
12865
+ client_reason: s.client_reason || void 0,
12866
+ extracted_data: this.sessionEntities && Object.keys(this.sessionEntities).length ? this.sessionEntities : void 0
12853
12867
  };
12854
12868
  $("DEBUG", "BabelbeezClient: Sending /end-chat beacon", {
12855
12869
  ...i,
@@ -12869,7 +12883,7 @@ ${((u = this.currentChatbotSettings) == null ? void 0 : u.instructions) || ""}`.
12869
12883
  } catch (r) {
12870
12884
  $("WARN", "BabelbeezClient: Error closing RealtimeSession.", r);
12871
12885
  }
12872
- this.session = null, this.agent = null, this.currentSystemSettings = null, this.currentChatbotSettings = null, this.currentSessionId = null, this.currentRagSearchUrl = null, this.sessionStartTime = null, this._resetInactivityState(), this.isUserSpeaking = !1, this.isAssistantSpeaking = !1, this._resetAccumulatedUsage(), this.hasEndConversationBeenHandled = !1, this.isTerminating = !1;
12886
+ this.session = null, this.agent = null, this.currentSystemSettings = null, this.currentChatbotSettings = null, this.currentSessionId = null, this.currentRagSearchUrl = null, this.sessionStartTime = null, this._resetInactivityState(), this.isUserSpeaking = !1, this.isAssistantSpeaking = !1, this._resetAccumulatedUsage(), this.hasEndConversationBeenHandled = !1, this.sessionEntities = {}, this.isTerminating = !1;
12873
12887
  }
12874
12888
  }
12875
12889
  export {