@siact/sime-x-vue 0.0.11 → 0.0.12
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/sime-x-vue.mjs +55 -16
- package/dist/sime-x-vue.mjs.map +1 -1
- package/dist/sime-x-vue.umd.js +55 -16
- package/dist/sime-x-vue.umd.js.map +1 -1
- package/package.json +1 -1
package/dist/sime-x-vue.umd.js
CHANGED
|
@@ -1683,8 +1683,43 @@
|
|
|
1683
1683
|
args: Array.isArray(cmd.args) ? cmd.args : []
|
|
1684
1684
|
}));
|
|
1685
1685
|
};
|
|
1686
|
-
const
|
|
1687
|
-
|
|
1686
|
+
const buildCommandDefinitionMap = (commands) => {
|
|
1687
|
+
return new Map(commands.map((command) => [command.name, command]));
|
|
1688
|
+
};
|
|
1689
|
+
const toExecutableCommand = (toolName, payload, commandDefinitions) => {
|
|
1690
|
+
const commandDefinition = commandDefinitions.get(toolName);
|
|
1691
|
+
if (!commandDefinition) {
|
|
1692
|
+
return null;
|
|
1693
|
+
}
|
|
1694
|
+
const parameters = commandDefinition.parameters || [];
|
|
1695
|
+
if (Array.isArray(payload)) {
|
|
1696
|
+
return {
|
|
1697
|
+
name: toolName,
|
|
1698
|
+
args: payload
|
|
1699
|
+
};
|
|
1700
|
+
}
|
|
1701
|
+
if (!payload || typeof payload !== "object") {
|
|
1702
|
+
return {
|
|
1703
|
+
name: toolName,
|
|
1704
|
+
args: []
|
|
1705
|
+
};
|
|
1706
|
+
}
|
|
1707
|
+
const payloadRecord = payload;
|
|
1708
|
+
return {
|
|
1709
|
+
name: toolName,
|
|
1710
|
+
args: parameters.map((parameter) => payloadRecord[parameter.name])
|
|
1711
|
+
};
|
|
1712
|
+
};
|
|
1713
|
+
const resolveExecutableCommands = (toolName, payload, commandDefinitions) => {
|
|
1714
|
+
const extractedCommands = extractExecutableCommands(payload);
|
|
1715
|
+
if (extractedCommands.length > 0) {
|
|
1716
|
+
return extractedCommands;
|
|
1717
|
+
}
|
|
1718
|
+
const directCommand = toExecutableCommand(toolName, payload, commandDefinitions);
|
|
1719
|
+
return directCommand ? [directCommand] : [];
|
|
1720
|
+
};
|
|
1721
|
+
const executeHostCommands = async (toolCallId, toolName, payload, commandDefinitions) => {
|
|
1722
|
+
const commands = resolveExecutableCommands(toolName, payload, commandDefinitions);
|
|
1688
1723
|
if (commands.length === 0) return false;
|
|
1689
1724
|
try {
|
|
1690
1725
|
executingTools.value = /* @__PURE__ */ new Set([...executingTools.value, toolCallId]);
|
|
@@ -1732,6 +1767,7 @@
|
|
|
1732
1767
|
const processingToolResults = /* @__PURE__ */ new Set();
|
|
1733
1768
|
abortController = new AbortController();
|
|
1734
1769
|
const commands = await aiChatbotX.getCommads();
|
|
1770
|
+
const commandDefinitions = buildCommandDefinitionMap(commands);
|
|
1735
1771
|
conversationHistory.value.length > 0 ? [...conversationHistory.value] : void 0;
|
|
1736
1772
|
try {
|
|
1737
1773
|
const response = await fetch(options.endpoint.value, {
|
|
@@ -1766,9 +1802,8 @@
|
|
|
1766
1802
|
state: "result"
|
|
1767
1803
|
};
|
|
1768
1804
|
currentToolParts.value = [...currentToolParts.value, toolPart];
|
|
1769
|
-
if (tr.toolName
|
|
1770
|
-
|
|
1771
|
-
void executeHostCommands(toolPart.toolCallId, tr.result);
|
|
1805
|
+
if (commandDefinitions.has(tr.toolName)) {
|
|
1806
|
+
void executeHostCommands(toolPart.toolCallId, tr.toolName, tr.result, commandDefinitions);
|
|
1772
1807
|
}
|
|
1773
1808
|
}
|
|
1774
1809
|
}
|
|
@@ -1785,23 +1820,27 @@
|
|
|
1785
1820
|
);
|
|
1786
1821
|
currentToolParts.value = toolParts;
|
|
1787
1822
|
for (const part of toolParts) {
|
|
1788
|
-
if (part.toolName
|
|
1823
|
+
if (commandDefinitions.has(part.toolName) && !processedToolResults.has(part.toolCallId) && !processingToolResults.has(part.toolCallId)) {
|
|
1789
1824
|
if (part.type === "tool-call" && part.state === "call" && part.args) {
|
|
1790
1825
|
processingToolResults.add(part.toolCallId);
|
|
1791
|
-
void executeHostCommands(part.toolCallId, part.args).then(
|
|
1792
|
-
|
|
1793
|
-
|
|
1826
|
+
void executeHostCommands(part.toolCallId, part.toolName, part.args, commandDefinitions).then(
|
|
1827
|
+
(executed) => {
|
|
1828
|
+
if (executed) {
|
|
1829
|
+
processedToolResults.add(part.toolCallId);
|
|
1830
|
+
}
|
|
1831
|
+
processingToolResults.delete(part.toolCallId);
|
|
1794
1832
|
}
|
|
1795
|
-
|
|
1796
|
-
});
|
|
1833
|
+
);
|
|
1797
1834
|
} else if (part.type === "tool-result" && part.result) {
|
|
1798
1835
|
processingToolResults.add(part.toolCallId);
|
|
1799
|
-
void executeHostCommands(part.toolCallId, part.result).then(
|
|
1800
|
-
|
|
1801
|
-
|
|
1836
|
+
void executeHostCommands(part.toolCallId, part.toolName, part.result, commandDefinitions).then(
|
|
1837
|
+
(executed) => {
|
|
1838
|
+
if (executed) {
|
|
1839
|
+
processedToolResults.add(part.toolCallId);
|
|
1840
|
+
}
|
|
1841
|
+
processingToolResults.delete(part.toolCallId);
|
|
1802
1842
|
}
|
|
1803
|
-
|
|
1804
|
-
});
|
|
1843
|
+
);
|
|
1805
1844
|
}
|
|
1806
1845
|
}
|
|
1807
1846
|
}
|