@axiom-lattice/client-sdk 4.3.4 → 4.3.7

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.
Files changed (43) hide show
  1. package/dist/__tests__/project-rooms.test.js +0 -66
  2. package/dist/__tests__/project-rooms.test.js.map +1 -1
  3. package/dist/__tests__/room-events.test.d.ts +2 -0
  4. package/dist/__tests__/room-events.test.d.ts.map +1 -0
  5. package/dist/__tests__/room-events.test.js +144 -0
  6. package/dist/__tests__/room-events.test.js.map +1 -0
  7. package/dist/__tests__/workspace-rooms.test.d.ts +2 -0
  8. package/dist/__tests__/workspace-rooms.test.d.ts.map +1 -0
  9. package/dist/__tests__/workspace-rooms.test.js +116 -0
  10. package/dist/__tests__/workspace-rooms.test.js.map +1 -0
  11. package/dist/abstract-client.d.ts +38 -1
  12. package/dist/abstract-client.d.ts.map +1 -1
  13. package/dist/abstract-client.js +56 -0
  14. package/dist/abstract-client.js.map +1 -1
  15. package/dist/client.d.ts +4 -0
  16. package/dist/client.d.ts.map +1 -1
  17. package/dist/client.js +4 -0
  18. package/dist/client.js.map +1 -1
  19. package/dist/index.d.ts +211 -50
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +359 -183
  22. package/dist/index.js.map +1 -1
  23. package/dist/index.mjs +357 -183
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/project-room-hydrators.d.ts +18 -0
  26. package/dist/project-room-hydrators.d.ts.map +1 -0
  27. package/dist/project-room-hydrators.js +95 -0
  28. package/dist/project-room-hydrators.js.map +1 -0
  29. package/dist/project-rooms.d.ts +4 -51
  30. package/dist/project-rooms.d.ts.map +1 -1
  31. package/dist/project-rooms.js +5 -178
  32. package/dist/project-rooms.js.map +1 -1
  33. package/dist/room-events.d.ts +108 -0
  34. package/dist/room-events.d.ts.map +1 -0
  35. package/dist/room-events.js +127 -0
  36. package/dist/room-events.js.map +1 -0
  37. package/dist/types.d.ts +35 -1
  38. package/dist/types.d.ts.map +1 -1
  39. package/dist/workspace-rooms.d.ts +28 -0
  40. package/dist/workspace-rooms.d.ts.map +1 -0
  41. package/dist/workspace-rooms.js +68 -0
  42. package/dist/workspace-rooms.js.map +1 -0
  43. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1837,11 +1837,13 @@ __export(src_exports, {
1837
1837
  ProjectRoomClientError: () => ProjectRoomClientError,
1838
1838
  ProjectRoomsClient: () => ProjectRoomsClient,
1839
1839
  ResourcesClient: () => ResourcesClient,
1840
+ RoomEventsClient: () => RoomEventsClient,
1840
1841
  RuntimeAxiomClient: () => RuntimeAxiomClient,
1841
1842
  ScheduleExecutionType: () => ScheduleExecutionType,
1842
1843
  ScheduledTaskStatus: () => ScheduledTaskStatus,
1843
1844
  WeChatClient: () => WeChatClient,
1844
1845
  WorkspaceClient: () => WorkspaceClient,
1846
+ WorkspaceRoomsClient: () => WorkspaceRoomsClient,
1845
1847
  createSimpleMessageMerger: () => createSimpleMessageMerger
1846
1848
  });
1847
1849
  module.exports = __toCommonJS(src_exports);
@@ -2159,6 +2161,52 @@ var AbstractClient = class {
2159
2161
  /**
2160
2162
  * A2A API keys namespace for managing A2A API keys
2161
2163
  */
2164
+ /** Open API surface helpers (capability catalog for the key picker). */
2165
+ this.open = {
2166
+ /**
2167
+ * Fetch the grantable capability catalog for the current tenant.
2168
+ * Drives the key-management grants picker.
2169
+ */
2170
+ catalog: async () => {
2171
+ const response = await this.makeRequest("/api/open/catalog");
2172
+ return response.data;
2173
+ },
2174
+ /**
2175
+ * Fetch what a key exposes (MCP tools + A2A agent cards).
2176
+ * @param id - Key identifier
2177
+ */
2178
+ exposure: async (id) => {
2179
+ const response = await this.makeRequest(`/api/keys/${id}/exposure`);
2180
+ return response.data;
2181
+ },
2182
+ /**
2183
+ * Query the tenant's Open audit log (newest first).
2184
+ * @param params - Optional credential/domain/status/time filters and pagination
2185
+ */
2186
+ auditLogs: async (params) => {
2187
+ const searchParams = new URLSearchParams();
2188
+ if (params?.credentialId)
2189
+ searchParams.set("credentialId", params.credentialId);
2190
+ if (params?.domain)
2191
+ searchParams.set("domain", params.domain);
2192
+ if (params?.status)
2193
+ searchParams.set("status", params.status);
2194
+ if (params?.from)
2195
+ searchParams.set("from", params.from);
2196
+ if (params?.to)
2197
+ searchParams.set("to", params.to);
2198
+ if (params?.limit !== void 0)
2199
+ searchParams.set("limit", String(params.limit));
2200
+ if (params?.offset !== void 0)
2201
+ searchParams.set("offset", String(params.offset));
2202
+ const qs = searchParams.toString();
2203
+ const response = await this.makeRequest(`/api/open/audit${qs ? `?${qs}` : ""}`);
2204
+ return response.data.records;
2205
+ }
2206
+ };
2207
+ /**
2208
+ * @deprecated Use {@link open} / `/api/keys`; kept as a compatibility alias.
2209
+ */
2162
2210
  this.a2aKeys = {
2163
2211
  /**
2164
2212
  * Lists A2A API keys, optionally filtered by tenant
@@ -2188,6 +2236,16 @@ var AbstractClient = class {
2188
2236
  const response = await this.makeRequest("/api/a2a/keys", { method: "POST", body: input });
2189
2237
  return response.data;
2190
2238
  },
2239
+ /**
2240
+ * Updates mutable fields (label, project, assistants, grants) of an existing key.
2241
+ * @param id - Key identifier
2242
+ * @param input - Fields to update (only provided fields change)
2243
+ * @returns A promise that resolves to the updated key record
2244
+ */
2245
+ update: async (id, input) => {
2246
+ const response = await this.makeRequest(`/api/a2a/keys/${id}`, { method: "PATCH", body: input });
2247
+ return response.data;
2248
+ },
2191
2249
  /**
2192
2250
  * Permanently deletes an A2A API key
2193
2251
  * @param id - Key identifier
@@ -2363,7 +2421,7 @@ var AbstractClient = class {
2363
2421
  const query = searchParams.toString();
2364
2422
  const response = await this.makeRequest(`/api/web-apps${query ? `?${query}` : ""}`);
2365
2423
  return {
2366
- records: response.data.records.map((record2) => this.hydrateAgentWebApp(record2)),
2424
+ records: response.data.records.map((record3) => this.hydrateAgentWebApp(record3)),
2367
2425
  total: response.data.total
2368
2426
  };
2369
2427
  },
@@ -3004,19 +3062,19 @@ var AbstractClient = class {
3004
3062
  if (!value || typeof value !== "object" || Array.isArray(value)) {
3005
3063
  throw new ApiError("Invalid Agent Web App response", 500, value);
3006
3064
  }
3007
- const record2 = value;
3065
+ const record3 = value;
3008
3066
  const hydrateDate = (field) => {
3009
- const raw = record2[field];
3010
- const date2 = raw instanceof Date ? new Date(raw.getTime()) : new Date(
3067
+ const raw = record3[field];
3068
+ const date3 = raw instanceof Date ? new Date(raw.getTime()) : new Date(
3011
3069
  typeof raw === "string" || typeof raw === "number" ? raw : Number.NaN
3012
3070
  );
3013
- if (Number.isNaN(date2.getTime())) {
3071
+ if (Number.isNaN(date3.getTime())) {
3014
3072
  throw new ApiError(`Invalid Agent Web App ${field}`, 500, value);
3015
3073
  }
3016
- return date2;
3074
+ return date3;
3017
3075
  };
3018
3076
  return {
3019
- ...record2,
3077
+ ...record3,
3020
3078
  createdAt: hydrateDate("createdAt"),
3021
3079
  updatedAt: hydrateDate("updatedAt")
3022
3080
  };
@@ -3456,115 +3514,7 @@ var ExportImportClient = class {
3456
3514
  }
3457
3515
  };
3458
3516
 
3459
- // src/sse-parser.ts
3460
- var SseParseError = class extends Error {
3461
- constructor(message) {
3462
- super(message);
3463
- this.code = "INVALID_EVENT";
3464
- this.name = "SseParseError";
3465
- }
3466
- };
3467
- async function* parseSseBody(body, options = {}) {
3468
- const reader = body.getReader();
3469
- const decoder = new TextDecoder();
3470
- let buffer = "";
3471
- let event = "";
3472
- let id;
3473
- let retry;
3474
- let data = [];
3475
- const dispatch = () => {
3476
- if (data.length === 0) {
3477
- event = "";
3478
- id = void 0;
3479
- retry = void 0;
3480
- return void 0;
3481
- }
3482
- let parsed;
3483
- try {
3484
- parsed = JSON.parse(data.join("\n"));
3485
- } catch {
3486
- throw new SseParseError("Invalid SSE JSON");
3487
- }
3488
- if (options.strictJsonObject && (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)))
3489
- throw new SseParseError("SSE data must be an object");
3490
- const result = { event, data: parsed, ...id === void 0 ? {} : { id }, ...retry === void 0 ? {} : { retry } };
3491
- event = "";
3492
- id = void 0;
3493
- retry = void 0;
3494
- data = [];
3495
- return result;
3496
- };
3497
- const processLine = (raw) => {
3498
- const line = raw.endsWith("\r") ? raw.slice(0, -1) : raw;
3499
- if (line === "")
3500
- return dispatch();
3501
- if (line.startsWith(":"))
3502
- return void 0;
3503
- const separator = line.indexOf(":");
3504
- const field = separator < 0 ? line : line.slice(0, separator);
3505
- let value = separator < 0 ? "" : line.slice(separator + 1);
3506
- if (value.startsWith(" "))
3507
- value = value.slice(1);
3508
- if (field === "event")
3509
- event = value;
3510
- else if (field === "data")
3511
- data.push(value);
3512
- else if (field === "id")
3513
- id = value;
3514
- else if (field === "retry") {
3515
- const parsed = Number(value);
3516
- if (!Number.isInteger(parsed) || parsed < 0 || !Number.isFinite(parsed))
3517
- throw new SseParseError("Invalid SSE retry");
3518
- retry = parsed;
3519
- }
3520
- return void 0;
3521
- };
3522
- try {
3523
- while (true) {
3524
- const chunk = await reader.read();
3525
- if (chunk.done) {
3526
- buffer += decoder.decode();
3527
- break;
3528
- }
3529
- buffer += decoder.decode(chunk.value, { stream: true });
3530
- let index = findLineBreak(buffer);
3531
- while (index >= 0) {
3532
- if (buffer[index] === "\r" && index === buffer.length - 1)
3533
- break;
3534
- const frame2 = processLine(buffer.slice(0, index));
3535
- buffer = buffer.slice(index + lineBreakLength(buffer, index));
3536
- if (frame2)
3537
- yield frame2;
3538
- index = findLineBreak(buffer);
3539
- }
3540
- }
3541
- if (buffer) {
3542
- const frame2 = processLine(buffer);
3543
- if (frame2)
3544
- yield frame2;
3545
- }
3546
- const frame = processLine("");
3547
- if (frame)
3548
- yield frame;
3549
- } finally {
3550
- await reader.cancel().catch(() => void 0);
3551
- reader.releaseLock();
3552
- }
3553
- }
3554
- function findLineBreak(value) {
3555
- const lf = value.indexOf("\n");
3556
- const cr = value.indexOf("\r");
3557
- if (lf < 0)
3558
- return cr;
3559
- if (cr < 0)
3560
- return lf;
3561
- return Math.min(lf, cr);
3562
- }
3563
- function lineBreakLength(value, index) {
3564
- return value[index] === "\r" && value[index + 1] === "\n" ? 2 : 1;
3565
- }
3566
-
3567
- // src/project-rooms.ts
3517
+ // src/project-room-hydrators.ts
3568
3518
  var ProjectRoomClientError = class extends Error {
3569
3519
  constructor(message, status, code, retryable, details) {
3570
3520
  super(message);
@@ -3582,10 +3532,10 @@ var date = (value, field) => {
3582
3532
  throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
3583
3533
  return result;
3584
3534
  };
3585
- var requiredString = (record2, field) => {
3586
- if (typeof record2[field] !== "string")
3535
+ var requiredString = (record3, field) => {
3536
+ if (typeof record3[field] !== "string")
3587
3537
  throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
3588
- return record2[field];
3538
+ return record3[field];
3589
3539
  };
3590
3540
  var oneOf = (value, values, field) => {
3591
3541
  if (typeof value !== "string" || !values.includes(value))
@@ -3648,21 +3598,31 @@ var hydrateMessage = (value) => {
3648
3598
  };
3649
3599
  var hydrateMember = (value) => {
3650
3600
  const row = record(value);
3651
- exactKeys(row, ["id", "tenantId", "projectId", "userId", "role", "status", "joinedAt", "updatedAt"]);
3652
- return { id: requiredString(row, "id"), tenantId: requiredString(row, "tenantId"), projectId: requiredString(row, "projectId"), userId: requiredString(row, "userId"), role: oneOf(row.role, humanRoles, "role"), status: oneOf(row.status, memberStatuses, "status"), joinedAt: date(row.joinedAt, "joinedAt"), updatedAt: date(row.updatedAt, "updatedAt") };
3601
+ exactKeys(row, ["id", "tenantId", "projectId", "userId", "role", "status", "joinedAt", "updatedAt"], ["name"]);
3602
+ return { id: requiredString(row, "id"), tenantId: requiredString(row, "tenantId"), projectId: requiredString(row, "projectId"), userId: requiredString(row, "userId"), ...row.name === void 0 ? {} : { name: requiredString(row, "name") }, role: oneOf(row.role, humanRoles, "role"), status: oneOf(row.status, memberStatuses, "status"), joinedAt: date(row.joinedAt, "joinedAt"), updatedAt: date(row.updatedAt, "updatedAt") };
3653
3603
  };
3654
3604
  var hydrateBot = (value) => {
3655
3605
  const row = record(value);
3656
3606
  exactKeys(row, ["id", "tenantId", "workspaceId", "projectId", "roomId", "assistantId", "role", "title", "mentionName", "status", "roomThreadId", "joinedAt", "updatedAt"], ["responsibility"]);
3657
3607
  return { id: requiredString(row, "id"), tenantId: requiredString(row, "tenantId"), workspaceId: requiredString(row, "workspaceId"), projectId: requiredString(row, "projectId"), roomId: requiredString(row, "roomId"), assistantId: requiredString(row, "assistantId"), role: oneOf(row.role, botRoles, "role"), title: requiredString(row, "title"), ...row.responsibility === void 0 ? {} : { responsibility: requiredString(row, "responsibility") }, mentionName: requiredString(row, "mentionName"), status: oneOf(row.status, botStatuses, "status"), roomThreadId: requiredString(row, "roomThreadId"), joinedAt: date(row.joinedAt, "joinedAt"), updatedAt: date(row.updatedAt, "updatedAt") };
3658
3608
  };
3659
- var iso = (value) => date(value, "date").toISOString();
3660
3609
  var hydrateDispatch = (value) => {
3661
3610
  const row = record(value);
3662
3611
  if (typeof row.success !== "boolean" || row.membershipId !== void 0 && typeof row.membershipId !== "string" || row.errorCode !== void 0 && typeof row.errorCode !== "string")
3663
3612
  throw new ProjectRoomClientError("Invalid dispatch response", 500, "INVALID_RESPONSE", false);
3664
3613
  return { success: row.success, ...row.membershipId === void 0 ? {} : { membershipId: row.membershipId }, ...row.errorCode === void 0 ? {} : { errorCode: row.errorCode } };
3665
3614
  };
3615
+ function hydratePublicMember(value) {
3616
+ const row = record(value);
3617
+ return { id: requiredString(row, "id"), userId: requiredString(row, "userId"), role: row.role, status: row.status, joinedAt: date(row.joinedAt, "joinedAt"), updatedAt: date(row.updatedAt, "updatedAt") };
3618
+ }
3619
+ function hydratePublicBot(value) {
3620
+ const row = record(value);
3621
+ return { id: requiredString(row, "id"), role: row.role, title: requiredString(row, "title"), ...row.responsibility === void 0 ? {} : { responsibility: row.responsibility }, mentionName: requiredString(row, "mentionName"), status: row.status, joinedAt: date(row.joinedAt, "joinedAt"), updatedAt: date(row.updatedAt, "updatedAt") };
3622
+ }
3623
+
3624
+ // src/project-rooms.ts
3625
+ var iso = (value) => date(value, "date").toISOString();
3666
3626
  var encode = encodeURIComponent;
3667
3627
  var ProjectRoomsClient = class {
3668
3628
  constructor(baseURL, getHeaders) {
@@ -3693,6 +3653,9 @@ var ProjectRoomsClient = class {
3693
3653
  if (!Array.isArray(result))
3694
3654
  throw new ProjectRoomClientError("Invalid retry response", 500, "INVALID_RESPONSE", false);
3695
3655
  return result.map(hydrateDispatch);
3656
+ },
3657
+ markRead: async (projectId) => {
3658
+ await this.request(`/api/projects/${encode(projectId)}/room/read-state`, { method: "POST", body: {} });
3696
3659
  }
3697
3660
  };
3698
3661
  this.members = {
@@ -3709,14 +3672,10 @@ var ProjectRoomsClient = class {
3709
3672
  resume: async (projectId, membershipId, input) => hydrateBot(await this.request(`/api/projects/${encode(projectId)}/bots/${encode(membershipId)}/resume`, { method: "POST", body: { expectedUpdatedAt: iso(input.expectedUpdatedAt) } })),
3710
3673
  remove: async (projectId, membershipId, input) => this.request(`/api/projects/${encode(projectId)}/bots/${encode(membershipId)}?expectedUpdatedAt=${encode(iso(input.expectedUpdatedAt))}`, { method: "DELETE" })
3711
3674
  };
3712
- this.events = { connect: (projectId, options) => this.connect(projectId, options) };
3713
3675
  }
3714
3676
  async getRoom(projectId) {
3715
3677
  return hydrateRoom(await this.request(`/api/projects/${encode(projectId)}/room`));
3716
3678
  }
3717
- async getRealtimeMode(projectId) {
3718
- return this.request(`/api/projects/${encode(projectId)}/room/realtime-mode`);
3719
- }
3720
3679
  async records(path, hydrate) {
3721
3680
  const result = await this.request(path);
3722
3681
  if (!Array.isArray(result))
@@ -3736,25 +3695,286 @@ var ProjectRoomsClient = class {
3736
3695
  throw new ProjectRoomClientError("Missing response data", 500, "INVALID_RESPONSE", false);
3737
3696
  return payload.data;
3738
3697
  }
3739
- connect(projectId, options) {
3740
- const headers = { ...this.getHeaders(), Accept: "text/event-stream", ...options.lastEventId ? { "Last-Event-ID": options.lastEventId } : {} };
3698
+ };
3699
+
3700
+ // src/workspace-rooms.ts
3701
+ var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
3702
+ var record2 = (value) => {
3703
+ if (!isRecord2(value))
3704
+ throw new ProjectRoomClientError("Invalid workspace rooms response", 500, "INVALID_RESPONSE", false);
3705
+ return value;
3706
+ };
3707
+ var requiredString2 = (row, field) => {
3708
+ if (typeof row[field] !== "string")
3709
+ throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
3710
+ return row[field];
3711
+ };
3712
+ var date2 = (value, field) => {
3713
+ const result = value instanceof Date ? new Date(value.getTime()) : new Date(typeof value === "string" ? value : Number.NaN);
3714
+ if (!Number.isFinite(result.getTime()))
3715
+ throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
3716
+ return result;
3717
+ };
3718
+ var hydrateProject = (value) => {
3719
+ const row = record2(value);
3720
+ return {
3721
+ id: requiredString2(row, "id"),
3722
+ tenantId: requiredString2(row, "tenantId"),
3723
+ workspaceId: requiredString2(row, "workspaceId"),
3724
+ name: requiredString2(row, "name"),
3725
+ ...row.description === void 0 ? {} : { description: requiredString2(row, "description") },
3726
+ ...row.config === void 0 ? {} : { config: row.config },
3727
+ ...row.kind === void 0 ? {} : { kind: requiredString2(row, "kind") },
3728
+ createdAt: date2(row.createdAt, "createdAt"),
3729
+ updatedAt: date2(row.updatedAt, "updatedAt")
3730
+ };
3731
+ };
3732
+ var hydrateEntry = (value) => {
3733
+ const row = record2(value);
3734
+ const names = row.participantNames;
3735
+ if (!Array.isArray(names) || names.some((n) => typeof n !== "string"))
3736
+ throw new ProjectRoomClientError("Invalid participantNames", 500, "INVALID_RESPONSE", false);
3737
+ if (typeof row.participantCount !== "number" || typeof row.unreadCount !== "number")
3738
+ throw new ProjectRoomClientError("Invalid room entry counts", 500, "INVALID_RESPONSE", false);
3739
+ return {
3740
+ project: hydrateProject(row.project),
3741
+ room: hydrateRoom(row.room),
3742
+ ...row.lastMessage === void 0 ? {} : { lastMessage: hydrateMessage(row.lastMessage) },
3743
+ participantCount: row.participantCount,
3744
+ participantNames: names,
3745
+ ...row.displayName === void 0 ? {} : { displayName: requiredString2(row, "displayName") },
3746
+ ...row.isPublic === void 0 ? {} : { isPublic: row.isPublic === true },
3747
+ unreadCount: row.unreadCount
3748
+ };
3749
+ };
3750
+ var WorkspaceRoomsClient = class {
3751
+ constructor(baseURL, getHeaders) {
3752
+ this.baseURL = baseURL;
3753
+ this.getHeaders = getHeaders;
3754
+ }
3755
+ /** Lists the user's rooms in a workspace with last message and unread count. */
3756
+ async list(workspaceId) {
3757
+ const response = await fetch(`${this.baseURL}/api/workspaces/${encodeURIComponent(workspaceId)}/rooms`, { headers: this.getHeaders() });
3758
+ const payload = await response.json().catch(() => void 0);
3759
+ if (!response.ok || !payload?.success) {
3760
+ const error = payload?.error;
3761
+ throw new ProjectRoomClientError(typeof error?.message === "string" ? error.message : "Workspace rooms request failed", response.status, typeof error?.code === "string" ? error.code : response.ok ? "INVALID_RESPONSE" : "HTTP_ERROR", error?.retryable === true, error?.details);
3762
+ }
3763
+ if (!payload.data || !Array.isArray(payload.data.rooms))
3764
+ throw new ProjectRoomClientError("Invalid workspace rooms response", 500, "INVALID_RESPONSE", false);
3765
+ return payload.data.rooms.map(hydrateEntry);
3766
+ }
3767
+ };
3768
+
3769
+ // src/sse-parser.ts
3770
+ var SseParseError = class extends Error {
3771
+ constructor(message) {
3772
+ super(message);
3773
+ this.code = "INVALID_EVENT";
3774
+ this.name = "SseParseError";
3775
+ }
3776
+ };
3777
+ async function* parseSseBody(body, options = {}) {
3778
+ const reader = body.getReader();
3779
+ const decoder = new TextDecoder();
3780
+ let buffer = "";
3781
+ let event = "";
3782
+ let id;
3783
+ let retry;
3784
+ let data = [];
3785
+ const dispatch = () => {
3786
+ if (data.length === 0) {
3787
+ event = "";
3788
+ id = void 0;
3789
+ retry = void 0;
3790
+ return void 0;
3791
+ }
3792
+ let parsed;
3793
+ try {
3794
+ parsed = JSON.parse(data.join("\n"));
3795
+ } catch {
3796
+ throw new SseParseError("Invalid SSE JSON");
3797
+ }
3798
+ if (options.strictJsonObject && (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)))
3799
+ throw new SseParseError("SSE data must be an object");
3800
+ const result = { event, data: parsed, ...id === void 0 ? {} : { id }, ...retry === void 0 ? {} : { retry } };
3801
+ event = "";
3802
+ id = void 0;
3803
+ retry = void 0;
3804
+ data = [];
3805
+ return result;
3806
+ };
3807
+ const processLine = (raw) => {
3808
+ const line = raw.endsWith("\r") ? raw.slice(0, -1) : raw;
3809
+ if (line === "")
3810
+ return dispatch();
3811
+ if (line.startsWith(":"))
3812
+ return void 0;
3813
+ const separator = line.indexOf(":");
3814
+ const field = separator < 0 ? line : line.slice(0, separator);
3815
+ let value = separator < 0 ? "" : line.slice(separator + 1);
3816
+ if (value.startsWith(" "))
3817
+ value = value.slice(1);
3818
+ if (field === "event")
3819
+ event = value;
3820
+ else if (field === "data")
3821
+ data.push(value);
3822
+ else if (field === "id")
3823
+ id = value;
3824
+ else if (field === "retry") {
3825
+ const parsed = Number(value);
3826
+ if (!Number.isInteger(parsed) || parsed < 0 || !Number.isFinite(parsed))
3827
+ throw new SseParseError("Invalid SSE retry");
3828
+ retry = parsed;
3829
+ }
3830
+ return void 0;
3831
+ };
3832
+ try {
3833
+ while (true) {
3834
+ const chunk = await reader.read();
3835
+ if (chunk.done) {
3836
+ buffer += decoder.decode();
3837
+ break;
3838
+ }
3839
+ buffer += decoder.decode(chunk.value, { stream: true });
3840
+ let index = findLineBreak(buffer);
3841
+ while (index >= 0) {
3842
+ if (buffer[index] === "\r" && index === buffer.length - 1)
3843
+ break;
3844
+ const frame2 = processLine(buffer.slice(0, index));
3845
+ buffer = buffer.slice(index + lineBreakLength(buffer, index));
3846
+ if (frame2)
3847
+ yield frame2;
3848
+ index = findLineBreak(buffer);
3849
+ }
3850
+ }
3851
+ if (buffer) {
3852
+ const frame2 = processLine(buffer);
3853
+ if (frame2)
3854
+ yield frame2;
3855
+ }
3856
+ const frame = processLine("");
3857
+ if (frame)
3858
+ yield frame;
3859
+ } finally {
3860
+ await reader.cancel().catch(() => void 0);
3861
+ reader.releaseLock();
3862
+ }
3863
+ }
3864
+ function findLineBreak(value) {
3865
+ const lf = value.indexOf("\n");
3866
+ const cr = value.indexOf("\r");
3867
+ if (lf < 0)
3868
+ return cr;
3869
+ if (cr < 0)
3870
+ return lf;
3871
+ return Math.min(lf, cr);
3872
+ }
3873
+ function lineBreakLength(value, index) {
3874
+ return value[index] === "\r" && value[index + 1] === "\n" ? 2 : 1;
3875
+ }
3876
+
3877
+ // src/room-events.ts
3878
+ var invalidFrame = (message) => new ProjectRoomClientError(message, 200, "INVALID_EVENT", false);
3879
+ var requiredString3 = (row, field) => {
3880
+ if (typeof row[field] !== "string")
3881
+ throw invalidFrame(`Invalid ${field}`);
3882
+ return row[field];
3883
+ };
3884
+ var oneOf2 = (value, values, field) => {
3885
+ if (typeof value !== "string" || !values.includes(value))
3886
+ throw invalidFrame(`Invalid ${field}`);
3887
+ return value;
3888
+ };
3889
+ var hydrateScope = (value) => {
3890
+ if (!isRecord(value))
3891
+ throw invalidFrame("Invalid scope");
3892
+ return { tenantId: requiredString3(value, "tenantId"), roomId: requiredString3(value, "roomId"), projectId: requiredString3(value, "projectId") };
3893
+ };
3894
+ var hydrateControl = (event, payload) => {
3895
+ if (event === "ready") {
3896
+ if (typeof payload.epoch !== "string" || payload.headEventId !== null && typeof payload.headEventId !== "string" || Object.keys(payload).some((key) => key !== "epoch" && key !== "headEventId"))
3897
+ throw invalidFrame("Invalid SSE control");
3898
+ return { type: "ready", data: { epoch: payload.epoch, headEventId: payload.headEventId } };
3899
+ }
3900
+ if (Object.keys(payload).some((key) => key !== "reason"))
3901
+ throw invalidFrame("Invalid SSE control");
3902
+ if (event === "resync")
3903
+ return { type: "resync", data: { reason: oneOf2(payload.reason, ["SERVER_RESTART", "CURSOR_EXPIRED", "SLOW_CONSUMER"], "reason") } };
3904
+ return { type: "access.revoked", data: { reason: oneOf2(payload.reason, ["PROJECT_ACCESS_REVOKED", "TOKEN_EXPIRED", "CONNECTION_SUPERSEDED"], "reason") } };
3905
+ };
3906
+ var ROOM_SCOPED_TYPES = ["message.created", "roster.changed", "membership.changed", "task.changed"];
3907
+ function hydrateWorkspaceFrame(raw) {
3908
+ const payload = isRecord(raw.data) ? raw.data : void 0;
3909
+ if (raw.event === "ready" || raw.event === "resync" || raw.event === "access.revoked") {
3910
+ if (!payload || Object.prototype.hasOwnProperty.call(payload, "type"))
3911
+ throw invalidFrame("Invalid SSE control");
3912
+ return hydrateControl(raw.event, payload);
3913
+ }
3914
+ if (typeof payload?.type !== "string" || payload.type !== raw.event || typeof payload.id !== "string" || raw.id !== payload.id)
3915
+ throw invalidFrame("Invalid SSE business event");
3916
+ const occurredAt = date(payload.occurredAt, "occurredAt");
3917
+ const scope = payload.scope === void 0 ? void 0 : hydrateScope(payload.scope);
3918
+ const roomScoped = ROOM_SCOPED_TYPES.includes(payload.type);
3919
+ if (roomScoped && scope === void 0)
3920
+ throw invalidFrame("Invalid SSE business event scope");
3921
+ const data = payload.data;
3922
+ if (payload.type === "message.created") {
3923
+ if (!isRecord(data))
3924
+ throw invalidFrame("Invalid SSE business event data");
3925
+ return { type: payload.type, id: payload.id, occurredAt, scope, data: { message: hydrateMessage(data.message) } };
3926
+ }
3927
+ if (payload.type === "roster.changed") {
3928
+ if (!isRecord(data))
3929
+ throw invalidFrame("Invalid SSE business event data");
3930
+ return { type: payload.type, id: payload.id, occurredAt, scope, data: { change: requiredString3(data, "change"), membership: hydratePublicBot(data.membership) } };
3931
+ }
3932
+ if (payload.type === "membership.changed") {
3933
+ if (!isRecord(data))
3934
+ throw invalidFrame("Invalid SSE business event data");
3935
+ return { type: payload.type, id: payload.id, occurredAt, scope, data: { change: requiredString3(data, "change"), membership: hydratePublicMember(data.membership) } };
3936
+ }
3937
+ if (payload.type === "task.changed") {
3938
+ if (!isRecord(data))
3939
+ throw invalidFrame("Invalid SSE business event data");
3940
+ return { type: payload.type, id: payload.id, occurredAt, scope, data: { taskId: requiredString3(data, "taskId"), status: requiredString3(data, "status"), ownerMembershipId: requiredString3(data, "ownerMembershipId"), updatedAt: date(data.updatedAt, "updatedAt") } };
3941
+ }
3942
+ if (payload.type === "read.changed") {
3943
+ if (!isRecord(data))
3944
+ throw invalidFrame("Invalid SSE business event data");
3945
+ return { type: payload.type, id: payload.id, occurredAt, data: { projectId: requiredString3(data, "projectId"), roomId: requiredString3(data, "roomId"), lastReadAt: date(data.lastReadAt, "lastReadAt") } };
3946
+ }
3947
+ if (payload.type === "membership.affected") {
3948
+ if (!isRecord(data))
3949
+ throw invalidFrame("Invalid SSE business event data");
3950
+ return { type: payload.type, id: payload.id, occurredAt, data: { change: oneOf2(data.change, ["added", "removed", "role_changed"], "change"), projectId: requiredString3(data, "projectId"), roomId: requiredString3(data, "roomId") } };
3951
+ }
3952
+ return { type: payload.type, id: payload.id, occurredAt, data: payload.data, ...scope === void 0 ? {} : { scope } };
3953
+ }
3954
+ var RoomEventsClient = class {
3955
+ constructor(baseURL, getHeaders) {
3956
+ this.baseURL = baseURL;
3957
+ this.getHeaders = getHeaders;
3958
+ }
3959
+ connect(workspaceId, options) {
3960
+ const headers = { ...this.getHeaders(), Accept: "text/event-stream" };
3741
3961
  let resolveOpen;
3742
3962
  let rejectOpen;
3743
3963
  const opened = new Promise((resolve, reject) => {
3744
3964
  resolveOpen = resolve;
3745
3965
  rejectOpen = reject;
3746
3966
  });
3747
- const responsePromise = fetch(`${this.baseURL}/api/projects/${encode(projectId)}/room/events`, { headers, signal: options.signal }).then(async (response) => {
3967
+ const responsePromise = fetch(`${this.baseURL}/api/workspaces/${encodeURIComponent(workspaceId)}/room-events`, { headers, signal: options.signal }).then(async (response) => {
3748
3968
  if (!response.ok) {
3749
3969
  const payload = await response.json().catch(() => void 0);
3750
3970
  const error = payload?.error;
3751
- throw new ProjectRoomClientError(typeof error?.message === "string" ? error.message : "Project Room stream failed", response.status, typeof error?.code === "string" ? error.code : "HTTP_ERROR", error?.retryable === true, error?.details);
3971
+ throw new ProjectRoomClientError(typeof error?.message === "string" ? error.message : "Workspace room events stream failed", response.status, typeof error?.code === "string" ? error.code : "HTTP_ERROR", error?.retryable === true, error?.details);
3752
3972
  }
3753
3973
  if (response.headers?.get && response.headers.get("content-type")?.split(";")[0].trim() !== "text/event-stream")
3754
- throw new ProjectRoomClientError("Project Room stream has invalid content type", response.status, "INVALID_RESPONSE", false);
3974
+ throw new ProjectRoomClientError("Workspace room events stream has invalid content type", response.status, "INVALID_RESPONSE", false);
3755
3975
  if (!response.body)
3756
- throw new ProjectRoomClientError("Project Room stream has no body", 500, "INVALID_RESPONSE", false);
3757
- resolveOpen({ status: 200, ...options.lastEventId === void 0 ? {} : { lastEventId: options.lastEventId } });
3976
+ throw new ProjectRoomClientError("Workspace room events stream has no body", 500, "INVALID_RESPONSE", false);
3977
+ resolveOpen({ status: 200 });
3758
3978
  return response;
3759
3979
  }).catch((error) => {
3760
3980
  rejectOpen(error);
@@ -3764,22 +3984,10 @@ var ProjectRoomsClient = class {
3764
3984
  const response = await responsePromise;
3765
3985
  const body = response.body;
3766
3986
  if (!body)
3767
- throw new ProjectRoomClientError("Project Room stream has no body", 500, "INVALID_RESPONSE", false);
3987
+ throw new ProjectRoomClientError("Workspace room events stream has no body", 500, "INVALID_RESPONSE", false);
3768
3988
  for await (const raw of parseSseBody(body, { strictJsonObject: true })) {
3769
3989
  try {
3770
- const event = raw.event;
3771
- const payload = isRecord(raw.data) ? raw.data : void 0;
3772
- let value = payload;
3773
- if (event === "ready" || event === "resync" || event === "access.revoked") {
3774
- if (!payload || Object.prototype.hasOwnProperty.call(payload, "type"))
3775
- throw new ProjectRoomClientError("Invalid SSE control", 200, "INVALID_EVENT", false);
3776
- value = { type: event, data: payload };
3777
- } else {
3778
- if (typeof payload?.type !== "string" || payload.type !== event || typeof payload.id !== "string" || raw.id !== payload.id)
3779
- throw new ProjectRoomClientError("Invalid SSE business event", 200, "INVALID_EVENT", false);
3780
- value = payload;
3781
- }
3782
- yield { event: hydrateEvent(value), ...raw.id === void 0 ? {} : { id: raw.id }, ...raw.retry === void 0 ? {} : { retry: raw.retry } };
3990
+ yield { event: hydrateWorkspaceFrame(raw), ...raw.id === void 0 ? {} : { id: raw.id }, ...raw.retry === void 0 ? {} : { retry: raw.retry } };
3783
3991
  } catch (error) {
3784
3992
  if (error instanceof ProjectRoomClientError && error.code === "INVALID_EVENT")
3785
3993
  throw new ProjectRoomClientError(error.message, 400, "INVALID_EVENT", false, error.details);
@@ -3794,42 +4002,6 @@ var ProjectRoomsClient = class {
3794
4002
  return { opened, [Symbol.asyncIterator]: () => stream };
3795
4003
  }
3796
4004
  };
3797
- function hydrateEvent(value) {
3798
- const row = record(value);
3799
- if (row.type === "ready") {
3800
- exactKeys(row, ["type", "data"]);
3801
- const data2 = record(row.data);
3802
- exactKeys(data2, ["epoch", "headEventId"]);
3803
- if (typeof data2.epoch !== "string" || data2.headEventId !== null && typeof data2.headEventId !== "string")
3804
- throw new ProjectRoomClientError("Invalid SSE control", 200, "INVALID_EVENT", false);
3805
- return { type: "ready", data: { epoch: data2.epoch, headEventId: data2.headEventId } };
3806
- }
3807
- if (row.type === "resync" || row.type === "access.revoked") {
3808
- exactKeys(row, ["type", "data"]);
3809
- const data2 = record(row.data);
3810
- exactKeys(data2, ["reason"]);
3811
- const reasons = row.type === "resync" ? ["SERVER_RESTART", "CURSOR_EXPIRED", "SLOW_CONSUMER"] : ["PROJECT_ACCESS_REVOKED", "TOKEN_EXPIRED"];
3812
- return { type: row.type, data: { reason: oneOf(data2.reason, reasons, "reason") } };
3813
- }
3814
- const data = record(row.data);
3815
- if (row.type === "message.created")
3816
- return { ...row, occurredAt: date(row.occurredAt, "occurredAt"), data: { message: hydrateMessage(data.message) } };
3817
- if (row.type === "roster.changed")
3818
- return { ...row, occurredAt: date(row.occurredAt, "occurredAt"), data: { change: data.change, membership: hydratePublicBot(data.membership) } };
3819
- if (row.type === "membership.changed")
3820
- return { ...row, occurredAt: date(row.occurredAt, "occurredAt"), data: { change: data.change, membership: hydratePublicMember(data.membership) } };
3821
- if (row.type === "task.changed")
3822
- return { ...row, occurredAt: date(row.occurredAt, "occurredAt"), data: { taskId: requiredString(data, "taskId"), status: data.status, ownerMembershipId: requiredString(data, "ownerMembershipId"), updatedAt: date(data.updatedAt, "updatedAt") } };
3823
- throw new ProjectRoomClientError("Invalid SSE event", 200, "INVALID_EVENT", false);
3824
- }
3825
- function hydratePublicMember(value) {
3826
- const row = record(value);
3827
- return { id: requiredString(row, "id"), userId: requiredString(row, "userId"), role: row.role, status: row.status, joinedAt: date(row.joinedAt, "joinedAt"), updatedAt: date(row.updatedAt, "updatedAt") };
3828
- }
3829
- function hydratePublicBot(value) {
3830
- const row = record(value);
3831
- return { id: requiredString(row, "id"), role: row.role, title: requiredString(row, "title"), ...row.responsibility === void 0 ? {} : { responsibility: row.responsibility }, mentionName: requiredString(row, "mentionName"), status: row.status, joinedAt: date(row.joinedAt, "joinedAt"), updatedAt: date(row.updatedAt, "updatedAt") };
3832
- }
3833
4005
 
3834
4006
  // src/client.ts
3835
4007
  var _Client = class extends AbstractClient {
@@ -3847,6 +4019,8 @@ var _Client = class extends AbstractClient {
3847
4019
  this.resources = new ResourcesClient(this.config.baseURL, () => this.getAllHeaders());
3848
4020
  this.exportImport = new ExportImportClient(this.config, () => this.getAllHeaders());
3849
4021
  this.projectRooms = new ProjectRoomsClient(this.config.baseURL, () => this.getAllHeaders());
4022
+ this.workspaceRooms = new WorkspaceRoomsClient(this.config.baseURL, () => this.getAllHeaders());
4023
+ this.roomEvents = new RoomEventsClient(this.config.baseURL, () => this.getAllHeaders());
3850
4024
  }
3851
4025
  /**
3852
4026
  * Helper method to handle fetch responses and errors
@@ -5044,11 +5218,13 @@ function createSimpleMessageMerger() {
5044
5218
  ProjectRoomClientError,
5045
5219
  ProjectRoomsClient,
5046
5220
  ResourcesClient,
5221
+ RoomEventsClient,
5047
5222
  RuntimeAxiomClient,
5048
5223
  ScheduleExecutionType,
5049
5224
  ScheduledTaskStatus,
5050
5225
  WeChatClient,
5051
5226
  WorkspaceClient,
5227
+ WorkspaceRoomsClient,
5052
5228
  createSimpleMessageMerger
5053
5229
  });
5054
5230
  //# sourceMappingURL=index.js.map