From c82a5301573cf74fdcdd198d5fba894474eed1da Mon Sep 17 00:00:00 2001 From: ehhuang Date: Fri, 23 May 2025 14:11:29 -0700 Subject: [PATCH] Sync updates from stainless branch: ehhuang/dev --- src/index.ts | 4 + src/resources/index.ts | 2 + src/resources/responses.ts | 282 +++++++++++++++++++++++++- tests/api-resources/responses.test.ts | 32 ++- 4 files changed, 316 insertions(+), 4 deletions(-) diff --git a/src/index.ts b/src/index.ts index 5903e66..6506d63 100644 --- a/src/index.ts +++ b/src/index.ts @@ -62,6 +62,8 @@ import { ResponseCreateParams, ResponseCreateParamsNonStreaming, ResponseCreateParamsStreaming, + ResponseListParams, + ResponseListResponse, ResponseObject, ResponseObjectStream, Responses, @@ -410,9 +412,11 @@ export declare namespace LlamaStackClient { Responses as Responses, type ResponseObject as ResponseObject, type ResponseObjectStream as ResponseObjectStream, + type ResponseListResponse as ResponseListResponse, type ResponseCreateParams as ResponseCreateParams, type ResponseCreateParamsNonStreaming as ResponseCreateParamsNonStreaming, type ResponseCreateParamsStreaming as ResponseCreateParamsStreaming, + type ResponseListParams as ResponseListParams, }; export { diff --git a/src/resources/index.ts b/src/resources/index.ts index e5cb567..92f3efd 100644 --- a/src/resources/index.ts +++ b/src/resources/index.ts @@ -85,9 +85,11 @@ export { Responses, type ResponseObject, type ResponseObjectStream, + type ResponseListResponse, type ResponseCreateParams, type ResponseCreateParamsNonStreaming, type ResponseCreateParamsStreaming, + type ResponseListParams, } from './responses'; export { Routes, type ListRoutesResponse, type RouteListResponse } from './routes'; export { Safety, type RunShieldResponse, type SafetyRunShieldParams } from './safety'; diff --git a/src/resources/responses.ts b/src/resources/responses.ts index 66ffa5f..66f1f07 100644 --- a/src/resources/responses.ts +++ b/src/resources/responses.ts @@ -1,6 +1,7 @@ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details. import { APIResource } from '../resource'; +import { isRequestOptions } from '../core'; import { APIPromise } from '../core'; import * as Core from '../core'; import * as ResponsesAPI from './responses'; @@ -33,8 +34,23 @@ export class Responses extends APIResource { /** * Retrieve an OpenAI response by its ID. */ - retrieve(id: string, options?: Core.RequestOptions): Core.APIPromise { - return this._client.get(`/v1/openai/v1/responses/${id}`, options); + retrieve(responseId: string, options?: Core.RequestOptions): Core.APIPromise { + return this._client.get(`/v1/openai/v1/responses/${responseId}`, options); + } + + /** + * List all OpenAI responses. + */ + list(query?: ResponseListParams, options?: Core.RequestOptions): Core.APIPromise; + list(options?: Core.RequestOptions): Core.APIPromise; + list( + query: ResponseListParams | Core.RequestOptions = {}, + options?: Core.RequestOptions, + ): Core.APIPromise { + if (isRequestOptions(query)) { + return this.list({}, query); + } + return this._client.get('/v1/openai/v1/responses', { query, ...options }); } } @@ -163,6 +179,217 @@ export namespace ResponseObjectStream { } } +export interface ResponseListResponse { + data: Array; + + first_id: string; + + has_more: boolean; + + last_id: string; + + object: 'list'; +} + +export namespace ResponseListResponse { + export interface Data { + id: string; + + created_at: number; + + input: Array< + | Data.OpenAIResponseOutputMessageWebSearchToolCall + | Data.OpenAIResponseOutputMessageFunctionToolCall + | Data.OpenAIResponseInputFunctionToolCallOutput + | Data.OpenAIResponseMessage + >; + + model: string; + + object: 'response'; + + output: Array< + | Data.OpenAIResponseMessage + | Data.OpenAIResponseOutputMessageWebSearchToolCall + | Data.OpenAIResponseOutputMessageFunctionToolCall + >; + + parallel_tool_calls: boolean; + + status: string; + + error?: Data.Error; + + previous_response_id?: string; + + temperature?: number; + + top_p?: number; + + truncation?: string; + + user?: string; + } + + export namespace Data { + export interface OpenAIResponseOutputMessageWebSearchToolCall { + id: string; + + status: string; + + type: 'web_search_call'; + } + + export interface OpenAIResponseOutputMessageFunctionToolCall { + id: string; + + arguments: string; + + call_id: string; + + name: string; + + status: string; + + type: 'function_call'; + } + + /** + * This represents the output of a function call that gets passed back to the + * model. + */ + export interface OpenAIResponseInputFunctionToolCallOutput { + call_id: string; + + output: string; + + type: 'function_call_output'; + + id?: string; + + status?: string; + } + + /** + * Corresponds to the various Message types in the Responses API. They are all + * under one type because the Responses API gives them all the same "type" value, + * and there is no way to tell them apart in certain scenarios. + */ + export interface OpenAIResponseMessage { + content: + | string + | Array< + | OpenAIResponseMessage.OpenAIResponseInputMessageContentText + | OpenAIResponseMessage.OpenAIResponseInputMessageContentImage + > + | Array; + + role: 'system' | 'developer' | 'user' | 'assistant'; + + type: 'message'; + + id?: string; + + status?: string; + } + + export namespace OpenAIResponseMessage { + export interface OpenAIResponseInputMessageContentText { + text: string; + + type: 'input_text'; + } + + export interface OpenAIResponseInputMessageContentImage { + detail: 'low' | 'high' | 'auto'; + + type: 'input_image'; + + image_url?: string; + } + + export interface UnionMember2 { + text: string; + + type: 'output_text'; + } + } + + /** + * Corresponds to the various Message types in the Responses API. They are all + * under one type because the Responses API gives them all the same "type" value, + * and there is no way to tell them apart in certain scenarios. + */ + export interface OpenAIResponseMessage { + content: + | string + | Array< + | OpenAIResponseMessage.OpenAIResponseInputMessageContentText + | OpenAIResponseMessage.OpenAIResponseInputMessageContentImage + > + | Array; + + role: 'system' | 'developer' | 'user' | 'assistant'; + + type: 'message'; + + id?: string; + + status?: string; + } + + export namespace OpenAIResponseMessage { + export interface OpenAIResponseInputMessageContentText { + text: string; + + type: 'input_text'; + } + + export interface OpenAIResponseInputMessageContentImage { + detail: 'low' | 'high' | 'auto'; + + type: 'input_image'; + + image_url?: string; + } + + export interface UnionMember2 { + text: string; + + type: 'output_text'; + } + } + + export interface OpenAIResponseOutputMessageWebSearchToolCall { + id: string; + + status: string; + + type: 'web_search_call'; + } + + export interface OpenAIResponseOutputMessageFunctionToolCall { + id: string; + + arguments: string; + + call_id: string; + + name: string; + + status: string; + + type: 'function_call'; + } + + export interface Error { + code: string; + + message: string; + } + } +} + export type ResponseCreateParams = ResponseCreateParamsNonStreaming | ResponseCreateParamsStreaming; export interface ResponseCreateParamsBase { @@ -202,6 +429,7 @@ export interface ResponseCreateParamsBase { | ResponseCreateParams.OpenAIResponseInputToolWebSearch | ResponseCreateParams.OpenAIResponseInputToolFileSearch | ResponseCreateParams.OpenAIResponseInputToolFunction + | ResponseCreateParams.OpenAIResponseInputToolMcp >; } @@ -323,6 +551,32 @@ export namespace ResponseCreateParams { strict?: boolean; } + export interface OpenAIResponseInputToolMcp { + require_approval: 'always' | 'never' | OpenAIResponseInputToolMcp.ApprovalFilter; + + server_label: string; + + server_url: string; + + type: 'mcp'; + + allowed_tools?: Array | OpenAIResponseInputToolMcp.AllowedToolsFilter; + + headers?: Record | unknown | null>; + } + + export namespace OpenAIResponseInputToolMcp { + export interface ApprovalFilter { + always?: Array; + + never?: Array; + } + + export interface AllowedToolsFilter { + tool_names?: Array; + } + } + export type ResponseCreateParamsNonStreaming = ResponsesAPI.ResponseCreateParamsNonStreaming; export type ResponseCreateParamsStreaming = ResponsesAPI.ResponseCreateParamsStreaming; } @@ -335,12 +589,36 @@ export interface ResponseCreateParamsStreaming extends ResponseCreateParamsBase stream: true; } +export interface ResponseListParams { + /** + * The ID of the last response to return. + */ + after?: string; + + /** + * The number of responses to return. + */ + limit?: number; + + /** + * The model to filter responses by. + */ + model?: string; + + /** + * The order to sort responses by when sorted by created_at ('asc' or 'desc'). + */ + order?: 'asc' | 'desc'; +} + export declare namespace Responses { export { type ResponseObject as ResponseObject, type ResponseObjectStream as ResponseObjectStream, + type ResponseListResponse as ResponseListResponse, type ResponseCreateParams as ResponseCreateParams, type ResponseCreateParamsNonStreaming as ResponseCreateParamsNonStreaming, type ResponseCreateParamsStreaming as ResponseCreateParamsStreaming, + type ResponseListParams as ResponseListParams, }; } diff --git a/tests/api-resources/responses.test.ts b/tests/api-resources/responses.test.ts index 07f7473..f46f600 100644 --- a/tests/api-resources/responses.test.ts +++ b/tests/api-resources/responses.test.ts @@ -31,7 +31,7 @@ describe('resource responses', () => { }); test('retrieve', async () => { - const responsePromise = client.responses.retrieve('id'); + const responsePromise = client.responses.retrieve('response_id'); const rawResponse = await responsePromise.asResponse(); expect(rawResponse).toBeInstanceOf(Response); const response = await responsePromise; @@ -43,8 +43,36 @@ describe('resource responses', () => { test('retrieve: request options instead of params are passed correctly', async () => { // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error - await expect(client.responses.retrieve('id', { path: '/_stainless_unknown_path' })).rejects.toThrow( + await expect( + client.responses.retrieve('response_id', { path: '/_stainless_unknown_path' }), + ).rejects.toThrow(LlamaStackClient.NotFoundError); + }); + + test('list', async () => { + const responsePromise = client.responses.list(); + const rawResponse = await responsePromise.asResponse(); + expect(rawResponse).toBeInstanceOf(Response); + const response = await responsePromise; + expect(response).not.toBeInstanceOf(Response); + const dataAndResponse = await responsePromise.withResponse(); + expect(dataAndResponse.data).toBe(response); + expect(dataAndResponse.response).toBe(rawResponse); + }); + + test('list: request options instead of params are passed correctly', async () => { + // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error + await expect(client.responses.list({ path: '/_stainless_unknown_path' })).rejects.toThrow( LlamaStackClient.NotFoundError, ); }); + + test('list: request options and params are passed correctly', async () => { + // ensure the request options are being passed correctly by passing an invalid HTTP method in order to cause an error + await expect( + client.responses.list( + { after: 'after', limit: 0, model: 'model', order: 'asc' }, + { path: '/_stainless_unknown_path' }, + ), + ).rejects.toThrow(LlamaStackClient.NotFoundError); + }); });