{"version":3,"file":"index.mjs","names":[],"sources":["../../src/agent-xiaozhi/xiaozhi-client.ts","../../src/agent-xiaozhi/xiaozhi.ts"],"sourcesContent":["/* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD */\n/* SPDX-License-Identifier: Apache-2.0 */\n\nimport {\n  callServiceFunction,\n  closeService,\n  isServiceAvailable,\n  openService,\n  resolveHost,\n  type ServiceClientOptions,\n  type ServiceHandle,\n} from '../common/service-rpc.ts';\nimport type { XiaozhiMcpTool } from './xiaozhi-types.ts';\n\nexport const XIAOZHI_SERVICE_NAME = 'XiaoZhi';\n\nexport const XIAOZHI_FUNCTIONS = {\n  AddMcpToolsWithServiceFunction: 'AddMCP_ToolsWithServiceFunction',\n  AddMcpToolsWithCustomFunction: 'AddMCP_ToolsWithCustomFunction',\n  RemoveMcpTools: 'RemoveMCP_Tools',\n  ExplainImage: 'ExplainImage',\n} as const;\n\nexport type XiaozhiClientOptions = ServiceClientOptions;\nexport { type ServiceHandle as XiaozhiHandle };\n\nexport function isXiaozhiAvailable(options?: XiaozhiClientOptions): boolean {\n  return isServiceAvailable(XIAOZHI_SERVICE_NAME, options);\n}\n\nexport function openXiaozhi(options?: XiaozhiClientOptions): ServiceHandle {\n  return openService(XIAOZHI_SERVICE_NAME, options);\n}\n\nexport function closeXiaozhi(handle: ServiceHandle, options?: XiaozhiClientOptions): void {\n  closeService(handle, options);\n}\n\nexport function addMcpToolsWithServiceFunction(\n  handle: ServiceHandle,\n  serviceName: string,\n  functionNames: string[],\n  options?: XiaozhiClientOptions,\n): string[] {\n  return callServiceFunction<string[]>(\n    resolveHost(options),\n    handle,\n    XIAOZHI_FUNCTIONS.AddMcpToolsWithServiceFunction,\n    {\n      ServiceName: serviceName,\n      FunctionNames: functionNames,\n    },\n  );\n}\n\nexport function addMcpToolsWithCustomFunction(\n  handle: ServiceHandle,\n  tools: XiaozhiMcpTool[],\n  options?: XiaozhiClientOptions,\n): string[] {\n  return callServiceFunction<string[]>(\n    resolveHost(options),\n    handle,\n    XIAOZHI_FUNCTIONS.AddMcpToolsWithCustomFunction,\n    {\n      Tools: tools,\n    },\n  );\n}\n\nexport function removeMcpTools(\n  handle: ServiceHandle,\n  toolNames: string[],\n  options?: XiaozhiClientOptions,\n): void {\n  callServiceFunction<void>(resolveHost(options), handle, XIAOZHI_FUNCTIONS.RemoveMcpTools, {\n    Tools: toolNames,\n  });\n}\n\nexport function explainImage(\n  handle: ServiceHandle,\n  imageData: ArrayBuffer | Uint8Array,\n  question: string,\n  options?: XiaozhiClientOptions,\n): string {\n  return callServiceFunction<string>(resolveHost(options), handle, XIAOZHI_FUNCTIONS.ExplainImage, {\n    Image: imageData,\n    Question: question,\n  });\n}\n","/* SPDX-FileCopyrightText: 2026 Espressif Systems (Shanghai) CO LTD */\n/* SPDX-License-Identifier: Apache-2.0 */\n\nimport {\n  addMcpToolsWithCustomFunction,\n  addMcpToolsWithServiceFunction,\n  closeXiaozhi,\n  explainImage,\n  isXiaozhiAvailable,\n  openXiaozhi,\n  removeMcpTools,\n  type XiaozhiClientOptions,\n  type XiaozhiHandle,\n} from './xiaozhi-client.ts';\nimport type { XiaozhiMcpTool } from './xiaozhi-types.ts';\n\nexport type XiaozhiModuleOptions = XiaozhiClientOptions;\n\ntype State = { handle: XiaozhiHandle | null; options: XiaozhiModuleOptions };\nconst state: State = { handle: null, options: {} };\n\nfunction handle(): XiaozhiHandle {\n  if (state.handle !== null) return state.handle;\n  if (!isXiaozhiAvailable(state.options)) throw new Error('XiaoZhi service is not available');\n  state.handle = openXiaozhi(state.options);\n  return state.handle;\n}\n\nexport function configure(options: XiaozhiModuleOptions): void {\n  if (state.handle !== null) closeXiaozhi(state.handle, state.options);\n  state.handle = null;\n  state.options = options;\n}\n\nconst xiaozhi = {\n  available(): boolean {\n    return isXiaozhiAvailable(state.options);\n  },\n  close(): void {\n    if (state.handle === null) return;\n    closeXiaozhi(state.handle, state.options);\n    state.handle = null;\n  },\n  addMcpToolsWithServiceFunction(serviceName: string, functionNames: string[]): string[] {\n    return addMcpToolsWithServiceFunction(handle(), serviceName, functionNames, state.options);\n  },\n  addMcpToolsWithCustomFunction(tools: XiaozhiMcpTool[]): string[] {\n    return addMcpToolsWithCustomFunction(handle(), tools, state.options);\n  },\n  removeMcpTools(toolNames: string[]): void {\n    removeMcpTools(handle(), toolNames, state.options);\n  },\n  explainImage(imageData: ArrayBuffer | Uint8Array, question: string): string {\n    return explainImage(handle(), imageData, question, state.options);\n  },\n};\n\nexport default xiaozhi;\n"],"mappings":";;AAcA,MAAa,uBAAuB;AAEpC,MAAa,oBAAoB;CAC/B,gCAAgC;CAChC,+BAA+B;CAC/B,gBAAgB;CAChB,cAAc;AAChB;AAKA,SAAgB,mBAAmB,SAAyC;CAC1E,OAAO,mBAAmB,sBAAsB,OAAO;AACzD;AAEA,SAAgB,YAAY,SAA+C;CACzE,OAAO,YAAY,sBAAsB,OAAO;AAClD;AAEA,SAAgB,aAAa,QAAuB,SAAsC;CACxF,aAAa,QAAQ,OAAO;AAC9B;AAEA,SAAgB,+BACd,QACA,aACA,eACA,SACU;CACV,OAAO,oBACL,YAAY,OAAO,GACnB,QACA,kBAAkB,gCAClB;EACE,aAAa;EACb,eAAe;CACjB,CACF;AACF;AAEA,SAAgB,8BACd,QACA,OACA,SACU;CACV,OAAO,oBACL,YAAY,OAAO,GACnB,QACA,kBAAkB,+BAClB,EACE,OAAO,MACT,CACF;AACF;AAEA,SAAgB,eACd,QACA,WACA,SACM;CACN,oBAA0B,YAAY,OAAO,GAAG,QAAQ,kBAAkB,gBAAgB,EACxF,OAAO,UACT,CAAC;AACH;AAEA,SAAgB,aACd,QACA,WACA,UACA,SACQ;CACR,OAAO,oBAA4B,YAAY,OAAO,GAAG,QAAQ,kBAAkB,cAAc;EAC/F,OAAO;EACP,UAAU;CACZ,CAAC;AACH;;;ACvEA,MAAM,QAAe;CAAE,QAAQ;CAAM,SAAS,CAAC;AAAE;AAEjD,SAAS,SAAwB;CAC/B,IAAI,MA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