@ghuri/ai-widget 0.3.2 → 0.4.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.
package/README.md CHANGED
@@ -78,7 +78,7 @@ chat.configure({
78
78
  return { ref: f.id, name: f.name, contentType: f.contentType, size: f.size, width: f.width, height: f.height,
79
79
  thumbnailUrl: new URL(f.url, location.origin).href }
80
80
  },
81
- attachments: { maxCount: 10, maxBytes: 5 * 1024 * 1024 }, // defaults; also accept, maxEdge (2048)
81
+ attachments: { maxCount: 10, maxBytes: 5 * 1024 * 1024 }, // defaults; also accept, maxEdge (2048), targetBytes
82
82
  // Optional: a photo uploaded but not sent (chip removed, draft left behind). Delete it if your upload created it.
83
83
  discardFile: async ({ ref }) => { /* delete ref from your library if this upload created it */ },
84
84
  })
@@ -89,7 +89,9 @@ The photo button appears only after Ghuri AI says the app's profile takes photos
89
89
  the widget opens), and in an opened conversation only if it was started with photos; the profile's types and count
90
90
  cap yours. If Ghuri AI still refuses the photos, nothing is sent, the words go back into the box and the widget says
91
91
  why (`photos-refused`). Before uploading, each photo is scaled so its longest edge is at most 2,048 px and re-encoded, which drops its
92
- metadata (the phone's location); GIFs are sent as they are. Send waits until every photo is uploaded, and while a failed
92
+ metadata (the phone's location); GIFs are sent as they are. When the profile lets the assistant see photos (`vision` in `GET /v1/capabilities`), photos
93
+ are scaled to 1,568 px instead and kept under 1 MB (`targetBytes`): a larger one (a PNG screenshot is often 1-2.5 MB)
94
+ is re-encoded as JPEG, or as WebP when it has transparent pixels (kept as it is where the browser cannot encode WebP). Send waits until every photo is uploaded, and while a failed
93
95
  upload can still be retried (retry or remove it first). The first message of a new conversation tells Ghuri AI this client can upload
94
96
  (`capabilities.attachments`), and Ghuri AI pins that on the conversation. Photos also need the product's profile to
95
97
  allow them (`attachments.enabled`), and `thumbnailUrl` must be on the profile's MCP host or one listed in
@@ -8,6 +8,14 @@ export declare const ATTACHMENT_DEFAULTS: {
8
8
  readonly maxBytes: number;
9
9
  readonly maxEdge: 2048;
10
10
  };
11
+ /**
12
+ * When the app's assistant sees photos (`vision` in `GET /v1/capabilities`): Ghuri AI shows the model pictures of at
13
+ * most 1,600 px and 1.5 MB, so photos are scaled to Claude's standard 1,568 px and kept under 1 MB.
14
+ */
15
+ export declare const VISION_DEFAULTS: {
16
+ readonly maxEdge: 1568;
17
+ readonly targetBytes: 1000000;
18
+ };
11
19
  /** What the user is told about a failed request. */
12
20
  export declare function problemFor(err: unknown): Problem;
13
21
  export declare class ChatClient {
@@ -67,6 +75,7 @@ export declare class ChatClient {
67
75
  maxCount: number;
68
76
  maxBytes: number;
69
77
  maxEdge: number;
78
+ targetBytes?: number;
70
79
  };
71
80
  /** A photo that failed to upload and can be retried: sending would silently leave it out. */
72
81
  private retryable;
@@ -1,4 +1,10 @@
1
1
  import type { PreparedImage } from './types';
2
+ type Canvas = OffscreenCanvas | HTMLCanvasElement;
3
+ /**
4
+ * The file name for a picture of `contentType`: "homepage.png" re-encoded as JPEG becomes "homepage.jpg". A name whose
5
+ * extension already fits is kept; one without a picture extension gets one added.
6
+ */
7
+ export declare function nameFor(name: string, contentType: string): string;
2
8
  /** The size to draw at: the longest edge at most `maxEdge`, never enlarged. */
3
9
  export declare function scaledSize(width: number, height: number, maxEdge: number): {
4
10
  width: number;
@@ -7,4 +13,8 @@ export declare function scaledSize(width: number, height: number, maxEdge: numbe
7
13
  export declare function prepareImage(file: Blob, opts: {
8
14
  maxEdge: number;
9
15
  contentType: string;
16
+ targetBytes?: number;
10
17
  }): Promise<PreparedImage>;
18
+ /** Does the drawn picture have no transparent pixels? Unknown counts as transparent (keeps it safe). */
19
+ export declare function isOpaque(canvas: Canvas): boolean;
20
+ export {};
@@ -35,6 +35,7 @@ export interface ChatClientOptions {
35
35
  prepareImage?: (file: Blob, opts: {
36
36
  maxEdge: number;
37
37
  contentType: string;
38
+ targetBytes?: number;
38
39
  }) => Promise<PreparedImage>;
39
40
  /** Defaults to the global `fetch`. */
40
41
  fetch?: typeof fetch;
@@ -73,14 +74,22 @@ export interface AttachmentOptions {
73
74
  maxCount?: number;
74
75
  /** Largest file after scaling, in bytes (default 5 MB). */
75
76
  maxBytes?: number;
76
- /** Longest edge after scaling, in pixels (default 2048). */
77
+ /** Longest edge after scaling, in pixels (default 2048; 1568 when the assistant sees photos). */
77
78
  maxEdge?: number;
79
+ /**
80
+ * A photo larger than this after scaling is re-encoded smaller: as JPEG when it has no transparent pixels, as WebP
81
+ * when it has (where the browser can encode WebP). Default: none; 1,000,000 when the assistant sees photos
82
+ * (Ghuri AI shows the model pictures of at most 1.5 MB, and a screenshot as PNG is often more).
83
+ */
84
+ targetBytes?: number;
78
85
  }
79
86
  /** What the app's active profile allows for photos (Ghuri AI's `GET /v1/capabilities`). */
80
87
  export interface AttachmentPolicy {
81
88
  enabled: boolean;
82
89
  accept?: string[];
83
90
  maxCount?: number;
91
+ /** The assistant also sees the photos (Ghuri AI `attachments.vision`). */
92
+ vision?: boolean;
84
93
  }
85
94
  export interface PreparedImage {
86
95
  blob: Blob;
@@ -147,8 +147,19 @@ function l(e, t = [], n = /* @__PURE__ */ new Map()) {
147
147
  return r.filter((e) => e.parts.length > 0);
148
148
  }
149
149
  // src/core/prepare.ts
150
- var u = .85;
151
- function d(e, t, n) {
150
+ var u = .85, d = .7, f = {
151
+ "image/jpeg": "jpg",
152
+ "image/png": "png",
153
+ "image/webp": "webp",
154
+ "image/gif": "gif"
155
+ }, p = /\.(jpe?g|jfif|png|webp|gif|heic|heif|avif|bmp|tiff?)$/i;
156
+ function m(e, t) {
157
+ let n = f[t];
158
+ if (!n) return e;
159
+ let r = p.exec(e)?.[1]?.toLowerCase();
160
+ return r === n || n === "jpg" && (r === "jpeg" || r === "jfif") ? e : `${r ? e.slice(0, -r.length - 1) : e}.${n}`;
161
+ }
162
+ function h(e, t, n) {
152
163
  let r = Math.max(e, t);
153
164
  if (!r || r <= n) return {
154
165
  width: e,
@@ -160,7 +171,7 @@ function d(e, t, n) {
160
171
  height: Math.max(1, Math.round(t * i))
161
172
  };
162
173
  }
163
- async function f(e, t) {
174
+ async function g(e, t) {
164
175
  let { contentType: n } = t;
165
176
  if (n === "image/gif" || typeof createImageBitmap != "function") return {
166
177
  blob: e,
@@ -176,41 +187,64 @@ async function f(e, t) {
176
187
  };
177
188
  }
178
189
  try {
179
- let i = d(r.width, r.height, t.maxEdge), a = await p(r, i, n);
180
- return a ? {
181
- blob: a,
182
- contentType: a.type || n,
183
- ...i
184
- } : {
190
+ let i = h(r.width, r.height, t.maxEdge), a = y(r, i), o = a && await b(a, n, u);
191
+ if (!a || !o) return {
185
192
  blob: e,
186
193
  contentType: n,
187
194
  width: r.width,
188
195
  height: r.height
189
196
  };
197
+ let s = t.targetBytes && o.size > t.targetBytes ? await _(a, t.targetBytes) : null, c = s && s.size < o.size ? s : o;
198
+ return {
199
+ blob: c,
200
+ contentType: c.type || n,
201
+ ...i
202
+ };
190
203
  } finally {
191
204
  r.close();
192
205
  }
193
206
  }
194
- async function p(e, t, n) {
195
- if (typeof OffscreenCanvas == "function") {
196
- let r = new OffscreenCanvas(t.width, t.height), i = r.getContext("2d");
197
- return i ? (i.drawImage(e, 0, 0, t.width, t.height), r.convertToBlob({
198
- type: n,
199
- quality: u
200
- }).catch(() => null)) : null;
201
- }
202
- if (typeof document > "u") return null;
203
- let r = document.createElement("canvas");
204
- r.width = t.width, r.height = t.height;
205
- let i = r.getContext("2d");
206
- return i ? (i.drawImage(e, 0, 0, t.width, t.height), new Promise((e) => r.toBlob((t) => e(t), n, u))) : null;
207
+ async function _(e, t) {
208
+ let n = v(e) ? "image/jpeg" : "image/webp", r = await b(e, n, u);
209
+ if (!r || r.type !== n) return null;
210
+ if (r.size > t) {
211
+ let t = await b(e, n, d);
212
+ t && t.type === n && t.size < r.size && (r = t);
213
+ }
214
+ return r;
215
+ }
216
+ function v(e) {
217
+ let t = e.getContext("2d");
218
+ if (!t) return !1;
219
+ let n;
220
+ try {
221
+ n = t.getImageData(0, 0, e.width, e.height).data;
222
+ } catch {
223
+ return !1;
224
+ }
225
+ for (let e = 3; e < n.length; e += 4) if (n[e] !== 255) return !1;
226
+ return !0;
227
+ }
228
+ function y(e, t) {
229
+ let n;
230
+ if (typeof OffscreenCanvas == "function") n = new OffscreenCanvas(t.width, t.height);
231
+ else if (typeof document < "u") n = document.createElement("canvas"), n.width = t.width, n.height = t.height;
232
+ else return null;
233
+ let r = n.getContext("2d");
234
+ return r ? (r.drawImage(e, 0, 0, t.width, t.height), n) : null;
235
+ }
236
+ function b(e, t, n) {
237
+ return "convertToBlob" in e ? e.convertToBlob({
238
+ type: t,
239
+ quality: n
240
+ }).catch(() => null) : new Promise((r) => e.toBlob((e) => r(e), t, n));
207
241
  }
208
242
  // src/core/sse.ts
209
- function m(e) {
210
- let t = new h(), n = t.push(e);
243
+ function x(e) {
244
+ let t = new S(), n = t.push(e);
211
245
  return n.push(...t.end()), n;
212
246
  }
213
- var h = class {
247
+ var S = class {
214
248
  buffer = "";
215
249
  carry = "";
216
250
  done = !1;
@@ -247,8 +281,8 @@ var h = class {
247
281
  }
248
282
  }
249
283
  };
250
- async function* g(e, t) {
251
- let n = new h(), r = new TextDecoder(), i = e.getReader(), a = () => void i.cancel().catch(() => {});
284
+ async function* C(e, t) {
285
+ let n = new S(), r = new TextDecoder(), i = e.getReader(), a = () => void i.cancel().catch(() => {});
252
286
  t?.addEventListener("abort", a, { once: !0 });
253
287
  try {
254
288
  for (;;) {
@@ -264,7 +298,7 @@ async function* g(e, t) {
264
298
  }
265
299
  }
266
300
  // src/core/client.ts
267
- var _ = 3e4, v = {
301
+ var w = 3e4, T = {
268
302
  accept: [
269
303
  "image/jpeg",
270
304
  "image/png",
@@ -274,8 +308,11 @@ var _ = 3e4, v = {
274
308
  maxCount: 10,
275
309
  maxBytes: 5242880,
276
310
  maxEdge: 2048
311
+ }, E = {
312
+ maxEdge: 1568,
313
+ targetBytes: 1e6
277
314
  };
278
- function y(e = !1) {
315
+ function D(e = !1) {
279
316
  return {
280
317
  status: "idle",
281
318
  conversationId: null,
@@ -288,19 +325,19 @@ function y(e = !1) {
288
325
  allowances: []
289
326
  };
290
327
  }
291
- function b(e) {
328
+ function O(e) {
292
329
  try {
293
330
  return typeof URL.createObjectURL == "function" ? URL.createObjectURL(e) : void 0;
294
331
  } catch {
295
332
  return;
296
333
  }
297
334
  }
298
- function x(e) {
335
+ function k(e) {
299
336
  try {
300
337
  e && typeof URL.revokeObjectURL == "function" && URL.revokeObjectURL(e);
301
338
  } catch {}
302
339
  }
303
- var S = class extends Error {
340
+ var A = class extends Error {
304
341
  status;
305
342
  code;
306
343
  detail;
@@ -310,16 +347,16 @@ var S = class extends Error {
310
347
  super(n || `HTTP ${e}`), this.status = e, this.code = t, this.detail = n, this.retryAfter = r, this.fields = i;
311
348
  }
312
349
  };
313
- async function C(e) {
350
+ async function j(e) {
314
351
  let t = null;
315
352
  try {
316
353
  t = await e.json();
317
354
  } catch {}
318
355
  let n = Number(e.headers.get("retry-after"));
319
- return new S(e.status, typeof t?.code == "string" ? t.code : "", typeof t?.detail == "string" ? t.detail : "", Number.isFinite(n) && n > 0 ? n : void 0, t && typeof t == "object" && !Array.isArray(t) ? t : {});
356
+ return new A(e.status, typeof t?.code == "string" ? t.code : "", typeof t?.detail == "string" ? t.detail : "", Number.isFinite(n) && n > 0 ? n : void 0, t && typeof t == "object" && !Array.isArray(t) ? t : {});
320
357
  }
321
- function w(e) {
322
- if (!(e instanceof S)) return { code: "unavailable" };
358
+ function M(e) {
359
+ if (!(e instanceof A)) return { code: "unavailable" };
323
360
  let { status: t, code: n, detail: r } = e, i = e.fields.attachments;
324
361
  return t === 400 && Array.isArray(i) ? {
325
362
  code: "photos-refused",
@@ -332,14 +369,14 @@ function w(e) {
332
369
  ...r ? { message: r } : {}
333
370
  };
334
371
  }
335
- function T(e) {
372
+ function N(e) {
336
373
  return e instanceof DOMException ? e.name === "AbortError" : e?.name === "AbortError";
337
374
  }
338
- function E(e, t) {
375
+ function P(e, t) {
339
376
  let n = new Date(e.expiresAt).getTime();
340
- return Number.isNaN(n) || n - _ > t;
377
+ return Number.isNaN(n) || n - w > t;
341
378
  }
342
- function D(e) {
379
+ function F(e) {
343
380
  return {
344
381
  ...e,
345
382
  messages: e.messages.map((e) => ({
@@ -351,7 +388,7 @@ function D(e) {
351
388
  allowances: [...e.allowances]
352
389
  };
353
390
  }
354
- var O = class {
391
+ var I = class {
355
392
  opts;
356
393
  state;
357
394
  view;
@@ -374,7 +411,7 @@ var O = class {
374
411
  this.opts = {
375
412
  ...e,
376
413
  apiUrl: e.apiUrl.replace(/\/+$/, "")
377
- }, this.state = y(!1), this.view = D(this.state);
414
+ }, this.state = D(!1), this.view = F(this.state);
378
415
  }
379
416
  getState() {
380
417
  return this.view;
@@ -390,7 +427,7 @@ var O = class {
390
427
  for (let n of this.events.get(e) ?? []) n(t);
391
428
  }
392
429
  changed(e = {}) {
393
- Object.assign(this.state, e), this.view = D(this.state);
430
+ Object.assign(this.state, e), this.view = F(this.state);
394
431
  for (let e of this.listeners) e(this.view);
395
432
  }
396
433
  id(e) {
@@ -401,7 +438,7 @@ var O = class {
401
438
  }
402
439
  async ensureSession() {
403
440
  let e = this.session;
404
- return e && E(e, this.now()) ? e : (this.session = null, this.starting ||= this.opts.startSession().then((e) => (this.session = e, e)).finally(() => {
441
+ return e && P(e, this.now()) ? e : (this.session = null, this.starting ||= this.opts.startSession().then((e) => (this.session = e, e)).finally(() => {
405
442
  this.starting = null;
406
443
  }), this.starting);
407
444
  }
@@ -413,7 +450,7 @@ var O = class {
413
450
  headers: i
414
451
  });
415
452
  if (a.status !== 401 || n) return a;
416
- let o = await C(a);
453
+ let o = await j(a);
417
454
  if (this.changed({ problem: { code: "reconnecting" } }), o.code === "user_token_expired") try {
418
455
  await this.opts.refreshUserToken(r.sessionId);
419
456
  } catch {
@@ -425,7 +462,7 @@ var O = class {
425
462
  }
426
463
  async json(e, t = {}) {
427
464
  let n = await this.request(e, t);
428
- if (!n.ok) throw await C(n);
465
+ if (!n.ok) throw await j(n);
429
466
  return await n.json();
430
467
  }
431
468
  async send(e) {
@@ -456,7 +493,7 @@ var O = class {
456
493
  role: "user",
457
494
  parts: i
458
495
  });
459
- for (let e of this.state.uploads) e.status !== "ready" && x(e.previewUrl);
496
+ for (let e of this.state.uploads) e.status !== "ready" && k(e.previewUrl);
460
497
  this.files = /* @__PURE__ */ new Map(), this.changed({
461
498
  pendingApprovals: [],
462
499
  problem: null,
@@ -471,12 +508,13 @@ var O = class {
471
508
  });
472
509
  }
473
510
  attachmentLimits() {
474
- let e = this.opts.attachments ?? {}, t = e.accept?.length ? e.accept : [...v.accept], n = this.policy?.accept?.length ? this.policy.accept : null;
511
+ let e = this.opts.attachments ?? {}, t = e.accept?.length ? e.accept : [...T.accept], n = this.policy?.accept?.length ? this.policy.accept : null, r = this.policy?.vision === !0;
475
512
  return {
476
513
  accept: n ? t.filter((e) => n.includes(e)) : t,
477
- maxCount: Math.min(e.maxCount ?? v.maxCount, this.policy?.maxCount ?? v.maxCount, v.maxCount),
478
- maxBytes: e.maxBytes ?? v.maxBytes,
479
- maxEdge: e.maxEdge ?? v.maxEdge
514
+ maxCount: Math.min(e.maxCount ?? T.maxCount, this.policy?.maxCount ?? T.maxCount, T.maxCount),
515
+ maxBytes: e.maxBytes ?? T.maxBytes,
516
+ maxEdge: e.maxEdge ?? (r ? E.maxEdge : T.maxEdge),
517
+ ...e.targetBytes || r ? { targetBytes: e.targetBytes ?? E.targetBytes } : {}
480
518
  };
481
519
  }
482
520
  retryable() {
@@ -492,10 +530,11 @@ var O = class {
492
530
  this.policy = {
493
531
  enabled: e.enabled === !0,
494
532
  ...Array.isArray(e.accept) ? { accept: e.accept.filter((e) => typeof e == "string") } : {},
495
- ...Number.isInteger(e.maxCount) ? { maxCount: e.maxCount } : {}
533
+ ...Number.isInteger(e.maxCount) ? { maxCount: e.maxCount } : {},
534
+ ...e.vision === !0 ? { vision: !0 } : {}
496
535
  };
497
536
  } catch (e) {
498
- e instanceof S && e.status === 404 && (this.policy = { enabled: !1 });
537
+ e instanceof A && e.status === 404 && (this.policy = { enabled: !1 });
499
538
  } finally {
500
539
  this.loadingPolicy = null;
501
540
  }
@@ -527,7 +566,7 @@ var O = class {
527
566
  size: r.size,
528
567
  status: "preparing",
529
568
  progress: 0
530
- }, o = t.includes(i) ? b(r) : void 0;
569
+ }, o = t.includes(i) ? O(r) : void 0;
531
570
  o && (a.previewUrl = o, this.previews.add(o)), this.state.uploads.push(a);
532
571
  let s = this.state.uploads.filter((e) => e.status !== "failed" || e.error === "upload").length;
533
572
  t.includes(i) ? s > n ? this.refuse(a, "count") : (this.files.set(a.id, { file: r }), this.startUpload(a.id)) : this.refuse(a, "type");
@@ -536,7 +575,7 @@ var O = class {
536
575
  }
537
576
  removeUpload(e) {
538
577
  let t = this.upload(e);
539
- t && (t.attachment && this.discard(t.attachment), this.files.get(e)?.controller?.abort(), this.files.delete(e), x(t.previewUrl), t.previewUrl && this.previews.delete(t.previewUrl), this.changed({ uploads: this.state.uploads.filter((t) => t.id !== e) }));
578
+ t && (t.attachment && this.discard(t.attachment), this.files.get(e)?.controller?.abort(), this.files.delete(e), k(t.previewUrl), t.previewUrl && this.previews.delete(t.previewUrl), this.changed({ uploads: this.state.uploads.filter((t) => t.id !== e) }));
540
579
  }
541
580
  retryUpload(e) {
542
581
  let t = this.upload(e);
@@ -552,13 +591,14 @@ var O = class {
552
591
  error: void 0,
553
592
  message: void 0
554
593
  }), this.changed();
555
- let { maxBytes: s, maxEdge: c } = this.attachmentLimits();
594
+ let { maxBytes: s, maxEdge: c, targetBytes: l } = this.attachmentLimits();
556
595
  try {
557
- let e = this.opts.prepareImage ?? f, i;
596
+ let e = this.opts.prepareImage ?? g, i;
558
597
  try {
559
598
  i = await e(t.file, {
560
599
  maxEdge: c,
561
- contentType: n.contentType
600
+ contentType: n.contentType,
601
+ ...l ? { targetBytes: l } : {}
562
602
  });
563
603
  } catch {
564
604
  i = {
@@ -573,9 +613,11 @@ var O = class {
573
613
  }
574
614
  Object.assign(n, {
575
615
  status: "uploading",
576
- size: i.blob.size
616
+ size: i.blob.size,
617
+ name: m(n.name, i.contentType),
618
+ contentType: i.contentType
577
619
  }), this.changed();
578
- let l = await r(i.blob, {
620
+ let u = await r(i.blob, {
579
621
  name: n.name,
580
622
  contentType: i.contentType,
581
623
  size: i.blob.size,
@@ -587,23 +629,23 @@ var O = class {
587
629
  }
588
630
  });
589
631
  if (!a() || o.signal.aborted) {
590
- l && typeof l.ref == "string" && l.ref && this.discard(l);
632
+ u && typeof u.ref == "string" && u.ref && this.discard(u);
591
633
  return;
592
634
  }
593
- if (!l || typeof l.ref != "string" || !l.ref) throw Error("The upload gave no reference.");
635
+ if (!u || typeof u.ref != "string" || !u.ref) throw Error("The upload gave no reference.");
594
636
  Object.assign(n, {
595
637
  status: "ready",
596
638
  progress: 1,
597
639
  attachment: {
598
- ...l,
599
- name: l.name || n.name,
600
- contentType: l.contentType || i.contentType,
601
- ...i.width && !l.width ? { width: i.width } : {},
602
- ...i.height && !l.height ? { height: i.height } : {}
640
+ ...u,
641
+ name: u.name || n.name,
642
+ contentType: u.contentType || i.contentType,
643
+ ...i.width && !u.width ? { width: i.width } : {},
644
+ ...i.height && !u.height ? { height: i.height } : {}
603
645
  }
604
646
  }), this.changed();
605
647
  } catch (e) {
606
- if (!a() || T(e) || o.signal.aborted) return;
648
+ if (!a() || N(e) || o.signal.aborted) return;
607
649
  this.refuse(n, "upload", e instanceof Error && e.message ? e.message : void 0), this.changed();
608
650
  }
609
651
  }
@@ -617,7 +659,7 @@ var O = class {
617
659
  for (let e of this.state.uploads) e.attachment && this.discard(e.attachment);
618
660
  for (let e of this.files.values()) e.controller?.abort();
619
661
  this.files = /* @__PURE__ */ new Map();
620
- for (let e of this.previews) x(e);
662
+ for (let e of this.previews) k(e);
621
663
  this.previews = /* @__PURE__ */ new Set();
622
664
  }
623
665
  async decide(e) {
@@ -649,7 +691,7 @@ var O = class {
649
691
  let n = await this.json(`/v1/conversations/${encodeURIComponent(t)}/allowances/${encodeURIComponent(e)}`, { method: "DELETE" });
650
692
  return this.changed({ allowances: n.allowances ?? [] }), !0;
651
693
  } catch (t) {
652
- let n = w(t);
694
+ let n = M(t);
653
695
  return this.changed({
654
696
  allowances: this.state.allowances.filter((t) => t.toolName !== e),
655
697
  ...t?.status === 404 ? {} : { problem: n }
@@ -683,7 +725,7 @@ var O = class {
683
725
  this.reset(), this.capabilitiesWanted && this.loadCapabilities();
684
726
  }
685
727
  reset() {
686
- this.generation += 1, this.controller?.abort(), this.dropPhotos(), this.tools = /* @__PURE__ */ new Map(), this.retryAction = null, this.state = y(this.newConversationTakesPhotos()), this.changed();
728
+ this.generation += 1, this.controller?.abort(), this.dropPhotos(), this.tools = /* @__PURE__ */ new Map(), this.retryAction = null, this.state = D(this.newConversationTakesPhotos()), this.changed();
687
729
  }
688
730
  async listConversations(e = {}) {
689
731
  let t = new URLSearchParams({
@@ -714,7 +756,7 @@ var O = class {
714
756
  t && (t.allowed = !0, e.preview && (t.preview = e.preview));
715
757
  }
716
758
  this.retryAction = null, this.dropPhotos(), this.state = {
717
- ...y(!!this.opts.uploadFile && n.attachments === !0),
759
+ ...D(!!this.opts.uploadFile && n.attachments === !0),
718
760
  conversationId: e,
719
761
  messages: i,
720
762
  pendingApprovals: r,
@@ -725,7 +767,7 @@ var O = class {
725
767
  if (t !== this.generation) return;
726
768
  this.retryAction = () => this.openConversation(e), this.changed({
727
769
  status: "idle",
728
- problem: w(n)
770
+ problem: M(n)
729
771
  });
730
772
  }
731
773
  }
@@ -756,11 +798,11 @@ var O = class {
756
798
  body: JSON.stringify(t),
757
799
  headers: { accept: "text/event-stream, application/json;q=0.9" },
758
800
  signal: a.signal
759
- }), !o.ok) throw await C(o);
801
+ }), !o.ok) throw await j(o);
760
802
  } catch (n) {
761
803
  if (this.controller === a && (this.controller = null), !r()) return "answered";
762
- if (this.drop(i), T(n)) return this.changed({ status: "idle" }), "not-sent";
763
- let o = w(n);
804
+ if (this.drop(i), N(n)) return this.changed({ status: "idle" }), "not-sent";
805
+ let o = M(n);
764
806
  if (o.code === "photos-refused") {
765
807
  let e = this.state.messages.at(-1);
766
808
  return e?.role === "user" && this.drop(e), this.policy = null, this.changed({
@@ -778,13 +820,13 @@ var O = class {
778
820
  this.changed({ status: "streaming" });
779
821
  let s = !1, c = null, l = !1, u = /* @__PURE__ */ new Map();
780
822
  try {
781
- let e = o.body ? g(o.body, a.signal) : k(await o.text());
823
+ let e = o.body ? C(o.body, a.signal) : L(await o.text());
782
824
  for await (let t of e) {
783
825
  if (!r()) break;
784
826
  t.type === "finish" ? s = !0 : t.type === "data-turn" && (c = t.data), this.apply(t, i, u), this.changed();
785
827
  }
786
828
  } catch (e) {
787
- T(e) || (l = !0);
829
+ N(e) || (l = !0);
788
830
  } finally {
789
831
  this.controller === a && (this.controller = null);
790
832
  }
@@ -928,9 +970,9 @@ var O = class {
928
970
  return r;
929
971
  }
930
972
  };
931
- async function* k(e) {
932
- yield* m(e);
973
+ async function* L(e) {
974
+ yield* x(e);
933
975
  }
934
- export { m as a, d as c, i as d, r as f, h as i, l, O as n, g as o, w as r, f as s, v as t, e as u };
976
+ export { x as a, h as c, i as d, r as f, S as i, l, I as n, C as o, M as r, g as s, T as t, e as u };
935
977
 
936
- //# sourceMappingURL=core-vIc1mTTy.js.map
978
+ //# sourceMappingURL=core-9svu5kzm.js.map