Skip to content

Commit cb192d4

Browse files
committed
Merge branch 'v2-develop' of https://github.com/elizaOS/eliza into v2-develop
2 parents 23f481d + 12eabfa commit cb192d4

File tree

5 files changed

+21
-15
lines changed

5 files changed

+21
-15
lines changed

packages/client/src/components/chat.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import { useAgent, useMessages } from '@/hooks/use-query-hooks';
1111
import { cn, getEntityId, moment } from '@/lib/utils';
1212
import SocketIOManager from '@/lib/socketio-manager';
1313
import { WorldManager } from '@/lib/world-manager';
14+
import { randomUUID } from '@/lib/utils';
1415
import type { IAttachment } from '@/types';
1516
import type { Content, UUID } from '@elizaos/core';
1617
import { AgentStatus } from '@elizaos/core';
@@ -315,7 +316,7 @@ export default function Page({ agentId }: { agentId: UUID }) {
315316
senderName: USER_NAME,
316317
roomId: roomId,
317318
source: SOURCE_NAME,
318-
id: crypto.randomUUID(), // Add a unique ID for React keys and duplicate detection
319+
id: randomUUID(), // Add a unique ID for React keys and duplicate detection
319320
};
320321

321322
console.log('[Chat] Adding user message to UI:', userMessage);

packages/client/src/lib/api.ts

+3-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import type { Agent, Character, UUID, Memory } from '@elizaos/core';
22
import { WorldManager } from './world-manager';
33

44
const API_PREFIX = '/api';
5-
const BASE_URL = `http://localhost:${import.meta.env.VITE_SERVER_PORT}${API_PREFIX}`;
65

76
/**
87
* A function that handles fetching data from a specified URL with various options.
@@ -25,12 +24,9 @@ const fetcher = async ({
2524
headers?: HeadersInit;
2625
}) => {
2726
// Ensure URL starts with a slash if it's a relative path
28-
const normalizedUrl = url.startsWith('/') ? url : `/${url}`;
27+
const normalizedUrl = API_PREFIX + (url.startsWith('/') ? url : `/${url}`);
2928

30-
// Construct the full URL
31-
const fullUrl = `${BASE_URL}${normalizedUrl}`;
32-
33-
console.log('API Request:', method || 'GET', fullUrl);
29+
console.log('API Request:', method || 'GET', normalizedUrl);
3430

3531
const options: RequestInit = {
3632
method: method ?? 'GET',
@@ -59,7 +55,7 @@ const fetcher = async ({
5955
}
6056

6157
try {
62-
const response = await fetch(fullUrl, options);
58+
const response = await fetch(normalizedUrl, options);
6359
const contentType = response.headers.get('Content-Type');
6460

6561
if (contentType === 'audio/mpeg') {

packages/client/src/lib/socketio-manager.ts

+6-3
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { SOCKET_MESSAGE_TYPE } from '@elizaos/core';
33
import EventEmitter from 'eventemitter3';
44
import { io, type Socket } from 'socket.io-client';
55
import { WorldManager } from './world-manager';
6+
import { randomUUID } from './utils';
67

7-
const BASE_URL = `http://localhost:${import.meta.env.VITE_SERVER_PORT}`;
8+
//const BASE_URL = `http://localhost:${import.meta.env.VITE_SERVER_PORT}`;
89

910
/**
1011
* SocketIOManager handles real-time communication between the client and server
@@ -44,7 +45,9 @@ class SocketIOManager extends EventEmitter {
4445
this.entityId = entityId;
4546

4647
// Create a single socket connection
47-
this.socket = io(BASE_URL, {
48+
const fullURL = window.location.origin + '/';
49+
console.log('connecting to', fullURL);
50+
this.socket = io(fullURL, {
4851
autoConnect: true,
4952
reconnection: true,
5053
});
@@ -181,7 +184,7 @@ class SocketIOManager extends EventEmitter {
181184
await this.connectPromise;
182185
}
183186

184-
const messageId = crypto.randomUUID();
187+
const messageId = randomUUID();
185188
const worldId = WorldManager.getWorldId();
186189

187190
console.log(`[SocketIO] Sending message to room ${roomId}`);

packages/client/src/lib/utils.ts

+6-1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ export function urlToCharacterName(urlName: string): string {
4141
return urlName.replace(/-+/g, ' ');
4242
}
4343

44+
// crypto.randomUUID only works in https context in firefox
45+
export function randomUUID(): UUID {
46+
return URL.createObjectURL(new Blob()).split('/').pop();
47+
}
48+
4449
export function getEntityId(): UUID {
4550
const USER_ID_KEY = 'elizaos-client-user-id';
4651
const existingUserId = localStorage.getItem(USER_ID_KEY);
@@ -49,7 +54,7 @@ export function getEntityId(): UUID {
4954
return existingUserId as UUID;
5055
}
5156

52-
const newUserId = crypto.randomUUID() as UUID;
57+
const newUserId = randomUUID() as UUID;
5358
localStorage.setItem(USER_ID_KEY, newUserId);
5459

5560
return newUserId;

packages/client/src/lib/world-manager.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import type { UUID } from '@elizaos/core';
2+
import { randomUUID } from './utils';
23

34
// Key used for storing the worldId in localStorage
45
const WORLD_ID_KEY = 'elizaos-world-id';
@@ -28,7 +29,7 @@ export const WorldManager = {
2829
}
2930

3031
// Create a new worldId if one doesn't exist
31-
const newWorldId = crypto.randomUUID() as UUID;
32+
const newWorldId = randomUUID() as UUID;
3233
localStorage.setItem(WORLD_ID_KEY, newWorldId);
3334

3435
return newWorldId;
@@ -38,7 +39,7 @@ export const WorldManager = {
3839
* Reset the world ID (mainly for testing purposes)
3940
*/
4041
resetWorldId: (): UUID => {
41-
const newWorldId = crypto.randomUUID() as UUID;
42+
const newWorldId = randomUUID() as UUID;
4243
localStorage.setItem(WORLD_ID_KEY, newWorldId);
4344
return newWorldId;
4445
},
@@ -67,7 +68,7 @@ export const WorldManager = {
6768

6869
if (options?.isGroup) {
6970
// For group chats, generate a new UUID
70-
return crypto.randomUUID() as UUID;
71+
return randomUUID() as UUID;
7172
}
7273

7374
// For 1:1 chats with an agent, use the agent ID as the room ID

0 commit comments

Comments
 (0)