From c06a7148456c7871b49dce7005d6ef8c37a633f8 Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Wed, 9 Jul 2025 11:01:31 +0100 Subject: [PATCH] chat: bump @ably/chat to 0.10.0 --- package.json | 2 +- pnpm-lock.yaml | 10 ++++---- src/commands/rooms/messages/get.ts | 2 +- src/commands/rooms/messages/reactions/add.ts | 2 +- src/commands/rooms/messages/subscribe.ts | 6 ++--- src/commands/rooms/occupancy/get.ts | 10 ++++---- src/commands/rooms/occupancy/subscribe.ts | 11 +++++++-- src/commands/rooms/presence/enter.ts | 26 ++++++++++---------- src/commands/rooms/presence/subscribe.ts | 24 +++++++++--------- src/commands/rooms/reactions/send.ts | 2 +- src/commands/rooms/reactions/subscribe.ts | 9 ++++--- 11 files changed, 57 insertions(+), 47 deletions(-) diff --git a/package.json b/package.json index ab7ddde60..552feca6d 100644 --- a/package.json +++ b/package.json @@ -81,7 +81,7 @@ } }, "dependencies": { - "@ably/chat": "^0.7.0", + "@ably/chat": "^0.10.0", "@ably/spaces": "^0.4.0", "@inquirer/prompts": "^5.1.3", "@modelcontextprotocol/sdk": "^1.8.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0c67f5351..8e029b918 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,8 +14,8 @@ importers: .: dependencies: '@ably/chat': - specifier: ^0.7.0 - version: 0.7.0(ably@2.9.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1) + specifier: ^0.10.0 + version: 0.10.0(ably@2.9.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1) '@ably/spaces': specifier: ^0.4.0 version: 0.4.0(ably@2.9.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1) @@ -367,8 +367,8 @@ importers: packages: - '@ably/chat@0.7.0': - resolution: {integrity: sha512-m7gChuLoXcB2KWDAwyLBfh+V5YJf3v5aweml+zdIwt5/JNztChmolN4pqJhEv0B5dT21tQU/fWkFtcyXBFJOvQ==} + '@ably/chat@0.10.0': + resolution: {integrity: sha512-74T/XAiYQkrNkRVcV18jnUjEiH23K3lOgt4yrZ0MXta0QJ9iWhqnemlmL+IDT9i/bN57AuhNXOVn8RdSSHjHnw==} engines: {node: '>=18.0.0'} peerDependencies: ably: ^2.9.0 @@ -6152,7 +6152,7 @@ packages: snapshots: - '@ably/chat@0.7.0(ably@2.9.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': + '@ably/chat@0.10.0(ably@2.9.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1))(react-dom@18.3.1(react@18.3.1))(react@18.3.1)': dependencies: ably: 2.9.0(react-dom@18.3.1(react@18.3.1))(react@18.3.1) async-mutex: 0.5.0 diff --git a/src/commands/rooms/messages/get.ts b/src/commands/rooms/messages/get.ts index 175c36027..651fce9f1 100644 --- a/src/commands/rooms/messages/get.ts +++ b/src/commands/rooms/messages/get.ts @@ -80,7 +80,7 @@ export default class MessagesGet extends ChatBaseCommand { } // Get historical messages - const messagesResult = await room.messages.get({ limit: flags.limit }); + const messagesResult = await room.messages.history({ limit: flags.limit }); const { items } = messagesResult; if (this.shouldOutputJson(flags)) { diff --git a/src/commands/rooms/messages/reactions/add.ts b/src/commands/rooms/messages/reactions/add.ts index 7416d554f..969c46824 100644 --- a/src/commands/rooms/messages/reactions/add.ts +++ b/src/commands/rooms/messages/reactions/add.ts @@ -236,7 +236,7 @@ export default class MessagesReactionsAdd extends ChatBaseCommand { } ); - await room.messages.reactions.add({ serial: messageSerial }, reactionParams); + await room.messages.reactions.send({ serial: messageSerial }, reactionParams); this.logCliEvent( flags, diff --git a/src/commands/rooms/messages/subscribe.ts b/src/commands/rooms/messages/subscribe.ts index df61375de..e5810b220 100644 --- a/src/commands/rooms/messages/subscribe.ts +++ b/src/commands/rooms/messages/subscribe.ts @@ -1,6 +1,6 @@ import { Args, Flags } from "@oclif/core"; import * as Ably from "ably"; -import { Subscription, StatusSubscription, MessageEvent } from "@ably/chat"; // Import ChatClient and StatusSubscription +import { Subscription, StatusSubscription, ChatMessageEvent } from "@ably/chat"; // Import ChatClient and StatusSubscription import chalk from "chalk"; import { ChatBaseCommand } from "../../../chat-base-command.js"; @@ -29,7 +29,7 @@ interface StatusChange { // Define room interface interface ChatRoom { messages: { - subscribe: (callback: (event: MessageEvent) => void) => Subscription; + subscribe: (callback: (event: ChatMessageEvent) => void) => Subscription; }; onStatusChange: (callback: (statusChange: unknown) => void) => StatusSubscription; attach: () => Promise; @@ -191,7 +191,7 @@ export default class MessagesSubscribe extends ChatBaseCommand { `Subscribing to messages in room ${this.roomId}`, ); this.messageSubscription = room.messages.subscribe( - (messageEvent: MessageEvent) => { + (messageEvent: ChatMessageEvent) => { const { message } = messageEvent; const messageLog: ChatMessage = { clientId: message.clientId, diff --git a/src/commands/rooms/occupancy/get.ts b/src/commands/rooms/occupancy/get.ts index ca2918a3e..297aa1baa 100644 --- a/src/commands/rooms/occupancy/get.ts +++ b/src/commands/rooms/occupancy/get.ts @@ -1,6 +1,6 @@ import { Args } from "@oclif/core"; import * as Ably from "ably"; -import { ChatClient, Room, OccupancyEvent } from "@ably/chat"; +import { ChatClient, Room, OccupancyData } from "@ably/chat"; import { ChatBaseCommand } from "../../../chat-base-command.js"; export default class RoomsOccupancyGet extends ChatBaseCommand { @@ -45,7 +45,7 @@ export default class RoomsOccupancyGet extends ChatBaseCommand { // Release room from chat client if (this.chatClient && this.room) { await Promise.race([ - this.chatClient.rooms.release(this.room.roomId), + this.chatClient.rooms.release(this.room.name), new Promise(resolve => setTimeout(resolve, 1000)) // 1s timeout ]); } @@ -117,9 +117,9 @@ export default class RoomsOccupancyGet extends ChatBaseCommand { // Get occupancy metrics using the Chat SDK's occupancy API const occupancyMetrics = await Promise.race([ this.room.occupancy.get(), - new Promise((_, reject) => - setTimeout(() => reject(new Error('Occupancy get timeout')), 5000) - ) + new Promise((_, reject) => + setTimeout(() => reject(new Error("Occupancy get timeout")), 5000), + ), ]); // Output the occupancy metrics based on format diff --git a/src/commands/rooms/occupancy/subscribe.ts b/src/commands/rooms/occupancy/subscribe.ts index 93b1d8c2c..a1cbf4e1a 100644 --- a/src/commands/rooms/occupancy/subscribe.ts +++ b/src/commands/rooms/occupancy/subscribe.ts @@ -1,4 +1,10 @@ -import { OccupancyEvent, RoomStatus, Subscription, RoomStatusChange, ChatClient } from "@ably/chat"; +import { + OccupancyEvent, + RoomStatus, + Subscription, + RoomStatusChange, + ChatClient, +} from "@ably/chat"; import { Args } from "@oclif/core"; import * as Ably from "ably"; import chalk from "chalk"; @@ -260,7 +266,8 @@ export default class RoomsOccupancySubscribe extends ChatBaseCommand { "Subscribing to occupancy updates", ); this.unsubscribeOccupancyFn = room.occupancy.subscribe( - (occupancyMetrics: OccupancyEvent) => { + (occupancyEvent: OccupancyEvent) => { + const occupancyMetrics = occupancyEvent.occupancy; this.logCliEvent( flags, "occupancy", diff --git a/src/commands/rooms/presence/enter.ts b/src/commands/rooms/presence/enter.ts index b4f4bf757..0430538a2 100644 --- a/src/commands/rooms/presence/enter.ts +++ b/src/commands/rooms/presence/enter.ts @@ -1,4 +1,4 @@ -import { ChatClient, Room, RoomStatus, RoomStatusChange, Subscription as ChatSubscription, StatusSubscription } from "@ably/chat"; +import { ChatClient, Room, RoomStatus, RoomStatusChange, Subscription as ChatSubscription, StatusSubscription, PresenceEvent, PresenceEventType } from "@ably/chat"; import { Args, Flags, Interfaces } from "@oclif/core"; import * as Ably from "ably"; import chalk from "chalk"; @@ -142,23 +142,24 @@ export default class RoomsPresenceEnter extends ChatBaseCommand { ); this.unsubscribePresenceFn = currentRoom.presence.subscribe( - (event) => { - if (event.clientId !== this.chatClient?.clientId) { + (event: PresenceEvent) => { + const member = event.member; + if (member.clientId !== this.chatClient?.clientId) { const timestamp = new Date().toISOString(); - const eventData = { action: event.action, member: { clientId: event.clientId, data: event.data }, roomId: this.roomId, timestamp }; - this.logCliEvent(flags, "presence", event.action, `Presence event '${event.action}' received`, eventData); + const eventData = { type: event.type, member: { clientId: member.clientId, data: member.data }, roomId: this.roomId, timestamp }; + this.logCliEvent(flags, "presence", event.type, `Presence event '${event.type}' received`, eventData); if (this.shouldOutputJson(flags)) { this.log(this.formatJsonOutput({ success: true, ...eventData }, flags)); } else { let actionSymbol = "•"; let actionColor = chalk.white; - if (event.action === "enter") { actionSymbol = "✓"; actionColor = chalk.green; } - if (event.action === "leave") { actionSymbol = "✗"; actionColor = chalk.red; } - if (event.action === "update") { actionSymbol = "⟲"; actionColor = chalk.yellow; } - this.log(`[${timestamp}] ${actionColor(actionSymbol)} ${chalk.blue(event.clientId || "Unknown")} ${actionColor(event.action)}`); - if (event.data && typeof event.data === 'object' && Object.keys(event.data).length > 0) { - const profile = event.data as { name?: string }; + if (event.type === PresenceEventType.Enter) { actionSymbol = "✓"; actionColor = chalk.green; } + if (event.type === PresenceEventType.Leave) { actionSymbol = "✗"; actionColor = chalk.red; } + if (event.type === PresenceEventType.Update) { actionSymbol = "⟲"; actionColor = chalk.yellow; } + this.log(`[${timestamp}] ${actionColor(actionSymbol)} ${chalk.blue(member.clientId || "Unknown")} ${actionColor(event.type)}`); + if (member.data && typeof member.data === 'object' && Object.keys(member.data).length > 0) { + const profile = member.data as { name?: string }; if (profile.name) { this.log(` ${chalk.dim("Name:")} ${profile.name}`); } - this.log(` ${chalk.dim("Full Profile Data:")} ${this.formatJsonOutput({ data: event.data }, flags)}`); + this.log(` ${chalk.dim("Full Profile Data:")} ${this.formatJsonOutput({ data: member.data }, flags)}`); } } } @@ -294,4 +295,3 @@ export default class RoomsPresenceEnter extends ChatBaseCommand { this.logCliEvent(flags, "connection", "AFTER_properlyCloseAblyClient", "Finished awaiting properlyCloseAblyClient."); } } - diff --git a/src/commands/rooms/presence/subscribe.ts b/src/commands/rooms/presence/subscribe.ts index bd33bbf19..0f7dd5af8 100644 --- a/src/commands/rooms/presence/subscribe.ts +++ b/src/commands/rooms/presence/subscribe.ts @@ -6,7 +6,8 @@ import { StatusSubscription, RoomStatusChange, Room, - PresenceEvent + PresenceEvent, + PresenceEventType } from "@ably/chat"; import { Args, Interfaces, Flags } from "@oclif/core"; import * as Ably from "ably"; @@ -177,20 +178,21 @@ export default class RoomsPresenceSubscribe extends ChatBaseCommand { this.logCliEvent(flags, "presence", "subscribingToEvents", "Subscribing to presence events"); this.presenceSubscription = currentRoom.presence.subscribe((event: PresenceEvent) => { const timestamp = new Date().toISOString(); - const eventData = { action: event.action, member: { clientId: event.clientId, data: event.data }, roomId: this.roomId, timestamp }; - this.logCliEvent(flags, "presence", event.action, `Presence event '${event.action}' received`, eventData); + const member = event.member; + const eventData = { type: event.type, member: { clientId: member.clientId, data: member.data }, roomId: this.roomId, timestamp }; + this.logCliEvent(flags, "presence", event.type, `Presence event '${event.type}' received`, eventData); if (this.shouldOutputJson(flags)) { this.log(this.formatJsonOutput({ success: true, ...eventData }, flags)); } else { let actionSymbol = "•"; let actionColor = chalk.white; - if (event.action === "enter") { actionSymbol = "✓"; actionColor = chalk.green; } - if (event.action === "leave") { actionSymbol = "✗"; actionColor = chalk.red; } - if (event.action === "update") { actionSymbol = "⟲"; actionColor = chalk.yellow; } - this.log(`[${timestamp}] ${actionColor(actionSymbol)} ${chalk.blue(event.clientId || "Unknown")} ${actionColor(event.action)}`); - if (event.data && typeof event.data === 'object' && Object.keys(event.data).length > 0) { - const profile = event.data as { name?: string }; + if (event.type === PresenceEventType.Enter) { actionSymbol = "✓"; actionColor = chalk.green; } + if (event.type === PresenceEventType.Leave) { actionSymbol = "✗"; actionColor = chalk.red; } + if (event.type === PresenceEventType.Update) { actionSymbol = "⟲"; actionColor = chalk.yellow; } + this.log(`[${timestamp}] ${actionColor(actionSymbol)} ${chalk.blue(member.clientId || "Unknown")} ${actionColor(event.type)}`); + if (member.data && typeof member.data === 'object' && Object.keys(member.data).length > 0) { + const profile = member.data as { name?: string }; if (profile.name) { this.log(` ${chalk.dim("Name:")} ${profile.name}`); } - this.log(` ${chalk.dim("Full Profile Data:")} ${this.formatJsonOutput({ data: event.data }, flags)}`); + this.log(` ${chalk.dim("Full Profile Data:")} ${this.formatJsonOutput({ data: member.data }, flags)}`); } } }); @@ -294,4 +296,4 @@ export default class RoomsPresenceSubscribe extends ChatBaseCommand { await this.properlyCloseAblyClient(); this.logCliEvent(flags, "connection", "clientClosedFinally", "Ably client close attempt finished."); } -} \ No newline at end of file +} diff --git a/src/commands/rooms/reactions/send.ts b/src/commands/rooms/reactions/send.ts index c4338c1a2..57e5a2bbe 100644 --- a/src/commands/rooms/reactions/send.ts +++ b/src/commands/rooms/reactions/send.ts @@ -203,7 +203,7 @@ export default class RoomsReactionsSend extends ChatBaseCommand { { emoji, metadata: this.metadataObj || {} }, ); await room.reactions.send({ - type: emoji, + name: emoji, metadata: this.metadataObj || {}, }); this.logCliEvent( diff --git a/src/commands/rooms/reactions/subscribe.ts b/src/commands/rooms/reactions/subscribe.ts index a8939cfe1..fac03e10a 100644 --- a/src/commands/rooms/reactions/subscribe.ts +++ b/src/commands/rooms/reactions/subscribe.ts @@ -1,4 +1,4 @@ -import { ChatClient, RoomStatus, Subscription } from "@ably/chat"; +import { ChatClient, RoomReactionEvent, RoomStatus, Subscription } from "@ably/chat"; import { Args } from "@oclif/core"; import * as Ably from "ably"; // Import Ably import chalk from "chalk"; @@ -186,14 +186,15 @@ export default class RoomsReactionsSubscribe extends ChatBaseCommand { "subscribing", "Subscribing to reactions", ); - this.unsubscribeReactionsFn = room.reactions.subscribe((reaction) => { + this.unsubscribeReactionsFn = room.reactions.subscribe((event: RoomReactionEvent) => { + const reaction = event.reaction; const timestamp = new Date().toISOString(); // Chat SDK doesn't provide timestamp in event const eventData = { clientId: reaction.clientId, metadata: reaction.metadata, roomId, timestamp, - type: reaction.type, + name: reaction.name, }; this.logCliEvent( flags, @@ -209,7 +210,7 @@ export default class RoomsReactionsSubscribe extends ChatBaseCommand { ); } else { this.log( - `[${chalk.dim(timestamp)}] ${chalk.green("⚡")} ${chalk.blue(reaction.clientId || "Unknown")} reacted with ${chalk.yellow(reaction.type || "unknown")}`, + `[${chalk.dim(timestamp)}] ${chalk.green("⚡")} ${chalk.blue(reaction.clientId || "Unknown")} reacted with ${chalk.yellow(reaction.name || "unknown")}`, ); // Show any additional metadata in the reaction