Skip to content

Commit f3ec03e

Browse files
authored
Merge pull request #96 from i-dot-ai/bugfix/correct-locai-model-name
bugfix/fix model name
2 parents 6f548d1 + 0eb2b64 commit f3ec03e

File tree

9 files changed

+108
-76
lines changed

9 files changed

+108
-76
lines changed

frontend/src/auth.ts

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { decodeJwt } from 'jose';
55
export async function parseAuthToken(header: string) {
66
if (!header) {
77
console.error('No auth token provided to parse');
8-
return { email: null, roles: [] };
8+
return { email: null };
99
}
1010

1111
// Decode without verification since we're using auth-at-the-edge and can trust all traffic
@@ -14,27 +14,16 @@ export async function parseAuthToken(header: string) {
1414
tokenContent = decodeJwt(header);
1515
} catch(error) {
1616
console.error('Malformed JWT during decoding: ' + header, error);
17-
return { email: null, roles: [] };
17+
return { email: null };
1818
}
1919

2020
const email = tokenContent.email as string | undefined;
2121
if (!email) {
2222
console.error('No email found in token');
23-
return null;
23+
return { email: null };
2424
}
2525

26-
const realmAccess = tokenContent.realm_access as { roles?: string[] } | undefined;
27-
if (!realmAccess) {
28-
console.error('No realm access information found in token');
29-
return { email: null, roles: [] };
30-
}
31-
32-
const roles = realmAccess.roles || [];
33-
// console.debug(`Roles found for user ${email}: ${roles}`);
34-
return {
35-
email,
36-
roles,
37-
};
26+
return { email };
3827
}
3928

4029

frontend/src/layouts/Chat.astro

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ const singleServer = mcpServers.find((server) => server.name.toLowerCase() === s
9292
<model-selector class="[tool-selector+&]:left-21 top-0 md:mt-0 md:absolute">
9393
<label class="sr-only" for="model-selector">Mode</label>
9494
<select class="border-pink border-solid border-1 cursor-pointer inline-block min-h-[36px] mr-5 outline-pink px-2 py-[5px] rounded-sm text-pink w-40 focus-visible:outline-2" id="model-selector" name="model">
95-
<option value="locai-l1" class="p-[4px]">
95+
<option value="locailabs/locai-l1-large-2011" class="p-[4px]">
9696
<svg focusable="false" aria-hidden="true" fill="none" viewBox="0 0 124 124" width="20px" height="20px">
9797
<rect x="0" y="0" width="110" height="110" rx="60" fill="#CCFF00"/>
9898
<rect x="30" y="25" width="10" height="60" fill="#000000"/>
@@ -106,13 +106,13 @@ const singleServer = mcpServers.find((server) => server.name.toLowerCase() === s
106106
<svg focusable="false" aria-hidden="true" width="20px" height="20px" viewBox="0 0 1200 1200"><path fill="#d97757" stroke="none" d="M 233.959793 800.214905 L 468.644287 668.536987 L 472.590637 657.100647 L 468.644287 650.738403 L 457.208069 650.738403 L 417.986633 648.322144 L 283.892639 644.69812 L 167.597321 639.865845 L 54.926208 633.825623 L 26.577238 627.785339 L 3.3e-05 592.751709 L 2.73832 575.27533 L 26.577238 559.248352 L 60.724873 562.228149 L 136.187973 567.382629 L 249.422867 575.194763 L 331.570496 580.026978 L 453.261841 592.671082 L 472.590637 592.671082 L 475.328857 584.859009 L 468.724915 580.026978 L 463.570557 575.194763 L 346.389313 495.785217 L 219.543671 411.865906 L 153.100723 363.543762 L 117.181267 339.060425 L 99.060455 316.107361 L 91.248367 266.01355 L 123.865784 230.093994 L 167.677887 233.073853 L 178.872513 236.053772 L 223.248367 270.201477 L 318.040283 343.570496 L 441.825592 434.738342 L 459.946411 449.798706 L 467.194672 444.64447 L 468.080597 441.020203 L 459.946411 427.409485 L 392.617493 305.718323 L 320.778564 181.932983 L 288.80542 130.630859 L 280.348999 99.865845 C 277.369171 87.221436 275.194641 76.590698 275.194641 63.624268 L 312.322174 13.20813 L 332.8591 6.604126 L 382.389313 13.20813 L 403.248352 31.328979 L 434.013519 101.71814 L 483.865753 212.537048 L 561.181274 363.221497 L 583.812134 407.919434 L 595.892639 449.315491 L 600.40271 461.959839 L 608.214783 461.959839 L 608.214783 454.711609 L 614.577271 369.825623 L 626.335632 265.61084 L 637.771851 131.516846 L 641.718201 93.745117 L 660.402832 48.483276 L 697.530334 24.000122 L 726.52356 37.852417 L 750.362549 72 L 747.060486 94.067139 L 732.886047 186.201416 L 705.100708 330.52356 L 686.979919 427.167847 L 697.530334 427.167847 L 709.61084 415.087341 L 758.496704 350.174561 L 840.644348 247.490051 L 876.885925 206.738342 L 919.167847 161.71814 L 946.308838 140.29541 L 997.61084 140.29541 L 1035.38269 196.429626 L 1018.469849 254.416199 L 965.637634 321.422852 L 921.825562 378.201538 L 859.006714 462.765259 L 819.785278 530.41626 L 823.409424 535.812073 L 832.75177 534.92627 L 974.657776 504.724915 L 1051.328979 490.872559 L 1142.818848 475.167786 L 1184.214844 494.496582 L 1188.724854 514.147644 L 1172.456421 554.335693 L 1074.604126 578.496765 L 959.838989 601.449829 L 788.939636 641.879272 L 786.845764 643.409485 L 789.261841 646.389343 L 866.255127 653.637634 L 899.194702 655.409424 L 979.812134 655.409424 L 1129.932861 666.604187 L 1169.154419 692.537109 L 1192.671265 724.268677 L 1188.724854 748.429688 L 1128.322144 779.194641 L 1046.818848 759.865845 L 856.590759 714.604126 L 791.355774 698.335754 L 782.335693 698.335754 L 782.335693 703.731567 L 836.69812 756.885986 L 936.322205 846.845581 L 1061.073975 962.81897 L 1067.436279 991.490112 L 1051.409424 1014.120911 L 1034.496704 1011.704712 L 924.885986 929.234924 L 882.604126 892.107544 L 786.845764 811.48999 L 780.483276 811.48999 L 780.483276 819.946289 L 802.550415 852.241699 L 919.087341 1027.409424 L 925.127625 1081.127686 L 916.671204 1098.604126 L 886.469849 1109.154419 L 853.288696 1103.114136 L 785.073914 1007.355835 L 714.684631 899.516785 L 657.906067 802.872498 L 650.979858 806.81897 L 617.476624 1167.704834 L 601.771851 1186.147705 L 565.530212 1200 L 535.328857 1177.046997 L 519.302124 1139.919556 L 535.328857 1066.550537 L 554.657776 970.792053 L 570.362488 894.68457 L 584.536926 800.134277 L 592.993347 768.724976 L 592.429626 766.630859 L 585.503479 767.516968 L 514.22821 865.369263 L 405.825531 1011.865906 L 320.053711 1103.677979 L 299.516815 1111.812256 L 263.919525 1093.369263 L 267.221497 1060.429688 L 287.114136 1031.114136 L 405.825531 880.107361 L 477.422913 786.52356 L 523.651062 732.483276 L 523.328918 724.671265 L 520.590698 724.671265 L 205.288605 929.395935 L 149.154434 936.644409 L 124.993355 914.01355 L 127.973183 876.885986 L 139.409409 864.80542 L 234.201385 799.570435 L 233.879227 799.8927 Z"/></svg>
107107
Claude Sonnet 3.7
108108
</option>
109-
<option value="gemini-2.5-flash" class="p-[4px]">
109+
<option value="gemini-2.5-flash-uk" class="p-[4px]">
110110
<svg focusable="false" aria-hidden="true" fill="none" viewBox="0 0 16 16" width="20px" height="20px"><path d="M16 8.016A8.522 8.522 0 008.016 16h-.032A8.521 8.521 0 000 8.016v-.032A8.521 8.521 0 007.984 0h.032A8.522 8.522 0 0016 7.984v.032z" fill="url(#prefix__paint0_radial_980_20147)"/><defs><radialGradient id="prefix__paint0_radial_980_20147" cx="0" cy="0" r="1" gradientUnits="userSpaceOnUse" gradientTransform="matrix(16.1326 5.4553 -43.70045 129.2322 1.588 6.503)"><stop offset=".067" stop-color="#9168C0"/><stop offset=".343" stop-color="#5684D1"/><stop offset=".672" stop-color="#1BA1E3"/></radialGradient></defs></svg>
111111
Gemini Flash 2.5
112112
</option>
113-
<option value="o4-mini" class="p-[4px]">
113+
<option value="gpt-4.1-nano" class="p-[4px]">
114114
<svg focusable="false" aria-hidden="true" fill="#000000" width="20px" height="20px" viewBox="0 0 24 24" role="img"><path d="M22.2819 9.8211a5.9847 5.9847 0 0 0-.5157-4.9108 6.0462 6.0462 0 0 0-6.5098-2.9A6.0651 6.0651 0 0 0 4.9807 4.1818a5.9847 5.9847 0 0 0-3.9977 2.9 6.0462 6.0462 0 0 0 .7427 7.0966 5.98 5.98 0 0 0 .511 4.9107 6.051 6.051 0 0 0 6.5146 2.9001A5.9847 5.9847 0 0 0 13.2599 24a6.0557 6.0557 0 0 0 5.7718-4.2058 5.9894 5.9894 0 0 0 3.9977-2.9001 6.0557 6.0557 0 0 0-.7475-7.0729zm-9.022 12.6081a4.4755 4.4755 0 0 1-2.8764-1.0408l.1419-.0804 4.7783-2.7582a.7948.7948 0 0 0 .3927-.6813v-6.7369l2.02 1.1686a.071.071 0 0 1 .038.052v5.5826a4.504 4.504 0 0 1-4.4945 4.4944zm-9.6607-4.1254a4.4708 4.4708 0 0 1-.5346-3.0137l.142.0852 4.783 2.7582a.7712.7712 0 0 0 .7806 0l5.8428-3.3685v2.3324a.0804.0804 0 0 1-.0332.0615L9.74 19.9502a4.4992 4.4992 0 0 1-6.1408-1.6464zM2.3408 7.8956a4.485 4.485 0 0 1 2.3655-1.9728V11.6a.7664.7664 0 0 0 .3879.6765l5.8144 3.3543-2.0201 1.1685a.0757.0757 0 0 1-.071 0l-4.8303-2.7865A4.504 4.504 0 0 1 2.3408 7.872zm16.5963 3.8558L13.1038 8.364 15.1192 7.2a.0757.0757 0 0 1 .071 0l4.8303 2.7913a4.4944 4.4944 0 0 1-.6765 8.1042v-5.6772a.79.79 0 0 0-.407-.667zm2.0107-3.0231l-.142-.0852-4.7735-2.7818a.7759.7759 0 0 0-.7854 0L9.409 9.2297V6.8974a.0662.0662 0 0 1 .0284-.0615l4.8303-2.7866a4.4992 4.4992 0 0 1 6.6802 4.66zM8.3065 12.863l-2.02-1.1638a.0804.0804 0 0 1-.038-.0567V6.0742a4.4992 4.4992 0 0 1 7.3757-3.4537l-.142.0805L8.704 5.459a.7948.7948 0 0 0-.3927.6813zm1.0976-2.3654l2.602-1.4998 2.6069 1.4998v2.9994l-2.5974 1.4997-2.6067-1.4997Z"/></svg>
115-
o4 mini
115+
GPT 4.1 nano
116116
</option>
117117
</select>
118118
</model-selector>

frontend/src/logic/ai3.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,19 @@ export const getLlmResponse = async(messages: Message[], selectedServers: FormDa
3636

3737
let agentModel;
3838
if (process.env['USE_LITE_LLM'] === 'true') {
39-
console.log('Using Lite LLM');
39+
const apiKey = process.env['LITELLM_GOVAI_CLIENT_OPENAI_API_KEY'];
40+
const baseURL = process.env['LLM_GATEWAY_URL'];
41+
console.log('LiteLLM configuration:', {
42+
baseURL,
43+
apiKey: apiKey ? `${apiKey.substring(0, 8)}...${apiKey.substring(apiKey.length - 4)}` : 'missing',
44+
model: selectedModel,
45+
});
4046
agentModel = new ChatOpenAI({
41-
openAIApiKey: process.env['LITELLM_GOVAI_CLIENT_OPENAI_API_KEY'],
47+
apiKey,
4248
configuration: {
43-
baseURL: process.env['LLM_GATEWAY_URL'],
49+
baseURL,
4450
},
45-
modelName: `${selectedModel}`,
51+
model: selectedModel,
4652
callbackManager,
4753
});
4854
} else {

frontend/src/logic/get-servers.ts

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -109,18 +109,17 @@ const getTools = async(mcpServer: MCP_SERVER, authToken?: string) => {
109109

110110
try {
111111
console.log(`${mcpServer.name}: Connected using Streamable HTTP transport`);
112+
const serverMcpTools = await loadMcpTools(mcpServer.url, client) as unknown as Tool[];
113+
const toolList = await client.listTools();
114+
serverMcpTools.forEach((tool, toolIndex) => {
115+
tool.serverName = mcpServer.name;
116+
tool.annotations = toolList.tools[toolIndex].annotations;
117+
});
118+
tools.push(...serverMcpTools);
112119
} catch(error) { /* eslint @typescript-eslint/no-unused-vars: "off" */
113-
console.log(`${mcpServer.name}: Error connecting via StreamableHTTTP`, error);
120+
console.log(`${mcpServer.name}: Error loading tools`, error);
114121
}
115122

116-
const serverMcpTools = await loadMcpTools(mcpServer.url, client) as unknown as Tool[];
117-
const toolList = await client.listTools();
118-
serverMcpTools.forEach((tool, toolIndex) => {
119-
tool.serverName = mcpServer.name;
120-
tool.annotations = toolList.tools[toolIndex].annotations;
121-
});
122-
123-
tools.push(...serverMcpTools);
124123
return tools;
125124
};
126125

@@ -141,13 +140,15 @@ const getPrompt = async(promptName: string, mcpServer: MCP_SERVER, authToken?: s
141140

142141
const cachedServers: MCP_SERVER[] = [];
143142
let caddyServer: MCP_SERVER | undefined;
143+
let testServer: MCP_SERVER | undefined;
144144

145145

146-
// Cache all servers except Caddy
146+
// Cache all servers except Caddy and test-mcp-server
147147
(async() => {
148148
const servers = getServerList();
149149
caddyServer = servers.find((server) => server.name === 'Caddy');
150-
for (const server of servers.filter((server) => server.name !== 'Caddy')) {
150+
testServer = servers.find((server) => server.name === 'test-mcp-server');
151+
for (const server of servers.filter((server) => server.name !== 'Caddy' && server.name !== 'test-mcp-server')) {
151152
server.tools = await getTools(server);
152153
cachedServers.push(server);
153154
}
@@ -158,25 +159,30 @@ export const getMcpServers = async(authToken: string) => {
158159

159160
// Get Caddy collections
160161
const caddyServers: MCP_SERVER[] = [];
161-
if (!caddyServer) {
162-
return cachedServers;
162+
if (caddyServer) {
163+
const caddyTools = await getTools(caddyServer, authToken);
164+
165+
for (const tool of caddyTools) {
166+
const prompt = await getPrompt(tool.name, caddyServer, authToken);
167+
caddyServers.push({
168+
name: tool.annotations?.title?.replace('Search ', '') || tool.name,
169+
description: tool.description,
170+
url: caddyServer?.url || '',
171+
accessToken: caddyServer?.accessToken,
172+
tools: [tool],
173+
customPrompt: prompt.trim(),
174+
isCaddy: true,
175+
});
176+
}
163177
}
164178

165-
const caddyTools = await getTools(caddyServer, authToken);
166-
167-
for (const tool of caddyTools) {
168-
const prompt = await getPrompt(tool.name, caddyServer, authToken);
169-
caddyServers.push({
170-
name: tool.annotations?.title?.replace('Search ', '') || tool.name,
171-
description: tool.description,
172-
url: caddyServer?.url || '',
173-
accessToken: caddyServer?.accessToken,
174-
tools: [tool],
175-
customPrompt: prompt.trim(),
176-
isCaddy: true,
177-
});
179+
// Load test server tools dynamically (not cached)
180+
const testServers: MCP_SERVER[] = [];
181+
if (testServer) {
182+
testServer.tools = await getTools(testServer, authToken);
183+
testServers.push(testServer);
178184
}
179185

180-
return [...caddyServers, ...cachedServers];
186+
return [...caddyServers, ...testServers, ...cachedServers];
181187

182188
};

frontend/src/middleware.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import 'dotenv/config';
2+
import type { MiddlewareNext } from 'astro';
23
import { parseAuthToken } from './auth.ts';
34

45
// Define paths that should be public (no authorisation required)
@@ -9,9 +10,9 @@ const PUBLIC_PATHS = [
910
'/clear-session',
1011
'/api/health',
1112
];
12-
const TEST_AUTHORISATION_JWT = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOiIxNzM5ODk2MTk5IiwiaWF0IjoiMTczOTg5NTg5OSIsImF1dGhfdGltZSI6IjE3Mzk4OTM1MjkiLCJqdGkiOiIyYmVmOGI1ZS0yOGY0LTQ2OWQtYWQ2My1lZjJlNDgxNzliODYiLCJpc3MiOiJodHRwczovL2xvY2FsLXRlc3Rpbmcub2JmdXNjYXRlZC50ZXN0LmRvbWFpbi5nb3YudWsvcmVhbG1zL29iZnVzY2F0ZWQiLCJhdWQiOiJhY2NvdW50Iiwic3ViIjoiYmMzNzNkZTQtNDAyMi00NmIyLTgxNTEtZjA0NjEzNzhlOWNiIiwidHlwIjoiQmVhcmVyIiwiYXpwIjoibWludXRlIiwic2lkIjoiYzM2NmE5ZmUtMDNiNC00MjIxLWI0ZWItOTE0MzMzNWFhNjUyIiwiYWNyIjoiMSIsImFsbG93ZWQtb3JpZ2lucyI6WyJodHRwczovL2xvY2FsLXRlc3Rpbmcub2JmdXNjYXRlZC50ZXN0LmRvbWFpbi5nb3YudWsiXSwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbImxvY2FsLXRlc3RpbmciXX0sInJlc291cmNlX2FjY2VzcyI6eyJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX19LCJzY29wZSI6Im9wZW5pZCBwcm9maWxlIGVtYWlsIiwiZW1haWxfdmVyaWZpZWQiOiJ0cnVlIiwicHJlZmVycmVkX3VzZXJuYW1lIjoidGVzdEB0ZXN0LmNvLnVrIiwiZW1haWwiOiJ0ZXN0QHRlc3QuY28udWsifQ.Pmlltl1M0Q9EAkU96J_zkPJUjjh2TGhQGzfi0v2J-IrxUt1KTnGEcnEk09TUJjdCuyIgO9YEH-uGj5MihnGj6PqCQjq17lWP5YUjYyjgrULfgM6jZ_659RK31wZdRg_72yiy-BeVd-c-v7UzRtdTXIMkwn_aWEIp7own__jfZV_E_32KfelgtwzljVGHjGXdz_Irg6_2B4lbRn8ipWAn3SDlM9Cj8aJw7q5qq7XPk9KkXclivi4bMQJ9RNgMxtgitFtdINRF1A9_pkbERM1LliAgvW-FTLwmVECAGDQyoE8xDQuti8JgixvM22WfpdznSLd2gWAWMiyYZJwRxzFSVw'; // pragma: allowlist secret
13+
export const TEST_AUTHORISATION_JWT = 'eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOiIxNzM5ODk2MTk5IiwiaWF0IjoiMTczOTg5NTg5OSIsImF1dGhfdGltZSI6IjE3Mzk4OTM1MjkiLCJqdGkiOiIyYmVmOGI1ZS0yOGY0LTQ2OWQtYWQ2My1lZjJlNDgxNzliODYiLCJpc3MiOiJodHRwczovL2xvY2FsLXRlc3Rpbmcub2JmdXNjYXRlZC50ZXN0LmRvbWFpbi5nb3YudWsvcmVhbG1zL29iZnVzY2F0ZWQiLCJhdWQiOiJhY2NvdW50Iiwic3ViIjoiYmMzNzNkZTQtNDAyMi00NmIyLTgxNTEtZjA0NjEzNzhlOWNiIiwidHlwIjoiQmVhcmVyIiwiYXpwIjoibWludXRlIiwic2lkIjoiYzM2NmE5ZmUtMDNiNC00MjIxLWI0ZWItOTE0MzMzNWFhNjUyIiwiYWNyIjoiMSIsImFsbG93ZWQtb3JpZ2lucyI6WyJodHRwczovL2xvY2FsLXRlc3Rpbmcub2JmdXNjYXRlZC50ZXN0LmRvbWFpbi5nb3YudWsiXSwicmVhbG1fYWNjZXNzIjp7InJvbGVzIjpbImxvY2FsLXRlc3RpbmciXX0sInJlc291cmNlX2FjY2VzcyI6eyJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX19LCJzY29wZSI6Im9wZW5pZCBwcm9maWxlIGVtYWlsIiwiZW1haWxfdmVyaWZpZWQiOiJ0cnVlIiwicHJlZmVycmVkX3VzZXJuYW1lIjoidGVzdEB0ZXN0LmNvLnVrIiwiZW1haWwiOiJ0ZXN0QHRlc3QuY28udWsifQ.Pmlltl1M0Q9EAkU96J_zkPJUjjh2TGhQGzfi0v2J-IrxUt1KTnGEcnEk09TUJjdCuyIgO9YEH-uGj5MihnGj6PqCQjq17lWP5YUjYyjgrULfgM6jZ_659RK31wZdRg_72yiy-BeVd-c-v7UzRtdTXIMkwn_aWEIp7own__jfZV_E_32KfelgtwzljVGHjGXdz_Irg6_2B4lbRn8ipWAn3SDlM9Cj8aJw7q5qq7XPk9KkXclivi4bMQJ9RNgMxtgitFtdINRF1A9_pkbERM1LliAgvW-FTLwmVECAGDQyoE8xDQuti8JgixvM22WfpdznSLd2gWAWMiyYZJwRxzFSVw'; // pragma: allowlist secret
1314

14-
export async function onRequest(context, next) {
15+
export async function onRequest(context: any, next: MiddlewareNext) { // eslint-disable-line @typescript-eslint/no-explicit-any
1516
const pathname = new URL(context.request.url).pathname;
1617

1718
// Check if the requested path is public
@@ -33,7 +34,7 @@ export async function onRequest(context, next) {
3334
return redirectToUnauthorised(context);
3435
}
3536

36-
const { email, roles } = await parseAuthToken(token);
37+
const { email } = await parseAuthToken(token);
3738

3839
// If the current user doesn't match the user for the session, destroy existing session data - it may be a shared device
3940
const storedUserEmail = await context.session.get('user-email');
@@ -42,18 +43,13 @@ export async function onRequest(context, next) {
4243
context.session.set('user-email', email);
4344
}
4445

45-
// allow any role (rather than the specific role for gov-ai-client)
46-
if (!roles) {
47-
return redirectToUnauthorised(context);
48-
}
49-
5046
return next();
5147
} catch(error) {
5248
console.error('Error authorising token:', error);
5349
return redirectToUnauthorised(context);
5450
}
5551
}
5652

57-
function redirectToUnauthorised(context) {
53+
function redirectToUnauthorised(context: any) { // eslint-disable-line @typescript-eslint/no-explicit-any
5854
return context.redirect('/unauthorised');
5955
}

frontend/src/pages/post-message.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { getLlmResponse } from '../logic/ai3.ts';
33
import type { Message } from '../logic/ai3.ts';
44
import { getChat, saveChat } from '../logic/database.ts';
55
import { sendMessage } from './api/sse.ts';
6+
import { parseAuthToken } from '../auth.ts';
7+
import { TEST_AUTHORISATION_JWT } from '../middleware.ts';
68

79
export async function POST(context: APIContext) {
810

@@ -27,8 +29,22 @@ export async function POST(context: APIContext) {
2729
}
2830
}
2931

32+
// get user email from JWT
33+
let oidcDataToken;
34+
if (process.env.ENVIRONMENT === 'local') {
35+
oidcDataToken = TEST_AUTHORISATION_JWT;
36+
} else {
37+
oidcDataToken = context.request.headers.get('x-amzn-oidc-data') || '';
38+
}
39+
const authResult = await parseAuthToken(oidcDataToken);
40+
const userEmail = authResult.email;
41+
42+
if (!userEmail) {
43+
console.error('No user email found in token');
44+
return new Response('Unauthorized: No user email in token', { status: 401 });
45+
}
46+
3047
// add user prompt to session data
31-
const userEmail = await context.session?.get('user-email');
3248
let messages: Message[] | undefined = (await getChat(userEmail, chatId))?.messages;
3349
if (!messages) {
3450
messages = [];

terraform/ecs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
locals {
22
frontend_port = 8081
33
additional_policy_arns = { for idx, arn in [aws_iam_policy.ecs_exec_custom_policy.arn] : idx => arn }
4-
llm_gateway_name = var.env == "dev" || var.env == "preprod" ? "llm-gateway.${var.env}" : "llm-gateway"
4+
llm_gateway_name = "llm-gateway"
55
llm_gateway_url = "https://${local.llm_gateway_name}.i.ai.gov.uk"
66
}
77

0 commit comments

Comments
 (0)