@agent-link/server 0.1.122 → 0.1.124
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/package.json +54 -54
- package/web/app.js +1192 -1192
- package/web/favicon.svg +10 -10
- package/web/landing.html +1241 -1237
- package/web/modules/connection.js +880 -880
- package/web/modules/fileBrowser.js +379 -379
- package/web/modules/filePreview.js +187 -187
- package/web/modules/sidebar.js +376 -376
- package/web/modules/streaming.js +110 -110
- package/web/style.css +2941 -2941
package/web/modules/streaming.js
CHANGED
|
@@ -1,110 +1,110 @@
|
|
|
1
|
-
// ── Progressive text streaming / reveal animation ────────────────────────────
|
|
2
|
-
|
|
3
|
-
const CHARS_PER_TICK = 5;
|
|
4
|
-
const TICK_MS = 16;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Creates a streaming text reveal controller.
|
|
8
|
-
* @param {object} deps
|
|
9
|
-
* @param {import('vue').Ref} deps.messages - messages ref array
|
|
10
|
-
* @param {() => void} deps.scrollToBottom - scroll callback
|
|
11
|
-
*/
|
|
12
|
-
export function createStreaming({ messages, scrollToBottom }) {
|
|
13
|
-
let pendingText = '';
|
|
14
|
-
let revealTimer = null;
|
|
15
|
-
let streamingMessageId = null;
|
|
16
|
-
let messageIdCounter = 0;
|
|
17
|
-
|
|
18
|
-
function getMessageIdCounter() { return messageIdCounter; }
|
|
19
|
-
function setMessageIdCounter(v) { messageIdCounter = v; }
|
|
20
|
-
function getStreamingMessageId() { return streamingMessageId; }
|
|
21
|
-
function setStreamingMessageId(v) { streamingMessageId = v; }
|
|
22
|
-
function nextId() { return ++messageIdCounter; }
|
|
23
|
-
|
|
24
|
-
function startReveal() {
|
|
25
|
-
if (revealTimer !== null) return;
|
|
26
|
-
revealTimer = setTimeout(revealTick, TICK_MS);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function revealTick() {
|
|
30
|
-
revealTimer = null;
|
|
31
|
-
if (!pendingText) return;
|
|
32
|
-
|
|
33
|
-
const streamMsg = streamingMessageId !== null
|
|
34
|
-
? messages.value.find(m => m.id === streamingMessageId)
|
|
35
|
-
: null;
|
|
36
|
-
|
|
37
|
-
if (!streamMsg) {
|
|
38
|
-
const id = ++messageIdCounter;
|
|
39
|
-
const chunk = pendingText.slice(0, CHARS_PER_TICK);
|
|
40
|
-
pendingText = pendingText.slice(CHARS_PER_TICK);
|
|
41
|
-
messages.value.push({
|
|
42
|
-
id, role: 'assistant', content: chunk,
|
|
43
|
-
isStreaming: true, timestamp: new Date(),
|
|
44
|
-
});
|
|
45
|
-
streamingMessageId = id;
|
|
46
|
-
} else {
|
|
47
|
-
const chunk = pendingText.slice(0, CHARS_PER_TICK);
|
|
48
|
-
pendingText = pendingText.slice(CHARS_PER_TICK);
|
|
49
|
-
streamMsg.content += chunk;
|
|
50
|
-
}
|
|
51
|
-
scrollToBottom();
|
|
52
|
-
if (pendingText) revealTimer = setTimeout(revealTick, TICK_MS);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function flushReveal() {
|
|
56
|
-
if (revealTimer !== null) { clearTimeout(revealTimer); revealTimer = null; }
|
|
57
|
-
if (!pendingText) return;
|
|
58
|
-
const streamMsg = streamingMessageId !== null
|
|
59
|
-
? messages.value.find(m => m.id === streamingMessageId) : null;
|
|
60
|
-
if (streamMsg) {
|
|
61
|
-
streamMsg.content += pendingText;
|
|
62
|
-
} else {
|
|
63
|
-
const id = ++messageIdCounter;
|
|
64
|
-
messages.value.push({
|
|
65
|
-
id, role: 'assistant', content: pendingText,
|
|
66
|
-
isStreaming: true, timestamp: new Date(),
|
|
67
|
-
});
|
|
68
|
-
streamingMessageId = id;
|
|
69
|
-
}
|
|
70
|
-
pendingText = '';
|
|
71
|
-
scrollToBottom();
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function appendPending(text) {
|
|
75
|
-
pendingText += text;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function reset() {
|
|
79
|
-
pendingText = '';
|
|
80
|
-
if (revealTimer !== null) { clearTimeout(revealTimer); revealTimer = null; }
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function cleanup() {
|
|
84
|
-
if (revealTimer !== null) { clearTimeout(revealTimer); revealTimer = null; }
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
function saveState() {
|
|
88
|
-
flushReveal(); // flush pending text into the message before saving
|
|
89
|
-
return {
|
|
90
|
-
pendingText: '',
|
|
91
|
-
streamingMessageId,
|
|
92
|
-
messageIdCounter,
|
|
93
|
-
};
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
function restoreState(saved) {
|
|
97
|
-
flushReveal(); // clear any current pending
|
|
98
|
-
pendingText = saved.pendingText || '';
|
|
99
|
-
streamingMessageId = saved.streamingMessageId ?? null;
|
|
100
|
-
messageIdCounter = saved.messageIdCounter || 0;
|
|
101
|
-
if (pendingText) startReveal();
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
return {
|
|
105
|
-
startReveal, flushReveal, appendPending, reset, cleanup,
|
|
106
|
-
getMessageIdCounter, setMessageIdCounter,
|
|
107
|
-
getStreamingMessageId, setStreamingMessageId,
|
|
108
|
-
nextId, saveState, restoreState,
|
|
109
|
-
};
|
|
110
|
-
}
|
|
1
|
+
// ── Progressive text streaming / reveal animation ────────────────────────────
|
|
2
|
+
|
|
3
|
+
const CHARS_PER_TICK = 5;
|
|
4
|
+
const TICK_MS = 16;
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Creates a streaming text reveal controller.
|
|
8
|
+
* @param {object} deps
|
|
9
|
+
* @param {import('vue').Ref} deps.messages - messages ref array
|
|
10
|
+
* @param {() => void} deps.scrollToBottom - scroll callback
|
|
11
|
+
*/
|
|
12
|
+
export function createStreaming({ messages, scrollToBottom }) {
|
|
13
|
+
let pendingText = '';
|
|
14
|
+
let revealTimer = null;
|
|
15
|
+
let streamingMessageId = null;
|
|
16
|
+
let messageIdCounter = 0;
|
|
17
|
+
|
|
18
|
+
function getMessageIdCounter() { return messageIdCounter; }
|
|
19
|
+
function setMessageIdCounter(v) { messageIdCounter = v; }
|
|
20
|
+
function getStreamingMessageId() { return streamingMessageId; }
|
|
21
|
+
function setStreamingMessageId(v) { streamingMessageId = v; }
|
|
22
|
+
function nextId() { return ++messageIdCounter; }
|
|
23
|
+
|
|
24
|
+
function startReveal() {
|
|
25
|
+
if (revealTimer !== null) return;
|
|
26
|
+
revealTimer = setTimeout(revealTick, TICK_MS);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function revealTick() {
|
|
30
|
+
revealTimer = null;
|
|
31
|
+
if (!pendingText) return;
|
|
32
|
+
|
|
33
|
+
const streamMsg = streamingMessageId !== null
|
|
34
|
+
? messages.value.find(m => m.id === streamingMessageId)
|
|
35
|
+
: null;
|
|
36
|
+
|
|
37
|
+
if (!streamMsg) {
|
|
38
|
+
const id = ++messageIdCounter;
|
|
39
|
+
const chunk = pendingText.slice(0, CHARS_PER_TICK);
|
|
40
|
+
pendingText = pendingText.slice(CHARS_PER_TICK);
|
|
41
|
+
messages.value.push({
|
|
42
|
+
id, role: 'assistant', content: chunk,
|
|
43
|
+
isStreaming: true, timestamp: new Date(),
|
|
44
|
+
});
|
|
45
|
+
streamingMessageId = id;
|
|
46
|
+
} else {
|
|
47
|
+
const chunk = pendingText.slice(0, CHARS_PER_TICK);
|
|
48
|
+
pendingText = pendingText.slice(CHARS_PER_TICK);
|
|
49
|
+
streamMsg.content += chunk;
|
|
50
|
+
}
|
|
51
|
+
scrollToBottom();
|
|
52
|
+
if (pendingText) revealTimer = setTimeout(revealTick, TICK_MS);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function flushReveal() {
|
|
56
|
+
if (revealTimer !== null) { clearTimeout(revealTimer); revealTimer = null; }
|
|
57
|
+
if (!pendingText) return;
|
|
58
|
+
const streamMsg = streamingMessageId !== null
|
|
59
|
+
? messages.value.find(m => m.id === streamingMessageId) : null;
|
|
60
|
+
if (streamMsg) {
|
|
61
|
+
streamMsg.content += pendingText;
|
|
62
|
+
} else {
|
|
63
|
+
const id = ++messageIdCounter;
|
|
64
|
+
messages.value.push({
|
|
65
|
+
id, role: 'assistant', content: pendingText,
|
|
66
|
+
isStreaming: true, timestamp: new Date(),
|
|
67
|
+
});
|
|
68
|
+
streamingMessageId = id;
|
|
69
|
+
}
|
|
70
|
+
pendingText = '';
|
|
71
|
+
scrollToBottom();
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function appendPending(text) {
|
|
75
|
+
pendingText += text;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function reset() {
|
|
79
|
+
pendingText = '';
|
|
80
|
+
if (revealTimer !== null) { clearTimeout(revealTimer); revealTimer = null; }
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function cleanup() {
|
|
84
|
+
if (revealTimer !== null) { clearTimeout(revealTimer); revealTimer = null; }
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function saveState() {
|
|
88
|
+
flushReveal(); // flush pending text into the message before saving
|
|
89
|
+
return {
|
|
90
|
+
pendingText: '',
|
|
91
|
+
streamingMessageId,
|
|
92
|
+
messageIdCounter,
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function restoreState(saved) {
|
|
97
|
+
flushReveal(); // clear any current pending
|
|
98
|
+
pendingText = saved.pendingText || '';
|
|
99
|
+
streamingMessageId = saved.streamingMessageId ?? null;
|
|
100
|
+
messageIdCounter = saved.messageIdCounter || 0;
|
|
101
|
+
if (pendingText) startReveal();
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return {
|
|
105
|
+
startReveal, flushReveal, appendPending, reset, cleanup,
|
|
106
|
+
getMessageIdCounter, setMessageIdCounter,
|
|
107
|
+
getStreamingMessageId, setStreamingMessageId,
|
|
108
|
+
nextId, saveState, restoreState,
|
|
109
|
+
};
|
|
110
|
+
}
|