@axiom-lattice/client-sdk 3.0.2 → 3.0.4
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/dist/__tests__/streamEvents.test.d.ts +9 -0
- package/dist/__tests__/streamEvents.test.d.ts.map +1 -0
- package/dist/__tests__/streamEvents.test.js +72 -0
- package/dist/__tests__/streamEvents.test.js.map +1 -0
- package/dist/client.d.ts +12 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +44 -2
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +19 -65
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +41 -113
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -112
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.ts +7 -0
- package/dist/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/dist/eval.d.ts +0 -64
- package/dist/eval.d.ts.map +0 -1
- package/dist/eval.js +0 -117
- package/dist/eval.js.map +0 -1
package/dist/index.mjs
CHANGED
|
@@ -2917,116 +2917,6 @@ var AbstractClient = class {
|
|
|
2917
2917
|
}
|
|
2918
2918
|
};
|
|
2919
2919
|
|
|
2920
|
-
// src/eval.ts
|
|
2921
|
-
var EvalClient = class {
|
|
2922
|
-
constructor(baseUrl, headers) {
|
|
2923
|
-
this.projects = {
|
|
2924
|
-
create: (data) => this.request("/api/eval/projects", {
|
|
2925
|
-
method: "POST",
|
|
2926
|
-
body: JSON.stringify(data)
|
|
2927
|
-
}),
|
|
2928
|
-
list: () => this.request("/api/eval/projects"),
|
|
2929
|
-
get: (id) => this.request(`/api/eval/projects/${id}`),
|
|
2930
|
-
update: (id, patch) => this.request(`/api/eval/projects/${id}`, {
|
|
2931
|
-
method: "PUT",
|
|
2932
|
-
body: JSON.stringify(patch)
|
|
2933
|
-
}),
|
|
2934
|
-
delete: (id) => this.request(`/api/eval/projects/${id}`, { method: "DELETE" }),
|
|
2935
|
-
suites: {
|
|
2936
|
-
create: (projectId, data) => this.request(`/api/eval/projects/${projectId}/suites`, {
|
|
2937
|
-
method: "POST",
|
|
2938
|
-
body: JSON.stringify(data)
|
|
2939
|
-
}),
|
|
2940
|
-
update: (projectId, suiteId, patch) => this.request(`/api/eval/projects/${projectId}/suites/${suiteId}`, {
|
|
2941
|
-
method: "PUT",
|
|
2942
|
-
body: JSON.stringify(patch)
|
|
2943
|
-
}),
|
|
2944
|
-
delete: (projectId, suiteId) => this.request(`/api/eval/projects/${projectId}/suites/${suiteId}`, { method: "DELETE" }),
|
|
2945
|
-
cases: {
|
|
2946
|
-
list: (projectId, suiteId) => this.request(`/api/eval/projects/${projectId}/suites/${suiteId}/cases`),
|
|
2947
|
-
create: (projectId, suiteId, data) => this.request(`/api/eval/projects/${projectId}/suites/${suiteId}/cases`, {
|
|
2948
|
-
method: "POST",
|
|
2949
|
-
body: JSON.stringify(data)
|
|
2950
|
-
}),
|
|
2951
|
-
update: (projectId, suiteId, caseId, patch) => this.request(`/api/eval/projects/${projectId}/suites/${suiteId}/cases/${caseId}`, {
|
|
2952
|
-
method: "PUT",
|
|
2953
|
-
body: JSON.stringify(patch)
|
|
2954
|
-
}),
|
|
2955
|
-
delete: (projectId, suiteId, caseId) => this.request(`/api/eval/projects/${projectId}/suites/${suiteId}/cases/${caseId}`, { method: "DELETE" })
|
|
2956
|
-
}
|
|
2957
|
-
}
|
|
2958
|
-
};
|
|
2959
|
-
this.runs = {
|
|
2960
|
-
/**
|
|
2961
|
-
* Start an eval run. Optional runConfig carries the workspace-project
|
|
2962
|
-
* environment (caller's runConfig) the run executes in.
|
|
2963
|
-
*/
|
|
2964
|
-
start: (projectId, runConfig) => this.request(`/api/eval/projects/${projectId}/runs`, {
|
|
2965
|
-
method: "POST",
|
|
2966
|
-
body: runConfig ? JSON.stringify({ runConfig }) : void 0
|
|
2967
|
-
}),
|
|
2968
|
-
list: (opts) => {
|
|
2969
|
-
const params = new URLSearchParams();
|
|
2970
|
-
if (opts?.projectId)
|
|
2971
|
-
params.set("project_id", opts.projectId);
|
|
2972
|
-
if (opts?.status)
|
|
2973
|
-
params.set("status", opts.status);
|
|
2974
|
-
const qs = params.toString();
|
|
2975
|
-
return this.request(`/api/eval/runs${qs ? `?${qs}` : ""}`);
|
|
2976
|
-
},
|
|
2977
|
-
get: (id) => this.request(`/api/eval/runs/${id}`),
|
|
2978
|
-
abort: (id) => this.request(`/api/eval/runs/${id}/abort`, { method: "POST" }),
|
|
2979
|
-
delete: (id) => this.request(`/api/eval/runs/${id}`, { method: "DELETE" }),
|
|
2980
|
-
stream: (id) => this.streamRun(id)
|
|
2981
|
-
};
|
|
2982
|
-
this.reports = {
|
|
2983
|
-
project: (projectId) => this.request(`/api/eval/reports/projects/${projectId}`)
|
|
2984
|
-
};
|
|
2985
|
-
this.baseUrl = baseUrl;
|
|
2986
|
-
this.headers = headers;
|
|
2987
|
-
}
|
|
2988
|
-
async request(path, opts) {
|
|
2989
|
-
const res = await fetch(`${this.baseUrl}${path}`, {
|
|
2990
|
-
...opts,
|
|
2991
|
-
headers: { ...this.headers, ...opts?.headers }
|
|
2992
|
-
});
|
|
2993
|
-
const json = await res.json();
|
|
2994
|
-
if (!json.success)
|
|
2995
|
-
throw new Error(json.message);
|
|
2996
|
-
return json.data;
|
|
2997
|
-
}
|
|
2998
|
-
async *streamRun(id) {
|
|
2999
|
-
const res = await fetch(`${this.baseUrl}/api/eval/runs/${id}/stream`, {
|
|
3000
|
-
headers: this.headers
|
|
3001
|
-
});
|
|
3002
|
-
if (!res.ok || !res.body)
|
|
3003
|
-
throw new Error("Stream connection failed");
|
|
3004
|
-
const reader = res.body.getReader();
|
|
3005
|
-
const decoder = new TextDecoder();
|
|
3006
|
-
let buffer = "";
|
|
3007
|
-
while (true) {
|
|
3008
|
-
const { done, value } = await reader.read();
|
|
3009
|
-
if (done)
|
|
3010
|
-
break;
|
|
3011
|
-
buffer += decoder.decode(value, { stream: true });
|
|
3012
|
-
const lines = buffer.split("\n");
|
|
3013
|
-
buffer = lines.pop() || "";
|
|
3014
|
-
let eventType = "";
|
|
3015
|
-
for (const line of lines) {
|
|
3016
|
-
if (line.startsWith("event: ")) {
|
|
3017
|
-
eventType = line.slice(7);
|
|
3018
|
-
} else if (line.startsWith("data: ")) {
|
|
3019
|
-
try {
|
|
3020
|
-
const data = JSON.parse(line.slice(6));
|
|
3021
|
-
yield { type: eventType, runId: id, data };
|
|
3022
|
-
} catch {
|
|
3023
|
-
}
|
|
3024
|
-
}
|
|
3025
|
-
}
|
|
3026
|
-
}
|
|
3027
|
-
}
|
|
3028
|
-
};
|
|
3029
|
-
|
|
3030
2920
|
// src/resources-client.ts
|
|
3031
2921
|
var ResourcesClient = class {
|
|
3032
2922
|
constructor(baseURL, getHeaders) {
|
|
@@ -3083,7 +2973,6 @@ var _Client = class extends AbstractClient {
|
|
|
3083
2973
|
Authorization: `Bearer ${this.config.apiKey}`,
|
|
3084
2974
|
...this.config.headers
|
|
3085
2975
|
};
|
|
3086
|
-
this.eval = new EvalClient(this.config.baseURL, this.getAllHeaders());
|
|
3087
2976
|
this.resources = new ResourcesClient(this.config.baseURL, () => this.getAllHeaders());
|
|
3088
2977
|
}
|
|
3089
2978
|
/**
|
|
@@ -3359,6 +3248,47 @@ var _Client = class extends AbstractClient {
|
|
|
3359
3248
|
* @param onError - Optional callback function called when an error occurs
|
|
3360
3249
|
* @returns A function that can be called to stop the stream
|
|
3361
3250
|
*/
|
|
3251
|
+
/**
|
|
3252
|
+
* Open an SSE stream and yield parsed events.
|
|
3253
|
+
*
|
|
3254
|
+
* Headers (auth, tenant, workspace) are resolved live at request time, so
|
|
3255
|
+
* a tenant selected after client construction is always sent.
|
|
3256
|
+
*
|
|
3257
|
+
* @param path - API path, e.g. "/api/eval/runs/r1/stream"
|
|
3258
|
+
* @param signal - Optional AbortSignal to cancel the stream
|
|
3259
|
+
* @yields Parsed `{ event, data }` pairs
|
|
3260
|
+
*/
|
|
3261
|
+
async *streamEvents(path, signal) {
|
|
3262
|
+
const headers = {
|
|
3263
|
+
Accept: "text/event-stream",
|
|
3264
|
+
...this.getAllHeaders()
|
|
3265
|
+
};
|
|
3266
|
+
const res = await fetch(`${this.config.baseURL}${path}`, { headers, signal });
|
|
3267
|
+
if (!res.ok || !res.body)
|
|
3268
|
+
throw new Error("Stream connection failed");
|
|
3269
|
+
const reader = res.body.getReader();
|
|
3270
|
+
const decoder = new TextDecoder();
|
|
3271
|
+
let buffer = "";
|
|
3272
|
+
while (true) {
|
|
3273
|
+
const { done, value } = await reader.read();
|
|
3274
|
+
if (done)
|
|
3275
|
+
break;
|
|
3276
|
+
buffer += decoder.decode(value, { stream: true });
|
|
3277
|
+
const lines = buffer.split("\n");
|
|
3278
|
+
buffer = lines.pop() || "";
|
|
3279
|
+
let event = "";
|
|
3280
|
+
for (const line of lines) {
|
|
3281
|
+
if (line.startsWith("event: ")) {
|
|
3282
|
+
event = line.slice(7);
|
|
3283
|
+
} else if (line.startsWith("data: ")) {
|
|
3284
|
+
try {
|
|
3285
|
+
yield { event, data: JSON.parse(line.slice(6)) };
|
|
3286
|
+
} catch {
|
|
3287
|
+
}
|
|
3288
|
+
}
|
|
3289
|
+
}
|
|
3290
|
+
}
|
|
3291
|
+
}
|
|
3362
3292
|
/**
|
|
3363
3293
|
* Get all headers including workspace context
|
|
3364
3294
|
* @private
|
|
@@ -4233,7 +4163,6 @@ export {
|
|
|
4233
4163
|
ApiError,
|
|
4234
4164
|
AuthenticationError,
|
|
4235
4165
|
Client,
|
|
4236
|
-
EvalClient,
|
|
4237
4166
|
ExportImportClient,
|
|
4238
4167
|
NetworkError,
|
|
4239
4168
|
ResourcesClient,
|