Skip to content

Commit 48de412

Browse files
authored
Merge pull request #56 from NillionNetwork/fix/various
fix/various
2 parents 0887c38 + 341ec67 commit 48de412

File tree

9 files changed

+71
-33
lines changed

9 files changed

+71
-33
lines changed

docker-compose-nilcc.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
services:
22
app:
3-
image: public.ecr.aws/x8g8t2h7/nilgpt:0.4.5
3+
image: public.ecr.aws/x8g8t2h7/nilgpt:0.4.6
44
container_name: nilGPT
55
ports:
66
- "3000:3000"

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "nil-gpt",
3-
"version": "0.4.5",
3+
"version": "0.4.6",
44
"private": true,
55
"scripts": {
66
"dev": "next dev",

src/app/api/createUser/route.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,18 @@ export async function POST(request: NextRequest) {
4848
console.error("User doesn't exist, proceeding with creation", readError);
4949
}
5050

51-
const creationTime = new Date().toISOString();
51+
// Create a predictable creation time rounded to the closest 5 minutes
52+
const now = new Date();
53+
const minutes = now.getMinutes();
54+
const roundedMinutes = Math.ceil(minutes / 5) * 5;
55+
const creationTime = new Date(
56+
now.getFullYear(),
57+
now.getMonth(),
58+
now.getDate(),
59+
now.getHours(),
60+
roundedMinutes,
61+
);
62+
const creationTimeString = creationTime.toISOString();
5263

5364
// Get UTM parameters from request body if provided
5465
let utmData: USER_SCHEMA["utm"];
@@ -64,7 +75,7 @@ export async function POST(request: NextRequest) {
6475
const userData: USER_SCHEMA = {
6576
_id: recordId,
6677
provider: auth.authProvider,
67-
created_at: creationTime,
78+
created_at: creationTimeString,
6879
...(utmData && { utm: utmData }),
6980
};
7081

src/components/AttestationModal.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { CheckCircle, Copy, RefreshCw } from "lucide-react";
22
import { useState } from "react";
33
import useDeployedMeasurementHash from "@/hooks/useDeployedMeasurementHash";
44
import useNilCCMeasurementHash from "@/hooks/useNilCCMeasurementHash";
5+
import API_ENDPOINTS from "@/services/API/constants";
56
import { LINKS } from "../constants";
67
import {
78
Accordion,
@@ -54,15 +55,15 @@ const AttestationModal = () => {
5455
</AccordionTrigger>
5556
<AccordionContent className="p-0 mt-1">
5657
<p className="text-xs text-gray-600">
57-
You can do this yourself by hex encoding report.measurement
58+
You can do this yourself by fetching the report.measurement
5859
from{" "}
5960
<a
60-
href="https://nilgpt.xyz/nilcc/api/v1/report"
61+
href={API_ENDPOINTS.NILCC_GENERATE_REPORT}
6162
target="_blank"
6263
rel="noopener noreferrer"
6364
className="text-blue-600 hover:text-blue-800 underline"
6465
>
65-
https://nilgpt.xyz/nilcc/api/v1/report
66+
{API_ENDPOINTS.NILCC_GENERATE_REPORT}
6667
</a>{" "}
6768
.
6869
</p>
@@ -79,7 +80,7 @@ const AttestationModal = () => {
7980
GET
8081
</span>
8182
<code className="text-sm font-mono text-gray-600 bg-gray-100 px-1 py-0.5 rounded break-all">
82-
https://nilgpt.xyz/nilcc/api/v1/report
83+
{API_ENDPOINTS.NILCC_GENERATE_REPORT}
8384
</code>
8485
</div>
8586
<Button

src/components/chat/PersonaSelector.tsx

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { ChevronDown, Loader2, PlusIcon } from "lucide-react";
22
import Image from "next/image";
3+
import { usePathname } from "next/navigation";
34
import type React from "react";
45
import { useEffect, useRef, useState } from "react";
56
import {
@@ -26,12 +27,36 @@ const PersonaSelector: React.FC<PersonaSelectorProps> = ({
2627
onPersonaChange,
2728
disabled = false,
2829
}) => {
29-
const { selectedPersona: selectedPersonaId, setSelectedPersona } = useApp();
30+
const {
31+
selectedPersona: selectedPersonaId,
32+
setSelectedPersona,
33+
chatHistory,
34+
} = useApp();
3035
const { createChat, isCreatingChat } = useCreateChat();
3136
const [isOpen, setIsOpen] = useState(false);
37+
const pathname = usePathname();
3238

39+
// Get current chat ID from pathname
40+
const currentChatId = pathname?.match(/\/app\/chat\/(.+)/)?.[1];
41+
42+
// Determine which persona to show
43+
const getCurrentPersona = () => {
44+
// If we're in an existing chat, find the current chat's persona
45+
if (currentChatId) {
46+
const currentChat = chatHistory.find(
47+
(chat) => chat._id === currentChatId,
48+
);
49+
if (currentChat?.persona) {
50+
return currentChat.persona;
51+
}
52+
}
53+
// Fall back to the selected persona from AppContext (for new chats)
54+
return selectedPersonaId;
55+
};
56+
57+
const currentPersonaId = getCurrentPersona();
3358
const selectedPersona =
34-
personas.find((persona) => persona.id === selectedPersonaId) || personas[0];
59+
personas.find((persona) => persona.id === currentPersonaId) || personas[0];
3560
const dropdownRef = useRef<HTMLDivElement>(null);
3661

3762
useEffect(() => {
@@ -112,7 +137,7 @@ const PersonaSelector: React.FC<PersonaSelectorProps> = ({
112137
<button
113138
key={persona.id}
114139
className={`block w-full text-left px-4 py-3 text-sm hover:bg-neutral-50 ${
115-
selectedPersona.id === persona.id
140+
currentPersonaId === persona.id
116141
? "text-neutral-900 bg-neutral-50"
117142
: "text-neutral-700"
118143
}`}
@@ -125,7 +150,7 @@ const PersonaSelector: React.FC<PersonaSelectorProps> = ({
125150
{persona.description}
126151
</div>
127152
</div>
128-
{selectedPersona.id === persona.id && (
153+
{currentPersonaId === persona.id && (
129154
<Image
130155
src="/img/tick_icon.svg"
131156
alt="Selected"

src/components/chat/Sidebar.tsx

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -184,21 +184,23 @@ const Sidebar: React.FC<SidebarProps> = ({ isCollapsed, onClose }) => {
184184

185185
const finalChats = [...optimistic, ...realChats];
186186

187-
// Check if there's a UTM-based persona selection first (higher priority)
188-
const utmParams = getStoredUTMParameters();
189-
const personaFromUTM = getPersonaFromUTM(utmParams);
190-
191-
if (personaFromUTM) {
192-
console.log(
193-
`UTM campaign detected, skipping latest chat persona selection`,
194-
);
195-
} else {
196-
// Extract the latest persona from the most recent chat (fallback)
197-
if (finalChats.length > 0) {
198-
const latestChat = finalChats[0]; // First chat is the most recent
199-
if (latestChat.persona) {
200-
// Set the persona in AppContext
201-
setSelectedPersona(latestChat.persona);
187+
if (!currentChatId) {
188+
// Check if there's a UTM-based persona selection first (higher priority)
189+
const utmParams = getStoredUTMParameters();
190+
const personaFromUTM = getPersonaFromUTM(utmParams);
191+
192+
if (personaFromUTM) {
193+
console.log(
194+
`UTM campaign detected, skipping latest chat persona selection`,
195+
);
196+
} else {
197+
// Extract the latest persona from the most recent chat (fallback)
198+
if (finalChats.length > 0) {
199+
const latestChat = finalChats[0]; // First chat is the most recent
200+
if (latestChat.persona) {
201+
// Set the persona in AppContext
202+
setSelectedPersona(latestChat.persona);
203+
}
202204
}
203205
}
204206
}

src/hooks/useNilCCMeasurementHash.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { useState } from "react";
22
import API from "@/services/API";
3-
import bytesToHex from "@/utils/bytesToHex";
43

54
const useNilCCMeasurementHash = () => {
65
const [measurementHash, setMeasurementHash] = useState<string | null>(null);
@@ -9,10 +8,10 @@ const useNilCCMeasurementHash = () => {
98
const getMeasurementHash = async () => {
109
setIsLoading(true);
1110
const response = await API.generateNilCCReport();
12-
const measurement = response?.data?.report?.measurement ?? null;
11+
const measurementHash = response?.data?.report?.measurement ?? null;
1312

14-
if (measurement) {
15-
setMeasurementHash(bytesToHex(measurement));
13+
if (measurementHash) {
14+
setMeasurementHash(measurementHash);
1615
}
1716
setIsLoading(false);
1817
};

src/services/API/constants.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const API_ENDPOINTS = {
2-
NILCC_GENERATE_REPORT: "https://nilgpt.xyz/nilcc/api/v1/report",
2+
NILCC_GENERATE_REPORT: "https://nilgpt.xyz/nilcc/api/v2/report",
33
};
44

55
export default API_ENDPOINTS;

src/services/API/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
export interface INilCCReportGenerationResponse {
22
report: {
3-
measurement: number[];
3+
measurement: string;
44
};
55
}

0 commit comments

Comments
 (0)