deepline 0.1.119 → 0.1.121

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 (148) hide show
  1. package/README.md +4 -0
  2. package/dist/bundling-sources/apps/play-runner-workers/src/runtime/README.md +21 -0
  3. package/dist/bundling-sources/apps/play-runner-workers/src/runtime/batching.ts +185 -0
  4. package/dist/bundling-sources/apps/play-runner-workers/src/runtime/tool-batch.ts +107 -0
  5. package/dist/{repo → bundling-sources}/sdk/src/client.ts +116 -12
  6. package/dist/bundling-sources/sdk/src/compat.ts +191 -0
  7. package/dist/bundling-sources/sdk/src/gtm.ts +146 -0
  8. package/dist/bundling-sources/sdk/src/helpers.ts +12 -0
  9. package/dist/{repo → bundling-sources}/sdk/src/index.ts +2 -1
  10. package/dist/{repo → bundling-sources}/sdk/src/play.ts +3 -1
  11. package/dist/{repo → bundling-sources}/sdk/src/plays/bundle-play-file.ts +17 -5
  12. package/dist/{repo → bundling-sources}/sdk/src/release.ts +2 -2
  13. package/dist/{repo → bundling-sources}/sdk/src/runs/observe-transport.ts +2 -3
  14. package/dist/bundling-sources/shared_libs/play-data-plane/index.ts +3 -0
  15. package/dist/bundling-sources/shared_libs/play-runtime/app-runtime-api.ts +838 -0
  16. package/dist/bundling-sources/shared_libs/play-runtime/context.ts +5510 -0
  17. package/dist/bundling-sources/shared_libs/play-runtime/ctx-contract.ts +261 -0
  18. package/dist/bundling-sources/shared_libs/play-runtime/ctx-types.ts +828 -0
  19. package/dist/bundling-sources/shared_libs/play-runtime/dataset-id.ts +10 -0
  20. package/dist/bundling-sources/shared_libs/play-runtime/daytona-runtime-config.ts +50 -0
  21. package/dist/bundling-sources/shared_libs/play-runtime/durability-store.ts +20 -0
  22. package/dist/bundling-sources/shared_libs/play-runtime/event-wait-tools.ts +9 -0
  23. package/dist/bundling-sources/shared_libs/play-runtime/governor/in-memory-rate-state-backend.ts +171 -0
  24. package/dist/bundling-sources/shared_libs/play-runtime/hatchet-cold-execution-diagnosis.ts +321 -0
  25. package/dist/bundling-sources/shared_libs/play-runtime/hatchet-cold-execution-target.ts +158 -0
  26. package/dist/bundling-sources/shared_libs/play-runtime/internal-step-ids.ts +34 -0
  27. package/dist/bundling-sources/shared_libs/play-runtime/ledger-safe-payload.ts +34 -0
  28. package/dist/bundling-sources/shared_libs/play-runtime/live-state-contract.ts +50 -0
  29. package/dist/bundling-sources/shared_libs/play-runtime/map-execution-frame.ts +119 -0
  30. package/dist/{repo → bundling-sources}/shared_libs/play-runtime/map-row-identity.ts +1 -1
  31. package/dist/bundling-sources/shared_libs/play-runtime/play-latency-trace.ts +636 -0
  32. package/dist/bundling-sources/shared_libs/play-runtime/postgres-json.ts +9 -0
  33. package/dist/bundling-sources/shared_libs/play-runtime/progress-emitter.ts +197 -0
  34. package/dist/bundling-sources/shared_libs/play-runtime/projection.ts +262 -0
  35. package/dist/bundling-sources/shared_libs/play-runtime/protocol.ts +143 -0
  36. package/dist/bundling-sources/shared_libs/play-runtime/public-play-contract.ts +42 -0
  37. package/dist/bundling-sources/shared_libs/play-runtime/receipt-status.ts +40 -0
  38. package/dist/bundling-sources/shared_libs/play-runtime/runtime-actions.ts +178 -0
  39. package/dist/bundling-sources/shared_libs/play-runtime/runtime-api.ts +4015 -0
  40. package/dist/bundling-sources/shared_libs/play-runtime/runtime-constraints.ts +2 -0
  41. package/dist/bundling-sources/shared_libs/play-runtime/runtime-pg-driver-neon-serverless.ts +238 -0
  42. package/dist/bundling-sources/shared_libs/play-runtime/runtime-pg-driver-pg.ts +53 -0
  43. package/dist/bundling-sources/shared_libs/play-runtime/runtime-pg-driver.ts +149 -0
  44. package/dist/bundling-sources/shared_libs/play-runtime/suspension.ts +68 -0
  45. package/dist/bundling-sources/shared_libs/play-runtime/tool-batch-executor.ts +149 -0
  46. package/dist/bundling-sources/shared_libs/play-runtime/tool-result-types.ts +159 -0
  47. package/dist/bundling-sources/shared_libs/play-runtime/tracing.ts +33 -0
  48. package/dist/bundling-sources/shared_libs/play-runtime/waterfall-replay.ts +79 -0
  49. package/dist/bundling-sources/shared_libs/play-runtime/worker-api-types.ts +139 -0
  50. package/dist/bundling-sources/shared_libs/plays/artifact-transport.ts +14 -0
  51. package/dist/bundling-sources/shared_libs/plays/artifact-types.ts +49 -0
  52. package/dist/bundling-sources/shared_libs/plays/compiler-manifest.ts +41 -0
  53. package/dist/bundling-sources/shared_libs/plays/dataset-summary.ts +163 -0
  54. package/dist/bundling-sources/shared_libs/plays/definition.ts +267 -0
  55. package/dist/bundling-sources/shared_libs/plays/file-refs.ts +11 -0
  56. package/dist/bundling-sources/shared_libs/plays/input-contract.ts +146 -0
  57. package/dist/bundling-sources/shared_libs/plays/resolve-static-pipeline.ts +190 -0
  58. package/dist/bundling-sources/shared_libs/plays/runtime-validation.ts +417 -0
  59. package/dist/bundling-sources/shared_libs/plays/tool-codegen.ts +142 -0
  60. package/dist/bundling-sources/shared_libs/security/safe-outbound-fetch.ts +274 -0
  61. package/dist/bundling-sources/shared_libs/temporal/preview-config.ts +150 -0
  62. package/dist/cli/index.js +811 -2207
  63. package/dist/cli/index.mjs +847 -2258
  64. package/dist/compiler-manifest-BjoRENv9.d.mts +227 -0
  65. package/dist/compiler-manifest-BjoRENv9.d.ts +227 -0
  66. package/dist/index.d.mts +8 -231
  67. package/dist/index.d.ts +8 -231
  68. package/dist/index.js +101 -15
  69. package/dist/index.mjs +101 -15
  70. package/dist/plays/bundle-play-file.d.mts +120 -0
  71. package/dist/plays/bundle-play-file.d.ts +120 -0
  72. package/dist/plays/bundle-play-file.mjs +1830 -0
  73. package/package.json +4 -9
  74. /package/dist/{repo → bundling-sources}/apps/play-runner-workers/src/child-play-await.ts +0 -0
  75. /package/dist/{repo → bundling-sources}/apps/play-runner-workers/src/child-play-submit.ts +0 -0
  76. /package/dist/{repo → bundling-sources}/apps/play-runner-workers/src/coordinator-entry.ts +0 -0
  77. /package/dist/{repo → bundling-sources}/apps/play-runner-workers/src/dedup-do.ts +0 -0
  78. /package/dist/{repo → bundling-sources}/apps/play-runner-workers/src/entry.ts +0 -0
  79. /package/dist/{repo → bundling-sources}/apps/play-runner-workers/src/runtime/csv-rows.ts +0 -0
  80. /package/dist/{repo → bundling-sources}/apps/play-runner-workers/src/runtime/dataset-handles.ts +0 -0
  81. /package/dist/{repo → bundling-sources}/apps/play-runner-workers/src/runtime/harness-receipt-store.ts +0 -0
  82. /package/dist/{repo → bundling-sources}/apps/play-runner-workers/src/runtime/live-progress.ts +0 -0
  83. /package/dist/{repo → bundling-sources}/apps/play-runner-workers/src/runtime/map-chunk-plan.ts +0 -0
  84. /package/dist/{repo → bundling-sources}/apps/play-runner-workers/src/runtime/receipts.ts +0 -0
  85. /package/dist/{repo → bundling-sources}/apps/play-runner-workers/src/runtime/row-isolation.ts +0 -0
  86. /package/dist/{repo → bundling-sources}/apps/play-runner-workers/src/runtime/tool-http-errors.ts +0 -0
  87. /package/dist/{repo → bundling-sources}/apps/play-runner-workers/src/workflow-instance-create.ts +0 -0
  88. /package/dist/{repo → bundling-sources}/apps/play-runner-workers/src/workflow-retry-state.ts +0 -0
  89. /package/dist/{repo → bundling-sources}/apps/play-runner-workers/src/workflow-retry.ts +0 -0
  90. /package/dist/{repo → bundling-sources}/sdk/src/agent-runtime.ts +0 -0
  91. /package/dist/{repo → bundling-sources}/sdk/src/config.ts +0 -0
  92. /package/dist/{repo → bundling-sources}/sdk/src/errors.ts +0 -0
  93. /package/dist/{repo → bundling-sources}/sdk/src/http.ts +0 -0
  94. /package/dist/{repo → bundling-sources}/sdk/src/plays/harness-stub.ts +0 -0
  95. /package/dist/{repo → bundling-sources}/sdk/src/plays/local-file-discovery.ts +0 -0
  96. /package/dist/{repo → bundling-sources}/sdk/src/stream-reconnect.ts +0 -0
  97. /package/dist/{repo → bundling-sources}/sdk/src/tool-output.ts +0 -0
  98. /package/dist/{repo → bundling-sources}/sdk/src/types.ts +0 -0
  99. /package/dist/{repo → bundling-sources}/sdk/src/version.ts +0 -0
  100. /package/dist/{repo → bundling-sources}/sdk/src/worker-play-entry.ts +0 -0
  101. /package/dist/{repo → bundling-sources}/shared_libs/play-data-plane/cell-policy.ts +0 -0
  102. /package/dist/{repo → bundling-sources}/shared_libs/play-data-plane/column-names.ts +0 -0
  103. /package/dist/{repo → bundling-sources}/shared_libs/play-data-plane/sheet-contract.ts +0 -0
  104. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/backend.ts +0 -0
  105. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/batch-runtime.ts +0 -0
  106. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/batching-types.ts +0 -0
  107. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/cell-staleness.ts +0 -0
  108. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/coordinator-headers.ts +0 -0
  109. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/csv-rename.ts +0 -0
  110. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/db-session-crypto.ts +0 -0
  111. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/db-session-plan.ts +0 -0
  112. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/db-session.ts +0 -0
  113. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/dedup-backend.ts +0 -0
  114. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/default-batch-strategies.ts +0 -0
  115. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/email-status.ts +0 -0
  116. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/execution-plan.ts +0 -0
  117. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/extractor-targets.ts +0 -0
  118. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/fullenrich-batching.ts +0 -0
  119. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/governor/coordinator-rate-state-backend.ts +0 -0
  120. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/governor/governor.ts +0 -0
  121. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/governor/policy.ts +0 -0
  122. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/governor/rate-state-backend.ts +0 -0
  123. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/live-events.ts +0 -0
  124. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/play-runtime-batching-registry.ts +0 -0
  125. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/profiles.ts +0 -0
  126. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/providers.ts +0 -0
  127. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/run-failure.ts +0 -0
  128. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/run-ledger.ts +0 -0
  129. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/run-snapshot-stream.ts +0 -0
  130. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/scheduler-backend.ts +0 -0
  131. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/secret-capability.ts +0 -0
  132. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/secret-redaction.ts +0 -0
  133. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/step-lifecycle-tracker.ts +0 -0
  134. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/step-program-dataset-builder.ts +0 -0
  135. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/submit-limits.ts +0 -0
  136. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/tool-result.ts +0 -0
  137. /package/dist/{repo → bundling-sources}/shared_libs/play-runtime/work-receipts.ts +0 -0
  138. /package/dist/{repo → bundling-sources}/shared_libs/plays/bootstrap-routes.ts +0 -0
  139. /package/dist/{repo → bundling-sources}/shared_libs/plays/bundling/index.ts +0 -0
  140. /package/dist/{repo → bundling-sources}/shared_libs/plays/bundling/limits.ts +0 -0
  141. /package/dist/{repo → bundling-sources}/shared_libs/plays/contracts.ts +0 -0
  142. /package/dist/{repo → bundling-sources}/shared_libs/plays/dataset.ts +0 -0
  143. /package/dist/{repo → bundling-sources}/shared_libs/plays/row-identity.ts +0 -0
  144. /package/dist/{repo → bundling-sources}/shared_libs/plays/secret-guardrails.ts +0 -0
  145. /package/dist/{repo → bundling-sources}/shared_libs/plays/static-pipeline.ts +0 -0
  146. /package/dist/{repo → bundling-sources}/shared_libs/security/outbound-url-policy.ts +0 -0
  147. /package/dist/{repo → bundling-sources}/shared_libs/security/safe-fetch.ts +0 -0
  148. /package/dist/{repo → bundling-sources}/shared_libs/temporal/constants.ts +0 -0
@@ -0,0 +1,1830 @@
1
+ // src/plays/bundle-play-file.ts
2
+ import { tmpdir as tmpdir2 } from "os";
3
+ import { dirname as dirname3, join as join3, resolve as resolve3 } from "path";
4
+ import { fileURLToPath } from "url";
5
+ import { existsSync as existsSync2 } from "fs";
6
+
7
+ // ../shared_libs/plays/bundling/index.ts
8
+ import { createHash } from "crypto";
9
+ import { existsSync, readFileSync } from "fs";
10
+ import { mkdir, readFile, realpath, stat, writeFile } from "fs/promises";
11
+ import { tmpdir } from "os";
12
+ import {
13
+ basename,
14
+ dirname,
15
+ extname,
16
+ isAbsolute,
17
+ join,
18
+ relative,
19
+ resolve
20
+ } from "path";
21
+ import { builtinModules } from "module";
22
+ import { build } from "esbuild";
23
+
24
+ // ../shared_libs/play-runtime/backend.ts
25
+ var PLAY_RUNTIME_BACKENDS = {
26
+ localProcess: "local_process",
27
+ daytona: "daytona",
28
+ // Artifact/runtime contract for Cloudflare Dynamic Workers. This is no
29
+ // longer a standalone runner backend; use profile=workers_edge so the
30
+ // cf-workflows scheduler owns loading and execution.
31
+ cloudflareWorkers: "cloudflare_workers"
32
+ };
33
+ var PLAY_ARTIFACT_KINDS = {
34
+ cjsNode20: "cjs_node20",
35
+ esmWorkers: "esm_workers"
36
+ };
37
+ var PLAY_BACKEND_DESCRIPTORS = {
38
+ [PLAY_RUNTIME_BACKENDS.localProcess]: {
39
+ id: PLAY_RUNTIME_BACKENDS.localProcess,
40
+ artifactKind: PLAY_ARTIFACT_KINDS.cjsNode20,
41
+ label: "Local node subprocess"
42
+ },
43
+ [PLAY_RUNTIME_BACKENDS.daytona]: {
44
+ id: PLAY_RUNTIME_BACKENDS.daytona,
45
+ artifactKind: PLAY_ARTIFACT_KINDS.cjsNode20,
46
+ label: "Daytona sandbox"
47
+ },
48
+ [PLAY_RUNTIME_BACKENDS.cloudflareWorkers]: {
49
+ id: PLAY_RUNTIME_BACKENDS.cloudflareWorkers,
50
+ artifactKind: PLAY_ARTIFACT_KINDS.esmWorkers,
51
+ label: "Cloudflare Dynamic Workers"
52
+ }
53
+ };
54
+
55
+ // ../shared_libs/plays/contracts.ts
56
+ var PLAY_PUBLIC_API_VERSION = 1;
57
+ var PLAY_ARTIFACT_VERSION = 1;
58
+ var PLAY_MIN_RUNNER_VERSION = 1;
59
+ var PLAY_RUNTIME_FEATURES = [
60
+ "artifact_storage",
61
+ "checkpoint_resume",
62
+ "durable_sleep",
63
+ "packaged_files"
64
+ ];
65
+ function buildPlayContractCompatibility(input) {
66
+ return {
67
+ apiVersion: PLAY_PUBLIC_API_VERSION,
68
+ artifactVersion: PLAY_ARTIFACT_VERSION,
69
+ minRunnerVersion: PLAY_MIN_RUNNER_VERSION,
70
+ runtimeFeatures: [...PLAY_RUNTIME_FEATURES],
71
+ runtimeBackend: input?.runtimeBackend ?? null
72
+ };
73
+ }
74
+
75
+ // ../shared_libs/plays/secret-guardrails.ts
76
+ var SECRET_ENV_PATTERN = /\bprocess(?:\.env|\[['"]env['"]\])(?:\.|\[['"])([A-Z0-9_]*(?:API[_-]?KEY|TOKEN|SECRET|PASSWORD|PRIVATE[_-]?KEY|ACCESS[_-]?KEY)[A-Z0-9_]*)(?:['"]\])?/g;
77
+ var PRIVATE_KEY_PATTERN = /-----BEGIN (?:RSA |EC |OPENSSH |PGP )?PRIVATE KEY-----/;
78
+ var BEARER_LITERAL_PATTERN = /\bBearer\s+[A-Za-z0-9._~+/=-]{16,}/i;
79
+ var ASSIGNMENT_SECRET_LITERAL_PATTERN = /\b(?:api[_-]?key|token|secret|password)\b\s*[:=]\s*['"][^'"]{12,}['"]/i;
80
+ var HIGH_ENTROPY_LITERAL_PATTERN = /['"]([A-Za-z0-9+/=_-]{32,})['"]/g;
81
+ function shannonEntropy(value) {
82
+ const counts = /* @__PURE__ */ new Map();
83
+ for (const char of value) counts.set(char, (counts.get(char) ?? 0) + 1);
84
+ return [...counts.values()].reduce((entropy, count) => {
85
+ const p = count / value.length;
86
+ return entropy - p * Math.log2(p);
87
+ }, 0);
88
+ }
89
+ function collectInlineSecretFindings(sourceCode) {
90
+ const findings = [];
91
+ for (const match of sourceCode.matchAll(SECRET_ENV_PATTERN)) {
92
+ findings.push(`process.env.${match[1]}`);
93
+ }
94
+ if (PRIVATE_KEY_PATTERN.test(sourceCode)) findings.push("private key block");
95
+ if (BEARER_LITERAL_PATTERN.test(sourceCode))
96
+ findings.push("bearer token literal");
97
+ if (ASSIGNMENT_SECRET_LITERAL_PATTERN.test(sourceCode)) {
98
+ findings.push("secret-looking assignment literal");
99
+ }
100
+ for (const match of sourceCode.matchAll(HIGH_ENTROPY_LITERAL_PATTERN)) {
101
+ const literal = match[1] ?? "";
102
+ if (literal.length >= 40 && shannonEntropy(literal) >= 4.2) {
103
+ findings.push("high-entropy string literal");
104
+ break;
105
+ }
106
+ }
107
+ return [...new Set(findings)];
108
+ }
109
+ function validatePlaySourceHasNoInlineSecrets(input) {
110
+ const findings = collectInlineSecretFindings(input.sourceCode);
111
+ if (!findings.length) return;
112
+ throw new Error(
113
+ [
114
+ `Play source ${input.filePath} appears to contain inline secret material: ${[
115
+ ...new Set(findings)
116
+ ].join(", ")}.`,
117
+ 'Author secrets in the dashboard and use ctx.secrets.get("NAME") with an approved helper such as ctx.secrets.bearer(handle).'
118
+ ].join(" ")
119
+ );
120
+ }
121
+ function validatePlaySourceFilesHaveNoInlineSecrets(sourceFiles) {
122
+ for (const [filePath, sourceCode] of Object.entries(sourceFiles)) {
123
+ validatePlaySourceHasNoInlineSecrets({ filePath, sourceCode });
124
+ }
125
+ }
126
+
127
+ // ../shared_libs/plays/bundling/limits.ts
128
+ var MAX_PLAY_BUNDLE_BYTES = 30 * 1024 * 1024;
129
+ var MAX_ESM_WORKERS_BUNDLE_BYTES = 115e4;
130
+
131
+ // ../shared_libs/plays/bundling/index.ts
132
+ var PLAY_BUNDLE_CACHE_VERSION = 24;
133
+ var PLAY_ARTIFACT_CACHE_DIR = join(
134
+ tmpdir(),
135
+ `deepline-play-artifacts-v${PLAY_BUNDLE_CACHE_VERSION}`
136
+ );
137
+ var PLAY_PROXY_NAMESPACE = "deepline-play-runtime-ref";
138
+ var SOURCE_EXTENSIONS = [
139
+ ".ts",
140
+ ".tsx",
141
+ ".mts",
142
+ ".cts",
143
+ ".js",
144
+ ".jsx",
145
+ ".mjs",
146
+ ".cjs",
147
+ ".json"
148
+ ];
149
+ var WORKERS_PLAY_ENTRY_VIRTUAL = "deepline-play-entry";
150
+ var PLAY_SOURCE_FILE_PATTERN = /\.play\.(?:[cm]?[jt]sx?)$/i;
151
+ var NODE_BUILTIN_SET = new Set(
152
+ builtinModules.flatMap(
153
+ (name) => name.startsWith("node:") ? [name, name.slice(5)] : [name, `node:${name}`]
154
+ )
155
+ );
156
+ function assertValidExportName(exportName) {
157
+ if (exportName === "default") return;
158
+ if (!/^[A-Za-z_$][A-Za-z0-9_$]*$/.test(exportName)) {
159
+ throw new Error(
160
+ `Invalid play export name "${exportName}". Named prebuilt exports must be valid JavaScript identifiers.`
161
+ );
162
+ }
163
+ }
164
+ function sha256(value) {
165
+ return createHash("sha256").update(value).digest("hex");
166
+ }
167
+ function formatEsbuildMessage(message) {
168
+ const location = message.location ? `${message.location.file}:${message.location.line}:${message.location.column}` : null;
169
+ return location ? `${location} ${message.text}` : message.text;
170
+ }
171
+ function isLocalSpecifier(specifier) {
172
+ return specifier.startsWith("./") || specifier.startsWith("../") || specifier.startsWith("/") || specifier.startsWith("file:");
173
+ }
174
+ async function normalizeLocalPath(filePath) {
175
+ try {
176
+ return await realpath(filePath);
177
+ } catch {
178
+ return resolve(filePath);
179
+ }
180
+ }
181
+ function createPlayWorkspace(entryFile) {
182
+ return {
183
+ entryFile,
184
+ rootDir: dirname(entryFile)
185
+ };
186
+ }
187
+ function isPathInsideDirectory(filePath, directory) {
188
+ return filePath === directory || filePath.startsWith(`${directory}/`);
189
+ }
190
+ function assertWithinPlayWorkspace(input) {
191
+ if (isPathInsideDirectory(input.resolvedPath, input.workspace.rootDir)) {
192
+ return;
193
+ }
194
+ throw new Error(
195
+ `${input.importer}:${input.line}:${input.column} Local play imports must stay inside the play workspace (${input.workspace.rootDir}). Import "${input.specifier}" resolved to ${input.resolvedPath}, which crosses into app/backend code. Use the public SDK/API surface or move shared helpers into the play workspace.`
196
+ );
197
+ }
198
+ function getPackageName(specifier) {
199
+ if (specifier.startsWith("@")) {
200
+ const [scope, name] = specifier.split("/");
201
+ return scope && name ? `${scope}/${name}` : specifier;
202
+ }
203
+ return specifier.split("/")[0] ?? specifier;
204
+ }
205
+ function isPlaySourceFile(filePath) {
206
+ return PLAY_SOURCE_FILE_PATTERN.test(filePath);
207
+ }
208
+ function stripCommentsToSpaces(source) {
209
+ return source.replace(/\/\*[\s\S]*?\*\//g, (match) => match.replace(/[^\n]/g, " ")).replace(
210
+ /(^|[^:])\/\/.*$/gm,
211
+ (match, prefix) => prefix + " ".repeat(Math.max(0, match.length - prefix.length))
212
+ );
213
+ }
214
+ function lineAndColumnAt(source, index) {
215
+ const prefix = source.slice(0, index);
216
+ const lines = prefix.split("\n");
217
+ return { line: lines.length, column: lines[lines.length - 1].length + 1 };
218
+ }
219
+ function findSourceImportReferences(sourceCode) {
220
+ const source = stripCommentsToSpaces(sourceCode);
221
+ const references = [];
222
+ const addReference = (specifier, specifierIndex, kind) => {
223
+ if (!specifier) return;
224
+ const position = lineAndColumnAt(sourceCode, specifierIndex);
225
+ references.push({
226
+ specifier,
227
+ line: position.line,
228
+ column: position.column,
229
+ kind
230
+ });
231
+ };
232
+ const staticImportPattern = /\b(?:import|export)\s+(?!type\b)(?:[\s\S]*?\s+from\s*)?(['"])([^'"\n]+)\1/g;
233
+ for (const match of source.matchAll(staticImportPattern)) {
234
+ addReference(
235
+ match[2],
236
+ match.index + match[0].lastIndexOf(match[1]),
237
+ "static"
238
+ );
239
+ }
240
+ const dynamicImportPattern = /\bimport\s*\(\s*(['"])([^'"\n]+)\1/g;
241
+ for (const match of source.matchAll(dynamicImportPattern)) {
242
+ addReference(
243
+ match[2],
244
+ match.index + match[0].lastIndexOf(match[1]),
245
+ "dynamic-import"
246
+ );
247
+ }
248
+ const requirePattern = /\brequire\s*\(\s*(['"])([^'"\n]+)\1/g;
249
+ for (const match of source.matchAll(requirePattern)) {
250
+ addReference(
251
+ match[2],
252
+ match.index + match[0].lastIndexOf(match[1]),
253
+ "require"
254
+ );
255
+ }
256
+ const literalDynamicImportIndexes = new Set(
257
+ [...source.matchAll(dynamicImportPattern)].map((match) => match.index)
258
+ );
259
+ for (const match of source.matchAll(/\bimport\s*\(/g)) {
260
+ if (literalDynamicImportIndexes.has(match.index)) continue;
261
+ const position = lineAndColumnAt(sourceCode, match.index);
262
+ throw new Error(
263
+ `:${position.line}:${position.column} Dynamic import() is not allowed in plays. Use static imports instead.`
264
+ );
265
+ }
266
+ const literalRequireIndexes = new Set(
267
+ [...source.matchAll(requirePattern)].map((match) => match.index)
268
+ );
269
+ for (const match of source.matchAll(/\brequire\s*\(/g)) {
270
+ if (literalRequireIndexes.has(match.index)) continue;
271
+ const position = lineAndColumnAt(sourceCode, match.index);
272
+ throw new Error(
273
+ `:${position.line}:${position.column} Dynamic require() is not allowed in plays. Use static imports or require("literal") only.`
274
+ );
275
+ }
276
+ return references.sort(
277
+ (left, right) => left.line === right.line ? left.column - right.column : left.line - right.line
278
+ );
279
+ }
280
+ function unquoteStringLiteral(literal) {
281
+ const trimmed = literal.trim();
282
+ const quote = trimmed[0];
283
+ if (quote !== '"' && quote !== "'" || trimmed[trimmed.length - 1] !== quote) {
284
+ return null;
285
+ }
286
+ try {
287
+ return JSON.parse(
288
+ quote === '"' ? trimmed : `"${trimmed.slice(1, -1).replace(/"/g, '\\"')}"`
289
+ );
290
+ } catch {
291
+ return trimmed.slice(1, -1);
292
+ }
293
+ }
294
+ function findMatchingBrace(source, openIndex) {
295
+ let depth = 0;
296
+ let quote = null;
297
+ let escaped = false;
298
+ for (let index = openIndex; index < source.length; index += 1) {
299
+ const char = source[index];
300
+ if (quote) {
301
+ if (escaped) {
302
+ escaped = false;
303
+ } else if (char === "\\") {
304
+ escaped = true;
305
+ } else if (char === quote) {
306
+ quote = null;
307
+ }
308
+ continue;
309
+ }
310
+ if (char === '"' || char === "'" || char === "`") {
311
+ quote = char;
312
+ continue;
313
+ }
314
+ if (char === "{") depth += 1;
315
+ if (char === "}") {
316
+ depth -= 1;
317
+ if (depth === 0) return index;
318
+ }
319
+ }
320
+ return -1;
321
+ }
322
+ function extractDefinedPlayName(sourceCode) {
323
+ const source = stripCommentsToSpaces(sourceCode);
324
+ const callPattern = /(?:\b[A-Za-z_$][\w$]*\s*\.\s*)?\b(?:definePlay|defineWorkflow)\s*\(/g;
325
+ for (const match of source.matchAll(callPattern)) {
326
+ const openParen = match.index + match[0].length - 1;
327
+ const firstArgStart = openParen + 1;
328
+ const firstNonSpace = source.slice(firstArgStart).search(/\S/);
329
+ if (firstNonSpace < 0) continue;
330
+ const argIndex = firstArgStart + firstNonSpace;
331
+ const quote = source[argIndex];
332
+ if (quote === '"' || quote === "'") {
333
+ const literalMatch = source.slice(argIndex).match(/^(['"])(?:\\.|(?!\1)[\s\S])*\1/);
334
+ const value = literalMatch ? unquoteStringLiteral(literalMatch[0]) : null;
335
+ if (value?.trim()) return value.trim();
336
+ }
337
+ if (quote === "{") {
338
+ const closeBrace = findMatchingBrace(source, argIndex);
339
+ if (closeBrace < 0) continue;
340
+ const objectSource = source.slice(argIndex + 1, closeBrace);
341
+ const idMatch = objectSource.match(
342
+ /(?:^|[,{\s])(?:id|['"]id['"])\s*:\s*(['"])([\s\S]*?)\1/
343
+ );
344
+ if (idMatch?.[2]?.trim()) {
345
+ return idMatch[2].trim();
346
+ }
347
+ }
348
+ }
349
+ return null;
350
+ }
351
+ function canonicalizeRootPlayNameForWorkersRuntimeHash(sourceCode) {
352
+ const source = stripCommentsToSpaces(sourceCode);
353
+ const callPattern = /(?:\b[A-Za-z_$][\w$]*\s*\.\s*)?\b(?:definePlay|defineWorkflow)\s*\(/g;
354
+ const match = callPattern.exec(source);
355
+ if (!match) return sourceCode;
356
+ const openParen = match.index + match[0].length - 1;
357
+ const firstArgStart = openParen + 1;
358
+ const firstNonSpace = source.slice(firstArgStart).search(/\S/);
359
+ if (firstNonSpace < 0) return sourceCode;
360
+ const argIndex = firstArgStart + firstNonSpace;
361
+ const quote = source[argIndex];
362
+ if (quote === '"' || quote === "'") {
363
+ const literalMatch = source.slice(argIndex).match(/^(['"])(?:\\.|(?!\1)[\s\S])*\1/);
364
+ if (!literalMatch) return sourceCode;
365
+ const replacement = `${quote}__deepline_runtime_play_name__${quote}`;
366
+ return `${sourceCode.slice(0, argIndex)}${replacement}${sourceCode.slice(argIndex + literalMatch[0].length)}`;
367
+ }
368
+ if (quote !== "{") return sourceCode;
369
+ const closeBrace = findMatchingBrace(source, argIndex);
370
+ if (closeBrace < 0) return sourceCode;
371
+ const objectSource = source.slice(argIndex + 1, closeBrace);
372
+ const idMatch = objectSource.match(
373
+ /(^|[,{\s])((?:id|['"]id['"])\s*:\s*)(['"])([\s\S]*?)\3/
374
+ );
375
+ if (!idMatch || idMatch.index === void 0) return sourceCode;
376
+ const idValueStart = argIndex + 1 + idMatch.index + idMatch[1].length + idMatch[2].length + idMatch[3].length;
377
+ return `${sourceCode.slice(0, idValueStart)}__deepline_runtime_play_name__${sourceCode.slice(idValueStart + idMatch[4].length)}`;
378
+ }
379
+ function workersRuntimeGraphFilePath(input) {
380
+ if (input.filePath === input.entryFile) return "<entry>";
381
+ const entryRelative = relative(dirname(input.entryFile), input.filePath);
382
+ if (entryRelative && !entryRelative.startsWith("..")) {
383
+ return entryRelative.replaceAll("\\", "/");
384
+ }
385
+ return `<project>/${relative(input.adapter.projectRoot, input.filePath).replaceAll("\\", "/")}`;
386
+ }
387
+ function buildWorkersRuntimeGraphHash(input) {
388
+ const sourceFiles = Object.entries(input.analysis.sourceFiles).map(([filePath, contents]) => ({
389
+ filePath: workersRuntimeGraphFilePath({
390
+ entryFile: input.entryFile,
391
+ filePath,
392
+ adapter: input.adapter
393
+ }),
394
+ hash: sha256(
395
+ filePath === input.entryFile ? canonicalizeRootPlayNameForWorkersRuntimeHash(contents) : contents
396
+ )
397
+ })).sort((left, right) => left.filePath.localeCompare(right.filePath));
398
+ return sha256(
399
+ JSON.stringify({
400
+ entryFile: "<entry>",
401
+ entryExport: input.exportName,
402
+ localFiles: sourceFiles,
403
+ nodeBuiltins: [...input.analysis.importPolicy.nodeBuiltins].sort(),
404
+ packages: input.analysis.importPolicy.packages.map(({ name, version }) => ({ name, version })).sort((left, right) => left.name.localeCompare(right.name)),
405
+ importedPlayDependencies: input.analysis.importedPlayDependencies.map((dependency) => ({
406
+ filePath: workersRuntimeGraphFilePath({
407
+ entryFile: input.entryFile,
408
+ filePath: dependency.filePath,
409
+ adapter: input.adapter
410
+ }),
411
+ playName: dependency.playName
412
+ })).sort((left, right) => left.filePath.localeCompare(right.filePath))
413
+ })
414
+ );
415
+ }
416
+ function readPackageVersionFromPackageJson(packageJsonPath, packageName) {
417
+ try {
418
+ const packageJson = JSON.parse(readFileSync(packageJsonPath, "utf-8"));
419
+ if (packageJson.name === packageName && typeof packageJson.version === "string") {
420
+ return packageJson.version;
421
+ }
422
+ } catch {
423
+ return null;
424
+ }
425
+ return null;
426
+ }
427
+ function findPackageJsonPathFrom(startDir, packageName) {
428
+ if (!isAbsolute(startDir)) {
429
+ throw new Error(
430
+ `Package resolution requires an absolute start directory, got ${startDir}`
431
+ );
432
+ }
433
+ let current = startDir;
434
+ while (true) {
435
+ const packageJsonPath = join(
436
+ current,
437
+ "node_modules",
438
+ packageName,
439
+ "package.json"
440
+ );
441
+ if (existsSync(packageJsonPath)) {
442
+ return packageJsonPath;
443
+ }
444
+ const parent = dirname(current);
445
+ if (parent === current) {
446
+ return null;
447
+ }
448
+ current = parent;
449
+ }
450
+ }
451
+ function findPackageJsonPath(packageName, fromFile, adapter) {
452
+ const startDirs = [
453
+ resolve(dirname(fromFile)),
454
+ resolve(adapter.projectRoot),
455
+ resolve(dirname(adapter.sdkPackageJson))
456
+ ];
457
+ const seen = /* @__PURE__ */ new Set();
458
+ for (const startDir of startDirs) {
459
+ if (seen.has(startDir)) continue;
460
+ seen.add(startDir);
461
+ const packageJsonPath = findPackageJsonPathFrom(startDir, packageName);
462
+ if (packageJsonPath) return packageJsonPath;
463
+ }
464
+ const adapterNodeModulesPackageJson = join(
465
+ adapter.nodeModulesDir,
466
+ packageName,
467
+ "package.json"
468
+ );
469
+ return existsSync(adapterNodeModulesPackageJson) ? adapterNodeModulesPackageJson : null;
470
+ }
471
+ function localSdkAliasPlugin(adapter, options) {
472
+ const entryFile = options?.workersRuntime ? adapter.sdkWorkersEntryFile : adapter.sdkEntryFile;
473
+ if (!existsSync(entryFile)) {
474
+ return null;
475
+ }
476
+ return {
477
+ name: "deepline-sdk-local-alias",
478
+ setup(buildContext) {
479
+ buildContext.onResolve({ filter: /^deepline$/ }, () => ({
480
+ path: entryFile
481
+ }));
482
+ buildContext.onResolve({ filter: /^deepline\/helpers$/ }, () => ({
483
+ path: join(adapter.sdkSourceRoot, "helpers.ts")
484
+ }));
485
+ }
486
+ };
487
+ }
488
+ function workersPlayEntryAliasPlugin(playFilePath) {
489
+ return {
490
+ name: "deepline-workers-play-entry-alias",
491
+ setup(buildContext) {
492
+ buildContext.onResolve(
493
+ { filter: new RegExp(`^${WORKERS_PLAY_ENTRY_VIRTUAL}$`) },
494
+ () => ({ path: playFilePath })
495
+ );
496
+ }
497
+ };
498
+ }
499
+ function workersNamedPlayEntryAliasPlugin(playFilePath, exportName) {
500
+ return {
501
+ name: "deepline-workers-named-play-entry-alias",
502
+ setup(buildContext) {
503
+ buildContext.onResolve(
504
+ { filter: new RegExp(`^${WORKERS_PLAY_ENTRY_VIRTUAL}$`) },
505
+ () => ({
506
+ path: `${playFilePath}.${exportName}.entry.ts`,
507
+ namespace: "deepline-named-play-entry"
508
+ })
509
+ );
510
+ buildContext.onLoad(
511
+ { filter: /.*/, namespace: "deepline-named-play-entry" },
512
+ () => ({
513
+ contents: `export { ${exportName} as default } from ${JSON.stringify(playFilePath)};
514
+ `,
515
+ loader: "ts",
516
+ resolveDir: dirname(playFilePath)
517
+ })
518
+ );
519
+ }
520
+ };
521
+ }
522
+ function workersNodeBuiltinStubPlugin() {
523
+ const UNSUPPORTED = /* @__PURE__ */ new Set([
524
+ "node:fs",
525
+ "node:fs/promises",
526
+ "node:os",
527
+ "node:child_process"
528
+ ]);
529
+ return {
530
+ name: "deepline-workers-node-builtin-stub",
531
+ setup(buildContext) {
532
+ buildContext.onResolve({ filter: /^node:/ }, (args) => {
533
+ if (!UNSUPPORTED.has(args.path)) return null;
534
+ return { path: args.path, namespace: "deepline-workers-node-stub" };
535
+ });
536
+ buildContext.onLoad(
537
+ { filter: /.*/, namespace: "deepline-workers-node-stub" },
538
+ (args) => {
539
+ const builtinName = args.path;
540
+ const stubSource = `
541
+ const message = ${JSON.stringify(
542
+ `Workers backend: ${builtinName} is not available in Cloudflare Workers (no filesystem / no OS). Run this play on Daytona or local-process backend if it needs node builtins.`
543
+ )};
544
+ function makeThrower(name) {
545
+ return new Proxy(function() { throw new Error(message + ' (called: ' + name + ')'); }, {
546
+ get(_t, prop) {
547
+ if (prop === '__esModule') return true;
548
+ if (typeof prop === 'symbol') return undefined;
549
+ return makeThrower(name + '.' + String(prop));
550
+ },
551
+ apply() { throw new Error(message + ' (called: ' + name + ')'); },
552
+ construct() { throw new Error(message + ' (constructed: ' + name + ')'); },
553
+ });
554
+ }
555
+ module.exports = makeThrower(${JSON.stringify(builtinName)});
556
+ `;
557
+ return { contents: stubSource, loader: "js" };
558
+ }
559
+ );
560
+ }
561
+ };
562
+ }
563
+ function zodNonEnglishLocaleStubPlugin() {
564
+ const LOCALE_PATH_FILTER = /[\\/]zod[\\/]v4[\\/]locales[\\/][^\\/]+\.(?:c?js|mjs)$/;
565
+ const NAMESPACE = "deepline-zod-locale-stub";
566
+ return {
567
+ name: "deepline-zod-non-english-locale-stub",
568
+ setup(buildContext) {
569
+ buildContext.onResolve({ filter: LOCALE_PATH_FILTER }, (args) => {
570
+ const norm = args.path.replace(/\\/g, "/");
571
+ const file = norm.slice(norm.lastIndexOf("/") + 1);
572
+ if (/^en(?:[-_][A-Za-z]+)?\.(?:c?js|mjs)$/.test(file)) {
573
+ return null;
574
+ }
575
+ return { path: args.path, namespace: NAMESPACE };
576
+ });
577
+ buildContext.onLoad({ filter: /.*/, namespace: NAMESPACE }, () => ({
578
+ // zod locales export a default object literal. Empty object is
579
+ // structurally compatible — accessing any locale key returns
580
+ // undefined and zod falls back to its built-in English.
581
+ contents: "export default {};",
582
+ loader: "js"
583
+ }));
584
+ }
585
+ };
586
+ }
587
+ var WORKERS_BANNED_NODE_MODULES = /* @__PURE__ */ new Set([
588
+ "node:fs",
589
+ "node:fs/promises",
590
+ "node:net",
591
+ "node:child_process",
592
+ "node:cluster",
593
+ "node:tls",
594
+ "node:dgram",
595
+ "node:dns",
596
+ "node:dns/promises",
597
+ "node:repl",
598
+ "node:vm",
599
+ "node:worker_threads"
600
+ ]);
601
+ function workersNodeImportBanlistPlugin(adapter) {
602
+ return {
603
+ name: "deepline-workers-node-import-banlist",
604
+ setup(buildContext) {
605
+ buildContext.onResolve({ filter: /^node:/ }, (args) => {
606
+ if (!WORKERS_BANNED_NODE_MODULES.has(args.path)) return null;
607
+ const importer = args.importer ?? "";
608
+ if (importer.startsWith(adapter.sdkSourceRoot)) {
609
+ return null;
610
+ }
611
+ return {
612
+ errors: [
613
+ {
614
+ text: `Module "${args.path}" is not allowed in workers_edge plays. See AGENTS.md for the V8 isolate boundary.`,
615
+ detail: { importer: args.importer, kind: args.kind }
616
+ }
617
+ ]
618
+ };
619
+ });
620
+ }
621
+ };
622
+ }
623
+ function buildImportedPlayProxyModule(playName) {
624
+ const serializedName = JSON.stringify(playName);
625
+ return `
626
+ const PLAY_METADATA_SYMBOL = Symbol.for('deepline.play.metadata');
627
+ const importedPlayRef = async function importedPlayRef(ctx, input) {
628
+ return ctx.runPlay(${JSON.stringify(`imported_${playName.replace(/[^A-Za-z0-9_]+/g, "_")}`)}, importedPlayRef, input, {
629
+ description: 'Run the imported Deepline play dependency.',
630
+ });
631
+ };
632
+ Object.defineProperty(importedPlayRef, 'playName', {
633
+ value: ${serializedName},
634
+ enumerable: true,
635
+ configurable: false,
636
+ writable: false,
637
+ });
638
+ Object.defineProperty(importedPlayRef, PLAY_METADATA_SYMBOL, {
639
+ value: { name: ${serializedName} },
640
+ enumerable: false,
641
+ configurable: false,
642
+ writable: false,
643
+ });
644
+ export const playName = ${serializedName};
645
+ export const name = ${serializedName};
646
+ export default importedPlayRef;
647
+ `;
648
+ }
649
+ function importedPlayProxyPlugin(importedPlayDependencies) {
650
+ if (importedPlayDependencies.length === 0) {
651
+ return null;
652
+ }
653
+ const dependenciesByPath = new Map(
654
+ importedPlayDependencies.map((dependency) => [
655
+ dependency.filePath,
656
+ dependency
657
+ ])
658
+ );
659
+ return {
660
+ name: "deepline-imported-play-proxy",
661
+ setup(buildContext) {
662
+ buildContext.onResolve({ filter: /.*/ }, async (args) => {
663
+ if (!args.importer || !isLocalSpecifier(args.path)) {
664
+ return null;
665
+ }
666
+ const resolvedPath = await resolveLocalImport(args.importer, args.path);
667
+ const dependency = dependenciesByPath.get(resolvedPath);
668
+ if (!dependency) {
669
+ return null;
670
+ }
671
+ return {
672
+ path: dependency.filePath,
673
+ namespace: PLAY_PROXY_NAMESPACE,
674
+ pluginData: dependency
675
+ };
676
+ });
677
+ buildContext.onLoad(
678
+ { filter: /.*/, namespace: PLAY_PROXY_NAMESPACE },
679
+ async (args) => {
680
+ const dependency = args.pluginData ?? dependenciesByPath.get(args.path);
681
+ if (!dependency) {
682
+ return null;
683
+ }
684
+ return {
685
+ contents: buildImportedPlayProxyModule(dependency.playName),
686
+ loader: "ts",
687
+ resolveDir: dirname(args.path)
688
+ };
689
+ }
690
+ );
691
+ }
692
+ };
693
+ }
694
+ async function fileExists(filePath) {
695
+ try {
696
+ await stat(filePath);
697
+ return true;
698
+ } catch {
699
+ return false;
700
+ }
701
+ }
702
+ async function resolveLocalImport(fromFile, specifier) {
703
+ if (specifier.startsWith("file:")) {
704
+ return normalizeLocalPath(new URL(specifier).pathname);
705
+ }
706
+ const base = isAbsolute(specifier) ? resolve(specifier) : resolve(dirname(fromFile), specifier);
707
+ const candidates = [base];
708
+ const explicitExtension = extname(base).toLowerCase();
709
+ if (!explicitExtension) {
710
+ candidates.push(
711
+ ...SOURCE_EXTENSIONS.map((extension) => `${base}${extension}`)
712
+ );
713
+ candidates.push(
714
+ ...SOURCE_EXTENSIONS.map((extension) => join(base, `index${extension}`))
715
+ );
716
+ } else if ([".js", ".jsx", ".mjs", ".cjs"].includes(explicitExtension)) {
717
+ const stem = base.slice(0, -explicitExtension.length);
718
+ candidates.push(
719
+ ...SOURCE_EXTENSIONS.map((extension) => `${stem}${extension}`)
720
+ );
721
+ }
722
+ for (const candidate of candidates) {
723
+ if (await fileExists(candidate)) {
724
+ return normalizeLocalPath(candidate);
725
+ }
726
+ }
727
+ throw new Error(
728
+ `Could not resolve local import "${specifier}" from ${fromFile}`
729
+ );
730
+ }
731
+ function resolvePackageImport(specifier, fromFile, adapter) {
732
+ const packageName = getPackageName(specifier);
733
+ if (packageName === "deepline" && existsSync(adapter.sdkPackageJson)) {
734
+ const packageJson = JSON.parse(
735
+ readFileSync(adapter.sdkPackageJson, "utf-8")
736
+ );
737
+ return {
738
+ name: "deepline",
739
+ version: packageJson.version ?? null
740
+ };
741
+ }
742
+ const packageJsonPath = findPackageJsonPath(packageName, fromFile, adapter);
743
+ if (!packageJsonPath) {
744
+ throw new Error(`Could not resolve "${specifier}" from ${fromFile}`);
745
+ }
746
+ return {
747
+ name: packageName,
748
+ version: readPackageVersionFromPackageJson(packageJsonPath, packageName)
749
+ };
750
+ }
751
+ async function analyzeSourceGraph(entryFile, adapter) {
752
+ const absoluteEntryFile = await normalizeLocalPath(entryFile);
753
+ const workspace = createPlayWorkspace(absoluteEntryFile);
754
+ const localFiles = /* @__PURE__ */ new Map();
755
+ const nodeBuiltins = /* @__PURE__ */ new Set();
756
+ const packages = /* @__PURE__ */ new Map();
757
+ const importedPlayDependencies = /* @__PURE__ */ new Map();
758
+ const visited = /* @__PURE__ */ new Set();
759
+ const visitFile = async (filePath) => {
760
+ const absolutePath = await normalizeLocalPath(filePath);
761
+ if (visited.has(absolutePath)) {
762
+ return;
763
+ }
764
+ visited.add(absolutePath);
765
+ const sourceCode2 = await readFile(absolutePath, "utf-8");
766
+ localFiles.set(absolutePath, sourceCode2);
767
+ if (extname(absolutePath).toLowerCase() === ".json") {
768
+ return;
769
+ }
770
+ const handleSpecifier = async (specifier, line, column, kind) => {
771
+ if (kind === "dynamic-import") {
772
+ throw new Error(
773
+ `${absolutePath}:${line}:${column} Dynamic import() is not allowed in plays. Use static imports instead.`
774
+ );
775
+ }
776
+ if (NODE_BUILTIN_SET.has(specifier)) {
777
+ nodeBuiltins.add(
778
+ specifier.startsWith("node:") ? specifier : `node:${specifier}`
779
+ );
780
+ return;
781
+ }
782
+ if (isLocalSpecifier(specifier)) {
783
+ const resolved = await resolveLocalImport(absolutePath, specifier);
784
+ assertWithinPlayWorkspace({
785
+ importer: absolutePath,
786
+ specifier,
787
+ resolvedPath: resolved,
788
+ workspace,
789
+ line,
790
+ column
791
+ });
792
+ if (resolved !== absoluteEntryFile && isPlaySourceFile(resolved)) {
793
+ const importedSource = await readFile(resolved, "utf-8");
794
+ const importedPlayName = extractDefinedPlayName(importedSource);
795
+ if (!importedPlayName) {
796
+ throw new Error(
797
+ `${absolutePath}:${line}:${column} Imported play file "${specifier}" must export definePlay(...) so it can be runtime-composed.`
798
+ );
799
+ }
800
+ importedPlayDependencies.set(resolved, {
801
+ filePath: resolved,
802
+ playName: importedPlayName
803
+ });
804
+ return;
805
+ }
806
+ await visitFile(resolved);
807
+ return;
808
+ }
809
+ if (specifier.includes(":")) {
810
+ throw new Error(
811
+ `${absolutePath}:${line}:${column} Unsupported import specifier "${specifier}". Allowed imports are relative files, Node builtins, and installed packages.`
812
+ );
813
+ }
814
+ const packageImport = resolvePackageImport(
815
+ specifier,
816
+ absolutePath,
817
+ adapter
818
+ );
819
+ packages.set(packageImport.name, packageImport.version);
820
+ };
821
+ try {
822
+ for (const reference of findSourceImportReferences(sourceCode2)) {
823
+ await handleSpecifier(
824
+ reference.specifier,
825
+ reference.line,
826
+ reference.column,
827
+ reference.kind
828
+ );
829
+ }
830
+ } catch (error) {
831
+ if (error instanceof Error && error.message.startsWith(":")) {
832
+ throw new Error(`${absolutePath}${error.message}`);
833
+ }
834
+ throw error;
835
+ }
836
+ };
837
+ await visitFile(absoluteEntryFile);
838
+ const sourceCode = localFiles.get(absoluteEntryFile) ?? "";
839
+ const sourceHash = sha256(sourceCode);
840
+ const graphHash = sha256(
841
+ JSON.stringify({
842
+ entryFile: absoluteEntryFile,
843
+ localFiles: [...localFiles.entries()].map(([filePath, contents]) => ({ filePath, hash: sha256(contents) })).sort((left, right) => left.filePath.localeCompare(right.filePath)),
844
+ nodeBuiltins: [...nodeBuiltins].sort(),
845
+ packages: [...packages.entries()].map(([name, version]) => ({ name, version })).sort((left, right) => left.name.localeCompare(right.name)),
846
+ importedPlayDependencies: [...importedPlayDependencies.values()].map((dependency) => ({
847
+ filePath: dependency.filePath,
848
+ playName: dependency.playName
849
+ })).sort((left, right) => left.filePath.localeCompare(right.filePath))
850
+ })
851
+ );
852
+ const playName = extractDefinedPlayName(sourceCode);
853
+ return {
854
+ sourceCode,
855
+ sourceFiles: Object.fromEntries(
856
+ [...localFiles.entries()].sort(
857
+ (left, right) => left[0].localeCompare(right[0])
858
+ )
859
+ ),
860
+ sourceHash,
861
+ graphHash,
862
+ importPolicy: {
863
+ localFiles: [...localFiles.keys()].sort(),
864
+ nodeBuiltins: [...nodeBuiltins].sort(),
865
+ packages: [...packages.entries()].map(([name, version]) => ({ name, version })).sort((left, right) => left.name.localeCompare(right.name))
866
+ },
867
+ playName,
868
+ importedPlayDependencies: [...importedPlayDependencies.values()].sort(
869
+ (left, right) => left.filePath.localeCompare(right.filePath)
870
+ )
871
+ };
872
+ }
873
+ async function computeWorkersHarnessFingerprintWithAdapter(adapter) {
874
+ const { readdir } = await import("fs/promises");
875
+ const addFilePart = async (parts2, rootDir, filePath) => {
876
+ const contents = await readFile(filePath, "utf-8");
877
+ parts2.push({
878
+ name: `${basename(rootDir)}:${filePath.slice(rootDir.length + 1)}`,
879
+ hash: sha256(contents)
880
+ });
881
+ };
882
+ const collectTopLevelTsFiles = async (rootDir, parts2) => {
883
+ if (!await fileExists(rootDir)) return;
884
+ const entries2 = await readdir(rootDir, { withFileTypes: true });
885
+ const tsFiles2 = entries2.filter((entry) => entry.isFile() && /\.[cm]?ts$/.test(entry.name)).map((entry) => entry.name).sort();
886
+ for (const name of tsFiles2) {
887
+ await addFilePart(parts2, rootDir, join(rootDir, name));
888
+ }
889
+ };
890
+ const collectIntegrationBatchingFiles = async (rootDir, parts2) => {
891
+ if (!await fileExists(rootDir)) return;
892
+ const entries2 = await readdir(rootDir, { withFileTypes: true });
893
+ const filePaths = [];
894
+ for (const entry of entries2) {
895
+ if (entry.isFile() && (entry.name === "play-runtime-batching-registry.ts" || /^batching.*\.ts$/.test(entry.name))) {
896
+ filePaths.push(join(rootDir, entry.name));
897
+ }
898
+ if (entry.isDirectory()) {
899
+ const batchingFile = join(rootDir, entry.name, "batching.ts");
900
+ if (await fileExists(batchingFile)) {
901
+ filePaths.push(batchingFile);
902
+ }
903
+ }
904
+ }
905
+ for (const filePath of filePaths.sort()) {
906
+ await addFilePart(parts2, rootDir, filePath);
907
+ }
908
+ };
909
+ const entries = await readdir(adapter.workersHarnessFilesDir, {
910
+ withFileTypes: true
911
+ });
912
+ const tsFiles = entries.filter((e) => e.isFile() && /\.[cm]?ts$/.test(e.name)).map((e) => e.name).sort();
913
+ const parts = [];
914
+ for (const name of tsFiles) {
915
+ await addFilePart(
916
+ parts,
917
+ adapter.workersHarnessFilesDir,
918
+ join(adapter.workersHarnessFilesDir, name)
919
+ );
920
+ }
921
+ for (const dir of adapter.workersRuntimeFingerprintDirs ?? []) {
922
+ if (basename(dir) === "integrations") {
923
+ await collectIntegrationBatchingFiles(dir, parts);
924
+ } else {
925
+ await collectTopLevelTsFiles(dir, parts);
926
+ }
927
+ }
928
+ return sha256(JSON.stringify(parts));
929
+ }
930
+ function artifactCachePath(graphHash, artifactKind, adapter) {
931
+ return join(
932
+ adapter.cacheDir ?? PLAY_ARTIFACT_CACHE_DIR,
933
+ `${graphHash}.${artifactKind}.json`
934
+ );
935
+ }
936
+ async function readArtifactCache(graphHash, artifactKind, adapter) {
937
+ try {
938
+ const serialized = await readFile(
939
+ artifactCachePath(graphHash, artifactKind, adapter),
940
+ "utf-8"
941
+ );
942
+ return JSON.parse(serialized);
943
+ } catch {
944
+ return null;
945
+ }
946
+ }
947
+ async function writeArtifactCache(artifact, adapter) {
948
+ const cacheDir = adapter.cacheDir ?? PLAY_ARTIFACT_CACHE_DIR;
949
+ await mkdir(cacheDir, { recursive: true });
950
+ await writeFile(
951
+ artifactCachePath(
952
+ artifact.graphHash,
953
+ artifact.artifactKind ?? PLAY_ARTIFACT_KINDS.cjsNode20,
954
+ adapter
955
+ ),
956
+ JSON.stringify(artifact),
957
+ "utf-8"
958
+ );
959
+ }
960
+ function normalizeSourceMapForRuntime(sourceMapText, projectRoot) {
961
+ const parsed = JSON.parse(sourceMapText);
962
+ parsed.sources = (parsed.sources ?? []).map((sourcePath) => {
963
+ if (sourcePath.startsWith("data:") || sourcePath.startsWith("node:") || sourcePath.startsWith("/") || /^[a-zA-Z]+:\/\//.test(sourcePath)) {
964
+ return sourcePath;
965
+ }
966
+ return join(projectRoot, sourcePath);
967
+ });
968
+ parsed.sourceRoot = void 0;
969
+ return JSON.stringify(parsed);
970
+ }
971
+ function getBundleSizeErrorForBytes(filePath, bundleBytes, artifactKind) {
972
+ if (bundleBytes > MAX_PLAY_BUNDLE_BYTES) {
973
+ return `${filePath} Play bundle exceeds the 30 MiB limit (${bundleBytes} bytes > ${MAX_PLAY_BUNDLE_BYTES} bytes).`;
974
+ }
975
+ if (artifactKind === PLAY_ARTIFACT_KINDS.esmWorkers && bundleBytes > MAX_ESM_WORKERS_BUNDLE_BYTES) {
976
+ const mib = (bundleBytes / 1024 / 1024).toFixed(2);
977
+ const limitMib = (MAX_ESM_WORKERS_BUNDLE_BYTES / 1024 / 1024).toFixed(2);
978
+ return `${filePath} Cloudflare Workers bundle is ${mib} MiB, above the workerd local-mode threshold of ${limitMib} MiB. Bundles past this size silently hang without executing the workflow body. Reduce dependencies (top offenders are usually date-fns, lodash, large schema libs) or split the play into smaller pieces with ctx.runPlay.`;
979
+ }
980
+ return null;
981
+ }
982
+ function getBundleSizeError(filePath, bundledCode, artifactKind) {
983
+ return getBundleSizeErrorForBytes(
984
+ filePath,
985
+ Buffer.byteLength(bundledCode, "utf8"),
986
+ artifactKind
987
+ );
988
+ }
989
+ async function runEsbuildForCjsNode(entryFile, importedPlayDependencies, adapter, exportName) {
990
+ const sdkAliasPlugin = localSdkAliasPlugin(adapter);
991
+ const playProxyPlugin = importedPlayProxyPlugin(importedPlayDependencies);
992
+ const namedExportShim = exportName === "default" ? null : `export { ${exportName} as default } from ${JSON.stringify(entryFile)};
993
+ `;
994
+ const result = await build({
995
+ ...namedExportShim ? {
996
+ stdin: {
997
+ contents: namedExportShim,
998
+ resolveDir: dirname(entryFile),
999
+ sourcefile: `${basename(entryFile)}.${exportName}.entry.ts`,
1000
+ loader: "ts"
1001
+ }
1002
+ } : { entryPoints: [entryFile] },
1003
+ absWorkingDir: adapter.projectRoot,
1004
+ bundle: true,
1005
+ format: "cjs",
1006
+ nodePaths: [adapter.nodeModulesDir],
1007
+ platform: "node",
1008
+ target: ["node20"],
1009
+ outfile: "play-artifact.cjs",
1010
+ write: false,
1011
+ sourcemap: "external",
1012
+ sourcesContent: false,
1013
+ logLevel: "silent",
1014
+ legalComments: "none",
1015
+ plugins: [sdkAliasPlugin, playProxyPlugin].filter(
1016
+ (plugin) => plugin != null
1017
+ )
1018
+ });
1019
+ const codeFile = result.outputFiles?.find((f) => f.path.endsWith(".cjs"));
1020
+ const mapFile = result.outputFiles?.find((f) => f.path.endsWith(".cjs.map"));
1021
+ if (!codeFile?.text || !mapFile?.text) {
1022
+ return ["Play bundling produced incomplete output."];
1023
+ }
1024
+ return {
1025
+ bundledCode: codeFile.text,
1026
+ sourceMapText: mapFile.text,
1027
+ outputExtension: "cjs"
1028
+ };
1029
+ }
1030
+ async function runEsbuildForEsmWorkers(playEntryFile, importedPlayDependencies, adapter, exportName) {
1031
+ const sdkAliasPlugin = localSdkAliasPlugin(adapter, { workersRuntime: true });
1032
+ const playProxyPlugin = importedPlayProxyPlugin(importedPlayDependencies);
1033
+ const playEntryAlias = exportName === "default" ? workersPlayEntryAliasPlugin(playEntryFile) : workersNamedPlayEntryAliasPlugin(playEntryFile, exportName);
1034
+ const result = await build({
1035
+ // Entry is the Workers harness; it imports the play via the virtual
1036
+ // `deepline-play-entry` alias resolved by workersPlayEntryAliasPlugin.
1037
+ entryPoints: [adapter.workersHarnessEntryFile],
1038
+ absWorkingDir: adapter.projectRoot,
1039
+ bundle: true,
1040
+ format: "esm",
1041
+ nodePaths: [adapter.nodeModulesDir],
1042
+ // Browser platform with workerd + worker conditions matches Cloudflare's
1043
+ // V8-isolate runtime. Avoids accidentally pulling node-only branches of
1044
+ // dual-publish packages.
1045
+ platform: "browser",
1046
+ conditions: ["workerd", "worker", "browser", "import", "default"],
1047
+ mainFields: ["module", "main"],
1048
+ target: ["es2022"],
1049
+ outfile: "play-worker.mjs",
1050
+ write: false,
1051
+ sourcemap: "external",
1052
+ sourcesContent: false,
1053
+ logLevel: "silent",
1054
+ legalComments: "none",
1055
+ // Aggressive minify + treeshake: a tiny play (<1KB source) was producing
1056
+ // an ~870KB bundle, dominated by zod's locale files (~260KB unused) and
1057
+ // dead-code branches across `shared_libs/play-runtime/*` and the SDK.
1058
+ // Both DCE on with these flags. workerd compiles each unique-graphHash
1059
+ // bundle on first dispatch, so bundle bytes translate ~linearly into
1060
+ // per-play cold latency on workers_edge. External sourcemap remains
1061
+ // unchanged (`sourcemap: 'external'`), so debugging is unaffected.
1062
+ minify: true,
1063
+ treeShaking: true,
1064
+ // Most node:* builtins are provided by Cloudflare's `nodejs_compat` flag.
1065
+ // The unsupported subset (fs, fs/promises, os, child_process) gets
1066
+ // replaced with throwing stubs by workersNodeBuiltinStubPlugin so deploy
1067
+ // validation passes; anything supported (path, crypto, buffer, etc.) is
1068
+ // marked external and resolved at runtime by the Workers runtime.
1069
+ external: ["node:*", "cloudflare:workers"],
1070
+ plugins: [
1071
+ // Banlist runs first so a forbidden import errors out before any other
1072
+ // resolver (esp. the workersNodeBuiltinStubPlugin which would silently
1073
+ // turn it into a throwing-stub).
1074
+ workersNodeImportBanlistPlugin(adapter),
1075
+ sdkAliasPlugin,
1076
+ playProxyPlugin,
1077
+ playEntryAlias,
1078
+ workersNodeBuiltinStubPlugin(),
1079
+ // Strip non-English zod locale data from the bundle. zod's locales
1080
+ // are re-exported as a static namespace from `zod/v4/core`, so
1081
+ // tree-shaking can't drop them; this plugin replaces each
1082
+ // non-English locale module with an empty default export at bundle
1083
+ // time. ~150–200 KB savings on every per-play bundle, with no
1084
+ // behavior change (we only surface English messages anyway).
1085
+ // If the bundle suddenly grows back, check whether a new dep added
1086
+ // its own zod copy or whether zod's locale layout changed.
1087
+ zodNonEnglishLocaleStubPlugin()
1088
+ ].filter((plugin) => plugin != null)
1089
+ });
1090
+ const codeFile = result.outputFiles?.find((f) => f.path.endsWith(".mjs"));
1091
+ const mapFile = result.outputFiles?.find((f) => f.path.endsWith(".mjs.map"));
1092
+ if (!codeFile?.text || !mapFile?.text) {
1093
+ return ["Workers play bundling produced incomplete output."];
1094
+ }
1095
+ return {
1096
+ bundledCode: codeFile.text,
1097
+ sourceMapText: mapFile.text,
1098
+ outputExtension: "mjs"
1099
+ };
1100
+ }
1101
+ var PLAY_ARTIFACT_TARGET_ADAPTERS = {
1102
+ [PLAY_ARTIFACT_KINDS.cjsNode20]: {
1103
+ artifactKind: PLAY_ARTIFACT_KINDS.cjsNode20,
1104
+ codeFormat: "cjs_module",
1105
+ includeWorkersHarnessInGraphHash: false,
1106
+ runEsbuild: ({
1107
+ entryFile,
1108
+ importedPlayDependencies,
1109
+ adapter,
1110
+ exportName
1111
+ }) => runEsbuildForCjsNode(
1112
+ entryFile,
1113
+ importedPlayDependencies,
1114
+ adapter,
1115
+ exportName
1116
+ )
1117
+ },
1118
+ [PLAY_ARTIFACT_KINDS.esmWorkers]: {
1119
+ artifactKind: PLAY_ARTIFACT_KINDS.esmWorkers,
1120
+ codeFormat: "esm_module",
1121
+ includeWorkersHarnessInGraphHash: true,
1122
+ runEsbuild: ({
1123
+ entryFile,
1124
+ importedPlayDependencies,
1125
+ adapter,
1126
+ exportName
1127
+ }) => runEsbuildForEsmWorkers(
1128
+ entryFile,
1129
+ importedPlayDependencies,
1130
+ adapter,
1131
+ exportName
1132
+ )
1133
+ }
1134
+ };
1135
+ function resolvePlayArtifactTargetAdapter(artifactKind) {
1136
+ return PLAY_ARTIFACT_TARGET_ADAPTERS[artifactKind];
1137
+ }
1138
+ async function bundlePlayFile(filePath, options) {
1139
+ const adapter = options.adapter;
1140
+ const target = options.target ?? PLAY_ARTIFACT_KINDS.cjsNode20;
1141
+ const targetAdapter = resolvePlayArtifactTargetAdapter(target);
1142
+ const exportName = options.exportName?.trim() || "default";
1143
+ assertValidExportName(exportName);
1144
+ const absolutePath = await normalizeLocalPath(filePath);
1145
+ adapter.warnAboutNonDevelopmentBundling?.(absolutePath);
1146
+ try {
1147
+ const analysis = await analyzeSourceGraph(absolutePath, adapter);
1148
+ analysis.graphHash = target === PLAY_ARTIFACT_KINDS.esmWorkers ? buildWorkersRuntimeGraphHash({
1149
+ analysis,
1150
+ entryFile: absolutePath,
1151
+ adapter,
1152
+ exportName
1153
+ }) : sha256(`${analysis.graphHash}
1154
+ entry-export:${exportName}`);
1155
+ if (targetAdapter.includeWorkersHarnessInGraphHash) {
1156
+ const harnessFingerprint = await computeWorkersHarnessFingerprintWithAdapter(adapter);
1157
+ analysis.graphHash = sha256(
1158
+ `${analysis.graphHash}
1159
+ workers-harness:${harnessFingerprint}`
1160
+ );
1161
+ }
1162
+ try {
1163
+ validatePlaySourceFilesHaveNoInlineSecrets(analysis.sourceFiles);
1164
+ } catch (error) {
1165
+ return {
1166
+ success: false,
1167
+ filePath: absolutePath,
1168
+ errors: [error instanceof Error ? error.message : String(error)]
1169
+ };
1170
+ }
1171
+ const typecheckErrors = [
1172
+ ...await adapter.typecheckPlaySource?.({
1173
+ sourceCode: analysis.sourceCode,
1174
+ sourcePath: absolutePath,
1175
+ importedFilePaths: [
1176
+ ...analysis.importPolicy.localFiles,
1177
+ ...analysis.importedPlayDependencies.map(
1178
+ (dependency) => dependency.filePath
1179
+ )
1180
+ ]
1181
+ }) ?? []
1182
+ ];
1183
+ if (typecheckErrors.length > 0) {
1184
+ return {
1185
+ success: false,
1186
+ filePath: absolutePath,
1187
+ errors: typecheckErrors
1188
+ };
1189
+ }
1190
+ const canUseArtifactCache = target !== PLAY_ARTIFACT_KINDS.esmWorkers;
1191
+ const cachedArtifact = canUseArtifactCache ? await readArtifactCache(analysis.graphHash, target, adapter) : null;
1192
+ const discoveredFiles = await adapter.discoverPackagedLocalFiles(absolutePath);
1193
+ if (cachedArtifact) {
1194
+ const cachedArtifactSizeError = getBundleSizeError(
1195
+ absolutePath,
1196
+ cachedArtifact.bundledCode,
1197
+ target
1198
+ );
1199
+ if (cachedArtifactSizeError) {
1200
+ return {
1201
+ success: false,
1202
+ filePath: absolutePath,
1203
+ errors: [cachedArtifactSizeError]
1204
+ };
1205
+ }
1206
+ return {
1207
+ success: true,
1208
+ artifact: {
1209
+ ...cachedArtifact,
1210
+ entryFile: absolutePath,
1211
+ sourceHash: analysis.sourceHash,
1212
+ importPolicy: analysis.importPolicy,
1213
+ cacheHit: true
1214
+ },
1215
+ sourceCode: analysis.sourceCode,
1216
+ sourceFiles: analysis.sourceFiles,
1217
+ filePath: absolutePath,
1218
+ playName: analysis.playName,
1219
+ packagedFiles: discoveredFiles.files,
1220
+ unresolvedFileReferences: discoveredFiles.unresolved,
1221
+ importedPlayDependencies: analysis.importedPlayDependencies
1222
+ };
1223
+ }
1224
+ const buildOutcome = await targetAdapter.runEsbuild({
1225
+ entryFile: absolutePath,
1226
+ importedPlayDependencies: analysis.importedPlayDependencies,
1227
+ adapter,
1228
+ exportName
1229
+ });
1230
+ if (Array.isArray(buildOutcome)) {
1231
+ return {
1232
+ success: false,
1233
+ filePath: absolutePath,
1234
+ errors: buildOutcome
1235
+ };
1236
+ }
1237
+ const { bundledCode, sourceMapText, outputExtension } = buildOutcome;
1238
+ const normalizedSourceMap = normalizeSourceMapForRuntime(
1239
+ sourceMapText,
1240
+ resolve(adapter.projectRoot)
1241
+ );
1242
+ const virtualBaseName = exportName === "default" ? basename(absolutePath).replace(/\.[^.]+$/, "") : `${basename(absolutePath).replace(/\.[^.]+$/, "")}.${exportName}`;
1243
+ const virtualFilename = `/virtual/deepline-plays/${analysis.graphHash}/${virtualBaseName}.${outputExtension}`;
1244
+ const executableCode = `${bundledCode}
1245
+ //# sourceMappingURL=${basename(virtualFilename)}.map
1246
+ `;
1247
+ const bundleSizeError = getBundleSizeError(
1248
+ absolutePath,
1249
+ executableCode,
1250
+ target
1251
+ );
1252
+ if (bundleSizeError) {
1253
+ return {
1254
+ success: false,
1255
+ filePath: absolutePath,
1256
+ errors: [bundleSizeError]
1257
+ };
1258
+ }
1259
+ const artifact = {
1260
+ codeFormat: targetAdapter.codeFormat,
1261
+ artifactKind: target,
1262
+ entryFile: absolutePath,
1263
+ virtualFilename,
1264
+ sourceHash: analysis.sourceHash,
1265
+ graphHash: analysis.graphHash,
1266
+ artifactHash: sha256(executableCode),
1267
+ sourceMapHash: sha256(normalizedSourceMap),
1268
+ bundledCode: executableCode,
1269
+ sourceMap: normalizedSourceMap,
1270
+ importPolicy: analysis.importPolicy,
1271
+ compatibility: buildPlayContractCompatibility(),
1272
+ generatedAt: Date.now(),
1273
+ cacheHit: false
1274
+ };
1275
+ if (canUseArtifactCache) {
1276
+ await writeArtifactCache(artifact, adapter);
1277
+ }
1278
+ return {
1279
+ success: true,
1280
+ artifact,
1281
+ sourceCode: analysis.sourceCode,
1282
+ sourceFiles: analysis.sourceFiles,
1283
+ filePath: absolutePath,
1284
+ playName: analysis.playName,
1285
+ packagedFiles: discoveredFiles.files,
1286
+ unresolvedFileReferences: discoveredFiles.unresolved,
1287
+ importedPlayDependencies: analysis.importedPlayDependencies
1288
+ };
1289
+ } catch (error) {
1290
+ if (error && typeof error === "object" && "errors" in error) {
1291
+ const errors = Array.isArray(error.errors) ? error.errors.map(formatEsbuildMessage) : ["Play bundling failed."];
1292
+ return {
1293
+ success: false,
1294
+ filePath: absolutePath,
1295
+ errors
1296
+ };
1297
+ }
1298
+ return {
1299
+ success: false,
1300
+ filePath: absolutePath,
1301
+ errors: [error instanceof Error ? error.message : String(error)]
1302
+ };
1303
+ }
1304
+ }
1305
+
1306
+ // ../shared_libs/play-runtime/dedup-backend.ts
1307
+ var PLAY_DEDUP_BACKENDS = {
1308
+ inMemory: "in_memory",
1309
+ neonTable: "neon_table",
1310
+ durableObject: "durable_object"
1311
+ };
1312
+
1313
+ // ../shared_libs/play-runtime/scheduler-backend.ts
1314
+ var PLAY_SCHEDULER_BACKENDS = {
1315
+ temporal: "temporal",
1316
+ cfWorkflows: "cf-workflows",
1317
+ /**
1318
+ * Private legacy id retained only so old persisted rows can be interpreted.
1319
+ * It is not a selectable scheduler backend after the Hatchet hard cutover.
1320
+ */
1321
+ postgres: "postgres",
1322
+ hatchet: "hatchet",
1323
+ inProcess: "in-process"
1324
+ };
1325
+
1326
+ // ../shared_libs/play-runtime/providers.ts
1327
+ var PLAY_RUNTIME_PROVIDER_IDS = {
1328
+ workersEdge: "workers_edge",
1329
+ hatchet: "hatchet",
1330
+ local: "local"
1331
+ };
1332
+ var PLAY_RUNTIME_PROVIDERS = {
1333
+ workers_edge: {
1334
+ id: PLAY_RUNTIME_PROVIDER_IDS.workersEdge,
1335
+ scheduler: PLAY_SCHEDULER_BACKENDS.cfWorkflows,
1336
+ runner: PLAY_RUNTIME_BACKENDS.cloudflareWorkers,
1337
+ dedup: PLAY_DEDUP_BACKENDS.durableObject,
1338
+ artifactKind: PLAY_ARTIFACT_KINDS.esmWorkers,
1339
+ label: "Cloudflare Dynamic Workflows + Dynamic Workers + DO dedup"
1340
+ },
1341
+ hatchet: {
1342
+ id: PLAY_RUNTIME_PROVIDER_IDS.hatchet,
1343
+ scheduler: PLAY_SCHEDULER_BACKENDS.hatchet,
1344
+ runner: PLAY_RUNTIME_BACKENDS.daytona,
1345
+ dedup: PLAY_DEDUP_BACKENDS.durableObject,
1346
+ artifactKind: PLAY_ARTIFACT_KINDS.cjsNode20,
1347
+ label: "Hatchet scheduler + one-shot Daytona runner + DO dedup"
1348
+ },
1349
+ local: {
1350
+ id: PLAY_RUNTIME_PROVIDER_IDS.local,
1351
+ scheduler: PLAY_SCHEDULER_BACKENDS.temporal,
1352
+ runner: PLAY_RUNTIME_BACKENDS.localProcess,
1353
+ dedup: PLAY_DEDUP_BACKENDS.inMemory,
1354
+ artifactKind: PLAY_ARTIFACT_KINDS.cjsNode20,
1355
+ label: "Local Temporal scheduler + local subprocess runner (tests)"
1356
+ }
1357
+ };
1358
+ function defaultPlayRuntimeProvider() {
1359
+ return PLAY_RUNTIME_PROVIDERS.workers_edge;
1360
+ }
1361
+ function resolvePlayRuntimeProvider(override) {
1362
+ if (override?.trim()) {
1363
+ const id = override.trim();
1364
+ if (id in PLAY_RUNTIME_PROVIDERS) {
1365
+ return PLAY_RUNTIME_PROVIDERS[id];
1366
+ }
1367
+ throw new Error(
1368
+ `Unknown play runtime provider "${id}". Expected one of: ${Object.keys(
1369
+ PLAY_RUNTIME_PROVIDERS
1370
+ ).join(", ")}.`
1371
+ );
1372
+ }
1373
+ return defaultPlayRuntimeProvider();
1374
+ }
1375
+
1376
+ // ../shared_libs/play-runtime/profiles.ts
1377
+ var PLAY_EXECUTION_PROFILE_IDS = {
1378
+ ...PLAY_RUNTIME_PROVIDER_IDS
1379
+ };
1380
+ var PLAY_EXECUTION_PROFILES = PLAY_RUNTIME_PROVIDERS;
1381
+ function resolveExecutionProfile(override) {
1382
+ try {
1383
+ return resolvePlayRuntimeProvider(override);
1384
+ } catch (error) {
1385
+ if (override?.trim()) {
1386
+ throw new Error(
1387
+ `Unknown execution profile "${override.trim()}". Expected one of: ${Object.keys(
1388
+ PLAY_EXECUTION_PROFILES
1389
+ ).join(", ")}.`
1390
+ );
1391
+ }
1392
+ throw error;
1393
+ }
1394
+ }
1395
+
1396
+ // src/plays/local-file-discovery.ts
1397
+ import { createHash as createHash2 } from "crypto";
1398
+ import { readFile as readFile2, stat as stat2 } from "fs/promises";
1399
+ import {
1400
+ basename as basename2,
1401
+ dirname as dirname2,
1402
+ extname as extname2,
1403
+ isAbsolute as isAbsolute2,
1404
+ join as join2,
1405
+ relative as relative2,
1406
+ resolve as resolve2
1407
+ } from "path";
1408
+ var SOURCE_EXTENSIONS2 = [
1409
+ ".ts",
1410
+ ".tsx",
1411
+ ".mts",
1412
+ ".cts",
1413
+ ".js",
1414
+ ".jsx",
1415
+ ".mjs",
1416
+ ".cjs",
1417
+ ".json"
1418
+ ];
1419
+ function sha2562(buffer) {
1420
+ return createHash2("sha256").update(buffer).digest("hex");
1421
+ }
1422
+ function contentTypeForFile(filePath) {
1423
+ const extension = extname2(filePath).toLowerCase();
1424
+ if (extension === ".csv") return "text/csv";
1425
+ if (extension === ".json") return "application/json";
1426
+ if (extension === ".txt") return "text/plain";
1427
+ return "application/octet-stream";
1428
+ }
1429
+ function stripCommentsToSpaces2(source) {
1430
+ return source.replace(/\/\*[\s\S]*?\*\//g, (match) => match.replace(/[^\n]/g, " ")).replace(
1431
+ /(^|[^:])\/\/.*$/gm,
1432
+ (match, prefix) => prefix + " ".repeat(Math.max(0, match.length - prefix.length))
1433
+ );
1434
+ }
1435
+ function unquoteStringLiteral2(literal) {
1436
+ const trimmed = literal.trim();
1437
+ const quote = trimmed[0];
1438
+ if (quote !== '"' && quote !== "'" || trimmed[trimmed.length - 1] !== quote) {
1439
+ return null;
1440
+ }
1441
+ try {
1442
+ return JSON.parse(
1443
+ quote === '"' ? trimmed : `"${trimmed.slice(1, -1).replace(/"/g, '\\"')}"`
1444
+ );
1445
+ } catch {
1446
+ return trimmed.slice(1, -1);
1447
+ }
1448
+ }
1449
+ function splitTopLevelPlus(expression) {
1450
+ const parts = [];
1451
+ let start = 0;
1452
+ let depth = 0;
1453
+ let quote = null;
1454
+ let escaped = false;
1455
+ for (let index = 0; index < expression.length; index += 1) {
1456
+ const char = expression[index];
1457
+ if (quote) {
1458
+ if (escaped) {
1459
+ escaped = false;
1460
+ } else if (char === "\\") {
1461
+ escaped = true;
1462
+ } else if (char === quote) {
1463
+ quote = null;
1464
+ }
1465
+ continue;
1466
+ }
1467
+ if (char === '"' || char === "'" || char === "`") {
1468
+ quote = char;
1469
+ continue;
1470
+ }
1471
+ if (char === "(" || char === "[" || char === "{") depth += 1;
1472
+ if (char === ")" || char === "]" || char === "}") depth -= 1;
1473
+ if (char === "+" && depth === 0) {
1474
+ parts.push(expression.slice(start, index));
1475
+ start = index + 1;
1476
+ }
1477
+ }
1478
+ if (parts.length === 0) return null;
1479
+ parts.push(expression.slice(start));
1480
+ return parts;
1481
+ }
1482
+ function stripOuterParens(expression) {
1483
+ let value = expression.trim();
1484
+ while (value.startsWith("(") && value.endsWith(")")) {
1485
+ value = value.slice(1, -1).trim();
1486
+ }
1487
+ return value;
1488
+ }
1489
+ function isRuntimeInputExpression(expression) {
1490
+ return /(^|[^\w$])input([^\w$]|$)/.test(expression);
1491
+ }
1492
+ function resolveStringExpression(expression, constants) {
1493
+ const value = stripOuterParens(expression);
1494
+ if (/^(['"])(?:\\.|(?!\1)[\s\S])*\1$/.test(value)) {
1495
+ return unquoteStringLiteral2(value);
1496
+ }
1497
+ if (/^`(?:\\.|[^`$]|\$(?!\{))*`$/.test(value)) {
1498
+ return value.slice(1, -1);
1499
+ }
1500
+ if (/^[A-Za-z_$][\w$]*$/.test(value)) {
1501
+ return constants.get(value) ?? null;
1502
+ }
1503
+ const parts = splitTopLevelPlus(value);
1504
+ if (parts) {
1505
+ const resolved = parts.map(
1506
+ (part) => resolveStringExpression(part, constants)
1507
+ );
1508
+ return resolved.every((part) => part != null) ? resolved.join("") : null;
1509
+ }
1510
+ return null;
1511
+ }
1512
+ function collectTopLevelStringConstants(sourceCode) {
1513
+ const constants = /* @__PURE__ */ new Map();
1514
+ const source = stripCommentsToSpaces2(sourceCode);
1515
+ for (const match of source.matchAll(
1516
+ /(?:^|\n)\s*const\s+([A-Za-z_$][\w$]*)\s*=\s*([^;\n]+)/g
1517
+ )) {
1518
+ const resolved = resolveStringExpression(match[2], constants);
1519
+ if (resolved != null) {
1520
+ constants.set(match[1], resolved);
1521
+ }
1522
+ }
1523
+ return constants;
1524
+ }
1525
+ function findMatchingGenericEnd(source, openIndex) {
1526
+ let depth = 0;
1527
+ let quote = null;
1528
+ let escaped = false;
1529
+ for (let index = openIndex; index < source.length; index += 1) {
1530
+ const char = source[index];
1531
+ if (quote) {
1532
+ if (escaped) {
1533
+ escaped = false;
1534
+ } else if (char === "\\") {
1535
+ escaped = true;
1536
+ } else if (char === quote) {
1537
+ quote = null;
1538
+ }
1539
+ continue;
1540
+ }
1541
+ if (char === '"' || char === "'" || char === "`") {
1542
+ quote = char;
1543
+ continue;
1544
+ }
1545
+ if (char === "<") depth += 1;
1546
+ if (char === ">") {
1547
+ depth -= 1;
1548
+ if (depth === 0) return index;
1549
+ }
1550
+ }
1551
+ return -1;
1552
+ }
1553
+ function findCallOpenParen(source, afterCsvIndex) {
1554
+ let index = afterCsvIndex;
1555
+ while (/\s/.test(source[index] ?? "")) index += 1;
1556
+ if (source[index] === "<") {
1557
+ const genericEnd = findMatchingGenericEnd(source, index);
1558
+ if (genericEnd < 0) return -1;
1559
+ index = genericEnd + 1;
1560
+ while (/\s/.test(source[index] ?? "")) index += 1;
1561
+ }
1562
+ return source[index] === "(" ? index : -1;
1563
+ }
1564
+ function firstCallArgument(source, openParen) {
1565
+ let depth = 0;
1566
+ let quote = null;
1567
+ let escaped = false;
1568
+ const start = openParen + 1;
1569
+ for (let index = start; index < source.length; index += 1) {
1570
+ const char = source[index];
1571
+ if (quote) {
1572
+ if (escaped) {
1573
+ escaped = false;
1574
+ } else if (char === "\\") {
1575
+ escaped = true;
1576
+ } else if (char === quote) {
1577
+ quote = null;
1578
+ }
1579
+ continue;
1580
+ }
1581
+ if (char === '"' || char === "'" || char === "`") {
1582
+ quote = char;
1583
+ continue;
1584
+ }
1585
+ if (char === "(" || char === "[" || char === "{") depth += 1;
1586
+ if (char === ")" && depth === 0) {
1587
+ const text = source.slice(start, index).trim();
1588
+ return text ? { text, start, end: index } : null;
1589
+ }
1590
+ if (char === "," && depth === 0) {
1591
+ const text = source.slice(start, index).trim();
1592
+ return text ? { text, start, end: index } : null;
1593
+ }
1594
+ if (char === ")" || char === "]" || char === "}") depth -= 1;
1595
+ }
1596
+ return null;
1597
+ }
1598
+ function localImportSpecifiers(sourceCode) {
1599
+ const source = stripCommentsToSpaces2(sourceCode);
1600
+ const specifiers = [];
1601
+ for (const match of source.matchAll(
1602
+ /\b(?:import|export)\s+(?!type\b)(?:[\s\S]*?\s+from\s*)?['"]([^'"]+)['"]/g
1603
+ )) {
1604
+ if (match[1]?.startsWith(".")) specifiers.push(match[1]);
1605
+ }
1606
+ for (const match of source.matchAll(
1607
+ /\brequire\s*\(\s*(['"])(\.[^'"]*)\1\s*\)/g
1608
+ )) {
1609
+ specifiers.push(match[2]);
1610
+ }
1611
+ return specifiers;
1612
+ }
1613
+ async function fileExists2(filePath) {
1614
+ try {
1615
+ await stat2(filePath);
1616
+ return true;
1617
+ } catch {
1618
+ return false;
1619
+ }
1620
+ }
1621
+ function isPathInsideDirectory2(filePath, directory) {
1622
+ const relativePath = relative2(directory, filePath);
1623
+ return relativePath === "" || !relativePath.startsWith("..") && !isAbsolute2(relativePath);
1624
+ }
1625
+ async function resolveLocalImport2(fromFile, specifier) {
1626
+ const base = isAbsolute2(specifier) ? resolve2(specifier) : resolve2(dirname2(fromFile), specifier);
1627
+ const candidates = [base];
1628
+ const explicitExtension = extname2(base).toLowerCase();
1629
+ if (!explicitExtension) {
1630
+ candidates.push(
1631
+ ...SOURCE_EXTENSIONS2.map((extension) => `${base}${extension}`)
1632
+ );
1633
+ candidates.push(
1634
+ ...SOURCE_EXTENSIONS2.map((extension) => join2(base, `index${extension}`))
1635
+ );
1636
+ } else if ([".js", ".jsx", ".mjs", ".cjs"].includes(explicitExtension)) {
1637
+ const stem = base.slice(0, -explicitExtension.length);
1638
+ candidates.push(
1639
+ ...SOURCE_EXTENSIONS2.map((extension) => `${stem}${extension}`)
1640
+ );
1641
+ }
1642
+ for (const candidate of candidates) {
1643
+ if (await fileExists2(candidate)) {
1644
+ return candidate;
1645
+ }
1646
+ }
1647
+ throw new Error(
1648
+ `Could not resolve local import "${specifier}" from ${fromFile}`
1649
+ );
1650
+ }
1651
+ async function discoverPackagedLocalFiles(entryFile) {
1652
+ const absoluteEntryFile = resolve2(entryFile);
1653
+ const packagingRoot = dirname2(absoluteEntryFile);
1654
+ const files = /* @__PURE__ */ new Map();
1655
+ const unresolved = [];
1656
+ const visitedFiles = /* @__PURE__ */ new Set();
1657
+ const visitSourceFile = async (filePath) => {
1658
+ const absolutePath = resolve2(filePath);
1659
+ if (visitedFiles.has(absolutePath)) {
1660
+ return;
1661
+ }
1662
+ visitedFiles.add(absolutePath);
1663
+ const sourceCode = await readFile2(absolutePath, "utf-8");
1664
+ const scanSource = stripCommentsToSpaces2(sourceCode);
1665
+ const constants = collectTopLevelStringConstants(sourceCode);
1666
+ const childVisits = [];
1667
+ for (const match of scanSource.matchAll(
1668
+ /\b([A-Za-z_$][\w$]*)\s*\.\s*csv\b/g
1669
+ )) {
1670
+ const target = match[1];
1671
+ if (target !== "ctx" && !target.endsWith("Ctx")) {
1672
+ continue;
1673
+ }
1674
+ const openParen = findCallOpenParen(
1675
+ scanSource,
1676
+ match.index + match[0].length
1677
+ );
1678
+ if (openParen < 0) {
1679
+ continue;
1680
+ }
1681
+ const argument = firstCallArgument(scanSource, openParen);
1682
+ if (!argument) {
1683
+ unresolved.push({
1684
+ sourceFragment: "ctx.csv()",
1685
+ message: "ctx.csv() requires a file path string or input reference."
1686
+ });
1687
+ } else if (!isRuntimeInputExpression(argument.text)) {
1688
+ const resolvedPath = resolveStringExpression(argument.text, constants);
1689
+ if (resolvedPath == null) {
1690
+ unresolved.push({
1691
+ sourceFragment: sourceCode.slice(argument.start, argument.end).trim(),
1692
+ message: "Could not resolve this ctx.csv(...) path at submit time. Use a string literal, a top-level const string, or pass a runtime input like input.file."
1693
+ });
1694
+ } else {
1695
+ const absoluteCsvPath = resolve2(dirname2(absolutePath), resolvedPath);
1696
+ if (isAbsolute2(resolvedPath) || !isPathInsideDirectory2(absoluteCsvPath, packagingRoot)) {
1697
+ unresolved.push({
1698
+ sourceFragment: sourceCode.slice(argument.start, argument.end).trim(),
1699
+ message: "ctx.csv(...) packaged file paths must be relative paths inside the play directory. Pass external files at runtime with input.file instead."
1700
+ });
1701
+ continue;
1702
+ }
1703
+ const buffer = await readFile2(absoluteCsvPath);
1704
+ const stats = await stat2(absoluteCsvPath);
1705
+ files.set(absoluteCsvPath, {
1706
+ sourceFragment: sourceCode.slice(argument.start, argument.end).trim(),
1707
+ logicalPath: resolvedPath,
1708
+ absolutePath: absoluteCsvPath,
1709
+ bytes: stats.size,
1710
+ contentHash: sha2562(buffer),
1711
+ contentType: contentTypeForFile(absoluteCsvPath)
1712
+ });
1713
+ }
1714
+ }
1715
+ }
1716
+ for (const specifier of localImportSpecifiers(sourceCode)) {
1717
+ childVisits.push(
1718
+ resolveLocalImport2(absolutePath, specifier).then(
1719
+ (resolvedImport) => visitSourceFile(resolvedImport)
1720
+ )
1721
+ );
1722
+ }
1723
+ await Promise.all(childVisits);
1724
+ };
1725
+ await visitSourceFile(absoluteEntryFile);
1726
+ return {
1727
+ files: [...files.values()],
1728
+ unresolved
1729
+ };
1730
+ }
1731
+
1732
+ // src/plays/bundle-play-file.ts
1733
+ var PLAY_BUNDLE_CACHE_VERSION2 = 30;
1734
+ var MODULE_DIR = dirname3(fileURLToPath(import.meta.url));
1735
+ var SDK_PACKAGE_ROOT = resolve3(MODULE_DIR, "..", "..");
1736
+ var SOURCE_REPO_ROOT = resolve3(SDK_PACKAGE_ROOT, "..");
1737
+ var HAS_SOURCE_BUNDLING_SOURCES = existsSync2(
1738
+ resolve3(SOURCE_REPO_ROOT, "apps", "play-runner-workers", "src", "entry.ts")
1739
+ );
1740
+ var PACKAGED_BUNDLING_SOURCE_ROOT = resolve3(
1741
+ SDK_PACKAGE_ROOT,
1742
+ "dist",
1743
+ "bundling-sources"
1744
+ );
1745
+ var HAS_PACKAGED_BUNDLING_SOURCES = existsSync2(
1746
+ resolve3(
1747
+ PACKAGED_BUNDLING_SOURCE_ROOT,
1748
+ "apps",
1749
+ "play-runner-workers",
1750
+ "src",
1751
+ "entry.ts"
1752
+ )
1753
+ );
1754
+ var PROJECT_ROOT = HAS_SOURCE_BUNDLING_SOURCES ? SOURCE_REPO_ROOT : HAS_PACKAGED_BUNDLING_SOURCES ? PACKAGED_BUNDLING_SOURCE_ROOT : resolve3(SDK_PACKAGE_ROOT, "..");
1755
+ var SDK_SOURCE_ROOT = HAS_SOURCE_BUNDLING_SOURCES ? resolve3(SOURCE_REPO_ROOT, "sdk", "src") : HAS_PACKAGED_BUNDLING_SOURCES ? resolve3(PACKAGED_BUNDLING_SOURCE_ROOT, "sdk", "src") : resolve3(SDK_PACKAGE_ROOT, "src");
1756
+ var SDK_PACKAGE_JSON = resolve3(SDK_PACKAGE_ROOT, "package.json");
1757
+ var SDK_ENTRY_FILE = resolve3(SDK_SOURCE_ROOT, "index.ts");
1758
+ var SDK_TYPES_ENTRY_FILE = HAS_SOURCE_BUNDLING_SOURCES ? SDK_ENTRY_FILE : resolve3(SDK_PACKAGE_ROOT, "dist", "index.d.ts");
1759
+ var SDK_WORKERS_ENTRY_FILE = resolve3(SDK_SOURCE_ROOT, "worker-play-entry.ts");
1760
+ var WORKERS_HARNESS_ENTRY_FILE = resolve3(
1761
+ PROJECT_ROOT,
1762
+ "apps",
1763
+ "play-runner-workers",
1764
+ "src",
1765
+ "entry.ts"
1766
+ );
1767
+ var WORKERS_HARNESS_FILES_DIR = resolve3(
1768
+ PROJECT_ROOT,
1769
+ "apps",
1770
+ "play-runner-workers",
1771
+ "src"
1772
+ );
1773
+ var hasWarnedAboutNonDevelopmentBundling = false;
1774
+ function warnAboutNonDevelopmentBundling(filePath) {
1775
+ if (hasWarnedAboutNonDevelopmentBundling) {
1776
+ return;
1777
+ }
1778
+ const nodeEnv = String(process.env.NODE_ENV ?? "").trim().toLowerCase();
1779
+ if (!nodeEnv || nodeEnv === "development" || nodeEnv === "test") {
1780
+ return;
1781
+ }
1782
+ hasWarnedAboutNonDevelopmentBundling = true;
1783
+ console.warn(
1784
+ `[deepline] Warning: live play bundling was invoked while NODE_ENV=${nodeEnv} for ${filePath}. This source-first SDK path is intended for local development. For preview/production, run a published or prebuilt play reference instead of bundling source at runtime.`
1785
+ );
1786
+ console.warn(
1787
+ '[deepline] Preferred production call pattern: client.play("person-to-email").run(...) or run a previously registered/published org play.'
1788
+ );
1789
+ }
1790
+ function defaultPlayBundleTarget() {
1791
+ return resolveExecutionProfile(null).artifactKind;
1792
+ }
1793
+ function createSdkPlayBundlingAdapter() {
1794
+ return {
1795
+ projectRoot: PROJECT_ROOT,
1796
+ nodeModulesDir: HAS_PACKAGED_BUNDLING_SOURCES ? resolve3(SDK_PACKAGE_ROOT, "node_modules") : resolve3(PROJECT_ROOT, "node_modules"),
1797
+ cacheDir: join3(
1798
+ tmpdir2(),
1799
+ `deepline-play-artifacts-v${PLAY_BUNDLE_CACHE_VERSION2}`
1800
+ ),
1801
+ sdkSourceRoot: SDK_SOURCE_ROOT,
1802
+ sdkPackageJson: SDK_PACKAGE_JSON,
1803
+ sdkEntryFile: SDK_ENTRY_FILE,
1804
+ sdkTypesEntryFile: HAS_SOURCE_BUNDLING_SOURCES || !existsSync2(SDK_TYPES_ENTRY_FILE) ? SDK_ENTRY_FILE : SDK_TYPES_ENTRY_FILE,
1805
+ sdkWorkersEntryFile: SDK_WORKERS_ENTRY_FILE,
1806
+ workersHarnessEntryFile: WORKERS_HARNESS_ENTRY_FILE,
1807
+ workersHarnessFilesDir: WORKERS_HARNESS_FILES_DIR,
1808
+ workersRuntimeFingerprintDirs: [
1809
+ resolve3(PROJECT_ROOT, "shared_libs", "play-runtime")
1810
+ ],
1811
+ discoverPackagedLocalFiles,
1812
+ warnAboutNonDevelopmentBundling
1813
+ };
1814
+ }
1815
+ async function bundlePlayFile2(filePath, options = {}) {
1816
+ const result = await bundlePlayFile(filePath, {
1817
+ target: options.target ?? defaultPlayBundleTarget(),
1818
+ exportName: options.exportName,
1819
+ adapter: createSdkPlayBundlingAdapter()
1820
+ });
1821
+ if (result.success)
1822
+ validatePlaySourceFilesHaveNoInlineSecrets(result.sourceFiles);
1823
+ return result;
1824
+ }
1825
+ export {
1826
+ PLAY_ARTIFACT_KINDS,
1827
+ bundlePlayFile2 as bundlePlayFile,
1828
+ createSdkPlayBundlingAdapter,
1829
+ extractDefinedPlayName
1830
+ };