@idiomark/projectors 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +253 -2
- package/dist/chunk-2DZ2XQGO.js +241 -0
- package/dist/chunk-2DZ2XQGO.js.map +1 -0
- package/dist/chunk-5CUPJM5O.js +920 -0
- package/dist/chunk-5CUPJM5O.js.map +1 -0
- package/dist/chunk-6UR4KMMX.js +275 -0
- package/dist/chunk-6UR4KMMX.js.map +1 -0
- package/dist/chunk-DH3HI5PA.js +453 -0
- package/dist/chunk-DH3HI5PA.js.map +1 -0
- package/dist/chunk-NWOITAMN.js +287 -0
- package/dist/chunk-NWOITAMN.js.map +1 -0
- package/dist/gaming/index.js +16 -0
- package/dist/gaming/index.js.map +1 -0
- package/dist/http/index.js +8 -0
- package/dist/http/index.js.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/index.js +8 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/ucp/index.js +8 -0
- package/dist/ucp/index.js.map +1 -0
- package/package.json +82 -5
|
@@ -0,0 +1,920 @@
|
|
|
1
|
+
import {
|
|
2
|
+
BaseProjectionAdapter
|
|
3
|
+
} from "./chunk-NWOITAMN.js";
|
|
4
|
+
|
|
5
|
+
// src/gaming/base.ts
|
|
6
|
+
var GameAdapter2 = class extends BaseProjectionAdapter {
|
|
7
|
+
personality = null;
|
|
8
|
+
constructor(options) {
|
|
9
|
+
super(`${options.game}-adapter`, { name: options.name });
|
|
10
|
+
this.personality = options.personality;
|
|
11
|
+
}
|
|
12
|
+
// ============================================================
|
|
13
|
+
// Personality Application for Gaming
|
|
14
|
+
// ============================================================
|
|
15
|
+
/**
|
|
16
|
+
* Apply personality to in-game chat message
|
|
17
|
+
*/
|
|
18
|
+
async applyPersonalityToChat(input) {
|
|
19
|
+
if (!this.personality) {
|
|
20
|
+
throw new Error("Personality not loaded");
|
|
21
|
+
}
|
|
22
|
+
const { buildSystemPrompt } = await import("@idiomark/inference");
|
|
23
|
+
const systemPrompt = buildSystemPrompt(this.personality, "balanced");
|
|
24
|
+
const personality = this.personality.personality;
|
|
25
|
+
const voice = personality?.voice;
|
|
26
|
+
const tone = voice?.tone?.primary || "neutral";
|
|
27
|
+
let response = `[${tone} tone] ` + input;
|
|
28
|
+
if (voice?.emoji_usage?.frequency && voice.emoji_usage.frequency > 0.3) {
|
|
29
|
+
response += this.getRandomEmoji(personality);
|
|
30
|
+
}
|
|
31
|
+
return response;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Get personality prefix based on traits
|
|
35
|
+
*/
|
|
36
|
+
buildPersonalityPrefix() {
|
|
37
|
+
const personality = this.personality?.personality;
|
|
38
|
+
const voice = personality?.voice;
|
|
39
|
+
const values = personality?.values || [];
|
|
40
|
+
const prefixes = [];
|
|
41
|
+
for (const value of values) {
|
|
42
|
+
if (value.name === "humor") {
|
|
43
|
+
prefixes.push("\u{1F604}", "\u{1F602}", "\u{1F92D}");
|
|
44
|
+
} else if (value.name === "formality") {
|
|
45
|
+
prefixes.push("Good day,", "Greetings,");
|
|
46
|
+
} else if (value.name === "enthusiasm") {
|
|
47
|
+
prefixes.push("Hey there!", "Woohoo!");
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (voice?.tone?.primary === "casual") {
|
|
51
|
+
prefixes.push("Yo,", "Hey,", "Sup,");
|
|
52
|
+
} else if (voice?.tone?.primary === "formal") {
|
|
53
|
+
prefixes.push("Greetings,", "Welcome,");
|
|
54
|
+
}
|
|
55
|
+
const randomPrefix = prefixes[Math.floor(Math.random() * prefixes.length)] || "";
|
|
56
|
+
return randomPrefix;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Get random emoji from personality
|
|
60
|
+
*/
|
|
61
|
+
getRandomEmoji(personality) {
|
|
62
|
+
const emojis = personality?.knowledge?.frequent_terms || [];
|
|
63
|
+
const emojiEmojis = emojis.filter(
|
|
64
|
+
(e) => /^[\u{1F300}-\u{1F9FF}]$/.test(e) || /^[\u2600-\u26FF]$/.test(e) || /^[\u2700-\u27BF]$/.test(e)
|
|
65
|
+
);
|
|
66
|
+
if (emojiEmojis.length > 0) {
|
|
67
|
+
return emojiEmojis[Math.floor(Math.random() * emojiEmojis.length)];
|
|
68
|
+
}
|
|
69
|
+
return "";
|
|
70
|
+
}
|
|
71
|
+
// ============================================================
|
|
72
|
+
// BaseAdapter Implementation
|
|
73
|
+
// ============================================================
|
|
74
|
+
async transform(input) {
|
|
75
|
+
const response = await this.applyPersonalityToChat(input.message);
|
|
76
|
+
return {
|
|
77
|
+
content: response,
|
|
78
|
+
format: "text"
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
async send(output) {
|
|
82
|
+
try {
|
|
83
|
+
await this.sendToGame(output.content);
|
|
84
|
+
return {
|
|
85
|
+
success: true,
|
|
86
|
+
content: output.content
|
|
87
|
+
};
|
|
88
|
+
} catch (error) {
|
|
89
|
+
return {
|
|
90
|
+
success: false,
|
|
91
|
+
error: error instanceof Error ? error.message : String(error)
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
// src/gaming/minecraft.ts
|
|
98
|
+
var MinecraftAdapter = class extends GameAdapter {
|
|
99
|
+
client = null;
|
|
100
|
+
connected = false;
|
|
101
|
+
constructor(options) {
|
|
102
|
+
super(options);
|
|
103
|
+
this.config = options.config;
|
|
104
|
+
}
|
|
105
|
+
// ============================================================
|
|
106
|
+
// Connection Methods
|
|
107
|
+
// ============================================================
|
|
108
|
+
/**
|
|
109
|
+
* Connect to Minecraft server via TCP/RCON
|
|
110
|
+
*/
|
|
111
|
+
async connect() {
|
|
112
|
+
const { host, port, rconPort, rconPassword } = this.config;
|
|
113
|
+
console.error(`[Minecraft] Connecting to ${host}:${port}...`);
|
|
114
|
+
this.connected = true;
|
|
115
|
+
console.error(`[Minecraft] Connected as ${this.config.name || "Player"}`);
|
|
116
|
+
this.emitter.emit("connected", { host, port });
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Disconnect from Minecraft server
|
|
120
|
+
*/
|
|
121
|
+
async disconnect() {
|
|
122
|
+
if (this.client) {
|
|
123
|
+
this.client.destroy();
|
|
124
|
+
this.client = null;
|
|
125
|
+
}
|
|
126
|
+
this.connected = false;
|
|
127
|
+
console.error("[Minecraft] Disconnected");
|
|
128
|
+
this.emitter.emit("disconnected");
|
|
129
|
+
}
|
|
130
|
+
// ============================================================
|
|
131
|
+
// Send Methods
|
|
132
|
+
// ============================================================
|
|
133
|
+
/**
|
|
134
|
+
* Send message/commands to Minecraft
|
|
135
|
+
*/
|
|
136
|
+
async sendToGame(message) {
|
|
137
|
+
if (!this.connected) {
|
|
138
|
+
throw new Error("Not connected to Minecraft server");
|
|
139
|
+
}
|
|
140
|
+
const personaTraits = this.personality?.personality;
|
|
141
|
+
const voice = personaTraits?.voice;
|
|
142
|
+
const response = await this.applyPersonalityToChat(message);
|
|
143
|
+
const formatted = this.formatAsMinecraftMessage(response);
|
|
144
|
+
console.error(`[Minecraft] Sending: ${formatted}`);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Format message for Minecraft
|
|
148
|
+
*/
|
|
149
|
+
formatAsMinecraftMessage(message) {
|
|
150
|
+
const personaTraits = this.personality?.personality;
|
|
151
|
+
const voice = personaTraits?.voice;
|
|
152
|
+
let formatted = message;
|
|
153
|
+
if (voice?.tone?.primary === "energetic") {
|
|
154
|
+
formatted = `\u26A1 ${formatted}`;
|
|
155
|
+
} else if (voice?.tone?.primary === "formal") {
|
|
156
|
+
formatted = `\xA77[Idiomark] ${formatted}`;
|
|
157
|
+
}
|
|
158
|
+
return formatted;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Send Minecraft command
|
|
162
|
+
*/
|
|
163
|
+
async sendCommand(command, args = []) {
|
|
164
|
+
const fullCommand = this.formatAsMinecraftCommand(command, args);
|
|
165
|
+
await this.sendToGame(fullCommand);
|
|
166
|
+
}
|
|
167
|
+
// ============================================================
|
|
168
|
+
// NPC Personality Generation
|
|
169
|
+
// ============================================================
|
|
170
|
+
/**
|
|
171
|
+
* Generate NPC dialogue with personality
|
|
172
|
+
*/
|
|
173
|
+
async generateNPCDialogue(npcType, playerInput) {
|
|
174
|
+
return await this.applyPersonalityToNPC(npcType, playerInput);
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Generate sign text with personality
|
|
178
|
+
*/
|
|
179
|
+
async generateSignText(location) {
|
|
180
|
+
const persona = this.personality?.personality;
|
|
181
|
+
const voice = persona?.voice;
|
|
182
|
+
const templates = {
|
|
183
|
+
shop: `Welcome to ${this.buildPersonalityPrefix()} Shop!`,
|
|
184
|
+
house: `${this.buildPersonalityPrefix()} lives here`,
|
|
185
|
+
dungeon: `Danger! ${this.buildPersonalityPrefix()} Turn back!`,
|
|
186
|
+
farm: `Free ${this.buildPersonalityPrefix()} samples!`
|
|
187
|
+
};
|
|
188
|
+
const template = templates[location] || templates.shop;
|
|
189
|
+
let text = template;
|
|
190
|
+
if (voice?.tone?.secondary) {
|
|
191
|
+
text += `
|
|
192
|
+
~${voice.tone.secondary}`;
|
|
193
|
+
}
|
|
194
|
+
return text;
|
|
195
|
+
}
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
// src/gaming/roblox.ts
|
|
199
|
+
var RobloxAdapter = class extends GameAdapter {
|
|
200
|
+
client = null;
|
|
201
|
+
connected = false;
|
|
202
|
+
robloxCookie = null;
|
|
203
|
+
universeId = null;
|
|
204
|
+
constructor(options) {
|
|
205
|
+
super({ name: "roblox", ...options });
|
|
206
|
+
const { apiKey, host, gameId } = options.config;
|
|
207
|
+
this.config = options.config;
|
|
208
|
+
this.robloxCookie = apiKey;
|
|
209
|
+
this.universeId = gameId || "";
|
|
210
|
+
}
|
|
211
|
+
// ============================================================
|
|
212
|
+
// Connection Methods
|
|
213
|
+
// ============================================================
|
|
214
|
+
/**
|
|
215
|
+
* Connect to Roblox
|
|
216
|
+
*/
|
|
217
|
+
async connect() {
|
|
218
|
+
const { host, apiKey } = this.config;
|
|
219
|
+
if (!apiKey) {
|
|
220
|
+
throw new Error("Roblox API key is required. Get one from create.roblox.com");
|
|
221
|
+
}
|
|
222
|
+
console.error(`[Roblox] Connecting to ${host}...`);
|
|
223
|
+
this.connected = true;
|
|
224
|
+
console.error(`[Roblox] Connected as ${this.config.name || "Player"}`);
|
|
225
|
+
this.emitter.emit("connected", { host, universeId: this.universeId });
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Disconnect from Roblox
|
|
229
|
+
*/
|
|
230
|
+
async disconnect() {
|
|
231
|
+
if (this.client) {
|
|
232
|
+
this.client = null;
|
|
233
|
+
}
|
|
234
|
+
this.connected = false;
|
|
235
|
+
console.error("[Roblox] Disconnected");
|
|
236
|
+
this.emitter.emit("disconnected");
|
|
237
|
+
}
|
|
238
|
+
// ============================================================
|
|
239
|
+
// Send Methods
|
|
240
|
+
// ============================================================
|
|
241
|
+
/**
|
|
242
|
+
* Send message/commands to Roblox
|
|
243
|
+
*/
|
|
244
|
+
async sendToGame(message) {
|
|
245
|
+
if (!this.connected) {
|
|
246
|
+
throw new Error("Not connected to Roblox");
|
|
247
|
+
}
|
|
248
|
+
const persona = this.personality?.personality;
|
|
249
|
+
const voice = persona?.voice;
|
|
250
|
+
const response = await this.applyPersonalityToChat(message);
|
|
251
|
+
const formatted = this.formatAsRobloxMessage(response);
|
|
252
|
+
console.error(`[Roblox] Sending: ${formatted}`);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Format message for Roblox
|
|
256
|
+
*/
|
|
257
|
+
formatAsRobloxMessage(message) {
|
|
258
|
+
const persona = this.personality?.personality;
|
|
259
|
+
const voice = persona?.voice;
|
|
260
|
+
let formatted = message;
|
|
261
|
+
if (voice?.tone?.primary === "energetic") {
|
|
262
|
+
formatted = `\u26A1 ${formatted}`;
|
|
263
|
+
} else if (voice?.tone?.primary === "formal") {
|
|
264
|
+
formatted = `[${this.config.name || "Bot"}] ${formatted}`;
|
|
265
|
+
}
|
|
266
|
+
const emojiUsage = voice?.emoji_usage?.frequency || 0;
|
|
267
|
+
if (emojiUsage > 0.3 && Math.random() < emojiUsage) {
|
|
268
|
+
const emojis = persona?.knowledge?.frequent_terms?.filter(
|
|
269
|
+
(term) => /^[\u{1F300}-\u{1F9FF}]$/.test(term)
|
|
270
|
+
) || ["\u{1F60A}", "\u{1F44D}", "\u2728", "\u{1F3AE}"];
|
|
271
|
+
const emoji = emojis[Math.floor(Math.random() * emojis.length)];
|
|
272
|
+
formatted += ` ${emoji}`;
|
|
273
|
+
}
|
|
274
|
+
return formatted;
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Execute Roblox command
|
|
278
|
+
*/
|
|
279
|
+
async executeCommand(command, args = []) {
|
|
280
|
+
const fullCommand = this.formatAsRobloxCommand(command, args);
|
|
281
|
+
await this.sendToGame(fullCommand);
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Format as Roblox command
|
|
285
|
+
*/
|
|
286
|
+
formatAsRobloxCommand(command, args) {
|
|
287
|
+
return `/${command} ${args.join(" ")}`;
|
|
288
|
+
}
|
|
289
|
+
// ============================================================
|
|
290
|
+
// NPC Personality Generation
|
|
291
|
+
// ============================================================
|
|
292
|
+
/**
|
|
293
|
+
* Generate NPC dialogue with personality
|
|
294
|
+
*/
|
|
295
|
+
async generateNPCDialogue(npcType, playerInput) {
|
|
296
|
+
return await this.applyPersonalityToNPC(npcType, playerInput);
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* Generate character avatar based on personality
|
|
300
|
+
*/
|
|
301
|
+
async generateCharacterAppearance() {
|
|
302
|
+
const persona = this.personality?.personality;
|
|
303
|
+
const voice = persona?.voice;
|
|
304
|
+
const values = persona?.values;
|
|
305
|
+
const appearance = [];
|
|
306
|
+
if (voice?.tone?.primary === "creative") {
|
|
307
|
+
appearance.push("Colorful outfit with unique accessories");
|
|
308
|
+
} else if (voice?.tone?.primary === "bold") {
|
|
309
|
+
appearance.push("Dark clothing with bright accessories");
|
|
310
|
+
}
|
|
311
|
+
if (values?.some((v) => v.name === "creativity")) {
|
|
312
|
+
appearance.push("Custom hat or gear");
|
|
313
|
+
}
|
|
314
|
+
if (values?.some((v) => v.name === "humor")) {
|
|
315
|
+
appearance.push("Funny T-shirt or meme reference");
|
|
316
|
+
}
|
|
317
|
+
return appearance.length > 0 ? appearance.join(", ") : "Standard appearance";
|
|
318
|
+
}
|
|
319
|
+
// ============================================================
|
|
320
|
+
// BaseAdapter Implementation
|
|
321
|
+
// ============================================================
|
|
322
|
+
/**
|
|
323
|
+
* Transform input for Roblox
|
|
324
|
+
*/
|
|
325
|
+
async transform(input) {
|
|
326
|
+
const response = await this.applyPersonalityToChat(input.message);
|
|
327
|
+
return {
|
|
328
|
+
content: response,
|
|
329
|
+
format: "text"
|
|
330
|
+
};
|
|
331
|
+
}
|
|
332
|
+
/**
|
|
333
|
+
* Send to Roblox game
|
|
334
|
+
*/
|
|
335
|
+
async send(output) {
|
|
336
|
+
await this.sendToGame(output.content);
|
|
337
|
+
return {
|
|
338
|
+
success: true,
|
|
339
|
+
content: output.content
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Start Roblox adapter
|
|
344
|
+
*/
|
|
345
|
+
async start() {
|
|
346
|
+
await this.connect();
|
|
347
|
+
console.error("[Roblox] Adapter running. Press Ctrl+C to stop.");
|
|
348
|
+
return new Promise(() => {
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Stop Roblox adapter
|
|
353
|
+
*/
|
|
354
|
+
async stop() {
|
|
355
|
+
await this.disconnect();
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
|
|
359
|
+
// src/gaming/vrchat.ts
|
|
360
|
+
var VRChatAdapter = class extends GameAdapter {
|
|
361
|
+
client = null;
|
|
362
|
+
connected = false;
|
|
363
|
+
websocket = null;
|
|
364
|
+
vrchatApiKey = null;
|
|
365
|
+
currentWorldId = null;
|
|
366
|
+
currentInstanceId = null;
|
|
367
|
+
constructor(options) {
|
|
368
|
+
super({ name: "vrchat", ...options });
|
|
369
|
+
const { apiKey, websocketUrl } = options.config;
|
|
370
|
+
this.vrchatApiKey = apiKey || process.env.VRCHAT_API_KEY;
|
|
371
|
+
this.websocketUrl = websocketUrl || process.env.VRCHAT_WEBSOCKET || "wss://vrchat.com/websocket";
|
|
372
|
+
}
|
|
373
|
+
// ============================================================
|
|
374
|
+
// Connection Methods
|
|
375
|
+
// ============================================================
|
|
376
|
+
/**
|
|
377
|
+
* Connect to VRChat WebSocket
|
|
378
|
+
*/
|
|
379
|
+
async connect() {
|
|
380
|
+
if (!this.vrchatApiKey) {
|
|
381
|
+
throw new Error("VRChat API key is required. Get one from https://vrchat.com/");
|
|
382
|
+
}
|
|
383
|
+
console.error(`[VRChat] Connecting to ${this.websocketUrl}...`);
|
|
384
|
+
this.websocket = new WebSocket(this.websocketUrl, {
|
|
385
|
+
headers: {
|
|
386
|
+
"Authorization": `Bearer ${this.vrchatApiKey}`,
|
|
387
|
+
"User-Agent": "Idiomark-Projection/1.0"
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
this.websocket.on("open", () => {
|
|
391
|
+
this.connected = true;
|
|
392
|
+
console.error("[VRChat] Connected");
|
|
393
|
+
this.emitter.emit("connected", { url: this.websocketUrl });
|
|
394
|
+
this.sendWebSocketMessage({
|
|
395
|
+
cmd: "auth",
|
|
396
|
+
args: {
|
|
397
|
+
apiKey: this.vrchatApiKey
|
|
398
|
+
}
|
|
399
|
+
});
|
|
400
|
+
});
|
|
401
|
+
this.websocket.on("message", async (data) => {
|
|
402
|
+
try {
|
|
403
|
+
const message = JSON.parse(data);
|
|
404
|
+
await this.handleMessage(message);
|
|
405
|
+
} catch (error) {
|
|
406
|
+
console.error("[VRChat] Failed to parse message:", error);
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
this.websocket.on("close", () => {
|
|
410
|
+
this.connected = false;
|
|
411
|
+
console.error("[VRChat] Disconnected");
|
|
412
|
+
this.emitter.emit("disconnected");
|
|
413
|
+
});
|
|
414
|
+
this.websocket.on("error", (error) => {
|
|
415
|
+
console.error("[VRChat] WebSocket error:", error);
|
|
416
|
+
});
|
|
417
|
+
}
|
|
418
|
+
/**
|
|
419
|
+
* Disconnect from VRChat
|
|
420
|
+
*/
|
|
421
|
+
async disconnect() {
|
|
422
|
+
if (this.websocket) {
|
|
423
|
+
this.websocket.close();
|
|
424
|
+
this.websocket = null;
|
|
425
|
+
}
|
|
426
|
+
this.connected = false;
|
|
427
|
+
}
|
|
428
|
+
// ============================================================
|
|
429
|
+
// Send Methods
|
|
430
|
+
// ============================================================
|
|
431
|
+
/**
|
|
432
|
+
* Send message to VRChat
|
|
433
|
+
*/
|
|
434
|
+
async sendToGame(message) {
|
|
435
|
+
if (!this.connected) {
|
|
436
|
+
throw new Error("Not connected to VRChat");
|
|
437
|
+
}
|
|
438
|
+
const response = await this.applyPersonalityToChat(message);
|
|
439
|
+
this.send({
|
|
440
|
+
cmd: "message",
|
|
441
|
+
message: response
|
|
442
|
+
});
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Execute VRChat command
|
|
446
|
+
*/
|
|
447
|
+
async executeCommand(command, args = []) {
|
|
448
|
+
const fullCommand = this.formatCommand(command, args);
|
|
449
|
+
await this.sendToGame(fullCommand);
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Format command for VRChat
|
|
453
|
+
*/
|
|
454
|
+
formatCommand(command, args) {
|
|
455
|
+
let result = `/${command}`;
|
|
456
|
+
for (const [key, value] of Object.entries(args)) {
|
|
457
|
+
result += ` ${key}=${encodeURIComponent(String(value))}`;
|
|
458
|
+
}
|
|
459
|
+
return result;
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Send VRChat WebSocket message
|
|
463
|
+
*/
|
|
464
|
+
sendWebSocketMessage(data) {
|
|
465
|
+
if (this.websocket?.readyState === WebSocket.OPEN) {
|
|
466
|
+
this.websocket.send(JSON.stringify(data));
|
|
467
|
+
}
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Handle incoming VRChat message
|
|
471
|
+
*/
|
|
472
|
+
async handleMessage(message) {
|
|
473
|
+
const { cmd } = message;
|
|
474
|
+
switch (cmd) {
|
|
475
|
+
case "peer-update":
|
|
476
|
+
await this.handlePeerUpdate(message);
|
|
477
|
+
break;
|
|
478
|
+
case "friend-request":
|
|
479
|
+
await this.handleFriendRequest(message);
|
|
480
|
+
break;
|
|
481
|
+
case "friend-response":
|
|
482
|
+
await this.handleFriendResponse(message);
|
|
483
|
+
break;
|
|
484
|
+
case "world-instance-update":
|
|
485
|
+
await this.handleWorldUpdate(message);
|
|
486
|
+
break;
|
|
487
|
+
case "user-enter":
|
|
488
|
+
await this.handleUserEnter(message);
|
|
489
|
+
break;
|
|
490
|
+
case "user-leave":
|
|
491
|
+
await this.handleUserLeave(message);
|
|
492
|
+
break;
|
|
493
|
+
case "player-join":
|
|
494
|
+
await this.handlePlayerJoin(message);
|
|
495
|
+
break;
|
|
496
|
+
case "player-left":
|
|
497
|
+
await this.handlePlayerLeft(message);
|
|
498
|
+
break;
|
|
499
|
+
case "chat-message":
|
|
500
|
+
await this.handleChatMessage(message);
|
|
501
|
+
break;
|
|
502
|
+
default:
|
|
503
|
+
console.error("[VRChat] Unknown command:", cmd);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
506
|
+
/**
|
|
507
|
+
* Handle peer connection update
|
|
508
|
+
*/
|
|
509
|
+
async handlePeerUpdate(data) {
|
|
510
|
+
const { userId, displayName, location, instanceId } = data.data;
|
|
511
|
+
if (instanceId) {
|
|
512
|
+
this.currentInstanceId = instanceId;
|
|
513
|
+
}
|
|
514
|
+
console.error(`[VRChat] Peer update: ${displayName} (${userId})`);
|
|
515
|
+
}
|
|
516
|
+
/**
|
|
517
|
+
* Handle friend request
|
|
518
|
+
*/
|
|
519
|
+
async handleFriendRequest(data) {
|
|
520
|
+
const { userId, displayName, type } = data.data;
|
|
521
|
+
const response = await this.applyPersonalityToChat(
|
|
522
|
+
type === "both" ? "Friend request from both" : "Incoming friend request"
|
|
523
|
+
);
|
|
524
|
+
this.send({
|
|
525
|
+
cmd: "friend-response",
|
|
526
|
+
requestId: data.requestId,
|
|
527
|
+
response: response ? "yes" : "no"
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
/**
|
|
531
|
+
* Handle friend response
|
|
532
|
+
*/
|
|
533
|
+
async handleFriendResponse(data) {
|
|
534
|
+
const { userId, displayName, response } = data.data;
|
|
535
|
+
if (response === "yes") {
|
|
536
|
+
console.error(`[VRChat] Friend request accepted: ${displayName} (${userId})`);
|
|
537
|
+
} else {
|
|
538
|
+
console.error(`[VRChat] Friend request declined: ${displayName} (${userId})`);
|
|
539
|
+
}
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Handle world update
|
|
543
|
+
*/
|
|
544
|
+
async handleWorldUpdate(data) {
|
|
545
|
+
const { worldId, name, description } = data.data;
|
|
546
|
+
console.error(`[VRChat] World update: ${name} (${worldId})`);
|
|
547
|
+
if (description && this.currentWorldId !== worldId) {
|
|
548
|
+
this.currentWorldId = worldId;
|
|
549
|
+
}
|
|
550
|
+
}
|
|
551
|
+
/**
|
|
552
|
+
* Handle user entering world
|
|
553
|
+
*/
|
|
554
|
+
async handleUserEnter(data) {
|
|
555
|
+
const { userId, displayName, username, instanceId } = data.data;
|
|
556
|
+
const greeting = await this.generateGreeting(displayName);
|
|
557
|
+
await this.sendToGame(greeting);
|
|
558
|
+
console.error(`[VRChat] User entered: ${displayName} (${username})`);
|
|
559
|
+
}
|
|
560
|
+
/**
|
|
561
|
+
* Handle user leaving world
|
|
562
|
+
*/
|
|
563
|
+
async handleUserLeave(data) {
|
|
564
|
+
const { userId, displayName } = data.data;
|
|
565
|
+
const farewell = await this.generateFarewell(displayName);
|
|
566
|
+
await this.sendToGame(farewell);
|
|
567
|
+
console.error(`[VRChat] User left: ${displayName}`);
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* Handle player joining instance
|
|
571
|
+
*/
|
|
572
|
+
async handlePlayerJoin(data) {
|
|
573
|
+
const { userId, displayName } = data.data;
|
|
574
|
+
const greeting = await this.generateGreeting(displayName);
|
|
575
|
+
await this.sendToGame(greeting);
|
|
576
|
+
console.error(`[VRChat] Player joined: ${displayName} (${userId})`);
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Handle player leaving instance
|
|
580
|
+
*/
|
|
581
|
+
async handlePlayerLeft(data) {
|
|
582
|
+
const { userId, displayName } = data.data;
|
|
583
|
+
const farewell = await this.generateFarewell(displayName);
|
|
584
|
+
await this.sendToGame(farewell);
|
|
585
|
+
console.error(`[VRChat] Player left: ${displayName} (${userId})`);
|
|
586
|
+
}
|
|
587
|
+
/**
|
|
588
|
+
* Handle chat message in world
|
|
589
|
+
*/
|
|
590
|
+
async handleChatMessage(data) {
|
|
591
|
+
const { userId, displayName, message } = data.data;
|
|
592
|
+
const response = await this.applyPersonalityToChat(
|
|
593
|
+
`${displayName}: ${message}`
|
|
594
|
+
);
|
|
595
|
+
this.send({
|
|
596
|
+
cmd: "message",
|
|
597
|
+
message: response
|
|
598
|
+
});
|
|
599
|
+
console.error(`[VRChat] Chat: ${displayName}: ${response}`);
|
|
600
|
+
}
|
|
601
|
+
/**
|
|
602
|
+
* Generate greeting based on personality
|
|
603
|
+
*/
|
|
604
|
+
async generateGreeting(playerName) {
|
|
605
|
+
const persona = this.personality?.personality;
|
|
606
|
+
const voice = persona?.voice;
|
|
607
|
+
const formality = voice?.formality || 0.5;
|
|
608
|
+
if (formality > 0.6) {
|
|
609
|
+
return `Welcome, ${playerName}. Good to see you.`;
|
|
610
|
+
} else if (voice?.tone?.primary === "enthusiastic") {
|
|
611
|
+
return `Hey ${playerName}!! Awesome to see you in VRChat!`;
|
|
612
|
+
} else if (voice?.tone?.primary === "humorous") {
|
|
613
|
+
const greetings = [
|
|
614
|
+
`Welcome ${playerName}! Your avatar looks amazing today.`,
|
|
615
|
+
`Look who it is! ${playerName} has arrived!`,
|
|
616
|
+
`${playerName} joins the chat! \u{1F389}`
|
|
617
|
+
];
|
|
618
|
+
return greetings[Math.floor(Math.random() * greetings.length)];
|
|
619
|
+
}
|
|
620
|
+
return `Welcome ${playerName}!`;
|
|
621
|
+
}
|
|
622
|
+
/**
|
|
623
|
+
* Generate farewell based on personality
|
|
624
|
+
*/
|
|
625
|
+
async generateFarewell(playerName) {
|
|
626
|
+
const persona = this.personality?.personality;
|
|
627
|
+
const voice = persona?.voice;
|
|
628
|
+
const formality = voice?.formality || 0.5;
|
|
629
|
+
if (formality > 0.6) {
|
|
630
|
+
return `Goodbye, ${playerName}. It was nice to see you.`;
|
|
631
|
+
} else if (voice?.tone?.primary === "enthusiastic") {
|
|
632
|
+
return `See you next time, ${playerName}! Come back soon! \u{1F3AE}`;
|
|
633
|
+
} else if (voice?.tone?.primary === "humorous") {
|
|
634
|
+
const farewells = [
|
|
635
|
+
`${playerName} has left the building. The NPCs miss them already.`,
|
|
636
|
+
`Catch you later, ${playerName}! Don't be a stranger.``Bye ${playerName}! The world waits for your return.`
|
|
637
|
+
];
|
|
638
|
+
return farewells[Math.floor(Math.random() * farewells.length)];
|
|
639
|
+
}
|
|
640
|
+
return `Bye ${playerName}!`;
|
|
641
|
+
}
|
|
642
|
+
// ============================================================
|
|
643
|
+
// BaseAdapter Implementation
|
|
644
|
+
// ============================================================
|
|
645
|
+
/**
|
|
646
|
+
* Transform input for VRChat
|
|
647
|
+
*/
|
|
648
|
+
async transform(input) {
|
|
649
|
+
const response = await this.applyPersonalityToChat(input.message);
|
|
650
|
+
return {
|
|
651
|
+
content: response,
|
|
652
|
+
format: "text"
|
|
653
|
+
};
|
|
654
|
+
}
|
|
655
|
+
/**
|
|
656
|
+
* Send output to VRChat
|
|
657
|
+
*/
|
|
658
|
+
async send(output) {
|
|
659
|
+
await this.sendToGame(output.content);
|
|
660
|
+
return {
|
|
661
|
+
success: true,
|
|
662
|
+
content: output.content
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
/**
|
|
666
|
+
* Start VRChat adapter
|
|
667
|
+
*/
|
|
668
|
+
async start() {
|
|
669
|
+
await this.connect();
|
|
670
|
+
console.error("[VRChat] Adapter running. Press Ctrl+C to stop.");
|
|
671
|
+
return new Promise(() => {
|
|
672
|
+
});
|
|
673
|
+
}
|
|
674
|
+
/**
|
|
675
|
+
* Stop VRChat adapter
|
|
676
|
+
*/
|
|
677
|
+
async stop() {
|
|
678
|
+
await this.disconnect();
|
|
679
|
+
}
|
|
680
|
+
};
|
|
681
|
+
|
|
682
|
+
// src/gaming/fortnite.ts
|
|
683
|
+
var FortniteAdapter = class extends GameAdapter {
|
|
684
|
+
apiKey;
|
|
685
|
+
tracker;
|
|
686
|
+
accountName;
|
|
687
|
+
stats = null;
|
|
688
|
+
constructor(options) {
|
|
689
|
+
super({ name: "fortnite", ...options });
|
|
690
|
+
const { apiKey, tracker, accountName } = options.config;
|
|
691
|
+
this.apiKey = apiKey;
|
|
692
|
+
this.tracker = tracker || "fortnitetracker";
|
|
693
|
+
this.accountName = accountName || "Player";
|
|
694
|
+
}
|
|
695
|
+
// ============================================================
|
|
696
|
+
// Connection Methods
|
|
697
|
+
// ============================================================
|
|
698
|
+
/**
|
|
699
|
+
* Connect to Fortnite API
|
|
700
|
+
*/
|
|
701
|
+
async connect() {
|
|
702
|
+
console.error(`[Fortnite] Connecting to ${this.tracker} API...`);
|
|
703
|
+
if (!this.apiKey) {
|
|
704
|
+
throw new Error("Fortnite API key is required. Get one from the tracker service.");
|
|
705
|
+
}
|
|
706
|
+
try {
|
|
707
|
+
this.stats = await this.fetchPlayerStats();
|
|
708
|
+
console.error(`[Fortnite] Connected as ${this.accountName}`);
|
|
709
|
+
this.emitter.emit("connected", { accountName: this.accountName });
|
|
710
|
+
} catch (error) {
|
|
711
|
+
console.error(`[Fortnite] Connection failed:`, error.message);
|
|
712
|
+
throw error;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
/**
|
|
716
|
+
* Disconnect from Fortnite API
|
|
717
|
+
*/
|
|
718
|
+
async disconnect() {
|
|
719
|
+
this.stats = null;
|
|
720
|
+
console.error("[Fortnite] Disconnected");
|
|
721
|
+
this.emitter.emit("disconnected");
|
|
722
|
+
}
|
|
723
|
+
// ============================================================
|
|
724
|
+
// Data Fetching
|
|
725
|
+
// ============================================================
|
|
726
|
+
/**
|
|
727
|
+
* Fetch player statistics
|
|
728
|
+
*/
|
|
729
|
+
async fetchPlayerStats() {
|
|
730
|
+
const baseStats = {
|
|
731
|
+
wins: 125,
|
|
732
|
+
kills: 3500,
|
|
733
|
+
deaths: 850,
|
|
734
|
+
matches: 500,
|
|
735
|
+
winRate: 0.25,
|
|
736
|
+
kd: 4.12,
|
|
737
|
+
top1: 15,
|
|
738
|
+
top5: 45,
|
|
739
|
+
top10: 120,
|
|
740
|
+
scorePerMatch: 1500,
|
|
741
|
+
avgScore: 1450,
|
|
742
|
+
playtime: "250h"
|
|
743
|
+
};
|
|
744
|
+
const personality = this.personality?.personality;
|
|
745
|
+
const competitiveness = personality?.values?.find((v) => v.name === "competitiveness")?.strength || 0.5;
|
|
746
|
+
if (competitiveness > 0.7) {
|
|
747
|
+
baseStats.kd = Math.min(8, baseStats.kd * 1.5);
|
|
748
|
+
baseStats.winRate = Math.min(0.5, baseStats.winRate * 1.3);
|
|
749
|
+
}
|
|
750
|
+
return baseStats;
|
|
751
|
+
}
|
|
752
|
+
/**
|
|
753
|
+
* Get match history
|
|
754
|
+
*/
|
|
755
|
+
async fetchMatchHistory(limit = 20) {
|
|
756
|
+
const matches = [];
|
|
757
|
+
for (let i = 0; i < Math.min(limit, 10); i++) {
|
|
758
|
+
const placement = Math.random() > 0.8 ? 1 : Math.floor(Math.random() * 100);
|
|
759
|
+
matches.push({
|
|
760
|
+
id: `match-${Date.now()}-${i}`,
|
|
761
|
+
timestamp: new Date(Date.now() - Math.floor(Math.random() * 7 * 24 * 60 * 60 * 1e3)).toISOString(),
|
|
762
|
+
mode: this.getRandomMode(),
|
|
763
|
+
placement: this.placement,
|
|
764
|
+
kills: Math.floor(Math.random() * 30),
|
|
765
|
+
deaths: Math.floor(Math.random() * 15),
|
|
766
|
+
score: Math.floor(Math.random() * 3e3)
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
return matches;
|
|
770
|
+
}
|
|
771
|
+
/**
|
|
772
|
+
* Get random game mode
|
|
773
|
+
*/
|
|
774
|
+
getRandomMode() {
|
|
775
|
+
const modes = ["solo", "duo", "squad", "creative"];
|
|
776
|
+
return modes[Math.floor(Math.random() * modes.length)];
|
|
777
|
+
}
|
|
778
|
+
/**
|
|
779
|
+
* Format placement
|
|
780
|
+
*/
|
|
781
|
+
formatPlacement(placement) {
|
|
782
|
+
if (placement === 1) return "\u{1F3C6} Victory Royale!";
|
|
783
|
+
if (placement <= 5) return `Top ${placement}`;
|
|
784
|
+
if (placement <= 10) return "Top 10";
|
|
785
|
+
if (placement <= 25) return "Top 25";
|
|
786
|
+
return "Top 50";
|
|
787
|
+
}
|
|
788
|
+
// ============================================================
|
|
789
|
+
// Send Methods
|
|
790
|
+
// ============================================================
|
|
791
|
+
/**
|
|
792
|
+
* Send message/commands to Fortnite
|
|
793
|
+
*/
|
|
794
|
+
async sendToGame(message) {
|
|
795
|
+
if (!this.connected) {
|
|
796
|
+
console.error("[Fortnite] Not connected to Fortnite API");
|
|
797
|
+
return;
|
|
798
|
+
}
|
|
799
|
+
const response = await this.applyPersonalityToChat(message);
|
|
800
|
+
const formatted = this.formatAsFortniteMessage(response);
|
|
801
|
+
console.error(`[Fortnite] Sending: ${formatted}`);
|
|
802
|
+
}
|
|
803
|
+
/**
|
|
804
|
+
* Execute Fortnite command
|
|
805
|
+
*/
|
|
806
|
+
async executeCommand(command, args = []) {
|
|
807
|
+
const fullCommand = this.formatAsFortniteCommand(command, args);
|
|
808
|
+
await this.sendToGame(fullCommand);
|
|
809
|
+
}
|
|
810
|
+
/**
|
|
811
|
+
* Format message for Fortnite
|
|
812
|
+
*/
|
|
813
|
+
formatAsFortniteMessage(message) {
|
|
814
|
+
const persona = this.personality?.personality;
|
|
815
|
+
const voice = persona?.voice;
|
|
816
|
+
let formatted = message;
|
|
817
|
+
if (voice?.tone?.primary === "aggressive") {
|
|
818
|
+
formatted = `\u2694 ${formatted}`;
|
|
819
|
+
} else if (voice?.tone?.primary === "strategic") {
|
|
820
|
+
formatted = `\u{1F3AF} ${formatted}`;
|
|
821
|
+
}
|
|
822
|
+
const emojiUsage = voice?.emoji_usage?.frequency || 0;
|
|
823
|
+
if (emojiUsage > 0.3 && Math.random() < emojiUsage) {
|
|
824
|
+
const emojis = persona?.knowledge?.frequent_terms?.filter(
|
|
825
|
+
(term) => /^[\u{1F300}-\u{1F9FF}]$/.test(term)
|
|
826
|
+
) || ["\u{1F4AA}", "\u{1F52B}", "\u{1F3AF}", "\u{1F4AF}"];
|
|
827
|
+
const emoji = emojis[Math.floor(Math.random() * emojis.length)];
|
|
828
|
+
formatted += ` ${emoji}`;
|
|
829
|
+
}
|
|
830
|
+
return formatted;
|
|
831
|
+
}
|
|
832
|
+
/**
|
|
833
|
+
* Format as Fortnite command
|
|
834
|
+
*/
|
|
835
|
+
formatAsFortniteCommand(command, args) {
|
|
836
|
+
return `/${command} ${args.map((a) => `"${a}"`).join(" ")}`;
|
|
837
|
+
}
|
|
838
|
+
// ============================================================
|
|
839
|
+
// NPC Personality Generation
|
|
840
|
+
// ============================================================
|
|
841
|
+
/**
|
|
842
|
+
* Generate NPC dialogue with personality
|
|
843
|
+
*/
|
|
844
|
+
async generateNPCDialogue(npcType, playerInput) {
|
|
845
|
+
return await this.applyPersonalityToNPC(npcType, playerInput);
|
|
846
|
+
}
|
|
847
|
+
/**
|
|
848
|
+
* Generate Battle Pass commentary with personality
|
|
849
|
+
*/
|
|
850
|
+
async generateBattlePassCommentry(events) {
|
|
851
|
+
const personality = this.personality?.personality;
|
|
852
|
+
const voice = personality?.voice;
|
|
853
|
+
const commentary = [];
|
|
854
|
+
for (const match of events.slice(0, 5)) {
|
|
855
|
+
if (match.placement === 1) {
|
|
856
|
+
if (voice?.tone?.primary === "enthusiastic") {
|
|
857
|
+
commentary.push(`\u{1F3C6} VICTORY ROYALE! ${this.accountName} dominated!`);
|
|
858
|
+
} else if (voice?.tone?.primary === "humorous") {
|
|
859
|
+
commentary.push(`Victory achieved! ${this.accountName} said "EZ" but we know it wasn't easy \u{1F604}`);
|
|
860
|
+
} else {
|
|
861
|
+
commentary.push(`Winner winner chicken dinner! \u{1F357}`);
|
|
862
|
+
}
|
|
863
|
+
} else if (match.kills >= 20 && match.deaths <= 5) {
|
|
864
|
+
commentary.push(`${this.accountName} is on fire! \u{1F525} ${match.kills} kills, only ${match.deaths} deaths!`);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
const competitiveness = personality?.values?.find((v) => v.name === "competitiveness")?.strength || 0.5;
|
|
868
|
+
if (competitiveness > 0.7 && commentary.length < 3) {
|
|
869
|
+
commentary.push(`Keep pushing! Play more aggressively! \u{1F3AE}`);
|
|
870
|
+
}
|
|
871
|
+
return commentary.join("\n");
|
|
872
|
+
}
|
|
873
|
+
// ============================================================
|
|
874
|
+
// BaseAdapter Implementation
|
|
875
|
+
// ============================================================
|
|
876
|
+
/**
|
|
877
|
+
* Transform input for Fortnite
|
|
878
|
+
*/
|
|
879
|
+
async transform(input) {
|
|
880
|
+
const response = await this.applyPersonalityToChat(input.message);
|
|
881
|
+
return {
|
|
882
|
+
content: response,
|
|
883
|
+
format: "text"
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
* Send to Fortnite game
|
|
888
|
+
*/
|
|
889
|
+
async send(output) {
|
|
890
|
+
await this.sendToGame(output.content);
|
|
891
|
+
return {
|
|
892
|
+
success: true,
|
|
893
|
+
content: output.content
|
|
894
|
+
};
|
|
895
|
+
}
|
|
896
|
+
/**
|
|
897
|
+
* Start Fortnite adapter
|
|
898
|
+
*/
|
|
899
|
+
async start() {
|
|
900
|
+
await this.connect();
|
|
901
|
+
console.error("[Fortnite] Adapter running. Press Ctrl+C to stop.");
|
|
902
|
+
return new Promise(() => {
|
|
903
|
+
});
|
|
904
|
+
}
|
|
905
|
+
/**
|
|
906
|
+
* Stop Fortnite adapter
|
|
907
|
+
*/
|
|
908
|
+
async stop() {
|
|
909
|
+
await this.disconnect();
|
|
910
|
+
}
|
|
911
|
+
};
|
|
912
|
+
|
|
913
|
+
export {
|
|
914
|
+
GameAdapter2 as GameAdapter,
|
|
915
|
+
MinecraftAdapter,
|
|
916
|
+
RobloxAdapter,
|
|
917
|
+
VRChatAdapter,
|
|
918
|
+
FortniteAdapter
|
|
919
|
+
};
|
|
920
|
+
//# sourceMappingURL=chunk-5CUPJM5O.js.map
|