Skip to content

Commit

Permalink
feat(stream): expose response property as well
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertCraigie committed Jan 22, 2025
1 parent db5fffe commit b0235c7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/lib/BetaMessageStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class BetaMessageStream implements AsyncIterable<BetaMessageStreamEvent>
#errored = false;
#aborted = false;
#catchingPromiseCreated = false;
#response: Response | null | undefined;
#request_id: string | null | undefined;

constructor() {
Expand All @@ -76,6 +77,10 @@ export class BetaMessageStream implements AsyncIterable<BetaMessageStreamEvent>
this.#endPromise.catch(() => {});
}

get response(): Response | null | undefined {
return this.#response;
}

get request_id(): string | null | undefined {
return this.#request_id;
}
Expand Down Expand Up @@ -183,6 +188,7 @@ export class BetaMessageStream implements AsyncIterable<BetaMessageStreamEvent>

protected _connected(response: Response | null) {
if (this.ended) return;
this.#response = response;
this.#request_id = response?.headers.get('request-id');
this.#resolveConnectedPromise(response);
this._emit('connect');
Expand Down
6 changes: 6 additions & 0 deletions src/lib/MessageStream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ export class MessageStream implements AsyncIterable<MessageStreamEvent> {
#errored = false;
#aborted = false;
#catchingPromiseCreated = false;
#response: Response | null | undefined;
#request_id: string | null | undefined;

constructor() {
Expand All @@ -76,6 +77,10 @@ export class MessageStream implements AsyncIterable<MessageStreamEvent> {
this.#endPromise.catch(() => {});
}

get response(): Response | null | undefined {
return this.#response;
}

get request_id(): string | null | undefined {
return this.#request_id;
}
Expand Down Expand Up @@ -183,6 +188,7 @@ export class MessageStream implements AsyncIterable<MessageStreamEvent> {

protected _connected(response: Response | null) {
if (this.ended) return;
this.#response = response;
this.#request_id = response?.headers.get('request-id');
this.#resolveConnectedPromise(response);
this._emit('connect');
Expand Down

0 comments on commit b0235c7

Please sign in to comment.