Skip to content

Commit e4be941

Browse files
committed
Be sure the bot supports sendFile before going through all the trouble
1 parent e18dc76 commit e4be941

2 files changed

Lines changed: 14 additions & 5 deletions

File tree

client-js/client/client.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ export class PipecatClient extends RTVIEventEmitter {
232232
private _uiSnapshotStreamer: A11ySnapshotStreamer | undefined;
233233
private _pendingUISnapshot: A11ySnapshot | undefined;
234234

235+
private _botVersion: number[] = [0, 0, 0];
236+
235237
private _botTranscriptionWarned = false;
236238
private _llmFunctionCallWarned = false;
237239

@@ -1167,6 +1169,14 @@ export class PipecatClient extends RTVIEventEmitter {
11671169
content: string,
11681170
options: SendFileOptions = {}
11691171
) {
1172+
if (
1173+
this._botVersion[0] < 1 ||
1174+
(this._botVersion[0] === 1 && this._botVersion[1] < 3)
1175+
) {
1176+
throw new RTVIErrors.RTVIError(
1177+
"sendFile() is not supported for bot versions less than 1.3.0"
1178+
);
1179+
}
11701180
let rtvi_file = file instanceof File ? ({} as RTVIFile) : file;
11711181
let mimeType: string =
11721182
file instanceof File ? file.type : rtvi_file.format.toLowerCase();
@@ -1346,12 +1356,12 @@ export class PipecatClient extends RTVIEventEmitter {
13461356
switch (ev.type) {
13471357
case RTVIMessageType.BOT_READY: {
13481358
const data = ev.data as BotReadyData;
1349-
const botVersion = data.version
1350-
? data.version.split(".").map(Number)
1359+
this._botVersion = data.version
1360+
? (data.version.split(".").map(Number) as number[])
13511361
: [0, 0, 0];
13521362
this._botVersion = botVersion;
13531363
logger.debug(`[Pipecat Client] Bot is ready. Version: ${data.version}`);
1354-
if (botVersion[0] < 2) {
1364+
if (this._botVersion[0] < 2) {
13551365
logger.warn(
13561366
`[Pipecat Client] Bot protocol version ${data.version} is older than this client (${RTVI_PROTOCOL_VERSION}). Compatibility issues may occur.`
13571367
);

client-js/rtvi/messages.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ export type FileUrl = {
350350
export type FileId = {
351351
type: Extract<FileSourceType, "id">;
352352
id: string;
353-
}
353+
};
354354

355355
export type RTVIFile = {
356356
name?: string;
@@ -367,7 +367,6 @@ export type SendFileOptions = {
367367
custom_options?: { [key: number | string]: Serializable };
368368
};
369369

370-
371370
export type FileSupport = {
372371
formats: string[];
373372
sources: FileSourceType[];

0 commit comments

Comments
 (0)