@asgard-js/react 0.2.58 → 0.2.59

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.
@@ -1 +1 @@
1
- {"version":3,"file":"bot-typing-placeholder.d.ts","sourceRoot":"","sources":["../../../../src/components/templates/text-template/bot-typing-placeholder.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAW,MAAM,OAAO,CAAC;AAI3C,UAAU,yBAAyB;IACjC,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,SAAS,CAahF"}
1
+ {"version":3,"file":"bot-typing-placeholder.d.ts","sourceRoot":"","sources":["../../../../src/components/templates/text-template/bot-typing-placeholder.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAW,MAAM,OAAO,CAAC;AAI3C,UAAU,yBAAyB;IACjC,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,yBAAyB,GAAG,SAAS,CAgChF"}
@@ -1 +1 @@
1
- {"version":3,"file":"tool-call-consent-gate.d.ts","sourceRoot":"","sources":["../../../src/components/tool-call-consent/tool-call-consent-gate.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA4C,MAAM,OAAO,CAAC;AAe5E;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,IAAI,SAAS,CAuJ/C"}
1
+ {"version":3,"file":"tool-call-consent-gate.d.ts","sourceRoot":"","sources":["../../../src/components/tool-call-consent/tool-call-consent-gate.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAA4C,MAAM,OAAO,CAAC;AAe5E;;;;;;;;;;;GAWG;AACH,wBAAgB,mBAAmB,IAAI,SAAS,CAmL/C"}
@@ -1 +1 @@
1
- {"version":3,"file":"use-channel.d.ts","sourceRoot":"","sources":["../../src/hooks/use-channel.ts"],"names":[],"mappings":"AAAA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AAO,CAAC;IACrB,YAAY,EAAE,OAAO,CAAC;IACtB,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;IAClC,WAAW,CAAC,EAAE,CACZ,OAAO,EAAE,IAAI,CAAC,eAAe,EAAE,MAAM,GAAG,SAAS,CAAC,GAChD,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC,GAAG;QAAE,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;QAAC,aAAa,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,KACnG,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,YAAY,CAAC,EAAE,CAAC,OAAO,CAAC,EAAE,IAAI,CAAC,eAAe,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,eAAe,EAAE,SAAS,CAAC,CAAC,KAAK,IAAI,CAAC;IAC7G,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,qBAAqB,CAAC,EAAE,CAAC,OAAO,EAAE,qBAAqB,EAAE,EAAE,OAAO,CAAC,EAAE,eAAe,CAAC,SAAS,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACnH;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,GAAG,gBAAgB,CAwQnE"}
package/dist/index.js CHANGED
@@ -136,7 +136,7 @@ function dI(e) {
136
136
  b(!1);
137
137
  },
138
138
  onSseError(O) {
139
- b(!1), O && typeof O == "object" && ("isAuthError" in O || "isBotProviderError" in O) && u?.(
139
+ b(!1), g(null), O && typeof O == "object" && ("isAuthError" in O || "isBotProviderError" in O) && u?.(
140
140
  O
141
141
  ), c?.(O);
142
142
  },
@@ -145,7 +145,11 @@ function dI(e) {
145
145
  conversation: M
146
146
  });
147
147
  }
148
- }
148
+ },
149
+ // Adopt the channel as soon as it exists — before the RESET_CHANNEL run
150
+ // completes — so a tool_call.consent emitted during reset can be replied
151
+ // to (otherwise `channel` is still null and the reply is dropped).
152
+ g
149
153
  );
150
154
  y(!0), g(I);
151
155
  },
@@ -199,7 +203,9 @@ function dI(e) {
199
203
  [p, o, l, u, c, E]
200
204
  ), D = ie(
201
205
  async (S, M) => {
202
- await p?.replyToolCallConsents(
206
+ t?.debugMode && console.log(
207
+ `[consent] use-channel.replyToolCallConsents · channel=${p ? "SET" : "NULL ← reply 會被丟掉!"}`
208
+ ), await p?.replyToolCallConsents(
203
209
  S,
204
210
  {
205
211
  onSseMessage(R) {
@@ -211,7 +217,7 @@ function dI(e) {
211
217
  M
212
218
  );
213
219
  },
214
- [p, l, E]
220
+ [p, t, l, E]
215
221
  );
216
222
  Fe(() => {
217
223
  h || !p && m && (a !== !1 ? $(r) : A());
@@ -1890,11 +1896,21 @@ function YT(e) {
1890
1896
  ] }) : null;
1891
1897
  }
1892
1898
  function pz(e) {
1893
- const { placeholder: t } = e, { isConnecting: n, messages: r } = Rt(), i = ve(
1894
- () => Array.from(r?.values() ?? []).some((o) => o.type === "bot" && o.isTyping),
1895
- [r]
1896
- );
1897
- return n && !i ? /* @__PURE__ */ C(YT, { isTyping: !0, typingText: t }) : null;
1899
+ const { placeholder: t } = e, { isConnecting: n, messages: r, pendingConsent: i } = Rt(), { hasTypingMessage: o, lastMessageIsCompletedBot: s } = ve(() => {
1900
+ const a = Array.from(r?.values() ?? []), l = a[a.length - 1];
1901
+ return {
1902
+ hasTypingMessage: a.some((u) => u.type === "bot" && u.isTyping),
1903
+ // A finished bot message as the latest entry means the bot has delivered
1904
+ // its answer; the run can linger briefly afterwards (the backend keeps it
1905
+ // open between `message.complete` and `run.done`), so suppress the
1906
+ // placeholder to stop it flashing under the already-rendered answer.
1907
+ // Tool-call messages are intentionally NOT treated this way — after a tool
1908
+ // runs the bot is still working toward its reply, so the indicator must
1909
+ // keep showing while we wait for it (otherwise the chat looks frozen).
1910
+ lastMessageIsCompletedBot: l?.type === "bot" && !l.isTyping
1911
+ };
1912
+ }, [r]);
1913
+ return n && !o && !i && !s ? /* @__PURE__ */ C(YT, { isTyping: !0, typingText: t }) : null;
1898
1914
  }
1899
1915
  const gz = "_carousel_root_v06v3_1", mz = "_carousel_time_v06v3_13", yk = {
1900
1916
  carousel_root: gz,
@@ -43478,102 +43494,108 @@ function t_(e, t) {
43478
43494
  return `${e}/${t}`;
43479
43495
  }
43480
43496
  function Ove() {
43481
- const { pendingConsent: e, replyToolCallConsents: t } = Rt(), [n, r] = be(null), i = it(/* @__PURE__ */ new Set()), o = it(!1);
43497
+ const { pendingConsent: e, replyToolCallConsents: t, client: n } = Rt(), [r, i] = be(null), o = it(/* @__PURE__ */ new Set()), s = it(null);
43482
43498
  Fe(() => {
43483
- e && r((f) => f?.processId === e.processId ? f : (i.current = /* @__PURE__ */ new Set(), o.current = !1, {
43499
+ e && i((d) => d?.processId === e.processId ? d : (o.current = /* @__PURE__ */ new Set(), {
43484
43500
  processId: e.processId,
43485
43501
  remaining: [...e.pendingCalls],
43486
43502
  answers: []
43487
43503
  }));
43488
43504
  }, [e]);
43489
- const s = ie(
43490
- async (f, d) => {
43491
- if (!o.current) {
43492
- o.current = !0;
43505
+ const a = ie(
43506
+ async (d, h) => {
43507
+ if (s.current !== h) {
43508
+ s.current = h;
43493
43509
  try {
43494
- await t?.(f);
43510
+ n?.debugMode && console.log(
43511
+ `[consent] 送出 RESPONSE_TOOL_CALL_CONSENT · pid=${h} · ${d.length} 筆 →`,
43512
+ d.map((p) => `${p.toolCallId}:${p.result}`)
43513
+ ), await t?.(d);
43495
43514
  } finally {
43496
- r((h) => h?.processId !== d ? h : (i.current = /* @__PURE__ */ new Set(), null));
43515
+ s.current === h && (s.current = null), i((p) => p?.processId !== h ? p : (o.current = /* @__PURE__ */ new Set(), null));
43497
43516
  }
43498
43517
  }
43499
43518
  },
43500
- [t]
43519
+ [t, n]
43501
43520
  );
43502
43521
  Fe(() => {
43503
- if (!n) return;
43504
- if (n.remaining.length === 0) {
43505
- s(n.answers, n.processId);
43522
+ if (!r) return;
43523
+ if (r.remaining.length === 0) {
43524
+ a(r.answers, r.processId);
43506
43525
  return;
43507
43526
  }
43508
- const f = n.remaining[0];
43509
- if (f) {
43510
- if (f.alreadyAllowed) {
43511
- r({
43512
- ...n,
43513
- remaining: n.remaining.slice(1),
43527
+ const d = r.remaining[0];
43528
+ if (d) {
43529
+ if (d.alreadyAllowed) {
43530
+ i({
43531
+ ...r,
43532
+ remaining: r.remaining.slice(1),
43514
43533
  answers: [
43515
- ...n.answers,
43516
- { toolCallId: f.toolCallId, result: yc.ALLOW_ONCE, denyReason: "" }
43534
+ ...r.answers,
43535
+ { toolCallId: d.toolCallId, result: yc.ALLOW_ONCE, denyReason: "" }
43517
43536
  ]
43518
43537
  });
43519
43538
  return;
43520
43539
  }
43521
- i.current.has(t_(f.toolsetName, f.toolName)) && r({
43522
- ...n,
43523
- remaining: n.remaining.slice(1),
43540
+ o.current.has(t_(d.toolsetName, d.toolName)) && i({
43541
+ ...r,
43542
+ remaining: r.remaining.slice(1),
43524
43543
  answers: [
43525
- ...n.answers,
43526
- { toolCallId: f.toolCallId, result: yc.ALLOW_ALWAYS, denyReason: "" }
43544
+ ...r.answers,
43545
+ { toolCallId: d.toolCallId, result: yc.ALLOW_ALWAYS, denyReason: "" }
43527
43546
  ]
43528
43547
  });
43529
43548
  }
43530
- }, [n, s]);
43531
- const a = ie((f) => {
43532
- r((d) => {
43533
- if (!d) return d;
43534
- const h = d.remaining[0];
43535
- if (!h) return d;
43536
- let p;
43537
- switch (f.result) {
43538
- case "ALLOW_ALWAYS":
43539
- i.current.add(t_(h.toolsetName, h.toolName)), p = {
43540
- toolCallId: h.toolCallId,
43541
- result: yc.ALLOW_ALWAYS,
43542
- denyReason: ""
43543
- };
43544
- break;
43545
- case "DENY_ONCE":
43546
- p = {
43547
- toolCallId: h.toolCallId,
43548
- result: yc.DENY_ONCE,
43549
- denyReason: f.denyReason
43550
- };
43551
- break;
43552
- default:
43553
- p = {
43554
- toolCallId: h.toolCallId,
43555
- result: yc.ALLOW_ONCE,
43556
- denyReason: ""
43557
- };
43558
- }
43559
- return {
43560
- ...d,
43561
- remaining: d.remaining.slice(1),
43562
- answers: [...d.answers, p]
43563
- };
43564
- });
43565
- }, []);
43566
- if (!n) return null;
43567
- const l = n.remaining[0];
43568
- if (!l || l.alreadyAllowed || i.current.has(t_(l.toolsetName, l.toolName))) return null;
43569
- const u = e?.pendingCalls.length ?? n.remaining.length + n.answers.length, c = n.answers.length + 1;
43549
+ }, [r, a]);
43550
+ const l = ie(
43551
+ (d) => {
43552
+ n?.debugMode && console.log(`[consent] 按下按鈕 → ${d.result}`), i((h) => {
43553
+ if (!h) return h;
43554
+ const p = h.remaining[0];
43555
+ if (!p) return h;
43556
+ let g;
43557
+ switch (d.result) {
43558
+ case "ALLOW_ALWAYS":
43559
+ o.current.add(t_(p.toolsetName, p.toolName)), g = {
43560
+ toolCallId: p.toolCallId,
43561
+ result: yc.ALLOW_ALWAYS,
43562
+ denyReason: ""
43563
+ };
43564
+ break;
43565
+ case "DENY_ONCE":
43566
+ g = {
43567
+ toolCallId: p.toolCallId,
43568
+ result: yc.DENY_ONCE,
43569
+ denyReason: d.denyReason
43570
+ };
43571
+ break;
43572
+ default:
43573
+ g = {
43574
+ toolCallId: p.toolCallId,
43575
+ result: yc.ALLOW_ONCE,
43576
+ denyReason: ""
43577
+ };
43578
+ }
43579
+ return {
43580
+ ...h,
43581
+ remaining: h.remaining.slice(1),
43582
+ answers: [...h.answers, g]
43583
+ };
43584
+ });
43585
+ },
43586
+ [n]
43587
+ );
43588
+ if (!r) return null;
43589
+ const u = r.remaining[0];
43590
+ if (!u || u.alreadyAllowed || o.current.has(t_(u.toolsetName, u.toolName))) return null;
43591
+ const c = e?.pendingCalls.length ?? r.remaining.length + r.answers.length, f = r.answers.length + 1;
43570
43592
  return /* @__PURE__ */ C(
43571
43593
  Rve,
43572
43594
  {
43573
- pendingCall: l,
43574
- totalCount: u,
43575
- currentIndex: c,
43576
- onDecide: a
43595
+ pendingCall: u,
43596
+ totalCount: c,
43597
+ currentIndex: f,
43598
+ onDecide: l
43577
43599
  }
43578
43600
  );
43579
43601
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@asgard-js/react",
3
- "version": "0.2.58",
3
+ "version": "0.2.59",
4
4
  "publishConfig": {
5
5
  "access": "public"
6
6
  },
@@ -47,7 +47,7 @@
47
47
  "vite-plugin-svgr": "^4.3.0"
48
48
  },
49
49
  "peerDependencies": {
50
- "@asgard-js/core": "^0.2.58",
50
+ "@asgard-js/core": "^0.2.59",
51
51
  "react": "^18.0.0 || ^19.0.0",
52
52
  "react-dom": "^18.0.0 || ^19.0.0"
53
53
  }