modular-studio 1.0.6 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/Badge-Bsy2H_p2.js +1 -0
- package/dist/assets/GraphPanel-D4X3faxA.js +47 -0
- package/dist/assets/{Input-ndEGQSgx.js → Input-Dyb88Erk.js} +1 -1
- package/dist/assets/KnowledgeTab-BccWz7Np.js +5 -0
- package/dist/assets/MemoryTab-Y_66cE01.js +16 -0
- package/dist/assets/QualificationTab-Dm9dEIpM.js +1 -0
- package/dist/assets/ReviewTab-BrfXSyyf.js +104 -0
- package/dist/assets/{Section-CgmwAj_2.js → Section-68XDCFTl.js} +1 -1
- package/dist/assets/TestTab-CLKRT63X.js +42 -0
- package/dist/assets/{ToolsTab-C10Ulm8b.js → ToolsTab-xumi9Uds.js} +1 -1
- package/dist/assets/icons-CS8RUPBi.js +1 -0
- package/dist/assets/index-B2bm0161.css +1 -0
- package/dist/assets/index-C626nWuA.js +422 -0
- package/dist/assets/services-BDk6yY4o.js +369 -0
- package/dist/index.html +4 -4
- package/dist-server/bin/modular-mcp.js +1 -0
- package/dist-server/server/index.d.ts.map +1 -1
- package/dist-server/server/index.js +30 -0
- package/dist-server/server/mcp/manager.d.ts +3 -0
- package/dist-server/server/mcp/manager.d.ts.map +1 -1
- package/dist-server/server/mcp/manager.js +64 -3
- package/dist-server/server/migrations/index.d.ts +11 -0
- package/dist-server/server/migrations/index.d.ts.map +1 -0
- package/dist-server/server/migrations/index.js +57 -0
- package/dist-server/server/routes/analytics.d.ts +3 -0
- package/dist-server/server/routes/analytics.d.ts.map +1 -0
- package/dist-server/server/routes/analytics.js +24 -0
- package/dist-server/server/routes/connectors/airtable.d.ts +7 -0
- package/dist-server/server/routes/connectors/airtable.d.ts.map +1 -0
- package/dist-server/server/routes/connectors/airtable.js +119 -0
- package/dist-server/server/routes/connectors/confluence.d.ts +7 -0
- package/dist-server/server/routes/connectors/confluence.d.ts.map +1 -0
- package/dist-server/server/routes/connectors/confluence.js +176 -0
- package/dist-server/server/routes/connectors/github.d.ts +7 -0
- package/dist-server/server/routes/connectors/github.d.ts.map +1 -0
- package/dist-server/server/routes/connectors/github.js +195 -0
- package/dist-server/server/routes/connectors/gmail.d.ts +7 -0
- package/dist-server/server/routes/connectors/gmail.d.ts.map +1 -0
- package/dist-server/server/routes/connectors/gmail.js +115 -0
- package/dist-server/server/routes/connectors/google-docs.d.ts +10 -0
- package/dist-server/server/routes/connectors/google-docs.d.ts.map +1 -0
- package/dist-server/server/routes/connectors/google-docs.js +165 -0
- package/dist-server/server/routes/connectors/google-drive.d.ts +7 -0
- package/dist-server/server/routes/connectors/google-drive.d.ts.map +1 -0
- package/dist-server/server/routes/connectors/google-drive.js +163 -0
- package/dist-server/server/routes/connectors/google-sheets.d.ts +7 -0
- package/dist-server/server/routes/connectors/google-sheets.d.ts.map +1 -0
- package/dist-server/server/routes/connectors/google-sheets.js +90 -0
- package/dist-server/server/routes/connectors/hubspot.d.ts +7 -0
- package/dist-server/server/routes/connectors/hubspot.d.ts.map +1 -0
- package/dist-server/server/routes/connectors/hubspot.js +134 -0
- package/dist-server/server/routes/connectors/index.d.ts +6 -0
- package/dist-server/server/routes/connectors/index.d.ts.map +1 -0
- package/dist-server/server/routes/connectors/index.js +38 -0
- package/dist-server/server/routes/connectors/jira.d.ts +7 -0
- package/dist-server/server/routes/connectors/jira.d.ts.map +1 -0
- package/dist-server/server/routes/connectors/jira.js +151 -0
- package/dist-server/server/routes/connectors/linear.d.ts +7 -0
- package/dist-server/server/routes/connectors/linear.d.ts.map +1 -0
- package/dist-server/server/routes/connectors/linear.js +154 -0
- package/dist-server/server/routes/connectors/notion.d.ts +10 -0
- package/dist-server/server/routes/connectors/notion.d.ts.map +1 -0
- package/dist-server/server/routes/connectors/notion.js +201 -0
- package/dist-server/server/routes/connectors/plane.d.ts +10 -0
- package/dist-server/server/routes/connectors/plane.d.ts.map +1 -0
- package/dist-server/server/routes/connectors/plane.js +189 -0
- package/dist-server/server/routes/connectors/shared.d.ts +25 -0
- package/dist-server/server/routes/connectors/shared.d.ts.map +1 -0
- package/dist-server/server/routes/connectors/shared.js +202 -0
- package/dist-server/server/routes/connectors/slack.d.ts +7 -0
- package/dist-server/server/routes/connectors/slack.d.ts.map +1 -0
- package/dist-server/server/routes/connectors/slack.js +153 -0
- package/dist-server/server/routes/cost.d.ts +3 -0
- package/dist-server/server/routes/cost.d.ts.map +1 -0
- package/dist-server/server/routes/cost.js +113 -0
- package/dist-server/server/routes/graph.d.ts +11 -0
- package/dist-server/server/routes/graph.d.ts.map +1 -0
- package/dist-server/server/routes/graph.js +213 -0
- package/dist-server/server/routes/lessons.d.ts.map +1 -1
- package/dist-server/server/routes/lessons.js +119 -5
- package/dist-server/server/routes/llm.d.ts.map +1 -1
- package/dist-server/server/routes/llm.js +85 -18
- package/dist-server/server/routes/metaprompt-v2.d.ts +3 -0
- package/dist-server/server/routes/metaprompt-v2.d.ts.map +1 -0
- package/dist-server/server/routes/metaprompt-v2.js +104 -0
- package/dist-server/server/routes/qualification.d.ts.map +1 -1
- package/dist-server/server/routes/qualification.js +61 -11
- package/dist-server/server/routes/skills-search.d.ts.map +1 -1
- package/dist-server/server/routes/skills-search.js +10 -0
- package/dist-server/server/routes/tool-analytics.d.ts +3 -0
- package/dist-server/server/routes/tool-analytics.d.ts.map +1 -0
- package/dist-server/server/routes/tool-analytics.js +47 -0
- package/dist-server/server/services/adapters/sqliteAdapter.d.ts +1 -0
- package/dist-server/server/services/adapters/sqliteAdapter.d.ts.map +1 -1
- package/dist-server/server/services/adapters/sqliteAdapter.js +78 -48
- package/dist-server/server/services/credentialStore.d.ts +10 -0
- package/dist-server/server/services/credentialStore.d.ts.map +1 -0
- package/dist-server/server/services/credentialStore.js +123 -0
- package/dist-server/server/services/hindsightClient.d.ts.map +1 -1
- package/dist-server/server/services/hindsightClient.js +1 -0
- package/dist-server/server/services/lessonExtractor.d.ts +2 -0
- package/dist-server/server/services/lessonExtractor.d.ts.map +1 -1
- package/dist-server/server/services/lessonExtractor.js +7 -2
- package/dist-server/server/services/repoIndexer.d.ts +7 -1
- package/dist-server/server/services/repoIndexer.d.ts.map +1 -1
- package/dist-server/server/services/repoIndexer.js +295 -94
- package/dist-server/server/services/sqliteStore.d.ts +64 -0
- package/dist-server/server/services/sqliteStore.d.ts.map +1 -1
- package/dist-server/server/services/sqliteStore.js +238 -0
- package/dist-server/src/config.d.ts +2 -0
- package/dist-server/src/config.d.ts.map +1 -0
- package/dist-server/src/config.js +3 -0
- package/dist-server/src/graph/db.d.ts +46 -0
- package/dist-server/src/graph/db.d.ts.map +1 -0
- package/dist-server/src/graph/db.js +241 -0
- package/dist-server/src/graph/extractors/code.d.ts +12 -0
- package/dist-server/src/graph/extractors/code.d.ts.map +1 -0
- package/dist-server/src/graph/extractors/code.js +239 -0
- package/dist-server/src/graph/extractors/cross-type.d.ts +16 -0
- package/dist-server/src/graph/extractors/cross-type.d.ts.map +1 -0
- package/dist-server/src/graph/extractors/cross-type.js +67 -0
- package/dist-server/src/graph/extractors/markdown.d.ts +29 -0
- package/dist-server/src/graph/extractors/markdown.d.ts.map +1 -0
- package/dist-server/src/graph/extractors/markdown.js +224 -0
- package/dist-server/src/graph/extractors/yaml.d.ts +15 -0
- package/dist-server/src/graph/extractors/yaml.d.ts.map +1 -0
- package/dist-server/src/graph/extractors/yaml.js +104 -0
- package/dist-server/src/graph/index.d.ts +62 -0
- package/dist-server/src/graph/index.d.ts.map +1 -0
- package/dist-server/src/graph/index.js +67 -0
- package/dist-server/src/graph/packer.d.ts +19 -0
- package/dist-server/src/graph/packer.d.ts.map +1 -0
- package/dist-server/src/graph/packer.js +134 -0
- package/dist-server/src/graph/resolver.d.ts +12 -0
- package/dist-server/src/graph/resolver.d.ts.map +1 -0
- package/dist-server/src/graph/resolver.js +81 -0
- package/dist-server/src/graph/scanner.d.ts +34 -0
- package/dist-server/src/graph/scanner.d.ts.map +1 -0
- package/dist-server/src/graph/scanner.js +252 -0
- package/dist-server/src/graph/traverser.d.ts +17 -0
- package/dist-server/src/graph/traverser.d.ts.map +1 -0
- package/dist-server/src/graph/traverser.js +185 -0
- package/dist-server/src/graph/types.d.ts +117 -0
- package/dist-server/src/graph/types.d.ts.map +1 -0
- package/dist-server/src/graph/types.js +63 -0
- package/dist-server/src/metaprompt/v2/assembler.d.ts +3 -0
- package/dist-server/src/metaprompt/v2/assembler.d.ts.map +1 -0
- package/dist-server/src/metaprompt/v2/assembler.js +261 -0
- package/dist-server/src/metaprompt/v2/context-strategist.d.ts +3 -0
- package/dist-server/src/metaprompt/v2/context-strategist.d.ts.map +1 -0
- package/dist-server/src/metaprompt/v2/context-strategist.js +173 -0
- package/dist-server/src/metaprompt/v2/evaluator.d.ts +3 -0
- package/dist-server/src/metaprompt/v2/evaluator.d.ts.map +1 -0
- package/dist-server/src/metaprompt/v2/evaluator.js +281 -0
- package/dist-server/src/metaprompt/v2/index.d.ts +41 -0
- package/dist-server/src/metaprompt/v2/index.d.ts.map +1 -0
- package/dist-server/src/metaprompt/v2/index.js +90 -0
- package/dist-server/src/metaprompt/v2/parser.d.ts +3 -0
- package/dist-server/src/metaprompt/v2/parser.d.ts.map +1 -0
- package/dist-server/src/metaprompt/v2/parser.js +138 -0
- package/dist-server/src/metaprompt/v2/pattern-selector.d.ts +3 -0
- package/dist-server/src/metaprompt/v2/pattern-selector.d.ts.map +1 -0
- package/dist-server/src/metaprompt/v2/pattern-selector.js +154 -0
- package/dist-server/src/metaprompt/v2/researcher.d.ts +3 -0
- package/dist-server/src/metaprompt/v2/researcher.d.ts.map +1 -0
- package/dist-server/src/metaprompt/v2/researcher.js +194 -0
- package/dist-server/src/metaprompt/v2/tool-discovery.d.ts +74 -0
- package/dist-server/src/metaprompt/v2/tool-discovery.d.ts.map +1 -0
- package/dist-server/src/metaprompt/v2/tool-discovery.js +290 -0
- package/dist-server/src/metaprompt/v2/types.d.ts +154 -0
- package/dist-server/src/metaprompt/v2/types.d.ts.map +1 -0
- package/dist-server/src/metaprompt/v2/types.js +2 -0
- package/dist-server/src/services/contradictionDetector.js +1 -1
- package/dist-server/src/services/llmService.d.ts +61 -0
- package/dist-server/src/services/llmService.d.ts.map +1 -0
- package/dist-server/src/services/llmService.js +222 -0
- package/dist-server/src/store/knowledgeBase.d.ts +5 -1
- package/dist-server/src/store/knowledgeBase.d.ts.map +1 -1
- package/dist-server/src/store/knowledgeBase.js +0 -1
- package/dist-server/src/store/mcp-registry.d.ts +29 -0
- package/dist-server/src/store/mcp-registry.d.ts.map +1 -0
- package/dist-server/src/store/mcp-registry.js +1303 -0
- package/dist-server/src/types/registry.types.d.ts +13 -0
- package/dist-server/src/types/registry.types.d.ts.map +1 -0
- package/dist-server/src/types/registry.types.js +2 -0
- package/dist-server/tsconfig.server.tsbuildinfo +1 -1
- package/package.json +118 -105
- package/scripts/cleanup-worktrees.ps1 +29 -0
- package/dist/assets/Badge-DrUmDAXz.js +0 -1
- package/dist/assets/KnowledgeTab-CxlC76Rf.js +0 -4
- package/dist/assets/MemoryTab-CUScYWs9.js +0 -16
- package/dist/assets/QualificationTab-BqnWSQHm.js +0 -1
- package/dist/assets/ReviewTab-DKYl6cR9.js +0 -103
- package/dist/assets/TestTab-iJ2vCf9l.js +0 -33
- package/dist/assets/icons-MKpPNvV8.js +0 -1
- package/dist/assets/index-B_ip7Amg.css +0 -1
- package/dist/assets/index-gBy3427k.js +0 -143
- package/dist/assets/services-CTWXQK6j.js +0 -356
|
@@ -1 +1 @@
|
|
|
1
|
-
import{r as l,j as t}from"./vendor-D1h_O76p.js";import{u as c}from"./index-
|
|
1
|
+
import{r as l,j as t}from"./vendor-D1h_O76p.js";import{u as c}from"./index-C626nWuA.js";const d=l.forwardRef(function({label:o,error:e,className:r="",style:n,...a},i){const s=c();return t.jsxs("div",{className:"flex flex-col gap-1",children:[o&&t.jsx("label",{className:"text-[13px] tracking-wider uppercase font-semibold",style:{color:s.textMuted,fontFamily:"'Geist Mono', monospace"},children:o}),t.jsx("input",{ref:i,className:`w-full px-3 py-2 rounded-md outline-none nodrag ${r}`,style:{background:s.inputBg,border:`1px solid ${e?s.statusError:s.border}`,color:s.textPrimary,fontFamily:"'Geist Sans', sans-serif",fontSize:16,lineHeight:1.5,...n},...a}),e&&t.jsx("span",{className:"text-[13px]",style:{color:s.statusError},children:e})]})});export{d as I};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/GraphPanel-D4X3faxA.js","assets/vendor-D1h_O76p.js","assets/index-C626nWuA.js","assets/services-BDk6yY4o.js","assets/stores-CeKWz7ou.js","assets/icons-CS8RUPBi.js","assets/index-B2bm0161.css"])))=>i.map(i=>d[i]);
|
|
2
|
+
import{A as E,u as K,z as L,K as Q,N as le,Q as ce,S as de,_ as ye}from"./services-BDk6yY4o.js";import{j as e,r as l,R as ge}from"./vendor-D1h_O76p.js";import{u as U,b as Y}from"./index-C626nWuA.js";import{c as be,p as je}from"./stores-CeKWz7ou.js";import{a as ke,C as Ne,a1 as we,aC as ne,Q as H,X as pe,i as ve,aI as ae,aJ as te,aK as ue,an as xe,Z as Se,a2 as oe,a0 as re,a3 as ie,x as Ce,$ as Fe,D as se,S as De,a4 as Te,aL as Me,aM as Ie}from"./icons-CS8RUPBi.js";function Pe(t,p){const r=new Map;for(const i of t)r.set(i.id,[]);for(const i of p)i.kind==="imports"&&r.get(i.sourceFile)?.push(i.targetFile);let u=0;const h=0,b=1,d=2,k=new Map;for(const i of t)k.set(i.id,h);function c(i){k.set(i,b);for(const y of r.get(i)??[])k.get(y)===b?u++:k.get(y)===h&&c(y);k.set(i,d)}for(const i of t)k.get(i.id)===h&&c(i.id);return u}const $e=be()(je((t,p)=>({nodes:[],relations:[],stats:null,lastScanResult:null,lastQueryResult:null,readiness:null,selectedNodeId:null,highlightIds:new Set,scanning:!1,querying:!1,error:null,lastScanTime:null,rootPath:null,scan:async r=>{t({scanning:!0,error:null});try{const h=await(await fetch(`${E}/graph/scan`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({rootPath:r})})).json();if(h.status!=="ok")throw new Error(h.error);const{totalFiles:b,totalSymbols:d,totalRelations:k,durationMs:c}=h.data,y=await(await fetch(`${E}/graph/data`)).json(),T=y.status==="ok"?y.data.nodes:[],M=y.status==="ok"?y.data.relations:[];t({nodes:T,relations:M,lastScanResult:{totalFiles:b,totalSymbols:d,totalRelations:k,durationMs:c},stats:{nodes:T.length,symbols:0,relations:M.length},lastScanTime:Date.now(),rootPath:r,scanning:!1}),p().computeReadiness()}catch(u){t({scanning:!1,error:u instanceof Error?u.message:String(u)})}},scanSources:async r=>{t({scanning:!0,error:null});try{const h=await(await fetch(`${E}/graph/scan-sources`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sources:r})})).json();if(h.status!=="ok")throw new Error(h.error);const{totalFiles:b,totalSymbols:d,totalRelations:k,durationMs:c}=h.data,y=await(await fetch(`${E}/graph/data`)).json(),T=y.status==="ok"?y.data.nodes:[],M=y.status==="ok"?y.data.relations:[];t({nodes:T,relations:M,lastScanResult:{totalFiles:b,totalSymbols:d,totalRelations:k,durationMs:c},stats:{nodes:T.length,symbols:0,relations:M.length},lastScanTime:Date.now(),rootPath:"(all sources)",scanning:!1}),p().computeReadiness()}catch(u){t({scanning:!1,error:u instanceof Error?u.message:String(u)})}},query:async(r,u,h)=>{t({querying:!0,error:null});try{const d=await(await fetch(`${E}/graph/query`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({query:r,tokenBudget:u,taskType:h})})).json();if(d.status!=="ok")throw new Error(d.error);const k=new Set(d.data.entryPoints.map(c=>c.fileId));t({lastQueryResult:d.data,highlightIds:k,querying:!1})}catch(b){t({querying:!1,error:b instanceof Error?b.message:String(b)})}},fetchStatus:async()=>{try{const u=await(await fetch(`${E}/graph/status`)).json();u.status==="ok"&&t({stats:u.data})}catch(r){t({error:r instanceof Error?r.message:String(r)})}},selectNode:r=>t({selectedNodeId:r}),setHighlights:r=>t({highlightIds:r}),computeReadiness:()=>{const{nodes:r,relations:u}=p();if(r.length===0){t({readiness:null});return}const h=new Set;for(const n of u)h.add(n.sourceFile),h.add(n.targetFile);const b=r.length>0?h.size/r.length:0,d=r.filter(n=>!n.path.includes(".test.")&&!n.path.includes(".spec.")&&!n.path.includes("__tests__")),k=new Set(u.filter(n=>n.kind==="tested_by").map(n=>n.sourceFile)),c=d.length>0?d.filter(n=>k.has(n.id)).length/d.length:0,i=new Set(r.map(n=>n.path.split("/").slice(0,-1).join("/"))),y=new Set(u.filter(n=>n.kind==="documents").map(n=>r.find(s=>s.id===n.sourceFile)?.path.split("/").slice(0,-1).join("/")??"")),T=i.size>0?y.size/i.size:0,M=Pe(r,u),z=new Map;for(const n of u)n.kind==="imports"&&z.set(n.targetFile,(z.get(n.targetFile)??0)+1);const o=z.size>0?Math.max(...Array.from(z.values())):0,N=r.length>0?o/r.length:0,f=r.filter(n=>!h.has(n.id)).length,I=r.length>0?f/r.length*20:0,S=Math.min(M*5,20),D=N*10,_=b*30+c*25+T*15+30-I-S-D,q=Math.max(0,Math.min(100,Math.round(_)));t({readiness:{coverage:b,testCoupling:c,docCoupling:T,circularDeps:M,hubConcentration:N,orphanFiles:f,score:q}})},clearError:()=>t({error:null})}),{name:"modular-graph-store",partialize:t=>({lastScanTime:t.lastScanTime,rootPath:t.rootPath})}));function Ge({node:t}){const p=U();return e.jsx("div",{className:"pl-4 py-0.5 text-[11px] truncate",style:{color:p.textFaint,fontFamily:"'Geist Mono', monospace"},title:t.meta?.firstSentence??t.title,children:t.title})}function Re({node:t}){const p=U(),[r,u]=l.useState(!1);return e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>u(h=>!h),className:"flex items-center gap-1.5 w-full py-0.5 hover:opacity-80 transition-opacity",style:{color:p.textDim,fontFamily:"'Geist Mono', monospace",fontSize:"11px"},children:[r?e.jsx(ke,{size:9}):e.jsx(Ne,{size:9}),e.jsx("span",{className:"flex-1 text-left",children:t.title}),e.jsxs("span",{style:{color:p.textFaint},children:["(",t.children.length,")"]})]}),r&&t.children.map(h=>e.jsx(Ge,{node:h},h.nodeId))]})}function fe({index:t}){const p=U(),r=t.root.children.filter(u=>u.children.length>0);return r.length===0?null:e.jsx("div",{className:"mt-2 pt-2 space-y-0.5",style:{borderTop:`1px solid ${p.borderSubtle}`},children:r.map(u=>e.jsx(Re,{node:u},u.nodeId))})}function Z(t){return t>=100?"Full":t>=75?"Detail":t>=50?"Summary":t>=25?"Headlines":"Mention"}function ze(t){return t>=100?"Full (100%) — Complete document, every line included. Best for specs, schemas, and ground-truth sources.":t>=75?"Detail (75%) — Main content with details; minor boilerplate trimmed. Good default for most sources.":t>=50?"Summary (50%) — Key points and structure; verbose sections condensed. Good for large reports.":t>=25?"Headlines (25%) — Section titles and key statements only. Good for broad awareness context.":"Mention (10%) — Brief reference only; title and top-level summary. Good for background context."}function Ee(){const t=U(),p=K(s=>s.channels),r=l.useMemo(()=>p.filter(s=>s.path&&!s.path.includes(".git")&&!s.contentSourceId),[p]),u=K(s=>s.setChannelDepth),h=K(s=>s.setChannelKnowledgeType),b=K(s=>s.removeChannel),d=K(s=>s.setShowFilePicker),k=L(s=>s.indexes),c=L(s=>s.loading),i=L(s=>s.errors),y=Y(s=>s.scanDirectory),T=Y(s=>s.lastDir),M=Y(s=>s.scanning),z=l.useRef(null),[o,N]=l.useState(!1),[f,I]=l.useState(""),[S,D]=l.useState(!1),_=l.useCallback(s=>{const m=k[s.path],w=(s.depth||100)/100;return Math.round(m?m.index.totalTokens*w:(s.baseTokens??0)*w)},[k]),q=l.useCallback(async()=>{N(!0);const s=r.filter(m=>m.enabled&&m.path).map(m=>m.path);s.length>0&&await L.getState().indexFiles(s),N(!1)},[r]),n=l.useCallback(async s=>{const m=s.target.files;if(s.target.value="",!m||m.length===0)return;const w=m[0];if(w.path){const g=w.path.includes("\\")?"\\":"/",R=w.path.split(g);R.pop();const C=R.join(g);I(C),D(!0),await y(C)}else{const R=(w.webkitRelativePath||"").split("/")[0]||"";I(R||""),D(!0)}},[y]),F=l.useCallback(async()=>{f.trim()&&(await y(f.trim()),I(""),D(!1))},[f,y]);return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>d(!0),className:"flex items-center justify-center gap-1.5 flex-1 px-2.5 py-2 rounded text-[12px] tracking-wide uppercase cursor-pointer transition-colors",style:{background:"transparent",border:"1px solid",borderColor:t.border,color:t.textDim,fontFamily:"'Geist Mono', monospace",minHeight:"44px"},onMouseEnter:s=>{s.currentTarget.style.borderColor=t.isDark?"#FF6B1A":"#FE5000",s.currentTarget.style.color=t.isDark?"#FF6B1A":"#FE5000"},onMouseLeave:s=>{s.currentTarget.style.borderColor=t.border,s.currentTarget.style.color=t.textDim},children:[e.jsx(we,{size:10})," Files"]}),e.jsxs("button",{type:"button",onClick:()=>{D(!0),z.current?.click()},className:"flex items-center justify-center gap-1.5 flex-1 px-2.5 py-2 rounded text-[12px] tracking-wide uppercase cursor-pointer transition-colors",style:{background:S?"#24292F15":"transparent",border:"1px solid",borderColor:S?"#24292F":t.border,color:S?"#24292F":t.textDim,fontFamily:"'Geist Mono', monospace",minHeight:"44px"},onMouseEnter:s=>{s.currentTarget.style.borderColor=t.isDark?"#FF6B1A":"#FE5000",s.currentTarget.style.color=t.isDark?"#FF6B1A":"#FE5000"},onMouseLeave:s=>{s.currentTarget.style.borderColor=S?"#24292F":t.border,s.currentTarget.style.color=S?"#24292F":t.textDim},children:[e.jsx(ne,{size:10})," Directory"]})]}),e.jsx("input",{ref:z,type:"file",webkitdirectory:"",className:"hidden",onChange:n,"aria-hidden":"true",tabIndex:-1}),S&&e.jsxs("div",{className:"flex gap-1.5",children:[e.jsx("input",{type:"text",value:f,onChange:s=>I(s.target.value),placeholder:T||"/path/to/directory",className:"flex-1 px-2.5 py-1.5 rounded text-[13px] outline-none",style:{background:t.inputBg,border:`1px solid ${t.border}`,color:t.textPrimary,fontFamily:"'Geist Sans', sans-serif"},onKeyDown:s=>s.key==="Enter"&&F()}),e.jsx("button",{type:"button",onClick:()=>z.current?.click(),className:"px-3 py-1.5 rounded text-[12px] font-semibold uppercase tracking-wide transition-opacity",style:{background:"transparent",border:"1px solid #FE5000",color:"#FE5000",fontFamily:"'Geist Mono', monospace"},children:"Browse"}),e.jsx("button",{type:"button",onClick:F,disabled:M||!f.trim(),className:"px-3 py-1.5 rounded text-[12px] font-semibold uppercase tracking-wide transition-opacity",style:{background:"#24292F",color:"#fff",opacity:M||!f.trim()?.5:1,fontFamily:"'Geist Mono', monospace"},children:M?e.jsx(H,{size:10,className:"animate-spin"}):"Scan"})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx("button",{type:"button",onClick:q,disabled:o||r.filter(s=>s.enabled).length===0,className:"flex items-center gap-2 px-4 py-2.5 rounded text-[13px] font-semibold transition-all duration-200",style:{background:o?"#f1c40f":"#2ecc71",color:"#fff",opacity:r.filter(s=>s.enabled).length===0?.5:1,fontFamily:"'Geist Sans', sans-serif",cursor:o||r.filter(s=>s.enabled).length===0?"not-allowed":"pointer",minWidth:"120px"},children:o?e.jsxs(e.Fragment,{children:[e.jsx(H,{size:14,className:"animate-spin"}),"Indexing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(ne,{size:14}),"Index Files"]})})}),e.jsx("div",{style:{display:"grid",gridTemplateColumns:"repeat(auto-fill, minmax(340px, 1fr))",gap:"12px"},children:r.map(s=>{const m=s.depth||100,w=Q[s.knowledgeType],g=!!k[s.path],R=!!c[s.path],C=!!i[s.path],B=_(s);return e.jsxs("div",{className:"p-3 rounded border",style:{borderColor:s.enabled?t.border:t.borderSubtle,background:s.enabled?t.isDark?"#ffffff05":"#00000005":t.isDark?"#ffffff02":"#00000002",maxWidth:520},children:[e.jsxs("div",{className:"flex items-center gap-2 mb-3",children:[e.jsx("span",{className:"flex-1 text-[13px] font-medium truncate",style:{color:s.enabled?t.textPrimary:t.textDim},title:s.path,children:s.name}),e.jsxs("button",{type:"button",onClick:()=>{const G=Object.keys(Q),J=G.indexOf(s.knowledgeType);h(s.sourceId,(J+1)%G.length)},title:`${w.label}: ${w.instruction}
|
|
3
|
+
Click to change type`,className:"flex items-center gap-1.5 px-2 py-0.5 rounded transition-opacity hover:opacity-75",style:{background:`${w.color}15`,border:`1px solid ${w.color}40`,cursor:"pointer"},children:[e.jsx("span",{style:{fontSize:"11px",lineHeight:1},children:w.icon}),e.jsx("span",{className:"text-[11px] font-medium",style:{color:w.color,fontFamily:"'Geist Mono', monospace"},children:w.label})]}),R&&e.jsx(H,{size:12,className:"animate-spin",style:{color:t.textDim}}),e.jsxs("span",{className:"text-[12px] px-2 py-0.5 rounded font-medium",style:{fontFamily:"'Geist Mono', monospace",color:g?t.textPrimary:t.textDim,background:g?"#2ecc7115":t.isDark?"#ffffff10":"#00000010",border:`1px solid ${g?"#2ecc7130":t.borderSubtle}`},title:g?`Indexed: ${k[s.path].index.nodeCount} nodes`:"Estimated",children:[Math.round(B/1e3),"K"]}),e.jsx("button",{type:"button",onClick:()=>b(s.sourceId),className:"p-1.5 rounded transition-colors",style:{color:t.textFaint},title:"Remove source",children:e.jsx(pe,{size:12})})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-[12px]",children:[e.jsx("span",{style:{color:t.textDim,fontFamily:"'Geist Mono', monospace"},children:"Depth"}),e.jsxs("span",{style:{color:"#FE5000",fontFamily:"'Geist Mono', monospace",fontWeight:600},children:[Z(m)," (",m,"%)"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px]",style:{color:t.textFaint},children:"10"}),e.jsxs("div",{className:"flex-1 relative h-2 rounded overflow-hidden",style:{background:t.isDark?"#ffffff12":"#00000012"},children:[e.jsx("div",{className:"absolute left-0 top-0 h-full rounded transition-all",style:{width:`${m}%`,background:"#FE5000"}}),e.jsx("input",{type:"range",min:de,max:ce,step:le,value:m,onChange:G=>u(s.sourceId,Number(G.target.value)),className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer","aria-label":`Depth level for ${s.name}: ${Z(m)} (${m}%)`,title:ze(m)})]}),e.jsx("span",{className:"text-[10px]",style:{color:t.textFaint},children:"100"})]}),e.jsxs("div",{className:"text-[11px]",style:{color:t.textFaint,fontFamily:"'Geist Mono', monospace"},children:["~",B>=1e3?`${(B/1e3).toFixed(1)}k`:B," tokens at ",Z(m)," level"]})]}),C&&e.jsxs("div",{className:"mt-2 text-[11px] px-2 py-1 rounded",style:{color:"#e74c3c",background:"#e74c3c15"},children:["Error: ",i[s.path]]}),g&&k[s.path].index.sourceType==="code"&&e.jsx(fe,{index:k[s.path].index})]},s.sourceId)})}),r.length===0&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx("p",{className:"text-sm",style:{color:t.textDim},children:"No local files added yet."}),e.jsx("p",{className:"text-xs mt-2",style:{color:t.textFaint},children:'Click "Files" to upload documents or "Directory" to scan a folder.'})]})]})}function ee(t){return t>=100?"Full":t>=75?"Detail":t>=50?"Summary":t>=25?"Headlines":"Mention"}function Ae(t){return t>=100?"Full (100%) — Complete document, every line included. Best for specs, schemas, and ground-truth sources.":t>=75?"Detail (75%) — Main content with details; minor boilerplate trimmed. Good default for most sources.":t>=50?"Summary (50%) — Key points and structure; verbose sections condensed. Good for large reports.":t>=25?"Headlines (25%) — Section titles and key statements only. Good for broad awareness context.":"Mention (10%) — Brief reference only; title and top-level summary. Good for background context."}function Oe(){const t=U(),p=K(n=>n.channels),r=l.useMemo(()=>p.filter(n=>n.path?.includes(".git")||n.contentSourceId),[p]),u=K(n=>n.addChannel),h=K(n=>n.removeChannel),b=K(n=>n.setChannelDepth),d=K(n=>n.setChannelKnowledgeType),k=L(n=>n.indexes),[c,i]=l.useState(""),[y,T]=l.useState("main"),[M,z]=l.useState(""),[o,N]=l.useState(!1),[f,I]=l.useState(!1),S=l.useCallback(n=>{const F=k[n.path],s=(n.depth||100)/100;return Math.round(F?F.index.totalTokens*s:(n.baseTokens??0)*s)},[k]),D=l.useCallback(async()=>{if(!(!c.trim()||o)){N(!0);try{const n=c.trim(),F=/github\.com\//i.test(n)||n.endsWith(".git"),s=F?`${E}/repo/index-github`:`${E}/repo/index`,m=F?{url:n,persist:!0,...y!=="main"&&{branch:y},...M&&{token:M}}:{path:n},g=await(await fetch(s,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(m)})).json();if(g.status==="ok"&&g.data){const R=g.data.totalTokens??g.data.scan?.totalTokens??5e3,C=g.data.scan,B=Array.isArray(C?.stack)?C.stack:C?.stack&&typeof C.stack=="object"?Object.values(C.stack).filter(G=>typeof G=="string"&&G!=="unknown"&&G!=="none"):[];for(const G of g.data.files){const J=`${g.data.outputDir}/${G}`,W=G.includes("overview");u({sourceId:`repo-${G}-${Date.now()}`,name:G.replace(".compressed.md","").replace(".md","").replace(/^\d+-/,""),path:J,category:"knowledge",knowledgeType:"ground-truth",depth:F?50:70,baseTokens:Math.round(R/Math.max(g.data.files.length,1)),...W&&g.data.overviewMarkdown?{content:g.data.overviewMarkdown}:{},...W&&C?{repoMeta:{name:g.data.name??"",stack:B,totalFiles:C.totalFiles??0,baseUrl:C.baseUrl,features:(C.features??[]).map(X=>X.name)}}:{},...g.data.contentSourceId?{contentSourceId:g.data.contentSourceId}:{},...W&&g.data.codeFiles?.length?{codeFilePaths:g.data.codeFiles}:{}})}await L.getState().indexFiles(g.data.files.map(G=>`${g.data.outputDir}/${G}`)),g.data.codeFiles?.length&&await L.getState().indexFiles(g.data.codeFiles),i(""),T("main"),z(""),I(!1)}}catch{}finally{N(!1)}}},[c,y,M,o,u]),_=l.useCallback(async(n,F)=>{await L.getState().indexFiles(F.map(s=>`${n}/${s}`))},[]),q=/github\.com\//i.test(c)||c.endsWith(".git");return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:c,onChange:n=>i(n.target.value),placeholder:"https://github.com/user/repo or /path/to/local/repo",className:"flex-1 px-3 py-2 rounded text-[13px] outline-none",style:{background:t.inputBg,border:`1px solid ${t.border}`,color:t.textPrimary,fontFamily:"'Geist Sans', sans-serif"},onKeyDown:n=>n.key==="Enter"&&!o&&c.trim()&&D()}),e.jsx("button",{type:"button",onClick:()=>I(!f),className:"px-3 py-2 rounded text-[12px] tracking-wide uppercase transition-colors",style:{background:f?t.isDark?"#ffffff15":"#00000015":"transparent",border:`1px solid ${t.border}`,color:t.textDim,fontFamily:"'Geist Mono', monospace"},children:f?"Basic":"Advanced"})]}),f&&e.jsxs("div",{className:"space-y-2 p-3 rounded",style:{background:t.isDark?"#ffffff08":"#00000008"},children:[e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx(ve,{size:14,style:{color:t.textDim}}),e.jsx("input",{type:"text",value:y,onChange:n=>T(n.target.value),placeholder:"Branch name",className:"flex-1 px-2 py-1 rounded text-[12px] outline-none",style:{background:t.inputBg,border:`1px solid ${t.border}`,color:t.textPrimary,fontFamily:"'Geist Mono', monospace"}})]}),q&&e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx(ae,{size:14,style:{color:t.textDim}}),e.jsx("input",{type:"password",value:M,onChange:n=>z(n.target.value),placeholder:"GitHub token (optional, for private repos)",className:"flex-1 px-2 py-1 rounded text-[12px] outline-none",style:{background:t.inputBg,border:`1px solid ${t.border}`,color:t.textPrimary,fontFamily:"'Geist Mono', monospace"}})]})]}),e.jsx("button",{type:"button",onClick:D,disabled:o||!c.trim(),className:"w-full py-2.5 rounded text-[13px] font-semibold tracking-wide transition-opacity flex items-center justify-center gap-2",style:{background:"#24292F",color:"#fff",opacity:o||!c.trim()?.5:1,fontFamily:"'Geist Sans', sans-serif",cursor:o||!c.trim()?"not-allowed":"pointer"},children:o?e.jsxs(e.Fragment,{children:[e.jsx(H,{size:14,className:"animate-spin"}),q?"Cloning & Indexing...":"Indexing..."]}):e.jsxs(e.Fragment,{children:[e.jsx(te,{size:14}),q?"Clone & Index":"Index Repository"]})})]}),e.jsx("div",{className:"space-y-3",children:r.map(n=>{const F=n.depth||100,s=Q[n.knowledgeType],m=S(n),w=n.repoMeta,g=!!k[n.path];return e.jsxs("div",{className:"p-3 rounded border",style:{borderColor:n.enabled?t.border:t.borderSubtle,background:n.enabled?t.isDark?"#ffffff05":"#00000005":t.isDark?"#ffffff02":"#00000002"},children:[e.jsxs("div",{className:"flex items-start justify-between mb-3",children:[e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(ae,{size:14,style:{color:t.textDim}}),e.jsx("span",{className:"font-medium text-[14px] truncate",style:{color:t.textPrimary},children:w?.name||n.name}),n.path?.includes(".compressed.md")&&e.jsx("span",{className:"text-[10px] px-1 py-0.5 rounded",style:{background:"#00A86B20",color:"#00A86B",fontFamily:"'Geist Mono', monospace"},children:"COMPRESSED"})]}),w?.stack&&w.stack.length>0&&e.jsxs("div",{className:"flex flex-wrap gap-1 mb-2",children:[w.stack.slice(0,4).map((R,C)=>e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded",style:{background:t.isDark?"#ffffff15":"#00000015",color:t.textDim,fontFamily:"'Geist Mono', monospace"},children:R},C)),w.stack.length>4&&e.jsxs("span",{className:"text-[10px] px-1.5 py-0.5 rounded",style:{color:t.textFaint},children:["+",w.stack.length-4]})]}),e.jsxs("button",{type:"button",onClick:()=>{const R=Object.keys(Q),C=R.indexOf(n.knowledgeType);d(n.sourceId,(C+1)%R.length)},title:`${s.label}: ${s.instruction}
|
|
4
|
+
Click to change type`,className:"flex items-center gap-1.5 px-2 py-0.5 rounded transition-opacity hover:opacity-75 w-fit",style:{background:`${s.color}15`,border:`1px solid ${s.color}40`,cursor:"pointer"},children:[e.jsx("span",{style:{fontSize:"11px",lineHeight:1},children:s.icon}),e.jsx("span",{className:"text-[11px] font-medium",style:{color:s.color,fontFamily:"'Geist Mono', monospace"},children:s.label})]})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsxs("span",{className:"text-[12px] px-2 py-1 rounded font-medium",style:{fontFamily:"'Geist Mono', monospace",color:g?t.textPrimary:t.textDim,background:g?"#2ecc7115":t.isDark?"#ffffff10":"#00000010",border:`1px solid ${g?"#2ecc7130":t.borderSubtle}`},children:[Math.round(m/1e3),"K"]}),e.jsx("button",{type:"button",onClick:()=>_(n.path?.split("/").slice(0,-1).join("/")||"",[n.path?.split("/").pop()||""]),className:"p-1.5 rounded transition-colors",style:{color:t.textDim},title:"Re-index",children:e.jsx(ue,{size:12})}),e.jsx("button",{type:"button",onClick:()=>h(n.sourceId),className:"p-1.5 rounded transition-colors",style:{color:t.textFaint},title:"Remove",children:e.jsx(pe,{size:12})})]})]}),e.jsxs("div",{className:"space-y-1 mb-3",children:[e.jsxs("div",{className:"flex items-center justify-between text-[12px]",children:[e.jsx("span",{style:{color:t.textDim,fontFamily:"'Geist Mono', monospace"},children:"Depth"}),e.jsxs("span",{style:{color:"#FE5000",fontFamily:"'Geist Mono', monospace",fontWeight:600},children:[ee(F)," (",F,"%)"]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px]",style:{color:t.textFaint},children:"10"}),e.jsxs("div",{className:"flex-1 relative h-2 rounded overflow-hidden",style:{background:t.isDark?"#ffffff12":"#00000012"},children:[e.jsx("div",{className:"absolute left-0 top-0 h-full rounded transition-all",style:{width:`${F}%`,background:"#FE5000"}}),e.jsx("input",{type:"range",min:de,max:ce,step:le,value:F,onChange:R=>b(n.sourceId,Number(R.target.value)),className:"absolute inset-0 w-full h-full opacity-0 cursor-pointer","aria-label":`Depth level for ${n.name}: ${ee(F)} (${F}%)`,title:Ae(F)})]}),e.jsx("span",{className:"text-[10px]",style:{color:t.textFaint},children:"100"})]}),e.jsxs("div",{className:"text-[11px]",style:{color:t.textFaint,fontFamily:"'Geist Mono', monospace"},children:["~",m>=1e3?`${(m/1e3).toFixed(1)}k`:m," tokens at ",ee(F)," level"]})]}),w&&e.jsxs("div",{className:"flex items-center gap-4 text-[11px]",style:{color:t.textDim},children:[w.totalFiles>0&&e.jsx("div",{className:"flex items-center gap-1",children:e.jsxs("span",{children:[w.totalFiles," files"]})}),w.features&&w.features.length>0&&e.jsx("div",{className:"flex items-center gap-1",children:e.jsxs("span",{children:[w.features.length," features"]})}),e.jsxs("div",{className:"flex items-center gap-1",children:[e.jsx(xe,{size:10}),e.jsx("span",{children:"Indexed recently"})]})]}),n.codeFilePaths&&n.codeFilePaths.length>0&&(()=>{const C=n.codeFilePaths.map(B=>k[B]?.index).filter(B=>!!B);return C.length===0?null:e.jsxs("div",{className:"mt-2",children:[e.jsxs("div",{className:"text-[11px] font-medium mb-1",style:{color:t.textDim},children:["Code Structure (",C.length," files indexed)"]}),C.slice(0,5).map((B,G)=>e.jsx(fe,{index:B},G)),C.length>5&&e.jsxs("div",{className:"text-[10px] mt-1",style:{color:t.textFaint},children:["+",C.length-5," more files"]})]})})()]},n.sourceId)})}),r.length===0&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx(te,{size:32,style:{color:t.textFaint,margin:"0 auto 12px"}}),e.jsx("p",{className:"text-sm mb-2",style:{color:t.textDim},children:"No repositories indexed yet."}),e.jsx("p",{className:"text-xs",style:{color:t.textFaint},children:"Enter a GitHub URL or local repository path to get started."})]})]})}const Ke=[{id:"notion",name:"Notion",icon:"📄",description:"Import databases, pages, and workspaces",authMethod:"api-key",fields:[{key:"apiKey",label:"API Key",type:"password",placeholder:"secret_...",required:!0},{key:"databaseIds",label:"Database IDs",type:"text",placeholder:"id1,id2,id3 (comma separated)",required:!1},{key:"pageUrls",label:"Page URLs",type:"text",placeholder:"https://notion.so/... (one per line)",required:!1}]},{id:"hubspot",name:"HubSpot",icon:"🧲",description:"Sync CRM objects: contacts, deals, tickets",authMethod:"oauth",fields:[{key:"objectTypes",label:"Object Types",type:"select",placeholder:"",required:!0,options:["contacts","deals","tickets","companies"]},{key:"filters",label:"Filters",type:"text",placeholder:"property filters (optional)",required:!1}]},{id:"slack",name:"Slack",icon:"💬",description:"Import messages and channels",authMethod:"oauth",fields:[{key:"channels",label:"Channels",type:"text",placeholder:"#general,#product (comma separated)",required:!1},{key:"keywords",label:"Keywords",type:"text",placeholder:"filter by keywords",required:!1},{key:"dateRange",label:"Date Range",type:"text",placeholder:"last 30 days",required:!1}]},{id:"google-drive",name:"Google Drive",icon:"📁",description:"Access documents and folders",authMethod:"oauth",fields:[{key:"folderIds",label:"Folder IDs",type:"text",placeholder:"folder1,folder2 (comma separated)",required:!1},{key:"fileTypes",label:"File Types",type:"select",placeholder:"",required:!1,options:["docs","sheets","slides","pdf","all"]}]},{id:"github",name:"GitHub",icon:"🐙",description:"Repository issues, PRs, and discussions",authMethod:"api-key",fields:[{key:"token",label:"Personal Access Token",type:"password",placeholder:"ghp_...",required:!0},{key:"repos",label:"Repositories",type:"text",placeholder:"owner/repo1,owner/repo2",required:!0},{key:"includeIssues",label:"Include Issues",type:"select",placeholder:"",required:!1,options:["yes","no"]},{key:"includePRs",label:"Include PRs",type:"select",placeholder:"",required:!1,options:["yes","no"]}]}];function Be(){const t=U(),[p,r]=l.useState({}),[u]=l.useState(!1),[h,b]=l.useState(null),[d,k]=l.useState({}),[c,i]=l.useState({}),[y,T]=l.useState({}),[M,z]=l.useState({}),[o,N]=l.useState({}),[f,I]=l.useState(""),[S,D]=l.useState([]),[_,q]=l.useState(!1),[n,F]=l.useState(new Set),s=K(a=>a.addChannel),m=l.useCallback(async()=>{try{const j=await(await fetch(`${E}/connectors/auth`)).json();j.status==="ok"&&r(j.data||{})}catch{}},[]);l.useEffect(()=>{m()},[m]);const w=l.useCallback(async(a,j)=>{i({...c,[a]:!0});try{(await(await fetch(`${E}/connectors/auth/api-key`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({service:a,apiKey:j})})).json()).status==="ok"&&(await m(),b(null))}catch{}finally{i({...c,[a]:!1})}},[c,m]),g=l.useCallback(async(a,j,A)=>{i({...c,[a]:!0});try{const v=new URLSearchParams({clientId:j});A&&v.set("clientSecret",A);const P=await(await fetch(`${E}/connectors/oauth/start/${a}?${v}`)).json();if(P.status==="ok"){window.open(P.data.redirectUrl,"_blank","width=600,height=700");const x=setInterval(async()=>{await m(),p[a]?.status==="connected"&&(clearInterval(x),b(null))},2e3)}}catch{}finally{i({...c,[a]:!1})}},[c,m,p]),R=l.useCallback(async a=>{i({...c,[a]:!0});try{(await(await fetch(`${E}/connectors/auth/test/${a}`,{method:"POST"})).json()).status==="ok"&&await m()}catch{}finally{i({...c,[a]:!1})}},[c,m]),C=l.useCallback(async a=>{try{(await fetch(`${E}/connectors/auth/${a}`,{method:"DELETE"})).ok&&await m()}catch{}},[m]),B=l.useCallback(async a=>{i(j=>({...j,notion:!0}));try{const A=await(await fetch(`${E}/connectors/notion/test`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:a})})).json();A.status==="ok"?(T(v=>({...v,notion:"ok"})),z(v=>({...v,notion:""}))):(T(v=>({...v,notion:"error"})),z(v=>({...v,notion:String(A.error??"Test failed")})))}catch{T(j=>({...j,notion:"error"})),z(j=>({...j,notion:"Connection error. Check your network."}))}finally{i(j=>({...j,notion:!1}))}},[]),G=l.useCallback(async(a,j)=>{q(!0),D([]);try{const v=await(await fetch(`${E}/connectors/notion/search`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:a,query:j})})).json();v.status==="ok"&&Array.isArray(v.data)&&(D(v.data),F(new Set))}catch{}finally{q(!1)}},[]),J=l.useCallback(async a=>{const j=d[a]??{},A=j.apiKey??"",v=j.databaseIds?j.databaseIds.split(",").map(P=>P.trim()).filter(Boolean):void 0,$=j.pageUrls?j.pageUrls.split(`
|
|
5
|
+
`).map(P=>P.trim()).filter(Boolean):void 0;N(P=>({...P,[a]:!0}));try{const x=await(await fetch(`${E}/connectors/notion/fetch`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:A,databaseIds:v,pageUrls:$})})).json();if(x.status==="ok"&&Array.isArray(x.data))for(const O of x.data)s({sourceId:`notion-${String(O.id)}`,name:String(O.title),path:`notion://${String(O.id)}`,category:"knowledge",knowledgeType:"evidence",depth:100,baseTokens:Number(O.tokens)||0,content:String(O.content)})}catch{}finally{N(P=>({...P,[a]:!1}))}},[d,s]),W=l.useCallback(async a=>{if(!n.size)return;const j=[],A=[];for(const v of n)S.find($=>$.id===v)?.type==="database"?A.push(v):j.push(`https://notion.so/${v.replace(/-/g,"")}`);N(v=>({...v,notion:!0}));try{const $=await(await fetch(`${E}/connectors/notion/fetch`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({apiKey:a,databaseIds:A,pageUrls:j})})).json();if($.status==="ok"&&Array.isArray($.data))for(const P of $.data)s({sourceId:`notion-${String(P.id)}`,name:String(P.title),path:`notion://${String(P.id)}`,category:"knowledge",knowledgeType:"evidence",depth:100,baseTokens:Number(P.tokens)||0,content:String(P.content)})}catch{}finally{N(v=>({...v,notion:!1}))}},[n,S,s]),X=l.useCallback(async a=>{i({...c,[a]:!0}),setTimeout(()=>{i({...c,[a]:!1})},2e3)},[c]),me=a=>{switch(a){case"connected":return e.jsx(ie,{size:16,style:{color:"#2ecc71"}});case"expired":return e.jsx(Te,{size:16,style:{color:"#e74c3c"}});case"configured":return e.jsx(xe,{size:16,style:{color:"#f1c40f"}});default:return e.jsx(De,{size:16,style:{color:t.textDim}})}},he=a=>{switch(a){case"connected":return"Connected";case"expired":return"Expired";case"configured":return"Configured";default:return"Not configured"}};return e.jsxs("div",{className:"space-y-4",children:[u&&e.jsx("div",{className:"flex items-center justify-center py-4",children:e.jsx(H,{size:20,className:"animate-spin",style:{color:t.textDim}})}),e.jsx("div",{className:"space-y-3",children:Ke.map(a=>{const j=p[a.id],A=h===a.id,v=j?.status==="connected",$=c[a.id],P=a.authMethod==="oauth";return e.jsxs("div",{className:"rounded-lg border overflow-hidden",style:{borderColor:v?"#2ecc71":t.border,background:t.isDark?"#ffffff05":"#00000005",opacity:P?.6:1},children:[e.jsx("div",{className:P?"p-4":"p-4 cursor-pointer",onClick:()=>!P&&b(A?null:a.id),children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-2xl",children:a.icon}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-medium text-[14px]",style:{color:t.textPrimary},children:a.name}),e.jsx("p",{className:"text-[12px]",style:{color:t.textDim},children:a.description})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[P&&e.jsx("span",{className:"text-[10px] px-2 py-0.5 rounded-full font-medium",style:{background:t.isDark?"#ffffff15":"#00000015",color:t.textDim},children:"Coming soon"}),j&&e.jsxs(e.Fragment,{children:[me(j.status),e.jsx("span",{className:"text-[12px]",style:{color:t.textDim},children:he(j.status)})]}),v&&e.jsxs("div",{className:"flex gap-1",children:[e.jsx("button",{type:"button",onClick:x=>{x.stopPropagation(),R(a.id)},disabled:$,className:"p-1.5 rounded transition-colors",style:{color:t.textDim},title:"Test connection",children:e.jsx(ue,{size:12,className:$?"animate-spin":""})}),e.jsx("button",{type:"button",onClick:x=>{x.stopPropagation(),X(a.id)},disabled:$,className:"p-1.5 rounded transition-colors",style:{background:"#2ecc71",color:"#fff"},title:"Sync now",children:e.jsx(Se,{size:12})})]})]})]})}),A&&e.jsx("div",{className:"border-t p-4",style:{borderColor:t.border,background:t.isDark?"#ffffff08":"#00000008"},children:e.jsx("div",{className:"space-y-3",children:a.authMethod==="api-key"?e.jsxs("div",{className:"space-y-3",children:[a.fields.map(x=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("label",{className:"text-[12px] font-medium",style:{color:t.textDim},children:[x.label," ",x.required&&e.jsx("span",{style:{color:"#e74c3c"},children:"*"})]}),x.type==="select"?e.jsxs("select",{value:d[a.id]?.[x.key]||"",onChange:O=>k({...d,[a.id]:{...d[a.id],[x.key]:O.target.value}}),className:"w-full px-3 py-2 rounded text-[13px] outline-none",style:{background:t.inputBg,border:`1px solid ${t.border}`,color:t.textPrimary},children:[e.jsx("option",{value:"",children:x.placeholder}),x.options?.map(O=>e.jsx("option",{value:O,children:O},O))]}):e.jsx("input",{type:x.type,value:d[a.id]?.[x.key]||"",onChange:O=>k({...d,[a.id]:{...d[a.id],[x.key]:O.target.value}}),placeholder:x.placeholder,className:"w-full px-3 py-2 rounded text-[13px] outline-none",style:{background:t.inputBg,border:`1px solid ${t.border}`,color:t.textPrimary}})]},x.key)),e.jsxs("div",{className:"flex gap-2 pt-2 flex-wrap",children:[a.id==="notion"?e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>{const x=d[a.id]?.apiKey;x&&B(x)},disabled:$||!d[a.id]?.apiKey,className:"flex items-center gap-2 px-4 py-2 rounded text-[12px] font-medium",style:{background:"#2ecc71",color:"#fff",opacity:$||!d[a.id]?.apiKey?.5:1},children:[$?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(oe,{size:12}),"Test"]}),y[a.id]==="ok"&&e.jsxs("button",{type:"button",onClick:()=>J(a.id),disabled:o[a.id],className:"flex items-center gap-2 px-4 py-2 rounded text-[12px] font-medium",style:{background:"#3498db",color:"#fff",opacity:o[a.id]?.5:1},children:[o[a.id]?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(re,{size:12}),"Fetch"]})]}):e.jsxs("button",{type:"button",onClick:()=>{const x=d[a.id]?.apiKey;x&&w(a.id,x)},disabled:$||!d[a.id]?.apiKey,className:"flex items-center gap-2 px-4 py-2 rounded text-[12px] font-medium",style:{background:"#2ecc71",color:"#fff",opacity:$||!d[a.id]?.apiKey?.5:1},children:[$?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(oe,{size:12}),"Connect"]}),v&&e.jsx("button",{type:"button",onClick:()=>C(a.id),className:"px-4 py-2 rounded text-[12px] font-medium",style:{background:"transparent",border:`1px solid ${t.border}`,color:t.textDim},children:"Disconnect"})]}),y[a.id]==="ok"&&a.id==="notion"&&e.jsxs("div",{className:"flex items-center gap-1 mt-2 text-[12px]",style:{color:"#2ecc71"},children:[e.jsx(ie,{size:12}),"Connection verified"]}),y[a.id]==="error"&&M[a.id]&&e.jsx("p",{className:"mt-2 text-[12px]",style:{color:"#e74c3c"},children:M[a.id]}),y[a.id]==="ok"&&a.id==="notion"&&e.jsxs("div",{className:"space-y-2 pt-3 border-t",style:{borderColor:t.border},children:[e.jsx("p",{className:"text-[11px] font-medium uppercase tracking-wider",style:{color:t.textDim},children:"Search workspace"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("input",{type:"text",value:f,onChange:x=>I(x.target.value),onKeyDown:x=>{x.key==="Enter"&&G(d[a.id]?.apiKey??"",f)},placeholder:"Search pages and databases…",className:"flex-1 px-3 py-1.5 rounded text-[13px] outline-none",style:{background:t.inputBg,border:`1px solid ${t.border}`,color:t.textPrimary}}),e.jsxs("button",{type:"button",onClick:()=>G(d[a.id]?.apiKey??"",f),disabled:_,className:"flex items-center gap-1 px-3 py-1.5 rounded text-[12px] font-medium",style:{background:"#3498db",color:"#fff",opacity:_?.5:1},children:[_?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(Ce,{size:12}),"Search"]})]}),S.length>0&&e.jsx("div",{className:"space-y-0 max-h-40 overflow-y-auto rounded border",style:{borderColor:t.border},children:S.map(x=>e.jsxs("label",{className:"flex items-center gap-2 px-2 py-1.5 cursor-pointer",style:{background:n.has(x.id)?t.isDark?"#ffffff10":"#00000010":"transparent"},children:[e.jsx("input",{type:"checkbox",checked:n.has(x.id),onChange:O=>{const V=new Set(n);O.target.checked?V.add(x.id):V.delete(x.id),F(V)}}),e.jsx("span",{className:"flex-1 text-[12px] truncate",style:{color:t.textPrimary},children:x.title}),e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded",style:{background:t.isDark?"#ffffff15":"#00000015",color:t.textDim},children:x.type})]},x.id))}),n.size>0&&e.jsxs("button",{type:"button",onClick:()=>W(d[a.id]?.apiKey??""),disabled:o[a.id],className:"flex items-center gap-2 px-4 py-1.5 rounded text-[12px] font-medium",style:{background:"#8e44ad",color:"#fff",opacity:o[a.id]?.5:1},children:[o[a.id]?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(re,{size:12}),"Add ",n.size," selected"]})]})]}):e.jsxs("div",{className:"space-y-3",children:[e.jsxs("p",{className:"text-[12px]",style:{color:t.textDim},children:['Click "Connect with OAuth" to authorize access to your ',a.name," account."]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs("button",{type:"button",onClick:()=>g(a.id,"your-client-id"),disabled:$,className:"flex items-center gap-2 px-4 py-2 rounded text-[12px] font-medium",style:{background:"#2ecc71",color:"#fff",opacity:$?.5:1},children:[$?e.jsx(H,{size:12,className:"animate-spin"}):e.jsx(Fe,{size:12}),"Connect with OAuth"]}),v&&e.jsx("button",{type:"button",onClick:()=>C(a.id),className:"px-4 py-2 rounded text-[12px] font-medium",style:{background:"transparent",border:`1px solid ${t.border}`,color:t.textDim},children:"Disconnect"})]})]})})})]},a.id)})}),Object.keys(p).length===0&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx(se,{size:32,style:{color:t.textFaint,margin:"0 auto 12px"}}),e.jsx("p",{className:"text-sm mb-2",style:{color:t.textDim},children:"Connect to external services"}),e.jsx("p",{className:"text-xs",style:{color:t.textFaint},children:"Import data from Notion, HubSpot, Slack and other platforms."})]})]})}const _e=ge.lazy(()=>ye(()=>import("./GraphPanel-D4X3faxA.js"),__vite__mapDeps([0,1,2,3,4,5,6])).then(t=>({default:t.GraphPanel})));function He({gaps:t}){const p=U(),r=K(b=>b.setShowFilePicker),h=K(b=>b.agentMeta).name!=="";return t.length===0?h?e.jsx("div",{className:"mb-6",style:{borderBottom:`1px solid ${p.isDark?"#1e1e22":"#e8e8ec"}`,borderLeft:"3px solid #2ecc71"},children:e.jsx("div",{className:"px-5 py-3",style:{background:p.isDark?"#0f1a0f":"#f0fdf0"},children:e.jsx("span",{className:"text-[12px] font-bold tracking-[0.08em] uppercase",style:{fontFamily:"'Geist Mono', monospace",color:"#2ecc71"},children:"✅ No missing sources detected"})})}):null:e.jsxs("div",{className:"mb-6",style:{borderBottom:`1px solid ${p.isDark?"#1e1e22":"#e8e8ec"}`,borderLeft:"3px solid #e74c3c"},children:[e.jsx("div",{className:"px-5 py-3",style:{background:p.isDark?"#1a1a1e":"#fff5f5"},children:e.jsxs("span",{className:"text-[12px] font-bold tracking-[0.08em] uppercase",style:{fontFamily:"'Geist Mono', monospace",color:"#e74c3c"},children:["⚠ ",t.length," MISSING SOURCES"]})}),e.jsx("div",{className:"px-5 pb-4 flex flex-col gap-3",children:t.map((b,d)=>e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{style:{color:"#e74c3c",fontSize:10,marginTop:3,flexShrink:0},children:"●"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"text-[13px]",children:[e.jsx("span",{style:{fontWeight:700,color:p.textPrimary},children:b.name}),e.jsxs("span",{style:{color:p.textDim},children:[" (",b.type,")"]})]}),b.description&&e.jsx("div",{className:"text-[12px] mt-0.5",style:{color:p.textDim},children:b.description}),e.jsx("button",{type:"button",onClick:()=>r(!0),title:"Add missing source",className:"mt-1.5 text-[12px] px-2 py-0.5 rounded cursor-pointer border-none",style:{background:"#e74c3c15",color:"#e74c3c",fontFamily:"'Geist Mono', monospace",border:"1px solid #e74c3c30"},children:"+ Add source"})]})]},d))})]})}function qe(){const t=U(),p=K(o=>o.channels),r=K(o=>o.connectors),u=K(o=>o.knowledgeGaps),h=L(o=>o.indexes),b=$e(o=>o.stats),[d,k]=l.useState("local-files"),c=l.useCallback(o=>{const N=h[o.path],f=(o.depth||100)/100;return Math.round(N?N.index.totalTokens*f:(o.baseTokens??0)*f)},[h]),i=l.useMemo(()=>{const o=p.filter(S=>S.enabled),N=o.length,f=o.filter(S=>h[S.path]).length,I=o.reduce((S,D)=>S+c(D),0);return{enabledCount:N,indexedCount:f,totalTokens:I}},[p,h,c]),y=l.useMemo(()=>{const o=p.filter(S=>S.enabled&&/\.compressed\.md$/i.test(S.path||"")),N=o.reduce((S,D)=>S+(D.baseTokens||0),0),f=o.reduce((S,D)=>S+c(D),0),I=N>0?Math.max(0,(N-f)/N*100):0;return{githubCompressedChannels:o,githubRawTokens:N,githubEffectiveTokens:f,githubSavingsPct:I}},[p,c]),T=o=>o>=1e3?`${(o/1e3).toFixed(0)}K`:`${o}`,M=l.useMemo(()=>[{id:"local-files",label:"Local Files",icon:Me,count:p.filter(o=>o.path&&!o.path.includes(".git")&&!o.contentSourceId).length},{id:"git-repos",label:"Git Repos",icon:te,count:p.filter(o=>o.path?.includes(".git")||o.contentSourceId).length},{id:"connectors",label:"Connectors",icon:se,count:r.filter(o=>o.status==="connected").length},{id:"graph",label:"Graph",icon:Ie,count:b?.nodes??0}],[p,r,b]),z=l.useMemo(()=>Object.entries(Q).map(([o,N])=>{const I=p.filter(D=>D.enabled&&D.knowledgeType===o).reduce((D,_)=>D+c(_),0),S=i.totalTokens>0?I/i.totalTokens*100:0;return{key:o,kt:N,typeTokens:I,pct:S}}).filter(o=>o.typeTokens>0),[p,i.totalTokens,c]);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-semibold mb-2 m-0",style:{color:t.textPrimary,fontFamily:"'Geist Sans', sans-serif"},children:"Knowledge Sources"}),e.jsx("p",{className:"text-sm",style:{color:t.textSecondary,lineHeight:1.5},children:"Configure the knowledge sources your agent will use. Different knowledge types serve different purposes in your agent's reasoning process."})]}),e.jsx(He,{gaps:u}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-[60%_40%] gap-6",children:[e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{className:"flex gap-1 p-1 rounded",style:{background:t.isDark?"#ffffff08":"#00000008"},children:M.map(o=>{const N=o.icon,f=d===o.id;return e.jsxs("button",{type:"button",onClick:()=>k(o.id),title:o.id==="local-files"?"Add local files":o.id==="git-repos"?"Add git repositories":"Add API connectors",className:"flex items-center justify-center gap-2 flex-1 px-3 py-2.5 rounded text-[12px] font-medium tracking-wide uppercase transition-all duration-200",style:{background:f?t.isDark?"#ffffff15":"#ffffff":"transparent",border:f?`1px solid ${t.border}`:"1px solid transparent",color:f?t.textPrimary:t.textDim,fontFamily:"'Geist Mono', monospace",boxShadow:f?t.isDark?"0 1px 3px rgba(255,255,255,0.1)":"0 1px 3px rgba(0,0,0,0.1)":"none"},onMouseEnter:I=>{f||(I.currentTarget.style.background=t.isDark?"#ffffff08":"#00000008")},onMouseLeave:I=>{f||(I.currentTarget.style.background="transparent")},children:[e.jsx(N,{size:14}),e.jsx("span",{children:o.label}),o.count>0&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 rounded font-semibold",style:{background:f?t.isDark?"#ffffff25":"#00000025":t.isDark?"#ffffff20":"#00000020",fontFamily:"'Geist Mono', monospace"},children:o.count})]},o.id)})}),e.jsxs("div",{style:{minHeight:"400px"},children:[d==="local-files"&&e.jsx(Ee,{}),d==="git-repos"&&e.jsx(Oe,{}),d==="connectors"&&e.jsx(Be,{}),d==="graph"&&e.jsx(l.Suspense,{fallback:e.jsx("div",{style:{padding:24,color:t.textDim,fontSize:13},children:"Loading graph..."}),children:e.jsx(_e,{})})]})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-semibold mb-2",style:{color:t.textPrimary,fontFamily:"'Geist Sans', sans-serif"},children:"Knowledge Map"}),e.jsxs("div",{className:"flex items-center gap-4 text-[13px]",style:{color:t.textDim},children:[e.jsxs("span",{children:[i.enabledCount," sources"]}),e.jsxs("span",{children:[T(i.totalTokens)," tokens"]}),i.indexedCount<i.enabledCount&&e.jsxs("span",{style:{color:"#f1c40f"},children:[i.enabledCount-i.indexedCount," pending index"]})]})]}),p.length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"text-[13px] font-medium tracking-wide uppercase",style:{color:t.textSecondary,fontFamily:"'Geist Mono', monospace"},children:"Type Distribution"}),z.map(({key:o,kt:N,pct:f})=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-[12px]",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{style:{width:8,height:8,borderRadius:1,background:N.color}}),e.jsx("span",{style:{color:t.textPrimary,fontFamily:"'Geist Sans', sans-serif"},children:N.label})]}),e.jsxs("span",{style:{color:t.textDim,fontFamily:"'Geist Mono', monospace"},children:[f.toFixed(0),"%"]})]}),e.jsx("div",{className:"h-2 rounded overflow-hidden",style:{background:t.isDark?"#ffffff12":"#00000012"},children:e.jsx("div",{className:"h-full transition-all duration-300",style:{width:`${f}%`,background:N.color,borderRadius:2}})})]},o))]}),i.totalTokens>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("h4",{className:"text-[13px] font-medium tracking-wide uppercase",style:{color:t.textSecondary,fontFamily:"'Geist Mono', monospace"},children:"Token Budget"}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center justify-between text-[12px]",children:[e.jsx("span",{style:{color:t.textDim},children:"Used"}),e.jsxs("span",{style:{color:t.textPrimary,fontFamily:"'Geist Mono', monospace"},children:[T(i.totalTokens)," / 200K"]})]}),e.jsx("div",{className:"h-3 rounded overflow-hidden",style:{background:t.isDark?"#ffffff12":"#00000012"},children:e.jsx("div",{className:"h-full transition-all duration-300",style:{width:`${Math.min(100,i.totalTokens/2e5*100)}%`,background:i.totalTokens>16e4?"#e74c3c":i.totalTokens>12e4?"#f1c40f":"#2ecc71",borderRadius:2}})}),e.jsxs("div",{className:"text-[11px]",style:{color:t.textFaint},children:[(i.totalTokens/2e5*100).toFixed(1),"% of budget used"]})]})]}),y.githubCompressedChannels.length>0&&e.jsxs("div",{className:"px-3 py-2.5 rounded",style:{border:`1px solid ${t.borderSubtle}`,background:t.isDark?"#ffffff08":"#00000008"},children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("span",{className:"text-[12px] tracking-wide uppercase",style:{fontFamily:"'Geist Mono', monospace",color:t.textSecondary},children:"GitHub Compression"}),e.jsxs("span",{className:"text-[12px] font-semibold",style:{color:"#00A86B"},children:["-",y.githubSavingsPct.toFixed(1),"%"]})]}),e.jsxs("div",{className:"mt-1 text-[11px]",style:{color:t.textDim},children:["Raw ",T(y.githubRawTokens)," → Effective ",T(y.githubEffectiveTokens)," tokens"]})]}),p.length===0&&e.jsxs("div",{className:"text-center py-8",children:[e.jsx(se,{size:32,style:{color:t.textFaint,margin:"0 auto 12px"}}),e.jsx("p",{className:"text-sm mb-2",style:{color:t.textDim},children:"No knowledge sources yet"}),e.jsx("p",{className:"text-xs",style:{color:t.textFaint},children:"Add files, repositories, or connect to external services to start building your knowledge base."})]})]})]})]})}const Xe=Object.freeze(Object.defineProperty({__proto__:null,KnowledgeTab:qe},Symbol.toStringTag,{value:"Module"}));export{Xe as K,$e as u};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import{j as s,r}from"./vendor-D1h_O76p.js";import{u as oe,S as x}from"./index-C626nWuA.js";import{u as ve,e as je,j as Se,k as Ce,m as c}from"./services-BDk6yY4o.js";import{I as ae}from"./Input-Dyb88Erk.js";import{S as j,T as w}from"./Section-68XDCFTl.js";import{Q as ke,s as Ne,B as T,X as we,a1 as Te,aQ as te,a3 as Ee,a4 as $e,ax as Fe,D as Me,Z as Pe,ad as ze}from"./icons-CS8RUPBi.js";import"./stores-CeKWz7ou.js";function Be(){const a=ve.getState(),o=[];a.agentMeta.name&&o.push(`Agent: ${a.agentMeta.name}`),a.agentMeta.description&&o.push(`Description: ${a.agentMeta.description}`),a.instructionState.persona&&o.push(`Persona: ${a.instructionState.persona}`),a.instructionState.objectives.primary&&o.push(`Primary objective: ${a.instructionState.objectives.primary}`),a.instructionState.constraints.scopeDefinition&&o.push(`Scope: ${a.instructionState.constraints.scopeDefinition}`);const t=a.skills.filter(i=>i.enabled).map(i=>i.name);t.length&&o.push(`Skills: ${t.join(", ")}`);const n=a.mcpServers.filter(i=>i.enabled).map(i=>i.name);return n.length&&o.push(`MCP servers: ${n.join(", ")}`),o.join(`
|
|
2
|
+
`)}const Oe={memory:`You are an expert AI agent architect. Given the agent context below, generate memory configuration and initial facts.
|
|
3
|
+
|
|
4
|
+
Output ONLY a JSON object:
|
|
5
|
+
{
|
|
6
|
+
"maxMessages": <10-50>,
|
|
7
|
+
"summarizeAfter": <5-25>,
|
|
8
|
+
"summarizeEnabled": <true|false>,
|
|
9
|
+
"suggestedFacts": ["<pre-loaded fact relevant to the agent's domain>"]
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
Rules:
|
|
13
|
+
- Conversational agents need higher maxMessages and summarization
|
|
14
|
+
- One-shot tools can have lower limits and no summarization
|
|
15
|
+
- Facts should be domain-relevant knowledge the agent should always have
|
|
16
|
+
- Generate 2-5 facts that help the agent do its job better`};async function Re(a,o){const t=je.getState(),n=t.providers.find(d=>d.id===t.selectedProviderId);if(!n)throw new Error("No provider configured — add one in Settings");const i=typeof n.models?.[0]=="object"?n.models[0].id:n.models?.[0]||"claude-sonnet-4-20250514";return n.authMethod==="claude-agent-sdk"?Se({prompt:o,model:i,systemPrompt:a,maxTurns:1}):Ce({providerId:n.id,model:i,messages:[{role:"system",content:a},{role:"user",content:o}],temperature:.4,maxTokens:2048})}function _e(a){try{return JSON.parse(a)}catch{}const o=a.match(/```(?:json)?\s*([\s\S]*?)```/);if(o)try{return JSON.parse(o[1].trim())}catch{}const t=a.match(/[\[{][\s\S]*[\]}]/);if(t)try{return JSON.parse(t[0])}catch{}throw new Error("Could not parse LLM response as JSON")}async function Ae(){const a=Be();if(!a)throw new Error("Add agent identity/persona first — the generator needs context");const o=await Re(Oe.memory,a);return _e(o)}function De({loading:a,onClick:o,label:t="Generate",disabled:n=!1,"aria-describedby":i}){const d=n||a;return s.jsxs("button",{type:"button",onClick:m=>{m.stopPropagation(),d||o()},disabled:d,"aria-label":a?`${t} in progress`:`${t} content`,"aria-describedby":i,className:"flex items-center gap-1 text-[13px] px-2 py-1 rounded cursor-pointer border-none transition-opacity",style:{background:"#FE500015",color:"#FE5000",fontFamily:"'Geist Mono', monospace",opacity:d?.6:1,cursor:d?"not-allowed":"pointer"},children:[a?s.jsx(ke,{size:9,className:"animate-spin motion-reduce:animate-none","aria-hidden":"true"}):s.jsx(Ne,{size:9,"aria-hidden":"true"}),t]})}function b({label:a,value:o,min:t,max:n,step:i,onChange:d,suffix:m}){const h=oe(),E=m==="K"?`${(o/1e3).toFixed(0)}K`:`${o}`,S=`slider-${a.toLowerCase().replace(/\s+/g,"-")}`,C=`${S}-value`;return s.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center gap-2 sm:gap-3 mb-3",children:[s.jsx("label",{htmlFor:S,className:"text-sm font-medium shrink-0 sm:w-32",style:{color:h.textPrimary},children:a}),s.jsxs("div",{className:"flex items-center gap-3 flex-1",children:[s.jsx("input",{id:S,type:"range",min:t,max:n,step:i,value:o,onChange:f=>d(Number(f.target.value)),title:`Adjust ${a.toLowerCase()}`,"aria-valuemin":t,"aria-valuemax":n,"aria-valuenow":o,"aria-valuetext":`${E}${m?" "+m.toLowerCase():""}`,"aria-describedby":C,className:"flex-1",style:{accentColor:"#FE5000"}}),s.jsx("span",{id:C,className:"text-sm w-12 text-right",style:{fontFamily:"'Geist Mono', monospace",color:h.textSecondary},"aria-live":"polite",children:E})]})]})}const L=[{value:"full",label:"Full History",description:"Keep all conversation messages in memory"},{value:"sliding_window",label:"Sliding Window",description:"Keep only the most recent messages"},{value:"summarize_and_recent",label:"Summarize + Recent",description:"Summarize old messages, keep recent ones"},{value:"rag",label:"RAG over History",description:"Retrieve relevant messages from searchable storage"}],Le=[{value:"local_sqlite",label:"SQLite (local)",disabled:!1},{value:"postgres",label:"PostgreSQL",disabled:!1},{value:"hindsight",label:"Hindsight",disabled:!1},{value:"redis",label:"Redis (coming soon)",disabled:!0},{value:"chromadb",label:"ChromaDB (coming soon)",disabled:!0},{value:"pinecone",label:"Pinecone (coming soon)",disabled:!0},{value:"custom",label:"Custom (coming soon)",disabled:!0}],Ge=[{value:"text-embedding-3-small",label:"Ada 3 Small"},{value:"text-embedding-3-large",label:"Ada 3 Large"},{value:"voyage-3",label:"Voyage 3"},{value:"custom",label:"Custom"}],Ie=[{value:"top_k",label:"Top-K"},{value:"threshold",label:"Threshold"},{value:"hybrid",label:"Hybrid"}],We=[{value:"auto_extract",label:"Auto Extract"},{value:"explicit",label:"Explicit Only"},{value:"both",label:"Both"}],He=[{value:"per_user",label:"Per User"},{value:"per_agent",label:"Per Agent"},{value:"global",label:"Global"}],Ke=[{value:"user_preferences",label:"Preferences",color:"#3498db"},{value:"decisions",label:"Decisions",color:"#e67e22"},{value:"facts",label:"Facts",color:"#2ecc71"},{value:"feedback",label:"Feedback",color:"#9b59b6"},{value:"entities",label:"Entities",color:"#f1c40f"}],Je=[{value:"reset_each_run",label:"Reset Each Run"},{value:"persistent_sandbox",label:"Persistent Sandbox"},{value:"clone_from_shared",label:"Clone from Shared"}],z={shared:"#2ecc71",agent_private:"#3498db",run_scratchpad:"#e67e22"},G={preference:"#3498db",decision:"#e67e22",fact:"#2ecc71",entity:"#f1c40f",custom:"#999"},Ye={display:"flex",alignItems:"center",gap:"0.5rem",fontSize:"0.875rem",padding:"0.5rem 0.75rem",borderRadius:"0.25rem"},Qe={fontSize:"0.75rem",padding:"0.25rem 0.5rem",borderRadius:"9999px",fontFamily:"'Geist Mono', monospace"},Xe={fontSize:"0.75rem",padding:"0.125rem 0.375rem",borderRadius:"0.25rem",fontFamily:"'Geist Mono', monospace"},qe={border:"none",background:"transparent",cursor:"pointer",borderRadius:"0.25rem",flexShrink:0,display:"flex",alignItems:"center",justifyContent:"center",minWidth:"44px",minHeight:"44px"};function os(){const a=oe(),o=c(e=>e.session),t=c(e=>e.longTerm),n=c(e=>e.working),i=c(e=>e.facts),d=c(e=>e.setSessionConfig),m=c(e=>e.setLongTermConfig),h=c(e=>e.setRecallConfig),E=c(e=>e.setWriteConfig),S=c(e=>e.toggleExtractType),C=c(e=>e.setWorkingConfig),f=c(e=>e.addFact),ne=c(e=>e.removeFact),$=c(e=>e.sandbox),I=c(e=>e.setSandboxConfig),le=c(e=>e.setSandboxDomain),k=c(e=>e.responseCache),W=c(e=>e.setResponseCacheConfig),[H,re]=r.useState(!1),[K,ie]=r.useState(!1),[J,ce]=r.useState(!1),[Y,de]=r.useState(!1),[Q,me]=r.useState(!1),[X,ue]=r.useState(!1),[F,ge]=r.useState(null),[q,Z]=r.useState(!1),[N,B]=r.useState(""),[O,pe]=r.useState("shared"),[be,U]=r.useState(!1),[R,xe]=r.useState(""),[g,_]=r.useState(null),[V,ee]=r.useState(!1),[A,y]=r.useState("idle"),he=r.useCallback(async()=>{U(!0);try{const e=await Ae();d({maxMessages:e.maxMessages,summarizeAfter:e.summarizeAfter,summarizeEnabled:e.summarizeEnabled});for(const l of e.suggestedFacts||[])f(l,["generated"])}catch{}U(!1)},[d,f]),M=r.useCallback(async()=>{try{const e=await fetch("/api/memory/health");if(!e.ok)return _({status:"unavailable",factCount:0}),{status:"unavailable",factCount:0};const l=await e.json(),u=l.health??l.data??{status:"unknown",factCount:0};return _(u),u}catch{return _({status:"unavailable",factCount:0}),{status:"unavailable",factCount:0}}},[]),D=r.useCallback(async(e,l)=>{ee(!0),y("testing");try{const se=await(await fetch("/api/memory/config",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({backend:e,connectionString:l})})).json();se.status==="success"?(y("success"),m({store:e}),await M()):(y("error"),console.error("Connection test failed:",se.error))}catch(u){y("error"),console.error("Connection test error:",u)}ee(!1)},[m,M]),fe=r.useCallback(async e=>{const l=e;l==="postgres"?(m({store:l}),y("idle")):l==="local_sqlite"?await D(l):(m({store:l}),y("idle"))},[m,D]),P=r.useCallback(async()=>{try{const e=await fetch("/api/cache/stats");if(!e.ok)return;const l=await e.json();ge(l)}catch{}},[]),ye=r.useCallback(async()=>{Z(!0);try{await fetch("/api/cache/purge",{method:"DELETE"}),await P()}catch{}Z(!1)},[P]);r.useEffect(()=>{M(),P()},[M,P]);const v=o.tokenBudget+t.tokenBudget+n.tokenBudget,p=e=>e>=1e3?`${(e/1e3).toFixed(0)}K`:`${e}`;return t.enabled,n.enabled,s.jsxs("div",{className:"space-y-6",children:[s.jsxs("div",{children:[s.jsx("h2",{className:"text-2xl font-semibold mb-2 m-0",style:{color:a.textPrimary,fontFamily:"'Geist Sans', sans-serif"},children:"Memory Configuration"}),s.jsx("p",{className:"text-sm",style:{color:a.textSecondary,lineHeight:1.5},children:"Configure how your agent remembers and manages information across conversations. Set up session memory, long-term storage, working memory, and seed facts."})]}),s.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-6",children:[s.jsxs("div",{className:"space-y-6",children:[s.jsxs(j,{icon:T,label:"Session Memory",color:"#3498db",badge:`${o.windowSize} messages · ${o.strategy}`,collapsed:H,onToggle:()=>re(!H),children:[s.jsx("div",{className:"flex justify-end mb-4",children:s.jsx(De,{loading:be,onClick:he,label:"Configure"})}),s.jsx(b,{label:"Window Size",value:o.windowSize,min:5,max:100,step:5,onChange:e=>d({windowSize:e})}),s.jsxs("div",{className:"mb-4",children:[s.jsx(x,{options:L,value:o.strategy,onChange:e=>d({strategy:e}),label:"Strategy"}),L.find(e=>e.value===o.strategy)?.description&&s.jsx("p",{className:"text-xs mt-1",style:{color:a.textSecondary},children:L.find(e=>e.value===o.strategy)?.description})]}),o.strategy==="summarize_and_recent"&&s.jsx(b,{label:"Summarize After",value:o.summarizeAfter,min:5,max:o.windowSize,step:5,onChange:e=>d({summarizeAfter:e})}),s.jsx("div",{className:"mb-4",children:s.jsx(w,{checked:o.summarizeEnabled,onChange:e=>d({summarizeEnabled:e}),label:"Enable summarization of older messages"})}),s.jsx(b,{label:"Token Budget",value:o.tokenBudget,min:1e3,max:6e4,step:1e3,onChange:e=>d({tokenBudget:e}),suffix:"K"})]}),s.jsxs(j,{icon:T,label:"Seed Facts",color:"#e74c3c",badge:`${i.length} facts`,collapsed:Y,onToggle:()=>de(!Y),children:[s.jsxs("div",{className:"space-y-2 mb-4",children:[i.map(e=>{const l=z[e.domain]||"#999";return s.jsxs("div",{style:{...Ye,background:a.surfaceElevated},children:[s.jsx("div",{style:{width:6,height:6,borderRadius:"50%",background:G[e.type]||"#999",flexShrink:0}}),s.jsx("span",{className:"flex-1 truncate",style:{color:a.textPrimary},children:e.content}),s.jsx("span",{style:{...Qe,background:`${l}15`,color:l},children:e.domain.replace("_"," ")}),e.tags.length>0&&e.tags.map(u=>s.jsx("span",{style:{...Xe,background:`${G[e.type]||"#999"}15`,color:G[e.type]||"#999"},children:u},u)),s.jsx("button",{type:"button","aria-label":"Remove fact",title:"Remove fact",onClick:()=>ne(e.id),style:{...qe,color:a.textFaint},onMouseEnter:u=>{u.currentTarget.style.background="#ef444420",u.currentTarget.style.color="#ef4444"},onMouseLeave:u=>{u.currentTarget.style.background="transparent",u.currentTarget.style.color=a.textFaint},children:s.jsx(we,{size:12})})]},e.id)}),i.length===0&&s.jsx("div",{className:"text-center py-8 text-sm",style:{color:a.textDim},children:"No seed facts added yet. Add facts that your agent should always remember."})]}),s.jsxs("div",{className:"flex gap-2",children:[s.jsx(ae,{value:N,onChange:e=>B(e.target.value),onKeyDown:e=>{e.key==="Enter"&&N.trim()&&(f(N.trim(),[],"fact",O),B(""))},placeholder:"Add a seed fact...",className:"flex-1"}),s.jsxs("select",{value:O,onChange:e=>pe(e.target.value),"aria-label":"Fact domain",title:"Select fact domain",className:"text-sm px-3 rounded border-none cursor-pointer",style:{background:a.surfaceElevated,color:a.textPrimary,fontFamily:"'Geist Mono', monospace"},children:[s.jsx("option",{value:"shared",children:"shared"}),s.jsx("option",{value:"agent_private",children:"private"}),s.jsx("option",{value:"run_scratchpad",children:"scratch"})]}),s.jsx("button",{type:"button","aria-label":"Add fact",title:"Add new fact",onClick:()=>{N.trim()&&(f(N.trim(),[],"fact",O),B(""))},className:"px-3 border-none rounded cursor-pointer shrink-0 min-w-[44px] min-h-[44px] flex items-center justify-center",style:{background:"#FE5000",color:"#fff"},children:s.jsx(Te,{size:12})})]})]}),s.jsx(j,{icon:T,label:"Sandbox Configuration",color:"#9b59b6",badge:$.isolation,collapsed:Q,onToggle:()=>me(!Q),children:s.jsxs("div",{className:"space-y-4",children:[s.jsx(x,{options:Je,value:$.isolation,onChange:e=>I({isolation:e}),label:"Isolation"}),s.jsx("div",{children:s.jsx(w,{checked:$.allowPromoteToShared,onChange:e=>I({allowPromoteToShared:e}),label:"Allow promote to shared memory"})}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium mb-2",style:{color:a.textPrimary},children:"Memory Domains"}),s.jsx("div",{className:"flex flex-wrap gap-2",children:[{key:"shared",label:"Shared",color:z.shared},{key:"agentPrivate",label:"Agent Private",color:z.agent_private},{key:"runScratchpad",label:"Run Scratchpad",color:z.run_scratchpad}].map(e=>{const l=$.domains[e.key].enabled;return s.jsx("button",{type:"button","aria-label":`Toggle ${e.label}`,title:`Toggle ${e.label}`,"aria-pressed":l,onClick:()=>le(e.key,!l),className:"text-sm px-3 py-2 rounded-full cursor-pointer border-none min-h-[44px]",style:{fontFamily:"'Geist Sans', sans-serif",background:l?`${e.color}20`:a.isDark?"#1c1c20":"#f0f0f5",color:l?e.color:a.textDim,border:`1px solid ${l?`${e.color}40`:"transparent"}`},children:e.label},e.key)})})]})]})})]}),s.jsxs("div",{className:"space-y-6",children:[s.jsxs(j,{icon:T,label:"Long-Term Memory",color:"#2ecc71",badge:t.enabled?`${t.store}${g?` · ${g.factCount} facts`:` · ${t.maxEntries} max`}`:"disabled",collapsed:K,onToggle:()=>ie(!K),children:[s.jsx("div",{className:"mb-4",children:s.jsx(w,{checked:t.enabled,onChange:e=>m({enabled:e}),label:"Enable long-term memory"})}),t.enabled&&s.jsxs("div",{className:"space-y-4",children:[s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[s.jsx(x,{options:Le,value:t.store,onChange:fe,label:"Store"}),s.jsx(x,{options:He,value:t.scope,onChange:e=>m({scope:e}),label:"Scope"})]}),t.store==="postgres"&&s.jsxs("div",{className:"space-y-3",children:[s.jsxs("div",{className:"flex gap-2",children:[s.jsx(ae,{value:R,onChange:e=>xe(e.target.value),placeholder:"postgresql://user:password@localhost:5432/database",className:"flex-1",type:"password"}),s.jsx("button",{type:"button",onClick:()=>D("postgres",R),disabled:!R||V,className:"px-4 py-2 rounded text-sm font-medium disabled:opacity-50 disabled:cursor-not-allowed min-w-[120px] flex items-center justify-center gap-2",style:{background:A==="success"?"#2ecc71":"#FE5000",color:"#fff"},children:V?s.jsxs(s.Fragment,{children:[s.jsx(te,{size:14,className:"animate-spin"}),"Testing..."]}):"Test Connection"})]}),s.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[A==="success"&&s.jsxs(s.Fragment,{children:[s.jsx(Ee,{size:14,style:{color:"#2ecc71"}}),s.jsx("span",{style:{color:"#2ecc71"},children:"Connected successfully"})]}),A==="error"&&s.jsxs(s.Fragment,{children:[s.jsx($e,{size:14,style:{color:"#e74c3c"}}),s.jsx("span",{style:{color:"#e74c3c"},children:"Connection failed"})]})]})]}),["redis","chromadb","pinecone","custom"].includes(t.store)&&s.jsxs("div",{className:"flex items-center gap-2 p-3 rounded",style:{background:"#f39c1220",border:"1px solid #f39c1240"},children:[s.jsx(Fe,{size:16,style:{color:"#f39c12"}}),s.jsx("span",{className:"text-sm",style:{color:"#f39c12"},children:"Coming soon"})]}),g&&s.jsxs("div",{className:"flex items-center gap-2 p-3 rounded",style:{background:g.status==="healthy"?"#2ecc7120":"#e74c3c20",border:`1px solid ${g.status==="healthy"?"#2ecc7140":"#e74c3c40"}`},children:[s.jsx(Me,{size:16,style:{color:g.status==="healthy"?"#2ecc71":"#e74c3c"}}),s.jsx("span",{className:"text-sm",style:{color:g.status==="healthy"?"#2ecc71":"#e74c3c"},children:g.status==="healthy"?`${g.factCount} facts stored`:"Backend unavailable"})]}),s.jsx(x,{options:Ge,value:t.embeddingModel,onChange:e=>m({embeddingModel:e}),label:"Embedding Model"}),s.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[s.jsx(x,{options:Ie,value:t.recall.strategy,onChange:e=>h({strategy:e}),label:"Recall Strategy"}),s.jsx(b,{label:"K",value:t.recall.k,min:1,max:20,step:1,onChange:e=>h({k:e})})]}),s.jsx(b,{label:"Min Score",value:Math.round(t.recall.minScore*100),min:0,max:100,step:5,onChange:e=>h({minScore:e/100})}),s.jsx(x,{options:We,value:t.write.mode,onChange:e=>E({mode:e}),label:"Write Mode"}),s.jsxs("div",{children:[s.jsx("label",{className:"block text-sm font-medium mb-2",style:{color:a.textPrimary},children:"Extract Types"}),s.jsx("div",{className:"flex flex-wrap gap-2",children:Ke.map(e=>{const l=t.write.extractTypes.includes(e.value);return s.jsx("button",{type:"button","aria-label":`Toggle ${e.label}`,"aria-pressed":l,onClick:()=>S(e.value),className:"text-sm px-3 py-2 rounded-full cursor-pointer border-none min-h-[44px]",style:{fontFamily:"'Geist Sans', sans-serif",background:l?`${e.color}20`:a.isDark?"#1c1c20":"#f0f0f5",color:l?e.color:a.textDim,border:`1px solid ${l?`${e.color}40`:"transparent"}`},children:e.label},e.value)})})]}),s.jsx(b,{label:"Max Entries",value:t.maxEntries,min:100,max:1e4,step:100,onChange:e=>m({maxEntries:e})}),s.jsx(b,{label:"Token Budget",value:t.tokenBudget,min:1e3,max:3e4,step:1e3,onChange:e=>m({tokenBudget:e}),suffix:"K"})]})]}),s.jsxs(j,{icon:T,label:"Working Memory",color:"#f1c40f",badge:n.enabled?`${p(n.maxTokens)} max`:"disabled",collapsed:J,onToggle:()=>ce(!J),children:[s.jsx("div",{className:"mb-4",children:s.jsx(w,{checked:n.enabled,onChange:e=>C({enabled:e}),label:"Enable working memory scratchpad"})}),n.enabled&&s.jsx(b,{label:"Max Tokens",value:n.maxTokens,min:500,max:8e3,step:500,onChange:e=>C({maxTokens:e})})]}),s.jsx(j,{icon:Pe,label:"Response Cache",color:"#FE5000",badge:k?.enabled?`enabled · TTL ${k.ttlSeconds}s`:"disabled",collapsed:X,onToggle:()=>ue(!X),children:s.jsxs("div",{className:"space-y-4",children:[s.jsx(w,{checked:k?.enabled??!1,onChange:e=>W({enabled:e}),label:"Enable semantic response caching"}),k?.enabled&&s.jsxs(s.Fragment,{children:[s.jsx(b,{label:"TTL",value:k.ttlSeconds,min:60,max:86400,step:60,onChange:e=>W({ttlSeconds:e}),suffix:"s"}),F&&s.jsx("div",{className:"grid grid-cols-3 gap-3",children:[{label:"Entries",value:String(F.totalEntries)},{label:"Hit Rate",value:`${(F.hitRate*100).toFixed(1)}%`},{label:"Saved",value:`$${F.estimatedSavings.toFixed(4)}`}].map(e=>s.jsxs("div",{className:"p-3 rounded text-center",style:{background:a.surfaceElevated},children:[s.jsx("div",{className:"text-lg font-semibold",style:{color:"#FE5000",fontFamily:"'Geist Mono', monospace"},children:e.value}),s.jsx("div",{className:"text-xs",style:{color:a.textDim},children:e.label})]},e.label))}),s.jsxs("button",{type:"button",onClick:ye,disabled:q,className:"flex items-center gap-2 px-4 py-2 rounded text-sm font-medium disabled:opacity-50 border-none cursor-pointer",style:{background:"#e74c3c20",color:"#e74c3c",border:"1px solid #e74c3c40"},children:[q?s.jsx(te,{size:14,className:"animate-spin"}):s.jsx(ze,{size:14}),"Purge Cache"]})]})]})}),v>0&&s.jsxs("div",{className:"mt-6 p-4 rounded-lg",style:{background:a.surfaceElevated,border:`1px solid ${a.border}`},children:[s.jsx("h3",{className:"text-sm font-semibold mb-3",style:{color:a.textPrimary,fontFamily:"'Geist Sans', sans-serif"},children:"Memory Budget Allocation"}),s.jsxs("div",{className:"flex gap-1 h-2 rounded overflow-hidden mb-3","aria-label":`Memory budget allocation: Session ${p(o.tokenBudget)}, ${t.enabled?`Long-term ${p(t.tokenBudget)}, `:""}${n.enabled?`Working ${p(n.tokenBudget)}, `:""}Total ${p(v)}`,role:"img",children:[s.jsx("div",{style:{width:`${o.tokenBudget/v*100}%`,background:"#3498db",borderRadius:2},title:`Session: ${p(o.tokenBudget)}`}),t.enabled&&s.jsx("div",{style:{width:`${t.tokenBudget/v*100}%`,background:"#2ecc71",borderRadius:2},title:`Long-term: ${p(t.tokenBudget)}`}),n.enabled&&s.jsx("div",{style:{width:`${n.tokenBudget/v*100}%`,background:"#f1c40f",borderRadius:2},title:`Working: ${p(n.tokenBudget)}`})]}),s.jsxs("div",{className:"flex justify-between",children:[s.jsx("div",{className:"flex gap-4",children:[{label:"Session",color:"#3498db",tokens:o.tokenBudget},...t.enabled?[{label:"Long-term",color:"#2ecc71",tokens:t.tokenBudget}]:[],...n.enabled?[{label:"Working",color:"#f1c40f",tokens:n.tokenBudget}]:[]].map(e=>s.jsxs("span",{className:"flex items-center gap-2 text-sm",style:{fontFamily:"'Geist Mono', monospace",color:a.textDim},children:[s.jsx("div",{style:{width:6,height:6,borderRadius:1,background:e.color}}),e.label]},e.label))}),s.jsxs("span",{className:"text-sm font-semibold",style:{fontFamily:"'Geist Mono', monospace",color:"#FE5000"},children:[p(v)," total"]})]})]})]})]})]})}export{os as MemoryTab};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as e,r as y}from"./vendor-D1h_O76p.js";import{u as w,T as xe,a as W,B as _}from"./index-C626nWuA.js";import{u as q,r as V,H as pe,n as me,I as ue,J as he,a as ge,L as fe}from"./services-BDk6yY4o.js";import{u as l,B as F}from"./Badge-Bsy2H_p2.js";import{I as G}from"./Input-Dyb88Erk.js";import{aG as U,Q as X,s as ye,X as Y,a1 as J,P as K,aH as Z,a4 as ee,W as be,C as je,a as ve}from"./icons-CS8RUPBi.js";import"./stores-CeKWz7ou.js";function Se({value:t,showLabel:d=!1,className:n="",color:p}){const i=w(),c=Math.max(0,Math.min(100,t));return e.jsxs("div",{className:`flex flex-col gap-1 ${n}`,children:[d&&e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"text-[14px] font-semibold",style:{color:i.textSecondary,fontFamily:"'Geist Mono', monospace",fontSize:12},children:"Progress"}),e.jsxs("span",{className:"text-[14px]",style:{color:i.textMuted,fontFamily:"'Geist Mono', monospace",fontSize:12},children:[Math.round(c),"%"]})]}),e.jsx("div",{className:"h-2 rounded-full overflow-hidden",style:{background:i.surfaceElevated},children:e.jsx("div",{className:"h-full transition-all duration-300 ease-out",style:{width:`${c}%`,background:p||"#FE5000"}})})]})}const B={nominal:"#2ecc71",edge:"#f39c12",anti:"#e74c3c"};function $({label:t,color:d,collapsed:n,onToggle:p,right:i,t:c}){return e.jsxs("div",{className:"flex items-center gap-2.5 w-full px-5 py-3.5 select-none",style:{borderTop:`1px solid ${c.isDark?"#222226":"#e8e8ec"}`,background:`${d}08`},children:[e.jsxs("button",{type:"button",onClick:p,"aria-expanded":!n,className:"flex items-center gap-2.5 flex-1 cursor-pointer border-none bg-transparent p-0 text-left",children:[n?e.jsx(je,{size:12,style:{color:c.textDim}}):e.jsx(ve,{size:12,style:{color:c.textDim}}),e.jsx("div",{style:{width:3,height:14,borderRadius:2,background:d,opacity:.8}}),e.jsx("span",{className:"text-[12px] font-bold tracking-[0.08em] uppercase",style:{fontFamily:"'Geist Mono', monospace",color:c.textPrimary},children:t})]}),i]})}function I({score:t,threshold:d}){const n=t>=d;return e.jsxs("span",{className:"inline-flex items-center gap-1 text-[13px] font-bold px-2 py-0.5 rounded-full",style:{background:n?"#2ecc7120":"#e74c3c20",color:n?"#2ecc71":"#e74c3c",fontFamily:"'Geist Mono', monospace"},children:[n?e.jsx(Z,{size:11}):e.jsx(ee,{size:11}),t]})}function Ne(){const t=w(),d=l(s=>s.status),n=l(s=>s.suite),p=l(s=>s.runs),i=l(s=>s.latestRunId),c=l(s=>s.publishGated),b=l(s=>s.setMissionBrief),g=l(s=>s.addTestCase),f=l(s=>s.updateTestCase),j=l(s=>s.removeTestCase),m=l(s=>s.addScoringDimension),o=l(s=>s.updateScoringDimension),u=l(s=>s.removeScoringDimension),N=l(s=>s.setPassThreshold),h=l(s=>s.setStatus),M=l(s=>s.recordRun),D=l(s=>s.applyPatch),k=q(s=>s.agentMeta),C=q(s=>s.instructionState),[E,se]=y.useState(!0),[O,te]=y.useState(!0),[A,ne]=y.useState(!1),[L,oe]=y.useState(!0),[z,P]=y.useState(null),x=p.find(s=>s.id===i),ae=!c||x&&x.globalScore>=n.passThreshold,re=y.useCallback(async()=>{if(n.missionBrief.trim()){P("generate"),h("generating");try{const s=V(),r=await pe({agentId:k.name||"current",missionBrief:n.missionBrief,persona:C.persona,constraints:C.constraints.customConstraints,objectives:C.objectives.primary,providerId:s.providerId||void 0,model:s.model||void 0});for(const a of r.testCases)g({type:a.type,label:a.label,input:a.input,expectedBehavior:a.expectedBehavior});for(const a of r.scoringDimensions)m({name:a.name,weight:a.weight});h("not-started")}catch{h("error")}P(null)}},[n.missionBrief,g,m,h,k.name,C.persona,C.constraints.customConstraints,C.objectives.primary]),ie=y.useCallback(async()=>{P("run"),h("running");const s=me.getState(),r=s.startTrace(`qualification-${Date.now()}`,"0.0.0");try{const a=V(),R=a.providerId||"default",v=a.model||"claude-opus-4",T=await ue({agentId:k.name||"current",providerId:R,model:v,suite:{missionBrief:n.missionBrief,testCases:n.testCases.map(({id:S,type:Q,label:H,input:ce,expectedBehavior:de})=>({id:S,type:Q,label:H,input:ce,expectedBehavior:de})),scoringDimensions:n.scoringDimensions.map(({id:S,name:Q,weight:H})=>({id:S,name:Q,weight:H})),passThreshold:n.passThreshold}},S=>{S.type==="case_start"?s.addEvent(r,{kind:"llm_call",model:v}):S.type==="case_done"&&s.addEvent(r,{kind:"llm_call",model:v,outputTokens:S.score})});s.endTrace(r),M({id:T.runId,timestamp:Date.now(),globalScore:T.globalScore,dimensionScores:T.dimensionScores,testResults:T.testResults,patches:T.patches})}catch{s.endTrace(r),h("error")}P(null)},[n,M,h,k.name]),le=y.useCallback(async(s,r)=>{const R=p.find(v=>v.id===s)?.patches.find(v=>v.id===r);try{await he({agentId:k.name||"current",runId:s,patchIds:[r],patches:R?[R]:void 0}),D(s,r)}catch{}},[D,k.name,p]);return e.jsxs("div",{className:"flex flex-col gap-5",children:[e.jsxs("div",{className:"rounded-xl overflow-hidden",style:{background:t.surfaceOpaque,border:`1px solid ${t.border}`,boxShadow:`0 2px 12px ${t.isDark?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.06)"}`},children:[e.jsxs("div",{className:"flex items-center gap-2.5 px-5 py-3.5 select-none",style:{borderBottom:`1px solid ${t.border}`,background:t.surfaceElevated},children:[e.jsx(U,{size:14,style:{color:"#3498db"}}),e.jsx(xe,{content:"Qualify your agent before deployment",children:e.jsx("span",{className:"text-[13px] font-bold tracking-[0.08em] uppercase",style:{fontFamily:"'Geist Mono', monospace",color:t.textPrimary},children:"Qualification"})}),e.jsx("div",{className:"flex-1"}),x&&e.jsx(I,{score:x.globalScore,threshold:n.passThreshold}),e.jsx(F,{variant:d==="passed"?"success":d==="needs-work"?"warning":d==="error"?"error":"neutral",children:d.replace("-"," ")})]}),e.jsx($,{label:"Mission Brief",color:"#3498db",collapsed:!E,onToggle:()=>se(!E),t,right:e.jsxs("button",{type:"button",onClick:re,disabled:z==="generate"||!n.missionBrief.trim(),className:"flex items-center gap-1 text-[13px] px-2 py-1 rounded cursor-pointer border-none",style:{background:"#3498db15",color:"#3498db",fontFamily:"'Geist Mono', monospace",opacity:n.missionBrief.trim()?1:.4},children:[z==="generate"?e.jsx(X,{size:9,className:"animate-spin"}):e.jsx(ye,{size:9}),"Generate Suite"]})}),E&&e.jsx("div",{className:"px-5 py-4",children:e.jsx(W,{label:"What should this agent do well? Describe its mission.",value:n.missionBrief,onChange:s=>b(s.target.value),placeholder:"e.g. This agent helps PMs write user stories from raw feedback. It should cite sources, stay concise, and refuse to fabricate data...",style:{minHeight:64}})}),e.jsx($,{label:`Test Cases (${n.testCases.length})`,color:"#f39c12",collapsed:!O,onToggle:()=>te(!O),t}),O&&e.jsxs("div",{className:"px-5 py-4 flex flex-col gap-3",children:[n.testCases.map(s=>{const r=x?.testResults.find(a=>a.testCaseId===s.id);return e.jsxs("div",{className:"rounded-lg p-3",style:{background:t.surfaceElevated,border:`1px solid ${t.border}`},children:[e.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[e.jsx("span",{className:"text-[13px] font-bold px-1.5 py-0.5 rounded",style:{background:`${B[s.type]}20`,color:B[s.type],fontFamily:"'Geist Mono', monospace"},children:s.type}),e.jsx(G,{value:s.label,onChange:a=>f(s.id,{label:a.target.value}),placeholder:"Test label...",style:{flex:1,fontSize:14}}),r&&e.jsx(I,{score:r.score,threshold:n.passThreshold}),e.jsx("button",{type:"button","aria-label":"Remove test case",onClick:()=>j(s.id),className:"border-none bg-transparent cursor-pointer p-1",style:{color:t.textFaint},children:e.jsx(Y,{size:11})})]}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(W,{label:"Input",value:s.input,onChange:a=>f(s.id,{input:a.target.value}),placeholder:"Agent input...",style:{minHeight:40,fontSize:13}}),e.jsx(W,{label:"Expected",value:s.expectedBehavior,onChange:a=>f(s.id,{expectedBehavior:a.target.value}),placeholder:"Expected behavior...",style:{minHeight:40,fontSize:13}})]}),r?.feedback&&e.jsx("div",{className:"mt-2 text-[12px] px-2 py-1 rounded",style:{background:r.passed?"#2ecc7110":"#e74c3c10",color:r.passed?"#2ecc71":"#e74c3c"},children:r.feedback})]},s.id)}),e.jsx("div",{className:"flex gap-2 justify-center",children:["nominal","edge","anti"].map(s=>e.jsxs("button",{type:"button",onClick:()=>g({type:s,label:"",input:"",expectedBehavior:""}),className:"flex items-center gap-1 text-[12px] px-3 py-1.5 rounded cursor-pointer border-none",style:{background:`${B[s]}15`,color:B[s],fontFamily:"'Geist Mono', monospace"},children:[e.jsx(J,{size:10})," ",s]},s))})]}),e.jsx($,{label:"Scoring Rubric",color:"#9b59b6",collapsed:!A,onToggle:()=>ne(!A),t}),A&&e.jsxs("div",{className:"px-5 py-4 flex flex-col gap-2",children:[n.scoringDimensions.map(s=>{const r=x?.dimensionScores[s.id];return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(G,{value:s.name,onChange:a=>o(s.id,{name:a.target.value}),placeholder:"Dimension...",style:{flex:1,fontSize:14}}),e.jsx(G,{value:String(Math.round(s.weight*100)),type:"number",onChange:a=>o(s.id,{weight:Number(a.target.value)/100}),style:{width:56,fontSize:13,textAlign:"center"}}),e.jsx("span",{className:"text-[13px]",style:{color:t.textDim},children:"%"}),r!==void 0&&e.jsx(I,{score:r,threshold:n.passThreshold}),e.jsx("button",{type:"button","aria-label":"Remove dimension",onClick:()=>u(s.id),className:"border-none bg-transparent cursor-pointer p-1",style:{color:t.textFaint},children:e.jsx(Y,{size:11})})]},s.id)}),e.jsxs("button",{type:"button",onClick:()=>m({name:"",weight:.25}),className:"flex items-center gap-1 text-[12px] cursor-pointer border-none bg-transparent self-start",style:{color:"#9b59b6",fontFamily:"'Geist Mono', monospace"},children:[e.jsx(J,{size:10})," Add Dimension"]}),e.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[e.jsx("span",{className:"text-[12px] font-semibold",style:{color:t.textDim,fontFamily:"'Geist Mono', monospace"},children:"Pass Threshold"}),e.jsx(G,{value:String(n.passThreshold),type:"number",onChange:s=>N(Number(s.target.value)),style:{width:56,fontSize:13,textAlign:"center"}}),e.jsx("span",{className:"text-[13px]",style:{color:t.textDim},children:"/ 100"})]})]})]}),e.jsxs("div",{className:"rounded-xl overflow-hidden",style:{background:t.surfaceOpaque,border:`1px solid ${t.border}`,boxShadow:`0 2px 12px ${t.isDark?"rgba(0,0,0,0.3)":"rgba(0,0,0,0.06)"}`},children:[e.jsxs("div",{className:"flex items-center gap-2.5 px-5 py-3.5 select-none",style:{background:t.surfaceElevated,borderBottom:`1px solid ${t.border}`},children:[e.jsx(K,{size:12,style:{color:"#3498db"}}),e.jsx("span",{className:"text-[13px] font-bold tracking-[0.08em] uppercase flex-1",style:{fontFamily:"'Geist Mono', monospace",color:t.textPrimary},children:"Run & Results"}),e.jsx(_,{size:"sm",onClick:ie,disabled:z==="run"||n.testCases.length===0,children:z==="run"?e.jsxs(e.Fragment,{children:[e.jsx(X,{size:11,className:"animate-spin"})," Running..."]}):e.jsxs(e.Fragment,{children:[e.jsx(K,{size:11})," Run Qualification"]})})]}),x?e.jsxs("div",{className:"px-5 py-4 flex flex-col gap-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("span",{className:"text-[12px] font-bold tracking-wider uppercase",style:{color:t.textDim,fontFamily:"'Geist Mono', monospace"},children:"Global Score"}),e.jsx("div",{className:"flex-1",children:e.jsx(Se,{value:x.globalScore,color:x.globalScore>=n.passThreshold?"#2ecc71":"#e74c3c"})}),e.jsx(I,{score:x.globalScore,threshold:n.passThreshold})]}),e.jsx($,{label:"Test Results",color:"#f39c12",collapsed:!L,onToggle:()=>oe(!L),t}),L&&x.testResults.map(s=>{const r=n.testCases.find(a=>a.id===s.testCaseId);return e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded",style:{background:s.passed?"#2ecc7108":"#e74c3c08",border:`1px solid ${s.passed?"#2ecc7120":"#e74c3c20"}`},children:[s.passed?e.jsx(Z,{size:12,style:{color:"#2ecc71"}}):e.jsx(ee,{size:12,style:{color:"#e74c3c"}}),e.jsx("span",{className:"text-[13px] flex-1",style:{color:t.textPrimary},children:r?.label||s.testCaseId}),e.jsx("span",{className:"text-[12px] font-bold",style:{fontFamily:"'Geist Mono', monospace",color:s.passed?"#2ecc71":"#e74c3c"},children:s.score})]},s.testCaseId)}),x.patches.length>0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("span",{className:"text-[12px] font-bold tracking-wider uppercase",style:{color:t.textDim,fontFamily:"'Geist Mono', monospace"},children:"Suggested Patches"}),x.patches.map(s=>e.jsxs("div",{className:"flex items-start gap-2 px-3 py-2 rounded",style:{background:"#f39c1208",border:"1px solid #f39c1220"},children:[e.jsx(be,{size:11,style:{color:"#f39c12",marginTop:2}}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-[13px]",style:{color:t.textPrimary},children:s.description}),e.jsx("code",{className:"text-[12px] block mt-1",style:{color:"#2ecc71",fontFamily:"'Geist Mono', monospace"},children:s.diff})]}),s.applied?e.jsx(F,{variant:"success",children:"Applied"}):e.jsx(_,{size:"sm",onClick:()=>le(x.id,s.id),children:"Apply"})]},s.id))]}),e.jsxs("div",{className:"flex items-center justify-between px-3 py-2 rounded",style:{background:t.surfaceElevated,border:`1px solid ${t.border}`},children:[e.jsx("span",{className:"text-[12px] font-bold tracking-wider uppercase",style:{color:t.textDim,fontFamily:"'Geist Mono', monospace"},children:"Publish Gate"}),ae?e.jsx(F,{variant:"success",children:"Ready to publish"}):e.jsxs(F,{variant:"error",children:["Score below ",n.passThreshold,"%"]})]})]}):e.jsxs("div",{className:"px-5 py-8 text-center",children:[e.jsx(U,{size:24,style:{color:t.textFaint,margin:"0 auto 8px"}}),e.jsx("div",{className:"text-[13px]",style:{color:t.textFaint},children:n.testCases.length===0?"Write a mission brief and generate a test suite to get started.":'Click "Run Qualification" to evaluate your agent.'})]})]})]})}function ke(){const t=w(),n=[...l(m=>m.runs)].sort((m,o)=>m.timestamp-o.timestamp).slice(-10);if(n.length<2)return null;const p=120,i=30,c=4,b=n.map((m,o)=>{const u=c+o/(n.length-1)*(p-2*c),N=c+(100-m.globalScore)/100*(i-2*c);return`${u},${N}`}).join(" "),f=n[n.length-1].globalScore>=n[0].globalScore?"#2ecc71":"#e74c3c",j=n[n.length-1].globalScore;return e.jsxs("div",{style:{display:"flex",alignItems:"center",gap:"12px",padding:"8px 12px",backgroundColor:t.surface,borderRadius:"6px",border:`1px solid ${t.border}`},children:[e.jsxs("div",{style:{display:"flex",flexDirection:"column",gap:"2px"},children:[e.jsxs("span",{style:{fontSize:"11px",color:t.textSecondary,fontWeight:500},children:["Score Trend (",n.length," runs)"]}),e.jsxs("span",{style:{fontSize:"14px",color:t.textPrimary,fontWeight:600},children:[j.toFixed(1),"%"]})]}),e.jsx("svg",{width:p,height:i,style:{flexShrink:0},children:e.jsx("polyline",{points:b,fill:"none",stroke:f,strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})})]})}function Ce(){const t=w(),d=ge(o=>o.agentId)??"",p=fe(o=>o.lessons).filter(o=>o.agentId===d),i=p.filter(o=>o.status==="approved"),c=i.length>0?i.reduce((o,u)=>o+u.confidence,0)/i.length:0,b=[...i].sort((o,u)=>new Date(o.lastSeenAt).getTime()-new Date(u.lastSeenAt).getTime());if(p.length===0)return null;const g=10,f=3,j=40,m=Math.max(100,b.length*(g+f));return e.jsxs("div",{className:"rounded-lg p-4 space-y-3",style:{background:t.surface,border:`1px solid ${t.border}`,fontFamily:"'Geist Sans', sans-serif"},children:[e.jsx("h4",{className:"text-sm font-semibold m-0",style:{color:t.textPrimary},children:"Learning Velocity"}),e.jsxs("div",{className:"flex gap-6 flex-wrap",children:[e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px]",style:{color:t.textDim},children:"Corrections Retained"}),e.jsx("div",{className:"text-lg font-semibold tabular-nums",style:{color:t.textPrimary},children:i.length})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px]",style:{color:t.textDim},children:"Repeated Mistakes"}),e.jsx("div",{className:"text-lg font-semibold tabular-nums",style:{color:t.textPrimary},children:"0"})]}),e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px]",style:{color:t.textDim},children:"Avg Confidence"}),e.jsx("div",{className:"text-lg font-semibold tabular-nums",style:{color:t.textPrimary},children:i.length>0?`${Math.round(c*100)}%`:"—"})]})]}),b.length>0&&e.jsxs("div",{children:[e.jsx("div",{className:"text-[11px] mb-1",style:{color:t.textDim,fontFamily:"'Geist Mono', monospace"},children:"CONFIDENCE BY LESSON (oldest → newest)"}),e.jsx("svg",{width:m,height:j,style:{display:"block",overflow:"visible"},children:b.map((o,u)=>{const N=Math.max(2,Math.round(o.confidence*(j-4))),h=u*(g+f),M=j-N,D=o.confidence<.5?"#e74c3c":o.confidence<.7?"#f39c12":"#2ecc71";return e.jsx("rect",{x:h,y:M,width:g,height:N,rx:2,fill:D,opacity:.85,children:e.jsx("title",{children:`${Math.round(o.confidence*100)}% — ${o.rule.slice(0,40)}`})},o.id)})})]})]})}function Fe(){const t=w();return e.jsxs("div",{className:"space-y-6",children:[e.jsx("div",{children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-start sm:justify-between gap-4 mb-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-semibold mb-2 m-0",style:{color:t.textPrimary,fontFamily:"'Geist Sans', sans-serif"},children:"Qualification & Testing"}),e.jsx("p",{className:"text-sm",style:{color:t.textSecondary,lineHeight:1.5},children:"Run comprehensive test suites to validate your agent's performance, reliability, and adherence to requirements before production deployment."})]}),e.jsx(ke,{})]})}),e.jsx(Ce,{}),e.jsx(Ne,{})]})}export{Fe as QualificationTab};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import{r as g,j as e}from"./vendor-D1h_O76p.js";import{a as B,e as V,j as Ge,k as We,O as at,u as j,m as ke,L as Y,A as ie,W as rt,G as it,X as lt,F as ct,Y as dt,n as pt}from"./services-BDk6yY4o.js";import{useConversationStore as Ue}from"./conversationStore-CkfEU2eV.js";import{B as ut,u as Pe}from"./Badge-Bsy2H_p2.js";import{u as E,M as mt,B as de,a as se,S as we,g as xt,d as ee,e as Re,h as ht,i as ft}from"./index-C626nWuA.js";import{I as K}from"./Input-Dyb88Erk.js";import{X as oe,i as Ie,aR as He,C as Ye,R as gt,ad as Ke,aS as yt,ak as Ce,B as bt,Z as _e,g as vt,ag as Se,T as Fe,am as jt,d as Te,aT as kt,E as wt,y as St,h as Nt,aU as Ct,aV as Ft,aW as Tt,aX as Mt,aY as Et,aZ as $t,a_ as At,a$ as Dt,b0 as Je,a1 as Oe,u as Ve,S as Pt,ac as Rt,a0 as ze,a as Xe,Q as It,w as Ot,V as Ne,b1 as zt,b2 as Lt,b3 as Bt,aK as Gt,aj as Wt}from"./icons-CS8RUPBi.js";import{S as W,T as te}from"./Section-68XDCFTl.js";import"./stores-CeKWz7ou.js";const Ut=g.forwardRef(function({icon:a,size:t="md",variant:n="ghost",tooltip:s,active:l,className:c="",style:d,...m},y){const r=E(),f=t==="sm"?24:32,v={ghost:{bg:l?"#FE500020":"transparent",color:l?"#FE5000":r.textDim,hoverBg:r.isDark?"#ffffff10":"#00000008"},secondary:{bg:r.surfaceElevated,color:r.textSecondary,hoverBg:r.isDark?"#2a2a30":"#eee"},danger:{bg:"transparent",color:r.statusError,hoverBg:r.statusErrorBg}}[n];return e.jsx("button",{ref:y,type:"button",title:s,"aria-label":s,className:`ds-icon-btn flex items-center justify-center rounded-md cursor-pointer border-none nodrag ${c}`,style:{width:f,height:f,background:v.bg,color:v.color,transition:"background 0.15s",...d},onMouseEnter:N=>N.currentTarget.style.background=v.hoverBg,onMouseLeave:N=>N.currentTarget.style.background=v.bg,...m,children:a})});function Ht({children:o,variant:a="default",onRemove:t,className:n=""}){const s=E(),c={default:{bg:`${s.textSecondary}15`,color:s.textSecondary},success:{bg:`${s.statusSuccess}15`,color:s.statusSuccess},error:{bg:`${s.statusError}15`,color:s.statusError},warning:{bg:`${s.statusWarning}15`,color:s.statusWarning},info:{bg:`${s.statusInfo}15`,color:s.statusInfo}}[a];return e.jsxs("div",{className:`inline-flex items-center gap-1 px-2 py-1 rounded-md text-[14px] nodrag ${n}`,style:{background:c.bg,color:c.color,fontFamily:"'Geist Mono', monospace",fontSize:12,fontWeight:500},children:[e.jsx("span",{children:o}),t&&e.jsx("button",{type:"button",onClick:t,className:"p-0 border-none bg-transparent cursor-pointer hover:opacity-70 nodrag",style:{color:c.color},"aria-label":"Remove",children:e.jsx(oe,{size:10})})]})}function Yt({type:o}){const a={major:"#FE5000",minor:"#3498db",patch:"#888"};return e.jsx(yt,{size:6,fill:a[o],stroke:"none"})}function Kt({v:o,isCurrent:a,onRestore:t,onDelete:n}){const s=E(),[l,c]=g.useState(!1);return e.jsxs("div",{className:"rounded-lg overflow-hidden",style:{border:`1px solid ${a?"#FE500040":s.borderSubtle}`,background:a?"#FE500008":"transparent"},children:[e.jsxs("button",{type:"button",onClick:()=>c(!l),className:"w-full min-h-[36px] flex items-center gap-2 px-3 py-2 cursor-pointer border-none bg-transparent text-left",children:[e.jsx(Ye,{size:10,style:{color:s.textDim,transform:l?"rotate(90deg)":"none",transition:"transform 0.15s"}}),e.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2",children:[e.jsxs("span",{className:"text-[14px] font-bold shrink-0",style:{fontFamily:"'Geist Mono', monospace",color:a?"#FE5000":s.textPrimary},children:["v",o.version]}),e.jsx("span",{className:"text-[12px] truncate",style:{color:s.textMuted},children:o.label||"Checkpoint"})]}),a&&e.jsx(ut,{variant:"success",size:"sm",dot:!0,children:"CURRENT"}),e.jsx("span",{className:"text-[13px] shrink-0",style:{color:s.textFaint},children:new Date(o.timestamp).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})})]}),l&&e.jsxs("div",{className:"px-3 pb-2 flex flex-col gap-1.5",children:[o.changes.length===0&&e.jsx("div",{className:"text-[12px]",style:{color:s.textMuted},children:"No changelog entries recorded for this version."}),o.changes.map((d,m)=>e.jsxs("div",{className:"flex items-center gap-2 text-[12px]",style:{color:s.textSecondary},children:[e.jsx(Yt,{type:d.type}),e.jsx("span",{className:"uppercase text-[12px] font-semibold w-14 shrink-0",style:{color:s.textDim},children:d.category}),e.jsx("span",{children:d.description})]},m)),e.jsxs("div",{className:"flex items-center gap-1 mt-1",children:[!a&&e.jsx(de,{variant:"secondary",size:"sm",icon:e.jsx(gt,{size:10}),onClick:t,children:"Restore"}),e.jsx(Ut,{icon:e.jsx(Ke,{size:11}),variant:"danger",size:"sm",tooltip:"Delete version",onClick:n})]})]})]})}function _t(){const o=E(),a=B(d=>d.versions),t=B(d=>d.currentVersion),n=B(d=>d.dirty),s=B(d=>d.checkpoint),[l,c]=g.useState(!1);return e.jsxs(e.Fragment,{children:[e.jsxs("button",{type:"button",onClick:()=>c(!0),className:"flex items-center gap-1.5 px-2 h-8 rounded-lg cursor-pointer border-none",style:{background:n?"#FE500015":"transparent",color:n?"#FE5000":o.textDim,fontFamily:"'Geist Mono', monospace",fontSize:12,fontWeight:600,transition:"background 0.15s"},title:"Version history",children:[e.jsx(Ie,{size:12}),"v",t,n&&e.jsx("span",{className:"w-1.5 h-1.5 rounded-full bg-[#FE5000] animate-pulse"})]}),e.jsx(mt,{open:l,onClose:()=>c(!1),title:"Version History",width:480,footer:e.jsx(de,{variant:"primary",size:"sm",icon:e.jsx(He,{size:10}),onClick:()=>{s()},children:"Save Checkpoint"}),children:e.jsxs("div",{className:"flex flex-col gap-1.5 p-3 max-h-[60vh] overflow-y-auto overscroll-contain pr-1",children:[a.length===0&&e.jsxs("div",{className:"py-8 text-center",children:[e.jsx(Ie,{size:20,style:{margin:"0 auto 8px",color:o.textFaint,opacity:.3}}),e.jsx("div",{className:"text-[12px]",style:{color:o.textFaint},children:"No versions yet"}),e.jsx("div",{className:"text-[12px] mt-1",style:{color:o.textMuted},children:"Make changes to your agent — versions are created automatically"})]}),[...a].reverse().map(d=>e.jsx(Kt,{v:d,isCurrent:d.version===t,onRestore:()=>{B.getState().restoreVersion(d.version),c(!1)},onDelete:()=>B.getState().deleteVersion(d.id)},d.id))]})})]})}const qe=[{id:"bot",icon:Ce},{id:"brain",icon:bt},{id:"zap",icon:_e},{id:"flame",icon:vt},{id:"lightbulb",icon:Se},{id:"target",icon:Fe},{id:"rocket",icon:jt},{id:"shield",icon:Te},{id:"microscope",icon:kt},{id:"chart",icon:wt},{id:"palette",icon:St},{id:"file",icon:Nt},{id:"drama",icon:Ct},{id:"star",icon:Ft},{id:"gem",icon:Tt},{id:"bird",icon:Mt},{id:"bug",icon:Et},{id:"cat",icon:$t},{id:"dog",icon:At},{id:"heart",icon:Dt}];function Le({avatarId:o,size:a=20,color:t}){const n=E(),s=qe.find(c=>c.id===o)?.icon??Ce,l=t||n.textPrimary;return e.jsx(s,{size:a,color:l})}function Jt({agentMeta:o,setAgentMeta:a,collapsed:t,onToggle:n}){const s=E(),[l,c]=g.useState(!1),[d,m]=g.useState(""),y={display:"flex",alignItems:"center",justifyContent:"center",width:"80px",height:"80px",borderRadius:"8px",border:"2px dashed var(--border)",background:"var(--surface-elevated)",cursor:"pointer"},r={position:"absolute",top:"96px",left:0,background:s.surfaceElevated,border:`1px solid ${s.border}`,borderRadius:"8px",padding:"12px",display:"grid",gridTemplateColumns:"repeat(4, 1fr)",gap:"8px",zIndex:1e3,boxShadow:"0 4px 12px rgba(0, 0, 0, 0.15)"},f={display:"inline-flex",alignItems:"center",padding:"4px 8px",background:s.badgeBg,color:s.textSecondary,borderRadius:"12px",fontSize:"12px",fontFamily:"'Geist Sans', sans-serif"},k=h=>{h&&!o.tags.includes(h)&&a({tags:[...o.tags,h]})},v=h=>{a({tags:o.tags.filter(p=>p!==h)})},N=h=>{h.key==="Enter"&&d.trim()&&(k(d.trim()),m(""))};return e.jsxs(W,{icon:Je,label:"Identity",color:"#2393f1",collapsed:t,onToggle:n,children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"md:col-span-2 space-y-4",children:[e.jsx(K,{label:"Agent Name",value:o.name,onChange:h=>a({name:h.target.value}),placeholder:"Enter agent name..."}),e.jsx(se,{label:"Description",value:o.description,onChange:h=>a({description:h.target.value}),placeholder:"Describe what this agent does...",rows:3}),e.jsx(K,{label:"Category",value:o.category,onChange:h=>a({category:h.target.value}),placeholder:"e.g., productivity, development, research..."})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("label",{className:"block text-sm font-medium",style:{color:s.textPrimary},children:"Avatar"}),e.jsxs("div",{className:"relative",children:[e.jsx("button",{type:"button",onClick:()=>c(!l),"aria-label":`Select agent avatar (currently ${o.avatar||"default"})`,title:"Choose avatar","aria-expanded":l,"aria-haspopup":"menu",style:y,children:e.jsx(Le,{avatarId:o.avatar,size:48})}),l&&e.jsx("div",{style:r,children:qe.map(h=>e.jsx("button",{type:"button",onClick:()=>{a({avatar:h.id}),c(!1)},"aria-label":`Select avatar ${h.id} as agent avatar`,title:`Select ${h.id} avatar`,className:"flex items-center justify-center w-12 h-12 rounded-lg cursor-pointer border-none",style:{background:o.avatar===h.id?"#FE500020":"transparent",border:`1px solid ${o.avatar===h.id?"#FE5000":"transparent"}`},children:e.jsx(Le,{avatarId:h.id,size:24})},h.id))})]})]})]}),e.jsxs("div",{className:"mt-4 space-y-3",children:[e.jsx("label",{className:"block text-sm font-medium",style:{color:s.textPrimary},children:"Tags"}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[o.tags.map(h=>e.jsxs("span",{style:f,children:[h,e.jsx("button",{type:"button",onClick:()=>v(h),title:`Remove ${h} tag`,className:"border-none bg-transparent cursor-pointer p-0 ml-1",style:{color:"#FE5000"},children:"×"})]},h)),e.jsx(K,{value:d,onChange:h=>m(h.target.value),onKeyDown:N,placeholder:"Add tag...",className:"w-24",style:{minWidth:"100px"}})]})]})]})}const Vt="#27ae60",Xt="#FE5000";function pe({onRefine:o}){const a=E(),[t,n]=g.useState(!1),[s,l]=g.useState(null),[c,d]=g.useState(!1),m=async()=>{l(null),d(!1),n(!0);try{await o(),d(!0),setTimeout(()=>d(!1),2e3)}catch(k){const v=k instanceof Error?k.message:"Refinement failed";l(v),setTimeout(()=>l(null),4e3)}finally{n(!1)}},y=s?a.statusError:c?Vt:Xt,r={background:"transparent",border:`1px solid ${y}`,color:y,borderRadius:6,padding:"2px 8px",fontSize:11,fontFamily:"'Geist Mono', monospace",fontWeight:600,letterSpacing:"0.05em",textTransform:"uppercase",cursor:t?"not-allowed":"pointer",display:"flex",alignItems:"center",gap:4,transition:"all 0.15s"},f=c?"Done":t?"Refining…":"Refine";return e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:m,disabled:t,title:"Refine with AI",style:r,children:[t?e.jsx("span",{className:"animate-spin",children:"⟳"}):e.jsx("span",{children:"✨"}),f]}),s&&e.jsx("span",{style:{color:a.statusError,fontSize:11,fontFamily:"'Geist Mono', monospace"},children:s})]})}const qt=`You are an expert prompt engineer. Your job is to take a user's rough brain dump about an AI agent they want to build, and transform it into structured, high-quality agent instructions following Anthropic's prompting best practices.
|
|
2
|
+
|
|
3
|
+
Given the user's rough input, produce a JSON response with this exact structure:
|
|
4
|
+
{
|
|
5
|
+
"persona": "<2-4 sentence persona description. Be specific about expertise, domain, and communication style. Use 'You are...' framing>",
|
|
6
|
+
"tone": "<one of: formal, neutral, casual>",
|
|
7
|
+
"expertise": <1-5 number, where 1=beginner-friendly and 5=expert-level>,
|
|
8
|
+
"constraints": [
|
|
9
|
+
"<clear, actionable constraint in imperative voice>"
|
|
10
|
+
],
|
|
11
|
+
"scopeDefinition": "<one sentence: what the agent handles and what it does NOT handle>",
|
|
12
|
+
"objectives": {
|
|
13
|
+
"primary": "<one clear sentence describing the agent's primary goal>",
|
|
14
|
+
"successCriteria": ["<measurable criterion>"],
|
|
15
|
+
"failureModes": ["<specific failure to avoid>"]
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
Follow these rules:
|
|
20
|
+
1. Be specific - replace vague descriptions with concrete, actionable language
|
|
21
|
+
2. Use XML-tag-friendly language (the output will be assembled into a system prompt)
|
|
22
|
+
3. Infer reasonable constraints from the domain (e.g., a medical agent should cite sources)
|
|
23
|
+
4. Generate 2-4 success criteria and 2-3 failure modes based on the domain
|
|
24
|
+
5. Keep the persona concise but distinctive - give it a clear identity
|
|
25
|
+
6. If the input mentions tools, APIs, or specific capabilities, reference them in constraints
|
|
26
|
+
7. Think step by step about what makes an excellent agent for this use case before writing
|
|
27
|
+
|
|
28
|
+
Output ONLY the JSON object. No markdown fences, no explanation.`,Zt={persona:'You are an expert prompt engineer. Transform this rough persona description into a clear, specific 2-4 sentence persona. Use "You are..." framing. Be concrete about expertise, domain knowledge, and communication style. Output ONLY the refined persona text.',constraints:"You are an expert prompt engineer. Transform these rough constraint notes into clear, actionable rules - one per line, imperative voice. Remove redundancy, sharpen vague rules, infer reasonable additions from the domain. Output ONLY the constraints, one per line.",scope:"You are an expert prompt engineer. Transform this rough scope description into a clear one-sentence definition of what the agent handles and what it does NOT handle. Output ONLY the scope sentence."};async function ue(o,a){if(!a.trim())throw new Error("Nothing to refine");const t=V.getState(),n=t.providers.filter(f=>f.models&&f.models.length>0),s=t.providers.find(f=>f.id===t.selectedProviderId&&n.includes(f))||n[0];if(!s)throw new Error("No provider configured — add one in Settings");const l=typeof s.models?.[0]=="object"?s.models[0].id:s.models?.[0]||"claude-sonnet-4-20250514",c=o==="full"?qt:Zt[o];if(!c)throw new Error(`Unknown field: ${o}`);const m=s.authMethod==="claude-agent-sdk"?await Ge({prompt:a,model:l,systemPrompt:c,maxTurns:1}):await We({providerId:s.id,model:l,messages:[{role:"system",content:c},{role:"user",content:a}],temperature:.3,maxTokens:1024});if(o!=="full")return m;try{return JSON.parse(m)}catch{}const y=m.match(/```(?:json)?\s*([\s\S]*?)```/);if(y)try{return JSON.parse(y[1].trim())}catch{}const r=m.match(/\{[\s\S]*\}/);if(r)try{return JSON.parse(r[0])}catch{}throw new Error("Could not parse agent structure from LLM response")}function Qt({persona:o,tone:a,expertise:t,updateInstruction:n,collapsed:s,onToggle:l}){const c=E(),d=async()=>{const m=await ue("persona",o);typeof m=="string"&&n({persona:m})};return e.jsx(W,{icon:Ce,label:"Persona",color:"#897bf0",collapsed:s,onToggle:l,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(se,{label:"Persona Description",labelAction:e.jsx(pe,{onRefine:d}),value:o,onChange:m=>n({persona:m.target.value}),placeholder:"Describe the agent's personality, communication style, and approach...",rows:4}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(we,{label:"Tone",options:[{value:"formal",label:"Formal"},{value:"neutral",label:"Neutral"},{value:"casual",label:"Casual"}],value:a,onChange:m=>n({tone:m})}),e.jsxs("div",{children:[e.jsxs("label",{className:"block text-sm font-medium mb-2",style:{color:c.textPrimary},children:["Expertise Level: ",t,"/5"]}),e.jsx("input",{type:"range",min:"1",max:"5",step:"1",value:t,onChange:m=>n({expertise:Number(m.target.value)}),className:"w-full",style:{accentColor:"#FE5000"}}),e.jsxs("div",{className:"flex justify-between text-xs mt-1",style:{color:c.textDim},children:[e.jsx("span",{children:"Beginner"}),e.jsx("span",{children:"Expert"})]})]})]})]})})}function es({constraints:o,onAdd:a,onRemove:t}){const[n,s]=g.useState(""),l=c=>{c.key==="Enter"&&n.trim()&&(a(n.trim()),s(""))};return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"flex flex-wrap gap-2",children:o.map(c=>e.jsx(Ht,{onRemove:()=>t(c),children:c},c))}),e.jsx(K,{value:n,onChange:c=>s(c.target.value),onKeyDown:l,placeholder:"Type constraint and press Enter..."})]})}function ts({constraints:o,updateInstruction:a,customConstraints:t,addCustomConstraint:n,removeCustomConstraint:s,collapsed:l,onToggle:c}){const d=E(),m=async()=>{const r=await ue("constraints",o.customConstraints);typeof r=="string"&&a({constraints:{...o,customConstraints:r}})},y=async()=>{const r=await ue("scope",o.scopeDefinition);typeof r=="string"&&a({constraints:{...o,scopeDefinition:r}})};return e.jsx(W,{icon:Te,label:"Constraints & Safety",color:"#e45c5e",collapsed:l,onToggle:c,children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx(te,{checked:o.neverMakeUp,onChange:r=>a({constraints:{...o,neverMakeUp:r}}),label:"Never fabricate information"}),e.jsx(te,{checked:o.askBeforeActions,onChange:r=>a({constraints:{...o,askBeforeActions:r}}),label:"Ask before taking actions"}),e.jsx(te,{checked:o.stayInScope,onChange:r=>a({constraints:{...o,stayInScope:r}}),label:"Stay within defined scope"}),e.jsx(te,{checked:o.useOnlyTools,onChange:r=>a({constraints:{...o,useOnlyTools:r}}),label:"Use only provided tools"})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(te,{checked:o.limitWords,onChange:r=>a({constraints:{...o,limitWords:r}}),label:"Limit response length"}),o.limitWords&&e.jsx(K,{type:"number",value:o.wordLimit.toString(),onChange:r=>a({constraints:{...o,wordLimit:Number(r.target.value)||0}}),placeholder:"Word limit",className:"w-24"})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-2",style:{color:d.textPrimary},children:"Custom Constraints"}),e.jsx(es,{constraints:t,onAdd:n,onRemove:s})]}),e.jsx(se,{label:"Scope Definition",labelAction:e.jsx(pe,{onRefine:y}),value:o.scopeDefinition,onChange:r=>a({constraints:{...o,scopeDefinition:r.target.value}}),placeholder:"Define the specific scope and boundaries for this agent...",rows:2}),e.jsx(se,{label:"Additional Notes",labelAction:e.jsx(pe,{onRefine:m}),value:o.customConstraints,onChange:r=>a({constraints:{...o,customConstraints:r.target.value}}),placeholder:"Add any additional constraints or rules (one per line)...",rows:3})]})})}function ss({objectives:o,updateInstruction:a,collapsed:t,onToggle:n}){const s=E(),[l,c]=g.useState(""),[d,m]=g.useState(""),y=()=>{if(l.trim()){const p=[...o.successCriteria,l.trim()];a({objectives:{...o,successCriteria:p}}),c("")}},r=p=>{const $=o.successCriteria.filter((z,D)=>D!==p);a({objectives:{...o,successCriteria:$}})},f=()=>{if(d.trim()){const p=[...o.failureModes,d.trim()];a({objectives:{...o,failureModes:p}}),m("")}},k=p=>{const $=o.failureModes.filter((z,D)=>D!==p);a({objectives:{...o,failureModes:$}})},v=p=>{p.key==="Enter"&&(p.preventDefault(),y())},N=p=>{p.key==="Enter"&&(p.preventDefault(),f())},h=async()=>{const p=await ue("scope",o.primary);typeof p=="string"&&a({objectives:{...o,primary:p}})};return e.jsx(W,{icon:Fe,label:"Objectives & Success Criteria",color:"#2caa4e",collapsed:t,onToggle:n,children:e.jsxs("div",{className:"space-y-6",children:[e.jsx(se,{label:"Primary Objective",labelAction:e.jsx(pe,{onRefine:h}),value:o.primary,onChange:p=>a({objectives:{...o,primary:p.target.value}}),placeholder:"What is the main goal this agent should achieve?",rows:2}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-2",style:{color:s.textPrimary},children:"Success Criteria"}),e.jsxs("div",{className:"space-y-2",children:[o.successCriteria.map((p,$)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 px-3 py-2 rounded-md text-sm",style:{background:s.surfaceElevated,border:`1px solid ${s.border}`,color:s.textPrimary},children:p}),e.jsx("button",{type:"button",onClick:()=>r($),className:"flex items-center justify-center w-8 h-8 rounded-md border-none cursor-pointer",style:{background:"transparent",color:s.textMuted},"aria-label":"Remove success criterion",title:"Remove criterion",children:e.jsx(oe,{size:14})})]},$)),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(K,{value:l,onChange:p=>c(p.target.value),onKeyDown:v,placeholder:"Add a success criterion...",className:"flex-1"}),e.jsxs(de,{onClick:y,variant:"secondary",size:"sm",disabled:!l.trim(),title:"Add success criterion",className:"flex items-center gap-1",children:[e.jsx(Oe,{size:14}),"Add"]})]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium mb-2",style:{color:s.textPrimary},children:"Failure Modes"}),e.jsxs("div",{className:"space-y-2",children:[o.failureModes.map((p,$)=>e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"flex-1 px-3 py-2 rounded-md text-sm",style:{background:s.surfaceElevated,border:`1px solid ${s.border}`,color:s.textPrimary},children:p}),e.jsx("button",{type:"button",onClick:()=>k($),className:"flex items-center justify-center w-8 h-8 rounded-md border-none cursor-pointer",style:{background:"transparent",color:s.textMuted},"aria-label":"Remove failure mode",title:"Remove failure mode",children:e.jsx(oe,{size:14})})]},$)),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(K,{value:d,onChange:p=>m(p.target.value),onKeyDown:N,placeholder:"Add a potential failure mode...",className:"flex-1"}),e.jsxs(de,{onClick:f,variant:"secondary",size:"sm",disabled:!d.trim(),title:"Add failure mode",className:"flex items-center gap-1",children:[e.jsx(Oe,{size:14}),"Add"]})]})]})]})]})})}function os({workflowSteps:o,collapsed:a,onToggle:t}){const n=E();return e.jsx(W,{icon:Ve,label:"Workflow Steps",color:"#d96e00",collapsed:a,onToggle:t,children:o.length===0?e.jsx("div",{className:"text-center py-8 text-sm",style:{color:n.textDim},children:"No workflow steps defined. The agent will operate without a structured workflow."}):e.jsx("div",{className:"space-y-2",children:o.map((s,l)=>e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded",style:{background:n.surfaceElevated},children:[e.jsx("span",{className:"flex items-center justify-center w-6 h-6 rounded-full text-xs font-bold",style:{background:"#d96e00",color:"white"},children:l+1}),e.jsx("span",{className:"flex-1 text-sm",style:{color:n.textPrimary},children:s.label}),e.jsx("span",{className:"text-xs px-2 py-1 rounded",style:{background:n.badgeBg,color:n.textDim},children:s.action})]},l))})})}function ns({outputFormat:o,setOutputFormat:a,selectedModel:t,tokenBudget:n,collapsed:s,onToggle:l}){const c=E(),d=V(r=>r.getAllModels),m=V(r=>r.providers),y=g.useMemo(()=>d().map(r=>({value:`${r.providerId}::${r.id}`,label:`${r.providerName} / ${r.label}`})),[d,m]);return e.jsx(W,{icon:Pt,label:"Output Configuration",color:"#b28a00",collapsed:s,onToggle:l,children:e.jsxs("div",{className:"space-y-4",children:[e.jsx(we,{label:"Output Format",options:at.map(r=>({value:r.id,label:r.label})),value:o,onChange:r=>a(r)}),e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsx("div",{children:e.jsx(we,{label:"Model",options:y,value:t,onChange:r=>j.getState().setModel(r)})}),e.jsxs("div",{children:[e.jsx("span",{className:"block text-sm font-medium mb-2",style:{color:c.textPrimary},children:"Token Budget"}),e.jsx("div",{className:"p-2 rounded",style:{background:c.surfaceElevated,color:c.textSecondary},children:n?.toLocaleString()||"Default"})]})]})]})})}function as({onExport:o,onExportFormat:a,onPromptPreview:t,saveStatus:n}){const s=E(),[l,c]=g.useState(!1),d={display:"flex",alignItems:"center",gap:"8px",padding:"10px 16px",background:"#FE5000",color:"white",border:"none",borderRadius:"6px",fontSize:"14px",fontWeight:"500",fontFamily:"'Geist Sans', sans-serif",cursor:"pointer",transition:"all 0.15s ease"},m={display:"flex",alignItems:"center",gap:"8px",padding:"10px 16px",background:"transparent",color:s.textSecondary,border:`1px solid ${s.border}`,borderRadius:"6px",fontSize:"14px",fontWeight:"500",fontFamily:"'Geist Sans', sans-serif",cursor:"pointer",transition:"all 0.15s ease"},y={position:"absolute",top:"100%",left:0,right:0,background:s.surfaceElevated,border:`1px solid ${s.border}`,borderRadius:"6px",marginTop:"4px",zIndex:1e3,boxShadow:"0 4px 12px rgba(0, 0, 0, 0.15)"},r=g.useCallback(f=>{a(f),c(!1)},[a]);return e.jsxs("div",{className:"flex flex-wrap items-center gap-3",children:[e.jsxs("button",{type:"button",onClick:t,className:"flex items-center gap-2 px-4 py-2 text-sm rounded border",style:{background:"transparent",color:s.textSecondary,borderColor:s.border,fontFamily:"'Geist Sans', sans-serif"},children:[e.jsx(Rt,{size:14}),"Prompt Preview"]}),e.jsxs("div",{className:"relative",children:[e.jsxs("button",{type:"button",onClick:()=>c(!l),"aria-expanded":l,"aria-haspopup":"menu","aria-label":"Export agent configuration in different formats",style:d,children:[e.jsx(ze,{size:14}),"Export",e.jsx(Xe,{size:12})]}),l&&e.jsx("div",{role:"menu",style:y,children:["JSON","YAML","Markdown","Claude format","OpenAI format"].map(f=>e.jsx("button",{type:"button",role:"menuitem",onClick:()=>r(f),"aria-label":`Export agent configuration as ${f}`,className:"w-full px-4 py-2 text-left text-sm hover:bg-gray-100",style:{background:"transparent",border:"none",color:s.textPrimary,cursor:"pointer"},children:f},f))})]}),e.jsxs("button",{type:"button",onClick:o,style:d,children:[e.jsx(ze,{size:16}),"Export Agent"]}),e.jsxs("button",{type:"button",disabled:n==="saving",onClick:()=>{const f=B.getState();if(!f.agentId){const k=`agent-${Date.now()}`;f.setAgentId(k)}f.saveToServer("Manual save")},style:{...m,opacity:n==="saving"?.6:1,cursor:n==="saving"?"not-allowed":"pointer"},children:[e.jsx(He,{size:16}),n==="saving"?"Saving...":"Save Draft"]}),e.jsxs("div",{className:"flex items-center gap-2 text-sm",children:[e.jsx("div",{className:"w-2 h-2 rounded-full",style:{background:n==="saved"?"#22c55e":n==="saving"?"#f59e0b":n==="error"?"#ef4444":"#6b7280"}}),e.jsx("span",{style:{color:s.textSecondary,fontSize:"13px"},children:n==="saved"?"Saved":n==="saving"?"Saving...":n==="error"?"Save failed":"Unsaved changes"})]})]})}function rs(o){const a=j.getState(),t=[a.agentMeta.name&&`Agent: ${a.agentMeta.name}`,a.agentMeta.description&&`Description: ${a.agentMeta.description}`,a.instructionState.persona&&`Persona: ${a.instructionState.persona.slice(0,200)}`,a.instructionState.objectives.primary&&`Objective: ${a.instructionState.objectives.primary}`,a.instructionState.constraints.customConstraints&&`Constraints: ${a.instructionState.constraints.customConstraints.slice(0,200)}`,a.workflowSteps.length>0&&`Workflow: ${a.workflowSteps.map(s=>s.label).join(" → ")}`,a.channels.filter(s=>s.enabled).length>0&&`Knowledge: ${a.channels.filter(s=>s.enabled).map(s=>s.name).join(", ")}`,a.mcpServers.filter(s=>s.enabled!==!1).length>0&&`MCP: ${a.mcpServers.filter(s=>s.enabled!==!1).map(s=>s.name).join(", ")}`,a.skills.filter(s=>s.enabled!==!1).length>0&&`Skills: ${a.skills.filter(s=>s.enabled!==!1).map(s=>s.name).join(", ")}`].filter(Boolean).join(`
|
|
29
|
+
`),n=o.map((s,l)=>`${l+1}. [${s.id}] "${s.content}" (type: ${s.type}, tags: ${s.tags.join(",")})`).join(`
|
|
30
|
+
`);return`You are an expert agent architect analyzing runtime memory facts to improve an agent's design.
|
|
31
|
+
|
|
32
|
+
<agent_context>
|
|
33
|
+
${t}
|
|
34
|
+
</agent_context>
|
|
35
|
+
|
|
36
|
+
<facts>
|
|
37
|
+
${n}
|
|
38
|
+
</facts>
|
|
39
|
+
|
|
40
|
+
Analyze each fact and determine if it should be PROMOTED from runtime memory into a structured agent component. Facts that encode persistent patterns, preferences, or capabilities should graduate into the agent's design.
|
|
41
|
+
|
|
42
|
+
Promotion targets:
|
|
43
|
+
- "instruction": Fact describes HOW the agent should behave → append to persona or instructions
|
|
44
|
+
- "constraint": Fact is a rule or limitation → add as a constraint
|
|
45
|
+
- "workflow": Fact describes a recurring process → add as a workflow step
|
|
46
|
+
- "knowledge": Fact points to a data source the agent needs → add as knowledge source
|
|
47
|
+
- "mcp": Fact mentions a tool/API the agent should use → suggest MCP server
|
|
48
|
+
- "skill": Fact describes a capability the agent needs → suggest a skill
|
|
49
|
+
- "keep": Fact is volatile/contextual → keep in runtime memory
|
|
50
|
+
|
|
51
|
+
Output ONLY valid JSON:
|
|
52
|
+
{
|
|
53
|
+
"promotions": [
|
|
54
|
+
{
|
|
55
|
+
"factId": "<id from facts list>",
|
|
56
|
+
"factContent": "<the fact text>",
|
|
57
|
+
"target": "<promotion target>",
|
|
58
|
+
"confidence": <0.0-1.0>,
|
|
59
|
+
"suggestion": "<human-readable suggestion>",
|
|
60
|
+
"reason": "<why this promotion improves the agent>",
|
|
61
|
+
"payload": {
|
|
62
|
+
"constraintText": "<if target=constraint>",
|
|
63
|
+
"workflowStep": { "label": "<step name>", "action": "<what to do>" },
|
|
64
|
+
"knowledgeSource": { "name": "<source name>", "type": "<ground-truth|signal|evidence|framework>" },
|
|
65
|
+
"mcpServerId": "<id from MCP registry if target=mcp>",
|
|
66
|
+
"skillId": "<skill id if target=skill>",
|
|
67
|
+
"instructionAppend": "<text to append to persona if target=instruction>"
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
],
|
|
71
|
+
"summary": "<one sentence summary of recommended changes>",
|
|
72
|
+
"versionImpact": "<major|minor|patch|none>"
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
Rules:
|
|
76
|
+
- Only promote facts with confidence >= 0.6
|
|
77
|
+
- Facts that are temporary/contextual should stay as "keep"
|
|
78
|
+
- Prefer fewer high-confidence promotions over many low-confidence ones
|
|
79
|
+
- Include payload fields ONLY for the relevant target (omit others)
|
|
80
|
+
- versionImpact: major if persona/objective changes, minor if adding knowledge/tools/steps, patch if constraints only`}async function is(o){const a=V.getState(),t=a.providers.filter(l=>l.models&&l.models.length>0),n=a.providers.find(l=>l.id===a.selectedProviderId&&t.includes(l))||t[0];if(!n)throw new Error("No provider configured — add one in Settings");const s=typeof n.models?.[0]=="object"?n.models[0].id:n.models?.[0]||"claude-sonnet-4-20250514";return n.authMethod==="claude-agent-sdk"?Ge({prompt:o,model:s,maxTurns:1}):We({providerId:n.id,model:s,messages:[{role:"user",content:o}],temperature:.3,maxTokens:4096})}function ls(o){try{return JSON.parse(o)}catch{}const a=o.match(/```(?:json)?\s*([\s\S]*?)```/);if(a)try{return JSON.parse(a[1].trim())}catch{}const t=o.match(/\{[\s\S]*\}/);if(t)try{return JSON.parse(t[0])}catch{}throw new Error("Could not parse analysis response")}async function cs(o){if(o.length===0)return{promotions:[],summary:"No facts to analyze",versionImpact:"none"};const a=rs(o),t=await is(a),n=ls(t);return n.promotions=n.promotions.filter(s=>s.confidence>=.6&&s.target!=="keep").sort((s,l)=>l.confidence-s.confidence),n}function ds({collapsed:o,onToggle:a}){const t=E(),n=ke(b=>b.facts),s=ke(b=>b.removeFact),l=j(b=>b.updateInstruction),c=j(b=>b.instructionState),d=j(b=>b.addWorkflowStep),m=j(b=>b.addChannel),y=B(b=>b.checkpoint),[r,f]=g.useState(!1),[k,v]=g.useState(null),[N,h]=g.useState(new Set),[p,$]=g.useState(""),z=g.useCallback(async()=>{if(n.length!==0){f(!0),$(""),h(new Set);try{const b=await cs(n);v(b)}catch(b){$(b instanceof Error?b.message:"Analysis failed")}f(!1)}},[n]),D=g.useCallback(b=>{const C=b.payload;switch(b.target){case"instruction":if(C.instructionAppend){const G=c.persona;l({persona:G?`${G}
|
|
81
|
+
|
|
82
|
+
${C.instructionAppend}`:C.instructionAppend})}break;case"constraint":if(C.constraintText){const G=c.constraints.customConstraints;l({constraints:{...c.constraints,customConstraints:G?`${G}
|
|
83
|
+
${C.constraintText}`:C.constraintText}})}break;case"workflow":C.workflowStep&&d({label:C.workflowStep.label,action:C.workflowStep.action,tool:"",condition:"always"});break;case"knowledge":C.knowledgeSource&&m({sourceId:`promoted-${crypto.randomUUID().slice(0,8)}`,name:C.knowledgeSource.name,path:"",category:"knowledge",knowledgeType:C.knowledgeSource.type,depth:0,baseTokens:500});break}h(G=>new Set([...G,b.factId])),s(b.factId)},[c,l,d,m,s]),u=g.useCallback(()=>{if(k){for(const b of k.promotions)N.has(b.factId)||D(b);y("Facts promoted to agent design")}},[k,N,D,y]);if(n.length===0&&!k)return null;const S=k?k.promotions.filter(b=>!N.has(b.factId)).length:0,M=k&&S>0?`${S} suggestion${S!==1?"s":""}`:`${n.length} facts`;return e.jsx(W,{icon:Se,label:"Fact Insights",color:"#00ae9b",badge:M,collapsed:o,onToggle:a,children:e.jsxs("div",{className:"space-y-3",children:[!k&&n.length>0&&e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsx("div",{className:"text-[12px] leading-relaxed",style:{color:t.textDim},children:"Analyze accumulated facts to discover which should become permanent parts of your agent — instructions, constraints, workflow steps, or knowledge sources."}),e.jsxs("button",{type:"button",onClick:z,disabled:r||n.length===0,title:r?"Analyzing facts":"Analyze for promotions",className:"flex items-center justify-center gap-1.5 w-full px-3 py-2.5 rounded text-[13px] tracking-wide uppercase cursor-pointer border-none",style:{background:r?"#CC4000":"#FE5000",color:"#fff",fontFamily:"'Geist Mono', monospace",opacity:r||n.length===0?.6:1},children:[r?e.jsx(It,{size:11,className:"animate-spin"}):e.jsx(Se,{size:11}),r?"Analyzing...":`Analyze ${n.length} fact${n.length!==1?"s":""}`]})]}),p&&e.jsx("div",{className:"text-xs text-red-500 p-2 rounded",style:{background:"#fee2e2"},children:p}),k&&S>0&&e.jsxs("button",{type:"button",onClick:u,title:"Apply all suggestions",className:"flex items-center justify-center gap-1.5 w-full px-3 py-2 rounded text-[12px] tracking-wide uppercase cursor-pointer border-none",style:{background:"#2ecc7120",color:"#2ecc71",fontFamily:"'Geist Mono', monospace"},children:["Apply all ",S," suggestions"]}),k&&S===0&&e.jsx("div",{className:"text-xs text-green-600 p-2 rounded",style:{background:"#f0fdf4"},children:"✅ All insights applied to your agent configuration."})]})})}function ps(o){const a=Date.now()-new Date(o).getTime(),t=Math.floor(a/6e4);if(t<2)return"just now";if(t<60)return`${t}m ago`;const n=Math.floor(t/60);return n<24?`${n}h ago`:`${Math.floor(n/24)}d ago`}function us(o){return o<.5?"#e74c3c":o<.7?"#f39c12":"#2ecc71"}const Be={accuracy:"Accuracy","output-style":"Output Style",safety:"Safety",workflow:"Workflow",general:"General"};function ye({lesson:o,onApprove:a,onReject:t,onRemove:n,onEdit:s,showMeta:l=!1}){const c=E(),[d,m]=g.useState(!1),[y,r]=g.useState(o.rule),f=()=>{y.trim()&&s?.(y.trim()),m(!1)},k={background:c.isDark?"#1c1c20":"#f9fafb",borderRadius:6,padding:"8px 10px"},v=o.confidence,N=us(v),h=Math.round(v*100);return e.jsxs("div",{className:"space-y-1",style:k,children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx("span",{className:"text-xs px-1.5 py-0.5 rounded shrink-0",style:{background:"#FE500015",color:"#FE5000"},children:o.category}),d?e.jsx("input",{className:"flex-1 text-[12px] bg-transparent border-b outline-none",style:{color:c.textPrimary,borderColor:c.border},value:y,onChange:p=>r(p.target.value),onKeyDown:p=>p.key==="Enter"&&f(),autoFocus:!0}):e.jsx("span",{className:"flex-1 text-[12px]",style:{color:c.textPrimary},children:o.rule}),e.jsxs("div",{className:"flex items-center gap-1 shrink-0",children:[a&&e.jsx("button",{type:"button",onClick:a,title:"Approve",className:"border-none bg-transparent cursor-pointer p-1",style:{color:"#2ecc71"},children:e.jsx(Ne,{size:13})}),t&&e.jsx("button",{type:"button",onClick:t,title:"Reject",className:"border-none bg-transparent cursor-pointer p-1",style:{color:c.textDim},children:e.jsx(oe,{size:13})}),s&&!a&&(d?e.jsx("button",{type:"button",onClick:f,title:"Save",className:"border-none bg-transparent cursor-pointer p-1",style:{color:"#2ecc71"},children:e.jsx(Ne,{size:13})}):e.jsx("button",{type:"button",onClick:()=>m(!0),title:"Edit",className:"border-none bg-transparent cursor-pointer p-1",style:{color:c.textDim},children:e.jsx(zt,{size:13})})),n&&e.jsx("button",{type:"button",onClick:n,title:"Remove",className:"border-none bg-transparent cursor-pointer p-1",style:{color:c.textDim},children:e.jsx(Ke,{size:13})})]})]}),l&&e.jsxs("div",{className:"flex items-center gap-3 mt-1",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("div",{style:{width:60,height:4,background:c.isDark?"#2a2a2e":"#e5e7eb",borderRadius:2,overflow:"hidden"},children:e.jsx("div",{style:{width:`${h}%`,height:"100%",background:N,borderRadius:2,transition:"width 0.3s"}})}),e.jsxs("span",{className:"text-[11px] tabular-nums",style:{color:N},children:[h,"%"]})]}),e.jsxs("span",{className:"text-[11px]",style:{color:c.textDim},children:["seen ",o.evidence.length,"×"]}),o.lastSeenAt&&e.jsxs("span",{className:"text-[11px]",style:{color:c.textDim},children:["last: ",ps(o.lastSeenAt)]})]})]})}function ms({collapsed:o,onToggle:a}){const t=E(),n=B(u=>u.agentId)??"",s=Y(u=>u.lessons),l=Y(u=>u.approveLesson),c=Y(u=>u.rejectLesson),d=Y(u=>u.removeLesson),m=Y(u=>u.updateLesson),y=Y(u=>u.archiveLessons),r=j(u=>u.addChannel),[f,k]=g.useState(null),v=s.filter(u=>u.agentId===n&&u.status==="pending"),N=s.filter(u=>u.agentId===n&&u.status==="approved"&&u.confidence>=.5),h=s.filter(u=>u.agentId===n&&u.status==="approved"&&u.confidence<.5),p=N.reduce((u,S)=>{const M=S.domain??"general";return u[M]=u[M]??[],u[M].push(S),u},{}),$=new Set(Object.entries(p).filter(([,u])=>u.length>=2&&u.every(S=>S.confidence>.7)).map(([u])=>u)),z=(u,S)=>{const M=S.map(C=>`- ${C.rule}`).join(`
|
|
84
|
+
`),b=`instinct-${u}-${crypto.randomUUID().slice(0,8)}`;r({sourceId:b,name:`Guideline: ${Be[u]??u}`,path:"",category:"knowledge",knowledgeType:"guideline",depth:80,baseTokens:Math.ceil(M.length/4),content:M}),y(S.map(C=>C.id)),k(`Promoted ${S.length} instinct${S.length!==1?"s":""} to Knowledge`),setTimeout(()=>k(null),3e3)};if(v.length===0&&N.length===0&&h.length===0)return null;const D=v.length>0?`${v.length} pending`:N.length>0?`${N.length} active`:void 0;return e.jsxs(e.Fragment,{children:[f&&e.jsxs("div",{style:{position:"fixed",bottom:24,right:24,zIndex:9999,background:"#2ecc71",color:"#fff",borderRadius:8,padding:"10px 16px",fontSize:13,fontFamily:"'Geist Sans', sans-serif",boxShadow:"0 4px 12px rgba(0,0,0,0.2)"},children:["✓ ",f]}),e.jsx(W,{icon:Ot,label:"Learned Behaviors",color:"#be67cc",badge:D,collapsed:o,onToggle:a,children:e.jsxs("div",{className:"space-y-4",children:[v.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wide m-0",style:{color:t.textDim,fontFamily:"'Geist Mono', monospace"},children:"Pending Review"}),v.map(u=>e.jsx(ye,{lesson:u,onApprove:()=>l(u.id),onReject:()=>c(u.id),showMeta:!0},u.id))]}),Object.keys(p).length>0&&e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wide m-0",style:{color:t.textDim,fontFamily:"'Geist Mono', monospace"},children:"Active"}),Object.entries(p).map(([u,S])=>e.jsxs("div",{className:"space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-[10px] uppercase tracking-widest font-semibold",style:{color:t.textDim,fontFamily:"'Geist Mono', monospace"},children:Be[u]??u}),e.jsx("div",{style:{flex:1,height:1,background:t.border}})]}),S.map(M=>e.jsx(ye,{lesson:M,onEdit:b=>m(M.id,b),onRemove:()=>d(M.id),showMeta:!0},M.id)),$.has(u)&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded text-[11px]",style:{background:"#FE500008",border:"1px dashed #FE500040",color:t.textDim},children:[e.jsx("span",{children:"💡 These could merge into a Knowledge item."}),e.jsx("button",{type:"button",className:"ml-auto text-[11px] font-medium border-none bg-transparent cursor-pointer",style:{color:"#FE5000"},onClick:()=>z(u,S),children:"Promote to Knowledge →"})]})]},u))]}),h.length>0&&e.jsxs("div",{className:"space-y-2",children:[e.jsx("p",{className:"text-[11px] uppercase tracking-wide m-0",style:{color:t.textDim,fontFamily:"'Geist Mono', monospace"},children:"Tentative"}),h.map(u=>{const S=Math.max(1,Math.ceil((.5-u.confidence)/.2));return e.jsxs("div",{className:"space-y-1",children:[e.jsx(ye,{lesson:u,onEdit:M=>m(u.id,M),onRemove:()=>d(u.id),showMeta:!0}),e.jsxs("p",{className:"text-[10px] m-0 ml-1",style:{color:t.textDim,fontFamily:"'Geist Mono', monospace"},children:["Needs ",S," more confirmation",S!==1?"s":""," to activate"]})]},u.id)})]})]})})]})}const be={haiku:"Haiku",sonnet:"Sonnet",opus:"Opus"},le={haiku:"#2ecc71",sonnet:"#3498db",opus:"#9b59b6"};function ve({label:o,value:a,sub:t}){const n=E();return e.jsxs("div",{className:"flex flex-col gap-0.5 px-3 py-2 rounded-lg",style:{background:n.isDark?"#1c1c20":"#f3f4f6",minWidth:0,flex:1},children:[e.jsx("span",{className:"text-[10px] uppercase tracking-wide",style:{color:n.textDim,fontFamily:"'Geist Mono', monospace"},children:o}),e.jsx("span",{className:"text-[15px] font-semibold",style:{color:n.textPrimary,fontFamily:"'Geist Mono', monospace"},children:a}),t&&e.jsx("span",{className:"text-[10px]",style:{color:n.textFaint},children:t})]})}function xs({spent:o,limit:a}){const t=a>0?Math.min(o/a*100,100):0,n=t>=100?"#e74c3c":t>=80?"#f39c12":"#2ecc71";return e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-[11px]",style:{fontFamily:"'Geist Mono', monospace"},children:[e.jsx("span",{style:{color:"#888"},children:"Budget used"}),e.jsxs("span",{style:{color:n},children:["$",o.toFixed(4)," / $",a.toFixed(2)]})]}),e.jsx("div",{style:{height:4,borderRadius:2,background:"#33333330",overflow:"hidden"},children:e.jsx("div",{style:{width:`${t}%`,height:"100%",borderRadius:2,background:n,transition:"width 400ms"}})})]})}function hs({collapsed:o,onToggle:a}){const t=E(),n=B(i=>i.agentId)??"default",s=j(i=>i.channels),l=j(i=>i.mcpServers),c=j(i=>i.connectors),d=j(i=>i.workflowSteps),m=Ue(i=>i.lastPipelineStats),y=V(i=>i.providers),r=V(i=>i.selectedProviderId),[f,k]=g.useState(null),[v,N]=g.useState({budgetLimit:1,totalSpent:0}),[h,p]=g.useState("auto"),[$,z]=g.useState("1.00"),[D,u]=g.useState(!1),[S,M]=g.useState([]),b=n||"default";g.useEffect(()=>{Promise.all([fetch(`${ie}/cost/${encodeURIComponent(b)}/summary`).then(i=>i.ok?i.json():null),fetch(`${ie}/cost/${encodeURIComponent(b)}/budget`).then(i=>i.ok?i.json():null)]).then(([i,P])=>{if(i?.data&&k(i.data),P?.data){const R=P.data;N(R),z(R.budgetLimit.toFixed(2)),R.preferredModel&&p(R.preferredModel)}}).catch(()=>{})},[b,m]),g.useEffect(()=>{D&&fetch(`${ie}/cost/${encodeURIComponent(b)}/history?limit=20`).then(i=>i.ok?i.json():null).then(i=>{i?.data&&M(i.data)}).catch(()=>{})},[D,b]);const C=m?.totalContextTokens??s.filter(i=>i.enabled).reduce((i,P)=>i+(P.baseTokens??0),0),G=new Set(s.filter(i=>i.enabled).map(i=>i.knowledgeType)).size,X=(l?.length??0)+(c?.filter(i=>i.enabled).length??0),me=d.length>1,_=dt(C,G,X,me),q=(y.find(i=>i.id===r)?.models??[]).map(i=>i.id),U=rt(_,q,h!=="auto"?h:void 0,v.maxModel,C||4e3),ne=it(U.model,C||4e3),xe=f?.cacheHitPct??(m?(m.cachedTokens??0)/Math.max(m.inputTokens??1,1):0),Z=lt(_,X,U.tier),he=()=>{const i=parseFloat($);if(isNaN(i)||i<=0)return;const P=h!=="auto"?h:void 0;fetch(`${ie}/cost/${encodeURIComponent(b)}/budget`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({budgetLimit:i,preferredModel:P})}).then(R=>R.ok?R.json():null).then(R=>{R?.data&&N(ge=>({...ge,budgetLimit:i,preferredModel:P}))}).catch(()=>{})},fe=[{value:"auto",label:"Auto (recommended)"},...q.map(i=>({value:i,label:i}))],ae=f&&f.runCount>0?`${f.runCount} run${f.runCount!==1?"s":""}`:void 0;return e.jsx(W,{icon:Lt,label:"Cost Intelligence",color:"#6ba211",badge:ae,collapsed:o,onToggle:a,children:e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{className:"flex gap-2",children:[e.jsx(ve,{label:"Est. $/run",value:`$${ne.netCost.toFixed(4)}`,sub:"with cache discount"}),e.jsx(ve,{label:"Auto-model",value:U.tier.charAt(0).toUpperCase()+U.tier.slice(1),sub:U.model.split("-").slice(0,3).join("-")}),e.jsx(ve,{label:"Cache hit",value:`${(xe*100).toFixed(0)}%`,sub:m?"last run":f?"avg":"no data"})]}),e.jsxs("div",{className:"flex items-start gap-2 px-3 py-2 rounded-lg text-[12px]",style:{background:t.isDark?"#1c1c20":"#f3f4f6",color:t.textSecondary},children:[e.jsx(_e,{size:12,style:{color:"#FE5000",flexShrink:0,marginTop:2}}),e.jsxs("div",{children:[e.jsxs("span",{style:{color:t.textDim},children:["Why ",be[U.tier],"? "]}),e.jsx("span",{children:U.reason}),e.jsxs("span",{style:{color:t.textFaint},children:[" ","(complexity: ",(_*100).toFixed(0),"%)"]})]})]}),Z&&e.jsxs("div",{className:"flex items-start gap-2 px-3 py-2 rounded-lg text-[12px]",style:{background:"#FE500008",border:"1px solid #FE500020",color:t.textSecondary},children:[e.jsx(Bt,{size:12,style:{color:"#FE5000",flexShrink:0,marginTop:2}}),e.jsx("span",{children:Z})]}),v.budgetLimit>0&&v.totalSpent>=v.budgetLimit&&e.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg text-[12px]",style:{background:"#e74c3c18",border:"1px solid #e74c3c40",color:"#e74c3c"},children:[e.jsx("span",{children:"🚫 Budget exceeded — test runs paused"}),e.jsxs("button",{type:"button",className:"ml-auto text-[11px] font-semibold border-none bg-transparent cursor-pointer",style:{color:"#e74c3c"},onClick:()=>{const i=(v.budgetLimit*2).toFixed(2);z(i)},children:["Increase to $",(v.budgetLimit*2).toFixed(2)," →"]})]}),e.jsx(xs,{spent:v.totalSpent,limit:v.budgetLimit}),f&&Object.keys(f.modelBreakdown).length>0&&e.jsx("div",{className:"flex gap-2 flex-wrap",children:Object.entries(f.modelBreakdown).map(([i,P])=>e.jsxs("span",{className:"text-[10px] px-2 py-1 rounded",style:{background:(le[i]??"#888")+"18",color:le[i]??"#888",fontFamily:"'Geist Mono', monospace"},children:[be[i]??i," × ",P.count," ($",P.cost.toFixed(3),")"]},i))}),e.jsxs("div",{className:"flex gap-2 flex-wrap items-end",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-[10px] uppercase tracking-wide",style:{color:t.textDim,fontFamily:"'Geist Mono', monospace"},children:"Model"}),e.jsx("select",{value:h,onChange:i=>p(i.target.value),className:"text-[12px] px-2 py-1 rounded border outline-none",style:{background:t.inputBg,border:`1px solid ${t.border}`,color:t.textPrimary,fontFamily:"'Geist Mono', monospace"},children:fe.map(i=>e.jsx("option",{value:i.value,children:i.label},i.value))})]}),e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx("label",{className:"text-[10px] uppercase tracking-wide",style:{color:t.textDim,fontFamily:"'Geist Mono', monospace"},children:"Budget ($)"}),e.jsx("input",{type:"number",step:"0.25",min:"0.01",value:$,onChange:i=>z(i.target.value),className:"text-[12px] px-2 py-1 rounded border outline-none w-20",style:{background:t.inputBg,border:`1px solid ${t.border}`,color:t.textPrimary,fontFamily:"'Geist Mono', monospace"}})]}),e.jsx("button",{type:"button",onClick:he,className:"text-[11px] px-3 py-1 rounded border-none cursor-pointer font-semibold",style:{background:"#FE5000",color:"#fff",fontFamily:"'Geist Mono', monospace"},children:"Save"}),e.jsx("button",{type:"button",onClick:()=>u(!D),className:"text-[11px] px-3 py-1 rounded cursor-pointer",style:{background:"transparent",border:`1px solid ${t.border}`,color:t.textDim,fontFamily:"'Geist Mono', monospace"},children:D?"Hide history":"History"})]}),D&&S.length>0&&e.jsx("div",{className:"overflow-x-auto rounded-lg",style:{border:`1px solid ${t.border}`},children:e.jsxs("table",{className:"w-full text-[11px]",style:{fontFamily:"'Geist Mono', monospace",borderCollapse:"collapse"},children:[e.jsx("thead",{children:e.jsx("tr",{style:{background:t.isDark?"#1c1c20":"#f3f4f6"},children:["Time","Model","In","Out","Cost"].map(i=>e.jsx("th",{className:"px-3 py-1.5 text-left font-medium",style:{color:t.textDim,borderBottom:`1px solid ${t.border}`},children:i},i))})}),e.jsx("tbody",{children:S.map((i,P)=>{const R=ct(i.model);return e.jsxs("tr",{style:{borderBottom:`1px solid ${t.border}20`},children:[e.jsx("td",{className:"px-3 py-1",style:{color:t.textFaint},children:new Date(i.timestamp).toLocaleTimeString()}),e.jsx("td",{className:"px-3 py-1",children:e.jsx("span",{className:"px-1 rounded",style:{background:(le[R]??"#888")+"18",color:le[R]??"#888"},children:be[R]??R})}),e.jsxs("td",{className:"px-3 py-1",style:{color:t.textSecondary},children:[(i.inputTokens/1e3).toFixed(1),"K"]}),e.jsx("td",{className:"px-3 py-1",style:{color:t.textSecondary},children:i.outputTokens}),e.jsxs("td",{className:"px-3 py-1",style:{color:t.textPrimary},children:["$",i.costUsd.toFixed(5)]})]},P)})})]})}),D&&S.length===0&&e.jsx("p",{className:"text-[12px]",style:{color:t.textFaint},children:"No cost records yet. Run the agent to track costs."})]})})}const je=[{label:"Low",value:.6,hint:"Only refine when very uncertain"},{label:"Medium",value:.4,hint:"Refine on moderate uncertainty (recommended)"},{label:"High",value:.2,hint:"Refine on any hint of uncertainty"}];function fs(){try{const o=pt(t=>t.getDisplayTrace),a=typeof o=="function"?o():null;if(!a||!Array.isArray(a.events))return null;for(let t=a.events.length-1;t>=0;t--){const n=a.events[t];if(n.kind==="pipeline_stage"&&n.provenanceStages){for(const s of n.provenanceStages)if(s.stage==="adaptive_retrieval")return s.data}}}catch{}return null}function gs({collapsed:o,onToggle:a}){const t=E(),n=j(r=>r.adaptiveConfig),s=j(r=>r.setAdaptiveConfig),[l,c]=g.useState(!1),d=fs(),m=n??{enabled:!1,maxCycles:1,gapThreshold:.4,totalTimeoutMs:8e3},y=je.find(r=>r.value===m.gapThreshold)??je[1];return e.jsx(W,{icon:Gt,label:"Smart Retrieval",color:"#00a6ce",badge:m.enabled?"on":"off",collapsed:o,onToggle:a,children:e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"flex-1",children:e.jsx("div",{className:"text-xs",style:{color:t.textDim},children:"Auto-refines context when the agent seems uncertain. Replaces low-relevance knowledge with better matches. Same token budget."})}),e.jsx("button",{type:"button",onClick:()=>s({enabled:!m.enabled}),className:"relative w-10 h-6 rounded-full transition-colors border-none cursor-pointer shrink-0",style:{background:m.enabled?"#FE5000":t.surfaceElevated},title:m.enabled?"Disable Smart Retrieval":"Enable Smart Retrieval",children:e.jsx("div",{className:"absolute top-0.5 w-5 h-5 rounded-full transition-transform",style:{background:"white",left:m.enabled?"18px":"2px",boxShadow:"0 1px 3px rgba(0,0,0,0.3)"}})})]}),d&&e.jsxs("div",{className:"rounded-lg p-3 space-y-2",style:{background:t.isDark?"#1c1c20":"#f3f4f6"},children:[e.jsx("div",{className:"text-xs font-medium",style:{color:t.textDim},children:"Last run"}),e.jsxs("div",{className:"flex items-center gap-4 text-xs",children:[e.jsxs("div",{children:[e.jsx("span",{style:{color:t.textDim},children:"Cycles: "}),e.jsx("span",{style:{fontFamily:"'Geist Mono', monospace",color:t.textPrimary},children:d.cycleCount})]}),e.jsxs("div",{children:[e.jsx("span",{style:{color:t.textDim},children:"Hedging: "}),e.jsxs("span",{style:{fontFamily:"'Geist Mono', monospace",color:d.hedgingScore>=d.threshold?"#FE5000":"#10b981"},children:[(d.hedgingScore*100).toFixed(0),"%"]})]}),d.cycleCount>0&&e.jsxs("div",{children:[e.jsx("span",{style:{color:t.textDim},children:"Rel. Δ: "}),e.jsxs("span",{style:{fontFamily:"'Geist Mono', monospace",color:d.avgRelevanceAfter>d.avgRelevanceBefore?"#10b981":t.textDim},children:[d.avgRelevanceAfter>d.avgRelevanceBefore?"+":"",((d.avgRelevanceAfter-d.avgRelevanceBefore)*100).toFixed(1),"%"]})]}),e.jsxs("div",{style:{color:t.textFaint,fontFamily:"'Geist Mono', monospace",marginLeft:"auto"},children:[d.durationMs,"ms"]})]}),d.aborted&&e.jsxs("div",{className:"text-xs",style:{color:"#f59e0b"},children:["Aborted: ",d.abortReason]})]}),e.jsxs("div",{children:[e.jsxs("button",{type:"button",onClick:()=>c(r=>!r),className:"flex items-center gap-1 text-xs border-none bg-transparent cursor-pointer",style:{color:t.textDim},children:[l?e.jsx(Xe,{size:12}):e.jsx(Ye,{size:12}),"Advanced settings"]}),l&&e.jsxs("div",{className:"mt-3 space-y-4",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-xs font-medium",style:{color:t.textDim},children:"Max Cycles"}),e.jsx("div",{className:"flex gap-2",children:[1,2,3].map(r=>e.jsx("button",{type:"button",onClick:()=>s({maxCycles:r}),className:"px-3 py-1.5 rounded text-xs border-none cursor-pointer",style:{background:m.maxCycles===r?"#FE500020":t.surfaceElevated,color:m.maxCycles===r?"#FE5000":t.textDim,border:`1px solid ${m.maxCycles===r?"#FE500060":t.border}`},children:r},r))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"text-xs font-medium",style:{color:t.textDim},children:"Gap Sensitivity"}),e.jsx("div",{className:"space-y-1.5",children:je.map(r=>e.jsxs("button",{type:"button",onClick:()=>s({gapThreshold:r.value}),className:"flex items-center gap-3 w-full px-3 py-2 rounded text-left border-none cursor-pointer",style:{background:y.label===r.label?"#FE500010":t.surfaceElevated,border:`1px solid ${y.label===r.label?"#FE500040":"transparent"}`},children:[e.jsx("div",{className:"w-3 h-3 rounded-full border-2",style:{borderColor:y.label===r.label?"#FE5000":t.textFaint,background:y.label===r.label?"#FE5000":"transparent"}}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"text-xs font-medium",style:{color:t.textPrimary},children:r.label}),e.jsx("div",{className:"text-xs",style:{color:t.textFaint},children:r.hint})]}),e.jsxs("div",{className:"text-xs",style:{color:t.textFaint,fontFamily:"'Geist Mono', monospace"},children:["≥",(r.value*100).toFixed(0),"%"]})]},r.label))})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx("div",{className:"text-xs font-medium",style:{color:t.textDim},children:"Timeout"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"range",min:2e3,max:15e3,step:1e3,value:m.totalTimeoutMs,onChange:r=>s({totalTimeoutMs:Number(r.target.value)}),className:"flex-1",style:{accentColor:"#FE5000"}}),e.jsxs("span",{className:"text-xs",style:{color:t.textDim,fontFamily:"'Geist Mono', monospace",minWidth:40},children:[(m.totalTimeoutMs/1e3).toFixed(0),"s"]})]})]})]})]})]})})}function ys({isOpen:o,onClose:a,prompt:t}){const n=E(),[s,l]=g.useState("Copy"),[c,d]=g.useState(!1),m=j(p=>p.agentMeta),y=j(p=>p.instructionState),r=j(p=>p.workflowSteps),f=j(p=>p.channels),k=j(p=>p.mcpServers),v=f.filter(p=>p.enabled),N=k?.filter(p=>p.enabled)??[],h=async()=>{try{await navigator.clipboard.writeText(t),l("Copied!"),setTimeout(()=>l("Copy"),2e3)}catch(p){console.error("Failed to copy:",p)}};return o?e.jsx("div",{className:"fixed inset-0 flex items-center justify-center z-50",style:{background:"rgba(0, 0, 0, 0.5)",backdropFilter:"blur(4px)"},onClick:a,children:e.jsxs("div",{className:"w-full h-[80vh] m-4 rounded-lg border shadow-lg flex flex-col",style:{background:n.surface,borderColor:n.border},onClick:p=>p.stopPropagation(),children:[e.jsxs("div",{className:"flex items-center justify-between p-4 border-b",style:{borderColor:n.border},children:[e.jsx("h3",{className:"text-lg font-semibold m-0",style:{color:n.textPrimary,fontFamily:"'Geist Sans', sans-serif"},children:"Agent Preview"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs("button",{type:"button",onClick:h,className:"flex items-center gap-2 px-3 py-2 text-sm rounded border",style:{background:"transparent",color:n.textSecondary,borderColor:n.border},children:[s==="Copy"?e.jsx(Wt,{size:14}):e.jsx(Ne,{size:14}),s]}),e.jsx("button",{type:"button",onClick:a,className:"flex items-center justify-center w-8 h-8 rounded-md border-none cursor-pointer",style:{background:"transparent",color:n.textSecondary},"aria-label":"Close modal",children:e.jsx(oe,{size:16})})]})]}),e.jsxs("div",{className:"flex-1 p-4 overflow-y-auto space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsx(ce,{icon:Je,label:"Identity",value:m.name||"Unnamed Agent",sub:y.persona?.slice(0,80)+(y.persona?.length>80?"…":""),color:"#2393f1",t:n}),e.jsx(ce,{icon:Fe,label:"Objective",value:y.objectives.primary?.slice(0,60)||"Not set",sub:`${y.objectives.successCriteria.length} success criteria`,color:"#2caa4e",t:n}),e.jsx(ce,{icon:Ve,label:"Workflow",value:`${r.length} steps`,sub:r.slice(0,3).map(p=>p.label).join(" → ")||"No workflow",color:"#d96e00",t:n}),e.jsx(ce,{icon:Te,label:"Context",value:`${v.length} sources, ${N.length} tools`,sub:`Tone: ${y.tone} · Expertise: ${y.expertise}/5`,color:"#00ae9b",t:n})]}),e.jsxs("button",{type:"button",onClick:()=>d(!c),className:"text-xs px-3 py-1.5 rounded border cursor-pointer",style:{background:"transparent",borderColor:n.border,color:n.textDim},children:[c?"Hide":"Show"," Raw System Prompt"]}),c&&e.jsx("div",{className:"p-4 rounded-lg border",style:{background:n.isDark?"#0a1929":"#f8fafc",borderColor:n.border},children:e.jsx("pre",{className:"whitespace-pre-wrap",style:{fontSize:"13px",color:n.textSecondary,fontFamily:"'Geist Mono', monospace",lineHeight:1.5,margin:0},children:t||"No system prompt generated yet."})})]})]})}):null}function ce({icon:o,label:a,value:t,sub:n,color:s,t:l}){return e.jsxs("div",{className:"p-3 rounded-lg border",style:{borderColor:l.border,background:l.surfaceElevated},children:[e.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[e.jsx(o,{size:14,style:{color:s}}),e.jsx("span",{className:"text-[11px] uppercase tracking-wide font-semibold",style:{color:l.textDim},children:a})]}),e.jsx("div",{className:"text-sm font-medium",style:{color:l.textPrimary},children:t}),n&&e.jsx("div",{className:"text-xs mt-1",style:{color:l.textSecondary},children:n})]})}function Ts(){const o=j(x=>x.agentMeta),a=j(x=>x.setAgentMeta),t=j(x=>x.instructionState),n=j(x=>x.updateInstruction),s=j(x=>x.workflowSteps),l=j(x=>x.channels),c=j(x=>x.selectedModel),d=j(x=>x.outputFormat),m=j(x=>x.setOutputFormat),y=j(x=>x.outputFormats),r=j(x=>x.prompt),f=j(x=>x.tokenBudget),k=j(x=>x.mcpServers),v=j(x=>x.skills),N=B(x=>x.saveStatus),h=B(x=>x.agentId)??"",[p,$]=g.useState(!1),[z,D]=g.useState(!1),[u,S]=g.useState(!1),[M,b]=g.useState(!1),[C,G]=g.useState(!1),[X,me]=g.useState(!1),[_,Me]=g.useState(!1),[q,U]=g.useState(!1),[ne,xe]=g.useState(!1),[Z,he]=g.useState(!1),[fe,ae]=g.useState(!1),i=g.useCallback(()=>{const x=j.getState(),F=Ue.getState(),L=ke.getState(),w=l.filter(A=>A.enabled).map(A=>({sourceId:A.sourceId,name:A.name,path:A.path,knowledgeType:A.knowledgeType,depth:A.depth,tokens:A.baseTokens,content:A.content})),T=F.lastPipelineStats?.pipeline,O=T?{context:T.context,tokens:T.tokens,utilization:T.utilization,sources:T.sources.map(A=>({name:A.name,type:A.type,totalTokens:A.totalTokens})),compression:{originalTokens:T.compression.originalTokens,compressedTokens:T.compression.compressedTokens,ratio:T.compression.ratio},timing:{totalMs:T.timing.totalMs}}:void 0,re=L.facts.map(A=>({id:A.id,text:A.content,domain:A.domain}));return{channels:l,selectedModel:c,outputFormat:d,outputFormats:y,prompt:r,tokenBudget:f,mcpServers:k,skills:v,agentMeta:o,agentConfig:x.agentConfig,connectors:x.connectors,instructionState:x.instructionState,workflowSteps:x.workflowSteps,knowledgeContent:w,pipelineSnapshot:O,facts:re.length>0?re:void 0}},[l,c,d,y,r,f,k,v,o,s]),P=g.useCallback(async()=>{const x=Y.getState().lessons,F=Pe.getState().runs,L=Pe.getState().suite,w=x.filter(I=>I.agentId===h&&I.status==="approved"),T=w.length>0?w.reduce((I,H)=>I+H.confidence,0)/w.length:0,O=F.length>0?F[F.length-1].globalScore:null,re=l.filter(I=>I.enabled).length,A=l.filter(I=>I.enabled).reduce((I,H)=>I+(H.baseTokens??0),0);let Ee=0,$e=0,Ae=c||"";try{const I=await fetch(`/api/cost/${h}/summary`).then(H=>H.json());if(I?.data){Ee=I.data.avgCostPerRun??0,$e=I.data.cacheHitPct??0;const H=I.data.modelBreakdown??{},De=Object.entries(H).sort((ot,nt)=>nt[1].count-ot[1].count)[0];De&&(Ae=De[0])}}catch{}return{knowledgeSources:re,knowledgeTokens:A,lessonsCount:w.length,avgConfidence:T,avgCostPerRun:Ee,topModel:Ae,cacheHitPct:$e,qualityScore:O,testCasesCount:L.testCases.length}},[h,l,c]),R=g.useCallback(async()=>{const x=i(),F=await P(),L={...x,performanceSummary:F},w=xt(L),T=w.match(/^name:\s*(.+)$/m)?.[1]?.trim()??"modular-agent";ee(w,T)},[i,P]),ge=g.useCallback(async x=>{const F=i(),L=await P(),w={...F,performanceSummary:L},T=w.agentMeta.name||"modular-agent";switch(x){case"JSON":{const O=ft(w);ee(O,T,".json");break}case"YAML":{const O=ht(w);ee(O,T,".yaml");break}case"Markdown":case"Claude format":{const O=Re("claude",w);ee(O,T,".md");break}case"OpenAI format":{const O=Re("codex",w);ee(O,T,".json");break}}},[i,P]),{constraints:Q}=t,J=Q.customConstraints?Q.customConstraints.split(`
|
|
85
|
+
`).filter(x=>x.trim()):[],Ze=x=>{if(x&&!J.includes(x)){const F=[...J,x];n({constraints:{...Q,customConstraints:F.join(`
|
|
86
|
+
`)}})}},Qe=x=>{const F=J.filter(L=>L!==x);n({constraints:{...Q,customConstraints:F.join(`
|
|
87
|
+
`)}})},et=()=>{const{persona:x,constraints:F,objectives:L}=t;let w="";return x&&(w+=`You are ${o.name||"an AI assistant"}.
|
|
88
|
+
|
|
89
|
+
${x}
|
|
90
|
+
|
|
91
|
+
`),(J.length>0||F.neverMakeUp||F.askBeforeActions)&&(w+=`CONSTRAINTS:
|
|
92
|
+
`,F.neverMakeUp&&(w+=`- Never fabricate information. If you don't know something, say so.
|
|
93
|
+
`),F.askBeforeActions&&(w+=`- Always ask for permission before taking actions that could affect the user's system.
|
|
94
|
+
`),F.stayInScope&&(w+=`- Stay within the defined scope of your role and responsibilities.
|
|
95
|
+
`),F.useOnlyTools&&(w+=`- Only use the tools and information sources provided to you.
|
|
96
|
+
`),F.limitWords&&F.wordLimit>0&&(w+=`- Keep responses concise, under ${F.wordLimit} words when possible.
|
|
97
|
+
`),J.forEach(T=>{w+=`- ${T}
|
|
98
|
+
`}),w+=`
|
|
99
|
+
`),L.primary&&(w+=`PRIMARY OBJECTIVE: ${L.primary}
|
|
100
|
+
|
|
101
|
+
`),s.length>0&&(w+=`WORKFLOW:
|
|
102
|
+
`,s.forEach((T,O)=>{w+=`${O+1}. ${T.label}
|
|
103
|
+
`}),w+=`
|
|
104
|
+
`),w.trim()},tt={color:"var(--text-primary)",fontFamily:"'Geist Sans', sans-serif"},st={color:"var(--text-secondary)",lineHeight:1.5};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-2xl font-semibold mb-2 m-0",style:tt,children:"Review & Configure"}),e.jsx("p",{className:"text-sm",style:st,children:"Review and finalize your agent's configuration. Customize the identity, persona, constraints, and output settings before testing."})]}),e.jsx(as,{onExport:R,onExportFormat:ge,onPromptPreview:()=>ae(!0),saveStatus:N}),e.jsxs("div",{className:"space-y-6",children:[e.jsx(Jt,{agentMeta:o,setAgentMeta:a,collapsed:p,onToggle:()=>$(!p)}),e.jsx(Qt,{persona:t.persona,tone:t.tone,expertise:t.expertise,updateInstruction:n,collapsed:z,onToggle:()=>D(!z)}),e.jsx(ts,{constraints:Q,updateInstruction:n,customConstraints:J,addCustomConstraint:Ze,removeCustomConstraint:Qe,collapsed:u,onToggle:()=>S(!u)}),e.jsx(ss,{objectives:t.objectives,updateInstruction:n,collapsed:M,onToggle:()=>b(!M)}),e.jsx(os,{workflowSteps:s,collapsed:C,onToggle:()=>G(!C)}),e.jsx(ns,{selectedModel:c,outputFormat:d,setOutputFormat:x=>m(x),tokenBudget:f,collapsed:X,onToggle:()=>me(!X)}),e.jsx(ds,{collapsed:_,onToggle:()=>Me(!_)}),e.jsx(ms,{collapsed:q,onToggle:()=>U(!q)}),e.jsx(hs,{collapsed:ne,onToggle:()=>xe(!ne)}),e.jsx(gs,{collapsed:Z,onToggle:()=>he(!Z)})]}),e.jsx("div",{className:"mt-4",children:e.jsx(_t,{})}),e.jsx(ys,{isOpen:fe,onClose:()=>ae(!1),prompt:et()})]})}export{Ts as ReviewTab};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as e}from"./vendor-D1h_O76p.js";import{u as p}from"./index-
|
|
1
|
+
import{j as e}from"./vendor-D1h_O76p.js";import{u as p}from"./index-C626nWuA.js";import{C as u,a as h}from"./icons-CS8RUPBi.js";function g({checked:n,onChange:r,label:i,size:o="md",disabled:s}){const a=p(),l=o==="sm"?28:36,d=o==="sm"?16:20,t=o==="sm"?12:16;return e.jsxs("button",{type:"button",role:"switch","aria-checked":n,onClick:()=>!s&&r(!n),className:"flex items-center gap-2 cursor-pointer border-none bg-transparent p-0 nodrag",style:{opacity:s?.5:1,cursor:s?"not-allowed":"pointer"},children:[e.jsx("div",{className:"relative rounded-full transition-colors",style:{width:l,height:d,background:n?"#FE5000":a.border},children:e.jsx("div",{className:"absolute top-[2px] rounded-full bg-white transition-transform",style:{width:t,height:t,transform:`translateX(${n?l-t-2:2}px)`,transition:"transform 0.15s ease"}})}),i&&e.jsx("span",{className:"text-[13px]",style:{color:a.textSecondary},children:i})]})}function j({icon:n,label:r,color:i,badge:o,collapsed:s,onToggle:a,children:l,id:d}){const t=p(),c=d||`section-${r.toLowerCase().replace(/\s+/g,"-")}`,m=`${c}-content`;return e.jsxs("section",{role:"region","aria-labelledby":`${c}-heading`,className:"mb-6",style:{border:`1px solid ${t.border}`,borderRadius:"8px",overflow:"hidden"},children:[e.jsx("h3",{id:`${c}-heading`,className:"m-0",children:e.jsxs("button",{type:"button",onClick:a,"aria-expanded":!s,"aria-controls":m,className:"flex items-center gap-2 w-full px-5 py-3.5 border-none cursor-pointer select-none transition-colors",style:{background:t.surfaceElevated},onKeyDown:x=>{(x.key==="Enter"||x.key===" ")&&(x.preventDefault(),a())},children:[e.jsx(n,{size:16,style:{color:i,flexShrink:0}}),s?e.jsx(u,{size:12,style:{color:t.textDim},"aria-hidden":"true"}):e.jsx(h,{size:12,style:{color:t.textDim},"aria-hidden":"true"}),e.jsx("span",{className:"text-sm font-semibold flex-1 text-left",style:{fontFamily:"'Geist Sans', sans-serif",color:t.textPrimary},children:r}),o&&e.jsx("span",{className:"text-[13px] px-2 py-1 rounded-full",style:{fontFamily:"'Geist Mono', monospace",color:t.textDim,background:t.badgeBg},"aria-label":`${r} status: ${o}`,children:o}),e.jsxs("span",{className:"sr-only",children:[s?"Expand":"Collapse"," ",r," section"]})]})}),!s&&e.jsx("div",{id:m,className:"px-5 pb-4",role:"region","aria-labelledby":`${c}-heading`,children:l})]})}export{j as S,g as T};
|