@zero-library/chat-copilot 3.2.3 → 3.2.5

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.cjs.js CHANGED
@@ -1085,7 +1085,7 @@ function formatResourceName(resourceName) {
1085
1085
  return `${name.slice(0, 3)}***${name.slice(-3)}${extension}`;
1086
1086
  }
1087
1087
  function ReadonlyResourceTag({ resource }) {
1088
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: index_module_default.resourceTag, children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Tag, { color: "blue", children: [
1088
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className: index_module_default.resourceTag, children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Tag, { color: "blue", children: [
1089
1089
  resource.resourceLabel,
1090
1090
  "\uFF1A",
1091
1091
  formatResourceName(resource.resourceName)
@@ -1101,7 +1101,7 @@ function ResourceTag({ resource }) {
1101
1101
  node?.remove();
1102
1102
  });
1103
1103
  };
1104
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className: index_module_default.resourceTag, children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Tag, { closeIcon: true, color: "blue", onClose: handleClose, children: [
1104
+ return /* @__PURE__ */ jsxRuntime.jsx("span", { className: index_module_default.resourceTag, children: /* @__PURE__ */ jsxRuntime.jsxs(antd.Tag, { closeIcon: true, color: "blue", onClose: handleClose, children: [
1105
1105
  resource.resourceLabel,
1106
1106
  "\uFF1A",
1107
1107
  formatResourceName(resource.resourceName)
@@ -1197,10 +1197,14 @@ var VariableNode = class _VariableNode extends lexical.DecoratorNode {
1197
1197
  function $createVariableNode(resourceLabel, resourceName, resourceType, resourceId) {
1198
1198
  return new VariableNode(resourceLabel, resourceName, resourceType, resourceId);
1199
1199
  }
1200
+ var RESOURCE_TOKEN_REGEX_SOURCE = String.raw`\/?(\w+):\/\/([^?\s#]+)\?name=([^&\s#]+)&label=([^#\s]+)(?:#)?`;
1201
+ function createResourceTokenRegex() {
1202
+ return new RegExp(RESOURCE_TOKEN_REGEX_SOURCE, "g");
1203
+ }
1200
1204
  function serializeResourceToken(resourceLabel, resourceName, resourceType, resourceId) {
1201
1205
  return `${encodeURIComponent(resourceType)}://${encodeURIComponent(resourceId)}?name=${encodeURIComponent(resourceName)}&label=${encodeURIComponent(
1202
1206
  resourceLabel
1203
- )}`;
1207
+ )}#`;
1204
1208
  }
1205
1209
  var emptyAgentResources = {
1206
1210
  skills: [],
@@ -1252,6 +1256,45 @@ var categoryValueTypeMap = Object.fromEntries(
1252
1256
  Object.entries(resourceTypeConfigMap).map(([type, config]) => [config.categoryValue, type])
1253
1257
  );
1254
1258
  var isHashCommandConfig = (config) => !!config && !Array.isArray(config);
1259
+ function insertVariableNode(editor, { resourceLabel, resourceName, resourceType, resourceId }, nodeToReplace) {
1260
+ editor.update(() => {
1261
+ const variableNode = $createVariableNode(resourceLabel, resourceName, resourceType, resourceId);
1262
+ if (nodeToReplace) {
1263
+ nodeToReplace.replace(variableNode);
1264
+ variableNode.selectNext();
1265
+ return;
1266
+ }
1267
+ const trailingTextNode = lexical.$createTextNode("");
1268
+ const selection = lexical.$getSelection();
1269
+ if (lexical.$isRangeSelection(selection)) {
1270
+ selection.insertNodes([variableNode, trailingTextNode]);
1271
+ trailingTextNode.select();
1272
+ return;
1273
+ }
1274
+ const root = lexical.$getRoot();
1275
+ const lastChild = root.getLastChild();
1276
+ const paragraph = lastChild?.getType() === "paragraph" ? lastChild : lexical.$createParagraphNode();
1277
+ if (!paragraph.getParent()) {
1278
+ root.append(paragraph);
1279
+ }
1280
+ paragraph.append(variableNode, trailingTextNode);
1281
+ trailingTextNode.select();
1282
+ });
1283
+ }
1284
+ function ResourceInsertPlugin() {
1285
+ const [editor] = LexicalComposerContext.useLexicalComposerContext();
1286
+ const chatStore = useChatStore();
1287
+ const resourceInsertionState = valtio.useSnapshot(chatStore.resourceInsertion);
1288
+ React10.useEffect(() => {
1289
+ const pendingResource = resourceInsertionState.pending;
1290
+ if (!pendingResource) return;
1291
+ editor.focus(() => {
1292
+ insertVariableNode(editor, pendingResource);
1293
+ });
1294
+ chatStore.consumeInsertedResource(pendingResource.requestId);
1295
+ }, [chatStore, editor, resourceInsertionState.pending]);
1296
+ return null;
1297
+ }
1255
1298
  var ResourceOption = class extends LexicalTypeaheadMenuPlugin.MenuOption {
1256
1299
  group;
1257
1300
  item;
@@ -1411,13 +1454,16 @@ function VariablePickerPlugin({ commandConfig = {} }) {
1411
1454
  const resource = selectedOption.item;
1412
1455
  const resourceLabel = selectedOption.group.label;
1413
1456
  const resourceType = selectedOption.group.value;
1414
- editor.update(() => {
1415
- const variableNode = $createVariableNode(resourceLabel, resource.label, resourceType, resource.value);
1416
- if (nodeToReplace) {
1417
- nodeToReplace.replace(variableNode);
1418
- variableNode.selectNext();
1419
- }
1420
- });
1457
+ insertVariableNode(
1458
+ editor,
1459
+ {
1460
+ resourceLabel,
1461
+ resourceName: resource.label,
1462
+ resourceType,
1463
+ resourceId: resource.value
1464
+ },
1465
+ nodeToReplace
1466
+ );
1421
1467
  closeMenu();
1422
1468
  },
1423
1469
  [editor]
@@ -1457,7 +1503,7 @@ function VariablePickerPlugin({ commandConfig = {} }) {
1457
1503
  function InitialStatePlugin({ value }) {
1458
1504
  const [editor] = LexicalComposerContext.useLexicalComposerContext();
1459
1505
  function parseAndAppendNodes(paragraph, value2) {
1460
- const variableRegex = /\/?(\w+):\/\/([^?\s]+)\?name=([^&\s]+)&label=([^\s]+)/g;
1506
+ const variableRegex = createResourceTokenRegex();
1461
1507
  let lastIndex = 0;
1462
1508
  let match;
1463
1509
  while ((match = variableRegex.exec(value2)) !== null) {
@@ -1612,6 +1658,7 @@ var ChatInput = React10__namespace.forwardRef(
1612
1658
  ),
1613
1659
  /* @__PURE__ */ jsxRuntime.jsx(LexicalHistoryPlugin.HistoryPlugin, {}),
1614
1660
  /* @__PURE__ */ jsxRuntime.jsx(VariablePickerPlugin, { commandConfig }),
1661
+ /* @__PURE__ */ jsxRuntime.jsx(ResourceInsertPlugin, {}),
1615
1662
  /* @__PURE__ */ jsxRuntime.jsx(LexicalOnChangePlugin.OnChangePlugin, { onChange: handleOnChange }),
1616
1663
  /* @__PURE__ */ jsxRuntime.jsx(InitialStatePlugin, { value: stringValue })
1617
1664
  ] }) });
@@ -2000,7 +2047,7 @@ function createChatStore() {
2000
2047
  await getAgentInfo(agentInfo.id);
2001
2048
  }
2002
2049
  agent.agentInfo = { ...agent.agentInfo, ...agentInfo };
2003
- if (config.layout.userInput) {
2050
+ if (config.layout.userInput && agent.agentInfo.agentType === 1 /* FLOW */) {
2004
2051
  await getUserInput(agent.agentInfo.id);
2005
2052
  }
2006
2053
  config.hooks?.onAfterSwitchAgent?.(agent.agentInfo);
@@ -2088,6 +2135,7 @@ function createChatStore() {
2088
2135
  }
2089
2136
  await getMessages(conversationId);
2090
2137
  await setPreview();
2138
+ closeSubAgent();
2091
2139
  config.hooks?.onAfterSwitchConversation?.(conversationId);
2092
2140
  };
2093
2141
  const updateConversations = (data) => {
@@ -2217,6 +2265,21 @@ function createChatStore() {
2217
2265
  const focusTarget = valtio.proxy({
2218
2266
  target: null
2219
2267
  });
2268
+ let resourceInsertionRequestId = 0;
2269
+ const resourceInsertion = valtio.proxy({
2270
+ pending: null
2271
+ });
2272
+ const insertResource = (resource) => {
2273
+ resourceInsertion.pending = {
2274
+ requestId: ++resourceInsertionRequestId,
2275
+ ...resource
2276
+ };
2277
+ };
2278
+ const consumeInsertedResource = (requestId) => {
2279
+ if (resourceInsertion.pending?.requestId === requestId) {
2280
+ resourceInsertion.pending = null;
2281
+ }
2282
+ };
2220
2283
  const openSubAgent = async (item) => {
2221
2284
  let subConvId = item.subConversationId ?? item.metadata?.conversationId;
2222
2285
  let agentName = item.agentName;
@@ -2885,6 +2948,7 @@ function createChatStore() {
2885
2948
  const canProceed = await config.hooks?.onBeforeSend?.(msgContent, files || []);
2886
2949
  if (canProceed === false) return;
2887
2950
  if (conversation.active.userInput?.length) {
2951
+ console.log(conversation.active.userInput);
2888
2952
  const invalid = conversation.active.userInput.some((item) => {
2889
2953
  const isRequired = item.rules?.some((r) => r.type === "required");
2890
2954
  if (isRequired) {
@@ -3051,7 +3115,13 @@ function createChatStore() {
3051
3115
  /** 关闭子智能体执行详情面板 */
3052
3116
  closeSubAgent,
3053
3117
  /** 右侧面板聚焦意图(通用) */
3054
- focusTarget
3118
+ focusTarget,
3119
+ /** 待插入的资源节点请求 */
3120
+ resourceInsertion,
3121
+ /** 发起资源节点插入 */
3122
+ insertResource,
3123
+ /** 消费已处理的资源节点请求 */
3124
+ consumeInsertedResource
3055
3125
  };
3056
3126
  }
3057
3127
  var AuthImage = ({ path, size, shape = "square" }) => {
@@ -4128,6 +4198,7 @@ var MdEdit_default = ({ data, loading }) => {
4128
4198
  };
4129
4199
  var PreviewLink_default = ({ data, loading, message: message3, ...rest }) => {
4130
4200
  const chatStore = useChatStore();
4201
+ const conversationId = chatStore.conversation.active?.id;
4131
4202
  const conversationWorkspacePrefix = "/workspace";
4132
4203
  const getLinkFileName = (path) => {
4133
4204
  const lastSegment = path.split("/").pop();
@@ -4157,7 +4228,7 @@ var PreviewLink_default = ({ data, loading, message: message3, ...rest }) => {
4157
4228
  chatStore.setPreview({
4158
4229
  fileUrl: chatStore.config.services.request.getPreviewUrl({
4159
4230
  path: normalizedPath,
4160
- workspaceId: message3.conversationId
4231
+ workspaceId: conversationId
4161
4232
  }),
4162
4233
  fileName,
4163
4234
  suffix
@@ -5921,7 +5992,6 @@ var RunStartedNode = React10__namespace.default.memo(() => {
5921
5992
  ] });
5922
5993
  });
5923
5994
  var RESOURCE_MARKDOWN_TAG = "resourcetag";
5924
- var RESOURCE_TOKEN_REGEX = /(\w+):\/\/([^?\s]+)\?name=([^&\s]+)&label=([^\s]+)/g;
5925
5995
  function QuestionSummary({ content }) {
5926
5996
  const { t: t11 } = common.useTranslation(NS_CHAT_COPILOT);
5927
5997
  return /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { display: "inline-flex", flexDirection: "column", gap: 4 }, children: [
@@ -5935,7 +6005,8 @@ function MessageResourceTag({ data }) {
5935
6005
  return /* @__PURE__ */ jsxRuntime.jsx(ReadonlyResourceTag, { resource });
5936
6006
  }
5937
6007
  function transformResourceText(content) {
5938
- return content.replace(RESOURCE_TOKEN_REGEX, (_, resourceType, resourceId, resourceName, resourceLabel) => {
6008
+ const resourceTokenRegex = createResourceTokenRegex();
6009
+ return content.replace(resourceTokenRegex, (_, resourceType, resourceId, resourceName, resourceLabel) => {
5939
6010
  const resource = {
5940
6011
  resourceType: decodeURIComponent(resourceType),
5941
6012
  resourceId: decodeURIComponent(resourceId),
@@ -6908,29 +6979,8 @@ var emptyAgentResources2 = {
6908
6979
  subAgents: [],
6909
6980
  tools: []
6910
6981
  };
6911
- var focusSenderInputToEnd = () => {
6912
- requestAnimationFrame(() => {
6913
- requestAnimationFrame(() => {
6914
- const input = document.querySelector('.zero-chat-sender .ant-sender-input[contenteditable="true"]');
6915
- if (!input) return;
6916
- input.focus();
6917
- const selection = window.getSelection();
6918
- if (!selection) return;
6919
- const range = document.createRange();
6920
- range.selectNodeContents(input);
6921
- range.collapse(false);
6922
- selection.removeAllRanges();
6923
- selection.addRange(range);
6924
- });
6925
- });
6926
- };
6927
- var appendResourceToken = (content, token) => {
6928
- if (!content) return token;
6929
- return /\s$/.test(content) ? `${content}${token}` : `${content} ${token}`;
6930
- };
6931
6982
  var ResourceBtn_default = ({ types = defaultResourceTypes }) => {
6932
6983
  const chatStore = useChatStore();
6933
- const conversationState = valtio.useSnapshot(chatStore.conversation);
6934
6984
  const { t: t11 } = common.useTranslation(NS_CHAT_COPILOT);
6935
6985
  const [open, setOpen] = React10.useState(false);
6936
6986
  const [loading, setLoading] = React10.useState(false);
@@ -6940,15 +6990,13 @@ var ResourceBtn_default = ({ types = defaultResourceTypes }) => {
6940
6990
  key: getResourceKey(item),
6941
6991
  label: getLabel(item),
6942
6992
  onClick: () => {
6943
- const resourceName = getLabel(item);
6944
- const currentContent = conversationState.messages[conversationState.active.id]?.content || "";
6945
- const nextContent = appendResourceToken(
6946
- currentContent,
6947
- serializeResourceToken(resourceLabel, resourceName, resourceTypeMap[categoryKey].nodeType, getResourceKey(item))
6948
- );
6949
- chatStore.setContent(nextContent);
6993
+ chatStore.insertResource({
6994
+ resourceLabel,
6995
+ resourceName: getLabel(item),
6996
+ resourceType: resourceTypeMap[categoryKey].nodeType,
6997
+ resourceId: getResourceKey(item)
6998
+ });
6950
6999
  setOpen(false);
6951
- focusSenderInputToEnd();
6952
7000
  }
6953
7001
  }));
6954
7002
  const buildSubMenu = (key, label, items2, getLabel) => ({
@@ -6992,7 +7040,7 @@ var ResourceBtn_default = ({ types = defaultResourceTypes }) => {
6992
7040
  label: t11("empty")
6993
7041
  }
6994
7042
  ];
6995
- }, [chatStore, conversationState.active.id, conversationState.messages, loading, resources, t11, types]);
7043
+ }, [chatStore, loading, resources, t11, types]);
6996
7044
  const handleOpenChange = async (nextOpen) => {
6997
7045
  setOpen(nextOpen);
6998
7046
  if (!nextOpen) return;
@@ -7268,10 +7316,19 @@ var UserInputPanel = () => {
7268
7316
  const [activeKey, setActiveKey] = React10.useState(["1"]);
7269
7317
  const { t: t11 } = common.useTranslation(NS_CHAT_COPILOT);
7270
7318
  const inputs = React10.useMemo(() => {
7271
- if (agentState.agentInfo.userInput?.length > 0) {
7272
- return agentState.agentInfo.userInput;
7273
- }
7319
+ return agentState.agentInfo.userInput || [];
7274
7320
  }, [agentState.agentInfo.userInput]);
7321
+ const syncConversationUserInput = React10.useCallback(
7322
+ (values) => {
7323
+ if (inputs.length === 0) return;
7324
+ const newInput = inputs.map((item) => ({
7325
+ ...item,
7326
+ value: values[item.name]
7327
+ }));
7328
+ chatStore.setConversationUserInput(newInput);
7329
+ },
7330
+ [chatStore, inputs]
7331
+ );
7275
7332
  React10.useEffect(() => {
7276
7333
  if (inputs.length > 0) {
7277
7334
  const initialValues = inputs.reduce((acc, cur) => {
@@ -7280,23 +7337,15 @@ var UserInputPanel = () => {
7280
7337
  return acc;
7281
7338
  }, {});
7282
7339
  form.setFieldsValue(initialValues);
7340
+ syncConversationUserInput(initialValues);
7283
7341
  }
7284
- }, [inputs, form]);
7285
- const handleValuesChange = (changedValues) => {
7286
- if (agentState.agentInfo.userInput?.length > 0) {
7287
- const newInput = agentState.agentInfo.userInput.map((v) => {
7288
- if (v.name in changedValues) {
7289
- const newValue = changedValues[v.name];
7290
- return { ...v, value: newValue };
7291
- }
7292
- return v;
7293
- });
7294
- chatStore.setConversationUserInput(newInput);
7295
- return;
7296
- }
7342
+ }, [form, inputs, syncConversationUserInput]);
7343
+ const handleValuesChange = (_changedValues, allValues) => {
7344
+ syncConversationUserInput(allValues);
7297
7345
  };
7298
7346
  const handleStartChat = () => {
7299
7347
  form.validateFields().then(() => {
7348
+ syncConversationUserInput(form.getFieldsValue(true));
7300
7349
  setActiveKey([]);
7301
7350
  }).catch(() => {
7302
7351
  antd.message.error(t11("checkParams"));
@@ -8168,9 +8217,7 @@ var ChatSubAgentPanel_default = ChatSubAgentPanel;
8168
8217
  var index_module_default3 = {
8169
8218
  chatLayout: "index_module_chatLayout",
8170
8219
  animatedSplitter: "index_module_animatedSplitter",
8171
- hideSplitterBar: "index_module_hideSplitterBar",
8172
- rightTabs: "index_module_rightTabs"
8173
- };
8220
+ hideSplitterBar: "index_module_hideSplitterBar"};
8174
8221
  var layouts_default = React10.forwardRef(({ theme: theme3, params, hooks, layout, config, services }, _ref) => {
8175
8222
  const { t: t11 } = common.useTranslation(NS_CHAT_COPILOT);
8176
8223
  const chatStore = React10.useMemo(() => createChatStore(), []);
@@ -8310,7 +8357,7 @@ var layouts_default = React10.forwardRef(({ theme: theme3, params, hooks, layout
8310
8357
  hasRightPanel && /* @__PURE__ */ jsxRuntime.jsx(antd.Splitter.Panel, { collapsible: false, min: 360, size: sizes[1], children: /* @__PURE__ */ jsxRuntime.jsx(
8311
8358
  antd.Tabs,
8312
8359
  {
8313
- className: classNames9__default.default("height-full", index_module_default3.rightTabs),
8360
+ className: "full-tabs",
8314
8361
  activeKey: effectiveRightTab,
8315
8362
  onChange: (k) => setActiveRightTab(k),
8316
8363
  tabBarStyle: { marginBottom: 0 },