@qearlyao/familiar 0.3.0 → 0.4.1
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/HEARTBEAT.md +1 -1
- package/README.md +35 -2
- package/config.example.toml +2 -0
- package/dist/{agent.js → agent/factory.js} +11 -11
- package/dist/agent/session-helpers.js +1 -1
- package/dist/agent/tools.js +4 -4
- package/dist/cli.js +26 -11
- package/dist/{config.js → config/index.js} +7 -7
- package/dist/config/model-refs.js +1 -1
- package/dist/{config-overrides.js → config/overrides.js} +1 -1
- package/dist/{config-registry.js → config/registry.js} +2 -2
- package/dist/{settings.js → config/settings.js} +2 -2
- package/dist/{chat-log.js → conversation/chat-log.js} +1 -1
- package/dist/{contact-note.js → conversation/contact-note.js} +1 -1
- package/dist/{owner-identity.js → conversation/owner-identity.js} +2 -2
- package/dist/discord/channel.js +1 -1
- package/dist/discord/commands.js +1 -1
- package/dist/{discord.js → discord/daemon.js} +17 -17
- package/dist/discord/inbound.js +1 -1
- package/dist/discord/send.js +29 -20
- package/dist/discord/turn.js +3 -3
- package/dist/index.js +12 -12
- package/dist/{data-retention.js → lifecycle/data-retention.js} +1 -1
- package/dist/{hot-reload.js → lifecycle/hot-reload.js} +2 -2
- package/dist/{service.js → lifecycle/service.js} +61 -6
- package/dist/media/attachment-limits.js +3 -0
- package/dist/{generated-media.js → media/generated-media.js} +1 -1
- package/dist/{image-gen.js → media/image-gen.js} +2 -2
- package/dist/{inbound-attachments.js → media/inbound-attachments.js} +47 -43
- package/dist/media/media-understanding.js +215 -0
- package/dist/memory/lcm/summarizer.js +1 -1
- package/dist/{added-models.js → models/added-models.js} +1 -1
- package/dist/{persona.js → prompting/persona.js} +1 -1
- package/dist/{agent-core.js → runtime/agent-core.js} +1 -1
- package/dist/{agent-events.js → runtime/agent-events.js} +1 -1
- package/dist/{agent-work-queue.js → runtime/agent-work-queue.js} +2 -2
- package/dist/{runtime.js → runtime/conversation-runtime.js} +3 -3
- package/dist/{runtime-manager.js → runtime/runtime-manager.js} +2 -2
- package/dist/{scheduler-runner.js → runtime/scheduler-runner.js} +1 -1
- package/dist/{scheduler.js → runtime/scheduler.js} +3 -3
- package/dist/{browser-tools.js → tools/browser-tools.js} +17 -26
- package/dist/util/fs.js +2 -1
- package/dist/web/agent-routes.js +104 -0
- package/dist/web/auth-routes.js +39 -0
- package/dist/web/auth.js +124 -30
- package/dist/web/config-routes.js +55 -0
- package/dist/web/conversation-routes.js +122 -0
- package/dist/web/daemon.js +108 -0
- package/dist/web/diary-routes.js +88 -0
- package/dist/web/errors.js +3 -0
- package/dist/web/event-hub.js +3 -3
- package/dist/web/messages.js +13 -10
- package/dist/web/multipart.js +7 -1
- package/dist/web/payloads.js +1 -1
- package/dist/web/request-context.js +25 -0
- package/dist/web/route-helpers.js +9 -0
- package/dist/web/routes.js +37 -0
- package/dist/web/runtime-actions.js +231 -0
- package/dist/web/session-store.js +161 -0
- package/dist/web/static.js +1 -1
- package/dist/web/stream.js +12 -3
- package/dist/{web-tools.js → web-tools/index.js} +8 -8
- package/npm-shrinkwrap.json +79 -2
- package/package.json +3 -1
- package/web/dist/assets/index-D5Kd_ara.js +8 -0
- package/web/dist/assets/index-DbJZ_MJn.css +2 -0
- package/web/dist/assets/markdown-kaIeGxdv.js +14 -0
- package/web/dist/assets/react-Bi_azaFt.js +9 -0
- package/web/dist/assets/rolldown-runtime-S-ySWqyJ.js +1 -0
- package/web/dist/assets/ui-C12-nN_X.js +51 -0
- package/web/dist/assets/vendor-D1QXMhXm.js +16 -0
- package/web/dist/index.html +7 -2
- package/dist/media-understanding.js +0 -120
- package/dist/web.js +0 -641
- package/web/dist/assets/index-CSkxUQCr.js +0 -63
- package/web/dist/assets/index-DllM6RqL.css +0 -2
- /package/dist/{ids.js → conversation/ids.js} +0 -0
- /package/dist/{control.js → lifecycle/control.js} +0 -0
- /package/dist/{image-derivatives.js → media/image-derivatives.js} +0 -0
- /package/dist/{tts.js → media/tts.js} +0 -0
- /package/dist/{models.js → models/index.js} +0 -0
- /package/dist/{skills.js → prompting/skills.js} +0 -0
- /package/dist/{silent-marker.js → runtime/silent-marker.js} +0 -0
package/dist/web/stream.js
CHANGED
|
@@ -23,14 +23,23 @@ export function attachWebSocketStream(server, options) {
|
|
|
23
23
|
server.on("upgrade", (request, socket) => {
|
|
24
24
|
const netSocket = socket;
|
|
25
25
|
const url = new URL(request.url ?? "/", `http://${request.headers.host ?? "localhost"}`);
|
|
26
|
-
if (url.pathname !== "/api/web/stream"
|
|
26
|
+
if (url.pathname !== "/api/web/stream") {
|
|
27
27
|
netSocket.write("HTTP/1.1 401 Unauthorized\r\n\r\n");
|
|
28
28
|
netSocket.destroy();
|
|
29
29
|
return;
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
void authorize(request, url.pathname)
|
|
32
|
+
.then((authorized) => {
|
|
33
|
+
if (!authorized) {
|
|
34
|
+
netSocket.write("HTTP/1.1 401 Unauthorized\r\n\r\n");
|
|
35
|
+
netSocket.destroy();
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
return getRuntime(url.searchParams.get("channelKey") || undefined);
|
|
39
|
+
})
|
|
33
40
|
.then((runtime) => {
|
|
41
|
+
if (!runtime)
|
|
42
|
+
return;
|
|
34
43
|
if (netSocket.destroyed)
|
|
35
44
|
return;
|
|
36
45
|
if (!acceptWebSocket(request, netSocket))
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { PageCache } from "./
|
|
2
|
-
import { loadWebConfig } from "./
|
|
3
|
-
import { createJinaProvider, createTinyfishProvider } from "./
|
|
4
|
-
import { formatFetchContent, formatSearchResults, paginateContent } from "./
|
|
5
|
-
import { resolveSearchProviders } from "./
|
|
6
|
-
import { isTransientProviderError, validateFetchUrl } from "./
|
|
7
|
-
import { createBraveProvider, createExaProvider, createTavilyProvider, normalizeDomains
|
|
8
|
-
import { FETCH_DEFAULT_MAX_CHARS, WEB_UNTRUSTED_PREFIX, webFetchSchema, webSearchSchema, } from "./
|
|
1
|
+
import { PageCache } from "./cache.js";
|
|
2
|
+
import { loadWebConfig } from "./config.js";
|
|
3
|
+
import { createJinaProvider, createTinyfishProvider } from "./fetch-providers.js";
|
|
4
|
+
import { formatFetchContent, formatSearchResults, paginateContent } from "./format.js";
|
|
5
|
+
import { resolveSearchProviders } from "./routing.js";
|
|
6
|
+
import { isTransientProviderError, validateFetchUrl } from "./safety.js";
|
|
7
|
+
import { createBraveProvider, createExaProvider, createTavilyProvider, normalizeDomains } from "./search-providers.js";
|
|
8
|
+
import { FETCH_DEFAULT_MAX_CHARS, WEB_UNTRUSTED_PREFIX, webFetchSchema, webSearchSchema, } from "./types.js";
|
|
9
9
|
const pageCache = new PageCache();
|
|
10
10
|
function makeSearchTool(config) {
|
|
11
11
|
const providers = {};
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qearlyao/familiar",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@qearlyao/familiar",
|
|
9
|
-
"version": "0.
|
|
9
|
+
"version": "0.4.1",
|
|
10
10
|
"license": "MIT",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@earendil-works/pi-agent-core": "0.78.0",
|
|
13
13
|
"@earendil-works/pi-ai": "0.78.0",
|
|
14
14
|
"@earendil-works/pi-coding-agent": "0.78.0",
|
|
15
15
|
"better-sqlite3": "^12.10.0",
|
|
16
|
+
"cross-spawn": "^7.0.6",
|
|
16
17
|
"discord.js": "^14.26.3",
|
|
17
18
|
"dotenv": "^16.4.5",
|
|
18
19
|
"sharp": "^0.34.5",
|
|
@@ -26,6 +27,7 @@
|
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"@biomejs/biome": "2.4.15",
|
|
28
29
|
"@types/better-sqlite3": "^7.6.13",
|
|
30
|
+
"@types/cross-spawn": "^6.0.6",
|
|
29
31
|
"@types/node": "^25.8.0",
|
|
30
32
|
"tsx": "^4.22.1",
|
|
31
33
|
"typescript": "^5.9.2"
|
|
@@ -3852,6 +3854,16 @@
|
|
|
3852
3854
|
"@types/node": "*"
|
|
3853
3855
|
}
|
|
3854
3856
|
},
|
|
3857
|
+
"node_modules/@types/cross-spawn": {
|
|
3858
|
+
"version": "6.0.6",
|
|
3859
|
+
"resolved": "https://registry.npmjs.org/@types/cross-spawn/-/cross-spawn-6.0.6.tgz",
|
|
3860
|
+
"integrity": "sha512-fXRhhUkG4H3TQk5dBhQ7m/JDdSNHKwR2BBia62lhwEIq9xGiQKLxd6LymNhn47SjXhsUEPmxi+PKw2OkW4LLjA==",
|
|
3861
|
+
"dev": true,
|
|
3862
|
+
"license": "MIT",
|
|
3863
|
+
"dependencies": {
|
|
3864
|
+
"@types/node": "*"
|
|
3865
|
+
}
|
|
3866
|
+
},
|
|
3855
3867
|
"node_modules/@types/node": {
|
|
3856
3868
|
"version": "25.8.0",
|
|
3857
3869
|
"resolved": "https://registry.npmjs.org/@types/node/-/node-25.8.0.tgz",
|
|
@@ -4000,6 +4012,20 @@
|
|
|
4000
4012
|
"integrity": "sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==",
|
|
4001
4013
|
"license": "ISC"
|
|
4002
4014
|
},
|
|
4015
|
+
"node_modules/cross-spawn": {
|
|
4016
|
+
"version": "7.0.6",
|
|
4017
|
+
"resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz",
|
|
4018
|
+
"integrity": "sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==",
|
|
4019
|
+
"license": "MIT",
|
|
4020
|
+
"dependencies": {
|
|
4021
|
+
"path-key": "^3.1.0",
|
|
4022
|
+
"shebang-command": "^2.0.0",
|
|
4023
|
+
"which": "^2.0.1"
|
|
4024
|
+
},
|
|
4025
|
+
"engines": {
|
|
4026
|
+
"node": ">= 8"
|
|
4027
|
+
}
|
|
4028
|
+
},
|
|
4003
4029
|
"node_modules/data-uri-to-buffer": {
|
|
4004
4030
|
"version": "4.0.1",
|
|
4005
4031
|
"resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz",
|
|
@@ -4423,6 +4449,12 @@
|
|
|
4423
4449
|
"integrity": "sha512-JV/yugV2uzW5iMRSiZAyDtQd+nxtUnjeLt0acNdw98kKLrvuRVyB80tsREOE7yvGVgalhZ6RNXCmEHkUKBKxew==",
|
|
4424
4450
|
"license": "ISC"
|
|
4425
4451
|
},
|
|
4452
|
+
"node_modules/isexe": {
|
|
4453
|
+
"version": "2.0.0",
|
|
4454
|
+
"resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz",
|
|
4455
|
+
"integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==",
|
|
4456
|
+
"license": "ISC"
|
|
4457
|
+
},
|
|
4426
4458
|
"node_modules/json-bigint": {
|
|
4427
4459
|
"version": "1.0.0",
|
|
4428
4460
|
"resolved": "https://registry.npmjs.org/json-bigint/-/json-bigint-1.0.0.tgz",
|
|
@@ -4643,6 +4675,15 @@
|
|
|
4643
4675
|
"node": ">=14.0.0"
|
|
4644
4676
|
}
|
|
4645
4677
|
},
|
|
4678
|
+
"node_modules/path-key": {
|
|
4679
|
+
"version": "3.1.1",
|
|
4680
|
+
"resolved": "https://registry.npmjs.org/path-key/-/path-key-3.1.1.tgz",
|
|
4681
|
+
"integrity": "sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==",
|
|
4682
|
+
"license": "MIT",
|
|
4683
|
+
"engines": {
|
|
4684
|
+
"node": ">=8"
|
|
4685
|
+
}
|
|
4686
|
+
},
|
|
4646
4687
|
"node_modules/prebuild-install": {
|
|
4647
4688
|
"version": "7.1.3",
|
|
4648
4689
|
"resolved": "https://registry.npmjs.org/prebuild-install/-/prebuild-install-7.1.3.tgz",
|
|
@@ -4818,6 +4859,27 @@
|
|
|
4818
4859
|
"@img/sharp-win32-x64": "0.34.5"
|
|
4819
4860
|
}
|
|
4820
4861
|
},
|
|
4862
|
+
"node_modules/shebang-command": {
|
|
4863
|
+
"version": "2.0.0",
|
|
4864
|
+
"resolved": "https://registry.npmjs.org/shebang-command/-/shebang-command-2.0.0.tgz",
|
|
4865
|
+
"integrity": "sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==",
|
|
4866
|
+
"license": "MIT",
|
|
4867
|
+
"dependencies": {
|
|
4868
|
+
"shebang-regex": "^3.0.0"
|
|
4869
|
+
},
|
|
4870
|
+
"engines": {
|
|
4871
|
+
"node": ">=8"
|
|
4872
|
+
}
|
|
4873
|
+
},
|
|
4874
|
+
"node_modules/shebang-regex": {
|
|
4875
|
+
"version": "3.0.0",
|
|
4876
|
+
"resolved": "https://registry.npmjs.org/shebang-regex/-/shebang-regex-3.0.0.tgz",
|
|
4877
|
+
"integrity": "sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==",
|
|
4878
|
+
"license": "MIT",
|
|
4879
|
+
"engines": {
|
|
4880
|
+
"node": ">=8"
|
|
4881
|
+
}
|
|
4882
|
+
},
|
|
4821
4883
|
"node_modules/simple-concat": {
|
|
4822
4884
|
"version": "1.0.1",
|
|
4823
4885
|
"resolved": "https://registry.npmjs.org/simple-concat/-/simple-concat-1.0.1.tgz",
|
|
@@ -5101,6 +5163,21 @@
|
|
|
5101
5163
|
"node": ">= 8"
|
|
5102
5164
|
}
|
|
5103
5165
|
},
|
|
5166
|
+
"node_modules/which": {
|
|
5167
|
+
"version": "2.0.2",
|
|
5168
|
+
"resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz",
|
|
5169
|
+
"integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==",
|
|
5170
|
+
"license": "ISC",
|
|
5171
|
+
"dependencies": {
|
|
5172
|
+
"isexe": "^2.0.0"
|
|
5173
|
+
},
|
|
5174
|
+
"bin": {
|
|
5175
|
+
"node-which": "bin/node-which"
|
|
5176
|
+
},
|
|
5177
|
+
"engines": {
|
|
5178
|
+
"node": ">= 8"
|
|
5179
|
+
}
|
|
5180
|
+
},
|
|
5104
5181
|
"node_modules/wrappy": {
|
|
5105
5182
|
"version": "1.0.2",
|
|
5106
5183
|
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qearlyao/familiar",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"repository": {
|
|
@@ -46,6 +46,7 @@
|
|
|
46
46
|
"@earendil-works/pi-ai": "0.78.0",
|
|
47
47
|
"@earendil-works/pi-coding-agent": "0.78.0",
|
|
48
48
|
"better-sqlite3": "^12.10.0",
|
|
49
|
+
"cross-spawn": "^7.0.6",
|
|
49
50
|
"discord.js": "^14.26.3",
|
|
50
51
|
"dotenv": "^16.4.5",
|
|
51
52
|
"sharp": "^0.34.5",
|
|
@@ -56,6 +57,7 @@
|
|
|
56
57
|
"devDependencies": {
|
|
57
58
|
"@biomejs/biome": "2.4.15",
|
|
58
59
|
"@types/better-sqlite3": "^7.6.13",
|
|
60
|
+
"@types/cross-spawn": "^6.0.6",
|
|
59
61
|
"@types/node": "^25.8.0",
|
|
60
62
|
"tsx": "^4.22.1",
|
|
61
63
|
"typescript": "^5.9.2"
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import{r as e}from"./rolldown-runtime-S-ySWqyJ.js";import{i as t,n,t as r}from"./react-Bi_azaFt.js";import{$ as i,A as a,At as o,B as s,C as c,Ct as l,D as u,Dt as d,E as f,Et as p,F as m,G as h,H as g,I as _,J as v,K as y,L as b,M as x,N as S,O as C,Ot as ee,P as w,Q as te,R as ne,S as re,St as ie,T as ae,Tt as oe,U as T,V as se,W as ce,X as le,Y as ue,Z as de,_ as fe,_t as pe,a as me,at as he,b as ge,bt as _e,c as ve,ct as ye,d as be,dt as xe,et as Se,f as Ce,ft as we,g as Te,gt as Ee,h as De,ht as Oe,i as ke,it as Ae,j as je,k as Me,kt as Ne,l as Pe,lt as Fe,m as Ie,mt as Le,n as Re,nt as ze,o as Be,ot as Ve,p as He,pt as Ue,q as We,r as Ge,rt as Ke,s as qe,st as Je,t as Ye,tt as Xe,u as Ze,ut as Qe,v as $e,vt as et,w as tt,wt as nt,x as rt,xt as it,y as at,yt as ot,z as st}from"./ui-C12-nN_X.js";import{n as ct,r as E,t as lt}from"./markdown-kaIeGxdv.js";import{t as ut}from"./vendor-D1QXMhXm.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),e.crossOrigin===`use-credentials`?t.credentials=`include`:e.crossOrigin===`anonymous`?t.credentials=`omit`:t.credentials=`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var D=e(t(),1),dt=n();function O(...e){return Ye(g(e))}var ft=se(`group/button inline-flex shrink-0 items-center justify-center rounded-lg border border-transparent bg-clip-padding text-sm font-medium whitespace-nowrap transition-[background-color,border-color,box-shadow,color,opacity,transform] outline-none select-none focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 active:not-aria-[haspopup]:translate-y-px disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,{variants:{variant:{default:`bg-primary text-primary-foreground [a]:hover:bg-primary/80`,outline:`border-border bg-background hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50`,secondary:`bg-secondary text-secondary-foreground hover:bg-secondary/80 aria-expanded:bg-secondary aria-expanded:text-secondary-foreground`,ghost:`hover:bg-muted hover:text-foreground aria-expanded:bg-muted aria-expanded:text-foreground`,destructive:`bg-destructive/10 text-destructive hover:bg-destructive/20 focus-visible:border-destructive/40 focus-visible:ring-destructive/20 dark:bg-destructive/20 dark:hover:bg-destructive/30 dark:focus-visible:ring-destructive/40`,link:`text-primary underline-offset-4 hover:underline`},size:{default:`h-8 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2`,xs:`h-6 gap-1 rounded-[min(var(--radius-md),10px)] px-2 text-xs in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3`,sm:`h-7 gap-1 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] in-data-[slot=button-group]:rounded-lg has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5`,lg:`h-9 gap-1.5 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2`,icon:`size-8`,"icon-xs":`size-6 rounded-[min(var(--radius-md),10px)] in-data-[slot=button-group]:rounded-lg [&_svg:not([class*='size-'])]:size-3`,"icon-sm":`size-7 rounded-[min(var(--radius-md),12px)] in-data-[slot=button-group]:rounded-lg`,"icon-lg":`size-9`}},defaultVariants:{variant:`default`,size:`default`}}),k=r();function A({className:e,variant:t=`default`,size:n=`default`,asChild:r=!1,...i}){return(0,k.jsx)(r?s:`button`,{"data-slot":`button`,"data-variant":t,"data-size":n,className:O(ft({variant:t,size:n,className:e})),...i})}function pt(){return typeof crypto<`u`&&`randomUUID`in crypto?crypto.randomUUID():`step-${Date.now()}-${Math.random().toString(36).slice(2)}`}function mt(e){if(e.steps)return{id:e.id,role:e.role,who:e.who,steps:e.steps,attachments:e.attachments,usage:e.usage,silent:e.silent,ts:e.ts};let t=[];if(e.thinking||e.thinkingMs!=null){let n=e.ts,r=n-(e.thinkingMs??0);t.push({kind:`thinking`,id:pt(),text:e.thinking??``,startedAt:r,endedAt:n,complete:!0})}for(let n of e.tools??[])t.push({kind:`tool`,id:n.id,tool:n});return e.text&&t.push({kind:`text`,id:pt(),text:e.text,complete:!0}),{id:e.id,role:e.role,who:e.who,steps:t,attachments:e.attachments,usage:e.usage,silent:e.silent,ts:e.ts}}async function ht(){let e=await fetch(`/api/web/auth/mode`);if(!e.ok)throw Error(`auth/mode: ${e.status}`);let t=await e.json();return{mode:t.mode,personaName:t.personaName??`Familiar`}}async function gt(){let e=await fetch(`/api/web/auth/session`);if(e.status!==401){if(!e.ok)throw Error(`auth/session: ${e.status}`);return(await e.json()).device}}async function _t(e,t){return(await j(`/api/web/auth/login`,`POST`,{token:e,deviceName:t?.trim()||void 0},`auth/login`)).device}async function vt(){let e=await fetch(`/api/web/auth/devices`);if(!e.ok)throw Error(`auth/devices: ${e.status}`);return(await e.json()).devices}async function yt(e){await j(`/api/web/auth/devices`,`DELETE`,{id:e},`auth/devices`)}async function bt(){return(await j(`/api/web/auth/devices/revoke-others`,`POST`,{},`auth/devices/revoke-others`)).revoked}async function xt(){await j(`/api/web/auth/logout`,`POST`,{},`auth/logout`)}async function St(){let e=await fetch(`/api/web/sessions`);if(!e.ok)throw Error(`sessions: ${e.status}`);return(await e.json()).sessions}async function Ct(e,t=50){let n=new URLSearchParams({limit:String(t)});e&&n.set(`channelKey`,e);let r=await fetch(`/api/web/history?${n.toString()}`);if(!r.ok)throw Error(`history: ${r.status}`);let i=await r.json();return{messages:i.messages.map(mt),hasMore:i.hasMore,channelKey:i.channelKey}}async function wt(){let e=await fetch(`/api/web/diaries`);if(!e.ok)throw Error(`diaries: ${e.status}`);return(await e.json()).diaries}async function Tt(e){let t=new URLSearchParams({date:e}),n=await fetch(`/api/web/diary?${t.toString()}`);if(!n.ok)throw Error(`diary: ${n.status}`);return(await n.json()).diary}async function Et(e,t,n,r=[]){let i=new FormData;i.set(`text`,e),i.set(`clientId`,t),n&&i.set(`channelKey`,n);for(let e of r)i.append(`attachments`,e,e.name);let a=await fetch(`/api/web/send`,{method:`POST`,body:i});if(!a.ok){let e=await a.json().catch(()=>({}));throw Error(e.error??`send: ${a.status}`)}return await a.json()}function Dt(e){let t=window.location.protocol===`https:`?`wss:`:`ws:`,n=e?`?channelKey=${encodeURIComponent(e)}`:``;return`${t}//${window.location.host}/api/web/stream${n}`}async function Ot(e){let t=new URLSearchParams;e&&t.set(`channelKey`,e);let n=await fetch(`/api/web/agent/settings${t.toString()?`?${t.toString()}`:``}`);if(!n.ok)throw Error(`agent/settings: ${n.status}`);return await n.json()}async function kt(){let e=await fetch(`/api/web/agent/models`);if(!e.ok)throw Error(`agent/models: ${e.status}`);let t=await e.json();return{models:t.models,added:t.added??[]}}async function j(e,t,n,r){let i=await fetch(e,{method:t,headers:{"Content-Type":`application/json`},body:JSON.stringify(n)});if(!i.ok){let e=await i.json().catch(()=>({}));throw Error(e.error??`${r}: ${i.status}`)}return await i.json().catch(()=>void 0)}async function At(e){let t=await j(`/api/web/agent/models`,`POST`,{model:e},`agent/models`);return{models:t.models,added:t.added??[]}}async function jt(e){let t=await j(`/api/web/agent/models`,`DELETE`,{model:e},`agent/models`);return{models:t.models,added:t.added??[]}}async function Mt(e,t){return j(`/api/web/agent/settings`,`POST`,{channelKey:e,...t},`agent/settings`)}async function Nt(e){await j(`/api/web/agent/new`,`POST`,{channelKey:e},`agent/new`)}async function Pt(){let e=await fetch(`/api/web/memes`);if(!e.ok)throw Error(`memes: ${e.status}`);return(await e.json()).families}async function Ft(){let e=await fetch(`/api/web/config`);if(!e.ok)throw Error(`config: ${e.status}`);return await e.json()}async function It(e,t){return j(`/api/web/config`,`POST`,{key:e,value:t},`config`)}async function Lt(e){return j(`/api/web/config`,`DELETE`,{key:e},`config`)}var Rt=/\.(?:jpe?g|png|gif|webp)(?:\?[^\s]*)?$/i,M=/https?:\/\/[^\s)<>"']+/gi,zt=/meme:\s*/gi,Bt=/meme:\s*([^\n]*?)\($/i;function Vt(e){return`meme: ${e.name} (${e.url})`}function Ht(e){let t=Bt.exec(e);if(t)return{before:e.slice(0,t.index),name:(t[1]??``).trim()}}function Ut(e,t){let n=e.indexOf(`
|
|
2
|
+
`,t),r=n===-1?e.length:n,i=e.slice(t,r),a=new RegExp(M.source,`gi`),o=Array.from(i.matchAll(a));for(let e=o.length-1;e>=0;--e){let t=o[e],n=t?.[0],r=t?.index??0;if(!n)continue;let a=i.lastIndexOf(`(`,r),s=r+n.length;if(a===-1||i[s]!==`)`)continue;let c=i.slice(0,a).trim();if(c)return{whole:i.slice(0,s+1),name:c,url:n}}return null}function Wt(e){let t=[],n=0;for(;n<e.length;){zt.lastIndex=n,M.lastIndex=n;let r=zt.exec(e),i=M.exec(e),a=r&&(!i||r.index<=i.index)?r.index:-1,o=a===-1?i?.index:a;if(o===void 0)break;let s=a===o?Ut(e,a+(r?.[0].length??0)):null;if(a===o&&!s){n=o+(r?.[0].length??0);continue}let c=s?.whole??i?.[0];if(!c)break;if(s){t.push({type:`meme`,index:o,whole:`${r?.[0]??``}${s.whole}`,name:s.name,url:s.url}),n=o+(r?.[0].length??0)+s.whole.length;continue}Rt.test(c)&&t.push({type:`image-url`,index:o,whole:c,url:c}),n=o+c.length}return t}var Gt=()=>[{type:`text`,value:``}];function N(e){return{type:`text`,value:e}}function Kt(e){return e.trim().length>0}function qt(e,t){return e?t?`${e.replace(/[ \t]+$/,``).replace(/\n+$/,``)}\n${t.replace(/^\n+/,``)}`:e:t}function Jt(e,t){let n=Math.max(0,Math.min(t.start,e.length));return{start:n,end:Math.max(n,Math.min(t.end,e.length))}}function Yt(e){let t=-1;for(let n=e.length-1;n>=0;--n)if(e[n]?.type===`text`){t=n;break}return t===-1?e.length:t}function Xt(e){return e.flatMap(e=>e.type===`meme`?[Vt(e)]:Kt(e.value)?[e.value.trim()]:[]).join(`
|
|
3
|
+
`).trim()}function Zt(e){return Xt(e).length>0}function Qt(e,t,n){let r=t&&e[t.blockIndex]?.type===`text`?t.blockIndex:Yt(e),i=e[r];if(!i||i.type!==`text`)return{blocks:[...e,{type:`meme`,...n},N(``)],focusIndex:e.length+1};let{start:a,end:o}=t?Jt(i.value,t):{start:i.value.length,end:i.value.length},s=i.value.slice(0,a),c=i.value.slice(o),l=[...s?[N(s)]:[],{type:`meme`,...n},N(c)];return{blocks:[...e.slice(0,r),...l,...e.slice(r+1)],focusIndex:r+l.length-1}}function $t(e,t){let n=[];for(let[r,i]of e.entries()){if(r===t)continue;let e=n.at(-1);if(e?.type===`text`&&i.type===`text`){e.value=qt(e.value,i.value);continue}n.push({...i})}if(n.length===0)return{blocks:Gt(),focusIndex:0};let r=n.findIndex((e,n)=>n>=t&&e.type===`text`);if(r!==-1)return{blocks:n,focusIndex:r};let i=-1;for(let e=n.length-1;e>=0;--e)if(n[e]?.type===`text`){i=e;break}return{blocks:n.some(e=>e.type===`text`)?n:[...n,N(``)],focusIndex:i===-1?n.length:i}}function en({onPick:e}){let[t,n]=(0,D.useState)(!1),[r,i]=(0,D.useState)(null),[a,o]=(0,D.useState)(null),[s,c]=(0,D.useState)(null),[l,u]=(0,D.useState)(``),d=(0,D.useRef)(null),f=(0,D.useRef)(!1);(0,D.useEffect)(()=>{t&&(r!=null||f.current||(f.current=!0,Pt().then(e=>{i(e),!s&&e[0]&&c(e[0].name),o(null)}).catch(()=>o(`catalog unavailable`)).finally(()=>{f.current=!1})))},[t,r,s]),(0,D.useEffect)(()=>{if(t){let e=window.setTimeout(()=>d.current?.focus(),30);return()=>window.clearTimeout(e)}let e=window.setTimeout(()=>u(``),0);return()=>window.clearTimeout(e)},[t]);let p=(0,D.useMemo)(()=>r?r.find(e=>e.name===s)??r[0]??null:null,[r,s]),m=(0,D.useMemo)(()=>{if(!p)return[];let e=l.trim().toLowerCase();return e?p.memes.filter(t=>t.name.toLowerCase().includes(e)):p.memes},[p,l]),h=t=>{e(t),n(!1)};return(0,k.jsxs)(Ie,{open:t,onOpenChange:n,children:[(0,k.jsx)(De,{asChild:!0,children:(0,k.jsx)(A,{type:`button`,size:`sm`,variant:`ghost`,"aria-label":`memes`,className:`text-muted-foreground hover:text-foreground`,children:(0,k.jsx)(te,{className:`size-4`})})}),(0,k.jsx)(He,{children:(0,k.jsx)(Ce,{side:`top`,align:`end`,sideOffset:10,collisionPadding:16,className:O(`z-50 w-[min(28rem,calc(100vw-2rem))] origin-(--radix-popover-content-transform-origin)`,`rounded-md border border-border bg-card p-3 shadow-md`,`data-[state=open]:animate-in data-[state=closed]:animate-out`,`data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0`,`data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95`),children:a?(0,k.jsx)(`div`,{className:`px-2 py-6 text-center font-serif text-sm italic text-muted-foreground`,children:a}):r?(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:`flex items-center gap-3 px-1 pb-2 text-sm`,children:r.map((e,t)=>(0,k.jsxs)(`span`,{className:`flex items-center gap-3`,children:[t>0&&(0,k.jsx)(`span`,{className:`text-muted-foreground/40`,children:`·`}),(0,k.jsx)(`button`,{type:`button`,onClick:()=>c(e.name),className:O(`font-serif tracking-tight transition-colors`,e.name===p?.name?`text-foreground`:`italic text-muted-foreground hover:text-foreground`),children:e.name})]},e.name))}),(0,k.jsx)(`input`,{ref:d,type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:`search by name…`,className:O(`mb-2 w-full rounded border border-input bg-background px-2.5 py-1.5 text-sm`,`placeholder:text-muted-foreground focus:outline-none`,`transition-[border-color,box-shadow] focus:border-ring focus:ring-3 focus:ring-ring/30`)}),(0,k.jsx)(`div`,{className:`max-h-72 overflow-y-auto`,children:m.length===0?(0,k.jsx)(`div`,{className:`px-2 py-6 text-center font-serif text-sm italic text-muted-foreground/80`,children:`nothing in this family matches`}):(0,k.jsx)(`div`,{className:`grid grid-cols-4 gap-2 sm:grid-cols-5`,children:m.map(e=>(0,k.jsxs)(`button`,{type:`button`,onClick:()=>h(e),title:e.name,className:O(`group relative aspect-square overflow-hidden rounded border border-border/60 bg-background`,`transition-[border-color,transform] hover:border-ring hover:-translate-y-px`),children:[(0,k.jsx)(`img`,{src:e.url,alt:e.name,loading:`lazy`,className:`h-full w-full object-cover`}),(0,k.jsx)(`span`,{className:O(`pointer-events-none absolute inset-x-0 bottom-0 truncate px-1 py-0.5`,`bg-gradient-to-t from-background/95 via-background/70 to-transparent`,`text-[10px] font-medium leading-tight text-foreground`,`opacity-0 transition-opacity group-hover:opacity-100`),children:e.name})]},e.url))})})]}):(0,k.jsx)(`div`,{className:`px-2 py-6 text-center font-serif text-sm italic text-muted-foreground/80`,children:`opening the drawer…`})})})]})}function tn(e,t,n){let r=e[n]?.type===`text`?n:e.findIndex(e=>e.type===`text`),i=e[r];if(r===-1||!i||i.type!==`text`)return;let a=t.get(r),o=i.value.length;return{blockIndex:r,start:a?.selectionStart??o,end:a?.selectionEnd??o}}function nn({blocks:e,personaName:t,onUpdateBlocks:n,onPasteFiles:r,onSubmit:i}){let a=(0,D.useRef)(new Map),o=(0,D.useRef)(0),s=(0,D.useRef)(null),c=!Zt(e);(0,D.useEffect)(()=>{for(let e of a.current.values())e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`;let e=s.current;if(e===null)return;s.current=null;let t=a.current.get(e);t&&(t.focus(),t.setSelectionRange(0,0))},[e]);let l=t=>{let r=tn(e,a.current,o.current);n(e=>{let n=Qt(e,r,t);return s.current=n.focusIndex,o.current=n.focusIndex,n.blocks})},u=e=>{n(t=>{let n=$t(t,e);return s.current=n.focusIndex,o.current=n.focusIndex,n.blocks})};return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(en,{onPick:l}),(0,k.jsx)(`div`,{className:`flex min-w-0 flex-1 flex-col gap-1.5`,children:e.map((e,s)=>e.type===`meme`?(0,k.jsxs)(`div`,{className:`inline-flex max-w-[16rem] items-center gap-2 self-start rounded border border-border/70 bg-background/70 p-1 pr-1.5`,children:[(0,k.jsx)(`img`,{src:e.url,alt:e.name,loading:`lazy`,className:`size-12 rounded-sm object-cover`}),(0,k.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-serif text-xs italic text-muted-foreground`,children:e.name}),(0,k.jsx)(`button`,{type:`button`,onClick:()=>u(s),className:`rounded-sm p-1 text-muted-foreground transition-colors hover:text-foreground focus-visible:ring-2 focus-visible:ring-ring/40 focus-visible:outline-none`,"aria-label":`remove ${e.name}`,children:(0,k.jsx)(T,{className:`size-3`})})]},`${e.url}-${s}`):(0,k.jsx)(`textarea`,{ref:e=>{e?a.current.set(s,e):a.current.delete(s)},value:e.value,onFocus:()=>{o.current=s},onSelect:()=>{o.current=s},onChange:e=>{let t=e.target.value;n(e=>{let n=e[s];if(!n||n.type!==`text`)return e;let r=[...e];return r[s]={type:`text`,value:t},r})},onPaste:e=>{let t=Array.from(e.clipboardData.files);t.length>0&&r(t)},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),i())},placeholder:c?`write to ${t}…`:void 0,rows:1,autoFocus:s===0,className:`min-h-8 w-full resize-none bg-transparent leading-8 text-foreground placeholder:text-muted-foreground focus:outline-none`},`text-${s}`))})]})}function rn(e=0){return{blocks:Gt(),attachments:[],revision:e}}function an(e){let t=e instanceof Error?e.message:`send failed`,n=t?`${t.charAt(0).toLowerCase()}${t.slice(1)}`:`send failed`;return n.startsWith(`send failed`)?n:`send failed: ${n}`}function on(e){return rn(e.revision+1)}function sn(e,t){return e.revision===t&&!Zt(e.blocks)&&e.attachments.length===0}function cn({onSend:e,onAbort:t,streaming:n,personaName:r}){let[i,a]=(0,D.useState)(()=>rn()),[o,s]=(0,D.useState)(!1),[c,l]=(0,D.useState)(!1),[u,d]=(0,D.useState)(),f=(0,D.useRef)(null),{blocks:p,attachments:m}=i,h=(0,D.useMemo)(()=>Xt(p),[p]),g=async()=>{if(c)return;let t=i,n=Xt(t.blocks);if(!n&&t.attachments.length===0)return;let r=t.revision+1;d(void 0),l(!0),a(on);try{await e(n,t.attachments)}catch(e){a(e=>sn(e,r)?t:e),d(an(e))}finally{l(!1)}},_=e=>{d(void 0),a(t=>{let n=e(t.blocks);return n===t.blocks?t:{...t,blocks:n,revision:t.revision+1}})},v=e=>{e.length!==0&&(d(void 0),a(t=>({...t,attachments:[...t.attachments,...e],revision:t.revision+1})))},y=(e,t)=>{let n=Array.from(e).filter(e=>e.kind===`file`).map(e=>e.getAsFile()).filter(e=>!!e);return n.length>0?n:Array.from(t)},b=c||!n&&!h&&m.length===0,x=n&&!c;return(0,k.jsx)(`div`,{className:`border-t border-border bg-background pb-[env(safe-area-inset-bottom)]`,children:(0,k.jsxs)(`div`,{className:`mx-auto max-w-3xl px-5 py-4`,children:[(0,k.jsx)(`input`,{ref:f,type:`file`,multiple:!0,className:`hidden`,onChange:e=>{v(e.target.files?Array.from(e.target.files):[]),e.target.value=``}}),(0,k.jsxs)(`div`,{onDragEnter:e=>{e.dataTransfer.types.includes(`Files`)&&(e.preventDefault(),s(!0))},onDragOver:e=>{e.dataTransfer.types.includes(`Files`)&&e.preventDefault()},onDragLeave:e=>{e.currentTarget.contains(e.relatedTarget)||s(!1)},onDrop:e=>{e.preventDefault(),s(!1),v(y(e.dataTransfer.items,e.dataTransfer.files))},className:O(`flex flex-col gap-2 rounded-md border border-input bg-card px-3 py-2.5 shadow-sm transition-[border-color,box-shadow] focus-within:border-ring focus-within:ring-3 focus-within:ring-ring/30`,o&&`border-ring ring-3 ring-ring/30`),children:[m.length>0&&(0,k.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:m.map((e,t)=>(0,k.jsxs)(`button`,{type:`button`,onClick:()=>{d(void 0),a(e=>({...e,attachments:e.attachments.filter((e,n)=>n!==t),revision:e.revision+1}))},className:`inline-flex items-center gap-1 rounded border border-border px-2 py-1 text-xs text-muted-foreground`,children:[e.name,(0,k.jsx)(T,{className:`size-3`})]},`${e.name}-${t}`))}),(0,k.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,k.jsx)(A,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>f.current?.click(),"aria-label":`attach`,className:`text-muted-foreground hover:text-foreground`,children:(0,k.jsx)(Ve,{className:`size-4`})}),(0,k.jsx)(nn,{blocks:p,personaName:r,onUpdateBlocks:_,onPasteFiles:v,onSubmit:()=>void g()}),(0,k.jsx)(A,{type:`button`,size:`sm`,onClick:x?t:()=>void g(),disabled:b,"aria-label":x?`stop`:`send`,className:`h-8 px-3`,children:x?(0,k.jsx)(ue,{className:`size-3 fill-current`,strokeWidth:0}):(0,k.jsx)(Se,{className:`size-4`})})]})]}),u?(0,k.jsx)(`p`,{className:`mt-1.5 text-center font-serif text-xs italic text-destructive`,children:u}):null,(0,k.jsx)(`p`,{className:`mt-1.5 text-center text-[11px] tracking-wide text-muted-foreground`,children:`enter to send · shift+enter for newline`})]})})}function ln({...e}){return(0,k.jsx)(st,{"data-slot":`collapsible`,...e})}function un({...e}){return(0,k.jsx)(ne,{"data-slot":`collapsible-trigger`,...e})}function dn({...e}){return(0,k.jsx)(b,{"data-slot":`collapsible-content`,...e})}function fn({...e}){return(0,k.jsx)(w,{"data-slot":`sheet`,...e})}function pn({...e}){return(0,k.jsx)(S,{"data-slot":`sheet-portal`,...e})}function mn({className:e,...t}){return(0,k.jsx)(x,{"data-slot":`sheet-overlay`,className:O(`fixed inset-0 z-50 bg-foreground/15 duration-100 data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0`,e),...t})}function hn({className:e,children:t,side:n=`right`,showCloseButton:r=!0,...i}){return(0,k.jsxs)(pn,{children:[(0,k.jsx)(mn,{}),(0,k.jsxs)(je,{"data-slot":`sheet-content`,"data-side":n,className:O(`fixed z-50 flex flex-col gap-4 bg-popover bg-clip-padding text-sm text-popover-foreground shadow-lg transition duration-200 ease-in-out data-[side=bottom]:inset-x-0 data-[side=bottom]:bottom-0 data-[side=bottom]:h-auto data-[side=bottom]:border-t data-[side=left]:inset-y-0 data-[side=left]:left-0 data-[side=left]:h-full data-[side=left]:w-3/4 data-[side=left]:border-r data-[side=right]:inset-y-0 data-[side=right]:right-0 data-[side=right]:h-full data-[side=right]:w-3/4 data-[side=right]:border-l data-[side=top]:inset-x-0 data-[side=top]:top-0 data-[side=top]:h-auto data-[side=top]:border-b data-[side=left]:sm:max-w-sm data-[side=right]:sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-[side=bottom]:data-open:slide-in-from-bottom-10 data-[side=left]:data-open:slide-in-from-left-10 data-[side=right]:data-open:slide-in-from-right-10 data-[side=top]:data-open:slide-in-from-top-10 data-closed:animate-out data-closed:fade-out-0 data-[side=bottom]:data-closed:slide-out-to-bottom-10 data-[side=left]:data-closed:slide-out-to-left-10 data-[side=right]:data-closed:slide-out-to-right-10 data-[side=top]:data-closed:slide-out-to-top-10`,e),...i,children:[t,r&&(0,k.jsx)(a,{"data-slot":`sheet-close`,asChild:!0,children:(0,k.jsxs)(A,{variant:`ghost`,className:`absolute top-3 right-3`,size:`icon-sm`,children:[(0,k.jsx)(T,{}),(0,k.jsx)(`span`,{className:`sr-only`,children:`Close`})]})})]})]})}function gn({className:e,...t}){return(0,k.jsx)(`div`,{"data-slot":`sheet-header`,className:O(`flex flex-col gap-0.5 p-4`,e),...t})}function _n({className:e,...t}){return(0,k.jsx)(m,{"data-slot":`sheet-title`,className:O(`font-heading text-base font-medium text-foreground`,e),...t})}function vn({className:e,...t}){return(0,k.jsx)(be,{"data-slot":`radio-group`,className:O(`grid w-full gap-2`,e),...t})}function yn({className:e,...t}){return(0,k.jsx)(Ze,{"data-slot":`radio-group-item`,className:O(`group/radio-group-item peer relative flex aspect-square size-4 shrink-0 rounded-full border border-input outline-none after:absolute after:-inset-x-3 after:-inset-y-2 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/20 aria-invalid:aria-checked:border-primary dark:bg-input/30 dark:aria-invalid:border-destructive/50 dark:aria-invalid:ring-destructive/40 data-checked:border-primary data-checked:bg-primary data-checked:text-primary-foreground dark:data-checked:bg-primary`,e),...t,children:(0,k.jsx)(Pe,{"data-slot":`radio-group-indicator`,className:`flex size-4 items-center justify-center`,children:(0,k.jsx)(`span`,{className:`absolute top-1/2 left-1/2 size-2 -translate-x-1/2 -translate-y-1/2 rounded-full bg-primary-foreground`})})})}function bn({className:e,...t}){return(0,k.jsx)(Te,{"data-slot":`label`,className:O(`flex items-center gap-2 text-sm leading-none font-medium select-none group-data-[disabled=true]:pointer-events-none group-data-[disabled=true]:opacity-50 peer-disabled:cursor-not-allowed peer-disabled:opacity-50`,e),...t})}function xn({models:e,added:t,current:n,source:r,disabled:i,onChange:a,onAdd:o,onRemove:s}){let[c,l]=(0,D.useState)(``),[u,d]=(0,D.useState)(!1),[f,p]=(0,D.useState)(),m=new Set(t),h=async e=>{e.preventDefault();let t=c.trim();if(t){if(!t.includes(`/`)||t.startsWith(`/`)||t.endsWith(`/`)){p(`format must be provider/model-id`);return}p(void 0),d(!0);try{await o(t),l(``)}catch(e){p(e instanceof Error?e.message:String(e))}finally{d(!1)}}},g=async(e,t)=>{e.preventDefault(),e.stopPropagation(),d(!0);try{await s(t)}catch{}finally{d(!1)}};return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(vn,{value:n??``,onValueChange:a,disabled:i,className:`grid gap-1`,children:e.map(e=>{let t=`model-${e}`,r=e===n,a=m.has(e),[o,...s]=e.split(`/`),c=s.join(`/`);return(0,k.jsxs)(bn,{htmlFor:t,className:`group/row flex cursor-pointer items-center gap-3 rounded-md px-3 py-2.5 transition-colors hover:bg-accent has-data-[state=checked]:bg-primary has-data-[state=checked]:text-primary-foreground has-data-[state=checked]:hover:bg-primary`,children:[(0,k.jsx)(yn,{value:e,id:t}),(0,k.jsxs)(`span`,{className:`min-w-0 flex-1 font-mono text-sm leading-tight`,children:[(0,k.jsx)(`span`,{className:r?`text-primary-foreground/70`:`text-muted-foreground group-hover/row:text-foreground`,children:o}),(0,k.jsx)(`span`,{className:r?`text-primary-foreground/70`:`text-muted-foreground group-hover/row:text-foreground`,children:`/`}),(0,k.jsx)(`span`,{className:r?`text-primary-foreground`:`text-muted-foreground group-hover/row:text-foreground`,children:c})]}),a?(0,k.jsx)(`button`,{type:`button`,onClick:t=>g(t,e),"aria-label":`remove ${e}`,disabled:u||i,className:`flex size-6 shrink-0 items-center justify-center rounded-sm opacity-0 transition-opacity group-hover/row:opacity-100 focus-visible:opacity-100 disabled:cursor-not-allowed `+(r?`text-primary-foreground/70 hover:text-primary-foreground`:`text-muted-foreground hover:text-foreground`),children:(0,k.jsx)(T,{className:`size-3.5`})}):null]},e)})}),n&&r?(0,k.jsx)(`p`,{className:`mt-2 font-serif text-xs italic text-muted-foreground/70`,children:r===`override`?`set for this channel`:`inherited from default config`}):null,(0,k.jsxs)(`form`,{onSubmit:h,className:`mt-4 flex items-center gap-2`,children:[(0,k.jsx)(`input`,{type:`text`,value:c,onChange:e=>{l(e.target.value),f&&p(void 0)},placeholder:`provider/model-id`,spellCheck:!1,autoComplete:`off`,disabled:u||i,className:`h-8 min-w-0 flex-1 rounded-md border border-border bg-background px-3 font-mono text-sm text-foreground placeholder:text-muted-foreground/60 focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-none disabled:opacity-50`}),(0,k.jsx)(A,{type:`submit`,variant:`outline`,size:`default`,disabled:u||i||!c.trim(),children:`add`})]}),f?(0,k.jsx)(`p`,{className:`mt-2 font-serif text-xs italic text-destructive`,children:f}):null]})}var Sn=se(`group/toggle inline-flex items-center justify-center gap-1 rounded-lg text-sm font-medium whitespace-nowrap transition-[background-color,border-color,box-shadow,color,opacity,transform] outline-none hover:bg-muted hover:text-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 aria-pressed:bg-muted data-[state=on]:bg-muted dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4`,{variants:{variant:{default:`bg-transparent`,outline:`border border-input bg-transparent hover:bg-muted`},size:{default:`h-8 min-w-8 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2`,sm:`h-7 min-w-7 rounded-[min(var(--radius-md),12px)] px-2.5 text-[0.8rem] has-data-[icon=inline-end]:pr-1.5 has-data-[icon=inline-start]:pl-1.5 [&_svg:not([class*='size-'])]:size-3.5`,lg:`h-9 min-w-9 px-2.5 has-data-[icon=inline-end]:pr-2 has-data-[icon=inline-start]:pl-2`}},defaultVariants:{variant:`default`,size:`default`}}),Cn=D.createContext({size:`default`,variant:`default`,spacing:0,orientation:`horizontal`});function P({className:e,variant:t,size:n,spacing:r=0,orientation:i=`horizontal`,children:a,...o}){return(0,k.jsx)(Ge,{"data-slot":`toggle-group`,"data-variant":t,"data-size":n,"data-spacing":r,"data-orientation":i,style:{"--gap":r},className:O(`group/toggle-group flex w-fit flex-row items-center gap-[--spacing(var(--gap))] rounded-lg data-[size=sm]:rounded-[min(var(--radius-md),10px)] data-vertical:flex-col data-vertical:items-stretch`,e),...o,children:(0,k.jsx)(Cn.Provider,{value:{variant:t,size:n,spacing:r,orientation:i},children:a})})}function F({className:e,children:t,variant:n=`default`,size:r=`default`,...i}){let a=D.useContext(Cn);return(0,k.jsx)(Re,{"data-slot":`toggle-group-item`,"data-variant":a.variant||n,"data-size":a.size||r,"data-spacing":a.spacing,className:O(`shrink-0 group-data-[spacing=0]/toggle-group:rounded-none group-data-[spacing=0]/toggle-group:px-2 focus:z-10 focus-visible:z-10 group-data-[spacing=0]/toggle-group:has-data-[icon=inline-end]:pr-1.5 group-data-[spacing=0]/toggle-group:has-data-[icon=inline-start]:pl-1.5 group-data-horizontal/toggle-group:data-[spacing=0]:first:rounded-l-lg group-data-vertical/toggle-group:data-[spacing=0]:first:rounded-t-lg group-data-horizontal/toggle-group:data-[spacing=0]:last:rounded-r-lg group-data-vertical/toggle-group:data-[spacing=0]:last:rounded-b-lg group-data-horizontal/toggle-group:data-[spacing=0]:data-[variant=outline]:border-l-0 group-data-vertical/toggle-group:data-[spacing=0]:data-[variant=outline]:border-t-0 group-data-horizontal/toggle-group:data-[spacing=0]:data-[variant=outline]:first:border-l group-data-vertical/toggle-group:data-[spacing=0]:data-[variant=outline]:first:border-t`,Sn({variant:a.variant||n,size:a.size||r}),e),...i,children:t})}var wn=[`off`,`minimal`,`low`,`medium`,`high`,`xhigh`];function Tn({current:e,supported:t,disabled:n,onChange:r}){let i=wn.filter(e=>t.includes(e)),a=i.length>0?i:wn,o=a.length<=1?`grid-cols-1`:a.length===2?`grid-cols-2`:`grid-cols-3`;return(0,k.jsx)(P,{type:`single`,value:e??``,onValueChange:e=>{e&&r(e)},disabled:n,className:O(`grid w-full items-stretch gap-1 rounded-md bg-muted/40 p-1`,o),children:a.map(e=>(0,k.jsx)(F,{value:e,"aria-label":`thinking ${e}`,className:`h-8 w-full justify-center rounded-sm px-2 font-mono text-xs lowercase text-muted-foreground transition-colors hover:bg-muted hover:text-foreground data-[state=on]:bg-primary data-[state=on]:text-primary-foreground data-[state=on]:hover:bg-primary`,children:e},e))})}var En=`familiar.theme`;function Dn(){return window.matchMedia(`(prefers-color-scheme: dark)`).matches}function I(){let e=localStorage.getItem(En);return e===`light`||e===`dark`||e===`auto`?e:`auto`}function On(e){localStorage.setItem(En,e),L(e)}function L(e){let t=e===`dark`||e===`auto`&&Dn();document.documentElement.classList.toggle(`dark`,t)}function kn(e){let t=window.matchMedia(`(prefers-color-scheme: dark)`),n=()=>{e()===`auto`&&L(`auto`)};return t.addEventListener(`change`,n),()=>t.removeEventListener(`change`,n)}var An=[`light`,`dark`,`auto`],jn={light:v,dark:Fe,auto:Qe},Mn={light:`light`,dark:`dark`,auto:`system`};function Nn(){let[e,t]=(0,D.useState)(()=>I());return(0,D.useEffect)(()=>{On(e)},[e]),(0,k.jsx)(P,{type:`single`,value:e,onValueChange:e=>{e&&t(e)},spacing:1,className:`rounded-lg bg-muted/40 p-1`,children:An.map(e=>{let t=jn[e];return(0,k.jsxs)(F,{value:e,"aria-label":Mn[e],className:`h-9 gap-2 rounded-md px-3.5 text-sm lowercase text-muted-foreground transition-colors hover:bg-muted hover:text-foreground data-[state=on]:bg-primary data-[state=on]:text-primary-foreground data-[state=on]:hover:bg-primary`,children:[(0,k.jsx)(t,{className:`size-4`}),(0,k.jsx)(`span`,{children:Mn[e]})]},e)})})}function R(e,t,n){let[r,i]=(0,D.useState)(e),[a,o]=(0,D.useState)(!1),[s,c]=(0,D.useState)(!1),l=(0,D.useRef)(!1);(0,D.useEffect)(()=>{l.current||i(e)},[e]);let u=async()=>{let a=t(r);if(a===`invalid`){c(!0);return}if(c(!1),a===`reset`){i(e);return}o(!0);try{await n(a.value)}catch{i(e)}finally{o(!1)}};return{busy:a,invalid:s,inputProps:{value:r,onChange:e=>{i(e.target.value),s&&c(!1)},onFocus:()=>{l.current=!0},onBlur:()=>{l.current=!1,u()},onKeyDown:e=>{e.key===`Enter`&&e.currentTarget.blur()}}}}var Pn=`h-9 rounded-md px-3.5 text-sm lowercase text-muted-foreground transition-colors hover:bg-muted hover:text-foreground data-[state=on]:bg-primary data-[state=on]:text-primary-foreground data-[state=on]:hover:bg-primary`;function z({enabled:e,disabled:t,ariaPrefix:n,onChange:r}){return(0,k.jsxs)(P,{type:`single`,value:e===void 0?``:e===!0?`on`:`off`,onValueChange:e=>{e&&r(e===`on`)},disabled:t,spacing:1,className:`rounded-lg bg-muted/40 p-1`,children:[(0,k.jsx)(F,{value:`on`,"aria-label":`${n} on`,className:Pn,children:`on`}),(0,k.jsx)(F,{value:`off`,"aria-label":`${n} off`,className:Pn,children:`off`})]})}var Fn=6e4;function In({valueMs:e,disabled:t,onCommit:n}){let r=R(e===void 0?``:String(Math.round(e/Fn)),t=>{let n=Number.parseInt(t,10);if(Number.isNaN(n)||n<1)return`reset`;let r=n*Fn;return r===e?`reset`:{value:r}},n);return(0,k.jsx)(`input`,{...r.inputProps,type:`number`,inputMode:`numeric`,disabled:t||r.busy,min:1,className:`h-8 w-16 rounded-md border border-border bg-background px-2 font-mono text-sm text-right text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-none disabled:opacity-50`})}function B({value:e,step:t=1,min:n,max:r,disabled:i,onCommit:a}){let o=R(e===void 0?``:String(e),t=>{let i=Number(t);return!Number.isFinite(i)||n!==void 0&&i<n||r!==void 0&&i>r||i===e?`reset`:{value:i}},a);return(0,k.jsx)(`input`,{...o.inputProps,type:`number`,inputMode:t<1?`decimal`:`numeric`,disabled:i||o.busy,step:t,min:n,max:r,className:`h-8 w-20 rounded-md border border-border bg-background px-2 font-mono text-sm text-right text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-none disabled:opacity-50`})}var Ln=/^[^/\s]+\/[^\s]+$/;function Rn({value:e,placeholder:t,allowEmpty:n,disabled:r,onCommit:i}){let a=e??``,o=R(a,e=>{let t=e.trim();return t===a?`reset`:t?Ln.test(t)?{value:t}:`invalid`:n?{value:``}:`reset`},i);return(0,k.jsx)(`input`,{...o.inputProps,type:`text`,autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`off`,spellCheck:!1,placeholder:t,disabled:r||o.busy,className:`h-9 w-full rounded-md border bg-background px-3 font-mono text-sm text-foreground focus-visible:ring-3 focus-visible:outline-none disabled:opacity-50 ${o.invalid?`border-destructive focus-visible:border-destructive focus-visible:ring-destructive/40`:`border-border focus-visible:border-ring focus-visible:ring-ring/50`}`})}function zn({values:e,disabled:t,onChange:n}){let r=e?.[`heartbeat.enabled`].value,i=r===!0;return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(z,{enabled:r,disabled:t,ariaPrefix:`heartbeat`,onChange:e=>void n(`heartbeat.enabled`,e)}),(0,k.jsxs)(`div`,{className:`mt-4 grid gap-4`,children:[(0,k.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,k.jsx)(`span`,{className:`flex-1 font-serif text-sm text-foreground`,children:`first wakeup after`}),(0,k.jsx)(In,{valueMs:e?.[`heartbeat.idleThresholdMs`].value,disabled:t||!i,onCommit:e=>n(`heartbeat.idleThresholdMs`,e)}),(0,k.jsx)(`span`,{className:`w-14 font-serif text-xs italic text-muted-foreground`,children:`minutes`})]}),(0,k.jsx)(`p`,{className:`font-serif text-xs italic text-muted-foreground/70`,children:`minutes of silence before the first wakeup`})]}),(0,k.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,k.jsx)(`span`,{className:`flex-1 font-serif text-sm text-foreground`,children:`between wakeups`}),(0,k.jsx)(In,{valueMs:e?.[`heartbeat.intervalMs`].value,disabled:t||!i,onCommit:e=>n(`heartbeat.intervalMs`,e)}),(0,k.jsx)(`span`,{className:`w-14 font-serif text-xs italic text-muted-foreground`,children:`minutes`})]}),(0,k.jsx)(`p`,{className:`font-serif text-xs italic text-muted-foreground/70`,children:`cadence of subsequent wakeups while you stay quiet`})]})]})]})}function Bn({values:e,disabled:t,onChange:n}){let r=e?.[`image_gen.enabled`].value,i=t||r!==!0;return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(z,{enabled:r,disabled:t,ariaPrefix:`image generation`,onChange:e=>void n(`image_gen.enabled`,e)}),(0,k.jsxs)(`div`,{className:`mt-4 grid gap-4`,children:[(0,k.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,k.jsx)(`span`,{className:`font-serif text-sm text-foreground`,children:`primary model`}),(0,k.jsx)(Rn,{value:e?.[`image_gen.model`].value,placeholder:`openrouter/google/gemini-2.5-flash-image`,allowEmpty:!1,disabled:i,onCommit:e=>n(`image_gen.model`,e)}),(0,k.jsx)(`p`,{className:`font-serif text-xs italic text-muted-foreground/70`,children:`format: provider/model-id`})]}),(0,k.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,k.jsx)(`span`,{className:`font-serif text-sm text-foreground`,children:`fallback model`}),(0,k.jsx)(Rn,{value:e?.[`image_gen.fallback_model`].value,placeholder:`none`,allowEmpty:!0,disabled:i,onCommit:e=>n(`image_gen.fallback_model`,e)}),(0,k.jsx)(`p`,{className:`font-serif text-xs italic text-muted-foreground/70`,children:`leave empty for no fallback`})]})]})]})}function V({label:e,description:t,children:n}){return(0,k.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,k.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,k.jsx)(`span`,{className:`flex-1 font-serif text-sm text-foreground`,children:e}),n]}),t?(0,k.jsx)(`p`,{className:`font-serif text-xs italic text-muted-foreground/70`,children:t}):null]})}function Vn({children:e}){return(0,k.jsx)(`h4`,{className:`mb-4 font-serif text-base lowercase tracking-tight text-foreground`,children:e})}function Hn({values:e,models:t,disabled:n,onChange:r,onClear:i}){let a=e?.[`memory.lcm.enabled`].value,o=e?.[`memory.lcm.model`].value,s=e?.[`memory.lcm.model`].source,c=n||a!==!0,l=n||e?.[`memory.ambient.enabled`].value!==!0;return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsxs)(`section`,{children:[(0,k.jsx)(Vn,{children:`compaction`}),(0,k.jsx)(z,{enabled:a,disabled:n,ariaPrefix:`compaction`,onChange:e=>void r(`memory.lcm.enabled`,e)}),(0,k.jsxs)(`div`,{className:`mt-4`,children:[(0,k.jsx)(vn,{value:o??``,onValueChange:e=>void r(`memory.lcm.model`,e),disabled:c,className:`grid gap-1`,children:t.map(e=>{let t=`memory-model-${e}`,n=e===o,[r,...i]=e.split(`/`),a=i.join(`/`);return(0,k.jsxs)(bn,{htmlFor:t,className:`group/row flex cursor-pointer items-center gap-3 rounded-md px-3 py-2.5 transition-colors hover:bg-accent has-data-[state=checked]:bg-primary has-data-[state=checked]:text-primary-foreground has-data-[state=checked]:hover:bg-primary`,children:[(0,k.jsx)(yn,{value:e,id:t}),(0,k.jsxs)(`span`,{className:`min-w-0 flex-1 font-mono text-sm leading-tight`,children:[(0,k.jsx)(`span`,{className:n?`text-primary-foreground/70`:`text-muted-foreground group-hover/row:text-foreground`,children:r}),(0,k.jsx)(`span`,{className:n?`text-primary-foreground/70`:`text-muted-foreground group-hover/row:text-foreground`,children:`/`}),(0,k.jsx)(`span`,{className:n?`text-primary-foreground`:`text-muted-foreground group-hover/row:text-foreground`,children:a})]})]},e)})}),s===`override`?(0,k.jsx)(`button`,{type:`button`,onClick:()=>void i(`memory.lcm.model`),disabled:c,className:`mt-2 font-serif text-xs italic text-muted-foreground/70 transition-colors hover:text-foreground disabled:opacity-50`,children:`set just for compaction · use default instead`}):o?(0,k.jsx)(`p`,{className:`mt-2 font-serif text-xs italic text-muted-foreground/70`,children:`following your conversation model`}):null]}),(0,k.jsxs)(`div`,{className:`mt-4 grid gap-4`,children:[(0,k.jsx)(V,{label:`context threshold`,description:`fraction of context that triggers compaction`,children:(0,k.jsx)(B,{value:e?.[`memory.lcm.contextThreshold`].value,step:.05,min:0,max:1,disabled:c,onCommit:e=>r(`memory.lcm.contextThreshold`,e)})}),(0,k.jsx)(V,{label:`fresh tail count`,description:`most recent messages kept raw, never compacted`,children:(0,k.jsx)(B,{value:e?.[`memory.lcm.freshTailCount`].value,min:1,disabled:c,onCommit:e=>r(`memory.lcm.freshTailCount`,e)})}),(0,k.jsx)(V,{label:`leaf chunk tokens`,description:`max tokens of input per leaf summary`,children:(0,k.jsx)(B,{value:e?.[`memory.lcm.leafChunkTokens`].value,min:1,disabled:c,onCommit:e=>r(`memory.lcm.leafChunkTokens`,e)})}),(0,k.jsx)(V,{label:`leaf target tokens`,description:`target tokens per leaf summary output`,children:(0,k.jsx)(B,{value:e?.[`memory.lcm.leafTargetTokens`].value,min:1,disabled:c,onCommit:e=>r(`memory.lcm.leafTargetTokens`,e)})}),(0,k.jsx)(V,{label:`condense group size`,description:`how many summaries combine into one at the next level`,children:(0,k.jsx)(B,{value:e?.[`memory.lcm.condenseGroupSize`].value,min:1,disabled:c,onCommit:e=>r(`memory.lcm.condenseGroupSize`,e)})}),(0,k.jsx)(V,{label:`max summary depth`,description:`deepest level of recursive summary-of-summaries`,children:(0,k.jsx)(B,{value:e?.[`memory.lcm.maxSummaryDepth`].value,min:1,disabled:c,onCommit:e=>r(`memory.lcm.maxSummaryDepth`,e)})}),(0,k.jsx)(V,{label:`kept after /new`,description:`lowest summary depth kept after /new. -1 keeps full context, 0 keeps every summary.`,children:(0,k.jsx)(B,{value:e?.[`memory.lcm.newSessionRetainDepth`].value,min:-1,disabled:c,onCommit:e=>r(`memory.lcm.newSessionRetainDepth`,e)})})]})]}),(0,k.jsxs)(`section`,{className:`mt-8`,children:[(0,k.jsx)(Vn,{children:`ambient`}),(0,k.jsx)(z,{enabled:e?.[`memory.ambient.enabled`].value,disabled:n,ariaPrefix:`ambient`,onChange:e=>void r(`memory.ambient.enabled`,e)}),(0,k.jsxs)(`div`,{className:`mt-4 grid gap-4`,children:[(0,k.jsx)(V,{label:`top k`,description:`how many memories to surface per query`,children:(0,k.jsx)(B,{value:e?.[`memory.ambient.topK`].value,min:1,disabled:l,onCommit:e=>r(`memory.ambient.topK`,e)})}),(0,k.jsx)(V,{label:`min query length`,description:`minimum query chars before recall fires`,children:(0,k.jsx)(B,{value:e?.[`memory.ambient.minQueryLength`].value,min:0,disabled:l,onCommit:e=>r(`memory.ambient.minQueryLength`,e)})}),(0,k.jsx)(V,{label:`throttle seconds`,description:`cooldown between recalls`,children:(0,k.jsx)(B,{value:e?.[`memory.ambient.throttleSeconds`].value,min:0,disabled:l,onCommit:e=>r(`memory.ambient.throttleSeconds`,e)})}),(0,k.jsx)(V,{label:`similarity weight`,description:`semantic match to your query`,children:(0,k.jsx)(B,{value:e?.[`memory.ambient.weightSimilarity`].value,step:.05,min:0,disabled:l,onCommit:e=>r(`memory.ambient.weightSimilarity`,e)})}),(0,k.jsx)(V,{label:`valence weight`,description:`emotional charge of the memory`,children:(0,k.jsx)(B,{value:e?.[`memory.ambient.weightValence`].value,step:.05,min:0,disabled:l,onCommit:e=>r(`memory.ambient.weightValence`,e)})}),(0,k.jsx)(V,{label:`recency weight`,description:`favors recent memories`,children:(0,k.jsx)(B,{value:e?.[`memory.ambient.weightRecency`].value,step:.05,min:0,disabled:l,onCommit:e=>r(`memory.ambient.weightRecency`,e)})}),(0,k.jsx)(V,{label:`intensity weight`,description:`favors strongly-felt memories`,children:(0,k.jsx)(B,{value:e?.[`memory.ambient.weightIntensity`].value,step:.05,min:0,disabled:l,onCommit:e=>r(`memory.ambient.weightIntensity`,e)})})]})]}),(0,k.jsx)(`p`,{className:`mt-8 font-serif text-xs italic text-muted-foreground/60`,children:`embedding model lives in config.toml. swapping it invalidates existing memory.`})]})}function Un(e){let t=new Date(e);return Number.isNaN(t.getTime())?e:new Intl.DateTimeFormat(void 0,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`}).format(t).toLowerCase()}function Wn(e){if(!e)return`browser unknown`;let t=e.includes(`Firefox/`)?`firefox`:e.includes(`Edg/`)?`edge`:e.includes(`Chrome/`)?`chrome`:e.includes(`Safari/`)?`safari`:`browser`,n=e.includes(`iPhone`)||e.includes(`iPad`)?`ios`:e.includes(`Mac OS X`)?`mac`:e.includes(`Windows`)?`windows`:e.includes(`Linux`)?`linux`:void 0;return n?`${t} on ${n}`:t}function Gn(e){let t=new Date(e.lastSeenAt);return Number.isNaN(t.getTime())?0:t.getTime()}function Kn({currentDevice:e,onSignedOut:t}){let[n,r]=(0,D.useState)(e?[e]:[]),[i,a]=(0,D.useState)(!0),[o,s]=(0,D.useState)(),[c,l]=(0,D.useState)(),u=(0,D.useCallback)((e={})=>{e.showLoading&&(a(!0),l(void 0)),vt().then(e=>{r(e),l(void 0)}).catch(e=>{l(e instanceof Error?e.message:String(e))}).finally(()=>{a(!1)})},[]);(0,D.useEffect)(()=>{let e=window.setTimeout(()=>u(),0);return()=>window.clearTimeout(e)},[u]);let d=(0,D.useMemo)(()=>[...n].sort((e,t)=>e.current&&!t.current?-1:!e.current&&t.current?1:Gn(t)-Gn(e)),[n]),f=d.filter(e=>!e.current),p=async e=>{s(e.id),l(void 0);try{await yt(e.id),r(t=>t.filter(t=>t.id!==e.id))}catch(e){l(e instanceof Error?e.message:String(e))}finally{s(void 0)}},m=async()=>{s(`current`),l(void 0);try{await xt(),t()}catch(e){l(e instanceof Error?e.message:String(e))}finally{s(void 0)}},h=async()=>{s(`others`),l(void 0);try{await bt(),r(e=>e.filter(e=>e.current))}catch(e){l(e instanceof Error?e.message:String(e)),u({showLoading:!0})}finally{s(void 0)}};return(0,k.jsxs)(`div`,{className:`grid gap-3`,children:[(0,k.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,k.jsxs)(A,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>void m(),disabled:!!o,className:`gap-2`,children:[(0,k.jsx)(Ue,{className:`size-3.5`}),`logout`]}),(0,k.jsx)(A,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void h(),disabled:!!o||f.length===0,children:`sign out others`})]}),(0,k.jsxs)(`div`,{className:`grid gap-2`,children:[d.map(e=>(0,k.jsx)(`div`,{className:O(`rounded-md border border-border bg-background px-3 py-2.5`,e.current&&`border-primary/50`),children:(0,k.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,k.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,k.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,k.jsx)(`p`,{className:`truncate text-sm leading-tight text-foreground`,children:e.deviceName||`unnamed device`}),e.current?(0,k.jsx)(`span`,{className:`font-serif text-xs italic text-primary`,children:`current`}):null]}),(0,k.jsxs)(`p`,{className:`mt-1 font-serif text-xs italic text-muted-foreground`,children:[`last seen `,Un(e.lastSeenAt)]}),(0,k.jsxs)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:[`made `,Un(e.createdAt),` · expires `,Un(e.expiresAt)]}),(0,k.jsxs)(`p`,{className:`mt-1 truncate text-xs text-muted-foreground/80`,children:[e.lastIp??`ip unknown`,` · `,Wn(e.userAgent)]})]}),e.current?null:(0,k.jsx)(`button`,{type:`button`,"aria-label":`revoke ${e.deviceName||`device`}`,title:`revoke`,disabled:!!o,onClick:()=>void p(e),className:`flex size-8 shrink-0 items-center justify-center rounded-md text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-none disabled:opacity-50`,children:(0,k.jsx)(y,{className:`size-4`})})]})},e.id)),i?(0,k.jsx)(`p`,{className:`font-serif text-xs italic text-muted-foreground`,children:`checking devices…`}):null,!i&&d.length===0?(0,k.jsx)(`p`,{className:`font-serif text-xs italic text-muted-foreground`,children:`no devices found.`}):null]}),c?(0,k.jsx)(`p`,{className:`font-serif text-xs italic text-destructive`,children:c}):null]})}function qn(){let e=(0,D.useRef)(!0);return(0,D.useEffect)(()=>(e.current=!0,()=>{e.current=!1}),[]),e}function Jn(){let e=qn(),[t,n]=(0,D.useState)(void 0),[r,i]=(0,D.useState)(!1),[a,o]=(0,D.useState)(!1);return{error:t,isLoading:r,isMutating:a,run:(0,D.useCallback)(async(t,r={})=>{let a=r.busy===`load`?i:o;a(!0),n(void 0);try{let n=await t();return e.current?(r.apply?.(n),n):void 0}catch(t){if(e.current&&(r.onError?.(),n(t instanceof Error?t.message:String(t))),r.rethrow)throw t;return}finally{e.current&&a(!1)}},[e])}}function Yn(e){let[t,n]=(0,D.useState)(void 0),[r,i]=(0,D.useState)([]),[a,o]=(0,D.useState)([]),{error:s,isLoading:c,isMutating:l,run:u}=Jn(),d=(0,D.useCallback)(async()=>{e&&await u(()=>Promise.all([Ot(e),kt()]),{busy:`load`,apply:([e,t])=>{n(e),i(t.models),o(t.added)}})},[e,u]);(0,D.useEffect)(()=>{let e=window.setTimeout(()=>void d(),0);return()=>window.clearTimeout(e)},[d]);let f=(0,D.useCallback)(async r=>{if(!e)return;let i=t;i&&n({...i,model:r.model?{value:r.model,source:`override`}:i.model,thinking:r.thinking?{value:r.thinking,source:`override`}:i.thinking}),await u(()=>Mt(e,r),{apply:n,onError:()=>{i&&n(i)}})},[e,t,u]);return{data:t,models:r,addedModels:a,error:s,isLoading:c,isMutating:l,setModel:(0,D.useCallback)(e=>f({model:e}),[f]),setThinking:(0,D.useCallback)(e=>f({thinking:e}),[f]),addModel:(0,D.useCallback)(async e=>{await u(()=>At(e),{apply:e=>{i(e.models),o(e.added)},rethrow:!0})},[u]),removeModel:(0,D.useCallback)(async e=>{await u(()=>jt(e),{apply:e=>{i(e.models),o(e.added)},rethrow:!0})},[u]),refetch:d}}function Xn(e){let[t,n]=(0,D.useState)(void 0),{error:r,isLoading:i,isMutating:a,run:o}=Jn(),s=(0,D.useCallback)(async()=>{e&&await o(()=>Ft(),{busy:`load`,apply:n})},[e,o]);return(0,D.useEffect)(()=>{let e=window.setTimeout(()=>void s(),0);return()=>window.clearTimeout(e)},[s]),{data:t,error:r,isLoading:i,isMutating:a,setConfig:(0,D.useCallback)(async(e,t)=>{await o(()=>It(e,t),{apply:n,rethrow:!0})},[o]),clearConfig:(0,D.useCallback)(async e=>{await o(()=>Lt(e),{apply:n,rethrow:!0})},[o]),refetch:s}}function H({title:e,description:t,icon:n,defaultOpen:r=!1,children:i}){let[a,o]=(0,D.useState)(r);return(0,k.jsxs)(ln,{open:a,onOpenChange:o,children:[(0,k.jsxs)(un,{className:`group flex w-full items-start gap-4 rounded-md px-2 py-3 text-left transition-colors hover:bg-accent/50 focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-none`,children:[(0,k.jsx)(n,{className:`mt-0.5 size-5 shrink-0 text-muted-foreground transition-colors group-hover:text-foreground`}),(0,k.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,k.jsx)(`span`,{className:`block font-serif text-base leading-tight tracking-tight text-foreground`,children:e}),(0,k.jsx)(`span`,{className:`mt-1 block text-xs leading-relaxed text-muted-foreground`,children:t})]}),(0,k.jsx)(nt,{className:O(`size-4 shrink-0 text-muted-foreground transition-transform duration-150 group-hover:text-foreground`,a&&`rotate-90`)})]}),(0,k.jsx)(dn,{children:(0,k.jsx)(`div`,{className:`px-2 pb-5`,children:(0,k.jsx)(`div`,{className:`mt-4`,children:i})})})]})}function U({children:e,className:t}){return(0,k.jsx)(`p`,{className:O(`px-2 pt-4 pb-1 font-serif text-xs italic text-muted-foreground`,t),children:e})}function Zn({open:e,onOpenChange:t,channelKey:n,authMode:r,authDevice:i,onSignedOut:a}){let{data:o,models:s,addedModels:c,error:l,isLoading:u,isMutating:d,setModel:f,setThinking:p,addModel:m,removeModel:h}=Yn(n),{data:g,error:_,isLoading:v,isMutating:y,setConfig:b,clearConfig:x}=Xn(e),S=!!o&&!!g,C=u||d||v||y,w=l??_;return(0,k.jsx)(fn,{open:e,onOpenChange:t,children:(0,k.jsxs)(hn,{className:`w-screen bg-card shadow-2xl sm:w-md sm:max-w-md sm:rounded-l-2xl`,side:`right`,children:[(0,k.jsx)(gn,{className:`px-6 pt-6 pb-2`,children:(0,k.jsx)(_n,{className:`font-serif text-2xl leading-none tracking-tight text-foreground`,children:`settings`})}),(0,k.jsxs)(`div`,{className:`flex flex-col overflow-y-auto px-5 pt-1 pb-8`,children:[(0,k.jsx)(U,{className:`pt-1`,children:`conversation`}),(0,k.jsx)(H,{title:`model`,description:`which language model carries this conversation.`,icon:Ne,defaultOpen:!0,children:(0,k.jsx)(xn,{models:s,added:c,current:o?.model.value,source:o?.model.source,disabled:!S||C,onChange:e=>void f(e),onAdd:m,onRemove:h})}),(0,k.jsx)(H,{title:`thinking`,description:`how long the model deliberates before answering.`,icon:ee,children:(0,k.jsx)(Tn,{current:o?.thinking.value,supported:o?.supportedThinking??[],disabled:!S||C,onChange:e=>void p(e)})}),(0,k.jsx)(U,{children:`companion`}),(0,k.jsx)(H,{title:`heartbeat`,description:`your companion's pulse when you've gone quiet.`,icon:pe,children:(0,k.jsx)(zn,{values:g?.values,disabled:!S||C,onChange:b})}),(0,k.jsx)(H,{title:`image generation`,description:`which model your companion uses to paint.`,icon:Ee,children:(0,k.jsx)(Bn,{values:g?.values,disabled:!S||C,onChange:b})}),(0,k.jsx)(H,{title:`memory`,description:`how older conversation is condensed and how earlier memories return.`,icon:it,children:(0,k.jsx)(Hn,{values:g?.values,models:s,disabled:!S||C,onChange:b,onClear:x})}),(0,k.jsx)(U,{children:`room`}),(0,k.jsx)(H,{title:`theme`,description:`light, dark, or follow your system.`,icon:ye,children:(0,k.jsx)(Nn,{})}),r===`bearer`&&a?(0,k.jsx)(H,{title:`devices`,description:`where this web room is still open.`,icon:xe,children:(0,k.jsx)(Kn,{currentDevice:i,onSignedOut:a})}):null,w?(0,k.jsx)(`p`,{className:`mt-4 font-serif text-xs italic text-destructive`,children:w}):null]})]})})}function Qn({...e}){return(0,k.jsx)(C,{"data-slot":`alert-dialog`,...e})}function $n({...e}){return(0,k.jsx)(u,{"data-slot":`alert-dialog-portal`,...e})}function er({className:e,...t}){return(0,k.jsx)(f,{"data-slot":`alert-dialog-overlay`,className:O(`fixed inset-0 z-50 bg-foreground/15 duration-100 data-open:animate-in data-open:fade-in-0 data-closed:animate-out data-closed:fade-out-0`,e),...t})}function tr({className:e,size:t=`default`,...n}){return(0,k.jsxs)($n,{children:[(0,k.jsx)(er,{}),(0,k.jsx)(tt,{"data-slot":`alert-dialog-content`,"data-size":t,className:O(`group/alert-dialog-content fixed top-1/2 left-1/2 z-50 grid w-full -translate-x-1/2 -translate-y-1/2 gap-4 rounded-xl bg-popover p-4 text-popover-foreground ring-1 ring-foreground/10 duration-100 outline-none data-[size=default]:max-w-xs data-[size=sm]:max-w-xs data-[size=default]:sm:max-w-sm data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95`,e),...n})]})}function nr({className:e,...t}){return(0,k.jsx)(`div`,{"data-slot":`alert-dialog-header`,className:O(`grid grid-rows-[auto_1fr] place-items-center gap-1.5 text-center has-data-[slot=alert-dialog-media]:grid-rows-[auto_auto_1fr] has-data-[slot=alert-dialog-media]:gap-x-4 sm:group-data-[size=default]/alert-dialog-content:place-items-start sm:group-data-[size=default]/alert-dialog-content:text-left sm:group-data-[size=default]/alert-dialog-content:has-data-[slot=alert-dialog-media]:grid-rows-[auto_1fr]`,e),...t})}function rr({className:e,...t}){return(0,k.jsx)(`div`,{"data-slot":`alert-dialog-footer`,className:O(`-mx-4 -mb-4 flex flex-col-reverse gap-2 rounded-b-xl border-t bg-muted/50 p-4 group-data-[size=sm]/alert-dialog-content:grid group-data-[size=sm]/alert-dialog-content:grid-cols-2 sm:flex-row sm:justify-end`,e),...t})}function ir({className:e,...t}){return(0,k.jsx)(Me,{"data-slot":`alert-dialog-title`,className:O(`font-heading text-base font-medium sm:group-data-[size=default]/alert-dialog-content:group-has-data-[slot=alert-dialog-media]/alert-dialog-content:col-start-2`,e),...t})}function ar({className:e,...t}){return(0,k.jsx)(ae,{"data-slot":`alert-dialog-description`,className:O(`text-sm text-balance text-muted-foreground md:text-pretty *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground`,e),...t})}function or({className:e,variant:t=`default`,size:n=`default`,...r}){return(0,k.jsx)(A,{variant:t,size:n,asChild:!0,children:(0,k.jsx)(re,{"data-slot":`alert-dialog-action`,className:O(e),...r})})}function sr({className:e,variant:t=`outline`,size:n=`default`,...r}){return(0,k.jsx)(A,{variant:t,size:n,asChild:!0,children:(0,k.jsx)(c,{"data-slot":`alert-dialog-cancel`,className:O(e),...r})})}function cr({channelKey:e,onStarted:t}){let[n,r]=(0,D.useState)(!1),[i,a]=(0,D.useState)(!1),[o,s]=(0,D.useState)(void 0),c=async()=>{if(e){a(!0),s(void 0);try{await Nt(e),r(!1),t()}catch(e){s(e instanceof Error?e.message:String(e))}finally{a(!1)}}};return(0,k.jsxs)(Qn,{open:n,onOpenChange:e=>{i||r(e)},children:[(0,k.jsx)(A,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`new chat`,title:`new chat`,className:`size-8 text-muted-foreground hover:text-foreground`,onClick:()=>r(!0),children:(0,k.jsx)(le,{className:`size-4`})}),(0,k.jsxs)(tr,{className:`bg-card`,children:[(0,k.jsxs)(nr,{children:[(0,k.jsx)(ir,{className:`font-serif text-xl tracking-tight`,children:`start fresh?`}),(0,k.jsx)(ar,{className:`font-sans text-sm`,children:`this clears the agent's context. you'll still see the conversation above, but they won't.`})]}),o?(0,k.jsx)(`p`,{className:`font-serif text-xs italic text-destructive`,children:o}):null,(0,k.jsxs)(rr,{children:[(0,k.jsx)(sr,{disabled:i,children:`cancel`}),(0,k.jsx)(or,{onClick:e=>{e.preventDefault(),c()},disabled:i||!e,children:i?`starting…`:`start fresh`})]})]})]})}function lr({...e}){return(0,k.jsx)(ge,{"data-slot":`dropdown-menu`,...e})}function ur({...e}){return(0,k.jsx)(rt,{"data-slot":`dropdown-menu-trigger`,...e})}function dr({className:e,align:t=`start`,sideOffset:n=4,...r}){return(0,k.jsx)(at,{children:(0,k.jsx)(fe,{"data-slot":`dropdown-menu-content`,sideOffset:n,align:t,className:O(`z-50 max-h-(--radix-dropdown-menu-content-available-height) w-(--radix-dropdown-menu-trigger-width) min-w-32 origin-(--radix-dropdown-menu-content-transform-origin) overflow-x-hidden overflow-y-auto rounded-lg bg-popover p-1 text-popover-foreground shadow-md ring-1 ring-foreground/10 duration-100 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:overflow-hidden data-open:animate-in data-open:fade-in-0 data-open:zoom-in-95 data-closed:animate-out data-closed:fade-out-0 data-closed:zoom-out-95`,e),...r})})}function fr({className:e,inset:t,variant:n=`default`,...r}){return(0,k.jsx)($e,{"data-slot":`dropdown-menu-item`,"data-inset":t,"data-variant":n,className:O(`group/dropdown-menu-item relative flex cursor-default items-center gap-1.5 rounded-md px-1.5 py-1 text-sm outline-hidden select-none focus:bg-accent focus:text-accent-foreground not-data-[variant=destructive]:focus:**:text-accent-foreground data-inset:pl-7 data-[variant=destructive]:text-destructive data-[variant=destructive]:focus:bg-destructive/10 data-[variant=destructive]:focus:text-destructive dark:data-[variant=destructive]:focus:bg-destructive/20 data-disabled:pointer-events-none data-disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 data-[variant=destructive]:*:[svg]:text-destructive`,e),...r})}function pr(e){return e.label?e.label:e.scope===`dm`?`Main Chat`:e.channelName??e.channelId}function mr({sessions:e,activeKey:t,onSelect:n}){if(e.length<=1)return null;let r=e.find(e=>e.key===t);return(0,k.jsxs)(lr,{children:[(0,k.jsxs)(ur,{className:`inline-flex items-center gap-1 rounded-md px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-foreground focus:outline-none focus:ring-2 focus:ring-ring/30`,children:[(0,k.jsx)(`span`,{className:`font-medium`,children:r?pr(r):`select session`}),(0,k.jsx)(p,{className:`size-3 opacity-70`})]}),(0,k.jsx)(dr,{align:`end`,className:`min-w-[180px]`,onCloseAutoFocus:e=>e.preventDefault(),children:e.map(e=>{let r=e.key===t;return(0,k.jsxs)(fr,{onSelect:()=>n(e.key),className:`flex items-center justify-between gap-3`,children:[(0,k.jsx)(`span`,{className:O(`truncate`,r&&`font-medium`),children:pr(e)}),r&&(0,k.jsx)(d,{className:`size-3.5 text-muted-foreground`})]},e.key)})})]})}var hr={connecting:`connecting`,open:`online`,closed:`offline`,error:`error`},gr={connecting:`reaching out…`,closed:`out of touch · trying again`,error:`out of touch · trying again`};function _r({nav:e,connection:t,personaName:n,sessions:r,activeSessionKey:a,channelKey:o,onSelectSession:s,onOpenConfig:c,onNewChatStarted:l}){let u=t===`open`;return(0,k.jsx)(`header`,{className:`sticky top-0 z-10 border-b border-border bg-background px-3 py-3 md:px-5`,children:(0,k.jsxs)(`div`,{className:`mx-auto flex max-w-3xl items-center gap-3`,children:[e,(0,k.jsx)(`span`,{"aria-label":hr[t],title:hr[t],className:O(`size-2 rounded-full ring-3 ring-accent/60`,u?`bg-primary`:`bg-muted-foreground/40 ring-transparent`)}),(0,k.jsx)(`span`,{className:`font-serif text-lg leading-none tracking-tight`,children:n}),!u&&(0,k.jsx)(`span`,{className:`font-serif text-xs italic leading-none text-muted-foreground/80`,children:gr[t]}),(0,k.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,k.jsx)(mr,{sessions:r,activeKey:a,onSelect:s}),(0,k.jsx)(cr,{channelKey:o,onStarted:l}),(0,k.jsx)(A,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`settings`,title:`settings`,className:`size-8 text-muted-foreground hover:text-foreground`,onClick:c,children:(0,k.jsx)(i,{className:`size-4`})})]})]})})}function vr({src:e,alt:t,className:n}){return(0,k.jsxs)(w,{children:[(0,k.jsx)(_,{asChild:!0,children:(0,k.jsx)(`button`,{type:`button`,className:O(`inline-block rounded-md text-left outline-none transition-opacity hover:opacity-90 focus-visible:ring-3 focus-visible:ring-ring/40`,n),children:(0,k.jsx)(`img`,{src:e,alt:t,loading:`lazy`,className:`max-h-72 max-w-[24rem] rounded-md`})})}),(0,k.jsxs)(S,{children:[(0,k.jsx)(x,{className:`fixed inset-0 z-50 bg-background/90 data-closed:animate-out data-closed:fade-out-0 data-open:animate-in data-open:fade-in-0`}),(0,k.jsxs)(je,{className:`fixed inset-0 z-50 flex items-center justify-center p-3 outline-none sm:p-6`,onCloseAutoFocus:e=>e.preventDefault(),children:[(0,k.jsx)(m,{className:`sr-only`,children:t}),(0,k.jsx)(`img`,{src:e,alt:t,className:`max-h-[calc(100dvh-1.5rem)] max-w-[calc(100vw-1.5rem)] rounded-md object-contain shadow-lg sm:max-h-[calc(100dvh-3rem)] sm:max-w-[calc(100vw-3rem)]`}),(0,k.jsxs)(`div`,{className:`fixed top-3 right-3 flex gap-1 sm:top-4 sm:right-4`,children:[(0,k.jsx)(A,{asChild:!0,type:`button`,variant:`ghost`,size:`icon-sm`,title:`open original`,"aria-label":`open original`,children:(0,k.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:(0,k.jsx)(_e,{className:`size-4`})})}),(0,k.jsx)(a,{asChild:!0,children:(0,k.jsx)(A,{type:`button`,variant:`ghost`,size:`icon-sm`,title:`close preview`,"aria-label":`close preview`,children:(0,k.jsx)(T,{className:`size-4`})})})]})]})]})]})}function yr(e){return e.some(e=>e.type!==`text`||e.value.trim().length>0)}function W(e){return{type:`paragraph`,children:e}}function br(e){if(!e.children.some(e=>e.type===`image`))return[e];let t=[],n=[];for(let r of e.children){if(r.type!==`image`){n.push(r);continue}yr(n)&&t.push(W(n)),n=[],t.push(W([r]))}return yr(n)&&t.push(W(n)),t.length>0?t:[e]}function xr(){return e=>{for(let t=0;t<e.children.length;t+=1){let n=e.children[t];if(n?.type!==`paragraph`)continue;let r=br(n);r.length===1&&r[0]===n||(e.children.splice(t,1,...r),t+=r.length-1)}}}function Sr(e){return{type:`text`,value:e}}function G(e,t=``){return{type:`image`,url:e,alt:t}}function K(e,t){let n=t.replace(/[ \t]+$/,``).replace(/\n{2,}$/,`
|
|
4
|
+
`);n.trim()&&e.push(Sr(n))}function Cr(e){let t=[],n=0;for(let r of Wt(e))r.index>n&&K(t,e.slice(n,r.index)),t.push(G(r.url,r.type===`meme`?r.name:``)),n=r.index+r.whole.length;if(t.length!==0)return n<e.length&&K(t,e.slice(n).replace(/^\n+/,``)),t}function wr(e){let t=e.children[0];return e.title==null&&e.children.length===1&&t?.type===`text`&&t.value===e.url&&Rt.test(e.url)}function Tr(e,t,n){e.children.splice(t,1,...n)}function Er(e){let{children:t}=e;for(let e=1;e<t.length-1;e+=1){let n=t[e-1],r=t[e],i=t[e+1];if(n?.type!==`text`||r?.type!==`link`||i?.type!==`text`||!i.value.startsWith(`)`)||!wr(r))continue;let a=Ht(n.value);if(!a)continue;let o=[];K(o,a.before),o.push(G(r.url,a.name)),K(o,i.value.slice(1).replace(/^\n+/,``)),t.splice(e-1,3,...o),e+=Math.max(0,o.length-2)}}function Dr(){return e=>{ct(e,`paragraph`,e=>{Er(e)}),ct(e,`link`,(e,t,n)=>(t===void 0||!n||wr(e)&&Tr(n,t,[G(e.url)]),E)),ct(e,`text`,(e,t,n)=>{if(t===void 0||!n||n.type===`link`)return E;let r=Cr(e.value);if(r)return Tr(n,t,r),[E,t+r.length]})}}function Or(e){let t=0;for(let n=0;n<e.length;n+=1){let{width:r}=e[n];r>t&&(t=r)}return Math.ceil(t)}function kr(e){let t=e.querySelectorAll(`:scope > p`);for(let e of t){if(e.style.width=``,!e.textContent?.trim())continue;let t=document.createRange();t.selectNodeContents(e);let n=Or(t.getClientRects());n>0&&(e.style.width=`${n}px`)}}var Ar=[ut,Dr,xr];function jr(e,t,n){(0,D.useLayoutEffect)(()=>{let n=e.current;if(!t||!n)return;let r=()=>kr(n);return r(),window.addEventListener(`resize`,r),document.fonts?.ready.then(r),()=>window.removeEventListener(`resize`,r)},[e,t,n])}function Mr(e){return{a(e){let{node:t,href:n,children:r,...i}=e,a=n?!n.startsWith(`#`):!1;return(0,k.jsx)(`a`,{...i,href:n,target:a?`_blank`:void 0,rel:a?`noopener noreferrer`:void 0,children:r})},img(t){let{node:n,src:r,alt:i}=t;return typeof r!=`string`||!r?null:(0,k.jsx)(vr,{src:r,alt:i??`image`,className:O(`my-1 block w-fit`,e===`end`&&`ml-auto`)})},table(e){let{node:t,...n}=e;return(0,k.jsx)(`div`,{className:`chat-markdown-table`,children:(0,k.jsx)(`table`,{...n})})}}}function Nr({text:e,streaming:t,align:n=`start`}){let r=(0,D.useMemo)(()=>Mr(n),[n]),i=(0,D.useRef)(null);return jr(i,n===`end`,e),(0,k.jsx)(`div`,{ref:i,className:O(`warm-prose chat-markdown`,n===`end`&&`chat-markdown-end`,t&&`chat-markdown-streaming`),children:(0,k.jsx)(lt,{remarkPlugins:Ar,components:r,children:e})})}var Pr=(0,k.jsx)(`span`,{className:`ml-0.5 inline-block animate-pulse`,children:`▎`});function Fr(e,t={}){let{trailingCursor:n,align:r=`start`}=t;if(!e.trim())return n?(0,k.jsx)(`div`,{className:`warm-prose chat-markdown`,children:Pr}):null;let i=(0,k.jsx)(Nr,{text:e,streaming:n===!0,align:r});return r===`end`?(0,k.jsx)(`div`,{className:`flex min-w-0 flex-col items-end`,children:i}):i}function Ir(e){if(!Number.isFinite(e)||e<0)return`0:00`;let t=Math.floor(e);return`${Math.floor(t/60)}:${(t%60).toString().padStart(2,`0`)}`}function Lr({src:e,name:t,className:n}){let r=(0,D.useRef)(null),[i,a]=(0,D.useState)(!1),[o,s]=(0,D.useState)(0),[c,l]=(0,D.useState)(0);(0,D.useEffect)(()=>{let e=r.current;if(!e)return;let t=()=>s(e.currentTime),n=()=>l(Number.isFinite(e.duration)?e.duration:0),i=()=>a(!0),o=()=>a(!1),c=()=>a(!1);return e.addEventListener(`timeupdate`,t),e.addEventListener(`loadedmetadata`,n),e.addEventListener(`durationchange`,n),e.addEventListener(`play`,i),e.addEventListener(`pause`,o),e.addEventListener(`ended`,c),()=>{e.removeEventListener(`timeupdate`,t),e.removeEventListener(`loadedmetadata`,n),e.removeEventListener(`durationchange`,n),e.removeEventListener(`play`,i),e.removeEventListener(`pause`,o),e.removeEventListener(`ended`,c)}},[]);let u=()=>{let e=r.current;e&&(i?e.pause():e.play())},d=e=>{let t=r.current;if(!t)return;let n=Math.max(0,Math.min(c||0,e));t.currentTime=n,s(n)},f=c>0?o/c*100:0;return(0,k.jsxs)(`div`,{className:O(`flex w-full max-w-sm items-center gap-3 rounded-md bg-card px-3 py-2`,n),children:[(0,k.jsx)(`audio`,{ref:r,src:e,preload:`metadata`,children:(0,k.jsx)(`a`,{href:e,children:t??`audio`})}),(0,k.jsx)(`button`,{type:`button`,onClick:u,"aria-label":i?`pause`:`play`,className:`grid size-8 shrink-0 place-items-center rounded-md text-foreground hover:bg-accent focus-visible:outline-none focus-visible:ring-3 focus-visible:ring-ring/40`,children:i?(0,k.jsx)(he,{className:`size-4 fill-current`,strokeWidth:0}):(0,k.jsx)(Ke,{className:`size-4 fill-current translate-x-px`,strokeWidth:0})}),(0,k.jsxs)(`span`,{className:`shrink-0 whitespace-nowrap font-serif text-xs italic text-muted-foreground tabular-nums`,children:[Ir(o),` / `,Ir(c)]}),(0,k.jsx)(`input`,{type:`range`,min:0,max:c||0,step:.1,value:o,onChange:e=>d(Number(e.target.value)),"aria-label":`seek`,className:O(`h-1 flex-1 cursor-pointer appearance-none rounded-full bg-border outline-none`,`[&::-webkit-slider-thumb]:size-3 [&::-webkit-slider-thumb]:appearance-none [&::-webkit-slider-thumb]:rounded-full [&::-webkit-slider-thumb]:bg-primary [&::-webkit-slider-thumb]:cursor-pointer`,`[&::-moz-range-thumb]:size-3 [&::-moz-range-thumb]:appearance-none [&::-moz-range-thumb]:rounded-full [&::-moz-range-thumb]:border-0 [&::-moz-range-thumb]:bg-primary [&::-moz-range-thumb]:cursor-pointer`,`focus-visible:ring-3 focus-visible:ring-ring/40`),style:{background:`linear-gradient(to right, var(--primary) 0%, var(--primary) ${f}%, var(--border) ${f}%, var(--border) 100%)`}})]})}function Rr(e){let t=[],n=[],r=()=>{n.length>0&&(t.push({kind:`stream`,steps:n}),n=[])};for(let i of e)i.kind===`text`?(r(),t.push({kind:`text`,step:i})):i.kind===`error`?(r(),t.push({kind:`error`,step:i})):n.push(i);return r(),t}var zr=[{match:e=>/^(web_)?search/.test(e)||/web/.test(e),icon:et},{match:e=>/^(read|cat|ls|view|list_files)/.test(e),icon:ot},{match:e=>/^(write|edit|patch|create_file)/.test(e),icon:Ae},{match:e=>/^(bash|shell|exec|terminal)/.test(e),icon:We},{match:e=>/^memory/.test(e),icon:o},{match:e=>/^(tts|speak|voice)/.test(e),icon:h},{match:e=>/^(image|meme|picture|photo)/.test(e),icon:Ee},{match:e=>/^skill/.test(e),icon:ie}];function Br(e){let t=e.toLowerCase();for(let e of zr)if(e.match(t))return e.icon;return ce}var Vr=l;function Hr(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function Ur(e){if(e==null)return``;if(typeof e==`string`)return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}var Wr=[`query`,`url`,`command`,`prompt`,`file_path`,`path`,`pattern`,`description`];function Gr(e){if(!Hr(e))return``;for(let t of Wr){let n=e[t];if(typeof n==`string`&&n.trim())return n.trim()}return``}function Kr(e){if(e==null)return``;if(Array.isArray(e))return e.length===1?`1 item`:`${e.length} items`;if(Hr(e))for(let t of[`results`,`items`,`matches`,`files`,`lines`]){let n=e[t];if(Array.isArray(n)){let e=t===`files`?`file`:t===`lines`?`line`:t===`matches`?`match`:t===`items`?`item`:`result`;return n.length===1?`1 ${e}`:`${n.length} ${e}s`}}if(typeof e==`string`){let t=e.split(`
|
|
5
|
+
`).length;if(t>3)return`${t} lines`}return``}function qr(e){if(!e.complete)return`thinking…`;if(e.endedAt==null)return`thought`;let t=Math.max(0,e.endedAt-e.startedAt);return t<1e3?`thought for <1s`:`thought for ${Math.round(t/100)/10}s`}function q(e){return e.kind===`thinking`?!e.complete:e.tool.status===`running`||e.tool.status===`pending`}function Jr(e){if(e.kind===`thinking`)return!!e.text;let t=e.tool;return!!(t.args||t.result||t.partialResult||t.error)}function Yr(e){return e.kind===`tool`&&e.tool.status===`error`}function J({step:e,active:t,hideThreadAbove:n,hideThreadBelow:r}){let i=e===`done`?d:e.kind===`thinking`?Vr:Br(e.tool.name);return(0,k.jsxs)(`div`,{className:`relative flex h-7 w-7 shrink-0 items-center justify-center`,"aria-hidden":!0,children:[(0,k.jsx)(`span`,{className:O(`absolute left-1/2 w-px -translate-x-1/2 bg-border`,n?`top-1/2`:`top-0`,r?`bottom-1/2`:`bottom-0`)}),(0,k.jsx)(`span`,{className:`relative z-10 inline-flex size-4 items-center justify-center bg-muted`,children:(0,k.jsx)(i,{className:O(`size-4 transition-colors`,t?`text-primary`:`text-muted-foreground/85`)})})]})}function Xr({step:e}){if(e.kind===`thinking`)return(0,k.jsx)(`span`,{className:`truncate font-serif italic text-sm tracking-wide text-foreground/75`,children:qr(e)});let t=e.tool,n=Gr(t.args),r=t.status===`error`,i=t.status===`running`?t.partialResult:t.result,a=!r&&t.status===`completed`?Kr(i):``;return(0,k.jsxs)(`span`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,k.jsx)(`span`,{className:`shrink-0 font-mono text-sm text-foreground/85`,children:t.name}),n&&(0,k.jsx)(`span`,{className:`min-w-0 truncate font-mono text-sm text-muted-foreground/70`,children:n}),r&&(0,k.jsx)(`span`,{className:`shrink-0 font-serif italic text-sm text-destructive/80`,children:`· failed`}),a&&!r&&(0,k.jsxs)(`span`,{className:`shrink-0 font-serif italic text-sm tracking-wide text-muted-foreground/65`,children:[`· `,a]})]})}function Zr({step:e,active:t}){return(0,k.jsxs)(`div`,{className:`font-serif italic text-sm leading-relaxed text-muted-foreground/85 whitespace-pre-wrap`,children:[e.text,t&&(0,k.jsx)(`span`,{className:`ml-0.5 inline-block animate-pulse`,children:`▎`})]})}function Qr({tool:e}){let t=(0,D.useMemo)(()=>Ur(e.args),[e.args]),n=e.status===`running`?e.partialResult:e.result,r=(0,D.useMemo)(()=>Ur(n),[n]);return(0,k.jsxs)(`div`,{className:`space-y-2`,children:[t&&(0,k.jsx)(`pre`,{className:`overflow-x-auto whitespace-pre-wrap break-words font-mono text-xs text-muted-foreground/80`,children:t}),r&&(0,k.jsx)(`pre`,{className:`overflow-x-auto whitespace-pre-wrap break-words font-mono text-xs text-muted-foreground/80`,children:r}),e.error&&(0,k.jsx)(`div`,{className:`font-mono text-xs whitespace-pre-wrap text-destructive/85`,children:e.error})]})}var $r=132;function ei({children:e}){let[t,n]=(0,D.useState)(!1),r=(0,D.useRef)(null),[i,a]=(0,D.useState)(!1);(0,D.useEffect)(()=>{let e=r.current;if(!e)return;let t=()=>a(e.scrollHeight>$r+4);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let o=i&&!t;return(0,k.jsxs)(k.Fragment,{children:[(0,k.jsx)(`div`,{className:`relative overflow-hidden`,style:{maxHeight:o?`${$r}px`:`9999px`,WebkitMaskImage:o?`linear-gradient(to bottom, black calc(100% - 2.5rem), transparent)`:void 0,maskImage:o?`linear-gradient(to bottom, black calc(100% - 2.5rem), transparent)`:void 0},children:(0,k.jsx)(`div`,{ref:r,children:e})}),i&&(0,k.jsx)(`button`,{type:`button`,onClick:()=>n(e=>!e),className:`mt-1.5 font-serif italic text-xs tracking-wide text-foreground/75 underline-offset-4 transition-colors hover:text-foreground hover:underline`,children:t?`show less`:`show more`})]})}function ti({step:e,threadContinues:t}){let n=q(e);return(0,k.jsxs)(`div`,{className:`relative py-1`,children:[t&&(0,k.jsx)(`span`,{className:`absolute left-3.5 inset-y-0 w-px -translate-x-1/2 bg-border`,"aria-hidden":!0}),(0,k.jsx)(`div`,{className:`ml-9 mt-1 mb-2`,children:(0,k.jsx)(ei,{children:e.kind===`thinking`?(0,k.jsx)(Zr,{step:e,active:n}):(0,k.jsx)(Qr,{tool:e.tool})})})]})}function ni({steps:e,autoCollapse:t=!1}){let n=e.some(q),r=!n&&e.length>0&&e.length>=2&&!e.some(Yr),[i,a]=(0,D.useState)(n),o=(0,D.useRef)(!1);(0,D.useEffect)(()=>{o.current||(n?a(!0):t&&a(!1))},[n,t]);let s=()=>{o.current=!0,a(e=>!e)};if(e.length===0)return null;let c=e[0],l=Jr(c),u=e.length-1,d=i&&(l||u>0||r);return(0,k.jsxs)(`div`,{className:`flex flex-col rounded-lg bg-muted px-3 py-2`,children:[(0,k.jsxs)(`button`,{type:`button`,onClick:s,"aria-expanded":i,className:`flex w-full items-center gap-2 text-left`,children:[(0,k.jsx)(J,{step:c,active:q(c),hideThreadAbove:!0,hideThreadBelow:!d}),(0,k.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,k.jsx)(Xr,{step:c}),!i&&u>0&&(0,k.jsxs)(`span`,{className:`shrink-0 font-serif italic text-sm tracking-wide text-muted-foreground/60`,children:[`· `,u,` more`]}),(0,k.jsx)(nt,{className:O(`size-3.5 shrink-0 text-muted-foreground/65 transition-transform duration-300 ease-[cubic-bezier(0.16,1,0.3,1)]`,i&&`rotate-90`)})]})]}),i&&(0,k.jsxs)(`div`,{children:[l&&(0,k.jsx)(ti,{step:c,threadContinues:u>0||r}),e.slice(1).map((t,n)=>{let i=n+1===e.length-1,a=Jr(t),o=!i||r||a,s=!i||r;return(0,k.jsxs)(`div`,{className:`flex flex-col`,children:[(0,k.jsxs)(`div`,{className:`flex w-full items-center gap-2`,children:[(0,k.jsx)(J,{step:t,active:q(t),hideThreadBelow:!o}),(0,k.jsx)(Xr,{step:t})]}),a&&(0,k.jsx)(ti,{step:t,threadContinues:s})]},t.id)}),r&&(0,k.jsxs)(`div`,{className:`flex w-full items-center gap-2`,children:[(0,k.jsx)(J,{step:`done`,hideThreadBelow:!0}),(0,k.jsx)(`span`,{className:`font-mono text-sm text-foreground/85`,children:`done`})]})]})]})}function ri({text:e}){return(0,k.jsxs)(`div`,{className:`my-1 rounded-r-md border-l-2 border-destructive/50 bg-destructive/[0.06] py-2 pl-3 pr-3`,children:[(0,k.jsx)(`span`,{className:`font-serif italic text-sm tracking-wide text-destructive/85`,children:`lost somewhere between us`}),(0,k.jsx)(`div`,{className:`mt-1.5 h-px bg-destructive/15`}),(0,k.jsx)(`div`,{className:`mt-1.5 overflow-x-auto whitespace-pre-wrap break-words font-mono text-xs leading-relaxed text-destructive/90`,children:e})]})}var ii=`[[FAMILIAR_SILENT]]`;function ai({step:e,who:t,showLabel:n}){let r=!e.complete,i=e.text.startsWith(ii);return(0,k.jsxs)(`div`,{className:`flex w-full flex-col`,children:[n&&t&&(0,k.jsx)(`span`,{className:`mt-2 mb-1 block text-xs uppercase tracking-wider text-muted-foreground`,children:t}),i?(0,k.jsx)(`p`,{className:`font-serif italic text-sm leading-relaxed text-muted-foreground/70`,children:`they kept quiet.`}):Fr(e.text,{trailingCursor:r})]})}function oi(e){return e.kind===`thinking`||e.kind===`text`?e.complete===!0:e.kind===`error`?!0:e.tool.status===`completed`||e.tool.status===`error`}function si({message:e}){let{steps:t,silent:n,who:r}=e,i=Rr(t),a=i.findIndex(e=>e.kind===`text`)>=0,o=n===!0&&!a&&!!r,s=t.length>0&&t.every(oi)&&(n===!0||a);return(0,k.jsxs)(`div`,{className:`flex w-full flex-col gap-1`,children:[o&&(0,k.jsx)(`span`,{className:`mt-2 mb-1 block text-xs uppercase tracking-wider text-muted-foreground`,children:r}),i.map((e,t)=>{if(e.kind===`stream`)return(0,k.jsx)(ni,{steps:e.steps,autoCollapse:s},`stream-${t}`);if(e.kind===`error`)return(0,k.jsx)(ri,{text:e.step.text},e.step.id);let n=i[t-1],a=!n||n.kind!==`text`;return(0,k.jsx)(ai,{step:e.step,who:r,showLabel:a},e.step.id)}),n&&!a&&(0,k.jsx)(`p`,{className:`font-serif italic text-sm leading-relaxed text-muted-foreground/70`,children:`they kept quiet.`})]})}function ci({derived:e}){return(0,k.jsxs)(`div`,{className:`mt-2 border-l border-border/80 pl-3 text-left font-serif text-xs italic leading-relaxed text-muted-foreground`,children:[e.label?(0,k.jsxs)(`span`,{children:[e.label,`: `]}):null,e.text]})}function li(e){if(e.url)return e.kind===`image`||e.mimeType?.startsWith(`image/`)?{content:(0,k.jsx)(vr,{src:e.url,alt:e.name})}:e.mimeType?.startsWith(`video/`)?{content:(0,k.jsx)(`div`,{className:`w-full max-w-[24rem]`,children:(0,k.jsx)(`video`,{src:e.url,controls:!0,preload:`metadata`,className:`aspect-video w-full rounded-md bg-muted object-contain`})})}:e.mimeType?.startsWith(`audio/`)?{content:(0,k.jsx)(`div`,{className:`max-w-full`,children:(0,k.jsx)(Lr,{src:e.url,name:e.name})})}:{align:`right`,content:(0,k.jsx)(`a`,{href:e.url,className:`text-sm italic text-muted-foreground underline-offset-4 hover:underline`,children:e.name})}}function ui({attachment:e}){let t=li(e);return t?(0,k.jsxs)(`div`,{className:O(`max-w-full`,t.align===`right`&&`text-right`),children:[t.content,e.derivedText?(0,k.jsx)(ci,{derived:e.derivedText}):null]}):null}function di({attachments:e,align:t}){return e.length===0?null:(0,k.jsx)(`div`,{className:O(`mt-2 flex flex-col gap-2`,t===`right`&&`items-end`),children:e.map(e=>(0,k.jsx)(ui,{attachment:e},e.id))})}function fi({message:e}){let t=e.steps.filter(e=>e.kind===`text`).map(e=>e.kind===`text`?e.text:``).join(``);return(0,k.jsxs)(`div`,{className:`flex w-full flex-col items-end gap-1`,children:[(0,k.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground`,children:e.who}),(0,k.jsxs)(`div`,{className:`flex min-w-0 max-w-[85%] flex-col items-end`,children:[t&&Fr(t,{align:`end`}),(0,k.jsx)(di,{attachments:e.attachments??[],align:`right`})]})]})}function pi({message:e}){let t=e.steps.find(e=>e.kind===`text`);return!t||t.kind!==`text`?null:(0,k.jsx)(`div`,{className:`flex justify-center`,children:(0,k.jsx)(`p`,{className:`text-xs italic text-muted-foreground`,children:t.text})})}function mi({icon:e,label:t,onClick:n,hoverClass:r}){return(0,k.jsx)(A,{type:`button`,variant:`ghost`,size:`sm`,onClick:n,"aria-label":t,title:t,className:O(`h-7 px-2 text-muted-foreground opacity-70 transition-opacity group-hover:opacity-100`,r),children:(0,k.jsx)(e,{className:`size-3.5`})})}var hi=(0,D.memo)(function({message:e,onRetry:t,onDelete:n}){let[r,i]=(0,D.useState)(!1);return e.role===`system`?(0,k.jsx)(pi,{message:e}):e.role===`user`?(0,k.jsx)(fi,{message:e}):(0,k.jsxs)(`div`,{className:`group flex w-full flex-col`,onPointerDown:e=>{e.pointerType!==`mouse`&&i(!0)},children:[(0,k.jsx)(si,{message:e}),(0,k.jsx)(di,{attachments:e.attachments??[],align:`left`}),(t||n)&&(0,k.jsxs)(`div`,{className:O(`pointer-events-none mt-2 flex opacity-0 transition-opacity duration-150 ease-out group-hover:pointer-events-auto group-hover:opacity-100 group-focus-within:pointer-events-auto group-focus-within:opacity-100`,r&&`pointer-events-auto opacity-100`),children:[t&&(0,k.jsx)(mi,{icon:Xe,label:`retry latest reply`,onClick:t,hoverClass:`hover:text-foreground`}),n&&(0,k.jsx)(mi,{icon:y,label:`delete latest reply`,onClick:n,hoverClass:`hover:text-destructive`})]})]})}),gi=1800*1e3;function _i(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function vi(e,t){let n=new Date(e),r=new Date(t),i=n.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`}).toLowerCase();if(_i(n,r))return i;let a=new Date,o=n.getFullYear()===a.getFullYear();return`${n.toLocaleDateString([],{weekday:`long`,month:o?`long`:`short`,day:`numeric`,year:o?void 0:`numeric`}).toLowerCase()} · ${i}`}function yi({messages:e,personaName:t,historyLoaded:n,streaming:r=!1,onRetry:i,onDelete:a}){let o=(0,D.useRef)(null),s=r?-1:e.findLastIndex(e=>e.role===`assistant`);return(0,D.useEffect)(()=>{o.current?.scrollIntoView({behavior:r?`auto`:`smooth`,block:`end`})},[e,r]),n&&e.length===0?(0,k.jsx)(`div`,{className:`mx-auto flex h-full max-w-3xl items-center justify-center px-5`,children:(0,k.jsxs)(`p`,{className:`font-serif text-base italic leading-relaxed text-muted-foreground/80`,children:[`hi, i'm `,t,`. write whenever.`]})}):(0,k.jsxs)(`div`,{className:`mx-auto flex max-w-3xl flex-col gap-12 px-5 py-6`,children:[e.map((t,n)=>{let r=e[n-1];return(0,k.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[r!=null&&t.ts-r.ts>=gi&&(0,k.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,k.jsx)(`span`,{className:`font-serif italic text-xs text-muted-foreground/70 tracking-wide`,children:vi(t.ts,r.ts)})}),(0,k.jsx)(hi,{message:t,onRetry:n===s?i:void 0,onDelete:n===s?a:void 0})]},t.id)}),(0,k.jsx)(`div`,{ref:o})]})}var bi=1e3,xi=15e3;function Y(){return typeof crypto<`u`&&`randomUUID`in crypto?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2)}`}function Si(e,t){let n=t.status===`completed`||t.status===`error`;return{...e,...t,args:t.args??e?.args,partialResult:n?void 0:t.partialResult??e?.partialResult,result:t.result??e?.result,error:t.error??e?.error,startedAt:e?.startedAt??t.startedAt}}function X(e,t){return e.length===0?e:e.map(e=>e.kind===`thinking`?e.complete?e:{...e,complete:!0,endedAt:e.endedAt??t}:e.kind===`text`?e.complete?e:{...e,complete:!0}:e)}function Ci(e,t,n,r){let i=e[e.length-1];if(t===`thinking`){if(i&&i.kind===`thinking`&&!i.complete){let t={...i,text:i.text+n};return[...e.slice(0,-1),t]}let t=X(e,r),a={kind:`thinking`,id:Y(),text:n,startedAt:r};return[...t,a]}if(i&&i.kind===`text`&&!i.complete){let t={...i,text:i.text+n};return[...e.slice(0,-1),t]}let a=X(e,r),o={kind:`text`,id:Y(),text:n};return[...a,o]}function wi(e,t,n){let r=e.findIndex(e=>e.kind===`tool`&&e.tool.id===t.id);if(r>=0){let n=e[r],i={...n,tool:Si(n.tool,t)},a=e.slice();return a[r]=i,a}let i=X(e,n),a={kind:`tool`,id:t.id,tool:t};return[...i,a]}function Ti(){let[e,t]=(0,D.useState)([]),[n,r]=(0,D.useState)(`connecting`),[i,a]=(0,D.useState)(`Familiar`),[o,s]=(0,D.useState)([]),[c,l]=(0,D.useState)(void 0),[u,d]=(0,D.useState)(!1),[f,p]=(0,D.useState)(!1),m=(0,D.useRef)(null),h=(0,D.useRef)(null),g=(0,D.useRef)(async()=>void 0),_=(0,D.useRef)(new Set),v=(0,D.useCallback)((e,n)=>{t(t=>t.map(t=>t.id===e?{...t,steps:n(t.steps)}:t))},[]),y=(0,D.useCallback)(e=>{switch(`eventId`in e&&(m.current=e.eventId),e.type){case`message_started`:e.role!==`user`&&(_.current.add(e.messageId),p(!0)),t(t=>t.some(t=>t.id===e.messageId)?t:[...t,{id:e.messageId,role:e.role,who:e.who,steps:[],ts:e.ts}]);break;case`message_replaced`:_.current.delete(e.oldMessageId),_.current.add(e.newMessageId),p(!0),t(t=>t.filter(t=>t.id!==e.oldMessageId));break;case`message_deleted`:_.current.delete(e.messageId),_.current.size===0&&p(!1),t(t=>t.filter(t=>t.id!==e.messageId));break;case`delta`:{let t=Date.now();v(e.messageId,n=>Ci(n,e.part,e.content,t));break}case`tool_event`:{let t=Date.now();v(e.messageId,n=>wi(n,e.tool,t));break}case`message_completed`:{let n=Date.now();_.current.delete(e.messageId)&&p(_.current.size>0),t(t=>t.find(t=>t.id===e.messageId)?t.map(t=>t.id===e.messageId?{...t,steps:X(t.steps,n),attachments:e.attachments??t.attachments,usage:e.usage??t.usage,silent:e.silent??t.silent}:t):[...t,{id:e.messageId,role:`assistant`,who:i,steps:[],attachments:e.attachments,usage:e.usage,silent:e.silent,ts:e.ts}]);break}case`model_error`:{let n=Date.now(),r=`${e.messageId}-error`;t(t=>{let a={kind:`error`,id:r,text:e.message};return t.find(t=>t.id===e.messageId)?t.map(t=>t.id===e.messageId?t.steps.some(e=>e.id===r)?{...t,steps:t.steps.map(e=>e.id===r?a:e)}:{...t,steps:[...X(t.steps,n),a]}:t):[...t,{id:e.messageId,role:`assistant`,who:i,steps:[a],ts:e.ts}]});break}case`status`:e.kind===`idle`&&(_.current.clear(),p(!1));break;case`error`:_.current.clear(),p(!1),t(t=>[...t,{id:Y(),role:`system`,who:``,steps:[{kind:`text`,id:Y(),text:`error · ${e.code}: ${e.message}`,complete:!0}],ts:e.ts}]);break;case`replay_window_lost`:Ct(c).then(e=>t(e.messages)).catch(()=>void 0);break}},[c,i,v]),b=(0,D.useRef)(y);(0,D.useEffect)(()=>{b.current=y},[y]),(0,D.useEffect)(()=>{let e=!1;return ht().then(t=>{e||a(t.personaName)}).catch(()=>void 0),St().then(t=>{if(e)return;s(t);let n=localStorage.getItem(`familiar.activeSession`),r=n?t.find(e=>e.key===n):void 0,i=t.find(e=>e.isDefault)??t[0],a=(r??i)?.key;a&&l(a)}).catch(()=>void 0),()=>{e=!0}},[]),(0,D.useEffect)(()=>{if(!c)return;localStorage.setItem(`familiar.activeSession`,c);let e=!1,n=null,i=0,a=null;m.current=null,_.current.clear();let o=window.setTimeout(()=>{e||(t([]),d(!1),p(!1))},0);Ct(c).then(n=>{e||(t(n.messages),d(!0))}).catch(()=>{e||d(!0)});let s=()=>{if(e)return;r(`connecting`);let t=new WebSocket(Dt(c));n=t,h.current=t,t.addEventListener(`open`,()=>{e||(i=0,r(`open`),t.send(JSON.stringify({type:`hello`,lastEventId:m.current})))}),t.addEventListener(`message`,t=>{if(!e)try{let e=JSON.parse(t.data);b.current(e)}catch{}}),t.addEventListener(`close`,()=>{if(e)return;h.current===t&&(h.current=null),r(`closed`);let n=Math.min(xi,bi*2**i);i+=1,a=setTimeout(s,n)}),t.addEventListener(`error`,()=>{e||r(`error`)})};return s(),g.current=async(e,t=[])=>{let n=e.trim();!n&&t.length===0||await Et(n,Y(),c,t)},()=>{e=!0,clearTimeout(o),a&&clearTimeout(a),h.current===n&&(h.current=null),n?.close()}},[c]);let x=(0,D.useCallback)((e,t=[])=>g.current(e,t),[]),S=(0,D.useCallback)(e=>l(e),[]),C=(0,D.useCallback)(e=>{let t=h.current;return t?.readyState===WebSocket.OPEN?(t.send(JSON.stringify({type:e})),!0):!1},[]);return{messages:e,connection:n,personaName:i,sessions:o,activeSessionKey:c,historyLoaded:u,streaming:f,selectSession:S,send:x,abort:(0,D.useCallback)(()=>{C(`abort`)},[C]),retry:(0,D.useCallback)(()=>{C(`retry`)},[C]),deleteLatest:(0,D.useCallback)(()=>{C(`delete`)},[C]),notifyNewChat:(0,D.useCallback)(()=>{t(e=>[...e,{id:Y(),role:`system`,who:``,steps:[{kind:`text`,id:Y(),text:`started fresh`,complete:!0}],ts:Date.now()}])},[])}}function Ei({nav:e,authMode:t,authDevice:n,onSignedOut:r}){let{messages:i,connection:a,personaName:o,sessions:s,activeSessionKey:c,historyLoaded:l,streaming:u,selectSession:d,send:f,abort:p,retry:m,deleteLatest:h,notifyNewChat:g}=Ti(),[_,v]=(0,D.useState)(!1);return(0,k.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-background text-foreground antialiased`,children:[(0,k.jsx)(_r,{nav:e,connection:a,personaName:o,sessions:s,activeSessionKey:c,channelKey:c,onSelectSession:d,onOpenConfig:()=>v(!0),onNewChatStarted:g}),(0,k.jsx)(`main`,{className:`flex-1 overflow-y-auto`,children:(0,k.jsx)(yi,{messages:i,personaName:o,historyLoaded:l,streaming:u,onRetry:m,onDelete:h})}),(0,k.jsx)(cn,{onSend:f,onAbort:p,streaming:u,personaName:o}),(0,k.jsx)(Zn,{open:_,onOpenChange:v,channelKey:c,authMode:t,authDevice:n,onSignedOut:r})]})}function Di(e){let t=new Date(`${e}T00:00:00`);return Number.isNaN(t.getTime())?null:t}function Oi(e){let t=Di(e);return t?new Intl.DateTimeFormat(void 0,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`}).format(t).toLowerCase():e}function ki(e){let t=Di(e);if(!t)return{weekday:``,day:e,month:``};let n=e=>new Intl.DateTimeFormat(void 0,e).format(t).toLowerCase();return{weekday:n({weekday:`short`}),day:n({day:`numeric`}),month:n({month:`short`})}}function Ai(e){let t=Di(e);if(!t)return null;let n=new Date;return n.setHours(0,0,0,0),Math.round((n.getTime()-t.getTime())/864e5)}function ji(e){let t=Ai(e);if(!(t===null||t<0)){if(t===0)return`today`;if(t===1)return`yesterday`;if(t<7)return`${t} days ago`;if(t<14)return`last week`;if(t<30)return`${Math.round(t/7)} weeks ago`;if(t<60)return`last month`;if(t<365)return`${Math.round(t/30)} months ago`}}function Mi(e){let t=e.trim().split(/\s+/).filter(Boolean).length;if(t===0)return``;let n=Math.max(1,Math.round(t/200));return n===1?`a minute’s read`:`a ${n}-minute read`}function Ni({diary:e,active:t,onSelect:n}){let{weekday:r,day:i,month:a}=ki(e.date),o=Ai(e.date)===0;return(0,k.jsxs)(`button`,{type:`button`,onClick:n,"aria-current":t?`page`:void 0,className:O(`flex w-full gap-3 rounded-md px-2 py-3 text-left transition-colors focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-none`,t?`bg-primary text-primary-foreground`:`text-foreground hover:bg-accent/50`),children:[(0,k.jsxs)(`span`,{className:`flex w-10 shrink-0 flex-col items-center font-serif leading-none`,children:[(0,k.jsx)(`span`,{className:O(`text-[0.6875rem] tracking-wide`,t?`text-primary-foreground/70`:`text-muted-foreground`),children:r}),(0,k.jsx)(`span`,{className:`mt-0.5 text-2xl tabular-nums`,children:i}),(0,k.jsx)(`span`,{className:O(`mt-0.5 text-[0.6875rem] tracking-wide`,t?`text-primary-foreground/70`:`text-muted-foreground`),children:a})]}),(0,k.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,k.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,k.jsx)(`span`,{className:`block truncate font-serif text-sm leading-tight tracking-tight`,children:e.title}),o?(0,k.jsx)(`span`,{className:O(`size-1.5 shrink-0 rounded-full`,t?`bg-primary-foreground/70`:`bg-primary`),"aria-hidden":!0}):null]}),e.excerpt?(0,k.jsx)(`span`,{className:O(`mt-1.5 line-clamp-2 text-xs leading-relaxed`,t?`text-primary-foreground/85`:`text-muted-foreground`),children:e.excerpt}):null]})]})}function Pi({content:e,title:t}){let n=(0,D.useMemo)(()=>Fi(e,t),[e,t]);return n.length===0?(0,k.jsx)(`p`,{className:`font-serif text-sm italic text-muted-foreground`,children:`this day is quiet.`}):(0,k.jsx)(`div`,{className:`warm-prose diary-prose`,children:n})}function Fi(e,t){let n=[],r=[],i=[],a,o=!1,s=()=>{let e=r.join(` `).trim();e&&n.push((0,k.jsx)(`p`,{children:Z(e)},n.length)),r.length=0},c=()=>{if(!a||i.length===0)return;let e=a;n.push((0,k.jsx)(e,{children:i.map((e,t)=>(0,k.jsx)(`li`,{children:Z(e)},t))},n.length)),i=[],a=void 0},l=()=>{s(),c()};for(let u of e.replace(/\r\n/g,`
|
|
6
|
+
`).split(`
|
|
7
|
+
`)){let e=u.trim();if(!e){l();continue}let d=/^(#{1,6})\s+(.+)$/.exec(e);if(d){l();let e=d[1]?.length??1,r=d[2]??``;if(!o&&Li(r)===Li(t)){o=!0;continue}o=!0;let i=e<=2?`h2`:`h3`;n.push((0,k.jsx)(i,{children:Z(r)},n.length));continue}let f=/^[-*+]\s+(.+)$/.exec(e),p=/^\d+[.)]\s+(.+)$/.exec(e);if(f||p){s();let e=f?`ul`:`ol`;a&&a!==e&&c(),a=e,i.push((f?.[1]??p?.[1]??``).trim());continue}let m=/^>\s+(.+)$/.exec(e);if(m){l(),n.push((0,k.jsx)(`blockquote`,{children:Z(m[1]??``)},n.length));continue}Ii(e)&&r.length>0&&s(),r.push(e)}return l(),n}function Z(e){let t=[],n=/(`([^`]+)`|\*\*([^*]+)\*\*|\*([^*]+)\*)/g,r=0;for(let i of e.matchAll(n)){let n=i.index??0;n>r&&t.push(e.slice(r,n));let a=i[2]??i[3]??i[4]??``;i[2]?t.push((0,k.jsx)(`code`,{children:a},t.length)):i[3]?t.push((0,k.jsx)(`strong`,{children:a},t.length)):t.push((0,k.jsx)(`em`,{children:a},t.length)),r=n+i[0].length}return r<e.length&&t.push(e.slice(r)),t}function Ii(e){return/^(?:[A-Z][A-Za-z ]{0,32}\s+)?\(?\d{1,2}:\d{2}\)?\s*[:.)-]/.test(e)}function Li(e){return e.replace(/`([^`]+)`/g,`$1`).replace(/\[([^\]]+)\]\([^)]+\)/g,`$1`).replace(/[*_~#>]/g,``).trim().toLowerCase()}function Ri(){return(0,k.jsxs)(`div`,{className:`mt-2 space-y-3`,"aria-hidden":!0,children:[(0,k.jsx)(`div`,{className:`h-3 w-full rounded-sm bg-muted-foreground/10`}),(0,k.jsx)(`div`,{className:`h-3 w-11/12 rounded-sm bg-muted-foreground/10`}),(0,k.jsx)(`div`,{className:`h-3 w-4/5 rounded-sm bg-muted-foreground/10`}),(0,k.jsx)(`div`,{className:`h-3 w-2/3 rounded-sm bg-muted-foreground/10`})]})}function zi({summary:e,content:t,loading:n,settle:r}){if(!e)return(0,k.jsx)(`div`,{className:`flex h-full min-h-[18rem] items-center justify-center px-6 text-center`,children:(0,k.jsx)(`p`,{className:`font-serif text-sm italic text-muted-foreground`,children:`choose a written day.`})});let i=[ji(e.date),t===void 0?``:Mi(t)].filter(Boolean).join(` · `);return(0,k.jsxs)(`article`,{className:O(`mx-auto flex w-full max-w-[70ch] flex-col px-6 py-8 md:px-8 md:py-10`,r&&`duration-200 ease-out-quart animate-in fade-in-0 slide-in-from-bottom-[0.375rem] motion-reduce:animate-none`),children:[(0,k.jsxs)(`div`,{className:`mb-8 border-b border-border pb-6`,children:[(0,k.jsx)(`p`,{className:`font-serif text-sm italic text-muted-foreground`,children:Oi(e.date)}),(0,k.jsx)(`h1`,{className:`mt-3 font-serif text-3xl leading-tight tracking-tight text-balance text-foreground`,children:e.title}),i?(0,k.jsx)(`p`,{className:`mt-3 font-serif text-xs italic text-muted-foreground`,children:i}):null]}),t===void 0?n?(0,k.jsx)(Ri,{}):null:(0,k.jsx)(`div`,{className:`duration-300 ease-out-quart animate-in fade-in-0 motion-reduce:animate-none`,children:(0,k.jsx)(Pi,{content:t,title:e.title})})]},e.date)}function Bi(){return(0,k.jsx)(`div`,{className:`grid gap-1 px-2 py-1`,children:Array.from({length:6},(e,t)=>(0,k.jsxs)(`div`,{className:`flex gap-3 rounded-md px-2 py-3`,children:[(0,k.jsxs)(`div`,{className:`flex w-10 shrink-0 flex-col items-center gap-1 pt-0.5`,children:[(0,k.jsx)(`div`,{className:`h-2 w-7 rounded-sm bg-muted-foreground/10`}),(0,k.jsx)(`div`,{className:`h-5 w-6 rounded-sm bg-muted-foreground/15`}),(0,k.jsx)(`div`,{className:`h-2 w-6 rounded-sm bg-muted-foreground/10`})]}),(0,k.jsxs)(`div`,{className:`min-w-0 flex-1 pt-0.5`,children:[(0,k.jsx)(`div`,{className:`h-3 w-2/3 rounded-sm bg-muted-foreground/15`}),(0,k.jsx)(`div`,{className:`mt-2.5 h-2 w-full rounded-sm bg-muted-foreground/10`}),(0,k.jsx)(`div`,{className:`mt-1.5 h-2 w-4/5 rounded-sm bg-muted-foreground/10`})]})]},t))})}function Vi(){return(0,k.jsxs)(`div`,{className:`mx-auto grid w-full max-w-6xl flex-1 grid-cols-1 gap-6 overflow-hidden px-4 py-5 md:grid-cols-[18rem_minmax(0,1fr)] md:px-8`,children:[(0,k.jsx)(`div`,{className:`rounded-md border border-border bg-card py-2`,children:(0,k.jsx)(Bi,{})}),(0,k.jsxs)(`div`,{className:`rounded-md border border-border bg-card p-8`,children:[(0,k.jsx)(`div`,{className:`h-4 w-28 rounded-sm bg-muted-foreground/15`}),(0,k.jsx)(`div`,{className:`mt-6 h-8 w-64 rounded-sm bg-muted-foreground/10`}),(0,k.jsxs)(`div`,{className:`mt-8 space-y-3`,children:[(0,k.jsx)(`div`,{className:`h-3 w-full rounded-sm bg-muted-foreground/10`}),(0,k.jsx)(`div`,{className:`h-3 w-11/12 rounded-sm bg-muted-foreground/10`}),(0,k.jsx)(`div`,{className:`h-3 w-3/4 rounded-sm bg-muted-foreground/10`})]})]})]})}function Hi({onRefresh:e}){return(0,k.jsx)(`div`,{className:`flex h-full min-h-[18rem] items-center justify-center px-6 text-center`,children:(0,k.jsxs)(`div`,{className:`max-w-sm`,children:[(0,k.jsx)(o,{className:`mx-auto size-7 text-muted-foreground`}),(0,k.jsx)(`h2`,{className:`mt-5 font-serif text-xl leading-tight tracking-tight`,children:`no written days yet`}),(0,k.jsx)(`p`,{className:`mt-3 text-sm leading-relaxed text-muted-foreground`,children:`when dated diary files arrive in the diary folder, they will settle here newest first.`}),(0,k.jsxs)(A,{type:`button`,variant:`ghost`,className:`mt-5`,onClick:e,children:[(0,k.jsx)(ze,{className:`size-4`}),`check again`]})]})})}function Ui({className:e,children:t,...n}){return(0,k.jsxs)(me,{"data-slot":`scroll-area`,className:O(`relative`,e),...n,children:[(0,k.jsx)(ve,{"data-slot":`scroll-area-viewport`,className:`size-full rounded-[inherit] transition-[color,box-shadow] outline-none focus-visible:ring-[3px] focus-visible:ring-ring/50 focus-visible:outline-1`,children:t}),(0,k.jsx)(Wi,{}),(0,k.jsx)(ke,{})]})}function Wi({className:e,orientation:t=`vertical`,...n}){return(0,k.jsx)(Be,{"data-slot":`scroll-area-scrollbar`,"data-orientation":t,orientation:t,className:O(`flex touch-none p-px transition-colors select-none data-horizontal:h-2.5 data-horizontal:flex-col data-horizontal:border-t data-horizontal:border-t-transparent data-vertical:h-full data-vertical:w-2.5 data-vertical:border-l data-vertical:border-l-transparent`,e),...n,children:(0,k.jsx)(qe,{"data-slot":`scroll-area-thumb`,className:`relative flex-1 rounded-full bg-border`})})}function Gi({nav:e}){let[t,n]=(0,D.useState)([]),[r,i]=(0,D.useState)(),[a,o]=(0,D.useState)(),[s,c]=(0,D.useState)(!0),[l,u]=(0,D.useState)(!1),[d,f]=(0,D.useState)(),[p,m]=(0,D.useState)(!1),[h,g]=(0,D.useState)(!1),_=(0,D.useCallback)(async()=>{c(!0),f(void 0);try{let e=await wt();n(e),i(t=>t&&e.some(e=>e.date===t)?t:e[0]?.date)}catch(e){f(e instanceof Error?e.message:String(e))}finally{c(!1)}},[]),v=(0,D.useCallback)(async e=>{u(!0),f(void 0);try{o(await Tt(e))}catch(e){f(e instanceof Error?e.message:String(e)),o(void 0)}finally{u(!1)}},[]);(0,D.useEffect)(()=>{let e=window.setTimeout(()=>void _(),0);return()=>window.clearTimeout(e)},[_]),(0,D.useEffect)(()=>{if(!r||a?.date===r)return;let e=window.setTimeout(()=>void v(r),0);return()=>window.clearTimeout(e)},[a?.date,v,r]);let y=t.find(e=>e.date===r),b=a&&a.date===r?a.content:void 0,x=s&&t.length===0;return(0,k.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-background text-foreground`,children:[(0,k.jsx)(`header`,{className:`border-b border-border bg-background px-3 py-3 md:px-8`,children:(0,k.jsxs)(`div`,{className:`mx-auto flex max-w-6xl items-center gap-3`,children:[e,(0,k.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,k.jsx)(`p`,{className:`font-serif text-2xl leading-tight tracking-tight`,children:`diaries`}),(0,k.jsx)(`p`,{className:`mt-0.5 font-serif text-xs italic text-muted-foreground`,children:`written days, kept close`})]}),(0,k.jsxs)(A,{type:`button`,variant:`ghost`,size:`sm`,className:`text-muted-foreground hover:text-foreground`,onClick:()=>void _(),disabled:s,children:[(0,k.jsx)(ze,{className:O(`size-4`,s&&`animate-spin`)}),`refresh`]})]})}),d?(0,k.jsx)(`p`,{className:`border-b border-border bg-card px-3 py-2 font-serif text-xs italic text-destructive md:px-8`,children:d}):null,x?(0,k.jsx)(Vi,{}):t.length===0?(0,k.jsx)(Hi,{onRefresh:()=>void _()}):(0,k.jsxs)(`div`,{className:`mx-auto flex w-full max-w-6xl flex-1 flex-col gap-5 overflow-hidden px-4 py-5 md:flex-row md:px-8`,children:[(0,k.jsx)(`aside`,{className:O(`min-h-0 flex-col rounded-md border border-border bg-card py-2 md:flex md:w-72 md:flex-none`,p?`hidden md:flex`:`flex flex-1`),children:(0,k.jsx)(Ui,{className:`min-h-0 flex-1`,children:(0,k.jsx)(`div`,{className:`grid gap-1 px-2`,children:t.map(e=>(0,k.jsx)(Ni,{diary:e,active:e.date===r,onSelect:()=>{e.date!==r&&g(!0),i(e.date),m(!0)}},e.date))})})}),(0,k.jsxs)(`main`,{className:O(`min-h-0 flex-col overflow-hidden rounded-md border border-border bg-card md:flex md:flex-1`,p?`flex flex-1`:`hidden md:flex`),children:[(0,k.jsxs)(`button`,{type:`button`,onClick:()=>m(!1),className:`flex items-center gap-1.5 border-b border-border px-4 py-2.5 text-left font-serif text-xs italic text-muted-foreground transition-colors hover:text-foreground md:hidden`,children:[(0,k.jsx)(oe,{className:`size-3.5`}),`all days`]}),(0,k.jsx)(Ui,{className:`min-h-0 flex-1`,children:(0,k.jsx)(zi,{summary:y,content:b,loading:l,settle:h})})]})]})]})}function Ki({item:e,active:t,onClick:n}){let r=e.icon,i=e.enabled===!0;return(0,k.jsxs)(`button`,{type:`button`,onClick:n,disabled:!i,className:O(`flex h-11 w-full items-center gap-3 rounded-md px-3 text-left transition-colors focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-none`,t?`bg-primary text-primary-foreground hover:bg-primary`:i?`text-sidebar-foreground/70 hover:bg-primary/20 hover:text-sidebar-foreground`:`cursor-default text-sidebar-foreground/35`),"aria-current":t?`page`:void 0,title:i?e.label:`${e.label} soon`,children:[(0,k.jsx)(`span`,{className:`flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-current`,children:(0,k.jsx)(r,{className:`size-4`})}),(0,k.jsxs)(`span`,{className:`min-w-0`,children:[(0,k.jsx)(`span`,{className:`block text-sm leading-tight`,children:e.label}),(0,k.jsx)(`span`,{className:O(`mt-0.5 block truncate font-serif text-[11px] italic`,t?`text-primary-foreground/75`:`text-muted-foreground`),children:e.description})]})]})}function qi({items:e,selectedPage:t,onSelectPage:n}){let[r,i]=(0,D.useState)(!1);return(0,k.jsxs)(Ie,{open:r,onOpenChange:i,children:[(0,k.jsx)(De,{asChild:!0,children:(0,k.jsx)(A,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`pages`,title:`pages`,className:`text-muted-foreground hover:text-foreground`,children:(0,k.jsx)(Je,{className:`size-[1.125rem]`})})}),(0,k.jsx)(He,{children:(0,k.jsxs)(Ce,{side:`bottom`,align:`start`,sideOffset:8,collisionPadding:16,className:O(`z-50 w-72 max-w-[calc(100vw-1.5rem)] origin-(--radix-popover-content-transform-origin)`,`rounded-lg bg-sidebar p-3 text-sidebar-foreground shadow-lg`,`data-[state=open]:animate-in data-[state=closed]:animate-out`,`data-[state=open]:fade-in-0 data-[state=closed]:fade-out-0`,`data-[state=open]:zoom-in-95 data-[state=closed]:zoom-out-95`,`motion-reduce:animate-none dark:bg-card dark:text-card-foreground`,`dark:shadow-[2px_3px_12px_0_oklch(0.14_0.01_58_/_0.34)]`),children:[(0,k.jsxs)(`div`,{className:`px-3 pb-5`,children:[(0,k.jsx)(`p`,{className:`font-serif text-lg leading-tight tracking-tight`,children:`familiar`}),(0,k.jsx)(`p`,{className:`mt-1 font-serif text-xs italic text-muted-foreground`,children:`choose a room`})]}),(0,k.jsx)(`nav`,{className:`grid gap-2`,children:e.map(e=>(0,k.jsx)(Ki,{item:e,active:t===e.id,onClick:()=>{e.enabled===!0&&(n(e.id),i(!1))}},e.id))})]})})]})}var Ji=[{id:`chat`,label:`chat`,description:`where you two are`,icon:we,enabled:!0},{id:`diaries`,label:`diaries`,description:`written days`,icon:o,enabled:!0},{id:`skills`,label:`skills`,description:`little tools`,icon:de},{id:`files`,label:`files`,description:`notes by the door`,icon:ot},{id:`gallery`,label:`gallery`,description:`pictures left behind`,icon:Oe}];function Yi({authMode:e,authDevice:t,onSignedOut:n}){let[r,i]=(0,D.useState)(`chat`),[a,o]=(0,D.useState)(!1),s=r===`diaries`,c=(0,k.jsx)(qi,{items:Ji,selectedPage:r,onSelectPage:e=>{e===`diaries`&&o(!0),i(e)}});return(0,k.jsxs)(`div`,{className:`relative flex h-dvh bg-background text-foreground antialiased`,children:[(0,k.jsx)(`section`,{className:O(`min-w-0 flex-1 flex-col`,r===`chat`?`flex`:`hidden`),children:(0,k.jsx)(Ei,{nav:c,authMode:e,authDevice:t,onSignedOut:n})}),a?(0,k.jsx)(`section`,{className:O(`min-w-0 flex-1 flex-col`,s?`flex`:`hidden`),children:(0,k.jsx)(Gi,{nav:c})}):null]})}function Xi(){return typeof navigator>`u`?``:navigator.platform?.trim()||`this browser`}function Zi(){let[e,t]=(0,D.useState)({status:`loading`,personaName:`Familiar`});return(0,D.useEffect)(()=>{let e=!1;async function n(){try{let n=await ht();if(n.mode!==`bearer`){e||t({status:`chat`,mode:n.mode,personaName:n.personaName});return}let r=await gt();if(e)return;t(r?{status:`chat`,mode:`bearer`,personaName:n.personaName,device:r}:{status:`login`,mode:`bearer`,personaName:n.personaName})}catch(n){e||t({status:`login`,mode:`bearer`,personaName:`Familiar`,error:n instanceof Error?n.message:String(n)})}}return n(),()=>{e=!0}},[]),e.status===`chat`?(0,k.jsx)(Yi,{authMode:e.mode,authDevice:e.device,onSignedOut:()=>{t({status:`login`,mode:`bearer`,personaName:e.personaName})}}):e.status===`login`?(0,k.jsx)(Qi,{personaName:e.personaName,initialError:e.error,onLogin:n=>{t({status:`chat`,mode:`bearer`,personaName:e.personaName,device:n})}}):(0,k.jsx)(`div`,{className:`flex h-dvh items-center justify-center bg-background px-5 text-foreground antialiased`,children:(0,k.jsx)(`p`,{className:`font-serif text-sm italic text-muted-foreground`,children:`checking the door…`})})}function Qi({personaName:e,initialError:t,onLogin:n}){let[r,i]=(0,D.useState)(``),[a,o]=(0,D.useState)(Xi),[s,c]=(0,D.useState)(t),[l,u]=(0,D.useState)(!1);return(0,k.jsx)(`div`,{className:`flex h-dvh flex-col bg-background text-foreground antialiased`,children:(0,k.jsx)(`main`,{className:`mx-auto flex w-full max-w-sm flex-1 flex-col justify-center px-5 py-10`,children:(0,k.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault();let t=r.trim();if(t){u(!0),c(void 0);try{n(await _t(t,a))}catch(e){c(e instanceof Error?e.message:String(e))}finally{u(!1)}}},className:`rounded-md border border-border bg-card px-5 py-5 shadow-sm`,children:[(0,k.jsxs)(`div`,{className:`mb-5`,children:[(0,k.jsx)(`p`,{className:`font-serif text-2xl leading-tight tracking-tight`,children:e}),(0,k.jsx)(`p`,{className:`mt-2 font-serif text-xs italic text-muted-foreground`,children:`come in with your token.`})]}),(0,k.jsxs)(`label`,{className:`grid gap-2`,children:[(0,k.jsx)(`span`,{className:`font-serif text-xs italic text-muted-foreground`,children:`token`}),(0,k.jsx)(`input`,{type:`password`,value:r,onChange:e=>{i(e.target.value),s&&c(void 0)},autoComplete:`current-password`,disabled:l,className:`h-10 rounded-md border border-border bg-background px-3 font-mono text-sm text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-none disabled:opacity-50`})]}),(0,k.jsxs)(`label`,{className:`mt-4 grid gap-2`,children:[(0,k.jsx)(`span`,{className:`font-serif text-xs italic text-muted-foreground`,children:`device name`}),(0,k.jsx)(`input`,{type:`text`,value:a,onChange:e=>o(e.target.value),autoComplete:`off`,disabled:l,className:`h-10 rounded-md border border-border bg-background px-3 text-sm text-foreground focus-visible:border-ring focus-visible:ring-3 focus-visible:ring-ring/50 focus-visible:outline-none disabled:opacity-50`})]}),s?(0,k.jsx)(`p`,{className:`mt-3 font-serif text-xs italic text-destructive`,children:s}):null,(0,k.jsxs)(A,{type:`submit`,className:`mt-5 h-9 w-full gap-2`,disabled:l||!r.trim(),children:[(0,k.jsx)(Le,{className:`size-4`}),(0,k.jsx)(`span`,{children:l?`checking`:`enter`})]})]})})})}var Q=Date.now(),$=6e4,$i=[{id:`u-1`,role:`user`,who:`you`,ts:Q-10*$,steps:[{kind:`text`,id:`u-1-t`,text:`do you remember that note about the lamp?`,complete:!0}]},{id:`a-1`,role:`assistant`,who:`ghost`,ts:Q-9*$,steps:[{kind:`thinking`,id:`a-1-think-1`,text:`she's asking about the hearth-lamp note. let me look through memory for it.`,startedAt:Q-9*$-3e3,endedAt:Q-9*$-1e3,complete:!0},{kind:`tool`,id:`a-1-tool-1`,tool:{id:`a-1-tool-1`,name:`memory_search`,status:`completed`,args:{query:`lamp hearth cold room`,topK:5},result:{results:[{id:`m-7`,text:`the hearth-lamp doesn't quite reach the corner where she sits at night.`,score:.91},{id:`m-3`,text:`she said cold rooms made her feel like a stranger in her own house.`,score:.78},{id:`m-12`,text:`the lamp is older than the apartment. she keeps meaning to rewire it.`,score:.74}]},startedAt:Q-9*$-1e3,completedAt:Q-9*$-100}},{kind:`thinking`,id:`a-1-think-2`,text:`ok, three matches. the most direct one is m-7. i'll quote it back gently.`,startedAt:Q-9*$-100,endedAt:Q-9*$+800,complete:!0},{kind:`text`,id:`a-1-text-1`,text:`yes — i was just looking at it. you wrote that the hearth-lamp doesn't quite reach the corner where you sit at night. it was a tuesday, the night we talked about cold rooms.`,complete:!0}]},{id:`u-2`,role:`user`,who:`you`,ts:Q-5*$,steps:[{kind:`text`,id:`u-2-t`,text:`send me the cat meme + read it aloud`,complete:!0}]},{id:`a-2`,role:`assistant`,who:`ghost`,ts:Q-5*$+500,attachments:[{id:`demo-image`,name:`cat-loaf.png`,kind:`image`,mimeType:`image/svg+xml`,url:`/familiar.svg`}],steps:[{kind:`thinking`,id:`a-2-think`,text:`she wants two things: the meme + TTS. send the meme first, then speak.`,startedAt:Q-5*$+500,endedAt:Q-5*$+1500,complete:!0},{kind:`tool`,id:`a-2-tool-1`,tool:{id:`a-2-tool-1`,name:`meme`,status:`completed`,args:{name:`cat-loaf`,family:`cats`},result:{url:`https://example.com/cat-loaf.png`},startedAt:Q-5*$+1500,completedAt:Q-5*$+1700}},{kind:`text`,id:`a-2-text-1`,text:`here's the loaf.`,complete:!0},{kind:`tool`,id:`a-2-tool-2`,tool:{id:`a-2-tool-2`,name:`tts_speak`,status:`completed`,args:{text:`here's the loaf. she is a small bread now.`},startedAt:Q-5*$+2e3,completedAt:Q-5*$+3500}},{kind:`text`,id:`a-2-text-2`,text:`she is a small bread now.`,complete:!0}]},{id:`u-3`,role:`user`,who:`you`,ts:Q-2*$,steps:[{kind:`text`,id:`u-3-t`,text:`what time is it where the server lives?`,complete:!0}]},{id:`a-3`,role:`assistant`,who:`ghost`,ts:Q-2*$+500,silent:!0,steps:[{kind:`thinking`,id:`a-3-think`,text:`she's checking on the server, not asking for chat. quick lookup and let it sit.`,startedAt:Q-2*$+500,endedAt:Q-2*$+1200,complete:!0},{kind:`tool`,id:`a-3-tool`,tool:{id:`a-3-tool`,name:`bash`,status:`completed`,args:{command:`date '+%Z %H:%M'`},result:`UTC 04:12
|
|
8
|
+
`,startedAt:Q-2*$+1200,completedAt:Q-2*$+1400}}]},{id:`u-4`,role:`user`,who:`you`,ts:Q-$,steps:[{kind:`text`,id:`u-4-t`,text:`can you write a note to the diary about today?`,complete:!0}]},{id:`a-4`,role:`assistant`,who:`ghost`,ts:Q-$+500,steps:[{kind:`thinking`,id:`a-4-think`,text:`diary write. compose then call write_file.`,startedAt:Q-$+500,endedAt:Q-$+1200,complete:!0},{kind:`tool`,id:`a-4-tool`,tool:{id:`a-4-tool`,name:`write_file`,status:`error`,args:{path:`/diary/2026-05-25.md`,content:`...`},error:`EACCES: permission denied, open '/diary/2026-05-25.md'`,startedAt:Q-$+1200,completedAt:Q-$+1300}},{kind:`text`,id:`a-4-text`,text:`i couldn't reach the diary file — permissions. could you check it for me?`,complete:!0}]},{id:`u-5`,role:`user`,who:`you`,ts:Q-4e4,steps:[{kind:`text`,id:`u-5-t`,text:`summarize the long thread from last week`,complete:!0}]},{id:`a-err-1`,role:`assistant`,who:`ghost`,ts:Q-38e3,steps:[{kind:`thinking`,id:`a-err-1-think`,text:`big context. let me pull the thread and condense it.`,startedAt:Q-38e3,endedAt:Q-37e3,complete:!0},{kind:`error`,id:`a-err-1-error`,text:`503 Service Unavailable · upstream provider overloaded (anthropic/claude-opus-4-8)`}]},{id:`a-err-2`,role:`assistant`,who:`ghost`,ts:Q-2e4,steps:[{kind:`error`,id:`a-err-2-error`,text:`429 Too Many Requests · rate_limit_exceeded — retry after 30s`}]},{id:`a-5`,role:`assistant`,who:`ghost`,ts:Q-5e3,steps:[{kind:`thinking`,id:`a-5-think`,text:`still thinking about how to phrase this. she asked about—`,startedAt:Q-5e3}]}];function ea(){return(0,k.jsxs)(`div`,{className:`flex h-dvh flex-col bg-background text-foreground antialiased`,children:[(0,k.jsxs)(`div`,{className:`border-b border-border px-5 py-3`,children:[(0,k.jsx)(`span`,{className:`font-serif text-lg text-foreground`,children:`ghost`}),(0,k.jsx)(`span`,{className:`ml-3 font-serif italic text-xs text-muted-foreground/70`,children:`playground · synthetic states`})]}),(0,k.jsx)(`main`,{className:`flex-1 overflow-y-auto`,children:(0,k.jsx)(yi,{messages:$i,personaName:`ghost`,historyLoaded:!0})})]})}function ta(){return typeof window<`u`&&new URLSearchParams(window.location.search).has(`demo`)?(0,k.jsx)(ea,{}):(0,k.jsx)(Zi,{})}L(I()),kn(I),(0,dt.createRoot)(document.getElementById(`root`)).render((0,k.jsx)(D.StrictMode,{children:(0,k.jsx)(ta,{})}));
|