openwork-orchestrator 0.11.176 → 0.11.178

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.
package/bin/openwork CHANGED
@@ -1,6 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
3
  const childProcess = require("child_process")
4
+ const fs = require("fs")
4
5
  const os = require("os")
5
6
  const path = require("path")
6
7
 
@@ -45,14 +46,18 @@ if (!arch) {
45
46
 
46
47
  const pkg = `openwork-orchestrator-${platform}-${arch}`
47
48
  const binary = platform === "windows" ? "openwork.exe" : "openwork"
49
+ const fallback = path.join(__dirname, "..", "dist", "bin", binary)
48
50
 
49
51
  let pkgJsonPath
50
52
  try {
51
53
  pkgJsonPath = require.resolve(`${pkg}/package.json`)
52
54
  } catch {
55
+ if (fs.existsSync(fallback)) {
56
+ run(fallback)
57
+ }
53
58
  console.error(
54
59
  `openwork: no prebuilt binary package found for ${platform}/${arch}.\n` +
55
- `Try installing the platform package manually: ${pkg}`,
60
+ `Try reinstalling openwork-orchestrator or installing the platform package manually: ${pkg}`,
56
61
  )
57
62
  process.exit(1)
58
63
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "openwork-orchestrator",
3
- "version": "0.11.176",
3
+ "version": "0.11.178",
4
4
  "description": "OpenWork host orchestrator for opencode + OpenWork server + opencode-router",
5
5
  "license": "MIT",
6
6
  "bin": {
@@ -8,14 +8,14 @@
8
8
  "openwork-orchestrator": "./bin/openwork"
9
9
  },
10
10
  "scripts": {
11
- "postinstall": "bun ./postinstall.mjs || node ./postinstall.mjs"
11
+ "postinstall": "node ./postinstall.mjs"
12
12
  },
13
13
  "optionalDependencies": {
14
- "openwork-orchestrator-darwin-arm64": "0.11.176",
15
- "openwork-orchestrator-darwin-x64": "0.11.176",
16
- "openwork-orchestrator-linux-x64": "0.11.176",
17
- "openwork-orchestrator-linux-arm64": "0.11.176",
18
- "openwork-orchestrator-windows-x64": "0.11.176"
14
+ "openwork-orchestrator-darwin-arm64": "0.11.178",
15
+ "openwork-orchestrator-darwin-x64": "0.11.178",
16
+ "openwork-orchestrator-linux-x64": "0.11.178",
17
+ "openwork-orchestrator-linux-arm64": "0.11.178",
18
+ "openwork-orchestrator-windows-x64": "0.11.178"
19
19
  },
20
20
  "files": [
21
21
  "bin",
package/postinstall.mjs CHANGED
@@ -1,9 +1,13 @@
1
1
  #!/usr/bin/env node
2
2
 
3
+ import { chmodSync, existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs"
4
+ import { dirname, join } from "node:path"
3
5
  import os from "os"
4
6
  import { createRequire } from "module"
7
+ import { fileURLToPath } from "node:url"
5
8
 
6
9
  const require = createRequire(import.meta.url)
10
+ const rootDir = dirname(fileURLToPath(import.meta.url))
7
11
 
8
12
  function detect() {
9
13
  const platformMap = {
@@ -22,21 +26,90 @@ function detect() {
22
26
  return { platform, arch }
23
27
  }
24
28
 
25
- function name() {
29
+ function packageName() {
26
30
  const { platform, arch } = detect()
27
31
  return `openwork-orchestrator-${platform}-${arch}`
28
32
  }
29
33
 
30
- try {
31
- const pkg = name()
32
- require.resolve(`${pkg}/package.json`)
33
- console.log(`openwork-orchestrator: verified platform package: ${pkg}`)
34
- } catch (error) {
35
- const pkg = name()
36
- console.error(
37
- `openwork-orchestrator: failed to locate platform binary package (${pkg}).\n` +
38
- `Your package manager may have skipped optionalDependencies.\n` +
39
- `Try installing it manually: npm i -g ${pkg}`,
40
- )
41
- process.exit(1)
34
+ function binaryName() {
35
+ const { platform } = detect()
36
+ return platform === "windows" ? "openwork.exe" : "openwork"
42
37
  }
38
+
39
+ function fallbackAssetName() {
40
+ const { platform, arch } = detect()
41
+ return `openwork-bun-${platform}-${arch}${platform === "windows" ? ".exe" : ""}`
42
+ }
43
+
44
+ function fallbackBinaryPath() {
45
+ return join(rootDir, "dist", "bin", binaryName())
46
+ }
47
+
48
+ function readOwnVersion() {
49
+ const pkg = JSON.parse(readFileSync(join(rootDir, "package.json"), "utf8"))
50
+ const version = String(pkg.version || "").trim()
51
+ if (!version) {
52
+ throw new Error("openwork-orchestrator: package version is missing")
53
+ }
54
+ return version
55
+ }
56
+
57
+ function resolveFallbackBaseUrl(version) {
58
+ const override = String(process.env.OPENWORK_ORCHESTRATOR_DOWNLOAD_BASE_URL || "").trim()
59
+ if (override) {
60
+ return override.replace(/\/$/, "")
61
+ }
62
+ return `https://github.com/different-ai/openwork/releases/download/openwork-orchestrator-v${version}`
63
+ }
64
+
65
+ async function downloadFallbackBinary() {
66
+ const version = readOwnVersion()
67
+ const asset = fallbackAssetName()
68
+ const url = `${resolveFallbackBaseUrl(version)}/${asset}`
69
+ const destination = fallbackBinaryPath()
70
+
71
+ console.log(`openwork-orchestrator: downloading fallback binary ${asset}`)
72
+ const response = await fetch(url)
73
+ if (!response.ok) {
74
+ throw new Error(`download failed (${response.status} ${response.statusText}) from ${url}`)
75
+ }
76
+
77
+ const buffer = Buffer.from(await response.arrayBuffer())
78
+ mkdirSync(dirname(destination), { recursive: true })
79
+ writeFileSync(destination, buffer)
80
+ if (binaryName() !== "openwork.exe") {
81
+ chmodSync(destination, 0o755)
82
+ }
83
+
84
+ console.log(`openwork-orchestrator: installed fallback binary at ${destination}`)
85
+ }
86
+
87
+ async function main() {
88
+ try {
89
+ const pkg = packageName()
90
+ require.resolve(`${pkg}/package.json`)
91
+ console.log(`openwork-orchestrator: verified platform package: ${pkg}`)
92
+ return
93
+ } catch {
94
+ if (existsSync(fallbackBinaryPath())) {
95
+ console.log(`openwork-orchestrator: using existing fallback binary at ${fallbackBinaryPath()}`)
96
+ return
97
+ }
98
+ }
99
+
100
+ try {
101
+ await downloadFallbackBinary()
102
+ } catch (error) {
103
+ const pkg = packageName()
104
+ const message = error instanceof Error ? error.message : String(error)
105
+ console.error(
106
+ `openwork-orchestrator: failed to locate platform binary package (${pkg}).\n` +
107
+ `Your package manager may have skipped optionalDependencies, or the package asset is unavailable.\n` +
108
+ `Fallback download failed: ${message}\n` +
109
+ `Try installing it manually: npm i -g ${pkg}`,
110
+ )
111
+ process.exit(1)
112
+ }
113
+ }
114
+
115
+ await main()