server now hosts ACS files, websocket is now at /api/socket

This commit is contained in:
Elijah R 2024-07-10 00:47:21 -04:00
parent 89d0092f65
commit 9951e7bcaf
6 changed files with 47 additions and 4 deletions

BIN
server/agents/CLIPPIT.ACS Executable file

Binary file not shown.

BIN
server/agents/rover.acs Executable file

Binary file not shown.

View file

@ -4,6 +4,7 @@ port = 3000
[chat] [chat]
charlimit = 100 charlimit = 100
agentsDir = "agents/"
[tts] [tts]
enabled = true enabled = true
@ -12,3 +13,11 @@ server = "http://127.0.0.1:3001"
voice = "Microsoft Sam" voice = "Microsoft Sam"
tempDir = "/tmp/msac-tts" tempDir = "/tmp/msac-tts"
wavExpirySeconds = 60 wavExpirySeconds = 60
[[agents]]
friendlyName = "Clippy"
filename = "CLIPPIT.ACS"
[[agents]]
friendlyName = "Rover"
filename = "rover.acs"

View file

@ -4,7 +4,8 @@ export interface IConfig {
port: number; port: number;
} }
chat: ChatConfig; chat: ChatConfig;
tts: TTSConfig tts: TTSConfig;
agents: AgentConfig[];
} }
export interface TTSConfig { export interface TTSConfig {
@ -17,4 +18,10 @@ export interface TTSConfig {
export interface ChatConfig { export interface ChatConfig {
charlimit: number; charlimit: number;
agentsDir: string;
}
export interface AgentConfig {
friendlyName: string;
filename: string;
} }

View file

@ -53,11 +53,38 @@ if (config.tts.enabled) {
}); });
} }
if (!config.chat.agentsDir.endsWith("/")) config.chat.agentsDir += "/";
if (!fs.existsSync(config.chat.agentsDir)) {
console.error(`Directory ${config.chat.agentsDir} does not exist.`);
process.exit(1);
}
for (let agent of config.agents) {
if (!fs.existsSync(path.join(config.chat.agentsDir, agent.filename))) {
console.error(`${agent.filename} does not exist.`);
process.exit(1);
}
}
app.register(FastifyStatic, {
root: path.resolve(config.chat.agentsDir),
prefix: "/api/agents/",
decorateReply: false,
});
app.get("/api/agents", (req, res) => {
return config.agents.map(a => {
return {
url: `/api/agents/${a.filename}`,
name: a.friendlyName
}
});
});
let room = new MSAgentChatRoom(config.chat, tts); let room = new MSAgentChatRoom(config.chat, tts);
app.register(async app => { app.register(async app => {
app.get("/socket", {websocket: true}, (socket, req) => { app.get("/api/socket", {websocket: true}, (socket, req) => {
let client = new Client(socket, room); let client = new Client(socket, room);
room.addClient(client); room.addClient(client);
}); });

View file

@ -45,7 +45,7 @@ export class MSAgentClient {
default: default:
throw new Error(`Unknown protocol ${url.protocol}`); throw new Error(`Unknown protocol ${url.protocol}`);
} }
url.pathname = "/socket" url.pathname = "/api/socket"
this.socket = new WebSocket(url); this.socket = new WebSocket(url);
this.socket.addEventListener('open', () => res()); this.socket.addEventListener('open', () => res());
this.socket.addEventListener('message', e => { this.socket.addEventListener('message', e => {