Skip to content

Commit

Permalink
feat(api): update via SDK Studio
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot committed Mar 20, 2024
1 parent 4ec746d commit f83af9e
Show file tree
Hide file tree
Showing 22 changed files with 2,189 additions and 218 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ jobs:


steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4

- name: Set up Node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '18'

Expand Down
2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
configured_endpoints: 8
configured_endpoints: 13
10 changes: 5 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
This repository uses [`yarn@v1`](https://classic.yarnpkg.com/lang/en/docs/install/#mac-stable).
Other package managers may work but are not officially supported for development.

To setup the repository, run:
To set up the repository, run:

```bash
yarn
Expand Down Expand Up @@ -42,7 +42,7 @@ If you’d like to use the repository from source, you can either install from g
To install via git:

```bash
npm install --save git+ssh://git@github.com:stainless-sdks/toddlzt-node.git
npm install git+ssh://git@github.com:stainless-sdks/toddlzt-node.git
```

Alternatively, to link a local copy of the repo:
Expand All @@ -65,10 +65,10 @@ pnpm link -—global toddlzt

## Running tests

Most tests will require you to [setup a mock server](https://github.com/stoplightio/prism) against the OpenAPI spec to run the tests.
Most tests require you to [set up a mock server](https://github.com/stoplightio/prism) against the OpenAPI spec to run the tests.

```bash
npx prism path/to/your/openapi.yml
npx prism mock path/to/your/openapi.yml
```

```bash
Expand Down Expand Up @@ -99,7 +99,7 @@ the changes aren't made through the automated pipeline, you may want to make rel

### Publish with a GitHub workflow

You can release to package managers by using [the `Publish NPM` GitHub action](https://www.github.com/stainless-sdks/toddlzt-node/actions/workflows/publish-npm.yml). This will require a setup organization or repository secret to be set up.
You can release to package managers by using [the `Publish NPM` GitHub action](https://www.github.com/stainless-sdks/toddlzt-node/actions/workflows/publish-npm.yml). This requires a setup organization or repository secret to be set up.

### Publish manually

Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@
same "printed page" as the copyright notice for easier
identification within third-party archives.

Copyright 2024 Toddlzt
Copyright 2024 Retell AI

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
Expand Down
80 changes: 40 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# Toddlzt Node API Library
# Retell AI Node API Library

[![NPM version](https://img.shields.io/npm/v/toddlzt.svg)](https://npmjs.org/package/toddlzt)

This library provides convenient access to the Toddlzt REST API from server-side TypeScript or JavaScript.
This library provides convenient access to the Retell AI REST API from server-side TypeScript or JavaScript.

The REST API documentation can be found [on www.retellai.com](https://www.retellai.com/). The full API of this library can be found in [api.md](api.md).

## Installation

```sh
npm install --save toddlzt
# or
yarn add toddlzt
npm install toddlzt
```

## Usage
Expand All @@ -20,14 +18,14 @@ The full API of this library can be found in [api.md](api.md).

<!-- prettier-ignore -->
```js
import Toddlzt from 'toddlzt';
import RetellAI from 'toddlzt';

const toddlzt = new Toddlzt();
const retellAI = new RetellAI();

async function main() {
const agentCreateResponse = await toddlzt.agents.create({
const agentCreateResponse = await retellAI.agents.create({
llm_websocket_url: 'wss://your-websocket-endpoint',
voice_id: '11labs-Ryan',
voice_id: '11labs-Adrian',
});

console.log(agentCreateResponse.agent_id);
Expand All @@ -42,16 +40,16 @@ This library includes TypeScript definitions for all request params and response

<!-- prettier-ignore -->
```ts
import Toddlzt from 'toddlzt';
import RetellAI from 'toddlzt';

const toddlzt = new Toddlzt();
const retellAI = new RetellAI();

async function main() {
const params: Toddlzt.AgentCreateParams = {
const params: RetellAI.AgentCreateParams = {
llm_websocket_url: 'wss://your-websocket-endpoint',
voice_id: '11labs-Ryan',
voice_id: '11labs-Adrian',
};
const agentCreateResponse: Toddlzt.AgentCreateResponse = await toddlzt.agents.create(params);
const agentCreateResponse: RetellAI.AgentCreateResponse = await retellAI.agents.create(params);
}

main();
Expand All @@ -68,10 +66,10 @@ a subclass of `APIError` will be thrown:
<!-- prettier-ignore -->
```ts
async function main() {
const agentCreateResponse = await toddlzt.agents
.create({ llm_websocket_url: 'wss://your-websocket-endpoint', voice_id: '11labs-Ryan' })
.catch((err) => {
if (err instanceof Toddlzt.APIError) {
const agentCreateResponse = await retellAI.agents
.create({ llm_websocket_url: 'wss://your-websocket-endpoint', voice_id: '11labs-Adrian' })
.catch(async (err) => {
if (err instanceof RetellAI.APIError) {
console.log(err.status); // 400
console.log(err.name); // BadRequestError
console.log(err.headers); // {server: 'nginx', ...}
Expand Down Expand Up @@ -108,12 +106,12 @@ You can use the `maxRetries` option to configure or disable this:
<!-- prettier-ignore -->
```js
// Configure the default for all requests:
const toddlzt = new Toddlzt({
const retellAI = new RetellAI({
maxRetries: 0, // default is 2
});

// Or, configure per-request:
await toddlzt.agents.create({ llm_websocket_url: 'wss://your-websocket-endpoint', voice_id: '11labs-Ryan' }, {
await retellAI.agents.create({ llm_websocket_url: 'wss://your-websocket-endpoint', voice_id: '11labs-Adrian' }, {
maxRetries: 5,
});
```
Expand All @@ -125,12 +123,12 @@ Requests time out after 1 minute by default. You can configure this with a `time
<!-- prettier-ignore -->
```ts
// Configure the default for all requests:
const toddlzt = new Toddlzt({
const retellAI = new RetellAI({
timeout: 20 * 1000, // 20 seconds (default is 1 minute)
});

// Override per-request:
await toddlzt.agents.create({ llm_websocket_url: 'wss://your-websocket-endpoint', voice_id: '11labs-Ryan' }, {
await retellAI.agents.create({ llm_websocket_url: 'wss://your-websocket-endpoint', voice_id: '11labs-Adrian' }, {
timeout: 5 * 1000,
});
```
Expand All @@ -149,16 +147,16 @@ You can also use the `.withResponse()` method to get the raw `Response` along wi

<!-- prettier-ignore -->
```ts
const toddlzt = new Toddlzt();
const retellAI = new RetellAI();

const response = await toddlzt.agents
.create({ llm_websocket_url: 'wss://your-websocket-endpoint', voice_id: '11labs-Ryan' })
const response = await retellAI.agents
.create({ llm_websocket_url: 'wss://your-websocket-endpoint', voice_id: '11labs-Adrian' })
.asResponse();
console.log(response.headers.get('X-My-Header'));
console.log(response.statusText); // access the underlying Response object

const { data: agentCreateResponse, response: raw } = await toddlzt.agents
.create({ llm_websocket_url: 'wss://your-websocket-endpoint', voice_id: '11labs-Ryan' })
const { data: agentCreateResponse, response: raw } = await retellAI.agents
.create({ llm_websocket_url: 'wss://your-websocket-endpoint', voice_id: '11labs-Adrian' })
.withResponse();
console.log(raw.headers.get('X-My-Header'));
console.log(agentCreateResponse.agent_id);
Expand All @@ -170,27 +168,27 @@ By default, this library uses `node-fetch` in Node, and expects a global `fetch`

If you would prefer to use a global, web-standards-compliant `fetch` function even in a Node environment,
(for example, if you are running Node with `--experimental-fetch` or using NextJS which polyfills with `undici`),
add the following import before your first import `from "Toddlzt"`:
add the following import before your first import `from "RetellAI"`:

```ts
// Tell TypeScript and the package to use the global web fetch instead of node-fetch.
// Note, despite the name, this does not add any polyfills, but expects them to be provided if needed.
import 'toddlzt/shims/web';
import Toddlzt from 'toddlzt';
import RetellAI from 'toddlzt';
```

To do the inverse, add `import "toddlzt/shims/node"` (which does import polyfills).
This can also be useful if you are getting the wrong TypeScript types for `Response` more details [here](https://github.com/stainless-sdks/tree/main/src/_shims#readme).
This can also be useful if you are getting the wrong TypeScript types for `Response` ([more details](https://github.com/stainless-sdks/tree/main/src/_shims#readme)).

You may also provide a custom `fetch` function when instantiating the client,
which can be used to inspect or alter the `Request` or `Response` before/after each request:

```ts
import { fetch } from 'undici'; // as one example
import Toddlzt from 'toddlzt';
import RetellAI from 'toddlzt';

const client = new Toddlzt({
fetch: async (url: RequestInfo, init?: RequestInfo): Promise<Response> => {
const client = new RetellAI({
fetch: async (url: RequestInfo, init?: RequestInit): Promise<Response> => {
console.log('About to make a request', url, init);
const response = await fetch(url, init);
console.log('Got response', response);
Expand All @@ -211,18 +209,20 @@ If you would like to disable or customize this behavior, for example to use the
<!-- prettier-ignore -->
```ts
import http from 'http';
import HttpsProxyAgent from 'https-proxy-agent';
import { HttpsProxyAgent } from 'https-proxy-agent';

// Configure the default for all requests:
const toddlzt = new Toddlzt({
const retellAI = new RetellAI({
httpAgent: new HttpsProxyAgent(process.env.PROXY_URL),
});

// Override per-request:
await toddlzt.agents.create({ llm_websocket_url: 'wss://your-websocket-endpoint', voice_id: '11labs-Ryan' }, {
baseURL: 'http://localhost:8080/test-api',
httpAgent: new http.Agent({ keepAlive: false }),
})
await retellAI.agents.create(
{ llm_websocket_url: 'wss://your-websocket-endpoint', voice_id: '11labs-Adrian' },
{
httpAgent: new http.Agent({ keepAlive: false }),
},
);
```

## Semantic Versioning
Expand All @@ -244,7 +244,7 @@ TypeScript >= 4.5 is supported.
The following runtimes are supported:

- Node.js 18 LTS or later ([non-EOL](https://endoflife.date/nodejs)) versions.
- Deno v1.28.0 or higher, using `import Toddlzt from "npm:toddlzt"`.
- Deno v1.28.0 or higher, using `import RetellAI from "npm:toddlzt"`.
- Bun 1.0 or later.
- Cloudflare Workers.
- Vercel Edge Runtime.
Expand Down
17 changes: 17 additions & 0 deletions api.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,20 @@ Methods:
- <code title="patch /update-agent/{agent_id}">client.agents.<a href="./src/resources/agents.ts">update</a>(agentId, { ...params }) -> AgentUpdateResponse</code>
- <code title="get /list-agents">client.agents.<a href="./src/resources/agents.ts">list</a>() -> AgentListResponse</code>
- <code title="delete /delete-agent/{agent_id}">client.agents.<a href="./src/resources/agents.ts">delete</a>(agentId) -> void</code>

# Llm

Types:

- <code><a href="./src/resources/llm.ts">LlmCreateResponse</a></code>
- <code><a href="./src/resources/llm.ts">LlmRetrieveResponse</a></code>
- <code><a href="./src/resources/llm.ts">LlmUpdateResponse</a></code>
- <code><a href="./src/resources/llm.ts">LlmListResponse</a></code>

Methods:

- <code title="post /create-retell-llm">client.llm.<a href="./src/resources/llm.ts">create</a>({ ...params }) -> LlmCreateResponse</code>
- <code title="get /get-retell-llm/{llm_id}">client.llm.<a href="./src/resources/llm.ts">retrieve</a>(llmId) -> LlmRetrieveResponse</code>
- <code title="patch /update-retell-llm/{llm_id}">client.llm.<a href="./src/resources/llm.ts">update</a>(llmId, { ...params }) -> LlmUpdateResponse</code>
- <code title="get /list-retell-llm">client.llm.<a href="./src/resources/llm.ts">list</a>() -> LlmListResponse</code>
- <code title="delete /delete-retell-llm/{llm_id}">client.llm.<a href="./src/resources/llm.ts">delete</a>(llmId) -> void</code>
2 changes: 1 addition & 1 deletion build
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ npm exec tsc-multi
# copy over handwritten .js/.mjs/.d.ts files
cp src/_shims/*.{d.ts,js,mjs,md} dist/_shims
cp src/_shims/auto/*.{d.ts,js,mjs} dist/_shims/auto
# we need to add exports = module.exports = Toddlzt Node to index.js;
# we need to add exports = module.exports = Retell AI Node to index.js;
# No way to get that from index.ts because it would cause compile errors
# when building .mjs
node scripts/fix-index-exports.cjs
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "toddlzt",
"version": "0.0.1-alpha.0",
"description": "The official TypeScript library for the Toddlzt API",
"author": "Toddlzt <founders@retellai.com>",
"description": "The official TypeScript library for the Retell AI API",
"author": "Retell AI <founders@retellai.com>",
"types": "dist/index.d.ts",
"main": "dist/index.js",
"type": "commonjs",
Expand Down
20 changes: 10 additions & 10 deletions src/core.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { VERSION } from './version';
import {
ToddlztError,
RetellAIError,
APIError,
APIConnectionError,
APIConnectionTimeoutError,
Expand Down Expand Up @@ -472,7 +472,7 @@ export abstract class APIClient {
if (value === null) {
return `${encodeURIComponent(key)}=`;
}
throw new ToddlztError(
throw new RetellAIError(
`Cannot stringify type ${typeof value}; Expected string, number, boolean, or null. If you need to pass nested query parameters, you can manually encode them, e.g. { query: { 'foo[key1]': value1, 'foo[key2]': value2 } }, and please open a GitHub issue requesting better support for your use case.`,
);
})
Expand Down Expand Up @@ -618,7 +618,7 @@ export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
async getNextPage(): Promise<this> {
const nextInfo = this.nextPageInfo();
if (!nextInfo) {
throw new ToddlztError(
throw new RetellAIError(
'No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.',
);
}
Expand Down Expand Up @@ -948,10 +948,10 @@ export const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve

const validatePositiveInteger = (name: string, n: unknown): number => {
if (typeof n !== 'number' || !Number.isInteger(n)) {
throw new ToddlztError(`${name} must be an integer`);
throw new RetellAIError(`${name} must be an integer`);
}
if (n < 0) {
throw new ToddlztError(`${name} must be a positive integer`);
throw new RetellAIError(`${name} must be a positive integer`);
}
return n;
};
Expand All @@ -962,7 +962,7 @@ export const castToError = (err: any): Error => {
};

export const ensurePresent = <T>(value: T | null | undefined): T => {
if (value == null) throw new ToddlztError(`Expected a value to be given but received ${value} instead.`);
if (value == null) throw new RetellAIError(`Expected a value to be given but received ${value} instead.`);
return value;
};

Expand All @@ -987,14 +987,14 @@ export const coerceInteger = (value: unknown): number => {
if (typeof value === 'number') return Math.round(value);
if (typeof value === 'string') return parseInt(value, 10);

throw new ToddlztError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
throw new RetellAIError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
};

export const coerceFloat = (value: unknown): number => {
if (typeof value === 'number') return value;
if (typeof value === 'string') return parseFloat(value);

throw new ToddlztError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
throw new RetellAIError(`Could not coerce ${value} (type: ${typeof value}) into a number`);
};

export const coerceBoolean = (value: unknown): boolean => {
Expand Down Expand Up @@ -1060,7 +1060,7 @@ function applyHeadersMut(targetHeaders: Headers, newHeaders: Headers): void {

export function debug(action: string, ...args: any[]) {
if (typeof process !== 'undefined' && process.env['DEBUG'] === 'true') {
console.log(`Toddlzt:DEBUG:${action}`, ...args);
console.log(`RetellAI:DEBUG:${action}`, ...args);
}
}

Expand Down Expand Up @@ -1137,7 +1137,7 @@ export const toBase64 = (str: string | null | undefined): string => {
return btoa(str);
}

throw new ToddlztError('Cannot generate b64 string; Expected `Buffer` or `btoa` to be defined');
throw new RetellAIError('Cannot generate b64 string; Expected `Buffer` or `btoa` to be defined');
};

export function isObj(obj: unknown): obj is Record<string, unknown> {
Expand Down
Loading

0 comments on commit f83af9e

Please sign in to comment.