server now hosts ACS files, websocket is now at /api/socket
This commit is contained in:
parent
89d0092f65
commit
9951e7bcaf
6 changed files with 47 additions and 4 deletions
BIN
server/agents/CLIPPIT.ACS
Executable file
BIN
server/agents/CLIPPIT.ACS
Executable file
Binary file not shown.
BIN
server/agents/rover.acs
Executable file
BIN
server/agents/rover.acs
Executable file
Binary file not shown.
|
@ -4,6 +4,7 @@ port = 3000
|
|||
|
||||
[chat]
|
||||
charlimit = 100
|
||||
agentsDir = "agents/"
|
||||
|
||||
[tts]
|
||||
enabled = true
|
||||
|
@ -12,3 +13,11 @@ server = "http://127.0.0.1:3001"
|
|||
voice = "Microsoft Sam"
|
||||
tempDir = "/tmp/msac-tts"
|
||||
wavExpirySeconds = 60
|
||||
|
||||
[[agents]]
|
||||
friendlyName = "Clippy"
|
||||
filename = "CLIPPIT.ACS"
|
||||
|
||||
[[agents]]
|
||||
friendlyName = "Rover"
|
||||
filename = "rover.acs"
|
|
@ -4,7 +4,8 @@ export interface IConfig {
|
|||
port: number;
|
||||
}
|
||||
chat: ChatConfig;
|
||||
tts: TTSConfig
|
||||
tts: TTSConfig;
|
||||
agents: AgentConfig[];
|
||||
}
|
||||
|
||||
export interface TTSConfig {
|
||||
|
@ -17,4 +18,10 @@ export interface TTSConfig {
|
|||
|
||||
export interface ChatConfig {
|
||||
charlimit: number;
|
||||
agentsDir: string;
|
||||
}
|
||||
|
||||
export interface AgentConfig {
|
||||
friendlyName: string;
|
||||
filename: string;
|
||||
}
|
|
@ -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);
|
||||
|
||||
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);
|
||||
room.addClient(client);
|
||||
});
|
||||
|
|
|
@ -45,7 +45,7 @@ export class MSAgentClient {
|
|||
default:
|
||||
throw new Error(`Unknown protocol ${url.protocol}`);
|
||||
}
|
||||
url.pathname = "/socket"
|
||||
url.pathname = "/api/socket"
|
||||
this.socket = new WebSocket(url);
|
||||
this.socket.addEventListener('open', () => res());
|
||||
this.socket.addEventListener('message', e => {
|
||||
|
|
Loading…
Reference in a new issue