Skip to content

Commit 8faaf56

Browse files
authored
fix(ui): agent card proxy urls (#1139)
Signed-off-by: Petr Bulánek <[email protected]>
1 parent f98b82a commit 8faaf56

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

apps/beeai-ui/src/app/api/[...path]/body-transformers.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
import { getBaseUrl } from '#utils/api/getBaseUrl.ts';
6+
import type { AgentCard } from '@a2a-js/sdk';
77

8-
export async function transformAgentManifestBody(response: Response, apiPath: string[]) {
8+
import { createProxyUrl } from '#utils/api/getProxyUrl.ts';
9+
10+
export async function transformAgentManifestBody(response: Response) {
911
try {
10-
const body = await response.json();
11-
const providerId = apiPath.at(2);
12+
const body: AgentCard = await response.json();
1213

13-
const modifiedBody = { ...body, url: getBaseUrl(`/api/v1/a2a/${providerId}/jsonrpc/`, true) };
14+
const modifiedBody = {
15+
...body,
16+
additionalInterfaces: body.additionalInterfaces?.map((item) => ({
17+
...item,
18+
url: createProxyUrl(item.url),
19+
})),
20+
url: createProxyUrl(body.url),
21+
};
1422

1523
return JSON.stringify(modifiedBody);
1624
} catch (err) {

apps/beeai-ui/src/app/api/[...path]/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ async function handler(request: NextRequest, context: RouteContext) {
4040

4141
let responseBody: ReadableStream<Uint8Array<ArrayBufferLike>> | string | null = res.body;
4242
if (isApiAgentManifestUrl(targetUrl)) {
43-
responseBody = await transformAgentManifestBody(res, path);
43+
responseBody = await transformAgentManifestBody(res);
4444
}
4545

4646
return new Response(responseBody, {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* Copyright 2025 © BeeAI a Series of LF Projects, LLC
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import { BASE_PATH } from '#utils/constants.ts';
7+
8+
export function createProxyUrl(url: string) {
9+
try {
10+
const { origin } = new URL(url);
11+
12+
return BASE_PATH + url.replace(origin, '');
13+
} catch {
14+
return url;
15+
}
16+
}

0 commit comments

Comments
 (0)