@djangocfg/ui-tools 2.1.337 → 2.1.338

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,14 @@
1
+ 'use strict';
2
+
3
+ var chunk5T4K3VUV_cjs = require('./chunk-5T4K3VUV.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 chunk5T4K3VUV_cjs.ChatRoot; }
12
+ });
13
+ //# sourceMappingURL=ChatRoot-BT3CLXI4.cjs.map
14
+ //# sourceMappingURL=ChatRoot-BT3CLXI4.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"ChatRoot-XV2QXMV4.mjs"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"ChatRoot-BT3CLXI4.cjs"}
@@ -0,0 +1,5 @@
1
+ export { ChatRoot } from './chunk-QE25H6DP.mjs';
2
+ import './chunk-2ZLKZ5VR.mjs';
3
+ import './chunk-N2XQF2OL.mjs';
4
+ //# sourceMappingURL=ChatRoot-R5YQTOLP.mjs.map
5
+ //# sourceMappingURL=ChatRoot-R5YQTOLP.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":[],"names":[],"mappings":"","file":"ChatRoot-YX4RLHQX.cjs"}
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"ChatRoot-R5YQTOLP.mjs"}
@@ -368,15 +368,15 @@ function useChat(config) {
368
368
  stateRef.current = state;
369
369
  const abortRef = react.useRef(null);
370
370
  const lastErrorRef = react.useRef(null);
371
- const initRef = react.useRef(false);
372
371
  const streamingMsgIdRef = react.useRef(null);
373
372
  const bootstrapRef = react.useRef(null);
374
373
  const { transport, autoCreateSession = true, streaming = true, pageSize = LIMITS.pageSize } = config;
375
374
  const log = getChatLogger(config.debug);
376
375
  react.useEffect(() => {
377
- if (initRef.current) return;
378
- initRef.current = true;
379
376
  let cancelled = false;
377
+ if (stateRef.current.sessionId) {
378
+ return;
379
+ }
380
380
  if (config.initialSessionId || autoCreateSession) {
381
381
  dispatch({ type: "HISTORY_LOAD_START" });
382
382
  }
@@ -388,14 +388,16 @@ function useChat(config) {
388
388
  const t0 = performance.now();
389
389
  try {
390
390
  if (config.initialSessionId) {
391
- dispatch({
392
- type: "SESSION_SET",
393
- sessionId: config.initialSessionId
394
- });
391
+ if (!cancelled) {
392
+ dispatch({
393
+ type: "SESSION_SET",
394
+ sessionId: config.initialSessionId
395
+ });
396
+ }
395
397
  const page = await transport.loadHistory(config.initialSessionId, null, pageSize);
396
398
  if (cancelled) {
397
399
  log.bootstrap.debug("cancelled (post-loadHistory)");
398
- return null;
400
+ return config.initialSessionId;
399
401
  }
400
402
  dispatch({
401
403
  type: "HISTORY_LOAD_DONE",
@@ -413,10 +415,6 @@ function useChat(config) {
413
415
  }
414
416
  if (autoCreateSession) {
415
417
  const info = await transport.createSession({ metadata: config.metadata });
416
- if (cancelled) {
417
- log.bootstrap.debug("cancelled (post-createSession)");
418
- return null;
419
- }
420
418
  dispatch({
421
419
  type: "SESSION_SET",
422
420
  sessionId: info.sessionId,
@@ -430,9 +428,10 @@ function useChat(config) {
430
428
  hasMore: info.hasMore ?? false,
431
429
  cursor: info.cursor ?? null
432
430
  });
433
- log.bootstrap.success("created", {
431
+ log.bootstrap.success(cancelled ? "created (post-cancel)" : "created", {
434
432
  sessionId: info.sessionId,
435
433
  resumed: info.resumed ?? false,
434
+ cancelled,
436
435
  elapsedMs: Math.round(performance.now() - t0)
437
436
  });
438
437
  return info.sessionId;
@@ -440,11 +439,11 @@ function useChat(config) {
440
439
  log.bootstrap.debug("idle (no initialSessionId, autoCreateSession=false)");
441
440
  return null;
442
441
  } catch (err) {
442
+ const e = err instanceof Error ? err : new Error(String(err));
443
443
  if (cancelled) {
444
- log.bootstrap.debug("cancelled (in catch)");
444
+ log.bootstrap.debug("cancelled (in catch)", { message: e.message });
445
445
  return null;
446
446
  }
447
- const e = err instanceof Error ? err : new Error(String(err));
448
447
  lastErrorRef.current = e;
449
448
  dispatch({ type: "ERROR_SET", error: e.message });
450
449
  config.onError?.(e);
@@ -2375,5 +2374,5 @@ exports.useChatContextOptional = useChatContextOptional;
2375
2374
  exports.useChatHistory = useChatHistory;
2376
2375
  exports.useChatLayout = useChatLayout;
2377
2376
  exports.useChatScroll = useChatScroll;
2378
- //# sourceMappingURL=chunk-ZWPBBAR2.cjs.map
2379
- //# sourceMappingURL=chunk-ZWPBBAR2.cjs.map
2377
+ //# sourceMappingURL=chunk-5T4K3VUV.cjs.map
2378
+ //# sourceMappingURL=chunk-5T4K3VUV.cjs.map