@camstack/types 0.1.31 → 0.1.33

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 (90) hide show
  1. package/dist/capabilities/admin-ui.cap.d.ts +6 -2
  2. package/dist/capabilities/admin-ui.cap.d.ts.map +1 -1
  3. package/dist/capabilities/advanced-notifier.cap.d.ts +202 -29
  4. package/dist/capabilities/advanced-notifier.cap.d.ts.map +1 -1
  5. package/dist/capabilities/audio-codec.cap.d.ts +2 -2
  6. package/dist/capabilities/capability-definition.d.ts +22 -0
  7. package/dist/capabilities/capability-definition.d.ts.map +1 -1
  8. package/dist/capabilities/device-export.cap.d.ts +77 -0
  9. package/dist/capabilities/device-export.cap.d.ts.map +1 -0
  10. package/dist/capabilities/embedding-encoder.cap.d.ts +14 -7
  11. package/dist/capabilities/embedding-encoder.cap.d.ts.map +1 -1
  12. package/dist/capabilities/index.d.ts +15 -11
  13. package/dist/capabilities/index.d.ts.map +1 -1
  14. package/dist/capabilities/intercom.cap.d.ts +34 -0
  15. package/dist/capabilities/intercom.cap.d.ts.map +1 -1
  16. package/dist/capabilities/mesh-network.cap.d.ts +72 -22
  17. package/dist/capabilities/mesh-network.cap.d.ts.map +1 -1
  18. package/dist/capabilities/mesh-orchestrator.cap.d.ts +67 -0
  19. package/dist/capabilities/mesh-orchestrator.cap.d.ts.map +1 -1
  20. package/dist/capabilities/mqtt-broker.cap.d.ts +153 -0
  21. package/dist/capabilities/mqtt-broker.cap.d.ts.map +1 -0
  22. package/dist/capabilities/network-access.cap.d.ts +41 -1
  23. package/dist/capabilities/network-access.cap.d.ts.map +1 -1
  24. package/dist/capabilities/nodes.cap.d.ts +23 -1
  25. package/dist/capabilities/nodes.cap.d.ts.map +1 -1
  26. package/dist/capabilities/platform-probe.cap.d.ts +234 -15
  27. package/dist/capabilities/platform-probe.cap.d.ts.map +1 -1
  28. package/dist/capabilities/smtp-provider.cap.d.ts +11 -10
  29. package/dist/capabilities/smtp-provider.cap.d.ts.map +1 -1
  30. package/dist/capabilities/sso-bridge.cap.d.ts +3 -0
  31. package/dist/capabilities/sso-bridge.cap.d.ts.map +1 -1
  32. package/dist/capabilities/stream-broker.cap.d.ts +90 -85
  33. package/dist/capabilities/stream-broker.cap.d.ts.map +1 -1
  34. package/dist/capabilities/user-management.cap.d.ts +4 -0
  35. package/dist/capabilities/user-management.cap.d.ts.map +1 -1
  36. package/dist/capabilities/webrtc-session.cap.d.ts +34 -0
  37. package/dist/capabilities/webrtc-session.cap.d.ts.map +1 -1
  38. package/dist/enums/event-category.d.ts +1 -8
  39. package/dist/enums/event-category.d.ts.map +1 -1
  40. package/dist/generated/addon-api.d.ts +13377 -10829
  41. package/dist/generated/addon-api.d.ts.map +1 -1
  42. package/dist/generated/cap-status-types.d.ts +5 -1
  43. package/dist/generated/cap-status-types.d.ts.map +1 -1
  44. package/dist/generated/capability-router-map.d.ts +7 -7
  45. package/dist/generated/capability-router-map.d.ts.map +1 -1
  46. package/dist/generated/device-proxy.d.ts +2 -0
  47. package/dist/generated/device-proxy.d.ts.map +1 -1
  48. package/dist/generated/method-access-map.d.ts +1 -1
  49. package/dist/generated/method-access-map.d.ts.map +1 -1
  50. package/dist/generated/provider-kind-map.d.ts +22 -0
  51. package/dist/generated/provider-kind-map.d.ts.map +1 -0
  52. package/dist/generated/system-proxy.d.ts +9 -5
  53. package/dist/generated/system-proxy.d.ts.map +1 -1
  54. package/dist/{index-BKifir_y.js → index-DRWlYskM.js} +541 -355
  55. package/dist/index-DRWlYskM.js.map +1 -0
  56. package/dist/{index-BKnvgAep.mjs → index-YnRVILXN.mjs} +801 -615
  57. package/dist/index-YnRVILXN.mjs.map +1 -0
  58. package/dist/index.d.ts +2 -0
  59. package/dist/index.d.ts.map +1 -1
  60. package/dist/index.js +119 -40
  61. package/dist/index.js.map +1 -1
  62. package/dist/index.mjs +376 -297
  63. package/dist/index.mjs.map +1 -1
  64. package/dist/interfaces/addon.d.ts +14 -3
  65. package/dist/interfaces/addon.d.ts.map +1 -1
  66. package/dist/interfaces/advanced-notifier.d.ts +8 -7
  67. package/dist/interfaces/advanced-notifier.d.ts.map +1 -1
  68. package/dist/interfaces/api-responses.d.ts +6 -0
  69. package/dist/interfaces/api-responses.d.ts.map +1 -1
  70. package/dist/interfaces/capability.d.ts +6 -6
  71. package/dist/interfaces/capability.d.ts.map +1 -1
  72. package/dist/interfaces/embedding-encoder.d.ts +16 -7
  73. package/dist/interfaces/embedding-encoder.d.ts.map +1 -1
  74. package/dist/interfaces/rtp-egress.d.ts +45 -0
  75. package/dist/interfaces/rtp-egress.d.ts.map +1 -0
  76. package/dist/interfaces/storage.d.ts +1 -1
  77. package/dist/interfaces/storage.d.ts.map +1 -1
  78. package/dist/node.js +6 -6
  79. package/dist/node.js.map +1 -1
  80. package/dist/node.mjs +6 -6
  81. package/dist/node.mjs.map +1 -1
  82. package/dist/storage/filesystem-storage-provider.d.ts +1 -1
  83. package/dist/storage/filesystem-storage-provider.d.ts.map +1 -1
  84. package/package.json +1 -1
  85. package/dist/capabilities/home-assistant.cap.d.ts +0 -138
  86. package/dist/capabilities/home-assistant.cap.d.ts.map +0 -1
  87. package/dist/capabilities/mqtt-provider.cap.d.ts +0 -91
  88. package/dist/capabilities/mqtt-provider.cap.d.ts.map +0 -1
  89. package/dist/index-BKifir_y.js.map +0 -1
  90. package/dist/index-BKnvgAep.mjs.map +0 -1
package/dist/node.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"node.js","sources":["../src/deps/binary-downloader.ts","../src/deps/ffmpeg-downloader.ts","../src/deps/python-downloader.ts","../src/storage/filesystem-storage-provider.ts"],"sourcesContent":["import { existsSync, mkdirSync, chmodSync, createWriteStream, unlinkSync } from 'node:fs'\nimport { join } from 'node:path'\nimport { pipeline } from 'node:stream/promises'\nimport { Readable } from 'node:stream'\nimport { execFileSync } from 'node:child_process'\nimport type { IScopedLogger } from '../index.js'\n\nexport interface PlatformInfo {\n readonly platform: NodeJS.Platform\n readonly arch: NodeJS.Architecture\n}\n\nexport function getPlatformInfo(): PlatformInfo {\n return {\n platform: process.platform,\n arch: process.arch,\n }\n}\n\nexport function buildBinaryPath(dataDir: string, name: string, platform?: string): string {\n const ext = (platform ?? process.platform) === 'win32' ? '.exe' : ''\n return join(dataDir, 'deps', `${name}${ext}`)\n}\n\n/** Check if a binary exists in PATH */\nexport function findInPath(name: string): string | null {\n try {\n execFileSync(name, ['--version'], { stdio: 'pipe', timeout: 5000 })\n return name\n } catch {\n return null\n }\n}\n\nexport interface DownloadOptions {\n readonly name: string\n readonly url: string\n readonly targetDir: string\n readonly targetName: string\n readonly logger: IScopedLogger\n readonly isArchive?: boolean\n readonly archiveFormat?: 'zip' | 'tar.gz' | 'tar.xz'\n /** Relative path within archive to the binary (e.g., 'ffmpeg-6.1/bin/ffmpeg') */\n readonly archiveInnerPath?: string\n}\n\n/**\n * Download a binary to the target directory.\n * Handles archives (zip, tar.gz, tar.xz) and raw binaries.\n */\nexport async function downloadBinary(opts: DownloadOptions): Promise<string> {\n const { name, url, targetDir, targetName, logger, isArchive, archiveFormat, archiveInnerPath } = opts\n const targetPath = join(targetDir, targetName)\n\n if (existsSync(targetPath)) {\n logger.debug('Binary already exists', { meta: { name, targetPath } })\n return targetPath\n }\n\n mkdirSync(targetDir, { recursive: true })\n\n logger.info('Downloading binary', { meta: { name, url } })\n const response = await fetch(url, { redirect: 'follow' })\n if (!response.ok || !response.body) {\n throw new Error(`Failed to download ${name}: ${response.status} ${response.statusText}`)\n }\n\n if (isArchive) {\n const ext = archiveFormat ?? 'tar.gz'\n const tmpArchive = join(targetDir, `${name}-download.${ext}`)\n const nodeStream = Readable.fromWeb(response.body as ReadableStream)\n await pipeline(nodeStream, createWriteStream(tmpArchive))\n\n // Extract\n const tmpExtractDir = join(targetDir, `${name}-extract`)\n mkdirSync(tmpExtractDir, { recursive: true })\n\n if (ext === 'zip') {\n try {\n execFileSync('unzip', ['-o', '-q', tmpArchive, '-d', tmpExtractDir], { stdio: 'pipe' })\n } catch {\n execFileSync('tar', ['-xf', tmpArchive, '-C', tmpExtractDir], { stdio: 'pipe' })\n }\n } else if (ext === 'tar.xz') {\n execFileSync('tar', ['-xJf', tmpArchive, '-C', tmpExtractDir], { stdio: 'pipe' })\n } else {\n execFileSync('tar', ['-xzf', tmpArchive, '-C', tmpExtractDir], { stdio: 'pipe' })\n }\n\n // Copy binary from archive\n if (archiveInnerPath) {\n const { copyFileSync } = await import('node:fs')\n const sourcePath = join(tmpExtractDir, archiveInnerPath)\n if (!existsSync(sourcePath)) {\n throw new Error(`Binary not found in archive at ${archiveInnerPath}`)\n }\n copyFileSync(sourcePath, targetPath)\n }\n\n // Cleanup\n unlinkSync(tmpArchive)\n const { rmSync } = await import('node:fs')\n rmSync(tmpExtractDir, { recursive: true, force: true })\n } else {\n // Direct binary download\n const nodeStream = Readable.fromWeb(response.body as ReadableStream)\n await pipeline(nodeStream, createWriteStream(targetPath))\n }\n\n chmodSync(targetPath, 0o755)\n logger.info('Binary downloaded', { meta: { name, targetPath } })\n return targetPath\n}\n\n/**\n * Ensure a binary is available. Checks:\n * 1. Target path (already downloaded)\n * 2. System PATH\n * 3. Download from URL\n */\nexport async function ensureBinary(opts: {\n readonly name: string\n readonly targetDir: string\n readonly downloadUrl: string\n readonly logger: IScopedLogger\n readonly isArchive?: boolean\n readonly archiveFormat?: 'zip' | 'tar.gz' | 'tar.xz'\n readonly archiveInnerPath?: string\n}): Promise<string> {\n const ext = process.platform === 'win32' ? '.exe' : ''\n const targetName = `${opts.name}${ext}`\n const targetPath = join(opts.targetDir, targetName)\n\n // 1. Already downloaded\n if (existsSync(targetPath)) {\n opts.logger.debug('Binary found at target path', { meta: { name: opts.name, targetPath } })\n return targetPath\n }\n\n // 2. System PATH\n const inPath = findInPath(opts.name)\n if (inPath) {\n opts.logger.info('Binary found in system PATH', { meta: { name: opts.name } })\n return inPath\n }\n\n // 3. Download\n return downloadBinary({\n name: opts.name,\n url: opts.downloadUrl,\n targetDir: opts.targetDir,\n targetName,\n logger: opts.logger,\n isArchive: opts.isArchive,\n archiveFormat: opts.archiveFormat,\n archiveInnerPath: opts.archiveInnerPath,\n })\n}\n","/**\n * Download ffmpeg static build for the current platform.\n *\n * Sources:\n * - Linux: https://johnvansickle.com/ffmpeg/ (static builds)\n * - macOS: https://evermeet.cx/ffmpeg/ or homebrew\n *\n * Using BtbN's GitHub releases as they cover both platforms:\n * https://github.com/BtbN/FFmpeg-Builds/releases\n */\nimport { join } from 'node:path'\nimport type { IScopedLogger } from '../index.js'\nimport { ensureBinary } from './binary-downloader.js'\n\nconst FFMPEG_VERSION = '7.1'\n\nexport function getFfmpegDownloadUrl(platform: string, arch: string): string {\n switch (platform) {\n case 'linux': {\n const archMap: Record<string, string> = { x64: 'amd64', arm64: 'arm64' }\n const a = archMap[arch]\n if (!a) throw new Error(`Unsupported Linux architecture: ${arch}`)\n // John Van Sickle static builds — well-tested, widely used\n return `https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-${a}-static.tar.xz`\n }\n case 'darwin': {\n const archMap: Record<string, string> = { arm64: 'arm64', x64: 'amd64' }\n const a = archMap[arch]\n if (!a) throw new Error(`Unsupported macOS architecture: ${arch}`)\n // macOS static builds from osxexperts (maintained, universal builds)\n return `https://www.osxexperts.net/ffmpeg${FFMPEG_VERSION.replace('.', '')}arm.zip`\n }\n default:\n throw new Error(`Unsupported platform: ${platform}`)\n }\n}\n\nexport function getFfmpegArchiveInfo(platform: string): {\n isArchive: boolean\n archiveFormat: 'zip' | 'tar.gz' | 'tar.xz'\n archiveInnerPath: string\n} {\n switch (platform) {\n case 'linux':\n return {\n isArchive: true,\n archiveFormat: 'tar.xz',\n archiveInnerPath: `ffmpeg-${FFMPEG_VERSION}-amd64-static/ffmpeg`,\n }\n case 'darwin':\n return {\n isArchive: true,\n archiveFormat: 'zip',\n archiveInnerPath: 'ffmpeg',\n }\n default:\n throw new Error(`Unsupported platform: ${platform}`)\n }\n}\n\n/**\n * Ensure ffmpeg binary is available.\n * Checks: deps dir → system PATH → download.\n */\nexport async function ensureFfmpeg(dataDir: string, logger: IScopedLogger): Promise<string> {\n const depsDir = join(dataDir, 'deps')\n const platform = process.platform\n const arch = process.arch\n\n const archiveInfo = getFfmpegArchiveInfo(platform)\n\n return ensureBinary({\n name: 'ffmpeg',\n targetDir: depsDir,\n downloadUrl: getFfmpegDownloadUrl(platform, arch),\n logger,\n ...archiveInfo,\n })\n}\n","/**\n * Download portable Python (headless) from bjia56/portable-python.\n *\n * Source: https://github.com/bjia56/portable-python\n *\n * Advantages over python-build-standalone:\n * - macOS universal2 binary (arm64+x86_64 in one)\n * - Lighter (~24-28MB headless zip)\n * - glibc 2.17 minimum (better compat)\n * - Headless variant excludes tkinter/UI (ideal for ML inference)\n *\n * The zip's top-level dir is platform-specific (e.g.\n * `python-headless-3.12.12-darwin-universal2/`); after extraction\n * we rename it to a stable `python/` so consumers can rely on\n * `<dataDir>/deps/python/bin/python3`.\n */\nimport { join, basename } from 'node:path'\nimport { existsSync, mkdirSync, chmodSync, readFileSync, writeFileSync, readdirSync, renameSync, rmSync } from 'node:fs'\nimport { execFileSync } from 'node:child_process'\nimport { createHash } from 'node:crypto'\nimport { pipeline } from 'node:stream/promises'\nimport { Readable } from 'node:stream'\nimport { createWriteStream } from 'node:fs'\nimport type { IScopedLogger } from '../index.js'\nimport { errMsg } from '../index.js'\n\nexport const PYTHON_VERSION = '3.12.12'\nconst PP_BASE = `https://github.com/bjia56/portable-python/releases/download/cpython-v${PYTHON_VERSION}-build.0`\n\nexport function getPythonDownloadUrl(platform: string, arch: string): string {\n switch (platform) {\n case 'linux': {\n const archMap: Record<string, string> = { x64: 'x86_64', arm64: 'aarch64' }\n const a = archMap[arch]\n if (!a) throw new Error(`Unsupported Linux architecture for Python: ${arch}`)\n return `${PP_BASE}/python-headless-${PYTHON_VERSION}-linux-${a}.zip`\n }\n case 'darwin': {\n // universal2 covers both arm64 and x86_64\n return `${PP_BASE}/python-headless-${PYTHON_VERSION}-darwin-universal2.zip`\n }\n default:\n throw new Error(`Unsupported platform for portable Python: ${platform}`)\n }\n}\n\n/**\n * Ensure the embedded portable Python is available.\n *\n * ALWAYS returns the path to the embedded interpreter under\n * `<dataDir>/deps/python/bin/python3` — downloads it on first call\n * and reuses it thereafter. The system PATH is intentionally NOT\n * consulted: addons rely on `installPythonRequirements()` to manage\n * deps inside the embedded site-packages, and a system interpreter\n * (different version, missing modules) silently breaks that contract.\n *\n * Returns null only if the download/extract step fails.\n */\nexport async function ensurePython(dataDir: string, logger: IScopedLogger): Promise<string | null> {\n const pythonDir = join(dataDir, 'deps', 'python')\n const pythonBin = join(pythonDir, 'bin', 'python3')\n\n // 1. Already downloaded\n if (existsSync(pythonBin)) {\n logger.debug('Portable Python found', { meta: { pythonBin } })\n return pythonBin\n }\n\n // 2. Download portable python (no system PATH fallback — by design)\n logger.info('Downloading portable Python (headless)', { meta: { version: PYTHON_VERSION } })\n\n const depsDir = join(dataDir, 'deps')\n mkdirSync(depsDir, { recursive: true })\n\n const url = getPythonDownloadUrl(process.platform, process.arch)\n const tmpArchive = join(depsDir, 'python-download.zip')\n\n logger.info('Python download source', { meta: { url } })\n\n const response = await fetch(url, { redirect: 'follow' })\n if (!response.ok || !response.body) {\n logger.warn('Failed to download Python — ML detection will not be available', { meta: { status: response.status } })\n return null\n }\n\n const nodeStream = Readable.fromWeb(response.body as ReadableStream)\n await pipeline(nodeStream, createWriteStream(tmpArchive))\n\n // Extract — zip's top-level dir is e.g. `python-headless-3.12.12-darwin-universal2/`\n // (varies per platform/arch).\n try {\n execFileSync('unzip', ['-o', '-q', tmpArchive, '-d', depsDir], { stdio: 'pipe' })\n } catch {\n // Fallback: some minimal Linux installs don't have unzip\n execFileSync('python3', ['-m', 'zipfile', '-e', tmpArchive, depsDir], { stdio: 'pipe' })\n }\n\n // Cleanup the archive\n const { unlinkSync } = await import('node:fs')\n unlinkSync(tmpArchive)\n\n // Locate the extracted directory and normalize it to `<depsDir>/python/`.\n // The zip's top-level name varies by platform (e.g.\n // `python-headless-3.12.12-darwin-universal2/`), so we look for any\n // `python-*` subdir that contains the expected `bin/python3` and rename it.\n if (!existsSync(pythonBin)) {\n const candidates = readdirSync(depsDir).filter((name) =>\n name.startsWith('python-') &&\n existsSync(join(depsDir, name, 'bin', 'python3')),\n )\n if (candidates.length === 0) {\n logger.warn('Python extraction succeeded but no python3 binary found in any subdir', {\n meta: { depsDir },\n })\n return null\n }\n const extractedRoot = join(depsDir, candidates[0]!)\n // Drop any stale `python/` (e.g. from a previous failed install)\n // before renaming so the move always succeeds.\n if (existsSync(pythonDir)) {\n rmSync(pythonDir, { recursive: true, force: true })\n }\n renameSync(extractedRoot, pythonDir)\n }\n\n if (!existsSync(pythonBin)) {\n logger.warn('Python extraction succeeded but binary not found at expected path', {\n meta: { pythonBin },\n })\n return null\n }\n\n chmodSync(pythonBin, 0o755)\n\n // On macOS the bjia56 build is universal2 — the host arch is decided\n // at spawn time based on the parent process. That makes pip wheels\n // and runtime spawns silently disagree when the server is launched\n // from a Rosetta shell once and a native shell next time (e.g. pip\n // installs `numpy x86_64`, then the next boot under arm64 fails with\n // `incompatible architecture`). Lock the slice deterministically by\n // wrapping `python3` in a shell stub that always invokes the matching\n // host arch via `/usr/bin/arch`. Idempotent: detected via the renamed\n // `.real` binary.\n if (process.platform === 'darwin') {\n const realBin = join(pythonDir, 'bin', 'python3.real')\n if (!existsSync(realBin)) {\n renameSync(pythonBin, realBin)\n const archFlag = process.arch === 'arm64' ? '-arm64' : '-x86_64'\n writeFileSync(\n pythonBin,\n `#!/bin/sh\\nexec /usr/bin/arch ${archFlag} \"${realBin}\" \"$@\"\\n`,\n )\n chmodSync(pythonBin, 0o755)\n // Mirror the same wrapping for the `python` symlink so consumers\n // that use the un-versioned name also lock the arch.\n const pyAlt = join(pythonDir, 'bin', 'python')\n if (existsSync(pyAlt)) {\n try {\n rmSync(pyAlt, { force: true })\n } catch {\n // ignore\n }\n writeFileSync(\n pyAlt,\n `#!/bin/sh\\nexec /usr/bin/arch ${archFlag} \"${realBin}\" \"$@\"\\n`,\n )\n chmodSync(pyAlt, 0o755)\n }\n logger.info('Locked python3 to host arch via shell stub', {\n meta: { archFlag, realBin },\n })\n }\n }\n\n logger.info('Portable Python installed', { meta: { version: PYTHON_VERSION, pythonBin } })\n return pythonBin\n}\n\n/**\n * Install Python packages into the portable Python environment.\n */\nexport async function installPythonPackages(\n pythonPath: string,\n packages: readonly string[],\n logger: IScopedLogger,\n): Promise<void> {\n if (packages.length === 0) return\n\n logger.info('Installing Python packages', { meta: { packages } })\n try {\n execFileSync(pythonPath, ['-m', 'pip', 'install', '--quiet', ...packages], {\n stdio: 'pipe',\n timeout: 300_000, // 5 minutes for large packages like torch\n })\n logger.info('Python packages installed successfully')\n } catch (err) {\n logger.error('Failed to install Python packages', { meta: { error: errMsg(err) } })\n throw err\n }\n}\n\n/**\n * Install a pip requirements file into the embedded Python.\n *\n * Idempotent: keyed on (requirements file basename + sha256 of its\n * contents). The marker is written under\n * `<python-install-dir>/.requirements-installed/` so it lives and\n * dies with the python install — re-downloading python wipes both\n * the site-packages and the markers, forcing a fresh re-install.\n *\n * The marker is updated only after `pip install` succeeds. A failed\n * install never writes a marker, so the next call retries.\n */\nexport async function installPythonRequirements(\n pythonPath: string,\n requirementsFile: string,\n logger: IScopedLogger,\n): Promise<void> {\n if (!existsSync(requirementsFile)) {\n throw new Error(`Requirements file not found: ${requirementsFile}`)\n }\n\n const contents = readFileSync(requirementsFile)\n const hash = createHash('sha256').update(contents).digest('hex').slice(0, 16)\n const fileBase = basename(requirementsFile).replace(/\\.txt$/i, '')\n\n // Markers live under the python install dir → wiped together when\n // the embedded interpreter is re-downloaded.\n const pythonRoot = join(pythonPath, '..', '..') // <root>/bin/python3 → <root>\n const markerDir = join(pythonRoot, '.requirements-installed')\n const markerPath = join(markerDir, `${fileBase}-${hash}.marker`)\n\n if (existsSync(markerPath)) {\n logger.debug('Python requirements already installed', { meta: { requirementsFile, hash } })\n return\n }\n\n logger.info('Installing Python requirements', { meta: { requirementsFile, hash } })\n try {\n execFileSync(\n pythonPath,\n ['-m', 'pip', 'install', '--quiet', '--disable-pip-version-check', '-r', requirementsFile],\n {\n stdio: 'pipe',\n timeout: 600_000, // 10 minutes — coremltools + tensorflow can be slow\n },\n )\n } catch (err) {\n logger.error('Failed to install Python requirements', {\n meta: { requirementsFile, error: errMsg(err) },\n })\n throw err\n }\n\n mkdirSync(markerDir, { recursive: true })\n writeFileSync(markerPath, `${requirementsFile}\\n${new Date().toISOString()}\\n`)\n logger.info('Python requirements installed', { meta: { requirementsFile, hash } })\n}\n","import * as fs from 'node:fs'\nimport * as path from 'node:path'\nimport type {\n IStorageProvider,\n StorageLocationType,\n StorageResolveInput,\n StorageWriteInput,\n StorageReadInput,\n StorageExistsInput,\n StorageListInput,\n StorageDeleteInput,\n StorageAvailableSpaceInput,\n} from '../index.js'\n\n// Inline constants to avoid runtime dependency on @camstack/types\n// (types is external in tsup bundle, may not be resolvable from data/addons/)\nconst STORAGE_LOCATION_TYPES: readonly StorageLocationType[] = [\n 'data', 'media', 'recordings',\n 'recordings-high', 'recordings-low', 'recordings-clips', 'event-images',\n 'models', 'addons-data', 'cache', 'logs', 'backups',\n]\n\nconst DEFAULT_LOCATION_SUBDIRS: Readonly<Record<StorageLocationType, string>> = {\n 'data': 'db',\n 'media': 'media',\n 'recordings': 'recordings',\n 'recordings-high': 'recordings-high',\n 'recordings-low': 'recordings-low',\n 'recordings-clips': 'recordings-clips',\n 'event-images': 'event-images',\n 'models': 'models',\n 'addons-data': 'addons-data',\n 'cache': '/tmp/camstack-cache',\n 'logs': 'logs',\n 'backups': 'backups',\n}\n\n/**\n * Filesystem storage provider — serves all location types from a local directory tree.\n *\n * Default layout:\n * {rootPath}/recordings-high/\n * {rootPath}/recordings-low/\n * {rootPath}/recordings-clips/\n * {rootPath}/event-images/\n * {rootPath}/models/\n * {rootPath}/addons-data/\n * {rootPath}/logs/\n * /tmp/camstack-cache/ (cache is always local)\n *\n * Individual location paths can be overridden.\n */\nexport class FilesystemStorageProvider implements IStorageProvider {\n readonly id = 'local'\n readonly name = 'Local Filesystem'\n readonly supportedLocations: readonly StorageLocationType[] = [...STORAGE_LOCATION_TYPES]\n\n private readonly rootPath: string\n private readonly locationPaths: Map<StorageLocationType, string>\n\n constructor(rootPath: string, overrides?: Partial<Record<StorageLocationType, string>>) {\n this.rootPath = path.resolve(rootPath)\n this.locationPaths = new Map()\n\n for (const loc of STORAGE_LOCATION_TYPES) {\n const override = overrides?.[loc]\n if (override) {\n this.locationPaths.set(loc, path.resolve(override))\n } else {\n const subdir = DEFAULT_LOCATION_SUBDIRS[loc]\n // Absolute paths (like /tmp/camstack-cache) are used as-is\n this.locationPaths.set(\n loc,\n path.isAbsolute(subdir) ? subdir : path.join(this.rootPath, subdir),\n )\n }\n }\n }\n\n resolve({ location, relativePath }: StorageResolveInput): string {\n const base = this.locationPaths.get(location)\n if (!base) throw new Error(`Unknown storage location: ${location}`)\n return path.join(base, relativePath)\n }\n\n async write({ location, relativePath, data }: StorageWriteInput): Promise<void> {\n const filePath = this.resolve({ location, relativePath })\n await fs.promises.mkdir(path.dirname(filePath), { recursive: true })\n\n if (Buffer.isBuffer(data)) {\n await fs.promises.writeFile(filePath, data)\n } else {\n // Stream\n const writeStream = fs.createWriteStream(filePath)\n await new Promise<void>((resolve, reject) => {\n (data as NodeJS.ReadableStream).pipe(writeStream)\n writeStream.on('finish', resolve)\n writeStream.on('error', reject)\n })\n }\n }\n\n async read({ location, relativePath }: StorageReadInput): Promise<Buffer> {\n return fs.promises.readFile(this.resolve({ location, relativePath }))\n }\n\n async exists({ location, relativePath }: StorageExistsInput): Promise<boolean> {\n try {\n await fs.promises.access(this.resolve({ location, relativePath }))\n return true\n } catch {\n return false\n }\n }\n\n async list({ location, prefix }: StorageListInput): Promise<readonly string[]> {\n const base = this.locationPaths.get(location)\n if (!base) return []\n const dir = prefix ? path.join(base, prefix) : base\n try {\n const entries = await fs.promises.readdir(dir, { withFileTypes: true })\n return entries.map(e => (prefix ? `${prefix}/${e.name}` : e.name))\n } catch {\n return []\n }\n }\n\n async delete({ location, relativePath }: StorageDeleteInput): Promise<void> {\n const filePath = this.resolve({ location, relativePath })\n await fs.promises.rm(filePath, { force: true })\n }\n\n async getAvailableSpace({ location }: StorageAvailableSpaceInput): Promise<number | null> {\n const base = this.locationPaths.get(location)\n if (!base) return null\n // If the directory doesn't exist yet (lazy creation), walk up to\n // the nearest existing ancestor so statfs can still report free\n // space on the mount point. This keeps the storage dashboard\n // working on a fresh install where no file has been written yet.\n try {\n let target = base\n while (!fs.existsSync(target)) {\n const parent = path.dirname(target)\n if (!parent || parent === target) return null\n target = parent\n }\n const stats = await fs.promises.statfs(target)\n return stats.bavail * stats.bsize\n } catch {\n return null\n }\n }\n\n\n /** Get the resolved path for a location type */\n getLocationPath(location: StorageLocationType): string {\n const p = this.locationPaths.get(location)\n if (!p) throw new Error(`Unknown storage location: ${location}`)\n return p\n }\n\n /** Get the root path */\n getRootPath(): string {\n return this.rootPath\n }\n}\n\nexport default FilesystemStorageProvider\n"],"names":["join","execFileSync","existsSync","mkdirSync","Readable","pipeline","createWriteStream","unlinkSync","chmodSync","readdirSync","rmSync","renameSync","writeFileSync","errMsg","readFileSync","createHash","basename","path","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYO,SAAS,kBAAgC;AAC9C,SAAO;AAAA,IACL,UAAU,QAAQ;AAAA,IAClB,MAAM,QAAQ;AAAA,EAAA;AAElB;AAEO,SAAS,gBAAgB,SAAiB,MAAc,UAA2B;AACxF,QAAM,OAAO,YAAY,QAAQ,cAAc,UAAU,SAAS;AAClE,SAAOA,KAAAA,KAAK,SAAS,QAAQ,GAAG,IAAI,GAAG,GAAG,EAAE;AAC9C;AAGO,SAAS,WAAW,MAA6B;AACtD,MAAI;AACFC,oCAAa,MAAM,CAAC,WAAW,GAAG,EAAE,OAAO,QAAQ,SAAS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AAM,UAAU,MAAMC,cAAG,SAAS,QAAQ,KAAK,EAAE,eAAe,MAAM;AACtE,aAAO,QAAQ,IAAI,CAAA,MAAM,SAAS,GAAG,MAAM,IAAI,EAAE,IAAI,KAAK,EAAE,IAAK;AAAA,IACnE,QAAQ;AACN,aAAO,CAAA;AAAA,IACT;AAAA,EACF;AAAA,EAEA,MAAM,OAAO,EAAE,UAAU,gBAAmD;AAC1E,UAAM,WAAW,KAAK,QAAQ,EAAE,UAAU,cAAc;AACxD,UAAMA,cAAG,SAAS,GAAG,UAAU,EAAE,OAAO,MAAM;AAAA,EAChD;AAAA,EAEA,MAAM,kBAAkB,EAAE,YAAgE;AACxF,UAAM,OAAO,KAAK,cAAc,IAAI,QAAQ;AAC5C,QAAI,CAAC,KAAM,QAAO;AAKlB,QAAI;AACF,UAAI,SAAS;AACb,aAAO,CAACA,cAAG,WAAW,MAAM,GAAG;AAC7B,cAAM,SAASD,gBAAK,QAAQ,MAAM;AAClC,YAAI,CAAC,UAAU,WAAW,OAAQ,QAAO;AACzC,iBAAS;AAAA,MACX;AACA,YAAM,QAAQ,MAAMC,cAAG,SAAS,OAAO,MAAM;AAC7C,aAAO,MAAM,SAAS,MAAM;AAAA,IAC9B,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAAA;AAAA,EAIA,gBAAgB,UAAuC;AACrD,UAAM,IAAI,KAAK,cAAc,IAAI,QAAQ;AACzC,QAAI,CAAC,EAAG,OAAM,IAAI,MAAM,6BAA6B,QAAQ,EAAE;AAC/D,WAAO;AAAA,EACT;AAAA;AAAA,EAGA,cAAsB;AACpB,WAAO,KAAK;AAAA,EACd;AACF;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"node.js","sources":["../src/deps/binary-downloader.ts","../src/deps/ffmpeg-downloader.ts","../src/deps/python-downloader.ts","../src/storage/filesystem-storage-provider.ts"],"sourcesContent":["import { existsSync, mkdirSync, chmodSync, createWriteStream, unlinkSync } from 'node:fs'\nimport { join } from 'node:path'\nimport { pipeline } from 'node:stream/promises'\nimport { Readable } from 'node:stream'\nimport { execFileSync } from 'node:child_process'\nimport type { IScopedLogger } from '../index.js'\n\nexport interface PlatformInfo {\n readonly platform: NodeJS.Platform\n readonly arch: NodeJS.Architecture\n}\n\nexport function getPlatformInfo(): PlatformInfo {\n return {\n platform: process.platform,\n arch: process.arch,\n }\n}\n\nexport function buildBinaryPath(dataDir: string, name: string, platform?: string): string {\n const ext = (platform ?? process.platform) === 'win32' ? '.exe' : ''\n return join(dataDir, 'deps', `${name}${ext}`)\n}\n\n/** Check if a binary exists in PATH */\nexport function findInPath(name: string): string | null {\n try {\n execFileSync(name, ['--version'], { stdio: 'pipe', timeout: 5000 })\n return name\n } catch {\n return null\n }\n}\n\nexport interface DownloadOptions {\n readonly name: string\n readonly url: string\n readonly targetDir: string\n readonly targetName: string\n readonly logger: IScopedLogger\n readonly isArchive?: boolean\n readonly archiveFormat?: 'zip' | 'tar.gz' | 'tar.xz'\n /** Relative path within archive to the binary (e.g., 'ffmpeg-6.1/bin/ffmpeg') */\n readonly archiveInnerPath?: string\n}\n\n/**\n * Download a binary to the target directory.\n * Handles archives (zip, tar.gz, tar.xz) and raw binaries.\n */\nexport async function downloadBinary(opts: DownloadOptions): Promise<string> {\n const { name, url, targetDir, targetName, logger, isArchive, archiveFormat, archiveInnerPath } = opts\n const targetPath = join(targetDir, targetName)\n\n if (existsSync(targetPath)) {\n logger.debug('Binary already exists', { meta: { name, targetPath } })\n return targetPath\n }\n\n mkdirSync(targetDir, { recursive: true })\n\n logger.info('Downloading binary', { meta: { name, url } })\n const response = await fetch(url, { redirect: 'follow' })\n if (!response.ok || !response.body) {\n throw new Error(`Failed to download ${name}: ${response.status} ${response.statusText}`)\n }\n\n if (isArchive) {\n const ext = archiveFormat ?? 'tar.gz'\n const tmpArchive = join(targetDir, `${name}-download.${ext}`)\n const nodeStream = Readable.fromWeb(response.body as ReadableStream)\n await pipeline(nodeStream, createWriteStream(tmpArchive))\n\n // Extract\n const tmpExtractDir = join(targetDir, `${name}-extract`)\n mkdirSync(tmpExtractDir, { recursive: true })\n\n if (ext === 'zip') {\n try {\n execFileSync('unzip', ['-o', '-q', tmpArchive, '-d', tmpExtractDir], { stdio: 'pipe' })\n } catch {\n execFileSync('tar', ['-xf', tmpArchive, '-C', tmpExtractDir], { stdio: 'pipe' })\n }\n } else if (ext === 'tar.xz') {\n execFileSync('tar', ['-xJf', tmpArchive, '-C', tmpExtractDir], { stdio: 'pipe' })\n } else {\n execFileSync('tar', ['-xzf', tmpArchive, '-C', tmpExtractDir], { stdio: 'pipe' })\n }\n\n // Copy binary from archive\n if (archiveInnerPath) {\n const { copyFileSync } = await import('node:fs')\n const sourcePath = join(tmpExtractDir, archiveInnerPath)\n if (!existsSync(sourcePath)) {\n throw new Error(`Binary not found in archive at ${archiveInnerPath}`)\n }\n copyFileSync(sourcePath, targetPath)\n }\n\n // Cleanup\n unlinkSync(tmpArchive)\n const { rmSync } = await import('node:fs')\n rmSync(tmpExtractDir, { recursive: true, force: true })\n } else {\n // Direct binary download\n const nodeStream = Readable.fromWeb(response.body as ReadableStream)\n await pipeline(nodeStream, createWriteStream(targetPath))\n }\n\n chmodSync(targetPath, 0o755)\n logger.info('Binary downloaded', { meta: { name, targetPath } })\n return targetPath\n}\n\n/**\n * Ensure a binary is available. Checks:\n * 1. Target path (already downloaded)\n * 2. System PATH\n * 3. Download from URL\n */\nexport async function ensureBinary(opts: {\n readonly name: string\n readonly targetDir: string\n readonly downloadUrl: string\n readonly logger: IScopedLogger\n readonly isArchive?: boolean\n readonly archiveFormat?: 'zip' | 'tar.gz' | 'tar.xz'\n readonly archiveInnerPath?: string\n}): Promise<string> {\n const ext = process.platform === 'win32' ? '.exe' : ''\n const targetName = `${opts.name}${ext}`\n const targetPath = join(opts.targetDir, targetName)\n\n // 1. Already downloaded\n if (existsSync(targetPath)) {\n opts.logger.debug('Binary found at target path', { meta: { name: opts.name, targetPath } })\n return targetPath\n }\n\n // 2. System PATH\n const inPath = findInPath(opts.name)\n if (inPath) {\n opts.logger.info('Binary found in system PATH', { meta: { name: opts.name } })\n return inPath\n }\n\n // 3. Download\n return downloadBinary({\n name: opts.name,\n url: opts.downloadUrl,\n targetDir: opts.targetDir,\n targetName,\n logger: opts.logger,\n isArchive: opts.isArchive,\n archiveFormat: opts.archiveFormat,\n archiveInnerPath: opts.archiveInnerPath,\n })\n}\n","/**\n * Download ffmpeg static build for the current platform.\n *\n * Sources:\n * - Linux: https://johnvansickle.com/ffmpeg/ (static builds)\n * - macOS: https://evermeet.cx/ffmpeg/ or homebrew\n *\n * Using BtbN's GitHub releases as they cover both platforms:\n * https://github.com/BtbN/FFmpeg-Builds/releases\n */\nimport { join } from 'node:path'\nimport type { IScopedLogger } from '../index.js'\nimport { ensureBinary } from './binary-downloader.js'\n\nconst FFMPEG_VERSION = '7.1'\n\nexport function getFfmpegDownloadUrl(platform: string, arch: string): string {\n switch (platform) {\n case 'linux': {\n const archMap: Record<string, string> = { x64: 'amd64', arm64: 'arm64' }\n const a = archMap[arch]\n if (!a) throw new Error(`Unsupported Linux architecture: ${arch}`)\n // John Van Sickle static builds — well-tested, widely used\n return `https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-${a}-static.tar.xz`\n }\n case 'darwin': {\n const archMap: Record<string, string> = { arm64: 'arm64', x64: 'amd64' }\n const a = archMap[arch]\n if (!a) throw new Error(`Unsupported macOS architecture: ${arch}`)\n // macOS static builds from osxexperts (maintained, universal builds)\n return `https://www.osxexperts.net/ffmpeg${FFMPEG_VERSION.replace('.', '')}arm.zip`\n }\n default:\n throw new Error(`Unsupported platform: ${platform}`)\n }\n}\n\nexport function getFfmpegArchiveInfo(platform: string): {\n isArchive: boolean\n archiveFormat: 'zip' | 'tar.gz' | 'tar.xz'\n archiveInnerPath: string\n} {\n switch (platform) {\n case 'linux':\n return {\n isArchive: true,\n archiveFormat: 'tar.xz',\n archiveInnerPath: `ffmpeg-${FFMPEG_VERSION}-amd64-static/ffmpeg`,\n }\n case 'darwin':\n return {\n isArchive: true,\n archiveFormat: 'zip',\n archiveInnerPath: 'ffmpeg',\n }\n default:\n throw new Error(`Unsupported platform: ${platform}`)\n }\n}\n\n/**\n * Ensure ffmpeg binary is available.\n * Checks: deps dir → system PATH → download.\n */\nexport async function ensureFfmpeg(dataDir: string, logger: IScopedLogger): Promise<string> {\n const depsDir = join(dataDir, 'deps')\n const platform = process.platform\n const arch = process.arch\n\n const archiveInfo = getFfmpegArchiveInfo(platform)\n\n return ensureBinary({\n name: 'ffmpeg',\n targetDir: depsDir,\n downloadUrl: getFfmpegDownloadUrl(platform, arch),\n logger,\n ...archiveInfo,\n })\n}\n","/**\n * Download portable Python (headless) from bjia56/portable-python.\n *\n * Source: https://github.com/bjia56/portable-python\n *\n * Advantages over python-build-standalone:\n * - macOS universal2 binary (arm64+x86_64 in one)\n * - Lighter (~24-28MB headless zip)\n * - glibc 2.17 minimum (better compat)\n * - Headless variant excludes tkinter/UI (ideal for ML inference)\n *\n * The zip's top-level dir is platform-specific (e.g.\n * `python-headless-3.12.12-darwin-universal2/`); after extraction\n * we rename it to a stable `python/` so consumers can rely on\n * `<dataDir>/deps/python/bin/python3`.\n */\nimport { join, basename } from 'node:path'\nimport { existsSync, mkdirSync, chmodSync, readFileSync, writeFileSync, readdirSync, renameSync, rmSync } from 'node:fs'\nimport { execFileSync } from 'node:child_process'\nimport { createHash } from 'node:crypto'\nimport { pipeline } from 'node:stream/promises'\nimport { Readable } from 'node:stream'\nimport { createWriteStream } from 'node:fs'\nimport type { IScopedLogger } from '../index.js'\nimport { errMsg } from '../index.js'\n\nexport const PYTHON_VERSION = '3.12.12'\nconst PP_BASE = `https://github.com/bjia56/portable-python/releases/download/cpython-v${PYTHON_VERSION}-build.0`\n\nexport function getPythonDownloadUrl(platform: string, arch: string): string {\n switch (platform) {\n case 'linux': {\n const archMap: Record<string, string> = { x64: 'x86_64', arm64: 'aarch64' }\n const a = archMap[arch]\n if (!a) throw new Error(`Unsupported Linux architecture for Python: ${arch}`)\n return `${PP_BASE}/python-headless-${PYTHON_VERSION}-linux-${a}.zip`\n }\n case 'darwin': {\n // universal2 covers both arm64 and x86_64\n return `${PP_BASE}/python-headless-${PYTHON_VERSION}-darwin-universal2.zip`\n }\n default:\n throw new Error(`Unsupported platform for portable Python: ${platform}`)\n }\n}\n\n/**\n * Ensure the embedded portable Python is available.\n *\n * ALWAYS returns the path to the embedded interpreter under\n * `<dataDir>/deps/python/bin/python3` — downloads it on first call\n * and reuses it thereafter. The system PATH is intentionally NOT\n * consulted: addons rely on `installPythonRequirements()` to manage\n * deps inside the embedded site-packages, and a system interpreter\n * (different version, missing modules) silently breaks that contract.\n *\n * Returns null only if the download/extract step fails.\n */\nexport async function ensurePython(dataDir: string, logger: IScopedLogger): Promise<string | null> {\n const pythonDir = join(dataDir, 'deps', 'python')\n const pythonBin = join(pythonDir, 'bin', 'python3')\n\n // 1. Already downloaded\n if (existsSync(pythonBin)) {\n logger.debug('Portable Python found', { meta: { pythonBin } })\n return pythonBin\n }\n\n // 2. Download portable python (no system PATH fallback — by design)\n logger.info('Downloading portable Python (headless)', { meta: { version: PYTHON_VERSION } })\n\n const depsDir = join(dataDir, 'deps')\n mkdirSync(depsDir, { recursive: true })\n\n const url = getPythonDownloadUrl(process.platform, process.arch)\n const tmpArchive = join(depsDir, 'python-download.zip')\n\n logger.info('Python download source', { meta: { url } })\n\n const response = await fetch(url, { redirect: 'follow' })\n if (!response.ok || !response.body) {\n logger.warn('Failed to download Python — ML detection will not be available', { meta: { status: response.status } })\n return null\n }\n\n const nodeStream = Readable.fromWeb(response.body as ReadableStream)\n await pipeline(nodeStream, createWriteStream(tmpArchive))\n\n // Extract — zip's top-level dir is e.g. `python-headless-3.12.12-darwin-universal2/`\n // (varies per platform/arch).\n try {\n execFileSync('unzip', ['-o', '-q', tmpArchive, '-d', depsDir], { stdio: 'pipe' })\n } catch {\n // Fallback: some minimal Linux installs don't have unzip\n execFileSync('python3', ['-m', 'zipfile', '-e', tmpArchive, depsDir], { stdio: 'pipe' })\n }\n\n // Cleanup the archive\n const { unlinkSync } = await import('node:fs')\n unlinkSync(tmpArchive)\n\n // Locate the extracted directory and normalize it to `<depsDir>/python/`.\n // The zip's top-level name varies by platform (e.g.\n // `python-headless-3.12.12-darwin-universal2/`), so we look for any\n // `python-*` subdir that contains the expected `bin/python3` and rename it.\n if (!existsSync(pythonBin)) {\n const candidates = readdirSync(depsDir).filter((name) =>\n name.startsWith('python-') &&\n existsSync(join(depsDir, name, 'bin', 'python3')),\n )\n if (candidates.length === 0) {\n logger.warn('Python extraction succeeded but no python3 binary found in any subdir', {\n meta: { depsDir },\n })\n return null\n }\n const extractedRoot = join(depsDir, candidates[0]!)\n // Drop any stale `python/` (e.g. from a previous failed install)\n // before renaming so the move always succeeds.\n if (existsSync(pythonDir)) {\n rmSync(pythonDir, { recursive: true, force: true })\n }\n renameSync(extractedRoot, pythonDir)\n }\n\n if (!existsSync(pythonBin)) {\n logger.warn('Python extraction succeeded but binary not found at expected path', {\n meta: { pythonBin },\n })\n return null\n }\n\n chmodSync(pythonBin, 0o755)\n\n // On macOS the bjia56 build is universal2 — the host arch is decided\n // at spawn time based on the parent process. That makes pip wheels\n // and runtime spawns silently disagree when the server is launched\n // from a Rosetta shell once and a native shell next time (e.g. pip\n // installs `numpy x86_64`, then the next boot under arm64 fails with\n // `incompatible architecture`). Lock the slice deterministically by\n // wrapping `python3` in a shell stub that always invokes the matching\n // host arch via `/usr/bin/arch`. Idempotent: detected via the renamed\n // `.real` binary.\n if (process.platform === 'darwin') {\n const realBin = join(pythonDir, 'bin', 'python3.real')\n if (!existsSync(realBin)) {\n renameSync(pythonBin, realBin)\n const archFlag = process.arch === 'arm64' ? '-arm64' : '-x86_64'\n writeFileSync(\n pythonBin,\n `#!/bin/sh\\nexec /usr/bin/arch ${archFlag} \"${realBin}\" \"$@\"\\n`,\n )\n chmodSync(pythonBin, 0o755)\n // Mirror the same wrapping for the `python` symlink so consumers\n // that use the un-versioned name also lock the arch.\n const pyAlt = join(pythonDir, 'bin', 'python')\n if (existsSync(pyAlt)) {\n try {\n rmSync(pyAlt, { force: true })\n } catch {\n // ignore\n }\n writeFileSync(\n pyAlt,\n `#!/bin/sh\\nexec /usr/bin/arch ${archFlag} \"${realBin}\" \"$@\"\\n`,\n )\n chmodSync(pyAlt, 0o755)\n }\n logger.info('Locked python3 to host arch via shell stub', {\n meta: { archFlag, realBin },\n })\n }\n }\n\n logger.info('Portable Python installed', { meta: { version: PYTHON_VERSION, pythonBin } })\n return pythonBin\n}\n\n/**\n * Install Python packages into the portable Python environment.\n */\nexport async function installPythonPackages(\n pythonPath: string,\n packages: readonly string[],\n logger: IScopedLogger,\n): Promise<void> {\n if (packages.length === 0) return\n\n logger.info('Installing Python packages', { meta: { packages } })\n try {\n execFileSync(pythonPath, ['-m', 'pip', 'install', '--quiet', ...packages], {\n stdio: 'pipe',\n timeout: 300_000, // 5 minutes for large packages like torch\n })\n logger.info('Python packages installed successfully')\n } catch (err) {\n logger.error('Failed to install Python packages', { meta: { error: errMsg(err) } })\n throw err\n }\n}\n\n/**\n * Install a pip requirements file into the embedded Python.\n *\n * Idempotent: keyed on (requirements file basename + sha256 of its\n * contents). The marker is written under\n * `<python-install-dir>/.requirements-installed/` so it lives and\n * dies with the python install — re-downloading python wipes both\n * the site-packages and the markers, forcing a fresh re-install.\n *\n * The marker is updated only after `pip install` succeeds. A failed\n * install never writes a marker, so the next call retries.\n */\nexport async function installPythonRequirements(\n pythonPath: string,\n requirementsFile: string,\n logger: IScopedLogger,\n): Promise<void> {\n if (!existsSync(requirementsFile)) {\n throw new Error(`Requirements file not found: ${requirementsFile}`)\n }\n\n const contents = readFileSync(requirementsFile)\n const hash = createHash('sha256').update(contents).digest('hex').slice(0, 16)\n const fileBase = basename(requirementsFile).replace(/\\.txt$/i, '')\n\n // Markers live under the python install dir → wiped together when\n // the embedded interpreter is re-downloaded.\n const pythonRoot = join(pythonPath, '..', '..') // <root>/bin/python3 → <root>\n const markerDir = join(pythonRoot, '.requirements-installed')\n const markerPath = join(markerDir, `${fileBase}-${hash}.marker`)\n\n if (existsSync(markerPath)) {\n logger.debug('Python requirements already installed', { meta: { requirementsFile, hash } })\n return\n }\n\n logger.info('Installing Python requirements', { meta: { requirementsFile, hash } })\n try {\n execFileSync(\n pythonPath,\n ['-m', 'pip', 'install', '--quiet', '--disable-pip-version-check', '-r', requirementsFile],\n {\n stdio: 'pipe',\n timeout: 600_000, // 10 minutes — coremltools + tensorflow can be slow\n },\n )\n } catch (err) {\n logger.error('Failed to install Python requirements', {\n meta: { requirementsFile, error: errMsg(err) },\n })\n throw err\n }\n\n mkdirSync(markerDir, { recursive: true })\n writeFileSync(markerPath, `${requirementsFile}\\n${new Date().toISOString()}\\n`)\n logger.info('Python requirements installed', { meta: { requirementsFile, hash } })\n}\n","import * as fs from 'node:fs'\nimport * as path from 'node:path'\nimport type {\n IStorageProvider,\n StorageLocationType,\n StorageResolveInput,\n StorageWriteInput,\n StorageReadInput,\n StorageExistsInput,\n StorageListInput,\n StorageDeleteInput,\n StorageAvailableSpaceInput,\n} from '../index.js'\n\n// Inline constants to avoid runtime dependency on @camstack/types\n// (types is external in tsup bundle, may not be resolvable from data/addons/)\nconst STORAGE_LOCATION_TYPES: readonly StorageLocationType[] = [\n 'data', 'media', 'recordings',\n 'recordings-high', 'recordings-low', 'recordings-clips', 'event-images',\n 'models', 'addons-data', 'cache', 'logs', 'backups',\n]\n\nconst DEFAULT_LOCATION_SUBDIRS: Readonly<Record<StorageLocationType, string>> = {\n 'data': 'db',\n 'media': 'media',\n 'recordings': 'recordings',\n 'recordings-high': 'recordings-high',\n 'recordings-low': 'recordings-low',\n 'recordings-clips': 'recordings-clips',\n 'event-images': 'event-images',\n 'models': 'models',\n 'addons-data': 'addons-data',\n 'cache': '/tmp/camstack-cache',\n 'logs': 'logs',\n 'backups': 'backups',\n}\n\n/**\n * Filesystem storage provider — serves all location types from a local directory tree.\n *\n * Default layout:\n * {rootPath}/recordings-high/\n * {rootPath}/recordings-low/\n * {rootPath}/recordings-clips/\n * {rootPath}/event-images/\n * {rootPath}/models/\n * {rootPath}/addons-data/\n * {rootPath}/logs/\n * /tmp/camstack-cache/ (cache is always local)\n *\n * Individual location paths can be overridden.\n */\nexport class FilesystemStorageProvider implements IStorageProvider {\n readonly id = 'local'\n readonly name = 'Local Filesystem'\n readonly supportedLocations: readonly StorageLocationType[] = [...STORAGE_LOCATION_TYPES]\n\n private readonly rootPath: string\n private readonly locationPaths: Map<StorageLocationType, string>\n\n constructor(rootPath: string, overrides?: Partial<Record<StorageLocationType, string>>) {\n this.rootPath = path.resolve(rootPath)\n this.locationPaths = new Map()\n\n for (const loc of STORAGE_LOCATION_TYPES) {\n const override = overrides?.[loc]\n if (override) {\n this.locationPaths.set(loc, path.resolve(override))\n } else {\n const subdir = DEFAULT_LOCATION_SUBDIRS[loc]\n // Absolute paths (like /tmp/camstack-cache) are used as-is\n this.locationPaths.set(\n loc,\n path.isAbsolute(subdir) ? subdir : path.join(this.rootPath, subdir),\n )\n }\n }\n }\n\n async resolve({ location, relativePath }: StorageResolveInput): Promise<string> {\n const base = this.locationPaths.get(location)\n if (!base) throw new Error(`Unknown storage location: ${location}`)\n return path.join(base, relativePath)\n }\n\n async write({ location, relativePath, data }: StorageWriteInput): Promise<void> {\n const filePath = await this.resolve({ location, relativePath })\n await fs.promises.mkdir(path.dirname(filePath), { recursive: true })\n\n if (Buffer.isBuffer(data)) {\n await fs.promises.writeFile(filePath, data)\n } else {\n // Stream\n const writeStream = fs.createWriteStream(filePath)\n await new Promise<void>((resolve, reject) => {\n (data as NodeJS.ReadableStream).pipe(writeStream)\n writeStream.on('finish', resolve)\n writeStream.on('error', reject)\n })\n }\n }\n\n async read({ location, relativePath }: StorageReadInput): Promise<Buffer> {\n return fs.promises.readFile(await this.resolve({ location, relativePath }))\n }\n\n async exists({ location, relativePath }: StorageExistsInput): Promise<boolean> {\n try {\n await fs.promises.access(await this.resolve({ location, relativePath }))\n return true\n } catch {\n return false\n }\n }\n\n async list({ location, prefix }: StorageListInput): Promise<readonly string[]> {\n const base = this.locationPaths.get(location)\n if (!base) return []\n const dir = prefix ? path.join(base, prefix) : base\n try {\n const entries = await fs.promises.readdir(dir, { withFileTypes: true })\n return entries.map(e => (prefix ? `${prefix}/${e.name}` : e.name))\n } catch {\n return []\n }\n }\n\n async delete({ location, relativePath }: StorageDeleteInput): Promise<void> {\n const filePath = await this.resolve({ location, relativePath })\n await fs.promises.rm(filePath, { force: true })\n }\n\n async getAvailableSpace({ location }: StorageAvailableSpaceInput): Promise<number | null> {\n const base = this.locationPaths.get(location)\n if (!base) return null\n // If the directory doesn't exist yet (lazy creation), walk up to\n // the nearest existing ancestor so statfs can still report free\n // space on the mount point. This keeps the storage dashboard\n // working on a fresh install where no file has been written yet.\n try {\n let target = base\n while (!fs.existsSync(target)) {\n const parent = path.dirname(target)\n if (!parent || parent === target) return null\n target = parent\n }\n const stats = await fs.promises.statfs(target)\n return stats.bavail * stats.bsize\n } catch {\n return null\n }\n }\n\n\n /** Get the resolved path for a location type */\n getLocationPath(location: StorageLocationType): string {\n const p = this.locationPaths.get(location)\n if (!p) throw new Error(`Unknown storage location: ${location}`)\n return p\n }\n\n /** Get the root path */\n getRootPath(): string {\n return this.rootPath\n }\n}\n\nexport default FilesystemStorageProvider\n"],"names":["join","execFileSync","existsSync","mkdirSync","Readable","pipeline","createWriteStream","unlinkSync","chmodSync","readdirSync","rmSync","renameSync","writeFileSync","errMsg","readFileSync","createHash","basename","path","fs"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAYO,SAAS,kBAAgC;AAC9C,SAAO;AAAA,IACL,UAAU,QAAQ;AAAA,IAClB,MAAM,QAAQ;AAAA,EAAA;AAElB;AAEO,SAAS,gBAAgB,SAAiB,MAAc,UAA2B;AACxF,QAAM,OAAO,YAAY,QAAQ,cAAc,UAAU,SAAS;AAClE,SAAOA,KAAAA,KAA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/node.mjs CHANGED
@@ -6,7 +6,7 @@ import { pipeline } from "node:stream/promises";
6
6
  import { Readable } from "node:stream";
7
7
  import { execFileSync } from "node:child_process";
8
8
  import { createHash } from "node:crypto";
9
- import { e as errMsg } from "./index-BKnvgAep.mjs";
9
+ import { e as errMsg } from "./index-YnRVILXN.mjs";
10
10
  import "zod";
11
11
  function getPlatformInfo() {
12
12
  return {
@@ -353,13 +353,13 @@ class FilesystemStorageProvider {
353
353
  }
354
354
  }
355
355
  }
356
- resolve({ location, relativePath }) {
356
+ async resolve({ location, relativePath }) {
357
357
  const base = this.locationPaths.get(location);
358
358
  if (!base) throw new Error(`Unknown storage location: ${location}`);
359
359
  return path.join(base, relativePath);
360
360
  }
361
361
  async write({ location, relativePath, data }) {
362
- const filePath = this.resolve({ location, relativePath });
362
+ const filePath = await this.resolve({ location, relativePath });
363
363
  await fs.promises.mkdir(path.dirname(filePath), { recursive: true });
364
364
  if (Buffer.isBuffer(data)) {
365
365
  await fs.promises.writeFile(filePath, data);
@@ -373,11 +373,11 @@ class FilesystemStorageProvider {
373
373
  }
374
374
  }
375
375
  async read({ location, relativePath }) {
376
- return fs.promises.readFile(this.resolve({ location, relativePath }));
376
+ return fs.promises.readFile(await this.resolve({ location, relativePath }));
377
377
  }
378
378
  async exists({ location, relativePath }) {
379
379
  try {
380
- await fs.promises.access(this.resolve({ location, relativePath }));
380
+ await fs.promises.access(await this.resolve({ location, relativePath }));
381
381
  return true;
382
382
  } catch {
383
383
  return false;
@@ -395,7 +395,7 @@ class FilesystemStorageProvider {
395
395
  }
396
396
  }
397
397
  async delete({ location, relativePath }) {
398
- const filePath = this.resolve({ location, relativePath });
398
+ const filePath = await this.resolve({ location, relativePath });
399
399
  await fs.promises.rm(filePath, { force: true });
400
400
  }
401
401
  async getAvailableSpace({ location }) {
package/dist/node.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"node.mjs","sources":["../src/deps/binary-downloader.ts","../src/deps/ffmpeg-downloader.ts","../src/deps/python-downloader.ts","../src/storage/filesystem-storage-provider.ts"],"sourcesContent":["import { existsSync, mkdirSync, chmodSync, createWriteStream, unlinkSync } from 'node:fs'\nimport { join } from 'node:path'\nimport { pipeline } from 'node:stream/promises'\nimport { Readable } from 'node:stream'\nimport { execFileSync } from 'node:child_process'\nimport type { IScopedLogger } from '../index.js'\n\nexport interface PlatformInfo {\n readonly platform: NodeJS.Platform\n readonly arch: NodeJS.Architecture\n}\n\nexport function getPlatformInfo(): PlatformInfo {\n return {\n platform: process.platform,\n arch: process.arch,\n }\n}\n\nexport function buildBinaryPath(dataDir: string, name: string, platform?: string): string {\n const ext = (platform ?? process.platform) === 'win32' ? '.exe' : ''\n return join(dataDir, 'deps', `${name}${ext}`)\n}\n\n/** Check if a binary exists in PATH */\nexport function findInPath(name: string): string | null {\n try {\n execFileSync(name, ['--version'], { stdio: 'pipe', timeout: 5000 })\n return name\n } catch {\n return null\n }\n}\n\nexport interface DownloadOptions {\n readonly name: string\n readonly url: string\n readonly targetDir: string\n readonly targetName: string\n readonly logger: IScopedLogger\n readonly isArchive?: boolean\n readonly archiveFormat?: 'zip' | 'tar.gz' | 'tar.xz'\n /** Relative path within archive to the binary (e.g., 'ffmpeg-6.1/bin/ffmpeg') */\n readonly archiveInnerPath?: string\n}\n\n/**\n * Download a binary to the target directory.\n * Handles archives (zip, tar.gz, tar.xz) and raw binaries.\n */\nexport async function downloadBinary(opts: DownloadOptions): Promise<string> {\n const { name, url, targetDir, targetName, logger, isArchive, archiveFormat, archiveInnerPath } = opts\n const targetPath = join(targetDir, targetName)\n\n if (existsSync(targetPath)) {\n logger.debug('Binary already exists', { meta: { name, targetPath } })\n return targetPath\n }\n\n mkdirSync(targetDir, { recursive: true })\n\n logger.info('Downloading binary', { meta: { name, url } })\n const response = await fetch(url, { redirect: 'follow' })\n if (!response.ok || !response.body) {\n throw new Error(`Failed to download ${name}: ${response.status} ${response.statusText}`)\n }\n\n if (isArchive) {\n const ext = archiveFormat ?? 'tar.gz'\n const tmpArchive = join(targetDir, `${name}-download.${ext}`)\n const nodeStream = Readable.fromWeb(response.body as ReadableStream)\n await pipeline(nodeStream, createWriteStream(tmpArchive))\n\n // Extract\n const tmpExtractDir = join(targetDir, `${name}-extract`)\n mkdirSync(tmpExtractDir, { recursive: true })\n\n if (ext === 'zip') {\n try {\n execFileSync('unzip', ['-o', '-q', tmpArchive, '-d', tmpExtractDir], { stdio: 'pipe' })\n } catch {\n execFileSync('tar', ['-xf', tmpArchive, '-C', tmpExtractDir], { stdio: 'pipe' })\n }\n } else if (ext === 'tar.xz') {\n execFileSync('tar', ['-xJf', tmpArchive, '-C', tmpExtractDir], { stdio: 'pipe' })\n } else {\n execFileSync('tar', ['-xzf', tmpArchive, '-C', tmpExtractDir], { stdio: 'pipe' })\n }\n\n // Copy binary from archive\n if (archiveInnerPath) {\n const { copyFileSync } = await import('node:fs')\n const sourcePath = join(tmpExtractDir, archiveInnerPath)\n if (!existsSync(sourcePath)) {\n throw new Error(`Binary not found in archive at ${archiveInnerPath}`)\n }\n copyFileSync(sourcePath, targetPath)\n }\n\n // Cleanup\n unlinkSync(tmpArchive)\n const { rmSync } = await import('node:fs')\n rmSync(tmpExtractDir, { recursive: true, force: true })\n } else {\n // Direct binary download\n const nodeStream = Readable.fromWeb(response.body as ReadableStream)\n await pipeline(nodeStream, createWriteStream(targetPath))\n }\n\n chmodSync(targetPath, 0o755)\n logger.info('Binary downloaded', { meta: { name, targetPath } })\n return targetPath\n}\n\n/**\n * Ensure a binary is available. Checks:\n * 1. Target path (already downloaded)\n * 2. System PATH\n * 3. Download from URL\n */\nexport async function ensureBinary(opts: {\n readonly name: string\n readonly targetDir: string\n readonly downloadUrl: string\n readonly logger: IScopedLogger\n readonly isArchive?: boolean\n readonly archiveFormat?: 'zip' | 'tar.gz' | 'tar.xz'\n readonly archiveInnerPath?: string\n}): Promise<string> {\n const ext = process.platform === 'win32' ? '.exe' : ''\n const targetName = `${opts.name}${ext}`\n const targetPath = join(opts.targetDir, targetName)\n\n // 1. Already downloaded\n if (existsSync(targetPath)) {\n opts.logger.debug('Binary found at target path', { meta: { name: opts.name, targetPath } })\n return targetPath\n }\n\n // 2. System PATH\n const inPath = findInPath(opts.name)\n if (inPath) {\n opts.logger.info('Binary found in system PATH', { meta: { name: opts.name } })\n return inPath\n }\n\n // 3. Download\n return downloadBinary({\n name: opts.name,\n url: opts.downloadUrl,\n targetDir: opts.targetDir,\n targetName,\n logger: opts.logger,\n isArchive: opts.isArchive,\n archiveFormat: opts.archiveFormat,\n archiveInnerPath: opts.archiveInnerPath,\n })\n}\n","/**\n * Download ffmpeg static build for the current platform.\n *\n * Sources:\n * - Linux: https://johnvansickle.com/ffmpeg/ (static builds)\n * - macOS: https://evermeet.cx/ffmpeg/ or homebrew\n *\n * Using BtbN's GitHub releases as they cover both platforms:\n * https://github.com/BtbN/FFmpeg-Builds/releases\n */\nimport { join } from 'node:path'\nimport type { IScopedLogger } from '../index.js'\nimport { ensureBinary } from './binary-downloader.js'\n\nconst FFMPEG_VERSION = '7.1'\n\nexport function getFfmpegDownloadUrl(platform: string, arch: string): string {\n switch (platform) {\n case 'linux': {\n const archMap: Record<string, string> = { x64: 'amd64', arm64: 'arm64' }\n const a = archMap[arch]\n if (!a) throw new Error(`Unsupported Linux architecture: ${arch}`)\n // John Van Sickle static builds — well-tested, widely used\n return `https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-${a}-static.tar.xz`\n }\n case 'darwin': {\n const archMap: Record<string, string> = { arm64: 'arm64', x64: 'amd64' }\n const a = archMap[arch]\n if (!a) throw new Error(`Unsupported macOS architecture: ${arch}`)\n // macOS static builds from osxexperts (maintained, universal builds)\n return `https://www.osxexperts.net/ffmpeg${FFMPEG_VERSION.replace('.', '')}arm.zip`\n }\n default:\n throw new Error(`Unsupported platform: ${platform}`)\n }\n}\n\nexport function getFfmpegArchiveInfo(platform: string): {\n isArchive: boolean\n archiveFormat: 'zip' | 'tar.gz' | 'tar.xz'\n archiveInnerPath: string\n} {\n switch (platform) {\n case 'linux':\n return {\n isArchive: true,\n archiveFormat: 'tar.xz',\n archiveInnerPath: `ffmpeg-${FFMPEG_VERSION}-amd64-static/ffmpeg`,\n }\n case 'darwin':\n return {\n isArchive: true,\n archiveFormat: 'zip',\n archiveInnerPath: 'ffmpeg',\n }\n default:\n throw new Error(`Unsupported platform: ${platform}`)\n }\n}\n\n/**\n * Ensure ffmpeg binary is available.\n * Checks: deps dir → system PATH → download.\n */\nexport async function ensureFfmpeg(dataDir: string, logger: IScopedLogger): Promise<string> {\n const depsDir = join(dataDir, 'deps')\n const platform = process.platform\n const arch = process.arch\n\n const archiveInfo = getFfmpegArchiveInfo(platform)\n\n return ensureBinary({\n name: 'ffmpeg',\n targetDir: depsDir,\n downloadUrl: getFfmpegDownloadUrl(platform, arch),\n logger,\n ...archiveInfo,\n })\n}\n","/**\n * Download portable Python (headless) from bjia56/portable-python.\n *\n * Source: https://github.com/bjia56/portable-python\n *\n * Advantages over python-build-standalone:\n * - macOS universal2 binary (arm64+x86_64 in one)\n * - Lighter (~24-28MB headless zip)\n * - glibc 2.17 minimum (better compat)\n * - Headless variant excludes tkinter/UI (ideal for ML inference)\n *\n * The zip's top-level dir is platform-specific (e.g.\n * `python-headless-3.12.12-darwin-universal2/`); after extraction\n * we rename it to a stable `python/` so consumers can rely on\n * `<dataDir>/deps/python/bin/python3`.\n */\nimport { join, basename } from 'node:path'\nimport { existsSync, mkdirSync, chmodSync, readFileSync, writeFileSync, readdirSync, renameSync, rmSync } from 'node:fs'\nimport { execFileSync } from 'node:child_process'\nimport { createHash } from 'node:crypto'\nimport { pipeline } from 'node:stream/promises'\nimport { Readable } from 'node:stream'\nimport { createWriteStream } from 'node:fs'\nimport type { IScopedLogger } from '../index.js'\nimport { errMsg } from '../index.js'\n\nexport const PYTHON_VERSION = '3.12.12'\nconst PP_BASE = `https://github.com/bjia56/portable-python/releases/download/cpython-v${PYTHON_VERSION}-build.0`\n\nexport function getPythonDownloadUrl(platform: string, arch: string): string {\n switch (platform) {\n case 'linux': {\n const archMap: Record<string, string> = { x64: 'x86_64', arm64: 'aarch64' }\n const a = archMap[arch]\n if (!a) throw new Error(`Unsupported Linux architecture for Python: ${arch}`)\n return `${PP_BASE}/python-headless-${PYTHON_VERSION}-linux-${a}.zip`\n }\n case 'darwin': {\n // universal2 covers both arm64 and x86_64\n return `${PP_BASE}/python-headless-${PYTHON_VERSION}-darwin-universal2.zip`\n }\n default:\n throw new Error(`Unsupported platform for portable Python: ${platform}`)\n }\n}\n\n/**\n * Ensure the embedded portable Python is available.\n *\n * ALWAYS returns the path to the embedded interpreter under\n * `<dataDir>/deps/python/bin/python3` — downloads it on first call\n * and reuses it thereafter. The system PATH is intentionally NOT\n * consulted: addons rely on `installPythonRequirements()` to manage\n * deps inside the embedded site-packages, and a system interpreter\n * (different version, missing modules) silently breaks that contract.\n *\n * Returns null only if the download/extract step fails.\n */\nexport async function ensurePython(dataDir: string, logger: IScopedLogger): Promise<string | null> {\n const pythonDir = join(dataDir, 'deps', 'python')\n const pythonBin = join(pythonDir, 'bin', 'python3')\n\n // 1. Already downloaded\n if (existsSync(pythonBin)) {\n logger.debug('Portable Python found', { meta: { pythonBin } })\n return pythonBin\n }\n\n // 2. Download portable python (no system PATH fallback — by design)\n logger.info('Downloading portable Python (headless)', { meta: { version: PYTHON_VERSION } })\n\n const depsDir = join(dataDir, 'deps')\n mkdirSync(depsDir, { recursive: true })\n\n const url = getPythonDownloadUrl(process.platform, process.arch)\n const tmpArchive = join(depsDir, 'python-download.zip')\n\n logger.info('Python download source', { meta: { url } })\n\n const response = await fetch(url, { redirect: 'follow' })\n if (!response.ok || !response.body) {\n logger.warn('Failed to download Python — ML detection will not be available', { meta: { status: response.status } })\n return null\n }\n\n const nodeStream = Readable.fromWeb(response.body as ReadableStream)\n await pipeline(nodeStream, createWriteStream(tmpArchive))\n\n // Extract — zip's top-level dir is e.g. `python-headless-3.12.12-darwin-universal2/`\n // (varies per platform/arch).\n try {\n execFileSync('unzip', ['-o', '-q', tmpArchive, '-d', depsDir], { stdio: 'pipe' })\n } catch {\n // Fallback: some minimal Linux installs don't have unzip\n execFileSync('python3', ['-m', 'zipfile', '-e', tmpArchive, depsDir], { stdio: 'pipe' })\n }\n\n // Cleanup the archive\n const { unlinkSync } = await import('node:fs')\n unlinkSync(tmpArchive)\n\n // Locate the extracted directory and normalize it to `<depsDir>/python/`.\n // The zip's top-level name varies by platform (e.g.\n // `python-headless-3.12.12-darwin-universal2/`), so we look for any\n // `python-*` subdir that contains the expected `bin/python3` and rename it.\n if (!existsSync(pythonBin)) {\n const candidates = readdirSync(depsDir).filter((name) =>\n name.startsWith('python-') &&\n existsSync(join(depsDir, name, 'bin', 'python3')),\n )\n if (candidates.length === 0) {\n logger.warn('Python extraction succeeded but no python3 binary found in any subdir', {\n meta: { depsDir },\n })\n return null\n }\n const extractedRoot = join(depsDir, candidates[0]!)\n // Drop any stale `python/` (e.g. from a previous failed install)\n // before renaming so the move always succeeds.\n if (existsSync(pythonDir)) {\n rmSync(pythonDir, { recursive: true, force: true })\n }\n renameSync(extractedRoot, pythonDir)\n }\n\n if (!existsSync(pythonBin)) {\n logger.warn('Python extraction succeeded but binary not found at expected path', {\n meta: { pythonBin },\n })\n return null\n }\n\n chmodSync(pythonBin, 0o755)\n\n // On macOS the bjia56 build is universal2 — the host arch is decided\n // at spawn time based on the parent process. That makes pip wheels\n // and runtime spawns silently disagree when the server is launched\n // from a Rosetta shell once and a native shell next time (e.g. pip\n // installs `numpy x86_64`, then the next boot under arm64 fails with\n // `incompatible architecture`). Lock the slice deterministically by\n // wrapping `python3` in a shell stub that always invokes the matching\n // host arch via `/usr/bin/arch`. Idempotent: detected via the renamed\n // `.real` binary.\n if (process.platform === 'darwin') {\n const realBin = join(pythonDir, 'bin', 'python3.real')\n if (!existsSync(realBin)) {\n renameSync(pythonBin, realBin)\n const archFlag = process.arch === 'arm64' ? '-arm64' : '-x86_64'\n writeFileSync(\n pythonBin,\n `#!/bin/sh\\nexec /usr/bin/arch ${archFlag} \"${realBin}\" \"$@\"\\n`,\n )\n chmodSync(pythonBin, 0o755)\n // Mirror the same wrapping for the `python` symlink so consumers\n // that use the un-versioned name also lock the arch.\n const pyAlt = join(pythonDir, 'bin', 'python')\n if (existsSync(pyAlt)) {\n try {\n rmSync(pyAlt, { force: true })\n } catch {\n // ignore\n }\n writeFileSync(\n pyAlt,\n `#!/bin/sh\\nexec /usr/bin/arch ${archFlag} \"${realBin}\" \"$@\"\\n`,\n )\n chmodSync(pyAlt, 0o755)\n }\n logger.info('Locked python3 to host arch via shell stub', {\n meta: { archFlag, realBin },\n })\n }\n }\n\n logger.info('Portable Python installed', { meta: { version: PYTHON_VERSION, pythonBin } })\n return pythonBin\n}\n\n/**\n * Install Python packages into the portable Python environment.\n */\nexport async function installPythonPackages(\n pythonPath: string,\n packages: readonly string[],\n logger: IScopedLogger,\n): Promise<void> {\n if (packages.length === 0) return\n\n logger.info('Installing Python packages', { meta: { packages } })\n try {\n execFileSync(pythonPath, ['-m', 'pip', 'install', '--quiet', ...packages], {\n stdio: 'pipe',\n timeout: 300_000, // 5 minutes for large packages like torch\n })\n logger.info('Python packages installed successfully')\n } catch (err) {\n logger.error('Failed to install Python packages', { meta: { error: errMsg(err) } })\n throw err\n }\n}\n\n/**\n * Install a pip requirements file into the embedded Python.\n *\n * Idempotent: keyed on (requirements file basename + sha256 of its\n * contents). The marker is written under\n * `<python-install-dir>/.requirements-installed/` so it lives and\n * dies with the python install — re-downloading python wipes both\n * the site-packages and the markers, forcing a fresh re-install.\n *\n * The marker is updated only after `pip install` succeeds. A failed\n * install never writes a marker, so the next call retries.\n */\nexport async function installPythonRequirements(\n pythonPath: string,\n requirementsFile: string,\n logger: IScopedLogger,\n): Promise<void> {\n if (!existsSync(requirementsFile)) {\n throw new Error(`Requirements file not found: ${requirementsFile}`)\n }\n\n const contents = readFileSync(requirementsFile)\n const hash = createHash('sha256').update(contents).digest('hex').slice(0, 16)\n const fileBase = basename(requirementsFile).replace(/\\.txt$/i, '')\n\n // Markers live under the python install dir → wiped together when\n // the embedded interpreter is re-downloaded.\n const pythonRoot = join(pythonPath, '..', '..') // <root>/bin/python3 → <root>\n const markerDir = join(pythonRoot, '.requirements-installed')\n const markerPath = join(markerDir, `${fileBase}-${hash}.marker`)\n\n if (existsSync(markerPath)) {\n logger.debug('Python requirements already installed', { meta: { requirementsFile, hash } })\n return\n }\n\n logger.info('Installing Python requirements', { meta: { requirementsFile, hash } })\n try {\n execFileSync(\n pythonPath,\n ['-m', 'pip', 'install', '--quiet', '--disable-pip-version-check', '-r', requirementsFile],\n {\n stdio: 'pipe',\n timeout: 600_000, // 10 minutes — coremltools + tensorflow can be slow\n },\n )\n } catch (err) {\n logger.error('Failed to install Python requirements', {\n meta: { requirementsFile, error: errMsg(err) },\n })\n throw err\n }\n\n mkdirSync(markerDir, { recursive: true })\n writeFileSync(markerPath, `${requirementsFile}\\n${new Date().toISOString()}\\n`)\n logger.info('Python requirements installed', { meta: { requirementsFile, hash } })\n}\n","import * as fs from 'node:fs'\nimport * as path from 'node:path'\nimport type {\n IStorageProvider,\n StorageLocationType,\n StorageResolveInput,\n StorageWriteInput,\n StorageReadInput,\n StorageExistsInput,\n StorageListInput,\n StorageDeleteInput,\n StorageAvailableSpaceInput,\n} from '../index.js'\n\n// Inline constants to avoid runtime dependency on @camstack/types\n// (types is external in tsup bundle, may not be resolvable from data/addons/)\nconst STORAGE_LOCATION_TYPES: readonly StorageLocationType[] = [\n 'data', 'media', 'recordings',\n 'recordings-high', 'recordings-low', 'recordings-clips', 'event-images',\n 'models', 'addons-data', 'cache', 'logs', 'backups',\n]\n\nconst DEFAULT_LOCATION_SUBDIRS: Readonly<Record<StorageLocationType, string>> = {\n 'data': 'db',\n 'media': 'media',\n 'recordings': 'recordings',\n 'recordings-high': 'recordings-high',\n 'recordings-low': 'recordings-low',\n 'recordings-clips': 'recordings-clips',\n 'event-images': 'event-images',\n 'models': 'models',\n 'addons-data': 'addons-data',\n 'cache': '/tmp/camstack-cache',\n 'logs': 'logs',\n 'backups': 'backups',\n}\n\n/**\n * Filesystem storage provider — serves all location types from a local directory tree.\n *\n * Default layout:\n * {rootPath}/recordings-high/\n * {rootPath}/recordings-low/\n * {rootPath}/recordings-clips/\n * {rootPath}/event-images/\n * {rootPath}/models/\n * {rootPath}/addons-data/\n * {rootPath}/logs/\n * /tmp/camstack-cache/ (cache is always local)\n *\n * Individual location paths can be overridden.\n */\nexport class FilesystemStorageProvider implements IStorageProvider {\n readonly id = 'local'\n readonly name = 'Local Filesystem'\n readonly supportedLocations: readonly StorageLocationType[] = [...STORAGE_LOCATION_TYPES]\n\n private readonly rootPath: string\n private readonly locationPaths: Map<StorageLocationType, string>\n\n constructor(rootPath: string, overrides?: Partial<Record<StorageLocationType, string>>) {\n this.rootPath = path.resolve(rootPath)\n this.locationPaths = new Map()\n\n for (const loc of STORAGE_LOCATION_TYPES) {\n const override = overrides?.[loc]\n if (override) {\n this.locationPaths.set(loc, path.resolve(override))\n } else {\n const subdir = DEFAULT_LOCATION_SUBDIRS[loc]\n // Absolute paths (like /tmp/camstack-cache) are used as-is\n this.locationPaths.set(\n loc,\n path.isAbsolute(subdir) ? subdir : path.join(this.rootPath, subdir),\n )\n }\n }\n }\n\n resolve({ location, relativePath }: StorageResolveInput): string {\n const base = this.locationPaths.get(location)\n if (!base) throw new Error(`Unknown storage location: ${location}`)\n return path.join(base, relativePath)\n }\n\n async write({ location, relativePath, data }: StorageWriteInput): Promise<void> {\n const filePath = this.resolve({ location, relativePath })\n await fs.promises.mkdir(path.dirname(filePath), { recursive: true })\n\n if (Buffer.isBuffer(data)) {\n await fs.promises.writeFile(filePath, data)\n } else {\n // Stream\n const writeStream = fs.createWriteStream(filePath)\n await new Promise<void>((resolve, reject) => {\n (data as NodeJS.ReadableStream).pipe(writeStream)\n writeStream.on('finish', resolve)\n writeStream.on('error', reject)\n })\n }\n }\n\n async read({ location, relativePath }: StorageReadInput): Promise<Buffer> {\n return fs.promises.readFile(this.resolve({ location, relativePath }))\n }\n\n async exists({ location, relativePath }: StorageExistsInput): Promise<boolean> {\n try {\n await fs.promises.access(this.resolve({ location, relativePath }))\n return true\n } catch {\n return false\n }\n }\n\n async list({ location, prefix }: StorageListInput): Promise<readonly string[]> {\n const base = this.locationPaths.get(location)\n if (!base) return []\n const dir = prefix ? path.join(base, prefix) : base\n try {\n const entries = await fs.promises.readdir(dir, { withFileTypes: true })\n return entries.map(e => (prefix ? `${prefix}/${e.name}` : e.name))\n } catch {\n return []\n }\n }\n\n async delete({ location, relativePath }: StorageDeleteInput): Promise<void> {\n const filePath = this.resolve({ location, relativePath })\n await fs.promises.rm(filePath, { force: true })\n }\n\n async getAvailableSpace({ location }: StorageAvailableSpaceInput): Promise<number | null> {\n const base = this.locationPaths.get(location)\n if (!base) return null\n // If the directory doesn't exist yet (lazy creation), walk up to\n // the nearest existing ancestor so statfs can still report free\n // space on the mount point. This keeps the storage dashboard\n // working on a fresh install where no file has been written yet.\n try {\n let target = base\n while (!fs.existsSync(target)) {\n const parent = path.dirname(target)\n if (!parent || parent === target) return null\n target = parent\n }\n const stats = await fs.promises.statfs(target)\n return stats.bavail * stats.bsize\n } catch {\n return null\n }\n }\n\n\n /** Get the resolved path for a location type */\n getLocationPath(location: StorageLocationType): string {\n const p = this.locationPaths.get(location)\n if (!p) throw new Error(`Unknown storage location: ${location}`)\n return p\n }\n\n /** Get the root path */\n getRootPath(): string {\n return this.rootPath\n }\n}\n\nexport default FilesystemStorageProvider\n"],"names":["rmSync","unlinkSync"],"mappings":";;;;;;;;;;AAYO,SAAS,kBAAgC;AAC9C,SAAO;AAAA,IACL,UAAU,QAAQ;AAAA,IAClB,MAAM,QAAQ;AAAA,EAAA;AAElB;AAEO,SAAS,gBAAgB,SAAiB,MAAc,UAA2B;AACxF,QAAM,OAAO,YAAY,QAAQ,cAAc,UAAU,SAAS;AAClE,SAAO,KAAK,SAAS,QAAQ,GAAG,IAAI,GAAG,GAAG,EAAE;AAC9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AE,YAAgE;AACxF,UAAM,OAAO,KAAK,cAAc,IAAI,QAAQ;AAC5C,QAAI,CAAC,KAAM,QAAO;AAKlB,QAAI;AACF,UAAI,SAAS;AACb,aAAO,CAAC,GAAG,WAAW,MAAM,GAAG;AAC7B,cAAM,SAAS,KAAK,QAAQ,MAAM;AAClC,YAAI,CAAC,UAAU,WAAW,OAAQ,QAAO;AACzC,iBAAS;AAAA,MACX;AACA,YAAM,QAAQ,MAAM,GAAG,SAAS,OAAO,MAAM;AAC7C,aAAO,MAAM,SAAS,MAAM;AAAA,IAC9B,QAAQ;AACN,aAAO;AAAA,IACT;AAAA,EACF;AAAA;AAAA,EAIA,gBAAgB,UAAuC;AACrD,UAAM,IAAI,KAAK,cAAc,IAAI,QAAQ;AACzC,QAAI,CAAC,EAAG,OAAM,IAAI,MAAM,6BAA6B,QAAQ,EAAE;AAC/D,WAAO;AAAA,EACT;AAAA;AAAA,EAGA,cAAsB;AACpB,WAAO,KAAK;AAAA,EACd;AACF;"}
1
+ {"version":3,"file":"node.mjs","sources":["../src/deps/binary-downloader.ts","../src/deps/ffmpeg-downloader.ts","../src/deps/python-downloader.ts","../src/storage/filesystem-storage-provider.ts"],"sourcesContent":["import { existsSync, mkdirSync, chmodSync, createWriteStream, unlinkSync } from 'node:fs'\nimport { join } from 'node:path'\nimport { pipeline } from 'node:stream/promises'\nimport { Readable } from 'node:stream'\nimport { execFileSync } from 'node:child_process'\nimport type { IScopedLogger } from '../index.js'\n\nexport interface PlatformInfo {\n readonly platform: NodeJS.Platform\n readonly arch: NodeJS.Architecture\n}\n\nexport function getPlatformInfo(): PlatformInfo {\n return {\n platform: process.platform,\n arch: process.arch,\n }\n}\n\nexport function buildBinaryPath(dataDir: string, name: string, platform?: string): string {\n const ext = (platform ?? process.platform) === 'win32' ? '.exe' : ''\n return join(dataDir, 'deps', `${name}${ext}`)\n}\n\n/** Check if a binary exists in PATH */\nexport function findInPath(name: string): string | null {\n try {\n execFileSync(name, ['--version'], { stdio: 'pipe', timeout: 5000 })\n return name\n } catch {\n return null\n }\n}\n\nexport interface DownloadOptions {\n readonly name: string\n readonly url: string\n readonly targetDir: string\n readonly targetName: string\n readonly logger: IScopedLogger\n readonly isArchive?: boolean\n readonly archiveFormat?: 'zip' | 'tar.gz' | 'tar.xz'\n /** Relative path within archive to the binary (e.g., 'ffmpeg-6.1/bin/ffmpeg') */\n readonly archiveInnerPath?: string\n}\n\n/**\n * Download a binary to the target directory.\n * Handles archives (zip, tar.gz, tar.xz) and raw binaries.\n */\nexport async function downloadBinary(opts: DownloadOptions): Promise<string> {\n const { name, url, targetDir, targetName, logger, isArchive, archiveFormat, archiveInnerPath } = opts\n const targetPath = join(targetDir, targetName)\n\n if (existsSync(targetPath)) {\n logger.debug('Binary already exists', { meta: { name, targetPath } })\n return targetPath\n }\n\n mkdirSync(targetDir, { recursive: true })\n\n logger.info('Downloading binary', { meta: { name, url } })\n const response = await fetch(url, { redirect: 'follow' })\n if (!response.ok || !response.body) {\n throw new Error(`Failed to download ${name}: ${response.status} ${response.statusText}`)\n }\n\n if (isArchive) {\n const ext = archiveFormat ?? 'tar.gz'\n const tmpArchive = join(targetDir, `${name}-download.${ext}`)\n const nodeStream = Readable.fromWeb(response.body as ReadableStream)\n await pipeline(nodeStream, createWriteStream(tmpArchive))\n\n // Extract\n const tmpExtractDir = join(targetDir, `${name}-extract`)\n mkdirSync(tmpExtractDir, { recursive: true })\n\n if (ext === 'zip') {\n try {\n execFileSync('unzip', ['-o', '-q', tmpArchive, '-d', tmpExtractDir], { stdio: 'pipe' })\n } catch {\n execFileSync('tar', ['-xf', tmpArchive, '-C', tmpExtractDir], { stdio: 'pipe' })\n }\n } else if (ext === 'tar.xz') {\n execFileSync('tar', ['-xJf', tmpArchive, '-C', tmpExtractDir], { stdio: 'pipe' })\n } else {\n execFileSync('tar', ['-xzf', tmpArchive, '-C', tmpExtractDir], { stdio: 'pipe' })\n }\n\n // Copy binary from archive\n if (archiveInnerPath) {\n const { copyFileSync } = await import('node:fs')\n const sourcePath = join(tmpExtractDir, archiveInnerPath)\n if (!existsSync(sourcePath)) {\n throw new Error(`Binary not found in archive at ${archiveInnerPath}`)\n }\n copyFileSync(sourcePath, targetPath)\n }\n\n // Cleanup\n unlinkSync(tmpArchive)\n const { rmSync } = await import('node:fs')\n rmSync(tmpExtractDir, { recursive: true, force: true })\n } else {\n // Direct binary download\n const nodeStream = Readable.fromWeb(response.body as ReadableStream)\n await pipeline(nodeStream, createWriteStream(targetPath))\n }\n\n chmodSync(targetPath, 0o755)\n logger.info('Binary downloaded', { meta: { name, targetPath } })\n return targetPath\n}\n\n/**\n * Ensure a binary is available. Checks:\n * 1. Target path (already downloaded)\n * 2. System PATH\n * 3. Download from URL\n */\nexport async function ensureBinary(opts: {\n readonly name: string\n readonly targetDir: string\n readonly downloadUrl: string\n readonly logger: IScopedLogger\n readonly isArchive?: boolean\n readonly archiveFormat?: 'zip' | 'tar.gz' | 'tar.xz'\n readonly archiveInnerPath?: string\n}): Promise<string> {\n const ext = process.platform === 'win32' ? '.exe' : ''\n const targetName = `${opts.name}${ext}`\n const targetPath = join(opts.targetDir, targetName)\n\n // 1. Already downloaded\n if (existsSync(targetPath)) {\n opts.logger.debug('Binary found at target path', { meta: { name: opts.name, targetPath } })\n return targetPath\n }\n\n // 2. System PATH\n const inPath = findInPath(opts.name)\n if (inPath) {\n opts.logger.info('Binary found in system PATH', { meta: { name: opts.name } })\n return inPath\n }\n\n // 3. Download\n return downloadBinary({\n name: opts.name,\n url: opts.downloadUrl,\n targetDir: opts.targetDir,\n targetName,\n logger: opts.logger,\n isArchive: opts.isArchive,\n archiveFormat: opts.archiveFormat,\n archiveInnerPath: opts.archiveInnerPath,\n })\n}\n","/**\n * Download ffmpeg static build for the current platform.\n *\n * Sources:\n * - Linux: https://johnvansickle.com/ffmpeg/ (static builds)\n * - macOS: https://evermeet.cx/ffmpeg/ or homebrew\n *\n * Using BtbN's GitHub releases as they cover both platforms:\n * https://github.com/BtbN/FFmpeg-Builds/releases\n */\nimport { join } from 'node:path'\nimport type { IScopedLogger } from '../index.js'\nimport { ensureBinary } from './binary-downloader.js'\n\nconst FFMPEG_VERSION = '7.1'\n\nexport function getFfmpegDownloadUrl(platform: string, arch: string): string {\n switch (platform) {\n case 'linux': {\n const archMap: Record<string, string> = { x64: 'amd64', arm64: 'arm64' }\n const a = archMap[arch]\n if (!a) throw new Error(`Unsupported Linux architecture: ${arch}`)\n // John Van Sickle static builds — well-tested, widely used\n return `https://johnvansickle.com/ffmpeg/releases/ffmpeg-release-${a}-static.tar.xz`\n }\n case 'darwin': {\n const archMap: Record<string, string> = { arm64: 'arm64', x64: 'amd64' }\n const a = archMap[arch]\n if (!a) throw new Error(`Unsupported macOS architecture: ${arch}`)\n // macOS static builds from osxexperts (maintained, universal builds)\n return `https://www.osxexperts.net/ffmpeg${FFMPEG_VERSION.replace('.', '')}arm.zip`\n }\n default:\n throw new Error(`Unsupported platform: ${platform}`)\n }\n}\n\nexport function getFfmpegArchiveInfo(platform: string): {\n isArchive: boolean\n archiveFormat: 'zip' | 'tar.gz' | 'tar.xz'\n archiveInnerPath: string\n} {\n switch (platform) {\n case 'linux':\n return {\n isArchive: true,\n archiveFormat: 'tar.xz',\n archiveInnerPath: `ffmpeg-${FFMPEG_VERSION}-amd64-static/ffmpeg`,\n }\n case 'darwin':\n return {\n isArchive: true,\n archiveFormat: 'zip',\n archiveInnerPath: 'ffmpeg',\n }\n default:\n throw new Error(`Unsupported platform: ${platform}`)\n }\n}\n\n/**\n * Ensure ffmpeg binary is available.\n * Checks: deps dir → system PATH → download.\n */\nexport async function ensureFfmpeg(dataDir: string, logger: IScopedLogger): Promise<string> {\n const depsDir = join(dataDir, 'deps')\n const platform = process.platform\n const arch = process.arch\n\n const archiveInfo = getFfmpegArchiveInfo(platform)\n\n return ensureBinary({\n name: 'ffmpeg',\n targetDir: depsDir,\n downloadUrl: getFfmpegDownloadUrl(platform, arch),\n logger,\n ...archiveInfo,\n })\n}\n","/**\n * Download portable Python (headless) from bjia56/portable-python.\n *\n * Source: https://github.com/bjia56/portable-python\n *\n * Advantages over python-build-standalone:\n * - macOS universal2 binary (arm64+x86_64 in one)\n * - Lighter (~24-28MB headless zip)\n * - glibc 2.17 minimum (better compat)\n * - Headless variant excludes tkinter/UI (ideal for ML inference)\n *\n * The zip's top-level dir is platform-specific (e.g.\n * `python-headless-3.12.12-darwin-universal2/`); after extraction\n * we rename it to a stable `python/` so consumers can rely on\n * `<dataDir>/deps/python/bin/python3`.\n */\nimport { join, basename } from 'node:path'\nimport { existsSync, mkdirSync, chmodSync, readFileSync, writeFileSync, readdirSync, renameSync, rmSync } from 'node:fs'\nimport { execFileSync } from 'node:child_process'\nimport { createHash } from 'node:crypto'\nimport { pipeline } from 'node:stream/promises'\nimport { Readable } from 'node:stream'\nimport { createWriteStream } from 'node:fs'\nimport type { IScopedLogger } from '../index.js'\nimport { errMsg } from '../index.js'\n\nexport const PYTHON_VERSION = '3.12.12'\nconst PP_BASE = `https://github.com/bjia56/portable-python/releases/download/cpython-v${PYTHON_VERSION}-build.0`\n\nexport function getPythonDownloadUrl(platform: string, arch: string): string {\n switch (platform) {\n case 'linux': {\n const archMap: Record<string, string> = { x64: 'x86_64', arm64: 'aarch64' }\n const a = archMap[arch]\n if (!a) throw new Error(`Unsupported Linux architecture for Python: ${arch}`)\n return `${PP_BASE}/python-headless-${PYTHON_VERSION}-linux-${a}.zip`\n }\n case 'darwin': {\n // universal2 covers both arm64 and x86_64\n return `${PP_BASE}/python-headless-${PYTHON_VERSION}-darwin-universal2.zip`\n }\n default:\n throw new Error(`Unsupported platform for portable Python: ${platform}`)\n }\n}\n\n/**\n * Ensure the embedded portable Python is available.\n *\n * ALWAYS returns the path to the embedded interpreter under\n * `<dataDir>/deps/python/bin/python3` — downloads it on first call\n * and reuses it thereafter. The system PATH is intentionally NOT\n * consulted: addons rely on `installPythonRequirements()` to manage\n * deps inside the embedded site-packages, and a system interpreter\n * (different version, missing modules) silently breaks that contract.\n *\n * Returns null only if the download/extract step fails.\n */\nexport async function ensurePython(dataDir: string, logger: IScopedLogger): Promise<string | null> {\n const pythonDir = join(dataDir, 'deps', 'python')\n const pythonBin = join(pythonDir, 'bin', 'python3')\n\n // 1. Already downloaded\n if (existsSync(pythonBin)) {\n logger.debug('Portable Python found', { meta: { pythonBin } })\n return pythonBin\n }\n\n // 2. Download portable python (no system PATH fallback — by design)\n logger.info('Downloading portable Python (headless)', { meta: { version: PYTHON_VERSION } })\n\n const depsDir = join(dataDir, 'deps')\n mkdirSync(depsDir, { recursive: true })\n\n const url = getPythonDownloadUrl(process.platform, process.arch)\n const tmpArchive = join(depsDir, 'python-download.zip')\n\n logger.info('Python download source', { meta: { url } })\n\n const response = await fetch(url, { redirect: 'follow' })\n if (!response.ok || !response.body) {\n logger.warn('Failed to download Python — ML detection will not be available', { meta: { status: response.status } })\n return null\n }\n\n const nodeStream = Readable.fromWeb(response.body as ReadableStream)\n await pipeline(nodeStream, createWriteStream(tmpArchive))\n\n // Extract — zip's top-level dir is e.g. `python-headless-3.12.12-darwin-universal2/`\n // (varies per platform/arch).\n try {\n execFileSync('unzip', ['-o', '-q', tmpArchive, '-d', depsDir], { stdio: 'pipe' })\n } catch {\n // Fallback: some minimal Linux installs don't have unzip\n execFileSync('python3', ['-m', 'zipfile', '-e', tmpArchive, depsDir], { stdio: 'pipe' })\n }\n\n // Cleanup the archive\n const { unlinkSync } = await import('node:fs')\n unlinkSync(tmpArchive)\n\n // Locate the extracted directory and normalize it to `<depsDir>/python/`.\n // The zip's top-level name varies by platform (e.g.\n // `python-headless-3.12.12-darwin-universal2/`), so we look for any\n // `python-*` subdir that contains the expected `bin/python3` and rename it.\n if (!existsSync(pythonBin)) {\n const candidates = readdirSync(depsDir).filter((name) =>\n name.startsWith('python-') &&\n existsSync(join(depsDir, name, 'bin', 'python3')),\n )\n if (candidates.length === 0) {\n logger.warn('Python extraction succeeded but no python3 binary found in any subdir', {\n meta: { depsDir },\n })\n return null\n }\n const extractedRoot = join(depsDir, candidates[0]!)\n // Drop any stale `python/` (e.g. from a previous failed install)\n // before renaming so the move always succeeds.\n if (existsSync(pythonDir)) {\n rmSync(pythonDir, { recursive: true, force: true })\n }\n renameSync(extractedRoot, pythonDir)\n }\n\n if (!existsSync(pythonBin)) {\n logger.warn('Python extraction succeeded but binary not found at expected path', {\n meta: { pythonBin },\n })\n return null\n }\n\n chmodSync(pythonBin, 0o755)\n\n // On macOS the bjia56 build is universal2 — the host arch is decided\n // at spawn time based on the parent process. That makes pip wheels\n // and runtime spawns silently disagree when the server is launched\n // from a Rosetta shell once and a native shell next time (e.g. pip\n // installs `numpy x86_64`, then the next boot under arm64 fails with\n // `incompatible architecture`). Lock the slice deterministically by\n // wrapping `python3` in a shell stub that always invokes the matching\n // host arch via `/usr/bin/arch`. Idempotent: detected via the renamed\n // `.real` binary.\n if (process.platform === 'darwin') {\n const realBin = join(pythonDir, 'bin', 'python3.real')\n if (!existsSync(realBin)) {\n renameSync(pythonBin, realBin)\n const archFlag = process.arch === 'arm64' ? '-arm64' : '-x86_64'\n writeFileSync(\n pythonBin,\n `#!/bin/sh\\nexec /usr/bin/arch ${archFlag} \"${realBin}\" \"$@\"\\n`,\n )\n chmodSync(pythonBin, 0o755)\n // Mirror the same wrapping for the `python` symlink so consumers\n // that use the un-versioned name also lock the arch.\n const pyAlt = join(pythonDir, 'bin', 'python')\n if (existsSync(pyAlt)) {\n try {\n rmSync(pyAlt, { force: true })\n } catch {\n // ignore\n }\n writeFileSync(\n pyAlt,\n `#!/bin/sh\\nexec /usr/bin/arch ${archFlag} \"${realBin}\" \"$@\"\\n`,\n )\n chmodSync(pyAlt, 0o755)\n }\n logger.info('Locked python3 to host arch via shell stub', {\n meta: { archFlag, realBin },\n })\n }\n }\n\n logger.info('Portable Python installed', { meta: { version: PYTHON_VERSION, pythonBin } })\n return pythonBin\n}\n\n/**\n * Install Python packages into the portable Python environment.\n */\nexport async function installPythonPackages(\n pythonPath: string,\n packages: readonly string[],\n logger: IScopedLogger,\n): Promise<void> {\n if (packages.length === 0) return\n\n logger.info('Installing Python packages', { meta: { packages } })\n try {\n execFileSync(pythonPath, ['-m', 'pip', 'install', '--quiet', ...packages], {\n stdio: 'pipe',\n timeout: 300_000, // 5 minutes for large packages like torch\n })\n logger.info('Python packages installed successfully')\n } catch (err) {\n logger.error('Failed to install Python packages', { meta: { error: errMsg(err) } })\n throw err\n }\n}\n\n/**\n * Install a pip requirements file into the embedded Python.\n *\n * Idempotent: keyed on (requirements file basename + sha256 of its\n * contents). The marker is written under\n * `<python-install-dir>/.requirements-installed/` so it lives and\n * dies with the python install — re-downloading python wipes both\n * the site-packages and the markers, forcing a fresh re-install.\n *\n * The marker is updated only after `pip install` succeeds. A failed\n * install never writes a marker, so the next call retries.\n */\nexport async function installPythonRequirements(\n pythonPath: string,\n requirementsFile: string,\n logger: IScopedLogger,\n): Promise<void> {\n if (!existsSync(requirementsFile)) {\n throw new Error(`Requirements file not found: ${requirementsFile}`)\n }\n\n const contents = readFileSync(requirementsFile)\n const hash = createHash('sha256').update(contents).digest('hex').slice(0, 16)\n const fileBase = basename(requirementsFile).replace(/\\.txt$/i, '')\n\n // Markers live under the python install dir → wiped together when\n // the embedded interpreter is re-downloaded.\n const pythonRoot = join(pythonPath, '..', '..') // <root>/bin/python3 → <root>\n const markerDir = join(pythonRoot, '.requirements-installed')\n const markerPath = join(markerDir, `${fileBase}-${hash}.marker`)\n\n if (existsSync(markerPath)) {\n logger.debug('Python requirements already installed', { meta: { requirementsFile, hash } })\n return\n }\n\n logger.info('Installing Python requirements', { meta: { requirementsFile, hash } })\n try {\n execFileSync(\n pythonPath,\n ['-m', 'pip', 'install', '--quiet', '--disable-pip-version-check', '-r', requirementsFile],\n {\n stdio: 'pipe',\n timeout: 600_000, // 10 minutes — coremltools + tensorflow can be slow\n },\n )\n } catch (err) {\n logger.error('Failed to install Python requirements', {\n meta: { requirementsFile, error: errMsg(err) },\n })\n throw err\n }\n\n mkdirSync(markerDir, { recursive: true })\n writeFileSync(markerPath, `${requirementsFile}\\n${new Date().toISOString()}\\n`)\n logger.info('Python requirements installed', { meta: { requirementsFile, hash } })\n}\n","import * as fs from 'node:fs'\nimport * as path from 'node:path'\nimport type {\n IStorageProvider,\n StorageLocationType,\n StorageResolveInput,\n StorageWriteInput,\n StorageReadInput,\n StorageExistsInput,\n StorageListInput,\n StorageDeleteInput,\n StorageAvailableSpaceInput,\n} from '../index.js'\n\n// Inline constants to avoid runtime dependency on @camstack/types\n// (types is external in tsup bundle, may not be resolvable from data/addons/)\nconst STORAGE_LOCATION_TYPES: readonly StorageLocationType[] = [\n 'data', 'media', 'recordings',\n 'recordings-high', 'recordings-low', 'recordings-clips', 'event-images',\n 'models', 'addons-data', 'cache', 'logs', 'backups',\n]\n\nconst DEFAULT_LOCATION_SUBDIRS: Readonly<Record<StorageLocationType, string>> = {\n 'data': 'db',\n 'media': 'media',\n 'recordings': 'recordings',\n 'recordings-high': 'recordings-high',\n 'recordings-low': 'recordings-low',\n 'recordings-clips': 'recordings-clips',\n 'event-images': 'event-images',\n 'models': 'models',\n 'addons-data': 'addons-data',\n 'cache': '/tmp/camstack-cache',\n 'logs': 'logs',\n 'backups': 'backups',\n}\n\n/**\n * Filesystem storage provider — serves all location types from a local directory tree.\n *\n * Default layout:\n * {rootPath}/recordings-high/\n * {rootPath}/recordings-low/\n * {rootPath}/recordings-clips/\n * {rootPath}/event-images/\n * {rootPath}/models/\n * {rootPath}/addons-data/\n * {rootPath}/logs/\n * /tmp/camstack-cache/ (cache is always local)\n *\n * Individual location paths can be overridden.\n */\nexport class FilesystemStorageProvider implements IStorageProvider {\n readonly id = 'local'\n readonly name = 'Local Filesystem'\n readonly supportedLocations: readonly StorageLocationType[] = [...STORAGE_LOCATION_TYPES]\n\n private readonly rootPath: string\n private readonly locationPaths: Map<StorageLocationType, string>\n\n constructor(rootPath: string, overrides?: Partial<Record<StorageLocationType, string>>) {\n this.rootPath = path.resolve(rootPath)\n this.locationPaths = new Map()\n\n for (const loc of STORAGE_LOCATION_TYPES) {\n const override = overrides?.[loc]\n if (override) {\n this.locationPaths.set(loc, path.resolve(override))\n } else {\n const subdir = DEFAULT_LOCATION_SUBDIRS[loc]\n // Absolute paths (like /tmp/camstack-cache) are used as-is\n this.locationPaths.set(\n loc,\n path.isAbsolute(subdir) ? subdir : path.join(this.rootPath, subdir),\n )\n }\n }\n }\n\n async resolve({ location, relativePath }: StorageResolveInput): Promise<string> {\n const base = this.locationPaths.get(location)\n if (!base) throw new Error(`Unknown storage location: ${location}`)\n return path.join(base, relativePath)\n }\n\n async write({ location, relativePath, data }: StorageWriteInput): Promise<void> {\n const filePath = await this.resolve({ location, relativePath })\n await fs.promises.mkdir(path.dirname(filePath), { recursive: true })\n\n if (Buffer.isBuffer(data)) {\n await fs.promises.writeFile(filePath, data)\n } else {\n // Stream\n const writeStream = fs.createWriteStream(filePath)\n await new Promise<void>((resolve, reject) => {\n (data as NodeJS.ReadableStream).pipe(writeStream)\n writeStream.on('finish', resolve)\n writeStream.on('error', reject)\n })\n }\n }\n\n async read({ location, relativePath }: StorageReadInput): Promise<Buffer> {\n return fs.promises.readFile(await this.resolve({ location, relativePath }))\n }\n\n async exists({ location, relativePath }: StorageExistsInput): Promise<boolean> {\n try {\n await fs.promises.access(await this.resolve({ location, relativePath }))\n return true\n } catch {\n return false\n }\n }\n\n async list({ location, prefix }: StorageListInput): Promise<readonly string[]> {\n const base = this.locationPaths.get(location)\n if (!base) return []\n const dir = prefix ? path.join(base, prefix) : base\n try {\n const entries = await fs.promises.readdir(dir, { withFileTypes: true })\n return entries.map(e => (prefix ? `${prefix}/${e.name}` : e.name))\n } catch {\n return []\n }\n }\n\n async delete({ location, relativePath }: StorageDeleteInput): Promise<void> {\n const filePath = await this.resolve({ location, relativePath })\n await fs.promises.rm(filePath, { force: true })\n }\n\n async getAvailableSpace({ location }: StorageAvailableSpaceInput): Promise<number | null> {\n const base = this.locationPaths.get(location)\n if (!base) return null\n // If the directory doesn't exist yet (lazy creation), walk up to\n // the nearest existing ancestor so statfs can still report free\n // space on the mount point. This keeps the storage dashboard\n // working on a fresh install where no file has been written yet.\n try {\n let target = base\n while (!fs.existsSync(target)) {\n const parent = path.dirname(target)\n if (!parent || parent === target) return null\n target = parent\n }\n const stats = await fs.promises.statfs(target)\n return stats.bavail * stats.bsize\n } catch {\n return null\n }\n }\n\n\n /** Get the resolved path for a location type */\n getLocationPath(location: StorageLocationType): string {\n const p = this.locationPaths.get(location)\n if (!p) throw new Error(`Unknown storage location: ${location}`)\n return p\n }\n\n /** Get the root path */\n getRootPath(): string {\n return this.rootPath\n }\n}\n\nexport default FilesystemStorageProvider\n"],"names":["rmSync","unlinkSync"],"mappings":";;;;;;;;;;AAYO,SAAS,kBAAgC;AAC9C,SAAO;AAAA,IACL,UAAU,QAAQ;AAAA,IAClB,MAAM,QAAQ;AAAA,EAAA;AAElB;AAEO,SAAS,gBAAgB,SAAiB,MAAc,UAA2B;AACxF,QAAM,OAAO,YAAY,QAAQ,cAAc,UAAU,SAAS;AAClE,SAAO,KAAK,SAAS,QAAQ,GAAG,IAAI,GAAG,GAAG,EAAE;AAC9C;AAGO,SAAS,WAAW,MAA6B;AACtD,MAAI;AACF,iBAAa,MAAM,CAAC,WAAW,GAAG,EAAE,OAAO,QAAQ,SAAS,KAAM;AAClE,WAAO;AAAA,EACT,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAkBA,eAAsB,eAAe,MAAwC;AAC3E,QAAM,EAAE,MAAM,KAAK,WAAW,YAAY,QAAQ,WAAW,eAAe,iBAAA,IAAqB;AACjG,QAAM,aAAa,KAAK,WAAW,UAAU;AAE7C,MAAI,WAAW,UAAU,GAAG;AAC1B,WAAO,MAAM,yBAAyB,EAAE,MAAM,EAAE,MAAM,WAAA,GAAc;AACpE,WAAO;AAAA,EACT;AAEA,YAAU,WAAW,EAAE,WAAW,KAAA,CAAM;AAExC,SAAO,KAAK,sBAAsB,EAAE,MAAM,EAAE,MAAM,IAAA,GA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EAAG,OAAM,IAAI,MAAM,6BAA6B,QAAQ,EAAE;AAC/D,WAAO;AAAA,EACT;AAAA;AAAA,EAGA,cAAsB;AACpB,WAAO,KAAK;AAAA,EACd;AACF;"}
@@ -21,7 +21,7 @@ export declare class FilesystemStorageProvider implements IStorageProvider {
21
21
  private readonly rootPath;
22
22
  private readonly locationPaths;
23
23
  constructor(rootPath: string, overrides?: Partial<Record<StorageLocationType, string>>);
24
- resolve({ location, relativePath }: StorageResolveInput): string;
24
+ resolve({ location, relativePath }: StorageResolveInput): Promise<string>;
25
25
  write({ location, relativePath, data }: StorageWriteInput): Promise<void>;
26
26
  read({ location, relativePath }: StorageReadInput): Promise<Buffer>;
27
27
  exists({ location, relativePath }: StorageExistsInput): Promise<boolean>;
@@ -1 +1 @@
1
- {"version":3,"file":"filesystem-storage-provider.d.ts","sourceRoot":"","sources":["../../src/storage/filesystem-storage-provider.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,gBAAgB,EAChB,mBAAmB,EACnB,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,gBAAgB,EAChB,kBAAkB,EAClB,0BAA0B,EAC3B,MAAM,aAAa,CAAA;AAyBpB;;;;;;;;;;;;;;GAcG;AACH,qBAAa,yBAA0B,YAAW,gBAAgB;IAChE,QAAQ,CAAC,EAAE,WAAU;IACrB,QAAQ,CAAC,IAAI,sBAAqB;IAClC,QAAQ,CAAC,kBAAkB,EAAE,SAAS,mBAAmB,EAAE,CAA8B;IAEzF,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAQ;IACjC,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAkC;gBAEpD,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC;IAmBtF,OAAO,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,mBAAmB,GAAG,MAAM;IAM1D,KAAK,C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OAAO,CAAC,QAAQ,CAAC,aAAa,CAAkC;gBAEpD,QAAQ,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,mBAAmB,EAAE,MAAM,CAAC,CAAC;IAmBhF,OAAO,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,mBAAmB,GAAG,OAAO,CAAC,MAAM,CAAC;IAMzE,KAAK,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,IAAI,EAAE,EAAE,iBAAiB,GAAG,OAAO,CAAC,IAAI,CAAC;IAiBzE,IAAI,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,gBAAgB,GAAG,OAAO,CAAC,MAAM,CAAC;IAInE,MAAM,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,OAAO,CAAC;IASxE,IAAI,CAAC,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,gBAAgB,GAAG,OAAO,CAAC,SAAS,MAAM,EAAE,CAAC;IAYxE,MAAM,CAAC,EAAE,QAAQ,EAAE,YAAY,EAAE,EAAE,kBAAkB,GAAG,OAAO,CAAC,IAAI,CAAC;IAKrE,iBAAiB,CAAC,EAAE,QAAQ,EAAE,EAAE,0BAA0B,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IAsBzF,gDAAgD;IAChD,eAAe,CAAC,QAAQ,EAAE,mBAAmB,GAAG,MAAM;IAMtD,wBAAwB;IACxB,WAAW,IAAI,MAAM;CAGtB;AAED,eAAe,yBAAyB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/types",
3
- "version": "0.1.31",
3
+ "version": "0.1.33",
4
4
  "description": "Shared types, interfaces, and model catalogs for the CamStack detection ecosystem",
5
5
  "keywords": [
6
6
  "camstack",
@@ -1,138 +0,0 @@
1
- import { z } from 'zod';
2
- import { type InferProvider } from './capability-definition.js';
3
- /**
4
- * `home-assistant` — collection cap exposing a long-lived WebSocket
5
- * connection to a Home Assistant instance.
6
- *
7
- * Backed by `@camstack/addon-home-assistant` (home-assistant-js-websocket
8
- * wrapper). Collection mode supports multi-HA deployments (e.g. one
9
- * per house / per site).
10
- *
11
- * ON-DEMAND CONNECTION: the addon opens the WebSocket on the first
12
- * `subscribeEvents` / `callService` / `getStates` call. Stays open
13
- * while at least one subscription is active OR the operator
14
- * configured `keepOpen`.
15
- *
16
- * SUBSCRIPTION OWNERSHIP: `subscribeEvents` returns a unique
17
- * `subscriptionId`. Multiple consumers can share the same upstream
18
- * event-type subscription (HA dispatches it once over the wire);
19
- * the addon refcounts the upstream sub and tags emitted events with
20
- * `subscriptionIds[]` so consumers filter precisely without leaking
21
- * messages between unrelated callers.
22
- */
23
- declare const HaServiceCallSchema: z.ZodObject<{
24
- domain: z.ZodString;
25
- service: z.ZodString;
26
- serviceData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
27
- target: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
28
- }, z.core.$strip>;
29
- declare const HaStateSchema: z.ZodObject<{
30
- entity_id: z.ZodString;
31
- state: z.ZodString;
32
- attributes: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
33
- last_changed: z.ZodOptional<z.ZodString>;
34
- last_updated: z.ZodOptional<z.ZodString>;
35
- }, z.core.$strip>;
36
- declare const HaStatusSchema: z.ZodObject<{
37
- connected: z.ZodBoolean;
38
- host: z.ZodString;
39
- subscriptionCount: z.ZodNumber;
40
- error: z.ZodOptional<z.ZodString>;
41
- haVersion: z.ZodOptional<z.ZodString>;
42
- connectedAt: z.ZodOptional<z.ZodNumber>;
43
- }, z.core.$strip>;
44
- declare const HaSubscribeInputSchema: z.ZodObject<{
45
- eventType: z.ZodOptional<z.ZodString>;
46
- owner: z.ZodOptional<z.ZodString>;
47
- }, z.core.$strip>;
48
- declare const HaSubscribeResultSchema: z.ZodObject<{
49
- success: z.ZodLiteral<true>;
50
- subscriptionId: z.ZodString;
51
- }, z.core.$strip>;
52
- declare const HaUnsubscribeInputSchema: z.ZodObject<{
53
- subscriptionId: z.ZodString;
54
- }, z.core.$strip>;
55
- declare const HaSubscriptionInfoSchema: z.ZodObject<{
56
- subscriptionId: z.ZodString;
57
- eventType: z.ZodString;
58
- owner: z.ZodString;
59
- createdAt: z.ZodNumber;
60
- }, z.core.$strip>;
61
- export declare const homeAssistantCapability: {
62
- readonly name: "home-assistant";
63
- readonly scope: "system";
64
- readonly mode: "collection";
65
- readonly internal: true;
66
- readonly methods: {
67
- /**
68
- * Subscribe to HA events. Returns a `subscriptionId` to pass to
69
- * `unsubscribeEvents`. The addon refcounts upstream subscriptions
70
- * so multiple consumers share one HA-side event stream.
71
- * Events arrive on the kernel bus under `home-assistant.event`
72
- * with `subscriptionIds[]` listing which subs matched.
73
- */
74
- readonly subscribeEvents: import("./capability-definition.js").CapabilityMethodSchema<z.ZodObject<{
75
- eventType: z.ZodOptional<z.ZodString>;
76
- owner: z.ZodOptional<z.ZodString>;
77
- }, z.core.$strip>, z.ZodObject<{
78
- success: z.ZodLiteral<true>;
79
- subscriptionId: z.ZodString;
80
- }, z.core.$strip>, "mutation">;
81
- /** Release a specific subscription. Tears down the upstream sub
82
- * only when the last owner releases. Idempotent. */
83
- readonly unsubscribeEvents: import("./capability-definition.js").CapabilityMethodSchema<z.ZodObject<{
84
- subscriptionId: z.ZodString;
85
- }, z.core.$strip>, z.ZodObject<{
86
- success: z.ZodLiteral<true>;
87
- }, z.core.$strip>, "mutation">;
88
- /**
89
- * Call an HA service (turn light on, run a script, etc.). Returns
90
- * the HA response object — usually `{context, response: ...}`.
91
- */
92
- readonly callService: import("./capability-definition.js").CapabilityMethodSchema<z.ZodObject<{
93
- domain: z.ZodString;
94
- service: z.ZodString;
95
- serviceData: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
96
- target: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
97
- }, z.core.$strip>, z.ZodObject<{
98
- result: z.ZodUnknown;
99
- }, z.core.$strip>, "mutation">;
100
- /** Fetch all entity states. Cheap snapshot — HA returns the full
101
- * state registry on every call. */
102
- readonly getStates: import("./capability-definition.js").CapabilityMethodSchema<z.ZodVoid, z.ZodReadonly<z.ZodArray<z.ZodObject<{
103
- entity_id: z.ZodString;
104
- state: z.ZodString;
105
- attributes: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
106
- last_changed: z.ZodOptional<z.ZodString>;
107
- last_updated: z.ZodOptional<z.ZodString>;
108
- }, z.core.$strip>>>, import("./capability-definition.js").CapabilityMethodKind>;
109
- /** Fetch a single entity's current state. `null` when not found. */
110
- readonly getState: import("./capability-definition.js").CapabilityMethodSchema<z.ZodObject<{
111
- entityId: z.ZodString;
112
- }, z.core.$strip>, z.ZodNullable<z.ZodObject<{
113
- entity_id: z.ZodString;
114
- state: z.ZodString;
115
- attributes: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
116
- last_changed: z.ZodOptional<z.ZodString>;
117
- last_updated: z.ZodOptional<z.ZodString>;
118
- }, z.core.$strip>>, import("./capability-definition.js").CapabilityMethodKind>;
119
- /** List active per-owner subscriptions. */
120
- readonly listSubscriptions: import("./capability-definition.js").CapabilityMethodSchema<z.ZodVoid, z.ZodReadonly<z.ZodArray<z.ZodObject<{
121
- subscriptionId: z.ZodString;
122
- eventType: z.ZodString;
123
- owner: z.ZodString;
124
- createdAt: z.ZodNumber;
125
- }, z.core.$strip>>>, import("./capability-definition.js").CapabilityMethodKind>;
126
- readonly getStatus: import("./capability-definition.js").CapabilityMethodSchema<z.ZodVoid, z.ZodObject<{
127
- connected: z.ZodBoolean;
128
- host: z.ZodString;
129
- subscriptionCount: z.ZodNumber;
130
- error: z.ZodOptional<z.ZodString>;
131
- haVersion: z.ZodOptional<z.ZodString>;
132
- connectedAt: z.ZodOptional<z.ZodNumber>;
133
- }, z.core.$strip>, import("./capability-definition.js").CapabilityMethodKind>;
134
- };
135
- };
136
- export type IHomeAssistantProvider = InferProvider<typeof homeAssistantCapability>;
137
- export { HaServiceCallSchema, HaStateSchema, HaStatusSchema, HaSubscribeInputSchema, HaSubscribeResultSchema, HaUnsubscribeInputSchema, HaSubscriptionInfoSchema, };
138
- //# sourceMappingURL=home-assistant.cap.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"home-assistant.cap.d.ts","sourceRoot":"","sources":["../../src/capabilities/home-assistant.cap.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAqC,KAAK,aAAa,EAAE,MAAM,4BAA4B,CAAA;AAElG;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,QAAA,MAAM,mBAAmB;;;;;iBASvB,CAAA;AAEF,QAAA,MAAM,aAAa;;;;;;iBAMjB,CAAA;AAEF,QAAA,MAAM,cAAc;;;;;;;iBAUlB,CAAA;AAEF,QAAA,MAAM,sBAAsB;;;iBAS1B,CAAA;AAEF,QAAA,MAAM,uBAAuB;;;iBAG3B,CAAA;AAEF,QAAA,MAAM,wBAAwB;;iBAE5B,CAAA;AAEF,QAAA,MAAM,wBAAwB;;;;;iBAM5B,CAAA;AAEF,eAAO,MAAM,uBAAuB;;;;;;QAMhC;;;;;;WAMG;;;;;;;;QAMH;6DACqD;;;;;;QAMrD;;;WAGG;;;;;;;;;QAMH;4CACoC;;;;;;;;QAMpC,oEAAoE;;;;;;;;;;QAMpE,2CAA2C;;;;;;;;;;;;;;;;CAQN,CAAA;AAEzC,MAAM,MAAM,sBAAsB,GAAG,aAAa,CAAC,OAAO,uBAAuB,CAAC,CAAA;AAClF,OAAO,EACL,mBAAmB,EACnB,aAAa,EACb,cAAc,EACd,sBAAsB,EACtB,uBAAuB,EACvB,wBAAwB,EACxB,wBAAwB,GACzB,CAAA"}