8000 feat: add database tables and API routes for agentic chat feature by johnstcn · Pull Request #17570 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

feat: add database tables and API routes for agentic chat feature #17570

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

Merged
merged 18 commits into from
May 2, 2025
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Add tool invocation stories stuff
  • Loading branch information
kylecarbs authored and johnstcn committed May 2, 2025
commit 6a583e090e7c3fdc5fd8be97d87f006bf4c29999
104 changes: 67 additions & 37 deletions site/src/pages/ChatPage/ChatToolInvocation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import * as TypesGen from "api/typesGenerated";
import CheckCircle from "@mui/icons-material/CheckCircle";
import CircularProgress from "@mui/material/CircularProgress";
import ErrorIcon from "@mui/icons-material/Error";
import CodeIcon from "@mui/icons-material/Code";
import ArticleIcon from "@mui/icons-material/Article";

interface ChatToolInvocationProps {
toolInvocation: ChatToolInvocations;
Expand All @@ -14,25 +16,44 @@ export const ChatToolInvocation: FC<ChatToolInvocationProps> = ({
toolInvocation,
}) => {
const theme = useTheme();
const friendlyName = useMemo(() => {
return toolInvocation.toolName
.replace("coder_", "")
.replace(/_/g, " ")
.replace(/\b\w/g, (char) => char.toUpperCase());
}, [toolInvocation.toolName]);

let preview: React.ReactNode;
switch (toolInvocation.toolName) {
case "coder_get_workspace":
switch (toolInvocation.state) {
case "partial-call":
case "call":
preview = <div>Getting Workspace By ID...</div>;
preview = (
<div css={{ display: "flex", alignItems: "center", gap: theme.spacing(1), color: theme.palette.text.secondary }}>
<CircularProgress size={14} color="inherit" />
<span>Fetching workspace details...</span>
</div>
);
break;
case "result":
preview = (
<div css={{ display: "flex", alignItems: "center" }}>
<div css={{ display: "flex", alignItems: "center", gap: theme.spacing(1.5) }}>
<img
src={toolInvocation.result.template_icon || "/icon/code.svg"}
alt={toolInvocation.result.name}
alt={toolInvocation.result.template_display_name || "Template"}
css={{
width: 32,
height: 32,
borderRadius: theme.shape.borderRadius / 2,
objectFit: "contain",
}}
/>
<div>
<div>{toolInvocation.result.name}</div>
<div>{toolInvocation.result.template_display_name}</div>
<div css={{ fontWeight: 500, lineHeight: 1.4 }}>{toolInvocation.result.name}</div>
<div css={{ fontSize: "0.875rem", color: theme.palette.text.secondary, lineHeight: 1.4 }}>
{toolInvocation.result.template_display_name}
</div>
</div>
</div>
);
Expand All @@ -43,10 +64,20 @@ export const ChatToolInvocation: FC<ChatToolInvocationProps> = ({
switch (toolInvocation.state) {
case "partial-call":
case "call":
preview = <div>Running Tool...</div>;
preview = (
<div css={{ display: "flex", alignItems: "center", gap: theme.spacing(1), color: theme.palette.text.secondary }}>
<CircularProgress size={14} color="inherit" />
<span>Executing {friendlyName}...</span>
</div>
);
break;
case "result":
preview = <pre>{JSON.stringify(toolInvocation.result, null, 2)}</pre>;
preview = (
<div css={{ display: 'flex', alignItems: 'center', gap: theme.spacing(1), color: theme.palette.text.secondary }}>
<ArticleIcon sx={{ fontSize: 16 }} />
<span>{friendlyName} result received.</span>
</div>
);
break;
}
}
Expand All @@ -57,35 +88,30 @@ export const ChatToolInvocation: FC<ChatToolInvocationProps> = ({
}
return (
typeof toolInvocation.result === "object" &&
toolInvocation.result !== null &&
"error" in toolInvocation.result
);
}, [toolInvocation]);
const statusColor = useMemo(() => {
if (toolInvocation.state !== "result") {
return theme.palette.primary.main;
return theme.palette.info.main;
}
return hasError ? theme.palette.error.main : theme.palette.success.main;
}, [toolInvocation, hasError]);
const friendlyName = useMemo(() => {
return toolInvocation.toolName
.replace("coder_", "")
.replace("_", " ")
.replace(/\b\w/g, (char) => char.toUpperCase());
}, [toolInvocation.toolName]);
}, [toolInvocation, hasError, theme]);

return (
<div
css={{
marginTop: theme.spacing(1),
marginLeft: theme.spacing(2),
borderLeft: `2px solid ${theme.palette.info.light}`,
marginLeft: theme.spacing(3),
borderLeft: `2px solid ${theme.palette.divider}`,
paddingLeft: theme.spacing(1.5),
display: "flex",
flexDirection: "column",
gap: theme.spacing(1),
gap: theme.spacing(0.75),
}}
>
<div css={{ display: "flex", alignItems: "center" }}>
<div css={{ display: "flex", alignItems: "center", gap: theme.spacing(1) }}>
{toolInvocation.state !== "result" && (
<CircularProgress
size={16}
Expand All @@ -104,12 +130,15 @@ export const ChatToolInvocation: FC<ChatToolInvocationProps> = ({
<div
css={{
flex: 1,
fontSize: '0.9rem',
fontWeight: 500,
color: theme.palette.text.primary,
}}
>
{friendlyName}
</div>
</div>
<div>{preview}</div>
<div css={{ paddingLeft: theme.spacing(3) }}>{preview}</div>
</div>
);
};
Expand All @@ -120,7 +149,7 @@ export type ChatToolInvocations =
{
id: string;
},
TypesGen.Workspace
TypesGen.Workspace & { error?: any }
>
| ToolInvocation<
"coder_create_workspace",
Expand All @@ -130,7 +159,7 @@ export type ChatToolInvocations =
name: string;
rich_parameters: Record<string, any>;
},
TypesGen.Workspace
TypesGen.Workspace & { error?: any }
>
| ToolInvocation<
"coder_list_workspaces",
Expand All @@ -147,7 +176,7 @@ export type ChatToolInvocations =
| "template_icon"
| "template_active_version_id"
| "outdated"
>[]
>[] & { error?: any }
>
| ToolInvocation<
"coder_list_templates",
Expand All @@ -159,83 +188,84 @@ export type ChatToolInvocations =
| "description"
| "active_version_id"
| "active_user_count"
>[]
>[] & { error?: any }
>
| ToolInvocation<
"coder_template_version_parameters",
{
template_version_id: string;
},
TypesGen.TemplateVersionParameter[]
TypesGen.TemplateVersionParameter[] & { error?: any }
>
| ToolInvocation<"coder_get_authenticated_user", {}, TypesGen.User>
| ToolInvocation<"coder_get_authenticated_user", {}, TypesGen.User & { error?: any }>
| ToolInvocation<
"coder_create_workspace_build",
{
workspace_id: string;
transition: "start" | "stop" | "delete";
},
TypesGen.WorkspaceBuild
TypesGen.WorkspaceBuild & { error?: any }
>
| ToolInvocation<
"coder_create_template_version",
{
template_id?: string;
file_id: string;
},
TypesGen.TemplateVersion
TypesGen.TemplateVersion & { error?: any }
>
| ToolInvocation<
"coder_get_workspace_agent_logs",
{
workspace_agent_id: string;
},
string[]
string[] & { error?: any }
>
| ToolInvocation<
"coder_get_workspace_build_logs",
{
workspace_build_id: string;
},
string[]
string[] & { error?: any }
>
| ToolInvocation<
"coder_get_template_version_logs",
{
template_version_id: string;
},
string[]
string[] & { error?: any }
>
| ToolInvocation<
"coder_update_template_active_version",
{
template_id: string;
template_version_id: string;
},
string
string & { error?: any }
>
| ToolInvocation<
"coder_upload_tar_file",
{
mime_type: string;
files: Record<string, string>;
},
TypesGen.UploadResponse
TypesGen.UploadResponse & { error?: any }
>
| ToolInvocation<
"coder_create_template",
{
name: string;
},
TypesGen.Template
TypesGen.Template & { error?: any }
>
| ToolInvocation<
"coder_delete_template",
{
template_id: string;
},
string
>;
string & { error?: any }
>
| ToolInvocation<string, Record<string, any>, any & { error?: any }>;

type ToolInvocation<N extends string, A, R> =
| ({
Expand All @@ -249,4 +279,4 @@ type ToolInvocation<N extends string, A, R> =
| ({
state: "result";
step?: number;
} & ToolResult<N, A, R>);
} & ToolResult<N, A, R & { error?: any }>);
0