rivet-design 0.26.0 → 0.26.1
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/dist/agent-variants/contracts.d.ts +320 -320
- package/dist/agent-variants/workItemInput.d.ts +210 -210
- package/dist/routes/variantRequestSchema.d.ts +4 -4
- package/dist/services/GuidanceVerifierRunner.js +13 -2
- package/dist/storage/library/ProjectPreviewCache.d.ts +2 -2
- package/dist/types/guidance-verifier.d.ts +458 -59
- package/dist/types/guidance-verifier.js +35 -12
- package/dist/utils/skills/cli-guidance.d.ts +1 -1
- package/dist/utils/skills/cli-guidance.js +2 -2
- package/package.json +2 -2
- package/src/ui/dist/assets/{LibraryEntry-CFkd6v_O.js → LibraryEntry-Cr4GFYXW.js} +2 -2
- package/src/ui/dist/assets/{main-B_jie9r3.js → main-tPO1OCpZ.js} +4 -4
- package/src/ui/dist/index.html +1 -1
|
@@ -25,24 +25,47 @@ const JsonValueSchema = zod_1.z.lazy(() => zod_1.z.union([
|
|
|
25
25
|
const CheckValueSchema = JsonValueSchema.refine((value) => value !== undefined &&
|
|
26
26
|
Buffer.byteLength(JSON.stringify(value)) <= VALUE_BYTES, 'Check values must be bounded JSON');
|
|
27
27
|
const CheckTextSchema = zod_1.z.string().trim().min(1).max(CHECK_TEXT_LENGTH);
|
|
28
|
-
|
|
28
|
+
const CheckSchema = zod_1.z
|
|
29
29
|
.object({
|
|
30
|
-
|
|
30
|
+
id: CheckTextSchema,
|
|
31
|
+
priority: zod_1.z.enum(['high', 'medium', 'low']).nullable(),
|
|
32
|
+
currentState: CheckTextSchema,
|
|
33
|
+
proposedFix: CheckTextSchema.nullable(),
|
|
34
|
+
evidence: zod_1.z
|
|
31
35
|
.array(zod_1.z
|
|
32
36
|
.object({
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
path: guidance_references_1.GuidanceReferenceNameSchema,
|
|
38
|
+
mediaType: CheckTextSchema.regex(/^[a-z0-9][a-z0-9!#$&^_.+-]*\/[a-z0-9][a-z0-9!#$&^_.+-]*$/i),
|
|
39
|
+
label: CheckTextSchema,
|
|
40
|
+
role: zod_1.z.enum(['observed', 'reference']),
|
|
41
|
+
})
|
|
42
|
+
.strict())
|
|
43
|
+
.max(CHECK_LIMIT),
|
|
44
|
+
comparison: zod_1.z
|
|
45
|
+
.object({
|
|
38
46
|
expected: CheckValueSchema,
|
|
39
47
|
observed: CheckValueSchema,
|
|
40
|
-
|
|
41
|
-
.array(guidance_references_1.GuidanceReferenceNameSchema)
|
|
42
|
-
.max(CHECK_LIMIT)
|
|
43
|
-
.optional(),
|
|
48
|
+
unit: CheckTextSchema.nullable(),
|
|
44
49
|
})
|
|
45
|
-
.strict()
|
|
50
|
+
.strict()
|
|
51
|
+
.optional(),
|
|
52
|
+
location: CheckTextSchema.optional(),
|
|
53
|
+
})
|
|
54
|
+
.strict();
|
|
55
|
+
exports.GuidanceVerifierResultSchema = zod_1.z
|
|
56
|
+
.object({
|
|
57
|
+
checks: zod_1.z
|
|
58
|
+
.array(zod_1.z.discriminatedUnion('status', [
|
|
59
|
+
CheckSchema.extend({ status: zod_1.z.literal('pass'), problem: zod_1.z.null() }),
|
|
60
|
+
CheckSchema.extend({
|
|
61
|
+
status: zod_1.z.literal('fail'),
|
|
62
|
+
problem: CheckTextSchema,
|
|
63
|
+
}),
|
|
64
|
+
CheckSchema.extend({
|
|
65
|
+
status: zod_1.z.literal('blocked'),
|
|
66
|
+
problem: CheckTextSchema,
|
|
67
|
+
}),
|
|
68
|
+
]))
|
|
46
69
|
.min(1)
|
|
47
70
|
.max(CHECK_LIMIT),
|
|
48
71
|
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const CLI_GUIDANCE_VERSION =
|
|
1
|
+
export declare const CLI_GUIDANCE_VERSION = 57;
|
|
2
2
|
export declare const CLI_GUIDANCE_BODY: string;
|
|
3
3
|
export declare const CLI_GUIDANCE_DESCRIPTION = "Rivet \u2014 open the visual editor or explore design directions for a web app.";
|
|
4
4
|
//# sourceMappingURL=cli-guidance.d.ts.map
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.CLI_GUIDANCE_DESCRIPTION = exports.CLI_GUIDANCE_BODY = exports.CLI_GUIDANCE_VERSION = void 0;
|
|
4
4
|
const displayLocale_1 = require("../displayLocale");
|
|
5
|
-
exports.CLI_GUIDANCE_VERSION =
|
|
5
|
+
exports.CLI_GUIDANCE_VERSION = 57;
|
|
6
6
|
const DISPLAY_LOCALE = (0, displayLocale_1.resolveDisplayLocale)();
|
|
7
7
|
exports.CLI_GUIDANCE_BODY = `Rivet helps you **explore multiple design directions** for a web app. You drive it by running \`rivet\` CLI commands. Every command prints exactly one JSON envelope on stdout (\`{ schemaVersion, ok, command, data | error }\`), routes progress to stderr, and never prompts for input.
|
|
8
8
|
|
|
@@ -86,7 +86,7 @@ For reusable executable checks, author an optional package with a named \`verify
|
|
|
86
86
|
|
|
87
87
|
Read expected brand values from the independent source. Bind target elements and modes explicitly in package-specific JSON rather than derive expected values from the app being checked. For color, distinguish token provenance from rendered color, including platform-specific paint layers. For spacing, bind semantic gaps or padding and density rather than check arbitrary multiples. For typography, compare the complete role and establish that the intended font loaded. Use evidence appropriate to the target, such as browser computed styles, native view/accessibility data, source inspection, or measured interactions; screenshots alone cannot prove every property. Missing or ambiguous targets and unavailable prerequisites must be blocked. Prove the package on a compliant target and intentional violations before saving it for reuse.
|
|
88
88
|
|
|
89
|
-
The export returns \`{checks:[{id,
|
|
89
|
+
The export returns \`{checks:[{id,status:"pass"|"fail"|"blocked",priority:"high"|"medium"|"low"|null,currentState,problem,proposedFix,evidence:[{path,mediaType,label,role:"observed"|"reference"}],comparison?:{expected,observed,unit},location?}]}\`. Write plain factual \`currentState\` text, explain the violation or blocker in \`problem\`, and recommend a supported \`proposedFix\` or use null. Pass requires null problem; fail and blocked require a nonempty problem. Priority is author-selected or null, never inferred by Rivet. Evidence is required but can be empty. Each attachment has a safe relative path, media type, nonempty label, and observed or reference role. Referenced evidence must be real regular files inside \`evidenceDirectory\`, without symlinks or hard links. Do not claim an after state without measuring it. Optional \`comparison\` holds bounded finite JSON expected/observed values and a nonempty unit or null. Optional \`location\` is a nonempty platform-specific identifier. Keep comparison and location in technical metadata rather than the default user explanation. IDs must be stable and unique, checks nonempty. Unknown fields and the preceding category/rule/target format are rejected. The runner owns schemaVersion, verifier identity/source digest, projectPath, runDirectory, durationMs, and aggregate status. These migrated packages require a Rivet release containing this contract; published v25 uses the preceding format. Save with \`context update <id> --verifier <Markdown path> --verifier-package <manifest.json> --source-digest <packet digest>\`. Run with \`rivet context verify <id> --project <absolute target> --input <target.json>\`; with MCP use \`rivet_run_design_check\` with \`contextId\`, \`project\`, and \`inputFile\`, then execute its returned arguments through the host. The MCP call itself runs no code. Saving through \`rivet_save_design_check\` adds \`packageFile\`. A recipe-only update preserves the saved package for the same source digest; changed source requires a replacement package or explicit verifier removal before a Markdown-only save. Rivet bounds runtime/output, cleans up the process tree even after normal returns, and derives fail before blocked before pass. A pass exits 0; fail or blocked exits 1 with the completed report in \`error.details\`. Runtime errors have \`execution: "error"\` and a normalized reason. Report runtime failures separately from assertion failures. Missing/stale recipes and recipes without packages do not execute. Retrieval still runs no checks. Generation excludes executable code and checking recipes. Only explicit \`includeChecks: true\` context reads include recipe text and package metadata; ordinary context reads exclude both, and executable code is never returned. Saving adds no automatic gate, dependency install or source maintenance.
|
|
90
90
|
|
|
91
91
|
## Commands
|
|
92
92
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rivet-design",
|
|
3
|
-
"version": "0.26.
|
|
3
|
+
"version": "0.26.1",
|
|
4
4
|
"description": "Local visual web development tool with AI-powered code modification",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"workspaces": [
|
|
@@ -212,5 +212,5 @@
|
|
|
212
212
|
"rivetPlugin": {
|
|
213
213
|
"toolContract": "intent-v2"
|
|
214
214
|
},
|
|
215
|
-
"gitHead": "
|
|
215
|
+
"gitHead": "c4c287a9215f2936c79e05ddce775dfbba251bb4"
|
|
216
216
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var Be=s=>{throw TypeError(s)};var Ee=(s,t,r)=>t.has(s)||Be("Cannot "+r);var h=(s,t,r)=>(Ee(s,t,"read from private field"),r?r.call(s):t.get(s)),z=(s,t,r)=>t.has(s)?Be("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(s):t.set(s,r),L=(s,t,r,i)=>(Ee(s,t,"write to private field"),i?i.call(s,r):t.set(s,r),r),M=(s,t,r)=>(Ee(s,t,"access private method"),r);import{S as lt,s as ct,h as Ve,g as Kt,n as fe,r as Qt,Q as dt,u as _e,a as Bt,b as Vt,c as d,e as Gt,d as Yt,f as Wt,i as ut,j as Ge,k as Jt,l as Xt,m as Zt,o as ce,p as me,q as es,t as e,B as J,v as Pe,P as ts,w as ss,x as rs,y as is,z as as,X as ht,D as mt,A as pt,C as xt,E as ft,F as bt,G as yt,H as gt,I as Ye,J as ns,K as os,L as ls,M as cs,N as ne,O as Se,R as ds,T as vt,U as ee,V as Y,W as x,Y as re,Z as H,_ as wt,$ as us,a0 as hs,a1 as ms,a2 as ps,a3 as xs,a4 as fs,a5 as bs,a6 as ys,a7 as B,a8 as gs,a9 as vs,aa as We,ab as ws,ac as js,ad as Ns,ae as ks,af as Ss,ag as jt,ah as _s,ai as Is,aj as Rs,ak as Cs,al as Es,am as Ps,an as Ts}from"./main-
|
|
1
|
+
var Be=s=>{throw TypeError(s)};var Ee=(s,t,r)=>t.has(s)||Be("Cannot "+r);var h=(s,t,r)=>(Ee(s,t,"read from private field"),r?r.call(s):t.get(s)),z=(s,t,r)=>t.has(s)?Be("Cannot add the same private member more than once"):t instanceof WeakSet?t.add(s):t.set(s,r),L=(s,t,r,i)=>(Ee(s,t,"write to private field"),i?i.call(s,r):t.set(s,r),r),M=(s,t,r)=>(Ee(s,t,"access private method"),r);import{S as lt,s as ct,h as Ve,g as Kt,n as fe,r as Qt,Q as dt,u as _e,a as Bt,b as Vt,c as d,e as Gt,d as Yt,f as Wt,i as ut,j as Ge,k as Jt,l as Xt,m as Zt,o as ce,p as me,q as es,t as e,B as J,v as Pe,P as ts,w as ss,x as rs,y as is,z as as,X as ht,D as mt,A as pt,C as xt,E as ft,F as bt,G as yt,H as gt,I as Ye,J as ns,K as os,L as ls,M as cs,N as ne,O as Se,R as ds,T as vt,U as ee,V as Y,W as x,Y as re,Z as H,_ as wt,$ as us,a0 as hs,a1 as ms,a2 as ps,a3 as xs,a4 as fs,a5 as bs,a6 as ys,a7 as B,a8 as gs,a9 as vs,aa as We,ab as ws,ac as js,ad as Ns,ae as ks,af as Ss,ag as jt,ah as _s,ai as Is,aj as Rs,ak as Cs,al as Es,am as Ps,an as Ts}from"./main-tPO1OCpZ.js";var ie,ae,U,ye,se,pe,Te,nt,Ls=(nt=class extends lt{constructor(t,r){super();z(this,se);z(this,ie);z(this,ae);z(this,U);z(this,ye);L(this,ie,t),this.setOptions(r),this.bindMethods(),M(this,se,pe).call(this)}bindMethods(){this.mutate=this.mutate.bind(this),this.reset=this.reset.bind(this)}setOptions(t){var i;const r=this.options;this.options=h(this,ie).defaultMutationOptions(t),ct(this.options,r)||h(this,ie).getMutationCache().notify({type:"observerOptionsUpdated",mutation:h(this,U),observer:this}),r!=null&&r.mutationKey&&this.options.mutationKey&&Ve(r.mutationKey)!==Ve(this.options.mutationKey)?this.reset():((i=h(this,U))==null?void 0:i.state.status)==="pending"&&h(this,U).setOptions(this.options)}onSubscribe(){this.listeners.size===1&&h(this,U)&&(h(this,U).addObserver(this),M(this,se,pe).call(this))}onUnsubscribe(){var t;this.hasListeners()||(t=h(this,U))==null||t.removeObserver(this)}onMutationUpdate(t){M(this,se,pe).call(this),M(this,se,Te).call(this,t)}getCurrentResult(){return h(this,ae)}reset(){var t;(t=h(this,U))==null||t.removeObserver(this),L(this,U,void 0),M(this,se,pe).call(this),M(this,se,Te).call(this)}mutate(t,r){var i;return L(this,ye,r),(i=h(this,U))==null||i.removeObserver(this),L(this,U,h(this,ie).getMutationCache().build(h(this,ie),this.options)),h(this,U).addObserver(this),h(this,U).execute(t)}},ie=new WeakMap,ae=new WeakMap,U=new WeakMap,ye=new WeakMap,se=new WeakSet,pe=function(){var r;const t=((r=h(this,U))==null?void 0:r.state)??Kt();L(this,ae,{...t,isPending:t.status==="pending",isSuccess:t.status==="success",isError:t.status==="error",isIdle:t.status==="idle",mutate:this.mutate,reset:this.reset})},Te=function(t){fe.batch(()=>{var i,n,o,a;const r=h(this,ye);if(r&&this.hasListeners()){const l=h(this,ae).variables,m=h(this,ae).context,f={client:h(this,ie),meta:this.options.meta,mutationKey:this.options.mutationKey};if((t==null?void 0:t.type)==="success"){try{(i=r.onSuccess)==null||i.call(r,t.data,l,m,f)}catch(b){Promise.reject(b)}try{(n=r.onSettled)==null||n.call(r,t.data,null,l,m,f)}catch(b){Promise.reject(b)}}else if((t==null?void 0:t.type)==="error"){try{(o=r.onError)==null||o.call(r,t.error,l,m,f)}catch(b){Promise.reject(b)}try{(a=r.onSettled)==null||a.call(r,void 0,t.error,l,m,f)}catch(b){Promise.reject(b)}}}this.listeners.forEach(l=>{l(h(this,ae))})})},nt);function Je(s,t){const r=new Set(t);return s.filter(i=>!r.has(i))}var ue,Q,he,oe,G,le,ge,ve,we,je,O,Le,Oe,Nt,Ae,Me,De,ot,Os=(ot=class extends lt{constructor(t,r,i){super();z(this,O);z(this,ue);z(this,Q);z(this,he);z(this,oe);z(this,G);z(this,le);z(this,ge);z(this,ve);z(this,we);z(this,je,[]);L(this,ue,t),L(this,oe,i),L(this,he,[]),L(this,G,[]),L(this,Q,[]),this.setQueries(r)}onSubscribe(){this.listeners.size===1&&h(this,G).forEach(t=>{t.subscribe(r=>{M(this,O,Me).call(this,t,r)})})}onUnsubscribe(){this.listeners.size||this.destroy()}destroy(){this.listeners=new Set,h(this,G).forEach(t=>{t.destroy()})}setQueries(t,r){L(this,he,t),L(this,oe,r),fe.batch(()=>{const i=h(this,G),n=M(this,O,Ae).call(this,h(this,he));n.forEach(p=>p.observer.setOptions(p.defaultedQueryOptions));const o=n.map(p=>p.observer),a=o.map(p=>p.getCurrentResult()),l=i.length!==o.length,m=o.some((p,j)=>p!==i[j]),f=l||m,b=f?!0:a.some((p,j)=>{const N=h(this,Q)[j];return!N||!ct(p,N)});!f&&!b||(f&&(L(this,je,n),L(this,G,o)),L(this,Q,a),this.hasListeners()&&(f&&(Je(i,o).forEach(p=>{p.destroy()}),Je(o,i).forEach(p=>{p.subscribe(j=>{M(this,O,Me).call(this,p,j)})})),M(this,O,De).call(this)))})}getCurrentResult(){return h(this,Q)}getQueries(){return h(this,G).map(t=>t.getCurrentQuery())}getObservers(){return h(this,G)}getOptimisticResult(t,r){const i=M(this,O,Ae).call(this,t),n=i.map(a=>a.observer.getOptimisticResult(a.defaultedQueryOptions)),o=i.map(a=>a.defaultedQueryOptions.queryHash);return[n,a=>M(this,O,Oe).call(this,a??n,r,o),()=>M(this,O,Le).call(this,n,i)]}},ue=new WeakMap,Q=new WeakMap,he=new WeakMap,oe=new WeakMap,G=new WeakMap,le=new WeakMap,ge=new WeakMap,ve=new WeakMap,we=new WeakMap,je=new WeakMap,O=new WeakSet,Le=function(t,r){const i=new Set;return r.map((n,o)=>{const a=t[o];return n.defaultedQueryOptions.notifyOnChangeProps?a:n.observer.trackResult(a,l=>{i.has(l)||(i.add(l),r.forEach(m=>{m.observer.trackProp(l)}))})})},Oe=function(t,r,i){if(r){const n=h(this,we),o=i!==void 0&&n!==void 0&&(n.length!==i.length||i.some((a,l)=>a!==n[l]));return(h(this,Q)!==h(this,ve)||o||r!==h(this,ge))&&(L(this,ge,r),L(this,ve,h(this,Q)),i!==void 0&&L(this,we,i),L(this,le,Qt(h(this,le),r(t)))),h(this,le)}return t},Nt=function(){var t;return!((t=h(this,oe))!=null&&t.combine)||h(this,G).some((r,i)=>{var n;return r.options.suspense&&((n=h(this,Q)[i])==null?void 0:n.data)===void 0})},Ae=function(t){const r=new Map;h(this,G).forEach(n=>{const o=n.options.queryHash;if(!o)return;const a=r.get(o);a?a.push(n):r.set(o,[n])});const i=[];return t.forEach(n=>{var l;const o=h(this,ue).defaultQueryOptions(n),a=((l=r.get(o.queryHash))==null?void 0:l.shift())??new dt(h(this,ue),o);i.push({defaultedQueryOptions:o,observer:a})}),i},Me=function(t,r){const i=h(this,G).indexOf(t);i!==-1&&(L(this,Q,h(this,Q).slice()),h(this,Q)[i]=r,M(this,O,De).call(this))},De=function(){var t;if(this.hasListeners()){const r=M(this,O,Nt).call(this),i=h(this,le),n=r?i:M(this,O,Oe).call(this,M(this,O,Le).call(this,h(this,Q),h(this,je)),(t=h(this,oe))==null?void 0:t.combine);(r||i!==n)&&fe.batch(()=>{this.listeners.forEach(o=>{o(h(this,Q))})})}},ot);function As({queries:s,...t},r){const i=_e(),n=Bt(),o=Vt(),a=t.subscribed!==!1,l=d.useMemo(()=>s.map(S=>{const y=i.defaultQueryOptions(S);return y._optimisticResults=n?"isRestoring":a?"optimistic":void 0,y}),[s,i,n,a]);l.forEach(S=>{Gt(S);const y=i.getQueryCache().get(S.queryHash);Yt(S,o,y)}),Wt(o);const[m]=d.useState(()=>new Os(i,l,t)),[f,b,p]=m.getOptimisticResult(l,t.combine),j=!n&&a;d.useSyncExternalStore(d.useCallback(S=>j?m.subscribe(fe.batchCalls(S)):ut,[m,j]),()=>m.getCurrentResult(),()=>m.getCurrentResult()),d.useEffect(()=>{m.setQueries(l,t)},[l,t,m]);const N=f.some((S,y)=>Ge(l[y],S))?f.flatMap((S,y)=>{const k=l[y];if(k&&Ge(k,S)){const $=new dt(i,k);return Jt(k,$,o)}return[]}):[];if(N.length>0)throw Promise.all(N);const R=f.find((S,y)=>{const k=l[y];return k&&Xt({result:S,errorResetBoundary:o,throwOnError:k.throwOnError,query:i.getQueryCache().get(k.queryHash),suspense:k.suspense})});if(R)throw R.error;return b(p())}function xe(s,t){const r=_e(),[i]=d.useState(()=>new Ls(r,s));d.useEffect(()=>{i.setOptions(s)},[i,s]);const n=d.useSyncExternalStore(d.useCallback(a=>i.subscribe(fe.batchCalls(a)),[i]),()=>i.getCurrentResult(),()=>i.getCurrentResult()),o=d.useCallback((...a)=>{i.mutate(a[0],a[1]).catch(ut)},[i]);if(n.error&&Zt(i.options.throwOnError,[n.error]))throw n.error;return{...n,mutate:o,mutateAsync:n.mutate}}/**
|
|
2
2
|
* @license lucide-react v1.64.0 - ISC
|
|
3
3
|
*
|
|
4
4
|
* This source code is licensed under the ISC license.
|
|
@@ -34,4 +34,4 @@ var Be=s=>{throw TypeError(s)};var Ee=(s,t,r)=>t.has(s)||Be("Cannot "+r);var h=(
|
|
|
34
34
|
* This source code is licensed under the ISC license.
|
|
35
35
|
* See the LICENSE file in the root directory of this source tree.
|
|
36
36
|
*/const Pt={name:"loader-circle",size:24,node:[["path",{d:"M21 12a9 9 0 1 1-6.219-8.56",key:"13zald"}]],aliases:["loader-2"]};Pt.node;const Tt=ce(Pt),$s=200,Fs=({project:s,onRename:t,onRemove:r,onSetPinned:i})=>{const n=me(),o=d.useRef(null),a=d.useRef(null),l=d.useRef(null),[m,f]=d.useState(!1),[b,p]=d.useState(!1),j=!!s.pinnedAt,[N,R]=d.useState(null),[S,y]=d.useState(s.name),[k,$]=d.useState(!1),[v,_]=d.useState(null),{containerRef:E,onKeyDown:D}=es();let X=N==="rename"?"Save name":"Remove from projects";k&&(X="Saving…"),d.useEffect(()=>{var q;if(b||!l.current)return;const g=l.current==="button"?a:o;l.current=null,(q=g.current)==null||q.focus()},[b]);const A=g=>{f(g),n==null||n.capture(g?"library_project_menu_opened":"library_project_menu_closed")},T=async g=>{if(!b){l.current=g,p(!0),n==null||n.capture("library_project_pin_clicked",{is_pinning:!j,method:g});try{await i(s.id,!j)}catch(q){gt.error(Ye(q,"Could not save pin. Try again."))}finally{p(!1)}}},W=g=>{A(!1),y(s.name),_(null),R(g),n==null||n.capture("library_project_action_opened",{action:g})},V=g=>{n==null||n.capture("library_project_action_closed",{action:N,outcome:g}),R(null)},I=async()=>{if(!(k||!N||N==="rename"&&!S.trim())){$(!0),_(null);try{N==="rename"?await t(s.id,S.trim()):await r(s.id),V("completed")}catch(g){_(Ye(g,"Could not save changes. Try again."))}finally{$(!1)}}};return e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:`flex items-center gap-0.5 group-hover/project:pointer-events-auto group-hover/project:opacity-100 has-[:focus-visible]:pointer-events-auto has-[:focus-visible]:opacity-100 [@media(hover:none)]:pointer-events-auto [@media(hover:none)]:opacity-100 ${m?"pointer-events-auto opacity-100":"pointer-events-none opacity-0"}`,children:[e.jsx(J,{ref:a,type:"button",variant:"ghost",size:"icon-compact",title:j?"Unpin project":"Pin project","aria-label":`${j?"Unpin":"Pin"} ${s.name}`,"aria-pressed":j,disabled:b,onClick:()=>{T("button")},children:e.jsx(Pe,{weight:j?"fill":"bold",size:16,"aria-hidden":!0})}),e.jsxs(ts,{open:m,onOpenChange:A,children:[e.jsx(ss,{asChild:!0,children:e.jsx(J,{ref:o,type:"button",variant:"ghost",size:"icon-compact","aria-label":`Actions for ${s.name}`,children:e.jsx(Ds,{size:16,"aria-hidden":!0})})}),e.jsx(rs,{children:e.jsxs(is,{"data-rivet-private":!0,ref:E,onKeyDown:D,role:"menu","aria-label":"Project actions",align:"start",sideOffset:4,onCloseAutoFocus:g=>{N&&g.preventDefault()},className:"ph-no-capture bg-surface-2 text-content z-ui-primary min-w-44 rounded-lg p-1 shadow-lg",children:[e.jsxs("button",{type:"button",role:"menuitem","data-menu-item":!0,disabled:b,onClick:()=>{A(!1),T("menu")},className:"hover:bg-hover focus:bg-hover flex w-full items-center gap-2 rounded-md px-3 py-2 text-xs focus:outline-none disabled:opacity-50",children:[e.jsx(Pe,{size:14,weight:j?"fill":"bold","aria-hidden":!0}),j?"Unpin":"Pin"]}),e.jsxs("button",{type:"button",role:"menuitem","data-menu-item":!0,onClick:()=>W("rename"),className:"hover:bg-hover focus:bg-hover flex w-full items-center gap-2 rounded-md px-3 py-2 text-xs focus:outline-none",children:[e.jsx(as,{size:14,"aria-hidden":!0}),"Rename"]}),e.jsxs("button",{type:"button",role:"menuitem","data-menu-item":!0,onClick:()=>W("remove"),className:"hover:bg-hover focus:bg-hover flex w-full items-center gap-2 rounded-md px-3 py-2 text-xs focus:outline-none",children:[e.jsx(ht,{size:14,"aria-hidden":!0}),"Remove from projects"]})]})})]})]}),e.jsx(mt,{open:N!==null,onOpenChange:g=>{!g&&!k&&V("cancelled")},children:e.jsxs(pt,{children:[e.jsx(xt,{className:"z-modal fixed inset-0 bg-black/60"}),e.jsxs(ft,{"data-rivet-private":!0,onCloseAutoFocus:g=>{var q;g.preventDefault(),(q=o.current)==null||q.focus()},className:"ph-no-capture bg-surface-2 text-content z-ui-secondary fixed top-1/2 left-1/2 w-[calc(100%-2rem)] max-w-sm -translate-x-1/2 -translate-y-1/2 rounded-xl p-6 shadow-lg",children:[e.jsx(bt,{className:"text-base font-medium break-words",children:N==="rename"?"Rename project":`Remove “${s.name}” from projects?`}),e.jsx(yt,{className:"mt-2 text-sm leading-6 text-white/60",children:N==="rename"?"Choose a display name for this project. Its folder name will stay the same.":"Your folders and saved variants will remain on this computer. Open the project again to restore it."}),e.jsxs("form",{onSubmit:g=>{g.preventDefault(),I()},children:[N==="rename"?e.jsxs("label",{className:"mt-5 block text-xs text-white/70",children:["Project name",e.jsx("input",{autoFocus:!0,value:S,onChange:g=>y(g.target.value),maxLength:$s,disabled:k,className:"mt-2 w-full rounded-lg border border-white/15 bg-white/5 px-3 py-2 text-sm text-white outline-none focus:border-white/50"})]}):null,v?e.jsx("p",{role:"alert",className:"mt-4 text-xs text-red-300",children:v}):null,e.jsxs("div",{className:"mt-6 flex justify-end gap-2",children:[e.jsx(J,{type:"button",variant:"ghost",disabled:k,onClick:()=>V("cancelled"),children:"Cancel"}),e.jsx(J,{type:"submit",variant:"secondary",disabled:k||N==="rename"&&!S.trim(),children:X})]})]})]})]})})]})},Lt=6e4,Ot=60*Lt,Ie=24*Ot,Us=7*Ie,Hs=30*Ie,Ks=365*Ie,Qs=[["year",Ks],["month",Hs],["week",Us],["day",Ie],["hour",Ot],["minute",Lt]],Bs=new Intl.RelativeTimeFormat("en",{numeric:"always"}),Vs=s=>{const t=new Map;for(const r of s??[]){const i=Date.parse(r.createdAt);if(!Number.isFinite(i))continue;const n=t.get(r.projectId);(n===void 0||i>n)&&t.set(r.projectId,i)}return t},Gs=({projects:s,latestEdits:t})=>[...s].sort((r,i)=>{if(r.pinnedAt&&!i.pinnedAt)return-1;if(i.pinnedAt&&!r.pinnedAt)return 1;if(r.pinnedAt&&i.pinnedAt)return r.pinnedAt.localeCompare(i.pinnedAt)||r.id.localeCompare(i.id);const n=t.get(r.id),o=t.get(i.id);return n===void 0&&o!==void 0?1:o===void 0&&n!==void 0?-1:(o??0)-(n??0)||r.name.localeCompare(i.name)||r.id.localeCompare(i.id)}),Ys=({editedAt:s,now:t})=>{const r=Math.max(0,t-s);for(const[i,n]of Qs)if(r>=n)return`Edited ${Bs.format(-Math.floor(r/n),i)}`;return"Edited just now"},At=d.createContext(null),Ws=({navigation:s,onBrowseProjects:t,controls:r,isHeaderVisible:i=!0,children:n})=>{const[o,a]=d.useState(null);return e.jsxs(At.Provider,{value:o,children:[i?e.jsxs("div",{className:"grid shrink-0 grid-cols-[auto_minmax(0,1fr)] items-center gap-4 px-10 py-5 max-sm:px-5 sm:grid-cols-[auto_minmax(0,1fr)_auto]",children:[e.jsx("button",{onClick:t,"aria-label":"Projects",className:"flex items-center",children:e.jsx("img",{src:ns,alt:"","aria-hidden":!0,draggable:!1,className:"h-8 w-8"})}),e.jsx("div",{ref:a,className:"col-span-2 row-start-2 flex min-w-0 items-center gap-3 sm:col-span-1 sm:col-start-2 sm:row-start-1",children:r}),e.jsx("div",{className:"col-start-2 row-start-1 justify-self-end sm:col-start-3",children:s})]}):null,n]})},Mt=({children:s})=>{const t=d.useContext(At);return t?os.createPortal(s,t):null},qe=({label:s,value:t,onChange:r,onBlur:i,isDisabled:n=!1})=>e.jsxs("label",{className:"flex w-64 min-w-0 items-center gap-2 rounded-lg border border-white/[0.08] bg-white/[0.02] px-3 py-2.5 text-white/35 max-sm:flex-1",children:[e.jsx(ls,{size:14,className:"shrink-0","aria-hidden":!0}),e.jsx("input",{type:"search","aria-label":s,placeholder:`${s}…`,value:t,onChange:o=>r==null?void 0:r(o.target.value),onBlur:i,disabled:n,className:"min-w-0 flex-1 bg-transparent text-xs text-white outline-none placeholder:text-white/30 disabled:opacity-40 [&::-webkit-search-cancel-button]:hidden"})]}),Js=({projects:s,variants:t,historyError:r,onRetryHistory:i,projectPreviews:n={},selectedProjectId:o,onSelectProject:a,onBrowseLibrary:l,onOpenProject:m,onRenameProject:f,onRemoveProject:b,onSetProjectPinned:p,isOpeningProject:j=!1,projectOpenError:N,onSearchCompleted:R,accountMenu:S,navigation:y,view:k="library",children:$})=>{const[v,_]=d.useState(""),E=o===null||$===void 0,D=d.useRef(null),X=Vs(t),A=Date.now(),T=s.find(I=>I.id===o),W=new Map;if(t)for(const I of s)I.historyIssue||W.set(I.id,0);for(const{projectId:I}of t??[]){const g=W.get(I);g!==void 0&&W.set(I,g+1)}const V=Gs({projects:s.filter(I=>I.name.toLowerCase().includes(v.toLowerCase())),latestEdits:X});return e.jsx("div",{className:"ph-no-capture bg-background text-foreground flex h-screen min-h-0","data-rivet-private":!0,children:e.jsx("main",{className:"relative flex min-w-0 flex-1 flex-col overflow-hidden",children:e.jsxs(Ws,{navigation:y,onBrowseProjects:l,isHeaderVisible:E,controls:k==="library"?e.jsx(qe,{label:"Search projects",value:v,onChange:_,onBlur:()=>R==null?void 0:R(v.length)}):null,children:[N?e.jsx("p",{role:"alert",className:"px-10 pt-5 text-xs text-red-200",children:N}):null,$!==void 0?$:e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-10 pb-10 max-sm:px-5",children:[e.jsx("h1",{ref:D,tabIndex:-1,className:"sr-only",children:"Projects"}),e.jsx("div",{className:"mb-9 flex items-center justify-end",children:e.jsx(J,{onClick:()=>m(),variant:"secondary",disabled:j,leadingIcon:Xe,className:"shrink-0",children:"Open project…"})}),r?e.jsxs("div",{role:"alert",className:"mb-6 flex items-center gap-3 text-xs text-white/60",children:[e.jsx("span",{children:r}),e.jsx("button",{onClick:i,className:"shrink-0 underline underline-offset-4",children:"Retry history"})]}):null,T!=null&&T.issue?e.jsx("p",{role:"alert",className:"mb-6 rounded-lg border border-amber-200/10 bg-amber-200/[0.03] p-4 text-xs leading-6 text-white/70",children:T.issue}):null,T&&!T.isAvailable?e.jsxs("div",{className:"mb-6 flex items-center justify-between gap-4 rounded-lg border border-amber-200/10 bg-amber-200/[0.03] p-4 text-xs text-white/60",children:[e.jsxs("span",{children:["Locate ",T.name,"’s working folder to open its workspace."]}),e.jsx("button",{disabled:j,onClick:()=>m(T.id),className:"shrink-0 text-white underline decoration-white/30 underline-offset-4",children:"Locate folder"})]}):null,e.jsxs("div",{className:"grid items-start gap-x-6 gap-y-8 sm:grid-cols-2",children:[V.map(I=>{const g=W.get(I.id);let q="Loading variants…";g!==void 0?q=`${g.toLocaleString()} ${g===1?"variant":"variants"}`:(r||I.historyIssue)&&(q="Variants unavailable");const u=X.get(I.id);let C="No edits yet";r||I.historyIssue?C="Edit history unavailable":t===void 0?C="Loading edits…":g&&(C="Edit date unavailable");const K=n[I.id];return e.jsxs("div",{className:"group/project grid min-w-0",children:[e.jsxs("button",{onClick:()=>{_(""),a(I.id)},className:"group col-start-1 row-span-2 row-start-1 -m-2 grid w-[calc(100%+1rem)] min-w-0 grid-rows-subgrid rounded-2xl p-2 text-left hover:bg-white/[0.06] focus-visible:bg-white/[0.06] focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-white/60",children:[e.jsx("span",{className:"group-hover:border-border relative block aspect-video overflow-hidden rounded-xl border border-white/[0.08] bg-white/[0.02]",children:K?e.jsx("img",{src:K.dataUrl,alt:`${I.name} — ${K.label}`,draggable:!1,className:"h-full w-full object-cover object-top"}):null}),e.jsxs("span",{className:"mt-3 block pr-16",children:[e.jsxs("span",{className:"flex min-w-0 items-center gap-1.5 text-sm font-medium",children:[I.pinnedAt?e.jsx(Pe,{size:12,weight:"fill","aria-hidden":!0,className:"text-content-muted shrink-0"}):null,e.jsx("span",{className:"truncate",children:I.name})]}),e.jsxs("span",{className:"mt-2 flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1 text-xs text-white/40 group-hover:text-white/65 group-focus-visible:text-white/65",children:[u!==void 0?e.jsx("time",{dateTime:new Date(u).toISOString(),title:new Date(u).toLocaleString(),children:Ys({editedAt:u,now:A})}):e.jsx("span",{children:C}),e.jsx("span",{className:"shrink-0",children:q})]}),I.isAvailable?null:e.jsx("span",{className:"mt-2 block text-xs text-amber-200/65",children:"Folder unavailable"})]})]}),e.jsx("div",{className:"z-content col-start-1 row-start-2 mt-3 self-center justify-self-end",children:e.jsx(Fs,{project:I,onRename:f,onSetPinned:p,onRemove:async Z=>{var de;await b(Z),(de=D.current)==null||de.focus()}})})]},I.id)}),V.length===0?e.jsxs("div",{className:"col-span-full flex min-h-80 flex-col items-center justify-center rounded-xl border border-dashed border-white/10 px-8 text-center",children:[e.jsx(Xe,{size:26,className:"mb-5 text-white/25"}),e.jsx("h2",{className:"text-sm font-medium",children:v?"No matching projects":"Add your projects"}),e.jsx("p",{className:"mt-2 max-w-sm text-xs leading-6 text-white/40",children:v?"Try another project name.":"Open an existing project to add it as a project here"}),v?null:e.jsx(J,{onClick:()=>m(),variant:"secondary",disabled:j,className:"mt-5",children:"Open project"})]}):null]})]}),E&&S?e.jsx("footer",{className:"border-main-border bg-main-light shrink-0 border-t px-2.5 py-2.5",children:S}):null]})})})},Dt=8,Ze=1,Xs=({children:s})=>e.jsx("ul",{className:"grid grid-cols-1 items-start gap-x-5 min-[400px]:grid-cols-2 md:grid-cols-3 xl:grid-cols-4 2xl:grid-cols-5",style:{gridAutoRows:`${Dt}px`},children:s}),Zs=({children:s})=>{const[t,r]=d.useState(Ze),i=d.useRef(null),n=d.useCallback(o=>{var l;if((l=i.current)==null||l.disconnect(),!o)return;const a=()=>r(Math.max(Ze,Math.ceil(o.getBoundingClientRect().height/Dt)));a(),i.current=new ResizeObserver(a),i.current.observe(o)},[]);return e.jsx("li",{className:"min-w-0",style:{gridRowEnd:`span ${t}`},children:e.jsx("div",{ref:n,className:"relative pb-8",children:s})})},er=async({profileId:s,referenceId:t,hash:r,signal:i})=>{const n=await cs(`/api/library/profile/references/${encodeURIComponent(t)}/media/${r}?${new URLSearchParams({profileId:s})}`,{signal:i});if(!n.ok)throw new Error("Image unavailable");return n.blob()},tr="200px",qt=({profileId:s,referenceId:t,hash:r,title:i,isDetail:n=!1})=>{const[o,a]=d.useState(!1),[l,m]=d.useState(!1),f=d.useRef(null),b=d.useCallback(N=>{var R;(R=f.current)==null||R.disconnect(),N&&(f.current=new IntersectionObserver(S=>{var y;S.some(k=>k.isIntersecting)&&(a(!0),(y=f.current)==null||y.disconnect())},{rootMargin:tr}),f.current.observe(N))},[]),p=ne({queryKey:["design-library-image",s,t,r],queryFn:async({signal:N})=>{const R=await er({profileId:s,referenceId:t,hash:r,signal:N});return new Promise((S,y)=>{const k=new FileReader;k.onload=()=>typeof k.result=="string"?S(k.result):y(new Error("Image unavailable")),k.onerror=()=>y(new Error("Image unavailable")),k.readAsDataURL(R)})},enabled:o,staleTime:1/0,gcTime:0,retry:!1}),j=!!p.data&&!l;return e.jsxs("div",{ref:b,className:Se("flex items-center justify-center overflow-hidden bg-white/[0.025]",n?"min-h-32":null,!n&&!j?"aspect-[4/3]":null),children:[p.isError||l?e.jsxs("span",{className:"flex items-center gap-2 p-5 text-xs text-white/35",children:[e.jsx(qs,{size:16,"aria-hidden":!0}),"Image unavailable"]}):null,p.data&&!l?e.jsx("img",{src:p.data,alt:i,onError:()=>m(!0),className:n?"max-h-[65vh] w-full object-contain":"block h-auto w-full"}):null,!p.data&&!p.isError?e.jsx("span",{className:"text-xs text-white/25",children:"Loading image…"}):null]})},sr={arena:"Are.na",cosmos:"Cosmos",pinterest:"Pinterest",x:"X",image:"Uploaded image",text:"Saved text",variant:"Saved direction",pdf:"PDF"},rr=({provider:s})=>e.jsxs("span",{className:"inline-flex items-center gap-1.5",children:[s==="arena"||s==="cosmos"||s==="pinterest"||s==="x"?e.jsx(ds,{provider:s,className:"h-3.5 w-3.5"}):null,sr[s]]}),ir=({label:s,onCopy:t,referenceCount:r=1})=>{const i=me(),[n,o]=d.useState("idle"),a=async()=>{o("copying");try{await t(),o("copied"),i==null||i.capture("library_reference_copy_completed",{reference_count:r,copy_kind:"agent"})}catch{o("failed"),gt.error("Could not copy. Check clipboard access and try again."),i==null||i.capture("library_reference_copy_failed",{reference_count:r,copy_kind:"agent"})}},l=n==="copied"?vt:Ms,m=n==="copied"?"Copied":s;return e.jsxs(e.Fragment,{children:[e.jsx(J,{variant:"secondary",size:"compact",leadingIcon:l,disabled:n==="copying",onClick:()=>void a(),"aria-label":m,"aria-live":"polite",children:e.jsxs("span",{className:"grid whitespace-nowrap",children:[e.jsx("span",{"aria-hidden":!0,className:"invisible col-start-1 row-start-1",children:s}),e.jsx("span",{className:"col-start-1 row-start-1",children:m})]})}),n==="failed"?e.jsx("span",{role:"alert",className:"sr-only",children:"Could not copy. Check clipboard access and try again."}):null]})},ar=6,be=100,et=100,nr=35*1024*1024,tt=Math.ceil(nr/3)*4,or=ee(["pinterest","arena","x","cosmos"]),zt=ee(["image",...or.options,"text","pdf","variant"]),Re=ee(["codex","claude","cursor"]),$t=Y({projectId:x().min(1).max(200),sessionId:x().min(1).max(200),variantId:x().min(1).max(200)}).strict();$t.extend({runtime:Re,note:x().trim().max(500).optional(),imageFile:x().min(1).max(2048).optional()});const Ft=$t.extend({treeSha:x().max(100).optional()}),lr=Y({hash:x().regex(/^[a-f0-9]{64}$/),mimeType:ee(["image/png","image/jpeg","image/webp","image/gif"]),bytes:re().int().positive(),representation:ee(["image","video-cover","page","variant"]).default("image"),page:re().int().positive().optional()});Y({provider:zt,remoteId:x().trim().min(1).max(2048),title:x().trim().min(1).max(500),url:x().url().optional()});Y({provider:zt,remoteId:x().trim().min(1).max(2048),title:x().max(1e3),text:x().max(1e5),url:x().url().optional(),media:H(lr).max(100),remoteImages:H(x().url()).max(100).optional(),remoteImageRepresentations:H(ee(["image","video-cover"])).max(100).optional(),unsupportedReason:x().max(1e3).optional(),variant:Ft.optional(),note:x().max(500).optional()});const Ut=Y({inputTokens:re().nonnegative().optional(),outputTokens:re().nonnegative().optional(),cachedInputTokens:re().nonnegative().optional(),allocation:wt("equal-share").optional()});Y({referenceId:x().min(1),revision:re().int().positive(),description:x().trim().min(1).max(8e3),runtime:us([Re,wt("user")]),evidence:ee(["observation","preference"]),usage:Ut.optional()});const cr=Y({requestId:x().min(1).max(200),instruction:x().min(1).max(3e4),runtime:Re,mode:ee(["auto","off","uploads"]).default("off"),excludedSourceIds:H(x()).max(100).default([]),excludedReferenceIds:H(x()).max(100).default([]),excludedMediaHashes:H(x()).max(100).default([]),suppliedInputHashes:H(x().regex(/^[a-f0-9]{64}$/)).max(be).optional()});cr.extend({mode:ee(["auto","off","uploads"]).default("uploads"),uploads:H(x().max(tt+et)).max(be).optional()}).refine(s=>(s.uploads??[]).reduce((t,r)=>t+r.length,0)<=tt+be*et,"Supplied images exceed the profile upload budget");const dr=hs().transform((s,t)=>{const r=ms.safeParse(s);return r.success?r.data:(t.addIssue({code:ps.custom,message:"Invalid supplied image reference"}),xs)}),st=Y({suppliedReferences:H(dr).max(be).optional(),failedUploadCount:re().int().min(0).max(be).optional(),usage:Ut.optional(),requestId:x(),status:ee(["selected","empty","off","unavailable","timeout"]),queries:H(x()),candidateIds:H(x()),selected:H(Y({id:x(),revision:re(),title:x().optional(),url:x().url().optional(),mediaHashes:H(x().regex(/^[a-f0-9]{64}$/)).optional(),reason:x(),sourceTitles:H(x()),variant:Ft.optional()})),contextText:x().max(6e3),images:H(Y({path:x(),hash:x().regex(/^[a-f0-9]{64}$/),mimeType:ee(["image/png","image/jpeg","image/webp","image/gif"])})).max(ar),durationMs:re()});st.pick({requestId:!0,suppliedReferences:!0,failedUploadCount:!0,status:!0,selected:!0,images:!0,durationMs:!0}).extend({requestId:x().min(1).max(200),selected:st.shape.selected.max(3)});Y({query:x().trim().min(2).max(1e3),sourceId:x().min(1).max(200).optional(),limit:re().int().min(1).max(100).default(24),runtime:Re.default("codex")});const Ht=50,rt=12,ur=x().regex(/^[a-f0-9]{12,64}@[1-9][0-9]*$/).refine(s=>Number.isSafeInteger(Number(s.split("@")[1])),"Invalid reference revision"),hr=Y({profileId:x().uuid(),keys:H(ur).min(1).max(Ht),isDetailed:fs().default(!1)}),mr=s=>{const t=new Map;for(const r of s){const i=r.id.slice(0,rt);t.set(i,(t.get(i)??0)+1)}return new Map(s.map(r=>{const i=r.id.slice(0,rt),n=t.get(i)===1?i:r.id;return[r.id,`${n}@${r.revision}`]}))},pr=({profileId:s,referenceKeys:t})=>{const r=hr.parse({profileId:s,keys:t});return["rivet","profile","reference",r.profileId,...r.keys].join(" ")},ze=s=>{const t=s.referenceKeys.length===1?"Copy to agent":`Copy ${s.referenceKeys.length} to agent`;return e.jsx(ir,{label:t,referenceCount:s.referenceKeys.length,onCopy:()=>navigator.clipboard.writeText(pr(s))})},xr=({profileId:s,reference:t,sources:r,referenceKey:i,children:n})=>{var m,f;const o=me(),a=t.title||"Untitled reference",l=t.url&&/^https?:\/\//i.test(t.url)?t.url:void 0;return e.jsxs(mt,{onOpenChange:b=>o==null?void 0:o.capture(b?"library_reference_opened":"library_reference_closed",{provider:t.provider,media_count:t.media.length}),children:[e.jsx(bs,{asChild:!0,children:n}),e.jsxs(pt,{children:[e.jsx(xt,{className:"fixed inset-0 z-50 bg-black/55"}),e.jsxs(ft,{className:"ph-no-capture bg-background text-foreground fixed inset-y-0 right-0 z-50 flex w-full max-w-2xl flex-col border-l border-white/10 shadow-2xl outline-none","data-rivet-private":!0,children:[e.jsxs("header",{className:"flex items-start justify-between gap-6 border-b border-white/[0.07] px-7 py-6",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx(yt,{className:"mb-2 text-xs text-white/40",children:e.jsx(rr,{provider:t.provider})}),e.jsx(bt,{className:"text-lg leading-snug font-medium tracking-tight break-words",children:a})]}),e.jsx(ys,{asChild:!0,children:e.jsx(J,{variant:"ghost",size:"icon-compact","aria-label":"Close reference",children:e.jsx(ht,{size:18})})})]}),e.jsx("div",{className:"border-b border-white/[0.07] px-7 py-4",children:e.jsx(ze,{profileId:s,referenceKeys:[i]},t.revision)}),e.jsxs("div",{className:"min-h-0 flex-1 space-y-7 overflow-y-auto px-7 py-6",children:[t.media.map(b=>e.jsx(qt,{profileId:s,referenceId:t.id,hash:b.hash,title:a,isDetail:!0},b.hash)),t.text?e.jsx("p",{className:"text-sm leading-7 break-words whitespace-pre-wrap text-white/70",children:t.text}):null,t.note?e.jsxs("section",{children:[e.jsx("h3",{className:"mb-2 text-xs font-medium text-white/45",children:"Your note"}),e.jsx("p",{className:"text-sm leading-7 break-words whitespace-pre-wrap text-white/75",children:t.note})]}):null,e.jsxs("section",{children:[e.jsx("h3",{className:"mb-2 text-xs font-medium text-white/45",children:((m=t.observation)==null?void 0:m.evidence)==="preference"?"Your preference":"Rivet’s analysis"}),e.jsx("p",{className:"text-sm leading-7 break-words whitespace-pre-wrap text-white/75",children:((f=t.observation)==null?void 0:f.description)??t.unsupportedReason??"No analysis saved yet."})]}),e.jsxs("section",{children:[e.jsx("h3",{className:"mb-3 text-xs font-medium text-white/45",children:"Saved in"}),e.jsx("ul",{className:"space-y-2",children:r.filter(b=>t.sourceIds.includes(b.id)).map(b=>e.jsxs("li",{className:"flex flex-wrap items-center justify-between gap-2 rounded-md bg-white/[0.035] px-3 py-2.5 text-xs",children:[e.jsx("span",{children:b.title}),b.isIncluded?null:e.jsx("span",{className:"text-white/35",children:"Excluded from generation"})]},b.id))})]}),l?e.jsxs("a",{href:l,target:"_blank",rel:"noopener noreferrer",onClick:()=>o==null?void 0:o.capture("library_reference_original_opened",{provider:t.provider}),className:"inline-flex items-center gap-1 text-xs text-white/70 underline-offset-4 hover:underline",children:["Open original",e.jsx(St,{size:14,"aria-hidden":!0})]}):null]})]})]})]})},it="opacity-0 group-hover/card:opacity-100 group-focus-within/card:opacity-100 [@media(hover:none)]:opacity-100",fr="pointer-events-none group-hover/card:pointer-events-auto group-focus-within/card:pointer-events-auto [@media(hover:none)]:pointer-events-auto",br=({profileId:s,reference:t,sources:r,referenceKey:i,isSelected:n,isSelectionDisabled:o,onSelect:a})=>{var f;const l=t.title||"Untitled reference",m=t.media[0];return e.jsxs("div",{className:"group/card relative",children:[e.jsx(xr,{profileId:s,reference:t,sources:r,referenceKey:i,children:e.jsx("button",{"aria-label":`Inspect ${l}`,className:"block w-full overflow-hidden text-left outline-none focus-visible:ring-2 focus-visible:ring-white/50 focus-visible:ring-offset-4 focus-visible:ring-offset-background",children:m?e.jsx(qt,{profileId:s,referenceId:t.id,hash:m.hash,title:l},m.hash):e.jsxs("div",{className:"min-h-44 border border-white/10 bg-white/[0.03] p-5 pb-14",children:[e.jsx("p",{className:"text-sm font-medium text-white/80",children:l}),e.jsx("p",{className:"mt-3 line-clamp-3 text-xs leading-5 text-white/45",children:((f=t.observation)==null?void 0:f.description)??t.text})]})})}),e.jsx("div",{"aria-hidden":!0,className:Se("pointer-events-none absolute inset-0 bg-black/40",it)}),e.jsxs("div",{className:Se("absolute inset-x-0 bottom-0 z-10 flex items-center justify-between gap-2 p-2",n?null:it,n?null:fr),children:[e.jsxs("label",{className:"relative shrink-0 cursor-pointer",title:n?"Deselect":"Select",children:[e.jsx("input",{type:"checkbox","aria-label":`Select ${l}`,checked:n,disabled:o,onChange:a,className:"peer absolute inset-0 h-full w-full cursor-pointer opacity-0 disabled:cursor-default"}),e.jsx("span",{className:Se("flex h-7 w-7 items-center justify-center rounded-full border shadow-sm peer-focus-visible:ring-2 peer-focus-visible:ring-white peer-focus-visible:ring-offset-2 peer-disabled:opacity-40",n?"border-orange-400 bg-orange-500 text-white":"border-white/35 bg-black/60 text-white/70"),children:e.jsx(vt,{size:14,"aria-hidden":!0})})]}),e.jsx(ze,{profileId:s,referenceKeys:[i]},t.revision)]})]})},Ne=24,yr="200px",gr=350,vr=100,wr=({snapshot:s})=>{var q;const t=me(),[r,i]=d.useState(""),[n,o]=d.useState(""),a=d.useRef(null),[l,m]=d.useState(""),[f,b]=d.useState(Ne),[p,j]=d.useState([]),N=d.useRef(null),R=mr(s.references),S=s.references.filter(u=>u.media.length>0),y=ne({queryKey:["design-reference-search",s.profileId,s.revision,s.references.map(({id:u,revision:C,sourceIds:K})=>[u,C,K]),n,l],queryFn:({signal:u})=>B("/profile/search",{method:"POST",body:{query:n,sourceId:l||void 0,limit:vr},signal:u}),enabled:n.length>=2&&s.references.length>0,retry:!1}),k=s.references.filter(u=>p.includes(u.id)),$=k.flatMap(u=>{const C=R.get(u.id);return C?[C]:[]}),v=r.trim(),_=v.length>=2,E=_&&s.references.length>0&&(n!==v||y.isLoading),D=_&&!E&&y.isError,X=new Map(s.references.map(u=>[u.id,u])),A=_?(((q=y.data)==null?void 0:q.results)??[]).flatMap(({id:u})=>{const C=X.get(u);return C?[C]:[]}):S.filter(u=>!l||u.sourceIds.includes(l)),T=S.length>0,W=A.length,V=s.references.length>0?"No images yet":"Your library starts here",I=d.useCallback(u=>{var C;(C=N.current)==null||C.disconnect(),u&&(N.current=new IntersectionObserver(K=>{var Z;K.some(de=>de.isIntersecting)&&((Z=N.current)==null||Z.disconnect(),b(Math.min(f+Ne,W)))},{root:u.parentElement,rootMargin:yr}),N.current.observe(u))},[f,W]),g=u=>{const C=k.map(Z=>Z.id),K=C.includes(u)?C.filter(Z=>Z!==u):[...C,u];j(K),t==null||t.capture("library_reference_selection_changed",{selected_count:K.length})};return e.jsxs("div",{className:"ph-no-capture flex min-h-0 flex-1 flex-col","data-rivet-private":!0,children:[e.jsx(Mt,{children:e.jsx(qe,{label:"Search references",value:r,onChange:u=>{i(u),a.current&&clearTimeout(a.current),a.current=setTimeout(()=>o(u.trim()),gr),b(Ne)},onBlur:()=>{var u;return t==null?void 0:t.capture("library_reference_search_completed",{query_length:r.length,result_count:_?((u=y.data)==null?void 0:u.results.length)??0:A.length})}})}),e.jsxs("div",{className:"min-h-0 flex-1 overflow-y-auto px-10 pb-10 max-sm:px-5",children:[!s.isEnabled&&T?e.jsx("p",{className:"mb-5 text-xs text-white/40",children:"Automatic use is paused. Your saved references are still here."}):null,T?e.jsx("div",{className:"mb-7 flex flex-wrap items-center gap-3",children:e.jsxs("select",{"aria-label":"Source",value:l,onChange:u=>{m(u.target.value),b(Ne),t==null||t.capture("library_reference_source_filtered",{is_filtered:!!u.target.value})},className:"bg-background max-w-64 rounded-lg border border-white/[0.08] px-3 py-2.5 text-xs text-white/60 focus-visible:outline-2",children:[e.jsx("option",{value:"",children:"All sources"}),s.sources.map(u=>e.jsx("option",{value:u.id,children:u.title},u.id))]})}):null,$.length?e.jsxs("div",{className:"bg-background sticky top-0 z-20 mb-6 flex flex-wrap items-center gap-3 rounded-lg border border-white/10 p-3 shadow-lg",children:[e.jsxs("span",{className:"text-xs text-white/50",children:[$.length," selected"]}),e.jsx(ze,{profileId:s.profileId,referenceKeys:$},$.join(" ")),e.jsx(J,{variant:"ghost",size:"compact",onClick:()=>{j([]),t==null||t.capture("library_reference_selection_changed",{selected_count:0})},children:"Clear selection"})]}):null,_&&y.data&&y.data.coverage.analyzed<y.data.coverage.saved?e.jsxs("p",{role:"status",className:"mb-5 text-xs text-white/45",children:[y.data.coverage.analyzed," of"," ",y.data.coverage.saved," references analyzed; results may be incomplete."]}):null,E?e.jsx("p",{role:"status",className:"py-10 text-center text-xs text-white/45",children:"Searching references…"}):null,D?e.jsxs("div",{role:"alert",className:"py-10 text-center text-xs text-white/50",children:[e.jsxs("p",{children:["Search is unavailable: ",y.error.message]}),e.jsx(J,{variant:"ghost",onClick:()=>{t==null||t.capture("library_reference_search_retry"),y.refetch()},children:"Try again"})]}):null,!E&&!D&&A.length?e.jsx(Xs,{children:A.slice(0,f).map(u=>{const C=R.get(u.id);return C?e.jsx(Zs,{children:e.jsx(br,{profileId:s.profileId,reference:u,sources:s.sources,referenceKey:C,isSelected:p.includes(u.id),isSelectionDisabled:!p.includes(u.id)&&$.length>=Ht,onSelect:()=>g(u.id)})},u.id):null})}):null,!E&&!D&&!A.length?e.jsxs("div",{className:"flex min-h-72 flex-col items-center justify-center rounded-xl border border-dashed border-white/[0.08] px-6 text-center",children:[e.jsx(zs,{size:28,strokeWidth:1,className:"mb-5 text-white/25","aria-hidden":!0}),e.jsx("h2",{className:"text-sm text-white/75",children:T||_?"No references found":V}),e.jsx("p",{className:"mt-2 max-w-sm text-xs leading-6 text-white/35",children:T||_?"Try another search or choose a different source.":"Ask your agent to save a design reference with an image to your library. It will appear here, ready to browse."})]}):null,!E&&!D&&A.length>f?e.jsx("div",{ref:I,role:"status",className:"py-8 text-center text-xs text-white/35",children:"Loading more references…"}):null]})]})},jr=1e4,Nr=({onBrowseProjects:s})=>{var a,l;const t=gs(),r=me(),i=ne({queryKey:["design-library",(a=t.data)==null?void 0:a.userId,(l=t.data)==null?void 0:l.isAuthenticated],queryFn:({signal:m})=>B("/profile/library",{signal:m}),enabled:!t.isPending,refetchInterval:jr,gcTime:0,retry:!1}),n=()=>{r==null||r.capture("library_reference_retry"),i.refetch()},o=e.jsx(Mt,{children:e.jsx(qe,{label:"Search references",value:"",isDisabled:!0})});return i.isError&&!i.data?e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[o,e.jsxs("div",{className:"m-auto max-w-md px-8 text-center",children:[e.jsx("h1",{className:"mb-3 text-lg font-medium",children:"References"}),e.jsx("p",{role:"alert",className:"text-sm text-white/50",children:i.error.message}),e.jsx("div",{className:"mt-5 flex justify-center gap-3",children:e.jsx(J,{variant:"ghost",onClick:s,children:"Projects"})})]})]}):i.data?e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[i.isError?e.jsxs("div",{role:"alert",className:"flex items-center justify-between gap-4 border-b border-white/10 px-8 py-3 text-xs text-white/50",children:[e.jsx("span",{children:"Could not refresh. Showing the last saved results."}),e.jsx(J,{variant:"ghost",onClick:n,children:"Try again"})]}):null,e.jsx(wr,{snapshot:i.data},i.data.profileId)]}):e.jsxs("div",{className:"flex min-h-0 flex-1 flex-col",children:[o,e.jsx("p",{role:"status",className:"m-auto text-xs text-white/40",children:"Loading references…"})]})},kr=({view:s,onNavigate:t})=>e.jsx("nav",{"aria-label":"Library",className:"flex items-center gap-1 rounded-lg bg-white/[0.03] p-1",children:["library","references"].map(r=>e.jsx("a",{href:r==="library"?"/rivet/library":"/rivet/library/references","aria-current":s===r?"page":void 0,onClick:i=>{i.metaKey||i.ctrlKey||i.shiftKey||i.altKey||(i.preventDefault(),t(r))},className:vs("rounded-md px-3 py-2 text-xs focus-visible:outline-2 focus-visible:outline-offset-2",s===r?"bg-white/[0.08] text-white":"text-white/45 hover:text-white/80"),children:r==="library"?"Projects":"References"},r))}),Sr=()=>{const s=_e(),t=async o=>{await s.cancelQueries({queryKey:["project-library"]}),s.setQueryData(["project-library","projects"],a=>a&&{projects:o(a.projects)}),s.setQueriesData({queryKey:["project-library","history"]},a=>{if(!a)return a;const l=o(a.projects),m=new Set(l.map(({id:f})=>f));return{projects:l,variants:a.variants.filter(({projectId:f})=>m.has(f))}}),s.invalidateQueries({queryKey:["project-library"]})},r=xe({mutationFn:({projectId:o,name:a})=>B(`/projects/${encodeURIComponent(o)}`,{method:"PATCH",body:{name:a}}),onSuccess:({project:o})=>t(a=>a.map(l=>l.id===o.id?{...l,name:o.name}:l))}),i=xe({mutationFn:({projectId:o,isPinned:a})=>B(`/projects/${encodeURIComponent(o)}/pin`,{method:a?"PUT":"DELETE"}),onSuccess:({project:o})=>t(a=>a.map(l=>l.id===o.id?{...l,pinnedAt:o.pinnedAt}:l))}),n=xe({mutationFn:o=>B(`/projects/${encodeURIComponent(o)}`,{method:"DELETE"}),onSuccess:async(o,a)=>{await t(l=>l.filter(({id:m})=>m!==a)),await s.cancelQueries({queryKey:["library-project-preview",a]}),s.removeQueries({queryKey:["library-project-preview",a]})}});return{setProjectPinned:async(o,a)=>{await i.mutateAsync({projectId:o,isPinned:a})},renameProject:async(o,a)=>{await r.mutateAsync({projectId:o,name:a})},removeProject:async o=>{await n.mutateAsync(o)}}},at=2500,_r=500,Ir=6e4,Rr=[],Cr=[],ke=({error:s,retry:t})=>e.jsxs("div",{className:"m-auto max-w-md px-8 text-center",children:[e.jsx("p",{className:"text-sm text-white/70",children:s.message}),e.jsx("button",{onClick:t,className:"mt-5 rounded-lg border border-white/15 px-4 py-2 text-xs text-white/70",children:"Try again"})]}),Er=()=>{var $e,Fe,Ue,He,Ke,Qe;const s=me(),t=_e(),{renameProject:r,removeProject:i,setProjectPinned:n}=Sr(),o=d.useRef(),[a,l]=d.useState(()=>We(new URL(window.location.href))),[m]=d.useState(()=>crypto.randomUUID()),f=d.useRef(0),b=d.useRef(null),p=ne({queryKey:["project-library","projects"],queryFn:({signal:c})=>B("/projects",{signal:c}),refetchInterval:at,retry:!1}),j=(($e=p.data)==null?void 0:$e.projects)??Rr,N=j.map(({id:c,projectPath:w})=>({id:c,projectPath:w})).sort((c,w)=>c.id.localeCompare(w.id)),R=ne({queryKey:["project-library","history",N],queryFn:({signal:c})=>B("",{signal:c}),placeholderData:c=>{if(!c)return;const w=new Map(c.projects.map(({id:F,projectPath:te})=>[F,te]));if(!j.every(({id:F,projectPath:te})=>w.get(F)===te))return;const P=new Set(j.map(({id:F})=>F));return{projects:c.projects.filter(({id:F})=>P.has(F)),variants:c.variants.filter(({projectId:F})=>P.has(F))}},enabled:j.length>0,refetchInterval:at,retry:!1}),S=new Map((Fe=R.data)==null?void 0:Fe.projects.map(c=>[c.id,c])),y=j.map(c=>{const w=S.get(c.id);return{...c,issue:w?w.issue:c.issue,historyIssue:w?w.historyIssue:c.historyIssue}}),k=((Ue=R.data)==null?void 0:Ue.variants)??Cr,$=As({queries:y.map(c=>({queryKey:["library-project-preview",c.id,c.projectPath],queryFn:({signal:w})=>B(`/projects/${c.id}/thumbnail`,{signal:w}),enabled:a.kind==="library",refetchInterval:Ir,retry:!1}))}),v=y.find(c=>c.id===a.projectId),_=k.find(c=>c.projectId===a.projectId&&c.sessionId===a.sessionId&&c.variantId===a.variantId),E=d.useCallback(c=>{window.history.pushState(null,"",ws(c)),l(c)},[]);d.useEffect(()=>{v?o.current=v.id:p.isSuccess&&!p.isFetching&&a.projectId===o.current&&a.projectId&&(o.current=void 0,E({kind:"library"}))},[v,a.projectId,p.isSuccess,p.isFetching,E]),d.useEffect(()=>{const c=()=>l(We(new URL(window.location.href)));return window.addEventListener("popstate",c),()=>window.removeEventListener("popstate",c)},[]),d.useEffect(()=>{const c=new AbortController;let w;const P=async()=>{try{const F=await B(`/views/${m}`,{method:"PUT",body:{isFocused:document.visibilityState==="visible"&&document.hasFocus()},signal:c.signal});for(const te of F.navigations){if(c.signal.aborted)return;if(te.sequence>f.current){let Ce="library";te.projectId&&(Ce="workspace"),te.variantId&&(Ce="preview"),E({...te,kind:Ce}),f.current=te.sequence}await B(`/views/${m}/acknowledgements`,{method:"POST",body:{sequence:te.sequence},signal:c.signal})}}catch{}c.signal.aborted||(w=setTimeout(()=>{P()},_r))};return P(),()=>{c.abort(),clearTimeout(w)}},[m,E]);const D=ne({queryKey:["library-workspace",a.projectId],queryFn:()=>B(`/projects/${a.projectId}/runtime`,{method:"POST"}),enabled:a.kind==="workspace"&&!!a.projectId&&(v==null?void 0:v.isAvailable)===!0,retry:!1,refetchOnWindowFocus:!1}),X=D.data?new URL(D.data.editorUrl).origin:null;d.useEffect(()=>{if(a.kind!=="workspace"||!X)return;const c=w=>{!b.current||w.source!==b.current.contentWindow||w.origin!==X||w.data!==Ss||(s==null||s.capture("library_view_changed",{view:"projects"}),E({kind:"library"}))};return window.addEventListener("message",c),()=>window.removeEventListener("message",c)},[a.kind,X,E,s]);const A=ne({queryKey:["library-preview",a.projectId,a.sessionId,a.variantId],queryFn:()=>B(`/projects/${a.projectId}/variants/${a.sessionId}/${a.variantId}/preview`,{method:"POST"}),enabled:a.kind==="preview"&&!!(_!=null&&_.hasStaticPreview),retry:!1,refetchOnWindowFocus:!1}),T=xe({mutationFn:c=>B(`/projects/${a.projectId}/variants/${a.sessionId}/${a.variantId}`,{method:"PATCH",body:{label:c}}),onSuccess:()=>t.invalidateQueries({queryKey:["project-library"]})}),W=c=>{const w=y.find(P=>P.id===c);s==null||s.capture("library_project_selected",{project_id:c,workspace_available:(w==null?void 0:w.isAvailable)??!1}),E({kind:"workspace",projectId:c})},V=xe({mutationFn:async c=>{const{projectPath:w}=await B("/folder-selections",{method:"POST"});return w===null?null:B(c?`/projects/${c}/workspace`:"/projects",{method:c?"PATCH":"POST",body:{projectPath:w}})},onSuccess:c=>{c&&(t.invalidateQueries({queryKey:["project-library"]}),s==null||s.capture("library_project_selected",{project_id:c.project.id,workspace_available:c.project.isAvailable}),E({kind:"workspace",projectId:c.project.id}))},onSettled:(c,w,P)=>{s==null||s.capture("library_open_project_closed",{is_relink:!!P})}}),I=c=>{V.isPending||(s==null||s.capture("library_open_project_opened",{is_relink:!!c}),V.mutate(c))},g=()=>{s==null||s.capture("library_view_changed",{view:"projects"}),E({kind:"library"})},q=()=>{s==null||s.capture("library_view_changed",{view:"workspace"}),E({...a,kind:"workspace"})},u=()=>{s==null||s.capture("library_history_retry"),R.refetch()};let C;if(a.kind==="workspace"&&(v==null?void 0:v.isAvailable)!==!1||a.kind==="preview"){let c=!1,w=e.jsxs("div",{className:"m-auto flex items-center gap-2 text-xs text-white/40",children:[e.jsx(Tt,{size:14,className:"animate-spin"}),"Opening ",(v==null?void 0:v.name)??"project","…"]});if(p.data&&!v||R.data&&a.variantId&&!_)w=e.jsx("div",{className:"m-auto text-sm text-white/60",children:"This project or direction is no longer in your library."});else if(a.kind==="preview"&&R.error&&!R.data)w=e.jsx(ke,{error:R.error,retry:u});else if(a.kind==="workspace"&&D.error)w=e.jsx(ke,{error:D.error,retry:()=>{D.refetch()}});else if(a.kind==="workspace"&&D.data){c=!0;const P=new URL(D.data.editorUrl);P.searchParams.set("library","1"),P.searchParams.set("libraryOrigin",window.location.origin),a.sessionId&&a.variantId&&(P.searchParams.set("historySession",a.sessionId),P.searchParams.set("historyVariant",a.variantId)),w=e.jsx("iframe",{ref:b,title:`${(v==null?void 0:v.name)??"Project"} workspace`,src:P.toString(),allow:"clipboard-write","data-rivet-private":!0,className:"ph-no-capture min-h-0 w-full flex-1 border-0"},P.toString())}else a.kind==="preview"&&A.error?w=e.jsx(ke,{error:A.error,retry:()=>{A.refetch()}}):a.kind==="preview"&&A.data?w=e.jsx("iframe",{title:`${(_==null?void 0:_.label)??"Saved direction"} preview`,src:A.data.url,sandbox:"allow-scripts allow-same-origin allow-forms allow-popups",className:"min-h-0 w-full flex-1 border-0 bg-white"}):a.kind==="preview"&&_&&!_.hasStaticPreview&&(w=e.jsxs("div",{className:"m-auto max-w-sm text-center",children:[e.jsx("p",{className:"text-sm",children:_.hasInteractivePreview?"Open this direction in its workspace":"This direction contains saved code changes"}),e.jsx("p",{className:"mt-2 text-xs leading-6 text-white/40",children:_.hasInteractivePreview?"Rivet will start the preview with this project’s dependencies and configuration.":"Open the project to continue working with its saved history."}),e.jsx("button",{onClick:q,disabled:(v==null?void 0:v.isAvailable)===!1,className:"mt-5 rounded-lg bg-white px-4 py-2.5 text-xs font-medium text-black disabled:opacity-30",children:"Open workspace"})]}));C=e.jsxs(e.Fragment,{children:[a.kind==="preview"?e.jsxs("header",{className:"flex h-14 shrink-0 items-center gap-3 border-b border-white/[0.07] px-5",children:[e.jsx("button",{"aria-label":"Back to projects",onClick:g,className:"rounded p-1.5 text-white/45 hover:bg-white/5",children:e.jsx(js,{size:15})}),e.jsx("span",{className:"text-xs text-white/40",children:v==null?void 0:v.name}),_?e.jsxs(e.Fragment,{children:[e.jsx("span",{className:"text-white/20",children:"/"}),e.jsxs("form",{onSubmit:P=>{P.preventDefault();const F=new FormData(P.currentTarget);T.mutate(String(F.get("label")))},className:"flex min-w-0 flex-1 gap-2",children:[e.jsx("input",{name:"label","aria-label":"Direction name",defaultValue:_.label,className:"max-w-xs min-w-0 flex-1 bg-transparent text-xs text-white/80 outline-none"}),e.jsx("button",{disabled:T.isPending,className:"text-[10px] text-white/30 hover:text-white",children:"Rename"})]},`${_.projectId}:${_.variantId}`)]}):e.jsx("span",{className:"flex-1"}),a.kind==="preview"?e.jsxs("button",{onClick:q,disabled:(v==null?void 0:v.isAvailable)===!1,className:"flex items-center gap-1.5 rounded-md border border-white/10 px-3 py-1.5 text-[11px] text-white/70 disabled:opacity-30",children:["Edit in project",e.jsx(St,{size:12})]}):null]}):null,a.kind==="workspace"&&!c?e.jsx("button",{onClick:g,className:"absolute top-5 left-5 rounded px-2 py-1 text-xs text-white/50 hover:bg-white/5 hover:text-white",children:"Projects"}):null,T.error?e.jsx("p",{role:"alert",className:"px-5 py-2 text-xs text-red-200",children:T.error.message}):null,w]})}let K=C;p.error&&!p.data?K=e.jsx(ke,{error:p.error,retry:()=>{p.refetch()}}):p.isPending&&(K=e.jsx("div",{role:"status",className:"m-auto text-xs text-white/40",children:"Loading projects…"}));const Z=a.kind==="references"?"references":"library",de=e.jsx(kr,{view:Z,onNavigate:c=>{s==null||s.capture("library_view_changed",{view:c==="references"?"references":"projects"}),E({kind:c})}});return a.kind==="references"&&(K=e.jsx(Nr,{onBrowseProjects:g})),e.jsxs(e.Fragment,{children:[e.jsx(Js,{projects:y,variants:(He=R.data)==null?void 0:He.variants,historyError:(Ke=R.error)==null?void 0:Ke.message,onRetryHistory:u,projectPreviews:Object.fromEntries(y.map((c,w)=>{var P,F;return[c.id,(F=(P=$[w])==null?void 0:P.data)==null?void 0:F.preview]})),selectedProjectId:a.projectId??null,onSelectProject:W,onBrowseLibrary:g,navigation:de,view:Z,onOpenProject:I,onRenameProject:r,onRemoveProject:i,onSetProjectPinned:n,accountMenu:e.jsx(Ns,{side:"top",align:"start"}),isOpeningProject:V.isPending,projectOpenError:(Qe=V.error)==null?void 0:Qe.message,onSearchCompleted:c=>s==null?void 0:s.capture("library_search_completed",{query_length:c}),children:K}),e.jsx(ks,{position:"bottom-right",theme:"dark"})]})},Pr=async s=>{const t=Ts(),r=await Cs("/api/library/browser-sessions",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)});if(!r.ok){const i=Y({error:x()}).safeParse(await r.json().catch(()=>null));throw new Error(i.success?i.data.error:"Could not start a library session.")}Es(Ps(await r.json()),t)},Tr=()=>{const s=d.useSyncExternalStore(jt,Is),{startLogin:t,isStartingLogin:r,loginError:i}=Rs("library",Pr);return e.jsx("main",{className:"flex min-h-screen items-center justify-center bg-[#111215] px-6 text-white",children:e.jsxs("div",{className:"w-full max-w-sm rounded-2xl border border-white/10 bg-white/[0.04] p-8 text-center shadow-2xl",children:[e.jsx("h1",{className:"text-2xl font-semibold tracking-tight",children:"Rivet"}),e.jsx("p",{className:"mt-3 text-sm leading-6 text-white/60",children:"Sign in to open your project library on this computer."}),e.jsxs("button",{type:"button",onClick:()=>void t(),disabled:r,className:"mt-7 inline-flex h-10 w-full items-center justify-center gap-2 rounded-lg bg-white px-4 text-sm font-medium text-black disabled:opacity-60",children:[r?e.jsx(Tt,{size:16,className:"animate-spin"}):null,r?"Connecting…":"Continue with Google"]}),i||s?e.jsx("p",{role:"alert",className:"mt-4 text-sm text-red-300",children:i??s}):null]})})},Ar=()=>d.useSyncExternalStore(jt,_s)?e.jsx(Er,{}):e.jsx(Tr,{});export{Ar as default};
|
|
37
|
-
//# sourceMappingURL=LibraryEntry-
|
|
37
|
+
//# sourceMappingURL=LibraryEntry-Cr4GFYXW.js.map
|