@zero-library/chat-copilot 3.2.4 → 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 +110 -62
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.css +1 -0
- package/dist/index.css.map +1 -1
- package/dist/index.esm.js +111 -63
- package/dist/index.esm.js.map +1 -1
- package/package.json +4 -4
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("
|
|
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("
|
|
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
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
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 =
|
|
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);
|
|
@@ -2218,6 +2265,21 @@ function createChatStore() {
|
|
|
2218
2265
|
const focusTarget = valtio.proxy({
|
|
2219
2266
|
target: null
|
|
2220
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
|
+
};
|
|
2221
2283
|
const openSubAgent = async (item) => {
|
|
2222
2284
|
let subConvId = item.subConversationId ?? item.metadata?.conversationId;
|
|
2223
2285
|
let agentName = item.agentName;
|
|
@@ -2886,6 +2948,7 @@ function createChatStore() {
|
|
|
2886
2948
|
const canProceed = await config.hooks?.onBeforeSend?.(msgContent, files || []);
|
|
2887
2949
|
if (canProceed === false) return;
|
|
2888
2950
|
if (conversation.active.userInput?.length) {
|
|
2951
|
+
console.log(conversation.active.userInput);
|
|
2889
2952
|
const invalid = conversation.active.userInput.some((item) => {
|
|
2890
2953
|
const isRequired = item.rules?.some((r) => r.type === "required");
|
|
2891
2954
|
if (isRequired) {
|
|
@@ -3052,7 +3115,13 @@ function createChatStore() {
|
|
|
3052
3115
|
/** 关闭子智能体执行详情面板 */
|
|
3053
3116
|
closeSubAgent,
|
|
3054
3117
|
/** 右侧面板聚焦意图(通用) */
|
|
3055
|
-
focusTarget
|
|
3118
|
+
focusTarget,
|
|
3119
|
+
/** 待插入的资源节点请求 */
|
|
3120
|
+
resourceInsertion,
|
|
3121
|
+
/** 发起资源节点插入 */
|
|
3122
|
+
insertResource,
|
|
3123
|
+
/** 消费已处理的资源节点请求 */
|
|
3124
|
+
consumeInsertedResource
|
|
3056
3125
|
};
|
|
3057
3126
|
}
|
|
3058
3127
|
var AuthImage = ({ path, size, shape = "square" }) => {
|
|
@@ -4129,6 +4198,7 @@ var MdEdit_default = ({ data, loading }) => {
|
|
|
4129
4198
|
};
|
|
4130
4199
|
var PreviewLink_default = ({ data, loading, message: message3, ...rest }) => {
|
|
4131
4200
|
const chatStore = useChatStore();
|
|
4201
|
+
const conversationId = chatStore.conversation.active?.id;
|
|
4132
4202
|
const conversationWorkspacePrefix = "/workspace";
|
|
4133
4203
|
const getLinkFileName = (path) => {
|
|
4134
4204
|
const lastSegment = path.split("/").pop();
|
|
@@ -4158,7 +4228,7 @@ var PreviewLink_default = ({ data, loading, message: message3, ...rest }) => {
|
|
|
4158
4228
|
chatStore.setPreview({
|
|
4159
4229
|
fileUrl: chatStore.config.services.request.getPreviewUrl({
|
|
4160
4230
|
path: normalizedPath,
|
|
4161
|
-
workspaceId:
|
|
4231
|
+
workspaceId: conversationId
|
|
4162
4232
|
}),
|
|
4163
4233
|
fileName,
|
|
4164
4234
|
suffix
|
|
@@ -5922,7 +5992,6 @@ var RunStartedNode = React10__namespace.default.memo(() => {
|
|
|
5922
5992
|
] });
|
|
5923
5993
|
});
|
|
5924
5994
|
var RESOURCE_MARKDOWN_TAG = "resourcetag";
|
|
5925
|
-
var RESOURCE_TOKEN_REGEX = /(\w+):\/\/([^?\s]+)\?name=([^&\s]+)&label=([^\s]+)/g;
|
|
5926
5995
|
function QuestionSummary({ content }) {
|
|
5927
5996
|
const { t: t11 } = common.useTranslation(NS_CHAT_COPILOT);
|
|
5928
5997
|
return /* @__PURE__ */ jsxRuntime.jsxs("span", { style: { display: "inline-flex", flexDirection: "column", gap: 4 }, children: [
|
|
@@ -5936,7 +6005,8 @@ function MessageResourceTag({ data }) {
|
|
|
5936
6005
|
return /* @__PURE__ */ jsxRuntime.jsx(ReadonlyResourceTag, { resource });
|
|
5937
6006
|
}
|
|
5938
6007
|
function transformResourceText(content) {
|
|
5939
|
-
|
|
6008
|
+
const resourceTokenRegex = createResourceTokenRegex();
|
|
6009
|
+
return content.replace(resourceTokenRegex, (_, resourceType, resourceId, resourceName, resourceLabel) => {
|
|
5940
6010
|
const resource = {
|
|
5941
6011
|
resourceType: decodeURIComponent(resourceType),
|
|
5942
6012
|
resourceId: decodeURIComponent(resourceId),
|
|
@@ -6909,29 +6979,8 @@ var emptyAgentResources2 = {
|
|
|
6909
6979
|
subAgents: [],
|
|
6910
6980
|
tools: []
|
|
6911
6981
|
};
|
|
6912
|
-
var focusSenderInputToEnd = () => {
|
|
6913
|
-
requestAnimationFrame(() => {
|
|
6914
|
-
requestAnimationFrame(() => {
|
|
6915
|
-
const input = document.querySelector('.zero-chat-sender .ant-sender-input[contenteditable="true"]');
|
|
6916
|
-
if (!input) return;
|
|
6917
|
-
input.focus();
|
|
6918
|
-
const selection = window.getSelection();
|
|
6919
|
-
if (!selection) return;
|
|
6920
|
-
const range = document.createRange();
|
|
6921
|
-
range.selectNodeContents(input);
|
|
6922
|
-
range.collapse(false);
|
|
6923
|
-
selection.removeAllRanges();
|
|
6924
|
-
selection.addRange(range);
|
|
6925
|
-
});
|
|
6926
|
-
});
|
|
6927
|
-
};
|
|
6928
|
-
var appendResourceToken = (content, token) => {
|
|
6929
|
-
if (!content) return token;
|
|
6930
|
-
return /\s$/.test(content) ? `${content}${token}` : `${content} ${token}`;
|
|
6931
|
-
};
|
|
6932
6982
|
var ResourceBtn_default = ({ types = defaultResourceTypes }) => {
|
|
6933
6983
|
const chatStore = useChatStore();
|
|
6934
|
-
const conversationState = valtio.useSnapshot(chatStore.conversation);
|
|
6935
6984
|
const { t: t11 } = common.useTranslation(NS_CHAT_COPILOT);
|
|
6936
6985
|
const [open, setOpen] = React10.useState(false);
|
|
6937
6986
|
const [loading, setLoading] = React10.useState(false);
|
|
@@ -6941,15 +6990,13 @@ var ResourceBtn_default = ({ types = defaultResourceTypes }) => {
|
|
|
6941
6990
|
key: getResourceKey(item),
|
|
6942
6991
|
label: getLabel(item),
|
|
6943
6992
|
onClick: () => {
|
|
6944
|
-
|
|
6945
|
-
|
|
6946
|
-
|
|
6947
|
-
|
|
6948
|
-
|
|
6949
|
-
);
|
|
6950
|
-
chatStore.setContent(nextContent);
|
|
6993
|
+
chatStore.insertResource({
|
|
6994
|
+
resourceLabel,
|
|
6995
|
+
resourceName: getLabel(item),
|
|
6996
|
+
resourceType: resourceTypeMap[categoryKey].nodeType,
|
|
6997
|
+
resourceId: getResourceKey(item)
|
|
6998
|
+
});
|
|
6951
6999
|
setOpen(false);
|
|
6952
|
-
focusSenderInputToEnd();
|
|
6953
7000
|
}
|
|
6954
7001
|
}));
|
|
6955
7002
|
const buildSubMenu = (key, label, items2, getLabel) => ({
|
|
@@ -6993,7 +7040,7 @@ var ResourceBtn_default = ({ types = defaultResourceTypes }) => {
|
|
|
6993
7040
|
label: t11("empty")
|
|
6994
7041
|
}
|
|
6995
7042
|
];
|
|
6996
|
-
}, [chatStore,
|
|
7043
|
+
}, [chatStore, loading, resources, t11, types]);
|
|
6997
7044
|
const handleOpenChange = async (nextOpen) => {
|
|
6998
7045
|
setOpen(nextOpen);
|
|
6999
7046
|
if (!nextOpen) return;
|
|
@@ -7269,10 +7316,19 @@ var UserInputPanel = () => {
|
|
|
7269
7316
|
const [activeKey, setActiveKey] = React10.useState(["1"]);
|
|
7270
7317
|
const { t: t11 } = common.useTranslation(NS_CHAT_COPILOT);
|
|
7271
7318
|
const inputs = React10.useMemo(() => {
|
|
7272
|
-
|
|
7273
|
-
return agentState.agentInfo.userInput;
|
|
7274
|
-
}
|
|
7319
|
+
return agentState.agentInfo.userInput || [];
|
|
7275
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
|
+
);
|
|
7276
7332
|
React10.useEffect(() => {
|
|
7277
7333
|
if (inputs.length > 0) {
|
|
7278
7334
|
const initialValues = inputs.reduce((acc, cur) => {
|
|
@@ -7281,23 +7337,15 @@ var UserInputPanel = () => {
|
|
|
7281
7337
|
return acc;
|
|
7282
7338
|
}, {});
|
|
7283
7339
|
form.setFieldsValue(initialValues);
|
|
7340
|
+
syncConversationUserInput(initialValues);
|
|
7284
7341
|
}
|
|
7285
|
-
}, [inputs,
|
|
7286
|
-
const handleValuesChange = (
|
|
7287
|
-
|
|
7288
|
-
const newInput = agentState.agentInfo.userInput.map((v) => {
|
|
7289
|
-
if (v.name in changedValues) {
|
|
7290
|
-
const newValue = changedValues[v.name];
|
|
7291
|
-
return { ...v, value: newValue };
|
|
7292
|
-
}
|
|
7293
|
-
return v;
|
|
7294
|
-
});
|
|
7295
|
-
chatStore.setConversationUserInput(newInput);
|
|
7296
|
-
return;
|
|
7297
|
-
}
|
|
7342
|
+
}, [form, inputs, syncConversationUserInput]);
|
|
7343
|
+
const handleValuesChange = (_changedValues, allValues) => {
|
|
7344
|
+
syncConversationUserInput(allValues);
|
|
7298
7345
|
};
|
|
7299
7346
|
const handleStartChat = () => {
|
|
7300
7347
|
form.validateFields().then(() => {
|
|
7348
|
+
syncConversationUserInput(form.getFieldsValue(true));
|
|
7301
7349
|
setActiveKey([]);
|
|
7302
7350
|
}).catch(() => {
|
|
7303
7351
|
antd.message.error(t11("checkParams"));
|