@axiom-lattice/client-sdk 4.3.4 → 4.3.6

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 (37) 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/client.d.ts +4 -0
  12. package/dist/client.d.ts.map +1 -1
  13. package/dist/client.js +4 -0
  14. package/dist/client.js.map +1 -1
  15. package/dist/index.d.ts +137 -46
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +300 -181
  18. package/dist/index.js.map +1 -1
  19. package/dist/index.mjs +298 -181
  20. package/dist/index.mjs.map +1 -1
  21. package/dist/project-room-hydrators.d.ts +18 -0
  22. package/dist/project-room-hydrators.d.ts.map +1 -0
  23. package/dist/project-room-hydrators.js +95 -0
  24. package/dist/project-room-hydrators.js.map +1 -0
  25. package/dist/project-rooms.d.ts +3 -51
  26. package/dist/project-rooms.d.ts.map +1 -1
  27. package/dist/project-rooms.js +5 -178
  28. package/dist/project-rooms.js.map +1 -1
  29. package/dist/room-events.d.ts +108 -0
  30. package/dist/room-events.d.ts.map +1 -0
  31. package/dist/room-events.js +127 -0
  32. package/dist/room-events.js.map +1 -0
  33. package/dist/workspace-rooms.d.ts +26 -0
  34. package/dist/workspace-rooms.d.ts.map +1 -0
  35. package/dist/workspace-rooms.js +67 -0
  36. package/dist/workspace-rooms.js.map +1 -0
  37. 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);
@@ -2363,7 +2365,7 @@ var AbstractClient = class {
2363
2365
  const query = searchParams.toString();
2364
2366
  const response = await this.makeRequest(`/api/web-apps${query ? `?${query}` : ""}`);
2365
2367
  return {
2366
- records: response.data.records.map((record2) => this.hydrateAgentWebApp(record2)),
2368
+ records: response.data.records.map((record3) => this.hydrateAgentWebApp(record3)),
2367
2369
  total: response.data.total
2368
2370
  };
2369
2371
  },
@@ -3004,19 +3006,19 @@ var AbstractClient = class {
3004
3006
  if (!value || typeof value !== "object" || Array.isArray(value)) {
3005
3007
  throw new ApiError("Invalid Agent Web App response", 500, value);
3006
3008
  }
3007
- const record2 = value;
3009
+ const record3 = value;
3008
3010
  const hydrateDate = (field) => {
3009
- const raw = record2[field];
3010
- const date2 = raw instanceof Date ? new Date(raw.getTime()) : new Date(
3011
+ const raw = record3[field];
3012
+ const date3 = raw instanceof Date ? new Date(raw.getTime()) : new Date(
3011
3013
  typeof raw === "string" || typeof raw === "number" ? raw : Number.NaN
3012
3014
  );
3013
- if (Number.isNaN(date2.getTime())) {
3015
+ if (Number.isNaN(date3.getTime())) {
3014
3016
  throw new ApiError(`Invalid Agent Web App ${field}`, 500, value);
3015
3017
  }
3016
- return date2;
3018
+ return date3;
3017
3019
  };
3018
3020
  return {
3019
- ...record2,
3021
+ ...record3,
3020
3022
  createdAt: hydrateDate("createdAt"),
3021
3023
  updatedAt: hydrateDate("updatedAt")
3022
3024
  };
@@ -3456,115 +3458,7 @@ var ExportImportClient = class {
3456
3458
  }
3457
3459
  };
3458
3460
 
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
3461
+ // src/project-room-hydrators.ts
3568
3462
  var ProjectRoomClientError = class extends Error {
3569
3463
  constructor(message, status, code, retryable, details) {
3570
3464
  super(message);
@@ -3582,10 +3476,10 @@ var date = (value, field) => {
3582
3476
  throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
3583
3477
  return result;
3584
3478
  };
3585
- var requiredString = (record2, field) => {
3586
- if (typeof record2[field] !== "string")
3479
+ var requiredString = (record3, field) => {
3480
+ if (typeof record3[field] !== "string")
3587
3481
  throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
3588
- return record2[field];
3482
+ return record3[field];
3589
3483
  };
3590
3484
  var oneOf = (value, values, field) => {
3591
3485
  if (typeof value !== "string" || !values.includes(value))
@@ -3656,13 +3550,23 @@ var hydrateBot = (value) => {
3656
3550
  exactKeys(row, ["id", "tenantId", "workspaceId", "projectId", "roomId", "assistantId", "role", "title", "mentionName", "status", "roomThreadId", "joinedAt", "updatedAt"], ["responsibility"]);
3657
3551
  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
3552
  };
3659
- var iso = (value) => date(value, "date").toISOString();
3660
3553
  var hydrateDispatch = (value) => {
3661
3554
  const row = record(value);
3662
3555
  if (typeof row.success !== "boolean" || row.membershipId !== void 0 && typeof row.membershipId !== "string" || row.errorCode !== void 0 && typeof row.errorCode !== "string")
3663
3556
  throw new ProjectRoomClientError("Invalid dispatch response", 500, "INVALID_RESPONSE", false);
3664
3557
  return { success: row.success, ...row.membershipId === void 0 ? {} : { membershipId: row.membershipId }, ...row.errorCode === void 0 ? {} : { errorCode: row.errorCode } };
3665
3558
  };
3559
+ function hydratePublicMember(value) {
3560
+ const row = record(value);
3561
+ 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") };
3562
+ }
3563
+ function hydratePublicBot(value) {
3564
+ const row = record(value);
3565
+ 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") };
3566
+ }
3567
+
3568
+ // src/project-rooms.ts
3569
+ var iso = (value) => date(value, "date").toISOString();
3666
3570
  var encode = encodeURIComponent;
3667
3571
  var ProjectRoomsClient = class {
3668
3572
  constructor(baseURL, getHeaders) {
@@ -3693,6 +3597,9 @@ var ProjectRoomsClient = class {
3693
3597
  if (!Array.isArray(result))
3694
3598
  throw new ProjectRoomClientError("Invalid retry response", 500, "INVALID_RESPONSE", false);
3695
3599
  return result.map(hydrateDispatch);
3600
+ },
3601
+ markRead: async (projectId) => {
3602
+ await this.request(`/api/projects/${encode(projectId)}/room/read-state`, { method: "POST", body: {} });
3696
3603
  }
3697
3604
  };
3698
3605
  this.members = {
@@ -3709,14 +3616,10 @@ var ProjectRoomsClient = class {
3709
3616
  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
3617
  remove: async (projectId, membershipId, input) => this.request(`/api/projects/${encode(projectId)}/bots/${encode(membershipId)}?expectedUpdatedAt=${encode(iso(input.expectedUpdatedAt))}`, { method: "DELETE" })
3711
3618
  };
3712
- this.events = { connect: (projectId, options) => this.connect(projectId, options) };
3713
3619
  }
3714
3620
  async getRoom(projectId) {
3715
3621
  return hydrateRoom(await this.request(`/api/projects/${encode(projectId)}/room`));
3716
3622
  }
3717
- async getRealtimeMode(projectId) {
3718
- return this.request(`/api/projects/${encode(projectId)}/room/realtime-mode`);
3719
- }
3720
3623
  async records(path, hydrate) {
3721
3624
  const result = await this.request(path);
3722
3625
  if (!Array.isArray(result))
@@ -3736,25 +3639,285 @@ var ProjectRoomsClient = class {
3736
3639
  throw new ProjectRoomClientError("Missing response data", 500, "INVALID_RESPONSE", false);
3737
3640
  return payload.data;
3738
3641
  }
3739
- connect(projectId, options) {
3740
- const headers = { ...this.getHeaders(), Accept: "text/event-stream", ...options.lastEventId ? { "Last-Event-ID": options.lastEventId } : {} };
3642
+ };
3643
+
3644
+ // src/workspace-rooms.ts
3645
+ var isRecord2 = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
3646
+ var record2 = (value) => {
3647
+ if (!isRecord2(value))
3648
+ throw new ProjectRoomClientError("Invalid workspace rooms response", 500, "INVALID_RESPONSE", false);
3649
+ return value;
3650
+ };
3651
+ var requiredString2 = (row, field) => {
3652
+ if (typeof row[field] !== "string")
3653
+ throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
3654
+ return row[field];
3655
+ };
3656
+ var date2 = (value, field) => {
3657
+ const result = value instanceof Date ? new Date(value.getTime()) : new Date(typeof value === "string" ? value : Number.NaN);
3658
+ if (!Number.isFinite(result.getTime()))
3659
+ throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
3660
+ return result;
3661
+ };
3662
+ var hydrateProject = (value) => {
3663
+ const row = record2(value);
3664
+ return {
3665
+ id: requiredString2(row, "id"),
3666
+ tenantId: requiredString2(row, "tenantId"),
3667
+ workspaceId: requiredString2(row, "workspaceId"),
3668
+ name: requiredString2(row, "name"),
3669
+ ...row.description === void 0 ? {} : { description: requiredString2(row, "description") },
3670
+ ...row.config === void 0 ? {} : { config: row.config },
3671
+ ...row.kind === void 0 ? {} : { kind: requiredString2(row, "kind") },
3672
+ createdAt: date2(row.createdAt, "createdAt"),
3673
+ updatedAt: date2(row.updatedAt, "updatedAt")
3674
+ };
3675
+ };
3676
+ var hydrateEntry = (value) => {
3677
+ const row = record2(value);
3678
+ const names = row.participantNames;
3679
+ if (!Array.isArray(names) || names.some((n) => typeof n !== "string"))
3680
+ throw new ProjectRoomClientError("Invalid participantNames", 500, "INVALID_RESPONSE", false);
3681
+ if (typeof row.participantCount !== "number" || typeof row.unreadCount !== "number")
3682
+ throw new ProjectRoomClientError("Invalid room entry counts", 500, "INVALID_RESPONSE", false);
3683
+ return {
3684
+ project: hydrateProject(row.project),
3685
+ room: hydrateRoom(row.room),
3686
+ ...row.lastMessage === void 0 ? {} : { lastMessage: hydrateMessage(row.lastMessage) },
3687
+ participantCount: row.participantCount,
3688
+ participantNames: names,
3689
+ ...row.isPublic === void 0 ? {} : { isPublic: row.isPublic === true },
3690
+ unreadCount: row.unreadCount
3691
+ };
3692
+ };
3693
+ var WorkspaceRoomsClient = class {
3694
+ constructor(baseURL, getHeaders) {
3695
+ this.baseURL = baseURL;
3696
+ this.getHeaders = getHeaders;
3697
+ }
3698
+ /** Lists the user's rooms in a workspace with last message and unread count. */
3699
+ async list(workspaceId) {
3700
+ const response = await fetch(`${this.baseURL}/api/workspaces/${encodeURIComponent(workspaceId)}/rooms`, { headers: this.getHeaders() });
3701
+ const payload = await response.json().catch(() => void 0);
3702
+ if (!response.ok || !payload?.success) {
3703
+ const error = payload?.error;
3704
+ 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);
3705
+ }
3706
+ if (!payload.data || !Array.isArray(payload.data.rooms))
3707
+ throw new ProjectRoomClientError("Invalid workspace rooms response", 500, "INVALID_RESPONSE", false);
3708
+ return payload.data.rooms.map(hydrateEntry);
3709
+ }
3710
+ };
3711
+
3712
+ // src/sse-parser.ts
3713
+ var SseParseError = class extends Error {
3714
+ constructor(message) {
3715
+ super(message);
3716
+ this.code = "INVALID_EVENT";
3717
+ this.name = "SseParseError";
3718
+ }
3719
+ };
3720
+ async function* parseSseBody(body, options = {}) {
3721
+ const reader = body.getReader();
3722
+ const decoder = new TextDecoder();
3723
+ let buffer = "";
3724
+ let event = "";
3725
+ let id;
3726
+ let retry;
3727
+ let data = [];
3728
+ const dispatch = () => {
3729
+ if (data.length === 0) {
3730
+ event = "";
3731
+ id = void 0;
3732
+ retry = void 0;
3733
+ return void 0;
3734
+ }
3735
+ let parsed;
3736
+ try {
3737
+ parsed = JSON.parse(data.join("\n"));
3738
+ } catch {
3739
+ throw new SseParseError("Invalid SSE JSON");
3740
+ }
3741
+ if (options.strictJsonObject && (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)))
3742
+ throw new SseParseError("SSE data must be an object");
3743
+ const result = { event, data: parsed, ...id === void 0 ? {} : { id }, ...retry === void 0 ? {} : { retry } };
3744
+ event = "";
3745
+ id = void 0;
3746
+ retry = void 0;
3747
+ data = [];
3748
+ return result;
3749
+ };
3750
+ const processLine = (raw) => {
3751
+ const line = raw.endsWith("\r") ? raw.slice(0, -1) : raw;
3752
+ if (line === "")
3753
+ return dispatch();
3754
+ if (line.startsWith(":"))
3755
+ return void 0;
3756
+ const separator = line.indexOf(":");
3757
+ const field = separator < 0 ? line : line.slice(0, separator);
3758
+ let value = separator < 0 ? "" : line.slice(separator + 1);
3759
+ if (value.startsWith(" "))
3760
+ value = value.slice(1);
3761
+ if (field === "event")
3762
+ event = value;
3763
+ else if (field === "data")
3764
+ data.push(value);
3765
+ else if (field === "id")
3766
+ id = value;
3767
+ else if (field === "retry") {
3768
+ const parsed = Number(value);
3769
+ if (!Number.isInteger(parsed) || parsed < 0 || !Number.isFinite(parsed))
3770
+ throw new SseParseError("Invalid SSE retry");
3771
+ retry = parsed;
3772
+ }
3773
+ return void 0;
3774
+ };
3775
+ try {
3776
+ while (true) {
3777
+ const chunk = await reader.read();
3778
+ if (chunk.done) {
3779
+ buffer += decoder.decode();
3780
+ break;
3781
+ }
3782
+ buffer += decoder.decode(chunk.value, { stream: true });
3783
+ let index = findLineBreak(buffer);
3784
+ while (index >= 0) {
3785
+ if (buffer[index] === "\r" && index === buffer.length - 1)
3786
+ break;
3787
+ const frame2 = processLine(buffer.slice(0, index));
3788
+ buffer = buffer.slice(index + lineBreakLength(buffer, index));
3789
+ if (frame2)
3790
+ yield frame2;
3791
+ index = findLineBreak(buffer);
3792
+ }
3793
+ }
3794
+ if (buffer) {
3795
+ const frame2 = processLine(buffer);
3796
+ if (frame2)
3797
+ yield frame2;
3798
+ }
3799
+ const frame = processLine("");
3800
+ if (frame)
3801
+ yield frame;
3802
+ } finally {
3803
+ await reader.cancel().catch(() => void 0);
3804
+ reader.releaseLock();
3805
+ }
3806
+ }
3807
+ function findLineBreak(value) {
3808
+ const lf = value.indexOf("\n");
3809
+ const cr = value.indexOf("\r");
3810
+ if (lf < 0)
3811
+ return cr;
3812
+ if (cr < 0)
3813
+ return lf;
3814
+ return Math.min(lf, cr);
3815
+ }
3816
+ function lineBreakLength(value, index) {
3817
+ return value[index] === "\r" && value[index + 1] === "\n" ? 2 : 1;
3818
+ }
3819
+
3820
+ // src/room-events.ts
3821
+ var invalidFrame = (message) => new ProjectRoomClientError(message, 200, "INVALID_EVENT", false);
3822
+ var requiredString3 = (row, field) => {
3823
+ if (typeof row[field] !== "string")
3824
+ throw invalidFrame(`Invalid ${field}`);
3825
+ return row[field];
3826
+ };
3827
+ var oneOf2 = (value, values, field) => {
3828
+ if (typeof value !== "string" || !values.includes(value))
3829
+ throw invalidFrame(`Invalid ${field}`);
3830
+ return value;
3831
+ };
3832
+ var hydrateScope = (value) => {
3833
+ if (!isRecord(value))
3834
+ throw invalidFrame("Invalid scope");
3835
+ return { tenantId: requiredString3(value, "tenantId"), roomId: requiredString3(value, "roomId"), projectId: requiredString3(value, "projectId") };
3836
+ };
3837
+ var hydrateControl = (event, payload) => {
3838
+ if (event === "ready") {
3839
+ if (typeof payload.epoch !== "string" || payload.headEventId !== null && typeof payload.headEventId !== "string" || Object.keys(payload).some((key) => key !== "epoch" && key !== "headEventId"))
3840
+ throw invalidFrame("Invalid SSE control");
3841
+ return { type: "ready", data: { epoch: payload.epoch, headEventId: payload.headEventId } };
3842
+ }
3843
+ if (Object.keys(payload).some((key) => key !== "reason"))
3844
+ throw invalidFrame("Invalid SSE control");
3845
+ if (event === "resync")
3846
+ return { type: "resync", data: { reason: oneOf2(payload.reason, ["SERVER_RESTART", "CURSOR_EXPIRED", "SLOW_CONSUMER"], "reason") } };
3847
+ return { type: "access.revoked", data: { reason: oneOf2(payload.reason, ["PROJECT_ACCESS_REVOKED", "TOKEN_EXPIRED", "CONNECTION_SUPERSEDED"], "reason") } };
3848
+ };
3849
+ var ROOM_SCOPED_TYPES = ["message.created", "roster.changed", "membership.changed", "task.changed"];
3850
+ function hydrateWorkspaceFrame(raw) {
3851
+ const payload = isRecord(raw.data) ? raw.data : void 0;
3852
+ if (raw.event === "ready" || raw.event === "resync" || raw.event === "access.revoked") {
3853
+ if (!payload || Object.prototype.hasOwnProperty.call(payload, "type"))
3854
+ throw invalidFrame("Invalid SSE control");
3855
+ return hydrateControl(raw.event, payload);
3856
+ }
3857
+ if (typeof payload?.type !== "string" || payload.type !== raw.event || typeof payload.id !== "string" || raw.id !== payload.id)
3858
+ throw invalidFrame("Invalid SSE business event");
3859
+ const occurredAt = date(payload.occurredAt, "occurredAt");
3860
+ const scope = payload.scope === void 0 ? void 0 : hydrateScope(payload.scope);
3861
+ const roomScoped = ROOM_SCOPED_TYPES.includes(payload.type);
3862
+ if (roomScoped && scope === void 0)
3863
+ throw invalidFrame("Invalid SSE business event scope");
3864
+ const data = payload.data;
3865
+ if (payload.type === "message.created") {
3866
+ if (!isRecord(data))
3867
+ throw invalidFrame("Invalid SSE business event data");
3868
+ return { type: payload.type, id: payload.id, occurredAt, scope, data: { message: hydrateMessage(data.message) } };
3869
+ }
3870
+ if (payload.type === "roster.changed") {
3871
+ if (!isRecord(data))
3872
+ throw invalidFrame("Invalid SSE business event data");
3873
+ return { type: payload.type, id: payload.id, occurredAt, scope, data: { change: requiredString3(data, "change"), membership: hydratePublicBot(data.membership) } };
3874
+ }
3875
+ if (payload.type === "membership.changed") {
3876
+ if (!isRecord(data))
3877
+ throw invalidFrame("Invalid SSE business event data");
3878
+ return { type: payload.type, id: payload.id, occurredAt, scope, data: { change: requiredString3(data, "change"), membership: hydratePublicMember(data.membership) } };
3879
+ }
3880
+ if (payload.type === "task.changed") {
3881
+ if (!isRecord(data))
3882
+ throw invalidFrame("Invalid SSE business event data");
3883
+ 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") } };
3884
+ }
3885
+ if (payload.type === "read.changed") {
3886
+ if (!isRecord(data))
3887
+ throw invalidFrame("Invalid SSE business event data");
3888
+ return { type: payload.type, id: payload.id, occurredAt, data: { projectId: requiredString3(data, "projectId"), roomId: requiredString3(data, "roomId"), lastReadAt: date(data.lastReadAt, "lastReadAt") } };
3889
+ }
3890
+ if (payload.type === "membership.affected") {
3891
+ if (!isRecord(data))
3892
+ throw invalidFrame("Invalid SSE business event data");
3893
+ 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") } };
3894
+ }
3895
+ return { type: payload.type, id: payload.id, occurredAt, data: payload.data, ...scope === void 0 ? {} : { scope } };
3896
+ }
3897
+ var RoomEventsClient = class {
3898
+ constructor(baseURL, getHeaders) {
3899
+ this.baseURL = baseURL;
3900
+ this.getHeaders = getHeaders;
3901
+ }
3902
+ connect(workspaceId, options) {
3903
+ const headers = { ...this.getHeaders(), Accept: "text/event-stream" };
3741
3904
  let resolveOpen;
3742
3905
  let rejectOpen;
3743
3906
  const opened = new Promise((resolve, reject) => {
3744
3907
  resolveOpen = resolve;
3745
3908
  rejectOpen = reject;
3746
3909
  });
3747
- const responsePromise = fetch(`${this.baseURL}/api/projects/${encode(projectId)}/room/events`, { headers, signal: options.signal }).then(async (response) => {
3910
+ const responsePromise = fetch(`${this.baseURL}/api/workspaces/${encodeURIComponent(workspaceId)}/room-events`, { headers, signal: options.signal }).then(async (response) => {
3748
3911
  if (!response.ok) {
3749
3912
  const payload = await response.json().catch(() => void 0);
3750
3913
  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);
3914
+ 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
3915
  }
3753
3916
  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);
3917
+ throw new ProjectRoomClientError("Workspace room events stream has invalid content type", response.status, "INVALID_RESPONSE", false);
3755
3918
  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 } });
3919
+ throw new ProjectRoomClientError("Workspace room events stream has no body", 500, "INVALID_RESPONSE", false);
3920
+ resolveOpen({ status: 200 });
3758
3921
  return response;
3759
3922
  }).catch((error) => {
3760
3923
  rejectOpen(error);
@@ -3764,22 +3927,10 @@ var ProjectRoomsClient = class {
3764
3927
  const response = await responsePromise;
3765
3928
  const body = response.body;
3766
3929
  if (!body)
3767
- throw new ProjectRoomClientError("Project Room stream has no body", 500, "INVALID_RESPONSE", false);
3930
+ throw new ProjectRoomClientError("Workspace room events stream has no body", 500, "INVALID_RESPONSE", false);
3768
3931
  for await (const raw of parseSseBody(body, { strictJsonObject: true })) {
3769
3932
  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 } };
3933
+ yield { event: hydrateWorkspaceFrame(raw), ...raw.id === void 0 ? {} : { id: raw.id }, ...raw.retry === void 0 ? {} : { retry: raw.retry } };
3783
3934
  } catch (error) {
3784
3935
  if (error instanceof ProjectRoomClientError && error.code === "INVALID_EVENT")
3785
3936
  throw new ProjectRoomClientError(error.message, 400, "INVALID_EVENT", false, error.details);
@@ -3794,42 +3945,6 @@ var ProjectRoomsClient = class {
3794
3945
  return { opened, [Symbol.asyncIterator]: () => stream };
3795
3946
  }
3796
3947
  };
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
3948
 
3834
3949
  // src/client.ts
3835
3950
  var _Client = class extends AbstractClient {
@@ -3847,6 +3962,8 @@ var _Client = class extends AbstractClient {
3847
3962
  this.resources = new ResourcesClient(this.config.baseURL, () => this.getAllHeaders());
3848
3963
  this.exportImport = new ExportImportClient(this.config, () => this.getAllHeaders());
3849
3964
  this.projectRooms = new ProjectRoomsClient(this.config.baseURL, () => this.getAllHeaders());
3965
+ this.workspaceRooms = new WorkspaceRoomsClient(this.config.baseURL, () => this.getAllHeaders());
3966
+ this.roomEvents = new RoomEventsClient(this.config.baseURL, () => this.getAllHeaders());
3850
3967
  }
3851
3968
  /**
3852
3969
  * Helper method to handle fetch responses and errors
@@ -5044,11 +5161,13 @@ function createSimpleMessageMerger() {
5044
5161
  ProjectRoomClientError,
5045
5162
  ProjectRoomsClient,
5046
5163
  ResourcesClient,
5164
+ RoomEventsClient,
5047
5165
  RuntimeAxiomClient,
5048
5166
  ScheduleExecutionType,
5049
5167
  ScheduledTaskStatus,
5050
5168
  WeChatClient,
5051
5169
  WorkspaceClient,
5170
+ WorkspaceRoomsClient,
5052
5171
  createSimpleMessageMerger
5053
5172
  });
5054
5173
  //# sourceMappingURL=index.js.map