mirror of
https://github.com/meta-llama/llama-stack.git
synced 2025-12-11 19:56:03 +00:00
chore(package): migrate to src/ layout (#3920)
Migrates package structure to src/ layout following Python packaging best practices. All code moved from `llama_stack/` to `src/llama_stack/`. Public API unchanged - imports remain `import llama_stack.*`. Updated build configs, pre-commit hooks, scripts, and GitHub workflows accordingly. All hooks pass, package builds cleanly. **Developer note**: Reinstall after pulling: `pip install -e .`
This commit is contained in:
parent
98a5047f9d
commit
471b1b248b
791 changed files with 2983 additions and 456 deletions
|
|
@ -0,0 +1,315 @@
|
|||
import React from "react";
|
||||
import { render, screen, fireEvent } from "@testing-library/react";
|
||||
import "@testing-library/jest-dom";
|
||||
import { VectorStoreDetailView } from "./vector-store-detail";
|
||||
import type { VectorStore } from "llama-stack-client/resources/vector-stores/vector-stores";
|
||||
import type { VectorStoreFile } from "llama-stack-client/resources/vector-stores/files";
|
||||
|
||||
const mockPush = jest.fn();
|
||||
jest.mock("next/navigation", () => ({
|
||||
useRouter: () => ({
|
||||
push: mockPush,
|
||||
}),
|
||||
}));
|
||||
|
||||
describe("VectorStoreDetailView", () => {
|
||||
const defaultProps = {
|
||||
store: null,
|
||||
files: [],
|
||||
isLoadingStore: false,
|
||||
isLoadingFiles: false,
|
||||
errorStore: null,
|
||||
errorFiles: null,
|
||||
id: "test_vector_store_id",
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
mockPush.mockClear();
|
||||
});
|
||||
|
||||
describe("Loading States", () => {
|
||||
test("renders loading skeleton when store is loading", () => {
|
||||
const { container } = render(
|
||||
<VectorStoreDetailView {...defaultProps} isLoadingStore={true} />
|
||||
);
|
||||
|
||||
const skeletons = container.querySelectorAll('[data-slot="skeleton"]');
|
||||
expect(skeletons.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test("renders files loading skeleton when files are loading", () => {
|
||||
const mockStore: VectorStore = {
|
||||
id: "vs_123",
|
||||
name: "Test Vector Store",
|
||||
created_at: 1710000000,
|
||||
status: "ready",
|
||||
file_counts: { total: 5 },
|
||||
usage_bytes: 1024,
|
||||
metadata: {
|
||||
provider_id: "test_provider",
|
||||
provider_vector_db_id: "test_db_id",
|
||||
},
|
||||
};
|
||||
|
||||
const { container } = render(
|
||||
<VectorStoreDetailView
|
||||
{...defaultProps}
|
||||
store={mockStore}
|
||||
isLoadingFiles={true}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText("Vector Store Details")).toBeInTheDocument();
|
||||
expect(screen.getByText("Files")).toBeInTheDocument();
|
||||
const skeletons = container.querySelectorAll('[data-slot="skeleton"]');
|
||||
expect(skeletons.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Error States", () => {
|
||||
test("renders error message when store error occurs", () => {
|
||||
render(
|
||||
<VectorStoreDetailView
|
||||
{...defaultProps}
|
||||
errorStore={{ name: "Error", message: "Failed to load store" }}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText("Vector Store Details")).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText(/Error loading details for ID test_vector_store_id/)
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByText(/Failed to load store/)).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("renders files error when files fail to load", () => {
|
||||
const mockStore: VectorStore = {
|
||||
id: "vs_123",
|
||||
name: "Test Vector Store",
|
||||
created_at: 1710000000,
|
||||
status: "ready",
|
||||
file_counts: { total: 5 },
|
||||
usage_bytes: 1024,
|
||||
metadata: {
|
||||
provider_id: "test_provider",
|
||||
provider_vector_db_id: "test_db_id",
|
||||
},
|
||||
};
|
||||
|
||||
render(
|
||||
<VectorStoreDetailView
|
||||
{...defaultProps}
|
||||
store={mockStore}
|
||||
errorFiles={{ name: "Error", message: "Failed to load files" }}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText("Files")).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText("Error loading files: Failed to load files")
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Not Found State", () => {
|
||||
test("renders not found message when store is null", () => {
|
||||
render(<VectorStoreDetailView {...defaultProps} store={null} />);
|
||||
|
||||
expect(screen.getByText("Vector Store Details")).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText(/No details found for ID: test_vector_store_id/)
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Store Data Rendering", () => {
|
||||
const mockStore: VectorStore = {
|
||||
id: "vs_123",
|
||||
name: "Test Vector Store",
|
||||
created_at: 1710000000,
|
||||
status: "ready",
|
||||
file_counts: { total: 3 },
|
||||
usage_bytes: 2048,
|
||||
metadata: {
|
||||
provider_id: "test_provider",
|
||||
provider_vector_db_id: "test_db_id",
|
||||
},
|
||||
};
|
||||
|
||||
test("renders store properties correctly", () => {
|
||||
render(<VectorStoreDetailView {...defaultProps} store={mockStore} />);
|
||||
|
||||
expect(screen.getByText("Vector Store Details")).toBeInTheDocument();
|
||||
expect(screen.getByText("vs_123")).toBeInTheDocument();
|
||||
expect(screen.getByText("Test Vector Store")).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText(new Date(1710000000 * 1000).toLocaleString())
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByText("ready")).toBeInTheDocument();
|
||||
expect(screen.getByText("3")).toBeInTheDocument();
|
||||
expect(screen.getByText("2048")).toBeInTheDocument();
|
||||
expect(screen.getByText("test_provider")).toBeInTheDocument();
|
||||
expect(screen.getByText("test_db_id")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("handles empty/missing optional fields", () => {
|
||||
const minimalStore: VectorStore = {
|
||||
id: "vs_minimal",
|
||||
name: "",
|
||||
created_at: 1710000000,
|
||||
status: "ready",
|
||||
file_counts: { total: 0 },
|
||||
usage_bytes: 0,
|
||||
metadata: {},
|
||||
};
|
||||
|
||||
render(<VectorStoreDetailView {...defaultProps} store={minimalStore} />);
|
||||
|
||||
expect(screen.getByText("vs_minimal")).toBeInTheDocument();
|
||||
expect(screen.getByText("ready")).toBeInTheDocument();
|
||||
const zeroTexts = screen.getAllByText("0");
|
||||
expect(zeroTexts.length).toBeGreaterThanOrEqual(2);
|
||||
});
|
||||
|
||||
test("shows empty files message when no files", () => {
|
||||
render(
|
||||
<VectorStoreDetailView {...defaultProps} store={mockStore} files={[]} />
|
||||
);
|
||||
|
||||
expect(screen.getByText("Files")).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText("No files in this vector store.")
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Files Table", () => {
|
||||
const mockStore: VectorStore = {
|
||||
id: "vs_123",
|
||||
name: "Test Vector Store",
|
||||
created_at: 1710000000,
|
||||
status: "ready",
|
||||
file_counts: { total: 2 },
|
||||
usage_bytes: 2048,
|
||||
metadata: {},
|
||||
};
|
||||
|
||||
const mockFiles: VectorStoreFile[] = [
|
||||
{
|
||||
id: "file_123",
|
||||
status: "completed",
|
||||
created_at: 1710001000,
|
||||
usage_bytes: 1024,
|
||||
},
|
||||
{
|
||||
id: "file_456",
|
||||
status: "processing",
|
||||
created_at: 1710002000,
|
||||
usage_bytes: 512,
|
||||
},
|
||||
];
|
||||
|
||||
test("renders files table with correct data", () => {
|
||||
render(
|
||||
<VectorStoreDetailView
|
||||
{...defaultProps}
|
||||
store={mockStore}
|
||||
files={mockFiles}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByText("Files")).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText("Files in this vector store")
|
||||
).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText("ID")).toBeInTheDocument();
|
||||
expect(screen.getByText("Status")).toBeInTheDocument();
|
||||
expect(screen.getByText("Created")).toBeInTheDocument();
|
||||
expect(screen.getByText("Usage Bytes")).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText("file_123")).toBeInTheDocument();
|
||||
expect(screen.getByText("completed")).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText(new Date(1710001000 * 1000).toLocaleString())
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByText("1024")).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText("file_456")).toBeInTheDocument();
|
||||
expect(screen.getByText("processing")).toBeInTheDocument();
|
||||
expect(
|
||||
screen.getByText(new Date(1710002000 * 1000).toLocaleString())
|
||||
).toBeInTheDocument();
|
||||
expect(screen.getByText("512")).toBeInTheDocument();
|
||||
});
|
||||
|
||||
test("file ID links are clickable and navigate correctly", () => {
|
||||
render(
|
||||
<VectorStoreDetailView
|
||||
{...defaultProps}
|
||||
store={mockStore}
|
||||
files={mockFiles}
|
||||
id="vs_123"
|
||||
/>
|
||||
);
|
||||
|
||||
const fileButton = screen.getByRole("button", { name: "file_123" });
|
||||
expect(fileButton).toBeInTheDocument();
|
||||
|
||||
fireEvent.click(fileButton);
|
||||
expect(mockPush).toHaveBeenCalledWith(
|
||||
"/logs/vector-stores/vs_123/files/file_123"
|
||||
);
|
||||
});
|
||||
|
||||
test("handles multiple file clicks correctly", () => {
|
||||
render(
|
||||
<VectorStoreDetailView
|
||||
{...defaultProps}
|
||||
store={mockStore}
|
||||
files={mockFiles}
|
||||
id="vs_123"
|
||||
/>
|
||||
);
|
||||
|
||||
const file1Button = screen.getByRole("button", { name: "file_123" });
|
||||
const file2Button = screen.getByRole("button", { name: "file_456" });
|
||||
|
||||
fireEvent.click(file1Button);
|
||||
expect(mockPush).toHaveBeenCalledWith(
|
||||
"/logs/vector-stores/vs_123/files/file_123"
|
||||
);
|
||||
|
||||
fireEvent.click(file2Button);
|
||||
expect(mockPush).toHaveBeenCalledWith(
|
||||
"/logs/vector-stores/vs_123/files/file_456"
|
||||
);
|
||||
|
||||
expect(mockPush).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Layout Structure", () => {
|
||||
const mockStore: VectorStore = {
|
||||
id: "vs_layout_test",
|
||||
name: "Layout Test Store",
|
||||
created_at: 1710000000,
|
||||
status: "ready",
|
||||
file_counts: { total: 1 },
|
||||
usage_bytes: 1024,
|
||||
metadata: {},
|
||||
};
|
||||
|
||||
test("renders main content and sidebar in correct layout", () => {
|
||||
render(<VectorStoreDetailView {...defaultProps} store={mockStore} />);
|
||||
|
||||
expect(screen.getByText("Files")).toBeInTheDocument();
|
||||
|
||||
expect(screen.getByText("vs_layout_test")).toBeInTheDocument();
|
||||
expect(screen.getByText("Layout Test Store")).toBeInTheDocument();
|
||||
expect(screen.getByText("ready")).toBeInTheDocument();
|
||||
expect(screen.getByText("1")).toBeInTheDocument();
|
||||
expect(screen.getByText("1024")).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
@ -0,0 +1,143 @@
|
|||
"use client";
|
||||
|
||||
import { useRouter } from "next/navigation";
|
||||
import type { VectorStore } from "llama-stack-client/resources/vector-stores/vector-stores";
|
||||
import type { VectorStoreFile } from "llama-stack-client/resources/vector-stores/files";
|
||||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import {
|
||||
DetailLoadingView,
|
||||
DetailErrorView,
|
||||
DetailNotFoundView,
|
||||
DetailLayout,
|
||||
PropertiesCard,
|
||||
PropertyItem,
|
||||
} from "@/components/layout/detail-layout";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCaption,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
|
||||
interface VectorStoreDetailViewProps {
|
||||
store: VectorStore | null;
|
||||
files: VectorStoreFile[];
|
||||
isLoadingStore: boolean;
|
||||
isLoadingFiles: boolean;
|
||||
errorStore: Error | null;
|
||||
errorFiles: Error | null;
|
||||
id: string;
|
||||
}
|
||||
|
||||
export function VectorStoreDetailView({
|
||||
store,
|
||||
files,
|
||||
isLoadingStore,
|
||||
isLoadingFiles,
|
||||
errorStore,
|
||||
errorFiles,
|
||||
id,
|
||||
}: VectorStoreDetailViewProps) {
|
||||
const title = "Vector Store Details";
|
||||
const router = useRouter();
|
||||
|
||||
const handleFileClick = (fileId: string) => {
|
||||
router.push(`/logs/vector-stores/${id}/files/${fileId}`);
|
||||
};
|
||||
|
||||
if (errorStore) {
|
||||
return <DetailErrorView title={title} id={id} error={errorStore} />;
|
||||
}
|
||||
if (isLoadingStore) {
|
||||
return <DetailLoadingView title={title} />;
|
||||
}
|
||||
if (!store) {
|
||||
return <DetailNotFoundView title={title} id={id} />;
|
||||
}
|
||||
|
||||
const mainContent = (
|
||||
<>
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Files</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
{isLoadingFiles ? (
|
||||
<Skeleton className="h-4 w-full" />
|
||||
) : errorFiles ? (
|
||||
<div className="text-destructive text-sm">
|
||||
Error loading files: {errorFiles.message}
|
||||
</div>
|
||||
) : files.length > 0 ? (
|
||||
<Table>
|
||||
<TableCaption>Files in this vector store</TableCaption>
|
||||
<TableHeader>
|
||||
<TableRow>
|
||||
<TableHead>ID</TableHead>
|
||||
<TableHead>Status</TableHead>
|
||||
<TableHead>Created</TableHead>
|
||||
<TableHead>Usage Bytes</TableHead>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
{files.map(file => (
|
||||
<TableRow key={file.id}>
|
||||
<TableCell>
|
||||
<Button
|
||||
variant="link"
|
||||
className="p-0 h-auto font-mono text-blue-600 hover:text-blue-800 dark:text-blue-400 dark:hover:text-blue-300"
|
||||
onClick={() => handleFileClick(file.id)}
|
||||
>
|
||||
{file.id}
|
||||
</Button>
|
||||
</TableCell>
|
||||
<TableCell>{file.status}</TableCell>
|
||||
<TableCell>
|
||||
{new Date(file.created_at * 1000).toLocaleString()}
|
||||
</TableCell>
|
||||
<TableCell>{file.usage_bytes}</TableCell>
|
||||
</TableRow>
|
||||
))}
|
||||
</TableBody>
|
||||
</Table>
|
||||
) : (
|
||||
<p className="text-gray-500 italic text-sm">
|
||||
No files in this vector store.
|
||||
</p>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
</>
|
||||
);
|
||||
|
||||
const sidebar = (
|
||||
<PropertiesCard>
|
||||
<PropertyItem label="ID" value={store.id} />
|
||||
<PropertyItem label="Name" value={store.name || ""} />
|
||||
<PropertyItem
|
||||
label="Created"
|
||||
value={new Date(store.created_at * 1000).toLocaleString()}
|
||||
/>
|
||||
<PropertyItem label="Status" value={store.status} />
|
||||
<PropertyItem label="Total Files" value={store.file_counts.total} />
|
||||
<PropertyItem label="Usage Bytes" value={store.usage_bytes} />
|
||||
<PropertyItem
|
||||
label="Provider ID"
|
||||
value={(store.metadata.provider_id as string) || ""}
|
||||
/>
|
||||
<PropertyItem
|
||||
label="Provider DB ID"
|
||||
value={(store.metadata.provider_vector_db_id as string) || ""}
|
||||
/>
|
||||
</PropertiesCard>
|
||||
);
|
||||
|
||||
return (
|
||||
<DetailLayout title={title} mainContent={mainContent} sidebar={sidebar} />
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue