@vertesia/client 0.50.1 → 0.53.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 (131) hide show
  1. package/lib/cjs/AccountApi.js +11 -1
  2. package/lib/cjs/AccountApi.js.map +1 -1
  3. package/lib/cjs/AccountsApi.js +3 -0
  4. package/lib/cjs/AccountsApi.js.map +1 -1
  5. package/lib/cjs/InteractionsApi.js +25 -0
  6. package/lib/cjs/InteractionsApi.js.map +1 -1
  7. package/lib/cjs/RunsApi.js +34 -8
  8. package/lib/cjs/RunsApi.js.map +1 -1
  9. package/lib/cjs/client.js +65 -10
  10. package/lib/cjs/client.js.map +1 -1
  11. package/lib/cjs/execute.js +6 -0
  12. package/lib/cjs/execute.js.map +1 -1
  13. package/lib/cjs/index.js +0 -1
  14. package/lib/cjs/index.js.map +1 -1
  15. package/lib/cjs/nodejs/NodeStreamSource.js +45 -0
  16. package/lib/cjs/nodejs/NodeStreamSource.js.map +1 -0
  17. package/lib/cjs/nodejs/index.js +18 -0
  18. package/lib/cjs/nodejs/index.js.map +1 -0
  19. package/lib/cjs/store/AnalyzeDocApi.js +56 -0
  20. package/lib/cjs/store/AnalyzeDocApi.js.map +1 -0
  21. package/lib/cjs/store/CollectionsApi.js +77 -0
  22. package/lib/cjs/store/CollectionsApi.js.map +1 -0
  23. package/lib/cjs/store/CommandsApi.js +7 -23
  24. package/lib/cjs/store/CommandsApi.js.map +1 -1
  25. package/lib/cjs/store/EmbeddingsApi.js +29 -0
  26. package/lib/cjs/store/EmbeddingsApi.js.map +1 -0
  27. package/lib/cjs/store/FilesApi.js +6 -0
  28. package/lib/cjs/store/FilesApi.js.map +1 -1
  29. package/lib/cjs/store/ObjectsApi.js +4 -0
  30. package/lib/cjs/store/ObjectsApi.js.map +1 -1
  31. package/lib/cjs/store/TypesApi.js +11 -6
  32. package/lib/cjs/store/TypesApi.js.map +1 -1
  33. package/lib/cjs/store/WorkflowsApi.js +90 -8
  34. package/lib/cjs/store/WorkflowsApi.js.map +1 -1
  35. package/lib/cjs/store/client.js +4 -0
  36. package/lib/cjs/store/client.js.map +1 -1
  37. package/lib/esm/AccountApi.js +11 -1
  38. package/lib/esm/AccountApi.js.map +1 -1
  39. package/lib/esm/AccountsApi.js +3 -0
  40. package/lib/esm/AccountsApi.js.map +1 -1
  41. package/lib/esm/InteractionsApi.js +26 -1
  42. package/lib/esm/InteractionsApi.js.map +1 -1
  43. package/lib/esm/RunsApi.js +34 -8
  44. package/lib/esm/RunsApi.js.map +1 -1
  45. package/lib/esm/client.js +65 -10
  46. package/lib/esm/client.js.map +1 -1
  47. package/lib/esm/execute.js +5 -0
  48. package/lib/esm/execute.js.map +1 -1
  49. package/lib/esm/index.js +0 -1
  50. package/lib/esm/index.js.map +1 -1
  51. package/lib/esm/nodejs/NodeStreamSource.js +41 -0
  52. package/lib/esm/nodejs/NodeStreamSource.js.map +1 -0
  53. package/lib/esm/nodejs/index.js +2 -0
  54. package/lib/esm/nodejs/index.js.map +1 -0
  55. package/lib/esm/store/AnalyzeDocApi.js +52 -0
  56. package/lib/esm/store/AnalyzeDocApi.js.map +1 -0
  57. package/lib/esm/store/CollectionsApi.js +73 -0
  58. package/lib/esm/store/CollectionsApi.js.map +1 -0
  59. package/lib/esm/store/CommandsApi.js +6 -21
  60. package/lib/esm/store/CommandsApi.js.map +1 -1
  61. package/lib/esm/store/EmbeddingsApi.js +25 -0
  62. package/lib/esm/store/EmbeddingsApi.js.map +1 -0
  63. package/lib/esm/store/FilesApi.js +6 -0
  64. package/lib/esm/store/FilesApi.js.map +1 -1
  65. package/lib/esm/store/ObjectsApi.js +4 -0
  66. package/lib/esm/store/ObjectsApi.js.map +1 -1
  67. package/lib/esm/store/TypesApi.js +11 -6
  68. package/lib/esm/store/TypesApi.js.map +1 -1
  69. package/lib/esm/store/WorkflowsApi.js +91 -9
  70. package/lib/esm/store/WorkflowsApi.js.map +1 -1
  71. package/lib/esm/store/client.js +4 -0
  72. package/lib/esm/store/client.js.map +1 -1
  73. package/lib/tsconfig.tsbuildinfo +1 -1
  74. package/lib/types/AccountApi.d.ts +8 -2
  75. package/lib/types/AccountApi.d.ts.map +1 -1
  76. package/lib/types/AccountsApi.d.ts +1 -0
  77. package/lib/types/AccountsApi.d.ts.map +1 -1
  78. package/lib/types/InteractionsApi.d.ts +23 -2
  79. package/lib/types/InteractionsApi.d.ts.map +1 -1
  80. package/lib/types/ProjectsApi.d.ts +2 -2
  81. package/lib/types/ProjectsApi.d.ts.map +1 -1
  82. package/lib/types/RunsApi.d.ts +17 -2
  83. package/lib/types/RunsApi.d.ts.map +1 -1
  84. package/lib/types/client.d.ts +20 -4
  85. package/lib/types/client.d.ts.map +1 -1
  86. package/lib/types/execute.d.ts +7 -3
  87. package/lib/types/execute.d.ts.map +1 -1
  88. package/lib/types/index.d.ts +2 -3
  89. package/lib/types/index.d.ts.map +1 -1
  90. package/lib/types/nodejs/NodeStreamSource.d.ts +9 -0
  91. package/lib/types/nodejs/NodeStreamSource.d.ts.map +1 -0
  92. package/lib/types/nodejs/index.d.ts +1 -0
  93. package/lib/types/nodejs/index.d.ts.map +1 -0
  94. package/lib/types/store/AnalyzeDocApi.d.ts +17 -0
  95. package/lib/types/store/AnalyzeDocApi.d.ts.map +1 -0
  96. package/lib/types/store/CollectionsApi.d.ts +37 -0
  97. package/lib/types/store/CollectionsApi.d.ts.map +1 -0
  98. package/lib/types/store/CommandsApi.d.ts +5 -8
  99. package/lib/types/store/CommandsApi.d.ts.map +1 -1
  100. package/lib/types/store/EmbeddingsApi.d.ts +12 -0
  101. package/lib/types/store/EmbeddingsApi.d.ts.map +1 -0
  102. package/lib/types/store/FilesApi.d.ts.map +1 -1
  103. package/lib/types/store/ObjectsApi.d.ts +2 -0
  104. package/lib/types/store/ObjectsApi.d.ts.map +1 -1
  105. package/lib/types/store/TypesApi.d.ts +13 -3
  106. package/lib/types/store/TypesApi.d.ts.map +1 -1
  107. package/lib/types/store/WorkflowsApi.d.ts +16 -8
  108. package/lib/types/store/WorkflowsApi.d.ts.map +1 -1
  109. package/lib/types/store/client.d.ts +4 -0
  110. package/lib/types/store/client.d.ts.map +1 -1
  111. package/package.json +25 -10
  112. package/src/AccountApi.ts +14 -2
  113. package/src/AccountsApi.ts +4 -0
  114. package/src/InteractionsApi.ts +34 -3
  115. package/src/ProjectsApi.ts +2 -2
  116. package/src/RunsApi.ts +67 -29
  117. package/src/client.test.ts +94 -0
  118. package/src/client.ts +84 -13
  119. package/src/execute.ts +9 -3
  120. package/src/index.ts +2 -3
  121. package/src/nodejs/NodeStreamSource.ts +43 -0
  122. package/src/nodejs/index.ts +1 -0
  123. package/src/store/AnalyzeDocApi.ts +61 -0
  124. package/src/store/CollectionsApi.ts +93 -0
  125. package/src/store/CommandsApi.ts +6 -33
  126. package/src/store/EmbeddingsApi.ts +39 -0
  127. package/src/store/FilesApi.ts +4 -0
  128. package/src/store/ObjectsApi.ts +5 -0
  129. package/src/store/TypesApi.ts +12 -8
  130. package/src/store/WorkflowsApi.ts +127 -25
  131. package/src/store/client.ts +4 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vertesia/client",
3
- "version": "0.50.1",
3
+ "version": "0.53.0",
4
4
  "type": "module",
5
5
  "types": "./lib/types/index.d.ts",
6
6
  "files": [
@@ -9,28 +9,43 @@
9
9
  ],
10
10
  "devDependencies": {
11
11
  "@types/eventsource": "^1.1.14",
12
- "@types/node": "^20.8.9",
12
+ "@types/node": "^22.13.5",
13
13
  "ts-dual-module": "^0.6.3",
14
14
  "typescript": "^5.0.2",
15
- "vitest": "^2.1.8"
15
+ "vitest": "^3.0.9"
16
16
  },
17
17
  "dependencies": {
18
18
  "eventsource": "^2.0.2",
19
- "@vertesia/common": "0.50.1",
20
- "@vertesia/api-fetch-client": "0.50.1",
21
- "@llumiverse/core": "0.15.0"
19
+ "@vertesia/api-fetch-client": "0.52.0",
20
+ "@llumiverse/core": "0.17.0",
21
+ "@vertesia/common": "0.52.0"
22
22
  },
23
23
  "ts_dual_module": {
24
24
  "outDir": "lib"
25
25
  },
26
26
  "exports": {
27
- "types": "./lib/types/index.d.ts",
28
- "import": "./lib/esm/index.js",
29
- "require": "./lib/cjs/index.js"
27
+ ".": {
28
+ "types": "./lib/types/index.d.ts",
29
+ "import": "./lib/esm/index.js",
30
+ "require": "./lib/cjs/index.js"
31
+ },
32
+ "./node": {
33
+ "types": "./lib/types/nodejs/index.d.ts",
34
+ "import": "./lib/esm/nodejs/index.js",
35
+ "require": "./lib/cjs/nodejs/index.js"
36
+ }
37
+ },
38
+ "typesVersions": {
39
+ "*": {
40
+ "node": [
41
+ "./lib/types/nodejs/index.d.ts"
42
+ ]
43
+ }
30
44
  },
31
45
  "scripts": {
32
46
  "eslint": "eslint './src/**/*.{jsx,js,tsx,ts}'",
33
47
  "build": "pnpm exec tsmod build",
34
- "clean": "rimraf ./node_modules ./lib ./tsconfig.tsbuildinfo"
48
+ "clean": "rimraf ./node_modules ./lib ./tsconfig.tsbuildinfo",
49
+ "test": "vitest run"
35
50
  }
36
51
  }
package/src/AccountApi.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
2
- import { Account, InviteUserRequestPayload, InviteUserResponsePayload, OnboardingProgress, ProjectRef, TransientToken, UpdateAccountPayload, User, UserInviteTokenData } from "@vertesia/common";
2
+ import { Account, InviteUserRequestPayload, InviteUserResponsePayload, OnboardingProgress, ProjectRef, StripeBillingStatusResponse, TransientToken, UpdateAccountPayload, User, UserInviteTokenData } from "@vertesia/common";
3
3
 
4
4
  export default class AccountApi extends ApiTopic {
5
5
 
@@ -42,13 +42,21 @@ export default class AccountApi extends ApiTopic {
42
42
  }
43
43
 
44
44
  /**
45
- * Fetch Invites for account
45
+ * Fetch Invites for Principal
46
46
  * @returns UserInviteTokenData[]
47
47
  * */
48
48
  listInvites(): Promise<TransientToken<UserInviteTokenData>[]> {
49
49
  return this.get('/invites');
50
50
  }
51
51
 
52
+ /**
53
+ * Fetch Invites for Account
54
+ * @returns UserInviteTokenData[]
55
+ * */
56
+ listAccountInvitation(id: string): Promise<TransientToken<UserInviteTokenData>[]> {
57
+ return this.get(`/invites/${id}`);
58
+ }
59
+
52
60
  /**
53
61
  * Accept Invite for account
54
62
  * @returns UserInviteTokenData
@@ -81,4 +89,8 @@ export default class AccountApi extends ApiTopic {
81
89
  return this.get('/google-token');
82
90
  }
83
91
 
92
+ getStripeBillingStatus(): Promise<StripeBillingStatusResponse> {
93
+ return this.get('/stripe-billing-status')
94
+ }
95
+
84
96
  }
@@ -11,6 +11,10 @@ export default class AccountsApi extends ApiTopic {
11
11
  return this.post('/', { payload: { name } });
12
12
  }
13
13
 
14
+ list(): Promise<Account[]> {
15
+ return this.get('/');
16
+ }
17
+
14
18
 
15
19
 
16
20
 
@@ -1,7 +1,7 @@
1
- import { ComputeInteractionFacetPayload, ExecutionRun, GenerateInteractionPayload, GenerateTestDataPayload, ImprovePromptPayload, Interaction, InteractionCreatePayload, InteractionExecutionPayload, InteractionForkPayload, InteractionPublishPayload, InteractionRef, InteractionRefWithSchema, InteractionUpdatePayload, InteractionsExportPayload, InteractionSearchPayload, InteractionSearchQuery } from "@vertesia/common";
2
1
  import { ApiTopic, ClientBase, ServerError } from "@vertesia/api-fetch-client";
2
+ import { AsyncExecutionPayload, ComputeInteractionFacetPayload, ExecutionRun, GenerateInteractionPayload, GenerateTestDataPayload, ImprovePromptPayload, Interaction, InteractionCreatePayload, InteractionEndpointQuery, InteractionExecutionPayload, InteractionExecutionResult, InteractionForkPayload, InteractionPublishPayload, InteractionRef, InteractionRefWithSchema, InteractionSearchPayload, InteractionSearchQuery, InteractionUpdatePayload, InteractionsExportPayload } from "@vertesia/common";
3
3
  import { VertesiaClient } from "./client.js";
4
- import { executeInteraction, executeInteractionByName } from "./execute.js";
4
+ import { executeInteraction, executeInteractionAsync, executeInteractionByName } from "./execute.js";
5
5
 
6
6
  export interface ComputeInteractionFacetsResponse {
7
7
  tags?: { _id: string, count: number }[];
@@ -9,6 +9,10 @@ export interface ComputeInteractionFacetsResponse {
9
9
  total?: { count: number }[];
10
10
  }
11
11
 
12
+ export interface AsyncExecutionResult {
13
+ runId: string, workflowId: string
14
+ }
15
+
12
16
  export default class InteractionsApi extends ApiTopic {
13
17
  constructor(parent: ClientBase) {
14
18
  super(parent, "/api/v1/interactions");
@@ -27,6 +31,24 @@ export default class InteractionsApi extends ApiTopic {
27
31
  }
28
32
  });
29
33
  }
34
+ /**
35
+ * Find interractions given a mongo match query.
36
+ * You can also specify if prompts schemas are included in the result
37
+ */
38
+ listEndpoints(payload: InteractionEndpointQuery): Promise<InteractionRef[]> {
39
+ return this.post("/endpoints", {
40
+ payload
41
+ });
42
+ }
43
+
44
+ /**
45
+ * List all interaction versions in the project having the given endpoint name.
46
+ * This is useful to list orphaned versions
47
+ * @param name
48
+ */
49
+ listVersionsByName(name: string): Promise<InteractionRef[]> {
50
+ return this.get(`/versions/${name}`);
51
+ }
30
52
 
31
53
  /**
32
54
  * Get the list of all interactions facets
@@ -137,7 +159,7 @@ export default class InteractionsApi extends ApiTopic {
137
159
  * @returns
138
160
  */
139
161
  executeByName<P = any, R = any>(nameWithTag: string, payload: InteractionExecutionPayload = {},
140
- onChunk?: (chunk: string) => void): Promise<ExecutionRun<P, R>> {
162
+ onChunk?: (chunk: string) => void): Promise<InteractionExecutionResult<P, R>> {
141
163
  return executeInteractionByName(this.client as VertesiaClient, nameWithTag, payload, onChunk).catch(err => {
142
164
  if (err instanceof ServerError && err.payload?.id) {
143
165
  throw err.updateDetails({ run_id: err.payload.id });
@@ -147,6 +169,15 @@ export default class InteractionsApi extends ApiTopic {
147
169
  });
148
170
  }
149
171
 
172
+ /**
173
+ * Execute an interaction in an workflow
174
+ * @param payload
175
+ * @returns
176
+ */
177
+ executeAsync(payload: AsyncExecutionPayload): Promise<AsyncExecutionResult> {
178
+ return executeInteractionAsync(this.client as VertesiaClient, payload);
179
+ }
180
+
150
181
  publish(id: string, payload: InteractionPublishPayload): Promise<Interaction> {
151
182
  return this.post(`/${id}/publish`, {
152
183
  payload
@@ -1,5 +1,5 @@
1
1
  import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
2
- import { AwsConfiguration, GithubConfiguration, GladiaConfiguration, ICreateProjectPayload, Project, ProjectIntegrationListEntry, ProjectRef, SupportedIntegrations } from "@vertesia/common";
2
+ import { AwsConfiguration, GithubConfiguration, GladiaConfiguration, ICreateProjectPayload, MacgicPdfConfiguration, Project, ProjectIntegrationListEntry, ProjectRef, SupportedIntegrations } from "@vertesia/common";
3
3
 
4
4
  export default class ProjectsApi extends ApiTopic {
5
5
  constructor(parent: ClientBase) {
@@ -40,7 +40,7 @@ class IntegrationsConfigurationApi extends ApiTopic {
40
40
  return this.get(`/${projectId}/integrations`).then(res => res.integrations);
41
41
  }
42
42
 
43
- retrieve(projectId: string, integrationId: SupportedIntegrations): Promise<GladiaConfiguration | GithubConfiguration | AwsConfiguration | undefined> {
43
+ retrieve(projectId: string, integrationId: SupportedIntegrations): Promise<GladiaConfiguration | GithubConfiguration | AwsConfiguration | MacgicPdfConfiguration | undefined> {
44
44
  return this.get(`/${projectId}/integrations/${integrationId}`).catch(err => {
45
45
  if (err.status === 404) {
46
46
  return undefined;
package/src/RunsApi.ts CHANGED
@@ -1,26 +1,38 @@
1
- import { ComputeRunFacetPayload, ExecutionRun, ExecutionRunRef, FindPayload, RunCreatePayload, RunListingFilters, RunListingQueryOptions, RunSearchPayload } from "@vertesia/common";
2
1
  import { ApiTopic, ClientBase } from "@vertesia/api-fetch-client";
2
+ import {
3
+ CheckpointConversationPayload,
4
+ ComputeRunFacetPayload,
5
+ ExecutionRun,
6
+ ExecutionRunRef,
7
+ FindPayload,
8
+ RunCreatePayload,
9
+ RunListingFilters,
10
+ RunListingQueryOptions,
11
+ RunSearchPayload,
12
+ ToolResultsPayload,
13
+ UserMessagePayload,
14
+ } from "@vertesia/common";
3
15
  import { VertesiaClient } from "./client.js";
16
+ import { ExecutionResponse } from "@llumiverse/core";
4
17
 
5
18
  export interface FilterOption {
6
- id: string,
7
- name: string,
8
- count: number
19
+ id: string;
20
+ name: string;
21
+ count: number;
9
22
  }
10
23
 
11
24
  export interface ComputeRunFacetsResponse {
12
- environments?: { _id: string, count: number }[];
13
- interactions?: { _id: string, count: number }[];
14
- models?: { _id: string, count: number }[];
15
- tags?: { _id: string, count: number }[];
16
- status?: { _id: string, count: number }[];
25
+ environments?: { _id: string; count: number }[];
26
+ interactions?: { _id: string; count: number }[];
27
+ models?: { _id: string; count: number }[];
28
+ tags?: { _id: string; count: number }[];
29
+ status?: { _id: string; count: number }[];
17
30
  total?: { count: number }[];
18
31
  }
19
32
 
20
33
  export class RunsApi extends ApiTopic {
21
-
22
34
  constructor(parent: ClientBase) {
23
- super(parent, "/api/v1/runs")
35
+ super(parent, "/api/v1/runs");
24
36
  }
25
37
 
26
38
  /**
@@ -30,29 +42,29 @@ export class RunsApi extends ApiTopic {
30
42
  * @returns InteractionResult[]
31
43
  **/
32
44
  list({ limit, offset, filters }: RunListingQueryOptions): Promise<ExecutionRunRef[]> {
33
-
34
45
  const query = {
35
46
  limit,
36
47
  offset,
37
- ...filters
38
- }
48
+ ...filters,
49
+ };
39
50
 
40
- return this.get('/', { query: query });
51
+ return this.get("/", { query: query });
41
52
  }
42
53
 
43
54
  find(payload: FindPayload): Promise<ExecutionRun[]> {
44
55
  return this.post("/find", {
45
- payload
56
+ payload,
46
57
  });
47
58
  }
48
59
 
49
60
  /**
50
61
  * Get a run by id
62
+ *
51
63
  * @param id
52
64
  * @returns InteractionResult
53
65
  **/
54
- retrieve(id: string): Promise<ExecutionRun> {
55
- return this.get('/' + id);
66
+ retrieve<P = any, R = any>(id: string): Promise<ExecutionRun<P, R>> {
67
+ return this.get("/" + id);
56
68
  }
57
69
 
58
70
  /**
@@ -61,10 +73,9 @@ export class RunsApi extends ApiTopic {
61
73
  */
62
74
  filterOptions(field: string, filters: RunListingFilters): Promise<FilterOption[]> {
63
75
  const query = {
64
- ...filters
65
- }
76
+ ...filters,
77
+ };
66
78
  return this.get(`/filter-options/${field}`, { query });
67
-
68
79
  }
69
80
 
70
81
  create(payload: RunCreatePayload): Promise<ExecutionRun> {
@@ -72,14 +83,42 @@ export class RunsApi extends ApiTopic {
72
83
  if (sessionTags) {
73
84
  let tags = Array.isArray(sessionTags) ? sessionTags : [sessionTags];
74
85
  if (Array.isArray(payload.tags)) {
75
- tags = tags.concat(payload.tags)
86
+ tags = tags.concat(payload.tags);
76
87
  } else if (payload.tags) {
77
- tags = tags.concat([payload.tags])
88
+ tags = tags.concat([payload.tags]);
78
89
  }
79
- payload = { ...payload, tags }
90
+ payload = { ...payload, tags };
80
91
  }
81
92
  return this.post("/", {
82
- payload
93
+ payload,
94
+ });
95
+ }
96
+
97
+ /**
98
+ * Send tool results and continues the conversation
99
+ * @param payload
100
+ * @returns
101
+ */
102
+ sendToolResults(payload: ToolResultsPayload): Promise<ExecutionResponse> {
103
+ return this.post(`/tool-results`, {
104
+ payload,
105
+ });
106
+ }
107
+
108
+ /**
109
+ *
110
+ * @param payload
111
+ * @returns
112
+ */
113
+ sendUserMessage(payload: UserMessagePayload): Promise<ExecutionResponse> {
114
+ return this.post(`/user-message`, {
115
+ payload,
116
+ });
117
+ }
118
+
119
+ createCheckpoint(payload: CheckpointConversationPayload): Promise<ExecutionResponse> {
120
+ return this.post(`/checkpoint`, {
121
+ payload,
83
122
  });
84
123
  }
85
124
 
@@ -90,14 +129,13 @@ export class RunsApi extends ApiTopic {
90
129
  **/
91
130
  computeFacets(query: ComputeRunFacetPayload): Promise<ComputeRunFacetsResponse> {
92
131
  return this.post("/facets", {
93
- payload: query
132
+ payload: query,
94
133
  });
95
134
  }
96
135
 
97
136
  search(payload: RunSearchPayload): Promise<ExecutionRunRef[]> {
98
137
  return this.post("/search", {
99
- payload
138
+ payload,
100
139
  });
101
140
  }
102
-
103
- }
141
+ }
@@ -0,0 +1,94 @@
1
+ import { describe, expect, test } from "vitest";
2
+ import { VertesiaClient } from "./client";
3
+
4
+ describe('Test Vertesia Client', () => {
5
+ test('Initialization with studio and zeno URLs', () => {
6
+ const client = new VertesiaClient({
7
+ serverUrl: 'https://api.vertesia.io',
8
+ storeUrl: 'https://api.vertesia.io',
9
+ apikey: '1234',
10
+ });
11
+ expect(client).toBeDefined();
12
+ });
13
+
14
+ test('Initialization with studio URL only', () => {
15
+ expect(() => {
16
+ new VertesiaClient({
17
+ serverUrl: 'https://api.vertesia.io',
18
+ storeUrl: '',
19
+ });
20
+ }).toThrowError("Parameter 'site' or 'storeUrl' is required for VertesiaClient");
21
+ });
22
+
23
+ test('Initialization with zeno URL only', () => {
24
+ expect(() => {
25
+ new VertesiaClient({
26
+ serverUrl: '',
27
+ storeUrl: 'https://api.vertesia.io',
28
+ });
29
+ }).toThrowError("Parameter 'site' or 'serverUrl' is required for VertesiaClient");
30
+ });
31
+
32
+ test('Initialization with same site', () => {
33
+ const client = new VertesiaClient({
34
+ serverUrl: 'https://api.vertesia.io',
35
+ storeUrl: 'https://api.vertesia.io',
36
+ site: 'api.vertesia.io',
37
+ });
38
+
39
+ expect(client).toBeDefined();
40
+ expect(client.baseUrl).toBe('https://api.vertesia.io');
41
+ expect(client.storeUrl).toBe('https://api.vertesia.io');
42
+ });
43
+
44
+ test('Initialization with default parameters', () => {
45
+ const client = new VertesiaClient();
46
+
47
+ expect(client).toBeDefined();
48
+ expect(client.baseUrl).toBe('https://api.vertesia.io');
49
+ expect(client.storeUrl).toBe('https://api.vertesia.io');
50
+ });
51
+
52
+ test('Initialization with site api-preview.vertesia.io', () => {
53
+ const client = new VertesiaClient({
54
+ site: 'api-preview.vertesia.io',
55
+ });
56
+
57
+ expect(client).toBeDefined();
58
+ expect(client.baseUrl).toBe('https://api-preview.vertesia.io');
59
+ expect(client.storeUrl).toBe('https://api-preview.vertesia.io');
60
+ });
61
+
62
+ test('Initialization with site api-staging.vertesia.io', () => {
63
+ const client = new VertesiaClient({
64
+ site: 'api-staging.vertesia.io',
65
+ });
66
+
67
+ expect(client).toBeDefined();
68
+ expect(client.baseUrl).toBe('https://api-staging.vertesia.io');
69
+ expect(client.storeUrl).toBe('https://api-staging.vertesia.io');
70
+ });
71
+
72
+ test('Initialization with site localhost', () => {
73
+ const client = new VertesiaClient({
74
+ serverUrl: 'http://localhost:8091',
75
+ storeUrl: 'http://localhost:8092',
76
+ });
77
+
78
+ expect(client).toBeDefined();
79
+ expect(client.baseUrl).toBe('http://localhost:8091');
80
+ expect(client.storeUrl).toBe('http://localhost:8092');
81
+ });
82
+
83
+ test('Initialization with overrides', () => {
84
+ const client = new VertesiaClient({
85
+ serverUrl: 'https://studio-server-production.api.becomposable.com',
86
+ storeUrl: 'https://zeno-server-production.api.becomposable.com',
87
+ site: 'api.vertesia.io',
88
+ });
89
+
90
+ expect(client).toBeDefined();
91
+ expect(client.baseUrl).toBe('https://studio-server-production.api.becomposable.com');
92
+ expect(client.storeUrl).toBe('https://zeno-server-production.api.becomposable.com');
93
+ });
94
+ });
package/src/client.ts CHANGED
@@ -21,9 +21,22 @@ import UsersApi from "./UsersApi.js";
21
21
  */
22
22
  const EXPIRATION_THRESHOLD = 60000;
23
23
 
24
- export interface VertesiaClientProps {
25
- serverUrl: string;
26
- storeUrl: string;
24
+ export type VertesiaClientProps = {
25
+ /**
26
+ * The site name of Vertesia.
27
+ *
28
+ * This is used to determine the API backend. It should not include the protocol. For more
29
+ * advanced configurations, use `serverUrl` and `storeUrl` instead.
30
+ *
31
+ * @example api.vertesia.io
32
+ * @example api-preview.vertesia.io
33
+ * @example api-staging.vertesia.io
34
+ * @default api.vertesia.io
35
+ * @since 0.52.0
36
+ */
37
+ site?: 'api.vertesia.io' | 'api-preview.vertesia.io' | 'api-staging.vertesia.io';
38
+ serverUrl?: string;
39
+ storeUrl?: string;
27
40
  apikey?: string;
28
41
  projectId?: string;
29
42
  sessionTags?: string | string[];
@@ -49,17 +62,33 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
49
62
  sessionTags?: string | string[];
50
63
 
51
64
  constructor(
52
- opts: VertesiaClientProps = {} as any
65
+ opts: VertesiaClientProps = {
66
+ site: 'api.vertesia.io',
67
+ }
53
68
  ) {
54
- super(opts.serverUrl);
55
- if (!opts.serverUrl) {
56
- throw new Error("storeUrl is required for VertesiaClient");
69
+ let studioServerUrl: string;
70
+ let zenoServerUrl: string;
71
+
72
+ if (opts.serverUrl) {
73
+ studioServerUrl = opts.serverUrl;
74
+ } else if (opts.site) {
75
+ studioServerUrl = `https://${opts.site}`;
76
+ } else {
77
+ throw new Error("Parameter 'site' or 'serverUrl' is required for VertesiaClient");
57
78
  }
58
- if (!opts.storeUrl) {
59
- throw new Error("storeUrl is required for VertesiaClient");
79
+
80
+ if (opts.storeUrl) {
81
+ zenoServerUrl = opts.storeUrl;
82
+ } else if (opts.site) {
83
+ zenoServerUrl = `https://${opts.site}`;
84
+ } else {
85
+ throw new Error("Parameter 'site' or 'storeUrl' is required for VertesiaClient");
60
86
  }
87
+
88
+ super(studioServerUrl);
89
+
61
90
  this.store = new ZenoClient({
62
- serverUrl: opts.storeUrl,
91
+ serverUrl: zenoServerUrl,
63
92
  apikey: opts.apikey,
64
93
  onRequest: opts.onRequest,
65
94
  onResponse: opts.onResponse
@@ -103,6 +132,21 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
103
132
  );
104
133
  }
105
134
 
135
+ async getRawJWT() {
136
+ if (!this._jwt && this._auth) {
137
+ const auth = await this._auth();
138
+ if (!this._jwt) { // the _jwt may be set by the auth callback
139
+ this._jwt = auth.trim().split(' ')[1]; // remove Bearer prefix
140
+ }
141
+ }
142
+ return this._jwt || null;
143
+ }
144
+
145
+ async getDecodedJWT() {
146
+ const jwt = await this.getRawJWT();
147
+ return jwt ? decodeJWT(jwt) : null;
148
+ }
149
+
106
150
  /**
107
151
  * Alias for store.workflows
108
152
  */
@@ -128,6 +172,9 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
128
172
  return this.store.types;
129
173
  }
130
174
 
175
+ get storeUrl() {
176
+ return this.store.baseUrl;
177
+ }
131
178
 
132
179
  set project(projectId: string | null) {
133
180
  if (projectId) {
@@ -182,10 +229,34 @@ function isTokenExpired(token: string | null) {
182
229
  return true;
183
230
  }
184
231
 
185
- const payloadBase64 = token.split('.')[1];
186
- const decodedJson = Buffer.from(payloadBase64, 'base64').toString();
187
- const decoded = JSON.parse(decodedJson)
232
+ const decoded = decodeJWT(token);
188
233
  const exp = decoded.exp;
189
234
  const currentTime = Date.now();
190
235
  return (currentTime <= exp * 1000 - EXPIRATION_THRESHOLD);
191
236
  }
237
+
238
+ function decodeJWT(jwt: string) {
239
+ const payloadBase64 = jwt.split('.')[1];
240
+ const decodedJson = base64UrlDecode(payloadBase64);
241
+ return JSON.parse(decodedJson)
242
+ }
243
+
244
+ function base64UrlDecode(input: string): string {
245
+ // Convert base64url to base64
246
+ const base64 = input.replace(/-/g, '+').replace(/_/g, '/')
247
+ // Pad with '=' to make length a multiple of 4
248
+ .padEnd(Math.ceil(input.length / 4) * 4, '=');
249
+
250
+ if (typeof Buffer !== 'undefined') {
251
+ // Node.js
252
+ return Buffer.from(base64, 'base64').toString('utf-8');
253
+ } else if (typeof atob !== 'undefined' && typeof TextDecoder !== 'undefined') {
254
+ // Browser
255
+ const binary = atob(base64);
256
+ const bytes = Uint8Array.from(binary, c => c.charCodeAt(0));
257
+ // decode to utf8
258
+ return new TextDecoder().decode(bytes);
259
+ } else {
260
+ throw new Error('No base64 decoder available');
261
+ }
262
+ }
package/src/execute.ts CHANGED
@@ -1,4 +1,4 @@
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
4
  export function EventSourceProvider(): Promise<typeof EventSource> {
@@ -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
@@ -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";