feat(webui): scope cookies to the instance and show non-default instance names

This commit is contained in:
sam committed 2026-10-19 10:17:05 +11:00
1 parent ce0d50a451
commit fb1099c973
14 files changed
+89 -53

No files matched your search

+1
View File
@@ -65,6 +65,7 @@ func compose(ctx context.Context, d deps) *webui.Server {
ControlPlane: d.ControlPlane,
Identities: d.Identities,
Issuer: strings.TrimSpace(d.Options.OidcIssuer),
Instance: d.Options.instance,
}
if subjects, ok := d.Identities.(identity.SubjectBinding); ok {
srv.Subjects = subjects
+6
View File
@@ -26,8 +26,12 @@ func Resolve(o Options, log *slog.Logger) (Options, error) {
if found {
o = merge(o, cfg)
tls = cfg.tls
o.instance = cfg.instance
}
}
if o.instance == "" {
o.instance = configuration.InstanceName()
}
o = withDefaults(o)
id, err := rpctls.Load(tls.CAFile, tls.CertDir, presence.UI)
if err != nil {
@@ -66,6 +70,7 @@ type projection struct {
daemon ServiceTarget
tls config.TLS
capture CaptureOptions
instance string
}
func project(cfg config.Config) projection {
@@ -78,6 +83,7 @@ func project(cfg config.Config) projection {
harness: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameHarness).Target},
daemon: ServiceTarget{Target: cfg.Services.Get(config.ServiceNameDaemon).Target},
tls: cfg.TLS,
instance: cfg.Instance,
capture: CaptureOptions{
Retention: cfg.Capture.Retention.Std(),
MaxEvents: cfg.Capture.MaxEvents,
+3
View File
@@ -79,6 +79,9 @@ type Options struct {
// identity is this process's certificate, loaded by Resolve from
// [tls]; nil is plaintext, loopback only.
identity *rpctls.Identity
// instance is the deployment name, from the configuration source or
// ARCHIE_INSTANCE.
instance string
}
// CaptureOptions carries the [capture] settings the capture receiver needs.
+10 -12
View File
@@ -15,8 +15,6 @@ import (
"github.com/samcharles93/archie-core/internal/ratelimit"
)
const accountCookie = "archie_session"
func (s *Server) registerAccountRoutes(public, protected *http.ServeMux) {
if s.Accounts == nil {
return
@@ -38,7 +36,7 @@ func (s *Server) registerAccountRoutes(public, protected *http.ServeMux) {
}
func (s *Server) accountIdentity(r *http.Request) (identity.Identity, error) {
if c, err := r.Cookie(accountCookie); err == nil {
if c, err := r.Cookie(s.cookies().account); err == nil {
value, err := s.Accounts.ResolveAccountSession(r.Context(), c.Value)
if err != nil {
return identity.Identity{}, err
@@ -51,7 +49,7 @@ func (s *Server) accountIdentity(r *http.Request) (identity.Identity, error) {
if s.Authenticate != nil && strings.HasPrefix(r.Header.Get("Authorization"), "Bearer ") {
return s.Authenticate(r.Context(), strings.TrimPrefix(r.Header.Get("Authorization"), "Bearer "))
}
if cookie, err := r.Cookie(providerTokenCookie); err == nil {
if cookie, err := r.Cookie(s.cookies().providerToken); err == nil {
return s.authenticateBrowser(r.Context(), cookie.Value)
}
@@ -100,7 +98,7 @@ func (s *Server) handleAccountStatus(w http.ResponseWriter, r *http.Request) {
oidcEnabled = settings.OIDCIssuer != ""
}
}
writeJSON(w, map[string]any{"setup_required": required, "user": user, "oidc": oidcEnabled, "public_url": publicURL})
writeJSON(w, map[string]any{"setup_required": required, "user": user, "oidc": oidcEnabled, "public_url": publicURL, "instance": s.Instance})
}
func decodeAccountRequest(w http.ResponseWriter, r *http.Request, value any) bool {
@@ -157,7 +155,7 @@ func (s *Server) signInAccount(w http.ResponseWriter, r *http.Request, email, pa
func (s *Server) setAccountCookie(w http.ResponseWriter, r *http.Request, value identity.AccountSession) {
scheme, _ := s.expectedOrigin(r)
http.SetCookie(w, &http.Cookie{Name: accountCookie, Value: value.Token, Path: "/", HttpOnly: true, Secure: scheme == "https", SameSite: http.SameSiteStrictMode, Expires: value.Expires, MaxAge: int(time.Until(value.Expires).Seconds())})
http.SetCookie(w, &http.Cookie{Name: s.cookies().account, Value: value.Token, Path: "/", HttpOnly: true, Secure: scheme == "https", SameSite: http.SameSiteStrictMode, Expires: value.Expires, MaxAge: int(time.Until(value.Expires).Seconds())})
w.Header().Set("Cache-Control", "no-store")
}
@@ -165,13 +163,13 @@ func (s *Server) handleAccountLogout(w http.ResponseWriter, r *http.Request) {
if !s.authorizeAuthenticationMutation(w, r) {
return
}
if c, err := r.Cookie(accountCookie); err == nil {
if c, err := r.Cookie(s.cookies().account); err == nil {
if err = s.Accounts.SignOutAccount(r.Context(), c.Value); err != nil {
s.writeAccountError(w, err)
return
}
}
for _, name := range []string{accountCookie, providerTokenCookie} {
for _, name := range []string{s.cookies().account, s.cookies().providerToken} {
http.SetCookie(w, &http.Cookie{Name: name, Path: "/", HttpOnly: true, MaxAge: -1, SameSite: http.SameSiteStrictMode})
}
w.WriteHeader(http.StatusNoContent)
@@ -212,7 +210,7 @@ func (s *Server) handleAccountPassword(w http.ResponseWriter, r *http.Request) {
s.writeAccountError(w, err)
return
}
http.SetCookie(w, &http.Cookie{Name: accountCookie, Path: "/", MaxAge: -1, HttpOnly: true, SameSite: http.SameSiteStrictMode})
http.SetCookie(w, &http.Cookie{Name: s.cookies().account, Path: "/", MaxAge: -1, HttpOnly: true, SameSite: http.SameSiteStrictMode})
w.WriteHeader(http.StatusNoContent)
}
@@ -301,7 +299,7 @@ func (s *Server) requireFreshAccount(w http.ResponseWriter, r *http.Request) boo
http.Error(w, "account security unavailable", http.StatusServiceUnavailable)
return false
}
cookie, err := r.Cookie(accountCookie)
cookie, err := r.Cookie(s.cookies().account)
if err == nil {
err = store.RequireFreshAccountSession(r.Context(), cookie.Value)
}
@@ -355,7 +353,7 @@ func (s *Server) handleAccountRecover(w http.ResponseWriter, r *http.Request) {
}
func (s *Server) clearProviderCookie(w http.ResponseWriter) {
http.SetCookie(w, &http.Cookie{Name: providerTokenCookie, Path: "/", HttpOnly: true, SameSite: http.SameSiteStrictMode, MaxAge: -1})
http.SetCookie(w, &http.Cookie{Name: s.cookies().providerToken, Path: "/", HttpOnly: true, SameSite: http.SameSiteStrictMode, MaxAge: -1})
}
func (s *Server) authorizeAuthenticationMutation(w http.ResponseWriter, r *http.Request) bool {
@@ -388,7 +386,7 @@ func (s *Server) authorizeAuthenticationMutation(w http.ResponseWriter, r *http.
}
func (s *Server) verifyAccountProvider(r *http.Request, value identity.Identity) error {
cookie, err := r.Cookie(providerTokenCookie)
cookie, err := r.Cookie(s.cookies().providerToken)
if errors.Is(err, http.ErrNoCookie) {
return nil
}
+2 -2
View File
@@ -73,7 +73,7 @@ func TestAccountBoundary(t *testing.T) {
req.Header.Set("Content-Type", "application/json")
req.Header.Set("X-Archie-CSRF", tc.csrf)
if tc.cookie != "" {
req.AddCookie(&http.Cookie{Name: accountCookie, Value: tc.cookie})
req.AddCookie(&http.Cookie{Name: "archie_session", Value: tc.cookie})
}
recorder := httptest.NewRecorder()
srv.Handler().ServeHTTP(recorder, req)
@@ -83,7 +83,7 @@ func TestAccountBoundary(t *testing.T) {
if tc.name == "successful login" {
var found bool
for _, cookie := range recorder.Result().Cookies() {
if cookie.Name == accountCookie {
if cookie.Name == "archie_session" {
found = true
if !cookie.HttpOnly || !cookie.Secure || cookie.SameSite != http.SameSiteStrictMode || cookie.Value != "new-session" {
t.Fatalf("unsafe session cookie: %+v", cookie)
+13 -25
View File
@@ -17,20 +17,8 @@ import (
"github.com/samcharles93/archie-core/internal/domain/identity"
)
// tokenCookie carries the dashboard token once it has been exchanged from the
// URL, so the token is not left sitting in browser history or referrers.
const (
tokenCookie = "archie_ui"
// providerTokenCookie holds the provider's own access token after a browser
// sign-in. It is not a session archie issued: the token belongs to the
// provider and is verified on every request exactly as a presented header is,
// so nothing archie stores can outlive the provider's decision.
providerTokenCookie = "archie_provider_token"
// The sign-in flow's state and PKCE verifier live in short-lived cookies for
// the duration of the redirect, scoped to the callback path.
loginStateCookie = "archie_login_state"
loginVerifierCookie = "archie_login_verifier"
loginCookieMaxAge = 600
loginCookieMaxAge = 600
// loginPath is where a browser signs in, and the path a refused browser is
// sent to. loginCallbackPath must match the redirect URI registered at the
// provider: the provider returns the browser to the path it was given.
@@ -98,7 +86,7 @@ func (s *Server) requireToken(h http.Handler) http.Handler {
return
}
http.SetCookie(w, &http.Cookie{
Name: tokenCookie,
Name: s.cookies().token,
Value: tok,
Path: "/",
HttpOnly: true,
@@ -113,7 +101,7 @@ func (s *Server) requireToken(h http.Handler) http.Handler {
return
}
if c, err := r.Cookie(tokenCookie); err == nil && tokenEqual(c.Value, s.Token) {
if c, err := r.Cookie(s.cookies().token); err == nil && tokenEqual(c.Value, s.Token) {
h.ServeHTTP(w, r)
return
}
@@ -137,7 +125,7 @@ func (s *Server) requireToken(h http.Handler) http.Handler {
// identity it resolves to.
func (s *Server) requireIdentity(h http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
credential, ok := bearerCredential(r)
credential, ok := s.bearerCredential(r)
if !ok {
s.refuseUnidentified(w, r, identity.ErrNoCredential)
return
@@ -152,7 +140,7 @@ func (s *Server) requireIdentity(h http.Handler) http.Handler {
}
// bearerCredential returns the request's bearer token or provider cookie.
func bearerCredential(r *http.Request) (string, bool) {
func (s *Server) bearerCredential(r *http.Request) (string, bool) {
const prefix = "Bearer "
header := r.Header.Get("Authorization")
if len(header) > len(prefix) && strings.EqualFold(header[:len(prefix)], prefix) {
@@ -160,7 +148,7 @@ func bearerCredential(r *http.Request) (string, bool) {
return token, true
}
}
if c, err := r.Cookie(providerTokenCookie); err == nil && strings.TrimSpace(c.Value) != "" {
if c, err := r.Cookie(s.cookies().providerToken); err == nil && strings.TrimSpace(c.Value) != "" {
return c.Value, true
}
return "", false
@@ -184,8 +172,8 @@ func (s *Server) handleLogin(w http.ResponseWriter, r *http.Request) {
s.refuseUnidentified(w, r, err)
return
}
setFlowCookie(w, r, loginStateCookie, state)
setFlowCookie(w, r, loginVerifierCookie, verifier)
setFlowCookie(w, r, s.cookies().loginState, state)
setFlowCookie(w, r, s.cookies().loginVerifier, verifier)
http.Redirect(w, r, url, http.StatusSeeOther)
}
@@ -203,12 +191,12 @@ func (s *Server) handleCallback(w http.ResponseWriter, r *http.Request) {
s.refuseUnidentified(w, r, fmt.Errorf("%w: provider returned %s", identity.ErrCredentialRejected, providerErr))
return
}
state, stateErr := r.Cookie(loginStateCookie)
state, stateErr := r.Cookie(s.cookies().loginState)
if stateErr != nil || !tokenEqual(state.Value, query.Get("state")) {
s.refuseUnidentified(w, r, fmt.Errorf("%w: sign-in state did not match", identity.ErrCredentialRejected))
return
}
verifier, verifierErr := r.Cookie(loginVerifierCookie)
verifier, verifierErr := r.Cookie(s.cookies().loginVerifier)
if verifierErr != nil || strings.TrimSpace(verifier.Value) == "" {
s.refuseUnidentified(w, r, fmt.Errorf("%w: sign-in verifier is missing", identity.ErrCredentialRejected))
return
@@ -223,8 +211,8 @@ func (s *Server) handleCallback(w http.ResponseWriter, r *http.Request) {
s.refuseUnidentified(w, r, err)
return
}
clearFlowCookie(w, r, loginStateCookie)
clearFlowCookie(w, r, loginVerifierCookie)
clearFlowCookie(w, r, s.cookies().loginState)
clearFlowCookie(w, r, s.cookies().loginVerifier)
if security, ok := s.Accounts.(identity.AccountSecurity); ok {
principal, resolveErr := s.Principals.PrincipalFor(r.Context(), value.ID)
if resolveErr != nil {
@@ -239,7 +227,7 @@ func (s *Server) handleCallback(w http.ResponseWriter, r *http.Request) {
s.setAccountCookie(w, r, local)
}
http.SetCookie(w, &http.Cookie{
Name: providerTokenCookie, Value: session.Token, Path: "/",
Name: s.cookies().providerToken, Value: session.Token, Path: "/",
HttpOnly: true, SameSite: http.SameSiteStrictMode, Secure: r.TLS != nil,
})
http.Redirect(w, r, "/", http.StatusSeeOther)
@@ -149,7 +149,7 @@ func TestHTTPPolicyCannotBeBypassed(t *testing.T) {
req.Header.Set("X-Archie-CSRF", "1")
want := http.StatusUnauthorized
if signedIn {
req.AddCookie(&http.Cookie{Name: accountCookie, Value: "valid"})
req.AddCookie(&http.Cookie{Name: "archie_session", Value: "valid"})
want = http.StatusForbidden
}
rec := httptest.NewRecorder()
+28
View File
@@ -0,0 +1,28 @@
package webui
import "strings"
// cookieNames are the dashboard's cookie names. Browsers scope cookies by host
// and ignore the port, so each name carries the instance: two instances on
// one host would otherwise overwrite each other's sessions.
type cookieNames struct {
token, account, providerToken, loginState, loginVerifier, passkeyRegistration, passkeyLogin string
}
func newCookieNames(instance string) cookieNames {
prefix := strings.ReplaceAll(instance, "-", "_")
if prefix == "" {
prefix = "archie"
}
return cookieNames{
token: prefix + "_ui",
account: prefix + "_session",
providerToken: prefix + "_provider_token",
loginState: prefix + "_login_state",
loginVerifier: prefix + "_login_verifier",
passkeyRegistration: prefix + "_passkey_registration",
passkeyLogin: prefix + "_passkey_login",
}
}
func (s *Server) cookies() cookieNames { return newCookieNames(s.Instance) }
+6 -6
View File
@@ -16,11 +16,11 @@ func (s *Server) registerPasskeyRoutes(public, protected *http.ServeMux) {
protected.HandleFunc("DELETE /api/account/passkeys/{id}", s.handlePasskeyDelete)
}
func passkeyCookie(registration bool) string {
func (s *Server) passkeyCookie(registration bool) string {
if registration {
return "archie_passkey_registration"
return s.cookies().passkeyRegistration
}
return "archie_passkey_login"
return s.cookies().passkeyLogin
}
func (s *Server) handlePasskeyBegin(w http.ResponseWriter, r *http.Request, registration bool) {
@@ -41,7 +41,7 @@ func (s *Server) handlePasskeyBegin(w http.ResponseWriter, r *http.Request, regi
return
}
scheme, _ := s.expectedOrigin(r)
http.SetCookie(w, &http.Cookie{Name: passkeyCookie(registration), Value: value.Token, Path: "/api/", HttpOnly: true, Secure: scheme == "https", SameSite: http.SameSiteStrictMode, MaxAge: 300})
http.SetCookie(w, &http.Cookie{Name: s.passkeyCookie(registration), Value: value.Token, Path: "/api/", HttpOnly: true, Secure: scheme == "https", SameSite: http.SameSiteStrictMode, MaxAge: 300})
w.Header().Set("Cache-Control", "no-store")
writeJSON(w, json.RawMessage(value.Options))
}
@@ -58,12 +58,12 @@ func (s *Server) handlePasskeyFinish(w http.ResponseWriter, r *http.Request, reg
http.Error(w, "passkeys unavailable", http.StatusServiceUnavailable)
return
}
cookie, err := r.Cookie(passkeyCookie(registration))
cookie, err := r.Cookie(s.passkeyCookie(registration))
if err != nil {
http.Error(w, "passkey request expired", http.StatusUnauthorized)
return
}
http.SetCookie(w, &http.Cookie{Name: passkeyCookie(registration), Path: "/api/", HttpOnly: true, SameSite: http.SameSiteStrictMode, MaxAge: -1})
http.SetCookie(w, &http.Cookie{Name: s.passkeyCookie(registration), Path: "/api/", HttpOnly: true, SameSite: http.SameSiteStrictMode, MaxAge: -1})
var request struct {
Credential json.RawMessage `json:"credential"`
Name string `json:"name"`
+5
View File
@@ -152,6 +152,11 @@ type Server struct {
Subjects identity.SubjectBinding
Issuer string
// Instance names this deployment among others on the same host. It
// prefixes the cookie names and is shown in the dashboard when it is not
// the default.
Instance string
// Orgs serves the org pages: the caller's org, its workspaces, members and
// agent assignments. Nil answers the org routes Unavailable.
Orgs org.API
+2 -2
View File
@@ -1,5 +1,5 @@
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/css2.js","assets/css.js","assets/html.js","assets/javascript.js","assets/javascript2.js","assets/AccountPage.js","assets/PageHeader.js","assets/createLucideIcon.js","assets/Input.js","assets/AuthenticationPage.js","assets/CredentialBindingsPage.js","assets/PlaybooksPage.js","assets/AgentProfilesPage.js","assets/HarnessPage.js","assets/alert.js","assets/NotFoundPage.js"])))=>i.map(i=>d[i]);
import{A as e,B as t,C as n,D as r,E as i,F as a,G as o,H as s,I as c,L as l,M as u,N as d,O as f,P as p,R as m,S as h,T as g,U as _,V as v,W as y,_ as b,a as x,b as S,c as C,d as w,f as ee,g as T,h as E,i as D,j as O,k as te,l as ne,m as re,n as k,o as ie,p as ae,r as oe,s as se,t as ce,u as le,v as ue,w as de,x as fe,y as pe,z as me}from"./alert.js";import{$t as he,A,B as ge,Bt as _e,C as j,Ct as M,D as ve,Dn as ye,Dt as be,En as xe,G as Se,Gt as N,H as Ce,It as we,Jt as Te,Kt as Ee,Lt as De,M as P,On as Oe,Pt as ke,Q as Ae,Qt as je,Rt as Me,S as F,Sn as Ne,T as Pe,Tt as Fe,U as Ie,Vt as Le,Xt as I,Z as Re,_t as L,an as ze,b as R,bn as Be,cn as Ve,dn as He,dt as Ue,er as z,gn as We,hn as Ge,ht as Ke,ir as B,it as qe,jn as V,k as H,kn as Je,l as U,m as Ye,n as W,nr as Xe,nt as Ze,o as Qe,ot as $e,p as et,pn as tt,r as nt,rr as rt,rt as G,sn as it,st as at,t as ot,tt as st,wn as ct,wt as K,x as q,xn as J,y as Y,yn as lt,yt as ut}from"./PageHeader.js";import{A as dt,C as ft,D as pt,F as mt,M as ht,N as gt,R as _t,a as eee,c as tee,et as vt,i as yt,it as bt,j as X,n as xt,nt as St,o as Ct,r as Z,rt as wt,s as Tt,t as Et,tt as Dt}from"./createLucideIcon.js";import{a as Ot,c as kt,d as nee,f as At,i as ree,l as iee,n as jt,o as aee,r as Mt,s as Nt,t as Q,u as Pt}from"./Input.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var Ft=typeof window<`u`,It,Lt=e=>It=e,Rt=Symbol();function zt(e){return e&&typeof e==`object`&&Object.prototype.toString.call(e)===`[object Object]`&&typeof e.toJSON!=`function`}var Bt=typeof window==`object`&&window.window===window?window:typeof self==`object`&&self.self===self?self:typeof global==`object`&&global.global===global?global:typeof globalThis==`object`?globalThis:{HTMLElement:null};function oee(e,{autoBom:t=!1}={}){return t&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)?new Blob([``,e],{type:e.type}):e}function Vt(e,t,n){let r=new XMLHttpRequest;r.open(`GET`,e),r.responseType=`blob`,r.onload=function(){see(r.response,t,n)},r.onerror=function(){console.error(`could not download file`)},r.send()}function Ht(e){let t=new XMLHttpRequest;t.open(`HEAD`,e,!1);try{t.send()}catch{}return t.status>=200&&t.status<=299}function Ut(e){try{e.dispatchEvent(new MouseEvent(`click`))}catch{let t=new MouseEvent(`click`,{bubbles:!0,cancelable:!0,view:window,detail:0,screenX:80,screenY:20,clientX:80,clientY:20,ctrlKey:!1,altKey:!1,shiftKey:!1,metaKey:!1,button:0,relatedTarget:null});e.dispatchEvent(t)}}var Wt=typeof navigator==`object`?navigator:{userAgent:``},Gt=/Macintosh/.test(Wt.userAgent)&&/AppleWebKit/.test(Wt.userAgent)&&!/Safari/.test(Wt.userAgent),see=Ft?typeof HTMLAnchorElement<`u`&&`download`in HTMLAnchorElement.prototype&&!Gt?cee:`msSaveOrOpenBlob`in Wt?lee:uee:()=>{};function cee(e,t=`download`,n){let r=document.createElement(`a`);r.download=t,r.rel=`noopener`,typeof e==`string`?(r.href=e,r.origin===location.origin?Ut(r):Ht(r.href)?Vt(e,t,n):(r.target=`_blank`,Ut(r))):(r.href=URL.createObjectURL(e),setTimeout(function(){URL.revokeObjectURL(r.href)},4e4),setTimeout(function(){Ut(r)},0))}function lee(e,t=`download`,n){if(typeof e==`string`){if(Ht(e))Vt(e,t,n);else{let t=document.createElement(`a`);t.href=e,t.target=`_blank`,setTimeout(function(){Ut(t)})}}else navigator.msSaveOrOpenBlob(oee(e,n),t)}function uee(e,t,n,r){if(r||=open(``,`_blank`),r&&(r.document.title=r.document.body.innerText=`downloading...`),typeof e==`string`)return Vt(e,t,n);let i=e.type===`application/octet-stream`,a=/constructor/i.test(String(Bt.HTMLElement))||`safari`in Bt,o=/CriOS\/[\d]+/.test(navigator.userAgent);if((o||i&&a||Gt)&&typeof FileReader<`u`){let t=new FileReader;t.onloadend=function(){let e=t.result;if(typeof e!=`string`)throw r=null,Error(`Wrong reader.result type`);e=o?e:e.replace(/^data:[^;]*;/,`data:attachment/file;`),r?r.location.href=e:location.assign(e),r=null},t.readAsDataURL(e)}else{let t=URL.createObjectURL(e);r?r.location.assign(t):location.href=t,r=null,setTimeout(function(){URL.revokeObjectURL(t)},4e4)}}var{assign:dee}=Object;function Kt(){let e=it(!0),t=e.run(()=>J({})),n=[],r=[],i=Ge({install(e){Lt(i),i._a=e,e.provide(Rt,i),e.config.globalProperties.$pinia=i,r.forEach(e=>n.push(e)),r=[]},use(e){return this._a?n.push(e):r.push(e),this},_p:n,_a:null,_e:e,_s:new Map,state:t});return i}var qt=()=>{};function Jt(e,t,n,r=qt){e.add(t);lLine truncated
import{A as e,B as t,C as n,D as r,E as i,F as a,G as o,H as s,I as c,L as l,M as u,N as d,O as f,P as p,R as m,S as h,T as g,U as _,V as v,W as y,_ as b,a as x,b as S,c as C,d as w,f as ee,g as T,h as E,i as D,j as O,k as te,l as ne,m as re,n as k,o as ie,p as ae,r as oe,s as se,t as ce,u as le,v as ue,w as de,x as fe,y as pe,z as me}from"./alert.js";import{$t as he,A,B as ge,Bt as _e,C as j,Ct as M,D as ve,Dn as ye,Dt as be,En as xe,G as Se,Gt as N,H as Ce,It as we,Jt as Te,Kt as Ee,Lt as De,M as P,On as Oe,Pt as ke,Q as Ae,Qt as je,Rt as Me,S as F,Sn as Ne,T as Pe,Tt as Fe,U as Ie,Vt as Le,Xt as I,Z as Re,_t as L,an as ze,b as R,bn as Be,cn as Ve,dn as He,dt as Ue,er as z,gn as We,hn as Ge,ht as Ke,ir as B,it as qe,jn as V,k as H,kn as Je,l as U,m as Ye,n as W,nr as Xe,nt as Ze,o as Qe,ot as $e,p as et,pn as tt,r as nt,rr as rt,rt as G,sn as it,st as at,t as ot,tt as st,wn as ct,wt as K,x as q,xn as J,y as Y,yn as lt,yt as ut}from"./PageHeader.js";import{A as dt,C as ft,D as pt,F as mt,M as ht,N as gt,R as _t,a as eee,c as tee,et as vt,i as yt,it as bt,j as X,n as xt,nt as St,o as Ct,r as Z,rt as wt,s as Tt,t as Et,tt as Dt}from"./createLucideIcon.js";import{a as Ot,c as kt,d as nee,f as At,i as ree,l as iee,n as jt,o as aee,r as Mt,s as Nt,t as Q,u as Pt}from"./Input.js";(function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var Ft=typeof window<`u`,It,Lt=e=>It=e,Rt=Symbol();function zt(e){return e&&typeof e==`object`&&Object.prototype.toString.call(e)===`[object Object]`&&typeof e.toJSON!=`function`}var Bt=typeof window==`object`&&window.window===window?window:typeof self==`object`&&self.self===self?self:typeof global==`object`&&global.global===global?global:typeof globalThis==`object`?globalThis:{HTMLElement:null};function oee(e,{autoBom:t=!1}={}){return t&&/^\s*(?:text\/\S*|application\/xml|\S*\/\S*\+xml)\s*;.*charset\s*=\s*utf-8/i.test(e.type)?new Blob([``,e],{type:e.type}):e}function Vt(e,t,n){let r=new XMLHttpRequest;r.open(`GET`,e),r.responseType=`blob`,r.onload=function(){see(r.response,t,n)},r.onerror=function(){console.error(`could not download file`)},r.send()}function Ht(e){let t=new XMLHttpRequest;t.open(`HEAD`,e,!1);try{t.send()}catch{}return t.status>=200&&t.status<=299}function Ut(e){try{e.dispatchEvent(new MouseEvent(`click`))}catch{let t=new MouseEvent(`click`,{bubbles:!0,cancelable:!0,view:window,detail:0,screenX:80,screenY:20,clientX:80,clientY:20,ctrlKey:!1,altKey:!1,shiftKey:!1,metaKey:!1,button:0,relatedTarget:null});e.dispatchEvent(t)}}var Wt=typeof navigator==`object`?navigator:{userAgent:``},Gt=/Macintosh/.test(Wt.userAgent)&&/AppleWebKit/.test(Wt.userAgent)&&!/Safari/.test(Wt.userAgent),see=Ft?typeof HTMLAnchorElement<`u`&&`download`in HTMLAnchorElement.prototype&&!Gt?cee:`msSaveOrOpenBlob`in Wt?lee:uee:()=>{};function cee(e,t=`download`,n){let r=document.createElement(`a`);r.download=t,r.rel=`noopener`,typeof e==`string`?(r.href=e,r.origin===location.origin?Ut(r):Ht(r.href)?Vt(e,t,n):(r.target=`_blank`,Ut(r))):(r.href=URL.createObjectURL(e),setTimeout(function(){URL.revokeObjectURL(r.href)},4e4),setTimeout(function(){Ut(r)},0))}function lee(e,t=`download`,n){if(typeof e==`string`){if(Ht(e))Vt(e,t,n);else{let t=document.createElement(`a`);t.href=e,t.target=`_blank`,setTimeout(function(){Ut(t)})}}else navigator.msSaveOrOpenBlob(oee(e,n),t)}function uee(e,t,n,r){if(r||=open(``,`_blank`),r&&(r.document.title=r.document.body.innerText=`downloading...`),typeof e==`string`)return Vt(e,t,n);let i=e.type===`application/octet-stream`,a=/constructor/i.test(String(Bt.HTMLElement))||`safari`in Bt,o=/CriOS\/[\d]+/.test(navigator.userAgent);if((o||i&&a||Gt)&&typeof FileReader<`u`){let t=new FileReader;t.onloadend=function(){let e=t.result;if(typeof e!=`string`)throw r=null,Error(`Wrong reader.result type`);e=o?e:e.replace(/^data:[^;]*;/,`data:attachment/file;`),r?r.location.href=e:location.assign(e),r=null},t.readAsDataURL(e)}else{let t=URL.createObjectURL(e);r?r.location.assign(t):location.href=t,r=null,setTimeout(function(){URL.revokeObjectURL(t)},4e4)}}var{assign:dee}=Object;function Kt(){let e=it(!0),t=e.run(()=>J({})),n=[],r=[],i=Ge({install(e){Lt(i),i._a=e,e.provide(Rt,i),e.config.globalProperties.$pinia=i,r.forEach(e=>n.push(e)),r=[]},use(e){return this._a?n.push(e):r.push(e),this},_p:n,_a:null,_e:e,_s:new Map,state:t});return i}var qt=()=>{};function Jt(e,t,n,r=qt){e.add(t);lLine truncated
`);p=n.pop()||``;for(let e of n){let t=e.split(`
`).find(e=>e.startsWith(`data: `));if(!t)continue;let n=JSON.parse(t.slice(6));if(n.session_id&&(Nu.value=n.session_id),n.type===`delta`&&(o+=n.text,zu.value=zu.value?{...zu.value,text:o}:null),(n.type===`tool`||n.type===`navigate`)&&(a=[...a,n],zu.value=zu.value?{...zu.value,tools:a}:null),n.type===`ask`&&n.ask&&(clearTimeout(l),zu.value=zu.value?{...zu.value,ask:n.ask}:null),n.type===`done`&&(s=!0,o||=n.text||``),n.type===`error`)throw Error(n.text)}if(t)break}if(!s)throw Error(`chat stream ended before completion`);Pu.value=!i&&n.trim()===`/new`?[]:[...Pu.value,{from:`assistant`,text:o,tool_calls:a}],zu.value=null,Iu.value=`Ready`,await Xu()}catch(e){let t=e;t.name===`AbortError`&&!c?(zu.value={text:`Turn stopped.`,tools:a,isError:!1,turn:r,isRetry:i},Iu.value=`Stopped`):(zu.value={text:`Unable to complete that turn: ${t.message||t}`,tools:a,isError:!0,turn:r?ku(r):void 0,isRetry:i},Iu.value=`Error. Retry available.`)}finally{clearTimeout(l),Au=null,Ju=null,Lu.value=!1,ed.after?.()}}function ane(){Iu.value=`Stopping…`,Nu.value&&Z.chatCancel(Nu.value).catch(()=>{}),Yu()}function one(){Ue(()=>{Xu().catch(e=>{Iu.value=e.message||`Chat unavailable`})}),Ke(()=>{Yu()})}async function ad(e){let t=new Uint8Array(await e.arrayBuffer()),n=``;for(let e=0;e<t.length;e+=32768)n+=String.fromCharCode(...t.subarray(e,e+32768));await id({textOverride:`🎤 Voice message`,voice:{data:btoa(n),mime_type:e.type||`audio/webm`}})}var od={class:`grid gap-3 p-2`},sd={key:0,class:`text-xs text-fg-subtle`},cd=`__default__`,ld=P({__name:`ChatSettings`,setup(e){let t=Y(()=>Vu.value||cd),n=Y(()=>Hu.value||cd);function r(e){return e===cd?``:String(e??``)}return(e,i)=>(L(),j(`div`,od,[V(Iu)===`Ready`?F(``,!0):(L(),j(`span`,sd,B(V(Iu)),1)),(V(Bu).providers||[]).length?(L(),q(V(_u),{key:1,class:`gap-1`},{default:I(()=>[A(V(bu),{class:`text-xs text-fg-muted`},{default:I(()=>[...i[2]||=[H(`Provider`,-1)]]),_:1}),A(V(xu),{"model-value":t.value,"onUpdate:modelValue":i[0]||=e=>V(tne)(r(e))},{default:I(()=>[A(V(Tu),{size:`sm`,class:`w-full`,"aria-label":`Provider`},{default:I(()=>[A(V(Eu))]),_:1}),A(V(Su),null,{default:I(()=>[A(V(Cu),null,{default:I(()=>[A(V(wu),{value:cd},{default:I(()=>[...i[3]||=[H(`Default`,-1)]]),_:1}),(L(!0),j(U,null,M(V(Bu).providers||[],e=>(L(),q(V(wu),{key:e,value:e},{default:I(()=>[H(B(e),1)]),_:2},1032,[`value`]))),128))]),_:1})]),_:1})]),_:1},8,[`model-value`])]),_:1})):F(``,!0),A(V(_u),{class:`gap-1`},{default:I(()=>[A(V(bu),{class:`text-xs text-fg-muted`},{default:I(()=>[...i[4]||=[H(`Model`,-1)]]),_:1}),A(V(xu),{"model-value":n.value,"onUpdate:modelValue":i[1]||=e=>V($u)(r(e))},{default:I(()=>[A(V(Tu),{size:`sm`,class:`w-full`,"aria-label":`Model`},{default:I(()=>[A(V(Eu))]),_:1}),A(V(Su),null,{default:I(()=>[A(V(Cu),null,{default:I(()=>[A(V(wu),{value:cd},{default:I(()=>[...i[5]||=[H(`Default`,-1)]]),_:1}),(L(!0),j(U,null,M(V(Xte),e=>(L(),q(V(wu),{key:e,value:e},{default:I(()=>[H(B(e),1)]),_:2},1032,[`value`]))),128))]),_:1})]),_:1})]),_:1},8,[`model-value`])]),_:1})]))}}),ud=P({__name:`ChatSessionActions`,setup(e){let t=J(!1);Zte(t);function n(e){t.value=!1,Qu(e)}function r(e,n){t.value=!1,ene(e,n)}return(e,i)=>(L(),q(V(mu),{open:t.value,"onUpdate:open":i[5]||=e=>t.value=e},{default:I(()=>[A(V(gu),{"as-child":``},{default:I(()=>[A(V(X),{variant:`ghost`,size:`icon-sm`,class:`flex-none`,"aria-label":`More`,title:`More`},{default:I(()=>[A(V(Nl))]),_:1})]),_:1}),A(V(hu),{align:`end`,class:`grid w-64 gap-0.5 p-1`},{default:I(()=>[V(Nu)?(L(),j(U,{key:0},[A(V(X),{variant:`ghost`,size:`sm`,class:`justify-start`,onClick:i[0]||=e=>n(`/retry`)},{default:I(()=>[A(V(Cte),{"data-icon":`inline-start`}),i[6]||=H(`Retry`,-1)]),_:1}),A(V(X),{variant:`ghost`,size:`sm`,class:`justify-start`,onClick:i[1]||=e=>n(`/undo`)},{default:I(()=>[A(V(lu),{"data-icon":`inline-start`}),i[7]||=H(`Undo`,-1)]),_:1}),A(V(X),{variant:`ghost`,size:`sm`,class:`justify-start`,onClick:i[2]||=e=>r(`/title`,`Session title`)},{default:I(()=>[A(V($l),{"data-icon":`inline-start`}),i[8]||=H(`Rename`,-1)]),_:1}),A(V(X),{variant:`ghost`,size:`sm`,class:`justify-start`,onClick:i[3]||=e=>r(`/branch`,`Branch name (optional)`)},{default:I(()=>[A(V(Vl),{"data-icon":`inline-start`}),i[9]||=H(`Branch`,-1)]),_:1}),A(V(X),{variant:`ghost`,size:`sm`,class:`justify-start`,onClick:i[4]||=e=>n(`/compress --preview`)},{default:I(()=>[A(V(Ote),{"data-icon":`inline-start`}),i[10]||=H(`Preview compression`,-1)]),_:1}),A(V(Pte),{class:`my-1`})],64)):F(``,!0),A(ld)]),_:1})]),_:1},8,[`open`]))}});function dd(e){return e.title||e.branch_name||`Conversation ${e.session_id.slice(0,8)}`}var fd={class:`min-w-0 flex-1`},pd=P({__name:`ChatSessionList`,setup(e){return(e,t)=>(L(),j(`div`,fd,[A(V(xu),{"model-value":V(Nu),disabled:!V(Mu).length,"onUpdate:modelValue":t[0]||=e=>V(Zu)(String(e))},{default:I(()=>[A(V(Tu),{size:`sm`,class:`w-full`,"aria-label":`Conversation`},{default:I(()=>[A(V(Eu),{placeholder:`No conversations yet`})]),_:1}),A(V(Su),null,{default:I(()=>[A(V(Cu),null,{defa Line truncated
@@ -320,4 +320,4 @@ Edge: ${e}`,EDGE_NOT_FOUND:e=>`Edge not found
Edge: ${e}`,USEVUEFLOW_OPTIONS:()=>`The options parameter is deprecated and will be removed in the next major version. Please use the id parameter instead`},y7=class extends Error{constructor(e,...t){super(v7[e]?.call(v7,...t)),this.name=`VueFlowError`,this.code=e,this.args=t}};function b7(e){return`clientX`in e}function xle(e){return`sourceEvent`in e}function x7(e,t){let n=b7(e),r,i;return n?(r=e.clientX,i=e.clientY):`touches`in e&&e.touches.length>0?(r=e.touches[0].clientX,i=e.touches[0].clientY):`changedTouches`in e&&e.changedTouches.length>0?(r=e.changedTouches[0].clientX,i=e.changedTouches[0].clientY):(r=0,i=0),{x:r-(t?.left??0),y:i-(t?.top??0)}}var S7=()=>typeof navigator<`u`&&(navigator==null?void 0:navigator.userAgent)?.indexOf(`Mac`)>=0;function Sle(e){return{width:e.dimensions?.width??e.width??0,height:e.dimensions?.height??e.height??0}}function C7(e,t=[1,1]){return{x:t[0]*Math.round(e.x/t[0]),y:t[1]*Math.round(e.y/t[1])}}var Cle=()=>!0;function w7(e){e?.classList.remove(`valid`,`connecting`,`vue-flow__handle-valid`,`vue-flow__handle-connecting`)}function wle(e,t,n){let r=[],i={x:e.x-n,y:e.y-n,width:n*2,height:n*2};for(let e of t.values())j5(i,A5(e))>0&&r.push(e);return r}var Tle=250;function Ele(e,t,n,r){let i=[],a=1/0,o=wle(e,n,t+Tle);for(let n of o){let o=[...n.handleBounds?.source??[],...n.handleBounds?.target??[]];for(let s of o){if(r.nodeId===s.nodeId&&r.type===s.type&&r.id===s.id)continue;let{x:o,y:c}=h7(n,s,s.position,!0),l=Math.sqrt((o-e.x)**2+(c-e.y)**2);l>t||(l<a?(i=[{...s,x:o,y:c}],a=l):l===a&&i.push({...s,x:o,y:c}))}}if(!i.length)return null;if(i.length>1){let e=r.type===`source`?`target`:`source`;return i.find(t=>t.type===e)??i[0]}return i[0]}function T7(e,{handle:t,connectionMode:n,fromNodeId:r,fromHandleId:i,fromType:a,doc:o,lib:s,flowId:c,isValidConnection:l=Cle},u,d,f,p){let m=a===`target`,h=t?o.querySelector(`.${s}-flow__handle[data-id="${c}-${t?.nodeId}-${t?.id}-${t?.type}"]`):null,{x:g,y:_}=x7(e),v=o.elementFromPoint(g,_),y=v?.classList.contains(`${s}-flow__handle`)?v:h,b={handleDomNode:y,isValid:!1,connection:null,toHandle:null};if(y){let e=E7(void 0,y),t=y.getAttribute(`data-nodeid`),a=y.getAttribute(`data-handleid`),o=y.classList.contains(`connectable`),s=y.classList.contains(`connectableend`);if(!t||!e)return b;let c={source:m?t:r,sourceHandle:m?a:i,target:m?r:t,targetHandle:m?i:a};b.connection=c,b.isValid=o&&s&&(n===b5.Strict?m&&e===`source`||!m&&e===`target`:t!==r||a!==i)&&l(c,{nodes:d,edges:u,sourceNode:f(c.source),targetNode:f(c.target)}),b.toHandle=D7(t,e,a,p,n,!0)}return b}function E7(e,t){return e||(t?.classList.contains(`target`)?`target`:t?.classList.contains(`source`)?`source`:null)}function Dle(e,t){let n=null;return t?n=`valid`:e&&!t&&(n=`invalid`),n}function Ole(e,t){let n=null;return t?n=!0:e&&!t&&(n=!1),n}function D7(e,t,n,r,i,a=!1){let o=r.get(e);if(!o)return null;let s=i===b5.Strict?o.handleBounds?.[t]:[...o.handleBounds?.source??[],...o.handleBounds?.target??[]],c=(n?s?.find(e=>e.id===n):s?.[0])??null;return c&&a?{...c,...h7(o,c,c.position,!0)}:c}var O7={[_5.Left]:_5.Right,[_5.Right]:_5.Left,[_5.Top]:_5.Bottom,[_5.Bottom]:_5.Top},kle=[`production`,`prod`];function k7(e,...t){A7()&&console.warn(`[Vue Flow]: ${e}`,...t)}function A7(){return!kle.includes(`production`)}function j7(e,t,n,r,i){let a=t.querySelectorAll(`.vue-flow__handle.${e}`);return a?.length?Array.from(a).map(t=>{let a=t.getBoundingClientRect();return{id:t.getAttribute(`data-handleid`),type:e,nodeId:i,position:t.getAttribute(`data-handlepos`),x:(a.left-n.left)/r,y:(a.top-n.top)/r,...M5(t)}}):null}function M7(e,t,n,r,i,a=!1,o){i.value=!1,e.selected?(a||e.selected&&t)&&(r([e]),qe(()=>{o.blur()})):n([e])}function N7(e){return V(e)!==void 0}function Ale(e,t,n,r){if(!e||!e.source||!e.target)return n(new y7(_7.EDGE_INVALID,e?.id??`[ID UNKNOWN]`)),!1;let i;return i=I5(e)?e:{...e,id:H5(e)},i=B5(i,void 0,r),!lle(i,t)&&i}function jle(e,t,n,r,i){if(!t.source||!t.target)return i(new y7(_7.EDGE_INVALID,e.id)),!1;if(!n)return i(new y7(_7.EDGE_NOT_FOUND,e.id)),!1;let{id:a,...o}=e;return{...o,id:r?H5(t):a,source:t.source,target:t.target,sourceHandle:t.sourceHandle,targetHandle:t.targetHandle}}function P7(e,t,n){let r={},i=[];for(let a=0;a<e.length;++a){let o=e[a];if(!L5(o)){n(new y7(_7.NODE_INVALID,o?.id));continue}let s=ole(o,t(o.id),o.parentNode);o.parentNode&&(r[o.parentNode]=!0),i[a]=s}for(let e of i){let a=t(e.parentNode)||i.find(t=>t.id===e.parentNode);e.parentNode&&!a&&n(new y7(_7.NODE_MISSING_PARENT,e.id,e.parentNode)),(e.parentNode||r[e.id])&&(r[e.id]&&(e.isParent=!0),a&&(a.isParent=!0))}return i}function F7(e,t,n,r,i,a){let o=i,s=r.get(o)||new Map;r.set(o,s.set(n,t)),o=`${i}-${e}`;let c=r.get(o)||new Map;if(r.set(o,c.set(n,t)),a){o=`${i}-${e}-${a}`;let s=r.get(o)||new Map;r.set(o,s.set(n,t))}}function I7(e,t,n){e.clear();for(let t of n){let{source:n,target:r,sourceHandle:i=null,targetHandle:a=null}=t,o={edgeId:t.id,source:n,target:r,sourceHandle:i,targetHandle:a},s=`${n}-${i}--${r}-${a}`;F7(`sourcLine truncated
`)},B(e.data.summary||e.data.detail),9,yde)):F(``,!0),e.data.when||e.data.retry||e.data.continues?(L(),j(`div`,bde,[e.data.when?(L(),j(`span`,{key:0,class:`flex max-w-full min-w-0 items-center gap-0.5 rounded bg-secondary px-1 font-mono`,title:`Runs only when ${e.data.when}`},[A(V(zl),{class:`size-3 shrink-0`,"aria-hidden":`true`}),R(`span`,Sde,B(e.data.when),1)],8,xde)):F(``,!0),e.data.retry?(L(),j(`span`,{key:1,class:`flex items-center gap-0.5 rounded bg-secondary px-1`,title:`Up to ${e.data.retry} attempts`},[A(V(xte),{class:`size-3`,"aria-hidden":`true`}),H(`×`+B(e.data.retry),1)],8,Cde)):F(``,!0),e.data.continues?(L(),j(`span`,wde,[A(V(kte),{class:`size-3`,"aria-hidden":`true`}),r[10]||=H(`continues`,-1)])):F(``,!0)])):F(``,!0),e.data.run?.error?(L(),j(`p`,{key:4,class:`mt-1 line-clamp-2 text-[11px] text-danger`,title:e.data.run.error},B(e.data.run.error),9,Tde)):F(``,!0)],64))]),A(mt,{"enter-from-class":`opacity-0 -translate-y-1`,"enter-active-class":`transition duration-200`,"leave-to-class":`opacity-0`,"leave-active-class":`transition duration-100`},{default:I(()=>[e.data.expanded?(L(),j(`div`,{key:0,class:`nodrag nopan nowheel cursor-auto border-t border-border`,onClick:r[6]||=bt(()=>{},[`stop`])},[K(t.$slots,`default`)])):F(``,!0)]),_:3}),A(V(Q7),{type:`source`,position:V(_5).Bottom},null,8,[`position`]),A(V(Q7),{id:`data-out`,type:`source`,position:V(_5).Right,class:`!opacity-0`},null,8,[`position`]),e.data.type===`switch`?(L(),q(V(Q7),{key:1,id:`otherwise`,type:`source`,position:V(_5).Right,class:`!opacity-0`},null,8,[`position`])):F(``,!0)],2))}}),Dde={class:`pointer-events-none size-full rounded-xl border border-dashed border-border bg-muted/30`},Ode={class:`flex items-center gap-1 px-2.5 pt-1.5 text-[11px] text-fg-subtle`},kde={key:0},Ade={key:1,class:`font-mono`},jde=P({__name:`LaneNode`,props:{data:{}},setup(e){return(t,n)=>(L(),j(`div`,Dde,[R(`div`,Ode,[e.data.lane===`switch`?(L(),j(U,{key:0},[A(V(au),{class:`size-3`,"aria-hidden":`true`}),e.data.title==="default"?(L(),j(`span`,kde,`otherwise`)):(L(),j(`span`,Ade,`= `+B(e.data.title),1))],64)):(L(),j(U,{key:1},[A(V(Vl),{class:`size-3`,"aria-hidden":`true`}),H(B(e.data.title),1)],64))])]))}}),Mde={class:`flex shrink-0 items-center justify-center gap-1 border-t border-border bg-card p-1`},S9=240,Nde=416,C9=-140,Pde=72,Fde=.9,w9=P({__name:`WorkflowCanvas`,props:{yaml:{},stages:{},open:{},triggers:{},types:{},readonly:{type:Boolean},restartable:{type:Boolean},marks:{},problems:{},title:{},summary:{}},emits:[`toggle`,`insert`,`duplicate`,`move`,`remove`,`rename`,`restart`],setup(e,{emit:t}){let n=e,r=t,i=Y(()=>!!n.types?.length&&!n.readonly),a=Y(()=>[...n.types??[],`parallel`,`switch`]),o=Y(()=>a.value.filter(e=>[`agent.run`,`workflow.call`].includes(e))),s=e=>e&&Y0(e)?o.value:a.value,c=e=>e.kind===`step`?JSON.stringify(e.path??null):e.kind,l=J(null),u=J(null),d=kt(`(max-width: 767px)`),f=Y(()=>{let e=m2(T2(n.yaml),n.stages??[]);return n.types?.length?{nodes:[{id:`workflow`,type:`step`,position:{x:0,y:C9},data:{kind:`workflow`,key:`workflow`,title:n.title||`Workflow`,type:``,detail:n.summary??``}},...e.nodes],edges:[{id:`flow-workflow-start`,source:`workflow`,target:`start`,kind:`flow`},...e.edges]}:e}),p=Y(()=>f.value.nodes.filter(e=>e.data.path?.length===2).length),m=J({}),h=J({}),g=Y(()=>f.value.nodes.find(e=>e.type===`step`&&c(e.data)===n.open));function _(e,t){m.value={...m.value,[e]:t},g.value?.id!==e&&(h.value={...h.value,[e]:t})}let v=Y(()=>{let e=d.value?void 0:g.value?.id;return e&&m.value[e]?Math.max(0,m.value[e]-(h.value[e]??m.value[e])):0}),y=iee(),b=nee(v,{duration:Y(()=>y.value===`reduce`?0:200)}),x=Y(()=>{let e=new Map;for(let t of f.value.nodes){if(t.type!==`step`)continue;let n=(t.id===g.value?.id?h.value[t.id]:void 0)??m.value[t.id];n!==void 0&&e.set(t.position.y,Math.max(e.get(t.position.y)??-72,n-Pde))}return[...e]}),S=e=>x.value.reduce((t,[n,r])=>n<e?t+r:t,0);function C(e){let t=e.data,a=c(t),o=t.path,s={triggers:t.kind===`start`?n.triggers??[]:t.triggers,expanded:!d.value&&a===n.open,editable:i.value,problem:o?n.problems?.[a]:void 0,onResize:t=>_(e.id,t)};return n.types?.length&&(s.onToggle=()=>r(`toggle`,a)),i.value&&o&&(s.onRename=e=>r(`rename`,o,e),s.onDuplicate=()=>r(`duplicate`,o),s.onRemove=()=>r(`remove`,o)),{...e,data:{...t,...s}}}let w=e=>{let t=g.value;return d.value||!t||!e.style?.width?!1:e.position.x<=t.position.x&&e.position.x+parseFloat(String(e.style.width))>=t.position.x+S9};function ee(e){let t=g.value;if(d.value||!t)return 0;if(e.id===t.id||w(e))return-88;let n=t.position.x+S9/2,r=e.style?.width?parseFloat(String(e.style.width)):e.type===`step`?S9:32,i=e.position.x+r/2;return Math.abs(i-n)<S9/2?0:i<n?-88:88}let T=Y(()=>{let e=g.value;return f.value.nodes.map(t=>{let a=t;t.type===`add`?t={...t,data:{...t.data,types:s(t.data.insertAfter),editable:i.value,onInsert:e=>r(`insert`,t.data.insertAfter,e)}}:t.type===`step`&&(t=C(t));let o=n.marks?.[t.id];o&&(t={...t,data:{...t.data,mark:o}});let c=t.position.x Line truncated
`),r=t.split(`
`),i=Array.from({length:n.length+1},()=>Array(r.length+1).fill(0));for(let e=n.length-1;e>=0;e--)for(let t=r.length-1;t>=0;t--)i[e][t]=n[e]===r[t]?i[e+1][t+1]+1:Math.max(i[e+1][t],i[e][t+1]);let a=[],o=0,s=0;for(;o<n.length&&s<r.length;)n[o]===r[s]?(a.push({kind:`same`,text:n[o++]}),s++):i[o+1][s]>=i[o][s+1]?a.push({kind:`del`,text:n[o++]}):a.push({kind:`add`,text:r[s++]});for(;o<n.length;)a.push({kind:`del`,text:n[o++]});for(;s<r.length;)a.push({kind:`add`,text:r[s++]});return a}function T9(e){let t=U0(e).toJS(),n=new Map;for(let r of T2(e).nodes){let{kind:e,path:i,stage:a,occurrence:o}=r.data;if(r.type!==`step`||e!==`step`||!i||a===void 0)continue;let s=t;for(let e of i)s=s?.[e];n.set(`${a}#${o??0}`,{node:r.id,signature:JSON.stringify(s??null)})}return n}function E9(e,t,n){let r=T9(e),i=T9(t),a={};for(let[e,t]of r){let r=i.get(e);r?r.signature!==t.signature&&(a[t.node]=`changed`):a[t.node]=n}return a}var Bde={class:`flex flex-col gap-3 md:grid md:h-[calc(100dvh-17rem)] md:min-h-[26rem] md:grid-cols-[18rem_1fr]`},Vde=[`aria-current`,`onClick`],Hde={class:`flex items-center gap-2 text-sm`},Ude={class:`font-mono text-xs text-fg-subtle`},Wde=[`title`],Gde={key:0,class:`px-3 py-2 text-sm text-fg-muted`},Kde={key:1,class:`flex min-h-0 flex-col gap-2`},qde={class:`flex items-center gap-2 max-md:flex-wrap`},Jde={key:0,class:`rounded-lg border border-border p-4 text-sm text-fg-muted`},Yde={key:1,class:`min-h-0 flex-1 overflow-auto rounded-lg border border-border pt-2 pb-[calc(0.5rem+var(--code-overscroll))] font-mono text-[13px] leading-6`},Xde={class:`inline-block w-4 select-none text-fg-subtle`},Zde={key:2,class:`grid min-h-0 flex-1 gap-3 max-md:flex-none md:grid-cols-2`},Qde={class:`flex min-h-0 flex-col gap-1`},$de={class:`text-xs font-medium text-fg-muted`},efe={class:`min-h-0 flex-1 max-md:h-72 max-md:flex-none`},tfe={class:`flex min-h-0 flex-col gap-1`},nfe={class:`min-h-0 flex-1 max-md:h-72 max-md:flex-none`},rfe=P({__name:`WorkflowHistory`,props:Ze({revisions:{},current:{},error:{}},{selected:{default:0},selectedModifiers:{},mode:{default:`yaml`},modeModifiers:{}}),emits:Ze([`restore`],[`update:selected`,`update:mode`]),setup(e,{emit:t}){let n=e,r=t,i=Me(e,`selected`),a=Me(e,`mode`);N(()=>n.revisions,e=>{e.some(e=>e.version===i.value)||(i.value=(e.find(e=>e.yaml!==n.current)??e[0])?.version??0)},{immediate:!0});let o=Y(()=>n.revisions.find(e=>e.version===i.value)),s=Y(()=>o.value?.yaml??null),c=Y(()=>s.value===null?[]:zde(s.value,n.current)),l=Y(()=>s.value!==null&&s.value===n.current),u=Y(()=>s.value===null?{}:E9(s.value,n.current,`removed`)),d=Y(()=>s.value===null?{}:E9(n.current,s.value,`added`)),f={added:`default`,edited:`secondary`,removed:`destructive`};return(t,n)=>(L(),j(`div`,Bde,[R(`ol`,{class:z(V(W)(`min-h-0 divide-y divide-border overflow-y-auto rounded-lg border border-border`,e.revisions.length&&`max-md:hidden`)),"aria-label":`Revisions`},[(L(!0),j(U,null,M(e.revisions,e=>(L(),j(`li`,{key:e.version},[R(`button`,{type:`button`,class:z([`block w-full px-3 py-2 text-left hover:bg-secondary`,e.version===i.value&&`bg-secondary`]),"aria-current":e.version===i.value,onClick:t=>i.value=e.version},[R(`span`,Hde,[R(`span`,Ude,`v`+B(e.version),1),A(V(D),{variant:f[e.change]},{default:I(()=>[H(B(e.change),1)]),_:2},1032,[`variant`])]),R(`span`,{class:`mt-0.5 block truncate text-xs text-fg-muted`,title:e.at},B(e.actor||`unknown`)+` · `+B(e.source||`unknown`)+` · `+B(V(PC)(e.at)),9,Wde)],10,Vde)]))),128)),e.revisions.length?F(``,!0):(L(),j(`li`,Gde,B(e.error||`No recorded changes`),1))],2),e.revisions.length?(L(),q(V(xu),{key:0,"model-value":String(i.value),"onUpdate:modelValue":n[0]||=e=>i.value=Number(e)},{default:I(()=>[A(V(Tu),{class:`w-full md:hidden`,"aria-label":`Revision`},{default:I(()=>[A(V(Eu))]),_:1}),A(V(Su),null,{default:I(()=>[(L(!0),j(U,null,M(e.revisions,e=>(L(),q(V(wu),{key:e.version,value:String(e.version)},{default:I(()=>[H(`v`+B(e.version)+` · `+B(e.change)+` · `+B(e.actor||`unknown`)+` · `+B(V(PC)(e.at)),1)]),_:2},1032,[`value`]))),128))]),_:1})]),_:1},8,[`model-value`])):F(``,!0),o.value?(L(),j(`div`,Kde,[R(`div`,qde,[A(V(FD),{modelValue:a.value,"onUpdate:modelValue":n[1]||=e=>a.value=e},{default:I(()=>[A(V(LD),null,{default:I(()=>[A(V(RD),{value:`yaml`},{default:I(()=>[...n[3]||=[H(`YAML`,-1)]]),_:1}),A(V(RD),{value:`canvas`},{default:I(()=>[...n[4]||=[H(`Canvas`,-1)]]),_:1})]),_:1})]),_:1},8,[`modelValue`]),A(V(X),{type:`button`,size:`sm`,variant:`outline`,class:`ml-auto`,disabled:s.value===null||l.value,title:s.value===null?`Workflow removed`:void 0,onClick:n[2]||=e=>r(`restore`,s.value)},{default:I(()=>[A(V(nu),{"data-icon":`inline-start`}),n[5]||=H(` Restore this version`,-1)]),_:1},8,[`disabled`,`title`])]),s.value===null?(L(),j(`p`,Jde,`Workflow removed in this revision.`)):a.value===`yaml`?(L(),j(`pre`,Yde,[R(`code`,null,[(L(!0),j(U,null,M(c.value,(e,t)=>(L(),j(`span`,{key:t,class:z([`block min-h-6 px-3 whitespace-pre-wrap`,{"bg-ok/10":e.kind===`add`,"bg-danger/10 text Line truncated
`),i=Array.from({length:n.length+1},()=>Array(r.length+1).fill(0));for(let e=n.length-1;e>=0;e--)for(let t=r.length-1;t>=0;t--)i[e][t]=n[e]===r[t]?i[e+1][t+1]+1:Math.max(i[e+1][t],i[e][t+1]);let a=[],o=0,s=0;for(;o<n.length&&s<r.length;)n[o]===r[s]?(a.push({kind:`same`,text:n[o++]}),s++):i[o+1][s]>=i[o][s+1]?a.push({kind:`del`,text:n[o++]}):a.push({kind:`add`,text:r[s++]});for(;o<n.length;)a.push({kind:`del`,text:n[o++]});for(;s<r.length;)a.push({kind:`add`,text:r[s++]});return a}function T9(e){let t=U0(e).toJS(),n=new Map;for(let r of T2(e).nodes){let{kind:e,path:i,stage:a,occurrence:o}=r.data;if(r.type!==`step`||e!==`step`||!i||a===void 0)continue;let s=t;for(let e of i)s=s?.[e];n.set(`${a}#${o??0}`,{node:r.id,signature:JSON.stringify(s??null)})}return n}function E9(e,t,n){let r=T9(e),i=T9(t),a={};for(let[e,t]of r){let r=i.get(e);r?r.signature!==t.signature&&(a[t.node]=`changed`):a[t.node]=n}return a}var Bde={class:`flex flex-col gap-3 md:grid md:h-[calc(100dvh-17rem)] md:min-h-[26rem] md:grid-cols-[18rem_1fr]`},Vde=[`aria-current`,`onClick`],Hde={class:`flex items-center gap-2 text-sm`},Ude={class:`font-mono text-xs text-fg-subtle`},Wde=[`title`],Gde={key:0,class:`px-3 py-2 text-sm text-fg-muted`},Kde={key:1,class:`flex min-h-0 flex-col gap-2`},qde={class:`flex items-center gap-2 max-md:flex-wrap`},Jde={key:0,class:`rounded-lg border border-border p-4 text-sm text-fg-muted`},Yde={key:1,class:`min-h-0 flex-1 overflow-auto rounded-lg border border-border pt-2 pb-[calc(0.5rem+var(--code-overscroll))] font-mono text-[13px] leading-6`},Xde={class:`inline-block w-4 select-none text-fg-subtle`},Zde={key:2,class:`grid min-h-0 flex-1 gap-3 max-md:flex-none md:grid-cols-2`},Qde={class:`flex min-h-0 flex-col gap-1`},$de={class:`text-xs font-medium text-fg-muted`},efe={class:`min-h-0 flex-1 max-md:h-72 max-md:flex-none`},tfe={class:`flex min-h-0 flex-col gap-1`},nfe={class:`min-h-0 flex-1 max-md:h-72 max-md:flex-none`},rfe=P({__name:`WorkflowHistory`,props:Ze({revisions:{},current:{},error:{}},{selected:{default:0},selectedModifiers:{},mode:{default:`yaml`},modeModifiers:{}}),emits:Ze([`restore`],[`update:selected`,`update:mode`]),setup(e,{emit:t}){let n=e,r=t,i=Me(e,`selected`),a=Me(e,`mode`);N(()=>n.revisions,e=>{e.some(e=>e.version===i.value)||(i.value=(e.find(e=>e.yaml!==n.current)??e[0])?.version??0)},{immediate:!0});let o=Y(()=>n.revisions.find(e=>e.version===i.value)),s=Y(()=>o.value?.yaml??null),c=Y(()=>s.value===null?[]:zde(s.value,n.current)),l=Y(()=>s.value!==null&&s.value===n.current),u=Y(()=>s.value===null?{}:E9(s.value,n.current,`removed`)),d=Y(()=>s.value===null?{}:E9(n.current,s.value,`added`)),f={added:`default`,edited:`secondary`,removed:`destructive`};return(t,n)=>(L(),j(`div`,Bde,[R(`ol`,{class:z(V(W)(`min-h-0 divide-y divide-border overflow-y-auto rounded-lg border border-border`,e.revisions.length&&`max-md:hidden`)),"aria-label":`Revisions`},[(L(!0),j(U,null,M(e.revisions,e=>(L(),j(`li`,{key:e.version},[R(`button`,{type:`button`,class:z([`block w-full px-3 py-2 text-left hover:bg-secondary`,e.version===i.value&&`bg-secondary`]),"aria-current":e.version===i.value,onClick:t=>i.value=e.version},[R(`span`,Hde,[R(`span`,Ude,`v`+B(e.version),1),A(V(D),{variant:f[e.change]},{default:I(()=>[H(B(e.change),1)]),_:2},1032,[`variant`])]),R(`span`,{class:`mt-0.5 block truncate text-xs text-fg-muted`,title:e.at},B(e.actor||`unknown`)+` · `+B(e.source||`unknown`)+` · `+B(V(PC)(e.at)),9,Wde)],10,Vde)]))),128)),e.revisions.length?F(``,!0):(L(),j(`li`,Gde,B(e.error||`No recorded changes`),1))],2),e.revisions.length?(L(),q(V(xu),{key:0,"model-value":String(i.value),"onUpdate:modelValue":n[0]||=e=>i.value=Number(e)},{default:I(()=>[A(V(Tu),{class:`w-full md:hidden`,"aria-label":`Revision`},{default:I(()=>[A(V(Eu))]),_:1}),A(V(Su),null,{default:I(()=>[(L(!0),j(U,null,M(e.revisions,e=>(L(),q(V(wu),{key:e.version,value:String(e.version)},{default:I(()=>[H(`v`+B(e.version)+` · `+B(e.change)+` · `+B(e.actor||`unknown`)+` · `+B(V(PC)(e.at)),1)]),_:2},1032,[`value`]))),128))]),_:1})]),_:1},8,[`model-value`])):F(``,!0),o.value?(L(),j(`div`,Kde,[R(`div`,qde,[A(V(FD),{modelValue:a.value,"onUpdate:modelValue":n[1]||=e=>a.value=e},{default:I(()=>[A(V(LD),null,{default:I(()=>[A(V(RD),{value:`yaml`},{default:I(()=>[...n[3]||=[H(`YAML`,-1)]]),_:1}),A(V(RD),{value:`canvas`},{default:I(()=>[...n[4]||=[H(`Canvas`,-1)]]),_:1})]),_:1})]),_:1},8,[`modelValue`]),A(V(X),{type:`button`,size:`sm`,variant:`outline`,class:`ml-auto`,disabled:s.value===null||l.value,title:s.value===null?`Workflow removed`:void 0,onClick:n[2]||=e=>r(`restore`,s.value)},{default:I(()=>[A(V(nu),{"data-icon":`inline-start`}),n[5]||=H(` Restore this version`,-1)]),_:1},8,[`disabled`,`title`])]),s.value===null?(L(),j(`p`,Jde,`Workflow removed in this revision.`)):a.value===`yaml`?(L(),j(`pre`,Yde,[R(`code`,null,[(L(!0),j(U,null,M(c.value,(e,t)=>(L(),j(`span`,{key:t,class:z([`block min-h-6 px-3 whitespace-pre-wrap`,{"bg-ok/10":e.kind===`add`,"bg-danger/10 text Line truncated
+2 -2
View File
@@ -20,9 +20,9 @@ const route = useRoute();
const workflowsPage = computed(() => route.path === "/workflows");
const hidden = computed(() => hiddenPaths(session.sections));
const main = ref<HTMLElement | null>(null);
watch(() => route.path, () => {
watch(() => [route.path, accounts.instance], () => {
const scope = route.meta.org ? "Organisation" : route.meta.settings ? "Instance" : "";
document.title = [route.meta.label || "Page not found", scope, "Archie"].filter(Boolean).join(" | ");
document.title = [route.meta.label || "Page not found", scope, "Archie", accounts.instance].filter(Boolean).join(" | ");
}, { immediate: true });
watch(() => route.path, async () => {
await nextTick();
+5 -3
View File
@@ -1,15 +1,17 @@
import { defineStore } from "pinia";
import { ref } from "vue";
import { computed, ref } from "vue";
import { api } from "@/lib/api";
export interface AccountUser {id:string;display_name:string;kind:string}
interface AuthStatus {setup_required:boolean;user:AccountUser|null;oidc:boolean;public_url:string}
interface AuthStatus {setup_required:boolean;user:AccountUser|null;oidc:boolean;public_url:string;instance?:string}
export const useAccountsStore=defineStore("accounts",()=>{
const status=ref<AuthStatus|null>(null);
const error=ref("");
async function load():Promise<void>{try{status.value=await api.authStatus<AuthStatus>();error.value=""}catch(cause){error.value=String((cause as Error).message||cause)}}
async function signOut():Promise<void>{await api.signOut();window.location.assign("/")}
return {status,error,load,signOut};
// Empty for the default instance, which needs no label.
const instance=computed(()=>{const name=status.value?.instance||"";return name==="archie"?"":name});
return {status,error,instance,load,signOut};
});
export function passkeysAvailable(publicURL:string):boolean{
+5
View File
@@ -1,6 +1,10 @@
<script setup lang="ts">
import Logo from "./Logo.vue";
import BrandName from "./BrandName.vue";
import { Badge } from "@/components/ui/badge";
import { useAccountsStore } from "@/accounts/accounts";
const accounts = useAccountsStore();
</script>
<template>
@@ -10,5 +14,6 @@ import BrandName from "./BrandName.vue";
>
<Logo />
<BrandName class="hidden sm:inline" />
<Badge v-if="accounts.instance" variant="info">{{ accounts.instance }}</Badge>
</RouterLink>
</template>