mtmsdk 0.0.41 → 0.0.43

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 (480) hide show
  1. package/dist/cloud-account/platform-configs.d.ts +64 -0
  2. package/dist/cloud-account/platform-configs.d.ts.map +1 -0
  3. package/dist/cloud-account/platform-configs.js +44 -0
  4. package/dist/cloud-account/platform-configs.js.map +1 -0
  5. package/dist/{gomtmapi_v2 → gomtmapi}/@tanstack/react-query.gen.d.ts +202 -8
  6. package/dist/gomtmapi/@tanstack/react-query.gen.d.ts.map +1 -0
  7. package/dist/{gomtmapi_v2 → gomtmapi}/@tanstack/react-query.gen.js +300 -10
  8. package/dist/gomtmapi/@tanstack/react-query.gen.js.map +1 -0
  9. package/dist/{opencode → gomtmapi}/client/client.gen.d.ts.map +1 -1
  10. package/dist/{opencode → gomtmapi}/client/client.gen.js.map +1 -1
  11. package/dist/{opencode → gomtmapi}/client/index.d.ts.map +1 -1
  12. package/dist/{opencode → gomtmapi}/client/index.js.map +1 -1
  13. package/dist/{opencode → gomtmapi}/client/types.gen.d.ts.map +1 -1
  14. package/dist/gomtmapi/client/types.gen.js.map +1 -0
  15. package/dist/{opencode → gomtmapi}/client/utils.gen.d.ts.map +1 -1
  16. package/dist/{opencode → gomtmapi}/client/utils.gen.js.map +1 -1
  17. package/dist/{opencode → gomtmapi}/client.gen.d.ts.map +1 -1
  18. package/dist/{opencode → gomtmapi}/client.gen.js.map +1 -1
  19. package/dist/{opencode → gomtmapi}/core/auth.gen.d.ts.map +1 -1
  20. package/dist/{opencode → gomtmapi}/core/auth.gen.js.map +1 -1
  21. package/dist/{opencode → gomtmapi}/core/bodySerializer.gen.d.ts.map +1 -1
  22. package/dist/{opencode → gomtmapi}/core/bodySerializer.gen.js.map +1 -1
  23. package/dist/{opencode → gomtmapi}/core/params.gen.d.ts.map +1 -1
  24. package/dist/{opencode → gomtmapi}/core/params.gen.js.map +1 -1
  25. package/dist/{opencode → gomtmapi}/core/pathSerializer.gen.d.ts.map +1 -1
  26. package/dist/{opencode → gomtmapi}/core/pathSerializer.gen.js.map +1 -1
  27. package/dist/{opencode → gomtmapi}/core/queryKeySerializer.gen.d.ts.map +1 -1
  28. package/dist/{opencode → gomtmapi}/core/queryKeySerializer.gen.js.map +1 -1
  29. package/dist/{opencode → gomtmapi}/core/serverSentEvents.gen.d.ts.map +1 -1
  30. package/dist/{opencode → gomtmapi}/core/serverSentEvents.gen.js.map +1 -1
  31. package/dist/{opencode → gomtmapi}/core/types.gen.d.ts.map +1 -1
  32. package/dist/gomtmapi/core/types.gen.js.map +1 -0
  33. package/dist/{opencode → gomtmapi}/core/utils.gen.d.ts.map +1 -1
  34. package/dist/{opencode → gomtmapi}/core/utils.gen.js.map +1 -1
  35. package/dist/gomtmapi/index.d.ts +3 -0
  36. package/dist/gomtmapi/index.d.ts.map +1 -0
  37. package/dist/gomtmapi/index.js +3 -0
  38. package/dist/gomtmapi/index.js.map +1 -0
  39. package/dist/{gomtmapi_v2 → gomtmapi}/schemas.gen.d.ts +337 -50
  40. package/dist/gomtmapi/schemas.gen.d.ts.map +1 -0
  41. package/dist/{gomtmapi_v2 → gomtmapi}/schemas.gen.js +355 -50
  42. package/dist/gomtmapi/schemas.gen.js.map +1 -0
  43. package/dist/gomtmapi/sdk.gen.d.ts +378 -0
  44. package/dist/gomtmapi/sdk.gen.d.ts.map +1 -0
  45. package/dist/{gomtmapi_v2 → gomtmapi}/sdk.gen.js +234 -15
  46. package/dist/gomtmapi/sdk.gen.js.map +1 -0
  47. package/dist/{gomtmapi_v2 → gomtmapi}/types.gen.d.ts +494 -50
  48. package/dist/gomtmapi/types.gen.d.ts.map +1 -0
  49. package/dist/gomtmapi/types.gen.js.map +1 -0
  50. package/dist/{gomtmapi_v2 → gomtmapi}/zod.gen.d.ts +391 -45
  51. package/dist/gomtmapi/zod.gen.d.ts.map +1 -0
  52. package/dist/{gomtmapi_v2 → gomtmapi}/zod.gen.js +270 -31
  53. package/dist/gomtmapi/zod.gen.js.map +1 -0
  54. package/dist/lib/logger/index.d.ts +3 -0
  55. package/dist/lib/logger/index.d.ts.map +1 -1
  56. package/dist/lib/schema.d.ts +14 -2
  57. package/dist/lib/schema.d.ts.map +1 -1
  58. package/dist/lib/schema.js +1 -1
  59. package/dist/lib/schema.js.map +1 -1
  60. package/dist/mtgate_api/@tanstack/react-query.gen.d.ts +29 -1
  61. package/dist/mtgate_api/@tanstack/react-query.gen.d.ts.map +1 -1
  62. package/dist/mtgate_api/@tanstack/react-query.gen.js +17 -1
  63. package/dist/mtgate_api/@tanstack/react-query.gen.js.map +1 -1
  64. package/dist/mtgate_api/index.d.ts +2 -2
  65. package/dist/mtgate_api/index.d.ts.map +1 -1
  66. package/dist/mtgate_api/index.js +1 -1
  67. package/dist/mtgate_api/index.js.map +1 -1
  68. package/dist/mtgate_api/schemas.gen.d.ts +1 -0
  69. package/dist/mtgate_api/schemas.gen.d.ts.map +1 -1
  70. package/dist/mtgate_api/schemas.gen.js +8 -1
  71. package/dist/mtgate_api/schemas.gen.js.map +1 -1
  72. package/dist/mtgate_api/sdk.gen.d.ts +5 -1
  73. package/dist/mtgate_api/sdk.gen.d.ts.map +1 -1
  74. package/dist/mtgate_api/sdk.gen.js +4 -0
  75. package/dist/mtgate_api/sdk.gen.js.map +1 -1
  76. package/dist/mtgate_api/types.gen.d.ts +7 -1
  77. package/dist/mtgate_api/types.gen.d.ts.map +1 -1
  78. package/dist/mtgate_api/zod.gen.d.ts +26 -3
  79. package/dist/mtgate_api/zod.gen.d.ts.map +1 -1
  80. package/dist/mtgate_api/zod.gen.js +12 -1
  81. package/dist/mtgate_api/zod.gen.js.map +1 -1
  82. package/dist/openclaw/client-info.d.ts +56 -0
  83. package/dist/openclaw/client-info.d.ts.map +1 -0
  84. package/dist/openclaw/client-info.js +44 -0
  85. package/dist/openclaw/client-info.js.map +1 -0
  86. package/dist/openclaw/device-auth-utils.d.ts +13 -0
  87. package/dist/openclaw/device-auth-utils.d.ts.map +1 -0
  88. package/dist/openclaw/device-auth-utils.js +20 -0
  89. package/dist/openclaw/device-auth-utils.js.map +1 -0
  90. package/dist/openclaw/device-auth.d.ts +21 -0
  91. package/dist/openclaw/device-auth.d.ts.map +1 -0
  92. package/dist/openclaw/device-auth.js +84 -0
  93. package/dist/openclaw/device-auth.js.map +1 -0
  94. package/dist/openclaw/device-identity.d.ts +8 -0
  95. package/dist/openclaw/device-identity.d.ts.map +1 -0
  96. package/dist/openclaw/device-identity.js +87 -0
  97. package/dist/openclaw/device-identity.js.map +1 -0
  98. package/dist/openclaw/gateway.d.ts +86 -0
  99. package/dist/openclaw/gateway.d.ts.map +1 -0
  100. package/dist/openclaw/gateway.js +268 -0
  101. package/dist/openclaw/gateway.js.map +1 -0
  102. package/dist/openclaw/types.d.ts +473 -0
  103. package/dist/openclaw/types.d.ts.map +1 -0
  104. package/dist/openclaw/types.js +2 -0
  105. package/dist/openclaw/types.js.map +1 -0
  106. package/dist/openclaw/uuid.d.ts +6 -0
  107. package/dist/openclaw/uuid.d.ts.map +1 -0
  108. package/dist/openclaw/uuid.js +39 -0
  109. package/dist/openclaw/uuid.js.map +1 -0
  110. package/dist/sbapi/@tanstack/react-query.gen.d.ts +3251 -6
  111. package/dist/sbapi/@tanstack/react-query.gen.d.ts.map +1 -1
  112. package/dist/sbapi/@tanstack/react-query.gen.js +6050 -6
  113. package/dist/sbapi/@tanstack/react-query.gen.js.map +1 -1
  114. package/dist/sbapi/client.gen.d.ts.map +1 -1
  115. package/dist/sbapi/client.gen.js +1 -1
  116. package/dist/sbapi/client.gen.js.map +1 -1
  117. package/dist/sbapi/index.d.ts +2 -2
  118. package/dist/sbapi/index.d.ts.map +1 -1
  119. package/dist/sbapi/index.js +1 -1
  120. package/dist/sbapi/index.js.map +1 -1
  121. package/dist/sbapi/schemas.gen.d.ts +2320 -36
  122. package/dist/sbapi/schemas.gen.d.ts.map +1 -1
  123. package/dist/sbapi/schemas.gen.js +2593 -45
  124. package/dist/sbapi/schemas.gen.js.map +1 -1
  125. package/dist/sbapi/sdk.gen.d.ts +819 -2
  126. package/dist/sbapi/sdk.gen.d.ts.map +1 -1
  127. package/dist/sbapi/sdk.gen.js +2463 -1
  128. package/dist/sbapi/sdk.gen.js.map +1 -1
  129. package/dist/sbapi/types.gen.d.ts +11701 -29
  130. package/dist/sbapi/types.gen.d.ts.map +1 -1
  131. package/dist/sbapi/zod.gen.d.ts +8134 -26
  132. package/dist/sbapi/zod.gen.d.ts.map +1 -1
  133. package/dist/sbapi/zod.gen.js +6572 -18
  134. package/dist/sbapi/zod.gen.js.map +1 -1
  135. package/dist/sbmng/@tanstack/react-query.gen.d.ts +253 -157
  136. package/dist/sbmng/@tanstack/react-query.gen.d.ts.map +1 -1
  137. package/dist/sbmng/@tanstack/react-query.gen.js +241 -145
  138. package/dist/sbmng/@tanstack/react-query.gen.js.map +1 -1
  139. package/dist/sbmng/index.d.ts +2 -2
  140. package/dist/sbmng/index.d.ts.map +1 -1
  141. package/dist/sbmng/index.js +1 -1
  142. package/dist/sbmng/index.js.map +1 -1
  143. package/dist/sbmng/schemas.gen.d.ts +1035 -917
  144. package/dist/sbmng/schemas.gen.d.ts.map +1 -1
  145. package/dist/sbmng/schemas.gen.js +1219 -1067
  146. package/dist/sbmng/schemas.gen.js.map +1 -1
  147. package/dist/sbmng/sdk.gen.d.ts +62 -38
  148. package/dist/sbmng/sdk.gen.d.ts.map +1 -1
  149. package/dist/sbmng/sdk.gen.js +140 -84
  150. package/dist/sbmng/sdk.gen.js.map +1 -1
  151. package/dist/sbmng/types.gen.d.ts +1214 -991
  152. package/dist/sbmng/types.gen.d.ts.map +1 -1
  153. package/dist/supabase/auth-provider.d.ts +4 -0
  154. package/dist/supabase/auth-provider.d.ts.map +1 -0
  155. package/dist/supabase/auth-provider.js +45 -0
  156. package/dist/supabase/auth-provider.js.map +1 -0
  157. package/dist/supabase/cursor-pagination.d.ts +92 -0
  158. package/dist/supabase/cursor-pagination.d.ts.map +1 -0
  159. package/dist/supabase/cursor-pagination.js +116 -0
  160. package/dist/supabase/cursor-pagination.js.map +1 -0
  161. package/dist/supabase/schema/browser.d.ts.map +1 -0
  162. package/dist/supabase/schema/browser.js.map +1 -0
  163. package/dist/supabase/schema/index.d.ts +29 -0
  164. package/dist/supabase/schema/index.d.ts.map +1 -0
  165. package/dist/supabase/schema/index.js +38 -0
  166. package/dist/supabase/schema/index.js.map +1 -0
  167. package/dist/supabase/supabase-client.d.ts +1912 -1128
  168. package/dist/supabase/supabase-client.d.ts.map +1 -1
  169. package/dist/supabase/supabase.d.ts +4466 -2898
  170. package/dist/supabase/supabase.d.ts.map +1 -1
  171. package/dist/supabase/supabase.js +7 -4
  172. package/dist/supabase/supabase.js.map +1 -1
  173. package/dist/supabase/use-sb-query/use-query.d.ts +1 -1
  174. package/dist/supabase/use-sb-query/use-query.d.ts.map +1 -1
  175. package/dist/supabase/use-sb-query/use-query.js +2 -6
  176. package/dist/supabase/use-sb-query/use-query.js.map +1 -1
  177. package/dist/supabase/use-sb-query/use-rpc-mutation.d.ts +61 -0
  178. package/dist/supabase/use-sb-query/use-rpc-mutation.d.ts.map +1 -0
  179. package/dist/supabase/use-sb-query/use-rpc-mutation.js +63 -0
  180. package/dist/supabase/use-sb-query/use-rpc-mutation.js.map +1 -0
  181. package/dist/supabase/use-sb-query/use-rpc-query.d.ts +124 -0
  182. package/dist/supabase/use-sb-query/use-rpc-query.d.ts.map +1 -0
  183. package/dist/supabase/use-sb-query/use-rpc-query.js +91 -0
  184. package/dist/supabase/use-sb-query/use-rpc-query.js.map +1 -0
  185. package/dist/supabase/utils.d.ts +1 -1
  186. package/dist/supabase/utils.d.ts.map +1 -1
  187. package/dist/types/database.schemas.d.ts +3911 -0
  188. package/dist/types/database.schemas.d.ts.map +1 -0
  189. package/dist/types/database.schemas.js +3180 -0
  190. package/dist/types/database.schemas.js.map +1 -0
  191. package/dist/types/database.types.d.ts +1923 -1134
  192. package/dist/types/database.types.d.ts.map +1 -1
  193. package/dist/types/database.types.js +24 -0
  194. package/dist/types/database.types.js.map +1 -1
  195. package/dist/types/index.d.ts +47 -6
  196. package/dist/types/index.d.ts.map +1 -1
  197. package/dist/types/index.js +27 -1
  198. package/dist/types/index.js.map +1 -1
  199. package/dist/types/rpc.schemas.d.ts +64 -0
  200. package/dist/types/rpc.schemas.d.ts.map +1 -0
  201. package/dist/types/rpc.schemas.js +122 -0
  202. package/dist/types/rpc.schemas.js.map +1 -0
  203. package/package.json +48 -39
  204. package/src/adk/api/client.ts +46 -0
  205. package/src/adk/core/constants/tool-icons.ts +51 -0
  206. package/src/adk/core/models/AgentBuilder.ts +80 -0
  207. package/src/adk/core/models/AgentRunRequest.ts +33 -0
  208. package/src/adk/core/models/Eval.ts +70 -0
  209. package/src/adk/core/models/LiveRequest.ts +23 -0
  210. package/src/adk/core/models/RuntimeConfig.ts +33 -0
  211. package/src/adk/core/models/Session.ts +52 -0
  212. package/src/adk/core/models/Trace.ts +42 -0
  213. package/src/adk/core/models/types.ts +255 -0
  214. package/src/api_hatchet/@tanstack/react-query.gen.ts +3025 -0
  215. package/src/api_hatchet/client/client.gen.ts +311 -0
  216. package/src/api_hatchet/client/index.ts +25 -0
  217. package/src/api_hatchet/client/types.gen.ts +241 -0
  218. package/src/api_hatchet/client/utils.gen.ts +332 -0
  219. package/{dist/opencode/client.gen.d.ts → src/api_hatchet/client.gen.ts} +6 -3
  220. package/src/api_hatchet/core/auth.gen.ts +42 -0
  221. package/src/api_hatchet/core/bodySerializer.gen.ts +100 -0
  222. package/src/api_hatchet/core/params.gen.ts +176 -0
  223. package/src/api_hatchet/core/pathSerializer.gen.ts +181 -0
  224. package/src/api_hatchet/core/queryKeySerializer.gen.ts +136 -0
  225. package/src/api_hatchet/core/serverSentEvents.gen.ts +266 -0
  226. package/src/api_hatchet/core/types.gen.ts +118 -0
  227. package/src/api_hatchet/core/utils.gen.ts +143 -0
  228. package/src/api_hatchet/index.ts +4 -0
  229. package/src/api_hatchet/schemas.gen.ts +4961 -0
  230. package/src/api_hatchet/sdk.gen.ts +1994 -0
  231. package/src/api_hatchet/types.gen.ts +7688 -0
  232. package/src/api_hatchet/zod.gen.ts +3230 -0
  233. package/src/cloud-account/platform-configs.ts +73 -0
  234. package/src/gomtmapi/@tanstack/react-query.gen.ts +757 -0
  235. package/src/gomtmapi/client/client.gen.ts +311 -0
  236. package/src/gomtmapi/client/index.ts +25 -0
  237. package/src/gomtmapi/client/types.gen.ts +241 -0
  238. package/src/gomtmapi/client/utils.gen.ts +332 -0
  239. package/src/gomtmapi/client.gen.ts +16 -0
  240. package/src/gomtmapi/core/auth.gen.ts +42 -0
  241. package/src/gomtmapi/core/bodySerializer.gen.ts +100 -0
  242. package/src/gomtmapi/core/params.gen.ts +176 -0
  243. package/src/gomtmapi/core/pathSerializer.gen.ts +181 -0
  244. package/src/gomtmapi/core/queryKeySerializer.gen.ts +136 -0
  245. package/src/gomtmapi/core/serverSentEvents.gen.ts +266 -0
  246. package/src/gomtmapi/core/types.gen.ts +118 -0
  247. package/src/gomtmapi/core/utils.gen.ts +143 -0
  248. package/src/gomtmapi/index.ts +4 -0
  249. package/src/gomtmapi/schemas.gen.ts +904 -0
  250. package/src/gomtmapi/sdk.gen.ts +541 -0
  251. package/src/gomtmapi/types.gen.ts +1456 -0
  252. package/src/gomtmapi/zod.gen.ts +758 -0
  253. package/src/index.ts +5 -0
  254. package/src/lib/aisdk/types.ts +8 -0
  255. package/src/lib/logger/index.ts +8 -0
  256. package/src/lib/schema.ts +50 -0
  257. package/src/lib/utils.ts +54 -0
  258. package/src/mtgate_api/@tanstack/react-query.gen.ts +175 -0
  259. package/src/mtgate_api/client/client.gen.ts +311 -0
  260. package/src/mtgate_api/client/index.ts +25 -0
  261. package/src/mtgate_api/client/types.gen.ts +241 -0
  262. package/src/mtgate_api/client/utils.gen.ts +332 -0
  263. package/src/mtgate_api/client.gen.ts +16 -0
  264. package/src/mtgate_api/core/auth.gen.ts +42 -0
  265. package/src/mtgate_api/core/bodySerializer.gen.ts +100 -0
  266. package/src/mtgate_api/core/params.gen.ts +176 -0
  267. package/src/mtgate_api/core/pathSerializer.gen.ts +181 -0
  268. package/src/mtgate_api/core/queryKeySerializer.gen.ts +136 -0
  269. package/src/mtgate_api/core/serverSentEvents.gen.ts +266 -0
  270. package/src/mtgate_api/core/types.gen.ts +118 -0
  271. package/src/mtgate_api/core/utils.gen.ts +143 -0
  272. package/src/mtgate_api/index.ts +4 -0
  273. package/src/mtgate_api/schemas.gen.ts +337 -0
  274. package/src/mtgate_api/sdk.gen.ts +61 -0
  275. package/src/mtgate_api/types.gen.ts +324 -0
  276. package/src/mtgate_api/zod.gen.ts +234 -0
  277. package/src/mtmai_api/@tanstack/react-query.gen.ts +1010 -0
  278. package/src/mtmai_api/client/client.gen.ts +311 -0
  279. package/src/mtmai_api/client/index.ts +25 -0
  280. package/src/mtmai_api/client/types.gen.ts +241 -0
  281. package/src/mtmai_api/client/utils.gen.ts +332 -0
  282. package/src/mtmai_api/client.gen.ts +16 -0
  283. package/src/mtmai_api/core/auth.gen.ts +42 -0
  284. package/src/mtmai_api/core/bodySerializer.gen.ts +100 -0
  285. package/src/mtmai_api/core/params.gen.ts +176 -0
  286. package/src/mtmai_api/core/pathSerializer.gen.ts +181 -0
  287. package/src/mtmai_api/core/queryKeySerializer.gen.ts +136 -0
  288. package/src/mtmai_api/core/serverSentEvents.gen.ts +266 -0
  289. package/src/mtmai_api/core/types.gen.ts +118 -0
  290. package/src/mtmai_api/core/utils.gen.ts +143 -0
  291. package/src/mtmai_api/index.ts +4 -0
  292. package/src/mtmai_api/schemas.gen.ts +9980 -0
  293. package/src/mtmai_api/sdk.gen.ts +471 -0
  294. package/src/mtmai_api/types.gen.ts +7609 -0
  295. package/src/mtmai_api/zod.gen.ts +5101 -0
  296. package/src/openclaw/client-info.ts +63 -0
  297. package/src/openclaw/device-auth-utils.ts +31 -0
  298. package/src/openclaw/device-auth.ts +96 -0
  299. package/src/openclaw/device-identity.ts +108 -0
  300. package/src/openclaw/gateway.ts +351 -0
  301. package/src/openclaw/types.ts +518 -0
  302. package/src/openclaw/uuid.ts +48 -0
  303. package/src/sbapi/@tanstack/react-query.gen.ts +6591 -0
  304. package/src/sbapi/client/client.gen.ts +311 -0
  305. package/src/sbapi/client/index.ts +25 -0
  306. package/src/sbapi/client/types.gen.ts +241 -0
  307. package/src/sbapi/client/utils.gen.ts +332 -0
  308. package/src/sbapi/client.gen.ts +16 -0
  309. package/src/sbapi/core/auth.gen.ts +42 -0
  310. package/src/sbapi/core/bodySerializer.gen.ts +100 -0
  311. package/src/sbapi/core/params.gen.ts +176 -0
  312. package/src/sbapi/core/pathSerializer.gen.ts +181 -0
  313. package/src/sbapi/core/queryKeySerializer.gen.ts +136 -0
  314. package/src/sbapi/core/serverSentEvents.gen.ts +266 -0
  315. package/src/sbapi/core/types.gen.ts +118 -0
  316. package/src/sbapi/core/utils.gen.ts +143 -0
  317. package/src/sbapi/index.ts +4 -0
  318. package/src/sbapi/schemas.gen.ts +2643 -0
  319. package/src/sbapi/sdk.gen.ts +2822 -0
  320. package/src/sbapi/types.gen.ts +12503 -0
  321. package/src/sbapi/zod.gen.ts +7021 -0
  322. package/src/sbmng/@tanstack/react-query.gen.ts +2999 -0
  323. package/src/sbmng/client/client.gen.ts +311 -0
  324. package/src/sbmng/client/index.ts +25 -0
  325. package/src/sbmng/client/types.gen.ts +241 -0
  326. package/src/sbmng/client/utils.gen.ts +332 -0
  327. package/src/sbmng/client.gen.ts +16 -0
  328. package/src/sbmng/core/auth.gen.ts +42 -0
  329. package/src/sbmng/core/bodySerializer.gen.ts +100 -0
  330. package/src/sbmng/core/params.gen.ts +176 -0
  331. package/src/sbmng/core/pathSerializer.gen.ts +181 -0
  332. package/src/sbmng/core/queryKeySerializer.gen.ts +136 -0
  333. package/src/sbmng/core/serverSentEvents.gen.ts +266 -0
  334. package/src/sbmng/core/types.gen.ts +118 -0
  335. package/src/sbmng/core/utils.gen.ts +143 -0
  336. package/src/sbmng/index.ts +4 -0
  337. package/src/sbmng/schemas.gen.ts +9680 -0
  338. package/src/sbmng/sdk.gen.ts +1771 -0
  339. package/src/sbmng/types.gen.ts +7956 -0
  340. package/src/supabase/auth-provider.tsx +67 -0
  341. package/src/supabase/context.tsx +51 -0
  342. package/src/supabase/cursor-pagination.ts +155 -0
  343. package/src/supabase/schema/browser.ts +45 -0
  344. package/src/supabase/schema/index.ts +50 -0
  345. package/src/supabase/supabase-client.ts +30 -0
  346. package/src/supabase/supabase.ts +65 -0
  347. package/src/supabase/use-sb-query/build-query-opts.ts +56 -0
  348. package/src/supabase/use-sb-query/key.ts +57 -0
  349. package/src/supabase/use-sb-query/prefetch.ts +59 -0
  350. package/src/supabase/use-sb-query/use-query.ts +340 -0
  351. package/src/supabase/use-sb-query/use-rpc-mutation.ts +83 -0
  352. package/src/supabase/use-sb-query/use-rpc-query.ts +230 -0
  353. package/src/supabase/utils.ts +75 -0
  354. package/src/types/database.schemas.ts +3804 -0
  355. package/src/types/database.types.ts +3828 -0
  356. package/src/types/index.ts +119 -0
  357. package/src/types/rpc.schemas.ts +157 -0
  358. package/dist/gomtmapi_v2/@tanstack/react-query.gen.d.ts.map +0 -1
  359. package/dist/gomtmapi_v2/@tanstack/react-query.gen.js.map +0 -1
  360. package/dist/gomtmapi_v2/client/client.gen.d.ts.map +0 -1
  361. package/dist/gomtmapi_v2/client/client.gen.js.map +0 -1
  362. package/dist/gomtmapi_v2/client/index.d.ts.map +0 -1
  363. package/dist/gomtmapi_v2/client/index.js.map +0 -1
  364. package/dist/gomtmapi_v2/client/types.gen.d.ts.map +0 -1
  365. package/dist/gomtmapi_v2/client/types.gen.js.map +0 -1
  366. package/dist/gomtmapi_v2/client/utils.gen.d.ts.map +0 -1
  367. package/dist/gomtmapi_v2/client/utils.gen.js.map +0 -1
  368. package/dist/gomtmapi_v2/client.gen.d.ts.map +0 -1
  369. package/dist/gomtmapi_v2/client.gen.js.map +0 -1
  370. package/dist/gomtmapi_v2/core/auth.gen.d.ts.map +0 -1
  371. package/dist/gomtmapi_v2/core/auth.gen.js.map +0 -1
  372. package/dist/gomtmapi_v2/core/bodySerializer.gen.d.ts.map +0 -1
  373. package/dist/gomtmapi_v2/core/bodySerializer.gen.js.map +0 -1
  374. package/dist/gomtmapi_v2/core/params.gen.d.ts.map +0 -1
  375. package/dist/gomtmapi_v2/core/params.gen.js.map +0 -1
  376. package/dist/gomtmapi_v2/core/pathSerializer.gen.d.ts.map +0 -1
  377. package/dist/gomtmapi_v2/core/pathSerializer.gen.js.map +0 -1
  378. package/dist/gomtmapi_v2/core/queryKeySerializer.gen.d.ts.map +0 -1
  379. package/dist/gomtmapi_v2/core/queryKeySerializer.gen.js.map +0 -1
  380. package/dist/gomtmapi_v2/core/serverSentEvents.gen.d.ts.map +0 -1
  381. package/dist/gomtmapi_v2/core/serverSentEvents.gen.js.map +0 -1
  382. package/dist/gomtmapi_v2/core/types.gen.d.ts.map +0 -1
  383. package/dist/gomtmapi_v2/core/types.gen.js.map +0 -1
  384. package/dist/gomtmapi_v2/core/utils.gen.d.ts.map +0 -1
  385. package/dist/gomtmapi_v2/core/utils.gen.js.map +0 -1
  386. package/dist/gomtmapi_v2/index.d.ts +0 -3
  387. package/dist/gomtmapi_v2/index.d.ts.map +0 -1
  388. package/dist/gomtmapi_v2/index.js +0 -3
  389. package/dist/gomtmapi_v2/index.js.map +0 -1
  390. package/dist/gomtmapi_v2/schemas.gen.d.ts.map +0 -1
  391. package/dist/gomtmapi_v2/schemas.gen.js.map +0 -1
  392. package/dist/gomtmapi_v2/sdk.gen.d.ts +0 -208
  393. package/dist/gomtmapi_v2/sdk.gen.d.ts.map +0 -1
  394. package/dist/gomtmapi_v2/sdk.gen.js.map +0 -1
  395. package/dist/gomtmapi_v2/types.gen.d.ts.map +0 -1
  396. package/dist/gomtmapi_v2/types.gen.js.map +0 -1
  397. package/dist/gomtmapi_v2/zod.gen.d.ts.map +0 -1
  398. package/dist/gomtmapi_v2/zod.gen.js.map +0 -1
  399. package/dist/opencode/@tanstack/react-query.gen.d.ts +0 -1903
  400. package/dist/opencode/@tanstack/react-query.gen.d.ts.map +0 -1
  401. package/dist/opencode/@tanstack/react-query.gen.js +0 -1696
  402. package/dist/opencode/@tanstack/react-query.gen.js.map +0 -1
  403. package/dist/opencode/client/client.gen.d.ts +0 -3
  404. package/dist/opencode/client/client.gen.js +0 -236
  405. package/dist/opencode/client/index.d.ts +0 -9
  406. package/dist/opencode/client/index.js +0 -7
  407. package/dist/opencode/client/types.gen.d.ts +0 -118
  408. package/dist/opencode/client/types.gen.js +0 -3
  409. package/dist/opencode/client/types.gen.js.map +0 -1
  410. package/dist/opencode/client/utils.gen.d.ts +0 -34
  411. package/dist/opencode/client/utils.gen.js +0 -232
  412. package/dist/opencode/client.gen.js +0 -4
  413. package/dist/opencode/core/auth.gen.d.ts +0 -19
  414. package/dist/opencode/core/auth.gen.js +0 -15
  415. package/dist/opencode/core/bodySerializer.gen.d.ts +0 -26
  416. package/dist/opencode/core/bodySerializer.gen.js +0 -58
  417. package/dist/opencode/core/params.gen.d.ts +0 -44
  418. package/dist/opencode/core/params.gen.js +0 -101
  419. package/dist/opencode/core/pathSerializer.gen.d.ts +0 -34
  420. package/dist/opencode/core/pathSerializer.gen.js +0 -115
  421. package/dist/opencode/core/queryKeySerializer.gen.d.ts +0 -19
  422. package/dist/opencode/core/queryKeySerializer.gen.js +0 -100
  423. package/dist/opencode/core/serverSentEvents.gen.d.ts +0 -72
  424. package/dist/opencode/core/serverSentEvents.gen.js +0 -138
  425. package/dist/opencode/core/types.gen.d.ts +0 -79
  426. package/dist/opencode/core/types.gen.js +0 -3
  427. package/dist/opencode/core/types.gen.js.map +0 -1
  428. package/dist/opencode/core/utils.gen.d.ts +0 -20
  429. package/dist/opencode/core/utils.gen.js +0 -88
  430. package/dist/opencode/index.d.ts +0 -3
  431. package/dist/opencode/index.d.ts.map +0 -1
  432. package/dist/opencode/index.js +0 -4
  433. package/dist/opencode/index.js.map +0 -1
  434. package/dist/opencode/schemas.gen.d.ts +0 -4823
  435. package/dist/opencode/schemas.gen.d.ts.map +0 -1
  436. package/dist/opencode/schemas.gen.js +0 -5816
  437. package/dist/opencode/schemas.gen.js.map +0 -1
  438. package/dist/opencode/sdk.gen.d.ts +0 -562
  439. package/dist/opencode/sdk.gen.d.ts.map +0 -1
  440. package/dist/opencode/sdk.gen.js +0 -766
  441. package/dist/opencode/sdk.gen.js.map +0 -1
  442. package/dist/opencode/types.gen.d.ts +0 -4213
  443. package/dist/opencode/types.gen.d.ts.map +0 -1
  444. package/dist/opencode/types.gen.js +0 -25
  445. package/dist/opencode/types.gen.js.map +0 -1
  446. package/dist/opencode/zod.gen.d.ts +0 -17243
  447. package/dist/opencode/zod.gen.d.ts.map +0 -1
  448. package/dist/opencode/zod.gen.js +0 -2876
  449. package/dist/opencode/zod.gen.js.map +0 -1
  450. package/dist/schema/browser.d.ts.map +0 -1
  451. package/dist/schema/browser.js.map +0 -1
  452. /package/dist/{gomtmapi_v2 → gomtmapi}/client/client.gen.d.ts +0 -0
  453. /package/dist/{gomtmapi_v2 → gomtmapi}/client/client.gen.js +0 -0
  454. /package/dist/{gomtmapi_v2 → gomtmapi}/client/index.d.ts +0 -0
  455. /package/dist/{gomtmapi_v2 → gomtmapi}/client/index.js +0 -0
  456. /package/dist/{gomtmapi_v2 → gomtmapi}/client/types.gen.d.ts +0 -0
  457. /package/dist/{gomtmapi_v2 → gomtmapi}/client/types.gen.js +0 -0
  458. /package/dist/{gomtmapi_v2 → gomtmapi}/client/utils.gen.d.ts +0 -0
  459. /package/dist/{gomtmapi_v2 → gomtmapi}/client/utils.gen.js +0 -0
  460. /package/dist/{gomtmapi_v2 → gomtmapi}/client.gen.d.ts +0 -0
  461. /package/dist/{gomtmapi_v2 → gomtmapi}/client.gen.js +0 -0
  462. /package/dist/{gomtmapi_v2 → gomtmapi}/core/auth.gen.d.ts +0 -0
  463. /package/dist/{gomtmapi_v2 → gomtmapi}/core/auth.gen.js +0 -0
  464. /package/dist/{gomtmapi_v2 → gomtmapi}/core/bodySerializer.gen.d.ts +0 -0
  465. /package/dist/{gomtmapi_v2 → gomtmapi}/core/bodySerializer.gen.js +0 -0
  466. /package/dist/{gomtmapi_v2 → gomtmapi}/core/params.gen.d.ts +0 -0
  467. /package/dist/{gomtmapi_v2 → gomtmapi}/core/params.gen.js +0 -0
  468. /package/dist/{gomtmapi_v2 → gomtmapi}/core/pathSerializer.gen.d.ts +0 -0
  469. /package/dist/{gomtmapi_v2 → gomtmapi}/core/pathSerializer.gen.js +0 -0
  470. /package/dist/{gomtmapi_v2 → gomtmapi}/core/queryKeySerializer.gen.d.ts +0 -0
  471. /package/dist/{gomtmapi_v2 → gomtmapi}/core/queryKeySerializer.gen.js +0 -0
  472. /package/dist/{gomtmapi_v2 → gomtmapi}/core/serverSentEvents.gen.d.ts +0 -0
  473. /package/dist/{gomtmapi_v2 → gomtmapi}/core/serverSentEvents.gen.js +0 -0
  474. /package/dist/{gomtmapi_v2 → gomtmapi}/core/types.gen.d.ts +0 -0
  475. /package/dist/{gomtmapi_v2 → gomtmapi}/core/types.gen.js +0 -0
  476. /package/dist/{gomtmapi_v2 → gomtmapi}/core/utils.gen.d.ts +0 -0
  477. /package/dist/{gomtmapi_v2 → gomtmapi}/core/utils.gen.js +0 -0
  478. /package/dist/{gomtmapi_v2 → gomtmapi}/types.gen.js +0 -0
  479. /package/dist/{schema → supabase/schema}/browser.d.ts +0 -0
  480. /package/dist/{schema → supabase/schema}/browser.js +0 -0
@@ -0,0 +1,63 @@
1
+ export const GATEWAY_CLIENT_IDS = {
2
+ WEBCHAT_UI: "webchat-ui",
3
+ CONTROL_UI: "openclaw-control-ui",
4
+ WEBCHAT: "webchat",
5
+ CLI: "cli",
6
+ GATEWAY_CLIENT: "gateway-client",
7
+ MACOS_APP: "openclaw-macos",
8
+ IOS_APP: "openclaw-ios",
9
+ ANDROID_APP: "openclaw-android",
10
+ NODE_HOST: "node-host",
11
+ TEST: "test",
12
+ FINGERPRINT: "fingerprint",
13
+ PROBE: "openclaw-probe",
14
+ CLAWDBOT_CONTROL_UI: "clawdbot-control-ui",
15
+ } as const;
16
+
17
+ export type GatewayClientId = (typeof GATEWAY_CLIENT_IDS)[keyof typeof GATEWAY_CLIENT_IDS];
18
+
19
+ // Back-compat naming (internal): these values are IDs, not display names.
20
+ export const GATEWAY_CLIENT_NAMES = GATEWAY_CLIENT_IDS;
21
+ export type GatewayClientName = GatewayClientId;
22
+
23
+ export const GATEWAY_CLIENT_MODES = {
24
+ WEBCHAT: "webchat",
25
+ CLI: "cli",
26
+ UI: "ui",
27
+ BACKEND: "backend",
28
+ NODE: "node",
29
+ PROBE: "probe",
30
+ TEST: "test",
31
+ } as const;
32
+
33
+ export type GatewayClientMode = (typeof GATEWAY_CLIENT_MODES)[keyof typeof GATEWAY_CLIENT_MODES];
34
+
35
+ export type GatewayClientInfo = {
36
+ id: GatewayClientId;
37
+ displayName?: string;
38
+ version: string;
39
+ platform: string;
40
+ deviceFamily?: string;
41
+ modelIdentifier?: string;
42
+ mode: GatewayClientMode;
43
+ instanceId?: string;
44
+ };
45
+
46
+ const GATEWAY_CLIENT_ID_SET = new Set<GatewayClientId>(Object.values(GATEWAY_CLIENT_IDS));
47
+ const GATEWAY_CLIENT_MODE_SET = new Set<GatewayClientMode>(Object.values(GATEWAY_CLIENT_MODES));
48
+
49
+ export function normalizeGatewayClientId(raw?: string | null): GatewayClientId | undefined {
50
+ const normalized = raw?.trim().toLowerCase();
51
+ if (!normalized) return undefined;
52
+ return GATEWAY_CLIENT_ID_SET.has(normalized as GatewayClientId) ? (normalized as GatewayClientId) : undefined;
53
+ }
54
+
55
+ export function normalizeGatewayClientName(raw?: string | null): GatewayClientName | undefined {
56
+ return normalizeGatewayClientId(raw);
57
+ }
58
+
59
+ export function normalizeGatewayClientMode(raw?: string | null): GatewayClientMode | undefined {
60
+ const normalized = raw?.trim().toLowerCase();
61
+ if (!normalized) return undefined;
62
+ return GATEWAY_CLIENT_MODE_SET.has(normalized as GatewayClientMode) ? (normalized as GatewayClientMode) : undefined;
63
+ }
@@ -0,0 +1,31 @@
1
+ export interface DeviceAuthPayloadParams {
2
+ version?: string;
3
+ nonce?: string;
4
+ scopes: string[];
5
+ token?: string;
6
+ deviceId: string;
7
+ clientId: string;
8
+ clientMode: string;
9
+ role: string;
10
+ signedAtMs: number;
11
+ }
12
+
13
+ export function buildDeviceAuthPayload(params: DeviceAuthPayloadParams) {
14
+ const version = params.version ?? (params.nonce ? "v2" : "v1");
15
+ const scopes = params.scopes.join(",");
16
+ const token = params.token ?? "";
17
+ const base = [
18
+ version,
19
+ params.deviceId,
20
+ params.clientId,
21
+ params.clientMode,
22
+ params.role,
23
+ scopes,
24
+ String(params.signedAtMs),
25
+ token,
26
+ ];
27
+ if (version === "v2") {
28
+ base.push(params.nonce ?? "");
29
+ }
30
+ return base.join("|");
31
+ }
@@ -0,0 +1,96 @@
1
+ export type DeviceAuthEntry = {
2
+ token: string;
3
+ role: string;
4
+ scopes: string[];
5
+ updatedAtMs: number;
6
+ };
7
+
8
+ type DeviceAuthStore = {
9
+ version: 1;
10
+ deviceId: string;
11
+ tokens: Record<string, DeviceAuthEntry>;
12
+ };
13
+
14
+ const STORAGE_KEY = "moltbot.device.auth.v1";
15
+
16
+ function normalizeRole(role: string): string {
17
+ return role.trim();
18
+ }
19
+
20
+ function normalizeScopes(scopes: string[] | undefined): string[] {
21
+ if (!Array.isArray(scopes)) return [];
22
+ const out = new Set<string>();
23
+ for (const scope of scopes) {
24
+ const trimmed = scope.trim();
25
+ if (trimmed) out.add(trimmed);
26
+ }
27
+ return [...out].sort();
28
+ }
29
+
30
+ function readStore(): DeviceAuthStore | null {
31
+ try {
32
+ const raw = window.localStorage.getItem(STORAGE_KEY);
33
+ if (!raw) return null;
34
+ const parsed = JSON.parse(raw) as DeviceAuthStore;
35
+ if (!parsed || parsed.version !== 1) return null;
36
+ if (!parsed.deviceId || typeof parsed.deviceId !== "string") return null;
37
+ if (!parsed.tokens || typeof parsed.tokens !== "object") return null;
38
+ return parsed;
39
+ } catch {
40
+ return null;
41
+ }
42
+ }
43
+
44
+ function writeStore(store: DeviceAuthStore) {
45
+ try {
46
+ window.localStorage.setItem(STORAGE_KEY, JSON.stringify(store));
47
+ } catch {
48
+ // best-effort
49
+ }
50
+ }
51
+
52
+ export function loadDeviceAuthToken(params: { deviceId: string; role: string }): DeviceAuthEntry | null {
53
+ const store = readStore();
54
+ if (!store || store.deviceId !== params.deviceId) return null;
55
+ const role = normalizeRole(params.role);
56
+ const entry = store.tokens[role];
57
+ if (!entry || typeof entry.token !== "string") return null;
58
+ return entry;
59
+ }
60
+
61
+ export function storeDeviceAuthToken(params: {
62
+ deviceId: string;
63
+ role: string;
64
+ token: string;
65
+ scopes?: string[];
66
+ }): DeviceAuthEntry {
67
+ const role = normalizeRole(params.role);
68
+ const next: DeviceAuthStore = {
69
+ version: 1,
70
+ deviceId: params.deviceId,
71
+ tokens: {},
72
+ };
73
+ const existing = readStore();
74
+ if (existing && existing.deviceId === params.deviceId) {
75
+ next.tokens = { ...existing.tokens };
76
+ }
77
+ const entry: DeviceAuthEntry = {
78
+ token: params.token,
79
+ role,
80
+ scopes: normalizeScopes(params.scopes),
81
+ updatedAtMs: Date.now(),
82
+ };
83
+ next.tokens[role] = entry;
84
+ writeStore(next);
85
+ return entry;
86
+ }
87
+
88
+ export function clearDeviceAuthToken(params: { deviceId: string; role: string }) {
89
+ const store = readStore();
90
+ if (!store || store.deviceId !== params.deviceId) return;
91
+ const role = normalizeRole(params.role);
92
+ if (!store.tokens[role]) return;
93
+ const next = { ...store, tokens: { ...store.tokens } };
94
+ delete next.tokens[role];
95
+ writeStore(next);
96
+ }
@@ -0,0 +1,108 @@
1
+ import { getPublicKeyAsync, signAsync, utils } from "@noble/ed25519";
2
+
3
+ type StoredIdentity = {
4
+ version: 1;
5
+ deviceId: string;
6
+ publicKey: string;
7
+ privateKey: string;
8
+ createdAtMs: number;
9
+ };
10
+
11
+ export type DeviceIdentity = {
12
+ deviceId: string;
13
+ publicKey: string;
14
+ privateKey: string;
15
+ };
16
+
17
+ const STORAGE_KEY = "moltbot-device-identity-v1";
18
+
19
+ function base64UrlEncode(bytes: Uint8Array): string {
20
+ let binary = "";
21
+ for (const byte of bytes) binary += String.fromCharCode(byte);
22
+ return btoa(binary).replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/g, "");
23
+ }
24
+
25
+ function base64UrlDecode(input: string): Uint8Array {
26
+ const normalized = input.replaceAll("-", "+").replaceAll("_", "/");
27
+ const padded = normalized + "=".repeat((4 - (normalized.length % 4)) % 4);
28
+ const binary = atob(padded);
29
+ const out = new Uint8Array(binary.length);
30
+ for (let i = 0; i < binary.length; i += 1) out[i] = binary.charCodeAt(i);
31
+ return out;
32
+ }
33
+
34
+ function bytesToHex(bytes: Uint8Array): string {
35
+ return Array.from(bytes)
36
+ .map((b) => b.toString(16).padStart(2, "0"))
37
+ .join("");
38
+ }
39
+
40
+ async function fingerprintPublicKey(publicKey: Uint8Array): Promise<string> {
41
+ const hash = await crypto.subtle.digest("SHA-256", publicKey as unknown as BufferSource);
42
+ return bytesToHex(new Uint8Array(hash));
43
+ }
44
+
45
+ async function generateIdentity(): Promise<DeviceIdentity> {
46
+ const privateKey = utils.randomSecretKey();
47
+ const publicKey = await getPublicKeyAsync(privateKey);
48
+ const deviceId = await fingerprintPublicKey(publicKey);
49
+ return {
50
+ deviceId,
51
+ publicKey: base64UrlEncode(publicKey),
52
+ privateKey: base64UrlEncode(privateKey),
53
+ };
54
+ }
55
+
56
+ export async function loadOrCreateDeviceIdentity(): Promise<DeviceIdentity> {
57
+ try {
58
+ const raw = localStorage.getItem(STORAGE_KEY);
59
+ if (raw) {
60
+ const parsed = JSON.parse(raw) as StoredIdentity;
61
+ if (
62
+ parsed?.version === 1 &&
63
+ typeof parsed.deviceId === "string" &&
64
+ typeof parsed.publicKey === "string" &&
65
+ typeof parsed.privateKey === "string"
66
+ ) {
67
+ const derivedId = await fingerprintPublicKey(base64UrlDecode(parsed.publicKey));
68
+ if (derivedId !== parsed.deviceId) {
69
+ const updated: StoredIdentity = {
70
+ ...parsed,
71
+ deviceId: derivedId,
72
+ };
73
+ localStorage.setItem(STORAGE_KEY, JSON.stringify(updated));
74
+ return {
75
+ deviceId: derivedId,
76
+ publicKey: parsed.publicKey,
77
+ privateKey: parsed.privateKey,
78
+ };
79
+ }
80
+ return {
81
+ deviceId: parsed.deviceId,
82
+ publicKey: parsed.publicKey,
83
+ privateKey: parsed.privateKey,
84
+ };
85
+ }
86
+ }
87
+ } catch {
88
+ // fall through to regenerate
89
+ }
90
+
91
+ const identity = await generateIdentity();
92
+ const stored: StoredIdentity = {
93
+ version: 1,
94
+ deviceId: identity.deviceId,
95
+ publicKey: identity.publicKey,
96
+ privateKey: identity.privateKey,
97
+ createdAtMs: Date.now(),
98
+ };
99
+ localStorage.setItem(STORAGE_KEY, JSON.stringify(stored));
100
+ return identity;
101
+ }
102
+
103
+ export async function signDevicePayload(privateKeyBase64Url: string, payload: string) {
104
+ const key = base64UrlDecode(privateKeyBase64Url);
105
+ const data = new TextEncoder().encode(payload);
106
+ const sig = await signAsync(data, key);
107
+ return base64UrlEncode(sig);
108
+ }
@@ -0,0 +1,351 @@
1
+ import {
2
+ GATEWAY_CLIENT_MODES,
3
+ GATEWAY_CLIENT_NAMES,
4
+ type GatewayClientMode,
5
+ type GatewayClientName,
6
+ } from "./client-info";
7
+ import { generateUUID } from "./uuid";
8
+
9
+ export type GatewayEventFrame = {
10
+ type: "event";
11
+ event: string;
12
+ payload?: unknown;
13
+ seq?: number;
14
+ stateVersion?: { presence: number; health: number };
15
+ };
16
+
17
+ export type GatewayResponseFrame = {
18
+ type: "res";
19
+ id: string;
20
+ ok: boolean;
21
+ payload?: unknown;
22
+ error?: { code: string; message: string; details?: unknown };
23
+ };
24
+
25
+ export type GatewayHelloOk = {
26
+ type: "hello-ok";
27
+ protocol: number;
28
+ features?: { methods?: string[]; events?: string[] };
29
+ snapshot?: unknown;
30
+ auth?: {
31
+ deviceToken?: string;
32
+ role?: string;
33
+ scopes?: string[];
34
+ issuedAtMs?: number;
35
+ };
36
+ policy?: { tickIntervalMs?: number };
37
+ };
38
+
39
+ type Pending = {
40
+ resolve: (value: unknown) => void;
41
+ reject: (err: unknown) => void;
42
+ };
43
+
44
+ export type GatewayBrowserClientOptions = {
45
+ url: string;
46
+ password?: string;
47
+ clientName?: GatewayClientName;
48
+ clientVersion?: string;
49
+ platform?: string;
50
+ mode?: GatewayClientMode;
51
+ instanceId?: string;
52
+ onHello?: (hello: GatewayHelloOk) => void;
53
+ onEvent?: (evt: GatewayEventFrame) => void;
54
+ onClose?: (info: { code: number; reason: string }) => void;
55
+ onGap?: (info: { expected: number; received: number }) => void;
56
+ autoReconnect?: boolean;
57
+ disableDeviceAuth?: boolean;
58
+ supabaseToken?: string;
59
+ skipConnectHandshake?: boolean;
60
+ };
61
+
62
+ // 4008 = application-defined code (browser rejects 1008 "Policy Violation")
63
+ const CONNECT_FAILED_CLOSE_CODE = 4008;
64
+
65
+ export class GatewayBrowserClient {
66
+ private ws: WebSocket | null = null;
67
+ private pending = new Map<string, Pending>();
68
+ private closed = false;
69
+ private lastSeq: number | null = null;
70
+ private connectNonce: string | null = null;
71
+ private connectSent = false;
72
+ private connectTimer: number | null = null;
73
+ private backoffMs = 800;
74
+
75
+ constructor(private opts: GatewayBrowserClientOptions) {}
76
+
77
+ start() {
78
+ this.closed = false;
79
+ this.connect();
80
+ }
81
+
82
+ stop() {
83
+ this.closed = true;
84
+ this.ws?.close();
85
+ this.ws = null;
86
+ this.flushPending(new Error("gateway client stopped"));
87
+ }
88
+
89
+ get connected() {
90
+ return this.ws?.readyState === WebSocket.OPEN;
91
+ }
92
+
93
+ private connect() {
94
+ if (this.closed) return;
95
+ try {
96
+ const protocols: string[] = [];
97
+ if (this.opts.supabaseToken) {
98
+ protocols.push(`sb_token.${this.opts.supabaseToken}`);
99
+ }
100
+
101
+ this.ws = new WebSocket(this.opts.url, protocols.length > 0 ? protocols : undefined);
102
+ this.ws.onopen = () => this.queueConnect();
103
+ this.ws.onmessage = (ev) => this.handleMessage(String(ev.data ?? ""));
104
+ this.ws.onclose = (ev) => {
105
+ const reason = String(ev.reason ?? "");
106
+ this.ws = null;
107
+ this.flushPending(new Error(`gateway closed (${ev.code}): ${reason}`));
108
+ this.opts.onClose?.({ code: ev.code, reason });
109
+ this.scheduleReconnect();
110
+ };
111
+ this.ws.onerror = () => {
112
+ // ignored; close handler will fire
113
+ };
114
+ } catch (err) {
115
+ console.error("[gateway] Failed to create WebSocket instance:", err);
116
+ // Simulate a close event for the UI to handle
117
+ this.opts.onClose?.({
118
+ code: 1006,
119
+ reason: err instanceof Error ? err.message : "Connect failed",
120
+ });
121
+ this.scheduleReconnect();
122
+ }
123
+ }
124
+
125
+ private scheduleReconnect() {
126
+ if (this.closed || this.opts.autoReconnect === false) return;
127
+ const delay = this.backoffMs;
128
+ this.backoffMs = Math.min(this.backoffMs * 1.7, 15_000);
129
+ window.setTimeout(() => this.connect(), delay);
130
+ }
131
+
132
+ private flushPending(err: Error) {
133
+ for (const [, p] of this.pending) p.reject(err);
134
+ this.pending.clear();
135
+ }
136
+
137
+ private async sendConnect() {
138
+ if (this.connectSent) return;
139
+ this.connectSent = true;
140
+ if (this.connectTimer !== null) {
141
+ window.clearTimeout(this.connectTimer);
142
+ this.connectTimer = null;
143
+ }
144
+ const { disableDeviceAuth } = this.opts;
145
+
146
+ const isSecureContext = typeof crypto !== "undefined" && !!crypto.subtle;
147
+
148
+ const scopes = ["operator.admin", "operator.approvals", "operator.pairing"];
149
+ const role = "operator";
150
+
151
+ // Dynamic import types for correct typing
152
+ type DeviceIdentityLib = typeof import("./device-identity");
153
+ let deviceIdentity: Awaited<ReturnType<DeviceIdentityLib["loadOrCreateDeviceIdentity"]>> | null = null;
154
+ let authToken: string | undefined;
155
+
156
+ // Dynamically import device auth logic only if needed and in secure context
157
+ if (!disableDeviceAuth && isSecureContext) {
158
+ try {
159
+ const { loadOrCreateDeviceIdentity } = await import("./device-identity");
160
+ const { loadDeviceAuthToken } = await import("./device-auth");
161
+
162
+ deviceIdentity = await loadOrCreateDeviceIdentity();
163
+ authToken = loadDeviceAuthToken({
164
+ deviceId: deviceIdentity.deviceId,
165
+ role,
166
+ })?.token;
167
+ } catch (e) {
168
+ console.warn("[gateway] Failed to load device identity libs", e);
169
+ }
170
+ }
171
+
172
+ const auth =
173
+ authToken || this.opts.password
174
+ ? {
175
+ token: authToken,
176
+ password: this.opts.password,
177
+ }
178
+ : undefined;
179
+
180
+ let device:
181
+ | {
182
+ id: string;
183
+ publicKey: string;
184
+ signature: string;
185
+ signedAt: number;
186
+ nonce: string | undefined;
187
+ }
188
+ | undefined;
189
+
190
+ if (!disableDeviceAuth && isSecureContext && deviceIdentity) {
191
+ const signedAtMs = Date.now();
192
+ const nonce = this.connectNonce ?? undefined;
193
+
194
+ try {
195
+ const { buildDeviceAuthPayload } = await import("./device-auth-utils");
196
+ const { signDevicePayload } = await import("./device-identity");
197
+
198
+ const payload = buildDeviceAuthPayload({
199
+ deviceId: deviceIdentity.deviceId,
200
+ clientId: this.opts.clientName ?? GATEWAY_CLIENT_NAMES.CONTROL_UI,
201
+ clientMode: this.opts.mode ?? GATEWAY_CLIENT_MODES.WEBCHAT,
202
+ role,
203
+ scopes,
204
+ signedAtMs,
205
+ token: authToken ?? undefined,
206
+ nonce,
207
+ });
208
+ const signature = await signDevicePayload(deviceIdentity.privateKey, payload);
209
+ device = {
210
+ id: deviceIdentity.deviceId,
211
+ publicKey: deviceIdentity.publicKey,
212
+ signature,
213
+ signedAt: signedAtMs,
214
+ nonce,
215
+ };
216
+ } catch (e) {
217
+ console.error("[gateway] Failed to sign device payload", e);
218
+ }
219
+ }
220
+
221
+ const params = {
222
+ minProtocol: 3,
223
+ maxProtocol: 3,
224
+ client: {
225
+ id: this.opts.clientName ?? GATEWAY_CLIENT_NAMES.CONTROL_UI,
226
+ version: this.opts.clientVersion ?? "dev",
227
+ platform: this.opts.platform ?? navigator.platform ?? "web",
228
+ mode: this.opts.mode ?? GATEWAY_CLIENT_MODES.WEBCHAT,
229
+ instanceId: this.opts.instanceId,
230
+ },
231
+ role,
232
+ scopes,
233
+ device,
234
+ caps: [],
235
+ auth,
236
+ userAgent: navigator.userAgent,
237
+ locale: navigator.language,
238
+ };
239
+
240
+ void this.request<GatewayHelloOk>("connect", params)
241
+ .then(async (hello) => {
242
+ if (!disableDeviceAuth && hello?.auth?.deviceToken && deviceIdentity) {
243
+ try {
244
+ const { storeDeviceAuthToken } = await import("./device-auth");
245
+ storeDeviceAuthToken({
246
+ deviceId: deviceIdentity.deviceId,
247
+ role: hello.auth.role ?? role,
248
+ token: hello.auth.deviceToken,
249
+ scopes: hello.auth.scopes ?? [],
250
+ });
251
+ } catch (e) {
252
+ console.warn("[gateway] Failed to store device token", e);
253
+ }
254
+ }
255
+ this.backoffMs = 800;
256
+ this.opts.onHello?.(hello);
257
+ })
258
+ .catch((err) => {
259
+ console.warn("[gateway] connect seq failed", err);
260
+ // Do not close here, let the interval handle it or the error event?
261
+ // Original code closed it.
262
+ this.ws?.close(CONNECT_FAILED_CLOSE_CODE, "connect failed");
263
+ });
264
+ }
265
+
266
+ private handleMessage(raw: string) {
267
+ let parsed: unknown;
268
+ try {
269
+ parsed = JSON.parse(raw);
270
+ } catch {
271
+ return;
272
+ }
273
+
274
+ const frame = parsed as { type?: unknown };
275
+ if (frame.type === "event") {
276
+ const evt = parsed as GatewayEventFrame;
277
+
278
+ // Handle Proxy Handshake Event
279
+ if (evt.event === "sys.proxy_hello") {
280
+ this.backoffMs = 800;
281
+ const hello = (evt.payload as GatewayHelloOk) || {
282
+ type: "hello-ok",
283
+ protocol: 3,
284
+ features: { methods: [], events: [] },
285
+ };
286
+ this.opts.onHello?.(hello);
287
+ return;
288
+ }
289
+
290
+ if (evt.event === "connect.challenge") {
291
+ const payload = evt.payload as { nonce?: unknown } | undefined;
292
+ const nonce = payload && typeof payload.nonce === "string" ? payload.nonce : null;
293
+ if (nonce) {
294
+ this.connectNonce = nonce;
295
+ void this.sendConnect();
296
+ }
297
+ return;
298
+ }
299
+ const seq = typeof evt.seq === "number" ? evt.seq : null;
300
+ if (seq !== null) {
301
+ if (this.lastSeq !== null && seq > this.lastSeq + 1) {
302
+ this.opts.onGap?.({ expected: this.lastSeq + 1, received: seq });
303
+ }
304
+ this.lastSeq = seq;
305
+ }
306
+ try {
307
+ this.opts.onEvent?.(evt);
308
+ } catch (err) {
309
+ console.error("[gateway] event handler error:", err);
310
+ }
311
+ return;
312
+ }
313
+
314
+ if (frame.type === "res") {
315
+ const res = parsed as GatewayResponseFrame;
316
+ const pending = this.pending.get(res.id);
317
+ if (!pending) return;
318
+ this.pending.delete(res.id);
319
+ if (res.ok) pending.resolve(res.payload);
320
+ else pending.reject(new Error(res.error?.message ?? "request failed"));
321
+ return;
322
+ }
323
+ }
324
+
325
+ request<T = unknown>(method: string, params?: unknown): Promise<T> {
326
+ if (!this.ws || this.ws.readyState !== WebSocket.OPEN) {
327
+ return Promise.reject(new Error("gateway not connected"));
328
+ }
329
+ const id = generateUUID();
330
+ const frame = { type: "req", id, method, params };
331
+ const p = new Promise<T>((resolve, reject) => {
332
+ this.pending.set(id, { resolve: (v) => resolve(v as T), reject });
333
+ });
334
+ this.ws.send(JSON.stringify(frame));
335
+ return p;
336
+ }
337
+
338
+ private queueConnect() {
339
+ this.connectNonce = null;
340
+ this.connectSent = false;
341
+ if (this.connectTimer !== null) window.clearTimeout(this.connectTimer);
342
+
343
+ if (this.opts.skipConnectHandshake) {
344
+ return;
345
+ }
346
+
347
+ this.connectTimer = window.setTimeout(() => {
348
+ void this.sendConnect();
349
+ }, 750);
350
+ }
351
+ }