@vertesia/client 1.1.0-dev.20260327.125707Z → 1.1.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 (152) hide show
  1. package/lib/cjs/AnalyticsApi.js +3 -1
  2. package/lib/cjs/AnalyticsApi.js.map +1 -1
  3. package/lib/cjs/AppsApi.js +18 -2
  4. package/lib/cjs/AppsApi.js.map +1 -1
  5. package/lib/cjs/AuditTrailApi.js +6 -2
  6. package/lib/cjs/AuditTrailApi.js.map +1 -1
  7. package/lib/cjs/GroupsApi.js +8 -0
  8. package/lib/cjs/GroupsApi.js.map +1 -1
  9. package/lib/cjs/InteractionsApi.js.map +1 -1
  10. package/lib/cjs/OAuthClientsApi.js +25 -0
  11. package/lib/cjs/OAuthClientsApi.js.map +1 -0
  12. package/lib/cjs/OAuthGrantsApi.js +30 -0
  13. package/lib/cjs/OAuthGrantsApi.js.map +1 -0
  14. package/lib/cjs/OAuthProvidersApi.js +43 -0
  15. package/lib/cjs/OAuthProvidersApi.js.map +1 -0
  16. package/lib/cjs/OAuthServerApi.js +22 -0
  17. package/lib/cjs/OAuthServerApi.js.map +1 -0
  18. package/lib/cjs/RemoteMcpConnectionsApi.js +38 -0
  19. package/lib/cjs/RemoteMcpConnectionsApi.js.map +1 -0
  20. package/lib/cjs/RunsApi.js +4 -12
  21. package/lib/cjs/RunsApi.js.map +1 -1
  22. package/lib/cjs/client.js +48 -45
  23. package/lib/cjs/client.js.map +1 -1
  24. package/lib/cjs/index.js +14 -0
  25. package/lib/cjs/index.js.map +1 -1
  26. package/lib/cjs/store/AgentsApi.js +30 -6
  27. package/lib/cjs/store/AgentsApi.js.map +1 -1
  28. package/lib/cjs/store/CostApi.js +56 -0
  29. package/lib/cjs/store/CostApi.js.map +1 -0
  30. package/lib/cjs/store/IndexingApi.js +94 -30
  31. package/lib/cjs/store/IndexingApi.js.map +1 -1
  32. package/lib/cjs/store/ObjectsApi.js +3 -2
  33. package/lib/cjs/store/ObjectsApi.js.map +1 -1
  34. package/lib/cjs/store/WorkflowsApi.js +258 -236
  35. package/lib/cjs/store/WorkflowsApi.js.map +1 -1
  36. package/lib/cjs/store/client.js +2 -0
  37. package/lib/cjs/store/client.js.map +1 -1
  38. package/lib/esm/AnalyticsApi.js +3 -1
  39. package/lib/esm/AnalyticsApi.js.map +1 -1
  40. package/lib/esm/AppsApi.js +18 -2
  41. package/lib/esm/AppsApi.js.map +1 -1
  42. package/lib/esm/AuditTrailApi.js +6 -2
  43. package/lib/esm/AuditTrailApi.js.map +1 -1
  44. package/lib/esm/GroupsApi.js +8 -0
  45. package/lib/esm/GroupsApi.js.map +1 -1
  46. package/lib/esm/InteractionsApi.js.map +1 -1
  47. package/lib/esm/OAuthClientsApi.js +22 -0
  48. package/lib/esm/OAuthClientsApi.js.map +1 -0
  49. package/lib/esm/OAuthGrantsApi.js +27 -0
  50. package/lib/esm/OAuthGrantsApi.js.map +1 -0
  51. package/lib/esm/OAuthProvidersApi.js +40 -0
  52. package/lib/esm/OAuthProvidersApi.js.map +1 -0
  53. package/lib/esm/OAuthServerApi.js +19 -0
  54. package/lib/esm/OAuthServerApi.js.map +1 -0
  55. package/lib/esm/RemoteMcpConnectionsApi.js +35 -0
  56. package/lib/esm/RemoteMcpConnectionsApi.js.map +1 -0
  57. package/lib/esm/RunsApi.js +4 -12
  58. package/lib/esm/RunsApi.js.map +1 -1
  59. package/lib/esm/client.js +48 -45
  60. package/lib/esm/client.js.map +1 -1
  61. package/lib/esm/index.js +5 -0
  62. package/lib/esm/index.js.map +1 -1
  63. package/lib/esm/store/AgentsApi.js +30 -6
  64. package/lib/esm/store/AgentsApi.js.map +1 -1
  65. package/lib/esm/store/CostApi.js +52 -0
  66. package/lib/esm/store/CostApi.js.map +1 -0
  67. package/lib/esm/store/IndexingApi.js +94 -30
  68. package/lib/esm/store/IndexingApi.js.map +1 -1
  69. package/lib/esm/store/ObjectsApi.js +3 -2
  70. package/lib/esm/store/ObjectsApi.js.map +1 -1
  71. package/lib/esm/store/WorkflowsApi.js +258 -236
  72. package/lib/esm/store/WorkflowsApi.js.map +1 -1
  73. package/lib/esm/store/client.js +2 -0
  74. package/lib/esm/store/client.js.map +1 -1
  75. package/lib/tsconfig.tsbuildinfo +1 -1
  76. package/lib/types/AnalyticsApi.d.ts +1 -1
  77. package/lib/types/AnalyticsApi.d.ts.map +1 -1
  78. package/lib/types/AppsApi.d.ts +20 -2
  79. package/lib/types/AppsApi.d.ts.map +1 -1
  80. package/lib/types/AuditTrailApi.d.ts.map +1 -1
  81. package/lib/types/GroupsApi.d.ts +6 -0
  82. package/lib/types/GroupsApi.d.ts.map +1 -1
  83. package/lib/types/InteractionsApi.d.ts +2 -0
  84. package/lib/types/InteractionsApi.d.ts.map +1 -1
  85. package/lib/types/OAuthClientsApi.d.ts +12 -0
  86. package/lib/types/OAuthClientsApi.d.ts.map +1 -0
  87. package/lib/types/OAuthGrantsApi.d.ts +11 -0
  88. package/lib/types/OAuthGrantsApi.d.ts.map +1 -0
  89. package/lib/types/OAuthProvidersApi.d.ts +22 -0
  90. package/lib/types/OAuthProvidersApi.d.ts.map +1 -0
  91. package/lib/types/OAuthServerApi.d.ts +10 -0
  92. package/lib/types/OAuthServerApi.d.ts.map +1 -0
  93. package/lib/types/ProjectsApi.d.ts +2 -2
  94. package/lib/types/ProjectsApi.d.ts.map +1 -1
  95. package/lib/types/RemoteMcpConnectionsApi.d.ts +13 -0
  96. package/lib/types/RemoteMcpConnectionsApi.d.ts.map +1 -0
  97. package/lib/types/RunsApi.d.ts +4 -16
  98. package/lib/types/RunsApi.d.ts.map +1 -1
  99. package/lib/types/client.d.ts +15 -9
  100. package/lib/types/client.d.ts.map +1 -1
  101. package/lib/types/index.d.ts +5 -0
  102. package/lib/types/index.d.ts.map +1 -1
  103. package/lib/types/store/AgentsApi.d.ts +27 -47
  104. package/lib/types/store/AgentsApi.d.ts.map +1 -1
  105. package/lib/types/store/CostApi.d.ts +35 -0
  106. package/lib/types/store/CostApi.d.ts.map +1 -0
  107. package/lib/types/store/IndexingApi.d.ts +48 -23
  108. package/lib/types/store/IndexingApi.d.ts.map +1 -1
  109. package/lib/types/store/ObjectsApi.d.ts +7 -2
  110. package/lib/types/store/ObjectsApi.d.ts.map +1 -1
  111. package/lib/types/store/WorkflowsApi.d.ts +84 -34
  112. package/lib/types/store/WorkflowsApi.d.ts.map +1 -1
  113. package/lib/types/store/client.d.ts +2 -0
  114. package/lib/types/store/client.d.ts.map +1 -1
  115. package/lib/vertesia-client.js +1 -1
  116. package/lib/vertesia-client.js.map +1 -1
  117. package/package.json +8 -8
  118. package/src/AnalyticsApi.ts +2 -1
  119. package/src/AppsApi.ts +26 -3
  120. package/src/AuditTrailApi.ts +3 -1
  121. package/src/GroupsApi.ts +9 -0
  122. package/src/InteractionsApi.ts +6 -1
  123. package/src/OAuthClientsApi.ts +33 -0
  124. package/src/OAuthGrantsApi.ts +42 -0
  125. package/src/OAuthProvidersApi.ts +59 -0
  126. package/src/OAuthServerApi.ts +30 -0
  127. package/src/ProjectsApi.ts +3 -3
  128. package/src/RemoteMcpConnectionsApi.ts +53 -0
  129. package/src/RunsApi.ts +6 -13
  130. package/src/client.test.ts +9 -11
  131. package/src/client.ts +83 -55
  132. package/src/index.ts +5 -0
  133. package/src/store/AgentsApi.ts +62 -43
  134. package/src/store/CostApi.ts +67 -0
  135. package/src/store/IndexingApi.ts +124 -35
  136. package/src/store/ObjectsApi.ts +7 -3
  137. package/src/store/WorkflowsApi.ts +327 -252
  138. package/src/store/client.ts +2 -0
  139. package/lib/cjs/MCPOAuthApi.js +0 -69
  140. package/lib/cjs/MCPOAuthApi.js.map +0 -1
  141. package/lib/cjs/OAuthAppsApi.js +0 -72
  142. package/lib/cjs/OAuthAppsApi.js.map +0 -1
  143. package/lib/esm/MCPOAuthApi.js +0 -66
  144. package/lib/esm/MCPOAuthApi.js.map +0 -1
  145. package/lib/esm/OAuthAppsApi.js +0 -69
  146. package/lib/esm/OAuthAppsApi.js.map +0 -1
  147. package/lib/types/MCPOAuthApi.d.ts +0 -50
  148. package/lib/types/MCPOAuthApi.d.ts.map +0 -1
  149. package/lib/types/OAuthAppsApi.d.ts +0 -51
  150. package/lib/types/OAuthAppsApi.d.ts.map +0 -1
  151. package/src/MCPOAuthApi.ts +0 -74
  152. package/src/OAuthAppsApi.ts +0 -87
package/src/client.ts CHANGED
@@ -3,24 +3,27 @@ import { AuthTokenPayload, AuthTokenResponse } from "@vertesia/common";
3
3
  import AccountApi from "./AccountApi.js";
4
4
  import AccountsApi from "./AccountsApi.js";
5
5
  import AnalyticsApi from "./AnalyticsApi.js";
6
- import AuditTrailApi from "./AuditTrailApi.js";
7
6
  import { ApiKeysApi } from "./ApiKeysApi.js";
8
7
  import AppsApi from "./AppsApi.js";
8
+ import AuditTrailApi from "./AuditTrailApi.js";
9
9
  import CommandsApi from "./CommandsApi.js";
10
10
  import EnvironmentsApi from "./EnvironmentsApi.js";
11
11
  import { IamApi } from "./IamApi.js";
12
12
  import InteractionsApi from "./InteractionsApi.js";
13
- import MCPOAuthApi from "./MCPOAuthApi.js";
14
- import OAuthAppsApi from "./OAuthAppsApi.js";
13
+ import OAuthClientsApi from "./OAuthClientsApi.js";
14
+ import OAuthGrantsApi from "./OAuthGrantsApi.js";
15
+ import OAuthProvidersApi from "./OAuthProvidersApi.js";
16
+ import OAuthServerApi from "./OAuthServerApi.js";
15
17
  import ProjectsApi from "./ProjectsApi.js";
16
- import SkillsApi from "./SkillsApi.js";
17
18
  import PromptsApi from "./PromptsApi.js";
18
19
  import { RefsApi } from "./RefsApi.js";
20
+ import RemoteMcpConnectionsApi from "./RemoteMcpConnectionsApi.js";
19
21
  import { RunsApi } from "./RunsApi.js";
22
+ import SkillsApi from "./SkillsApi.js";
20
23
  import { ZenoClient } from "./store/client.js";
24
+ import { VERSION, VERSION_HEADER } from "./store/version.js";
21
25
  import TrainingApi from "./TrainingApi.js";
22
26
  import UsersApi from "./UsersApi.js";
23
- import { VERSION, VERSION_HEADER } from "./store/version.js";
24
27
 
25
28
 
26
29
  /**
@@ -36,15 +39,21 @@ export type VertesiaClientProps = {
36
39
  * advanced configurations, use `serverUrl` and `storeUrl` instead.
37
40
  *
38
41
  * @example api.vertesia.io
39
- * @example api-preview.vertesia.io
40
- * @example api-staging.vertesia.io
42
+ * @example api.us1.vertesia.io
43
+ * @example api-preview.eu1.vertesia.io
41
44
  * @default api.vertesia.io
42
45
  * @since 0.52.0
43
46
  */
44
47
  site?:
45
- | "api.vertesia.io"
46
- | "api-preview.vertesia.io"
47
- | "api-staging.vertesia.io";
48
+ | "api.vertesia.io"
49
+ | "api-preview.vertesia.io"
50
+ | "api.us1.vertesia.io"
51
+ | "api-preview.us1.vertesia.io"
52
+ | "api.eu1.vertesia.io"
53
+ | "api-preview.eu1.vertesia.io"
54
+ | "api.jp1.vertesia.io"
55
+ | "api-preview.jp1.vertesia.io"
56
+ | "api.dev1.vertesia.io";
48
57
  serverUrl?: string;
49
58
  storeUrl?: string;
50
59
  tokenServerUrl?: string;
@@ -76,6 +85,12 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
76
85
  */
77
86
  tokenServerUrl: string;
78
87
 
88
+ oauthClients: OAuthClientsApi;
89
+ oauthGrants: OAuthGrantsApi;
90
+ oauthServer: OAuthServerApi;
91
+ oauthProviders: OAuthProvidersApi;
92
+ remoteMcpConnections: RemoteMcpConnectionsApi;
93
+
79
94
  /**
80
95
  * Create a client from the given token.
81
96
  * If you already have the decoded token you can pass it as the second argument to avoid decodinf it again.
@@ -101,7 +116,7 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
101
116
  }).withApiKey(token);
102
117
  }
103
118
 
104
- static decodeEndpoints() {}
119
+ static decodeEndpoints() { }
105
120
 
106
121
  constructor(
107
122
  opts: VertesiaClientProps = {
@@ -136,45 +151,35 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
136
151
  if (opts.tokenServerUrl) {
137
152
  this.tokenServerUrl = opts.tokenServerUrl;
138
153
  } else if (opts.site) {
139
- // Preview uses production STS, staging uses its own STS
140
- if (opts.site === "api-preview.vertesia.io" || opts.site === "api.vertesia.io") {
141
- this.tokenServerUrl = "https://sts.vertesia.io";
142
- } else {
143
- this.tokenServerUrl = `https://${opts.site.replace(/^api/, "sts")}`;
144
- }
154
+ // Strip -preview (preview uses the same STS as production for the same region),
155
+ // then replace api prefix with sts.
156
+ // Examples:
157
+ // api.vertesia.io -> sts.vertesia.io
158
+ // api-preview.vertesia.io -> sts.vertesia.io
159
+ // api.us1.vertesia.io -> sts.us1.vertesia.io
160
+ // api-preview.eu1.vertesia.io -> sts.eu1.vertesia.io
161
+ const stsHost = opts.site.replace('api-preview.', 'api.').replace(/^api/, 'sts');
162
+ this.tokenServerUrl = `https://${stsHost}`;
145
163
  } else if (opts.serverUrl || opts.storeUrl) {
146
164
  // Determine STS URL based on environment in serverUrl or storeUrl
147
165
  const urlToCheck = opts.serverUrl || opts.storeUrl || "";
148
166
  try {
149
167
  const url = new URL(urlToCheck);
150
- // Check for environment patterns
151
- if (url.hostname.includes("-production.")) {
152
- // zeno-server-production.api.vertesia.io -> sts.vertesia.io
153
- this.tokenServerUrl = "https://sts.vertesia.io";
154
- } else if (url.hostname.includes("-preview.")) {
155
- // zeno-server-preview.api.vertesia.io -> sts.vertesia.io
156
- this.tokenServerUrl = "https://sts.vertesia.io";
157
- } else if (url.hostname === "api.vertesia.io") {
158
- this.tokenServerUrl = "https://sts.vertesia.io";
159
- } else if (url.hostname === "api-preview.vertesia.io") {
160
- this.tokenServerUrl = "https://sts.vertesia.io";
161
- } else if (url.hostname === "api-staging.vertesia.io") {
162
- this.tokenServerUrl = "https://sts-staging.vertesia.io";
163
- } else if (url.hostname.startsWith("api")) {
164
- // Generic api.* pattern replacement
165
- url.hostname = url.hostname.replace(/^api/, "sts");
166
- this.tokenServerUrl = url.toString();
168
+ if (url.hostname.startsWith("api")) {
169
+ // Strip -preview and replace api with sts.
170
+ // api.us1.vertesia.io -> sts.us1.vertesia.io
171
+ // api-preview.us1.vertesia.io -> sts.us1.vertesia.io
172
+ // api.vertesia.io -> sts.vertesia.io
173
+ const stsHost = url.hostname.replace('api-preview.', 'api.').replace(/^api/, 'sts');
174
+ this.tokenServerUrl = `https://${stsHost}`;
167
175
  } else {
168
- // Default to staging for everything else
169
- this.tokenServerUrl = "https://sts-staging.vertesia.io";
176
+ this.tokenServerUrl = "https://sts.dev1.vertesia.io";
170
177
  }
171
178
  } catch (e) {
172
- // Default to staging if URL parsing fails
173
- this.tokenServerUrl = "https://sts-staging.vertesia.io";
179
+ this.tokenServerUrl = "https://sts.dev1.vertesia.io";
174
180
  }
175
181
  } else {
176
- // Default to staging if no URL provided
177
- this.tokenServerUrl = "https://sts-staging.vertesia.io";
182
+ this.tokenServerUrl = "https://sts.dev1.vertesia.io";
178
183
  }
179
184
 
180
185
  this.store = new ZenoClient({
@@ -192,6 +197,11 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
192
197
  this.onRequest = opts.onRequest;
193
198
  this.onResponse = opts.onResponse;
194
199
  this.sessionTags = opts.sessionTags;
200
+ this.oauthClients = new OAuthClientsApi(this);
201
+ this.oauthGrants = new OAuthGrantsApi(this);
202
+ this.oauthServer = new OAuthServerApi(this);
203
+ this.oauthProviders = new OAuthProvidersApi(this);
204
+ this.remoteMcpConnections = new RemoteMcpConnectionsApi(this);
195
205
  }
196
206
 
197
207
  withApiVersion(version: string | number | null) {
@@ -217,16 +227,16 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
217
227
  return this.withAuthCallback(
218
228
  apiKey
219
229
  ? async () => {
220
- if (!isApiKey(apiKey)) {
221
- return `Bearer ${apiKey}`;
222
- }
223
-
224
- if (isTokenExpired(this._jwt)) {
225
- const jwt = await this.getAuthToken(apiKey);
226
- this._jwt = jwt.token;
227
- }
228
- return `Bearer ${this._jwt}`;
229
- }
230
+ if (!isApiKey(apiKey)) {
231
+ return `Bearer ${apiKey}`;
232
+ }
233
+
234
+ if (isTokenExpired(this._jwt)) {
235
+ const jwt = await this.getAuthToken(apiKey);
236
+ this._jwt = jwt.token;
237
+ }
238
+ return `Bearer ${this._jwt}`;
239
+ }
230
240
  : undefined,
231
241
  );
232
242
  }
@@ -349,8 +359,6 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
349
359
  refs = new RefsApi(this);
350
360
  commands = new CommandsApi(this);
351
361
  apps = new AppsApi(this);
352
- mcpOAuth = new MCPOAuthApi(this);
353
- oauthApps = new OAuthAppsApi(this);
354
362
  }
355
363
 
356
364
  function isApiKey(apiKey: string) {
@@ -374,6 +382,25 @@ export function decodeJWT(jwt: string): AuthTokenPayload {
374
382
  return JSON.parse(decodedJson);
375
383
  }
376
384
 
385
+ type RuntimeProcess = {
386
+ env?: Record<string, string | undefined>;
387
+ };
388
+
389
+ type RuntimeBuffer = {
390
+ from(input: string, encoding: string): {
391
+ toString(encoding: string): string;
392
+ };
393
+ };
394
+
395
+ function getRuntimeBuffer() {
396
+ return (globalThis as typeof globalThis & { Buffer?: RuntimeBuffer }).Buffer;
397
+ }
398
+
399
+ function getRuntimeStsUrl() {
400
+ const runtimeProcess = (globalThis as typeof globalThis & { process?: RuntimeProcess }).process;
401
+ return runtimeProcess?.env?.STS_URL;
402
+ }
403
+
377
404
  function base64UrlDecode(input: string): string {
378
405
  // Convert base64url to base64
379
406
  const base64 = input
@@ -382,9 +409,10 @@ function base64UrlDecode(input: string): string {
382
409
  // Pad with '=' to make length a multiple of 4
383
410
  .padEnd(Math.ceil(input.length / 4) * 4, "=");
384
411
 
385
- if (typeof Buffer !== "undefined") {
412
+ const runtimeBuffer = getRuntimeBuffer();
413
+ if (runtimeBuffer) {
386
414
  // Node.js
387
- return Buffer.from(base64, "base64").toString("utf-8");
415
+ return runtimeBuffer.from(base64, "base64").toString("utf-8");
388
416
  } else if (
389
417
  typeof atob !== "undefined" &&
390
418
  typeof TextDecoder !== "undefined"
@@ -417,7 +445,7 @@ function getEndpointsFromDomain(domain: string) {
417
445
  return {
418
446
  studio: `http://localhost:8091`,
419
447
  store: `http://localhost:8092`,
420
- token: process.env.STS_URL ?? "https://sts-staging.vertesia.io",
448
+ token: getRuntimeStsUrl() ?? "https://sts.dev1.vertesia.io",
421
449
  };
422
450
  } else {
423
451
  const url = `https://${domain}`;
package/src/index.ts CHANGED
@@ -3,6 +3,11 @@ export * from './client.js';
3
3
  export type { GroupsQueryOptions } from './GroupsApi.js';
4
4
  export * from './InteractionBase.js';
5
5
  export * from './InteractionOutput.js';
6
+ export { default as OAuthClientsApi } from './OAuthClientsApi.js';
7
+ export { default as OAuthGrantsApi } from './OAuthGrantsApi.js';
8
+ export { default as OAuthProvidersApi } from './OAuthProvidersApi.js';
9
+ export { default as OAuthServerApi } from './OAuthServerApi.js';
10
+ export { default as RemoteMcpConnectionsApi } from './RemoteMcpConnectionsApi.js';
6
11
  export type { AsyncExecutionResult, ComputeInteractionFacetsResponse } from './InteractionsApi.js';
7
12
  export type { ComputePromptFacetsResponse, ListInteractionsResponse } from './PromptsApi.js';
8
13
  export type { ComputeRunFacetsResponse, FilterOption } from './RunsApi.js';
@@ -2,36 +2,47 @@ import { ApiTopic, ClientBase } from '@vertesia/api-fetch-client';
2
2
  import {
3
3
  ActiveWorkstreamsQueryResult,
4
4
  AgentEvent,
5
+ AgentArtifactUrlResponse,
5
6
  AgentMessage,
6
7
  AgentMessageType,
7
8
  AgentRun,
9
+ AgentRunDetailsStreamEvent,
8
10
  AgentRunInternals,
9
- AgentRunStatus,
11
+ AgentRunUpdatesResponse,
10
12
  CompactMessage,
11
- ConversationActivityState,
12
13
  CreateAgentRunPayload,
13
14
  ErrorAnalyticsResponse,
14
15
  FirstResponseBehaviorAnalyticsResponse,
15
16
  LatencyAnalyticsResponse,
16
17
  ListAgentRunsQuery,
18
+ ListAgentRunsResponse,
17
19
  ListWorkflowRunsResponse,
18
20
  parseMessage,
19
21
  PromptSizeAnalyticsResponse,
22
+ PostAgentRunUpdatePayload,
23
+ PostAgentRunUpdateResponse,
24
+ RecordAgentRunPayload,
20
25
  RunsByAgentAnalyticsResponse,
21
26
  SearchAgentRunsQuery,
22
27
  SearchAgentRunsResponse,
28
+ SignalAgentPayload,
29
+ SignalAgentResponse,
23
30
  TimeToFirstResponseAnalyticsResponse,
31
+ TerminateAgentRunResponse,
24
32
  toAgentMessage,
25
33
  TokenUsageAnalyticsResponse,
26
34
  ToolAnalyticsResponse,
27
35
  ToolParameterAnalyticsResponse,
28
36
  TopPrincipalsAnalyticsResponse,
37
+ UpdateAgentRunStatusPayload,
29
38
  WorkflowAnalyticsFilterOptionsResponse,
30
39
  WorkflowAnalyticsSummaryQuery,
31
40
  WorkflowAnalyticsSummaryResponse,
32
41
  WorkflowAnalyticsTimeSeriesQuery,
33
42
  WorkflowRunWithDetails,
34
43
  WorkflowToolParametersQuery,
44
+ IngestAgentEventsPayload,
45
+ IngestAgentEventsResponse,
35
46
  } from '@vertesia/common';
36
47
  import { VertesiaClient } from '../client.js';
37
48
  import { EventSourceProvider } from '../execute.js';
@@ -49,7 +60,7 @@ export class AgentsApi extends ApiTopic {
49
60
  * Create and start a new agent run.
50
61
  * Returns the created AgentRun with its stable id.
51
62
  */
52
- start<TData = Record<string, any>>(
63
+ start<TData = Record<string, unknown>>(
53
64
  payload: CreateAgentRunPayload<TData>,
54
65
  ): Promise<AgentRun<TData>> {
55
66
  return this.post('/', { payload });
@@ -59,29 +70,21 @@ export class AgentsApi extends ApiTopic {
59
70
  * Record an AgentRun for an already-running workflow (e.g. schedule-triggered).
60
71
  * Only creates the MongoDB document — the workflow passes its own Temporal IDs.
61
72
  */
62
- createRecord(payload: {
63
- interaction: string;
64
- schedule_id?: string;
65
- workflow_id: string;
66
- first_workflow_run_id: string;
67
- visibility?: string;
68
- data?: Record<string, any>;
69
- type?: string;
70
- }): Promise<AgentRun> {
73
+ createRecord(payload: RecordAgentRunPayload): Promise<AgentRun> {
71
74
  return this.post('/record', { payload });
72
75
  }
73
76
 
74
77
  /**
75
78
  * Get agent run by id.
76
79
  */
77
- retrieve<TData = Record<string, any>>(id: string): Promise<AgentRun<TData>> {
80
+ retrieve<TData = Record<string, unknown>>(id: string): Promise<AgentRun<TData>> {
78
81
  return this.get(`/${id}`);
79
82
  }
80
83
 
81
84
  /**
82
85
  * List agent runs with optional filters.
83
86
  */
84
- list(query?: ListAgentRunsQuery): Promise<AgentRun[]> {
87
+ list(query?: ListAgentRunsQuery): Promise<ListAgentRunsResponse> {
85
88
  const params: Record<string, string> = {};
86
89
  if (query?.id) params.id = query.id;
87
90
  if (query?.status) {
@@ -90,10 +93,12 @@ export class AgentsApi extends ApiTopic {
90
93
  if (query?.interaction) params.interaction = query.interaction;
91
94
  if (query?.started_by) params.started_by = query.started_by;
92
95
  if (query?.since) params.since = query.since.toISOString();
96
+ if (query?.until) params.until = query.until.toISOString();
93
97
  if (query?.schedule_id) params.schedule_id = query.schedule_id;
94
98
  if (query?.type) params.type = query.type;
95
99
  if (query?.limit) params.limit = String(query.limit);
96
100
  if (query?.offset) params.offset = String(query.offset);
101
+ if (query?.cursor) params.cursor = query.cursor;
97
102
  if (query?.sort) params.sort = query.sort;
98
103
  if (query?.order) params.order = query.order;
99
104
  return this.get('/', { query: params });
@@ -114,6 +119,7 @@ export class AgentsApi extends ApiTopic {
114
119
  if (query?.tags?.length) params.tags = query.tags.join(',');
115
120
  if (query?.content_type_name) params.content_type_name = query.content_type_name;
116
121
  if (query?.since) params.since = query.since.toISOString();
122
+ if (query?.until) params.until = query.until.toISOString();
117
123
  if (query?.limit) params.limit = String(query.limit);
118
124
  if (query?.offset) params.offset = String(query.offset);
119
125
  return this.get('/search', { query: params });
@@ -122,7 +128,7 @@ export class AgentsApi extends ApiTopic {
122
128
  /**
123
129
  * Cancel/terminate an agent run.
124
130
  */
125
- terminate(id: string, reason?: string): Promise<{ message: string }> {
131
+ terminate(id: string, reason?: string): Promise<TerminateAgentRunResponse> {
126
132
  const query = reason ? { reason } : undefined;
127
133
  return this.del(`/${id}`, { query });
128
134
  }
@@ -150,15 +156,7 @@ export class AgentsApi extends ApiTopic {
150
156
  */
151
157
  updateStatus(
152
158
  id: string,
153
- update: {
154
- status?: AgentRunStatus;
155
- activity_state?: ConversationActivityState;
156
- title?: string;
157
- topic?: string;
158
- lessons_learned?: string[];
159
- /** ES-only: conversation content text (not stored in MongoDB) */
160
- content?: string;
161
- },
159
+ update: UpdateAgentRunStatusPayload,
162
160
  ): Promise<AgentRun> {
163
161
  return this.post(`/${id}/status`, { payload: update });
164
162
  }
@@ -171,7 +169,7 @@ export class AgentsApi extends ApiTopic {
171
169
  * Send a signal to a running agent.
172
170
  * Signals: "UserInput", "Stop", "FileUploaded"
173
171
  */
174
- sendSignal(id: string, signalName: string, payload?: any): Promise<{ message: string }> {
172
+ sendSignal(id: string, signalName: string, payload?: SignalAgentPayload): Promise<SignalAgentResponse> {
175
173
  return this.post(`/${id}/signal/${signalName}`, { payload });
176
174
  }
177
175
 
@@ -200,16 +198,14 @@ export class AgentsApi extends ApiTopic {
200
198
  */
201
199
  async retrieveMessages(id: string, since?: number): Promise<AgentMessage[]> {
202
200
  const query = since ? { since } : undefined;
203
- const response = (await this.get(`/${id}/updates`, { query })) as {
204
- messages: CompactMessage[];
205
- };
201
+ const response = await this.get(`/${id}/updates`, { query }) as AgentRunUpdatesResponse;
206
202
  return response.messages.map((m: CompactMessage) => toAgentMessage(m, id));
207
203
  }
208
204
 
209
205
  /**
210
206
  * Post a message/update to an agent run.
211
207
  */
212
- postMessage(id: string, msg: Partial<AgentMessage>): Promise<void> {
208
+ postMessage(id: string, msg: PostAgentRunUpdatePayload): Promise<PostAgentRunUpdateResponse> {
213
209
  return this.post(`/${id}/updates`, { payload: msg });
214
210
  }
215
211
 
@@ -240,7 +236,7 @@ export class AgentsApi extends ApiTopic {
240
236
  let lastMessageTimestamp = since || 0;
241
237
  let isClosed = false;
242
238
  let currentSse: EventSource | null = null;
243
- let interval: NodeJS.Timeout | null = null;
239
+ let interval: ReturnType<typeof setInterval> | null = null;
244
240
  let reconnectTimer: ReturnType<typeof setTimeout> | null = null;
245
241
  let abortHandler: (() => void) | null = null;
246
242
 
@@ -372,7 +368,7 @@ export class AgentsApi extends ApiTopic {
372
368
  }
373
369
  };
374
370
 
375
- sse.onerror = (_err: any) => {
371
+ sse.onerror = (_err: unknown) => {
376
372
  if (isClosed) return;
377
373
  cleanup();
378
374
 
@@ -452,7 +448,7 @@ export class AgentsApi extends ApiTopic {
452
448
  */
453
449
  async streamRunDetails(
454
450
  id: string,
455
- onEvent?: (event: { type: string; data: unknown }) => void,
451
+ onEvent?: (event: AgentRunDetailsStreamEvent) => void,
456
452
  signal?: AbortSignal,
457
453
  ): Promise<void> {
458
454
  const EventSourceImpl = await EventSourceProvider();
@@ -486,16 +482,16 @@ export class AgentsApi extends ApiTopic {
486
482
 
487
483
  sse.addEventListener('history', (ev: MessageEvent) => {
488
484
  try {
489
- const data = JSON.parse(ev.data);
485
+ const data = JSON.parse(ev.data) as Extract<AgentRunDetailsStreamEvent, { type: 'history' }>['data'];
490
486
  if (onEvent) onEvent({ type: 'history', data });
491
487
  } catch (_err) { /* ignore parse errors */ }
492
488
  });
493
489
 
494
490
  sse.addEventListener('control', (ev: MessageEvent) => {
495
491
  try {
496
- const data = JSON.parse(ev.data);
492
+ const data = JSON.parse(ev.data) as Extract<AgentRunDetailsStreamEvent, { type: 'control' }>['data'];
497
493
  if (onEvent) onEvent({ type: 'control', data });
498
- if (data.type === 'done') {
494
+ if ('type' in data && data.type === 'done') {
499
495
  cleanup();
500
496
  resolve();
501
497
  }
@@ -504,7 +500,7 @@ export class AgentsApi extends ApiTopic {
504
500
 
505
501
  sse.addEventListener('error', (ev: MessageEvent) => {
506
502
  try {
507
- const data = JSON.parse(ev.data);
503
+ const data = JSON.parse(ev.data) as Extract<AgentRunDetailsStreamEvent, { type: 'error' }>['data'];
508
504
  if (onEvent) onEvent({ type: 'error', data });
509
505
  } catch (_err) { /* ignore parse errors */ }
510
506
  });
@@ -523,15 +519,34 @@ export class AgentsApi extends ApiTopic {
523
519
  return this.get(`/${id}/children`);
524
520
  }
525
521
 
522
+ /**
523
+ * Get details for a specific child workflow.
524
+ * Serves from GCS archive when available, falls back to Temporal.
525
+ */
526
+ getChildDetails(
527
+ id: string,
528
+ childWorkflowId: string,
529
+ options?: { includeHistory?: boolean },
530
+ ): Promise<WorkflowRunWithDetails> {
531
+ const query: Record<string, string> = {};
532
+ if (options?.includeHistory) query.include_history = 'true';
533
+ return this.get(`/${id}/children/${childWorkflowId}/details`, { query });
534
+ }
535
+
526
536
  // ========================================================================
527
537
  // Artifacts
528
538
  // ========================================================================
529
539
 
530
540
  /**
531
541
  * List artifacts for an agent run.
542
+ * visibility:
543
+ * - 'user' (default): only user-facing artifacts
544
+ * - 'internal': only system-managed state files such as conversation snapshots
545
+ * - 'all': both user-facing and internal files
532
546
  */
533
- listArtifacts(id: string): Promise<string[]> {
534
- return this.get(`/${id}/artifacts`);
547
+ listArtifacts(id: string, options?: { visibility?: 'user' | 'internal' | 'all' }): Promise<string[]> {
548
+ const query = options?.visibility ? { visibility: options.visibility } : undefined;
549
+ return this.get(`/${id}/artifacts`, { query });
535
550
  }
536
551
 
537
552
  /**
@@ -541,9 +556,11 @@ export class AgentsApi extends ApiTopic {
541
556
  id: string,
542
557
  path: string,
543
558
  disposition?: 'inline' | 'attachment',
544
- ): Promise<{ url: string; path: string }> {
559
+ fileName?: string,
560
+ ): Promise<AgentArtifactUrlResponse> {
545
561
  const query: Record<string, string> = { url: '1' };
546
562
  if (disposition) query.disposition = disposition;
563
+ if (fileName) query.filename = fileName;
547
564
  return this.get(`/${id}/artifacts/${path}`, { query });
548
565
  }
549
566
 
@@ -561,13 +578,13 @@ export class AgentsApi extends ApiTopic {
561
578
  path: string,
562
579
  content: Blob | ReadableStream | ArrayBuffer | string,
563
580
  contentType?: string,
564
- ): Promise<{ url: string; path: string }> {
581
+ ): Promise<AgentArtifactUrlResponse> {
565
582
  const mimeType = contentType || 'application/octet-stream';
566
583
 
567
584
  // 1. Get signed upload URL from the agents API
568
585
  const result = await this.put(`/${id}/artifacts/${path}`, {
569
586
  headers: { 'Content-Type': mimeType },
570
- }) as { url: string; path: string };
587
+ }) as AgentArtifactUrlResponse;
571
588
 
572
589
  // 2. Upload directly to cloud storage
573
590
  const res = await fetch(result.url, {
@@ -612,8 +629,9 @@ export class AgentsApi extends ApiTopic {
612
629
  ingestEvents(
613
630
  agentRunId: string,
614
631
  events: AgentEvent[],
615
- ): Promise<{ ingested: number; status?: string; error?: string }> {
616
- return this.post(`/${agentRunId}/events`, { payload: { events } });
632
+ ): Promise<IngestAgentEventsResponse> {
633
+ const payload: IngestAgentEventsPayload = { events };
634
+ return this.post(`/${agentRunId}/events`, { payload });
617
635
  }
618
636
 
619
637
  // ========================================================================
@@ -762,4 +780,5 @@ export class AgentsApi extends ApiTopic {
762
780
  ): Promise<FirstResponseBehaviorAnalyticsResponse> {
763
781
  return this.post('/analytics/first-response-behavior', { payload: query });
764
782
  }
783
+
765
784
  }
@@ -0,0 +1,67 @@
1
+ import { ApiTopic, ClientBase } from '@vertesia/api-fetch-client';
2
+ import { CostAnalyticsQuery, CostAnalyticsResponse, CostRunPriceQuery, CostRunPriceResponse, ModelPriceComparisonResponse } from '@vertesia/common';
3
+
4
+ export class CostApi extends ApiTopic {
5
+ constructor(parent: ClientBase) {
6
+ super(parent, '/api/v1/cost');
7
+ }
8
+
9
+ /**
10
+ * Get cost analytics for the current project.
11
+ * Returns cost breakdown by model/environment with pricing from billing export.
12
+ * Covers all inference types: direct, agent, embedding.
13
+ */
14
+ getAnalytics(
15
+ query: CostAnalyticsQuery = {}
16
+ ): Promise<CostAnalyticsResponse> {
17
+ return this.post('/analytics', { payload: query });
18
+ }
19
+
20
+ /**
21
+ * Get platform-wide cost analytics across all customers.
22
+ * Requires Vertesia staff privileges. Defaults to group_by='account'.
23
+ */
24
+ getGlobalAnalytics(
25
+ query: CostAnalyticsQuery = {}
26
+ ): Promise<CostAnalyticsResponse> {
27
+ return this.post('/analytics/global', { payload: query });
28
+ }
29
+
30
+ /**
31
+ * Get current list prices and effective prices for the selected period.
32
+ */
33
+ getModelPrices(
34
+ query: Pick<CostAnalyticsQuery, 'from' | 'to'> = {}
35
+ ): Promise<ModelPriceComparisonResponse> {
36
+ return this.get('/model-prices', { query });
37
+ }
38
+
39
+ /**
40
+ * Price a single interaction run or agent run.
41
+ */
42
+ getRunPrice(
43
+ query: CostRunPriceQuery
44
+ ): Promise<CostRunPriceResponse> {
45
+ return this.post('/run-price', { payload: query });
46
+ }
47
+
48
+ /**
49
+ * Price a run and include the full model pricing catalog for comparison.
50
+ */
51
+ getRunPriceComparison(
52
+ query: CostRunPriceQuery
53
+ ): Promise<CostRunPriceResponse> {
54
+ return this.post('/run-price', { payload: { ...query, include_comparison_pricing: true } });
55
+ }
56
+
57
+ /**
58
+ * Get the CSV export URL for raw inference audit events.
59
+ */
60
+ getExportUrl(params?: { from?: string | number; to?: string | number }): string {
61
+ const searchParams = new URLSearchParams();
62
+ if (params?.from) searchParams.set('from', typeof params.from === 'number' ? new Date(params.from).toISOString() : params.from);
63
+ if (params?.to) searchParams.set('to', typeof params.to === 'number' ? new Date(params.to).toISOString() : params.to);
64
+ const qs = searchParams.toString();
65
+ return `${this.baseUrl}/export${qs ? `?${qs}` : ''}`;
66
+ }
67
+ }