Matt Huntington 2 days ago
commit c249783683

@ -0,0 +1,18 @@
{
"id": "claude-gm",
"title": "Claude GM",
"description": "Routes chat messages to a Claude Code relay server for AI Game Master responses.",
"version": "0.1.0",
"compatibility": {
"minimum": "12",
"verified": "13"
},
"authors": [
{
"name": "Matt Huntington"
}
],
"esmodules": [
"scripts/claude-gm.js"
]
}

@ -0,0 +1,39 @@
function formatResponse(text) {
return text
// Escape HTML entities first
.replace(/&/g, "&")
.replace(/</g, "&lt;")
.replace(/>/g, "&gt;")
// Bold: **text**
.replace(/\*\*(.+?)\*\*/g, "<strong>$1</strong>")
// Italic: *text*
.replace(/\*(.+?)\*/g, "<em>$1</em>")
// Dice notation: 🎲 lines get highlighted
.replace(/^(🎲.*)$/gm, '<span style="color: #c9a33e; font-weight: bold;">$1</span>')
// Line breaks
.replace(/\n\n/g, "</p><p>")
.replace(/\n/g, "<br>")
// Wrap in paragraph
.replace(/^(.*)$/, "<p>$1</p>");
}
Hooks.on("chatMessage", async (chatLog, message, chatData) => {
console.log(chatData);
console.log(message);
const response = await fetch('http://192.168.1.183:3000/prompt', {
//const response = await fetch('http://debianmacbookair:3000/prompt', {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ message })
});
const data = await response.json();
console.log(data);
await ChatMessage.create({
content: formatResponse(data.result),
speaker: { alias: 'AI DM'},
style: CONST.CHAT_MESSAGE_STYLES.IC
});
})
Hooks.once("ready", () => {
console.log('Claude listening...');
});
Loading…
Cancel
Save