@poncho-ai/cli 0.3.1 → 0.3.2
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/.turbo/turbo-build.log +8 -9
- package/CHANGELOG.md +8 -0
- package/dist/chunk-3OBDF3LI.js +1893 -0
- package/dist/chunk-ESPC4MPN.js +4043 -0
- package/dist/chunk-XABZUC4W.js +4043 -0
- package/dist/chunk-YJZ3MQIA.js +2145 -0
- package/dist/cli.js +1 -2
- package/dist/index.d.ts +6 -1
- package/dist/index.js +3 -2
- package/dist/run-interactive-ink-BOD2F5JM.js +463 -0
- package/dist/run-interactive-ink-EHJVWEDC.js +462 -0
- package/dist/run-interactive-ink-M5E55KCC.js +463 -0
- package/package.json +1 -1
- package/src/index.ts +57 -5
- package/src/init-feature-context.ts +2 -1
- package/src/run-interactive-ink.ts +2 -1
- package/src/web-ui.ts +1 -1
|
@@ -0,0 +1,1893 @@
|
|
|
1
|
+
// src/web-ui.ts
|
|
2
|
+
import { createHash, randomUUID, timingSafeEqual } from "crypto";
|
|
3
|
+
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
4
|
+
import { basename, dirname, resolve } from "path";
|
|
5
|
+
import { homedir } from "os";
|
|
6
|
+
var DEFAULT_OWNER = "local-owner";
|
|
7
|
+
var SessionStore = class {
|
|
8
|
+
sessions = /* @__PURE__ */ new Map();
|
|
9
|
+
ttlMs;
|
|
10
|
+
constructor(ttlMs = 1e3 * 60 * 60 * 8) {
|
|
11
|
+
this.ttlMs = ttlMs;
|
|
12
|
+
}
|
|
13
|
+
create(ownerId = DEFAULT_OWNER) {
|
|
14
|
+
const now = Date.now();
|
|
15
|
+
const session = {
|
|
16
|
+
sessionId: randomUUID(),
|
|
17
|
+
ownerId,
|
|
18
|
+
csrfToken: randomUUID(),
|
|
19
|
+
createdAt: now,
|
|
20
|
+
expiresAt: now + this.ttlMs,
|
|
21
|
+
lastSeenAt: now
|
|
22
|
+
};
|
|
23
|
+
this.sessions.set(session.sessionId, session);
|
|
24
|
+
return session;
|
|
25
|
+
}
|
|
26
|
+
get(sessionId) {
|
|
27
|
+
const session = this.sessions.get(sessionId);
|
|
28
|
+
if (!session) {
|
|
29
|
+
return void 0;
|
|
30
|
+
}
|
|
31
|
+
if (Date.now() > session.expiresAt) {
|
|
32
|
+
this.sessions.delete(sessionId);
|
|
33
|
+
return void 0;
|
|
34
|
+
}
|
|
35
|
+
session.lastSeenAt = Date.now();
|
|
36
|
+
return session;
|
|
37
|
+
}
|
|
38
|
+
delete(sessionId) {
|
|
39
|
+
this.sessions.delete(sessionId);
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
var LoginRateLimiter = class {
|
|
43
|
+
constructor(maxAttempts = 5, windowMs = 1e3 * 60 * 5, lockoutMs = 1e3 * 60 * 10) {
|
|
44
|
+
this.maxAttempts = maxAttempts;
|
|
45
|
+
this.windowMs = windowMs;
|
|
46
|
+
this.lockoutMs = lockoutMs;
|
|
47
|
+
}
|
|
48
|
+
attempts = /* @__PURE__ */ new Map();
|
|
49
|
+
canAttempt(key) {
|
|
50
|
+
const current = this.attempts.get(key);
|
|
51
|
+
if (!current) {
|
|
52
|
+
return { allowed: true };
|
|
53
|
+
}
|
|
54
|
+
if (current.lockedUntil && Date.now() < current.lockedUntil) {
|
|
55
|
+
return {
|
|
56
|
+
allowed: false,
|
|
57
|
+
retryAfterSeconds: Math.ceil((current.lockedUntil - Date.now()) / 1e3)
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return { allowed: true };
|
|
61
|
+
}
|
|
62
|
+
registerFailure(key) {
|
|
63
|
+
const now = Date.now();
|
|
64
|
+
const current = this.attempts.get(key);
|
|
65
|
+
if (!current || now - current.firstFailureAt > this.windowMs) {
|
|
66
|
+
this.attempts.set(key, { count: 1, firstFailureAt: now });
|
|
67
|
+
return { locked: false };
|
|
68
|
+
}
|
|
69
|
+
const count = current.count + 1;
|
|
70
|
+
const next = {
|
|
71
|
+
...current,
|
|
72
|
+
count
|
|
73
|
+
};
|
|
74
|
+
if (count >= this.maxAttempts) {
|
|
75
|
+
next.lockedUntil = now + this.lockoutMs;
|
|
76
|
+
this.attempts.set(key, next);
|
|
77
|
+
return { locked: true, retryAfterSeconds: Math.ceil(this.lockoutMs / 1e3) };
|
|
78
|
+
}
|
|
79
|
+
this.attempts.set(key, next);
|
|
80
|
+
return { locked: false };
|
|
81
|
+
}
|
|
82
|
+
registerSuccess(key) {
|
|
83
|
+
this.attempts.delete(key);
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var parseCookies = (request) => {
|
|
87
|
+
const cookieHeader = request.headers.cookie ?? "";
|
|
88
|
+
const pairs = cookieHeader.split(";").map((part) => part.trim()).filter(Boolean);
|
|
89
|
+
const cookies = {};
|
|
90
|
+
for (const pair of pairs) {
|
|
91
|
+
const index = pair.indexOf("=");
|
|
92
|
+
if (index <= 0) {
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
const key = pair.slice(0, index);
|
|
96
|
+
const value = pair.slice(index + 1);
|
|
97
|
+
try {
|
|
98
|
+
cookies[key] = decodeURIComponent(value);
|
|
99
|
+
} catch {
|
|
100
|
+
cookies[key] = value;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
return cookies;
|
|
104
|
+
};
|
|
105
|
+
var setCookie = (response, name, value, options) => {
|
|
106
|
+
const segments = [`${name}=${encodeURIComponent(value)}`];
|
|
107
|
+
segments.push(`Path=${options.path ?? "/"}`);
|
|
108
|
+
if (typeof options.maxAge === "number") {
|
|
109
|
+
segments.push(`Max-Age=${Math.max(0, Math.floor(options.maxAge))}`);
|
|
110
|
+
}
|
|
111
|
+
if (options.httpOnly) {
|
|
112
|
+
segments.push("HttpOnly");
|
|
113
|
+
}
|
|
114
|
+
if (options.secure) {
|
|
115
|
+
segments.push("Secure");
|
|
116
|
+
}
|
|
117
|
+
if (options.sameSite) {
|
|
118
|
+
segments.push(`SameSite=${options.sameSite}`);
|
|
119
|
+
}
|
|
120
|
+
const previous = response.getHeader("Set-Cookie");
|
|
121
|
+
const serialized = segments.join("; ");
|
|
122
|
+
if (!previous) {
|
|
123
|
+
response.setHeader("Set-Cookie", serialized);
|
|
124
|
+
return;
|
|
125
|
+
}
|
|
126
|
+
if (Array.isArray(previous)) {
|
|
127
|
+
response.setHeader("Set-Cookie", [...previous, serialized]);
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
response.setHeader("Set-Cookie", [String(previous), serialized]);
|
|
131
|
+
};
|
|
132
|
+
var verifyPassphrase = (provided, expected) => {
|
|
133
|
+
const providedBuffer = Buffer.from(provided);
|
|
134
|
+
const expectedBuffer = Buffer.from(expected);
|
|
135
|
+
if (providedBuffer.length !== expectedBuffer.length) {
|
|
136
|
+
const zero = Buffer.alloc(expectedBuffer.length);
|
|
137
|
+
return timingSafeEqual(expectedBuffer, zero) && false;
|
|
138
|
+
}
|
|
139
|
+
return timingSafeEqual(providedBuffer, expectedBuffer);
|
|
140
|
+
};
|
|
141
|
+
var getRequestIp = (request) => {
|
|
142
|
+
return request.socket.remoteAddress ?? "unknown";
|
|
143
|
+
};
|
|
144
|
+
var inferConversationTitle = (text) => {
|
|
145
|
+
const normalized = text.trim().replace(/\s+/g, " ");
|
|
146
|
+
if (!normalized) {
|
|
147
|
+
return "New conversation";
|
|
148
|
+
}
|
|
149
|
+
return normalized.length <= 48 ? normalized : `${normalized.slice(0, 48)}...`;
|
|
150
|
+
};
|
|
151
|
+
var renderManifest = (options) => {
|
|
152
|
+
const name = options?.agentName ?? "Agent";
|
|
153
|
+
return JSON.stringify({
|
|
154
|
+
name,
|
|
155
|
+
short_name: name,
|
|
156
|
+
description: `${name} \u2014 AI agent powered by Poncho`,
|
|
157
|
+
start_url: "/",
|
|
158
|
+
display: "standalone",
|
|
159
|
+
background_color: "#000000",
|
|
160
|
+
theme_color: "#000000",
|
|
161
|
+
icons: [
|
|
162
|
+
{ src: "/icon.svg", sizes: "any", type: "image/svg+xml" },
|
|
163
|
+
{ src: "/icon-192.png", sizes: "192x192", type: "image/png" },
|
|
164
|
+
{ src: "/icon-512.png", sizes: "512x512", type: "image/png" }
|
|
165
|
+
]
|
|
166
|
+
});
|
|
167
|
+
};
|
|
168
|
+
var renderIconSvg = (options) => {
|
|
169
|
+
const letter = (options?.agentName ?? "A").charAt(0).toUpperCase();
|
|
170
|
+
return `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512">
|
|
171
|
+
<rect width="512" height="512" rx="96" fill="#000"/>
|
|
172
|
+
<text x="256" y="256" dy=".35em" text-anchor="middle"
|
|
173
|
+
font-family="-apple-system,BlinkMacSystemFont,sans-serif"
|
|
174
|
+
font-size="280" font-weight="700" fill="#fff">${letter}</text>
|
|
175
|
+
</svg>`;
|
|
176
|
+
};
|
|
177
|
+
var renderServiceWorker = () => `
|
|
178
|
+
const CACHE_NAME = "poncho-shell-v1";
|
|
179
|
+
const SHELL_URLS = ["/"];
|
|
180
|
+
|
|
181
|
+
self.addEventListener("install", (event) => {
|
|
182
|
+
event.waitUntil(
|
|
183
|
+
caches.open(CACHE_NAME).then((cache) => cache.addAll(SHELL_URLS))
|
|
184
|
+
);
|
|
185
|
+
self.skipWaiting();
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
self.addEventListener("activate", (event) => {
|
|
189
|
+
event.waitUntil(
|
|
190
|
+
caches.keys().then((keys) =>
|
|
191
|
+
Promise.all(keys.filter((k) => k !== CACHE_NAME).map((k) => caches.delete(k)))
|
|
192
|
+
)
|
|
193
|
+
);
|
|
194
|
+
self.clients.claim();
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
self.addEventListener("fetch", (event) => {
|
|
198
|
+
const url = new URL(event.request.url);
|
|
199
|
+
// Only cache GET requests for the app shell; let API calls pass through
|
|
200
|
+
if (event.request.method !== "GET" || url.pathname.startsWith("/api/")) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
event.respondWith(
|
|
204
|
+
fetch(event.request)
|
|
205
|
+
.then((response) => {
|
|
206
|
+
const clone = response.clone();
|
|
207
|
+
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, clone));
|
|
208
|
+
return response;
|
|
209
|
+
})
|
|
210
|
+
.catch(() => caches.match(event.request))
|
|
211
|
+
);
|
|
212
|
+
});
|
|
213
|
+
`;
|
|
214
|
+
var renderWebUiHtml = (options) => {
|
|
215
|
+
const agentInitial = (options?.agentName ?? "A").charAt(0).toUpperCase();
|
|
216
|
+
const agentName = options?.agentName ?? "Agent";
|
|
217
|
+
return `<!doctype html>
|
|
218
|
+
<html lang="en">
|
|
219
|
+
<head>
|
|
220
|
+
<meta charset="utf-8">
|
|
221
|
+
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no, viewport-fit=cover">
|
|
222
|
+
<meta name="theme-color" content="#000000">
|
|
223
|
+
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
224
|
+
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
|
|
225
|
+
<meta name="apple-mobile-web-app-title" content="${agentName}">
|
|
226
|
+
<link rel="manifest" href="/manifest.json">
|
|
227
|
+
<link rel="icon" href="/icon.svg" type="image/svg+xml">
|
|
228
|
+
<link rel="apple-touch-icon" href="/icon-192.png">
|
|
229
|
+
<title>${agentName}</title>
|
|
230
|
+
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Inconsolata:400,700">
|
|
231
|
+
<style>
|
|
232
|
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
|
233
|
+
html, body { height: 100vh; overflow: hidden; overscroll-behavior: none; touch-action: pan-y; }
|
|
234
|
+
body {
|
|
235
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Helvetica Neue", sans-serif;
|
|
236
|
+
background: #000;
|
|
237
|
+
color: #ededed;
|
|
238
|
+
font-size: 14px;
|
|
239
|
+
line-height: 1.5;
|
|
240
|
+
-webkit-font-smoothing: antialiased;
|
|
241
|
+
-moz-osx-font-smoothing: grayscale;
|
|
242
|
+
}
|
|
243
|
+
button, input, textarea { font: inherit; color: inherit; }
|
|
244
|
+
.hidden { display: none !important; }
|
|
245
|
+
a { color: #ededed; }
|
|
246
|
+
|
|
247
|
+
/* Auth */
|
|
248
|
+
.auth {
|
|
249
|
+
min-height: 100vh;
|
|
250
|
+
display: grid;
|
|
251
|
+
place-items: center;
|
|
252
|
+
padding: 20px;
|
|
253
|
+
background: #000;
|
|
254
|
+
}
|
|
255
|
+
.auth-card {
|
|
256
|
+
width: min(380px, 90vw);
|
|
257
|
+
background: #0a0a0a;
|
|
258
|
+
border: 1px solid rgba(255,255,255,0.08);
|
|
259
|
+
border-radius: 12px;
|
|
260
|
+
padding: 32px;
|
|
261
|
+
display: grid;
|
|
262
|
+
gap: 20px;
|
|
263
|
+
}
|
|
264
|
+
.auth-brand {
|
|
265
|
+
display: flex;
|
|
266
|
+
align-items: center;
|
|
267
|
+
gap: 8px;
|
|
268
|
+
}
|
|
269
|
+
.auth-brand svg { width: 20px; height: 20px; }
|
|
270
|
+
.auth-title {
|
|
271
|
+
font-size: 16px;
|
|
272
|
+
font-weight: 500;
|
|
273
|
+
letter-spacing: -0.01em;
|
|
274
|
+
}
|
|
275
|
+
.auth-text { color: #666; font-size: 13px; line-height: 1.5; }
|
|
276
|
+
.auth-input {
|
|
277
|
+
width: 100%;
|
|
278
|
+
background: #000;
|
|
279
|
+
border: 1px solid rgba(255,255,255,0.12);
|
|
280
|
+
border-radius: 6px;
|
|
281
|
+
color: #ededed;
|
|
282
|
+
padding: 10px 12px;
|
|
283
|
+
font-size: 14px;
|
|
284
|
+
outline: none;
|
|
285
|
+
transition: border-color 0.15s;
|
|
286
|
+
}
|
|
287
|
+
.auth-input:focus { border-color: rgba(255,255,255,0.3); }
|
|
288
|
+
.auth-input::placeholder { color: #555; }
|
|
289
|
+
.auth-submit {
|
|
290
|
+
background: #ededed;
|
|
291
|
+
color: #000;
|
|
292
|
+
border: 0;
|
|
293
|
+
border-radius: 6px;
|
|
294
|
+
padding: 10px 16px;
|
|
295
|
+
font-size: 14px;
|
|
296
|
+
font-weight: 500;
|
|
297
|
+
cursor: pointer;
|
|
298
|
+
transition: background 0.15s;
|
|
299
|
+
}
|
|
300
|
+
.auth-submit:hover { background: #fff; }
|
|
301
|
+
.error { color: #ff4444; font-size: 13px; min-height: 16px; }
|
|
302
|
+
.message-error {
|
|
303
|
+
background: rgba(255,68,68,0.08);
|
|
304
|
+
border: 1px solid rgba(255,68,68,0.25);
|
|
305
|
+
border-radius: 10px;
|
|
306
|
+
color: #ff6b6b;
|
|
307
|
+
padding: 12px 16px;
|
|
308
|
+
font-size: 13px;
|
|
309
|
+
line-height: 1.5;
|
|
310
|
+
max-width: 600px;
|
|
311
|
+
}
|
|
312
|
+
.message-error strong { color: #ff4444; }
|
|
313
|
+
|
|
314
|
+
/* Layout - use fixed positioning with explicit dimensions */
|
|
315
|
+
.shell {
|
|
316
|
+
position: fixed;
|
|
317
|
+
top: 0;
|
|
318
|
+
left: 0;
|
|
319
|
+
width: 100vw;
|
|
320
|
+
height: 100vh;
|
|
321
|
+
height: 100dvh; /* Dynamic viewport height for normal browsers */
|
|
322
|
+
display: flex;
|
|
323
|
+
overflow: hidden;
|
|
324
|
+
}
|
|
325
|
+
/* PWA standalone mode: use 100vh which works correctly */
|
|
326
|
+
@media (display-mode: standalone) {
|
|
327
|
+
.shell {
|
|
328
|
+
height: 100vh;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/* Edge swipe blocker - invisible touch target to intercept right edge gestures */
|
|
333
|
+
.edge-blocker-right {
|
|
334
|
+
position: fixed;
|
|
335
|
+
top: 0;
|
|
336
|
+
bottom: 0;
|
|
337
|
+
right: 0;
|
|
338
|
+
width: 20px;
|
|
339
|
+
z-index: 9999;
|
|
340
|
+
touch-action: none;
|
|
341
|
+
}
|
|
342
|
+
.sidebar {
|
|
343
|
+
width: 260px;
|
|
344
|
+
background: #000;
|
|
345
|
+
border-right: 1px solid rgba(255,255,255,0.06);
|
|
346
|
+
display: flex;
|
|
347
|
+
flex-direction: column;
|
|
348
|
+
padding: 12px 8px;
|
|
349
|
+
}
|
|
350
|
+
.new-chat-btn {
|
|
351
|
+
background: transparent;
|
|
352
|
+
border: 0;
|
|
353
|
+
color: #888;
|
|
354
|
+
border-radius: 12px;
|
|
355
|
+
height: 36px;
|
|
356
|
+
padding: 0 10px;
|
|
357
|
+
display: flex;
|
|
358
|
+
align-items: center;
|
|
359
|
+
gap: 8px;
|
|
360
|
+
font-size: 13px;
|
|
361
|
+
cursor: pointer;
|
|
362
|
+
transition: background 0.15s, color 0.15s;
|
|
363
|
+
}
|
|
364
|
+
.new-chat-btn:hover { color: #ededed; }
|
|
365
|
+
.new-chat-btn svg { width: 16px; height: 16px; }
|
|
366
|
+
.conversation-list {
|
|
367
|
+
flex: 1;
|
|
368
|
+
overflow-y: auto;
|
|
369
|
+
margin-top: 12px;
|
|
370
|
+
display: flex;
|
|
371
|
+
flex-direction: column;
|
|
372
|
+
gap: 2px;
|
|
373
|
+
}
|
|
374
|
+
.conversation-item {
|
|
375
|
+
padding: 7px 28px 7px 10px;
|
|
376
|
+
border-radius: 12px;
|
|
377
|
+
cursor: pointer;
|
|
378
|
+
font-size: 13px;
|
|
379
|
+
color: #555;
|
|
380
|
+
white-space: nowrap;
|
|
381
|
+
overflow: hidden;
|
|
382
|
+
text-overflow: ellipsis;
|
|
383
|
+
position: relative;
|
|
384
|
+
transition: color 0.15s;
|
|
385
|
+
}
|
|
386
|
+
.conversation-item:hover { color: #999; }
|
|
387
|
+
.conversation-item.active {
|
|
388
|
+
color: #ededed;
|
|
389
|
+
}
|
|
390
|
+
.conversation-item .delete-btn {
|
|
391
|
+
position: absolute;
|
|
392
|
+
right: 0;
|
|
393
|
+
top: 0;
|
|
394
|
+
bottom: 0;
|
|
395
|
+
opacity: 0;
|
|
396
|
+
background: #000;
|
|
397
|
+
border: 0;
|
|
398
|
+
color: #444;
|
|
399
|
+
padding: 0 8px;
|
|
400
|
+
border-radius: 0 4px 4px 0;
|
|
401
|
+
cursor: pointer;
|
|
402
|
+
font-size: 16px;
|
|
403
|
+
line-height: 1;
|
|
404
|
+
display: grid;
|
|
405
|
+
place-items: center;
|
|
406
|
+
transition: opacity 0.15s, color 0.15s;
|
|
407
|
+
}
|
|
408
|
+
.conversation-item:hover .delete-btn { opacity: 1; }
|
|
409
|
+
.conversation-item.active .delete-btn { background: rgba(0,0,0,1); }
|
|
410
|
+
.conversation-item .delete-btn::before {
|
|
411
|
+
content: "";
|
|
412
|
+
position: absolute;
|
|
413
|
+
right: 100%;
|
|
414
|
+
top: 0;
|
|
415
|
+
bottom: 0;
|
|
416
|
+
width: 24px;
|
|
417
|
+
background: linear-gradient(to right, transparent, #000);
|
|
418
|
+
pointer-events: none;
|
|
419
|
+
}
|
|
420
|
+
.conversation-item.active .delete-btn::before {
|
|
421
|
+
background: linear-gradient(to right, transparent, rgba(0,0,0,1));
|
|
422
|
+
}
|
|
423
|
+
.conversation-item .delete-btn:hover { color: #888; }
|
|
424
|
+
.conversation-item .delete-btn.confirming {
|
|
425
|
+
opacity: 1;
|
|
426
|
+
width: auto;
|
|
427
|
+
padding: 0 8px;
|
|
428
|
+
font-size: 11px;
|
|
429
|
+
color: #ff4444;
|
|
430
|
+
border-radius: 3px;
|
|
431
|
+
}
|
|
432
|
+
.conversation-item .delete-btn.confirming:hover {
|
|
433
|
+
color: #ff6666;
|
|
434
|
+
}
|
|
435
|
+
.sidebar-footer {
|
|
436
|
+
margin-top: auto;
|
|
437
|
+
padding-top: 8px;
|
|
438
|
+
}
|
|
439
|
+
.logout-btn {
|
|
440
|
+
background: transparent;
|
|
441
|
+
border: 0;
|
|
442
|
+
color: #555;
|
|
443
|
+
width: 100%;
|
|
444
|
+
padding: 8px 10px;
|
|
445
|
+
text-align: left;
|
|
446
|
+
border-radius: 6px;
|
|
447
|
+
cursor: pointer;
|
|
448
|
+
font-size: 13px;
|
|
449
|
+
transition: color 0.15s, background 0.15s;
|
|
450
|
+
}
|
|
451
|
+
.logout-btn:hover { color: #888; }
|
|
452
|
+
|
|
453
|
+
/* Main */
|
|
454
|
+
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; max-width: 100%; background: #000; overflow: hidden; }
|
|
455
|
+
.topbar {
|
|
456
|
+
height: calc(52px + env(safe-area-inset-top, 0px));
|
|
457
|
+
padding-top: env(safe-area-inset-top, 0px);
|
|
458
|
+
display: flex;
|
|
459
|
+
align-items: center;
|
|
460
|
+
justify-content: center;
|
|
461
|
+
font-size: 13px;
|
|
462
|
+
font-weight: 500;
|
|
463
|
+
color: #888;
|
|
464
|
+
border-bottom: 1px solid rgba(255,255,255,0.06);
|
|
465
|
+
position: relative;
|
|
466
|
+
flex-shrink: 0;
|
|
467
|
+
}
|
|
468
|
+
.topbar-title {
|
|
469
|
+
max-width: calc(100% - 100px);
|
|
470
|
+
overflow: hidden;
|
|
471
|
+
text-overflow: ellipsis;
|
|
472
|
+
white-space: nowrap;
|
|
473
|
+
letter-spacing: -0.01em;
|
|
474
|
+
padding: 0 50px;
|
|
475
|
+
}
|
|
476
|
+
.sidebar-toggle {
|
|
477
|
+
display: none;
|
|
478
|
+
position: absolute;
|
|
479
|
+
left: 12px;
|
|
480
|
+
bottom: 4px; /* Position from bottom of topbar content area */
|
|
481
|
+
background: transparent;
|
|
482
|
+
border: 0;
|
|
483
|
+
color: #666;
|
|
484
|
+
width: 44px;
|
|
485
|
+
height: 44px;
|
|
486
|
+
border-radius: 6px;
|
|
487
|
+
cursor: pointer;
|
|
488
|
+
transition: color 0.15s, background 0.15s;
|
|
489
|
+
font-size: 18px;
|
|
490
|
+
z-index: 10;
|
|
491
|
+
-webkit-tap-highlight-color: transparent;
|
|
492
|
+
}
|
|
493
|
+
.sidebar-toggle:hover { color: #ededed; }
|
|
494
|
+
.topbar-new-chat {
|
|
495
|
+
display: none;
|
|
496
|
+
position: absolute;
|
|
497
|
+
right: 12px;
|
|
498
|
+
bottom: 4px;
|
|
499
|
+
background: transparent;
|
|
500
|
+
border: 0;
|
|
501
|
+
color: #666;
|
|
502
|
+
width: 44px;
|
|
503
|
+
height: 44px;
|
|
504
|
+
border-radius: 6px;
|
|
505
|
+
cursor: pointer;
|
|
506
|
+
transition: color 0.15s, background 0.15s;
|
|
507
|
+
z-index: 10;
|
|
508
|
+
-webkit-tap-highlight-color: transparent;
|
|
509
|
+
}
|
|
510
|
+
.topbar-new-chat:hover { color: #ededed; }
|
|
511
|
+
.topbar-new-chat svg { width: 16px; height: 16px; }
|
|
512
|
+
|
|
513
|
+
/* Messages */
|
|
514
|
+
.messages { flex: 1; overflow-y: auto; overflow-x: hidden; padding: 24px 24px; }
|
|
515
|
+
.messages-column { max-width: 680px; margin: 0 auto; }
|
|
516
|
+
.message-row { margin-bottom: 24px; display: flex; max-width: 100%; }
|
|
517
|
+
.message-row.user { justify-content: flex-end; }
|
|
518
|
+
.assistant-wrap { display: flex; gap: 12px; max-width: 100%; min-width: 0; }
|
|
519
|
+
.assistant-avatar {
|
|
520
|
+
width: 24px;
|
|
521
|
+
height: 24px;
|
|
522
|
+
background: #ededed;
|
|
523
|
+
color: #000;
|
|
524
|
+
border-radius: 6px;
|
|
525
|
+
display: grid;
|
|
526
|
+
place-items: center;
|
|
527
|
+
font-size: 11px;
|
|
528
|
+
font-weight: 600;
|
|
529
|
+
flex-shrink: 0;
|
|
530
|
+
margin-top: 2px;
|
|
531
|
+
}
|
|
532
|
+
.assistant-content {
|
|
533
|
+
line-height: 1.65;
|
|
534
|
+
color: #ededed;
|
|
535
|
+
font-size: 14px;
|
|
536
|
+
min-width: 0;
|
|
537
|
+
max-width: 100%;
|
|
538
|
+
overflow-wrap: break-word;
|
|
539
|
+
word-break: break-word;
|
|
540
|
+
margin-top: 2px;
|
|
541
|
+
}
|
|
542
|
+
.assistant-content p { margin: 0 0 12px; }
|
|
543
|
+
.assistant-content p:last-child { margin-bottom: 0; }
|
|
544
|
+
.assistant-content ul, .assistant-content ol { margin: 8px 0; padding-left: 20px; }
|
|
545
|
+
.assistant-content li { margin: 4px 0; }
|
|
546
|
+
.assistant-content strong { font-weight: 600; color: #fff; }
|
|
547
|
+
.assistant-content h2 {
|
|
548
|
+
font-size: 16px;
|
|
549
|
+
font-weight: 600;
|
|
550
|
+
letter-spacing: -0.02em;
|
|
551
|
+
margin: 20px 0 8px;
|
|
552
|
+
color: #fff;
|
|
553
|
+
}
|
|
554
|
+
.assistant-content h3 {
|
|
555
|
+
font-size: 14px;
|
|
556
|
+
font-weight: 600;
|
|
557
|
+
letter-spacing: -0.01em;
|
|
558
|
+
margin: 16px 0 6px;
|
|
559
|
+
color: #fff;
|
|
560
|
+
}
|
|
561
|
+
.assistant-content code {
|
|
562
|
+
background: rgba(255,255,255,0.06);
|
|
563
|
+
border: 1px solid rgba(255,255,255,0.06);
|
|
564
|
+
padding: 2px 5px;
|
|
565
|
+
border-radius: 4px;
|
|
566
|
+
font-family: ui-monospace, "SF Mono", "Fira Code", monospace;
|
|
567
|
+
font-size: 0.88em;
|
|
568
|
+
}
|
|
569
|
+
.assistant-content pre {
|
|
570
|
+
background: #0a0a0a;
|
|
571
|
+
border: 1px solid rgba(255,255,255,0.06);
|
|
572
|
+
padding: 14px 16px;
|
|
573
|
+
border-radius: 8px;
|
|
574
|
+
overflow-x: auto;
|
|
575
|
+
margin: 14px 0;
|
|
576
|
+
}
|
|
577
|
+
.assistant-content pre code {
|
|
578
|
+
background: none;
|
|
579
|
+
border: 0;
|
|
580
|
+
padding: 0;
|
|
581
|
+
font-size: 13px;
|
|
582
|
+
line-height: 1.5;
|
|
583
|
+
}
|
|
584
|
+
.tool-activity {
|
|
585
|
+
margin-top: 12px;
|
|
586
|
+
border: 1px solid rgba(255,255,255,0.08);
|
|
587
|
+
background: rgba(255,255,255,0.03);
|
|
588
|
+
border-radius: 10px;
|
|
589
|
+
font-size: 12px;
|
|
590
|
+
line-height: 1.45;
|
|
591
|
+
color: #bcbcbc;
|
|
592
|
+
max-width: 300px;
|
|
593
|
+
}
|
|
594
|
+
.tool-activity-disclosure {
|
|
595
|
+
display: block;
|
|
596
|
+
}
|
|
597
|
+
.tool-activity-summary {
|
|
598
|
+
list-style: none;
|
|
599
|
+
display: flex;
|
|
600
|
+
align-items: center;
|
|
601
|
+
gap: 8px;
|
|
602
|
+
cursor: pointer;
|
|
603
|
+
padding: 10px 12px;
|
|
604
|
+
user-select: none;
|
|
605
|
+
}
|
|
606
|
+
.tool-activity-summary::-webkit-details-marker {
|
|
607
|
+
display: none;
|
|
608
|
+
}
|
|
609
|
+
.tool-activity-label {
|
|
610
|
+
font-size: 11px;
|
|
611
|
+
text-transform: uppercase;
|
|
612
|
+
letter-spacing: 0.06em;
|
|
613
|
+
color: #8a8a8a;
|
|
614
|
+
font-weight: 600;
|
|
615
|
+
}
|
|
616
|
+
.tool-activity-caret {
|
|
617
|
+
margin-left: auto;
|
|
618
|
+
color: #8a8a8a;
|
|
619
|
+
display: inline-flex;
|
|
620
|
+
align-items: center;
|
|
621
|
+
justify-content: center;
|
|
622
|
+
transition: transform 120ms ease;
|
|
623
|
+
transform: rotate(0deg);
|
|
624
|
+
}
|
|
625
|
+
.tool-activity-caret svg {
|
|
626
|
+
width: 14px;
|
|
627
|
+
height: 14px;
|
|
628
|
+
display: block;
|
|
629
|
+
}
|
|
630
|
+
.tool-activity-disclosure[open] .tool-activity-caret {
|
|
631
|
+
transform: rotate(90deg);
|
|
632
|
+
}
|
|
633
|
+
.tool-activity-list {
|
|
634
|
+
display: grid;
|
|
635
|
+
gap: 6px;
|
|
636
|
+
padding: 0 12px 10px;
|
|
637
|
+
}
|
|
638
|
+
.tool-activity-item {
|
|
639
|
+
font-family: ui-monospace, "SF Mono", "Fira Code", monospace;
|
|
640
|
+
background: rgba(255,255,255,0.04);
|
|
641
|
+
border-radius: 6px;
|
|
642
|
+
padding: 4px 7px;
|
|
643
|
+
color: #d6d6d6;
|
|
644
|
+
}
|
|
645
|
+
.user-bubble {
|
|
646
|
+
background: #111;
|
|
647
|
+
border: 1px solid rgba(255,255,255,0.08);
|
|
648
|
+
padding: 10px 16px;
|
|
649
|
+
border-radius: 18px;
|
|
650
|
+
max-width: 70%;
|
|
651
|
+
font-size: 14px;
|
|
652
|
+
line-height: 1.5;
|
|
653
|
+
overflow-wrap: break-word;
|
|
654
|
+
word-break: break-word;
|
|
655
|
+
}
|
|
656
|
+
.empty-state {
|
|
657
|
+
display: flex;
|
|
658
|
+
flex-direction: column;
|
|
659
|
+
align-items: center;
|
|
660
|
+
justify-content: center;
|
|
661
|
+
height: 100%;
|
|
662
|
+
gap: 16px;
|
|
663
|
+
color: #555;
|
|
664
|
+
}
|
|
665
|
+
.empty-state .assistant-avatar {
|
|
666
|
+
width: 36px;
|
|
667
|
+
height: 36px;
|
|
668
|
+
font-size: 14px;
|
|
669
|
+
border-radius: 8px;
|
|
670
|
+
}
|
|
671
|
+
.empty-state-text {
|
|
672
|
+
font-size: 14px;
|
|
673
|
+
color: #555;
|
|
674
|
+
}
|
|
675
|
+
.thinking-indicator {
|
|
676
|
+
display: inline-block;
|
|
677
|
+
font-family: Inconsolata, monospace;
|
|
678
|
+
font-size: 20px;
|
|
679
|
+
line-height: 1;
|
|
680
|
+
vertical-align: middle;
|
|
681
|
+
color: #ededed;
|
|
682
|
+
opacity: 0.5;
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
/* Composer */
|
|
686
|
+
.composer {
|
|
687
|
+
padding: 12px 24px 24px;
|
|
688
|
+
position: relative;
|
|
689
|
+
}
|
|
690
|
+
/* PWA standalone mode - extra bottom padding */
|
|
691
|
+
@media (display-mode: standalone), (-webkit-touch-callout: none) {
|
|
692
|
+
.composer {
|
|
693
|
+
padding-bottom: 32px;
|
|
694
|
+
}
|
|
695
|
+
}
|
|
696
|
+
@supports (-webkit-touch-callout: none) {
|
|
697
|
+
/* iOS Safari standalone check via JS class */
|
|
698
|
+
.standalone .composer {
|
|
699
|
+
padding-bottom: 32px;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
.composer::before {
|
|
703
|
+
content: "";
|
|
704
|
+
position: absolute;
|
|
705
|
+
left: 0;
|
|
706
|
+
right: 0;
|
|
707
|
+
bottom: 100%;
|
|
708
|
+
height: 48px;
|
|
709
|
+
background: linear-gradient(to top, #000 0%, transparent 100%);
|
|
710
|
+
pointer-events: none;
|
|
711
|
+
}
|
|
712
|
+
.composer-inner { max-width: 680px; margin: 0 auto; }
|
|
713
|
+
.composer-shell {
|
|
714
|
+
background: #0a0a0a;
|
|
715
|
+
border: 1px solid rgba(255,255,255,0.1);
|
|
716
|
+
border-radius: 9999px;
|
|
717
|
+
display: flex;
|
|
718
|
+
align-items: center;
|
|
719
|
+
padding: 4px 6px 4px 18px;
|
|
720
|
+
transition: border-color 0.15s;
|
|
721
|
+
}
|
|
722
|
+
.composer-shell:focus-within { border-color: rgba(255,255,255,0.2); }
|
|
723
|
+
.composer-input {
|
|
724
|
+
flex: 1;
|
|
725
|
+
background: transparent;
|
|
726
|
+
border: 0;
|
|
727
|
+
outline: none;
|
|
728
|
+
color: #ededed;
|
|
729
|
+
min-height: 40px;
|
|
730
|
+
max-height: 200px;
|
|
731
|
+
resize: none;
|
|
732
|
+
padding: 10px 0 8px;
|
|
733
|
+
font-size: 14px;
|
|
734
|
+
line-height: 1.5;
|
|
735
|
+
}
|
|
736
|
+
.composer-input::placeholder { color: #444; }
|
|
737
|
+
.send-btn {
|
|
738
|
+
width: 32px;
|
|
739
|
+
height: 32px;
|
|
740
|
+
background: #ededed;
|
|
741
|
+
border: 0;
|
|
742
|
+
border-radius: 50%;
|
|
743
|
+
color: #000;
|
|
744
|
+
cursor: pointer;
|
|
745
|
+
display: grid;
|
|
746
|
+
place-items: center;
|
|
747
|
+
flex-shrink: 0;
|
|
748
|
+
margin-bottom: 2px;
|
|
749
|
+
transition: background 0.15s, opacity 0.15s;
|
|
750
|
+
}
|
|
751
|
+
.send-btn:hover { background: #fff; }
|
|
752
|
+
.send-btn:disabled { opacity: 0.2; cursor: default; }
|
|
753
|
+
.send-btn:disabled:hover { background: #ededed; }
|
|
754
|
+
.disclaimer {
|
|
755
|
+
text-align: center;
|
|
756
|
+
color: #333;
|
|
757
|
+
font-size: 12px;
|
|
758
|
+
margin-top: 10px;
|
|
759
|
+
}
|
|
760
|
+
|
|
761
|
+
/* Scrollbar */
|
|
762
|
+
::-webkit-scrollbar { width: 6px; }
|
|
763
|
+
::-webkit-scrollbar-track { background: transparent; }
|
|
764
|
+
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.1); border-radius: 3px; }
|
|
765
|
+
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.16); }
|
|
766
|
+
|
|
767
|
+
/* Mobile */
|
|
768
|
+
@media (max-width: 768px) {
|
|
769
|
+
.sidebar {
|
|
770
|
+
position: fixed;
|
|
771
|
+
inset: 0 auto 0 0;
|
|
772
|
+
z-index: 100;
|
|
773
|
+
transform: translateX(-100%);
|
|
774
|
+
padding-top: calc(env(safe-area-inset-top, 0px) + 12px);
|
|
775
|
+
will-change: transform;
|
|
776
|
+
}
|
|
777
|
+
.sidebar.dragging { transition: none; }
|
|
778
|
+
.sidebar:not(.dragging) { transition: transform 0.25s cubic-bezier(0.4, 0, 0.2, 1); }
|
|
779
|
+
.shell.sidebar-open .sidebar { transform: translateX(0); }
|
|
780
|
+
.sidebar-toggle { display: grid; place-items: center; }
|
|
781
|
+
.topbar-new-chat { display: grid; place-items: center; }
|
|
782
|
+
.sidebar-backdrop {
|
|
783
|
+
position: fixed;
|
|
784
|
+
inset: 0;
|
|
785
|
+
background: rgba(0,0,0,0.6);
|
|
786
|
+
z-index: 50;
|
|
787
|
+
backdrop-filter: blur(2px);
|
|
788
|
+
-webkit-backdrop-filter: blur(2px);
|
|
789
|
+
opacity: 0;
|
|
790
|
+
pointer-events: none;
|
|
791
|
+
will-change: opacity;
|
|
792
|
+
}
|
|
793
|
+
.sidebar-backdrop:not(.dragging) { transition: opacity 0.25s cubic-bezier(0.4, 0, 0.2, 1); }
|
|
794
|
+
.sidebar-backdrop.dragging { transition: none; }
|
|
795
|
+
.shell.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }
|
|
796
|
+
.messages { padding: 16px; }
|
|
797
|
+
.composer { padding: 8px 16px 16px; }
|
|
798
|
+
/* Always show delete button on mobile (no hover) */
|
|
799
|
+
.conversation-item .delete-btn { opacity: 1; }
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
/* Reduced motion */
|
|
803
|
+
@media (prefers-reduced-motion: reduce) {
|
|
804
|
+
*, *::before, *::after {
|
|
805
|
+
animation-duration: 0.01ms !important;
|
|
806
|
+
transition-duration: 0.01ms !important;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
</style>
|
|
810
|
+
</head>
|
|
811
|
+
<body data-agent-initial="${agentInitial}" data-agent-name="${agentName}">
|
|
812
|
+
<div class="edge-blocker-right"></div>
|
|
813
|
+
<div id="auth" class="auth hidden">
|
|
814
|
+
<form id="login-form" class="auth-card">
|
|
815
|
+
<div class="auth-brand">
|
|
816
|
+
<svg viewBox="0 0 24 24" fill="none"><path d="M12 2L2 19.5h20L12 2z" fill="currentColor"/></svg>
|
|
817
|
+
<h2 class="auth-title">Poncho</h2>
|
|
818
|
+
</div>
|
|
819
|
+
<p class="auth-text">Enter the passphrase to continue.</p>
|
|
820
|
+
<input id="passphrase" class="auth-input" type="password" placeholder="Passphrase" required>
|
|
821
|
+
<button class="auth-submit" type="submit">Continue</button>
|
|
822
|
+
<div id="login-error" class="error"></div>
|
|
823
|
+
</form>
|
|
824
|
+
</div>
|
|
825
|
+
|
|
826
|
+
<div id="app" class="shell hidden">
|
|
827
|
+
<aside class="sidebar">
|
|
828
|
+
<button id="new-chat" class="new-chat-btn">
|
|
829
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 5v14M5 12h14"/></svg>
|
|
830
|
+
</button>
|
|
831
|
+
<div id="conversation-list" class="conversation-list"></div>
|
|
832
|
+
<div class="sidebar-footer">
|
|
833
|
+
<button id="logout" class="logout-btn">Log out</button>
|
|
834
|
+
</div>
|
|
835
|
+
</aside>
|
|
836
|
+
<div id="sidebar-backdrop" class="sidebar-backdrop"></div>
|
|
837
|
+
<main class="main">
|
|
838
|
+
<div class="topbar">
|
|
839
|
+
<button id="sidebar-toggle" class="sidebar-toggle">☰</button>
|
|
840
|
+
<div id="chat-title" class="topbar-title"></div>
|
|
841
|
+
<button id="topbar-new-chat" class="topbar-new-chat">
|
|
842
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M12 5v14M5 12h14"/></svg>
|
|
843
|
+
</button>
|
|
844
|
+
</div>
|
|
845
|
+
<div id="messages" class="messages">
|
|
846
|
+
<div class="empty-state">
|
|
847
|
+
<div class="assistant-avatar">${agentInitial}</div>
|
|
848
|
+
<div class="empty-state-text">How can I help you today?</div>
|
|
849
|
+
</div>
|
|
850
|
+
</div>
|
|
851
|
+
<form id="composer" class="composer">
|
|
852
|
+
<div class="composer-inner">
|
|
853
|
+
<div class="composer-shell">
|
|
854
|
+
<textarea id="prompt" class="composer-input" placeholder="Send a message..." rows="1"></textarea>
|
|
855
|
+
<button id="send" class="send-btn" type="submit">
|
|
856
|
+
<svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M8 12V4M4 7l4-4 4 4" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/></svg>
|
|
857
|
+
</button>
|
|
858
|
+
</div>
|
|
859
|
+
</div>
|
|
860
|
+
</form>
|
|
861
|
+
</main>
|
|
862
|
+
</div>
|
|
863
|
+
|
|
864
|
+
<script>
|
|
865
|
+
const state = {
|
|
866
|
+
csrfToken: "",
|
|
867
|
+
conversations: [],
|
|
868
|
+
activeConversationId: null,
|
|
869
|
+
activeMessages: [],
|
|
870
|
+
isStreaming: false,
|
|
871
|
+
confirmDeleteId: null
|
|
872
|
+
};
|
|
873
|
+
|
|
874
|
+
const agentInitial = document.body.dataset.agentInitial || "A";
|
|
875
|
+
const $ = (id) => document.getElementById(id);
|
|
876
|
+
const elements = {
|
|
877
|
+
auth: $("auth"),
|
|
878
|
+
app: $("app"),
|
|
879
|
+
loginForm: $("login-form"),
|
|
880
|
+
passphrase: $("passphrase"),
|
|
881
|
+
loginError: $("login-error"),
|
|
882
|
+
list: $("conversation-list"),
|
|
883
|
+
newChat: $("new-chat"),
|
|
884
|
+
topbarNewChat: $("topbar-new-chat"),
|
|
885
|
+
messages: $("messages"),
|
|
886
|
+
chatTitle: $("chat-title"),
|
|
887
|
+
logout: $("logout"),
|
|
888
|
+
composer: $("composer"),
|
|
889
|
+
prompt: $("prompt"),
|
|
890
|
+
send: $("send"),
|
|
891
|
+
shell: $("app"),
|
|
892
|
+
sidebarToggle: $("sidebar-toggle"),
|
|
893
|
+
sidebarBackdrop: $("sidebar-backdrop")
|
|
894
|
+
};
|
|
895
|
+
|
|
896
|
+
const pushConversationUrl = (conversationId) => {
|
|
897
|
+
const target = conversationId ? "/c/" + encodeURIComponent(conversationId) : "/";
|
|
898
|
+
if (window.location.pathname !== target) {
|
|
899
|
+
history.pushState({ conversationId: conversationId || null }, "", target);
|
|
900
|
+
}
|
|
901
|
+
};
|
|
902
|
+
|
|
903
|
+
const replaceConversationUrl = (conversationId) => {
|
|
904
|
+
const target = conversationId ? "/c/" + encodeURIComponent(conversationId) : "/";
|
|
905
|
+
if (window.location.pathname !== target) {
|
|
906
|
+
history.replaceState({ conversationId: conversationId || null }, "", target);
|
|
907
|
+
}
|
|
908
|
+
};
|
|
909
|
+
|
|
910
|
+
const getConversationIdFromUrl = () => {
|
|
911
|
+
const match = window.location.pathname.match(/^\\/c\\/([^\\/]+)/);
|
|
912
|
+
return match ? decodeURIComponent(match[1]) : null;
|
|
913
|
+
};
|
|
914
|
+
|
|
915
|
+
const mutatingMethods = new Set(["POST", "PATCH", "PUT", "DELETE"]);
|
|
916
|
+
|
|
917
|
+
const api = async (path, options = {}) => {
|
|
918
|
+
const method = (options.method || "GET").toUpperCase();
|
|
919
|
+
const headers = { ...(options.headers || {}) };
|
|
920
|
+
if (mutatingMethods.has(method) && state.csrfToken) {
|
|
921
|
+
headers["x-csrf-token"] = state.csrfToken;
|
|
922
|
+
}
|
|
923
|
+
if (options.body && !headers["Content-Type"]) {
|
|
924
|
+
headers["Content-Type"] = "application/json";
|
|
925
|
+
}
|
|
926
|
+
const response = await fetch(path, { credentials: "include", ...options, method, headers });
|
|
927
|
+
if (!response.ok) {
|
|
928
|
+
let payload = {};
|
|
929
|
+
try { payload = await response.json(); } catch {}
|
|
930
|
+
const error = new Error(payload.message || ("Request failed: " + response.status));
|
|
931
|
+
error.status = response.status;
|
|
932
|
+
error.payload = payload;
|
|
933
|
+
throw error;
|
|
934
|
+
}
|
|
935
|
+
const contentType = response.headers.get("content-type") || "";
|
|
936
|
+
if (contentType.includes("application/json")) {
|
|
937
|
+
return await response.json();
|
|
938
|
+
}
|
|
939
|
+
return await response.text();
|
|
940
|
+
};
|
|
941
|
+
|
|
942
|
+
const escapeHtml = (value) =>
|
|
943
|
+
String(value || "")
|
|
944
|
+
.replace(/&/g, "&")
|
|
945
|
+
.replace(/</g, "<")
|
|
946
|
+
.replace(/>/g, ">")
|
|
947
|
+
.replace(/"/g, """)
|
|
948
|
+
.replace(/'/g, "'");
|
|
949
|
+
|
|
950
|
+
const renderInlineMarkdown = (value) => {
|
|
951
|
+
let html = escapeHtml(value);
|
|
952
|
+
html = html.replace(/\\*\\*([^*]+)\\*\\*/g, "<strong>$1</strong>");
|
|
953
|
+
html = html.replace(/\\x60([^\\x60]+)\\x60/g, "<code>$1</code>");
|
|
954
|
+
return html;
|
|
955
|
+
};
|
|
956
|
+
|
|
957
|
+
const renderMarkdownBlock = (value) => {
|
|
958
|
+
const lines = String(value || "").split("\\n");
|
|
959
|
+
let html = "";
|
|
960
|
+
let inList = false;
|
|
961
|
+
|
|
962
|
+
for (const rawLine of lines) {
|
|
963
|
+
const line = rawLine.trimEnd();
|
|
964
|
+
const trimmed = line.trim();
|
|
965
|
+
const headingMatch = trimmed.match(/^(#{1,3})\\s+(.+)$/);
|
|
966
|
+
|
|
967
|
+
if (headingMatch) {
|
|
968
|
+
if (inList) {
|
|
969
|
+
html += "</ul>";
|
|
970
|
+
inList = false;
|
|
971
|
+
}
|
|
972
|
+
const level = Math.min(3, headingMatch[1].length);
|
|
973
|
+
const tag = level === 1 ? "h2" : level === 2 ? "h3" : "p";
|
|
974
|
+
html += "<" + tag + ">" + renderInlineMarkdown(headingMatch[2]) + "</" + tag + ">";
|
|
975
|
+
continue;
|
|
976
|
+
}
|
|
977
|
+
|
|
978
|
+
if (/^\\s*-\\s+/.test(line)) {
|
|
979
|
+
if (!inList) {
|
|
980
|
+
html += "<ul>";
|
|
981
|
+
inList = true;
|
|
982
|
+
}
|
|
983
|
+
html += "<li>" + renderInlineMarkdown(line.replace(/^\\s*-\\s+/, "")) + "</li>";
|
|
984
|
+
continue;
|
|
985
|
+
}
|
|
986
|
+
if (inList) {
|
|
987
|
+
html += "</ul>";
|
|
988
|
+
inList = false;
|
|
989
|
+
}
|
|
990
|
+
if (trimmed.length === 0) {
|
|
991
|
+
continue;
|
|
992
|
+
}
|
|
993
|
+
html += "<p>" + renderInlineMarkdown(line) + "</p>";
|
|
994
|
+
}
|
|
995
|
+
|
|
996
|
+
if (inList) {
|
|
997
|
+
html += "</ul>";
|
|
998
|
+
}
|
|
999
|
+
return html;
|
|
1000
|
+
};
|
|
1001
|
+
|
|
1002
|
+
const renderAssistantMarkdown = (value) => {
|
|
1003
|
+
const source = String(value || "");
|
|
1004
|
+
const fenceRegex = /\\x60\\x60\\x60([\\s\\S]*?)\\x60\\x60\\x60/g;
|
|
1005
|
+
let html = "";
|
|
1006
|
+
let lastIndex = 0;
|
|
1007
|
+
let match;
|
|
1008
|
+
|
|
1009
|
+
while ((match = fenceRegex.exec(source))) {
|
|
1010
|
+
const before = source.slice(lastIndex, match.index);
|
|
1011
|
+
html += renderMarkdownBlock(before);
|
|
1012
|
+
const codeText = String(match[1] || "").replace(/^\\n+|\\n+$/g, "");
|
|
1013
|
+
html += "<pre><code>" + escapeHtml(codeText) + "</code></pre>";
|
|
1014
|
+
lastIndex = match.index + match[0].length;
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
html += renderMarkdownBlock(source.slice(lastIndex));
|
|
1018
|
+
return html || "<p></p>";
|
|
1019
|
+
};
|
|
1020
|
+
|
|
1021
|
+
const extractToolActivity = (value) => {
|
|
1022
|
+
const source = String(value || "");
|
|
1023
|
+
let markerIndex = source.lastIndexOf("\\n### Tool activity\\n");
|
|
1024
|
+
if (markerIndex < 0 && source.startsWith("### Tool activity\\n")) {
|
|
1025
|
+
markerIndex = 0;
|
|
1026
|
+
}
|
|
1027
|
+
if (markerIndex < 0) {
|
|
1028
|
+
return { content: source, activities: [] };
|
|
1029
|
+
}
|
|
1030
|
+
const content = markerIndex === 0 ? "" : source.slice(0, markerIndex).trimEnd();
|
|
1031
|
+
const rawSection = markerIndex === 0 ? source : source.slice(markerIndex + 1);
|
|
1032
|
+
const afterHeading = rawSection.replace(/^### Tool activity\\s*\\n?/, "");
|
|
1033
|
+
const activities = afterHeading
|
|
1034
|
+
.split("\\n")
|
|
1035
|
+
.map((line) => line.trim())
|
|
1036
|
+
.filter((line) => line.startsWith("- "))
|
|
1037
|
+
.map((line) => line.slice(2).trim())
|
|
1038
|
+
.filter(Boolean);
|
|
1039
|
+
return { content, activities };
|
|
1040
|
+
};
|
|
1041
|
+
|
|
1042
|
+
const renderToolActivity = (items) => {
|
|
1043
|
+
if (!items || !items.length) {
|
|
1044
|
+
return "";
|
|
1045
|
+
}
|
|
1046
|
+
const chips = items
|
|
1047
|
+
.map((item) => '<div class="tool-activity-item">' + escapeHtml(item) + "</div>")
|
|
1048
|
+
.join("");
|
|
1049
|
+
return (
|
|
1050
|
+
'<div class="tool-activity">' +
|
|
1051
|
+
'<details class="tool-activity-disclosure">' +
|
|
1052
|
+
'<summary class="tool-activity-summary">' +
|
|
1053
|
+
'<span class="tool-activity-label">Tool activity</span>' +
|
|
1054
|
+
'<span class="tool-activity-caret" aria-hidden="true"><svg viewBox="0 0 12 12" fill="none"><path d="M4.5 2.75L8 6L4.5 9.25" stroke="currentColor" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"></path></svg></span>' +
|
|
1055
|
+
"</summary>" +
|
|
1056
|
+
'<div class="tool-activity-list">' +
|
|
1057
|
+
chips +
|
|
1058
|
+
"</div>" +
|
|
1059
|
+
"</details>" +
|
|
1060
|
+
"</div>"
|
|
1061
|
+
);
|
|
1062
|
+
};
|
|
1063
|
+
|
|
1064
|
+
const formatDate = (epoch) => {
|
|
1065
|
+
try {
|
|
1066
|
+
const date = new Date(epoch);
|
|
1067
|
+
const now = new Date();
|
|
1068
|
+
const startOfToday = new Date(now.getFullYear(), now.getMonth(), now.getDate()).getTime();
|
|
1069
|
+
const startOfDate = new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();
|
|
1070
|
+
const dayDiff = Math.floor((startOfToday - startOfDate) / 86400000);
|
|
1071
|
+
if (dayDiff === 0) {
|
|
1072
|
+
return "Today";
|
|
1073
|
+
}
|
|
1074
|
+
if (dayDiff === 1) {
|
|
1075
|
+
return "Yesterday";
|
|
1076
|
+
}
|
|
1077
|
+
if (dayDiff < 7 && dayDiff > 1) {
|
|
1078
|
+
return date.toLocaleDateString(undefined, { weekday: "short" });
|
|
1079
|
+
}
|
|
1080
|
+
return date.toLocaleDateString(undefined, { month: "short", day: "numeric" });
|
|
1081
|
+
} catch {
|
|
1082
|
+
return "";
|
|
1083
|
+
}
|
|
1084
|
+
};
|
|
1085
|
+
|
|
1086
|
+
const isMobile = () => window.matchMedia("(max-width: 900px)").matches;
|
|
1087
|
+
|
|
1088
|
+
const setSidebarOpen = (open) => {
|
|
1089
|
+
if (!isMobile()) {
|
|
1090
|
+
elements.shell.classList.remove("sidebar-open");
|
|
1091
|
+
return;
|
|
1092
|
+
}
|
|
1093
|
+
elements.shell.classList.toggle("sidebar-open", open);
|
|
1094
|
+
};
|
|
1095
|
+
|
|
1096
|
+
const renderConversationList = () => {
|
|
1097
|
+
elements.list.innerHTML = "";
|
|
1098
|
+
for (const c of state.conversations) {
|
|
1099
|
+
const item = document.createElement("div");
|
|
1100
|
+
item.className = "conversation-item" + (c.conversationId === state.activeConversationId ? " active" : "");
|
|
1101
|
+
item.textContent = c.title;
|
|
1102
|
+
|
|
1103
|
+
const isConfirming = state.confirmDeleteId === c.conversationId;
|
|
1104
|
+
const deleteBtn = document.createElement("button");
|
|
1105
|
+
deleteBtn.className = "delete-btn" + (isConfirming ? " confirming" : "");
|
|
1106
|
+
deleteBtn.textContent = isConfirming ? "sure?" : "\\u00d7";
|
|
1107
|
+
deleteBtn.onclick = async (e) => {
|
|
1108
|
+
e.stopPropagation();
|
|
1109
|
+
if (!isConfirming) {
|
|
1110
|
+
state.confirmDeleteId = c.conversationId;
|
|
1111
|
+
renderConversationList();
|
|
1112
|
+
return;
|
|
1113
|
+
}
|
|
1114
|
+
await api("/api/conversations/" + c.conversationId, { method: "DELETE" });
|
|
1115
|
+
if (state.activeConversationId === c.conversationId) {
|
|
1116
|
+
state.activeConversationId = null;
|
|
1117
|
+
state.activeMessages = [];
|
|
1118
|
+
pushConversationUrl(null);
|
|
1119
|
+
elements.chatTitle.textContent = "";
|
|
1120
|
+
renderMessages([]);
|
|
1121
|
+
}
|
|
1122
|
+
state.confirmDeleteId = null;
|
|
1123
|
+
await loadConversations();
|
|
1124
|
+
};
|
|
1125
|
+
item.appendChild(deleteBtn);
|
|
1126
|
+
|
|
1127
|
+
item.onclick = async () => {
|
|
1128
|
+
// Clear any delete confirmation, but still navigate
|
|
1129
|
+
if (state.confirmDeleteId) {
|
|
1130
|
+
state.confirmDeleteId = null;
|
|
1131
|
+
}
|
|
1132
|
+
state.activeConversationId = c.conversationId;
|
|
1133
|
+
pushConversationUrl(c.conversationId);
|
|
1134
|
+
renderConversationList();
|
|
1135
|
+
await loadConversation(c.conversationId);
|
|
1136
|
+
if (isMobile()) setSidebarOpen(false);
|
|
1137
|
+
};
|
|
1138
|
+
|
|
1139
|
+
elements.list.appendChild(item);
|
|
1140
|
+
}
|
|
1141
|
+
};
|
|
1142
|
+
|
|
1143
|
+
const renderMessages = (messages, isStreaming = false) => {
|
|
1144
|
+
elements.messages.innerHTML = "";
|
|
1145
|
+
if (!messages || !messages.length) {
|
|
1146
|
+
elements.messages.innerHTML = '<div class="empty-state"><div class="assistant-avatar">' + agentInitial + '</div><div>How can I help you today?</div></div>';
|
|
1147
|
+
return;
|
|
1148
|
+
}
|
|
1149
|
+
const col = document.createElement("div");
|
|
1150
|
+
col.className = "messages-column";
|
|
1151
|
+
messages.forEach((m, i) => {
|
|
1152
|
+
const row = document.createElement("div");
|
|
1153
|
+
row.className = "message-row " + m.role;
|
|
1154
|
+
if (m.role === "assistant") {
|
|
1155
|
+
const wrap = document.createElement("div");
|
|
1156
|
+
wrap.className = "assistant-wrap";
|
|
1157
|
+
wrap.innerHTML = '<div class="assistant-avatar">' + agentInitial + '</div>';
|
|
1158
|
+
const content = document.createElement("div");
|
|
1159
|
+
content.className = "assistant-content";
|
|
1160
|
+
const text = String(m.content || "");
|
|
1161
|
+
const parsed = extractToolActivity(text);
|
|
1162
|
+
const metadataToolActivity =
|
|
1163
|
+
m.metadata && Array.isArray(m.metadata.toolActivity)
|
|
1164
|
+
? m.metadata.toolActivity
|
|
1165
|
+
: [];
|
|
1166
|
+
const toolActivity =
|
|
1167
|
+
Array.isArray(m._toolActivity) && m._toolActivity.length > 0
|
|
1168
|
+
? m._toolActivity
|
|
1169
|
+
: metadataToolActivity.length > 0
|
|
1170
|
+
? metadataToolActivity
|
|
1171
|
+
: parsed.activities;
|
|
1172
|
+
if (m._error) {
|
|
1173
|
+
const errorEl = document.createElement("div");
|
|
1174
|
+
errorEl.className = "message-error";
|
|
1175
|
+
errorEl.innerHTML = "<strong>Error</strong><br>" + escapeHtml(m._error);
|
|
1176
|
+
content.appendChild(errorEl);
|
|
1177
|
+
} else if (isStreaming && i === messages.length - 1 && !parsed.content) {
|
|
1178
|
+
const spinner = document.createElement("span");
|
|
1179
|
+
spinner.className = "thinking-indicator";
|
|
1180
|
+
const starFrames = ["\u2736","\u2738","\u2739","\u273A","\u2739","\u2737"];
|
|
1181
|
+
let frame = 0;
|
|
1182
|
+
spinner.textContent = starFrames[0];
|
|
1183
|
+
spinner._interval = setInterval(() => { frame = (frame + 1) % starFrames.length; spinner.textContent = starFrames[frame]; }, 70);
|
|
1184
|
+
content.appendChild(spinner);
|
|
1185
|
+
} else {
|
|
1186
|
+
content.innerHTML = renderAssistantMarkdown(parsed.content);
|
|
1187
|
+
}
|
|
1188
|
+
if (toolActivity.length > 0) {
|
|
1189
|
+
content.insertAdjacentHTML("beforeend", renderToolActivity(toolActivity));
|
|
1190
|
+
}
|
|
1191
|
+
wrap.appendChild(content);
|
|
1192
|
+
row.appendChild(wrap);
|
|
1193
|
+
} else {
|
|
1194
|
+
row.innerHTML = '<div class="user-bubble">' + escapeHtml(m.content) + '</div>';
|
|
1195
|
+
}
|
|
1196
|
+
col.appendChild(row);
|
|
1197
|
+
});
|
|
1198
|
+
elements.messages.appendChild(col);
|
|
1199
|
+
elements.messages.scrollTop = elements.messages.scrollHeight;
|
|
1200
|
+
};
|
|
1201
|
+
|
|
1202
|
+
const loadConversations = async () => {
|
|
1203
|
+
const payload = await api("/api/conversations");
|
|
1204
|
+
state.conversations = payload.conversations || [];
|
|
1205
|
+
renderConversationList();
|
|
1206
|
+
};
|
|
1207
|
+
|
|
1208
|
+
const loadConversation = async (conversationId) => {
|
|
1209
|
+
const payload = await api("/api/conversations/" + encodeURIComponent(conversationId));
|
|
1210
|
+
elements.chatTitle.textContent = payload.conversation.title;
|
|
1211
|
+
state.activeMessages = payload.conversation.messages || [];
|
|
1212
|
+
renderMessages(state.activeMessages);
|
|
1213
|
+
elements.prompt.focus();
|
|
1214
|
+
};
|
|
1215
|
+
|
|
1216
|
+
const createConversation = async (title, options = {}) => {
|
|
1217
|
+
const shouldLoadConversation = options.loadConversation !== false;
|
|
1218
|
+
const payload = await api("/api/conversations", {
|
|
1219
|
+
method: "POST",
|
|
1220
|
+
body: JSON.stringify(title ? { title } : {})
|
|
1221
|
+
});
|
|
1222
|
+
state.activeConversationId = payload.conversation.conversationId;
|
|
1223
|
+
state.confirmDeleteId = null;
|
|
1224
|
+
pushConversationUrl(state.activeConversationId);
|
|
1225
|
+
await loadConversations();
|
|
1226
|
+
if (shouldLoadConversation) {
|
|
1227
|
+
await loadConversation(state.activeConversationId);
|
|
1228
|
+
} else {
|
|
1229
|
+
elements.chatTitle.textContent = payload.conversation.title || "New conversation";
|
|
1230
|
+
}
|
|
1231
|
+
return state.activeConversationId;
|
|
1232
|
+
};
|
|
1233
|
+
|
|
1234
|
+
const parseSseChunk = (buffer, onEvent) => {
|
|
1235
|
+
let rest = buffer;
|
|
1236
|
+
while (true) {
|
|
1237
|
+
const index = rest.indexOf("\\n\\n");
|
|
1238
|
+
if (index < 0) {
|
|
1239
|
+
return rest;
|
|
1240
|
+
}
|
|
1241
|
+
const raw = rest.slice(0, index);
|
|
1242
|
+
rest = rest.slice(index + 2);
|
|
1243
|
+
const lines = raw.split("\\n");
|
|
1244
|
+
let eventName = "message";
|
|
1245
|
+
let data = "";
|
|
1246
|
+
for (const line of lines) {
|
|
1247
|
+
if (line.startsWith("event:")) {
|
|
1248
|
+
eventName = line.slice(6).trim();
|
|
1249
|
+
} else if (line.startsWith("data:")) {
|
|
1250
|
+
data += line.slice(5).trim();
|
|
1251
|
+
}
|
|
1252
|
+
}
|
|
1253
|
+
if (data) {
|
|
1254
|
+
try {
|
|
1255
|
+
onEvent(eventName, JSON.parse(data));
|
|
1256
|
+
} catch {}
|
|
1257
|
+
}
|
|
1258
|
+
}
|
|
1259
|
+
};
|
|
1260
|
+
|
|
1261
|
+
const setStreaming = (value) => {
|
|
1262
|
+
state.isStreaming = value;
|
|
1263
|
+
elements.send.disabled = value;
|
|
1264
|
+
};
|
|
1265
|
+
|
|
1266
|
+
const pushToolActivity = (assistantMessage, line) => {
|
|
1267
|
+
if (!line) {
|
|
1268
|
+
return;
|
|
1269
|
+
}
|
|
1270
|
+
if (
|
|
1271
|
+
!assistantMessage.metadata ||
|
|
1272
|
+
!Array.isArray(assistantMessage.metadata.toolActivity)
|
|
1273
|
+
) {
|
|
1274
|
+
assistantMessage.metadata = {
|
|
1275
|
+
...(assistantMessage.metadata || {}),
|
|
1276
|
+
toolActivity: [],
|
|
1277
|
+
};
|
|
1278
|
+
}
|
|
1279
|
+
assistantMessage.metadata.toolActivity.push(line);
|
|
1280
|
+
};
|
|
1281
|
+
|
|
1282
|
+
const autoResizePrompt = () => {
|
|
1283
|
+
const el = elements.prompt;
|
|
1284
|
+
el.style.height = "auto";
|
|
1285
|
+
const scrollHeight = el.scrollHeight;
|
|
1286
|
+
const nextHeight = Math.min(scrollHeight, 200);
|
|
1287
|
+
el.style.height = nextHeight + "px";
|
|
1288
|
+
el.style.overflowY = scrollHeight > 200 ? "auto" : "hidden";
|
|
1289
|
+
};
|
|
1290
|
+
|
|
1291
|
+
const sendMessage = async (text) => {
|
|
1292
|
+
const messageText = (text || "").trim();
|
|
1293
|
+
if (!messageText || state.isStreaming) {
|
|
1294
|
+
return;
|
|
1295
|
+
}
|
|
1296
|
+
const localMessages = [...(state.activeMessages || []), { role: "user", content: messageText }];
|
|
1297
|
+
let assistantMessage = { role: "assistant", content: "", metadata: { toolActivity: [] } };
|
|
1298
|
+
localMessages.push(assistantMessage);
|
|
1299
|
+
state.activeMessages = localMessages;
|
|
1300
|
+
renderMessages(localMessages, true);
|
|
1301
|
+
setStreaming(true);
|
|
1302
|
+
let conversationId = state.activeConversationId;
|
|
1303
|
+
try {
|
|
1304
|
+
if (!conversationId) {
|
|
1305
|
+
conversationId = await createConversation(messageText, { loadConversation: false });
|
|
1306
|
+
}
|
|
1307
|
+
const response = await fetch("/api/conversations/" + encodeURIComponent(conversationId) + "/messages", {
|
|
1308
|
+
method: "POST",
|
|
1309
|
+
credentials: "include",
|
|
1310
|
+
headers: { "Content-Type": "application/json", "x-csrf-token": state.csrfToken },
|
|
1311
|
+
body: JSON.stringify({ message: messageText })
|
|
1312
|
+
});
|
|
1313
|
+
if (!response.ok || !response.body) {
|
|
1314
|
+
throw new Error("Failed to stream response");
|
|
1315
|
+
}
|
|
1316
|
+
const reader = response.body.getReader();
|
|
1317
|
+
const decoder = new TextDecoder();
|
|
1318
|
+
let buffer = "";
|
|
1319
|
+
while (true) {
|
|
1320
|
+
const { value, done } = await reader.read();
|
|
1321
|
+
if (done) {
|
|
1322
|
+
break;
|
|
1323
|
+
}
|
|
1324
|
+
buffer += decoder.decode(value, { stream: true });
|
|
1325
|
+
buffer = parseSseChunk(buffer, (eventName, payload) => {
|
|
1326
|
+
if (eventName === "model:chunk") {
|
|
1327
|
+
assistantMessage.content += String(payload.content || "");
|
|
1328
|
+
renderMessages(localMessages, true);
|
|
1329
|
+
}
|
|
1330
|
+
if (eventName === "tool:started") {
|
|
1331
|
+
pushToolActivity(assistantMessage, "start " + (payload.tool || "tool"));
|
|
1332
|
+
renderMessages(localMessages, true);
|
|
1333
|
+
}
|
|
1334
|
+
if (eventName === "tool:completed") {
|
|
1335
|
+
const duration = typeof payload.duration === "number" ? payload.duration : null;
|
|
1336
|
+
pushToolActivity(
|
|
1337
|
+
assistantMessage,
|
|
1338
|
+
"done " +
|
|
1339
|
+
(payload.tool || "tool") +
|
|
1340
|
+
(duration !== null ? " (" + duration + "ms)" : ""),
|
|
1341
|
+
);
|
|
1342
|
+
renderMessages(localMessages, true);
|
|
1343
|
+
}
|
|
1344
|
+
if (eventName === "tool:error") {
|
|
1345
|
+
pushToolActivity(
|
|
1346
|
+
assistantMessage,
|
|
1347
|
+
"error " + (payload.tool || "tool") + ": " + (payload.error || "unknown error"),
|
|
1348
|
+
);
|
|
1349
|
+
renderMessages(localMessages, true);
|
|
1350
|
+
}
|
|
1351
|
+
if (eventName === "tool:approval:required") {
|
|
1352
|
+
pushToolActivity(assistantMessage, "approval required for " + (payload.tool || "tool"));
|
|
1353
|
+
renderMessages(localMessages, true);
|
|
1354
|
+
}
|
|
1355
|
+
if (eventName === "tool:approval:granted") {
|
|
1356
|
+
pushToolActivity(assistantMessage, "approval granted");
|
|
1357
|
+
renderMessages(localMessages, true);
|
|
1358
|
+
}
|
|
1359
|
+
if (eventName === "tool:approval:denied") {
|
|
1360
|
+
pushToolActivity(assistantMessage, "approval denied");
|
|
1361
|
+
renderMessages(localMessages, true);
|
|
1362
|
+
}
|
|
1363
|
+
if (eventName === "run:completed" && (!assistantMessage.content || assistantMessage.content.length === 0)) {
|
|
1364
|
+
assistantMessage.content = String(payload.result?.response || "");
|
|
1365
|
+
renderMessages(localMessages, false);
|
|
1366
|
+
}
|
|
1367
|
+
if (eventName === "run:error") {
|
|
1368
|
+
const errMsg = payload.error?.message || "Something went wrong";
|
|
1369
|
+
assistantMessage.content = "";
|
|
1370
|
+
assistantMessage._error = errMsg;
|
|
1371
|
+
renderMessages(localMessages, false);
|
|
1372
|
+
}
|
|
1373
|
+
});
|
|
1374
|
+
}
|
|
1375
|
+
await loadConversations();
|
|
1376
|
+
await loadConversation(conversationId);
|
|
1377
|
+
} finally {
|
|
1378
|
+
setStreaming(false);
|
|
1379
|
+
elements.prompt.focus();
|
|
1380
|
+
}
|
|
1381
|
+
};
|
|
1382
|
+
|
|
1383
|
+
const requireAuth = async () => {
|
|
1384
|
+
try {
|
|
1385
|
+
const session = await api("/api/auth/session");
|
|
1386
|
+
if (!session.authenticated) {
|
|
1387
|
+
elements.auth.classList.remove("hidden");
|
|
1388
|
+
elements.app.classList.add("hidden");
|
|
1389
|
+
return false;
|
|
1390
|
+
}
|
|
1391
|
+
state.csrfToken = session.csrfToken || "";
|
|
1392
|
+
elements.auth.classList.add("hidden");
|
|
1393
|
+
elements.app.classList.remove("hidden");
|
|
1394
|
+
return true;
|
|
1395
|
+
} catch {
|
|
1396
|
+
elements.auth.classList.remove("hidden");
|
|
1397
|
+
elements.app.classList.add("hidden");
|
|
1398
|
+
return false;
|
|
1399
|
+
}
|
|
1400
|
+
};
|
|
1401
|
+
|
|
1402
|
+
elements.loginForm.addEventListener("submit", async (event) => {
|
|
1403
|
+
event.preventDefault();
|
|
1404
|
+
elements.loginError.textContent = "";
|
|
1405
|
+
try {
|
|
1406
|
+
const result = await api("/api/auth/login", {
|
|
1407
|
+
method: "POST",
|
|
1408
|
+
body: JSON.stringify({ passphrase: elements.passphrase.value || "" })
|
|
1409
|
+
});
|
|
1410
|
+
state.csrfToken = result.csrfToken || "";
|
|
1411
|
+
elements.passphrase.value = "";
|
|
1412
|
+
elements.auth.classList.add("hidden");
|
|
1413
|
+
elements.app.classList.remove("hidden");
|
|
1414
|
+
await loadConversations();
|
|
1415
|
+
const urlConversationId = getConversationIdFromUrl();
|
|
1416
|
+
if (urlConversationId) {
|
|
1417
|
+
state.activeConversationId = urlConversationId;
|
|
1418
|
+
renderConversationList();
|
|
1419
|
+
try {
|
|
1420
|
+
await loadConversation(urlConversationId);
|
|
1421
|
+
} catch {
|
|
1422
|
+
state.activeConversationId = null;
|
|
1423
|
+
state.activeMessages = [];
|
|
1424
|
+
replaceConversationUrl(null);
|
|
1425
|
+
renderMessages([]);
|
|
1426
|
+
renderConversationList();
|
|
1427
|
+
}
|
|
1428
|
+
}
|
|
1429
|
+
} catch (error) {
|
|
1430
|
+
elements.loginError.textContent = error.message || "Login failed";
|
|
1431
|
+
}
|
|
1432
|
+
});
|
|
1433
|
+
|
|
1434
|
+
const startNewChat = () => {
|
|
1435
|
+
state.activeConversationId = null;
|
|
1436
|
+
state.activeMessages = [];
|
|
1437
|
+
state.confirmDeleteId = null;
|
|
1438
|
+
pushConversationUrl(null);
|
|
1439
|
+
elements.chatTitle.textContent = "";
|
|
1440
|
+
renderMessages([]);
|
|
1441
|
+
renderConversationList();
|
|
1442
|
+
elements.prompt.focus();
|
|
1443
|
+
if (isMobile()) {
|
|
1444
|
+
setSidebarOpen(false);
|
|
1445
|
+
}
|
|
1446
|
+
};
|
|
1447
|
+
|
|
1448
|
+
elements.newChat.addEventListener("click", startNewChat);
|
|
1449
|
+
elements.topbarNewChat.addEventListener("click", startNewChat);
|
|
1450
|
+
|
|
1451
|
+
elements.prompt.addEventListener("input", () => {
|
|
1452
|
+
autoResizePrompt();
|
|
1453
|
+
});
|
|
1454
|
+
|
|
1455
|
+
elements.prompt.addEventListener("keydown", (event) => {
|
|
1456
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
1457
|
+
event.preventDefault();
|
|
1458
|
+
elements.composer.requestSubmit();
|
|
1459
|
+
}
|
|
1460
|
+
});
|
|
1461
|
+
|
|
1462
|
+
elements.sidebarToggle.addEventListener("click", () => {
|
|
1463
|
+
if (isMobile()) setSidebarOpen(!elements.shell.classList.contains("sidebar-open"));
|
|
1464
|
+
});
|
|
1465
|
+
|
|
1466
|
+
elements.sidebarBackdrop.addEventListener("click", () => setSidebarOpen(false));
|
|
1467
|
+
|
|
1468
|
+
elements.logout.addEventListener("click", async () => {
|
|
1469
|
+
await api("/api/auth/logout", { method: "POST" });
|
|
1470
|
+
state.activeConversationId = null;
|
|
1471
|
+
state.activeMessages = [];
|
|
1472
|
+
state.confirmDeleteId = null;
|
|
1473
|
+
state.conversations = [];
|
|
1474
|
+
state.csrfToken = "";
|
|
1475
|
+
await requireAuth();
|
|
1476
|
+
});
|
|
1477
|
+
|
|
1478
|
+
elements.composer.addEventListener("submit", async (event) => {
|
|
1479
|
+
event.preventDefault();
|
|
1480
|
+
const value = elements.prompt.value;
|
|
1481
|
+
elements.prompt.value = "";
|
|
1482
|
+
autoResizePrompt();
|
|
1483
|
+
await sendMessage(value);
|
|
1484
|
+
});
|
|
1485
|
+
|
|
1486
|
+
document.addEventListener("click", (event) => {
|
|
1487
|
+
if (!(event.target instanceof Node)) {
|
|
1488
|
+
return;
|
|
1489
|
+
}
|
|
1490
|
+
if (!event.target.closest(".conversation-item") && state.confirmDeleteId) {
|
|
1491
|
+
state.confirmDeleteId = null;
|
|
1492
|
+
renderConversationList();
|
|
1493
|
+
}
|
|
1494
|
+
});
|
|
1495
|
+
|
|
1496
|
+
window.addEventListener("resize", () => {
|
|
1497
|
+
setSidebarOpen(false);
|
|
1498
|
+
});
|
|
1499
|
+
|
|
1500
|
+
const navigateToConversation = async (conversationId) => {
|
|
1501
|
+
if (conversationId) {
|
|
1502
|
+
state.activeConversationId = conversationId;
|
|
1503
|
+
renderConversationList();
|
|
1504
|
+
try {
|
|
1505
|
+
await loadConversation(conversationId);
|
|
1506
|
+
} catch {
|
|
1507
|
+
// Conversation not found \u2013 fall back to empty state
|
|
1508
|
+
state.activeConversationId = null;
|
|
1509
|
+
state.activeMessages = [];
|
|
1510
|
+
replaceConversationUrl(null);
|
|
1511
|
+
elements.chatTitle.textContent = "";
|
|
1512
|
+
renderMessages([]);
|
|
1513
|
+
renderConversationList();
|
|
1514
|
+
}
|
|
1515
|
+
} else {
|
|
1516
|
+
state.activeConversationId = null;
|
|
1517
|
+
state.activeMessages = [];
|
|
1518
|
+
elements.chatTitle.textContent = "";
|
|
1519
|
+
renderMessages([]);
|
|
1520
|
+
renderConversationList();
|
|
1521
|
+
}
|
|
1522
|
+
};
|
|
1523
|
+
|
|
1524
|
+
window.addEventListener("popstate", async () => {
|
|
1525
|
+
if (state.isStreaming) return;
|
|
1526
|
+
const conversationId = getConversationIdFromUrl();
|
|
1527
|
+
await navigateToConversation(conversationId);
|
|
1528
|
+
});
|
|
1529
|
+
|
|
1530
|
+
(async () => {
|
|
1531
|
+
const authenticated = await requireAuth();
|
|
1532
|
+
if (!authenticated) {
|
|
1533
|
+
return;
|
|
1534
|
+
}
|
|
1535
|
+
await loadConversations();
|
|
1536
|
+
const urlConversationId = getConversationIdFromUrl();
|
|
1537
|
+
if (urlConversationId) {
|
|
1538
|
+
state.activeConversationId = urlConversationId;
|
|
1539
|
+
replaceConversationUrl(urlConversationId);
|
|
1540
|
+
renderConversationList();
|
|
1541
|
+
try {
|
|
1542
|
+
await loadConversation(urlConversationId);
|
|
1543
|
+
} catch {
|
|
1544
|
+
// URL pointed to a conversation that no longer exists
|
|
1545
|
+
state.activeConversationId = null;
|
|
1546
|
+
state.activeMessages = [];
|
|
1547
|
+
replaceConversationUrl(null);
|
|
1548
|
+
elements.chatTitle.textContent = "";
|
|
1549
|
+
renderMessages([]);
|
|
1550
|
+
renderConversationList();
|
|
1551
|
+
if (state.conversations.length === 0) {
|
|
1552
|
+
await createConversation();
|
|
1553
|
+
}
|
|
1554
|
+
}
|
|
1555
|
+
} else if (state.conversations.length === 0) {
|
|
1556
|
+
await createConversation();
|
|
1557
|
+
}
|
|
1558
|
+
autoResizePrompt();
|
|
1559
|
+
elements.prompt.focus();
|
|
1560
|
+
})();
|
|
1561
|
+
|
|
1562
|
+
if ("serviceWorker" in navigator) {
|
|
1563
|
+
navigator.serviceWorker.register("/sw.js").catch(() => {});
|
|
1564
|
+
}
|
|
1565
|
+
|
|
1566
|
+
// Detect iOS standalone mode and add class for CSS targeting
|
|
1567
|
+
if (window.navigator.standalone === true || window.matchMedia("(display-mode: standalone)").matches) {
|
|
1568
|
+
document.documentElement.classList.add("standalone");
|
|
1569
|
+
}
|
|
1570
|
+
|
|
1571
|
+
// iOS viewport and keyboard handling
|
|
1572
|
+
(function() {
|
|
1573
|
+
var shell = document.querySelector(".shell");
|
|
1574
|
+
var pinScroll = function() { if (window.scrollY !== 0) window.scrollTo(0, 0); };
|
|
1575
|
+
|
|
1576
|
+
// Track the "full" height when keyboard is not open
|
|
1577
|
+
var fullHeight = window.innerHeight;
|
|
1578
|
+
|
|
1579
|
+
// Resize shell when iOS keyboard opens/closes
|
|
1580
|
+
var resizeForKeyboard = function() {
|
|
1581
|
+
if (!shell || !window.visualViewport) return;
|
|
1582
|
+
var vvHeight = window.visualViewport.height;
|
|
1583
|
+
|
|
1584
|
+
// Update fullHeight if viewport grew (keyboard closed)
|
|
1585
|
+
if (vvHeight > fullHeight) {
|
|
1586
|
+
fullHeight = vvHeight;
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
// Only apply height override if keyboard appears to be open
|
|
1590
|
+
// (viewport significantly smaller than full height)
|
|
1591
|
+
if (vvHeight < fullHeight - 100) {
|
|
1592
|
+
shell.style.height = vvHeight + "px";
|
|
1593
|
+
} else {
|
|
1594
|
+
// Keyboard closed - remove override, let CSS handle it
|
|
1595
|
+
shell.style.height = "";
|
|
1596
|
+
}
|
|
1597
|
+
pinScroll();
|
|
1598
|
+
};
|
|
1599
|
+
|
|
1600
|
+
if (window.visualViewport) {
|
|
1601
|
+
window.visualViewport.addEventListener("scroll", pinScroll);
|
|
1602
|
+
window.visualViewport.addEventListener("resize", resizeForKeyboard);
|
|
1603
|
+
}
|
|
1604
|
+
document.addEventListener("scroll", pinScroll);
|
|
1605
|
+
|
|
1606
|
+
// Draggable sidebar from left edge (mobile only)
|
|
1607
|
+
(function() {
|
|
1608
|
+
var sidebar = document.querySelector(".sidebar");
|
|
1609
|
+
var backdrop = document.querySelector(".sidebar-backdrop");
|
|
1610
|
+
var shell = document.querySelector(".shell");
|
|
1611
|
+
if (!sidebar || !backdrop || !shell) return;
|
|
1612
|
+
|
|
1613
|
+
var sidebarWidth = 260;
|
|
1614
|
+
var edgeThreshold = 50; // px from left edge to start drag
|
|
1615
|
+
var velocityThreshold = 0.3; // px/ms to trigger open/close
|
|
1616
|
+
|
|
1617
|
+
var dragging = false;
|
|
1618
|
+
var startX = 0;
|
|
1619
|
+
var startY = 0;
|
|
1620
|
+
var currentX = 0;
|
|
1621
|
+
var startTime = 0;
|
|
1622
|
+
var isOpen = false;
|
|
1623
|
+
var directionLocked = false;
|
|
1624
|
+
var isHorizontal = false;
|
|
1625
|
+
|
|
1626
|
+
function getProgress() {
|
|
1627
|
+
// Returns 0 (closed) to 1 (open)
|
|
1628
|
+
if (isOpen) {
|
|
1629
|
+
return Math.max(0, Math.min(1, 1 + currentX / sidebarWidth));
|
|
1630
|
+
} else {
|
|
1631
|
+
return Math.max(0, Math.min(1, currentX / sidebarWidth));
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
|
|
1635
|
+
function updatePosition(progress) {
|
|
1636
|
+
var offset = (progress - 1) * sidebarWidth;
|
|
1637
|
+
sidebar.style.transform = "translateX(" + offset + "px)";
|
|
1638
|
+
backdrop.style.opacity = progress;
|
|
1639
|
+
if (progress > 0) {
|
|
1640
|
+
backdrop.style.pointerEvents = "auto";
|
|
1641
|
+
} else {
|
|
1642
|
+
backdrop.style.pointerEvents = "none";
|
|
1643
|
+
}
|
|
1644
|
+
}
|
|
1645
|
+
|
|
1646
|
+
function onTouchStart(e) {
|
|
1647
|
+
if (window.innerWidth > 768) return;
|
|
1648
|
+
|
|
1649
|
+
// Don't intercept touches on interactive elements
|
|
1650
|
+
var target = e.target;
|
|
1651
|
+
if (target.closest("button") || target.closest("a") || target.closest("input") || target.closest("textarea")) {
|
|
1652
|
+
return;
|
|
1653
|
+
}
|
|
1654
|
+
|
|
1655
|
+
var touch = e.touches[0];
|
|
1656
|
+
isOpen = shell.classList.contains("sidebar-open");
|
|
1657
|
+
|
|
1658
|
+
// When sidebar is closed: only respond to edge swipes
|
|
1659
|
+
// When sidebar is open: only respond to backdrop touches (not sidebar content)
|
|
1660
|
+
var fromEdge = touch.clientX < edgeThreshold;
|
|
1661
|
+
var onBackdrop = e.target === backdrop;
|
|
1662
|
+
|
|
1663
|
+
if (!isOpen && !fromEdge) return;
|
|
1664
|
+
if (isOpen && !onBackdrop) return;
|
|
1665
|
+
|
|
1666
|
+
// Prevent Safari back gesture when starting from edge
|
|
1667
|
+
if (fromEdge) {
|
|
1668
|
+
e.preventDefault();
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
startX = touch.clientX;
|
|
1672
|
+
startY = touch.clientY;
|
|
1673
|
+
currentX = 0;
|
|
1674
|
+
startTime = Date.now();
|
|
1675
|
+
directionLocked = false;
|
|
1676
|
+
isHorizontal = false;
|
|
1677
|
+
dragging = true;
|
|
1678
|
+
sidebar.classList.add("dragging");
|
|
1679
|
+
backdrop.classList.add("dragging");
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
function onTouchMove(e) {
|
|
1683
|
+
if (!dragging) return;
|
|
1684
|
+
var touch = e.touches[0];
|
|
1685
|
+
var dx = touch.clientX - startX;
|
|
1686
|
+
var dy = touch.clientY - startY;
|
|
1687
|
+
|
|
1688
|
+
// Lock direction after some movement
|
|
1689
|
+
if (!directionLocked && (Math.abs(dx) > 10 || Math.abs(dy) > 10)) {
|
|
1690
|
+
directionLocked = true;
|
|
1691
|
+
isHorizontal = Math.abs(dx) > Math.abs(dy);
|
|
1692
|
+
if (!isHorizontal) {
|
|
1693
|
+
// Vertical scroll, cancel drag
|
|
1694
|
+
dragging = false;
|
|
1695
|
+
sidebar.classList.remove("dragging");
|
|
1696
|
+
backdrop.classList.remove("dragging");
|
|
1697
|
+
return;
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1700
|
+
|
|
1701
|
+
if (!directionLocked) return;
|
|
1702
|
+
|
|
1703
|
+
// Prevent scrolling while dragging sidebar
|
|
1704
|
+
e.preventDefault();
|
|
1705
|
+
|
|
1706
|
+
currentX = dx;
|
|
1707
|
+
updatePosition(getProgress());
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
function onTouchEnd(e) {
|
|
1711
|
+
if (!dragging) return;
|
|
1712
|
+
dragging = false;
|
|
1713
|
+
sidebar.classList.remove("dragging");
|
|
1714
|
+
backdrop.classList.remove("dragging");
|
|
1715
|
+
|
|
1716
|
+
var touch = e.changedTouches[0];
|
|
1717
|
+
var dx = touch.clientX - startX;
|
|
1718
|
+
var dt = Date.now() - startTime;
|
|
1719
|
+
var velocity = dx / dt; // px/ms
|
|
1720
|
+
|
|
1721
|
+
var progress = getProgress();
|
|
1722
|
+
var shouldOpen;
|
|
1723
|
+
|
|
1724
|
+
// Use velocity if fast enough, otherwise use position threshold
|
|
1725
|
+
if (Math.abs(velocity) > velocityThreshold) {
|
|
1726
|
+
shouldOpen = velocity > 0;
|
|
1727
|
+
} else {
|
|
1728
|
+
shouldOpen = progress > 0.5;
|
|
1729
|
+
}
|
|
1730
|
+
|
|
1731
|
+
// Reset inline styles and let CSS handle the animation
|
|
1732
|
+
sidebar.style.transform = "";
|
|
1733
|
+
backdrop.style.opacity = "";
|
|
1734
|
+
backdrop.style.pointerEvents = "";
|
|
1735
|
+
|
|
1736
|
+
if (shouldOpen) {
|
|
1737
|
+
shell.classList.add("sidebar-open");
|
|
1738
|
+
} else {
|
|
1739
|
+
shell.classList.remove("sidebar-open");
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
|
|
1743
|
+
document.addEventListener("touchstart", onTouchStart, { passive: false });
|
|
1744
|
+
document.addEventListener("touchmove", onTouchMove, { passive: false });
|
|
1745
|
+
document.addEventListener("touchend", onTouchEnd, { passive: true });
|
|
1746
|
+
document.addEventListener("touchcancel", onTouchEnd, { passive: true });
|
|
1747
|
+
})();
|
|
1748
|
+
|
|
1749
|
+
// Prevent Safari back/forward navigation by manipulating history
|
|
1750
|
+
// This doesn't stop the gesture animation but prevents actual navigation
|
|
1751
|
+
if (window.navigator.standalone || window.matchMedia("(display-mode: standalone)").matches) {
|
|
1752
|
+
history.pushState(null, "", location.href);
|
|
1753
|
+
window.addEventListener("popstate", function() {
|
|
1754
|
+
history.pushState(null, "", location.href);
|
|
1755
|
+
});
|
|
1756
|
+
}
|
|
1757
|
+
|
|
1758
|
+
// Right edge blocker - intercept touch events to prevent forward navigation
|
|
1759
|
+
var rightBlocker = document.querySelector(".edge-blocker-right");
|
|
1760
|
+
if (rightBlocker) {
|
|
1761
|
+
rightBlocker.addEventListener("touchstart", function(e) {
|
|
1762
|
+
e.preventDefault();
|
|
1763
|
+
}, { passive: false });
|
|
1764
|
+
rightBlocker.addEventListener("touchmove", function(e) {
|
|
1765
|
+
e.preventDefault();
|
|
1766
|
+
}, { passive: false });
|
|
1767
|
+
}
|
|
1768
|
+
})();
|
|
1769
|
+
|
|
1770
|
+
</script>
|
|
1771
|
+
</body>
|
|
1772
|
+
</html>`;
|
|
1773
|
+
};
|
|
1774
|
+
|
|
1775
|
+
// src/init-feature-context.ts
|
|
1776
|
+
import { createHash as createHash2 } from "crypto";
|
|
1777
|
+
import { access, mkdir as mkdir2, readFile as readFile2, writeFile as writeFile2 } from "fs/promises";
|
|
1778
|
+
import { basename as basename2, dirname as dirname2, resolve as resolve2 } from "path";
|
|
1779
|
+
import { homedir as homedir2 } from "os";
|
|
1780
|
+
var ONBOARDING_VERSION = 1;
|
|
1781
|
+
var getStateDirectory = () => {
|
|
1782
|
+
const cwd = process.cwd();
|
|
1783
|
+
const home = homedir2();
|
|
1784
|
+
const isServerless = process.env.VERCEL === "1" || process.env.VERCEL_ENV !== void 0 || process.env.VERCEL_URL !== void 0 || process.env.AWS_LAMBDA_FUNCTION_NAME !== void 0 || process.env.AWS_EXECUTION_ENV?.includes("AWS_Lambda") === true || process.env.LAMBDA_TASK_ROOT !== void 0 || process.env.NOW_REGION !== void 0 || cwd.startsWith("/var/task") || home.startsWith("/var/task") || process.env.SERVERLESS === "1";
|
|
1785
|
+
if (isServerless) {
|
|
1786
|
+
return "/tmp/.poncho/state";
|
|
1787
|
+
}
|
|
1788
|
+
return resolve2(homedir2(), ".poncho", "state");
|
|
1789
|
+
};
|
|
1790
|
+
var summarizeConfig = (config) => {
|
|
1791
|
+
const provider = config?.storage?.provider ?? config?.state?.provider ?? "local";
|
|
1792
|
+
const memoryEnabled = config?.storage?.memory?.enabled ?? config?.memory?.enabled ?? false;
|
|
1793
|
+
const authRequired = config?.auth?.required ?? false;
|
|
1794
|
+
const telemetryEnabled = config?.telemetry?.enabled ?? true;
|
|
1795
|
+
return [
|
|
1796
|
+
`storage: ${provider}`,
|
|
1797
|
+
`memory tools: ${memoryEnabled ? "enabled" : "disabled"}`,
|
|
1798
|
+
`auth: ${authRequired ? "required" : "not required"}`,
|
|
1799
|
+
`telemetry: ${telemetryEnabled ? "enabled" : "disabled"}`
|
|
1800
|
+
];
|
|
1801
|
+
};
|
|
1802
|
+
var getOnboardingMarkerPath = (workingDir) => resolve2(
|
|
1803
|
+
getStateDirectory(),
|
|
1804
|
+
`${basename2(workingDir).replace(/[^a-zA-Z0-9_-]+/g, "-") || "project"}-${createHash2("sha256").update(workingDir).digest("hex").slice(0, 12)}-onboarding.json`
|
|
1805
|
+
);
|
|
1806
|
+
var readMarker = async (workingDir) => {
|
|
1807
|
+
const markerPath = getOnboardingMarkerPath(workingDir);
|
|
1808
|
+
try {
|
|
1809
|
+
await access(markerPath);
|
|
1810
|
+
} catch {
|
|
1811
|
+
return void 0;
|
|
1812
|
+
}
|
|
1813
|
+
try {
|
|
1814
|
+
const raw = await readFile2(markerPath, "utf8");
|
|
1815
|
+
return JSON.parse(raw);
|
|
1816
|
+
} catch {
|
|
1817
|
+
return void 0;
|
|
1818
|
+
}
|
|
1819
|
+
};
|
|
1820
|
+
var writeMarker = async (workingDir, state) => {
|
|
1821
|
+
const markerPath = getOnboardingMarkerPath(workingDir);
|
|
1822
|
+
await mkdir2(dirname2(markerPath), { recursive: true });
|
|
1823
|
+
await writeFile2(markerPath, JSON.stringify(state, null, 2), "utf8");
|
|
1824
|
+
};
|
|
1825
|
+
var initializeOnboardingMarker = async (workingDir, options) => {
|
|
1826
|
+
const current = await readMarker(workingDir);
|
|
1827
|
+
if (current) {
|
|
1828
|
+
return;
|
|
1829
|
+
}
|
|
1830
|
+
const allowIntro = options?.allowIntro ?? true;
|
|
1831
|
+
await writeMarker(workingDir, {
|
|
1832
|
+
introduced: allowIntro ? false : true,
|
|
1833
|
+
allowIntro,
|
|
1834
|
+
onboardingVersion: ONBOARDING_VERSION,
|
|
1835
|
+
createdAt: Date.now()
|
|
1836
|
+
});
|
|
1837
|
+
};
|
|
1838
|
+
var consumeFirstRunIntro = async (workingDir, input) => {
|
|
1839
|
+
const runtimeEnv = (process.env.PONCHO_ENV ?? process.env.NODE_ENV ?? "").toLowerCase();
|
|
1840
|
+
if (runtimeEnv === "production") {
|
|
1841
|
+
return void 0;
|
|
1842
|
+
}
|
|
1843
|
+
const marker = await readMarker(workingDir);
|
|
1844
|
+
if (marker?.allowIntro === false) {
|
|
1845
|
+
return void 0;
|
|
1846
|
+
}
|
|
1847
|
+
const shouldShow = !marker || marker.introduced === false;
|
|
1848
|
+
if (!shouldShow) {
|
|
1849
|
+
return void 0;
|
|
1850
|
+
}
|
|
1851
|
+
await writeMarker(workingDir, {
|
|
1852
|
+
introduced: true,
|
|
1853
|
+
allowIntro: true,
|
|
1854
|
+
onboardingVersion: ONBOARDING_VERSION,
|
|
1855
|
+
createdAt: marker?.createdAt ?? Date.now(),
|
|
1856
|
+
introducedAt: Date.now()
|
|
1857
|
+
});
|
|
1858
|
+
const summary = summarizeConfig(input.config);
|
|
1859
|
+
return [
|
|
1860
|
+
`Hi! I'm **${input.agentName}**. I can configure myself directly by chat.
|
|
1861
|
+
`,
|
|
1862
|
+
`**Current config**`,
|
|
1863
|
+
` Model: ${input.provider}/${input.model}`,
|
|
1864
|
+
` \`\`\`${summary.join(" \xB7 ")}\`\`\``,
|
|
1865
|
+
"",
|
|
1866
|
+
"Feel free to ask me anything when you're ready. I can help you:",
|
|
1867
|
+
"",
|
|
1868
|
+
"- **Build skills**: Create custom tools and capabilities for this agent",
|
|
1869
|
+
"- **Configure the model**: Switch providers (OpenAI, Anthropic, etc.) or models",
|
|
1870
|
+
"- **Set up storage**: Use local files, Upstash, or other backends",
|
|
1871
|
+
"- **Enable auth**: Add bearer tokens or custom authentication",
|
|
1872
|
+
"- **Turn on telemetry**: Track usage with OpenTelemetry/OTLP",
|
|
1873
|
+
"- **Add MCP servers**: Connect external tool servers",
|
|
1874
|
+
"",
|
|
1875
|
+
"Just let me know what you'd like to work on!\n"
|
|
1876
|
+
].join("\n");
|
|
1877
|
+
};
|
|
1878
|
+
|
|
1879
|
+
export {
|
|
1880
|
+
SessionStore,
|
|
1881
|
+
LoginRateLimiter,
|
|
1882
|
+
parseCookies,
|
|
1883
|
+
setCookie,
|
|
1884
|
+
verifyPassphrase,
|
|
1885
|
+
getRequestIp,
|
|
1886
|
+
inferConversationTitle,
|
|
1887
|
+
renderManifest,
|
|
1888
|
+
renderIconSvg,
|
|
1889
|
+
renderServiceWorker,
|
|
1890
|
+
renderWebUiHtml,
|
|
1891
|
+
initializeOnboardingMarker,
|
|
1892
|
+
consumeFirstRunIntro
|
|
1893
|
+
};
|