Skip to content

Commit 5c0544f

Browse files
authored
feat: add workspaces impacted by provider deletion (#340)
* chore: update openapi * feat: add workspaces by provider * fix: query refetch
1 parent 2f8ab95 commit 5c0544f

10 files changed

+265
-29
lines changed

src/api/generated/@tanstack/react-query.gen.ts

+23
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
v1DeleteWorkspaceCustomInstructions,
2929
v1GetWorkspaceMuxes,
3030
v1SetWorkspaceMuxes,
31+
v1ListWorkspacesByProvider,
3132
v1StreamSse,
3233
v1VersionCheck,
3334
v1GetWorkspaceTokenUsage,
@@ -76,6 +77,7 @@ import type {
7677
V1SetWorkspaceMuxesData,
7778
V1SetWorkspaceMuxesError,
7879
V1SetWorkspaceMuxesResponse,
80+
V1ListWorkspacesByProviderData,
7981
V1GetWorkspaceTokenUsageData,
8082
} from '../types.gen'
8183

@@ -687,6 +689,27 @@ export const v1SetWorkspaceMuxesMutation = (
687689
return mutationOptions
688690
}
689691

692+
export const v1ListWorkspacesByProviderQueryKey = (
693+
options: OptionsLegacyParser<V1ListWorkspacesByProviderData>
694+
) => [createQueryKey('v1ListWorkspacesByProvider', options)]
695+
696+
export const v1ListWorkspacesByProviderOptions = (
697+
options: OptionsLegacyParser<V1ListWorkspacesByProviderData>
698+
) => {
699+
return queryOptions({
700+
queryFn: async ({ queryKey, signal }) => {
701+
const { data } = await v1ListWorkspacesByProvider({
702+
...options,
703+
...queryKey[0],
704+
signal,
705+
throwOnError: true,
706+
})
707+
return data
708+
},
709+
queryKey: v1ListWorkspacesByProviderQueryKey(options),
710+
})
711+
}
712+
690713
export const v1StreamSseQueryKey = (options?: OptionsLegacyParser) => [
691714
createQueryKey('v1StreamSse', options),
692715
]

src/api/generated/sdk.gen.ts

+22
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ import type {
7373
V1SetWorkspaceMuxesData,
7474
V1SetWorkspaceMuxesError,
7575
V1SetWorkspaceMuxesResponse,
76+
V1ListWorkspacesByProviderData,
77+
V1ListWorkspacesByProviderError,
78+
V1ListWorkspacesByProviderResponse,
7679
V1StreamSseError,
7780
V1StreamSseResponse,
7881
V1VersionCheckError,
@@ -512,6 +515,25 @@ export const v1SetWorkspaceMuxes = <ThrowOnError extends boolean = false>(
512515
})
513516
}
514517

518+
/**
519+
* List Workspaces By Provider
520+
* List workspaces by provider ID.
521+
*/
522+
export const v1ListWorkspacesByProvider = <
523+
ThrowOnError extends boolean = false,
524+
>(
525+
options: OptionsLegacyParser<V1ListWorkspacesByProviderData, ThrowOnError>
526+
) => {
527+
return (options?.client ?? client).get<
528+
V1ListWorkspacesByProviderResponse,
529+
V1ListWorkspacesByProviderError,
530+
ThrowOnError
531+
>({
532+
...options,
533+
url: '/api/v1/workspaces/{provider_id}',
534+
})
535+
}
536+
515537
/**
516538
* Stream Sse
517539
* Send alerts event

src/api/generated/types.gen.ts

+36-10
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ export type Alert = {
3535
| {
3636
[key: string]: unknown
3737
}
38-
| null;
39-
trigger_type: string;
40-
trigger_category: AlertSeverity;
41-
timestamp: string;
42-
};
38+
| null
39+
trigger_type: string
40+
trigger_category: AlertSeverity
41+
timestamp: string
42+
}
4343

4444
/**
4545
* Represents an alert with it's respective conversation.
@@ -60,8 +60,8 @@ export type AlertConversation = {
6060
}
6161

6262
export enum AlertSeverity {
63-
INFO = "info",
64-
CRITICAL = "critical",
63+
INFO = 'info',
64+
CRITICAL = 'critical',
6565
}
6666

6767
/**
@@ -111,6 +111,7 @@ export type Conversation = {
111111

112112
export type CreateOrRenameWorkspaceRequest = {
113113
name: string
114+
config?: WorkspaceConfig | null
114115
rename_to?: string | null
115116
}
116117

@@ -145,15 +146,16 @@ export type ModelByProvider = {
145146
* Represents the different types of matchers we support.
146147
*/
147148
export enum MuxMatcherType {
148-
CATCH_ALL = "catch_all",
149-
FILENAME_MATCH = "filename_match",
150-
REQUEST_TYPE_MATCH = "request_type_match",
149+
CATCH_ALL = 'catch_all',
150+
FILENAME_MATCH = 'filename_match',
151+
REQUEST_TYPE_MATCH = 'request_type_match',
151152
}
152153

153154
/**
154155
* Represents a mux rule for a provider.
155156
*/
156157
export type MuxRule = {
158+
provider_name?: string | null
157159
provider_id: string
158160
model: string
159161
matcher_type: MuxMatcherType
@@ -251,6 +253,20 @@ export type Workspace = {
251253
is_active: boolean
252254
}
253255

256+
export type WorkspaceConfig = {
257+
system_prompt: string
258+
muxing_rules: Array<MuxRule>
259+
}
260+
261+
/**
262+
* Returns a workspace ID with model name
263+
*/
264+
export type WorkspaceWithModel = {
265+
id: string
266+
name: string
267+
provider_model_name: string
268+
}
269+
254270
export type HealthCheckHealthGetResponse = unknown
255271

256272
export type HealthCheckHealthGetError = unknown
@@ -462,6 +478,16 @@ export type V1SetWorkspaceMuxesResponse = void
462478

463479
export type V1SetWorkspaceMuxesError = HTTPValidationError
464480

481+
export type V1ListWorkspacesByProviderData = {
482+
path: {
483+
provider_id: string
484+
}
485+
}
486+
487+
export type V1ListWorkspacesByProviderResponse = Array<WorkspaceWithModel>
488+
489+
export type V1ListWorkspacesByProviderError = HTTPValidationError
490+
465491
export type V1StreamSseResponse = unknown
466492

467493
export type V1StreamSseError = unknown

src/api/openapi.json

+116
Original file line numberDiff line numberDiff line change
@@ -989,6 +989,55 @@
989989
}
990990
}
991991
},
992+
"/api/v1/workspaces/{provider_id}": {
993+
"get": {
994+
"tags": [
995+
"CodeGate API",
996+
"Workspaces"
997+
],
998+
"summary": "List Workspaces By Provider",
999+
"description": "List workspaces by provider ID.",
1000+
"operationId": "v1_list_workspaces_by_provider",
1001+
"parameters": [
1002+
{
1003+
"name": "provider_id",
1004+
"in": "path",
1005+
"required": true,
1006+
"schema": {
1007+
"type": "string",
1008+
"format": "uuid",
1009+
"title": "Provider Id"
1010+
}
1011+
}
1012+
],
1013+
"responses": {
1014+
"200": {
1015+
"description": "Successful Response",
1016+
"content": {
1017+
"application/json": {
1018+
"schema": {
1019+
"type": "array",
1020+
"items": {
1021+
"$ref": "#/components/schemas/WorkspaceWithModel"
1022+
},
1023+
"title": "Response V1 List Workspaces By Provider"
1024+
}
1025+
}
1026+
}
1027+
},
1028+
"422": {
1029+
"description": "Validation Error",
1030+
"content": {
1031+
"application/json": {
1032+
"schema": {
1033+
"$ref": "#/components/schemas/HTTPValidationError"
1034+
}
1035+
}
1036+
}
1037+
}
1038+
}
1039+
}
1040+
},
9921041
"/api/v1/alerts_notification": {
9931042
"get": {
9941043
"tags": [
@@ -1478,6 +1527,16 @@
14781527
"type": "string",
14791528
"title": "Name"
14801529
},
1530+
"config": {
1531+
"anyOf": [
1532+
{
1533+
"$ref": "#/components/schemas/WorkspaceConfig"
1534+
},
1535+
{
1536+
"type": "null"
1537+
}
1538+
]
1539+
},
14811540
"rename_to": {
14821541
"anyOf": [
14831542
{
@@ -1590,6 +1649,17 @@
15901649
},
15911650
"MuxRule": {
15921651
"properties": {
1652+
"provider_name": {
1653+
"anyOf": [
1654+
{
1655+
"type": "string"
1656+
},
1657+
{
1658+
"type": "null"
1659+
}
1660+
],
1661+
"title": "Provider Name"
1662+
},
15931663
"provider_id": {
15941664
"type": "string",
15951665
"title": "Provider Id"
@@ -1842,6 +1912,52 @@
18421912
"is_active"
18431913
],
18441914
"title": "Workspace"
1915+
},
1916+
"WorkspaceConfig": {
1917+
"properties": {
1918+
"system_prompt": {
1919+
"type": "string",
1920+
"title": "System Prompt"
1921+
},
1922+
"muxing_rules": {
1923+
"items": {
1924+
"$ref": "#/components/schemas/MuxRule"
1925+
},
1926+
"type": "array",
1927+
"title": "Muxing Rules"
1928+
}
1929+
},
1930+
"type": "object",
1931+
"required": [
1932+
"system_prompt",
1933+
"muxing_rules"
1934+
],
1935+
"title": "WorkspaceConfig"
1936+
},
1937+
"WorkspaceWithModel": {
1938+
"properties": {
1939+
"id": {
1940+
"type": "string",
1941+
"title": "Id"
1942+
},
1943+
"name": {
1944+
"type": "string",
1945+
"pattern": "^[a-zA-Z0-9_-]+$",
1946+
"title": "Name"
1947+
},
1948+
"provider_model_name": {
1949+
"type": "string",
1950+
"title": "Provider Model Name"
1951+
}
1952+
},
1953+
"type": "object",
1954+
"required": [
1955+
"id",
1956+
"name",
1957+
"provider_model_name"
1958+
],
1959+
"title": "WorkspaceWithModel",
1960+
"description": "Returns a workspace ID with model name"
18451961
}
18461962
}
18471963
}

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

+12-13
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ const COLUMNS: Column[] = [
5151
function CellRenderer({
5252
column,
5353
row,
54-
deleteProvider,
5554
}: {
5655
column: Column
5756
row: ProviderEndpoint
58-
deleteProvider: () => void
5957
}) {
58+
const deleteProvider = useConfirmDeleteProvider(row.id)
59+
6060
return match(column.id)
6161
.with(COLUMN_MAP.provider, () => (
6262
<>
@@ -90,7 +90,15 @@ function CellRenderer({
9090
</div>
9191
))
9292
.with(COLUMN_MAP.configuration, () => (
93-
<Button isIcon variant="tertiary" onPress={deleteProvider}>
93+
<Button
94+
isIcon
95+
variant="tertiary"
96+
onPress={() =>
97+
deleteProvider({
98+
path: { provider_id: row.id as string },
99+
})
100+
}
101+
>
94102
<Trash01 />
95103
</Button>
96104
))
@@ -99,7 +107,6 @@ function CellRenderer({
99107

100108
export function TableProviders() {
101109
const { data: providers = [] } = useProviders()
102-
const deleteProvider = useConfirmDeleteProvider()
103110

104111
return (
105112
<ResizableTableContainer>
@@ -117,15 +124,7 @@ export function TableProviders() {
117124
id={column.id}
118125
alignment={column.alignment}
119126
>
120-
<CellRenderer
121-
column={column}
122-
row={row}
123-
deleteProvider={() => {
124-
deleteProvider({
125-
path: { provider_id: row.id as string },
126-
})
127-
}}
128-
/>
127+
<CellRenderer column={column} row={row} />
129128
</Cell>
130129
)}
131130
</Row>

0 commit comments

Comments
 (0)