@hybridaione/hybridclaw 0.27.0 → 0.27.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +46 -0
- package/README.md +7 -5
- package/console/dist/assets/{apps-BCUhkPkB.js → apps-_oJDy7mi.js} +1 -1
- package/console/dist/assets/chat-DtbW21G6.js +4 -0
- package/console/dist/assets/{chat-sidebar-bGb6YbfM.js → chat-sidebar-ZV6o-A2S.js} +1 -1
- package/console/dist/assets/{index-Btzl6jZZ.js → index-B7ZQvYLH.js} +4 -4
- package/console/dist/assets/index-BIPFwWNZ.css +1 -0
- package/console/dist/assets/{terminal-BOibs0Ai.js → terminal-CJP-btmG.js} +1 -1
- package/console/dist/index.html +2 -2
- package/console/package.json +1 -1
- package/container/dist/chat-segments.js +44 -0
- package/container/dist/chat-segments.js.map +1 -0
- package/container/dist/index.js +47 -29
- package/container/dist/index.js.map +1 -1
- package/container/dist/tool-progress-log.js +23 -0
- package/container/dist/tool-progress-log.js.map +1 -0
- package/container/npm-shrinkwrap.json +2 -2
- package/container/package-lock.json +2 -2
- package/container/package.json +1 -1
- package/container/src/chat-segments.ts +73 -0
- package/container/src/index.ts +67 -36
- package/container/src/tool-progress-log.ts +38 -0
- package/container/src/types.ts +15 -0
- package/dist/agent/prompt-hooks.d.ts.map +1 -1
- package/dist/agent/prompt-hooks.js +1 -0
- package/dist/agent/prompt-hooks.js.map +1 -1
- package/dist/channels/email/connection.d.ts.map +1 -1
- package/dist/channels/email/connection.js +21 -11
- package/dist/channels/email/connection.js.map +1 -1
- package/dist/gateway/gateway-chat-service.d.ts.map +1 -1
- package/dist/gateway/gateway-chat-service.js +55 -2
- package/dist/gateway/gateway-chat-service.js.map +1 -1
- package/dist/gateway/gateway-http-server.d.ts.map +1 -1
- package/dist/gateway/gateway-http-server.js +18 -4
- package/dist/gateway/gateway-http-server.js.map +1 -1
- package/dist/gateway/gateway-service.d.ts.map +1 -1
- package/dist/gateway/gateway-service.js +58 -5
- package/dist/gateway/gateway-service.js.map +1 -1
- package/dist/gateway/gateway-types.d.ts +3 -1
- package/dist/gateway/gateway-types.d.ts.map +1 -1
- package/dist/gateway/gateway-types.js.map +1 -1
- package/dist/gateway/hatching-completion.d.ts +54 -0
- package/dist/gateway/hatching-completion.d.ts.map +1 -1
- package/dist/gateway/hatching-completion.js +266 -8
- package/dist/gateway/hatching-completion.js.map +1 -1
- package/dist/infra/tool-progress-parser.d.ts.map +1 -1
- package/dist/infra/tool-progress-parser.js +14 -2
- package/dist/infra/tool-progress-parser.js.map +1 -1
- package/dist/types/activity-trace.d.ts +13 -7
- package/dist/types/activity-trace.d.ts.map +1 -1
- package/dist/types/activity-trace.js +24 -6
- package/dist/types/activity-trace.js.map +1 -1
- package/dist/types/container.d.ts +8 -0
- package/dist/types/container.d.ts.map +1 -1
- package/dist/workspace.d.ts +16 -0
- package/dist/workspace.d.ts.map +1 -1
- package/dist/workspace.js +59 -5
- package/dist/workspace.js.map +1 -1
- package/docs/content/README.md +15 -0
- package/docs/content/channels/admin-console.md +4 -1
- package/docs/content/developer-guide/runtime.md +3 -0
- package/npm-shrinkwrap.json +5 -5
- package/package.json +1 -1
- package/console/dist/assets/chat-B4ykLwkT.js +0 -4
- package/console/dist/assets/index-DuxG8IST.css +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,52 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
## [0.27.2](https://github.com/HybridAIOne/hybridclaw/tree/v0.27.2) - 2026-07-06
|
|
6
|
+
|
|
7
|
+
### Fixed
|
|
8
|
+
|
|
9
|
+
- **Console PDF previews**: Console pages now allow `blob:` iframe sources in
|
|
10
|
+
the defensive Content Security Policy, so browser-backed PDF previews render
|
|
11
|
+
instead of being blocked by the `default-src 'self'` fallback. Gateway HTTP
|
|
12
|
+
server tests cover the `frame-src 'self' blob:` directive.
|
|
13
|
+
|
|
14
|
+
## [0.27.1](https://github.com/HybridAIOne/hybridclaw/tree/v0.27.1) - 2026-07-06
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- **Onboarding audit trail**: First-run `BOOTSTRAP.md` hatching now records
|
|
19
|
+
structured onboarding events for start/continue, quick prelude messages,
|
|
20
|
+
user replies, assistant messages, welcome mail, workspace file updates,
|
|
21
|
+
completion, and abort paths. The admin audit view recognizes `onboarding`
|
|
22
|
+
as a first-class event category so operators can search and filter the
|
|
23
|
+
hatching lifecycle directly.
|
|
24
|
+
- **Agent email e2e coverage**: Added an end-to-end agent email flow test and
|
|
25
|
+
expanded focused coverage around onboarding audits, chat activity traces,
|
|
26
|
+
tool progress parsing, mailbox polling, bootstrap autostart, and workspace
|
|
27
|
+
bootstrap behavior.
|
|
28
|
+
|
|
29
|
+
### Changed
|
|
30
|
+
|
|
31
|
+
- **Tool progress retention**: Container tool progress now preserves complete
|
|
32
|
+
progress output for chat activity traces while masking and capping retained
|
|
33
|
+
log previews so long or sensitive tool progress does not overwhelm the UI or
|
|
34
|
+
audit-adjacent surfaces.
|
|
35
|
+
|
|
36
|
+
### Fixed
|
|
37
|
+
|
|
38
|
+
- **Chat activity drafts**: Web chat preserves interim assistant drafts and
|
|
39
|
+
tool-turn activity while a run is active, renders live drafts without answer
|
|
40
|
+
bubbles, suppresses tool-call-only prose traces, collapses completed tool
|
|
41
|
+
turns into the activity trace, and keeps non-final assistant drafts out of
|
|
42
|
+
persisted chat history.
|
|
43
|
+
- **Email mailbox polling**: Mailbox status is refreshed before polling and
|
|
44
|
+
idle email searches are skipped, avoiding stale UID state and unnecessary
|
|
45
|
+
search work when there is no new mailbox activity.
|
|
46
|
+
- **Onboarding completion audits**: Hatching completion now survives agent
|
|
47
|
+
cleanup, terminal audit records are preserved on error paths, onboarding mail
|
|
48
|
+
and file-update events are captured, and lifecycle events are ordered so the
|
|
49
|
+
audit trail reads from start through completion or abort.
|
|
50
|
+
|
|
5
51
|
## [0.27.0](https://github.com/HybridAIOne/hybridclaw/tree/v0.27.0) - 2026-07-05
|
|
6
52
|
|
|
7
53
|
### Added
|
package/README.md
CHANGED
|
@@ -32,7 +32,9 @@ channels.
|
|
|
32
32
|
|
|
33
33
|
First-run onboarding is built around hatching: a new agent asks about the
|
|
34
34
|
user's work, records useful context, keeps setup links visible in chat, and can
|
|
35
|
-
send a tailored first-jobs welcome email when an email route is available.
|
|
35
|
+
send a tailored first-jobs welcome email when an email route is available. The
|
|
36
|
+
bootstrap lifecycle is recorded as structured onboarding audit events, including
|
|
37
|
+
messages, welcome mail, workspace file updates, completion, and abort paths.
|
|
36
38
|
|
|
37
39
|
Credentials stay outside the model context. Secrets live in the encrypted
|
|
38
40
|
runtime store and SecretRef-backed tools resolve them at execution time, so
|
|
@@ -55,7 +57,7 @@ HybridClaw on HybridAI Cloud in a few minutes at
|
|
|
55
57
|
|
|
56
58
|
| You need | HybridClaw gives you |
|
|
57
59
|
| --- | --- |
|
|
58
|
-
| A first run that becomes useful quickly | Guided hatching with setup links, tailored first-job suggestions, optional onboarding-specific model routing,
|
|
60
|
+
| A first run that becomes useful quickly | Guided hatching with setup links, tailored first-job suggestions, optional onboarding-specific model routing, welcome-email handoff, and structured audit events |
|
|
59
61
|
| Business workflows that survive real use | Production skill helpers with fixtures, eval scenarios, targeted tests, approval tiers, and a `Qwen/Qwen3.6-27B-FP8` validation baseline |
|
|
60
62
|
| Generated work artifacts you can reuse | An Apps gallery for self-contained HTML apps, dashboards, documents, games, tools, and live connector-backed views |
|
|
61
63
|
| Multi-agent workflows across installations | Local agents, hosted proxy agents, A2A trust, explicit addressing, inbound envelopes, and admin-visible peer pairing |
|
|
@@ -139,7 +141,7 @@ npm run desktop
|
|
|
139
141
|
- **Guided onboarding**: hatching collects useful work context, keeps setup
|
|
140
142
|
links handy, writes first-job suggestions, and can route the first-run
|
|
141
143
|
conversation through a stronger onboarding model before returning to the
|
|
142
|
-
normal default.
|
|
144
|
+
normal default. Its lifecycle is searchable in audit as onboarding events.
|
|
143
145
|
- **Multi-agent operations**: agents can coordinate across local workspaces,
|
|
144
146
|
hosted HybridAI proxies, and trusted peer HybridClaw instances with A2A
|
|
145
147
|
pairing, explicit addressing, inbound envelopes, and admin-visible trust.
|
|
@@ -160,7 +162,7 @@ npm run desktop
|
|
|
160
162
|
surface.
|
|
161
163
|
- **Operator visibility**: `/admin` covers channels, connectors, approvals,
|
|
162
164
|
audit, statistics, output guard, secrets, fleet topology, A2A inbox/trust,
|
|
163
|
-
and
|
|
165
|
+
distillation, and browser PDF previews without requiring shell access.
|
|
164
166
|
- **Business-ready extension model**: packaged skills, plugins, MCP servers,
|
|
165
167
|
and SecretRef-backed HTTP tools share the same approval and credential
|
|
166
168
|
boundaries.
|
|
@@ -234,7 +236,7 @@ Core pieces:
|
|
|
234
236
|
| Build desktop releases | [Desktop Release Builds](https://hybridaione.github.io/hybridclaw/docs/developer-guide/desktop-release) |
|
|
235
237
|
| Contribute | [CONTRIBUTING.md](./CONTRIBUTING.md), [docs/content/README.md](./docs/content/README.md) |
|
|
236
238
|
|
|
237
|
-
Latest release: [v0.27.
|
|
239
|
+
Latest release: [v0.27.2](https://github.com/HybridAIOne/hybridclaw/releases/tag/v0.27.2).
|
|
238
240
|
Release notes: [CHANGELOG.md](./CHANGELOG.md)
|
|
239
241
|
|
|
240
242
|
## Development
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{n as e}from"./rolldown-runtime-Bh1tDfsg.js";import{C as t,a as n,n as r,o as i,r as a}from"./query-o_Dd9s85.js";import{l as o}from"./router-DoNPHesn.js";import{D as s,H as c,J as l,L as u,O as d,T as f,X as p,Y as m,at as h,ct as g,et as _,ft as v,ht as y,it as b,j as x,k as S,mt as C,nt as w,ot as T,pt as E,q as D,r as O,rt as k,tt as A,vt as j}from"./index-Btzl6jZZ.js";import{C as M,S as ee,_ as N,b as P,i as F,m as I,n as L,r as R,t as z,v as te,w as ne,x as B}from"./chat-sidebar-bGb6YbfM.js";var V=e(t(),1),H={scroll:`_scroll_in2v6_1`,page:`_page_in2v6_7`,topbar:`_topbar_in2v6_18`,topbarLeft:`_topbarLeft_in2v6_25`,mobileTrigger:`_mobileTrigger_in2v6_31`,title:`_title_in2v6_35`,toolbar:`_toolbar_in2v6_43`,searchWrap:`_searchWrap_in2v6_49`,searchIcon:`_searchIcon_in2v6_56`,searchInput:`_searchInput_in2v6_65`,filterTrigger:`_filterTrigger_in2v6_82`,newAppTrigger:`_newAppTrigger_in2v6_101`,newAppItem:`_newAppItem_in2v6_120`,newAppItemTitle:`_newAppItemTitle_in2v6_127`,newAppItemHint:`_newAppItemHint_in2v6_133`,grid:`_grid_in2v6_138`,card:`_card_in2v6_147`,cardMain:`_cardMain_in2v6_162`,cardTop:`_cardTop_in2v6_176`,cardGlyph:`_cardGlyph_in2v6_183`,kindBadge:`_kindBadge_in2v6_194`,kindBadgeLive:`_kindBadgeLive_in2v6_195`,cardActions:`_cardActions_in2v6_213`,cardAction:`_cardAction_in2v6_213`,cardActionIcon:`_cardActionIcon_in2v6_246`,inlineIcon:`_inlineIcon_in2v6_251`,cardBody:`_cardBody_in2v6_262`,cardTitle:`_cardTitle_in2v6_269`,cardDesc:`_cardDesc_in2v6_276`,cardMeta:`_cardMeta_in2v6_287`,cardCategory:`_cardCategory_in2v6_296`,cardDot:`_cardDot_in2v6_301`,cardDelete:`_cardDelete_in2v6_305`,cardDeleteIcon:`_cardDeleteIcon_in2v6_333`,buildingBanner:`_buildingBanner_in2v6_338`,buildingSpinner:`_buildingSpinner_in2v6_350`,appsSpin:`_appsSpin_in2v6_1`,empty:`_empty_in2v6_367`,emptyGlyph:`_emptyGlyph_in2v6_379`,emptyTitle:`_emptyTitle_in2v6_395`,emptyText:`_emptyText_in2v6_402`,newDialog:`_newDialog_in2v6_410`,categoryGrid:`_categoryGrid_in2v6_415`,categoryTile:`_categoryTile_in2v6_422`,categoryGlyph:`_categoryGlyph_in2v6_443`,dialogTitleIcon:`_dialogTitleIcon_in2v6_459`,examples:`_examples_in2v6_475`,examplesLabel:`_examplesLabel_in2v6_482`,exampleChips:`_exampleChips_in2v6_490`,exampleChip:`_exampleChip_in2v6_490`,categoryLabel:`_categoryLabel_in2v6_519`,categoryHint:`_categoryHint_in2v6_525`,promptInput:`_promptInput_in2v6_531`,secondaryButton:`_secondaryButton_in2v6_552`,viewerDialog:`_viewerDialog_in2v6_578`,viewerHeader:`_viewerHeader_in2v6_588`,viewerTitle:`_viewerTitle_in2v6_600`,viewerActions:`_viewerActions_in2v6_609`,viewerFrame:`_viewerFrame_in2v6_618`},U=i();function re(){let e=y(),t=s(),i=o(),c=n(),l=(0,V.useRef)(f()).current,[u,p]=(0,V.useState)(``),[m,g]=(0,V.useState)(`user`),[v,S]=(0,V.useState)(null),E=u.trim(),D=a({queryKey:[`apps-chat-recent`,e.token,l,E,m],queryFn:()=>I(e.token,l,`web`,E?F.maxSearchResults:F.maxRecentSessions,E||void 0,m),staleTime:1e4,enabled:C(e)}),O=r({mutationFn:t=>j(e.token,t),onSuccess:async()=>{S(null),await c.invalidateQueries({queryKey:[`apps-chat-recent`]}),t.success(`Conversation deleted.`)},onError:e=>{t.error(`Delete failed: ${x(e)}`)}});return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(z,{sessions:D.data?.sessions??[],activeSessionId:``,onNewChat:()=>i({to:`/chat`}),onOpenSession:e=>i({to:`/chat/$sessionId`,params:{sessionId:e}}),onRequestDeleteSession:e=>S(e),deleteDisabled:O.isPending,searchQuery:u,onSearchQueryChange:p,recentScope:m,onRecentScopeChange:g,isLoading:D.isFetching,onRefreshRecent:()=>{D.refetch()}}),(0,U.jsx)(_,{open:v!==null,onOpenChange:e=>{e||S(null)},children:(0,U.jsxs)(w,{size:`sm`,role:`alertdialog`,children:[(0,U.jsxs)(h,{children:[(0,U.jsx)(T,{children:`Delete conversation?`}),(0,U.jsxs)(k,{children:[`“`,v?.title||`Untitled`,`” will be permanently removed.`]})]}),(0,U.jsxs)(b,{children:[(0,U.jsx)(A,{children:`Cancel`}),(0,U.jsx)(d,{variant:`danger`,disabled:O.isPending,onClick:()=>v&&O.mutate(v.sessionId),children:O.isPending?`Deleting…`:`Delete`})]})]})})]})}var W=[{slug:`apps`,label:`Apps & websites`,hint:`Internal tools, portals, landing pages`,seedNoun:`web app or website`,examples:[`A client onboarding portal with step-by-step progress`,`A SaaS pricing page with a monthly/annual toggle`,`An internal team directory with search`]},{slug:`documents`,label:`Documents & templates`,hint:`Proposals, reports, printable templates`,seedNoun:`document or template`,examples:[`A consulting invoice with line items and totals`,`A quarterly business review one-pager`,`A statement-of-work proposal template`]},{slug:`games`,label:`Games`,hint:`Playable browser games`,seedNoun:`browser game`,examples:[`A product-knowledge quiz game for new hires`,`A typing-speed trainer`,`A memory match game`]},{slug:`productivity`,label:`Productivity tools`,hint:`Calculators, trackers, dashboards`,seedNoun:`productivity tool`,examples:[`A SaaS MRR and churn dashboard`,`A meeting-cost calculator`,`A project ROI calculator`]},{slug:`creative`,label:`Creative projects`,hint:`Brand assets, mockups, visuals`,seedNoun:`creative project`,examples:[`A branded social media post mockup`,`A pitch-deck cover slide`,`A simple drawing canvas`]},{slug:`quiz`,label:`Quiz or survey`,hint:`Lead capture, feedback, assessments`,seedNoun:`quiz or survey`,examples:[`A lead-qualification survey with scoring`,`An employee eNPS survey`,`A customer CSAT form`]},{slug:`scratch`,label:`Start from scratch`,hint:`Describe anything you can imagine`,seedNoun:null,examples:[]}],G=new Map(W.map(e=>[e.slug,e]));function K(e){return G.get(e)?.label??`App`}function q(){let{token:e}=y(),t=s(),i=o(),f=n(),[g,S]=(0,V.useState)(``),[C,j]=(0,V.useState)(`all`),[P,F]=(0,V.useState)(null),[I,L]=(0,V.useState)(null),[R,z]=(0,V.useState)(0),[B,q]=(0,V.useState)(null),J=(0,V.useRef)(null),Y=a({queryKey:[`apps`,e],queryFn:()=>ne(e),retry:!1});function ce(e,t){let n=G.get(e)?.seedNoun??null;F(null),i({to:`/chat`,search:{prompt:N(n,t),send:`1`,app:`1`,kind:`web`,...e===`scratch`?{}:{category:e}}})}function le(e){F(null),i({to:`/chat`,search:{prompt:te(e),send:`1`,app:`1`,kind:`live`}})}async function X(n){if(n.kind!==`live`){t.error(`Only live apps can refresh connector data.`);return}if(!(I?.id===n.id&&J.current?.refreshData()))try{L((await M(e,n.id)).app),z(e=>e+1)}catch(e){t.error(`Could not refresh app: ${x(e)}`)}}let Z=r({mutationFn:t=>ee(e,t),onSuccess:async(e,n)=>{await f.invalidateQueries({queryKey:[`apps`]}),I?.id===n&&L(null),q(null),t.success(`App deleted.`)},onError:e=>{t.error(`Delete failed: ${x(e)}`)}}),Q=Y.data?.apps??[],$=(0,V.useMemo)(()=>{let e=g.trim().toLowerCase();return Q.filter(t=>C!==`all`&&t.category!==C?!1:e?t.title.toLowerCase().includes(e)||(t.description??``).toLowerCase().includes(e):!0)},[Q,g,C]);async function ue(n){try{L((await M(e,n.id)).app)}catch(e){t.error(`Could not open app: ${x(e)}`)}}let de=C===`all`?`All`:K(C);return(0,U.jsxs)(c,{children:[(0,U.jsxs)(`div`,{className:O.chatPage,children:[(0,U.jsx)(re,{}),(0,U.jsx)(`div`,{className:O.chatMain,children:(0,U.jsx)(`div`,{className:H.scroll,children:(0,U.jsxs)(`div`,{className:H.page,children:[(0,U.jsxs)(`header`,{className:H.topbar,children:[(0,U.jsxs)(`div`,{className:H.topbarLeft,children:[(0,U.jsx)(u,{className:H.mobileTrigger}),(0,U.jsx)(`h1`,{className:H.title,children:`Apps`})]}),(0,U.jsxs)(D,{children:[(0,U.jsxs)(p,{className:H.newAppTrigger,children:[`+ New app`,(0,U.jsx)(E,{"aria-hidden":`true`})]}),(0,U.jsxs)(l,{align:`end`,children:[(0,U.jsx)(m,{onSelect:()=>F(`web`),children:(0,U.jsxs)(`span`,{className:H.newAppItem,children:[(0,U.jsx)(`span`,{className:H.newAppItemTitle,children:`Web app`}),(0,U.jsx)(`span`,{className:H.newAppItemHint,children:`Self-contained app, document, game, or tool`})]})}),(0,U.jsx)(m,{onSelect:()=>F(`live`),children:(0,U.jsxs)(`span`,{className:H.newAppItem,children:[(0,U.jsx)(`span`,{className:H.newAppItemTitle,children:`Live app`}),(0,U.jsx)(`span`,{className:H.newAppItemHint,children:`Uses your connectors and can be refreshed`})]})})]})]})]}),(0,U.jsxs)(`div`,{className:H.toolbar,children:[(0,U.jsxs)(`div`,{className:H.searchWrap,children:[(0,U.jsx)(v,{className:H.searchIcon,"aria-hidden":`true`}),(0,U.jsx)(`input`,{type:`search`,className:H.searchInput,placeholder:`Search apps…`,value:g,onChange:e=>S(e.target.value),"aria-label":`Search apps`})]}),(0,U.jsxs)(D,{children:[(0,U.jsxs)(p,{className:H.filterTrigger,children:[(0,U.jsxs)(`span`,{children:[`Filter: `,(0,U.jsx)(`strong`,{children:de})]}),(0,U.jsx)(E,{"aria-hidden":`true`})]}),(0,U.jsxs)(l,{align:`end`,children:[(0,U.jsx)(m,{active:C===`all`,onSelect:()=>j(`all`),children:`All`}),W.map(e=>(0,U.jsx)(m,{active:C===e.slug,onSelect:()=>j(e.slug),children:e.label},e.slug))]})]})]}),Y.isPending?(0,U.jsx)(`div`,{className:`empty-state`,children:`Loading apps…`}):Y.isError?(0,U.jsxs)(`div`,{className:`empty-state`,children:[`Failed to load apps: `,x(Y.error)]}):$.length===0?(0,U.jsx)(ie,{hasApps:Q.length>0,onCreate:()=>F(`web`)}):(0,U.jsx)(`ul`,{className:H.grid,children:$.map(e=>(0,U.jsx)(`li`,{children:(0,U.jsx)(ae,{app:e,onOpen:()=>ue(e),onDelete:()=>q(e),onRefresh:()=>X(e)})},e.id))})]})})})]}),(0,U.jsx)(oe,{kind:P,onClose:()=>F(null),onStartWeb:ce,onStartLive:le}),(0,U.jsx)(se,{app:I,token:e,onClose:()=>L(null),frameRef:J,refreshNonce:R,onRefresh:I?()=>X(I):void 0}),(0,U.jsx)(_,{open:B!==null,onOpenChange:e=>{e||q(null)},children:(0,U.jsxs)(w,{size:`sm`,role:`alertdialog`,children:[(0,U.jsxs)(h,{children:[(0,U.jsx)(T,{children:`Delete app?`}),(0,U.jsxs)(k,{children:[`“`,B?.title,`” will be permanently removed from the gallery.`]})]}),(0,U.jsxs)(b,{children:[(0,U.jsx)(A,{className:H.secondaryButton,children:`Cancel`}),(0,U.jsx)(d,{variant:`danger`,disabled:Z.isPending,onClick:()=>B&&Z.mutate(B.id),children:Z.isPending?`Deleting…`:`Delete`})]})]})})]})}function ie(e){return(0,U.jsxs)(`div`,{className:H.empty,children:[(0,U.jsx)(`div`,{className:H.emptyGlyph,"aria-hidden":`true`,children:(0,U.jsx)(L,{category:`scratch`})}),(0,U.jsx)(`h2`,{className:H.emptyTitle,children:e.hasApps?`No matching apps`:`No apps yet`}),(0,U.jsx)(`p`,{className:H.emptyText,children:e.hasApps?`Try a different search or filter.`:`Describe an app, document, tool, or report and HybridClaw builds it for you.`}),e.hasApps?null:(0,U.jsx)(d,{onClick:e.onCreate,children:`+ New app`})]})}function ae(e){let{app:t}=e,n=t.kind===`live`;return(0,U.jsxs)(`div`,{className:H.card,children:[(0,U.jsxs)(`button`,{type:`button`,className:H.cardMain,onClick:e.onOpen,children:[(0,U.jsxs)(`div`,{className:H.cardTop,children:[(0,U.jsx)(`div`,{className:H.cardGlyph,"aria-hidden":`true`,children:(0,U.jsx)(L,{category:t.category})}),(0,U.jsx)(`span`,{className:n?H.kindBadgeLive:H.kindBadge,title:n?`Connector-aware, refreshable`:void 0,children:n?`Live`:`Web`})]}),(0,U.jsxs)(`div`,{className:H.cardBody,children:[(0,U.jsx)(`span`,{className:H.cardTitle,children:t.title}),t.description?(0,U.jsx)(`span`,{className:H.cardDesc,children:t.description}):null]}),(0,U.jsxs)(`div`,{className:H.cardMeta,children:[(0,U.jsx)(`span`,{className:H.cardCategory,children:K(t.category)}),(0,U.jsx)(`span`,{className:H.cardDot,children:`·`}),(0,U.jsx)(`span`,{children:S(t.createdAt)}),(0,U.jsx)(`span`,{className:H.cardDot,children:`·`}),(0,U.jsx)(`span`,{children:t.visibility===`public`?`Public`:`Private`})]})]}),(0,U.jsxs)(`div`,{className:H.cardActions,children:[n?(0,U.jsx)(`button`,{type:`button`,className:H.cardAction,"aria-label":`Refresh ${t.title}`,title:`Refresh with latest data`,onClick:e.onRefresh,children:(0,U.jsx)(R,{className:H.cardActionIcon})}):null,(0,U.jsx)(`button`,{type:`button`,className:H.cardAction,"aria-label":`Delete ${t.title}`,title:`Delete`,onClick:e.onDelete,children:(0,U.jsx)(g,{className:H.cardActionIcon})})]})]})}function oe(e){let[t,n]=(0,V.useState)(null),[r,i]=(0,V.useState)(``),a=e.kind!==null;(0,V.useEffect)(()=>{a&&(n(null),i(``))},[a,e.kind]);let o=t?G.get(t):void 0,s=e.kind===`web`&&t===null;return(0,U.jsx)(_,{open:a,onOpenChange:t=>{t||e.onClose()},children:(0,U.jsx)(w,{className:H.newDialog,children:s?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(h,{children:[(0,U.jsx)(T,{children:`Create a web app`}),(0,U.jsx)(k,{children:`Pick a category to get started, or start from scratch with your own idea.`})]}),(0,U.jsx)(`div`,{className:H.categoryGrid,children:W.map(e=>(0,U.jsxs)(`button`,{type:`button`,className:H.categoryTile,onClick:()=>n(e.slug),children:[(0,U.jsx)(`span`,{className:H.categoryGlyph,"aria-hidden":`true`,children:(0,U.jsx)(L,{category:e.slug})}),(0,U.jsx)(`span`,{className:H.categoryLabel,children:e.label}),(0,U.jsx)(`span`,{className:H.categoryHint,children:e.hint})]},e.slug))})]}):e.kind===`live`?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(h,{children:[(0,U.jsx)(T,{children:`Create a live app`}),(0,U.jsx)(k,{children:`HybridClaw checks your connected tools (MCP), suggests apps that use them, then builds one you can refresh. Add a starting idea (optional).`})]}),(0,U.jsx)(`textarea`,{className:H.promptInput,value:r,autoFocus:!0,placeholder:`e.g. A dashboard of my upcoming meetings and unread priority emails`,onChange:e=>i(e.target.value),rows:4}),(0,U.jsxs)(b,{children:[(0,U.jsx)(`button`,{type:`button`,className:H.secondaryButton,onClick:e.onClose,children:`Cancel`}),(0,U.jsx)(d,{onClick:()=>e.onStartLive(r.trim()),children:`Start building →`})]})]}):t?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(h,{children:[(0,U.jsxs)(T,{children:[(0,U.jsx)(`span`,{className:H.dialogTitleIcon,"aria-hidden":`true`,children:(0,U.jsx)(L,{category:t})}),o?.label]}),(0,U.jsx)(k,{children:`Add a starting idea (optional). HybridClaw opens a chat, asks a few questions, then builds it for you.`})]}),(0,U.jsx)(`textarea`,{className:H.promptInput,value:r,autoFocus:!0,placeholder:`e.g. A client onboarding portal that tracks setup steps and shows progress`,onChange:e=>i(e.target.value),rows:4}),o&&o.examples.length>0?(0,U.jsxs)(`div`,{className:H.examples,children:[(0,U.jsx)(`span`,{className:H.examplesLabel,children:`Examples`}),(0,U.jsx)(`div`,{className:H.exampleChips,children:o.examples.map(e=>(0,U.jsx)(`button`,{type:`button`,className:H.exampleChip,onClick:()=>i(e),children:e},e))})]}):null,(0,U.jsxs)(b,{children:[(0,U.jsx)(`button`,{type:`button`,className:H.secondaryButton,onClick:()=>n(null),children:`← Back`}),(0,U.jsx)(d,{onClick:()=>e.onStartWeb(t,r.trim()),children:`Start building →`})]})]}):null})})}function se(e){let{app:t}=e;return(0,U.jsx)(_,{open:t!==null,onOpenChange:t=>{t||e.onClose()},children:(0,U.jsxs)(w,{className:H.viewerDialog,"aria-label":`App preview`,children:[(0,U.jsxs)(`div`,{className:H.viewerHeader,children:[(0,U.jsx)(T,{className:H.viewerTitle,children:t?.title}),(0,U.jsxs)(`div`,{className:H.viewerActions,children:[t&&t.kind===`live`&&e.onRefresh?(0,U.jsxs)(`button`,{type:`button`,className:H.secondaryButton,onClick:t=>{t.stopPropagation(),e.onRefresh?.()},children:[(0,U.jsx)(R,{className:H.inlineIcon}),` Refresh`]}):null,t?(0,U.jsx)(`a`,{className:H.secondaryButton,href:B(t.id,e.token),target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),children:`Open in new tab ↗`}):null,(0,U.jsx)(A,{className:H.secondaryButton,onClick:e=>e.stopPropagation(),children:`Close`})]})]}),t?(0,U.jsx)(P,{ref:e.frameRef,appId:t.id,className:H.viewerFrame,refreshNonce:e.refreshNonce,title:t.title,token:e.token}):null]})})}export{q as AppsPage};
|
|
1
|
+
import{n as e}from"./rolldown-runtime-Bh1tDfsg.js";import{C as t,a as n,n as r,o as i,r as a}from"./query-o_Dd9s85.js";import{l as o}from"./router-DoNPHesn.js";import{D as s,H as c,J as l,L as u,O as d,T as f,X as p,Y as m,at as h,ct as g,et as _,ft as v,ht as y,it as b,j as x,k as S,mt as C,nt as w,ot as T,pt as E,q as D,r as O,rt as k,tt as A,vt as j}from"./index-B7ZQvYLH.js";import{C as M,S as ee,_ as N,b as P,i as F,m as I,n as L,r as R,t as z,v as te,w as ne,x as B}from"./chat-sidebar-ZV6o-A2S.js";var V=e(t(),1),H={scroll:`_scroll_in2v6_1`,page:`_page_in2v6_7`,topbar:`_topbar_in2v6_18`,topbarLeft:`_topbarLeft_in2v6_25`,mobileTrigger:`_mobileTrigger_in2v6_31`,title:`_title_in2v6_35`,toolbar:`_toolbar_in2v6_43`,searchWrap:`_searchWrap_in2v6_49`,searchIcon:`_searchIcon_in2v6_56`,searchInput:`_searchInput_in2v6_65`,filterTrigger:`_filterTrigger_in2v6_82`,newAppTrigger:`_newAppTrigger_in2v6_101`,newAppItem:`_newAppItem_in2v6_120`,newAppItemTitle:`_newAppItemTitle_in2v6_127`,newAppItemHint:`_newAppItemHint_in2v6_133`,grid:`_grid_in2v6_138`,card:`_card_in2v6_147`,cardMain:`_cardMain_in2v6_162`,cardTop:`_cardTop_in2v6_176`,cardGlyph:`_cardGlyph_in2v6_183`,kindBadge:`_kindBadge_in2v6_194`,kindBadgeLive:`_kindBadgeLive_in2v6_195`,cardActions:`_cardActions_in2v6_213`,cardAction:`_cardAction_in2v6_213`,cardActionIcon:`_cardActionIcon_in2v6_246`,inlineIcon:`_inlineIcon_in2v6_251`,cardBody:`_cardBody_in2v6_262`,cardTitle:`_cardTitle_in2v6_269`,cardDesc:`_cardDesc_in2v6_276`,cardMeta:`_cardMeta_in2v6_287`,cardCategory:`_cardCategory_in2v6_296`,cardDot:`_cardDot_in2v6_301`,cardDelete:`_cardDelete_in2v6_305`,cardDeleteIcon:`_cardDeleteIcon_in2v6_333`,buildingBanner:`_buildingBanner_in2v6_338`,buildingSpinner:`_buildingSpinner_in2v6_350`,appsSpin:`_appsSpin_in2v6_1`,empty:`_empty_in2v6_367`,emptyGlyph:`_emptyGlyph_in2v6_379`,emptyTitle:`_emptyTitle_in2v6_395`,emptyText:`_emptyText_in2v6_402`,newDialog:`_newDialog_in2v6_410`,categoryGrid:`_categoryGrid_in2v6_415`,categoryTile:`_categoryTile_in2v6_422`,categoryGlyph:`_categoryGlyph_in2v6_443`,dialogTitleIcon:`_dialogTitleIcon_in2v6_459`,examples:`_examples_in2v6_475`,examplesLabel:`_examplesLabel_in2v6_482`,exampleChips:`_exampleChips_in2v6_490`,exampleChip:`_exampleChip_in2v6_490`,categoryLabel:`_categoryLabel_in2v6_519`,categoryHint:`_categoryHint_in2v6_525`,promptInput:`_promptInput_in2v6_531`,secondaryButton:`_secondaryButton_in2v6_552`,viewerDialog:`_viewerDialog_in2v6_578`,viewerHeader:`_viewerHeader_in2v6_588`,viewerTitle:`_viewerTitle_in2v6_600`,viewerActions:`_viewerActions_in2v6_609`,viewerFrame:`_viewerFrame_in2v6_618`},U=i();function re(){let e=y(),t=s(),i=o(),c=n(),l=(0,V.useRef)(f()).current,[u,p]=(0,V.useState)(``),[m,g]=(0,V.useState)(`user`),[v,S]=(0,V.useState)(null),E=u.trim(),D=a({queryKey:[`apps-chat-recent`,e.token,l,E,m],queryFn:()=>I(e.token,l,`web`,E?F.maxSearchResults:F.maxRecentSessions,E||void 0,m),staleTime:1e4,enabled:C(e)}),O=r({mutationFn:t=>j(e.token,t),onSuccess:async()=>{S(null),await c.invalidateQueries({queryKey:[`apps-chat-recent`]}),t.success(`Conversation deleted.`)},onError:e=>{t.error(`Delete failed: ${x(e)}`)}});return(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)(z,{sessions:D.data?.sessions??[],activeSessionId:``,onNewChat:()=>i({to:`/chat`}),onOpenSession:e=>i({to:`/chat/$sessionId`,params:{sessionId:e}}),onRequestDeleteSession:e=>S(e),deleteDisabled:O.isPending,searchQuery:u,onSearchQueryChange:p,recentScope:m,onRecentScopeChange:g,isLoading:D.isFetching,onRefreshRecent:()=>{D.refetch()}}),(0,U.jsx)(_,{open:v!==null,onOpenChange:e=>{e||S(null)},children:(0,U.jsxs)(w,{size:`sm`,role:`alertdialog`,children:[(0,U.jsxs)(h,{children:[(0,U.jsx)(T,{children:`Delete conversation?`}),(0,U.jsxs)(k,{children:[`“`,v?.title||`Untitled`,`” will be permanently removed.`]})]}),(0,U.jsxs)(b,{children:[(0,U.jsx)(A,{children:`Cancel`}),(0,U.jsx)(d,{variant:`danger`,disabled:O.isPending,onClick:()=>v&&O.mutate(v.sessionId),children:O.isPending?`Deleting…`:`Delete`})]})]})})]})}var W=[{slug:`apps`,label:`Apps & websites`,hint:`Internal tools, portals, landing pages`,seedNoun:`web app or website`,examples:[`A client onboarding portal with step-by-step progress`,`A SaaS pricing page with a monthly/annual toggle`,`An internal team directory with search`]},{slug:`documents`,label:`Documents & templates`,hint:`Proposals, reports, printable templates`,seedNoun:`document or template`,examples:[`A consulting invoice with line items and totals`,`A quarterly business review one-pager`,`A statement-of-work proposal template`]},{slug:`games`,label:`Games`,hint:`Playable browser games`,seedNoun:`browser game`,examples:[`A product-knowledge quiz game for new hires`,`A typing-speed trainer`,`A memory match game`]},{slug:`productivity`,label:`Productivity tools`,hint:`Calculators, trackers, dashboards`,seedNoun:`productivity tool`,examples:[`A SaaS MRR and churn dashboard`,`A meeting-cost calculator`,`A project ROI calculator`]},{slug:`creative`,label:`Creative projects`,hint:`Brand assets, mockups, visuals`,seedNoun:`creative project`,examples:[`A branded social media post mockup`,`A pitch-deck cover slide`,`A simple drawing canvas`]},{slug:`quiz`,label:`Quiz or survey`,hint:`Lead capture, feedback, assessments`,seedNoun:`quiz or survey`,examples:[`A lead-qualification survey with scoring`,`An employee eNPS survey`,`A customer CSAT form`]},{slug:`scratch`,label:`Start from scratch`,hint:`Describe anything you can imagine`,seedNoun:null,examples:[]}],G=new Map(W.map(e=>[e.slug,e]));function K(e){return G.get(e)?.label??`App`}function q(){let{token:e}=y(),t=s(),i=o(),f=n(),[g,S]=(0,V.useState)(``),[C,j]=(0,V.useState)(`all`),[P,F]=(0,V.useState)(null),[I,L]=(0,V.useState)(null),[R,z]=(0,V.useState)(0),[B,q]=(0,V.useState)(null),J=(0,V.useRef)(null),Y=a({queryKey:[`apps`,e],queryFn:()=>ne(e),retry:!1});function ce(e,t){let n=G.get(e)?.seedNoun??null;F(null),i({to:`/chat`,search:{prompt:N(n,t),send:`1`,app:`1`,kind:`web`,...e===`scratch`?{}:{category:e}}})}function le(e){F(null),i({to:`/chat`,search:{prompt:te(e),send:`1`,app:`1`,kind:`live`}})}async function X(n){if(n.kind!==`live`){t.error(`Only live apps can refresh connector data.`);return}if(!(I?.id===n.id&&J.current?.refreshData()))try{L((await M(e,n.id)).app),z(e=>e+1)}catch(e){t.error(`Could not refresh app: ${x(e)}`)}}let Z=r({mutationFn:t=>ee(e,t),onSuccess:async(e,n)=>{await f.invalidateQueries({queryKey:[`apps`]}),I?.id===n&&L(null),q(null),t.success(`App deleted.`)},onError:e=>{t.error(`Delete failed: ${x(e)}`)}}),Q=Y.data?.apps??[],$=(0,V.useMemo)(()=>{let e=g.trim().toLowerCase();return Q.filter(t=>C!==`all`&&t.category!==C?!1:e?t.title.toLowerCase().includes(e)||(t.description??``).toLowerCase().includes(e):!0)},[Q,g,C]);async function ue(n){try{L((await M(e,n.id)).app)}catch(e){t.error(`Could not open app: ${x(e)}`)}}let de=C===`all`?`All`:K(C);return(0,U.jsxs)(c,{children:[(0,U.jsxs)(`div`,{className:O.chatPage,children:[(0,U.jsx)(re,{}),(0,U.jsx)(`div`,{className:O.chatMain,children:(0,U.jsx)(`div`,{className:H.scroll,children:(0,U.jsxs)(`div`,{className:H.page,children:[(0,U.jsxs)(`header`,{className:H.topbar,children:[(0,U.jsxs)(`div`,{className:H.topbarLeft,children:[(0,U.jsx)(u,{className:H.mobileTrigger}),(0,U.jsx)(`h1`,{className:H.title,children:`Apps`})]}),(0,U.jsxs)(D,{children:[(0,U.jsxs)(p,{className:H.newAppTrigger,children:[`+ New app`,(0,U.jsx)(E,{"aria-hidden":`true`})]}),(0,U.jsxs)(l,{align:`end`,children:[(0,U.jsx)(m,{onSelect:()=>F(`web`),children:(0,U.jsxs)(`span`,{className:H.newAppItem,children:[(0,U.jsx)(`span`,{className:H.newAppItemTitle,children:`Web app`}),(0,U.jsx)(`span`,{className:H.newAppItemHint,children:`Self-contained app, document, game, or tool`})]})}),(0,U.jsx)(m,{onSelect:()=>F(`live`),children:(0,U.jsxs)(`span`,{className:H.newAppItem,children:[(0,U.jsx)(`span`,{className:H.newAppItemTitle,children:`Live app`}),(0,U.jsx)(`span`,{className:H.newAppItemHint,children:`Uses your connectors and can be refreshed`})]})})]})]})]}),(0,U.jsxs)(`div`,{className:H.toolbar,children:[(0,U.jsxs)(`div`,{className:H.searchWrap,children:[(0,U.jsx)(v,{className:H.searchIcon,"aria-hidden":`true`}),(0,U.jsx)(`input`,{type:`search`,className:H.searchInput,placeholder:`Search apps…`,value:g,onChange:e=>S(e.target.value),"aria-label":`Search apps`})]}),(0,U.jsxs)(D,{children:[(0,U.jsxs)(p,{className:H.filterTrigger,children:[(0,U.jsxs)(`span`,{children:[`Filter: `,(0,U.jsx)(`strong`,{children:de})]}),(0,U.jsx)(E,{"aria-hidden":`true`})]}),(0,U.jsxs)(l,{align:`end`,children:[(0,U.jsx)(m,{active:C===`all`,onSelect:()=>j(`all`),children:`All`}),W.map(e=>(0,U.jsx)(m,{active:C===e.slug,onSelect:()=>j(e.slug),children:e.label},e.slug))]})]})]}),Y.isPending?(0,U.jsx)(`div`,{className:`empty-state`,children:`Loading apps…`}):Y.isError?(0,U.jsxs)(`div`,{className:`empty-state`,children:[`Failed to load apps: `,x(Y.error)]}):$.length===0?(0,U.jsx)(ie,{hasApps:Q.length>0,onCreate:()=>F(`web`)}):(0,U.jsx)(`ul`,{className:H.grid,children:$.map(e=>(0,U.jsx)(`li`,{children:(0,U.jsx)(ae,{app:e,onOpen:()=>ue(e),onDelete:()=>q(e),onRefresh:()=>X(e)})},e.id))})]})})})]}),(0,U.jsx)(oe,{kind:P,onClose:()=>F(null),onStartWeb:ce,onStartLive:le}),(0,U.jsx)(se,{app:I,token:e,onClose:()=>L(null),frameRef:J,refreshNonce:R,onRefresh:I?()=>X(I):void 0}),(0,U.jsx)(_,{open:B!==null,onOpenChange:e=>{e||q(null)},children:(0,U.jsxs)(w,{size:`sm`,role:`alertdialog`,children:[(0,U.jsxs)(h,{children:[(0,U.jsx)(T,{children:`Delete app?`}),(0,U.jsxs)(k,{children:[`“`,B?.title,`” will be permanently removed from the gallery.`]})]}),(0,U.jsxs)(b,{children:[(0,U.jsx)(A,{className:H.secondaryButton,children:`Cancel`}),(0,U.jsx)(d,{variant:`danger`,disabled:Z.isPending,onClick:()=>B&&Z.mutate(B.id),children:Z.isPending?`Deleting…`:`Delete`})]})]})})]})}function ie(e){return(0,U.jsxs)(`div`,{className:H.empty,children:[(0,U.jsx)(`div`,{className:H.emptyGlyph,"aria-hidden":`true`,children:(0,U.jsx)(L,{category:`scratch`})}),(0,U.jsx)(`h2`,{className:H.emptyTitle,children:e.hasApps?`No matching apps`:`No apps yet`}),(0,U.jsx)(`p`,{className:H.emptyText,children:e.hasApps?`Try a different search or filter.`:`Describe an app, document, tool, or report and HybridClaw builds it for you.`}),e.hasApps?null:(0,U.jsx)(d,{onClick:e.onCreate,children:`+ New app`})]})}function ae(e){let{app:t}=e,n=t.kind===`live`;return(0,U.jsxs)(`div`,{className:H.card,children:[(0,U.jsxs)(`button`,{type:`button`,className:H.cardMain,onClick:e.onOpen,children:[(0,U.jsxs)(`div`,{className:H.cardTop,children:[(0,U.jsx)(`div`,{className:H.cardGlyph,"aria-hidden":`true`,children:(0,U.jsx)(L,{category:t.category})}),(0,U.jsx)(`span`,{className:n?H.kindBadgeLive:H.kindBadge,title:n?`Connector-aware, refreshable`:void 0,children:n?`Live`:`Web`})]}),(0,U.jsxs)(`div`,{className:H.cardBody,children:[(0,U.jsx)(`span`,{className:H.cardTitle,children:t.title}),t.description?(0,U.jsx)(`span`,{className:H.cardDesc,children:t.description}):null]}),(0,U.jsxs)(`div`,{className:H.cardMeta,children:[(0,U.jsx)(`span`,{className:H.cardCategory,children:K(t.category)}),(0,U.jsx)(`span`,{className:H.cardDot,children:`·`}),(0,U.jsx)(`span`,{children:S(t.createdAt)}),(0,U.jsx)(`span`,{className:H.cardDot,children:`·`}),(0,U.jsx)(`span`,{children:t.visibility===`public`?`Public`:`Private`})]})]}),(0,U.jsxs)(`div`,{className:H.cardActions,children:[n?(0,U.jsx)(`button`,{type:`button`,className:H.cardAction,"aria-label":`Refresh ${t.title}`,title:`Refresh with latest data`,onClick:e.onRefresh,children:(0,U.jsx)(R,{className:H.cardActionIcon})}):null,(0,U.jsx)(`button`,{type:`button`,className:H.cardAction,"aria-label":`Delete ${t.title}`,title:`Delete`,onClick:e.onDelete,children:(0,U.jsx)(g,{className:H.cardActionIcon})})]})]})}function oe(e){let[t,n]=(0,V.useState)(null),[r,i]=(0,V.useState)(``),a=e.kind!==null;(0,V.useEffect)(()=>{a&&(n(null),i(``))},[a,e.kind]);let o=t?G.get(t):void 0,s=e.kind===`web`&&t===null;return(0,U.jsx)(_,{open:a,onOpenChange:t=>{t||e.onClose()},children:(0,U.jsx)(w,{className:H.newDialog,children:s?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(h,{children:[(0,U.jsx)(T,{children:`Create a web app`}),(0,U.jsx)(k,{children:`Pick a category to get started, or start from scratch with your own idea.`})]}),(0,U.jsx)(`div`,{className:H.categoryGrid,children:W.map(e=>(0,U.jsxs)(`button`,{type:`button`,className:H.categoryTile,onClick:()=>n(e.slug),children:[(0,U.jsx)(`span`,{className:H.categoryGlyph,"aria-hidden":`true`,children:(0,U.jsx)(L,{category:e.slug})}),(0,U.jsx)(`span`,{className:H.categoryLabel,children:e.label}),(0,U.jsx)(`span`,{className:H.categoryHint,children:e.hint})]},e.slug))})]}):e.kind===`live`?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(h,{children:[(0,U.jsx)(T,{children:`Create a live app`}),(0,U.jsx)(k,{children:`HybridClaw checks your connected tools (MCP), suggests apps that use them, then builds one you can refresh. Add a starting idea (optional).`})]}),(0,U.jsx)(`textarea`,{className:H.promptInput,value:r,autoFocus:!0,placeholder:`e.g. A dashboard of my upcoming meetings and unread priority emails`,onChange:e=>i(e.target.value),rows:4}),(0,U.jsxs)(b,{children:[(0,U.jsx)(`button`,{type:`button`,className:H.secondaryButton,onClick:e.onClose,children:`Cancel`}),(0,U.jsx)(d,{onClick:()=>e.onStartLive(r.trim()),children:`Start building →`})]})]}):t?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)(h,{children:[(0,U.jsxs)(T,{children:[(0,U.jsx)(`span`,{className:H.dialogTitleIcon,"aria-hidden":`true`,children:(0,U.jsx)(L,{category:t})}),o?.label]}),(0,U.jsx)(k,{children:`Add a starting idea (optional). HybridClaw opens a chat, asks a few questions, then builds it for you.`})]}),(0,U.jsx)(`textarea`,{className:H.promptInput,value:r,autoFocus:!0,placeholder:`e.g. A client onboarding portal that tracks setup steps and shows progress`,onChange:e=>i(e.target.value),rows:4}),o&&o.examples.length>0?(0,U.jsxs)(`div`,{className:H.examples,children:[(0,U.jsx)(`span`,{className:H.examplesLabel,children:`Examples`}),(0,U.jsx)(`div`,{className:H.exampleChips,children:o.examples.map(e=>(0,U.jsx)(`button`,{type:`button`,className:H.exampleChip,onClick:()=>i(e),children:e},e))})]}):null,(0,U.jsxs)(b,{children:[(0,U.jsx)(`button`,{type:`button`,className:H.secondaryButton,onClick:()=>n(null),children:`← Back`}),(0,U.jsx)(d,{onClick:()=>e.onStartWeb(t,r.trim()),children:`Start building →`})]})]}):null})})}function se(e){let{app:t}=e;return(0,U.jsx)(_,{open:t!==null,onOpenChange:t=>{t||e.onClose()},children:(0,U.jsxs)(w,{className:H.viewerDialog,"aria-label":`App preview`,children:[(0,U.jsxs)(`div`,{className:H.viewerHeader,children:[(0,U.jsx)(T,{className:H.viewerTitle,children:t?.title}),(0,U.jsxs)(`div`,{className:H.viewerActions,children:[t&&t.kind===`live`&&e.onRefresh?(0,U.jsxs)(`button`,{type:`button`,className:H.secondaryButton,onClick:t=>{t.stopPropagation(),e.onRefresh?.()},children:[(0,U.jsx)(R,{className:H.inlineIcon}),` Refresh`]}):null,t?(0,U.jsx)(`a`,{className:H.secondaryButton,href:B(t.id,e.token),target:`_blank`,rel:`noreferrer`,onClick:e=>e.stopPropagation(),children:`Open in new tab ↗`}):null,(0,U.jsx)(A,{className:H.secondaryButton,onClick:e=>e.stopPropagation(),children:`Close`})]})]}),t?(0,U.jsx)(P,{ref:e.frameRef,appId:t.id,className:H.viewerFrame,refreshNonce:e.refreshNonce,title:t.title,token:e.token}):null]})})}export{q as AppsPage};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{n as e}from"./rolldown-runtime-Bh1tDfsg.js";import{C as t,a as n,n as r,o as i,r as a}from"./query-o_Dd9s85.js";import{d as o,l as s,u as c}from"./router-DoNPHesn.js";import{$ as l,A as u,C as d,Ct as f,Dt as p,E as m,H as h,L as g,N as _,O as v,Ot as y,P as b,Q as ee,S as x,St as S,T as C,Z as w,_ as te,a as T,at as E,b as D,bt as ne,c as O,d as re,dt as ie,et as ae,f as k,g as A,h as oe,ht as se,i as j,it as ce,j as M,l as le,lt as ue,m as de,mt as fe,n as pe,nt as me,o as N,ot as he,p as ge,r as P,rt as _e,s as F,st as I,t as ve,tt as ye,u as be,ut as xe,vt as Se,w as L,x as Ce,xt as we,y as Te}from"./index-B7ZQvYLH.js";import{_ as Ee,a as De,b as Oe,c as ke,d as Ae,f as je,g as Me,h as Ne,i as Pe,l as Fe,m as Ie,o as Le,p as Re,s as ze,t as Be,u as Ve,x as He,y as R}from"./chat-sidebar-ZV6o-A2S.js";var z=e(t(),1);function Ue(e,t){let[n,r]=(0,z.useState)(e);return(0,z.useEffect)(()=>{let n=window.setTimeout(()=>{r(e)},t);return()=>{window.clearTimeout(n)}},[e,t]),n}var We=`[A-Za-z0-9._-]+(?:@[A-Za-z0-9._-]+@[A-Za-z0-9._-]+)?`,Ge=String.raw`(?=$|[\s:.,!?;)\]}])`;RegExp(`^@(${We})${Ge}`,`u`);var Ke=RegExp(`@(${We})${Ge}`,`gu`);function qe(e){let t=[];for(let n of e.matchAll(Ke)){let r=n[0],i=n[1]??``,a=n.index??0;if(!i)continue;let o=a===0?``:e[a-1];o&&!/[\s([{]/u.test(o)||t.push({mention:r,agentId:i,index:a})}return t}var Je=new Map;function B(e){return String(e??``).trim().toLowerCase()}function V(e,t){if(!e||!Array.isArray(e.steps)||e.steps.length===0)return null;let n=[];for(let t of e.steps){if(t.kind===`thinking`){n.push({kind:`thinking`,text:t.text});continue}if(t.kind===`draft`){n.push({kind:`draft`,text:t.text});continue}n.push({kind:`tool`,toolName:t.toolName,status:`done`,...t.argsPreview?{argsPreview:t.argsPreview}:{},...t.resultPreview?{resultPreview:t.resultPreview}:{},...typeof t.durationMs==`number`?{durationMs:t.durationMs}:{}})}return{id:L(),role:`trace`,content:``,sessionId:t,steps:n,done:!0,startedAt:0,...typeof e.elapsedMs==`number`?{finishedAt:e.elapsedMs}:{}}}function Ye(e,t){let n=e.sessionId??t,r=new Map((e.branchFamilies??[]).map(e=>[`${e.anchorSessionId}:${e.anchorMessageId}`,e.variants])),i=new Map;for(let[e,t]of r.entries()){let r=t.find(e=>e.sessionId===n);r&&i.set(r.messageId,e)}let a=e.history??[],o=B(e.agentId),s=null,c=[];return a.forEach((e,t)=>{let r=a.slice(t+1).find(e=>e.role!==`system`),l=B(r?.agent_id??r?.assistantPresentation?.agentId),u=e.role===`user`&&r?.role===`assistant`&&l&&l!==o?r?.assistantPresentation??null:null;e.role===`user`&&(s=e.content);let d=e.role===`user`?e.content:e.role===`assistant`?s:null,f={id:L(),role:e.role,content:e.content,rawContent:e.content,sessionId:n,messageId:e.id??null,media:[],artifacts:e.artifacts??[],replayRequest:d===null?null:{content:d,media:[]},assistantPresentation:e.assistantPresentation??null,addressedAgentPresentation:u,responseRating:e.response_rating??null,branchKey:e.id!==void 0&&e.id!==null?i.get(e.id)??null:null};if(e.role===`assistant`){let t=V(e.activityTrace,n);t&&c.push(t)}c.push(f)}),{messages:c,branchFamilies:r,requestedSessionId:t,resolvedSessionId:n,agentId:e.agentId?.trim()||null,bootstrapAutostart:e.bootstrapAutostart??null}}function H(e,t){return[`chat-history`,e,t]}async function Xe(e,t,n,r){return Ye(await Re(e,t,80,n,r),t)}var Ze=new Map;function Qe(e,t){return`${e}\u0000${t}`}function U(e,t){let n=Qe(e,t),r=Ze.get(n);return r||(r={objectUrl:null,loading:!1,promise:null,listeners:new Set},Ze.set(n,r)),r}function $e(e){for(let t of e.listeners)t()}function et(e,t){let n=t?.trim(),r=e.trim();if(!n)return null;let i=U(r,n);return i.objectUrl?Promise.resolve(i.objectUrl):i.promise?i.promise:(i.loading=!0,i.promise=Fe(r,n).then(e=>{let t=URL.createObjectURL(e);return i.objectUrl=t,i.loading=!1,i.promise=null,$e(i),t}).catch(()=>(i.objectUrl=null,i.loading=!1,i.promise=null,$e(i),null)),$e(i),i.promise)}function W(e){let t=e.token.trim(),n=e.imageUrl?.trim()??``,[r,i]=(0,z.useState)(()=>{if(!n)return{objectUrl:null,loading:!1};let e=U(t,n);return{objectUrl:e.objectUrl,loading:e.loading}});return(0,z.useEffect)(()=>{if(!n){i({objectUrl:null,loading:!1});return}let e=U(t,n),r=()=>{i({objectUrl:e.objectUrl,loading:e.loading})};return e.listeners.add(r),r(),et(t,n),()=>{e.listeners.delete(r)}},[t,n]),r}var G=i();function K(){return(0,G.jsx)(`svg`,{"aria-hidden":`true`,focusable:`false`,viewBox:`0 0 24 24`,width:`14`,height:`14`,fill:`none`,stroke:`currentColor`,strokeWidth:`2`,strokeLinecap:`round`,strokeLinejoin:`round`,children:(0,G.jsx)(`path`,{d:`m6 9 6 6 6-6`})})}function tt(e){let t=e.agents.find(t=>t.id===e.selectedAgentId),n=t?.name?.trim()||t?.id||`Agent`,{localAgents:r,remoteGroups:i}=(0,z.useMemo)(()=>{let t=e.agents.filter(e=>e.source?.type!==`remote`),n=new Map;for(let t of e.agents){if(t.source?.type!==`remote`)continue;let e=t.source.instanceId;n.set(e,[...n.get(e)??[],t])}return{localAgents:t,remoteGroups:[...n.entries()]}},[e.agents]),a=i.length>0;return e.agents.length===0?null:(0,G.jsxs)(j,{value:e.selectedAgentId,disabled:e.disabled,onValueChange:t=>{if(!t||t===e.selectedAgentId)return;let n=e.agents.find(e=>e.id===t);n&&e.onSwitch(n)},children:[(0,G.jsxs)(k,{className:P.composerPill,"aria-label":`Switch agent`,disabled:e.disabled,children:[(0,G.jsx)(ge,{children:n}),(0,G.jsx)(O,{className:P.composerPillChevron,children:(0,G.jsx)(K,{})})]}),(0,G.jsxs)(T,{className:P.agentSelectPopup,children:[a?(0,G.jsxs)(N,{children:[(0,G.jsx)(F,{children:`Local`}),r.map(t=>(0,G.jsx)(q,{agent:t,token:e.token},t.id))]}):r.map(t=>(0,G.jsx)(q,{agent:t,token:e.token},t.id)),i.map(([t,n])=>(0,G.jsxs)(N,{children:[(0,G.jsxs)(F,{className:P.remoteAgentGroupLabel,children:[(0,G.jsx)(ie,{"aria-hidden":`true`,className:P.remoteAgentGroupIcon,width:13,height:13}),(0,G.jsx)(`span`,{children:t})]}),n.map(t=>(0,G.jsx)(q,{agent:t,token:e.token},t.id))]},t))]})]})}function q(e){let t=e.agent.name?.trim()||e.agent.id,n=e.agent.source?.type===`remote`;return(0,G.jsxs)(le,{value:e.agent.id,textValue:t,className:P.agentSelectItem,children:[(0,G.jsx)(nt,{agent:e.agent,token:e.token}),n?(0,G.jsxs)(be,{children:[(0,G.jsx)(`span`,{className:P.agentSelectItemText,children:t}),(0,G.jsx)(re,{children:e.agent.id})]}):(0,G.jsx)(`span`,{className:P.agentSelectItemText,children:t})]})}function nt(e){let t=e.agent.imageUrl?.trim(),n=W({token:e.token??``,imageUrl:t});return n.objectUrl?(0,G.jsx)(`img`,{className:P.agentSelectAvatar,src:n.objectUrl,alt:``}):t?(0,G.jsx)(`span`,{className:P.agentSelectAvatarLoading,"aria-hidden":`true`}):null}function rt(e,t){let n=e.lastIndexOf(`
|
|
2
|
+
`,t-1)+1,r=-1;for(let i=n;i<t;i++)e[i]===`/`&&(i===n||/\s/.test(e[i-1]))&&(r=i);return r===-1?null:{query:e.slice(r+1,t),tokenStart:r}}function it(e,t){return`${e}-opt-${t}`}function at({mode:e,kind:t=`slash`,suggestions:n,activeIdx:r,query:i,listboxId:a,token:o,onSelect:s,onActiveChange:c}){(0,z.useEffect)(()=>{e!==`list`||n.length===0||document.getElementById(it(a,r))?.scrollIntoView({block:`nearest`})},[r,e,n.length,a]);let u=i.trim().toLowerCase(),d=t===`agent`?`@`:`/`,f=t===`agent`?`Agents`:`Slash commands`,p=t===`agent`?`No agents match ${d}${i}`:`No commands match ${d}${i}`;return(0,G.jsx)(l,{side:`top`,focusOnOpen:`none`,closeOnEscape:!1,closeOnOutsideClick:!0,sideOffset:4,className:P.slashSuggestions,children:(0,G.jsxs)(de,{className:P.slashSuggestionsScroll,children:[(0,G.jsx)(te,{id:a,role:`listbox`,"aria-label":f,className:P.slashSuggestionsList,children:e===`list`?n.map((e,n)=>(0,G.jsxs)(`div`,{id:it(a,n),className:I(P.suggestionItem,t===`agent`&&P.suggestionItemAgent,n===r&&P.suggestionItemActive,(e.depth??1)>=2&&P.suggestionItemSub),role:`option`,tabIndex:-1,"aria-selected":n===r,onMouseDown:t=>{t.preventDefault(),s(e)},onMouseEnter:()=>c(n),title:e.description||void 0,children:[t===`agent`?(0,G.jsx)(ot,{item:e,token:o}):null,(0,G.jsxs)(`span`,{className:P.suggestionText,children:[(0,G.jsx)(`span`,{className:P.suggestionLabel,children:ct(e.label,u)}),e.description?(0,G.jsx)(`span`,{className:P.suggestionDesc,children:e.description}):null]})]},e.id)):(0,G.jsx)(`div`,{className:P.suggestionEmpty,role:`status`,children:p})}),(0,G.jsx)(oe,{children:(0,G.jsx)(A,{})})]})})}function ot(e){let t=e.item.imageUrl?.trim(),n=W({token:e.token??``,imageUrl:t});return n.objectUrl?(0,G.jsx)(`img`,{className:P.suggestionAvatar,src:n.objectUrl,alt:``}):t?(0,G.jsx)(`span`,{className:P.suggestionAvatarLoading,"aria-hidden":`true`}):null}var st=/<[^>]+>|\[[^\]]+\]/g;function ct(e,t){let n=[],r=0,i=0,a=(e,r)=>{if(!e)return;let a=r?P.suggestionLabelMono:void 0,o=t?e.toLowerCase().indexOf(t):-1;n.push(o===-1?(0,G.jsx)(`span`,{className:a,children:e},i++):(0,G.jsxs)(`span`,{className:a,children:[e.slice(0,o),(0,G.jsx)(`mark`,{className:P.suggestionMatch,children:e.slice(o,o+t.length)}),e.slice(o+t.length)]},i++))};for(let t of e.matchAll(st)){let n=t.index??0;a(e.slice(r,n),!1),a(t[0],!0),r=n+t[0].length}return a(e.slice(r),!1),n}var lt=RegExp(`(?:^|[\\s([{])@([A-Za-z0-9._-]*(?:@[A-Za-z0-9._-]*){0,2})$`,`u`),ut=RegExp(`@(${We})(?=$|[\\s:])`,`gu`),J=RegExp(`^@${We}(?=$|[\\s:])\\s*`,`u`);function dt(e,t){let n=e.slice(0,t),r=lt.exec(n);if(!r)return null;let i=r[1]??``;return{tokenStart:n.length-i.length-1,query:i}}function ft(e){let t=(0,z.useRef)(null),n=(0,z.useRef)(null),r=(0,z.useRef)(null),[i,a]=(0,z.useState)([]),[o,s]=(0,z.useState)(0),[c,l]=(0,z.useState)([]),[d,f]=(0,z.useState)(`slash`),[p,m]=(0,z.useState)(0),[h,g]=(0,z.useState)(`closed`),[_,v]=(0,z.useState)(``),[y,b]=(0,z.useState)(``),[S,C]=(0,z.useState)(0),te=(0,z.useRef)(null),T=(0,z.useRef)(null),E=(0,z.useRef)(null),D=(0,z.useRef)(0),ne=(0,z.useRef)(null),O=(0,z.useId)(),re=h!==`closed`,ie=h===`closed`?``:d===`agent`?h===`list`?`${u(c.length,`agent`)} available`:`No agents match @${_}`:h===`list`?`${u(c.length,`command`)} available`:`No commands match /${_}`;(0,z.useEffect)(()=>()=>{T.current&&clearTimeout(T.current),E.current&&clearTimeout(E.current),D.current+=1},[]),(0,z.useEffect)(()=>{let e=r.current;if(!e)return;let t=()=>{let t=e.getBoundingClientRect().height;!Number.isFinite(t)||t<=0||document.documentElement.style.setProperty(`--chat-composer-height`,`${Math.ceil(t)}px`)};t();let n=typeof ResizeObserver>`u`?null:new ResizeObserver(t);return n?.observe(e),window.addEventListener(`resize`,t),()=>{n?.disconnect(),window.removeEventListener(`resize`,t),document.documentElement.style.removeProperty(`--chat-composer-height`)}},[]);let ae=(0,z.useRef)(e.isStreaming);(0,z.useEffect)(()=>{ae.current&&!e.isStreaming&&t.current?.focus(),ae.current=e.isStreaming},[e.isStreaming]);let k=(0,z.useCallback)(()=>{let e=t.current;e&&(e.style.height=`36px`,e.style.height=`${Math.max(36,Math.min(e.scrollHeight,180))}px`)},[]),A=(0,z.useCallback)(()=>{let e=t.current;e&&C(e.selectionStart??e.value.length)},[]),oe=(0,z.useCallback)(e=>{let n=()=>{let n=t.current;if(!n)return;let r=Math.max(0,Math.min(e,n.value.length));n.focus(),n.setSelectionRange(r,r),C(r)};n(),E.current&&clearTimeout(E.current),E.current=setTimeout(()=>{E.current=null,n()},0)},[]);(0,z.useEffect)(()=>{let n=e.initialValue?.trim()||``;if(te.current===n||(te.current=n,!n))return;let r=t.current;r&&(r.value=n,r.setSelectionRange(n.length,n.length),b(n),C(n.length),g(`closed`),D.current+=1,k(),r.focus())},[e.initialValue,k]);let se=(0,z.useCallback)(()=>{T.current&&=(clearTimeout(T.current),null),D.current+=1},[]),j=(0,z.useCallback)(()=>{se(),g(`closed`)},[se]),ce=(0,z.useCallback)(async t=>{let n=D.current;try{let r=await Ae(e.token,t||void 0);if(n!==D.current)return;let i=r.commands??[];l(i),m(0),v(t),i.length>0?g(`list`):g(t===``?`closed`:`empty`)}catch{if(n!==D.current)return;l([]),g(`closed`)}},[e.token]),M=(0,z.useCallback)(t=>{let n=t.trim().toLowerCase();return(e.agents??[]).filter(e=>n?e.id.toLowerCase().includes(n)||(e.name??``).toLowerCase().includes(n):!0).map(e=>{let t=e.name?.trim();return{id:`agent:${e.id}`,label:`@${e.id}`,insertText:`@${e.id}`,description:t&&t!==e.id?t:``,imageUrl:e.imageUrl??null}})},[e.agents]);(0,z.useEffect)(()=>{for(let t of e.agents??[])et(e.token,t.imageUrl)},[e.agents,e.token]);let le=()=>{k();let n=t.current;if(!n)return;b(n.value);let r=n.selectionStart??n.value.length;C(r);let i=rt(n.value,r);if(i){let e=i.query.trim();f(`slash`),se(),T.current=setTimeout(()=>{ce(e)},150);return}let a=dt(n.value,r);if(a&&(e.agents?.length??0)>0){se();let e=M(a.query);l(e),f(`agent`),m(0),v(a.query),g(e.length>0?`list`:a.query===``?`closed`:`empty`)}else j()},ue=e=>{let n=t.current;if(!n)return;let r=n.value,i=n.selectionStart??r.length,a=e.insertText.replace(/\s+$/,``),o=n.value.length;if(d===`agent`){let e=dt(r,i);if(e){let t=r.slice(0,e.tokenStart),s=r.slice(i),c=s.startsWith(` `)?a:`${a} `;n.value=t+c+s,o=t.length+c.length,n.setSelectionRange(o,o)}else n.value=`${a} `,o=n.value.length,n.setSelectionRange(o,o);b(n.value),C(o),j(),k(),n.focus();return}let s=rt(r,i);if(s){let e=r.slice(0,s.tokenStart),t=r.slice(i),c=t.startsWith(` `)?a:`${a} `;n.value=e+c+t,o=e.length+c.length,n.setSelectionRange(o,o)}else n.value=`${a} `,o=n.value.length,n.setSelectionRange(o,o);b(n.value),C(o),j(),k(),n.focus()},de=(0,z.useCallback)(e=>{let n=t.current;if(!n)return;let r=`${`@${e}`} `,i=n.value,a=J.exec(i),o;o=i.trim()?a?`${r}${i.slice(a[0].length).trimStart()}`:`${r}${i.trimStart()}`:r,n.value=o,b(n.value),C(r.length),j(),k(),oe(r.length)},[j,k,oe]),fe=()=>{if(e.isStreaming){e.onStop();return}let n=(t.current?.value??``).trim();!n&&i.length===0||o>0||(e.onSend(n,i),t.current&&(t.current.value=``),b(``),C(0),a([]),j(),k())},me=()=>{let e=t.current,n=ne.current;!e||!n||(n.scrollTop=e.scrollTop,n.scrollLeft=e.scrollLeft)},N=e=>{if(!(e.nativeEvent.isComposing||e.nativeEvent.keyCode===229)){if(h===`list`&&c.length>0){if(e.key===`ArrowDown`){e.preventDefault(),m(e=>(e+1)%c.length);return}if(e.key===`ArrowUp`){e.preventDefault(),m(e=>(e-1+c.length)%c.length);return}if(e.key===`Home`){e.preventDefault(),m(0);return}if(e.key===`End`){e.preventDefault(),m(c.length-1);return}if(e.key===`Tab`){e.preventDefault(),ue(c[p]);return}}if(e.key===`Escape`){let t=re;if(j(),t){e.preventDefault();return}}e.key===`Enter`&&!e.shiftKey&&(e.preventDefault(),fe())}},he=e=>{let t=x(e.clipboardData);t.length>0&&(e.preventDefault(),ge(t))},ge=async t=>{s(e=>e+t.length);try{let n=await e.onUploadFiles(t);n.length>0&&a(e=>[...e,...n])}finally{s(e=>Math.max(0,e-t.length))}},_e=e=>{let t=Array.from(e.target.files??[]);t.length>0&&ge(t),e.target.value=``},F=e=>{a(t=>t.filter((t,n)=>n!==e))},ve=e.agents??[],ye=(0,z.useMemo)(()=>new Map(ve.map(e=>[e.id,e])),[ve]),be=e.selectedAgentId??``,xe=e.models??[],Se=e.selectedModelId??``;return(0,G.jsxs)(`div`,{className:P.composerWrapper,ref:r,children:[(0,G.jsxs)(w,{open:re,onOpenChange:e=>{e||j()},children:[(0,G.jsxs)(`div`,{className:P.composer,children:[i.length>0||o>0?(0,G.jsxs)(`div`,{className:P.pendingMediaRow,children:[i.map((e,t)=>(0,G.jsxs)(`span`,{className:P.mediaChip,children:[(0,G.jsx)(`span`,{className:P.mediaChipName,children:e.filename}),(0,G.jsx)(`button`,{type:`button`,className:P.mediaChipRemove,onClick:()=>F(t),children:`×`})]},e.path)),o>0?(0,G.jsx)(`span`,{className:P.mediaChip,children:`Uploading…`}):null]}):null,(0,G.jsxs)(ee,{className:P.composerInputWrap,children:[y?(0,G.jsx)(`div`,{ref:ne,className:P.composerInputOverlay,"aria-hidden":`true`,children:(0,G.jsx)(Y,{value:y,caretIndex:S,agents:ye,token:e.token})}):null,(0,G.jsx)(`textarea`,{ref:t,className:I(P.composerInput,y&&P.composerInputHasOverlay),rows:1,placeholder:`Message HybridClaw`,disabled:e.isStreaming,onInput:le,onSelect:A,onClick:A,onKeyUp:A,onFocus:A,onKeyDown:N,onPaste:he,onScroll:me,"aria-label":`Message input`,role:`combobox`,"aria-autocomplete":`list`,"aria-haspopup":`listbox`,"aria-controls":O,"aria-expanded":re,"aria-activedescendant":h===`list`&&c.length>0?it(O,p):void 0})]}),(0,G.jsxs)(`div`,{className:P.composerActions,children:[(0,G.jsxs)(`div`,{className:P.composerLeftActions,children:[(0,G.jsx)(`button`,{type:`button`,className:P.attachButton,onClick:()=>n.current?.click(),"aria-label":`Attach files`,children:`+`}),(0,G.jsx)(tt,{agents:ve,selectedAgentId:be,token:e.token,disabled:e.isStreaming,onSwitch:t=>{if(t.source?.type===`remote`){de(t.id);return}e.onAgentSwitch?.(t.id)}}),(0,G.jsx)(pe,{models:xe,selectedModelId:Se,disabled:e.isStreaming,onSwitch:t=>e.onModelSwitch?.(t)})]}),(0,G.jsx)(`button`,{type:`button`,className:I(P.sendButton,e.isStreaming&&P.stopping),onClick:fe,"aria-label":e.isStreaming?`Stop`:`Send message`,children:e.isStreaming?(0,G.jsx)(`svg`,{viewBox:`0 0 24 24`,width:`16`,height:`16`,fill:`currentColor`,"aria-hidden":`true`,children:(0,G.jsx)(`rect`,{x:`6`,y:`6`,width:`12`,height:`12`,rx:`2`})}):(0,G.jsxs)(`svg`,{viewBox:`0 0 24 24`,width:`16`,height:`16`,fill:`none`,stroke:`currentColor`,strokeWidth:`2.4`,strokeLinecap:`round`,strokeLinejoin:`round`,"aria-hidden":`true`,children:[(0,G.jsx)(`path`,{d:`M12 19V5`}),(0,G.jsx)(`path`,{d:`m5 12 7-7 7 7`})]})}),(0,G.jsx)(`input`,{ref:n,type:`file`,hidden:!0,multiple:!0,onChange:_e})]})]}),h===`closed`?null:(0,G.jsx)(at,{mode:h,kind:d,suggestions:c,activeIdx:p,query:_,listboxId:O,token:e.token,onSelect:ue,onActiveChange:m})]}),(0,G.jsx)(`div`,{className:P.slashLiveRegion,"aria-live":`polite`,"aria-atomic":`true`,children:ie})]})}function Y(e){let t=[],n=0,r=0,i=!1,a=Math.max(0,Math.min(e.caretIndex,e.value.length)),o=()=>{i||=(t.push((0,G.jsx)(`span`,{className:P.composerOverlayCaret,"aria-hidden":`true`},`caret-${r++}`)),!0)},s=(e,n)=>{let r=n+e.length;if(a<n||a>r){t.push(e);return}let i=a-n;i>0&&t.push(e.slice(0,i)),o(),i<e.length&&t.push(e.slice(i))};for(let i of e.value.matchAll(ut)){let c=i[0],l=i[1]??``,u=i.index??0,d=u+c.length,f=e.agents.get(l);f&&(u>n&&s(e.value.slice(n,u),n),a>u&&a<d?s(c,u):(a===u&&o(),t.push((0,G.jsx)(X,{mention:c,imageUrl:f.imageUrl??null,token:e.token},`mention-${r++}`)),a===d&&o()),n=d)}return n<e.value.length&&s(e.value.slice(n),n),!i&&a===e.value.length&&o(),t.length>0?t:e.value}function X(e){let t=W({token:e.token,imageUrl:e.imageUrl});return(0,G.jsxs)(`span`,{className:P.composerMentionPill,children:[t.objectUrl?(0,G.jsx)(`img`,{className:P.composerMentionAvatar,src:t.objectUrl,alt:``}):null,(0,G.jsx)(`span`,{children:e.mention})]})}var Z={wrap:`_wrap_jrif0_1`,trigger:`_trigger_jrif0_11`,ring:`_ring_jrif0_33`,ringTrack:`_ringTrack_jrif0_37`,ringFill:`_ringFill_jrif0_43`,ringFillNominal:`_ringFillNominal_jrif0_52`,ringFillWarn:`_ringFillWarn_jrif0_56`,ringFillDanger:`_ringFillDanger_jrif0_60`,ringLabel:`_ringLabel_jrif0_64`,ringLabelUnknown:`_ringLabelUnknown_jrif0_77`,popover:`_popover_jrif0_81`,popoverTitle:`_popoverTitle_jrif0_112`,popoverTitleValue:`_popoverTitleValue_jrif0_121`,popoverRow:`_popoverRow_jrif0_126`,popoverRowValue:`_popoverRowValue_jrif0_133`,popoverProgress:`_popoverProgress_jrif0_138`,popoverProgressFill:`_popoverProgressFill_jrif0_148`,popoverProgressFillWarn:`_popoverProgressFillWarn_jrif0_157`,popoverProgressFillDanger:`_popoverProgressFillDanger_jrif0_161`,popoverFoot:`_popoverFoot_jrif0_165`},pt=14,mt=2*Math.PI*pt;function Q(e){if(e==null)return`n/a`;let t=Math.abs(e);return t>=1e6?`${(t>=1e7?(e/1e6).toFixed(0):(e/1e6).toFixed(1)).replace(/\.0$/,``)}M`:t>=1e3?`${(t>=1e4?(e/1e3).toFixed(0):(e/1e3).toFixed(1)).replace(/\.0$/,``)}k`:String(Math.round(e))}function ht(e){return e==null||!Number.isFinite(e)?0:Math.max(0,Math.min(100,e))}function gt(e){return e==null?`nominal`:e>=90?`danger`:e>=70?`warn`:`nominal`}function _t(e){let t=e.sessionId,n=e.enabled&&!!t,r=a({queryKey:[`chat-context`,e.token,t],queryFn:()=>je(e.token,t),enabled:n,staleTime:15e3,refetchOnWindowFocus:!1}).data?.snapshot??null,i=r?.contextUsagePercent??null,o=ht(i),s=gt(i),c=r?.contextBudgetTokens!=null&&r.contextUsedTokens!=null,l=c?mt*(1-o/100):mt,u=i!=null&&Number.isFinite(i)?Math.max(0,Math.round(i)):null,d=u==null?`–`:`${u}%`,f=r&&c&&u!=null?`Context usage ${u} percent (${Q(r.contextUsedTokens)} of ${Q(r.contextBudgetTokens)} tokens)`:`Context usage unavailable`;return(0,G.jsxs)(`div`,{className:Z.wrap,children:[(0,G.jsxs)(`button`,{type:`button`,className:Z.trigger,"aria-label":f,children:[(0,G.jsxs)(`svg`,{width:34,height:34,viewBox:`0 0 34 34`,className:Z.ring,"aria-hidden":`true`,children:[(0,G.jsx)(`circle`,{cx:17,cy:17,r:pt,className:Z.ringTrack}),(0,G.jsx)(`circle`,{cx:17,cy:17,r:pt,className:I(Z.ringFill,s===`warn`&&Z.ringFillWarn,s===`danger`&&Z.ringFillDanger,s===`nominal`&&Z.ringFillNominal),strokeDasharray:mt,strokeDashoffset:l})]}),(0,G.jsx)(`span`,{className:I(Z.ringLabel,u==null&&Z.ringLabelUnknown),children:d})]}),(0,G.jsxs)(`div`,{role:`tooltip`,className:Z.popover,children:[(0,G.jsxs)(`div`,{className:Z.popoverTitle,children:[(0,G.jsx)(`span`,{children:`Context`}),(0,G.jsx)(`span`,{className:Z.popoverTitleValue,children:r?.model||`unknown model`})]}),r&&c?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:Z.popoverProgress,children:(0,G.jsx)(`div`,{className:I(Z.popoverProgressFill,s===`warn`&&Z.popoverProgressFillWarn,s===`danger`&&Z.popoverProgressFillDanger),style:{width:`${o}%`}})}),(0,G.jsxs)(`div`,{className:Z.popoverRow,children:[(0,G.jsx)(`span`,{children:`Used`}),(0,G.jsxs)(`span`,{className:Z.popoverRowValue,children:[Q(r.contextUsedTokens),` /`,` `,Q(r.contextBudgetTokens),` tokens`]})]}),(0,G.jsxs)(`div`,{className:Z.popoverRow,children:[(0,G.jsx)(`span`,{children:`Headroom`}),(0,G.jsxs)(`span`,{className:Z.popoverRowValue,children:[Q(r.contextRemainingTokens),` tokens`]})]})]}):(0,G.jsxs)(`div`,{className:Z.popoverRow,children:[(0,G.jsx)(`span`,{children:`Used`}),(0,G.jsx)(`span`,{className:Z.popoverRowValue,children:r?.contextUsedTokens==null?`no usage recorded yet`:`${Q(r.contextUsedTokens)} tokens`})]}),(0,G.jsxs)(`div`,{className:Z.popoverRow,children:[(0,G.jsx)(`span`,{children:`Compactions`}),(0,G.jsx)(`span`,{className:Z.popoverRowValue,children:r?`${r.compactionCount} · ${Q(r.compactionMessageThreshold)} msgs / ${Q(r.compactionTokenBudget)} tokens`:`n/a`})]}),(0,G.jsxs)(`div`,{className:Z.popoverFoot,children:[`Run `,(0,G.jsx)(`code`,{children:`/context`}),` for full details · `,(0,G.jsx)(`code`,{children:`/compact`}),` to archive older history.`]})]})]})}var vt=[{label:`Trust session`,action:`session`,isAvailable:e=>e.allowSession===!0},{label:`Trust agent`,action:`agent`,isAvailable:e=>e.allowAgent===!0},{label:`Always allow`,action:`all`,isAvailable:e=>e.allowAll===!0}],$=/^([^:\n]{2,44}):\s+(.+)$/,yt=/^(GET|POST|PUT|PATCH|DELETE|HEAD|OPTIONS)\s+/i;function bt(e){return e===`yellow`?`Amber`:e===`red`?`Red`:null}function xt(e){return/^reply\b/i.test(e)||/^approval expires\b/i.test(e)||/^approval id\b/i.test(e)}function St(e){let t=e.trim();return/^proposed action$/i.test(t)?`Request`:/^why$/i.test(t)?`Reason`:t}function Ct(e){let t=[],n,r=e.split(/\r?\n/).map(e=>e.trim()).filter(Boolean);for(let e of r){if(xt(e)||/^classifier reasoning$/i.test(e)||/^if you skip this/i.test(e))continue;let r=e.match($);if(r){let e=St(r[1]??``);/^classifier reasoning$/i.test(e)||t.push({label:e,value:r[2]??``});continue}n??=e}return{introLine:n,rows:t}}function wt(e){let t=[],n=new Set,r=(e,r)=>{let i=e.trim(),a=String(r??``).trim();if(!i||!a)return;let o=`${i.toLowerCase()}:${a}`;n.has(o)||(n.add(o),t.push({label:i,value:a}))};e.intent&&r(`Action`,e.intent),e.commandPreview&&r(yt.test(e.commandPreview)?`Request`:`Preview`,e.commandPreview),e.toolName&&r(`Tool`,e.toolName);for(let t of Ct(e.prompt).rows)r(t.label,t.value);if(r(`Approval ID`,e.approvalId),e.expiresAt&&Number.isFinite(e.expiresAt)){let t=new Date(e.expiresAt);Number.isNaN(t.getTime())||r(`Expires`,t.toLocaleTimeString())}return t}function Tt(e){let{introLine:t}=Ct(e.prompt);return t||(e.summary?e.summary.split(/\r?\n/)[0]??``:e.intent?`Confirmation required for ${e.intent}.`:`Confirmation required before this action can continue.`)}function Et(e){let{approval:t}=e,n=(0,z.useMemo)(()=>wt(t),[t]),r=(0,z.useMemo)(()=>Tt(t),[t]),i=vt.filter(e=>e.isAvailable(t)),a=bt(t.approvalTier),o=n=>{e.onAction(n,t.approvalId)};return(0,G.jsxs)(`div`,{className:P.approvalCard,children:[(0,G.jsxs)(`div`,{className:P.approvalHeader,children:[a?(0,G.jsx)(`span`,{className:P.approvalTier,children:a}):null,(0,G.jsx)(`span`,{className:P.approvalTitle,children:`Confirmation required`})]}),(0,G.jsx)(`p`,{className:P.approvalIntro,children:r}),n.length>0?(0,G.jsx)(`dl`,{className:P.approvalDetails,children:n.map(e=>(0,G.jsxs)(`div`,{className:P.approvalDetailRow,children:[(0,G.jsx)(`dt`,{children:e.label}),(0,G.jsx)(`dd`,{children:e.value})]},`${e.label}:${e.value}`))}):null,(0,G.jsxs)(`div`,{className:P.approvalPrimaryActions,children:[(0,G.jsx)(v,{size:`sm`,disabled:e.busy,onClick:()=>o(`once`),children:`Allow once`}),(0,G.jsx)(v,{variant:`danger`,size:`sm`,disabled:e.busy,onClick:()=>o(`deny`),children:`Cancel`})]}),i.length>0?(0,G.jsx)(`div`,{className:P.approvalTrustActions,children:i.map(t=>(0,G.jsx)(v,{variant:`outline`,size:`sm`,className:P.approvalAllow,disabled:e.busy,onClick:()=>o(t.action),children:t.label},t.action))}):null]})}function Dt(e){if(e<1e3)return`${Math.max(0,Math.round(e))}ms`;let t=e/1e3;if(t<10)return`${t.toFixed(1)}s`;if(t<60)return`${Math.round(t)}s`;let n=Math.floor(t/60),r=Math.round(t%60);return r>0?`${n}m ${r}s`:`${n}m`}function Ot(e,t,n){if(!e.done){let e=t.slice().reverse().find(e=>e.kind!==`draft`)??t[t.length-1];return e?.kind===`tool`&&e.status===`running`?`${e.toolName}…`:e?.kind===`thinking`?`Thinking…`:`Working…`}let r=t.filter(e=>e.kind===`tool`).length,i=t.some(e=>e.kind===`thinking`),a=[];r>0?(a.push(`${r} tool call${r===1?``:`s`}`),i&&a.push(`thinking`)):i?a.push(`Thought`):t.some(e=>e.kind===`draft`)&&a.push(`Agent activity`);let o=e.finishedAt?e.finishedAt-e.startedAt:0;return n&&o>=1e3&&a.push(Dt(o)),a.join(` · `)||`Agent activity`}function kt(e){let t=(0,z.useMemo)(()=>ve(e.text,{highlight:!1}),[e.text]);return(0,G.jsx)(`div`,{className:P.traceDraftInterim,children:(0,G.jsx)(`div`,{className:P.markdownContent,dangerouslySetInnerHTML:{__html:t}})})}function At(e){let{step:t,live:n}=e;if(t.kind===`draft`)return(0,G.jsx)(kt,{text:t.text});if(t.kind===`thinking`)return(0,G.jsxs)(`div`,{className:P.traceStep,children:[(0,G.jsx)(`span`,{className:P.traceStepMarker,"aria-hidden":`true`,children:(0,G.jsx)(`span`,{className:P.traceDot})}),(0,G.jsx)(`div`,{className:P.traceThinkingText,children:t.text})]});let r=n&&t.status===`running`;return(0,G.jsxs)(`div`,{className:P.traceStep,children:[(0,G.jsx)(`span`,{className:P.traceStepMarker,"aria-hidden":`true`,children:(0,G.jsx)(`span`,{className:I(P.traceDot,r&&P.traceDotRunning)})}),(0,G.jsxs)(`div`,{className:P.traceStepBody,children:[(0,G.jsxs)(`div`,{className:P.traceToolLine,children:[(0,G.jsx)(`span`,{className:P.traceToolName,children:t.toolName}),t.argsPreview?(0,G.jsx)(`span`,{className:P.traceToolPreview,title:t.argsPreview,children:t.argsPreview}):null,typeof t.durationMs==`number`?(0,G.jsx)(`span`,{className:P.traceToolDuration,children:Dt(t.durationMs)}):null]}),t.resultPreview?(0,G.jsx)(`div`,{className:P.traceToolResult,title:t.resultPreview,children:t.resultPreview}):null]})]})}function jt(e){let{message:t,steps:n}=e,[r,i]=(0,z.useState)(null);if((0,z.useEffect)(()=>{t.done&&i(null)},[t.done]),n.length===0)return null;let a=r??!t.done;return(0,G.jsxs)(`div`,{className:P.traceBlock,children:[(0,G.jsxs)(`button`,{type:`button`,className:P.traceHeader,"aria-expanded":a,"aria-label":a?`Collapse agent activity`:`Expand agent activity`,onClick:()=>i(!a),children:[(0,G.jsx)(`span`,{className:I(P.traceChevron,a&&P.traceChevronOpen),"aria-hidden":`true`,children:`›`}),(0,G.jsx)(`span`,{className:I(P.traceSummary,!t.done&&P.traceSummaryLive),children:Ot(t,n,!0)})]}),a?(0,G.jsx)(`div`,{className:P.traceSteps,children:n.map((e,n)=>(0,G.jsx)(At,{step:e,live:!t.done},n))}):null]})}var Mt=(0,z.memo)(function(e){let{message:t}=e;return t.steps.length===0?null:(0,G.jsx)(`div`,{className:P.traceSequence,children:(0,G.jsx)(jt,{message:t,steps:t.steps})})}),Nt=120;function Pt(e,t,n){let[r,i]=(0,z.useState)(e),a=(0,z.useRef)(e),o=(0,z.useRef)(null);a.current=e,(0,z.useEffect)(()=>{if(!t){o.current!==null&&(window.clearTimeout(o.current),o.current=null),i(``);return}if(!n){o.current!==null&&(window.clearTimeout(o.current),o.current=null),i(e);return}o.current!==null||e===r||(o.current=window.setTimeout(()=>{o.current=null,(0,z.startTransition)(()=>{i(a.current)})},Nt))},[e,t,n,r]),(0,z.useEffect)(()=>()=>{o.current!==null&&window.clearTimeout(o.current)},[]);let s=t?n?r:e:``;return(0,z.useMemo)(()=>t?ve(s,{highlight:!n}):``,[t,s,n])}var Ft=`<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="9" y="9" width="11" height="11" rx="2"/><path d="M5 15V5a2 2 0 0 1 2-2h10"/></svg>`,It=`<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 6 9 17l-5-5"/></svg>`,Lt=`<svg viewBox="0 0 24 24" width="11" height="11" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="m9 7-5 5 5 5"/><path d="m15 7 5 5-5 5"/><path d="m13.5 5-3 14"/></svg>`,Rt=/^\/([A-Za-z0-9][A-Za-z0-9._-]*)(?=$|[\s:.,!?;)\]}])/u,zt=new Set([`text`,`plaintext`,`plain`,`txt`]);function Bt(e){let t=e.querySelector(`code`)?.className.match(/language-([\w#.+-]+)/)?.[1]??``;return zt.has(t)?``:t}function Vt(e){if(e.querySelector(`button[data-copy-btn]`))return;let t=Bt(e);if(t){e.classList.add(P.codeBlockLabeled);let n=document.createElement(`span`);n.className=P.codeLangLabel,n.setAttribute(`aria-hidden`,`true`),n.innerHTML=Lt;let r=document.createElement(`span`);r.textContent=t,n.appendChild(r),e.appendChild(n)}let n=document.createElement(`button`);n.type=`button`,n.dataset.copyBtn=``,n.className=P.codeCopyButton,n.innerHTML=Ft;let r=e=>{n.setAttribute(`aria-label`,e),n.title=e};r(`Copy code`);let i=null;n.addEventListener(`click`,()=>{Ce((e.querySelector(`code`)??e).textContent??``).then(e=>{e&&(n.innerHTML=It,n.classList.add(P.codeCopyButtonDone),r(`Copied`),i!==null&&window.clearTimeout(i),i=window.setTimeout(()=>{n.innerHTML=Ft,n.classList.remove(P.codeCopyButtonDone),r(`Copy code`)},1500))})}),e.appendChild(n)}function Ht(){let e=(0,z.useRef)(null);return(0,z.useCallback)(t=>{if(e.current?.disconnect(),e.current=null,!t)return;let n=()=>{for(let e of t.querySelectorAll(`pre`))Vt(e)};n();let r=new MutationObserver(n);r.observe(t,{childList:!0,subtree:!0}),e.current=r},[])}function Ut(e,t){let n=t.split(`;`)[0]?.trim().toLowerCase()||``;return!n||n!==`application/pdf`&&!n.startsWith(`image/`)&&!n.startsWith(`video/`)||e.type.toLowerCase()===n?e:new Blob([e],{type:n})}function Wt(e){let{artifact:t,token:n}=e,r=(0,z.useRef)(null),[i,a]=(0,z.useState)(null),[o,s]=(0,z.useState)(!1),c=(t.mimeType??``).toLowerCase(),l=t.filename??`artifact`,u=c.startsWith(`image/`),d=c.startsWith(`video/`)||/\.(mp4|m4v|mov|webm)$/i.test(t.filename??``)||/\.(mp4|m4v|mov|webm)$/i.test(t.path??``),f=c===`application/pdf`||/\.pdf$/i.test(t.filename??``)||/\.pdf$/i.test(t.path??``),p=u||d||f;(0,z.useEffect)(()=>{let e=r.current;if(r.current=null,e&&URL.revokeObjectURL(e),a(null),!p||!t.path)return;let i=!1;return Ve(n,t.path).then(e=>{if(i)return;let t=URL.createObjectURL(Ut(e,c));r.current=t,a(t)}).catch(()=>{i||a(null)}),()=>{i=!0;let e=r.current;r.current=null,e&&URL.revokeObjectURL(e)}},[t.path,p,c,n]);let m=o?`Downloading…`:`Download`,h=async()=>{if(!(!t.path||o)){s(!0);try{let e=i??URL.createObjectURL(await Ve(n,t.path)),r=document.createElement(`a`);r.href=e,r.download=t.filename??`artifact`,r.rel=`noopener noreferrer`,document.body.appendChild(r),r.click(),r.remove(),i||window.setTimeout(()=>URL.revokeObjectURL(e),0)}catch{}finally{s(!1)}}};return(0,G.jsxs)(`div`,{className:I(P.artifactCard,i&&P.artifactCardWithPreview),children:[(0,G.jsxs)(`div`,{className:P.artifactHeader,children:[(0,G.jsx)(`span`,{className:P.artifactFilename,children:l}),t.type?(0,G.jsx)(`span`,{className:P.artifactBadge,children:t.type}):null,t.path?(0,G.jsx)(`button`,{type:`button`,className:P.artifactDownload,disabled:o,onClick:()=>{h()},children:m}):null]}),u&&i?(0,G.jsx)(`div`,{className:P.artifactPreview,children:(0,G.jsx)(`img`,{src:i,alt:l})}):null,f&&i?(0,G.jsx)(`div`,{className:I(P.artifactPreview,P.artifactPdfPreview),children:(0,G.jsx)(`iframe`,{src:i,title:`${l} preview`,sandbox:``})}):null,d&&i?(0,G.jsx)(`div`,{className:I(P.artifactPreview,P.artifactVideoPreview),children:(0,G.jsx)(`video`,{controls:!0,preload:`metadata`,src:i,children:(0,G.jsxs)(`a`,{href:i,download:l,children:[`Download `,l]})})}):null]})}function Gt(e){let t=(0,z.useRef)(null),[n,r]=(0,z.useState)(null);return(0,z.useEffect)(()=>{let n=t.current;if(t.current=null,n&&URL.revokeObjectURL(n),r(null),!e.imageUrl)return;let i=!1;return Fe(e.token,e.imageUrl).then(e=>{if(i)return;let n=URL.createObjectURL(e);t.current=n,r(n)}).catch(()=>{i||r(null)}),()=>{i=!0;let e=t.current;t.current=null,e&&URL.revokeObjectURL(e)}},[e.imageUrl,e.token]),n}var Kt=(0,z.memo)(function(e){let{message:t,token:n}=e,[r,i]=(0,z.useState)(!1),a=()=>{e.onCopy(t.rawContent??t.content),i(!0),setTimeout(()=>i(!1),900)},o=(0,z.useMemo)(()=>{let e=new Map;return(t.artifacts??[]).map(t=>{let n=[t.path,t.filename,t.mimeType,t.type].filter(Boolean),r=n.length>0?n.join(`|`):`artifact`,i=e.get(r)??0;return e.set(r,i+1),{artifact:t,key:`${r}:${i}`}})},[t.artifacts]),s=t.role===`approval`,c=t.role===`draft`,l=s&&!!t.pendingApproval,u=t.role===`assistant`||c||t.role===`command`||s&&!l,d=Pt(t.content,u,e.isStreaming),f=Ht(),p=t.assistantPresentation,m=p?.displayName??`Assistant`,h=Gt({token:n,imageUrl:p?.imageUrl});if(t.role===`trace`)return(0,G.jsx)(Mt,{message:t});if(t.role===`thinking`)return(0,G.jsxs)(`div`,{className:P.thinking,role:`status`,"aria-label":`Assistant is thinking`,children:[(0,G.jsx)(`span`,{className:P.thinkingDot}),(0,G.jsx)(`span`,{className:P.thinkingDot}),(0,G.jsx)(`span`,{className:P.thinkingDot})]});if(c)return(0,G.jsx)(`div`,{className:P.traceDraftInterim,children:(0,G.jsx)(`div`,{ref:f,className:P.markdownContent,dangerouslySetInnerHTML:{__html:d}})});let g=t.role===`user`,_=t.role===`assistant`,y=g||t.content.trim().length>0||o.length===0||s,b=I(P.messageBlock,g&&P.messageBlockUser,(_||t.role===`system`||t.role===`command`||s)&&P.messageBlockAssistant),ee=I(P.bubble,g&&P.bubbleUser,(_||s)&&P.bubbleAssistant,s&&P.bubbleApproval,t.role===`system`&&P.bubbleSystem,t.role===`command`&&P.bubbleCommand);return(0,G.jsxs)(`div`,{className:b,children:[_?(0,G.jsxs)(`div`,{className:P.agentLabel,children:[h?(0,G.jsx)(`img`,{className:P.agentAvatar,src:h,alt:``}):(0,G.jsx)(`span`,{className:P.agentInitial,children:m.charAt(0).toUpperCase()}),(0,G.jsx)(`span`,{children:m})]}):null,y?(0,G.jsx)(`div`,{className:ee,children:l&&t.pendingApproval?(0,G.jsx)(Et,{approval:t.pendingApproval,busy:e.approvalBusy,onAction:e.onApprovalAction}):u?(0,G.jsx)(`div`,{ref:f,className:P.markdownContent,dangerouslySetInnerHTML:{__html:d}}):g?(0,G.jsx)(qt,{content:R(t.content),presentation:t.addressedAgentPresentation,skillInvocationTargets:e.skillInvocationTargets,token:n}):t.content}):null,o.map(({artifact:e,key:t})=>(0,G.jsx)(Wt,{artifact:e,token:n},t)),e.isStreaming?null:(0,G.jsxs)(`div`,{className:P.messageActions,children:[_&&t.replayRequest?(0,G.jsx)(v,{variant:`ghost`,size:`icon`,className:P.actionButton,title:`Regenerate`,"aria-label":`Regenerate response`,onClick:()=>e.onRegenerate(t),children:`↻`}):null,_?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(v,{variant:`ghost`,size:`icon`,className:I(P.actionButton,t.responseRating===`up`&&P.actionButtonSelected),title:t.responseRating===`up`?`Clear thumbs up`:`Thumbs up`,"aria-label":t.responseRating===`up`?`Clear thumbs up rating`:`Rate response thumbs up`,"aria-pressed":t.responseRating===`up`,"data-rating-locked":t.responseRating?`true`:void 0,disabled:e.ratingBusy===!0||!t.messageId||t.responseRating===`down`,onClick:()=>e.onRate?.(t,t.responseRating===`up`?null:`up`),children:(0,G.jsx)(ue,{width:`13`,height:`13`,filled:t.responseRating===`up`})}),(0,G.jsx)(v,{variant:`ghost`,size:`icon`,className:I(P.actionButton,t.responseRating===`down`&&P.actionButtonSelected),title:t.responseRating===`down`?`Clear thumbs down`:`Thumbs down`,"aria-label":t.responseRating===`down`?`Clear thumbs down rating`:`Rate response thumbs down`,"aria-pressed":t.responseRating===`down`,"data-rating-locked":t.responseRating?`true`:void 0,disabled:e.ratingBusy===!0||!t.messageId||t.responseRating===`up`,onClick:()=>e.onRate?.(t,t.responseRating===`down`?null:`down`),children:(0,G.jsx)(xe,{width:`13`,height:`13`,filled:t.responseRating===`down`})})]}):null,(0,G.jsx)(v,{variant:`ghost`,size:`icon`,className:I(P.actionButton,r&&P.actionButtonSuccess),title:`Copy`,"aria-label":r?`Copied`:`Copy message`,onClick:a,children:r?`✓`:`⧉`}),g?(0,G.jsx)(v,{variant:`ghost`,size:`icon`,className:P.actionButton,title:`Edit`,"aria-label":`Edit message`,onClick:()=>e.onEdit(t),children:`✎`}):null,e.branchInfo&&e.branchInfo.total>1?(0,G.jsxs)(`div`,{className:P.branchSwitcher,children:[(0,G.jsx)(v,{variant:`ghost`,size:`icon`,className:P.branchButton,"aria-label":`Previous branch`,disabled:e.branchInfo.current<=1,onClick:()=>e.onBranchNav(t,-1),children:`‹`}),(0,G.jsxs)(`span`,{children:[e.branchInfo.current,`/`,e.branchInfo.total]}),(0,G.jsx)(v,{variant:`ghost`,size:`icon`,className:P.branchButton,"aria-label":`Next branch`,disabled:e.branchInfo.current>=e.branchInfo.total,onClick:()=>e.onBranchNav(t,1),children:`›`})]}):null]})]})});function qt(e){let t=qe(e.content),n=[],r=0;for(let[i,a]of t.entries()){a.index>r&&Jt(n,e.content.slice(r,a.index),`text-${i}`,r===0,e.skillInvocationTargets);let t=e.presentation?.agentId?.toLowerCase()===a.agentId.toLowerCase()?e.presentation:null;n.push((0,G.jsx)(Yt,{mention:a.mention,imageUrl:t?.imageUrl??null,token:e.token},`${a.index}-${i}`)),r=a.index+a.mention.length}return r<e.content.length&&Jt(n,e.content.slice(r),`text-tail`,r===0,e.skillInvocationTargets),(0,G.jsx)(G.Fragment,{children:n})}function Jt(e,t,n,r,i){if(!t)return;if(!r||!i){e.push(t);return}let a=Rt.exec(t),o=a?.[1]??``,s=i.get(o.toLowerCase());if(!a||!o||!s){e.push(t);return}let c=a[0];e.push((0,G.jsx)(`a`,{className:P.userSkillCommandLink,href:`/admin/skills/${encodeURIComponent(s)}`,children:c},`${n}-skill-command`));let l=t.slice(c.length);l&&e.push(l)}function Yt(e){let t=Gt({token:e.token,imageUrl:e.imageUrl});return(0,G.jsxs)(`span`,{className:P.userAgentMentionPill,children:[t?(0,G.jsx)(`img`,{className:P.userAgentMentionAvatar,src:t,alt:``}):null,(0,G.jsx)(`span`,{children:e.mention})]})}function Xt(e){let[t,n]=(0,z.useState)(e.initial);return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`textarea`,{className:P.editArea,value:t,onChange:e=>n(e.target.value),"aria-label":`Edit message`,autoFocus:!0}),(0,G.jsxs)(`div`,{className:P.editButtons,children:[(0,G.jsx)(v,{onClick:()=>e.onSave(t.trim()),disabled:!t.trim(),children:`Save`}),(0,G.jsx)(v,{variant:`ghost`,onClick:e.onCancel,children:`Cancel`})]})]})}function Zt(){let e=o({strict:!1}),t=s(),n=e.sessionId,r=(0,z.useRef)(null),i=(0,z.useRef)(new Set);if(!n&&!r.current){let e=d();r.current=e,i.current.add(e)}let a=n??r.current??``,c=(0,z.useRef)(a);c.current=a,(0,z.useEffect)(()=>{n&&(r.current=null)},[n]),(0,z.useEffect)(()=>{a&&m(a)},[a]);let l=(0,z.useCallback)(()=>c.current,[]),u=(0,z.useCallback)((e,n)=>t({to:`/chat/$sessionId`,params:{sessionId:e},...n}),[t]);return(0,z.useEffect)(()=>{n||!a||u(a,{replace:!0})},[u,a,n]),{sessionId:a,getSessionId:l,navigateToSession:u,switchToSession:(0,z.useCallback)((e,t)=>(r.current=e,c.current=e,u(e,t)),[u]),startFreshChat:(0,z.useCallback)(e=>{let t=d();return r.current=t,c.current=t,i.current.add(t),u(t,e),t},[u]),ensureSessionForSend:(0,z.useCallback)(()=>{if(c.current)return c.current;let e=d();return r.current=e,c.current=e,i.current.add(e),u(e,{replace:!0}),e},[u]),isLocallyCreatedSession:(0,z.useCallback)(e=>i.current.has(e),[]),handleSessionIdCorrection:(0,z.useCallback)(e=>{e!==c.current&&u(e,{replace:!0})},[u])}}async function Qt(e,t){let n=await fetch(e,{method:`POST`,headers:{...f(t.token,t.body),Accept:`application/x-ndjson`},body:JSON.stringify(t.body),signal:t.signal});n.ok||await p(n);let{callbacks:r}=t,i=e=>{let t=String(e||``).trim();if(!t)return null;let n;try{n=JSON.parse(t)}catch{return console.warn(`Ignoring malformed chat stream line`,t),null}return!n||typeof n!=`object`?null:n.type===`text`&&typeof n.delta==`string`?(r.onTextDelta(n.delta,n),null):n.type===`thinking`&&typeof n.delta==`string`?(r.onThinkingDelta?.(n.delta),null):n.type===`tool`&&typeof n.toolName==`string`&&(n.phase===`start`||n.phase===`finish`)?(r.onToolEvent?.(n),null):n.type===`approval`&&typeof n.approvalId==`string`&&typeof n.prompt==`string`?(r.onApproval(n),null):n.type===`result`&&n.result&&typeof n.result==`object`?n.result:typeof n.status==`string`&&Array.isArray(n.toolsUsed)?n:null};if(!n.body){let e=await n.text().catch(()=>``),t=null;for(let n of e.split(`
|
|
3
|
+
`)){let e=i(n);e&&(t=e)}if(!t)throw Error(`Chat stream ended without a result payload.`);return t}let a=n.body.getReader(),o=new TextDecoder,s=``,c=null,l=(e=!1)=>{let t=s.split(`
|
|
4
|
+
`),n=e?t.pop()??``:null;s=e?``:t.pop()??``;for(let e of t){let t=i(e);t&&(c=t)}if(e&&n?.trim()){let e=i(n);e&&(c=e)}};try{for(;;){let{done:e,value:t}=await a.read();if(e)break;s+=o.decode(t,{stream:!0}),l()}s+=o.decode(),l(!0)}finally{a.releaseLock()}if(!c)throw Error(`Chat stream ended without a result payload.`);return c}function $t(e){let t=e.trim().split(/\s+/),n=t[0]?.replace(/^\/+/,``).toLowerCase(),r=t[1]?.toLowerCase();return(n===`agent`||n===`agents`)&&(r===`create`||r===`install`)}function en(e){let t=e.trim().split(/\s+/),n=t[0]?.replace(/^\/+/,``).toLowerCase();if(n!==`agent`&&n!==`agents`||t[1]?.toLowerCase()!==`switch`)return null;let r=t[2]?.trim();return r&&!/\s/.test(r)?r:null}function tn(e){return/^Session agent set to\b/i.test(e.trim())}function nn(e){return/\bBOOTSTRAP\.md\b/i.test(e)}function rn(e){let{token:t,userId:r,getSessionId:i,setError:a,refreshRecent:o,onSessionIdCorrection:s,onModelResolved:c,onAppsCaptured:l,resolveAddressedAgentPresentation:u}=e,d=n(),f=(0,z.useRef)(null),[p,m]=(0,z.useState)(!1),[h,g]=(0,z.useState)(null),[_,v]=(0,z.useState)(null),y=(0,z.useCallback)((e,n)=>{let r=H(t,e);d.setQueryData(r,t=>{let r=t?.messages??[],i=typeof n==`function`?n(r):n;return i===r?t:{messages:i,branchFamilies:t?.branchFamilies??new Map,requestedSessionId:t?.requestedSessionId??e,resolvedSessionId:t?.resolvedSessionId??e,agentId:t?.agentId??null,bootstrapAutostart:t?.bootstrapAutostart??null}})},[d,t]);return{sendMessage:(0,z.useCallback)(async(e,n,p)=>{if(f.current)return a(`Wait for the current run to finish before sending another message.`),!1;let h=i(),_=e=>y(h,e),b=p?.hideUser?null:L();if(a(``),b){let t=u?.(e)??null,r={id:b,role:`user`,content:e,rawContent:e,sessionId:h,media:n,artifacts:[],replayRequest:{content:e,media:n},addressedAgentPresentation:t};_(e=>[...e,r])}let ee=L(),x=L();_(e=>[...e,{id:x,role:`trace`,content:``,sessionId:h,steps:[],done:!1,startedAt:Date.now()},{id:ee,role:`thinking`,content:``,sessionId:h}]);let S=L();g(S);let C={controller:new AbortController,sessionId:h,messageRole:`assistant`,assistantText:``,lastRenderedText:``,pendingApproval:null,trace:[],traceVersion:0,lastRenderedTraceVersion:0,renderFrame:0,stopping:!1};f.current=C,v(h),m(!0);let w=()=>{C.renderFrame=0;let e=C.traceVersion!==C.lastRenderedTraceVersion;if(C.assistantText===C.lastRenderedText&&!C.pendingApproval&&!e)return;C.lastRenderedText=C.assistantText,C.lastRenderedTraceVersion=C.traceVersion;let t=C.assistantText,n=C.pendingApproval,r=C.messageRole===`assistant`&&!n&&C.trace.length>0?`draft`:C.messageRole,i=e?C.trace.map(e=>({...e})):null;_(e=>{let a=i?e.map(e=>e.id===x&&e.role===`trace`?{...e,steps:i}:e):e;if(!t&&!n)return a.filter(e=>e.id!==S);let o=a.filter(e=>e.id!==ee),s=o.find(e=>e.id===S);return s?o.map(e=>e===s?{...e,role:r,content:t,pendingApproval:n}:e):[...o,{id:S,role:r,content:t,sessionId:C.sessionId,artifacts:[],pendingApproval:n}]})},te=()=>{C.renderFrame&&=(cancelAnimationFrame(C.renderFrame),0),w()},T=()=>{C.renderFrame||=requestAnimationFrame(w)},E=e=>{if(!e)return;let t=C.trace.at(-1);t?.kind===`thinking`?t.text+=e:C.trace.push({kind:`thinking`,text:e}),C.traceVersion+=1,T()},ne=()=>{let e=C.assistantText.trim();e.trim()&&(C.trace.push({kind:`draft`,text:e}),C.assistantText=``,C.lastRenderedText=``)},O=e=>{if(e.phase===`start`)ne(),C.trace.push({kind:`tool`,toolName:e.toolName,status:`running`,argsPreview:e.preview||void 0});else{let t;for(let n=C.trace.length-1;n>=0;n--){let r=C.trace[n];if(r?.kind===`tool`&&r.status===`running`&&r.toolName===e.toolName){t=r;break}}t?(t.status=`done`,t.durationMs=e.durationMs,t.resultPreview=e.preview||void 0):C.trace.push({kind:`tool`,toolName:e.toolName,status:`done`,durationMs:e.durationMs,resultPreview:e.preview||void 0})}C.traceVersion+=1,T()},re=e=>{if(C.trace.length===0)return e.filter(e=>e.id!==x);let t=C.trace.map(e=>({...e}));return e.map(e=>e.id===x&&e.role===`trace`?{...e,steps:t,done:!0,finishedAt:Date.now()}:e)};try{let i=await Qt(`/api/chat`,{token:t,body:{sessionId:h,channelId:`web`,userId:r,username:`web`,content:e,stream:!0,...n.length>0?{media:n}:{},...p?.appBuild?{appBuild:!0}:{},...p?.appCategory?{appCategory:p.appCategory}:{},...p?.appKind?{appKind:p.appKind}:{}},signal:C.controller.signal,callbacks:{onTextDelta:(e,t)=>{t?.outputPresentation?.visible!==!1&&(C.assistantText+=e,T())},onApproval:e=>{C.pendingApproval=e,C.messageRole=`approval`,C.assistantText.trim()||(C.assistantText=D(e)),T()},onThinkingDelta:E,onToolEvent:O}});if(i.status===`error`)throw Error(i.error??`Unknown error`);i.sessionId&&i.sessionId!==h&&s(i.sessionId);let a=i.model?.trim();a&&c?.(a),p?.appBuild&&i.apps&&i.apps.length>0&&l?.(i.apps),te();let u=i.result??C.assistantText??``,f=C.pendingApproval,m=i.artifacts??[],g=typeof i.addressEnvelope?.to==`string`?i.addressEnvelope.to:null;if(!i.messageRole)throw Error(`Gateway chat result is missing messageRole.`);let v=i.messageRole,y=v===`command`&&u.trim().length===0&&m.length===0,x=i.outputPresentation?.visible===!1&&m.length===0&&!f,w=(t,r,a)=>({...a,id:t,role:v,content:u,sessionId:r,messageId:i.assistantMessageId??null,artifacts:m,assistantPresentation:i.assistantPresentation??null,pendingApproval:f,responseRating:null,replayRequest:{content:e,media:n}});_(e=>{let t=re(e).filter(e=>e.id!==ee),n=t.some(e=>e.id===S),r=e=>e.id===S?w(S,i.sessionId??e.sessionId,e):b&&e.id===b&&e.role===`user`?{...e,addressedAgentPresentation:g?i.assistantPresentation??null:null,messageId:e.messageId??i.userMessageId??null,sessionId:i.sessionId??e.sessionId}:e;if(y||x)return t.filter(e=>e.id!==S).map(r);let a=t.map(r);return n?a:[...a,w(S,i.sessionId??C.sessionId)]}),o();let ne=v===`command`&&tn(u)?en(e):null;if(ne){let e=i.sessionId??h,n=H(t,e);d.setQueryData(n,e=>e&&{...e,agentId:ne,bootstrapAutostart:nn(u)?{status:`starting`,fileName:`BOOTSTRAP.md`}:e.bootstrapAutostart}),d.invalidateQueries({queryKey:n,refetchType:`none`}),d.invalidateQueries({queryKey:[`chat-context`,t,e]})}v===`command`&&$t(e)&&d.invalidateQueries({queryKey:[`agents-list`,t]})}catch(e){C.renderFrame&&cancelAnimationFrame(C.renderFrame);let t=M(e);_(e=>{let n=re(e).filter(e=>e.id!==ee);return C.stopping?n:[...n,{id:L(),role:`system`,content:`Error: ${t}`,sessionId:h}]})}finally{f.current=null,v(null),m(!1),g(null)}return!0},[t,r,i,y,s,c,l,u,d,a,o]),stopRequest:(0,z.useCallback)(async()=>{let e=f.current;if(!(!e||e.stopping)){e.stopping=!0;try{await ke(t,e.sessionId,r,[`stop`])}catch(e){a(`Failed to stop: ${M(e)}`)}finally{e.controller.abort()}}},[t,r,a]),isStreaming:p,streamingMsgId:h,activeSessionId:_,isActive:(0,z.useCallback)(()=>f.current!==null,[])}}var an=120,on=220;function sn(){let e=(0,z.useRef)(null),t=(0,z.useRef)(null),n=(0,z.useRef)(null),r=(0,z.useRef)(0),[i,a]=(0,z.useState)(!0),o=(0,z.useRef)(!0),s=(0,z.useRef)(!1),c=(0,z.useCallback)(e=>{o.current!==e&&(o.current=e,a(e))},[]),l=(0,z.useCallback)((e,t)=>{let n=Math.max(0,e.scrollHeight-e.clientHeight),r=Math.max(0,Math.min(t,n));r!==e.scrollTop&&(s.current=!0,e.scrollTop=r)},[]),u=(0,z.useCallback)(()=>{let t=e.current;!t||!o.current||t.scrollHeight<=t.clientHeight||l(t,t.scrollHeight)},[l]),d=(0,z.useCallback)(n=>{if(t.current?.abort(),t.current=null,e.current=n,!n)return;let r=new AbortController;t.current=r,n.addEventListener(`scroll`,()=>{if(s.current){s.current=!1;return}c(n.scrollHeight-n.scrollTop-n.clientHeight<=an)},{passive:!0,signal:r.signal}),u()},[c,u]),f=(0,z.useCallback)(e=>{if(n.current?.disconnect(),n.current=null,!e||typeof ResizeObserver>`u`)return;let t=new ResizeObserver(()=>u());t.observe(e),n.current=t},[u]),p=(0,z.useCallback)(()=>{let t=e.current;if(!t)return;if(r.current&&=(cancelAnimationFrame(r.current),0),c(!0),typeof window<`u`&&typeof window.matchMedia==`function`&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches){l(t,t.scrollHeight);return}let n=t.scrollTop;if(t.scrollHeight-t.clientHeight-n<=0)return;let i=performance.now(),a=()=>{let t=e.current;if(!t){r.current=0;return}let o=Math.min(1,(performance.now()-i)/on),s=1-(1-o)**3;l(t,n+(t.scrollHeight-t.clientHeight-n)*s),r.current=o<1?requestAnimationFrame(a):0};r.current=requestAnimationFrame(a)},[c,l]),m=(0,z.useCallback)(()=>{c(!0);let t=e.current;t&&l(t,t.scrollHeight)},[c,l]);return(0,z.useEffect)(()=>()=>{t.current?.abort(),n.current?.disconnect(),r.current&&cancelAnimationFrame(r.current)},[]),{scrollRef:d,contentRef:f,isPinned:i,jumpToBottom:p,resetToBottom:m}}var cn=[],ln=[],un=5e3,dn=`bootstrap-autostart-thinking`,fn=1500,pn=`Ready to claw through your to-do list?`,mn=/^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$/;function hn(){let e=new URLSearchParams(window.location.search).get(`agent`)?.trim();return e&&mn.test(e)?e:``}function gn(e,t){let n=new Map;if(t.size===0)return n;for(let r of e){let e=r.branchKey;if(!e)continue;let i=t.get(e);if(!i||i.length<2)continue;let a=i.findIndex(e=>e.sessionId===r.sessionId);a<0||n.set(r.id,{current:a+1,total:i.length})}return n}function _n(e,t,n=``,r=`user`){return[`chat-recent`,e,t,n,r]}function vn(e,t){return[`chat-recent`,e,t]}function yn(e,t){return[`chat-context`,e,t]}var bn=`hybridclaw.appBuildSessions`;function xn(){try{let e=localStorage.getItem(bn);return e?new Map(Object.entries(JSON.parse(e))):new Map}catch{return new Map}}function Sn(e){try{localStorage.setItem(bn,JSON.stringify(Object.fromEntries(e)))}catch{}}function Cn(){let e=se(),t=s(),i=n(),o=(0,z.useRef)(C()).current,l=c({strict:!1}),[u]=(0,z.useState)(()=>{let e=l.kind,t=e===`live`?`live`:e===`web`?`web`:void 0;return{prompt:l.prompt??``,autoSend:l.send===`1`,appBuild:l.app===`1`,appCategory:l.category,appKind:t}}),d=(0,z.useRef)(xn()),f=(0,z.useCallback)((e,t)=>{d.current.set(e,t),Sn(d.current)},[]),p=u.autoSend?``:u.prompt,m=(0,z.useMemo)(hn,[]),[v,ee]=(0,z.useState)({message:``,version:0}),x=v.message,w=(0,z.useCallback)(e=>{ee(t=>({message:typeof e==`function`?e(t.message):e,version:t.version+1}))},[]),[te,T]=(0,z.useState)(!1),[D,O]=(0,z.useState)(null),[re,ie]=(0,z.useState)(!1),[k,A]=(0,z.useState)(null),[oe,j]=(0,z.useState)(!1),[le,ue]=(0,z.useState)(m||null),[de,pe]=(0,z.useState)(``),[N,ge]=(0,z.useState)(`user`),[F,I]=(0,z.useState)(null),[ve,be]=(0,z.useState)(``),xe=(0,z.useRef)(null),Ae=Ue(ve,160).trim(),{scrollRef:Fe,contentRef:Re,isPinned:Ve,jumpToBottom:R,resetToBottom:We}=sn(),Ge=(0,z.useRef)(null),Ke=(0,z.useRef)(null);(0,z.useEffect)(()=>{let e=()=>{let e=window.visualViewport?.height??window.innerHeight;!Number.isFinite(e)||e<=0||(document.documentElement.style.setProperty(`--chat-visual-viewport-height`,`${Math.round(e)}px`),document.scrollingElement?.scrollTo({left:0}),document.body.scrollLeft=0,document.documentElement.scrollLeft=0)};return e(),window.addEventListener(`resize`,e),window.addEventListener(`orientationchange`,e),window.visualViewport?.addEventListener(`resize`,e),window.visualViewport?.addEventListener(`scroll`,e),()=>{window.removeEventListener(`resize`,e),window.removeEventListener(`orientationchange`,e),window.visualViewport?.removeEventListener(`resize`,e),window.visualViewport?.removeEventListener(`scroll`,e),document.documentElement.style.removeProperty(`--chat-visual-viewport-height`)}},[]);let{sessionId:B,getSessionId:V,navigateToSession:Ye,switchToSession:Ze,startFreshChat:Qe,ensureSessionForSend:U,handleSessionIdCorrection:$e}=Zt();m&&B&&!xe.current&&(xe.current=B);let et=B&&xe.current===B?m:``,W=(0,z.useCallback)(()=>{i.invalidateQueries({queryKey:vn(e.token,o)}),i.invalidateQueries({queryKey:H(e.token,V()),refetchType:`none`})},[i,e.token,o,V]),K=fe(e),tt=b(e.token),q=a({queryKey:[`app-status`,e.token],queryFn:()=>y(e.token),staleTime:1/0,enabled:K,initialData:e.status===`ready`&&e.gatewayStatus?e.gatewayStatus:void 0}),nt=a({queryKey:[`agents-list`,e.token],queryFn:()=>ne(e.token),staleTime:3e4,enabled:K}),rt=a({queryKey:[`models`,e.token],queryFn:()=>we(e.token),staleTime:3e4,enabled:K}),it=a({queryKey:[`skills`,e.token],queryFn:()=>S(e.token),staleTime:6e4,retry:!1,enabled:K});(0,z.useEffect)(()=>{pe(q.data?.defaultModel?.trim()??``)},[B,q.data?.defaultModel]),(0,z.useEffect)(()=>{q.error&&(console.error(`Failed to load gateway status for chat page`,q.error),w(`Failed to load the default agent. New chats will use main until gateway status loads.`))},[q.error,w]),(0,z.useEffect)(()=>{rt.error&&(console.error(`Failed to load models list for chat page`,rt.error),w(`Failed to load the model list. Model switching is unavailable.`))},[rt.error,w]);let at=a({queryKey:_n(e.token,o,Ae,N),queryFn:()=>Ie(e.token,o,`web`,Ae?Pe.maxSearchResults:Pe.maxRecentSessions,Ae||void 0,N),staleTime:1e4,enabled:K}),ot=at.data?.sessions??[],st=(0,z.useMemo)(()=>(nt.data??[]).map(e=>({id:e.id,name:e.name,imageUrl:e.imageUrl??null,emptyChatHeader:e.emptyChatHeader??null,source:e.source})),[nt.data]),ct=(0,z.useMemo)(()=>new Map((it.data?.skills??[]).filter(e=>e.userInvocable).map(e=>[e.name.toLowerCase(),e.name])),[it.data?.skills]),lt=(0,z.useCallback)(e=>{let t=qe(e);for(let e of t){let t=st.find(t=>t.id.toLowerCase()===e.agentId.toLowerCase());if(t)return{agentId:t.id,displayName:t.name??t.id,imageUrl:t.imageUrl??null}}return null},[st]),ut=rt.data?.models??ln,[J,dt]=(0,z.useState)(null),Y=rn({token:e.token,userId:o,getSessionId:V,setError:w,refreshRecent:W,onSessionIdCorrection:$e,onModelResolved:pe,onAppsCaptured:e=>dt(e[e.length-1]??null),resolveAddressedAgentPresentation:lt});(0,z.useEffect)(()=>{let e=v.message;if(T(!1),!e)return;let t=window.setTimeout(()=>{T(!0)},un),n=window.setTimeout(()=>{w(``),T(!1)},5200);return()=>{window.clearTimeout(t),window.clearTimeout(n)}},[v,w]);let X=a({queryKey:H(e.token,B),queryFn:()=>Xe(e.token,B,o,et||void 0),enabled:K&&!!B,staleTime:1/0}),Z=a({queryKey:yn(e.token,B),queryFn:()=>je(e.token,B),enabled:K&&!!B,staleTime:15e3,refetchOnWindowFocus:!1}),pt=X.data?.messages??cn,mt=X.data?.bootstrapAutostart?.status===`starting`,Q=(0,z.useMemo)(()=>mt?[...pt,{id:dn,role:`thinking`,content:``,sessionId:B}]:pt,[mt,pt,B]),ht=X.data?.branchFamilies??Je,gt=le?.trim().toLowerCase()||X.data?.agentId?.trim().toLowerCase()||q.data?.defaultAgentId?.trim().toLowerCase()||`main`,vt=st.find(e=>e.id.toLowerCase()===gt)?.emptyChatHeader?.trim()||pn,$=r({mutationFn:t=>Se(e.token,t),onSuccess:t=>{if(!t.deleted){w(`Delete failed: session was not found.`);return}let n=t.sessionId;i.removeQueries({queryKey:H(e.token,n)}),i.removeQueries({queryKey:yn(e.token,n)}),i.invalidateQueries({queryKey:vn(e.token,o)}),i.invalidateQueries({queryKey:[`overview`],refetchType:`none`}),I(null),n===V()&&Qe({replace:!0})},onError:e=>{w(`Delete failed: ${M(e)}`)}}),yt=r({mutationFn:t=>{if(!t.message.messageId)throw Error(`This response cannot be rated right now.`);return Ne(e.token,{sessionId:t.message.sessionId,messageId:t.message.messageId,userId:o,rating:t.rating})},onSuccess:(t,n)=>{let r=n.message.sessionId;i.setQueryData(H(e.token,r),e=>e&&{...e,messages:e.messages.map(e=>e.messageId===t.messageId?{...e,responseRating:t.rating}:e)})},onError:e=>{w(`Rating failed: ${M(e)}`)}});(0,z.useEffect)(()=>{let e=Z.data?.snapshot?.model?.trim()??``;e&&pe(e)},[Z.data?.snapshot?.model]),(0,z.useEffect)(()=>{if(m&&xe.current===B){ue(m);return}ue(null)},[m,B]),(0,z.useEffect)(()=>{X.error&&w(M(X.error))},[X.error,w]),(0,z.useEffect)(()=>{if(X.data?.bootstrapAutostart?.status!==`starting`||X.isFetching)return;let e=window.setTimeout(()=>{X.refetch()},fn);return()=>window.clearTimeout(e)},[X.data?.bootstrapAutostart?.status,X.isFetching,X.refetch]),(0,z.useEffect)(()=>{if(!k)return;let e=document.body.style.overflow,t=document.activeElement;document.body.style.overflow=`hidden`,Ke.current?.focus();let n=e=>{if(e.key===`Escape`){e.preventDefault(),A(null);return}if(e.key!==`Tab`)return;let t=Array.from(Ge.current?.querySelectorAll(`a[href], button:not(:disabled)`)??[]);if(t.length===0)return;let n=t[0],r=t[t.length-1];e.shiftKey&&document.activeElement===n?(e.preventDefault(),r?.focus()):!e.shiftKey&&document.activeElement===r&&(e.preventDefault(),n?.focus())};return document.addEventListener(`keydown`,n),()=>{document.removeEventListener(`keydown`,n),document.body.style.overflow=e,t instanceof HTMLElement&&t.focus()}},[k]),(0,z.useEffect)(()=>{if(X.isPending||X.fetchStatus!==`idle`||X.data?.requestedSessionId!==B)return;let e=X.data?.resolvedSessionId;!e||e===B||Ye(e,{replace:!0})},[X.data?.requestedSessionId,X.data?.resolvedSessionId,X.fetchStatus,X.isPending,B,Ye]);let bt=(0,z.useMemo)(()=>gn(pt,ht),[pt,ht]),xt=(0,z.useRef)(!1);(0,z.useEffect)(()=>{xt.current&&!Y.isStreaming&&B&&i.invalidateQueries({queryKey:yn(e.token,B)}),xt.current=Y.isStreaming},[Y.isStreaming,i,e.token,B]),(0,z.useEffect)(()=>{B&&We()},[B,We]);let St=(0,z.useCallback)(async(t,n)=>{if(!t.messageId||!t.sessionId){w(`This message cannot be edited right now.`);return}O(null);try{let r=await Le(e.token,t.sessionId,t.messageId);i.invalidateQueries({queryKey:H(e.token,t.sessionId),refetchType:`none`}),await i.ensureQueryData({queryKey:H(e.token,r.sessionId),queryFn:()=>Xe(e.token,r.sessionId,o)}),await Ze(r.sessionId),Y.sendMessage(n,t.media??[])}catch(e){w(M(e))}},[e.token,i,w,Ze,Y.sendMessage,o]),Ct=(0,z.useCallback)(e=>{e.replayRequest&&(R(),Y.sendMessage(e.replayRequest.content,e.replayRequest.media,{hideUser:!0}))},[R,Y.sendMessage]),wt=(0,z.useCallback)(async(e,t)=>{let n=Te(e,t);if(n){ie(!0);try{R(),await Y.sendMessage(n,[],{hideUser:!0})}finally{ie(!1)}}},[R,Y.sendMessage]),Tt=(0,z.useCallback)((e,t)=>{yt.mutate({message:e,rating:t})},[yt]),Et=(0,z.useCallback)(async t=>{let n=await Promise.allSettled(t.map(t=>Me(e.token,t))),r=[];for(let e of n)e.status===`fulfilled`&&e.value.media?r.push(e.value.media):e.status===`rejected`&&w(M(e.reason));return r},[e.token,w]),Dt=(0,z.useCallback)(t=>{De(e.token,{channelId:`web`,keepSessionId:t}).then(t=>{if(t.deletedCount!==0){for(let n of t.deletedSessionIds)i.removeQueries({queryKey:H(e.token,n)}),i.removeQueries({queryKey:yn(e.token,n)});i.invalidateQueries({queryKey:vn(e.token,o)}),i.invalidateQueries({queryKey:[`overview`],refetchType:`none`})}}).catch(e=>{console.warn(`Failed to clean up no-user chat session`,e)})},[e.token,i,o]),Ot=(0,z.useCallback)(()=>{if(Y.isActive()){w(`Stop the current run before starting a new chat.`);return}Dt(Qe()),W()},[Y.isActive,Qe,Dt,W,w]),kt=(0,z.useCallback)((e,n)=>{let r=/^\/apps?\b[ \t]*([\s\S]*)$/i.exec(e.trim());if(r&&n.length===0){let e=r[1].trim();if(!e){t({to:`/apps`});return}f(U(),{kind:`web`}),R(),Y.sendMessage(Ee(null,e),[],{appBuild:!0,appKind:`web`});return}let i=U();R();let a=d.current.get(i);if(a){Y.sendMessage(e,n,{appBuild:!0,...a.category?{appCategory:a.category}:{},...a.kind?{appKind:a.kind}:{}});return}Y.sendMessage(e,n)},[U,R,t,f,Y.sendMessage]),At=(0,z.useRef)(!1);(0,z.useEffect)(()=>{if(At.current||!u.autoSend)return;let e=u.prompt.trim();e&&K&&X.isFetched&&(At.current=!0,window.history.replaceState(null,``,window.location.pathname),u.appBuild&&f(U(),{category:u.appCategory,kind:u.appKind}),kt(e,[]))},[u,K,X.isFetched,U,f,kt]);let jt=(0,z.useCallback)((t,n)=>{let r=n.trim();r&&i.setQueryData(H(e.token,t),e=>{let n=e?.messages??[];return n.some(e=>e.role===`command`&&(e.rawContent||e.content).trim()===r)?e:{messages:[...n,{id:L(),role:`command`,content:r,rawContent:r,sessionId:t,artifacts:[],replayRequest:null}],branchFamilies:e?.branchFamilies??new Map,requestedSessionId:e?.requestedSessionId??t,resolvedSessionId:t,agentId:e?.agentId??null,bootstrapAutostart:e?.bootstrapAutostart??null}})},[e.token,i]),Mt=(0,z.useCallback)(async t=>{let n=H(e.token,t);return i.fetchQuery({queryKey:n,queryFn:()=>Xe(e.token,t,o),staleTime:0}).catch(e=>(console.warn(`Failed to prefetch chat history before appending switch result`,e),null))},[e.token,i,o]),Nt=(0,z.useCallback)(async(t,n,r,a)=>{if(!n||/\s/.test(n))return;if(Y.isActive()){w(a);return}U();let s=V();try{let a=await ke(e.token,s,o,[...t,n]),c=a.sessionId?.trim()||s,l=await Mt(c);jt(c,a.text),c!==s&&await Ze(c,{replace:!0}),i.invalidateQueries({queryKey:yn(e.token,c)}),t[0]===`agent`&&t[1]===`switch`&&l?.bootstrapAutostart?.fileName===`BOOTSTRAP.md`&&(l.bootstrapAutostart.status===`idle`||l.bootstrapAutostart.status===`starting`)&&(i.setQueryData(H(e.token,c),e=>e&&{...e,bootstrapAutostart:{status:`starting`,fileName:`BOOTSTRAP.md`}}),R()),W(),r(n)}catch(e){w(M(e))}},[jt,e.token,U,Mt,V,R,i,W,w,Y.isActive,Ze,o]),Pt=(0,z.useCallback)(e=>Nt([`agent`,`switch`],e,ue,`Could not switch agent — stop the current run and try again.`),[Nt]),Ft=(0,z.useCallback)(e=>Nt([`model`,`set`],e,pe,`Could not switch model — stop the current run and try again.`),[Nt]),It=(0,z.useCallback)(e=>{if(Y.isActive()){w(`Stop the current run before switching chats.`);return}Ye(e)},[Y.isActive,Ye,w]),Lt=(0,z.useCallback)(e=>Y.activeSessionId===e?(w(`Stop the current run before deleting this chat.`),!1):!$.isPending,[$.isPending,Y.activeSessionId,w]),Rt=(0,z.useCallback)(e=>{Lt(e.sessionId)&&I(e)},[Lt]),zt=(0,z.useCallback)(()=>{if(!F)throw Error(`Delete confirmation is missing a session.`);Lt(F.sessionId)&&$.mutate(F.sessionId)},[Lt,$,F]),Bt=(0,z.useCallback)(t=>{t!==V()&&i.prefetchQuery({queryKey:H(e.token,t),queryFn:()=>Xe(e.token,t,o),staleTime:3e4})},[i,e.token,V,o]),Vt=(0,z.useCallback)(()=>{i.invalidateQueries({queryKey:_n(e.token,o,Ae,N)})},[i,e.token,o,Ae,N]),Ht=(0,z.useCallback)(async()=>{let t=V();if(!t){w(`Open or send a chat before creating a mobile QR code.`);return}j(!0);try{A(await ze(e.token,{userId:o,sessionId:t,baseUrl:window.location.origin}))}catch(e){w(M(e))}finally{j(!1)}},[e.token,V,o,w]),Ut=(0,z.useCallback)(e=>{O(e.id)},[]),Wt=(0,z.useCallback)((e,t)=>{let n=e.branchKey;if(!n)return;let r=ht.get(n);if(!r||r.length<2)return;let i=r.findIndex(t=>t.sessionId===e.sessionId);if(i<0)return;let a=i+t;if(a<0||a>=r.length)return;let o=r[a];o&&It(o.sessionId)},[ht,It]),Gt=Q.length===0,qt=X.isFetching,Jt={sessions:ot,activeSessionId:B,onNewChat:Ot,onOpenSession:It,onHoverSession:Bt,onRequestDeleteSession:Rt,deleteDisabled:$.isPending,isPending:qt,searchQuery:ve,onSearchQueryChange:be,recentScope:N,onRecentScopeChange:ge,isLoading:at.isFetching,onRefreshRecent:Vt};return(0,G.jsx)(h,{children:(0,G.jsxs)(`div`,{className:P.chatPage,"aria-busy":qt,children:[(0,G.jsx)(Be,{...Jt}),(0,G.jsxs)(`div`,{className:P.chatMain,children:[(0,G.jsxs)(`div`,{className:P.chatTopbar,children:[(0,G.jsx)(g,{className:P.chatMobileTrigger}),(0,G.jsx)(_t,{sessionId:B,token:e.token,enabled:K}),(0,G.jsx)(`button`,{type:`button`,className:P.mobileQrButton,onClick:()=>void Ht(),disabled:oe,"aria-label":`Show mobile QR code`,title:`Show mobile QR code`,children:(0,G.jsxs)(`span`,{"aria-hidden":`true`,className:P.mobileQrIcon,children:[(0,G.jsx)(`span`,{}),(0,G.jsx)(`span`,{}),(0,G.jsx)(`span`,{}),(0,G.jsx)(`span`,{})]})}),(0,G.jsx)(_,{items:tt})]}),k?(0,G.jsx)(`div`,{className:P.mobileQrOverlay,children:(0,G.jsxs)(`div`,{ref:Ge,className:P.mobileQrDialog,role:`dialog`,"aria-modal":`true`,"aria-labelledby":`mobile-qr-title`,children:[(0,G.jsxs)(`div`,{className:P.mobileQrHeader,children:[(0,G.jsx)(`h2`,{id:`mobile-qr-title`,children:`Open on mobile`}),(0,G.jsx)(`button`,{ref:Ke,type:`button`,className:P.mobileQrClose,onClick:()=>A(null),"aria-label":`Close mobile QR code`,children:`x`})]}),(0,G.jsx)(`div`,{className:P.mobileQrImage,children:(0,G.jsx)(`img`,{src:`data:image/svg+xml;charset=utf-8,${encodeURIComponent(k.qrSvg)}`,alt:`Mobile session QR code`})}),(0,G.jsx)(`a`,{className:P.mobileQrLink,href:k.launchUrl,children:`Open link`})]})}):null,Gt?(0,G.jsx)(`div`,{className:P.emptyState,children:(0,G.jsx)(`h1`,{className:P.greeting,children:vt})}):(0,G.jsx)(`div`,{className:P.messageArea,ref:Fe,children:(0,G.jsx)(`div`,{className:P.messageList,ref:Re,children:Q.map(t=>D===t.id&&t.role!==`thinking`&&t.role!==`trace`&&t.role!==`draft`?(0,G.jsx)(`div`,{className:P.messageBlock,children:(0,G.jsx)(Xt,{initial:t.rawContent??t.content,onSave:e=>void St(t,e),onCancel:()=>O(null)})},t.id):(0,G.jsx)(Kt,{message:t,token:e.token,isStreaming:t.id===Y.streamingMsgId,onCopy:Ce,onEdit:Ut,onRegenerate:Ct,onRate:Tt,ratingBusy:yt.isPending&&yt.variables?.message.id===t.id,skillInvocationTargets:ct,onApprovalAction:wt,approvalBusy:re,branchInfo:bt.get(t.id)??null,onBranchNav:Wt},t.id))})}),!Gt&&!Ve?(0,G.jsxs)(`button`,{type:`button`,className:P.jumpToLatest,onClick:R,"aria-label":`Jump to latest message`,children:[(0,G.jsx)(`span`,{"aria-hidden":`true`,children:`↓`}),(0,G.jsx)(`span`,{children:`Latest`})]}):null,x?(0,G.jsx)(`div`,{className:`${P.errorBanner} ${te?P.errorBannerExiting:``}`,children:x}):null,(0,G.jsx)(ft,{isStreaming:Y.isStreaming,onSend:kt,onStop:()=>void Y.stopRequest(),onUploadFiles:Et,token:e.token,agents:st,selectedAgentId:gt,onAgentSwitch:e=>void Pt(e),models:ut,selectedModelId:de,onModelSwitch:e=>void Ft(e),initialValue:p})]}),(0,G.jsx)(ae,{open:F!==null,onOpenChange:e=>{!e&&!$.isPending&&I(null)},children:(0,G.jsxs)(me,{size:`sm`,role:`alertdialog`,preventCloseOnOutsideClick:$.isPending,children:[(0,G.jsxs)(E,{children:[(0,G.jsx)(he,{children:`Delete session?`}),(0,G.jsx)(_e,{children:`This permanently removes the conversation and associated session records.`})]}),(0,G.jsxs)(ce,{children:[(0,G.jsx)(ye,{className:`ghost-button`,disabled:$.isPending,children:`Cancel`}),(0,G.jsx)(`button`,{type:`button`,className:`danger-button`,disabled:$.isPending,onClick:zt,children:$.isPending?`Deleting...`:`Delete`})]})]})}),(0,G.jsx)(ae,{open:J!==null,onOpenChange:e=>{e||dt(null)},children:(0,G.jsxs)(me,{className:P.appPreviewDialog,"aria-label":`App preview`,children:[(0,G.jsxs)(`div`,{className:P.appPreviewHeader,children:[(0,G.jsx)(he,{className:P.appPreviewTitle,children:J?.title}),(0,G.jsxs)(`div`,{className:P.appPreviewActions,children:[(0,G.jsx)(`button`,{type:`button`,className:P.appPreviewLink,onClick:()=>{dt(null),t({to:`/apps`})},children:`View in Apps`}),J?(0,G.jsx)(`a`,{className:P.appPreviewLink,href:He(J.id,e.token),target:`_blank`,rel:`noreferrer`,children:`Open in new tab ↗`}):null,(0,G.jsx)(ye,{className:P.appPreviewLink,children:`Close`})]})]}),J?(0,G.jsx)(Oe,{appId:J.id,className:P.appPreviewFrame,title:J.title,token:e.token}):null]})})]})})}export{Cn as ChatPage};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{n as e}from"./rolldown-runtime-Bh1tDfsg.js";import{C as t,o as n}from"./query-o_Dd9s85.js";import{l as r}from"./router-DoNPHesn.js";import{B as i,Ct as a,F as o,G as s,I as c,K as l,R as u,U as ee,V as d,W as f,_t as p,ct as m,ht as h,k as g,r as _,st as v,wt as y,yt as te,z as ne}from"./index-
|
|
1
|
+
import{n as e}from"./rolldown-runtime-Bh1tDfsg.js";import{C as t,o as n}from"./query-o_Dd9s85.js";import{l as r}from"./router-DoNPHesn.js";import{B as i,Ct as a,F as o,G as s,I as c,K as l,R as u,U as ee,V as d,W as f,_t as p,ct as m,ht as h,k as g,r as _,st as v,wt as y,yt as te,z as ne}from"./index-B7ZQvYLH.js";var b=e(t(),1);function x(e,t={}){let n=new URLSearchParams;t.category&&t.category!==`all`&&n.set(`category`,t.category),t.search?.trim()&&n.set(`q`,t.search.trim());let r=n.toString();return y(`/api/apps${r?`?${r}`:``}`,{token:e})}function S(e,t){return y(`/api/apps/${encodeURIComponent(t)}`,{token:e})}function C(e,t){return y(`/api/apps/${encodeURIComponent(t)}`,{token:e,method:`DELETE`})}function w(e,t,n){return y(`/api/apps/${encodeURIComponent(t)}/bridge/tool`,{token:e,method:`POST`,body:n})}function T(e,t){let n=new URLSearchParams({token:t});return`/api/apps/${encodeURIComponent(e)}/view?${n.toString()}`}var E=n();function D(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function O(e){if(!D(e)||e.type!==`hybridclaw:live-app-tool-call`||typeof e.appId!=`string`||typeof e.requestId!=`string`||typeof e.toolName!=`string`)return null;let t=e.arguments;return t!==void 0&&!D(t)?null:{type:`hybridclaw:live-app-tool-call`,appId:e.appId,requestId:e.requestId,toolName:e.toolName,...t===void 0?{}:{arguments:t}}}var k=(0,b.forwardRef)(function(e,t){let n=(0,b.useRef)(null),r=(0,b.useRef)(!1),i=(0,b.useRef)(e.appId);i.current!==e.appId&&(i.current=e.appId,r.current=!1);let a=(0,b.useCallback)(()=>{let t=n.current?.contentWindow;return!t||!r.current?!1:(t.postMessage({type:`hybridclaw:live-app-refresh`,appId:e.appId},`*`),!0)},[e.appId]);return(0,b.useImperativeHandle)(t,()=>({refreshData:a}),[a]),(0,b.useEffect)(()=>{let t=!0,r=(t,r)=>{let i=n.current?.contentWindow;i&&i.postMessage({type:`hybridclaw:live-app-tool-result`,appId:e.appId,requestId:t,...r},`*`)},i=i=>{if(i.source!==n.current?.contentWindow)return;let a=O(i.data);!a||a.appId!==e.appId||w(e.token,e.appId,{toolName:a.toolName,arguments:a.arguments??{}}).then(e=>{t&&r(a.requestId,{ok:!0,payload:e})}).catch(e=>{t&&r(a.requestId,{ok:!1,error:e instanceof Error?e.message:String(e)})})};return window.addEventListener(`message`,i),()=>{t=!1,window.removeEventListener(`message`,i)}},[e.appId,e.token]),(0,b.useEffect)(()=>{!e.refreshNonce||!r.current||a()},[a,e.refreshNonce]),(0,E.jsx)(`iframe`,{ref:n,className:e.className,title:e.title,src:T(e.appId,e.token),sandbox:`allow-scripts allow-forms allow-popups allow-modals allow-downloads allow-popups-to-escape-sandbox`,onLoad:()=>{r.current=!0,e.refreshNonce&&a()}},e.appId)}),A=`
|
|
2
2
|
|
|
3
3
|
<<<APP_BUILD_DIRECTIVE>>>
|
|
4
4
|
`;function j(e){let t=e.indexOf(A);return t===-1?e:e.slice(0,t).trimEnd()}var M='Build one self-contained, fully client-side HTML file (no backend), and save it into the workspace `apps/` folder (e.g. apps/<short-name>.html). Default to React via CDN — load React, ReactDOM, and Babel standalone from a CDN and put your JSX in an inline <script type="text/babel"> so it stays a single HTML file. Use a different stack only if I ask. Design it with care — if you have a frontend-design skill, use it; otherwise apply strong fundamentals (clear layout, sensible typography, responsive, accessible, modern). When you finish, the app is automatically published to my Apps gallery and opened as a preview with its own link — no external hosting needed, so just build it.',N='For live refresh inside the Apps viewer, never call `/api/mcp/...` or other gateway URLs directly. Generated HTML runs in a sandbox and must use `window.hybridclaw.callMcpTool("<namespaced_mcp_tool>", { ... })` (or `window.hybridclaw.callTool`) from its refresh action. Register the same refresh function with `window.hybridclaw.setRefreshHandler(refresh)` when that API exists, so the Apps viewer Refresh button updates data in place instead of rebuilding the app. Keep an embedded snapshot fallback so the app still works outside the Apps viewer or when the bridge is unavailable.';function P(e,t){return`${e}${A}${t.join(`
|