@djangocfg/ui-tools 2.1.344 → 2.1.345

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.
@@ -0,0 +1,5 @@
1
+ export { ChatRoot } from './chunk-OMUJNA42.mjs';
2
+ import './chunk-2ZLKZ5VR.mjs';
3
+ import './chunk-N2XQF2OL.mjs';
4
+ //# sourceMappingURL=ChatRoot-APZXBHDT.mjs.map
5
+ //# sourceMappingURL=ChatRoot-APZXBHDT.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"ChatRoot-CIOFUESH.cjs"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"ChatRoot-APZXBHDT.mjs"}
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ var chunkHE3N2ACJ_cjs = require('./chunk-HE3N2ACJ.cjs');
4
+ require('./chunk-B5AWZOHJ.cjs');
5
+ require('./chunk-OLISEQHS.cjs');
6
+
7
+
8
+
9
+ Object.defineProperty(exports, "ChatRoot", {
10
+ enumerable: true,
11
+ get: function () { return chunkHE3N2ACJ_cjs.ChatRoot; }
12
+ });
13
+ //# sourceMappingURL=ChatRoot-RU7MQUXF.cjs.map
14
+ //# sourceMappingURL=ChatRoot-RU7MQUXF.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"ChatRoot-OURQVRLD.mjs"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"ChatRoot-RU7MQUXF.cjs"}
@@ -149,19 +149,6 @@ function reducer(state, action) {
149
149
  }
150
150
  return state;
151
151
  }
152
- if (action.continueExisting) {
153
- const lastAssistantIdx = (() => {
154
- for (let i = state.messages.length - 1; i >= 0; i--) {
155
- if (state.messages[i].role === "assistant") return i;
156
- }
157
- return -1;
158
- })();
159
- if (lastAssistantIdx !== -1) {
160
- const msgs = state.messages.slice();
161
- msgs[lastAssistantIdx] = { ...msgs[lastAssistantIdx], isStreaming: true };
162
- return { ...state, isStreaming: true, messages: msgs };
163
- }
164
- }
165
152
  const placeholder = {
166
153
  id: action.id,
167
154
  role: "assistant",
@@ -255,6 +242,24 @@ _${suffix}_` : `_${suffix}_`)
255
242
  })) : state.messages;
256
243
  return { ...state, isStreaming: false, error: action.message, messages };
257
244
  }
245
+ case "STREAM_CANCEL_PLACEHOLDER":
246
+ return {
247
+ ...state,
248
+ isStreaming: false,
249
+ messages: state.messages.filter((m) => m.id !== action.id)
250
+ };
251
+ case "STREAM_RESUME_EXISTING": {
252
+ const lastIdx = (() => {
253
+ for (let i = state.messages.length - 1; i >= 0; i--) {
254
+ if (state.messages[i].role === "assistant") return i;
255
+ }
256
+ return -1;
257
+ })();
258
+ if (lastIdx === -1) return { ...state, isStreaming: true };
259
+ const msgs = state.messages.slice();
260
+ msgs[lastIdx] = { ...msgs[lastIdx], isStreaming: true };
261
+ return { ...state, isStreaming: true, messages: msgs };
262
+ }
258
263
  case "MESSAGE_EDIT": {
259
264
  const messages = patchMessageById(state.messages, action.id, (m) => ({
260
265
  ...m,
@@ -488,20 +493,10 @@ function useChat(config) {
488
493
  attachments,
489
494
  metadata: config.metadata
490
495
  });
491
- let continueExisting = false;
492
496
  let peekedEvent = null;
493
- const firstResult = await iterator.next();
494
- if (!firstResult.done) {
495
- const ev = firstResult.value;
496
- if (ev.type === "resume_start") {
497
- continueExisting = true;
498
- } else {
499
- peekedEvent = ev;
500
- }
501
- }
502
- dispatch({ type: "STREAM_START", id: assistantId, continueExisting });
497
+ dispatch({ type: "STREAM_START", id: assistantId });
503
498
  config.onStreamStart?.(assistantId);
504
- log.stream.info("start", { sessionId, assistantId, chars: content.length, continueExisting });
499
+ log.stream.info("start", { sessionId, assistantId, chars: content.length });
505
500
  const tokenBuffer = createTokenBuffer(
506
501
  (delta) => dispatch({ type: "STREAM_CHUNK", delta })
507
502
  );
@@ -509,6 +504,16 @@ function useChat(config) {
509
504
  let charsReceived = 0;
510
505
  const t0 = performance.now();
511
506
  try {
507
+ const firstResult = await iterator.next();
508
+ if (!firstResult.done) {
509
+ const ev = firstResult.value;
510
+ if (ev.type === "resume_start") {
511
+ dispatch({ type: "STREAM_CANCEL_PLACEHOLDER", id: assistantId });
512
+ dispatch({ type: "STREAM_RESUME_EXISTING" });
513
+ } else {
514
+ peekedEvent = ev;
515
+ }
516
+ }
512
517
  if (peekedEvent) handleEvent(peekedEvent);
513
518
  for await (const ev of iterator) {
514
519
  if (ctrl.signal.aborted) break;
@@ -2399,5 +2404,5 @@ exports.useChatContextOptional = useChatContextOptional;
2399
2404
  exports.useChatHistory = useChatHistory;
2400
2405
  exports.useChatLayout = useChatLayout;
2401
2406
  exports.useChatScroll = useChatScroll;
2402
- //# sourceMappingURL=chunk-AK2VHUJV.cjs.map
2403
- //# sourceMappingURL=chunk-AK2VHUJV.cjs.map
2407
+ //# sourceMappingURL=chunk-HE3N2ACJ.cjs.map
2408
+ //# sourceMappingURL=chunk-HE3N2ACJ.cjs.map