@scenario-labs/sdk 0.2.0 → 0.3.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 (115) hide show
  1. package/CHANGELOG.md +26 -0
  2. package/README.md +4 -2
  3. package/client.d.mts +4 -4
  4. package/client.d.mts.map +1 -1
  5. package/client.d.ts +4 -4
  6. package/client.d.ts.map +1 -1
  7. package/client.js +11 -11
  8. package/client.js.map +1 -1
  9. package/client.mjs +11 -11
  10. package/client.mjs.map +1 -1
  11. package/index.d.mts +1 -0
  12. package/index.d.mts.map +1 -1
  13. package/index.d.ts +1 -0
  14. package/index.d.ts.map +1 -1
  15. package/index.js +3 -1
  16. package/index.js.map +1 -1
  17. package/index.mjs +1 -0
  18. package/index.mjs.map +1 -1
  19. package/internal/request-options.d.mts +1 -1
  20. package/internal/request-options.d.mts.map +1 -1
  21. package/internal/request-options.d.ts +1 -1
  22. package/internal/request-options.d.ts.map +1 -1
  23. package/lib/workflow.d.mts +6 -1
  24. package/lib/workflow.d.mts.map +1 -1
  25. package/lib/workflow.d.ts +6 -1
  26. package/lib/workflow.d.ts.map +1 -1
  27. package/lib/workflow.js +9 -1
  28. package/lib/workflow.js.map +1 -1
  29. package/lib/workflow.mjs +9 -1
  30. package/lib/workflow.mjs.map +1 -1
  31. package/lib/workflow_validator.d.mts +22 -0
  32. package/lib/workflow_validator.d.mts.map +1 -0
  33. package/lib/workflow_validator.d.ts +22 -0
  34. package/lib/workflow_validator.d.ts.map +1 -0
  35. package/lib/workflow_validator.js +124 -0
  36. package/lib/workflow_validator.js.map +1 -0
  37. package/lib/workflow_validator.mjs +121 -0
  38. package/lib/workflow_validator.mjs.map +1 -0
  39. package/package.json +1 -1
  40. package/resources/assets/assets.d.mts +9 -3
  41. package/resources/assets/assets.d.mts.map +1 -1
  42. package/resources/assets/assets.d.ts +9 -3
  43. package/resources/assets/assets.d.ts.map +1 -1
  44. package/resources/assets/assets.js +2 -2
  45. package/resources/assets/assets.js.map +1 -1
  46. package/resources/assets/assets.mjs +2 -2
  47. package/resources/assets/assets.mjs.map +1 -1
  48. package/resources/assets/index.d.mts +1 -1
  49. package/resources/assets/index.d.mts.map +1 -1
  50. package/resources/assets/index.d.ts +1 -1
  51. package/resources/assets/index.d.ts.map +1 -1
  52. package/resources/assets/index.js.map +1 -1
  53. package/resources/assets/index.mjs.map +1 -1
  54. package/resources/collections/assets.d.mts +8 -2
  55. package/resources/collections/assets.d.mts.map +1 -1
  56. package/resources/collections/assets.d.ts +8 -2
  57. package/resources/collections/assets.d.ts.map +1 -1
  58. package/resources/collections/assets.js +2 -2
  59. package/resources/collections/assets.js.map +1 -1
  60. package/resources/collections/assets.mjs +2 -2
  61. package/resources/collections/assets.mjs.map +1 -1
  62. package/resources/collections/collections.d.mts +4 -4
  63. package/resources/collections/collections.d.mts.map +1 -1
  64. package/resources/collections/collections.d.ts +4 -4
  65. package/resources/collections/collections.d.ts.map +1 -1
  66. package/resources/collections/collections.js.map +1 -1
  67. package/resources/collections/collections.mjs.map +1 -1
  68. package/resources/collections/index.d.mts +2 -2
  69. package/resources/collections/index.d.mts.map +1 -1
  70. package/resources/collections/index.d.ts +2 -2
  71. package/resources/collections/index.d.ts.map +1 -1
  72. package/resources/collections/index.js.map +1 -1
  73. package/resources/collections/index.mjs +2 -2
  74. package/resources/collections/index.mjs.map +1 -1
  75. package/resources/collections/models.d.mts +8 -2
  76. package/resources/collections/models.d.mts.map +1 -1
  77. package/resources/collections/models.d.ts +8 -2
  78. package/resources/collections/models.d.ts.map +1 -1
  79. package/resources/collections/models.js +2 -2
  80. package/resources/collections/models.js.map +1 -1
  81. package/resources/collections/models.mjs +2 -2
  82. package/resources/collections/models.mjs.map +1 -1
  83. package/resources/index.d.mts +1 -1
  84. package/resources/index.d.mts.map +1 -1
  85. package/resources/index.d.ts +1 -1
  86. package/resources/index.d.ts.map +1 -1
  87. package/resources/index.js.map +1 -1
  88. package/resources/index.mjs.map +1 -1
  89. package/resources/models/models.d.mts +133 -133
  90. package/resources/models/models.d.mts.map +1 -1
  91. package/resources/models/models.d.ts +133 -133
  92. package/resources/models/models.d.ts.map +1 -1
  93. package/resources/models/train.d.mts +38 -38
  94. package/resources/models/train.d.mts.map +1 -1
  95. package/resources/models/train.d.ts +38 -38
  96. package/resources/models/train.d.ts.map +1 -1
  97. package/src/client.ts +15 -13
  98. package/src/index.ts +1 -0
  99. package/src/internal/request-options.ts +1 -1
  100. package/src/lib/workflow.ts +10 -1
  101. package/src/lib/workflow_validator.ts +167 -0
  102. package/src/resources/assets/assets.ts +84 -3
  103. package/src/resources/assets/index.ts +1 -0
  104. package/src/resources/collections/assets.ts +14 -2
  105. package/src/resources/collections/collections.ts +4 -2
  106. package/src/resources/collections/index.ts +14 -2
  107. package/src/resources/collections/models.ts +14 -2
  108. package/src/resources/index.ts +1 -0
  109. package/src/resources/models/models.ts +140 -140
  110. package/src/resources/models/train.ts +40 -40
  111. package/src/version.ts +1 -1
  112. package/version.d.mts +1 -1
  113. package/version.d.ts +1 -1
  114. package/version.js +1 -1
  115. package/version.mjs +1 -1
@@ -0,0 +1,167 @@
1
+ const VALID_NODE_TYPES = new Set([
2
+ 'custom-model',
3
+ 'for-each',
4
+ 'generate-prompt',
5
+ 'list',
6
+ 'logic',
7
+ 'model',
8
+ 'remove-background',
9
+ 'transform',
10
+ 'user-approval',
11
+ 'workflow',
12
+ ]);
13
+
14
+ type RawRef = {
15
+ node?: unknown;
16
+ conditional?: unknown;
17
+ };
18
+
19
+ type RawInput = {
20
+ name?: unknown;
21
+ ref?: RawRef;
22
+ items?: unknown[][];
23
+ };
24
+
25
+ type RawNode = {
26
+ id?: unknown;
27
+ type?: unknown;
28
+ modelId?: unknown;
29
+ workflowId?: unknown;
30
+ logicType?: unknown;
31
+ loopBodyNodeIds?: unknown;
32
+ count?: unknown;
33
+ dependsOn?: unknown;
34
+ inputs?: unknown;
35
+ };
36
+
37
+ /**
38
+ * Validates the structural integrity of a workflow flow (array of nodes).
39
+ *
40
+ * Throws an `Error` with a human-readable message on the first violation found.
41
+ *
42
+ * Checks performed:
43
+ * 1. Every node has a non-empty string `id`
44
+ * 2. Node IDs are unique within the flow
45
+ * 3. Every node `type` is a recognized workflow node type
46
+ * 4. Per-type required fields:
47
+ * - custom-model → modelId
48
+ * - workflow → workflowId
49
+ * - logic → logicType
50
+ * - for-each → loopBodyNodeIds (non-empty) OR count (>0)
51
+ * 5. Cross-references all point to node IDs that exist in the flow:
52
+ * - dependsOn entries
53
+ * - input ref.node (excluding "workflow" which is a reserved keyword)
54
+ * - input ref.conditional entries
55
+ * - loopBodyNodeIds entries
56
+ */
57
+ export function validateWorkflowFlow(flow: unknown[]): void {
58
+ const nodeIds = new Set<string>();
59
+ const firstSeenAt = new Map<string, number>();
60
+
61
+ // Pass 1 — per-node checks (ID, type, required fields)
62
+ for (let i = 0; i < flow.length; i++) {
63
+ const node = flow[i] as RawNode;
64
+
65
+ if (typeof node.id !== 'string' || !node.id) {
66
+ throw new Error(`Node at index ${i} is missing an "id" field`);
67
+ }
68
+ if (nodeIds.has(node.id)) {
69
+ throw new Error(
70
+ `Duplicate node id "${node.id}" at index ${i} (first seen at index ${firstSeenAt.get(node.id)})`,
71
+ );
72
+ }
73
+ nodeIds.add(node.id);
74
+ firstSeenAt.set(node.id, i);
75
+
76
+ const label = `"${node.id}"`;
77
+
78
+ if (typeof node.type !== 'string' || !VALID_NODE_TYPES.has(node.type)) {
79
+ throw new Error(
80
+ `Node ${label} has invalid type "${node.type}". Valid types are: ${[...VALID_NODE_TYPES].join(', ')}`,
81
+ );
82
+ }
83
+
84
+ const type = node.type;
85
+
86
+ if (type === 'custom-model' && !node.modelId) {
87
+ throw new Error(`Node ${label} (custom-model) is missing required field "modelId"`);
88
+ }
89
+ if (type === 'workflow' && !node.workflowId) {
90
+ throw new Error(`Node ${label} (workflow) is missing required field "workflowId"`);
91
+ }
92
+ if (type === 'logic' && !node.logicType) {
93
+ throw new Error(`Node ${label} (logic) is missing required field "logicType"`);
94
+ }
95
+ if (type === 'for-each') {
96
+ const hasLoopBody = Array.isArray(node.loopBodyNodeIds) && node.loopBodyNodeIds.length > 0;
97
+ const hasCount = typeof node.count === 'number' && node.count > 0;
98
+ if (!hasLoopBody && !hasCount) {
99
+ throw new Error(
100
+ `Node ${label} (for-each) requires either "loopBodyNodeIds" (non-empty array) or "count" (positive number)`,
101
+ );
102
+ }
103
+ }
104
+ }
105
+
106
+ // Pass 2 — cross-reference checks (all node IDs are now collected)
107
+ for (const rawNode of flow) {
108
+ const node = rawNode as RawNode;
109
+ const nodeId = node.id as string;
110
+
111
+ if (Array.isArray(node.dependsOn)) {
112
+ for (const depId of node.dependsOn) {
113
+ if (typeof depId === 'string' && !nodeIds.has(depId)) {
114
+ throw new Error(`Node "${nodeId}" dependsOn unknown node "${depId}"`);
115
+ }
116
+ }
117
+ }
118
+
119
+ if (Array.isArray(node.inputs)) {
120
+ for (const input of node.inputs) {
121
+ validateInputRefs(nodeId, input as RawInput, nodeIds);
122
+ }
123
+ }
124
+
125
+ if (Array.isArray(node.loopBodyNodeIds)) {
126
+ for (const bodyId of node.loopBodyNodeIds as unknown[]) {
127
+ if (typeof bodyId === 'string' && !nodeIds.has(bodyId)) {
128
+ throw new Error(`Node "${nodeId}" loopBodyNodeIds references unknown node "${bodyId}"`);
129
+ }
130
+ }
131
+ }
132
+ }
133
+ }
134
+
135
+ function validateInputRefs(nodeId: string, input: RawInput, nodeIds: Set<string>): void {
136
+ const inputName = typeof input.name === 'string' && input.name ? input.name : '(unnamed)';
137
+
138
+ if (input.ref) {
139
+ const { node: refNode, conditional } = input.ref;
140
+
141
+ // "workflow" is a reserved keyword meaning "take from the workflow's own inputs"
142
+ if (typeof refNode === 'string' && refNode !== 'workflow' && !nodeIds.has(refNode)) {
143
+ throw new Error(`Node "${nodeId}" input "${inputName}" references unknown node "${refNode}"`);
144
+ }
145
+
146
+ if (Array.isArray(conditional)) {
147
+ for (const condId of conditional) {
148
+ if (typeof condId === 'string' && !nodeIds.has(condId)) {
149
+ throw new Error(
150
+ `Node "${nodeId}" input "${inputName}" has a conditional ref pointing to unknown node "${condId}"`,
151
+ );
152
+ }
153
+ }
154
+ }
155
+ }
156
+
157
+ // Recurse into INPUTS_ARRAY sub-inputs
158
+ if (Array.isArray(input.items)) {
159
+ for (const item of input.items) {
160
+ if (Array.isArray(item)) {
161
+ for (const subInput of item) {
162
+ validateInputRefs(nodeId, subInput as RawInput, nodeIds);
163
+ }
164
+ }
165
+ }
166
+ }
167
+ }
@@ -60,8 +60,8 @@ export class Assets extends APIResource {
60
60
  /**
61
61
  * Delete multiple assets
62
62
  */
63
- deleteMultiple(options?: RequestOptions): APIPromise<unknown> {
64
- return this._client.delete('/assets', options);
63
+ deleteMultiple(body: AssetDeleteMultipleParams, options?: RequestOptions): APIPromise<unknown> {
64
+ return this._client.delete('/assets', { body, ...options });
65
65
  }
66
66
 
67
67
  /**
@@ -10274,7 +10274,80 @@ export interface AssetListParams {
10274
10274
  * img2img, txt2video, uploaded, uploaded-video, uploaded-audio, uploaded-3d,
10275
10275
  * uploaded-avatar, upscale-video
10276
10276
  */
10277
- types?: string;
10277
+ types?:
10278
+ | 'inference-txt2img'
10279
+ | 'inference-txt2img-ip-adapter'
10280
+ | 'inference-txt2img-texture'
10281
+ | 'inference-img2img'
10282
+ | 'inference-img2img-ip-adapter'
10283
+ | 'inference-img2img-texture'
10284
+ | 'inference-inpaint'
10285
+ | 'inference-inpaint-ip-adapter'
10286
+ | 'inference-reference'
10287
+ | 'inference-reference-texture'
10288
+ | 'inference-controlnet'
10289
+ | 'inference-controlnet-ip-adapter'
10290
+ | 'inference-controlnet-img2img'
10291
+ | 'inference-controlnet-reference'
10292
+ | 'inference-controlnet-inpaint'
10293
+ | 'inference-controlnet-inpaint-ip-adapter'
10294
+ | 'inference-controlnet-texture'
10295
+ | 'background-removal'
10296
+ | 'canvas'
10297
+ | 'canvas-export'
10298
+ | 'canvas-drawing'
10299
+ | 'detection'
10300
+ | 'patch'
10301
+ | 'pixelization'
10302
+ | 'upscale'
10303
+ | 'upscale-texture'
10304
+ | 'upscale-skybox'
10305
+ | 'vectorization'
10306
+ | 'segment'
10307
+ | 'segmentation-image'
10308
+ | 'segmentation-mask'
10309
+ | 'skybox-base-360'
10310
+ | 'skybox-hdri'
10311
+ | 'skybox-3d'
10312
+ | 'restyle'
10313
+ | 'reframe'
10314
+ | 'generative-fill'
10315
+ | 'texture'
10316
+ | 'texture-height'
10317
+ | 'texture-normal'
10318
+ | 'texture-smoothness'
10319
+ | 'texture-metallic'
10320
+ | 'texture-edge'
10321
+ | 'texture-ao'
10322
+ | 'texture-albedo'
10323
+ | 'image-prompt-editing'
10324
+ | 'unknown'
10325
+ | 'img23d'
10326
+ | 'txt23d'
10327
+ | 'video23d'
10328
+ | '3d23d'
10329
+ | '3d23d-texture'
10330
+ | '3d-texture'
10331
+ | '3d-texture-mtl'
10332
+ | '3d-texture-albedo'
10333
+ | '3d-texture-normal'
10334
+ | '3d-texture-roughness'
10335
+ | '3d-texture-metallic'
10336
+ | 'img2video'
10337
+ | 'txt2audio'
10338
+ | 'audio2audio'
10339
+ | 'voice-clone'
10340
+ | 'video2video'
10341
+ | 'video2img'
10342
+ | 'txt2img'
10343
+ | 'img2img'
10344
+ | 'txt2video'
10345
+ | 'uploaded'
10346
+ | 'uploaded-video'
10347
+ | 'uploaded-audio'
10348
+ | 'uploaded-3d'
10349
+ | 'uploaded-avatar'
10350
+ | 'upscale-video';
10278
10351
 
10279
10352
  /**
10280
10353
  * Filter results to only return assets updated after the specified ISO string date
@@ -10289,6 +10362,13 @@ export interface AssetListParams {
10289
10362
  updatedBefore?: string;
10290
10363
  }
10291
10364
 
10365
+ export interface AssetDeleteMultipleParams {
10366
+ /**
10367
+ * The ids of the assets to delete. (Max 100 at once)
10368
+ */
10369
+ assetIds: Array<string>;
10370
+ }
10371
+
10292
10372
  export interface AssetDuplicateParams {
10293
10373
  /**
10294
10374
  * Query param: If set to true, returns the original asset without transformation
@@ -10442,6 +10522,7 @@ export declare namespace Assets {
10442
10522
  type AssetRetrieveParams as AssetRetrieveParams,
10443
10523
  type AssetUpdateParams as AssetUpdateParams,
10444
10524
  type AssetListParams as AssetListParams,
10525
+ type AssetDeleteMultipleParams as AssetDeleteMultipleParams,
10445
10526
  type AssetDuplicateParams as AssetDuplicateParams,
10446
10527
  type AssetGetBulkParams as AssetGetBulkParams,
10447
10528
  type AssetListSnapshotsParams as AssetListSnapshotsParams,
@@ -16,6 +16,7 @@ export {
16
16
  type AssetRetrieveParams,
17
17
  type AssetUpdateParams,
18
18
  type AssetListParams,
19
+ type AssetDeleteMultipleParams,
19
20
  type AssetDuplicateParams,
20
21
  type AssetGetBulkParams,
21
22
  type AssetListSnapshotsParams,
@@ -16,8 +16,12 @@ export class Assets extends APIResource {
16
16
  /**
17
17
  * Remove assets from a specific collection
18
18
  */
19
- remove(collectionID: string, options?: RequestOptions): APIPromise<AssetRemoveResponse> {
20
- return this._client.delete(path`/collections/${collectionID}/assets`, options);
19
+ remove(
20
+ collectionID: string,
21
+ body: AssetRemoveParams,
22
+ options?: RequestOptions,
23
+ ): APIPromise<AssetRemoveResponse> {
24
+ return this._client.delete(path`/collections/${collectionID}/assets`, { body, ...options });
21
25
  }
22
26
  }
23
27
 
@@ -142,10 +146,18 @@ export interface AssetAddParams {
142
146
  assetIds: Array<string>;
143
147
  }
144
148
 
149
+ export interface AssetRemoveParams {
150
+ /**
151
+ * The ids of the assets to remove from the collection. (Max 49 at once)
152
+ */
153
+ assetIds: Array<string>;
154
+ }
155
+
145
156
  export declare namespace Assets {
146
157
  export {
147
158
  type AssetAddResponse as AssetAddResponse,
148
159
  type AssetRemoveResponse as AssetRemoveResponse,
149
160
  type AssetAddParams as AssetAddParams,
161
+ type AssetRemoveParams as AssetRemoveParams,
150
162
  };
151
163
  }
@@ -2,9 +2,9 @@
2
2
 
3
3
  import { APIResource } from '../../core/resource';
4
4
  import * as AssetsAPI from './assets';
5
- import { AssetAddParams, AssetAddResponse, AssetRemoveResponse, Assets } from './assets';
5
+ import { AssetAddParams, AssetAddResponse, AssetRemoveParams, AssetRemoveResponse, Assets } from './assets';
6
6
  import * as ModelsAPI from './models';
7
- import { ModelAddParams, ModelAddResponse, ModelRemoveResponse, Models } from './models';
7
+ import { ModelAddParams, ModelAddResponse, ModelRemoveParams, ModelRemoveResponse, Models } from './models';
8
8
  import { APIPromise } from '../../core/api-promise';
9
9
  import { RequestOptions } from '../../internal/request-options';
10
10
  import { path } from '../../internal/utils/path';
@@ -344,6 +344,7 @@ export declare namespace Collections {
344
344
  type AssetAddResponse as AssetAddResponse,
345
345
  type AssetRemoveResponse as AssetRemoveResponse,
346
346
  type AssetAddParams as AssetAddParams,
347
+ type AssetRemoveParams as AssetRemoveParams,
347
348
  };
348
349
 
349
350
  export {
@@ -351,5 +352,6 @@ export declare namespace Collections {
351
352
  type ModelAddResponse as ModelAddResponse,
352
353
  type ModelRemoveResponse as ModelRemoveResponse,
353
354
  type ModelAddParams as ModelAddParams,
355
+ type ModelRemoveParams as ModelRemoveParams,
354
356
  };
355
357
  }
@@ -1,6 +1,12 @@
1
1
  // File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
2
2
 
3
- export { Assets, type AssetAddResponse, type AssetRemoveResponse, type AssetAddParams } from './assets';
3
+ export {
4
+ Assets,
5
+ type AssetAddResponse,
6
+ type AssetRemoveResponse,
7
+ type AssetAddParams,
8
+ type AssetRemoveParams,
9
+ } from './assets';
4
10
  export {
5
11
  Collections,
6
12
  type CollectionCreateResponse,
@@ -12,4 +18,10 @@ export {
12
18
  type CollectionUpdateParams,
13
19
  type CollectionListParams,
14
20
  } from './collections';
15
- export { Models, type ModelAddResponse, type ModelRemoveResponse, type ModelAddParams } from './models';
21
+ export {
22
+ Models,
23
+ type ModelAddResponse,
24
+ type ModelRemoveResponse,
25
+ type ModelAddParams,
26
+ type ModelRemoveParams,
27
+ } from './models';
@@ -16,8 +16,12 @@ export class Models extends APIResource {
16
16
  /**
17
17
  * Remove models from a specific collection
18
18
  */
19
- remove(collectionID: string, options?: RequestOptions): APIPromise<ModelRemoveResponse> {
20
- return this._client.delete(path`/collections/${collectionID}/models`, options);
19
+ remove(
20
+ collectionID: string,
21
+ body: ModelRemoveParams,
22
+ options?: RequestOptions,
23
+ ): APIPromise<ModelRemoveResponse> {
24
+ return this._client.delete(path`/collections/${collectionID}/models`, { body, ...options });
21
25
  }
22
26
  }
23
27
 
@@ -142,10 +146,18 @@ export interface ModelAddParams {
142
146
  modelIds: Array<string>;
143
147
  }
144
148
 
149
+ export interface ModelRemoveParams {
150
+ /**
151
+ * The ids of the models to remove from the collection. (Max 49 at once)
152
+ */
153
+ modelIds: Array<string>;
154
+ }
155
+
145
156
  export declare namespace Models {
146
157
  export {
147
158
  type ModelAddResponse as ModelAddResponse,
148
159
  type ModelRemoveResponse as ModelRemoveResponse,
149
160
  type ModelAddParams as ModelAddParams,
161
+ type ModelRemoveParams as ModelRemoveParams,
150
162
  };
151
163
  }
@@ -16,6 +16,7 @@ export {
16
16
  type AssetRetrieveParams,
17
17
  type AssetUpdateParams,
18
18
  type AssetListParams,
19
+ type AssetDeleteMultipleParams,
19
20
  type AssetDuplicateParams,
20
21
  type AssetGetBulkParams,
21
22
  type AssetListSnapshotsParams,