Skip to content

Commit cadbd5f

Browse files
authored
fix: provider endpoint and mux section (#275)
* fix: workspace model initial state * fix: provider form overlfow * feat: add banner in case of empty models * fix: text uppercase * feat: prefilled provider configuration based on data * chore: update openapi * feat: create util fn for porivder endpoint and auth * feat: add provider link and description on muxing section * refactor: types * fix: save api_key only when it is updated * fix: type and create form * refactor: remove provider table action cell * fix: show banner after query fetch * fix: openrouter endpoint url and other minor stuff
1 parent 2a5234c commit cadbd5f

13 files changed

+269
-131
lines changed

src/api/generated/types.gen.ts

+30-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,28 @@ export type AddProviderEndpointRequest = {
1919
description?: string;
2020
provider_type: ProviderType;
2121
endpoint?: string;
22-
auth_type?: ProviderAuthType | null;
22+
auth_type?: ProviderAuthType;
2323
api_key?: string | null;
2424
};
2525

26+
/**
27+
* Represents an alert.
28+
*/
29+
export type Alert = {
30+
id: string;
31+
prompt_id: string;
32+
code_snippet: CodeSnippet | null;
33+
trigger_string:
34+
| string
35+
| {
36+
[key: string]: unknown;
37+
}
38+
| null;
39+
trigger_type: string;
40+
trigger_category: string | null;
41+
timestamp: string;
42+
};
43+
2644
/**
2745
* Represents an alert with it's respective conversation.
2846
*/
@@ -50,11 +68,19 @@ export type ChatMessage = {
5068
message_id: string;
5169
};
5270

71+
/**
72+
* Represents a code snippet with its programming language.
73+
*
74+
* Args:
75+
* language: The programming language identifier (e.g., 'python', 'javascript')
76+
* code: The actual code content
77+
*/
5378
export type CodeSnippet = {
5479
code: string;
5580
language: string | null;
5681
filepath: string | null;
5782
libraries?: Array<string>;
83+
file_extension?: string | null;
5884
};
5985

6086
/**
@@ -75,6 +101,7 @@ export type Conversation = {
75101
chat_id: string;
76102
conversation_timestamp: string;
77103
token_usage_agg: TokenUsageAggregate | null;
104+
alerts?: Array<Alert>;
78105
};
79106

80107
export type CreateOrRenameWorkspaceRequest = {
@@ -146,7 +173,7 @@ export type ProviderEndpoint = {
146173
description?: string;
147174
provider_type: ProviderType;
148175
endpoint?: string;
149-
auth_type?: ProviderAuthType | null;
176+
auth_type?: ProviderAuthType;
150177
};
151178

152179
/**
@@ -159,6 +186,7 @@ export enum ProviderType {
159186
OLLAMA = "ollama",
160187
LM_STUDIO = "lm_studio",
161188
LLAMACPP = "llamacpp",
189+
OPENROUTER = "openrouter",
162190
}
163191

164192
/**

src/api/openapi.json

+95-19
Original file line numberDiff line numberDiff line change
@@ -1145,14 +1145,7 @@
11451145
"default": ""
11461146
},
11471147
"auth_type": {
1148-
"anyOf": [
1149-
{
1150-
"$ref": "#/components/schemas/ProviderAuthType"
1151-
},
1152-
{
1153-
"type": "null"
1154-
}
1155-
],
1148+
"$ref": "#/components/schemas/ProviderAuthType",
11561149
"default": "none"
11571150
},
11581151
"api_key": {
@@ -1175,6 +1168,74 @@
11751168
"title": "AddProviderEndpointRequest",
11761169
"description": "Represents a request to add a provider endpoint."
11771170
},
1171+
"Alert": {
1172+
"properties": {
1173+
"id": {
1174+
"type": "string",
1175+
"title": "Id"
1176+
},
1177+
"prompt_id": {
1178+
"type": "string",
1179+
"title": "Prompt Id"
1180+
},
1181+
"code_snippet": {
1182+
"anyOf": [
1183+
{
1184+
"$ref": "#/components/schemas/CodeSnippet"
1185+
},
1186+
{
1187+
"type": "null"
1188+
}
1189+
]
1190+
},
1191+
"trigger_string": {
1192+
"anyOf": [
1193+
{
1194+
"type": "string"
1195+
},
1196+
{
1197+
"type": "object"
1198+
},
1199+
{
1200+
"type": "null"
1201+
}
1202+
],
1203+
"title": "Trigger String"
1204+
},
1205+
"trigger_type": {
1206+
"type": "string",
1207+
"title": "Trigger Type"
1208+
},
1209+
"trigger_category": {
1210+
"anyOf": [
1211+
{
1212+
"type": "string"
1213+
},
1214+
{
1215+
"type": "null"
1216+
}
1217+
],
1218+
"title": "Trigger Category"
1219+
},
1220+
"timestamp": {
1221+
"type": "string",
1222+
"format": "date-time",
1223+
"title": "Timestamp"
1224+
}
1225+
},
1226+
"type": "object",
1227+
"required": [
1228+
"id",
1229+
"prompt_id",
1230+
"code_snippet",
1231+
"trigger_string",
1232+
"trigger_type",
1233+
"trigger_category",
1234+
"timestamp"
1235+
],
1236+
"title": "Alert",
1237+
"description": "Represents an alert."
1238+
},
11781239
"AlertConversation": {
11791240
"properties": {
11801241
"conversation": {
@@ -1300,7 +1361,19 @@
13001361
"type": "string"
13011362
},
13021363
"type": "array",
1303-
"title": "Libraries"
1364+
"title": "Libraries",
1365+
"default": []
1366+
},
1367+
"file_extension": {
1368+
"anyOf": [
1369+
{
1370+
"type": "string"
1371+
},
1372+
{
1373+
"type": "null"
1374+
}
1375+
],
1376+
"title": "File Extension"
13041377
}
13051378
},
13061379
"type": "object",
@@ -1309,7 +1382,8 @@
13091382
"language",
13101383
"filepath"
13111384
],
1312-
"title": "CodeSnippet"
1385+
"title": "CodeSnippet",
1386+
"description": "Represents a code snippet with its programming language.\n\nArgs:\n language: The programming language identifier (e.g., 'python', 'javascript')\n code: The actual code content"
13131387
},
13141388
"ConfigureAuthMaterial": {
13151389
"properties": {
@@ -1376,6 +1450,14 @@
13761450
"type": "null"
13771451
}
13781452
]
1453+
},
1454+
"alerts": {
1455+
"items": {
1456+
"$ref": "#/components/schemas/Alert"
1457+
},
1458+
"type": "array",
1459+
"title": "Alerts",
1460+
"default": []
13791461
}
13801462
},
13811463
"type": "object",
@@ -1580,14 +1662,7 @@
15801662
"default": ""
15811663
},
15821664
"auth_type": {
1583-
"anyOf": [
1584-
{
1585-
"$ref": "#/components/schemas/ProviderAuthType"
1586-
},
1587-
{
1588-
"type": "null"
1589-
}
1590-
],
1665+
"$ref": "#/components/schemas/ProviderAuthType",
15911666
"default": "none"
15921667
}
15931668
},
@@ -1607,7 +1682,8 @@
16071682
"vllm",
16081683
"ollama",
16091684
"lm_studio",
1610-
"llamacpp"
1685+
"llamacpp",
1686+
"openrouter"
16111687
],
16121688
"title": "ProviderType",
16131689
"description": "Represents the different types of providers we support."

src/features/providers/components/provider-form.tsx

+20-5
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import {
88
} from "@stacklok/ui-kit";
99
import {
1010
getAuthTypeOptions,
11+
getProviderAuthByType,
12+
getProviderEndpointByAuthType,
1113
getProviderType,
1214
isProviderAuthType,
1315
isProviderType,
@@ -19,6 +21,19 @@ interface Props {
1921
}
2022

2123
export function ProviderForm({ provider, setProvider }: Props) {
24+
const providerAuthType =
25+
provider.auth_type || getProviderAuthByType(provider.provider_type);
26+
const providerEndpoint =
27+
provider.endpoint || getProviderEndpointByAuthType(provider.provider_type);
28+
29+
const handleProviderType = (provider: AddProviderEndpointRequest) => {
30+
setProvider({
31+
...provider,
32+
auth_type: getProviderAuthByType(provider.provider_type),
33+
endpoint: getProviderEndpointByAuthType(provider.provider_type),
34+
});
35+
};
36+
2237
return (
2338
<div className="w-full">
2439
<div className="">
@@ -45,7 +60,7 @@ export function ProviderForm({ provider, setProvider }: Props) {
4560
items={getProviderType()}
4661
onSelectionChange={(provider_type) => {
4762
if (isProviderType(provider_type)) {
48-
setProvider({
63+
handleProviderType({
4964
...provider,
5065
provider_type,
5166
});
@@ -78,15 +93,15 @@ export function ProviderForm({ provider, setProvider }: Props) {
7893
onChange={(endpoint) => setProvider({ ...provider, endpoint })}
7994
>
8095
<Label>Endpoint</Label>
81-
<Input placeholder="Provider endpoint" value={provider.endpoint} />
96+
<Input placeholder="Provider endpoint" value={providerEndpoint} />
8297
</TextField>
8398
</div>
8499
<div className="py-3">
85100
<Label id="provider-authentication">Authentication</Label>
86101
<Select
87102
aria-labelledby="provider auth type"
88103
name="auth_type"
89-
selectedKey={provider.auth_type}
104+
selectedKey={providerAuthType}
90105
isRequired
91106
className="w-full"
92107
placeholder="Select the authentication type"
@@ -101,7 +116,7 @@ export function ProviderForm({ provider, setProvider }: Props) {
101116
</Select>
102117
</div>
103118

104-
{provider.auth_type === ProviderAuthType.API_KEY && (
119+
{providerAuthType === ProviderAuthType.API_KEY && (
105120
<div className="pt-4">
106121
<TextField
107122
aria-label="Provider API key"
@@ -111,7 +126,7 @@ export function ProviderForm({ provider, setProvider }: Props) {
111126
isRequired
112127
onChange={(api_key) => setProvider({ ...provider, api_key })}
113128
>
114-
<Label>Api key</Label>
129+
<Label>API key</Label>
115130
<Input
116131
placeholder={
117132
provider.api_key === undefined

src/features/providers/components/table-actions.tsx

-53
This file was deleted.

0 commit comments

Comments
 (0)