@scenario-labs/sdk 0.2.0 → 1.0.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.
- package/CHANGELOG.md +48 -0
- package/README.md +44 -8
- package/client.d.mts +36 -16
- package/client.d.mts.map +1 -1
- package/client.d.ts +36 -16
- package/client.d.ts.map +1 -1
- package/client.js +21 -11
- package/client.js.map +1 -1
- package/client.mjs +21 -11
- package/client.mjs.map +1 -1
- package/core/pagination.d.mts +153 -0
- package/core/pagination.d.mts.map +1 -0
- package/core/pagination.d.ts +153 -0
- package/core/pagination.d.ts.map +1 -0
- package/core/pagination.js +276 -0
- package/core/pagination.js.map +1 -0
- package/core/pagination.mjs +263 -0
- package/core/pagination.mjs.map +1 -0
- package/index.d.mts +3 -0
- package/index.d.mts.map +1 -1
- package/index.d.ts +3 -0
- package/index.d.ts.map +1 -1
- package/index.js +9 -1
- package/index.js.map +1 -1
- package/index.mjs +3 -0
- package/index.mjs.map +1 -1
- package/internal/request-options.d.mts +1 -1
- package/internal/request-options.d.mts.map +1 -1
- package/internal/request-options.d.ts +1 -1
- package/internal/request-options.d.ts.map +1 -1
- package/lib/models.d.mts +34 -2
- package/lib/models.d.mts.map +1 -1
- package/lib/models.d.ts +34 -2
- package/lib/models.d.ts.map +1 -1
- package/lib/models.js +39 -2
- package/lib/models.js.map +1 -1
- package/lib/models.mjs +37 -1
- package/lib/models.mjs.map +1 -1
- package/lib/scenario.d.mts +2 -0
- package/lib/scenario.d.mts.map +1 -1
- package/lib/scenario.d.ts +2 -0
- package/lib/scenario.d.ts.map +1 -1
- package/lib/scenario.js +2 -0
- package/lib/scenario.js.map +1 -1
- package/lib/scenario.mjs +2 -0
- package/lib/scenario.mjs.map +1 -1
- package/lib/upload.d.mts +89 -0
- package/lib/upload.d.mts.map +1 -0
- package/lib/upload.d.ts +89 -0
- package/lib/upload.d.ts.map +1 -0
- package/lib/upload.js +193 -0
- package/lib/upload.js.map +1 -0
- package/lib/upload.mjs +156 -0
- package/lib/upload.mjs.map +1 -0
- package/lib/workflow.d.mts +19 -3
- package/lib/workflow.d.mts.map +1 -1
- package/lib/workflow.d.ts +19 -3
- package/lib/workflow.d.ts.map +1 -1
- package/lib/workflow.js +26 -5
- package/lib/workflow.js.map +1 -1
- package/lib/workflow.mjs +26 -5
- package/lib/workflow.mjs.map +1 -1
- package/lib/workflow_import_validator.d.mts +40 -0
- package/lib/workflow_import_validator.d.mts.map +1 -0
- package/lib/workflow_import_validator.d.ts +40 -0
- package/lib/workflow_import_validator.d.ts.map +1 -0
- package/lib/workflow_import_validator.js +69 -0
- package/lib/workflow_import_validator.js.map +1 -0
- package/lib/workflow_import_validator.mjs +64 -0
- package/lib/workflow_import_validator.mjs.map +1 -0
- package/lib/workflow_validator.d.mts +22 -0
- package/lib/workflow_validator.d.mts.map +1 -0
- package/lib/workflow_validator.d.ts +22 -0
- package/lib/workflow_validator.d.ts.map +1 -0
- package/lib/workflow_validator.js +124 -0
- package/lib/workflow_validator.js.map +1 -0
- package/lib/workflow_validator.mjs +121 -0
- package/lib/workflow_validator.mjs.map +1 -0
- package/package.json +11 -1
- package/pagination.d.mts +2 -0
- package/pagination.d.mts.map +1 -0
- package/pagination.d.ts +2 -0
- package/pagination.d.ts.map +1 -0
- package/pagination.js +6 -0
- package/pagination.js.map +1 -0
- package/pagination.mjs +2 -0
- package/pagination.mjs.map +1 -0
- package/resources/assets/assets.d.mts +631 -648
- package/resources/assets/assets.d.mts.map +1 -1
- package/resources/assets/assets.d.ts +631 -648
- package/resources/assets/assets.d.ts.map +1 -1
- package/resources/assets/assets.js +5 -4
- package/resources/assets/assets.js.map +1 -1
- package/resources/assets/assets.mjs +5 -4
- package/resources/assets/assets.mjs.map +1 -1
- package/resources/assets/index.d.mts +1 -1
- package/resources/assets/index.d.mts.map +1 -1
- package/resources/assets/index.d.ts +1 -1
- package/resources/assets/index.d.ts.map +1 -1
- package/resources/assets/index.js.map +1 -1
- package/resources/assets/index.mjs.map +1 -1
- package/resources/collections/assets.d.mts +8 -2
- package/resources/collections/assets.d.mts.map +1 -1
- package/resources/collections/assets.d.ts +8 -2
- package/resources/collections/assets.d.ts.map +1 -1
- package/resources/collections/assets.js +2 -2
- package/resources/collections/assets.js.map +1 -1
- package/resources/collections/assets.mjs +2 -2
- package/resources/collections/assets.mjs.map +1 -1
- package/resources/collections/collections.d.mts +42 -53
- package/resources/collections/collections.d.mts.map +1 -1
- package/resources/collections/collections.d.ts +42 -53
- package/resources/collections/collections.d.ts.map +1 -1
- package/resources/collections/collections.js +5 -1
- package/resources/collections/collections.js.map +1 -1
- package/resources/collections/collections.mjs +5 -1
- package/resources/collections/collections.mjs.map +1 -1
- package/resources/collections/index.d.mts +3 -3
- package/resources/collections/index.d.mts.map +1 -1
- package/resources/collections/index.d.ts +3 -3
- package/resources/collections/index.d.ts.map +1 -1
- package/resources/collections/index.js.map +1 -1
- package/resources/collections/index.mjs +2 -2
- package/resources/collections/index.mjs.map +1 -1
- package/resources/collections/models.d.mts +8 -2
- package/resources/collections/models.d.mts.map +1 -1
- package/resources/collections/models.d.ts +8 -2
- package/resources/collections/models.d.ts.map +1 -1
- package/resources/collections/models.js +2 -2
- package/resources/collections/models.js.map +1 -1
- package/resources/collections/models.mjs +2 -2
- package/resources/collections/models.mjs.map +1 -1
- package/resources/index.d.mts +7 -7
- package/resources/index.d.mts.map +1 -1
- package/resources/index.d.ts +7 -7
- package/resources/index.d.ts.map +1 -1
- package/resources/index.js.map +1 -1
- package/resources/index.mjs.map +1 -1
- package/resources/jobs.d.mts +369 -380
- package/resources/jobs.d.mts.map +1 -1
- package/resources/jobs.d.ts +369 -380
- package/resources/jobs.d.ts.map +1 -1
- package/resources/jobs.js +2 -1
- package/resources/jobs.js.map +1 -1
- package/resources/jobs.mjs +2 -1
- package/resources/jobs.mjs.map +1 -1
- package/resources/models/index.d.mts +1 -1
- package/resources/models/index.d.mts.map +1 -1
- package/resources/models/index.d.ts +1 -1
- package/resources/models/index.d.ts.map +1 -1
- package/resources/models/index.js.map +1 -1
- package/resources/models/index.mjs.map +1 -1
- package/resources/models/models.d.mts +956 -967
- package/resources/models/models.d.mts.map +1 -1
- package/resources/models/models.d.ts +956 -967
- package/resources/models/models.d.ts.map +1 -1
- package/resources/models/models.js +2 -1
- package/resources/models/models.js.map +1 -1
- package/resources/models/models.mjs +2 -1
- package/resources/models/models.mjs.map +1 -1
- package/resources/models/train.d.mts +38 -38
- package/resources/models/train.d.mts.map +1 -1
- package/resources/models/train.d.ts +38 -38
- package/resources/models/train.d.ts.map +1 -1
- package/resources/search.d.mts +215 -295
- package/resources/search.d.mts.map +1 -1
- package/resources/search.d.ts +215 -295
- package/resources/search.d.ts.map +1 -1
- package/resources/search.js +9 -2
- package/resources/search.js.map +1 -1
- package/resources/search.mjs +9 -2
- package/resources/search.mjs.map +1 -1
- package/resources/tags.d.mts +23 -35
- package/resources/tags.d.mts.map +1 -1
- package/resources/tags.d.ts +23 -35
- package/resources/tags.d.ts.map +1 -1
- package/resources/tags.js +2 -1
- package/resources/tags.js.map +1 -1
- package/resources/tags.mjs +2 -1
- package/resources/tags.mjs.map +1 -1
- package/resources/workflows.d.mts +688 -704
- package/resources/workflows.d.mts.map +1 -1
- package/resources/workflows.d.ts +688 -704
- package/resources/workflows.d.ts.map +1 -1
- package/resources/workflows.js +5 -1
- package/resources/workflows.js.map +1 -1
- package/resources/workflows.mjs +5 -1
- package/resources/workflows.mjs.map +1 -1
- package/src/client.ts +118 -15
- package/src/core/pagination.ts +497 -0
- package/src/index.ts +9 -0
- package/src/internal/request-options.ts +1 -1
- package/src/lib/models.ts +62 -2
- package/src/lib/scenario.ts +2 -0
- package/src/lib/upload.ts +250 -0
- package/src/lib/workflow.ts +39 -5
- package/src/lib/workflow_import_validator.ts +104 -0
- package/src/lib/workflow_validator.ts +167 -0
- package/src/pagination.ts +2 -0
- package/src/resources/assets/assets.ts +971 -905
- package/src/resources/assets/index.ts +3 -0
- package/src/resources/collections/assets.ts +14 -2
- package/src/resources/collections/collections.ts +49 -56
- package/src/resources/collections/index.ts +15 -2
- package/src/resources/collections/models.ts +14 -2
- package/src/resources/index.ts +10 -1
- package/src/resources/jobs.ts +613 -622
- package/src/resources/models/index.ts +1 -0
- package/src/resources/models/models.ts +1118 -1130
- package/src/resources/models/train.ts +40 -40
- package/src/resources/search.ts +239 -327
- package/src/resources/tags.ts +32 -39
- package/src/resources/workflows.ts +850 -864
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
|
@@ -0,0 +1,497 @@
|
|
|
1
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
2
|
+
|
|
3
|
+
import { ScenarioError } from './error';
|
|
4
|
+
import { FinalRequestOptions } from '../internal/request-options';
|
|
5
|
+
import { defaultParseResponse } from '../internal/parse';
|
|
6
|
+
import { type Scenario } 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: Scenario;
|
|
15
|
+
protected options: FinalRequestOptions;
|
|
16
|
+
|
|
17
|
+
protected response: Response;
|
|
18
|
+
protected body: unknown;
|
|
19
|
+
|
|
20
|
+
constructor(client: Scenario, 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 ScenarioError(
|
|
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: Scenario,
|
|
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 AssetsCursorResponse<Item> {
|
|
111
|
+
assets: Array<Item>;
|
|
112
|
+
|
|
113
|
+
nextPaginationToken: string;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export interface AssetsCursorParams {
|
|
117
|
+
paginationToken?: string;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
export class AssetsCursor<Item> extends AbstractPage<Item> implements AssetsCursorResponse<Item> {
|
|
121
|
+
assets: Array<Item>;
|
|
122
|
+
|
|
123
|
+
nextPaginationToken: string;
|
|
124
|
+
|
|
125
|
+
constructor(
|
|
126
|
+
client: Scenario,
|
|
127
|
+
response: Response,
|
|
128
|
+
body: AssetsCursorResponse<Item>,
|
|
129
|
+
options: FinalRequestOptions,
|
|
130
|
+
) {
|
|
131
|
+
super(client, response, body, options);
|
|
132
|
+
|
|
133
|
+
this.assets = body.assets || [];
|
|
134
|
+
this.nextPaginationToken = body.nextPaginationToken || '';
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
getPaginatedItems(): Item[] {
|
|
138
|
+
return this.assets ?? [];
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
nextPageRequestOptions(): PageRequestOptions | null {
|
|
142
|
+
const cursor = this.nextPaginationToken;
|
|
143
|
+
if (!cursor) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return {
|
|
148
|
+
...this.options,
|
|
149
|
+
query: {
|
|
150
|
+
...maybeObj(this.options.query),
|
|
151
|
+
paginationToken: cursor,
|
|
152
|
+
},
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
export interface SnapshotsCursorResponse<Item> {
|
|
158
|
+
snapshots: Array<Item>;
|
|
159
|
+
|
|
160
|
+
nextPaginationToken: string;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
export interface SnapshotsCursorParams {
|
|
164
|
+
paginationToken?: string;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export class SnapshotsCursor<Item> extends AbstractPage<Item> implements SnapshotsCursorResponse<Item> {
|
|
168
|
+
snapshots: Array<Item>;
|
|
169
|
+
|
|
170
|
+
nextPaginationToken: string;
|
|
171
|
+
|
|
172
|
+
constructor(
|
|
173
|
+
client: Scenario,
|
|
174
|
+
response: Response,
|
|
175
|
+
body: SnapshotsCursorResponse<Item>,
|
|
176
|
+
options: FinalRequestOptions,
|
|
177
|
+
) {
|
|
178
|
+
super(client, response, body, options);
|
|
179
|
+
|
|
180
|
+
this.snapshots = body.snapshots || [];
|
|
181
|
+
this.nextPaginationToken = body.nextPaginationToken || '';
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
getPaginatedItems(): Item[] {
|
|
185
|
+
return this.snapshots ?? [];
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
nextPageRequestOptions(): PageRequestOptions | null {
|
|
189
|
+
const cursor = this.nextPaginationToken;
|
|
190
|
+
if (!cursor) {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return {
|
|
195
|
+
...this.options,
|
|
196
|
+
query: {
|
|
197
|
+
...maybeObj(this.options.query),
|
|
198
|
+
paginationToken: cursor,
|
|
199
|
+
},
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
export interface CollectionsCursorResponse<Item> {
|
|
205
|
+
collections: Array<Item>;
|
|
206
|
+
|
|
207
|
+
nextPaginationToken: string;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
export interface CollectionsCursorParams {
|
|
211
|
+
paginationToken?: string;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
export class CollectionsCursor<Item> extends AbstractPage<Item> implements CollectionsCursorResponse<Item> {
|
|
215
|
+
collections: Array<Item>;
|
|
216
|
+
|
|
217
|
+
nextPaginationToken: string;
|
|
218
|
+
|
|
219
|
+
constructor(
|
|
220
|
+
client: Scenario,
|
|
221
|
+
response: Response,
|
|
222
|
+
body: CollectionsCursorResponse<Item>,
|
|
223
|
+
options: FinalRequestOptions,
|
|
224
|
+
) {
|
|
225
|
+
super(client, response, body, options);
|
|
226
|
+
|
|
227
|
+
this.collections = body.collections || [];
|
|
228
|
+
this.nextPaginationToken = body.nextPaginationToken || '';
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
getPaginatedItems(): Item[] {
|
|
232
|
+
return this.collections ?? [];
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
nextPageRequestOptions(): PageRequestOptions | null {
|
|
236
|
+
const cursor = this.nextPaginationToken;
|
|
237
|
+
if (!cursor) {
|
|
238
|
+
return null;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
return {
|
|
242
|
+
...this.options,
|
|
243
|
+
query: {
|
|
244
|
+
...maybeObj(this.options.query),
|
|
245
|
+
paginationToken: cursor,
|
|
246
|
+
},
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
export interface JobsCursorResponse<Item> {
|
|
252
|
+
jobs: Array<Item>;
|
|
253
|
+
|
|
254
|
+
nextPaginationToken: string;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
export interface JobsCursorParams {
|
|
258
|
+
paginationToken?: string;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
export class JobsCursor<Item> extends AbstractPage<Item> implements JobsCursorResponse<Item> {
|
|
262
|
+
jobs: Array<Item>;
|
|
263
|
+
|
|
264
|
+
nextPaginationToken: string;
|
|
265
|
+
|
|
266
|
+
constructor(
|
|
267
|
+
client: Scenario,
|
|
268
|
+
response: Response,
|
|
269
|
+
body: JobsCursorResponse<Item>,
|
|
270
|
+
options: FinalRequestOptions,
|
|
271
|
+
) {
|
|
272
|
+
super(client, response, body, options);
|
|
273
|
+
|
|
274
|
+
this.jobs = body.jobs || [];
|
|
275
|
+
this.nextPaginationToken = body.nextPaginationToken || '';
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
getPaginatedItems(): Item[] {
|
|
279
|
+
return this.jobs ?? [];
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
nextPageRequestOptions(): PageRequestOptions | null {
|
|
283
|
+
const cursor = this.nextPaginationToken;
|
|
284
|
+
if (!cursor) {
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
return {
|
|
289
|
+
...this.options,
|
|
290
|
+
query: {
|
|
291
|
+
...maybeObj(this.options.query),
|
|
292
|
+
paginationToken: cursor,
|
|
293
|
+
},
|
|
294
|
+
};
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
export interface ModelsCursorResponse<Item> {
|
|
299
|
+
models: Array<Item>;
|
|
300
|
+
|
|
301
|
+
nextPaginationToken: string;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export interface ModelsCursorParams {
|
|
305
|
+
paginationToken?: string;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
export class ModelsCursor<Item> extends AbstractPage<Item> implements ModelsCursorResponse<Item> {
|
|
309
|
+
models: Array<Item>;
|
|
310
|
+
|
|
311
|
+
nextPaginationToken: string;
|
|
312
|
+
|
|
313
|
+
constructor(
|
|
314
|
+
client: Scenario,
|
|
315
|
+
response: Response,
|
|
316
|
+
body: ModelsCursorResponse<Item>,
|
|
317
|
+
options: FinalRequestOptions,
|
|
318
|
+
) {
|
|
319
|
+
super(client, response, body, options);
|
|
320
|
+
|
|
321
|
+
this.models = body.models || [];
|
|
322
|
+
this.nextPaginationToken = body.nextPaginationToken || '';
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
getPaginatedItems(): Item[] {
|
|
326
|
+
return this.models ?? [];
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
nextPageRequestOptions(): PageRequestOptions | null {
|
|
330
|
+
const cursor = this.nextPaginationToken;
|
|
331
|
+
if (!cursor) {
|
|
332
|
+
return null;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
return {
|
|
336
|
+
...this.options,
|
|
337
|
+
query: {
|
|
338
|
+
...maybeObj(this.options.query),
|
|
339
|
+
paginationToken: cursor,
|
|
340
|
+
},
|
|
341
|
+
};
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
export interface TagsCursorResponse<Item> {
|
|
346
|
+
tags: Array<Item>;
|
|
347
|
+
|
|
348
|
+
nextPaginationToken: string;
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export interface TagsCursorParams {
|
|
352
|
+
paginationToken?: string;
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export class TagsCursor<Item> extends AbstractPage<Item> implements TagsCursorResponse<Item> {
|
|
356
|
+
tags: Array<Item>;
|
|
357
|
+
|
|
358
|
+
nextPaginationToken: string;
|
|
359
|
+
|
|
360
|
+
constructor(
|
|
361
|
+
client: Scenario,
|
|
362
|
+
response: Response,
|
|
363
|
+
body: TagsCursorResponse<Item>,
|
|
364
|
+
options: FinalRequestOptions,
|
|
365
|
+
) {
|
|
366
|
+
super(client, response, body, options);
|
|
367
|
+
|
|
368
|
+
this.tags = body.tags || [];
|
|
369
|
+
this.nextPaginationToken = body.nextPaginationToken || '';
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
getPaginatedItems(): Item[] {
|
|
373
|
+
return this.tags ?? [];
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
nextPageRequestOptions(): PageRequestOptions | null {
|
|
377
|
+
const cursor = this.nextPaginationToken;
|
|
378
|
+
if (!cursor) {
|
|
379
|
+
return null;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
return {
|
|
383
|
+
...this.options,
|
|
384
|
+
query: {
|
|
385
|
+
...maybeObj(this.options.query),
|
|
386
|
+
paginationToken: cursor,
|
|
387
|
+
},
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
export interface WorkflowsCursorResponse<Item> {
|
|
393
|
+
workflows: Array<Item>;
|
|
394
|
+
|
|
395
|
+
nextPaginationToken: string;
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
export interface WorkflowsCursorParams {
|
|
399
|
+
paginationToken?: string;
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
export class WorkflowsCursor<Item> extends AbstractPage<Item> implements WorkflowsCursorResponse<Item> {
|
|
403
|
+
workflows: Array<Item>;
|
|
404
|
+
|
|
405
|
+
nextPaginationToken: string;
|
|
406
|
+
|
|
407
|
+
constructor(
|
|
408
|
+
client: Scenario,
|
|
409
|
+
response: Response,
|
|
410
|
+
body: WorkflowsCursorResponse<Item>,
|
|
411
|
+
options: FinalRequestOptions,
|
|
412
|
+
) {
|
|
413
|
+
super(client, response, body, options);
|
|
414
|
+
|
|
415
|
+
this.workflows = body.workflows || [];
|
|
416
|
+
this.nextPaginationToken = body.nextPaginationToken || '';
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
getPaginatedItems(): Item[] {
|
|
420
|
+
return this.workflows ?? [];
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
nextPageRequestOptions(): PageRequestOptions | null {
|
|
424
|
+
const cursor = this.nextPaginationToken;
|
|
425
|
+
if (!cursor) {
|
|
426
|
+
return null;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
return {
|
|
430
|
+
...this.options,
|
|
431
|
+
query: {
|
|
432
|
+
...maybeObj(this.options.query),
|
|
433
|
+
paginationToken: cursor,
|
|
434
|
+
},
|
|
435
|
+
};
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
export interface SearchHitsOffsetResponse<Item> {
|
|
440
|
+
hits: Array<Item>;
|
|
441
|
+
|
|
442
|
+
estimatedTotalHits: number;
|
|
443
|
+
|
|
444
|
+
offset: number;
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
export interface SearchHitsOffsetParams {
|
|
448
|
+
offset?: number;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
export class SearchHitsOffset<Item> extends AbstractPage<Item> implements SearchHitsOffsetResponse<Item> {
|
|
452
|
+
hits: Array<Item>;
|
|
453
|
+
|
|
454
|
+
estimatedTotalHits: number;
|
|
455
|
+
|
|
456
|
+
offset: number;
|
|
457
|
+
|
|
458
|
+
constructor(
|
|
459
|
+
client: Scenario,
|
|
460
|
+
response: Response,
|
|
461
|
+
body: SearchHitsOffsetResponse<Item>,
|
|
462
|
+
options: FinalRequestOptions,
|
|
463
|
+
) {
|
|
464
|
+
super(client, response, body, options);
|
|
465
|
+
|
|
466
|
+
this.hits = body.hits || [];
|
|
467
|
+
this.estimatedTotalHits = body.estimatedTotalHits || 0;
|
|
468
|
+
this.offset = body.offset || 0;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
getPaginatedItems(): Item[] {
|
|
472
|
+
return this.hits ?? [];
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
nextPageRequestOptions(): PageRequestOptions | null {
|
|
476
|
+
const offset = this.offset ?? 0;
|
|
477
|
+
const length = this.getPaginatedItems().length;
|
|
478
|
+
const currentCount = offset + length;
|
|
479
|
+
|
|
480
|
+
const totalCount = this.estimatedTotalHits;
|
|
481
|
+
if (!totalCount) {
|
|
482
|
+
return null;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
if (currentCount < totalCount) {
|
|
486
|
+
return {
|
|
487
|
+
...this.options,
|
|
488
|
+
body: {
|
|
489
|
+
...maybeObj(this.options.body),
|
|
490
|
+
offset: currentCount,
|
|
491
|
+
},
|
|
492
|
+
};
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
return null;
|
|
496
|
+
}
|
|
497
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,7 @@ export { type Uploadable, toFile } from './core/uploads';
|
|
|
6
6
|
export { APIPromise } from './core/api-promise';
|
|
7
7
|
export { Scenario } from './lib/scenario';
|
|
8
8
|
export { type ClientOptions } from './client';
|
|
9
|
+
export { PagePromise } from './core/pagination';
|
|
9
10
|
export {
|
|
10
11
|
ScenarioError,
|
|
11
12
|
APIError,
|
|
@@ -23,5 +24,13 @@ export {
|
|
|
23
24
|
} from './core/error';
|
|
24
25
|
export { Job, type WaitOptions, type WithJob } from './lib/job';
|
|
25
26
|
export { EnhancedWorkflows, WorkflowEntity } from './lib/workflow';
|
|
27
|
+
export { validateWorkflowFlow } from './lib/workflow_validator';
|
|
28
|
+
export {
|
|
29
|
+
validateEditorInfo,
|
|
30
|
+
WorkflowImportError,
|
|
31
|
+
VALID_EDITOR_NODE_TYPES,
|
|
32
|
+
type WorkflowExportData,
|
|
33
|
+
type WorkflowEditorNodeType,
|
|
34
|
+
} from './lib/workflow_import_validator';
|
|
26
35
|
export { EnhancedGenerate } from './lib/generate';
|
|
27
36
|
export { EnhancedModels, EnhancedTrain } from './lib/models';
|
|
@@ -75,7 +75,7 @@ export type RequestOptions = {
|
|
|
75
75
|
*/
|
|
76
76
|
defaultBaseURL?: string | undefined;
|
|
77
77
|
|
|
78
|
-
__security?: {
|
|
78
|
+
__security?: { scBasicAuth?: boolean; scBearerAuth?: boolean };
|
|
79
79
|
|
|
80
80
|
__binaryResponse?: boolean | undefined;
|
|
81
81
|
};
|
package/src/lib/models.ts
CHANGED
|
@@ -1,8 +1,55 @@
|
|
|
1
1
|
import type { APIPromise } from '../core/api-promise';
|
|
2
2
|
import type { RequestOptions } from '../internal/request-options';
|
|
3
|
-
import {
|
|
3
|
+
import type { GenerateRunModelParams, GenerateRunModelResponse } from '../resources/generate';
|
|
4
|
+
import { Models, type ModelRetrieveParams, type ModelRetrieveResponse } from '../resources/models/models';
|
|
4
5
|
import { Train, type TrainTriggerParams, type TrainTriggerResponse } from '../resources/models/train';
|
|
5
6
|
import { type WithJob, enhanceJob } from './job';
|
|
7
|
+
// Type-only import to break the circular `scenario.ts` ↔ `models.ts` graph at runtime.
|
|
8
|
+
import type { Scenario } from './scenario';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Enhanced Model entity with helper methods.
|
|
12
|
+
* Has all original model fields plus `.run()`.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const { model } = await client.models.retrieve(modelId);
|
|
17
|
+
* const gen = await model.run({ body: { prompt: 'a red car' } });
|
|
18
|
+
* const completed = await gen.job.wait();
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export class ModelEntity {
|
|
22
|
+
/** @internal */ declare readonly _client: Scenario;
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Generate with this model. Shortcut for
|
|
26
|
+
* `client.generate.runModel(this.id, params)`.
|
|
27
|
+
*
|
|
28
|
+
* Returns an enhanced response where `response.job` has `.wait()`.
|
|
29
|
+
*/
|
|
30
|
+
run(
|
|
31
|
+
this: ModelEntity & ModelRetrieveResponse.Model,
|
|
32
|
+
params: GenerateRunModelParams,
|
|
33
|
+
options?: RequestOptions,
|
|
34
|
+
): APIPromise<WithJob<GenerateRunModelResponse>> {
|
|
35
|
+
return this._client.generate.runModel(this.id, params, options);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** @internal Create a ModelEntity wrapping raw model data. */
|
|
39
|
+
static from(
|
|
40
|
+
client: Scenario,
|
|
41
|
+
data: ModelRetrieveResponse.Model,
|
|
42
|
+
): ModelRetrieveResponse.Model & ModelEntity {
|
|
43
|
+
const entity = Object.assign(Object.create(ModelEntity.prototype), data);
|
|
44
|
+
Object.defineProperty(entity, '_client', { value: client, enumerable: false });
|
|
45
|
+
return entity;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Enhanced retrieve response where `model` has `.run()` on top of its original fields. */
|
|
50
|
+
export type EnhancedModelRetrieveResponse = Omit<ModelRetrieveResponse, 'model'> & {
|
|
51
|
+
model: ModelRetrieveResponse.Model & ModelEntity;
|
|
52
|
+
};
|
|
6
53
|
|
|
7
54
|
/**
|
|
8
55
|
* Enhanced Train resource.
|
|
@@ -20,8 +67,21 @@ export class EnhancedTrain extends Train {
|
|
|
20
67
|
|
|
21
68
|
/**
|
|
22
69
|
* Enhanced Models resource.
|
|
23
|
-
* All original methods inherited.
|
|
70
|
+
* All original methods inherited.
|
|
71
|
+
* - `train` is an {@link EnhancedTrain}
|
|
72
|
+
* - `retrieve()` returns a response where `model` has `.run()`
|
|
24
73
|
*/
|
|
25
74
|
export class EnhancedModels extends Models {
|
|
26
75
|
override train: EnhancedTrain = new EnhancedTrain(this._client);
|
|
76
|
+
|
|
77
|
+
override retrieve(
|
|
78
|
+
modelID: string,
|
|
79
|
+
query: ModelRetrieveParams | null | undefined = {},
|
|
80
|
+
options?: RequestOptions,
|
|
81
|
+
): APIPromise<EnhancedModelRetrieveResponse> {
|
|
82
|
+
return super.retrieve(modelID, query, options)._thenUnwrap((data) => ({
|
|
83
|
+
...data,
|
|
84
|
+
model: ModelEntity.from(this._client as Scenario, data.model),
|
|
85
|
+
}));
|
|
86
|
+
}
|
|
27
87
|
}
|
package/src/lib/scenario.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Scenario as BaseScenario } from '../client';
|
|
2
2
|
import { EnhancedGenerate } from './generate';
|
|
3
3
|
import { EnhancedModels } from './models';
|
|
4
|
+
import { EnhancedUploads } from './upload';
|
|
4
5
|
import { EnhancedWorkflows } from './workflow';
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -36,4 +37,5 @@ export class Scenario extends BaseScenario {
|
|
|
36
37
|
override workflows: EnhancedWorkflows = new EnhancedWorkflows(this);
|
|
37
38
|
override generate: EnhancedGenerate = new EnhancedGenerate(this);
|
|
38
39
|
override models: EnhancedModels = new EnhancedModels(this);
|
|
40
|
+
override uploads: EnhancedUploads = new EnhancedUploads(this);
|
|
39
41
|
}
|