@axiom-lattice/client-sdk 4.1.0 → 4.2.1

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/index.mjs CHANGED
@@ -2200,6 +2200,127 @@ var AbstractClient = class {
2200
2200
  return response.data;
2201
2201
  }
2202
2202
  };
2203
+ /** Capability bundle namespace for managing tenant-scoped bundles. */
2204
+ this.capabilityBundles = {
2205
+ /**
2206
+ * List all capability bundles visible to the current tenant.
2207
+ * @returns The tenant's capability bundles, unwrapped from the API response.
2208
+ */
2209
+ list: async () => {
2210
+ const response = await this.makeRequest(
2211
+ "/api/capability-bundles"
2212
+ );
2213
+ return response.data;
2214
+ },
2215
+ /**
2216
+ * List valid bundles together with safe invalid-record summaries.
2217
+ * @returns Inventory suitable for management and remediation workflows.
2218
+ */
2219
+ listInventory: async () => {
2220
+ const response = await this.makeRequest("/api/capability-bundles");
2221
+ return { bundles: response.data, errors: response.errors ?? [] };
2222
+ },
2223
+ /**
2224
+ * Get one capability bundle by identifier.
2225
+ * @param bundleId - Capability bundle identifier.
2226
+ * @returns The requested capability bundle.
2227
+ */
2228
+ get: async (bundleId) => {
2229
+ const response = await this.makeRequest(
2230
+ `/api/capability-bundles/${encodeURIComponent(bundleId)}`
2231
+ );
2232
+ return response.data;
2233
+ },
2234
+ /**
2235
+ * Create a capability bundle for the current tenant.
2236
+ * @param input - Bundle name, optional description, and capabilities. The server generates the stable key.
2237
+ * @returns The created capability bundle.
2238
+ */
2239
+ create: async (input) => {
2240
+ const response = await this.makeRequest(
2241
+ "/api/capability-bundles",
2242
+ { method: "POST", body: input }
2243
+ );
2244
+ return response.data;
2245
+ },
2246
+ /**
2247
+ * Update a capability bundle for the current tenant.
2248
+ * @param bundleId - Capability bundle identifier.
2249
+ * @param input - The partial bundle fields and required expected revision to update.
2250
+ * @returns The updated capability bundle.
2251
+ */
2252
+ update: async (bundleId, input) => {
2253
+ const response = await this.makeRequest(
2254
+ `/api/capability-bundles/${encodeURIComponent(bundleId)}`,
2255
+ { method: "PUT", body: input }
2256
+ );
2257
+ return response.data;
2258
+ },
2259
+ /**
2260
+ * Delete a capability bundle when the backend permits deletion.
2261
+ * @param bundleId - Capability bundle identifier.
2262
+ * @returns A promise that resolves after the bundle is deleted.
2263
+ * @throws ApiError when the bundle is missing, in use, or the request fails.
2264
+ */
2265
+ delete: async (bundleId) => {
2266
+ await this.makeRequest(
2267
+ `/api/capability-bundles/${encodeURIComponent(bundleId)}`,
2268
+ { method: "DELETE" }
2269
+ );
2270
+ }
2271
+ };
2272
+ this.projects = {
2273
+ capabilities: {
2274
+ /**
2275
+ * Get a project's selected bundles and its persisted capability preview.
2276
+ * @param projectId - Project identifier.
2277
+ * @returns The project, selected bundles, and preview resolved from persisted selections.
2278
+ */
2279
+ get: async (projectId) => {
2280
+ const response = await this.makeRequest(
2281
+ `/api/projects/${encodeURIComponent(projectId)}/capability-bundles`
2282
+ );
2283
+ return response.data;
2284
+ },
2285
+ /**
2286
+ * Replace a project's selected capability bundles.
2287
+ * @param projectId - Project identifier.
2288
+ * @param bundleIds - Ordered capability bundle identifiers to persist.
2289
+ * @returns The updated project, selected bundles, and persisted-selection preview.
2290
+ */
2291
+ update: async (projectId, bundleIds, expectedRevisions) => {
2292
+ const response = await this.makeRequest(
2293
+ `/api/projects/${encodeURIComponent(projectId)}/capability-bundles`,
2294
+ { method: "PUT", body: { bundleIds, expectedRevisions } }
2295
+ );
2296
+ return response.data;
2297
+ },
2298
+ /**
2299
+ * Preview the capability bundles currently persisted on a project.
2300
+ * @param projectId - Project identifier.
2301
+ * @returns The preview resolved from the project's persisted bundle selections.
2302
+ */
2303
+ preview: async (projectId) => {
2304
+ const response = await this.makeRequest(
2305
+ `/api/projects/${encodeURIComponent(projectId)}/capability-preview`
2306
+ );
2307
+ return response.data;
2308
+ },
2309
+ /**
2310
+ * Preview a draft bundle selection without changing the project.
2311
+ * @param projectId - Project identifier.
2312
+ * @param bundleIds - Ordered capability bundle identifiers to preview.
2313
+ * @returns The draft preview resolved from the supplied bundle IDs; no project state is changed.
2314
+ */
2315
+ previewWithBundles: async (projectId, bundleIds) => {
2316
+ const response = await this.makeRequest(
2317
+ `/api/projects/${encodeURIComponent(projectId)}/capability-preview`,
2318
+ { method: "POST", body: { bundleIds } }
2319
+ );
2320
+ return response.data;
2321
+ }
2322
+ }
2323
+ };
2203
2324
  /** Agent Web Apps namespace for managing React SDK publications. */
2204
2325
  this.webApps = {
2205
2326
  /**
@@ -3618,25 +3739,59 @@ var _Client = class extends AbstractClient {
3618
3739
  const reader = res.body.getReader();
3619
3740
  const decoder = new TextDecoder();
3620
3741
  let buffer = "";
3742
+ let event = "";
3743
+ let dataLines = [];
3744
+ const processLine = (rawLine) => {
3745
+ const line = rawLine.endsWith("\r") ? rawLine.slice(0, -1) : rawLine;
3746
+ if (line === "") {
3747
+ if (dataLines.length === 0) {
3748
+ event = "";
3749
+ return null;
3750
+ }
3751
+ const data = dataLines.join("\n");
3752
+ const eventName = event;
3753
+ event = "";
3754
+ dataLines = [];
3755
+ try {
3756
+ return { event: eventName, data: JSON.parse(data) };
3757
+ } catch {
3758
+ return null;
3759
+ }
3760
+ }
3761
+ if (line.startsWith(":"))
3762
+ return null;
3763
+ const separator = line.indexOf(":");
3764
+ const field = separator === -1 ? line : line.slice(0, separator);
3765
+ let value = separator === -1 ? "" : line.slice(separator + 1);
3766
+ if (value.startsWith(" "))
3767
+ value = value.slice(1);
3768
+ if (field === "event")
3769
+ event = value;
3770
+ else if (field === "data")
3771
+ dataLines.push(value);
3772
+ return null;
3773
+ };
3621
3774
  while (true) {
3622
3775
  const { done, value } = await reader.read();
3623
- if (done)
3776
+ if (done) {
3777
+ buffer += decoder.decode();
3624
3778
  break;
3779
+ }
3625
3780
  buffer += decoder.decode(value, { stream: true });
3626
- const lines = buffer.split("\n");
3627
- buffer = lines.pop() || "";
3628
- let event = "";
3629
- for (const line of lines) {
3630
- if (line.startsWith("event: ")) {
3631
- event = line.slice(7);
3632
- } else if (line.startsWith("data: ")) {
3633
- try {
3634
- yield { event, data: JSON.parse(line.slice(6)) };
3635
- } catch {
3636
- }
3637
- }
3781
+ let newline = buffer.indexOf("\n");
3782
+ while (newline !== -1) {
3783
+ const parsed = processLine(buffer.slice(0, newline));
3784
+ buffer = buffer.slice(newline + 1);
3785
+ if (parsed)
3786
+ yield parsed;
3787
+ newline = buffer.indexOf("\n");
3638
3788
  }
3639
3789
  }
3790
+ if (buffer.length > 0)
3791
+ processLine(buffer);
3792
+ const finalEvent = processLine("");
3793
+ if (finalEvent)
3794
+ yield finalEvent;
3640
3795
  }
3641
3796
  /**
3642
3797
  * Get all headers including workspace context
@@ -3762,6 +3917,32 @@ var WeChatClient = class extends AbstractClient {
3762
3917
  setTenantId(tenantId) {
3763
3918
  this.tenantId = tenantId;
3764
3919
  }
3920
+ /**
3921
+ * Set workspace and project headers for requests made by this client.
3922
+ * @param workspaceId - Workspace identifier, or undefined to leave it unchanged
3923
+ * @param projectId - Project identifier, or undefined to leave it unchanged
3924
+ */
3925
+ setWorkspaceContext(workspaceId, projectId) {
3926
+ if (workspaceId !== void 0) {
3927
+ if (workspaceId)
3928
+ this.workspaceHeaders["x-workspace-id"] = workspaceId;
3929
+ else
3930
+ delete this.workspaceHeaders["x-workspace-id"];
3931
+ }
3932
+ if (projectId !== void 0) {
3933
+ if (projectId)
3934
+ this.workspaceHeaders["x-project-id"] = projectId;
3935
+ else
3936
+ delete this.workspaceHeaders["x-project-id"];
3937
+ }
3938
+ }
3939
+ /**
3940
+ * Get the workspace and project headers currently applied to this client.
3941
+ * @returns A copy of the current workspace and project header values
3942
+ */
3943
+ getWorkspaceHeaders() {
3944
+ return { ...this.workspaceHeaders };
3945
+ }
3765
3946
  /**
3766
3947
  * Creates a new instance of the client with the given configuration
3767
3948
  * @param config - Configuration options for the client
@@ -3792,7 +3973,8 @@ var WeChatClient = class extends AbstractClient {
3792
3973
  return this.wechatRequest({
3793
3974
  url: fullUrl,
3794
3975
  method,
3795
- data: options?.body
3976
+ data: options?.body,
3977
+ headers: this.getWorkspaceHeaders()
3796
3978
  });
3797
3979
  }
3798
3980
  /**
@@ -3872,11 +4054,12 @@ var WeChatClient = class extends AbstractClient {
3872
4054
  * @private
3873
4055
  */
3874
4056
  async wechatRequest(options) {
3875
- const { url, method, data } = options;
4057
+ const { url, method, data, headers: requestHeaders } = options;
3876
4058
  const headers = {
3877
4059
  "Content-Type": "application/json",
3878
4060
  Authorization: `Bearer ${this.config.apiKey}`,
3879
- ...this.config.headers
4061
+ ...this.config.headers,
4062
+ ...requestHeaders
3880
4063
  };
3881
4064
  if (this.tenantId) {
3882
4065
  headers["x-tenant-id"] = this.tenantId;
@@ -4200,6 +4383,33 @@ var WorkspaceClient = class {
4200
4383
  }
4201
4384
  return `${this.baseURL}/api/workspaces/${workspaceId}/projects/${projectId}/downloadfile?${params}`;
4202
4385
  }
4386
+ /**
4387
+ * Download a project folder as an authenticated ZIP Blob.
4388
+ *
4389
+ * The request is scoped by this client's bearer token and tenant headers;
4390
+ * callers are responsible for triggering browser download behavior.
4391
+ *
4392
+ * @param workspaceId - Workspace identifier.
4393
+ * @param projectId - Project identifier.
4394
+ * @param folderPath - Backend folder path to archive.
4395
+ * @param assistantId - Optional sandbox assistant context.
4396
+ * @returns The ZIP response as a Blob.
4397
+ * @throws Error when the authenticated request fails.
4398
+ */
4399
+ async downloadFolder(workspaceId, projectId, folderPath, assistantId) {
4400
+ const params = new URLSearchParams({ path: folderPath, tenantId: this.tenantId });
4401
+ if (assistantId)
4402
+ params.set("assistantId", assistantId);
4403
+ const response = await fetch(
4404
+ `${this.baseURL}/api/workspaces/${workspaceId}/projects/${projectId}/downloadfolder?${params}`,
4405
+ { headers: this.headers }
4406
+ );
4407
+ if (!response.ok) {
4408
+ const error = await response.json().catch(() => ({}));
4409
+ throw new Error(error.error || error.message || `HTTP error! Status: ${response.status}`);
4410
+ }
4411
+ return response.blob();
4412
+ }
4203
4413
  /**
4204
4414
  * Get a URL for viewing a file inline in the browser (not download).
4205
4415
  * The file will be displayed in the browser rather than downloaded.