@xinghunm/ai-chat 1.4.3 → 1.4.4

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.d.mts CHANGED
@@ -739,6 +739,7 @@ interface ChatState {
739
739
  sessionMessageLoadErrorBySession: Record<string, string | null>;
740
740
  historyMessagePaginationBySession: Record<string, ChatHistoryMessagePaginationState>;
741
741
  timelineAnchorStateBySession: Record<string, Record<string, ChatTimelineAnchorStateSnapshot>>;
742
+ newlyCreatedSessionIds: string[];
742
743
  }
743
744
  interface ChatHistoryMessagePaginationState {
744
745
  previousCursor: string | null;
package/dist/index.d.ts CHANGED
@@ -739,6 +739,7 @@ interface ChatState {
739
739
  sessionMessageLoadErrorBySession: Record<string, string | null>;
740
740
  historyMessagePaginationBySession: Record<string, ChatHistoryMessagePaginationState>;
741
741
  timelineAnchorStateBySession: Record<string, Record<string, ChatTimelineAnchorStateSnapshot>>;
742
+ newlyCreatedSessionIds: string[];
742
743
  }
743
744
  interface ChatHistoryMessagePaginationState {
744
745
  previousCursor: string | null;
package/dist/index.js CHANGED
@@ -262,6 +262,7 @@ var createChatStore = (initialState) => (0, import_vanilla.createStore)((set, ge
262
262
  sessionMessageLoadErrorBySession: {},
263
263
  historyMessagePaginationBySession: {},
264
264
  timelineAnchorStateBySession: {},
265
+ newlyCreatedSessionIds: [],
265
266
  // ---- Session management ------------------------------------------------
266
267
  createSession: (session) => {
267
268
  const state = get();
@@ -393,6 +394,7 @@ var createChatStore = (initialState) => (0, import_vanilla.createStore)((set, ge
393
394
  delete nextTimelineAnchorStateBySession[previousSessionId];
394
395
  }
395
396
  const nextActiveSessionId = state.activeSessionId === previousSessionId ? nextSessionId : state.activeSessionId;
397
+ const nextNewlyCreatedSessionIds = state.newlyCreatedSessionIds.includes(nextSessionId) ? state.newlyCreatedSessionIds : [...state.newlyCreatedSessionIds.filter((id) => id !== previousSessionId), nextSessionId];
396
398
  set({
397
399
  sessions: nextSessions,
398
400
  messagesBySession: nextMessagesBySession,
@@ -404,7 +406,8 @@ var createChatStore = (initialState) => (0, import_vanilla.createStore)((set, ge
404
406
  sessionMessageLoadErrorBySession: nextSessionMessageLoadErrorBySession,
405
407
  historyMessagePaginationBySession: nextHistoryMessagePaginationBySession,
406
408
  timelineAnchorStateBySession: nextTimelineAnchorStateBySession,
407
- activeSessionId: nextActiveSessionId
409
+ activeSessionId: nextActiveSessionId,
410
+ newlyCreatedSessionIds: nextNewlyCreatedSessionIds
408
411
  });
409
412
  },
410
413
  setPreferredMode: (mode) => {
@@ -421,15 +424,28 @@ var createChatStore = (initialState) => (0, import_vanilla.createStore)((set, ge
421
424
  const hasActiveInIncoming = sessions.some(
422
425
  (session) => session.sessionId === state.activeSessionId
423
426
  );
424
- const keepActiveSession = activePersistedSession && !hasActiveInIncoming ? [activePersistedSession] : [];
427
+ let prependActiveSession = [];
428
+ let appendActiveSession = [];
429
+ if (activePersistedSession && !hasActiveInIncoming) {
430
+ const isNewlyCreated = state.newlyCreatedSessionIds.includes(
431
+ activePersistedSession.sessionId
432
+ );
433
+ if (isNewlyCreated) {
434
+ prependActiveSession = [activePersistedSession];
435
+ } else {
436
+ appendActiveSession = [activePersistedSession];
437
+ }
438
+ }
425
439
  const excludeIds = /* @__PURE__ */ new Set([
426
440
  ...draftSessions.map((s) => s.sessionId),
427
- ...keepActiveSession.map((s) => s.sessionId)
441
+ ...prependActiveSession.map((s) => s.sessionId),
442
+ ...appendActiveSession.map((s) => s.sessionId)
428
443
  ]);
429
444
  const nextSessions = [
430
445
  ...draftSessions,
446
+ ...prependActiveSession,
431
447
  ...sessions.filter((session) => !excludeIds.has(session.sessionId)),
432
- ...keepActiveSession
448
+ ...appendActiveSession
433
449
  ];
434
450
  const nextMessagesBySession = { ...state.messagesBySession };
435
451
  const nextErrorBySession = { ...state.errorBySession };
@@ -465,6 +481,10 @@ var createChatStore = (initialState) => (0, import_vanilla.createStore)((set, ge
465
481
  nextHistoryMessagePaginationBySession[sid] = createHistoryMessagePaginationState();
466
482
  }
467
483
  });
484
+ const incomingSessionIds = new Set(sessions.map((s) => s.sessionId));
485
+ const nextNewlyCreatedSessionIds = state.newlyCreatedSessionIds.filter(
486
+ (id) => !incomingSessionIds.has(id)
487
+ );
468
488
  set({
469
489
  sessions: nextSessions,
470
490
  messagesBySession: nextMessagesBySession,
@@ -474,7 +494,8 @@ var createChatStore = (initialState) => (0, import_vanilla.createStore)((set, ge
474
494
  sessionMessageLoadStatusBySession: nextSessionMessageLoadStatusBySession,
475
495
  sessionMessageLoadErrorBySession: nextSessionMessageLoadErrorBySession,
476
496
  historyMessagePaginationBySession: nextHistoryMessagePaginationBySession,
477
- timelineAnchorStateBySession: nextTimelineAnchorStateBySession
497
+ timelineAnchorStateBySession: nextTimelineAnchorStateBySession,
498
+ newlyCreatedSessionIds: nextNewlyCreatedSessionIds
478
499
  });
479
500
  },
480
501
  // ---- Message operations ------------------------------------------------
package/dist/index.mjs CHANGED
@@ -215,6 +215,7 @@ var createChatStore = (initialState) => createStore((set, get) => ({
215
215
  sessionMessageLoadErrorBySession: {},
216
216
  historyMessagePaginationBySession: {},
217
217
  timelineAnchorStateBySession: {},
218
+ newlyCreatedSessionIds: [],
218
219
  // ---- Session management ------------------------------------------------
219
220
  createSession: (session) => {
220
221
  const state = get();
@@ -346,6 +347,7 @@ var createChatStore = (initialState) => createStore((set, get) => ({
346
347
  delete nextTimelineAnchorStateBySession[previousSessionId];
347
348
  }
348
349
  const nextActiveSessionId = state.activeSessionId === previousSessionId ? nextSessionId : state.activeSessionId;
350
+ const nextNewlyCreatedSessionIds = state.newlyCreatedSessionIds.includes(nextSessionId) ? state.newlyCreatedSessionIds : [...state.newlyCreatedSessionIds.filter((id) => id !== previousSessionId), nextSessionId];
349
351
  set({
350
352
  sessions: nextSessions,
351
353
  messagesBySession: nextMessagesBySession,
@@ -357,7 +359,8 @@ var createChatStore = (initialState) => createStore((set, get) => ({
357
359
  sessionMessageLoadErrorBySession: nextSessionMessageLoadErrorBySession,
358
360
  historyMessagePaginationBySession: nextHistoryMessagePaginationBySession,
359
361
  timelineAnchorStateBySession: nextTimelineAnchorStateBySession,
360
- activeSessionId: nextActiveSessionId
362
+ activeSessionId: nextActiveSessionId,
363
+ newlyCreatedSessionIds: nextNewlyCreatedSessionIds
361
364
  });
362
365
  },
363
366
  setPreferredMode: (mode) => {
@@ -374,15 +377,28 @@ var createChatStore = (initialState) => createStore((set, get) => ({
374
377
  const hasActiveInIncoming = sessions.some(
375
378
  (session) => session.sessionId === state.activeSessionId
376
379
  );
377
- const keepActiveSession = activePersistedSession && !hasActiveInIncoming ? [activePersistedSession] : [];
380
+ let prependActiveSession = [];
381
+ let appendActiveSession = [];
382
+ if (activePersistedSession && !hasActiveInIncoming) {
383
+ const isNewlyCreated = state.newlyCreatedSessionIds.includes(
384
+ activePersistedSession.sessionId
385
+ );
386
+ if (isNewlyCreated) {
387
+ prependActiveSession = [activePersistedSession];
388
+ } else {
389
+ appendActiveSession = [activePersistedSession];
390
+ }
391
+ }
378
392
  const excludeIds = /* @__PURE__ */ new Set([
379
393
  ...draftSessions.map((s) => s.sessionId),
380
- ...keepActiveSession.map((s) => s.sessionId)
394
+ ...prependActiveSession.map((s) => s.sessionId),
395
+ ...appendActiveSession.map((s) => s.sessionId)
381
396
  ]);
382
397
  const nextSessions = [
383
398
  ...draftSessions,
399
+ ...prependActiveSession,
384
400
  ...sessions.filter((session) => !excludeIds.has(session.sessionId)),
385
- ...keepActiveSession
401
+ ...appendActiveSession
386
402
  ];
387
403
  const nextMessagesBySession = { ...state.messagesBySession };
388
404
  const nextErrorBySession = { ...state.errorBySession };
@@ -418,6 +434,10 @@ var createChatStore = (initialState) => createStore((set, get) => ({
418
434
  nextHistoryMessagePaginationBySession[sid] = createHistoryMessagePaginationState();
419
435
  }
420
436
  });
437
+ const incomingSessionIds = new Set(sessions.map((s) => s.sessionId));
438
+ const nextNewlyCreatedSessionIds = state.newlyCreatedSessionIds.filter(
439
+ (id) => !incomingSessionIds.has(id)
440
+ );
421
441
  set({
422
442
  sessions: nextSessions,
423
443
  messagesBySession: nextMessagesBySession,
@@ -427,7 +447,8 @@ var createChatStore = (initialState) => createStore((set, get) => ({
427
447
  sessionMessageLoadStatusBySession: nextSessionMessageLoadStatusBySession,
428
448
  sessionMessageLoadErrorBySession: nextSessionMessageLoadErrorBySession,
429
449
  historyMessagePaginationBySession: nextHistoryMessagePaginationBySession,
430
- timelineAnchorStateBySession: nextTimelineAnchorStateBySession
450
+ timelineAnchorStateBySession: nextTimelineAnchorStateBySession,
451
+ newlyCreatedSessionIds: nextNewlyCreatedSessionIds
431
452
  });
432
453
  },
433
454
  // ---- Message operations ------------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xinghunm/ai-chat",
3
- "version": "1.4.3",
3
+ "version": "1.4.4",
4
4
  "description": "AI chat React component library",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
@@ -19,7 +19,7 @@
19
19
  "peerDependencies": {
20
20
  "@emotion/react": ">=11",
21
21
  "@emotion/styled": ">=11",
22
- "@xinghunm/compass-ui": "0.9.0",
22
+ "@xinghunm/compass-ui": "0.8.3",
23
23
  "axios": ">=1.0",
24
24
  "react": ">=18",
25
25
  "react-dom": ">=18",