@axiom-lattice/client-sdk 2.1.18 → 2.1.20
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/client.d.ts +16 -0
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +47 -8
- package/dist/client.js.map +1 -1
- package/dist/index.d.ts +122 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +203 -10
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +202 -10
- package/dist/index.mjs.map +1 -1
- package/dist/types.d.ts +68 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/workspace-client.d.ts +38 -0
- package/dist/workspace-client.d.ts.map +1 -0
- package/dist/workspace-client.js +138 -0
- package/dist/workspace-client.js.map +1 -0
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -2562,7 +2562,7 @@ var AbstractClient = class {
|
|
|
2562
2562
|
};
|
|
2563
2563
|
|
|
2564
2564
|
// src/client.ts
|
|
2565
|
-
var
|
|
2565
|
+
var _Client = class extends AbstractClient {
|
|
2566
2566
|
/**
|
|
2567
2567
|
* Creates a new Client instance
|
|
2568
2568
|
* @param config - Configuration options for the client
|
|
@@ -2610,10 +2610,12 @@ var Client = class extends AbstractClient {
|
|
|
2610
2610
|
const timeoutId = setTimeout(() => controller.abort(), this.config.timeout);
|
|
2611
2611
|
try {
|
|
2612
2612
|
const fullUrl = url.startsWith("http") ? url : `${this.config.baseURL}${url}`;
|
|
2613
|
+
const workspaceHeaders = _Client.getWorkspaceHeaders();
|
|
2613
2614
|
const response = await fetch(fullUrl, {
|
|
2614
2615
|
...options,
|
|
2615
2616
|
headers: {
|
|
2616
2617
|
...this.headers,
|
|
2618
|
+
...workspaceHeaders,
|
|
2617
2619
|
...options.headers || {}
|
|
2618
2620
|
},
|
|
2619
2621
|
signal: controller.signal
|
|
@@ -2638,13 +2640,40 @@ var Client = class extends AbstractClient {
|
|
|
2638
2640
|
this.tenantId = tenantId;
|
|
2639
2641
|
this.headers["x-tenant-id"] = tenantId;
|
|
2640
2642
|
}
|
|
2643
|
+
/**
|
|
2644
|
+
* Set workspace and project headers for API requests (static)
|
|
2645
|
+
* @param workspaceId - Workspace identifier
|
|
2646
|
+
* @param projectId - Project identifier
|
|
2647
|
+
*/
|
|
2648
|
+
static setWorkspaceContext(workspaceId, projectId) {
|
|
2649
|
+
if (workspaceId !== void 0) {
|
|
2650
|
+
if (workspaceId) {
|
|
2651
|
+
_Client.workspaceHeaders["x-workspace-id"] = workspaceId;
|
|
2652
|
+
} else {
|
|
2653
|
+
delete _Client.workspaceHeaders["x-workspace-id"];
|
|
2654
|
+
}
|
|
2655
|
+
}
|
|
2656
|
+
if (projectId !== void 0) {
|
|
2657
|
+
if (projectId) {
|
|
2658
|
+
_Client.workspaceHeaders["x-project-id"] = projectId;
|
|
2659
|
+
} else {
|
|
2660
|
+
delete _Client.workspaceHeaders["x-project-id"];
|
|
2661
|
+
}
|
|
2662
|
+
}
|
|
2663
|
+
}
|
|
2664
|
+
/**
|
|
2665
|
+
* Get current workspace headers
|
|
2666
|
+
*/
|
|
2667
|
+
static getWorkspaceHeaders() {
|
|
2668
|
+
return { ..._Client.workspaceHeaders };
|
|
2669
|
+
}
|
|
2641
2670
|
/**
|
|
2642
2671
|
* Creates a new instance of the client with the given configuration
|
|
2643
2672
|
* @param config - Configuration options for the client
|
|
2644
2673
|
* @returns A new Client instance
|
|
2645
2674
|
*/
|
|
2646
2675
|
createInstance(config) {
|
|
2647
|
-
return new
|
|
2676
|
+
return new _Client(config);
|
|
2648
2677
|
}
|
|
2649
2678
|
/**
|
|
2650
2679
|
* Implementation of the abstract makeRequest method for web clients
|
|
@@ -2654,8 +2683,10 @@ var Client = class extends AbstractClient {
|
|
|
2654
2683
|
*/
|
|
2655
2684
|
async makeRequest(url, options) {
|
|
2656
2685
|
const method = options?.method || "GET";
|
|
2686
|
+
const workspaceHeaders = _Client.getWorkspaceHeaders();
|
|
2657
2687
|
const requestHeaders = {
|
|
2658
2688
|
...this.headers,
|
|
2689
|
+
...workspaceHeaders,
|
|
2659
2690
|
...options?.headers || {}
|
|
2660
2691
|
};
|
|
2661
2692
|
const requestOptions = {
|
|
@@ -2685,11 +2716,8 @@ var Client = class extends AbstractClient {
|
|
|
2685
2716
|
const headers = {
|
|
2686
2717
|
"Content-Type": "application/json",
|
|
2687
2718
|
Accept: "text/event-stream",
|
|
2688
|
-
...this.
|
|
2719
|
+
...this.getAllHeaders()
|
|
2689
2720
|
};
|
|
2690
|
-
if (this.tenantId) {
|
|
2691
|
-
headers["x-tenant-id"] = this.tenantId;
|
|
2692
|
-
}
|
|
2693
2721
|
const controller = new AbortController();
|
|
2694
2722
|
const { signal } = controller;
|
|
2695
2723
|
(async () => {
|
|
@@ -2776,15 +2804,23 @@ var Client = class extends AbstractClient {
|
|
|
2776
2804
|
* @param onError - Optional callback function called when an error occurs
|
|
2777
2805
|
* @returns A function that can be called to stop the stream
|
|
2778
2806
|
*/
|
|
2807
|
+
/**
|
|
2808
|
+
* Get all headers including workspace context
|
|
2809
|
+
* @private
|
|
2810
|
+
*/
|
|
2811
|
+
getAllHeaders() {
|
|
2812
|
+
const workspaceHeaders = _Client.getWorkspaceHeaders();
|
|
2813
|
+
return {
|
|
2814
|
+
...this.headers,
|
|
2815
|
+
...workspaceHeaders
|
|
2816
|
+
};
|
|
2817
|
+
}
|
|
2779
2818
|
streamRun(options, onEvent, onComplete, onError) {
|
|
2780
2819
|
const headers = {
|
|
2781
2820
|
"Content-Type": "application/json",
|
|
2782
2821
|
Accept: "text/event-stream",
|
|
2783
|
-
...this.
|
|
2822
|
+
...this.getAllHeaders()
|
|
2784
2823
|
};
|
|
2785
|
-
if (this.tenantId) {
|
|
2786
|
-
headers["x-tenant-id"] = this.tenantId;
|
|
2787
|
-
}
|
|
2788
2824
|
const controller = new AbortController();
|
|
2789
2825
|
const { signal } = controller;
|
|
2790
2826
|
(async () => {
|
|
@@ -2869,6 +2905,8 @@ var Client = class extends AbstractClient {
|
|
|
2869
2905
|
};
|
|
2870
2906
|
}
|
|
2871
2907
|
};
|
|
2908
|
+
var Client = _Client;
|
|
2909
|
+
Client.workspaceHeaders = {};
|
|
2872
2910
|
|
|
2873
2911
|
// src/wechat-client.ts
|
|
2874
2912
|
var import_encoding = __toESM(require_encoding());
|
|
@@ -3148,6 +3186,159 @@ var WeChatClient = class extends AbstractClient {
|
|
|
3148
3186
|
}
|
|
3149
3187
|
};
|
|
3150
3188
|
|
|
3189
|
+
// src/workspace-client.ts
|
|
3190
|
+
var WorkspaceClient = class {
|
|
3191
|
+
constructor(config, tenantId = "default") {
|
|
3192
|
+
this.baseURL = config.baseURL;
|
|
3193
|
+
this.headers = {
|
|
3194
|
+
"Content-Type": "application/json",
|
|
3195
|
+
Authorization: `Bearer ${config.apiKey}`,
|
|
3196
|
+
"x-tenant-id": tenantId,
|
|
3197
|
+
...config.headers
|
|
3198
|
+
};
|
|
3199
|
+
}
|
|
3200
|
+
async request(url, options = {}) {
|
|
3201
|
+
const fullUrl = `${this.baseURL}${url}`;
|
|
3202
|
+
const response = await fetch(fullUrl, {
|
|
3203
|
+
...options,
|
|
3204
|
+
headers: {
|
|
3205
|
+
...this.headers,
|
|
3206
|
+
...options.headers
|
|
3207
|
+
}
|
|
3208
|
+
});
|
|
3209
|
+
if (!response.ok) {
|
|
3210
|
+
const err = await response.json().catch(() => ({}));
|
|
3211
|
+
throw new Error(err.message || `HTTP error! Status: ${response.status}`);
|
|
3212
|
+
}
|
|
3213
|
+
return response.json();
|
|
3214
|
+
}
|
|
3215
|
+
// ==================== Workspace CRUD ====================
|
|
3216
|
+
async listWorkspaces() {
|
|
3217
|
+
const response = await this.request("/api/workspaces");
|
|
3218
|
+
return response.data || [];
|
|
3219
|
+
}
|
|
3220
|
+
async createWorkspace(data) {
|
|
3221
|
+
const response = await this.request("/api/workspaces", {
|
|
3222
|
+
method: "POST",
|
|
3223
|
+
body: JSON.stringify(data)
|
|
3224
|
+
});
|
|
3225
|
+
return response.data;
|
|
3226
|
+
}
|
|
3227
|
+
async getWorkspace(workspaceId) {
|
|
3228
|
+
const response = await this.request(`/api/workspaces/${workspaceId}`);
|
|
3229
|
+
return response.data;
|
|
3230
|
+
}
|
|
3231
|
+
async updateWorkspace(workspaceId, updates) {
|
|
3232
|
+
const response = await this.request(
|
|
3233
|
+
`/api/workspaces/${workspaceId}`,
|
|
3234
|
+
{
|
|
3235
|
+
method: "PATCH",
|
|
3236
|
+
body: JSON.stringify(updates)
|
|
3237
|
+
}
|
|
3238
|
+
);
|
|
3239
|
+
return response.data;
|
|
3240
|
+
}
|
|
3241
|
+
async deleteWorkspace(workspaceId) {
|
|
3242
|
+
await this.request(`/api/workspaces/${workspaceId}`, {
|
|
3243
|
+
method: "DELETE"
|
|
3244
|
+
});
|
|
3245
|
+
}
|
|
3246
|
+
// ==================== Project CRUD ====================
|
|
3247
|
+
async listProjects(workspaceId) {
|
|
3248
|
+
const response = await this.request(
|
|
3249
|
+
`/api/workspaces/${workspaceId}/projects`
|
|
3250
|
+
);
|
|
3251
|
+
return response.data || [];
|
|
3252
|
+
}
|
|
3253
|
+
async createProject(workspaceId, data) {
|
|
3254
|
+
const response = await this.request(
|
|
3255
|
+
`/api/workspaces/${workspaceId}/projects`,
|
|
3256
|
+
{
|
|
3257
|
+
method: "POST",
|
|
3258
|
+
body: JSON.stringify(data)
|
|
3259
|
+
}
|
|
3260
|
+
);
|
|
3261
|
+
return response.data;
|
|
3262
|
+
}
|
|
3263
|
+
async getProject(workspaceId, projectId) {
|
|
3264
|
+
const response = await this.request(
|
|
3265
|
+
`/api/workspaces/${workspaceId}/projects/${projectId}`
|
|
3266
|
+
);
|
|
3267
|
+
return response.data;
|
|
3268
|
+
}
|
|
3269
|
+
async updateProject(workspaceId, projectId, updates) {
|
|
3270
|
+
const response = await this.request(
|
|
3271
|
+
`/api/workspaces/${workspaceId}/projects/${projectId}`,
|
|
3272
|
+
{
|
|
3273
|
+
method: "PATCH",
|
|
3274
|
+
body: JSON.stringify(updates)
|
|
3275
|
+
}
|
|
3276
|
+
);
|
|
3277
|
+
return response.data;
|
|
3278
|
+
}
|
|
3279
|
+
async deleteProject(workspaceId, projectId) {
|
|
3280
|
+
await this.request(
|
|
3281
|
+
`/api/workspaces/${workspaceId}/projects/${projectId}`,
|
|
3282
|
+
{
|
|
3283
|
+
method: "DELETE"
|
|
3284
|
+
}
|
|
3285
|
+
);
|
|
3286
|
+
}
|
|
3287
|
+
// ==================== File Operations ====================
|
|
3288
|
+
async listPath(workspaceId, projectId, path = "/") {
|
|
3289
|
+
const response = await this.request(
|
|
3290
|
+
`/api/workspaces/${workspaceId}/projects/${projectId}/listpath?path=${encodeURIComponent(path)}`
|
|
3291
|
+
);
|
|
3292
|
+
return response.data || [];
|
|
3293
|
+
}
|
|
3294
|
+
async readFile(workspaceId, projectId, path, offset = 0, limit = 1e3) {
|
|
3295
|
+
const params = new URLSearchParams({
|
|
3296
|
+
path,
|
|
3297
|
+
offset: String(offset),
|
|
3298
|
+
limit: String(limit)
|
|
3299
|
+
});
|
|
3300
|
+
const response = await this.request(
|
|
3301
|
+
`/api/workspaces/${workspaceId}/projects/${projectId}/readfile?${params}`
|
|
3302
|
+
);
|
|
3303
|
+
return response.data;
|
|
3304
|
+
}
|
|
3305
|
+
/**
|
|
3306
|
+
* Upload a file to the workspace project storage.
|
|
3307
|
+
*
|
|
3308
|
+
* Uses multipart/form-data against:
|
|
3309
|
+
* POST /api/workspaces/:workspaceId/projects/:projectId/uploadfile
|
|
3310
|
+
*/
|
|
3311
|
+
async uploadFile(workspaceId, projectId, file, path = "/") {
|
|
3312
|
+
const url = `/api/workspaces/${workspaceId}/projects/${projectId}/uploadfile`;
|
|
3313
|
+
const fullUrl = `${this.baseURL}${url}`;
|
|
3314
|
+
const formData = new FormData();
|
|
3315
|
+
const filename = file.name && typeof file.name === "string" ? file.name : "file";
|
|
3316
|
+
formData.append("file", file, filename);
|
|
3317
|
+
formData.append("path", path);
|
|
3318
|
+
const headers = { ...this.headers };
|
|
3319
|
+
delete headers["Content-Type"];
|
|
3320
|
+
const response = await fetch(fullUrl, {
|
|
3321
|
+
method: "POST",
|
|
3322
|
+
headers,
|
|
3323
|
+
body: formData
|
|
3324
|
+
});
|
|
3325
|
+
if (!response.ok) {
|
|
3326
|
+
const err = await response.json().catch(() => ({}));
|
|
3327
|
+
throw new Error(
|
|
3328
|
+
err.error || err.message || `HTTP error! Status: ${response.status}`
|
|
3329
|
+
);
|
|
3330
|
+
}
|
|
3331
|
+
const json = await response.json();
|
|
3332
|
+
if (!json.success || !json.data) {
|
|
3333
|
+
throw new Error(json.error || "Upload failed");
|
|
3334
|
+
}
|
|
3335
|
+
return json.data;
|
|
3336
|
+
}
|
|
3337
|
+
getFileDownloadUrl(workspaceId, projectId, filePath) {
|
|
3338
|
+
return `${this.baseURL}/api/workspaces/${workspaceId}/projects/${projectId}/downloadfile?path=${encodeURIComponent(filePath)}`;
|
|
3339
|
+
}
|
|
3340
|
+
};
|
|
3341
|
+
|
|
3151
3342
|
// src/ChunkMessageMerger.ts
|
|
3152
3343
|
import { parse } from "best-effort-json-parser";
|
|
3153
3344
|
function createSimpleMessageMerger() {
|
|
@@ -3363,6 +3554,7 @@ export {
|
|
|
3363
3554
|
ScheduleExecutionType,
|
|
3364
3555
|
ScheduledTaskStatus,
|
|
3365
3556
|
WeChatClient,
|
|
3557
|
+
WorkspaceClient,
|
|
3366
3558
|
createSimpleMessageMerger
|
|
3367
3559
|
};
|
|
3368
3560
|
//# sourceMappingURL=index.mjs.map
|