@vertesia/client 0.24.0-dev.202601221707

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 (339) hide show
  1. package/LICENSE +13 -0
  2. package/README.md +110 -0
  3. package/lib/cjs/AccountApi.js +85 -0
  4. package/lib/cjs/AccountApi.js.map +1 -0
  5. package/lib/cjs/AccountsApi.js +16 -0
  6. package/lib/cjs/AccountsApi.js.map +1 -0
  7. package/lib/cjs/AnalyticsApi.js +41 -0
  8. package/lib/cjs/AnalyticsApi.js.map +1 -0
  9. package/lib/cjs/ApiKeysApi.js +63 -0
  10. package/lib/cjs/ApiKeysApi.js.map +1 -0
  11. package/lib/cjs/AppsApi.js +119 -0
  12. package/lib/cjs/AppsApi.js.map +1 -0
  13. package/lib/cjs/CommandsApi.js +19 -0
  14. package/lib/cjs/CommandsApi.js.map +1 -0
  15. package/lib/cjs/EnvironmentsApi.js +72 -0
  16. package/lib/cjs/EnvironmentsApi.js.map +1 -0
  17. package/lib/cjs/GroupsApi.js +78 -0
  18. package/lib/cjs/GroupsApi.js.map +1 -0
  19. package/lib/cjs/IamApi.js +53 -0
  20. package/lib/cjs/IamApi.js.map +1 -0
  21. package/lib/cjs/InteractionBase.js +44 -0
  22. package/lib/cjs/InteractionBase.js.map +1 -0
  23. package/lib/cjs/InteractionCatalogApi.js +64 -0
  24. package/lib/cjs/InteractionCatalogApi.js.map +1 -0
  25. package/lib/cjs/InteractionOutput.js +300 -0
  26. package/lib/cjs/InteractionOutput.js.map +1 -0
  27. package/lib/cjs/InteractionResult.example.js +57 -0
  28. package/lib/cjs/InteractionResult.example.js.map +1 -0
  29. package/lib/cjs/InteractionsApi.js +262 -0
  30. package/lib/cjs/InteractionsApi.js.map +1 -0
  31. package/lib/cjs/MCPOAuthApi.js +62 -0
  32. package/lib/cjs/MCPOAuthApi.js.map +1 -0
  33. package/lib/cjs/ProjectsApi.js +72 -0
  34. package/lib/cjs/ProjectsApi.js.map +1 -0
  35. package/lib/cjs/PromptsApi.js +133 -0
  36. package/lib/cjs/PromptsApi.js.map +1 -0
  37. package/lib/cjs/RefsApi.js +14 -0
  38. package/lib/cjs/RefsApi.js.map +1 -0
  39. package/lib/cjs/RunsApi.js +113 -0
  40. package/lib/cjs/RunsApi.js.map +1 -0
  41. package/lib/cjs/SkillsApi.js +39 -0
  42. package/lib/cjs/SkillsApi.js.map +1 -0
  43. package/lib/cjs/StreamSource.js +17 -0
  44. package/lib/cjs/StreamSource.js.map +1 -0
  45. package/lib/cjs/TrainingApi.js +54 -0
  46. package/lib/cjs/TrainingApi.js.map +1 -0
  47. package/lib/cjs/UsersApi.js +13 -0
  48. package/lib/cjs/UsersApi.js.map +1 -0
  49. package/lib/cjs/client.js +360 -0
  50. package/lib/cjs/client.js.map +1 -0
  51. package/lib/cjs/execute.js +158 -0
  52. package/lib/cjs/execute.js.map +1 -0
  53. package/lib/cjs/index.js +22 -0
  54. package/lib/cjs/index.js.map +1 -0
  55. package/lib/cjs/nodejs/NodeStreamSource.js +45 -0
  56. package/lib/cjs/nodejs/NodeStreamSource.js.map +1 -0
  57. package/lib/cjs/nodejs/index.js +18 -0
  58. package/lib/cjs/nodejs/index.js.map +1 -0
  59. package/lib/cjs/package.json +3 -0
  60. package/lib/cjs/store/AnalyzeDocApi.js +56 -0
  61. package/lib/cjs/store/AnalyzeDocApi.js.map +1 -0
  62. package/lib/cjs/store/CollectionsApi.js +131 -0
  63. package/lib/cjs/store/CollectionsApi.js.map +1 -0
  64. package/lib/cjs/store/CommandsApi.js +17 -0
  65. package/lib/cjs/store/CommandsApi.js.map +1 -0
  66. package/lib/cjs/store/DashboardApi.js +182 -0
  67. package/lib/cjs/store/DashboardApi.js.map +1 -0
  68. package/lib/cjs/store/DataApi.js +433 -0
  69. package/lib/cjs/store/DataApi.js.map +1 -0
  70. package/lib/cjs/store/EmailApi.js +103 -0
  71. package/lib/cjs/store/EmailApi.js.map +1 -0
  72. package/lib/cjs/store/EmbeddingsApi.js +29 -0
  73. package/lib/cjs/store/EmbeddingsApi.js.map +1 -0
  74. package/lib/cjs/store/FilesApi.js +237 -0
  75. package/lib/cjs/store/FilesApi.js.map +1 -0
  76. package/lib/cjs/store/ObjectsApi.js +314 -0
  77. package/lib/cjs/store/ObjectsApi.js.map +1 -0
  78. package/lib/cjs/store/PendingAsksApi.js +43 -0
  79. package/lib/cjs/store/PendingAsksApi.js.map +1 -0
  80. package/lib/cjs/store/SchedulesApi.js +103 -0
  81. package/lib/cjs/store/SchedulesApi.js.map +1 -0
  82. package/lib/cjs/store/ToolsApi.js +21 -0
  83. package/lib/cjs/store/ToolsApi.js.map +1 -0
  84. package/lib/cjs/store/TypesApi.js +57 -0
  85. package/lib/cjs/store/TypesApi.js.map +1 -0
  86. package/lib/cjs/store/WorkersApi.js +16 -0
  87. package/lib/cjs/store/WorkersApi.js.map +1 -0
  88. package/lib/cjs/store/WorkflowsApi.js +596 -0
  89. package/lib/cjs/store/WorkflowsApi.js.map +1 -0
  90. package/lib/cjs/store/client.js +81 -0
  91. package/lib/cjs/store/client.js.map +1 -0
  92. package/lib/cjs/store/errors.js +11 -0
  93. package/lib/cjs/store/errors.js.map +1 -0
  94. package/lib/cjs/store/index.js +27 -0
  95. package/lib/cjs/store/index.js.map +1 -0
  96. package/lib/cjs/store/version.js +6 -0
  97. package/lib/cjs/store/version.js.map +1 -0
  98. package/lib/esm/AccountApi.js +82 -0
  99. package/lib/esm/AccountApi.js.map +1 -0
  100. package/lib/esm/AccountsApi.js +13 -0
  101. package/lib/esm/AccountsApi.js.map +1 -0
  102. package/lib/esm/AnalyticsApi.js +38 -0
  103. package/lib/esm/AnalyticsApi.js.map +1 -0
  104. package/lib/esm/ApiKeysApi.js +59 -0
  105. package/lib/esm/ApiKeysApi.js.map +1 -0
  106. package/lib/esm/AppsApi.js +116 -0
  107. package/lib/esm/AppsApi.js.map +1 -0
  108. package/lib/esm/CommandsApi.js +16 -0
  109. package/lib/esm/CommandsApi.js.map +1 -0
  110. package/lib/esm/EnvironmentsApi.js +69 -0
  111. package/lib/esm/EnvironmentsApi.js.map +1 -0
  112. package/lib/esm/GroupsApi.js +74 -0
  113. package/lib/esm/GroupsApi.js.map +1 -0
  114. package/lib/esm/IamApi.js +47 -0
  115. package/lib/esm/IamApi.js.map +1 -0
  116. package/lib/esm/InteractionBase.js +40 -0
  117. package/lib/esm/InteractionBase.js.map +1 -0
  118. package/lib/esm/InteractionCatalogApi.js +60 -0
  119. package/lib/esm/InteractionCatalogApi.js.map +1 -0
  120. package/lib/esm/InteractionOutput.js +293 -0
  121. package/lib/esm/InteractionOutput.js.map +1 -0
  122. package/lib/esm/InteractionResult.example.js +55 -0
  123. package/lib/esm/InteractionResult.example.js.map +1 -0
  124. package/lib/esm/InteractionsApi.js +259 -0
  125. package/lib/esm/InteractionsApi.js.map +1 -0
  126. package/lib/esm/MCPOAuthApi.js +59 -0
  127. package/lib/esm/MCPOAuthApi.js.map +1 -0
  128. package/lib/esm/ProjectsApi.js +69 -0
  129. package/lib/esm/ProjectsApi.js.map +1 -0
  130. package/lib/esm/PromptsApi.js +130 -0
  131. package/lib/esm/PromptsApi.js.map +1 -0
  132. package/lib/esm/RefsApi.js +10 -0
  133. package/lib/esm/RefsApi.js.map +1 -0
  134. package/lib/esm/RunsApi.js +109 -0
  135. package/lib/esm/RunsApi.js.map +1 -0
  136. package/lib/esm/SkillsApi.js +36 -0
  137. package/lib/esm/SkillsApi.js.map +1 -0
  138. package/lib/esm/StreamSource.js +13 -0
  139. package/lib/esm/StreamSource.js.map +1 -0
  140. package/lib/esm/TrainingApi.js +51 -0
  141. package/lib/esm/TrainingApi.js.map +1 -0
  142. package/lib/esm/UsersApi.js +10 -0
  143. package/lib/esm/UsersApi.js.map +1 -0
  144. package/lib/esm/client.js +351 -0
  145. package/lib/esm/client.js.map +1 -0
  146. package/lib/esm/execute.js +118 -0
  147. package/lib/esm/execute.js.map +1 -0
  148. package/lib/esm/index.js +6 -0
  149. package/lib/esm/index.js.map +1 -0
  150. package/lib/esm/nodejs/NodeStreamSource.js +41 -0
  151. package/lib/esm/nodejs/NodeStreamSource.js.map +1 -0
  152. package/lib/esm/nodejs/index.js +2 -0
  153. package/lib/esm/nodejs/index.js.map +1 -0
  154. package/lib/esm/store/AnalyzeDocApi.js +52 -0
  155. package/lib/esm/store/AnalyzeDocApi.js.map +1 -0
  156. package/lib/esm/store/CollectionsApi.js +127 -0
  157. package/lib/esm/store/CollectionsApi.js.map +1 -0
  158. package/lib/esm/store/CommandsApi.js +13 -0
  159. package/lib/esm/store/CommandsApi.js.map +1 -0
  160. package/lib/esm/store/DashboardApi.js +178 -0
  161. package/lib/esm/store/DashboardApi.js.map +1 -0
  162. package/lib/esm/store/DataApi.js +429 -0
  163. package/lib/esm/store/DataApi.js.map +1 -0
  164. package/lib/esm/store/EmailApi.js +99 -0
  165. package/lib/esm/store/EmailApi.js.map +1 -0
  166. package/lib/esm/store/EmbeddingsApi.js +25 -0
  167. package/lib/esm/store/EmbeddingsApi.js.map +1 -0
  168. package/lib/esm/store/FilesApi.js +231 -0
  169. package/lib/esm/store/FilesApi.js.map +1 -0
  170. package/lib/esm/store/ObjectsApi.js +309 -0
  171. package/lib/esm/store/ObjectsApi.js.map +1 -0
  172. package/lib/esm/store/PendingAsksApi.js +39 -0
  173. package/lib/esm/store/PendingAsksApi.js.map +1 -0
  174. package/lib/esm/store/SchedulesApi.js +99 -0
  175. package/lib/esm/store/SchedulesApi.js.map +1 -0
  176. package/lib/esm/store/ToolsApi.js +17 -0
  177. package/lib/esm/store/ToolsApi.js.map +1 -0
  178. package/lib/esm/store/TypesApi.js +53 -0
  179. package/lib/esm/store/TypesApi.js.map +1 -0
  180. package/lib/esm/store/WorkersApi.js +12 -0
  181. package/lib/esm/store/WorkersApi.js.map +1 -0
  182. package/lib/esm/store/WorkflowsApi.js +590 -0
  183. package/lib/esm/store/WorkflowsApi.js.map +1 -0
  184. package/lib/esm/store/client.js +77 -0
  185. package/lib/esm/store/client.js.map +1 -0
  186. package/lib/esm/store/errors.js +7 -0
  187. package/lib/esm/store/errors.js.map +1 -0
  188. package/lib/esm/store/index.js +11 -0
  189. package/lib/esm/store/index.js.map +1 -0
  190. package/lib/esm/store/version.js +3 -0
  191. package/lib/esm/store/version.js.map +1 -0
  192. package/lib/tsconfig.tsbuildinfo +1 -0
  193. package/lib/types/AccountApi.d.ts +59 -0
  194. package/lib/types/AccountApi.d.ts.map +1 -0
  195. package/lib/types/AccountsApi.d.ts +7 -0
  196. package/lib/types/AccountsApi.d.ts.map +1 -0
  197. package/lib/types/AnalyticsApi.d.ts +11 -0
  198. package/lib/types/AnalyticsApi.d.ts.map +1 -0
  199. package/lib/types/ApiKeysApi.d.ts +42 -0
  200. package/lib/types/ApiKeysApi.d.ts.map +1 -0
  201. package/lib/types/AppsApi.d.ts +65 -0
  202. package/lib/types/AppsApi.d.ts.map +1 -0
  203. package/lib/types/CommandsApi.d.ts +10 -0
  204. package/lib/types/CommandsApi.d.ts.map +1 -0
  205. package/lib/types/EnvironmentsApi.d.ts +40 -0
  206. package/lib/types/EnvironmentsApi.d.ts.map +1 -0
  207. package/lib/types/GroupsApi.d.ts +65 -0
  208. package/lib/types/GroupsApi.d.ts.map +1 -0
  209. package/lib/types/IamApi.d.ts +41 -0
  210. package/lib/types/IamApi.d.ts.map +1 -0
  211. package/lib/types/InteractionBase.d.ts +22 -0
  212. package/lib/types/InteractionBase.d.ts.map +1 -0
  213. package/lib/types/InteractionCatalogApi.d.ts +36 -0
  214. package/lib/types/InteractionCatalogApi.d.ts.map +1 -0
  215. package/lib/types/InteractionOutput.d.ts +174 -0
  216. package/lib/types/InteractionOutput.d.ts.map +1 -0
  217. package/lib/types/InteractionResult.example.d.ts +6 -0
  218. package/lib/types/InteractionResult.example.d.ts.map +1 -0
  219. package/lib/types/InteractionsApi.d.ts +183 -0
  220. package/lib/types/InteractionsApi.d.ts.map +1 -0
  221. package/lib/types/MCPOAuthApi.d.ts +45 -0
  222. package/lib/types/MCPOAuthApi.d.ts.map +1 -0
  223. package/lib/types/ProjectsApi.d.ts +28 -0
  224. package/lib/types/ProjectsApi.d.ts.map +1 -0
  225. package/lib/types/PromptsApi.d.ts +106 -0
  226. package/lib/types/PromptsApi.d.ts.map +1 -0
  227. package/lib/types/RefsApi.d.ts +6 -0
  228. package/lib/types/RefsApi.d.ts.map +1 -0
  229. package/lib/types/RunsApi.d.ts +79 -0
  230. package/lib/types/RunsApi.d.ts.map +1 -0
  231. package/lib/types/SkillsApi.d.ts +26 -0
  232. package/lib/types/SkillsApi.d.ts.map +1 -0
  233. package/lib/types/StreamSource.d.ts +7 -0
  234. package/lib/types/StreamSource.d.ts.map +1 -0
  235. package/lib/types/TrainingApi.d.ts +27 -0
  236. package/lib/types/TrainingApi.d.ts.map +1 -0
  237. package/lib/types/UsersApi.d.ts +6 -0
  238. package/lib/types/UsersApi.d.ts.map +1 -0
  239. package/lib/types/client.d.ts +136 -0
  240. package/lib/types/client.d.ts.map +1 -0
  241. package/lib/types/execute.d.ts +37 -0
  242. package/lib/types/execute.d.ts.map +1 -0
  243. package/lib/types/index.d.ts +10 -0
  244. package/lib/types/index.d.ts.map +1 -0
  245. package/lib/types/nodejs/NodeStreamSource.d.ts +9 -0
  246. package/lib/types/nodejs/NodeStreamSource.d.ts.map +1 -0
  247. package/lib/types/nodejs/index.d.ts +1 -0
  248. package/lib/types/nodejs/index.d.ts.map +1 -0
  249. package/lib/types/store/AnalyzeDocApi.d.ts +17 -0
  250. package/lib/types/store/AnalyzeDocApi.d.ts.map +1 -0
  251. package/lib/types/store/CollectionsApi.d.ts +82 -0
  252. package/lib/types/store/CollectionsApi.d.ts.map +1 -0
  253. package/lib/types/store/CommandsApi.d.ts +10 -0
  254. package/lib/types/store/CommandsApi.d.ts.map +1 -0
  255. package/lib/types/store/DashboardApi.d.ts +149 -0
  256. package/lib/types/store/DashboardApi.d.ts.map +1 -0
  257. package/lib/types/store/DataApi.d.ts +392 -0
  258. package/lib/types/store/DataApi.d.ts.map +1 -0
  259. package/lib/types/store/EmailApi.d.ts +185 -0
  260. package/lib/types/store/EmailApi.d.ts.map +1 -0
  261. package/lib/types/store/EmbeddingsApi.d.ts +12 -0
  262. package/lib/types/store/EmbeddingsApi.d.ts.map +1 -0
  263. package/lib/types/store/FilesApi.d.ts +110 -0
  264. package/lib/types/store/FilesApi.d.ts.map +1 -0
  265. package/lib/types/store/ObjectsApi.d.ts +139 -0
  266. package/lib/types/store/ObjectsApi.d.ts.map +1 -0
  267. package/lib/types/store/PendingAsksApi.d.ts +79 -0
  268. package/lib/types/store/PendingAsksApi.d.ts.map +1 -0
  269. package/lib/types/store/SchedulesApi.d.ts +89 -0
  270. package/lib/types/store/SchedulesApi.d.ts.map +1 -0
  271. package/lib/types/store/ToolsApi.d.ts +13 -0
  272. package/lib/types/store/ToolsApi.d.ts.map +1 -0
  273. package/lib/types/store/TypesApi.d.ts +23 -0
  274. package/lib/types/store/TypesApi.d.ts.map +1 -0
  275. package/lib/types/store/WorkersApi.d.ts +6 -0
  276. package/lib/types/store/WorkersApi.d.ts.map +1 -0
  277. package/lib/types/store/WorkflowsApi.d.ts +167 -0
  278. package/lib/types/store/WorkflowsApi.d.ts.map +1 -0
  279. package/lib/types/store/client.d.ts +45 -0
  280. package/lib/types/store/client.d.ts.map +1 -0
  281. package/lib/types/store/errors.d.ts +4 -0
  282. package/lib/types/store/errors.d.ts.map +1 -0
  283. package/lib/types/store/index.d.ts +10 -0
  284. package/lib/types/store/index.d.ts.map +1 -0
  285. package/lib/types/store/version.d.ts +2 -0
  286. package/lib/types/store/version.d.ts.map +1 -0
  287. package/lib/vertesia-client.js +2 -0
  288. package/lib/vertesia-client.js.map +1 -0
  289. package/package.json +71 -0
  290. package/src/AccountApi.ts +96 -0
  291. package/src/AccountsApi.ts +22 -0
  292. package/src/AnalyticsApi.ts +36 -0
  293. package/src/ApiKeysApi.ts +67 -0
  294. package/src/AppsApi.ts +134 -0
  295. package/src/CommandsApi.ts +23 -0
  296. package/src/EnvironmentsApi.ts +94 -0
  297. package/src/GroupsApi.ts +92 -0
  298. package/src/IamApi.ts +70 -0
  299. package/src/InteractionBase.ts +44 -0
  300. package/src/InteractionCatalogApi.ts +72 -0
  301. package/src/InteractionOutput.test.ts +305 -0
  302. package/src/InteractionOutput.ts +328 -0
  303. package/src/InteractionResult.example.ts +72 -0
  304. package/src/InteractionsApi.ts +308 -0
  305. package/src/MCPOAuthApi.ts +67 -0
  306. package/src/ProjectsApi.ts +85 -0
  307. package/src/PromptsApi.ts +160 -0
  308. package/src/RefsApi.ts +18 -0
  309. package/src/RunsApi.ts +151 -0
  310. package/src/SkillsApi.ts +46 -0
  311. package/src/StreamSource.ts +3 -0
  312. package/src/TrainingApi.ts +71 -0
  313. package/src/UsersApi.ts +18 -0
  314. package/src/client.test.ts +99 -0
  315. package/src/client.ts +419 -0
  316. package/src/execute.ts +126 -0
  317. package/src/index.ts +10 -0
  318. package/src/nodejs/NodeStreamSource.ts +43 -0
  319. package/src/nodejs/index.ts +1 -0
  320. package/src/store/AnalyzeDocApi.ts +61 -0
  321. package/src/store/CollectionsApi.ts +166 -0
  322. package/src/store/CommandsApi.ts +15 -0
  323. package/src/store/DashboardApi.ts +216 -0
  324. package/src/store/DataApi.ts +516 -0
  325. package/src/store/EmailApi.ts +211 -0
  326. package/src/store/EmbeddingsApi.ts +39 -0
  327. package/src/store/FilesApi.ts +288 -0
  328. package/src/store/ObjectsApi.ts +432 -0
  329. package/src/store/PendingAsksApi.ts +98 -0
  330. package/src/store/SchedulesApi.ts +114 -0
  331. package/src/store/ToolsApi.ts +19 -0
  332. package/src/store/TypesApi.ts +65 -0
  333. package/src/store/WorkersApi.ts +17 -0
  334. package/src/store/WorkflowsApi.ts +752 -0
  335. package/src/store/client.ts +95 -0
  336. package/src/store/errors.ts +7 -0
  337. package/src/store/index.ts +11 -0
  338. package/src/store/version.ts +2 -0
  339. package/tsconfig.dist.json +20 -0
package/src/client.ts ADDED
@@ -0,0 +1,419 @@
1
+ import { AbstractFetchClient } from "@vertesia/api-fetch-client";
2
+ import { AuthTokenPayload, AuthTokenResponse } from "@vertesia/common";
3
+ import AccountApi from "./AccountApi.js";
4
+ import AccountsApi from "./AccountsApi.js";
5
+ import AnalyticsApi from "./AnalyticsApi.js";
6
+ import { ApiKeysApi } from "./ApiKeysApi.js";
7
+ import AppsApi from "./AppsApi.js";
8
+ import CommandsApi from "./CommandsApi.js";
9
+ import EnvironmentsApi from "./EnvironmentsApi.js";
10
+ import { IamApi } from "./IamApi.js";
11
+ import InteractionsApi from "./InteractionsApi.js";
12
+ import MCPOAuthApi from "./MCPOAuthApi.js";
13
+ import ProjectsApi from "./ProjectsApi.js";
14
+ import SkillsApi from "./SkillsApi.js";
15
+ import PromptsApi from "./PromptsApi.js";
16
+ import { RefsApi } from "./RefsApi.js";
17
+ import { RunsApi } from "./RunsApi.js";
18
+ import { ZenoClient } from "./store/client.js";
19
+ import TrainingApi from "./TrainingApi.js";
20
+ import UsersApi from "./UsersApi.js";
21
+ import { VERSION, VERSION_HEADER } from "./store/version.js";
22
+
23
+
24
+ /**
25
+ * 1 min threshold constant in ms
26
+ */
27
+ const EXPIRATION_THRESHOLD = 60000;
28
+
29
+ export type VertesiaClientProps = {
30
+ /**
31
+ * The site name of Vertesia.
32
+ *
33
+ * This is used to determine the API backend. It should not include the protocol. For more
34
+ * advanced configurations, use `serverUrl` and `storeUrl` instead.
35
+ *
36
+ * @example api.vertesia.io
37
+ * @example api-preview.vertesia.io
38
+ * @example api-staging.vertesia.io
39
+ * @default api.vertesia.io
40
+ * @since 0.52.0
41
+ */
42
+ site?:
43
+ | "api.vertesia.io"
44
+ | "api-preview.vertesia.io"
45
+ | "api-staging.vertesia.io";
46
+ serverUrl?: string;
47
+ storeUrl?: string;
48
+ tokenServerUrl?: string;
49
+ apikey?: string;
50
+ projectId?: string;
51
+ sessionTags?: string | string[];
52
+ onRequest?: (request: Request) => void;
53
+ onResponse?: (response: Response) => void;
54
+ };
55
+
56
+ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
57
+ /**
58
+ * The JWT token linked to the API KEY (sk or pk)
59
+ */
60
+ _jwt: string | null = null;
61
+
62
+ /**
63
+ * The store client
64
+ */
65
+ store: ZenoClient;
66
+
67
+ /**
68
+ * The session name will be sent when executing an interaction as a tag
69
+ */
70
+ sessionTags?: string | string[];
71
+
72
+ /**
73
+ * tokenServerUrl
74
+ */
75
+ tokenServerUrl: string;
76
+
77
+ /**
78
+ * Create a client from the given token.
79
+ * If you already have the decoded token you can pass it as the second argument to avoid decodinf it again.
80
+ *
81
+ * @param token the raw JWT token
82
+ * @param payload the decoded JWT token as an AuthTokenPayload - optional
83
+ * @param endpoints optional endpoints to override those in the payload
84
+ */
85
+ static async fromAuthToken(
86
+ token: string,
87
+ payload?: AuthTokenPayload,
88
+ endpoints?: { studio: string; store: string; token?: string }
89
+ ) {
90
+ if (!payload) {
91
+ payload = decodeJWT(token);
92
+ }
93
+
94
+ const resolvedEndpoints = endpoints || decodeEndpoints(payload.endpoints);
95
+ return await new VertesiaClient({
96
+ serverUrl: resolvedEndpoints.studio,
97
+ storeUrl: resolvedEndpoints.store,
98
+ tokenServerUrl: resolvedEndpoints.token || payload.iss,
99
+ }).withApiKey(token);
100
+ }
101
+
102
+ static decodeEndpoints() {}
103
+
104
+ constructor(
105
+ opts: VertesiaClientProps = {
106
+ site: "api.vertesia.io",
107
+ },
108
+ ) {
109
+ let studioServerUrl: string;
110
+ let zenoServerUrl: string;
111
+
112
+ if (opts.serverUrl) {
113
+ studioServerUrl = opts.serverUrl;
114
+ } else if (opts.site) {
115
+ studioServerUrl = `https://${opts.site}`;
116
+ } else {
117
+ throw new Error(
118
+ "Parameter 'site' or 'serverUrl' is required for VertesiaClient",
119
+ );
120
+ }
121
+
122
+ if (opts.storeUrl) {
123
+ zenoServerUrl = opts.storeUrl;
124
+ } else if (opts.site) {
125
+ zenoServerUrl = `https://${opts.site}`;
126
+ } else {
127
+ throw new Error(
128
+ "Parameter 'site' or 'storeUrl' is required for VertesiaClient",
129
+ );
130
+ }
131
+
132
+ super(studioServerUrl);
133
+
134
+ if (opts.tokenServerUrl) {
135
+ this.tokenServerUrl = opts.tokenServerUrl;
136
+ } else if (opts.site) {
137
+ // Preview uses production STS, staging uses its own STS
138
+ if (opts.site === "api-preview.vertesia.io" || opts.site === "api.vertesia.io") {
139
+ this.tokenServerUrl = "https://sts.vertesia.io";
140
+ } else {
141
+ this.tokenServerUrl = `https://${opts.site.replace(/^api/, "sts")}`;
142
+ }
143
+ } else if (opts.serverUrl || opts.storeUrl) {
144
+ // Determine STS URL based on environment in serverUrl or storeUrl
145
+ const urlToCheck = opts.serverUrl || opts.storeUrl || "";
146
+ try {
147
+ const url = new URL(urlToCheck);
148
+ // Check for environment patterns
149
+ if (url.hostname.includes("-production.")) {
150
+ // zeno-server-production.api.vertesia.io -> sts.vertesia.io
151
+ this.tokenServerUrl = "https://sts.vertesia.io";
152
+ } else if (url.hostname.includes("-preview.")) {
153
+ // zeno-server-preview.api.vertesia.io -> sts.vertesia.io
154
+ this.tokenServerUrl = "https://sts.vertesia.io";
155
+ } else if (url.hostname === "api.vertesia.io") {
156
+ this.tokenServerUrl = "https://sts.vertesia.io";
157
+ } else if (url.hostname === "api-preview.vertesia.io") {
158
+ this.tokenServerUrl = "https://sts.vertesia.io";
159
+ } else if (url.hostname === "api-staging.vertesia.io") {
160
+ this.tokenServerUrl = "https://sts-staging.vertesia.io";
161
+ } else if (url.hostname.startsWith("api")) {
162
+ // Generic api.* pattern replacement
163
+ url.hostname = url.hostname.replace(/^api/, "sts");
164
+ this.tokenServerUrl = url.toString();
165
+ } else {
166
+ // Default to staging for everything else
167
+ this.tokenServerUrl = "https://sts-staging.vertesia.io";
168
+ }
169
+ } catch (e) {
170
+ // Default to staging if URL parsing fails
171
+ this.tokenServerUrl = "https://sts-staging.vertesia.io";
172
+ }
173
+ } else {
174
+ // Default to staging if no URL provided
175
+ this.tokenServerUrl = "https://sts-staging.vertesia.io";
176
+ }
177
+
178
+ this.store = new ZenoClient({
179
+ serverUrl: zenoServerUrl,
180
+ tokenServerUrl: this.tokenServerUrl,
181
+ apikey: opts.apikey,
182
+ onRequest: opts.onRequest,
183
+ onResponse: opts.onResponse,
184
+ });
185
+
186
+ if (opts.apikey) {
187
+ this.withApiKey(opts.apikey);
188
+ }
189
+
190
+ this.onRequest = opts.onRequest;
191
+ this.onResponse = opts.onResponse;
192
+ this.sessionTags = opts.sessionTags;
193
+ }
194
+
195
+ withApiVersion(version: string | number | null) {
196
+ if (!version) {
197
+ delete this.headers[VERSION_HEADER];
198
+ } else {
199
+ this.headers[VERSION_HEADER] = String(version);
200
+ }
201
+ return this;
202
+ }
203
+
204
+ /**
205
+ * Overwrite to keep store and composable clients synchronized on the auth callback
206
+ * @param authCb
207
+ * @returns
208
+ */
209
+ withAuthCallback(authCb?: (() => Promise<string>) | null) {
210
+ this.store.withAuthCallback(authCb);
211
+ return super.withAuthCallback(authCb);
212
+ }
213
+
214
+ async withApiKey(apiKey: string | null) {
215
+ return this.withAuthCallback(
216
+ apiKey
217
+ ? async () => {
218
+ if (!isApiKey(apiKey)) {
219
+ return `Bearer ${apiKey}`;
220
+ }
221
+
222
+ if (isTokenExpired(this._jwt)) {
223
+ const jwt = await this.getAuthToken(apiKey);
224
+ this._jwt = jwt.token;
225
+ }
226
+ return `Bearer ${this._jwt}`;
227
+ }
228
+ : undefined,
229
+ );
230
+ }
231
+
232
+ async getRawJWT() {
233
+ if (!this._jwt && this._auth) {
234
+ const auth = await this._auth();
235
+ if (!this._jwt) {
236
+ // the _jwt may be set by the auth callback
237
+ this._jwt = auth.trim().split(" ")[1]; // remove Bearer prefix
238
+ }
239
+ }
240
+ return this._jwt || null;
241
+ }
242
+
243
+ async getDecodedJWT(): Promise<AuthTokenPayload | null> {
244
+ const jwt = await this.getRawJWT();
245
+ return jwt ? decodeJWT(jwt) : null;
246
+ }
247
+
248
+ async getProject() {
249
+ const jwt = await this.getDecodedJWT();
250
+ return jwt?.project || null;
251
+ }
252
+
253
+ async getAccount() {
254
+ const jwt = await this.getDecodedJWT();
255
+ return jwt?.account || null;
256
+ }
257
+
258
+ /**
259
+ * Alias for store.workflows
260
+ */
261
+ get workflows() {
262
+ return this.store.workflows;
263
+ }
264
+
265
+ /**
266
+ * Alias for store.objects
267
+ */
268
+ get objects() {
269
+ return this.store.objects;
270
+ }
271
+
272
+ get files() {
273
+ return this.store.files;
274
+ }
275
+
276
+ /**
277
+ * Alias for store.types
278
+ */
279
+ get types() {
280
+ return this.store.types;
281
+ }
282
+
283
+ /**
284
+ * Alias for store.data
285
+ */
286
+ get data() {
287
+ return this.store.data;
288
+ }
289
+
290
+ get storeUrl() {
291
+ return this.store.baseUrl;
292
+ }
293
+
294
+ /**
295
+ *
296
+ * Generate a token for use with other Vertesia's services
297
+ *
298
+ * @returns AuthTokenResponse
299
+ */
300
+ async getAuthToken(token?: string): Promise<AuthTokenResponse> {
301
+ return fetch(`${this.tokenServerUrl}/token/issue`, {
302
+ method: "POST",
303
+ headers: {
304
+ "Content-Type": "application/json",
305
+ Authorization: `Bearer ${token}`,
306
+ },
307
+ })
308
+ .then((response) => response.json())
309
+ .then((data) => data as AuthTokenResponse)
310
+ .catch((error) => {
311
+ console.error(
312
+ `Error fetching token from ${this.tokenServerUrl}:`,
313
+ { error },
314
+ );
315
+ throw error;
316
+ });
317
+ }
318
+
319
+ get initialHeaders() {
320
+ return {
321
+ ...super.initialHeaders,
322
+ [VERSION_HEADER]: VERSION
323
+ }
324
+ }
325
+
326
+ projects = new ProjectsApi(this);
327
+ environments = new EnvironmentsApi(this);
328
+ interactions = new InteractionsApi(this);
329
+ skills = new SkillsApi(this);
330
+ prompts = new PromptsApi(this);
331
+ runs = new RunsApi(this);
332
+ account = new AccountApi(this);
333
+ accounts = new AccountsApi(this);
334
+ apikeys = new ApiKeysApi(this);
335
+ analytics = new AnalyticsApi(this);
336
+ training = new TrainingApi(this);
337
+ users = new UsersApi(this);
338
+ iam = new IamApi(this);
339
+ refs = new RefsApi(this);
340
+ commands = new CommandsApi(this);
341
+ apps = new AppsApi(this);
342
+ mcpOAuth = new MCPOAuthApi(this);
343
+ }
344
+
345
+ function isApiKey(apiKey: string) {
346
+ return apiKey.startsWith("pk-") || apiKey.startsWith("sk-");
347
+ }
348
+
349
+ function isTokenExpired(token: string | null) {
350
+ if (!token) {
351
+ return true;
352
+ }
353
+
354
+ const decoded = decodeJWT(token);
355
+ const exp = decoded.exp;
356
+ const currentTime = Date.now();
357
+ return currentTime <= exp * 1000 - EXPIRATION_THRESHOLD;
358
+ }
359
+
360
+ export function decodeJWT(jwt: string): AuthTokenPayload {
361
+ const payloadBase64 = jwt.split(".")[1];
362
+ const decodedJson = base64UrlDecode(payloadBase64);
363
+ return JSON.parse(decodedJson);
364
+ }
365
+
366
+ function base64UrlDecode(input: string): string {
367
+ // Convert base64url to base64
368
+ const base64 = input
369
+ .replace(/-/g, "+")
370
+ .replace(/_/g, "/")
371
+ // Pad with '=' to make length a multiple of 4
372
+ .padEnd(Math.ceil(input.length / 4) * 4, "=");
373
+
374
+ if (typeof Buffer !== "undefined") {
375
+ // Node.js
376
+ return Buffer.from(base64, "base64").toString("utf-8");
377
+ } else if (
378
+ typeof atob !== "undefined" &&
379
+ typeof TextDecoder !== "undefined"
380
+ ) {
381
+ // Browser
382
+ const binary = atob(base64);
383
+ const bytes = Uint8Array.from(binary, (c) => c.charCodeAt(0));
384
+ // decode to utf8
385
+ return new TextDecoder().decode(bytes);
386
+ } else {
387
+ throw new Error("No base64 decoder available");
388
+ }
389
+ }
390
+
391
+ export function decodeEndpoints(
392
+ endpoints: string | Record<string, string> | undefined,
393
+ ): Record<string, string> {
394
+ if (!endpoints) {
395
+ return getEndpointsFromDomain("api.vertesia.io");
396
+ }
397
+ if (typeof endpoints === "string") {
398
+ return getEndpointsFromDomain(endpoints);
399
+ } else {
400
+ return endpoints;
401
+ }
402
+ }
403
+
404
+ function getEndpointsFromDomain(domain: string) {
405
+ if (domain === "local") {
406
+ return {
407
+ studio: `http://localhost:8091`,
408
+ store: `http://localhost:8092`,
409
+ token: process.env.STS_URL ?? "https://sts-staging.vertesia.io",
410
+ };
411
+ } else {
412
+ const url = `https://${domain}`;
413
+ return {
414
+ studio: url,
415
+ store: url,
416
+ token: url.replace("api", "sts"),
417
+ };
418
+ }
419
+ }
package/src/execute.ts ADDED
@@ -0,0 +1,126 @@
1
+ import { AsyncExecutionPayload, ExecutionRunStatus, InteractionExecutionPayload, InteractionExecutionResult, NamedInteractionExecutionPayload, RateLimitRequestPayload, RateLimitRequestResponse } from '@vertesia/common';
2
+ import { VertesiaClient } from './client.js';
3
+
4
+ export async function EventSourceProvider(): Promise<typeof EventSource> {
5
+ if (typeof globalThis.EventSource === 'function') {
6
+ return globalThis.EventSource;
7
+ } else {
8
+ return (await import('eventsource')).EventSource;
9
+ }
10
+ }
11
+ /**
12
+ *
13
+ * Execute an interaction and return a promise which will be resolved with the executed run when
14
+ * the run completes or fails.
15
+ * If the onChunk callback is passed then the streaming of the result is enabled.
16
+ * The onChunk callback with be called with the next chunk of the result as soon as it is available.
17
+ * When all chunks are received the function will return the resolved promise
18
+ * @param id of the interaction to execute
19
+ * @param payload InteractionExecutionPayload
20
+ * @param onChunk callback to be called when the next chunk of the response is available
21
+ */
22
+ export async function executeInteraction<P = any>(client: VertesiaClient,
23
+ interactionId: string,
24
+ payload: InteractionExecutionPayload = {},
25
+ onChunk?: (chunk: string) => void): Promise<InteractionExecutionResult<P>> {
26
+ const stream = !!onChunk;
27
+ const response = await client.runs.create({
28
+ ...payload, interaction: interactionId, stream
29
+ });
30
+ if (stream) {
31
+ if (response.status === ExecutionRunStatus.failed) {
32
+ return response;
33
+ }
34
+ await handleStreaming(client, response.id, onChunk);
35
+ }
36
+ return response;
37
+ }
38
+
39
+ /**
40
+ * Same as executeInteraction but uses the interaction name selector instead of the id.
41
+ * A name selector is the interaction endpoint name suffixed with an optional tag or version which is starting with a `@` character.
42
+ * The special `draft` tag is used to select the draft version of the interaction. If no tag or version is specified then the latest version is selected.
43
+ * Examples of selectors:
44
+ * - `ReviewContract` - select the latest version of the ReviewContract interaction
45
+ * - `ReviewContract@1` - select the version 1 of the ReviewContract interaction
46
+ * - `ReviewContract@draft` - select the draft version of the ReviewContract interaction
47
+ * - `ReviewContract@fixed` - select the ReviewContract interaction which is tagged with 'fixed' tag.
48
+ *
49
+ * @param client
50
+ * @param interaction
51
+ * @param payload
52
+ * @param onChunk
53
+ * @returns
54
+ */
55
+ export async function executeInteractionByName<P = any>(client: VertesiaClient,
56
+ interaction: string,
57
+ payload: InteractionExecutionPayload = {},
58
+ onChunk?: (chunk: string) => void): Promise<InteractionExecutionResult<P>> {
59
+ const stream = !!onChunk;
60
+ const response = await client.post('/api/v1/execute', {
61
+ payload: {
62
+ ...payload,
63
+ interaction,
64
+ stream
65
+ } as NamedInteractionExecutionPayload,
66
+ });
67
+ if (stream) {
68
+ if (response.status === ExecutionRunStatus.failed) {
69
+ return response;
70
+ }
71
+ await handleStreaming(client, response.id, onChunk);
72
+ }
73
+ return response;
74
+ }
75
+
76
+ function handleStreaming(client: VertesiaClient, runId: string, onChunk: (chunk: string) => void) {
77
+ return new Promise(async (resolve, reject) => {
78
+ try {
79
+ const EventSourceImpl = await EventSourceProvider();
80
+ const streamUrl = new URL(client.runs.baseUrl + '/' + runId + '/stream');
81
+ const bearerToken = client._auth ? await client._auth() : undefined;
82
+
83
+ if (bearerToken) {
84
+ const token = bearerToken.split(' ')[1];
85
+ streamUrl.searchParams.set('access_token', token);
86
+ } else {
87
+ throw new Error('No auth token available');
88
+ }
89
+
90
+ const sse = new EventSourceImpl(streamUrl.href);
91
+ sse.addEventListener("message", ev => {
92
+ try {
93
+ const data = JSON.parse(ev.data);
94
+ if (data) {
95
+ onChunk && onChunk(data);
96
+ }
97
+ } catch (err) {
98
+ reject(err);
99
+ }
100
+ });
101
+ sse.addEventListener("close", (ev) => {
102
+ try {
103
+ sse.close();
104
+ const msg = JSON.parse(ev.data)
105
+ resolve(msg);
106
+ } catch (err) {
107
+ reject(err);
108
+ }
109
+ });
110
+ } catch (err) {
111
+ reject(err);
112
+ }
113
+ });
114
+ }
115
+
116
+ export async function executeInteractionAsync(client: VertesiaClient, payload: AsyncExecutionPayload): Promise<{ runId: string, workflowId: string }> {
117
+ return await client.post('/api/v1/execute/async', {
118
+ payload,
119
+ });
120
+ }
121
+
122
+ export async function checkRateLimit(client: VertesiaClient, payload: RateLimitRequestPayload): Promise<RateLimitRequestResponse> {
123
+ return await client.post('/api/v1/execute/rate-limit/request', {
124
+ payload
125
+ });
126
+ }
package/src/index.ts ADDED
@@ -0,0 +1,10 @@
1
+ export type { OrphanedAppInstallation } from "./AppsApi.js";
2
+ export * from './client.js';
3
+ export type { GroupsQueryOptions } from './GroupsApi.js';
4
+ export * from './InteractionBase.js';
5
+ export * from './InteractionOutput.js';
6
+ export type { AsyncExecutionResult, ComputeInteractionFacetsResponse } from './InteractionsApi.js';
7
+ export type { ComputePromptFacetsResponse, ListInteractionsResponse } from './PromptsApi.js';
8
+ export type { ComputeRunFacetsResponse, FilterOption } from './RunsApi.js';
9
+ export * from "./store/index.js";
10
+ export * from "./StreamSource.js";
@@ -0,0 +1,43 @@
1
+ import type { Readable } from "node:stream";
2
+ import { ReadableStream as NodeReadableStream } from "node:stream/web";
3
+ import { StreamSource } from "../StreamSource.js";
4
+
5
+
6
+ /**
7
+ * A stream source that wraps a Node.js Readable stream.
8
+ * This class is only works in Node.js environments.
9
+ */
10
+ export class NodeStreamSource extends StreamSource {
11
+ constructor(stream: Readable, name: string, type?: string, id?: string) {
12
+ super(readableToWebStream(stream) as ReadableStream, name, type, id);
13
+ }
14
+ }
15
+
16
+ function readableToWebStream<T = string | Buffer>(stream: Readable): ReadableStream<T> {
17
+ if (NodeReadableStream.from) {
18
+ return NodeReadableStream.from(stream) as ReadableStream<T>;
19
+ } else {
20
+ return readableToWebStream_BUN(stream);
21
+ }
22
+ }
23
+
24
+ /**
25
+ * Bun implementation since bun is not yet supporting NodeReadableStream.from
26
+ * @returns
27
+ */
28
+ function readableToWebStream_BUN<T = string | Buffer>(stream: Readable): ReadableStream<T> {
29
+ const it = stream[Symbol.asyncIterator]();
30
+ return new ReadableStream<T>({
31
+ async pull(controller) {
32
+ const { value, done } = await it.next();
33
+ if (done) {
34
+ controller.close();
35
+ } else {
36
+ controller.enqueue(value);
37
+ }
38
+ },
39
+ cancel() {
40
+ it.return?.();
41
+ }
42
+ });
43
+ }
@@ -0,0 +1 @@
1
+ export * from "./NodeStreamSource.js";
@@ -0,0 +1,61 @@
1
+ import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
2
+ import { AdaptedTable, AdaptTablesRequest, DocAnalyzerResultResponse, DocAnalyzeRunStatusResponse, DocImage, DocTableCsv, DocTableJson, ExportTableFormats, GetAdaptedTablesRequestQuery, PdfToRichtextOptions, WorkflowRunStatus } from "@vertesia/common";
3
+
4
+ export class AnalyzeDocApi extends ApiTopic {
5
+ constructor(parent: ClientBase, public objectId: string) {
6
+ super(parent, `/${objectId}/analyze`);
7
+ }
8
+
9
+ async start(payload: PdfToRichtextOptions): Promise<DocAnalyzeRunStatusResponse> {
10
+ return this.post("/", { payload });
11
+ }
12
+
13
+ async getStatus(): Promise<DocAnalyzeRunStatusResponse> {
14
+ return this.get("/status");
15
+ }
16
+
17
+ async getResults(): Promise<DocAnalyzerResultResponse> {
18
+ return this.get("/results");
19
+ }
20
+
21
+ async adaptTables(payload: AdaptTablesRequest): Promise<WorkflowRunStatus> {
22
+ return this.post("/adapt_tables", { payload });
23
+ }
24
+
25
+ async getAdaptedTables(runId?: string, query?: GetAdaptedTablesRequestQuery): Promise<Record<number, AdaptedTable>> {
26
+ const path = runId ? `/adapt_tables/${runId}` : "/adapt_tables";
27
+
28
+ // Build query parameters
29
+ const queryParams: any = {};
30
+ if (query?.format) queryParams.format = query.format;
31
+ if (query?.raw !== undefined) queryParams.raw = query.raw;
32
+
33
+ // If format is CSV, set response type to text to avoid automatic JSON parsing
34
+ const options: any = { query: queryParams };
35
+ if (query?.format === 'csv') {
36
+ options.responseType = 'text';
37
+ }
38
+
39
+ return this.get(path, options);
40
+ }
41
+
42
+ async getXml(): Promise<string> {
43
+ return this.get("/xml");
44
+ }
45
+
46
+ async getTables(format?: ExportTableFormats): Promise<DocTableCsv[] | DocTableJson[]> {
47
+ const options: any = {};
48
+ if (format) {
49
+ options.query = {format: format}
50
+ }
51
+ return this.get("/tables", options);
52
+ }
53
+
54
+ async getImages(): Promise<DocImage[]> {
55
+ return this.get("/images");
56
+ }
57
+
58
+ async getAnnotated(): Promise<{ url: string }> {
59
+ return this.get("/annotated");
60
+ }
61
+ }