Skip to content

Commit d55bb64

Browse files
committed
fix(client): ensure addOutputText is called on responses.retrieve
1 parent 0ee396a commit d55bb64

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/resources/responses/responses.ts

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,18 @@ export class Responses extends APIResource {
132132
query: ResponseRetrieveParams | undefined = {},
133133
options?: RequestOptions,
134134
): APIPromise<Response> | APIPromise<Stream<ResponseStreamEvent>> {
135-
return this._client.get(path`/responses/${responseID}`, {
136-
query,
137-
...options,
138-
stream: query?.stream ?? false,
135+
return (
136+
this._client.get(path`/responses/${responseID}`, {
137+
query,
138+
...options,
139+
stream: query?.stream ?? false,
140+
}) as APIPromise<Response> | APIPromise<Stream<ResponseStreamEvent>>
141+
)._thenUnwrap((rsp) => {
142+
if ('object' in rsp && rsp.object === 'response') {
143+
addOutputText(rsp as Response);
144+
}
145+
146+
return rsp;
139147
}) as APIPromise<Response> | APIPromise<Stream<ResponseStreamEvent>>;
140148
}
141149

tests/api-resources/responses/responses.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ describe('resource responses', () => {
1717
const dataAndResponse = await responsePromise.withResponse();
1818
expect(dataAndResponse.data).toBe(response);
1919
expect(dataAndResponse.response).toBe(rawResponse);
20+
21+
expect(response).toHaveProperty('output_text');
22+
expect(typeof response.output_text).toBe('string');
2023
});
2124

2225
test('retrieve', async () => {
@@ -28,6 +31,9 @@ describe('resource responses', () => {
2831
const dataAndResponse = await responsePromise.withResponse();
2932
expect(dataAndResponse.data).toBe(response);
3033
expect(dataAndResponse.response).toBe(rawResponse);
34+
35+
expect(response).toHaveProperty('output_text');
36+
expect(typeof response.output_text).toBe('string');
3137
});
3238

3339
test('retrieve: request options and params are passed correctly', async () => {

0 commit comments

Comments
 (0)