@vertesia/client 0.78.0-dev-28b447d → 0.79.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/AccountApi.js +85 -0
- package/lib/cjs/AccountApi.js.map +1 -0
- package/lib/cjs/AccountsApi.js +16 -0
- package/lib/cjs/AccountsApi.js.map +1 -0
- package/lib/cjs/AnalyticsApi.js +13 -0
- package/lib/cjs/AnalyticsApi.js.map +1 -0
- package/lib/cjs/ApiKeysApi.js +63 -0
- package/lib/cjs/ApiKeysApi.js.map +1 -0
- package/lib/cjs/AppsApi.js +119 -0
- package/lib/cjs/AppsApi.js.map +1 -0
- package/lib/cjs/CommandsApi.js +19 -0
- package/lib/cjs/CommandsApi.js.map +1 -0
- package/lib/cjs/EnvironmentsApi.js +58 -0
- package/lib/cjs/EnvironmentsApi.js.map +1 -0
- package/lib/cjs/GroupsApi.js +78 -0
- package/lib/cjs/GroupsApi.js.map +1 -0
- package/lib/cjs/IamApi.js +53 -0
- package/lib/cjs/IamApi.js.map +1 -0
- package/lib/cjs/InteractionBase.js +44 -0
- package/lib/cjs/InteractionBase.js.map +1 -0
- package/lib/cjs/InteractionsApi.js +217 -0
- package/lib/cjs/InteractionsApi.js.map +1 -0
- package/lib/cjs/ProjectsApi.js +48 -0
- package/lib/cjs/ProjectsApi.js.map +1 -0
- package/lib/cjs/PromptsApi.js +133 -0
- package/lib/cjs/PromptsApi.js.map +1 -0
- package/lib/cjs/RefsApi.js +14 -0
- package/lib/cjs/RefsApi.js.map +1 -0
- package/lib/cjs/RunsApi.js +105 -0
- package/lib/cjs/RunsApi.js.map +1 -0
- package/lib/cjs/StreamSource.js +17 -0
- package/lib/cjs/StreamSource.js.map +1 -0
- package/lib/cjs/TrainingApi.js +54 -0
- package/lib/cjs/TrainingApi.js.map +1 -0
- package/lib/cjs/UsersApi.js +13 -0
- package/lib/cjs/UsersApi.js.map +1 -0
- package/lib/cjs/client.js +279 -0
- package/lib/cjs/client.js.map +1 -0
- package/lib/cjs/execute.js +158 -0
- package/lib/cjs/execute.js.map +1 -0
- package/lib/cjs/index.js +21 -0
- package/lib/cjs/index.js.map +1 -0
- package/lib/cjs/nodejs/NodeStreamSource.js +45 -0
- package/lib/cjs/nodejs/NodeStreamSource.js.map +1 -0
- package/lib/cjs/nodejs/index.js +18 -0
- package/lib/cjs/nodejs/index.js.map +1 -0
- package/lib/cjs/package.json +3 -0
- package/lib/cjs/store/AgentsApi.js +16 -0
- package/lib/cjs/store/AgentsApi.js.map +1 -0
- package/lib/cjs/store/AnalyzeDocApi.js +56 -0
- package/lib/cjs/store/AnalyzeDocApi.js.map +1 -0
- package/lib/cjs/store/CollectionsApi.js +101 -0
- package/lib/cjs/store/CollectionsApi.js.map +1 -0
- package/lib/cjs/store/CommandsApi.js +17 -0
- package/lib/cjs/store/CommandsApi.js.map +1 -0
- package/lib/cjs/store/EmbeddingsApi.js +29 -0
- package/lib/cjs/store/EmbeddingsApi.js.map +1 -0
- package/lib/cjs/store/FilesApi.js +147 -0
- package/lib/cjs/store/FilesApi.js.map +1 -0
- package/lib/cjs/store/ObjectsApi.js +281 -0
- package/lib/cjs/store/ObjectsApi.js.map +1 -0
- package/lib/cjs/store/TypesApi.js +57 -0
- package/lib/cjs/store/TypesApi.js.map +1 -0
- package/lib/cjs/store/WorkflowsApi.js +265 -0
- package/lib/cjs/store/WorkflowsApi.js.map +1 -0
- package/lib/cjs/store/client.js +71 -0
- package/lib/cjs/store/client.js.map +1 -0
- package/lib/cjs/store/errors.js +11 -0
- package/lib/cjs/store/errors.js.map +1 -0
- package/lib/cjs/store/index.js +22 -0
- package/lib/cjs/store/index.js.map +1 -0
- package/lib/cjs/store/version.js +6 -0
- package/lib/cjs/store/version.js.map +1 -0
- package/lib/esm/AccountApi.js +82 -0
- package/lib/esm/AccountApi.js.map +1 -0
- package/lib/esm/AccountsApi.js +13 -0
- package/lib/esm/AccountsApi.js.map +1 -0
- package/lib/esm/AnalyticsApi.js +10 -0
- package/lib/esm/AnalyticsApi.js.map +1 -0
- package/lib/esm/ApiKeysApi.js +59 -0
- package/lib/esm/ApiKeysApi.js.map +1 -0
- package/lib/esm/AppsApi.js +116 -0
- package/lib/esm/AppsApi.js.map +1 -0
- package/lib/esm/CommandsApi.js +16 -0
- package/lib/esm/CommandsApi.js.map +1 -0
- package/lib/esm/EnvironmentsApi.js +55 -0
- package/lib/esm/EnvironmentsApi.js.map +1 -0
- package/lib/esm/GroupsApi.js +74 -0
- package/lib/esm/GroupsApi.js.map +1 -0
- package/lib/esm/IamApi.js +47 -0
- package/lib/esm/IamApi.js.map +1 -0
- package/lib/esm/InteractionBase.js +40 -0
- package/lib/esm/InteractionBase.js.map +1 -0
- package/lib/esm/InteractionsApi.js +214 -0
- package/lib/esm/InteractionsApi.js.map +1 -0
- package/lib/esm/ProjectsApi.js +45 -0
- package/lib/esm/ProjectsApi.js.map +1 -0
- package/lib/esm/PromptsApi.js +130 -0
- package/lib/esm/PromptsApi.js.map +1 -0
- package/lib/esm/RefsApi.js +10 -0
- package/lib/esm/RefsApi.js.map +1 -0
- package/lib/esm/RunsApi.js +101 -0
- package/lib/esm/RunsApi.js.map +1 -0
- package/lib/esm/StreamSource.js +13 -0
- package/lib/esm/StreamSource.js.map +1 -0
- package/lib/esm/TrainingApi.js +51 -0
- package/lib/esm/TrainingApi.js.map +1 -0
- package/lib/esm/UsersApi.js +10 -0
- package/lib/esm/UsersApi.js.map +1 -0
- package/lib/esm/client.js +270 -0
- package/lib/esm/client.js.map +1 -0
- package/lib/esm/execute.js +118 -0
- package/lib/esm/execute.js.map +1 -0
- package/lib/esm/index.js +5 -0
- package/lib/esm/index.js.map +1 -0
- package/lib/esm/nodejs/NodeStreamSource.js +41 -0
- package/lib/esm/nodejs/NodeStreamSource.js.map +1 -0
- package/lib/esm/nodejs/index.js +2 -0
- package/lib/esm/nodejs/index.js.map +1 -0
- package/lib/esm/store/AgentsApi.js +12 -0
- package/lib/esm/store/AgentsApi.js.map +1 -0
- package/lib/esm/store/AnalyzeDocApi.js +52 -0
- package/lib/esm/store/AnalyzeDocApi.js.map +1 -0
- package/lib/esm/store/CollectionsApi.js +97 -0
- package/lib/esm/store/CollectionsApi.js.map +1 -0
- package/lib/esm/store/CommandsApi.js +13 -0
- package/lib/esm/store/CommandsApi.js.map +1 -0
- package/lib/esm/store/EmbeddingsApi.js +25 -0
- package/lib/esm/store/EmbeddingsApi.js.map +1 -0
- package/lib/esm/store/FilesApi.js +142 -0
- package/lib/esm/store/FilesApi.js.map +1 -0
- package/lib/esm/store/ObjectsApi.js +277 -0
- package/lib/esm/store/ObjectsApi.js.map +1 -0
- package/lib/esm/store/TypesApi.js +53 -0
- package/lib/esm/store/TypesApi.js.map +1 -0
- package/lib/esm/store/WorkflowsApi.js +259 -0
- package/lib/esm/store/WorkflowsApi.js.map +1 -0
- package/lib/esm/store/client.js +67 -0
- package/lib/esm/store/client.js.map +1 -0
- package/lib/esm/store/errors.js +7 -0
- package/lib/esm/store/errors.js.map +1 -0
- package/lib/esm/store/index.js +6 -0
- package/lib/esm/store/index.js.map +1 -0
- package/lib/esm/store/version.js +3 -0
- package/lib/esm/store/version.js.map +1 -0
- package/lib/tsconfig.tsbuildinfo +1 -0
- package/lib/types/AccountApi.d.ts +59 -0
- package/lib/types/AccountApi.d.ts.map +1 -0
- package/lib/types/AccountsApi.d.ts +7 -0
- package/lib/types/AccountsApi.d.ts.map +1 -0
- package/lib/types/AnalyticsApi.d.ts +6 -0
- package/lib/types/AnalyticsApi.d.ts.map +1 -0
- package/lib/types/ApiKeysApi.d.ts +42 -0
- package/lib/types/ApiKeysApi.d.ts.map +1 -0
- package/lib/types/AppsApi.d.ts +65 -0
- package/lib/types/AppsApi.d.ts.map +1 -0
- package/lib/types/CommandsApi.d.ts +10 -0
- package/lib/types/CommandsApi.d.ts.map +1 -0
- package/lib/types/EnvironmentsApi.d.ts +30 -0
- package/lib/types/EnvironmentsApi.d.ts.map +1 -0
- package/lib/types/GroupsApi.d.ts +65 -0
- package/lib/types/GroupsApi.d.ts.map +1 -0
- package/lib/types/IamApi.d.ts +41 -0
- package/lib/types/IamApi.d.ts.map +1 -0
- package/lib/types/InteractionBase.d.ts +22 -0
- package/lib/types/InteractionBase.d.ts.map +1 -0
- package/lib/types/InteractionsApi.d.ts +156 -0
- package/lib/types/InteractionsApi.d.ts.map +1 -0
- package/lib/types/ProjectsApi.d.ts +17 -0
- package/lib/types/ProjectsApi.d.ts.map +1 -0
- package/lib/types/PromptsApi.d.ts +106 -0
- package/lib/types/PromptsApi.d.ts.map +1 -0
- package/lib/types/RefsApi.d.ts +6 -0
- package/lib/types/RefsApi.d.ts.map +1 -0
- package/lib/types/RunsApi.d.ts +77 -0
- package/lib/types/RunsApi.d.ts.map +1 -0
- package/lib/types/StreamSource.d.ts +7 -0
- package/lib/types/StreamSource.d.ts.map +1 -0
- package/lib/types/TrainingApi.d.ts +27 -0
- package/lib/types/TrainingApi.d.ts.map +1 -0
- package/lib/types/UsersApi.d.ts +6 -0
- package/lib/types/UsersApi.d.ts.map +1 -0
- package/lib/types/client.d.ts +119 -0
- package/lib/types/client.d.ts.map +1 -0
- package/lib/types/execute.d.ts +37 -0
- package/lib/types/execute.d.ts.map +1 -0
- package/lib/types/index.d.ts +8 -0
- package/lib/types/index.d.ts.map +1 -0
- package/lib/types/nodejs/NodeStreamSource.d.ts +9 -0
- package/lib/types/nodejs/NodeStreamSource.d.ts.map +1 -0
- package/lib/types/nodejs/index.d.ts +1 -0
- package/lib/types/nodejs/index.d.ts.map +1 -0
- package/lib/types/store/AgentsApi.d.ts +6 -0
- package/lib/types/store/AgentsApi.d.ts.map +1 -0
- package/lib/types/store/AnalyzeDocApi.d.ts +17 -0
- package/lib/types/store/AnalyzeDocApi.d.ts.map +1 -0
- package/lib/types/store/CollectionsApi.d.ts +66 -0
- package/lib/types/store/CollectionsApi.d.ts.map +1 -0
- package/lib/types/store/CommandsApi.d.ts +10 -0
- package/lib/types/store/CommandsApi.d.ts.map +1 -0
- package/lib/types/store/EmbeddingsApi.d.ts +12 -0
- package/lib/types/store/EmbeddingsApi.d.ts.map +1 -0
- package/lib/types/store/FilesApi.d.ts +47 -0
- package/lib/types/store/FilesApi.d.ts.map +1 -0
- package/lib/types/store/ObjectsApi.d.ts +122 -0
- package/lib/types/store/ObjectsApi.d.ts.map +1 -0
- package/lib/types/store/TypesApi.d.ts +23 -0
- package/lib/types/store/TypesApi.d.ts.map +1 -0
- package/lib/types/store/WorkflowsApi.d.ts +50 -0
- package/lib/types/store/WorkflowsApi.d.ts.map +1 -0
- package/lib/types/store/client.d.ts +34 -0
- package/lib/types/store/client.d.ts.map +1 -0
- package/lib/types/store/errors.d.ts +4 -0
- package/lib/types/store/errors.d.ts.map +1 -0
- package/lib/types/store/index.d.ts +5 -0
- package/lib/types/store/index.d.ts.map +1 -0
- package/lib/types/store/version.d.ts +2 -0
- package/lib/types/store/version.d.ts.map +1 -0
- package/lib/vertesia-client.js +2 -0
- package/lib/vertesia-client.js.map +1 -0
- package/package.json +54 -59
- package/src/InteractionsApi.ts +1 -2
- package/src/RunsApi.ts +1 -8
- package/src/client.test.ts +0 -2
- package/src/client.ts +69 -129
- package/src/store/FilesApi.ts +2 -2
- package/src/store/WorkflowsApi.ts +0 -166
- package/src/store/client.ts +12 -3
- package/src/store/version.ts +2 -0
package/src/client.ts
CHANGED
|
@@ -16,6 +16,8 @@ import { RunsApi } from "./RunsApi.js";
|
|
|
16
16
|
import { ZenoClient } from "./store/client.js";
|
|
17
17
|
import TrainingApi from "./TrainingApi.js";
|
|
18
18
|
import UsersApi from "./UsersApi.js";
|
|
19
|
+
import { VERSION, VERSION_HEADER } from "./store/version.js";
|
|
20
|
+
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
23
|
* 1 min threshold constant in ms
|
|
@@ -35,21 +37,18 @@ export type VertesiaClientProps = {
|
|
|
35
37
|
* @default api.vertesia.io
|
|
36
38
|
* @since 0.52.0
|
|
37
39
|
*/
|
|
38
|
-
site?:
|
|
39
|
-
| "api.vertesia.io"
|
|
40
|
-
| "api-preview.vertesia.io"
|
|
41
|
-
| "api-staging.vertesia.io";
|
|
40
|
+
site?: 'api.vertesia.io' | 'api-preview.vertesia.io' | 'api-staging.vertesia.io';
|
|
42
41
|
serverUrl?: string;
|
|
43
42
|
storeUrl?: string;
|
|
44
|
-
tokenServerUrl?: string;
|
|
45
43
|
apikey?: string;
|
|
46
44
|
projectId?: string;
|
|
47
45
|
sessionTags?: string | string[];
|
|
48
46
|
onRequest?: (request: Request) => void;
|
|
49
47
|
onResponse?: (response: Response) => void;
|
|
50
|
-
}
|
|
48
|
+
}
|
|
51
49
|
|
|
52
50
|
export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
|
|
51
|
+
|
|
53
52
|
/**
|
|
54
53
|
* The JWT token linked to the API KEY (sk or pk)
|
|
55
54
|
*/
|
|
@@ -65,15 +64,11 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
|
|
|
65
64
|
*/
|
|
66
65
|
sessionTags?: string | string[];
|
|
67
66
|
|
|
68
|
-
/**
|
|
69
|
-
* tokenServerUrl
|
|
70
|
-
*/
|
|
71
|
-
tokenServerUrl: string;
|
|
72
67
|
|
|
73
68
|
/**
|
|
74
|
-
* Create a client from the given token.
|
|
69
|
+
* Create a client from the given token.
|
|
75
70
|
* If you already have the decoded token you can pass it as the second argument to avoid decodinf it again.
|
|
76
|
-
*
|
|
71
|
+
*
|
|
77
72
|
* @param token the raw JWT token
|
|
78
73
|
* @param payload the decoded JWT token as an AuthTokenPayload - optional
|
|
79
74
|
*/
|
|
@@ -81,21 +76,21 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
|
|
|
81
76
|
if (!payload) {
|
|
82
77
|
payload = decodeJWT(token);
|
|
83
78
|
}
|
|
84
|
-
|
|
85
|
-
const endpoints = decodeEndpoints(payload.endpoints);
|
|
79
|
+
const endpoints = decodeEndpoints(payload!.endpoints);
|
|
86
80
|
return await new VertesiaClient({
|
|
87
81
|
serverUrl: endpoints.studio,
|
|
88
|
-
storeUrl: endpoints.store
|
|
89
|
-
tokenServerUrl: payload.iss,
|
|
82
|
+
storeUrl: endpoints.store
|
|
90
83
|
}).withApiKey(token);
|
|
91
84
|
}
|
|
92
85
|
|
|
93
|
-
static decodeEndpoints() {
|
|
86
|
+
static decodeEndpoints() {
|
|
87
|
+
|
|
88
|
+
}
|
|
94
89
|
|
|
95
90
|
constructor(
|
|
96
91
|
opts: VertesiaClientProps = {
|
|
97
|
-
site:
|
|
98
|
-
}
|
|
92
|
+
site: 'api.vertesia.io',
|
|
93
|
+
}
|
|
99
94
|
) {
|
|
100
95
|
let studioServerUrl: string;
|
|
101
96
|
let zenoServerUrl: string;
|
|
@@ -105,9 +100,7 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
|
|
|
105
100
|
} else if (opts.site) {
|
|
106
101
|
studioServerUrl = `https://${opts.site}`;
|
|
107
102
|
} else {
|
|
108
|
-
throw new Error(
|
|
109
|
-
"Parameter 'site' or 'serverUrl' is required for VertesiaClient",
|
|
110
|
-
);
|
|
103
|
+
throw new Error("Parameter 'site' or 'serverUrl' is required for VertesiaClient");
|
|
111
104
|
}
|
|
112
105
|
|
|
113
106
|
if (opts.storeUrl) {
|
|
@@ -115,72 +108,39 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
|
|
|
115
108
|
} else if (opts.site) {
|
|
116
109
|
zenoServerUrl = `https://${opts.site}`;
|
|
117
110
|
} else {
|
|
118
|
-
throw new Error(
|
|
119
|
-
"Parameter 'site' or 'storeUrl' is required for VertesiaClient",
|
|
120
|
-
);
|
|
111
|
+
throw new Error("Parameter 'site' or 'storeUrl' is required for VertesiaClient");
|
|
121
112
|
}
|
|
122
113
|
|
|
123
114
|
super(studioServerUrl);
|
|
124
115
|
|
|
125
|
-
if (opts.tokenServerUrl) {
|
|
126
|
-
this.tokenServerUrl = opts.tokenServerUrl;
|
|
127
|
-
} else if (opts.site) {
|
|
128
|
-
this.tokenServerUrl = `https://${opts.site.replace(/^api/, "sts")}`;
|
|
129
|
-
} else if (opts.serverUrl || opts.storeUrl) {
|
|
130
|
-
// Determine STS URL based on environment in serverUrl or storeUrl
|
|
131
|
-
const urlToCheck = opts.serverUrl || opts.storeUrl || "";
|
|
132
|
-
try {
|
|
133
|
-
const url = new URL(urlToCheck);
|
|
134
|
-
// Check for environment patterns
|
|
135
|
-
if (url.hostname.includes("-production.")) {
|
|
136
|
-
// zeno-server-production.api.vertesia.io -> sts.vertesia.io
|
|
137
|
-
this.tokenServerUrl = "https://sts.vertesia.io";
|
|
138
|
-
} else if (url.hostname.includes("-preview.")) {
|
|
139
|
-
// zeno-server-preview.api.vertesia.io -> sts-preview.vertesia.io
|
|
140
|
-
this.tokenServerUrl = "https://sts-preview.vertesia.io";
|
|
141
|
-
} else if (url.hostname === "api.vertesia.io") {
|
|
142
|
-
// api.vertesia.io -> sts.vertesia.io
|
|
143
|
-
this.tokenServerUrl = "https://sts.vertesia.io";
|
|
144
|
-
} else if (url.hostname === "api-preview.vertesia.io") {
|
|
145
|
-
// api-preview.vertesia.io -> sts-preview.vertesia.io
|
|
146
|
-
this.tokenServerUrl = "https://sts-preview.vertesia.io";
|
|
147
|
-
} else if (url.hostname === "api-staging.vertesia.io") {
|
|
148
|
-
// api-staging.vertesia.io -> sts-staging.vertesia.io
|
|
149
|
-
this.tokenServerUrl = "https://sts-staging.vertesia.io";
|
|
150
|
-
} else if (url.hostname.startsWith("api")) {
|
|
151
|
-
// Generic api.* pattern replacement
|
|
152
|
-
url.hostname = url.hostname.replace(/^api/, "sts");
|
|
153
|
-
this.tokenServerUrl = url.toString();
|
|
154
|
-
} else {
|
|
155
|
-
// Default to staging for everything else
|
|
156
|
-
this.tokenServerUrl = "https://sts-staging.vertesia.io";
|
|
157
|
-
}
|
|
158
|
-
} catch (e) {
|
|
159
|
-
// Default to staging if URL parsing fails
|
|
160
|
-
this.tokenServerUrl = "https://sts-staging.vertesia.io";
|
|
161
|
-
}
|
|
162
|
-
} else {
|
|
163
|
-
// Default to staging if no URL provided
|
|
164
|
-
this.tokenServerUrl = "https://sts-staging.vertesia.io";
|
|
165
|
-
}
|
|
166
|
-
|
|
167
116
|
this.store = new ZenoClient({
|
|
168
117
|
serverUrl: zenoServerUrl,
|
|
169
|
-
tokenServerUrl: this.tokenServerUrl,
|
|
170
118
|
apikey: opts.apikey,
|
|
171
119
|
onRequest: opts.onRequest,
|
|
172
|
-
onResponse: opts.onResponse
|
|
120
|
+
onResponse: opts.onResponse
|
|
173
121
|
});
|
|
174
122
|
|
|
175
123
|
if (opts.apikey) {
|
|
176
124
|
this.withApiKey(opts.apikey);
|
|
177
125
|
}
|
|
178
|
-
|
|
126
|
+
//TODO: this is no more used, remove in next major version
|
|
127
|
+
if (opts.projectId) {
|
|
128
|
+
this.headers["x-project-id"] = opts.projectId;
|
|
129
|
+
}
|
|
179
130
|
this.onRequest = opts.onRequest;
|
|
180
131
|
this.onResponse = opts.onResponse;
|
|
181
132
|
this.sessionTags = opts.sessionTags;
|
|
182
133
|
}
|
|
183
134
|
|
|
135
|
+
withApiVersion(version: string | number | null) {
|
|
136
|
+
if (!version) {
|
|
137
|
+
delete this.headers[VERSION_HEADER];
|
|
138
|
+
} else {
|
|
139
|
+
this.headers[VERSION_HEADER] = String(version);
|
|
140
|
+
}
|
|
141
|
+
return this;
|
|
142
|
+
}
|
|
143
|
+
|
|
184
144
|
/**
|
|
185
145
|
* Overwrite to keep store and composable clients synchronized on the auth callback
|
|
186
146
|
* @param authCb
|
|
@@ -193,28 +153,25 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
|
|
|
193
153
|
|
|
194
154
|
async withApiKey(apiKey: string | null) {
|
|
195
155
|
return this.withAuthCallback(
|
|
196
|
-
apiKey
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
}
|
|
208
|
-
: undefined,
|
|
156
|
+
apiKey ? async () => {
|
|
157
|
+
if (!isApiKey(apiKey)) {
|
|
158
|
+
return `Bearer ${apiKey}`
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (isTokenExpired(this._jwt)) {
|
|
162
|
+
const jwt = await this.getAuthToken(apiKey);
|
|
163
|
+
this._jwt = jwt.token;
|
|
164
|
+
}
|
|
165
|
+
return `Bearer ${this._jwt}`
|
|
166
|
+
} : undefined
|
|
209
167
|
);
|
|
210
168
|
}
|
|
211
169
|
|
|
212
170
|
async getRawJWT() {
|
|
213
171
|
if (!this._jwt && this._auth) {
|
|
214
172
|
const auth = await this._auth();
|
|
215
|
-
if (!this._jwt) {
|
|
216
|
-
|
|
217
|
-
this._jwt = auth.trim().split(" ")[1]; // remove Bearer prefix
|
|
173
|
+
if (!this._jwt) { // the _jwt may be set by the auth callback
|
|
174
|
+
this._jwt = auth.trim().split(' ')[1]; // remove Bearer prefix
|
|
218
175
|
}
|
|
219
176
|
}
|
|
220
177
|
return this._jwt || null;
|
|
@@ -264,35 +221,27 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
|
|
|
264
221
|
return this.store.baseUrl;
|
|
265
222
|
}
|
|
266
223
|
|
|
224
|
+
|
|
267
225
|
/**
|
|
268
226
|
*
|
|
269
|
-
* Generate a token for use with other
|
|
227
|
+
* Generate a token for use with other Composable's services
|
|
270
228
|
*
|
|
229
|
+
* @param accountId: selected account to generate the token for
|
|
271
230
|
* @returns AuthTokenResponse
|
|
272
231
|
*/
|
|
273
|
-
async getAuthToken(token?: string): Promise<AuthTokenResponse> {
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
})
|
|
281
|
-
.then((response) => response.json())
|
|
282
|
-
.then((data) => data as AuthTokenResponse)
|
|
283
|
-
.catch((error) => {
|
|
284
|
-
console.error(
|
|
285
|
-
`Error fetching token from ${this.tokenServerUrl}:`,
|
|
286
|
-
{ error },
|
|
287
|
-
);
|
|
288
|
-
throw error;
|
|
289
|
-
});
|
|
232
|
+
async getAuthToken(token?: string, accountId?: string): Promise<AuthTokenResponse> {
|
|
233
|
+
const query = {
|
|
234
|
+
accountId,
|
|
235
|
+
token
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
return this.get('/auth/token', { query: query, headers: { "authorization": undefined } as any });
|
|
290
239
|
}
|
|
291
240
|
|
|
292
241
|
get initialHeaders() {
|
|
293
242
|
return {
|
|
294
243
|
...super.initialHeaders,
|
|
295
|
-
|
|
244
|
+
[VERSION_HEADER]: VERSION
|
|
296
245
|
}
|
|
297
246
|
}
|
|
298
247
|
|
|
@@ -314,7 +263,7 @@ export class VertesiaClient extends AbstractFetchClient<VertesiaClient> {
|
|
|
314
263
|
}
|
|
315
264
|
|
|
316
265
|
function isApiKey(apiKey: string) {
|
|
317
|
-
return apiKey.startsWith(
|
|
266
|
+
return (apiKey.startsWith('pk-') || apiKey.startsWith('sk-'));
|
|
318
267
|
}
|
|
319
268
|
|
|
320
269
|
function isTokenExpired(token: string | null) {
|
|
@@ -325,45 +274,38 @@ function isTokenExpired(token: string | null) {
|
|
|
325
274
|
const decoded = decodeJWT(token);
|
|
326
275
|
const exp = decoded.exp;
|
|
327
276
|
const currentTime = Date.now();
|
|
328
|
-
return currentTime <= exp * 1000 - EXPIRATION_THRESHOLD;
|
|
277
|
+
return (currentTime <= exp * 1000 - EXPIRATION_THRESHOLD);
|
|
329
278
|
}
|
|
330
279
|
|
|
331
280
|
export function decodeJWT(jwt: string): AuthTokenPayload {
|
|
332
|
-
const payloadBase64 = jwt.split(
|
|
281
|
+
const payloadBase64 = jwt.split('.')[1];
|
|
333
282
|
const decodedJson = base64UrlDecode(payloadBase64);
|
|
334
|
-
return JSON.parse(decodedJson)
|
|
283
|
+
return JSON.parse(decodedJson)
|
|
335
284
|
}
|
|
336
285
|
|
|
337
286
|
function base64UrlDecode(input: string): string {
|
|
338
287
|
// Convert base64url to base64
|
|
339
|
-
const base64 = input
|
|
340
|
-
.replace(/-/g, "+")
|
|
341
|
-
.replace(/_/g, "/")
|
|
288
|
+
const base64 = input.replace(/-/g, '+').replace(/_/g, '/')
|
|
342
289
|
// Pad with '=' to make length a multiple of 4
|
|
343
|
-
.padEnd(Math.ceil(input.length / 4) * 4,
|
|
290
|
+
.padEnd(Math.ceil(input.length / 4) * 4, '=');
|
|
344
291
|
|
|
345
|
-
if (typeof Buffer !==
|
|
292
|
+
if (typeof Buffer !== 'undefined') {
|
|
346
293
|
// Node.js
|
|
347
|
-
return Buffer.from(base64,
|
|
348
|
-
} else if (
|
|
349
|
-
typeof atob !== "undefined" &&
|
|
350
|
-
typeof TextDecoder !== "undefined"
|
|
351
|
-
) {
|
|
294
|
+
return Buffer.from(base64, 'base64').toString('utf-8');
|
|
295
|
+
} else if (typeof atob !== 'undefined' && typeof TextDecoder !== 'undefined') {
|
|
352
296
|
// Browser
|
|
353
297
|
const binary = atob(base64);
|
|
354
|
-
const bytes = Uint8Array.from(binary,
|
|
298
|
+
const bytes = Uint8Array.from(binary, c => c.charCodeAt(0));
|
|
355
299
|
// decode to utf8
|
|
356
300
|
return new TextDecoder().decode(bytes);
|
|
357
301
|
} else {
|
|
358
|
-
throw new Error(
|
|
302
|
+
throw new Error('No base64 decoder available');
|
|
359
303
|
}
|
|
360
304
|
}
|
|
361
305
|
|
|
362
|
-
export function decodeEndpoints(
|
|
363
|
-
endpoints: string | Record<string, string> | undefined,
|
|
364
|
-
): Record<string, string> {
|
|
306
|
+
export function decodeEndpoints(endpoints: string | Record<string, string> | undefined): Record<string, string> {
|
|
365
307
|
if (!endpoints) {
|
|
366
|
-
return getEndpointsFromDomain("api.vertesia.io")
|
|
308
|
+
return getEndpointsFromDomain("api.vertesia.io")
|
|
367
309
|
}
|
|
368
310
|
if (typeof endpoints === "string") {
|
|
369
311
|
return getEndpointsFromDomain(endpoints);
|
|
@@ -377,14 +319,12 @@ function getEndpointsFromDomain(domain: string) {
|
|
|
377
319
|
return {
|
|
378
320
|
studio: `http://localhost:8091`,
|
|
379
321
|
store: `http://localhost:8092`,
|
|
380
|
-
|
|
381
|
-
};
|
|
322
|
+
}
|
|
382
323
|
} else {
|
|
383
324
|
const url = `https://${domain}`;
|
|
384
325
|
return {
|
|
385
326
|
studio: url,
|
|
386
327
|
store: url,
|
|
387
|
-
|
|
388
|
-
};
|
|
328
|
+
}
|
|
389
329
|
}
|
|
390
330
|
}
|
package/src/store/FilesApi.ts
CHANGED
|
@@ -120,9 +120,9 @@ export class FilesApi extends ApiTopic {
|
|
|
120
120
|
if (res.ok) {
|
|
121
121
|
return res;
|
|
122
122
|
} else if (res.status === 404) {
|
|
123
|
-
throw new Error(`File
|
|
123
|
+
throw new Error(`File ${location} not found`); //TODO: type fetch error better with a fetch error class
|
|
124
124
|
} else if (res.status === 403) {
|
|
125
|
-
throw new Error(`File
|
|
125
|
+
throw new Error(`File ${location} is forbidden`);
|
|
126
126
|
} else {
|
|
127
127
|
console.log(res);
|
|
128
128
|
throw new Error(
|
|
@@ -10,8 +10,6 @@ import {
|
|
|
10
10
|
ListWorkflowInteractionsResponse,
|
|
11
11
|
ListWorkflowRunsPayload,
|
|
12
12
|
ListWorkflowRunsResponse,
|
|
13
|
-
WebSocketClientMessage,
|
|
14
|
-
WebSocketServerMessage,
|
|
15
13
|
WorkflowDefinitionRef,
|
|
16
14
|
WorkflowRule,
|
|
17
15
|
WorkflowRuleItem,
|
|
@@ -250,170 +248,6 @@ export class WorkflowsApi extends ApiTopic {
|
|
|
250
248
|
});
|
|
251
249
|
}
|
|
252
250
|
|
|
253
|
-
/**
|
|
254
|
-
* Stream workflow messages via WebSocket (for mobile/React Native clients)
|
|
255
|
-
* @param workflowId The workflow ID
|
|
256
|
-
* @param runId The run ID
|
|
257
|
-
* @param onMessage Callback for incoming messages
|
|
258
|
-
* @param since Optional timestamp to resume from
|
|
259
|
-
* @returns Promise that resolves with cleanup function and sendSignal helper
|
|
260
|
-
*/
|
|
261
|
-
async streamMessagesWS(
|
|
262
|
-
workflowId: string,
|
|
263
|
-
runId: string,
|
|
264
|
-
onMessage?: (message: AgentMessage) => void,
|
|
265
|
-
since?: number
|
|
266
|
-
): Promise<{ cleanup: () => void; sendSignal: (signalName: string, data: any) => void }> {
|
|
267
|
-
return new Promise((resolve, reject) => {
|
|
268
|
-
let reconnectAttempts = 0;
|
|
269
|
-
const maxReconnectAttempts = 10;
|
|
270
|
-
const baseDelay = 1000;
|
|
271
|
-
const maxDelay = 30000;
|
|
272
|
-
let ws: WebSocket | null = null;
|
|
273
|
-
let lastMessageTimestamp = since || 0;
|
|
274
|
-
let isClosed = false;
|
|
275
|
-
|
|
276
|
-
const calculateBackoffDelay = (attempts: number): number => {
|
|
277
|
-
const exponentialDelay = Math.min(baseDelay * Math.pow(2, attempts), maxDelay);
|
|
278
|
-
const jitter = Math.random() * 0.1 * exponentialDelay;
|
|
279
|
-
return exponentialDelay + jitter;
|
|
280
|
-
};
|
|
281
|
-
|
|
282
|
-
const connect = async () => {
|
|
283
|
-
if (isClosed) return;
|
|
284
|
-
|
|
285
|
-
try {
|
|
286
|
-
const client = this.client as VertesiaClient;
|
|
287
|
-
const wsUrl = new URL(client.workflows.baseUrl + `/runs/${workflowId}/${runId}/ws`);
|
|
288
|
-
|
|
289
|
-
// Replace http/https with ws/wss
|
|
290
|
-
wsUrl.protocol = wsUrl.protocol.replace('http', 'ws');
|
|
291
|
-
|
|
292
|
-
// Add query parameters
|
|
293
|
-
if (lastMessageTimestamp > 0) {
|
|
294
|
-
wsUrl.searchParams.set('since', lastMessageTimestamp.toString());
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
const bearerToken = client._auth ? await client._auth() : undefined;
|
|
298
|
-
if (!bearerToken) {
|
|
299
|
-
reject(new Error('No auth token available'));
|
|
300
|
-
return;
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
const token = bearerToken.split(' ')[1];
|
|
304
|
-
wsUrl.searchParams.set('access_token', token);
|
|
305
|
-
|
|
306
|
-
if (reconnectAttempts > 0) {
|
|
307
|
-
console.log(`Reconnecting to WebSocket for run ${runId} (attempt ${reconnectAttempts + 1}/${maxReconnectAttempts})`);
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
ws = new WebSocket(wsUrl.href);
|
|
311
|
-
|
|
312
|
-
ws.onopen = () => {
|
|
313
|
-
if (reconnectAttempts > 0) {
|
|
314
|
-
console.log(`Successfully reconnected to WebSocket for run ${runId}`);
|
|
315
|
-
}
|
|
316
|
-
reconnectAttempts = 0;
|
|
317
|
-
|
|
318
|
-
// Resolve with helpers on first successful connection
|
|
319
|
-
if (!isClosed) {
|
|
320
|
-
resolve({
|
|
321
|
-
cleanup: () => {
|
|
322
|
-
isClosed = true;
|
|
323
|
-
if (ws) {
|
|
324
|
-
ws.close();
|
|
325
|
-
ws = null;
|
|
326
|
-
}
|
|
327
|
-
},
|
|
328
|
-
sendSignal: (signalName: string, data: any) => {
|
|
329
|
-
if (ws?.readyState === WebSocket.OPEN) {
|
|
330
|
-
const message: WebSocketClientMessage = {
|
|
331
|
-
type: 'signal',
|
|
332
|
-
signalName,
|
|
333
|
-
data,
|
|
334
|
-
requestId: Date.now()
|
|
335
|
-
};
|
|
336
|
-
ws.send(JSON.stringify(message));
|
|
337
|
-
} else {
|
|
338
|
-
console.warn('WebSocket not open, cannot send signal');
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
});
|
|
342
|
-
}
|
|
343
|
-
};
|
|
344
|
-
|
|
345
|
-
ws.onmessage = (event: MessageEvent) => {
|
|
346
|
-
try {
|
|
347
|
-
const message = JSON.parse(event.data) as WebSocketServerMessage;
|
|
348
|
-
|
|
349
|
-
// Handle different message types
|
|
350
|
-
if ('workflow_run_id' in message) {
|
|
351
|
-
// This is an AgentMessage
|
|
352
|
-
const agentMessage = message as AgentMessage;
|
|
353
|
-
|
|
354
|
-
if (agentMessage.timestamp) {
|
|
355
|
-
lastMessageTimestamp = Math.max(lastMessageTimestamp, agentMessage.timestamp);
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
if (onMessage) onMessage(agentMessage);
|
|
359
|
-
|
|
360
|
-
// Check for stream completion
|
|
361
|
-
const streamIsOver =
|
|
362
|
-
agentMessage.type === AgentMessageType.TERMINATED ||
|
|
363
|
-
(agentMessage.type === AgentMessageType.COMPLETE &&
|
|
364
|
-
(!agentMessage.workstream_id || agentMessage.workstream_id === 'main'));
|
|
365
|
-
|
|
366
|
-
if (streamIsOver) {
|
|
367
|
-
console.log('Closing WebSocket due to workflow completion');
|
|
368
|
-
isClosed = true;
|
|
369
|
-
if (ws) {
|
|
370
|
-
ws.close();
|
|
371
|
-
ws = null;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
} else if (message.type === 'pong') {
|
|
375
|
-
// Heartbeat response
|
|
376
|
-
console.debug('Received pong');
|
|
377
|
-
} else if (message.type === 'ack') {
|
|
378
|
-
console.debug('Signal acknowledged', message);
|
|
379
|
-
} else if (message.type === 'error') {
|
|
380
|
-
console.error('WebSocket error message', message);
|
|
381
|
-
}
|
|
382
|
-
} catch (err) {
|
|
383
|
-
console.error('Failed to parse WebSocket message', err);
|
|
384
|
-
}
|
|
385
|
-
};
|
|
386
|
-
|
|
387
|
-
ws.onerror = (err) => {
|
|
388
|
-
console.error('WebSocket error', err);
|
|
389
|
-
};
|
|
390
|
-
|
|
391
|
-
ws.onclose = () => {
|
|
392
|
-
if (!isClosed && reconnectAttempts < maxReconnectAttempts) {
|
|
393
|
-
const delay = calculateBackoffDelay(reconnectAttempts);
|
|
394
|
-
console.log(`WebSocket closed, reconnecting in ${delay}ms (attempt ${reconnectAttempts + 1}/${maxReconnectAttempts})`);
|
|
395
|
-
reconnectAttempts++;
|
|
396
|
-
setTimeout(connect, delay);
|
|
397
|
-
} else if (reconnectAttempts >= maxReconnectAttempts) {
|
|
398
|
-
reject(new Error(`WebSocket connection failed after ${maxReconnectAttempts} attempts`));
|
|
399
|
-
}
|
|
400
|
-
};
|
|
401
|
-
} catch (err) {
|
|
402
|
-
console.error('Error setting up WebSocket', err);
|
|
403
|
-
if (reconnectAttempts < maxReconnectAttempts) {
|
|
404
|
-
const delay = calculateBackoffDelay(reconnectAttempts);
|
|
405
|
-
reconnectAttempts++;
|
|
406
|
-
setTimeout(connect, delay);
|
|
407
|
-
} else {
|
|
408
|
-
reject(err);
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
};
|
|
412
|
-
|
|
413
|
-
connect();
|
|
414
|
-
});
|
|
415
|
-
}
|
|
416
|
-
|
|
417
251
|
rules = new WorkflowsRulesApi(this);
|
|
418
252
|
definitions = new WorkflowsDefinitionApi(this);
|
|
419
253
|
}
|
package/src/store/client.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { AbstractFetchClient, RequestError } from "@vertesia/api-fetch-client";
|
|
2
2
|
import { BulkOperationPayload, BulkOperationResult } from "@vertesia/common";
|
|
3
3
|
import { AgentsApi } from "./AgentsApi.js";
|
|
4
|
+
import { CollectionsApi } from "./CollectionsApi.js";
|
|
4
5
|
import { CommandsApi } from "./CommandsApi.js";
|
|
5
6
|
import { EmbeddingsApi } from "./EmbeddingsApi.js";
|
|
6
7
|
import { ZenoClientNotFoundError } from "./errors.js";
|
|
7
8
|
import { FilesApi } from "./FilesApi.js";
|
|
8
9
|
import { ObjectsApi } from "./ObjectsApi.js";
|
|
9
10
|
import { TypesApi } from "./TypesApi.js";
|
|
11
|
+
import { VERSION, VERSION_HEADER } from "./version.js";
|
|
10
12
|
import { WorkflowsApi } from "./WorkflowsApi.js";
|
|
11
|
-
import { CollectionsApi } from "./CollectionsApi.js";
|
|
12
13
|
|
|
13
14
|
export interface ZenoClientProps {
|
|
14
15
|
serverUrl?: string;
|
|
15
|
-
tokenServerUrl?: string;
|
|
16
16
|
apikey?: string;
|
|
17
17
|
onRequest?: (request: Request) => void;
|
|
18
18
|
onResponse?: (response: Response) => void;
|
|
@@ -45,6 +45,15 @@ export class ZenoClient extends AbstractFetchClient<ZenoClient> {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
+
withApiVersion(version: string | number | null) {
|
|
49
|
+
if (!version) {
|
|
50
|
+
delete this.headers[VERSION_HEADER];
|
|
51
|
+
} else {
|
|
52
|
+
this.headers[VERSION_HEADER] = String(version);
|
|
53
|
+
}
|
|
54
|
+
return this;
|
|
55
|
+
}
|
|
56
|
+
|
|
48
57
|
withApiKey(apiKey: string | null) {
|
|
49
58
|
return this.withAuthCallback(
|
|
50
59
|
apiKey ? () => Promise.resolve(`Bearer ${apiKey}`) : undefined
|
|
@@ -60,7 +69,7 @@ export class ZenoClient extends AbstractFetchClient<ZenoClient> {
|
|
|
60
69
|
get initialHeaders() {
|
|
61
70
|
return {
|
|
62
71
|
...super.initialHeaders,
|
|
63
|
-
|
|
72
|
+
[VERSION_HEADER]: VERSION
|
|
64
73
|
}
|
|
65
74
|
}
|
|
66
75
|
|