Skip to content

SigNoz is an open-source, OpenTelemetry-native observability platform for your team and their AI agents. Get logs, metrics, and traces in one tool with features like APM, distributed tracing, log management, infra monitoring, etc. Combined with SigNoz MCP and a native AI teammate (in SigNoz Cloud) it helps you build more resilient apps.

feat: use empty suggestions api for empty ui state of ai assistant (#11744)

Yunus Mbdb0091c879e
diff --git a/frontend/src/api/ai-assistant/chat.ts b/frontend/src/api/ai-assistant/chat.ts
index 6be69a652a..fd62b20171 100644
--- a/frontend/src/api/ai-assistant/chat.ts
+++ b/frontend/src/api/ai-assistant/chat.ts
@@ -55,6 +55,9 @@ import type {
ThreadDetailResponseDTO,
ThreadListResponseDTO,
ThreadSummaryDTO,
+ ChipDTO,
+ ChipsResponseDTO,
+ PageTypeDTO,
ToolCallEventDTO,
ToolResultEventDTO,
} from './sigNozAIAssistantAPI.schemas';
@@ -541,3 +544,19 @@ export async function submitFeedback(
comment: comment ?? null,
});
}
+
+// ---------------------------------------------------------------------------
+// Contextual empty-state chips
+// GET /api/v1/assistant/empty-state/chips?page_type=… → { chips }
+// ---------------------------------------------------------------------------
+
+export async function getEmptyStateChips(
+ pageType: PageTypeDTO,
+ signal?: AbortSignal,
+): Promise<ChipDTO[]> {
+ const response = await AIAssistantInstance.get<ChipsResponseDTO>(
+ '/empty-state/chips',
+ { params: { page_type: pageType }, signal },
+ );
+ return response.data.chips;
+}
diff --git a/frontend/src/api/ai-assistant/index.ts b/frontend/src/api/ai-assistant/index.ts
index 9e5b19c78b..b797d08a68 100644
--- a/frontend/src/api/ai-assistant/index.ts
+++ b/frontend/src/api/ai-assistant/index.ts
@@ -26,6 +26,7 @@ import type {
CancelApiV1AssistantCancelPostHeaders,
CancelRequestDTO,
CancelResponseDTO,
+ ChipsResponseDTO,
ClarifyApiV1AssistantClarifyPostHeaders,
ClarifyRequestDTO,
ClarifyResponseDTO,
@@ -39,8 +40,11 @@ import type {
ErrorResponseDTO,
FeedbackRequestDTO,
FeedbackResponseDTO,
+ GetChipsApiV1AssistantEmptyStateChipsGetHeaders,
+ GetChipsApiV1AssistantEmptyStateChipsGetParams,
GetThreadApiV1AssistantThreadsThreadIdGetHeaders,
GetThreadApiV1AssistantThreadsThreadIdGetPathParameters,
+ GetUsageApiV1AssistantUsageGetHeaders,
HTTPValidationErrorDTO,
HealthResponseDTO,
ListThreadsApiV1AssistantThreadsGetHeaders,
@@ -65,93 +69,89 @@ import type {
UpdateThreadApiV1AssistantThreadsThreadIdPatchHeaders,
UpdateThreadApiV1AssistantThreadsThreadIdPatchPathParameters,
UpdateThreadRequestDTO,
+ UsageResponseDTO,
} from './sigNozAIAssistantAPI.schemas';
-import {
- GeneratedAPIInstance,
- getGeneratedAPIQueryKeyHeaders,
-} from '../generatedAPIInstance';
+import { GeneratedAPIInstance } from '../generatedAPIInstance';
import type { ErrorType, BodyType } from '../generatedAPIInstance';
/**
- * @summary Health
+ * @summary Healthz
*/
-export const healthHealthGet = (signal?: AbortSignal) => {
+export const healthzHealthzGet = (signal?: AbortSignal) => {
return GeneratedAPIInstance<HealthResponseDTO>({
- url: `/health`,
+ url: `/healthz`,
method: 'GET',
signal,
});
};
-export const getHealthHealthGetQueryKey = () => {
- return [`/health`] as const;
+export const getHealthzHealthzGetQueryKey = () => {
+ return [`/healthz`] as const;
};
-export const getHealthHealthGetQueryOptions = <
- TData = Awaited<ReturnType<typeof healthHealthGet>>,
+export const getHealthzHealthzGetQueryOptions = <
+ TData = Awaited<ReturnType<typeof healthzHealthzGet>>,
TError = ErrorType<unknown>,
>(options?: {
query?: UseQueryOptions<
- Awaited<ReturnType<typeof healthHealthGet>>,
+ Awaited<ReturnType<typeof healthzHealthzGet>>,
TError,
TData
>;
}) => {
const { query: queryOptions } = options ?? {};
- const queryKey = queryOptions?.queryKey ?? getHealthHealthGetQueryKey();
+ const queryKey = queryOptions?.queryKey ?? getHealthzHealthzGetQueryKey();
- const queryFn: QueryFunction<Awaited<ReturnType<typeof healthHealthGet>>> = ({
- signal,
- }) => healthHealthGet(signal);
+ const queryFn: QueryFunction<
+ Awaited<ReturnType<typeof healthzHealthzGet>>
+ > = ({ signal }) => healthzHealthzGet(signal);
return { queryKey, queryFn, ...queryOptions } as UseQueryOptions<
- Awaited<ReturnType<typeof healthHealthGet>>,
+ Awaited<ReturnType<typeof healthzHealthzGet>>,
TError,
TData
> & { queryKey: QueryKey };
};
-export type HealthHealthGetQueryResult = NonNullable<
- Awaited<ReturnType<typeof healthHealthGet>>
+export type HealthzHealthzGetQueryResult = NonNullable<
+ Awaited<ReturnType<typeof healthzHealthzGet>>
>;
-export type HealthHealthGetQueryError = ErrorType<unknown>;
+export type HealthzHealthzGetQueryError = ErrorType<unknown>;
/**
- * @summary Health
+ * @summary Healthz
*/
-export function useHealthHealthGet<
- TData = Awaited<ReturnType<typeof healthHealthGet>>,
+export function useHealthzHealthzGet<
+ TData = Awaited<ReturnType<typeof healthzHealthzGet>>,
TError = ErrorType<unknown>,
>(options?: {
query?: UseQueryOptions<
- Awaited<ReturnType<typeof healthHealthGet>>,
+ Awaited<ReturnType<typeof healthzHealthzGet>>,
TError,
TData
>;
}): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
- const queryOptions = getHealthHealthGetQueryOptions(options);
+ const queryOptions = getHealthzHealthzGetQueryOptions(options);
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & {
queryKey: QueryKey;
};
- query.queryKey = queryOptions.queryKey;
-
- return query;
+ return { ...query, queryKey: queryOptions.queryKey };
}
/**
- * @summary Health
+ * @summary Healthz
*/
-export const invalidateHealthHealthGet = async (
+export const invalidateHealthzHealthzGet = async (
queryClient: QueryClient,
options?: InvalidateOptions,
): Promise<QueryClient> => {
await queryClient.invalidateQueries(
- { queryKey: getHealthHealthGetQueryKey() },
+ { queryKey: getHealthzHealthzGetQueryKey() },
options,
);
@@ -159,84 +159,82 @@ export const invalidateHealthHealthGet = async (
};
/**
- * @summary Ready
+ * @summary Readyz
*/
-export const readyReadyGet = (signal?: AbortSignal) => {
+export const readyzReadyzGet = (signal?: AbortSignal) => {
return GeneratedAPIInstance<ReadinessResponseDTO>({
- url: `/ready`,
+ url: `/readyz`,
method: 'GET',
signal,
});
};
-export const getReadyReadyGetQueryKey = () => {
- return [`/ready`] as const;
+export const getReadyzReadyzGetQueryKey = () => {
+ return [`/readyz`] as const;
};
-export const getReadyReadyGetQueryOptions = <
- TData = Awaited<ReturnType<typeof readyReadyGet>>,
+export const getReadyzReadyzGetQueryOptions = <
+ TData = Awaited<ReturnType<typeof readyzReadyzGet>>,
TError = ErrorType<ReadinessResponseDTO>,
>(options?: {
query?: UseQueryOptions<
- Awaited<ReturnType<typeof readyReadyGet>>,
+ Awaited<ReturnType<typeof readyzReadyzGet>>,
TError,
TData
>;
}) => {
const { query: queryOptions } = options ?? {};
- const queryKey = queryOptions?.queryKey ?? getReadyReadyGetQueryKey();
+ const queryKey = queryOptions?.queryKey ?? getReadyzReadyzGetQueryKey();
- const queryFn: QueryFunction<Awaited<ReturnType<typeof readyReadyGet>>> = ({
+ const queryFn: QueryFunction<Awaited<ReturnType<typeof readyzReadyzGet>>> = ({
signal,
- }) => readyReadyGet(signal);
+ }) => readyzReadyzGet(signal);
return { queryKey, queryFn, ...queryOptions } as UseQueryOptions<
- Awaited<ReturnType<typeof readyReadyGet>>,
+ Awaited<ReturnType<typeof readyzReadyzGet>>,
TError,
TData
> & { queryKey: QueryKey };
};
-export type ReadyReadyGetQueryResult = NonNullable<
- Awaited<ReturnType<typeof readyReadyGet>>
+export type ReadyzReadyzGetQueryResult = NonNullable<
+ Awaited<ReturnType<typeof readyzReadyzGet>>
>;
-export type ReadyReadyGetQueryError = ErrorType<ReadinessResponseDTO>;
+export type ReadyzReadyzGetQueryError = ErrorType<ReadinessResponseDTO>;
/**
- * @summary Ready
+ * @summary Readyz
*/
-export function useReadyReadyGet<
- TData = Awaited<ReturnType<typeof readyReadyGet>>,
+export function useReadyzReadyzGet<
+ TData = Awaited<ReturnType<typeof readyzReadyzGet>>,
TError = ErrorType<ReadinessResponseDTO>,
>(options?: {
query?: UseQueryOptions<
- Awaited<ReturnType<typeof readyReadyGet>>,
+ Awaited<ReturnType<typeof readyzReadyzGet>>,
TError,
TData
>;
}): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
- const queryOptions = getReadyReadyGetQueryOptions(options);
+ const queryOptions = getReadyzReadyzGetQueryOptions(options);
const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & {
queryKey: QueryKey;
};
- query.queryKey = queryOptions.queryKey;
-
- return query;
+ return { ...query, queryKey: queryOptions.queryKey };
}
/**
- * @summary Ready
+ * @summary Readyz
*/
-export const invalidateReadyReadyGet = async (
+export const invalidateReadyzReadyzGet = async (
queryClient: QueryClient,
options?: InvalidateOptions,
): Promise<QueryClient> => {
await queryClient.invalidateQueries(
- { queryKey: getReadyReadyGetQueryKey() },
+ { queryKey: getReadyzReadyzGetQueryKey() },
options,
);
@@ -247,7 +245,7 @@ export const invalidateReadyReadyGet = async (
* @summary Create a new thread
*/
export const createThreadApiV1AssistantThreadsPost = (
- createThreadApiV1AssistantThreadsPostBody: BodyType<CreateThreadApiV1AssistantThreadsPostBody>,
+ createThreadApiV1AssistantThreadsPostBody?: BodyType<CreateThreadApiV1AssistantThreadsPostBody>,
headers?: CreateThreadApiV1AssistantThreadsPostHeaders,
signal?: AbortSignal,
) => {
@@ -268,7 +266,7 @@ export const getCreateThreadApiV1AssistantThreadsPostMutationOptions = <
Awaited<ReturnType<typeof createThreadApiV1AssistantThreadsPost>>,
TError,
{
- data: BodyType<CreateThreadApiV1AssistantThreadsPostBody>;
+ data?: BodyType<CreateThreadApiV1AssistantThreadsPostBody>;
headers?: CreateThreadApiV1AssistantThreadsPostHeaders;
},
TContext
@@ -277,7 +275,7 @@ export const getCreateThreadApiV1AssistantThreadsPostMutationOptions = <
Awaited<ReturnType<typeof createThreadApiV1AssistantThreadsPost>>,
TError,
{
- data: BodyType<CreateThreadApiV1AssistantThreadsPostBody>;
+ data?: BodyType<CreateThreadApiV1AssistantThreadsPostBody>;
headers?: CreateThreadApiV1AssistantThreadsPostHeaders;
},
TContext
@@ -294,7 +292,7 @@ export const getCreateThreadApiV1AssistantThreadsPostMutationOptions = <
const mutationFn: MutationFunction<
Awaited<ReturnType<typeof createThreadApiV1AssistantThreadsPost>>,
{
- data: BodyType<CreateThreadApiV1AssistantThreadsPostBody>;
+ data?: BodyType<CreateThreadApiV1AssistantThreadsPostBody>;
headers?: CreateThreadApiV1AssistantThreadsPostHeaders;
}
> = (props) => {
@@ -310,7 +308,8 @@ export type CreateThreadApiV1AssistantThreadsPostMutationResult = NonNullable<
Awaited<ReturnType<typeof createThreadApiV1AssistantThreadsPost>>
>;
export type CreateThreadApiV1AssistantThreadsPostMutationBody =
- BodyType<CreateThreadApiV1AssistantThreadsPostBody>;
+ | BodyType<CreateThreadApiV1AssistantThreadsPostBody>
+ | undefined;
export type CreateThreadApiV1AssistantThreadsPostMutationError = ErrorType<
ErrorResponseDTO | HTTPValidationErrorDTO
>;
@@ -326,7 +325,7 @@ export const useCreateThreadApiV1AssistantThreadsPost = <
Awaited<ReturnType<typeof createThreadApiV1AssistantThreadsPost>>,
TError,
{
- data: BodyType<CreateThreadApiV1AssistantThreadsPostBody>;
+ data?: BodyType<CreateThreadApiV1AssistantThreadsPostBody>;
headers?: CreateThreadApiV1AssistantThreadsPostHeaders;
},
TContext
@@ -335,15 +334,14 @@ export const useCreateThreadApiV1AssistantThreadsPost = <
Awaited<ReturnType<typeof createThreadApiV1AssistantThreadsPost>>,
TError,
{
- data: BodyType<CreateThreadApiV1AssistantThreadsPostBody>;
+ data?: BodyType<CreateThreadApiV1AssistantThreadsPostBody>;
headers?: CreateThreadApiV1AssistantThreadsPostHeaders;
},
TContext
> => {
- const mutationOptions =
- getCreateThreadApiV1AssistantThreadsPostMutationOptions(options);
-
- return useMutation(mutationOptions);
+ return useMutation(
+ getCreateThreadApiV1AssistantThreadsPostMutationOptions(options),
+ );
};
/**
* Cursor-based pagination, sorted by updatedAt desc. Use `archived=true|false|all` to filter.
@@ -365,13 +363,8 @@ export const listThreadsApiV1AssistantThreadsGet = (
export const getListThreadsApiV1AssistantThreadsGetQueryKey = (
params?: ListThreadsApiV1AssistantThreadsGetParams,
- headers?: ListThreadsApiV1AssistantThreadsGetHeaders,
) => {
- return [
- `/api/v1/assistant/threads`,
- ...(params ? [params] : []),
- ...getGeneratedAPIQueryKeyHeaders(headers),
- ] as const;
+ return [`/api/v1/assistant/threads`, ...(params ? [params] : [])] as const;
};
export const getListThreadsApiV1AssistantThreadsGetQueryOptions = <
@@ -392,7 +385,7 @@ export const getListThreadsApiV1AssistantThreadsGetQueryOptions = <
const queryKey =
queryOptions?.queryKey ??
- getListThreadsApiV1AssistantThreadsGetQueryKey(params, headers);
+ getListThreadsApiV1AssistantThreadsGetQueryKey(params);
const queryFn: QueryFunction<
Awaited<ReturnType<typeof listThreadsApiV1AssistantThreadsGet>>
@@ -441,9 +434,7 @@ export function useListThreadsApiV1AssistantThreadsGet<
queryKey: QueryKey;
};
- query.queryKey = queryOptions.queryKey;
-
- return query;
+ return { ...query, queryKey: queryOptions.queryKey };
}
/**
@@ -456,7 +447,7 @@ export const invalidateListThreadsApiV1AssistantThreadsGet = async (
options?: InvalidateOptions,
): Promise<QueryClient> => {
await queryClient.invalidateQueries(
- { queryKey: getListThreadsApiV1AssistantThreadsGetQueryKey(params, headers) },
+ { queryKey: getListThreadsApiV1AssistantThreadsGetQueryKey(params) },
options,
);
@@ -480,14 +471,10 @@ export const getThreadApiV1AssistantThreadsThreadIdGet = (
});
};
-export const getGetThreadApiV1AssistantThreadsThreadIdGetQueryKey = (
- { threadId }: GetThreadApiV1AssistantThreadsThreadIdGetPathParameters,
- headers?: GetThreadApiV1AssistantThreadsThreadIdGetHeaders,
-) => {
- return [
- `/api/v1/assistant/threads/${threadId}`,
- ...getGeneratedAPIQueryKeyHeaders(headers),
- ] as const;
+export const getGetThreadApiV1AssistantThreadsThreadIdGetQueryKey = ({
+ threadId,
+}: GetThreadApiV1AssistantThreadsThreadIdGetPathParameters) => {
+ return [`/api/v1/assistant/threads/${threadId}`] as const;
};
export const getGetThreadApiV1AssistantThreadsThreadIdGetQueryOptions = <
@@ -508,7 +495,7 @@ export const getGetThreadApiV1AssistantThreadsThreadIdGetQueryOptions = <
const queryKey =
queryOptions?.queryKey ??
- getGetThreadApiV1AssistantThreadsThreadIdGetQueryKey({ threadId }, headers);
+ getGetThreadApiV1AssistantThreadsThreadIdGetQueryKey({ threadId });
const queryFn: QueryFunction<
Awaited<ReturnType<typeof getThreadApiV1AssistantThreadsThreadIdGet>>
@@ -562,9 +549,7 @@ export function useGetThreadApiV1AssistantThreadsThreadIdGet<
queryKey: QueryKey;
};
- query.queryKey = queryOptions.queryKey;
-
- return query;
+ return { ...query, queryKey: queryOptions.queryKey };
}
/**
@@ -578,10 +563,7 @@ export const invalidateGetThreadApiV1AssistantThreadsThreadIdGet = async (
): Promise<QueryClient> => {
await queryClient.invalidateQueries(
{
- queryKey: getGetThreadApiV1AssistantThreadsThreadIdGetQueryKey(
- { threadId },
- headers,
- ),
+ queryKey: getGetThreadApiV1AssistantThreadsThreadIdGetQueryKey({ threadId }),
},
options,
);
@@ -596,12 +578,14 @@ export const updateThreadApiV1AssistantThreadsThreadIdPatch = (
{ threadId }: UpdateThreadApiV1AssistantThreadsThreadIdPatchPathParameters,
updateThreadRequestDTO: BodyType<UpdateThreadRequestDTO>,
headers?: UpdateThreadApiV1AssistantThreadsThreadIdPatchHeaders,
+ signal?: AbortSignal,
) => {
return GeneratedAPIInstance<ThreadSummaryDTO>({
url: `/api/v1/assistant/threads/${threadId}`,
method: 'PATCH',
headers: { 'Content-Type': 'application/json', ...headers },
data: updateThreadRequestDTO,
+ signal,
});
};
@@ -695,10 +679,9 @@ export const useUpdateThreadApiV1AssistantThreadsThreadIdPatch = <
},
TContext
> => {
- const mutationOptions =
- getUpdateThreadApiV1AssistantThreadsThreadIdPatchMutationOptions(options);
-
- return useMutation(mutationOptions);
+ return useMutation(
+ getUpdateThreadApiV1AssistantThreadsThreadIdPatchMutationOptions(options),
+ );
};
/**
* Persists the user message, creates an execution (state: queued), kicks off the agent loop asynchronously, and returns immediately. Open `GET /executions/{executionId}/events` for the SSE stream.
@@ -825,12 +808,11 @@ export const useCreateMessageApiV1AssistantThreadsThreadIdMessagesPost = <
},
TContext
> => {
- const mutationOptions =
+ return useMutation(
getCreateMessageApiV1AssistantThreadsThreadIdMessagesPostMutationOptions(
options,
- );
-
- return useMutation(mutationOptions);
+ ),
+ );
};
/**
* Clean-slate regeneration. Starts a fresh execution with conversation history up to (excluding) the original assistant response.
@@ -961,12 +943,11 @@ export const useRegenerateMessageApiV1AssistantMessagesMessageIdRegeneratePost =
},
TContext
> => {
- const mutationOptions =
+ return useMutation(
getRegenerateMessageApiV1AssistantMessagesMessageIdRegeneratePostMutationOptions(
options,
- );
-
- return useMutation(mutationOptions);
+ ),
+ );
};
/**
* Triggers a replay execution that runs the stored tool call with exact params. Returns a new executionId — open SSE for that execution.
@@ -1066,10 +1047,9 @@ export const useApproveApiV1AssistantApprovePost = <
},
TContext
> => {
- const mutationOptions =
- getApproveApiV1AssistantApprovePostMutationOptions(options);
-
- return useMutation(mutationOptions);
+ return useMutation(
+ getApproveApiV1AssistantApprovePostMutationOptions(options),
+ );
};
/**
* Marks the approval as rejected. The execution completes with no tool execution.
@@ -1169,10 +1149,7 @@ export const useRejectApiV1AssistantRejectPost = <
},
TContext
> => {
- const mutationOptions =
- getRejectApiV1AssistantRejectPostMutationOptions(options);
-
- return useMutation(mutationOptions);
+ return useMutation(getRejectApiV1AssistantRejectPostMutationOptions(options));
};
/**
* Provides structured answers to a clarification request. Persists the answers as a user transcript message, emits `user_message` as the first replayable event on the new execution stream, and resumes the agent with the answers as tool results.
@@ -1272,10 +1249,9 @@ export const useClarifyApiV1AssistantClarifyPost = <
},
TContext
> => {
- const mutationOptions =
- getClarifyApiV1AssistantClarifyPostMutationOptions(options);
-
- return useMutation(mutationOptions);
+ return useMutation(
+ getClarifyApiV1AssistantClarifyPostMutationOptions(options),
+ );
};
/**
* Cooperative cancel. The agent loop finishes its current step, emits a truncated message if streaming, and transitions to canceled.
@@ -1375,10 +1351,7 @@ export const useCancelApiV1AssistantCancelPost = <
},
TContext
> => {
- const mutationOptions =
- getCancelApiV1AssistantCancelPostMutationOptions(options);
-
- return useMutation(mutationOptions);
+ return useMutation(getCancelApiV1AssistantCancelPostMutationOptions(options));
};
/**
* Deletes the resource that was created by the assistant.
@@ -1477,9 +1450,7 @@ export const useUndoApiV1AssistantUndoPost = <
},
TContext
> => {
- const mutationOptions = getUndoApiV1AssistantUndoPostMutationOptions(options);
-
- return useMutation(mutationOptions);
+ return useMutation(getUndoApiV1AssistantUndoPostMutationOptions(options));
};
/**
* Rolls back the resource to its pre-change snapshot.
@@ -1579,10 +1550,7 @@ export const useRevertApiV1AssistantRevertPost = <
},
TContext
> => {
- const mutationOptions =
- getRevertApiV1AssistantRevertPostMutationOptions(options);
-
- return useMutation(mutationOptions);
+ return useMutation(getRevertApiV1AssistantRevertPostMutationOptions(options));
};
/**
* Recreates the resource from its pre-delete snapshot.
@@ -1682,10 +1650,9 @@ export const useRestoreApiV1AssistantRestorePost = <
},
TContext
> => {
- const mutationOptions =
- getRestoreApiV1AssistantRestorePostMutationOptions(options);
-
- return useMutation(mutationOptions);
+ return useMutation(
+ getRestoreApiV1AssistantRestorePostMutationOptions(options),
+ );
};
/**
* @summary Submit feedback on an assistant message
@@ -1811,10 +1778,221 @@ export const useSubmitFeedbackApiV1AssistantMessagesMessageIdFeedbackPost = <
},
TContext
> => {
- const mutationOptions =
+ return useMutation(
getSubmitFeedbackApiV1AssistantMessagesMessageIdFeedbackPostMutationOptions(
options,
- );
+ ),
+ );
+};
+/**
+ * @summary Current rate-limit usage for the authenticated user + org
+ */
+export const getUsageApiV1AssistantUsageGet = (
+ headers?: GetUsageApiV1AssistantUsageGetHeaders,
+ signal?: AbortSignal,
+) => {
+ return GeneratedAPIInstance<UsageResponseDTO>({
+ url: `/api/v1/assistant/usage`,
+ method: 'GET',
+ headers,
+ signal,
+ });
+};
+
+export const getGetUsageApiV1AssistantUsageGetQueryKey = () => {
+ return [`/api/v1/assistant/usage`] as const;
+};
+
+export const getGetUsageApiV1AssistantUsageGetQueryOptions = <
+ TData = Awaited<ReturnType<typeof getUsageApiV1AssistantUsageGet>>,
+ TError = ErrorType<ErrorResponseDTO | HTTPValidationErrorDTO>,
+>(
+ headers?: GetUsageApiV1AssistantUsageGetHeaders,
+ options?: {
+ query?: UseQueryOptions<
+ Awaited<ReturnType<typeof getUsageApiV1AssistantUsageGet>>,
+ TError,
+ TData
+ >;
+ },
+) => {
+ const { query: queryOptions } = options ?? {};
+
+ const queryKey =
+ queryOptions?.queryKey ?? getGetUsageApiV1AssistantUsageGetQueryKey();
+
+ const queryFn: QueryFunction<
+ Awaited<ReturnType<typeof getUsageApiV1AssistantUsageGet>>
+ > = ({ signal }) => getUsageApiV1AssistantUsageGet(headers, signal);
+
+ return { queryKey, queryFn, ...queryOptions } as UseQueryOptions<
+ Awaited<ReturnType<typeof getUsageApiV1AssistantUsageGet>>,
+ TError,
+ TData
+ > & { queryKey: QueryKey };
+};
+
+export type GetUsageApiV1AssistantUsageGetQueryResult = NonNullable<
+ Awaited<ReturnType<typeof getUsageApiV1AssistantUsageGet>>
+>;
+export type GetUsageApiV1AssistantUsageGetQueryError = ErrorType<
+ ErrorResponseDTO | HTTPValidationErrorDTO
+>;
+
+/**
+ * @summary Current rate-limit usage for the authenticated user + org
+ */
+
+export function useGetUsageApiV1AssistantUsageGet<
+ TData = Awaited<ReturnType<typeof getUsageApiV1AssistantUsageGet>>,
+ TError = ErrorType<ErrorResponseDTO | HTTPValidationErrorDTO>,
+>(
+ headers?: GetUsageApiV1AssistantUsageGetHeaders,
+ options?: {
+ query?: UseQueryOptions<
+ Awaited<ReturnType<typeof getUsageApiV1AssistantUsageGet>>,
+ TError,
+ TData
+ >;
+ },
+): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
+ const queryOptions = getGetUsageApiV1AssistantUsageGetQueryOptions(
+ headers,
+ options,
+ );
- return useMutation(mutationOptions);
+ const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & {
+ queryKey: QueryKey;
+ };
+
+ return { ...query, queryKey: queryOptions.queryKey };
+}
+
+/**
+ * @summary Current rate-limit usage for the authenticated user + org
+ */
+export const invalidateGetUsageApiV1AssistantUsageGet = async (
+ queryClient: QueryClient,
+ headers?: GetUsageApiV1AssistantUsageGetHeaders,
+ options?: InvalidateOptions,
+): Promise<QueryClient> => {
+ await queryClient.invalidateQueries(
+ { queryKey: getGetUsageApiV1AssistantUsageGetQueryKey() },
+ options,
+ );
+
+ return queryClient;
+};
+
+/**
+ * @summary Contextual empty-state chips
+ */
+export const getChipsApiV1AssistantEmptyStateChipsGet = (
+ params: GetChipsApiV1AssistantEmptyStateChipsGetParams,
+ headers?: GetChipsApiV1AssistantEmptyStateChipsGetHeaders,
+ signal?: AbortSignal,
+) => {
+ return GeneratedAPIInstance<ChipsResponseDTO>({
+ url: `/api/v1/assistant/empty-state/chips`,
+ method: 'GET',
+ headers,
+ params,
+ signal,
+ });
+};
+
+export const getGetChipsApiV1AssistantEmptyStateChipsGetQueryKey = (
+ params?: GetChipsApiV1AssistantEmptyStateChipsGetParams,
+) => {
+ return [
+ `/api/v1/assistant/empty-state/chips`,
+ ...(params ? [params] : []),
+ ] as const;
+};
+
+export const getGetChipsApiV1AssistantEmptyStateChipsGetQueryOptions = <
+ TData = Awaited<ReturnType<typeof getChipsApiV1AssistantEmptyStateChipsGet>>,
+ TError = ErrorType<ErrorResponseDTO | HTTPValidationErrorDTO>,
+>(
+ params: GetChipsApiV1AssistantEmptyStateChipsGetParams,
+ headers?: GetChipsApiV1AssistantEmptyStateChipsGetHeaders,
+ options?: {
+ query?: UseQueryOptions<
+ Awaited<ReturnType<typeof getChipsApiV1AssistantEmptyStateChipsGet>>,
+ TError,
+ TData
+ >;
+ },
+) => {
+ const { query: queryOptions } = options ?? {};
+
+ const queryKey =
+ queryOptions?.queryKey ??
+ getGetChipsApiV1AssistantEmptyStateChipsGetQueryKey(params);
+
+ const queryFn: QueryFunction<
+ Awaited<ReturnType<typeof getChipsApiV1AssistantEmptyStateChipsGet>>
+ > = ({ signal }) =>
+ getChipsApiV1AssistantEmptyStateChipsGet(params, headers, signal);
+
+ return { queryKey, queryFn, ...queryOptions } as UseQueryOptions<
+ Awaited<ReturnType<typeof getChipsApiV1AssistantEmptyStateChipsGet>>,
+ TError,
+ TData
+ > & { queryKey: QueryKey };
+};
+
+export type GetChipsApiV1AssistantEmptyStateChipsGetQueryResult = NonNullable<
+ Awaited<ReturnType<typeof getChipsApiV1AssistantEmptyStateChipsGet>>
+>;
+export type GetChipsApiV1AssistantEmptyStateChipsGetQueryError = ErrorType<
+ ErrorResponseDTO | HTTPValidationErrorDTO
+>;
+
+/**
+ * @summary Contextual empty-state chips
+ */
+
+export function useGetChipsApiV1AssistantEmptyStateChipsGet<
+ TData = Awaited<ReturnType<typeof getChipsApiV1AssistantEmptyStateChipsGet>>,
+ TError = ErrorType<ErrorResponseDTO | HTTPValidationErrorDTO>,
+>(
+ params: GetChipsApiV1AssistantEmptyStateChipsGetParams,
+ headers?: GetChipsApiV1AssistantEmptyStateChipsGetHeaders,
+ options?: {
+ query?: UseQueryOptions<
+ Awaited<ReturnType<typeof getChipsApiV1AssistantEmptyStateChipsGet>>,
+ TError,
+ TData
+ >;
+ },
+): UseQueryResult<TData, TError> & { queryKey: QueryKey } {
+ const queryOptions = getGetChipsApiV1AssistantEmptyStateChipsGetQueryOptions(
+ params,
+ headers,
+ options,
+ );
+
+ const query = useQuery(queryOptions) as UseQueryResult<TData, TError> & {
+ queryKey: QueryKey;
+ };
+
+ return { ...query, queryKey: queryOptions.queryKey };
+}
+
+/**
+ * @summary Contextual empty-state chips
+ */
+export const invalidateGetChipsApiV1AssistantEmptyStateChipsGet = async (
+ queryClient: QueryClient,
+ params: GetChipsApiV1AssistantEmptyStateChipsGetParams,
+ headers?: GetChipsApiV1AssistantEmptyStateChipsGetHeaders,
+ options?: InvalidateOptions,
+): Promise<QueryClient> => {
+ await queryClient.invalidateQueries(
+ { queryKey: getGetChipsApiV1AssistantEmptyStateChipsGetQueryKey(params) },
+ options,
+ );
+
+ return queryClient;
};
diff --git a/frontend/src/constants/reactQueryKeys.ts b/frontend/src/constants/reactQueryKeys.ts
index 4a80cbfa3c..8270e71bd1 100644
--- a/frontend/src/constants/reactQueryKeys.ts
+++ b/frontend/src/constants/reactQueryKeys.ts
@@ -113,4 +113,7 @@ export const REACT_QUERY_KEY = {
// Fields Selector Query Keys
GET_FIELDS_SELECTOR_SUGGESTIONS: 'GET_FIELDS_SELECTOR_SUGGESTIONS',
+
+ // AI Assistant Query Keys
+ AI_ASSISTANT_EMPTY_STATE_CHIPS: 'AI_ASSISTANT_EMPTY_STATE_CHIPS',
} as const;
diff --git a/frontend/src/container/AIAssistant/__tests__/getAutoContexts.test.ts b/frontend/src/container/AIAssistant/__tests__/getAutoContexts.test.ts
index cf55622641..3899c0337a 100644
--- a/frontend/src/container/AIAssistant/__tests__/getAutoContexts.test.ts
+++ b/frontend/src/container/AIAssistant/__tests__/getAutoContexts.test.ts
@@ -63,6 +63,50 @@ describe('getAutoContexts', () => {
]);
});
+ it('resolves alert list tabs on /alerts', () => {
+ expect(getAutoContexts(ROUTES.LIST_ALL_ALERT, '')).toStrictEqual([
+ {
+ source: 'auto',
+ type: 'alert',
+ resourceId: null,
+ metadata: { page: 'alert_list' },
+ },
+ ]);
+
+ expect(
+ getAutoContexts(ROUTES.LIST_ALL_ALERT, '?tab=AlertRules'),
+ ).toStrictEqual([
+ {
+ source: 'auto',
+ type: 'alert',
+ resourceId: null,
+ metadata: { page: 'alert_list' },
+ },
+ ]);
+
+ expect(
+ getAutoContexts(ROUTES.LIST_ALL_ALERT, '?tab=TriggeredAlerts'),
+ ).toStrictEqual([
+ {
+ source: 'auto',
+ type: 'alert',
+ resourceId: null,
+ metadata: { page: 'alerts_triggered' },
+ },
+ ]);
+
+ expect(
+ getAutoContexts(ROUTES.LIST_ALL_ALERT, '?tab=Configuration'),
+ ).toStrictEqual([
+ {
+ source: 'auto',
+ type: 'alert',
+ resourceId: null,
+ metadata: { page: 'alert_list' },
+ },
+ ]);
+ });
+
it('returns dashboard detail context on dashboard page', () => {
const dashboardId = 'dash-123';
const pathname = ROUTES.DASHBOARD.replace(':dashboardId', dashboardId);
@@ -86,4 +130,21 @@ describe('getAutoContexts', () => {
expect(contexts).toStrictEqual([]);
});
+
+ it('emits no auto-context on /home (no attachable resource)', () => {
+ expect(getAutoContexts(ROUTES.HOME, '')).toStrictEqual([]);
+ });
+
+ it('emits no auto-context on infrastructure monitoring routes', () => {
+ expect(
+ getAutoContexts(ROUTES.INFRASTRUCTURE_MONITORING_BASE, ''),
+ ).toStrictEqual([]);
+
+ expect(
+ getAutoContexts(
+ ROUTES.INFRASTRUCTURE_MONITORING_HOSTS,
+ '?selectedItem=host-1',
+ ),
+ ).toStrictEqual([]);
+ });
});
diff --git a/frontend/src/container/AIAssistant/__tests__/resolvePageType.test.ts b/frontend/src/container/AIAssistant/__tests__/resolvePageType.test.ts
new file mode 100644
index 0000000000..e4f90e2cdb
--- /dev/null
+++ b/frontend/src/container/AIAssistant/__tests__/resolvePageType.test.ts
@@ -0,0 +1,87 @@
+import { PageTypeDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
+import { QueryParams } from 'constants/query';
+import ROUTES from 'constants/routes';
+
+import { resolvePageType } from '../resolvePageType';
+
+describe('resolvePageType', () => {
+ it('returns other for the standalone assistant surface', () => {
+ expect(
+ resolvePageType('/services', '', { isStandaloneAssistant: true }),
+ ).toBe(PageTypeDTO.other);
+ });
+
+ it('returns dashboard_detail on a dashboard page', () => {
+ const pathname = ROUTES.DASHBOARD.replace(':dashboardId', 'dash-123');
+
+ expect(resolvePageType(pathname, '')).toBe(PageTypeDTO.dashboard_detail);
+ });
+
+ it('returns alerts_triggered on alert history without ruleId', () => {
+ expect(resolvePageType(ROUTES.ALERT_HISTORY, '')).toBe(
+ PageTypeDTO.alerts_triggered,
+ );
+ });
+
+ it('resolves alert list tabs on /alerts', () => {
+ expect(resolvePageType(ROUTES.LIST_ALL_ALERT, '')).toBe(
+ PageTypeDTO.alert_list,
+ );
+ expect(resolvePageType(ROUTES.LIST_ALL_ALERT, '?tab=AlertRules')).toBe(
+ PageTypeDTO.alert_list,
+ );
+ expect(resolvePageType(ROUTES.LIST_ALL_ALERT, '?tab=TriggeredAlerts')).toBe(
+ PageTypeDTO.alerts_triggered,
+ );
+ expect(resolvePageType(ROUTES.LIST_ALL_ALERT, '?tab=Configuration')).toBe(
+ PageTypeDTO.alert_list,
+ );
+ });
+
+ it('returns log_detail when logs explorer has activeLogId', () => {
+ const search = `?${QueryParams.activeLogId}=log-1`;
+
+ expect(resolvePageType(ROUTES.LOGS_EXPLORER, search)).toBe(
+ PageTypeDTO.log_detail,
+ );
+ });
+
+ it('returns other for unmapped routes', () => {
+ expect(resolvePageType(ROUTES.ALERT_OVERVIEW, '')).toBe(PageTypeDTO.other);
+ });
+
+ it('returns other for the app root route (no contextual mapping)', () => {
+ expect(resolvePageType(ROUTES.HOME_PAGE, '')).toBe(PageTypeDTO.other);
+ });
+
+ it('returns homepage on /home', () => {
+ expect(resolvePageType(ROUTES.HOME, '')).toBe(PageTypeDTO.homepage);
+ });
+
+ it('returns infra_entity_detail on infrastructure monitoring routes', () => {
+ expect(resolvePageType(ROUTES.INFRASTRUCTURE_MONITORING_BASE, '')).toBe(
+ PageTypeDTO.infra_entity_detail,
+ );
+ expect(resolvePageType(ROUTES.INFRASTRUCTURE_MONITORING_HOSTS, '')).toBe(
+ PageTypeDTO.infra_entity_detail,
+ );
+ expect(resolvePageType(ROUTES.INFRASTRUCTURE_MONITORING_KUBERNETES, '')).toBe(
+ PageTypeDTO.infra_entity_detail,
+ );
+ });
+
+ it('returns metrics_explorer on all metrics explorer routes', () => {
+ expect(resolvePageType(ROUTES.METRICS_EXPLORER_BASE, '')).toBe(
+ PageTypeDTO.metrics_explorer,
+ );
+ expect(resolvePageType(ROUTES.METRICS_EXPLORER, '')).toBe(
+ PageTypeDTO.metrics_explorer,
+ );
+ expect(resolvePageType(ROUTES.METRICS_EXPLORER_EXPLORER, '')).toBe(
+ PageTypeDTO.metrics_explorer,
+ );
+ expect(resolvePageType(ROUTES.METRICS_EXPLORER_VIEWS, '')).toBe(
+ PageTypeDTO.metrics_explorer,
+ );
+ });
+});
diff --git a/frontend/src/container/AIAssistant/components/VirtualizedMessages/VirtualizedMessages.module.scss b/frontend/src/container/AIAssistant/components/VirtualizedMessages/VirtualizedMessages.module.scss
index 2a97a97eb2..83623c2088 100644
--- a/frontend/src/container/AIAssistant/components/VirtualizedMessages/VirtualizedMessages.module.scss
+++ b/frontend/src/container/AIAssistant/components/VirtualizedMessages/VirtualizedMessages.module.scss
@@ -45,7 +45,7 @@
line-height: 1.45;
}
-.emptySuggestions {
+.suggestions {
display: flex;
flex-direction: column;
gap: 6px;
@@ -53,11 +53,8 @@
max-width: 360px;
}
-.emptyChip {
- display: flex;
- align-items: center;
- justify-content: flex-start !important;
- gap: 8px;
+.suggestion {
+ width: 100%;
padding: 10px 14px;
border: 1px solid var(--l2-border);
border-radius: var(--radius-2);
@@ -66,21 +63,16 @@
font-size: 12.5px;
text-align: left;
cursor: pointer;
- transition: all 0.15s ease;
+ transition:
+ background 0.15s ease,
+ border-color 0.15s ease,
+ color 0.15s ease;
line-height: 1.35;
+ overflow-wrap: anywhere;
&:hover {
background: var(--l2-background);
border-color: var(--l3-border);
color: var(--l1-foreground);
}
-
- svg {
- flex-shrink: 0;
- color: var(--l3-foreground);
- }
-
- &:hover svg {
- color: var(--accent-primary);
- }
}
diff --git a/frontend/src/container/AIAssistant/components/VirtualizedMessages/VirtualizedMessages.tsx b/frontend/src/container/AIAssistant/components/VirtualizedMessages/VirtualizedMessages.tsx
index 70402f73d8..b99d9a81f5 100644
--- a/frontend/src/container/AIAssistant/components/VirtualizedMessages/VirtualizedMessages.tsx
+++ b/frontend/src/container/AIAssistant/components/VirtualizedMessages/VirtualizedMessages.tsx
@@ -1,13 +1,5 @@
import { useCallback, useEffect, useRef } from 'react';
-import { Button } from '@signozhq/ui/button';
import { Virtuoso, VirtuosoHandle } from 'react-virtuoso';
-import {
- Activity,
- TriangleAlert,
- ChartBar,
- Search,
- Zap,
-} from '@signozhq/icons';
import Noz from 'components/Noz/Noz';
import logEvent from 'api/common/logEvent';
@@ -20,29 +12,7 @@ import MessageBubble from '../MessageBubble';
import StreamingMessage from '../StreamingMessage';
import styles from './VirtualizedMessages.module.scss';
-
-const SUGGESTIONS = [
- {
- icon: TriangleAlert,
- text: 'Show me the top errors in the last hour',
- },
- {
- icon: Activity,
- text: 'What services have the highest latency?',
- },
- {
- icon: ChartBar,
- text: 'Give me an overview of system health',
- },
- {
- icon: Search,
- text: 'Find slow database queries',
- },
- {
- icon: Zap,
- text: 'Which endpoints have the most 5xx errors?',
- },
-];
+import { useEmptyStateChips } from './useEmptyStateChips';
const EMPTY_EVENTS: StreamingEventItem[] = [];
@@ -173,8 +143,10 @@ export default function VirtualizedMessages({
const showStreamingSlot =
isStreaming || Boolean(pendingApproval) || Boolean(pendingClarification);
+ const isEmptyState = messages.length === 0 && !showStreamingSlot;
+ const { chips: emptyStateChips } = useEmptyStateChips(isEmptyState);
- if (messages.length === 0 && !showStreamingSlot) {
+ if (isEmptyState) {
return (
<div className={styles.empty}>
<div className={`${styles.emptyIcon} noz-wave`}>
@@ -184,24 +156,22 @@ export default function VirtualizedMessages({
<p className={styles.emptySubtitle}>
Ask questions about your traces, logs, metrics, and infrastructure.
</p>
- <div className={styles.emptySuggestions}>
- {SUGGESTIONS.map((s) => (
- <Button
- key={s.text}
- variant="outlined"
- color="secondary"
- className={styles.emptyChip}
+ <div className={styles.suggestions}>
+ {emptyStateChips.map((chip) => (
+ <div
+ key={chip.id}
+ className={styles.suggestion}
onClick={(): void => {
void logEvent(AIAssistantEvents.SuggestedPromptClicked, {
- promptId: s.text,
+ promptId: chip.id,
category: SuggestedPromptCategory.EmptyState,
});
- onSendSuggestedPrompt(s.text);
+ onSendSuggestedPrompt(chip.text);
}}
- prefix={<s.icon size={14} />}
+ data-testid={`empty-state-chip-${chip.id}`}
>
- {s.text}
- </Button>
+ {chip.text}
+ </div>
))}
</div>
</div>
diff --git a/frontend/src/container/AIAssistant/components/VirtualizedMessages/emptyStateChipsFallback.ts b/frontend/src/container/AIAssistant/components/VirtualizedMessages/emptyStateChipsFallback.ts
new file mode 100644
index 0000000000..d0bbcf4191
--- /dev/null
+++ b/frontend/src/container/AIAssistant/components/VirtualizedMessages/emptyStateChipsFallback.ts
@@ -0,0 +1,25 @@
+import type { ChipDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
+
+/** Static empty-state chips used when the contextual chips API is unavailable. */
+export const EMPTY_STATE_CHIPS_FALLBACK: ChipDTO[] = [
+ {
+ id: 'top_errors_last_hour',
+ text: 'Show me the top errors in the last hour',
+ },
+ {
+ id: 'highest_latency_services',
+ text: 'What services have the highest latency?',
+ },
+ {
+ id: 'system_health_overview',
+ text: 'Give me an overview of system health',
+ },
+ {
+ id: 'slow_database_queries',
+ text: 'Find slow database queries',
+ },
+ {
+ id: 'endpoints_5xx_errors',
+ text: 'Which endpoints have the most 5xx errors?',
+ },
+];
diff --git a/frontend/src/container/AIAssistant/components/VirtualizedMessages/useEmptyStateChips.ts b/frontend/src/container/AIAssistant/components/VirtualizedMessages/useEmptyStateChips.ts
new file mode 100644
index 0000000000..cc72a462fc
--- /dev/null
+++ b/frontend/src/container/AIAssistant/components/VirtualizedMessages/useEmptyStateChips.ts
@@ -0,0 +1,33 @@
+import { useMemo } from 'react';
+import { useQuery } from 'react-query';
+
+import { getEmptyStateChips } from 'api/ai-assistant/chat';
+import type { ChipDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
+import { REACT_QUERY_KEY } from 'constants/reactQueryKeys';
+
+import { useResolvePageType } from 'hooks/aiAssistant/useResolvePageType';
+
+import { EMPTY_STATE_CHIPS_FALLBACK } from './emptyStateChipsFallback';
+
+interface UseEmptyStateChipsResult {
+ chips: ChipDTO[];
+}
+
+export function useEmptyStateChips(enabled: boolean): UseEmptyStateChipsResult {
+ const pageType = useResolvePageType();
+
+ const { data, isError } = useQuery(
+ [REACT_QUERY_KEY.AI_ASSISTANT_EMPTY_STATE_CHIPS, pageType],
+ ({ signal }) => getEmptyStateChips(pageType, signal),
+ { enabled },
+ );
+
+ const chips = useMemo(() => {
+ if (isError) {
+ return EMPTY_STATE_CHIPS_FALLBACK;
+ }
+ return data ?? [];
+ }, [data, isError]);
+
+ return { chips };
+}
diff --git a/frontend/src/container/AIAssistant/getAutoContexts.ts b/frontend/src/container/AIAssistant/getAutoContexts.ts
index 71d103e9a0..3fc86eebce 100644
--- a/frontend/src/container/AIAssistant/getAutoContexts.ts
+++ b/frontend/src/container/AIAssistant/getAutoContexts.ts
@@ -1,6 +1,7 @@
import type { MessageContext } from 'api/ai-assistant/chat';
import { QueryParams } from 'constants/query';
import ROUTES from 'constants/routes';
+import { AlertListTabs } from 'pages/AlertList/types';
import { matchPath } from 'react-router-dom';
/**
@@ -164,13 +165,18 @@ export function getAutoContexts(
];
}
+ // Alerts index — `/alerts` with tab query param (defaults to Alert Rules).
if (matchPath(pathname, { path: ROUTES.LIST_ALL_ALERT, exact: true })) {
+ const page = resolveAlertsIndexPage(params.get(QueryParams.tab));
return [
{
source: 'auto',
type: 'alert',
resourceId: null,
- metadata: { page: 'alert_list' },
+ metadata: {
+ page,
+ ...(page === 'alerts_triggered' ? sharedMetadata : {}),
+ },
},
];
}
@@ -276,8 +282,9 @@ export function getAutoContexts(
// ── Metrics ───────────────────────────────────────────────────────────────
+ // Metrics explorer — `/metrics-explorer` and sub-routes (summary, explorer, views).
if (
- matchPath(pathname, { path: ROUTES.METRICS_EXPLORER_EXPLORER, exact: false })
+ matchPath(pathname, { path: ROUTES.METRICS_EXPLORER_BASE, exact: false })
) {
return [
{
@@ -292,9 +299,25 @@ export function getAutoContexts(
];
}
+ // NOTE: Homepage (`/home`) and infrastructure monitoring
+ // (`/infrastructure-monitoring/*`) intentionally emit no auto-context here.
+ // They have no resource that maps to `MessageContextDTOType`, so attaching
+ // a chip would misrepresent the page (e.g. a bogus "metrics_explorer"
+ // context). Their `page_type` for empty-state chips is resolved directly
+ // from the route in `resolvePageType`.
+
return [];
}
+type AlertsIndexPage = 'alert_list' | 'alerts_triggered';
+
+function resolveAlertsIndexPage(tab: string | null): AlertsIndexPage {
+ if (tab === AlertListTabs.TRIGGERED_ALERTS) {
+ return 'alerts_triggered';
+ }
+ return 'alert_list';
+}
+
/**
* Pulls metadata fields that any page may carry in its query string —
* `timeRange`, `query`, saved-view selectors, dashboard variables. Each
diff --git a/frontend/src/container/AIAssistant/resolvePageType.ts b/frontend/src/container/AIAssistant/resolvePageType.ts
new file mode 100644
index 0000000000..2f71262195
--- /dev/null
+++ b/frontend/src/container/AIAssistant/resolvePageType.ts
@@ -0,0 +1,74 @@
+import { PageTypeDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
+import { QueryParams } from 'constants/query';
+import ROUTES from 'constants/routes';
+import { matchPath } from 'react-router-dom';
+
+import { getAutoContexts } from './getAutoContexts';
+
+const PAGE_METADATA_TO_DTO: Record<string, PageTypeDTO> = {
+ dashboard_detail: PageTypeDTO.dashboard_detail,
+ dashboard_list: PageTypeDTO.dashboard_list,
+ panel_edit: PageTypeDTO.panel_edit,
+ panel_fullscreen: PageTypeDTO.panel_fullscreen,
+ logs_explorer: PageTypeDTO.logs_explorer,
+ trace_detail: PageTypeDTO.trace_detail,
+ traces_explorer: PageTypeDTO.traces_explorer,
+ metrics_explorer: PageTypeDTO.metrics_explorer,
+ service_detail: PageTypeDTO.service_detail,
+ services_list: PageTypeDTO.services_list,
+ alert_edit: PageTypeDTO.alert_edit,
+ alert_list: PageTypeDTO.alert_list,
+ alert_new: PageTypeDTO.alert_new,
+ alerts_triggered: PageTypeDTO.alerts_triggered,
+};
+
+interface ResolvePageTypeOptions {
+ /** Standalone `/ai-assistant` surface — no underlying observability page. */
+ isStandaloneAssistant?: boolean;
+}
+
+/**
+ * Maps the current URL (and assistant surface) to the backend `page_type`
+ * enum used by contextual empty-state chips.
+ */
+export function resolvePageType(
+ pathname: string,
+ search: string,
+ options?: ResolvePageTypeOptions,
+): PageTypeDTO {
+ if (options?.isStandaloneAssistant) {
+ return PageTypeDTO.other;
+ }
+
+ // Pseudo-pages with no attachable resource: resolved straight from the
+ // route. They deliberately emit no auto-context chip (see `getAutoContexts`),
+ // so they can't be derived from `metadata.page` like the pages below.
+ if (matchPath(pathname, { path: ROUTES.HOME, exact: true })) {
+ return PageTypeDTO.homepage;
+ }
+ if (
+ matchPath(pathname, {
+ path: ROUTES.INFRASTRUCTURE_MONITORING_BASE,
+ exact: false,
+ })
+ ) {
+ return PageTypeDTO.infra_entity_detail;
+ }
+
+ const contexts = getAutoContexts(pathname, search);
+ const page = contexts[0]?.metadata?.page;
+ if (typeof page === 'string') {
+ if (page === 'logs_explorer') {
+ const activeLogId = new URLSearchParams(search).get(QueryParams.activeLogId);
+ if (activeLogId) {
+ return PageTypeDTO.log_detail;
+ }
+ }
+ const mapped = PAGE_METADATA_TO_DTO[page];
+ if (mapped) {
+ return mapped;
+ }
+ }
+
+ return PageTypeDTO.other;
+}
diff --git a/frontend/src/hooks/aiAssistant/__tests__/useResolvePageType.test.ts b/frontend/src/hooks/aiAssistant/__tests__/useResolvePageType.test.ts
new file mode 100644
index 0000000000..ded08705c6
--- /dev/null
+++ b/frontend/src/hooks/aiAssistant/__tests__/useResolvePageType.test.ts
@@ -0,0 +1,48 @@
+import { renderHook } from '@testing-library/react';
+import { PageTypeDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
+import type { AIAssistantVariant } from 'container/AIAssistant/VariantContext';
+import ROUTES from 'constants/routes';
+
+import { useResolvePageType } from '../useResolvePageType';
+
+const mockUseLocation = jest.fn();
+const mockUseVariant = jest.fn();
+
+jest.mock('react-router-dom', () => ({
+ ...jest.requireActual('react-router-dom'),
+ useLocation: (): unknown => mockUseLocation(),
+}));
+
+jest.mock('container/AIAssistant/VariantContext', () => ({
+ useVariant: (): unknown => mockUseVariant(),
+}));
+
+function setup(
+ pathname: string,
+ search: string,
+ variant: AIAssistantVariant,
+): PageTypeDTO {
+ mockUseLocation.mockReturnValue({ pathname, search });
+ mockUseVariant.mockReturnValue(variant);
+
+ return renderHook(() => useResolvePageType()).result.current;
+}
+
+describe('useResolvePageType', () => {
+ afterEach(() => {
+ jest.clearAllMocks();
+ });
+
+ it('returns other for the standalone "page" assistant surface', () => {
+ const pathname = ROUTES.DASHBOARD.replace(':dashboardId', 'dash-123');
+
+ expect(setup(pathname, '', 'page')).toBe(PageTypeDTO.other);
+ });
+
+ it('resolves the underlying page type for embedded variants', () => {
+ const pathname = ROUTES.DASHBOARD.replace(':dashboardId', 'dash-123');
+
+ expect(setup(pathname, '', 'panel')).toBe(PageTypeDTO.dashboard_detail);
+ expect(setup(pathname, '', 'modal')).toBe(PageTypeDTO.dashboard_detail);
+ });
+});
diff --git a/frontend/src/hooks/aiAssistant/useResolvePageType.ts b/frontend/src/hooks/aiAssistant/useResolvePageType.ts
new file mode 100644
index 0000000000..3fb3db6637
--- /dev/null
+++ b/frontend/src/hooks/aiAssistant/useResolvePageType.ts
@@ -0,0 +1,23 @@
+import { useMemo } from 'react';
+import { useLocation } from 'react-router-dom';
+
+import { PageTypeDTO } from 'api/ai-assistant/sigNozAIAssistantAPI.schemas';
+import { resolvePageType } from 'container/AIAssistant/resolvePageType';
+import { useVariant } from 'container/AIAssistant/VariantContext';
+
+/**
+ * React hook wrapper around `resolvePageType` that derives the current
+ * `page_type` from the active location and assistant variant.
+ */
+export function useResolvePageType(): PageTypeDTO {
+ const location = useLocation();
+ const variant = useVariant();
+
+ return useMemo(
+ () =>
+ resolvePageType(location.pathname, location.search, {
+ isStandaloneAssistant: variant === 'page',
+ }),
+ [location.pathname, location.search, variant],
+ );
+}
diff --git a/frontend/src/utils/signozInstanceUrl.test.ts b/frontend/src/utils/signozInstanceUrl.test.ts
new file mode 100644
index 0000000000..0fbdcfa466
--- /dev/null
+++ b/frontend/src/utils/signozInstanceUrl.test.ts
@@ -0,0 +1,72 @@
+import getLocalStorageApi from 'api/browser/localstorage/get';
+import { ENVIRONMENT } from 'constants/env';
+import { LOCALSTORAGE } from 'constants/localStorage';
+
+import { getSigNozInstanceUrl } from './signozInstanceUrl';
+
+jest.mock('api/browser/localstorage/get');
+jest.mock('constants/env', () => ({
+ ENVIRONMENT: { baseURL: '' },
+}));
+
+const mockedGet = getLocalStorageApi as jest.MockedFunction<
+ typeof getLocalStorageApi
+>;
+
+function setOrigin(origin: string): void {
+ Object.defineProperty(window, 'location', {
+ value: { origin },
+ writable: true,
+ configurable: true,
+ });
+}
+
+describe('getSigNozInstanceUrl', () => {
+ beforeEach(() => {
+ mockedGet.mockReset();
+ ENVIRONMENT.baseURL = '';
+ setOrigin('http://localhost');
+ });
+
+ it('returns the localStorage override when present', () => {
+ mockedGet.mockReturnValue('https://override.example.com');
+ ENVIRONMENT.baseURL = 'https://build.example.com';
+ setOrigin('https://browser.example.com');
+
+ expect(getSigNozInstanceUrl()).toBe('https://override.example.com');
+ expect(mockedGet).toHaveBeenCalledWith(
+ LOCALSTORAGE.ACTIVE_SIGNOZ_INSTANCE_URL,
+ );
+ });
+
+ it('ignores a blank/whitespace-only override and falls through', () => {
+ mockedGet.mockReturnValue(' ');
+ ENVIRONMENT.baseURL = 'https://build.example.com';
+
+ expect(getSigNozInstanceUrl()).toBe('https://build.example.com');
+ });
+
+ it('returns the build-time baseURL when no override exists (cloud)', () => {
+ mockedGet.mockReturnValue(null);
+ ENVIRONMENT.baseURL = 'https://build.example.com';
+ setOrigin('https://browser.example.com');
+
+ expect(getSigNozInstanceUrl()).toBe('https://build.example.com');
+ });
+
+ it('falls back to window.location.origin when baseURL is empty (self-hosted)', () => {
+ mockedGet.mockReturnValue(null);
+ ENVIRONMENT.baseURL = '';
+ setOrigin('https://self-hosted.example.com');
+
+ expect(getSigNozInstanceUrl()).toBe('https://self-hosted.example.com');
+ });
+
+ it('returns an empty string when nothing is resolvable', () => {
+ mockedGet.mockReturnValue(null);
+ ENVIRONMENT.baseURL = '';
+ setOrigin('');
+
+ expect(getSigNozInstanceUrl()).toBe('');
+ });
+});
diff --git a/frontend/src/utils/signozInstanceUrl.ts b/frontend/src/utils/signozInstanceUrl.ts
index b45111714f..b2af62341a 100644
--- a/frontend/src/utils/signozInstanceUrl.ts
+++ b/frontend/src/utils/signozInstanceUrl.ts
@@ -2,7 +2,37 @@ import getLocalStorageApi from 'api/browser/localstorage/get';
import setLocalStorageApi from 'api/browser/localstorage/set';
import { LOCALSTORAGE } from 'constants/localStorage';
import { ENVIRONMENT } from 'constants/env';
+import { getBaseUrl } from 'utils/basePath';
+/**
+ * Resolves the SigNoz instance URL sent to the AI Assistant backend via the
+ * `X-SigNoz-URL` header. Resolution order:
+ *
+ * 1. `ACTIVE_SIGNOZ_INSTANCE_URL` localStorage override (cloud instance switcher).
+ * 2. `ENVIRONMENT.baseURL` — the build-time absolute endpoint
+ * (`VITE_FRONTEND_API_ENDPOINT`). Non-empty on SigNoz Cloud builds.
+ * 3. `getBaseUrl()` (origin + base path) — fallback for self-hosted builds.
+ *
+ * Decision (self-hosted fallback to the browser's current URL):
+ * Self-hosted builds ship with `VITE_FRONTEND_API_ENDPOINT` unset because the
+ * frontend talks to its backend over relative paths, so `ENVIRONMENT.baseURL`
+ * is an empty string. That previously caused `X-SigNoz-URL` to be sent empty,
+ * which the AI backend rejects (`missing_signoz_url` / `invalid_signoz_url`)
+ * rather than treating as "omitted". We deliberately fall back to the URL the
+ * user is actually accessing the instance from so the header is always
+ * populated. We use `getBaseUrl()` rather than raw `window.location.origin`
+ * because a self-hosted instance may be served under a base path (e.g.
+ * `https://host/signoz`); the backend needs that full base to reach the API.
+ *
+ * Known tradeoff: this reflects the *browser's* view of the instance. For
+ * deployments where the instance is not reachable from the cloud AI backend at
+ * that URL (air-gapped, internal-only DNS, private IPs, behind a reverse proxy
+ * on a different external host), it will be unreachable and the AI backend may
+ * fail to query the instance. Those deployments must set an explicit,
+ * externally reachable URL via the localStorage override. A first-class admin
+ * config for the public instance URL is the proper long-term fix; this fallback
+ * is the pragmatic default until that exists.
+ */
export function getSigNozInstanceUrl(): string {
const fromStorage = getLocalStorageApi(
LOCALSTORAGE.ACTIVE_SIGNOZ_INSTANCE_URL,
@@ -12,7 +42,11 @@ export function getSigNozInstanceUrl(): string {
return fromStorage;
}
- return ENVIRONMENT.baseURL;
+ if (ENVIRONMENT.baseURL) {
+ return ENVIRONMENT.baseURL;
+ }
+
+ return getBaseUrl();
}
export function setSigNozInstanceUrl(url: string | null | undefined): void {