@itechchoice/prime-chatkit 0.1.0-alpha.7 → 0.1.0-alpha.8

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/index.js CHANGED
@@ -13,7 +13,7 @@ function fi(e) {
13
13
  if (t === null) throw new Error("PrimeViaChatProvider is required");
14
14
  return t;
15
15
  }
16
- const gi = () => fi(fa), mt = () => fi(ma), xc = () => mt().scope, wc = () => mt().availability, _c = () => mt().locale, bc = () => mt().processView;
16
+ const gi = () => fi(fa), mt = () => fi(ma), wc = () => mt().scope, _c = () => mt().availability, bc = () => mt().locale, vc = () => mt().processView;
17
17
  function xa() {
18
18
  const { controller: e } = gi(), t = Ya(e.subscribe, e.getState, e.getState);
19
19
  return je(() => ({
@@ -27,7 +27,7 @@ function xa() {
27
27
  upload: e.upload
28
28
  }), [t, e]);
29
29
  }
30
- function vc() {
30
+ function yc() {
31
31
  const { state: e } = xa(), { controller: t } = gi(), o = e.provisioning;
32
32
  return {
33
33
  checked: o?.checked ?? !1,
@@ -8584,9 +8584,14 @@ function vi(e) {
8584
8584
  const t = [...e.turns].reverse().find((o) => o.text);
8585
8585
  return !t || t.model?.stopReason === "TOOL_USE" ? "" : t.text;
8586
8586
  }
8587
- const ws = /\n{1,}(?:#{1,6}\s*|\*\*)(?:Sources|References|来源|参考来源|参考资料)(?:\*\*)?[::]?\s*\n+([\s\S]*)$/i;
8588
- function _s(e) {
8589
- const t = ws.exec(e);
8587
+ function ws(e) {
8588
+ return e.replace(/([^\n])(\*\*[^*\n]+\*\*\n\n)/g, `$1
8589
+
8590
+ $2`);
8591
+ }
8592
+ const _s = /\n{1,}(?:#{1,6}\s*|\*\*)(?:Sources|References|来源|参考来源|参考资料)(?:\*\*)?[::]?\s*\n+([\s\S]*)$/i;
8593
+ function bs(e) {
8594
+ const t = _s.exec(e);
8590
8595
  if (!t) return { body: e, sources: [] };
8591
8596
  const o = [];
8592
8597
  for (const n of t[1].split(/\n|,|,|、/)) {
@@ -8600,10 +8605,10 @@ function _s(e) {
8600
8605
  function Gi(e, t) {
8601
8606
  return t.text ? e.answer.outputId ? t.outputId !== e.answer.outputId : t.model?.stopReason === "TOOL_USE" : !1;
8602
8607
  }
8603
- function bs(e) {
8608
+ function vs(e) {
8604
8609
  return e.turns.reduce((t, o) => t + o.tools.length, 0);
8605
8610
  }
8606
- function vs(e, t, o = Date.now()) {
8611
+ function ys(e, t, o = Date.now()) {
8607
8612
  const n = at(t.id);
8608
8613
  if (n && e.lastEventId && !bi(n, e.lastEventId)) return { run: e };
8609
8614
  const a = t.data;
@@ -8822,7 +8827,7 @@ function vs(e, t, o = Date.now()) {
8822
8827
  }
8823
8828
  return { run: r, title: c };
8824
8829
  }
8825
- function ys(e, t, o = {}) {
8830
+ function ks(e, t, o = {}) {
8826
8831
  return e.map((n) => {
8827
8832
  if (n.role === "user")
8828
8833
  return {
@@ -8870,19 +8875,19 @@ function ys(e, t, o = {}) {
8870
8875
  if (c.length && l.push({ kind: "tools", id: `${a}:process`, tools: c }), o.processView === "replies" && (r.status === "running" || r.status === "waiting")) {
8871
8876
  let w = "";
8872
8877
  for (const m of s) {
8873
- const k = m.thinking.trim(), y = Gi(r, m) ? m.text.trim() : "";
8878
+ const k = ws(m.thinking).trim(), y = Gi(r, m) ? m.text.trim() : "";
8874
8879
  k && (w = k), y && (w = y);
8875
8880
  }
8876
8881
  w && l.push({ kind: "note", text: w });
8877
8882
  }
8878
- const { body: x, sources: _ } = _s(vi(r)), v = x.trim();
8883
+ const { body: x, sources: _ } = bs(vi(r)), v = x.trim();
8879
8884
  v && l.push({ kind: "text", text: v }), _.length && l.push({ kind: "artifacts", names: _.map((w) => w.label) });
8880
8885
  for (const w of r.asks)
8881
8886
  l.push({ kind: "decision", ask: { id: w.id, question: w.question, task: w.header ?? "", kind: "decision" } });
8882
- return r.status === "failed" ? l.push({ kind: "error", text: t.failedAnswer, retry: !0 }) : r.status === "completed" && !v && bs(r) === 0 && l.push({ kind: "error", text: t.emptyAnswer }), { id: a, role: "agent", at: n.createdAt, parts: l, streaming: r.status === "running", stopped: r.status === "cancelled" };
8887
+ return r.status === "failed" ? l.push({ kind: "error", text: t.failedAnswer, retry: !0 }) : r.status === "completed" && !v && vs(r) === 0 && l.push({ kind: "error", text: t.emptyAnswer }), { id: a, role: "agent", at: n.createdAt, parts: l, streaming: r.status === "running", stopped: r.status === "cancelled" };
8883
8888
  });
8884
8889
  }
8885
- function ks(e) {
8890
+ function zs(e) {
8886
8891
  const t = [...e].reverse().find((o) => o.role === "assistant");
8887
8892
  return !t || t.run.status !== "completed" && t.run.status !== "waiting" ? [] : t.run.asks.map((o) => ({
8888
8893
  id: o.id,
@@ -8892,9 +8897,9 @@ function ks(e) {
8892
8897
  options: o.options.map((n) => ({ id: n.id, title: n.label, summary: n.description }))
8893
8898
  }));
8894
8899
  }
8895
- const zs = ht(null);
8896
- function Ms({ title: e, meta: t, icon: o, onClose: n, children: a, placement: r = "inside", size: c = "default", labels: u }) {
8897
- const s = Ht(zs), l = q(null), x = s?.previewRef ?? l, _ = q(null), v = q(null), [w, m] = I(!1);
8900
+ const Ms = ht(null);
8901
+ function Cs({ title: e, meta: t, icon: o, onClose: n, children: a, placement: r = "inside", size: c = "default", labels: u }) {
8902
+ const s = Ht(Ms), l = q(null), x = s?.previewRef ?? l, _ = q(null), v = q(null), [w, m] = I(!1);
8898
8903
  ke(() => {
8899
8904
  if (r !== "viewport") return;
8900
8905
  const f = [];
@@ -8909,7 +8914,7 @@ function Ms({ title: e, meta: t, icon: o, onClose: n, children: a, placement: r
8909
8914
  const k = () => {
8910
8915
  n(), _.current?.focus({ preventScroll: !0 });
8911
8916
  }, y = /* @__PURE__ */ d(Me, { children: [
8912
- /* @__PURE__ */ i("style", { href: "ui-collaboration-stream-clean", precedence: "default", children: Ns }),
8917
+ /* @__PURE__ */ i("style", { href: "ui-collaboration-stream-clean", precedence: "default", children: Is }),
8913
8918
  /* @__PURE__ */ i(
8914
8919
  "div",
8915
8920
  {
@@ -8957,7 +8962,7 @@ function Ms({ title: e, meta: t, icon: o, onClose: n, children: a, placement: r
8957
8962
  typeof document < "u" && xn(y, document.body)
8958
8963
  ] }) : y;
8959
8964
  }
8960
- const Cs = (
8965
+ const Ns = (
8961
8966
  /* css */
8962
8967
  `
8963
8968
  .ui-crsc.ui-crsc__preview { container-type: normal; }
@@ -8966,7 +8971,7 @@ const Cs = (
8966
8971
  .ui-crsc__window[data-size="large"] .ui-crsc__window-body { display: grid; place-items: center; }
8967
8972
  .ui-crsc__window[data-size="large"] .ui-crsc__window-body img { display: block; width: auto; height: auto; max-width: 100%; max-height: calc(85vh - 110px); object-fit: contain; }
8968
8973
  `
8969
- ), Ns = (
8974
+ ), Is = (
8970
8975
  /* css */
8971
8976
  `
8972
8977
  /* Colors and motion as variables – override them on .ui-crsc */
@@ -9260,7 +9265,7 @@ const Cs = (
9260
9265
  --ui-crsc-focus: rgba(77, 141, 255, 0.8);
9261
9266
  }
9262
9267
  /* PrimeChatKit LOCAL ㉓ start */
9263
- ${Cs}
9268
+ ${Ns}
9264
9269
  /* PrimeChatKit LOCAL ㉓ end */
9265
9270
  `
9266
9271
  ), jt = 600 * 1e3, Qi = /* @__PURE__ */ new WeakMap();
@@ -9273,7 +9278,7 @@ async function Ba(e, t) {
9273
9278
  if (!n) throw new Error("attachment-url-missing");
9274
9279
  return n;
9275
9280
  }
9276
- function Is(e, t) {
9281
+ function Ls(e, t) {
9277
9282
  const o = hi(e);
9278
9283
  for (const [c, u] of o.urls)
9279
9284
  Date.now() - u.fetchedAt >= jt && o.urls.delete(c);
@@ -9286,11 +9291,11 @@ function Is(e, t) {
9286
9291
  });
9287
9292
  return o.pending.set(t, r), r;
9288
9293
  }
9289
- function Ls(e) {
9294
+ function Ts(e) {
9290
9295
  return e.mimeType ? /^image\/(?:png|jpe?g|gif|webp|bmp)$/i.test(e.mimeType.trim()) : /\.(?:png|jpe?g|gif|webp|bmp)$/i.test(e.name);
9291
9296
  }
9292
- function Ts({ files: e, getAttachmentUrls: t, onDownload: o, copy: n }) {
9293
- return /* @__PURE__ */ i("div", { className: "prime-blocks__attachments", children: e.map((a) => t && Ls(a) ? /* @__PURE__ */ i(As, { file: a, getUrls: t, onDownload: o, closeLabel: n.closePreview }, a.id) : /* @__PURE__ */ i(
9297
+ function As({ files: e, getAttachmentUrls: t, onDownload: o, copy: n }) {
9298
+ return /* @__PURE__ */ i("div", { className: "prime-blocks__attachments", children: e.map((a) => t && Ts(a) ? /* @__PURE__ */ i(Ss, { file: a, getUrls: t, onDownload: o, closeLabel: n.closePreview }, a.id) : /* @__PURE__ */ i(
9294
9299
  Ae,
9295
9300
  {
9296
9301
  variant: "ghost",
@@ -9303,7 +9308,7 @@ function Ts({ files: e, getAttachmentUrls: t, onDownload: o, copy: n }) {
9303
9308
  a.id
9304
9309
  )) });
9305
9310
  }
9306
- function As({ file: e, getUrls: t, onDownload: o, closeLabel: n }) {
9311
+ function Ss({ file: e, getUrls: t, onDownload: o, closeLabel: n }) {
9307
9312
  const [a, r] = I(), [c, u] = I(!1), [s, l] = I(), x = q(null), _ = q(0), v = q(0), w = hi(t).urls.get(e.id), m = !w || Date.now() - w.fetchedAt >= jt;
9308
9313
  se(() => {
9309
9314
  const f = ++_.current;
@@ -9312,7 +9317,7 @@ function As({ file: e, getUrls: t, onDownload: o, closeLabel: n }) {
9312
9317
  };
9313
9318
  }, [t, e.id]), se(() => {
9314
9319
  let f = !0;
9315
- return Is(t, e.id).then((b) => {
9320
+ return Ls(t, e.id).then((b) => {
9316
9321
  f && r({ getUrls: t, id: e.id, url: b });
9317
9322
  }).catch(() => {
9318
9323
  f && r(void 0);
@@ -9357,7 +9362,7 @@ function As({ file: e, getUrls: t, onDownload: o, closeLabel: n }) {
9357
9362
  }
9358
9363
  ),
9359
9364
  s && /* @__PURE__ */ i(
9360
- Ms,
9365
+ Cs,
9361
9366
  {
9362
9367
  title: e.name,
9363
9368
  placement: "viewport",
@@ -9369,7 +9374,7 @@ function As({ file: e, getUrls: t, onDownload: o, closeLabel: n }) {
9369
9374
  )
9370
9375
  ] });
9371
9376
  }
9372
- function Ss(e, t, o, n = {}) {
9377
+ function Ds(e, t, o, n = {}) {
9373
9378
  if (e.status === "waiting") return t.waiting;
9374
9379
  if (e.prepare.status === "running" && e.turns.length === 0) return t.ready;
9375
9380
  const a = e.turns.flatMap((r) => r.tools).filter((r) => r.status === "running");
@@ -9385,7 +9390,7 @@ function Ss(e, t, o, n = {}) {
9385
9390
  }
9386
9391
  return vi(e) ? t.writing : t.thinking;
9387
9392
  }
9388
- function Ds({ run: e, live: t, copy: o, hideTools: n }) {
9393
+ function $s({ run: e, live: t, copy: o, hideTools: n }) {
9389
9394
  const a = e.status === "running", [r, c] = I(Date.now);
9390
9395
  if (se(() => {
9391
9396
  if (!a) return;
@@ -9395,7 +9400,7 @@ function Ds({ run: e, live: t, copy: o, hideTools: n }) {
9395
9400
  }, [a, e.startedAt]), !a) return null;
9396
9401
  const u = Math.max(0, Math.floor((r - e.startedAt) / 1e3));
9397
9402
  return /* @__PURE__ */ d("div", { className: "prime-blocks__live", children: [
9398
- /* @__PURE__ */ i(Sa, { variant: "plain", size: "sm", phases: [Ss(e, t, o, { hideTools: n })], phase: 0 }),
9403
+ /* @__PURE__ */ i(Sa, { variant: "plain", size: "sm", phases: [Ds(e, t, o, { hideTools: n })], phase: 0 }),
9399
9404
  /* @__PURE__ */ d("span", { className: "prime-blocks__clock ui-th-who__time ui-th-num", children: [
9400
9405
  Math.floor(u / 60),
9401
9406
  ":",
@@ -9404,7 +9409,7 @@ function Ds({ run: e, live: t, copy: o, hideTools: n }) {
9404
9409
  ] });
9405
9410
  }
9406
9411
  const Zi = () => ({ values: {}, custom: {} }), Rt = (e, t) => Object.hasOwn(e.values, t) || Object.hasOwn(e.custom, t);
9407
- function $s(e) {
9412
+ function Os(e) {
9408
9413
  return e.map(({ id: t, question: o, task: n, kind: a, options: r, facts: c }) => ({
9409
9414
  id: t,
9410
9415
  question: o,
@@ -9415,7 +9420,7 @@ function $s(e) {
9415
9420
  facts: c
9416
9421
  }));
9417
9422
  }
9418
- function Os(e, t, o, n) {
9423
+ function Es(e, t, o, n) {
9419
9424
  if (typeof n == "string") return;
9420
9425
  const a = e.steps.find((u) => `${e.id}:${u.id}` === o);
9421
9426
  if (!a || Rt(t, a.id)) return;
@@ -9436,10 +9441,10 @@ function Os(e, t, o, n) {
9436
9441
  else return;
9437
9442
  return { values: r, custom: c };
9438
9443
  }
9439
- function Es(e) {
9440
- return /* @__PURE__ */ i(js, { ...e }, `${e.suspension.taskId}:${e.suspension.id}`);
9444
+ function js(e) {
9445
+ return /* @__PURE__ */ i(Rs, { ...e }, `${e.suspension.taskId}:${e.suspension.id}`);
9441
9446
  }
9442
- function js({ suspension: e, locale: t, onAnswer: o, error: n, onCancel: a, onNavigate: r }) {
9447
+ function Rs({ suspension: e, locale: t, onAnswer: o, error: n, onCancel: a, onNavigate: r }) {
9443
9448
  const [c, u] = I(Zi), [s, l] = I(0), x = ja(t), _ = li(t), v = n?.code === "resume-failed", w = e.kind === "approval" ? e.toolName?.split(":").at(-1) : void 0;
9444
9449
  if (e.kind === "approval" && !e.readOnly) return /* @__PURE__ */ i(
9445
9450
  oo,
@@ -9526,7 +9531,7 @@ function js({ suspension: e, locale: t, onAnswer: o, error: n, onCancel: a, onNa
9526
9531
  return;
9527
9532
  }
9528
9533
  if (e.kind !== "questions") return;
9529
- const M = Os(e, c, f, b);
9534
+ const M = Es(e, c, f, b);
9530
9535
  M && (u(M), e.steps.every((j) => Rt(M, j.id)) && o?.({ kind: "questions", ...M }));
9531
9536
  }
9532
9537
  },
@@ -9535,7 +9540,7 @@ function js({ suspension: e, locale: t, onAnswer: o, error: n, onCancel: a, onNa
9535
9540
  e.kind !== "approval" && e.canCancel && a && /* @__PURE__ */ i(Ae, { variant: "ghost", size: "sm", onClick: a, children: x.questions.cancel })
9536
9541
  ] });
9537
9542
  }
9538
- function Rs({ messages: e, older: t, active: o = !0 }) {
9543
+ function Fs({ messages: e, older: t, active: o = !0 }) {
9539
9544
  const n = q(null), a = q(null), r = q(!0), c = q(0), u = q(o), s = q(null), l = e.find(() => !0)?.id, x = q(l), _ = q(!1), [v, w] = I(!1), m = Ne(() => {
9540
9545
  const b = n.current;
9541
9546
  b && o && r.current && !s.current && (b.scrollTop = Math.max(0, b.scrollHeight - b.clientHeight), c.current = b.scrollTop);
@@ -9564,7 +9569,7 @@ function Rs({ messages: e, older: t, active: o = !0 }) {
9564
9569
  return a.current && b.observe(a.current), n.current && b.observe(n.current), () => b.disconnect();
9565
9570
  }, [m]), { viewport: n, content: a, away: v, onScroll: f, jump: k, loadOlder: y };
9566
9571
  }
9567
- function Fs(e, t) {
9572
+ function Ps(e, t) {
9568
9573
  const o = q(/* @__PURE__ */ new Set()), n = q([]), [a, r] = I([]), [c, u] = I(!1), [s, l] = I(0);
9569
9574
  return se(() => {
9570
9575
  const m = o.current;
@@ -9612,7 +9617,7 @@ function Fs(e, t) {
9612
9617
  failed: a.some((m) => m.status === "error")
9613
9618
  };
9614
9619
  }
9615
- function Ps(e) {
9620
+ function Bs(e) {
9616
9621
  const t = q(/* @__PURE__ */ new Map()), o = q(!1), [n, a] = I(!1);
9617
9622
  return se(() => {
9618
9623
  o.current = !0;
@@ -9640,8 +9645,8 @@ function Ps(e) {
9640
9645
  }, failed: n };
9641
9646
  }
9642
9647
  const ii = () => {
9643
- }, Bs = () => "waiting", Ki = /* @__PURE__ */ new Set(["stream-lost", "resume-failed", "create-task-failed", "history-failed"]);
9644
- function Us({
9648
+ }, Us = () => "waiting", Ki = /* @__PURE__ */ new Set(["stream-lost", "resume-failed", "create-task-failed", "history-failed"]);
9649
+ function qs({
9645
9650
  messages: e,
9646
9651
  loading: t = !1,
9647
9652
  title: o,
@@ -9686,7 +9691,7 @@ function Us({
9686
9691
  };
9687
9692
  }, [oe.locale, oe.labels, W]), Y = je(() => new Intl.DateTimeFormat(oe.locale, { hour: "2-digit", minute: "2-digit" }), [oe.locale]), p = c !== void 0 && !c.ready;
9688
9693
  Z === "history" && (p || !n) && K("chat");
9689
- const A = r?.available === !1, C = p || A || !!s, h = Fs(B, te.attachments.dropzone.uploadFailed), N = q(null), G = Ps(z), g = h.uploading || h.failed, D = C ? void 0 : P, R = [...e].reverse().find((Q) => Q.role === "assistant"), U = !p && !!n && Z === "history", S = je(() => ys(e, oe.copy, { processView: F }).map((Q) => {
9694
+ const A = r?.available === !1, C = p || A || !!s, h = Ps(B, te.attachments.dropzone.uploadFailed), N = q(null), G = Bs(z), g = h.uploading || h.failed, D = C ? void 0 : P, R = [...e].reverse().find((Q) => Q.role === "assistant"), U = !p && !!n && Z === "history", S = je(() => ks(e, oe.copy, { processView: F }).map((Q) => {
9690
9695
  if (Q.role !== "agent") return Q;
9691
9696
  const ce = s ? Q.parts.filter((pe) => pe.kind !== "decision") : Q.parts, xe = _ && Q.id === R?.id && Ki.has(_.code) ? ce.map((pe) => pe.kind === "error" ? { ...pe, retry: !1 } : pe) : ce;
9692
9697
  return {
@@ -9700,9 +9705,9 @@ function Us({
9700
9705
  const Q = window.setInterval(() => ue(Date.now()), 1e3);
9701
9706
  return () => window.clearInterval(Q);
9702
9707
  }, [ae, p]);
9703
- const ge = je(() => ks(e), [e]), _e = R?.run.status === "running", we = R?.run.status === "waiting" ? te.live.waiting : _e ? te.live.working : o ? W : void 0, he = Rs({ messages: e, older: p || t ? void 0 : u, active: !U && !p && !t });
9708
+ const ge = je(() => zs(e), [e]), _e = R?.run.status === "running", we = R?.run.status === "waiting" ? te.live.waiting : _e ? te.live.working : o ? W : void 0, he = Fs({ messages: e, older: p || t ? void 0 : u, active: !U && !p && !t });
9704
9709
  return /* @__PURE__ */ d(fr, { className: ["prime-blocks", H].filter(Boolean).join(" "), children: [
9705
- /* @__PURE__ */ i("style", { href: "prime-blocks-layout", precedence: "default", children: qs }),
9710
+ /* @__PURE__ */ i("style", { href: "prime-blocks-layout", precedence: "default", children: Hs }),
9706
9711
  /* @__PURE__ */ d(
9707
9712
  "header",
9708
9713
  {
@@ -9788,7 +9793,7 @@ function Us({
9788
9793
  return /* @__PURE__ */ d("div", { "data-ui-message": Q.id, className: "prime-blocks__user", children: [
9789
9794
  /* @__PURE__ */ i(ir, { message: Ce, labels: $, onRetry: ii }),
9790
9795
  J?.role === "user" && !!J.attachments?.length && /* @__PURE__ */ i(
9791
- Ts,
9796
+ As,
9792
9797
  {
9793
9798
  files: J.attachments,
9794
9799
  getAttachmentUrls: z,
@@ -9806,7 +9811,7 @@ function Us({
9806
9811
  labels: $,
9807
9812
  phase: pe,
9808
9813
  liveOpen: F !== "replies",
9809
- status: xe && /* @__PURE__ */ i(Ds, { run: xe, live: te.live, copy: oe.copy, hideTools: F === "replies" }),
9814
+ status: xe && /* @__PURE__ */ i($s, { run: xe, live: te.live, copy: oe.copy, hideTools: F === "replies" }),
9810
9815
  orchestratorAvatar: m?.avatar ?? ei,
9811
9816
  first: !0,
9812
9817
  now: fe,
@@ -9815,7 +9820,7 @@ function Us({
9815
9820
  onRegenerate: D,
9816
9821
  onFeedback: O ? (ve, Ce, J) => O(ve, Ce, J) : void 0,
9817
9822
  feedbackReasons: te.feedbackReasons,
9818
- askState: Bs,
9823
+ askState: Us,
9819
9824
  onTask: ii,
9820
9825
  onAsk: ii
9821
9826
  },
@@ -9827,7 +9832,7 @@ function Us({
9827
9832
  !p && !t && /* @__PURE__ */ d(Me, { children: [
9828
9833
  he.away && /* @__PURE__ */ i("div", { className: "prime-blocks__latest", children: /* @__PURE__ */ i(Ae, { variant: "secondary", size: "sm", onClick: he.jump, children: te.latest }) }),
9829
9834
  _ && !R && !(s && _.code === "resume-failed") && /* @__PURE__ */ i("div", { className: "prime-blocks__status", children: /* @__PURE__ */ i("div", { role: "alert", children: li(v).errorText(_.code, _.status) }) }),
9830
- s ? /* @__PURE__ */ i(Es, { suspension: s, locale: v, onAnswer: l, error: _, onCancel: x, onNavigate: T }, `${s.taskId}:${s.id}`) : ge.length > 0 && /* @__PURE__ */ i(Ta, { decisions: $s(ge), labels: te.decision, onDecide: (Q, ce) => {
9835
+ s ? /* @__PURE__ */ i(js, { suspension: s, locale: v, onAnswer: l, error: _, onCancel: x, onNavigate: T }, `${s.taskId}:${s.id}`) : ge.length > 0 && /* @__PURE__ */ i(Ta, { decisions: Os(ge), labels: te.decision, onDecide: (Q, ce) => {
9831
9836
  if (!(C || typeof ce == "string"))
9832
9837
  if (ce.option !== void 0) {
9833
9838
  const xe = ge.find((pe) => pe.id === Q)?.options?.find((pe) => pe.id === ce.option);
@@ -9881,7 +9886,7 @@ function Us({
9881
9886
  ] })
9882
9887
  ] });
9883
9888
  }
9884
- const qs = `
9889
+ const Hs = `
9885
9890
  .prime-blocks.ui-th--parts { display: flex; flex-direction: column; height: 100%; min-height: 0; min-width: 0; overflow: hidden; overscroll-behavior: contain; }
9886
9891
  .prime-blocks__header { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 12px 16px; }
9887
9892
  .prime-blocks__titles { display: flex; flex-direction: column; min-width: 0; flex: 1; }
@@ -9908,7 +9913,7 @@ const qs = `
9908
9913
  .prime-blocks__clock { flex-shrink: 0; }
9909
9914
  .prime-blocks__status { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; }
9910
9915
  `, Ji = /* @__PURE__ */ new WeakMap();
9911
- function Hs({ enabled: e, panelMode: t, panelVisible: o }) {
9916
+ function Ws({ enabled: e, panelMode: t, panelVisible: o }) {
9912
9917
  const n = mt(), { controller: a, client: r } = gi(), { state: c } = xa(), { showPanel: u, hidePanel: s, setPanelMode: l } = wa(), [x, _] = I();
9913
9918
  return se(() => {
9914
9919
  let v = !0, w = Ji.get(r);
@@ -9928,7 +9933,7 @@ function Hs({ enabled: e, panelMode: t, panelVisible: o }) {
9928
9933
  onRestore: u,
9929
9934
  onPanelModeChange: l,
9930
9935
  children: (v) => /* @__PURE__ */ i(
9931
- Us,
9936
+ qs,
9932
9937
  {
9933
9938
  messages: c.messages,
9934
9939
  suspension: c.suspension,
@@ -9995,9 +10000,9 @@ function Hs({ enabled: e, panelMode: t, panelVisible: o }) {
9995
10000
  }
9996
10001
  );
9997
10002
  }
9998
- const yc = Nt(function() {
10003
+ const kc = Nt(function() {
9999
10004
  const { enabled: t, visible: o, mode: n } = wa();
10000
- return /* @__PURE__ */ i(Hs, { enabled: t, panelMode: n, panelVisible: o });
10005
+ return /* @__PURE__ */ i(Ws, { enabled: t, panelMode: n, panelVisible: o });
10001
10006
  });
10002
10007
  function Xi(e) {
10003
10008
  let t, o = "message";
@@ -10021,7 +10026,7 @@ function Xi(e) {
10021
10026
  }
10022
10027
  return { id: t, event: o, data: a };
10023
10028
  }
10024
- function Ws() {
10029
+ function Ys() {
10025
10030
  let e = "";
10026
10031
  return {
10027
10032
  push(t) {
@@ -10062,11 +10067,11 @@ const Te = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, be =
10062
10067
  const t = De(e);
10063
10068
  return t !== void 0 && !/\D/.test(t) ? t : void 0;
10064
10069
  }, Ua = (e) => e.toLowerCase().replace(/^\.+/, "");
10065
- function Ys(e, t) {
10070
+ function Vs(e, t) {
10066
10071
  const o = e.name.lastIndexOf("."), n = o >= 0 ? e.name.slice(o + 1).toLowerCase() : "";
10067
10072
  return t.allowedExtensions.length > 0 && (!n || !t.allowedExtensions.some((a) => Ua(a) === n)) ? "extension" : t.maxSizeBytes !== void 0 && e.size > t.maxSizeBytes ? "size" : "ok";
10068
10073
  }
10069
- function Vs(e) {
10074
+ function Gs(e) {
10070
10075
  const { request: t, buildStreamHeaders: o, fetch: n } = e, a = (e.baseUrl ?? "/uta-api/adviser/abc-prime").replace(/\/+$/, ""), r = (e.streamOrigin ?? "").replace(/\/+$/, ""), c = (s) => `${a}/tasks/${encodeURIComponent(s)}`, u = (s) => {
10071
10076
  if (Ze(s) === void 0) throw new $e("invalid-session-id");
10072
10077
  return `${a}/sessions/${encodeURIComponent(s)}`;
@@ -10164,7 +10169,7 @@ function Vs(e) {
10164
10169
  maxSizeBytes: me(s.maxSizeBytes)
10165
10170
  };
10166
10171
  },
10167
- checkAttachment: Ys,
10172
+ checkAttachment: Vs,
10168
10173
  async uploadAttachment(s) {
10169
10174
  if (Ze(s.sessionId) === void 0) throw new $e("invalid-session-id");
10170
10175
  const { file: l, onProgress: x } = s, _ = new FormData();
@@ -10322,7 +10327,7 @@ function Vs(e) {
10322
10327
  if (T.ok) {
10323
10328
  if (T.body) {
10324
10329
  m = T.body.getReader();
10325
- const B = new TextDecoder(), ee = Ws();
10330
+ const B = new TextDecoder(), ee = Ys();
10326
10331
  for (; !_?.aborted; ) {
10327
10332
  const { value: z, done: H } = await b(m.read());
10328
10333
  if (_?.aborted) return { kind: "aborted" };
@@ -10408,7 +10413,7 @@ function ia(e) {
10408
10413
  return "completed";
10409
10414
  }
10410
10415
  }
10411
- function Gs(e) {
10416
+ function Qs(e) {
10412
10417
  return qt(e.attachments).flatMap((t) => {
10413
10418
  const o = et(t), n = ye(o.attachmentId) ?? ye(o.id);
10414
10419
  return n ? [{
@@ -10419,7 +10424,7 @@ function Gs(e) {
10419
10424
  }] : [];
10420
10425
  });
10421
10426
  }
10422
- function Qs(e, t, o) {
10427
+ function Zs(e, t, o) {
10423
10428
  const n = /* @__PURE__ */ new Map();
10424
10429
  return qt(e.capabilities).forEach((a, r) => {
10425
10430
  const c = et(a), u = me(c.iteration) ?? 1, s = n.get(u) ?? { iteration: u, text: "", thinking: "", tools: [] }, l = ye(c.callId) ?? `${t}:${r}`, x = ye(c.capabilityName) ?? ye(c.stepRef) ?? "", _ = {
@@ -10438,7 +10443,7 @@ function Qs(e, t, o) {
10438
10443
  s.tools.push(_), n.set(u, s);
10439
10444
  }), [...n.values()].sort((a, r) => a.iteration - r.iteration);
10440
10445
  }
10441
- function Zs(e) {
10446
+ function Ks(e) {
10442
10447
  return qt(et(e.ui).directives).flatMap((t) => {
10443
10448
  const o = et(t);
10444
10449
  return o.type !== "next_questions" ? [] : qt(o.items).flatMap((n) => {
@@ -10467,7 +10472,7 @@ function aa(e) {
10467
10472
  role: "user",
10468
10473
  createdAt: u,
10469
10474
  text: (ye(a.content) ?? "").replace(/^\s*<page-context-notice>[\s\S]*?<\/page-context-notice>\s*/, ""),
10470
- attachments: Gs(r)
10475
+ attachments: Qs(r)
10471
10476
  });
10472
10477
  const l = ia(a.taskStatus);
10473
10478
  s && !o.has(s) && (l === "running" || l === "waiting" || ye(a.taskStatus)?.toUpperCase() === "FAILED") && (n.push({ id: `${c}:live`, role: "assistant", createdAt: u, run: { ...pi(s, u), status: l } }), o.add(s));
@@ -10482,8 +10487,8 @@ function aa(e) {
10482
10487
  status: x,
10483
10488
  answer: { text: x === "cancelled" ? "" : ye(a.content) ?? "", final: !0 },
10484
10489
  prepare: { status: "done" },
10485
- turns: Qs(l, c, u),
10486
- followUps: Zs(l),
10490
+ turns: Zs(l, c, u),
10491
+ followUps: Ks(l),
10487
10492
  startedAt: me(l.startedAt) ?? ai(l.startedAt, u),
10488
10493
  endedAt: me(l.endedAt) ?? ai(l.endedAt, u),
10489
10494
  asks: []
@@ -10498,14 +10503,14 @@ const na = {
10498
10503
  CLIENT: "CLIENT",
10499
10504
  PRODUCT: "PRODUCT"
10500
10505
  };
10501
- function Ks(e) {
10506
+ function Js(e) {
10502
10507
  return !e || e.pending ? null : e.scopeId ? `${e.scopeType}:${e.scopeId}` : e.scopeType;
10503
10508
  }
10504
- function Js(e) {
10509
+ function Xs(e) {
10505
10510
  return !e || e.pending || !e.scopeId ? {} : e.scopeType === na.CLIENT ? { clientId: e.scopeId } : e.scopeType === na.PRODUCT ? { productId: e.scopeId } : {};
10506
10511
  }
10507
10512
  const Se = (e) => e && typeof e == "object" && !Array.isArray(e) ? e : {}, Ee = (e) => typeof e == "string" && e !== "" ? e : void 0, mi = (e) => Array.isArray(e) ? e.filter((t) => typeof t == "string") : [];
10508
- function Xs(e, t) {
10513
+ function ec(e, t) {
10509
10514
  const o = Array.isArray(e.oneOf) ? e.oneOf : e.anyOf;
10510
10515
  let n;
10511
10516
  if (Array.isArray(o) && o.some((r) => Se(r).const !== void 0))
@@ -10532,8 +10537,8 @@ function Xs(e, t) {
10532
10537
  }];
10533
10538
  });
10534
10539
  }
10535
- function ec(e, t, o) {
10536
- const n = Se(o.properties), a = Se(n[e]), r = typeof a.type == "string" ? a.type : mi(a.type).find((_) => _ !== "null"), c = Xs(r === "array" ? Se(a.items) : a, t.options), u = r === "array" ? "multi" : r === "boolean" ? "boolean" : c !== void 0 ? "single" : r === "number" || r === "integer" ? "number" : "text", s = `${e}_custom`, l = Object.hasOwn(n, s), x = {
10540
+ function tc(e, t, o) {
10541
+ const n = Se(o.properties), a = Se(n[e]), r = typeof a.type == "string" ? a.type : mi(a.type).find((_) => _ !== "null"), c = ec(r === "array" ? Se(a.items) : a, t.options), u = r === "array" ? "multi" : r === "boolean" ? "boolean" : c !== void 0 ? "single" : r === "number" || r === "integer" ? "number" : "text", s = `${e}_custom`, l = Object.hasOwn(n, s), x = {
10537
10542
  id: e,
10538
10543
  question: String(t.message ?? t.title ?? a.title ?? a.description ?? e),
10539
10544
  type: u,
@@ -10605,13 +10610,13 @@ function oa(e) {
10605
10610
  const k = /* @__PURE__ */ new Set([...m.keys(), ...Object.keys(v)]), y = [];
10606
10611
  for (const f of k) {
10607
10612
  if (f.endsWith("_custom")) continue;
10608
- const b = ec(f, m.get(f) ?? {}, _);
10613
+ const b = tc(f, m.get(f) ?? {}, _);
10609
10614
  if (!b) return;
10610
10615
  y.push(b);
10611
10616
  }
10612
10617
  return y.length ? { ...l, kind: "questions", steps: y } : void 0;
10613
10618
  }
10614
- function tc(e, t) {
10619
+ function ic(e, t) {
10615
10620
  if (t === void 0) return;
10616
10621
  const o = () => new Error(`invalid-answer:${e.id}`), n = (r) => {
10617
10622
  const c = e.options?.find((u) => u.id === r);
@@ -10638,7 +10643,7 @@ function tc(e, t) {
10638
10643
  return a;
10639
10644
  }
10640
10645
  }
10641
- function ic(e, t) {
10646
+ function ac(e, t) {
10642
10647
  if (e.kind === "approval" && !e.readOnly && t.kind === "approval") {
10643
10648
  const o = t.comment ?? "";
10644
10649
  if (t.decision === "reject") return { action: "REJECT", payload: { comment: o } };
@@ -10648,7 +10653,7 @@ function ic(e, t) {
10648
10653
  if (e.kind === "questions" && t.kind === "questions") {
10649
10654
  const o = [];
10650
10655
  for (const n of e.steps) {
10651
- const a = tc(n, Object.hasOwn(t.values, n.id) ? t.values[n.id] : void 0), r = n.customField ? t.custom?.[n.id]?.trim() : void 0;
10656
+ const a = ic(n, Object.hasOwn(t.values, n.id) ? t.values[n.id] : void 0), r = n.customField ? t.custom?.[n.id]?.trim() : void 0;
10652
10657
  if (a === void 0 && !r && n.required) throw new Error(`missing-required:${n.id}`);
10653
10658
  a !== void 0 && o.push([n.id, a]), r && n.customField && o.push([n.customField, r]);
10654
10659
  }
@@ -10656,7 +10661,7 @@ function ic(e, t) {
10656
10661
  }
10657
10662
  throw new Error("answer-kind-mismatch");
10658
10663
  }
10659
- const ac = 1e4, ra = () => ({
10664
+ const nc = 1e4, ra = () => ({
10660
10665
  messages: [],
10661
10666
  phase: "idle",
10662
10667
  connection: "online",
@@ -10687,7 +10692,7 @@ function Re(e, t) {
10687
10692
  ), t.aborted && a();
10688
10693
  });
10689
10694
  }
10690
- function nc(e) {
10695
+ function oc(e) {
10691
10696
  const { client: t, pageSize: o = 20, stopPoll: n = { intervalMs: 1500, timeoutMs: 3e4 }, getTraceId: a, provisioning: r = !1 } = e;
10692
10697
  let c = ra();
10693
10698
  r && (c.provisioning = {
@@ -10737,7 +10742,7 @@ function nc(e) {
10737
10742
  return;
10738
10743
  }
10739
10744
  v = void 0;
10740
- const A = Ks(p);
10745
+ const A = Js(p);
10741
10746
  if (A === null || A === _) return;
10742
10747
  _ = A;
10743
10748
  const C = w;
@@ -10799,7 +10804,7 @@ function nc(e) {
10799
10804
  if (!P(p.view) || f !== p || p.stream.signal.aborted) return;
10800
10805
  const h = B(p);
10801
10806
  if (!h) return;
10802
- const N = vs(h.run, C);
10807
+ const N = ys(h.run, C);
10803
10808
  C.event.toUpperCase() === "FINAL_MESSAGE_COMPLETED" && N.run !== h.run && (p.finalReceived = !0), (N.run !== h.run || N.title !== void 0) && T({
10804
10809
  messages: N.run === h.run ? c.messages : ee(h.id, N.run),
10805
10810
  ...N.title !== void 0 ? { title: N.title } : {}
@@ -10957,7 +10962,7 @@ function nc(e) {
10957
10962
  };
10958
10963
  },
10959
10964
  setScope: Z,
10960
- keepSessionOnNextScopeChange(p = ac) {
10965
+ keepSessionOnNextScopeChange(p = nc) {
10961
10966
  u || (w = Date.now() + p);
10962
10967
  },
10963
10968
  async provision() {
@@ -11039,7 +11044,7 @@ function nc(e) {
11039
11044
  async send(p, A) {
11040
11045
  if (u || O()) return;
11041
11046
  if (c.phase !== "idle" || b) throw new $e("busy");
11042
- const C = Js(x);
11047
+ const C = Xs(x);
11043
11048
  let h;
11044
11049
  try {
11045
11050
  const R = a?.();
@@ -11103,7 +11108,7 @@ function nc(e) {
11103
11108
  if (u || O() || !A || b || c.phase !== "idle") return;
11104
11109
  let C;
11105
11110
  try {
11106
- C = ic(A, p);
11111
+ C = ac(A, p);
11107
11112
  } catch (h) {
11108
11113
  T({ error: { code: h instanceof Error ? h.message : "invalid-answer" } });
11109
11114
  return;
@@ -11169,11 +11174,11 @@ function nc(e) {
11169
11174
  };
11170
11175
  }
11171
11176
  const ca = () => {
11172
- }, oc = () => "", rc = [];
11173
- function sc(e = {}) {
11177
+ }, rc = () => "", sc = [];
11178
+ function cc(e = {}) {
11174
11179
  return {
11175
11180
  locale: e.locale ?? "en",
11176
- getTraceId: e.getTraceId ?? oc,
11181
+ getTraceId: e.getTraceId ?? rc,
11177
11182
  onNavigate: e.onNavigate ?? ca,
11178
11183
  availability: { available: e.availability?.available !== !1, message: e.availability?.message ?? "" },
11179
11184
  scope: { scopeType: e.scope?.scopeType || "GLOBAL", scopeId: e.scope?.scopeId ?? "", pending: !!e.scope?.pending },
@@ -11181,15 +11186,15 @@ function sc(e = {}) {
11181
11186
  available: e.credit.available,
11182
11187
  ...e.credit.plan ? { plan: { ...e.credit.plan } } : {}
11183
11188
  } : null,
11184
- startScreen: { greeting: e.startScreen?.greeting ?? "", prompts: e.startScreen?.prompts ?? rc },
11189
+ startScreen: { greeting: e.startScreen?.greeting ?? "", prompts: e.startScreen?.prompts ?? sc },
11185
11190
  branding: { title: e.branding?.title ?? "VIA", logo: e.branding?.logo ?? null },
11186
11191
  panel: e.panel ? { enabled: e.panel.enabled, visible: e.panel.visible, mode: e.panel.mode } : null,
11187
11192
  onPanelChange: e.onPanelChange ?? ca,
11188
11193
  processView: e.processView === "full" ? "full" : "replies"
11189
11194
  };
11190
11195
  }
11191
- function kc(e) {
11192
- const t = sc(e), o = JSON.stringify(t.startScreen.prompts.map(({ icon: y, label: f, prompt: b }) => [y, f, b])), n = je(() => t, [
11196
+ function zc(e) {
11197
+ const t = cc(e), o = JSON.stringify(t.startScreen.prompts.map(({ icon: y, label: f, prompt: b }) => [y, f, b])), n = je(() => t, [
11193
11198
  t.locale,
11194
11199
  t.getTraceId,
11195
11200
  t.onNavigate,
@@ -11223,8 +11228,8 @@ function kc(e) {
11223
11228
  let y = !1, f;
11224
11229
  return queueMicrotask(() => {
11225
11230
  if (y) return;
11226
- const b = Vs(u);
11227
- f = nc({ client: b, getTraceId: () => a.current(), provisioning: !0 }), c({ http: u, client: b, controller: f });
11231
+ const b = Gs(u);
11232
+ f = oc({ client: b, getTraceId: () => a.current(), provisioning: !0 }), c({ http: u, client: b, controller: f });
11228
11233
  }), () => {
11229
11234
  y = !0, f?.dispose();
11230
11235
  };
@@ -11238,16 +11243,16 @@ function kc(e) {
11238
11243
  }
11239
11244
  export {
11240
11245
  na as CHAT_SCOPE_TYPE,
11241
- kc as PrimeViaChatProvider,
11242
- Hs as PrimeViaChatShell,
11243
- yc as default,
11244
- Ks as scopeKeyOf,
11245
- wc as useAvailability,
11246
- _c as useChatLocale,
11247
- xc as useChatScope,
11246
+ zc as PrimeViaChatProvider,
11247
+ Ws as PrimeViaChatShell,
11248
+ kc as default,
11249
+ Js as scopeKeyOf,
11250
+ _c as useAvailability,
11251
+ bc as useChatLocale,
11252
+ wc as useChatScope,
11248
11253
  wa as usePanelState,
11249
11254
  xa as usePrimeViaChat,
11250
11255
  mt as usePrimeViaConfig,
11251
- bc as useProcessView,
11252
- vc as useProvisioning
11256
+ vc as useProcessView,
11257
+ yc as useProvisioning
11253
11258
  };
@@ -12,6 +12,8 @@ export declare function idGreater(a: string, b: string): boolean;
12
12
  export declare function createRun(taskId: string, now?: number): Run;
13
13
  /** Text the user should read as the answer right now: the confirmed final text, else the newest turn still writing */
14
14
  export declare function answerText(run: Run): string;
15
+ /** The backend joins reasoning sections without separators; restore blank lines before their headings. */
16
+ export declare function reasoningText(text: string): string;
15
17
  export type AnswerSource = {
16
18
  label: string;
17
19
  href?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@itechchoice/prime-chatkit",
3
- "version": "0.1.0-alpha.7",
3
+ "version": "0.1.0-alpha.8",
4
4
  "description": "PrimeChatKit: React chat UI for products built on the prime-chatkit SDK BFF contract. Shows the agent's work: thinking, tool calls, approvals, sources and cost.",
5
5
  "license": "SEE LICENSE IN LICENSE",
6
6
  "publishConfig": {