@glodon-aiot/chat-app-sdk 0.0.13 → 0.0.15

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/es/index.esm.js CHANGED
@@ -15005,6 +15005,7 @@ ___CSS_LOADER_EXPORT___.push([module.id, `.f93f377f7f3466bb {
15005
15005
  .f93f377f7f3466bb .a78675f9ead11e1c {
15006
15006
  flex: 1 1 auto;
15007
15007
  min-height: 0;
15008
+ position: relative;
15008
15009
  }
15009
15010
  `, ""]);
15010
15011
  // Exports
@@ -15147,15 +15148,38 @@ ___CSS_LOADER_EXPORT___.push([module.id, `.f86baf679567ad27 {
15147
15148
  align-self: stretch;
15148
15149
  border-radius: var(--mini, 5px);
15149
15150
  cursor: pointer;
15151
+ position: relative;
15150
15152
  }
15151
- .b604f7d22988c3dd .d81b38a3a3378ade {
15152
- display: none;
15153
+ .b604f7d22988c3dd .f4df3ee0cadb5d32 {
15154
+ position: absolute;
15155
+ right: 8px;
15156
+ top: 50%;
15157
+ transform: translateY(-50%);
15158
+ opacity: 0;
15159
+ pointer-events: none;
15160
+ transition: opacity 0.2s;
15161
+ width: auto;
15162
+ min-width: 0;
15163
+ flex-shrink: 0;
15164
+ display: flex;
15165
+ align-items: center;
15166
+ justify-content: center;
15167
+ }
15168
+ .b604f7d22988c3dd .def35156ce4da8d3 {
15169
+ width: auto;
15170
+ min-width: 0;
15171
+ flex-shrink: 0;
15172
+ background: #F1F1F1 !important;
15173
+ }
15174
+ .b604f7d22988c3dd .def35156ce4da8d3:hover {
15175
+ background: #DFDFDF !important;
15153
15176
  }
15154
15177
  .b604f7d22988c3dd:hover {
15155
15178
  background: #F1F1F1;
15156
15179
  }
15157
- .b604f7d22988c3dd:hover .d81b38a3a3378ade {
15158
- display: block;
15180
+ .b604f7d22988c3dd:hover .f4df3ee0cadb5d32 {
15181
+ opacity: 1;
15182
+ pointer-events: auto;
15159
15183
  }
15160
15184
  .d20070d79d26fc4c {
15161
15185
  background: #DFDFDF;
@@ -15169,8 +15193,10 @@ ___CSS_LOADER_EXPORT___.locals = {
15169
15193
  "conversationItemTime": `a333a6f519d76789`,
15170
15194
  "conversation-item-content": `b604f7d22988c3dd`,
15171
15195
  "conversationItemContent": `b604f7d22988c3dd`,
15172
- "conversation-operate": `d81b38a3a3378ade`,
15173
- "conversationOperate": `d81b38a3a3378ade`,
15196
+ "conversation-operate-wrapper": `f4df3ee0cadb5d32`,
15197
+ "conversationOperateWrapper": `f4df3ee0cadb5d32`,
15198
+ "conversation-operate-button": `def35156ce4da8d3`,
15199
+ "conversationOperateButton": `def35156ce4da8d3`,
15174
15200
  "conversation-item-content-active": `d20070d79d26fc4c`,
15175
15201
  "conversationItemContentActive": `d20070d79d26fc4c`
15176
15202
  };
@@ -15661,6 +15687,8 @@ ___CSS_LOADER_EXPORT___.push([module.id, `.c64c9a8ea4a38e72 {
15661
15687
  width: 100%;
15662
15688
  height: 100%;
15663
15689
  min-height: 0;
15690
+ padding-bottom: 34px;
15691
+ box-sizing: border-box;
15664
15692
  }
15665
15693
  .c5a6e169fa0cf192 * {
15666
15694
  box-sizing: border-box;
@@ -297047,7 +297075,7 @@ const TextItemList = (param)=>{
297047
297075
  // mix-content 内的文本内容应该和纯文本消息使用相同的样式
297048
297076
  background: '#F4F4F4',
297049
297077
  padding: '10px',
297050
- borderRadius: '10px 0px 10px 10px',
297078
+ borderRadius: '10px 0 10px 10px',
297051
297079
  textAlign: 'right'
297052
297080
  },
297053
297081
  children: [
@@ -298958,7 +298986,7 @@ const FileCard_FileCard = (props)=>{
298958
298986
  }),
298959
298987
  children: nameWithoutExtension
298960
298988
  }),
298961
- /*#__PURE__*/ (0,jsx_runtime.jsx)("span", {
298989
+ file.file_size > 0 && /*#__PURE__*/ (0,jsx_runtime.jsx)("span", {
298962
298990
  // chat-uikit-file-card__info__size
298963
298991
  className: classnames_default()('text-base font-normal leading-[16px]', isCanceled ? 'coz-fg-dim' : 'coz-fg-secondary'),
298964
298992
  children: convertBytes(file.file_size)
@@ -299081,6 +299109,19 @@ FileCard_FileCard.displayName = 'FileCard';
299081
299109
  */
299082
299110
 
299083
299111
 
299112
+ // 默认的 fileAttributeKeys,用于混合消息中的文件显示
299113
+ // 注意:这些值需要与实际的 FileStatus 枚举值匹配
299114
+ // FileStatus: Init=0, Uploading=1, Success=2, Canceled=3, Error=4
299115
+ const DEFAULT_FILE_ATTRIBUTE_KEYS = {
299116
+ statusKey: 'upload_status',
299117
+ statusEnum: {
299118
+ successEnum: 2,
299119
+ failEnum: 4,
299120
+ cancelEnum: 3,
299121
+ uploadingEnum: 1
299122
+ },
299123
+ percentKey: 'upload_percent'
299124
+ };
299084
299125
  const FileItemList = (param)=>{
299085
299126
  let { fileItemList, fileAttributeKeys, fileCopywriting, readonly, onRetry, onCancel, onCopy, message, layout, showBackground } = param;
299086
299127
  /**
@@ -299107,13 +299148,15 @@ const FileItemList = (param)=>{
299107
299148
  extra: {}
299108
299149
  });
299109
299150
  };
299151
+ // 使用传入的 fileAttributeKeys 或默认值
299152
+ const effectiveFileAttributeKeys = fileAttributeKeys || DEFAULT_FILE_ATTRIBUTE_KEYS;
299110
299153
  return /*#__PURE__*/ (0,jsx_runtime.jsx)(jsx_runtime.Fragment, {
299111
299154
  children: fileItemList.map((item)=>{
299112
- if (isFileMixItem(item) && fileAttributeKeys) {
299155
+ if (isFileMixItem(item)) {
299113
299156
  return /*#__PURE__*/ (0,jsx_runtime.jsx)(components_FileCard, {
299114
299157
  className: "chat-uikit-multi-modal-file-image-content select-none",
299115
299158
  file: item.file,
299116
- attributeKeys: fileAttributeKeys,
299159
+ attributeKeys: effectiveFileAttributeKeys,
299117
299160
  tooltipsCopywriting: fileCopywriting === null || fileCopywriting === void 0 ? void 0 : fileCopywriting.tooltips,
299118
299161
  readonly: readonly,
299119
299162
  onCancel: handleCancel,
@@ -383278,9 +383321,9 @@ const scroll_view_ScrollView = /*#__PURE__*/ (0,react.forwardRef)(function Scrol
383278
383321
  className: classnames_default()(src_scroll_view_index_module.scrollable, showScrollbar && src_scroll_view_index_module["show-scrollbar"], autoShowScrollbar && src_scroll_view_index_module["auto-show-scrollbar"], scrollbarWidthNone && src_scroll_view_index_module["scrollbar-width-none"], {
383279
383322
  [src_scroll_view_index_module.reverse]: reverse
383280
383323
  }),
383281
- style: {
383282
- height: '100%'
383283
- },
383324
+ // style={{
383325
+ // height: '100%',
383326
+ // }}
383284
383327
  onScroll: handleScroll,
383285
383328
  children: [
383286
383329
  lodash_es_isFunction(children) ? children(controller) : children,
@@ -407977,6 +408020,48 @@ const useGroupedConversations = (conversations)=>{
407977
408020
  return groupedConversations;
407978
408021
  };
407979
408022
 
408023
+ ;// CONCATENATED MODULE: ../open-chat/src/util/conversation-display-name.ts
408024
+ /*
408025
+ * Copyright 2025 coze-dev Authors
408026
+ *
408027
+ * Licensed under the Apache License, Version 2.0 (the "License");
408028
+ * you may not use this file except in compliance with the License.
408029
+ * You may obtain a copy of the License at
408030
+ *
408031
+ * http://www.apache.org/licenses/LICENSE-2.0
408032
+ *
408033
+ * Unless required by applicable law or agreed to in writing, software
408034
+ * distributed under the License is distributed on an "AS IS" BASIS,
408035
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
408036
+ * See the License for the specific language governing permissions and
408037
+ * limitations under the License.
408038
+ */
408039
+ // UUID格式判断:xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
408040
+ const UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
408041
+ const isUUID = (str)=>{
408042
+ if (!str) {
408043
+ return false;
408044
+ }
408045
+ return UUID_REGEX.test(str);
408046
+ };
408047
+ /**
408048
+ * 获取会话显示名称
408049
+ * 优先级:title > name(如果不是UUID)> 新创建的会话
408050
+ * @param item 会话项
408051
+ * @returns 显示名称
408052
+ */ const getConversationDisplayName = (item)=>{
408053
+ // 优先使用title
408054
+ if (item.title) {
408055
+ return item.title;
408056
+ }
408057
+ // 如果name存在且不是UUID格式,使用name
408058
+ if (item.name && !isUUID(item.name)) {
408059
+ return item.name;
408060
+ }
408061
+ // 否则显示"新创建的会话"
408062
+ return intl_i18n.t('web_sdk_conversation_default_name');
408063
+ };
408064
+
407980
408065
  ;// CONCATENATED MODULE: ../open-chat/src/components/conversation-list-sider/conversation-item/mobile/operate/index.tsx
407981
408066
  /*
407982
408067
  * Copyright 2025 coze-dev Authors
@@ -408177,7 +408262,7 @@ const MobileConversationItem = (param)=>{
408177
408262
  ellipsis: {
408178
408263
  showTooltip: {
408179
408264
  opts: {
408180
- content: item.title || intl_i18n.t('web_sdk_conversation_default_name'),
408265
+ content: getConversationDisplayName(item),
408181
408266
  style: {
408182
408267
  wordBreak: 'break-all'
408183
408268
  },
@@ -408186,7 +408271,7 @@ const MobileConversationItem = (param)=>{
408186
408271
  }
408187
408272
  }
408188
408273
  },
408189
- children: item.title || intl_i18n.t('web_sdk_conversation_default_name')
408274
+ children: getConversationDisplayName(item)
408190
408275
  })
408191
408276
  })
408192
408277
  }),
@@ -408345,7 +408430,7 @@ const PcConversationItem = (param)=>{
408345
408430
  ellipsis: {
408346
408431
  showTooltip: {
408347
408432
  opts: {
408348
- content: item.title,
408433
+ content: getConversationDisplayName(item),
408349
408434
  style: {
408350
408435
  wordBreak: 'break-all'
408351
408436
  },
@@ -408354,25 +408439,28 @@ const PcConversationItem = (param)=>{
408354
408439
  }
408355
408440
  }
408356
408441
  },
408357
- children: item.title || intl_i18n.t('web_sdk_conversation_default_name')
408442
+ children: getConversationDisplayName(item)
408358
408443
  }),
408359
- /*#__PURE__*/ (0,jsx_runtime.jsx)(Operate, {
408360
- onRename: ()=>{
408361
- onRename(item);
408362
- setVisible(false);
408363
- },
408364
- onDelete: ()=>{
408365
- onDelete(item);
408366
- setVisible(false);
408367
- },
408368
- visible: visible,
408369
- setVisible: setVisible,
408370
- children: /*#__PURE__*/ (0,jsx_runtime.jsx)(esm_webpack_exports_IconButton, {
408371
- className: conversation_item_pc_index_module["conversation-operate"],
408372
- onClick: handleClick,
408373
- size: "small",
408374
- icon: /*#__PURE__*/ (0,jsx_runtime.jsx)(__webpack_exports__IconCozMore, {}),
408375
- color: "secondary"
408444
+ /*#__PURE__*/ (0,jsx_runtime.jsx)("div", {
408445
+ className: conversation_item_pc_index_module["conversation-operate-wrapper"],
408446
+ children: /*#__PURE__*/ (0,jsx_runtime.jsx)(Operate, {
408447
+ onRename: ()=>{
408448
+ onRename(item);
408449
+ setVisible(false);
408450
+ },
408451
+ onDelete: ()=>{
408452
+ onDelete(item);
408453
+ setVisible(false);
408454
+ },
408455
+ visible: visible,
408456
+ setVisible: setVisible,
408457
+ children: /*#__PURE__*/ (0,jsx_runtime.jsx)(esm_webpack_exports_IconButton, {
408458
+ className: conversation_item_pc_index_module["conversation-operate-button"],
408459
+ onClick: handleClick,
408460
+ size: "small",
408461
+ icon: /*#__PURE__*/ (0,jsx_runtime.jsx)(__webpack_exports__IconCozMore, {}),
408462
+ color: "secondary"
408463
+ })
408376
408464
  })
408377
408465
  })
408378
408466
  ]
@@ -409268,9 +409356,20 @@ const createChatStore = (chatConfig, userInfo)=>{
409268
409356
  }));
409269
409357
  },
409270
409358
  updateCurrentConversationNameByMessage: async (name)=>{
409359
+ var _chatConfigRef_current;
409271
409360
  const { currentConversationInfo, updateCurrentConversationInfo, updateConversations, cozeApi } = get();
409272
- // 如果没有 conversationInfo 或已有名称,直接返回
409273
- if (!currentConversationInfo || currentConversationInfo.name) {
409361
+ // 如果没有 conversationInfo,直接返回
409362
+ if (!currentConversationInfo) {
409363
+ return Promise.resolve(false);
409364
+ }
409365
+ const isAppType = ((_chatConfigRef_current = chatConfigRef.current) === null || _chatConfigRef_current === void 0 ? void 0 : _chatConfigRef_current.type) === client_ChatType.APP;
409366
+ // 对于App模式,title应该只由chat接口的更新事件来设置,不应该主动PUT请求
409367
+ // 完全禁用App模式下的PUT请求,避免死循环
409368
+ if (isAppType) {
409369
+ return Promise.resolve(false);
409370
+ }
409371
+ // 对于Bot模式,如果已有名称,直接返回
409372
+ if (currentConversationInfo.name) {
409274
409373
  return Promise.resolve(false);
409275
409374
  }
409276
409375
  // 如果 conversationId 不存在或为空,说明 conversation 还未创建成功,直接返回
@@ -409279,13 +409378,9 @@ const createChatStore = (chatConfig, userInfo)=>{
409279
409378
  return Promise.resolve(false);
409280
409379
  }
409281
409380
  try {
409282
- var _chatConfigRef_current;
409283
- const isAppType = ((_chatConfigRef_current = chatConfigRef.current) === null || _chatConfigRef_current === void 0 ? void 0 : _chatConfigRef_current.type) === client_ChatType.APP;
409284
- const url = isAppType ? `/v1/workflow/conversations/${currentConversationInfo.id}` : `/v1/conversations/${currentConversationInfo.id}`;
409285
- // App 模式使用 title 字段,Bot 模式使用 name 字段
409286
- const requestBody = isAppType ? {
409287
- title: name
409288
- } : {
409381
+ const url = `/v1/conversations/${currentConversationInfo.id}`;
409382
+ // Bot 模式使用 name 字段
409383
+ const requestBody = {
409289
409384
  name
409290
409385
  };
409291
409386
  console.log('cozeApi?.put', url);
@@ -409309,7 +409404,24 @@ const createChatStore = (chatConfig, userInfo)=>{
409309
409404
  updateConversations: (conversations, operate)=>{
409310
409405
  set(immer_produce((s)=>{
409311
409406
  if (operate === 'replace') {
409312
- s.conversations = conversations;
409407
+ // 修复:在replace时,保留store中已有的title字段
409408
+ // 因为服务器返回的数据可能不包含最新的title(title是通过chat接口更新事件更新的)
409409
+ // 需要将新数据与store中已有的数据合并,保留store中的title
409410
+ const existingConversationsMap = new Map(s.conversations.map((c)=>[
409411
+ c.id,
409412
+ c
409413
+ ]));
409414
+ s.conversations = conversations.map((newConv)=>{
409415
+ const existingConv = existingConversationsMap.get(newConv.id);
409416
+ if (existingConv && existingConv.title) {
409417
+ // 如果store中已有该会话且有title,保留title
409418
+ return {
409419
+ ...newConv,
409420
+ title: existingConv.title
409421
+ };
409422
+ }
409423
+ return newConv;
409424
+ });
409313
409425
  } else if (operate === 'add') {
409314
409426
  s.conversations = [
409315
409427
  ...s.conversations,
@@ -409326,8 +409438,12 @@ const createChatStore = (chatConfig, userInfo)=>{
409326
409438
  conversations.forEach((conversation)=>{
409327
409439
  const index = s.conversations.findIndex((c)=>c.id === conversation.id);
409328
409440
  if (index !== -1) {
409441
+ // 修复:确保只更新传入的字段,保留原有字段
409442
+ // 先展开原有对象,再展开新对象,确保新对象的字段覆盖原有字段
409443
+ // 但不会丢失原有对象中的其他字段(如其他会话的title)
409444
+ const existingConversation = s.conversations[index];
409329
409445
  s.conversations[index] = {
409330
- ...s.conversations[index],
409446
+ ...existingConversation,
409331
409447
  ...conversation
409332
409448
  };
409333
409449
  }
@@ -413658,30 +413774,41 @@ studioOpenClientReporter.init(studio_open_client_reporter_slardarInstance);
413658
413774
 
413659
413775
 
413660
413776
 
413777
+
413661
413778
  const useUpdateConversationNameByMessage = ()=>{
413662
413779
  const currentConversationNameRef = (0,react.useRef)();
413663
413780
  const { updateCurrentConversationNameByMessage, currentConversationInfo } = context_useChatAppStore(shallow_useShallow((s)=>({
413664
413781
  updateCurrentConversationNameByMessage: s.updateCurrentConversationNameByMessage,
413665
413782
  currentConversationInfo: s.currentConversationInfo
413666
413783
  })));
413784
+ const { chatConfig: { type: chatType } } = context_useChatAppProps();
413785
+ const isAppType = chatType === client_ChatType.APP;
413667
413786
  const { useMessagesStore } = use_chat_area_context_useChatAreaStoreSet();
413668
413787
  const messages = useMessagesStore((s)=>s.messages, lodash_es_isEqual);
413669
413788
  (0,react.useEffect)(()=>{
413670
- currentConversationNameRef.current = currentConversationInfo === null || currentConversationInfo === void 0 ? void 0 : currentConversationInfo.name;
413789
+ // 对于App模式,检查title;对于Bot模式,检查name
413790
+ if (isAppType) {
413791
+ currentConversationNameRef.current = currentConversationInfo === null || currentConversationInfo === void 0 ? void 0 : currentConversationInfo.title;
413792
+ } else {
413793
+ currentConversationNameRef.current = currentConversationInfo === null || currentConversationInfo === void 0 ? void 0 : currentConversationInfo.name;
413794
+ }
413671
413795
  }, [
413672
- currentConversationInfo
413796
+ currentConversationInfo,
413797
+ isAppType
413673
413798
  ]);
413674
413799
  (0,react.useEffect)(()=>{
413675
413800
  const message = messages[messages.length - 1];
413676
413801
  const name = message === null || message === void 0 ? void 0 : message.content.slice(0, 100);
413677
413802
  // 确保 conversation 已创建成功(有 id)且还没有名称时才更新
413803
+ // 对于App模式,如果title已经存在(通过chat接口更新事件设置的),不应该再PUT请求
413678
413804
  if (message && !currentConversationNameRef.current && (currentConversationInfo === null || currentConversationInfo === void 0 ? void 0 : currentConversationInfo.id) && currentConversationInfo.id.trim() !== '') {
413679
413805
  updateCurrentConversationNameByMessage(name);
413680
413806
  currentConversationNameRef.current = name;
413681
413807
  }
413682
413808
  }, [
413683
413809
  messages,
413684
- currentConversationInfo
413810
+ currentConversationInfo,
413811
+ updateCurrentConversationNameByMessage
413685
413812
  ]);
413686
413813
  };
413687
413814
 
@@ -416930,7 +417057,45 @@ const convertShortcutData = (shortcutCommands, botInfo)=>//@ts-expect-error: 不
416930
417057
 
416931
417058
 
416932
417059
 
417060
+
417061
+
417062
+
416933
417063
  const microSeconds = 1000;
417064
+ /**
417065
+ * 从URL中提取文件名
417066
+ * @param url 文件URL
417067
+ * @returns 文件名,如果无法提取则返回空字符串
417068
+ */ const extractFileNameFromUrl = (url)=>{
417069
+ if (!url) {
417070
+ return '';
417071
+ }
417072
+ try {
417073
+ const urlObj = new URL(url);
417074
+ const { pathname } = urlObj;
417075
+ let fileName = pathname.split('/').pop() || '';
417076
+ // 移除查询参数和hash
417077
+ fileName = fileName.split('?')[0].split('#')[0] || '';
417078
+ // 解码URI编码的文件名
417079
+ try {
417080
+ return decodeURIComponent(fileName);
417081
+ } catch {
417082
+ // 如果解码失败,返回原始文件名
417083
+ return fileName;
417084
+ }
417085
+ } catch {
417086
+ // 如果不是有效的URL,尝试直接解析路径
417087
+ const parts = url.split('/');
417088
+ let fileName = parts[parts.length - 1] || '';
417089
+ fileName = fileName.split('?')[0].split('#')[0] || '';
417090
+ // 解码URI编码的文件名
417091
+ try {
417092
+ return decodeURIComponent(fileName);
417093
+ } catch {
417094
+ // 如果解码失败,返回原始文件名
417095
+ return fileName;
417096
+ }
417097
+ }
417098
+ };
416934
417099
  // 消息转换成 Coze的消息,主要用于消息接收后,在页面显示。
416935
417100
  class MessageConverseToCoze {
416936
417101
  convertMessageListResponse(res) {
@@ -417081,22 +417246,25 @@ class MessageConverseToCoze {
417081
417246
  }
417082
417247
  case 'file':
417083
417248
  {
417084
- const { fileType = const_FileTypeEnum.DEFAULT_UNKNOWN } = // @ts-expect-error -- linter-disable-autofix, 新添加参数,sdk中还未支持到
417085
- getFileInfo(new File([], item === null || item === void 0 ? void 0 : item.name)) || {};
417086
- return {
417249
+ const fileName = (item === null || item === void 0 ? void 0 : item.name) || extractFileNameFromUrl(item === null || item === void 0 ? void 0 : item.file_url);
417250
+ const { fileType = const_FileTypeEnum.DEFAULT_UNKNOWN } = getFileInfo(new File([], fileName)) || {};
417251
+ console.log('convertMixContent file', item);
417252
+ // 当没有 file_id 时,使用 file_url 作为 file_key
417253
+ const fileKey = item.file_id || item.file_url || '';
417254
+ const fileData = {
417087
417255
  type: types_ContentType.File,
417088
417256
  file: {
417089
- file_key: item.file_id || '',
417090
- // @ts-expect-error -- linter-disable-autofix, 新添加参数,sdk中还未支持到
417091
- file_name: item === null || item === void 0 ? void 0 : item.name,
417092
- // @ts-expect-error -- linter-disable-autofix, 新添加参数,sdk中还未支持到
417093
- file_size: item === null || item === void 0 ? void 0 : item.size,
417257
+ file_key: fileKey,
417258
+ file_name: fileName || '未知文件',
417259
+ file_size: (item === null || item === void 0 ? void 0 : item.size) ?? 0,
417094
417260
  file_type: fileType,
417095
- file_url: item === null || item === void 0 ? void 0 : item.file_url
417261
+ file_url: (item === null || item === void 0 ? void 0 : item.file_url) || ''
417096
417262
  },
417097
417263
  // @ts-expect-error -- linter-disable-autofix
417098
417264
  is_refer: item.is_refer || undefined
417099
417265
  };
417266
+ console.log('convertMixContent file result', fileData);
417267
+ return fileData;
417100
417268
  }
417101
417269
  case 'json':
417102
417270
  {
@@ -417613,6 +417781,35 @@ const useClearMessageContextAdapter = ()=>{
417613
417781
  ]);
417614
417782
  };
417615
417783
 
417784
+ ;// CONCATENATED MODULE: ../open-chat/src/chat/builder-chat/helper/get-connector-id.ts
417785
+ /*
417786
+ * Copyright 2025 coze-dev Authors
417787
+ *
417788
+ * Licensed under the Apache License, Version 2.0 (the "License");
417789
+ * you may not use this file except in compliance with the License.
417790
+ * You may obtain a copy of the License at
417791
+ *
417792
+ * http://www.apache.org/licenses/LICENSE-2.0
417793
+ *
417794
+ * Unless required by applicable law or agreed to in writing, software
417795
+ * distributed under the License is distributed on an "AS IS" BASIS,
417796
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
417797
+ * See the License for the specific language governing permissions and
417798
+ * limitations under the License.
417799
+ */
417800
+ const getConnectorId = (props)=>{
417801
+ const { project } = props;
417802
+ const { mode, connectorId } = project || {};
417803
+ if (!connectorId) {
417804
+ if (mode === 'websdk') {
417805
+ return webSdkDefaultConnectorId;
417806
+ } else if (mode === 'draft') {
417807
+ return chatflowDraftConnectorId;
417808
+ }
417809
+ }
417810
+ return connectorId;
417811
+ };
417812
+
417616
417813
  ;// CONCATENATED MODULE: ../open-chat/src/chat/builder-chat/services/create-conversation.ts
417617
417814
  /*
417618
417815
  * Copyright 2025 coze-dev Authors
@@ -417630,6 +417827,7 @@ const useClearMessageContextAdapter = ()=>{
417630
417827
  * limitations under the License.
417631
417828
  */
417632
417829
 
417830
+
417633
417831
  // 用于发送消息时创建 conversation 的函数
417634
417832
  const createConversationForMessage = async (apiSdk, props)=>{
417635
417833
  let conversationId = '';
@@ -417750,13 +417948,87 @@ const createConversationForMessage = async (apiSdk, props)=>{
417750
417948
  throw new Error(`Failed to create conversation: ${JSON.stringify(error)}`);
417751
417949
  }
417752
417950
  };
417753
- const createOrGetConversation = (apiSdk, props)=>// 初始化时不创建 conversation,返回空值
417951
+ const createOrGetConversation = async (apiSdk, props)=>{
417952
+ // 如果没有 conversationName,保持现有行为:不创建会话,返回空值
417754
417953
  // conversation 将在用户发送第一条消息时创建
417755
- Promise.resolve({
417954
+ if (!props.project.conversationName || props.project.conversationName.trim() === '') {
417955
+ return {
417956
+ conversationId: '',
417957
+ sectionId: '',
417958
+ conversationName: undefined
417959
+ };
417960
+ }
417961
+ // 如果有 conversationName,在初始化时就创建/获取会话
417962
+ if (props.project.type === 'app') {
417963
+ try {
417964
+ const connectorId = getConnectorId(props);
417965
+ const createPayload = {
417966
+ app_id: props.project.id,
417967
+ draft_mode: props.project.mode === 'draft',
417968
+ workflow_id: props.workflow.id || '',
417969
+ connector_id: connectorId,
417970
+ get_or_create: true,
417971
+ conversation_name: props.project.conversationName
417972
+ };
417973
+ const res = await (apiSdk === null || apiSdk === void 0 ? void 0 : apiSdk.post('/v1/workflow/conversation/create', createPayload, false, {
417974
+ headers: {
417975
+ 'Accept-Language': intl.language === 'zh-CN' ? 'zh' : 'en'
417976
+ }
417977
+ }));
417978
+ if ((res === null || res === void 0 ? void 0 : res.code) === 0 && (res === null || res === void 0 ? void 0 : res.data)) {
417979
+ const conversationId = res.data.id || '';
417980
+ const sectionId = res.data.last_section_id || '';
417981
+ // 确保 conversationId 不为空
417982
+ if (!conversationId || conversationId.trim() === '') {
417983
+ throw new Error('Failed to create conversation: empty conversationId returned');
417984
+ }
417985
+ // 获取会话详情以获取 conversation_name
417986
+ let conversationName = undefined;
417987
+ if (conversationId) {
417988
+ try {
417989
+ const detailRes = await (apiSdk === null || apiSdk === void 0 ? void 0 : apiSdk.get(`/v1/workflow/conversations/${conversationId}`, {
417990
+ app_id: props.project.id,
417991
+ workflow_id: props.workflow.id || '',
417992
+ connector_id: connectorId
417993
+ }));
417994
+ if ((detailRes === null || detailRes === void 0 ? void 0 : detailRes.code) === 0 && (detailRes === null || detailRes === void 0 ? void 0 : detailRes.data)) {
417995
+ const name = detailRes.data.conversation_name || detailRes.data.name || detailRes.data.title;
417996
+ conversationName = name || undefined;
417997
+ }
417998
+ } catch (detailError) {
417999
+ console.warn('Failed to fetch conversation detail:', detailError);
418000
+ conversationName = props.project.conversationName;
418001
+ }
418002
+ }
418003
+ return {
418004
+ conversationId,
418005
+ sectionId,
418006
+ conversationName: conversationName || props.project.conversationName
418007
+ };
418008
+ } else {
418009
+ const errorMsg = (res === null || res === void 0 ? void 0 : res.msg) || `code=${(res === null || res === void 0 ? void 0 : res.code) ?? 'unknown'}`;
418010
+ throw new Error(`Failed to create conversation: ${errorMsg}`);
418011
+ }
418012
+ } catch (error) {
418013
+ console.error('createOrGetConversation error:', error);
418014
+ // 如果创建失败,返回空值,让系统在发送消息时再创建
418015
+ if (error instanceof Error) {
418016
+ console.warn('Failed to create conversation during init, will create on first message:', error.message);
418017
+ }
418018
+ return {
418019
+ conversationId: '',
418020
+ sectionId: '',
418021
+ conversationName: undefined
418022
+ };
418023
+ }
418024
+ }
418025
+ // Bot 模式:保持现有行为,不在这里创建会话
418026
+ return {
417756
418027
  conversationId: '',
417757
418028
  sectionId: '',
417758
418029
  conversationName: undefined
417759
- });
418030
+ };
418031
+ };
417760
418032
 
417761
418033
  ;// CONCATENATED MODULE: ../open-chat/src/components/studio-open-chat/provider/coz-sdk/api-adapter/message/message-convert-to-sdk.ts
417762
418034
  /*
@@ -419943,35 +420215,43 @@ class MessageParser {
419943
420215
  const currentConversation = refCurrentConversationInfo.current;
419944
420216
  const updateConversationsFn = refUpdateConversations.current;
419945
420217
  const updateCurrentConversationInfoFn = refUpdateCurrentConversationInfo.current;
419946
- const conversationsList = refConversations.current;
419947
420218
  const { title } = updates;
419948
420219
  if (title !== undefined) {
419949
- // 找到要更新的会话,保留其原有字段
419950
- const existingConversation = conversationsList.find((c)=>c.id === conversation_id);
419951
420220
  // 更新会话列表中的会话名称
419952
420221
  // 注意:PC 端和 Mobile 端都优先使用 title,如果没有 title 则使用 name
419953
420222
  // 对于 App 模式,需要同时更新 name 和 title
419954
420223
  // 对于 Bot 模式,也需要更新 name 和 title(如果存在)
419955
- const updatedConversation = {
420224
+ // 修复:使用函数式更新,确保从最新的store状态中获取并保留所有字段
420225
+ // 这样可以避免因为ref未及时更新而导致的数据丢失问题
420226
+ const updatedConversationObj = {
419956
420227
  id: conversation_id,
419957
420228
  name: title,
419958
420229
  title,
419959
- updated_at: Math.floor(updated_at / 1000),
419960
- // 保留原有字段(如果存在),否则使用默认值
419961
- created_at: (existingConversation === null || existingConversation === void 0 ? void 0 : existingConversation.created_at) ?? Math.floor(updated_at / 1000),
419962
- meta_data: (existingConversation === null || existingConversation === void 0 ? void 0 : existingConversation.meta_data) ?? {},
419963
- last_section_id: (existingConversation === null || existingConversation === void 0 ? void 0 : existingConversation.last_section_id) ?? ''
420230
+ updated_at: Math.floor(updated_at / 1000)
419964
420231
  };
419965
420232
  updateConversationsFn([
419966
- updatedConversation
420233
+ updatedConversationObj
419967
420234
  ], 'update');
419968
420235
  // 如果当前会话是被更新的会话,同时更新 currentConversationInfo
419969
- if ((currentConversation === null || currentConversation === void 0 ? void 0 : currentConversation.id) === conversation_id) {
420236
+ // 修复:无论ref是否是最新的,都更新currentConversationInfo,确保header能显示title
420237
+ // updateCurrentConversationInfo函数会合并字段,所以即使ref不是最新的,title也会被正确设置
420238
+ // 从conversations列表中查找对应的会话,如果找到说明这个会话存在,可能是当前会话
420239
+ const conversationsList = refConversations.current;
420240
+ const foundConversation = conversationsList.find((c)=>c.id === conversation_id);
420241
+ // 如果ref中的id匹配,或者找到了对应的会话,就更新title
420242
+ // 这样可以确保即使ref不是最新的,也能正确更新title
420243
+ if ((currentConversation === null || currentConversation === void 0 ? void 0 : currentConversation.id) === conversation_id || foundConversation) {
420244
+ // 优先使用ref中的currentConversationInfo,保留其所有字段
420245
+ // 如果ref中没有,使用conversations列表中的信息
420246
+ const baseInfo = currentConversation || foundConversation;
419970
420247
  updateCurrentConversationInfoFn({
419971
- ...currentConversation,
420248
+ ...baseInfo || {},
420249
+ id: conversation_id,
419972
420250
  name: title,
419973
- // @ts-expect-error: title 字段可能不在类型定义中,但实际需要
419974
- title
420251
+ title,
420252
+ // 保留currentConversationInfo特有的字段
420253
+ conversationListVisible: (currentConversation === null || currentConversation === void 0 ? void 0 : currentConversation.conversationListVisible) ?? false,
420254
+ isLargeWidth: (currentConversation === null || currentConversation === void 0 ? void 0 : currentConversation.isLargeWidth) ?? false
419975
420255
  });
419976
420256
  }
419977
420257
  }
@@ -436935,35 +437215,6 @@ const getBuilderEventCallbackPlugin = (props)=>{
436935
437215
 
436936
437216
  ;// CONCATENATED MODULE: ../open-chat/src/assets/chatflow-logo.png
436937
437217
  const chatflow_logo_namespaceObject = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAASwAAAEsCAYAAAB5fY51AAAACXBIWXMAACE4AAAhOAFFljFgAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAwkSURBVHgB7d2xblRXGsDxwyrQGGkxhaHACmsatgEiUQSKYCRoSBHnCYAngDxBnCcIPAEgP0BIkTRBwk4RUiCF0EADSwQFuABWwg0p2PkGhiUBxL0zd+z57v39pNGwu83OzJ2/zzn33DubytLSiwKQwD8KQBKCBaQhWEAaggWkIVhAGoIFpCFYQBqCBaQhWEAaggWkIVhAGoIFpCFYQBqCBaQhWEAaggWkIVhAGoIFpCFYQBqCBaQhWEAaggWkIVhAGoIFpCFYQBqCBaQhWEAaggWkIVhAGoIFpCFYQBqCBaQhWEAaggWkIVhAGoIFpCFYQBqCBaQhWEAaggWkIVhAGoIFpCFYQBqCBaQhWEAaggWkIVhAGoIFpCFYQBqCBaQhWEAaggWkIVhAGoIFpCFYQBqCBaQhWEAaggWkIVhAGoIFpCFYQBqCBaQhWEAaggWk8VGBEe2emirbtmz5yyPce/as//z0+fNyb22t/wyjECwqixAdmJ7uP/b3HvM7d5Ztmze/DlQVN5486Yds5dGj/r+Xe89Q1aaytPSiwHtEjE7NzZUvZmf7oaoTp6oiWpfu3CnLq6uvR2XwLoLFW96M1PyOHWU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hAGoIFpCFYQBqCBaQhWEAaggWkIVhAGoIFpCFYQBqCBaQhWEAaggWkIVhAGoIFpCFYQBqCBaQhWEAaggWkIVhAGoIFpCFYQBqCBaQhWEAaggWkIVhAGoIFpCFYQBqCBaQhWEAaggWkIVhAGoIFpCFYQBqCBaQhWEAaggWkIVhAGoIFpCFYQBqCBaQhWEAaggWkIVhAGoIFpCFYQBqCBaQhWEAaggWkIVhAGoIFpCFYQBqCBaQhWEAaggWkIVhAGoIFpCFYQBqCBaQhWEAaggWkIVhAGv8DJbWhlGwbFtYAAAAASUVORK5CYII=";
436938
- ;// CONCATENATED MODULE: ../open-chat/src/chat/builder-chat/helper/get-connector-id.ts
436939
- /*
436940
- * Copyright 2025 coze-dev Authors
436941
- *
436942
- * Licensed under the Apache License, Version 2.0 (the "License");
436943
- * you may not use this file except in compliance with the License.
436944
- * You may obtain a copy of the License at
436945
- *
436946
- * http://www.apache.org/licenses/LICENSE-2.0
436947
- *
436948
- * Unless required by applicable law or agreed to in writing, software
436949
- * distributed under the License is distributed on an "AS IS" BASIS,
436950
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
436951
- * See the License for the specific language governing permissions and
436952
- * limitations under the License.
436953
- */
436954
- const getConnectorId = (props)=>{
436955
- const { project } = props;
436956
- const { mode, connectorId } = project || {};
436957
- if (!connectorId) {
436958
- if (mode === 'websdk') {
436959
- return webSdkDefaultConnectorId;
436960
- } else if (mode === 'draft') {
436961
- return chatflowDraftConnectorId;
436962
- }
436963
- }
436964
- return connectorId;
436965
- };
436966
-
436967
437218
  ;// CONCATENATED MODULE: ../open-chat/src/chat/builder-chat/services/get-bot-info.ts
436968
437219
  /*
436969
437220
  * Copyright 2025 coze-dev Authors