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