@gendive/chatllm 0.13.1 → 0.14.0

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.
@@ -444,6 +444,12 @@ interface ThemeConfig {
444
444
  borderRadius?: 'none' | 'sm' | 'md' | 'lg' | 'xl';
445
445
  }
446
446
  interface ChatUIProps {
447
+ /**
448
+ * @description 외부에서 생성한 useChatUI 상태 주입
449
+ * @Todo vibecode - 레이아웃 수준에서 hook 초기화 후 ChatUI와 ChatSidebar에 공유할 때 사용
450
+ * 제공 시 ChatUI 내부에서 useChatUI를 호출하지 않고 이 상태를 직접 사용
451
+ */
452
+ chatState?: UseChatUIReturn;
447
453
  /** 사용 가능한 모델 목록 (기본값 제공) */
448
454
  models?: ModelConfig[];
449
455
  /** 사용 가능한 Actions */
@@ -452,6 +458,8 @@ interface ChatUIProps {
452
458
  templates?: PromptTemplate[];
453
459
  /** 개인화 설정 */
454
460
  personalization?: Partial<PersonalizationConfig>;
461
+ /** @Todo vibecode - 개인화 설정 변경 콜백 (백엔드 저장용) */
462
+ onPersonalizationChange?: (config: PersonalizationConfig) => void;
455
463
  /** API 키 (DevDive 등 외부 프로바이더용) */
456
464
  apiKey?: string;
457
465
  /** API 키 변경 핸들러 */
@@ -476,6 +484,8 @@ interface ChatUIProps {
476
484
  keepRecentMessages?: number;
477
485
  /** 스토리지 키 (로컬 저장용) */
478
486
  storageKey?: string;
487
+ /** @Todo vibecode - 초기 선택 세션 ID (미제공 시 sessions[0] 자동 선택) */
488
+ initialSessionId?: string;
479
489
  /** CSS 클래스 */
480
490
  className?: string;
481
491
  /** 메시지 전송 핸들러 (커스텀 API 사용 시) */
@@ -885,6 +895,10 @@ interface UseChatUIReturn {
885
895
  * 풀 기능 채팅 UI
886
896
  */
887
897
 
898
+ /**
899
+ * @description ChatUI 메인 컴포넌트
900
+ * @Todo vibecode - chatState 제공 시 외부 상태 사용, 미제공 시 내부 useChatUI 호출
901
+ */
888
902
  declare const ChatUI: React$1.FC<ChatUIProps>;
889
903
 
890
904
  /**
@@ -899,6 +913,10 @@ interface UseChatUIOptions {
899
913
  actions?: ActionItem[];
900
914
  /** 초기 개인화 설정 */
901
915
  initialPersonalization?: Partial<PersonalizationConfig>;
916
+ /** @Todo vibecode - 개인화 설정 변경 콜백 (백엔드 저장용) */
917
+ onPersonalizationChange?: (config: PersonalizationConfig) => void;
918
+ /** @Todo vibecode - 초기 선택 세션 ID (미제공 시 sessions[0] 자동 선택) */
919
+ initialSessionId?: string;
902
920
  /** API 키 */
903
921
  apiKey?: string;
904
922
  /** API 엔드포인트 */
@@ -444,6 +444,12 @@ interface ThemeConfig {
444
444
  borderRadius?: 'none' | 'sm' | 'md' | 'lg' | 'xl';
445
445
  }
446
446
  interface ChatUIProps {
447
+ /**
448
+ * @description 외부에서 생성한 useChatUI 상태 주입
449
+ * @Todo vibecode - 레이아웃 수준에서 hook 초기화 후 ChatUI와 ChatSidebar에 공유할 때 사용
450
+ * 제공 시 ChatUI 내부에서 useChatUI를 호출하지 않고 이 상태를 직접 사용
451
+ */
452
+ chatState?: UseChatUIReturn;
447
453
  /** 사용 가능한 모델 목록 (기본값 제공) */
448
454
  models?: ModelConfig[];
449
455
  /** 사용 가능한 Actions */
@@ -452,6 +458,8 @@ interface ChatUIProps {
452
458
  templates?: PromptTemplate[];
453
459
  /** 개인화 설정 */
454
460
  personalization?: Partial<PersonalizationConfig>;
461
+ /** @Todo vibecode - 개인화 설정 변경 콜백 (백엔드 저장용) */
462
+ onPersonalizationChange?: (config: PersonalizationConfig) => void;
455
463
  /** API 키 (DevDive 등 외부 프로바이더용) */
456
464
  apiKey?: string;
457
465
  /** API 키 변경 핸들러 */
@@ -476,6 +484,8 @@ interface ChatUIProps {
476
484
  keepRecentMessages?: number;
477
485
  /** 스토리지 키 (로컬 저장용) */
478
486
  storageKey?: string;
487
+ /** @Todo vibecode - 초기 선택 세션 ID (미제공 시 sessions[0] 자동 선택) */
488
+ initialSessionId?: string;
479
489
  /** CSS 클래스 */
480
490
  className?: string;
481
491
  /** 메시지 전송 핸들러 (커스텀 API 사용 시) */
@@ -885,6 +895,10 @@ interface UseChatUIReturn {
885
895
  * 풀 기능 채팅 UI
886
896
  */
887
897
 
898
+ /**
899
+ * @description ChatUI 메인 컴포넌트
900
+ * @Todo vibecode - chatState 제공 시 외부 상태 사용, 미제공 시 내부 useChatUI 호출
901
+ */
888
902
  declare const ChatUI: React$1.FC<ChatUIProps>;
889
903
 
890
904
  /**
@@ -899,6 +913,10 @@ interface UseChatUIOptions {
899
913
  actions?: ActionItem[];
900
914
  /** 초기 개인화 설정 */
901
915
  initialPersonalization?: Partial<PersonalizationConfig>;
916
+ /** @Todo vibecode - 개인화 설정 변경 콜백 (백엔드 저장용) */
917
+ onPersonalizationChange?: (config: PersonalizationConfig) => void;
918
+ /** @Todo vibecode - 초기 선택 세션 ID (미제공 시 sessions[0] 자동 선택) */
919
+ initialSessionId?: string;
902
920
  /** API 키 */
903
921
  apiKey?: string;
904
922
  /** API 엔드포인트 */
@@ -1369,7 +1369,8 @@ var useChatUI = (options) => {
1369
1369
  }));
1370
1370
  setSessions(sessionsWithoutMessages);
1371
1371
  if (sessionsWithoutMessages.length > 0) {
1372
- setCurrentSessionId(sessionsWithoutMessages[0].id);
1372
+ const targetId = options.initialSessionId && sessionsWithoutMessages.some((s) => s.id === options.initialSessionId) ? options.initialSessionId : sessionsWithoutMessages[0].id;
1373
+ setCurrentSessionId(targetId);
1373
1374
  }
1374
1375
  }).catch((error) => {
1375
1376
  onError?.(error instanceof Error ? error : new Error("Failed to load sessions"));
@@ -1391,8 +1392,10 @@ var useChatUI = (options) => {
1391
1392
  const parsed = JSON.parse(saved);
1392
1393
  setSessions(parsed);
1393
1394
  if (parsed.length > 0) {
1394
- setCurrentSessionId(parsed[0].id);
1395
- setSelectedModel(parsed[0].model);
1395
+ const targetSession = options.initialSessionId ? parsed.find((s) => s.id === options.initialSessionId) : null;
1396
+ const selected = targetSession || parsed[0];
1397
+ setCurrentSessionId(selected.id);
1398
+ setSelectedModel(selected.model);
1396
1399
  }
1397
1400
  } catch {
1398
1401
  }
@@ -1798,8 +1801,12 @@ ${newConversation}
1798
1801
  abortControllerRef.current?.abort();
1799
1802
  }, []);
1800
1803
  const updatePersonalization = (0, import_react4.useCallback)((config) => {
1801
- setPersonalization((prev) => ({ ...prev, ...config }));
1802
- }, []);
1804
+ setPersonalization((prev) => {
1805
+ const next = { ...prev, ...config };
1806
+ options.onPersonalizationChange?.(next);
1807
+ return next;
1808
+ });
1809
+ }, [options.onPersonalizationChange]);
1803
1810
  const toggleDeepResearchMode = (0, import_react4.useCallback)(() => {
1804
1811
  setIsDeepResearchMode((prev) => !prev);
1805
1812
  }, []);
@@ -7884,74 +7891,23 @@ var injectStyles = () => {
7884
7891
  `;
7885
7892
  document.head.appendChild(style);
7886
7893
  };
7887
- var ChatUI = ({
7888
- models = DEFAULT_MODELS,
7889
- actions = DEFAULT_ACTIONS,
7890
- templates = DEFAULT_TEMPLATES,
7891
- personalization,
7894
+ var ChatUIView = ({
7895
+ state,
7896
+ models,
7897
+ actions,
7898
+ templates,
7899
+ showSidebar,
7900
+ sidebarWidth,
7901
+ showSettings,
7902
+ showModelSelector,
7903
+ showThinking,
7904
+ thinkingDefaultOpen,
7905
+ theme,
7906
+ className,
7892
7907
  apiKey,
7893
7908
  onApiKeyChange,
7894
- apiEndpoint = "/api/chat",
7895
- theme,
7896
- showSidebar = true,
7897
- sidebarWidth,
7898
- showSettings = true,
7899
- showModelSelector = true,
7900
- systemPrompt,
7901
- contextCompressionThreshold = 20,
7902
- keepRecentMessages = 6,
7903
- storageKey = "chatllm_sessions",
7904
- className = "",
7905
- onSendMessage,
7906
- onSessionChange,
7907
- onError,
7908
- onTitleChange,
7909
- generateTitle: generateTitle2,
7910
- // External Storage Props
7911
- useExternalStorage = false,
7912
- onLoadSessions,
7913
- onCreateSession,
7914
- onLoadSession,
7915
- onDeleteSession,
7916
- onUpdateSessionTitle,
7917
- onSaveMessages,
7918
- // Thinking Block Props
7919
- showThinking = true,
7920
- thinkingDefaultOpen = false,
7921
- // Deep Research Props
7922
- deepResearch,
7923
- // Skills Props
7924
- skills
7909
+ deepResearchEnabled
7925
7910
  }) => {
7926
- injectStyles();
7927
- const hookOptions = {
7928
- models,
7929
- actions,
7930
- initialPersonalization: personalization,
7931
- apiKey,
7932
- apiEndpoint,
7933
- initialModel: models[0]?.id,
7934
- storageKey,
7935
- contextCompressionThreshold,
7936
- keepRecentMessages,
7937
- onSendMessage,
7938
- onSessionChange,
7939
- onError,
7940
- onTitleChange,
7941
- generateTitle: generateTitle2,
7942
- // External Storage Options
7943
- useExternalStorage,
7944
- onLoadSessions,
7945
- onCreateSession,
7946
- onLoadSession,
7947
- onDeleteSession,
7948
- onUpdateSessionTitle,
7949
- onSaveMessages,
7950
- // Deep Research Options
7951
- deepResearch,
7952
- // Skills Options
7953
- skills
7954
- };
7955
7911
  const {
7956
7912
  sessions,
7957
7913
  currentSession,
@@ -7982,8 +7938,6 @@ var ChatUI = ({
7982
7938
  setSelectedAction,
7983
7939
  copyMessage,
7984
7940
  startEdit,
7985
- cancelEdit,
7986
- saveEdit,
7987
7941
  regenerate,
7988
7942
  askOtherModel,
7989
7943
  setActiveAlternative,
@@ -7991,19 +7945,15 @@ var ChatUI = ({
7991
7945
  loadingAlternativeFor,
7992
7946
  updatePersonalization,
7993
7947
  models: hookModels,
7994
- // Deep Research
7995
7948
  isDeepResearchMode,
7996
7949
  toggleDeepResearchMode,
7997
- // Poll
7998
7950
  handlePollSubmit,
7999
- // Memory
8000
7951
  globalMemory,
8001
7952
  compressionState,
8002
- // Skills
8003
7953
  manualSkills,
8004
7954
  activeSkillExecution,
8005
7955
  executeManualSkill
8006
- } = useChatUI(hookOptions);
7956
+ } = state;
8007
7957
  const greeting = currentPersonalization.userProfile.nickname ? `\uC548\uB155\uD558\uC138\uC694, ${currentPersonalization.userProfile.nickname}\uB2D8` : "\uC548\uB155\uD558\uC138\uC694";
8008
7958
  const handleTemplateClick = (template) => {
8009
7959
  setInput(template.prompt);
@@ -8134,7 +8084,7 @@ var ChatUI = ({
8134
8084
  actions,
8135
8085
  onDeepResearch: toggleDeepResearchMode,
8136
8086
  isDeepResearchMode,
8137
- deepResearchEnabled: !!deepResearch?.onWebSearch,
8087
+ deepResearchEnabled,
8138
8088
  manualSkills,
8139
8089
  onSkillSelect: executeManualSkill,
8140
8090
  activeSkillExecution
@@ -8167,6 +8117,134 @@ var ChatUI = ({
8167
8117
  }
8168
8118
  );
8169
8119
  };
8120
+ var ChatUIWithHook = ({
8121
+ models = DEFAULT_MODELS,
8122
+ actions = DEFAULT_ACTIONS,
8123
+ templates = DEFAULT_TEMPLATES,
8124
+ personalization,
8125
+ onPersonalizationChange,
8126
+ apiKey,
8127
+ onApiKeyChange,
8128
+ apiEndpoint = "/api/chat",
8129
+ theme,
8130
+ showSidebar = true,
8131
+ sidebarWidth,
8132
+ showSettings = true,
8133
+ showModelSelector = true,
8134
+ systemPrompt,
8135
+ contextCompressionThreshold = 20,
8136
+ keepRecentMessages = 6,
8137
+ storageKey = "chatllm_sessions",
8138
+ initialSessionId,
8139
+ className = "",
8140
+ onSendMessage,
8141
+ onSessionChange,
8142
+ onError,
8143
+ onTitleChange,
8144
+ generateTitle: generateTitle2,
8145
+ useExternalStorage = false,
8146
+ onLoadSessions,
8147
+ onCreateSession,
8148
+ onLoadSession,
8149
+ onDeleteSession,
8150
+ onUpdateSessionTitle,
8151
+ onSaveMessages,
8152
+ showThinking = true,
8153
+ thinkingDefaultOpen = false,
8154
+ deepResearch,
8155
+ skills
8156
+ }) => {
8157
+ const hookOptions = {
8158
+ models,
8159
+ actions,
8160
+ initialPersonalization: personalization,
8161
+ onPersonalizationChange,
8162
+ initialSessionId,
8163
+ apiKey,
8164
+ apiEndpoint,
8165
+ initialModel: models[0]?.id,
8166
+ storageKey,
8167
+ contextCompressionThreshold,
8168
+ keepRecentMessages,
8169
+ onSendMessage,
8170
+ onSessionChange,
8171
+ onError,
8172
+ onTitleChange,
8173
+ generateTitle: generateTitle2,
8174
+ useExternalStorage,
8175
+ onLoadSessions,
8176
+ onCreateSession,
8177
+ onLoadSession,
8178
+ onDeleteSession,
8179
+ onUpdateSessionTitle,
8180
+ onSaveMessages,
8181
+ deepResearch,
8182
+ skills
8183
+ };
8184
+ const state = useChatUI(hookOptions);
8185
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
8186
+ ChatUIView,
8187
+ {
8188
+ state,
8189
+ models,
8190
+ actions,
8191
+ templates,
8192
+ showSidebar,
8193
+ sidebarWidth,
8194
+ showSettings,
8195
+ showModelSelector,
8196
+ showThinking,
8197
+ thinkingDefaultOpen,
8198
+ theme,
8199
+ className,
8200
+ apiKey,
8201
+ onApiKeyChange,
8202
+ deepResearchEnabled: !!deepResearch?.onWebSearch
8203
+ }
8204
+ );
8205
+ };
8206
+ var ChatUI = (props) => {
8207
+ injectStyles();
8208
+ if (props.chatState) {
8209
+ const {
8210
+ models = DEFAULT_MODELS,
8211
+ actions = DEFAULT_ACTIONS,
8212
+ templates = DEFAULT_TEMPLATES,
8213
+ showSidebar = true,
8214
+ sidebarWidth,
8215
+ showSettings = true,
8216
+ showModelSelector = true,
8217
+ showThinking = true,
8218
+ thinkingDefaultOpen = false,
8219
+ theme,
8220
+ className = "",
8221
+ apiKey,
8222
+ onApiKeyChange,
8223
+ deepResearch
8224
+ } = props;
8225
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
8226
+ ChatUIView,
8227
+ {
8228
+ state: props.chatState,
8229
+ models,
8230
+ actions,
8231
+ templates,
8232
+ showSidebar,
8233
+ sidebarWidth,
8234
+ showSettings,
8235
+ showModelSelector,
8236
+ showThinking,
8237
+ thinkingDefaultOpen,
8238
+ theme,
8239
+ className,
8240
+ apiKey,
8241
+ onApiKeyChange,
8242
+ deepResearchEnabled: !!deepResearch?.onWebSearch
8243
+ }
8244
+ );
8245
+ }
8246
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ChatUIWithHook, { ...props });
8247
+ };
8170
8248
 
8171
8249
  // src/react/hooks/useDeepResearch.ts
8172
8250
  var import_react16 = require("react");