Skip to content

Commit

Permalink
[js] Adding type to RTResponse and more fields to RTMessageItem. (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
glecaros authored Oct 28, 2024
1 parent f8d091a commit b438a09
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions javascript/standalone/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
Item,
ItemInputAudioTranscriptionCompletedMessage,
ItemInputAudioTranscriptionFailedMessage,
MessageRole,
RealtimeError,
Response,
ResponseAudioDeltaMessage,
Expand All @@ -18,6 +19,7 @@ import {
ResponseFunctionCallItem,
ResponseItem,
ResponseItemAudioContentPart,
ResponseItemStatus,
ResponseItemTextContentPart,
ResponseMessageItem,
ResponseStatus,
Expand Down Expand Up @@ -164,6 +166,7 @@ export class RTError extends Error {
type Optional<T> = T | undefined;

class RTInputAudioItem {
public type: "input_audio" = "input_audio";
public audioEndMillis: Optional<number> = undefined;
public transcription: Optional<string> = undefined;

Expand Down Expand Up @@ -464,6 +467,14 @@ class RTMessageItem implements AsyncIterable<RTMessageContent> {
return this.item.id!;
}

get role(): MessageRole {
return this.item.role;
}

get status(): ResponseItemStatus {
return this.item.status;
}

async *[Symbol.asyncIterator]() {
while (true) {
const message = await this.queue.receive(
Expand Down Expand Up @@ -600,6 +611,7 @@ export function isFunctionCallItem(
}

class RTResponse implements AsyncIterable<RTOutputItem> {
public type: "response" = "response";
private done: boolean = false;

private constructor(
Expand Down

0 comments on commit b438a09

Please sign in to comment.