Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export function LeftNavigation({
collapsed={collapsed}
activeItem={activeItem}
onSelect={onNavigationClick}
width={280}
>
<Sidebar.Nav>
<Sidebar.Category>
Expand Down
1 change: 1 addition & 0 deletions console/workspaces/libs/api-client/src/apis/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ export * from './metrics';
export * from './monitors';
export * from './runtime-logs';
export * from './repositories';
export * from './resource-configs';
export * from './llm-providers';
export * from './gateways';
11 changes: 9 additions & 2 deletions console/workspaces/libs/api-client/src/apis/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,22 @@ export async function getAgentMetrics(
if (!agentName) {
throw new Error("agentName is required");
}

const bodyClone = cloneDeep(body);
const now = new Date();
if (!bodyClone?.endTime) {
bodyClone.endTime = now.toISOString();
}
if (!bodyClone?.startTime) {
bodyClone.startTime = new Date(now.getTime() - 1000 * 10).toISOString();
}
const token = getToken ? await getToken() : undefined;
const res = await httpPOST(
`${SERVICE_BASE}/orgs/${encodeURIComponent(
orgName
)}/projects/${encodeURIComponent(projName)}/agents/${encodeURIComponent(
agentName
)}/metrics`,
cloneDeep(body),
bodyClone,
{ token }
);
if (!res.ok) throw await res.json();
Expand Down
104 changes: 104 additions & 0 deletions console/workspaces/libs/api-client/src/apis/resource-configs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/**
* Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { httpGET, httpPUT, SERVICE_BASE } from "../utils";
import type {
AgentResourceConfigsResponse,
GetAgentResourceConfigsPathParams,
GetAgentResourceConfigsQuery,
UpdateAgentResourceConfigsPathParams,
UpdateAgentResourceConfigsQuery,
UpdateAgentResourceConfigsRequest,
} from "@agent-management-platform/types";

function buildBaseUrl(params: GetAgentResourceConfigsPathParams): string {
const orgName = params.orgName ?? "default";
const projName = params.projName ?? "default";
const agentName = params.agentName;
if (!agentName) {
throw new Error("agentName is required");
}
return `${SERVICE_BASE}/orgs/${encodeURIComponent(orgName)}/projects/${encodeURIComponent(projName)}/agents/${encodeURIComponent(agentName)}/resource-configs`;
}

export async function getAgentResourceConfigs(
params: GetAgentResourceConfigsPathParams,
query?: GetAgentResourceConfigsQuery,
getToken?: () => Promise<string>
): Promise<AgentResourceConfigsResponse> {
const baseUrl = buildBaseUrl(params);
const token = getToken ? await getToken() : undefined;

const searchParams: Record<string, string> = {};
if (query?.environment !== undefined) {
searchParams.environment = query.environment;
}

const res = await httpGET(baseUrl, {
token,
searchParams: Object.keys(searchParams).length > 0 ? searchParams : undefined,
});
let body: unknown;
try {
body = await res.json();
} catch {
body = await res.text().catch(() => "Failed to parse response");
}
if (!res.ok) {
const err = new Error(typeof body === "string" ? body : "Request failed") as Error & { status?: number; statusText?: string; body?: unknown };
err.status = res.status;
err.statusText = res.statusText;
err.body = body;
throw err;
}
return body as AgentResourceConfigsResponse;
}

export async function updateAgentResourceConfigs(
params: UpdateAgentResourceConfigsPathParams,
body: UpdateAgentResourceConfigsRequest,
query?: UpdateAgentResourceConfigsQuery,
getToken?: () => Promise<string>
): Promise<AgentResourceConfigsResponse> {
const baseUrl = buildBaseUrl(params);
const token = getToken ? await getToken() : undefined;

const searchParams: Record<string, string> = {};
if (query?.environment !== undefined) {
searchParams.environment = query.environment;
}

const res = await httpPUT(baseUrl, body, {
token,
searchParams: Object.keys(searchParams).length > 0 ? searchParams : undefined,
});
let responseBody: unknown;
try {
responseBody = await res.json();
} catch {
responseBody = await res.text().catch(() => "Failed to parse response");
}
if (!res.ok) {
const err = new Error(typeof responseBody === "string" ? responseBody : "Request failed") as Error & { status?: number; statusText?: string; body?: unknown };
err.status = res.status;
err.statusText = res.statusText;
err.body = responseBody;
throw err;
}
return responseBody as AgentResourceConfigsResponse;
}
1 change: 1 addition & 0 deletions console/workspaces/libs/api-client/src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export * from './metrics';
export * from './monitors';
export * from './runtime-logs';
export * from './repositories';
export * from './resource-configs';
export * from './llm-providers';
export * from './gateways';
export * from './guardrails';
8 changes: 4 additions & 4 deletions console/workspaces/libs/api-client/src/hooks/metrics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ import {
MetricsFilterRequest,
MetricsResponse,
} from "@agent-management-platform/types";
import { SLOW_POLL_INTERVAL } from "../utils";

export function useGetAgentMetrics(
params: GetAgentMetricsPathParams,
body: MetricsFilterRequest,
options?: { enabled?: boolean }
options?: { enabled?: boolean, enableAutoRefresh?: boolean }
) {
const { getToken } = useAuthHooks();
return useApiQuery<MetricsResponse>({
queryKey: ["agent-metrics", params, body],
queryFn: () => getAgentMetrics(params, body, getToken),
refetchInterval: options?.enableAutoRefresh ? SLOW_POLL_INTERVAL : undefined,
enabled:
(options?.enabled ?? true) &&
!!params.agentName &&
!!body.environmentName &&
!!body.startTime &&
!!body.endTime,
!!body.environmentName
});
}
69 changes: 69 additions & 0 deletions console/workspaces/libs/api-client/src/hooks/resource-configs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/**
* Copyright (c) 2026, WSO2 LLC. (https://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { useQueryClient } from "@tanstack/react-query";
import { useAuthHooks } from "@agent-management-platform/auth";
import { useApiMutation, useApiQuery } from "./react-query-notifications";
import {
getAgentResourceConfigs,
updateAgentResourceConfigs,
} from "../apis/resource-configs";
import type {
AgentResourceConfigsResponse,
GetAgentResourceConfigsPathParams,
GetAgentResourceConfigsQuery,
UpdateAgentResourceConfigsPathParams,
UpdateAgentResourceConfigsQuery,
UpdateAgentResourceConfigsRequest,
} from "@agent-management-platform/types";

const QUERY_KEY = "resource-configs";

export function useGetAgentResourceConfigs(
params: GetAgentResourceConfigsPathParams,
query?: GetAgentResourceConfigsQuery
) {
const { getToken } = useAuthHooks();
return useApiQuery<AgentResourceConfigsResponse>({
queryKey: [QUERY_KEY, params, query],
queryFn: () => getAgentResourceConfigs(params, query, getToken),
enabled:
!!params.orgName && !!params.projName && !!params.agentName,
});
}

export function useUpdateAgentResourceConfigs() {
const { getToken } = useAuthHooks();
const queryClient = useQueryClient();
return useApiMutation<
AgentResourceConfigsResponse,
unknown,
{
params: UpdateAgentResourceConfigsPathParams;
body: UpdateAgentResourceConfigsRequest;
query?: UpdateAgentResourceConfigsQuery;
}
>({
action: { verb: "update", target: "agent resource configs" },
mutationFn: ({ params, body, query }) =>
updateAgentResourceConfigs(params, body, query, getToken),
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: [QUERY_KEY] });
},
});
}
1 change: 1 addition & 0 deletions console/workspaces/libs/api-client/src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export function encodeRequired(value: string | undefined, label: string): string
}
export const OBS_SERVICE_BASE = '/api';
export const POLL_INTERVAL = 5000;
export const SLOW_POLL_INTERVAL = 15000;

const DEFAULT_TIMEOUT = 1000;

Expand Down
Loading
Loading