@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
@@ -0,0 +1,752 @@
1
+ import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
2
+ import {
3
+ ActivityCatalog,
4
+ AgentEvent,
5
+ AgentMessage,
6
+ AgentMessageType,
7
+ CompactMessage,
8
+ CreateWorkflowRulePayload,
9
+ DSLWorkflowDefinition,
10
+ DSLWorkflowSpec,
11
+ ErrorAnalyticsResponse,
12
+ ExecuteWorkflowPayload,
13
+ FirstResponseBehaviorAnalyticsResponse,
14
+ LatencyAnalyticsResponse,
15
+ ListWorkflowInteractionsResponse,
16
+ ListWorkflowRunsPayload,
17
+ ListWorkflowRunsResponse,
18
+ parseMessage,
19
+ toAgentMessage,
20
+ PromptSizeAnalyticsResponse,
21
+ RunsByAgentAnalyticsResponse,
22
+ TimeToFirstResponseAnalyticsResponse,
23
+ TokenUsageAnalyticsResponse,
24
+ ToolAnalyticsResponse,
25
+ ToolParameterAnalyticsResponse,
26
+ TopPrincipalsAnalyticsResponse,
27
+ WebSocketClientMessage,
28
+ WebSocketServerMessage,
29
+ WorkflowActionPayload,
30
+ WorkflowAnalyticsFilterOptionsResponse,
31
+ WorkflowAnalyticsSummaryQuery,
32
+ WorkflowAnalyticsSummaryResponse,
33
+ WorkflowAnalyticsTimeSeriesQuery,
34
+ WorkflowDefinitionRef,
35
+ WorkflowRule,
36
+ WorkflowRuleItem,
37
+ WorkflowRunWithDetails,
38
+ WorkflowToolParametersQuery,
39
+ } from "@vertesia/common";
40
+ import { VertesiaClient } from "../client.js";
41
+ import { EventSourceProvider } from "../execute.js";
42
+
43
+ export class WorkflowsApi extends ApiTopic {
44
+ constructor(parent: ClientBase) {
45
+ super(parent, "/api/v1/workflows");
46
+ }
47
+
48
+ getActivityCatalog(): Promise<ActivityCatalog> {
49
+ return this.get("/activity-catalog");
50
+ }
51
+
52
+ listRuns(documentId: string, eventName: string, ruleId: string): Promise<ListWorkflowRunsResponse> {
53
+ return this.post(`/runs`, { payload: { documentId, eventName, ruleId } });
54
+ }
55
+
56
+ /** List conversations the users has access to */
57
+ listConversations(payload: ListWorkflowRunsPayload): Promise<ListWorkflowRunsResponse> {
58
+ return this.post(`/conversations`, {
59
+ payload
60
+ });
61
+ }
62
+
63
+ searchRuns(payload: ListWorkflowRunsPayload): Promise<ListWorkflowRunsResponse> {
64
+ return this.post(`/runs`, { payload: payload });
65
+ }
66
+
67
+ sendSignal(workflowId: string, runId: string, signal: string, payload?: any): Promise<{ message: string }> {
68
+ return this.post(`/runs/${workflowId}/${runId}/signal/${signal}`, { payload });
69
+ }
70
+
71
+ getRunDetails(runId: string, workflowId: string, includeHistory: boolean = false): Promise<WorkflowRunWithDetails> {
72
+ const query = { include_history: includeHistory };
73
+ return this.get(`/runs/${workflowId}/${runId}`, { query });
74
+ }
75
+
76
+ getRunInteraction(workflowId: string, runId: string): Promise<ListWorkflowInteractionsResponse> {
77
+ return this.get(`/runs/${workflowId}/${runId}/interaction`);
78
+ }
79
+
80
+ terminate(workflowId: string, runId: string, reason?: string): Promise<{ message: string }> {
81
+ const payload: WorkflowActionPayload = { reason };
82
+ return this.post(`/runs/${workflowId}/${runId}/actions/terminate`, { payload });
83
+ }
84
+
85
+ cancel(workflowId: string, runId: string, reason?: string): Promise<{ message: string }> {
86
+ const payload: WorkflowActionPayload = { reason };
87
+ return this.post(`/runs/${workflowId}/${runId}/actions/cancel`, { payload });
88
+ }
89
+
90
+ /**
91
+ * Query a workflow for its current state.
92
+ * The workflow must have a query handler registered with the given name.
93
+ * @param workflowId The workflow ID
94
+ * @param runId The run ID
95
+ * @param queryName The name of the query to execute (e.g., "BatchAgentProgress")
96
+ * @returns The query result
97
+ */
98
+ query<T = unknown>(workflowId: string, runId: string, queryName: string): Promise<T> {
99
+ return this.get(`/runs/${workflowId}/${runId}/query/${queryName}`);
100
+ }
101
+
102
+ execute(
103
+ name: string,
104
+ payload: ExecuteWorkflowPayload = {},
105
+ ): Promise<({ run_id: string; workflow_id: string } | undefined)[]> {
106
+ return this.post(`/execute/${name}`, { payload });
107
+ }
108
+
109
+ postMessage(runId: string, msg: AgentMessage): Promise<void> {
110
+ if (!runId) {
111
+ throw new Error("runId is required");
112
+ }
113
+ return this.post(`/runs/${runId}/updates`, { payload: msg });
114
+ }
115
+
116
+ /**
117
+ * Retrieve historical messages for a workflow run.
118
+ * Returns messages in AgentMessage format for backward compatibility.
119
+ * This endpoint returns gzip-compressed responses for large payloads (> 3KB).
120
+ */
121
+ async retrieveMessages(workflowId: string, runId: string, since?: number): Promise<AgentMessage[]> {
122
+ const query = { since };
123
+ const response = await this.get(`/runs/${workflowId}/${runId}/updates`, { query }) as { messages: CompactMessage[] };
124
+ // Convert compact messages to AgentMessage for backward compatibility
125
+ return response.messages.map((m: CompactMessage) => toAgentMessage(m, runId));
126
+ }
127
+
128
+ /**
129
+ * Stream workflow messages in real-time via SSE.
130
+ *
131
+ * This method fetches historical messages via GET /updates (gzip-compressed for large payloads)
132
+ * then connects to SSE for real-time updates only (skipHistory=true).
133
+ *
134
+ * This approach provides better performance for conversations with large historical messages
135
+ * since HTTP responses are compressed while SSE streams cannot be compressed.
136
+ */
137
+ async streamMessages(workflowId: string, runId: string, onMessage?: (message: AgentMessage, exitFn?: (payload: unknown) => void) => void, since?: number): Promise<unknown> {
138
+ return new Promise<unknown>(async (resolve, reject) => {
139
+ let reconnectAttempts = 0;
140
+ let lastMessageTimestamp = since || 0;
141
+ let isClosed = false;
142
+ let currentSse: EventSource | null = null;
143
+ let interval: NodeJS.Timeout | null = null;
144
+
145
+ const maxReconnectAttempts = 10;
146
+ const baseDelay = 1000; // 1 second base delay
147
+ const maxDelay = 30000; // 30 seconds max delay
148
+
149
+ const calculateBackoffDelay = (attempts: number): number => {
150
+ const exponentialDelay = Math.min(baseDelay * Math.pow(2, attempts), maxDelay);
151
+ // Add jitter to prevent thundering herd
152
+ const jitter = Math.random() * 0.1 * exponentialDelay;
153
+ return exponentialDelay + jitter;
154
+ };
155
+
156
+ const cleanup = () => {
157
+ if (interval) {
158
+ clearInterval(interval);
159
+ interval = null;
160
+ }
161
+ if (currentSse) {
162
+ currentSse.close();
163
+ currentSse = null;
164
+ }
165
+ };
166
+
167
+ const exit = (payload: unknown) => {
168
+ if (!isClosed) {
169
+ isClosed = true;
170
+ cleanup();
171
+ resolve(payload);
172
+ }
173
+ };
174
+
175
+ // 1. Fetch historical messages via GET /updates (gzip-compressed if > 3KB)
176
+ // This is more efficient than receiving historical over uncompressed SSE
177
+ try {
178
+ const historical = await this.retrieveMessages(workflowId, runId, since);
179
+ for (const msg of historical) {
180
+ // Update timestamp for SSE connection
181
+ lastMessageTimestamp = Math.max(lastMessageTimestamp, msg.timestamp || 0);
182
+
183
+ // Deliver historical messages to consumer
184
+ if (onMessage) {
185
+ onMessage(msg, exit);
186
+ }
187
+
188
+ // Check if workflow already completed
189
+ const workstreamId = msg.workstream_id || 'main';
190
+ const streamIsOver = msg.type === AgentMessageType.TERMINATED ||
191
+ (msg.type === AgentMessageType.COMPLETE && workstreamId === 'main');
192
+ if (streamIsOver) {
193
+ console.log("Workflow already completed in historical messages");
194
+ resolve(null);
195
+ return;
196
+ }
197
+ }
198
+ } catch (err) {
199
+ console.warn("Failed to fetch historical messages, continuing with SSE:", err);
200
+ // Continue to SSE - it will send historical if skipHistory is not set
201
+ }
202
+
203
+ // 2. Connect to SSE for real-time updates only (skipHistory=true)
204
+ const setupStream = async (isReconnect: boolean = false) => {
205
+ if (isClosed) return;
206
+
207
+ try {
208
+ const EventSourceImpl = await EventSourceProvider();
209
+ const client = this.client as VertesiaClient;
210
+ const streamUrl = new URL(client.workflows.baseUrl + `/runs/${workflowId}/${runId}/stream`);
211
+
212
+ // Use the timestamp of the last received message for reconnection
213
+ if (lastMessageTimestamp > 0) {
214
+ streamUrl.searchParams.set("since", lastMessageTimestamp.toString());
215
+ }
216
+
217
+ // Skip historical messages - we already fetched them via GET /updates
218
+ streamUrl.searchParams.set("skipHistory", "true");
219
+
220
+ const bearerToken = client._auth ? await client._auth() : undefined;
221
+ if (!bearerToken) {
222
+ reject(new Error("No auth token available"));
223
+ return;
224
+ }
225
+
226
+ const token = bearerToken.split(" ")[1];
227
+ streamUrl.searchParams.set("access_token", token);
228
+
229
+ if (isReconnect) {
230
+ console.log(`Reconnecting to SSE stream for run ${runId} (attempt ${reconnectAttempts + 1}/${maxReconnectAttempts})`);
231
+ }
232
+
233
+ const sse = new EventSourceImpl(streamUrl.href);
234
+ currentSse = sse;
235
+
236
+ // Prevent Node from exiting prematurely
237
+ interval = setInterval(() => { }, 1000);
238
+
239
+ sse.onopen = () => {
240
+ if (isReconnect) {
241
+ console.log(`Successfully reconnected to SSE stream for run ${runId}`);
242
+ }
243
+ // Reset reconnect attempts on successful connection
244
+ reconnectAttempts = 0;
245
+ };
246
+
247
+ sse.onmessage = (ev: MessageEvent) => {
248
+ if (!ev.data || ev.data.startsWith(":")) {
249
+ console.log("Received comment or heartbeat; ignoring it.: ", ev.data);
250
+ return;
251
+ }
252
+
253
+ try {
254
+ // Parse message using parseMessage() which handles both compact and legacy formats
255
+ const compactMessage = parseMessage(ev.data);
256
+
257
+ // Update last message timestamp for reconnection (use ts field or current time)
258
+ if (compactMessage.ts) {
259
+ lastMessageTimestamp = Math.max(lastMessageTimestamp, compactMessage.ts);
260
+ } else {
261
+ lastMessageTimestamp = Date.now();
262
+ }
263
+
264
+ // Convert to AgentMessage for consumers (they shouldn't need to know about compact format)
265
+ if (onMessage) {
266
+ const agentMessage = toAgentMessage(compactMessage, runId);
267
+ onMessage(agentMessage, exit);
268
+ }
269
+
270
+ // Get workstream ID (defaults to 'main' if not set)
271
+ const workstreamId = compactMessage.w || 'main';
272
+
273
+ const streamIsOver = compactMessage.t === AgentMessageType.TERMINATED ||
274
+ (compactMessage.t === AgentMessageType.COMPLETE && workstreamId === 'main');
275
+
276
+ // Only close the stream when the main workstream completes or terminates
277
+ if (streamIsOver) {
278
+ console.log("Closing stream due to COMPLETE message from main workstream");
279
+ if (!isClosed) {
280
+ isClosed = true;
281
+ cleanup();
282
+ resolve(null);
283
+ }
284
+ } else if (compactMessage.t === AgentMessageType.COMPLETE) {
285
+ console.log(`Received COMPLETE message from non-main workstream: ${workstreamId}, keeping stream open`);
286
+ }
287
+ } catch (err) {
288
+ console.error("Failed to parse SSE message:", err, ev.data);
289
+ }
290
+ };
291
+
292
+ sse.onerror = (err: any) => {
293
+ if (isClosed) return;
294
+
295
+ console.warn(`SSE stream error for run ${runId}:`, err);
296
+ cleanup();
297
+
298
+ // Check if we should attempt reconnection
299
+ if (reconnectAttempts < maxReconnectAttempts) {
300
+ const delay = calculateBackoffDelay(reconnectAttempts);
301
+ console.log(`Attempting to reconnect in ${delay}ms (attempt ${reconnectAttempts + 1}/${maxReconnectAttempts})`);
302
+
303
+ reconnectAttempts++;
304
+ setTimeout(() => {
305
+ if (!isClosed) {
306
+ setupStream(true);
307
+ }
308
+ }, delay);
309
+ } else {
310
+ console.error(`Failed to reconnect to SSE stream for run ${runId} after ${maxReconnectAttempts} attempts`);
311
+ isClosed = true;
312
+ reject(new Error(`SSE connection failed after ${maxReconnectAttempts} reconnection attempts`));
313
+ }
314
+ };
315
+ } catch (err) {
316
+ console.error("Error setting up SSE stream:", err);
317
+ if (reconnectAttempts < maxReconnectAttempts) {
318
+ const delay = calculateBackoffDelay(reconnectAttempts);
319
+ reconnectAttempts++;
320
+ setTimeout(() => {
321
+ if (!isClosed) {
322
+ setupStream(true);
323
+ }
324
+ }, delay);
325
+ } else {
326
+ reject(err);
327
+ }
328
+ }
329
+ };
330
+
331
+ // Start the async setup process
332
+ setupStream(false);
333
+
334
+ // Return cleanup function for external cancellation
335
+ return () => {
336
+ isClosed = true;
337
+ cleanup();
338
+ };
339
+ });
340
+ }
341
+
342
+ /**
343
+ * Stream workflow messages via WebSocket (for mobile/React Native clients)
344
+ * @param workflowId The workflow ID
345
+ * @param runId The run ID
346
+ * @param onMessage Callback for incoming messages (CompactMessage format)
347
+ * @param since Optional timestamp to resume from
348
+ * @returns Promise that resolves with cleanup function and sendSignal helper
349
+ */
350
+ async streamMessagesWS(
351
+ workflowId: string,
352
+ runId: string,
353
+ onMessage?: (message: CompactMessage) => void,
354
+ since?: number
355
+ ): Promise<{ cleanup: () => void; sendSignal: (signalName: string, data: any) => void }> {
356
+ return new Promise((resolve, reject) => {
357
+ let reconnectAttempts = 0;
358
+ const maxReconnectAttempts = 10;
359
+ const baseDelay = 1000;
360
+ const maxDelay = 30000;
361
+ let ws: WebSocket | null = null;
362
+ let lastMessageTimestamp = since || 0;
363
+ let isClosed = false;
364
+
365
+ const calculateBackoffDelay = (attempts: number): number => {
366
+ const exponentialDelay = Math.min(baseDelay * Math.pow(2, attempts), maxDelay);
367
+ const jitter = Math.random() * 0.1 * exponentialDelay;
368
+ return exponentialDelay + jitter;
369
+ };
370
+
371
+ const connect = async () => {
372
+ if (isClosed) return;
373
+
374
+ try {
375
+ const client = this.client as VertesiaClient;
376
+ const wsUrl = new URL(client.workflows.baseUrl + `/runs/${workflowId}/${runId}/ws`);
377
+
378
+ // Replace http/https with ws/wss
379
+ wsUrl.protocol = wsUrl.protocol.replace('http', 'ws');
380
+
381
+ // Add query parameters
382
+ if (lastMessageTimestamp > 0) {
383
+ wsUrl.searchParams.set('since', lastMessageTimestamp.toString());
384
+ }
385
+
386
+ const bearerToken = client._auth ? await client._auth() : undefined;
387
+ if (!bearerToken) {
388
+ reject(new Error('No auth token available'));
389
+ return;
390
+ }
391
+
392
+ const token = bearerToken.split(' ')[1];
393
+ wsUrl.searchParams.set('access_token', token);
394
+
395
+ if (reconnectAttempts > 0) {
396
+ console.log(`Reconnecting to WebSocket for run ${runId} (attempt ${reconnectAttempts + 1}/${maxReconnectAttempts})`);
397
+ }
398
+
399
+ ws = new WebSocket(wsUrl.href);
400
+
401
+ ws.onopen = () => {
402
+ if (reconnectAttempts > 0) {
403
+ console.log(`Successfully reconnected to WebSocket for run ${runId}`);
404
+ }
405
+ reconnectAttempts = 0;
406
+
407
+ // Resolve with helpers on first successful connection
408
+ if (!isClosed) {
409
+ resolve({
410
+ cleanup: () => {
411
+ isClosed = true;
412
+ if (ws) {
413
+ ws.close();
414
+ ws = null;
415
+ }
416
+ },
417
+ sendSignal: (signalName: string, data: any) => {
418
+ if (ws?.readyState === WebSocket.OPEN) {
419
+ const message: WebSocketClientMessage = {
420
+ type: 'signal',
421
+ signalName,
422
+ data,
423
+ requestId: Date.now()
424
+ };
425
+ ws.send(JSON.stringify(message));
426
+ } else {
427
+ console.warn('WebSocket not open, cannot send signal');
428
+ }
429
+ }
430
+ });
431
+ }
432
+ };
433
+
434
+ ws.onmessage = (event: MessageEvent) => {
435
+ try {
436
+ const rawMessage = JSON.parse(event.data) as WebSocketServerMessage;
437
+
438
+ // Handle control messages (pong, ack, error)
439
+ if ('type' in rawMessage && typeof rawMessage.type === 'string') {
440
+ if (rawMessage.type === 'pong') {
441
+ console.debug('Received pong');
442
+ return;
443
+ } else if (rawMessage.type === 'ack') {
444
+ console.debug('Signal acknowledged', rawMessage);
445
+ return;
446
+ } else if (rawMessage.type === 'error') {
447
+ console.error('WebSocket error message', rawMessage);
448
+ return;
449
+ }
450
+ }
451
+
452
+ // Parse agent message (handles both compact and legacy formats)
453
+ const message = parseMessage(rawMessage);
454
+
455
+ // Update timestamp for reconnection
456
+ if (message.ts) {
457
+ lastMessageTimestamp = Math.max(lastMessageTimestamp, message.ts);
458
+ } else {
459
+ lastMessageTimestamp = Date.now();
460
+ }
461
+
462
+ if (onMessage) onMessage(message);
463
+
464
+ // Get workstream ID (defaults to 'main' if not set)
465
+ const workstreamId = message.w || 'main';
466
+
467
+ // Check for stream completion
468
+ const streamIsOver =
469
+ message.t === AgentMessageType.TERMINATED ||
470
+ (message.t === AgentMessageType.COMPLETE && workstreamId === 'main');
471
+
472
+ if (streamIsOver) {
473
+ console.log('Closing WebSocket due to workflow completion');
474
+ isClosed = true;
475
+ if (ws) {
476
+ ws.close();
477
+ ws = null;
478
+ }
479
+ }
480
+ } catch (err) {
481
+ console.error('Failed to parse WebSocket message', err);
482
+ }
483
+ };
484
+
485
+ ws.onerror = (err) => {
486
+ console.error('WebSocket error', err);
487
+ };
488
+
489
+ ws.onclose = () => {
490
+ if (!isClosed && reconnectAttempts < maxReconnectAttempts) {
491
+ const delay = calculateBackoffDelay(reconnectAttempts);
492
+ console.log(`WebSocket closed, reconnecting in ${delay}ms (attempt ${reconnectAttempts + 1}/${maxReconnectAttempts})`);
493
+ reconnectAttempts++;
494
+ setTimeout(connect, delay);
495
+ } else if (reconnectAttempts >= maxReconnectAttempts) {
496
+ reject(new Error(`WebSocket connection failed after ${maxReconnectAttempts} attempts`));
497
+ }
498
+ };
499
+ } catch (err) {
500
+ console.error('Error setting up WebSocket', err);
501
+ if (reconnectAttempts < maxReconnectAttempts) {
502
+ const delay = calculateBackoffDelay(reconnectAttempts);
503
+ reconnectAttempts++;
504
+ setTimeout(connect, delay);
505
+ } else {
506
+ reject(err);
507
+ }
508
+ }
509
+ };
510
+
511
+ connect();
512
+ });
513
+ }
514
+
515
+ /**
516
+ * Ingest telemetry events for a workflow run.
517
+ * Workers use this to send telemetry to zeno-server for BigQuery storage.
518
+ */
519
+ ingestEvents(
520
+ workflowId: string,
521
+ runId: string,
522
+ events: AgentEvent[]
523
+ ): Promise<{ ingested: number; status?: string; error?: string }> {
524
+ return this.post(`/runs/${workflowId}/${runId}/events`, {
525
+ payload: { events },
526
+ });
527
+ }
528
+
529
+ // ========================================================================
530
+ // Analytics API
531
+ // ========================================================================
532
+
533
+ /**
534
+ * Get workflow analytics summary.
535
+ * Returns overall metrics including token usage, success rates, and run counts.
536
+ */
537
+ getAnalyticsSummary(
538
+ query: WorkflowAnalyticsSummaryQuery = {}
539
+ ): Promise<WorkflowAnalyticsSummaryResponse> {
540
+ return this.post('/analytics/summary', { payload: query });
541
+ }
542
+
543
+ /**
544
+ * Get token usage analytics.
545
+ * Returns token consumption metrics by model, agent, tool, or over time.
546
+ */
547
+ getTokenUsageAnalytics(
548
+ query: WorkflowAnalyticsTimeSeriesQuery = {}
549
+ ): Promise<TokenUsageAnalyticsResponse> {
550
+ return this.post('/analytics/tokens', { payload: query });
551
+ }
552
+
553
+ /**
554
+ * Get LLM latency analytics.
555
+ * Returns duration/latency metrics for LLM calls.
556
+ */
557
+ getLlmLatencyAnalytics(
558
+ query: WorkflowAnalyticsTimeSeriesQuery = {}
559
+ ): Promise<LatencyAnalyticsResponse> {
560
+ return this.post('/analytics/latency/llm', { payload: query });
561
+ }
562
+
563
+ /**
564
+ * Get tool latency analytics.
565
+ * Returns duration/latency metrics for tool calls.
566
+ */
567
+ getToolLatencyAnalytics(
568
+ query: WorkflowAnalyticsTimeSeriesQuery = {}
569
+ ): Promise<LatencyAnalyticsResponse> {
570
+ return this.post('/analytics/latency/tools', { payload: query });
571
+ }
572
+
573
+ /**
574
+ * Get agent/workflow latency analytics.
575
+ * Returns duration metrics for complete workflow runs.
576
+ */
577
+ getAgentLatencyAnalytics(
578
+ query: WorkflowAnalyticsTimeSeriesQuery = {}
579
+ ): Promise<LatencyAnalyticsResponse> {
580
+ return this.post('/analytics/latency/agents', { payload: query });
581
+ }
582
+
583
+ /**
584
+ * Get error analytics.
585
+ * Returns error rates, types, and trends.
586
+ */
587
+ getErrorAnalytics(
588
+ query: WorkflowAnalyticsTimeSeriesQuery = {}
589
+ ): Promise<ErrorAnalyticsResponse> {
590
+ return this.post('/analytics/errors', { payload: query });
591
+ }
592
+
593
+ /**
594
+ * Get tool usage analytics.
595
+ * Returns tool invocation counts, success rates, and performance metrics.
596
+ */
597
+ getToolAnalytics(
598
+ query: WorkflowAnalyticsSummaryQuery = {}
599
+ ): Promise<ToolAnalyticsResponse> {
600
+ return this.post('/analytics/tools', { payload: query });
601
+ }
602
+
603
+ /**
604
+ * Get tool parameter analytics.
605
+ * Returns parameter value distributions for a specific tool.
606
+ */
607
+ getToolParameterAnalytics(
608
+ query: WorkflowToolParametersQuery
609
+ ): Promise<ToolParameterAnalyticsResponse> {
610
+ return this.post('/analytics/tools/parameters', { payload: query });
611
+ }
612
+
613
+ /**
614
+ * Get available filter options for analytics.
615
+ * Returns unique agents, environments, and models from telemetry data.
616
+ */
617
+ getAnalyticsFilterOptions(
618
+ query: WorkflowAnalyticsSummaryQuery = {}
619
+ ): Promise<WorkflowAnalyticsFilterOptionsResponse> {
620
+ return this.post('/analytics/filter-options', { payload: query });
621
+ }
622
+
623
+ /**
624
+ * Get average prompt size (input tokens) by agent for startConversation calls.
625
+ * This represents the initial prompt + tools size.
626
+ */
627
+ getPromptSizeAnalytics(
628
+ query: WorkflowAnalyticsSummaryQuery = {}
629
+ ): Promise<PromptSizeAnalyticsResponse> {
630
+ return this.post('/analytics/prompt-size', { payload: query });
631
+ }
632
+
633
+ /**
634
+ * Get top principals (users/API keys) who started the most agent runs.
635
+ * Returns the top N principals sorted by run count descending.
636
+ */
637
+ getTopPrincipalsAnalytics(
638
+ query: WorkflowAnalyticsSummaryQuery = {}
639
+ ): Promise<TopPrincipalsAnalyticsResponse> {
640
+ return this.post('/analytics/top-principals', { payload: query });
641
+ }
642
+
643
+ /**
644
+ * Get agent run distribution - how many runs per agent/interaction type.
645
+ * Returns the top N agents sorted by run count descending.
646
+ */
647
+ getRunsByAgentAnalytics(
648
+ query: WorkflowAnalyticsSummaryQuery = {}
649
+ ): Promise<RunsByAgentAnalyticsResponse> {
650
+ return this.post('/analytics/runs-by-agent', { payload: query });
651
+ }
652
+
653
+ /**
654
+ * Get time to first response analytics.
655
+ * Measures the time from agent start to the completion of the first LLM call.
656
+ * Returns average, min, max, median, p95, and p99 metrics.
657
+ */
658
+ getTimeToFirstResponseAnalytics(
659
+ query: WorkflowAnalyticsTimeSeriesQuery = {}
660
+ ): Promise<TimeToFirstResponseAnalyticsResponse> {
661
+ return this.post('/analytics/time-to-first-response', { payload: query });
662
+ }
663
+
664
+ /**
665
+ * Get first response behavior analytics.
666
+ * Analyzes the agent's first LLM response behavior:
667
+ * - Percentage of agents that start by making a plan
668
+ * - Percentage of agents that return no tool calls at start
669
+ */
670
+ getFirstResponseBehaviorAnalytics(
671
+ query: WorkflowAnalyticsTimeSeriesQuery = {}
672
+ ): Promise<FirstResponseBehaviorAnalyticsResponse> {
673
+ return this.post('/analytics/first-response-behavior', { payload: query });
674
+ }
675
+
676
+ rules = new WorkflowsRulesApi(this);
677
+ definitions = new WorkflowsDefinitionApi(this);
678
+ }
679
+
680
+ export class WorkflowsRulesApi extends ApiTopic {
681
+ constructor(parent: WorkflowsApi) {
682
+ super(parent, "/rules");
683
+ }
684
+
685
+ list(): Promise<WorkflowRuleItem[]> {
686
+ return this.get("/");
687
+ }
688
+
689
+ retrieve(id: string): Promise<WorkflowRule> {
690
+ return this.get(`/${id}`);
691
+ }
692
+
693
+ update(id: string, payload: any): Promise<WorkflowRule> {
694
+ return this.put(`/${id}`, {
695
+ payload,
696
+ });
697
+ }
698
+
699
+ create(payload: CreateWorkflowRulePayload): Promise<WorkflowRule> {
700
+ return this.post("/", {
701
+ payload,
702
+ });
703
+ }
704
+
705
+ delete(id: string) {
706
+ return this.del(`/${id}`);
707
+ }
708
+
709
+ execute(
710
+ id: string,
711
+ objectIds?: string[],
712
+ vars?: Record<string, any>,
713
+ ): Promise<({ run_id: string; workflow_id: string } | undefined)[]> {
714
+ const payload: ExecuteWorkflowPayload = {
715
+ objectIds,
716
+ vars,
717
+ };
718
+ return this.post(`/${id}/execute`, { payload });
719
+ }
720
+ }
721
+
722
+ export class WorkflowsDefinitionApi extends ApiTopic {
723
+ //model: DSLWorkflowDefinition;
724
+
725
+ constructor(parent: WorkflowsApi) {
726
+ super(parent, "/definitions");
727
+ }
728
+
729
+ list(): Promise<WorkflowDefinitionRef[]> {
730
+ return this.get("/");
731
+ }
732
+
733
+ retrieve(id: string): Promise<DSLWorkflowDefinition> {
734
+ return this.get(`/${id}`);
735
+ }
736
+
737
+ update(id: string, payload: any): Promise<DSLWorkflowDefinition> {
738
+ return this.put(`/${id}`, {
739
+ payload,
740
+ });
741
+ }
742
+
743
+ create(payload: DSLWorkflowSpec): Promise<DSLWorkflowDefinition> {
744
+ return this.post("/", {
745
+ payload,
746
+ });
747
+ }
748
+
749
+ delete(id: string) {
750
+ return this.del(`/${id}`);
751
+ }
752
+ }