@scenario-labs/sdk 2.2.1 → 2.4.0-alpha.1

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 (163) hide show
  1. package/CHANGELOG.md +35 -0
  2. package/client.d.mts.map +1 -1
  3. package/client.d.ts.map +1 -1
  4. package/client.js +9 -1
  5. package/client.js.map +1 -1
  6. package/client.mjs +9 -1
  7. package/client.mjs.map +1 -1
  8. package/index.d.mts +1 -0
  9. package/index.d.mts.map +1 -1
  10. package/index.d.ts +1 -0
  11. package/index.d.ts.map +1 -1
  12. package/index.js +3 -1
  13. package/index.js.map +1 -1
  14. package/index.mjs +1 -0
  15. package/index.mjs.map +1 -1
  16. package/lib/auth-refresh.d.mts +52 -0
  17. package/lib/auth-refresh.d.mts.map +1 -0
  18. package/lib/auth-refresh.d.ts +52 -0
  19. package/lib/auth-refresh.d.ts.map +1 -0
  20. package/lib/auth-refresh.js +81 -0
  21. package/lib/auth-refresh.js.map +1 -0
  22. package/lib/auth-refresh.mjs +78 -0
  23. package/lib/auth-refresh.mjs.map +1 -0
  24. package/lib/generate.js +7 -7
  25. package/lib/generate.js.map +1 -1
  26. package/lib/generate.mjs +7 -7
  27. package/lib/generate.mjs.map +1 -1
  28. package/lib/job.d.mts +15 -3
  29. package/lib/job.d.mts.map +1 -1
  30. package/lib/job.d.ts +15 -3
  31. package/lib/job.d.ts.map +1 -1
  32. package/lib/job.js +22 -8
  33. package/lib/job.js.map +1 -1
  34. package/lib/job.mjs +22 -8
  35. package/lib/job.mjs.map +1 -1
  36. package/lib/models.d.mts +8 -2
  37. package/lib/models.d.mts.map +1 -1
  38. package/lib/models.d.ts +8 -2
  39. package/lib/models.d.ts.map +1 -1
  40. package/lib/models.js +13 -5
  41. package/lib/models.js.map +1 -1
  42. package/lib/models.mjs +13 -5
  43. package/lib/models.mjs.map +1 -1
  44. package/lib/scenario.d.mts +28 -13
  45. package/lib/scenario.d.mts.map +1 -1
  46. package/lib/scenario.d.ts +28 -13
  47. package/lib/scenario.d.ts.map +1 -1
  48. package/lib/scenario.js +31 -12
  49. package/lib/scenario.js.map +1 -1
  50. package/lib/scenario.mjs +31 -12
  51. package/lib/scenario.mjs.map +1 -1
  52. package/lib/scope.d.mts +41 -0
  53. package/lib/scope.d.mts.map +1 -0
  54. package/lib/scope.d.ts +41 -0
  55. package/lib/scope.d.ts.map +1 -0
  56. package/lib/scope.js +55 -0
  57. package/lib/scope.js.map +1 -0
  58. package/lib/scope.mjs +49 -0
  59. package/lib/scope.mjs.map +1 -0
  60. package/lib/upload.d.mts +15 -3
  61. package/lib/upload.d.mts.map +1 -1
  62. package/lib/upload.d.ts +15 -3
  63. package/lib/upload.d.ts.map +1 -1
  64. package/lib/upload.js +29 -12
  65. package/lib/upload.js.map +1 -1
  66. package/lib/upload.mjs +29 -12
  67. package/lib/upload.mjs.map +1 -1
  68. package/lib/workflow.d.mts +8 -2
  69. package/lib/workflow.d.mts.map +1 -1
  70. package/lib/workflow.d.ts +8 -2
  71. package/lib/workflow.d.ts.map +1 -1
  72. package/lib/workflow.js +14 -6
  73. package/lib/workflow.js.map +1 -1
  74. package/lib/workflow.mjs +14 -6
  75. package/lib/workflow.mjs.map +1 -1
  76. package/lib/workflow_converter.d.mts +8 -2
  77. package/lib/workflow_converter.d.mts.map +1 -1
  78. package/lib/workflow_converter.d.ts +8 -2
  79. package/lib/workflow_converter.d.ts.map +1 -1
  80. package/lib/workflow_converter.js +83 -19
  81. package/lib/workflow_converter.js.map +1 -1
  82. package/lib/workflow_converter.mjs +83 -19
  83. package/lib/workflow_converter.mjs.map +1 -1
  84. package/lib/workflow_import_validator.d.mts +1 -1
  85. package/lib/workflow_import_validator.d.mts.map +1 -1
  86. package/lib/workflow_import_validator.d.ts +1 -1
  87. package/lib/workflow_import_validator.d.ts.map +1 -1
  88. package/lib/workflow_import_validator.js +1 -0
  89. package/lib/workflow_import_validator.js.map +1 -1
  90. package/lib/workflow_import_validator.mjs +1 -0
  91. package/lib/workflow_import_validator.mjs.map +1 -1
  92. package/package.json +9 -3
  93. package/resources/assets/assets.d.mts +1 -1
  94. package/resources/assets/assets.d.mts.map +1 -1
  95. package/resources/assets/assets.d.ts +1 -1
  96. package/resources/assets/assets.d.ts.map +1 -1
  97. package/resources/generate.d.mts +594 -10
  98. package/resources/generate.d.mts.map +1 -1
  99. package/resources/generate.d.ts +594 -10
  100. package/resources/generate.d.ts.map +1 -1
  101. package/resources/generate.js +2 -2
  102. package/resources/generate.js.map +1 -1
  103. package/resources/generate.mjs +2 -2
  104. package/resources/generate.mjs.map +1 -1
  105. package/resources/jobs.d.mts +3 -3
  106. package/resources/jobs.d.mts.map +1 -1
  107. package/resources/jobs.d.ts +3 -3
  108. package/resources/jobs.d.ts.map +1 -1
  109. package/resources/models/examples.d.mts +2 -2
  110. package/resources/models/examples.d.mts.map +1 -1
  111. package/resources/models/examples.d.ts +2 -2
  112. package/resources/models/examples.d.ts.map +1 -1
  113. package/resources/models/models.d.mts +126 -7
  114. package/resources/models/models.d.mts.map +1 -1
  115. package/resources/models/models.d.ts +126 -7
  116. package/resources/models/models.d.ts.map +1 -1
  117. package/resources/models/models.js.map +1 -1
  118. package/resources/models/models.mjs.map +1 -1
  119. package/resources/models/train.d.mts +106 -3
  120. package/resources/models/train.d.mts.map +1 -1
  121. package/resources/models/train.d.ts +106 -3
  122. package/resources/models/train.d.ts.map +1 -1
  123. package/resources/usages.d.mts +23 -3
  124. package/resources/usages.d.mts.map +1 -1
  125. package/resources/usages.d.ts +23 -3
  126. package/resources/usages.d.ts.map +1 -1
  127. package/resources/workflows.d.mts +22 -5
  128. package/resources/workflows.d.mts.map +1 -1
  129. package/resources/workflows.d.ts +22 -5
  130. package/resources/workflows.d.ts.map +1 -1
  131. package/resources/workflows.js +4 -1
  132. package/resources/workflows.js.map +1 -1
  133. package/resources/workflows.mjs +4 -1
  134. package/resources/workflows.mjs.map +1 -1
  135. package/src/client.ts +9 -1
  136. package/src/index.ts +1 -0
  137. package/src/lib/auth-refresh.ts +98 -0
  138. package/src/lib/generate.ts +7 -7
  139. package/src/lib/job.ts +29 -7
  140. package/src/lib/models.ts +14 -4
  141. package/src/lib/scenario.ts +51 -13
  142. package/src/lib/scope.ts +68 -0
  143. package/src/lib/upload.ts +36 -11
  144. package/src/lib/workflow.ts +15 -5
  145. package/src/lib/workflow_converter.ts +128 -19
  146. package/src/lib/workflow_import_validator.ts +3 -1
  147. package/src/resources/assets/assets.ts +1 -1
  148. package/src/resources/generate.ts +713 -12
  149. package/src/resources/jobs.ts +3 -3
  150. package/src/resources/models/examples.ts +2 -2
  151. package/src/resources/models/models.ts +189 -7
  152. package/src/resources/models/train.ts +138 -3
  153. package/src/resources/usages.ts +27 -1
  154. package/src/resources/workflows.ts +24 -5
  155. package/src/version.ts +1 -1
  156. package/version.d.mts +1 -1
  157. package/version.d.mts.map +1 -1
  158. package/version.d.ts +1 -1
  159. package/version.d.ts.map +1 -1
  160. package/version.js +1 -1
  161. package/version.js.map +1 -1
  162. package/version.mjs +1 -1
  163. package/version.mjs.map +1 -1
@@ -47,7 +47,7 @@ export type WorkflowEditorNode =
47
47
  }
48
48
  | { id: string; type: 'transformText'; data: NodeCommonData & { value?: string } }
49
49
  | { id: string; type: 'splitText'; data: NodeCommonData & { splitDelimiter?: string } }
50
- | { id: string; type: 'aspectRatio'; data: NodeCommonData & { output?: string } }
50
+ | { id: string; type: 'aspectRatio'; data: NodeCommonData & { output?: string; quality?: string } }
51
51
  | { id: string; type: 'groupItems'; data: NodeCommonData & { value?: string } }
52
52
  | {
53
53
  id: string;
@@ -62,7 +62,16 @@ export type WorkflowEditorNode =
62
62
  data: NodeCommonData & { conditionBlocks?: WorkflowEditorConditionBlock[] };
63
63
  }
64
64
  | { id: string; type: 'approval'; data: NodeCommonData & { message?: string } }
65
- | { id: string; type: string; data: NodeCommonData };
65
+ | {
66
+ id: string;
67
+ type: 'modelInput';
68
+ data: NodeCommonData & {
69
+ inputName: string;
70
+ form?: Record<string, unknown>;
71
+ parentModelNodeId?: string;
72
+ modelId?: string;
73
+ };
74
+ };
66
75
 
67
76
  export type WorkflowEditorEdge = {
68
77
  source: string;
@@ -111,7 +120,14 @@ export type WorkflowEditorModel = {
111
120
  };
112
121
  };
113
122
 
123
+ type ModelInputNodeData = NodeCommonData & {
124
+ inputName: string;
125
+ form?: Record<string, unknown>;
126
+ };
127
+
114
128
  const RUNNABLE_TYPES = new Set(['model', 'llm', 'forEach', 'forEachEnd']);
129
+ const MODEL_CUSTOM_INPUT_HANDLE_SUFFIX = '-source-custom';
130
+
115
131
  export const ASPECT_RATIO_PRESETS = [
116
132
  '21:9',
117
133
  '16:9',
@@ -660,9 +676,28 @@ function applyAspectRatioInputs(args: {
660
676
  flowId: string;
661
677
  aspectRatioRef: WorkflowEditorFlowInputRef;
662
678
  model: WorkflowEditorModel;
679
+ aspectRatioQuality: string | undefined;
663
680
  }): void {
664
681
  const modelInputNames = getAspectRatioModelInputNames(args.model);
665
- const modelBounds = getAspectRatioBounds(args.model, modelInputNames);
682
+ const rawModelBounds = getAspectRatioBounds(args.model, modelInputNames);
683
+ const quality = args.aspectRatioQuality;
684
+ const maxDimensionCap =
685
+ quality === 'high' ? 2048
686
+ : quality === 'medium' ? 1024
687
+ : undefined;
688
+ const isCapApplied =
689
+ rawModelBounds != null &&
690
+ maxDimensionCap != null &&
691
+ (rawModelBounds.maxWidth > maxDimensionCap || rawModelBounds.maxHeight > maxDimensionCap);
692
+ const modelBounds =
693
+ rawModelBounds && maxDimensionCap != null ?
694
+ {
695
+ ...rawModelBounds,
696
+ maxWidth: Math.min(rawModelBounds.maxWidth, maxDimensionCap),
697
+ maxHeight: Math.min(rawModelBounds.maxHeight, maxDimensionCap),
698
+ multipleOf: isCapApplied ? Math.min(rawModelBounds.multipleOf, 8) : rawModelBounds.multipleOf,
699
+ }
700
+ : rawModelBounds;
666
701
  const { widthInputName, heightInputName, aspectRatioInputName } = modelInputNames;
667
702
 
668
703
  if (aspectRatioInputName) {
@@ -808,6 +843,13 @@ function getNodeOutputValue(
808
843
  }
809
844
  return (Array.isArray(d.value) ? d.value : d.value) || undefined;
810
845
  }
846
+ if (node.type === 'modelInput') {
847
+ const value = getModelInputNodeStaticValue(node);
848
+ if (value === undefined) return undefined;
849
+ if (typeof value === 'boolean') return value ? 'true' : 'false';
850
+ if (typeof value === 'number') return String(value);
851
+ return value;
852
+ }
811
853
  return undefined;
812
854
  }
813
855
 
@@ -899,6 +941,54 @@ function normalizeNodes(nodes: WorkflowEditorNode[]): WorkflowEditorNode[] {
899
941
  });
900
942
  }
901
943
 
944
+ function getIsModelCustomInputHandleId(handleId: string | null | undefined): boolean {
945
+ return !!handleId && handleId.endsWith(MODEL_CUSTOM_INPUT_HANDLE_SUFFIX);
946
+ }
947
+
948
+ function getModelInputEdgeInputName(
949
+ edge: WorkflowEditorEdge,
950
+ handle: WorkflowEditorHandleInput | undefined,
951
+ nodes: WorkflowEditorNode[],
952
+ ): string | undefined {
953
+ if (handle?.name) return handle.name;
954
+ const targetNode = nodes.find((n) => n.id === edge.target);
955
+ if (targetNode?.type !== 'modelInput') return undefined;
956
+ if (handle?.type === 'custom' || getIsModelCustomInputHandleId(edge.sourceHandle)) {
957
+ return (targetNode.data as ModelInputNodeData).inputName;
958
+ }
959
+ return undefined;
960
+ }
961
+
962
+ function getModelInputNodeStaticValue(node: WorkflowEditorNode): string | number | boolean | undefined {
963
+ if (node.type !== 'modelInput') return undefined;
964
+ const data = node.data as ModelInputNodeData;
965
+ const value = data.form?.[data.inputName];
966
+ if (value === undefined) return undefined;
967
+ if (typeof value === 'boolean' || typeof value === 'number' || typeof value === 'string') return value;
968
+ return undefined;
969
+ }
970
+
971
+ function pushModelFlowInputFromEdge(
972
+ flowInputs: WorkflowEditorFlowInput[],
973
+ existingIndex: number,
974
+ inputName: string,
975
+ inputType: string,
976
+ edge: WorkflowEditorEdge,
977
+ ctx: SourceRefContext,
978
+ filteredNodes: WorkflowEditorNode[],
979
+ ): void {
980
+ const ref = getSourceRef(edge, ctx);
981
+ if (ref) {
982
+ setOrPushFlowInput(flowInputs, existingIndex, { name: inputName, type: inputType, ref });
983
+ return;
984
+ }
985
+ const targetNode = filteredNodes.find((n) => n.id === edge.target);
986
+ if (targetNode?.type === 'modelInput') {
987
+ const staticInput = toStaticInput(inputName, inputType, getModelInputNodeStaticValue(targetNode));
988
+ if (staticInput) setOrPushFlowInput(flowInputs, existingIndex, staticInput);
989
+ }
990
+ }
991
+
902
992
  // ---- Main function ----
903
993
 
904
994
  /**
@@ -973,7 +1063,7 @@ export function convertWorkflowEditorToFlow(
973
1063
 
974
1064
  const nodeIdToFlowIdMap = new Map<string, string>(
975
1065
  sortedNodes
976
- .filter((n) => !inputNodeIds.includes(n.id) && n.type !== 'forEachEnd')
1066
+ .filter((n) => !inputNodeIds.includes(n.id) && n.type !== 'forEachEnd' && n.type !== 'modelInput')
977
1067
  .map((n) => [n.id, nodeIdToFlowId(n.id)]),
978
1068
  );
979
1069
  const nodeIdToInputNameMap = new Map<string, string>(inputNodeIds.map((id) => [id, nodeIdToFlowId(id)]));
@@ -1065,24 +1155,25 @@ export function convertWorkflowEditorToFlow(
1065
1155
  for (const edge of incomingEdges) {
1066
1156
  if (edge.sourceHandle === conditionalHandleId) continue;
1067
1157
  const handle = getInputHandle(edge, node.data.inputHandles);
1068
- if (!handle?.name) continue;
1069
- if (handleTypeIncludes(handle.type, 'aspectRatio')) {
1158
+ const inputName = getModelInputEdgeInputName(edge, handle, nodes);
1159
+ if (!inputName) continue;
1160
+ if (handleTypeIncludes(handle?.type, 'aspectRatio')) {
1070
1161
  aspectRatioEdges.push(edge);
1071
1162
  continue;
1072
1163
  }
1073
- const existing = edgesByInput.get(handle.name);
1164
+ const existing = edgesByInput.get(inputName);
1074
1165
  if (existing) existing.push(edge);
1075
- else edgesByInput.set(handle.name, [edge]);
1166
+ else edgesByInput.set(inputName, [edge]);
1076
1167
  }
1077
1168
 
1078
1169
  if (nodeData.form) {
1079
1170
  for (const [key, value] of Object.entries(nodeData.form)) {
1080
1171
  if (value === undefined || value === '') continue;
1081
- const modelInput = modelInputs?.find((inp) => inp.name === key);
1172
+ const modelFormInput = modelInputs?.find((inp) => inp.name === key);
1082
1173
 
1083
- if (modelInput?.type === 'inputs_array') {
1174
+ if (modelFormInput?.type === 'inputs_array') {
1084
1175
  if (!getIsFormArray(value)) continue;
1085
- const nestedInputs = modelInput.inputs ?? [];
1176
+ const nestedInputs = modelFormInput.inputs ?? [];
1086
1177
  const items: WorkflowEditorFlowInput[][] = [];
1087
1178
 
1088
1179
  for (const [index, form] of (value as Record<string, unknown>[]).entries()) {
@@ -1106,7 +1197,7 @@ export function convertWorkflowEditorToFlow(
1106
1197
  if (items.length > 0) flowInputs.push({ name: key, type: 'inputs_array', items });
1107
1198
  } else {
1108
1199
  const type =
1109
- modelInput?.type ??
1200
+ modelFormInput?.type ??
1110
1201
  (typeof value === 'number' ? 'number'
1111
1202
  : typeof value === 'boolean' ? 'boolean'
1112
1203
  : 'string');
@@ -1118,6 +1209,9 @@ export function convertWorkflowEditorToFlow(
1118
1209
 
1119
1210
  if (aspectRatioEdges.length > 0 && model) {
1120
1211
  const aspectRatioRef = getSourceRef(aspectRatioEdges[0]!, ctx);
1212
+ const aspectRatioNode = nodes.find((candidate) => candidate.id === aspectRatioEdges[0]!.target);
1213
+ const aspectRatioQuality =
1214
+ aspectRatioNode?.type === 'aspectRatio' ? aspectRatioNode.data.quality : undefined;
1121
1215
  if (aspectRatioRef) {
1122
1216
  applyAspectRatioInputs({
1123
1217
  flow,
@@ -1125,6 +1219,7 @@ export function convertWorkflowEditorToFlow(
1125
1219
  flowId,
1126
1220
  aspectRatioRef,
1127
1221
  model,
1222
+ aspectRatioQuality,
1128
1223
  });
1129
1224
  }
1130
1225
  }
@@ -1136,9 +1231,15 @@ export function convertWorkflowEditorToFlow(
1136
1231
  const inputType = modelInput.type;
1137
1232
 
1138
1233
  if (inputEdges.length === 1) {
1139
- const ref = getSourceRef(inputEdges[0]!, ctx);
1140
- if (!ref) continue;
1141
- setOrPushFlowInput(flowInputs, existingIndex, { name: inputName, type: inputType, ref });
1234
+ pushModelFlowInputFromEdge(
1235
+ flowInputs,
1236
+ existingIndex,
1237
+ inputName,
1238
+ inputType,
1239
+ inputEdges[0]!,
1240
+ ctx,
1241
+ filteredNodes,
1242
+ );
1142
1243
  } else {
1143
1244
  const allConditional = inputEdges.every((e) => getIsConditionallyExecuted(e.target, nodes, edges));
1144
1245
 
@@ -1202,7 +1303,9 @@ export function convertWorkflowEditorToFlow(
1202
1303
 
1203
1304
  if (
1204
1305
  !targetNode?.data.isInput &&
1205
- (targetNode?.type === 'asset' || targetNode?.type === 'text')
1306
+ (targetNode?.type === 'asset' ||
1307
+ targetNode?.type === 'text' ||
1308
+ targetNode?.type === 'modelInput')
1206
1309
  ) {
1207
1310
  transformInputs.push({
1208
1311
  name: targetNodeKey,
@@ -1241,9 +1344,15 @@ export function convertWorkflowEditorToFlow(
1241
1344
  ref: { node: concatItem.id, name: 'all' },
1242
1345
  });
1243
1346
  } else {
1244
- const ref = getSourceRef(inputEdges[0]!, ctx);
1245
- if (!ref) continue;
1246
- setOrPushFlowInput(flowInputs, existingIndex, { name: inputName, type: inputType, ref });
1347
+ pushModelFlowInputFromEdge(
1348
+ flowInputs,
1349
+ existingIndex,
1350
+ inputName,
1351
+ inputType,
1352
+ inputEdges[0]!,
1353
+ ctx,
1354
+ filteredNodes,
1355
+ );
1247
1356
  }
1248
1357
  }
1249
1358
  }
@@ -19,7 +19,8 @@ export type WorkflowEditorNodeType =
19
19
  | 'forEach'
20
20
  | 'forEachEnd'
21
21
  | 'stickyNote'
22
- | 'approval';
22
+ | 'approval'
23
+ | 'modelInput';
23
24
 
24
25
  export const VALID_EDITOR_NODE_TYPES: readonly WorkflowEditorNodeType[] = [
25
26
  'text',
@@ -36,6 +37,7 @@ export const VALID_EDITOR_NODE_TYPES: readonly WorkflowEditorNodeType[] = [
36
37
  'forEachEnd',
37
38
  'stickyNote',
38
39
  'approval',
40
+ 'modelInput',
39
41
  ];
40
42
 
41
43
  export interface WorkflowExportData {
@@ -9515,7 +9515,7 @@ export namespace AssetUploadResponse {
9515
9515
  /**
9516
9516
  * The status of the node. Only available for WorkflowJob nodes.
9517
9517
  */
9518
- status: 'failure' | 'pending' | 'processing' | 'skipped' | 'success';
9518
+ status: 'failure' | 'pending' | 'processing' | 'rejected' | 'skipped' | 'success';
9519
9519
 
9520
9520
  /**
9521
9521
  * The type of the job for the node.