Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: workspace system prompt CRUD #147

Merged
merged 2 commits into from
Jan 21, 2025
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
71 changes: 71 additions & 0 deletions src/api/generated/@tanstack/react-query.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ import {
v1DeleteWorkspace,
v1GetWorkspaceAlerts,
v1GetWorkspaceMessages,
v1GetWorkspaceSystemPrompt,
v1SetWorkspaceSystemPrompt,
v1DeleteWorkspaceSystemPrompt,
} from "../sdk.gen";
import type {
V1CreateWorkspaceData,
Expand All @@ -29,6 +32,13 @@ import type {
V1DeleteWorkspaceResponse,
V1GetWorkspaceAlertsData,
V1GetWorkspaceMessagesData,
V1GetWorkspaceSystemPromptData,
V1SetWorkspaceSystemPromptData,
V1SetWorkspaceSystemPromptError,
V1SetWorkspaceSystemPromptResponse,
V1DeleteWorkspaceSystemPromptData,
V1DeleteWorkspaceSystemPromptError,
V1DeleteWorkspaceSystemPromptResponse,
} from "../types.gen";

type QueryKey<TOptions extends OptionsLegacyParser> = [
Expand Down Expand Up @@ -343,3 +353,64 @@ export const v1GetWorkspaceMessagesOptions = (
queryKey: v1GetWorkspaceMessagesQueryKey(options),
});
};

export const v1GetWorkspaceSystemPromptQueryKey = (
options: OptionsLegacyParser<V1GetWorkspaceSystemPromptData>,
) => [createQueryKey("v1GetWorkspaceSystemPrompt", options)];

export const v1GetWorkspaceSystemPromptOptions = (
options: OptionsLegacyParser<V1GetWorkspaceSystemPromptData>,
) => {
return queryOptions({
queryFn: async ({ queryKey, signal }) => {
const { data } = await v1GetWorkspaceSystemPrompt({
...options,
...queryKey[0],
signal,
throwOnError: true,
});
return data;
},
queryKey: v1GetWorkspaceSystemPromptQueryKey(options),
});
};

export const v1SetWorkspaceSystemPromptMutation = (
options?: Partial<OptionsLegacyParser<V1SetWorkspaceSystemPromptData>>,
) => {
const mutationOptions: UseMutationOptions<
V1SetWorkspaceSystemPromptResponse,
V1SetWorkspaceSystemPromptError,
OptionsLegacyParser<V1SetWorkspaceSystemPromptData>
> = {
mutationFn: async (localOptions) => {
const { data } = await v1SetWorkspaceSystemPrompt({
...options,
...localOptions,
throwOnError: true,
});
return data;
},
};
return mutationOptions;
};

export const v1DeleteWorkspaceSystemPromptMutation = (
options?: Partial<OptionsLegacyParser<V1DeleteWorkspaceSystemPromptData>>,
) => {
const mutationOptions: UseMutationOptions<
V1DeleteWorkspaceSystemPromptResponse,
V1DeleteWorkspaceSystemPromptError,
OptionsLegacyParser<V1DeleteWorkspaceSystemPromptData>
> = {
mutationFn: async (localOptions) => {
const { data } = await v1DeleteWorkspaceSystemPrompt({
...options,
...localOptions,
throwOnError: true,
});
return data;
},
};
return mutationOptions;
};
64 changes: 64 additions & 0 deletions src/api/generated/sdk.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ import type {
V1GetWorkspaceMessagesData,
V1GetWorkspaceMessagesError,
V1GetWorkspaceMessagesResponse,
V1GetWorkspaceSystemPromptData,
V1GetWorkspaceSystemPromptError,
V1GetWorkspaceSystemPromptResponse,
V1SetWorkspaceSystemPromptData,
V1SetWorkspaceSystemPromptError,
V1SetWorkspaceSystemPromptResponse,
V1DeleteWorkspaceSystemPromptData,
V1DeleteWorkspaceSystemPromptError,
V1DeleteWorkspaceSystemPromptResponse,
} from "./types.gen";

export const client = createClient(createConfig());
Expand Down Expand Up @@ -243,3 +252,58 @@ export const v1GetWorkspaceMessages = <ThrowOnError extends boolean = false>(
url: "/api/v1/workspaces/{workspace_name}/messages",
});
};

/**
* Get Workspace System Prompt
* Get the system prompt for a workspace.
*/
export const v1GetWorkspaceSystemPrompt = <
ThrowOnError extends boolean = false,
>(
options: OptionsLegacyParser<V1GetWorkspaceSystemPromptData, ThrowOnError>,
) => {
return (options?.client ?? client).get<
V1GetWorkspaceSystemPromptResponse,
V1GetWorkspaceSystemPromptError,
ThrowOnError
>({
...options,
url: "/api/v1/workspaces/{workspace_name}/system-prompt",
});
};

/**
* Set Workspace System Prompt
*/
export const v1SetWorkspaceSystemPrompt = <
ThrowOnError extends boolean = false,
>(
options: OptionsLegacyParser<V1SetWorkspaceSystemPromptData, ThrowOnError>,
) => {
return (options?.client ?? client).put<
V1SetWorkspaceSystemPromptResponse,
V1SetWorkspaceSystemPromptError,
ThrowOnError
>({
...options,
url: "/api/v1/workspaces/{workspace_name}/system-prompt",
});
};

/**
* Delete Workspace System Prompt
*/
export const v1DeleteWorkspaceSystemPrompt = <
ThrowOnError extends boolean = false,
>(
options: OptionsLegacyParser<V1DeleteWorkspaceSystemPromptData, ThrowOnError>,
) => {
return (options?.client ?? client).delete<
V1DeleteWorkspaceSystemPromptResponse,
V1DeleteWorkspaceSystemPromptError,
ThrowOnError
>({
...options,
url: "/api/v1/workspaces/{workspace_name}/system-prompt",
});
};
35 changes: 35 additions & 0 deletions src/api/generated/types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export type QuestionAnswer = {
answer: ChatMessage | null;
};

export type SystemPrompt = {
prompt: string;
};

export type ValidationError = {
loc: Array<string | number>;
msg: string;
Expand Down Expand Up @@ -166,3 +170,34 @@ export type V1GetWorkspaceMessagesData = {
export type V1GetWorkspaceMessagesResponse = Array<Conversation>;

export type V1GetWorkspaceMessagesError = HTTPValidationError;

export type V1GetWorkspaceSystemPromptData = {
path: {
workspace_name: string;
};
};

export type V1GetWorkspaceSystemPromptResponse = SystemPrompt;

export type V1GetWorkspaceSystemPromptError = HTTPValidationError;

export type V1SetWorkspaceSystemPromptData = {
body: SystemPrompt;
path: {
workspace_name: string;
};
};

export type V1SetWorkspaceSystemPromptResponse = void;

export type V1SetWorkspaceSystemPromptError = HTTPValidationError;

export type V1DeleteWorkspaceSystemPromptData = {
path: {
workspace_name: string;
};
};

export type V1DeleteWorkspaceSystemPromptResponse = void;

export type V1DeleteWorkspaceSystemPromptError = HTTPValidationError;
124 changes: 124 additions & 0 deletions src/api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,119 @@
}
}
}
},
"/api/v1/workspaces/{workspace_name}/system-prompt": {
"get": {
"tags": ["CodeGate API", "Workspaces"],
"summary": "Get Workspace System Prompt",
"description": "Get the system prompt for a workspace.",
"operationId": "v1_get_workspace_system_prompt",
"parameters": [
{
"name": "workspace_name",
"in": "path",
"required": true,
"schema": {
"type": "string",
"title": "Workspace Name"
}
}
],
"responses": {
"200": {
"description": "Successful Response",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SystemPrompt"
}
}
}
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
},
"put": {
"tags": ["CodeGate API", "Workspaces"],
"summary": "Set Workspace System Prompt",
"operationId": "v1_set_workspace_system_prompt",
"parameters": [
{
"name": "workspace_name",
"in": "path",
"required": true,
"schema": {
"type": "string",
"title": "Workspace Name"
}
}
],
"requestBody": {
"required": true,
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/SystemPrompt"
}
}
}
},
"responses": {
"204": {
"description": "Successful Response"
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
},
"delete": {
"tags": ["CodeGate API", "Workspaces"],
"summary": "Delete Workspace System Prompt",
"operationId": "v1_delete_workspace_system_prompt",
"parameters": [
{
"name": "workspace_name",
"in": "path",
"required": true,
"schema": {
"type": "string",
"title": "Workspace Name"
}
}
],
"responses": {
"204": {
"description": "Successful Response"
},
"422": {
"description": "Validation Error",
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
}
}
}
}
}
},
"components": {
Expand Down Expand Up @@ -652,6 +765,17 @@
"title": "QuestionAnswer",
"description": "Represents a question and answer pair."
},
"SystemPrompt": {
"properties": {
"prompt": {
"type": "string",
"title": "Prompt"
}
},
"type": "object",
"required": ["prompt"],
"title": "SystemPrompt"
},
"ValidationError": {
"properties": {
"loc": {
Expand Down
Loading
Loading