@vertesia/client 0.61.0 → 0.63.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.
- package/lib/cjs/client.js +10 -12
- package/lib/cjs/client.js.map +1 -1
- package/lib/cjs/store/WorkflowsApi.js +3 -2
- package/lib/cjs/store/WorkflowsApi.js.map +1 -1
- package/lib/esm/client.js +10 -12
- package/lib/esm/client.js.map +1 -1
- package/lib/esm/store/WorkflowsApi.js +3 -2
- package/lib/esm/store/WorkflowsApi.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/lib/types/AccountApi.d.ts +1 -0
- package/lib/types/AccountsApi.d.ts +1 -0
- package/lib/types/AnalyticsApi.d.ts +1 -0
- package/lib/types/ApiKeysApi.d.ts +1 -0
- package/lib/types/CommandsApi.d.ts +1 -0
- package/lib/types/EnvironmentsApi.d.ts +1 -0
- package/lib/types/IamApi.d.ts +1 -0
- package/lib/types/InteractionBase.d.ts +1 -0
- package/lib/types/InteractionsApi.d.ts +1 -0
- package/lib/types/PluginsApi.d.ts +1 -0
- package/lib/types/ProjectsApi.d.ts +1 -0
- package/lib/types/PromptsApi.d.ts +1 -0
- package/lib/types/RefsApi.d.ts +1 -0
- package/lib/types/RunsApi.d.ts +1 -0
- package/lib/types/StreamSource.d.ts +1 -0
- package/lib/types/TrainingApi.d.ts +1 -0
- package/lib/types/UsersApi.d.ts +1 -0
- package/lib/types/client.d.ts +6 -5
- package/lib/types/client.d.ts.map +1 -1
- package/lib/types/execute.d.ts +1 -0
- package/lib/types/index.d.ts +1 -0
- package/lib/types/nodejs/NodeStreamSource.d.ts +1 -0
- package/lib/types/nodejs/index.d.ts +1 -0
- package/lib/types/store/AgentsApi.d.ts +1 -0
- package/lib/types/store/AnalyzeDocApi.d.ts +1 -0
- package/lib/types/store/CollectionsApi.d.ts +1 -0
- package/lib/types/store/CommandsApi.d.ts +1 -0
- package/lib/types/store/EmbeddingsApi.d.ts +1 -0
- package/lib/types/store/FilesApi.d.ts +1 -0
- package/lib/types/store/ObjectsApi.d.ts +1 -0
- package/lib/types/store/TypesApi.d.ts +1 -0
- package/lib/types/store/WorkflowsApi.d.ts +2 -1
- package/lib/types/store/WorkflowsApi.d.ts.map +1 -1
- package/lib/types/store/client.d.ts +1 -0
- package/lib/types/store/errors.d.ts +1 -0
- package/lib/types/store/index.d.ts +1 -0
- package/lib/vertesia-client.js +1 -1
- package/lib/vertesia-client.js.map +1 -1
- package/package.json +3 -3
- package/src/client.ts +14 -15
- package/src/store/WorkflowsApi.ts +16 -15
package/src/client.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AbstractFetchClient } from "@vertesia/api-fetch-client";
|
|
2
|
-
import { AuthTokenResponse } from "@vertesia/common";
|
|
2
|
+
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";
|
|
@@ -8,6 +8,7 @@ import CommandsApi from "./CommandsApi.js";
|
|
|
8
8
|
import EnvironmentsApi from "./EnvironmentsApi.js";
|
|
9
9
|
import { IamApi } from "./IamApi.js";
|
|
10
10
|
import InteractionsApi from "./InteractionsApi.js";
|
|
11
|
+
import PluginsApi from "./PluginsApi.js";
|
|
11
12
|
import ProjectsApi from "./ProjectsApi.js";
|
|
12
13
|
import PromptsApi from "./PromptsApi.js";
|
|
13
14
|
import { RefsApi } from "./RefsApi.js";
|
|
@@ -15,7 +16,6 @@ import { RunsApi } from "./RunsApi.js";
|
|
|
15
16
|
import { ZenoClient } from "./store/client.js";
|
|
16
17
|
import TrainingApi from "./TrainingApi.js";
|
|
17
18
|
import UsersApi from "./UsersApi.js";
|
|
18
|
-
import PluginsApi from "./PluginsApi.js";
|
|
19
19
|
|
|
20
20
|
/**
|
|
21
21
|
* 1 min threshold constant in ms
|
|
@@ -98,6 +98,7 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
|
|
|
98
98
|
if (opts.apikey) {
|
|
99
99
|
this.withApiKey(opts.apikey);
|
|
100
100
|
}
|
|
101
|
+
//TODO: this is no more used, remove in next major version
|
|
101
102
|
if (opts.projectId) {
|
|
102
103
|
this.headers["x-project-id"] = opts.projectId;
|
|
103
104
|
}
|
|
@@ -106,7 +107,6 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
|
|
|
106
107
|
this.sessionTags = opts.sessionTags;
|
|
107
108
|
}
|
|
108
109
|
|
|
109
|
-
|
|
110
110
|
/**
|
|
111
111
|
* Overwrite to keep store and composable clients synchronized on the auth callback
|
|
112
112
|
* @param authCb
|
|
@@ -143,11 +143,21 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
|
|
|
143
143
|
return this._jwt || null;
|
|
144
144
|
}
|
|
145
145
|
|
|
146
|
-
async getDecodedJWT() {
|
|
146
|
+
async getDecodedJWT(): Promise<AuthTokenPayload | null> {
|
|
147
147
|
const jwt = await this.getRawJWT();
|
|
148
148
|
return jwt ? decodeJWT(jwt) : null;
|
|
149
149
|
}
|
|
150
150
|
|
|
151
|
+
async getProject() {
|
|
152
|
+
const jwt = await this.getDecodedJWT();
|
|
153
|
+
return jwt?.project || null;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
async getAccount() {
|
|
157
|
+
const jwt = await this.getDecodedJWT();
|
|
158
|
+
return jwt?.account || null;
|
|
159
|
+
}
|
|
160
|
+
|
|
151
161
|
/**
|
|
152
162
|
* Alias for store.workflows
|
|
153
163
|
*/
|
|
@@ -177,17 +187,6 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
|
|
|
177
187
|
return this.store.baseUrl;
|
|
178
188
|
}
|
|
179
189
|
|
|
180
|
-
set project(projectId: string | null) {
|
|
181
|
-
if (projectId) {
|
|
182
|
-
this.headers["x-project-id"] = projectId;
|
|
183
|
-
} else {
|
|
184
|
-
delete this.headers["x-project-id"];
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
get project() {
|
|
189
|
-
return this.headers["x-project-id"] || null;
|
|
190
|
-
}
|
|
191
190
|
|
|
192
191
|
/**
|
|
193
192
|
*
|
|
@@ -38,8 +38,9 @@ export class WorkflowsApi extends ApiTopic {
|
|
|
38
38
|
return this.post(`/runs/${workflowId}/${runId}/signal/${signal}`, { payload });
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
getRunDetails(runId: string, workflowId: string): Promise<WorkflowRunWithDetails> {
|
|
42
|
-
|
|
41
|
+
getRunDetails(runId: string, workflowId: string, includeHistory: boolean = false): Promise<WorkflowRunWithDetails> {
|
|
42
|
+
const query = { include_history: includeHistory };
|
|
43
|
+
return this.get(`/runs/${workflowId}/${runId}`, { query });
|
|
43
44
|
}
|
|
44
45
|
|
|
45
46
|
terminate(workflowId: string, runId: string, reason?: string): Promise<{ message: string }> {
|
|
@@ -116,31 +117,31 @@ export class WorkflowsApi extends ApiTopic {
|
|
|
116
117
|
const EventSourceImpl = await EventSourceProvider();
|
|
117
118
|
const client = this.client as VertesiaClient;
|
|
118
119
|
const streamUrl = new URL(client.workflows.baseUrl + "/runs/" + runId + "/stream");
|
|
119
|
-
|
|
120
|
+
|
|
120
121
|
// Use the timestamp of the last received message for reconnection
|
|
121
122
|
if (lastMessageTimestamp > 0) {
|
|
122
123
|
streamUrl.searchParams.set("since", lastMessageTimestamp.toString());
|
|
123
124
|
}
|
|
124
|
-
|
|
125
|
+
|
|
125
126
|
const bearerToken = client._auth ? await client._auth() : undefined;
|
|
126
127
|
if (!bearerToken) {
|
|
127
128
|
reject(new Error("No auth token available"));
|
|
128
129
|
return;
|
|
129
130
|
}
|
|
130
|
-
|
|
131
|
+
|
|
131
132
|
const token = bearerToken.split(" ")[1];
|
|
132
133
|
streamUrl.searchParams.set("access_token", token);
|
|
133
134
|
|
|
134
135
|
if (isReconnect) {
|
|
135
136
|
console.log(`Reconnecting to SSE stream for run ${runId} (attempt ${reconnectAttempts + 1}/${maxReconnectAttempts})`);
|
|
136
137
|
}
|
|
137
|
-
|
|
138
|
+
|
|
138
139
|
const sse = new EventSourceImpl(streamUrl.href);
|
|
139
140
|
currentSse = sse;
|
|
140
|
-
|
|
141
|
+
|
|
141
142
|
// Prevent Node from exiting prematurely
|
|
142
|
-
interval = setInterval(() => {}, 1000);
|
|
143
|
-
|
|
143
|
+
interval = setInterval(() => { }, 1000);
|
|
144
|
+
|
|
144
145
|
sse.onopen = () => {
|
|
145
146
|
if (isReconnect) {
|
|
146
147
|
console.log(`Successfully reconnected to SSE stream for run ${runId}`);
|
|
@@ -154,17 +155,17 @@ export class WorkflowsApi extends ApiTopic {
|
|
|
154
155
|
console.log("Received comment or heartbeat; ignoring it.: ", ev.data);
|
|
155
156
|
return;
|
|
156
157
|
}
|
|
157
|
-
|
|
158
|
+
|
|
158
159
|
try {
|
|
159
160
|
const message = JSON.parse(ev.data) as AgentMessage;
|
|
160
|
-
|
|
161
|
+
|
|
161
162
|
// Update last message timestamp for reconnection
|
|
162
163
|
if (message.timestamp) {
|
|
163
164
|
lastMessageTimestamp = Math.max(lastMessageTimestamp, message.timestamp);
|
|
164
165
|
}
|
|
165
166
|
|
|
166
167
|
if (onMessage) onMessage(message, exit);
|
|
167
|
-
|
|
168
|
+
|
|
168
169
|
// Only close the stream when the main workstream completes
|
|
169
170
|
if (message.type === AgentMessageType.COMPLETE && (!message.workstream_id || message.workstream_id === 'main')) {
|
|
170
171
|
console.log("Closing stream due to COMPLETE message from main workstream");
|
|
@@ -180,7 +181,7 @@ export class WorkflowsApi extends ApiTopic {
|
|
|
180
181
|
console.error("Failed to parse SSE message:", err, ev.data);
|
|
181
182
|
}
|
|
182
183
|
};
|
|
183
|
-
|
|
184
|
+
|
|
184
185
|
sse.onerror = (err: any) => {
|
|
185
186
|
if (isClosed) return;
|
|
186
187
|
|
|
@@ -191,7 +192,7 @@ export class WorkflowsApi extends ApiTopic {
|
|
|
191
192
|
if (reconnectAttempts < maxReconnectAttempts) {
|
|
192
193
|
const delay = calculateBackoffDelay(reconnectAttempts);
|
|
193
194
|
console.log(`Attempting to reconnect in ${delay}ms (attempt ${reconnectAttempts + 1}/${maxReconnectAttempts})`);
|
|
194
|
-
|
|
195
|
+
|
|
195
196
|
reconnectAttempts++;
|
|
196
197
|
setTimeout(() => {
|
|
197
198
|
if (!isClosed) {
|
|
@@ -219,7 +220,7 @@ export class WorkflowsApi extends ApiTopic {
|
|
|
219
220
|
}
|
|
220
221
|
}
|
|
221
222
|
};
|
|
222
|
-
|
|
223
|
+
|
|
223
224
|
// Start the async setup process
|
|
224
225
|
setupStream(false);
|
|
225
226
|
|