spitch 1.20.0 → 1.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (82) hide show
  1. package/CHANGELOG.md +20 -23
  2. package/README.md +40 -7
  3. package/client.d.mts +13 -4
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts +13 -4
  6. package/client.d.ts.map +1 -1
  7. package/client.js +11 -2
  8. package/client.js.map +1 -1
  9. package/client.mjs +13 -4
  10. package/client.mjs.map +1 -1
  11. package/core/pagination.d.mts +54 -0
  12. package/core/pagination.d.mts.map +1 -0
  13. package/core/pagination.d.ts +54 -0
  14. package/core/pagination.d.ts.map +1 -0
  15. package/core/pagination.js +101 -0
  16. package/core/pagination.js.map +1 -0
  17. package/core/pagination.mjs +95 -0
  18. package/core/pagination.mjs.map +1 -0
  19. package/index.d.mts +1 -0
  20. package/index.d.mts.map +1 -1
  21. package/index.d.ts +1 -0
  22. package/index.d.ts.map +1 -1
  23. package/index.js +3 -1
  24. package/index.js.map +1 -1
  25. package/index.mjs +1 -0
  26. package/index.mjs.map +1 -1
  27. package/internal/to-file.d.mts +1 -1
  28. package/internal/to-file.d.ts +1 -1
  29. package/internal/to-file.js +1 -1
  30. package/internal/to-file.mjs +1 -1
  31. package/internal/utils/values.js +3 -3
  32. package/internal/utils/values.js.map +1 -1
  33. package/internal/utils/values.mjs +3 -3
  34. package/internal/utils/values.mjs.map +1 -1
  35. package/package.json +14 -1
  36. package/pagination.d.mts +2 -0
  37. package/pagination.d.mts.map +1 -0
  38. package/pagination.d.ts +2 -0
  39. package/pagination.d.ts.map +1 -0
  40. package/pagination.js +6 -0
  41. package/pagination.js.map +1 -0
  42. package/pagination.mjs +2 -0
  43. package/pagination.mjs.map +1 -0
  44. package/resources/files.d.mts +74 -0
  45. package/resources/files.d.mts.map +1 -0
  46. package/resources/files.d.ts +74 -0
  47. package/resources/files.d.ts.map +1 -0
  48. package/resources/files.js +48 -0
  49. package/resources/files.js.map +1 -0
  50. package/resources/files.mjs +44 -0
  51. package/resources/files.mjs.map +1 -0
  52. package/resources/index.d.mts +3 -2
  53. package/resources/index.d.mts.map +1 -1
  54. package/resources/index.d.ts +3 -2
  55. package/resources/index.d.ts.map +1 -1
  56. package/resources/index.js +3 -1
  57. package/resources/index.js.map +1 -1
  58. package/resources/index.mjs +2 -1
  59. package/resources/index.mjs.map +1 -1
  60. package/resources/speech.d.mts +7 -6
  61. package/resources/speech.d.mts.map +1 -1
  62. package/resources/speech.d.ts +7 -6
  63. package/resources/speech.d.ts.map +1 -1
  64. package/resources/text.d.mts +5 -5
  65. package/resources/text.d.mts.map +1 -1
  66. package/resources/text.d.ts +5 -5
  67. package/resources/text.d.ts.map +1 -1
  68. package/src/client.ts +56 -17
  69. package/src/core/pagination.ts +157 -0
  70. package/src/index.ts +1 -0
  71. package/src/internal/to-file.ts +1 -1
  72. package/src/internal/utils/values.ts +3 -3
  73. package/src/pagination.ts +2 -0
  74. package/src/resources/files.ts +136 -0
  75. package/src/resources/index.ts +13 -7
  76. package/src/resources/speech.ts +8 -6
  77. package/src/resources/text.ts +6 -6
  78. package/src/version.ts +1 -1
  79. package/version.d.mts +1 -1
  80. package/version.d.ts +1 -1
  81. package/version.js +1 -1
  82. package/version.mjs +1 -1
@@ -0,0 +1,157 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { SpitchError } from './error';
4
+ import { FinalRequestOptions } from '../internal/request-options';
5
+ import { defaultParseResponse } from '../internal/parse';
6
+ import { type Spitch } from '../client';
7
+ import { APIPromise } from './api-promise';
8
+ import { type APIResponseProps } from '../internal/parse';
9
+ import { maybeObj } from '../internal/utils/values';
10
+
11
+ export type PageRequestOptions = Pick<FinalRequestOptions, 'query' | 'headers' | 'body' | 'path' | 'method'>;
12
+
13
+ export abstract class AbstractPage<Item> implements AsyncIterable<Item> {
14
+ #client: Spitch;
15
+ protected options: FinalRequestOptions;
16
+
17
+ protected response: Response;
18
+ protected body: unknown;
19
+
20
+ constructor(client: Spitch, response: Response, body: unknown, options: FinalRequestOptions) {
21
+ this.#client = client;
22
+ this.options = options;
23
+ this.response = response;
24
+ this.body = body;
25
+ }
26
+
27
+ abstract nextPageRequestOptions(): PageRequestOptions | null;
28
+
29
+ abstract getPaginatedItems(): Item[];
30
+
31
+ hasNextPage(): boolean {
32
+ const items = this.getPaginatedItems();
33
+ if (!items.length) return false;
34
+ return this.nextPageRequestOptions() != null;
35
+ }
36
+
37
+ async getNextPage(): Promise<this> {
38
+ const nextOptions = this.nextPageRequestOptions();
39
+ if (!nextOptions) {
40
+ throw new SpitchError(
41
+ 'No next page expected; please check `.hasNextPage()` before calling `.getNextPage()`.',
42
+ );
43
+ }
44
+
45
+ return await this.#client.requestAPIList(this.constructor as any, nextOptions);
46
+ }
47
+
48
+ async *iterPages(): AsyncGenerator<this> {
49
+ let page: this = this;
50
+ yield page;
51
+ while (page.hasNextPage()) {
52
+ page = await page.getNextPage();
53
+ yield page;
54
+ }
55
+ }
56
+
57
+ async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
58
+ for await (const page of this.iterPages()) {
59
+ for (const item of page.getPaginatedItems()) {
60
+ yield item;
61
+ }
62
+ }
63
+ }
64
+ }
65
+
66
+ /**
67
+ * This subclass of Promise will resolve to an instantiated Page once the request completes.
68
+ *
69
+ * It also implements AsyncIterable to allow auto-paginating iteration on an unawaited list call, eg:
70
+ *
71
+ * for await (const item of client.items.list()) {
72
+ * console.log(item)
73
+ * }
74
+ */
75
+ export class PagePromise<
76
+ PageClass extends AbstractPage<Item>,
77
+ Item = ReturnType<PageClass['getPaginatedItems']>[number],
78
+ >
79
+ extends APIPromise<PageClass>
80
+ implements AsyncIterable<Item>
81
+ {
82
+ constructor(
83
+ client: Spitch,
84
+ request: Promise<APIResponseProps>,
85
+ Page: new (...args: ConstructorParameters<typeof AbstractPage>) => PageClass,
86
+ ) {
87
+ super(
88
+ client,
89
+ request,
90
+ async (client, props) =>
91
+ new Page(client, props.response, await defaultParseResponse(client, props), props.options),
92
+ );
93
+ }
94
+
95
+ /**
96
+ * Allow auto-paginating iteration on an unawaited list call, eg:
97
+ *
98
+ * for await (const item of client.items.list()) {
99
+ * console.log(item)
100
+ * }
101
+ */
102
+ async *[Symbol.asyncIterator](): AsyncGenerator<Item> {
103
+ const page = await this;
104
+ for await (const item of page) {
105
+ yield item;
106
+ }
107
+ }
108
+ }
109
+
110
+ export interface FilesCursorResponse<Item> {
111
+ items: Array<Item>;
112
+
113
+ next_cursor: string | null;
114
+ }
115
+
116
+ export interface FilesCursorParams {
117
+ cursor?: string;
118
+
119
+ limit?: number;
120
+ }
121
+
122
+ export class FilesCursor<Item> extends AbstractPage<Item> implements FilesCursorResponse<Item> {
123
+ items: Array<Item>;
124
+
125
+ next_cursor: string | null;
126
+
127
+ constructor(
128
+ client: Spitch,
129
+ response: Response,
130
+ body: FilesCursorResponse<Item>,
131
+ options: FinalRequestOptions,
132
+ ) {
133
+ super(client, response, body, options);
134
+
135
+ this.items = body.items || [];
136
+ this.next_cursor = body.next_cursor || null;
137
+ }
138
+
139
+ getPaginatedItems(): Item[] {
140
+ return this.items ?? [];
141
+ }
142
+
143
+ nextPageRequestOptions(): PageRequestOptions | null {
144
+ const cursor = this.next_cursor;
145
+ if (!cursor) {
146
+ return null;
147
+ }
148
+
149
+ return {
150
+ ...this.options,
151
+ query: {
152
+ ...maybeObj(this.options.query),
153
+ cursor,
154
+ },
155
+ };
156
+ }
157
+ }
package/src/index.ts CHANGED
@@ -5,6 +5,7 @@ export { Spitch as default } from './client';
5
5
  export { type Uploadable, toFile } from './core/uploads';
6
6
  export { APIPromise } from './core/api-promise';
7
7
  export { Spitch, type ClientOptions } from './client';
8
+ export { PagePromise } from './core/pagination';
8
9
  export {
9
10
  SpitchError,
10
11
  APIError,
@@ -73,7 +73,7 @@ export type ToFileInput =
73
73
 
74
74
  /**
75
75
  * Helper for creating a {@link File} to pass to an SDK upload method from a variety of different data formats
76
- * @param value the raw content of the file. Can be an {@link Uploadable}, {@link BlobLikePart}, or {@link AsyncIterable} of {@link BlobLikePart}s
76
+ * @param value the raw content of the file. Can be an {@link Uploadable}, BlobLikePart, or AsyncIterable of BlobLikeParts
77
77
  * @param {string=} name the name of the file. If omitted, toFile will try to determine a file name from bits if possible
78
78
  * @param {Object=} options additional properties
79
79
  * @param {string=} options.type the MIME type of the content
@@ -76,21 +76,21 @@ export const coerceBoolean = (value: unknown): boolean => {
76
76
  };
77
77
 
78
78
  export const maybeCoerceInteger = (value: unknown): number | undefined => {
79
- if (value === undefined) {
79
+ if (value == null) {
80
80
  return undefined;
81
81
  }
82
82
  return coerceInteger(value);
83
83
  };
84
84
 
85
85
  export const maybeCoerceFloat = (value: unknown): number | undefined => {
86
- if (value === undefined) {
86
+ if (value == null) {
87
87
  return undefined;
88
88
  }
89
89
  return coerceFloat(value);
90
90
  };
91
91
 
92
92
  export const maybeCoerceBoolean = (value: unknown): boolean | undefined => {
93
- if (value === undefined) {
93
+ if (value == null) {
94
94
  return undefined;
95
95
  }
96
96
  return coerceBoolean(value);
@@ -0,0 +1,2 @@
1
+ /** @deprecated Import from ./core/pagination instead */
2
+ export * from './core/pagination';
@@ -0,0 +1,136 @@
1
+ // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
+
3
+ import { APIResource } from '../core/resource';
4
+ import { APIPromise } from '../core/api-promise';
5
+ import { FilesCursor, type FilesCursorParams, PagePromise } from '../core/pagination';
6
+ import { type Uploadable } from '../core/uploads';
7
+ import { RequestOptions } from '../internal/request-options';
8
+ import { multipartFormRequestOptions } from '../internal/uploads';
9
+ import { path } from '../internal/utils/path';
10
+
11
+ export class Files extends APIResource {
12
+ /**
13
+ * Get Files
14
+ */
15
+ list(
16
+ query: FileListParams | null | undefined = {},
17
+ options?: RequestOptions,
18
+ ): PagePromise<FilesFilesCursor, File> {
19
+ return this._client.getAPIList('/v1/files', FilesCursor<File>, { query, ...options });
20
+ }
21
+
22
+ /**
23
+ * Delete File
24
+ */
25
+ delete(fileID: string, options?: RequestOptions): APIPromise<FileDeleteResponse> {
26
+ return this._client.delete(path`/v1/files/${fileID}`, options);
27
+ }
28
+
29
+ /**
30
+ * Download File
31
+ */
32
+ download(
33
+ fileID: string,
34
+ query: FileDownloadParams | null | undefined = {},
35
+ options?: RequestOptions,
36
+ ): APIPromise<FileDownloadResponse> {
37
+ return this._client.get(path`/v1/files/${fileID}/url`, { query, ...options });
38
+ }
39
+
40
+ /**
41
+ * Get File
42
+ */
43
+ get(fileID: string, options?: RequestOptions): APIPromise<File> {
44
+ return this._client.get(path`/v1/files/${fileID}`, options);
45
+ }
46
+
47
+ /**
48
+ * Upload File
49
+ */
50
+ upload(body: FileUploadParams, options?: RequestOptions): APIPromise<File> {
51
+ return this._client.post('/v1/files', multipartFormRequestOptions({ body, ...options }, this._client));
52
+ }
53
+
54
+ /**
55
+ * Get Usage
56
+ */
57
+ usage(options?: RequestOptions): APIPromise<FileUsage> {
58
+ return this._client.get('/v1/files:usage', options);
59
+ }
60
+ }
61
+
62
+ export type FilesFilesCursor = FilesCursor<File>;
63
+
64
+ export interface File {
65
+ category: string | null;
66
+
67
+ content_type: string | null;
68
+
69
+ created_at: string;
70
+
71
+ file_id: string;
72
+
73
+ original_name: string | null;
74
+
75
+ size_bytes: number | null;
76
+
77
+ status: string;
78
+
79
+ uploaded_by: string | null;
80
+ }
81
+
82
+ export interface FileUsage {
83
+ num_files: number;
84
+
85
+ total: string;
86
+
87
+ total_bytes: number;
88
+
89
+ used: string;
90
+
91
+ used_bytes: number;
92
+ }
93
+
94
+ export interface Files {
95
+ items: Array<File>;
96
+
97
+ next_cursor?: string | null;
98
+ }
99
+
100
+ export interface FileDeleteResponse {
101
+ status?: boolean;
102
+ }
103
+
104
+ export interface FileDownloadResponse {
105
+ expires_at: string;
106
+
107
+ file_id: string;
108
+
109
+ url: string;
110
+ }
111
+
112
+ export interface FileListParams extends FilesCursorParams {
113
+ status?: 'uploading' | 'ready' | null;
114
+ }
115
+
116
+ export interface FileDownloadParams {
117
+ ttl?: number;
118
+ }
119
+
120
+ export interface FileUploadParams {
121
+ file: Uploadable;
122
+ }
123
+
124
+ export declare namespace Files {
125
+ export {
126
+ type File as File,
127
+ type FileUsage as FileUsage,
128
+ type Files as Files,
129
+ type FileDeleteResponse as FileDeleteResponse,
130
+ type FileDownloadResponse as FileDownloadResponse,
131
+ type FilesFilesCursor as FilesFilesCursor,
132
+ type FileListParams as FileListParams,
133
+ type FileDownloadParams as FileDownloadParams,
134
+ type FileUploadParams as FileUploadParams,
135
+ };
136
+ }
@@ -1,15 +1,21 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
3
  export {
4
- Speech,
5
- type SpeechTranscribeResponse,
6
- type SpeechGenerateParams,
7
- type SpeechTranscribeParams,
8
- } from './speech';
4
+ Files,
5
+ type File,
6
+ type FileUsage,
7
+ type FileDeleteResponse,
8
+ type FileDownloadResponse,
9
+ type FileListParams,
10
+ type FileDownloadParams,
11
+ type FileUploadParams,
12
+ type FilesFilesCursor,
13
+ } from './files';
14
+ export { Speech, type Transcription, type SpeechGenerateParams, type SpeechTranscribeParams } from './speech';
9
15
  export {
10
16
  Text,
11
- type TextToneMarkResponse,
12
- type TextTranslateResponse,
17
+ type Diacritics,
18
+ type Translation,
13
19
  type TextToneMarkParams,
14
20
  type TextTranslateParams,
15
21
  } from './text';
@@ -23,7 +23,7 @@ export class Speech extends APIResource {
23
23
  /**
24
24
  * Transcribe
25
25
  */
26
- transcribe(body: SpeechTranscribeParams, options?: RequestOptions): APIPromise<SpeechTranscribeResponse> {
26
+ transcribe(body: SpeechTranscribeParams, options?: RequestOptions): APIPromise<Transcription> {
27
27
  return this._client.post(
28
28
  '/v1/transcriptions',
29
29
  multipartFormRequestOptions({ body, ...options }, this._client),
@@ -31,15 +31,15 @@ export class Speech extends APIResource {
31
31
  }
32
32
  }
33
33
 
34
- export interface SpeechTranscribeResponse {
34
+ export interface Transcription {
35
35
  request_id: string;
36
36
 
37
37
  text: string;
38
38
 
39
- timestamps?: Array<SpeechTranscribeResponse.Timestamp> | null;
39
+ timestamps?: Array<Transcription.Timestamp> | null;
40
40
  }
41
41
 
42
- export namespace SpeechTranscribeResponse {
42
+ export namespace Transcription {
43
43
  export interface Timestamp {
44
44
  end: number;
45
45
 
@@ -78,6 +78,8 @@ export interface SpeechGenerateParams {
78
78
  | 'tena'
79
79
  | 'tesfaye';
80
80
 
81
+ format?: 'wav' | 'mp3' | 'ogg_opus' | 'webm_opus' | 'flac' | 'pcm_s16le' | 'mulaw' | 'alaw';
82
+
81
83
  model?: 'legacy' | null;
82
84
  }
83
85
 
@@ -86,7 +88,7 @@ export interface SpeechTranscribeParams {
86
88
 
87
89
  content?: Uploadable | null;
88
90
 
89
- model?: 'mansa_v1' | 'legacy' | null;
91
+ model?: 'mansa_v1' | 'legacy' | 'human' | null;
90
92
 
91
93
  special_words?: string | null;
92
94
 
@@ -97,7 +99,7 @@ export interface SpeechTranscribeParams {
97
99
 
98
100
  export declare namespace Speech {
99
101
  export {
100
- type SpeechTranscribeResponse as SpeechTranscribeResponse,
102
+ type Transcription as Transcription,
101
103
  type SpeechGenerateParams as SpeechGenerateParams,
102
104
  type SpeechTranscribeParams as SpeechTranscribeParams,
103
105
  };
@@ -8,25 +8,25 @@ export class Text extends APIResource {
8
8
  /**
9
9
  * Tone Mark
10
10
  */
11
- toneMark(body: TextToneMarkParams, options?: RequestOptions): APIPromise<TextToneMarkResponse> {
11
+ toneMark(body: TextToneMarkParams, options?: RequestOptions): APIPromise<Diacritics> {
12
12
  return this._client.post('/v1/diacritics', { body, ...options });
13
13
  }
14
14
 
15
15
  /**
16
16
  * Translate
17
17
  */
18
- translate(body: TextTranslateParams, options?: RequestOptions): APIPromise<TextTranslateResponse> {
18
+ translate(body: TextTranslateParams, options?: RequestOptions): APIPromise<Translation> {
19
19
  return this._client.post('/v1/translate', { body, ...options });
20
20
  }
21
21
  }
22
22
 
23
- export interface TextToneMarkResponse {
23
+ export interface Diacritics {
24
24
  request_id: string;
25
25
 
26
26
  text: string;
27
27
  }
28
28
 
29
- export interface TextTranslateResponse {
29
+ export interface Translation {
30
30
  request_id: string;
31
31
 
32
32
  text: string;
@@ -48,8 +48,8 @@ export interface TextTranslateParams {
48
48
 
49
49
  export declare namespace Text {
50
50
  export {
51
- type TextToneMarkResponse as TextToneMarkResponse,
52
- type TextTranslateResponse as TextTranslateResponse,
51
+ type Diacritics as Diacritics,
52
+ type Translation as Translation,
53
53
  type TextToneMarkParams as TextToneMarkParams,
54
54
  type TextTranslateParams as TextTranslateParams,
55
55
  };
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '1.20.0'; // x-release-please-version
1
+ export const VERSION = '1.22.0'; // x-release-please-version
package/version.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "1.20.0";
1
+ export declare const VERSION = "1.22.0";
2
2
  //# sourceMappingURL=version.d.mts.map
package/version.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare const VERSION = "1.20.0";
1
+ export declare const VERSION = "1.22.0";
2
2
  //# sourceMappingURL=version.d.ts.map
package/version.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '1.20.0'; // x-release-please-version
4
+ exports.VERSION = '1.22.0'; // x-release-please-version
5
5
  //# sourceMappingURL=version.js.map
package/version.mjs CHANGED
@@ -1,2 +1,2 @@
1
- export const VERSION = '1.20.0'; // x-release-please-version
1
+ export const VERSION = '1.22.0'; // x-release-please-version
2
2
  //# sourceMappingURL=version.mjs.map