From dd87b22782a4147b00a20fcd3db511835c62e682 Mon Sep 17 00:00:00 2001 From: Michael Silva Date: Mon, 17 Mar 2025 12:55:59 -0400 Subject: [PATCH 1/8] started --- .../components/controls/components/logs-search/index.tsx | 5 +++++ .../components/logs/llm-search/components/search-actions.tsx | 2 ++ .../logs/llm-search/components/search-example-tooltip.tsx | 5 +++-- apps/dashboard/components/logs/llm-search/index.tsx | 3 +++ 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/apps/dashboard/app/(app)/ratelimits/[namespaceId]/_overview/components/controls/components/logs-search/index.tsx b/apps/dashboard/app/(app)/ratelimits/[namespaceId]/_overview/components/controls/components/logs-search/index.tsx index b562471c46..4119c692fc 100644 --- a/apps/dashboard/app/(app)/ratelimits/[namespaceId]/_overview/components/controls/components/logs-search/index.tsx +++ b/apps/dashboard/app/(app)/ratelimits/[namespaceId]/_overview/components/controls/components/logs-search/index.tsx @@ -44,6 +44,11 @@ export const LogsSearch = () => { return ( diff --git a/apps/dashboard/components/logs/llm-search/components/search-actions.tsx b/apps/dashboard/components/logs/llm-search/components/search-actions.tsx index d754a32b2e..e31262c7e2 100644 --- a/apps/dashboard/components/logs/llm-search/components/search-actions.tsx +++ b/apps/dashboard/components/logs/llm-search/components/search-actions.tsx @@ -2,6 +2,7 @@ import { XMark } from "@unkey/icons"; import { SearchExampleTooltip } from "./search-example-tooltip"; type SearchActionsProps = { + exampleQueries?: { id: string; text: string }[]; searchText: string; hideClear: boolean; hideExplainer: boolean; @@ -15,6 +16,7 @@ type SearchActionsProps = { * SearchActions component renders the right-side actions (clear button or examples tooltip) */ export const SearchActions: React.FC = ({ + exampleQueries, searchText, hideClear, hideExplainer, diff --git a/apps/dashboard/components/logs/llm-search/components/search-example-tooltip.tsx b/apps/dashboard/components/logs/llm-search/components/search-example-tooltip.tsx index 8fbdd68d37..987a5475f9 100644 --- a/apps/dashboard/components/logs/llm-search/components/search-example-tooltip.tsx +++ b/apps/dashboard/components/logs/llm-search/components/search-example-tooltip.tsx @@ -3,10 +3,11 @@ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "compon type SearchExampleTooltipProps = { onSelectExample: (query: string) => void; + exampleQueries?: { id: string; text: string }[]; }; -export const SearchExampleTooltip: React.FC = ({ onSelectExample }) => { - const examples = [ +export const SearchExampleTooltip: React.FC = ({ onSelectExample, exampleQueries }) => { + const examples = exampleQueries ?? [ { id: "failed-requests", text: "Show failed requests today" }, { id: "auth-errors", text: "auth errors in the last 3h" }, { id: "api-calls", text: "API calls from a path that includes /api/v1/oz" }, diff --git a/apps/dashboard/components/logs/llm-search/index.tsx b/apps/dashboard/components/logs/llm-search/index.tsx index d2d2e7d1aa..300307984f 100644 --- a/apps/dashboard/components/logs/llm-search/index.tsx +++ b/apps/dashboard/components/logs/llm-search/index.tsx @@ -9,6 +9,7 @@ import { useSearchStrategy } from "./hooks/use-search-strategy"; type SearchMode = "allowTypeDuringSearch" | "debounced" | "manual"; type Props = { + exampleQueries?: { id: string; text: string }[]; onSearch: (query: string) => void; onClear?: () => void; placeholder?: string; @@ -22,6 +23,7 @@ type Props = { }; export const LogsLLMSearch = ({ + exampleQueries, onSearch, isLoading, onClear, @@ -154,6 +156,7 @@ export const LogsLLMSearch = ({ Date: Tue, 18 Mar 2025 10:50:23 -0400 Subject: [PATCH 2/8] working --- .../_components/controls/components/logs-search/index.tsx | 5 +++++ .../components/controls/components/logs-search/index.tsx | 5 +++++ .../components/controls/components/logs-search/index.tsx | 5 +++++ .../components/controls/components/logs-search/index.tsx | 6 +++--- .../components/controls/components/logs-search/index.tsx | 5 +++++ .../_components/controls/components/logs-search/index.tsx | 5 +++++ .../logs/llm-search/components/search-actions.tsx | 4 +++- .../logs/llm-search/components/search-example-tooltip.tsx | 5 ++++- apps/dashboard/lib/trpc/routers/audit/llm-search/utils.ts | 6 +++++- apps/dashboard/lib/trpc/routers/logs/llm-search/utils.ts | 5 ++++- .../lib/trpc/routers/ratelimit/llm-search/utils.ts | 5 ++++- 11 files changed, 48 insertions(+), 8 deletions(-) diff --git a/apps/dashboard/app/(app)/apis/_components/controls/components/logs-search/index.tsx b/apps/dashboard/app/(app)/apis/_components/controls/components/logs-search/index.tsx index 439a6a4705..b08f67b76f 100644 --- a/apps/dashboard/app/(app)/apis/_components/controls/components/logs-search/index.tsx +++ b/apps/dashboard/app/(app)/apis/_components/controls/components/logs-search/index.tsx @@ -46,6 +46,11 @@ export const LogsSearch = ({ onSearch, onApiListChange, apiList }: Props) => { return ( { return ( diff --git a/apps/dashboard/app/(app)/logs/components/controls/components/logs-search/index.tsx b/apps/dashboard/app/(app)/logs/components/controls/components/logs-search/index.tsx index 523aa0eea5..8e614e8792 100644 --- a/apps/dashboard/app/(app)/logs/components/controls/components/logs-search/index.tsx +++ b/apps/dashboard/app/(app)/logs/components/controls/components/logs-search/index.tsx @@ -44,6 +44,11 @@ export const LogsSearch = () => { return ( diff --git a/apps/dashboard/app/(app)/ratelimits/[namespaceId]/_overview/components/controls/components/logs-search/index.tsx b/apps/dashboard/app/(app)/ratelimits/[namespaceId]/_overview/components/controls/components/logs-search/index.tsx index 4119c692fc..465b029685 100644 --- a/apps/dashboard/app/(app)/ratelimits/[namespaceId]/_overview/components/controls/components/logs-search/index.tsx +++ b/apps/dashboard/app/(app)/ratelimits/[namespaceId]/_overview/components/controls/components/logs-search/index.tsx @@ -45,9 +45,9 @@ export const LogsSearch = () => { return ( { return ( diff --git a/apps/dashboard/app/(app)/ratelimits/_components/controls/components/logs-search/index.tsx b/apps/dashboard/app/(app)/ratelimits/_components/controls/components/logs-search/index.tsx index 2a73b38bcb..da252c2fe7 100644 --- a/apps/dashboard/app/(app)/ratelimits/_components/controls/components/logs-search/index.tsx +++ b/apps/dashboard/app/(app)/ratelimits/_components/controls/components/logs-search/index.tsx @@ -41,6 +41,11 @@ export const LogsSearch = ({ setNamespaces, initialNamespaces }: LogsSearchProps return ( = ({ } if (searchText.length === 0 && !hideExplainer) { - return ; + return ( + + ); } return null; diff --git a/apps/dashboard/components/logs/llm-search/components/search-example-tooltip.tsx b/apps/dashboard/components/logs/llm-search/components/search-example-tooltip.tsx index 987a5475f9..9c77201600 100644 --- a/apps/dashboard/components/logs/llm-search/components/search-example-tooltip.tsx +++ b/apps/dashboard/components/logs/llm-search/components/search-example-tooltip.tsx @@ -6,7 +6,10 @@ type SearchExampleTooltipProps = { exampleQueries?: { id: string; text: string }[]; }; -export const SearchExampleTooltip: React.FC = ({ onSelectExample, exampleQueries }) => { +export const SearchExampleTooltip: React.FC = ({ + onSelectExample, + exampleQueries, +}) => { const examples = exampleQueries ?? [ { id: "failed-requests", text: "Show failed requests today" }, { id: "auth-errors", text: "auth errors in the last 3h" }, diff --git a/apps/dashboard/lib/trpc/routers/audit/llm-search/utils.ts b/apps/dashboard/lib/trpc/routers/audit/llm-search/utils.ts index 61dbed9350..d2a506bfc1 100644 --- a/apps/dashboard/lib/trpc/routers/audit/llm-search/utils.ts +++ b/apps/dashboard/lib/trpc/routers/audit/llm-search/utils.ts @@ -13,8 +13,12 @@ export async function getStructuredAuditSearchFromLLM( usersReferenceMS: number, ) { try { + // Skip LLM processing in development environment when OpenAI API key is not configured if (!openai) { - return null; // Skip LLM processing in development environment when OpenAI API key is not configured + throw new TRPCError({ + code: "PRECONDITION_FAILED", + message: "OpenAI isn't configured correctly, please check your API key", + }); } const completion = await openai.beta.chat.completions.parse({ diff --git a/apps/dashboard/lib/trpc/routers/logs/llm-search/utils.ts b/apps/dashboard/lib/trpc/routers/logs/llm-search/utils.ts index 3228d3c279..1c9ae73d01 100644 --- a/apps/dashboard/lib/trpc/routers/logs/llm-search/utils.ts +++ b/apps/dashboard/lib/trpc/routers/logs/llm-search/utils.ts @@ -11,7 +11,10 @@ export async function getStructuredSearchFromLLM( ) { try { if (!openai) { - return null; // Skip LLM processing in development environment when OpenAI API key is not configured + throw new TRPCError({ + code: "PRECONDITION_FAILED", + message: "OpenAI isn't configured correctly, please check your API key", + }); } const completion = await openai.beta.chat.completions.parse({ // Don't change the model only a few models allow structured outputs diff --git a/apps/dashboard/lib/trpc/routers/ratelimit/llm-search/utils.ts b/apps/dashboard/lib/trpc/routers/ratelimit/llm-search/utils.ts index 861e40db92..fa703beb56 100644 --- a/apps/dashboard/lib/trpc/routers/ratelimit/llm-search/utils.ts +++ b/apps/dashboard/lib/trpc/routers/ratelimit/llm-search/utils.ts @@ -30,7 +30,10 @@ export async function getStructuredSearchFromLLM( ) { try { if (!openai) { - return null; // Skip LLM processing in development environment when OpenAI API key is not configured + throw new TRPCError({ + code: "PRECONDITION_FAILED", + message: "OpenAI isn't configured correctly, please check your API key", + }); } const completion = await openai.beta.chat.completions.parse({ // Don't change the model only a few models allow structured outputs From 761b2fbf70a2a32fcf3b584ea47ecfe2be0c37d5 Mon Sep 17 00:00:00 2001 From: Michael Silva Date: Thu, 20 Mar 2025 09:55:02 -0400 Subject: [PATCH 3/8] wording edits on search suggestions --- .../components/controls/components/logs-search/index.tsx | 6 +++--- .../components/controls/components/logs-search/index.tsx | 4 ++-- .../components/controls/components/logs-search/index.tsx | 6 +++--- .../components/controls/components/logs-search/index.tsx | 9 ++++++--- .../controls/components/logs-search/index.tsx | 9 ++++++--- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/apps/dashboard/app/(app)/audit/components/controls/components/logs-search/index.tsx b/apps/dashboard/app/(app)/audit/components/controls/components/logs-search/index.tsx index c425071b7c..bace2bdd3a 100644 --- a/apps/dashboard/app/(app)/audit/components/controls/components/logs-search/index.tsx +++ b/apps/dashboard/app/(app)/audit/components/controls/components/logs-search/index.tsx @@ -45,9 +45,9 @@ export const LogsSearch = () => { return ( { { return ( { return ( Date: Thu, 20 Mar 2025 11:04:48 -0400 Subject: [PATCH 4/8] fix typo --- .../_components/controls/components/logs-search/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/dashboard/app/(app)/ratelimits/_components/controls/components/logs-search/index.tsx b/apps/dashboard/app/(app)/ratelimits/_components/controls/components/logs-search/index.tsx index e5b41d35fc..0c7a006816 100644 --- a/apps/dashboard/app/(app)/ratelimits/_components/controls/components/logs-search/index.tsx +++ b/apps/dashboard/app/(app)/ratelimits/_components/controls/components/logs-search/index.tsx @@ -42,7 +42,7 @@ export const LogsSearch = ({ setNamespaces, initialNamespaces }: LogsSearchProps return ( Date: Thu, 20 Mar 2025 11:21:06 -0400 Subject: [PATCH 5/8] added examples to api route --- .../components/controls/components/logs-search/index.tsx | 5 +++++ .../components/controls/components/logs-search/index.tsx | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/dashboard/app/(app)/apis/[apiId]/_overview/components/controls/components/logs-search/index.tsx b/apps/dashboard/app/(app)/apis/[apiId]/_overview/components/controls/components/logs-search/index.tsx index f7fe9cb659..83cf914e1a 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/_overview/components/controls/components/logs-search/index.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/_overview/components/controls/components/logs-search/index.tsx @@ -44,6 +44,11 @@ export const LogsSearch = ({ apiId }: { apiId: string }) => { return ( diff --git a/apps/dashboard/app/(app)/ratelimits/[namespaceId]/logs/components/controls/components/logs-search/index.tsx b/apps/dashboard/app/(app)/ratelimits/[namespaceId]/logs/components/controls/components/logs-search/index.tsx index 641f166e8f..304c51aa33 100644 --- a/apps/dashboard/app/(app)/ratelimits/[namespaceId]/logs/components/controls/components/logs-search/index.tsx +++ b/apps/dashboard/app/(app)/ratelimits/[namespaceId]/logs/components/controls/components/logs-search/index.tsx @@ -45,7 +45,7 @@ export const LogsSearch = () => { return ( Date: Thu, 20 Mar 2025 14:50:26 -0400 Subject: [PATCH 6/8] change to string array --- .../controls/components/logs-search/index.tsx | 6 +++--- .../controls/components/logs-search/index.tsx | 6 +++--- .../controls/components/logs-search/index.tsx | 6 +++--- .../controls/components/logs-search/index.tsx | 6 +++--- .../controls/components/logs-search/index.tsx | 6 +++--- .../controls/components/logs-search/index.tsx | 9 +++------ .../controls/components/logs-search/index.tsx | 9 +++------ .../llm-search/components/search-actions.tsx | 2 +- .../components/search-example-tooltip.tsx | 16 ++++++++-------- .../components/logs/llm-search/index.tsx | 2 +- 10 files changed, 31 insertions(+), 37 deletions(-) diff --git a/apps/dashboard/app/(app)/apis/[apiId]/_overview/components/controls/components/logs-search/index.tsx b/apps/dashboard/app/(app)/apis/[apiId]/_overview/components/controls/components/logs-search/index.tsx index 83cf914e1a..712fe0c3fc 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/_overview/components/controls/components/logs-search/index.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/_overview/components/controls/components/logs-search/index.tsx @@ -45,9 +45,9 @@ export const LogsSearch = ({ apiId }: { apiId: string }) => { return ( { return ( { return ( { return ( { return ( { return ( void; - exampleQueries?: { id: string; text: string }[]; + exampleQueries?: string[]; }; export const SearchExampleTooltip: React.FC = ({ @@ -11,9 +11,9 @@ export const SearchExampleTooltip: React.FC = ({ exampleQueries, }) => { const examples = exampleQueries ?? [ - { id: "failed-requests", text: "Show failed requests today" }, - { id: "auth-errors", text: "auth errors in the last 3h" }, - { id: "api-calls", text: "API calls from a path that includes /api/v1/oz" }, + "Show failed requests today", + "auth errors in the last 3h", + "API calls from a path that includes /api/v1/oz", ]; return ( @@ -35,15 +35,15 @@ export const SearchExampleTooltip: React.FC = ({
    {examples.map((example) => ( -
  • +
  • ))} diff --git a/apps/dashboard/components/logs/llm-search/index.tsx b/apps/dashboard/components/logs/llm-search/index.tsx index 300307984f..1c48576f52 100644 --- a/apps/dashboard/components/logs/llm-search/index.tsx +++ b/apps/dashboard/components/logs/llm-search/index.tsx @@ -9,7 +9,7 @@ import { useSearchStrategy } from "./hooks/use-search-strategy"; type SearchMode = "allowTypeDuringSearch" | "debounced" | "manual"; type Props = { - exampleQueries?: { id: string; text: string }[]; + exampleQueries?: string[]; onSearch: (query: string) => void; onClear?: () => void; placeholder?: string; From a74d3f6dfb4830c98198f08a479664edcc8854b9 Mon Sep 17 00:00:00 2001 From: Michael Silva Date: Thu, 20 Mar 2025 15:52:59 -0400 Subject: [PATCH 7/8] fix tests --- .../lib/trpc/routers/logs/llm-search/utils.test.ts | 9 +++++++-- .../lib/trpc/routers/ratelimit/llm-search/utils.test.ts | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/apps/dashboard/lib/trpc/routers/logs/llm-search/utils.test.ts b/apps/dashboard/lib/trpc/routers/logs/llm-search/utils.test.ts index 49104c58d2..726622f908 100644 --- a/apps/dashboard/lib/trpc/routers/logs/llm-search/utils.test.ts +++ b/apps/dashboard/lib/trpc/routers/logs/llm-search/utils.test.ts @@ -27,9 +27,14 @@ describe("getStructuredSearchFromLLM", () => { }, }; - it("should return null if openai is not configured", async () => { + it("should return TRPCError if openai is not configured", async () => { const result = await getStructuredSearchFromLLM(null as any, "test query", 1706024400000); - expect(result).toBeNull(); + expect(result).rejects.toThrowError( + new TRPCError({ + code: "PRECONDITION_FAILED", + message: "OpenAI isn't configured correctly, please check your API key", + }), + ); }); it("should handle successful LLM response", async () => { diff --git a/apps/dashboard/lib/trpc/routers/ratelimit/llm-search/utils.test.ts b/apps/dashboard/lib/trpc/routers/ratelimit/llm-search/utils.test.ts index 5ae0ef763b..538160e156 100644 --- a/apps/dashboard/lib/trpc/routers/ratelimit/llm-search/utils.test.ts +++ b/apps/dashboard/lib/trpc/routers/ratelimit/llm-search/utils.test.ts @@ -43,9 +43,14 @@ describe("getStructuredSearchFromLLM", () => { }, }; - it("should return null if openai is not configured", async () => { + it("should return TRPCError if openai is not configured", async () => { const result = await getStructuredSearchFromLLM(null as any, "test query", 1706024400000); - expect(result).toBeNull(); + expect(result).rejects.toThrowError( + new TRPCError({ + code: "PRECONDITION_FAILED", + message: "OpenAI isn't configured correctly, please check your API key", + }), + ); }); it("should handle successful LLM response", async () => { From c647a4002ad5ef5ce8ba7a2ae2991b7e18b21400 Mon Sep 17 00:00:00 2001 From: Michael Silva Date: Thu, 20 Mar 2025 16:15:35 -0400 Subject: [PATCH 8/8] typo fix --- .../components/controls/components/logs-search/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/dashboard/app/(app)/apis/[apiId]/_overview/components/controls/components/logs-search/index.tsx b/apps/dashboard/app/(app)/apis/[apiId]/_overview/components/controls/components/logs-search/index.tsx index 712fe0c3fc..e6a189c231 100644 --- a/apps/dashboard/app/(app)/apis/[apiId]/_overview/components/controls/components/logs-search/index.tsx +++ b/apps/dashboard/app/(app)/apis/[apiId]/_overview/components/controls/components/logs-search/index.tsx @@ -46,7 +46,7 @@ export const LogsSearch = ({ apiId }: { apiId: string }) => {