mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-29 01:03:17 +00:00
* feat(lens): own trace reads behind a cached TraceStore port Move storage-independent trace reads into litellm-traces-cache behind a TraceStore port that ClickHouse implements. One keyset pager drives the span, list span and spend reads, and a run list batch reads spend once. Trace opens, pages and list summaries share one resolved read per trace in an in-process cache with single-flight loading. Live traces and reads with unknown spend expire after 5s, quiet traces after 10 minutes, failed reads are never cached, and the accepted list page size is remembered per scope. Trace read failures map to their own status and code (400, 409, 413, 503 with Retry-After), and the trace drawer retries temporary failures while offering only a refresh for changed or oversized traces. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * perf(lens): seed large profiles with server-side copies and long sessions Replay one copy through the proxy, then copy it inside ClickHouse and PostgreSQL with INSERT ... SELECT, rewriting trace, span and call IDs so every copy keeps its own spend. Add three long single-trace sessions for drawer paging and the oversized read path Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * chores * style(lens): float the investigation setup badge on the tab edge Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * refactor(lens): restructure the trace drawer and polish its layout Split the 547-line TraceDrawer into run/, tree/, span/, content/ and conversation/ modules. Step rows now sit on one line with colored span family tiles, and the per-row timing bar moved into an optional Waterfall layout with a time axis. The steps and details panes are separated by the shadcn Resizable handle, with the split remembered per orientation. Span payloads go through one pure classifier (payloadView) that picks messages, a tool result, a nested field tree or text. JSON-encoded field values unfold into a tree, prose renders as markdown, repr and tracebacks stay monospace, and every section offers a Raw view. LangChain's serialized messages now render as conversation cards. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * typesafety * wip * fmt --------- Co-authored-by: Yujong Lee <yujong@berri.ai> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
101 lines
3.9 KiB
TypeScript
101 lines
3.9 KiB
TypeScript
import type { ReactElement } from "react";
|
|
import { vi } from "vitest";
|
|
import { LensServicesProvider, liveLensServices } from "@/components/lens/data/LensServices";
|
|
import { OnboardingProvider, type Onboarding } from "@/components/lens/onboarding/OnboardingContext";
|
|
import { LENS_INTRO_DISMISSED } from "@/components/lens/storage";
|
|
import { writeStorage } from "@/lib/storage";
|
|
import { renderWithProviders } from "./test-utils";
|
|
|
|
export interface StubbedRequest {
|
|
readonly path: string;
|
|
readonly method: string;
|
|
readonly query: URLSearchParams;
|
|
readonly body: unknown;
|
|
readonly authorization: string | null;
|
|
}
|
|
|
|
/** The path of a stubbed fetch call, whether a client passed a URL or a Request. */
|
|
export const requestPath = (input: RequestInfo | URL): string =>
|
|
new URL(input instanceof Request ? input.url : String(input), "http://localhost").pathname;
|
|
|
|
/** Reads a stubbed fetch call the same way whether a client passed a URL and init or a Request. */
|
|
export async function readRequest(input: RequestInfo | URL, init?: RequestInit): Promise<StubbedRequest> {
|
|
const request = input instanceof Request ? input : new Request(new URL(String(input), "http://localhost"), init);
|
|
const url = new URL(request.url);
|
|
const text = await request.clone().text();
|
|
return {
|
|
path: url.pathname,
|
|
method: request.method,
|
|
query: url.searchParams,
|
|
body: text ? JSON.parse(text) : undefined,
|
|
authorization: request.headers.get("Authorization"),
|
|
};
|
|
}
|
|
|
|
export interface GatewayRequest {
|
|
readonly query: Readonly<Record<string, string>>;
|
|
readonly body: unknown;
|
|
readonly authorization: string | null;
|
|
}
|
|
|
|
type GatewayHandler = (path: string, request: GatewayRequest) => unknown;
|
|
|
|
/**
|
|
* Fakes the proxy at fetch, so Lens code runs its real HTTP clients. Each method's handler gets the path and the
|
|
* parsed query and body; a rejection becomes a 500 carrying its message, and a pending promise stays pending.
|
|
*/
|
|
export function stubGateway() {
|
|
const gateway = {
|
|
get: vi.fn<GatewayHandler>(),
|
|
post: vi.fn<GatewayHandler>(),
|
|
put: vi.fn<GatewayHandler>(),
|
|
patch: vi.fn<GatewayHandler>(),
|
|
delete: vi.fn<GatewayHandler>(),
|
|
};
|
|
vi.stubGlobal(
|
|
"fetch",
|
|
vi.fn<typeof fetch>(async (input, init) => {
|
|
const { path, method, query, body, authorization } = await readRequest(input, init);
|
|
const handler = gateway[method.toLowerCase() as keyof typeof gateway];
|
|
try {
|
|
return Response.json((await handler(path, { query: Object.fromEntries(query), body, authorization })) ?? null);
|
|
} catch (error) {
|
|
return Response.json({ detail: error instanceof Error ? error.message : String(error) }, { status: 500 });
|
|
}
|
|
}),
|
|
);
|
|
return gateway;
|
|
}
|
|
|
|
/** The Lens introduction opens on a first visit; tests about anything else start with it dismissed. */
|
|
export function dismissLensIntro() {
|
|
writeStorage(LENS_INTRO_DISMISSED, true);
|
|
}
|
|
|
|
type LensRenderOptions = Parameters<typeof renderWithProviders>[1] & {
|
|
accessToken?: string;
|
|
onboarding?: Partial<Onboarding>;
|
|
};
|
|
|
|
/** Lens components read their API from context, so standalone renders need the live services for a token. */
|
|
export function renderWithLens(ui: ReactElement, options?: LensRenderOptions) {
|
|
const { accessToken = "test", onboarding: overrides, ...renderOptions } = options ?? {};
|
|
const services = liveLensServices(accessToken);
|
|
const onboarding: Onboarding = {
|
|
readOnly: false,
|
|
canViewInvestigations: true,
|
|
canInvestigate: true,
|
|
canMintTracingKey: true,
|
|
connect: () => {},
|
|
create: () => {},
|
|
openTrace: () => {},
|
|
...overrides,
|
|
};
|
|
const wrap = (element: ReactElement) => (
|
|
<LensServicesProvider services={services}>
|
|
<OnboardingProvider value={onboarding}>{element}</OnboardingProvider>
|
|
</LensServicesProvider>
|
|
);
|
|
const view = renderWithProviders(wrap(ui), renderOptions);
|
|
return { ...view, rerender: (next: ReactElement) => view.rerender(wrap(next)) };
|
|
}
|