draken 0.2.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/ACCEPTANCE.md +6 -3
- package/CHANGELOG.md +64 -0
- package/CONTRIBUTING.md +1 -1
- package/MEMORY.md +30 -8
- package/README.md +25 -9
- package/SETUP.md +2 -2
- package/SOURCES.md +1 -1
- package/VOICE.md +11 -3
- package/dist/db/schema.d.ts.map +1 -1
- package/dist/db/schema.js +6 -0
- package/dist/db/schema.js.map +1 -1
- package/dist/memory/automatic.d.ts +12 -6
- package/dist/memory/automatic.d.ts.map +1 -1
- package/dist/memory/automatic.js +65 -21
- package/dist/memory/automatic.js.map +1 -1
- package/dist/memory/context.d.ts +4 -4
- package/dist/memory/context.d.ts.map +1 -1
- package/dist/memory/context.js +64 -16
- package/dist/memory/context.js.map +1 -1
- package/dist/memory/embedding-pool.d.ts +1 -1
- package/dist/memory/embedding-pool.d.ts.map +1 -1
- package/dist/memory/embedding-pool.js +1 -1
- package/dist/memory/embedding-pool.js.map +1 -1
- package/dist/memory/index.d.ts +8 -2
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/memory/index.js +195 -37
- package/dist/memory/index.js.map +1 -1
- package/dist/memory/model-files.d.ts +9 -0
- package/dist/memory/model-files.d.ts.map +1 -0
- package/dist/memory/model-files.js +13 -0
- package/dist/memory/model-files.js.map +1 -0
- package/dist/memory/model.d.ts +1 -1
- package/dist/memory/model.d.ts.map +1 -1
- package/dist/memory/model.js +11 -16
- package/dist/memory/model.js.map +1 -1
- package/dist/memory/readiness.d.ts +16 -0
- package/dist/memory/readiness.d.ts.map +1 -0
- package/dist/memory/readiness.js +131 -0
- package/dist/memory/readiness.js.map +1 -0
- package/dist/memory/reconcile.d.ts +11 -0
- package/dist/memory/reconcile.d.ts.map +1 -0
- package/dist/memory/reconcile.js +132 -0
- package/dist/memory/reconcile.js.map +1 -0
- package/dist/memory/service.d.ts +4 -2
- package/dist/memory/service.d.ts.map +1 -1
- package/dist/memory/service.js +34 -8
- package/dist/memory/service.js.map +1 -1
- package/dist/memory/sources.d.ts +2 -2
- package/dist/memory/sources.d.ts.map +1 -1
- package/dist/memory/sources.js +12 -5
- package/dist/memory/sources.js.map +1 -1
- package/dist/memory/storage.d.ts.map +1 -1
- package/dist/memory/storage.js +9 -0
- package/dist/memory/storage.js.map +1 -1
- package/dist/memory/types.d.ts +22 -1
- package/dist/memory/types.d.ts.map +1 -1
- package/dist/memory/types.js.map +1 -1
- package/dist/memory/worker.js +4 -2
- package/dist/memory/worker.js.map +1 -1
- package/dist/routes/live-voice.d.ts.map +1 -1
- package/dist/routes/live-voice.js +7 -1
- package/dist/routes/live-voice.js.map +1 -1
- package/dist/routes/memory.d.ts.map +1 -1
- package/dist/routes/memory.js +12 -2
- package/dist/routes/memory.js.map +1 -1
- package/dist/routes/sync.d.ts.map +1 -1
- package/dist/routes/sync.js +44 -10
- package/dist/routes/sync.js.map +1 -1
- package/dist/sync/answer-references.d.ts +10 -0
- package/dist/sync/answer-references.d.ts.map +1 -0
- package/dist/sync/answer-references.js +47 -0
- package/dist/sync/answer-references.js.map +1 -0
- package/dist/sync/automatic.d.ts +7 -0
- package/dist/sync/automatic.d.ts.map +1 -0
- package/dist/sync/automatic.js +56 -0
- package/dist/sync/automatic.js.map +1 -0
- package/dist/sync/collector.d.ts +1 -1
- package/dist/sync/collector.d.ts.map +1 -1
- package/dist/sync/collector.js +109 -69
- package/dist/sync/collector.js.map +1 -1
- package/dist/sync/cost.d.ts +2 -1
- package/dist/sync/cost.d.ts.map +1 -1
- package/dist/sync/cost.js +10 -6
- package/dist/sync/cost.js.map +1 -1
- package/dist/sync/manager.d.ts +7 -1
- package/dist/sync/manager.d.ts.map +1 -1
- package/dist/sync/manager.js +104 -19
- package/dist/sync/manager.js.map +1 -1
- package/dist/sync/reconciliation.d.ts +16 -0
- package/dist/sync/reconciliation.d.ts.map +1 -0
- package/dist/sync/reconciliation.js +22 -0
- package/dist/sync/reconciliation.js.map +1 -0
- package/dist/sync/store.d.ts +8 -1
- package/dist/sync/store.d.ts.map +1 -1
- package/dist/sync/store.js +51 -5
- package/dist/sync/store.js.map +1 -1
- package/dist/sync/tree.d.ts.map +1 -1
- package/dist/sync/tree.js +13 -7
- package/dist/sync/tree.js.map +1 -1
- package/dist/sync/usage.d.ts +6 -0
- package/dist/sync/usage.d.ts.map +1 -0
- package/dist/sync/usage.js +91 -0
- package/dist/sync/usage.js.map +1 -0
- package/dist/types.d.ts +46 -2
- package/dist/types.d.ts.map +1 -1
- package/dist/voice/continuation.d.ts.map +1 -1
- package/dist/voice/continuation.js +1 -0
- package/dist/voice/continuation.js.map +1 -1
- package/dist/voice/history-focus.d.ts +14 -0
- package/dist/voice/history-focus.d.ts.map +1 -0
- package/dist/voice/history-focus.js +39 -0
- package/dist/voice/history-focus.js.map +1 -0
- package/dist/voice/live-context.d.ts +1 -1
- package/dist/voice/live-context.d.ts.map +1 -1
- package/dist/voice/live-context.js +3 -3
- package/dist/voice/live-context.js.map +1 -1
- package/dist/voice/live.d.ts.map +1 -1
- package/dist/voice/live.js +47 -33
- package/dist/voice/live.js.map +1 -1
- package/dist/voice/preparation.d.ts +8 -0
- package/dist/voice/preparation.d.ts.map +1 -0
- package/dist/voice/preparation.js +59 -0
- package/dist/voice/preparation.js.map +1 -0
- package/package.json +1 -1
- package/public/assets/index-BCDcSZkB.css +1 -0
- package/public/assets/index-SXgKBqZw.js +131 -0
- package/public/assets/{persona-XbLvCqRT.js → persona-BgbqhiLa.js} +1 -1
- package/public/index.html +3 -3
- package/public/persona/chat-avatar.webp +0 -0
- package/public/persona.html +3 -3
- package/voice/realtime/native.mjs +1 -1
- package/public/assets/index-CYz_kpAp.js +0 -126
- package/public/assets/index-DmRid5xE.css +0 -1
- /package/public/assets/{index-Ymd62i3g.js → index-S46UUaj8.js} +0 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
var Ss=Object.defineProperty;var ss=t=>{throw TypeError(t)};var Cs=(t,s,n)=>s in t?Ss(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n;var P=(t,s,n)=>Cs(t,typeof s!="symbol"?s+"":s,n),ts=(t,s,n)=>s.has(t)||ss("Cannot "+n);var f=(t,s,n)=>(ts(t,s,"read from private field"),n?n.call(t):s.get(t)),U=(t,s,n)=>s.has(t)?ss("Cannot add the same private member more than once"):s instanceof WeakSet?s.add(t):s.set(t,n),D=(t,s,n,a)=>(ts(t,s,"write to private field"),a?a.call(t,n):s.set(t,n),n);import{r as o,j as e,P as Es,R as _s,a as As}from"./index-S46UUaj8.js";/**
|
|
2
|
+
* @license lucide-react v0.468.0 - ISC
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the ISC license.
|
|
5
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/const Ts=t=>t.replace(/([a-z0-9])([A-Z])/g,"$1-$2").toLowerCase(),us=(...t)=>t.filter((s,n,a)=>!!s&&s.trim()!==""&&a.indexOf(s)===n).join(" ").trim();/**
|
|
7
|
+
* @license lucide-react v0.468.0 - ISC
|
|
8
|
+
*
|
|
9
|
+
* This source code is licensed under the ISC license.
|
|
10
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
11
|
+
*/var Ps={xmlns:"http://www.w3.org/2000/svg",width:24,height:24,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:2,strokeLinecap:"round",strokeLinejoin:"round"};/**
|
|
12
|
+
* @license lucide-react v0.468.0 - ISC
|
|
13
|
+
*
|
|
14
|
+
* This source code is licensed under the ISC license.
|
|
15
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
16
|
+
*/const Is=o.forwardRef(({color:t="currentColor",size:s=24,strokeWidth:n=2,absoluteStrokeWidth:a,className:i="",children:l,iconNode:r,...p},u)=>o.createElement("svg",{ref:u,...Ps,width:s,height:s,stroke:t,strokeWidth:a?Number(n)*24/Number(s):n,className:us("lucide",i),...p},[...r.map(([j,c])=>o.createElement(j,c)),...Array.isArray(l)?l:[l]]));/**
|
|
17
|
+
* @license lucide-react v0.468.0 - ISC
|
|
18
|
+
*
|
|
19
|
+
* This source code is licensed under the ISC license.
|
|
20
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
21
|
+
*/const M=(t,s)=>{const n=o.forwardRef(({className:a,...i},l)=>o.createElement(Is,{ref:l,iconNode:s,className:us(`lucide-${Ts(t)}`,a),...i}));return n.displayName=`${t}`,n};/**
|
|
22
|
+
* @license lucide-react v0.468.0 - ISC
|
|
23
|
+
*
|
|
24
|
+
* This source code is licensed under the ISC license.
|
|
25
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
26
|
+
*/const qs=M("ArrowLeft",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]);/**
|
|
27
|
+
* @license lucide-react v0.468.0 - ISC
|
|
28
|
+
*
|
|
29
|
+
* This source code is licensed under the ISC license.
|
|
30
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
31
|
+
*/const as=M("ArrowRight",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]);/**
|
|
32
|
+
* @license lucide-react v0.468.0 - ISC
|
|
33
|
+
*
|
|
34
|
+
* This source code is licensed under the ISC license.
|
|
35
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
36
|
+
*/const ps=M("ArrowUp",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]);/**
|
|
37
|
+
* @license lucide-react v0.468.0 - ISC
|
|
38
|
+
*
|
|
39
|
+
* This source code is licensed under the ISC license.
|
|
40
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
41
|
+
*/const Ms=M("AudioLines",[["path",{d:"M2 10v3",key:"1fnikh"}],["path",{d:"M6 6v11",key:"11sgs0"}],["path",{d:"M10 3v18",key:"yhl04a"}],["path",{d:"M14 8v7",key:"3a1oy3"}],["path",{d:"M18 5v13",key:"123xd1"}],["path",{d:"M22 10v3",key:"154ddg"}]]);/**
|
|
42
|
+
* @license lucide-react v0.468.0 - ISC
|
|
43
|
+
*
|
|
44
|
+
* This source code is licensed under the ISC license.
|
|
45
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
46
|
+
*/const Ds=M("Check",[["path",{d:"M20 6 9 17l-5-5",key:"1gmf2c"}]]);/**
|
|
47
|
+
* @license lucide-react v0.468.0 - ISC
|
|
48
|
+
*
|
|
49
|
+
* This source code is licensed under the ISC license.
|
|
50
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
51
|
+
*/const Rs=M("CircleAlert",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["line",{x1:"12",x2:"12",y1:"8",y2:"12",key:"1pkeuh"}],["line",{x1:"12",x2:"12.01",y1:"16",y2:"16",key:"4dfq90"}]]);/**
|
|
52
|
+
* @license lucide-react v0.468.0 - ISC
|
|
53
|
+
*
|
|
54
|
+
* This source code is licensed under the ISC license.
|
|
55
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
56
|
+
*/const Ls=M("ExternalLink",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"M10 14 21 3",key:"gplh6r"}],["path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6",key:"a6xqqp"}]]);/**
|
|
57
|
+
* @license lucide-react v0.468.0 - ISC
|
|
58
|
+
*
|
|
59
|
+
* This source code is licensed under the ISC license.
|
|
60
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
61
|
+
*/const $s=M("Headphones",[["path",{d:"M3 14h3a2 2 0 0 1 2 2v3a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-7a9 9 0 0 1 18 0v7a2 2 0 0 1-2 2h-1a2 2 0 0 1-2-2v-3a2 2 0 0 1 2-2h3",key:"1xhozi"}]]);/**
|
|
62
|
+
* @license lucide-react v0.468.0 - ISC
|
|
63
|
+
*
|
|
64
|
+
* This source code is licensed under the ISC license.
|
|
65
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
66
|
+
*/const Os=M("Keyboard",[["path",{d:"M10 8h.01",key:"1r9ogq"}],["path",{d:"M12 12h.01",key:"1mp3jc"}],["path",{d:"M14 8h.01",key:"1primd"}],["path",{d:"M16 12h.01",key:"1l6xoz"}],["path",{d:"M18 8h.01",key:"emo2bl"}],["path",{d:"M6 8h.01",key:"x9i8wu"}],["path",{d:"M7 16h10",key:"wp8him"}],["path",{d:"M8 12h.01",key:"czm47f"}],["rect",{width:"20",height:"16",x:"2",y:"4",rx:"2",key:"18n3k1"}]]);/**
|
|
67
|
+
* @license lucide-react v0.468.0 - ISC
|
|
68
|
+
*
|
|
69
|
+
* This source code is licensed under the ISC license.
|
|
70
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
71
|
+
*/const Us=M("Lock",[["rect",{width:"18",height:"11",x:"3",y:"11",rx:"2",ry:"2",key:"1w4ew1"}],["path",{d:"M7 11V7a5 5 0 0 1 10 0v4",key:"fwvmzm"}]]);/**
|
|
72
|
+
* @license lucide-react v0.468.0 - ISC
|
|
73
|
+
*
|
|
74
|
+
* This source code is licensed under the ISC license.
|
|
75
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
76
|
+
*/const zs=M("LogIn",[["path",{d:"M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4",key:"u53s6r"}],["polyline",{points:"10 17 15 12 10 7",key:"1ail0h"}],["line",{x1:"15",x2:"3",y1:"12",y2:"12",key:"v6grx8"}]]);/**
|
|
77
|
+
* @license lucide-react v0.468.0 - ISC
|
|
78
|
+
*
|
|
79
|
+
* This source code is licensed under the ISC license.
|
|
80
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
81
|
+
*/const Fs=M("LogOut",[["path",{d:"M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4",key:"1uf3rs"}],["polyline",{points:"16 17 21 12 16 7",key:"1gabdz"}],["line",{x1:"21",x2:"9",y1:"12",y2:"12",key:"1uyos4"}]]);/**
|
|
82
|
+
* @license lucide-react v0.468.0 - ISC
|
|
83
|
+
*
|
|
84
|
+
* This source code is licensed under the ISC license.
|
|
85
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
86
|
+
*/const ms=M("MessageSquare",[["path",{d:"M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z",key:"1lielz"}]]);/**
|
|
87
|
+
* @license lucide-react v0.468.0 - ISC
|
|
88
|
+
*
|
|
89
|
+
* This source code is licensed under the ISC license.
|
|
90
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
91
|
+
*/const Hs=M("MicOff",[["line",{x1:"2",x2:"22",y1:"2",y2:"22",key:"a6p6uj"}],["path",{d:"M18.89 13.23A7.12 7.12 0 0 0 19 12v-2",key:"80xlxr"}],["path",{d:"M5 10v2a7 7 0 0 0 12 5",key:"p2k8kg"}],["path",{d:"M15 9.34V5a3 3 0 0 0-5.68-1.33",key:"1gzdoj"}],["path",{d:"M9 9v3a3 3 0 0 0 5.12 2.12",key:"r2i35w"}],["line",{x1:"12",x2:"12",y1:"19",y2:"22",key:"x3vr5v"}]]);/**
|
|
92
|
+
* @license lucide-react v0.468.0 - ISC
|
|
93
|
+
*
|
|
94
|
+
* This source code is licensed under the ISC license.
|
|
95
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
96
|
+
*/const Bs=M("Mic",[["path",{d:"M12 2a3 3 0 0 0-3 3v7a3 3 0 0 0 6 0V5a3 3 0 0 0-3-3Z",key:"131961"}],["path",{d:"M19 10v2a7 7 0 0 1-14 0v-2",key:"1vc78b"}],["line",{x1:"12",x2:"12",y1:"19",y2:"22",key:"x3vr5v"}]]);/**
|
|
97
|
+
* @license lucide-react v0.468.0 - ISC
|
|
98
|
+
*
|
|
99
|
+
* This source code is licensed under the ISC license.
|
|
100
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
101
|
+
*/const Vs=M("PhoneOff",[["path",{d:"M10.68 13.31a16 16 0 0 0 3.41 2.6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7 2 2 0 0 1 1.72 2v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.42 19.42 0 0 1-3.33-2.67m-2.67-3.34a19.79 19.79 0 0 1-3.07-8.63A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91",key:"z86iuo"}],["line",{x1:"22",x2:"2",y1:"2",y2:"22",key:"11kh81"}]]);/**
|
|
102
|
+
* @license lucide-react v0.468.0 - ISC
|
|
103
|
+
*
|
|
104
|
+
* This source code is licensed under the ISC license.
|
|
105
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
106
|
+
*/const We=M("Phone",[["path",{d:"M22 16.92v3a2 2 0 0 1-2.18 2 19.79 19.79 0 0 1-8.63-3.07 19.5 19.5 0 0 1-6-6 19.79 19.79 0 0 1-3.07-8.67A2 2 0 0 1 4.11 2h3a2 2 0 0 1 2 1.72 12.84 12.84 0 0 0 .7 2.81 2 2 0 0 1-.45 2.11L8.09 9.91a16 16 0 0 0 6 6l1.27-1.27a2 2 0 0 1 2.11-.45 12.84 12.84 0 0 0 2.81.7A2 2 0 0 1 22 16.92z",key:"foiqr5"}]]);/**
|
|
107
|
+
* @license lucide-react v0.468.0 - ISC
|
|
108
|
+
*
|
|
109
|
+
* This source code is licensed under the ISC license.
|
|
110
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
111
|
+
*/const Ys=M("RefreshCw",[["path",{d:"M3 12a9 9 0 0 1 9-9 9.75 9.75 0 0 1 6.74 2.74L21 8",key:"v9h5vc"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}],["path",{d:"M21 12a9 9 0 0 1-9 9 9.75 9.75 0 0 1-6.74-2.74L3 16",key:"3uifl3"}],["path",{d:"M8 16H3v5",key:"1cv678"}]]);/**
|
|
112
|
+
* @license lucide-react v0.468.0 - ISC
|
|
113
|
+
*
|
|
114
|
+
* This source code is licensed under the ISC license.
|
|
115
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
116
|
+
*/const Gs=M("Settings",[["path",{d:"M12.22 2h-.44a2 2 0 0 0-2 2v.18a2 2 0 0 1-1 1.73l-.43.25a2 2 0 0 1-2 0l-.15-.08a2 2 0 0 0-2.73.73l-.22.38a2 2 0 0 0 .73 2.73l.15.1a2 2 0 0 1 1 1.72v.51a2 2 0 0 1-1 1.74l-.15.09a2 2 0 0 0-.73 2.73l.22.38a2 2 0 0 0 2.73.73l.15-.08a2 2 0 0 1 2 0l.43.25a2 2 0 0 1 1 1.73V20a2 2 0 0 0 2 2h.44a2 2 0 0 0 2-2v-.18a2 2 0 0 1 1-1.73l.43-.25a2 2 0 0 1 2 0l.15.08a2 2 0 0 0 2.73-.73l.22-.39a2 2 0 0 0-.73-2.73l-.15-.08a2 2 0 0 1-1-1.74v-.5a2 2 0 0 1 1-1.74l.15-.09a2 2 0 0 0 .73-2.73l-.22-.38a2 2 0 0 0-2.73-.73l-.15.08a2 2 0 0 1-2 0l-.43-.25a2 2 0 0 1-1-1.73V4a2 2 0 0 0-2-2z",key:"1qme2f"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);/**
|
|
117
|
+
* @license lucide-react v0.468.0 - ISC
|
|
118
|
+
*
|
|
119
|
+
* This source code is licensed under the ISC license.
|
|
120
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
121
|
+
*/const gs=M("Square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]]);/**
|
|
122
|
+
* @license lucide-react v0.468.0 - ISC
|
|
123
|
+
*
|
|
124
|
+
* This source code is licensed under the ISC license.
|
|
125
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
126
|
+
*/const Ks=M("User",[["path",{d:"M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2",key:"975kel"}],["circle",{cx:"12",cy:"7",r:"4",key:"17ys0d"}]]);/**
|
|
127
|
+
* @license lucide-react v0.468.0 - ISC
|
|
128
|
+
*
|
|
129
|
+
* This source code is licensed under the ISC license.
|
|
130
|
+
* See the LICENSE file in the root directory of this source tree.
|
|
131
|
+
*/const Qe=M("X",[["path",{d:"M18 6 6 18",key:"1bl5f8"}],["path",{d:"m6 6 12 12",key:"d8bk6v"}]]),fs=o.createContext(null),Oe="draken_token",Ue="draken_username";function Ws({children:t}){const[s,n]=o.useState({isAuthenticated:!1,isLoading:!0,authEnabled:!0,username:null,token:null}),a=o.useCallback(async()=>{n(r=>({...r,isLoading:!0}));try{if(!(await(await fetch("/api/auth/status")).json()).enabled){n({isAuthenticated:!0,isLoading:!1,authEnabled:!1,username:null,token:null});return}const u=localStorage.getItem(Oe),j=localStorage.getItem(Ue);if(!u){n({isAuthenticated:!1,isLoading:!1,authEnabled:!0,username:null,token:null});return}(await fetch("/api/auth/verify",{headers:{Authorization:`Bearer ${u}`}})).ok?n({isAuthenticated:!0,isLoading:!1,authEnabled:!0,username:j,token:u}):(localStorage.removeItem(Oe),localStorage.removeItem(Ue),n({isAuthenticated:!1,isLoading:!1,authEnabled:!0,username:null,token:null}))}catch(r){console.error("Auth check failed:",r),n({isAuthenticated:!1,isLoading:!1,authEnabled:!0,username:null,token:null})}},[]),i=async(r,p)=>{const u=await fetch("/api/auth/login",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:r,password:p})});if(!u.ok){const c=await u.json();throw new Error(c.error||"Login failed")}const j=await u.json();localStorage.setItem(Oe,j.token),localStorage.setItem(Ue,j.username),n({isAuthenticated:!0,isLoading:!1,authEnabled:!0,username:j.username,token:j.token})},l=()=>{localStorage.removeItem(Oe),localStorage.removeItem(Ue),n({isAuthenticated:!1,isLoading:!1,authEnabled:!0,username:null,token:null})};return o.useEffect(()=>{a()},[a]),e.jsx(fs.Provider,{value:{...s,login:i,logout:l,checkAuth:a},children:t})}function xs(){const t=o.useContext(fs);if(!t)throw new Error("useAuth must be used within an AuthProvider");return t}function Qs(){const{login:t}=xs(),[s,n]=o.useState(""),[a,i]=o.useState(""),[l,r]=o.useState(null),[p,u]=o.useState(!1),j=async c=>{c.preventDefault(),r(null),u(!0);try{await t(s,a)}catch(y){r(y instanceof Error?y.message:"Login failed")}finally{u(!1)}};return e.jsx("div",{className:"login-page",children:e.jsxs("div",{className:"login-card",children:[e.jsxs("div",{className:"login-header",children:[e.jsx("img",{src:"/favicon.png",alt:"Draken",className:"login-logo"}),e.jsx("h1",{children:"Draken"}),e.jsx("p",{className:"login-subtitle",children:"Your engineering sync across pi sessions"})]}),e.jsxs("form",{onSubmit:j,className:"login-form",children:[l&&e.jsxs("div",{className:"login-error",role:"alert",children:[e.jsx(Rs,{size:16}),l]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"username",children:"Username"}),e.jsxs("div",{className:"input-with-icon",children:[e.jsx(Ks,{size:18,className:"input-icon"}),e.jsx("input",{id:"username",type:"text",className:"input",placeholder:"Enter username",value:s,onChange:c=>n(c.target.value),autoComplete:"username",autoFocus:!0})]})]}),e.jsxs("div",{className:"form-group",children:[e.jsx("label",{htmlFor:"password",children:"Password"}),e.jsxs("div",{className:"input-with-icon",children:[e.jsx(Us,{size:18,className:"input-icon"}),e.jsx("input",{id:"password",type:"password",className:"input",placeholder:"Enter password",value:a,onChange:c=>i(c.target.value),autoComplete:"current-password"})]})]}),e.jsx("button",{type:"submit",className:"btn btn-primary btn-lg login-btn",disabled:p||!s||!a,children:p?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"spinner spinner-sm"})," Signing in..."]}):e.jsxs(e.Fragment,{children:[e.jsx(zs,{size:18})," Sign In"]})})]})]})})}async function T(t,s="GET",n,a){const i=localStorage.getItem("draken_token"),l=await fetch(`/api${t}`,{method:s,signal:a,headers:{"Content-Type":"application/json",...i?{Authorization:`Bearer ${i}`}:{}},body:n===void 0?void 0:JSON.stringify(n)});if(l.status===401)throw localStorage.removeItem("draken_token"),localStorage.removeItem("draken_username"),window.location.reload(),new Error("Authentication required");if(l.status===204)return;const r=await l.json();if(!l.ok)throw new Error(r.error||`Request failed (${l.status})`);return r}const Js=(t=!1)=>T(`/setup${t?"?refresh=1":""}`),Zs=(t,s,n)=>T(`/settings/preparation-usage?range=${t}&bucket=${s}`,"GET",void 0,n),ys=()=>T("/settings/auto-index"),ns=t=>T("/settings/auto-index","PATCH",{enabled:t,...t?{preparation_scope:"index-and-briefing-v1"}:{}}),Je=t=>T(`/home${t?`?before=${t}`:""}`),Xs=t=>T("/syncs/start-call","POST",{request_id:t}),et=t=>T("/syncs/start-chat","POST",{request_id:t}),st=(t,s,n)=>T(`/syncs/${t}/chat/messages`,"POST",{message:s,request_id:n}),rs=t=>T(`/syncs/${t}/recap`,"POST"),is=()=>T("/overview"),tt=()=>T("/scan","POST"),at=(t,s)=>T(`/agents/${encodeURIComponent(t)}`,"PATCH",{enabled:s}),nt=(t,s)=>T(`/sessions/${encodeURIComponent(t)}`,"PATCH",{included:s}),Ye=t=>T(`/syncs/${t}`),rt=t=>T(`/syncs/${t}/progress`),os=(t,s)=>T(`/syncs/${t}/call-readiness`,"GET",void 0,s),it=(t,s)=>T(`/syncs/${t}/chat-readiness`,"GET",void 0,s),ot=t=>T(`/syncs/${t}/prepare-call`,"POST"),ct=(t,s)=>T(`/syncs/${t}/tree/${s}`),lt=t=>T(`/syncs/${t}/expand`,"POST"),dt=t=>T(`/syncs/${t}/cancel`,"POST"),ht=t=>T(`/syncs/${t}/briefing`,"POST"),ut=(t,s)=>T(`/syncs/${t}/messages`,"POST",{message:s}),pt=t=>T("/memory/progress","GET",void 0,t),mt=(t,s)=>T("/memory/search","POST",t,s),gt=(t,s=0)=>T(`/memory/records/${encodeURIComponent(t)}?offset=${s}`),Ee=(t,s,n)=>T(`/syncs/${t}/notes`,"PATCH",{decisions:s,carry_forward:n}),ft=(t,s,n)=>T(`/syncs/${t}/complete`,"POST",{decisions:s,carry_forward:n,reviewed:!0}),xt=t=>T(`/syncs/${t}/discard`,"POST"),_e=25;function cs({items:t,title:s}){const[n,a]=o.useState(0),[i,l]=o.useState(""),[r,p]=o.useState("");if(o.useEffect(()=>{const h=S=>{const b=S.detail,w=t.findIndex(d=>d.ref===b);w<0||(l(""),a(Math.floor(w/_e)),p(b))};return window.addEventListener("draken:evidence",h),()=>window.removeEventListener("draken:evidence",h)},[t]),o.useEffect(()=>{if(!r)return;const h=document.getElementById(`evidence-${r}`);h&&(h.open=!0,h.scrollIntoView({behavior:"smooth",block:"center"}),p(""))},[r,n,i]),!t.length)return null;const u=i.toLocaleLowerCase(),j=u?t.filter(h=>`${h.ref} ${h.session_name} ${h.cwd} ${h.text}`.toLocaleLowerCase().includes(u)):t,c=Math.max(1,Math.ceil(j.length/_e)),y=Math.min(n,c-1);return e.jsxs("section",{className:"evidence-section",children:[e.jsxs("h3",{children:[s," ",e.jsx("span",{className:"count",children:t.length})]}),t.length>_e&&e.jsxs("div",{className:"evidence-controls",children:[e.jsx("input",{className:"input","aria-label":`Search ${s}`,placeholder:"Find a topic, workspace, or evidence ID…",value:i,onChange:h=>{l(h.target.value),a(0)}}),e.jsxs("div",{className:"pagination",children:[e.jsx("button",{className:"btn btn-secondary",disabled:y===0,onClick:()=>a(y-1),children:"Previous"}),e.jsxs("span",{children:[y+1," / ",c," · ",j.length," entries"]}),e.jsx("button",{className:"btn btn-secondary",disabled:y>=c-1,onClick:()=>a(y+1),children:"Next"})]})]}),e.jsx("div",{className:"evidence-list",children:j.slice(y*_e,(y+1)*_e).map(h=>e.jsxs("details",{className:"evidence",id:`evidence-${h.ref}`,children:[e.jsxs("summary",{children:[e.jsx("span",{className:"reference",children:h.ref}),e.jsxs("span",{className:"evidence-title",children:[e.jsxs("strong",{children:[h.agent&&h.agent!=="pi"&&`${h.agent} · `,h.session_name||h.cwd.split("/").filter(Boolean).pop()||h.cwd]}),e.jsx("span",{children:h.unavailable?"Original session source unavailable":h.text.slice(0,130)})]}),e.jsx("span",{className:"role-label",children:h.role})]}),e.jsxs("div",{className:"evidence-body",children:[e.jsxs("dl",{children:[e.jsx("dt",{children:"Workspace"}),e.jsx("dd",{children:h.cwd}),e.jsx("dt",{children:"Session"}),e.jsx("dd",{children:h.session_id}),e.jsx("dt",{children:"Source"}),e.jsx("dd",{children:h.source_path}),e.jsx("dt",{children:"Entry"}),e.jsxs("dd",{children:[h.entry_id," · ",h.timestamp]})]}),h.unavailable?e.jsx("p",{className:"alert warning",role:"status",children:h.unavailable}):e.jsx("pre",{children:h.text})]})]},h.ref))})]})}function Ae({text:t,evidence:s}){const n=new Set(s.map(a=>a.ref));return e.jsx("div",{className:"prose",children:t.split(/(\[(?:[EC]\d+|H[a-f0-9]{24})\])/g).map((a,i)=>{const l=a.slice(1,-1);return/^H[a-f0-9]{24}$/.test(l)?e.jsxs("a",{className:"citation",href:`/history/${l}`,target:"_blank",rel:"noopener noreferrer","aria-label":`Inspect historical source ${l}`,children:["[history ",l.slice(-6),"]"]},i):!/^\[(E|C)\d+\]$/.test(a)||!n.has(l)?e.jsx("span",{children:a},i):e.jsx("button",{className:"citation",onClick:()=>window.dispatchEvent(new CustomEvent("draken:evidence",{detail:l})),"aria-label":`Inspect evidence ${l}`,children:a},i)})})}function yt({syncId:t,progress:s,evidence:n,onCancel:a,onResume:i,resumeEnabled:l}){var x;const[r,p]=o.useState(new Set),[u,j]=o.useState(null),[c,y]=o.useState(""),[h,S]=o.useState(!1),b=s.run;if(o.useEffect(()=>{j(null),p(new Set)},[b==null?void 0:b.id]),!b)return null;const w=!s.busy&&["failed","cancelled","interrupted"].includes(b.status),d=new Map(s.nodes.map(v=>[v.key,v])),E=new Set(s.nodes.flatMap(v=>v.children)),C=s.nodes.filter(v=>!E.has(v.key)),m=async v=>{S(!0),y("");try{j(await ct(t,v.key))}catch(A){y(A instanceof Error?A.message:"Could not load summary")}finally{S(!1)}},k=(v,A=new Set)=>{if(A.has(v.key))return null;const z=new Set([...A,v.key]),ee=r.has(v.key);return e.jsxs("li",{children:[e.jsxs("div",{className:"tree-node",children:[e.jsx("button",{className:"tree-toggle","aria-label":`Expand ${v.label}`,disabled:!v.children.length,onClick:()=>p(I=>{const R=new Set(I);return R.has(v.key)?R.delete(v.key):R.add(v.key),R}),children:v.children.length?ee?"▾":"▸":"·"}),e.jsxs("button",{className:"tree-label",disabled:!["done","cached"].includes(v.status)||h,onClick:()=>void m(v),title:v.error||v.label,children:[e.jsx("span",{className:"role-label",children:v.kind})," ",v.label]}),e.jsx("span",{className:`status ${v.status}`,children:v.status})]}),ee&&e.jsx("ul",{children:v.children.map(I=>d.has(I)?k(d.get(I),z):null)})]},v.key)};return e.jsxs("section",{className:"card tree-card",children:[e.jsxs("div",{className:"section-heading",children:[e.jsx("h2",{children:"Summary tree"}),e.jsx("span",{className:`status ${b.status}`,children:b.status})]}),e.jsx("p",{className:"small muted",children:"Complete source batches → compact reconciliation → final verdict"}),e.jsx("progress",{max:Math.max(1,b.total_entries),value:b.processed_entries,"aria-label":"Evidence compression progress"}),e.jsxs("div",{className:"tree-stats",children:[e.jsxs("span",{children:[b.processed_entries," / ",b.total_entries," entries processed"]}),e.jsxs("span",{children:[b.invocations," / ",b.max_invocations," pi invocations"]}),e.jsxs("span",{children:[b.cache_hits," cached nodes reused"]})]}),!!((x=b.metrics)!=null&&x.length)&&e.jsxs("details",{className:"small",children:[e.jsx("summary",{children:"Model request timing"}),e.jsxs("p",{children:[(b.metrics.reduce((v,A)=>v+A.elapsed_ms,0)/1e3).toFixed(1)," seconds across ",b.metrics.length," requests · ",b.metrics.reduce((v,A)=>v+A.input_tokens_estimate,0).toLocaleString()," estimated input tokens."]}),e.jsx("p",{className:"muted",children:"Includes pi startup and provider waiting/generation, not separately measured. Token counts are local planning estimates with input headroom, not billed usage. A completed request can still fail summary validation."}),e.jsx("ul",{children:b.metrics.map((v,A)=>e.jsxs("li",{children:[v.stage||v.task,v.repair?" (repair)":""," · ",(v.elapsed_ms/1e3).toFixed(1)," s · ",v.status]},A))})]}),e.jsxs("p",{className:"small",children:[w?"Stopped at: ":"",b.stage]}),b.question&&e.jsxs("p",{className:"small muted",children:["Question: ",b.question]}),b.error&&e.jsxs("div",{className:"alert error",role:"alert",children:[e.jsx("strong",{children:"Last run’s error:"})," ",b.error]}),w&&e.jsxs("div",{className:"alert warning",children:[e.jsx("strong",{children:"Generation stopped. No model calls are running."}),e.jsxs("p",{className:"small",children:[b.processed_entries<b.total_entries?`${b.total_entries-b.processed_entries} entries still need compression.`:"Raw chunks were processed, but reconciliation or the final reply did not finish."," Successful chunks are cached; nothing was marked reviewed."]}),i&&e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"small",children:"Resume to continue from cached chunks instead of generating them again."}),e.jsx("button",{className:"btn btn-primary",disabled:!l,onClick:i,children:"Resume generation"})]})]}),s.busy&&e.jsx("button",{className:"btn btn-secondary",onClick:a,children:"Cancel generation"}),e.jsxs("details",{className:"tree-browser",children:[e.jsxs("summary",{children:["Inspect ",s.nodes.length," summary nodes"]}),e.jsx("ul",{children:C.map(v=>k(v))})]}),c&&e.jsx("p",{role:"alert",className:"error",children:c}),u&&e.jsxs("div",{className:"node-inspector",children:[e.jsxs("div",{className:"section-heading",children:[e.jsx("h3",{children:u.label}),e.jsx("button",{className:"btn btn-ghost",onClick:()=>j(null),children:"Close"})]}),"observations"in u.output?e.jsxs(e.Fragment,{children:[u.output.observations.map((v,A)=>e.jsxs("div",{className:"node-observation",children:[e.jsx("strong",{children:v.topic})," ",e.jsx("span",{className:"status",children:v.state}),e.jsx(Ae,{text:`${v.summary} ${v.evidence.map(z=>u.refs[z]?`[${u.refs[z]}]`:"[source unavailable]").join(" ")}`,evidence:n})]},A)),u.output.limitations.map((v,A)=>e.jsx("p",{className:"muted small",children:v},A))]}):u.output.groups.map((v,A)=>e.jsxs("p",{className:"small",children:[v.topic," · ",v.members.length," related observations"]},A))]})]})}function vs(){const t=crypto.getRandomValues(new Uint8Array(16));t[6]=t[6]&15|64,t[8]=t[8]&63|128;const s=[...t].map(n=>n.toString(16).padStart(2,"0")).join("");return`${s.slice(0,8)}-${s.slice(8,12)}-${s.slice(12,16)}-${s.slice(16,20)}-${s.slice(20)}`}const Ze={phase:"connecting",muted:!1,microphone:!1,voiceInterruption:!1,question:"",answer:"",evidence:[],error:"",notice:"",startedAt:0,turnId:0,replyPendingSince:0,historyReady:!1};function js(t=!0){const s=localStorage.getItem("draken_token");return{...t?{"Content-Type":"application/json"}:{},...s?{Authorization:`Bearer ${s}`}:{}}}async function X(t,s={}){const n=await fetch(`/api/voice${t}`,{...s,headers:js()});if(!n.ok){const a=await n.json().catch(()=>({}));throw new Error(a.error||(n.status===401?"Sign in again to use the call.":"The live connection failed."))}return n.status===204?void 0:n.json()}function bs({cost:t}){if(!t)return null;const s=t.usd===null?"unavailable":t.usd>0&&t.usd<1e-6?"<$0.000001":new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",minimumFractionDigits:2,maximumFractionDigits:t.usd<.01?6:2}).format(t.usd),n="Sync preparation only: summaries, consolidation, preparation recaps and final briefing, including retries. Excludes later questions, calls and conversation recaps. API-equivalent estimate from pi usage and catalog prices, not a subscription charge or invoice.",a=t.usd===null?" Usage/pricing was not captured or is unavailable for this preparation.":t.complete?"":" Partial total: some preparation usage/pricing is missing or work is still running.";return e.jsxs("span",{className:"sync-cost small muted",title:n+a,children:["Est. cost: ",s,t.usd!==null&&!t.complete?" (partial)":""]})}function ws({active:t=!0,firstRun:s=!1,always:n=!1,onReady:a,onTextReady:i}){const[l,r]=o.useState(null),[p,u]=o.useState(null),[j,c]=o.useState(""),[y,h]=o.useState(!1),[S,b]=o.useState(0);if(o.useEffect(()=>{if(!t)return;let d=!0;const E=async(m=!1)=>{h(!0);try{const[k,x]=await Promise.all([Js(m),X("/status").catch(()=>null)]);if(!d)return;r(k),u(x),c(x?"":"Voice status is unavailable. Configured text chat can still be used."),a==null||a(k.pi.state==="configured"&&!!(x!=null&&x.installed)),i==null||i(k.pi.state==="configured")}catch{d&&(c("Could not check setup or reach Draken. The last displayed state may be stale. Check the server terminal, then retry."),a==null||a(!1),i==null||i(!1))}finally{d&&h(!1)}};E(S>0);const C=setInterval(()=>void E(),6e4);return()=>{d=!1,clearInterval(C)}},[t,S,a,i]),!t||!n&&!s&&!j&&(l==null?void 0:l.pi.state)==="configured"&&(p!=null&&p.installed))return null;const w=l==null?void 0:l.pi;return e.jsxs("section",{className:"setup-panel","aria-label":"Draken setup",children:[e.jsx("h2",{children:s?"First-time setup":"Runtime & sign-in"}),e.jsx("p",{className:"small muted",children:"Draken reads agent histories, but pi runs summaries and text chat. Voice uses a separate ChatGPT sign-in. Setup and login are explicit terminal commands—not browser downloads or credential forms."}),!l&&!j&&e.jsx("p",{className:"small",role:"status",children:"Checking setup…"}),w&&e.jsxs(e.Fragment,{children:[e.jsxs("p",{children:[e.jsxs("strong",{children:["Summarization: ",w.state==="configured"?"credentials configured":w.state==="missing"?"pi not found":w.state==="needs_login"?"sign-in needed":"needs attention"]}),e.jsxs("span",{className:"small muted",children:[" · ",w.source==="managed"?"Draken-private pi":"Existing / external pi",w.version&&` ${w.version}`]})]}),e.jsx("p",{className:"small",children:w.message}),w.state!=="configured"&&e.jsxs("div",{className:"setup-commands",children:[["missing","incompatible"].includes(w.state)&&e.jsxs("p",{children:[e.jsx("code",{children:"draken setup"})," — install a pinned, private pi after confirmation. An explicit ",e.jsx("code",{children:"DRAKEN_PI_BIN"})," must be fixed or unset first."]}),e.jsxs("p",{children:[e.jsx("code",{children:"draken login"})," — open pi; type ",e.jsx("code",{children:"/login"}),", follow its prompts, then ",e.jsx("code",{children:"/quit"}),"."]}),e.jsxs("p",{children:[e.jsx("code",{children:"draken doctor"})," — inspect configuration without a generation request."]})]}),e.jsx("ul",{className:"small muted",children:w.models.map(d=>e.jsxs("li",{children:[d.model," · ",d.state.replace(/_/g," ")]},d.model))}),e.jsxs("p",{className:"small muted source-path",children:["Pi credential directory: ",w.agent_dir]})]}),p&&e.jsx("p",{children:e.jsxs("strong",{children:["ChatGPT voice: ",p.installed?"helper and sign-in configured":"setup needed"]})}),p&&!p.installed&&e.jsxs("div",{className:"setup-commands",children:[e.jsxs("p",{children:[e.jsx("code",{children:"draken voice setup"})," — install the native helper."]}),e.jsxs("p",{children:[e.jsx("code",{children:"draken voice login"})," — use its separate official ChatGPT sign-in. No pi tokens are copied."]})]}),(n||s||(w==null?void 0:w.state)!=="configured"||!(p!=null&&p.installed))&&e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"small muted",children:["Run commands on the server as its user, with the same environment. After login, click Check setup again. Keep the server terminal open; Ctrl+C stops it. ",e.jsx("code",{children:"draken status"})," checks connectivity."]}),l&&e.jsxs("p",{className:"small muted source-path",children:["Draken data: ",l.data_dir]}),e.jsxs("p",{className:"small muted",children:["Choose sources in ",e.jsx("strong",{children:"Settings → Agents & sessions"}),", then ",e.jsx("strong",{children:"Sync with Draken"}),". Source scanning works before sign-in. Credential presence does not verify model access, billing or voice playback."]})]}),j&&e.jsx("p",{className:"small",role:"alert",children:j}),e.jsx("button",{type:"button",className:"btn btn-secondary",disabled:y,onClick:()=>b(d=>d+1),children:y?"Checking…":"Check setup again"})]})}const vt={scanning:"Checking history for changes…",downloading:"Downloading the local search model…",loading:"Preparing the local search model…",indexing:"Indexing new and changed history…",searching:"Finding matching history…",reading:"Reading a historical source…"},Ge=t=>t<60?`${Math.ceil(t)} sec`:`${Math.ceil(t/60)} min`,ze=t=>t.toLocaleString();function He({enabled:t,waiting:s=!1,backgroundOnly:n=!1,onLookupChange:a}){const[i,l]=o.useState(null),[r,p]=o.useState(!1);if(o.useEffect(()=>{if(a==null||a(!1),!t)return;l(null),p(!1);const w=new AbortController;let d;const E=async()=>{try{const C=await pt(w.signal);w.signal.aborted||(l(C),p(!1),a==null||a(!!(C.active&&!C.background&&C.work&&["scanning","searching","reading"].includes(C.work.stage)&&C.updated_at&&Math.abs(Date.now()-C.updated_at)<5e3)))}catch{w.signal.aborted||(p(!0),a==null||a(!1))}w.signal.aborted||(d=setTimeout(()=>void E(),1e3))};return E(),()=>{w.abort(),clearTimeout(d),a==null||a(!1)}},[t,a]),!t)return null;if(!(i!=null&&i.active)||!i.work||n&&!i.background)return s?e.jsx("p",{className:"small muted",role:"status",children:r?"Progress is unavailable; your search is still pending.":"Waiting for local history work…"}):null;const u=i.work,j=u.stage==="indexing",c=u.stage==="downloading",y=c?u.downloaded_bytes:u.completed,h=c?u.download_total_bytes:u.total,S=h?Math.floor(y/h*100):0,b=i.updated_at?Math.floor((Date.now()-i.updated_at)/1e3):0;return e.jsxs("section",{className:"history-progress","aria-label":"Local history progress",children:[e.jsx("p",{role:"status",children:e.jsx("strong",{children:j&&!h?"History is up to date.":vt[u.stage]})}),(j&&h>0||c)&&e.jsxs(e.Fragment,{children:[e.jsx("progress",{"aria-label":c?"Model download":"History indexing",max:h||1,value:h?y:void 0}),e.jsxs("p",{children:[c?`${(y/1e6).toFixed(1)} / ${(h/1e6).toFixed(1)} MB`:`${ze(y)} / ${ze(h)} new or changed passages ready`," · ",S,"%"]})]}),e.jsxs("p",{className:"small muted",children:[j&&`${ze(u.reused)} unchanged passages reused (not part of this progress). `,"Elapsed ",Ge(i.elapsed_ms/1e3),".",j&&u.remaining_seconds!==null&&u.remaining_seconds>0&&` About ${Ge(u.remaining_seconds)} remaining (estimate).`,j&&h>0&&u.parallelism&&` Up to ${u.parallelism.workers} embedding worker${u.parallelism.workers===1?"":"s"}, ${u.parallelism.threads} CPU threads total.`,i.queued>0&&` ${ze(i.queued)} other history request${i.queued===1?"":"s"} waiting.`]}),(r||b>=15)&&e.jsxs("p",{className:"small muted",children:[r?"Progress updates are temporarily unavailable.":`No new progress for ${Ge(b)}.`," Cancelling keeps completed embeddings for the next request."]})]})}function ks({settings:t}){const s=t.pending_entries??0,n={off:"Automatic preparation is off.",waiting:t.ready_sync_id?"Your next briefing is prepared.":"Waiting for the next preparation batch.",scanning:"Checking history for changes…",indexing:"Preparing searchable history…",briefing:"Preparing your next briefing…",paused:"Paused for your conversation or foreground work.",stopping:"Stopping automatic preparation…",error:"Automatic preparation needs attention."}[t.phase];return e.jsxs("section",{className:"history-progress","aria-label":"Automatic preparation",children:[e.jsx("p",{role:"status",children:e.jsx("strong",{children:n})}),t.enabled&&e.jsxs("p",{className:"small muted",children:[s.toLocaleString()," entries waiting for preparation. ",t.last_completed_at&&`Last completed batch: ${new Date(t.last_completed_at).toLocaleString()}.`]}),t.phase==="briefing"&&t.progress&&e.jsxs(e.Fragment,{children:[e.jsx("p",{role:"status",children:t.progress.stage}),e.jsx("progress",{"aria-label":"Automatic briefing summaries",max:Math.max(1,t.progress.total),value:t.progress.completed}),e.jsxs("p",{className:"small muted",children:[t.progress.completed.toLocaleString()," / ",t.progress.total.toLocaleString()," entries summarized. ",t.progress.invocations," / ",t.progress.max_invocations," model calls this attempt. The opening briefing and search readiness finish this batch."]})]}),t.error&&e.jsx("p",{role:"alert",children:t.error}),t.sync_id&&e.jsx("a",{href:`/syncs/${t.sync_id}`,children:"Open preparation"}),!t.sync_id&&t.ready_sync_id&&e.jsx("a",{href:`/syncs/${t.ready_sync_id}`,children:"Open prepared briefing"}),e.jsx(He,{enabled:t.enabled&&["indexing","briefing"].includes(t.phase),backgroundOnly:!0})]})}function jt(){const[t,s]=o.useState(null),[n,a]=o.useState(!1);return o.useEffect(()=>{let i=!0;const l=async()=>{try{const p=await ys();i&&(s(p),a(!1))}catch{i&&a(!0)}};l();const r=setInterval(()=>void l(),4e3);return()=>{i=!1,clearInterval(r)}},[]),n?e.jsx("p",{role:"status",className:"small muted",children:"Automatic preparation status is temporarily unavailable."}):t!=null&&t.enabled?e.jsx(ks,{settings:t}):null}const me=(t,s,n)=>{t.button||t.metaKey||t.ctrlKey||t.shiftKey||t.altKey||(t.preventDefault(),s(n))},bt=t=>new Date(t).toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"});function wt({navigate:t}){const[s,n]=o.useState(null),[a,i]=o.useState(""),[l,r]=o.useState(""),[p,u]=o.useState(""),[j,c]=o.useState(!1),[y,h]=o.useState(!1),S=o.useRef(!0),b=o.useRef(!1),w=o.useRef(),d=async()=>{const m=await Je();S.current&&n(k=>k&&k.syncs.length>20?{...m,syncs:[...m.syncs,...k.syncs.filter(x=>{var v;return x.id<((v=m.syncs[m.syncs.length-1])==null?void 0:v.id)})],next_cursor:k.next_cursor}:m)};o.useEffect(()=>{S.current=!0,d().catch(k=>r(k.message)),window.isSecureContext||X("/status").then(k=>{if(S.current&&k.httpsPort){const x=new URL("/",location.href);x.protocol="https:",x.port=String(k.httpsPort),u(x.href)}}).catch(()=>{});const m=setInterval(()=>{b.current||d().catch(()=>{})},4e3);return()=>{S.current=!1,clearInterval(m)}},[]);const E=async(m="call")=>{if(!b.current){b.current=!0,i("Collecting new activity…"),r(""),w.current||(w.current=vs());try{if(m==="call"){const x=await X("/status");if(!x.installed)throw new Error("Voice is not ready on this server. Complete voice setup before starting a sync call.");if(x.activeCall)throw new Error("End the existing call before starting another sync.")}const k=await(m==="chat"?et:Xs)(w.current);S.current&&t(`/syncs/${k.sync.id}${m==="chat"?"/chat":""}`,m==="call")}catch(k){S.current&&r(k instanceof Error?k.message:"Could not start the sync")}finally{b.current=!1,S.current&&i("")}}},C=!!(!j||a||s!=null&&s.busy||s!=null&&s.active_call);return e.jsxs("main",{className:"sync-home",children:[e.jsxs("div",{className:"page-heading",children:[e.jsxs("div",{children:[e.jsx("h1",{children:"Pick up where you left off."}),e.jsx("p",{className:"muted",children:"New activity. A little memory. One conversation."})]}),e.jsxs("div",{className:"conversation-actions",children:[e.jsxs("button",{className:"btn btn-secondary",disabled:!s||!y||!!(a||s!=null&&s.busy||s!=null&&s.active_call),onClick:()=>void E("chat"),children:[e.jsx(ms,{size:17}),"Chat instead"]}),p?e.jsxs("a",{className:"btn btn-primary",href:p,children:["Open secure Draken",e.jsx(as,{size:17})]}):e.jsxs("button",{className:"btn btn-primary",disabled:!s||C||!window.isSecureContext,onClick:()=>void E(),children:[e.jsx(We,{size:17}),"Sync with Draken"]})]})]}),!window.isSecureContext&&e.jsx("p",{className:"small muted",children:"Use trusted HTTPS or localhost for the combined sync and call."}),e.jsx("p",{className:"home-hint muted small",children:"With automatic preparation enabled, new history becomes a ready briefing before you arrive. Join the prepared conversation, or catch up the newest entries in one final preparation. Nothing is marked reviewed until you confirm it."}),e.jsxs("div",{className:"home-counts","aria-label":"Sync tracking",children:[e.jsxs("span",{children:[e.jsx("strong",{children:(s==null?void 0:s.available)??"—"})," awaiting preparation"]}),e.jsxs("span",{children:[e.jsx("strong",{children:(s==null?void 0:s.included_unreviewed)??"—"})," included, not reviewed"]}),e.jsxs("span",{children:[e.jsx("strong",{children:(s==null?void 0:s.covered)??"—"})," reviewed"]})]}),e.jsx(jt,{}),a&&e.jsxs("p",{role:"status",className:"working",children:[e.jsx("span",{className:"spinner"}),a]}),(s==null?void 0:s.busy)&&!a&&e.jsx("p",{className:"small muted",role:"status",children:"Draken is updating a sync. Open its card to follow progress."}),(s==null?void 0:s.active_call)&&e.jsx("p",{className:"small muted",children:"A call is active. End it before starting another sync."}),l&&e.jsx("div",{className:"alert error",role:"alert",children:l}),e.jsx(ws,{firstRun:!!(s&&!s.syncs.length),onReady:c,onTextReady:h}),e.jsxs("section",{className:"sync-feed","aria-label":"Sync history",children:[s==null?void 0:s.syncs.map(m=>e.jsxs("a",{className:"card sync-tile",href:`/syncs/${m.id}`,onClick:k=>me(k,t,`/syncs/${m.id}`),children:[e.jsxs("div",{className:"sync-tile-heading",children:[e.jsxs("strong",{children:["Sync #",m.id]}),e.jsx("span",{className:`status ${m.status}`,children:m.busy?"working":m.active_call?"in call":m.needs_retry?"needs retry":m.status==="completed"?"reviewed":m.status==="open"?"open":"discarded"}),e.jsx(as,{size:17,"aria-hidden":"true"})]}),e.jsxs("div",{className:"small muted",children:[bt(m.created_at)," · ",m.item_count," ",m.item_count===1?"entry":"entries"," · ",m.calls," ",m.calls===1?"call":"calls",m.aggregation_cost&&e.jsxs(e.Fragment,{children:[" · ",e.jsx(bs,{cost:m.aggregation_cost})]})]}),e.jsx("p",{className:"sync-tile-preview",children:m.preview||(m.needs_retry?"Preparation stopped. Open this sync to retry; its entries and cached work are retained.":m.busy?"Bringing the new activity together. Open this sync to follow preparation.":"No recap yet. Open this sync to continue the conversation.")}),e.jsx("span",{className:"sync-tile-kind small muted",children:m.preview_kind==="recap"?"Conversation recap · not saved decisions":m.preview_kind==="previous_recap"?"Earlier recap · conversation changed":m.preview_kind==="briefing"?"Briefing preview":"Frozen snapshot"})]},m.id)),s&&!s.syncs.length&&e.jsxs("div",{className:"card welcome",children:[e.jsx("h2",{children:"Your next conversation starts here."}),e.jsx("p",{children:"Draken keeps track of the work you’ve already brought into a sync. Start above; the details can wait until you need them."})]})]}),(s==null?void 0:s.next_cursor)&&e.jsx("button",{className:"btn btn-secondary",onClick:async()=>{try{const m=await Je(s.next_cursor);n(k=>k?{...k,syncs:[...k.syncs,...m.syncs.filter(x=>!k.syncs.some(v=>v.id===x.id))],next_cursor:m.next_cursor}:m)}catch(m){r(m instanceof Error?m.message:"Could not load history")}},children:"Older syncs"})]})}const kt=t=>t?new Date(t).toLocaleString():"Edit date not retained";function Xe({record:t}){return e.jsxs(e.Fragment,{children:[e.jsxs("p",{className:"small muted",children:[kt(t.at)," · ",t.role," · ",t.kind,t.sync_id?` · Sync #${t.sync_id}`:""]}),e.jsx("p",{className:"small muted",children:t.qualification})]})}function Ns({reference:t}){const[s,n]=o.useState(null),[a,i]=o.useState(0),[l,r]=o.useState("");return o.useEffect(()=>{i(0)},[t]),o.useEffect(()=>{let p=!0;return r(""),n(null),gt(t,a).then(u=>{p&&n(u)}).catch(u=>{p&&r(u.message)}),()=>{p=!1}},[t,a]),e.jsxs("section",{className:"history-source","aria-label":"Historical source",children:[l&&e.jsx("p",{role:"alert",children:l}),!s&&!l&&e.jsx("p",{role:"status",children:"Reading historical source…"}),s&&e.jsxs(e.Fragment,{children:[e.jsx("h2",{children:s.record.title}),e.jsx(Xe,{record:s.record}),s.record.workspace&&e.jsx("p",{className:"source-path",children:s.record.workspace}),e.jsx("pre",{className:"history-excerpt",children:s.record.text}),e.jsxs("p",{className:"small muted",children:["Characters ",Math.min(a+1,s.total),"–",Math.min(a+4e3,s.total)," of ",s.total," in the retained record. Source logs may contain more."]}),s.total>4e3&&e.jsxs("div",{className:"pagination",children:[e.jsx("button",{className:"btn btn-secondary",disabled:!a,onClick:()=>i(Math.max(0,a-4e3)),children:"Earlier text"}),e.jsx("button",{className:"btn btn-secondary",disabled:a+4e3>=s.total,onClick:()=>i(a+4e3),children:"Later text"})]}),s.record.sync_id&&e.jsxs("p",{children:[e.jsxs("a",{href:`/syncs/${s.record.sync_id}`,target:"_blank",rel:"noopener noreferrer",children:["Open original sync #",s.record.sync_id]}),s.record.origin_ref&&` · original reference ${s.record.origin_ref}`]}),s.neighbors.length>0&&e.jsxs("details",{children:[e.jsx("summary",{children:"Surrounding retained records"}),e.jsx("p",{className:"small muted",children:"Nearby records in this session or discussion—not necessarily the full conversation."}),s.neighbors.map(p=>e.jsxs("article",{children:[e.jsx("h3",{children:e.jsx("a",{href:`/history/${p.ref}`,target:"_blank",rel:"noopener noreferrer",children:p.title})}),e.jsx(Xe,{record:p}),e.jsx("pre",{className:"history-excerpt",children:p.text})]},p.ref))]})]})]})}function Nt({navigate:t,reference:s}){const[n,a]=o.useState(null),[i,l]=o.useState(""),[r,p]=o.useState(""),[u,j]=o.useState(!1),c=o.useRef();return o.useEffect(()=>()=>{var y;return(y=c.current)==null?void 0:y.abort()},[]),e.jsxs("main",{className:"sync-home history-page",children:[e.jsx("a",{className:"back-link",href:"/",onClick:y=>me(y,t,"/"),children:"All syncs"}),e.jsx("h1",{children:s?"Historical source":"Find earlier work."}),e.jsx("p",{className:"muted",children:"Search retained sessions, sync discussions and explicitly saved notes. Results are historical evidence—not new progress, agreement or proof of execution."}),s?e.jsxs(e.Fragment,{children:[e.jsx(Ns,{reference:s},s),e.jsx("p",{children:e.jsx("a",{href:"/history",onClick:y=>me(y,t,"/history"),children:"Search history"})})]}):e.jsxs(e.Fragment,{children:[e.jsx("p",{className:"small muted",children:"Draken combines meaning and keyword matches automatically. First use prepares a local model (about 136 MB); later searches reuse it and update changed records. Search text stays on this server. Your source exclusions and history baseline still apply."}),e.jsxs("form",{className:"history-search",onSubmit:async y=>{y.preventDefault(),j(!0),p(""),a(null);const h=new AbortController;c.current=h;try{const S=await mt({question:i},h.signal);h.signal.aborted||a(S)}catch(S){h.signal.aborted||p(S instanceof Error?S.message:"Search failed")}finally{j(!1)}},children:[e.jsx("label",{htmlFor:"history-question",children:"What do you want to find?"}),e.jsx("textarea",{id:"history-question",rows:3,maxLength:2e3,value:i,onChange:y=>l(y.target.value),placeholder:"Why did we change that approach?"}),e.jsxs("div",{className:"history-actions",children:[e.jsx("button",{className:"btn btn-primary",disabled:u||!i.trim(),children:u?"Searching…":"Search history"}),u&&e.jsx("button",{type:"button",className:"btn btn-secondary",onClick:()=>{var y;return(y=c.current)==null?void 0:y.abort()},children:"Cancel search"})]}),e.jsx(He,{enabled:u,waiting:!0})]}),r&&e.jsx("p",{className:"alert error",role:"alert",children:r}),n&&e.jsxs("section",{"aria-label":"History search results",children:[e.jsx("p",{className:"small muted",children:"Meaning + keyword matches"}),!n.results.length&&e.jsx("p",{children:"No matches in this search. That does not prove the event never happened; try different wording or a wider scope."}),n.results.map(y=>e.jsxs("article",{className:"card history-result",children:[e.jsx("h2",{children:e.jsx("a",{href:`/history/${y.ref}`,target:"_blank",rel:"noopener noreferrer",children:y.title})}),e.jsx(Xe,{record:y}),e.jsx("pre",{className:"history-excerpt",children:y.text}),e.jsx("a",{href:`/history/${y.ref}`,target:"_blank",rel:"noopener noreferrer",children:"Read source and surrounding context"})]},y.ref)),e.jsx("p",{className:"small muted",children:n.limitations})]})]})]})}const ls=["[Thinking...]","[Hmmm...]","[Hmmmmmm...]"],ds=["[Checking...]","[Looking that up...]"];function Ke(t){const s=Array.from(t.trim().replace(/\s+/g," "));if(s.length<=140)return s.join("");const n=s.slice(-140).join(""),a=n.indexOf(" ");return"…"+(a>=0&&a<25?n.slice(a+1):n)}function St({call:t,historyLookup:s}){const[n,a]=o.useState(0),i=!!t.replyPendingSince&&!["connecting","hearing","speaking","paused","ended"].includes(t.phase)&&!t.error;o.useEffect(()=>{if(a(0),!i)return;const p=setInterval(()=>a(u=>(u+1)%6),5e3);return()=>clearInterval(p)},[i,t.replyPendingSince,s]);let l,r="";return t.phase==="ended"?l="[Call ended]":t.error?l="[Reply unavailable]":t.phase==="paused"?l="[Sound paused]":t.phase==="connecting"?l=t.notice.includes("microphone permission")?"[Waiting for microphone...]":"[Connecting...]":t.phase==="hearing"?(l=t.question?Ke(t.question):"[Listening...]",r=t.question?"You":""):i?l=s?ds[n%ds.length]:ls[n%ls.length]:t.notice.startsWith("Reply muted locally;")?l="[Reply stopped]":t.answer?(l=Ke(t.answer),r="Draken"):t.question?(l=Ke(t.question),r="You"):l=t.phase==="speaking"?"[Speaking...]":t.muted?"[Microphone off]":"[Listening...]",e.jsxs("div",{className:"voice-captions",role:"region","aria-label":"Live captions","aria-live":"off","data-kind":r?"transcript":"status",children:[r&&e.jsx("span",{className:"voice-caption-speaker",children:r}),e.jsx("div",{className:"voice-caption-window",children:e.jsx("p",{children:l})})]})}var Y,H,Q,ue,ve,ke,ne,oe,J,pe,Te,B,Pe,Ie,je,Ne,qe,Me;class Ct{constructor({onClose:s=()=>{},onEvent:n=()=>{}}={}){U(this,Y);U(this,H);U(this,Q);U(this,ue);U(this,ve,new Set);U(this,ke,[]);U(this,ne);U(this,oe);U(this,J);U(this,pe,new Float32Array(1024));U(this,Te,new AbortController);U(this,B,!1);U(this,Pe,!1);U(this,Ie,!1);U(this,je);U(this,Ne);U(this,qe);U(this,Me);D(this,qe,s),D(this,Me,n)}get closed(){return f(this,B)}get clock(){var s;return!f(this,B)&&((s=f(this,H))==null?void 0:s.state)==="running"?f(this,H).currentTime:NaN}get audioState(){var s;return((s=f(this,H))==null?void 0:s.state)||"closed"}async resume(){var s,n;f(this,B)||(await((s=f(this,H))==null?void 0:s.resume()),await((n=f(this,J))==null?void 0:n.play()))}gateInput(s){var n;(n=f(this,Q))==null||n.getAudioTracks().forEach(a=>{a.enabled=!!s})}get inputActive(){var s;return!!((s=f(this,Q))!=null&&s.getAudioTracks().some(n=>n.readyState==="live"))}get level(){var n;if(f(this,B)||f(this,Ie)||((n=f(this,H))==null?void 0:n.state)!=="running"||!f(this,ne))return 0;f(this,ne).getFloatTimeDomainData(f(this,pe));const s=Math.sqrt(f(this,pe).reduce((a,i)=>a+i*i,0)/f(this,pe).length);return Number.isFinite(s)?Math.min(1,s*12):0}async open(s,n){if(f(this,Pe)||f(this,B))throw s.getTracks().forEach(a=>a.stop()),new Error("A voice peer can open only once.");D(this,Pe,!0),D(this,Q,s);try{if(s.getAudioTracks().length!==1||s.getVideoTracks().length)throw new Error("Exactly one audio track is required.");if(D(this,Y,new RTCPeerConnection),D(this,H,new AudioContext),D(this,ne,f(this,H).createAnalyser()),f(this,ne).fftSize=f(this,pe).length,D(this,oe,f(this,H).createGain()),f(this,ne).connect(f(this,oe)),f(this,oe).connect(f(this,H).destination),D(this,Ne,setTimeout(()=>this.close("Voice connection timed out."),6e4)),await f(this,H).resume(),f(this,B)||f(this,H).state!=="running")throw new Error("Voice playback could not start.");D(this,ue,f(this,Y).addTrack(s.getAudioTracks()[0],s));const a=f(this,Y).createDataChannel("oai-events"),i=new Promise((r,p)=>{D(this,je,p);const u=()=>{f(this,Y).connectionState==="connected"&&a.readyState==="open"?(D(this,je,void 0),clearTimeout(f(this,Ne)),r()):["failed","disconnected","closed"].includes(f(this,Y).connectionState)&&this.close("Voice connection lost. Start a new call explicitly.")};f(this,Y).onconnectionstatechange=u,a.onopen=u,a.onclose=()=>this.close("Voice event connection closed."),a.onerror=()=>this.close("Voice event connection failed.")});if(i.catch(()=>{}),a.onmessage=r=>{if(!f(this,B)){if(typeof r.data!="string"||r.data.length>2e5){this.close("Voice event exceeds its limit.");return}try{f(this,Me).call(this,JSON.parse(r.data))}catch{this.close("Invalid voice event.")}}},f(this,Y).ontrack=r=>{if(f(this,B)){r.track.stop();return}if(r.track.kind!=="audio"||f(this,ve).size){this.close("Unexpected remote media track.");return}f(this,ve).add(r.track);const p=new MediaStream([r.track]);D(this,J,new Audio),f(this,J).muted=!0,f(this,J).srcObject=p,f(this,J).play().catch(()=>this.close("Voice playback could not start."));const u=f(this,H).createMediaStreamSource(p);f(this,ke).push(u),u.connect(f(this,ne)),r.track.onended=()=>this.close("Voice output ended.")},await f(this,Y).setLocalDescription(await f(this,Y).createOffer()),f(this,B))throw new Error("Voice connection cancelled.");const l=await n(f(this,Y).localDescription.sdp,f(this,Te).signal);if(f(this,B))throw new Error("Voice connection cancelled.");if(typeof l!="string"||l.length>64e3||!l.startsWith("v=0"))throw new Error("Invalid voice answer.");await f(this,Y).setRemoteDescription({type:"answer",sdp:l}),await i}catch(a){throw this.close("Voice connection failed or cancelled."),a}}muteOutput(s){D(this,Ie,!!s),f(this,oe)&&(f(this,oe).gain.value=s?0:1)}stopInput(){var s;(s=f(this,Q))==null||s.getTracks().forEach(n=>n.stop()),D(this,Q,void 0),f(this,ue)&&!f(this,B)&&f(this,ue).replaceTrack(null).catch(()=>this.close("Cannot mute voice input."))}async replaceInput(s){if(f(this,B)||!f(this,ue)||s.getAudioTracks().length!==1||s.getVideoTracks().length)throw s.getTracks().forEach(a=>a.stop()),new Error("Cannot attach voice input.");const n=f(this,Q);D(this,Q,s),n==null||n.getTracks().forEach(a=>a.stop());try{await f(this,ue).replaceTrack(s.getAudioTracks()[0])}catch(a){throw s.getTracks().forEach(i=>i.stop()),this.close("Cannot attach voice input."),a}if(f(this,B)||f(this,Q)!==s)throw s.getTracks().forEach(a=>a.stop()),new Error("Voice input was superseded.")}close(s="Call ended."){var n,a,i,l,r;if(!f(this,B)){D(this,B,!0),clearTimeout(f(this,Ne)),f(this,Te).abort(),(n=f(this,je))==null||n.call(this,new Error(s)),D(this,je,void 0),(a=f(this,Y))==null||a.close(),(i=f(this,Q))==null||i.getTracks().forEach(p=>p.stop()),f(this,ve).forEach(p=>p.stop()),f(this,ve).clear(),f(this,ke).forEach(p=>p.disconnect()),D(this,ke,[]),(l=f(this,ne))==null||l.disconnect(),(r=f(this,oe))==null||r.disconnect(),f(this,pe).fill(0),f(this,J)&&(f(this,J).pause(),f(this,J).srcObject=null,D(this,J,void 0)),f(this,H)&&f(this,H).state!=="closed"&&f(this,H).close().catch(()=>{});try{f(this,qe).call(this,s)}catch{}}}}Y=new WeakMap,H=new WeakMap,Q=new WeakMap,ue=new WeakMap,ve=new WeakMap,ke=new WeakMap,ne=new WeakMap,oe=new WeakMap,J=new WeakMap,pe=new WeakMap,Te=new WeakMap,B=new WeakMap,Pe=new WeakMap,Ie=new WeakMap,je=new WeakMap,Ne=new WeakMap,qe=new WeakMap,Me=new WeakMap;class Et{constructor(s){P(this,"state",{...Ze,phase:"connecting"});P(this,"alive",!0);P(this,"id","");P(this,"pageExit",()=>{this.end()});P(this,"peer");P(this,"life",new AbortController);P(this,"inputContext",new AudioContext);P(this,"inputMeter",this.inputContext.createAnalyser());P(this,"inputSource");P(this,"input");P(this,"changing",!1);P(this,"cursor",0);P(this,"timer",0);P(this,"speechAt",0);P(this,"providerDone",!0);P(this,"stopped",!1);P(this,"newQuestion",!1);P(this,"pendingAnswer",!1);P(this,"answerSettled",!1);P(this,"awaitingUser",!1);P(this,"userId",0);P(this,"inputEpoch",0);P(this,"pendingNotice","Preparing the answer. I’ll continue automatically.");P(this,"assistantId",null);P(this,"observed",0);P(this,"reportedAt",0);P(this,"micBuffer",new Float32Array(1024));this.options=s,window.addEventListener("pagehide",this.pageExit),this.inputMeter.fftSize=1024,this.inputContext.resume().catch(()=>{}),this.peer=new Ct({onEvent:n=>this.providerEvent(n),onClose:n=>{this.alive&&(this.set({error:n}),this.end())}}),this.set({})}set(s){this.state={...this.state,...s},this.options.onState(this.state)}async request(s,n){return X(`/live/calls/${this.id}${s}`,{method:n?"POST":"GET",...n?{body:JSON.stringify(n)}:{},signal:this.life.signal})}async microphone(){var n;const s=await navigator.mediaDevices.getUserMedia({audio:{echoCancellation:!0,noiseSuppression:!0,autoGainControl:!0},video:!1});if(!this.alive)throw s.getTracks().forEach(a=>a.stop()),new Error("Call ended");(n=this.inputSource)==null||n.disconnect(),this.inputSource=this.inputContext.createMediaStreamSource(s),this.inputSource.connect(this.inputMeter),this.input=s,this.set({microphone:!0});for(const a of s.getAudioTracks())a.addEventListener("ended",()=>{this.alive&&!this.state.muted&&this.input===s&&(this.set({muted:!0,microphone:!1,notice:"Microphone disconnected. Type, or turn the microphone on again."}),this.peer.stopInput())});return s}silentInput(){const s=this.inputContext.createMediaStreamDestination(),n=this.inputContext.createConstantSource();return n.offset.value=0,n.connect(s),n.start(),s.stream}async start(s,n){var a,i;try{if(await(n==null?void 0:n()),!this.alive)return;this.set({notice:"Connecting your call. Your microphone is still off."}),this.id=crypto.randomUUID();const l=await X("/live/calls",{method:"POST",body:JSON.stringify({syncId:s,requestId:this.id}),signal:this.life.signal});if(l.id!==this.id)throw new Error("The call reservation identity did not match.");if(!this.alive){X(`/live/calls/${this.id}/end`,{method:"POST",keepalive:!0}).catch(()=>{});return}if(document.visibilityState!=="visible")throw new Error("History is ready. Return to this page and start the call again to enable the microphone.");this.set({historyReady:!0,startedAt:l.startedAt,notice:"History is ready. Waiting for microphone permission…"}),this.poll();let r;try{r=await this.microphone(),this.set({notice:""})}catch{if(!this.alive)return;r=this.silentInput(),this.set({muted:!0,notice:"Microphone unavailable. You can type instead."})}if(this.input=r,await this.peer.open(r,async(p,u)=>(await X(`/live/calls/${l.id}/connect`,{method:"POST",body:JSON.stringify({sdp:p}),signal:u})).sdp),!this.alive)return;try{(i=(a=this.options).onPlayback)==null||i.call(a,{text:"",samples:new Float32Array(0),sampleRate:0,duration:1/0,startedAt:0,now:()=>this.peer.clock,level:()=>this.peer.level})}catch{}this.set({phase:this.state.replyPendingSince?"thinking":"listening"}),this.timer=window.setInterval(()=>this.meter(),80)}catch(l){this.alive&&(this.set({error:l instanceof Error?l.message:"Live voice could not start"}),await this.end())}}providerEvent(s){var n,a;this.alive&&(s.type==="input_transcript.added"&&this.stopped&&this.newQuestion&&(this.stopped=!1,this.peer.muteOutput(!1),this.set({notice:""})),s.type==="turn.created"&&((n=s.turn)==null?void 0:n.role)==="assistant"&&(this.stopped&&this.newQuestion&&(this.stopped=!1,this.newQuestion=!1,this.peer.muteOutput(!1)),this.providerDone=!1),s.type==="output_transcript.added"&&!this.stopped&&(this.providerDone=!1,this.state.voiceInterruption||this.peer.gateInput(!1)),s.type==="turn.done"&&((a=s.turn)==null?void 0:a.role)==="assistant"&&(this.providerDone=!0))}meter(){var i,l;if(!this.alive)return;const s=performance.now(),n=this.peer.level;let a=0;this.state.muted||(this.inputMeter.getFloatTimeDomainData(this.micBuffer),a=Math.sqrt(this.micBuffer.reduce((r,p)=>r+p*p,0)/this.micBuffer.length)*10),this.stopped&&a>.08&&(this.newQuestion=!0),(l=(i=this.options).onLevel)==null||l.call(i,Math.min(1,Math.max(n,a))),n>.02?(this.speechAt=s,this.observed+=80,this.state.phase!=="speaking"&&this.set({phase:"speaking"}),this.state.voiceInterruption||this.peer.gateInput(!1),this.assistantId&&s-this.reportedAt>1e3&&(this.reportedAt=s,this.request("/observed",{messageId:this.assistantId,milliseconds:this.observed}).catch(()=>{}))):(this.providerDone||this.pendingAnswer||this.answerSettled)&&s-this.speechAt>400&&this.state.phase==="speaking"&&(this.set({phase:this.state.replyPendingSince?"thinking":"listening"}),this.peer.gateInput(!this.state.muted)),this.peer.audioState==="suspended"&&this.state.phase!=="paused"&&this.set({phase:"paused"})}async poll(){var s,n;try{for(;this.alive;){const a=await this.request(`/events?after=${this.cursor}`);if(!this.alive)return;for(const i of a.events){if(this.cursor=i.sequence,i.type==="sources"&&this.set({evidence:i.evidence}),i.type==="message"){if(i.role==="user"){if(i.id<this.userId)continue;i.id>this.userId&&(this.awaitingUser||this.inputEpoch++,this.pendingAnswer=!1,this.answerSettled=!1,this.set({answer:"",error:"",replyPendingSince:this.awaitingUser?this.state.replyPendingSince:0,...!this.awaitingUser&&!this.stopped?{phase:"hearing"}:{},...this.state.notice===this.pendingNotice?{notice:""}:{}}),this.awaitingUser=!1),this.userId=i.id,this.set({question:i.text}),i.final&&!this.answerSettled&&(!this.stopped||this.newQuestion)&&(this.pendingAnswer=!0,this.set({replyPendingSince:this.state.replyPendingSince||Date.now(),...["speaking","paused"].includes(this.state.phase)?{}:{phase:"thinking"}}))}else this.assistantId!==i.id&&(this.assistantId=i.id,this.observed=0),this.set({turnId:i.id,answer:i.text,evidence:i.evidence});(n=(s=this.options).onTurn)==null||n.call(s,i.role==="user"?i.text:"",i.role==="assistant"?i.text:"",i.evidence,i.id)}i.type==="answer_pending"&&i.id===this.userId&&!this.awaitingUser&&(!this.stopped||this.newQuestion)&&(this.pendingAnswer=i.pending===!0,this.answerSettled=!this.pendingAnswer,this.set({replyPendingSince:this.pendingAnswer?this.state.replyPendingSince||Date.now():0,...["thinking","listening","hearing"].includes(this.state.phase)?{phase:this.pendingAnswer?"thinking":"listening"}:{},...!this.state.notice||this.state.notice===this.pendingNotice?{notice:this.pendingAnswer?this.pendingNotice:""}:{},...i.error?{error:i.error}:{}})),i.type==="error"&&this.set({error:i.error})}if(!a.active){await this.end();return}await new Promise(i=>setTimeout(i,250))}}catch(a){this.alive&&(this.set({error:a instanceof Error?a.message:"Live connection lost"}),await this.end())}}async sendText(s){if(!this.alive||!this.id||!s.trim()||s.length>2e3)return;const n=++this.inputEpoch;this.newQuestion=!0,this.awaitingUser=!0,this.answerSettled=!1,this.pendingAnswer=!1,this.set({phase:"thinking",error:"",question:s,answer:"",replyPendingSince:Date.now()});try{await this.request("/text",{question:s,requestId:crypto.randomUUID()}),this.alive&&n===this.inputEpoch&&this.stopped&&(this.stopped=!1,this.peer.muteOutput(!1),this.set({notice:""}))}catch(a){this.alive&&n===this.inputEpoch&&(this.awaitingUser=!1,this.pendingAnswer=!1,this.answerSettled=!0,this.set({phase:"listening",replyPendingSince:0,error:a instanceof Error?a.message:"Question could not be sent"}))}}async toggleMute(){var s;if(!(!this.alive||this.changing)){this.changing=!0;try{if(!this.state.muted)this.set({muted:!0}),this.peer.stopInput(),(s=this.inputSource)==null||s.disconnect();else{const n=await this.microphone();await this.peer.replaceInput(n),this.alive&&(this.set({muted:!1,notice:""}),this.peer.gateInput(this.state.voiceInterruption||this.state.phase!=="speaking"))}}catch{this.alive&&this.set({muted:!0,notice:"Microphone unavailable. You can type instead."})}finally{this.changing=!1}}}setVoiceInterruption(s){this.set({voiceInterruption:s}),this.peer.gateInput(!this.state.muted&&(s||this.state.phase!=="speaking"))}async interrupt(){if(this.alive){this.inputEpoch++,this.pendingAnswer=!1,this.awaitingUser=!1,this.answerSettled=!0,this.stopped=!0,this.newQuestion=!1,this.peer.muteOutput(!0),this.peer.gateInput(!this.state.muted),this.set({phase:"listening",replyPendingSince:0,notice:"Reply muted locally; a stop request was sent. Ask another question to continue."});try{await this.request("/interrupt",{})}catch{this.alive&&(this.set({error:"The remote stop could not be confirmed. The call was ended."}),await this.end())}}}async resumeSound(){await this.peer.resume(),this.alive&&this.set({phase:this.state.replyPendingSince?"thinking":"listening"})}async end(){var s,n,a,i,l,r;if(this.alive){this.alive=!1,window.removeEventListener("pagehide",this.pageExit),clearInterval(this.timer),this.life.abort(),(s=this.input)==null||s.getTracks().forEach(p=>p.stop()),(n=this.inputSource)==null||n.disconnect(),this.peer.close(),this.inputContext.close().catch(()=>{});try{(i=(a=this.options).onPlayback)==null||i.call(a,null)}catch{}if(this.pendingAnswer=!1,this.awaitingUser=!1,(r=(l=this.options).onLevel)==null||r.call(l,0),this.set({phase:"ended",muted:!0,notice:"",replyPendingSince:0}),this.id){const p=new AbortController,u=setTimeout(()=>p.abort(),4e3);try{await X(`/live/calls/${this.id}/end`,{method:"POST",keepalive:!0,signal:p.signal})}catch{}finally{clearTimeout(u)}}}}}const _t={connecting:"Getting ready",listening:"Your turn",hearing:"Listening to you",thinking:"Preparing your answer",speaking:"Draken is speaking",paused:"Sound paused",ended:"Call ended"},At=t=>`${Math.floor(t/60)}:${String(t%60).padStart(2,"0")}`;function Tt({sync:t,readiness:s,onPrepareHistory:n,disabled:a,beforeStart:i,onActiveChange:l,onClosed:r,onChat:p,autoStart:u=!1,onAutoStartHandled:j}){const[c,y]=o.useState(null),[h,S]=o.useState(""),[b,w]=o.useState(!1),[d,E]=o.useState(Ze),[C,m]=o.useState(0),[k,x]=o.useState(!1),[v,A]=o.useState(""),[z,ee]=o.useState([]),[I,R]=o.useState(null),[L,ce]=o.useState(""),[re,V]=o.useState(!1),[se,ge]=o.useState(!1),G=o.useRef(null),fe=o.useRef(null),xe=o.useRef(null),De=o.useRef(null),F=o.useRef(null),K=o.useRef(!0),le=o.useRef(!1),ie=o.useRef(!1),[be,Se]=o.useState(!1),Ce=[...t.items,...t.context],de=Ce.find(g=>g.ref===L),te=(s==null?void 0:s.ready)===!0,ye=window.isSecureContext,we=new URL(window.location.href);we.protocol="https:",we.port=String((c==null?void 0:c.httpsPort)||443),o.useEffect(()=>{L&&fe.current&&xe.current&&(fe.current.scrollTop+=xe.current.getBoundingClientRect().top-fe.current.getBoundingClientRect().top)},[L]);const N=async()=>{try{const g=await X("/status");K.current&&(y(g),S(""))}catch(g){K.current&&S(g instanceof Error?g.message:"Could not check ChatGPT voice")}};o.useEffect(()=>{K.current=!0,N();const g=setInterval(()=>{F.current||N()},15e3);return()=>{var _;clearInterval(g),K.current=!1,(_=F.current)==null||_.end()}},[]),o.useEffect(()=>{var g,_,q;b&&!((g=G.current)!=null&&g.open)?(_=G.current)==null||_.showModal():b||(q=G.current)==null||q.close()},[b]),o.useEffect(()=>{if(!b||!d.startedAt||d.phase==="ended")return;const g=()=>m(Math.max(0,Math.floor((Date.now()-d.startedAt)/1e3)));g();const _=setInterval(g,1e3);return()=>clearInterval(_)},[b,d.startedAt,d.phase==="ended"]);const $=async()=>{var g;if(!(F.current||le.current||ie.current||!te)){ie.current=!0,Se(!0),S("");try{if(await i(),!K.current||document.visibilityState!=="visible")return;E({...Ze}),m(0),ee([]),A(""),ce(""),x(!1),V(!1),ge(!1),w(!0),l(!0);const _=new Et({onState:q=>{K.current&&(E(q),!q.microphone&&q.muted&&x(!0))},onLevel:()=>{},onPlayback:q=>{De.current=q},onTurn:(q,Re,es,Le)=>{K.current&&ee(Ve=>Ve.some($e=>$e.id===Le)?Ve.map($e=>$e.id===Le?{id:Le,question:q,answer:Re,refs:es}:$e):[...Ve,{id:Le,question:q,answer:Re,refs:es}])}});F.current=_,F.current===_&&await _.start(t.id)}catch(_){if(await((g=F.current)==null?void 0:g.end()),K.current){const q=_ instanceof Error?_.message:"The call could not start";S(q),F.current&&E(Re=>({...Re,phase:"ended",error:q}))}}finally{ie.current=!1,K.current&&Se(!1)}}};o.useEffect(()=>{!u||a||!te||!c||(j==null||j(),c.installed&&!c.activeCall&&ye&&document.visibilityState==="visible"?$():S("Your snapshot is ready. Start the call explicitly when audio is available and this page is visible."))},[u,a,te,c]);const O=async()=>{var g;if(!le.current){le.current=!0,await((g=F.current)==null?void 0:g.end()),F.current=null,K.current&&(w(!1),R(null),l(!1));try{await r(),await N()}finally{le.current=!1}}},W=async()=>{try{R(await X(`/syncs/${t.id}/history`))}catch(g){S(g instanceof Error?g.message:"Could not load call history")}},ae=async()=>{try{const g=await fetch("/api/voice/certificate",{headers:js(!1)});if(!g.ok)throw new Error("Could not download the local certificate. Check your dashboard login.");const _=URL.createObjectURL(await g.blob()),q=document.createElement("a");q.href=_,q.download="draken-local-root.crt",q.click(),setTimeout(()=>URL.revokeObjectURL(_),1e3)}catch(g){S(g instanceof Error?g.message:"Certificate download failed")}},Be=()=>{var _;if(!v.trim())return;const g=v.trim();A(""),(_=F.current)==null||_.sendText(g)};return e.jsxs(e.Fragment,{children:[e.jsxs("section",{className:"card voice-entry","aria-label":"Voice calls",children:[e.jsxs("div",{className:"voice-entry-main",children:[e.jsx("div",{className:"voice-entry-icon","aria-hidden":"true",children:e.jsx(We,{size:22})}),e.jsxs("div",{children:[e.jsx("h2",{children:"Talk it through. Out loud."}),e.jsx("p",{className:"muted small",children:"Live voice through ChatGPT. Audio goes to OpenAI; replies may paraphrase."})]}),e.jsxs("div",{className:"conversation-actions",children:[e.jsxs("button",{className:"btn btn-secondary",disabled:b||be,onClick:p,children:[e.jsx(ms,{size:16}),"Chat instead"]}),!ye&&(c!=null&&c.httpsPort)?e.jsxs("a",{className:"btn btn-primary",href:we.href,children:["Open secure call page ",e.jsx(Ls,{size:15})]}):e.jsxs("button",{className:"btn btn-primary",disabled:a||be||!te||!(c!=null&&c.installed)||!!(c!=null&&c.activeCall)||!ye,onClick:()=>void $(),children:[e.jsx(We,{size:16}),"Call Draken"]})]})]}),e.jsx("p",{className:"small muted",children:"Relevant earlier history is found automatically. Retrieved excerpts go to ChatGPT, separately from this frozen snapshot; no review or saved decisions change."}),!ye&&e.jsxs("p",{className:"small muted",children:["The microphone needs trusted HTTPS. ",c!=null&&c.httpsPort?"The secure page uses your existing dashboard login. Install the local certificate once on this device before opening it.":"Use localhost, or enable HTTPS on the server."]}),(c==null?void 0:c.certificateAvailable)&&e.jsxs("details",{className:"voice-history",children:[e.jsx("summary",{children:"First-time browser setup"}),e.jsx("p",{className:"small",children:"Trust only your own Draken server’s certificate. This is a one-time device setup, not another account or voice subscription."}),e.jsx("button",{className:"btn btn-secondary",onClick:()=>void ae(),children:"Download local certificate"}),e.jsxs("ul",{className:"small",children:[e.jsxs("li",{children:[e.jsx("strong",{children:"Windows:"})," open the downloaded certificate → Install Certificate → Current User → place in Trusted Root Certification Authorities."]}),e.jsxs("li",{children:[e.jsx("strong",{children:"macOS:"})," import into Keychain Access → login keychain. Open its Trust section and choose Always Trust."]}),e.jsxs("li",{children:[e.jsx("strong",{children:"Firefox/Linux:"})," Settings → Privacy & Security → Certificates → View Certificates → Authorities → Import. Trust it to identify websites."]})]}),e.jsxs("p",{className:"small muted",children:["Restart the browser if needed, open the secure page, sign in, and allow the microphone when you start a call. Keep the server’s private keys private. See ",e.jsx("code",{children:"VOICE.md"})," for an SSH-tunnel alternative."]})]}),t.status==="open"&&e.jsx("p",{className:"small muted",role:"status",children:te?`Ready to call. History cutoff: ${s!=null&&s.before?new Date(s.before).toLocaleString():"prepared snapshot"}. Refresh history for later work.`:s?s.preparing?"Preparing history before calling. Your microphone is off.":s.briefingReady?"History needs preparation before you can call.":"Prepare the briefing first.":"Checking call readiness…"}),t.status==="open"&&(s==null?void 0:s.briefingReady)&&!s.preparing&&e.jsx("button",{className:"btn btn-secondary",disabled:a||be,onClick:n,children:te?"Refresh history":"Prepare history"}),(s==null?void 0:s.error)&&!te&&e.jsx("p",{className:"small",role:"alert",children:s.error}),t.status!=="open"&&e.jsx("p",{className:"small muted",children:"This sync is closed. Start a new sync for another call."}),c&&!c.installed&&e.jsxs("p",{className:"small muted",children:["ChatGPT voice needs server setup and sign-in: ",e.jsx("code",{children:"npm run voice:realtime:setup"}),", then ",e.jsx("code",{children:"npm run voice:realtime:login"}),"."]}),h&&e.jsxs("p",{className:"small",role:"alert",children:[h," ",e.jsx("button",{className:"btn btn-secondary",onClick:()=>void N(),children:"Retry"})]}),(c==null?void 0:c.activeCall)&&!b&&e.jsxs("div",{className:"small voice-reconnect",children:["A call is still open in another tab or device.",e.jsx("button",{className:"btn btn-secondary",disabled:a,onClick:()=>{window.confirm("End the existing voice call? Its completed transcript is kept.")&&X(`/live/calls/${c.activeCall.id}/end`,{method:"POST",body:"{}"}).then(N).catch(g=>S(g.message))},children:"End previous call"})]}),e.jsxs("details",{className:"voice-history",onToggle:g=>{g.currentTarget.open&&W()},children:[e.jsx("summary",{children:"Call history"}),(I==null?void 0:I.length)===0&&e.jsx("p",{className:"muted small",children:"No calls yet. Transcripts are saved here; raw audio is not recorded."}),I==null?void 0:I.map(g=>e.jsxs("details",{className:"voice-history-call",children:[e.jsxs("summary",{children:[new Date(g.started_at).toLocaleString()," · ",g.turns.length," ",g.mode==="native"?"messages":"turns"," · ",g.status]}),e.jsx("p",{className:"small muted",children:g.end_reason||"Call in progress"}),g.mode==="native"?e.jsx("p",{className:"small muted",children:"Ordered live transcripts, not verified question–answer pairs. Sources are supplied context, not verified citations. Exact playback is not confirmed."}):e.jsx("p",{className:"small muted",children:"Historical call from the retired local speech engine. These records are preserved; this engine cannot start new calls."}),g.turns.map(_=>e.jsxs("div",{className:"voice-history-turn",children:[_.question&&e.jsxs(e.Fragment,{children:[e.jsx("strong",{className:"message-author",children:"You"}),e.jsx("p",{className:"prose",children:_.question})]}),(_.answer||!_.question||g.mode!=="native")&&e.jsxs(e.Fragment,{children:[e.jsxs("strong",{className:"message-author",children:["Draken · ",_.status]}),e.jsx(Ae,{text:`${_.answer||_.error||"No reply generated."} ${JSON.parse(_.evidence_json).map(q=>`[${q}]`).join(" ")}`,evidence:Ce}),_.status!=="completed"&&e.jsxs("p",{className:"small muted",children:["Generated text is shown above. ",_.heard_text?`Confirmed played: ${_.heard_text}`:"Playback was not confirmed."]})]})]},_.id))]},g.id))]})]}),e.jsxs("dialog",{ref:G,className:"voice-dialog","aria-labelledby":"voice-title",onCancel:g=>{g.preventDefault(),O()},children:[e.jsxs("div",{className:"voice-dialog-header",children:[e.jsxs("div",{children:[e.jsx("span",{className:"eyebrow",children:"DRAKEN / VOICE SYNC"}),e.jsxs("h2",{id:"voice-title",children:["Sync #",t.id]})]}),e.jsx("span",{className:"voice-clock","aria-label":"Call duration",children:At(C)}),e.jsx("button",{className:"icon-button","aria-label":"Close call",onClick:()=>void O(),children:e.jsx(Qe,{size:18})})]}),e.jsxs("div",{className:"voice-call-body",children:[d.historyReady?e.jsxs("div",{className:"voice-scene",children:[b&&d.phase!=="ended"?e.jsx(Es,{playback:De,mode:d.phase==="speaking"?"speaking":d.phase==="hearing"?"listening":d.replyPendingSince&&!d.error?"thinking":"idle"}):e.jsx("img",{loading:"lazy",className:"voice-scene-poster",src:"/persona/call-poster.webp",alt:"Draken’s workshop"}),e.jsx(St,{call:d,historyLookup:se})]}):e.jsxs("section",{className:"voice-preparation","aria-label":"Call preparation",children:[e.jsx("h3",{children:d.phase==="ended"?"Call could not start":"Connecting your call"}),e.jsx("p",{className:"small muted",children:"Your microphone is off until the call is ready."})]}),e.jsx("p",{className:"sr-only",role:"status","aria-label":"Call state","aria-live":"polite",children:d.muted&&d.phase==="listening"?"Microphone muted":_t[d.phase]})]}),d.error&&e.jsx("div",{className:"alert error",role:"alert",children:d.error}),d.error&&d.question&&d.phase==="listening"&&e.jsx("button",{className:"btn btn-primary",onClick:()=>{var g;return void((g=F.current)==null?void 0:g.sendText(d.question))},children:"Retry question"}),d.phase==="paused"&&e.jsx("button",{className:"btn btn-primary",onClick:()=>{var g;return void((g=F.current)==null?void 0:g.resumeSound())},children:"Resume sound"}),e.jsxs("div",{className:"voice-controls",children:[e.jsxs("button",{className:`btn btn-secondary ${d.muted?"is-muted":""}`,disabled:d.phase==="connecting"||d.phase==="ended",onClick:()=>{var g;return void((g=F.current)==null?void 0:g.toggleMute())},children:[d.muted?e.jsx(Hs,{size:18}):e.jsx(Bs,{size:18}),d.muted?d.microphone?"Unmute":"Enable mic":"Mute"]}),e.jsxs("button",{className:"btn btn-secondary",disabled:!["thinking","speaking","paused"].includes(d.phase),onClick:()=>{var g;return void((g=F.current)==null?void 0:g.interrupt().catch(()=>{}))},children:[e.jsx(gs,{size:15}),"Stop reply"]}),e.jsxs("button",{className:"btn btn-danger",onClick:()=>void O(),children:[e.jsx(Vs,{size:18}),d.phase==="ended"?"Close":"End call"]})]}),e.jsxs("div",{className:"voice-options",children:[e.jsxs("button",{className:"voice-keyboard-toggle","aria-pressed":d.voiceInterruption,disabled:d.phase==="connecting"||d.phase==="ended",onClick:()=>{var g;return(g=F.current)==null?void 0:g.setVoiceInterruption(!d.voiceInterruption)},children:[e.jsx($s,{size:16}),"Headphone mode"]}),e.jsxs("button",{className:"voice-keyboard-toggle",onClick:()=>x(g=>!g),"aria-expanded":k,children:[e.jsx(Os,{size:16}),k?"Hide keyboard":"Type a question"]})]}),k&&e.jsxs("form",{className:"voice-compose",onSubmit:g=>{g.preventDefault(),Be()},children:[e.jsx("input",{className:"input","aria-label":"Type a question for this call",placeholder:"Or ask here…",maxLength:2e3,disabled:d.phase==="connecting"||d.phase==="ended",value:v,onChange:g=>A(g.target.value)}),e.jsx("button",{className:"btn btn-primary","aria-label":"Send voice-call question",disabled:!v.trim()||d.phase==="connecting"||d.phase==="ended",children:e.jsx(ps,{size:18})})]}),e.jsxs("details",{className:"voice-conversation",open:re,onToggle:g=>V(g.currentTarget.open),children:[e.jsx("summary",{children:"Conversation & details"}),e.jsxs("div",{className:"voice-call-details",ref:fe,children:[d.notice&&e.jsx("p",{className:"small muted voice-notice",children:d.notice}),e.jsx(He,{enabled:b&&d.historyReady&&(!!d.replyPendingSince||["connecting","thinking"].includes(d.phase)),onLookupChange:ge}),e.jsx("p",{className:"small muted",children:d.phase==="speaking"?d.voiceInterruption?"Speak to interrupt. Use headphones to avoid speaker feedback.":"Listening pauses during replies to prevent echo. Tap Stop reply to speak.":"Speak naturally. A short pause sends your question."}),e.jsx("div",{className:"voice-transcript",children:z.map(g=>e.jsxs("div",{children:[g.question&&e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"You"}),e.jsx("p",{children:g.question})]}),g.answer&&e.jsxs(e.Fragment,{children:[e.jsx("strong",{children:"Draken · generated reply"}),e.jsx("p",{className:g.id===d.turnId?"voice-answer":void 0,children:g.answer})]})]},g.id))}),!z.length&&e.jsx("p",{className:"small muted",children:"No transcript yet."}),e.jsx("p",{className:"small muted",children:"Live generated transcripts, not word-timed subtitles. Exact playback and agreement are not confirmed. Full text is retained here even when the scene shows only its latest lines."}),d.evidence.length>0&&e.jsxs("details",{className:"voice-history",children:[e.jsxs("summary",{children:["Sources supplied (",d.evidence.length,")"]}),e.jsx("p",{className:"small muted",children:"Context available to the voice model, not verified citations for every spoken claim."}),e.jsx("div",{className:"voice-sources",children:d.evidence.map(g=>e.jsx("button",{className:"citation",onClick:_=>{const q=_.currentTarget.closest("details");q&&(q.open=!1),ce(L===g?"":g)},children:g.startsWith("H")?`History ${g.slice(-6)}`:`Source ${g}`},g))})]}),/^H[a-f0-9]{24}$/.test(L)&&e.jsxs("section",{className:"voice-source",ref:xe,children:[e.jsx("button",{className:"btn btn-secondary",onClick:()=>ce(""),children:"Close historical source"}),e.jsx(Ns,{reference:L})]}),de&&e.jsxs("section",{className:"voice-source",ref:xe,children:[e.jsxs("div",{className:"section-heading",children:[e.jsxs("strong",{children:[de.ref," · ",de.session_name||de.cwd]}),e.jsx("button",{className:"icon-button","aria-label":"Close source",onClick:()=>ce(""),children:e.jsx(Qe,{size:16})})]}),e.jsx("pre",{children:de.text})]})]})]}),e.jsxs("div",{className:"voice-footer",children:[e.jsx(Ms,{size:14}),e.jsx("span",{children:"Experimental live audio to OpenAI · Generated, not verified · 30-minute limit"})]})]})]})}function Pt({sync:t,readiness:s,draft:n,setDraft:a,disabled:i,sending:l,onSend:r,onCancel:p,onPrepareHistory:u,onVoice:j}){const c=t.tree.run,y=t.status==="open",h=t.busy&&(c==null?void 0:c.status)==="running"&&!!c.question,S=!t.busy&&!!(c!=null&&c.question)&&["failed","cancelled","interrupted"].includes((c==null?void 0:c.status)||""),b=l?n:h||S?c==null?void 0:c.question:null,w=h||l,d=l?"Sending your message…":c!=null&&c.stage.includes("Searching")?"Searching your prepared history…":c!=null&&c.stage.includes("Reconciling")?"Checking later updates…":c!=null&&c.stage.includes("Checking evidence")?"Checking source references…":c!=null&&c.stage.includes("Thinking")?"Draken is thinking…":"Reading the snapshot context…",E=o.useRef(null),C=o.useRef(!0);o.useEffect(()=>{C.current&&E.current&&(E.current.scrollTop=E.current.scrollHeight)},[t.messages.length,b,w,d]);const m=[...t.items,...t.context],k=i||!y||!(s!=null&&s.ready);return e.jsxs("section",{className:"card text-chat","aria-label":"Chat with Draken",children:[e.jsxs("header",{className:"chat-heading",children:[e.jsx("img",{className:"chat-avatar",src:"/persona/chat-avatar.webp",alt:"Draken",width:"52",height:"52"}),e.jsxs("div",{children:[e.jsx("h2",{children:"Chat with Draken"}),e.jsx("p",{className:"small muted",children:"Same history. No microphone or audio."})]}),e.jsx("button",{type:"button",className:"btn btn-ghost",onClick:j,children:"Voice & call history"})]}),e.jsxs("div",{className:"chat-thread",ref:E,onScroll:()=>{const x=E.current;x&&(C.current=x.scrollHeight-x.scrollTop-x.clientHeight<80)},children:[!t.messages.length&&!b&&e.jsxs("div",{className:"chat-welcome",children:[e.jsx("h3",{children:"What would you like to pick up?"}),e.jsx("p",{children:"Ask about a project, a decision, or what still needs your attention. Draken will use the snapshot and prepared original history."})]}),t.messages.map(x=>e.jsxs("article",{className:`chat-message ${x.role}`,children:[x.role==="assistant"&&e.jsx("img",{className:"chat-avatar",src:"/persona/chat-avatar.webp",alt:"",width:"36",height:"36"}),e.jsxs("div",{className:"chat-bubble",children:[e.jsxs("div",{className:"chat-author",children:[e.jsx("strong",{children:x.role==="user"?"You":"Draken"}),e.jsx("time",{dateTime:x.created_at,children:new Date(x.created_at).toLocaleTimeString(void 0,{hour:"2-digit",minute:"2-digit"})})]}),e.jsx(Ae,{text:x.content,evidence:m})]})]},x.id)),b&&!(c!=null&&c.request_id&&(h||S&&!l))&&e.jsx("article",{className:"chat-message user",children:e.jsxs("div",{className:"chat-bubble",children:[e.jsx("strong",{children:"You"}),e.jsx("p",{className:"prose",children:b})]})}),w&&e.jsxs("div",{className:"chat-message assistant",children:[e.jsx("img",{className:"chat-avatar",src:"/persona/chat-avatar.webp",alt:"",width:"36",height:"36"}),e.jsxs("div",{className:"chat-bubble chat-thinking",role:"status","aria-label":"Chat status","aria-live":"polite",children:[e.jsx("span",{className:"spinner","aria-hidden":"true"}),d,e.jsx("span",{className:"small muted",children:"Your answer will appear here when it’s ready."})]})]}),S&&e.jsxs("div",{className:"alert warning",role:"alert",children:[e.jsx("strong",{children:(c==null?void 0:c.status)==="failed"?"Reply failed.":"Reply stopped."}),e.jsx("p",{children:(c==null?void 0:c.error)||"The question is retained. Nothing was marked reviewed."}),e.jsx("button",{className:"btn btn-secondary",disabled:k,onClick:()=>r((c==null?void 0:c.question)||""),children:"Retry chat reply"})]})]}),y&&e.jsxs(e.Fragment,{children:[!w&&e.jsx("p",{className:"small muted",role:"status",children:s!=null&&s.ready?`History cutoff: ${s.before?new Date(s.before).toLocaleString():"prepared snapshot"}. Refresh for later work.`:t.busy?"Preparing the briefing and history for chat…":s!=null&&s.briefingReady?"Prepare history before sending a message.":"Prepare the briefing and history first."}),(s==null?void 0:s.error)&&e.jsx("p",{role:"alert",className:"small",children:s.error}),e.jsxs("form",{className:"chat-compose",onSubmit:x=>{x.preventDefault(),!k&&n.trim()&&(C.current=!0,r())},children:[e.jsx("label",{htmlFor:"chat-question",className:"sr-only",children:"Message Draken"}),e.jsx("textarea",{id:"chat-question",rows:3,maxLength:4e3,value:n,disabled:k,onChange:x=>a(x.target.value),placeholder:"Ask Draken…",onKeyDown:x=>{var v;x.key==="Enter"&&!x.shiftKey&&!x.nativeEvent.isComposing&&(x.preventDefault(),n.trim()&&!k&&((v=x.currentTarget.form)==null||v.requestSubmit()))}}),e.jsxs("div",{className:"chat-compose-footer",children:[e.jsx("span",{className:"small muted",children:"Enter to send · Shift+Enter for a new line"}),h?e.jsxs("button",{type:"button",className:"btn btn-secondary",onClick:p,children:[e.jsx(gs,{size:14}),"Stop reply"]}):e.jsxs("button",{className:"btn btn-primary",disabled:k||!n.trim(),children:[e.jsx(ps,{size:16}),"Send message"]})]})]}),(s==null?void 0:s.briefingReady)&&!s.preparing&&!w&&e.jsx("button",{className:"btn btn-secondary chat-refresh",disabled:i,onClick:u,children:s.ready?"Refresh history":"Prepare history"})]}),!y&&e.jsx("p",{className:"small muted",children:"This sync is closed. Its chat is preserved; start a new sync to continue."}),e.jsx("p",{className:"small muted chat-boundary",children:"Messages stay with this sync. Calls remain in call history. Chatting never marks anything reviewed or saves decisions for you."})]})}function It({id:t,chat:s=!1,callIntent:n,consumeIntent:a,navigate:i,setGuard:l}){var be,Se,Ce,de,te,ye,we;const[r,p]=o.useState(null),[u,j]=o.useState(null),[c,y]=o.useState(""),[h,S]=o.useState(""),[b,w]=o.useState(!1),[d,E]=o.useState(!1),[C,m]=o.useState(""),[k,x]=o.useState(""),[v,A]=o.useState(""),z=o.useRef(!0),ee=o.useRef(null),I=N=>{z.current&&(p(N),m(N.decisions),x(N.carry_forward))},R=async(N,$)=>{y(N),S("");try{await $()}catch(O){z.current&&S(O instanceof Error?O.message:"Something went wrong")}finally{z.current&&y("")}};o.useEffect(()=>(z.current=!0,Ye(t).then(I).catch(N=>{z.current&&S(N.message)}),()=>{z.current=!1}),[t]),o.useEffect(()=>{if(!(r!=null&&r.busy))return;let N=!1,$;const O=async()=>{try{const W=await rt(t);if(N)return;if(W.busy)p(ae=>ae&&{...ae,tree:W});else{const ae=await Ye(t);N||I(ae);return}}catch(W){N||S(W instanceof Error?W.message:"Could not refresh progress")}N||($=setTimeout(()=>void O(),1e3))};return O(),()=>{N=!0,clearTimeout($)}},[t,r==null?void 0:r.busy]),o.useEffect(()=>{j(null);const N=new AbortController;let $;const O=async()=>{try{const W=await(s?it:os)(t,N.signal);N.signal.aborted||j(W)}catch{N.signal.aborted||j(null)}N.signal.aborted||($=setTimeout(()=>void O(),r!=null&&r.busy?1e3:3e3))};return O(),()=>{N.abort(),clearTimeout($)}},[t,r==null?void 0:r.busy,r==null?void 0:r.briefing,r==null?void 0:r.status,b,s]);const L=!!(r&&(C!==r.decisions||k!==r.carry_forward)),ce=!!v.trim();o.useEffect(()=>{l(()=>!(L||ce||b)||window.confirm(b?"Leave this page and end the call?":"Leave with unsaved notes or an unsent message?"));const $=O=>{(L||ce||b)&&(O.preventDefault(),O.returnValue="")};return window.addEventListener("beforeunload",$),()=>{l(null),window.removeEventListener("beforeunload",$)}},[L,ce,b,l]);const re=()=>{a(),E(!1)},V=!!(c||r!=null&&r.busy||b),se=(r==null?void 0:r.status)==="open",ge=r?[...r.items,...r.context]:[],G=ge.some(N=>N.unavailable),fe=()=>void R("Preparing your conversation…",async()=>{if(r){if(s&&L)throw new Error("Save or undo your note edits before preparing chat.");E(!s),L&&await Ee(t,C,k),I(await ht(t))}}),xe=()=>void R("Preparing history for your conversation…",async()=>{if(s&&L)throw new Error("Save or undo your note edits before refreshing history.");re(),j(null),L&&await Ee(t,C,k),I(await ot(t))}),De=(N=v)=>void R("Starting discussion…",async()=>{L&&await Ee(t,C,k),I(await ut(t,N))}),F=(N=v)=>void R("Sending message…",async()=>{var W,ae;if(re(),L)throw new Error("Save your note edits, or undo them, before sending a message. Chat does not save decisions for you.");const $=((W=ee.current)==null?void 0:W.text)===N?ee.current:{text:N,id:vs()};ee.current=$;let O;try{O=await st(t,N,$.id)}catch(Be){const g=await Ye(t).catch(()=>null);if(((ae=g==null?void 0:g.tree.run)==null?void 0:ae.request_id)!==$.id)throw Be;O=g}I(O),A(""),ee.current=null}),K=()=>{var N;return(N=r==null?void 0:r.tree.run)!=null&&N.question?s||r.tree.run.request_id?F(r.tree.run.question):De(r.tree.run.question):fe()},le=()=>{re(),R("Stopping preparation…",async()=>{await dt(t)})},ie=!(r!=null&&r.busy)&&(r==null?void 0:r.tree.run)&&["failed","cancelled","interrupted"].includes(r.tree.run.status);return o.useEffect(()=>{(ie||u!=null&&u.error)&&re()},[ie,u==null?void 0:u.error]),e.jsxs("main",{className:"sync-detail",children:[e.jsxs("a",{className:"back-link",href:"/",onClick:N=>me(N,i,"/"),children:[e.jsx(qs,{size:16}),"All syncs"]}),h&&e.jsx("div",{className:"alert error",role:"alert",children:h}),!r&&!h&&e.jsx("p",{role:"status",children:"Opening sync…"}),r&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"page-heading",children:[e.jsxs("div",{children:[e.jsx("span",{className:"eyebrow",children:"FROZEN CONVERSATION"}),e.jsxs("h1",{children:["Sync #",t]}),e.jsxs("p",{className:"muted",children:["Snapshot created ",new Date(r.snapshot_at).toLocaleString()," · ",r.item_count," entries · ",e.jsx("span",{className:`status ${r.status}`,children:r.status==="completed"?"reviewed":r.status})]}),e.jsx(bs,{cost:r.aggregation_cost})]}),se&&e.jsxs("button",{className:"btn btn-secondary",disabled:V||G||!!(r.tree.run&&!r.tree.complete),onClick:()=>{window.confirm(`Mark these ${r.item_count} snapshot entries reviewed? Later activity is not affected. This does not mean every spoken suggestion was agreed.`)&&R("Marking snapshot reviewed…",async()=>{I(await ft(t,C,k))})},children:[e.jsx(Ds,{size:16}),"Mark reviewed"]})]}),G&&e.jsxs("div",{className:"alert warning",role:"alert",children:[e.jsx("strong",{children:"Original session evidence unavailable."}),e.jsx("p",{children:"Restore the original session files to inspect the missing excerpts, prepare replies, call or mark this snapshot reviewed. Your conversation and saved notes are still available; Draken keeps pointers, not copies of original session text."})]}),(c||r.busy)&&!(s&&(c==="Sending message…"||(be=r.tree.run)!=null&&be.question&&r.tree.run.status==="running"))&&e.jsxs("div",{className:"working",role:"status",children:[e.jsx("span",{className:"spinner"}),c||(r.recap_state==="running"?"Making a short conversation recap…":u!=null&&u.preparing?"Preparing searchable history…":((Se=r.tree.run)==null?void 0:Se.stage)||"Preparing your conversation…"),r.busy&&e.jsx("button",{className:"btn btn-secondary",onClick:le,children:"Cancel preparation"})]}),e.jsx(He,{enabled:r.busy}),r.busy&&!((Ce=r.tree.run)!=null&&Ce.question)&&r.recap_state!=="running"&&e.jsx("p",{className:"small muted",children:"The complete new snapshot is being reconciled. Large histories can take a while. Leaving or reloading will not start your microphone."}),ie&&!(s&&((de=r.tree.run)!=null&&de.question))&&e.jsxs("div",{className:"alert warning",role:"alert",children:[e.jsx("strong",{children:(te=r.tree.run)!=null&&te.question?"Reply stopped.":"Preparation stopped."}),e.jsx("p",{children:((ye=r.tree.run)==null?void 0:ye.error)||"Your snapshot is retained. Nothing was marked reviewed."}),e.jsx("button",{className:"btn btn-primary",disabled:V||G,onClick:K,children:(we=r.tree.run)!=null&&we.question?"Retry reply":s?"Retry preparation":"Retry preparation & call"})]}),se&&!r.briefing&&!r.busy&&!ie&&r.snapshot_version===2&&e.jsx("button",{className:"btn btn-primary",disabled:V||G,onClick:fe,children:s?"Prepare for chat":"Prepare & call"}),s?e.jsx(Pt,{sync:r,readiness:u,draft:v,setDraft:A,disabled:V||G,sending:c==="Sending message…",onSend:F,onCancel:le,onPrepareHistory:xe,onVoice:()=>i(`/syncs/${t}`)}):e.jsx(Tt,{sync:r,readiness:u,onPrepareHistory:xe,disabled:V||G,onActiveChange:w,onChat:()=>{re(),i(`/syncs/${t}/chat`)},autoStart:(n||d)&&!ie&&!G,onAutoStartHandled:re,beforeStart:async()=>{L&&I(await Ee(t,C,k));const N=await os(t);if(j(N),!N.ready)throw new Error("History needs preparation before calling. Use Prepare history first.")},onClosed:async()=>{await R("Saving a short recap…",async()=>{I(await rs(t))})}},t),e.jsxs("section",{className:"card recap-card",children:[e.jsxs("div",{className:"section-heading",children:[e.jsx("h2",{children:"At a glance"}),e.jsx("button",{className:"btn btn-secondary",disabled:V,onClick:()=>void R("Summarizing the conversation…",async()=>I(await rs(t))),children:r.recap?"Refresh recap":"Make recap"})]}),e.jsx("p",{className:"prose",children:r.recap||"Use Make recap to condense this conversation. Ending a call also requests a recap. The full briefing and original history remain below."}),e.jsx("p",{className:"small muted",children:"Automatic summary, not saved decisions or proof of agreement."}),r.recap_error&&e.jsx("p",{role:"alert",className:"small",children:r.recap_error})]}),r.memory.length>0&&e.jsxs("details",{className:"detail-section",children:[e.jsx("summary",{children:"Previous sync recaps"}),r.memory.map(N=>e.jsxs("article",{className:"memory-recap",children:[e.jsxs("a",{href:`/syncs/${N.sync_id}`,onClick:$=>me($,i,`/syncs/${N.sync_id}`),children:["Sync #",N.sync_id]})," ",e.jsx("span",{className:"small muted",children:N.status==="open"?"not marked reviewed":N.status||"historical"}),e.jsx("p",{className:"prose",children:N.recap||"No automatic recap in this older snapshot."}),N.decisions&&e.jsxs("p",{className:"small prose",children:["Saved decisions: ",N.decisions]}),N.carry_forward&&e.jsxs("p",{className:"small prose",children:["Carried forward: ",N.carry_forward]})]},N.sync_id))]}),e.jsxs("details",{className:"detail-section",open:!r.messages.length&&!!r.briefing,children:[e.jsx("summary",{children:"Full briefing"}),e.jsxs("section",{className:"briefing-card",children:[e.jsx("p",{className:"small muted",children:"This snapshot contains the entries captured during preparation, not a live view. Check the original source dates in the evidence."}),(u==null?void 0:u.before)&&e.jsxs("p",{className:"small muted",children:["Conversation history cutoff: ",new Date(u.before).toLocaleString(),". Later activity waits for another preparation."]}),r.briefing?e.jsx(Ae,{text:r.briefing,evidence:ge}):e.jsx("p",{children:"No briefing yet."}),r.snapshot_version<2&&e.jsxs("div",{className:"alert warning",children:["This is a historical capped snapshot. Notes and discussion are preserved.",se&&e.jsx("button",{className:"btn btn-secondary",disabled:V,onClick:()=>{window.confirm("Expand this legacy snapshot to currently eligible history? Existing notes and citations are retained.")&&R("Expanding snapshot…",async()=>I((await lt(t)).sync))},children:"Expand to full history"})]})]})]}),!s&&e.jsxs("details",{className:"detail-section",children:[e.jsxs("summary",{children:["Saved text conversation (",r.messages.length,")"]}),e.jsxs("section",{className:"discussion",children:[r.messages.map(N=>e.jsxs("div",{className:`message ${N.role}`,children:[e.jsx("span",{className:"message-author",children:N.role==="user"?"You":"Draken"}),e.jsx(Ae,{text:N.content,evidence:ge})]},N.id)),e.jsx("button",{className:"btn btn-secondary",disabled:b,onClick:()=>{re(),i(`/syncs/${t}/chat`)},children:"Open chat"})]})]}),e.jsxs("details",{className:"detail-section",children:[e.jsxs("summary",{children:["Decisions & carry-forward",L?" · unsaved":""]}),e.jsxs("section",{className:"notes-card",children:[e.jsxs("div",{className:"notes-grid",children:[e.jsxs("div",{children:[e.jsx("label",{htmlFor:"decisions",children:"Decisions"}),e.jsx("textarea",{id:"decisions",rows:4,maxLength:4e3,disabled:!se||V,value:C,onChange:N=>m(N.target.value)})]}),e.jsxs("div",{children:[e.jsx("label",{htmlFor:"carry-forward",children:"Carry into the next sync"}),e.jsx("textarea",{id:"carry-forward",rows:4,maxLength:4e3,disabled:!se||V,value:k,onChange:N=>x(N.target.value)})]})]}),e.jsx("p",{className:"small muted",children:"Only these explicitly saved notes are decisions. A call or its automatic recap does not mark anything agreed or reviewed."}),se&&e.jsx("button",{className:"btn btn-secondary",disabled:V||!L,onClick:()=>void R("Saving notes…",async()=>I(await Ee(t,C,k))),children:"Save notes"})]})]}),e.jsxs("details",{className:"detail-section",children:[e.jsx("summary",{children:"Evidence & preparation details"}),e.jsx(yt,{syncId:t,progress:r.tree,evidence:ge,onResume:se?K:void 0,resumeEnabled:!V&&!G,onCancel:le}),e.jsx(cs,{items:r.items,title:"New evidence in this snapshot"}),e.jsx(cs,{items:r.context,title:"Earlier context — not new progress"})]}),se&&e.jsxs("div",{className:"detail-footer",children:[e.jsx("p",{className:"small muted",children:"Included does not mean reviewed. You can return to this sync at this URL, or start a separate one for new activity."}),e.jsx("button",{className:"btn btn-ghost",disabled:V,onClick:()=>{window.confirm("Discard this sync and release its unreviewed entries? Its history is retained.")&&R("Discarding sync…",async()=>I(await xt(t)))},children:"Discard sync"})]})]})]})}const hs=t=>new Date(t).toLocaleString(),qt={pi:"pi v3 JSONL",codex:"Rollout JSONL",claude:"Transcript JSONL"};function Mt({open:t}){const[s,n]=o.useState(!1),[a,i]=o.useState(null),[l,r]=o.useState(!0),[p,u]=o.useState(!1),[j,c]=o.useState(""),[y,h]=o.useState(""),[S,b]=o.useState(null),w=o.useRef(!0),d=o.useRef(!1);o.useEffect(()=>(w.current=!0,()=>{w.current=!1}),[]),o.useEffect(()=>{if(!t||!s||p)return;let m=!0;const k=async()=>{try{const[v,A]=await Promise.all([is(),Je()]);m&&!d.current&&(i(v),r(A.busy||A.active_call),h(""))}catch(v){m&&!d.current&&h(v instanceof Error?v.message:"Could not read session sources")}};k();const x=setInterval(()=>void k(),4e3);return()=>{m=!1,clearInterval(x)}},[t,s,p]);const E=async(m,k)=>{if(!a||l||y||d.current)return;const x=a;d.current=!0,u(!0),c(""),k&&i(k);try{const v=await m();w.current&&i(v)}catch(v){w.current&&(k&&i(x),c(v instanceof Error?v.message:"Could not update session sources"))}finally{d.current=!1,w.current&&u(!1)}},C=!a||l||p||!!y;return e.jsxs("details",{className:"source-settings",onToggle:m=>n(m.currentTarget.open),children:[e.jsx("summary",{children:"Agents & sessions"}),e.jsx("p",{className:"small muted",children:"Directory presence is not an installation check. Opening this panel reads recorded metadata; it does not scan transcripts, index embeddings or call a model."}),e.jsx("p",{className:"small muted",children:"Enable each history source before importing it. Codex and Claude history start off; existing pi choices are preserved. Enabling a source allows its logs into the next scan, sync or opted-in background batch. New sessions from enabled agents are selected by default. Summarization still runs through pi, regardless of which agent produced the history."}),!a&&e.jsx("p",{className:"small muted",role:"status",children:"Loading session inventory…"}),e.jsxs("button",{type:"button",className:"btn btn-secondary",disabled:C||!(a!=null&&a.agents.some(m=>m.enabled)),onClick:()=>void E(async()=>{const m=await tt();return w.current&&b(m),is()}),children:[e.jsx(Ys,{size:15,"aria-hidden":"true"}),"Scan enabled agents"]}),l&&a&&e.jsx("p",{className:"small muted",children:"Source changes are paused while a call or sync preparation is active."}),p&&e.jsx("p",{className:"small muted",role:"status",children:"Updating session sources…"}),a==null?void 0:a.agents.map(m=>{const k=a.sessions.filter(x=>x.agent===m.id);return e.jsxs("section",{className:"agent-source","aria-labelledby":`${m.id}-source-title`,children:[e.jsxs("div",{className:"section-heading",children:[e.jsx("h3",{id:`${m.id}-source-title`,children:m.name}),e.jsx("span",{className:"status",children:qt[m.id]})]}),e.jsxs("label",{className:"index-toggle",children:[e.jsx("input",{type:"checkbox",role:"switch","aria-label":`Enable ${m.name} history`,checked:m.enabled,disabled:C,onChange:x=>{const v=x.target.checked;E(()=>at(m.id,v),{...a,agents:a.agents.map(A=>A.id===m.id?{...A,enabled:v}:A)})}}),e.jsxs("span",{children:[e.jsxs("strong",{children:["Include ",m.name," history"]}),e.jsx("span",{className:"small muted",children:m.enabled?"Enabled for scanning and future syncs":"Off — transcripts are not scanned or indexed"})]})]}),m.roots.map(x=>e.jsxs("div",{children:[e.jsx("p",{className:"small muted",children:x.status==="present"?"Directory found":x.status==="missing"?"Directory not found":"Directory unavailable"}),e.jsx("code",{className:"source-path",children:x.path})]},x.path)),e.jsxs("p",{className:"small muted",children:[k.length," recorded sessions · ",k.filter(x=>x.included).length," selected · ",k.filter(x=>x.missing).length," unavailable at last scan"]}),!k.length&&e.jsxs("p",{className:"small muted",children:["No ",m.name," sessions recorded yet.",m.enabled?" Scan enabled agents to discover them.":" Enable this source before scanning."]}),e.jsx("div",{className:"session-list","aria-label":`Discovered ${m.name} sessions`,children:k.map(x=>e.jsxs("label",{className:"session-source",children:[e.jsx("input",{type:"checkbox",checked:!!x.included,disabled:C||!m.enabled||!!x.missing,"aria-label":`Include ${x.name||"session"} (${x.id})`,onChange:v=>{const A=v.target.checked;E(()=>nt(x.id,A),{...a,sessions:a.sessions.map(z=>z.id===x.id?{...z,included:Number(A)}:z)})}}),e.jsxs("span",{children:[e.jsx("strong",{children:x.name||x.cwd.split(/[\\/]/).filter(Boolean).pop()||x.id}),e.jsx("span",{className:"source-cwd",title:x.cwd,children:x.cwd||"Workspace unavailable"}),e.jsxs("span",{className:"small",children:[x.included?"Selected":"Excluded"," · ",x.pending," unreviewed ",x.pending===1?"entry":"entries",x.missing?" · unavailable at last scan":""]}),e.jsxs("span",{className:"source-session-meta small muted",children:["Session ",x.external_id||x.id," · Last recorded change: ",hs(x.modified_at)]}),e.jsx("code",{className:"source-path",children:x.path})]})]},x.id))})]},m.id)}),a&&e.jsxs("p",{className:"small muted",children:[a.history_initialized&&a.history_since?`Existing history baseline: ${hs(a.history_since)}. It is preserved.`:"All indexed history is eligible; there is no rolling time window."," Source choices do not edit existing frozen syncs or mark evidence reviewed. Scanning does not generate summaries or start a call. Keep the original logs: evidence is verified from them, not copied into Draken."]}),S&&e.jsxs("p",{className:"small muted",role:"status",children:["Last requested scan: ",S.files," candidate log files checked · ",S.added," new records recorded."]}),S&&S.warnings.length>0&&e.jsx("ul",{className:"source-warnings small","aria-label":"Scan warnings",children:S.warnings.map((m,k)=>e.jsx("li",{children:m},k))}),(j||y)&&e.jsx("p",{className:"small",role:"alert",children:j||y})]})}const Fe=t=>t===null?"Unavailable":t>0&&t<1e-6?"<$0.000001":new Intl.NumberFormat("en-US",{style:"currency",currency:"USD",maximumFractionDigits:t<.01?6:2}).format(t),he=t=>t.slice(0,16).replace("T"," "),Z=t=>t.toLocaleString();function Dt({active:t}){const[s,n]=o.useState("7d"),[a,i]=o.useState("1h"),[l,r]=o.useState("cost"),[p,u]=o.useState(null),[j,c]=o.useState("");if(o.useEffect(()=>{if(!t)return;const d=new AbortController;let E=!1;u(null),c("");const C=async()=>{if(!E){E=!0;try{const k=await Zs(s,a,d.signal);d.signal.aborted||(u(k),c(""))}catch(k){d.signal.aborted||(u(null),c(k instanceof Error?k.message:"Could not load preparation usage"))}finally{E=!1}}};C();const m=setInterval(()=>void C(),15e3);return()=>{d.abort(),clearInterval(m)}},[t,s,a]),!t)return null;const y=(p==null?void 0:p.range)===s&&p.bucket===a?p:null,h=y==null?void 0:y.totals,S=(y==null?void 0:y.buckets.map(d=>l==="cost"?d.cost.usd||0:d.completed_batches))||[],b=Math.max(0,...S),w=b||1;return e.jsxs("section",{className:"preparation-usage","aria-labelledby":"preparation-usage-title",children:[e.jsx("h3",{id:"preparation-usage-title",children:"Preparation usage"}),e.jsx("p",{className:"small muted",children:"Automatic and manual preparation, including retries and discarded batches. Estimates use recorded model usage and prices—not your bill, subscription charge or remaining quota."}),e.jsxs("div",{className:"usage-controls",children:[e.jsxs("label",{children:["Look back",e.jsxs("select",{value:s,onChange:d=>n(d.target.value),children:[e.jsx("option",{value:"6h",children:"6 hours"}),e.jsx("option",{value:"1d",children:"1 day"}),e.jsx("option",{value:"7d",children:"7 days"}),e.jsx("option",{value:"14d",children:"14 days"})]})]}),e.jsxs("label",{children:["Bucket size",e.jsxs("select",{value:a,onChange:d=>i(d.target.value),children:[e.jsx("option",{value:"1h",children:"1 hour"}),e.jsx("option",{value:"6h",children:"6 hours"}),e.jsx("option",{value:"24h",children:"24 hours"})]})]}),e.jsxs("label",{children:["Chart",e.jsxs("select",{value:l,onChange:d=>r(d.target.value),children:[e.jsx("option",{value:"cost",children:"Estimated cost"}),e.jsx("option",{value:"batches",children:"Completed batches"})]})]})]}),j?e.jsxs("p",{role:"alert",children:["Usage unavailable: ",j]}):y?h&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"usage-totals",children:[e.jsxs("div",{children:[e.jsx("span",{className:"small",children:h.incomplete_pricing?"Known cost subtotal":"Est. preparation cost"}),e.jsx("strong",{children:Fe(h.cost.usd)}),e.jsx("span",{className:"small muted",children:h.incomplete_pricing?`${Z(h.incomplete_pricing)} ${h.incomplete_pricing===1?"request has":"requests have"} incomplete pricing`:"USD · recorded API-price estimate"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"small",children:"Completed batches"}),e.jsx("strong",{children:Z(h.completed_batches)}),e.jsxs("span",{className:"small muted",children:[Z(h.entries)," entries across these batches"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"small",children:"Model requests"}),e.jsx("strong",{children:Z(h.requests)}),e.jsxs("span",{className:"small muted",children:[Z(y.active_attempts)," preparation ",y.active_attempts===1?"attempt":"attempts"," active now"]})]})]}),e.jsxs("p",{className:"small muted",children:[he(y.from)," – ",he(y.to)," UTC. Refreshes every 15 seconds while Settings is open."]}),!h.requests&&!h.completed_batches&&!h.failed_attempts?e.jsx("p",{children:"No preparation recorded in this period."}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"usage-chart-heading small",children:[e.jsxs("strong",{children:[l==="cost"?"Estimated cost":"Completed batches"," per ",a]}),e.jsx("span",{children:l==="cost"?`Peak known: ${Fe(h.cost.usd===null?null:b)}`:`Peak: ${Z(b)}`})]}),e.jsxs("svg",{className:"usage-chart",viewBox:"0 0 720 120",preserveAspectRatio:"none",role:"img","aria-label":`${l==="cost"?"Estimated preparation cost":"Completed batches"} by ${a} bucket. Exact values in bucket details below.`,children:[e.jsx("line",{x1:"0",y1:"119",x2:"720",y2:"119"}),y.buckets.map((d,E)=>{const C=l==="cost"&&!d.cost.complete,m=Math.max(S[E]>0?2:C?4:0,S[E]/w*112);return e.jsx("rect",{x:E/S.length*720,y:119-m,width:Math.max(.5,720/S.length-1),height:m,className:C?"usage-incomplete":void 0,children:e.jsxs("title",{children:[he(d.from)," – ",he(d.to)," UTC: ",l==="cost"?Fe(d.cost.usd)+(C?" (incomplete pricing)":""):`${d.completed_batches} batches`,"; ",d.requests," requests"]})},d.from)})]}),e.jsxs("div",{className:"usage-chart-axis small muted",children:[e.jsx("span",{children:he(y.from).slice(5)}),e.jsx("span",{children:"UTC"}),e.jsx("span",{children:he(y.to).slice(5)})]}),l==="cost"&&h.incomplete_pricing>0&&e.jsx("p",{className:"small muted",children:"Gray bars have incomplete pricing. Their heights show only the known subtotal; an unpriced request is not free."}),e.jsxs("details",{className:"usage-details",children:[e.jsx("summary",{children:"Bucket details"}),e.jsx("div",{className:"usage-table-wrap",tabIndex:0,role:"region","aria-label":"Usage bucket details",children:e.jsxs("table",{children:[e.jsx("caption",{className:"sr-only",children:"Preparation usage by UTC time bucket, newest first"}),e.jsx("thead",{children:e.jsxs("tr",{children:[e.jsx("th",{scope:"col",children:"UTC interval"}),e.jsx("th",{scope:"col",children:"Batches"}),e.jsx("th",{scope:"col",children:"Requests"}),e.jsx("th",{scope:"col",children:"Est. cost"}),e.jsx("th",{scope:"col",children:"Incomplete pricing"})]})}),e.jsx("tbody",{children:[...y.buckets].reverse().map(d=>e.jsxs("tr",{children:[e.jsxs("th",{scope:"row",children:[he(d.from),e.jsx("br",{}),"to ",he(d.to)]}),e.jsx("td",{children:Z(d.completed_batches)}),e.jsx("td",{children:Z(d.requests)}),e.jsxs("td",{children:[Fe(d.cost.usd),!d.cost.complete&&" (partial)"]}),e.jsx("td",{children:Z(d.incomplete_pricing)})]},d.from))})]})})]})]}),e.jsxs("p",{className:"small muted",children:[Z(h.failed_attempts)," failed or stopped ",h.failed_attempts===1?"attempt":"attempts"," in this period. ",Z(h.approximate_timing)," ",h.approximate_timing===1?"request uses":"requests use"," older, approximate timing (the preparation run’s start); newer requests use their recorded start time. Buckets align to UTC hours, with partial first and last buckets."]})]}):e.jsx("p",{role:"status",children:"Loading preparation usage…"}),e.jsx("p",{className:"small muted",children:"A completed batch is a snapshot’s first successful briefing preparation. Retries and rebuilds add costs, not extra batches. Batch counts use completion time; request costs use start time. Counts do not mean reviewed work or current call readiness. Chat, voice and post-conversation recaps are excluded. Local search indexing uses no model API; machine and network costs are not measured."})]})}function Rt(){const[t,s]=o.useState(!1),[n,a]=o.useState(null),[i,l]=o.useState(!1),[r,p]=o.useState(""),u=o.useRef(null);return o.useEffect(()=>{var j,c,y;t&&!((j=u.current)!=null&&j.open)?(c=u.current)==null||c.showModal():t||(y=u.current)==null||y.close()},[t]),o.useEffect(()=>{if(!t||i)return;let j=!0;const c=async()=>{try{const h=await ys();j&&(a(h),p(""))}catch(h){j&&p(h instanceof Error?h.message:"Could not read settings")}};c();const y=setInterval(()=>void c(),4e3);return()=>{j=!1,clearInterval(y)}},[t,i]),e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",className:"btn btn-secondary header-settings","aria-haspopup":"dialog",onClick:()=>s(!0),children:[e.jsx(Gs,{size:16,"aria-hidden":"true"}),"Settings"]}),e.jsxs("dialog",{ref:u,className:"settings-dialog","aria-labelledby":"settings-title",onCancel:j=>{j.preventDefault(),s(!1)},onClose:j=>{j.currentTarget.open||s(!1)},children:[e.jsxs("div",{className:"section-heading",children:[e.jsx("h2",{id:"settings-title",children:"Settings"}),e.jsx("button",{type:"button",className:"icon-button","aria-label":"Close settings",autoFocus:!0,onClick:()=>s(!1),children:e.jsx(Qe,{size:18,"aria-hidden":"true"})})]}),e.jsx(Dt,{active:t}),e.jsxs("label",{className:"index-toggle",children:[e.jsx("input",{type:"checkbox",role:"switch",checked:(n==null?void 0:n.enabled)||!1,disabled:!n||i,onChange:async j=>{const c=j.target.checked,y=n;l(!0),p(""),a(h=>h&&{...h,enabled:c});try{a(await ns(c))}catch(h){a(y),p(h instanceof Error?h.message:"Could not save settings")}finally{l(!1)}}}),e.jsxs("span",{children:[e.jsx("strong",{children:"Automatically prepare conversations"}),e.jsx("span",{className:"small muted",children:"Index history, summarize new work and prepare the next briefing together."})]})]}),e.jsx("p",{className:"small muted",children:"One automatic mode, off by default. While the server runs, check once a minute and prepare a batch at 64 source changes or waiting entries. Interrupted batches resume from cached work. Smaller new tails wait for your next sync; there is no timed flush. A completed briefing is reused when you join, rather than generated again. Calls and foreground work take priority."}),e.jsx("p",{className:"small muted",children:"This uses your configured pi summary and final models and their account quota or API billing, within the saved per-run invocation limit. Search embeddings stay local; first use may download the pinned search model. Failures stop automatic model retries until you explicitly retry. Existing conversations, notes and frozen snapshots are not rewritten. Nothing is marked reviewed and no microphone or call starts automatically. Agent and session exclusions remain respected."}),i&&e.jsx("p",{role:"status",children:"Saving…"}),r&&e.jsx("p",{className:"small",role:"alert",children:r}),t&&n&&e.jsx(ks,{settings:n}),(n==null?void 0:n.enabled)&&n.phase==="error"&&e.jsx("button",{type:"button",className:"btn btn-secondary",disabled:i,onClick:async()=>{l(!0),p("");try{a(await ns(!0))}catch(j){p(j instanceof Error?j.message:"Could not retry preparation")}finally{l(!1)}},children:"Retry automatic preparation"}),e.jsx(Mt,{open:t}),e.jsx(ws,{active:t,always:!0})]})]})}function Lt(){const{isAuthenticated:t,isLoading:s,authEnabled:n,username:a,logout:i}=xs(),[l,r]=o.useState(window.location.pathname),[p,u]=o.useState(null),j=o.useRef(null),c=o.useRef(l),y=o.useCallback(w=>{j.current=w},[]),h=o.useCallback((w,d=!1)=>{j.current&&!j.current()||(window.history.pushState(null,"",w),c.current=w,r(w),u(d?Number(w.split("/").pop()):null),window.scrollTo(0,0))},[]);if(o.useEffect(()=>{const w=()=>{if(j.current&&!j.current()){window.history.pushState(null,"",c.current);return}c.current=window.location.pathname,r(c.current),u(null)};return window.addEventListener("popstate",w),()=>window.removeEventListener("popstate",w)},[]),s)return e.jsxs("div",{className:"app-loading",children:[e.jsx("span",{className:"spinner"}),"Opening Draken…"]});if(!t)return e.jsx(Qs,{});const S=/^\/syncs\/([1-9]\d*)(\/chat)?\/?$/.exec(l),b=S?Number(S[1]):null;return e.jsxs("div",{className:"app-container",children:[e.jsxs("header",{className:"header",children:[e.jsxs("a",{className:"brand",href:"/",onClick:w=>me(w,h,"/"),"aria-label":"Draken sync history",children:[e.jsx("img",{src:"/favicon.png",alt:""}),e.jsxs("div",{children:[e.jsx("strong",{children:"Draken"}),e.jsx("span",{children:"Session sync"})]})]}),e.jsxs("div",{className:"header-right",children:[e.jsx("a",{href:"/history",onClick:w=>me(w,h,"/history"),children:"Search history"}),e.jsx(Rt,{}),n&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"muted small",children:a}),e.jsx("button",{className:"icon-button",onClick:()=>{(!j.current||j.current())&&i()},"aria-label":"Sign out",children:e.jsx(Fs,{size:18})})]})]})]}),b&&Number.isSafeInteger(b)?e.jsx(It,{id:b,chat:!!(S!=null&&S[2]),callIntent:p===b,consumeIntent:()=>u(null),navigate:h,setGuard:y},b):/^\/history(?:\/H[a-f0-9]{24})?\/?$/.test(l)?e.jsx(Nt,{navigate:h,reference:l.split("/")[2]},l):l==="/"?e.jsx(wt,{navigate:h}):e.jsxs("main",{className:"sync-home",children:[e.jsx("h1",{children:"Page not found"}),e.jsx("a",{href:"/",onClick:w=>me(w,h,"/"),children:"All syncs"})]})]})}function $t(){return e.jsx(Ws,{children:e.jsx(Lt,{})})}_s.createRoot(document.getElementById("root")).render(e.jsx(As.StrictMode,{children:e.jsx($t,{})}));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{c as g,j as e,r as s,P as b}from"./index-
|
|
1
|
+
import{c as g,j as e,r as s,P as b}from"./index-S46UUaj8.js";function y(){const[m,o]=s.useState("idle"),[h,f]=s.useState(""),a=s.useRef(null),l=s.useRef(),i=s.useRef(),d=s.useRef(!0),t=s.useRef(0),p=()=>{var r;t.current++,(r=i.current)==null||r.stop(),i.current=void 0,a.current=null,o("idle")};s.useEffect(()=>()=>{var r,n;d.current=!1,t.current++,(r=i.current)==null||r.stop(),a.current=null,(n=l.current)==null||n.close()},[]);const w=async()=>{p();const r=t.current;f("");try{const n=l.current||(l.current=new AudioContext);await n.resume();const x=await fetch("/persona/sample.wav");if(!x.ok)throw Error("The local sample could not be loaded.");const u=await n.decodeAudioData(await x.arrayBuffer());if(!d.current||r!==t.current)return;const c=n.createBufferSource();i.current=c,c.buffer=u,c.connect(n.destination);const j=n.currentTime;a.current={text:"Did the export tests pass?",samples:u.getChannelData(0).slice(),sampleRate:u.sampleRate,duration:u.duration,startedAt:j,now:()=>n.state==="running"?n.currentTime:NaN},c.onended=()=>{c.disconnect(),r===t.current&&d.current&&(i.current=void 0,a.current=null,o("idle"))},o("speaking"),c.start(j)}catch(n){d.current&&r===t.current&&(f(n instanceof Error?n.message:"Sample playback failed"),o("idle"),a.current=null)}};return e.jsxs("main",{className:"dp-preview",children:[e.jsxs("header",{className:"dp-preview-heading",children:[e.jsxs("div",{children:[e.jsx("span",{className:"eyebrow",children:"DRAKEN / PERSONA STUDIO"}),e.jsxs("h1",{children:["A little warmth.",e.jsx("br",{}),"A clear head."]})]}),e.jsx("a",{className:"btn btn-secondary",href:"/",children:"Back to Draken"})]}),e.jsx("div",{className:"dp-preview-scene",children:e.jsx(b,{mode:m,playback:a,studioControls:!0})}),e.jsxs("section",{className:"dp-preview-controls","aria-label":"Persona preview controls",children:[["idle","listening","thinking"].map(r=>e.jsx("button",{className:"btn btn-secondary","aria-pressed":m===r,onClick:()=>{p(),o(r)},children:r},r)),e.jsx("button",{className:"btn btn-primary",onClick:()=>void w(),children:"Play speech sample"}),e.jsx("button",{className:"btn btn-secondary",onClick:p,disabled:m!=="speaking",children:"Stop sample"})]}),h&&e.jsx("p",{role:"alert",children:h}),e.jsx("p",{className:"muted small",children:"Standalone presentation module. No microphone, login, model request, or session data. The sample is generated speech. Mouth timing follows audio energy and approximate English text cues, not exact phoneme alignment."}),e.jsxs("details",{className:"dp-reference",children:[e.jsx("summary",{children:"Character reference"}),e.jsx("img",{loading:"lazy",src:"/persona/reference.jpg",alt:"The original illustrated mechanical Draken dragon with wooden jaw and wings, amber eyes, ivory horns, and mustard knitwear."}),e.jsx("p",{className:"small muted",children:"Based on the exact illustration from draken.mehanig.com. The beanie and seated workshop scene are a new 3D interpretation."})]})]})}g.createRoot(document.getElementById("root")).render(e.jsx(y,{}));
|
package/public/index.html
CHANGED
|
@@ -6,9 +6,9 @@
|
|
|
6
6
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
7
7
|
<meta name="description" content="A local-first engineering sync across your pi sessions." />
|
|
8
8
|
<title>Draken — Session Sync</title>
|
|
9
|
-
<script type="module" crossorigin src="/assets/index-
|
|
10
|
-
<link rel="modulepreload" crossorigin href="/assets/index-
|
|
11
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
9
|
+
<script type="module" crossorigin src="/assets/index-SXgKBqZw.js"></script>
|
|
10
|
+
<link rel="modulepreload" crossorigin href="/assets/index-S46UUaj8.js">
|
|
11
|
+
<link rel="stylesheet" crossorigin href="/assets/index-BCDcSZkB.css">
|
|
12
12
|
</head>
|
|
13
13
|
<body>
|
|
14
14
|
<div id="root"></div>
|
|
Binary file
|
package/public/persona.html
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<!doctype html>
|
|
2
|
-
<html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Draken · Persona studio</title><link rel="icon" href="/favicon.png" /> <script type="module" crossorigin src="/assets/persona-
|
|
3
|
-
<link rel="modulepreload" crossorigin href="/assets/index-
|
|
4
|
-
<link rel="stylesheet" crossorigin href="/assets/index-
|
|
2
|
+
<html lang="en"><head><meta charset="UTF-8" /><meta name="viewport" content="width=device-width, initial-scale=1.0" /><title>Draken · Persona studio</title><link rel="icon" href="/favicon.png" /> <script type="module" crossorigin src="/assets/persona-BgbqhiLa.js"></script>
|
|
3
|
+
<link rel="modulepreload" crossorigin href="/assets/index-S46UUaj8.js">
|
|
4
|
+
<link rel="stylesheet" crossorigin href="/assets/index-BCDcSZkB.css">
|
|
5
5
|
<link rel="stylesheet" crossorigin href="/assets/persona-C_m1CVKe.css">
|
|
6
6
|
</head>
|
|
7
7
|
<body><div id="root"></div></body></html>
|
|
@@ -178,7 +178,7 @@ export class NativeVoice {
|
|
|
178
178
|
await this.#rpc.request('thread/realtime/appendText', { threadId: this.#thread, role: 'user', text });
|
|
179
179
|
}
|
|
180
180
|
async context(text) {
|
|
181
|
-
if (!this.#thread || this.#closed || typeof text !== 'string' || !text.trim() || Buffer.byteLength(text, 'utf8') >
|
|
181
|
+
if (!this.#thread || this.#closed || typeof text !== 'string' || !text.trim() || Buffer.byteLength(text, 'utf8') > 8192) throw new Error('Cannot supply this native voice context.');
|
|
182
182
|
// In v3 this becomes session context, without the user-text prefix.
|
|
183
183
|
await this.#rpc.request('thread/realtime/appendText', { threadId: this.#thread, role: 'developer', text });
|
|
184
184
|
}
|