chatgpt-api/stdlib/openapi-to-ts/fixtures/generated/pet-store-client.ts

95 wiersze
1.9 KiB
TypeScript
Czysty Zwykły widok Historia

/**
* This file was auto-generated from an OpenAPI spec.
*/
import {
2025-04-05 12:11:50 +00:00
aiFunction,
2025-04-06 13:26:27 +00:00
AIFunctionsProvider,
pick,
sanitizeSearchParams
} from '@agentic/core'
import defaultKy, { type KyInstance } from 'ky'
2025-04-06 13:26:27 +00:00
2025-03-25 13:50:43 +00:00
import { petstore } from './pet-store'
2025-03-22 20:28:12 +00:00
/**
* Agentic PetStore client.
*/
export class PetStoreClient extends AIFunctionsProvider {
protected readonly ky: KyInstance
protected readonly apiBaseUrl: string
constructor({
apiBaseUrl = petstore.apiBaseUrl,
ky = defaultKy
}: {
apiKey?: string
apiBaseUrl?: string
ky?: KyInstance
} = {}) {
super()
this.apiBaseUrl = apiBaseUrl
this.ky = ky.extend({
prefixUrl: apiBaseUrl
})
}
/**
* List all pets.
*/
@aiFunction({
name: 'pet_store_list_pets',
description: `List all pets.`,
2025-03-25 13:50:43 +00:00
inputSchema: petstore.ListPetsParamsSchema,
tags: ['pets']
})
async listPets(
params: petstore.ListPetsParams
): Promise<petstore.ListPetsResponse> {
return this.ky
.get('/pets', {
searchParams: sanitizeSearchParams(params)
})
.json<petstore.ListPetsResponse>()
}
/**
* Create a pet.
*/
@aiFunction({
name: 'pet_store_create_pets',
description: `Create a pet.`,
2025-03-25 13:50:43 +00:00
inputSchema: petstore.CreatePetsParamsSchema,
tags: ['pets']
})
async createPets(
params: petstore.CreatePetsParams
): Promise<petstore.CreatePetsResponse> {
return this.ky
.post('/pets', {
json: pick(params, 'id', 'name', 'tag')
})
.json<petstore.CreatePetsResponse>()
}
/**
* Info for a specific pet.
*/
@aiFunction({
name: 'pet_store_show_pet_by_id',
description: `Info for a specific pet.`,
2025-03-25 13:50:43 +00:00
inputSchema: petstore.ShowPetByIdParamsSchema,
tags: ['pets']
})
async showPetById(
params: petstore.ShowPetByIdParams
): Promise<petstore.ShowPetByIdResponse> {
return this.ky
2025-04-06 13:26:27 +00:00
.get(`/pets/${params.petId}`)
.json<petstore.ShowPetByIdResponse>()
}
}