@siact/sime-x-vue 0.0.11 → 0.0.13
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 +67 -27
- package/dist/sime-x-vue.mjs.map +1 -1
- package/dist/sime-x-vue.umd.js +67 -27
- package/dist/sime-x-vue.umd.js.map +1 -1
- package/dist/style.css +60 -60
- package/package.json +1 -1
- package/types/components/sime-provider.vue.d.ts +2 -0
- package/types/components/voice-assistant.vue.d.ts +1 -1
- package/types/composables/use-agent-invoke.d.ts +7 -7
- package/types/types.d.ts +1 -0
- /package/dist/{sime.png → x.png} +0 -0
package/dist/sime-x-vue.mjs
CHANGED
|
@@ -773,7 +773,8 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
773
773
|
debug: { type: Boolean },
|
|
774
774
|
chatbotUrl: {},
|
|
775
775
|
appId: {},
|
|
776
|
-
appToken: {}
|
|
776
|
+
appToken: {},
|
|
777
|
+
agentId: {}
|
|
777
778
|
},
|
|
778
779
|
setup(__props) {
|
|
779
780
|
const props = __props;
|
|
@@ -784,6 +785,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
784
785
|
chatbotUrl: () => props.chatbotUrl,
|
|
785
786
|
appId: () => props.appId,
|
|
786
787
|
appToken: () => props.appToken,
|
|
788
|
+
agentId: () => props.agentId,
|
|
787
789
|
stopBroadcast: () => stopBroadcastRef.value(),
|
|
788
790
|
registerVoiceMethods: (methods) => {
|
|
789
791
|
if (methods.stopBroadcast) stopBroadcastRef.value = methods.stopBroadcast;
|
|
@@ -1682,8 +1684,43 @@ function useAgentInvoke(options) {
|
|
|
1682
1684
|
args: Array.isArray(cmd.args) ? cmd.args : []
|
|
1683
1685
|
}));
|
|
1684
1686
|
};
|
|
1685
|
-
const
|
|
1686
|
-
|
|
1687
|
+
const buildCommandDefinitionMap = (commands) => {
|
|
1688
|
+
return new Map(commands.map((command) => [command.name, command]));
|
|
1689
|
+
};
|
|
1690
|
+
const toExecutableCommand = (toolName, payload, commandDefinitions) => {
|
|
1691
|
+
const commandDefinition = commandDefinitions.get(toolName);
|
|
1692
|
+
if (!commandDefinition) {
|
|
1693
|
+
return null;
|
|
1694
|
+
}
|
|
1695
|
+
const parameters = commandDefinition.parameters || [];
|
|
1696
|
+
if (Array.isArray(payload)) {
|
|
1697
|
+
return {
|
|
1698
|
+
name: toolName,
|
|
1699
|
+
args: payload
|
|
1700
|
+
};
|
|
1701
|
+
}
|
|
1702
|
+
if (!payload || typeof payload !== "object") {
|
|
1703
|
+
return {
|
|
1704
|
+
name: toolName,
|
|
1705
|
+
args: []
|
|
1706
|
+
};
|
|
1707
|
+
}
|
|
1708
|
+
const payloadRecord = payload;
|
|
1709
|
+
return {
|
|
1710
|
+
name: toolName,
|
|
1711
|
+
args: parameters.map((parameter) => payloadRecord[parameter.name])
|
|
1712
|
+
};
|
|
1713
|
+
};
|
|
1714
|
+
const resolveExecutableCommands = (toolName, payload, commandDefinitions) => {
|
|
1715
|
+
const extractedCommands = extractExecutableCommands(payload);
|
|
1716
|
+
if (extractedCommands.length > 0) {
|
|
1717
|
+
return extractedCommands;
|
|
1718
|
+
}
|
|
1719
|
+
const directCommand = toExecutableCommand(toolName, payload, commandDefinitions);
|
|
1720
|
+
return directCommand ? [directCommand] : [];
|
|
1721
|
+
};
|
|
1722
|
+
const executeHostCommands = async (toolCallId, toolName, payload, commandDefinitions) => {
|
|
1723
|
+
const commands = resolveExecutableCommands(toolName, payload, commandDefinitions);
|
|
1687
1724
|
if (commands.length === 0) return false;
|
|
1688
1725
|
try {
|
|
1689
1726
|
executingTools.value = /* @__PURE__ */ new Set([...executingTools.value, toolCallId]);
|
|
@@ -1731,11 +1768,12 @@ function useAgentInvoke(options) {
|
|
|
1731
1768
|
const processingToolResults = /* @__PURE__ */ new Set();
|
|
1732
1769
|
abortController = new AbortController();
|
|
1733
1770
|
const commands = await aiChatbotX.getCommads();
|
|
1771
|
+
const commandDefinitions = buildCommandDefinitionMap(commands);
|
|
1734
1772
|
conversationHistory.value.length > 0 ? [...conversationHistory.value] : void 0;
|
|
1735
1773
|
try {
|
|
1736
|
-
const response = await fetch(options.endpoint
|
|
1774
|
+
const response = await fetch(options.endpoint, {
|
|
1737
1775
|
method: "POST",
|
|
1738
|
-
headers: { "Content-Type": "application/json" },
|
|
1776
|
+
headers: { "Content-Type": "application/json", Authorization: `Bearer ${options.appToken || ""}` },
|
|
1739
1777
|
body: JSON.stringify({
|
|
1740
1778
|
input: content,
|
|
1741
1779
|
projectId: options.projectId || "",
|
|
@@ -1765,9 +1803,8 @@ function useAgentInvoke(options) {
|
|
|
1765
1803
|
state: "result"
|
|
1766
1804
|
};
|
|
1767
1805
|
currentToolParts.value = [...currentToolParts.value, toolPart];
|
|
1768
|
-
if (tr.toolName
|
|
1769
|
-
|
|
1770
|
-
void executeHostCommands(toolPart.toolCallId, tr.result);
|
|
1806
|
+
if (commandDefinitions.has(tr.toolName)) {
|
|
1807
|
+
void executeHostCommands(toolPart.toolCallId, tr.toolName, tr.result, commandDefinitions);
|
|
1771
1808
|
}
|
|
1772
1809
|
}
|
|
1773
1810
|
}
|
|
@@ -1784,23 +1821,27 @@ function useAgentInvoke(options) {
|
|
|
1784
1821
|
);
|
|
1785
1822
|
currentToolParts.value = toolParts;
|
|
1786
1823
|
for (const part of toolParts) {
|
|
1787
|
-
if (part.toolName
|
|
1824
|
+
if (commandDefinitions.has(part.toolName) && !processedToolResults.has(part.toolCallId) && !processingToolResults.has(part.toolCallId)) {
|
|
1788
1825
|
if (part.type === "tool-call" && part.state === "call" && part.args) {
|
|
1789
1826
|
processingToolResults.add(part.toolCallId);
|
|
1790
|
-
void executeHostCommands(part.toolCallId, part.args).then(
|
|
1791
|
-
|
|
1792
|
-
|
|
1827
|
+
void executeHostCommands(part.toolCallId, part.toolName, part.args, commandDefinitions).then(
|
|
1828
|
+
(executed) => {
|
|
1829
|
+
if (executed) {
|
|
1830
|
+
processedToolResults.add(part.toolCallId);
|
|
1831
|
+
}
|
|
1832
|
+
processingToolResults.delete(part.toolCallId);
|
|
1793
1833
|
}
|
|
1794
|
-
|
|
1795
|
-
});
|
|
1834
|
+
);
|
|
1796
1835
|
} else if (part.type === "tool-result" && part.result) {
|
|
1797
1836
|
processingToolResults.add(part.toolCallId);
|
|
1798
|
-
void executeHostCommands(part.toolCallId, part.result).then(
|
|
1799
|
-
|
|
1800
|
-
|
|
1837
|
+
void executeHostCommands(part.toolCallId, part.toolName, part.result, commandDefinitions).then(
|
|
1838
|
+
(executed) => {
|
|
1839
|
+
if (executed) {
|
|
1840
|
+
processedToolResults.add(part.toolCallId);
|
|
1841
|
+
}
|
|
1842
|
+
processingToolResults.delete(part.toolCallId);
|
|
1801
1843
|
}
|
|
1802
|
-
|
|
1803
|
-
});
|
|
1844
|
+
);
|
|
1804
1845
|
}
|
|
1805
1846
|
}
|
|
1806
1847
|
}
|
|
@@ -1909,9 +1950,9 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1909
1950
|
xSize: {},
|
|
1910
1951
|
xTheme: {},
|
|
1911
1952
|
wakeWords: {},
|
|
1953
|
+
wakeResponses: {},
|
|
1912
1954
|
modelPath: {},
|
|
1913
1955
|
projectId: {},
|
|
1914
|
-
invokeUrl: {},
|
|
1915
1956
|
voiceConfig: {},
|
|
1916
1957
|
bubbleSize: {},
|
|
1917
1958
|
bubbleDismissDelay: {}
|
|
@@ -1923,10 +1964,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1923
1964
|
if (props.voiceConfig) return props.voiceConfig;
|
|
1924
1965
|
return null;
|
|
1925
1966
|
};
|
|
1926
|
-
const
|
|
1927
|
-
return props.invokeUrl || "http://localhost:3001/agent/zyy55sw40nrl801056m0o/stream-invoke";
|
|
1928
|
-
});
|
|
1929
|
-
const wakeResponses = ["在呢"];
|
|
1967
|
+
const wakeResponses = computed(() => props.wakeResponses || ["在呢"]);
|
|
1930
1968
|
const tts = useTTS(getVoiceConfig);
|
|
1931
1969
|
const bubbleBridge = {
|
|
1932
1970
|
open: () => {
|
|
@@ -1936,8 +1974,10 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1936
1974
|
scrollToBottom: () => {
|
|
1937
1975
|
}
|
|
1938
1976
|
};
|
|
1977
|
+
const endpoint = `/sime/proxy/agent/${aiChatbotX.agentId()}/stream-invoke`;
|
|
1939
1978
|
const agent = useAgentInvoke({
|
|
1940
1979
|
endpoint,
|
|
1980
|
+
appToken: aiChatbotX.appToken(),
|
|
1941
1981
|
projectId: props.projectId,
|
|
1942
1982
|
aiChatbotX,
|
|
1943
1983
|
tts: {
|
|
@@ -1976,7 +2016,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
1976
2016
|
onWake: () => {
|
|
1977
2017
|
interruptCurrentResponse();
|
|
1978
2018
|
tts.warmUpAudio();
|
|
1979
|
-
const text = wakeResponses[Math.floor(Math.random() * wakeResponses.length)];
|
|
2019
|
+
const text = wakeResponses.value[Math.floor(Math.random() * wakeResponses.value.length)];
|
|
1980
2020
|
tts.speak(text);
|
|
1981
2021
|
},
|
|
1982
2022
|
onTranscriptionDone: (text) => {
|
|
@@ -2082,7 +2122,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2082
2122
|
unref(transcriptionText) || unref(isInvoking) ? (openBlock(), createElementBlock("div", _hoisted_11, toDisplayString(unref(isInvoking) ? "正在思考中..." : unref(transcriptionText)), 1)) : createCommentVNode("", true),
|
|
2083
2123
|
createElementVNode("div", _hoisted_12, [
|
|
2084
2124
|
createElementVNode("img", {
|
|
2085
|
-
src: __props.xLogo ? __props.xLogo : "/
|
|
2125
|
+
src: __props.xLogo ? __props.xLogo : "/x.png",
|
|
2086
2126
|
alt: "voice assistant",
|
|
2087
2127
|
style: normalizeStyle({
|
|
2088
2128
|
width: `${__props.xSize?.width || 88}px`
|
|
@@ -2129,7 +2169,7 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
|
2129
2169
|
}
|
|
2130
2170
|
});
|
|
2131
2171
|
|
|
2132
|
-
const voiceAssistant = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-
|
|
2172
|
+
const voiceAssistant = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-a88f03ab"]]);
|
|
2133
2173
|
|
|
2134
2174
|
var clientCommandKey = /* @__PURE__ */ ((clientCommandKey2) => {
|
|
2135
2175
|
clientCommandKey2["SET_THEME"] = "SiMeAgent_setTheme";
|