@cloudbase/js-sdk 4.0.0 → 4.0.1-alpha.1

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.
Files changed (203) hide show
  1. package/CHANGELOG.md +398 -0
  2. package/ai/dist/index.esm.js +2 -3
  3. package/ai/dist/index.esm.js.map +1 -0
  4. package/ai/dist/index.js +2 -21
  5. package/ai/dist/index.js.map +1 -0
  6. package/apis/dist/index.d.ts +1 -0
  7. package/apis/dist/index.esm.js +2 -0
  8. package/apis/dist/index.esm.js.map +1 -0
  9. package/apis/dist/index.js +2 -0
  10. package/apis/dist/index.js.map +1 -0
  11. package/{analytics → apis}/package.json +1 -1
  12. package/app/dist/index.esm.js +2 -11
  13. package/app/dist/index.esm.js.map +1 -0
  14. package/app/dist/index.js +2 -18
  15. package/app/dist/index.js.map +1 -0
  16. package/app/dist/index.node.esm.js +3 -0
  17. package/app/dist/index.node.esm.js.LICENSE.txt +13 -0
  18. package/app/dist/index.node.esm.js.map +1 -0
  19. package/app/dist/index.node.js +3 -0
  20. package/app/dist/index.node.js.LICENSE.txt +13 -0
  21. package/app/dist/index.node.js.map +1 -0
  22. package/app/package.json +12 -1
  23. package/auth/dist/index.d.ts +2 -2
  24. package/auth/dist/index.esm.js +3 -4
  25. package/auth/dist/index.esm.js.LICENSE.txt +12 -0
  26. package/auth/dist/index.esm.js.map +1 -0
  27. package/auth/dist/index.js +3 -9
  28. package/auth/dist/index.js.LICENSE.txt +12 -0
  29. package/auth/dist/index.js.map +1 -0
  30. package/cloudrun/dist/index.esm.js +2 -3
  31. package/cloudrun/dist/index.esm.js.map +1 -0
  32. package/cloudrun/dist/index.js +2 -21
  33. package/cloudrun/dist/index.js.map +1 -0
  34. package/container/dist/index.d.ts +2 -2
  35. package/container/dist/index.esm.js +2 -4
  36. package/container/dist/index.esm.js.map +1 -0
  37. package/container/dist/index.js +2 -9
  38. package/container/dist/index.js.map +1 -0
  39. package/core.d.ts +4331 -0
  40. package/core.node.d.ts +294 -0
  41. package/database/dist/index.esm.js +2 -47
  42. package/database/dist/index.esm.js.map +1 -0
  43. package/database/dist/index.js +2 -53
  44. package/database/dist/index.js.map +1 -0
  45. package/database/package.json +34 -4
  46. package/dist/index.cjs.js +3 -37
  47. package/dist/index.cjs.js.LICENSE.txt +12 -0
  48. package/dist/index.cjs.js.map +1 -0
  49. package/dist/index.esm.js +3 -32
  50. package/dist/index.esm.js.LICENSE.txt +12 -0
  51. package/dist/index.esm.js.map +1 -0
  52. package/dist/index.node.cjs.js +3 -0
  53. package/dist/index.node.cjs.js.LICENSE.txt +26 -0
  54. package/dist/index.node.cjs.js.map +1 -0
  55. package/dist/index.node.esm.js +3 -0
  56. package/dist/index.node.esm.js.LICENSE.txt +26 -0
  57. package/dist/index.node.esm.js.map +1 -0
  58. package/functions/dist/index.d.ts +2 -2
  59. package/functions/dist/index.esm.js +2 -4
  60. package/functions/dist/index.esm.js.map +1 -0
  61. package/functions/dist/index.js +2 -9
  62. package/functions/dist/index.js.map +1 -0
  63. package/index.d.ts +7 -1785
  64. package/index.node.d.ts +13 -0
  65. package/miniprogram_dist/ai/index.d.ts +42 -0
  66. package/miniprogram_dist/ai/index.js +2 -0
  67. package/miniprogram_dist/apis/index.d.ts +5 -0
  68. package/miniprogram_dist/apis/index.js +1 -0
  69. package/miniprogram_dist/app/index.d.ts +67 -0
  70. package/miniprogram_dist/app/index.js +2 -0
  71. package/miniprogram_dist/auth/index.d.ts +269 -0
  72. package/miniprogram_dist/auth/index.js +2 -0
  73. package/miniprogram_dist/cloudrun/index.d.ts +4 -0
  74. package/miniprogram_dist/cloudrun/index.js +1 -0
  75. package/miniprogram_dist/container/index.d.ts +13 -0
  76. package/miniprogram_dist/container/index.js +1 -0
  77. package/miniprogram_dist/database/index.d.ts +3 -0
  78. package/miniprogram_dist/database/index.js +1 -0
  79. package/miniprogram_dist/functions/index.d.ts +2 -0
  80. package/miniprogram_dist/functions/index.js +1 -0
  81. package/miniprogram_dist/index.js +1 -1
  82. package/miniprogram_dist/model/index.d.ts +5 -0
  83. package/miniprogram_dist/model/index.js +1 -0
  84. package/miniprogram_dist/mysql/index.d.ts +3 -0
  85. package/miniprogram_dist/mysql/index.js +1 -0
  86. package/miniprogram_dist/oauth/index.d.ts +22 -0
  87. package/miniprogram_dist/oauth/index.js +2 -0
  88. package/miniprogram_dist/realtime/index.d.ts +2 -0
  89. package/miniprogram_dist/realtime/index.js +1 -0
  90. package/miniprogram_dist/storage/index.d.ts +13 -0
  91. package/miniprogram_dist/storage/index.js +1 -0
  92. package/model/dist/index.esm.js +2 -3
  93. package/model/dist/index.esm.js.map +1 -0
  94. package/model/dist/index.js +2 -21
  95. package/model/dist/index.js.map +1 -0
  96. package/mysql/dist/index.d.ts +1 -0
  97. package/mysql/dist/index.esm.js +2 -0
  98. package/mysql/dist/index.esm.js.map +1 -0
  99. package/mysql/dist/index.js +2 -0
  100. package/mysql/dist/index.js.map +1 -0
  101. package/mysql/package.json +6 -0
  102. package/oauth/dist/index.esm.js +3 -3
  103. package/oauth/dist/index.esm.js.LICENSE.txt +12 -0
  104. package/oauth/dist/index.esm.js.map +1 -0
  105. package/oauth/dist/index.js +3 -21
  106. package/oauth/dist/index.js.LICENSE.txt +12 -0
  107. package/oauth/dist/index.js.map +1 -0
  108. package/package.json +144 -18
  109. package/realtime/dist/index.d.ts +2 -2
  110. package/realtime/dist/index.esm.js +2 -4
  111. package/realtime/dist/index.esm.js.map +1 -0
  112. package/realtime/dist/index.js +2 -9
  113. package/realtime/dist/index.js.map +1 -0
  114. package/storage/dist/index.d.ts +2 -2
  115. package/storage/dist/index.esm.js +2 -4
  116. package/storage/dist/index.esm.js.map +1 -0
  117. package/storage/dist/index.js +2 -9
  118. package/storage/dist/index.js.map +1 -0
  119. package/types/analytics.d.ts +51 -0
  120. package/types/auth.d.ts +166 -0
  121. package/types/cache.d.ts +26 -0
  122. package/types/cloudrun.d.ts +9 -0
  123. package/types/component.d.ts +17 -0
  124. package/types/container.d.ts +93 -0
  125. package/types/database.d.ts +31 -0
  126. package/types/error.d.ts +40 -0
  127. package/types/events.d.ts +13 -0
  128. package/types/functions.d.ts +49 -0
  129. package/types/index.d.ts +269 -0
  130. package/types/package.json +47 -0
  131. package/types/realtime.d.ts +350 -0
  132. package/types/request.d.ts +30 -0
  133. package/types/result.d.ts +48 -0
  134. package/types/storage.d.ts +144 -0
  135. package/utilities/dist/cjs/adapters/index.d.ts +45 -0
  136. package/utilities/dist/cjs/adapters/index.js +68 -0
  137. package/utilities/dist/cjs/adapters/platforms/web.d.ts +20 -0
  138. package/utilities/dist/cjs/adapters/platforms/web.js +286 -0
  139. package/utilities/dist/cjs/constants/common.d.ts +6 -0
  140. package/utilities/dist/cjs/constants/common.js +24 -0
  141. package/utilities/dist/cjs/constants/errors.d.ts +8 -0
  142. package/utilities/dist/cjs/constants/errors.js +12 -0
  143. package/utilities/dist/cjs/constants/index.d.ts +3 -0
  144. package/utilities/dist/cjs/constants/index.js +21 -0
  145. package/utilities/dist/cjs/helpers/decorators.d.ts +11 -0
  146. package/utilities/dist/cjs/helpers/decorators.js +238 -0
  147. package/utilities/dist/cjs/helpers/index.d.ts +1 -0
  148. package/utilities/dist/cjs/helpers/index.js +18 -0
  149. package/utilities/dist/cjs/index.d.ts +13 -0
  150. package/utilities/dist/cjs/index.js +51 -0
  151. package/utilities/dist/cjs/libs/abortController.d.ts +9 -0
  152. package/utilities/dist/cjs/libs/abortController.js +25 -0
  153. package/utilities/dist/cjs/libs/cache.d.ts +17 -0
  154. package/utilities/dist/cjs/libs/cache.js +261 -0
  155. package/utilities/dist/cjs/libs/events.d.ts +27 -0
  156. package/utilities/dist/cjs/libs/events.js +108 -0
  157. package/utilities/dist/cjs/libs/langEvent.d.ts +3 -0
  158. package/utilities/dist/cjs/libs/langEvent.js +7 -0
  159. package/utilities/dist/cjs/libs/util.d.ts +49 -0
  160. package/utilities/dist/cjs/libs/util.js +282 -0
  161. package/utilities/dist/esm/adapters/index.d.ts +45 -0
  162. package/utilities/dist/esm/adapters/index.js +40 -0
  163. package/utilities/dist/esm/adapters/platforms/web.d.ts +20 -0
  164. package/utilities/dist/esm/adapters/platforms/web.js +282 -0
  165. package/utilities/dist/esm/constants/common.d.ts +6 -0
  166. package/utilities/dist/esm/constants/common.js +17 -0
  167. package/utilities/dist/esm/constants/errors.d.ts +8 -0
  168. package/utilities/dist/esm/constants/errors.js +9 -0
  169. package/utilities/dist/esm/constants/index.d.ts +3 -0
  170. package/utilities/dist/esm/constants/index.js +4 -0
  171. package/utilities/dist/esm/helpers/decorators.d.ts +11 -0
  172. package/utilities/dist/esm/helpers/decorators.js +234 -0
  173. package/utilities/dist/esm/helpers/index.d.ts +1 -0
  174. package/utilities/dist/esm/helpers/index.js +2 -0
  175. package/utilities/dist/esm/index.d.ts +13 -0
  176. package/utilities/dist/esm/index.js +14 -0
  177. package/utilities/dist/esm/libs/abortController.d.ts +9 -0
  178. package/utilities/dist/esm/libs/abortController.js +23 -0
  179. package/utilities/dist/esm/libs/cache.d.ts +17 -0
  180. package/utilities/dist/esm/libs/cache.js +258 -0
  181. package/utilities/dist/esm/libs/events.d.ts +27 -0
  182. package/utilities/dist/esm/libs/events.js +102 -0
  183. package/utilities/dist/esm/libs/langEvent.d.ts +3 -0
  184. package/utilities/dist/esm/libs/langEvent.js +4 -0
  185. package/utilities/dist/esm/libs/util.d.ts +49 -0
  186. package/utilities/dist/esm/libs/util.js +254 -0
  187. package/utilities/dist/miniprogram/index.js +1 -0
  188. package/utilities/package.json +26 -0
  189. package/analytics/dist/index.d.ts +0 -2
  190. package/analytics/dist/index.esm.js +0 -4
  191. package/analytics/dist/index.js +0 -9
  192. package/miniprogram_dist/ai.js +0 -2
  193. package/miniprogram_dist/analytics.js +0 -1
  194. package/miniprogram_dist/app.js +0 -2
  195. package/miniprogram_dist/auth.js +0 -2
  196. package/miniprogram_dist/cloudrun.js +0 -1
  197. package/miniprogram_dist/container.js +0 -1
  198. package/miniprogram_dist/database.js +0 -2
  199. package/miniprogram_dist/functions.js +0 -1
  200. package/miniprogram_dist/model.js +0 -1
  201. package/miniprogram_dist/oauth.js +0 -1
  202. package/miniprogram_dist/realtime.js +0 -1
  203. package/miniprogram_dist/storage.js +0 -1
package/CHANGELOG.md ADDED
@@ -0,0 +1,398 @@
1
+ # Change Log
2
+
3
+ All notable changes to this project will be documented in this file.
4
+ See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
+
6
+ # [4.0.0](https://github.com/TencentCloudBase/cloudbase-js-sdk/compare/v3.3.13...v4.0.0) (2026-07-27)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * bug ([d7c8936](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/d7c8936f7210b04e00d002d7dcb6203a615bd677))
12
+ * **cloudbase:** 修复 Node 构建 process.env 被整体替换的问题 ([0f4c22d](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/0f4c22d897d30e61d7fe177d2a6fc286ec5ce6f5))
13
+ * database get doc ([89d8aea](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/89d8aea56e0bead80941c890b859dadebcc27bbe))
14
+ * node credentials ([3a0a4ac](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/3a0a4ac7e84536b847120bf7e78030cbd990fd0b))
15
+ * **storage:** 对象名 URL 编码并修正类型/文档/忽略产物 ([526d6ac](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/526d6ac4d5d19eacafe319369f87ad861d3794ba))
16
+ * **storage:** 避免 FileBody 强依赖 @types/node ([fef33a3](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/fef33a3fed7cd6fdceea3d5f1c2b3005773b9e01))
17
+ * 修复 bundledDependencies 子包版本号导致 yarn install 时从 registry 查找失败的问题 ([1fbeb6a](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/1fbeb6aa6f569e2cd5cac98ad01170b0c920d7ea))
18
+ * 修复 Node.js 环境下调用 downloadFile 报 的问题 ([c5d1b14](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/c5d1b144646daffecc71ec1686ee018583148f1c))
19
+
20
+
21
+ * refactor(storage)!: require bucketId in app.storage.from(), drop classic from() ([eeb9f17](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/eeb9f17f45001c68d10f00c825b580e68da2e8b0))
22
+
23
+
24
+ ### Features
25
+
26
+ * add bson dependencies ([26cfce5](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/26cfce579d33b532e9f0bdeb360f0b3d7f2f35bd))
27
+ * add registerHost ([f738301](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/f738301b73563deb5ab6f5bfbb7c42ee8fe3d1fc))
28
+ * **storage:** 下载支持 blob/stream 两种终态,对齐 supabase ([b7b610d](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/b7b610ddc5ac798396dc1ebe4395a7c9c73f913c))
29
+ * **storage:** 实现 setHeader 支持实例级自定义请求头 ([a325759](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/a32575945b0f23568e100dee8dcc9ea731319e09))
30
+ * **storage:** 对齐 supabase 参数名与 options,移除多余字段 ([e329c7a](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/e329c7a36cdc4eaa2947afe46bb0f4d2a63c8380))
31
+ * **storage:** 新增 Postgres-Native 原生 Storage 客户端并对齐 Supabase 签名 ([470e4ca](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/470e4ca3d36448708fd46eb017fcbcf00fbd8f7e))
32
+ * type define ([0566e48](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/0566e489fb864cae3c2f027f05fd81514072302a))
33
+ * update ([384d164](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/384d1641d22faa4617a5a0a4bce25fca91cfa8b5))
34
+ * update auth api ([f371507](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/f37150767903aa8bc4bf0d4d09648f4e56761155))
35
+ * update miniprograme build ([53eb626](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/53eb6265c49098f0fe3ed1040e3550ad5e08fc31))
36
+ * update node adapter ([66bd3e0](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/66bd3e00233592179d4fbc6a99ca7e1213ad005a))
37
+ * update node polyfill ([451c910](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/451c910cc64da8b900393362824e1c4d052f9f04))
38
+ * update node session ([b8673c7](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/b8673c7aa7c096129714f9e20856b1308053b469))
39
+ * update node timeout & update user params ([9f1fb3e](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/9f1fb3ef648007f54738d775a077bad9d5143f1c))
40
+ * update pacakge bundle ([76df203](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/76df2034bcd2f3c28a5dc72a007f037f9fb3e9d8))
41
+ * update pacakge json ([ff160bc](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/ff160bc211690b4cae9afdd655eae3647a42e7f2))
42
+ * update package ([fcbf467](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/fcbf467dc18cb4987ec7261e9346c6c52e7ef080))
43
+ * update readme ([5a3853b](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/5a3853ba843afb0d13f39a1ee89c77fc15e3d1a2))
44
+ * update sub path ([dd559ee](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/dd559eeefcabf22158c995b3edd020479db59bea))
45
+ * update version ([1e4472a](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/1e4472ac302a7d2ffca2d4968e2df5932d4c99ef))
46
+ * 修复 Node 服务端 fetch ([fbc317c](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/fbc317cb93016258e5ffc4ff771c91aea8722e07))
47
+ * 修复getUser 和 getSession 在无凭证或 accessKey 模式下返回 user 统一返回 null ([9df43f1](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/9df43f12924c2f5704ba9ff0277220f4c033a0ea))
48
+ * 服务端 body 为 stream 时设置 duplex: 'half' ([f1799e6](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/f1799e6119a261dc65cb2b913401f48b3acc99d3))
49
+
50
+
51
+ ### Reverts
52
+
53
+ * **storage:** 恢复 ClassicStorageFileApi 及 from() 分流引用 ([8b59f1e](https://github.com/TencentCloudBase/cloudbase-js-sdk/commit/8b59f1e95ded91461922d875aa30df1b96a48465))
54
+
55
+
56
+ ### BREAKING CHANGES
57
+
58
+ * app.storage.from() 不再支持无参调用,必须传入 bucketId。
59
+
60
+
61
+
62
+
63
+
64
+ # 更新日志
65
+
66
+ ## [3.6.4] 2026-07-24
67
+ - [Fixed] 自定义登录场景下用户通过 `init({ env, auth: { credentials } })` 传入的私钥无法被 `createTicket` 读取的问题:`getSecretInfo()` 此前仅从顶层 `config.credentials` 读取,现同时兼容 `config.auth.credentials`(js-sdk 风格)与顶层 `credentials`(node-sdk 风格)两种传法
68
+ - [Fixed] `dealNodeAdapterConfig()` 回填 `config.auth.credentials` 时会被空值覆盖的问题,改为保留用户显式传入的 `credentials`;并修正其兜底值类型(`ICredentialsInfo` 对象,无有效值时为 `undefined`,不再用空字符串)
69
+
70
+ ## [3.6.3] 2026-07-17
71
+ - [Changed] `timeout` 默认值区分运行环境:Node.js 环境(云函数/云托管/自建服务器)默认不设置超时(不限制),以适配服务端长耗时请求;Web 等非 Node.js 环境仍默认 15000ms。显式传入 `timeout` 时以传入值为准
72
+ - [Changed] `NodeRequest` 未设置 `timeout` 时不再施加超时中断(`download` 及 `createAbortController` 均按需启用超时),仅在显式传入 `timeout` 时启用
73
+ - [Changed] Auth `updateUser` 不再支持修改密码:传入 `password` / `new_password` 参数将抛出错误,请改用 `resetPasswordForOld`(旧密码修改)、`resetPasswordForEmail`(验证码重置)或 `reauthenticate`(重新认证后改密)
74
+ - [Changed] `UpdateUserReq` 类型从基础请求中剔除 `password` / `new_password` 字段(标记为 `never`)
75
+
76
+ ## [3.6.2] 2026-06-29
77
+ - [Fixed] `getSecretInfo()` 中顶层 secretId/secretKey 场景下 `sessionToken` 错误地从环境变量 `TENCENTCLOUD_SESSIONTOKEN` 取值,修正为从 config 顶层 `sessionToken` 字段取值
78
+ - [Fixed] `getSecretInfo()` 中 `config.auth` 场景下 `sessionToken` 错误地从环境变量取值,修正为从 `config.auth.sessionToken` 取值
79
+ - [Fixed] `NodeRequest` V3 签名时 `secretId`/`secretKey`/`sessionToken` 取值逻辑修正为同时支持顶层配置和 `config.auth` 配置(`config.auth` 优先级更高)
80
+
81
+ ## [3.6.1] 2026-06-29
82
+ - [Fixed] AI 模块:优先使用原生 Web Streams API(Node.js >= 18 / 现代浏览器),避免 `web-streams-polyfill` 在高版本环境中的兼容问题
83
+ - [Fixed] 浏览器端 webpack 构建增加 `resolve.fallback: { crypto: false }`,避免引入 Node.js `crypto` 模块的 polyfill
84
+ - [Changed] `@cloudbase/database` 依赖 `bson` 版本从 `^7.1.1` 降级为 `^6.10.3`
85
+ - [Changed] `@cloudbase/mysql` 及 `database` 的 `typescript` devDependency 升级至 `^5.0.0`
86
+ - [Changed] `@cloudbase/mysql` tsconfig.esm.json 补充 `moduleResolution: "node"`
87
+
88
+ ## [3.6.0] 2026-06-29
89
+ - [Fixed] 修复 Node 端构建时 `webpack.DefinePlugin` 将 `process.env` 整体替换为静态对象,导致运行时无法读取 `TENCENTCLOUD_SECRETID`、`TENCENTCLOUD_SECRETKEY`、`SCF_NAMESPACE` 等环境变量的问题
90
+ - [Fixed] `getSecretInfo()` 改为从 `getCloudbaseContext()` 统一取值(而非直接 `getEnv()`),确保 context 中的环境变量优先级正确
91
+ - [Fixed] `getCloudbaseContext()` 新增 `CLOUDBASE_APIKEY` 环境变量的采集
92
+ - [Fixed] AI 模块:Node.js 适配器非流式场景下 `responseData` 已是 JSON 对象时,跳过 ReadableStream 解析直接返回结果
93
+
94
+ ## [3.5.4] 2026-06-25
95
+ - [Fixed] 修复 Node.js ESM 环境下初始化时 `getWxDefaultAdapter` 返回空对象导致 `useAdapters` 调用 `isMatch()` 报 `TypeError: i is not a function` 的问题
96
+ - [Fixed] 修复 GATEWAY 模式下文档型数据库集合查询时,后端返回数据缺少 `list` 字段导致 `formatResDocumentData` 报 `TypeError: Cannot read properties of undefined (reading 'map')` 的问题
97
+
98
+ ## [3.5.3] 2026-06-25
99
+ - [Added] App 实例新增 `registerHost(host, protocol?)` 方法,一次性设置所有端点(CLOUD_API / GATEWAY),只需传入 host 地址自动拼接路径
100
+ - [Added] `cloudbase.app.App` 类型声明补充 `registerHost`、`getEndPointWithKey`、`registerEndPoint`、`registerEndPointWithKey`、`parseCaptcha` 实例方法
101
+ - [Added] `ai(options?)` 支持传入 `baseUrl` 参数自定义 AI 服务地址
102
+ - [Fixed] AI 模块支持 `registerEndPointWithKey` 后端点动态变更自动生效(`aiBaseUrl` / `aiBotBaseUrl` 改为动态 getter)
103
+ - [Fixed] MySQL/RDB 模块支持端点动态变更,`registerEndPointWithKey` 后新请求自动使用最新 GATEWAY 地址
104
+ - [Fixed] Auth/OAuth 模块支持端点动态变更,`registerEndPointWithKey` 后认证请求自动跟随最新 apiOrigin
105
+
106
+ ## [3.5.2] 2026-06-24
107
+ - [Fixed] 修复 Node 服务端(secretId/secretKey 认证)场景下,`CloudbaseRequest.fetch` 因无 `oauthInstance` 导致请求失败的问题,使 RDB 等模块能正确通过底层 `NodeRequest` 的 V3 签名自动换取 access_token
108
+
109
+ ## [3.5.1] 2026-06-23
110
+ - [Added] Auth 模块新增 `AuthErrorCode` 数字错误码枚举及 `AuthError.errorCode`、`retryAfter` 属性
111
+ - [Added] `AuthErrorCategory` 新增 `RATE_LIMITED`、`CAPTCHA_REQUIRED`、`CAPTCHA_INVALID`、`MFA_REQUIRED`、`PRECONDITION_FAILED`、`VERIFICATION_FAILED` 分类
112
+ - [Fixed] Auth `updateUser` 中 `verifyOtp` 校验失败时正确返回错误;仅在实际修改时触发 `USER_UPDATED` 事件
113
+ - [Fixed] 验证码发送补充 `target: 'USER'` 参数;修复 abort 监听器泄漏、容错解析非 JSON 响应体
114
+
115
+ ## [3.5.0] 2026-06-23
116
+ - [Added] Storage 模块新增 Neo 环境对象存储能力,`app.storage.from(bucketId)` 返回全新对象存储客户端(上传/下载/删除/移动/复制/签名 URL 等)
117
+ - [Added] `app.storage` 新增 Bucket 管理 API:`listBuckets` / `getBucket` / `createBucket` / `updateBucket` / `deleteBucket`
118
+ - [Changed] `app.storage.from()` 无参仍返回 `ClassicStorageFileApi`(行为不变);传入 `bucketId` 返回 Neo 对象存储客户端
119
+ - [Deprecated] 传统顶层云存储 API(`uploadFile` / `downloadFile` / `deleteFile` 等)标记为废弃,推荐改用 `app.storage.from(bucketId)` 新 API
120
+
121
+ ## [3.4.8] 2026-06-16
122
+ - [Fixed] 修复 `getUser` 和 `getSession` 在无凭证或 `accessKey` 模式下返回 `user` 统一返回 `null`
123
+
124
+ ## [3.4.7] 2026-06-16
125
+ - [Fixed] Auth 模块 `verifyOtp` 的 `token` 参数兼容 `number` 和 `string` 类型
126
+
127
+ ## [3.4.6] 2026-06-12
128
+ - [Refactor] 重构 Node.js adapter 层,整合微信云开发相关请求逻辑(callWxOpenApi / callWxPayApi / callCompatibleWxOpenApi / wxCallContainerApi)
129
+ - [Fixed] 修复微信云开发 form-data 请求返回值格式与旧版不一致的问题,正确返回 Buffer 类型响应
130
+ - [Changed] request 模块新增 responseType: 'buffer' 支持,兼容二进制响应场景
131
+
132
+ ## [3.4.5] 2026-06-10
133
+ - [Fixed] 服务端 body 为 stream 时设置 duplex: 'half'
134
+
135
+ ## [3.4.4] 2026-06-10
136
+ - [Fixed] 服务端增加 `bson` 依赖
137
+
138
+ ## [3.4.3] 2026-06-10
139
+ - [Fixed] 修复 Node.js 环境下调用 downloadFile 报 `window is not defined` 的问题
140
+
141
+ ## [3.4.2] 2026-06-10
142
+ - [Fixed] 修复 bundledDependencies 子包版本号导致 yarn install 时从 registry 查找失败的问题
143
+
144
+ ## [3.4.1] 2026-06-10
145
+ - [Fixed] 修复 database 模块文档查询相关问题
146
+
147
+ ## [3.4.0] 2026-06-09
148
+ - [Changed] 移除 analytics 模块,不再随主包发布
149
+ - [Changed] 子模块随主包一起发布,不再单独进行模块独立版本更新
150
+ - [Added] 支持 sub-path exports 按需引入(如 `@cloudbase/js-sdk/auth`)
151
+
152
+ ## [3.3.13] 2026-05-29
153
+ - [Fixed] 修复云函数相关问题
154
+
155
+ ## [3.3.12] 2026-05-28
156
+ - [Fixed] 适配 v1/user/me 接口返回字段变化,hasPassword 改用 password === 'SET' 判断
157
+
158
+ ## [3.3.11] 2026-05-26
159
+ - [Fixed] 修复 _getCredentials 中 credentials 为空时访问 scope 属性报错的问题
160
+
161
+ ## [3.3.10] 2026-05-19
162
+ - [Changed] fetch 请求支持 withCredentials 参数控制是否携带鉴权信息
163
+
164
+ ## [3.3.9] 2026-05-08
165
+ - [Changed] endPointMode 默认值更新为 GATEWAY
166
+
167
+ ## [3.3.8] 2026-05-07
168
+ - [Added] getUser 支持从 providers 中匹配当前小程序 appId 对应的 open_id
169
+
170
+ ## [3.3.7] 2026-05-06
171
+ - [Fixed] getUser 返回用户信息支持 open_id 字段
172
+
173
+ ## [3.3.6] 2026-04-30
174
+ - [Added] 文档型数据库支持批量新增数据
175
+
176
+ ## [3.3.5] 2026-04-29
177
+ - [Added] 添加类型定义
178
+
179
+ ## [3.3.4] 2026-04-21
180
+ - [Added] database where条件支持事务
181
+
182
+ ## [3.3.3] 2026-04-17
183
+ - [Fixed] signUp 修复 phone_number 为空时格式化报错的问题
184
+
185
+ ## [3.3.2] 2026-04-13
186
+ - [Changed] getUser/getCurrentUser 支持 isRefresh 参数控制是否发请求获取最新用户信息,默认每次请求最新数据
187
+
188
+ ## [3.3.1] 2026-04-13
189
+ - [Added] getUser 支持读缓存和读接口数据可选
190
+
191
+ ## [3.3.0] 2026-04-08
192
+ - [Added] database 支持 http api
193
+
194
+ ## [3.2.2] 2026-04-02
195
+ - [Added] signInWithOtp 支持 emailRedirectTo
196
+
197
+ ## [3.2.1] 2026-03-24
198
+ - [Added] 增加帮助信息
199
+
200
+ ## [3.2.0] 2026-03-23
201
+ - [Added] 小程序手机号授权支持服务商类型小程序
202
+
203
+ ## [3.1.12] 2026-03-16
204
+ - [Fixed] node 模式下请求参数增加 envName
205
+
206
+ ## [3.1.11] 2026-03-16
207
+ - [Fixed] node 模式下 v3 签名兼容 headers 为空场景
208
+
209
+ ## [3.1.9] 2026-03-13
210
+ - [Added] 增强类型声明以及错误提示
211
+
212
+ ## [3.1.8] 2026-03-12
213
+ - [Fixed] 增加 storage 类型定义
214
+
215
+ ## [3.1.7] 2026-03-12
216
+ - [Fixed] getVerification 增加 phone_number 参数格式化
217
+
218
+ ## [3.1.6] 2026-03-12
219
+ - [Added] signInWithOtp 增加可选参数 options.shouldCreateUser 控制是否自动注册用户
220
+
221
+ ## [3.1.5] 2026-03-11
222
+ - [Changed] 完善 database 类型定义
223
+ - [Added] 异常时增加 requestId 返回
224
+
225
+ ## [3.1.4] 2026-03-11
226
+ - [Fixed] verifyOAuth 返回预设重定向地址
227
+
228
+ ## [3.1.3] 2026-03-10
229
+ - [Fixed] verifyOAuth 兼容 hash 地址
230
+
231
+ ## [3.1.2] 2026-03-06
232
+ - [Fixed] 修复 HBuilderX 找不到 SourceMap 问题
233
+
234
+ ## [3.1.1] 2026-03-03
235
+ - [Changed] 更新微信小程序端adapter
236
+
237
+ ## [3.1.0] 2026-03-03
238
+ - [Fixed] 兼容多端
239
+
240
+ ## [3.0.6] 2026-03-03
241
+ - [Fixed] 修复 Node.js 端签名问题
242
+
243
+ ## [3.0.5] 2026-03-01
244
+ - [Added] Node.js 端支持 SecretId 和 SecretKey
245
+
246
+ ## [3.0.4] 2026-02-27
247
+ - [Added] 支持 Node.js 端
248
+
249
+ ## [3.0.3] 2026-02-26
250
+ - [Fixed] 修复用户信息nickName获取问题
251
+
252
+ ## [3.0.2] 2026-02-12
253
+ - [Fixed] 修复用户信息role获取问题
254
+
255
+ ## [3.0.0] 2026-02-10
256
+ - [Changed] endPointMode 默认启用 GATEWAY 模式
257
+
258
+ ## [2.28.4] 2026-05-06
259
+ - [Fixed] getUser 返回用户信息支持 open_id 字段
260
+
261
+ ## [2.28.3] 2026-04-30
262
+ - [Added] 文档型数据库支持批量新增数据
263
+
264
+ ## [2.28.2] 2026-04-29
265
+ - [Added] 类型定义
266
+
267
+ ## [2.28.1] 2026-04-23
268
+ - [Added] 海外支持
269
+
270
+ ## [2.27.5] 2026-04-21
271
+ - [Added] database where条件支持事务
272
+
273
+ ## [2.27.4] 2026-04-17
274
+ - [Fixed] signUp 修复 phone_number 为空时格式化报错的问题
275
+
276
+ ## [2.27.3] 2026-04-13
277
+ - [Added] getUser 支持读缓存和读接口数据可选
278
+
279
+ ## [2.27.2] 2026-04-02
280
+ - [Added] signInWithOtp 支持 emailRedirectTo
281
+
282
+ ## [2.27.1] 2026-03-24
283
+ - [Added] 增加帮助信息
284
+
285
+ ## [2.27.0] 2026-03-23
286
+ - [Added] 小程序手机号授权支持服务商类型小程序
287
+
288
+ ## [2.26.2] 2026-03-13
289
+ - [Added] 增强类型声明以及错误提示
290
+
291
+ ## [2.26.1] 2026-03-12
292
+ - [Fixed] getVerification 增加 phone_number 参数格式化
293
+
294
+ ## [2.26.0] 2026-03-12
295
+ - [Added] signInWithOtp 增加可选参数 options.shouldCreateUser 控制是否自动注册用户
296
+
297
+ ## [2.25.11] 2026-03-11
298
+ - [Fixed] verifyOAuth 返回预设重定向地址
299
+
300
+ ## [2.25.10] 2026-03-10
301
+ - [Fixed] verifyOAuth 兼容 hash 地址
302
+
303
+ ## [2.25.9] 2026-03-06
304
+ - [Fixed] 修复 HBuilderX 找不到 SourceMap 问题
305
+
306
+ ## [2.25.8] 2026-03-03
307
+ - [Changed] 更新微信小程序端adapter
308
+
309
+ ## [2.25.5] 2026-02-04
310
+ - [Fixed] 修复用户信息role获取问题
311
+
312
+ ## [2.25.4] 2026-02-04
313
+ - [Added] encryptlong 兼容多端
314
+
315
+ ## [2.25.3] 2026-01-28
316
+ - [Fixed] GET/HEAD 请求时,将请求体设置为空
317
+ - [Fixed] auth\.wsWebSign action 一直走 tcb api 请求
318
+
319
+ ## [2.25.2] 2026-01-26
320
+ - [Added] 新版本 auth api 上线
321
+
322
+ ## [2.25.1] 2026-01-22
323
+ - [Added] 更新 database 依赖版本
324
+
325
+ ## [2.25.0] 2026-01-22
326
+ - [Changed] 构建 CI 发布、Node.js 版本升级至 22、代码优化
327
+
328
+ ## [2.24.10] 2026‑01‑14
329
+ - [Changed] 更新 getDeviceInfo 和错误处理
330
+
331
+ ## [2.24.9] 2026‑01‑13
332
+ - [Changed] 更新数据库依赖至 0.10.0、多认证支持、清理构建文件
333
+
334
+ ## [2.24.8] 2026‑01‑12
335
+ - [Added] 添加混元 AR 图像模型支持
336
+
337
+ ## [2.24.7 及更早版本] 2025-12-29 至 2026-01-12
338
+ - 略
339
+
340
+ ## [1.4.1] 2021-03-08
341
+ - [Fixed] 修复上传文件进度获取异常 bug
342
+
343
+ ## [1.4.0] 2020-12-16
344
+ - [Added] 新增 analytics 接口
345
+
346
+ ## [1.3.3] 2020-09-25
347
+ - [Changed] 优化 TypeScript 语法提示
348
+ - [Fixed] 修复未登录调用数据库报错问题
349
+
350
+ ## [1.3.2] 2020-09-24
351
+ - [Fixed] 微信小程序插件环境获取 appSign 取插件 AppId
352
+ - [Fixed] storage 满仓情况下写入抛出错误
353
+
354
+ ## [1.3.1] 2020-09-23
355
+ - [Fixed] 兼容微信小程序插件环境
356
+
357
+ ## [1.3.0] 2020-09-11
358
+ - [Changed] 数据库实时推送功能抽离为独立的模块
359
+
360
+ ## [1.2.5] 2020-09-07
361
+ - [Fixed] 修复微信小程序真机环境报错
362
+
363
+ ## [1.2.3] 2020-09-03
364
+ - [Changed] 优化 API 语法提示
365
+
366
+ ## [1.2.2] 2020-09-01
367
+ - [Changed] 优化开发环境的错误信息
368
+
369
+ ## [1.2.1] 2020-08-26
370
+ - [Added] 新增 `Auth.getAuthHeaderAsync` API
371
+
372
+ ## [1.1.4] 2020-08-25
373
+ - [Fixed] 修复微信公众号登录 Bug
374
+ - [Fixed] 修复微信小程序上传文件 Bug
375
+
376
+ ## [1.1.2] 2020-08-24
377
+ - [Fixed] 修复小程序无法直接引用 npm 包问题
378
+
379
+ ## [1.1.1] 2020-08-19
380
+ - [Fixed] 修复用户名密码登录bug
381
+
382
+ ## [1.1.0] 2020-08-18
383
+ - [Added] 增加 `cloudbase.registerSdkName` API
384
+
385
+ ## [1.0.4] 2020-08-13
386
+ - [Fixed] 修复实时推送多环境混淆问题
387
+
388
+ ## [1.0.3] 2020-08-11
389
+ - [Fixed] 修复由 Crypto-JS 引起的打包体积过大问题
390
+
391
+ ## [1.0.2] 2020-08-10
392
+ - [Changed] 优化版本统计信息
393
+
394
+ ## [1.0.1] 2020-08-05
395
+ - [Fixed] `Storage.downloadFile` 可将文件直接下载到本地
396
+
397
+ ## [1.0.0] 2020-07-31
398
+ - [Added] 发布 1.0.0 版本,旧版本 SDK [tcb-js-sdk](https://github.com/TencentCloudBase/tcb-js-sdk) 未来不再增加新功能
@@ -1,3 +1,2 @@
1
- export * from '@cloudbase/ai';
2
-
3
- //# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImluZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLGNBQWMsZUFBZSxDQUFBIiwiZmlsZSI6ImluZGV4LmVzbS5qcyIsInNvdXJjZXNDb250ZW50IjpbImV4cG9ydCAqIGZyb20gJ0BjbG91ZGJhc2UvYWknXG4iXX0=
1
+ import*as t from"web-streams-polyfill";import*as e from"@mattiasbuelens/web-streams-adapter";import*as n from"text-encoding-shim";import*as r from"@cloudbase/adapter-interface";import*as o from"jwt-decode";var i={d:(t,e)=>{for(var n in e)i.o(e,n)&&!i.o(t,n)&&Object.defineProperty(t,n,{enumerable:!0,get:e[n]})},o:(t,e)=>Object.prototype.hasOwnProperty.call(t,e),r:t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})}},a={};i.d(a,{AI:()=>Se,rf:()=>C,rT:()=>Bt,pe:()=>_e,jE:()=>Pe,jM:()=>Ue,Cq:()=>xe,el:()=>Ie,P6:()=>u});var u={};i.r(u),i.d(u,{ReadableStream:()=>g,TextDecoderStream:()=>O,TransformStream:()=>w,createAsyncIterable:()=>j,createEventSourceParserTransformStream:()=>S,createPromise:()=>U,functionToolToModelTool:()=>I,intoStandardStream:()=>x,intoTextStream:()=>k,isToolCallAssistantMessage:()=>q,readableStream2JsonObject:()=>P,toPolyfillReadable:()=>_});var s={};i.r(s),i.d(s,{ArkSimpleModel:()=>rt,DSSimpleModel:()=>st,DefaultImageModel:()=>Gt,DefaultSimpleModel:()=>Ct,HunYuanBetaSimpleModel:()=>K,HunYuanExpSimpleModel:()=>Ot,HunYuanOpenSimpleModel:()=>Pt,HunYuanSimpleModel:()=>Q,MODELS:()=>Zt,MoonshotSimpleModel:()=>gt,ReactModel:()=>Ht,YiSimpleModel:()=>ht,ZhiPuSimpleModel:()=>L,toolMap:()=>zt});const l=(c={ReadableStream:()=>t.ReadableStream,TransformStream:()=>t.TransformStream},f={},i.d(f,c),f);var c,f;const p=(t=>{var e={};return i.d(e,t),e})({createReadableStreamWrapper:()=>e.createReadableStreamWrapper});var h=[239,187,191];const d=(t=>{var e={};return i.d(e,t),e})({TextDecoder:()=>n.TextDecoder});var v=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())})},b=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},m=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t="function"==typeof __values?__values(t):t[Symbol.iterator](),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(n){e[n]=t[n]&&function(e){return new Promise(function(r,o){!function(t,e,n,r){Promise.resolve(r).then(function(e){t({value:e,done:n})},e)}(r,o,(e=t[n](e)).done,e.value)})}}},y="function"==typeof globalThis.ReadableStream&&"function"==typeof globalThis.TransformStream&&"function"==typeof globalThis.ReadableStream.prototype.pipeThrough,g=y?globalThis.ReadableStream:l.ReadableStream,w=y?globalThis.TransformStream:l.TransformStream,S=function(){var t;return new w({start:function(e){t=function(t){var e,n,r,o,i,a,u;return s(),{feed:function(t){n=n?n+t:t,e&&function(t){return h.every(function(e,n){return t.charCodeAt(n)===e})}(n)&&(n=n.slice(h.length)),e=!1;for(var i=n.length,a=0,u=!1;a<i;){u&&("\n"===n[a]&&(a+=1),u=!1);for(var s=-1,c=o,f=void 0,p=r;s<0&&p<i;p++)":"===(f=n[p])&&c<0?c=p-a:"\r"===f?(u=!0,s=p-a):"\n"===f&&(s=p-a);if(s<0){r=i-a,o=c;break}r=0,o=-1,l(n,a,c,s),a+=s+1}a===i?n="":a>0&&(n=n.slice(a))},reset:s};function s(){e=!0,n="",r=0,o=-1,i=void 0,a=void 0,u=""}function l(e,n,r,o){if(0===o)return u.length>0&&(t({type:"event",id:i,event:a||void 0,data:u.slice(0,-1)}),u="",i=void 0),void(a=void 0);var s,l=r<0,c=e.slice(n,n+(l?o:r)),f=n+(s=l?o:" "===e[n+r+1]?r+2:r+1),p=o-s,h=e.slice(f,f+p).toString();if("data"===c)u+=h?"".concat(h,"\n"):"\n";else if("event"===c)a=h;else if("id"!==c||h.includes("\0")){if("retry"===c){var d=parseInt(h,10);Number.isNaN(d)||t({type:"reconnect-interval",value:d})}}else i=h}}(function(t){"event"===t.type&&e.enqueue(t)})},transform:function(e){t.feed(e)}})},_=y?function(t){return t}:(0,p.createReadableStreamWrapper)(g),O=function(){function t(t,e){void 0===t&&(t="utf-8"),void 0===e&&(e={});var n=this;this.transform=new w({transform:function(t,e){var r=n.handle.decode(new Uint8Array(t),{stream:!0});r&&e.enqueue(r)},flush:function(t){var e=n.handle.decode();e&&t.enqueue(e),t.terminate()}}),this.handle=new d.TextDecoder(t,e)}return Object.defineProperty(t.prototype,"encoding",{get:function(){return this.handle.encoding},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"fatal",{get:function(){return this.handle.fatal},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"ignoreBOM",{get:function(){return this.handle.ignoreBOM},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"readable",{get:function(){return this.transform.readable},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"writable",{get:function(){return this.transform.writable},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,Symbol.toStringTag,{get:function(){return"TextDecoderStream"},enumerable:!1,configurable:!0}),t}();function j(t){var e=t;return e[Symbol.asyncIterator]=function(){var e=t.getReader();return{next:function(){return v(this,void 0,Promise,function(){var t,n,r;return b(this,function(o){switch(o.label){case 0:return[4,e.read()];case 1:return t=o.sent(),n=t.done,r=t.value,[2,n?{done:!0,value:void 0}:{done:!1,value:r}]}})})}}},e}function x(t){return j(t.pipeThrough(new O).pipeThrough(S()).pipeThrough(new w({transform:function(t,e){try{var n=JSON.parse(t.data);e.enqueue(n)}catch(n){"[DONE]"!==t.data?console.warn("Error when transforming event source data to json",n,t):e.terminate()}}})))}function k(t){return j(_(t).pipeThrough(new O))}function P(t){var e,n,r,o;return v(this,void 0,void 0,function(){var i,a,u,s,l,c;return b(this,function(f){switch(f.label){case 0:i=k(t),a="",f.label=1;case 1:f.trys.push([1,6,7,12]),u=!0,s=m(i),f.label=2;case 2:return[4,s.next()];case 3:if(l=f.sent(),e=l.done)return[3,5];o=l.value,u=!1;try{a+=o}finally{u=!0}f.label=4;case 4:return[3,2];case 5:return[3,12];case 6:return c=f.sent(),n={error:c},[3,12];case 7:return f.trys.push([7,,10,11]),u||e||!(r=s.return)?[3,9]:[4,r.call(s)];case 8:f.sent(),f.label=9;case 9:return[3,11];case 10:if(n)throw n.error;return[7];case 11:return[7];case 12:return[2,JSON.parse(a)]}})})}function U(){var t,e;return{promise:new Promise(function(n,r){t=n,e=r}),res:t,rej:e}}function q(t){var e;return"assistant"===t.role&&"tool_calls"in t&&null!=(null===(e=t.tool_calls)||void 0===e?void 0:e[0])}function I(t){return{type:"function",function:{description:t.description,name:t.name,parameters:t.parameters}}}var T=function(){return T=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},T.apply(this,arguments)},R=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())})},E=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},A=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n},C=function(){function t(t,e){this.baseUrl=e;var n=arguments[2];this.req="string"==typeof n?function(e){var r=e.headers,o=void 0===r?{}:r,i=A(e,["headers"]);return t(T(T({},i),{headers:T(T({},o),{Authorization:"Bearer ".concat(n)})}))}:t}return t.prototype.list=function(t,e){return this.req({method:"get",url:this.join("bots"),data:t,timeout:null==e?void 0:e.timeout})},t.prototype.create=function(t,e){var n=t.botInfo;return this.req({method:"post",url:this.join("bots"),data:n,timeout:null==e?void 0:e.timeout})},t.prototype.get=function(t,e){var n=t.botId;return this.req({method:"get",url:this.join("bots/".concat(n)),timeout:null==e?void 0:e.timeout})},t.prototype.update=function(t,e){var n=t.botId,r=t.botInfo;return this.req({method:"PATCH",url:this.join("bots/".concat(n)),data:r,timeout:null==e?void 0:e.timeout})},t.prototype.delete=function(t,e){var n=t.botId;return this.req({method:"delete",url:this.join("bots/".concat(n)),timeout:null==e?void 0:e.timeout})},t.prototype.getChatRecords=function(t,e){return this.req({method:"get",url:this.join("bots/".concat(t.botId,"/records")),data:t,timeout:null==e?void 0:e.timeout})},t.prototype.sendFeedback=function(t,e){var n=t.userFeedback;return this.req({method:"post",url:this.join("bots/".concat(n.botId,"/feedback")),data:n,timeout:null==e?void 0:e.timeout})},t.prototype.getFeedback=function(t,e){return this.req({method:"get",url:this.join("bots/".concat(t.botId,"/feedback")),data:t,timeout:null==e?void 0:e.timeout})},t.prototype.uploadFiles=function(t,e){return R(this,void 0,void 0,function(){return E(this,function(n){return[2,this.req({method:"post",url:this.join("bots/".concat(t.botId,"/files")),data:t,timeout:null==e?void 0:e.timeout})]})})},t.prototype.createConversation=function(t,e){var n=t.botId,r=A(t,["botId"]);return R(this,void 0,void 0,function(){return E(this,function(t){return[2,this.req({method:"post",url:this.join("bots/".concat(n,"/conversation")),data:r,timeout:null==e?void 0:e.timeout})]})})},t.prototype.getConversation=function(t,e){var n=t.pageSize,r=void 0===n?10:n,o=t.pageNumber,i=void 0===o?1:o,a=t.botId,u=A(t,["pageSize","pageNumber","botId"]);return R(this,void 0,void 0,function(){var t,n;return E(this,function(o){if(i<1)throw new Error("pageNumber must be greater than 0");return t=r*(i-1),n=r,[2,this.req({method:"get",url:this.join("bots/".concat(a,"/conversation")),data:T(T({},u),{offset:t,limit:n}),timeout:null==e?void 0:e.timeout})]})})},t.prototype.deleteConversation=function(t,e){var n=t.botId,r=t.conversationId,o=A(t,["botId","conversationId"]);return R(this,void 0,void 0,function(){return E(this,function(t){return[2,this.req({method:"delete",url:this.join("bots/".concat(n,"/conversation/").concat(r)),data:o,timeout:null==e?void 0:e.timeout})]})})},t.prototype.speechToText=function(t,e){return R(this,void 0,void 0,function(){return E(this,function(n){return[2,this.req({method:"post",url:this.join("bots/".concat(t.botId,"/speech-to-text")),data:t,timeout:null==e?void 0:e.timeout})]})})},t.prototype.textToSpeech=function(t,e){return R(this,void 0,void 0,function(){return E(this,function(n){return[2,this.req({method:"post",url:this.join("bots/".concat(t.botId,"/text-to-speech")),data:t,timeout:null==e?void 0:e.timeout})]})})},t.prototype.getTextToSpeechResult=function(t,e){return R(this,void 0,void 0,function(){return E(this,function(n){return[2,this.req({method:"get",url:this.join("bots/".concat(t.botId,"/text-to-speech")),data:t,timeout:null==e?void 0:e.timeout})]})})},t.prototype.getRecommendQuestions=function(t,e){return R(this,void 0,void 0,function(){var n;return E(this,function(r){switch(r.label){case 0:return[4,this.req({method:"post",url:this.join("bots/".concat(t.botId,"/recommend-questions")),data:t,stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,new M(n)]}})})},t.prototype.generateBot=function(t,e){return R(this,void 0,void 0,function(){var n;return E(this,function(r){switch(r.label){case 0:return[4,this.req({method:"post",url:this.join("generate-bot"),data:t,stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,new M(n)]}})})},t.prototype.getPreview=function(t,e){return R(this,void 0,void 0,function(){var n;return E(this,function(r){switch(r.label){case 0:return[4,this.req({method:"post",url:this.join("preview"),data:t,stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,new M(n)]}})})},t.prototype.generateImage=function(t,e){return this.req({method:"post",url:this.join("generate-image"),data:t,timeout:null==e?void 0:e.timeout})},t.prototype.sendMessage=function(t,e){return R(this,void 0,void 0,function(){var n;return E(this,function(r){switch(r.label){case 0:return[4,this.req({method:"post",url:this.join("bots/".concat(t.botId,"/send-message")),data:t,stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,new M(n)]}})})},t.prototype.join=function(t){return"".concat(this.baseUrl,"/").concat(t)},t}(),M=function(){function t(t){var e=_(t);this._eventSourceStream=e.pipeThrough(new O).pipeThrough(S())}return Object.defineProperty(t.prototype,"teeedStream",{get:function(){var t=this._eventSourceStream.tee(),e=t[0],n=t[1];return this._eventSourceStream=n,e},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"eventSourceStream",{get:function(){return j(this.teeedStream)},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"dataStream",{get:function(){return j(this.eventSourceStream.pipeThrough(new w({transform:function(t,e){try{var n=JSON.parse(t.data);e.enqueue(n)}catch(n){"[DONE]"!==t.data?console.warn("Error when transforming event source data to json",n,t):e.terminate()}}})))},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"textStream",{get:function(){return j(this.dataStream.pipeThrough(new w({transform:function(t,e){var n;e.enqueue(null!==(n=null==t?void 0:t.content)&&void 0!==n?n:"")}})))},enumerable:!1,configurable:!0}),t}(),B=function(){return B=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},B.apply(this,arguments)},G=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())})},D=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}};function N(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tool_choice,i=t.tools,a=t.top_p;return B(B({},t),{messages:e,model:n,temperature:r,tool_choice:(o&&"auto"!==o&&console.warn("`tool_choice` is not 'auto'"),o),tools:i,top_p:a})}var L=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="zhipu/api/paas/v4/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return G(this,void 0,Promise,function(){var n,r;return D(this,function(o){switch(o.label){case 0:return n=N(t),[4,this.req({url:this.url,data:B(B({},n),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return r=o.sent(),[2,B(B({},r),{rawResponse:r})]}})})},t.prototype.doStream=function(t,e){return G(this,void 0,Promise,function(){var n,r,o,i;return D(this,function(a){switch(a.label){case 0:return n=N(t),r=null,[4,this.req({url:this.url,data:B(B({},n),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return o=a.sent(),i=_(o),[2,j(x(i).pipeThrough(new w({transform:function(t,e){var n=t.choices.map(function(t){var e=t.delta;return null==r&&(r=q(e)),r?B(B({},t),{finish_reason:"tool_calls",delta:e}):t}),o=B(B({},t),{choices:n});e.enqueue(B(B({},o),{rawResponse:t}))}})))]}})})},t}(),J=function(){return J=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},J.apply(this,arguments)};function F(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tool_choice,i=t.tools,a=t.top_p;return J(J({},t),{messages:(e.forEach(function(t){"tool_calls"in t&&t.tool_calls.filter(function(t){return"function"!==t.type}).forEach(function(e){return console.warn("`type` in tool_call is not 'function'",e,t)})}),e),model:n,tools:function(){if(i)return i.forEach(function(t){"function"!==t.type&&console.warn("`type` in tool is not 'function'",t)}),i}(),top_p:a,tool_choice:o,temperature:r})}function H(t){return"object"!=typeof t||null==t?t:Array.isArray(t)?t.map(function(t){return H(t)}):Object.entries(t).reduce(function(t,e){var n,r=e[0],o=e[1];return t["_"===(n=r.replace(/[A-Z]/g,function(t){return"_".concat(t.toLowerCase())})).charAt(0)?n.slice(1):n]="object"==typeof o?H(o):o,t},{})}var W=function(){return W=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},W.apply(this,arguments)},Y=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())})},z=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},K=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="hunyuan-beta/openapi/v1/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return Y(this,void 0,Promise,function(){var n;return z(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:W(W({},F(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,W(W({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return Y(this,void 0,Promise,function(){var n,r,o;return z(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:W(W({},F(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=_(r),[2,j(x(o).pipeThrough(new w({transform:function(t,e){var r=t.choices.map(function(t){var e=t.delta;return null==n&&(n=q(e)),n?W(W({},t),{finish_reason:"tool_calls",delta:e}):t}),o=W(W({},t),{choices:r});e.enqueue(W(W({},o),{rawResponse:t}))}})))]}})})},t}(),X=function(){return X=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},X.apply(this,arguments)},V=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())})},Z=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},Q=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="hunyuan",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return V(this,void 0,Promise,function(){var n,r;return Z(this,function(o){switch(o.label){case 0:return[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:X(X({},F(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=o.sent(),r=H(n.Response),[2,X(X({},r),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return V(this,void 0,Promise,function(){var n,r,o;return Z(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,headers:{"X-Tc-Action":"ChatCompletions"},data:X(X({},t),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=_(r),[2,j(x(o).pipeThrough(new w({transform:function(t,e){var r=H(t),o=r.choices.map(function(t){var e=t.delta;return null==n&&(n=q(e)),n?X(X({},t),{finish_reason:"tool_calls",delta:e}):t}),i=X(X({},r),{choices:o});e.enqueue(X(X({},i),{rawResponse:t}))}})))]}})})},t}(),$=function(){return $=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},$.apply(this,arguments)},tt=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())})},et=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}};function nt(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return $($({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var rt=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="ark/api/v3/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return tt(this,void 0,Promise,function(){var n;return et(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:$($({},nt(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,$($({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return tt(this,void 0,Promise,function(){var n,r,o;return et(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:$($({},nt(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=_(r),[2,j(x(o).pipeThrough(new w({transform:function(t,e){var r=t.choices.map(function(t){var e=t.delta;return null==n&&(n=q(e)),n?$($({},t),{finish_reason:"tool_calls",delta:e}):t}),o=$($({},t),{choices:r});e.enqueue($($({},o),{rawResponse:t}))}})))]}})})},t}(),ot=function(){return ot=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},ot.apply(this,arguments)},it=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())})},at=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}};function ut(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return ot(ot({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var st=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="dashscope/compatible-mode/v1/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return it(this,void 0,Promise,function(){var n;return at(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:ot(ot({},ut(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,ot(ot({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return it(this,void 0,Promise,function(){var n,r,o;return at(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:ot(ot({},ut(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=_(r),[2,j(x(o).pipeThrough(new w({transform:function(t,e){var r=t.choices.map(function(t){var e=Object.assign(t.delta,{role:"assistant"});return null==n&&(n=q(e)),ot(ot({},t),n?{finish_reason:"tool_calls",delta:e}:{delta:e})}),o=ot(ot({},t),{choices:r});e.enqueue(ot(ot({},o),{rawResponse:t}))}})))]}})})},t}(),lt=function(){return lt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},lt.apply(this,arguments)},ct=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())})},ft=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}};function pt(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return lt(lt({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var ht=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="01-ai/v1/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return ct(this,void 0,Promise,function(){var n;return ft(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:lt(lt({},pt(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,lt(lt({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return ct(this,void 0,Promise,function(){var n,r,o,i,a;return ft(this,function(u){switch(u.label){case 0:return n=null,[4,this.req({url:this.url,data:lt(lt({},pt(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=u.sent(),o=_(r),i=x(o),a=i.pipeThrough(new w({transform:function(t,e){var r,o,i,a,u,s;if((null===(i=null===(o=null===(r=null==t?void 0:t.choices)||void 0===r?void 0:r[0])||void 0===o?void 0:o.delta)||void 0===i?void 0:i.content)||(null===(s=null===(u=null===(a=null==t?void 0:t.choices)||void 0===a?void 0:a[0])||void 0===u?void 0:u.delta)||void 0===s?void 0:s.tool_calls)){var l=t.choices.map(function(t){var e=Object.assign(t.delta,{role:"assistant"});return null==n&&(n=q(e)),lt(lt({},t),n?{finish_reason:"tool_calls",delta:e}:{delta:e})}),c=lt(lt({},t),{choices:l});e.enqueue(lt(lt({},c),{rawResponse:t}))}}})),[2,j(a)]}})})},t}(),dt=function(){return dt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},dt.apply(this,arguments)},vt=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())})},bt=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}};function mt(t){var e=t.messages,n=t.model,r=t.temperature,o=t.tools,i=t.top_p;return dt(dt({},t),{messages:e,model:n,tools:o,top_p:i,temperature:r})}var yt,gt=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="moonshot/v1/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return vt(this,void 0,Promise,function(){var n;return bt(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:dt(dt({},mt(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,dt(dt({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return vt(this,void 0,Promise,function(){var n,r,o;return bt(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:dt(dt({},mt(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=_(r),[2,j(x(o).pipeThrough(new w({transform:function(t,e){var r=t.choices.map(function(t){var e=t.delta;return null==n&&(n=q(e)),n?dt(dt({},t),{finish_reason:"tool_calls",delta:e}):t}),o=dt(dt({},t),{choices:r});e.enqueue(dt(dt({},o),{rawResponse:t}))}})))]}})})},t}(),wt=function(){return wt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},wt.apply(this,arguments)},St=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())})},_t=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},Ot=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="hunyuan-exp/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t){return St(this,void 0,Promise,function(){var e;return _t(this,function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:wt(wt({},F(t)),{stream:!1}),stream:!1})];case 1:return e=n.sent(),[2,wt(wt({},e),{rawResponse:e})]}})})},t.prototype.doStream=function(t){return St(this,void 0,Promise,function(){var e,n,r;return _t(this,function(o){switch(o.label){case 0:return e=null,[4,this.req({url:this.url,data:wt(wt({},F(t)),{stream:!0}),stream:!0})];case 1:return n=o.sent(),r=_(n),[2,j(x(r).pipeThrough(new w({transform:function(t,n){var r=t.choices.map(function(t){var n=t.delta;return null==e&&(e=q(n)),e?wt(wt({},t),{finish_reason:"tool_calls",delta:n}):t}),o=wt(wt({},t),{choices:r});n.enqueue(wt(wt({},o),{rawResponse:t}))}})))]}})})},t}(),jt=function(){return jt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},jt.apply(this,arguments)},xt=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())})},kt=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},Pt=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="hunyuan-open/v1/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return xt(this,void 0,Promise,function(){var n;return kt(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:jt(jt({},F(t)),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,jt(jt({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return xt(this,void 0,Promise,function(){var n,r,o;return kt(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:jt(jt({},F(t)),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=_(r),[2,j(x(o).pipeThrough(new w({transform:function(t,e){var r=t.choices.map(function(t){var e=t.delta;return null==n&&(n=q(e)),n?jt(jt({},t),{finish_reason:"tool_calls",delta:e}):t}),o=jt(jt({},t),{choices:r});e.enqueue(jt(jt({},o),{rawResponse:t}))}})))]}})})},t}(),Ut=function(){return Ut=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Ut.apply(this,arguments)},qt=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())})},It=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},Tt=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.subUrl="deepseek/chat/completions",null!=n&&(this.subUrl=n)}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t,e){return qt(this,void 0,Promise,function(){var n;return It(this,function(r){switch(r.label){case 0:return[4,this.req({url:this.url,data:Ut(Ut({},t),{stream:!1}),stream:!1,timeout:null==e?void 0:e.timeout})];case 1:return n=r.sent(),[2,Ut(Ut({},n),{rawResponse:n})]}})})},t.prototype.doStream=function(t,e){return qt(this,void 0,Promise,function(){var n,r,o;return It(this,function(i){switch(i.label){case 0:return n=null,[4,this.req({url:this.url,data:Ut(Ut({},t),{stream:!0}),stream:!0,timeout:null==e?void 0:e.timeout})];case 1:return r=i.sent(),o=_(r),[2,j(x(o).pipeThrough(new w({transform:function(t,e){var r=t.choices.map(function(t){var e=t.delta;return null==n&&(n=q(e)),n?Ut(Ut({},t),{finish_reason:"tool_calls",delta:e}):t}),o=Ut(Ut({},t),{choices:r});e.enqueue(Ut(Ut({},o),{rawResponse:t}))}})))]}})})},t}(),Rt=function(){return Rt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Rt.apply(this,arguments)},Et=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())})},At=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},Ct=function(){function t(t,e,n){void 0===n&&(n=""),this.req=t,this.baseUrl=e,this.subUrl=n}return Object.defineProperty(t.prototype,"url",{get:function(){return"".concat(this.baseUrl,"/").concat(this.subUrl)},enumerable:!1,configurable:!0}),t.prototype.doGenerate=function(t){return Et(this,void 0,Promise,function(){var e;return At(this,function(n){switch(n.label){case 0:return[4,this.req({url:this.url,data:Rt(Rt({},t),{stream:!1}),stream:!1})];case 1:return e=n.sent(),[2,Rt(Rt({},e),{rawResponse:e})]}})})},t.prototype.doStream=function(t){return Et(this,void 0,Promise,function(){var e,n,r;return At(this,function(o){switch(o.label){case 0:return e=null,[4,this.req({url:this.url,data:Rt(Rt({},t),{stream:!0}),stream:!0})];case 1:return n=o.sent(),r=_(n),[2,j(x(r).pipeThrough(new w({transform:function(t,n){var r=t.choices.map(function(t){var n=t.delta;return null==e&&(e=q(n)),e?Rt(Rt({},t),{finish_reason:"tool_calls",delta:n}):t}),o=Rt(Rt({},t),{choices:r});n.enqueue(Rt(Rt({},o),{rawResponse:t}))}})))]}})})},t}(),Mt=(yt=function(t,e){return yt=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},yt(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}yt(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}),Bt=function(t){function e(e,n){var r=t.call(this,e)||this;return r.name="InvalidParamsError",r.code="INVALID_PARAMS",r.field=n,r}return Mt(e,t),e.prototype.toJSON=function(){return{code:this.code,message:this.message,field:this.field}},e}(Error),Gt=function(){function t(t,e,n){this.req=t,this.baseUrl=e,this.provider=n,this.defaultGenerateImageSubUrl="images/ar/generations",this.generateImageSubUrlConfig={"hunyuan-image":[[/^hunyuan-image(-v[12](\..*)?)?$/,"images/generations"]]},this.generateImage=this.generateImageImpl.bind(this)}return t.prototype.generateImageImpl=function(t){return e=this,n=void 0,o=function(){var e,n,r,o,i;return function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}}(this,function(a){switch(a.label){case 0:if("object"==typeof t&&t&&"model"in t&&"HY-Image-v3.0-I2I-ToB-v1.0.1"===t.model&&(""===this.provider||"hunyuan-image"===this.provider)){if(n=(e=t).image_urls,r=e.images,n&&n.length>1)throw new Bt("当模型为 HY-Image-v3.0-I2I-ToB-v1.0.1 时,image_urls 最多只能有 1 个元素","image_urls");if(r&&r.length>1)throw new Bt("当模型为 HY-Image-v3.0-I2I-ToB-v1.0.1 时,images 最多只能有 1 个元素","images")}return o=this.defaultGenerateImageSubUrl,"object"==typeof t&&t&&"model"in t&&"string"==typeof t.model&&(i=this.getGenerateImageSubUrl(this.provider,t.model))&&(o=i),[4,this.req({url:this.getGenerateUrl(o),data:t,stream:!1})];case 1:return[2,a.sent()]}})},new((r=Promise)||(r=Promise))(function(t,i){function a(t){try{s(o.next(t))}catch(t){i(t)}}function u(t){try{s(o.throw(t))}catch(t){i(t)}}function s(e){var n;e.done?t(e.value):(n=e.value,n instanceof r?n:new r(function(t){t(n)})).then(a,u)}s((o=o.apply(e,n||[])).next())});var e,n,r,o},t.prototype.getGenerateUrl=function(t){return"".concat(this.baseUrl,"/").concat(this.provider,"/").concat(t)},t.prototype.getGenerateImageSubUrl=function(t,e){var n=this.generateImageSubUrlConfig[t];if(n)for(var r=0,o=n;r<o.length;r++){var i=o[r],a=i[0],u=i[1];if(a.test(e))return u}},t}(),Dt=function(){return Dt=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Dt.apply(this,arguments)},Nt=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())})},Lt=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},Jt=function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))};function Ft(t){var e,n=t.onStepFinish,r=t.abortSignal,o=t.maxSteps,i=t.topP,a=t.toolChoice,u=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n}(t,["onStepFinish","abortSignal","maxSteps","topP","toolChoice"]);if(null!=o&&o<1)throw new Error("`maxSteps` muse be greater than 0.");return[{onStepFinish:n,abortSignal:r,maxSteps:o},Dt(Dt({},u),{tools:null===(e=u.tools)||void 0===e?void 0:e.map(function(t){return"fn"in t?I(t):t}),top_p:null!=i?i:u.top_p,tool_choice:null!=a?a:u.tool_choice})]}var Ht=function(){function t(t){this.model=t}return t.prototype.generateText=function(t,e){var n,r;return Nt(this,void 0,Promise,function(){var o,i,a,u,s,l,c,f,p,h,d,v,b,m,y,g,w,S,_,O,j,x=this;return Lt(this,function(k){switch(k.label){case 0:return o=[],i={completion_tokens:0,prompt_tokens:0,total_tokens:0},a=Ft(t),u=a[0],s=u.onStepFinish,l=u.maxSteps,c=void 0===l?10:l,f=a[1],[4,(p=function(){return x.model.doGenerate(f,e)})()];case 1:h=k.sent(),d=1,h.rawResponse&&o.push(h.rawResponse),v=null,k.label=2;case 2:if(!(d<c&&null!=(v=Wt(h))))return[3,9];b=Xt(h.usage),Vt(i,b),k.label=3;case 3:return k.trys.push([3,7,,8]),[4,Kt(v)];case 4:return m=k.sent(),y=h.choices[0],[4,null==s?void 0:s({finishReason:y.finish_reason,messages:f.messages.slice(),text:y.message.content,toolCall:v,toolResult:m,stepUsage:b,totalUsage:Object.assign({},i)})];case 5:return k.sent(),Yt(f.messages,y.message,m),[4,p()];case 6:return(h=k.sent()).rawResponse&&o.push(h.rawResponse),d+=1,[3,8];case 7:return g=k.sent(),[2,{text:"",messages:f.messages,usage:i,error:g,rawResponses:o}];case 8:return[3,2];case 9:return w=null===(n=null==h?void 0:h.choices)||void 0===n?void 0:n[0],S=null==w?void 0:w.message,_=null!==(r=null==S?void 0:S.content)&&void 0!==r?r:"",O=S?Jt(Jt([],f.messages,!0),[S],!1):f.messages,j=Xt(h.usage),Vt(i,j),[4,null==s?void 0:s({finishReason:w.finish_reason,messages:O.slice(),text:_,toolCall:Wt(h),toolResult:null,stepUsage:j,totalUsage:Object.assign({},i)})];case 10:return k.sent(),[2,{text:_,messages:O,usage:i,rawResponses:o}]}})})},t.prototype.streamText=function(t,e){var n;return Nt(this,void 0,Promise,function(){var r,o,i,a,u,s,l,c,f,p,h,d,v,b,m,y,g,S,_,O,x,k,P,q,I,T,R,E,A,C,M,B,G,D,N,L,J=this;return Lt(this,function(F){switch(F.label){case 0:return r={completion_tokens:0,prompt_tokens:0,total_tokens:0},o=Ft(t),i=o[0],a=i.onStepFinish,u=i.maxSteps,s=void 0===u?10:u,l=o[1],[4,(c=function(){return J.model.doStream(l,e)})()];case 1:f=F.sent(),p=1,h=null,d=function(){var t=f.tee(),e=t[0],n=t[1];return f=j(e),function(t){var e,n,r,o,i,a,u,s,l,c;return Nt(this,void 0,Promise,function(){var f,p,h,d,v,b,m,y,g,w,S,_,O;return Lt(this,function(x){switch(x.label){case 0:f={completion_tokens:0,prompt_tokens:0,total_tokens:0},p=j(t),d={role:"assistant",content:"",tool_calls:[h={id:"",function:{name:"",arguments:""},type:""}]},x.label=1;case 1:x.trys.push([1,6,7,12]),v=!0,b=function(t){if(!Symbol.asyncIterator)throw new TypeError("Symbol.asyncIterator is not defined.");var e,n=t[Symbol.asyncIterator];return n?n.call(t):(t="function"==typeof __values?__values(t):t[Symbol.iterator](),e={},r("next"),r("throw"),r("return"),e[Symbol.asyncIterator]=function(){return this},e);function r(n){e[n]=t[n]&&function(e){return new Promise(function(r,o){!function(t,e,n,r){Promise.resolve(r).then(function(e){t({value:e,done:n})},e)}(r,o,(e=t[n](e)).done,e.value)})}}}(p),x.label=2;case 2:return[4,b.next()];case 3:if(m=x.sent(),e=m.done)return[3,5];o=m.value,v=!1;try{if(!(g=null==(y=o)?void 0:y.choices[0]))return[2,null];if(w=g.finish_reason,S=g.delta,"tool_calls"!==w)return[2,null];if(!S)return[3,4];if(S.content&&(d.content+=S.content),!("tool_calls"in S))return[3,4];(null==(_=null===(i=null==S?void 0:S.tool_calls)||void 0===i?void 0:i[0])?void 0:_.id)&&(h.id=_.id),(null==_?void 0:_.type)&&(h.type=_.type),(null===(a=null==_?void 0:_.function)||void 0===a?void 0:a.name)&&(h.function.name=_.function.name),(null===(u=null==_?void 0:_.function)||void 0===u?void 0:u.arguments)&&(h.function.arguments+=_.function.arguments),(null===(s=null==y?void 0:y.usage)||void 0===s?void 0:s.completion_tokens)&&(f.completion_tokens=y.usage.completion_tokens),(null===(l=null==y?void 0:y.usage)||void 0===l?void 0:l.prompt_tokens)&&(f.prompt_tokens=y.usage.prompt_tokens),(null===(c=null==y?void 0:y.usage)||void 0===c?void 0:c.total_tokens)&&(f.total_tokens=y.usage.total_tokens)}finally{v=!0}x.label=4;case 4:return[3,2];case 5:return[3,12];case 6:return O=x.sent(),n={error:O},[3,12];case 7:return x.trys.push([7,,10,11]),v||e||!(r=b.return)?[3,9]:[4,r.call(b)];case 8:x.sent(),x.label=9;case 9:return[3,11];case 10:if(n)throw n.error;return[7];case 11:return[7];case 12:return[2,{message:d,usage:f}]}})})}(n)},F.label=2;case 2:return(v=p<s)?[4,d()]:[3,4];case 3:v=null!=(h=F.sent()),F.label=4;case 4:if(!v)return[3,11];b=h.message,m=h.usage,Vt(r,m),y=null===(n=b.tool_calls)||void 0===n?void 0:n[0],F.label=5;case 5:return F.trys.push([5,9,,10]),[4,Kt(y)];case 6:return g=F.sent(),[4,null==a?void 0:a({finishReason:"tool_calls",messages:l.messages.slice(),text:b.content,toolCall:y,toolResult:g,stepUsage:m,totalUsage:Object.assign({},r)})];case 7:return F.sent(),Yt(l.messages,b,g),[4,c()];case 8:return f=F.sent(),[3,10];case 9:return S=F.sent(),_=f.tee(),O=_[0],x=_[1],[2,{messages:Promise.resolve(l.messages),dataStream:j(O),textStream:j(x.pipeThrough(new w({transform:function(t,e){var n,r,o,i=null===(o=null===(r=null===(n=null==t?void 0:t.choices)||void 0===n?void 0:n[0])||void 0===r?void 0:r.delta)||void 0===o?void 0:o.content;"string"==typeof i&&e.enqueue(i)}}))),usage:Promise.resolve(r),error:S}];case 10:return[3,2];case 11:return[4,d()];case 12:return(h=F.sent())?(k=h.message,P=h.usage,Vt(r,P),q=Jt(Jt([],l.messages,!0),[k],!1),a({messages:q.slice(),finishReason:"tool_call",stepUsage:P,text:k.content,toolCall:k.tool_calls[0],totalUsage:Object.assign({},r)}),I=f.tee(),T=I[0],R=I[1],[2,{messages:Promise.resolve(Jt(Jt([],l.messages,!0),[k],!1)),dataStream:j(T),textStream:j(R.pipeThrough(new w({transform:function(t,e){var n,r,o,i=null===(o=null===(r=null===(n=null==t?void 0:t.choices)||void 0===n?void 0:n[0])||void 0===r?void 0:r.delta)||void 0===o?void 0:o.content;"string"==typeof i&&e.enqueue(i)}}))),usage:Promise.resolve(r)}]):(E=U(),A=U(),C={role:"assistant",content:""},M="",B={completion_tokens:0,prompt_tokens:0,total_tokens:0},G=f.pipeThrough(new w({transform:function(t,e){var n,r,o,i,a,u,s,l,c=null===(o=null===(r=null===(n=null==t?void 0:t.choices)||void 0===n?void 0:n[0])||void 0===r?void 0:r.delta)||void 0===o?void 0:o.content;"string"==typeof c&&(C.content+=c);var f=null===(a=null===(i=null==t?void 0:t.choices)||void 0===i?void 0:i[0])||void 0===a?void 0:a.finish_reason;f&&(M=f),(null===(u=null==t?void 0:t.usage)||void 0===u?void 0:u.completion_tokens)&&(B.completion_tokens=t.usage.completion_tokens),(null===(s=null==t?void 0:t.usage)||void 0===s?void 0:s.prompt_tokens)&&(B.prompt_tokens=t.usage.prompt_tokens),(null===(l=null==t?void 0:t.usage)||void 0===l?void 0:l.total_tokens)&&(B.total_tokens=t.usage.total_tokens),e.enqueue(t)},flush:function(){E.res(Jt(Jt([],l.messages,!0),[C],!1)),Vt(r,B),A.res(Object.assign({},r)),null==a||a({messages:Jt(Jt([],l.messages,!0),[C],!1),finishReason:M,text:C.content,stepUsage:B,totalUsage:Object.assign({},r)})}})),D=G.tee(),N=D[0],L=D[1],[2,{messages:E.promise,dataStream:j(N),textStream:j(L.pipeThrough(new w({transform:function(t,e){var n,r,o,i=null===(o=null===(r=null===(n=null==t?void 0:t.choices)||void 0===n?void 0:n[0])||void 0===r?void 0:r.delta)||void 0===o?void 0:o.content;"string"==typeof i&&e.enqueue(i)}}))),usage:A.promise}])}})})},t}();function Wt(t){var e,n=null===(e=null==t?void 0:t.choices)||void 0===e?void 0:e[0];if(!n)return null;var r=n.finish_reason,o=n.message;return"tool_calls"!==r?null:o&&q(o)?o.tool_calls[0]:null}function Yt(t,e,n){t.push(e,{role:"tool",tool_call_id:e.tool_calls[0].id,content:JSON.stringify(n)})}var zt=new Map;function Kt(t){return zt.get(t.function.name)(JSON.parse(t.function.arguments))}function Xt(t){var e,n,r;return{completion_tokens:null!==(e=null==t?void 0:t.completion_tokens)&&void 0!==e?e:0,prompt_tokens:null!==(n=null==t?void 0:t.prompt_tokens)&&void 0!==n?n:0,total_tokens:null!==(r=null==t?void 0:t.total_tokens)&&void 0!==r?r:0}}function Vt(t,e){t.completion_tokens+=e.completion_tokens,t.prompt_tokens+=e.prompt_tokens,t.total_tokens+=e.total_tokens}var Zt={hunyuan:Q,"hunyuan-beta":K,ark:rt,dashscope:st,"01-ai":ht,moonshot:gt,zhipu:L,"hunyuan-exp":Ot,"hunyuan-open":Pt,deepseek:Tt};var Qt="INVALID_OPERATION",$t="OPERATION_FAIL";const te=(t=>{var e={};return i.d(e,t),e})({AbstractSDKRequest:()=>r.AbstractSDKRequest,AbstractStorage:()=>r.AbstractStorage});function ee(t,e){console.warn("[".concat("@cloudbase/js-sdk","][").concat(t,"]:").concat(e))}var ne,re=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),oe=function(){return oe=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},oe.apply(this,arguments)},ie=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())})},ae=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}};!function(t){function e(e){var n=t.call(this)||this,r=e.timeout,o=e.timeoutMsg,i=e.restrictedMethods;return n.timeout=r||0,n.timeoutMsg=o||"请求超时",n.restrictedMethods=i||["get","post","upload","download"],n}re(e,t),e.prototype.get=function(t){return this.request(oe(oe({},t),{method:"get"}),this.restrictedMethods.includes("get"))},e.prototype.post=function(t){return this.request(oe(oe({},t),{method:"post"}),this.restrictedMethods.includes("post"))},e.prototype.put=function(t){return this.request(oe(oe({},t),{method:"put"}))},e.prototype.upload=function(t){var e=t.data,n=t.file,r=t.name,o=t.method,i=t.headers,a=void 0===i?{}:i,u={post:"post",put:"put"}[null==o?void 0:o.toLowerCase()]||"put",s=new FormData;return"post"===u?(Object.keys(e).forEach(function(t){s.append(t,e[t])}),s.append("key",r),s.append("file",n),this.request(oe(oe({},t),{data:s,method:u}),this.restrictedMethods.includes("upload"))):this.request(oe(oe({},t),{method:"put",headers:a,body:n}),this.restrictedMethods.includes("upload"))},e.prototype.download=function(t){return ie(this,void 0,Promise,function(){var e,n,r,o;return ae(this,function(i){switch(i.label){case 0:return i.trys.push([0,2,,3]),[4,this.get(oe(oe({},t),{headers:{},responseType:"blob"}))];case 1:return e=i.sent().data,n=window.URL.createObjectURL(new Blob([e])),r=decodeURIComponent(new URL(t.url).pathname.split("/").pop()||""),(o=document.createElement("a")).href=n,o.setAttribute("download",r),o.style.display="none",document.body.appendChild(o),o.click(),window.URL.revokeObjectURL(n),document.body.removeChild(o),[3,3];case 2:return i.sent(),[3,3];case 3:return[2,new Promise(function(e){e({statusCode:200,tempFilePath:t.url})})]}})})},e.prototype.fetch=function(t){var e;return ie(this,void 0,Promise,function(){var n,r,o,i,a,u,s,l,c,f,p,h,d,v=this;return ae(this,function(b){switch(b.label){case 0:return n=new AbortController,r=t.url,o=t.enableAbort,i=void 0!==o&&o,a=t.stream,u=void 0!==a&&a,s=t.signal,l=t.timeout,c=t.shouldThrowOnError,f=void 0===c||c,p=null!=l?l:this.timeout,s&&(s.aborted&&n.abort(),s.addEventListener("abort",function(){return n.abort()})),h=null,i&&p&&(h=setTimeout(function(){console.warn(v.timeoutMsg),n.abort(new Error(v.timeoutMsg))},p)),[4,fetch(r,oe(oe({},t),{signal:n.signal})).then(function(t){return ie(v,void 0,void 0,function(){var e,n,r;return ae(this,function(o){switch(o.label){case 0:return clearTimeout(h),f?t.ok?(e=t,[3,3]):[3,1]:[3,4];case 1:return r=(n=Promise).reject,[4,t.json()];case 2:e=r.apply(n,[o.sent()]),o.label=3;case 3:return[2,e];case 4:return[2,t]}})})}).catch(function(t){return clearTimeout(h),Promise.reject(t)})];case 1:return d=b.sent(),[2,{data:u?d.body:(null===(e=d.headers.get("content-type"))||void 0===e?void 0:e.includes("application/json"))?d.json():d.text(),statusCode:d.status,header:d.headers,response:d}]}})})},e.prototype.request=function(t,e){var n=this;void 0===e&&(e=!1);var r=String(t.method).toLowerCase()||"get";return new Promise(function(o){var i=t.url,a=t.headers,u=void 0===a?{}:a,s=t.data,l=t.responseType,c=t.withCredentials,f=t.body,p=t.onUploadProgress,h=function(t,e,n){void 0===n&&(n={});var r=/\?/.test(e),o="";return Object.keys(n).forEach(function(t){""===o?!r&&(e+="?"):o+="&",o+="".concat(t,"=").concat(encodeURIComponent(n[t]))}),/^http(s)?:\/\//.test(e+=o)?e:"".concat(t).concat(e)}("https:",i,"get"===r?s:{}),d=new XMLHttpRequest;d.open(r,h),l&&(d.responseType=l);var v,b,m,y=t.signal;y&&(y.aborted?d.abort():y.addEventListener("abort",function(){return d.abort()},{once:!0})),Object.keys(u).forEach(function(t){d.setRequestHeader(t,u[t])}),p&&d.upload.addEventListener("progress",p),d.onreadystatechange=function(){var t={};if(4===d.readyState){var e=d.getAllResponseHeaders().trim().split(/[\r\n]+/),n={};e.forEach(function(t){var e=t.split(": "),r=e.shift().toLowerCase(),o=e.join(": ");n[r]=o}),t.header=n,t.statusCode=d.status;try{t.data="blob"===l?d.response:JSON.parse(d.responseText)}catch(e){t.data="blob"===l?d.response:d.responseText}clearTimeout(v),o(t)}},e&&n.timeout&&(v=setTimeout(function(){console.warn(n.timeoutMsg),d.abort()},n.timeout)),m=s,b="[object FormData]"===Object.prototype.toString.call(m)?s:"application/x-www-form-urlencoded"===u["content-type"]?function(t){void 0===t&&(t={});var e=[];return Object.keys(t).forEach(function(n){e.push("".concat(n,"=").concat(encodeURIComponent(t[n])))}),e.join("&")}(s):f||(s?JSON.stringify(s):void 0),c&&(d.withCredentials=!0),d.send(b)})}}(te.AbstractSDKRequest),function(t){t.WEB="web",t.WX_MP="wx_mp"}(ne||(ne={}));var ue=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),se=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())})},le=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},ce=function(t){function e(e){var n=t.call(this)||this;return n.root=e,e.tcbCacheObject||(e.tcbCacheObject={}),n}return ue(e,t),e.prototype.setItem=function(t,e){this.root.tcbCacheObject[t]=e},e.prototype.getItem=function(t){return this.root.tcbCacheObject[t]},e.prototype.removeItem=function(t){delete this.root.tcbCacheObject[t]},e.prototype.clear=function(){delete this.root.tcbCacheObject},e}(te.AbstractStorage);!function(){function t(t){this.keys={};var e=t.persistence,n=t.platformInfo,r=void 0===n?{}:n,o=t.keys,i=void 0===o?{}:o;this.platformInfo=r,this.storage||(this.persistenceTag=this.platformInfo.adapter.primaryStorage||e,this.storage=function(t,e){switch(t){case"local":default:return e.localStorage?e.localStorage:(ee("INVALID_PARAMS","localStorage is not supported on current platform"),new ce(e.root));case"none":return new ce(e.root)}}(this.persistenceTag,this.platformInfo.adapter),this.keys=i)}Object.defineProperty(t.prototype,"mode",{get:function(){return this.storage.mode||"sync"},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"persistence",{get:function(){return this.persistenceTag},enumerable:!1,configurable:!0}),t.prototype.setStore=function(t,e,n){if("async"!==this.mode){if(this.storage)try{var r={version:n||"localCachev1",content:e};this.storage.setItem(t,JSON.stringify(r))}catch(t){throw new Error(JSON.stringify({code:$t,msg:"[".concat("@cloudbase/js-sdk","][").concat($t,"]setStore failed"),info:t}))}}else ee(Qt,"current platform's storage is asynchronous, please use setStoreAsync insteed")},t.prototype.setStoreAsync=function(t,e,n){return se(this,void 0,void 0,function(){var r;return le(this,function(o){switch(o.label){case 0:if(!this.storage)return[2];o.label=1;case 1:return o.trys.push([1,3,,4]),r={version:n||"localCachev1",content:e},[4,this.storage.setItem(t,JSON.stringify(r))];case 2:return o.sent(),[3,4];case 3:return o.sent(),[2];case 4:return[2]}})})},t.prototype.getStore=function(t,e){var n;if("async"!==this.mode){try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return{IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0}.tcb_token;if(!this.storage)return""}catch(t){return""}e=e||"localCachev1";var r=this.storage.getItem(t);return r&&r.indexOf(e)>=0?JSON.parse(r).content:""}ee(Qt,"current platform's storage is asynchronous, please use getStoreAsync insteed")},t.prototype.getStoreAsync=function(t,e){var n;return se(this,void 0,void 0,function(){var r;return le(this,function(o){switch(o.label){case 0:try{if("undefined"!=typeof process&&(null===(n={IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0})||void 0===n?void 0:n.tcb_token))return[2,{IS_MP_BUILD:!1,IS_BROWSER_BUILD:!0}.tcb_token];if(!this.storage)return[2,""]}catch(t){return[2,""]}return e=e||"localCachev1",[4,this.storage.getItem(t)];case 1:return(r=o.sent())&&r.indexOf(e)>=0?[2,JSON.parse(r).content]:[2,""]}})})},t.prototype.removeStore=function(t){"async"!==this.mode?this.storage.removeItem(t):ee(Qt,"current platform's storage is asynchronous, please use removeStoreAsync insteed")},t.prototype.removeStoreAsync=function(t){return se(this,void 0,void 0,function(){return le(this,function(e){switch(e.label){case 0:return[4,this.storage.removeItem(t)];case 1:return e.sent(),[2]}})})}}();var fe=function(){var t=function(e,n){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},t(e,n)};return function(e,n){if("function"!=typeof n&&null!==n)throw new TypeError("Class extends value "+String(n)+" is not a constructor or null");function r(){this.constructor=e}t(e,n),e.prototype=null===n?Object.create(n):(r.prototype=n.prototype,new r)}}(),pe=function(t,e){this.data=e||null,this.name=t},he=function(t){function e(e,n){var r=t.call(this,"error",{error:e,data:n})||this;return r.error=e,r}return fe(e,t),e}(pe),de=function(){function t(){this.listeners={}}return t.prototype.on=function(t,e){return function(t,e,n){n[t]=n[t]||[],n[t].push(e)}(t,e,this.listeners),this},t.prototype.off=function(t,e){return function(t,e,n){if(null==n?void 0:n[t]){var r=n[t].indexOf(e);-1!==r&&n[t].splice(r,1)}}(t,e,this.listeners),this},t.prototype.fire=function(t,e){if(t instanceof he)return console.error(t.error),this;var n="string"==typeof t?new pe(t,e||{}):t,r=n.name;if(this.listens(r)){n.target=this;for(var o=0,i=this.listeners[r]?function(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}([],this.listeners[r],!0):[];o<i.length;o++)i[o].call(this,n)}return this},t.prototype.listens=function(t){return this.listeners[t]&&this.listeners[t].length>0},t}();new de;var ve=new de;"undefined"!=typeof navigator&&navigator.userAgent&&navigator.userAgent.indexOf("Firefox");const be=(t=>{var e={};return i.d(e,t),e})({default:()=>o.default});be.default;var me=function(){return me=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},me.apply(this,arguments)},ye=function(t,e,n,r){return new(n||(n=Promise))(function(o,i){function a(t){try{s(r.next(t))}catch(t){i(t)}}function u(t){try{s(r.throw(t))}catch(t){i(t)}}function s(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n(function(t){t(e)})).then(a,u)}s((r=r.apply(t,e||[])).next())})},ge=function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}},we=Zt,Se=function(){function t(t,e,n,r){var o=this;this.req=t,this.baseUrl=e,this.modelRequest=function(t){var e=t.url,n=t.data,r=t.headers,i=t.stream,a=t.timeout;return ye(o,void 0,void 0,function(){var t,o,u,s,l,c,f;return ge(this,function(p){switch(p.label){case 0:return t={"Content-Type":"application/json"},i&&Object.assign(t,{Accept:"text/event-stream"}),[4,this.req.fetch({method:"post",headers:me(me((l={},l[null===(c=this.i18n)||void 0===c?void 0:c.LANG_HEADER_KEY]=null===(f=this.i18n)||void 0===f?void 0:f.lang,l),t),r),body:JSON.stringify(n),url:this.resolveUrl(e),stream:i,timeout:a})];case 1:return o=p.sent(),u=o.data,s=o.header,[2,this.handleResponseData(u,s)]}})})},this.botRequest=function(t){var e=t.method,n=t.url,r=t.data,i=void 0===r?{}:r,a=t.headers,u=t.stream,s=t.timeout;return ye(o,void 0,void 0,function(){var t,r,o,l,c,f,p,h,d;return ge(this,function(v){switch(v.label){case 0:return t=this.resolveUrl(n),"get"!==e?[3,2]:(r=this.handleResponseData,[4,this.req.fetch({url:"".concat(t,"?").concat((b=i,Object.entries(b).map(function(t){var e=t[0],n=t[1];return"".concat(e,"=").concat(n)}).join("&"))),method:e,headers:a,stream:u,timeout:s})]);case 1:return[2,r.apply(this,[v.sent().data])];case 2:return o={"Content-Type":"application/json"},u&&Object.assign(o,{Accept:"text/event-stream"}),[4,this.req.fetch({url:t,body:JSON.stringify(i),headers:me(me((p={},p[null===(h=this.i18n)||void 0===h?void 0:h.LANG_HEADER_KEY]=null===(d=this.i18n)||void 0===d?void 0:d.lang,p),o),a),stream:u,method:e,timeout:s})];case 3:return l=v.sent(),c=l.data,f=l.header,[2,this.handleResponseData(c,f)]}var b})})},this._getBaseUrl=r,this.bot=new C(this.botRequest,this.aiBotBaseUrl),this.i18n=n,ve.on("lang_change",function(t){var e;o.i18n=(null===(e=t.data)||void 0===e?void 0:e.i18n)||o.i18n})}return Object.defineProperty(t.prototype,"aiBaseUrl",{get:function(){return"".concat(this._getBaseUrl?this._getBaseUrl():this.baseUrl,"/ai")},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"aiBotBaseUrl",{get:function(){return"".concat(this._getBaseUrl?this._getBaseUrl():this.baseUrl,"/aibot")},enumerable:!1,configurable:!0}),t.prototype.handleResponseData=function(t,e){var n,r;return ye(this,void 0,void 0,function(){var o,i,a,u,s=this;return ge(this,function(l){switch(l.label){case 0:return o="".concat(this.i18n.t("请检查调用方式,或前往云开发 AI+ 首页查看文档"),":https://tcb.cloud.tencent.com/dev#/ai"),i=function(t){if("object"==typeof t&&t&&"code"in t&&"NORMAL"!==t.code)throw new Error("".concat(s.i18n.t("AI+ 请求出错,错误码"),":").concat(t.code,",").concat(s.i18n.t("错误信息"),":").concat(t.message,"\n").concat(o,"\n").concat(JSON.stringify(t,null,2)))},"object"==typeof t&&t&&"function"!=typeof t.getReader?"then"in t?[4,t]:[3,2]:[3,4];case 1:return a=l.sent(),[3,3];case 2:a=t,l.label=3;case 3:return i(u=a),[2,t];case 4:if("function"!=typeof(null==t?void 0:t.getReader)){if("object"==typeof(u=t)&&u&&"code"in u&&"NORMAL"!==u.code)throw new Error("".concat(this.i18n.t("AI+ 请求出错,错误码"),":").concat(u.code,",").concat(this.i18n.t("错误信息"),":").concat(u.message,"\n").concat(o,"\n").concat(JSON.stringify(u,null,2)));return[2,t]}return(null===(r=null===(n=null==e?void 0:e.get)||void 0===n?void 0:n.call(e,"content-type"))||void 0===r?void 0:r.includes("application/json"))?[4,P(t)]:[3,6];case 5:u=l.sent(),i(u),l.label=6;case 6:return[2,t]}})})},t.prototype.createModel=function(t,e){var n,r=we[t];if(r)n=new r(this.modelRequest,this.aiBaseUrl);else{var o="string"==typeof(null==e?void 0:e.defaultModelSubUrl)?e.defaultModelSubUrl:"/chat/completions";n=new Ct(this.modelRequest,this.aiBaseUrl,"".concat(t).concat(o))}return new Ht(n)},t.prototype.registerModel=function(t,e){null==we[t]?we[t]=e:console.warn("AI model ".concat(t," already exists!"))},t.prototype.createImageModel=function(t){return new Gt(this.modelRequest,this.aiBaseUrl,t)},t.prototype.registerFunctionTool=function(t){zt.has(t.name)&&console.warn("AI function tool ".concat(t.name," already exists and will be overwritten!")),zt.set(t.name,t.fn)},t.prototype.resolveUrl=function(t){if(!this._getBaseUrl)return t;var e=this._getBaseUrl();return e!==this.baseUrl&&t.startsWith(this.baseUrl)?t.replace(this.baseUrl,e):t},t}(),_e=function(){},Oe=function(){return Oe=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},Oe.apply(this,arguments)},je=function(t,e){var n={};for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&e.indexOf(r)<0&&(n[r]=t[r]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var o=0;for(r=Object.getOwnPropertySymbols(t);o<r.length;o++)e.indexOf(r[o])<0&&Object.prototype.propertyIsEnumerable.call(t,r[o])&&(n[r[o]]=t[r[o]])}return n},xe=je(s,["MODELS"]),ke=function(t){var e=t.getAccessToken,n=t.req;return{download:n.download,post:n.post,upload:n.upload,fetch:function(t){return r=void 0,o=void 0,a=function(){var r,o,i,a,u;return function(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:u(0),throw:u(1),return:u(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function u(u){return function(s){return function(u){if(n)throw new TypeError("Generator is already executing.");for(;i&&(i=0,u[0]&&(a=0)),a;)try{if(n=1,r&&(o=2&u[0]?r.return:u[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,u[1])).done)return o;switch(r=0,o&&(u=[2&u[0],o.value]),u[0]){case 0:case 1:o=u;break;case 4:return a.label++,{value:u[1],done:!1};case 5:a.label++,r=u[1],u=[0];continue;case 7:u=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==u[0]&&2!==u[0])){a=0;continue}if(3===u[0]&&(!o||u[1]>o[0]&&u[1]<o[3])){a.label=u[1];break}if(6===u[0]&&a.label<o[1]){a.label=o[1],o=u;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(u);break}o[2]&&a.ops.pop(),a.trys.pop();continue}u=e.call(t,a)}catch(t){u=[6,t],r=0}finally{n=o=0}if(5&u[0])throw u[1];return{value:u[0]?u[1]:void 0,done:!0}}([u,s])}}}(this,function(s){switch(s.label){case 0:if("function"!=typeof n.fetch)throw new Error("req.fetch is not a function");return r=t.token,o=t.headers,i=void 0===o?{}:o,a=je(t,["token","headers"]),null==r?[3,1]:(u=r,[3,3]);case 1:return[4,e()];case 2:u=s.sent().accessToken,s.label=3;case 3:return[2,n.fetch(Oe({headers:Oe({Authorization:"Bearer ".concat(u)},i)},a))]}})},new((i=void 0)||(i=Promise))(function(t,e){function n(t){try{s(a.next(t))}catch(t){e(t)}}function u(t){try{s(a.throw(t))}catch(t){e(t)}}function s(e){var r;e.done?t(e.value):(r=e.value,r instanceof i?r:new i(function(t){t(r)})).then(n,u)}s((a=a.apply(r,o||[])).next())});var r,o,i,a}}};function Pe(t){var e=t.env,n=t.baseUrl,r=t.getBaseUrl,o=t.req,i=t.getAccessToken,a=t.handleReqInstance,u=t.i18n;return new Se(function(){if(null==a){if(null==i)throw new Error("`getAccessToken` is required when `handleReqInstance` is not provided!");return ke({req:o,getAccessToken:i})}return a({req:o})}(),function(){if(null!=r)return r();if(null!=n)return n;if(null==e)throw new Error("`env` is required when `baseUrl` is not provided!");return"https://".concat(e,".api.tcloudbasegateway.com/v1")}(),u,r)}var Ue=Pe,qe={name:"ai",entity:{ai:function(t){var e=this,n=this.request;if(null==n.fetch)throw new Error("cloudbase.request.fetch() unimplemented!");var r=function(){var t=e.getEndPointWithKey("GATEWAY"),n=t.BASE_URL,r=t.PROTOCOL;return"".concat(r).concat(n)};return(null==t?void 0:t.baseUrl)?Pe({req:n,baseUrl:t.baseUrl,handleReqInstance:function(t){return t.req},i18n:this.config.i18n}):Pe({req:n,baseUrl:r(),getBaseUrl:r,handleReqInstance:function(t){return t.req},i18n:this.config.i18n})}}};function Ie(t){try{t.registerComponent(qe)}catch(t){console.warn(t)}}try{window.registerAi=Ie}catch(t){}var Te=a.AI,Re=a.rf,Ee=a.rT,Ae=a.pe,Ce=a.jE,Me=a.jM,Be=a.Cq,Ge=a.el,De=a.P6;export{Te as AI,Re as Bot,Ee as InvalidParamsError,Ae as SimpleChatModel,Ce as createAI,Me as createAi,Be as models,Ge as registerAi,De as utils};
2
+ //# sourceMappingURL=index.esm.js.map