Skip to content

Commit a8cdd4e

Browse files
igorcostaAutohand Evolve
andcommitted
Repair obsolete control-plane API configuration
Normalize saved Autohand website deployment origins to the canonical control-plane API while preserving explicit development overrides. This restores announcements and other authenticated API features for affected installations. Co-authored-by: Autohand Evolve <code-noreply@autohand.ai>
1 parent 09d5c04 commit a8cdd4e

3 files changed

Lines changed: 78 additions & 3 deletions

File tree

‎docs/config-reference.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,11 @@ Backend API configuration for team features.
14231423
| `baseUrl` | string | `https://api.autohand.ai` | API endpoint |
14241424
| `companySecret` | string | - | Team/company secret for shared features |
14251425

1426+
`api.baseUrl` must point to the Autohand control-plane API, not the Autohand website. Saved
1427+
`*.autohand-web.pages.dev` website deployment URLs are repaired to the canonical API during
1428+
config loading. Explicit `AUTOHAND_API_URL` overrides remain unchanged for development and
1429+
staging environments.
1430+
14261431
Can also be set via environment variables:
14271432

14281433
- `AUTOHAND_API_URL` → `api.baseUrl`

‎src/config.ts‎

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const DEFAULT_SAKANA_URL = "https://api.sakana.ai/v1";
4545
const DEFAULT_DEEPSEEK_URL = "https://api.deepseek.com";
4646
const DEFAULT_BEDROCK_REGION = "us-east-1";
4747
const DEFAULT_AUTOHAND_AI_URL = "https://api.autohand.ai/v1";
48+
const DEFAULT_CONTROL_PLANE_API_URL = "https://api.autohand.ai";
4849

4950
interface LegacyConfigShape {
5051
api_key?: string;
@@ -610,6 +611,27 @@ function mergeWorkspaceSettings(
610611
return merged;
611612
}
612613

614+
function normalizeSavedApiBaseUrl(baseUrl: string | undefined): string | undefined {
615+
const normalized = baseUrl?.trim();
616+
if (!normalized) {
617+
return undefined;
618+
}
619+
620+
try {
621+
const hostname = new URL(normalized).hostname.toLowerCase();
622+
if (
623+
hostname === "autohand-web.pages.dev"
624+
|| hostname.endsWith(".autohand-web.pages.dev")
625+
) {
626+
return DEFAULT_CONTROL_PLANE_API_URL;
627+
}
628+
} catch {
629+
return normalized;
630+
}
631+
632+
return normalized;
633+
}
634+
613635
/**
614636
* Merge environment variables into config
615637
* Env vars take precedence over config file values
@@ -620,8 +642,8 @@ function mergeEnvVariables(config: AutohandConfig): AutohandConfig {
620642
api: {
621643
baseUrl:
622644
process.env.AUTOHAND_API_URL ||
623-
config.api?.baseUrl ||
624-
"https://api.autohand.ai",
645+
normalizeSavedApiBaseUrl(config.api?.baseUrl) ||
646+
DEFAULT_CONTROL_PLANE_API_URL,
625647
companySecret:
626648
process.env.AUTOHAND_SECRET || config.api?.companySecret || "",
627649
},

‎tests/config.test.ts‎

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,17 @@
77
import fs from 'fs-extra';
88
import path from 'node:path';
99
import os from 'node:os';
10-
import { describe, expect, it } from 'vitest';
10+
import { afterEach, describe, expect, it } from 'vitest';
1111
import { getProviderConfig, loadConfig } from '../src/config';
1212
import type { AutohandConfig } from '../src/types';
1313

14+
const originalApiUrl = process.env.AUTOHAND_API_URL;
15+
16+
afterEach(() => {
17+
if (originalApiUrl === undefined) delete process.env.AUTOHAND_API_URL;
18+
else process.env.AUTOHAND_API_URL = originalApiUrl;
19+
});
20+
1421
describe('getProviderConfig', () => {
1522
it('creates new configs with completion reports enabled by default', async () => {
1623
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'autohand-config-'));
@@ -48,6 +55,47 @@ describe('getProviderConfig', () => {
4855
}
4956
});
5057

58+
it('repairs a saved website deployment URL used as the control-plane API', async () => {
59+
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'autohand-config-'));
60+
const configPath = path.join(tempDir, 'config.json');
61+
62+
await fs.writeJson(configPath, {
63+
provider: 'openrouter',
64+
api: {
65+
baseUrl: 'https://e2d1306c.autohand-web.pages.dev',
66+
},
67+
});
68+
69+
try {
70+
const config = await loadConfig(configPath);
71+
72+
expect(config.api?.baseUrl).toBe('https://api.autohand.ai');
73+
} finally {
74+
await fs.remove(tempDir);
75+
}
76+
});
77+
78+
it('preserves an explicit website deployment API override for development', async () => {
79+
const tempDir = await fs.mkdtemp(path.join(os.tmpdir(), 'autohand-config-'));
80+
const configPath = path.join(tempDir, 'config.json');
81+
process.env.AUTOHAND_API_URL = 'https://preview.autohand-web.pages.dev';
82+
83+
await fs.writeJson(configPath, {
84+
provider: 'openrouter',
85+
api: {
86+
baseUrl: 'https://api.autohand.ai',
87+
},
88+
});
89+
90+
try {
91+
const config = await loadConfig(configPath);
92+
93+
expect(config.api?.baseUrl).toBe('https://preview.autohand-web.pages.dev');
94+
} finally {
95+
await fs.remove(tempDir);
96+
}
97+
});
98+
5199
it('allows llama.cpp config without an explicit model', () => {
52100
const config = {
53101
provider: 'llamacpp',

0 commit comments

Comments
 (0)