File size: 4,823 Bytes
2f6a09b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6d3ffa2
2f6a09b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
function createLoadingIndicator() {
  const loadingDiv = document.createElement("div");
  loadingDiv.className = "chat-message assistant-message";
  loadingDiv.innerHTML = `
                <div class="loading-dots">
                    <div class="dot"></div>
                    <div class="dot"></div>
                    <div class="dot"></div>
                </div>
            `;
  return loadingDiv;
}

async function addProgramaticMessage(message) {
  const chatHistory = document.getElementById("chatHistory");
  const loadingIndicator = createLoadingIndicator();
  chatHistory.appendChild(loadingIndicator);
  await new Promise(resolve => setTimeout(resolve, 2000));
  chatHistory.removeChild(loadingIndicator);
  addMessageToChat("assistant", message);
}

async function strongIndependantWoman(){
  
    const chatHistory = document.getElementById("chatHistory");
    const loadingIndicator = createLoadingIndicator();
    chatHistory.appendChild(loadingIndicator);
    chatHistory.scrollTop = chatHistory.scrollHeight;

  
    let masterPrompt = gameState.getPrompt();

    const recentMessages = chatMessages.slice(-5);
  
    const messages = [
      { role: "system", content: masterPrompt },
      ...recentMessages,
      { role: "user", content: `
        **your boyfriend has been away from his phone for a while and has not replied promptly to your last message, 
        you shall based on all that you know decide to take an action, also you're pissed at the boyfriend**
        you are brave, strong, fabulous and will do something about this situation
        you're gall is to escape the house and avoid the clown at all costs
        
        ` },
    ];
  
    const assistantResponse = await mistralAPI.sendMessage(messages);
  
    chatHistory.removeChild(loadingIndicator);
  
    const jsonStart = assistantResponse.indexOf("{");
    const jsonEnd = assistantResponse.lastIndexOf("}") + 1;
    const jsonContent = assistantResponse.substring(jsonStart, jsonEnd);
    const jsonResponse = JSON.parse(jsonContent);
  
    if (jsonResponse.action) {
      girlfriend.handleAction(jsonResponse, true);
    }
  
    if (jsonResponse.textMessage) {
      addMessageToChat("assistant", jsonResponse.textMessage);
    }
}

async function sendMessage() {
  const prompt = document.getElementById("prompt").value.trim();
  if (!prompt) return;

  addMessageToChat("user", prompt);
  document.getElementById("prompt").value = "";

  const chatHistory = document.getElementById("chatHistory");
  const loadingIndicator = createLoadingIndicator();
  chatHistory.appendChild(loadingIndicator);
  chatHistory.scrollTop = chatHistory.scrollHeight;


  // First, get the stress prompt and send it
  const stressPrompt = gameState.getStressPrompt();
  const stressMessages = [
    {
      role: "system",
      content: stressPrompt,
    },
    { role: "user", content: prompt },
  ];

  const stressResponse = await mistralAPI.sendMessage(stressMessages);
  const stressChange = JSON.parse(stressResponse).stressChange || 0;

  girlfriend.updateStressLevel(stressChange);
 

  let masterPrompt = gameState.getPrompt();
  const recentMessages = chatMessages.slice(-5);

  const messages = [
    { role: "system", content: masterPrompt },
    ...recentMessages,
    { role: "user", content: prompt },
  ];

  const assistantResponse = await mistralAPI.sendMessage(messages);

  chatHistory.removeChild(loadingIndicator);

  const jsonStart = assistantResponse.indexOf("{");
  const jsonEnd = assistantResponse.lastIndexOf("}") + 1;
  const jsonContent = assistantResponse.substring(jsonStart, jsonEnd);
  const jsonResponse = JSON.parse(jsonContent);

  if (jsonResponse.action) {
    girlfriend.handleAction(jsonResponse, true);
  }

  if (jsonResponse.textMessage) {
    addMessageToChat("assistant", jsonResponse.textMessage);
  }
}

function addMessageToChat(role, content) {
  const chatHistory = document.getElementById("chatHistory");
  const messageDiv = document.createElement("div");
  messageDiv.className = `chat-message ${role}-message`;
  messageDiv.textContent = content;
  chatHistory.appendChild(messageDiv);
  chatHistory.scrollTop = chatHistory.scrollHeight;

  chatMessages.push({ role, content });

  if (role === "assistant" && localStorage.getItem("isSoundOn") !== "false") {
    playSound('message');
  }
}


// Allow sending message with Enter
document.addEventListener("DOMContentLoaded", () => {
  document.getElementById("prompt").addEventListener("keypress", function (e) {
    if (e.key === "Enter") {
      e.preventDefault();
      sendMessage();
    }
  });

  try {
    const bgMusic = document.getElementById("bgMusic");
    bgMusic.currentTime = 10;
    bgMusic.play().catch((error) => {
      isSoundOn = false;
      updateSoundIcon();
    });
  } catch (error) {
  }
});