UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

2 lines • 17.3 kB
import{createRequire as e}from"node:module";import t,{posix as n}from"node:path";import r,{existsSync as i,readFileSync as a}from"node:fs";import{getEnvironmentData as o,isMainThread as s,setEnvironmentData as c}from"node:worker_threads";import{fileURLToPath as l,pathToFileURL as u}from"node:url";import{spawnSync as d}from"node:child_process";import f from"node:os";var __esmMin=(e,t,n)=>()=>{if(n)throw n[0];try{return e&&(t=e(e=0)),t}catch(e){throw n=[e],e}};function probeSqlite(e){let t={available:!1,version:null,text:!1,blob:!1,json:!1},n;try{n=new e(`:memory:`),t.available=!0;let r=`a\0b\0`,i=Buffer.from(r,`utf8`),a=JSON.stringify({value:r});n.exec(`CREATE TABLE probe (text_value TEXT, blob_value BLOB, json_value TEXT)`),n.prepare(`INSERT INTO probe VALUES (?, ?, ?)`).run(r,i,a);let o=n.prepare(`SELECT sqlite_version() AS version, text_value, blob_value, json_value FROM probe`).get();t.version=typeof o?.version==`string`?o.version:null,t.text=typeof o?.text_value==`string`&&o.text_value.length===4&&Buffer.from(o.text_value,`utf8`).equals(i),t.blob=o?.blob_value instanceof Uint8Array&&Buffer.from(o.blob_value).equals(i),t.json=o?.json_value===a&&JSON.parse(o.json_value).value===r}catch(e){let r=e;if(n&&t.version===null)try{let e=n.prepare(`SELECT sqlite_version() AS version`).get()?.version;t.version=typeof e==`string`?e:null}catch(e){r=e}t.error=r instanceof Error?r.message:String(r)}finally{n?.close()}return t}function isSqliteWalResetSafeVersion(e){let t=/^(\d+)\.(\d+)\.(\d+)$/u.exec(e.trim());if(!t)return!1;let[n,r,i]=t.slice(1).map(Number);return[n,r,i].every(Number.isSafeInteger)?n>3||n===3&&(r>51||r===51&&i>=3||r===50&&i>=7||r===44&&i>=6):!1}var p,m,h,g=__esmMin((()=>{p=Symbol.for(`openclaw.cliRespawnParent`),m=`OPENCLAW_CLI_RESPAWN_PARENT`,h=process.env[m],delete process.env[m],h===String(process.ppid)&&(globalThis[p]={pid:process.ppid})}));function readStandaloneRuntimeManifest(e=process.execPath){return readStandaloneManifest({executable:e})}function projectStandaloneBuildInfo(e){let nonBlank=e=>typeof e==`string`&&e.trim().length>0,stringList=e=>Array.isArray(e)&&e.every(nonBlank),t={mode:e.mode,openclaw:{version:e.openclaw.version,...nonBlank(e.openclaw.commit)?{commit:e.openclaw.commit}:{}},bun:{version:e.bun.version}};for(let n of[`revision`,`commit`,`executableSha256`])nonBlank(e.bun[n])&&(t.bun[n]=e.bun[n]);if(e.build!==void 0){let{id:n,flavor:r,pluginSetSha256:i,moduleGraphSha256:a}=e.build;if(!nonBlank(n)||![`standard`,`support`].includes(r)||!/^[a-f0-9]{64}$/.test(i)||!/^[a-f0-9]{64}$/.test(a))throw Error(`Invalid standalone build provenance`);if(t.build={id:n,flavor:r,pluginSetSha256:i,moduleGraphSha256:a},e.build.debugEntry!==void 0){let n=e.build.debugEntry;if(typeof n!=`string`||!n.startsWith(`debug/`)||n.includes(`\\`)||n.split(`/`).some(e=>!e||e===`.`||e===`..`))throw Error(`Invalid standalone debugger entry`);t.build.debugEntry=n}}if(e.target!==void 0){if(!nonBlank(e.target.platform)||!nonBlank(e.target.arch))throw Error(`Invalid standalone build target`);t.target={platform:e.target.platform,arch:e.target.arch}}if(e.plugins!==void 0){if(!stringList(e.plugins.embedded)||!stringList(e.plugins.omitted))throw Error(`Invalid standalone plugin inventory`);t.plugins={embedded:[...e.plugins.embedded],omitted:[...e.plugins.omitted]}}if(e.nativeModules!==void 0){if(!Array.isArray(e.nativeModules)||e.nativeModules.some(e=>!e||!nonBlank(e.name)||!nonBlank(e.version)||!stringList(e.artifacts)||e.qualification!==`unverified`||!nonBlank(e.backend)))throw Error(`Invalid standalone native inventory`);t.nativeModules=e.nativeModules.map(({name:e,version:t,artifacts:n,qualification:r,backend:i})=>({name:e,version:t,artifacts:[...n],qualification:r,backend:i}))}return t}function readStandaloneManifest({executable:e,runtimeRoot:n,includeBuild:r=!1}){let i=e??n;if(!t.isAbsolute(i))return;let o=t.dirname(i),s=t.join(o,`manifest.json`),c;try{c=a(s,`utf8`)}catch(e){if(e?.code===`ENOENT`||e?.code===`ENOTDIR`)return;throw e}let l;try{l=JSON.parse(c)}catch(e){throw Error(`Invalid standalone runtime manifest: ${s}`,{cause:e})}let nonBlank=e=>typeof e==`string`&&e.trim().length>0;if(l?.schemaVersion!==1||![`jit`,`bytecode`,`aot`].includes(l.mode)||!nonBlank(l.executable?.path)||!nonBlank(l.runtime?.path)||!nonBlank(l.openclaw?.version)||!nonBlank(l.bun?.version))throw Error(`Invalid standalone runtime manifest: ${s}`);let u=t.relative(o,t.resolve(o,l.executable.path)),d=t.relative(o,t.resolve(o,l.runtime.path));if(t.isAbsolute(l.executable.path)||!u||u===`..`||u.startsWith(`..${t.sep}`)||e&&t.resolve(o,l.executable.path)!==t.resolve(e)||n&&t.resolve(o,l.runtime.path)!==t.resolve(n)||t.isAbsolute(l.runtime.path)||!d||d===`..`||d.startsWith(`..${t.sep}`))throw Error(`Invalid standalone runtime manifest: ${s}`);return{schemaVersion:1,mode:l.mode,executable:{path:l.executable.path,...nonBlank(l.executable.sha256)?{sha256:l.executable.sha256}:{}},runtime:{path:l.runtime.path,...nonBlank(l.runtime.sha256)?{sha256:l.runtime.sha256}:{}},openclaw:{version:l.openclaw.version,...nonBlank(l.openclaw.commit)?{commit:l.openclaw.commit}:{}},bun:{version:l.bun.version},...r?projectStandaloneBuildInfo(l):{}}}function getEmbeddedStandaloneRuntimeRoot(){let e=globalThis.__openclawStandaloneRootUrl;return typeof e==`string`?l(e):void 0}function resolveStandaloneSidecarRoot(e=process.execPath){if(e===process.execPath){let e=getEmbeddedStandaloneRuntimeRoot();if(e!==void 0)return e}let n=readStandaloneRuntimeManifest(e);return n?t.resolve(t.dirname(e),n.runtime.path):void 0}function isStandaloneRuntimeExecutable(e=process.execPath){return resolveStandaloneSidecarRoot(e)!==void 0}function resolveRuntimeScriptEnv(e){return isStandaloneRuntimeExecutable()?{...e,BUN_BE_BUN:`1`}:{...e}}var _=__esmMin((()=>{g()}));_();const v=Symbol.for(`openclaw.globalSingletonLifecycleResets`);function resolveGlobalSingletonResetRegistry(){let e=globalThis,t=e[v];if(t instanceof Map)return t;let n=/* @__PURE__ */ new Map;return e[v]=n,n}function resolveGlobalSingleton(e,t,n,r=`close-and-restart`){let i=globalThis,a;return Object.hasOwn(i,e)?a=i[e]:(a=t(),i[e]=a),n&&resolveGlobalSingletonResetRegistry().set(e,{lifecycle:r,reset:()=>n(a)}),a}function pluginRuntimeProcess(e,t,n){return{plugin:e,ownerSource:`extensions/${e}/${t}.ts`,sourceWorkerName:n,distWorkerPath:`extensions/${e}/${n}.js`,package:{name:`@openclaw/${e}`,distWorkerPath:`${n}.js`}}}var y;__esmMin((()=>{({...pluginRuntimeProcess(`browser`,`native-host-entry`,`native-host-entry`)}),{...pluginRuntimeProcess(`browser`,`native-host-entry`,`relay-daemon-entry`)},{...pluginRuntimeProcess(`browser`,`setup-entry`,`setup-entry`)},{...pluginRuntimeProcess(`code-mode-quickjs`,`src/executor`,`src/code-mode.worker`)},pluginRuntimeProcess(`codex`,`stdio-worker-entrypoint`,`stdio.worker`),pluginRuntimeProcess(`codex`,`catalog-page-worker-entrypoint`,`catalog-page.worker`),pluginRuntimeProcess(`codex`,`session-history-worker-entrypoint`,`session-history.worker`),{...pluginRuntimeProcess(`discord`,`src/voice/audio-worker-thread`,`src/voice/audio-worker.runtime`)},{...pluginRuntimeProcess(`document-extract`,`document-extractor-worker-entrypoint`,`document-extractor.worker`)},{...pluginRuntimeProcess(`web-readability`,`web-content-extractor-worker.runtime`,`web-content-extractor.worker`)},{...pluginRuntimeProcess(`imessage`,`src/chat-db`,`src/chat-db.worker`)},{...pluginRuntimeProcess(`knowledge`,`src/registry-client`,`src/registry-worker`)},{...pluginRuntimeProcess(`knowledge`,`src/storage-client`,`src/storage-worker`)},{...pluginRuntimeProcess(`memory-core`,`src/memory/manager-cpu-entrypoints`,`src/memory/manager-search.worker`)},{...pluginRuntimeProcess(`memory-core`,`src/memory/manager-cpu-entrypoints`,`src/memory/manager-index.worker`)},{...pluginRuntimeProcess(`memory-core`,`src/memory/manager-cpu-entrypoints`,`src/memory/manager-publication.worker`)},{...pluginRuntimeProcess(`memory-core`,`src/memory/manager-cpu-entrypoints`,`src/standing-intents.worker`)},{...pluginRuntimeProcess(`memory-core`,`src/memory/manager-cpu-entrypoints`,`src/memory-entry-origins.worker`)},pluginRuntimeProcess(`memory-lancedb`,`memory-stats-entrypoint`,`memory-stats.worker`),{...pluginRuntimeProcess(`memory-wiki`,`src/query-reader`,`src/query-reader.worker`)},{...pluginRuntimeProcess(`openai`,`realtime-quicksilver-peer.runtime`,`realtime-quicksilver-audio.worker`)},{...pluginRuntimeProcess(`openai`,`realtime-quicksilver-socket`,`realtime-quicksilver-socket.worker`)},{...pluginRuntimeProcess(`qa-lab`,`src/execution-identity-storage-inspection`,`src/execution-identity-storage-inspection.worker`)},{...pluginRuntimeProcess(`telegram`,`src/telegram-ingress-worker`,`src/telegram-ingress-worker.runtime`)},{...pluginRuntimeProcess(`telegram`,`src/widgets/widget-check`,`src/widgets/widget-check.worker`)},pluginRuntimeProcess(`onnx`,`index`,`src/inference.worker`),pluginRuntimeProcess(`team-reports`,`index`,`src/store.worker`),pluginRuntimeProcess(`team-reports`,`index`,`src/run.worker`),pluginRuntimeProcess(`logbook`,`index`,`src/store.worker`),pluginRuntimeProcess(`workboard`,`index`,`src/sqlite-store.worker`),y={bunSqliteLibraryProbe:{buildSource:`src/infra/bun-sqlite-library-probe.entry.ts`,sourceModule:`src/infra/bun-sqlite-library-probe.generated.ts`,sourceBinding:`BUN_SQLITE_LIBRARY_PROBE_SOURCE`,kind:`file`,fileName:`bun-sqlite-library-probe.mjs`,materialize:!0},packageCliNodeProbe:{buildSource:`scripts/lib/package-cli-node-probe.entry.mjs`,sourceModule:`scripts/lib/package-cli-node-probe.generated.mjs`,sourceBinding:`PACKAGE_CLI_NODE_PROBE_SOURCE`,kind:`file`,fileName:`package-cli-node-probe.mjs`,materialize:!0},fsSafeNpmCliPreload:{buildSource:`scripts/lib/fs-safe-npm-cli-preload.entry.mjs`,sourceModule:`scripts/lib/fs-safe-npm-cli-preload.generated.mjs`,sourceBinding:`FS_SAFE_NPM_CLI_PRELOAD_DATA_URL`,kind:`data-url`},repositoryPublicationRestoreRemote:{sourceModule:`src/gateway/github-repository-publication-restore.ts`,sourceBinding:`RESTORE_PUBLICATION_INDEX_JS`,kind:`source`},nodeRuntimeProbe:{buildSource:`src/infra/node-runtime-probe.entry.ts`,sourceModule:`src/infra/node-runtime-probe.generated.mjs`,sourceBinding:`NODE_RUNTIME_PROBE_SOURCE`,kind:`file`,fileName:`node-runtime-probe.mjs`,materialize:!0},daemonRuntimeProbe:{buildSource:`src/infra/daemon-runtime-probe.entry.ts`,sourceModule:`src/infra/daemon-runtime-probe.generated.mjs`,sourceBinding:`DAEMON_RUNTIME_PROBE_SOURCE`,kind:`file`,fileName:`daemon-runtime-probe.mjs`,materialize:!0,runtimeEntrypoint:`daemonRuntimeProbe`},updateStateSizes:{sourceModule:`src/infra/update-state-sizes.generated.mjs`,sourceBinding:`UPDATE_STATE_SIZES_SOURCE`,kind:`file`,fileName:`update-state-sizes.mjs`,materialize:!0,runtimeEntrypoint:`updateStateSizes`},updateNativeGate:{sourceModule:`src/cli/update-cli/update-command-native-gate.generated.ts`,sourceBinding:`UPDATE_NATIVE_GATE_SOURCE`,kind:`file`,fileName:`update-native-gate.mjs`},managedUpdateHandoff:{sourceModule:`src/infra/update-managed-service-handoff.ts`,sourceBinding:`HANDOFF_SCRIPT`,kind:`file`,fileName:`handoff.cjs`},workspaceQuiescence:{sourceModule:`src/gateway/worker-environments/workspace-quiescence-scripts.ts`,export:`workspaceQuiescenceArgv`,kind:`argv`}}}))();function materializeRuntimeProcessScriptFile(e,n={}){let i=r.mkdtempSync(t.join(n.parentDirectory??f.tmpdir(),`openclaw-script-`)),a=t.join(i,e.fileName),o=!1,dispose=()=>{if(!o)try{r.rmSync(i,{recursive:!0,force:!0}),o=!0}catch(e){process.emitWarning(`Runtime script cleanup failed at ${i}: ${e instanceof Error?e.message:String(e)}`)}};try{return r.writeFileSync(a,e.source,{mode:384,flag:`wx`}),{url:u(a),dispose}}catch(e){throw dispose(),e}}function probeBunSqliteLibrary(e){let n=materializeRuntimeProcessScriptFile({fileName:y.bunSqliteLibraryProbe.fileName,source:`import{createRequire}from"node:module";try{const candidate=process.argv[2];if(!candidate||process.argv.length!==3){throw new Error("Expected one SQLite library path")}const require2=createRequire(import.meta.url);const{Database}=require2("bun:sqlite");Database.setCustomSQLite(candidate);const database=new Database(":memory:");let facts;try{facts=database.query("SELECT sqlite_version() AS version, sqlite_compileoption_used('OMIT_LOAD_EXTENSION') AS omitted").get()}finally{database.close()}process.stdout.write(JSON.stringify({protocol:1,version:facts.version,extensionLoadingSupported:facts.omitted===0}))}catch(error){process.stdout.write(JSON.stringify({protocol:1,error:(error instanceof Error?error.message:String(error)).slice(0,512)}));process.exitCode=1} `});try{let i=l(n.url),a=t.dirname(i),o=t.join(a,`bunfig.toml`);r.writeFileSync(o,``,{mode:384,flag:`wx`});let s={};for(let e of[`SystemRoot`,`SYSTEMROOT`,`WINDIR`,`TEMP`,`TMP`,`TMPDIR`])process.env[e]&&(s[e]=process.env[e]);let c=d(process.execPath,[`--no-install`,`--no-env-file`,`--config=${o}`,i,t.resolve(e)],{cwd:a,env:resolveRuntimeScriptEnv(s),encoding:`utf8`,stdio:[`ignore`,`pipe`,`pipe`],timeout:5e3,killSignal:`SIGKILL`,maxBuffer:4096});if(c.error)throw c.error;let u;try{u=JSON.parse(c.stdout)}catch{throw Error(`SQLite library probe returned invalid output`)}if(typeof u!=`object`||!u||Array.isArray(u)||!(`protocol`in u)||u.protocol!==1)throw Error(`SQLite library probe returned invalid output`);if(c.status!==0)throw Error(`error`in u&&typeof u.error==`string`?u.error.slice(0,512):`SQLite library probe failed (${c.signal??c.status})`);if(!(`version`in u)||typeof u.version!=`string`||u.version.length>64||!(`extensionLoadingSupported`in u)||typeof u.extensionLoadingSupported!=`boolean`)throw Error(`SQLite library probe returned invalid output`);return{version:u.version,extensionLoadingSupported:u.extensionLoadingSupported}}finally{n.dispose()}}_();const b=`openclaw.bunSqliteLibrarySelection`;function selectLibrary(t){let{Database:n}=e(import.meta.url)(`bun:sqlite`);n.setCustomSQLite(t)}function createSelector(){let e,t;return(r={})=>{if(t)throw t;if(e)return e;let a=r.explicitPath??(process.env.OPENCLAW_SQLITE_LIBRARY?.trim()||void 0);if(!process.versions.bun||process.platform!==`darwin`)return e=a?{source:`runtime`,ignoredOverride:`OPENCLAW_SQLITE_LIBRARY requires Bun on macOS`}:{source:`runtime`},e;let o=r.standaloneRoot??resolveStandaloneSidecarRoot(),s=a===void 0&&o!==void 0?n.join(o,`lib/libsqlite3.dylib`):void 0,c=process.env.HOMEBREW_PREFIX?.trim(),l=a===void 0?[.../* @__PURE__ */ new Set([...s?[s]:[],...c?[n.join(c,`opt/sqlite/lib/libsqlite3.dylib`)]:[],`/opt/homebrew/opt/sqlite/lib/libsqlite3.dylib`,`/usr/local/opt/sqlite/lib/libsqlite3.dylib`,`/opt/local/lib/libsqlite3.dylib`])]:[a],u=[];for(let n of l){let r=a===void 0?n===s?`bundled`:`discovered`:`env`,o,c=!0;try{try{o=probeBunSqliteLibrary(n)}catch(e){throw c=i(n),c?e:Error(`missing file`,{cause:e})}if(!isSqliteWalResetSafeVersion(o.version))throw Error(`SQLite version ${o.version} below the WAL safety floor`);if(!o.extensionLoadingSupported)throw Error(`built with SQLITE_OMIT_LOAD_EXTENSION`)}catch(e){if(a===void 0){(c||n===s)&&u.push(`${n} (${e instanceof Error?e.message:String(e)})`);continue}throw t=selectionError(n,e,r===`bundled`),t}try{selectLibrary(n)}catch(e){throw t=selectionError(n,e,r===`bundled`),t}return e={source:r,path:n,version:o.version,extensionLoadingSupported:!0},e}throw t=/* @__PURE__ */ Error(`No supported SQLite library for Bun on macOS (${process.arch})`+(u.length>0?`; unusable: ${u.join(`, `)}`:``)+`. Apple's system SQLite fails OpenClaw's read-only database connections. `+(s?`Rebuild or replace the complete standalone artifact to restore its bundled SQLite library. `:``)+`Install one with brew install sqlite, or set OPENCLAW_SQLITE_LIBRARY to a libsqlite3.dylib built for ${process.arch}.`),t}}function selectionError(e,t,n=!1){let r=n?`Rebuild or replace the complete standalone artifact (openclaw and runtime/), or set OPENCLAW_SQLITE_LIBRARY to a supported library.`:`Fix or unset OPENCLAW_SQLITE_LIBRARY; install a supported library with brew install sqlite.`;return Error(`Cannot use ${n?`bundled `:``}SQLite library ${e}: ${t instanceof Error?t.message:String(t)}. ${r}`,{cause:t})}function createRuntimeSelector(){let e=!!process.versions.bun&&process.platform===`darwin`,t;e&&!s&&(t=o(b));let n=createSelector(),r=!1;return i=>{let a=t??n(i);return e&&s&&!r&&(c(b,Object.freeze({...a})),r=!0),a}}function runtimeSelector(){return resolveGlobalSingleton(Symbol.for(`openclaw.bunSqliteLibrarySelection`),createRuntimeSelector)}function ensureSqliteLibrarySelected(e){return runtimeSelector()(e)}async function readRuntimeProbeInfo(e,n){let r=null,i=null,a=null,o={available:!1,version:null,text:!1,blob:!1,json:!1};if(e===`bun`)try{let e=ensureSqliteLibrarySelected({standaloneRoot:n});`path`in e&&(a=t.resolve(e.path))}catch(e){i=e instanceof Error?e.message:String(e)}if(i===null)try{let{DatabaseSync:e}=await import(`node:sqlite`);o=probeSqlite(e),r=o.version}catch{}let s=process.config?.variables?.node_shared_sqlite,c=s===!0||s===`true`;return{nodeVersion:process.versions.node,bunVersion:process.versions.bun??null,sqliteVersion:r,sqliteProbe:o,sqliteSelectionError:i,sqliteLibraryPath:a,nodeSharedSqlite:c}}process.stdout.write(JSON.stringify(await readRuntimeProbeInfo(process.argv[2]===`bun`?`bun`:`node`,process.argv[3]||void 0)));export{};