@vertesia/client 1.0.0-dev.20260305.083323Z → 1.0.0-dev.20260331.091034Z

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 (113) hide show
  1. package/lib/cjs/InteractionBase.js +3 -3
  2. package/lib/cjs/InteractionBase.js.map +1 -1
  3. package/lib/cjs/InteractionsApi.js.map +1 -1
  4. package/lib/cjs/MCPOAuthApi.js +14 -7
  5. package/lib/cjs/MCPOAuthApi.js.map +1 -1
  6. package/lib/cjs/OAuthAppsApi.js +72 -0
  7. package/lib/cjs/OAuthAppsApi.js.map +1 -0
  8. package/lib/cjs/PromptsApi.js +2 -0
  9. package/lib/cjs/PromptsApi.js.map +1 -1
  10. package/lib/cjs/RunsApi.js +7 -0
  11. package/lib/cjs/RunsApi.js.map +1 -1
  12. package/lib/cjs/client.js +29 -35
  13. package/lib/cjs/client.js.map +1 -1
  14. package/lib/cjs/execute.js +38 -36
  15. package/lib/cjs/execute.js.map +1 -1
  16. package/lib/cjs/store/AgentsApi.js +639 -0
  17. package/lib/cjs/store/AgentsApi.js.map +1 -0
  18. package/lib/cjs/store/FilesApi.js +49 -2
  19. package/lib/cjs/store/FilesApi.js.map +1 -1
  20. package/lib/cjs/store/IndexingApi.js +47 -10
  21. package/lib/cjs/store/IndexingApi.js.map +1 -1
  22. package/lib/cjs/store/ObjectsApi.js +28 -5
  23. package/lib/cjs/store/ObjectsApi.js.map +1 -1
  24. package/lib/cjs/store/WorkflowsApi.js +234 -263
  25. package/lib/cjs/store/WorkflowsApi.js.map +1 -1
  26. package/lib/cjs/store/client.js +2 -0
  27. package/lib/cjs/store/client.js.map +1 -1
  28. package/lib/cjs/store/index.js +1 -0
  29. package/lib/cjs/store/index.js.map +1 -1
  30. package/lib/cjs/store/version.js +1 -1
  31. package/lib/esm/InteractionBase.js +3 -3
  32. package/lib/esm/InteractionBase.js.map +1 -1
  33. package/lib/esm/InteractionsApi.js.map +1 -1
  34. package/lib/esm/MCPOAuthApi.js +14 -7
  35. package/lib/esm/MCPOAuthApi.js.map +1 -1
  36. package/lib/esm/OAuthAppsApi.js +69 -0
  37. package/lib/esm/OAuthAppsApi.js.map +1 -0
  38. package/lib/esm/PromptsApi.js +2 -0
  39. package/lib/esm/PromptsApi.js.map +1 -1
  40. package/lib/esm/RunsApi.js +7 -0
  41. package/lib/esm/RunsApi.js.map +1 -1
  42. package/lib/esm/client.js +29 -35
  43. package/lib/esm/client.js.map +1 -1
  44. package/lib/esm/execute.js +38 -36
  45. package/lib/esm/execute.js.map +1 -1
  46. package/lib/esm/store/AgentsApi.js +635 -0
  47. package/lib/esm/store/AgentsApi.js.map +1 -0
  48. package/lib/esm/store/FilesApi.js +49 -2
  49. package/lib/esm/store/FilesApi.js.map +1 -1
  50. package/lib/esm/store/IndexingApi.js +47 -10
  51. package/lib/esm/store/IndexingApi.js.map +1 -1
  52. package/lib/esm/store/ObjectsApi.js +28 -5
  53. package/lib/esm/store/ObjectsApi.js.map +1 -1
  54. package/lib/esm/store/WorkflowsApi.js +234 -263
  55. package/lib/esm/store/WorkflowsApi.js.map +1 -1
  56. package/lib/esm/store/client.js +2 -0
  57. package/lib/esm/store/client.js.map +1 -1
  58. package/lib/esm/store/index.js +1 -0
  59. package/lib/esm/store/index.js.map +1 -1
  60. package/lib/esm/store/version.js +1 -1
  61. package/lib/tsconfig.tsbuildinfo +1 -1
  62. package/lib/types/InteractionBase.d.ts +1 -1
  63. package/lib/types/InteractionBase.d.ts.map +1 -1
  64. package/lib/types/InteractionsApi.d.ts +1 -0
  65. package/lib/types/InteractionsApi.d.ts.map +1 -1
  66. package/lib/types/MCPOAuthApi.d.ts +10 -5
  67. package/lib/types/MCPOAuthApi.d.ts.map +1 -1
  68. package/lib/types/OAuthAppsApi.d.ts +51 -0
  69. package/lib/types/OAuthAppsApi.d.ts.map +1 -0
  70. package/lib/types/PromptsApi.d.ts +1 -1
  71. package/lib/types/PromptsApi.d.ts.map +1 -1
  72. package/lib/types/RunsApi.d.ts +6 -1
  73. package/lib/types/RunsApi.d.ts.map +1 -1
  74. package/lib/types/client.d.ts +9 -3
  75. package/lib/types/client.d.ts.map +1 -1
  76. package/lib/types/execute.d.ts +2 -4
  77. package/lib/types/execute.d.ts.map +1 -1
  78. package/lib/types/store/AgentsApi.d.ts +231 -0
  79. package/lib/types/store/AgentsApi.d.ts.map +1 -0
  80. package/lib/types/store/FilesApi.d.ts +20 -1
  81. package/lib/types/store/FilesApi.d.ts.map +1 -1
  82. package/lib/types/store/IndexingApi.d.ts +25 -4
  83. package/lib/types/store/IndexingApi.d.ts.map +1 -1
  84. package/lib/types/store/ObjectsApi.d.ts +14 -4
  85. package/lib/types/store/ObjectsApi.d.ts.map +1 -1
  86. package/lib/types/store/WorkflowsApi.d.ts +34 -84
  87. package/lib/types/store/WorkflowsApi.d.ts.map +1 -1
  88. package/lib/types/store/client.d.ts +2 -0
  89. package/lib/types/store/client.d.ts.map +1 -1
  90. package/lib/types/store/index.d.ts +1 -0
  91. package/lib/types/store/index.d.ts.map +1 -1
  92. package/lib/types/store/version.d.ts +1 -1
  93. package/lib/vertesia-client.js +1 -1
  94. package/lib/vertesia-client.js.map +1 -1
  95. package/package.json +8 -5
  96. package/src/InteractionBase.ts +3 -3
  97. package/src/InteractionsApi.ts +3 -1
  98. package/src/MCPOAuthApi.ts +14 -7
  99. package/src/OAuthAppsApi.ts +87 -0
  100. package/src/PromptsApi.ts +3 -1
  101. package/src/RunsApi.ts +10 -0
  102. package/src/client.test.ts +41 -5
  103. package/src/client.ts +39 -32
  104. package/src/execute.ts +37 -34
  105. package/src/store/AgentsApi.ts +765 -0
  106. package/src/store/FilesApi.ts +62 -2
  107. package/src/store/IndexingApi.ts +56 -12
  108. package/src/store/ObjectsApi.ts +45 -8
  109. package/src/store/WorkflowsApi.ts +250 -334
  110. package/src/store/client.ts +2 -0
  111. package/src/store/index.ts +1 -0
  112. package/src/store/version.ts +1 -1
  113. package/tsconfig.dist.json +1 -1
@@ -47,21 +47,28 @@ export default class MCPOAuthApi extends ApiTopic {
47
47
  }
48
48
 
49
49
  /**
50
- * Disconnect OAuth authentication for an MCP server
51
- * @param mcpServerUrl - The MCP server URL
50
+ * Disconnect OAuth authentication for a specific collection
51
+ * @param appInstallId - The app installation ID
52
+ * @param collectionName - The collection name
52
53
  */
53
- disconnect(mcpServerUrl: string): Promise<void> {
54
- return this.del(`/disconnect/${encodeURIComponent(mcpServerUrl)}`);
54
+ disconnect(appInstallId: string, collectionName: string): Promise<void> {
55
+ return this.del(`/disconnect/${appInstallId}/${collectionName}`);
55
56
  }
56
57
 
57
58
  /**
58
- * Get or refresh OAuth token for an MCP server (internal use by workflows)
59
+ * Get or refresh OAuth token (internal use by workflows).
60
+ * When oauthAppName is provided, uses the generic OAuth Application flow
61
+ * (resolves by name in the caller's project).
62
+ * Otherwise falls back to legacy MCP server URL-based token retrieval.
59
63
  * @param mcpServerUrl - The MCP server URL
64
+ * @param oauthAppName - Optional OAuth Application name (from collection's oauth_app field)
60
65
  * @returns Access token
61
66
  */
62
- getToken(mcpServerUrl: string): Promise<{ access_token: string }> {
67
+ getToken(mcpServerUrl: string, oauthAppName?: string): Promise<{ access_token: string }> {
63
68
  return this.post('/token', {
64
- payload: { mcp_server_url: mcpServerUrl }
69
+ payload: oauthAppName
70
+ ? { oauth_app_name: oauthAppName }
71
+ : { mcp_server_url: mcpServerUrl }
65
72
  });
66
73
  }
67
74
  }
@@ -0,0 +1,87 @@
1
+ import { ApiTopic, ClientBase } from '@vertesia/api-fetch-client';
2
+ import type {
3
+ CreateOAuthApplicationPayload,
4
+ OAuthAppAuthStatus,
5
+ OAuthAppAuthorizeResponse,
6
+ OAuthApplication,
7
+ UpdateOAuthApplicationPayload,
8
+ } from '@vertesia/common';
9
+
10
+ export default class OAuthAppsApi extends ApiTopic {
11
+
12
+ constructor(parent: ClientBase) {
13
+ super(parent, '/api/v1/oauth-apps');
14
+ }
15
+
16
+ /**
17
+ * List all OAuth applications in the current project.
18
+ */
19
+ list(): Promise<OAuthApplication[]> {
20
+ return this.get('/');
21
+ }
22
+
23
+ /**
24
+ * Get a single OAuth application by ID (secret redacted).
25
+ */
26
+ retrieve(id: string): Promise<OAuthApplication> {
27
+ return this.get(`/${id}`);
28
+ }
29
+
30
+ /**
31
+ * Create a new OAuth application.
32
+ */
33
+ create(payload: CreateOAuthApplicationPayload): Promise<OAuthApplication> {
34
+ return this.post('/', { payload });
35
+ }
36
+
37
+ /**
38
+ * Update an OAuth application.
39
+ */
40
+ update(id: string, payload: UpdateOAuthApplicationPayload): Promise<OAuthApplication> {
41
+ return this.put(`/${id}`, { payload });
42
+ }
43
+
44
+ /**
45
+ * Delete an OAuth application.
46
+ */
47
+ remove(id: string): Promise<void> {
48
+ return this.del(`/${id}`);
49
+ }
50
+
51
+ /**
52
+ * Initiate OAuth 2.0 authorization flow for the current user.
53
+ * Returns an authorization URL to open in a popup/browser.
54
+ */
55
+ authorize(id: string): Promise<OAuthAppAuthorizeResponse> {
56
+ return this.get(`/${id}/authorize`);
57
+ }
58
+
59
+ /**
60
+ * Exchange an authorization code for tokens (called by UI callback).
61
+ */
62
+ exchange(code: string, state: string): Promise<{ success: boolean }> {
63
+ return this.post('/exchange', { payload: { code, state } });
64
+ }
65
+
66
+ /**
67
+ * Check the current user's authentication status for an OAuth application.
68
+ */
69
+ getStatus(id: string): Promise<OAuthAppAuthStatus> {
70
+ return this.get(`/${id}/status`);
71
+ }
72
+
73
+ /**
74
+ * Get a valid access token for an OAuth application (auto-refreshes).
75
+ * Primarily used by workflows/activities.
76
+ */
77
+ getToken(id: string): Promise<{ access_token: string }> {
78
+ return this.post(`/${id}/token`, { payload: {} });
79
+ }
80
+
81
+ /**
82
+ * Delete the current user's tokens for an OAuth application.
83
+ */
84
+ disconnect(id: string): Promise<void> {
85
+ return this.del(`/${id}/disconnect`);
86
+ }
87
+ }
package/src/PromptsApi.ts CHANGED
@@ -97,6 +97,7 @@ export default class PromptsApi extends ApiTopic {
97
97
  });
98
98
  }
99
99
 
100
+ //TODO - Does this exist?
100
101
  /**
101
102
  * Render a prompt template
102
103
  * @param id of the prompt template to render
@@ -107,12 +108,13 @@ export default class PromptsApi extends ApiTopic {
107
108
  * @throws 400 if payload is invalid
108
109
  * @throws 500 if render fails
109
110
  **/
110
- render(id: string, payload: {}): Promise<PromptTemplate> {
111
+ render(id: string, payload: object): Promise<PromptTemplate> {
111
112
  return this.post(`/${id}/render`, {
112
113
  payload
113
114
  });
114
115
  }
115
116
 
117
+ //TODO - Does this exist?
116
118
  /**
117
119
  * Get options for a field
118
120
  * @param field name to get options for
package/src/RunsApi.ts CHANGED
@@ -7,6 +7,8 @@ import {
7
7
  FindPayload,
8
8
  PopulatedExecutionRun,
9
9
  RunCreatePayload,
10
+ ExecutionRunDocRef,
11
+ RunClonePayload,
10
12
  RunListingFilters,
11
13
  RunListingQueryOptions,
12
14
  RunSearchPayload,
@@ -141,4 +143,12 @@ export class RunsApi extends ApiTopic {
141
143
  payload,
142
144
  });
143
145
  }
146
+
147
+ /**
148
+ * Clone an existing ExecutionRun for fork workflows.
149
+ * Creates a new run with the same interaction/config but fresh status.
150
+ */
151
+ clone(payload: RunClonePayload): Promise<ExecutionRunDocRef> {
152
+ return this.post('/clone', { payload });
153
+ }
144
154
  }
@@ -62,15 +62,51 @@ describe('Test Vertesia Client', () => {
62
62
  expect(client.tokenServerUrl).toBe('https://sts.vertesia.io');
63
63
  });
64
64
 
65
- test('Initialization with site api-staging.vertesia.io', () => {
65
+ test('Initialization with site api.dev1.vertesia.io', () => {
66
66
  const client = new VertesiaClient({
67
- site: 'api-staging.vertesia.io',
67
+ site: 'api.dev1.vertesia.io',
68
68
  });
69
69
 
70
70
  expect(client).toBeDefined();
71
- expect(client.baseUrl).toBe('https://api-staging.vertesia.io');
72
- expect(client.storeUrl).toBe('https://api-staging.vertesia.io');
73
- expect(client.tokenServerUrl).toBe('https://sts-staging.vertesia.io');
71
+ expect(client.baseUrl).toBe('https://api.dev1.vertesia.io');
72
+ expect(client.storeUrl).toBe('https://api.dev1.vertesia.io');
73
+ expect(client.tokenServerUrl).toBe('https://sts.dev1.vertesia.io');
74
+ });
75
+
76
+ test('Initialization with regional serverUrl (api.us1)', () => {
77
+ const client = new VertesiaClient({
78
+ serverUrl: 'https://api.us1.vertesia.io',
79
+ storeUrl: 'https://api.us1.vertesia.io',
80
+ });
81
+
82
+ expect(client).toBeDefined();
83
+ expect(client.baseUrl).toBe('https://api.us1.vertesia.io');
84
+ expect(client.storeUrl).toBe('https://api.us1.vertesia.io');
85
+ expect(client.tokenServerUrl).toBe('https://sts.us1.vertesia.io');
86
+ });
87
+
88
+ test('Initialization with regional serverUrl (api.eu1)', () => {
89
+ const client = new VertesiaClient({
90
+ serverUrl: 'https://api.eu1.vertesia.io',
91
+ storeUrl: 'https://api.eu1.vertesia.io',
92
+ });
93
+
94
+ expect(client).toBeDefined();
95
+ expect(client.baseUrl).toBe('https://api.eu1.vertesia.io');
96
+ expect(client.storeUrl).toBe('https://api.eu1.vertesia.io');
97
+ expect(client.tokenServerUrl).toBe('https://sts.eu1.vertesia.io');
98
+ });
99
+
100
+ test('Initialization with regional preview serverUrl (api-preview.us1)', () => {
101
+ const client = new VertesiaClient({
102
+ serverUrl: 'https://api-preview.us1.vertesia.io',
103
+ storeUrl: 'https://api-preview.us1.vertesia.io',
104
+ });
105
+
106
+ expect(client).toBeDefined();
107
+ expect(client.baseUrl).toBe('https://api-preview.us1.vertesia.io');
108
+ // preview strips -preview., then api → sts: sts.us1.vertesia.io
109
+ expect(client.tokenServerUrl).toBe('https://sts.us1.vertesia.io');
74
110
  });
75
111
 
76
112
  test('Initialization with site localhost', () => {
package/src/client.ts CHANGED
@@ -11,6 +11,7 @@ import EnvironmentsApi from "./EnvironmentsApi.js";
11
11
  import { IamApi } from "./IamApi.js";
12
12
  import InteractionsApi from "./InteractionsApi.js";
13
13
  import MCPOAuthApi from "./MCPOAuthApi.js";
14
+ import OAuthAppsApi from "./OAuthAppsApi.js";
14
15
  import ProjectsApi from "./ProjectsApi.js";
15
16
  import SkillsApi from "./SkillsApi.js";
16
17
  import PromptsApi from "./PromptsApi.js";
@@ -35,15 +36,21 @@ export type VertesiaClientProps = {
35
36
  * advanced configurations, use `serverUrl` and `storeUrl` instead.
36
37
  *
37
38
  * @example api.vertesia.io
38
- * @example api-preview.vertesia.io
39
- * @example api-staging.vertesia.io
39
+ * @example api.us1.vertesia.io
40
+ * @example api-preview.eu1.vertesia.io
40
41
  * @default api.vertesia.io
41
42
  * @since 0.52.0
42
43
  */
43
44
  site?:
44
45
  | "api.vertesia.io"
45
46
  | "api-preview.vertesia.io"
46
- | "api-staging.vertesia.io";
47
+ | "api.us1.vertesia.io"
48
+ | "api-preview.us1.vertesia.io"
49
+ | "api.eu1.vertesia.io"
50
+ | "api-preview.eu1.vertesia.io"
51
+ | "api.jp1.vertesia.io"
52
+ | "api-preview.jp1.vertesia.io"
53
+ | "api.dev1.vertesia.io";
47
54
  serverUrl?: string;
48
55
  storeUrl?: string;
49
56
  tokenServerUrl?: string;
@@ -135,45 +142,35 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
135
142
  if (opts.tokenServerUrl) {
136
143
  this.tokenServerUrl = opts.tokenServerUrl;
137
144
  } else if (opts.site) {
138
- // Preview uses production STS, staging uses its own STS
139
- if (opts.site === "api-preview.vertesia.io" || opts.site === "api.vertesia.io") {
140
- this.tokenServerUrl = "https://sts.vertesia.io";
141
- } else {
142
- this.tokenServerUrl = `https://${opts.site.replace(/^api/, "sts")}`;
143
- }
145
+ // Strip -preview (preview uses the same STS as production for the same region),
146
+ // then replace api prefix with sts.
147
+ // Examples:
148
+ // api.vertesia.io -> sts.vertesia.io
149
+ // api-preview.vertesia.io -> sts.vertesia.io
150
+ // api.us1.vertesia.io -> sts.us1.vertesia.io
151
+ // api-preview.eu1.vertesia.io -> sts.eu1.vertesia.io
152
+ const stsHost = opts.site.replace('api-preview.', 'api.').replace(/^api/, 'sts');
153
+ this.tokenServerUrl = `https://${stsHost}`;
144
154
  } else if (opts.serverUrl || opts.storeUrl) {
145
155
  // Determine STS URL based on environment in serverUrl or storeUrl
146
156
  const urlToCheck = opts.serverUrl || opts.storeUrl || "";
147
157
  try {
148
158
  const url = new URL(urlToCheck);
149
- // Check for environment patterns
150
- if (url.hostname.includes("-production.")) {
151
- // zeno-server-production.api.vertesia.io -> sts.vertesia.io
152
- this.tokenServerUrl = "https://sts.vertesia.io";
153
- } else if (url.hostname.includes("-preview.")) {
154
- // zeno-server-preview.api.vertesia.io -> sts.vertesia.io
155
- this.tokenServerUrl = "https://sts.vertesia.io";
156
- } else if (url.hostname === "api.vertesia.io") {
157
- this.tokenServerUrl = "https://sts.vertesia.io";
158
- } else if (url.hostname === "api-preview.vertesia.io") {
159
- this.tokenServerUrl = "https://sts.vertesia.io";
160
- } else if (url.hostname === "api-staging.vertesia.io") {
161
- this.tokenServerUrl = "https://sts-staging.vertesia.io";
162
- } else if (url.hostname.startsWith("api")) {
163
- // Generic api.* pattern replacement
164
- url.hostname = url.hostname.replace(/^api/, "sts");
165
- this.tokenServerUrl = url.toString();
159
+ if (url.hostname.startsWith("api")) {
160
+ // Strip -preview and replace api with sts.
161
+ // api.us1.vertesia.io -> sts.us1.vertesia.io
162
+ // api-preview.us1.vertesia.io -> sts.us1.vertesia.io
163
+ // api.vertesia.io -> sts.vertesia.io
164
+ const stsHost = url.hostname.replace('api-preview.', 'api.').replace(/^api/, 'sts');
165
+ this.tokenServerUrl = `https://${stsHost}`;
166
166
  } else {
167
- // Default to staging for everything else
168
- this.tokenServerUrl = "https://sts-staging.vertesia.io";
167
+ this.tokenServerUrl = "https://sts.dev1.vertesia.io";
169
168
  }
170
169
  } catch (e) {
171
- // Default to staging if URL parsing fails
172
- this.tokenServerUrl = "https://sts-staging.vertesia.io";
170
+ this.tokenServerUrl = "https://sts.dev1.vertesia.io";
173
171
  }
174
172
  } else {
175
- // Default to staging if no URL provided
176
- this.tokenServerUrl = "https://sts-staging.vertesia.io";
173
+ this.tokenServerUrl = "https://sts.dev1.vertesia.io";
177
174
  }
178
175
 
179
176
  this.store = new ZenoClient({
@@ -256,6 +253,13 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
256
253
  return jwt?.account || null;
257
254
  }
258
255
 
256
+ /**
257
+ * Alias for store.agents
258
+ */
259
+ get agents() {
260
+ return this.store.agents;
261
+ }
262
+
259
263
  /**
260
264
  * Alias for store.workflows
261
265
  */
@@ -342,6 +346,7 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
342
346
  commands = new CommandsApi(this);
343
347
  apps = new AppsApi(this);
344
348
  mcpOAuth = new MCPOAuthApi(this);
349
+ oauthApps = new OAuthAppsApi(this);
345
350
  }
346
351
 
347
352
  function isApiKey(apiKey: string) {
@@ -412,6 +417,8 @@ function getEndpointsFromDomain(domain: string) {
412
417
  };
413
418
  } else {
414
419
  const url = `https://${domain}`;
420
+ // Supports both dot-separated (api.us1.vertesia.io → sts.us1.vertesia.io)
421
+ // and legacy (api.vertesia.io → sts.vertesia.io)
415
422
  return {
416
423
  studio: url,
417
424
  store: url,
package/src/execute.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import { AsyncExecutionPayload, ExecutionRunStatus, InteractionExecutionPayload, InteractionExecutionResult, NamedInteractionExecutionPayload, RateLimitRequestPayload, RateLimitRequestResponse } from '@vertesia/common';
2
2
  import { VertesiaClient } from './client.js';
3
+ import type { AsyncExecutionResult } from './InteractionsApi.js';
3
4
 
4
5
  export async function EventSourceProvider(): Promise<typeof EventSource> {
5
6
  if (typeof globalThis.EventSource === 'function') {
@@ -74,46 +75,48 @@ export async function executeInteractionByName<P = any>(client: VertesiaClient,
74
75
  }
75
76
 
76
77
  function handleStreaming(client: VertesiaClient, runId: string, onChunk: (chunk: string) => void) {
77
- return new Promise(async (resolve, reject) => {
78
- try {
79
- const EventSourceImpl = await EventSourceProvider();
80
- const streamUrl = new URL(client.runs.baseUrl + '/' + runId + '/stream');
81
- const bearerToken = client._auth ? await client._auth() : undefined;
78
+ return new Promise((resolve, reject) => {
79
+ (async () => {
80
+ try {
81
+ const EventSourceImpl = await EventSourceProvider();
82
+ const streamUrl = new URL(client.runs.baseUrl + '/' + runId + '/stream');
83
+ const bearerToken = client._auth ? await client._auth() : undefined;
82
84
 
83
- if (bearerToken) {
84
- const token = bearerToken.split(' ')[1];
85
- streamUrl.searchParams.set('access_token', token);
86
- } else {
87
- throw new Error('No auth token available');
88
- }
85
+ if (bearerToken) {
86
+ const token = bearerToken.split(' ')[1];
87
+ streamUrl.searchParams.set('access_token', token);
88
+ } else {
89
+ throw new Error('No auth token available');
90
+ }
89
91
 
90
- const sse = new EventSourceImpl(streamUrl.href);
91
- sse.addEventListener("message", ev => {
92
- try {
93
- const data = JSON.parse(ev.data);
94
- if (data) {
95
- onChunk && onChunk(data);
92
+ const sse = new EventSourceImpl(streamUrl.href);
93
+ sse.addEventListener("message", ev => {
94
+ try {
95
+ const data = JSON.parse(ev.data);
96
+ if (data) {
97
+ onChunk && onChunk(data);
98
+ }
99
+ } catch (err) {
100
+ reject(err);
96
101
  }
97
- } catch (err) {
98
- reject(err);
99
- }
100
- });
101
- sse.addEventListener("close", (ev) => {
102
- try {
103
- sse.close();
104
- const msg = JSON.parse(ev.data)
105
- resolve(msg);
106
- } catch (err) {
107
- reject(err);
108
- }
109
- });
110
- } catch (err) {
111
- reject(err);
112
- }
102
+ });
103
+ sse.addEventListener("close", (ev) => {
104
+ try {
105
+ sse.close();
106
+ const msg = JSON.parse(ev.data)
107
+ resolve(msg);
108
+ } catch (err) {
109
+ reject(err);
110
+ }
111
+ });
112
+ } catch (err) {
113
+ reject(err);
114
+ }
115
+ })();
113
116
  });
114
117
  }
115
118
 
116
- export async function executeInteractionAsync(client: VertesiaClient, payload: AsyncExecutionPayload): Promise<{ runId: string, workflowId: string }> {
119
+ export async function executeInteractionAsync(client: VertesiaClient, payload: AsyncExecutionPayload): Promise<AsyncExecutionResult> {
117
120
  return await client.post('/api/v1/execute/async', {
118
121
  payload,
119
122
  });