brief-lens 0.1.2 → 0.1.3

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.
Files changed (85) hide show
  1. package/dist/python/prompts/chat_insights.md +34 -0
  2. package/dist/python/src/chat_cli.py +28 -9
  3. package/dist/python/src/chat_insights.py +200 -0
  4. package/dist/python/src/local_llm/config.py +5 -0
  5. package/dist/python/src/local_llm/indexer.py +63 -10
  6. package/dist/python/src/workflow/definitions/chat_insights.py +83 -0
  7. package/dist/python/src/workflow/definitions/daily.py +4 -1
  8. package/dist/python/web/routers/chat.py +36 -19
  9. package/dist/python/web/routers/config.py +28 -0
  10. package/dist/web/.next-pack/BUILD_ID +1 -1
  11. package/dist/web/.next-pack/app-build-manifest.json +33 -32
  12. package/dist/web/.next-pack/app-path-routes-manifest.json +1 -1
  13. package/dist/web/.next-pack/build-manifest.json +2 -2
  14. package/dist/web/.next-pack/prerender-manifest.json +1 -1
  15. package/dist/web/.next-pack/server/app/(main)/auth/page.js.nft.json +1 -1
  16. package/dist/web/.next-pack/server/app/(main)/auth/page_client-reference-manifest.js +1 -1
  17. package/dist/web/.next-pack/server/app/(main)/briefing/page.js.nft.json +1 -1
  18. package/dist/web/.next-pack/server/app/(main)/briefing/page_client-reference-manifest.js +1 -1
  19. package/dist/web/.next-pack/server/app/(main)/chat/page.js +1 -1
  20. package/dist/web/.next-pack/server/app/(main)/chat/page.js.nft.json +1 -1
  21. package/dist/web/.next-pack/server/app/(main)/chat/page_client-reference-manifest.js +1 -1
  22. package/dist/web/.next-pack/server/app/(main)/config/usage/page.js.nft.json +1 -1
  23. package/dist/web/.next-pack/server/app/(main)/config/usage/page_client-reference-manifest.js +1 -1
  24. package/dist/web/.next-pack/server/app/(main)/credentials/page.js.nft.json +1 -1
  25. package/dist/web/.next-pack/server/app/(main)/credentials/page_client-reference-manifest.js +1 -1
  26. package/dist/web/.next-pack/server/app/(main)/geopolitical/page.js.nft.json +1 -1
  27. package/dist/web/.next-pack/server/app/(main)/geopolitical/page_client-reference-manifest.js +1 -1
  28. package/dist/web/.next-pack/server/app/(main)/journal/page.js +1 -1
  29. package/dist/web/.next-pack/server/app/(main)/journal/page.js.nft.json +1 -1
  30. package/dist/web/.next-pack/server/app/(main)/journal/page_client-reference-manifest.js +1 -1
  31. package/dist/web/.next-pack/server/app/(main)/monitor/page.js.nft.json +1 -1
  32. package/dist/web/.next-pack/server/app/(main)/monitor/page_client-reference-manifest.js +1 -1
  33. package/dist/web/.next-pack/server/app/(main)/portfolio/page.js.nft.json +1 -1
  34. package/dist/web/.next-pack/server/app/(main)/portfolio/page_client-reference-manifest.js +1 -1
  35. package/dist/web/.next-pack/server/app/(main)/run/page.js.nft.json +1 -1
  36. package/dist/web/.next-pack/server/app/(main)/run/page_client-reference-manifest.js +1 -1
  37. package/dist/web/.next-pack/server/app/(main)/watch-sectors/page.js.nft.json +1 -1
  38. package/dist/web/.next-pack/server/app/(main)/watch-sectors/page_client-reference-manifest.js +1 -1
  39. package/dist/web/.next-pack/server/app/(main)/workspace/page.js.nft.json +1 -1
  40. package/dist/web/.next-pack/server/app/(main)/workspace/page_client-reference-manifest.js +1 -1
  41. package/dist/web/.next-pack/server/app/_not-found/page.js.nft.json +1 -1
  42. package/dist/web/.next-pack/server/app/_not-found/page_client-reference-manifest.js +1 -1
  43. package/dist/web/.next-pack/server/app/_not-found.html +2 -2
  44. package/dist/web/.next-pack/server/app/_not-found.rsc +1 -1
  45. package/dist/web/.next-pack/server/app/api/[...path]/route.js.nft.json +1 -1
  46. package/dist/web/.next-pack/server/app/api/attachments/[...path]/route.js.nft.json +1 -1
  47. package/dist/web/.next-pack/server/app/api/attachments/upload/route.js.nft.json +1 -1
  48. package/dist/web/.next-pack/server/app/api/images/[...path]/route.js.nft.json +1 -1
  49. package/dist/web/.next-pack/server/app/api/images/upload/route.js.nft.json +1 -1
  50. package/dist/web/.next-pack/server/app/icon.svg/route.js.nft.json +1 -1
  51. package/dist/web/.next-pack/server/app/page.js +9 -9
  52. package/dist/web/.next-pack/server/app/page.js.nft.json +1 -1
  53. package/dist/web/.next-pack/server/app/page_client-reference-manifest.js +1 -1
  54. package/dist/web/.next-pack/server/app-paths-manifest.json +6 -6
  55. package/dist/web/.next-pack/server/chunks/1442.js +2 -2
  56. package/dist/web/.next-pack/server/chunks/899.js +1 -0
  57. package/dist/web/.next-pack/server/pages/404.html +2 -2
  58. package/dist/web/.next-pack/server/pages/500.html +1 -1
  59. package/dist/web/.next-pack/server/pages/_app.js.nft.json +1 -1
  60. package/dist/web/.next-pack/server/pages/_document.js.nft.json +1 -1
  61. package/dist/web/.next-pack/server/pages/_error.js.nft.json +1 -1
  62. package/dist/web/.next-pack/server/server-reference-manifest.json +1 -1
  63. package/dist/web/.next-pack/static/chunks/2793-3a816c3e63003cd6.js +1 -0
  64. package/dist/web/.next-pack/static/chunks/4397-f2bbfac974a09e4a.js +1 -0
  65. package/dist/web/.next-pack/static/chunks/6739-73ae2a518896a21d.js +1 -0
  66. package/dist/web/.next-pack/static/chunks/9095-7b51a045d7ef3c03.js +1 -0
  67. package/dist/web/.next-pack/static/chunks/app/(main)/briefing/page-2bd110800f6f6092.js +1 -0
  68. package/dist/web/.next-pack/static/chunks/app/(main)/chat/page-4787522c9ae8eb98.js +1 -0
  69. package/dist/web/.next-pack/static/chunks/app/(main)/journal/page-f06bd837eb652eec.js +1 -0
  70. package/dist/web/.next-pack/static/chunks/app/(main)/layout-722c5f8b47c03713.js +1 -0
  71. package/dist/web/.next-pack/static/chunks/app/page-31f1d43bab366b86.js +1 -0
  72. package/dist/web/.next-pack/static/css/eeafe748380067e9.css +3 -0
  73. package/package.json +1 -1
  74. package/dist/web/.next-pack/server/chunks/3462.js +0 -1
  75. package/dist/web/.next-pack/static/chunks/2941-b28caa63b1192cbf.js +0 -1
  76. package/dist/web/.next-pack/static/chunks/6739-26a12feb3f34ac69.js +0 -1
  77. package/dist/web/.next-pack/static/chunks/8480-3e063ceeceee7e6a.js +0 -1
  78. package/dist/web/.next-pack/static/chunks/app/(main)/briefing/page-32855bc0aad3c4c5.js +0 -1
  79. package/dist/web/.next-pack/static/chunks/app/(main)/chat/page-f176f405e29e9deb.js +0 -1
  80. package/dist/web/.next-pack/static/chunks/app/(main)/journal/page-d0b70496ffe17f8d.js +0 -1
  81. package/dist/web/.next-pack/static/chunks/app/(main)/layout-b0cecbd1d6c9d290.js +0 -1
  82. package/dist/web/.next-pack/static/chunks/app/page-ecd907ac75b147cf.js +0 -1
  83. package/dist/web/.next-pack/static/css/ddefc688f27e14b2.css +0 -3
  84. /package/dist/web/.next-pack/static/{VdoUHqMuKEB2yUBQvac5b → HRelvfbIJ8aRo0S_dK4jo}/_buildManifest.js +0 -0
  85. /package/dist/web/.next-pack/static/{VdoUHqMuKEB2yUBQvac5b → HRelvfbIJ8aRo0S_dK4jo}/_ssgManifest.js +0 -0
@@ -0,0 +1 @@
1
+ "use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6739],{90160:function(t,e,n){n.d(e,{JournalChatJobStateProvider:function(){return f},R:function(){return d}});var r=n(57437),a=n(2265),u=n(22384);let o="ai-agent:journal-chat-job:v1",s={jobId:null,status:"idle",question:"",targetEntryId:null,imagePaths:[],assistantContent:"",error:null},l=t=>"pending"===t||"running"===t;function i(){try{window.sessionStorage.removeItem(o)}catch(t){}}let c=(0,a.createContext)(null);function f(t){let{children:e}=t,[n,f]=(0,a.useState)(s),[d,h]=(0,a.useState)(!1),g=(0,a.useRef)(!1);(0,a.useEffect)(()=>{f(function(){try{let t=window.sessionStorage.getItem(o);if(!t)return s;let e=JSON.parse(t),n={...s,...e};if(l(n.status)&&!n.jobId)return s;return n}catch(t){return s}}()),h(!0)},[]),(0,a.useEffect)(()=>{d&&(n.jobId&&l(n.status)?function(t){try{window.sessionStorage.setItem(o,JSON.stringify({...t,assistantContent:""}))}catch(t){}}(n):i())},[n,d]);let m=n.jobId,b=l(n.status);(0,a.useEffect)(()=>{if(!d||!m||!b)return;let t=new AbortController,e=!1,n=t=>{e||f(e=>e.jobId!==m?e:t(e))};return(async()=>{let e;n(t=>({...t,assistantContent:""}));try{e=await fetch("/api/chat/".concat(m,"/stream"),{method:"GET",cache:"no-store",signal:t.signal})}catch(e){if(t.signal.aborted)return;n(t=>({...t,status:"failed",error:e instanceof Error?e.message:"Network error"}));return}if(t.signal.aborted)return;if(404===e.status){n(()=>({...s,status:"failed",error:"The previous brainstorm job is no longer available — please ask again."}));return}if(!e.ok||!e.body){let t=await e.text().catch(()=>"");n(n=>({...n,status:"failed",error:"Stream failed (HTTP ".concat(e.status,"): ").concat(t)}));return}let r="";try{for await(let a of(0,u.v$)(e.body,t.signal))"message"===a.type&&(r=(0,u.bv)(r,a.data),n(t=>({...t,assistantContent:(0,u.bv)(t.assistantContent,a.data)})))}catch(e){if(t.signal.aborted)return;n(t=>({...t,status:"failed",error:e instanceof Error?e.message:"Stream read error"}));return}if(!t.signal.aborted){if(!r){n(t=>({...t,status:"failed",error:"Brainstorm returned an empty answer."}));return}n(t=>({...t,status:"done"}))}})(),()=>{e=!0,t.abort()}},[d,m,b]);let y=(0,a.useCallback)(async t=>{let e;g.current=!1,f(()=>{var e;return{...s,status:"pending",question:t.question,targetEntryId:t.targetEntryId,imagePaths:null!==(e=t.imagePaths)&&void 0!==e?e:[]}});try{var n;e=await fetch("/api/journal/chat",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({question:t.question,...(null===(n=t.imagePaths)||void 0===n?void 0:n.length)?{image_paths:t.imagePaths}:{}})})}catch(t){f(e=>({...e,status:"failed",error:t instanceof Error?t.message:"Network error"}));return}if(!e.ok){let t=await e.text().catch(()=>""),n=404===e.status?"No journal entries yet — record something first.":"Brainstorm failed (HTTP ".concat(e.status,"): ").concat(t);f(t=>({...t,status:"failed",error:n}));return}let r=await e.json();if(!r.job_id){f(t=>({...t,status:"failed",error:"POST /api/journal/chat returned no job_id"}));return}if(g.current){fetch("/api/chat/".concat(r.job_id),{method:"DELETE",cache:"no-store"}),g.current=!1,f(()=>s);return}f(t=>{var e;return"pending"===t.status?{...t,jobId:null!==(e=r.job_id)&&void 0!==e?e:null,status:"running"}:t})},[]),p=(0,a.useCallback)(()=>{n.jobId?(fetch("/api/chat/".concat(n.jobId),{method:"DELETE",cache:"no-store"}),f(s),i()):g.current=!0},[n.jobId]),j=(0,a.useCallback)(()=>{f(s),i()},[]),w=(0,a.useCallback)(t=>{f(e=>({...e,status:"failed",error:t}))},[]),S=(0,a.useMemo)(()=>({...n,startJob:y,cancelJob:p,reset:j,setError:w}),[n,y,p,j,w]);return(0,r.jsx)(c.Provider,{value:S,children:e})}function d(){let t=(0,a.useContext)(c);if(!t)throw Error("useJournalChatJobState must be used inside <JournalChatJobStateProvider>");return t}},75408:function(t,e,n){n.d(e,{JournalChatStateProvider:function(){return c},l:function(){return f}});var r=n(57437),a=n(2265);let u="ai-agent:journal-chat-history:v1";function o(t){return"object"==typeof t&&null!==t&&"string"==typeof t.question&&"string"==typeof t.answer}function s(t){return t.length<=50?t:t.slice(t.length-50)}function l(){try{window.sessionStorage.removeItem(u)}catch(t){}}let i=(0,a.createContext)(null);function c(t){let{children:e}=t,[n,c]=(0,a.useState)([]),[f,d]=(0,a.useState)(null),[h,g]=(0,a.useState)(!1);(0,a.useEffect)(()=>{let t=function(){try{let t=window.sessionStorage.getItem(u);if(!t)return{turns:[],entryId:null};let e=JSON.parse(t),n=Array.isArray(e.turns)?s(e.turns.filter(o)):[],r="string"==typeof e.entryId?e.entryId:null;return{turns:n,entryId:r}}catch(t){return{turns:[],entryId:null}}}();c(t.turns),d(t.entryId),g(!0)},[]),(0,a.useEffect)(()=>{h&&(0===n.length&&null===f?l():function(t){try{window.sessionStorage.setItem(u,JSON.stringify(t))}catch(t){}}({turns:n,entryId:f}))},[n,f,h]);let m=(0,a.useCallback)(t=>{c(e=>s([...e,t]))},[]),b=(0,a.useCallback)(t=>{d(t)},[]),y=(0,a.useCallback)(()=>{c([]),d(null),l()},[]),p=(0,a.useMemo)(()=>({turns:n,entryId:f,addTurn:m,setEntryId:b,reset:y}),[n,f,m,b,y]);return(0,r.jsx)(i.Provider,{value:p,children:e})}function f(){let t=(0,a.useContext)(i);if(!t)throw Error("useJournalChatState must be used inside <JournalChatStateProvider>");return t}},5620:function(t,e,n){n.d(e,{JournalNavProvider:function(){return i},O:function(){return c}});var r=n(57437),a=n(99376),u=n(2265),o=n(90160),s=n(75408);let l=(0,u.createContext)(null);function i(t){let{children:e}=t,[n,i]=(0,u.useState)([]),[c,f]=(0,u.useState)(null),[d,h]=(0,u.useState)([]),[g,m]=(0,u.useState)(!1),[b,y]=(0,u.useState)(null),[p,j]=(0,u.useState)(!1),[w,S]=(0,u.useState)(""),C=(0,u.useRef)(0),[v,k]=(0,u.useState)(null),[E,I]=(0,u.useState)(""),P=(0,u.useRef)(0),T=(0,s.l)(),J=(0,o.R)(),N=(0,a.usePathname)(),x="/journal"===N||!!(null==N?void 0:N.startsWith("/journal/")),O=(0,u.useRef)(0),_=(0,u.useCallback)(async()=>{try{f(null);let t=await fetch("/api/journal",{cache:"no-store"});if(!t.ok){f("Failed to load entries (HTTP ".concat(t.status,")"));return}let e=await t.json();return i(e.entries),e.entries}catch(t){f("Failed to load entries: ".concat(String(t)))}},[]),R=(0,u.useCallback)(async t=>{let e;let n=++C.current;y(t),j(!1),m(!1),k(null),O.current+=1,T.reset(),T.setEntryId(t),S("");try{e=await fetch("/api/journal/".concat(t),{cache:"no-store"})}catch(t){return}if(n!==C.current||!e.ok)return;let r=await e.json();n===C.current&&S(r.content)},[T]),q=(0,u.useCallback)(async t=>{let e;let n=++P.current;k(t),I("");try{e=await fetch("/api/journal/trash/".concat(t),{cache:"no-store"})}catch(t){return}if(n!==P.current||!e.ok)return;let r=await e.json();n===P.current&&I(r.content)},[]),H=(0,u.useCallback)(async()=>{try{f(null);let t=await fetch("/api/journal/trash",{cache:"no-store"});if(!t.ok){f("Failed to load trash (HTTP ".concat(t.status,")"));return}let e=await t.json();h(e.entries)}catch(t){f("Failed to load trash: ".concat(String(t)))}},[]);(0,u.useEffect)(()=>{x&&_()},[_,x]),(0,u.useEffect)(()=>{let t=T.turns.length>0||null!==J.jobId,e=null===b&&!p&&null===v;t&&e&&j(!0)},[T.turns.length,J.jobId,b,p,v]);let D=(0,u.useCallback)(()=>{y(null),j(!1),k(null),T.setEntryId(null)},[T]),L=(0,u.useCallback)(()=>{y(null),k(null),m(!1),O.current+=1,T.reset(),j(!0)},[T]),M=(0,u.useCallback)(async t=>{try{let e=await fetch("/api/journal/".concat(t),{method:"DELETE"});if(!e.ok){f("Delete failed (HTTP ".concat(e.status,")"));return}y(e=>e===t?null:e),await _()}catch(t){f("Delete failed: ".concat(String(t)))}},[_]),A=(0,u.useCallback)(async t=>{try{let e=await fetch("/api/journal/".concat(t,"/restore"),{method:"POST"});if(!e.ok){f("Restore failed (HTTP ".concat(e.status,")"));return}k(e=>e===t?null:e),await Promise.all([_(),H()])}catch(t){f("Restore failed: ".concat(String(t)))}},[_,H]),F=(0,u.useCallback)(async t=>{try{let e=await fetch("/api/journal/".concat(t,"?purge=true"),{method:"DELETE"});if(!e.ok){f("Permanent delete failed (HTTP ".concat(e.status,")"));return}k(e=>e===t?null:e),await H()}catch(t){f("Permanent delete failed: ".concat(String(t)))}},[H]),B=(0,u.useCallback)(()=>{let t=!g;m(t),y(null),j(!1),k(null),O.current+=1,T.reset(),t&&H()},[g,H,T]),G=(0,u.useMemo)(()=>[...n].sort((t,e)=>e.id.localeCompare(t.id)),[n]),$=G.find(t=>t.id===b),W=d.find(t=>t.id===v),Y=null!==b||p||null!==v,z=(0,u.useMemo)(()=>({entries:n,sortedEntries:G,entriesError:c,trash:d,showTrash:g,selected:b,composing:p,trashPreview:v,content:w,trashContent:E,panelOpen:Y,selectedMeta:$,trashMeta:W,viewEpoch:O,loadDates:_,loadEntry:R,loadTrashEntry:q,loadTrash:H,deleteEntry:M,restoreEntry:A,purgeEntry:F,toggleTrash:B,startCompose:L,closePanel:D}),[n,G,c,d,g,b,p,v,w,E,Y,$,W,_,R,q,H,M,A,F,B,L,D]);return(0,r.jsx)(l.Provider,{value:z,children:e})}function c(){let t=(0,u.useContext)(l);if(!t)throw Error("useJournalNav must be used inside <JournalNavProvider>");return t}},30641:function(t,e,n){n.d(e,{GL:function(){return l},ML:function(){return i}});let r="**You:**",a="**AI:**",u=[r,a].map(t=>[t,t.replaceAll("*","\\*")]);function o(t){return t.split("\n").map(t=>{let e=u.find(e=>{let[n]=e;return t.trim()===n});return e?t.replace(e[0],e[1]):t}).join("\n")}function s(t){return t.map(t=>{let e=u.find(e=>{let[,n]=e;return t.trim()===n});return e?t.replace(e[1],e[0]):t}).join("\n")}function l(t,e){return"".concat(r,"\n\n").concat(o(t),"\n\n").concat(a,"\n\n").concat(o(e))}function i(t){let e=t.split("\n"),n=e.flatMap((t,e)=>t.trim()===r?[e]:[]);return 0===n.length?null:{preamble:e.slice(0,n[0]).join("\n").trim(),turns:n.map((t,r)=>{let u=r+1<n.length?n[r+1]:e.length,o=e.slice(t+1,u),l=o.findIndex(t=>t.trim()===a),i=s(-1===l?o:o.slice(0,l)),c=-1===l?"":s(o.slice(l+1));return{question:i.trim(),answer:c.trim().replace(/\n*-{3,}$/,"").trim()}})}}}}]);
@@ -0,0 +1 @@
1
+ "use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[9095],{20580:function(e,t,n){n.d(t,{Qq:function(){return i},Tw:function(){return u},XH:function(){return s},h0:function(){return o},jG:function(){return l}});var r=n(57437);function a(e){let{size:t=14,children:n}=e;return(0,r.jsx)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:n})}function l(e){return(0,r.jsxs)(a,{...e,children:[(0,r.jsx)("path",{d:"M8 3v3a2 2 0 0 1-2 2H3"}),(0,r.jsx)("path",{d:"M21 8h-3a2 2 0 0 1-2-2V3"}),(0,r.jsx)("path",{d:"M3 16h3a2 2 0 0 1 2 2v3"}),(0,r.jsx)("path",{d:"M16 21v-3a2 2 0 0 1 2-2h3"})]})}function i(e){return(0,r.jsxs)(a,{...e,children:[(0,r.jsx)("path",{d:"M15 3h6v6"}),(0,r.jsx)("path",{d:"M9 21H3v-6"}),(0,r.jsx)("path",{d:"M21 3l-7 7"}),(0,r.jsx)("path",{d:"M3 21l7-7"})]})}function u(e){return(0,r.jsxs)(a,{...e,children:[(0,r.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,r.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function s(e){let{size:t=14}=e;return(0,r.jsxs)(a,{size:t,children:[(0,r.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,r.jsx)("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}),(0,r.jsx)("line",{x1:"10",y1:"11",x2:"10",y2:"17"}),(0,r.jsx)("line",{x1:"14",y1:"11",x2:"14",y2:"17"})]})}function o(e){let{size:t=12}=e;return(0,r.jsxs)(a,{size:t,children:[(0,r.jsx)("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),(0,r.jsx)("polyline",{points:"15 3 21 3 21 9"}),(0,r.jsx)("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})}},70812:function(e,t,n){n.d(t,{W:function(){return j}});var r=n(57437),a=n(83922),l=n(67608),i=n(58843),u=n(2265),s=n(62869);async function o(e){let t=new FormData;t.append("file",e);let n=await fetch("/api/images/upload",{method:"POST",body:t}),r=await n.json();if(!n.ok||!r.url||!r.path){var a;throw Error(null!==(a=r.error)&&void 0!==a?a:"Upload failed, please try again")}return{url:r.url,path:r.path}}async function c(e){let t=await Promise.allSettled(e.map(o)),n=[],r=null;for(let e of t)"fulfilled"===e.status?n.push(e.value):null===r&&(r=e.reason instanceof Error?e.reason.message:"Upload failed, please try again");return{attachments:n,error:r}}function d(e){let{onAttach:t,disabled:n,onUploadingChange:a}=e,l=(0,u.useRef)(null),[i,s]=(0,u.useState)(null),[o,d]=(0,u.useState)(!1);function f(e){d(e),null==a||a(e)}async function h(e){var n;let r=Array.from(null!==(n=e.target.files)&&void 0!==n?n:[]);if(0===r.length)return;s(null),f(!0);let{attachments:a,error:i}=await c(r);a.forEach(e=>t(e)),s(i),f(!1),l.current&&(l.current.value="")}return(0,r.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,r.jsx)("input",{ref:l,type:"file",accept:"image/jpeg,image/png,image/gif,image/webp",multiple:!0,className:"hidden",onChange:h}),(0,r.jsx)("button",{type:"button","aria-label":"Attach image",disabled:n||o,onClick:()=>{var e;return null===(e=l.current)||void 0===e?void 0:e.click()},className:"flex h-8 w-8 items-center justify-center rounded-md border bg-background text-sm font-medium hover:bg-accent disabled:opacity-50",children:o?"…":"+"}),i&&(0,r.jsx)("p",{className:"text-xs text-destructive",children:i})]})}var f=n(54891);function h(e){let{image:t,onRemove:n,index:a}=e;return(0,r.jsxs)("div",{className:"relative inline-block",children:[(0,r.jsx)("img",{src:t.url,alt:"Attached image","aria-label":"Attached image",className:"h-16 w-16 rounded-md border object-cover"}),(0,r.jsx)("button",{type:"button","aria-label":void 0===a?"Remove attached image":"Remove attached image ".concat(a+1),onClick:n,className:"absolute -right-1 -top-1 flex h-4 w-4 items-center justify-center rounded-full bg-destructive text-[10px] text-destructive-foreground",children:(0,r.jsx)(f.Z,{"aria-hidden":!0,className:"h-3 w-3"})})]})}var m=n(31623),p=n(40704);async function g(e){let t=new FormData;t.append("file",e);let n=await fetch("/api/attachments/upload",{method:"POST",body:t}),r=await n.json();if(!n.ok||!r.url||!r.path||!r.name){var a;throw Error(null!==(a=r.error)&&void 0!==a?a:"Upload failed, please try again")}return{url:r.url,path:r.path,name:r.name}}function v(e){let{onAttachImage:t,onInsertFile:n,disabled:a,onUploadingChange:l}=e,i=(0,u.useRef)(null),s=(0,u.useRef)(null),o=(0,u.useRef)(null),[d,f]=(0,u.useState)(!1),[h,v]=(0,u.useState)(!1);function x(e){v(e),null==l||l(e)}let[b,y]=(0,u.useState)(null);async function j(e){var n;let r=Array.from(null!==(n=e.target.files)&&void 0!==n?n:[]);if(0===r.length)return;y(null),x(!0);let{attachments:a,error:l}=await c(r);a.forEach(e=>t(e)),y(l),x(!1),i.current&&(i.current.value="")}async function w(e){var t;let r=null===(t=e.target.files)||void 0===t?void 0:t[0];if(r){y(null),x(!0);try{let e=await g(r);n("[".concat(e.name,"](").concat(e.url,")"))}catch(e){y(e instanceof Error?e.message:"Upload failed, please try again")}finally{x(!1),s.current&&(s.current.value="")}}}return(0,u.useEffect)(()=>{if(d)return document.addEventListener("mousedown",e),document.addEventListener("keydown",t),()=>{document.removeEventListener("mousedown",e),document.removeEventListener("keydown",t)};function e(e){o.current&&!o.current.contains(e.target)&&f(!1)}function t(e){"Escape"===e.key&&f(!1)}},[d]),(0,r.jsxs)("div",{ref:o,className:"relative flex flex-col gap-1",children:[(0,r.jsx)("input",{ref:i,type:"file",accept:"image/jpeg,image/png,image/gif,image/webp",multiple:!0,className:"hidden",onChange:j}),(0,r.jsx)("input",{ref:s,type:"file",accept:".pdf,.csv,.txt,.md",className:"hidden",onChange:w}),(0,r.jsx)("button",{type:"button","aria-label":"Attach","aria-haspopup":"menu","aria-expanded":d,disabled:a||h,onClick:()=>f(e=>!e),className:"flex h-8 w-8 items-center justify-center rounded-md border bg-background text-sm font-medium hover:bg-accent disabled:opacity-50",children:h?"…":"+"}),d&&(0,r.jsxs)("div",{role:"menu",className:"absolute bottom-full left-0 z-10 mb-1 min-w-[10rem] overflow-hidden rounded-md border bg-popover py-1 text-sm shadow-md",children:[(0,r.jsxs)("button",{type:"button",role:"menuitem",onClick:()=>{var e;f(!1),null===(e=i.current)||void 0===e||e.click()},className:"flex w-full items-center gap-2 px-3 py-1.5 text-left hover:bg-accent",children:[(0,r.jsx)(m.Z,{"aria-hidden":!0,className:"h-4 w-4"}),"Insert image"]}),(0,r.jsxs)("button",{type:"button",role:"menuitem",onClick:()=>{var e;f(!1),null===(e=s.current)||void 0===e||e.click()},className:"flex w-full items-center gap-2 px-3 py-1.5 text-left hover:bg-accent",children:[(0,r.jsx)(p.Z,{"aria-hidden":!0,className:"h-4 w-4"}),"Attach file"]})]}),b&&(0,r.jsx)("p",{className:"text-xs text-destructive",children:b})]})}function x(e){let{attachedImages:t,onAttach:n,onRemove:a,disabled:l,isDragging:i,onInsertFile:u,onUploadingChange:s}=e;return(0,r.jsxs)("div",{className:"flex items-center gap-2 ".concat(i?"ring-2 ring-primary rounded-md":""),children:[u?(0,r.jsx)(v,{onAttachImage:n,onInsertFile:u,disabled:l,onUploadingChange:s}):(0,r.jsx)(d,{onAttach:n,disabled:l,onUploadingChange:s}),t.map((e,n)=>(0,r.jsx)(h,{image:e,index:t.length>1?n:void 0,onRemove:()=>a(n)},e.path))]})}var b=n(94508);function y(e){e.style.height="auto";let t=Math.min(Math.max(e.scrollHeight,40),200);e.style.height="".concat(t,"px"),e.style.overflowY=e.scrollHeight>200?"auto":"hidden"}function j(e){let{input:t,setInput:n,busy:o,supportsMic:d,listening:f,onToggleMic:h,onSend:m,onCancel:p,onHistoryKeyDown:g,searchHistory:v=!1,onToggleSearchHistory:j,placeholder:w="Ask about today's briefing…",sendLabel:k="Send",cancelLabel:N="Cancel"}=e,E=(0,u.useRef)(!1),C=(0,u.useRef)(null),{images:R,attach:S,remove:A,take:L,error:M,isDragging:z,uploading:D,onPickerUploadingChange:T}=function(e){let[t,n]=(0,u.useState)([]),r=(0,u.useRef)([]),[a,l]=(0,u.useState)(null),[i,s]=(0,u.useState)(!1),o=(0,u.useCallback)(e=>{r.current=e,n(e)},[]),d=(0,u.useCallback)(e=>{if(r.current.length>=5){l("Up to ".concat(5," images per message"));return}o([...r.current,e])},[o]),f=(0,u.useCallback)(e=>o(r.current.filter((t,n)=>n!==e)),[o]),h=(0,u.useCallback)(()=>{let e=r.current.map(e=>e.path);return o([]),l(null),e},[o]),{isDragging:m,dropping:p}=function(e,t){let[n,r]=(0,u.useState)(!1),[a,l]=(0,u.useState)(!1),i=(0,u.useRef)(0),s=(0,u.useRef)(t);return s.current=t,(0,u.useEffect)(()=>{function t(e){var t,n;return null!==(n=null===(t=e.dataTransfer)||void 0===t?void 0:t.types.includes("Files"))&&void 0!==n&&n}function n(t){let n=e.current;return!!n&&t.target instanceof Node&&n.contains(t.target)}function a(e){t(e)&&(e.preventDefault(),r(n(e)))}function u(e){e.relatedTarget||r(!1)}async function o(e){var a,u;if(!t(e)||(e.preventDefault(),r(!1),!n(e)))return;let o=Array.from(null!==(u=null===(a=e.dataTransfer)||void 0===a?void 0:a.files)&&void 0!==u?u:[]).filter(e=>e.type.startsWith("image/"));if(0===o.length)return;i.current++,l(!0);let{attachments:d}=await c(o);d.forEach(e=>s.current(e)),0==--i.current&&l(!1)}return document.addEventListener("dragover",a),document.addEventListener("dragleave",u),document.addEventListener("drop",o),()=>{document.removeEventListener("dragover",a),document.removeEventListener("dragleave",u),document.removeEventListener("drop",o)}},[e]),{isDragging:n,dropping:a}}(e,d),{pasting:g}=function(e,t,n){let[r,a]=(0,u.useState)(!1),l=(0,u.useRef)(t);l.current=t;let i=(0,u.useRef)(n);i.current=n;let s=(0,u.useRef)(0);return(0,u.useEffect)(()=>{async function t(t){var n,r;let u=e.current;if(!u||!(t.target instanceof Node)||!u.contains(t.target))return;let o=Array.from(null!==(r=null===(n=t.clipboardData)||void 0===n?void 0:n.files)&&void 0!==r?r:[]).filter(e=>e.type.startsWith("image/"));if(0===o.length)return;s.current++,a(!0),i.current(null);let{attachments:d,error:f}=await c(o);d.forEach(e=>l.current(e)),null!==f&&i.current(f),0==--s.current&&a(!1)}return document.addEventListener("paste",t),()=>document.removeEventListener("paste",t)},[e]),{pasting:r}}(e,d,l);return{images:t,attach:d,remove:f,take:h,error:a,isDragging:m,uploading:g||p||i,onPickerUploadingChange:s}}(C);function H(){0===t.trim().length||D||m(L())}return(0,u.useEffect)(()=>{C.current&&y(C.current)},[t]),(0,r.jsxs)("div",{className:"mx-auto w-full max-w-3xl px-1",children:[(0,r.jsxs)("div",{className:(0,b.cn)("rounded-3xl border bg-card shadow-sm",z&&"ring-2 ring-primary"),children:[(0,r.jsx)("div",{className:"px-3 pt-3",children:(0,r.jsx)("textarea",{ref:C,"aria-label":"Chat message",value:t,onChange:e=>{n(e.target.value),y(e.target)},onCompositionStart:()=>{E.current=!0},onCompositionEnd:()=>{E.current=!1},onKeyDown:e=>{if(!E.current&&!e.nativeEvent.isComposing){if("Enter"===e.key&&!e.shiftKey){e.preventDefault(),H();return}null==g||g(e)}},placeholder:w,rows:2,className:"w-full resize-none overflow-hidden bg-transparent px-1 text-sm outline-none placeholder:text-muted-foreground","data-testid":"chat-input"})}),(0,r.jsxs)("div",{className:"flex items-center gap-1 px-2 pb-2",children:[(0,r.jsx)(x,{attachedImages:R,onAttach:S,onRemove:A,onUploadingChange:T,disabled:o,isDragging:z,onInsertFile:e=>n(function(e,t,n){var r,a;if(!e)return t+n;let l=e.value,i=null!==(r=e.selectionStart)&&void 0!==r?r:l.length,u=null!==(a=e.selectionEnd)&&void 0!==a?a:l.length,s=l.slice(0,i)+n+l.slice(u),o=i+n.length;return requestAnimationFrame(()=>{e.focus(),e.setSelectionRange(o,o)}),s}(C.current,t,e))}),d&&(0,r.jsx)(s.z,{type:"button",variant:f?"destructive":"ghost",size:"icon",className:"rounded-full",onClick:()=>h(t),"data-testid":"mic-button","aria-label":f?"音声入力停止":"音声入力開始","aria-pressed":f,title:f?"音声入力停止":"音声入力開始 (ja-JP)",children:f?(0,r.jsx)(a.Z,{"aria-hidden":!0,className:"h-4 w-4"}):(0,r.jsx)(l.Z,{"aria-hidden":!0,className:"h-4 w-4"})}),j&&(0,r.jsxs)("label",{className:"flex items-center gap-1.5 text-xs text-muted-foreground",children:[(0,r.jsx)("input",{type:"checkbox",checked:v,onChange:e=>j(e.target.checked),disabled:o,"data-testid":"search-history-toggle"}),"過去ブリーフィングを検索"]}),(0,r.jsx)("div",{className:"flex-1"}),o?(0,r.jsx)(s.z,{type:"button",variant:"destructive",className:"rounded-full",onClick:p,"data-testid":"cancel-button",title:"送信中の応答を中止 (Esc)",children:N}):(0,r.jsx)(s.z,{onClick:H,disabled:0===t.trim().length||D,"data-testid":"send-button",size:"icon",className:"shrink-0 rounded-full","aria-label":k,children:(0,r.jsx)(i.Z,{"aria-hidden":!0,className:"h-4 w-4"})})]})]}),M&&(0,r.jsx)("p",{className:"px-2 pt-2 text-xs text-destructive",role:"alert","data-testid":"attach-error",children:M}),!d&&(0,r.jsx)("p",{className:"px-2 pt-2 text-xs text-muted-foreground","data-testid":"mic-unsupported",children:"Voice input is unavailable in this browser (Chrome / Edge supported)."})]})}},62869:function(e,t,n){n.d(t,{z:function(){return o}});var r=n(57437),a=n(2265),l=n(37053),i=n(90535),u=n(94508);let s=(0,i.j)("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground shadow hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),o=a.forwardRef((e,t)=>{let{className:n,variant:a,size:i,asChild:o=!1,...c}=e,d=o?l.g7:"button";return(0,r.jsx)(d,{className:(0,u.cn)(s({variant:a,size:i,className:n})),ref:t,...c})});o.displayName="Button"},53819:function(e,t,n){n.d(t,{x:function(){return l}});var r=n(57437),a=n(94508);function l(e){let{label:t="Thinking",className:n,...l}=e;return(0,r.jsxs)("span",{role:"status","aria-label":t||"loading",className:(0,a.cn)("inline-flex items-center gap-1.5 text-current",n),...l,children:[t&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:t}),(0,r.jsxs)("span",{className:"inline-flex items-end gap-1",children:[(0,r.jsx)("span",{className:"h-1.5 w-1.5 animate-bounce rounded-full bg-current opacity-70 [animation-delay:-0.3s]"}),(0,r.jsx)("span",{className:"h-1.5 w-1.5 animate-bounce rounded-full bg-current opacity-70 [animation-delay:-0.15s]"}),(0,r.jsx)("span",{className:"h-1.5 w-1.5 animate-bounce rounded-full bg-current opacity-70"})]})]})}},54367:function(e,t,n){n.d(t,{fO:function(){return h},od:function(){return m},zC:function(){return f}});var r,a,l,i,u,s,o=n(94428),c=n(46882);function d(){let e=new Map;return t=>{var n;let r=t.toLowerCase().replace(/[\s]+/g,"-").replace(/["'`()[\]{}<>()「」、。,.!?!?::;;/\\|#*~]/g,""),a=null!==(n=e.get(r))&&void 0!==n?n:0;return e.set(r,a+1),0===a?r:"".concat(r,"-").concat(a)}}function f(){return e=>{let t=d();(0,c.Vn)(e,"element",e=>{/^h[1-3]$/.test(e.tagName)&&(e.properties={...e.properties,id:t(function e(t){return"text"===t.type?t.value:"children"in t?t.children.map(e).join(""):""}(e))})})}}let h={...o.R,clobberPrefix:"",attributes:{...o.R.attributes,h1:[...null!==(i=null===(r=o.R.attributes)||void 0===r?void 0:r.h1)&&void 0!==i?i:[],"id"],h2:[...null!==(u=null===(a=o.R.attributes)||void 0===a?void 0:a.h2)&&void 0!==u?u:[],"id"],h3:[...null!==(s=null===(l=o.R.attributes)||void 0===l?void 0:l.h3)&&void 0!==s?s:[],"id"]}};function m(e){let t=d(),n=[];for(let r of e.split("\n")){let e=r.match(/^(#{1,3})\s+(.+)/);if(!e)continue;let a=e[2].trim();n.push({id:t(a),text:a,level:e[1].length})}return n}},33525:function(e,t,n){n.d(t,{h:function(){return a}});var r=n(2265);function a(e){let{followFromStart:t=!0,followOnNewUserMessage:n=!0}=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},a=(0,r.useRef)(null),l=(0,r.useRef)(t),i=(0,r.useRef)(0),u=(0,r.useCallback)(()=>{let e=a.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight;l.current=t<=40},[]),s=(0,r.useCallback)(()=>{l.current=!0;let e=a.current;e&&(e.scrollTop=e.scrollHeight)},[]),o=(0,r.useCallback)(()=>{l.current=!1},[]);return(0,r.useLayoutEffect)(()=>{let t=e.filter(e=>"user"===e.role).length;n&&t>i.current&&(l.current=!0),i.current=t;let r=a.current;r&&l.current&&(r.scrollTop=r.scrollHeight)},[e,n]),{ref:a,onScroll:u,follow:s,stopFollowing:o}}},14092:function(e,t,n){n.d(t,{x:function(){return l}});var r=n(2265);function a(){var e,t;let n=window;return null!==(t=null!==(e=n.SpeechRecognition)&&void 0!==e?e:n.webkitSpeechRecognition)&&void 0!==t?t:null}function l(e){let{onTranscript:t,lang:n="ja-JP"}=e,[l,i]=(0,r.useState)(!1),[u,s]=(0,r.useState)(!1),o=(0,r.useRef)(null),c=(0,r.useRef)(""),d=(0,r.useRef)(!0),f=(0,r.useRef)(t);f.current=t,(0,r.useEffect)(()=>(d.current=!0,i(null!==a()),()=>{var e;d.current=!1,null===(e=o.current)||void 0===e||e.stop()}),[]);let h=(0,r.useCallback)(e=>{if(u){var t;null===(t=o.current)||void 0===t||t.stop();return}let r=a();if(!r)return;let l=new r;l.lang=n,l.continuous=!0,l.interimResults=!0,c.current=e,l.onresult=e=>{if(o.current!==l)return;let t="";for(let n=0;n<e.results.length;n++)t+=e.results[n][0].transcript;let n=c.current,r=n&&!/\s$/.test(n)?" ":"";f.current(n+r+t)};let i=()=>{o.current===l&&(d.current&&s(!1),o.current=null,c.current="")};l.onend=i,l.onerror=i,o.current=l,l.start(),s(!0)},[n,u]);return{supportsMic:l,listening:u,toggle:h,stop:(0,r.useCallback)(()=>{let e=o.current;e&&(o.current=null,c.current="",s(!1),e.stop())},[])}}},22384:function(e,t,n){function r(e){let t;let n=[],r=e;for(;-1!==(t=r.indexOf("\n\n"));){let e=a(r.slice(0,t));r=r.slice(t+2),null!==e&&n.push(e)}return{events:n,rest:r}}function a(e){let t="message",n=[];for(let r of e.split("\n"))r.startsWith("event:")?t=r.slice(6).replace(/^ /,""):r.startsWith("data:")&&n.push(r.slice(5).replace(/^ /,""));return 0===n.length&&"message"===t?null:{type:t,data:n.join("\n")}}function l(e,t){return e?"".concat(e,"\n").concat(t):t}async function*i(e,t){let n=e.getReader(),l=()=>void n.cancel().catch(()=>{});null==t||t.addEventListener("abort",l,{once:!0});let i=new TextDecoder,u="";try{for(;;){let e;try{e=await n.read()}catch(e){if((null==t?void 0:t.aborted)&&e instanceof DOMException&&"AbortError"===e.name)return;throw e}if(e.done)break;u+=i.decode(e.value,{stream:!0});let{events:a,rest:l}=r(u);for(let e of(u=l,a))yield e}let e=a(u);null!==e&&(yield e)}finally{null==t||t.removeEventListener("abort",l)}}n.d(t,{Tg:function(){return r},bv:function(){return l},v$:function(){return i}})},94508:function(e,t,n){n.d(t,{E:function(){return i},_:function(){return u},cn:function(){return l}});var r=n(61994),a=n(53335);function l(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return(0,a.m6)((0,r.W)(t))}function i(e){let t=e.replace(/[\\/]+$/,"").split(/[\\/]/);return t[t.length-1]||e}function u(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Date,t=e.getFullYear(),n=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getDate()).padStart(2,"0");return"".concat(t,"-").concat(n,"-").concat(r)}}}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6535],{92126:function(e,t,n){Promise.resolve().then(n.bind(n,5642))},20580:function(e,t,n){"use strict";n.d(t,{Qq:function(){return s},Tw:function(){return o},XH:function(){return l},h0:function(){return c},jG:function(){return a}});var r=n(57437);function i(e){let{size:t=14,children:n}=e;return(0,r.jsx)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:n})}function a(e){return(0,r.jsxs)(i,{...e,children:[(0,r.jsx)("path",{d:"M8 3v3a2 2 0 0 1-2 2H3"}),(0,r.jsx)("path",{d:"M21 8h-3a2 2 0 0 1-2-2V3"}),(0,r.jsx)("path",{d:"M3 16h3a2 2 0 0 1 2 2v3"}),(0,r.jsx)("path",{d:"M16 21v-3a2 2 0 0 1 2-2h3"})]})}function s(e){return(0,r.jsxs)(i,{...e,children:[(0,r.jsx)("path",{d:"M15 3h6v6"}),(0,r.jsx)("path",{d:"M9 21H3v-6"}),(0,r.jsx)("path",{d:"M21 3l-7 7"}),(0,r.jsx)("path",{d:"M3 21l7-7"})]})}function o(e){return(0,r.jsxs)(i,{...e,children:[(0,r.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,r.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function l(e){let{size:t=14}=e;return(0,r.jsxs)(i,{size:t,children:[(0,r.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,r.jsx)("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}),(0,r.jsx)("line",{x1:"10",y1:"11",x2:"10",y2:"17"}),(0,r.jsx)("line",{x1:"14",y1:"11",x2:"14",y2:"17"})]})}function c(e){let{size:t=12}=e;return(0,r.jsxs)(i,{size:t,children:[(0,r.jsx)("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),(0,r.jsx)("polyline",{points:"15 3 21 3 21 9"}),(0,r.jsx)("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})}},5642:function(e,t,n){"use strict";n.d(t,{BriefingDashboard:function(){return w}});var r=n(57437),i=n(2265),a=n(90535),s=n(54891),o=n(94508);let l=(0,a.j)("pointer-events-auto flex items-start gap-3 rounded-md border px-4 py-3 shadow-lg",{variants:{variant:{success:"border-green-700 bg-green-600/70 text-white backdrop-blur-sm",error:"border-red-700 bg-red-600/70 text-white backdrop-blur-sm"}},defaultVariants:{variant:"success"}});function c(e){let{className:t,variant:n,onClose:i,children:a,role:c,...d}=e;return(0,r.jsxs)("div",{role:null!=c?c:"error"===n?"alert":"status",className:(0,o.cn)(l({variant:n}),t),...d,children:[(0,r.jsx)("div",{className:"flex-1 break-words text-sm",children:a}),i&&(0,r.jsx)("button",{type:"button","aria-label":"Close","data-testid":"toast-close",onClick:i,className:"rounded-sm opacity-80 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-white/60",children:(0,r.jsx)(s.Z,{className:"h-4 w-4"})})]})}function d(e){let{className:t,...n}=e;return(0,r.jsx)("div",{className:(0,o.cn)("pointer-events-none fixed left-1/2 top-4 z-50 flex w-full -translate-x-1/2 flex-col gap-2 px-4",t),...n})}function u(){let[e,t]=(0,i.useState)("idle"),[n,a]=(0,i.useState)(""),s=async()=>{t("running"),a("");try{var e,n;let r=await fetch("/api/archive",{method:"POST",cache:"no-store"}),i=await r.json().catch(()=>({}));if(!r.ok){t("error"),a(String(null!==(e=null==i?void 0:i.detail)&&void 0!==e?e:"HTTP ".concat(r.status)));return}t("done"),a(String(null!==(n=null==i?void 0:i.stdout)&&void 0!==n?n:"").trim()||"Archive complete.")}catch(e){t("error"),a(String(e))}},o=("done"===e||"error"===e)&&n;return(0,r.jsxs)("div",{className:"flex items-center gap-2 px-2 py-1",children:[(0,r.jsx)("button",{"data-testid":"archive-button",onClick:s,disabled:"running"===e,className:"rounded border px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground disabled:opacity-50",children:"running"===e?"Archiving…":"Archive last month"}),o&&(0,r.jsx)(d,{children:(0,r.jsx)(c,{"data-testid":"archive-message",variant:"error"===e?"error":"success",onClose:()=>{t("idle"),a("")},children:n})})]})}var x=n(10644),h=n(52115),f=n(20580);function p(e){let{file:t,selected:n,onOpen:i,onHover:a}=e;return(0,r.jsxs)("tr",{"data-testid":"briefing-row-".concat(t.name),tabIndex:0,"aria-selected":n,onClick:()=>i(t),onMouseEnter:()=>a(t),onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&(e.preventDefault(),i(t))},className:(0,o.cn)("group cursor-pointer border-b text-xs transition-colors last:border-0",n?"bg-accent font-medium text-accent-foreground":"hover:bg-accent/50"),children:[(0,r.jsx)("td",{className:"max-w-[160px] truncate px-3 py-2",title:t.name,children:t.name}),(0,r.jsx)("td",{className:"px-3 py-2",children:(0,h.C)(t.type)}),(0,r.jsx)("td",{className:"px-3 py-2 tabular-nums",children:t.date}),(0,r.jsx)("td",{className:"px-2 py-2",children:(0,r.jsx)("button",{"data-testid":"briefing-open-".concat(t.name),onClick:()=>i(t),"aria-label":"Open ".concat(t.name),className:"rounded p-0.5 text-muted-foreground opacity-0 transition-opacity hover:bg-accent hover:text-accent-foreground focus:opacity-100 group-hover:opacity-100",children:(0,r.jsx)(f.h0,{})})})]})}function g(e){let{onSearch:t,debounceMs:n=250}=e,[a,s]=(0,i.useState)(""),o=(0,i.useRef)(t);return o.current=t,(0,i.useEffect)(()=>{let e=setTimeout(()=>o.current(a.trim()),n);return()=>clearTimeout(e)},[a,n]),(0,r.jsxs)("div",{className:"relative flex items-center px-2 py-1",children:[(0,r.jsx)("input",{"data-testid":"briefing-search-input",type:"search",value:a,onChange:e=>s(e.target.value),placeholder:"Search name or content…","aria-label":"Search briefings",className:"w-full rounded border bg-background px-2 py-1 pr-7 text-xs focus:outline-none focus:ring-1 focus:ring-ring"}),a&&(0,r.jsx)("button",{"data-testid":"briefing-search-clear",onClick:()=>s(""),"aria-label":"Clear search",className:"absolute right-3 rounded p-0.5 text-muted-foreground hover:text-foreground",children:(0,r.jsx)(f.Tw,{})})]})}let m="__all__";function b(e){let{files:t,selected:n,onSelect:i}=e,a=function(e){let t=new Set,n=[];for(let r of e)t.has(r.type)||(t.add(r.type),n.push(r.type));return n}(t);return(0,r.jsx)("div",{"data-testid":"briefing-tabs",className:"flex gap-1 border-b px-2 py-1",children:[m,...a].map(e=>(0,r.jsx)("button",{"data-testid":"briefing-tab-".concat(e),onClick:()=>i(e),"aria-selected":n===e,className:(0,o.cn)("rounded px-3 py-1 text-xs transition-colors",n===e?"bg-accent font-medium text-accent-foreground":"text-muted-foreground hover:bg-accent/50"),children:e===m?"All":(0,h.C)(e)},e))})}var v=n(6970),j=n(46915),y=n(12886);function N(){var e;return null!==(e=new URLSearchParams(window.location.search).get("type"))&&void 0!==e?e:m}function w(){let{files:e,selected:t,content:n,loadingContent:a,listError:s,contentError:l,fetchContent:c,prefetch:d,close:h}=(0,j.N)(),[f,w]=(0,i.useState)(!1),{width:S,startResize:k}=(0,y.L)({storageKey:"ai-agent:briefing-list-width:v1",defaultWidth:288,minWidth:200,maxWidth:560}),[C,M]=(0,i.useState)(N),[T,_]=(0,i.useState)(""),[E,P]=(0,i.useState)(null),[R,z]=(0,i.useState)(!1),[H,D]=(0,i.useState)(null);(0,i.useEffect)(()=>{let e=new URL(window.location.href);C===m?e.searchParams.delete("type"):e.searchParams.set("type",C),window.history.replaceState(null,"",e.toString())},[C]),(0,i.useEffect)(()=>{if(""===T){P(null),z(!1),D(null);return}let e=!1;return z(!0),D(null),fetch("/api/briefing/search?q=".concat(encodeURIComponent(T)),{cache:"no-store"}).then(e=>e.ok?e.json():Promise.reject(Error("HTTP ".concat(e.status)))).then(t=>{e||P(t.files)}).catch(t=>{e||(P([]),D(String(t)))}).finally(()=>{e||z(!1)}),()=>{e=!0}},[T]);let O=(0,i.useMemo)(()=>(""!==T?null!=E?E:[]:null!=e?e:[]).filter(e=>C===m||e.type===C),[e,C,T,E]);return s?(0,r.jsxs)("p",{"data-testid":"briefing-error",className:"text-sm text-destructive",children:["Failed to load briefings: ",s]}):null===e?(0,r.jsx)("p",{"data-testid":"briefing-loading",className:"text-sm text-muted-foreground",children:"Loading briefings…"}):0===e.length?(0,r.jsx)("p",{"data-testid":"briefing-empty",className:"text-sm text-muted-foreground",children:"No briefing files found."}):(0,r.jsxs)("div",{"data-testid":"briefing-dashboard",className:"flex h-full",children:[(0,r.jsxs)("div",{"data-testid":"briefing-records-list",style:t&&!f?{width:S}:void 0,className:(0,o.cn)("relative flex-shrink-0 overflow-y-auto border-r",!(t&&!f)&&"flex-1",f&&"hidden"),children:[(0,r.jsx)(u,{}),(0,r.jsx)(g,{onSearch:_}),(0,r.jsx)(b,{files:e,selected:C,onSelect:M}),(0,r.jsxs)("table",{className:"w-full text-sm",children:[(0,r.jsx)("thead",{children:(0,r.jsxs)("tr",{className:"border-b bg-muted/50 text-left text-xs text-muted-foreground",children:[(0,r.jsx)("th",{className:"px-3 py-2",children:"Name"}),(0,r.jsx)("th",{className:"px-3 py-2",children:"Type"}),(0,r.jsx)("th",{className:"px-3 py-2",children:"Date"}),(0,r.jsx)("th",{className:"w-8 px-3 py-2"})]})}),(0,r.jsx)("tbody",{children:O.map(e=>(0,r.jsx)(p,{file:e,selected:(null==t?void 0:t.name)===e.name,onOpen:c,onHover:d},e.name))})]}),R&&(0,r.jsx)("p",{"data-testid":"briefing-search-loading",className:"px-3 py-2 text-xs text-muted-foreground",children:"Searching…"}),!R&&H&&(0,r.jsxs)("p",{"data-testid":"briefing-search-error",className:"px-3 py-2 text-xs text-destructive",children:["Search failed: ",H]}),!R&&!H&&0===O.length&&(0,r.jsx)("p",{"data-testid":"briefing-no-results",className:"px-3 py-2 text-xs text-muted-foreground",children:"No matching briefings."}),t&&!f&&(0,r.jsx)(v.O,{onPointerDown:k,ariaLabel:"Resize briefing list","data-testid":"briefing-list-resizer"})]}),t&&(0,r.jsx)("div",{className:"min-w-0 flex-1 overflow-hidden",children:(0,r.jsx)(x.Y,{file:t,content:n,loading:a,error:l,fullSize:f,onToggleFullSize:()=>w(e=>!e),onClose:()=>{w(!1),h()}})})]})}},54367:function(e,t,n){"use strict";n.d(t,{fO:function(){return h},od:function(){return f},zC:function(){return x}});var r,i,a,s,o,l,c=n(94428),d=n(46882);function u(){let e=new Map;return t=>{var n;let r=t.toLowerCase().replace(/[\s]+/g,"-").replace(/["'`()[\]{}<>()「」、。,.!?!?::;;/\\|#*~]/g,""),i=null!==(n=e.get(r))&&void 0!==n?n:0;return e.set(r,i+1),0===i?r:"".concat(r,"-").concat(i)}}function x(){return e=>{let t=u();(0,d.Vn)(e,"element",e=>{/^h[1-3]$/.test(e.tagName)&&(e.properties={...e.properties,id:t(function e(t){return"text"===t.type?t.value:"children"in t?t.children.map(e).join(""):""}(e))})})}}let h={...c.R,clobberPrefix:"",attributes:{...c.R.attributes,h1:[...null!==(s=null===(r=c.R.attributes)||void 0===r?void 0:r.h1)&&void 0!==s?s:[],"id"],h2:[...null!==(o=null===(i=c.R.attributes)||void 0===i?void 0:i.h2)&&void 0!==o?o:[],"id"],h3:[...null!==(l=null===(a=c.R.attributes)||void 0===a?void 0:a.h3)&&void 0!==l?l:[],"id"]}};function f(e){let t=u(),n=[];for(let r of e.split("\n")){let e=r.match(/^(#{1,3})\s+(.+)/);if(!e)continue;let i=e[2].trim();n.push({id:t(i),text:i,level:e[1].length})}return n}},94508:function(e,t,n){"use strict";n.d(t,{E:function(){return s},_:function(){return o},cn:function(){return a}});var r=n(61994),i=n(53335);function a(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return(0,i.m6)((0,r.W)(t))}function s(e){let t=e.replace(/[\\/]+$/,"").split(/[\\/]/);return t[t.length-1]||e}function o(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Date,t=e.getFullYear(),n=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getDate()).padStart(2,"0");return"".concat(t,"-").concat(n,"-").concat(r)}}},function(e){e.O(0,[6137,6892,4397,2971,2117,1744],function(){return e(e.s=92126)}),_N_E=e.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1069],{97627:function(e,t,r){Promise.resolve().then(r.bind(r,28787))},1618:function(e,t,r){"use strict";r.d(t,{v:function(){return s}});var n=r(57437),a=r(66070);function s(){return(0,n.jsx)(a.Zb,{children:(0,n.jsxs)(a.aY,{className:"space-y-2 pt-6 text-sm","data-testid":"session-expired",children:[(0,n.jsx)("p",{className:"font-medium text-destructive",children:"Session expired"}),(0,n.jsxs)("p",{className:"text-muted-foreground",children:["The bearer token in ",(0,n.jsx)("code",{className:"font-mono",children:"apps/web/.token"})," ","no longer matches"," ",(0,n.jsx)("code",{className:"font-mono",children:"~/.ai-agent/session-token"}),". Restart the dev server (",(0,n.jsx)("code",{className:"font-mono",children:"bin/serve.sh"}),") to mirror a fresh token and refresh this page."]})]})})}},28787:function(e,t,r){"use strict";r.d(t,{ChatSplitView:function(){return k}});var n=r(57437),a=r(2265),s=r(10644),o=r(70812),i=r(20200),l=r(78537),c=r(43713),u=r(62869),d=r(53819),f=r(33525),h=r(94508);let m=["半導体セクターの新着リスクは?","今日のブリーフィングを3行で要約して","先週の見立てで外したテーマは?"];function p(e){let{messages:t,busy:r,retrying:a,notionReady:s,notionState:o,onNotionSave:u,fill:p=!1,onSuggest:g}=e,{ref:v,onScroll:y}=(0,f.h)(t);return(0,n.jsx)("div",{ref:v,onScroll:y,className:(0,h.cn)("scrollbar-slim overflow-y-auto",p?"min-h-0 flex-1":"max-h-[70vh]"),"data-testid":"chat-log",children:(0,n.jsxs)("div",{className:"mx-auto flex w-full max-w-3xl flex-col gap-6 px-1 py-2",children:[0===t.length?(0,n.jsxs)("div",{className:"flex flex-col items-start gap-4 py-6",children:[(0,n.jsx)("p",{className:"text-sm text-muted-foreground",children:"Ask anything about today's briefing."}),g&&(0,n.jsx)("div",{className:"flex flex-wrap gap-2",children:m.map(e=>(0,n.jsx)("button",{type:"button",onClick:()=>g(e),className:"rounded-full border bg-card px-3 py-1.5 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground",children:e},e))})]}):t.map((e,a)=>"user"===e.role?(0,n.jsx)("div",{className:"max-w-[80%] self-end whitespace-pre-wrap rounded-2xl rounded-br-md bg-muted px-4 py-2.5 text-sm leading-relaxed","data-testid":"chat-msg-user",children:e.content},a):(0,n.jsxs)("div",{"data-testid":"chat-msg-assistant",children:[e.content?(0,n.jsx)("div",{className:"prose prose-sm max-w-none leading-7 dark:prose-invert",children:(0,n.jsx)(i.UG,{remarkPlugins:[c.Z],rehypePlugins:[l.Z],children:e.content})}):r&&a===t.length-1&&!e.cancelled?(0,n.jsx)(d.x,{label:"調査中","data-testid":"chat-thinking"}):null,e.error&&(0,n.jsx)("p",{className:"mt-2 text-xs text-destructive","data-testid":"chat-error",children:e.error}),e.cancelled&&(0,n.jsx)("p",{className:"mt-2 text-xs text-muted-foreground","data-testid":"chat-cancelled",children:"Cancelled"}),e.content&&!e.error&&!e.cancelled&&(0,n.jsx)(x,{state:o[a],enabled:s&&!(r&&a===t.length-1),onSave:()=>u(a)})]},a)),a&&(0,n.jsx)("p",{className:"text-xs text-muted-foreground","data-testid":"chat-retrying",children:"Session expired upstream, retrying…"})]})})}function x(e){var t,r;let{state:a,enabled:s,onSave:o}=e,i=null!==(t=null==a?void 0:a.status)&&void 0!==t?t:"idle";return(0,n.jsxs)("div",{className:"mt-1 flex flex-wrap items-center gap-2 text-xs",children:[(0,n.jsx)(u.z,{type:"button",variant:"ghost",size:"sm",onClick:o,disabled:!s||"saving"===i||"saved"===i,title:s?void 0:"Notion 認証情報が未設定です(Credentials タブで設定してください)","data-testid":"notion-save-button",children:"saving"===i?"追記中…":"saved"===i?"✓ Notion に追記済":"error"===i?"追記を再試行":"Notion ブリーフィングに追記"}),"saved"===i&&(null==a?void 0:a.url)&&(0,n.jsx)("a",{href:a.url,target:"_blank",rel:"noreferrer",className:"text-primary underline","data-testid":"notion-save-link",children:"ページを開く"}),"saved"===i&&(null==a?void 0:a.localSaved)&&(0,n.jsx)("span",{className:"text-muted-foreground","data-testid":"local-save-note",children:"ローカル md にも追記済"}),"saved"===i&&(null==a?void 0:a.localSaved)===!1&&(0,n.jsxs)("span",{className:"text-destructive","data-testid":"local-save-error",children:["ローカル md への追記に失敗: ",null!==(r=a.localError)&&void 0!==r?r:"unknown error"]}),"error"===i&&(null==a?void 0:a.error)&&(0,n.jsx)("span",{className:"text-destructive","data-testid":"notion-save-error",children:a.error})]})}var g=r(1618),v=r(96215),y=r(56743),b=r(14092);function w(){let{fill:e=!1,onLocalSave:t}=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},{messages:r,setMessages:s,hydrated:i}=(0,y.R)(),l=(0,v.w)(),{draft:c,setDraft:u}=function(e){let{storageKey:t}=e,[r,n]=(0,a.useState)(""),[s,o]=(0,a.useState)(!1);return(0,a.useEffect)(()=>{try{var e;n(null!==(e=window.sessionStorage.getItem(t))&&void 0!==e?e:"")}catch(e){}o(!0)},[t]),(0,a.useEffect)(()=>{if(s)try{""===r?window.sessionStorage.removeItem(t):window.sessionStorage.setItem(t,r)}catch(e){}},[r,s,t]),{draft:r,setDraft:n,hydrated:s}}({storageKey:"ai-agent:chat-draft:v1"}),[d,f]=(0,a.useState)(!1),[m,x]=(0,a.useState)(!1),{notionReady:w}=function(){let[e,t]=(0,a.useState)(null);return(0,a.useEffect)(()=>{let e=!1;return fetch("/api/credentials",{cache:"no-store"}).then(e=>e.ok?e.json():null).then(r=>{e||t(null!=r?r:{})}).catch(()=>{}),()=>{e=!0}},[]),{notionReady:!!(e&&e.NOTION_API_KEY&&e.NOTION_DATABASE_ID),hydrated:null!==e}}(),{supportsMic:j,listening:N,toggle:S,stop:k}=(0,b.x)({onTranscript:u}),{notionState:E,saveToNotion:C}=function(e){let{messages:t,autoSave:r=!1,hydrated:n=!1,onLocalSave:s}=e,[o,i]=(0,a.useState)({}),l=(0,a.useRef)(!0),c=(0,a.useRef)(s);c.current=s,(0,a.useEffect)(()=>(l.current=!0,()=>{l.current=!1}),[]);let u=(0,a.useCallback)(async e=>{let r=t[e];if(!r||"assistant"!==r.role||!r.content)return;let n="";for(let r=e-1;r>=0;r--)if("user"===t[r].role){n=t[r].content;break}if(n){i(t=>({...t,[e]:{status:"saving"}}));try{let t=await fetch("/api/chat/notion-import",{method:"POST",cache:"no-store",headers:{"content-type":"application/json"},body:JSON.stringify({date:(0,h._)(),question:n,answer:r.content})});if(!t.ok){let r="HTTP ".concat(t.status);try{let e=await t.json();e.detail&&(r=e.detail)}catch(e){}if(!l.current)return;i(t=>({...t,[e]:{status:"error",error:r}}));return}let s=await t.json();if(!l.current)return;if(i(t=>{var r,n,a;return{...t,[e]:{status:"saved",url:s.url,localPath:null!==(r=s.local_path)&&void 0!==r?r:void 0,localSaved:null!==(n=s.local_saved)&&void 0!==n&&n,localError:null!==(a=s.local_error)&&void 0!==a?a:void 0}}}),s.local_saved&&s.local_path){var a;null===(a=c.current)||void 0===a||a.call(c,s.local_path)}}catch(t){if(!l.current)return;i(r=>({...r,[e]:{status:"error",error:t instanceof Error?t.message:"Network error"}}))}}},[t]),d=(0,a.useRef)(null),f=(0,a.useRef)(new Set);return(0,a.useEffect)(()=>{if(n){if(null===d.current){d.current=t.length;return}if(r)for(let e=d.current;e<t.length;e++){let r=t[e];"assistant"===r.role&&r.content&&!r.error&&!r.cancelled&&(f.current.has(e)||(f.current.add(e),u(e)))}}},[n,r,t,u]),{notionState:o,saveToNotion:u}}({messages:r,autoSave:w,hydrated:i,onLocalSave:t}),_=(0,a.useRef)(!1),R=(0,a.useMemo)(()=>r.filter(e=>"user"===e.role).map(e=>e.content),[r]),P=l.isBackgrounded,I=function(e){let{history:t,setInput:r,busy:n}=e,s=(0,a.useRef)(-1),o=(0,a.useRef)("");return(0,a.useEffect)(()=>{s.current=-1,o.current=""},[t.length]),(0,a.useCallback)(e=>{let a=e.currentTarget;if("ArrowUp"===e.key){if(0===t.length||a.value.slice(0,a.selectionStart).includes("\n"))return;e.preventDefault(),-1===s.current?(o.current=a.value,s.current=t.length-1):s.current>0&&(s.current-=1),r(t[s.current]);return}if("ArrowDown"===e.key){if(-1===s.current||a.value.slice(a.selectionEnd).includes("\n"))return;e.preventDefault(),s.current<t.length-1?(s.current+=1,r(t[s.current])):(r(o.current),s.current=-1,o.current="");return}if("Escape"===e.key){if(n||-1===s.current)return;e.preventDefault(),r(o.current),s.current=-1,o.current=""}},[t,r,n])}({history:R,setInput:u,busy:P}),T=(0,a.useMemo)(()=>(l.jobId||"pending"===l.status)&&l.question?[{role:"user",content:l.question},{role:"assistant",content:l.assistantContent,error:l.error}]:null,[l.jobId,l.status,l.question,l.assistantContent,l.error]),O=(0,a.useMemo)(()=>T?[...r,...T]:r,[r,T]),D=(0,a.useCallback)(function(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:[],t=c.trim();t&&!P&&(k(),u(""),f(!1),_.current=!1,l.startJob({question:t,date:(0,h._)(),...e.length>0?{image_paths:e}:{},...m?{search_history:!0}:{}}))},[P,l,c,m,u,k]),Z=(0,a.useCallback)(()=>{if(!P)return;let e=l.jobId,t=l.question,r=l.assistantContent;e&&fetch("/api/chat/".concat(e),{method:"DELETE",cache:"no-store"}),t&&(s(e=>[...e,{role:"user",content:t},{role:"assistant",content:r,cancelled:!0}]),u(t)),l.reset()},[P,l,u,s]);return((0,a.useEffect)(()=>{if(l.sessionExpired||"done"!==l.status&&"failed"!==l.status||!l.question)return;if(l.staleSession&&!_.current){_.current=!0;let{question:e,date:t,searchHistory:r,imagePaths:n=[]}=l;f(!0),l.reset(),l.startJob({question:e,date:t,...n.length>0?{image_paths:n}:{},...r?{search_history:!0}:{}}).finally(()=>{f(!1)});return}let e={role:"user",content:l.question},t={role:"assistant",content:l.assistantContent,error:l.error};s(r=>[...r,e,t]),l.reset()},[l.status,l.sessionExpired]),(0,a.useEffect)(()=>{if(P)return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e);function e(e){"Escape"===e.key&&(e.preventDefault(),Z())}},[P,Z]),l.sessionExpired)?(0,n.jsx)(g.v,{}):(0,n.jsxs)("div",{className:e?"flex h-full min-h-0 flex-col gap-4":"space-y-4",children:[(0,n.jsx)(p,{messages:O,busy:P,retrying:d,notionReady:w,notionState:E,onNotionSave:e=>void C(e),fill:e,onSuggest:u}),(0,n.jsx)(o.W,{input:c,setInput:u,busy:P,supportsMic:j,listening:N,onToggleMic:S,onSend:D,onCancel:Z,onHistoryKeyDown:I,searchHistory:m,onToggleSearchHistory:x})]})}var j=r(6970),N=r(46915),S=r(12886);function k(){var e;let{files:t,selected:r,content:s,loadingContent:o,listError:i,contentError:l,fetchContent:c,refreshContent:d}=(0,N.N)(),{width:f,startResize:m}=(0,S.L)({storageKey:"ai-agent:chat-split-width:v1",defaultWidth:480,minWidth:320,maxWidth:880,edge:"left"}),[p,x]=(0,a.useState)(!1),g=(0,a.useRef)(!1);return(0,a.useEffect)(()=>{g.current||null===t||0===t.length||(g.current=!0,c(t[0]))},[t,c]),(0,n.jsxs)("div",{className:"flex h-full min-h-0 flex-col",children:[(0,n.jsx)("div",{className:"flex justify-end pb-2 lg:hidden",children:(0,n.jsx)(u.z,{type:"button",variant:"outline",size:"sm","data-testid":"chat-doc-toggle",onClick:()=>x(e=>!e),children:p?"Back to Q&A":"Show document"})}),(0,n.jsxs)("div",{"data-testid":"chat-split-view",className:"flex min-h-0 flex-1",children:[(0,n.jsx)("div",{"data-testid":"chat-pane-qa",className:(0,h.cn)("flex min-h-0 min-w-0 flex-1 flex-col pr-0 lg:pr-4",p&&"hidden lg:flex"),children:(0,n.jsx)(w,{fill:!0,onLocalSave:e=>d((0,h.E)(e))})}),(0,n.jsxs)("div",{"data-testid":"chat-pane-doc",style:{"--doc-width":"".concat(f,"px")},className:(0,h.cn)("relative flex min-h-0 w-full min-w-0 flex-1 flex-col","lg:w-[length:var(--doc-width)] lg:flex-none",!p&&"hidden lg:flex"),children:[(0,n.jsx)(j.O,{onPointerDown:m,edge:"left",ariaLabel:"Resize document pane","data-testid":"chat-split-resizer",className:"hidden lg:block"}),(0,n.jsxs)("div",{className:"flex min-h-0 flex-1 flex-col overflow-hidden rounded-2xl border bg-card",children:[null!==t&&t.length>0&&(0,n.jsxs)("div",{className:"flex items-center gap-2 border-b px-3 py-2",children:[(0,n.jsx)("label",{htmlFor:"chat-doc-picker",className:"text-xs text-muted-foreground",children:"Document"}),(0,n.jsx)("select",{id:"chat-doc-picker","data-testid":"chat-doc-picker",value:null!==(e=null==r?void 0:r.name)&&void 0!==e?e:"",onChange:e=>{let r=t.find(t=>t.name===e.target.value);r&&c(r)},className:"min-w-0 flex-1 rounded border bg-background px-2 py-1 text-xs",children:t.map(e=>(0,n.jsx)("option",{value:e.name,children:e.name},e.name))})]}),(0,n.jsx)("div",{className:"min-h-0 flex-1 overflow-hidden",children:(0,n.jsx)(E,{listError:i,loadingList:null===t,selected:r,content:s,loadingContent:o,contentError:l})})]})]})]})]})}function E(e){let{listError:t,loadingList:r,selected:a,content:o,loadingContent:i,contentError:l}=e;return null!==t?(0,n.jsxs)("p",{"data-testid":"chat-doc-error",className:"p-4 text-sm text-destructive",children:["Failed to load documents: ",t]}):r?(0,n.jsx)("p",{"data-testid":"chat-doc-loading",className:"p-4 text-sm text-muted-foreground",children:"Loading documents…"}):null===a?(0,n.jsx)("p",{"data-testid":"chat-doc-empty",className:"p-4 text-sm text-muted-foreground",children:"No briefing document to show yet. Run a briefing, then pick it here to read it alongside the conversation."}):(0,n.jsx)(s.Y,{file:a,content:o,loading:i,error:l})}},66070:function(e,t,r){"use strict";r.d(t,{Ol:function(){return i},SZ:function(){return c},Zb:function(){return o},aY:function(){return u},eW:function(){return d},ll:function(){return l}});var n=r(57437),a=r(2265),s=r(94508);let o=a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,n.jsx)("div",{ref:t,className:(0,s.cn)("rounded-xl border bg-card text-card-foreground shadow",r),...a})});o.displayName="Card";let i=a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,n.jsx)("div",{ref:t,className:(0,s.cn)("flex flex-col space-y-1.5 p-6",r),...a})});i.displayName="CardHeader";let l=a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,n.jsx)("div",{ref:t,className:(0,s.cn)("font-semibold leading-none tracking-tight",r),...a})});l.displayName="CardTitle";let c=a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,n.jsx)("div",{ref:t,className:(0,s.cn)("text-sm text-muted-foreground",r),...a})});c.displayName="CardDescription";let u=a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,n.jsx)("div",{ref:t,className:(0,s.cn)("p-6 pt-0",r),...a})});u.displayName="CardContent";let d=a.forwardRef((e,t)=>{let{className:r,...a}=e;return(0,n.jsx)("div",{ref:t,className:(0,s.cn)("flex items-center p-6 pt-0",r),...a})});d.displayName="CardFooter"},96215:function(e,t,r){"use strict";r.d(t,{ChatJobStateProvider:function(){return u},w:function(){return d}});var n=r(57437),a=r(87411),s=r(22384);let o={jobId:null,status:"idle",question:"",date:"",searchHistory:!1,imagePaths:[],assistantContent:"",error:null,sessionExpired:!1,staleSession:!1},i=e=>"pending"===e||"running"===e,{Provider:l,useStore:c}=(0,a.U)({storageKey:"ai-agent:chat-job:v1",initialState:o,getJobId:e=>e.jobId,isInFlight:e=>i(e.status),isPersistable:e=>!!e.jobId&&i(e.status),serializeForStorage:e=>({...e,assistantContent:"",sessionExpired:!1,staleSession:!1}),start:async(e,t)=>{let{question:r,date:n,image_paths:a,search_history:s}=e,{setState:i}=t;i(()=>({...o,status:"pending",question:r,date:n,searchHistory:!!s,imagePaths:null!=a?a:[]}));try{let e=await fetch("/api/chat",{method:"POST",cache:"no-store",headers:{"content-type":"application/json"},body:JSON.stringify({date:n,question:r,...(null==a?void 0:a.length)?{image_paths:a}:{},...s?{search_history:!0}:{}})});if(401===e.status){i(()=>({...o,sessionExpired:!0}));return}if(!e.ok){let t=await e.text().catch(()=>"");i(r=>({...r,status:"failed",error:"POST /api/chat failed (HTTP ".concat(e.status,"): ").concat(t)}));return}let t=await e.json();if(!t.job_id){i(e=>({...e,status:"failed",error:"POST /api/chat returned no job_id"}));return}i(e=>{var r;return{...e,jobId:null!==(r=t.job_id)&&void 0!==r?r:null,status:"running"}})}catch(e){i(t=>({...t,status:"failed",error:e instanceof Error?e.message:"Network error"}))}},watch:async(e,t)=>{let r,{signal:n,setState:a}=t;a(e=>({...e,assistantContent:""}));try{r=await fetch("/api/chat/".concat(e,"/stream"),{method:"GET",cache:"no-store",signal:n})}catch(e){if(n.aborted)return;a(t=>({...t,status:"failed",error:e instanceof Error?e.message:"Network error"}));return}if(n.aborted)return;if(401===r.status){a(e=>({...e,sessionExpired:!0,status:"failed"}));return}if(404===r.status){a(()=>({...o,status:"failed",error:"The previous chat job is no longer available — please ask again."}));return}if(!r.ok||!r.body){let t=await r.text().catch(()=>"");a(n=>({...n,status:"failed",error:"GET /api/chat/".concat(e,"/stream failed (HTTP ").concat(r.status,"): ").concat(t)}));return}let i=r.body.getReader(),l=new TextDecoder,c="";try{for(;;){let{value:e,done:t}=await i.read();if(t)break;if(n.aborted)return;c+=l.decode(e,{stream:!0});let{events:r,rest:o}=(0,s.Tg)(c);for(let e of(c=o,r)){if(n.aborted)return;"message"===e.type?a(t=>({...t,assistantContent:(0,s.bv)(t.assistantContent,e.data)})):"stale_session"===e.type?a(e=>({...e,staleSession:!0})):"error"===e.type&&a(t=>({...t,error:e.data||"stream error"}))}}}catch(e){if(n.aborted)return;a(t=>({...t,status:"failed",error:e instanceof Error?e.message:"Stream read error"}));return}n.aborted||a(e=>({...e,status:e.error?"failed":"done"}))}});function u(e){let{children:t}=e;return(0,n.jsx)(l,{children:t})}function d(){return c()}},56743:function(e,t,r){"use strict";r.d(t,{ChatStateProvider:function(){return u},R:function(){return d}});var n=r(57437),a=r(2265);let s="ai-agent:chat-history:v1";function o(e){return e.length<=50?e:e.slice(e.length-50)}function i(e){return"object"==typeof e&&null!==e&&("user"===e.role||"assistant"===e.role)&&"string"==typeof e.content&&(void 0===e.error||null===e.error||"string"==typeof e.error)&&(void 0===e.cancelled||"boolean"==typeof e.cancelled)}function l(){try{window.sessionStorage.removeItem(s)}catch(e){}}let c=(0,a.createContext)(null);function u(e){let{children:t}=e,[r,u]=(0,a.useState)([]),[d,f]=(0,a.useState)(!1);(0,a.useEffect)(()=>{u(function(){try{let e=window.sessionStorage.getItem(s);if(!e)return[];let t=JSON.parse(e);if(!Array.isArray(t))return[];return o(t.filter(i))}catch(e){return[]}}()),f(!0)},[]),(0,a.useEffect)(()=>{d&&(0===r.length?l():function(e){try{window.sessionStorage.setItem(s,JSON.stringify(e))}catch(e){}}(r))},[r,d]);let h=(0,a.useCallback)(e=>{u(t=>o("function"==typeof e?e(t):e))},[]),m=(0,a.useCallback)(()=>{u([]),l()},[]),p=(0,a.useMemo)(()=>({messages:r,setMessages:h,reset:m,hydrated:d}),[r,h,m,d]);return(0,n.jsx)(c.Provider,{value:p,children:t})}function d(){let e=(0,a.useContext)(c);if(!e)throw Error("useChatState must be used inside <ChatStateProvider>");return e}},87411:function(e,t,r){"use strict";r.d(t,{U:function(){return o}});var n=r(57437),a=r(2265);function s(e){try{window.sessionStorage.removeItem(e)}catch(e){}}function o(e){let{storageKey:t,initialState:r,getJobId:o,isInFlight:i,isPersistable:l,isUnresumable:c=e=>i(e)&&null===o(e),serializeForStorage:u=e=>e,start:d,watch:f}=e,h=(0,a.createContext)(null);return{Provider:function(e){let{children:m}=e,[p,x]=(0,a.useState)(r),[g,v]=(0,a.useState)(!1);(0,a.useEffect)(()=>{x(function(e,t,r){try{let n=window.sessionStorage.getItem(e);if(!n)return t;let a=JSON.parse(n),s={...t,...a};if(r(s))return t;return s}catch(e){return t}}(t,r,c)),v(!0)},[]),(0,a.useEffect)(()=>{g&&(l(p)?function(e,t){try{window.sessionStorage.setItem(e,JSON.stringify(t))}catch(e){}}(t,u(p)):s(t))},[p,g]);let y=o(p),b=i(p);(0,a.useEffect)(()=>{if(!g||!y||!b)return;let e=new AbortController,t=!1,r=e=>{t||x(t=>o(t)!==y?t:e(t))};return(async()=>{try{await f(y,{signal:e.signal,setState:r})}catch(e){}})(),()=>{t=!0,e.abort()}},[g,y,b]);let w=(0,a.useCallback)(async e=>{await d(e,{setState:e=>{x(e)}})},[]),j=(0,a.useCallback)(()=>{x(r),s(t)},[]),N=(0,a.useMemo)(()=>({...p,isBackgrounded:b,startJob:w,reset:j}),[p,b,w,j]);return(0,n.jsx)(h.Provider,{value:N,children:m})},useStore:function(){let e=(0,a.useContext)(h);if(!e)throw Error("useStore must be used inside the Provider returned by createJobStoreProvider");return e}}}},98575:function(e,t,r){"use strict";r.d(t,{F:function(){return s},e:function(){return o}});var n=r(2265);function a(e,t){if("function"==typeof e)return e(t);null!=e&&(e.current=t)}function s(...e){return t=>{let r=!1,n=e.map(e=>{let n=a(e,t);return r||"function"!=typeof n||(r=!0),n});if(r)return()=>{for(let t=0;t<n.length;t++){let r=n[t];"function"==typeof r?r():a(e[t],null)}}}}function o(...e){return n.useCallback(s(...e),e)}},37053:function(e,t,r){"use strict";r.d(t,{g7:function(){return u}});var n,a=r(2265),s=r(98575),o=r(57437),i=Symbol.for("react.lazy"),l=(n||(n=r.t(a,2)))[" use ".trim().toString()];function c(e){var t;return null!=e&&"object"==typeof e&&"$$typeof"in e&&e.$$typeof===i&&"_payload"in e&&"object"==typeof(t=e._payload)&&null!==t&&"then"in t}var u=function(e){let t=function(e){let t=a.forwardRef((e,t)=>{let{children:r,...n}=e;if(c(r)&&"function"==typeof l&&(r=l(r._payload)),a.isValidElement(r)){var o;let e,i;let l=(o=r,(e=Object.getOwnPropertyDescriptor(o.props,"ref")?.get)&&"isReactWarning"in e&&e.isReactWarning?o.ref:(e=Object.getOwnPropertyDescriptor(o,"ref")?.get)&&"isReactWarning"in e&&e.isReactWarning?o.props.ref:o.props.ref||o.ref),c=function(e,t){let r={...t};for(let n in t){let a=e[n],s=t[n];/^on[A-Z]/.test(n)?a&&s?r[n]=(...e)=>{let t=s(...e);return a(...e),t}:a&&(r[n]=a):"style"===n?r[n]={...a,...s}:"className"===n&&(r[n]=[a,s].filter(Boolean).join(" "))}return{...e,...r}}(n,r.props);return r.type!==a.Fragment&&(c.ref=t?(0,s.F)(t,l):l),a.cloneElement(r,c)}return a.Children.count(r)>1?a.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}(e),r=a.forwardRef((e,r)=>{let{children:n,...s}=e;c(n)&&"function"==typeof l&&(n=l(n._payload));let i=a.Children.toArray(n),u=i.find(f);if(u){let e=u.props.children,n=i.map(t=>t!==u?t:a.Children.count(e)>1?a.Children.only(null):a.isValidElement(e)?e.props.children:null);return(0,o.jsx)(t,{...s,ref:r,children:a.isValidElement(e)?a.cloneElement(e,void 0,n):null})}return(0,o.jsx)(t,{...s,ref:r,children:n})});return r.displayName=`${e}.Slot`,r}("Slot"),d=Symbol("radix.slottable");function f(e){return a.isValidElement(e)&&"function"==typeof e.type&&"__radixId"in e.type&&e.type.__radixId===d}},58843:function(e,t,r){"use strict";r.d(t,{Z:function(){return n}});let n=(0,r(58135).Z)("arrow-up",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]])},31623:function(e,t,r){"use strict";r.d(t,{Z:function(){return n}});let n=(0,r(58135).Z)("image",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",ry:"2",key:"1m3agn"}],["circle",{cx:"9",cy:"9",r:"2",key:"af1f0g"}],["path",{d:"m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21",key:"1xmnt7"}]])},67608:function(e,t,r){"use strict";r.d(t,{Z:function(){return n}});let n=(0,r(58135).Z)("mic",[["path",{d:"M12 19v3",key:"npa21l"}],["path",{d:"M19 10v2a7 7 0 0 1-14 0v-2",key:"1vc78b"}],["rect",{x:"9",y:"2",width:"6",height:"13",rx:"3",key:"s6n7sd"}]])},40704:function(e,t,r){"use strict";r.d(t,{Z:function(){return n}});let n=(0,r(58135).Z)("paperclip",[["path",{d:"m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551",key:"1miecu"}]])},83922:function(e,t,r){"use strict";r.d(t,{Z:function(){return n}});let n=(0,r(58135).Z)("square",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}]])}},function(e){e.O(0,[6137,6892,9095,4397,2971,2117,1744],function(){return e(e.s=97627)}),_N_E=e.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[664],{39240:function(e,t,n){Promise.resolve().then(n.bind(n,95292))},95292:function(e,t,n){"use strict";n.d(t,{JournalScreen:function(){return j}});var s=n(57437),r=n(2265),l=n(20580),a=n(70812),o=n(53819),i=n(42648);function d(e){let{question:t,answer:n}=e;return(0,s.jsxs)("div",{className:"flex flex-col gap-4",children:[(0,s.jsx)("div",{className:"max-w-[80%] self-end rounded-2xl rounded-br-md bg-muted px-4 py-2.5 text-sm leading-relaxed","data-testid":"journal-turn-question",children:(0,s.jsx)(i.O,{content:t,breaks:!0})}),null===n?(0,s.jsx)(o.x,{label:"Thinking…","data-testid":"journal-chat-thinking"}):n&&(0,s.jsx)("div",{className:"leading-7","data-testid":"journal-turn-answer",children:(0,s.jsx)(i.O,{content:n})})]})}var c=n(90160),u=n(75408),x=n(5620),m=n(30641),h=n(33525),p=n(14092);function f(e){let t=e.match(/^\d{4}-\d{2}-\d{2}_(\d{2})(\d{2})(\d{2})/);return t?"".concat(t[1],":").concat(t[2],":").concat(t[3]):null}function g(e){let{md:t}=e,n=t.replace(/^\s*# [^\n]*\n+/,""),r=(0,m.ML)(n);return r?(0,s.jsxs)("div",{className:"flex flex-col gap-6",children:[r.preamble&&(0,s.jsx)(i.O,{content:r.preamble,breaks:!0}),r.turns.map((e,t)=>(0,s.jsx)(d,{question:e.question,answer:e.answer},t))]}):(0,s.jsx)(i.O,{content:n,breaks:!0})}function j(){var e,t;let{selected:n,composing:o,trashPreview:i,content:m,trashContent:j,panelOpen:v,selectedMeta:b,trashMeta:y,viewEpoch:w,closePanel:N,restoreEntry:k,purgeEntry:C}=(0,x.O)(),[S,_]=(0,r.useState)(""),{supportsMic:E,listening:O,toggle:I,stop:L}=(0,p.x)({onTranscript:_}),M=(0,u.l)(),q=(0,c.R)(),T="pending"===q.status||"running"===q.status,z=q.error,F=(0,r.useRef)(0),K=null!==q.jobId&&F.current===w.current,P=(0,r.useMemo)(()=>K?[...M.turns,{question:q.question,answer:q.assistantContent}]:M.turns,[K,M.turns,q.question,q.assistantContent]),R=(0,r.useMemo)(()=>P.flatMap(e=>[{role:"user",content:e.question},{role:"assistant",content:e.answer}]),[P]),{ref:Z,onScroll:D,follow:J,stopFollowing:A}=(0,h.h)(R,{followFromStart:!1,followOnNewUserMessage:!1});(0,r.useEffect)(()=>{A()},[n,o,i,A]);let B=(0,r.useCallback)(async e=>{let t=S.trim();t&&!T&&(L(),_(""),F.current=w.current,J(),await q.startJob({question:t,imagePaths:e,targetEntryId:M.entryId}))},[S,T,q,M.entryId,J,L]),U=(0,r.useCallback)(()=>{if("idle"===q.status)return;let e=q.question;q.cancelJob(),_(e)},[q]);if((0,r.useEffect)(()=>{if(T)return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e);function e(e){"Escape"===e.key&&(e.preventDefault(),U())}},[T,U]),!v)return(0,s.jsx)("div",{className:"flex h-full items-center justify-center text-sm text-muted-foreground",children:"Select an entry or click + New to get started."});let H=i?(null==y?void 0:y.item)||i:o&&!n?null:(null==b?void 0:b.item)||n;return(0,s.jsxs)("div",{className:"flex h-full min-w-0 flex-col overflow-hidden rounded-lg border bg-background",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between border-b px-4 py-2",children:[(0,s.jsxs)("div",{className:"flex items-center gap-3 text-xs text-muted-foreground",children:[!i&&!(o&&!n)&&(0,s.jsx)("span",{children:"Journal"}),i?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("span",{className:"font-medium text-destructive",children:"Trash"}),(0,s.jsxs)("span",{children:[null!==(e=null==y?void 0:y.date)&&void 0!==e?e:i,f(i)&&" ".concat(f(i))]}),y&&(0,s.jsxs)("span",{children:[(y.size/1024).toFixed(1)," KB"]})]}):o&&!n?(0,s.jsx)("span",{className:"font-medium",children:"New entry"}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("span",{children:[null!==(t=null==b?void 0:b.date)&&void 0!==t?t:n,n&&f(n)&&" ".concat(f(n))]}),b&&(0,s.jsxs)("span",{children:[(b.size/1024).toFixed(1)," KB"]}),(null==b?void 0:b.notion_url)?(0,s.jsx)("a",{href:b.notion_url,target:"_blank",rel:"noreferrer",className:"text-blue-600 hover:underline dark:text-blue-400",children:"Synced to Notion ↗"}):b&&(0,s.jsx)("span",{title:"Syncs automatically once NOTION_DATABASE_ID_JOURNAL is configured",children:"Not synced to Notion"})]})]}),(0,s.jsxs)("div",{className:"flex items-center gap-2",children:[i&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("button",{type:"button",onClick:()=>void k(i),className:"rounded-md border px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground",children:"Restore"}),(0,s.jsx)("button",{type:"button",onClick:()=>void C(i),className:"rounded-md border px-2 py-1 text-xs text-muted-foreground transition-colors hover:bg-accent hover:text-destructive",children:"Delete"})]}),(0,s.jsx)("button",{onClick:N,"aria-label":"Close panel",className:"rounded p-1 text-muted-foreground hover:bg-accent hover:text-accent-foreground",children:(0,s.jsx)(l.Tw,{})})]})]}),H&&(0,s.jsx)("div",{className:"border-b px-4 py-3",children:(0,s.jsx)("h2",{className:"truncate text-sm font-semibold","data-testid":"journal-panel-title",children:H})}),(0,s.jsx)("div",{ref:Z,onScroll:D,className:"scrollbar-slim flex-1 overflow-y-auto px-4 py-4 pr-6","data-testid":"journal-scroll",children:i?j?(0,s.jsx)(g,{md:j}):(0,s.jsx)("p",{className:"text-sm text-muted-foreground",children:"Loading…"}):(0,s.jsxs)("div",{className:"mx-auto flex w-full max-w-3xl flex-col gap-6",children:[n&&m&&(0,s.jsx)("div",{"data-testid":"journal-content",children:(0,s.jsx)(g,{md:m})}),P.length>0&&(0,s.jsx)("div",{className:"flex flex-col gap-6",children:P.map((e,t)=>(0,s.jsx)(d,{question:e.question,answer:e.answer||null},t))})]})}),!i&&(0,s.jsxs)("div",{className:"border-t px-4 pb-4 pt-3",children:[(0,s.jsx)(a.W,{input:S,setInput:_,busy:T,supportsMic:E,listening:O,onToggleMic:I,onSend:e=>void B(e),onCancel:U,placeholder:"e.g. What should I focus on next based on this week?",sendLabel:"Brainstorm",cancelLabel:"Stop"}),z&&(0,s.jsx)("p",{className:"mx-auto max-w-3xl px-3 pt-2 text-sm text-destructive",children:z})]})]})}},42648:function(e,t,n){"use strict";let s;n.d(t,{O:function(){return f}});var r=n(57437),l=n(2265),a=n(20200),o=n(78537),i=n(90224),d=n(43713),c=n(69590);function u(){let{zoomIn:e,zoomOut:t,resetTransform:n}=(0,c.M4)();return(0,r.jsxs)("div",{className:"absolute bottom-4 right-4 z-10 flex flex-col gap-2",children:[(0,r.jsx)("button",{type:"button","aria-label":"Zoom in",className:"rounded bg-gray-800 px-3 py-2 text-white",onClick:()=>e(),children:"+"}),(0,r.jsx)("button",{type:"button","aria-label":"Reset zoom",className:"rounded bg-gray-800 px-3 py-2 text-white",onClick:()=>n(),children:"⟳"}),(0,r.jsx)("button",{type:"button","aria-label":"Zoom out",className:"rounded bg-gray-800 px-3 py-2 text-white",onClick:()=>t(),children:"−"})]})}function x(e){let{svg:t,onClose:n}=e;return(0,l.useEffect)(()=>{let e=document.body.style.overflow;function t(e){"Escape"===e.key&&n()}return document.body.style.overflow="hidden",document.addEventListener("keydown",t),()=>{document.body.style.overflow=e,document.removeEventListener("keydown",t)}},[n]),(0,r.jsxs)("div",{"data-testid":"mermaid-modal-overlay",className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80",onClick:n,children:[(0,r.jsx)("button",{type:"button","aria-label":"Close",className:"absolute right-4 top-4 text-2xl text-white",onClick:e=>{e.stopPropagation(),n()},children:"\xd7"}),(0,r.jsx)("div",{className:"relative h-[80vh] w-[80vw] bg-gray-950",onClick:e=>e.stopPropagation(),children:(0,r.jsxs)(c.d$,{wheel:{disabled:!0},centerOnInit:!0,initialScale:1,children:[(0,r.jsx)(u,{}),(0,r.jsx)(c.Uv,{wrapperStyle:{width:"100%",height:"100%"},contentStyle:{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"center"},children:(0,r.jsx)("div",{dangerouslySetInnerHTML:{__html:t}})})]})})]})}let m=!1;function h(e){let{code:t}=e,a=(0,l.useId)(),o="mermaid-".concat(a.replace(/:/g,"")),[i,d]=(0,l.useState)({status:"loading"}),[c,u]=(0,l.useState)(!1);return((0,l.useEffect)(()=>{let e=!1;return async function(){try{let{default:r}=await (s||(s=Promise.all([n.e(7853),n.e(4734),n.e(3045)]).then(n.bind(n,98284))),s);m||(r.initialize({startOnLoad:!1,securityLevel:"strict"}),m=!0);let{svg:l}=await r.render(o,t);e||d({status:"success",svg:l})}catch(t){e||d({status:"error",message:t instanceof Error?t.message:String(t)})}}(),()=>{e=!0}},[t,o]),"loading"===i.status)?(0,r.jsx)("div",{className:"text-sm text-gray-500",children:"Rendering mermaid diagram..."}):"error"===i.status?(0,r.jsxs)("div",{className:"my-2",children:[(0,r.jsxs)("p",{className:"text-sm text-red-600 dark:text-red-400",children:["Mermaid render error: ",i.message]}),(0,r.jsxs)("details",{className:"mt-1",children:[(0,r.jsx)("summary",{className:"cursor-pointer text-sm text-gray-500",children:"Show source"}),(0,r.jsx)("pre",{className:"whitespace-pre-wrap text-xs",children:(0,r.jsx)("code",{children:t})})]})]}):(0,r.jsxs)(r.Fragment,{children:[(0,r.jsx)("div",{className:"my-2 cursor-zoom-in",onClick:()=>u(!0),dangerouslySetInnerHTML:{__html:i.svg}}),c&&(0,r.jsx)(x,{svg:i.svg,onClose:()=>u(!1)})]})}var p=n(54367);function f(e){let{content:t,onLinkClick:n,breaks:s=!1}=e,c=(0,l.useMemo)(()=>({a:e=>{let{children:t,href:s,...l}=e;return(0,r.jsx)("a",{...l,href:s,target:"_blank",rel:"noopener noreferrer",onClick:e=>{var t;0!==e.button||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey||void 0===s||null===(t=null==n?void 0:n(s))||void 0===t||!t||e.preventDefault()},children:t})},code:e=>{let{className:t,children:n,...s}=e;return(null==t?void 0:t.split(/\s+/).includes("language-mermaid"))?(0,r.jsx)(h,{code:(function e(t){return"string"==typeof t?t:t.map(e).join("")})(n).replace(/\n$/,"")}):(0,r.jsx)("code",{className:t,...s,children:n})}}),[n]);return(0,r.jsx)("div",{className:"prose prose-sm max-w-none dark:prose-invert prose-a:text-blue-600 prose-a:no-underline hover:prose-a:underline dark:prose-a:text-blue-400","data-testid":"markdown-view",children:(0,r.jsx)(a.UG,{remarkPlugins:s?[d.Z,i.Z]:[d.Z],rehypePlugins:[[o.Z,p.fO]],components:c,children:t})})}}},function(e){e.O(0,[6137,6892,7565,2793,9095,6739,2971,2117,1744],function(){return e(e.s=39240)}),_N_E=e.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[4095],{13255:function(e,t,n){Promise.resolve().then(n.bind(n,53621)),Promise.resolve().then(n.bind(n,65047)),Promise.resolve().then(n.bind(n,35102)),Promise.resolve().then(n.bind(n,96215)),Promise.resolve().then(n.bind(n,56743)),Promise.resolve().then(n.bind(n,75780)),Promise.resolve().then(n.bind(n,90160)),Promise.resolve().then(n.bind(n,75408)),Promise.resolve().then(n.bind(n,5620)),Promise.resolve().then(n.bind(n,98763))},6970:function(e,t,n){"use strict";n.d(t,{O:function(){return s}});var a=n(57437),r=n(94508);function s(e){let{onPointerDown:t,edge:n="right",ariaLabel:s="Resize panel",className:i,...o}=e;return(0,a.jsx)("div",{role:"separator","aria-orientation":"vertical","aria-label":s,"data-testid":o["data-testid"],onPointerDown:t,className:(0,r.cn)("group absolute inset-y-0 z-10 w-3 cursor-col-resize bg-transparent","left"===n?"left-0":"right-0",i),children:(0,a.jsx)("div",{className:(0,r.cn)("pointer-events-none absolute inset-y-0 w-1 group-hover:bg-primary/50","left"===n?"left-0":"right-0")})})}},17378:function(e,t,n){"use strict";n.d(t,{Q:function(){return r}});var a=n(57437);function r(e){let{status:t}=e;return"idle"===t?null:"saving"===t?(0,a.jsx)("span",{className:"text-sm text-muted-foreground","data-testid":"save-status",children:"Saving…"}):"saved"===t?(0,a.jsx)("span",{className:"text-sm text-green-600 dark:text-green-400","data-testid":"save-status",children:"Saved"}):(0,a.jsx)("span",{className:"text-sm text-destructive","data-testid":"save-status",children:"Save failed"})}},65047:function(e,t,n){"use strict";n.d(t,{ServiceTabs:function(){return l}});var a=n(57437),r=n(27648),s=n(99376),i=n(53528),o=n(94508);function l(){let e=(0,s.usePathname)(),t=(0,i.I)(e).id;return(0,a.jsx)("nav",{"data-testid":"service-tabs","aria-label":"Services",className:"flex items-center gap-1 border-b px-8 py-2",children:i.A.map(e=>{let n=e.id===t;return(0,a.jsxs)(r.default,{href:e.defaultHref,"data-testid":"service-tab-".concat(e.id),"aria-current":n?"page":void 0,className:(0,o.cn)("flex items-center rounded-md px-3 py-1.5 transition-colors",n?"bg-accent text-accent-foreground":"text-muted-foreground hover:bg-accent/50"),children:[(0,a.jsx)(e.icon,{"aria-hidden":!0,className:"h-4 w-4"}),(0,a.jsx)("span",{className:"sr-only",children:e.label})]},e.id)})})}},35102:function(e,t,n){"use strict";n.d(t,{Sidebar:function(){return Q}});var a=n(57437),r=n(27648),s=n(99376),i=n(2265),o=n(20580),l=n(5620),c=n(94508);function d(){let{sortedEntries:e,entriesError:t,trash:n,showTrash:r,selected:s,trashPreview:i,loadEntry:d,loadTrashEntry:u,deleteEntry:f,restoreEntry:h,purgeEntry:p,toggleTrash:m,startCompose:x}=(0,l.O)();return(0,a.jsxs)("section",{"data-sidebar-section":"journal",className:"flex min-h-0 flex-1 flex-col gap-2",children:[(0,a.jsxs)("div",{className:"flex shrink-0 items-center gap-2",children:[(0,a.jsxs)("button",{type:"button",onClick:x,className:"flex flex-1 items-center justify-center gap-1 rounded-md border border-dashed px-3 py-2 text-xs font-medium text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground",children:[(0,a.jsx)("span",{className:"text-base leading-none",children:"+"})," New"]}),(0,a.jsxs)("button",{type:"button",onClick:m,"aria-pressed":r,className:(0,c.cn)("flex items-center gap-1 rounded-md border px-3 py-2 text-xs font-medium transition-colors",r?"bg-accent text-accent-foreground":"text-muted-foreground hover:bg-accent hover:text-accent-foreground"),children:[(0,a.jsx)(o.XH,{})," Trash"]})]}),(0,a.jsxs)("div",{className:"flex min-h-0 flex-1 flex-col gap-2 overflow-y-auto",children:[t&&(0,a.jsx)("p",{className:"px-1 py-2 text-xs text-destructive",children:t}),r?0===n.length?(0,a.jsx)("p",{className:"px-1 py-2 text-xs text-muted-foreground",children:"Trash is empty."}):(0,a.jsx)("ul",{className:"flex flex-col gap-0.5",children:[...n].sort((e,t)=>t.id.localeCompare(e.id)).map(e=>(0,a.jsx)("li",{children:(0,a.jsxs)("div",{tabIndex:0,role:"button","aria-label":"Preview trashed entry ".concat(e.item||e.id),onClick:()=>void u(e.id),onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),u(e.id))},className:(0,c.cn)("group flex cursor-pointer items-center justify-between gap-2 rounded-md px-3 py-2 text-xs transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",i===e.id?"bg-accent font-medium text-accent-foreground":"hover:bg-accent/50"),children:[(0,a.jsx)("span",{className:"truncate",children:e.item||"—"}),(0,a.jsxs)("div",{className:"flex shrink-0 items-center gap-1 opacity-0 transition-opacity group-hover:opacity-100",children:[(0,a.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),h(e.id)},className:"rounded-md border px-2 py-0.5 text-[11px] text-muted-foreground transition-colors hover:bg-accent hover:text-accent-foreground",children:"Restore"}),(0,a.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),p(e.id)},className:"rounded-md border px-2 py-0.5 text-[11px] text-muted-foreground transition-colors hover:bg-accent hover:text-destructive",children:"Delete"})]})]})},e.id))}):0===e.length?(0,a.jsx)("p",{className:"px-1 py-2 text-xs text-muted-foreground",children:"No entries yet."}):(0,a.jsx)("ul",{className:"flex flex-col gap-0.5",children:e.map(e=>(0,a.jsx)("li",{children:(0,a.jsxs)("div",{tabIndex:0,role:"button","aria-label":"Open entry ".concat(e.item||e.id),onClick:()=>void d(e.id),onKeyDown:t=>{("Enter"===t.key||" "===t.key)&&(t.preventDefault(),d(e.id))},className:(0,c.cn)("group flex cursor-pointer items-center justify-between gap-2 rounded-md px-3 py-2 text-xs transition-colors focus:outline-none focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",s===e.id?"bg-accent font-medium text-accent-foreground":"hover:bg-accent/50"),children:[(0,a.jsx)("span",{className:"truncate",children:e.item||"—"}),(0,a.jsx)("button",{type:"button",onClick:t=>{t.stopPropagation(),f(e.id)},"aria-label":"Delete entry ".concat(e.id),className:"shrink-0 rounded p-1 text-muted-foreground opacity-0 transition-opacity hover:bg-accent hover:text-destructive focus:opacity-100 group-hover:opacity-100",children:(0,a.jsx)(o.XH,{})})]})},e.id))})]})]})}var u=n(84452),f=n(58104),h=n(98550),p=n(98763),m=n(69027);function x(e){let{entry:t,parentPath:n,depth:r,signal:s}=e,[o,l]=(0,i.useState)(!1),[c,d]=(0,i.useState)(null),[u,h]=(0,i.useState)(null),p=n?"".concat(n,"/").concat(t.name):t.name,x=(0,i.useCallback)(async()=>{try{d(await (0,f.X2)(t.handle))}catch(e){h(e instanceof Error?e.message:"failed to load")}},[t.handle]),g=(0,i.useCallback)(async()=>{let e=!o;l(e),e&&null===c&&await x()},[o,c,x]);return(0,i.useEffect)(()=>{0===s.expandGen||f.Eh.has(t.name)||(l(!0),null===c&&x())},[s.expandGen]),(0,i.useEffect)(()=>{0!==s.collapseGen&&l(!1)},[s.collapseGen]),(0,a.jsxs)("div",{children:[(0,a.jsxs)("button",{type:"button",onClick:g,className:"flex w-full items-center gap-1 rounded px-1 py-0.5 text-left text-sm hover:bg-accent",style:{paddingLeft:12*r+4},"data-testid":"tree-dir-".concat(p),children:[(0,a.jsx)(m.DV,{className:"h-3 w-3 shrink-0 text-muted-foreground",open:o}),(0,a.jsx)(m.RO,{className:"h-4 w-4 shrink-0"}),(0,a.jsx)("span",{className:"truncate",children:t.name})]}),o&&null!==u?(0,a.jsx)("p",{className:"px-2 text-xs text-destructive",style:{paddingLeft:12*r+20},children:u}):null,o&&null!==c?c.map(e=>(0,a.jsx)(b,{entry:e,parentPath:p,depth:r+1,signal:s},e.name)):null]})}function g(e){let{entry:t,parentPath:n,depth:r}=e,{selected:s,selectFile:i}=(0,p.w)(),o=n?"".concat(n,"/").concat(t.name):t.name,l=(null==s?void 0:s.path)===o;return(0,a.jsxs)("button",{type:"button",onClick:()=>i({handle:t.handle,path:o}),className:"flex w-full items-center gap-1 rounded px-1 py-0.5 text-left text-sm hover:bg-accent ".concat(l?"bg-accent font-medium":""),style:{paddingLeft:12*r+20},"data-testid":"tree-file-".concat(o),children:[(0,a.jsx)(m.aA,{className:"h-4 w-4 shrink-0",color:(0,u.dH)(t.name)}),(0,a.jsx)("span",{className:"truncate",children:t.name})]})}function y(e){let{file:t}=e,{selected:n,selectFile:r}=(0,p.w)(),s=(null==n?void 0:n.path)===t.path;return(0,a.jsxs)("button",{type:"button",onClick:()=>r(t),className:"flex w-full items-center gap-1.5 rounded px-2 py-1 text-left text-sm hover:bg-accent ".concat(s?"bg-accent font-medium":""),"data-testid":"tree-filter-result-".concat(t.path),children:[(0,a.jsx)(m.aA,{className:"h-4 w-4 shrink-0",color:(0,u.dH)(t.path)}),(0,a.jsx)("span",{className:"truncate",children:(0,c.E)(t.path)}),(0,a.jsx)("span",{className:"ml-auto shrink-0 truncate text-xs text-muted-foreground",children:t.path})]})}function b(e){let{entry:t,parentPath:n,depth:r,signal:s}=e;return"directory"===t.kind?(0,a.jsx)(x,{entry:t,parentPath:n,depth:r,signal:s}):(0,a.jsx)(g,{entry:t,parentPath:n,depth:r})}function v(){let{root:e,rootName:t,needsReopen:n,openFolder:r,fileIndex:s,indexing:o}=(0,p.w)(),[l,d]=(0,i.useState)(null),[u,x]=(0,i.useState)(null),[g,v]=(0,i.useState)(0),[j,w]=(0,i.useState)(0),[k,N]=(0,i.useState)(""),S=""!==k.trim(),C=S?(0,h.s)(s,k,e=>(0,c.E)(e.path),50):[];return(0,i.useEffect)(()=>{if(null===e){d(null);return}x(null),(0,f.X2)(e).then(d).catch(e=>x(e instanceof Error?e.message:"failed to load"))},[e]),(0,a.jsxs)("div",{className:"flex min-h-0 flex-col","data-testid":"file-tree",children:[(0,a.jsxs)("button",{type:"button",onClick:()=>void r(),className:"mb-2 flex items-center gap-1.5 rounded border px-2 py-1 text-xs hover:bg-accent","data-testid":"workspace-open-folder",children:[(0,a.jsx)(m.RO,{className:"h-4 w-4"}),null!==e?(0,a.jsx)("span",{className:"truncate",title:null!=t?t:void 0,children:t}):"Open Folder…"]}),n&&null===e?(0,a.jsx)("p",{className:"px-1 text-xs text-muted-foreground",children:"Reopen the folder to grant access again."}):null,null!==e?(0,a.jsxs)("div",{className:"relative mb-1",children:[(0,a.jsx)(m.W1,{className:"pointer-events-none absolute left-2 top-1/2 h-3 w-3 -translate-y-1/2 text-muted-foreground"}),(0,a.jsx)("input",{type:"text",value:k,onChange:e=>N(e.target.value),placeholder:o?"Indexing…":"Filter by filename…",className:"w-full rounded border bg-background py-1 pl-6 pr-2 text-xs","data-testid":"workspace-name-filter"})]}):null,null===e||S?null:(0,a.jsxs)("div",{className:"mb-1 flex items-center justify-end gap-1",children:[(0,a.jsx)("button",{type:"button",onClick:()=>v(e=>e+1),title:"Expand all","aria-label":"Expand all","data-testid":"workspace-expand-all",className:"rounded p-1 text-muted-foreground hover:bg-accent hover:text-accent-foreground",children:(0,a.jsx)(m.o_,{className:"h-3.5 w-3.5"})}),(0,a.jsx)("button",{type:"button",onClick:()=>w(e=>e+1),title:"Collapse all","aria-label":"Collapse all","data-testid":"workspace-collapse-all",className:"rounded p-1 text-muted-foreground hover:bg-accent hover:text-accent-foreground",children:(0,a.jsx)(m.nf,{className:"h-3.5 w-3.5"})})]}),(0,a.jsx)("div",{className:"min-h-0 flex-1 overflow-y-auto",children:S?C.length>0?C.map(e=>(0,a.jsx)(y,{file:e},e.path)):(0,a.jsx)("p",{className:"p-2 text-xs text-muted-foreground",children:"No matching files"}):null!==u?(0,a.jsx)("p",{className:"p-2 text-xs text-destructive",children:u}):null===e?null:null===l?(0,a.jsx)("p",{className:"p-2 text-xs text-muted-foreground",children:"Loading…"}):l.map(e=>(0,a.jsx)(b,{entry:e,parentPath:"",depth:0,signal:{expandGen:g,collapseGen:j}},e.name))})]})}var j=n(6970),w=n(58135);let k=(0,w.Z)("chart-line",[["path",{d:"M3 3v16a2 2 0 0 0 2 2h16",key:"c24i48"}],["path",{d:"m19 9-5 5-4-4-3 3",key:"2osh9i"}]]),N=(0,w.Z)("palette",[["path",{d:"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z",key:"e79jfc"}],["circle",{cx:"13.5",cy:"6.5",r:".5",fill:"currentColor",key:"1okk4w"}],["circle",{cx:"17.5",cy:"10.5",r:".5",fill:"currentColor",key:"f64h9f"}],["circle",{cx:"6.5",cy:"12.5",r:".5",fill:"currentColor",key:"qy21gx"}],["circle",{cx:"8.5",cy:"7.5",r:".5",fill:"currentColor",key:"fotxhn"}]]),S=(0,w.Z)("file-cog",[["path",{d:"M15 8a1 1 0 0 1-1-1V2a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8z",key:"1ckgky"}],["path",{d:"M20 8v12a2 2 0 0 1-2 2h-4.182",key:"1726p0"}],["path",{d:"m3.305 19.53.923-.382",key:"ao1pio"}],["path",{d:"M4 10.592V4a2 2 0 0 1 2-2h8",key:"1foop0"}],["path",{d:"m4.228 16.852-.924-.383",key:"1fv9zy"}],["path",{d:"m5.852 15.228-.383-.923",key:"1a9hc2"}],["path",{d:"m5.852 20.772-.383.924",key:"1sh9ke"}],["path",{d:"m8.148 15.228.383-.923",key:"4yu6lf"}],["path",{d:"m8.53 21.696-.382-.924",key:"18b0s9"}],["path",{d:"m9.773 16.852.922-.383",key:"ti6xop"}],["path",{d:"m9.773 19.148.922.383",key:"rws47d"}],["circle",{cx:"7",cy:"18",r:"3",key:"lvkj7j"}]]),C=(0,w.Z)("package",[["path",{d:"M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z",key:"1a0edw"}],["path",{d:"M12 22V12",key:"d0xqtd"}],["polyline",{points:"3.29 7 12 12 20.71 7",key:"ousv84"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}]]),E=(0,w.Z)("mail",[["path",{d:"m22 7-8.991 5.727a2 2 0 0 1-2.009 0L2 7",key:"132q7q"}],["rect",{x:"2",y:"4",width:"20",height:"16",rx:"2",key:"izxlao"}]]),A=(0,w.Z)("key-round",[["path",{d:"M2.586 17.414A2 2 0 0 0 2 18.828V21a1 1 0 0 0 1 1h3a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h1a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1h.172a2 2 0 0 0 1.414-.586l.814-.814a6.5 6.5 0 1 0-4-4z",key:"1s6t7t"}],["circle",{cx:"16.5",cy:"7.5",r:".5",fill:"currentColor",key:"w0ekpg"}]]),P=(0,w.Z)("rotate-ccw",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]),T=(0,w.Z)("settings",[["path",{d:"M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915",key:"1i5ecw"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]);var O=n(75495),I=n(26447);let M={light:"Light",dark:"Dark"},z={default:"Default",soft:"Soft"};function R(){let{theme:e,background:t,setTheme:n,setBackground:r}=(0,O.Fg)();return(0,a.jsxs)("div",{className:"space-y-2","data-testid":"appearance-panel",children:[(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("p",{className:"text-[10px] uppercase text-muted-foreground",children:"Theme"}),(0,a.jsx)("div",{className:"flex gap-1",children:I.yU.map(t=>(0,a.jsx)("button",{type:"button",onClick:()=>n(t),"aria-pressed":e===t,"data-testid":"theme-".concat(t),className:(0,c.cn)("flex-1 rounded-md border px-2 py-1 text-xs transition-colors",e===t?"border-primary bg-primary text-primary-foreground":"border-input hover:bg-accent"),children:M[t]},t))})]}),(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("p",{className:"text-[10px] uppercase text-muted-foreground",children:"Background"}),(0,a.jsx)("div",{className:"flex gap-1",children:I.nY.map(e=>(0,a.jsx)("button",{type:"button",onClick:()=>r(e),"aria-pressed":t===e,"data-testid":"bg-".concat(e),className:(0,c.cn)("flex-1 rounded-md border px-2 py-1 text-xs transition-colors",t===e?"border-primary bg-primary text-primary-foreground":"border-input hover:bg-accent"),children:z[e]},e))})]})]})}var D=n(62869);function _(){let e=(0,s.useRouter)(),t=(0,i.useRef)(null),[n,r]=(0,i.useState)("idle"),[o,l]=(0,i.useState)(null),[c,d]=(0,i.useState)(null),u="busy"===n,f=async()=>{let e;r("busy"),l(null),d(null);try{e=await fetch("/api/config",{cache:"no-store"})}catch(e){l(e instanceof Error?e.message:"Network error"),r("error");return}if(!e.ok){l("GET /api/config failed (HTTP ".concat(e.status,")")),r("error");return}let t=new Blob([JSON.stringify(await e.json(),null,2)],{type:"application/json"}),n=URL.createObjectURL(t),a=document.createElement("a");a.href=n,a.download="briefing.json",a.click(),URL.revokeObjectURL(n),d("Exported"),r("success")},h=async t=>{var n;let a,s;let i=null===(n=t.target.files)||void 0===n?void 0:n[0];if(t.target.value="",i){r("busy"),l(null),d(null);try{let e=await i.text();a=JSON.parse(e)}catch(e){l("Invalid JSON — file is not parseable"),r("error");return}try{s=await fetch("/api/config",{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify(a)})}catch(e){l(e instanceof Error?e.message:"Network error"),r("error");return}if(s.ok){d("Imported"),r("success"),e.refresh();return}422===s.status?l("Schema validation failed — file does not match briefing.json"):l("PUT /api/config failed (HTTP ".concat(s.status,")")),r("error")}};return(0,a.jsxs)("div",{className:"space-y-2","data-testid":"config-file-panel",children:[(0,a.jsxs)("div",{className:"flex flex-col gap-1",children:[(0,a.jsx)(D.z,{size:"sm",variant:"outline",onClick:()=>void f(),disabled:u,"data-testid":"config-export",children:"Export"}),(0,a.jsx)(D.z,{size:"sm",variant:"outline",onClick:()=>{var e;return null===(e=t.current)||void 0===e?void 0:e.click()},disabled:u,"data-testid":"config-import",children:"Import"}),(0,a.jsx)("input",{ref:t,type:"file",accept:"application/json,.json",className:"hidden",onChange:e=>void h(e),"data-testid":"config-import-input"})]}),c&&(0,a.jsx)("p",{className:"text-xs text-green-600 dark:text-green-400","data-testid":"config-success",children:c}),o&&(0,a.jsx)("p",{className:"text-xs text-destructive","data-testid":"config-error",children:o})]})}function H(){let[e,t]=(0,i.useState)("idle"),[n,r]=(0,i.useState)(null),s="busy"===e,o=async()=>{let e;t("busy"),r(null);try{e=await fetch("/api/export",{cache:"no-store"})}catch(e){r(e instanceof Error?e.message:"Network error"),t("error");return}if(!e.ok){r("GET /api/export failed (HTTP ".concat(e.status,")")),t("error");return}let n=await e.blob(),a=function(e,t){var n;let a=null==e?void 0:e.match(/filename="?([^"]+)"?/);return null!==(n=null==a?void 0:a[1])&&void 0!==n?n:t}(e.headers.get("content-disposition"),"archive.zip"),s=URL.createObjectURL(n),i=document.createElement("a");i.href=s,i.download=a,i.click(),setTimeout(()=>URL.revokeObjectURL(s),0),t("success")};return(0,a.jsxs)("div",{className:"space-y-2","data-testid":"output-export-panel",children:[(0,a.jsx)("p",{className:"text-xs text-muted-foreground",children:"Download all output and input files (briefing, journal, eval, images…) as a zip for backup or migration."}),(0,a.jsx)(D.z,{size:"sm",variant:"outline",onClick:()=>void o(),disabled:s,"data-testid":"output-export",children:s?"Preparing…":"Download archive zip"}),"success"===e&&(0,a.jsx)("p",{className:"text-xs text-green-600 dark:text-green-400","data-testid":"output-export-success",children:"Downloaded"}),n&&(0,a.jsx)("p",{className:"text-xs text-destructive","data-testid":"output-export-error",children:n})]})}var L=n(63101),F=n(49620);async function J(){let e=await fetch("/api/credentials");if(!e.ok)throw Error("GET /api/credentials HTTP ".concat(e.status));return await e.json()}function B(){let[e,t]=(0,i.useState)(null),[n,r]=(0,i.useState)(null);return((0,i.useEffect)(()=>{Promise.all([fetch("/api/auth/mode"),J()]).then(async e=>{let[n,a]=e;if(!n.ok)throw Error("GET /api/auth/mode HTTP ".concat(n.status));t({authMode:(await n.json()).auth_mode,anthropicKeySet:!!a.ANTHROPIC_API_KEY})}).catch(()=>r("Failed to load auth settings."))},[]),n)?(0,a.jsx)("p",{className:"text-sm text-destructive",children:n}):e?(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("header",{children:[(0,a.jsx)("h2",{className:"text-xl font-semibold",children:"Auth"}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"How ai-agent talks to Claude. Switch any time."})]}),(0,a.jsx)(F.AuthModeForm,{initialAuthMode:e.authMode,anthropicKeySet:e.anthropicKeySet})]}):(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"Loading…"})}var U=n(16502);function V(){let[e,t]=(0,i.useState)(null),[n,r]=(0,i.useState)(null);return((0,i.useEffect)(()=>{J().then(t).catch(()=>r("Failed to load credentials."))},[]),n)?(0,a.jsx)("p",{className:"text-sm text-destructive",children:n}):e?(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("header",{children:[(0,a.jsx)("h2",{className:"text-xl font-semibold",children:"Credentials"}),(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"Stored in the OS keychain. Existing values are never shown — only whether each key is set."})]}),(0,a.jsx)(U.CredentialsForm,{initial:e})]}):(0,a.jsx)("p",{className:"text-sm text-muted-foreground",children:"Loading…"})}function Z(){return(0,a.jsxs)("div",{className:"space-y-3 text-sm",children:[(0,a.jsx)("p",{className:"text-muted-foreground",children:"Walk through the first-run wizard again: auth mode, portfolio, notifications and a dry-run check. It starts from your current settings, and sectors, events and conflicts are left as they are."}),(0,a.jsx)(D.z,{asChild:!0,children:(0,a.jsx)(r.default,{href:"/?rerun=1","data-testid":"rerun-setup",children:"Re-run setup wizard"})})]})}var W=n(26110),K=n(12886);let q=[{key:"usage",label:"Usage",icon:k,render:()=>(0,a.jsx)(L.UsageDashboard,{})},{key:"appearance",label:"Appearance",icon:N,render:()=>(0,a.jsx)(R,{})},{key:"config-file",label:"Config file",icon:S,render:()=>(0,a.jsx)(_,{})},{key:"export",label:"Export data",icon:C,render:()=>(0,a.jsx)(H,{})},{key:"credentials",label:"Credentials",icon:E,render:()=>(0,a.jsx)(V,{})},{key:"auth",label:"Auth",icon:A,render:()=>(0,a.jsx)(B,{})},{key:"setup",label:"Setup",icon:P,render:()=>(0,a.jsx)(Z,{})}];function G(){var e;let[t,n]=(0,i.useState)(!1),[r,s]=(0,i.useState)(q[0].key),o=null!==(e=q.find(e=>e.key===r))&&void 0!==e?e:q[0],{width:l,startResize:d}=(0,K.L)({storageKey:"ai-agent:settings-nav-width:v1",defaultWidth:192,minWidth:140,maxWidth:480});return(0,a.jsxs)(W.Vq,{open:t,onOpenChange:e=>{n(e),e&&s(q[0].key)},children:[(0,a.jsx)(W.hg,{asChild:!0,children:(0,a.jsxs)("button",{type:"button","data-testid":"config-toggle","data-sidebar-row":!0,title:"Config","aria-label":"Config",className:"flex w-full items-center gap-2 rounded-md px-2 py-2 text-base font-semibold transition-colors hover:bg-accent/50",children:[(0,a.jsx)(T,{"aria-hidden":!0,className:"h-4 w-4 shrink-0"}),(0,a.jsx)("span",{"data-sidebar-label":!0,children:"Config"})]})}),(0,a.jsxs)(W.cZ,{"data-testid":"settings-modal",className:"flex h-[80vh] w-[80vw] max-w-[80vw] gap-0 overflow-hidden p-0",children:[(0,a.jsx)(W.$N,{className:"sr-only",children:"Config"}),(0,a.jsxs)("div",{role:"tablist","aria-orientation":"vertical","aria-label":"Settings sections",style:{width:l},className:"relative flex shrink-0 flex-col gap-1 border-r bg-card p-3",children:[(0,a.jsx)("p",{className:"px-2 pb-1 text-xs font-semibold uppercase text-muted-foreground",children:"Settings"}),q.map(e=>(0,a.jsxs)("button",{type:"button",role:"tab",id:"settings-tab-".concat(e.key),"aria-controls":"settings-content","aria-selected":r===e.key,onClick:()=>s(e.key),"data-testid":"settings-nav-".concat(e.key),className:(0,c.cn)("flex items-center gap-2 rounded-md px-3 py-2 text-left text-sm transition-colors",r===e.key?"bg-accent font-medium text-accent-foreground":"hover:bg-accent/50"),children:[(0,a.jsx)(e.icon,{"aria-hidden":!0,className:"h-4 w-4 shrink-0"}),(0,a.jsx)("span",{children:e.label})]},e.key)),(0,a.jsx)(j.O,{onPointerDown:d,ariaLabel:"Resize settings navigation","data-testid":"settings-nav-resizer"})]}),(0,a.jsxs)("div",{role:"tabpanel",id:"settings-content","aria-labelledby":"settings-tab-".concat(o.key),"data-testid":"settings-section-".concat(o.key),className:"min-w-0 flex-1 overflow-y-auto p-6",children:[(0,a.jsx)("h2",{className:"mb-4 text-lg font-semibold",children:o.label}),o.render()]})]})]})}var Y=n(75780),X=n(63943),$=n(53528);function Q(){let e=(0,s.usePathname)(),t=(0,$.I)(e).items,n="/workspace"===e||e.startsWith("/workspace/"),o="/journal"===e||e.startsWith("/journal/"),{isBackgrounded:l}=(0,Y.h)(),[u,f]=(0,i.useState)(!1),[h,p]=(0,i.useState)(!1);(0,i.useEffect)(()=>{f("true"===document.documentElement.getAttribute(X.N8)),p(!0)},[]),(0,i.useEffect)(()=>{if(h){try{localStorage.setItem(X.K0,String(u))}catch(e){}u?document.documentElement.setAttribute(X.N8,"true"):document.documentElement.removeAttribute(X.N8)}},[u,h]);let m=(0,i.useCallback)(e=>{var t;e.preventDefault();let n=e.clientX,a=document.documentElement,r=parseInt(getComputedStyle(a).getPropertyValue(X.is),10)||(null===(t=a.querySelector("[data-sidebar-rail]"))||void 0===t?void 0:t.offsetWidth)||X.kv,s=e=>Math.min(X.Iy,Math.max(X.od,e)),i=new AbortController,{signal:o}=i,l=()=>{i.abort();let e=parseInt(getComputedStyle(a).getPropertyValue(X.is),10);try{e&&localStorage.setItem(X.oS,String(e))}catch(e){}};window.addEventListener("pointermove",e=>{let t=s(r+(e.clientX-n));a.style.setProperty(X.is,"".concat(t,"px"))},{signal:o}),window.addEventListener("pointerup",l,{signal:o}),window.addEventListener("pointercancel",l,{signal:o})},[]);return(0,a.jsxs)("aside",{"data-sidebar-rail":!0,"data-testid":"sidebar","data-collapsed":u,className:"relative flex shrink-0 flex-col gap-4 overflow-hidden border-r bg-card p-4",children:[(0,a.jsxs)("div",{"data-sidebar-header":!0,className:"flex shrink-0 items-center justify-between",children:[(0,a.jsx)("span",{"data-sidebar-brand":!0,className:"px-2 text-base font-semibold",children:"ai-agent"}),(0,a.jsx)("button",{type:"button",onClick:()=>f(e=>!e),"aria-expanded":!u,"aria-label":u?"Expand sidebar":"Collapse sidebar",title:u?"Expand sidebar":"Collapse sidebar","data-testid":"sidebar-toggle",className:"rounded-md p-1 text-sm text-muted-foreground transition-colors hover:bg-accent/50",children:(0,a.jsx)("span",{"aria-hidden":!0,"data-sidebar-toggle-icon":!0})})]}),(0,a.jsxs)("div",{className:"flex min-h-0 flex-1 flex-col gap-4 overflow-hidden",children:[(0,a.jsx)("section",{className:"flex shrink-0 flex-col gap-1",children:(0,a.jsx)("nav",{className:"flex flex-col gap-1",children:t.map(t=>{let n=e===t.href,s="/run"===t.href&&l;return(0,a.jsxs)(r.default,{href:t.href,title:t.label,"aria-label":t.label,"data-sidebar-row":!0,"data-testid":"nav-".concat(t.href.slice(1)),className:(0,c.cn)("flex items-center gap-2 rounded-md px-3 py-2 text-sm transition-colors",n?"bg-accent font-medium text-accent-foreground":"hover:bg-accent/50"),children:[(0,a.jsx)(t.icon,{"aria-hidden":!0,className:"h-4 w-4 shrink-0"}),(0,a.jsx)("span",{"data-sidebar-label":!0,children:t.label}),s&&(0,a.jsx)("span",{"data-testid":"sidebar-run-dot","aria-label":"Background job in progress",className:"ml-auto h-2 w-2 shrink-0 rounded-full bg-primary"})]},t.href)})})}),n&&!u&&(0,a.jsx)("section",{className:"flex min-h-0 flex-1 flex-col overflow-y-auto",children:(0,a.jsx)(v,{})}),o&&!u&&(0,a.jsx)(d,{}),(0,a.jsx)("section",{"data-sidebar-section":"config",className:"flex shrink-0 flex-col gap-1",children:(0,a.jsx)(G,{})})]}),!u&&(0,a.jsx)(j.O,{onPointerDown:m,ariaLabel:"Resize sidebar","data-testid":"sidebar-resizer"})]})}},75495:function(e,t,n){"use strict";n.d(t,{Fg:function(){return u},ThemeProvider:function(){return d},themeBootScript:function(){return m}});var a=n(57437),r=n(2265),s=n(63943),i=n(26447);let o=(0,r.createContext)(null);function l(){return"undefined"==typeof document?"light":document.documentElement.classList.contains("dark")?"dark":"light"}function c(){if("undefined"==typeof document)return"default";let e=document.documentElement.getAttribute("data-bg");return(0,i.k4)(e)?e:"default"}function d(e){let{children:t}=e,[n,s]=(0,r.useState)(l),[d,u]=(0,r.useState)(c);(0,r.useEffect)(()=>{document.documentElement.classList.toggle("dark","dark"===n)},[n]),(0,r.useEffect)(()=>{document.documentElement.setAttribute("data-bg",d)},[d]);let f=(0,r.useCallback)(e=>{s(e);try{localStorage.setItem(i.Fh,e)}catch(e){}},[]),h=(0,r.useCallback)(e=>{u(e);try{localStorage.setItem(i.zE,e)}catch(e){}},[]),p=(0,r.useMemo)(()=>({theme:n,background:d,setTheme:f,setBackground:h}),[n,d,f,h]);return(0,a.jsx)(o.Provider,{value:p,children:t})}function u(){let e=(0,r.useContext)(o);if(!e)throw Error("useTheme must be used within ThemeProvider");return e}let f=JSON.stringify(i.yU),h=JSON.stringify(i.nY),p="dark",m="\n(function(){try{\n var THEMES = ".concat(f,";\n var BGS = ").concat(h,";\n var t = localStorage.getItem(").concat(JSON.stringify(i.Fh),');\n if (THEMES.indexOf(t) === -1) {\n t = window.matchMedia && window.matchMedia("(prefers-color-scheme: dark)").matches\n ? ').concat(JSON.stringify(p)," : ").concat(JSON.stringify("light"),";\n }\n if (t === ").concat(JSON.stringify(p),") document.documentElement.classList.add(").concat(JSON.stringify(p),");\n var b = localStorage.getItem(").concat(JSON.stringify(i.zE),");\n if (BGS.indexOf(b) === -1) b = ").concat(JSON.stringify("default"),';\n document.documentElement.setAttribute("data-bg", b);\n var sc = localStorage.getItem(').concat(JSON.stringify(s.K0),');\n if (sc === "true") document.documentElement.setAttribute(').concat(JSON.stringify(s.N8),', "true");\n var sw = parseInt(localStorage.getItem(').concat(JSON.stringify(s.oS),"), 10);\n if (sw >= ").concat(s.od," && sw <= ").concat(s.Iy,") {\n document.documentElement.style.setProperty(").concat(JSON.stringify(s.is),', sw + "px");\n }\n}catch(e){}})();\n')},20580:function(e,t,n){"use strict";n.d(t,{Qq:function(){return i},Tw:function(){return o},XH:function(){return l},h0:function(){return c},jG:function(){return s}});var a=n(57437);function r(e){let{size:t=14,children:n}=e;return(0,a.jsx)("svg",{width:t,height:t,viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",children:n})}function s(e){return(0,a.jsxs)(r,{...e,children:[(0,a.jsx)("path",{d:"M8 3v3a2 2 0 0 1-2 2H3"}),(0,a.jsx)("path",{d:"M21 8h-3a2 2 0 0 1-2-2V3"}),(0,a.jsx)("path",{d:"M3 16h3a2 2 0 0 1 2 2v3"}),(0,a.jsx)("path",{d:"M16 21v-3a2 2 0 0 1 2-2h3"})]})}function i(e){return(0,a.jsxs)(r,{...e,children:[(0,a.jsx)("path",{d:"M15 3h6v6"}),(0,a.jsx)("path",{d:"M9 21H3v-6"}),(0,a.jsx)("path",{d:"M21 3l-7 7"}),(0,a.jsx)("path",{d:"M3 21l7-7"})]})}function o(e){return(0,a.jsxs)(r,{...e,children:[(0,a.jsx)("line",{x1:"18",y1:"6",x2:"6",y2:"18"}),(0,a.jsx)("line",{x1:"6",y1:"6",x2:"18",y2:"18"})]})}function l(e){let{size:t=14}=e;return(0,a.jsxs)(r,{size:t,children:[(0,a.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,a.jsx)("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}),(0,a.jsx)("line",{x1:"10",y1:"11",x2:"10",y2:"17"}),(0,a.jsx)("line",{x1:"14",y1:"11",x2:"14",y2:"17"})]})}function c(e){let{size:t=12}=e;return(0,a.jsxs)(r,{size:t,children:[(0,a.jsx)("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),(0,a.jsx)("polyline",{points:"15 3 21 3 21 9"}),(0,a.jsx)("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]})}},53621:function(e,t,n){"use strict";n.d(t,{JournalChatBridge:function(){return l}});var a=n(2265),r=n(30641),s=n(90160),i=n(75408),o=n(5620);function l(){let e=(0,s.R)(),t=(0,i.l)(),{loadDates:n}=(0,o.O)(),l=(0,a.useRef)(new Set),{status:c,jobId:d,question:u,assistantContent:f,targetEntryId:h,setError:p,reset:m}=e,{addTurn:x,setEntryId:g}=t;return(0,a.useEffect)(()=>{"done"===c&&d&&(l.current.has(d)||(l.current.add(d),(async()=>{let e;let t=(0,r.GL)(u,f);try{e=h?await fetch("/api/journal/".concat(h),{method:"PATCH",headers:{"content-type":"application/json"},body:JSON.stringify({content:t})}):await fetch("/api/journal",{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify({content:t,item:u.slice(0,20)})})}catch(e){p(e instanceof Error?e.message:"Auto-save network error"),l.current.delete(d);return}if(!e.ok){let t=await e.text().catch(()=>"");p("Auto-save failed (HTTP ".concat(e.status,"): ").concat(t)),l.current.delete(d);return}let a=h;a||(a=(await e.json()).id),x({question:u,answer:f}),g(a),m(),n(),l.current.delete(d)})()))},[c,d,u,f,h,p,m,x,g,n]),null}},49620:function(e,t,n){"use strict";n.d(t,{AuthModeForm:function(){return u}});var a=n(57437),r=n(27648),s=n(99376),i=n(2265),o=n(62869),l=n(66070),c=n(17378);let d=[{value:"cli",label:"Claude Pro / Max subscription (CLI)",hint:"Uses the OAuth session from `claude login`. No API key billing."},{value:"api",label:"Anthropic API key",hint:"Pay-per-use via ANTHROPIC_API_KEY (stored in the keychain)."}];function u(e){let{initialAuthMode:t,anthropicKeySet:n}=e,u=(0,s.useRouter)(),[f,h]=(0,i.useState)(t),[p,m]=(0,i.useState)("idle"),[x,g]=(0,i.useState)(null),y="api"===f&&!n,b=async()=>{if(y){g("Set ANTHROPIC_API_KEY in Credentials before switching to API mode."),m("error");return}m("saving"),g(null);let e=await fetch("/api/auth/mode",{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({auth_mode:f})});if(!e.ok){g("PUT /api/auth/mode failed (HTTP ".concat(e.status,")")),m("error");return}m("saved"),u.refresh()};return(0,a.jsxs)("div",{className:"space-y-4",children:[(0,a.jsxs)("fieldset",{className:"space-y-3","data-testid":"auth-options",children:[(0,a.jsx)("legend",{className:"sr-only",children:"Authentication mode"}),d.map(e=>(0,a.jsx)(l.Zb,{children:(0,a.jsx)(l.aY,{className:"pt-6",children:(0,a.jsxs)("label",{className:"flex cursor-pointer items-start gap-3",children:[(0,a.jsx)("input",{type:"radio",name:"auth-mode",value:e.value,checked:f===e.value,onChange:()=>h(e.value),className:"mt-1","data-testid":"auth-radio-".concat(e.value)}),(0,a.jsxs)("span",{className:"flex flex-col",children:[(0,a.jsx)("span",{className:"font-medium",children:e.label}),(0,a.jsx)("span",{className:"text-xs text-muted-foreground",children:e.hint})]})]})})},e.value))]}),y&&(0,a.jsxs)("p",{className:"rounded-md border border-destructive/40 bg-destructive/5 p-3 text-sm text-destructive","data-testid":"api-blocked",children:["API mode requires ",(0,a.jsx)("code",{className:"font-mono",children:"ANTHROPIC_API_KEY"})," ","in the keychain. Open"," ",(0,a.jsx)(r.default,{href:"/credentials",className:"underline underline-offset-2",children:"Credentials"})," ","to set it, then come back."]}),(0,a.jsxs)("div",{className:"flex items-center gap-3",children:[(0,a.jsx)(o.z,{onClick:()=>void b(),disabled:"saving"===p||f===t,"data-testid":"auth-save",children:"Save"}),(0,a.jsx)(c.Q,{status:p})]}),x&&(0,a.jsx)("p",{className:"text-sm text-destructive","data-testid":"generic-error",children:x})]})}},16502:function(e,t,n){"use strict";n.d(t,{CredentialsForm:function(){return f}});var a=n(57437),r=n(99376),s=n(2265),i=n(35974),o=n(62869),l=n(66070),c=n(26110),d=n(95186);let u=[{name:"DISCORD_TOKEN",label:"Discord bot token",secret:!0},{name:"CHANNEL_ID",label:"Discord channel id",secret:!1},{name:"NOTION_API_KEY",label:"Notion integration key",secret:!0},{name:"NOTION_DATABASE_ID",label:"Notion database id",secret:!1},{name:"NOTION_DATABASE_ID_JOURNAL",label:"Notion journal database id",secret:!1},{name:"ANTHROPIC_API_KEY",label:"Anthropic API key",secret:!0}];function f(e){let{initial:t}=e,n=(0,r.useRouter)(),[f,h]=(0,s.useState)(t),[p,m]=(0,s.useState)(null),[x,g]=(0,s.useState)(""),[y,b]=(0,s.useState)(null),[v,j]=(0,s.useState)(null),w=e=>{m(e),g(""),j(null)},k=()=>{m(null),g("")},N=async()=>{if(!p)return;let e=x.trim();if(""===e){j("Value is required");return}b(p.name),j(null);let t=await fetch("/api/credentials/".concat(encodeURIComponent(p.name)),{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({value:e})});if(b(null),!t.ok){j("PUT failed (HTTP ".concat(t.status,")"));return}h(e=>({...e,[p.name]:!0})),k(),n.refresh()},S=async e=>{b(e),j(null);let t=await fetch("/api/credentials/".concat(encodeURIComponent(e)),{method:"DELETE"});if(b(null),!t.ok){j("DELETE failed (HTTP ".concat(t.status,")"));return}h(t=>({...t,[e]:!1})),n.refresh()};return(0,a.jsxs)("div",{className:"space-y-3",children:[u.map(e=>{let t=!!f[e.name];return(0,a.jsx)(l.Zb,{children:(0,a.jsxs)(l.aY,{className:"flex items-center justify-between gap-4 pt-6",children:[(0,a.jsxs)("div",{className:"space-y-1",children:[(0,a.jsx)("p",{className:"font-medium",children:e.label}),(0,a.jsx)("p",{className:"text-xs font-mono text-muted-foreground",children:e.name})]}),(0,a.jsxs)("div",{className:"flex items-center gap-3",children:[(0,a.jsx)(i.C,{variant:t?"default":"secondary","data-testid":"status-".concat(e.name),children:t?"Set":"Not set"}),(0,a.jsx)(o.z,{variant:"outline",size:"sm",onClick:()=>w(e),disabled:y===e.name,"data-testid":"update-".concat(e.name),children:t?"Update":"Set"}),(0,a.jsx)(o.z,{variant:"ghost",size:"sm",onClick:()=>void S(e.name),disabled:!t||y===e.name,"data-testid":"delete-".concat(e.name),children:"Delete"})]})]})},e.name)}),(0,a.jsx)(c.Vq,{open:null!==p,onOpenChange:e=>{e||k()},children:(0,a.jsx)(c.cZ,{children:p&&(0,a.jsxs)(a.Fragment,{children:[(0,a.jsxs)(c.fK,{children:[(0,a.jsxs)(c.$N,{children:[f[p.name]?"Update":"Set"," ",p.label]}),(0,a.jsxs)(c.Be,{children:["Stored in the OS keychain under",(0,a.jsx)("code",{className:"ml-1 font-mono",children:p.name}),"."]})]}),(0,a.jsx)(d.I,{autoFocus:!0,type:p.secret?"password":"text",value:x,onChange:e=>g(e.target.value),placeholder:p.secret?"••••••••••":"Paste the value",onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),N())},"data-testid":"credential-draft"}),v&&(0,a.jsx)("p",{className:"text-sm text-destructive","data-testid":"credential-error",children:v}),(0,a.jsxs)(c.cN,{children:[(0,a.jsx)(o.z,{variant:"ghost",onClick:k,children:"Cancel"}),(0,a.jsx)(o.z,{onClick:()=>void N(),disabled:y===p.name,"data-testid":"credential-save",children:"Save"})]})]})})}),v&&!p&&(0,a.jsx)("p",{className:"text-sm text-destructive","data-testid":"generic-error",children:v})]})}},35974:function(e,t,n){"use strict";n.d(t,{C:function(){return o}});var a=n(57437);n(2265);var r=n(90535),s=n(94508);let i=(0,r.j)("inline-flex items-center rounded-md border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2",{variants:{variant:{default:"border-transparent bg-primary text-primary-foreground shadow hover:bg-primary/80",secondary:"border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80",destructive:"border-transparent bg-destructive text-destructive-foreground shadow hover:bg-destructive/80",outline:"text-foreground"}},defaultVariants:{variant:"default"}});function o(e){let{className:t,variant:n,...r}=e;return(0,a.jsx)("div",{className:(0,s.cn)(i({variant:n}),t),...r})}},62869:function(e,t,n){"use strict";n.d(t,{z:function(){return c}});var a=n(57437),r=n(2265),s=n(37053),i=n(90535),o=n(94508);let l=(0,i.j)("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground shadow hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),c=r.forwardRef((e,t)=>{let{className:n,variant:r,size:i,asChild:c=!1,...d}=e,u=c?s.g7:"button";return(0,a.jsx)(u,{className:(0,o.cn)(l({variant:r,size:i,className:n})),ref:t,...d})});c.displayName="Button"},66070:function(e,t,n){"use strict";n.d(t,{Ol:function(){return o},SZ:function(){return c},Zb:function(){return i},aY:function(){return d},eW:function(){return u},ll:function(){return l}});var a=n(57437),r=n(2265),s=n(94508);let i=r.forwardRef((e,t)=>{let{className:n,...r}=e;return(0,a.jsx)("div",{ref:t,className:(0,s.cn)("rounded-xl border bg-card text-card-foreground shadow",n),...r})});i.displayName="Card";let o=r.forwardRef((e,t)=>{let{className:n,...r}=e;return(0,a.jsx)("div",{ref:t,className:(0,s.cn)("flex flex-col space-y-1.5 p-6",n),...r})});o.displayName="CardHeader";let l=r.forwardRef((e,t)=>{let{className:n,...r}=e;return(0,a.jsx)("div",{ref:t,className:(0,s.cn)("font-semibold leading-none tracking-tight",n),...r})});l.displayName="CardTitle";let c=r.forwardRef((e,t)=>{let{className:n,...r}=e;return(0,a.jsx)("div",{ref:t,className:(0,s.cn)("text-sm text-muted-foreground",n),...r})});c.displayName="CardDescription";let d=r.forwardRef((e,t)=>{let{className:n,...r}=e;return(0,a.jsx)("div",{ref:t,className:(0,s.cn)("p-6 pt-0",n),...r})});d.displayName="CardContent";let u=r.forwardRef((e,t)=>{let{className:n,...r}=e;return(0,a.jsx)("div",{ref:t,className:(0,s.cn)("flex items-center p-6 pt-0",n),...r})});u.displayName="CardFooter"},26110:function(e,t,n){"use strict";n.d(t,{$N:function(){return m},Be:function(){return x},Vq:function(){return l},cN:function(){return p},cZ:function(){return f},fK:function(){return h},hg:function(){return c}});var a=n(57437),r=n(2265),s=n(18508),i=n(54891),o=n(94508);let l=s.fC,c=s.xz,d=s.h_;s.x8;let u=r.forwardRef((e,t)=>{let{className:n,...r}=e;return(0,a.jsx)(s.aV,{ref:t,className:(0,o.cn)("fixed inset-0 z-50 bg-black/80 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0",n),...r})});u.displayName=s.aV.displayName;let f=r.forwardRef((e,t)=>{let{className:n,children:r,...l}=e;return(0,a.jsxs)(d,{children:[(0,a.jsx)(u,{}),(0,a.jsxs)(s.VY,{ref:t,className:(0,o.cn)("fixed left-[50%] top-[50%] z-50 grid w-full max-w-lg translate-x-[-50%] translate-y-[-50%] gap-4 border bg-background p-6 shadow-lg duration-200 data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[state=closed]:slide-out-to-left-1/2 data-[state=closed]:slide-out-to-top-[48%] data-[state=open]:slide-in-from-left-1/2 data-[state=open]:slide-in-from-top-[48%] sm:rounded-lg",n),...l,children:[r,(0,a.jsxs)(s.x8,{className:"absolute right-4 top-4 rounded-sm opacity-70 ring-offset-background transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none data-[state=open]:bg-accent data-[state=open]:text-muted-foreground",children:[(0,a.jsx)(i.Z,{className:"h-4 w-4"}),(0,a.jsx)("span",{className:"sr-only",children:"Close"})]})]})]})});f.displayName=s.VY.displayName;let h=e=>{let{className:t,...n}=e;return(0,a.jsx)("div",{className:(0,o.cn)("flex flex-col space-y-1.5 text-center sm:text-left",t),...n})};h.displayName="DialogHeader";let p=e=>{let{className:t,...n}=e;return(0,a.jsx)("div",{className:(0,o.cn)("flex flex-col-reverse sm:flex-row sm:justify-end sm:space-x-2",t),...n})};p.displayName="DialogFooter";let m=r.forwardRef((e,t)=>{let{className:n,...r}=e;return(0,a.jsx)(s.Dx,{ref:t,className:(0,o.cn)("text-lg font-semibold leading-none tracking-tight",n),...r})});m.displayName=s.Dx.displayName;let x=r.forwardRef((e,t)=>{let{className:n,...r}=e;return(0,a.jsx)(s.dk,{ref:t,className:(0,o.cn)("text-sm text-muted-foreground",n),...r})});x.displayName=s.dk.displayName},95186:function(e,t,n){"use strict";n.d(t,{I:function(){return i}});var a=n(57437),r=n(2265),s=n(94508);let i=r.forwardRef((e,t)=>{let{className:n,type:r,...i}=e;return(0,a.jsx)("input",{type:r,className:(0,s.cn)("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",n),ref:t,...i})});i.displayName="Input"},69027:function(e,t,n){"use strict";n.d(t,{DV:function(){return o},RO:function(){return s},W1:function(){return d},aA:function(){return i},nf:function(){return c},o_:function(){return l}});var a=n(57437);let r={width:16,height:16,viewBox:"0 0 16 16",fill:"none",stroke:"currentColor",strokeWidth:1.4,strokeLinecap:"round",strokeLinejoin:"round"};function s(e){let{className:t}=e;return(0,a.jsx)("svg",{...r,className:t,"aria-hidden":!0,children:(0,a.jsx)("path",{d:"M1.75 4.25c0-.55.45-1 1-1h3l1.5 1.5h5c.55 0 1 .45 1 1v5.5c0 .55-.45 1-1 1H2.75c-.55 0-1-.45-1-1v-6z"})})}function i(e){let{className:t,color:n}=e;return(0,a.jsxs)("svg",{...r,stroke:null!=n?n:r.stroke,className:t,"aria-hidden":!0,children:[(0,a.jsx)("path",{d:"M4 1.75h5l3 3v9.5c0 .14-.11.25-.25.25H4a.25.25 0 0 1-.25-.25V2A.25.25 0 0 1 4 1.75z"}),(0,a.jsx)("path",{d:"M9 1.75v3h3"})]})}function o(e){let{className:t,open:n}=e;return(0,a.jsx)("svg",{...r,className:t,style:{transform:n?"rotate(90deg)":void 0},"aria-hidden":!0,children:(0,a.jsx)("path",{d:"M6 4l4 4-4 4"})})}function l(e){let{className:t}=e;return(0,a.jsxs)("svg",{...r,className:t,"aria-hidden":!0,children:[(0,a.jsx)("path",{d:"M4 5.5l4 3 4-3"}),(0,a.jsx)("path",{d:"M4 9.5l4 3 4-3"})]})}function c(e){let{className:t}=e;return(0,a.jsxs)("svg",{...r,className:t,"aria-hidden":!0,children:[(0,a.jsx)("path",{d:"M4 10.5l4-3 4 3"}),(0,a.jsx)("path",{d:"M4 6.5l4-3 4 3"})]})}function d(e){let{className:t}=e;return(0,a.jsxs)("svg",{...r,className:t,"aria-hidden":!0,children:[(0,a.jsx)("circle",{cx:"6.75",cy:"6.75",r:"4"}),(0,a.jsx)("path",{d:"M9.75 9.75L13.25 13.25"})]})}},96215:function(e,t,n){"use strict";n.d(t,{ChatJobStateProvider:function(){return d},w:function(){return u}});var a=n(57437),r=n(87411),s=n(22384);let i={jobId:null,status:"idle",question:"",date:"",searchHistory:!1,imagePaths:[],assistantContent:"",error:null,sessionExpired:!1,staleSession:!1},o=e=>"pending"===e||"running"===e,{Provider:l,useStore:c}=(0,r.U)({storageKey:"ai-agent:chat-job:v1",initialState:i,getJobId:e=>e.jobId,isInFlight:e=>o(e.status),isPersistable:e=>!!e.jobId&&o(e.status),serializeForStorage:e=>({...e,assistantContent:"",sessionExpired:!1,staleSession:!1}),start:async(e,t)=>{let{question:n,date:a,image_paths:r,search_history:s}=e,{setState:o}=t;o(()=>({...i,status:"pending",question:n,date:a,searchHistory:!!s,imagePaths:null!=r?r:[]}));try{let e=await fetch("/api/chat",{method:"POST",cache:"no-store",headers:{"content-type":"application/json"},body:JSON.stringify({date:a,question:n,...(null==r?void 0:r.length)?{image_paths:r}:{},...s?{search_history:!0}:{}})});if(401===e.status){o(()=>({...i,sessionExpired:!0}));return}if(!e.ok){let t=await e.text().catch(()=>"");o(n=>({...n,status:"failed",error:"POST /api/chat failed (HTTP ".concat(e.status,"): ").concat(t)}));return}let t=await e.json();if(!t.job_id){o(e=>({...e,status:"failed",error:"POST /api/chat returned no job_id"}));return}o(e=>{var n;return{...e,jobId:null!==(n=t.job_id)&&void 0!==n?n:null,status:"running"}})}catch(e){o(t=>({...t,status:"failed",error:e instanceof Error?e.message:"Network error"}))}},watch:async(e,t)=>{let n,{signal:a,setState:r}=t;r(e=>({...e,assistantContent:""}));try{n=await fetch("/api/chat/".concat(e,"/stream"),{method:"GET",cache:"no-store",signal:a})}catch(e){if(a.aborted)return;r(t=>({...t,status:"failed",error:e instanceof Error?e.message:"Network error"}));return}if(a.aborted)return;if(401===n.status){r(e=>({...e,sessionExpired:!0,status:"failed"}));return}if(404===n.status){r(()=>({...i,status:"failed",error:"The previous chat job is no longer available — please ask again."}));return}if(!n.ok||!n.body){let t=await n.text().catch(()=>"");r(a=>({...a,status:"failed",error:"GET /api/chat/".concat(e,"/stream failed (HTTP ").concat(n.status,"): ").concat(t)}));return}let o=n.body.getReader(),l=new TextDecoder,c="";try{for(;;){let{value:e,done:t}=await o.read();if(t)break;if(a.aborted)return;c+=l.decode(e,{stream:!0});let{events:n,rest:i}=(0,s.Tg)(c);for(let e of(c=i,n)){if(a.aborted)return;"message"===e.type?r(t=>({...t,assistantContent:(0,s.bv)(t.assistantContent,e.data)})):"stale_session"===e.type?r(e=>({...e,staleSession:!0})):"error"===e.type&&r(t=>({...t,error:e.data||"stream error"}))}}}catch(e){if(a.aborted)return;r(t=>({...t,status:"failed",error:e instanceof Error?e.message:"Stream read error"}));return}a.aborted||r(e=>({...e,status:e.error?"failed":"done"}))}});function d(e){let{children:t}=e;return(0,a.jsx)(l,{children:t})}function u(){return c()}},56743:function(e,t,n){"use strict";n.d(t,{ChatStateProvider:function(){return d},R:function(){return u}});var a=n(57437),r=n(2265);let s="ai-agent:chat-history:v1";function i(e){return e.length<=50?e:e.slice(e.length-50)}function o(e){return"object"==typeof e&&null!==e&&("user"===e.role||"assistant"===e.role)&&"string"==typeof e.content&&(void 0===e.error||null===e.error||"string"==typeof e.error)&&(void 0===e.cancelled||"boolean"==typeof e.cancelled)}function l(){try{window.sessionStorage.removeItem(s)}catch(e){}}let c=(0,r.createContext)(null);function d(e){let{children:t}=e,[n,d]=(0,r.useState)([]),[u,f]=(0,r.useState)(!1);(0,r.useEffect)(()=>{d(function(){try{let e=window.sessionStorage.getItem(s);if(!e)return[];let t=JSON.parse(e);if(!Array.isArray(t))return[];return i(t.filter(o))}catch(e){return[]}}()),f(!0)},[]),(0,r.useEffect)(()=>{u&&(0===n.length?l():function(e){try{window.sessionStorage.setItem(s,JSON.stringify(e))}catch(e){}}(n))},[n,u]);let h=(0,r.useCallback)(e=>{d(t=>i("function"==typeof e?e(t):e))},[]),p=(0,r.useCallback)(()=>{d([]),l()},[]),m=(0,r.useMemo)(()=>({messages:n,setMessages:h,reset:p,hydrated:u}),[n,h,p,u]);return(0,a.jsx)(c.Provider,{value:m,children:t})}function u(){let e=(0,r.useContext)(c);if(!e)throw Error("useChatState must be used inside <ChatStateProvider>");return e}},87411:function(e,t,n){"use strict";n.d(t,{U:function(){return i}});var a=n(57437),r=n(2265);function s(e){try{window.sessionStorage.removeItem(e)}catch(e){}}function i(e){let{storageKey:t,initialState:n,getJobId:i,isInFlight:o,isPersistable:l,isUnresumable:c=e=>o(e)&&null===i(e),serializeForStorage:d=e=>e,start:u,watch:f}=e,h=(0,r.createContext)(null);return{Provider:function(e){let{children:p}=e,[m,x]=(0,r.useState)(n),[g,y]=(0,r.useState)(!1);(0,r.useEffect)(()=>{x(function(e,t,n){try{let a=window.sessionStorage.getItem(e);if(!a)return t;let r=JSON.parse(a),s={...t,...r};if(n(s))return t;return s}catch(e){return t}}(t,n,c)),y(!0)},[]),(0,r.useEffect)(()=>{g&&(l(m)?function(e,t){try{window.sessionStorage.setItem(e,JSON.stringify(t))}catch(e){}}(t,d(m)):s(t))},[m,g]);let b=i(m),v=o(m);(0,r.useEffect)(()=>{if(!g||!b||!v)return;let e=new AbortController,t=!1,n=e=>{t||x(t=>i(t)!==b?t:e(t))};return(async()=>{try{await f(b,{signal:e.signal,setState:n})}catch(e){}})(),()=>{t=!0,e.abort()}},[g,b,v]);let j=(0,r.useCallback)(async e=>{await u(e,{setState:e=>{x(e)}})},[]),w=(0,r.useCallback)(()=>{x(n),s(t)},[]),k=(0,r.useMemo)(()=>({...m,isBackgrounded:v,startJob:j,reset:w}),[m,v,j,w]);return(0,a.jsx)(h.Provider,{value:k,children:p})},useStore:function(){let e=(0,r.useContext)(h);if(!e)throw Error("useStore must be used inside the Provider returned by createJobStoreProvider");return e}}}},84452:function(e,t,n){"use strict";n.d(t,{CO:function(){return l},C_:function(){return c},JM:function(){return p},MH:function(){return u},Yb:function(){return i},dH:function(){return f}});let a={py:"#3776AB",js:"#F7DF1E",jsx:"#61DAFB",ts:"#3178C6",tsx:"#3178C6",json:"#F7DF1E",md:"#42A5F5",markdown:"#42A5F5",html:"#E34C26",css:"#2965F1",scss:"#CC6699",yml:"#CB171E",yaml:"#CB171E",toml:"#9C4221",sh:"#4EAA25",bash:"#4EAA25",rs:"#DEA584",go:"#00ADD8",java:"#EA2D2E",rb:"#CC342D",php:"#777BB4",sql:"#4479A1",svg:"#FFB13B",png:"#A78BFA",jpg:"#A78BFA",jpeg:"#A78BFA",gif:"#A78BFA",webp:"#A78BFA",bmp:"#A78BFA",ico:"#A78BFA",pdf:"#EC4C47",txt:"#9CA3AF",env:"#ECD53F",lock:"#9CA3AF",log:"#8B95A5"};function r(e){let t=e.lastIndexOf(".");return -1===t?"":e.slice(t+1).toLowerCase()}function s(e){return/^\.env(\.|$)/i.test(e)}function i(e){return"log"===r(e)}let o=new Set(["png","jpg","jpeg","gif","webp","bmp","ico","svg"]);function l(e){return o.has(r(e))}function c(e){return"pdf"===r(e)}let d=new Set(["zip","gz","tgz","bz2","xz","7z","rar","jar","xlsx","xls","docx","doc","pptx","ppt","woff","woff2","ttf","otf","eot","mp3","wav","flac","ogg","mp4","mov","avi","mkv","webm","so","dylib","dll","exe","bin","wasm","sqlite","db","pyc"]);function u(e){return l(e)||c(e)||d.has(r(e))}function f(e){var t;return s(e)?a.env:null!==(t=a[r(e)])&&void 0!==t?t:"currentColor"}let h={py:"python",js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",json:"json",html:"markup",css:"css",scss:"scss",yml:"yaml",yaml:"yaml",toml:"toml",sh:"bash",bash:"bash",rs:"rust",go:"go",java:"java",rb:"ruby",php:"php",sql:"sql"};function p(e){var t;return s(e)?"ini":null!==(t=h[r(e)])&&void 0!==t?t:null}},58104:function(e,t,n){"use strict";n.d(t,{BI:function(){return d},Eh:function(){return a},Mz:function(){return r},SK:function(){return u},Uo:function(){return c},X2:function(){return s},X5:function(){return o},bL:function(){return i},iT:function(){return l},ib:function(){return m},uE:function(){return x}});let a=new Set(["node_modules",".git",".next","dist","build","__pycache__",".venv","venv",".cache","coverage",".turbo",".pytest_cache"]);async function r(){if("function"!=typeof window.showDirectoryPicker)throw Error("This browser does not support the File System Access API");return window.showDirectoryPicker({mode:"readwrite"})}async function s(e){let t=[];for await(let n of e.values())t.push({name:n.name,kind:n.kind,handle:n});return[...t].sort((e,t)=>e.kind!==t.kind?"directory"===e.kind?-1:1:e.name.localeCompare(t.name))}async function i(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:5e3,n=[];async function r(e,s){for await(let i of e.values()){if(n.length>=t)return;let e=s?"".concat(s,"/").concat(i.name):i.name;if("directory"===i.kind){if(a.has(i.name))continue;await r(i,e)}else n.push({path:e,handle:i})}}return await r(e,""),n}function o(e,t){if(/^[a-z][a-z0-9+.-]*:/i.test(e)||e.startsWith("//")||e.startsWith("#")||e.startsWith("/"))return null;let[n]=e.split("#");if(""===n)return null;let a=t.includes("/")?t.slice(0,t.lastIndexOf("/")):"",r=""===a?[]:a.split("/");for(let e of n.split("/"))if(""!==e&&"."!==e){if(".."===e){if(0===r.length)return null;r.pop();continue}r.push(e)}return r.join("/")}async function l(e){return(await e.getFile()).text()}async function c(e){let t=await e.getFile();return URL.createObjectURL(t)}async function d(e,t){let n=await e.createWritable();await n.write(t),await n.close()}async function u(e){var t,n;let a={mode:"readwrite"};return await (null===(t=e.queryPermission)||void 0===t?void 0:t.call(e,a))==="granted"||await (null===(n=e.requestPermission)||void 0===n?void 0:n.call(e,a))==="granted"}let f="handles",h="rootHandle";function p(e,t){return new Promise((e,t)=>{let n=indexedDB.open("workspace",1);n.onupgradeneeded=()=>n.result.createObjectStore(f),n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)}).then(n=>new Promise((a,r)=>{let s=t(n.transaction(f,e).objectStore(f));s.onsuccess=()=>a(s.result),s.onerror=()=>r(s.error)}))}async function m(e){await p("readwrite",t=>t.put(e,h))}async function x(){try{let e=await p("readonly",e=>e.get(h));return null!=e?e:null}catch(e){return null}}},98550:function(e,t,n){"use strict";function a(e,t,n){let a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:20;if(""===t.trim())return e.slice(0,a);let r=[];for(let a of e){let e=function(e,t){if(0===e.length)return 0;let n=e.toLowerCase(),a=t.toLowerCase(),r=0,s=0,i=!1;for(let e=0;e<a.length&&r<n.length;e++)a[e]===n[r]?(s+=i?3:1,(0===e||"/"===a[e-1])&&(s+=2),i=!0,r++):i=!1;return r===n.length?s:null}(t,n(a));null!==e&&r.push({item:a,score:e})}return r.sort((e,t)=>t.score-e.score),r.slice(0,a).map(e=>e.item)}n.d(t,{s:function(){return a}})},12886:function(e,t,n){"use strict";n.d(t,{L:function(){return r}});var a=n(2265);function r(e){let{storageKey:t,defaultWidth:n,minWidth:r,maxWidth:s,edge:i="right"}=e,[o,l]=(0,a.useState)(n);(0,a.useEffect)(()=>{try{let e=Number(localStorage.getItem(t));e>=r&&e<=s&&l(e)}catch(e){}},[t,r,s]);let c=(0,a.useCallback)(e=>{e.preventDefault();let n=e.clientX,a="left"===i?-1:1,c=e=>Math.min(s,Math.max(r,e)),d=new AbortController,{signal:u}=d,f=o,h=()=>{d.abort();try{localStorage.setItem(t,String(f))}catch(e){}};window.addEventListener("pointermove",e=>{l(f=c(o+a*(e.clientX-n)))},{signal:u}),window.addEventListener("pointerup",h,{signal:u}),window.addEventListener("pointercancel",h,{signal:u})},[o,t,r,s,i]);return{width:o,startResize:c}}},75780:function(e,t,n){"use strict";n.d(t,{JobStateProvider:function(){return d},h:function(){return u}});var a=n(57437),r=n(87411);let s={jobId:null,status:"idle",dryRun:!1,startedAt:null,finishedAt:null,error:null,sessionExpired:!1},i=e=>"pending"===e||"running"===e,o=e=>"done"===e||"failed"===e,{Provider:l,useStore:c}=(0,r.U)({storageKey:"ai-agent:run-job:v1",initialState:s,getJobId:e=>e.jobId,isInFlight:e=>i(e.status),isPersistable:e=>!!e.jobId||!!e.error,serializeForStorage:e=>({...e,sessionExpired:!1}),start:async(e,t)=>{let{dryRun:n}=e,{setState:a}=t;a(()=>({...s,status:"pending",dryRun:n}));try{let e=await fetch("/api/run".concat(n?"?dry_run=true":""),{method:"POST",cache:"no-store"});if(401===e.status){a(()=>({...s,sessionExpired:!0}));return}if(!e.ok){let t=await e.text();a(n=>({...n,status:"failed",error:"POST /api/run failed (HTTP ".concat(e.status,"): ").concat(t)}));return}let t=await e.json();a(e=>{var n,a,r,s;return{...e,jobId:null!==(n=t.job_id)&&void 0!==n?n:null,status:t.status,startedAt:null!==(a=t.started_at)&&void 0!==a?a:e.startedAt,finishedAt:null!==(r=t.finished_at)&&void 0!==r?r:e.finishedAt,dryRun:null!==(s=t.dry_run)&&void 0!==s?s:e.dryRun}})}catch(e){a(t=>({...t,status:"failed",error:e instanceof Error?e.message:"Network error"}))}},watch:async(e,t)=>{let{signal:n,setState:a}=t,r=Date.now();for(;!n.aborted;){if(await new Promise(e=>setTimeout(e,2e3)),n.aborted)return;if(Date.now()-r>6e5){a(e=>({...e,status:"failed",error:"Timed out waiting for the job to finish"}));return}try{let t=await fetch("/api/run/".concat(e),{cache:"no-store",signal:n});if(n.aborted)return;if(401===t.status){a(e=>({...e,sessionExpired:!0}));return}if(404===t.status){a(()=>({...s,error:"The previous background job is no longer available — please run it again."}));return}if(!t.ok){a(n=>({...n,status:"failed",error:"GET /api/run/".concat(e," failed (HTTP ").concat(t.status,")")}));return}let r=await t.json();if(n.aborted||(a(e=>{var t,n,a,s;return{...e,status:r.status,startedAt:null!==(t=r.started_at)&&void 0!==t?t:e.startedAt,finishedAt:null!==(n=r.finished_at)&&void 0!==n?n:e.finishedAt,dryRun:null!==(a=r.dry_run)&&void 0!==a?a:e.dryRun,error:"failed"===r.status?null!==(s=r.error)&&void 0!==s?s:"Job failed without an error message":e.error}}),o(r.status)))return}catch(e){if(n.aborted)return;a(t=>({...t,status:"failed",error:e instanceof Error?e.message:"Network error"}));return}}}});function d(e){let{children:t}=e;return(0,a.jsx)(l,{children:t})}function u(){return c()}},53528:function(e,t,n){"use strict";n.d(t,{A:function(){return h},I:function(){return p}});var a=n(58135);let r=(0,a.Z)("book-open",[["path",{d:"M12 7v14",key:"1akyts"}],["path",{d:"M3 18a1 1 0 0 1-1-1V4a1 1 0 0 1 1-1h5a4 4 0 0 1 4 4 4 4 0 0 1 4-4h5a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3z",key:"ruj8y"}]]),s=(0,a.Z)("chart-pie",[["path",{d:"M21 12c.552 0 1.005-.449.95-.998a10 10 0 0 0-8.953-8.951c-.55-.055-.998.398-.998.95v8a1 1 0 0 0 1 1z",key:"pzmjnu"}],["path",{d:"M21.21 15.89A10 10 0 1 1 8 2.83",key:"k2fpak"}]]),i=(0,a.Z)("globe",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]]),o=(0,a.Z)("map",[["path",{d:"M14.106 5.553a2 2 0 0 0 1.788 0l3.659-1.83A1 1 0 0 1 21 4.619v12.764a1 1 0 0 1-.553.894l-4.553 2.277a2 2 0 0 1-1.788 0l-4.212-2.106a2 2 0 0 0-1.788 0l-3.659 1.83A1 1 0 0 1 3 19.381V6.618a1 1 0 0 1 .553-.894l4.553-2.277a2 2 0 0 1 1.788 0z",key:"169xi5"}],["path",{d:"M15 5.764v15",key:"1pn4in"}],["path",{d:"M9 3.236v15",key:"1uimfh"}]]),l=(0,a.Z)("play",[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]]),c=(0,a.Z)("message-square",[["path",{d:"M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z",key:"18887p"}]]),d=(0,a.Z)("notebook-pen",[["path",{d:"M13.4 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-7.4",key:"re6nr2"}],["path",{d:"M2 6h4",key:"aawbzj"}],["path",{d:"M2 10h4",key:"l0bgd4"}],["path",{d:"M2 14h4",key:"1gsvsf"}],["path",{d:"M2 18h4",key:"1bu2t1"}],["path",{d:"M21.378 5.626a1 1 0 1 0-3.004-3.004l-5.01 5.012a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506z",key:"pqwjuv"}]]),u=(0,a.Z)("activity",[["path",{d:"M22 12h-2.48a2 2 0 0 0-1.93 1.46l-2.35 8.36a.25.25 0 0 1-.48 0L9.24 2.18a.25.25 0 0 0-.48 0l-2.35 8.36A2 2 0 0 1 4.49 12H2",key:"169zse"}]]),f=(0,a.Z)("folder-tree",[["path",{d:"M20 10a1 1 0 0 0 1-1V6a1 1 0 0 0-1-1h-2.5a1 1 0 0 1-.8-.4l-.9-1.2A1 1 0 0 0 15 3h-2a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"hod4my"}],["path",{d:"M20 21a1 1 0 0 0 1-1v-3a1 1 0 0 0-1-1h-2.9a1 1 0 0 1-.88-.55l-.42-.85a1 1 0 0 0-.92-.6H13a1 1 0 0 0-1 1v5a1 1 0 0 0 1 1Z",key:"w4yl2u"}],["path",{d:"M3 5a2 2 0 0 0 2 2h3",key:"f2jnh7"}],["path",{d:"M3 3v13a2 2 0 0 0 2 2h3",key:"k8epm1"}]]),h=[{id:"briefing",label:"Briefing",icon:r,defaultHref:"/portfolio",items:[{href:"/portfolio",label:"Portfolio",icon:s},{href:"/watch-sectors",label:"Watch Sectors",icon:i},{href:"/geopolitical",label:"Geopolitical Risks",icon:o},{href:"/run",label:"Run",icon:l},{href:"/chat",label:"Q&A Chat",icon:c},{href:"/briefing",label:"Briefing",icon:r}]},{id:"journal",label:"Journal",icon:d,defaultHref:"/journal",items:[{href:"/journal",label:"Journal",icon:d}]},{id:"monitor",label:"Monitor",icon:u,defaultHref:"/monitor",items:[{href:"/monitor",label:"Monitor",icon:u}]},{id:"workspace",label:"Workspace",icon:f,defaultHref:"/workspace",items:[{href:"/workspace",label:"Workspace",icon:f}]}];function p(e){for(let t of h)for(let n of t.items)if(e===n.href||e.startsWith(n.href+"/"))return t;return h[0]}},63943:function(e,t,n){"use strict";n.d(t,{Iy:function(){return l},K0:function(){return a},N8:function(){return r},is:function(){return i},kv:function(){return c},oS:function(){return s},od:function(){return o}});let a="ai-agent:sidebar-collapsed",r="data-sidebar-collapsed",s="ai-agent:sidebar-width",i="--sidebar-width",o=180,l=480,c=240},22384:function(e,t,n){"use strict";function a(e){let t;let n=[],a=e;for(;-1!==(t=a.indexOf("\n\n"));){let e=r(a.slice(0,t));a=a.slice(t+2),null!==e&&n.push(e)}return{events:n,rest:a}}function r(e){let t="message",n=[];for(let a of e.split("\n"))a.startsWith("event:")?t=a.slice(6).replace(/^ /,""):a.startsWith("data:")&&n.push(a.slice(5).replace(/^ /,""));return 0===n.length&&"message"===t?null:{type:t,data:n.join("\n")}}function s(e,t){return e?"".concat(e,"\n").concat(t):t}async function*i(e,t){let n=e.getReader(),s=()=>void n.cancel().catch(()=>{});null==t||t.addEventListener("abort",s,{once:!0});let i=new TextDecoder,o="";try{for(;;){let e;try{e=await n.read()}catch(e){if((null==t?void 0:t.aborted)&&e instanceof DOMException&&"AbortError"===e.name)return;throw e}if(e.done)break;o+=i.decode(e.value,{stream:!0});let{events:r,rest:s}=a(o);for(let e of(o=s,r))yield e}let e=r(o);null!==e&&(yield e)}finally{null==t||t.removeEventListener("abort",s)}}n.d(t,{Tg:function(){return a},bv:function(){return s},v$:function(){return i}})},26447:function(e,t,n){"use strict";n.d(t,{Fh:function(){return s},k4:function(){return o},nY:function(){return r},yU:function(){return a},zE:function(){return i}});let a=["light","dark"],r=["default","soft"],s="ai-agent:theme",i="ai-agent:background";function o(e){return"default"===e||"soft"===e}},98763:function(e,t,n){"use strict";n.d(t,{WorkspaceStateProvider:function(){return o},w:function(){return l}});var a=n(57437),r=n(2265),s=n(58104);let i=(0,r.createContext)(null);function o(e){let{children:t}=e,[n,o]=(0,r.useState)(null),[l,c]=(0,r.useState)(!1),[d,u]=(0,r.useState)(null),[f,h]=(0,r.useState)([]),[p,m]=(0,r.useState)(!1);(0,r.useEffect)(()=>{let e=!1;return(0,s.uE)().then(async t=>{var n;e||null===t||(await (null===(n=t.queryPermission)||void 0===n?void 0:n.call(t,{mode:"readwrite"}))==="granted"?o(t):c(!0))}),()=>{e=!0}},[]),(0,r.useEffect)(()=>{if(null===n){h([]);return}let e=!1;return m(!0),(0,s.bL)(n).then(t=>{e||h(t)}).finally(()=>{e||m(!1)}),()=>{e=!0}},[n]);let x=async()=>{let e=await (0,s.Mz)();if(await (0,s.SK)(e)){try{await (0,s.ib)(e)}catch(e){}o(e),c(!1),u(null)}},g=(0,r.useMemo)(()=>{var e;return{root:n,rootName:null!==(e=null==n?void 0:n.name)&&void 0!==e?e:null,needsReopen:l,openFolder:x,selected:d,selectFile:u,fileIndex:f,indexing:p}},[n,l,d,f,p]);return(0,a.jsx)(i.Provider,{value:g,children:t})}function l(){let e=(0,r.useContext)(i);if(null===e)throw Error("useWorkspaceState must be used within a WorkspaceStateProvider");return e}}},function(e){e.O(0,[6137,259,7648,3101,6739,2971,2117,1744],function(){return e(e.s=13255)}),_N_E=e.O()}]);
@@ -0,0 +1 @@
1
+ (self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[1931],{45763:function(e,t,n){Promise.resolve().then(n.bind(n,37246))},37246:function(e,t,n){"use strict";n.d(t,{Wizard:function(){return N}});var r=n(57437),a=n(2265),s=n(62869),i=n(66070);function o(e){let{step:t,title:n,description:a,error:o,busy:l,primaryLabel:c,onPrimary:d,primaryDisabled:u,onBack:f,children:p}=e;return(0,r.jsxs)(i.Zb,{children:[(0,r.jsxs)(i.Ol,{children:[(0,r.jsxs)("p",{className:"text-xs text-muted-foreground",children:["Step ",t," / 4"]}),(0,r.jsx)(i.ll,{children:n}),a&&(0,r.jsx)(i.SZ,{children:a})]}),(0,r.jsx)(i.aY,{className:"space-y-4",children:p}),(0,r.jsxs)(i.eW,{className:"flex flex-col items-stretch gap-2",children:[o&&(0,r.jsx)("p",{role:"alert",className:"text-sm text-destructive","data-testid":"wizard-error",children:o}),(0,r.jsxs)("div",{className:"flex justify-between gap-2",children:[(0,r.jsx)(s.z,{variant:"ghost",onClick:f,disabled:!f||l,"data-testid":"wizard-back",children:"Back"}),(0,r.jsx)(s.z,{onClick:()=>void d(),disabled:l||u,"data-testid":"wizard-primary",children:l?"...":c})]})]})]})}let l=[{value:"cli",label:"Claude Pro / Max subscription (CLI)",hint:"Uses the OAuth session from `claude login`. No API key billing."},{value:"api",label:"Anthropic API key",hint:"Pay-per-use via ANTHROPIC_API_KEY. Set the key in Step 3."}];function c(e){let{data:t,setData:n,onNext:s,step:i,onBusyChange:c}=e,[d,u]=(0,a.useState)(!1);(0,a.useEffect)(()=>{null==c||c(d)},[d,c]);let[f,p]=(0,a.useState)(null),m=async()=>{u(!0),p(null);try{let e=await fetch("/api/auth/mode",{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({auth_mode:t.authMode})});if(!e.ok){p("Failed to set auth mode (HTTP ".concat(e.status,")"));return}s()}catch(e){p(e instanceof Error?e.message:"Network error")}finally{u(!1)}};return(0,r.jsxs)(o,{step:i,title:"Choose how to call Claude",description:"You can switch later from the sidebar.",busy:d,error:f,primaryLabel:"Next",onPrimary:m,children:[(0,r.jsxs)("fieldset",{className:"space-y-3",children:[(0,r.jsx)("legend",{className:"sr-only",children:"Authentication mode"}),l.map(e=>(0,r.jsxs)("label",{className:"flex cursor-pointer items-start gap-3 rounded-md border p-3 hover:bg-accent",children:[(0,r.jsx)("input",{type:"radio",name:"auth-mode",value:e.value,checked:t.authMode===e.value,onChange:()=>n(t=>({...t,authMode:e.value})),className:"mt-1"}),(0,r.jsxs)("span",{className:"flex flex-col",children:[(0,r.jsx)("span",{className:"font-medium",children:e.label}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:e.hint})]})]},e.value))]}),"cli"===t.authMode&&(0,r.jsxs)("p",{className:"text-xs text-muted-foreground",children:["Run ",(0,r.jsx)("code",{className:"font-mono",children:"claude login"})," in a terminal first if you have not authenticated yet."]})]})}var d=n(95186);let u=e=>e.split(",").map(e=>e.trim()).filter(Boolean),f=e=>Array.from(new Set(u(e).map(e=>e.toUpperCase()))),p=(e,t)=>"Default"===e.sector&&e.tickers.length===t.length&&e.tickers.every(e=>t.includes(e));function m(e){let{data:t,setData:n,onNext:s,onBack:i,step:l,existing:c=null,onBusyChange:m}=e,[h,x]=(0,a.useState)(t.tickers.join(", ")),[g,y]=(0,a.useState)(t.themes.join(", ")),[v,b]=(0,a.useState)(!1);(0,a.useEffect)(()=>{null==m||m(v)},[v,m]);let[j,w]=(0,a.useState)(null),N=f(h),k=u(g),S=N.length>0,T=async()=>{b(!0),w(null);try{let e=c?{...c,portfolio:{...c.portfolio,tickers:N,themes:k},watch_sectors:c.watch_sectors.map(e=>p(e,c.portfolio.tickers)?{...e,tickers:N}:e)}:{portfolio:{tickers:N,themes:k},watch_sectors:[{sector:"Default",tickers:N,notes:null}],geopolitical:{conflicts:[]},watch_events:[]},t=await fetch("/api/config",{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify(e)});if(!t.ok){let e=await t.text();w("PUT /api/config failed (HTTP ".concat(t.status,"): ").concat(e));return}n(e=>({...e,tickers:N,themes:k})),s()}catch(e){w(e instanceof Error?e.message:"Network error")}finally{b(!1)}};return(0,r.jsxs)(o,{step:l,title:"Portfolio basics",description:"Comma-separated. You can edit watch sectors later.",busy:v,error:j,primaryLabel:"Next",primaryDisabled:!S,onPrimary:T,onBack:i,children:[(0,r.jsxs)("label",{className:"block space-y-1",children:[(0,r.jsx)("span",{className:"text-sm font-medium",children:"Tickers"}),(0,r.jsx)(d.I,{value:h,onChange:e=>x(e.target.value),placeholder:"PLTR, NVDA, GOOGL","data-testid":"tickers-input"}),(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:"At least one ticker is required."})]}),(0,r.jsxs)("label",{className:"block space-y-1",children:[(0,r.jsx)("span",{className:"text-sm font-medium",children:"Themes"}),(0,r.jsx)(d.I,{value:g,onChange:e=>y(e.target.value),placeholder:"AI規制, 半導体, 関税","data-testid":"themes-input"})]})]})}let h=[{name:"DISCORD_TOKEN",label:"Discord bot token",secret:!0},{name:"CHANNEL_ID",label:"Discord channel id"},{name:"NOTION_API_KEY",label:"Notion integration API key",secret:!0},{name:"NOTION_DATABASE_ID",label:"Notion database id"}];function x(e){let{data:t,onNext:n,onBack:s,step:i,onBusyChange:l}=e,[c,u]=(0,a.useState)(()=>Object.fromEntries(h.map(e=>[e.name,""]))),f="api"===t.authMode?[...h,{name:"ANTHROPIC_API_KEY",label:"Anthropic API key",hint:"Required because you picked API mode in Step 1.",secret:!0}]:h,[p,m]=(0,a.useState)(!1);(0,a.useEffect)(()=>{null==l||l(p)},[p,l]);let[x,g]=(0,a.useState)(null),y=async()=>{m(!0),g(null);try{for(let[e,t]of f.map(e=>{var t;return[e.name,(null!==(t=c[e.name])&&void 0!==t?t:"").trim()]}).filter(e=>{let[,t]=e;return t.length>0})){let n=await fetch("/api/credentials/".concat(encodeURIComponent(e)),{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify({value:t})});if(!n.ok){let t=await n.text();g("PUT /api/credentials/".concat(e," failed (HTTP ").concat(n.status,"): ").concat(t));return}}n()}catch(e){g(e instanceof Error?e.message:"Network error")}finally{m(!1)}};return(0,r.jsx)(o,{step:i,title:"Notifications and credentials",description:"Leave any field blank to skip. You can add them later from the sidebar.",busy:p,error:x,primaryLabel:"Next",onPrimary:y,onBack:s,children:f.map(e=>{var t;return(0,r.jsxs)("label",{className:"block space-y-1",children:[(0,r.jsx)("span",{className:"text-sm font-medium",children:e.label}),(0,r.jsx)(d.I,{type:e.secret?"password":"text",value:null!==(t=c[e.name])&&void 0!==t?t:"",onChange:t=>u(n=>({...n,[e.name]:t.target.value})),"data-testid":"cred-".concat(e.name)}),e.hint&&(0,r.jsx)("span",{className:"text-xs text-muted-foreground",children:e.hint})]},e.name)})})}let g=(e,t)=>fetch(e,{method:"PUT",headers:{"content-type":"application/json"},body:JSON.stringify(t)});async function y(){let e=await fetch("/api/config/seed",{method:"POST"});if(!e.ok)throw Error("POST /api/config/seed failed (HTTP ".concat(e.status,")"))}async function v(){let e=await g("/api/state",{onboarded:!0});if(!e.ok)throw Error("PUT /api/state failed (HTTP ".concat(e.status,")"));window.location.assign("/")}function b(e){let t,n,{onBack:s,step:i,onBusyChange:l}=e,[c,d]=(0,a.useState)("idle"),[u,f]=(0,a.useState)(null),[p,m]=(0,a.useState)(null),[h,x]=(0,a.useState)(!1),g=(0,a.useCallback)(async()=>{x(!0);try{await v()}catch(e){m(e instanceof Error?e.message:"Network error"),x(!1)}},[]),y=(0,a.useCallback)(async()=>{m(null),d("pending"),f(null);try{let t=await fetch("/api/run?dry_run=true",{method:"POST",cache:"no-store"});if(!t.ok){let e=await t.text();m("POST /api/run failed (HTTP ".concat(t.status,"): ").concat(e)),d("failed");return}let n=await t.json();f(n.job_id);let r=Date.now();for(;;){if(await new Promise(e=>setTimeout(e,1e3)),Date.now()-r>3e4){m("Timed out waiting for the job to finish"),d("failed");return}let t=await fetch("/api/run/".concat(n.job_id),{cache:"no-store"});if(!t.ok){m("GET /api/run/".concat(n.job_id," failed (HTTP ").concat(t.status,")")),d("failed");return}let a=await t.json();if(d(a.status),"done"===a.status)return;if("failed"===a.status){var e;m(null!==(e=a.error)&&void 0!==e?e:"Job failed without an error message");return}}}catch(e){m(e instanceof Error?e.message:"Network error"),d("failed")}},[]),b="done"===c,j="failed"===c,w="pending"===c||"running"===c||h;return(0,a.useEffect)(()=>{null==l||l(w)},[w,l]),b?(t="Finish",n=g):w?(t="...",n=()=>void 0):(t=j?"Retry":"Run test",n=()=>void y()),(0,r.jsx)(o,{step:i,title:"Verify the pipeline",description:"Runs /api/run?dry_run=true — credential preflight only, no Claude calls.",busy:w,error:p,primaryLabel:t,onPrimary:n,onBack:b||h?void 0:s,children:(0,r.jsxs)("div",{className:"space-y-2 text-sm",children:[(0,r.jsxs)("p",{children:[(0,r.jsx)("span",{className:"font-medium",children:"Status:"})," ",(0,r.jsx)("span",{"data-testid":"job-status",children:c})]}),u&&(0,r.jsxs)("p",{className:"text-xs text-muted-foreground",children:["Job id: ",(0,r.jsx)("code",{className:"font-mono",children:u})]}),b&&(0,r.jsxs)("p",{className:"text-sm",children:["All good. Press ",(0,r.jsx)("strong",{children:"Finish"})," to complete onboarding."]})]})})}let j={authMode:"cli",tickers:[],themes:[]};async function w(){let[e,t]=await Promise.all([fetch("/api/auth/mode"),fetch("/api/config")]);if(!e.ok)throw Error("GET /api/auth/mode failed (HTTP ".concat(e.status,")"));if(!t.ok&&404!==t.status)throw Error("GET /api/config failed (HTTP ".concat(t.status,")"));let n=await e.json(),r=t.ok?await t.json():null;return{authMode:n.auth_mode,config:r}}function N(e){var t;let{rerun:n=!1}=e,[i,o]=(0,a.useState)(1),[l,d]=(0,a.useState)(1),[u,f]=(0,a.useState)(j),[p,h]=(0,a.useState)(null),[N,k]=(0,a.useState)(null),[S,T]=(0,a.useState)(!1),[C,P]=(0,a.useState)(null),[_,E]=(0,a.useState)(!1),[O,z]=(0,a.useState)(!1),[A,R]=(0,a.useState)(null),[I,D]=(0,a.useState)(!1);(0,a.useEffect)(()=>{if(!n)return;let e=!0;return w().then(t=>{var n,r,a,s;e&&(h(t),f({authMode:t.authMode,tickers:null!==(a=null===(n=t.config)||void 0===n?void 0:n.portfolio.tickers)&&void 0!==a?a:[],themes:null!==(s=null===(r=t.config)||void 0===r?void 0:r.portfolio.themes)&&void 0!==s?s:[]}))},t=>{e&&k(t instanceof Error?t.message:"Network error")}),()=>{e=!1}},[n]);let H=async()=>{T(!0),P(null);try{if(p&&l>=2){let e=await g("/api/auth/mode",{auth_mode:p.authMode});if(!e.ok)throw Error("Restoring auth mode failed (HTTP ".concat(e.status,")"))}if((null==p?void 0:p.config)&&l>=3){let e=await g("/api/config",p.config);if(!e.ok)throw Error("Restoring config failed (HTTP ".concat(e.status,")"))}window.location.assign("/portfolio")}catch(e){P(e instanceof Error?e.message:"Network error"),T(!1)}},M=async()=>{z(!0),R(null);try{await y(),await v()}catch(e){R(e instanceof Error?e.message:"Network error"),z(!1)}},B={data:u,setData:f,onNext:()=>{let e=4===i?i:i+1;o(e),d(t=>e>t?e:t)},onBack:()=>o(e=>1===e?e:e-1),step:i,onBusyChange:D},L=n&&!p&&!N;return(0,r.jsxs)("div",{className:"w-full max-w-xl space-y-2","data-testid":"wizard",children:[n&&(0,r.jsxs)("div",{className:"flex items-center justify-between gap-2 text-sm text-muted-foreground",children:[(0,r.jsx)("span",{children:"Re-running setup. Cancel restores the auth mode and portfolio saved before."}),(0,r.jsx)(s.z,{variant:"ghost",size:"sm",onClick:()=>void H(),disabled:S,"data-testid":"wizard-cancel-rerun",children:"Cancel"})]}),!n&&!_&&(0,r.jsx)("div",{className:"flex justify-end",children:(0,r.jsx)(s.z,{variant:"ghost",size:"sm",onClick:()=>E(!0),disabled:I,"data-testid":"wizard-skip",children:"Skip setup"})}),!n&&_&&(0,r.jsxs)("div",{className:"space-y-2 rounded-md border p-3 text-sm","data-testid":"wizard-skip-note",children:[(0,r.jsxs)("p",{children:[l>=2?"Skip the remaining steps? What you already saved stays, and anything not set up yet starts from the default settings.":"Skip setup and start with the default settings?"," ","You can change them later in Config → Setup, or run this wizard again from there."]}),A&&(0,r.jsx)("p",{role:"alert",className:"text-destructive","data-testid":"wizard-skip-error",children:A}),(0,r.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,r.jsx)(s.z,{variant:"ghost",size:"sm",onClick:()=>{E(!1),R(null)},disabled:O,"data-testid":"wizard-skip-dismiss",children:"Continue setup"}),(0,r.jsx)(s.z,{size:"sm",onClick:()=>void M(),disabled:O,"data-testid":"wizard-skip-confirm",children:O?"...":"Skip setup"})]})]}),C&&(0,r.jsx)("p",{role:"alert",className:"text-sm text-destructive","data-testid":"wizard-cancel-error",children:C}),N?(0,r.jsxs)("p",{role:"alert",className:"text-sm text-destructive","data-testid":"wizard-load-error",children:["Could not load the current settings: ",N]}):L?(0,r.jsx)("p",{className:"text-sm text-muted-foreground",children:"Loading current settings…"}):(0,r.jsxs)("div",{hidden:_,children:[1===i&&(0,r.jsx)(c,{...B}),2===i&&(0,r.jsx)(m,{...B,existing:null!==(t=null==p?void 0:p.config)&&void 0!==t?t:null}),3===i&&(0,r.jsx)(x,{...B}),4===i&&(0,r.jsx)(b,{...B})]})]})}},62869:function(e,t,n){"use strict";n.d(t,{z:function(){return c}});var r=n(57437),a=n(2265),s=n(37053),i=n(90535),o=n(94508);let l=(0,i.j)("inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50 [&_svg]:pointer-events-none [&_svg]:size-4 [&_svg]:shrink-0",{variants:{variant:{default:"bg-primary text-primary-foreground shadow hover:bg-primary/90",destructive:"bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90",outline:"border border-input bg-background shadow-sm hover:bg-accent hover:text-accent-foreground",secondary:"bg-secondary text-secondary-foreground shadow-sm hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2",sm:"h-8 rounded-md px-3 text-xs",lg:"h-10 rounded-md px-8",icon:"h-9 w-9"}},defaultVariants:{variant:"default",size:"default"}}),c=a.forwardRef((e,t)=>{let{className:n,variant:a,size:i,asChild:c=!1,...d}=e,u=c?s.g7:"button";return(0,r.jsx)(u,{className:(0,o.cn)(l({variant:a,size:i,className:n})),ref:t,...d})});c.displayName="Button"},66070:function(e,t,n){"use strict";n.d(t,{Ol:function(){return o},SZ:function(){return c},Zb:function(){return i},aY:function(){return d},eW:function(){return u},ll:function(){return l}});var r=n(57437),a=n(2265),s=n(94508);let i=a.forwardRef((e,t)=>{let{className:n,...a}=e;return(0,r.jsx)("div",{ref:t,className:(0,s.cn)("rounded-xl border bg-card text-card-foreground shadow",n),...a})});i.displayName="Card";let o=a.forwardRef((e,t)=>{let{className:n,...a}=e;return(0,r.jsx)("div",{ref:t,className:(0,s.cn)("flex flex-col space-y-1.5 p-6",n),...a})});o.displayName="CardHeader";let l=a.forwardRef((e,t)=>{let{className:n,...a}=e;return(0,r.jsx)("div",{ref:t,className:(0,s.cn)("font-semibold leading-none tracking-tight",n),...a})});l.displayName="CardTitle";let c=a.forwardRef((e,t)=>{let{className:n,...a}=e;return(0,r.jsx)("div",{ref:t,className:(0,s.cn)("text-sm text-muted-foreground",n),...a})});c.displayName="CardDescription";let d=a.forwardRef((e,t)=>{let{className:n,...a}=e;return(0,r.jsx)("div",{ref:t,className:(0,s.cn)("p-6 pt-0",n),...a})});d.displayName="CardContent";let u=a.forwardRef((e,t)=>{let{className:n,...a}=e;return(0,r.jsx)("div",{ref:t,className:(0,s.cn)("flex items-center p-6 pt-0",n),...a})});u.displayName="CardFooter"},95186:function(e,t,n){"use strict";n.d(t,{I:function(){return i}});var r=n(57437),a=n(2265),s=n(94508);let i=a.forwardRef((e,t)=>{let{className:n,type:a,...i}=e;return(0,r.jsx)("input",{type:a,className:(0,s.cn)("flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm",n),ref:t,...i})});i.displayName="Input"},94508:function(e,t,n){"use strict";n.d(t,{E:function(){return i},_:function(){return o},cn:function(){return s}});var r=n(61994),a=n(53335);function s(){for(var e=arguments.length,t=Array(e),n=0;n<e;n++)t[n]=arguments[n];return(0,a.m6)((0,r.W)(t))}function i(e){let t=e.replace(/[\\/]+$/,"").split(/[\\/]/);return t[t.length-1]||e}function o(){let e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:new Date,t=e.getFullYear(),n=String(e.getMonth()+1).padStart(2,"0"),r=String(e.getDate()).padStart(2,"0");return"".concat(t,"-").concat(n,"-").concat(r)}},98575:function(e,t,n){"use strict";n.d(t,{F:function(){return s},e:function(){return i}});var r=n(2265);function a(e,t){if("function"==typeof e)return e(t);null!=e&&(e.current=t)}function s(...e){return t=>{let n=!1,r=e.map(e=>{let r=a(e,t);return n||"function"!=typeof r||(n=!0),r});if(n)return()=>{for(let t=0;t<r.length;t++){let n=r[t];"function"==typeof n?n():a(e[t],null)}}}}function i(...e){return r.useCallback(s(...e),e)}},37053:function(e,t,n){"use strict";n.d(t,{g7:function(){return d}});var r,a=n(2265),s=n(98575),i=n(57437),o=Symbol.for("react.lazy"),l=(r||(r=n.t(a,2)))[" use ".trim().toString()];function c(e){var t;return null!=e&&"object"==typeof e&&"$$typeof"in e&&e.$$typeof===o&&"_payload"in e&&"object"==typeof(t=e._payload)&&null!==t&&"then"in t}var d=function(e){let t=function(e){let t=a.forwardRef((e,t)=>{let{children:n,...r}=e;if(c(n)&&"function"==typeof l&&(n=l(n._payload)),a.isValidElement(n)){var i;let e,o;let l=(i=n,(e=Object.getOwnPropertyDescriptor(i.props,"ref")?.get)&&"isReactWarning"in e&&e.isReactWarning?i.ref:(e=Object.getOwnPropertyDescriptor(i,"ref")?.get)&&"isReactWarning"in e&&e.isReactWarning?i.props.ref:i.props.ref||i.ref),c=function(e,t){let n={...t};for(let r in t){let a=e[r],s=t[r];/^on[A-Z]/.test(r)?a&&s?n[r]=(...e)=>{let t=s(...e);return a(...e),t}:a&&(n[r]=a):"style"===r?n[r]={...a,...s}:"className"===r&&(n[r]=[a,s].filter(Boolean).join(" "))}return{...e,...n}}(r,n.props);return n.type!==a.Fragment&&(c.ref=t?(0,s.F)(t,l):l),a.cloneElement(n,c)}return a.Children.count(n)>1?a.Children.only(null):null});return t.displayName=`${e}.SlotClone`,t}(e),n=a.forwardRef((e,n)=>{let{children:r,...s}=e;c(r)&&"function"==typeof l&&(r=l(r._payload));let o=a.Children.toArray(r),d=o.find(f);if(d){let e=d.props.children,r=o.map(t=>t!==d?t:a.Children.count(e)>1?a.Children.only(null):a.isValidElement(e)?e.props.children:null);return(0,i.jsx)(t,{...s,ref:n,children:a.isValidElement(e)?a.cloneElement(e,void 0,r):null})}return(0,i.jsx)(t,{...s,ref:n,children:r})});return n.displayName=`${e}.Slot`,n}("Slot"),u=Symbol("radix.slottable");function f(e){return a.isValidElement(e)&&"function"==typeof e.type&&"__radixId"in e.type&&e.type.__radixId===u}},90535:function(e,t,n){"use strict";n.d(t,{j:function(){return i}});var r=n(61994);let a=e=>"boolean"==typeof e?`${e}`:0===e?"0":e,s=r.W,i=(e,t)=>n=>{var r;if((null==t?void 0:t.variants)==null)return s(e,null==n?void 0:n.class,null==n?void 0:n.className);let{variants:i,defaultVariants:o}=t,l=Object.keys(i).map(e=>{let t=null==n?void 0:n[e],r=null==o?void 0:o[e];if(null===t)return null;let s=a(t)||a(r);return i[e][s]}),c=n&&Object.entries(n).reduce((e,t)=>{let[n,r]=t;return void 0===r||(e[n]=r),e},{});return s(e,l,null==t?void 0:null===(r=t.compoundVariants)||void 0===r?void 0:r.reduce((e,t)=>{let{class:n,className:r,...a}=t;return Object.entries(a).every(e=>{let[t,n]=e;return Array.isArray(n)?n.includes({...o,...c}[t]):({...o,...c})[t]===n})?[...e,n,r]:e},[]),null==n?void 0:n.class,null==n?void 0:n.className)}}},function(e){e.O(0,[6137,2971,2117,1744],function(){return e(e.s=45763)}),_N_E=e.O()}]);