@pagelines/sdk 1.0.572 → 1.0.574

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/dist/sdkClient.js CHANGED
@@ -1,27 +1,27 @@
1
- var ae = Object.defineProperty;
2
- var ve = (n, e, t) => e in n ? ae(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var u = (n, e) => ae(n, "name", { value: e, configurable: !0 });
1
+ var oe = Object.defineProperty;
2
+ var ve = (n, e, t) => e in n ? oe(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
+ var u = (n, e) => oe(n, "name", { value: e, configurable: !0 });
4
4
  var c = (n, e, t) => ve(n, typeof e != "symbol" ? e + "" : e, t);
5
5
  import { APP_PORT as pe, APP_PROD_URL as me, createRefreshingFetch as ye, cookieUtil as U, createLogger as we, shortId as xe, objectId as C, SettingsObject as Se } from "@pagelines/core";
6
- import { watch as N, ref as R, computed as oe } from "vue";
7
- function I(n, e) {
6
+ import { watch as N, ref as R, computed as ae } from "vue";
7
+ function k(n, e) {
8
8
  return n || (e ? `http://localhost:${pe}` : me);
9
9
  }
10
- u(I, "resolveApiBase");
11
- function Ie(n, e, t) {
12
- const r = I(n.apiBase, n.isDev), s = t ? ye({
10
+ u(k, "resolveApiBase");
11
+ function ke(n, e, t) {
12
+ const r = k(n.apiBase, n.isDev), s = t ? ye({
13
13
  fetch: globalThis.fetch.bind(globalThis),
14
14
  getDeviceId: t.getDeviceId,
15
15
  refreshUrl: `${r}/api/auth/refresh`,
16
16
  onAccessTokenRefreshed: t.onAccessTokenRefreshed,
17
17
  onTerminalFailure: t.onTerminalFailure
18
18
  }) : globalThis.fetch.bind(globalThis);
19
- return async (a, i) => {
20
- const h = U.getAuthToken(), o = new Headers(i?.headers);
21
- o.has("Content-Type") || o.set("Content-Type", "application/json"), h && !o.has("Authorization") && o.set("Authorization", `Bearer ${h}`);
22
- const p = typeof a == "string" && a.startsWith("/") ? `${r}${a}` : a, g = await s(p, {
19
+ return async (o, i) => {
20
+ const f = U.getAuthToken(), a = new Headers(i?.headers);
21
+ a.has("Content-Type") || a.set("Content-Type", "application/json"), f && !a.has("Authorization") && a.set("Authorization", `Bearer ${f}`);
22
+ const p = typeof o == "string" && o.startsWith("/") ? `${r}${o}` : o, g = await s(p, {
23
23
  ...i,
24
- headers: o,
24
+ headers: a,
25
25
  credentials: "include"
26
26
  });
27
27
  if (e) {
@@ -34,8 +34,8 @@ function Ie(n, e, t) {
34
34
  return g;
35
35
  };
36
36
  }
37
- u(Ie, "createApiFetch");
38
- const ke = /* @__PURE__ */ Symbol("clean");
37
+ u(ke, "createApiFetch");
38
+ const Ie = /* @__PURE__ */ Symbol("clean");
39
39
  let y = [], b = 0;
40
40
  const P = 4, be = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal = { epoch: 0 }), H = /* @__PURE__ */ u(/* @__NO_SIDE_EFFECTS__ */ (n) => {
41
41
  let e = [], t = {
@@ -47,18 +47,18 @@ const P = 4, be = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal =
47
47
  lc: 0,
48
48
  listen(r) {
49
49
  return t.lc = e.push(r), () => {
50
- for (let a = b + P; a < y.length; )
51
- y[a] === r ? y.splice(a, P) : a += P;
50
+ for (let o = b + P; o < y.length; )
51
+ y[o] === r ? y.splice(o, P) : o += P;
52
52
  let s = e.indexOf(r);
53
53
  ~s && (e.splice(s, 1), --t.lc || t.off());
54
54
  };
55
55
  },
56
56
  notify(r, s) {
57
57
  be.epoch++;
58
- let a = !y.length;
58
+ let o = !y.length;
59
59
  for (let i of e)
60
60
  y.push(i, t.value, r, s);
61
- if (a) {
61
+ if (o) {
62
62
  for (b = 0; b < y.length; b += P)
63
63
  y[b](
64
64
  y[b + 1],
@@ -82,10 +82,10 @@ const P = 4, be = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal =
82
82
  },
83
83
  value: n
84
84
  };
85
- return process.env.NODE_ENV !== "production" && (t[ke] = () => {
85
+ return process.env.NODE_ENV !== "production" && (t[Ie] = () => {
86
86
  e = [], t.lc = 0, t.off();
87
87
  }), t;
88
- }, "atom"), k = globalThis, D = k.__PL_AUTH_USER__ ?? (k.__PL_AUTH_USER__ = /* @__PURE__ */ H(void 0)), B = k.__PL_AUTH_TOKEN__ ?? (k.__PL_AUTH_TOKEN__ = /* @__PURE__ */ H(null)), _ = k.__PL_AUTH_DEVICE_ID__ ?? (k.__PL_AUTH_DEVICE_ID__ = /* @__PURE__ */ H(null)), V = class V {
88
+ }, "atom"), I = globalThis, D = I.__PL_AUTH_USER__ ?? (I.__PL_AUTH_USER__ = /* @__PURE__ */ H(void 0)), B = I.__PL_AUTH_TOKEN__ ?? (I.__PL_AUTH_TOKEN__ = /* @__PURE__ */ H(null)), _ = I.__PL_AUTH_DEVICE_ID__ ?? (I.__PL_AUTH_DEVICE_ID__ = /* @__PURE__ */ H(null)), V = class V {
89
89
  constructor() {
90
90
  c(this, "logger", we("SDKStorage"));
91
91
  }
@@ -99,13 +99,13 @@ const P = 4, be = globalThis.nanostoresGlobal || (globalThis.nanostoresGlobal =
99
99
  * Sync Vue reactive refs with global nanostores for cross-bundle persistence.
100
100
  */
101
101
  syncWithGlobalStores(e) {
102
- const { activeUser: t, token: r, deviceId: s } = e, a = D.get(), i = B.get(), h = _.get();
103
- a && (t.value = a), i && (r.value = i), h && (s.value = h), N(t, (o) => D.set(o), { immediate: !0 }), N(r, (o) => B.set(o), { immediate: !0 }), N(s, (o) => _.set(o), { immediate: !0 }), D.subscribe((o) => {
104
- o !== t.value && (t.value = o);
105
- }), B.subscribe((o) => {
106
- o !== r.value && (r.value = o);
107
- }), _.subscribe((o) => {
108
- o !== s.value && (s.value = o);
102
+ const { activeUser: t, token: r, deviceId: s } = e, o = D.get(), i = B.get(), f = _.get();
103
+ o && (t.value = o), i && (r.value = i), f && (s.value = f), N(t, (a) => D.set(a), { immediate: !0 }), N(r, (a) => B.set(a), { immediate: !0 }), N(s, (a) => _.set(a), { immediate: !0 }), D.subscribe((a) => {
104
+ a !== t.value && (t.value = a);
105
+ }), B.subscribe((a) => {
106
+ a !== r.value && (r.value = a);
107
+ }), _.subscribe((a) => {
108
+ a !== s.value && (s.value = a);
109
109
  });
110
110
  }
111
111
  /**
@@ -186,7 +186,7 @@ const Q = class Q {
186
186
  this.ctx = e;
187
187
  }
188
188
  async create(e) {
189
- const t = e.orgId || this.resolveOrgId(), r = I(this.ctx.apiBase, this.ctx.isDev), a = await (await fetch(`${r}/api/agents`, {
189
+ const t = e.orgId || this.resolveOrgId(), r = k(this.ctx.apiBase, this.ctx.isDev), o = await (await fetch(`${r}/api/agents`, {
190
190
  method: "POST",
191
191
  headers: {
192
192
  "Content-Type": "application/json",
@@ -194,14 +194,14 @@ const Q = class Q {
194
194
  },
195
195
  body: JSON.stringify({ name: e.name, orgId: t })
196
196
  })).json();
197
- if (!a.ok || !a.data?.[0]) {
198
- const i = a.error || "Failed to create agent";
197
+ if (!o.ok || !o.data?.[0]) {
198
+ const i = o.error || "Failed to create agent";
199
199
  throw this.ctx.error.value = i, new Error(i);
200
200
  }
201
- return this.ctx.processApiResponse(a), a.data[0];
201
+ return this.ctx.processApiResponse(o), o.data[0];
202
202
  }
203
203
  async getStatus(e) {
204
- const t = I(this.ctx.apiBase, this.ctx.isDev), s = await (await fetch(`${t}/api/agents/${e.agentId}/status`, {
204
+ const t = k(this.ctx.apiBase, this.ctx.isDev), s = await (await fetch(`${t}/api/agents/${e.agentId}/status`, {
205
205
  headers: {
206
206
  ...this.ctx.token.value && { Authorization: `Bearer ${this.ctx.token.value}` }
207
207
  }
@@ -218,34 +218,34 @@ const Q = class Q {
218
218
  * names to user copy at the call site.
219
219
  */
220
220
  async waitUntilReady(e) {
221
- const { agentId: t, onStatus: r, timeoutMs: s = 3e5, pollIntervalMs: a = 3e3 } = e, i = Date.now();
222
- let h;
221
+ const { agentId: t, onStatus: r, timeoutMs: s = 3e5, pollIntervalMs: o = 3e3 } = e, i = Date.now();
222
+ let f;
223
223
  for (; Date.now() - i < s; ) {
224
- const o = await this.getStatus({ agentId: t });
225
- if (o.ready) {
224
+ const a = await this.getStatus({ agentId: t });
225
+ if (a.ready) {
226
226
  r?.("running");
227
227
  return;
228
228
  }
229
- if (o.status === "error")
230
- throw new Error(o.error || "Provisioning failed");
231
- o.status !== h && (r?.(o.status), h = o.status), await new Promise((p) => setTimeout(p, a));
229
+ if (a.status === "error")
230
+ throw new Error(a.error || "Provisioning failed");
231
+ a.status !== f && (r?.(a.status), f = a.status), await new Promise((p) => setTimeout(p, o));
232
232
  }
233
233
  throw new Error("Agent provisioning timed out — please try again");
234
234
  }
235
235
  /** Send a typed webhook event to a bot agent. No auth required — the proxy is public. */
236
236
  async webhook(e) {
237
- const r = `${I(this.ctx.apiBase, this.ctx.isDev)}/api/bot-api/webhooks/agents/${e.agentId}`, s = { type: e.type, data: e.data };
237
+ const r = `${k(this.ctx.apiBase, this.ctx.isDev)}/api/bot-api/webhooks/agents/${e.agentId}`, s = { type: e.type, data: e.data };
238
238
  e.meta && (s.meta = e.meta);
239
- const a = await fetch(r, {
239
+ const o = await fetch(r, {
240
240
  method: "POST",
241
241
  headers: { "Content-Type": "application/json" },
242
242
  body: JSON.stringify(s)
243
243
  });
244
- if (!a.ok) {
245
- const i = await a.text().catch(() => "Unknown error");
246
- throw new Error(`Webhook delivery failed (${a.status}): ${i.slice(0, 200)}`);
244
+ if (!o.ok) {
245
+ const i = await o.text().catch(() => "Unknown error");
246
+ throw new Error(`Webhook delivery failed (${o.status}): ${i.slice(0, 200)}`);
247
247
  }
248
- return a.json();
248
+ return o.json();
249
249
  }
250
250
  resolveOrgId() {
251
251
  const t = this.ctx.activeUser.value?.orgs?.[0]?.orgId;
@@ -361,10 +361,10 @@ const X = class X {
361
361
  this.ctx.logger.error("loginWithGoogle: Only available in browser");
362
362
  return;
363
363
  }
364
- const t = I(this.ctx.apiBase, this.ctx.isDev), r = window.location.origin, s = `${t}/auth/google-popup?origin=${encodeURIComponent(r)}`, a = 500, i = 600, h = window.screenX + (window.outerWidth - a) / 2, o = window.screenY + (window.outerHeight - i) / 2, p = window.open(
364
+ const t = k(this.ctx.apiBase, this.ctx.isDev), r = window.location.origin, s = `${t}/auth/google-popup?origin=${encodeURIComponent(r)}`, o = 500, i = 600, f = window.screenX + (window.outerWidth - o) / 2, a = window.screenY + (window.outerHeight - i) / 2, p = window.open(
365
365
  s,
366
366
  "google-auth",
367
- `width=${a},height=${i},left=${h},top=${o},popup=yes`
367
+ `width=${o},height=${i},left=${f},top=${a},popup=yes`
368
368
  );
369
369
  if (!p) {
370
370
  const l = "Popup was blocked. Please allow popups for this site.";
@@ -376,8 +376,8 @@ const X = class X {
376
376
  if (l.origin === m) {
377
377
  if (l.data?.type === "auth-success") {
378
378
  window.removeEventListener("message", g);
379
- const { token: x, user: f } = l.data;
380
- this.ctx.processApiResponse({ ok: !0, data: {}, token: x, user: f }), this.ctx.logger.info("Google login successful"), e?.onSuccess?.(f);
379
+ const { token: x, user: h } = l.data;
380
+ this.ctx.processApiResponse({ ok: !0, data: {}, token: x, user: h }), this.ctx.logger.info("Google login successful"), e?.onSuccess?.(h);
381
381
  } else if (l.data?.type === "auth-error") {
382
382
  window.removeEventListener("message", g);
383
383
  const x = l.data.error || "Google authentication failed";
@@ -392,14 +392,14 @@ const X = class X {
392
392
  }
393
393
  };
394
394
  u(X, "AuthClient");
395
- let z = X;
395
+ let W = X;
396
396
  const Y = class Y {
397
397
  constructor(e) {
398
398
  c(this, "ctx");
399
399
  this.ctx = e;
400
400
  }
401
401
  async startTrial(e) {
402
- const t = this.resolveOrgId(), r = I(this.ctx.apiBase, this.ctx.isDev), a = await (await fetch(`${r}/api/billing/checkout/create`, {
402
+ const t = this.resolveOrgId(), r = k(this.ctx.apiBase, this.ctx.isDev), o = await (await fetch(`${r}/api/billing/checkout/create`, {
403
403
  method: "POST",
404
404
  headers: {
405
405
  "Content-Type": "application/json",
@@ -411,17 +411,17 @@ const Y = class Y {
411
411
  ...e?.planKey && { planKey: e.planKey }
412
412
  })
413
413
  })).json();
414
- if (!a.ok || !a.data?.url) {
415
- const i = a.error || "Failed to create checkout session";
414
+ if (!o.ok || !o.data?.url) {
415
+ const i = o.error || "Failed to create checkout session";
416
416
  throw this.ctx.error.value = i, new Error(i);
417
417
  }
418
- window.location.href = a.data.url;
418
+ window.location.href = o.data.url;
419
419
  }
420
420
  async confirmCheckout(e) {
421
421
  return this.getStatus();
422
422
  }
423
423
  async getStatus() {
424
- const e = this.resolveOrgId(), t = I(this.ctx.apiBase, this.ctx.isDev), s = await (await fetch(`${t}/api/billing/details/${e}`, {
424
+ const e = this.resolveOrgId(), t = k(this.ctx.apiBase, this.ctx.isDev), s = await (await fetch(`${t}/api/billing/details/${e}`, {
425
425
  headers: {
426
426
  ...this.ctx.token.value && { Authorization: `Bearer ${this.ctx.token.value}` }
427
427
  }
@@ -433,11 +433,11 @@ const Y = class Y {
433
433
  hasActiveBilling: !1,
434
434
  maxAgents: 0
435
435
  };
436
- const a = ["active", "trialing"];
436
+ const o = ["active", "trialing"];
437
437
  return {
438
438
  plan: s.data.plan,
439
439
  status: s.data.status,
440
- hasActiveBilling: a.includes(s.data.status),
440
+ hasActiveBilling: o.includes(s.data.status),
441
441
  maxAgents: s.data.maxAgents,
442
442
  ...s.data.trialEnd && { trialEnd: s.data.trialEnd },
443
443
  ...s.data.trialDaysRemaining !== void 0 && { trialDaysRemaining: s.data.trialDaysRemaining }
@@ -451,7 +451,7 @@ const Y = class Y {
451
451
  }
452
452
  };
453
453
  u(Y, "BillingClient");
454
- let W = Y;
454
+ let q = Y;
455
455
  const Te = /* @__PURE__ */ new Set(["status", "message", "message_delta", "working_state", "working_end", "error", "stream_end"]);
456
456
  function ie(n) {
457
457
  const e = n.split(`
@@ -475,6 +475,9 @@ function ne(n) {
475
475
  text: n.content,
476
476
  sender: n.role === "system" ? "system" : "agent",
477
477
  timestamp: n.createdAt,
478
+ conversationId: n.conversationId,
479
+ sequence: n.sequence,
480
+ systemKind: n.systemKind,
478
481
  ...n.metadata?.attachments?.length ? { attachments: n.metadata.attachments } : {},
479
482
  ...n.metadata?.issue ? { issue: n.metadata.issue } : {}
480
483
  };
@@ -496,10 +499,10 @@ const Z = class Z {
496
499
  * which stores a stable ID in localStorage).
497
500
  */
498
501
  async chatStreamPublic(e) {
499
- const r = `${I(this.ctx.apiBase, this.ctx.isDev)}/api/agents/public/${encodeURIComponent(e.handle)}/chat/v2/stream`;
500
- let s = "", a = !1, i = !1, h;
502
+ const r = `${k(this.ctx.apiBase, this.ctx.isDev)}/api/agents/public/${encodeURIComponent(e.handle)}/chat/v2/stream`;
503
+ let s = "", o = !1, i = !1, f;
501
504
  try {
502
- const o = await fetch(r, {
505
+ const a = await fetch(r, {
503
506
  method: "POST",
504
507
  headers: { "Content-Type": "application/json" },
505
508
  body: JSON.stringify({
@@ -509,19 +512,19 @@ const Z = class Z {
509
512
  ...e.context ? { context: e.context } : {}
510
513
  })
511
514
  });
512
- if (!o.ok) {
513
- const w = await o.json().catch(() => ({ error: "Request failed" }));
514
- e.onError(w.error || `HTTP ${o.status}`);
515
+ if (!a.ok) {
516
+ const w = await a.json().catch(() => ({ error: "Request failed" }));
517
+ e.onError(w.error || `HTTP ${a.status}`);
515
518
  return;
516
519
  }
517
- if (s = o.headers.get("X-Conversation-Id") || "", h = o.body?.getReader(), !h) {
520
+ if (s = a.headers.get("X-Conversation-Id") || "", f = a.body?.getReader(), !f) {
518
521
  e.onError("No response stream");
519
522
  return;
520
523
  }
521
524
  const p = new TextDecoder();
522
525
  let g = "";
523
526
  e: for (; ; ) {
524
- const { done: w, value: l } = await h.read();
527
+ const { done: w, value: l } = await f.read();
525
528
  if (w)
526
529
  break;
527
530
  g += p.decode(l, { stream: !0 });
@@ -531,20 +534,22 @@ const Z = class Z {
531
534
  for (; m !== -1; ) {
532
535
  const x = g.slice(0, m);
533
536
  g = g.slice(m + 2);
534
- const f = ie(x);
535
- if (f) {
536
- if (f.event === "working_state")
537
- e.onStatus?.(f.data.description);
538
- else if (f.event === "message_delta")
539
- e.onDelta(f.data.delta, f.data.role);
540
- else if (f.event === "error") {
541
- a = !0, e.onError(f.data.message);
537
+ const h = ie(x);
538
+ if (h) {
539
+ if (h.event === "working_state")
540
+ e.onStatus?.(h.data.description);
541
+ else if (h.event === "working_end")
542
+ e.onWorkingEnd?.();
543
+ else if (h.event === "message_delta")
544
+ e.onDelta(h.data.delta, h.data.role);
545
+ else if (h.event === "error") {
546
+ o = !0, e.onError(h.data.message);
542
547
  break e;
543
- } else if (f.event === "message" && (f.data.message.role === "assistant" || f.data.message.role === "system")) {
548
+ } else if (h.event === "message" && (h.data.message.role === "assistant" || h.data.message.role === "system")) {
544
549
  i = !0;
545
- const A = ne(f.data.message);
550
+ const A = ne(h.data.message);
546
551
  A && e.onMessage?.(A);
547
- } else if (f.event === "stream_end")
552
+ } else if (h.event === "stream_end")
548
553
  break e;
549
554
  }
550
555
  m = g.indexOf(`
@@ -552,12 +557,12 @@ const Z = class Z {
552
557
  `);
553
558
  }
554
559
  }
555
- !a && i ? e.onDone(s) : a || e.onError("Stream ended before reply arrived");
556
- } catch (o) {
557
- e.onError(o instanceof Error ? o.message : "Stream failed");
560
+ !o && i ? e.onDone(s) : o || e.onError("Stream ended before reply arrived");
561
+ } catch (a) {
562
+ e.onError(a instanceof Error ? a.message : "Stream failed");
558
563
  } finally {
559
564
  try {
560
- await h?.cancel();
565
+ await f?.cancel();
561
566
  } catch {
562
567
  }
563
568
  }
@@ -571,8 +576,8 @@ const Z = class Z {
571
576
  * Mirrors `src/modules/agent/client.ts → sendChatMessageStream`.
572
577
  */
573
578
  async chatStreamAuthenticated(e) {
574
- const t = I(this.ctx.apiBase, this.ctx.isDev), r = this.ctx.token.value ? { Authorization: `Bearer ${this.ctx.token.value}` } : {};
575
- let s, a = null;
579
+ const t = k(this.ctx.apiBase, this.ctx.isDev), r = this.ctx.token.value ? { Authorization: `Bearer ${this.ctx.token.value}` } : {};
580
+ let s, o = null;
576
581
  try {
577
582
  const d = await fetch(`${t}/api/conversations`, {
578
583
  method: "POST",
@@ -583,25 +588,25 @@ const Z = class Z {
583
588
  e.onError(S.error || `Conversation failed: HTTP ${d.status}`);
584
589
  return;
585
590
  }
586
- s = S.data.conversationId, a = S.data.latestSequence ?? null;
591
+ s = S.data.conversationId, o = S.data.latestSequence ?? null;
587
592
  } catch (d) {
588
593
  e.onError(d instanceof Error ? d.message : "Conversation failed");
589
594
  return;
590
595
  }
591
- let i = !1, h = !1, o = !1, p = !1, g = !1, w = !1, l;
596
+ let i = !1, f = !1, a = !1, p = !1, g = !1, w = !1, l;
592
597
  const m = new AbortController();
593
- let x = !1, f, A = /* @__PURE__ */ u(() => {
598
+ let x = !1, h, A = /* @__PURE__ */ u(() => {
594
599
  }, "resolveStreamReady");
595
600
  const le = new Promise((d) => {
596
601
  A = d;
597
602
  }), $ = /* @__PURE__ */ u((d) => {
598
- x || (x = !0, f && clearTimeout(f), A(d));
603
+ x || (x = !0, h && clearTimeout(h), A(d));
599
604
  }, "settleStreamReady"), re = /* @__PURE__ */ u(() => {
600
605
  l?.cancel().catch(() => {
601
606
  });
602
- }, "cancelReader"), de = a ? `${t}/api/conversations/${encodeURIComponent(s)}/stream?since=${encodeURIComponent(a)}` : `${t}/api/conversations/${encodeURIComponent(s)}/stream`;
603
- f = setTimeout(() => {
604
- w = !0, o = !0, e.onError("Timed out opening stream"), m.abort(), $("failed");
607
+ }, "cancelReader"), de = o ? `${t}/api/conversations/${encodeURIComponent(s)}/stream?since=${encodeURIComponent(o)}` : `${t}/api/conversations/${encodeURIComponent(s)}/stream`;
608
+ h = setTimeout(() => {
609
+ w = !0, a = !0, e.onError("Timed out opening stream"), m.abort(), $("failed");
605
610
  }, 1e4);
606
611
  const O = (async () => {
607
612
  try {
@@ -610,11 +615,11 @@ const Z = class Z {
610
615
  signal: m.signal
611
616
  });
612
617
  if (!d.ok) {
613
- o = !0, $("failed"), e.onError(`Stream failed: HTTP ${d.status}`);
618
+ a = !0, $("failed"), e.onError(`Stream failed: HTTP ${d.status}`);
614
619
  return;
615
620
  }
616
621
  if (l = d.body?.getReader(), !l) {
617
- o = !0, $("failed"), e.onError("No response stream");
622
+ a = !0, $("failed"), e.onError("No response stream");
618
623
  return;
619
624
  }
620
625
  $("ready");
@@ -635,10 +640,12 @@ const Z = class Z {
635
640
  if (v) {
636
641
  if (v.event === "working_state")
637
642
  i && e.onStatus?.(v.data.description);
643
+ else if (v.event === "working_end")
644
+ i && e.onWorkingEnd?.();
638
645
  else if (v.event === "message_delta")
639
646
  i && e.onDelta(v.data.delta, v.data.role);
640
647
  else if (v.event === "error") {
641
- o = !0, e.onError(v.data.message);
648
+ a = !0, e.onError(v.data.message);
642
649
  break e;
643
650
  } else if (v.event === "message" && (v.data.message.role === "assistant" || v.data.message.role === "system")) {
644
651
  if (!i)
@@ -655,9 +662,9 @@ const Z = class Z {
655
662
  `);
656
663
  }
657
664
  }
658
- !o && p ? e.onDone(s) : !o && i && !h && e.onError("Stream ended before reply arrived");
665
+ !a && p ? e.onDone(s) : !a && i && !f && e.onError("Stream ended before reply arrived");
659
666
  } catch (d) {
660
- !h && !w && (o = !0, $("failed"), e.onError(d instanceof Error ? d.message : "Stream failed"));
667
+ !f && !w && (a = !0, $("failed"), e.onError(d instanceof Error ? d.message : "Stream failed"));
661
668
  } finally {
662
669
  g = !0;
663
670
  try {
@@ -688,18 +695,18 @@ const Z = class Z {
688
695
  })
689
696
  }), S = await d.json();
690
697
  if (!S.ok) {
691
- h = !0, m.abort(), re(), e.onError(S.error || `Send failed: HTTP ${d.status}`), await O;
698
+ f = !0, m.abort(), re(), e.onError(S.error || `Send failed: HTTP ${d.status}`), await O;
692
699
  return;
693
700
  }
694
701
  } catch (d) {
695
- h = !0, m.abort(), re(), e.onError(d instanceof Error ? d.message : "Send failed"), await O;
702
+ f = !0, m.abort(), re(), e.onError(d instanceof Error ? d.message : "Send failed"), await O;
696
703
  return;
697
704
  }
698
705
  await O;
699
706
  }
700
707
  };
701
708
  u(Z, "ChatClient");
702
- let q = Z;
709
+ let z = Z;
703
710
  const ee = class ee {
704
711
  constructor(e) {
705
712
  c(this, "ctx");
@@ -795,7 +802,7 @@ const j = new K(), L = class L extends Se {
795
802
  // Auto-managed session ID for usage tracking
796
803
  c(this, "sessionId", C({ prefix: "ses" }));
797
804
  // Computed properties derived from activeUser (matches UserClient pattern)
798
- c(this, "currentAgent", oe(() => {
805
+ c(this, "currentAgent", ae(() => {
799
806
  const t = this.activeUser.value;
800
807
  if (!t?.agents)
801
808
  return;
@@ -803,7 +810,7 @@ const j = new K(), L = class L extends Se {
803
810
  if (r)
804
811
  return t.agents.find((s) => s.agentId === r);
805
812
  }));
806
- c(this, "currentOrg", oe(() => {
813
+ c(this, "currentOrg", ae(() => {
807
814
  const t = this.currentAgent.value;
808
815
  if (!t?.orgId)
809
816
  return;
@@ -821,8 +828,8 @@ const j = new K(), L = class L extends Se {
821
828
  c(this, "chat");
822
829
  c(this, "user");
823
830
  j.set(this);
824
- const a = {
825
- apiFetch: Ie(
831
+ const o = {
832
+ apiFetch: ke(
826
833
  { isDev: this.isDev, apiBase: this.apiBase },
827
834
  this.processApiResponse.bind(this),
828
835
  {
@@ -847,7 +854,7 @@ const j = new K(), L = class L extends Se {
847
854
  logger: this.logger,
848
855
  processApiResponse: this.processApiResponse.bind(this)
849
856
  };
850
- this.agent = new G(a), this.auth = new z(a), this.billing = new W(a), this.chat = new q(a), this.user = new M(a), this.logger.info("PageLinesSDK initialized"), this.storage.loadFromStorage(this.authRefs()), this.storage.syncWithGlobalStores(this.authRefs()), this.initialized = new Promise((i) => {
857
+ this.agent = new G(o), this.auth = new W(o), this.billing = new q(o), this.chat = new z(o), this.user = new M(o), this.logger.info("PageLinesSDK initialized"), this.storage.loadFromStorage(this.authRefs()), this.storage.syncWithGlobalStores(this.authRefs()), this.initialized = new Promise((i) => {
851
858
  this.resolveUser = i;
852
859
  }), this.token.value && !this.activeUser.value ? this.auth.getCurrentUser().then((i) => {
853
860
  this.resolveUser && (this.resolveUser(i), this.resolveUser = void 0);
@@ -897,11 +904,11 @@ u(L, "PageLinesSDK");
897
904
  let ce = L;
898
905
  export {
899
906
  G as A,
900
- W as B,
901
- q as C,
907
+ q as B,
908
+ z as C,
902
909
  ce as P,
903
910
  M as U,
904
- z as a,
905
- I as r
911
+ W as a,
912
+ k as r
906
913
  };
907
914
  //# sourceMappingURL=sdkClient.js.map