@vertesia/client 0.51.0 → 0.54.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 (208) hide show
  1. package/LICENSE +3 -3
  2. package/package.json +27 -12
  3. package/src/AccountApi.ts +14 -2
  4. package/src/AccountsApi.ts +4 -0
  5. package/src/ApiKeysApi.ts +1 -1
  6. package/src/EnvironmentsApi.ts +2 -2
  7. package/src/InteractionBase.ts +1 -1
  8. package/src/InteractionsApi.ts +29 -7
  9. package/src/PluginsApi.ts +28 -0
  10. package/src/ProjectsApi.ts +10 -2
  11. package/src/PromptsApi.ts +1 -1
  12. package/src/RunsApi.ts +67 -30
  13. package/src/client.test.ts +94 -0
  14. package/src/client.ts +86 -13
  15. package/src/execute.ts +14 -8
  16. package/src/index.ts +2 -3
  17. package/src/nodejs/NodeStreamSource.ts +43 -0
  18. package/src/nodejs/index.ts +1 -0
  19. package/src/store/AnalyzeDocApi.ts +29 -9
  20. package/src/store/CommandsApi.ts +6 -33
  21. package/src/store/EmbeddingsApi.ts +39 -0
  22. package/src/store/FilesApi.ts +4 -0
  23. package/src/store/ObjectsApi.ts +179 -86
  24. package/src/store/TypesApi.ts +2 -1
  25. package/src/store/WorkflowsApi.ts +127 -25
  26. package/src/store/client.ts +2 -0
  27. package/lib/cjs/AccountApi.js +0 -74
  28. package/lib/cjs/AccountApi.js.map +0 -1
  29. package/lib/cjs/AccountsApi.js +0 -13
  30. package/lib/cjs/AccountsApi.js.map +0 -1
  31. package/lib/cjs/AnalyticsApi.js +0 -13
  32. package/lib/cjs/AnalyticsApi.js.map +0 -1
  33. package/lib/cjs/ApiKeysApi.js +0 -63
  34. package/lib/cjs/ApiKeysApi.js.map +0 -1
  35. package/lib/cjs/CommandsApi.js +0 -19
  36. package/lib/cjs/CommandsApi.js.map +0 -1
  37. package/lib/cjs/EnvironmentsApi.js +0 -58
  38. package/lib/cjs/EnvironmentsApi.js.map +0 -1
  39. package/lib/cjs/IamApi.js +0 -51
  40. package/lib/cjs/IamApi.js.map +0 -1
  41. package/lib/cjs/InteractionBase.js +0 -44
  42. package/lib/cjs/InteractionBase.js.map +0 -1
  43. package/lib/cjs/InteractionsApi.js +0 -192
  44. package/lib/cjs/InteractionsApi.js.map +0 -1
  45. package/lib/cjs/ProjectsApi.js +0 -48
  46. package/lib/cjs/ProjectsApi.js.map +0 -1
  47. package/lib/cjs/PromptsApi.js +0 -133
  48. package/lib/cjs/PromptsApi.js.map +0 -1
  49. package/lib/cjs/RefsApi.js +0 -14
  50. package/lib/cjs/RefsApi.js.map +0 -1
  51. package/lib/cjs/RunsApi.js +0 -80
  52. package/lib/cjs/RunsApi.js.map +0 -1
  53. package/lib/cjs/StreamSource.js +0 -17
  54. package/lib/cjs/StreamSource.js.map +0 -1
  55. package/lib/cjs/TrainingApi.js +0 -54
  56. package/lib/cjs/TrainingApi.js.map +0 -1
  57. package/lib/cjs/UsersApi.js +0 -13
  58. package/lib/cjs/UsersApi.js.map +0 -1
  59. package/lib/cjs/client.js +0 -161
  60. package/lib/cjs/client.js.map +0 -1
  61. package/lib/cjs/execute.js +0 -146
  62. package/lib/cjs/execute.js.map +0 -1
  63. package/lib/cjs/index.js +0 -22
  64. package/lib/cjs/index.js.map +0 -1
  65. package/lib/cjs/package.json +0 -3
  66. package/lib/cjs/store/AgentsApi.js +0 -16
  67. package/lib/cjs/store/AgentsApi.js.map +0 -1
  68. package/lib/cjs/store/AnalyzeDocApi.js +0 -37
  69. package/lib/cjs/store/AnalyzeDocApi.js.map +0 -1
  70. package/lib/cjs/store/CollectionsApi.js +0 -77
  71. package/lib/cjs/store/CollectionsApi.js.map +0 -1
  72. package/lib/cjs/store/CommandsApi.js +0 -33
  73. package/lib/cjs/store/CommandsApi.js.map +0 -1
  74. package/lib/cjs/store/FilesApi.js +0 -122
  75. package/lib/cjs/store/FilesApi.js.map +0 -1
  76. package/lib/cjs/store/ObjectsApi.js +0 -189
  77. package/lib/cjs/store/ObjectsApi.js.map +0 -1
  78. package/lib/cjs/store/TypesApi.js +0 -56
  79. package/lib/cjs/store/TypesApi.js.map +0 -1
  80. package/lib/cjs/store/WorkflowsApi.js +0 -92
  81. package/lib/cjs/store/WorkflowsApi.js.map +0 -1
  82. package/lib/cjs/store/client.js +0 -53
  83. package/lib/cjs/store/client.js.map +0 -1
  84. package/lib/cjs/store/errors.js +0 -11
  85. package/lib/cjs/store/errors.js.map +0 -1
  86. package/lib/cjs/store/index.js +0 -22
  87. package/lib/cjs/store/index.js.map +0 -1
  88. package/lib/esm/AccountApi.js +0 -71
  89. package/lib/esm/AccountApi.js.map +0 -1
  90. package/lib/esm/AccountsApi.js +0 -10
  91. package/lib/esm/AccountsApi.js.map +0 -1
  92. package/lib/esm/AnalyticsApi.js +0 -10
  93. package/lib/esm/AnalyticsApi.js.map +0 -1
  94. package/lib/esm/ApiKeysApi.js +0 -59
  95. package/lib/esm/ApiKeysApi.js.map +0 -1
  96. package/lib/esm/CommandsApi.js +0 -16
  97. package/lib/esm/CommandsApi.js.map +0 -1
  98. package/lib/esm/EnvironmentsApi.js +0 -55
  99. package/lib/esm/EnvironmentsApi.js.map +0 -1
  100. package/lib/esm/IamApi.js +0 -45
  101. package/lib/esm/IamApi.js.map +0 -1
  102. package/lib/esm/InteractionBase.js +0 -40
  103. package/lib/esm/InteractionBase.js.map +0 -1
  104. package/lib/esm/InteractionsApi.js +0 -189
  105. package/lib/esm/InteractionsApi.js.map +0 -1
  106. package/lib/esm/ProjectsApi.js +0 -45
  107. package/lib/esm/ProjectsApi.js.map +0 -1
  108. package/lib/esm/PromptsApi.js +0 -130
  109. package/lib/esm/PromptsApi.js.map +0 -1
  110. package/lib/esm/RefsApi.js +0 -10
  111. package/lib/esm/RefsApi.js.map +0 -1
  112. package/lib/esm/RunsApi.js +0 -76
  113. package/lib/esm/RunsApi.js.map +0 -1
  114. package/lib/esm/StreamSource.js +0 -13
  115. package/lib/esm/StreamSource.js.map +0 -1
  116. package/lib/esm/TrainingApi.js +0 -51
  117. package/lib/esm/TrainingApi.js.map +0 -1
  118. package/lib/esm/UsersApi.js +0 -10
  119. package/lib/esm/UsersApi.js.map +0 -1
  120. package/lib/esm/client.js +0 -154
  121. package/lib/esm/client.js.map +0 -1
  122. package/lib/esm/execute.js +0 -108
  123. package/lib/esm/execute.js.map +0 -1
  124. package/lib/esm/index.js +0 -6
  125. package/lib/esm/index.js.map +0 -1
  126. package/lib/esm/store/AgentsApi.js +0 -12
  127. package/lib/esm/store/AgentsApi.js.map +0 -1
  128. package/lib/esm/store/AnalyzeDocApi.js +0 -33
  129. package/lib/esm/store/AnalyzeDocApi.js.map +0 -1
  130. package/lib/esm/store/CollectionsApi.js +0 -73
  131. package/lib/esm/store/CollectionsApi.js.map +0 -1
  132. package/lib/esm/store/CommandsApi.js +0 -28
  133. package/lib/esm/store/CommandsApi.js.map +0 -1
  134. package/lib/esm/store/FilesApi.js +0 -117
  135. package/lib/esm/store/FilesApi.js.map +0 -1
  136. package/lib/esm/store/ObjectsApi.js +0 -185
  137. package/lib/esm/store/ObjectsApi.js.map +0 -1
  138. package/lib/esm/store/TypesApi.js +0 -52
  139. package/lib/esm/store/TypesApi.js.map +0 -1
  140. package/lib/esm/store/WorkflowsApi.js +0 -86
  141. package/lib/esm/store/WorkflowsApi.js.map +0 -1
  142. package/lib/esm/store/client.js +0 -49
  143. package/lib/esm/store/client.js.map +0 -1
  144. package/lib/esm/store/errors.js +0 -7
  145. package/lib/esm/store/errors.js.map +0 -1
  146. package/lib/esm/store/index.js +0 -6
  147. package/lib/esm/store/index.js.map +0 -1
  148. package/lib/tsconfig.tsbuildinfo +0 -1
  149. package/lib/types/AccountApi.d.ts +0 -53
  150. package/lib/types/AccountApi.d.ts.map +0 -1
  151. package/lib/types/AccountsApi.d.ts +0 -7
  152. package/lib/types/AccountsApi.d.ts.map +0 -1
  153. package/lib/types/AnalyticsApi.d.ts +0 -7
  154. package/lib/types/AnalyticsApi.d.ts.map +0 -1
  155. package/lib/types/ApiKeysApi.d.ts +0 -43
  156. package/lib/types/ApiKeysApi.d.ts.map +0 -1
  157. package/lib/types/CommandsApi.d.ts +0 -11
  158. package/lib/types/CommandsApi.d.ts.map +0 -1
  159. package/lib/types/EnvironmentsApi.d.ts +0 -31
  160. package/lib/types/EnvironmentsApi.d.ts.map +0 -1
  161. package/lib/types/IamApi.d.ts +0 -40
  162. package/lib/types/IamApi.d.ts.map +0 -1
  163. package/lib/types/InteractionBase.d.ts +0 -23
  164. package/lib/types/InteractionBase.d.ts.map +0 -1
  165. package/lib/types/InteractionsApi.d.ts +0 -136
  166. package/lib/types/InteractionsApi.d.ts.map +0 -1
  167. package/lib/types/ProjectsApi.d.ts +0 -18
  168. package/lib/types/ProjectsApi.d.ts.map +0 -1
  169. package/lib/types/PromptsApi.d.ts +0 -107
  170. package/lib/types/PromptsApi.d.ts.map +0 -1
  171. package/lib/types/RefsApi.d.ts +0 -7
  172. package/lib/types/RefsApi.d.ts.map +0 -1
  173. package/lib/types/RunsApi.d.ts +0 -64
  174. package/lib/types/RunsApi.d.ts.map +0 -1
  175. package/lib/types/StreamSource.d.ts +0 -8
  176. package/lib/types/StreamSource.d.ts.map +0 -1
  177. package/lib/types/TrainingApi.d.ts +0 -28
  178. package/lib/types/TrainingApi.d.ts.map +0 -1
  179. package/lib/types/UsersApi.d.ts +0 -7
  180. package/lib/types/UsersApi.d.ts.map +0 -1
  181. package/lib/types/client.d.ts +0 -86
  182. package/lib/types/client.d.ts.map +0 -1
  183. package/lib/types/execute.d.ts +0 -33
  184. package/lib/types/execute.d.ts.map +0 -1
  185. package/lib/types/index.d.ts +0 -9
  186. package/lib/types/index.d.ts.map +0 -1
  187. package/lib/types/store/AgentsApi.d.ts +0 -7
  188. package/lib/types/store/AgentsApi.d.ts.map +0 -1
  189. package/lib/types/store/AnalyzeDocApi.d.ts +0 -17
  190. package/lib/types/store/AnalyzeDocApi.d.ts.map +0 -1
  191. package/lib/types/store/CollectionsApi.d.ts +0 -38
  192. package/lib/types/store/CollectionsApi.d.ts.map +0 -1
  193. package/lib/types/store/CommandsApi.d.ts +0 -14
  194. package/lib/types/store/CommandsApi.d.ts.map +0 -1
  195. package/lib/types/store/FilesApi.d.ts +0 -42
  196. package/lib/types/store/FilesApi.d.ts.map +0 -1
  197. package/lib/types/store/ObjectsApi.d.ts +0 -79
  198. package/lib/types/store/ObjectsApi.d.ts.map +0 -1
  199. package/lib/types/store/TypesApi.d.ts +0 -23
  200. package/lib/types/store/TypesApi.d.ts.map +0 -1
  201. package/lib/types/store/WorkflowsApi.d.ts +0 -40
  202. package/lib/types/store/WorkflowsApi.d.ts.map +0 -1
  203. package/lib/types/store/client.d.ts +0 -28
  204. package/lib/types/store/client.d.ts.map +0 -1
  205. package/lib/types/store/errors.d.ts +0 -5
  206. package/lib/types/store/errors.d.ts.map +0 -1
  207. package/lib/types/store/index.d.ts +0 -6
  208. package/lib/types/store/index.d.ts.map +0 -1
package/src/client.ts CHANGED
@@ -15,15 +15,29 @@ import { RunsApi } from "./RunsApi.js";
15
15
  import { ZenoClient } from "./store/client.js";
16
16
  import TrainingApi from "./TrainingApi.js";
17
17
  import UsersApi from "./UsersApi.js";
18
+ import PluginsApi from "./PluginsApi.js";
18
19
 
19
20
  /**
20
21
  * 1 min threshold constant in ms
21
22
  */
22
23
  const EXPIRATION_THRESHOLD = 60000;
23
24
 
24
- export interface VertesiaClientProps {
25
- serverUrl: string;
26
- storeUrl: string;
25
+ export type VertesiaClientProps = {
26
+ /**
27
+ * The site name of Vertesia.
28
+ *
29
+ * This is used to determine the API backend. It should not include the protocol. For more
30
+ * advanced configurations, use `serverUrl` and `storeUrl` instead.
31
+ *
32
+ * @example api.vertesia.io
33
+ * @example api-preview.vertesia.io
34
+ * @example api-staging.vertesia.io
35
+ * @default api.vertesia.io
36
+ * @since 0.52.0
37
+ */
38
+ site?: 'api.vertesia.io' | 'api-preview.vertesia.io' | 'api-staging.vertesia.io';
39
+ serverUrl?: string;
40
+ storeUrl?: string;
27
41
  apikey?: string;
28
42
  projectId?: string;
29
43
  sessionTags?: string | string[];
@@ -49,17 +63,33 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
49
63
  sessionTags?: string | string[];
50
64
 
51
65
  constructor(
52
- opts: VertesiaClientProps = {} as any
66
+ opts: VertesiaClientProps = {
67
+ site: 'api.vertesia.io',
68
+ }
53
69
  ) {
54
- super(opts.serverUrl);
55
- if (!opts.serverUrl) {
56
- throw new Error("storeUrl is required for VertesiaClient");
70
+ let studioServerUrl: string;
71
+ let zenoServerUrl: string;
72
+
73
+ if (opts.serverUrl) {
74
+ studioServerUrl = opts.serverUrl;
75
+ } else if (opts.site) {
76
+ studioServerUrl = `https://${opts.site}`;
77
+ } else {
78
+ throw new Error("Parameter 'site' or 'serverUrl' is required for VertesiaClient");
57
79
  }
58
- if (!opts.storeUrl) {
59
- throw new Error("storeUrl is required for VertesiaClient");
80
+
81
+ if (opts.storeUrl) {
82
+ zenoServerUrl = opts.storeUrl;
83
+ } else if (opts.site) {
84
+ zenoServerUrl = `https://${opts.site}`;
85
+ } else {
86
+ throw new Error("Parameter 'site' or 'storeUrl' is required for VertesiaClient");
60
87
  }
88
+
89
+ super(studioServerUrl);
90
+
61
91
  this.store = new ZenoClient({
62
- serverUrl: opts.storeUrl,
92
+ serverUrl: zenoServerUrl,
63
93
  apikey: opts.apikey,
64
94
  onRequest: opts.onRequest,
65
95
  onResponse: opts.onResponse
@@ -103,6 +133,21 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
103
133
  );
104
134
  }
105
135
 
136
+ async getRawJWT() {
137
+ if (!this._jwt && this._auth) {
138
+ const auth = await this._auth();
139
+ if (!this._jwt) { // the _jwt may be set by the auth callback
140
+ this._jwt = auth.trim().split(' ')[1]; // remove Bearer prefix
141
+ }
142
+ }
143
+ return this._jwt || null;
144
+ }
145
+
146
+ async getDecodedJWT() {
147
+ const jwt = await this.getRawJWT();
148
+ return jwt ? decodeJWT(jwt) : null;
149
+ }
150
+
106
151
  /**
107
152
  * Alias for store.workflows
108
153
  */
@@ -128,6 +173,9 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
128
173
  return this.store.types;
129
174
  }
130
175
 
176
+ get storeUrl() {
177
+ return this.store.baseUrl;
178
+ }
131
179
 
132
180
  set project(projectId: string | null) {
133
181
  if (projectId) {
@@ -171,6 +219,7 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
171
219
  iam = new IamApi(this);
172
220
  refs = new RefsApi(this);
173
221
  commands = new CommandsApi(this);
222
+ plugins = new PluginsApi(this);
174
223
  }
175
224
 
176
225
  function isApiKey(apiKey: string) {
@@ -182,10 +231,34 @@ function isTokenExpired(token: string | null) {
182
231
  return true;
183
232
  }
184
233
 
185
- const payloadBase64 = token.split('.')[1];
186
- const decodedJson = Buffer.from(payloadBase64, 'base64').toString();
187
- const decoded = JSON.parse(decodedJson)
234
+ const decoded = decodeJWT(token);
188
235
  const exp = decoded.exp;
189
236
  const currentTime = Date.now();
190
237
  return (currentTime <= exp * 1000 - EXPIRATION_THRESHOLD);
191
238
  }
239
+
240
+ function decodeJWT(jwt: string) {
241
+ const payloadBase64 = jwt.split('.')[1];
242
+ const decodedJson = base64UrlDecode(payloadBase64);
243
+ return JSON.parse(decodedJson)
244
+ }
245
+
246
+ function base64UrlDecode(input: string): string {
247
+ // Convert base64url to base64
248
+ const base64 = input.replace(/-/g, '+').replace(/_/g, '/')
249
+ // Pad with '=' to make length a multiple of 4
250
+ .padEnd(Math.ceil(input.length / 4) * 4, '=');
251
+
252
+ if (typeof Buffer !== 'undefined') {
253
+ // Node.js
254
+ return Buffer.from(base64, 'base64').toString('utf-8');
255
+ } else if (typeof atob !== 'undefined' && typeof TextDecoder !== 'undefined') {
256
+ // Browser
257
+ const binary = atob(base64);
258
+ const bytes = Uint8Array.from(binary, c => c.charCodeAt(0));
259
+ // decode to utf8
260
+ return new TextDecoder().decode(bytes);
261
+ } else {
262
+ throw new Error('No base64 decoder available');
263
+ }
264
+ }
package/src/execute.ts CHANGED
@@ -1,11 +1,11 @@
1
- import { ExecutionRun, ExecutionRunStatus, InteractionExecutionPayload, NamedInteractionExecutionPayload } from '@vertesia/common';
1
+ import { AsyncExecutionPayload, ExecutionRunStatus, InteractionExecutionPayload, InteractionExecutionResult, NamedInteractionExecutionPayload } from '@vertesia/common';
2
2
  import { VertesiaClient } from './client.js';
3
3
 
4
- export function EventSourceProvider(): Promise<typeof EventSource> {
4
+ export async function EventSourceProvider(): Promise<typeof EventSource> {
5
5
  if (typeof globalThis.EventSource === 'function') {
6
- return Promise.resolve(globalThis.EventSource)
6
+ return globalThis.EventSource;
7
7
  } else {
8
- return import('eventsource').then(module => module.default as unknown as typeof EventSource);
8
+ return (await import('eventsource')).EventSource;
9
9
  }
10
10
  }
11
11
  /**
@@ -14,7 +14,7 @@ export function EventSourceProvider(): Promise<typeof EventSource> {
14
14
  * the run completes or fails.
15
15
  * If the onChunk callback is passed then the streaming of the result is enabled.
16
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 fucntion will return the resolved promise
17
+ * When all chunks are received the function will return the resolved promise
18
18
  * @param id of the interaction to execute
19
19
  * @param payload InteractionExecutionPayload
20
20
  * @param onChunk callback to be called when the next chunk of the response is available
@@ -22,7 +22,7 @@ export function EventSourceProvider(): Promise<typeof EventSource> {
22
22
  export async function executeInteraction<P = any, R = any>(client: VertesiaClient,
23
23
  interactionId: string,
24
24
  payload: InteractionExecutionPayload = {},
25
- onChunk?: (chunk: string) => void): Promise<ExecutionRun<P, R>> {
25
+ onChunk?: (chunk: string) => void): Promise<InteractionExecutionResult<P, R>> {
26
26
  const stream = !!onChunk;
27
27
  const response = await client.runs.create({
28
28
  ...payload, interaction: interactionId, stream
@@ -38,7 +38,7 @@ export async function executeInteraction<P = any, R = any>(client: VertesiaClien
38
38
 
39
39
  /**
40
40
  * Same as executeInteraction but uses the interaction name selector instead of the id.
41
- * A name selector is the interaction endpoint name suffuxed with an optional tag or version wich is starting with a `@` character.
41
+ * A name selector is the interaction endpoint name suffixed with an optional tag or version which is starting with a `@` character.
42
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
43
  * Examples of selectors:
44
44
  * - `ReviewContract` - select the latest version of the ReviewContract interaction
@@ -55,7 +55,7 @@ export async function executeInteraction<P = any, R = any>(client: VertesiaClien
55
55
  export async function executeInteractionByName<P = any, R = any>(client: VertesiaClient,
56
56
  interaction: string,
57
57
  payload: InteractionExecutionPayload = {},
58
- onChunk?: (chunk: string) => void): Promise<ExecutionRun<P, R>> {
58
+ onChunk?: (chunk: string) => void): Promise<InteractionExecutionResult<P, R>> {
59
59
  const stream = !!onChunk;
60
60
  const response = await client.post('/api/v1/execute', {
61
61
  payload: {
@@ -111,4 +111,10 @@ function handleStreaming(client: VertesiaClient, runId: string, onChunk: (chunk:
111
111
  reject(err);
112
112
  }
113
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
+ });
114
120
  }
package/src/index.ts CHANGED
@@ -1,8 +1,7 @@
1
+ export * from './client.js';
1
2
  export * from './InteractionBase.js';
3
+ export type { AsyncExecutionResult, ComputeInteractionFacetsResponse } from './InteractionsApi.js';
2
4
  export type { ComputePromptFacetsResponse, ListInteractionsResponse } from './PromptsApi.js';
3
- export type { ComputeInteractionFacetsResponse } from './InteractionsApi.js';
4
5
  export type { ComputeRunFacetsResponse, FilterOption } from './RunsApi.js';
5
- export * from './client.js';
6
- export * from './InteractionBase.js';
7
6
  export * from "./store/index.js";
8
7
  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";
@@ -1,5 +1,5 @@
1
1
  import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
2
- import { ContentObject, DocAnalyzerResultResponse, DocAnalyzeRunStatusResponse, DocImage, DocTableCsv, DocTableJson, PdfToRichtextOptions } from "@vertesia/common";
2
+ import { AdaptedTable, AdaptTablesRequest, DocAnalyzerResultResponse, DocAnalyzeRunStatusResponse, DocImage, DocTableCsv, DocTableJson, ExportTableFormats, GetAdaptedTablesRequestQuery, PdfToRichtextOptions, WorkflowRunStatus } from "@vertesia/common";
3
3
 
4
4
  export class AnalyzeDocApi extends ApiTopic {
5
5
  constructor(parent: ClientBase, public objectId: string) {
@@ -18,24 +18,44 @@ export class AnalyzeDocApi extends ApiTopic {
18
18
  return this.get("/results");
19
19
  }
20
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
+
21
42
  async getXml(): Promise<string> {
22
43
  return this.get("/xml");
23
44
  }
24
45
 
25
- async getTables(): Promise<DocTableCsv[] | DocTableJson[]> {
26
- return this.get("/tables");
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);
27
52
  }
28
53
 
29
54
  async getImages(): Promise<DocImage[]> {
30
- return this.get("/tables");
31
- }
32
-
33
- async getParts(): Promise<ContentObject[]> {
34
- return this.get("/parts");
55
+ return this.get("/images");
35
56
  }
36
57
 
37
58
  async getAnnotated(): Promise<{ url: string }> {
38
59
  return this.get("/annotated");
39
60
  }
40
-
41
61
  }
@@ -1,42 +1,15 @@
1
1
  import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
2
- import { EmbeddingsStatusResponse, GenericCommandResponse, ProjectConfigurationEmbeddings, SupportedEmbeddingTypes } from "@vertesia/common";
3
-
2
+ import { EmbeddingsApi } from "./EmbeddingsApi.js";
4
3
 
4
+ /**
5
+ * @deprecated use EmbeddingsApi instead
6
+ * @see EmbeddingsApi
7
+ */
5
8
  export class CommandsApi extends ApiTopic {
6
9
 
7
10
  constructor(parent: ClientBase) {
8
11
  super(parent, "/api/v1/commands");
9
12
  }
10
13
 
11
- embeddings = new EmbeddingsApi(this);
12
-
14
+ embeddings = new EmbeddingsApi(this, "/embeddings");
13
15
  }
14
-
15
- export class EmbeddingsApi extends ApiTopic {
16
-
17
- constructor(parent: ClientBase) {
18
- super(parent, "/embeddings");
19
- }
20
-
21
- async status(type: SupportedEmbeddingTypes): Promise<EmbeddingsStatusResponse> {
22
- return this.get(type + "/status");
23
- }
24
-
25
- async activate(type: SupportedEmbeddingTypes, config: Partial<ProjectConfigurationEmbeddings>): Promise<GenericCommandResponse> {
26
-
27
- if (!config.environment) {
28
- throw new Error("Invalid configuration: select environment");
29
- }
30
-
31
- return this.post(type + "/enable", { payload: config });
32
- }
33
-
34
- async disable(type: SupportedEmbeddingTypes): Promise<GenericCommandResponse> {
35
- return this.post(type + "/disable");
36
- }
37
-
38
- async recalculate(type: SupportedEmbeddingTypes): Promise<GenericCommandResponse> {
39
- return this.post(type + "/recalculate");
40
- }
41
-
42
- }
@@ -0,0 +1,39 @@
1
+ import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
2
+ import {
3
+ EmbeddingsStatusResponse,
4
+ GenericCommandResponse,
5
+ ProjectConfigurationEmbeddings,
6
+ SupportedEmbeddingTypes,
7
+ } from "@vertesia/common";
8
+
9
+ /**
10
+ * @since 0.52.0
11
+ */
12
+ export class EmbeddingsApi extends ApiTopic {
13
+
14
+ constructor(parent: ClientBase, basePath: string = "/api/v1/embeddings") {
15
+ super(parent, basePath);
16
+ }
17
+
18
+ async status(type: SupportedEmbeddingTypes): Promise<EmbeddingsStatusResponse> {
19
+ return this.get(type + "/status");
20
+ }
21
+
22
+ async activate(type: SupportedEmbeddingTypes, config: Partial<ProjectConfigurationEmbeddings>): Promise<GenericCommandResponse> {
23
+
24
+ if (!config.environment) {
25
+ throw new Error("Invalid configuration: select environment");
26
+ }
27
+
28
+ return this.post(type + "/enable", { payload: config });
29
+ }
30
+
31
+ async disable(type: SupportedEmbeddingTypes): Promise<GenericCommandResponse> {
32
+ return this.post(type + "/disable");
33
+ }
34
+
35
+ async recalculate(type: SupportedEmbeddingTypes): Promise<GenericCommandResponse> {
36
+ return this.post(type + "/recalculate");
37
+ }
38
+
39
+ }
@@ -101,6 +101,10 @@ export class FilesApi extends ApiTopic {
101
101
  }).then((res: Response) => {
102
102
  if (res.ok) {
103
103
  return res;
104
+ } else if (res.status === 404) {
105
+ throw new Error(`File ${name} not found`); //TODO: type fetch error better with a fetch error class
106
+ } else if (res.status === 403) {
107
+ throw new Error(`File ${name} is forbidden`);
104
108
  } else {
105
109
  console.log(res);
106
110
  throw new Error(`Failed to download file ${name}: ${res.statusText}`);