psionic 0.3.2 → 0.3.3
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/adapters/reconnect.d.mts +10 -0
- package/adapters/reconnect.mjs +2 -0
- package/adapters/reconnect.mjs.map +1 -0
- package/adapters/resend.d.mts +13 -0
- package/adapters/resend.mjs +2 -0
- package/adapters/resend.mjs.map +1 -0
- package/adapters/socket.d.mts +14 -0
- package/adapters/socket.mjs +3 -0
- package/adapters/socket.mjs.map +1 -0
- package/adapters/websocket.d.mts +21 -0
- package/adapters/websocket.mjs +2 -0
- package/adapters/websocket.mjs.map +1 -0
- package/adapters/webworker.d.mts +8 -0
- package/adapters/webworker.mjs +2 -0
- package/adapters/webworker.mjs.map +1 -0
- package/codecs/cbor.d.mts +12 -0
- package/codecs/cbor.mjs +2 -0
- package/codecs/cbor.mjs.map +1 -0
- package/codecs/psionic.d.mts +12 -0
- package/codecs/psionic.mjs +2 -0
- package/codecs/psionic.mjs.map +1 -0
- package/package.json +42 -24
- package/psionic.d.mts +203 -0
- package/psionic.mjs +2 -0
- package/psionic.mjs.map +1 -0
- package/session.d.mts +63 -0
- package/session.mjs +2 -0
- package/session.mjs.map +1 -0
- package/utils/react-hooks.d.mts +24 -0
- package/utils/react-hooks.mjs +2 -0
- package/utils/react-hooks.mjs.map +1 -0
- package/README.md +0 -321
- package/__tests__/async-functions.ts +0 -43
- package/__tests__/async-generator-functions.ts +0 -137
- package/__tests__/convert-from-wire-format.ts +0 -65
- package/__tests__/convert-to-wire-format.ts +0 -66
- package/__tests__/describe.ts +0 -26
- package/__tests__/lib/adapter.ts +0 -47
- package/docs/extending.md +0 -19
- package/docs/protocol.md +0 -154
- package/examples/cli-chat/client.mjs +0 -21
- package/examples/cli-chat/package.json +0 -17
- package/examples/cli-chat/server.mjs +0 -48
- package/examples/cloudflare/README.md +0 -37
- package/examples/cloudflare/eslint.config.js +0 -19
- package/examples/cloudflare/index.html +0 -13
- package/examples/cloudflare/package.json +0 -29
- package/examples/cloudflare/public/vite.svg +0 -1
- package/examples/cloudflare/src/App.svelte +0 -450
- package/examples/cloudflare/src/api.ts +0 -33
- package/examples/cloudflare/src/main.ts +0 -4
- package/examples/cloudflare/tsconfig.app.json +0 -27
- package/examples/cloudflare/tsconfig.json +0 -14
- package/examples/cloudflare/tsconfig.node.json +0 -26
- package/examples/cloudflare/tsconfig.worker.json +0 -8
- package/examples/cloudflare/vite.config.ts +0 -8
- package/examples/cloudflare/worker/cloudflare.ts +0 -115
- package/examples/cloudflare/worker/index.ts +0 -17
- package/examples/cloudflare/worker/peer.ts +0 -47
- package/examples/cloudflare/worker-configuration.d.ts +0 -10922
- package/examples/cloudflare/wrangler.jsonc +0 -58
- package/examples/nodestreams/adapter.mjs +0 -36
- package/examples/nodestreams/child.mjs +0 -20
- package/examples/nodestreams/package.json +0 -14
- package/examples/nodestreams/parent.mjs +0 -20
- package/examples/reconnect/client.mjs +0 -22
- package/examples/reconnect/package.json +0 -15
- package/examples/reconnect/server.mjs +0 -30
- package/examples/tokens/client.mjs +0 -26
- package/examples/tokens/package.json +0 -20
- package/examples/tokens/server.mjs +0 -46
- package/make-package.js +0 -23
- package/src/adapters/reconnect.ts +0 -54
- package/src/adapters/resend.ts +0 -34
- package/src/adapters/socket.ts +0 -183
- package/src/adapters/websocket.ts +0 -157
- package/src/adapters/webworker.ts +0 -48
- package/src/codecs/cbor.ts +0 -239
- package/src/codecs/psionic.ts +0 -75
- package/src/psionic.ts +0 -876
- package/src/session.ts +0 -164
- package/src/utils/react-hooks.ts +0 -48
- package/tests +0 -8
- package/tsdown.config.ts +0 -19
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
<!doctype html>
|
|
2
|
-
<html lang="en">
|
|
3
|
-
<head>
|
|
4
|
-
<meta charset="UTF-8" />
|
|
5
|
-
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
6
|
-
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
|
-
<title>Chat example</title>
|
|
8
|
-
</head>
|
|
9
|
-
<body>
|
|
10
|
-
<div id="app"></div>
|
|
11
|
-
<script type="module" src="/src/main.ts"></script>
|
|
12
|
-
</body>
|
|
13
|
-
</html>
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "chat-example",
|
|
3
|
-
"private": true,
|
|
4
|
-
"version": "0.0.0",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"dev": "vite",
|
|
8
|
-
"build": "tsc -b && vite build",
|
|
9
|
-
"lint": "eslint .",
|
|
10
|
-
"preview": "npm run build && vite preview",
|
|
11
|
-
"deploy": "npm run build && wrangler deploy",
|
|
12
|
-
"cf-typegen": "wrangler types"
|
|
13
|
-
},
|
|
14
|
-
"devDependencies": {
|
|
15
|
-
"@cloudflare/vite-plugin": "^1.25.2",
|
|
16
|
-
"@eslint/js": "^9.39.1",
|
|
17
|
-
"@sveltejs/vite-plugin-svelte": "^6.2.4",
|
|
18
|
-
"@types/node": "^24.10.13",
|
|
19
|
-
"eslint": "^9.39.1",
|
|
20
|
-
"globals": "^16.5.0",
|
|
21
|
-
"openai": "^6.24.0",
|
|
22
|
-
"psionic": "file:../..",
|
|
23
|
-
"svelte": "^5.53.3",
|
|
24
|
-
"typescript": "~5.9.3",
|
|
25
|
-
"typescript-eslint": "^8.48.0",
|
|
26
|
-
"vite": "^7.3.1",
|
|
27
|
-
"wrangler": "^4.67.0"
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>
|
|
@@ -1,450 +0,0 @@
|
|
|
1
|
-
<script lang="ts">
|
|
2
|
-
import { server, ready } from "./api";
|
|
3
|
-
let prompt = "";
|
|
4
|
-
|
|
5
|
-
let chatlog: HTMLDivElement | null = null;
|
|
6
|
-
|
|
7
|
-
let pending = false;
|
|
8
|
-
let conversation: any[] = [];
|
|
9
|
-
let newMessage: any[] = [];
|
|
10
|
-
|
|
11
|
-
async function call() {
|
|
12
|
-
conversation = [...conversation, { from: 'user', content: prompt }];
|
|
13
|
-
const sent = prompt;
|
|
14
|
-
prompt = "";
|
|
15
|
-
|
|
16
|
-
pending = true;
|
|
17
|
-
try {
|
|
18
|
-
if (!$server.prompt) return;
|
|
19
|
-
for await (const result of $server.prompt(sent)) {
|
|
20
|
-
if (result.type === "response.output_text.delta") {
|
|
21
|
-
newMessage = [...newMessage, result.delta];
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
} catch (ex: any) {
|
|
25
|
-
newMessage = [...newMessage, `\n\nError: ${ex.message}\n\n---\n\n`];
|
|
26
|
-
} finally {
|
|
27
|
-
pending = false;
|
|
28
|
-
conversation = [...conversation, { from: 'assistant', content: newMessage.join("") }];
|
|
29
|
-
newMessage = [];
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function handleKeydown(e: KeyboardEvent) {
|
|
34
|
-
if (e.key === "Enter" && !e.shiftKey && !pending) {
|
|
35
|
-
e.preventDefault();
|
|
36
|
-
call();
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function setupMutationObserver(node: HTMLDivElement) {
|
|
41
|
-
if (!node) return;
|
|
42
|
-
const observer = new MutationObserver(updateScroll);
|
|
43
|
-
updateScroll();
|
|
44
|
-
observer.observe(node, { childList: true, subtree: true });
|
|
45
|
-
function updateScroll() {
|
|
46
|
-
window.requestAnimationFrame(() => {
|
|
47
|
-
if (!chatlog) return;
|
|
48
|
-
chatlog.scrollTop = chatlog.scrollHeight;
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
return {
|
|
52
|
-
destroy() {
|
|
53
|
-
observer.disconnect();
|
|
54
|
-
},
|
|
55
|
-
};
|
|
56
|
-
}
|
|
57
|
-
</script>
|
|
58
|
-
|
|
59
|
-
<div class="shell">
|
|
60
|
-
<!-- Ambient background glow -->
|
|
61
|
-
<div class="glow glow-1"></div>
|
|
62
|
-
<div class="glow glow-2"></div>
|
|
63
|
-
|
|
64
|
-
<header class="topbar">
|
|
65
|
-
<div class="logo-mark">
|
|
66
|
-
<svg viewBox="0 0 28 28" width="28" height="28" fill="none">
|
|
67
|
-
<rect x="2" y="2" width="24" height="24" rx="7" stroke="url(#g1)" stroke-width="2"/>
|
|
68
|
-
<circle cx="10" cy="14" r="2" fill="url(#g1)"/>
|
|
69
|
-
<circle cx="18" cy="14" r="2" fill="url(#g1)"/>
|
|
70
|
-
<path d="M9 18.5c1.5 1.5 3 2 5 2s3.5-.5 5-2" stroke="url(#g1)" stroke-width="1.5" stroke-linecap="round"/>
|
|
71
|
-
<defs>
|
|
72
|
-
<linearGradient id="g1" x1="0" y1="0" x2="28" y2="28">
|
|
73
|
-
<stop stop-color="#6ee7b7"/>
|
|
74
|
-
<stop offset="1" stop-color="#3b82f6"/>
|
|
75
|
-
</linearGradient>
|
|
76
|
-
</defs>
|
|
77
|
-
</svg>
|
|
78
|
-
</div>
|
|
79
|
-
<div class="topbar-text">
|
|
80
|
-
<span class="topbar-title">Chat</span>
|
|
81
|
-
<span class="topbar-status" class:live={$ready}>
|
|
82
|
-
<span class="status-dot"></span>
|
|
83
|
-
{$ready ? 'Connected' : 'Offline'}
|
|
84
|
-
</span>
|
|
85
|
-
</div>
|
|
86
|
-
</header>
|
|
87
|
-
|
|
88
|
-
<div class="chatlog" bind:this={chatlog} use:setupMutationObserver>
|
|
89
|
-
{#each conversation as message, i (i)}
|
|
90
|
-
<div class="msg-row" class:is-user={message.from === 'user'} class:no-anim={message.from === 'assistant'}>
|
|
91
|
-
{#if message.from === 'assistant'}
|
|
92
|
-
<div class="avatar assistant-avatar">
|
|
93
|
-
<svg viewBox="0 0 20 20" width="16" height="16" fill="none">
|
|
94
|
-
<circle cx="7" cy="10" r="1.5" fill="#6ee7b7"/>
|
|
95
|
-
<circle cx="13" cy="10" r="1.5" fill="#3b82f6"/>
|
|
96
|
-
</svg>
|
|
97
|
-
</div>
|
|
98
|
-
{/if}
|
|
99
|
-
<div class="bubble" class:user-bubble={message.from === 'user'} class:assistant-bubble={message.from === 'assistant'}>
|
|
100
|
-
<span class="msg-text">{message.content}</span>
|
|
101
|
-
</div>
|
|
102
|
-
</div>
|
|
103
|
-
{/each}
|
|
104
|
-
|
|
105
|
-
{#if pending}
|
|
106
|
-
<div class="msg-row">
|
|
107
|
-
<div class="avatar assistant-avatar">
|
|
108
|
-
<svg viewBox="0 0 20 20" width="16" height="16" fill="none">
|
|
109
|
-
<circle cx="7" cy="10" r="1.5" fill="#6ee7b7"/>
|
|
110
|
-
<circle cx="13" cy="10" r="1.5" fill="#3b82f6"/>
|
|
111
|
-
</svg>
|
|
112
|
-
</div>
|
|
113
|
-
<div class="bubble assistant-bubble streaming">
|
|
114
|
-
{#each newMessage as result, i (i)}
|
|
115
|
-
<span class="msg-text">{result}</span>
|
|
116
|
-
{/each}
|
|
117
|
-
<span class="caret"></span>
|
|
118
|
-
</div>
|
|
119
|
-
</div>
|
|
120
|
-
{/if}
|
|
121
|
-
</div>
|
|
122
|
-
|
|
123
|
-
{#if $server.prompt}
|
|
124
|
-
<div class="composer">
|
|
125
|
-
<div class="composer-inner">
|
|
126
|
-
<textarea
|
|
127
|
-
bind:value={prompt}
|
|
128
|
-
on:keydown={handleKeydown}
|
|
129
|
-
placeholder="Message…"
|
|
130
|
-
rows="1"
|
|
131
|
-
></textarea>
|
|
132
|
-
<button
|
|
133
|
-
class="send-btn"
|
|
134
|
-
on:click={call}
|
|
135
|
-
disabled={pending || !prompt.trim()}
|
|
136
|
-
title="Send"
|
|
137
|
-
class:ready={!pending && prompt.trim()}
|
|
138
|
-
>
|
|
139
|
-
<svg viewBox="0 0 24 24" width="18" height="18" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
|
140
|
-
<line x1="12" y1="19" x2="12" y2="5"/>
|
|
141
|
-
<polyline points="5 12 12 5 19 12"/>
|
|
142
|
-
</svg>
|
|
143
|
-
</button>
|
|
144
|
-
</div>
|
|
145
|
-
<span class="composer-hint">Enter to send · Shift+Enter for new line</span>
|
|
146
|
-
</div>
|
|
147
|
-
{/if}
|
|
148
|
-
</div>
|
|
149
|
-
|
|
150
|
-
<style>
|
|
151
|
-
@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300..700;1,9..40,300..700&family=JetBrains+Mono:wght@400;500&display=swap');
|
|
152
|
-
|
|
153
|
-
:global(body) {
|
|
154
|
-
margin: 0;
|
|
155
|
-
padding: 0;
|
|
156
|
-
background: #0a0a0f;
|
|
157
|
-
overflow: hidden;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
* {
|
|
161
|
-
box-sizing: border-box;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
.shell {
|
|
165
|
-
position: relative;
|
|
166
|
-
max-width: 44em;
|
|
167
|
-
margin: 0 auto;
|
|
168
|
-
height: 100vh;
|
|
169
|
-
height: 100dvh;
|
|
170
|
-
display: flex;
|
|
171
|
-
flex-direction: column;
|
|
172
|
-
font-family: 'DM Sans', sans-serif;
|
|
173
|
-
font-size: 0.9rem;
|
|
174
|
-
color: #e4e4e7;
|
|
175
|
-
background: #0c0c14;
|
|
176
|
-
overflow: hidden;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
/* ── Ambient glows ── */
|
|
180
|
-
.glow {
|
|
181
|
-
position: absolute;
|
|
182
|
-
border-radius: 50%;
|
|
183
|
-
filter: blur(100px);
|
|
184
|
-
opacity: 0.15;
|
|
185
|
-
pointer-events: none;
|
|
186
|
-
z-index: 0;
|
|
187
|
-
}
|
|
188
|
-
.glow-1 {
|
|
189
|
-
width: 400px;
|
|
190
|
-
height: 400px;
|
|
191
|
-
background: #6ee7b7;
|
|
192
|
-
top: -120px;
|
|
193
|
-
left: -80px;
|
|
194
|
-
animation: drift1 12s ease-in-out infinite alternate;
|
|
195
|
-
}
|
|
196
|
-
.glow-2 {
|
|
197
|
-
width: 350px;
|
|
198
|
-
height: 350px;
|
|
199
|
-
background: #3b82f6;
|
|
200
|
-
bottom: -100px;
|
|
201
|
-
right: -60px;
|
|
202
|
-
animation: drift2 14s ease-in-out infinite alternate;
|
|
203
|
-
}
|
|
204
|
-
@keyframes drift1 {
|
|
205
|
-
to { transform: translate(60px, 40px); }
|
|
206
|
-
}
|
|
207
|
-
@keyframes drift2 {
|
|
208
|
-
to { transform: translate(-50px, -30px); }
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/* ── Header ── */
|
|
212
|
-
.topbar {
|
|
213
|
-
position: relative;
|
|
214
|
-
z-index: 2;
|
|
215
|
-
display: flex;
|
|
216
|
-
align-items: center;
|
|
217
|
-
gap: 0.75em;
|
|
218
|
-
padding: 1em 1.25em;
|
|
219
|
-
border-bottom: 1px solid rgba(255,255,255,0.06);
|
|
220
|
-
backdrop-filter: blur(20px);
|
|
221
|
-
background: rgba(12,12,20,0.7);
|
|
222
|
-
}
|
|
223
|
-
.logo-mark {
|
|
224
|
-
display: grid;
|
|
225
|
-
place-items: center;
|
|
226
|
-
}
|
|
227
|
-
.topbar-text {
|
|
228
|
-
display: flex;
|
|
229
|
-
flex-direction: column;
|
|
230
|
-
gap: 0.1em;
|
|
231
|
-
}
|
|
232
|
-
.topbar-title {
|
|
233
|
-
font-weight: 600;
|
|
234
|
-
font-size: 0.95rem;
|
|
235
|
-
letter-spacing: -0.01em;
|
|
236
|
-
color: #f4f4f5;
|
|
237
|
-
}
|
|
238
|
-
.topbar-status {
|
|
239
|
-
display: flex;
|
|
240
|
-
align-items: center;
|
|
241
|
-
gap: 0.35em;
|
|
242
|
-
font-size: 0.7rem;
|
|
243
|
-
color: #71717a;
|
|
244
|
-
font-weight: 500;
|
|
245
|
-
text-transform: uppercase;
|
|
246
|
-
letter-spacing: 0.05em;
|
|
247
|
-
}
|
|
248
|
-
.status-dot {
|
|
249
|
-
width: 6px;
|
|
250
|
-
height: 6px;
|
|
251
|
-
border-radius: 50%;
|
|
252
|
-
background: #52525b;
|
|
253
|
-
transition: background 0.3s;
|
|
254
|
-
}
|
|
255
|
-
.topbar-status.live .status-dot {
|
|
256
|
-
background: #34d399;
|
|
257
|
-
box-shadow: 0 0 6px #34d39988;
|
|
258
|
-
}
|
|
259
|
-
|
|
260
|
-
/* ── Chat log ── */
|
|
261
|
-
.chatlog {
|
|
262
|
-
position: relative;
|
|
263
|
-
z-index: 1;
|
|
264
|
-
flex: 1;
|
|
265
|
-
overflow-y: auto;
|
|
266
|
-
overflow-x: hidden;
|
|
267
|
-
padding: 1.5em 1.25em;
|
|
268
|
-
display: flex;
|
|
269
|
-
flex-direction: column;
|
|
270
|
-
gap: 0.5em;
|
|
271
|
-
scrollbar-width: thin;
|
|
272
|
-
scrollbar-color: rgba(255,255,255,0.08) transparent;
|
|
273
|
-
}
|
|
274
|
-
.chatlog::-webkit-scrollbar {
|
|
275
|
-
width: 5px;
|
|
276
|
-
}
|
|
277
|
-
.chatlog::-webkit-scrollbar-thumb {
|
|
278
|
-
background: rgba(255,255,255,0.08);
|
|
279
|
-
border-radius: 10px;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/* ── Messages ── */
|
|
283
|
-
.msg-row {
|
|
284
|
-
display: flex;
|
|
285
|
-
align-items: flex-end;
|
|
286
|
-
gap: 0.5em;
|
|
287
|
-
}
|
|
288
|
-
.msg-row.is-user {
|
|
289
|
-
justify-content: flex-end;
|
|
290
|
-
animation: fadeUp 0.25s ease-out both;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
.msg-row.no-anim {
|
|
294
|
-
animation: none;
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
@keyframes fadeUp {
|
|
298
|
-
from {
|
|
299
|
-
opacity: 0;
|
|
300
|
-
transform: translateY(8px);
|
|
301
|
-
}
|
|
302
|
-
to {
|
|
303
|
-
opacity: 1;
|
|
304
|
-
transform: translateY(0);
|
|
305
|
-
}
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
.avatar {
|
|
309
|
-
width: 28px;
|
|
310
|
-
height: 28px;
|
|
311
|
-
border-radius: 8px;
|
|
312
|
-
display: grid;
|
|
313
|
-
place-items: center;
|
|
314
|
-
flex-shrink: 0;
|
|
315
|
-
margin-bottom: 2px;
|
|
316
|
-
}
|
|
317
|
-
.assistant-avatar {
|
|
318
|
-
background: rgba(255,255,255,0.05);
|
|
319
|
-
border: 1px solid rgba(255,255,255,0.08);
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
.bubble {
|
|
323
|
-
max-width: 75%;
|
|
324
|
-
padding: 0.65em 0.9em;
|
|
325
|
-
border-radius: 1.1em;
|
|
326
|
-
line-height: 1.55;
|
|
327
|
-
font-size: 0.88rem;
|
|
328
|
-
position: relative;
|
|
329
|
-
}
|
|
330
|
-
.user-bubble {
|
|
331
|
-
background: linear-gradient(135deg, #2563eb, #1d4ed8);
|
|
332
|
-
color: #f0f6ff;
|
|
333
|
-
border-bottom-right-radius: 0.3em;
|
|
334
|
-
box-shadow: 0 2px 12px rgba(37,99,235,0.25);
|
|
335
|
-
}
|
|
336
|
-
.assistant-bubble {
|
|
337
|
-
background: rgba(255,255,255,0.06);
|
|
338
|
-
border: 1px solid rgba(255,255,255,0.07);
|
|
339
|
-
color: #d4d4d8;
|
|
340
|
-
border-bottom-left-radius: 0.3em;
|
|
341
|
-
backdrop-filter: blur(8px);
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
.msg-text {
|
|
345
|
-
white-space: pre-wrap;
|
|
346
|
-
word-break: break-word;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
/* ── Streaming caret ── */
|
|
350
|
-
.caret {
|
|
351
|
-
display: inline-block;
|
|
352
|
-
width: 2px;
|
|
353
|
-
height: 1.05em;
|
|
354
|
-
margin-left: 1px;
|
|
355
|
-
vertical-align: text-bottom;
|
|
356
|
-
border-radius: 1px;
|
|
357
|
-
background: linear-gradient(to bottom, #6ee7b7, #3b82f6);
|
|
358
|
-
animation: caretPulse 0.8s ease-in-out infinite;
|
|
359
|
-
}
|
|
360
|
-
@keyframes caretPulse {
|
|
361
|
-
0%, 100% { opacity: 1; }
|
|
362
|
-
50% { opacity: 0.2; }
|
|
363
|
-
}
|
|
364
|
-
|
|
365
|
-
/* ── Composer ── */
|
|
366
|
-
.composer {
|
|
367
|
-
position: relative;
|
|
368
|
-
z-index: 2;
|
|
369
|
-
padding: 0.75em 1.25em 1em;
|
|
370
|
-
display: flex;
|
|
371
|
-
flex-direction: column;
|
|
372
|
-
gap: 0.4em;
|
|
373
|
-
border-top: 1px solid rgba(255,255,255,0.06);
|
|
374
|
-
backdrop-filter: blur(20px);
|
|
375
|
-
background: rgba(12,12,20,0.7);
|
|
376
|
-
}
|
|
377
|
-
.composer-inner {
|
|
378
|
-
display: flex;
|
|
379
|
-
align-items: flex-end;
|
|
380
|
-
gap: 0.5em;
|
|
381
|
-
background: rgba(255,255,255,0.05);
|
|
382
|
-
border: 1px solid rgba(255,255,255,0.08);
|
|
383
|
-
border-radius: 1em;
|
|
384
|
-
padding: 0.35em 0.4em 0.35em 0.85em;
|
|
385
|
-
transition: border-color 0.2s;
|
|
386
|
-
}
|
|
387
|
-
.composer-inner:focus-within {
|
|
388
|
-
border-color: rgba(59,130,246,0.5);
|
|
389
|
-
box-shadow: 0 0 0 3px rgba(59,130,246,0.08);
|
|
390
|
-
}
|
|
391
|
-
.composer-hint {
|
|
392
|
-
font-size: 0.65rem;
|
|
393
|
-
color: #3f3f46;
|
|
394
|
-
text-align: center;
|
|
395
|
-
letter-spacing: 0.02em;
|
|
396
|
-
}
|
|
397
|
-
|
|
398
|
-
textarea {
|
|
399
|
-
flex: 1;
|
|
400
|
-
resize: none;
|
|
401
|
-
border: none;
|
|
402
|
-
background: transparent;
|
|
403
|
-
padding: 0.5em 0;
|
|
404
|
-
font: inherit;
|
|
405
|
-
font-size: 0.88rem;
|
|
406
|
-
color: #e4e4e7;
|
|
407
|
-
outline: none;
|
|
408
|
-
line-height: 1.5;
|
|
409
|
-
min-height: 1.5em;
|
|
410
|
-
max-height: 8em;
|
|
411
|
-
}
|
|
412
|
-
textarea::placeholder {
|
|
413
|
-
color: #52525b;
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
.send-btn {
|
|
417
|
-
display: grid;
|
|
418
|
-
place-items: center;
|
|
419
|
-
width: 2.2em;
|
|
420
|
-
height: 2.2em;
|
|
421
|
-
border: none;
|
|
422
|
-
border-radius: 0.7em;
|
|
423
|
-
background: rgba(255,255,255,0.06);
|
|
424
|
-
color: #52525b;
|
|
425
|
-
cursor: pointer;
|
|
426
|
-
flex-shrink: 0;
|
|
427
|
-
transition: all 0.2s ease;
|
|
428
|
-
margin-bottom: 4px;
|
|
429
|
-
}
|
|
430
|
-
.send-btn.ready {
|
|
431
|
-
background: linear-gradient(135deg, #34d399, #3b82f6);
|
|
432
|
-
color: white;
|
|
433
|
-
box-shadow: 0 2px 10px rgba(59,130,246,0.3);
|
|
434
|
-
}
|
|
435
|
-
.send-btn.ready:hover {
|
|
436
|
-
transform: translateY(-1px);
|
|
437
|
-
box-shadow: 0 4px 16px rgba(59,130,246,0.4);
|
|
438
|
-
}
|
|
439
|
-
.send-btn:disabled {
|
|
440
|
-
cursor: default;
|
|
441
|
-
}
|
|
442
|
-
.send-btn.ready:active {
|
|
443
|
-
transform: translateY(0);
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
/* ── Scrollbar for Webkit ── */
|
|
447
|
-
.chatlog::-webkit-scrollbar-track {
|
|
448
|
-
background: transparent;
|
|
449
|
-
}
|
|
450
|
-
</style>
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
import { createPeer, STATE_READY } from 'psionic';
|
|
2
|
-
import { writable } from 'svelte/store';
|
|
3
|
-
import { createWebSocketAdapter } from 'psionic/adapters/websocket';
|
|
4
|
-
import { reconnect } from 'psionic/adapters/reconnect';
|
|
5
|
-
import { type CFWorkerAPI } from '../worker/peer'
|
|
6
|
-
|
|
7
|
-
export type ClientAPI = { };
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const peer = createPeer<CFWorkerAPI, ClientAPI>({
|
|
11
|
-
description: {},
|
|
12
|
-
receiveErrorMessages: true
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
// Attempt to reuse existing session ID from previous connection, if available.
|
|
16
|
-
let sid = sessionStorage.getItem('sid') ?? undefined;
|
|
17
|
-
|
|
18
|
-
peer.on('describe', d => {
|
|
19
|
-
// update sid from the server if it sends one, and persist for next time.
|
|
20
|
-
if (d.sid && d.sid !== sid) {
|
|
21
|
-
sid = d.sid;
|
|
22
|
-
sessionStorage.setItem('sid', sid);
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
export const server = writable<Partial<CFWorkerAPI>>({});
|
|
27
|
-
|
|
28
|
-
export const ready = writable(false);
|
|
29
|
-
peer.on('readyStateChange', (s) => { ready.set(s === STATE_READY); });
|
|
30
|
-
peer.on('describe', d => server.set(d));
|
|
31
|
-
|
|
32
|
-
// setup a reconnecting websocket adapter to the Durable Object, which will maintain session state across disconnects.
|
|
33
|
-
peer.connect(reconnect(() => createWebSocketAdapter(new WebSocket('/websocket?sid=' + (sid || '')))));
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
|
4
|
-
"target": "ES2022",
|
|
5
|
-
"useDefineForClassFields": true,
|
|
6
|
-
"lib": ["ES2022", "DOM", "DOM.Iterable"],
|
|
7
|
-
"module": "ESNext",
|
|
8
|
-
"types": ["vite/client"],
|
|
9
|
-
"skipLibCheck": true,
|
|
10
|
-
|
|
11
|
-
/* Bundler mode */
|
|
12
|
-
"moduleResolution": "bundler",
|
|
13
|
-
"allowImportingTsExtensions": true,
|
|
14
|
-
"verbatimModuleSyntax": true,
|
|
15
|
-
"moduleDetection": "force",
|
|
16
|
-
"noEmit": true,
|
|
17
|
-
|
|
18
|
-
/* Linting */
|
|
19
|
-
"strict": true,
|
|
20
|
-
"noUnusedLocals": true,
|
|
21
|
-
"noUnusedParameters": true,
|
|
22
|
-
"erasableSyntaxOnly": true,
|
|
23
|
-
"noFallthroughCasesInSwitch": true,
|
|
24
|
-
"noUncheckedSideEffectImports": true
|
|
25
|
-
},
|
|
26
|
-
"include": ["src"]
|
|
27
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
|
4
|
-
"target": "ES2023",
|
|
5
|
-
"lib": ["ES2023", "DOM"],
|
|
6
|
-
"module": "ESNext",
|
|
7
|
-
"types": ["node"],
|
|
8
|
-
"skipLibCheck": true,
|
|
9
|
-
|
|
10
|
-
/* Bundler mode */
|
|
11
|
-
"moduleResolution": "bundler",
|
|
12
|
-
"allowImportingTsExtensions": true,
|
|
13
|
-
"verbatimModuleSyntax": true,
|
|
14
|
-
"moduleDetection": "force",
|
|
15
|
-
"noEmit": true,
|
|
16
|
-
|
|
17
|
-
/* Linting */
|
|
18
|
-
"strict": true,
|
|
19
|
-
"noUnusedLocals": true,
|
|
20
|
-
"noUnusedParameters": true,
|
|
21
|
-
"erasableSyntaxOnly": true,
|
|
22
|
-
"noFallthroughCasesInSwitch": true,
|
|
23
|
-
"noUncheckedSideEffectImports": true
|
|
24
|
-
},
|
|
25
|
-
"include": ["vite.config.ts"]
|
|
26
|
-
}
|