@gendive/chatllm 0.13.2 → 0.14.1

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 */
@@ -478,6 +484,8 @@ interface ChatUIProps {
478
484
  keepRecentMessages?: number;
479
485
  /** 스토리지 키 (로컬 저장용) */
480
486
  storageKey?: string;
487
+ /** @Todo vibecode - 초기 선택 세션 ID (미제공 시 sessions[0] 자동 선택) */
488
+ initialSessionId?: string;
481
489
  /** CSS 클래스 */
482
490
  className?: string;
483
491
  /** 메시지 전송 핸들러 (커스텀 API 사용 시) */
@@ -887,6 +895,10 @@ interface UseChatUIReturn {
887
895
  * 풀 기능 채팅 UI
888
896
  */
889
897
 
898
+ /**
899
+ * @description ChatUI 메인 컴포넌트
900
+ * @Todo vibecode - chatState 제공 시 외부 상태 사용, 미제공 시 내부 useChatUI 호출
901
+ */
890
902
  declare const ChatUI: React$1.FC<ChatUIProps>;
891
903
 
892
904
  /**
@@ -903,6 +915,8 @@ interface UseChatUIOptions {
903
915
  initialPersonalization?: Partial<PersonalizationConfig>;
904
916
  /** @Todo vibecode - 개인화 설정 변경 콜백 (백엔드 저장용) */
905
917
  onPersonalizationChange?: (config: PersonalizationConfig) => void;
918
+ /** @Todo vibecode - 초기 선택 세션 ID (미제공 시 sessions[0] 자동 선택) */
919
+ initialSessionId?: string;
906
920
  /** API 키 */
907
921
  apiKey?: string;
908
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 */
@@ -478,6 +484,8 @@ interface ChatUIProps {
478
484
  keepRecentMessages?: number;
479
485
  /** 스토리지 키 (로컬 저장용) */
480
486
  storageKey?: string;
487
+ /** @Todo vibecode - 초기 선택 세션 ID (미제공 시 sessions[0] 자동 선택) */
488
+ initialSessionId?: string;
481
489
  /** CSS 클래스 */
482
490
  className?: string;
483
491
  /** 메시지 전송 핸들러 (커스텀 API 사용 시) */
@@ -887,6 +895,10 @@ interface UseChatUIReturn {
887
895
  * 풀 기능 채팅 UI
888
896
  */
889
897
 
898
+ /**
899
+ * @description ChatUI 메인 컴포넌트
900
+ * @Todo vibecode - chatState 제공 시 외부 상태 사용, 미제공 시 내부 useChatUI 호출
901
+ */
890
902
  declare const ChatUI: React$1.FC<ChatUIProps>;
891
903
 
892
904
  /**
@@ -903,6 +915,8 @@ interface UseChatUIOptions {
903
915
  initialPersonalization?: Partial<PersonalizationConfig>;
904
916
  /** @Todo vibecode - 개인화 설정 변경 콜백 (백엔드 저장용) */
905
917
  onPersonalizationChange?: (config: PersonalizationConfig) => void;
918
+ /** @Todo vibecode - 초기 선택 세션 ID (미제공 시 sessions[0] 자동 선택) */
919
+ initialSessionId?: string;
906
920
  /** API 키 */
907
921
  apiKey?: string;
908
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
  }
@@ -5083,7 +5086,10 @@ var MarkdownRenderer = ({
5083
5086
  processedContent = processedContent.replace(UNCLOSED_POLL_TAG_REGEX, "");
5084
5087
  processedContent = processedContent.replace(UNCLOSED_SKILL_TAG_REGEX, "");
5085
5088
  const codeBlocks = [];
5086
- processedContent = processedContent.replace(CODE_BLOCK_REGEX, (_, lang, code) => {
5089
+ processedContent = processedContent.replace(CODE_BLOCK_REGEX, (match, lang, code) => {
5090
+ if (lang === "markdown" && TABLE_ROW_REGEX.test(code.trim().split("\n")[0])) {
5091
+ return code;
5092
+ }
5087
5093
  codeBlocks.push({ language: lang || "", code });
5088
5094
  return `\xA7CODEBLOCK\xA7${codeBlocks.length - 1}\xA7/CODEBLOCK\xA7`;
5089
5095
  });
@@ -7888,76 +7894,23 @@ var injectStyles = () => {
7888
7894
  `;
7889
7895
  document.head.appendChild(style);
7890
7896
  };
7891
- var ChatUI = ({
7892
- models = DEFAULT_MODELS,
7893
- actions = DEFAULT_ACTIONS,
7894
- templates = DEFAULT_TEMPLATES,
7895
- personalization,
7896
- onPersonalizationChange,
7897
+ var ChatUIView = ({
7898
+ state,
7899
+ models,
7900
+ actions,
7901
+ templates,
7902
+ showSidebar,
7903
+ sidebarWidth,
7904
+ showSettings,
7905
+ showModelSelector,
7906
+ showThinking,
7907
+ thinkingDefaultOpen,
7908
+ theme,
7909
+ className,
7897
7910
  apiKey,
7898
7911
  onApiKeyChange,
7899
- apiEndpoint = "/api/chat",
7900
- theme,
7901
- showSidebar = true,
7902
- sidebarWidth,
7903
- showSettings = true,
7904
- showModelSelector = true,
7905
- systemPrompt,
7906
- contextCompressionThreshold = 20,
7907
- keepRecentMessages = 6,
7908
- storageKey = "chatllm_sessions",
7909
- className = "",
7910
- onSendMessage,
7911
- onSessionChange,
7912
- onError,
7913
- onTitleChange,
7914
- generateTitle: generateTitle2,
7915
- // External Storage Props
7916
- useExternalStorage = false,
7917
- onLoadSessions,
7918
- onCreateSession,
7919
- onLoadSession,
7920
- onDeleteSession,
7921
- onUpdateSessionTitle,
7922
- onSaveMessages,
7923
- // Thinking Block Props
7924
- showThinking = true,
7925
- thinkingDefaultOpen = false,
7926
- // Deep Research Props
7927
- deepResearch,
7928
- // Skills Props
7929
- skills
7912
+ deepResearchEnabled
7930
7913
  }) => {
7931
- injectStyles();
7932
- const hookOptions = {
7933
- models,
7934
- actions,
7935
- initialPersonalization: personalization,
7936
- onPersonalizationChange,
7937
- apiKey,
7938
- apiEndpoint,
7939
- initialModel: models[0]?.id,
7940
- storageKey,
7941
- contextCompressionThreshold,
7942
- keepRecentMessages,
7943
- onSendMessage,
7944
- onSessionChange,
7945
- onError,
7946
- onTitleChange,
7947
- generateTitle: generateTitle2,
7948
- // External Storage Options
7949
- useExternalStorage,
7950
- onLoadSessions,
7951
- onCreateSession,
7952
- onLoadSession,
7953
- onDeleteSession,
7954
- onUpdateSessionTitle,
7955
- onSaveMessages,
7956
- // Deep Research Options
7957
- deepResearch,
7958
- // Skills Options
7959
- skills
7960
- };
7961
7914
  const {
7962
7915
  sessions,
7963
7916
  currentSession,
@@ -7988,8 +7941,6 @@ var ChatUI = ({
7988
7941
  setSelectedAction,
7989
7942
  copyMessage,
7990
7943
  startEdit,
7991
- cancelEdit,
7992
- saveEdit,
7993
7944
  regenerate,
7994
7945
  askOtherModel,
7995
7946
  setActiveAlternative,
@@ -7997,19 +7948,15 @@ var ChatUI = ({
7997
7948
  loadingAlternativeFor,
7998
7949
  updatePersonalization,
7999
7950
  models: hookModels,
8000
- // Deep Research
8001
7951
  isDeepResearchMode,
8002
7952
  toggleDeepResearchMode,
8003
- // Poll
8004
7953
  handlePollSubmit,
8005
- // Memory
8006
7954
  globalMemory,
8007
7955
  compressionState,
8008
- // Skills
8009
7956
  manualSkills,
8010
7957
  activeSkillExecution,
8011
7958
  executeManualSkill
8012
- } = useChatUI(hookOptions);
7959
+ } = state;
8013
7960
  const greeting = currentPersonalization.userProfile.nickname ? `\uC548\uB155\uD558\uC138\uC694, ${currentPersonalization.userProfile.nickname}\uB2D8` : "\uC548\uB155\uD558\uC138\uC694";
8014
7961
  const handleTemplateClick = (template) => {
8015
7962
  setInput(template.prompt);
@@ -8140,7 +8087,7 @@ var ChatUI = ({
8140
8087
  actions,
8141
8088
  onDeepResearch: toggleDeepResearchMode,
8142
8089
  isDeepResearchMode,
8143
- deepResearchEnabled: !!deepResearch?.onWebSearch,
8090
+ deepResearchEnabled,
8144
8091
  manualSkills,
8145
8092
  onSkillSelect: executeManualSkill,
8146
8093
  activeSkillExecution
@@ -8173,6 +8120,134 @@ var ChatUI = ({
8173
8120
  }
8174
8121
  );
8175
8122
  };
8123
+ var ChatUIWithHook = ({
8124
+ models = DEFAULT_MODELS,
8125
+ actions = DEFAULT_ACTIONS,
8126
+ templates = DEFAULT_TEMPLATES,
8127
+ personalization,
8128
+ onPersonalizationChange,
8129
+ apiKey,
8130
+ onApiKeyChange,
8131
+ apiEndpoint = "/api/chat",
8132
+ theme,
8133
+ showSidebar = true,
8134
+ sidebarWidth,
8135
+ showSettings = true,
8136
+ showModelSelector = true,
8137
+ systemPrompt,
8138
+ contextCompressionThreshold = 20,
8139
+ keepRecentMessages = 6,
8140
+ storageKey = "chatllm_sessions",
8141
+ initialSessionId,
8142
+ className = "",
8143
+ onSendMessage,
8144
+ onSessionChange,
8145
+ onError,
8146
+ onTitleChange,
8147
+ generateTitle: generateTitle2,
8148
+ useExternalStorage = false,
8149
+ onLoadSessions,
8150
+ onCreateSession,
8151
+ onLoadSession,
8152
+ onDeleteSession,
8153
+ onUpdateSessionTitle,
8154
+ onSaveMessages,
8155
+ showThinking = true,
8156
+ thinkingDefaultOpen = false,
8157
+ deepResearch,
8158
+ skills
8159
+ }) => {
8160
+ const hookOptions = {
8161
+ models,
8162
+ actions,
8163
+ initialPersonalization: personalization,
8164
+ onPersonalizationChange,
8165
+ initialSessionId,
8166
+ apiKey,
8167
+ apiEndpoint,
8168
+ initialModel: models[0]?.id,
8169
+ storageKey,
8170
+ contextCompressionThreshold,
8171
+ keepRecentMessages,
8172
+ onSendMessage,
8173
+ onSessionChange,
8174
+ onError,
8175
+ onTitleChange,
8176
+ generateTitle: generateTitle2,
8177
+ useExternalStorage,
8178
+ onLoadSessions,
8179
+ onCreateSession,
8180
+ onLoadSession,
8181
+ onDeleteSession,
8182
+ onUpdateSessionTitle,
8183
+ onSaveMessages,
8184
+ deepResearch,
8185
+ skills
8186
+ };
8187
+ const state = useChatUI(hookOptions);
8188
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
8189
+ ChatUIView,
8190
+ {
8191
+ state,
8192
+ models,
8193
+ actions,
8194
+ templates,
8195
+ showSidebar,
8196
+ sidebarWidth,
8197
+ showSettings,
8198
+ showModelSelector,
8199
+ showThinking,
8200
+ thinkingDefaultOpen,
8201
+ theme,
8202
+ className,
8203
+ apiKey,
8204
+ onApiKeyChange,
8205
+ deepResearchEnabled: !!deepResearch?.onWebSearch
8206
+ }
8207
+ );
8208
+ };
8209
+ var ChatUI = (props) => {
8210
+ injectStyles();
8211
+ if (props.chatState) {
8212
+ const {
8213
+ models = DEFAULT_MODELS,
8214
+ actions = DEFAULT_ACTIONS,
8215
+ templates = DEFAULT_TEMPLATES,
8216
+ showSidebar = true,
8217
+ sidebarWidth,
8218
+ showSettings = true,
8219
+ showModelSelector = true,
8220
+ showThinking = true,
8221
+ thinkingDefaultOpen = false,
8222
+ theme,
8223
+ className = "",
8224
+ apiKey,
8225
+ onApiKeyChange,
8226
+ deepResearch
8227
+ } = props;
8228
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
8229
+ ChatUIView,
8230
+ {
8231
+ state: props.chatState,
8232
+ models,
8233
+ actions,
8234
+ templates,
8235
+ showSidebar,
8236
+ sidebarWidth,
8237
+ showSettings,
8238
+ showModelSelector,
8239
+ showThinking,
8240
+ thinkingDefaultOpen,
8241
+ theme,
8242
+ className,
8243
+ apiKey,
8244
+ onApiKeyChange,
8245
+ deepResearchEnabled: !!deepResearch?.onWebSearch
8246
+ }
8247
+ );
8248
+ }
8249
+ return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ChatUIWithHook, { ...props });
8250
+ };
8176
8251
 
8177
8252
  // src/react/hooks/useDeepResearch.ts
8178
8253
  var import_react16 = require("react");