@vertesia/client 0.78.0-dev-28b447d → 0.79.0

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 (229) hide show
  1. package/lib/cjs/AccountApi.js +85 -0
  2. package/lib/cjs/AccountApi.js.map +1 -0
  3. package/lib/cjs/AccountsApi.js +16 -0
  4. package/lib/cjs/AccountsApi.js.map +1 -0
  5. package/lib/cjs/AnalyticsApi.js +13 -0
  6. package/lib/cjs/AnalyticsApi.js.map +1 -0
  7. package/lib/cjs/ApiKeysApi.js +63 -0
  8. package/lib/cjs/ApiKeysApi.js.map +1 -0
  9. package/lib/cjs/AppsApi.js +119 -0
  10. package/lib/cjs/AppsApi.js.map +1 -0
  11. package/lib/cjs/CommandsApi.js +19 -0
  12. package/lib/cjs/CommandsApi.js.map +1 -0
  13. package/lib/cjs/EnvironmentsApi.js +58 -0
  14. package/lib/cjs/EnvironmentsApi.js.map +1 -0
  15. package/lib/cjs/GroupsApi.js +78 -0
  16. package/lib/cjs/GroupsApi.js.map +1 -0
  17. package/lib/cjs/IamApi.js +53 -0
  18. package/lib/cjs/IamApi.js.map +1 -0
  19. package/lib/cjs/InteractionBase.js +44 -0
  20. package/lib/cjs/InteractionBase.js.map +1 -0
  21. package/lib/cjs/InteractionsApi.js +217 -0
  22. package/lib/cjs/InteractionsApi.js.map +1 -0
  23. package/lib/cjs/ProjectsApi.js +48 -0
  24. package/lib/cjs/ProjectsApi.js.map +1 -0
  25. package/lib/cjs/PromptsApi.js +133 -0
  26. package/lib/cjs/PromptsApi.js.map +1 -0
  27. package/lib/cjs/RefsApi.js +14 -0
  28. package/lib/cjs/RefsApi.js.map +1 -0
  29. package/lib/cjs/RunsApi.js +105 -0
  30. package/lib/cjs/RunsApi.js.map +1 -0
  31. package/lib/cjs/StreamSource.js +17 -0
  32. package/lib/cjs/StreamSource.js.map +1 -0
  33. package/lib/cjs/TrainingApi.js +54 -0
  34. package/lib/cjs/TrainingApi.js.map +1 -0
  35. package/lib/cjs/UsersApi.js +13 -0
  36. package/lib/cjs/UsersApi.js.map +1 -0
  37. package/lib/cjs/client.js +279 -0
  38. package/lib/cjs/client.js.map +1 -0
  39. package/lib/cjs/execute.js +158 -0
  40. package/lib/cjs/execute.js.map +1 -0
  41. package/lib/cjs/index.js +21 -0
  42. package/lib/cjs/index.js.map +1 -0
  43. package/lib/cjs/nodejs/NodeStreamSource.js +45 -0
  44. package/lib/cjs/nodejs/NodeStreamSource.js.map +1 -0
  45. package/lib/cjs/nodejs/index.js +18 -0
  46. package/lib/cjs/nodejs/index.js.map +1 -0
  47. package/lib/cjs/package.json +3 -0
  48. package/lib/cjs/store/AgentsApi.js +16 -0
  49. package/lib/cjs/store/AgentsApi.js.map +1 -0
  50. package/lib/cjs/store/AnalyzeDocApi.js +56 -0
  51. package/lib/cjs/store/AnalyzeDocApi.js.map +1 -0
  52. package/lib/cjs/store/CollectionsApi.js +101 -0
  53. package/lib/cjs/store/CollectionsApi.js.map +1 -0
  54. package/lib/cjs/store/CommandsApi.js +17 -0
  55. package/lib/cjs/store/CommandsApi.js.map +1 -0
  56. package/lib/cjs/store/EmbeddingsApi.js +29 -0
  57. package/lib/cjs/store/EmbeddingsApi.js.map +1 -0
  58. package/lib/cjs/store/FilesApi.js +147 -0
  59. package/lib/cjs/store/FilesApi.js.map +1 -0
  60. package/lib/cjs/store/ObjectsApi.js +281 -0
  61. package/lib/cjs/store/ObjectsApi.js.map +1 -0
  62. package/lib/cjs/store/TypesApi.js +57 -0
  63. package/lib/cjs/store/TypesApi.js.map +1 -0
  64. package/lib/cjs/store/WorkflowsApi.js +265 -0
  65. package/lib/cjs/store/WorkflowsApi.js.map +1 -0
  66. package/lib/cjs/store/client.js +71 -0
  67. package/lib/cjs/store/client.js.map +1 -0
  68. package/lib/cjs/store/errors.js +11 -0
  69. package/lib/cjs/store/errors.js.map +1 -0
  70. package/lib/cjs/store/index.js +22 -0
  71. package/lib/cjs/store/index.js.map +1 -0
  72. package/lib/cjs/store/version.js +6 -0
  73. package/lib/cjs/store/version.js.map +1 -0
  74. package/lib/esm/AccountApi.js +82 -0
  75. package/lib/esm/AccountApi.js.map +1 -0
  76. package/lib/esm/AccountsApi.js +13 -0
  77. package/lib/esm/AccountsApi.js.map +1 -0
  78. package/lib/esm/AnalyticsApi.js +10 -0
  79. package/lib/esm/AnalyticsApi.js.map +1 -0
  80. package/lib/esm/ApiKeysApi.js +59 -0
  81. package/lib/esm/ApiKeysApi.js.map +1 -0
  82. package/lib/esm/AppsApi.js +116 -0
  83. package/lib/esm/AppsApi.js.map +1 -0
  84. package/lib/esm/CommandsApi.js +16 -0
  85. package/lib/esm/CommandsApi.js.map +1 -0
  86. package/lib/esm/EnvironmentsApi.js +55 -0
  87. package/lib/esm/EnvironmentsApi.js.map +1 -0
  88. package/lib/esm/GroupsApi.js +74 -0
  89. package/lib/esm/GroupsApi.js.map +1 -0
  90. package/lib/esm/IamApi.js +47 -0
  91. package/lib/esm/IamApi.js.map +1 -0
  92. package/lib/esm/InteractionBase.js +40 -0
  93. package/lib/esm/InteractionBase.js.map +1 -0
  94. package/lib/esm/InteractionsApi.js +214 -0
  95. package/lib/esm/InteractionsApi.js.map +1 -0
  96. package/lib/esm/ProjectsApi.js +45 -0
  97. package/lib/esm/ProjectsApi.js.map +1 -0
  98. package/lib/esm/PromptsApi.js +130 -0
  99. package/lib/esm/PromptsApi.js.map +1 -0
  100. package/lib/esm/RefsApi.js +10 -0
  101. package/lib/esm/RefsApi.js.map +1 -0
  102. package/lib/esm/RunsApi.js +101 -0
  103. package/lib/esm/RunsApi.js.map +1 -0
  104. package/lib/esm/StreamSource.js +13 -0
  105. package/lib/esm/StreamSource.js.map +1 -0
  106. package/lib/esm/TrainingApi.js +51 -0
  107. package/lib/esm/TrainingApi.js.map +1 -0
  108. package/lib/esm/UsersApi.js +10 -0
  109. package/lib/esm/UsersApi.js.map +1 -0
  110. package/lib/esm/client.js +270 -0
  111. package/lib/esm/client.js.map +1 -0
  112. package/lib/esm/execute.js +118 -0
  113. package/lib/esm/execute.js.map +1 -0
  114. package/lib/esm/index.js +5 -0
  115. package/lib/esm/index.js.map +1 -0
  116. package/lib/esm/nodejs/NodeStreamSource.js +41 -0
  117. package/lib/esm/nodejs/NodeStreamSource.js.map +1 -0
  118. package/lib/esm/nodejs/index.js +2 -0
  119. package/lib/esm/nodejs/index.js.map +1 -0
  120. package/lib/esm/store/AgentsApi.js +12 -0
  121. package/lib/esm/store/AgentsApi.js.map +1 -0
  122. package/lib/esm/store/AnalyzeDocApi.js +52 -0
  123. package/lib/esm/store/AnalyzeDocApi.js.map +1 -0
  124. package/lib/esm/store/CollectionsApi.js +97 -0
  125. package/lib/esm/store/CollectionsApi.js.map +1 -0
  126. package/lib/esm/store/CommandsApi.js +13 -0
  127. package/lib/esm/store/CommandsApi.js.map +1 -0
  128. package/lib/esm/store/EmbeddingsApi.js +25 -0
  129. package/lib/esm/store/EmbeddingsApi.js.map +1 -0
  130. package/lib/esm/store/FilesApi.js +142 -0
  131. package/lib/esm/store/FilesApi.js.map +1 -0
  132. package/lib/esm/store/ObjectsApi.js +277 -0
  133. package/lib/esm/store/ObjectsApi.js.map +1 -0
  134. package/lib/esm/store/TypesApi.js +53 -0
  135. package/lib/esm/store/TypesApi.js.map +1 -0
  136. package/lib/esm/store/WorkflowsApi.js +259 -0
  137. package/lib/esm/store/WorkflowsApi.js.map +1 -0
  138. package/lib/esm/store/client.js +67 -0
  139. package/lib/esm/store/client.js.map +1 -0
  140. package/lib/esm/store/errors.js +7 -0
  141. package/lib/esm/store/errors.js.map +1 -0
  142. package/lib/esm/store/index.js +6 -0
  143. package/lib/esm/store/index.js.map +1 -0
  144. package/lib/esm/store/version.js +3 -0
  145. package/lib/esm/store/version.js.map +1 -0
  146. package/lib/tsconfig.tsbuildinfo +1 -0
  147. package/lib/types/AccountApi.d.ts +59 -0
  148. package/lib/types/AccountApi.d.ts.map +1 -0
  149. package/lib/types/AccountsApi.d.ts +7 -0
  150. package/lib/types/AccountsApi.d.ts.map +1 -0
  151. package/lib/types/AnalyticsApi.d.ts +6 -0
  152. package/lib/types/AnalyticsApi.d.ts.map +1 -0
  153. package/lib/types/ApiKeysApi.d.ts +42 -0
  154. package/lib/types/ApiKeysApi.d.ts.map +1 -0
  155. package/lib/types/AppsApi.d.ts +65 -0
  156. package/lib/types/AppsApi.d.ts.map +1 -0
  157. package/lib/types/CommandsApi.d.ts +10 -0
  158. package/lib/types/CommandsApi.d.ts.map +1 -0
  159. package/lib/types/EnvironmentsApi.d.ts +30 -0
  160. package/lib/types/EnvironmentsApi.d.ts.map +1 -0
  161. package/lib/types/GroupsApi.d.ts +65 -0
  162. package/lib/types/GroupsApi.d.ts.map +1 -0
  163. package/lib/types/IamApi.d.ts +41 -0
  164. package/lib/types/IamApi.d.ts.map +1 -0
  165. package/lib/types/InteractionBase.d.ts +22 -0
  166. package/lib/types/InteractionBase.d.ts.map +1 -0
  167. package/lib/types/InteractionsApi.d.ts +156 -0
  168. package/lib/types/InteractionsApi.d.ts.map +1 -0
  169. package/lib/types/ProjectsApi.d.ts +17 -0
  170. package/lib/types/ProjectsApi.d.ts.map +1 -0
  171. package/lib/types/PromptsApi.d.ts +106 -0
  172. package/lib/types/PromptsApi.d.ts.map +1 -0
  173. package/lib/types/RefsApi.d.ts +6 -0
  174. package/lib/types/RefsApi.d.ts.map +1 -0
  175. package/lib/types/RunsApi.d.ts +77 -0
  176. package/lib/types/RunsApi.d.ts.map +1 -0
  177. package/lib/types/StreamSource.d.ts +7 -0
  178. package/lib/types/StreamSource.d.ts.map +1 -0
  179. package/lib/types/TrainingApi.d.ts +27 -0
  180. package/lib/types/TrainingApi.d.ts.map +1 -0
  181. package/lib/types/UsersApi.d.ts +6 -0
  182. package/lib/types/UsersApi.d.ts.map +1 -0
  183. package/lib/types/client.d.ts +119 -0
  184. package/lib/types/client.d.ts.map +1 -0
  185. package/lib/types/execute.d.ts +37 -0
  186. package/lib/types/execute.d.ts.map +1 -0
  187. package/lib/types/index.d.ts +8 -0
  188. package/lib/types/index.d.ts.map +1 -0
  189. package/lib/types/nodejs/NodeStreamSource.d.ts +9 -0
  190. package/lib/types/nodejs/NodeStreamSource.d.ts.map +1 -0
  191. package/lib/types/nodejs/index.d.ts +1 -0
  192. package/lib/types/nodejs/index.d.ts.map +1 -0
  193. package/lib/types/store/AgentsApi.d.ts +6 -0
  194. package/lib/types/store/AgentsApi.d.ts.map +1 -0
  195. package/lib/types/store/AnalyzeDocApi.d.ts +17 -0
  196. package/lib/types/store/AnalyzeDocApi.d.ts.map +1 -0
  197. package/lib/types/store/CollectionsApi.d.ts +66 -0
  198. package/lib/types/store/CollectionsApi.d.ts.map +1 -0
  199. package/lib/types/store/CommandsApi.d.ts +10 -0
  200. package/lib/types/store/CommandsApi.d.ts.map +1 -0
  201. package/lib/types/store/EmbeddingsApi.d.ts +12 -0
  202. package/lib/types/store/EmbeddingsApi.d.ts.map +1 -0
  203. package/lib/types/store/FilesApi.d.ts +47 -0
  204. package/lib/types/store/FilesApi.d.ts.map +1 -0
  205. package/lib/types/store/ObjectsApi.d.ts +122 -0
  206. package/lib/types/store/ObjectsApi.d.ts.map +1 -0
  207. package/lib/types/store/TypesApi.d.ts +23 -0
  208. package/lib/types/store/TypesApi.d.ts.map +1 -0
  209. package/lib/types/store/WorkflowsApi.d.ts +50 -0
  210. package/lib/types/store/WorkflowsApi.d.ts.map +1 -0
  211. package/lib/types/store/client.d.ts +34 -0
  212. package/lib/types/store/client.d.ts.map +1 -0
  213. package/lib/types/store/errors.d.ts +4 -0
  214. package/lib/types/store/errors.d.ts.map +1 -0
  215. package/lib/types/store/index.d.ts +5 -0
  216. package/lib/types/store/index.d.ts.map +1 -0
  217. package/lib/types/store/version.d.ts +2 -0
  218. package/lib/types/store/version.d.ts.map +1 -0
  219. package/lib/vertesia-client.js +2 -0
  220. package/lib/vertesia-client.js.map +1 -0
  221. package/package.json +54 -59
  222. package/src/InteractionsApi.ts +1 -2
  223. package/src/RunsApi.ts +1 -8
  224. package/src/client.test.ts +0 -2
  225. package/src/client.ts +69 -129
  226. package/src/store/FilesApi.ts +2 -2
  227. package/src/store/WorkflowsApi.ts +0 -166
  228. package/src/store/client.ts +12 -3
  229. package/src/store/version.ts +2 -0
package/src/client.ts CHANGED
@@ -16,6 +16,8 @@ import { RunsApi } from "./RunsApi.js";
16
16
  import { ZenoClient } from "./store/client.js";
17
17
  import TrainingApi from "./TrainingApi.js";
18
18
  import UsersApi from "./UsersApi.js";
19
+ import { VERSION, VERSION_HEADER } from "./store/version.js";
20
+
19
21
 
20
22
  /**
21
23
  * 1 min threshold constant in ms
@@ -35,21 +37,18 @@ export type VertesiaClientProps = {
35
37
  * @default api.vertesia.io
36
38
  * @since 0.52.0
37
39
  */
38
- site?:
39
- | "api.vertesia.io"
40
- | "api-preview.vertesia.io"
41
- | "api-staging.vertesia.io";
40
+ site?: 'api.vertesia.io' | 'api-preview.vertesia.io' | 'api-staging.vertesia.io';
42
41
  serverUrl?: string;
43
42
  storeUrl?: string;
44
- tokenServerUrl?: string;
45
43
  apikey?: string;
46
44
  projectId?: string;
47
45
  sessionTags?: string | string[];
48
46
  onRequest?: (request: Request) => void;
49
47
  onResponse?: (response: Response) => void;
50
- };
48
+ }
51
49
 
52
50
  export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
51
+
53
52
  /**
54
53
  * The JWT token linked to the API KEY (sk or pk)
55
54
  */
@@ -65,15 +64,11 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
65
64
  */
66
65
  sessionTags?: string | string[];
67
66
 
68
- /**
69
- * tokenServerUrl
70
- */
71
- tokenServerUrl: string;
72
67
 
73
68
  /**
74
- * Create a client from the given token.
69
+ * Create a client from the given token.
75
70
  * If you already have the decoded token you can pass it as the second argument to avoid decodinf it again.
76
- *
71
+ *
77
72
  * @param token the raw JWT token
78
73
  * @param payload the decoded JWT token as an AuthTokenPayload - optional
79
74
  */
@@ -81,21 +76,21 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
81
76
  if (!payload) {
82
77
  payload = decodeJWT(token);
83
78
  }
84
-
85
- const endpoints = decodeEndpoints(payload.endpoints);
79
+ const endpoints = decodeEndpoints(payload!.endpoints);
86
80
  return await new VertesiaClient({
87
81
  serverUrl: endpoints.studio,
88
- storeUrl: endpoints.store,
89
- tokenServerUrl: payload.iss,
82
+ storeUrl: endpoints.store
90
83
  }).withApiKey(token);
91
84
  }
92
85
 
93
- static decodeEndpoints() {}
86
+ static decodeEndpoints() {
87
+
88
+ }
94
89
 
95
90
  constructor(
96
91
  opts: VertesiaClientProps = {
97
- site: "api.vertesia.io",
98
- },
92
+ site: 'api.vertesia.io',
93
+ }
99
94
  ) {
100
95
  let studioServerUrl: string;
101
96
  let zenoServerUrl: string;
@@ -105,9 +100,7 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
105
100
  } else if (opts.site) {
106
101
  studioServerUrl = `https://${opts.site}`;
107
102
  } else {
108
- throw new Error(
109
- "Parameter 'site' or 'serverUrl' is required for VertesiaClient",
110
- );
103
+ throw new Error("Parameter 'site' or 'serverUrl' is required for VertesiaClient");
111
104
  }
112
105
 
113
106
  if (opts.storeUrl) {
@@ -115,72 +108,39 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
115
108
  } else if (opts.site) {
116
109
  zenoServerUrl = `https://${opts.site}`;
117
110
  } else {
118
- throw new Error(
119
- "Parameter 'site' or 'storeUrl' is required for VertesiaClient",
120
- );
111
+ throw new Error("Parameter 'site' or 'storeUrl' is required for VertesiaClient");
121
112
  }
122
113
 
123
114
  super(studioServerUrl);
124
115
 
125
- if (opts.tokenServerUrl) {
126
- this.tokenServerUrl = opts.tokenServerUrl;
127
- } else if (opts.site) {
128
- this.tokenServerUrl = `https://${opts.site.replace(/^api/, "sts")}`;
129
- } else if (opts.serverUrl || opts.storeUrl) {
130
- // Determine STS URL based on environment in serverUrl or storeUrl
131
- const urlToCheck = opts.serverUrl || opts.storeUrl || "";
132
- try {
133
- const url = new URL(urlToCheck);
134
- // Check for environment patterns
135
- if (url.hostname.includes("-production.")) {
136
- // zeno-server-production.api.vertesia.io -> sts.vertesia.io
137
- this.tokenServerUrl = "https://sts.vertesia.io";
138
- } else if (url.hostname.includes("-preview.")) {
139
- // zeno-server-preview.api.vertesia.io -> sts-preview.vertesia.io
140
- this.tokenServerUrl = "https://sts-preview.vertesia.io";
141
- } else if (url.hostname === "api.vertesia.io") {
142
- // api.vertesia.io -> sts.vertesia.io
143
- this.tokenServerUrl = "https://sts.vertesia.io";
144
- } else if (url.hostname === "api-preview.vertesia.io") {
145
- // api-preview.vertesia.io -> sts-preview.vertesia.io
146
- this.tokenServerUrl = "https://sts-preview.vertesia.io";
147
- } else if (url.hostname === "api-staging.vertesia.io") {
148
- // api-staging.vertesia.io -> sts-staging.vertesia.io
149
- this.tokenServerUrl = "https://sts-staging.vertesia.io";
150
- } else if (url.hostname.startsWith("api")) {
151
- // Generic api.* pattern replacement
152
- url.hostname = url.hostname.replace(/^api/, "sts");
153
- this.tokenServerUrl = url.toString();
154
- } else {
155
- // Default to staging for everything else
156
- this.tokenServerUrl = "https://sts-staging.vertesia.io";
157
- }
158
- } catch (e) {
159
- // Default to staging if URL parsing fails
160
- this.tokenServerUrl = "https://sts-staging.vertesia.io";
161
- }
162
- } else {
163
- // Default to staging if no URL provided
164
- this.tokenServerUrl = "https://sts-staging.vertesia.io";
165
- }
166
-
167
116
  this.store = new ZenoClient({
168
117
  serverUrl: zenoServerUrl,
169
- tokenServerUrl: this.tokenServerUrl,
170
118
  apikey: opts.apikey,
171
119
  onRequest: opts.onRequest,
172
- onResponse: opts.onResponse,
120
+ onResponse: opts.onResponse
173
121
  });
174
122
 
175
123
  if (opts.apikey) {
176
124
  this.withApiKey(opts.apikey);
177
125
  }
178
-
126
+ //TODO: this is no more used, remove in next major version
127
+ if (opts.projectId) {
128
+ this.headers["x-project-id"] = opts.projectId;
129
+ }
179
130
  this.onRequest = opts.onRequest;
180
131
  this.onResponse = opts.onResponse;
181
132
  this.sessionTags = opts.sessionTags;
182
133
  }
183
134
 
135
+ withApiVersion(version: string | number | null) {
136
+ if (!version) {
137
+ delete this.headers[VERSION_HEADER];
138
+ } else {
139
+ this.headers[VERSION_HEADER] = String(version);
140
+ }
141
+ return this;
142
+ }
143
+
184
144
  /**
185
145
  * Overwrite to keep store and composable clients synchronized on the auth callback
186
146
  * @param authCb
@@ -193,28 +153,25 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
193
153
 
194
154
  async withApiKey(apiKey: string | null) {
195
155
  return this.withAuthCallback(
196
- apiKey
197
- ? async () => {
198
- if (!isApiKey(apiKey)) {
199
- return `Bearer ${apiKey}`;
200
- }
201
-
202
- if (isTokenExpired(this._jwt)) {
203
- const jwt = await this.getAuthToken(apiKey);
204
- this._jwt = jwt.token;
205
- }
206
- return `Bearer ${this._jwt}`;
207
- }
208
- : undefined,
156
+ apiKey ? async () => {
157
+ if (!isApiKey(apiKey)) {
158
+ return `Bearer ${apiKey}`
159
+ }
160
+
161
+ if (isTokenExpired(this._jwt)) {
162
+ const jwt = await this.getAuthToken(apiKey);
163
+ this._jwt = jwt.token;
164
+ }
165
+ return `Bearer ${this._jwt}`
166
+ } : undefined
209
167
  );
210
168
  }
211
169
 
212
170
  async getRawJWT() {
213
171
  if (!this._jwt && this._auth) {
214
172
  const auth = await this._auth();
215
- if (!this._jwt) {
216
- // the _jwt may be set by the auth callback
217
- this._jwt = auth.trim().split(" ")[1]; // remove Bearer prefix
173
+ if (!this._jwt) { // the _jwt may be set by the auth callback
174
+ this._jwt = auth.trim().split(' ')[1]; // remove Bearer prefix
218
175
  }
219
176
  }
220
177
  return this._jwt || null;
@@ -264,35 +221,27 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
264
221
  return this.store.baseUrl;
265
222
  }
266
223
 
224
+
267
225
  /**
268
226
  *
269
- * Generate a token for use with other Vertesia's services
227
+ * Generate a token for use with other Composable's services
270
228
  *
229
+ * @param accountId: selected account to generate the token for
271
230
  * @returns AuthTokenResponse
272
231
  */
273
- async getAuthToken(token?: string): Promise<AuthTokenResponse> {
274
- return fetch(`${this.tokenServerUrl}/token/issue`, {
275
- method: "POST",
276
- headers: {
277
- "Content-Type": "application/json",
278
- Authorization: `Bearer ${token}`,
279
- },
280
- })
281
- .then((response) => response.json())
282
- .then((data) => data as AuthTokenResponse)
283
- .catch((error) => {
284
- console.error(
285
- `Error fetching token from ${this.tokenServerUrl}:`,
286
- { error },
287
- );
288
- throw error;
289
- });
232
+ async getAuthToken(token?: string, accountId?: string): Promise<AuthTokenResponse> {
233
+ const query = {
234
+ accountId,
235
+ token
236
+ };
237
+
238
+ return this.get('/auth/token', { query: query, headers: { "authorization": undefined } as any });
290
239
  }
291
240
 
292
241
  get initialHeaders() {
293
242
  return {
294
243
  ...super.initialHeaders,
295
- 'X-Api-Version': '20250925' // YYYYMMDD, client versioning for API endpoints. Increment manually for breaking changes
244
+ [VERSION_HEADER]: VERSION
296
245
  }
297
246
  }
298
247
 
@@ -314,7 +263,7 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
314
263
  }
315
264
 
316
265
  function isApiKey(apiKey: string) {
317
- return apiKey.startsWith("pk-") || apiKey.startsWith("sk-");
266
+ return (apiKey.startsWith('pk-') || apiKey.startsWith('sk-'));
318
267
  }
319
268
 
320
269
  function isTokenExpired(token: string | null) {
@@ -325,45 +274,38 @@ function isTokenExpired(token: string | null) {
325
274
  const decoded = decodeJWT(token);
326
275
  const exp = decoded.exp;
327
276
  const currentTime = Date.now();
328
- return currentTime <= exp * 1000 - EXPIRATION_THRESHOLD;
277
+ return (currentTime <= exp * 1000 - EXPIRATION_THRESHOLD);
329
278
  }
330
279
 
331
280
  export function decodeJWT(jwt: string): AuthTokenPayload {
332
- const payloadBase64 = jwt.split(".")[1];
281
+ const payloadBase64 = jwt.split('.')[1];
333
282
  const decodedJson = base64UrlDecode(payloadBase64);
334
- return JSON.parse(decodedJson);
283
+ return JSON.parse(decodedJson)
335
284
  }
336
285
 
337
286
  function base64UrlDecode(input: string): string {
338
287
  // Convert base64url to base64
339
- const base64 = input
340
- .replace(/-/g, "+")
341
- .replace(/_/g, "/")
288
+ const base64 = input.replace(/-/g, '+').replace(/_/g, '/')
342
289
  // Pad with '=' to make length a multiple of 4
343
- .padEnd(Math.ceil(input.length / 4) * 4, "=");
290
+ .padEnd(Math.ceil(input.length / 4) * 4, '=');
344
291
 
345
- if (typeof Buffer !== "undefined") {
292
+ if (typeof Buffer !== 'undefined') {
346
293
  // Node.js
347
- return Buffer.from(base64, "base64").toString("utf-8");
348
- } else if (
349
- typeof atob !== "undefined" &&
350
- typeof TextDecoder !== "undefined"
351
- ) {
294
+ return Buffer.from(base64, 'base64').toString('utf-8');
295
+ } else if (typeof atob !== 'undefined' && typeof TextDecoder !== 'undefined') {
352
296
  // Browser
353
297
  const binary = atob(base64);
354
- const bytes = Uint8Array.from(binary, (c) => c.charCodeAt(0));
298
+ const bytes = Uint8Array.from(binary, c => c.charCodeAt(0));
355
299
  // decode to utf8
356
300
  return new TextDecoder().decode(bytes);
357
301
  } else {
358
- throw new Error("No base64 decoder available");
302
+ throw new Error('No base64 decoder available');
359
303
  }
360
304
  }
361
305
 
362
- export function decodeEndpoints(
363
- endpoints: string | Record<string, string> | undefined,
364
- ): Record<string, string> {
306
+ export function decodeEndpoints(endpoints: string | Record<string, string> | undefined): Record<string, string> {
365
307
  if (!endpoints) {
366
- return getEndpointsFromDomain("api.vertesia.io");
308
+ return getEndpointsFromDomain("api.vertesia.io")
367
309
  }
368
310
  if (typeof endpoints === "string") {
369
311
  return getEndpointsFromDomain(endpoints);
@@ -377,14 +319,12 @@ function getEndpointsFromDomain(domain: string) {
377
319
  return {
378
320
  studio: `http://localhost:8091`,
379
321
  store: `http://localhost:8092`,
380
- token: process.env.STS_URL ?? "https://sts-staging.vertesia.io",
381
- };
322
+ }
382
323
  } else {
383
324
  const url = `https://${domain}`;
384
325
  return {
385
326
  studio: url,
386
327
  store: url,
387
- token: url.replace("api", "sts"),
388
- };
328
+ }
389
329
  }
390
330
  }
@@ -120,9 +120,9 @@ export class FilesApi extends ApiTopic {
120
120
  if (res.ok) {
121
121
  return res;
122
122
  } else if (res.status === 404) {
123
- throw new Error(`File at ${url} not found`); //TODO: type fetch error better with a fetch error class
123
+ throw new Error(`File ${location} not found`); //TODO: type fetch error better with a fetch error class
124
124
  } else if (res.status === 403) {
125
- throw new Error(`File at ${url} is forbidden`);
125
+ throw new Error(`File ${location} is forbidden`);
126
126
  } else {
127
127
  console.log(res);
128
128
  throw new Error(
@@ -10,8 +10,6 @@ import {
10
10
  ListWorkflowInteractionsResponse,
11
11
  ListWorkflowRunsPayload,
12
12
  ListWorkflowRunsResponse,
13
- WebSocketClientMessage,
14
- WebSocketServerMessage,
15
13
  WorkflowDefinitionRef,
16
14
  WorkflowRule,
17
15
  WorkflowRuleItem,
@@ -250,170 +248,6 @@ export class WorkflowsApi extends ApiTopic {
250
248
  });
251
249
  }
252
250
 
253
- /**
254
- * Stream workflow messages via WebSocket (for mobile/React Native clients)
255
- * @param workflowId The workflow ID
256
- * @param runId The run ID
257
- * @param onMessage Callback for incoming messages
258
- * @param since Optional timestamp to resume from
259
- * @returns Promise that resolves with cleanup function and sendSignal helper
260
- */
261
- async streamMessagesWS(
262
- workflowId: string,
263
- runId: string,
264
- onMessage?: (message: AgentMessage) => void,
265
- since?: number
266
- ): Promise<{ cleanup: () => void; sendSignal: (signalName: string, data: any) => void }> {
267
- return new Promise((resolve, reject) => {
268
- let reconnectAttempts = 0;
269
- const maxReconnectAttempts = 10;
270
- const baseDelay = 1000;
271
- const maxDelay = 30000;
272
- let ws: WebSocket | null = null;
273
- let lastMessageTimestamp = since || 0;
274
- let isClosed = false;
275
-
276
- const calculateBackoffDelay = (attempts: number): number => {
277
- const exponentialDelay = Math.min(baseDelay * Math.pow(2, attempts), maxDelay);
278
- const jitter = Math.random() * 0.1 * exponentialDelay;
279
- return exponentialDelay + jitter;
280
- };
281
-
282
- const connect = async () => {
283
- if (isClosed) return;
284
-
285
- try {
286
- const client = this.client as VertesiaClient;
287
- const wsUrl = new URL(client.workflows.baseUrl + `/runs/${workflowId}/${runId}/ws`);
288
-
289
- // Replace http/https with ws/wss
290
- wsUrl.protocol = wsUrl.protocol.replace('http', 'ws');
291
-
292
- // Add query parameters
293
- if (lastMessageTimestamp > 0) {
294
- wsUrl.searchParams.set('since', lastMessageTimestamp.toString());
295
- }
296
-
297
- const bearerToken = client._auth ? await client._auth() : undefined;
298
- if (!bearerToken) {
299
- reject(new Error('No auth token available'));
300
- return;
301
- }
302
-
303
- const token = bearerToken.split(' ')[1];
304
- wsUrl.searchParams.set('access_token', token);
305
-
306
- if (reconnectAttempts > 0) {
307
- console.log(`Reconnecting to WebSocket for run ${runId} (attempt ${reconnectAttempts + 1}/${maxReconnectAttempts})`);
308
- }
309
-
310
- ws = new WebSocket(wsUrl.href);
311
-
312
- ws.onopen = () => {
313
- if (reconnectAttempts > 0) {
314
- console.log(`Successfully reconnected to WebSocket for run ${runId}`);
315
- }
316
- reconnectAttempts = 0;
317
-
318
- // Resolve with helpers on first successful connection
319
- if (!isClosed) {
320
- resolve({
321
- cleanup: () => {
322
- isClosed = true;
323
- if (ws) {
324
- ws.close();
325
- ws = null;
326
- }
327
- },
328
- sendSignal: (signalName: string, data: any) => {
329
- if (ws?.readyState === WebSocket.OPEN) {
330
- const message: WebSocketClientMessage = {
331
- type: 'signal',
332
- signalName,
333
- data,
334
- requestId: Date.now()
335
- };
336
- ws.send(JSON.stringify(message));
337
- } else {
338
- console.warn('WebSocket not open, cannot send signal');
339
- }
340
- }
341
- });
342
- }
343
- };
344
-
345
- ws.onmessage = (event: MessageEvent) => {
346
- try {
347
- const message = JSON.parse(event.data) as WebSocketServerMessage;
348
-
349
- // Handle different message types
350
- if ('workflow_run_id' in message) {
351
- // This is an AgentMessage
352
- const agentMessage = message as AgentMessage;
353
-
354
- if (agentMessage.timestamp) {
355
- lastMessageTimestamp = Math.max(lastMessageTimestamp, agentMessage.timestamp);
356
- }
357
-
358
- if (onMessage) onMessage(agentMessage);
359
-
360
- // Check for stream completion
361
- const streamIsOver =
362
- agentMessage.type === AgentMessageType.TERMINATED ||
363
- (agentMessage.type === AgentMessageType.COMPLETE &&
364
- (!agentMessage.workstream_id || agentMessage.workstream_id === 'main'));
365
-
366
- if (streamIsOver) {
367
- console.log('Closing WebSocket due to workflow completion');
368
- isClosed = true;
369
- if (ws) {
370
- ws.close();
371
- ws = null;
372
- }
373
- }
374
- } else if (message.type === 'pong') {
375
- // Heartbeat response
376
- console.debug('Received pong');
377
- } else if (message.type === 'ack') {
378
- console.debug('Signal acknowledged', message);
379
- } else if (message.type === 'error') {
380
- console.error('WebSocket error message', message);
381
- }
382
- } catch (err) {
383
- console.error('Failed to parse WebSocket message', err);
384
- }
385
- };
386
-
387
- ws.onerror = (err) => {
388
- console.error('WebSocket error', err);
389
- };
390
-
391
- ws.onclose = () => {
392
- if (!isClosed && reconnectAttempts < maxReconnectAttempts) {
393
- const delay = calculateBackoffDelay(reconnectAttempts);
394
- console.log(`WebSocket closed, reconnecting in ${delay}ms (attempt ${reconnectAttempts + 1}/${maxReconnectAttempts})`);
395
- reconnectAttempts++;
396
- setTimeout(connect, delay);
397
- } else if (reconnectAttempts >= maxReconnectAttempts) {
398
- reject(new Error(`WebSocket connection failed after ${maxReconnectAttempts} attempts`));
399
- }
400
- };
401
- } catch (err) {
402
- console.error('Error setting up WebSocket', err);
403
- if (reconnectAttempts < maxReconnectAttempts) {
404
- const delay = calculateBackoffDelay(reconnectAttempts);
405
- reconnectAttempts++;
406
- setTimeout(connect, delay);
407
- } else {
408
- reject(err);
409
- }
410
- }
411
- };
412
-
413
- connect();
414
- });
415
- }
416
-
417
251
  rules = new WorkflowsRulesApi(this);
418
252
  definitions = new WorkflowsDefinitionApi(this);
419
253
  }
@@ -1,18 +1,18 @@
1
1
  import { AbstractFetchClient, RequestError } from "@vertesia/api-fetch-client";
2
2
  import { BulkOperationPayload, BulkOperationResult } from "@vertesia/common";
3
3
  import { AgentsApi } from "./AgentsApi.js";
4
+ import { CollectionsApi } from "./CollectionsApi.js";
4
5
  import { CommandsApi } from "./CommandsApi.js";
5
6
  import { EmbeddingsApi } from "./EmbeddingsApi.js";
6
7
  import { ZenoClientNotFoundError } from "./errors.js";
7
8
  import { FilesApi } from "./FilesApi.js";
8
9
  import { ObjectsApi } from "./ObjectsApi.js";
9
10
  import { TypesApi } from "./TypesApi.js";
11
+ import { VERSION, VERSION_HEADER } from "./version.js";
10
12
  import { WorkflowsApi } from "./WorkflowsApi.js";
11
- import { CollectionsApi } from "./CollectionsApi.js";
12
13
 
13
14
  export interface ZenoClientProps {
14
15
  serverUrl?: string;
15
- tokenServerUrl?: string;
16
16
  apikey?: string;
17
17
  onRequest?: (request: Request) => void;
18
18
  onResponse?: (response: Response) => void;
@@ -45,6 +45,15 @@ export class ZenoClient extends AbstractFetchClient<ZenoClient> {
45
45
  }
46
46
  }
47
47
 
48
+ withApiVersion(version: string | number | null) {
49
+ if (!version) {
50
+ delete this.headers[VERSION_HEADER];
51
+ } else {
52
+ this.headers[VERSION_HEADER] = String(version);
53
+ }
54
+ return this;
55
+ }
56
+
48
57
  withApiKey(apiKey: string | null) {
49
58
  return this.withAuthCallback(
50
59
  apiKey ? () => Promise.resolve(`Bearer ${apiKey}`) : undefined
@@ -60,7 +69,7 @@ export class ZenoClient extends AbstractFetchClient<ZenoClient> {
60
69
  get initialHeaders() {
61
70
  return {
62
71
  ...super.initialHeaders,
63
- 'X-Api-Version': '20250925' // YYYYMMDD, client versioning for API endpoints. Increment manually for breaking changes
72
+ [VERSION_HEADER]: VERSION
64
73
  }
65
74
  }
66
75
 
@@ -0,0 +1,2 @@
1
+ export const VERSION = '20250925' // YYYYMMDD, client versioning for API endpoints. Increment manually for breaking changes
2
+ export const VERSION_HEADER = 'x-api-version';