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
10 changes: 10 additions & 0 deletions config/ai_connectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,16 @@ func RenderManagedAIConnectorsSection(connectors []uicfg.ConnectorRemote, sectio
builder.WriteString(strconv.Quote(connector.GCPLocation))
builder.WriteString("\n")
}
if connector.AWSAccessKeyID != "" {
builder.WriteString("aws_access_key_id = ")
builder.WriteString(strconv.Quote(connector.AWSAccessKeyID))
builder.WriteString("\n")
}
if connector.AWSRegion != "" {
builder.WriteString("aws_region = ")
builder.WriteString(strconv.Quote(connector.AWSRegion))
builder.WriteString("\n")
}
if connector.SelectedModel != "" {
builder.WriteString("selected_model = ")
builder.WriteString(strconv.Quote(connector.SelectedModel))
Expand Down
1 change: 1 addition & 0 deletions internal/appui/ui_connectors.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func RunUI(c *cli.Context) error {
mux.HandleFunc("/api/ui/connectors/settings", srv.handleHelperSettings)
mux.HandleFunc("/api/ui/connectors/validate-key", srv.handleValidateKey)
mux.HandleFunc("/api/ui/connectors/ollama/models", srv.handleOllamaModels)
mux.HandleFunc("/api/ui/connectors/bedrock/models", srv.handleBedrockModels)
mux.HandleFunc("/api/ui/connectors/providers/", srv.handleProviderModels)
mux.HandleFunc("/api/ui/usage-chip", srv.handleUsageChip)
mux.HandleFunc("/api/ui/connectors/", srv.handleConnectorByID)
Expand Down
21 changes: 20 additions & 1 deletion internal/appui/ui_connectors_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,26 @@ func (s *connectorManagerServer) handleOllamaModels(w http.ResponseWriter, r *ht
writeRawJSON(w, status, respBody)
}

func (s *connectorManagerServer) handleBedrockModels(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
writeJSONError(w, http.StatusMethodNotAllowed, "method not allowed")
return
}

body, err := io.ReadAll(r.Body)
if err != nil {
writeJSONError(w, http.StatusBadRequest, "failed to read request body")
return
}

status, respBody, err := s.proxyJSONRequest(http.MethodPost, "/api/v1/aiconnectors/bedrock/models", body)
if err != nil {
writeJSONError(w, http.StatusBadGateway, err.Error())
return
}
writeRawJSON(w, status, respBody)
}

func (s *connectorManagerServer) handleProviderModels(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodGet {
writeJSONError(w, http.StatusMethodNotAllowed, "method not allowed")
Expand All @@ -431,4 +451,3 @@ func (s *connectorManagerServer) handleProviderModels(w http.ResponseWriter, r *
}
writeRawJSON(w, status, respBody)
}

4 changes: 2 additions & 2 deletions internal/staticserve/static/ui-connectors.html
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@
}
button.tertiary-danger:hover { background: var(--status-error-bg); }
button:disabled { opacity: 0.6; cursor: not-allowed; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.connector-name-row {
display: grid;
grid-template-columns: minmax(0, 1fr) auto;
Expand All @@ -441,7 +441,7 @@
white-space: nowrap;
opacity: 0.92;
}
.status { margin-top: 8px; font-size: 13px; }
.status { margin-top: 8px; margin-bottom: 10px; font-size: 13px; }
.status.ok { color: var(--status-success-text); }
.status.err { color: var(--status-error-text); }
.connectors-content {
Expand Down
104 changes: 102 additions & 2 deletions internal/staticserve/static/ui-connectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function App() {
const [modelsFetched, setModelsFetched] = useState(false);
const [form, setForm] = useState(defaultForm());
const [ollamaModels, setOllamaModels] = useState([]);
const [bedrockModels, setBedrockModels] = useState([]);
const [dynamicModels, setDynamicModels] = useState([]);
const [apiDefaultModel, setApiDefaultModel] = useState('');
const [session, setSession] = useState(null);
Expand All @@ -44,7 +45,7 @@ function App() {
}, [form.provider_name]);

useEffect(() => {
if (!form.provider_name || form.provider_name === 'ollama') {
if (!form.provider_name || form.provider_name === 'ollama' || form.provider_name === 'bedrock') {
setDynamicModels([]);
setApiDefaultModel('');
return;
Expand Down Expand Up @@ -93,11 +94,14 @@ function App() {
if (form.provider_name === 'ollama' && ollamaModels.length > 0) {
return ollamaModels;
}
if (form.provider_name === 'bedrock' && bedrockModels.length > 0) {
return bedrockModels.map((model) => model.model_id);
}
if (dynamicModels.length > 0) {
return dynamicModels;
}
return selectedProvider.models || [];
}, [selectedProvider, form.provider_name, ollamaModels, dynamicModels]);
}, [selectedProvider, form.provider_name, ollamaModels, bedrockModels, dynamicModels]);

const [searchQuery, setSearchQuery] = useState('');
const [isOpen, setIsOpen] = useState(false);
Expand Down Expand Up @@ -431,6 +435,7 @@ function App() {
const connector = connectors.find((entry) => String(entry.id) === String(route.connectorID));
if (connector) {
setOllamaModels([]);
setBedrockModels([]);
setModelsFetched(false);
setFetchingModels(false);
setForm({
Expand All @@ -442,6 +447,8 @@ function App() {
selected_model: connector.selected_model || '',
gcp_project_id: connector.gcp_project_id || '',
gcp_location: connector.gcp_location || '',
aws_access_key_id: connector.aws_access_key_id || '',
aws_region: connector.aws_region || '',
role: connector.role || 'leader',
});
setStatus(`Editing connector #${connector.id}`);
Expand All @@ -452,6 +459,7 @@ function App() {
function resetFormState(role) {
setForm({ ...defaultForm(), role: role || 'leader' });
setOllamaModels([]);
setBedrockModels([]);
setApiDefaultModel('');
setModelsFetched(false);
setFetchingModels(false);
Expand All @@ -471,12 +479,21 @@ function App() {
: '',
gcp_project_id: '',
gcp_location: '',
aws_access_key_id: '',
aws_region: '',
}));
if (provider.id !== 'ollama') {
setOllamaModels([]);
}
if (provider.id !== 'bedrock') {
setBedrockModels([]);
}
if (provider.id !== 'ollama' && provider.id !== 'bedrock') {
setApiDefaultModel('');
setModelsFetched(false);
}
setStatus('');
setError('');
}

function setFormField(field, value) {
Expand All @@ -501,8 +518,14 @@ function App() {
selected_model: connector.selected_model || '',
gcp_project_id: connector.gcp_project_id || '',
gcp_location: connector.gcp_location || '',
aws_access_key_id: connector.aws_access_key_id || '',
aws_region: connector.aws_region || '',
role: connector.role || 'leader',
});
setOllamaModels([]);
setBedrockModels([]);
setModelsFetched(false);
setFetchingModels(false);
setStatus(`Editing connector #${connector.id}`);
navigate(`/connectors/edit/${connector.id}`);
}
Expand Down Expand Up @@ -545,6 +568,51 @@ function App() {
}
}

async function fetchBedrockModels() {
setFetchingModels(true);
setError('');
setStatus('');
const awsRegion = (form.aws_region || '').trim();
if (!awsRegion) {
setError('Region is required for Bedrock model discovery');
setFetchingModels(false);
return;
}
try {
const response = await api('/api/ui/connectors/bedrock/models', {
method: 'POST',
body: JSON.stringify({
access_key_id: (form.aws_access_key_id || '').trim(),
secret_access_key: form.api_key || '',
region: awsRegion,
}),
});
const models = response.models || [];
setBedrockModels(models);
setModelsFetched(true);
const modelIds = models.map((model) => model.model_id);
setForm((prev) => {
if (prev.selected_model && modelIds.includes(prev.selected_model)) {
return prev;
}
return { ...prev, selected_model: '' };
});
if (models.length === 0) {
setError('No foundation models found for this region. Request model access in the AWS Bedrock console first.');
} else {
setStatus(`Fetched ${models.length} Bedrock model(s)`);
}
} catch (err) {
setModelsFetched(false);
if (await handleAuthError(err)) {
return;
}
setError(err.message || String(err));
} finally {
setFetchingModels(false);
}
}

async function saveConnector() {
const provider = providers.find((entry) => entry.id === form.provider_name) || providers[0];
const connectorName = (form.connector_name || '').trim();
Expand Down Expand Up @@ -582,6 +650,27 @@ function App() {
return;
}

if (!selectedModel) {
setError('Please select a model');
setStatus('');
return;
}
} else if (provider.id === 'bedrock') {
if (!(form.aws_access_key_id || '').trim()) {
setError('AWS Access Key ID is required');
setStatus('');
return;
}
if (!apiKey) {
setError('AWS Secret Access Key is required');
setStatus('');
return;
}
if (!(form.aws_region || '').trim()) {
setError('Region is required');
setStatus('');
return;
}
if (!selectedModel) {
setError('Please select a model');
setStatus('');
Expand Down Expand Up @@ -609,6 +698,8 @@ function App() {
model: selectedModel || apiDefaultModel || undefined,
gcp_project_id: (form.gcp_project_id || '').trim() || undefined,
gcp_location: (form.gcp_location || '').trim() || undefined,
aws_access_key_id: (form.aws_access_key_id || '').trim() || undefined,
aws_region: (form.aws_region || '').trim() || undefined,
}),
});

Expand All @@ -627,6 +718,8 @@ function App() {
selected_model: selectedModel || apiDefaultModel || undefined,
gcp_project_id: (form.gcp_project_id || '').trim() || undefined,
gcp_location: (form.gcp_location || '').trim() || undefined,
aws_access_key_id: (form.aws_access_key_id || '').trim() || undefined,
aws_region: (form.aws_region || '').trim() || undefined,
display_order: 0,
role: form.role || 'leader',
};
Expand Down Expand Up @@ -759,6 +852,12 @@ function App() {
return !apiKey || !gcpProjectID || !gcpLocation;
}

if (provider.id === 'bedrock') {
const awsAccessKeyID = (form.aws_access_key_id || '').trim();
const awsRegion = (form.aws_region || '').trim();
return !apiKey || !awsAccessKeyID || !awsRegion || !selectedModel;
}

if (!apiKey) {
return true;
}
Expand Down Expand Up @@ -838,6 +937,7 @@ function App() {
onProviderChange=${setProvider}
onFieldChange=${setFormField}
onFetchOllamaModels=${fetchOllamaModels}
onFetchBedrockModels=${fetchBedrockModels}
onSave=${saveConnector}
onGenerateName=${generateConnectorName}
onCancel=${() => {
Expand Down
Loading
Loading