# What does this PR do?


## Test Plan
# What does this PR do?


## Test Plan
# What does this PR do?


## Test Plan
This commit is contained in:
Eric Huang 2025-06-25 20:10:45 -07:00
parent 114946ae88
commit a4d84f7805
22 changed files with 821 additions and 38 deletions

View file

@ -0,0 +1,77 @@
export interface User {
username: string;
email?: string;
name?: string;
avatar_url?: string;
organizations?: string[];
}
export interface AuthResponse {
access_token: string;
token_type: string;
expires_in: number;
user_info: User;
}
const TOKEN_KEY = "llama_stack_token";
const USER_KEY = "llama_stack_user";
export function getAuthToken(): string | null {
if (typeof window === "undefined") return null;
return localStorage.getItem(TOKEN_KEY);
}
export function setAuthToken(token: string): void {
if (typeof window !== "undefined") {
localStorage.setItem(TOKEN_KEY, token);
}
}
export function removeAuthToken(): void {
if (typeof window !== "undefined") {
localStorage.removeItem(TOKEN_KEY);
}
}
export function getStoredUser(): User | null {
if (typeof window === "undefined") return null;
const userStr = localStorage.getItem(USER_KEY);
if (!userStr) return null;
try {
return JSON.parse(userStr);
} catch {
return null;
}
}
export function setStoredUser(user: User): void {
if (typeof window !== "undefined") {
localStorage.setItem(USER_KEY, JSON.stringify(user));
}
}
export function removeStoredUser(): void {
if (typeof window !== "undefined") {
localStorage.removeItem(USER_KEY);
}
}
export function clearAuth(): void {
removeAuthToken();
removeStoredUser();
}
export function isAuthenticated(): boolean {
return !!getAuthToken();
}
export function isTokenExpired(token: string): boolean {
try {
const payload = JSON.parse(atob(token.split(".")[1]));
const exp = payload.exp;
if (!exp) return false;
return Date.now() >= exp * 1000;
} catch {
return true;
}
}

View file

@ -1,6 +1,12 @@
import LlamaStackClient from "llama-stack-client";
import { getAuthToken } from "./auth";
export const client = new LlamaStackClient({
baseURL:
typeof window !== "undefined" ? `${window.location.origin}/api` : "/api",
});
export function getClient() {
const token = getAuthToken();
return new LlamaStackClient({
baseURL:
typeof window !== "undefined" ? `${window.location.origin}/api` : "/api",
apiKey: token || undefined,
});
}

View file

@ -0,0 +1,15 @@
/**
* Server-side configuration for the Llama Stack UI
* This file should only be imported in server components
*/
// Get backend URL from environment variable or default to localhost for development
export const BACKEND_URL =
process.env.LLAMA_STACK_BACKEND_URL ||
`http://localhost:${process.env.LLAMA_STACK_PORT || 8321}`;
export const serverConfig = {
backendUrl: BACKEND_URL,
} as const;
export default serverConfig;