File size: 10,571 Bytes
bc89546
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0fe7384
bc89546
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0fe7384
bc89546
0fe7384
bc89546
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <style>
    * { margin: 0; padding: 0; box-sizing: border-box; }
    body {
      background: transparent;
      display: flex;
      justify-content: center;
      align-items: center;
      width: 100vw;
      height: 100vh;
      font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
      padding: 0;
      overflow: hidden;
    }
    
    .api-window {
      background: linear-gradient(135deg, #1e1e1e 0%, #252526 100%);
      border-radius: 16px;
      padding: 20px;
      width: 480px;
      height: 460px;
      box-shadow: 0 10px 40px rgba(0,0,0,0.3);
      overflow: hidden;
      position: relative;
    }

    .api-header {
      color: #888;
      font-size: 11px;
      margin-bottom: 12px;
      padding-bottom: 8px;
      border-bottom: 1px solid #333;
    }

    .direction-label {
      font-size: 10px;
      margin-bottom: 10px;
      padding: 4px 8px;
      border-radius: 4px;
      display: inline-block;
    }
    .to-server { background: #0b93f620; color: #0b93f6; }
    .to-client { background: #f5a62320; color: #f5a623; }

    .single-message {
      position: absolute;
      top: 80px;
      left: 20px;
      right: 20px;
      opacity: 0;
      transform: scale(0.95);
    }

    .single-message.show {
      animation: popIn 0.3s ease forwards;
    }

    .single-message.fade-out {
      animation: popOut 0.25s ease forwards;
    }

    .msg-box {
      padding: 16px;
      border-radius: 10px;
      font-size: 11px;
      line-height: 1.5;
      color: #d4d4d4;
    }

    .client-msg .msg-box {
      background: linear-gradient(135deg, #0b93f615 0%, #007AFF15 100%);
      border: 1px solid #0b93f640;
    }

    .server-msg .msg-box {
      background: linear-gradient(135deg, #f5a62315 0%, #f0981915 100%);
      border: 1px solid #f5a62340;
    }

    .json-brace { color: #d4d4d4; }
    .json-key { color: #9cdcfe; }
    .json-string { color: #ce9178; }
    .json-bool { color: #569cd6; }

    .state-indicator {
      position: absolute;
      bottom: 20px;
      left: 20px;
      right: 20px;
      padding: 12px;
      background: #2d2d3a;
      border-radius: 8px;
      font-size: 10px;
      color: #888;
      opacity: 0;
    }

    .state-indicator.show {
      animation: fadeIn 0.3s ease forwards;
    }
    .state-indicator.fade-out {
      animation: fadeOut 0.5s ease forwards;
    }

    .state-indicator .label {
      color: #f5a623;
      font-weight: 600;
      margin-bottom: 4px;
    }

    .state-dots {
      display: flex;
      gap: 6px;
      margin-top: 8px;
    }

    .state-dot {
      width: 8px;
      height: 8px;
      border-radius: 50%;
      background: #444;
    }
    .state-dot.active { background: #f5a623; }

    @keyframes popIn {
      from { opacity: 0; transform: scale(0.95); }
      to { opacity: 1; transform: scale(1); }
    }

    @keyframes popOut {
      from { opacity: 1; transform: scale(1); }
      to { opacity: 0; transform: scale(0.95); }
    }

    @keyframes fadeIn {
      from { opacity: 0; }
      to { opacity: 1; }
    }

    @keyframes fadeOut {
      from { opacity: 1; }
      to { opacity: 0; }
    }
  </style>
</head>
<body>
  <div class="api-window canvas-root">
    <div class="api-header">Current: Individual Messages (Stateful)</div>

    <!-- Message 1: CallToolRequest -->
    <div class="single-message client-msg" id="msg1">
      <div class="direction-label to-server">→ Client to Server</div>
      <div class="msg-box">
        <span class="json-brace">{</span><br>
        &nbsp;&nbsp;<span class="json-key">"method"</span>: <span class="json-string">"tools/call"</span>,<br>
        &nbsp;&nbsp;<span class="json-key">"params"</span>: <span class="json-brace">{</span><br>
        &nbsp;&nbsp;&nbsp;&nbsp;<span class="json-key">"name"</span>: <span class="json-string">"deploy_app"</span>,<br>
        &nbsp;&nbsp;&nbsp;&nbsp;<span class="json-key">"env"</span>: <span class="json-string">"production"</span><br>
        &nbsp;&nbsp;<span class="json-brace">}</span><br>
        <span class="json-brace">}</span>
      </div>
    </div>

    <!-- Message 2: ElicitationRequest -->
    <div class="single-message server-msg" id="msg2">
      <div class="direction-label to-client">← Server to Client</div>
      <div class="msg-box">
        <span class="json-brace">{</span><br>
        &nbsp;&nbsp;<span class="json-key">"method"</span>: <span class="json-string">"elicitation/create"</span>,<br>
        &nbsp;&nbsp;<span class="json-key">"params"</span>: <span class="json-brace">{</span><br>
        &nbsp;&nbsp;&nbsp;&nbsp;<span class="json-key">"message"</span>: <span class="json-string">"Confirm deployment to production?"</span><br>
        &nbsp;&nbsp;<span class="json-brace">}</span><br>
        <span class="json-brace">}</span>
      </div>
    </div>

    <!-- Message 3: ElicitationResponse -->
    <div class="single-message client-msg" id="msg3">
      <div class="direction-label to-server">→ Client to Server</div>
      <div class="msg-box">
        <span class="json-brace">{</span><br>
        &nbsp;&nbsp;<span class="json-key">"result"</span>: <span class="json-brace">{</span><br>
        &nbsp;&nbsp;&nbsp;&nbsp;<span class="json-key">"confirmed"</span>: <span class="json-bool">true</span><br>
        &nbsp;&nbsp;<span class="json-brace">}</span><br>
        <span class="json-brace">}</span>
      </div>
    </div>

    <!-- Message 4: SamplingRequest -->
    <div class="single-message server-msg" id="msg4">
      <div class="direction-label to-client">← Server to Client</div>
      <div class="msg-box">
        <span class="json-brace">{</span><br>
        &nbsp;&nbsp;<span class="json-key">"method"</span>: <span class="json-string">"sampling/createMessage"</span>,<br>
        &nbsp;&nbsp;<span class="json-key">"params"</span>: <span class="json-brace">{</span><br>
        &nbsp;&nbsp;&nbsp;&nbsp;<span class="json-key">"prompt"</span>: <span class="json-string">"Generate deployment summary"</span><br>
        &nbsp;&nbsp;<span class="json-brace">}</span><br>
        <span class="json-brace">}</span>
      </div>
    </div>

    <!-- Message 5: SamplingResponse -->
    <div class="single-message client-msg" id="msg5">
      <div class="direction-label to-server">→ Client to Server</div>
      <div class="msg-box">
        <span class="json-brace">{</span><br>
        &nbsp;&nbsp;<span class="json-key">"result"</span>: <span class="json-brace">{</span><br>
        &nbsp;&nbsp;&nbsp;&nbsp;<span class="json-key">"content"</span>: <span class="json-string">"Deployed v2.1.0 to prod..."</span><br>
        &nbsp;&nbsp;<span class="json-brace">}</span><br>
        <span class="json-brace">}</span>
      </div>
    </div>

    <!-- Message 6: CallToolResult -->
    <div class="single-message server-msg" id="msg6">
      <div class="direction-label to-client">← Server to Client</div>
      <div class="msg-box">
        <span class="json-brace">{</span><br>
        &nbsp;&nbsp;<span class="json-key">"result"</span>: <span class="json-brace">{</span><br>
        &nbsp;&nbsp;&nbsp;&nbsp;<span class="json-key">"status"</span>: <span class="json-string">"success"</span><br>
        &nbsp;&nbsp;<span class="json-brace">}</span><br>
        <span class="json-brace">}</span>
      </div>
    </div>

    <!-- State indicator -->
    <div class="state-indicator" id="stateBox">
      <div class="label">⚠ Server must maintain state</div>
      <div>Remembering: tool call, elicitation, sampling context...</div>
      <div class="state-dots">
        <div class="state-dot" id="dot1"></div>
        <div class="state-dot" id="dot2"></div>
        <div class="state-dot" id="dot3"></div>
        <div class="state-dot" id="dot4"></div>
        <div class="state-dot" id="dot5"></div>
        <div class="state-dot" id="dot6"></div>
      </div>
    </div>
  </div>

  <script src="shared/canvas-scale.js"></script>
  <script>
    const messages = [
      document.getElementById('msg1'),
      document.getElementById('msg2'),
      document.getElementById('msg3'),
      document.getElementById('msg4'),
      document.getElementById('msg5'),
      document.getElementById('msg6')
    ];
    const dots = [
      document.getElementById('dot1'),
      document.getElementById('dot2'),
      document.getElementById('dot3'),
      document.getElementById('dot4'),
      document.getElementById('dot5'),
      document.getElementById('dot6')
    ];
    const stateBox = document.getElementById('stateBox');
    const CYCLE_PAUSE = 1200;
    const MSG_DURATION = 2500;

    let timers = [];
    let runId = 0;

    function clearTimers() {
      timers.forEach((id) => clearTimeout(id));
      timers = [];
    }

    function schedule(fn, delay) {
      const id = setTimeout(fn, delay);
      timers.push(id);
      return id;
    }

    function runAnimation(activeRunId) {
      if (activeRunId !== runId) {
        return;
      }

      // Reset
      messages.forEach((m) => m.classList.remove('show', 'fade-out'));
      dots.forEach((d) => d.classList.remove('active'));
      stateBox.classList.remove('show', 'fade-out');

      // Force reflow to ensure class removal is processed
      void document.body.offsetHeight;

      // Show state box
      schedule(() => {
        if (activeRunId !== runId) return;
        stateBox.classList.add('show');
      }, 200);

      // Show each message one at a time
      messages.forEach((msg, i) => {
        const showTime = i * MSG_DURATION;

        schedule(() => {
          if (activeRunId !== runId) return;

          // Hide previous
          if (i > 0) messages[i - 1].classList.add('fade-out');
          // Show current
          msg.classList.add('show');
          // Activate dot
          dots[i].classList.add('active');
        }, showTime);
      });

      // Keep last message visible briefly, then restart.
      const totalTime = messages.length * MSG_DURATION;
      schedule(() => runAnimation(activeRunId), totalTime + CYCLE_PAUSE);
    }

    function startAnimation() {
      runId++;
      clearTimers();
      schedule(() => runAnimation(runId), 500);
    }

    if (document.readyState === 'complete') {
      startAnimation();
    } else {
      window.addEventListener('load', startAnimation, { once: true });
    }

    // Restart only on bfcache restore.
    window.addEventListener('pageshow', (event) => {
      if (event.persisted) {
        startAnimation();
      }
    });

    scaleCanvas();
  </script>
</body>
</html>