@qearlyao/familiar 0.3.0 → 0.4.0
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 +29 -0
- 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 +11 -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/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-C-k4O5Dz.js +6 -0
- package/web/dist/assets/index-Dj-L9nX4.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/{service.js → lifecycle/service.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/npm-shrinkwrap.json
CHANGED
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@qearlyao/familiar",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
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.0",
|
|
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.0",
|
|
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,6 @@
|
|
|
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 E,x as nt,xt as rt,y as it,yt as D,z as at}from"./ui-C12-nN_X.js";import{n as ot,r as O,t as st}from"./markdown-kaIeGxdv.js";import{t as ct}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 k=e(t(),1),lt=n();function A(...e){return Ye(g(e))}var ut=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`}}),j=r();function M({className:e,variant:t=`default`,size:n=`default`,asChild:r=!1,...i}){return(0,j.jsx)(r?s:`button`,{"data-slot":`button`,"data-variant":t,"data-size":n,className:A(ut({variant:t,size:n,className:e})),...i})}function dt(){return typeof crypto<`u`&&`randomUUID`in crypto?crypto.randomUUID():`step-${Date.now()}-${Math.random().toString(36).slice(2)}`}function ft(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:dt(),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:dt(),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 pt(){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 mt(){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 ht(e,t){return(await N(`/api/web/auth/login`,`POST`,{token:e,deviceName:t?.trim()||void 0},`auth/login`)).device}async function gt(){let e=await fetch(`/api/web/auth/devices`);if(!e.ok)throw Error(`auth/devices: ${e.status}`);return(await e.json()).devices}async function _t(e){await N(`/api/web/auth/devices`,`DELETE`,{id:e},`auth/devices`)}async function vt(){return(await N(`/api/web/auth/devices/revoke-others`,`POST`,{},`auth/devices/revoke-others`)).revoked}async function yt(){await N(`/api/web/auth/logout`,`POST`,{},`auth/logout`)}async function bt(){let e=await fetch(`/api/web/sessions`);if(!e.ok)throw Error(`sessions: ${e.status}`);return(await e.json()).sessions}async function xt(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(ft),hasMore:i.hasMore,channelKey:i.channelKey}}async function St(){let e=await fetch(`/api/web/diaries`);if(!e.ok)throw Error(`diaries: ${e.status}`);return(await e.json()).diaries}async function Ct(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 wt(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 Tt(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 Et(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 Dt(){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 N(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 Ot(e){let t=await N(`/api/web/agent/models`,`POST`,{model:e},`agent/models`);return{models:t.models,added:t.added??[]}}async function kt(e){let t=await N(`/api/web/agent/models`,`DELETE`,{model:e},`agent/models`);return{models:t.models,added:t.added??[]}}async function At(e,t){return N(`/api/web/agent/settings`,`POST`,{channelKey:e,...t},`agent/settings`)}async function jt(e){await N(`/api/web/agent/new`,`POST`,{channelKey:e},`agent/new`)}async function Mt(){let e=await fetch(`/api/web/memes`);if(!e.ok)throw Error(`memes: ${e.status}`);return(await e.json()).families}async function Nt(){let e=await fetch(`/api/web/config`);if(!e.ok)throw Error(`config: ${e.status}`);return await e.json()}async function Pt(e,t){return N(`/api/web/config`,`POST`,{key:e,value:t},`config`)}async function Ft(e){return N(`/api/web/config`,`DELETE`,{key:e},`config`)}function It({onPick:e}){let[t,n]=(0,k.useState)(!1),[r,i]=(0,k.useState)(null),[a,o]=(0,k.useState)(null),[s,c]=(0,k.useState)(null),[l,u]=(0,k.useState)(``),d=(0,k.useRef)(null),f=(0,k.useRef)(!1);(0,k.useEffect)(()=>{t&&(r!=null||f.current||(f.current=!0,Mt().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,k.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,k.useMemo)(()=>r?r.find(e=>e.name===s)??r[0]??null:null,[r,s]),m=(0,k.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,j.jsxs)(Ie,{open:t,onOpenChange:n,children:[(0,j.jsx)(De,{asChild:!0,children:(0,j.jsx)(M,{type:`button`,size:`sm`,variant:`ghost`,"aria-label":`memes`,className:`text-muted-foreground hover:text-foreground`,children:(0,j.jsx)(te,{className:`size-4`})})}),(0,j.jsx)(He,{children:(0,j.jsx)(Ce,{side:`top`,align:`end`,sideOffset:10,collisionPadding:16,className:A(`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,j.jsx)(`div`,{className:`px-2 py-6 text-center font-serif text-sm italic text-muted-foreground`,children:a}):r?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:`flex items-center gap-3 px-1 pb-2 text-sm`,children:r.map((e,t)=>(0,j.jsxs)(`span`,{className:`flex items-center gap-3`,children:[t>0&&(0,j.jsx)(`span`,{className:`text-muted-foreground/40`,children:`·`}),(0,j.jsx)(`button`,{type:`button`,onClick:()=>c(e.name),className:A(`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,j.jsx)(`input`,{ref:d,type:`text`,value:l,onChange:e=>u(e.target.value),placeholder:`search by name…`,className:A(`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,j.jsx)(`div`,{className:`max-h-72 overflow-y-auto`,children:m.length===0?(0,j.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,j.jsx)(`div`,{className:`grid grid-cols-4 gap-2 sm:grid-cols-5`,children:m.map(e=>(0,j.jsxs)(`button`,{type:`button`,onClick:()=>h(e),title:e.name,className:A(`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,j.jsx)(`img`,{src:e.url,alt:e.name,loading:`lazy`,className:`h-full w-full object-cover`}),(0,j.jsx)(`span`,{className:A(`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,j.jsx)(`div`,{className:`px-2 py-6 text-center font-serif text-sm italic text-muted-foreground/80`,children:`opening the drawer…`})})})]})}var Lt={value:``,attachments:[],revision:0};function Rt(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 zt(e){return{value:``,attachments:[],revision:e.revision+1}}function Bt(e,t){return e.revision===t&&e.value.length===0&&e.attachments.length===0}function Vt({onSend:e,onAbort:t,streaming:n,personaName:r}){let[i,a]=(0,k.useState)(Lt),[o,s]=(0,k.useState)(!1),[c,l]=(0,k.useState)(!1),[u,d]=(0,k.useState)(),f=(0,k.useRef)(null),p=(0,k.useRef)(null),{value:m,attachments:h}=i;(0,k.useEffect)(()=>{let e=f.current;e&&(e.style.height=`auto`,e.style.height=`${Math.min(e.scrollHeight,200)}px`)},[m]);let g=async()=>{if(c)return;let t=i,n=m.trim();if(!n&&h.length===0)return;let r=t.revision+1;d(void 0),l(!0),a(zt);try{await e(n,t.attachments)}catch(e){a(e=>Bt(e,r)?t:e),d(Rt(e))}finally{l(!1)}},_=e=>{let t=`meme: ${e.name} (${e.url})`;a(e=>({...e,value:e.value.trim()?`${e.value.trimEnd()}\n${t}`:t,revision:e.revision+1})),d(void 0),window.setTimeout(()=>f.current?.focus(),0)},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&&!m.trim()&&h.length===0,x=n&&!c;return(0,j.jsx)(`div`,{className:`border-t border-border bg-background pb-[env(safe-area-inset-bottom)]`,children:(0,j.jsxs)(`div`,{className:`mx-auto max-w-3xl px-5 py-4`,children:[(0,j.jsx)(`input`,{ref:p,type:`file`,multiple:!0,className:`hidden`,onChange:e=>{v(e.target.files?Array.from(e.target.files):[]),e.target.value=``}}),(0,j.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:A(`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:[h.length>0&&(0,j.jsx)(`div`,{className:`flex flex-wrap gap-2`,children:h.map((e,t)=>(0,j.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,j.jsx)(T,{className:`size-3`})]},`${e.name}-${t}`))}),(0,j.jsxs)(`div`,{className:`flex items-end gap-2`,children:[(0,j.jsx)(M,{type:`button`,size:`sm`,variant:`ghost`,onClick:()=>p.current?.click(),"aria-label":`attach`,className:`text-muted-foreground hover:text-foreground`,children:(0,j.jsx)(Ve,{className:`size-4`})}),(0,j.jsx)(It,{onPick:_}),(0,j.jsx)(`textarea`,{ref:f,value:m,onChange:e=>{d(void 0),a(t=>({...t,value:e.target.value,revision:t.revision+1}))},onPaste:e=>{let t=Array.from(e.clipboardData.files);t.length>0&&v(t)},onKeyDown:e=>{e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),g())},placeholder:`write to ${r}…`,rows:1,autoFocus:!0,className:`min-h-8 flex-1 resize-none bg-transparent leading-8 text-foreground placeholder:text-muted-foreground focus:outline-none`}),(0,j.jsx)(M,{type:`button`,size:`sm`,onClick:x?t:()=>void g(),disabled:b,"aria-label":x?`stop`:`send`,className:`h-8 px-3`,children:x?(0,j.jsx)(ue,{className:`size-3 fill-current`,strokeWidth:0}):(0,j.jsx)(Se,{className:`size-4`})})]})]}),u?(0,j.jsx)(`p`,{className:`mt-1.5 text-center font-serif text-xs italic text-destructive`,children:u}):null,(0,j.jsx)(`p`,{className:`mt-1.5 text-center text-[11px] tracking-wide text-muted-foreground`,children:`enter to send · shift+enter for newline`})]})})}function Ht({...e}){return(0,j.jsx)(at,{"data-slot":`collapsible`,...e})}function Ut({...e}){return(0,j.jsx)(ne,{"data-slot":`collapsible-trigger`,...e})}function Wt({...e}){return(0,j.jsx)(b,{"data-slot":`collapsible-content`,...e})}function Gt({...e}){return(0,j.jsx)(w,{"data-slot":`sheet`,...e})}function Kt({...e}){return(0,j.jsx)(S,{"data-slot":`sheet-portal`,...e})}function qt({className:e,...t}){return(0,j.jsx)(x,{"data-slot":`sheet-overlay`,className:A(`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 Jt({className:e,children:t,side:n=`right`,showCloseButton:r=!0,...i}){return(0,j.jsxs)(Kt,{children:[(0,j.jsx)(qt,{}),(0,j.jsxs)(je,{"data-slot":`sheet-content`,"data-side":n,className:A(`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,j.jsx)(a,{"data-slot":`sheet-close`,asChild:!0,children:(0,j.jsxs)(M,{variant:`ghost`,className:`absolute top-3 right-3`,size:`icon-sm`,children:[(0,j.jsx)(T,{}),(0,j.jsx)(`span`,{className:`sr-only`,children:`Close`})]})})]})]})}function Yt({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`sheet-header`,className:A(`flex flex-col gap-0.5 p-4`,e),...t})}function Xt({className:e,...t}){return(0,j.jsx)(m,{"data-slot":`sheet-title`,className:A(`font-heading text-base font-medium text-foreground`,e),...t})}function Zt({className:e,...t}){return(0,j.jsx)(be,{"data-slot":`radio-group`,className:A(`grid w-full gap-2`,e),...t})}function Qt({className:e,...t}){return(0,j.jsx)(Ze,{"data-slot":`radio-group-item`,className:A(`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,j.jsx)(Pe,{"data-slot":`radio-group-indicator`,className:`flex size-4 items-center justify-center`,children:(0,j.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 $t({className:e,...t}){return(0,j.jsx)(Te,{"data-slot":`label`,className:A(`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 en({models:e,added:t,current:n,source:r,disabled:i,onChange:a,onAdd:o,onRemove:s}){let[c,l]=(0,k.useState)(``),[u,d]=(0,k.useState)(!1),[f,p]=(0,k.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,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(Zt,{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,j.jsxs)($t,{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,j.jsx)(Qt,{value:e,id:t}),(0,j.jsxs)(`span`,{className:`min-w-0 flex-1 font-mono text-sm leading-tight`,children:[(0,j.jsx)(`span`,{className:r?`text-primary-foreground/70`:`text-muted-foreground group-hover/row:text-foreground`,children:o}),(0,j.jsx)(`span`,{className:r?`text-primary-foreground/70`:`text-muted-foreground group-hover/row:text-foreground`,children:`/`}),(0,j.jsx)(`span`,{className:r?`text-primary-foreground`:`text-muted-foreground group-hover/row:text-foreground`,children:c})]}),a?(0,j.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,j.jsx)(T,{className:`size-3.5`})}):null]},e)})}),n&&r?(0,j.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,j.jsxs)(`form`,{onSubmit:h,className:`mt-4 flex items-center gap-2`,children:[(0,j.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,j.jsx)(M,{type:`submit`,variant:`outline`,size:`default`,disabled:u||i||!c.trim(),children:`add`})]}),f?(0,j.jsx)(`p`,{className:`mt-2 font-serif text-xs italic text-destructive`,children:f}):null]})}var tn=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`}}),nn=k.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,j.jsx)(Ge,{"data-slot":`toggle-group`,"data-variant":t,"data-size":n,"data-spacing":r,"data-orientation":i,style:{"--gap":r},className:A(`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,j.jsx)(nn.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=k.useContext(nn);return(0,j.jsx)(Re,{"data-slot":`toggle-group-item`,"data-variant":a.variant||n,"data-size":a.size||r,"data-spacing":a.spacing,className:A(`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`,tn({variant:a.variant||n,size:a.size||r}),e),...i,children:t})}var rn=[`off`,`minimal`,`low`,`medium`,`high`,`xhigh`];function an({current:e,supported:t,disabled:n,onChange:r}){let i=rn.filter(e=>t.includes(e)),a=i.length>0?i:rn,o=a.length<=1?`grid-cols-1`:a.length===2?`grid-cols-2`:`grid-cols-3`;return(0,j.jsx)(P,{type:`single`,value:e??``,onValueChange:e=>{e&&r(e)},disabled:n,className:A(`grid w-full items-stretch gap-1 rounded-md bg-muted/40 p-1`,o),children:a.map(e=>(0,j.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 on=`familiar.theme`;function sn(){return window.matchMedia(`(prefers-color-scheme: dark)`).matches}function I(){let e=localStorage.getItem(on);return e===`light`||e===`dark`||e===`auto`?e:`auto`}function cn(e){localStorage.setItem(on,e),L(e)}function L(e){let t=e===`dark`||e===`auto`&&sn();document.documentElement.classList.toggle(`dark`,t)}function ln(e){let t=window.matchMedia(`(prefers-color-scheme: dark)`),n=()=>{e()===`auto`&&L(`auto`)};return t.addEventListener(`change`,n),()=>t.removeEventListener(`change`,n)}var un=[`light`,`dark`,`auto`],dn={light:v,dark:Fe,auto:Qe},fn={light:`light`,dark:`dark`,auto:`system`};function pn(){let[e,t]=(0,k.useState)(()=>I());return(0,k.useEffect)(()=>{cn(e)},[e]),(0,j.jsx)(P,{type:`single`,value:e,onValueChange:e=>{e&&t(e)},spacing:1,className:`rounded-lg bg-muted/40 p-1`,children:un.map(e=>{let t=dn[e];return(0,j.jsxs)(F,{value:e,"aria-label":fn[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,j.jsx)(t,{className:`size-4`}),(0,j.jsx)(`span`,{children:fn[e]})]},e)})})}function R(e,t,n){let[r,i]=(0,k.useState)(e),[a,o]=(0,k.useState)(!1),[s,c]=(0,k.useState)(!1),l=(0,k.useRef)(!1);(0,k.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 mn=`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,j.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,j.jsx)(F,{value:`on`,"aria-label":`${n} on`,className:mn,children:`on`}),(0,j.jsx)(F,{value:`off`,"aria-label":`${n} off`,className:mn,children:`off`})]})}var hn=6e4;function gn({valueMs:e,disabled:t,onCommit:n}){let r=R(e===void 0?``:String(Math.round(e/hn)),t=>{let n=Number.parseInt(t,10);if(Number.isNaN(n)||n<1)return`reset`;let r=n*hn;return r===e?`reset`:{value:r}},n);return(0,j.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,j.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 _n=/^[^/\s]+\/[^\s]+$/;function vn({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?_n.test(t)?{value:t}:`invalid`:n?{value:``}:`reset`},i);return(0,j.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 yn({values:e,disabled:t,onChange:n}){let r=e?.[`heartbeat.enabled`].value,i=r===!0;return(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(z,{enabled:r,disabled:t,ariaPrefix:`heartbeat`,onChange:e=>void n(`heartbeat.enabled`,e)}),(0,j.jsxs)(`div`,{className:`mt-4 grid gap-4`,children:[(0,j.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,j.jsx)(`span`,{className:`flex-1 font-serif text-sm text-foreground`,children:`first wakeup after`}),(0,j.jsx)(gn,{valueMs:e?.[`heartbeat.idleThresholdMs`].value,disabled:t||!i,onCommit:e=>n(`heartbeat.idleThresholdMs`,e)}),(0,j.jsx)(`span`,{className:`w-14 font-serif text-xs italic text-muted-foreground`,children:`minutes`})]}),(0,j.jsx)(`p`,{className:`font-serif text-xs italic text-muted-foreground/70`,children:`minutes of silence before the first wakeup`})]}),(0,j.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,j.jsx)(`span`,{className:`flex-1 font-serif text-sm text-foreground`,children:`between wakeups`}),(0,j.jsx)(gn,{valueMs:e?.[`heartbeat.intervalMs`].value,disabled:t||!i,onCommit:e=>n(`heartbeat.intervalMs`,e)}),(0,j.jsx)(`span`,{className:`w-14 font-serif text-xs italic text-muted-foreground`,children:`minutes`})]}),(0,j.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,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(z,{enabled:r,disabled:t,ariaPrefix:`image generation`,onChange:e=>void n(`image_gen.enabled`,e)}),(0,j.jsxs)(`div`,{className:`mt-4 grid gap-4`,children:[(0,j.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,j.jsx)(`span`,{className:`font-serif text-sm text-foreground`,children:`primary model`}),(0,j.jsx)(vn,{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,j.jsx)(`p`,{className:`font-serif text-xs italic text-muted-foreground/70`,children:`format: provider/model-id`})]}),(0,j.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,j.jsx)(`span`,{className:`font-serif text-sm text-foreground`,children:`fallback model`}),(0,j.jsx)(vn,{value:e?.[`image_gen.fallback_model`].value,placeholder:`none`,allowEmpty:!0,disabled:i,onCommit:e=>n(`image_gen.fallback_model`,e)}),(0,j.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,j.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,j.jsxs)(`div`,{className:`flex items-center gap-3`,children:[(0,j.jsx)(`span`,{className:`flex-1 font-serif text-sm text-foreground`,children:e}),n]}),t?(0,j.jsx)(`p`,{className:`font-serif text-xs italic text-muted-foreground/70`,children:t}):null]})}function xn({children:e}){return(0,j.jsx)(`h4`,{className:`mb-4 font-serif text-base lowercase tracking-tight text-foreground`,children:e})}function Sn({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,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)(`section`,{children:[(0,j.jsx)(xn,{children:`compaction`}),(0,j.jsx)(z,{enabled:a,disabled:n,ariaPrefix:`compaction`,onChange:e=>void r(`memory.lcm.enabled`,e)}),(0,j.jsxs)(`div`,{className:`mt-4`,children:[(0,j.jsx)(Zt,{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,j.jsxs)($t,{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,j.jsx)(Qt,{value:e,id:t}),(0,j.jsxs)(`span`,{className:`min-w-0 flex-1 font-mono text-sm leading-tight`,children:[(0,j.jsx)(`span`,{className:n?`text-primary-foreground/70`:`text-muted-foreground group-hover/row:text-foreground`,children:r}),(0,j.jsx)(`span`,{className:n?`text-primary-foreground/70`:`text-muted-foreground group-hover/row:text-foreground`,children:`/`}),(0,j.jsx)(`span`,{className:n?`text-primary-foreground`:`text-muted-foreground group-hover/row:text-foreground`,children:a})]})]},e)})}),s===`override`?(0,j.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,j.jsx)(`p`,{className:`mt-2 font-serif text-xs italic text-muted-foreground/70`,children:`following your conversation model`}):null]}),(0,j.jsxs)(`div`,{className:`mt-4 grid gap-4`,children:[(0,j.jsx)(V,{label:`context threshold`,description:`fraction of context that triggers compaction`,children:(0,j.jsx)(B,{value:e?.[`memory.lcm.contextThreshold`].value,step:.05,min:0,max:1,disabled:c,onCommit:e=>r(`memory.lcm.contextThreshold`,e)})}),(0,j.jsx)(V,{label:`fresh tail count`,description:`most recent messages kept raw, never compacted`,children:(0,j.jsx)(B,{value:e?.[`memory.lcm.freshTailCount`].value,min:1,disabled:c,onCommit:e=>r(`memory.lcm.freshTailCount`,e)})}),(0,j.jsx)(V,{label:`leaf chunk tokens`,description:`max tokens of input per leaf summary`,children:(0,j.jsx)(B,{value:e?.[`memory.lcm.leafChunkTokens`].value,min:1,disabled:c,onCommit:e=>r(`memory.lcm.leafChunkTokens`,e)})}),(0,j.jsx)(V,{label:`leaf target tokens`,description:`target tokens per leaf summary output`,children:(0,j.jsx)(B,{value:e?.[`memory.lcm.leafTargetTokens`].value,min:1,disabled:c,onCommit:e=>r(`memory.lcm.leafTargetTokens`,e)})}),(0,j.jsx)(V,{label:`condense group size`,description:`how many summaries combine into one at the next level`,children:(0,j.jsx)(B,{value:e?.[`memory.lcm.condenseGroupSize`].value,min:1,disabled:c,onCommit:e=>r(`memory.lcm.condenseGroupSize`,e)})}),(0,j.jsx)(V,{label:`max summary depth`,description:`deepest level of recursive summary-of-summaries`,children:(0,j.jsx)(B,{value:e?.[`memory.lcm.maxSummaryDepth`].value,min:1,disabled:c,onCommit:e=>r(`memory.lcm.maxSummaryDepth`,e)})}),(0,j.jsx)(V,{label:`kept after /new`,description:`lowest summary depth kept after /new. -1 keeps full context, 0 keeps every summary.`,children:(0,j.jsx)(B,{value:e?.[`memory.lcm.newSessionRetainDepth`].value,min:-1,disabled:c,onCommit:e=>r(`memory.lcm.newSessionRetainDepth`,e)})})]})]}),(0,j.jsxs)(`section`,{className:`mt-8`,children:[(0,j.jsx)(xn,{children:`ambient`}),(0,j.jsx)(z,{enabled:e?.[`memory.ambient.enabled`].value,disabled:n,ariaPrefix:`ambient`,onChange:e=>void r(`memory.ambient.enabled`,e)}),(0,j.jsxs)(`div`,{className:`mt-4 grid gap-4`,children:[(0,j.jsx)(V,{label:`top k`,description:`how many memories to surface per query`,children:(0,j.jsx)(B,{value:e?.[`memory.ambient.topK`].value,min:1,disabled:l,onCommit:e=>r(`memory.ambient.topK`,e)})}),(0,j.jsx)(V,{label:`min query length`,description:`minimum query chars before recall fires`,children:(0,j.jsx)(B,{value:e?.[`memory.ambient.minQueryLength`].value,min:0,disabled:l,onCommit:e=>r(`memory.ambient.minQueryLength`,e)})}),(0,j.jsx)(V,{label:`throttle seconds`,description:`cooldown between recalls`,children:(0,j.jsx)(B,{value:e?.[`memory.ambient.throttleSeconds`].value,min:0,disabled:l,onCommit:e=>r(`memory.ambient.throttleSeconds`,e)})}),(0,j.jsx)(V,{label:`similarity weight`,description:`semantic match to your query`,children:(0,j.jsx)(B,{value:e?.[`memory.ambient.weightSimilarity`].value,step:.05,min:0,disabled:l,onCommit:e=>r(`memory.ambient.weightSimilarity`,e)})}),(0,j.jsx)(V,{label:`valence weight`,description:`emotional charge of the memory`,children:(0,j.jsx)(B,{value:e?.[`memory.ambient.weightValence`].value,step:.05,min:0,disabled:l,onCommit:e=>r(`memory.ambient.weightValence`,e)})}),(0,j.jsx)(V,{label:`recency weight`,description:`favors recent memories`,children:(0,j.jsx)(B,{value:e?.[`memory.ambient.weightRecency`].value,step:.05,min:0,disabled:l,onCommit:e=>r(`memory.ambient.weightRecency`,e)})}),(0,j.jsx)(V,{label:`intensity weight`,description:`favors strongly-felt memories`,children:(0,j.jsx)(B,{value:e?.[`memory.ambient.weightIntensity`].value,step:.05,min:0,disabled:l,onCommit:e=>r(`memory.ambient.weightIntensity`,e)})})]})]}),(0,j.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 H(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 Cn(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 wn(e){let t=new Date(e.lastSeenAt);return Number.isNaN(t.getTime())?0:t.getTime()}function Tn({currentDevice:e,onSignedOut:t}){let[n,r]=(0,k.useState)(e?[e]:[]),[i,a]=(0,k.useState)(!0),[o,s]=(0,k.useState)(),[c,l]=(0,k.useState)(),u=(0,k.useCallback)((e={})=>{e.showLoading&&(a(!0),l(void 0)),gt().then(e=>{r(e),l(void 0)}).catch(e=>{l(e instanceof Error?e.message:String(e))}).finally(()=>{a(!1)})},[]);(0,k.useEffect)(()=>{let e=window.setTimeout(()=>u(),0);return()=>window.clearTimeout(e)},[u]);let d=(0,k.useMemo)(()=>[...n].sort((e,t)=>e.current&&!t.current?-1:!e.current&&t.current?1:wn(t)-wn(e)),[n]),f=d.filter(e=>!e.current),p=async e=>{s(e.id),l(void 0);try{await _t(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 yt(),t()}catch(e){l(e instanceof Error?e.message:String(e))}finally{s(void 0)}},h=async()=>{s(`others`),l(void 0);try{await vt(),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,j.jsxs)(`div`,{className:`grid gap-3`,children:[(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,j.jsxs)(M,{type:`button`,variant:`outline`,size:`sm`,onClick:()=>void m(),disabled:!!o,className:`gap-2`,children:[(0,j.jsx)(Ue,{className:`size-3.5`}),`logout`]}),(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`sm`,onClick:()=>void h(),disabled:!!o||f.length===0,children:`sign out others`})]}),(0,j.jsxs)(`div`,{className:`grid gap-2`,children:[d.map(e=>(0,j.jsx)(`div`,{className:A(`rounded-md border border-border bg-background px-3 py-2.5`,e.current&&`border-primary/50`),children:(0,j.jsxs)(`div`,{className:`flex items-start gap-3`,children:[(0,j.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,j.jsxs)(`div`,{className:`flex flex-wrap items-center gap-x-2 gap-y-1`,children:[(0,j.jsx)(`p`,{className:`truncate text-sm leading-tight text-foreground`,children:e.deviceName||`unnamed device`}),e.current?(0,j.jsx)(`span`,{className:`font-serif text-xs italic text-primary`,children:`current`}):null]}),(0,j.jsxs)(`p`,{className:`mt-1 font-serif text-xs italic text-muted-foreground`,children:[`last seen `,H(e.lastSeenAt)]}),(0,j.jsxs)(`p`,{className:`mt-1 text-xs leading-relaxed text-muted-foreground`,children:[`made `,H(e.createdAt),` · expires `,H(e.expiresAt)]}),(0,j.jsxs)(`p`,{className:`mt-1 truncate text-xs text-muted-foreground/80`,children:[e.lastIp??`ip unknown`,` · `,Cn(e.userAgent)]})]}),e.current?null:(0,j.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,j.jsx)(y,{className:`size-4`})})]})},e.id)),i?(0,j.jsx)(`p`,{className:`font-serif text-xs italic text-muted-foreground`,children:`checking devices…`}):null,!i&&d.length===0?(0,j.jsx)(`p`,{className:`font-serif text-xs italic text-muted-foreground`,children:`no devices found.`}):null]}),c?(0,j.jsx)(`p`,{className:`font-serif text-xs italic text-destructive`,children:c}):null]})}function En(){let e=(0,k.useRef)(!0);return(0,k.useEffect)(()=>(e.current=!0,()=>{e.current=!1}),[]),e}function Dn(){let e=En(),[t,n]=(0,k.useState)(void 0),[r,i]=(0,k.useState)(!1),[a,o]=(0,k.useState)(!1);return{error:t,isLoading:r,isMutating:a,run:(0,k.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 On(e){let[t,n]=(0,k.useState)(void 0),[r,i]=(0,k.useState)([]),[a,o]=(0,k.useState)([]),{error:s,isLoading:c,isMutating:l,run:u}=Dn(),d=(0,k.useCallback)(async()=>{e&&await u(()=>Promise.all([Et(e),Dt()]),{busy:`load`,apply:([e,t])=>{n(e),i(t.models),o(t.added)}})},[e,u]);(0,k.useEffect)(()=>{let e=window.setTimeout(()=>void d(),0);return()=>window.clearTimeout(e)},[d]);let f=(0,k.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(()=>At(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,k.useCallback)(e=>f({model:e}),[f]),setThinking:(0,k.useCallback)(e=>f({thinking:e}),[f]),addModel:(0,k.useCallback)(async e=>{await u(()=>Ot(e),{apply:e=>{i(e.models),o(e.added)},rethrow:!0})},[u]),removeModel:(0,k.useCallback)(async e=>{await u(()=>kt(e),{apply:e=>{i(e.models),o(e.added)},rethrow:!0})},[u]),refetch:d}}function kn(e){let[t,n]=(0,k.useState)(void 0),{error:r,isLoading:i,isMutating:a,run:o}=Dn(),s=(0,k.useCallback)(async()=>{e&&await o(()=>Nt(),{busy:`load`,apply:n})},[e,o]);return(0,k.useEffect)(()=>{let e=window.setTimeout(()=>void s(),0);return()=>window.clearTimeout(e)},[s]),{data:t,error:r,isLoading:i,isMutating:a,setConfig:(0,k.useCallback)(async(e,t)=>{await o(()=>Pt(e,t),{apply:n,rethrow:!0})},[o]),clearConfig:(0,k.useCallback)(async e=>{await o(()=>Ft(e),{apply:n,rethrow:!0})},[o]),refetch:s}}function U({title:e,description:t,icon:n,defaultOpen:r=!1,children:i}){let[a,o]=(0,k.useState)(r);return(0,j.jsxs)(Ht,{open:a,onOpenChange:o,children:[(0,j.jsxs)(Ut,{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,j.jsx)(n,{className:`mt-0.5 size-5 shrink-0 text-muted-foreground transition-colors group-hover:text-foreground`}),(0,j.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,j.jsx)(`span`,{className:`block font-serif text-base leading-tight tracking-tight text-foreground`,children:e}),(0,j.jsx)(`span`,{className:`mt-1 block text-xs leading-relaxed text-muted-foreground`,children:t})]}),(0,j.jsx)(E,{className:A(`size-4 shrink-0 text-muted-foreground transition-transform duration-150 group-hover:text-foreground`,a&&`rotate-90`)})]}),(0,j.jsx)(Wt,{children:(0,j.jsx)(`div`,{className:`px-2 pb-5`,children:(0,j.jsx)(`div`,{className:`mt-4`,children:i})})})]})}function W({children:e,className:t}){return(0,j.jsx)(`p`,{className:A(`px-2 pt-4 pb-1 font-serif text-xs italic text-muted-foreground`,t),children:e})}function An({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}=On(n),{data:g,error:_,isLoading:v,isMutating:y,setConfig:b,clearConfig:x}=kn(e),S=!!o&&!!g,C=u||d||v||y,w=l??_;return(0,j.jsx)(Gt,{open:e,onOpenChange:t,children:(0,j.jsxs)(Jt,{className:`w-screen bg-card shadow-2xl sm:w-md sm:max-w-md sm:rounded-l-2xl`,side:`right`,children:[(0,j.jsx)(Yt,{className:`px-6 pt-6 pb-2`,children:(0,j.jsx)(Xt,{className:`font-serif text-2xl leading-none tracking-tight text-foreground`,children:`settings`})}),(0,j.jsxs)(`div`,{className:`flex flex-col overflow-y-auto px-5 pt-1 pb-8`,children:[(0,j.jsx)(W,{className:`pt-1`,children:`conversation`}),(0,j.jsx)(U,{title:`model`,description:`which language model carries this conversation.`,icon:Ne,defaultOpen:!0,children:(0,j.jsx)(en,{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,j.jsx)(U,{title:`thinking`,description:`how long the model deliberates before answering.`,icon:ee,children:(0,j.jsx)(an,{current:o?.thinking.value,supported:o?.supportedThinking??[],disabled:!S||C,onChange:e=>void p(e)})}),(0,j.jsx)(W,{children:`companion`}),(0,j.jsx)(U,{title:`heartbeat`,description:`your companion's pulse when you've gone quiet.`,icon:pe,children:(0,j.jsx)(yn,{values:g?.values,disabled:!S||C,onChange:b})}),(0,j.jsx)(U,{title:`image generation`,description:`which model your companion uses to paint.`,icon:Ee,children:(0,j.jsx)(bn,{values:g?.values,disabled:!S||C,onChange:b})}),(0,j.jsx)(U,{title:`memory`,description:`how older conversation is condensed and how earlier memories return.`,icon:rt,children:(0,j.jsx)(Sn,{values:g?.values,models:s,disabled:!S||C,onChange:b,onClear:x})}),(0,j.jsx)(W,{children:`room`}),(0,j.jsx)(U,{title:`theme`,description:`light, dark, or follow your system.`,icon:ye,children:(0,j.jsx)(pn,{})}),r===`bearer`&&a?(0,j.jsx)(U,{title:`devices`,description:`where this web room is still open.`,icon:xe,children:(0,j.jsx)(Tn,{currentDevice:i,onSignedOut:a})}):null,w?(0,j.jsx)(`p`,{className:`mt-4 font-serif text-xs italic text-destructive`,children:w}):null]})]})})}function jn({...e}){return(0,j.jsx)(C,{"data-slot":`alert-dialog`,...e})}function Mn({...e}){return(0,j.jsx)(u,{"data-slot":`alert-dialog-portal`,...e})}function Nn({className:e,...t}){return(0,j.jsx)(f,{"data-slot":`alert-dialog-overlay`,className:A(`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 Pn({className:e,size:t=`default`,...n}){return(0,j.jsxs)(Mn,{children:[(0,j.jsx)(Nn,{}),(0,j.jsx)(tt,{"data-slot":`alert-dialog-content`,"data-size":t,className:A(`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 Fn({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`alert-dialog-header`,className:A(`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 In({className:e,...t}){return(0,j.jsx)(`div`,{"data-slot":`alert-dialog-footer`,className:A(`-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 Ln({className:e,...t}){return(0,j.jsx)(Me,{"data-slot":`alert-dialog-title`,className:A(`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 Rn({className:e,...t}){return(0,j.jsx)(ae,{"data-slot":`alert-dialog-description`,className:A(`text-sm text-balance text-muted-foreground md:text-pretty *:[a]:underline *:[a]:underline-offset-3 *:[a]:hover:text-foreground`,e),...t})}function zn({className:e,variant:t=`default`,size:n=`default`,...r}){return(0,j.jsx)(M,{variant:t,size:n,asChild:!0,children:(0,j.jsx)(re,{"data-slot":`alert-dialog-action`,className:A(e),...r})})}function Bn({className:e,variant:t=`outline`,size:n=`default`,...r}){return(0,j.jsx)(M,{variant:t,size:n,asChild:!0,children:(0,j.jsx)(c,{"data-slot":`alert-dialog-cancel`,className:A(e),...r})})}function Vn({channelKey:e,onStarted:t}){let[n,r]=(0,k.useState)(!1),[i,a]=(0,k.useState)(!1),[o,s]=(0,k.useState)(void 0),c=async()=>{if(e){a(!0),s(void 0);try{await jt(e),r(!1),t()}catch(e){s(e instanceof Error?e.message:String(e))}finally{a(!1)}}};return(0,j.jsxs)(jn,{open:n,onOpenChange:e=>{i||r(e)},children:[(0,j.jsx)(M,{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,j.jsx)(le,{className:`size-4`})}),(0,j.jsxs)(Pn,{className:`bg-card`,children:[(0,j.jsxs)(Fn,{children:[(0,j.jsx)(Ln,{className:`font-serif text-xl tracking-tight`,children:`start fresh?`}),(0,j.jsx)(Rn,{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,j.jsx)(`p`,{className:`font-serif text-xs italic text-destructive`,children:o}):null,(0,j.jsxs)(In,{children:[(0,j.jsx)(Bn,{disabled:i,children:`cancel`}),(0,j.jsx)(zn,{onClick:e=>{e.preventDefault(),c()},disabled:i||!e,children:i?`starting…`:`start fresh`})]})]})]})}function Hn({...e}){return(0,j.jsx)(ge,{"data-slot":`dropdown-menu`,...e})}function Un({...e}){return(0,j.jsx)(nt,{"data-slot":`dropdown-menu-trigger`,...e})}function Wn({className:e,align:t=`start`,sideOffset:n=4,...r}){return(0,j.jsx)(it,{children:(0,j.jsx)(fe,{"data-slot":`dropdown-menu-content`,sideOffset:n,align:t,className:A(`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 Gn({className:e,inset:t,variant:n=`default`,...r}){return(0,j.jsx)($e,{"data-slot":`dropdown-menu-item`,"data-inset":t,"data-variant":n,className:A(`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 Kn(e){return e.label?e.label:e.scope===`dm`?`Main Chat`:e.channelName??e.channelId}function qn({sessions:e,activeKey:t,onSelect:n}){if(e.length<=1)return null;let r=e.find(e=>e.key===t);return(0,j.jsxs)(Hn,{children:[(0,j.jsxs)(Un,{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,j.jsx)(`span`,{className:`font-medium`,children:r?Kn(r):`select session`}),(0,j.jsx)(p,{className:`size-3 opacity-70`})]}),(0,j.jsx)(Wn,{align:`end`,className:`min-w-[180px]`,onCloseAutoFocus:e=>e.preventDefault(),children:e.map(e=>{let r=e.key===t;return(0,j.jsxs)(Gn,{onSelect:()=>n(e.key),className:`flex items-center justify-between gap-3`,children:[(0,j.jsx)(`span`,{className:A(`truncate`,r&&`font-medium`),children:Kn(e)}),r&&(0,j.jsx)(d,{className:`size-3.5 text-muted-foreground`})]},e.key)})})]})}var Jn={connecting:`connecting`,open:`online`,closed:`offline`,error:`error`},Yn={connecting:`reaching out…`,closed:`out of touch · trying again`,error:`out of touch · trying again`};function Xn({nav:e,connection:t,personaName:n,sessions:r,activeSessionKey:a,channelKey:o,onSelectSession:s,onOpenConfig:c,onNewChatStarted:l}){let u=t===`open`;return(0,j.jsx)(`header`,{className:`sticky top-0 z-10 border-b border-border bg-background px-3 py-3 md:px-5`,children:(0,j.jsxs)(`div`,{className:`mx-auto flex max-w-3xl items-center gap-3`,children:[e,(0,j.jsx)(`span`,{"aria-label":Jn[t],title:Jn[t],className:A(`size-2 rounded-full ring-3 ring-accent/60`,u?`bg-primary`:`bg-muted-foreground/40 ring-transparent`)}),(0,j.jsx)(`span`,{className:`font-serif text-lg leading-none tracking-tight`,children:n}),!u&&(0,j.jsx)(`span`,{className:`font-serif text-xs italic leading-none text-muted-foreground/80`,children:Yn[t]}),(0,j.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[(0,j.jsx)(qn,{sessions:r,activeKey:a,onSelect:s}),(0,j.jsx)(Vn,{channelKey:o,onStarted:l}),(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`settings`,title:`settings`,className:`size-8 text-muted-foreground hover:text-foreground`,onClick:c,children:(0,j.jsx)(i,{className:`size-4`})})]})]})})}function Zn({src:e,alt:t,className:n}){return(0,j.jsxs)(w,{children:[(0,j.jsx)(_,{asChild:!0,children:(0,j.jsx)(`button`,{type:`button`,className:A(`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,j.jsx)(`img`,{src:e,alt:t,loading:`lazy`,className:`max-h-72 max-w-[24rem] rounded-md`})})}),(0,j.jsxs)(S,{children:[(0,j.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,j.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,j.jsx)(m,{className:`sr-only`,children:t}),(0,j.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,j.jsxs)(`div`,{className:`fixed top-3 right-3 flex gap-1 sm:top-4 sm:right-4`,children:[(0,j.jsx)(M,{asChild:!0,type:`button`,variant:`ghost`,size:`icon-sm`,title:`open original`,"aria-label":`open original`,children:(0,j.jsx)(`a`,{href:e,target:`_blank`,rel:`noopener noreferrer`,children:(0,j.jsx)(_e,{className:`size-4`})})}),(0,j.jsx)(a,{asChild:!0,children:(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`icon-sm`,title:`close preview`,"aria-label":`close preview`,children:(0,j.jsx)(T,{className:`size-4`})})})]})]})]})]})}var Qn=/\.(?:jpe?g|png|gif|webp)(?:\?[^\s]*)?$/i,$n=/meme:\s*([^\n]*?)\s*\((https?:\/\/[^\s)<>"']+)\)|(https?:\/\/[^\s)<>"']+)/gi;function er(e){return{type:`text`,value:e}}function tr(e,t=``){return{type:`image`,url:e,alt:t}}function nr(e){return Qn.test(e)}function rr(e,t){let n=t.replace(/[ \t]+$/,``).replace(/\n{2,}$/,`
|
|
2
|
+
`);n.trim()&&e.push(er(n))}function ir(e){let t=[],n=0;for(let r of e.matchAll($n)){let i=r.index??0,a=r[2],o=r[3],s=a??o;!s||!a&&!nr(s)||(i>n&&rr(t,e.slice(n,i)),t.push(tr(s,a?(r[1]??``).trim():``)),n=i+r[0].length)}if(t.length!==0)return n<e.length&&rr(t,e.slice(n).replace(/^\n+/,``)),t}function ar(e){let t=e.children[0];return e.title==null&&e.children.length===1&&t?.type===`text`&&t.value===e.url&&nr(e.url)}function or(e,t,n){e.children.splice(t,1,...n)}function sr(){return e=>{ot(e,`link`,(e,t,n)=>(t===void 0||!n||ar(e)&&or(n,t,[tr(e.url)]),O)),ot(e,`text`,(e,t,n)=>{if(t===void 0||!n||n.type===`link`)return O;let r=ir(e.value);if(r)return or(n,t,r),[O,t+r.length]})}}var cr=[ct,sr],lr={a(e){let{node:t,href:n,children:r,...i}=e,a=n?!n.startsWith(`#`):!1;return(0,j.jsx)(`a`,{...i,href:n,target:a?`_blank`:void 0,rel:a?`noopener noreferrer`:void 0,children:r})},img(e){let{node:t,src:n,alt:r}=e;return typeof n!=`string`||!n?null:(0,j.jsx)(Zn,{src:n,alt:r??`image`})},table(e){let{node:t,...n}=e;return(0,j.jsx)(`div`,{className:`chat-markdown-table`,children:(0,j.jsx)(`table`,{...n})})}};function ur({text:e,streaming:t}){return(0,j.jsx)(`div`,{className:A(`warm-prose chat-markdown`,t&&`chat-markdown-streaming`),children:(0,j.jsx)(st,{remarkPlugins:cr,components:lr,children:e})})}var dr=(0,j.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,j.jsx)(`div`,{className:`warm-prose chat-markdown`,children:dr}):null;let i=(0,j.jsx)(ur,{text:e,streaming:n===!0});return r===`end`?(0,j.jsx)(`div`,{className:`flex min-w-0 flex-col items-end`,children:i}):i}function pr(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 mr({src:e,name:t,className:n}){let r=(0,k.useRef)(null),[i,a]=(0,k.useState)(!1),[o,s]=(0,k.useState)(0),[c,l]=(0,k.useState)(0);(0,k.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,j.jsxs)(`div`,{className:A(`flex w-full max-w-sm items-center gap-3 rounded-md bg-card px-3 py-2`,n),children:[(0,j.jsx)(`audio`,{ref:r,src:e,preload:`metadata`,children:(0,j.jsx)(`a`,{href:e,children:t??`audio`})}),(0,j.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,j.jsx)(he,{className:`size-4 fill-current`,strokeWidth:0}):(0,j.jsx)(Ke,{className:`size-4 fill-current translate-x-px`,strokeWidth:0})}),(0,j.jsxs)(`span`,{className:`shrink-0 whitespace-nowrap font-serif text-xs italic text-muted-foreground tabular-nums`,children:[pr(o),` / `,pr(c)]}),(0,j.jsx)(`input`,{type:`range`,min:0,max:c||0,step:.1,value:o,onChange:e=>d(Number(e.target.value)),"aria-label":`seek`,className:A(`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 hr(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 gr=[{match:e=>/^(web_)?search/.test(e)||/web/.test(e),icon:et},{match:e=>/^(read|cat|ls|view|list_files)/.test(e),icon:D},{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 _r(e){let t=e.toLowerCase();for(let e of gr)if(e.match(t))return e.icon;return ce}var vr=l;function yr(e){return!!e&&typeof e==`object`&&!Array.isArray(e)}function br(e){if(e==null)return``;if(typeof e==`string`)return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}var xr=[`query`,`url`,`command`,`prompt`,`file_path`,`path`,`pattern`,`description`];function Sr(e){if(!yr(e))return``;for(let t of xr){let n=e[t];if(typeof n==`string`&&n.trim())return n.trim()}return``}function Cr(e){if(e==null)return``;if(Array.isArray(e))return e.length===1?`1 item`:`${e.length} items`;if(yr(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(`
|
|
3
|
+
`).length;if(t>3)return`${t} lines`}return``}function wr(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 G(e){return e.kind===`thinking`?!e.complete:e.tool.status===`running`||e.tool.status===`pending`}function Tr(e){if(e.kind===`thinking`)return!!e.text;let t=e.tool;return!!(t.args||t.result||t.partialResult||t.error)}function Er(e){return e.kind===`tool`&&e.tool.status===`error`}function K({step:e,active:t,hideThreadAbove:n,hideThreadBelow:r}){let i=e===`done`?d:e.kind===`thinking`?vr:_r(e.tool.name);return(0,j.jsxs)(`div`,{className:`relative flex h-7 w-7 shrink-0 items-center justify-center`,"aria-hidden":!0,children:[(0,j.jsx)(`span`,{className:A(`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,j.jsx)(`span`,{className:`relative z-10 inline-flex size-4 items-center justify-center bg-muted`,children:(0,j.jsx)(i,{className:A(`size-4 transition-colors`,t?`text-primary`:`text-muted-foreground/85`)})})]})}function Dr({step:e}){if(e.kind===`thinking`)return(0,j.jsx)(`span`,{className:`truncate font-serif italic text-sm tracking-wide text-foreground/75`,children:wr(e)});let t=e.tool,n=Sr(t.args),r=t.status===`error`,i=t.status===`running`?t.partialResult:t.result,a=!r&&t.status===`completed`?Cr(i):``;return(0,j.jsxs)(`span`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,j.jsx)(`span`,{className:`shrink-0 font-mono text-sm text-foreground/85`,children:t.name}),n&&(0,j.jsx)(`span`,{className:`min-w-0 truncate font-mono text-sm text-muted-foreground/70`,children:n}),r&&(0,j.jsx)(`span`,{className:`shrink-0 font-serif italic text-sm text-destructive/80`,children:`· failed`}),a&&!r&&(0,j.jsxs)(`span`,{className:`shrink-0 font-serif italic text-sm tracking-wide text-muted-foreground/65`,children:[`· `,a]})]})}function Or({step:e,active:t}){return(0,j.jsxs)(`div`,{className:`font-serif italic text-sm leading-relaxed text-muted-foreground/85 whitespace-pre-wrap`,children:[e.text,t&&(0,j.jsx)(`span`,{className:`ml-0.5 inline-block animate-pulse`,children:`▎`})]})}function kr({tool:e}){let t=(0,k.useMemo)(()=>br(e.args),[e.args]),n=e.status===`running`?e.partialResult:e.result,r=(0,k.useMemo)(()=>br(n),[n]);return(0,j.jsxs)(`div`,{className:`space-y-2`,children:[t&&(0,j.jsx)(`pre`,{className:`overflow-x-auto whitespace-pre-wrap break-words font-mono text-xs text-muted-foreground/80`,children:t}),r&&(0,j.jsx)(`pre`,{className:`overflow-x-auto whitespace-pre-wrap break-words font-mono text-xs text-muted-foreground/80`,children:r}),e.error&&(0,j.jsx)(`div`,{className:`font-mono text-xs whitespace-pre-wrap text-destructive/85`,children:e.error})]})}var Ar=132;function jr({children:e}){let[t,n]=(0,k.useState)(!1),r=(0,k.useRef)(null),[i,a]=(0,k.useState)(!1);(0,k.useEffect)(()=>{let e=r.current;if(!e)return;let t=()=>a(e.scrollHeight>Ar+4);t();let n=new ResizeObserver(t);return n.observe(e),()=>n.disconnect()},[]);let o=i&&!t;return(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)(`div`,{className:`relative overflow-hidden`,style:{maxHeight:o?`${Ar}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,j.jsx)(`div`,{ref:r,children:e})}),i&&(0,j.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 Mr({step:e,threadContinues:t}){let n=G(e);return(0,j.jsxs)(`div`,{className:`relative py-1`,children:[t&&(0,j.jsx)(`span`,{className:`absolute left-3.5 inset-y-0 w-px -translate-x-1/2 bg-border`,"aria-hidden":!0}),(0,j.jsx)(`div`,{className:`ml-9 mt-1 mb-2`,children:(0,j.jsx)(jr,{children:e.kind===`thinking`?(0,j.jsx)(Or,{step:e,active:n}):(0,j.jsx)(kr,{tool:e.tool})})})]})}function Nr({steps:e,autoCollapse:t=!1}){let n=e.some(G),r=!n&&e.length>0&&e.length>=2&&!e.some(Er),[i,a]=(0,k.useState)(n),o=(0,k.useRef)(!1);(0,k.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=Tr(c),u=e.length-1,d=i&&(l||u>0||r);return(0,j.jsxs)(`div`,{className:`flex flex-col rounded-lg bg-muted px-3 py-2`,children:[(0,j.jsxs)(`button`,{type:`button`,onClick:s,"aria-expanded":i,className:`flex w-full items-center gap-2 text-left`,children:[(0,j.jsx)(K,{step:c,active:G(c),hideThreadAbove:!0,hideThreadBelow:!d}),(0,j.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,j.jsx)(Dr,{step:c}),!i&&u>0&&(0,j.jsxs)(`span`,{className:`shrink-0 font-serif italic text-sm tracking-wide text-muted-foreground/60`,children:[`· `,u,` more`]}),(0,j.jsx)(E,{className:A(`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,j.jsxs)(`div`,{children:[l&&(0,j.jsx)(Mr,{step:c,threadContinues:u>0||r}),e.slice(1).map((t,n)=>{let i=n+1===e.length-1,a=Tr(t),o=!i||r||a,s=!i||r;return(0,j.jsxs)(`div`,{className:`flex flex-col`,children:[(0,j.jsxs)(`div`,{className:`flex w-full items-center gap-2`,children:[(0,j.jsx)(K,{step:t,active:G(t),hideThreadBelow:!o}),(0,j.jsx)(Dr,{step:t})]}),a&&(0,j.jsx)(Mr,{step:t,threadContinues:s})]},t.id)}),r&&(0,j.jsxs)(`div`,{className:`flex w-full items-center gap-2`,children:[(0,j.jsx)(K,{step:`done`,hideThreadBelow:!0}),(0,j.jsx)(`span`,{className:`font-mono text-sm text-foreground/85`,children:`done`})]})]})]})}function Pr({text:e}){return(0,j.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,j.jsx)(`span`,{className:`font-serif italic text-sm tracking-wide text-destructive/85`,children:`lost somewhere between us`}),(0,j.jsx)(`div`,{className:`mt-1.5 h-px bg-destructive/15`}),(0,j.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 Fr=`[[FAMILIAR_SILENT]]`;function Ir({step:e,who:t,showLabel:n}){let r=!e.complete,i=e.text.startsWith(Fr);return(0,j.jsxs)(`div`,{className:`flex w-full flex-col`,children:[n&&t&&(0,j.jsx)(`span`,{className:`mt-2 mb-1 block text-xs uppercase tracking-wider text-muted-foreground`,children:t}),i?(0,j.jsx)(`p`,{className:`font-serif italic text-sm leading-relaxed text-muted-foreground/70`,children:`they kept quiet.`}):fr(e.text,{trailingCursor:r})]})}function Lr(e){return e.kind===`thinking`||e.kind===`text`?e.complete===!0:e.kind===`error`?!0:e.tool.status===`completed`||e.tool.status===`error`}function Rr({message:e}){let{steps:t,silent:n,who:r}=e,i=hr(t),a=i.findIndex(e=>e.kind===`text`)>=0,o=n===!0&&!a&&!!r,s=t.length>0&&t.every(Lr)&&(n===!0||a);return(0,j.jsxs)(`div`,{className:`flex w-full flex-col gap-1`,children:[o&&(0,j.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,j.jsx)(Nr,{steps:e.steps,autoCollapse:s},`stream-${t}`);if(e.kind===`error`)return(0,j.jsx)(Pr,{text:e.step.text},e.step.id);let n=i[t-1],a=!n||n.kind!==`text`;return(0,j.jsx)(Ir,{step:e.step,who:r,showLabel:a},e.step.id)}),n&&!a&&(0,j.jsx)(`p`,{className:`font-serif italic text-sm leading-relaxed text-muted-foreground/70`,children:`they kept quiet.`})]})}function zr({derived:e}){return(0,j.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,j.jsxs)(`span`,{children:[e.label,`: `]}):null,e.text]})}function Br(e){if(e.url)return e.kind===`image`||e.mimeType?.startsWith(`image/`)?{content:(0,j.jsx)(Zn,{src:e.url,alt:e.name})}:e.mimeType?.startsWith(`video/`)?{content:(0,j.jsx)(`div`,{className:`w-full max-w-[24rem]`,children:(0,j.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,j.jsx)(`div`,{className:`max-w-full`,children:(0,j.jsx)(mr,{src:e.url,name:e.name})})}:{align:`right`,content:(0,j.jsx)(`a`,{href:e.url,className:`text-sm italic text-muted-foreground underline-offset-4 hover:underline`,children:e.name})}}function Vr({attachment:e}){let t=Br(e);return t?(0,j.jsxs)(`div`,{className:A(`max-w-full`,t.align===`right`&&`text-right`),children:[t.content,e.derivedText?(0,j.jsx)(zr,{derived:e.derivedText}):null]}):null}function Hr({attachments:e,align:t}){return e.length===0?null:(0,j.jsx)(`div`,{className:A(`mt-2 flex flex-col gap-2`,t===`right`&&`items-end`),children:e.map(e=>(0,j.jsx)(Vr,{attachment:e},e.id))})}function Ur({message:e}){let t=e.steps.filter(e=>e.kind===`text`).map(e=>e.kind===`text`?e.text:``).join(``);return(0,j.jsxs)(`div`,{className:`flex w-full flex-col items-end gap-1`,children:[(0,j.jsx)(`span`,{className:`text-xs uppercase tracking-wider text-muted-foreground`,children:e.who}),(0,j.jsxs)(`div`,{className:`flex min-w-0 max-w-[85%] flex-col items-end`,children:[t&&fr(t,{align:`end`}),(0,j.jsx)(Hr,{attachments:e.attachments??[],align:`right`})]})]})}function Wr({message:e}){let t=e.steps.find(e=>e.kind===`text`);return!t||t.kind!==`text`?null:(0,j.jsx)(`div`,{className:`flex justify-center`,children:(0,j.jsx)(`p`,{className:`text-xs italic text-muted-foreground`,children:t.text})})}function q({icon:e,label:t,onClick:n,hoverClass:r}){return(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`sm`,onClick:n,"aria-label":t,title:t,className:A(`h-7 px-2 text-muted-foreground opacity-70 transition-opacity group-hover:opacity-100`,r),children:(0,j.jsx)(e,{className:`size-3.5`})})}var Gr=(0,k.memo)(function({message:e,onRetry:t,onDelete:n}){let[r,i]=(0,k.useState)(!1);return e.role===`system`?(0,j.jsx)(Wr,{message:e}):e.role===`user`?(0,j.jsx)(Ur,{message:e}):(0,j.jsxs)(`div`,{className:`group flex w-full flex-col`,onPointerDown:e=>{e.pointerType!==`mouse`&&i(!0)},children:[(0,j.jsx)(Rr,{message:e}),(0,j.jsx)(Hr,{attachments:e.attachments??[],align:`left`}),(t||n)&&(0,j.jsxs)(`div`,{className:A(`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,j.jsx)(q,{icon:Xe,label:`retry latest reply`,onClick:t,hoverClass:`hover:text-foreground`}),n&&(0,j.jsx)(q,{icon:y,label:`delete latest reply`,onClick:n,hoverClass:`hover:text-destructive`})]})]})}),Kr=1800*1e3;function qr(e,t){return e.getFullYear()===t.getFullYear()&&e.getMonth()===t.getMonth()&&e.getDate()===t.getDate()}function Jr(e,t){let n=new Date(e),r=new Date(t),i=n.toLocaleTimeString([],{hour:`numeric`,minute:`2-digit`}).toLowerCase();if(qr(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 Yr({messages:e,personaName:t,historyLoaded:n,streaming:r=!1,onRetry:i,onDelete:a}){let o=(0,k.useRef)(null),s=r?-1:e.findLastIndex(e=>e.role===`assistant`);return(0,k.useEffect)(()=>{o.current?.scrollIntoView({behavior:r?`auto`:`smooth`,block:`end`})},[e,r]),n&&e.length===0?(0,j.jsx)(`div`,{className:`mx-auto flex h-full max-w-3xl items-center justify-center px-5`,children:(0,j.jsxs)(`p`,{className:`font-serif text-base italic leading-relaxed text-muted-foreground/80`,children:[`hi, i'm `,t,`. write whenever.`]})}):(0,j.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,j.jsxs)(`div`,{className:`flex flex-col gap-5`,children:[r!=null&&t.ts-r.ts>=Kr&&(0,j.jsx)(`div`,{className:`flex justify-center pt-2`,children:(0,j.jsx)(`span`,{className:`font-serif italic text-xs text-muted-foreground/70 tracking-wide`,children:Jr(t.ts,r.ts)})}),(0,j.jsx)(Gr,{message:t,onRetry:n===s?i:void 0,onDelete:n===s?a:void 0})]},t.id)}),(0,j.jsx)(`div`,{ref:o})]})}var Xr=1e3,Zr=15e3;function J(){return typeof crypto<`u`&&`randomUUID`in crypto?crypto.randomUUID():`${Date.now()}-${Math.random().toString(36).slice(2)}`}function Qr(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 Y(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 $r(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=Y(e,r),a={kind:`thinking`,id:J(),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=Y(e,r),o={kind:`text`,id:J(),text:n};return[...a,o]}function ei(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:Qr(n.tool,t)},a=e.slice();return a[r]=i,a}let i=Y(e,n),a={kind:`tool`,id:t.id,tool:t};return[...i,a]}function ti(){let[e,t]=(0,k.useState)([]),[n,r]=(0,k.useState)(`connecting`),[i,a]=(0,k.useState)(`Familiar`),[o,s]=(0,k.useState)([]),[c,l]=(0,k.useState)(void 0),[u,d]=(0,k.useState)(!1),[f,p]=(0,k.useState)(!1),m=(0,k.useRef)(null),h=(0,k.useRef)(null),g=(0,k.useRef)(async()=>void 0),_=(0,k.useRef)(new Set),v=(0,k.useCallback)((e,n)=>{t(t=>t.map(t=>t.id===e?{...t,steps:n(t.steps)}:t))},[]),y=(0,k.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=>$r(n,e.part,e.content,t));break}case`tool_event`:{let t=Date.now();v(e.messageId,n=>ei(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:Y(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:[...Y(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:J(),role:`system`,who:``,steps:[{kind:`text`,id:J(),text:`error · ${e.code}: ${e.message}`,complete:!0}],ts:e.ts}]);break;case`replay_window_lost`:xt(c).then(e=>t(e.messages)).catch(()=>void 0);break}},[c,i,v]),b=(0,k.useRef)(y);(0,k.useEffect)(()=>{b.current=y},[y]),(0,k.useEffect)(()=>{let e=!1;return pt().then(t=>{e||a(t.personaName)}).catch(()=>void 0),bt().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,k.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);xt(c).then(n=>{e||(t(n.messages),d(!0))}).catch(()=>{e||d(!0)});let s=()=>{if(e)return;r(`connecting`);let t=new WebSocket(Tt(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(Zr,Xr*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 wt(n,J(),c,t)},()=>{e=!0,clearTimeout(o),a&&clearTimeout(a),h.current===n&&(h.current=null),n?.close()}},[c]);let x=(0,k.useCallback)((e,t=[])=>g.current(e,t),[]),S=(0,k.useCallback)(e=>l(e),[]),C=(0,k.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,k.useCallback)(()=>{C(`abort`)},[C]),retry:(0,k.useCallback)(()=>{C(`retry`)},[C]),deleteLatest:(0,k.useCallback)(()=>{C(`delete`)},[C]),notifyNewChat:(0,k.useCallback)(()=>{t(e=>[...e,{id:J(),role:`system`,who:``,steps:[{kind:`text`,id:J(),text:`started fresh`,complete:!0}],ts:Date.now()}])},[])}}function ni({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,k.useState)(!1);return(0,j.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-background text-foreground antialiased`,children:[(0,j.jsx)(Xn,{nav:e,connection:a,personaName:o,sessions:s,activeSessionKey:c,channelKey:c,onSelectSession:d,onOpenConfig:()=>v(!0),onNewChatStarted:g}),(0,j.jsx)(`main`,{className:`flex-1 overflow-y-auto`,children:(0,j.jsx)(Yr,{messages:i,personaName:o,historyLoaded:l,streaming:u,onRetry:m,onDelete:h})}),(0,j.jsx)(Vt,{onSend:f,onAbort:p,streaming:u,personaName:o}),(0,j.jsx)(An,{open:_,onOpenChange:v,channelKey:c,authMode:t,authDevice:n,onSignedOut:r})]})}function X(e){let t=new Date(`${e}T00:00:00`);return Number.isNaN(t.getTime())?null:t}function ri(e){let t=X(e);return t?new Intl.DateTimeFormat(void 0,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`}).format(t).toLowerCase():e}function ii(e){let t=X(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=X(e);if(!t)return null;let n=new Date;return n.setHours(0,0,0,0),Math.round((n.getTime()-t.getTime())/864e5)}function oi(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 si(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 ci({diary:e,active:t,onSelect:n}){let{weekday:r,day:i,month:a}=ii(e.date),o=ai(e.date)===0;return(0,j.jsxs)(`button`,{type:`button`,onClick:n,"aria-current":t?`page`:void 0,className:A(`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,j.jsxs)(`span`,{className:`flex w-10 shrink-0 flex-col items-center font-serif leading-none`,children:[(0,j.jsx)(`span`,{className:A(`text-[0.6875rem] tracking-wide`,t?`text-primary-foreground/70`:`text-muted-foreground`),children:r}),(0,j.jsx)(`span`,{className:`mt-0.5 text-2xl tabular-nums`,children:i}),(0,j.jsx)(`span`,{className:A(`mt-0.5 text-[0.6875rem] tracking-wide`,t?`text-primary-foreground/70`:`text-muted-foreground`),children:a})]}),(0,j.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,j.jsxs)(`span`,{className:`flex items-center gap-1.5`,children:[(0,j.jsx)(`span`,{className:`block truncate font-serif text-sm leading-tight tracking-tight`,children:e.title}),o?(0,j.jsx)(`span`,{className:A(`size-1.5 shrink-0 rounded-full`,t?`bg-primary-foreground/70`:`bg-primary`),"aria-hidden":!0}):null]}),e.excerpt?(0,j.jsx)(`span`,{className:A(`mt-1.5 line-clamp-2 text-xs leading-relaxed`,t?`text-primary-foreground/85`:`text-muted-foreground`),children:e.excerpt}):null]})]})}function li({content:e,title:t}){let n=(0,k.useMemo)(()=>ui(e,t),[e,t]);return n.length===0?(0,j.jsx)(`p`,{className:`font-serif text-sm italic text-muted-foreground`,children:`this day is quiet.`}):(0,j.jsx)(`div`,{className:`warm-prose diary-prose`,children:n})}function ui(e,t){let n=[],r=[],i=[],a,o=!1,s=()=>{let e=r.join(` `).trim();e&&n.push((0,j.jsx)(`p`,{children:Z(e)},n.length)),r.length=0},c=()=>{if(!a||i.length===0)return;let e=a;n.push((0,j.jsx)(e,{children:i.map((e,t)=>(0,j.jsx)(`li`,{children:Z(e)},t))},n.length)),i=[],a=void 0},l=()=>{s(),c()};for(let u of e.replace(/\r\n/g,`
|
|
4
|
+
`).split(`
|
|
5
|
+
`)){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&&fi(r)===fi(t)){o=!0;continue}o=!0;let i=e<=2?`h2`:`h3`;n.push((0,j.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,j.jsx)(`blockquote`,{children:Z(m[1]??``)},n.length));continue}di(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,j.jsx)(`code`,{children:a},t.length)):i[3]?t.push((0,j.jsx)(`strong`,{children:a},t.length)):t.push((0,j.jsx)(`em`,{children:a},t.length)),r=n+i[0].length}return r<e.length&&t.push(e.slice(r)),t}function di(e){return/^(?:[A-Z][A-Za-z ]{0,32}\s+)?\(?\d{1,2}:\d{2}\)?\s*[:.)-]/.test(e)}function fi(e){return e.replace(/`([^`]+)`/g,`$1`).replace(/\[([^\]]+)\]\([^)]+\)/g,`$1`).replace(/[*_~#>]/g,``).trim().toLowerCase()}function pi(){return(0,j.jsxs)(`div`,{className:`mt-2 space-y-3`,"aria-hidden":!0,children:[(0,j.jsx)(`div`,{className:`h-3 w-full rounded-sm bg-muted-foreground/10`}),(0,j.jsx)(`div`,{className:`h-3 w-11/12 rounded-sm bg-muted-foreground/10`}),(0,j.jsx)(`div`,{className:`h-3 w-4/5 rounded-sm bg-muted-foreground/10`}),(0,j.jsx)(`div`,{className:`h-3 w-2/3 rounded-sm bg-muted-foreground/10`})]})}function mi({summary:e,content:t,loading:n,settle:r}){if(!e)return(0,j.jsx)(`div`,{className:`flex h-full min-h-[18rem] items-center justify-center px-6 text-center`,children:(0,j.jsx)(`p`,{className:`font-serif text-sm italic text-muted-foreground`,children:`choose a written day.`})});let i=[oi(e.date),t===void 0?``:si(t)].filter(Boolean).join(` · `);return(0,j.jsxs)(`article`,{className:A(`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,j.jsxs)(`div`,{className:`mb-8 border-b border-border pb-6`,children:[(0,j.jsx)(`p`,{className:`font-serif text-sm italic text-muted-foreground`,children:ri(e.date)}),(0,j.jsx)(`h1`,{className:`mt-3 font-serif text-3xl leading-tight tracking-tight text-balance text-foreground`,children:e.title}),i?(0,j.jsx)(`p`,{className:`mt-3 font-serif text-xs italic text-muted-foreground`,children:i}):null]}),t===void 0?n?(0,j.jsx)(pi,{}):null:(0,j.jsx)(`div`,{className:`duration-300 ease-out-quart animate-in fade-in-0 motion-reduce:animate-none`,children:(0,j.jsx)(li,{content:t,title:e.title})})]},e.date)}function hi(){return(0,j.jsx)(`div`,{className:`grid gap-1 px-2 py-1`,children:Array.from({length:6},(e,t)=>(0,j.jsxs)(`div`,{className:`flex gap-3 rounded-md px-2 py-3`,children:[(0,j.jsxs)(`div`,{className:`flex w-10 shrink-0 flex-col items-center gap-1 pt-0.5`,children:[(0,j.jsx)(`div`,{className:`h-2 w-7 rounded-sm bg-muted-foreground/10`}),(0,j.jsx)(`div`,{className:`h-5 w-6 rounded-sm bg-muted-foreground/15`}),(0,j.jsx)(`div`,{className:`h-2 w-6 rounded-sm bg-muted-foreground/10`})]}),(0,j.jsxs)(`div`,{className:`min-w-0 flex-1 pt-0.5`,children:[(0,j.jsx)(`div`,{className:`h-3 w-2/3 rounded-sm bg-muted-foreground/15`}),(0,j.jsx)(`div`,{className:`mt-2.5 h-2 w-full rounded-sm bg-muted-foreground/10`}),(0,j.jsx)(`div`,{className:`mt-1.5 h-2 w-4/5 rounded-sm bg-muted-foreground/10`})]})]},t))})}function gi(){return(0,j.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,j.jsx)(`div`,{className:`rounded-md border border-border bg-card py-2`,children:(0,j.jsx)(hi,{})}),(0,j.jsxs)(`div`,{className:`rounded-md border border-border bg-card p-8`,children:[(0,j.jsx)(`div`,{className:`h-4 w-28 rounded-sm bg-muted-foreground/15`}),(0,j.jsx)(`div`,{className:`mt-6 h-8 w-64 rounded-sm bg-muted-foreground/10`}),(0,j.jsxs)(`div`,{className:`mt-8 space-y-3`,children:[(0,j.jsx)(`div`,{className:`h-3 w-full rounded-sm bg-muted-foreground/10`}),(0,j.jsx)(`div`,{className:`h-3 w-11/12 rounded-sm bg-muted-foreground/10`}),(0,j.jsx)(`div`,{className:`h-3 w-3/4 rounded-sm bg-muted-foreground/10`})]})]})]})}function _i({onRefresh:e}){return(0,j.jsx)(`div`,{className:`flex h-full min-h-[18rem] items-center justify-center px-6 text-center`,children:(0,j.jsxs)(`div`,{className:`max-w-sm`,children:[(0,j.jsx)(o,{className:`mx-auto size-7 text-muted-foreground`}),(0,j.jsx)(`h2`,{className:`mt-5 font-serif text-xl leading-tight tracking-tight`,children:`no written days yet`}),(0,j.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,j.jsxs)(M,{type:`button`,variant:`ghost`,className:`mt-5`,onClick:e,children:[(0,j.jsx)(ze,{className:`size-4`}),`check again`]})]})})}function vi({className:e,children:t,...n}){return(0,j.jsxs)(me,{"data-slot":`scroll-area`,className:A(`relative`,e),...n,children:[(0,j.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,j.jsx)(yi,{}),(0,j.jsx)(ke,{})]})}function yi({className:e,orientation:t=`vertical`,...n}){return(0,j.jsx)(Be,{"data-slot":`scroll-area-scrollbar`,"data-orientation":t,orientation:t,className:A(`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,j.jsx)(qe,{"data-slot":`scroll-area-thumb`,className:`relative flex-1 rounded-full bg-border`})})}function bi({nav:e}){let[t,n]=(0,k.useState)([]),[r,i]=(0,k.useState)(),[a,o]=(0,k.useState)(),[s,c]=(0,k.useState)(!0),[l,u]=(0,k.useState)(!1),[d,f]=(0,k.useState)(),[p,m]=(0,k.useState)(!1),[h,g]=(0,k.useState)(!1),_=(0,k.useCallback)(async()=>{c(!0),f(void 0);try{let e=await St();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,k.useCallback)(async e=>{u(!0),f(void 0);try{o(await Ct(e))}catch(e){f(e instanceof Error?e.message:String(e)),o(void 0)}finally{u(!1)}},[]);(0,k.useEffect)(()=>{let e=window.setTimeout(()=>void _(),0);return()=>window.clearTimeout(e)},[_]),(0,k.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,j.jsxs)(`div`,{className:`flex h-full min-h-0 flex-col bg-background text-foreground`,children:[(0,j.jsx)(`header`,{className:`border-b border-border bg-background px-3 py-3 md:px-8`,children:(0,j.jsxs)(`div`,{className:`mx-auto flex max-w-6xl items-center gap-3`,children:[e,(0,j.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,j.jsx)(`p`,{className:`font-serif text-2xl leading-tight tracking-tight`,children:`diaries`}),(0,j.jsx)(`p`,{className:`mt-0.5 font-serif text-xs italic text-muted-foreground`,children:`written days, kept close`})]}),(0,j.jsxs)(M,{type:`button`,variant:`ghost`,size:`sm`,className:`text-muted-foreground hover:text-foreground`,onClick:()=>void _(),disabled:s,children:[(0,j.jsx)(ze,{className:A(`size-4`,s&&`animate-spin`)}),`refresh`]})]})}),d?(0,j.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,j.jsx)(gi,{}):t.length===0?(0,j.jsx)(_i,{onRefresh:()=>void _()}):(0,j.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,j.jsx)(`aside`,{className:A(`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,j.jsx)(vi,{className:`min-h-0 flex-1`,children:(0,j.jsx)(`div`,{className:`grid gap-1 px-2`,children:t.map(e=>(0,j.jsx)(ci,{diary:e,active:e.date===r,onSelect:()=>{e.date!==r&&g(!0),i(e.date),m(!0)}},e.date))})})}),(0,j.jsxs)(`main`,{className:A(`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,j.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,j.jsx)(oe,{className:`size-3.5`}),`all days`]}),(0,j.jsx)(vi,{className:`min-h-0 flex-1`,children:(0,j.jsx)(mi,{summary:y,content:b,loading:l,settle:h})})]})]})]})}function xi({item:e,active:t,onClick:n}){let r=e.icon,i=e.enabled===!0;return(0,j.jsxs)(`button`,{type:`button`,onClick:n,disabled:!i,className:A(`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,j.jsx)(`span`,{className:`flex size-8 shrink-0 items-center justify-center rounded-md bg-background/55 text-current`,children:(0,j.jsx)(r,{className:`size-4`})}),(0,j.jsxs)(`span`,{className:`min-w-0`,children:[(0,j.jsx)(`span`,{className:`block text-sm leading-tight`,children:e.label}),(0,j.jsx)(`span`,{className:A(`mt-0.5 block truncate font-serif text-[11px] italic`,t?`text-primary-foreground/75`:`text-muted-foreground`),children:e.description})]})]})}function Si({items:e,selectedPage:t,onSelectPage:n}){let[r,i]=(0,k.useState)(!1);return(0,j.jsxs)(Ie,{open:r,onOpenChange:i,children:[(0,j.jsx)(De,{asChild:!0,children:(0,j.jsx)(M,{type:`button`,variant:`ghost`,size:`icon`,"aria-label":`pages`,title:`pages`,className:`text-muted-foreground hover:text-foreground`,children:(0,j.jsx)(Je,{className:`size-[1.125rem]`})})}),(0,j.jsx)(He,{children:(0,j.jsxs)(Ce,{side:`bottom`,align:`start`,sideOffset:8,collisionPadding:16,className:A(`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,j.jsxs)(`div`,{className:`px-3 pb-5`,children:[(0,j.jsx)(`p`,{className:`font-serif text-lg leading-tight tracking-tight`,children:`familiar`}),(0,j.jsx)(`p`,{className:`mt-1 font-serif text-xs italic text-muted-foreground`,children:`choose a room`})]}),(0,j.jsx)(`nav`,{className:`grid gap-2`,children:e.map(e=>(0,j.jsx)(xi,{item:e,active:t===e.id,onClick:()=>{e.enabled===!0&&(n(e.id),i(!1))}},e.id))})]})})]})}var Ci=[{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:D},{id:`gallery`,label:`gallery`,description:`pictures left behind`,icon:Oe}];function wi({authMode:e,authDevice:t,onSignedOut:n}){let[r,i]=(0,k.useState)(`chat`),[a,o]=(0,k.useState)(!1),s=r===`diaries`,c=(0,j.jsx)(Si,{items:Ci,selectedPage:r,onSelectPage:e=>{e===`diaries`&&o(!0),i(e)}});return(0,j.jsxs)(`div`,{className:`relative flex h-dvh bg-background text-foreground antialiased`,children:[(0,j.jsx)(`section`,{className:A(`min-w-0 flex-1 flex-col`,r===`chat`?`flex`:`hidden`),children:(0,j.jsx)(ni,{nav:c,authMode:e,authDevice:t,onSignedOut:n})}),a?(0,j.jsx)(`section`,{className:A(`min-w-0 flex-1 flex-col`,s?`flex`:`hidden`),children:(0,j.jsx)(bi,{nav:c})}):null]})}function Ti(){return typeof navigator>`u`?``:navigator.platform?.trim()||`this browser`}function Ei(){let[e,t]=(0,k.useState)({status:`loading`,personaName:`Familiar`});return(0,k.useEffect)(()=>{let e=!1;async function n(){try{let n=await pt();if(n.mode!==`bearer`){e||t({status:`chat`,mode:n.mode,personaName:n.personaName});return}let r=await mt();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,j.jsx)(wi,{authMode:e.mode,authDevice:e.device,onSignedOut:()=>{t({status:`login`,mode:`bearer`,personaName:e.personaName})}}):e.status===`login`?(0,j.jsx)(Di,{personaName:e.personaName,initialError:e.error,onLogin:n=>{t({status:`chat`,mode:`bearer`,personaName:e.personaName,device:n})}}):(0,j.jsx)(`div`,{className:`flex h-dvh items-center justify-center bg-background px-5 text-foreground antialiased`,children:(0,j.jsx)(`p`,{className:`font-serif text-sm italic text-muted-foreground`,children:`checking the door…`})})}function Di({personaName:e,initialError:t,onLogin:n}){let[r,i]=(0,k.useState)(``),[a,o]=(0,k.useState)(Ti),[s,c]=(0,k.useState)(t),[l,u]=(0,k.useState)(!1);return(0,j.jsx)(`div`,{className:`flex h-dvh flex-col bg-background text-foreground antialiased`,children:(0,j.jsx)(`main`,{className:`mx-auto flex w-full max-w-sm flex-1 flex-col justify-center px-5 py-10`,children:(0,j.jsxs)(`form`,{onSubmit:async e=>{e.preventDefault();let t=r.trim();if(t){u(!0),c(void 0);try{n(await ht(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,j.jsxs)(`div`,{className:`mb-5`,children:[(0,j.jsx)(`p`,{className:`font-serif text-2xl leading-tight tracking-tight`,children:e}),(0,j.jsx)(`p`,{className:`mt-2 font-serif text-xs italic text-muted-foreground`,children:`come in with your token.`})]}),(0,j.jsxs)(`label`,{className:`grid gap-2`,children:[(0,j.jsx)(`span`,{className:`font-serif text-xs italic text-muted-foreground`,children:`token`}),(0,j.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,j.jsxs)(`label`,{className:`mt-4 grid gap-2`,children:[(0,j.jsx)(`span`,{className:`font-serif text-xs italic text-muted-foreground`,children:`device name`}),(0,j.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,j.jsx)(`p`,{className:`mt-3 font-serif text-xs italic text-destructive`,children:s}):null,(0,j.jsxs)(M,{type:`submit`,className:`mt-5 h-9 w-full gap-2`,disabled:l||!r.trim(),children:[(0,j.jsx)(Le,{className:`size-4`}),(0,j.jsx)(`span`,{children:l?`checking`:`enter`})]})]})})})}var Q=Date.now(),$=6e4,Oi=[{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
|
|
6
|
+
`,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 ki(){return(0,j.jsxs)(`div`,{className:`flex h-dvh flex-col bg-background text-foreground antialiased`,children:[(0,j.jsxs)(`div`,{className:`border-b border-border px-5 py-3`,children:[(0,j.jsx)(`span`,{className:`font-serif text-lg text-foreground`,children:`ghost`}),(0,j.jsx)(`span`,{className:`ml-3 font-serif italic text-xs text-muted-foreground/70`,children:`playground · synthetic states`})]}),(0,j.jsx)(`main`,{className:`flex-1 overflow-y-auto`,children:(0,j.jsx)(Yr,{messages:Oi,personaName:`ghost`,historyLoaded:!0})})]})}function Ai(){return typeof window<`u`&&new URLSearchParams(window.location.search).has(`demo`)?(0,j.jsx)(ki,{}):(0,j.jsx)(Ei,{})}L(I()),ln(I),(0,lt.createRoot)(document.getElementById(`root`)).render((0,j.jsx)(k.StrictMode,{children:(0,j.jsx)(Ai,{})}));
|