HarnessRouter Community Edition: the self-hosted, Apache-2.0 edition of the unified interface for agent harnesses. Run Codex, Claude Code, Hermes, PI, DSH, and more through one API, with sessions, streaming, files, cancellation, and failure handling. Implements the Unified Harness Protocol (UHP), an open standard. Your keys, your infrastructure.
Python agent-apiagent-frameworkagent-harnessai-agentsai-infrastructurecoding-agentconformance-testingdeepseek-harnessharness-engineeringhermesllmopen-protocolopen-sourceopen-standardpi-coding-agentself-hosteduhpunified-apiunified-harness-protocolunified-interface
Fix custom provider model IDs and show compatible harness bases (#453)
harikiran-laba957121969f2
diff --git a/docs/self-hosting-guide.md b/docs/self-hosting-guide.mdindex d7e71833..f304e3e6 100644--- a/docs/self-hosting-guide.md+++ b/docs/self-hosting-guide.md@@ -271,11 +271,17 @@ integration there is nothing to set.Pick the **Custom** provider. It asks for the API format the endpoint speaks (OpenAI ChatCompletions, OpenAI Responses for Codex, or Anthropic Messages), the endpoint URL, the key, and-the **models** it serves. Each model row pairs the id a harness picks (the same ids every other-provider uses, `gpt-5.5`, `claude-opus-4.8`) with the name this endpoint wants on the wire. That+the **models** it serves. In **Model**, type any id, including one absent from the suggested+catalog. Each row pairs that id, which a harness picks, with the name this endpoint wants on the wire. Thatname is an arbitrary string per row and is sent verbatim: a bare vendor id, a deployment alias, aversioned SKU. Leave it blank to send the model id as it is. No transform is applied, because the-name a proxy expects is a fact about that proxy and nothing else.+name a proxy expects is a fact about that proxy and nothing else. If only **Name on the wire**+is filled in, the console also uses it as the model id when saving; completely empty rows are skipped.++The form lists the compatible harness bases below the model rows for the selected API format.+Choose one of those bases to use the model. If another connection serves the same id, select+this connection under **Model routing**. Model ids are entered manually; the form does not fetch+the endpoint's model list.The mapping is a property of the connection, not of a harness: a harness picks a model by its id,the connection decides how that id is written for its endpoint. Two harnesses that need differentdiff --git a/gateway/app.py b/gateway/app.pyindex e73e56bb..acdba19f 100644--- a/gateway/app.py+++ b/gateway/app.py@@ -5644,6 +5644,9 @@ def _provider_catalog_public() -> list[dict]:for c, v in _VENDOR_MODELS.get(pid, {}).items()],# The custom provider's rows name any canonical; the form offers this list."canonicals": _catalog_canonicals() if pid == "custom" else [],+ **({"format_backends": {fmt: sorted(bases)+ for fmt, bases in _CUSTOM_FORMAT_BACKENDS.items()}}+ if pid == "custom" else {}),"backends": backends})return outdiff --git a/gateway/tests/test_custom_model_map.py b/gateway/tests/test_custom_model_map.pyindex e4bd7efe..6c9e037c 100644--- a/gateway/tests/test_custom_model_map.py+++ b/gateway/tests/test_custom_model_map.py@@ -63,3 +63,26 @@ def test_the_connections_disabled_tools_join_the_harness_list_for_the_turn():conn = {"provider": "tokenrouter", "disabled_tools": "web_search, image_generation"}conn_off = [t.strip() for t in str(conn.get("disabled_tools") or "").split(",") if t.strip()]assert sorted(set(["Bash"]) | set(conn_off)) == ["Bash", "image_generation", "web_search"]+++def test_custom_format_metadata_matches_routing_compatibility():+ custom = next(c for c in gw._provider_catalog_public() if c['id'] == 'custom')+ assert custom['format_backends'] == {+ fmt: sorted(bases) for fmt, bases in gw._CUSTOM_FORMAT_BACKENDS.items()+ }+++def test_uncatalogued_custom_model_is_available_only_on_compatible_bases(monkeypatch):+ integ = {'name': 'proxy', 'provider': 'custom',+ 'config': {'api_format': 'openai', 'base_url': 'https://proxy.example/v1'},+ 'models': [{'canonical': 'gpt-4.1-mini', 'provider_id': 'endpoint-mini'}]}++ async def docs(): return [integ]+ async def model_map(): return {'gpt-4.1-mini': 'proxy'}++ monkeypatch.setattr(gw, '_integrations_doc', docs)+ monkeypatch.setattr(gw, '_effective_model_map', model_map)+ assert gw._integration_models(integ) == {'gpt-4.1-mini': 'endpoint-mini'}+ conn = asyncio.run(gw._mapped_integration_conn('pi', 'gpt-4.1-mini'))+ assert conn and conn['model'] == 'endpoint-mini'+ assert asyncio.run(gw._mapped_integration_conn('codex', 'gpt-4.1-mini')) is Nonediff --git a/ui/package-lock.json b/ui/package-lock.jsonindex a280887d..7c180173 100644--- a/ui/package-lock.json+++ b/ui/package-lock.json@@ -66,6 +66,7 @@"devDependencies": {"@eslint/eslintrc": "^3","@hocuspocus/server": "^2.13.5",+ "@testing-library/dom": "^10.4.1","@testing-library/jest-dom": "^6.8.0","@testing-library/react": "^16.3.0","@testing-library/user-event": "^14.6.1",@@ -2401,6 +2402,78 @@"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==","license": "0BSD"},+ "node_modules/@testing-library/dom": {+ "version": "10.4.1",+ "resolved": "https://registry.npmjs.org/@testing-library/dom/-/dom-10.4.1.tgz",+ "integrity": "sha512-o4PXJQidqJl82ckFaXUeoAW+XysPLauYI43Abki5hABd853iMhitooc6znOnczgbTYmEP6U6/y1ZyKAIsvMKGg==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "@babel/code-frame": "^7.10.4",+ "@babel/runtime": "^7.12.5",+ "@types/aria-query": "^5.0.1",+ "aria-query": "5.3.0",+ "dom-accessibility-api": "^0.5.9",+ "lz-string": "^1.5.0",+ "picocolors": "1.1.1",+ "pretty-format": "^27.0.2"+ },+ "engines": {+ "node": ">=18"+ }+ },+ "node_modules/@testing-library/dom/node_modules/ansi-styles": {+ "version": "5.2.0",+ "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz",+ "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==",+ "dev": true,+ "license": "MIT",+ "engines": {+ "node": ">=10"+ },+ "funding": {+ "url": "https://github.com/chalk/ansi-styles?sponsor=1"+ }+ },+ "node_modules/@testing-library/dom/node_modules/aria-query": {+ "version": "5.3.0",+ "resolved": "https://registry.npmjs.org/aria-query/-/aria-query-5.3.0.tgz",+ "integrity": "sha512-b0P0sZPKtyu8HkeRAfCq0IfURZK+SuwMjY1UXGBU27wpAiTwQAIlq56IbIO+ytk/JjS1fMR14ee5WBBfKi5J6A==",+ "dev": true,+ "license": "Apache-2.0",+ "dependencies": {+ "dequal": "^2.0.3"+ }+ },+ "node_modules/@testing-library/dom/node_modules/dom-accessibility-api": {+ "version": "0.5.16",+ "resolved": "https://registry.npmjs.org/dom-accessibility-api/-/dom-accessibility-api-0.5.16.tgz",+ "integrity": "sha512-X7BJ2yElsnOJ30pZF4uIIDfBEVgF4XEBxL9Bxhy6dnrm5hkzqmsWHGTiHqRiITNhMyFLyAiWndIJP7Z1NTteDg==",+ "dev": true,+ "license": "MIT"+ },+ "node_modules/@testing-library/dom/node_modules/pretty-format": {+ "version": "27.5.1",+ "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-27.5.1.tgz",+ "integrity": "sha512-Qb1gy5OrP5+zDf2Bvnzdl3jsTf1qXVMazbvCoKhtKqVs4/YK4ozX4gKQJJVyNe+cajNPn0KoC0MC3FUmaHWEmQ==",+ "dev": true,+ "license": "MIT",+ "dependencies": {+ "ansi-regex": "^5.0.1",+ "ansi-styles": "^5.0.0",+ "react-is": "^17.0.1"+ },+ "engines": {+ "node": "^10.13.0 || ^12.13.0 || ^14.15.0 || >=15.0.0"+ }+ },+ "node_modules/@testing-library/dom/node_modules/react-is": {+ "version": "17.0.2",+ "resolved": "https://registry.npmjs.org/react-is/-/react-is-17.0.2.tgz",+ "integrity": "sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==",+ "dev": true,+ "license": "MIT"+ },"node_modules/@testing-library/jest-dom": {"version": "6.9.1","resolved": "https://registry.npmjs.org/@testing-library/jest-dom/-/jest-dom-6.9.1.tgz",@@ -2966,6 +3039,13 @@"license": "0BSD","optional": true},+ "node_modules/@types/aria-query": {+ "version": "5.0.4",+ "resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.4.tgz",+ "integrity": "sha512-rfT93uj5s0PRL7EzccGMs3brplhcrghnDoV26NqKhCAS1hVo+WdNsPvE/yb6ilfr5hi2MEk6d5EWJTKdxg8jVw==",+ "dev": true,+ "license": "MIT"+ },"node_modules/@types/babel__core": {"version": "7.20.5","resolved": "https://registry.npmjs.org/@types/babel__core/-/babel__core-7.20.5.tgz",@@ -9892,6 +9972,16 @@"react": "^16.5.1 || ^17.0.0 || ^18.0.0 || ^19.0.0"}},+ "node_modules/lz-string": {+ "version": "1.5.0",+ "resolved": "https://registry.npmjs.org/lz-string/-/lz-string-1.5.0.tgz",+ "integrity": "sha512-h5bgJWpxJNswbU7qCrV0tIKQCaS3blPDrqKWx+QxzuzL1zGUzij9XCWLrSLsJPu5t+eWA/ycetzYAO5IOMcWAQ==",+ "dev": true,+ "license": "MIT",+ "bin": {+ "lz-string": "bin/bin.js"+ }+ },"node_modules/make-dir": {"version": "4.0.0","resolved": "https://registry.npmjs.org/make-dir/-/make-dir-4.0.0.tgz",diff --git a/ui/package.json b/ui/package.jsonindex 5e1c06f7..7850d5ee 100644--- a/ui/package.json+++ b/ui/package.json@@ -73,6 +73,7 @@"devDependencies": {"@eslint/eslintrc": "^3","@hocuspocus/server": "^2.13.5",+ "@testing-library/dom": "^10.4.1","@testing-library/jest-dom": "^6.8.0","@testing-library/react": "^16.3.0","@testing-library/user-event": "^14.6.1",diff --git a/ui/src/app/(app)/integrations/page.test.tsx b/ui/src/app/(app)/integrations/page.test.tsxnew file mode 100644index 00000000..4fc2fd7c--- /dev/null+++ b/ui/src/app/(app)/integrations/page.test.tsx@@ -0,0 +1,58 @@+/** @jest-environment jsdom */+import { fireEvent, render, screen, waitFor } from '@testing-library/react';+import Integrations from './page';+import { harnessFetch } from '@/lib/hfetch';++jest.mock('@/lib/hfetch', () => ({ harnessFetch: jest.fn() }));+jest.mock('next/navigation', () => ({ useRouter: () => ({ push: jest.fn() }) }));+jest.mock('@/lib/auth', () => ({ getSession: () => null }));+jest.mock('@/lib/chat', () => ({ authHeaders: () => ({}) }));+jest.mock('@/lib/edition', () => ({ SELF_HOSTED: true, PLATFORM_ADMIN_ORGS: [] }));++const doc = {+ integrations: [], model_map: {}, providers: ['custom'],+ catalog: [{ id: 'custom', label: 'Custom', base_url: null, secret: 'api_key',+ secret_label: 'API key', fields: [{ key: 'api_format', label: 'API format' }],+ models: [], canonicals: ['catalog-model'], backends: ['pi', 'codex'],+ format_backends: { openai: ['pi'], responses: ['codex'], anthropic: ['claude'] } }],+};++beforeEach(() => {+ jest.clearAllMocks();+ (harnessFetch as jest.Mock).mockResolvedValue({ ok: true, json: async () => doc });+});++async function openCustom() {+ render(<Integrations />);+ await waitFor(() => expect(harnessFetch).toHaveBeenCalled());+ fireEvent.click(screen.getByText('Add Integration'));+ fireEvent.click(await screen.findByRole('button', { name: 'Custom' }));+}++test('saves arbitrary ids and wire-only rows, skipping empty rows', async () => {+ await openCustom();+ fireEvent.change(screen.getByLabelText('Name', { exact: true }), { target: { value: 'proxy' } });+ fireEvent.click(screen.getByText('Add model'));+ fireEvent.change(screen.getByLabelText('Model', { exact: true }), { target: { value: 'gpt-4.1-mini' } });+ expect(screen.getByLabelText('Model').tagName).toBe('INPUT');+ expect(document.querySelector('#custom-model-ids option')?.getAttribute('value')).toBe('catalog-model');+ fireEvent.click(screen.getByText('Add model'));+ fireEvent.change(screen.getAllByLabelText('Name on the wire')[1], { target: { value: 'wire-only-model' } });+ fireEvent.click(screen.getByText('Add model'));+ fireEvent.click(screen.getByRole('button', { name: 'Create' }));+ await waitFor(() => expect(harnessFetch).toHaveBeenCalledWith(expect.any(String), expect.objectContaining({ method: 'PUT' })));+ const put = (harnessFetch as jest.Mock).mock.calls.find(([, opts]) => opts?.method === 'PUT');+ expect(JSON.parse(put![1].body).integrations[0].models).toEqual([+ { canonical: 'gpt-4.1-mini', provider_id: '' },+ { canonical: 'wire-only-model', provider_id: 'wire-only-model' },+ ]);+});++test('updates compatible bases from metadata when the format changes', async () => {+ await openCustom();+ expect(screen.getByText(/Compatible harness bases: Pi\./)).toBeTruthy();+ fireEvent.change(screen.getByLabelText('API format'), { target: { value: 'responses' } });+ expect(screen.getByText(/Compatible harness bases: Codex\./)).toBeTruthy();+ fireEvent.change(screen.getByLabelText('API format'), { target: { value: 'anthropic' } });+ expect(screen.getByText(/Compatible harness bases: Claude Code\./)).toBeTruthy();+});diff --git a/ui/src/app/(app)/integrations/page.tsx b/ui/src/app/(app)/integrations/page.tsxindex 6bd8799d..121e0f5a 100644--- a/ui/src/app/(app)/integrations/page.tsx+++ b/ui/src/app/(app)/integrations/page.tsx@@ -18,6 +18,7 @@ import { SkelRows } from '@/components/Skel';import { getSession } from '@/lib/auth';import { authHeaders } from '@/lib/chat';import { PLATFORM_ADMIN_ORGS, SELF_HOSTED } from '@/lib/edition';+import { OOB } from '@/lib/harness';interface ModelRow { canonical: string; provider_id: string }interface Integration {@@ -46,6 +47,7 @@ interface ProviderMeta {models: ModelRow[];/** For the custom provider: every canonical id a harness can ask for, the choices of its rows. */canonicals?: string[];+ format_backends?: Record<string, string[]>;backends: string[];}interface Doc {@@ -81,6 +83,13 @@ interface MediaChain { capability: string; unit: string; candidates: MediaCandidconst SECRET = '__secret__';+/** The bases' names as the console shows them everywhere else ("Claude Code", not the gateway's+ * `claude`), from its own list of bases; an id that list does not know is shown as it is. */+function baseNames(backends: string[]): string[] {+ const names = new Map(OOB.filter((h) => h.backend).map((h) => [h.backend as string, h.name]));+ return [...new Set(backends.map((b) => names.get(b) || b))].sort((a, b) => a.localeCompare(b));+}+export default function IntegrationsPage() {const router = useRouter();const org = getSession()?.orgId || '';@@ -419,13 +428,7 @@ export default function IntegrationsPage() {<option value="anthropic">Anthropic Messages</option></select><p className="field-help">- {editing.config['api_format'] === 'anthropic'- ? 'Anthropic Messages format works with Claude Code, OpenCode, Pi, and DSH backends.'- : editing.config['api_format'] === 'responses'- ? 'OpenAI Responses format is what Codex speaks; only Codex can drive it. The endpoint gets /responses appended.'- : editing.config['api_format'] === 'openai'- ? 'OpenAI Chat Completions format works with Hermes, OpenCode, Pi, Qwen Code, Cline, Oh My Pi and DSH backends. Codex and Claude Code cannot drive a chat endpoint.'- : 'If you use Claude Code, choose Anthropic Messages format.'}+ Choose the API format your endpoint accepts. Compatible harness bases are listed below.</p></div>);@@ -540,15 +543,15 @@ export default function IntegrationsPage() {<label>Models</label><p className="field-help">The models this endpoint serves, and the name it wants for each one. Leave the- name blank to send the model id as it is.+ name blank to send the model id as it is. Type any model id or choose a suggestion.</p>+ <datalist id="custom-model-ids">+ {choices.map((c) => <option key={c} value={c} />)}+ </datalist>{rows.map((r, idx) => (<div className="itg-model-row" key={idx}>- <select className="select" aria-label="Model" value={r.canonical}- onChange={(e) => setRows(rows.map((x, i) => i === idx ? { ...x, canonical: e.target.value } : x))}>- <option value="">Choose a model</option>- {choices.map((c) => <option key={c} value={c}>{c}</option>)}- </select>+ <input type="text" list="custom-model-ids" aria-label="Model" placeholder="Model id" value={r.canonical}+ onChange={(e) => setRows(rows.map((x, i) => i === idx ? { ...x, canonical: e.target.value } : x))} /><input type="text" aria-label="Name on the wire" placeholder={r.canonical || 'same as the model id'}value={r.provider_id === r.canonical ? '' : r.provider_id}onChange={(e) => setRows(rows.map((x, i) => i === idx ? { ...x, provider_id: e.target.value } : x))} />@@ -561,6 +564,12 @@ export default function IntegrationsPage() {<button type="button" className="button" onClick={() => setRows([...rows, { canonical: '', provider_id: '' }])}><iconify-icon icon="tabler:plus"></iconify-icon>Add model</button>+ <p className="field-help">+ {meta?.format_backends?.[editing.config.api_format]?.length+ ? `Compatible harness bases: ${baseNames(meta.format_backends[editing.config.api_format]).join(', ')}.`+ : 'Compatibility information is unavailable for this API format.'}+ {' '}If another connection serves the same model id, choose this connection under Model routing.+ </p></div>);}@@ -633,7 +642,10 @@ export default function IntegrationsPage() {[k, v === editingOriginal ? editing.name.trim() : v]));if (await persist({integrations: [...rest, { ...editing, name: editing.name.trim(),- models: (editing.models || []).filter((m) => m.canonical.trim()) }],+ models: (editing.models || []).map((m) => ({+ ...m,+ canonical: m.canonical.trim() || (editing.provider === 'custom' ? m.provider_id.trim() : ''),+ })).filter((m) => m.canonical) }],model_map: mm,})) setEditing(null);}}>{busy ? 'Saving…' : editingOriginal ? 'Save' : 'Create'}</button>