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