@axiom-lattice/client-sdk 4.3.2 → 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 (45) 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__/runtime-client.test.d.ts +10 -0
  8. package/dist/__tests__/runtime-client.test.d.ts.map +1 -0
  9. package/dist/__tests__/runtime-client.test.js +113 -0
  10. package/dist/__tests__/runtime-client.test.js.map +1 -0
  11. package/dist/__tests__/workspace-rooms.test.d.ts +2 -0
  12. package/dist/__tests__/workspace-rooms.test.d.ts.map +1 -0
  13. package/dist/__tests__/workspace-rooms.test.js +116 -0
  14. package/dist/__tests__/workspace-rooms.test.js.map +1 -0
  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 +201 -46
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.js +411 -181
  22. package/dist/index.js.map +1 -1
  23. package/dist/index.mjs +408 -181
  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 +3 -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/runtime-client.d.ts +67 -0
  38. package/dist/runtime-client.d.ts.map +1 -0
  39. package/dist/runtime-client.js +122 -0
  40. package/dist/runtime-client.js.map +1 -0
  41. package/dist/workspace-rooms.d.ts +26 -0
  42. package/dist/workspace-rooms.d.ts.map +1 -0
  43. package/dist/workspace-rooms.js +67 -0
  44. package/dist/workspace-rooms.js.map +1 -0
  45. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1837,10 +1837,13 @@ __export(src_exports, {
1837
1837
  ProjectRoomClientError: () => ProjectRoomClientError,
1838
1838
  ProjectRoomsClient: () => ProjectRoomsClient,
1839
1839
  ResourcesClient: () => ResourcesClient,
1840
+ RoomEventsClient: () => RoomEventsClient,
1841
+ RuntimeAxiomClient: () => RuntimeAxiomClient,
1840
1842
  ScheduleExecutionType: () => ScheduleExecutionType,
1841
1843
  ScheduledTaskStatus: () => ScheduledTaskStatus,
1842
1844
  WeChatClient: () => WeChatClient,
1843
1845
  WorkspaceClient: () => WorkspaceClient,
1846
+ WorkspaceRoomsClient: () => WorkspaceRoomsClient,
1844
1847
  createSimpleMessageMerger: () => createSimpleMessageMerger
1845
1848
  });
1846
1849
  module.exports = __toCommonJS(src_exports);
@@ -2362,7 +2365,7 @@ var AbstractClient = class {
2362
2365
  const query = searchParams.toString();
2363
2366
  const response = await this.makeRequest(`/api/web-apps${query ? `?${query}` : ""}`);
2364
2367
  return {
2365
- records: response.data.records.map((record2) => this.hydrateAgentWebApp(record2)),
2368
+ records: response.data.records.map((record3) => this.hydrateAgentWebApp(record3)),
2366
2369
  total: response.data.total
2367
2370
  };
2368
2371
  },
@@ -3003,19 +3006,19 @@ var AbstractClient = class {
3003
3006
  if (!value || typeof value !== "object" || Array.isArray(value)) {
3004
3007
  throw new ApiError("Invalid Agent Web App response", 500, value);
3005
3008
  }
3006
- const record2 = value;
3009
+ const record3 = value;
3007
3010
  const hydrateDate = (field) => {
3008
- const raw = record2[field];
3009
- 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(
3010
3013
  typeof raw === "string" || typeof raw === "number" ? raw : Number.NaN
3011
3014
  );
3012
- if (Number.isNaN(date2.getTime())) {
3015
+ if (Number.isNaN(date3.getTime())) {
3013
3016
  throw new ApiError(`Invalid Agent Web App ${field}`, 500, value);
3014
3017
  }
3015
- return date2;
3018
+ return date3;
3016
3019
  };
3017
3020
  return {
3018
- ...record2,
3021
+ ...record3,
3019
3022
  createdAt: hydrateDate("createdAt"),
3020
3023
  updatedAt: hydrateDate("updatedAt")
3021
3024
  };
@@ -3455,115 +3458,7 @@ var ExportImportClient = class {
3455
3458
  }
3456
3459
  };
3457
3460
 
3458
- // src/sse-parser.ts
3459
- var SseParseError = class extends Error {
3460
- constructor(message) {
3461
- super(message);
3462
- this.code = "INVALID_EVENT";
3463
- this.name = "SseParseError";
3464
- }
3465
- };
3466
- async function* parseSseBody(body, options = {}) {
3467
- const reader = body.getReader();
3468
- const decoder = new TextDecoder();
3469
- let buffer = "";
3470
- let event = "";
3471
- let id;
3472
- let retry;
3473
- let data = [];
3474
- const dispatch = () => {
3475
- if (data.length === 0) {
3476
- event = "";
3477
- id = void 0;
3478
- retry = void 0;
3479
- return void 0;
3480
- }
3481
- let parsed;
3482
- try {
3483
- parsed = JSON.parse(data.join("\n"));
3484
- } catch {
3485
- throw new SseParseError("Invalid SSE JSON");
3486
- }
3487
- if (options.strictJsonObject && (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)))
3488
- throw new SseParseError("SSE data must be an object");
3489
- const result = { event, data: parsed, ...id === void 0 ? {} : { id }, ...retry === void 0 ? {} : { retry } };
3490
- event = "";
3491
- id = void 0;
3492
- retry = void 0;
3493
- data = [];
3494
- return result;
3495
- };
3496
- const processLine = (raw) => {
3497
- const line = raw.endsWith("\r") ? raw.slice(0, -1) : raw;
3498
- if (line === "")
3499
- return dispatch();
3500
- if (line.startsWith(":"))
3501
- return void 0;
3502
- const separator = line.indexOf(":");
3503
- const field = separator < 0 ? line : line.slice(0, separator);
3504
- let value = separator < 0 ? "" : line.slice(separator + 1);
3505
- if (value.startsWith(" "))
3506
- value = value.slice(1);
3507
- if (field === "event")
3508
- event = value;
3509
- else if (field === "data")
3510
- data.push(value);
3511
- else if (field === "id")
3512
- id = value;
3513
- else if (field === "retry") {
3514
- const parsed = Number(value);
3515
- if (!Number.isInteger(parsed) || parsed < 0 || !Number.isFinite(parsed))
3516
- throw new SseParseError("Invalid SSE retry");
3517
- retry = parsed;
3518
- }
3519
- return void 0;
3520
- };
3521
- try {
3522
- while (true) {
3523
- const chunk = await reader.read();
3524
- if (chunk.done) {
3525
- buffer += decoder.decode();
3526
- break;
3527
- }
3528
- buffer += decoder.decode(chunk.value, { stream: true });
3529
- let index = findLineBreak(buffer);
3530
- while (index >= 0) {
3531
- if (buffer[index] === "\r" && index === buffer.length - 1)
3532
- break;
3533
- const frame2 = processLine(buffer.slice(0, index));
3534
- buffer = buffer.slice(index + lineBreakLength(buffer, index));
3535
- if (frame2)
3536
- yield frame2;
3537
- index = findLineBreak(buffer);
3538
- }
3539
- }
3540
- if (buffer) {
3541
- const frame2 = processLine(buffer);
3542
- if (frame2)
3543
- yield frame2;
3544
- }
3545
- const frame = processLine("");
3546
- if (frame)
3547
- yield frame;
3548
- } finally {
3549
- await reader.cancel().catch(() => void 0);
3550
- reader.releaseLock();
3551
- }
3552
- }
3553
- function findLineBreak(value) {
3554
- const lf = value.indexOf("\n");
3555
- const cr = value.indexOf("\r");
3556
- if (lf < 0)
3557
- return cr;
3558
- if (cr < 0)
3559
- return lf;
3560
- return Math.min(lf, cr);
3561
- }
3562
- function lineBreakLength(value, index) {
3563
- return value[index] === "\r" && value[index + 1] === "\n" ? 2 : 1;
3564
- }
3565
-
3566
- // src/project-rooms.ts
3461
+ // src/project-room-hydrators.ts
3567
3462
  var ProjectRoomClientError = class extends Error {
3568
3463
  constructor(message, status, code, retryable, details) {
3569
3464
  super(message);
@@ -3581,10 +3476,10 @@ var date = (value, field) => {
3581
3476
  throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
3582
3477
  return result;
3583
3478
  };
3584
- var requiredString = (record2, field) => {
3585
- if (typeof record2[field] !== "string")
3479
+ var requiredString = (record3, field) => {
3480
+ if (typeof record3[field] !== "string")
3586
3481
  throw new ProjectRoomClientError(`Invalid ${field}`, 500, "INVALID_RESPONSE", false);
3587
- return record2[field];
3482
+ return record3[field];
3588
3483
  };
3589
3484
  var oneOf = (value, values, field) => {
3590
3485
  if (typeof value !== "string" || !values.includes(value))
@@ -3655,13 +3550,23 @@ var hydrateBot = (value) => {
3655
3550
  exactKeys(row, ["id", "tenantId", "workspaceId", "projectId", "roomId", "assistantId", "role", "title", "mentionName", "status", "roomThreadId", "joinedAt", "updatedAt"], ["responsibility"]);
3656
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") };
3657
3552
  };
3658
- var iso = (value) => date(value, "date").toISOString();
3659
3553
  var hydrateDispatch = (value) => {
3660
3554
  const row = record(value);
3661
3555
  if (typeof row.success !== "boolean" || row.membershipId !== void 0 && typeof row.membershipId !== "string" || row.errorCode !== void 0 && typeof row.errorCode !== "string")
3662
3556
  throw new ProjectRoomClientError("Invalid dispatch response", 500, "INVALID_RESPONSE", false);
3663
3557
  return { success: row.success, ...row.membershipId === void 0 ? {} : { membershipId: row.membershipId }, ...row.errorCode === void 0 ? {} : { errorCode: row.errorCode } };
3664
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();
3665
3570
  var encode = encodeURIComponent;
3666
3571
  var ProjectRoomsClient = class {
3667
3572
  constructor(baseURL, getHeaders) {
@@ -3692,6 +3597,9 @@ var ProjectRoomsClient = class {
3692
3597
  if (!Array.isArray(result))
3693
3598
  throw new ProjectRoomClientError("Invalid retry response", 500, "INVALID_RESPONSE", false);
3694
3599
  return result.map(hydrateDispatch);
3600
+ },
3601
+ markRead: async (projectId) => {
3602
+ await this.request(`/api/projects/${encode(projectId)}/room/read-state`, { method: "POST", body: {} });
3695
3603
  }
3696
3604
  };
3697
3605
  this.members = {
@@ -3708,14 +3616,10 @@ var ProjectRoomsClient = class {
3708
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) } })),
3709
3617
  remove: async (projectId, membershipId, input) => this.request(`/api/projects/${encode(projectId)}/bots/${encode(membershipId)}?expectedUpdatedAt=${encode(iso(input.expectedUpdatedAt))}`, { method: "DELETE" })
3710
3618
  };
3711
- this.events = { connect: (projectId, options) => this.connect(projectId, options) };
3712
3619
  }
3713
3620
  async getRoom(projectId) {
3714
3621
  return hydrateRoom(await this.request(`/api/projects/${encode(projectId)}/room`));
3715
3622
  }
3716
- async getRealtimeMode(projectId) {
3717
- return this.request(`/api/projects/${encode(projectId)}/room/realtime-mode`);
3718
- }
3719
3623
  async records(path, hydrate) {
3720
3624
  const result = await this.request(path);
3721
3625
  if (!Array.isArray(result))
@@ -3735,25 +3639,285 @@ var ProjectRoomsClient = class {
3735
3639
  throw new ProjectRoomClientError("Missing response data", 500, "INVALID_RESPONSE", false);
3736
3640
  return payload.data;
3737
3641
  }
3738
- connect(projectId, options) {
3739
- 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" };
3740
3904
  let resolveOpen;
3741
3905
  let rejectOpen;
3742
3906
  const opened = new Promise((resolve, reject) => {
3743
3907
  resolveOpen = resolve;
3744
3908
  rejectOpen = reject;
3745
3909
  });
3746
- 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) => {
3747
3911
  if (!response.ok) {
3748
3912
  const payload = await response.json().catch(() => void 0);
3749
3913
  const error = payload?.error;
3750
- 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);
3751
3915
  }
3752
3916
  if (response.headers?.get && response.headers.get("content-type")?.split(";")[0].trim() !== "text/event-stream")
3753
- 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);
3754
3918
  if (!response.body)
3755
- throw new ProjectRoomClientError("Project Room stream has no body", 500, "INVALID_RESPONSE", false);
3756
- 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 });
3757
3921
  return response;
3758
3922
  }).catch((error) => {
3759
3923
  rejectOpen(error);
@@ -3763,22 +3927,10 @@ var ProjectRoomsClient = class {
3763
3927
  const response = await responsePromise;
3764
3928
  const body = response.body;
3765
3929
  if (!body)
3766
- 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);
3767
3931
  for await (const raw of parseSseBody(body, { strictJsonObject: true })) {
3768
3932
  try {
3769
- const event = raw.event;
3770
- const payload = isRecord(raw.data) ? raw.data : void 0;
3771
- let value = payload;
3772
- if (event === "ready" || event === "resync" || event === "access.revoked") {
3773
- if (!payload || Object.prototype.hasOwnProperty.call(payload, "type"))
3774
- throw new ProjectRoomClientError("Invalid SSE control", 200, "INVALID_EVENT", false);
3775
- value = { type: event, data: payload };
3776
- } else {
3777
- if (typeof payload?.type !== "string" || payload.type !== event || typeof payload.id !== "string" || raw.id !== payload.id)
3778
- throw new ProjectRoomClientError("Invalid SSE business event", 200, "INVALID_EVENT", false);
3779
- value = payload;
3780
- }
3781
- 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 } };
3782
3934
  } catch (error) {
3783
3935
  if (error instanceof ProjectRoomClientError && error.code === "INVALID_EVENT")
3784
3936
  throw new ProjectRoomClientError(error.message, 400, "INVALID_EVENT", false, error.details);
@@ -3793,42 +3945,6 @@ var ProjectRoomsClient = class {
3793
3945
  return { opened, [Symbol.asyncIterator]: () => stream };
3794
3946
  }
3795
3947
  };
3796
- function hydrateEvent(value) {
3797
- const row = record(value);
3798
- if (row.type === "ready") {
3799
- exactKeys(row, ["type", "data"]);
3800
- const data2 = record(row.data);
3801
- exactKeys(data2, ["epoch", "headEventId"]);
3802
- if (typeof data2.epoch !== "string" || data2.headEventId !== null && typeof data2.headEventId !== "string")
3803
- throw new ProjectRoomClientError("Invalid SSE control", 200, "INVALID_EVENT", false);
3804
- return { type: "ready", data: { epoch: data2.epoch, headEventId: data2.headEventId } };
3805
- }
3806
- if (row.type === "resync" || row.type === "access.revoked") {
3807
- exactKeys(row, ["type", "data"]);
3808
- const data2 = record(row.data);
3809
- exactKeys(data2, ["reason"]);
3810
- const reasons = row.type === "resync" ? ["SERVER_RESTART", "CURSOR_EXPIRED", "SLOW_CONSUMER"] : ["PROJECT_ACCESS_REVOKED", "TOKEN_EXPIRED"];
3811
- return { type: row.type, data: { reason: oneOf(data2.reason, reasons, "reason") } };
3812
- }
3813
- const data = record(row.data);
3814
- if (row.type === "message.created")
3815
- return { ...row, occurredAt: date(row.occurredAt, "occurredAt"), data: { message: hydrateMessage(data.message) } };
3816
- if (row.type === "roster.changed")
3817
- return { ...row, occurredAt: date(row.occurredAt, "occurredAt"), data: { change: data.change, membership: hydratePublicBot(data.membership) } };
3818
- if (row.type === "membership.changed")
3819
- return { ...row, occurredAt: date(row.occurredAt, "occurredAt"), data: { change: data.change, membership: hydratePublicMember(data.membership) } };
3820
- if (row.type === "task.changed")
3821
- return { ...row, occurredAt: date(row.occurredAt, "occurredAt"), data: { taskId: requiredString(data, "taskId"), status: data.status, ownerMembershipId: requiredString(data, "ownerMembershipId"), updatedAt: date(data.updatedAt, "updatedAt") } };
3822
- throw new ProjectRoomClientError("Invalid SSE event", 200, "INVALID_EVENT", false);
3823
- }
3824
- function hydratePublicMember(value) {
3825
- const row = record(value);
3826
- 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") };
3827
- }
3828
- function hydratePublicBot(value) {
3829
- const row = record(value);
3830
- 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") };
3831
- }
3832
3948
 
3833
3949
  // src/client.ts
3834
3950
  var _Client = class extends AbstractClient {
@@ -3846,6 +3962,8 @@ var _Client = class extends AbstractClient {
3846
3962
  this.resources = new ResourcesClient(this.config.baseURL, () => this.getAllHeaders());
3847
3963
  this.exportImport = new ExportImportClient(this.config, () => this.getAllHeaders());
3848
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());
3849
3967
  }
3850
3968
  /**
3851
3969
  * Helper method to handle fetch responses and errors
@@ -4189,6 +4307,115 @@ var _Client = class extends AbstractClient {
4189
4307
  var Client = _Client;
4190
4308
  Client.globalWorkspaceHeaders = {};
4191
4309
 
4310
+ // src/runtime-client.ts
4311
+ var RuntimeAxiomClient = class extends Client {
4312
+ constructor(config) {
4313
+ super({
4314
+ ...config,
4315
+ baseURL: `${config.gatewayUrl.replace(/\/$/, "")}/api/web-apps/${config.webAppId}/runtime`,
4316
+ apiKey: "runtime-bearer"
4317
+ });
4318
+ this.token = null;
4319
+ this.tokenPromise = null;
4320
+ this.gatewayUrl = config.gatewayUrl.replace(/\/$/, "");
4321
+ this.webAppId = config.webAppId;
4322
+ this.identity = config.identity;
4323
+ if (config.identity.mode === "unverified" && config.identity.userId.length === 0) {
4324
+ throw new Error("RuntimeAxiomClient requires a non-empty userId in unverified mode");
4325
+ }
4326
+ }
4327
+ /**
4328
+ * Resolve (and cache) the current identity credential.
4329
+ *
4330
+ * - `verified`: resolves the bearer token from the provider (single-flight;
4331
+ * call again later to force a refresh, or pass through a fresh provider).
4332
+ * - `unverified`: no credential is needed; returns `""`.
4333
+ *
4334
+ * Transport methods resolve this lazily, so the chat stack needs no explicit
4335
+ * priming — the first request triggers the token provider.
4336
+ */
4337
+ async primeToken() {
4338
+ if (this.identity.mode !== "verified")
4339
+ return "";
4340
+ if (!this.tokenPromise) {
4341
+ this.tokenPromise = this.identity.tokenProvider().then((token) => {
4342
+ this.token = token;
4343
+ return token;
4344
+ });
4345
+ }
4346
+ return this.tokenPromise;
4347
+ }
4348
+ identityHeaders() {
4349
+ if (this.identity.mode === "verified") {
4350
+ return { Authorization: `Bearer ${this.token ?? ""}` };
4351
+ }
4352
+ return { "X-Axiom-External-User-Id": this.identity.userId };
4353
+ }
4354
+ getAllHeaders() {
4355
+ const workspace = this.getWorkspaceHeaders();
4356
+ return {
4357
+ ...this.identityHeaders(),
4358
+ ...workspace
4359
+ };
4360
+ }
4361
+ async makeRequest(url, options) {
4362
+ await this.primeToken();
4363
+ const method = options?.method ?? "GET";
4364
+ const headers = {
4365
+ "Content-Type": "application/json",
4366
+ ...this.identityHeaders(),
4367
+ ...options?.headers ?? {}
4368
+ };
4369
+ const requestOptions = { method, headers };
4370
+ if (options?.body !== void 0) {
4371
+ if (options.body instanceof FormData) {
4372
+ requestOptions.body = options.body;
4373
+ delete headers["Content-Type"];
4374
+ } else {
4375
+ requestOptions.body = JSON.stringify(options.body);
4376
+ }
4377
+ }
4378
+ const response = await fetch(`${this.getBaseUrl()}${url}`, requestOptions);
4379
+ if (!response.ok) {
4380
+ let message = `HTTP ${response.status}`;
4381
+ try {
4382
+ const body = await response.json();
4383
+ message = body.error ?? body.message ?? message;
4384
+ } catch {
4385
+ }
4386
+ const error = new Error(message);
4387
+ error.status = response.status;
4388
+ throw error;
4389
+ }
4390
+ if (response.status === 204)
4391
+ return void 0;
4392
+ return await response.json();
4393
+ }
4394
+ getBaseUrl() {
4395
+ return this.config.baseURL;
4396
+ }
4397
+ /**
4398
+ * Clone into a real sibling instance sharing the runtime identity so the
4399
+ * `AxiomLatticeProvider` per-assistant `clone({ assistantId })` cache keeps
4400
+ * working (each clone carries its own resolved credential cache).
4401
+ */
4402
+ createInstance(config) {
4403
+ return new RuntimeAxiomClient({
4404
+ gatewayUrl: this.gatewayUrl,
4405
+ webAppId: this.webAppId,
4406
+ identity: this.identity,
4407
+ assistantId: config.assistantId,
4408
+ transport: config.transport,
4409
+ ...config.timeout !== void 0 ? { timeout: config.timeout } : {},
4410
+ ...config.headers !== void 0 ? { headers: config.headers } : {},
4411
+ ...config.retry !== void 0 ? { retry: config.retry } : {}
4412
+ });
4413
+ }
4414
+ streamRequest(_options, _onEvent, _onComplete, _onError) {
4415
+ throw new Error("RuntimeAxiomClient uses resumeStream; chat.stream is unsupported");
4416
+ }
4417
+ };
4418
+
4192
4419
  // src/wechat-client.ts
4193
4420
  var import_encoding = __toESM(require_encoding());
4194
4421
  var WeChatClient = class extends AbstractClient {
@@ -4934,10 +5161,13 @@ function createSimpleMessageMerger() {
4934
5161
  ProjectRoomClientError,
4935
5162
  ProjectRoomsClient,
4936
5163
  ResourcesClient,
5164
+ RoomEventsClient,
5165
+ RuntimeAxiomClient,
4937
5166
  ScheduleExecutionType,
4938
5167
  ScheduledTaskStatus,
4939
5168
  WeChatClient,
4940
5169
  WorkspaceClient,
5170
+ WorkspaceRoomsClient,
4941
5171
  createSimpleMessageMerger
4942
5172
  });
4943
5173
  //# sourceMappingURL=index.js.map