deepline 0.3.294 → 0.3.295

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 (136) hide show
  1. package/dist/bundling-sources/sdk/src/compat.ts +35 -7
  2. package/dist/bundling-sources/sdk/src/release.ts +1 -1
  3. package/dist/bundling-sources/shared_libs/play-runtime/tool-http-errors.ts +14 -1
  4. package/dist/cli/auth-EDTRERZP.mjs +31 -0
  5. package/dist/cli/auth-TDHKB277.js +31 -0
  6. package/dist/cli/billing-ELIDPILY.js +1749 -0
  7. package/dist/cli/billing-EXGXJVAU.mjs +1749 -0
  8. package/dist/cli/chunk-2S5Y3TZP.js +5688 -0
  9. package/dist/cli/chunk-3KC45UVF.js +150 -0
  10. package/dist/cli/chunk-3XX5TEA4.js +15 -0
  11. package/dist/cli/chunk-4MBOJQPL.mjs +0 -0
  12. package/dist/cli/chunk-4NEFYBF7.js +2240 -0
  13. package/dist/cli/chunk-5JLQPVNX.js +3056 -0
  14. package/dist/cli/chunk-5KDKFHZI.js +1269 -0
  15. package/dist/cli/chunk-6A3TJUWC.js +76 -0
  16. package/dist/cli/chunk-6O5YZOVN.mjs +890 -0
  17. package/dist/cli/chunk-7P5AA3SN.js +344 -0
  18. package/dist/cli/chunk-AYHLUHE5.js +52 -0
  19. package/dist/cli/chunk-CBVIJSHF.mjs +560 -0
  20. package/dist/cli/chunk-CFVVCN4A.js +735 -0
  21. package/dist/cli/chunk-COGTRVWW.js +30 -0
  22. package/dist/cli/chunk-D4AZUZO4.js +190 -0
  23. package/dist/cli/chunk-DLIRSHV6.mjs +28 -0
  24. package/dist/cli/chunk-EACVZI6N.mjs +1995 -0
  25. package/dist/cli/chunk-EDWJY6T4.mjs +3056 -0
  26. package/dist/cli/chunk-EXMLR72R.mjs +0 -0
  27. package/dist/cli/chunk-F35VOIQL.js +890 -0
  28. package/dist/cli/chunk-GAMFK2ZP.mjs +148 -0
  29. package/dist/cli/chunk-GHRQQPW2.mjs +2240 -0
  30. package/dist/cli/chunk-GONRLVV3.js +3440 -0
  31. package/dist/cli/chunk-GVUJJJ5G.mjs +76 -0
  32. package/dist/cli/chunk-H7HIDGZ7.mjs +150 -0
  33. package/dist/cli/chunk-HUZXWOSK.mjs +503 -0
  34. package/dist/cli/chunk-I5YZLGMG.js +1 -0
  35. package/dist/cli/chunk-ITOFSXIU.mjs +15 -0
  36. package/dist/cli/chunk-J5NA2TTX.js +503 -0
  37. package/dist/cli/chunk-JCS5TPNY.mjs +3440 -0
  38. package/dist/cli/chunk-JNNOCMQY.js +47 -0
  39. package/dist/cli/chunk-KRD6H754.mjs +30 -0
  40. package/dist/cli/chunk-LA46MMTL.js +560 -0
  41. package/dist/cli/chunk-LDWT7RJK.mjs +190 -0
  42. package/dist/cli/chunk-M2V26OR5.js +499 -0
  43. package/dist/cli/chunk-MIMASXO4.mjs +389 -0
  44. package/dist/cli/chunk-MROPCKW2.mjs +190 -0
  45. package/dist/cli/chunk-NXDRDJ4K.js +389 -0
  46. package/dist/cli/chunk-NXGCO4JB.mjs +344 -0
  47. package/dist/cli/chunk-OG64RBAC.js +6 -0
  48. package/dist/cli/chunk-OQYEC4GL.mjs +34 -0
  49. package/dist/cli/chunk-OWJZUE3Y.mjs +103 -0
  50. package/dist/cli/chunk-SDK3ZA2C.js +103 -0
  51. package/dist/cli/chunk-SFLARO4Y.mjs +47 -0
  52. package/dist/cli/chunk-SVIIIYIQ.js +923 -0
  53. package/dist/cli/chunk-TAC3JIFE.mjs +354 -0
  54. package/dist/cli/chunk-U3PI7HBM.js +34 -0
  55. package/dist/cli/chunk-UFS752TU.mjs +52 -0
  56. package/dist/cli/chunk-UI37DQE7.mjs +499 -0
  57. package/dist/cli/chunk-UNEMDKXN.js +1 -0
  58. package/dist/cli/chunk-WB6Z2Q44.mjs +1622 -0
  59. package/dist/cli/chunk-WJYPBHTE.js +148 -0
  60. package/dist/cli/chunk-WOHBA5PV.js +354 -0
  61. package/dist/cli/chunk-WQICC2B3.js +190 -0
  62. package/dist/cli/chunk-WZYKRD7T.mjs +6 -0
  63. package/dist/cli/chunk-XL2FO6CW.mjs +5688 -0
  64. package/dist/cli/chunk-XNYIZMNQ.js +28 -0
  65. package/dist/cli/chunk-XRK2TZT5.js +1995 -0
  66. package/dist/cli/chunk-YJYPL5OK.mjs +1269 -0
  67. package/dist/cli/chunk-YWNDYCXR.mjs +735 -0
  68. package/dist/cli/chunk-YWWAF7KZ.mjs +923 -0
  69. package/dist/cli/chunk-ZDO3TO3M.js +1622 -0
  70. package/dist/cli/client-4JVOYVC5.js +20 -0
  71. package/dist/cli/client-EEN2IJN2.mjs +20 -0
  72. package/dist/cli/csv-BOHBEP2I.mjs +585 -0
  73. package/dist/cli/csv-S5NYRUEX.js +585 -0
  74. package/dist/cli/db-CLODWCOB.mjs +486 -0
  75. package/dist/cli/db-F6PKFOOV.js +486 -0
  76. package/dist/cli/executions-5TQAKLJU.js +28 -0
  77. package/dist/cli/executions-MAKW6QOY.mjs +28 -0
  78. package/dist/cli/feedback-GV4QJFEN.js +107 -0
  79. package/dist/cli/feedback-XY24TW7H.mjs +107 -0
  80. package/dist/cli/getting-started.js +18 -76
  81. package/dist/cli/getting-started.mjs +10 -37
  82. package/dist/cli/git-6S2C22T5.js +23 -0
  83. package/dist/cli/git-OZLBD5HH.mjs +23 -0
  84. package/dist/cli/index.js +291 -54294
  85. package/dist/cli/index.mjs +209 -54352
  86. package/dist/cli/legacy-noops-LLCGDPQE.js +157 -0
  87. package/dist/cli/legacy-noops-TYH3TW2D.mjs +157 -0
  88. package/dist/cli/monitors-CABMB4DW.js +3251 -0
  89. package/dist/cli/monitors-TTD55HMK.mjs +3251 -0
  90. package/dist/cli/org-MSF3RG76.js +849 -0
  91. package/dist/cli/org-SFJ77MWY.mjs +849 -0
  92. package/dist/cli/play-NXHJSCKL.mjs +18439 -0
  93. package/dist/cli/play-OKSFNNO4.js +18439 -0
  94. package/dist/cli/providers-QC2ERERL.js +95 -0
  95. package/dist/cli/providers-TIIAZEUA.mjs +95 -0
  96. package/dist/cli/proxy-env-EBANZHPV.js +161 -0
  97. package/dist/cli/proxy-env-M4ZHXHRL.mjs +161 -0
  98. package/dist/cli/quickstart-ICANHLMI.js +69 -0
  99. package/dist/cli/quickstart-KWUOP3FI.mjs +69 -0
  100. package/dist/cli/search-U5H2FDOO.mjs +18 -0
  101. package/dist/cli/search-XQRQOLWS.js +18 -0
  102. package/dist/cli/secrets-3J6YTWFA.mjs +400 -0
  103. package/dist/cli/secrets-YNMNZNOM.js +400 -0
  104. package/dist/cli/sessions-CLEES4L6.mjs +15 -0
  105. package/dist/cli/sessions-J6VR47FG.js +15 -0
  106. package/dist/cli/settings-EEKZMTY4.js +846 -0
  107. package/dist/cli/settings-UVLOQZRH.mjs +846 -0
  108. package/dist/cli/setup-DLMDXPGJ.mjs +1257 -0
  109. package/dist/cli/setup-HC4Q7QM4.js +1257 -0
  110. package/dist/cli/skills-33PHFBSB.mjs +28 -0
  111. package/dist/cli/skills-LFRY3KPX.js +28 -0
  112. package/dist/cli/tools-3COEPKML.mjs +2955 -0
  113. package/dist/cli/tools-QXEVCN45.js +2955 -0
  114. package/dist/cli/update-LSAC4FF5.mjs +28 -0
  115. package/dist/cli/update-NXHSPYXA.js +28 -0
  116. package/dist/cli/workflow-7S44OECF.mjs +1936 -0
  117. package/dist/cli/workflow-QPZWYSZE.js +1936 -0
  118. package/dist/helpers.js +6 -32
  119. package/dist/helpers.mjs +2 -0
  120. package/dist/index.js +1972 -12825
  121. package/dist/index.mjs +1910 -12672
  122. package/dist/install-integrity.json +110 -0
  123. package/dist/monitor-fleet-contract.js +31 -730
  124. package/dist/monitor-fleet-contract.mjs +18 -667
  125. package/dist/monitor-input-contract.js +10 -390
  126. package/dist/monitor-input-contract.mjs +7 -348
  127. package/dist/plays/bundle-play-file.mjs +13 -5178
  128. package/dist/plays/csv-data-input.js +5 -3132
  129. package/dist/plays/csv-data-input.mjs +5 -3105
  130. package/dist/plays/run-request.js +56 -664
  131. package/dist/plays/run-request.mjs +30 -588
  132. package/dist/release.d.mts +1 -1
  133. package/dist/release.d.ts +1 -1
  134. package/dist/release.js +5 -212
  135. package/dist/release.mjs +5 -185
  136. package/package.json +1 -1
@@ -0,0 +1,560 @@
1
+ import {
2
+ apiErrorCodeFromResponse,
3
+ apiErrorMessage
4
+ } from "./chunk-DLIRSHV6.mjs";
5
+ import {
6
+ DeeplineError
7
+ } from "./chunk-NXGCO4JB.mjs";
8
+
9
+ // ../play-runtime/run-lifecycle-policy.ts
10
+ var TERMINAL_PLAY_RUN_STATUSES = /* @__PURE__ */ new Set([
11
+ "completed",
12
+ "failed",
13
+ "cancelled",
14
+ "terminated",
15
+ "timed_out"
16
+ ]);
17
+ function normalizePlayRunLifecycleStatus(value) {
18
+ const normalized = String(value ?? "").trim().toLowerCase();
19
+ switch (normalized) {
20
+ case "queued":
21
+ case "pending":
22
+ return "queued";
23
+ case "running":
24
+ case "started":
25
+ return "running";
26
+ case "waiting":
27
+ return "waiting";
28
+ case "completed":
29
+ case "complete":
30
+ case "succeeded":
31
+ return "completed";
32
+ case "failed":
33
+ case "error":
34
+ return "failed";
35
+ case "cancelled":
36
+ case "canceled":
37
+ return "cancelled";
38
+ case "terminated":
39
+ return "terminated";
40
+ case "timed_out":
41
+ case "timeout":
42
+ return "timed_out";
43
+ default:
44
+ return "unknown";
45
+ }
46
+ }
47
+ function isTerminalPlayRunLifecycleStatus(status) {
48
+ return TERMINAL_PLAY_RUN_STATUSES.has(
49
+ normalizePlayRunLifecycleStatus(status)
50
+ );
51
+ }
52
+ function decodePlayRunPublicStatus(value) {
53
+ const status = normalizePlayRunLifecycleStatus(value);
54
+ switch (status) {
55
+ case "queued":
56
+ case "running":
57
+ case "waiting":
58
+ case "completed":
59
+ case "failed":
60
+ case "cancelled":
61
+ return status;
62
+ case "terminated":
63
+ case "timed_out":
64
+ return "cancelled";
65
+ case "unknown":
66
+ return null;
67
+ }
68
+ }
69
+
70
+ // src/plays/run-request.ts
71
+ var PLAY_RUN_START_PATH = "/api/v2/plays/run";
72
+ var PLAY_RUN_START_STREAM_PATH = `${PLAY_RUN_START_PATH}?stream=true`;
73
+ var PLAY_FILES_STAGE_PATH = "/api/v2/plays/files/stage";
74
+ var PLAY_FILES_STAGE_MINT_PATH = `${PLAY_FILES_STAGE_PATH}/mint`;
75
+ function buildPlayRunStartBody(request) {
76
+ return {
77
+ ...request.name ? { name: request.name } : {},
78
+ ...request.revisionId ? { revisionId: request.revisionId } : {},
79
+ ...request.artifactStorageKey ? { artifactStorageKey: request.artifactStorageKey } : {},
80
+ ...request.sourceCode ? { sourceCode: request.sourceCode } : {},
81
+ ...request.sourceFiles ? { sourceFiles: request.sourceFiles } : {},
82
+ ...request.description ? { description: request.description } : {},
83
+ ..."staticPipeline" in request ? { staticPipeline: request.staticPipeline } : {},
84
+ ...request.artifactHash ? { artifactHash: request.artifactHash } : {},
85
+ ...request.graphHash ? { graphHash: request.graphHash } : {},
86
+ ...request.runtimeArtifact ? { runtimeArtifact: request.runtimeArtifact } : {},
87
+ ...request.compilerManifest ? { compilerManifest: request.compilerManifest } : {},
88
+ ...request.inputFileUpload ? { inputFileUpload: request.inputFileUpload } : {},
89
+ ...request.packagedFileUploads?.length ? { packagedFileUploads: request.packagedFileUploads } : {},
90
+ ...request.input ? { input: request.input } : {},
91
+ ...request.inputFile ? { inputFile: request.inputFile } : {},
92
+ ...request.packagedFiles?.length ? { packagedFiles: request.packagedFiles } : {},
93
+ ...request.force ? { force: true } : {},
94
+ ...request.forceToolRefresh === true ? { forceToolRefresh: true } : {},
95
+ ...typeof request.maxConcurrentExternalCalls === "number" ? { maxConcurrentExternalCalls: request.maxConcurrentExternalCalls } : {},
96
+ ...typeof request.maxConcurrentRows === "number" ? { maxConcurrentRows: request.maxConcurrentRows } : {},
97
+ ...typeof request.waitForCompletionMs === "number" ? { waitForCompletionMs: request.waitForCompletionMs } : {},
98
+ // Profile selection is the API's job, not the caller's. The server
99
+ // defaults to absurd; callers normally omit this field.
100
+ ...request.profile ? { profile: request.profile } : {},
101
+ ...request.integrationMode ? { integrationMode: request.integrationMode } : {},
102
+ ...request.fixtureBehavior ? { fixtureBehavior: request.fixtureBehavior } : {},
103
+ ...request.runtime ? { runtime: request.runtime } : {},
104
+ ...request.testPolicyOverrides ? { testPolicyOverrides: request.testPolicyOverrides } : {}
105
+ };
106
+ }
107
+ async function startPlayRun(http, request, headers) {
108
+ const response = await http.post(
109
+ PLAY_RUN_START_PATH,
110
+ buildPlayRunStartBody(request),
111
+ headers,
112
+ { maxRetries: 0, exactUrlOnly: true }
113
+ );
114
+ return normalizePlayRunStart(response);
115
+ }
116
+ function isPlayRunPackage(value) {
117
+ return Boolean(
118
+ value && typeof value === "object" && !Array.isArray(value) && value.kind === "play_run" && value.run && typeof value.run?.id === "string"
119
+ );
120
+ }
121
+ function normalizePlayRunStart(raw) {
122
+ const runPackage = isPlayRunPackage(raw) ? raw : isPlayRunPackage(raw.package) ? raw.package : null;
123
+ if (!runPackage) {
124
+ const workflowId = typeof raw.workflowId === "string" && raw.workflowId ? raw.workflowId : typeof raw.runId === "string" ? raw.runId : "";
125
+ return {
126
+ ...raw,
127
+ workflowId
128
+ };
129
+ }
130
+ const status = typeof runPackage.run.status === "string" ? runPackage.run.status : "running";
131
+ return {
132
+ workflowId: runPackage.run.id,
133
+ name: runPackage.run.playName,
134
+ status,
135
+ ...runPackage.run.dashboardUrl ? { dashboardUrl: runPackage.run.dashboardUrl } : {},
136
+ ...isTerminalPlayRunLifecycleStatus(status) ? { finalStatus: runPackage } : {},
137
+ package: runPackage
138
+ };
139
+ }
140
+ function buildNamedPlayRunRequest(input) {
141
+ return {
142
+ name: input.name,
143
+ ...input.revisionId ? { revisionId: input.revisionId } : {},
144
+ ...Object.keys(input.runtimeInput).length > 0 ? { input: input.runtimeInput } : {},
145
+ ...input.stagedFileInputs.inputFile ? { inputFile: input.stagedFileInputs.inputFile } : {},
146
+ ...input.stagedFileInputs.packagedFiles.length ? { packagedFiles: input.stagedFileInputs.packagedFiles } : {},
147
+ ...input.extra
148
+ };
149
+ }
150
+ var CSV_DATA_INPUT_KEY = "csv";
151
+ function schemaMetadata(schema, key) {
152
+ if (!schema || typeof schema !== "object" || Array.isArray(schema))
153
+ return null;
154
+ const value = schema[key];
155
+ return value && typeof value === "object" && !Array.isArray(value) ? value : null;
156
+ }
157
+ function stringMetadata(metadata, key) {
158
+ const value = metadata?.[key];
159
+ return typeof value === "string" && value.trim() ? value.trim() : null;
160
+ }
161
+ function inputFieldFromCsvArg(csvArg) {
162
+ if (typeof csvArg !== "string") return null;
163
+ const match = /^\(?\s*input\.([A-Za-z_$][\w$]*)\s*\)?(?:\s*\?\?[\s\S]+)?$/.exec(
164
+ csvArg.trim()
165
+ );
166
+ return match?.[1] ?? null;
167
+ }
168
+ function fileInputBindingsFromPlaySchema(inputSchema) {
169
+ const csvInput = schemaMetadata(inputSchema, "csvInput");
170
+ if (!csvInput) return [];
171
+ return [
172
+ {
173
+ inputPath: stringMetadata(csvInput, "inputField") ?? CSV_DATA_INPUT_KEY
174
+ }
175
+ ];
176
+ }
177
+ function fileInputBindingsFromStaticPipeline(staticPipeline) {
178
+ if (!staticPipeline || typeof staticPipeline !== "object" || Array.isArray(staticPipeline)) {
179
+ return [];
180
+ }
181
+ const inputField = inputFieldFromCsvArg(
182
+ staticPipeline.csvArg
183
+ );
184
+ return inputField ? [{ inputPath: inputField }] : [];
185
+ }
186
+ function playRunFileInputBindings(play) {
187
+ return [
188
+ ...fileInputBindingsFromPlaySchema(play.inputSchema),
189
+ ...fileInputBindingsFromStaticPipeline(play.staticPipeline)
190
+ ];
191
+ }
192
+ function getDottedInputValue(input, path) {
193
+ const parts = path.split(".").map((part) => part.trim()).filter(Boolean);
194
+ let cursor = input;
195
+ for (const part of parts) {
196
+ if (!cursor || typeof cursor !== "object" || Array.isArray(cursor)) {
197
+ return void 0;
198
+ }
199
+ cursor = cursor[part];
200
+ }
201
+ return cursor;
202
+ }
203
+ function setDottedInputValue(input, path, value) {
204
+ const parts = path.split(".").map((part) => part.trim()).filter(Boolean);
205
+ if (parts.length === 0) {
206
+ throw new Error(`Invalid play input flag path: ${path}`);
207
+ }
208
+ let cursor = input;
209
+ for (const part of parts.slice(0, -1)) {
210
+ const existing = cursor[part];
211
+ if (existing !== void 0 && (!existing || typeof existing !== "object" || Array.isArray(existing))) {
212
+ throw new Error(
213
+ `Cannot set --${path}; input.${part} is already a non-object value.`
214
+ );
215
+ }
216
+ if (!existing) {
217
+ cursor[part] = {};
218
+ }
219
+ cursor = cursor[part];
220
+ }
221
+ cursor[parts[parts.length - 1]] = value;
222
+ }
223
+ var webStagedFileCodec = {
224
+ async sha256Hex(bytes) {
225
+ const digest = await globalThis.crypto.subtle.digest(
226
+ "SHA-256",
227
+ bytes
228
+ );
229
+ return Array.from(
230
+ new Uint8Array(digest),
231
+ (byte) => byte.toString(16).padStart(2, "0")
232
+ ).join("");
233
+ },
234
+ base64(bytes) {
235
+ let binary = "";
236
+ for (let offset = 0; offset < bytes.length; offset += 32768) {
237
+ binary += String.fromCharCode(...bytes.subarray(offset, offset + 32768));
238
+ }
239
+ return btoa(binary);
240
+ }
241
+ };
242
+ function stagedFileContentType(logicalPath) {
243
+ const lower = logicalPath.toLowerCase();
244
+ return lower.endsWith(".csv") ? "text/csv" : lower.endsWith(".json") ? "application/json" : "application/octet-stream";
245
+ }
246
+ async function createStagedFileUpload(logicalPath, bytes, codec = webStagedFileCodec) {
247
+ return {
248
+ logicalPath,
249
+ contentBase64: codec.base64(bytes),
250
+ contentHash: await codec.sha256Hex(bytes),
251
+ contentType: stagedFileContentType(logicalPath),
252
+ bytes: bytes.byteLength
253
+ };
254
+ }
255
+ var STAGE_LEGACY_MULTIPART_MAX_BYTES = 4e6;
256
+ var STAGE_DIRECT_UPLOAD_MAX_ATTEMPTS = 3;
257
+ function sleep(ms) {
258
+ return new Promise((resolve) => setTimeout(resolve, ms));
259
+ }
260
+ function stagedUploadIdentity(logicalPath, contentHash) {
261
+ return `${contentHash}:${logicalPath}`;
262
+ }
263
+ function isStagedUploadMintUnsupported(error) {
264
+ return error instanceof DeeplineError && error.statusCode === 404;
265
+ }
266
+ function isStagedUploadDirectEgressDenied(error) {
267
+ return error instanceof DeeplineError && error.code === "STAGED_FILE_UPLOAD_EGRESS_DENIED";
268
+ }
269
+ function formatMegabytes(bytes) {
270
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
271
+ }
272
+ function decodeBase64Bytes(value) {
273
+ const binary = atob(value);
274
+ const bytes = new Uint8Array(binary.length);
275
+ for (let index = 0; index < binary.length; index += 1) {
276
+ bytes[index] = binary.charCodeAt(index);
277
+ }
278
+ return bytes;
279
+ }
280
+ async function uploadStagedFileToPresignedUrl(input) {
281
+ const arrayBuffer = input.body.buffer.slice(
282
+ input.body.byteOffset,
283
+ input.body.byteOffset + input.body.byteLength
284
+ );
285
+ let lastError;
286
+ for (let attempt = 1; attempt <= STAGE_DIRECT_UPLOAD_MAX_ATTEMPTS; attempt += 1) {
287
+ try {
288
+ const response = await fetch(input.url, {
289
+ method: "PUT",
290
+ headers: input.headers,
291
+ body: new Blob([arrayBuffer])
292
+ });
293
+ if (response.ok) {
294
+ return;
295
+ }
296
+ const text = await response.text().catch(() => "");
297
+ const egressDenied = response.status === 403 && response.headers.get("x-deny-reason")?.trim().toLowerCase() === "host_not_allowed";
298
+ lastError = new DeeplineError(
299
+ `Direct storage upload of ${input.logicalPath} failed: ${response.status} ${text.slice(0, 200)}`,
300
+ response.status,
301
+ egressDenied ? "STAGED_FILE_UPLOAD_EGRESS_DENIED" : "STAGED_FILE_UPLOAD_FAILED",
302
+ { logicalPath: input.logicalPath }
303
+ );
304
+ if (response.status < 500 && response.status !== 429) {
305
+ break;
306
+ }
307
+ } catch (error) {
308
+ lastError = error instanceof TypeError ? new DeeplineError(
309
+ `Direct storage upload of ${input.logicalPath} could not reach the storage endpoint: ${error.message}`,
310
+ void 0,
311
+ "STAGED_FILE_UPLOAD_EGRESS_DENIED",
312
+ { logicalPath: input.logicalPath }
313
+ ) : error;
314
+ }
315
+ if (attempt < STAGE_DIRECT_UPLOAD_MAX_ATTEMPTS) {
316
+ await sleep(250 * attempt);
317
+ }
318
+ }
319
+ throw lastError instanceof Error ? lastError : new DeeplineError(
320
+ `Direct storage upload of ${input.logicalPath} failed.`,
321
+ void 0,
322
+ "STAGED_FILE_UPLOAD_FAILED",
323
+ { logicalPath: input.logicalPath }
324
+ );
325
+ }
326
+ async function mintStagedPlayFileUploads(http, files) {
327
+ const response = await http.post(PLAY_FILES_STAGE_MINT_PATH, { files });
328
+ return response.uploads ?? [];
329
+ }
330
+ async function stagePlayFilesViaMultipart(http, files, reason = "mint-unsupported") {
331
+ for (const file of files) {
332
+ if (file.bytes > STAGE_LEGACY_MULTIPART_MAX_BYTES) {
333
+ const reasonMessage = reason === "direct-egress-denied" ? "direct storage is blocked by this environment's network egress policy" : "the connected Deepline server does not support direct-to-storage uploads";
334
+ throw new DeeplineError(
335
+ `Cannot stage ${file.logicalPath} (${formatMegabytes(file.bytes)}): ${reasonMessage}, and this file exceeds the ~4.5MB request-body limit the legacy upload path is subject to.`,
336
+ 413,
337
+ "STAGED_FILE_TOO_LARGE_FOR_LEGACY_UPLOAD",
338
+ {
339
+ logicalPath: file.logicalPath,
340
+ bytes: file.bytes,
341
+ maxBytes: STAGE_LEGACY_MULTIPART_MAX_BYTES
342
+ }
343
+ );
344
+ }
345
+ }
346
+ const buildFormData = () => {
347
+ const formData = new FormData();
348
+ formData.set(
349
+ "metadata",
350
+ JSON.stringify({
351
+ files: files.map((file, index) => ({
352
+ index,
353
+ logicalPath: file.logicalPath,
354
+ contentHash: file.contentHash,
355
+ contentType: file.contentType,
356
+ bytes: file.bytes
357
+ }))
358
+ })
359
+ );
360
+ for (const [index, file] of files.entries()) {
361
+ const bytes = decodeBase64Bytes(file.contentBase64);
362
+ const body = bytes.buffer.slice(
363
+ bytes.byteOffset,
364
+ bytes.byteOffset + bytes.byteLength
365
+ );
366
+ formData.set(
367
+ `file:${index}`,
368
+ new Blob([body], { type: file.contentType }),
369
+ file.logicalPath
370
+ );
371
+ }
372
+ return formData;
373
+ };
374
+ const response = await http.postFormData(PLAY_FILES_STAGE_PATH, buildFormData);
375
+ return response.files;
376
+ }
377
+ async function stagePlayFiles(http, files) {
378
+ let uploads;
379
+ try {
380
+ uploads = await mintStagedPlayFileUploads(
381
+ http,
382
+ files.map((file) => ({
383
+ logicalPath: file.logicalPath,
384
+ contentHash: file.contentHash,
385
+ contentType: file.contentType,
386
+ bytes: file.bytes
387
+ }))
388
+ );
389
+ } catch (error) {
390
+ if (isStagedUploadMintUnsupported(error)) {
391
+ return stagePlayFilesViaMultipart(http, files);
392
+ }
393
+ throw error;
394
+ }
395
+ const uploadByIdentity = /* @__PURE__ */ new Map();
396
+ for (const upload of uploads) {
397
+ uploadByIdentity.set(
398
+ stagedUploadIdentity(upload.logicalPath, upload.contentHash),
399
+ upload
400
+ );
401
+ }
402
+ const directResults = await Promise.all(
403
+ files.map(async (file) => {
404
+ const upload = uploadByIdentity.get(
405
+ stagedUploadIdentity(file.logicalPath, file.contentHash)
406
+ );
407
+ if (!upload) {
408
+ throw new DeeplineError(
409
+ `The staging server did not return an upload target for ${file.logicalPath}.`,
410
+ void 0,
411
+ "STAGED_FILE_MINT_INCOMPLETE"
412
+ );
413
+ }
414
+ if (upload.alreadyStaged || !upload.uploadUrl) {
415
+ return { ref: upload.ref };
416
+ }
417
+ try {
418
+ await uploadStagedFileToPresignedUrl({
419
+ url: upload.uploadUrl,
420
+ headers: upload.uploadHeaders ?? {
421
+ "content-type": file.contentType
422
+ },
423
+ body: decodeBase64Bytes(file.contentBase64),
424
+ logicalPath: file.logicalPath
425
+ });
426
+ return { ref: upload.ref };
427
+ } catch (error) {
428
+ if (isStagedUploadDirectEgressDenied(error)) {
429
+ return { fallbackFile: file };
430
+ }
431
+ throw error;
432
+ }
433
+ })
434
+ );
435
+ return await Promise.all(
436
+ directResults.map(async (result) => {
437
+ if ("fallbackFile" in result) {
438
+ const [ref] = await stagePlayFilesViaMultipart(
439
+ http,
440
+ [result.fallbackFile],
441
+ "direct-egress-denied"
442
+ );
443
+ if (!ref) {
444
+ throw new DeeplineError(
445
+ `The staging server did not return an upload target for ${result.fallbackFile.logicalPath}.`,
446
+ void 0,
447
+ "STAGED_FILE_MINT_INCOMPLETE"
448
+ );
449
+ }
450
+ return ref;
451
+ }
452
+ return result.ref;
453
+ })
454
+ );
455
+ }
456
+ async function stageFileInputs(input) {
457
+ const uniqueBindings = [
458
+ ...new Map(
459
+ input.bindings.map((binding) => [binding.inputPath, binding])
460
+ ).values()
461
+ ];
462
+ const localFiles = uniqueBindings.flatMap((binding) => {
463
+ const file = input.resolveLocalFile(
464
+ getDottedInputValue(input.runtimeInput, binding.inputPath),
465
+ binding
466
+ );
467
+ return file ? [{ binding, file }] : [];
468
+ });
469
+ if (localFiles.length === 0) {
470
+ return { inputFile: null, packagedFiles: [] };
471
+ }
472
+ input.onStaging?.(localFiles.length);
473
+ const uploads = await Promise.all(
474
+ localFiles.map(
475
+ async ({ file }) => createStagedFileUpload(file.logicalPath, await file.read(), input.codec)
476
+ )
477
+ );
478
+ const staged = await input.stage(uploads);
479
+ for (const [index, { binding, file }] of localFiles.entries()) {
480
+ setDottedInputValue(
481
+ input.runtimeInput,
482
+ binding.inputPath,
483
+ file.logicalPath
484
+ );
485
+ const stagedFile = staged[index];
486
+ if (stagedFile && stagedFile.logicalPath !== file.logicalPath) {
487
+ setDottedInputValue(
488
+ input.runtimeInput,
489
+ binding.inputPath,
490
+ stagedFile.logicalPath
491
+ );
492
+ }
493
+ }
494
+ return {
495
+ inputFile: staged[0] ?? null,
496
+ packagedFiles: staged.slice(1)
497
+ };
498
+ }
499
+ function createSessionPlayRunHttp(fetchImpl = (...args) => fetch(...args)) {
500
+ const send = async (path, init) => {
501
+ const response = await fetchImpl(path, {
502
+ ...init,
503
+ credentials: "include"
504
+ });
505
+ const text = await response.text();
506
+ let parsed = text;
507
+ try {
508
+ parsed = text ? JSON.parse(text) : null;
509
+ } catch {
510
+ }
511
+ if (!response.ok) {
512
+ throw new DeeplineError(
513
+ apiErrorMessage(parsed, response.status),
514
+ response.status,
515
+ apiErrorCodeFromResponse(parsed),
516
+ { response: parsed }
517
+ );
518
+ }
519
+ return parsed;
520
+ };
521
+ return {
522
+ post: (path, body, headers) => send(path, {
523
+ method: "POST",
524
+ headers: { "content-type": "application/json", ...headers },
525
+ body: JSON.stringify(body)
526
+ }),
527
+ postFormData: (path, formData) => send(path, {
528
+ method: "POST",
529
+ body: typeof formData === "function" ? formData() : formData
530
+ })
531
+ };
532
+ }
533
+
534
+ export {
535
+ isTerminalPlayRunLifecycleStatus,
536
+ decodePlayRunPublicStatus,
537
+ PLAY_RUN_START_PATH,
538
+ PLAY_RUN_START_STREAM_PATH,
539
+ PLAY_FILES_STAGE_PATH,
540
+ PLAY_FILES_STAGE_MINT_PATH,
541
+ buildPlayRunStartBody,
542
+ startPlayRun,
543
+ isPlayRunPackage,
544
+ normalizePlayRunStart,
545
+ buildNamedPlayRunRequest,
546
+ CSV_DATA_INPUT_KEY,
547
+ fileInputBindingsFromPlaySchema,
548
+ fileInputBindingsFromStaticPipeline,
549
+ playRunFileInputBindings,
550
+ getDottedInputValue,
551
+ setDottedInputValue,
552
+ webStagedFileCodec,
553
+ stagedFileContentType,
554
+ createStagedFileUpload,
555
+ STAGE_LEGACY_MULTIPART_MAX_BYTES,
556
+ mintStagedPlayFileUploads,
557
+ stagePlayFiles,
558
+ stageFileInputs,
559
+ createSessionPlayRunHttp
560
+ };