@vertesia/client 0.53.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 (212) hide show
  1. package/LICENSE +3 -3
  2. package/package.json +5 -5
  3. package/src/ApiKeysApi.ts +1 -1
  4. package/src/EnvironmentsApi.ts +2 -2
  5. package/src/InteractionBase.ts +1 -1
  6. package/src/InteractionsApi.ts +5 -5
  7. package/src/PluginsApi.ts +28 -0
  8. package/src/ProjectsApi.ts +10 -2
  9. package/src/PromptsApi.ts +1 -1
  10. package/src/client.ts +2 -0
  11. package/src/execute.ts +5 -5
  12. package/src/store/ObjectsApi.ts +179 -86
  13. package/lib/cjs/AccountApi.js +0 -84
  14. package/lib/cjs/AccountApi.js.map +0 -1
  15. package/lib/cjs/AccountsApi.js +0 -16
  16. package/lib/cjs/AccountsApi.js.map +0 -1
  17. package/lib/cjs/AnalyticsApi.js +0 -13
  18. package/lib/cjs/AnalyticsApi.js.map +0 -1
  19. package/lib/cjs/ApiKeysApi.js +0 -63
  20. package/lib/cjs/ApiKeysApi.js.map +0 -1
  21. package/lib/cjs/CommandsApi.js +0 -19
  22. package/lib/cjs/CommandsApi.js.map +0 -1
  23. package/lib/cjs/EnvironmentsApi.js +0 -58
  24. package/lib/cjs/EnvironmentsApi.js.map +0 -1
  25. package/lib/cjs/IamApi.js +0 -51
  26. package/lib/cjs/IamApi.js.map +0 -1
  27. package/lib/cjs/InteractionBase.js +0 -44
  28. package/lib/cjs/InteractionBase.js.map +0 -1
  29. package/lib/cjs/InteractionsApi.js +0 -209
  30. package/lib/cjs/InteractionsApi.js.map +0 -1
  31. package/lib/cjs/ProjectsApi.js +0 -48
  32. package/lib/cjs/ProjectsApi.js.map +0 -1
  33. package/lib/cjs/PromptsApi.js +0 -133
  34. package/lib/cjs/PromptsApi.js.map +0 -1
  35. package/lib/cjs/RefsApi.js +0 -14
  36. package/lib/cjs/RefsApi.js.map +0 -1
  37. package/lib/cjs/RunsApi.js +0 -105
  38. package/lib/cjs/RunsApi.js.map +0 -1
  39. package/lib/cjs/StreamSource.js +0 -17
  40. package/lib/cjs/StreamSource.js.map +0 -1
  41. package/lib/cjs/TrainingApi.js +0 -54
  42. package/lib/cjs/TrainingApi.js.map +0 -1
  43. package/lib/cjs/UsersApi.js +0 -13
  44. package/lib/cjs/UsersApi.js.map +0 -1
  45. package/lib/cjs/client.js +0 -216
  46. package/lib/cjs/client.js.map +0 -1
  47. package/lib/cjs/execute.js +0 -152
  48. package/lib/cjs/execute.js.map +0 -1
  49. package/lib/cjs/index.js +0 -21
  50. package/lib/cjs/index.js.map +0 -1
  51. package/lib/cjs/nodejs/NodeStreamSource.js +0 -45
  52. package/lib/cjs/nodejs/NodeStreamSource.js.map +0 -1
  53. package/lib/cjs/nodejs/index.js +0 -18
  54. package/lib/cjs/nodejs/index.js.map +0 -1
  55. package/lib/cjs/package.json +0 -3
  56. package/lib/cjs/store/AgentsApi.js +0 -16
  57. package/lib/cjs/store/AgentsApi.js.map +0 -1
  58. package/lib/cjs/store/AnalyzeDocApi.js +0 -56
  59. package/lib/cjs/store/AnalyzeDocApi.js.map +0 -1
  60. package/lib/cjs/store/CollectionsApi.js +0 -77
  61. package/lib/cjs/store/CollectionsApi.js.map +0 -1
  62. package/lib/cjs/store/CommandsApi.js +0 -17
  63. package/lib/cjs/store/CommandsApi.js.map +0 -1
  64. package/lib/cjs/store/EmbeddingsApi.js +0 -29
  65. package/lib/cjs/store/EmbeddingsApi.js.map +0 -1
  66. package/lib/cjs/store/FilesApi.js +0 -128
  67. package/lib/cjs/store/FilesApi.js.map +0 -1
  68. package/lib/cjs/store/ObjectsApi.js +0 -189
  69. package/lib/cjs/store/ObjectsApi.js.map +0 -1
  70. package/lib/cjs/store/TypesApi.js +0 -57
  71. package/lib/cjs/store/TypesApi.js.map +0 -1
  72. package/lib/cjs/store/WorkflowsApi.js +0 -174
  73. package/lib/cjs/store/WorkflowsApi.js.map +0 -1
  74. package/lib/cjs/store/client.js +0 -55
  75. package/lib/cjs/store/client.js.map +0 -1
  76. package/lib/cjs/store/errors.js +0 -11
  77. package/lib/cjs/store/errors.js.map +0 -1
  78. package/lib/cjs/store/index.js +0 -22
  79. package/lib/cjs/store/index.js.map +0 -1
  80. package/lib/esm/AccountApi.js +0 -81
  81. package/lib/esm/AccountApi.js.map +0 -1
  82. package/lib/esm/AccountsApi.js +0 -13
  83. package/lib/esm/AccountsApi.js.map +0 -1
  84. package/lib/esm/AnalyticsApi.js +0 -10
  85. package/lib/esm/AnalyticsApi.js.map +0 -1
  86. package/lib/esm/ApiKeysApi.js +0 -59
  87. package/lib/esm/ApiKeysApi.js.map +0 -1
  88. package/lib/esm/CommandsApi.js +0 -16
  89. package/lib/esm/CommandsApi.js.map +0 -1
  90. package/lib/esm/EnvironmentsApi.js +0 -55
  91. package/lib/esm/EnvironmentsApi.js.map +0 -1
  92. package/lib/esm/IamApi.js +0 -45
  93. package/lib/esm/IamApi.js.map +0 -1
  94. package/lib/esm/InteractionBase.js +0 -40
  95. package/lib/esm/InteractionBase.js.map +0 -1
  96. package/lib/esm/InteractionsApi.js +0 -206
  97. package/lib/esm/InteractionsApi.js.map +0 -1
  98. package/lib/esm/ProjectsApi.js +0 -45
  99. package/lib/esm/ProjectsApi.js.map +0 -1
  100. package/lib/esm/PromptsApi.js +0 -130
  101. package/lib/esm/PromptsApi.js.map +0 -1
  102. package/lib/esm/RefsApi.js +0 -10
  103. package/lib/esm/RefsApi.js.map +0 -1
  104. package/lib/esm/RunsApi.js +0 -101
  105. package/lib/esm/RunsApi.js.map +0 -1
  106. package/lib/esm/StreamSource.js +0 -13
  107. package/lib/esm/StreamSource.js.map +0 -1
  108. package/lib/esm/TrainingApi.js +0 -51
  109. package/lib/esm/TrainingApi.js.map +0 -1
  110. package/lib/esm/UsersApi.js +0 -10
  111. package/lib/esm/UsersApi.js.map +0 -1
  112. package/lib/esm/client.js +0 -209
  113. package/lib/esm/client.js.map +0 -1
  114. package/lib/esm/execute.js +0 -113
  115. package/lib/esm/execute.js.map +0 -1
  116. package/lib/esm/index.js +0 -5
  117. package/lib/esm/index.js.map +0 -1
  118. package/lib/esm/nodejs/NodeStreamSource.js +0 -41
  119. package/lib/esm/nodejs/NodeStreamSource.js.map +0 -1
  120. package/lib/esm/nodejs/index.js +0 -2
  121. package/lib/esm/nodejs/index.js.map +0 -1
  122. package/lib/esm/store/AgentsApi.js +0 -12
  123. package/lib/esm/store/AgentsApi.js.map +0 -1
  124. package/lib/esm/store/AnalyzeDocApi.js +0 -52
  125. package/lib/esm/store/AnalyzeDocApi.js.map +0 -1
  126. package/lib/esm/store/CollectionsApi.js +0 -73
  127. package/lib/esm/store/CollectionsApi.js.map +0 -1
  128. package/lib/esm/store/CommandsApi.js +0 -13
  129. package/lib/esm/store/CommandsApi.js.map +0 -1
  130. package/lib/esm/store/EmbeddingsApi.js +0 -25
  131. package/lib/esm/store/EmbeddingsApi.js.map +0 -1
  132. package/lib/esm/store/FilesApi.js +0 -123
  133. package/lib/esm/store/FilesApi.js.map +0 -1
  134. package/lib/esm/store/ObjectsApi.js +0 -185
  135. package/lib/esm/store/ObjectsApi.js.map +0 -1
  136. package/lib/esm/store/TypesApi.js +0 -53
  137. package/lib/esm/store/TypesApi.js.map +0 -1
  138. package/lib/esm/store/WorkflowsApi.js +0 -168
  139. package/lib/esm/store/WorkflowsApi.js.map +0 -1
  140. package/lib/esm/store/client.js +0 -51
  141. package/lib/esm/store/client.js.map +0 -1
  142. package/lib/esm/store/errors.js +0 -7
  143. package/lib/esm/store/errors.js.map +0 -1
  144. package/lib/esm/store/index.js +0 -6
  145. package/lib/esm/store/index.js.map +0 -1
  146. package/lib/tsconfig.tsbuildinfo +0 -1
  147. package/lib/types/AccountApi.d.ts +0 -58
  148. package/lib/types/AccountApi.d.ts.map +0 -1
  149. package/lib/types/AccountsApi.d.ts +0 -7
  150. package/lib/types/AccountsApi.d.ts.map +0 -1
  151. package/lib/types/AnalyticsApi.d.ts +0 -6
  152. package/lib/types/AnalyticsApi.d.ts.map +0 -1
  153. package/lib/types/ApiKeysApi.d.ts +0 -42
  154. package/lib/types/ApiKeysApi.d.ts.map +0 -1
  155. package/lib/types/CommandsApi.d.ts +0 -10
  156. package/lib/types/CommandsApi.d.ts.map +0 -1
  157. package/lib/types/EnvironmentsApi.d.ts +0 -30
  158. package/lib/types/EnvironmentsApi.d.ts.map +0 -1
  159. package/lib/types/IamApi.d.ts +0 -39
  160. package/lib/types/IamApi.d.ts.map +0 -1
  161. package/lib/types/InteractionBase.d.ts +0 -22
  162. package/lib/types/InteractionBase.d.ts.map +0 -1
  163. package/lib/types/InteractionsApi.d.ts +0 -150
  164. package/lib/types/InteractionsApi.d.ts.map +0 -1
  165. package/lib/types/ProjectsApi.d.ts +0 -17
  166. package/lib/types/ProjectsApi.d.ts.map +0 -1
  167. package/lib/types/PromptsApi.d.ts +0 -106
  168. package/lib/types/PromptsApi.d.ts.map +0 -1
  169. package/lib/types/RefsApi.d.ts +0 -6
  170. package/lib/types/RefsApi.d.ts.map +0 -1
  171. package/lib/types/RunsApi.d.ts +0 -77
  172. package/lib/types/RunsApi.d.ts.map +0 -1
  173. package/lib/types/StreamSource.d.ts +0 -7
  174. package/lib/types/StreamSource.d.ts.map +0 -1
  175. package/lib/types/TrainingApi.d.ts +0 -27
  176. package/lib/types/TrainingApi.d.ts.map +0 -1
  177. package/lib/types/UsersApi.d.ts +0 -6
  178. package/lib/types/UsersApi.d.ts.map +0 -1
  179. package/lib/types/client.d.ts +0 -101
  180. package/lib/types/client.d.ts.map +0 -1
  181. package/lib/types/execute.d.ts +0 -36
  182. package/lib/types/execute.d.ts.map +0 -1
  183. package/lib/types/index.d.ts +0 -7
  184. package/lib/types/index.d.ts.map +0 -1
  185. package/lib/types/nodejs/NodeStreamSource.d.ts +0 -9
  186. package/lib/types/nodejs/NodeStreamSource.d.ts.map +0 -1
  187. package/lib/types/nodejs/index.d.ts +0 -1
  188. package/lib/types/nodejs/index.d.ts.map +0 -1
  189. package/lib/types/store/AgentsApi.d.ts +0 -6
  190. package/lib/types/store/AgentsApi.d.ts.map +0 -1
  191. package/lib/types/store/AnalyzeDocApi.d.ts +0 -17
  192. package/lib/types/store/AnalyzeDocApi.d.ts.map +0 -1
  193. package/lib/types/store/CollectionsApi.d.ts +0 -37
  194. package/lib/types/store/CollectionsApi.d.ts.map +0 -1
  195. package/lib/types/store/CommandsApi.d.ts +0 -10
  196. package/lib/types/store/CommandsApi.d.ts.map +0 -1
  197. package/lib/types/store/EmbeddingsApi.d.ts +0 -12
  198. package/lib/types/store/EmbeddingsApi.d.ts.map +0 -1
  199. package/lib/types/store/FilesApi.d.ts +0 -41
  200. package/lib/types/store/FilesApi.d.ts.map +0 -1
  201. package/lib/types/store/ObjectsApi.d.ts +0 -78
  202. package/lib/types/store/ObjectsApi.d.ts.map +0 -1
  203. package/lib/types/store/TypesApi.d.ts +0 -23
  204. package/lib/types/store/TypesApi.d.ts.map +0 -1
  205. package/lib/types/store/WorkflowsApi.d.ts +0 -47
  206. package/lib/types/store/WorkflowsApi.d.ts.map +0 -1
  207. package/lib/types/store/client.d.ts +0 -29
  208. package/lib/types/store/client.d.ts.map +0 -1
  209. package/lib/types/store/errors.d.ts +0 -4
  210. package/lib/types/store/errors.d.ts.map +0 -1
  211. package/lib/types/store/index.d.ts +0 -5
  212. package/lib/types/store/index.d.ts.map +0 -1
package/LICENSE CHANGED
@@ -1,13 +1,13 @@
1
- Copyright 2024 Composable
1
+ Copyright 2024 Composable Prompts
2
2
 
3
3
  Licensed under the Apache License, Version 2.0 (the "License");
4
4
  you may not use this file except in compliance with the License.
5
5
  You may obtain a copy of the License at
6
6
 
7
- http://www.apache.org/licenses/LICENSE-2.0
7
+ http://www.apache.org/licenses/LICENSE-2.0
8
8
 
9
9
  Unless required by applicable law or agreed to in writing, software
10
10
  distributed under the License is distributed on an "AS IS" BASIS,
11
11
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
12
  See the License for the specific language governing permissions and
13
- limitations under the License.
13
+ limitations under the License.
package/package.json CHANGED
@@ -1,24 +1,24 @@
1
1
  {
2
2
  "name": "@vertesia/client",
3
- "version": "0.53.0",
3
+ "version": "0.54.0",
4
4
  "type": "module",
5
5
  "types": "./lib/types/index.d.ts",
6
6
  "files": [
7
7
  "lib",
8
8
  "src"
9
9
  ],
10
+ "license": "Apache-2.0",
10
11
  "devDependencies": {
11
- "@types/eventsource": "^1.1.14",
12
12
  "@types/node": "^22.13.5",
13
13
  "ts-dual-module": "^0.6.3",
14
14
  "typescript": "^5.0.2",
15
15
  "vitest": "^3.0.9"
16
16
  },
17
17
  "dependencies": {
18
- "eventsource": "^2.0.2",
19
- "@vertesia/api-fetch-client": "0.52.0",
18
+ "eventsource": "^3.0.6",
19
+ "@vertesia/common": "0.54.0",
20
20
  "@llumiverse/core": "0.17.0",
21
- "@vertesia/common": "0.52.0"
21
+ "@vertesia/api-fetch-client": "0.54.0"
22
22
  },
23
23
  "ts_dual_module": {
24
24
  "outDir": "lib"
package/src/ApiKeysApi.ts CHANGED
@@ -50,7 +50,7 @@ export class ApiKeysApi extends ApiTopic {
50
50
  }
51
51
 
52
52
  /**
53
- * get or create a temporary public key which can be used from browser to browse and execute itneractions.
53
+ * get or create a temporary public key which can be used from browser to browse and execute interactions.
54
54
  * If a public key already exists for the given project (or for the current organization) then it is returned, otherwise a new one is created.
55
55
  * The payload object can contain the following properties:
56
56
  * - name: the name of the public key. If not specified a random name is generated.
@@ -34,8 +34,8 @@ export default class EnvironmentsApi extends ApiTopic {
34
34
  }
35
35
 
36
36
  /**
37
- * udpate enabled models and / or config. If enabled_models is not provided, the existing enabled models will not change.
38
- * Same, if config is not provioded the exiting config is not changed.
37
+ * Update enabled models and / or config. If enabled_models is not provided, the existing enabled models will not change.
38
+ * Same, if config is not provided the exiting config is not changed.
39
39
  * If the config is provided then it will be updated without removing fields that are not provided.
40
40
  *
41
41
  * @param id
@@ -31,7 +31,7 @@ export class InteractionBase<P = any, R = any> {
31
31
  * the run completes or fails.
32
32
  * If the onChunk callback is passed then the streaming of the result is enabled.
33
33
  * The onChunk callback with be called with the next chunk of the result as soon as it is available.
34
- * When all chunks are received the fucntion will return the resolved promise
34
+ * When all chunks are received the function will return the resolved promise
35
35
  * @param id of the interaction to execute
36
36
  * @param payload InteractionExecutionPayload
37
37
  * @param onChunk callback to be called when the next chunk of the response is available
@@ -32,7 +32,7 @@ export default class InteractionsApi extends ApiTopic {
32
32
  });
33
33
  }
34
34
  /**
35
- * Find interractions given a mongo match query.
35
+ * Find interactions given a mongo match query.
36
36
  * You can also specify if prompts schemas are included in the result
37
37
  */
38
38
  listEndpoints(payload: InteractionEndpointQuery): Promise<InteractionRef[]> {
@@ -92,7 +92,7 @@ export default class InteractionsApi extends ApiTopic {
92
92
  }
93
93
 
94
94
  /**
95
- * Retrieve an existing interaction definiton
95
+ * Retrieve an existing interaction definition
96
96
  * @param id of the interaction to retrieve
97
97
  * @returns Interaction
98
98
  **/
@@ -101,7 +101,7 @@ export default class InteractionsApi extends ApiTopic {
101
101
  }
102
102
 
103
103
  /**
104
- * Update an existing interaction definiton
104
+ * Update an existing interaction definition
105
105
  * @param id of the interaction to update
106
106
  * @param payload InteractionUpdatePayload
107
107
  * @returns Interaction
@@ -121,7 +121,7 @@ export default class InteractionsApi extends ApiTopic {
121
121
  * the run completes or fails.
122
122
  * If the onChunk callback is passed then the streaming of the result is enabled.
123
123
  * The onChunk callback with be called with the next chunk of the result as soon as it is available.
124
- * When all chunks are received the fucntion will return the resolved promise
124
+ * When all chunks are received the function will return the resolved promise
125
125
  * @param id of the interaction to execute
126
126
  * @param payload InteractionExecutionPayload
127
127
  * @param onChunk callback to be called when the next chunk of the response is available
@@ -146,7 +146,7 @@ export default class InteractionsApi extends ApiTopic {
146
146
  /**
147
147
  * Same as execute but uses the interaction name selector instead of the id.
148
148
  *
149
- * A name selector is the interaction endpoint name suffuxed with an optional tag or version wich is starting with a `@` character.
149
+ * A name selector is the interaction endpoint name suffixed with an optional tag or version which is starting with a `@` character.
150
150
  * 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.
151
151
  * Examples of selectors:
152
152
  * - `ReviewContract` - select the latest version of the ReviewContract interaction
@@ -0,0 +1,28 @@
1
+ import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
2
+ import type { PluginManifest } from "@vertesia/common";
3
+
4
+ export default class PluginsApi extends ApiTopic {
5
+
6
+ constructor(parent: ClientBase) {
7
+ super(parent, "/api/v1/plugins")
8
+ }
9
+
10
+ create(manifest: Omit<PluginManifest, 'id'>): Promise<PluginManifest> {
11
+ return this.post('/', { payload: manifest });
12
+ }
13
+
14
+ update(manifest: PluginManifest) {
15
+ return this.put(`/${manifest.id}`, { payload: manifest });
16
+ }
17
+
18
+ /**
19
+ * If a project ID is specified through the project query param
20
+ * then only the plugins that are enabled on the project are returned.
21
+ * @param query
22
+ * @returns
23
+ */
24
+ list(): Promise<PluginManifest[]> {
25
+ return this.get('/');
26
+ }
27
+
28
+ }
@@ -1,5 +1,5 @@
1
1
  import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
2
- import { AwsConfiguration, GithubConfiguration, GladiaConfiguration, ICreateProjectPayload, MacgicPdfConfiguration, Project, ProjectIntegrationListEntry, ProjectRef, SupportedIntegrations } from "@vertesia/common";
2
+ import { AwsConfiguration, GithubConfiguration, GladiaConfiguration, ICreateProjectPayload, MagicPdfConfiguration, PluginManifest, Project, ProjectIntegrationListEntry, ProjectRef, SupportedIntegrations } from "@vertesia/common";
3
3
 
4
4
  export default class ProjectsApi extends ApiTopic {
5
5
  constructor(parent: ClientBase) {
@@ -26,6 +26,14 @@ export default class ProjectsApi extends ApiTopic {
26
26
  });
27
27
  }
28
28
 
29
+ listPlugins(projectId: string): Promise<PluginManifest[]> {
30
+ return this.get(`/${projectId}/plugins`);
31
+ }
32
+
33
+ setPlugins(projectId: string, pluginIds: string[]): Promise<{ count: number }> {
34
+ return this.post(`/${projectId}/plugins`, { payload: { plugins: pluginIds } });
35
+ }
36
+
29
37
  integrations: IntegrationsConfigurationApi = new IntegrationsConfigurationApi(this);
30
38
 
31
39
  }
@@ -40,7 +48,7 @@ class IntegrationsConfigurationApi extends ApiTopic {
40
48
  return this.get(`/${projectId}/integrations`).then(res => res.integrations);
41
49
  }
42
50
 
43
- retrieve(projectId: string, integrationId: SupportedIntegrations): Promise<GladiaConfiguration | GithubConfiguration | AwsConfiguration | MacgicPdfConfiguration | undefined> {
51
+ retrieve(projectId: string, integrationId: SupportedIntegrations): Promise<GladiaConfiguration | GithubConfiguration | AwsConfiguration | MagicPdfConfiguration | undefined> {
44
52
  return this.get(`/${projectId}/integrations/${integrationId}`).catch(err => {
45
53
  if (err.status === 404) {
46
54
  return undefined;
package/src/PromptsApi.ts CHANGED
@@ -123,7 +123,7 @@ export default class PromptsApi extends ApiTopic {
123
123
  }
124
124
 
125
125
  /**
126
- * List the versions of the prompt template. Returens an empty array if no versions are found
126
+ * List the versions of the prompt template. Returns an empty array if no versions are found
127
127
  * @param id
128
128
  * @returns the versions list or an empty array if no versions are found
129
129
  */
package/src/client.ts CHANGED
@@ -15,6 +15,7 @@ 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
@@ -218,6 +219,7 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
218
219
  iam = new IamApi(this);
219
220
  refs = new RefsApi(this);
220
221
  commands = new CommandsApi(this);
222
+ plugins = new PluginsApi(this);
221
223
  }
222
224
 
223
225
  function isApiKey(apiKey: string) {
package/src/execute.ts CHANGED
@@ -1,11 +1,11 @@
1
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
@@ -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
@@ -1,35 +1,54 @@
1
- import { ApiTopic, ClientBase } from '@vertesia/api-fetch-client';
2
- import { ComplexSearchPayload, ComputeObjectFacetPayload, ContentObject, ContentObjectItem, ContentSource, CreateContentObjectPayload, Embedding, ExportPropertiesPayload, ExportPropertiesResponse, FindPayload, GetFileUrlPayload, GetFileUrlResponse, GetRenditionResponse, GetUploadUrlPayload, ListWorkflowRunsResponse, ObjectSearchPayload, ObjectSearchQuery, SupportedEmbeddingTypes } from '@vertesia/common';
3
-
4
- import { StreamSource } from '../StreamSource.js';
5
- import { ZenoClient } from './client.js';
6
- import { AnalyzeDocApi } from './AnalyzeDocApi.js';
7
-
8
- export interface UploadContentObjectPayload extends Omit<CreateContentObjectPayload, 'content'> {
9
- content?: StreamSource | File | {
10
-
11
- // the source URI
12
- source: string,
13
- // the original name of the input file if any
14
- name?: string,
15
- // the mime type of the content source.
16
- type?: string
17
-
18
- // the target id in the content store
19
- id?: string
20
-
21
- }
1
+ import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
2
+ import {
3
+ ComplexSearchPayload,
4
+ ComputeObjectFacetPayload,
5
+ ContentObject,
6
+ ContentObjectItem,
7
+ ContentSource,
8
+ CreateContentObjectPayload,
9
+ Embedding,
10
+ ExportPropertiesPayload,
11
+ ExportPropertiesResponse,
12
+ FindPayload,
13
+ GetFileUrlPayload,
14
+ GetFileUrlResponse,
15
+ GetRenditionResponse,
16
+ GetUploadUrlPayload,
17
+ ListWorkflowRunsResponse,
18
+ ObjectSearchPayload,
19
+ ObjectSearchQuery,
20
+ SupportedEmbeddingTypes,
21
+ } from "@vertesia/common";
22
+
23
+ import { StreamSource } from "../StreamSource.js";
24
+ import { ZenoClient } from "./client.js";
25
+ import { AnalyzeDocApi } from "./AnalyzeDocApi.js";
26
+
27
+ export interface UploadContentObjectPayload extends Omit<CreateContentObjectPayload, "content"> {
28
+ content?:
29
+ | StreamSource
30
+ | File
31
+ | {
32
+ // the source URI
33
+ source: string;
34
+ // the original name of the input file if any
35
+ name?: string;
36
+ // the mime type of the content source.
37
+ type?: string;
38
+
39
+ // the target id in the content store
40
+ id?: string;
41
+ };
22
42
  }
23
43
 
24
44
  export interface ComputeFacetsResponse {
25
- type?: { _id: string, count: number }[];
26
- location?: { _id: string, count: number }[];
27
- status?: { _id: string, count: number }[];
45
+ type?: { _id: string; count: number }[];
46
+ location?: { _id: string; count: number }[];
47
+ status?: { _id: string; count: number }[];
28
48
  total?: { count: number }[];
29
49
  }
30
50
 
31
51
  export class ObjectsApi extends ApiTopic {
32
-
33
52
  constructor(parent: ClientBase) {
34
53
  super(parent, "/api/v1/objects");
35
54
  }
@@ -39,64 +58,85 @@ export class ObjectsApi extends ApiTopic {
39
58
  }
40
59
 
41
60
  getUploadUrl(payload: GetUploadUrlPayload): Promise<GetFileUrlResponse> {
42
- return this.post('/upload-url', {
43
- payload
44
- })
61
+ return this.post("/upload-url", {
62
+ payload,
63
+ });
45
64
  }
46
65
 
47
66
  getDownloadUrl(fileUri: string): Promise<{ url: string }> {
48
- return this.post('/download-url', {
67
+ return this.post("/download-url", {
49
68
  payload: {
50
- file: fileUri
51
- } satisfies GetFileUrlPayload
52
- })
69
+ file: fileUri,
70
+ } satisfies GetFileUrlPayload,
71
+ });
53
72
  }
54
73
 
55
74
  getContentSource(objectId: string): Promise<ContentSource> {
56
75
  return this.get(`/${objectId}/content-source`);
57
76
  }
58
77
 
59
- list(payload: ObjectSearchPayload = {}): Promise<ContentObjectItem[]> {
78
+ /**
79
+ * List objects with revision filtering options
80
+ *
81
+ * @param payload Search/filter parameters
82
+ * @returns Matching content objects
83
+ */
84
+ list<T = any>(payload: ObjectSearchPayload = {}): Promise<ContentObjectItem<T>[]> {
60
85
  const limit = payload.limit || 100;
61
86
  const offset = payload.offset || 0;
62
- const query = payload.query || {} as ObjectSearchQuery;
87
+ const query = payload.query || ({} as ObjectSearchQuery);
88
+
89
+ // Add revision filtering options
90
+ const showAllRevisions = payload.show_all_revisions === true;
91
+ const revisionRoot = payload.from_root;
63
92
 
64
93
  return this.get("/", {
65
94
  query: {
66
95
  limit,
67
96
  offset,
68
- ...query
69
- }
97
+ ...query,
98
+ show_all_revisions: showAllRevisions ? "true" : undefined,
99
+ from_root: revisionRoot,
100
+ },
70
101
  });
71
102
  }
72
103
 
73
104
  computeFacets(query: ComputeObjectFacetPayload): Promise<ComputeFacetsResponse> {
74
105
  return this.post("/facets", {
75
- payload: query
106
+ payload: query,
76
107
  });
77
108
  }
78
109
 
79
- listFolders(path: string = '/') {
80
- path;//TODO
110
+ listFolders(path: string = "/") {
111
+ path; //TODO
81
112
  }
82
113
 
114
+ /** Find object based on query */
83
115
  find(payload: FindPayload): Promise<ContentObject[]> {
84
116
  return this.post("/find", {
85
- payload
117
+ payload,
86
118
  });
87
119
  }
88
120
 
121
+ /** Count number of objects matching this query */
122
+ count(payload: FindPayload): Promise<{ count: number }> {
123
+ return this.post("/count", {
124
+ payload,
125
+ });
126
+ }
127
+
128
+ /** Search object — different from find because allow full text search */
89
129
  search(payload: ComplexSearchPayload): Promise<ContentObjectItem[]> {
90
130
  return this.post("/search", {
91
- payload
131
+ payload,
92
132
  });
93
133
  }
94
134
 
95
135
  retrieve(id: string, select?: string): Promise<ContentObject> {
96
136
  return this.get(`/${id}`, {
97
137
  query: {
98
- select
99
- }
138
+ select,
139
+ },
100
140
  });
101
141
  }
102
142
 
@@ -110,10 +150,10 @@ export class ObjectsApi extends ApiTopic {
110
150
  const { url, id, mime_type } = await this.getUploadUrl({
111
151
  id: isStream ? source.id : undefined,
112
152
  name: source.name,
113
- mime_type: source.type
153
+ mime_type: source.type,
114
154
  });
115
155
 
116
- console.log(`Uploading file to ${url}`, { id, mime_type, isStream, source })
156
+ console.log(`Uploading content to ${url}`, { id, mime_type, isStream, source });
117
157
 
118
158
  // upload the file content to the signed URL
119
159
  /*const res = await this.fetch(url, {
@@ -134,44 +174,50 @@ export class ObjectsApi extends ApiTopic {
134
174
  });*/
135
175
 
136
176
  const res = await fetch(url, {
137
- method: 'PUT',
177
+ method: "PUT",
138
178
  body: isStream ? source.stream : source,
139
179
  //@ts-ignore: duplex is not in the types. See https://github.com/node-fetch/node-fetch/issues/1769
140
180
  duplex: isStream ? "half" : undefined,
141
181
  headers: {
142
- 'Content-Type': mime_type || 'application/octet-stream'
143
- }
144
- }).then((res: Response) => {
145
- if (res.ok) {
146
- return res;
147
- } else {
148
- console.log(res);
149
- throw new Error(`Failed to upload file: ${res.statusText}`);
150
- }
151
- }).catch(err => {
152
- console.error('Failed to upload file', err);
153
- throw err;
154
- });
155
-
182
+ "Content-Type": mime_type || "application/octet-stream",
183
+ },
184
+ })
185
+ .then((res: Response) => {
186
+ if (res.ok) {
187
+ return res;
188
+ } else {
189
+ console.log(res);
190
+ throw new Error(`Failed to upload file: ${res.statusText}`);
191
+ }
192
+ })
193
+ .catch((err) => {
194
+ console.error("Failed to upload file", err);
195
+ throw err;
196
+ });
197
+
198
+ //Etag need to be unquoted
199
+ //When a server returns an ETag header, it includes the quotes around the actual hash value.
200
+ //This is part of the HTTP specification (RFC 7232), which states that ETags should be
201
+ //enclosed in double quotes.
202
+ const etag = res.headers.get("etag")?.replace(/^"(.*)"$/, "$1");
156
203
 
157
204
  return {
158
205
  source: id,
159
206
  name: source.name,
160
207
  type: mime_type,
161
- etag: res.headers.get('etag') ?? undefined
162
- }
208
+ etag,
209
+ };
163
210
  }
164
211
 
165
212
  async create(payload: UploadContentObjectPayload): Promise<ContentObject> {
166
-
167
213
  const createPayload: CreateContentObjectPayload = {
168
- ...payload
214
+ ...payload,
169
215
  };
170
216
  if (payload.content instanceof StreamSource || payload.content instanceof File) {
171
217
  createPayload.content = await this.upload(payload.content);
172
218
  }
173
- return await this.post('/', {
174
- payload: createPayload
219
+ return await this.post("/", {
220
+ payload: createPayload,
175
221
  });
176
222
  }
177
223
 
@@ -184,25 +230,72 @@ export class ObjectsApi extends ApiTopic {
184
230
  * @returns
185
231
  */
186
232
  async createFromExternalSource(uri: string, payload: CreateContentObjectPayload = {}): Promise<ContentObject> {
187
- const metadata = await ((this.client as ZenoClient).files.getMetadata(uri));
233
+ const metadata = await (this.client as ZenoClient).files.getMetadata(uri);
188
234
  const createPayload: CreateContentObjectPayload = {
189
235
  ...payload,
190
236
  content: {
191
237
  source: uri,
192
238
  name: metadata.name,
193
239
  type: metadata.contentType,
194
- etag: metadata.etag
195
- }
240
+ etag: metadata.etag,
241
+ },
196
242
  };
197
- return await this.post('/', {
198
- payload: createPayload
243
+ return await this.post("/", {
244
+ payload: createPayload,
199
245
  });
200
246
  }
201
247
 
202
- update(id: string, payload: Partial<CreateContentObjectPayload>): Promise<ContentObject> {
203
- return this.put(`/${id}`, {
204
- payload
205
- });
248
+ /**
249
+ * Updates an existing object or creates a new revision
250
+ * Handles file uploads similar to the create method
251
+ *
252
+ * @param id The ID of the object to update
253
+ * @param payload The changes to apply
254
+ * @param options Additional options
255
+ * @param options.createRevision Whether to create a new revision instead of updating in place
256
+ * @param options.revisionLabel Optional label for the revision (e.g., "v1.2")
257
+ * @returns The updated object or newly created revision
258
+ */
259
+ async update(
260
+ id: string,
261
+ payload: Partial<CreateContentObjectPayload>,
262
+ options?: {
263
+ createRevision?: boolean;
264
+ revisionLabel?: string;
265
+ },
266
+ ): Promise<ContentObject> {
267
+ const updatePayload: Partial<CreateContentObjectPayload> = {
268
+ ...payload,
269
+ };
270
+
271
+ // Handle file upload if content is provided as File or StreamSource
272
+ if (payload.content instanceof StreamSource || payload.content instanceof File) {
273
+ updatePayload.content = await this.upload(payload.content);
274
+ }
275
+
276
+ if (options?.createRevision) {
277
+ return this.put(`/${id}`, {
278
+ payload: updatePayload,
279
+ headers: {
280
+ "x-create-revision": "true",
281
+ "x-revision-label": options.revisionLabel || "",
282
+ },
283
+ });
284
+ } else {
285
+ return this.put(`/${id}`, {
286
+ payload: updatePayload,
287
+ });
288
+ }
289
+ }
290
+
291
+ /**
292
+ * Retrieves all revisions of a content object
293
+ *
294
+ * @param id The ID of any revision in the object's history
295
+ * @returns Array of all revisions sharing the same root
296
+ */
297
+ getRevisions(id: string): Promise<ContentObjectItem[]> {
298
+ return this.get(`/${id}/revisions`);
206
299
  }
207
300
 
208
301
  delete(id: string): Promise<{ id: string }> {
@@ -210,9 +303,7 @@ export class ObjectsApi extends ApiTopic {
210
303
  }
211
304
 
212
305
  listWorkflowRuns(documentId: string): Promise<ListWorkflowRunsResponse> {
213
-
214
- return this.get(`/${documentId}/workflow-runs`)
215
-
306
+ return this.get(`/${documentId}/workflow-runs`);
216
307
  }
217
308
 
218
309
  listRenditions(documentId: string): Promise<ContentObjectItem[]> {
@@ -220,31 +311,33 @@ export class ObjectsApi extends ApiTopic {
220
311
  }
221
312
 
222
313
  getRendition(documentId: string, options: GetRenditionParams): Promise<GetRenditionResponse> {
223
-
224
314
  const query = {
225
315
  max_hw: options.max_hw,
226
- generate_if_missing: options.generate_if_missing
227
- }
316
+ generate_if_missing: options.generate_if_missing,
317
+ };
228
318
 
229
319
  return this.get(`/${documentId}/renditions/${options.format}`, { query });
230
320
  }
231
321
 
232
322
  exportProperties(payload: ExportPropertiesPayload): Promise<ExportPropertiesResponse> {
233
323
  return this.post("/export", {
234
- payload
324
+ payload,
235
325
  });
236
326
  }
237
327
 
238
- setEmbedding(id: string, type: SupportedEmbeddingTypes, payload: Embedding): Promise<Record<SupportedEmbeddingTypes, Embedding>> {
328
+ setEmbedding(
329
+ id: string,
330
+ type: SupportedEmbeddingTypes,
331
+ payload: Embedding,
332
+ ): Promise<Record<SupportedEmbeddingTypes, Embedding>> {
239
333
  return this.put(`/${id}/embeddings/${type}`, {
240
- payload
334
+ payload,
241
335
  });
242
336
  }
243
-
244
337
  }
245
338
 
246
339
  interface GetRenditionParams {
247
340
  format: string;
248
341
  max_hw?: number;
249
342
  generate_if_missing?: boolean;
250
- }
343
+ }