From 9c251dbd3fd82b5a02c287ab7e7bee2bc95bd28e Mon Sep 17 00:00:00 2001 From: haotianlong Date: Fri, 14 Mar 2025 17:45:53 +0800 Subject: [PATCH 1/2] feat: add cloud extend interfaces - added cloud ai related api - fix saas definitions for gateway --- types/wx/lib.wx.cloud.d.ts | 65 +++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/types/wx/lib.wx.cloud.d.ts b/types/wx/lib.wx.cloud.d.ts index 0eb620f..08465d8 100644 --- a/types/wx/lib.wx.cloud.d.ts +++ b/types/wx/lib.wx.cloud.d.ts @@ -137,6 +137,7 @@ interface WxCloud { ): Promise services: ICloud.CloudServices + extend: ICloud.ICloudExtendServices } declare namespace ICloud { @@ -218,7 +219,7 @@ declare namespace ICloud { refresh: (session: AsyncSession) => Promise } interface GatewayConstructOptions { - id: string + id?: string appid?: string domain?: string keepalive?: boolean @@ -234,6 +235,68 @@ declare namespace ICloud { } // === end === + // === API: extend === + interface ICloudExtendServices { + AI: ICloudAI + } + interface ICloudAI { + createModel: (modelName: string) => ICloudAIModel + bot: ICloudBot + } + interface ICloudAICallbackOptions { + onEvent?: (ev: ICloudAIEvent) => void + onText?: (text: string) => void + onFinish?: (text: string) => void + } + interface ICloudBot { + get: ({ botId: string }: any) => any + list: (data: any) => any + create: (data: any) => any + update: (data: any) => any + delete: (data: any) => any + getChatRecords: (data: any) => any + sendFeedback: (data: any) => any + getFeedBack: (data: any) => any + getRecommendQuestions: (options: ICloudAICallbackOptions & ICloudBotOptions) => Promise + sendMessage: (options: ICloudAICallbackOptions & ICloudBotOptions) => Promise + } + + interface ICloudBotOptions { data: any; botId: string; timeout?: number } + interface ICloudAIModel { + streamText: (opts: ICloudAIOptions & ICloudAICallbackOptions) => Promise + generateText: (opts: ICloudAIOptions & ICloudAICallbackOptions) => Promise + } + interface ICloudAIChatMessage { + role: 'user' | 'assistant' | string + content: string + } + interface ICloudAIChatModelInput { + model: string + messages: ICloudAIChatMessage[] + temperature?: number + top_p?: number + } + interface ICloudAIOptions{ + data: ICloudAIChatModelInput + } + interface ICloudAIEvent { + event: string + id: string + data: string + json?: any + } + interface AsyncIterator { + next(value?: any): Promise>; + return?(value?: any): Promise>; + throw?(e?: any): Promise>; + } + interface ICloudAIStreamResult { + textStream: AsyncIterator + eventStream: AsyncIterator + abort?: () => void + } + // === end === + // === API: uploadFile === interface UploadFileResult extends IAPISuccessParam { fileID: string From 53deacffe4482087be19eedd4216c2745a7cfdc0 Mon Sep 17 00:00:00 2001 From: haotianlong Date: Fri, 14 Mar 2025 17:54:51 +0800 Subject: [PATCH 2/2] fix(cloud): async iterators ... with eslint --- types/wx/lib.wx.cloud.d.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/types/wx/lib.wx.cloud.d.ts b/types/wx/lib.wx.cloud.d.ts index 08465d8..d452f05 100644 --- a/types/wx/lib.wx.cloud.d.ts +++ b/types/wx/lib.wx.cloud.d.ts @@ -20,6 +20,8 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ***************************************************************************** */ +/// + /** * Common interfaces and types */ @@ -261,7 +263,7 @@ declare namespace ICloud { sendMessage: (options: ICloudAICallbackOptions & ICloudBotOptions) => Promise } - interface ICloudBotOptions { data: any; botId: string; timeout?: number } + interface ICloudBotOptions { data: any, botId: string, timeout?: number } interface ICloudAIModel { streamText: (opts: ICloudAIOptions & ICloudAICallbackOptions) => Promise generateText: (opts: ICloudAIOptions & ICloudAICallbackOptions) => Promise @@ -285,10 +287,12 @@ declare namespace ICloud { data: string json?: any } + interface AsyncIterator { - next(value?: any): Promise>; - return?(value?: any): Promise>; - throw?(e?: any): Promise>; + next(value?: any): Promise> + return?(value?: any): Promise> + throw?(e?: any): Promise> + [Symbol.asyncIterator](): AsyncIterableIterator } interface ICloudAIStreamResult { textStream: AsyncIterator