pikiloom 0.4.26 → 0.4.27
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/dashboard/dist/assets/{AgentTab-BNJ73P0m.js → AgentTab-DIP-y4dl.js} +1 -1
- package/dashboard/dist/assets/ConnectionModal-BCfvhkiI.js +1 -0
- package/dashboard/dist/assets/{DirBrowser-D-GT-G-w.js → DirBrowser-Dot7ua9-.js} +1 -1
- package/dashboard/dist/assets/{ExtensionsTab-BrJMulJR.js → ExtensionsTab-GioMx4S6.js} +1 -1
- package/dashboard/dist/assets/{IMAccessTab-auPnx468.js → IMAccessTab-C9_r8jJP.js} +1 -1
- package/dashboard/dist/assets/{Modal-lYfO9m-I.js → Modal-M1AP1sgR.js} +1 -1
- package/dashboard/dist/assets/{Modals-PRdWOIY9.js → Modals-CCm3UUfJ.js} +1 -1
- package/dashboard/dist/assets/{Select-BhbU-rll.js → Select-YubDM16P.js} +1 -1
- package/dashboard/dist/assets/{SessionPanel-_0dLWvEb.js → SessionPanel-Cnv9o96n.js} +1 -1
- package/dashboard/dist/assets/SystemTab-VgNivIe3.js +1 -0
- package/dashboard/dist/assets/index-BY7l20bi.js +23 -0
- package/dashboard/dist/assets/index-BlqvzDUL.js +3 -0
- package/dashboard/dist/assets/index-CXIN3nTr.css +1 -0
- package/dashboard/dist/assets/{shared-C5uXvhZJ.js → shared-C0SAInnT.js} +1 -1
- package/dashboard/dist/index.html +2 -2
- package/dist/agent/acp-client.js +0 -59
- package/dist/agent/artifacts.js +1 -38
- package/dist/agent/auto-update.js +2 -78
- package/dist/agent/await-resume.js +0 -20
- package/dist/agent/cli/auth.js +3 -51
- package/dist/agent/cli/catalog.js +0 -3
- package/dist/agent/cli/detector.js +1 -19
- package/dist/agent/cli/index.js +0 -3
- package/dist/agent/cli/registry.js +0 -25
- package/dist/agent/driver.js +0 -14
- package/dist/agent/drivers/claude-tui.js +2 -769
- package/dist/agent/drivers/claude.js +12 -631
- package/dist/agent/drivers/codex.js +11 -162
- package/dist/agent/drivers/gemini.js +6 -114
- package/dist/agent/drivers/hermes.js +0 -128
- package/dist/agent/goal.js +0 -45
- package/dist/agent/handover.js +1 -46
- package/dist/agent/images.js +7 -133
- package/dist/agent/index.js +1 -29
- package/dist/agent/mcp/bridge.js +1 -197
- package/dist/agent/mcp/extensions.js +5 -84
- package/dist/agent/mcp/oauth.js +2 -69
- package/dist/agent/mcp/registry.js +2 -33
- package/dist/agent/mcp/session-server.js +2 -45
- package/dist/agent/mcp/tools/ask-user.js +0 -6
- package/dist/agent/mcp/tools/await-resume.js +0 -15
- package/dist/agent/mcp/tools/goal.js +0 -25
- package/dist/agent/mcp/tools/types.js +0 -5
- package/dist/agent/mcp/tools/workspace.js +0 -23
- package/dist/agent/npm.js +0 -14
- package/dist/agent/session.js +86 -196
- package/dist/agent/skill-installer.js +3 -70
- package/dist/agent/skills.js +0 -43
- package/dist/agent/stream.js +5 -148
- package/dist/agent/types.js +0 -12
- package/dist/agent/utils.js +2 -120
- package/dist/bot/bot.js +3 -468
- package/dist/bot/command-ui.js +0 -45
- package/dist/bot/commands.js +0 -51
- package/dist/bot/headless-bot.js +0 -21
- package/dist/bot/host.js +1 -5
- package/dist/bot/human-loop.js +0 -8
- package/dist/bot/menu.js +0 -3
- package/dist/bot/orchestration.js +0 -3
- package/dist/bot/render-shared.js +0 -63
- package/dist/bot/session-hub.js +14 -92
- package/dist/bot/session-status.js +1 -5
- package/dist/bot/streaming.js +0 -53
- package/dist/browser-profile.js +0 -51
- package/dist/browser-supervisor.js +0 -75
- package/dist/catalog/cli-tools.js +0 -53
- package/dist/catalog/index.js +0 -18
- package/dist/catalog/local-models.js +0 -18
- package/dist/catalog/mcp-servers.js +0 -35
- package/dist/catalog/skill-repos.js +0 -32
- package/dist/channels/base.js +0 -19
- package/dist/channels/dingtalk/bot.js +0 -3
- package/dist/channels/dingtalk/channel.js +0 -33
- package/dist/channels/discord/bot.js +0 -7
- package/dist/channels/discord/channel.js +0 -22
- package/dist/channels/feishu/bot.js +0 -71
- package/dist/channels/feishu/channel.js +0 -78
- package/dist/channels/feishu/markdown.js +0 -5
- package/dist/channels/feishu/render.js +0 -45
- package/dist/channels/health.js +0 -46
- package/dist/channels/slack/bot.js +0 -7
- package/dist/channels/slack/channel.js +1 -27
- package/dist/channels/states.js +0 -3
- package/dist/channels/telegram/bot.js +0 -60
- package/dist/channels/telegram/channel.js +2 -99
- package/dist/channels/telegram/directory.js +0 -3
- package/dist/channels/telegram/live-preview.js +0 -8
- package/dist/channels/telegram/render.js +0 -30
- package/dist/channels/wecom/bot.js +0 -3
- package/dist/channels/wecom/channel.js +0 -58
- package/dist/channels/weixin/api.js +0 -9
- package/dist/channels/weixin/bot.js +0 -88
- package/dist/channels/weixin/channel.js +0 -6
- package/dist/cli/autostart.js +1 -44
- package/dist/cli/channel-supervisor.js +1 -59
- package/dist/cli/channels.js +0 -6
- package/dist/cli/main.js +1 -145
- package/dist/cli/onboarding.js +0 -6
- package/dist/cli/run.js +0 -11
- package/dist/cli/setup-wizard.js +0 -3
- package/dist/core/config/runtime-config.js +0 -38
- package/dist/core/config/user-config.js +0 -63
- package/dist/core/config/validation.js +0 -9
- package/dist/core/constants.js +0 -268
- package/dist/core/git.js +0 -31
- package/dist/core/legacy-compat.js +1 -28
- package/dist/core/logging.js +0 -3
- package/dist/core/platform.js +0 -28
- package/dist/core/process-control.js +0 -8
- package/dist/core/secrets/index.js +0 -17
- package/dist/core/secrets/inline-seal.js +0 -7
- package/dist/core/secrets/ref.js +0 -19
- package/dist/core/secrets/resolver.js +0 -8
- package/dist/core/secrets/store.js +1 -12
- package/dist/core/utils.js +1 -37
- package/dist/core/version.js +0 -3
- package/dist/dashboard/platform.js +1 -35
- package/dist/dashboard/routes/agents.js +2 -71
- package/dist/dashboard/routes/cli.js +0 -27
- package/dist/dashboard/routes/config.js +0 -54
- package/dist/dashboard/routes/extensions.js +0 -132
- package/dist/dashboard/routes/local-models.js +0 -68
- package/dist/dashboard/routes/models.js +0 -46
- package/dist/dashboard/routes/sessions.js +0 -100
- package/dist/dashboard/runtime.js +1 -58
- package/dist/dashboard/server.js +0 -49
- package/dist/dashboard/session-control.js +2 -69
- package/dist/model/catalog.js +1 -17
- package/dist/model/index.js +0 -15
- package/dist/model/injector.js +1 -181
- package/dist/model/provider-models.js +1 -48
- package/dist/model/responses-bridge.js +3 -45
- package/dist/model/store.js +0 -17
- package/dist/model/types.js +0 -12
- package/dist/model/validation.js +1 -18
- package/dist/pikichannel/adapter-pikiloom.js +0 -31
- package/dist/pikichannel/code.js +0 -12
- package/dist/pikichannel/codec.js +0 -14
- package/dist/pikichannel/host.js +4 -33
- package/dist/pikichannel/protocol.js +0 -52
- package/dist/pikichannel/rendezvous-broker.js +5 -26
- package/dist/pikichannel/rendezvous-host.js +3 -16
- package/dist/pikichannel/server.js +6 -55
- package/dist/pikichannel/transport.js +0 -25
- package/dist/pikichannel/transports/webrtc-host.js +0 -18
- package/dist/pikichannel/transports/webrtc-shared.js +4 -34
- package/dist/pikichannel/transports/websocket-host.js +1 -14
- package/dist/pikichannel/turn.js +2 -69
- package/dist/pikichannel/web/sdk.js +14 -71
- package/package.json +1 -1
- package/dashboard/dist/assets/ConnectionModal-Dt05H2f9.js +0 -1
- package/dashboard/dist/assets/SystemTab-CN_QrRKt.js +0 -1
- package/dashboard/dist/assets/index-CP3LYJR2.js +0 -23
- package/dashboard/dist/assets/index-C_neLnaO.js +0 -3
- package/dashboard/dist/assets/index-CyCspgtc.css +0 -1
|
@@ -1,37 +1,7 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* pikichannel-sdk.js — the reference browser client SDK (vanilla ESM, zero deps).
|
|
3
|
-
*
|
|
4
|
-
* This is the embeddable client: drop it into any web app (or wrap it in a
|
|
5
|
-
* WebView for mobile) and you get a live, bidirectional agent session over
|
|
6
|
-
* either transport. It mirrors the L2 protocol in src/pikichannel/protocol.ts —
|
|
7
|
-
* keep the message `type` literals in lockstep with that file.
|
|
8
|
-
*
|
|
9
|
-
* Layering mirrors the host:
|
|
10
|
-
* - Transport (L1): WsTransport | RtcTransport — both expose connect/send and
|
|
11
|
-
* onopen/onmessage/onclose. The client is blind to which one it holds.
|
|
12
|
-
* - Client (L2): PikichannelClient — speaks the protocol, keeps a reactive
|
|
13
|
-
* `sessions` store, exposes prompt/stop/steer/interact, and emits events.
|
|
14
|
-
*
|
|
15
|
-
* Public surface:
|
|
16
|
-
* const c = new Pikichannel.Client({ transport: 'websocket' | 'webrtc' })
|
|
17
|
-
* c.on('status'|'welcome'|'session'|'sessions'|'accepted'|'error', cb)
|
|
18
|
-
* await c.connect(); c.subscribeAll();
|
|
19
|
-
* c.prompt({ prompt, sessionKey?, agent?, model?, effort? })
|
|
20
|
-
* c.stop(key) / c.steer(taskId) / c.recall(taskId) / c.interact(promptId, action, value)
|
|
21
|
-
* c.sessions // Map<sessionKey, UniversalSnapshot>
|
|
22
|
-
* c.stats() // { transport, state, rtt, framesIn, framesOut, bytesIn, bytesOut }
|
|
23
|
-
*/
|
|
24
|
-
|
|
25
1
|
export const PROTOCOL_VERSION = 1;
|
|
26
2
|
|
|
27
|
-
// The browser keeps plain STUN (no secrets). Relay fallback rides the host's
|
|
28
|
-
// TURN: the host (answerer) trickles its Cloudflare relay candidate, which the
|
|
29
|
-
// browser reaches outbound — so no browser-side TURN credential is needed.
|
|
30
3
|
const ICE_SERVERS = [{ urls: 'stun:stun.l.google.com:19302' }, { urls: 'stun:stun.cloudflare.com:3478' }];
|
|
31
4
|
|
|
32
|
-
// Resolve the ws(s):// base for a target host. `host` may be a bare authority
|
|
33
|
-
// ("192.168.1.5:3940"), a full ws(s)/http(s) URL, or empty (same origin). This
|
|
34
|
-
// is what makes a client repointable: pass `host` to talk to a different node.
|
|
35
5
|
function wsBase(host) {
|
|
36
6
|
const loc = window.location;
|
|
37
7
|
const proto = loc.protocol === 'https:' ? 'wss:' : 'ws:';
|
|
@@ -42,10 +12,6 @@ function wsBase(host) {
|
|
|
42
12
|
return proto + '//' + host.replace(/\/$/, '');
|
|
43
13
|
}
|
|
44
14
|
|
|
45
|
-
// ---------------------------------------------------------------------------
|
|
46
|
-
// L1 transports (browser side)
|
|
47
|
-
// ---------------------------------------------------------------------------
|
|
48
|
-
|
|
49
15
|
class WsTransport {
|
|
50
16
|
constructor(base) {
|
|
51
17
|
this.kind = 'websocket';
|
|
@@ -66,16 +32,12 @@ class WsTransport {
|
|
|
66
32
|
isOpen() { return !!this.ws && this.ws.readyState === WebSocket.OPEN; }
|
|
67
33
|
}
|
|
68
34
|
|
|
69
|
-
// The browser is always the WebRTC offerer (creates the datachannel + offer).
|
|
70
|
-
// Two signaling paths share the same PC setup:
|
|
71
|
-
// - direct: SDP/ICE over `${base}/pikichannel/signal` (reachable host).
|
|
72
|
-
// - rendezvous: dial a NodeID through a broker both peers reach (NAT traversal).
|
|
73
35
|
class RtcTransport {
|
|
74
36
|
constructor(cfg) {
|
|
75
37
|
this.kind = 'webrtc';
|
|
76
38
|
this.base = cfg.base;
|
|
77
|
-
this.rendezvous = cfg.rendezvous || null;
|
|
78
|
-
this.nodeId = cfg.nodeId || null;
|
|
39
|
+
this.rendezvous = cfg.rendezvous || null;
|
|
40
|
+
this.nodeId = cfg.nodeId || null;
|
|
79
41
|
this.pc = null; this.dc = null; this.signal = null;
|
|
80
42
|
this.onopen = null; this.onmessage = null; this.onclose = null; this.onerror = null;
|
|
81
43
|
}
|
|
@@ -103,7 +65,6 @@ class RtcTransport {
|
|
|
103
65
|
this.signal = signal;
|
|
104
66
|
|
|
105
67
|
if (useRendezvous) {
|
|
106
|
-
// NAT path: dial the NodeID through the broker; signaling is relayed.
|
|
107
68
|
let sessionId = null;
|
|
108
69
|
pc.onicecandidate = (e) => { if (e.candidate && sessionId && signal.readyState === WebSocket.OPEN) signal.send(JSON.stringify({ t: 'signal', sessionId, data: { kind: 'candidate', candidate: e.candidate.toJSON() } })); };
|
|
109
70
|
signal.onopen = () => signal.send(JSON.stringify({ t: 'dial', nodeId: this.nodeId }));
|
|
@@ -123,7 +84,6 @@ class RtcTransport {
|
|
|
123
84
|
};
|
|
124
85
|
signal.onerror = () => this.onerror && this.onerror(new Error('rendezvous socket error'));
|
|
125
86
|
} else {
|
|
126
|
-
// Direct path: SDP/ICE straight to the reachable host.
|
|
127
87
|
pc.onicecandidate = (e) => { if (e.candidate && signal.readyState === WebSocket.OPEN) signal.send(JSON.stringify({ kind: 'candidate', candidate: e.candidate.toJSON() })); };
|
|
128
88
|
signal.onmessage = async (m) => {
|
|
129
89
|
let msg; try { msg = JSON.parse(m.data); } catch (e) { return; }
|
|
@@ -152,7 +112,6 @@ function makeTransport(kind, cfg) {
|
|
|
152
112
|
return new WsTransport(cfg.base);
|
|
153
113
|
}
|
|
154
114
|
|
|
155
|
-
// Mirror of applySnapshotPatch() in src/pikichannel/protocol.ts — keep in lockstep.
|
|
156
115
|
function applyPatch(prev, patch) {
|
|
157
116
|
if (patch.full) return patch.full;
|
|
158
117
|
const next = prev ? Object.assign({}, prev) : { phase: 'idle', updatedAt: 0 };
|
|
@@ -162,28 +121,23 @@ function applyPatch(prev, patch) {
|
|
|
162
121
|
return next;
|
|
163
122
|
}
|
|
164
123
|
|
|
165
|
-
// ---------------------------------------------------------------------------
|
|
166
|
-
// L2 client
|
|
167
|
-
// ---------------------------------------------------------------------------
|
|
168
|
-
|
|
169
124
|
export class PikichannelClient {
|
|
170
125
|
constructor(opts) {
|
|
171
126
|
opts = opts || {};
|
|
172
|
-
this.rendezvous = opts.rendezvous || null;
|
|
173
|
-
this.nodeId = opts.nodeId || null;
|
|
174
|
-
// A rendezvous dial implies WebRTC (the broker only brokers P2P signaling).
|
|
127
|
+
this.rendezvous = opts.rendezvous || null;
|
|
128
|
+
this.nodeId = opts.nodeId || null;
|
|
175
129
|
this.transportKind = (this.rendezvous && this.nodeId) ? 'webrtc' : (opts.transport === 'webrtc' ? 'webrtc' : 'websocket');
|
|
176
130
|
this.token = opts.token || null;
|
|
177
|
-
this.endpoint = opts.host || null;
|
|
178
|
-
this._base = wsBase(this.endpoint);
|
|
131
|
+
this.endpoint = opts.host || null;
|
|
132
|
+
this._base = wsBase(this.endpoint);
|
|
179
133
|
this.transport = null;
|
|
180
|
-
this.state = 'idle';
|
|
181
|
-
this.host = null;
|
|
182
|
-
this.sessions = new Map();
|
|
183
|
-
this.sessionMetas = [];
|
|
184
|
-
this._seqs = new Map();
|
|
134
|
+
this.state = 'idle';
|
|
135
|
+
this.host = null;
|
|
136
|
+
this.sessions = new Map();
|
|
137
|
+
this.sessionMetas = [];
|
|
138
|
+
this._seqs = new Map();
|
|
185
139
|
this._listeners = new Map();
|
|
186
|
-
this._pending = new Map();
|
|
140
|
+
this._pending = new Map();
|
|
187
141
|
this._reqSeq = 0;
|
|
188
142
|
this._pingTimer = null;
|
|
189
143
|
this._rtt = null;
|
|
@@ -191,7 +145,6 @@ export class PikichannelClient {
|
|
|
191
145
|
this._pendingResolve = null;
|
|
192
146
|
}
|
|
193
147
|
|
|
194
|
-
// -- event emitter --
|
|
195
148
|
on(type, cb) {
|
|
196
149
|
let set = this._listeners.get(type);
|
|
197
150
|
if (!set) { set = new Set(); this._listeners.set(type, set); }
|
|
@@ -203,7 +156,6 @@ export class PikichannelClient {
|
|
|
203
156
|
|
|
204
157
|
_setState(state) { this.state = state; this._emit('status', this.stats()); }
|
|
205
158
|
|
|
206
|
-
// -- lifecycle --
|
|
207
159
|
connect() {
|
|
208
160
|
return new Promise((resolve, reject) => {
|
|
209
161
|
this._pendingResolve = resolve;
|
|
@@ -221,7 +173,6 @@ export class PikichannelClient {
|
|
|
221
173
|
t.onmessage = (data) => this._onFrame(data);
|
|
222
174
|
t.onclose = () => { this._stopPing(); this._failPending('connection closed'); this._setState('closed'); this._emit('close', null); };
|
|
223
175
|
t.onerror = (err) => { this._emit('error', { message: err && err.message ? err.message : 'transport error' }); if (this._pendingResolve) { reject(err); this._pendingResolve = null; } };
|
|
224
|
-
// resolve connect() on welcome
|
|
225
176
|
const off = this.on('welcome', () => { off(); if (this._pendingResolve) { this._pendingResolve(this.host); this._pendingResolve = null; } });
|
|
226
177
|
Promise.resolve(t.connect()).catch((e) => { this._emit('error', { message: e && e.message ? e.message : 'connect failed' }); reject(e); });
|
|
227
178
|
});
|
|
@@ -229,7 +180,6 @@ export class PikichannelClient {
|
|
|
229
180
|
|
|
230
181
|
disconnect() { this._stopPing(); if (this.transport) this.transport.close(); this._setState('closed'); }
|
|
231
182
|
|
|
232
|
-
// -- outbound commands --
|
|
233
183
|
subscribeAll() { this._send({ type: 'subscribe', sessionKey: '*' }); }
|
|
234
184
|
subscribe(sessionKey) { this._send({ type: 'subscribe', sessionKey: sessionKey }); }
|
|
235
185
|
unsubscribe(sessionKey) { this._send({ type: 'unsubscribe', sessionKey: sessionKey }); }
|
|
@@ -247,12 +197,6 @@ export class PikichannelClient {
|
|
|
247
197
|
this._send({ type: 'interact', promptId: promptId, action: action, value: value, requestFreeform: requestFreeform });
|
|
248
198
|
}
|
|
249
199
|
|
|
250
|
-
/**
|
|
251
|
-
* Control-plane HTTP over the channel — full management of the connected host
|
|
252
|
-
* WITHOUT it exposing REST publicly (no CORS, rides the authenticated channel).
|
|
253
|
-
* Only `/api/*` is allowed by the host. Resolves with a fetch-like response:
|
|
254
|
-
* { status, ok, headers, text(), json(), base64(), bytes() }.
|
|
255
|
-
*/
|
|
256
200
|
request(method, path, opts) {
|
|
257
201
|
opts = opts || {};
|
|
258
202
|
let body = opts.body;
|
|
@@ -271,7 +215,6 @@ export class PikichannelClient {
|
|
|
271
215
|
this._pending.clear();
|
|
272
216
|
}
|
|
273
217
|
|
|
274
|
-
// -- inbound --
|
|
275
218
|
_onFrame(data) {
|
|
276
219
|
this._stats.framesIn++;
|
|
277
220
|
this._stats.bytesIn += (data && data.length) ? data.length : 0;
|
|
@@ -289,8 +232,8 @@ export class PikichannelClient {
|
|
|
289
232
|
const lastSeq = this._seqs.get(key);
|
|
290
233
|
const contiguous = lastSeq === undefined || msg.seq === lastSeq + 1 || !!msg.patch.full;
|
|
291
234
|
if (!msg.patch.full && (prev === null || !contiguous)) {
|
|
292
|
-
this.getSnapshot(key);
|
|
293
|
-
break;
|
|
235
|
+
this.getSnapshot(key);
|
|
236
|
+
break;
|
|
294
237
|
}
|
|
295
238
|
const next = applyPatch(prev, msg.patch);
|
|
296
239
|
this.sessions.set(key, next);
|
package/package.json
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{r as a,j as t}from"./react-vendor-C7Sl8SE7.js";import{u as O,d as B,O as R,P as J,c as Q,I as r,m as w,Q as q,V as E,W as D}from"./index-C_neLnaO.js";import{M as V,a as W}from"./Modal-lYfO9m-I.js";import"./router-DHISdpPk.js";function L({open:x,onClose:b}){const j=O(e=>e.locale),c=O(e=>e.toast),n=a.useMemo(()=>B(j),[j]),l=R(),[i,k]=a.useState(l?l.mode:"local"),[p,y]=a.useState(l?.host||""),[N,H]=a.useState(l?.token||""),[C,S]=a.useState(""),[o,u]=a.useState(null),[f,P]=a.useState(""),[d,z]=a.useState(""),[g,h]=a.useState(!1);a.useEffect(()=>{if(!x)return;const e=R();k(e?e.mode:"local"),y(e?.host||""),H(e?.token||""),S(""),fetch("/pikichannel/pair").then(s=>s.ok?s.json():null).then(s=>{s?.ok&&(u(s),P(s.rendezvous||""),z(s.publicHost||""))}).catch(()=>{})},[x]);const M=()=>{if(i==="local")q();else if(i==="direct"){if(!p.trim()){c(n("conn.needHost"),!1);return}E({host:p.trim(),token:N.trim()||void 0})}else{const e=D(C.trim());if(!e){c(n("conn.badCode"),!1);return}E(e)}window.location.reload()},m=o?J(d.trim()?{host:d.trim(),token:o.token}:o.registered&&o.rendezvous&&o.nodeId?{rendezvous:o.rendezvous,nodeId:o.nodeId,token:o.token}:{token:o.token}):"",T=async()=>{h(!0);try{const e=await fetch("/pikichannel/remote",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({publicHost:d.trim()})}).then(s=>s.json());e.ok&&u(s=>({...s||{},publicHost:e.publicHost||""}))}catch{}finally{h(!1)}},I=async e=>{if(e)try{await navigator.clipboard.writeText(e),c(n("conn.copied"))}catch{c(n("conn.copyFail"),!1)}},F=async e=>{if(e&&!f.trim()){c(n("conn.needRdv"),!1);return}h(!0);try{const s=await fetch("/pikichannel/remote",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({enabled:e,rendezvous:f.trim()})}).then(v=>v.json());s.ok?(u(v=>({...v||{},registered:!!s.registered,rendezvous:s.rendezvous||""})),c(n(e?"conn.remoteOn":"conn.remoteOff"))):c(s.error||n("conn.remoteFail"),!1)}catch{c(n("conn.remoteFail"),!1)}finally{h(!1)}},U=[{key:"local",label:n("conn.local"),hint:n("conn.localHint")},{key:"direct",label:n("conn.direct"),hint:n("conn.directHint")},{key:"remote",label:n("conn.remote"),hint:n("conn.remoteHint")}];return t.jsxs(V,{open:x,onClose:b,size:"md",children:[t.jsx(W,{title:n("conn.title"),description:n("conn.subtitle"),onClose:b}),t.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5 mb-2",children:n("conn.targetTitle")}),t.jsx("div",{className:"grid grid-cols-3 gap-2",children:U.map(e=>t.jsxs("button",{onClick:()=>k(e.key),className:Q("rounded-lg border p-2.5 text-left transition-colors",i===e.key?"border-[var(--brand)] bg-[var(--surface-2)]":"border-[var(--edge-default)] hover:border-[var(--edge-strong)]"),children:[t.jsx("div",{className:"text-[13px] font-semibold text-fg",children:e.label}),t.jsx("div",{className:"mt-0.5 text-[11px] leading-snug text-fg-5",children:e.hint})]},e.key))}),t.jsxs("div",{className:"mt-3 space-y-2",children:[i==="direct"&&t.jsxs(t.Fragment,{children:[t.jsx(r,{tone:"inset",value:p,onChange:e=>y(e.target.value),placeholder:n("conn.hostPh")}),t.jsx(r,{tone:"inset",value:N,onChange:e=>H(e.target.value),placeholder:n("conn.tokenPh")})]}),i==="remote"&&t.jsx(r,{tone:"inset",value:C,onChange:e=>S(e.target.value),placeholder:n("conn.codePh")}),i==="local"&&t.jsx("div",{className:"text-[12px] text-fg-4",children:n("conn.localBody")})]}),t.jsx("div",{className:"mt-3 flex justify-end",children:t.jsx(w,{variant:"primary",size:"sm",onClick:M,children:n("conn.connect")})}),t.jsxs("div",{className:"mt-6 border-t border-edge pt-4",children:[t.jsx("div",{className:"text-[11px] font-semibold uppercase tracking-[0.16em] text-fg-5 mb-1",children:n("conn.shareTitle")}),t.jsx("div",{className:"text-[12px] text-fg-4 mb-3",children:n("conn.shareHint")}),o?t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx(r,{tone:"inset",value:d,onChange:e=>z(e.target.value),onBlur:T,placeholder:n("conn.publicHostPh"),disabled:g}),t.jsx("div",{className:"text-[11px] text-fg-5",children:n("conn.publicHostHint")})]}),t.jsxs("label",{className:"flex items-center gap-2 text-[13px] text-fg-2",children:[t.jsx("input",{type:"checkbox",checked:!!o.registered,disabled:g,onChange:e=>F(e.target.checked)}),n("conn.enableRemote")]}),t.jsx(r,{tone:"inset",value:f,onChange:e=>P(e.target.value),placeholder:n("conn.rdvPh"),disabled:g}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(r,{tone:"inset",readOnly:!0,value:m,className:"font-mono text-[11px]"}),t.jsx(w,{variant:"outline",size:"sm",onClick:()=>I(m),children:n("conn.copyCode")})]}),m&&t.jsxs("div",{className:"flex items-center gap-3 pt-0.5",children:[t.jsx("img",{src:`/pikichannel/qr?data=${encodeURIComponent(m)}`,alt:"QR",width:116,height:116,className:"shrink-0 rounded-md bg-white p-2"}),t.jsx("div",{className:"text-[11px] leading-relaxed text-fg-5",children:n("conn.scan")})]}),t.jsx("div",{className:"text-[11px] text-fg-5",children:n("conn.shareFoot")})]}):t.jsx("div",{className:"text-[12px] text-fg-5",children:n("conn.shareUnavailable")})]})]})}export{L as ConnectionModal};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{j as e,r as f}from"./react-vendor-C7Sl8SE7.js";import{K as N,c as C,M as F,u as x,d as G,a as $,m as w,R as z,z as g,F as L}from"./index-C_neLnaO.js";import{S as v}from"./shared-C5uXvhZJ.js";import"./router-DHISdpPk.js";function k(s){return Number.isFinite(s??NaN)?Math.max(0,Math.min(100,Number(s))):null}function S(s){return Number.isFinite(s??NaN)?Number(s).toFixed(2):null}function O(s){return s?[s.hostName||"—",s.platform,s.arch].filter(Boolean).join(" · "):""}function E(s,r){if(!s)return[];const o=s.totalMem||0,i=s.memoryUsed||o-(s.freeMem||0),t=k(s.memoryPercent||(o>0?i/o*100:0)),a=k(s.cpuUsage?.usedPercent),d=s.loadAverage||null,c=S(d?.one),p=S(d?.five),u=S(d?.fifteen),h=k(d?d.one/Math.max(s.cpuCount||1,1)*100:null),y=[{key:"cpu",label:r("sessions.cpu"),value:a!=null?`${a.toFixed(0)}%`:`${s.cpuCount} cores`,detail:[`${s.cpuCount} cores`,s.cpuModel||""].filter(Boolean),tone:a!=null&&a>=85?"warn":"ok",progressPercent:a},...c&&p&&u?[{key:"cpu-load",label:r("system.cpuLoad"),value:`1m ${c}`,detail:[`5m ${p}`,`15m ${u}`],tone:h!=null&&h>=85?"warn":"muted",progressPercent:h}]:[],{key:"memory",label:r("sessions.memory"),value:`${F(i)} / ${F(o)}`,detail:t!=null?`${t.toFixed(0)}%`:void 0,tone:t!=null&&t>=85?"warn":"ok",progressPercent:t}];if(s.disk){const m=k(parseFloat(String(s.disk.percent).replace("%","")));y.push({key:"disk",label:r("sessions.disk"),value:`${s.disk.used} / ${s.disk.total}`,detail:s.disk.percent,tone:m!=null&&m>=85?"warn":"muted",progressPercent:m})}else if(s.battery){const m=k(parseFloat(String(s.battery.percent).replace("%","")));y.push({key:"battery",label:r("sessions.battery"),value:s.battery.percent,detail:s.battery.state,tone:m!=null&&m<=20?"warn":"muted",progressPercent:m})}return y}function K(s){return s?Array.isArray(s)?s.join(" · "):s:""}function W({items:s,loading:r,className:o}){return r?e.jsx("div",{className:C("space-y-1",o),children:Array.from({length:4},(i,t)=>e.jsxs("div",{className:"grid grid-cols-[80px_auto_1fr] items-baseline gap-x-4 py-1",children:[e.jsx(N,{className:"h-3 w-12"}),e.jsx(N,{className:"h-3 w-24"}),e.jsx(N,{className:"h-3 w-28"})]},t))}):e.jsx("div",{className:C("flex flex-wrap items-baseline gap-x-5 gap-y-1.5",o),children:s.map(i=>{const t=K(i.detail);return e.jsxs("div",{className:"inline-flex items-baseline gap-1.5 whitespace-nowrap",title:t||void 0,children:[e.jsx("span",{className:"text-[10px] font-medium uppercase tracking-[0.12em] text-fg-5",children:i.label}),e.jsx("span",{className:"font-mono text-[12px] tabular-nums text-fg-2",children:i.value}),t&&e.jsxs("span",{className:"text-[11px] text-fg-5",children:["· ",t]})]},i.key)})})}const q=[{key:"screenRecording",labelKey:"perm.screenRecording",reasonZh:"用于截图与界面分析",reasonEn:"For screenshots and UI inspection",guidePathKey:"perm.pathScreenRecording",icon:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"4",y:"5.5",width:"11.5",height:"10",rx:"2.4"}),e.jsx("path",{d:"m17.5 8.4 2.7-1.5v7.2l-2.7-1.5"}),e.jsx("circle",{cx:"9.75",cy:"10.5",r:"1.1",fill:"currentColor",stroke:"none"})]})},{key:"fullDiskAccess",labelKey:"perm.fullDiskAccess",reasonZh:"访问桌面、下载等受保护目录",reasonEn:"Access to Desktop, Downloads and other protected folders",guidePathKey:"perm.pathFullDiskAccess",icon:e.jsxs("svg",{width:"18",height:"18",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"6.2",y:"10.1",width:"11.6",height:"8.6",rx:"2.6"}),e.jsx("path",{d:"M9 10V7.8a3 3 0 1 1 6 0V10"}),e.jsx("circle",{cx:"12",cy:"13.5",r:"0.9",fill:"currentColor",stroke:"none"}),e.jsx("path",{d:"M12 14.6v1.8"})]})}];function B(s){return s==="zh-CN"?{introWithHost:"请在 macOS 中为 {hostApp} 开启以下权限。",intro:"请在 macOS 中开启以下权限。",status:"状态",summary:"系统位置",loading:"检查中",needsGrant:"需要授权",granted:"已授权",authorize:"授权",openSettings:"前往设置",refreshState:"刷新状态",checking:"检查中...",hostGranted:"{hostApp} 已可直接使用此权限。",hostGrantedFallback:"当前宿主应用已可直接使用此权限。",needsGrantDetail:"尚未授权,可通过右侧按钮发起系统授权。",needsSettingsDetail:"需要在系统设置中手动开启此权限。"}:{introWithHost:"Grant the following permissions to {hostApp} in macOS.",intro:"Grant the following permissions in macOS.",status:"Status",summary:"System path",loading:"Checking",needsGrant:"Needs access",granted:"Granted",authorize:"Authorize",openSettings:"Open settings",refreshState:"Refresh status",checking:"Checking...",hostGranted:"{hostApp} can use this permission now.",hostGrantedFallback:"The current host app can use this permission now.",needsGrantDetail:"Access has not been granted yet. Use the button on the right to trigger the macOS prompt.",needsSettingsDetail:"This permission needs to be enabled manually in System Settings."}}function I(){const s=x(n=>n.state),r=x(n=>n.locale),o=x(n=>n.reload),i=x(n=>n.toast),t=f.useMemo(()=>G(r),[r]),a=B(r),d=s?.permissions||{},c=s?.hostApp||null,p=!s,[u,h]=f.useState(null),y=f.useMemo(()=>q.map(n=>({...n,permission:d[n.key]})),[d]),m=f.useCallback(async n=>{if(!u){h(n);try{const l=await $.requestPermission(n);if(!l.ok){i(l.error||t("perm.requestFailed"),!1);return}l.action==="already_granted"?i(t("perm.alreadyGranted")):l.action==="prompted"?i(t("perm.promptOpened")):i(t("perm.settingsOpened")),await o()}catch(l){i(l instanceof Error?l.message:t("perm.requestFailed"),!1)}finally{h(l=>l===n?null:l)}}},[o,u,t,i]),M=f.useCallback(async()=>{await o()},[o]);return e.jsxs("div",{className:"animate-in space-y-3",children:[e.jsxs("div",{className:"flex flex-col gap-2 sm:flex-row sm:items-center sm:justify-between",children:[e.jsx("div",{className:"min-w-0 flex-1",children:e.jsx("div",{className:"text-[13px] leading-relaxed text-fg-4",children:c?a.introWithHost.replace("{hostApp}",c):a.intro})}),e.jsx(w,{variant:"outline",size:"sm",onClick:()=>{M()},children:a.refreshState})]}),e.jsx(z,{children:y.map(n=>{const l=n.permission,j=!!l?.granted,P=!!l&&l.checkable,A=p?a.loading:j?a.granted:a.needsGrant,D=p?"idle":j?"ok":"warn",b=p?a.loading:j?c?a.hostGranted.replace("{hostApp}",c):a.hostGrantedFallback:P?a.needsGrantDetail:a.needsSettingsDetail,R=p?a.checking:P?a.authorize:a.openSettings;return e.jsxs(g,{children:[e.jsx(g.Lead,{icon:n.icon,title:t(n.labelKey),subtitle:r==="zh-CN"?n.reasonZh:n.reasonEn}),e.jsx(g.Status,{children:e.jsx(L,{state:D,label:A})}),e.jsx(g.Field,{children:t(n.guidePathKey)}),e.jsx(g.Action,{children:!j&&e.jsx(w,{variant:"primary",size:"sm",disabled:p||!!u,onClick:()=>{m(n.key)},children:u===n.key?a.checking:R})}),b&&b!==A&&e.jsx(g.Description,{children:b})]},n.key)})})]})}function _({onOpenWorkdir:s}){const r=x(c=>c.state),o=x(c=>c.host),i=x(c=>c.locale),t=f.useMemo(()=>G(i),[i]),a=r?.bot?.workdir||r?.runtimeWorkdir||r?.config.workdir||"",d=O(o);return e.jsxs("div",{className:"animate-in space-y-3",children:[e.jsx(v,{className:"!p-3.5",children:e.jsxs("div",{className:"flex items-center justify-between gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"flex items-baseline gap-2",children:e.jsx("span",{className:"text-[13px] font-semibold tracking-tight text-fg",children:t("config.workdir")})}),e.jsx("div",{className:"mt-0.5 break-all font-mono text-[12px] leading-relaxed text-fg-2",children:a||t("sidebar.notSet")})]}),e.jsx(w,{variant:"outline",size:"sm",onClick:s,children:t("sidebar.switchDir")})]})}),e.jsxs(v,{className:"space-y-2 !p-3.5",children:[e.jsxs("div",{className:"flex flex-wrap items-baseline justify-between gap-x-3 gap-y-0.5",children:[e.jsxs("div",{className:"flex items-baseline gap-2 min-w-0",children:[e.jsx("span",{className:"text-[13px] font-semibold tracking-tight text-fg",children:t("app.systemInfo")}),e.jsx("span",{className:"truncate text-[11px] text-fg-5",children:d||t("status.loading")})]}),e.jsxs("div",{className:"text-[11px] text-fg-5",children:[r?.version?`Pikiloom v${r.version}`:"Pikiloom",r?.nodeVersion?` · Node ${r.nodeVersion}`:""]})]}),e.jsx(W,{items:E(o,t),loading:!o})]}),e.jsxs(v,{className:"space-y-2 !p-3.5",children:[e.jsx("div",{className:"text-[13px] font-semibold tracking-tight text-fg",children:t("tab.permissions")}),e.jsx(I,{})]})]})}export{_ as SystemTab};
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SessionPanel-_0dLWvEb.js","assets/react-vendor-C7Sl8SE7.js","assets/index-C_neLnaO.js","assets/router-DHISdpPk.js","assets/index-CyCspgtc.css","assets/Modal-lYfO9m-I.js","assets/Select-BhbU-rll.js","assets/DirBrowser-D-GT-G-w.js","assets/markdown-DxQYQFeH.js","assets/ExtensionsTab-BrJMulJR.js"])))=>i.map(i=>d[i]);
|
|
2
|
-
import{c as M,a as J,u as Ce,i as wn,f as Et,A as ds,s as Ot,S as fe,B as st,g as on,w as us,b as hs,E as Zt,C as hn,d as xs,e as kn,h as ps,n as fs,j as gs,k as Tn,l as Wt,m as Re,D as Ut,o as ms,p as En,_ as In,T as bs,q as vs}from"./index-C_neLnaO.js";import{j as e,r,a as xn}from"./react-vendor-C7Sl8SE7.js";import{I as js}from"./Select-BhbU-rll.js";import{M as Dt,a as Ft}from"./Modal-lYfO9m-I.js";import{D as ws}from"./DirBrowser-D-GT-G-w.js";import{n as ks,r as ys,M as pn}from"./markdown-DxQYQFeH.js";import{WorkspaceExtensionsBody as Ns}from"./ExtensionsTab-BrJMulJR.js";function Ss({open:t,className:n}){return e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:M("shrink-0 text-fg-5/40 transition-transform duration-200",t&&"rotate-180",n),children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})}function rt({open:t,onToggle:n,dot:s,label:a,preview:l,badge:c,collapsedContent:x,children:d,className:m}){return e.jsxs("div",{className:M("rounded-md border border-edge bg-panel overflow-hidden","shadow-[0_2px_8px_rgba(0,0,0,0.06)]",m),children:[e.jsxs("button",{onClick:n,className:"w-full flex items-center gap-2.5 px-3.5 py-2.5 text-left hover:bg-panel-h/40 transition-colors",children:[s&&e.jsx("span",{className:M("h-[7px] w-[7px] shrink-0 rounded-full",s.color,s.pulse&&"animate-pulse")}),e.jsx("span",{className:"text-[10.5px] font-semibold uppercase tracking-[0.14em] text-fg-5",children:a}),e.jsx("span",{className:"flex-1 min-w-0 overflow-hidden",children:l}),c,e.jsx(Ss,{open:t})]}),!t&&x,t&&d&&e.jsx("div",{className:"border-t border-edge",children:d})]})}const Cs=5e3,Ls=15e3,Bt=8,$t=30,Ms=1,nt=new Map,Se=new Map,en=new Set,An=[];let It=0;function tn(t){return typeof t=="number"&&Number.isFinite(t)}function Ke(t,n,s,a){for(t.delete(n),t.set(n,s);t.size>a;){const l=t.keys().next().value;if(!l)break;t.delete(l)}}function Rn(t,n){const s=t.get(n);return!s?.value||s.expiresAt<=Date.now()?null:(Ke(t,n,s,t===Se?$t:Bt),s.value)}function _n(t){return{workdir:t.workdir,agent:t.agent,sessionId:t.sessionId,rich:t.rich??!0,lastNTurns:tn(t.lastNTurns)?t.lastNTurns:void 0,turnOffset:tn(t.turnOffset)?t.turnOffset:void 0,turnLimit:tn(t.turnLimit)?t.turnLimit:void 0}}function fn(t){const n=_n(t);return[n.workdir,n.agent,n.sessionId,n.rich?"rich":"plain",n.lastNTurns??"",n.turnOffset??"",n.turnLimit??""].join("::")}function Pn(){for(;It<Ms;){const t=An.shift();if(!t)return;It+=1,t().finally(()=>{It=Math.max(0,It-1),Pn()})}}async function Ts(t,n={}){const s=t;if(!n.force){const c=Rn(nt,s);if(c)return c}const a=nt.get(s);if(a?.promise)return a.promise;const l=J.getWorkspaceSessions(t,n.request).then(c=>(Ke(nt,s,{value:c,expiresAt:c.ok?Date.now()+Cs:0},Bt),c)).finally(()=>{const c=nt.get(s);c?.promise&&Ke(nt,s,{value:c.value,expiresAt:c.expiresAt},Bt)});return Ke(nt,s,{value:a?.value,expiresAt:a?.expiresAt??0,promise:l},Bt),l}function Es(t,n={}){const s=fn(t),a=Se.get(s);return a?.value?.ok&&(n.allowStale||a.expiresAt>Date.now())?a.value:null}async function Is(t,n={}){const s=_n(t),a=fn(s);if(!n.force){const x=Rn(Se,a);if(x?.ok)return x}const l=Se.get(a);if(l?.promise)return l.promise;const c=J.getSessionMessages(s.workdir,s.agent,s.sessionId,{rich:s.rich,lastNTurns:s.lastNTurns,turnOffset:s.turnOffset,turnLimit:s.turnLimit},n.request).then(x=>(Ke(Se,a,{value:x,expiresAt:x.ok?Date.now()+Ls:0},$t),x)).finally(()=>{const x=Se.get(a);x?.promise&&Ke(Se,a,{value:x.value,expiresAt:x.expiresAt},$t)});return Ke(Se,a,{value:l?.value,expiresAt:l?.expiresAt??0,promise:c},$t),c}function As(t){const n=fn(t);Es(t)||en.has(n)||Se.get(n)?.promise||(en.add(n),An.push(async()=>{try{await Is(t)}catch{}finally{en.delete(n)}}),Pn())}function yn(t){return(t||"").replace(/\s+/g," ").trim()}function eo(t,n){return yn(t)===yn(n)}function to(t){const n=t.richMessages?.length?t.richMessages:t.messages?.map(x=>({role:x.role,text:x.text,blocks:[{type:"text",content:x.text}]}))||[],s=_s(n),a=Math.max(t.window?.totalTurns??t.totalTurns??s.length,s.length),l=t.window?.endTurn??a,c=t.window?.startTurn??Math.max(0,l-s.length);return{turns:s,startTurn:c,endTurn:l,totalTurns:a,hasOlder:t.window?.hasOlder??c>0}}function no(t,n){const s=Math.max(0,t.startTurn-n.startTurn);return{turns:[...n.turns.slice(0,s),...t.turns],startTurn:n.startTurn,endTurn:t.endTurn,totalTurns:Math.max(t.totalTurns,n.totalTurns),hasOlder:n.hasOlder}}function so(t,n){if(n.startTurn<=t.startTurn)return n;const s=Math.max(0,n.startTurn-t.startTurn);return{turns:[...t.turns.slice(0,s),...n.turns],startTurn:t.startTurn,endTurn:n.endTurn,totalTurns:n.totalTurns,hasOlder:t.startTurn>0}}function Rs(t,n){const s=[t.text,n.text].filter(Boolean);return{role:t.role,text:s.join(`
|
|
3
|
-
|
|
4
|
-
`),blocks:[...t.blocks,...n.blocks],usage:n.usage??t.usage??null}}function _s(t){const n=[];let s={user:null,assistant:null};for(const a of t)if(a.role==="user"){if(s.assistant&&Wn(a.text))continue;(s.user||s.assistant)&&(n.push(s),s={user:null,assistant:null}),s.user=a}else s.assistant?s.assistant=Rs(s.assistant,a):s.assistant=a;return(s.user||s.assistant)&&n.push(s),n}const Ps=new Set(["task-notification","system-reminder","persisted-output","local-command-stdout","local-command-caveat","local-command-stderr","ide_opened_file","ide_diagnostics","ide_selection","event","analysis","case_id","tool-use-id","output-file"]),Ws=["continued from a previous","summary below covers","earlier portion of the conversation","Summary:","Key Technical Concepts"];function Wn(t){const s=t.trim().match(/^<([a-z][a-z0-9_-]*)\b/i);return s&&Ps.has(s[1].toLowerCase())?!0:Ws.some(a=>t.includes(a))}function Bn(t,n){const s=t.split(`
|
|
5
|
-
`).filter(a=>a.trim());return s.length<=n?s.join(`
|
|
6
|
-
`):s.slice(-n).join(`
|
|
7
|
-
`)}function Bs(t){const n=String(t||"").trim().toLowerCase();return n?n.startsWith("interrupted by user")?"interrupted":n.startsWith("timed out")||n.startsWith("stopped before completion")||n.includes("max tokens")?"incomplete":"error":"error"}function nn(t){return{id:`${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`,file:t,previewUrl:URL.createObjectURL(t)}}function $s(t){for(const n of t)URL.revokeObjectURL(n.previewUrl)}function $n(t){if(!Number.isFinite(t)||t<=0)return"0 B";if(t<1024)return`${t} B`;const n=t/1024;if(n<1024)return`${n.toFixed(n>=100?0:1)} KB`;const s=n/1024;return`${s.toFixed(s>=100?0:1)} MB`}async function Os(t){if(typeof ClipboardItem>"u"||!navigator.clipboard?.write)return!1;try{return await navigator.clipboard.write([new ClipboardItem({[t.type||"image/png"]:t})]),!0}catch{return!1}}function Q(t,n=120){if(t==null)return"";const a=(typeof t=="string"?t:String(t)).replace(/\s+/g," ").trim();return a.length<=n?a:a.slice(0,Math.max(0,n-1))+"…"}function Ds(t){if(!t)return null;try{const n=JSON.parse(t);return n&&typeof n=="object"&&!Array.isArray(n)?n:null}catch{return null}}function On(t){const n=String(t.toolName||"").trim()||"Tool",s=Ds(t.content);if(!s)return n;const a=Q(s.description,120);switch(n){case"Read":{const l=Q(s.file_path||s.path,140);return l?`Read ${l}`:"Read"}case"Edit":{const l=Q(s.file_path||s.path,140);return l?`Edit ${l}`:"Edit"}case"Write":{const l=Q(s.file_path||s.path,140);return l?`Write ${l}`:"Write"}case"Glob":{const l=Q(s.pattern||s.glob,120);return l?`Glob ${l}`:"Glob"}case"Grep":{const l=Q(s.pattern||s.query,120);return l?`Grep ${l}`:"Grep"}case"WebFetch":{const l=Q(s.url,120);return l?`WebFetch ${l}`:"WebFetch"}case"WebSearch":{const l=Q(s.query,120);return l?`WebSearch ${l}`:"WebSearch"}case"TodoWrite":return"Update plan";case"AskUserQuestion":{const c=(Array.isArray(s.questions)?s.questions:[])[0],x=Q(c?.question||s.question,120);return x?`Ask user: ${x}`:"Ask user"}case"Task":{const l=Q(s.description||s.prompt,120);return l?`Task: ${l}`:"Task"}case"Bash":{if(a)return`Bash: ${a}`;const l=Q(s.command,120);return l?`Bash: ${l}`:"Bash"}default:{const l=n.match(/^mcp__[^_]+__(.+)$/),c=l?l[1]:n;if(c==="im_send_file"){const d=Q(s.path,120);return d?`Send file: ${d}`:"Send file"}if(c==="im_list_files")return"List workspace files";if(a)return`${n}: ${a}`;const x=Q(s.file_path||s.path||s.command||s.query||s.pattern||s.url,120);return x?`${n}: ${x}`:n}}}function Fs(t){const n=(t.content||"").trim();if(!n)return"result";const s=n.split(`
|
|
8
|
-
`).map(a=>a.trim()).find(Boolean)||"";return s?Q(s,140):"result"}function Us(t){const n=t.indexOf(":");if(n<=0)return null;const s=t.slice(0,n).trim(),a=t.slice(n+1).trim();return!s||!a?null:{agent:s,sessionId:a}}const mt=new Map;function zs(t,n){return`${t}:${n}`}function Ks(t){const n=(()=>{try{return new URL(t.baseURL).host.toLowerCase()}catch{return""}})();return n.includes("openrouter")?"openrouter":n.includes("anthropic")?"anthropic":n.includes("deepseek")?"deepseek":n.includes("googleapis")||n.includes("vertex")?"google":n.includes("openai.com")?"openai":n.includes("dashscope")||n.includes("qwen")||n.includes("aliyun")?"qwen":n.includes("volces")||n.includes("volcengine")||n.includes("doubao")?"doubao":n.includes("bigmodel")||n.includes("zhipu")||n.includes("z.ai")?"glm":n.includes("minimax")?"minimax":t.kind==="anthropic"?"anthropic":t.kind==="google"?"google":t.kind==="openai"?"openai":"custom"}const Hs=r.memo(function({session:n,workdir:s,onStreamQueued:a,onSendStart:l,onSendTaskAssigned:c,onSessionChange:x,t:d,streamPhase:m,streamTaskId:v,queuedTaskIds:g,queuedTasks:j,pendingQueuedSends:C,onRecall:k,onSteer:R,onStopAll:I,editDraft:_,onEditDraftConsumed:B,onSelectionChange:y}){const[O,Z]=r.useState(""),[A,K]=r.useState(!1),[$,D]=r.useState(null),[ae,P]=r.useState(()=>new Set),[ce,se]=r.useState(()=>new Set),V=r.useRef({prompt:"",files:[]}),Le=Ce(i=>i.agentStatus?.agents??null),[z,bt]=r.useState(Le||[]),[ge,it]=r.useState(""),[He,Ve]=r.useState(""),[re,_e]=r.useState(""),[ee,Me]=r.useState([]),[Pe,Ge]=r.useState(null),[de,vt]=r.useState(null),[me,oe]=r.useState(null),[We,Te]=r.useState(null),[lt,Ee]=r.useState(null),[te,be]=r.useState(void 0),[L,Y]=r.useState("closed"),[G,jt]=r.useState(null),Ie=r.useRef(null),qe=r.useRef(!1),Be=r.useRef(null),Kt=r.useRef(null),ue=r.useRef(null),ve=r.useRef([]),[je,wt]=r.useState([]),[ie,$e]=r.useState(!1),[Qe,Ye]=r.useState(0),Xe=r.useRef(null),he=Ce(i=>i.refreshAgentStatus),[we,Je]=r.useState([]),[Oe,ke]=r.useState([]),[at,ct]=r.useState({}),ne=r.useCallback(async()=>{try{const[i,p,b]=await Promise.all([fetch("/api/models/providers").then(S=>S.json()),fetch("/api/models/profiles").then(S=>S.json()),fetch("/api/models/agents").then(S=>S.json())]);if(i?.ok&&ke(i.providers||[]),p?.ok&&Je(p.profiles||[]),b?.ok){const S={};for(const F of b.bindings||[])S[F.agent]=F.activeProfileId;ct(S)}}catch{}},[]);r.useEffect(()=>{ne()},[ne]),r.useEffect(()=>{Le?.length&&bt(Le)},[Le]),r.useEffect(()=>{ve.current=ee},[ee]);const ye=zs(n.agent||"",n.sessionId),Ze=r.useRef(ye);Ze.current=ye,r.useEffect(()=>{const i=mt.get(ye);return i&&(mt.delete(ye),i.text&&Z(i.text),i.files.length&&Me(i.files.map(nn))),()=>{const p=Ie.current?.value||"",b=ve.current.map(S=>S.file);for(const S of ve.current)URL.revokeObjectURL(S.previewUrl);p||b.length?mt.set(Ze.current,{text:p,files:b}):mt.delete(Ze.current)}},[ye]);const kt=r.useRef({agent:n.agent||"",sessionId:n.sessionId});r.useEffect(()=>{const i=kt.current,p={agent:n.agent||"",sessionId:n.sessionId};kt.current=p,!(i.agent===p.agent&&wn(i.sessionId)&&!wn(p.sessionId))&&(it(""),Ve(""),_e(""),oe(null),Te(null),Ee(null),Y("closed"))},[n.agent,n.sessionId]),r.useEffect(()=>{_!=null&&(Z(_),B?.(),requestAnimationFrame(()=>{const i=Ie.current;i&&(i.focus(),i.setSelectionRange(_.length,_.length))}))},[_,B]),r.useEffect(()=>{if(!s)return;let i=!1;return J.getSkills(s).then(p=>{!i&&p.ok&&wt(p.skills)}).catch(()=>{}),()=>{i=!0}},[s]);const dt=ie?(()=>{const i=O.match(/^\/(\S*)$/);return i?i[1].toLowerCase():null})():null,Ne=dt!==null?je.filter(i=>i.name.toLowerCase().includes(dt)||i.label&&i.label.toLowerCase().includes(dt)):[];r.useEffect(()=>{Ye(0)},[ie,O]),r.useEffect(()=>{if(!ie||!Xe.current)return;const i=Xe.current.querySelector(`[data-skill-idx="${Qe}"]`);i&&i.scrollIntoView({block:"nearest"})},[Qe,ie]),r.useEffect(()=>{if(!ie)return;const i=p=>{Xe.current?.contains(p.target)||Ie.current?.contains(p.target)||$e(!1)};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[ie]),r.useEffect(()=>{if(L==="closed")return;const i=p=>{const b=p.target;ue.current?.contains(b)||document.getElementById("cascade-portal")?.contains(b)||(Y("closed"),oe(null),Te(null),Ee(null))};return document.addEventListener("mousedown",i),()=>document.removeEventListener("mousedown",i)},[L]),r.useLayoutEffect(()=>{if(L==="closed"||!ue.current){jt(null);return}const i=ue.current.getBoundingClientRect();jt({left:i.left,bottom:window.innerHeight-i.top+8})},[L]);const yt=g&&g.length?g[0]:null;r.useEffect(()=>{$&&(yt||m!==null&&m!=="queued")&&D(null)},[m,$,yt]),r.useEffect(()=>{const i=Ie.current;i&&(i.style.height="auto",i.style.height=Math.min(i.scrollHeight,200)+"px")},[O]);const ut=r.useCallback(i=>{const p=Array.from(i||[]).filter(b=>b.type.startsWith("image/"));p.length&&Me(b=>[...b,...p.map(nn)])},[]),Nt=r.useCallback(()=>{Ge(null),Me(i=>($s(i),[]))},[]),St=r.useCallback(i=>{Me(p=>{const b=p.find(S=>S.id===i);return b&&URL.revokeObjectURL(b.previewUrl),p.filter(S=>S.id!==i)}),Ge(p=>p===i?null:p)},[]),Ct=r.useCallback(()=>{const i=O.trim(),p=ee.map(q=>q.file);if(!i&&p.length===0||A)return;const b=ge||n.agent||z.find(q=>q.isDefault)?.agent||"";if(!b)return;const S=z.find(q=>q.agent===b)||null,F=!!n.agent&&b===n.agent,pe=(He||F&&n.model||""||S?.selectedModel||"").trim()||null,Ue=b==="gemini"?null:(re||(F?Et(b,n.thinkingEffort,n.workflowEnabled):"")||Et(b,S?.selectedEffort,S?.workflowEnabled)||"").trim()||null,Ae=b!==n.agent,le=Ae?"":n.sessionId,Jt=Ae&&n.agent?n.agent:null,as=Ae&&n.sessionId?n.sessionId:null;K(!0),V.current={prompt:i,files:p},Z(""),mt.delete(Ze.current);const cs=p.length?p.map(q=>URL.createObjectURL(q)):void 0;Nt(),l(i,cs),a(),J.sendSessionMessage(s,b,le,i,{attachments:p,model:pe,effort:Ue,previousAgent:Jt,previousSessionId:as}).then(q=>{if(q.taskId&&(D(q.taskId),c?.(q.taskId)),!q.ok)return;const gt=typeof q.sessionKey=="string"?Us(q.sessionKey):null;gt&&(gt.agent!==n.agent||gt.sessionId!==n.sessionId)&>&&x?.({...gt,workdir:s})}).catch(()=>{}).finally(()=>K(!1))},[z,Nt,ee,O,l,c,x,a,ge,re,He,A,n.agent,n.sessionId,s]),ht=m==="streaming",xe=(()=>{const i=[];return g&&g.length&&i.push(...g),m==="queued"&&v&&!i.includes(v)&&i.unshift(v),$&&!i.includes($)&&(m==="queued"||!m)&&i.push($),i})(),Lt=xe[xe.length-1]||null,xt=xe.length>0,Ht=xt||ht;r.useEffect(()=>{const i=p=>xe.includes(p)||p===v;P(p=>{let b=!1;const S=new Set;for(const F of p)i(F)?S.add(F):b=!0;return b?S:p}),se(p=>{let b=!1;const S=new Set;for(const F of p)i(F)?S.add(F):b=!0;return b?S:p})},[xe,v]),r.useEffect(()=>{!xt&&V.current.files.length&&(V.current={prompt:"",files:[]})},[xt]);const Vt=r.useCallback(i=>{if(!ae.has(i)){if(P(p=>{const b=new Set(p);return b.add(i),b}),i===Lt){const p=V.current;p.prompt&&Z(p.prompt),p.files.length&&Me(p.files.map(nn)),V.current={prompt:"",files:[]}}k?.(i),i===$&&D(null)}},[ae,Lt,$,k]),[o,h]=r.useState(!1),u=r.useCallback(async()=>{if(!(o||!I)){h(!0);try{await I()}finally{h(!1)}}},[o,I]),f=r.useCallback(i=>{ce.has(i)||(se(p=>{const b=new Set(p);return b.add(i),b}),R?.(i),i===$&&D(null))},[ce,$,R]),w=r.useCallback(i=>{Z(`/${i.name} `),$e(!1),requestAnimationFrame(()=>{const p=Ie.current;p&&(p.focus(),p.setSelectionRange(p.value.length,p.value.length))})},[]),N=r.useCallback(i=>{Z(i);const p=/^\/\S*$/.test(i)&&je.length>0;$e(p)},[je.length]),T=i=>{if(ie&&Ne.length>0){if(i.key==="ArrowDown"){i.preventDefault(),Ye(p=>(p+1)%Ne.length);return}if(i.key==="ArrowUp"){i.preventDefault(),Ye(p=>(p-1+Ne.length)%Ne.length);return}if(i.key==="Tab"||i.key==="Enter"&&!i.shiftKey&&!qe.current){i.preventDefault(),w(Ne[Qe]);return}if(i.key==="Escape"){i.preventDefault(),$e(!1);return}}i.key==="Enter"&&!i.shiftKey&&!qe.current&&(i.preventDefault(),Ct())},X=r.useCallback(i=>{const p=Array.from(i.clipboardData?.items||[]).filter(b=>b.kind==="file"&&b.type.startsWith("image/")).map(b=>b.getAsFile()).filter(b=>!!b);p.length&&(i.preventDefault(),ut(p))},[ut]),E=ge||n.agent||z.find(i=>i.isDefault)?.agent||z.find(i=>i.installed)?.agent||z[0]?.agent||"",W=z.find(i=>i.agent===E)||null,U=me||E,pt=z.find(i=>i.agent===U)||W,Mt=r.useMemo(()=>{if(!pt)return[];const i=[];for(const b of pt.models||[])i.push({id:b.id,label:b.id,kind:"native",description:b.alias&&b.alias.toLowerCase()!==b.id.toLowerCase()?b.alias:void 0});const p=new Set(ds[U]||[]);for(const b of we){const S=Oe.find(pe=>pe.id===b.providerId);if(!S||!p.has(S.kind))continue;const F=b.name.trim().toLowerCase()!==b.modelId.trim().toLowerCase();i.push({id:b.modelId,label:b.name,kind:"profile",profileId:b.id,description:F?`${S.name} · ${b.modelId}`:S.name})}return i},[pt,U,we,Oe]),es=r.useMemo(()=>Mt.findIndex(i=>i.kind==="profile"),[Mt]),ts=at[U]||null,bn=!!n.agent&&E===n.agent,ft=He||bn&&n.model||""||W?.selectedModel||"",Tt=E==="gemini"?"":re||(bn?Et(E,n.thinkingEffort,n.workflowEnabled):"")||Et(E,W?.selectedEffort,W?.workflowEnabled)||"";r.useEffect(()=>{y?.({model:ft||null,effort:Tt||null})},[ft,Tt,y]);const ns=Zt[U]||[],De=Pe&&ee.find(i=>i.id===Pe)||null,ss=De?{key:De.id,url:De.previewUrl,name:De.file.name,size:De.file.size,file:De.file,onRemove:()=>St(De.id)}:de?{key:de,url:de}:null,vn=(!!O.trim()||ee.length>0)&&!A&&!!E,Gt=()=>{oe(null),Te(null),Ee(null),be(void 0)},qt=r.useCallback(async(i,p,b)=>{const S=i==="gemini"?"":b||"";if(te!==void 0)try{await fetch(`/api/models/agents/${i}/active`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({profileId:te})}),ne(),he()}catch{}it(i),Ve(p),_e(S),Gt(),Y("closed")},[te,ne,he]),rs=()=>{L==="closed"?(Gt(),he(),ne(),Y("agent")):(Gt(),Y("closed"))},Qt=me||E,jn=on(Qt),Yt=We??ft,et=lt??Tt,os=Yt?Ot(Yt):"",Fe=(()=>{const i=at[Qt];return i?we.find(p=>p.id===i)??null:null})(),tt=Fe?Oe.find(i=>i.id===Fe.providerId)??null:null,is=tt?Ks(tt):null,Xt=Fe?Fe.name.trim().toLowerCase()!==Fe.modelId.trim().toLowerCase()?Fe.name:Ot(Fe.modelId):os,ls=[jn.shortLabel,tt?tt.name:null,Xt||null,et?et.charAt(0).toUpperCase()+et.slice(1):null].filter(Boolean).join(" / ");return e.jsxs("div",{className:"shrink-0",ref:Kt,children:[e.jsxs("div",{className:"max-w-[680px] mx-auto px-5 pb-4 pt-2",children:[Ht&&e.jsxs("div",{className:"mb-2 space-y-1.5",children:[ht&&e.jsxs("div",{className:"flex items-center gap-2.5 rounded-lg border border-primary/20 bg-primary/[0.04] px-3.5 py-1.5 transition-colors",children:[e.jsx(fe,{className:"h-3 w-3 text-primary shrink-0"}),e.jsx("span",{className:"flex-1 min-w-0 text-[12px] font-medium text-fg-3 truncate",children:d("hub.running")}),e.jsxs("button",{onClick:u,disabled:o,title:d("hub.stopHint"),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium text-fg-4 hover:text-err hover:bg-err/10 transition-colors disabled:opacity-30 disabled:pointer-events-none shrink-0",children:[o?e.jsx(fe,{className:"h-2.5 w-2.5"}):e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"currentColor",children:e.jsx("rect",{x:"4",y:"4",width:"16",height:"16",rx:"2"})}),d("hub.stop")]})]}),xe.map((i,p)=>{const b=p===xe.length-1,S=ce.has(i),F=S?d("hub.steering"):xe.length>1?`${d("hub.queued")} #${p+1}`:d("hub.queued"),pe=C?.find(le=>le.taskId===i)||(b?C?.find(le=>!le.taskId):void 0),Ue=j?.find(le=>le.taskId===i)?.prompt||pe?.prompt||null,Ae=pe?.imageUrls?.length?pe.imageUrls:[];return e.jsxs("div",{className:"flex items-center gap-2.5 rounded-lg border border-warn/25 bg-warn/[0.04] px-3.5 py-1.5 transition-colors",children:[S?e.jsx(fe,{className:"h-3 w-3 text-warn shrink-0"}):e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-warn animate-pulse shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[e.jsx("span",{className:"text-[12px] font-medium text-warn shrink-0",children:F}),Ae.length>0&&e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[Ae.slice(0,3).map((le,Jt)=>e.jsx("button",{type:"button",onClick:()=>vt(le),title:d("hub.previewImage"),className:"block h-5 w-5 shrink-0 overflow-hidden rounded border border-warn/30 transition-opacity hover:opacity-80",children:e.jsx("img",{src:le,alt:"",className:"h-full w-full object-cover"})},`${le}-${Jt}`)),Ae.length>3&&e.jsxs("span",{className:"text-[10px] text-fg-5/60",children:["+",Ae.length-3]})]}),Ue&&e.jsx("span",{className:"text-[11px] text-fg-5/60 truncate",children:Ue})]}),!S&&e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsxs("button",{onClick:()=>f(i),title:d("hub.steerHint"),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium text-fg-4 hover:text-blue-400 hover:bg-blue-400/10 transition-colors disabled:opacity-30 disabled:pointer-events-none",children:[e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}),d("hub.steer")]}),e.jsxs("button",{onClick:()=>Vt(i),disabled:ae.has(i),title:d("hub.recallHint"),className:"flex items-center gap-1 px-2 py-1 rounded-md text-[11px] font-medium text-fg-4 hover:text-err hover:bg-err/10 transition-colors disabled:opacity-30 disabled:pointer-events-none",children:[ae.has(i)?e.jsx(fe,{className:"h-2.5 w-2.5"}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]}),d("hub.recall")]})]})]},i)})]}),e.jsxs("div",{className:"relative rounded-xl border border-edge/40 bg-panel shadow-sm transition-[border-color,box-shadow] duration-200 focus-within:border-fg-5/40 focus-within:shadow-md",children:[e.jsx("input",{ref:Be,type:"file",accept:"image/*",multiple:!0,className:"hidden",onChange:i=>{ut(i.target.files),i.target.value=""}}),ee.length>0&&e.jsx("div",{className:"px-3 pt-3",children:e.jsx("div",{className:"flex gap-2 overflow-x-auto pb-1",children:ee.map(i=>e.jsxs("div",{className:"relative shrink-0",children:[e.jsxs("button",{type:"button",onClick:()=>Ge(i.id),title:d("hub.previewImage"),className:"group relative h-[72px] w-[72px] overflow-hidden rounded-lg border border-edge/30 bg-panel-alt/30",children:[e.jsx("img",{src:i.previewUrl,alt:i.file.name,className:"h-full w-full object-cover transition-transform duration-200 group-hover:scale-[1.03]"}),e.jsx("div",{className:"pointer-events-none absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/60 via-black/10 to-transparent px-1.5 pb-1 pt-3 text-left",children:e.jsx("div",{className:"truncate text-[8px] font-medium text-white/90 leading-tight",children:i.file.name})})]}),e.jsx("button",{type:"button",onClick:p=>{p.stopPropagation(),St(i.id)},title:d("hub.removeImage"),className:"absolute -right-1 -top-1 flex h-5 w-5 items-center justify-center rounded-full border border-white/10 bg-black/65 text-white/75 transition-colors hover:bg-black/80 hover:text-white",children:e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]},i.id))})}),ie&&Ne.length>0&&e.jsxs("div",{ref:Xe,className:"absolute bottom-full left-0 right-0 mb-1.5 z-50 max-h-[200px] overflow-y-auto rounded-xl border border-edge/40 bg-[var(--th-dropdown)] backdrop-blur-xl shadow-lg animate-in",children:[e.jsx("div",{className:"px-3 pt-2 pb-1 border-b border-edge/20",children:e.jsx("span",{className:"text-[10px] font-semibold text-fg-5 uppercase tracking-wider",children:d("hub.skills")})}),e.jsx("div",{className:"py-1",children:Ne.map((i,p)=>e.jsxs("button",{"data-skill-idx":p,onMouseDown:b=>{b.preventDefault(),w(i)},onMouseEnter:()=>Ye(p),className:M("flex flex-col w-full px-3 py-1.5 text-left transition-colors",p===Qe?"bg-panel-h text-fg":"text-fg-3 hover:bg-panel-alt/50"),children:[e.jsxs("span",{className:"text-[12.5px] font-medium",children:["/",i.name]}),(i.label||i.description)&&e.jsx("span",{className:"text-[11px] text-fg-5 truncate",children:i.label||i.description})]},i.name))})]}),e.jsx("textarea",{ref:Ie,value:O,onChange:i=>N(i.target.value),onPaste:X,onKeyDown:T,onCompositionStart:()=>{qe.current=!0},onCompositionEnd:()=>{qe.current=!1},placeholder:d("hub.inputPlaceholder"),rows:1,className:"w-full resize-none bg-transparent px-4 pt-3 pb-1 text-[13.5px] text-fg outline-none placeholder:text-fg-5/25 leading-[1.6]",style:{maxHeight:200,overflow:O.split(`
|
|
9
|
-
`).length>6?"auto":"hidden"}}),e.jsxs("div",{className:"flex items-center gap-1.5 px-2.5 pb-2 pt-1",children:[e.jsx("button",{type:"button",onClick:()=>Be.current?.click(),title:d("hub.addImages"),className:"flex h-7 w-7 items-center justify-center rounded-lg text-fg-5/50 transition-colors hover:bg-panel-h/60 hover:text-fg-3",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.1",strokeLinecap:"round",children:[e.jsx("path",{d:"M12 5v14"}),e.jsx("path",{d:"M5 12h14"})]})}),e.jsxs("button",{ref:ue,onClick:rs,disabled:!z.length,title:z.length?ls:void 0,className:M("flex items-center gap-1.5 h-[28px] px-2.5 rounded-lg text-[11px] font-medium transition-all duration-200 select-none",L!=="closed"?"bg-panel-h border border-edge-h text-fg-3":"text-fg-5/60 hover:text-fg-4 hover:bg-panel-h/50 border border-transparent"),children:[z.length?e.jsx(st,{brand:Qt,size:12}):e.jsx(fe,{className:"h-3 w-3"}),z.length?e.jsxs("span",{className:"flex items-center gap-1 max-w-[460px] min-w-0 truncate",children:[e.jsx("span",{className:"shrink-0",children:jn.shortLabel}),tt&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx(st,{brand:is||"custom",size:12}),e.jsx("span",{className:"shrink-0 truncate max-w-[140px]",children:tt.name})]}),Xt&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx("span",{className:"truncate",title:Yt||void 0,children:Xt})]}),et&&e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-fg-5/40 shrink-0",children:"/"}),e.jsx("span",{className:"shrink-0",children:et.charAt(0).toUpperCase()+et.slice(1)})]})]}):e.jsx("span",{className:"max-w-[420px] truncate",children:d("hub.selectAgent")}),e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:M("text-fg-5/30 transition-transform duration-200",L!=="closed"&&"rotate-180"),children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]}),L!=="closed"&&G&&xn.createPortal(e.jsxs("div",{id:"cascade-portal",className:"fixed z-[200] w-[300px] rounded-xl border border-edge/40 bg-[var(--th-dropdown)] backdrop-blur-xl shadow-lg overflow-hidden animate-in",style:{left:G.left,bottom:G.bottom},children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 pt-2.5 pb-1.5 border-b border-edge/20",children:[L!=="agent"&&e.jsx("button",{onClick:()=>{if(L==="effort"){const i=pt?.capabilities?.modelSwitch!==!1;Y(i?"model":"agent")}else Y("agent")},className:"p-0.5 rounded text-fg-5/50 hover:text-fg-3 transition-colors",children:e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:e.jsx("polyline",{points:"15 18 9 12 15 6"})})}),e.jsx("span",{className:"text-[10px] font-semibold text-fg-5 uppercase tracking-wider",children:d(L==="agent"?"hub.selectAgent":L==="model"?"hub.selectModel":"hub.selectEffort")}),e.jsx("div",{className:"ml-auto flex items-center gap-0.5",children:(()=>{const p=pt?.capabilities?.modelSwitch!==!1?["agent","model","effort"]:["agent","effort"],b=p.indexOf(L);return p.map((S,F)=>e.jsx("span",{className:M("w-1.5 h-1.5 rounded-full transition-colors",L===S?"bg-primary":F<b?"bg-primary/40":"bg-fg-5/15")},S))})()})]}),e.jsxs("div",{className:"max-h-[200px] overflow-y-auto py-1",children:[L==="agent"&&z.filter(i=>i.installed).map(i=>{const p=on(i.agent),b=us(i.usage),S=b?hs(b):"ok";return e.jsxs(sn,{selected:i.agent===(me||E),onClick:()=>{if(oe(i.agent),Te(i.selectedModel||""),Ee(i.selectedEffort||""),!(i.capabilities?.modelSwitch!==!1)){(Zt[i.agent]||[]).length?Y("effort"):qt(i.agent,i.selectedModel||"",null);return}Y("model")},children:[e.jsx(st,{brand:i.agent,size:14}),e.jsx("span",{style:{color:p.color},children:p.label}),b&&e.jsxs("span",{className:M("ml-auto font-mono text-[10px]",S==="err"?"text-err":S==="warn"?"text-warn":"text-fg-5"),children:[b.label," ",Math.round(b.usedPercent??0),"%"]})]},i.agent)}),L==="model"&&e.jsxs(e.Fragment,{children:[Mt.map((i,p)=>{const b=p===0&&i.kind==="native",S=p===es&&i.kind==="profile",F=te!==void 0?te:ts,pe=i.kind==="profile"?!!i.profileId&&i.profileId===F:!F&&i.id===(We??ft);return e.jsxs("div",{children:[b&&e.jsx("div",{className:"px-3 pb-1 pt-1.5 text-[10px] font-medium uppercase tracking-wide text-fg-5",children:d("hub.modelGroupNative")}),S&&e.jsx("div",{className:"px-3 pb-1 pt-2 text-[10px] font-medium uppercase tracking-wide text-fg-5",children:d("hub.modelGroupProfiles")}),e.jsx(sn,{selected:pe,onClick:()=>{const Ue=me||E;if(Te(i.id),be(i.profileId??null),Zt[Ue]?.length){Y("effort");return}qt(Ue,i.id,null)},children:e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("div",{className:M("truncate text-[11.5px]",i.kind==="native"&&"font-mono text-[11px]"),title:i.id,children:i.label}),i.description&&e.jsx("div",{className:"truncate text-[10px] text-fg-5/80",children:i.description})]})})]},`${i.kind}:${i.profileId||i.id}`)}),Mt.length===0&&e.jsx("div",{className:"px-3 py-3 text-[11px] text-fg-5 text-center",children:d("config.noModel")})]}),L==="effort"&&ns.map(i=>e.jsx(sn,{selected:i===(lt||Tt),onClick:()=>{Ee(i),qt(me||E,We??ft,i)},children:i.charAt(0).toUpperCase()+i.slice(1)},i))]})]}),document.body),e.jsx("div",{className:"flex-1"}),e.jsx("button",{onClick:Ct,disabled:!vn,className:M("flex items-center justify-center w-[30px] h-[30px] rounded-lg transition-all duration-200",vn?"bg-primary text-primary-fg hover:brightness-110 shadow-sm":"bg-fg/6 text-fg-5/20"),children:A?e.jsx(fe,{className:"h-3.5 w-3.5"}):e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("line",{x1:"12",y1:"19",x2:"12",y2:"5"}),e.jsx("polyline",{points:"5 12 12 5 19 12"})]})})]})]})]}),e.jsx(Vs,{source:ss,onClose:()=>{Ge(null),vt(null)},t:d})]})});function Vs({source:t,onClose:n,t:s}){const[a,l]=r.useState(!1);if(r.useEffect(()=>{l(!1)},[t?.key]),r.useEffect(()=>{if(!t)return;const d=m=>{m.key==="Escape"&&n()};return document.addEventListener("keydown",d),()=>document.removeEventListener("keydown",d)},[t,n]),!t)return null;const c=t.file,x=t.onRemove;return xn.createPortal(e.jsx("div",{className:"fixed inset-0 z-[220] flex items-center justify-center bg-black/72 px-4 py-6 backdrop-blur-sm",onClick:n,children:e.jsxs("div",{className:"w-full max-w-[1024px]",onClick:d=>d.stopPropagation(),children:[e.jsxs("div",{className:"mb-3 flex items-center gap-2 text-[11px] text-white/72",children:[t.name&&e.jsx("span",{className:"truncate font-medium text-white/90",children:t.name}),typeof t.size=="number"&&e.jsx("span",{children:$n(t.size)}),e.jsxs("div",{className:"ml-auto flex items-center gap-2",children:[c&&e.jsx("button",{type:"button",onClick:async()=>{await Os(c)&&(l(!0),window.setTimeout(()=>l(!1),1600))},className:"rounded-lg border border-white/12 bg-white/10 px-3 py-1.5 text-[11px] font-medium text-white/88 transition-colors hover:bg-white/14",children:s(a?"hub.copied":"hub.copyImage")}),x&&e.jsx("button",{type:"button",onClick:x,className:"rounded-lg border border-white/12 bg-white/10 px-3 py-1.5 text-[11px] font-medium text-white/88 transition-colors hover:bg-white/14",children:s("hub.removeImage")}),e.jsx("button",{type:"button",onClick:n,className:"flex h-9 w-9 items-center justify-center rounded-full border border-white/12 bg-white/10 text-white/88 transition-colors hover:bg-white/14",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.2",strokeLinecap:"round",children:[e.jsx("path",{d:"M18 6 6 18"}),e.jsx("path",{d:"M6 6l12 12"})]})})]})]}),e.jsx("div",{className:"overflow-hidden rounded-xl border border-white/10 bg-black/35 shadow-[0_20px_70px_rgba(0,0,0,0.45)]",children:e.jsx("img",{src:t.url,alt:t.name||"",className:"max-h-[80vh] w-full object-contain"})})]})}),document.body)}function sn({selected:t,onClick:n,children:s}){return e.jsxs("button",{onClick:n,className:M("flex items-center gap-2 w-full px-3 py-2 text-[12px] text-left transition-colors",t?"text-fg bg-panel-h font-medium":"text-fg-3 hover:bg-panel-alt/50 hover:text-fg-2"),children:[s,t&&e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:"ml-auto text-ok",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}),!t&&e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"ml-auto text-fg-5/20",children:e.jsx("polyline",{points:"9 6 15 12 9 18"})})]})}function Gs(){return function(t){ks(t)}}const gn=[ys,Gs],Dn=t=>/^https?:\/\//.test(t),qs=t=>/^[a-z][a-z0-9+.-]*:\/\//i.test(t);function Qs(t){return t.replace(/:(\d+)(?::\d+)?$/,"")}function Ys(t){let n=t.trim();const s=[["`","`"],['"','"'],["'","'"],["<",">"]];let a=!0;for(;a&&n.length>=2;){a=!1;for(const[l,c]of s)n.startsWith(l)&&n.endsWith(c)&&(n=n.slice(l.length,-c.length).trim(),a=!0)}return n}function Fn(t){let n=Ys(t),s="";for(;n.length>1;){const a=n[n.length-1];if(!a||!/[),.;!?]/.test(a)||a==="."&&/^\.[A-Za-z0-9_-]+$/.test(n))break;s=a+s,n=n.slice(0,-1)}return{text:n,trailing:s}}function ln(t){const n=Fn(t).text;if(!n||Dn(n)||qs(n)&&!n.startsWith("file://"))return!1;const s=Qs(n);if(!s)return!1;if(s.startsWith("file://"))return s.length>7;if(/^[A-Za-z]:[\\/]/.test(s))return!0;if(/^(\/|~\/|\.{1,2}\/)/.test(s))return s.length>1;if(s.includes("/")){const a=s.split("/")[0]||"";return!/^[A-Za-z0-9-]+\.[A-Za-z]{2,}$/.test(a)}return!1}function mn(t,n){J.openInEditor(t,void 0,n||void 0).catch(()=>{})}function Un(t,n,s){t.key!=="Enter"&&t.key!==" "||(t.preventDefault(),mn(n,s))}function Xs({locator:t,workdir:n,children:s}){return e.jsx("span",{role:"link",tabIndex:0,title:t,className:"text-blue-400 underline underline-offset-2 decoration-blue-400/30 cursor-pointer hover:text-blue-300 transition-colors",onClick:()=>mn(t,n),onKeyDown:a=>Un(a,t,n),children:s??t})}function Js({text:t}){const[n,s]=r.useState(!1),a=()=>{navigator.clipboard.writeText(t).then(()=>{s(!0),setTimeout(()=>s(!1),2e3)}).catch(()=>{})};return e.jsx("button",{onClick:a,className:"flex items-center text-fg-5/50 hover:text-fg-3 transition-colors",children:n?e.jsx("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"#34d399",strokeWidth:"2",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})})}function Nn(t){const n=ln(t),s=/^(npm |npx |git |python|pip |yarn |pnpm |cargo |go |make )/.test(t);return n?"bg-blue-500/8 border-blue-400/12 text-blue-300/90":s?"bg-amber-500/8 border-amber-400/10 text-amber-300/80":"bg-[rgba(255,255,255,0.06)] border-edge/20 text-fg-3"}function zt(t={}){const n=t.workdir||null;return{h1:({children:s})=>e.jsx("h2",{className:"text-[16px] font-bold text-fg mt-4 mb-2",children:s}),h2:({children:s})=>e.jsx("h3",{className:"text-[14.5px] font-semibold text-fg mt-4 mb-1.5",children:s}),h3:({children:s})=>e.jsx("h4",{className:"text-[13.5px] font-semibold text-fg mt-3 mb-1",children:s}),p:({children:s})=>e.jsx("p",{className:"my-1.5 whitespace-pre-wrap break-words",children:s}),strong:({children:s})=>e.jsx("strong",{className:"font-semibold text-fg",children:s}),em:({children:s})=>e.jsx("em",{className:"italic text-fg-3",children:s}),a:({href:s,children:a})=>s&&Dn(s)?e.jsx("a",{href:s,target:"_blank",rel:"noopener noreferrer",className:"text-blue-400 underline underline-offset-2 decoration-blue-400/30 cursor-pointer hover:text-blue-300 transition-colors",children:a}):s&&ln(s)?e.jsx(Xs,{locator:Fn(s).text,workdir:n,children:a}):e.jsx("span",{className:"text-blue-400 underline underline-offset-2 decoration-blue-400/30",children:a}),ul:({children:s})=>e.jsx("ul",{className:"space-y-1 my-2 ml-1",children:s}),ol:({children:s})=>e.jsx("ol",{className:"space-y-1 my-2 ml-1 list-decimal list-inside",children:s}),li:({children:s})=>e.jsxs("li",{className:"flex gap-2 items-start",children:[e.jsx("span",{className:"shrink-0 mt-[10px] w-[5px] h-[5px] rounded-full bg-fg-5/40"}),e.jsx("span",{className:"flex-1",children:s})]}),blockquote:({children:s})=>e.jsx("blockquote",{className:"border-l-2 border-fg-5/30 pl-3 my-2 text-fg-4 italic",children:s}),hr:()=>e.jsx("hr",{className:"border-edge/30 my-4"}),code:({className:s,children:a})=>{const l=String(a).replace(/\n$/,""),c=/language-(\w+)/.exec(s||"");if(!c&&!s&&!l.includes(`
|
|
10
|
-
`))return ln(l)?e.jsx("code",{role:"link",tabIndex:0,title:l,className:M("px-1.5 py-[1px] rounded text-[12px] font-mono border cursor-pointer hover:brightness-125 transition-all",Nn(l)),onClick:()=>mn(l,n),onKeyDown:d=>Un(d,l,n),children:l}):e.jsx("code",{className:M("px-1.5 py-[1px] rounded text-[12px] font-mono border",Nn(l)),children:l});const x=c?.[1]||"";return e.jsxs("div",{className:"rounded-lg overflow-hidden border border-edge/30 bg-[rgba(0,0,0,0.25)] my-3 not-prose",children:[e.jsxs("div",{className:"flex items-center justify-between px-3.5 py-1.5 border-b border-edge/15 bg-[rgba(0,0,0,0.12)]",children:[e.jsx("span",{className:"text-[10px] font-mono text-fg-5/50",children:x||"text"}),e.jsx(Js,{text:l})]}),e.jsx("pre",{className:"px-3.5 py-3 text-[12px] leading-[1.65] text-fg-3 font-mono whitespace-pre-wrap break-words overflow-x-auto",children:e.jsx("code",{children:l})})]})},pre:({children:s})=>e.jsx(e.Fragment,{children:s}),table:({children:s})=>e.jsx("div",{className:"my-3 overflow-x-auto rounded-lg border border-edge/30",children:e.jsx("table",{className:"w-full text-[12.5px]",children:s})}),thead:({children:s})=>e.jsx("thead",{className:"bg-[rgba(0,0,0,0.1)]",children:s}),th:({children:s})=>e.jsx("th",{className:"px-3 py-1.5 text-left font-semibold text-fg-3 border-b border-edge/30",children:s}),td:({children:s})=>e.jsx("td",{className:"px-3 py-1.5 text-fg-4 border-t border-edge/12",children:s}),tr:({children:s})=>e.jsx("tr",{className:"even:bg-[rgba(255,255,255,0.015)]",children:s})}}zt();function ot(t){return!!t?.steps?.length}function Zs(t,n){let s=t;for(const[a,l]of Object.entries(n))s=s.replace(new RegExp(`\\{${a}\\}`,"g"),l);return s}function er({status:t}){return t==="completed"?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",className:"text-ok",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):t==="inProgress"?e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-cyan-400 animate-pulse"}):e.jsx("span",{className:"h-1.5 w-1.5 rounded-full bg-fg-5/25"})}function zn({plan:t,t:n,className:s}){const[a,l]=r.useState(!1);if(!ot(t))return null;const c=t.steps.length,x=t.steps.filter(v=>v.status==="completed").length,d=c>0&&x===c,m=Zs(n("hub.planProgress"),{done:String(x),total:String(c)});return e.jsx(rt,{open:a,onToggle:()=>l(v=>!v),dot:{color:d?"bg-emerald-400/60":"bg-cyan-400/60",pulse:!d},label:m,preview:t.explanation?e.jsx("span",{className:"text-[11.5px] text-fg-4 truncate",children:t.explanation}):void 0,badge:e.jsx("span",{className:M("rounded-md border px-1.5 py-0.5 text-[10px] font-mono",d?"border-ok/20 text-ok":"border-edge text-fg-5"),children:n(d?"hub.planDone":"hub.planInProgress")}),className:s,children:e.jsx("div",{className:"px-3.5 py-2.5 space-y-1",children:t.steps.map((v,g)=>{const j=v.status==="completed"?"text-fg-5 line-through decoration-fg-5/40":v.status==="inProgress"?"text-fg-3":"text-fg-4";return e.jsxs("div",{className:"flex items-center gap-2 py-[2px]",children:[e.jsx("span",{className:"shrink-0 flex items-center justify-center w-[10px]",children:e.jsx(er,{status:v.status})}),e.jsx("span",{className:M("text-[12px] leading-[1.5]",j),children:v.step})]},`${g}:${v.step}`)})})})}function Kn({url:t,fileName:n,fileSize:s,caption:a}){return e.jsxs("div",{className:"flex flex-col gap-1 max-w-[340px]",children:[e.jsxs("a",{href:t,download:n,target:"_blank",rel:"noreferrer",title:a||n,className:M("group inline-flex items-center gap-2.5 rounded-md no-underline","border border-fg-6/40 bg-fg-6/[0.05] px-3 py-2","hover:bg-fg-6/[0.12] hover:border-fg-6/60 transition-colors"),children:[e.jsx("span",{className:"grid h-8 w-8 shrink-0 place-items-center rounded bg-fg-6/10 text-fg-3",children:e.jsxs("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]})}),e.jsxs("span",{className:"min-w-0 flex-1",children:[e.jsx("span",{className:"block truncate text-[12.5px] font-medium text-fg-2",children:n}),typeof s=="number"&&s>0&&e.jsx("span",{className:"block text-[11px] text-fg-5/70",children:$n(s)})]}),e.jsx("span",{className:"shrink-0 text-fg-5/50 group-hover:text-fg-3 transition-colors",children:e.jsxs("svg",{width:"15",height:"15",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.6",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4"}),e.jsx("polyline",{points:"7 10 12 15 17 10"}),e.jsx("line",{x1:"12",y1:"15",x2:"12",y2:"3"})]})})]}),a&&e.jsx("span",{className:"px-0.5 text-[11.5px] leading-[1.55] text-fg-4 break-words",children:a})]})}function Hn(t){return!!t.text||!!t.thinking||!!(t.activity&&t.activity.split(`
|
|
11
|
-
`).filter(Boolean).length)||!!t.previewMeta?.toolCalls?.length||ot(t.plan)||!!(t.subAgents&&t.subAgents.length)||!!(t.artifacts&&t.artifacts.length)}function ro(t){return Hn(t)||t.phase==="streaming"?!0:t.phase==="done"&&!!t.error}function tr(t){return t.phase!=="done"||!t.error?null:Hn(t)?"hub.streamErrored":"hub.streamFailed"}function nr({detail:t,t:n,className:s}){const a=Bs(t);if(a==="interrupted")return e.jsxs("div",{className:M("flex items-center gap-1.5 text-[11px] text-fg-5/55",s),children:[e.jsx("span",{className:"inline-block h-2 w-2 rounded-[2px] bg-fg-5/45 shrink-0"}),e.jsx("span",{children:n("hub.turnStopped")})]});const l=a==="error"?{dot:"bg-rose-400/55",text:"text-rose-300/65"}:{dot:"bg-fg-5/40",text:"text-fg-5/55"};return e.jsxs("div",{className:M("flex items-start gap-1.5 text-[11px] leading-[1.6]",l.text,s),children:[e.jsx("span",{className:M("mt-[5px] h-1 w-1 rounded-full shrink-0",l.dot)}),e.jsx("span",{className:"min-w-0 break-words",children:t})]})}const sr=64;function rr(t,n){const[s,a]=r.useState(t),l=r.useRef(0),c=r.useRef(null);return r.useEffect(()=>{if(n<=0)return;const x=Date.now()-l.current,d=()=>{l.current=Date.now(),a(t)};return x>=n?d():(c.current&&clearTimeout(c.current),c.current=window.setTimeout(d,n-x)),()=>{c.current&&clearTimeout(c.current)}},[t,n]),n<=0?t:s}function oo({stream:t,t:n,workdir:s}){const a=ot(t.plan),[l,c]=r.useState(!1),[x,d]=r.useState(!1),m=r.useRef(null),v=r.useRef(null),g=tr(t),j=r.useMemo(()=>(t.activity||"").split(`
|
|
12
|
-
`).filter(Boolean),[t.activity]),C=t.previewMeta?.toolCalls??[],k=j[j.length-1]||C[C.length-1]?.summary||"";r.useLayoutEffect(()=>{const y=m.current;y&&l&&(y.scrollTop=y.scrollHeight)},[l,t.activity,C.length]),r.useLayoutEffect(()=>{const y=v.current;y&&x&&(y.scrollTop=y.scrollHeight)},[x,t.thinking]);const R=t.subAgents??null,I=rr(t.text,t.phase==="streaming"?sr:0),_=r.useMemo(()=>zt({workdir:s}),[s]),B=r.useMemo(()=>e.jsx(pn,{remarkPlugins:gn,components:_,children:I}),[I,_]);return e.jsxs("div",{className:"space-y-3 animate-in",children:[a&&e.jsx(zn,{plan:t.plan,t:n,className:"mb-1 max-w-[760px]"}),R&&R.length>0&&R.map(y=>e.jsx(Vn,{sub:y,t:n},y.id)),(C.length>0||j.length>0)&&e.jsx(rt,{open:l,onToggle:()=>c(y=>!y),dot:{color:"bg-cyan-400/60",pulse:!0},label:n("hub.activity"),preview:e.jsx("span",{className:"text-[12px] text-fg-4 truncate",children:k}),badge:(C.length||j.length)>1?e.jsx(hn,{children:C.length||j.length}):void 0,children:e.jsx("div",{ref:m,className:"px-3.5 py-2.5 space-y-0.5 max-h-[280px] overflow-y-auto",children:C.length>0?C.map(y=>e.jsx(or,{call:y},y.id)):j.map((y,O)=>e.jsxs("div",{className:"flex items-center gap-1.5 py-[2px]",children:[e.jsx("span",{className:"w-1 h-1 rounded-full shrink-0 bg-fg-5/30"}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/60 truncate",children:y})]},O))})}),t.thinking&&e.jsx(rt,{open:x,onToggle:()=>d(y=>!y),dot:{color:"bg-violet-400/50",pulse:!0},label:n("hub.thinking"),collapsedContent:e.jsx("div",{className:"px-3.5 pb-2.5 -mt-0.5 text-[12px] text-fg-4 leading-[1.65] whitespace-pre-wrap break-words line-clamp-3",children:Bn(t.thinking,3)}),children:e.jsx("div",{ref:v,className:"px-3.5 py-3 text-[12px] text-fg-4 leading-[1.7] whitespace-pre-wrap break-words max-h-[280px] overflow-y-auto",children:t.thinking})}),t.text&&e.jsxs("div",{className:"session-md text-[13.5px] leading-[1.75] text-fg-2",children:[B,t.phase==="streaming"&&e.jsx(an,{className:"ml-1 inline-flex align-text-bottom text-fg-4"})]}),t.artifacts&&t.artifacts.length>0&&e.jsx("div",{className:"flex flex-col gap-2",children:t.artifacts.map((y,O)=>y.kind==="photo"?e.jsx("a",{href:y.url,target:"_blank",rel:"noreferrer",className:"inline-block",children:e.jsx("img",{src:y.url,alt:y.caption||y.fileName,className:"max-w-[400px] max-h-[300px] rounded-md border border-fg-6/50 object-contain hover:opacity-90 transition-opacity"})},O):e.jsx(Kn,{url:y.url,fileName:y.fileName,fileSize:y.fileSize,caption:y.caption},O))}),!t.text&&t.phase==="streaming"&&e.jsx("div",{className:"py-1",children:e.jsx(an,{className:"text-fg-5"})}),t.phase==="streaming"&&(t.generatingImages??0)>0&&e.jsxs("div",{className:"flex items-center gap-2 text-[12px] text-fg-4",children:[e.jsxs("span",{className:"relative inline-flex items-center justify-center w-3 h-3",children:[e.jsx("span",{className:"absolute inline-flex w-3 h-3 rounded-full bg-cyan-400/40 animate-ping"}),e.jsx("span",{className:"relative inline-block w-1.5 h-1.5 rounded-full bg-cyan-400/80"})]}),e.jsx("span",{children:t.generatingImages===1?"Generating image…":`Generating ${t.generatingImages} images…`})]}),g&&t.error&&e.jsx(nr,{detail:t.error,t:n,className:"pt-0.5"})]})}function or({call:t}){const[n,s]=r.useState(!1),a=!!(t.input||t.result),l=t.status==="failed"?"bg-rose-400/70":t.status==="running"?"bg-cyan-400/70":"bg-fg-5/30";return e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>a&&s(c=>!c),className:`flex w-full items-center gap-1.5 py-[2px] text-left min-w-0 ${a?"cursor-pointer hover:bg-white/[0.03] rounded":"cursor-default"}`,title:a?void 0:t.summary,children:[e.jsx("span",{className:`w-1 h-1 rounded-full shrink-0 ${l} ${t.status==="running"?"animate-pulse":""}`}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/60 truncate flex-1",children:t.summary}),a&&e.jsx("span",{className:`shrink-0 text-[9px] text-fg-5/40 transition-transform ${n?"rotate-90":""}`,children:"▸"})]}),n&&e.jsxs("div",{className:"ml-2.5 mt-0.5 mb-1 space-y-1 border-l border-white/[0.06] pl-2.5",children:[t.input&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-[10.5px] font-mono leading-[1.55] text-fg-4/80 max-h-[140px] overflow-y-auto",children:t.input}),t.result&&e.jsx("pre",{className:"whitespace-pre-wrap break-words text-[10.5px] font-mono leading-[1.55] text-fg-5/70 max-h-[140px] overflow-y-auto border-t border-white/[0.04] pt-1",children:t.result})]})]})}function an({className:t}){return e.jsxs("span",{className:`thinking-dots inline-flex items-center gap-[3px] ${t||""}`,children:[e.jsx("span",{}),e.jsx("span",{}),e.jsx("span",{})]})}function Vn({sub:t,t:n}){const[s,a]=r.useState(!1),l=t.status,c=l==="failed"?"bg-rose-400/60":l==="done"?"bg-emerald-400/55":"bg-amber-400/60",x=l==="running",d=t.tools,m=r.useMemo(()=>{const j=new Set,C=[];for(const k of d)j.has(k.name)||(j.add(k.name),C.push(k.name));return C},[d]),v=t.kind?`${n("hub.subAgent")||"Sub-agent"} · ${t.kind}`:n("hub.subAgent")||"Sub-agent",g=t.model?Ot(t.model):null;return e.jsx(rt,{open:s,onToggle:()=>a(j=>!j),dot:{color:c,pulse:x},label:v,preview:e.jsxs("span",{className:"flex items-center gap-1.5 min-w-0 text-[12px] text-fg-4",children:[t.description&&e.jsx("span",{className:"truncate",children:t.description}),g&&e.jsx("span",{className:"text-[10px] font-mono text-fg-5/55 shrink-0",children:g}),!t.description&&m.length>0&&e.jsx("span",{className:"font-mono text-fg-5/60 truncate",children:m.join(" · ")})]}),badge:d.length>0?e.jsx(hn,{children:d.length}):void 0,children:e.jsxs("div",{className:"px-3.5 py-2.5 space-y-1 max-h-[260px] overflow-y-auto",children:[t.description&&e.jsx("div",{className:"mb-1.5 text-[12px] text-fg-3 leading-[1.55]",children:t.description}),d.length===0?e.jsxs("div",{className:"text-[11px] font-mono text-fg-5/50",children:["— ",n("hub.subAgentWaiting")||"waiting for first tool…"]}):d.map(j=>e.jsxs("div",{className:"flex items-center gap-1.5 py-[2px]",children:[e.jsx("span",{className:"w-1 h-1 rounded-full shrink-0 bg-fg-5/30"}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/65 truncate",children:j.summary})]},j.id))]})})}function ir({message:t,t:n,workdir:s}){const{activityBlocks:a,thinkingBlocks:l,planBlocks:c,subAgentBlocks:x,outputBlocks:d,noticeBlocks:m}=Gn(t.blocks),v=[...c].reverse().find(j=>ot(j.plan));return a.length>0||x.length>0||!!v?.plan||l.length>0||d.length>0||m.length>0?e.jsxs("div",{className:"space-y-3",children:[a.length>0&&e.jsx(cr,{blocks:a,t:n}),x.map(j=>j.subAgent?e.jsx(Vn,{sub:j.subAgent,t:n},j.toolId||j.subAgent.id):null),v?.plan&&e.jsx(zn,{plan:v.plan,t:n,className:"max-w-[760px]"}),l.length>0&&e.jsx(ur,{blocks:l,t:n}),d.length>0&&e.jsx(pr,{blocks:d,t:n,workdir:s}),m.length>0&&e.jsx(ar,{blocks:m,t:n})]}):null}function lr(t){const{activityBlocks:n,thinkingBlocks:s,planBlocks:a,subAgentBlocks:l,outputBlocks:c,noticeBlocks:x}=Gn(t.blocks);return c.length>0||n.length>0||l.length>0||s.length>0||a.some(d=>ot(d.plan))||x.length>0}function Gn(t){const n=t.filter(s=>s.type==="plan"||s.type==="tool_use"||s.type==="tool_result"||s.type==="image"||s.type==="file"||s.type==="sub_agent"||!!s.content.trim());return{activityBlocks:n.filter(s=>s.type==="tool_use"||s.type==="tool_result"),thinkingBlocks:n.filter(s=>s.type==="thinking"),planBlocks:n.filter(s=>s.type==="plan"&&ot(s.plan)),subAgentBlocks:n.filter(s=>s.type==="sub_agent"),outputBlocks:n.filter(s=>s.type==="text"||s.type==="image"||s.type==="file"),noticeBlocks:n.filter(s=>s.type==="system_notice")}}function ar({blocks:t,t:n}){const s=t.map(a=>a.content).filter(Boolean).join(`
|
|
13
|
-
|
|
14
|
-
`).trim();return s?e.jsxs("div",{className:"flex items-start gap-2 rounded-md border border-amber-500/30 bg-amber-500/[0.06] px-3 py-2 text-[12.5px] leading-[1.7] text-fg-3",children:[e.jsx("span",{className:"mt-[6px] h-1.5 w-1.5 rounded-full bg-amber-400/70 shrink-0"}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"text-[11px] font-mono uppercase tracking-wide text-amber-300/80",children:n("hub.systemNotice")||"Agent notice"}),e.jsx("div",{className:"mt-0.5 break-words whitespace-pre-wrap",children:s})]})]}):null}function cr({blocks:t,t:n}){const[s,a]=r.useState(!1),l=t.filter(m=>m.type==="tool_use"),c=l.length,x=l[l.length-1],d=x?On(x):"";return e.jsx(rt,{open:s,onToggle:()=>a(m=>!m),dot:{color:"bg-cyan-400/60"},label:n("hub.activity"),preview:e.jsx("span",{className:"text-[11.5px] font-mono text-fg-4 truncate",children:d}),badge:c>0?e.jsx(hn,{children:c}):void 0,children:e.jsx("div",{className:"px-3.5 py-2.5 space-y-0.5",children:t.map((m,v)=>e.jsx(dr,{block:m},v))})})}function dr({block:t}){const[n,s]=r.useState(!1),a=t.type==="tool_use",l=a?On(t):Fs(t);return e.jsxs("div",{children:[e.jsxs("button",{onClick:()=>t.content&&s(c=>!c),className:M("flex items-center gap-2 py-[3px] w-full text-left group rounded-sm transition-colors",t.content&&"hover:bg-panel-h/30"),children:[e.jsx("span",{className:M("h-1.5 w-1.5 rounded-full shrink-0",a?"bg-fg-5/40":"bg-ok/40")}),e.jsx("span",{className:"text-[11px] font-mono text-fg-5/60 group-hover:text-fg-3 transition-colors truncate",children:l})]}),n&&t.content&&e.jsx("pre",{className:"ml-3 mt-1 mb-2 p-3 rounded-md bg-inset border border-edge text-[11px] leading-[1.6] text-fg-4 font-mono whitespace-pre-wrap break-words max-h-[240px] overflow-y-auto",children:t.content.length>3e3?t.content.slice(0,3e3)+`
|
|
15
|
-
…`:t.content})]})}function ur({blocks:t,t:n}){const[s,a]=r.useState(!1),l=r.useRef(null),c=t.map(d=>d.content).filter(Boolean).join(`
|
|
16
|
-
|
|
17
|
-
`).trim();if(!c)return null;const x=Bn(c,3);return e.jsx(rt,{open:s,onToggle:()=>a(d=>!d),dot:{color:"bg-violet-400/50"},label:n("hub.thinking"),collapsedContent:x?e.jsx("div",{className:"px-3.5 pb-2.5 -mt-0.5 text-[12px] text-fg-4 leading-[1.65] whitespace-pre-wrap break-words line-clamp-3",children:x}):void 0,children:e.jsx(hr,{scrollRef:l,text:c})})}function hr({scrollRef:t,text:n}){return r.useLayoutEffect(()=>{const s=t.current;s&&(s.scrollTop=s.scrollHeight)},[t]),e.jsx("div",{ref:t,className:"px-3.5 py-3 text-[12px] text-fg-4 leading-[1.7] whitespace-pre-wrap break-words max-h-[320px] overflow-y-auto",children:n})}function xr({block:t,onLightbox:n,t:s}){const a=t.imageCaption?.trim()||"",[l,c]=r.useState(!1);return e.jsxs("figure",{className:"flex flex-col gap-1.5 max-w-[400px]",children:[e.jsx("img",{src:t.content,alt:a||"",className:"max-w-[400px] max-h-[300px] rounded-md border border-fg-6/50 object-contain cursor-zoom-in hover:opacity-90 transition-opacity",onClick:()=>n(t.content)}),a&&e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>c(x=>!x),"aria-expanded":l,className:M("self-start inline-flex items-center gap-1 px-2 py-[3px] rounded-md","text-[11px] font-medium tracking-wide","border border-fg-6/40 bg-fg-6/[0.06] text-fg-3","hover:bg-fg-6/[0.12] hover:text-fg-2 hover:border-fg-6/60","transition-colors"),title:s(l?"hub.imagePromptHide":"hub.imagePromptShow"),children:[e.jsx("span",{"aria-hidden":!0,className:"text-[9px] leading-none",children:l?"▾":"▸"}),e.jsx("span",{children:s("hub.imagePrompt")})]}),l&&e.jsx("div",{className:"rounded-md border border-fg-6/30 bg-fg-6/[0.05] px-3 py-2 max-w-[400px] max-h-[260px] overflow-y-auto",children:e.jsx("div",{className:"text-[11.5px] leading-[1.65] text-fg-3 whitespace-pre-wrap break-words",children:a})})]})]})}function pr({blocks:t,t:n,workdir:s}){const a=t.filter(g=>g.type==="text"),l=t.filter(g=>g.type==="image"),c=t.filter(g=>g.type==="file"),x=a.map(g=>g.content).filter(Boolean).join(`
|
|
18
|
-
|
|
19
|
-
`),[d,m]=r.useState(null),v=r.useMemo(()=>zt({workdir:s}),[s]);return!x.trim()&&l.length===0&&c.length===0?null:e.jsxs(e.Fragment,{children:[x.trim()&&e.jsx("div",{className:"session-md text-[13.5px] leading-[1.75] text-fg-2",children:e.jsx(pn,{remarkPlugins:gn,components:v,children:x})}),l.length>0&&e.jsx("div",{className:"flex flex-wrap gap-3 mt-2",children:l.map((g,j)=>e.jsx(xr,{block:g,onLightbox:m,t:n},j))}),c.length>0&&e.jsx("div",{className:"flex flex-col gap-2 mt-2",children:c.map((g,j)=>e.jsx(Kn,{url:g.content,fileName:g.fileName||"file",fileSize:g.fileSize,caption:g.fileCaption},j))}),d&&e.jsx(qn,{src:d,onClose:()=>m(null)})]})}const io=r.memo(function({turn:n,turnIndex:s,agent:a,meta:l,model:c,effort:x,providerName:d,t:m,workdir:v,onResend:g,onEdit:j,onFork:C}){const k=n.user&&Wn(n.user.text),R=C&&typeof s=="number"?()=>C(s):void 0,I=r.useMemo(()=>zt({workdir:v}),[v]),_=!!n.assistant&&lr(n.assistant);return e.jsxs("div",{className:"session-turn",children:[n.user&&!k&&e.jsx(Qn,{text:n.user.text,blocks:n.user.blocks,t:m,onResend:g,onEdit:j,onFork:R}),k&&n.user&&!n.assistant&&e.jsx("div",{className:"mb-4 px-4 py-3 rounded-lg bg-[rgba(255,255,255,0.02)] border border-edge/20 text-[12.5px] leading-[1.7] text-fg-4",children:e.jsx(pn,{remarkPlugins:gn,components:I,children:n.user.text})}),_&&e.jsxs(e.Fragment,{children:[e.jsx(br,{agent:a,meta:l,model:c,effort:x,providerName:d,previewMeta:n.assistant.usage??null}),e.jsx("div",{className:"mb-6",children:e.jsx(ir,{message:n.assistant,t:m,workdir:v})})]})]})});function qn({src:t,onClose:n}){return r.useEffect(()=>{const s=a=>{a.key==="Escape"&&n()};return window.addEventListener("keydown",s),()=>window.removeEventListener("keydown",s)},[n]),xn.createPortal(e.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/80 backdrop-blur-sm cursor-zoom-out",onClick:n,children:e.jsx("img",{src:t,className:"max-w-[90vw] max-h-[90vh] object-contain rounded-lg shadow-2xl",onClick:s=>s.stopPropagation()})}),document.body)}const fr=1500,gr=16,Sn=8;function mr(t){const n=t.split(`
|
|
20
|
-
`);return n.length<=Sn?t:n.slice(0,Sn).join(`
|
|
21
|
-
`)}function Qn({text:t,blocks:n,t:s,onResend:a,onEdit:l,onFork:c}){const[x,d]=r.useState(!1),[m,v]=r.useState(!1),[g,j]=r.useState(null),C=t?t.split(`
|
|
22
|
-
`).length:0,k=!!t&&(t.length>fr||C>gr),[R,I]=r.useState(!1),_=t?k&&!R?mr(t):t:"",B=!!(a||l||c),y=n?.filter(A=>A.type==="image")||[],O=()=>{navigator.clipboard.writeText(t).then(()=>{v(!0),setTimeout(()=>v(!1),1500)}).catch(()=>{})},Z=s("hub.expand").replace("{chars}",t?t.length.toLocaleString():"0").replace("{lines}",String(C));return e.jsxs("div",{className:"flex flex-col items-end mb-5 group/bubble",onMouseEnter:()=>d(!0),onMouseLeave:()=>d(!1),children:[e.jsxs("div",{className:"max-w-[72%] rounded-md border border-fg-6 bg-panel px-4 py-3 text-[13.5px] leading-[1.72] text-fg shadow-sm",children:[t&&e.jsxs("div",{className:"whitespace-pre-wrap break-words",children:[_,k&&!R&&e.jsx("span",{className:"text-fg-5/60",children:"…"})]}),k&&e.jsx("button",{type:"button",onClick:()=>I(A=>!A),className:"mt-2 text-[11.5px] text-fg-4 hover:text-fg-2 underline decoration-fg-5/40 underline-offset-2 transition-colors",children:R?s("hub.collapse"):Z}),y.length>0&&e.jsx("div",{className:M("flex flex-wrap gap-2",t&&"mt-2"),children:y.map((A,K)=>e.jsx("img",{src:A.content,className:"max-w-[280px] max-h-[200px] rounded border border-fg-6/50 object-cover cursor-zoom-in hover:opacity-90 transition-opacity",onClick:()=>j(A.content)},K))})]}),g&&e.jsx(qn,{src:g,onClose:()=>j(null)}),B&&e.jsxs("div",{className:M("flex items-center gap-1 mt-1.5 mr-1 transition-all duration-200",x?"opacity-100 translate-y-0":"opacity-0 -translate-y-1 pointer-events-none"),children:[e.jsx(At,{label:s(m?"hub.copied":"hub.copy"),onClick:O,children:m?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"#34d399",strokeWidth:"2",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]})}),a&&e.jsx(At,{label:s("hub.rerun"),onClick:()=>a(t),children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}),l&&e.jsx(At,{label:s("hub.edit"),onClick:()=>l(t),children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("path",{d:"M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"}),e.jsx("path",{d:"M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"})]})}),c&&e.jsx(At,{label:s("hub.fork"),onClick:c,children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("circle",{cx:"6",cy:"6",r:"2"}),e.jsx("circle",{cx:"18",cy:"6",r:"2"}),e.jsx("circle",{cx:"12",cy:"20",r:"2"}),e.jsx("path",{d:"M6 8v3a3 3 0 0 0 3 3h6a3 3 0 0 0 3-3V8"}),e.jsx("path",{d:"M12 14v4"})]})})]})]})}function At({label:t,onClick:n,children:s}){return e.jsx("button",{onClick:n,title:t,className:"flex items-center justify-center w-7 h-7 rounded border border-fg-6 bg-panel text-fg-4 shadow-sm hover:text-fg-2 hover:border-edge-h hover:bg-panel-h transition-colors",children:s})}function br({agent:t,meta:n,model:s,effort:a,providerName:l,previewMeta:c,liveStartedAt:x}){const d=c?.contextPercent??null,m=c?.contextUsedTokens??0,v=c?.turnOutputTokens??0,g=d!=null||m>0||v>0,j=x!=null&&x>0,C=c?.providerName??l??null;return e.jsxs("div",{className:"flex items-center gap-1.5 mt-1 mb-3",children:[e.jsx(st,{brand:t,size:13}),e.jsx("span",{style:{color:n.color},className:"text-[12px] font-semibold opacity-70",children:n.label}),(s||a)&&e.jsxs("span",{className:"text-[10px] font-mono text-fg-5/50",children:[s||"",s&&a?" · ":"",a||""]}),C&&e.jsxs("span",{className:"text-[10px] font-mono text-fg-5/70 px-1.5 py-px rounded bg-fg-5/8",title:`This turn is routed through ${C} (BYOK), not the agent CLI's native auth.`,children:["via ",C]}),(g||j)&&e.jsxs("span",{className:"ml-auto inline-flex items-center gap-1 text-[10px] font-mono text-fg-5/55",title:kr(c),children:[d!=null&&e.jsx(yr,{pct:d}),e.jsx("span",{children:d!=null?`${d.toFixed(1)}%`:""}),m>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ",wr(m)]}),v>0&&e.jsxs("span",{className:"text-fg-5/40",children:["· ↑",Yn(v)]}),j&&e.jsx(vr,{startedAt:x,leadingDot:g})]})]})}function vr({startedAt:t,leadingDot:n}){const[,s]=r.useState(0);r.useEffect(()=>{const l=setInterval(()=>s(c=>c+1),1e3);return()=>clearInterval(l)},[]);const a=Math.max(0,Date.now()-t);return e.jsxs("span",{className:"text-fg-5/55 tabular-nums",title:"Elapsed time of the running turn",children:[n?"· ":"",jr(a)]})}function jr(t){const n=Math.floor(t/1e3);if(n<60)return`${n}s`;const s=Math.floor(n/60),a=n%60;return s<60?`${s}m${a.toString().padStart(2,"0")}s`:`${Math.floor(s/60)}h${(s%60).toString().padStart(2,"0")}m`}function wr(t){return`${Yn(t)} tok`}function Yn(t){return t>=1e6?`${(t/1e6).toFixed(1)}M`:t>=1e3?`${(t/1e3).toFixed(1)}k`:`${t}`}function kr(t){if(!t)return"";const n=[];return t.contextPercent!=null&&n.push(`Context: ${t.contextPercent.toFixed(1)}%`),t.inputTokens!=null&&n.push(`Input: ${t.inputTokens.toLocaleString()}`),t.turnOutputTokens!=null?n.push(`Output (turn): ${t.turnOutputTokens.toLocaleString()}`):t.outputTokens!=null&&n.push(`Output: ${t.outputTokens.toLocaleString()}`),t.cachedInputTokens!=null&&n.push(`Cached: ${t.cachedInputTokens.toLocaleString()}`),n.join(" · ")}function yr({pct:t}){const n=t>=85?"bg-rose-400/70":t>=60?"bg-amber-400/70":"bg-emerald-400/70";return e.jsx("span",{className:`h-1.5 w-1.5 rounded-full ${n}`})}function Cn(t,n,s){return t==="zh-CN"?n:s}function Nr({open:t,onClose:n,workdir:s}){const a=Ce(c=>c.locale),l=s.split("/").pop()||s;return e.jsxs(Dt,{open:t,onClose:n,wide:!0,children:[e.jsx(Ft,{title:Cn(a,`${l} — 项目扩展`,`${l} — Project Extensions`),description:Cn(a,"仅对当前工作区生效。直接操作项目目录中的 .mcp.json 与 .pikiloom/skills/。","Project-scoped only. Operates directly on .mcp.json and .pikiloom/skills/ in the workspace directory."),onClose:n}),t?e.jsx(Ns,{workdir:s}):null]})}let Ln=In(()=>import("./SessionPanel-_0dLWvEb.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9]));function cn(){return Ln??=In(()=>import("./SessionPanel-_0dLWvEb.js"),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9])),Ln}const Sr=r.lazy(async()=>({default:(await cn()).SessionPanel})),rn=5,Cr=240,Lr=120,Mr=12,Tr=900*1e3,H=(t,n)=>`${t}:${n}`;function Er(t){const n=new Map;for(const d of t)n.set(H(d.agent||"",d.sessionId),d);const s=new Map,a=new Set;for(const d of t){const m=d.migratedFrom;if(!m||m.kind!=="fork"||!m.sessionId)continue;const v=H(m.agent||d.agent||"",m.sessionId);n.has(v)&&(a.add(H(d.agent||"",d.sessionId)),s.has(v)||s.set(v,[]),s.get(v).push(d))}const l=[],c=new Set,x=(d,m)=>{const v=H(d.agent||"",d.sessionId);if(c.has(v))return;c.add(v),l.push(Object.assign({},d,{__forkDepth:m}));const g=s.get(v);if(g)for(const j of g)x(j,m+1)};for(const d of t){const m=H(d.agent||"",d.sessionId);a.has(m)||x(d,0)}for(const d of t)x(d,0);return l}let Ir=0;function Rt(){return`mk-${Date.now().toString(36)}-${(++Ir).toString(36)}`}function _t(t){try{const n=localStorage.getItem(t);if(n!=null)return n;const s=sessionStorage.getItem(t);if(s!=null){try{localStorage.setItem(t,s),sessionStorage.removeItem(t)}catch{}return s}}catch{}return null}function Pt(t,n){try{localStorage.setItem(t,n)}catch{}}const Ar=[1,2,3,6],dn=6;function Rr(t){for(const n of Ar)if(n>=t)return n;return dn}function Mn(){const t=typeof window<"u"?window.innerWidth:1280;return t>=1920?3:t>=1280?2:1}function ze(t,n){const s=Rr(t);return s>n?s:n}function _r(t){return t==="vscode"||t==="cursor"||t==="windsurf"||t==="finder"||t==="default"}function Pr(t,n){const s=String(t||"").toLowerCase();return s.includes("cursor")?"cursor":s.includes("windsurf")?"windsurf":s.includes("code")||n==="darwin"?"vscode":"default"}function Xn(t){switch(t){case"cursor":return"hub.openTargetCursor";case"windsurf":return"hub.openTargetWindsurf";case"finder":return"hub.openTargetFinder";case"default":return"hub.openTargetDefault";default:return"hub.openTargetVsCode"}}const Wr=r.memo(function({active:n=!0}){const s=Ce(o=>o.locale),a=Ce(o=>o.state?.runtimeWorkdir??null),l=r.useMemo(()=>xs(s),[s]),[c,x]=r.useState([]),[d,m]=r.useState({}),[v,g]=r.useState({}),[j,C]=r.useState(!0),[k,R]=r.useState(()=>{const o=_t("pikiloom-layout-mode");return o==="1"||o==="2"||o==="3"||o==="6"?Number(o):Mn()}),[I,_]=r.useState(()=>{const o=_t("pikiloom-layout-floor");return o==="1"||o==="2"||o==="3"||o==="6"?Number(o):Mn()}),[B,y]=r.useState(()=>{try{const o=_t("pikiloom-open-sessions");if(o){const h=JSON.parse(o);if(Array.isArray(h))return h.map(u=>({...u,mountKey:u.mountKey||Rt()}))}}catch{}return[]}),[O,Z]=r.useState(()=>{const o=_t("pikiloom-active-slot");if(o!=null){const h=Number(o);if(Number.isFinite(h)&&h>=0)return h}return 0}),A=r.useCallback(o=>{R(o),Pt("pikiloom-layout-mode",String(o))},[]),K=r.useCallback(o=>{_(o),Pt("pikiloom-layout-floor",String(o))},[]),$=r.useCallback(o=>{y(h=>{const u=typeof o=="function"?o(h):o,f=u.map(({pendingPrompt:w,pendingImageUrls:N,...T})=>T);return Pt("pikiloom-open-sessions",JSON.stringify(f)),u})},[]),D=r.useCallback(o=>{Z(h=>{const u=typeof o=="function"?o(h):o;return Pt("pikiloom-active-slot",String(u)),u})},[]),ae=r.useCallback(o=>{A(o),K(o)},[A,K]);r.useEffect(()=>{$(o=>o.length>k?o.slice(0,k):o),D(o=>o>=k?k-1:o)},[k]);const[P,ce]=r.useState(!1),se=r.useRef(k);se.current=k;const V=r.useRef(I);V.current=I;const Le=r.useRef(O);Le.current=O;const z=r.useRef(B);z.current=B;const bt=r.useRef(-1),ge=B[O]??null,it=r.useCallback(o=>{if(!o){$([]),D(0);return}const h=o.mountKey?o:{...o,mountKey:Rt()};$(u=>{const f=u.findIndex(N=>N.agent===h.agent&&N.sessionId===h.sessionId);if(f>=0)return D(f),u;if(u.length<se.current){const N=[...u,h];return D(N.length-1),N}if(se.current<dn){const N=[...u,h];return A(ze(N.length,V.current)),D(N.length-1),N}const w=[...u];return w[Le.current]=h,w})},[$,D,A]),[He,Ve]=r.useState(!1),[re,_e]=r.useState(null),[ee,Me]=r.useState(""),[Pe,Ge]=r.useState("all"),[de,vt]=r.useState({}),me=r.useDeferredValue(ee),oe=r.useRef(!1),We=r.useRef({}),Te=r.useRef(d);Te.current=d;const lt=r.useRef(de);lt.current=de;const Ee=r.useRef(new Set),te=r.useRef({});r.useEffect(()=>()=>{for(const o of Object.values(te.current))clearTimeout(o)},[]);const be=r.useCallback(async()=>{try{const o=await J.getWorkspaces(),h=o.ok?o.workspaces:[];h.length&&x(u=>u.length===h.length&&u.every((f,w)=>f.path===h[w].path&&f.name===h[w].name)?u:h),oe.current=!0}catch{oe.current=!0}finally{C(!1)}},[]);r.useEffect(()=>{be()},[be]);const L=r.useCallback(async(o,h={})=>{if(!We.current[o]){We.current[o]=!0,h.background||g(u=>({...u,[o]:!0}));try{const u=await Ts(o,{force:h.force});r.startTransition(()=>{m(f=>{const w=u.sessions||[],N=f[o]||[],T=new Set(w.map(E=>H(E.agent||"",E.sessionId))),X=N.filter(E=>{if(E.runState!=="running")return!1;const W=H(E.agent||"",E.sessionId);if(T.has(W))return!1;const U=lt.current[W];return!(U?.resolvedKey&&U.resolvedKey!==W)});return{...f,[o]:X.length?[...X,...w]:w}})})}catch{h.background||r.startTransition(()=>{m(u=>({...u,[o]:[]}))})}finally{We.current[o]=!1,h.background||g(u=>({...u,[o]:!1}))}}},[]),Y=r.useRef(a);r.useEffect(()=>{a!==Y.current&&(Y.current=a,!(!a||!oe.current)&&be().then(()=>{L(a,{force:!0})}))},[a,be,L]);const G=r.useCallback((o,h)=>{const u=o.agent||"";!u||!o.sessionId||(cn(),As({workdir:h,agent:u,sessionId:o.sessionId,rich:!0,turnOffset:0,turnLimit:Mr}))},[]),jt=r.useCallback((o,h,u=Lr)=>{const f=`${h}:${H(o.agent||"",o.sessionId)}`,w=te.current[f];w&&clearTimeout(w),te.current[f]=setTimeout(()=>{delete te.current[f],G(o,h)},u)},[G]),Ie=r.useCallback((o,h)=>{const u=`${h}:${H(o.agent||"",o.sessionId)}`,f=te.current[u];f&&(clearTimeout(f),delete te.current[u])},[]);r.useEffect(()=>{n&&cn()},[n]),r.useEffect(()=>{if(!n)return;const o=[];return c.forEach((h,u)=>{if(d[h.path]||v[h.path])return;const f=setTimeout(()=>{L(h.path)},u*90);o.push(f)}),()=>{for(const h of o)clearTimeout(h)}},[n,L,v,d,c]);const qe=r.useRef(new Map);kn(n&&oe.current&&c.length>0?"sessions-changed":null,r.useCallback(o=>{if(typeof document<"u"&&document.visibilityState==="hidden")return;const h=o.key,u=h?c.filter(N=>(Te.current[N.path]||[]).some(T=>H(T.agent||"",T.sessionId)===h)):c,f=u.length?u:c,w=qe.current;for(const N of f)w.has(N.path)&&clearTimeout(w.get(N.path)),w.set(N.path,setTimeout(()=>{w.delete(N.path),L(N.path,{background:!0,force:!0})},300))},[c,L]));const Be=r.useCallback(o=>{const h=o.agent||"";return!h||!o.sessionId?o:ps(o,de[H(h,o.sessionId)]||null)},[de]);kn("stream-update",r.useCallback(o=>{const h=o.key;if(!h)return;const u=fs(h,o.snapshot??null);vt(f=>{if(!u){const W=f[h];return!W||W.phase==="done"?f:{...f,[h]:{...W,phase:"done",updatedAt:Date.now()}}}const w=(W,U)=>!!W&&!!U&&W.phase===U.phase&&W.resolvedKey===U.resolvedKey&&W.sessionId===U.sessionId&&W.incomplete===U.incomplete&&W.error===U.error,N=w(f[h],u),T=u.resolvedKey===h||w(f[u.resolvedKey],{...u,key:u.resolvedKey});if(N&&T)return f;const X=Date.now()-Tr,E={};for(const[W,U]of Object.entries(f))U.phase==="done"&&U.updatedAt<X||(E[W]=U);return E[h]=u,u.resolvedKey!==h&&(E[u.resolvedKey]={...u,key:u.resolvedKey}),E})},[])),gs(r.useCallback(()=>{if(!(!n||!oe.current||c.length===0))for(const o of c)L(o.path,{background:!0,force:!0})},[n,c,L])),r.useEffect(()=>{if(!n||!oe.current||c.length===0)return;const o=()=>{if(!(typeof document<"u"&&document.visibilityState==="hidden"))for(const u of c)L(u.path,{background:!0,force:!0})};if(o(),typeof document>"u"||typeof window>"u")return;const h=()=>{document.visibilityState==="visible"&&o()};return document.addEventListener("visibilitychange",h),window.addEventListener("focus",h),()=>{document.removeEventListener("visibilitychange",h),window.removeEventListener("focus",h)}},[n,L,c]),r.useEffect(()=>{if(!n)return;const o=[];return c.forEach((h,u)=>{const f=(d[h.path]||[])[0];if(!f)return;const w=`${h.path}:${H(f.agent||"",f.sessionId)}`;if(Ee.current.has(w))return;const N=setTimeout(()=>{Ee.current.add(w),G(f,h.path)},Cr+u*120);o.push(N)}),()=>{for(const h of o)clearTimeout(h)}},[n,d,G,c]);const Kt=r.useCallback(async o=>{try{(await J.addWorkspace(o)).ok&&(Ve(!1),await be(),L(o))}catch{}},[be,L]),[ue,ve]=r.useState(null),[je,wt]=r.useState(!1),[ie,$e]=r.useState(null),Qe=r.useCallback(o=>{ve(o)},[]),Ye=r.useCallback(async()=>{const o=ue;if(o){wt(!0);try{await J.removeWorkspace(o),x(h=>h.filter(u=>u.path!==o)),m(h=>{const u={...h};return delete u[o],u}),$(h=>{const u=h.filter(f=>f.workdir!==o);return u.length!==h.length&&A(ze(u.length,V.current)),u}),D(0),ve(null)}catch{}finally{wt(!1)}}},[ue]),Xe=r.useCallback(o=>{L(o,{force:!0})},[L]),[he,we]=r.useState(null),[Je,Oe]=r.useState(!1),[ke,at]=r.useState(!1),ct=Ce(o=>o.toast),[ne,ye]=r.useState(null),Ze=r.useCallback((o,h,u)=>{ye({anchor:{right:o.right,bottom:o.bottom},target:{workdir:u,agent:h.agent||"",sessionId:h.sessionId,title:Tn(h).slice(0,120)||h.sessionId.slice(0,16)}})},[]);r.useEffect(()=>{if(!ne)return;const o=()=>ye(null),h=u=>{u.key==="Escape"&&o()};return window.addEventListener("mousedown",o),window.addEventListener("scroll",o,!0),window.addEventListener("resize",o),window.addEventListener("keydown",h),()=>{window.removeEventListener("mousedown",o),window.removeEventListener("scroll",o,!0),window.removeEventListener("resize",o),window.removeEventListener("keydown",h)}},[ne]);const kt=r.useCallback(o=>{Oe(!1),we(o),ye(null)},[]),dt=r.useCallback(async()=>{const o=he;if(o){at(!0);try{const h=await J.deleteSession(o.workdir,o.agent,o.sessionId,Je);if(!h.ok){const u=h.error?.includes("still running")?l("session.deleteRunningError"):h.error||l("session.deleteFailed");ct(u,!1);return}m(u=>{const f=u[o.workdir];if(!f)return u;const w=f.filter(N=>!(N.agent===o.agent&&N.sessionId===o.sessionId));return w.length===f.length?u:{...u,[o.workdir]:w}}),$(u=>{const f=u.filter(w=>!(w.workdir===o.workdir&&w.agent===o.agent&&w.sessionId===o.sessionId));return f.length!==u.length&&A(ze(f.length,V.current)),f}),we(null)}catch(h){ct(h?.message||l("session.deleteFailed"),!1)}finally{at(!1)}}},[he,Je,l,ct]),Ne=r.useCallback(o=>{$(h=>{let u=!1;const f=h.map(w=>w.mountKey===o&&(w.pendingPrompt!=null||w.pendingImageUrls)?(u=!0,{...w,pendingPrompt:null,pendingImageUrls:void 0}):w);return u?f:h})},[$]),yt=r.useCallback((o,h,u)=>{G({agent:o.agent,sessionId:o.sessionId,runState:"running"},o.workdir),m(N=>{const T=N[o.workdir]||[];if(T.some(W=>W.sessionId===o.sessionId&&W.agent===o.agent))return N;const E={sessionId:o.sessionId,agent:o.agent,runState:"running",lastQuestion:h,createdAt:new Date().toISOString(),runUpdatedAt:new Date().toISOString()};return{...N,[o.workdir]:[E,...T]}});const f=bt.current,w={...o,mountKey:Rt(),pendingPrompt:h||null,pendingImageUrls:u&&u.length?u:void 0};r.startTransition(()=>{_e(null),$(N=>{if(f>=N.length)return[...N,w];const T=[...N];return T[f]=w,T}),D(f>=0?f:0)}),L(o.workdir,{background:!0,force:!0})},[L,G,$,D]),ut=r.useCallback(o=>{z.current.length>=se.current&&se.current<dn&&A(ze(se.current+1,V.current)),_e(o)},[A]),Nt=r.useCallback(()=>{_e(null),A(ze(z.current.length,V.current))},[A]),St=r.useCallback((o,h)=>{G(o,h);const u=o.agent||"";z.current.some(f=>f.agent===u&&f.sessionId===o.sessionId)&&A(ze(z.current.length,V.current)),_e(null),r.startTransition(()=>{it({agent:u,sessionId:o.sessionId,workdir:h})})},[G,A]),Ct=r.useCallback((o,h)=>{G({agent:o.agent,sessionId:o.sessionId,runState:"running"},o.workdir),r.startTransition(()=>{h!=null?($(u=>{if(h>=u.length)return u;const f=[...u];return f[h]={...u[h],agent:o.agent,sessionId:o.sessionId,workdir:o.workdir},f}),D(h)):it({...o,mountKey:Rt()})}),L(o.workdir,{background:!0,force:!0})},[L,G]),ht=r.useCallback(o=>{let h=o;if(Pe==="running"?h=h.filter(u=>Wt(u)==="running"):Pe==="review"&&(h=h.filter(u=>Wt(u)==="incomplete")),me.trim()){const u=me.toLowerCase();h=h.filter(f=>(f.lastMessageText||"").toLowerCase().includes(u)||(f.lastQuestion||"").toLowerCase().includes(u)||(f.lastAnswer||"").toLowerCase().includes(u)||(f.title||"").toLowerCase().includes(u)||(f.agent||"").toLowerCase().includes(u))}return h},[me,Pe]),xe=r.useMemo(()=>{const o={};for(const h of c){const u=(d[h.path]||[]).map(Be),f=new Map;for(const N of u){const T=H(N.agent||"",N.sessionId),X=de[T],E=X?.resolvedKey&&X.resolvedKey!==T?X.resolvedKey:T,W=f.get(E);if(!W){f.set(E,N);continue}H(W.agent||"",W.sessionId)!==E&&T===E&&f.set(E,N)}const w=ht([...f.values()]);o[h.path]=Er(w)}return o},[c,d,de,ht,Be]),Lt=r.useCallback(o=>{const h=(d[o.workdir]||[]).find(u=>u.sessionId===o.sessionId&&u.agent===o.agent)??{sessionId:o.sessionId,agent:o.agent,runState:"running"};return Be(h)},[Be,d]),xt=r.useMemo(()=>new Set(B.map(o=>H(o.agent,o.sessionId))),[B]),Ht=ge?H(ge.agent,ge.sessionId):null,Vt=r.useCallback(o=>{$(h=>{const u=h.filter((f,w)=>w!==o);return u.length===0?D(0):Le.current>=u.length&&D(u.length-1),A(ze(u.length,V.current)),u})},[$,D,A]);return e.jsxs("div",{className:"h-full overflow-hidden p-4 flex gap-3 mx-auto",children:[e.jsxs("div",{className:"panel-isolated w-[252px] shrink-0 flex flex-col overflow-hidden rounded-xl border border-edge bg-panel backdrop-blur-sm",style:{boxShadow:"var(--th-card-shadow)"},children:[e.jsxs("div",{className:"px-3 pt-3 pb-2 space-y-2",children:[e.jsxs("div",{className:"relative group",children:[e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"absolute left-2.5 top-1/2 -translate-y-1/2 text-fg-5/40 group-focus-within:text-fg-4 transition-colors",children:[e.jsx("circle",{cx:"11",cy:"11",r:"8"}),e.jsx("line",{x1:"21",y1:"21",x2:"16.65",y2:"16.65"})]}),e.jsx("input",{value:ee,onChange:o=>Me(o.target.value),placeholder:l("hub.search"),className:"w-full rounded-lg border border-edge/40 bg-inset/50 pl-8 pr-7 py-1.5 text-[12px] text-fg outline-none placeholder:text-fg-5/30 focus:border-primary/30 focus:bg-inset focus:shadow-[0_0_0_3px_rgba(99,102,241,0.06)] transition-all duration-200"}),ee&&e.jsx("button",{onClick:()=>Me(""),className:"absolute right-2 top-1/2 -translate-y-1/2 p-0.5 rounded text-fg-5/30 hover:text-fg-4 transition-colors",children:e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsx("div",{className:"flex items-center rounded-lg bg-inset/30 border border-edge/20 p-0.5",children:["all","running","review"].map(o=>e.jsx("button",{onClick:()=>Ge(o),className:M("flex-1 px-2 py-[5px] rounded-md text-[11px] font-medium transition-all duration-200",Pe===o?"bg-panel-h text-fg-2 shadow-[0_1px_2px_rgba(0,0,0,0.1),inset_0_1px_0_rgba(255,255,255,0.04)]":"text-fg-5/60 hover:text-fg-4"),children:l(`hub.filter${o[0].toUpperCase()+o.slice(1)}`)},o))})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:j?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(fe,{className:"h-4 w-4 text-fg-5"})}):c.length===0&&!He?e.jsx("div",{className:"py-12 text-center text-[13px] text-fg-5",children:l("hub.noWorkspaces")}):c.map(o=>e.jsx(Dr,{workspace:o,sessions:xe[o.path]||[],loading:!!v[o.path]||!(o.path in d),isActive:o.path===a,selectedKey:Ht,openSessionKeys:xt,onSelectSession:St,onNewSession:ut,onRefresh:Xe,onRemove:Qe,onExtensions:$e,onWarmSession:jt,onCancelWarmSession:Ie,onSessionMenuOpen:Ze,t:l},o.path))}),e.jsxs("div",{className:"shrink-0 border-t border-edge/20 px-3 py-2 space-y-1.5",children:[e.jsx("div",{className:"flex items-center rounded-md bg-inset/30 border border-edge/20 p-0.5",children:[1,2,3,6].map(o=>e.jsx("button",{onClick:()=>ae(o),className:M("flex-1 flex items-center justify-center p-1.5 rounded transition-all",k===o?"bg-panel-h text-fg-2 shadow-[0_1px_2px_rgba(0,0,0,0.1)]":"text-fg-5/40 hover:text-fg-4"),title:l(`hub.layout${o}`),children:o===1?e.jsx("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:e.jsx("rect",{x:"2",y:"2",width:"12",height:"12",rx:"1.5"})}):o===2?e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"1",y:"2",width:"6",height:"12",rx:"1.5"}),e.jsx("rect",{x:"9",y:"2",width:"6",height:"12",rx:"1.5"})]}):o===3?e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"0.5",y:"2",width:"4",height:"12",rx:"1"}),e.jsx("rect",{x:"6",y:"2",width:"4",height:"12",rx:"1"}),e.jsx("rect",{x:"11.5",y:"2",width:"4",height:"12",rx:"1"})]}):e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:"1.2",children:[e.jsx("rect",{x:"0.5",y:"1",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"6",y:"1",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"11.5",y:"1",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"0.5",y:"9.5",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"6",y:"9.5",width:"4",height:"5.5",rx:"0.8"}),e.jsx("rect",{x:"11.5",y:"9.5",width:"4",height:"5.5",rx:"0.8"})]})},o))}),e.jsxs(Re,{variant:"ghost",size:"sm",onClick:()=>Ve(o=>!o),className:"w-full",children:[e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]}),l("hub.addWorkspace")]})]})]}),e.jsx("div",{className:"flex-1 min-w-0 flex flex-col overflow-hidden gap-0",children:e.jsx("div",{className:"flex-1 min-h-0 grid gap-3",style:{gridTemplateColumns:`repeat(${k===6?3:k}, 1fr)`,gridTemplateRows:k===6?"repeat(2, 1fr)":"1fr"},children:(()=>{const o=re?B.length<k?B.length:O:-1;return bt.current=o,Array.from({length:k},(h,u)=>{if(re&&u===o)return e.jsx("div",{className:"min-w-0 overflow-hidden rounded-xl border border-edge bg-panel flex flex-col",style:{boxShadow:"var(--th-card-shadow)"},children:e.jsx($r,{workdir:re,workspaceName:c.find(T=>T.path===re)?.name||re.split("/").pop()||"",onSessionCreated:yt,onClose:Nt,t:l},re)},`new-${re}`);const f=B[u]??null;if(!f)return e.jsx("div",{className:"min-w-0 overflow-hidden rounded-xl border border-dashed border-edge/40 bg-panel/30 flex items-center justify-center",children:e.jsxs("div",{className:"text-center px-4",children:[e.jsxs("svg",{width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",className:"mx-auto text-fg-5/20 mb-2",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("line",{x1:"12",y1:"8",x2:"12",y2:"16"}),e.jsx("line",{x1:"8",y1:"12",x2:"16",y2:"12"})]}),e.jsx("div",{className:"text-[12px] text-fg-5/40",children:l("hub.emptySlot")})]})},`empty-${u}`);const w=Lt(f),N=u===O;return e.jsxs("div",{className:M("min-w-0 overflow-hidden rounded-xl border bg-panel flex flex-col transition-[border-color,box-shadow] duration-200",N?"border-primary/40 ring-[3px] ring-primary/[0.06]":"border-edge hover:border-edge-h"),style:{boxShadow:N?"var(--th-card-shadow), 0 0 0 1px rgba(14,165,233,0.08)":"var(--th-card-shadow)"},onClick:()=>D(u),children:[e.jsxs("div",{className:M("shrink-0 flex items-center gap-2 px-2.5 h-8 border-b border-edge/30",N?"bg-primary/[0.03]":"bg-panel/60"),children:[(()=>{const T=Wt(w);return e.jsx(Ut,{variant:T==="running"?"ok":T==="waiting"?"info":T==="incomplete"?"warn":"idle",pulse:T==="running"||T==="waiting"})})(),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-0",children:[e.jsx("span",{className:"shrink-0 text-[10px] font-medium text-fg-5",children:f.workdir.split("/").pop()||f.workdir}),e.jsx("span",{className:"shrink-0 text-fg-6 text-[10px] mx-1",children:"/"}),e.jsx("span",{className:"min-w-0 truncate text-[11px] font-medium text-fg-3",children:w.title||w.lastQuestion?.slice(0,60)||f.sessionId.slice(0,12)})]}),e.jsxs("div",{className:"shrink-0 flex items-center gap-2.5 pl-4 text-[9px] text-fg-5/50 tabular-nums",children:[e.jsx("span",{title:l("hub.created"),children:ms(w.createdAt)}),w.runUpdatedAt&&e.jsx("span",{title:l("hub.updated"),children:En(w.runUpdatedAt)}),!!w.numTurns&&e.jsxs("span",{className:"flex items-center gap-0.5",children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"opacity-60",children:e.jsx("path",{d:"M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"})}),w.numTurns]}),e.jsx("button",{"data-filetree-toggle":!0,onClick:T=>{T.stopPropagation(),ce(X=>!X)},className:M("p-0.5 rounded transition-colors",P?"text-fg-3 bg-panel-h":"text-fg-5/40 hover:text-fg-3 hover:bg-panel-h"),title:l("hub.files"),children:e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z"})})}),e.jsx("button",{onClick:T=>{T.stopPropagation(),Vt(u)},className:"p-0.5 rounded text-fg-5/40 hover:text-fg-2 hover:bg-panel-h transition-colors",title:l("hub.closePanel"),children:e.jsxs("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),e.jsx("div",{className:"flex-1 min-h-0",children:e.jsx(r.Suspense,{fallback:e.jsx("div",{className:"h-full"}),children:e.jsx(Sr,{session:w,workdir:f.workdir,active:n&&N,onSessionChange:T=>Ct(T,u),initialPendingPrompt:f.pendingPrompt??null,initialPendingImageUrls:f.pendingImageUrls,onPendingPromptConsumed:()=>Ne(f.mountKey)},f.mountKey)})})]},f.mountKey||H(f.agent,f.sessionId))})})()})}),P&&ge&&e.jsx(Ur,{workdir:ge.workdir,onClose:()=>ce(!1),t:l}),e.jsx(Br,{open:He,initialPath:a||void 0,onAdd:Kt,onClose:()=>Ve(!1),t:l}),e.jsxs(Dt,{open:!!ue,onClose:()=>!je&&ve(null),children:[e.jsx(Ft,{title:l("hub.removeWorkspace"),onClose:()=>!je&&ve(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:l("modal.confirmRemoveWorkspace")}),e.jsx("div",{className:"mt-1 text-[12px] text-fg-5",children:l("modal.confirmRemoveWorkspaceHint")}),ue&&e.jsx("div",{className:"mt-3 rounded-md bg-inset/50 border border-edge/30 px-3 py-2 font-mono text-[11px] text-fg-4 break-all",children:ue}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Re,{variant:"ghost",onClick:()=>ve(null),disabled:je,children:l("modal.cancel")}),e.jsx(Re,{variant:"primary",onClick:Ye,disabled:je,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:l(je?"modal.removing":"modal.remove")})]})]}),ne&&(()=>{const h=Math.max(8,Math.min(ne.anchor.right-160,window.innerWidth-160-8)),u=Math.min(ne.anchor.bottom+4,window.innerHeight-60);return e.jsx("div",{className:"fixed z-[60] min-w-[160px] rounded-md border border-edge bg-panel/95 backdrop-blur-md py-1",style:{left:h,top:u,boxShadow:"0 8px 24px rgba(0,0,0,0.20), 0 2px 6px rgba(0,0,0,0.10)"},onMouseDown:f=>f.stopPropagation(),role:"menu",children:e.jsxs("button",{type:"button",role:"menuitem",onClick:()=>kt(ne.target),className:"w-full flex items-center gap-2 px-3 py-1.5 text-left text-[12px] text-fg-2 hover:bg-panel-h/60 hover:text-red-400 transition-colors",children:[e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("polyline",{points:"3 6 5 6 21 6"}),e.jsx("path",{d:"M19 6l-1 14a2 2 0 01-2 2H8a2 2 0 01-2-2L5 6"}),e.jsx("path",{d:"M10 11v6"}),e.jsx("path",{d:"M14 11v6"}),e.jsx("path",{d:"M9 6V4a2 2 0 012-2h2a2 2 0 012 2v2"})]}),l("session.delete")]})})})(),e.jsxs(Dt,{open:!!he,onClose:()=>!ke&&we(null),children:[e.jsx(Ft,{title:l("session.deleteTitle"),onClose:()=>!ke&&we(null)}),e.jsx("div",{className:"text-[13px] text-fg-3 leading-relaxed",children:l("session.deleteHint")}),he&&e.jsxs("div",{className:"mt-3 rounded-md bg-inset/50 border border-edge/30 px-3 py-2 text-[11px] text-fg-4 break-all",children:[e.jsx("span",{className:"font-mono text-fg-5",children:he.agent}),e.jsx("span",{className:"mx-1.5 text-fg-5/50",children:"·"}),e.jsx("span",{children:he.title})]}),e.jsxs("div",{className:"mt-4 space-y-2",children:[e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"delete-session-scope",checked:!Je,onChange:()=>Oe(!1),disabled:ke,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:l("session.deletePikiloomOnly")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:l("session.deletePikiloomOnlyHint")})]})]}),e.jsxs("label",{className:"flex items-start gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"delete-session-scope",checked:Je,onChange:()=>Oe(!0),disabled:ke,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[12px] text-fg-2",children:l("session.deletePurgeNative")}),e.jsx("div",{className:"text-[11px] text-fg-5 leading-snug mt-0.5",children:l("session.deletePurgeNativeHint")})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 mt-4",children:[e.jsx(Re,{variant:"ghost",onClick:()=>we(null),disabled:ke,children:l("modal.cancel")}),e.jsx(Re,{variant:"primary",onClick:dt,disabled:ke,className:"!bg-red-500/90 !border-red-500/50 hover:!bg-red-500 !text-white",children:l(ke?"session.deleting":"modal.remove")})]})]}),e.jsx(Nr,{open:!!ie,onClose:()=>$e(null),workdir:ie||""})]})});function Br({open:t,initialPath:n,onAdd:s,onClose:a,t:l}){const[c,x]=r.useState(""),d=r.useCallback(m=>x(m),[]);return r.useEffect(()=>{t&&x("")},[t]),e.jsxs(Dt,{open:t,onClose:a,children:[e.jsx(Ft,{title:l("hub.addWorkspace"),onClose:a}),e.jsx(ws,{initialPath:n,maxHeight:360,minHeight:200,onSelect:d,t:l}),e.jsxs("div",{className:"flex gap-2 mt-4",children:[e.jsx(Re,{disabled:!c,onClick:()=>c&&s(c),className:"flex-1",children:l("hub.add")}),e.jsx(Re,{variant:"secondary",onClick:a,className:"flex-1",children:l("hub.cancel")})]})]})}function $r({workdir:t,workspaceName:n,onSessionCreated:s,onClose:a,t:l}){const[c,x]=r.useState(null),[d,m]=r.useState([]),v=r.useRef(null),g=r.useRef([]),j=r.useMemo(()=>({sessionId:"",agent:"",runState:"completed"}),[]),C=r.useCallback(()=>{},[]),k=r.useCallback((_,B)=>{x(_||null),v.current=_||null;const y=B||[];m(y),g.current=y},[]),R=r.useCallback(_=>{const B=g.current;g.current=[],s(_,v.current||void 0,B.length?B:void 0)},[s]),I=!!c||d.length>0;return e.jsxs("div",{className:"flex flex-col h-full overflow-hidden",children:[e.jsxs("div",{className:"shrink-0 flex items-center gap-2 px-4 h-10 border-b border-edge/50 bg-panel/40 backdrop-blur-md z-10",children:[e.jsx("span",{className:"flex-1 min-w-0 text-[13px] font-medium text-fg truncate",children:l("hub.newSession")}),e.jsxs("span",{className:"flex items-center gap-1 text-[10px] text-fg-5/60 shrink-0",children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"opacity-60",children:e.jsx("path",{d:"M22 19a2 2 0 01-2 2H4a2 2 0 01-2-2V5a2 2 0 012-2h5l2 3h9a2 2 0 012 2z"})}),e.jsx("span",{className:"max-w-[80px] truncate",children:n})]}),e.jsx(Ut,{variant:I?"ok":"idle",pulse:I}),!I&&e.jsx("button",{onClick:a,className:"p-1 rounded text-fg-5 hover:text-fg-2 transition-colors",children:e.jsxs("svg",{width:"12",height:"12",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsx("div",{className:"flex-1 overflow-y-auto",children:I?e.jsxs("div",{className:"max-w-[900px] mx-auto px-6 py-6 space-y-0",children:[e.jsx(Qn,{text:c||"",blocks:d.map(_=>({type:"image",content:_})),t:l}),e.jsx("div",{className:"mt-3 mb-4 animate-in",children:e.jsx(an,{className:"text-fg-5"})})]}):e.jsx("div",{className:"flex items-center justify-center h-full",children:e.jsx("div",{className:"text-center space-y-1.5",children:e.jsx("div",{className:"text-[13px] text-fg-5",children:l("hub.newSessionHint")})})})}),e.jsx(Hs,{session:j,workdir:t,onStreamQueued:C,onSendStart:k,onSessionChange:R,t:l,streamPhase:null})]})}function Or({git:t}){if(!t)return null;const n=[t.detached?`detached HEAD${t.shortSha?` @ ${t.shortSha}`:""}`:`branch ${t.branch??"?"}`,t.upstream?`upstream ${t.upstream}`:t.detached?"":"no upstream",t.ahead||t.behind?`↑${t.ahead} ahead · ↓${t.behind} behind`:"",t.changed>0?`${t.changed} changed (${t.staged} staged · ${t.unstaged} unstaged · ${t.untracked} untracked)`:"clean"].filter(Boolean).join(`
|
|
23
|
-
`);return e.jsx(bs,{content:n,className:M("shrink-0 items-center",t.changed>0?"text-amber-400/80":t.ahead||t.behind?"text-sky-400/70":"text-fg-5/50"),onClick:s=>s.stopPropagation(),children:e.jsxs("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("circle",{cx:"6",cy:"6",r:"2.5"}),e.jsx("circle",{cx:"6",cy:"18",r:"2.5"}),e.jsx("circle",{cx:"18",cy:"8",r:"2.5"}),e.jsx("path",{d:"M6 8.5v7"}),e.jsx("path",{d:"M18 10.5c0 4.5-6 3-6 7.5"})]})})}const Dr=r.memo(function({workspace:n,sessions:s,loading:a,isActive:l,selectedKey:c,openSessionKeys:x,onSelectSession:d,onNewSession:m,onRefresh:v,onRemove:g,onExtensions:j,onWarmSession:C,onCancelWarmSession:k,onSessionMenuOpen:R,t:I}){const[_,B]=r.useState(!0),[y,O]=r.useState(rn);r.useEffect(()=>{O(rn)},[s.length]);const Z=s.slice(0,y),A=s.length-y,K=n.path,[$,D]=r.useState(null),ae=r.useCallback(()=>{J.getWorkspaceGit(K).then(P=>D(P.git)).catch(()=>D(null))},[K]);return r.useEffect(()=>{ae()},[ae]),e.jsxs("div",{className:"border-b border-edge/30",children:[e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 cursor-pointer hover:bg-panel-h/50 transition-colors",onClick:()=>B(P=>!P),children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:M("shrink-0 text-fg-5 transition-transform duration-150",_&&"rotate-90"),children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-1.5",children:[e.jsx("span",{className:M("min-w-0 truncate text-[12px] font-semibold",l?"text-primary":"text-fg-3"),children:n.name}),e.jsx(Or,{git:$})]}),l&&e.jsx(Ut,{variant:"ok"}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[e.jsx("button",{onClick:P=>{P.stopPropagation(),m(K)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:I("hub.newSession"),children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",children:[e.jsx("line",{x1:"12",y1:"5",x2:"12",y2:"19"}),e.jsx("line",{x1:"5",y1:"12",x2:"19",y2:"12"})]})}),e.jsx("button",{onClick:P=>{P.stopPropagation(),j(K)},className:"p-1 rounded text-fg-5 hover:text-primary hover:bg-panel-h/60 transition-colors",title:I("hub.extensions"),children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M12 22v-5"}),e.jsx("path",{d:"M9 8V2"}),e.jsx("path",{d:"M15 8V2"}),e.jsx("path",{d:"M18 8v5a6 6 0 0 1-12 0V8z"})]})}),e.jsx("button",{onClick:P=>{P.stopPropagation(),v(K),ae()},className:"p-1 rounded text-fg-5 hover:text-fg-2 hover:bg-panel-h/60 transition-colors",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",children:[e.jsx("polyline",{points:"23 4 23 10 17 10"}),e.jsx("path",{d:"M20.49 15a9 9 0 1 1-2.12-9.36L23 10"})]})}),!l&&e.jsx("button",{onClick:P=>{P.stopPropagation(),g(K)},className:"p-1 rounded text-fg-5 hover:text-red-400 hover:bg-panel-h/60 transition-colors",children:e.jsxs("svg",{width:"13",height:"13",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]})]}),_&&e.jsx("div",{className:"pb-1",children:a?e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(fe,{className:"h-3 w-3 text-fg-5"})}):s.length===0?e.jsx("div",{className:"py-3 text-center text-[11px] text-fg-5",children:I("sessions.noSessions")}):e.jsxs(e.Fragment,{children:[Z.map(P=>{const ce=H(P.agent||"",P.sessionId),se=P.__forkDepth||0;return e.jsx(Fr,{session:P,isSelected:c===ce,isOpen:x?.has(ce)??!1,forkDepth:se,onClick:()=>d(P,K),onWarm:()=>C(P,K),onCancelWarm:()=>k(P,K),onShowMenu:V=>R(V,P,K),menuLabel:I("session.openActions")},ce)}),A>0&&e.jsxs("button",{onClick:()=>O(P=>P+rn),className:"flex items-center gap-1.5 w-full px-3 py-1.5 text-[11px] text-fg-5 hover:text-fg-3 hover:bg-panel-h/50 transition-colors",children:[e.jsxs("span",{children:["+ ",I("hub.nMore").replace("{n}",String(A))]}),e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:e.jsx("polyline",{points:"6 9 12 15 18 9"})})]})]})})]})}),Fr=r.memo(function({session:n,isSelected:s,isOpen:a,forkDepth:l=0,onClick:c,onWarm:x,onCancelWarm:d,onShowMenu:m,menuLabel:v}){const g=on(n.agent||""),j=Wt(n),C=Tn(n).slice(0,500)||n.sessionId.slice(0,16),k=vs(n,C).slice(0,500),R=n.model?Ot(n.model):null,I=l>0?Math.min(l,3)*14:0,_=a?10:12,B=r.useRef(null);return e.jsxs("div",{className:"relative group",children:[e.jsxs("button",{onClick:c,onMouseEnter:x,onFocus:x,onMouseLeave:d,onBlur:d,className:M("w-full pr-3 py-2 text-left transition-all duration-100",s?"bg-selected hover:bg-selected-h":a?"bg-panel-h/30 hover:bg-panel-h/50":"hover:bg-panel-h/50"),style:{paddingLeft:_+I,...a?{borderLeft:`2px solid ${s?g.color:`${g.color}30`}`}:{}},children:[e.jsxs("div",{className:"flex items-center gap-1.5 text-[10px] text-fg-5",children:[l>0&&e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",className:"text-fg-5/60 shrink-0","aria-label":"Fork",children:[e.jsx("circle",{cx:"6",cy:"6",r:"2"}),e.jsx("circle",{cx:"18",cy:"6",r:"2"}),e.jsx("circle",{cx:"12",cy:"20",r:"2"}),e.jsx("path",{d:"M6 8v3a3 3 0 0 0 3 3h6a3 3 0 0 0 3-3V8"}),e.jsx("path",{d:"M12 14v4"})]}),e.jsx(st,{brand:n.agent||"",size:10}),e.jsx("span",{className:"font-medium shrink-0",style:{color:g.color},children:g.shortLabel}),R&&e.jsx("span",{className:"truncate max-w-[72px] font-mono text-fg-5/40 text-[9px]",children:R}),e.jsxs("div",{className:"ml-auto flex items-center gap-1.5 shrink-0 transition-opacity group-hover:opacity-0 group-focus-within:opacity-0",children:[!!n.numTurns&&e.jsxs("span",{className:"flex items-center gap-0.5 text-fg-5/50 tabular-nums",children:[e.jsx("svg",{width:"9",height:"9",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"opacity-50",children:e.jsx("path",{d:"M21 15a2 2 0 01-2 2H7l-4 4V5a2 2 0 012-2h14a2 2 0 012 2z"})}),n.numTurns]}),e.jsx("span",{className:"tabular-nums",children:En(n.runUpdatedAt||n.createdAt)})]})]}),e.jsxs("div",{className:"mt-1 flex items-center gap-1.5",children:[e.jsx(Ut,{variant:j==="running"?"ok":j==="waiting"?"info":j==="incomplete"?"warn":"idle",pulse:j==="running"||j==="waiting"}),e.jsx("span",{className:"truncate text-[12px] leading-snug text-fg-2",children:C})]}),k&&e.jsx("div",{className:"mt-0.5 pl-[11px]",children:e.jsx("span",{className:"block truncate text-[10px] leading-snug text-fg-5",children:k})})]}),e.jsx("button",{ref:B,type:"button","aria-label":v,"aria-haspopup":"menu",onMouseDown:y=>{y.stopPropagation()},onClick:y=>{y.stopPropagation(),y.preventDefault(),B.current&&m(B.current.getBoundingClientRect())},className:"absolute top-1.5 right-1.5 p-1 rounded text-fg-5 opacity-0 group-hover:opacity-100 focus-visible:opacity-100 hover:bg-panel-h hover:text-fg-2 transition-opacity",children:e.jsxs("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"currentColor","aria-hidden":"true",children:[e.jsx("circle",{cx:"12",cy:"5",r:"1.5"}),e.jsx("circle",{cx:"12",cy:"12",r:"1.5"}),e.jsx("circle",{cx:"12",cy:"19",r:"1.5"})]})})]})}),Ur=r.memo(function({workdir:n,onClose:s,t:a}){const l=Ce(g=>g.state?.hostApp??null),c=Ce(g=>g.state?.platform??null),x=Ce(g=>g.toast),[d,m]=r.useState(()=>Pr(l,c)),v=r.useCallback(async g=>{try{const j=await J.openInEditor(g,d);if(!j.ok)throw new Error(j.error||`Failed to open ${g}`)}catch(j){x(j?.message||String(j),!1)}},[d,x]);return e.jsxs("div",{className:"fixed z-50 w-[280px] max-h-[calc(100vh-100px)] flex flex-col rounded-xl border border-edge bg-panel/95 backdrop-blur-md overflow-hidden",style:{boxShadow:"0 8px 32px rgba(0,0,0,0.18), 0 2px 8px rgba(0,0,0,0.12)",right:16,top:80},children:[e.jsxs("div",{className:"shrink-0 flex items-center gap-1.5 px-2.5 py-1.5 border-b border-edge/30",children:[e.jsx("svg",{width:"11",height:"11",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",className:"shrink-0 text-fg-5",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z"})}),e.jsx("span",{className:"flex-1 text-[10px] font-semibold text-fg-4 uppercase tracking-wider",children:a("hub.files")}),e.jsx("button",{onClick:s,className:"p-0.5 rounded text-fg-5/40 hover:text-fg-2 transition-colors",title:a("hub.closePanel"),children:e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:[e.jsx("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),e.jsx("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})})]}),e.jsxs("div",{className:"shrink-0 px-2.5 py-1.5 border-b border-edge/20 flex items-center gap-2",children:[e.jsx(js,{value:d,options:(c==="darwin"?["vscode","finder"]:["vscode"]).map(g=>({value:g,label:a(Xn(g))})),onChange:g=>{_r(g)&&m(g)},renderIcon:g=>e.jsx(Jn,{target:g,size:14})}),e.jsx(Re,{size:"sm",variant:"ghost",onClick:()=>v(n),className:"flex-1 min-w-0 text-[11px]",children:a("hub.openProject")})]}),e.jsx("div",{className:"flex-1 overflow-y-auto px-1 py-1.5",children:e.jsx(zr,{basePath:n,openTarget:d,onOpenPath:v,t:a})})]})});function Jn({target:t,size:n=16}){return t==="default"?e.jsxs("svg",{width:n,height:n,viewBox:"0 0 16 16",className:"shrink-0 text-fg-4",fill:"none",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M6 3H4a1 1 0 0 0-1 1v8a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1v-2"}),e.jsx("path",{d:"M9 2h5v5"}),e.jsx("path",{d:"M14 2L7 9"})]}):e.jsx(st,{brand:t,size:n})}function zr({basePath:t,includeHidden:n=!1,openTarget:s,onOpenPath:a,t:l}){const[c,x]=r.useState([]),[d,m]=r.useState(!0);r.useEffect(()=>{let g=!1;return m(!0),J.lsDir(t,!0,n).then(j=>{!g&&j.ok&&x(j.dirs.slice(0,50).map(C=>({entry:C,expanded:!1,children:null,loading:!1})))}).catch(()=>{}).finally(()=>{g||m(!1)}),()=>{g=!0}},[t,n]);const v=r.useCallback(g=>{const j=C=>C.map(k=>k.entry.path===g?k.expanded?{...k,expanded:!1}:k.children===null?(J.lsDir(g,!0,n).then(R=>{R.ok&&x(I=>un(I,g,{children:R.dirs.slice(0,50).map(_=>({entry:_,expanded:!1,children:null,loading:!1})),loading:!1}))}).catch(()=>{x(R=>un(R,g,{children:[],loading:!1}))}),{...k,loading:!0,expanded:!0}):{...k,expanded:!0}:k.children?{...k,children:j(k.children)}:k);x(C=>j(C))},[n]);return d?e.jsx("div",{className:"flex justify-center py-3",children:e.jsx(fe,{className:"h-3 w-3 text-fg-5"})}):c.length===0?e.jsx("div",{className:"py-3 text-center text-[11px] text-fg-5",children:"—"}):e.jsx("div",{className:"space-y-px",children:e.jsx(Zn,{nodes:c,depth:0,onToggle:v,openTarget:s,onOpenPath:a,t:l})})}function Zn({nodes:t,depth:n,onToggle:s,openTarget:a,onOpenPath:l,t:c}){return e.jsx(e.Fragment,{children:t.map(x=>e.jsx(Kr,{node:x,depth:n,onToggle:s,openTarget:a,onOpenPath:l,t:c},x.entry.path))})}function Kr({node:t,depth:n,onToggle:s,openTarget:a,onOpenPath:l,t:c}){const{entry:x,expanded:d,children:m,loading:v}=t,g=n*14,[j,C]=r.useState(!1),k=c(Xn(a)),R=c("hub.openWithTarget").replace("{target}",k);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{onClick:x.isDir?()=>s(x.path):void 0,onMouseEnter:()=>C(!0),onMouseLeave:()=>C(!1),className:M("flex items-center gap-1.5 py-1 rounded text-[11px] text-fg-3 transition-colors",x.isDir?"hover:bg-panel-h/50 cursor-pointer":"hover:bg-panel-h/50 cursor-default"),style:{paddingLeft:8+g,paddingRight:8},children:[x.isDir?v?e.jsx(fe,{className:"h-2 w-2 text-fg-5 shrink-0"}):e.jsx("svg",{width:"8",height:"8",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",className:M("shrink-0 text-fg-5/40 transition-transform duration-150",d&&"rotate-90"),children:e.jsx("polyline",{points:"9 6 15 12 9 18"})}):e.jsx("span",{className:"w-2 shrink-0"}),x.isDir?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",className:"shrink-0 text-blue-400/70",children:e.jsx("path",{d:"M2 6a2 2 0 012-2h5l2 2h9a2 2 0 012 2v10a2 2 0 01-2 2H4a2 2 0 01-2-2V6z",fill:"currentColor",opacity:"0.25",stroke:"currentColor",strokeWidth:"1.5"})}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",className:"shrink-0 text-fg-5",children:[e.jsx("path",{d:"M14 2H6a2 2 0 00-2 2v16a2 2 0 002 2h12a2 2 0 002-2V8z"}),e.jsx("polyline",{points:"14 2 14 8 20 8"})]}),e.jsx("span",{className:"truncate flex-1",children:x.name}),j&&e.jsxs("div",{className:"flex items-center gap-0.5 shrink-0",children:[e.jsx("button",{onClick:I=>{I.stopPropagation(),l(x.path)},className:"inline-flex items-center gap-1 rounded px-1 py-0.5 text-fg-5 hover:text-blue-400 transition-colors",title:R,children:e.jsx(Jn,{target:a,subtle:!0})}),!x.isDir&&e.jsx(Hr,{filePath:x.path,t:c})]})]}),x.isDir&&d&&m&&m.length>0&&e.jsx(Zn,{nodes:m,depth:n+1,onToggle:s,openTarget:a,onOpenPath:l,t:c})]})}function Hr({filePath:t,t:n}){const[s,a]=r.useState(!1);return e.jsx("button",{onClick:l=>{l.stopPropagation(),navigator.clipboard.writeText(t).then(()=>{a(!0),setTimeout(()=>a(!1),1500)}).catch(()=>{})},className:M("p-0.5 rounded transition-colors",s?"text-ok":"text-fg-5 hover:text-fg-3"),title:n("hub.copied"),children:s?e.jsx("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",children:e.jsx("polyline",{points:"20 6 9 17 4 12"})}):e.jsxs("svg",{width:"10",height:"10",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.5",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 01-2-2V4a2 2 0 012-2h9a2 2 0 012 2v1"})]})})}function un(t,n,s){return t.map(a=>a.entry.path===n?{...a,...s}:a.children?{...a,children:un(a.children,n,s)}:a)}const lo=Object.freeze(Object.defineProperty({__proto__:null,SessionWorkspace:Wr},Symbol.toStringTag,{value:"Module"}));export{Hs as I,oo as L,nr as R,io as T,Qn as U,no as a,Hn as b,an as c,ro as d,br as e,lo as i,Is as l,so as m,to as n,Es as p,eo as s};
|