Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 23 additions & 2 deletions plugins/agent/providers/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,7 @@ impl ApiProvider {
_ => self.facts.label.clone(),
},
custom_endpoint: self.facts.base_url.is_empty(),
configuration_schema: serde_json::to_value(schemars::schema_for!(Configuration))
.map_err(|error| error.to_string())?,
configuration_schema: self.configuration_schema()?,
configuration_defaults: if self.facts.base_url.is_empty() {
json!({})
} else {
Expand All @@ -204,6 +203,28 @@ impl ApiProvider {
.map_err(|error| error.to_string())
}

/// A custom OpenAI-family endpoint advertises a versioned example base;
/// the configured value stays authoritative and is never rewritten.
fn configuration_schema(&self) -> Result<serde_json::Value, String> {
let mut schema = serde_json::to_value(schemars::schema_for!(Configuration))
.map_err(|error| error.to_string())?;
if self.facts.base_url.is_empty()
&& matches!(
self.facts.model_discovery,
facts::discovery::ModelDiscovery::Protocol { .. }
)
&& matches!(
self.facts.runtime_adapter,
facts::adapter::RuntimeAdapter::OpenaiChat {}
| facts::adapter::RuntimeAdapter::OpenaiResponses { .. }
| facts::adapter::RuntimeAdapter::OpenaiCompatible { .. }
)
{
schema["properties"]["baseUrl"]["examples"] = json!(["https://api.example.com/v1"]);
}
Ok(schema)
}

fn model_metadata(&self, model: ModelInfo, overrides: Option<&ModelOverride>) -> ModelMetadata {
let info = self.snapshot.resolve(self.id, model, overrides);
let thinking_levels = overrides
Expand Down
28 changes: 28 additions & 0 deletions plugins/agent/providers/tests/integration/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,3 +867,31 @@ async fn responses_discovery_and_probe_share_the_configured_base() {
);
}
}

#[test]
fn custom_openai_endpoints_advertise_a_versioned_example_base() {
for (provider, example) in [
("openai-compatible", Some("https://api.example.com/v1")),
(
"openai-responses-compatible",
Some("https://api.example.com/v1"),
),
("new-api", Some("https://api.example.com/v1")),
("sub2api", Some("https://api.example.com/v1")),
("cloudflare-workers-ai", None),
("anthropic-compatible", None),
("openai", None),
("ollama", None),
] {
let binding = binding(provider);
let schema = &binding.descriptor().configuration_schema;
assert_eq!(
schema["properties"]["baseUrl"]["examples"][0].as_str(),
example,
"{provider}"
);
binding
.configure(json!({"baseUrl": "http://relay.test"}))
.unwrap();
}
}
12 changes: 3 additions & 9 deletions products/maka/workbench/app/ConnectionForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import type { CredentialStatus } from '../../../../packages/plugin-sdk/src/gener
import type { ExternalAgentSettingsOwner } from './externalAgentSettingsState';
import type { ConnectionEditor, ModelSettingsOwner } from './settings';
import { ConnectionLogin } from './ConnectionLogin';
import { baseUrlPlaceholder } from './connectionEndpoint';
import { ExternalAgentSection } from './ExternalAgentSettings';
import { InlineCallout } from './Feedback';
import { useHost } from './host';
Expand Down Expand Up @@ -84,13 +85,6 @@ const modelViewportHeight = () =>
const blocked = (o: ModelSettingsOwner) =>
o.busy() || o.loading() || !!o.openingProvider() || !o.pendingKnown() || o.pending().length > 0;

const baseUrlPlaceholder = (provider: ConnectionEditor['provider']) => {
const defaults = provider.descriptor.configurationDefaults as Record<string, unknown> | null;
return typeof defaults?.baseUrl === 'string' && defaults.baseUrl.trim()
? defaults.baseUrl
: 'https://…';
};

const submitConnection = (owner: ModelSettingsOwner) => () => {
const form = owner.editor();
if (!form || blocked(owner) || (form.baseline && !owner.dirty())) return;
Expand Down Expand Up @@ -425,7 +419,7 @@ function ConnectionStandardForm(props: {
label={tr('Base URL')}
value={form().baseUrl}
autoFocus={props.autoFocus() && !keyed()}
placeholder={baseUrlPlaceholder(form().provider)}
placeholder={baseUrlPlaceholder(form().provider.descriptor)}
change={(text) => owner.edit('baseUrl', text)}
onSubmit={submit}
disabled={disabled()}
Expand Down Expand Up @@ -769,7 +763,7 @@ export function ConnectionAdvanced(props: { settings: ModelSettingsOwner }) {
<SettingsInput
label={tr('Base URL')}
value={form().baseUrl}
placeholder={baseUrlPlaceholder(form().provider)}
placeholder={baseUrlPlaceholder(form().provider.descriptor)}
change={(text) => owner.edit('baseUrl', text)}
onSubmit={submit}
disabled={disabled()}
Expand Down
35 changes: 35 additions & 0 deletions products/maka/workbench/app/connectionEndpoint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

type EndpointDescriptor = { configurationSchema: unknown; configurationDefaults: unknown };

/** The versioned example base a custom endpoint advertises, if any. */
function endpointExample(descriptor: EndpointDescriptor): string | undefined {
const schema = descriptor.configurationSchema as {
properties?: { baseUrl?: { examples?: unknown[] } };
} | null;
const example = schema?.properties?.baseUrl?.examples?.[0];
return typeof example === 'string' && example.trim() ? example : undefined;
}

export function baseUrlPlaceholder(descriptor: EndpointDescriptor): string {
const defaults = descriptor.configurationDefaults as Record<string, unknown> | null;
if (typeof defaults?.baseUrl === 'string' && defaults.baseUrl.trim()) return defaults.baseUrl;
return endpointExample(descriptor) ?? 'https://…';
}
42 changes: 42 additions & 0 deletions products/maka/workbench/tests/connection-endpoint.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import assert from 'node:assert/strict';
import test from 'node:test';

const { baseUrlPlaceholder } = await import(
new URL('../app/connectionEndpoint.ts', import.meta.url)
);

const example = 'https://api.example.com/v1';
const custom = {
configurationSchema: { properties: { baseUrl: { type: 'string', examples: [example] } } },
configurationDefaults: {},
};
const plain = {
configurationSchema: { properties: { baseUrl: { type: 'string' } } },
configurationDefaults: {},
};
const preset = { ...plain, configurationDefaults: { baseUrl: 'http://127.0.0.1:11434/v1' } };

test('the Base URL placeholder prefers defaults, then the advertised example', () => {
assert.equal(baseUrlPlaceholder(preset), 'http://127.0.0.1:11434/v1');
assert.equal(baseUrlPlaceholder(custom), example);
assert.equal(baseUrlPlaceholder(plain), 'https://…');
});