@djangocfg/ui-tools 2.1.344 → 2.1.346

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-QCKJVSJF.mjs';
2
+ import './chunk-2ZLKZ5VR.mjs';
3
+ import './chunk-N2XQF2OL.mjs';
4
+ //# sourceMappingURL=ChatRoot-CZMOJOGD.mjs.map
5
+ //# sourceMappingURL=ChatRoot-CZMOJOGD.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"ChatRoot-CIOFUESH.cjs"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"ChatRoot-CZMOJOGD.mjs"}
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ var chunkXYGB26BY_cjs = require('./chunk-XYGB26BY.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 chunkXYGB26BY_cjs.ChatRoot; }
12
+ });
13
+ //# sourceMappingURL=ChatRoot-VTYANC7M.cjs.map
14
+ //# sourceMappingURL=ChatRoot-VTYANC7M.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"ChatRoot-OURQVRLD.mjs"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"ChatRoot-VTYANC7M.cjs"}
@@ -147,19 +147,6 @@ function reducer(state, action) {
147
147
  }
148
148
  return state;
149
149
  }
150
- if (action.continueExisting) {
151
- const lastAssistantIdx = (() => {
152
- for (let i = state.messages.length - 1; i >= 0; i--) {
153
- if (state.messages[i].role === "assistant") return i;
154
- }
155
- return -1;
156
- })();
157
- if (lastAssistantIdx !== -1) {
158
- const msgs = state.messages.slice();
159
- msgs[lastAssistantIdx] = { ...msgs[lastAssistantIdx], isStreaming: true };
160
- return { ...state, isStreaming: true, messages: msgs };
161
- }
162
- }
163
150
  const placeholder = {
164
151
  id: action.id,
165
152
  role: "assistant",
@@ -225,13 +212,15 @@ function reducer(state, action) {
225
212
  return { ...state, messages };
226
213
  }
227
214
  case "STREAM_DONE": {
228
- const messages = patchMessageById(state.messages, action.id, (m) => ({
215
+ const patched = patchMessageById(state.messages, action.id, (m) => ({
229
216
  ...m,
230
217
  isStreaming: false,
231
218
  tokensIn: action.tokensIn ?? m.tokensIn,
232
219
  tokensOut: action.tokensOut ?? m.tokensOut,
233
220
  sources: action.sources ?? m.sources
234
221
  }));
222
+ const msg = patched.find((m) => m.id === action.id);
223
+ const messages = msg && !msg.content && !msg.toolCalls?.length ? patched.filter((m) => m.id !== action.id) : patched;
235
224
  return { ...state, isStreaming: false, messages };
236
225
  }
237
226
  case "STREAM_CANCELLED": {
@@ -253,6 +242,24 @@ _${suffix}_` : `_${suffix}_`)
253
242
  })) : state.messages;
254
243
  return { ...state, isStreaming: false, error: action.message, messages };
255
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
+ }
256
263
  case "MESSAGE_EDIT": {
257
264
  const messages = patchMessageById(state.messages, action.id, (m) => ({
258
265
  ...m,
@@ -486,20 +493,10 @@ function useChat(config) {
486
493
  attachments,
487
494
  metadata: config.metadata
488
495
  });
489
- let continueExisting = false;
490
496
  let peekedEvent = null;
491
- const firstResult = await iterator.next();
492
- if (!firstResult.done) {
493
- const ev = firstResult.value;
494
- if (ev.type === "resume_start") {
495
- continueExisting = true;
496
- } else {
497
- peekedEvent = ev;
498
- }
499
- }
500
- dispatch({ type: "STREAM_START", id: assistantId, continueExisting });
497
+ dispatch({ type: "STREAM_START", id: assistantId });
501
498
  config.onStreamStart?.(assistantId);
502
- log.stream.info("start", { sessionId, assistantId, chars: content.length, continueExisting });
499
+ log.stream.info("start", { sessionId, assistantId, chars: content.length });
503
500
  const tokenBuffer = createTokenBuffer(
504
501
  (delta) => dispatch({ type: "STREAM_CHUNK", delta })
505
502
  );
@@ -507,6 +504,16 @@ function useChat(config) {
507
504
  let charsReceived = 0;
508
505
  const t0 = performance.now();
509
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
+ }
510
517
  if (peekedEvent) handleEvent(peekedEvent);
511
518
  for await (const ev of iterator) {
512
519
  if (ctrl.signal.aborted) break;
@@ -2359,5 +2366,5 @@ function copy2(text) {
2359
2366
  __name(copy2, "copy");
2360
2367
 
2361
2368
  export { Attachments, AttachmentsGrid, AttachmentsList, CHAT_EVENT_NAME, CSS_VARS, ChatProvider, ChatRoot, Composer, DEFAULT_LABELS, DEFAULT_SIDEBAR, DEFAULT_Z_INDEX, EmptyState, ErrorBanner, HOTKEYS, JumpToLatest, LIMITS, MessageActions, MessageBubble, MessageList, STORAGE_KEYS, Sources, StreamingIndicator, ToolCalls, createId, createTokenBuffer, deriveInitials, getChatLogger, initialState, reducer, resolvePersona, useChat, useChatAudio, useChatAudioPrefs, useChatComposer, useChatContext, useChatContextOptional, useChatHistory, useChatLayout, useChatScroll };
2362
- //# sourceMappingURL=chunk-D7ISTFUS.mjs.map
2363
- //# sourceMappingURL=chunk-D7ISTFUS.mjs.map
2369
+ //# sourceMappingURL=chunk-QCKJVSJF.mjs.map
2370
+ //# sourceMappingURL=chunk-QCKJVSJF.mjs.map