@distri/core 0.3.2 → 0.3.3

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
@@ -770,6 +770,7 @@ function convertDistriMessageToA2A(distriMessage, context) {
770
770
  break;
771
771
  case "system":
772
772
  case "tool":
773
+ case "developer":
773
774
  role = "user";
774
775
  break;
775
776
  default:
@@ -866,6 +867,9 @@ var _DistriClient = class _DistriClient {
866
867
  constructor(config) {
867
868
  this.agentClients = /* @__PURE__ */ new Map();
868
869
  const headers = { ...config.headers };
870
+ if (config.workspaceId) {
871
+ headers["X-Workspace-Id"] = config.workspaceId;
872
+ }
869
873
  this.accessToken = config.accessToken;
870
874
  this.refreshToken = config.refreshToken;
871
875
  this.tokenRefreshSkewMs = config.tokenRefreshSkewMs ?? 6e4;
@@ -880,7 +884,8 @@ var _DistriClient = class _DistriClient {
880
884
  headers,
881
885
  interceptor: config.interceptor ?? (async (init) => Promise.resolve(init)),
882
886
  onTokenRefresh: config.onTokenRefresh,
883
- clientId: config.clientId
887
+ clientId: config.clientId,
888
+ workspaceId: config.workspaceId
884
889
  };
885
890
  }
886
891
  /**
@@ -895,6 +900,24 @@ var _DistriClient = class _DistriClient {
895
900
  set clientId(value) {
896
901
  this.config.clientId = value;
897
902
  }
903
+ /**
904
+ * Get the configured workspace ID.
905
+ */
906
+ get workspaceId() {
907
+ return this.config.workspaceId;
908
+ }
909
+ /**
910
+ * Set the workspace ID for multi-tenant support.
911
+ * Updates the X-Workspace-Id header for all subsequent requests.
912
+ */
913
+ set workspaceId(value) {
914
+ this.config.workspaceId = value;
915
+ if (value) {
916
+ this.config.headers["X-Workspace-Id"] = value;
917
+ } else {
918
+ delete this.config.headers["X-Workspace-Id"];
919
+ }
920
+ }
898
921
  /**
899
922
  * Create a client with default cloud configuration.
900
923
  *
@@ -1347,8 +1370,46 @@ var _DistriClient = class _DistriClient {
1347
1370
  yield* await client.sendMessageStream(params);
1348
1371
  } catch (error) {
1349
1372
  console.error(error);
1350
- throw new DistriError(`Failed to stream message to agent ${agentId}`, "STREAM_MESSAGE_ERROR", error);
1373
+ const errorMessage = this.extractErrorMessage(error);
1374
+ throw new DistriError(errorMessage, "STREAM_MESSAGE_ERROR", error);
1375
+ }
1376
+ }
1377
+ /**
1378
+ * Extract a user-friendly error message from potentially nested errors
1379
+ */
1380
+ extractErrorMessage(error) {
1381
+ if (!error) return "Unknown error occurred";
1382
+ if (typeof error === "object" && error !== null) {
1383
+ const err = error;
1384
+ if (err.error && typeof err.error === "object") {
1385
+ const jsonRpcError = err.error;
1386
+ if (typeof jsonRpcError.message === "string") {
1387
+ return jsonRpcError.message;
1388
+ }
1389
+ }
1390
+ if (err.message && typeof err.message === "string") {
1391
+ return err.message;
1392
+ }
1393
+ if (err.details && typeof err.details === "object") {
1394
+ const details = err.details;
1395
+ if (details.message && typeof details.message === "string") {
1396
+ return details.message;
1397
+ }
1398
+ if (details.error && typeof details.error === "object") {
1399
+ const nestedError = details.error;
1400
+ if (typeof nestedError.message === "string") {
1401
+ return nestedError.message;
1402
+ }
1403
+ }
1404
+ }
1405
+ if (err.cause && typeof err.cause === "object") {
1406
+ return this.extractErrorMessage(err.cause);
1407
+ }
1408
+ }
1409
+ if (error instanceof Error) {
1410
+ return error.message;
1351
1411
  }
1412
+ return String(error);
1352
1413
  }
1353
1414
  /**
1354
1415
  * Get task details