Skip to content

Commit

Permalink
feat: add version displayed to ui
Browse files Browse the repository at this point in the history
  • Loading branch information
snobbee committed Feb 14, 2025
1 parent 029cde8 commit 4435a24
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 11 deletions.
17 changes: 14 additions & 3 deletions clients/client-direct/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import cors from "cors";
import express from "express";
import type { Router } from "express";

import { execSync } from "node:child_process";
import {
type AgentRuntime,
type Character,
Expand All @@ -23,6 +22,8 @@ import type { WebhookEvent } from "@realityspiral/client-coinbase";
import { REST, Routes } from "discord.js";
import type { DirectClient } from ".";

const GITHUB_REPO_URL = "https://github.com/Sifchain/realityspiral";

interface UUIDParams {
agentId: UUID;
roomId?: UUID;
Expand Down Expand Up @@ -143,8 +144,18 @@ export function createApiRouter(
});

router.get("/version", (_req, res) => {
const version = process.env.VERSION || "unknown";
res.json({ version });
if (!process.env.VERSION) {
res.json({
version: "unknown",
url: GITHUB_REPO_URL,
});
return;
}
const version = process.env.VERSION;
const url = version?.startsWith("v")
? `${GITHUB_REPO_URL}/releases/${version}`
: `${GITHUB_REPO_URL}/commit/${version}`;
res.json({ version, url });
});

router.get("/agents", (_req, res) => {
Expand Down
8 changes: 4 additions & 4 deletions scripts/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ get_version_tag() {
fi

if [ "$tag" == "latest" ]; then
# For prod/latest, get the version from label
version_tag=$(docker inspect "${image_name}:${tag}" --format='{{index .Config.Labels "org.opencontainers.image.version"}}' 2>/dev/null)
# For prod/latest, get the version from label prefixing with v
version_tag="v$(docker inspect "${image_name}:${tag}" --format='{{index .Config.Labels "org.opencontainers.image.version"}}' 2>/dev/null)"
else
# For staging/dev, get the SHA
version_tag=$(docker inspect "${image_name}:${tag}" --format='{{index .Config.Labels "org.opencontainers.image.revision"}}' 2>/dev/null)
# For staging/dev, get the short SHA
version_tag=$(docker inspect "${image_name}:${tag}" --format='{{index .Config.Labels "org.opencontainers.image.revision"}}' 2>/dev/null | cut -c1-7)
fi

if [ -z "$version_tag" ]; then
Expand Down
2 changes: 0 additions & 2 deletions ui/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { BrowserRouter, Route, Routes } from "react-router";
import { AppSidebar } from "./components/app-sidebar";
import { Toaster } from "./components/ui/toaster";
import { TooltipProvider } from "./components/ui/tooltip";
import useVersion from "./hooks/use-version";
import Chat from "./routes/chat";
import Home from "./routes/home";
import Overview from "./routes/overview";
Expand All @@ -19,7 +18,6 @@ const queryClient = new QueryClient({
});

function App() {
useVersion();
return (
<QueryClientProvider client={queryClient}>
<div
Expand Down
18 changes: 16 additions & 2 deletions ui/src/components/app-sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
import { apiClient } from "@/lib/api";
import type { UUID } from "@elizaos/core";
import { useQuery } from "@tanstack/react-query";
import { Book, Cog, User } from "lucide-react";
import { Book, Cog, User, Info } from "lucide-react";
import { NavLink, useLocation } from "react-router";
import ConnectionStatus from "./connection-status";

Expand All @@ -26,7 +26,14 @@ export function AppSidebar() {
refetchInterval: 5_000,
});

const versionQuery = useQuery({
queryKey: ["version"],
queryFn: () => apiClient.getVersion(),
});

const agents = query?.data?.agents;
const version = versionQuery.data?.version;
const url = versionQuery.data?.url;

return (
<Sidebar>
Expand Down Expand Up @@ -97,10 +104,17 @@ export function AppSidebar() {
</SidebarMenuButton>
</NavLink>
</SidebarMenuItem>
<SidebarMenuItem>
{/* <SidebarMenuItem>
<SidebarMenuButton disabled>
<Cog /> Settings
</SidebarMenuButton>
</SidebarMenuItem> */}
<SidebarMenuItem>
<NavLink to={url ?? ""} target="_blank">
<SidebarMenuButton disabled>
<Info /> {version ? `${version}` : "---"}
</SidebarMenuButton>
</NavLink>
</SidebarMenuItem>
<ConnectionStatus />
</SidebarMenu>
Expand Down
3 changes: 3 additions & 0 deletions ui/src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,7 @@ export const apiClient = {
body: formData,
});
},
async getVersion(): Promise<{ version: string; url: string }> {
return fetcher({ url: "/version" });
},
};

0 comments on commit 4435a24

Please sign in to comment.