Skip to content

Open source CapCut alternative.

TypeScript

Use web base URL for Mac inference

David Lea9beeb4b81be
diff --git a/apps/Donkey/Sources/DonkeyAI/DonkeyBackendInferenceClient.swift b/apps/Donkey/Sources/DonkeyAI/DonkeyBackendInferenceClient.swift
index 201da31c..bba17007 100644
--- a/apps/Donkey/Sources/DonkeyAI/DonkeyBackendInferenceClient.swift
+++ b/apps/Donkey/Sources/DonkeyAI/DonkeyBackendInferenceClient.swift
@@ -13,7 +13,7 @@ public enum DonkeyBackendInferenceClientError: Error, Equatable, Sendable {
public struct DonkeyBackendInferenceConfiguration: Equatable, Sendable {
public var baseURL: URL
public var clientID: String
- public static let baseURLConfigurationDescription = "DONKEY_BACKEND_URL, DONKEY_WEB_BASE_URL, or BETTER_AUTH_URL"
+ public static let baseURLConfigurationDescription = "DONKEY_WEB_BASE_URL"
public init(baseURL: URL, clientID: String) {
self.baseURL = baseURL
@@ -24,10 +24,11 @@ public struct DonkeyBackendInferenceConfiguration: Equatable, Sendable {
_ environment: [String: String] = ProcessInfo.processInfo.environment,
bundle: Bundle = .main
) throws -> DonkeyBackendInferenceConfiguration {
- guard let baseURLString = configuredBaseURLString(
+ let baseURLString = configuredBaseURLString(
environment: environment,
bundle: bundle
- ),
+ )
+ guard let baseURLString,
let baseURL = URL(string: baseURLString) else {
throw DonkeyBackendInferenceClientError.missingConfiguration(
baseURLConfigurationDescription
@@ -44,10 +45,7 @@ public struct DonkeyBackendInferenceConfiguration: Equatable, Sendable {
environment: [String: String],
bundle: Bundle
) -> String? {
- trimmed(environment["DONKEY_BACKEND_URL"])
- ?? trimmed(environment["DONKEY_WEB_BASE_URL"])
- ?? trimmed(environment["BETTER_AUTH_URL"])
- ?? configuredBundleValue("DonkeyBackendURL", bundle: bundle)
+ trimmed(environment["DONKEY_WEB_BASE_URL"])
?? configuredBundleValue("DonkeyWebBaseURL", bundle: bundle)
}
diff --git a/apps/Donkey/Tests/DonkeyRuntimeTests/DonkeyBackendInferenceClientTests.swift b/apps/Donkey/Tests/DonkeyRuntimeTests/DonkeyBackendInferenceClientTests.swift
index e42c67ca..474d4861 100644
--- a/apps/Donkey/Tests/DonkeyRuntimeTests/DonkeyBackendInferenceClientTests.swift
+++ b/apps/Donkey/Tests/DonkeyRuntimeTests/DonkeyBackendInferenceClientTests.swift
@@ -65,30 +65,49 @@ struct DonkeyBackendInferenceClientTests {
}
@Test
- func configurationPrefersDedicatedBackendEnvironmentURL() throws {
+ func configurationUsesWebBaseEnvironmentURL() throws {
let configuration = try DonkeyBackendInferenceConfiguration.fromEnvironment([
- "DONKEY_BACKEND_URL": "https://api.donkey.example",
"DONKEY_WEB_BASE_URL": "https://web.donkey.example",
+ "DONKEY_BACKEND_URL": "https://api.donkey.example",
+ "BETTER_AUTH_URL": "https://auth.donkey.example",
"DONKEY_CLIENT_ID": "client-env"
])
- #expect(configuration.baseURL.absoluteString == "https://api.donkey.example")
+ #expect(configuration.baseURL.absoluteString == "https://web.donkey.example")
#expect(configuration.clientID == "client-env")
}
@Test
- func configurationFallsBackToWebBaseEnvironmentURL() throws {
- let configuration = try DonkeyBackendInferenceConfiguration.fromEnvironment([
- "DONKEY_WEB_BASE_URL": "https://web.donkey.example",
- "DONKEY_CLIENT_ID": "client-env"
+ func configurationUsesBundledWebBaseURL() throws {
+ let fixture = try temporaryBundle(info: [
+ "DonkeyWebBaseURL": "https://bundle.donkey.example"
])
+ defer {
+ try? FileManager.default.removeItem(at: fixture.directory)
+ }
- #expect(configuration.baseURL.absoluteString == "https://web.donkey.example")
+ let configuration = try DonkeyBackendInferenceConfiguration.fromEnvironment(
+ ["DONKEY_CLIENT_ID": "client-env"],
+ bundle: fixture.bundle
+ )
+
+ #expect(configuration.baseURL.absoluteString == "https://bundle.donkey.example")
#expect(configuration.clientID == "client-env")
}
@Test
- func configurationEnvironmentOverridesBundledBackendURL() throws {
+ func configurationDoesNotUseBackendEnvironmentURLAsBaseURL() {
+ #expect(throws: DonkeyBackendInferenceClientError.missingConfiguration("DONKEY_WEB_BASE_URL")) {
+ _ = try DonkeyBackendInferenceConfiguration.fromEnvironment([
+ "DONKEY_BACKEND_URL": "https://api.donkey.example",
+ "BETTER_AUTH_URL": "https://auth.donkey.example",
+ "DONKEY_CLIENT_ID": "client-env"
+ ])
+ }
+ }
+
+ @Test
+ func configurationDoesNotUseBundledBackendURLAsBaseURL() throws {
let fixture = try temporaryBundle(info: [
"DonkeyBackendURL": "https://bundle-api.donkey.example"
])
@@ -96,6 +115,23 @@ struct DonkeyBackendInferenceClientTests {
try? FileManager.default.removeItem(at: fixture.directory)
}
+ #expect(throws: DonkeyBackendInferenceClientError.missingConfiguration("DONKEY_WEB_BASE_URL")) {
+ _ = try DonkeyBackendInferenceConfiguration.fromEnvironment(
+ ["DONKEY_CLIENT_ID": "client-env"],
+ bundle: fixture.bundle
+ )
+ }
+ }
+
+ @Test
+ func configurationEnvironmentWebBaseURLOverridesBundledWebBaseURL() throws {
+ let fixture = try temporaryBundle(info: [
+ "DonkeyWebBaseURL": "https://bundle.donkey.example"
+ ])
+ defer {
+ try? FileManager.default.removeItem(at: fixture.directory)
+ }
+
let configuration = try DonkeyBackendInferenceConfiguration.fromEnvironment(
[
"DONKEY_WEB_BASE_URL": "https://web.donkey.example",
@@ -109,7 +145,7 @@ struct DonkeyBackendInferenceClientTests {
}
@Test
- func configurationFallsBackToBundledWebBaseURL() throws {
+ func invalidEnvironmentWebBaseURLDoesNotUseBundledWebBaseURL() throws {
let fixture = try temporaryBundle(info: [
"DonkeyWebBaseURL": "https://bundle.donkey.example"
])
@@ -117,13 +153,15 @@ struct DonkeyBackendInferenceClientTests {
try? FileManager.default.removeItem(at: fixture.directory)
}
- let configuration = try DonkeyBackendInferenceConfiguration.fromEnvironment(
- ["DONKEY_CLIENT_ID": "client-env"],
- bundle: fixture.bundle
- )
-
- #expect(configuration.baseURL.absoluteString == "https://bundle.donkey.example")
- #expect(configuration.clientID == "client-env")
+ #expect(throws: DonkeyBackendInferenceClientError.missingConfiguration("DONKEY_WEB_BASE_URL")) {
+ _ = try DonkeyBackendInferenceConfiguration.fromEnvironment(
+ [
+ "DONKEY_WEB_BASE_URL": "not a url",
+ "DONKEY_CLIENT_ID": "client-env"
+ ],
+ bundle: fixture.bundle
+ )
+ }
}
@Test
diff --git a/docs/guides/install-donkey.md b/docs/guides/install-donkey.md
index bbc0c706..d5e40536 100644
--- a/docs/guides/install-donkey.md
+++ b/docs/guides/install-donkey.md
@@ -16,26 +16,20 @@ The script builds the release executable, creates `dist/Donkey.app`, copies bund
The app bundle version defaults to `0.1.0` build `1`. Override it for local release testing:
```bash
-DONKEY_APP_VERSION="0.1.1" DONKEY_APP_BUILD="2" ./scripts/package-donkey-app.sh
+DONKEY_APP_VERSION="0.1.1" \
+DONKEY_APP_BUILD="2" \
+./scripts/package-donkey-app.sh
```
The app bundle registers the `donkey://auth/callback` sign-in callback and
opens the site `/mac-auth` handoff for Google OAuth before the overlay starts.
-Packaged apps point auth and hosted inference at `https://donkeyuse.com` by
-default. Override the web base URL only for local or staging testing:
+Packaged apps point auth and hosted inference at the same base URL:
+`https://donkeyuse.com` by default.
-```bash
-DONKEY_WEB_BASE_URL="http://localhost:3000" ./scripts/package-donkey-app.sh
-```
-
-If hosted inference is served from a different origin than auth, set
-`DONKEY_BACKEND_URL`; otherwise the packaged app uses `DONKEY_WEB_BASE_URL` for
-both:
+Override the single base URL for local or staging testing:
```bash
-DONKEY_WEB_BASE_URL="https://staging.example" \
-DONKEY_BACKEND_URL="https://api.staging.example" \
-./scripts/package-donkey-app.sh
+DONKEY_WEB_BASE_URL="http://localhost:3000" ./scripts/package-donkey-app.sh
```
For distribution through the site, publish the disk image:
diff --git a/scripts/package-donkey-app.sh b/scripts/package-donkey-app.sh
index e87f2336..b34bff44 100755
--- a/scripts/package-donkey-app.sh
+++ b/scripts/package-donkey-app.sh
@@ -10,7 +10,6 @@ RUNTIME_PACKAGE_DIR="$ROOT_DIR/dist/LocalRuntimePackages"
APP_VERSION="${DONKEY_APP_VERSION:-0.1.0}"
APP_BUILD="${DONKEY_APP_BUILD:-1}"
WEB_BASE_URL="${DONKEY_WEB_BASE_URL:-https://donkeyuse.com}"
-BACKEND_BASE_URL="${DONKEY_BACKEND_URL:-$WEB_BASE_URL}"
AUTH_CALLBACK_SCHEME="${DONKEY_AUTH_CALLBACK_SCHEME:-donkey}"
SPARKLE_FEED_URL="${DONKEY_SPARKLE_FEED_URL:-}"
SPARKLE_PUBLIC_ED_KEY="${DONKEY_SPARKLE_PUBLIC_ED_KEY:-}"
@@ -222,8 +221,6 @@ cat > "$CONTENTS_DIR/Info.plist" <<PLIST
<string>14.0</string>
<key>DonkeyWebBaseURL</key>
<string>$WEB_BASE_URL</string>
- <key>DonkeyBackendURL</key>
- <string>$BACKEND_BASE_URL</string>
<key>DonkeyAuthCallbackScheme</key>
<string>$AUTH_CALLBACK_SCHEME</string>
<key>CFBundleURLTypes</key>
diff --git a/scripts/run-donkey-dev.sh b/scripts/run-donkey-dev.sh
index cd80c107..f2cdc4e1 100755
--- a/scripts/run-donkey-dev.sh
+++ b/scripts/run-donkey-dev.sh
@@ -7,6 +7,8 @@ LOG_SCRIPT="$ROOT_DIR/scripts/tail-donkey-logs.sh"
DONKEY_BIN="$APP_DIR/.build/debug/Donkey"
LOG_PID=""
+export DONKEY_WEB_BASE_URL="${DONKEY_WEB_BASE_URL:-http://localhost:3000}"
+
cleanup() {
if [ -n "$LOG_PID" ] && kill -0 "$LOG_PID" >/dev/null 2>&1; then
kill "$LOG_PID" >/dev/null 2>&1 || true