Skip to content

Commit

Permalink
feat(api): API version 2024-11-06 (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-app[bot] authored and stainless-bot committed Nov 6, 2024
1 parent 3ab42c5 commit 2f91b22
Show file tree
Hide file tree
Showing 15 changed files with 213 additions and 141 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ yarn-error.log
codegen.log
Brewfile.lock.json
dist
/deno
dist-deno
/*.tgz
.idea/

2 changes: 1 addition & 1 deletion .stats.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
configured_endpoints: 3
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/runwayml%2Frunwayml-e9db3689e5377f05e22b2dd594ac7eea68b859b98ba4d18103ed7376dbd43a4f.yml
openapi_spec_url: https://storage.googleapis.com/stainless-sdk-openapi-specs/runwayml%2Frunwayml-256f9e345a6be31b0c9fc494e70c5ff977f52316c2a7b07f388154522e74d7bb.yml
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"license": "Apache-2.0",
"packageManager": "yarn@1.22.22",
"files": [
"*"
"**/*"
],
"private": false,
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion scripts/build
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ node scripts/utils/postprocess-files.cjs
(cd dist && node -e 'require("@runwayml/sdk")')
(cd dist && node -e 'import("@runwayml/sdk")' --input-type=module)

if command -v deno &> /dev/null && [ -e ./scripts/build-deno ]
if [ -e ./scripts/build-deno ]
then
./scripts/build-deno
fi
26 changes: 16 additions & 10 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ export class APIPromise<T> extends Promise<T> {
});
}

_thenUnwrap<U>(transform: (data: T) => U): APIPromise<U> {
return new APIPromise(this.responsePromise, async (props) => transform(await this.parseResponse(props)));
_thenUnwrap<U>(transform: (data: T, props: APIResponseProps) => U): APIPromise<U> {
return new APIPromise(this.responsePromise, async (props) =>
transform(await this.parseResponse(props), props),
);
}

/**
Expand Down Expand Up @@ -349,9 +351,13 @@ export abstract class APIClient {
delete reqHeaders['content-type'];
}

// Don't set the retry count header if it was already set or removed by the caller. We check `headers`,
// which can contain nulls, instead of `reqHeaders` to account for the removal case.
if (getHeader(headers, 'x-stainless-retry-count') === undefined) {
// Don't set the retry count header if it was already set or removed through default headers or by the
// caller. We check `defaultHeaders` and `headers`, which can contain nulls, instead of `reqHeaders` to
// account for the removal case.
if (
getHeader(defaultHeaders, 'x-stainless-retry-count') === undefined &&
getHeader(headers, 'x-stainless-retry-count') === undefined
) {
reqHeaders['x-stainless-retry-count'] = String(retryCount);
}

Expand Down Expand Up @@ -390,7 +396,7 @@ export abstract class APIClient {
error: Object | undefined,
message: string | undefined,
headers: Headers | undefined,
) {
): APIError {
return APIError.generate(status, error, message, headers);
}

Expand Down Expand Up @@ -662,17 +668,17 @@ export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
return await this.#client.requestAPIList(this.constructor as any, nextOptions);
}

async *iterPages() {
async *iterPages(): AsyncGenerator<this> {
// eslint-disable-next-line @typescript-eslint/no-this-alias
let page: AbstractPage<Item> = this;
let page: this = this;
yield page;
while (page.hasNextPage()) {
page = await page.getNextPage();
yield page;
}
}

async *[Symbol.asyncIterator]() {
async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
for await (const page of this.iterPages()) {
for (const item of page.getPaginatedItems()) {
yield item;
Expand Down Expand Up @@ -715,7 +721,7 @@ export class PagePromise<
* console.log(item)
* }
*/
async *[Symbol.asyncIterator]() {
async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
const page = await this;
for await (const item of page) {
yield item;
Expand Down
2 changes: 1 addition & 1 deletion src/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class APIError extends RunwayMLError {
errorResponse: Object | undefined,
message: string | undefined,
headers: Headers | undefined,
) {
): APIError {
if (!status) {
return new APIConnectionError({ message, cause: castToError(errorResponse) });
}
Expand Down
32 changes: 21 additions & 11 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

import * as Errors from './error';
import * as Uploads from './uploads';
import { type Agent } from './_shims/index';
import * as Core from './core';
import * as Errors from './error';
import * as Uploads from './uploads';
import * as API from './resources/index';
import {
ImageToVideo,
ImageToVideoCreateParams,
ImageToVideoCreateResponse,
} from './resources/image-to-video';
import { TaskRetrieveResponse, Tasks } from './resources/tasks';

export interface ClientOptions {
/**
Expand Down Expand Up @@ -172,7 +178,7 @@ export class RunwayML extends Core.APIClient {
static fileFromPath = Uploads.fileFromPath;
}

export const {
export {
RunwayMLError,
APIError,
APIConnectionError,
Expand All @@ -186,20 +192,24 @@ export const {
InternalServerError,
PermissionDeniedError,
UnprocessableEntityError,
} = Errors;
} from './error';

export import toFile = Uploads.toFile;
export import fileFromPath = Uploads.fileFromPath;

export namespace RunwayML {
export import RequestOptions = Core.RequestOptions;
RunwayML.Tasks = Tasks;
RunwayML.ImageToVideo = ImageToVideo;

export declare namespace RunwayML {
export type RequestOptions = Core.RequestOptions;

export import Tasks = API.Tasks;
export import TaskRetrieveResponse = API.TaskRetrieveResponse;
export { Tasks as Tasks, type TaskRetrieveResponse as TaskRetrieveResponse };

export import ImageToVideo = API.ImageToVideo;
export import ImageToVideoCreateResponse = API.ImageToVideoCreateResponse;
export import ImageToVideoCreateParams = API.ImageToVideoCreateParams;
export {
ImageToVideo as ImageToVideo,
type ImageToVideoCreateResponse as ImageToVideoCreateResponse,
type ImageToVideoCreateParams as ImageToVideoCreateParams,
};
}

export default RunwayML;
41 changes: 29 additions & 12 deletions src/resources/image-to-video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { APIResource } from '../resource';
import * as Core from '../core';
import * as ImageToVideoAPI from './image-to-video';

export class ImageToVideo extends APIResource {
/**
Expand All @@ -18,7 +17,8 @@ export class ImageToVideo extends APIResource {

export interface ImageToVideoCreateResponse {
/**
* The ID of the newly created task.
* The ID of the newly created task. Use this ID to query the task status and
* retrieve the generated video.
*/
id: string;
}
Expand All @@ -30,10 +30,11 @@ export interface ImageToVideoCreateParams {
model: 'gen3a_turbo';

/**
* A HTTPS URL pointing to an image. Images must be JPEG, PNG, or WebP and are
* limited to 16MB. Responses must include a valid `Content-Length` header.
* A HTTPS URL or data URI containing an encoded image to be used as the first
* frame of the generated video. See [our docs](/assets/inputs#images) on image
* inputs for more information.
*/
promptImage: string;
promptImage: string | Array<ImageToVideoCreateParams.PromptImage>;

/**
* The number of seconds of duration for the output video.
Expand All @@ -42,10 +43,7 @@ export interface ImageToVideoCreateParams {

promptText?: string;

/**
* The aspect ratio of the output video.
*/
ratio?: '16:9' | '9:16';
ratio?: '1280:768' | '768:1280';

/**
* If unspecified, a random number is chosen. Varying the seed integer is a way to
Expand All @@ -61,7 +59,26 @@ export interface ImageToVideoCreateParams {
watermark?: boolean;
}

export namespace ImageToVideo {
export import ImageToVideoCreateResponse = ImageToVideoAPI.ImageToVideoCreateResponse;
export import ImageToVideoCreateParams = ImageToVideoAPI.ImageToVideoCreateParams;
export namespace ImageToVideoCreateParams {
export interface PromptImage {
/**
* The position of the image in the output video. "first" will use the image as the
* first frame of the video, "last" will use the image as the last frame of the
* video.
*/
position: 'first' | 'last';

/**
* A HTTPS URL or data URI containing an encoded image. See
* [our docs](/assets/inputs#images) on image inputs for more information.
*/
uri: string;
}
}

export declare namespace ImageToVideo {
export {
type ImageToVideoCreateResponse as ImageToVideoCreateResponse,
type ImageToVideoCreateParams as ImageToVideoCreateParams,
};
}
8 changes: 6 additions & 2 deletions src/resources/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.

export { ImageToVideoCreateResponse, ImageToVideoCreateParams, ImageToVideo } from './image-to-video';
export { TaskRetrieveResponse, Tasks } from './tasks';
export {
ImageToVideo,
type ImageToVideoCreateResponse,
type ImageToVideoCreateParams,
} from './image-to-video';
export { Tasks, type TaskRetrieveResponse } from './tasks';
8 changes: 5 additions & 3 deletions src/resources/tasks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import { APIResource } from '../resource';
import * as Core from '../core';
import * as TasksAPI from './tasks';

export class Tasks extends APIResource {
/**
Expand Down Expand Up @@ -30,6 +29,9 @@ export class Tasks extends APIResource {
}

export interface TaskRetrieveResponse {
/**
* The ID of the task being returned.
*/
id: string;

/**
Expand Down Expand Up @@ -78,6 +80,6 @@ export interface TaskRetrieveResponse {
progress?: number;
}

export namespace Tasks {
export import TaskRetrieveResponse = TasksAPI.TaskRetrieveResponse;
export declare namespace Tasks {
export { type TaskRetrieveResponse as TaskRetrieveResponse };
}
2 changes: 1 addition & 1 deletion tests/api-resources/image-to-video.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('resource imageToVideo', () => {
promptImage: 'https://example.com',
duration: 5,
promptText: 'promptText',
ratio: '16:9',
ratio: '1280:768',
seed: 0,
watermark: true,
});
Expand Down
33 changes: 33 additions & 0 deletions tests/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,39 @@ describe('retries', () => {
expect(capturedRequest!.headers as Headers).not.toHaveProperty('x-stainless-retry-count');
});

test('omit retry count header by default', async () => {
let count = 0;
let capturedRequest: RequestInit | undefined;
const testFetch = async (url: RequestInfo, init: RequestInit = {}): Promise<Response> => {
count++;
if (count <= 2) {
return new Response(undefined, {
status: 429,
headers: {
'Retry-After': '0.1',
},
});
}
capturedRequest = init;
return new Response(JSON.stringify({ a: 1 }), { headers: { 'Content-Type': 'application/json' } });
};
const client = new RunwayML({
apiKey: 'My API Key',
fetch: testFetch,
maxRetries: 4,
defaultHeaders: { 'X-Stainless-Retry-Count': null },
});

expect(
await client.request({
path: '/foo',
method: 'get',
}),
).toEqual({ a: 1 });

expect(capturedRequest!.headers as Headers).not.toHaveProperty('x-stainless-retry-count');
});

test('overwrite retry count header', async () => {
let count = 0;
let capturedRequest: RequestInit | undefined;
Expand Down
11 changes: 3 additions & 8 deletions tsconfig.deno.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
{
"extends": "./tsconfig.json",
"include": ["deno"],
"include": ["dist-deno"],
"exclude": [],
"compilerOptions": {
"rootDir": "./deno",
"rootDir": "./dist-deno",
"lib": ["es2020", "DOM"],
"paths": {
"@runwayml/sdk/_shims/auto/*": ["deno/_shims/auto/*-deno"],
"@runwayml/sdk/*": ["deno/*"],
"@runwayml/sdk": ["deno/index.ts"],
},
"noEmit": true,
"declaration": true,
"declarationMap": true,
"outDir": "deno",
"outDir": "dist-deno",
"pretty": true,
"sourceMap": true
}
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"paths": {
"@runwayml/sdk/_shims/auto/*": ["src/_shims/auto/*-node"],
"@runwayml/sdk/*": ["src/*"],
"@runwayml/sdk": ["src/index.ts"],
"@runwayml/sdk": ["src/index.ts"]
},
"noEmit": true,

Expand All @@ -32,6 +32,7 @@
"noUncheckedIndexedAccess": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"isolatedModules": false,

"skipLibCheck": true
}
Expand Down
Loading

0 comments on commit 2f91b22

Please sign in to comment.