@poe-platform/safe-bash 0.1.661 → 0.1.663

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 (29) hide show
  1. package/dist/safe-bash/chunks/{chunk-Y7MAMRAF.js → chunk-AJ355TRJ.js} +4 -4
  2. package/dist/safe-bash/chunks/{chunk-Y7MAMRAF.js.map → chunk-AJ355TRJ.js.map} +2 -2
  3. package/dist/safe-bash/chunks/{chunk-Z4UKD5FF.js → chunk-PUNPTDFQ.js} +208 -126
  4. package/dist/safe-bash/chunks/chunk-PUNPTDFQ.js.map +7 -0
  5. package/dist/safe-bash/commands/playwright/index.d.ts +4 -2
  6. package/dist/safe-bash/commands/playwright/index.d.ts.map +1 -1
  7. package/dist/safe-bash/commands/playwright/index.js +1 -1
  8. package/dist/safe-bash/commands/playwright/index.js.map +1 -1
  9. package/dist/safe-bash/commands/python/diagnostics.d.ts +2 -1
  10. package/dist/safe-bash/commands/python/diagnostics.d.ts.map +1 -1
  11. package/dist/safe-bash/commands/python/diagnostics.js +6 -4
  12. package/dist/safe-bash/commands/python/diagnostics.js.map +1 -1
  13. package/dist/safe-bash/commands/python/index.browser.js +2 -2
  14. package/dist/safe-bash/commands/python/index.d.ts +14 -1
  15. package/dist/safe-bash/commands/python/index.d.ts.map +1 -1
  16. package/dist/safe-bash/commands/python/index.js +213 -123
  17. package/dist/safe-bash/commands/python/index.js.map +1 -1
  18. package/dist/safe-bash/commands/python/worker.browser.js +1 -1
  19. package/dist/safe-bash/core.browser.js +2 -2
  20. package/dist/safe-bash/playwright/controller.d.ts +20 -1
  21. package/dist/safe-bash/playwright/controller.d.ts.map +1 -1
  22. package/dist/safe-bash/playwright/controller.js +135 -24
  23. package/dist/safe-bash/playwright/controller.js.map +1 -1
  24. package/dist/safe-bash/playwright/invocation.d.ts +1 -0
  25. package/dist/safe-bash/playwright/invocation.d.ts.map +1 -1
  26. package/dist/safe-bash/playwright/invocation.js +5 -2
  27. package/dist/safe-bash/playwright/invocation.js.map +1 -1
  28. package/package.json +2 -2
  29. package/dist/safe-bash/chunks/chunk-Z4UKD5FF.js.map +0 -7
@@ -73,7 +73,7 @@ function parsePythonInvocation(args, env) {
73
73
  // packages/safe-bash/src/commands/python/diagnostics.ts
74
74
  init_platform();
75
75
  var messages = {
76
- "executor-unavailable": "Python executor is unavailable; configure a supported interpreter worker.",
76
+ "executor-unavailable": "Python executor is unavailable; configure exactly one supported executor or interpreter worker.",
77
77
  "transport-unavailable": "Python worker transport or shared-memory operations are unavailable.",
78
78
  "runtime-abi": "Python runtime version or native ABI is unsupported.",
79
79
  "runtime-assets": "Python runtime or package assets could not be loaded.",
@@ -109,8 +109,8 @@ function reportPythonFailure(category, cause, observer) {
109
109
  }
110
110
  function inspectPythonCapabilities(options = {}) {
111
111
  const failures = /* @__PURE__ */ new Set();
112
- if (typeof options.createWorker !== "function") failures.add("executor-unavailable");
113
- if (typeof SharedArrayBuffer !== "function" || typeof Atomics !== "object" || typeof Atomics.store !== "function" || typeof Atomics.notify !== "function") failures.add("transport-unavailable");
112
+ if (typeof options.createWorker === "function" === (typeof options.createExecutor === "function") || options.createWorker !== void 0 && typeof options.createWorker !== "function" || options.createExecutor !== void 0 && typeof options.createExecutor !== "function") failures.add("executor-unavailable");
113
+ if (typeof options.createExecutor !== "function" && (typeof SharedArrayBuffer !== "function" || typeof Atomics !== "object" || typeof Atomics.store !== "function" || typeof Atomics.notify !== "function")) failures.add("transport-unavailable");
114
114
  if (options.runtimeVersion !== void 0 && options.runtimeVersion !== "314.0.6") failures.add("runtime-abi");
115
115
  for (const requirement of options.requiredFileSystem ?? []) {
116
116
  if (!["open", "read", "write", "directory"].includes(requirement)) throw new TypeError("Unknown Python filesystem requirement");
@@ -140,4 +140,4 @@ export {
140
140
  reportPythonFailure,
141
141
  inspectPythonCapabilities
142
142
  };
143
- //# sourceMappingURL=chunk-Y7MAMRAF.js.map
143
+ //# sourceMappingURL=chunk-AJ355TRJ.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../src/commands/python/invocation.ts", "../../src/commands/python/diagnostics.ts"],
4
- "sourcesContent": ["/** An explicit compatibility failure, rendered as Python usage status 2. */\nexport class PythonInvocationError extends Error {\n constructor(message: string) { super(message); this.name = 'PythonInvocationError'; }\n}\n\n/** Extract native initialization flags without consuming script/module arguments. */\nexport function parsePythonInvocation(args: readonly string[], env: Readonly<Record<string, string>>): {\n readonly startupArgs: string[];\n readonly env: Record<string, string>;\n} {\n const startupArgs: string[] = [];\n let informational = false;\n scan: for (let index = 0; index < args.length; index++) {\n const option = args[index]!;\n if (option === '--' || option === '-' || !option.startsWith('-')) break;\n if (option === '--help') { informational = true; break; }\n if (option === '--version') { informational = true; continue; }\n if (option.startsWith('--')) throw new PythonInvocationError('unsupported option ' + option);\n for (let offset = 1; offset < option.length; offset++) {\n const flag = option[offset]!;\n if (flag === 'h' || flag === '?') { informational = true; break scan; }\n if (flag === 'V') { informational = true; continue; }\n if ('cmWX'.includes(flag)) {\n const operand = option.slice(offset + 1) || args[++index];\n if (operand === undefined) throw new PythonInvocationError('argument expected for -' + flag);\n if (flag === 'c' || flag === 'm') break scan;\n if (flag === 'X') {\n const separator = operand.indexOf('=');\n const name = separator < 0 ? operand : operand.slice(0, separator);\n const value = separator < 0 ? undefined : operand.slice(separator + 1);\n let decimal = value ?? '';\n while (decimal.length && ' \\t\\n\\r\\v\\f'.includes(decimal[0]!)) decimal = decimal.slice(1);\n if (decimal[0] === '+' || decimal[0] === '-') decimal = decimal.slice(1);\n const digits = decimal.length > 0 && [...decimal].every(character => character >= '0' && character <= '9');\n const supported = (name === 'utf8' && (value === undefined || value === '0' || value === '1'))\n || ((name === 'dev' || name === 'warn_default_encoding') && value === undefined)\n || (name === 'int_max_str_digits' && digits && Number.isSafeInteger(Number(value)) && Number(value) <= 2147483647 && (Number(value) === 0 || Number(value) >= 640));\n if (!supported) throw new PythonInvocationError('unsupported -X option ' + operand);\n startupArgs.push('-X', operand);\n }\n // Warning-as-error can prevent Pyodide bootstrap; apply -W after bootstrap.\n break;\n }\n if (!'BEPOusISbdvqR'.includes(flag)) throw new PythonInvocationError('unsupported option -' + flag);\n startupArgs.push('-' + flag);\n }\n }\n if (!informational && !startupArgs.includes('-E') && !startupArgs.includes('-I')) {\n if (env.PYTHONINSPECT) throw new PythonInvocationError('PYTHONINSPECT requires an interactive terminal, which the shell does not expose');\n if (env.PYTHONHOME) throw new PythonInvocationError('PYTHONHOME cannot replace the configured Pyodide runtime');\n }\n const runtimeEnv = { ...env };\n // These paths belong to the canonical filesystem, mounted after bootstrap.\n delete runtimeEnv.PYTHONPATH;\n delete runtimeEnv.PYTHONHOME;\n delete runtimeEnv.PYTHONWARNINGS;\n // Pyodide otherwise supplies PYTHONINSPECT=1, including with a -c operand.\n runtimeEnv.PYTHONINSPECT = '';\n // Without a command Pyodide initializes CPython in inspect mode.\n startupArgs.push('-c', '');\n return { startupArgs, env: runtimeEnv };\n}\n", "import type { FileSystem } from '../../contracts/filesystem.js';\n\nconst messages = {\n 'executor-unavailable': 'Python executor is unavailable; configure a supported interpreter worker.',\n 'transport-unavailable': 'Python worker transport or shared-memory operations are unavailable.',\n 'runtime-abi': 'Python runtime version or native ABI is unsupported.',\n 'runtime-assets': 'Python runtime or package assets could not be loaded.',\n 'filesystem-open': 'Python filesystem handle access is unavailable; the backend must support retained open.',\n 'filesystem-read': 'Python filesystem reads are unavailable for this backend.',\n 'filesystem-write': 'Python filesystem writes are unavailable for this backend.',\n 'filesystem-directory': 'Python retained directory operations are unavailable for this backend.',\n 'filesystem-operation': 'The requested Python filesystem operation is unavailable for this backend.',\n capacity: 'Python worker capacity exhausted.',\n cleanup: 'Python resource cleanup failed; retirement could not be confirmed.',\n startup: 'Python startup failed; consult the host diagnostic callback.',\n runtime: 'Python runtime failed; consult the host diagnostic callback.',\n} as const;\n\nexport type PythonFailureCategory = keyof typeof messages;\n\nexport class PythonFailure extends Error {\n constructor(readonly category: PythonFailureCategory, options?: ErrorOptions) {\n super(messages[category], options);\n this.name = 'PythonFailure';\n }\n}\n\nexport interface PythonDiagnostic {\n readonly failure: PythonFailure;\n readonly cause: unknown;\n}\n\nexport type PythonDiagnosticObserver = (diagnostic: PythonDiagnostic) => void | Promise<void>;\nexport type PythonFileSystemRequirement = 'open' | 'read' | 'write' | 'directory';\n\nexport function isPythonFailureCategory(value: unknown): value is PythonFailureCategory {\n return typeof value === 'string' && Object.hasOwn(messages, value);\n}\n\nexport function reportPythonFailure(category: PythonFailureCategory, cause: unknown, observer?: PythonDiagnosticObserver): PythonFailure {\n const failure = new PythonFailure(category);\n try { void Promise.resolve(observer?.({ failure, cause })).catch(() => {}); } catch {}\n return failure;\n}\n\nexport interface PythonCapabilityOptions {\n readonly createWorker?: () => unknown;\n readonly fs?: FileSystem;\n readonly requiredFileSystem?: readonly PythonFileSystemRequirement[];\n readonly runtimeVersion?: string;\n}\n\nexport interface PythonCapabilityReport {\n readonly configurationValid: boolean;\n readonly failures: readonly PythonFailure[];\n}\n\nexport function inspectPythonCapabilities(options: PythonCapabilityOptions = {}): PythonCapabilityReport {\n const failures = new Set<PythonFailureCategory>();\n if (typeof options.createWorker !== 'function') failures.add('executor-unavailable');\n if (typeof SharedArrayBuffer !== 'function' || typeof Atomics !== 'object'\n || typeof Atomics.store !== 'function' || typeof Atomics.notify !== 'function') failures.add('transport-unavailable');\n if (options.runtimeVersion !== undefined && options.runtimeVersion !== '314.0.6') failures.add('runtime-abi');\n for (const requirement of options.requiredFileSystem ?? []) {\n if (!['open', 'read', 'write', 'directory'].includes(requirement)) throw new TypeError('Unknown Python filesystem requirement');\n const category: PythonFailureCategory = requirement === 'open' ? 'filesystem-open'\n : requirement === 'read' ? 'filesystem-read' : requirement === 'write' ? 'filesystem-write' : 'filesystem-directory';\n try {\n const fs = options.fs;\n if (requirement === 'directory') {\n failures.add(category);\n } else if (!fs || typeof fs.open !== 'function' || fs.capabilities.open === false) failures.add('filesystem-open');\n else if (requirement === 'write' && (fs.capabilities.readOnly === true || fs.capabilities.write === false)) failures.add(category);\n else if (requirement === 'read' && fs.capabilities.read === false) failures.add(category);\n } catch { failures.add(category); }\n }\n return Object.freeze({ configurationValid: failures.size === 0,\n failures: Object.freeze([...failures].map(category => new PythonFailure(category))) });\n}\n"],
5
- "mappings": ";;;;;AAAA;AACO,IAAM,wBAAN,cAAoC,MAAM;AAAA,EAC/C,YAAY,SAAiB;AAAE,UAAM,OAAO;AAAG,SAAK,OAAO;AAAA,EAAyB;AACtF;AAGO,SAAS,sBAAsB,MAAyB,KAG7D;AACA,QAAM,cAAwB,CAAC;AAC/B,MAAI,gBAAgB;AACpB,OAAM,UAAS,QAAQ,GAAG,QAAQ,KAAK,QAAQ,SAAS;AACtD,UAAM,SAAS,KAAK,KAAK;AACzB,QAAI,WAAW,QAAQ,WAAW,OAAO,CAAC,OAAO,WAAW,GAAG,EAAG;AAClE,QAAI,WAAW,UAAU;AAAE,sBAAgB;AAAM;AAAA,IAAO;AACxD,QAAI,WAAW,aAAa;AAAE,sBAAgB;AAAM;AAAA,IAAU;AAC9D,QAAI,OAAO,WAAW,IAAI,EAAG,OAAM,IAAI,sBAAsB,wBAAwB,MAAM;AAC3F,aAAS,SAAS,GAAG,SAAS,OAAO,QAAQ,UAAU;AACrD,YAAM,OAAO,OAAO,MAAM;AAC1B,UAAI,SAAS,OAAO,SAAS,KAAK;AAAE,wBAAgB;AAAM,cAAM;AAAA,MAAM;AACtE,UAAI,SAAS,KAAK;AAAE,wBAAgB;AAAM;AAAA,MAAU;AACpD,UAAI,OAAO,SAAS,IAAI,GAAG;AACzB,cAAM,UAAU,OAAO,MAAM,SAAS,CAAC,KAAK,KAAK,EAAE,KAAK;AACxD,YAAI,YAAY,OAAW,OAAM,IAAI,sBAAsB,4BAA4B,IAAI;AAC3F,YAAI,SAAS,OAAO,SAAS,IAAK,OAAM;AACxC,YAAI,SAAS,KAAK;AAChB,gBAAM,YAAY,QAAQ,QAAQ,GAAG;AAC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AQ,QAAQ,SAAS,WAAW,EAAE,SAAS,WAAW,EAAG,OAAM,IAAI,UAAU,uCAAuC;AAC9H,UAAM,WAAkC,gBAAgB,SAAS,oBAC7D,gBAAgB,SAAS,oBAAoB,gBAAgB,UAAU,qBAAqB;AAChG,QAAI;AACF,YAAM,KAAK,QAAQ;AACnB,UAAI,gBAAgB,aAAa;AAC/B,iBAAS,IAAI,QAAQ;AAAA,MACvB,WAAW,CAAC,MAAM,OAAO,GAAG,SAAS,cAAc,GAAG,aAAa,SAAS,MAAO,UAAS,IAAI,iBAAiB;AAAA,eACxG,gBAAgB,YAAY,GAAG,aAAa,aAAa,QAAQ,GAAG,aAAa,UAAU,OAAQ,UAAS,IAAI,QAAQ;AAAA,eACxH,gBAAgB,UAAU,GAAG,aAAa,SAAS,MAAO,UAAS,IAAI,QAAQ;AAAA,IAC1F,QAAQ;AAAE,eAAS,IAAI,QAAQ;AAAA,IAAG;AAAA,EACpC;AACA,SAAO,OAAO,OAAO;AAAA,IAAE,oBAAoB,SAAS,SAAS;AAAA,IAC3D,UAAU,OAAO,OAAO,CAAC,GAAG,QAAQ,EAAE,IAAI,cAAY,IAAI,cAAc,QAAQ,CAAC,CAAC;AAAA,EAAE,CAAC;AACzF;",
4
+ "sourcesContent": ["/** An explicit compatibility failure, rendered as Python usage status 2. */\nexport class PythonInvocationError extends Error {\n constructor(message: string) { super(message); this.name = 'PythonInvocationError'; }\n}\n\n/** Extract native initialization flags without consuming script/module arguments. */\nexport function parsePythonInvocation(args: readonly string[], env: Readonly<Record<string, string>>): {\n readonly startupArgs: string[];\n readonly env: Record<string, string>;\n} {\n const startupArgs: string[] = [];\n let informational = false;\n scan: for (let index = 0; index < args.length; index++) {\n const option = args[index]!;\n if (option === '--' || option === '-' || !option.startsWith('-')) break;\n if (option === '--help') { informational = true; break; }\n if (option === '--version') { informational = true; continue; }\n if (option.startsWith('--')) throw new PythonInvocationError('unsupported option ' + option);\n for (let offset = 1; offset < option.length; offset++) {\n const flag = option[offset]!;\n if (flag === 'h' || flag === '?') { informational = true; break scan; }\n if (flag === 'V') { informational = true; continue; }\n if ('cmWX'.includes(flag)) {\n const operand = option.slice(offset + 1) || args[++index];\n if (operand === undefined) throw new PythonInvocationError('argument expected for -' + flag);\n if (flag === 'c' || flag === 'm') break scan;\n if (flag === 'X') {\n const separator = operand.indexOf('=');\n const name = separator < 0 ? operand : operand.slice(0, separator);\n const value = separator < 0 ? undefined : operand.slice(separator + 1);\n let decimal = value ?? '';\n while (decimal.length && ' \\t\\n\\r\\v\\f'.includes(decimal[0]!)) decimal = decimal.slice(1);\n if (decimal[0] === '+' || decimal[0] === '-') decimal = decimal.slice(1);\n const digits = decimal.length > 0 && [...decimal].every(character => character >= '0' && character <= '9');\n const supported = (name === 'utf8' && (value === undefined || value === '0' || value === '1'))\n || ((name === 'dev' || name === 'warn_default_encoding') && value === undefined)\n || (name === 'int_max_str_digits' && digits && Number.isSafeInteger(Number(value)) && Number(value) <= 2147483647 && (Number(value) === 0 || Number(value) >= 640));\n if (!supported) throw new PythonInvocationError('unsupported -X option ' + operand);\n startupArgs.push('-X', operand);\n }\n // Warning-as-error can prevent Pyodide bootstrap; apply -W after bootstrap.\n break;\n }\n if (!'BEPOusISbdvqR'.includes(flag)) throw new PythonInvocationError('unsupported option -' + flag);\n startupArgs.push('-' + flag);\n }\n }\n if (!informational && !startupArgs.includes('-E') && !startupArgs.includes('-I')) {\n if (env.PYTHONINSPECT) throw new PythonInvocationError('PYTHONINSPECT requires an interactive terminal, which the shell does not expose');\n if (env.PYTHONHOME) throw new PythonInvocationError('PYTHONHOME cannot replace the configured Pyodide runtime');\n }\n const runtimeEnv = { ...env };\n // These paths belong to the canonical filesystem, mounted after bootstrap.\n delete runtimeEnv.PYTHONPATH;\n delete runtimeEnv.PYTHONHOME;\n delete runtimeEnv.PYTHONWARNINGS;\n // Pyodide otherwise supplies PYTHONINSPECT=1, including with a -c operand.\n runtimeEnv.PYTHONINSPECT = '';\n // Without a command Pyodide initializes CPython in inspect mode.\n startupArgs.push('-c', '');\n return { startupArgs, env: runtimeEnv };\n}\n", "import type { FileSystem } from '../../contracts/filesystem.js';\n\nconst messages = {\n 'executor-unavailable': 'Python executor is unavailable; configure exactly one supported executor or interpreter worker.',\n 'transport-unavailable': 'Python worker transport or shared-memory operations are unavailable.',\n 'runtime-abi': 'Python runtime version or native ABI is unsupported.',\n 'runtime-assets': 'Python runtime or package assets could not be loaded.',\n 'filesystem-open': 'Python filesystem handle access is unavailable; the backend must support retained open.',\n 'filesystem-read': 'Python filesystem reads are unavailable for this backend.',\n 'filesystem-write': 'Python filesystem writes are unavailable for this backend.',\n 'filesystem-directory': 'Python retained directory operations are unavailable for this backend.',\n 'filesystem-operation': 'The requested Python filesystem operation is unavailable for this backend.',\n capacity: 'Python worker capacity exhausted.',\n cleanup: 'Python resource cleanup failed; retirement could not be confirmed.',\n startup: 'Python startup failed; consult the host diagnostic callback.',\n runtime: 'Python runtime failed; consult the host diagnostic callback.',\n} as const;\n\nexport type PythonFailureCategory = keyof typeof messages;\n\nexport class PythonFailure extends Error {\n constructor(readonly category: PythonFailureCategory, options?: ErrorOptions) {\n super(messages[category], options);\n this.name = 'PythonFailure';\n }\n}\n\nexport interface PythonDiagnostic {\n readonly failure: PythonFailure;\n readonly cause: unknown;\n}\n\nexport type PythonDiagnosticObserver = (diagnostic: PythonDiagnostic) => void | Promise<void>;\nexport type PythonFileSystemRequirement = 'open' | 'read' | 'write' | 'directory';\n\nexport function isPythonFailureCategory(value: unknown): value is PythonFailureCategory {\n return typeof value === 'string' && Object.hasOwn(messages, value);\n}\n\nexport function reportPythonFailure(category: PythonFailureCategory, cause: unknown, observer?: PythonDiagnosticObserver): PythonFailure {\n const failure = new PythonFailure(category);\n try { void Promise.resolve(observer?.({ failure, cause })).catch(() => {}); } catch {}\n return failure;\n}\n\nexport interface PythonCapabilityOptions {\n readonly createWorker?: () => unknown;\n readonly createExecutor?: () => unknown;\n readonly fs?: FileSystem;\n readonly requiredFileSystem?: readonly PythonFileSystemRequirement[];\n readonly runtimeVersion?: string;\n}\n\nexport interface PythonCapabilityReport {\n readonly configurationValid: boolean;\n readonly failures: readonly PythonFailure[];\n}\n\nexport function inspectPythonCapabilities(options: PythonCapabilityOptions = {}): PythonCapabilityReport {\n const failures = new Set<PythonFailureCategory>();\n if ((typeof options.createWorker === 'function') === (typeof options.createExecutor === 'function')\n || options.createWorker !== undefined && typeof options.createWorker !== 'function'\n || options.createExecutor !== undefined && typeof options.createExecutor !== 'function') failures.add('executor-unavailable');\n if (typeof options.createExecutor !== 'function' && (typeof SharedArrayBuffer !== 'function' || typeof Atomics !== 'object'\n || typeof Atomics.store !== 'function' || typeof Atomics.notify !== 'function')) failures.add('transport-unavailable');\n if (options.runtimeVersion !== undefined && options.runtimeVersion !== '314.0.6') failures.add('runtime-abi');\n for (const requirement of options.requiredFileSystem ?? []) {\n if (!['open', 'read', 'write', 'directory'].includes(requirement)) throw new TypeError('Unknown Python filesystem requirement');\n const category: PythonFailureCategory = requirement === 'open' ? 'filesystem-open'\n : requirement === 'read' ? 'filesystem-read' : requirement === 'write' ? 'filesystem-write' : 'filesystem-directory';\n try {\n const fs = options.fs;\n if (requirement === 'directory') {\n failures.add(category);\n } else if (!fs || typeof fs.open !== 'function' || fs.capabilities.open === false) failures.add('filesystem-open');\n else if (requirement === 'write' && (fs.capabilities.readOnly === true || fs.capabilities.write === false)) failures.add(category);\n else if (requirement === 'read' && fs.capabilities.read === false) failures.add(category);\n } catch { failures.add(category); }\n }\n return Object.freeze({ configurationValid: failures.size === 0,\n failures: Object.freeze([...failures].map(category => new PythonFailure(category))) });\n}\n"],
5
+ "mappings": ";;;;;AAAA;AACO,IAAM,wBAAN,cAAoC,MAAM;AAAA,EAC/C,YAAY,SAAiB;AAAE,UAAM,OAAO;AAAG,SAAK,OAAO;AAAA,EAAyB;AACtF;AAGO,SAAS,sBAAsB,MAAyB,KAG7D;AACA,QAAM,cAAwB,CAAC;AAC/B,MAAI,gBAAgB;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Q;AAAA,MACvB,WAAW,CAAC,MAAM,OAAO,GAAG,SAAS,cAAc,GAAG,aAAa,SAAS,MAAO,UAAS,IAAI,iBAAiB;AAAA,eACxG,gBAAgB,YAAY,GAAG,aAAa,aAAa,QAAQ,GAAG,aAAa,UAAU,OAAQ,UAAS,IAAI,QAAQ;AAAA,eACxH,gBAAgB,UAAU,GAAG,aAAa,SAAS,MAAO,UAAS,IAAI,QAAQ;AAAA,IAC1F,QAAQ;AAAE,eAAS,IAAI,QAAQ;AAAA,IAAG;AAAA,EACpC;AACA,SAAO,OAAO,OAAO;AAAA,IAAE,oBAAoB,SAAS,SAAS;AAAA,IAC3D,UAAU,OAAO,OAAO,CAAC,GAAG,QAAQ,EAAE,IAAI,cAAY,IAAI,cAAc,QAAQ,CAAC,CAAC;AAAA,EAAE,CAAC;AACzF;",
6
6
  "names": []
7
7
  }
@@ -7,7 +7,7 @@ import {
7
7
  isPythonFailureCategory,
8
8
  parsePythonInvocation,
9
9
  reportPythonFailure
10
- } from "./chunk-Y7MAMRAF.js";
10
+ } from "./chunk-AJ355TRJ.js";
11
11
  import {
12
12
  createOutputOperation
13
13
  } from "./chunk-CDBQXRWL.js";
@@ -1342,7 +1342,7 @@ function createPythonPackageEnvironment(options = {}) {
1342
1342
  var PythonInputChunkError = class extends RangeError {
1343
1343
  };
1344
1344
  function createPythonCommands(options) {
1345
- if (typeof options?.createWorker !== "function") throw new PythonFailure("executor-unavailable");
1345
+ if (!options || typeof options.createWorker === "function" === (typeof options.createExecutor === "function") || options.createWorker !== void 0 && typeof options.createWorker !== "function" || options.createExecutor !== void 0 && typeof options.createExecutor !== "function") throw new PythonFailure("executor-unavailable");
1346
1346
  if (options.onDiagnostic !== void 0 && typeof options.onDiagnostic !== "function") throw new TypeError("Python onDiagnostic must be a function");
1347
1347
  if (options.environment && options.provisioning) throw new TypeError("A borrowed Python environment cannot be combined with provisioning options");
1348
1348
  const maxTransferBytes = options.maxTransferBytes ?? 65536;
@@ -1391,6 +1391,7 @@ function createPythonCommands(options) {
1391
1391
  let stdoutOperation;
1392
1392
  let stderrOperation;
1393
1393
  let endpoint;
1394
+ let executor;
1394
1395
  let packages;
1395
1396
  let unsubscribe;
1396
1397
  let admitted = false;
@@ -1415,7 +1416,7 @@ function createPythonCommands(options) {
1415
1416
  void (async () => {
1416
1417
  signal.removeEventListener("abort", aborted);
1417
1418
  const subscription = Promise.resolve().then(() => unsubscribe?.());
1418
- const termination = Promise.resolve().then(() => endpoint?.terminate());
1419
+ const termination = Promise.resolve().then(() => executor ? executor.terminate() : endpoint?.terminate());
1419
1420
  const results = await Promise.allSettled([subscription, termination, service.close(), stdoutOperation?.close(), stderrOperation?.close(), ...pending]);
1420
1421
  await input.return?.(void 0);
1421
1422
  fragment = void 0;
@@ -1447,31 +1448,13 @@ function createPythonCommands(options) {
1447
1448
  const outputContext = { signal, ...context.registerCleanup ? { registerCleanup: context.registerCleanup } : {} };
1448
1449
  stdoutOperation = createOutputOperation(outputContext, context.stdout);
1449
1450
  stderrOperation = createOutputOperation(outputContext, context.stderr);
1450
- let shared;
1451
- try {
1452
- shared = new SharedArrayBuffer(8 + maxTransferBytes * 6 + 65536);
1453
- } catch (reason) {
1454
- throw reportPythonFailure("transport-unavailable", reason, options.onDiagnostic);
1455
- }
1456
- const control = new Int32Array(shared, 0, 2);
1457
- const payload = new Uint8Array(shared, 8);
1458
- const reply = (value, status) => {
1459
- if (closed) return;
1460
- let bytes;
1461
- try {
1462
- bytes = encodePythonReply(value, payload.length);
1463
- } catch (error) {
1464
- if (typeof error !== "object" || error === null || !("code" in error) || error.code !== "EFBIG") throw error;
1465
- bytes = encodePythonReply({ code: "EFBIG" }, payload.length);
1466
- status = 2;
1467
- }
1468
- payload.set(bytes);
1469
- try {
1470
- Atomics.store(control, 1, bytes.length);
1471
- Atomics.store(control, 0, status);
1472
- Atomics.notify(control, 0);
1473
- } catch (reason) {
1474
- throw reportPythonFailure("transport-unavailable", reason, options.onDiagnostic);
1451
+ const diagnoseFilesystemFailure = async (operation, error) => {
1452
+ if (typeof error !== "object" || error === null || !("code" in error) || error.code !== "ENOTSUP") return;
1453
+ const category = operation === "open" ? "filesystem-open" : operation === "read" ? "filesystem-read" : operation === "write" || operation === "ftruncate" ? "filesystem-write" : operation === "readdir" ? "filesystem-directory" : "filesystem-operation";
1454
+ if (!filesystemDiagnostics.has(category)) {
1455
+ filesystemDiagnostics.add(category);
1456
+ const failure2 = reportPythonFailure(category, error, options.onDiagnostic);
1457
+ await writeBytes(stderrOperation.output, new TextEncoder().encode("python: " + failure2.message + "\n"), signal);
1475
1458
  }
1476
1459
  };
1477
1460
  const dispatch = async (request) => {
@@ -1523,114 +1506,213 @@ function createPythonCommands(options) {
1523
1506
  pending.delete(preparation);
1524
1507
  }
1525
1508
  signal.throwIfAborted();
1526
- try {
1527
- endpoint = options.createWorker();
1528
- } catch (reason) {
1529
- throw reportPythonFailure(reason instanceof PythonFailure ? reason.category : "startup", reason, options.onDiagnostic);
1530
- }
1531
- signal.throwIfAborted();
1532
- result = await new Promise((resolve, reject) => {
1533
- let settled = false;
1534
- const fail = (reason) => {
1535
- settled = true;
1536
- reject(reason);
1537
- };
1538
- rejectRun = fail;
1539
- signal.addEventListener("abort", aborted, { once: true });
1540
- const transportFailure = (reason) => {
1541
- fail(reportPythonFailure("transport-unavailable", reason, options.onDiagnostic));
1542
- };
1509
+ if (options.createExecutor) {
1543
1510
  try {
1544
- unsubscribe = endpoint.subscribe((value) => {
1545
- if (closed || settled) return;
1546
- if (typeof value !== "object" || value === null) {
1547
- transportFailure(new TypeError("Invalid Python worker message"));
1548
- return;
1511
+ executor = options.createExecutor();
1512
+ } catch (reason) {
1513
+ throw reportPythonFailure(reason instanceof PythonFailure ? reason.category : "startup", reason, options.onDiagnostic);
1514
+ }
1515
+ if (!executor || typeof executor.run !== "function" || typeof executor.terminate !== "function") throw reportPythonFailure("executor-unavailable", void 0, options.onDiagnostic);
1516
+ let requesting = false;
1517
+ let running = true;
1518
+ const start = {
1519
+ invocation: { command: context.command, args: [...context.args], cwd: context.cwd, env: { ...context.env } },
1520
+ runtimeMount,
1521
+ maxTransferBytes,
1522
+ signal,
1523
+ ...packages ? { packages } : {},
1524
+ installOnly: !!installation,
1525
+ onReady() {
1526
+ if (closed || !running || signal.aborted || ready) return;
1527
+ ready = true;
1528
+ try {
1529
+ options.onProgress?.({ phase: "ready", command: context.command });
1530
+ } catch (reason) {
1531
+ running = false;
1532
+ rejectRun?.(reason);
1533
+ throw reason;
1549
1534
  }
1550
- const message = value;
1551
- if (message.type === "ready") {
1552
- ready = true;
1553
- try {
1554
- options.onProgress?.({ phase: "ready", command: context.command });
1555
- } catch (error) {
1556
- fail(error);
1557
- }
1558
- return;
1535
+ },
1536
+ async dispatch(request) {
1537
+ signal.throwIfAborted();
1538
+ if (closed || !running || requesting || !request || typeof request.op !== "string" || !Array.isArray(request.args)) throw reportPythonFailure("transport-unavailable", void 0, options.onDiagnostic);
1539
+ requesting = true;
1540
+ const operation = Promise.resolve().then(() => dispatch(request)).catch(async (error) => {
1541
+ signal.throwIfAborted();
1542
+ if (error instanceof PythonInputChunkError) rejectRun?.(error);
1543
+ if (request.op.startsWith("package-")) throw Object.assign(reportPythonFailure("runtime-assets", error, options.onDiagnostic), { code: "EPACKAGE" });
1544
+ await diagnoseFilesystemFailure(request.op, error);
1545
+ throw error;
1546
+ });
1547
+ const tracked2 = operation.then(() => {
1548
+ }, () => {
1549
+ });
1550
+ pending.add(tracked2);
1551
+ try {
1552
+ return await operation;
1553
+ } finally {
1554
+ requesting = false;
1555
+ pending.delete(tracked2);
1559
1556
  }
1560
- if (message.type === "exit") {
1561
- if (pending.size) {
1562
- transportFailure(new TypeError("Python worker exited with an outstanding request"));
1557
+ }
1558
+ };
1559
+ const execution = Promise.resolve().then(() => {
1560
+ signal.throwIfAborted();
1561
+ return executor.run(start);
1562
+ }).catch((reason) => {
1563
+ running = false;
1564
+ if (signal.aborted) throw signal.reason;
1565
+ throw reportPythonFailure(reason instanceof PythonFailure ? reason.category : ready ? "runtime" : "startup", reason, options.onDiagnostic);
1566
+ }).then((status) => {
1567
+ running = false;
1568
+ if (requesting) throw reportPythonFailure("transport-unavailable", void 0, options.onDiagnostic);
1569
+ try {
1570
+ return validateExitCode(status);
1571
+ } catch (reason) {
1572
+ throw reportPythonFailure("transport-unavailable", reason, options.onDiagnostic);
1573
+ }
1574
+ });
1575
+ const tracked = execution.then(() => {
1576
+ }, () => {
1577
+ });
1578
+ pending.add(tracked);
1579
+ void tracked.then(() => pending.delete(tracked));
1580
+ result = await new Promise((resolve, reject) => {
1581
+ rejectRun = reject;
1582
+ signal.addEventListener("abort", aborted, { once: true });
1583
+ if (signal.aborted) aborted();
1584
+ execution.then(resolve, reject);
1585
+ });
1586
+ } else {
1587
+ let shared;
1588
+ try {
1589
+ shared = new SharedArrayBuffer(8 + maxTransferBytes * 6 + 65536);
1590
+ } catch (reason) {
1591
+ throw reportPythonFailure("transport-unavailable", reason, options.onDiagnostic);
1592
+ }
1593
+ const control = new Int32Array(shared, 0, 2);
1594
+ const payload = new Uint8Array(shared, 8);
1595
+ const reply = (value, status) => {
1596
+ if (closed) return;
1597
+ let bytes;
1598
+ try {
1599
+ bytes = encodePythonReply(value, payload.length);
1600
+ } catch (error) {
1601
+ if (typeof error !== "object" || error === null || !("code" in error) || error.code !== "EFBIG") throw error;
1602
+ bytes = encodePythonReply({ code: "EFBIG" }, payload.length);
1603
+ status = 2;
1604
+ }
1605
+ payload.set(bytes);
1606
+ try {
1607
+ Atomics.store(control, 1, bytes.length);
1608
+ Atomics.store(control, 0, status);
1609
+ Atomics.notify(control, 0);
1610
+ } catch (reason) {
1611
+ throw reportPythonFailure("transport-unavailable", reason, options.onDiagnostic);
1612
+ }
1613
+ };
1614
+ try {
1615
+ endpoint = options.createWorker();
1616
+ } catch (reason) {
1617
+ throw reportPythonFailure(reason instanceof PythonFailure ? reason.category : "startup", reason, options.onDiagnostic);
1618
+ }
1619
+ signal.throwIfAborted();
1620
+ result = await new Promise((resolve, reject) => {
1621
+ let settled = false;
1622
+ const fail = (reason) => {
1623
+ settled = true;
1624
+ reject(reason);
1625
+ };
1626
+ rejectRun = fail;
1627
+ signal.addEventListener("abort", aborted, { once: true });
1628
+ const transportFailure = (reason) => {
1629
+ fail(reportPythonFailure("transport-unavailable", reason, options.onDiagnostic));
1630
+ };
1631
+ try {
1632
+ unsubscribe = endpoint.subscribe((value) => {
1633
+ if (closed || settled) return;
1634
+ if (typeof value !== "object" || value === null) {
1635
+ transportFailure(new TypeError("Invalid Python worker message"));
1563
1636
  return;
1564
1637
  }
1565
- try {
1566
- const status = validateExitCode(message.exitCode);
1567
- settled = true;
1568
- resolve(status);
1569
- } catch (error) {
1570
- transportFailure(error);
1638
+ const message = value;
1639
+ if (message.type === "ready") {
1640
+ ready = true;
1641
+ try {
1642
+ options.onProgress?.({ phase: "ready", command: context.command });
1643
+ } catch (error) {
1644
+ fail(error);
1645
+ }
1646
+ return;
1571
1647
  }
1572
- return;
1573
- }
1574
- if (message.type === "error") {
1575
- fail(reportPythonFailure(isPythonFailureCategory(message.category) ? message.category : ready ? "runtime" : "startup", message.message, options.onDiagnostic));
1576
- return;
1577
- }
1578
- if (typeof message.op !== "string" || !Array.isArray(message.args) || pending.size) {
1579
- transportFailure(new TypeError("Invalid concurrent Python worker request"));
1580
- return;
1581
- }
1582
- const work = dispatch({ op: message.op, args: message.args }).then(
1583
- (value2) => {
1584
- pending.delete(work);
1585
- reply(value2, 1);
1586
- },
1587
- async (error) => {
1588
- if (signal.aborted) {
1589
- pending.delete(work);
1590
- fail(signal.reason);
1648
+ if (message.type === "exit") {
1649
+ if (pending.size) {
1650
+ transportFailure(new TypeError("Python worker exited with an outstanding request"));
1591
1651
  return;
1592
1652
  }
1593
- if (typeof message.op === "string" && message.op.startsWith("package-")) {
1594
- const failure2 = reportPythonFailure("runtime-assets", error, options.onDiagnostic);
1595
- pending.delete(work);
1596
- reply({ code: "EPACKAGE", message: failure2.message }, 2);
1597
- return;
1653
+ try {
1654
+ const status = validateExitCode(message.exitCode);
1655
+ settled = true;
1656
+ resolve(status);
1657
+ } catch (error) {
1658
+ transportFailure(error);
1598
1659
  }
1599
- if (typeof error !== "object" || error === null || !("code" in error) || typeof error.code !== "string") {
1660
+ return;
1661
+ }
1662
+ if (message.type === "error") {
1663
+ fail(reportPythonFailure(isPythonFailureCategory(message.category) ? message.category : ready ? "runtime" : "startup", message.message, options.onDiagnostic));
1664
+ return;
1665
+ }
1666
+ if (typeof message.op !== "string" || !Array.isArray(message.args) || pending.size) {
1667
+ transportFailure(new TypeError("Invalid concurrent Python worker request"));
1668
+ return;
1669
+ }
1670
+ const work = dispatch({ op: message.op, args: message.args }).then(
1671
+ (value2) => {
1600
1672
  pending.delete(work);
1601
- fail(error);
1602
- return;
1603
- }
1604
- if (error.code === "ENOTSUP") {
1605
- const category = message.op === "open" ? "filesystem-open" : message.op === "read" ? "filesystem-read" : message.op === "write" || message.op === "ftruncate" ? "filesystem-write" : message.op === "readdir" ? "filesystem-directory" : "filesystem-operation";
1606
- if (!filesystemDiagnostics.has(category)) {
1607
- filesystemDiagnostics.add(category);
1608
- const failure2 = reportPythonFailure(category, error, options.onDiagnostic);
1609
- await writeBytes(stderrOperation.output, new TextEncoder().encode("python: " + failure2.message + "\n"), signal);
1673
+ reply(value2, 1);
1674
+ },
1675
+ async (error) => {
1676
+ if (signal.aborted) {
1677
+ pending.delete(work);
1678
+ fail(signal.reason);
1679
+ return;
1680
+ }
1681
+ if (typeof message.op === "string" && message.op.startsWith("package-")) {
1682
+ const failure2 = reportPythonFailure("runtime-assets", error, options.onDiagnostic);
1683
+ pending.delete(work);
1684
+ reply({ code: "EPACKAGE", message: failure2.message }, 2);
1685
+ return;
1610
1686
  }
1687
+ if (typeof error !== "object" || error === null || !("code" in error) || typeof error.code !== "string") {
1688
+ pending.delete(work);
1689
+ fail(error);
1690
+ return;
1691
+ }
1692
+ await diagnoseFilesystemFailure(message.op, error);
1693
+ pending.delete(work);
1694
+ reply({ code: error.code }, 2);
1611
1695
  }
1696
+ );
1697
+ pending.add(work);
1698
+ void work.catch((reason) => {
1612
1699
  pending.delete(work);
1613
- reply({ code: error.code }, 2);
1614
- }
1615
- );
1616
- pending.add(work);
1617
- void work.catch((reason) => {
1618
- pending.delete(work);
1619
- fail(reason);
1620
- });
1621
- }, transportFailure);
1622
- } catch (reason) {
1623
- transportFailure(reason);
1624
- }
1625
- if (settled) return;
1626
- const start = { type: "start", shared, invocation: { command: context.command, args: [...context.args], cwd: context.cwd, env: { ...context.env } }, runtimeMount, maxTransferBytes, ...packages ? { packages } : {}, installOnly: !!installation };
1627
- signal.throwIfAborted();
1628
- try {
1629
- endpoint.postMessage(start);
1630
- } catch (reason) {
1631
- transportFailure(reason);
1632
- }
1633
- });
1700
+ fail(reason);
1701
+ });
1702
+ }, transportFailure);
1703
+ } catch (reason) {
1704
+ transportFailure(reason);
1705
+ }
1706
+ if (settled) return;
1707
+ const start = { type: "start", shared, invocation: { command: context.command, args: [...context.args], cwd: context.cwd, env: { ...context.env } }, runtimeMount, maxTransferBytes, ...packages ? { packages } : {}, installOnly: !!installation };
1708
+ signal.throwIfAborted();
1709
+ try {
1710
+ endpoint.postMessage(start);
1711
+ } catch (reason) {
1712
+ transportFailure(reason);
1713
+ }
1714
+ });
1715
+ }
1634
1716
  } catch (reason) {
1635
1717
  if (!signal.aborted && reason instanceof PythonInputChunkError) {
1636
1718
  try {
@@ -1661,10 +1743,10 @@ function createPythonCommands(options) {
1661
1743
  }
1662
1744
  return { exitCode: result };
1663
1745
  };
1664
- return ["python", "python3"].map((name) => ({ name, description: "Python with an explicit synchronous interpreter worker and canonical filesystem", execute }));
1746
+ return ["python", "python3"].map((name) => ({ name, description: "Python with an explicit interpreter executor and canonical filesystem", execute }));
1665
1747
  }
1666
1748
  function pythonCommands(options) {
1667
- if (typeof options?.createWorker !== "function") throw new PythonFailure("executor-unavailable");
1749
+ if (!options || typeof options.createWorker === "function" === (typeof options.createExecutor === "function")) throw new PythonFailure("executor-unavailable");
1668
1750
  if (options?.environment && options.provisioning) throw new TypeError("A borrowed Python environment cannot be combined with provisioning options");
1669
1751
  const { provisioning, ...configuration } = options;
1670
1752
  const environment = options.environment ?? createPythonPackageEnvironment(provisioning);
@@ -1697,4 +1779,4 @@ export {
1697
1779
  createPythonCommands,
1698
1780
  pythonCommands
1699
1781
  };
1700
- //# sourceMappingURL=chunk-Z4UKD5FF.js.map
1782
+ //# sourceMappingURL=chunk-PUNPTDFQ.js.map