@vite-hub/comments 0.6.1 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/README.md +8 -12
  2. package/dist/anchor.d.ts +1 -1
  3. package/dist/{client-diagnostics-D987sEK7.js → client-diagnostics-DoXqdnBd.js} +8 -0
  4. package/dist/client-request-B1DCz3a9.js +29 -0
  5. package/dist/client.d.ts +48 -223
  6. package/dist/client.js +232 -569
  7. package/dist/database.d.ts +1 -2
  8. package/dist/database.js +1 -1
  9. package/dist/{define-C2tnAtBU.js → define-C-LUOouq.js} +1 -1
  10. package/dist/{errors-C0VwRHiy.js → errors-C5utwZ5H.js} +0 -24
  11. package/dist/{errors-ByCRdInk.js → errors-DeSEHzRf.js} +1 -13
  12. package/dist/hosted/hosted-comments/frame.js +4 -1
  13. package/dist/hosted/hosted-comments/tools.js +362 -0
  14. package/dist/hosted/hosted-comments.js +1 -19
  15. package/dist/{index-D1T7RJ4R.d.ts → index-d6NsDxu9.d.ts} +4 -112
  16. package/dist/index.d.ts +4 -5
  17. package/dist/index.js +6 -20
  18. package/dist/{install-D6hXZaSN.js → install-BueV_fJY.js} +22 -780
  19. package/dist/{install-9L4ASzUC.d.ts → install-F-_O7zDr.d.ts} +5 -11
  20. package/dist/{installed-bPUnazFf.js → installed-BqQKo6WC.js} +2 -7
  21. package/dist/{database-Cguz3hZL.js → migrate-oseJAYbm.js} +2 -46
  22. package/dist/{operations-B1ALn4VS.js → operations-0llC5kKO.js} +49 -51
  23. package/dist/{operations-8hqTi0DH.d.ts → operations-DFLer1fR.d.ts} +1 -0
  24. package/dist/{operations-BkkrI8a3.d.ts → operations-jaihyWw2.d.ts} +36 -4
  25. package/dist/operations.d.ts +3 -3
  26. package/dist/operations.js +2 -2
  27. package/dist/overlay/client-ZBsUybIe.js +4 -0
  28. package/dist/overlay/overlay.js +68 -37
  29. package/dist/page/loader.js +36 -30
  30. package/dist/page-BgvzzsJb.d.ts +32 -0
  31. package/dist/{page-2NzFladc.js → page-CDhmXO-y.js} +24 -1
  32. package/dist/{page-tools-shared-fvmJQCrP.js → page-tools-shared-BCdvqA4S.js} +41 -6
  33. package/dist/{plugin-l4sPt5-n.js → plugin-DGUqlc3C.js} +9 -9
  34. package/dist/realtime.d.ts +10 -9
  35. package/dist/realtime.js +2 -4
  36. package/dist/{rpc-BYmbVkr8.js → rpc-kkxzQ3Qy.js} +1 -1
  37. package/dist/rpc.js +1 -1
  38. package/dist/runtime/auth.d.ts +1 -2
  39. package/dist/runtime/auth.js +1 -1
  40. package/dist/runtime/client-request-plugin.d.ts +2 -0
  41. package/dist/runtime/client-request-plugin.js +21 -0
  42. package/dist/runtime/console.js +2 -2
  43. package/dist/runtime/index.d.ts +6 -8
  44. package/dist/runtime/index.js +25 -153
  45. package/dist/{server-DvSehkPP.js → server-CAMs6viR.js} +1 -1
  46. package/dist/server.d.ts +11 -7
  47. package/dist/server.js +8 -7
  48. package/dist/{store-DvNTDNgn.d.ts → service-CMVA_Ryv.d.ts} +67 -1
  49. package/dist/{service-BIGe1Hpo.js → service-DaMq8TBw.js} +35 -33
  50. package/dist/{session-CCRLR9bf.js → session-B7GDrqsK.js} +207 -41
  51. package/dist/{session-CN4irEqf.d.ts → session-EzQqBeE8.d.ts} +2 -3
  52. package/dist/{table-names-BIHjuEFK.js → table-names-DUmWROM4.js} +1 -3
  53. package/dist/testing.js +1 -1
  54. package/dist/{define-B1jLSPe9.d.ts → types-qzJKgWYS.d.ts} +157 -4
  55. package/dist/vite.d.ts +3 -20
  56. package/dist/vite.js +20 -52
  57. package/package.json +9 -8
  58. package/dist/database-CPua6Q6_.d.ts +0 -573
  59. package/dist/hosted/hosted-comments/client-Czl2zu9P.js +0 -4
  60. package/dist/hosted/hosted-comments/dist-DyVmH21U.js +0 -14
  61. package/dist/hosted/hosted-comments/overlay-DpS0P-nd.js +0 -186
  62. package/dist/hosted/hosted-comments/protocol-DuB0Zhs-.js +0 -1
  63. package/dist/hosted/hosted-comments/rest-transport-CKZG_jZ4.js +0 -1
  64. package/dist/hosted/hosted-comments/tools-D8xg-kDW.js +0 -126
  65. package/dist/overlay/client-C7ftI-CB.js +0 -4
  66. package/dist/overlay/dist-yIZmvSaU.js +0 -1
  67. package/dist/page-DE71P_gQ.d.ts +0 -11
  68. package/dist/request-origin-YPzfE2eh.js +0 -48
  69. package/dist/service-IvgrI4XM.d.ts +0 -71
  70. package/dist/types-l6GOb_yc.d.ts +0 -206
@@ -1,19 +1 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["./hosted-comments/tools-D8xg-kDW.js","./hosted-comments/protocol-DuB0Zhs-.js","./hosted-comments/rest-transport-CKZG_jZ4.js"])))=>i.map(i=>d[i]);
2
- import{a as e,n as t,r as n,s as r,t as i}from"./hosted-comments/protocol-DuB0Zhs-.js";var a=`vitehub`,o=[`comment`];function s(e,t){let n=new URLSearchParams(e);if(n.has(`vitehub`)||o.some(e=>n.has(e)))return!0;let r=t.split(`;`).map(e=>e.trim());return r.includes(`vitehub-tools=1`)?!0:r.includes(`vitehub_session=1`)&&!r.some(e=>e.startsWith(`vitehub-tools=`))}var c=`/_vitehub/page/assets`,l=`/_vitehub/page/tools`,u=`button{all:unset;box-sizing:border-box;display:inline-flex;align-items:center;justify-content:var(--vitehub-pill-justify,center);gap:4px;min-width:28px;height:28px;padding:0 8px;border-radius:8px;font:inherit;white-space:nowrap;color:var(--vitehub-pill-text);cursor:pointer;touch-action:manipulation;-webkit-tap-highlight-color:transparent;transition-property:background-color,color;transition-duration:150ms;transition-timing-function:cubic-bezier(.23,1,.32,1)}
3
- @media(hover:hover){button:where(:not(:disabled):hover){background:var(--vitehub-pill-hover);color:var(--vitehub-pill-strong)}}
4
- button[aria-pressed=true],button[aria-expanded=true]{background:var(--vitehub-pill-on);color:var(--vitehub-pill-on-text)}
5
- :host([aria-busy=true]) button,button[aria-busy=true]{background:var(--vitehub-pill-on);color:var(--vitehub-pill-on-text);cursor:progress}
6
- button:focus-visible{outline:2px solid var(--vitehub-pill-on);outline-offset:1px}
7
- button svg{width:14px;height:14px;flex:none}
8
- @media(any-pointer:coarse){button{min-width:44px;height:44px}}
9
- @media(prefers-reduced-motion:reduce){button{transition:none}}`,d=`data-vitehub-pill`;function f(e){let t=new URL(e,`http://localhost`).pathname,n=t.lastIndexOf(`${c}/`);return n===-1?l:`${t.slice(0,n)}${l}`}function p(e){return typeof e==`string`&&e?e:void 0}function m(e){if(typeof e!=`object`||!e)return;let t=p(Reflect.get(e,`id`)),n=p(Reflect.get(e,`script`));if(!t||!n)return;let r={id:t,label:p(Reflect.get(e,`label`))??t,icon:p(Reflect.get(e,`icon`))??``,script:n};Reflect.get(e,`lazy`)===!0&&(r.lazy=!0);let i=p(Reflect.get(e,`hotkey`));i&&(r.hotkey=i);let a=p(Reflect.get(e,`param`));return a&&(r.param=a),r}function h(e){if(typeof e!=`object`||!e)return;let t=p(Reflect.get(e,`name`)),n=p(Reflect.get(e,`signOut`));if(!t||!n?.startsWith(`/`)||n.startsWith(`//`)||n.includes(`\\`))return;let r={name:t,signOut:n},i=p(Reflect.get(e,`email`));i&&(r.email=i);let a=p(Reflect.get(e,`image`));return a&&/^https?:\/\//i.test(a)&&(r.image=a),Reflect.get(e,`via`)===`console`&&(r.via=`console`),Reflect.get(e,`guest`)===!0&&(r.guest=!0),r}function g(e){let t=typeof e==`object`&&e?Reflect.get(e,`tools`):void 0,n={tools:Array.isArray(t)?t.map(m).filter(e=>!!e):[]},r=typeof e==`object`&&e?h(Reflect.get(e,`account`)):void 0;return r&&(n.account=r),n}var _=`https://app.t3.codes/new`,v=/^[A-Za-z0-9][A-Za-z0-9-]{0,38}\/(?!\.+$)[A-Za-z0-9._-]{1,100}$/,y=40;function b(e){return e&&v.test(e)?e:void 0}function x(e,t){return e.length>t?`${e.slice(0,t).trimEnd()}…`:e}function S(e,t){return e.kind===`page`?`on the whole page`:e.kind===`text`?`on the text "${x(e.exact,t)}" in ${x(e.selector,t)}`:`on ${x(e.selector,t)}`}function C(e,t){let[n,...r]=e.messages,i=e.revision===void 0?``:` (version ${e.revision})`;return[`"${x(n?.body??``,t)}" — ${n?.author??`Someone`}, ${S(e.anchor,t)}${i}`,...r.map(e=>`Reply: "${x(e.body,t)}" — ${e.author}`),...e.files?.length?[`Files: ${e.files.join(` `)}`]:[]]}function w(e,t){if(!e)return[`When you are done, tell me what you changed.`];let{mcp:n,project:r,resolve:i}=e,a=`operation "comments.get", and input { threadId } for ${t.length===1?`thread ${t[0]}`:`each ID in ${JSON.stringify(t)}`}`;return[`In the ViteHub MCP (${n}), use list_apps to verify team ${r.teamId} and app ${r.url} (id: ${r.id}). If the team is different, ask me to switch to that team in the Console; if the app is missing, ask me to check the link. Only after both match, call read_operation with the app id, ${a}.`,i?`When the fix is live, use run_operation with the app id, operation "comments.resolve", and input { threadId, reply }. In the reply, say what you changed.`:`Report the fixes to me without resolving the threads.`]}function T(e){return`${e.id}: "${x(e.messages[0]?.body??``,y)}"`}function E({agent:e,threads:t,url:n},r){let i=new URL(n).href,a=t.length===1,o=w(e,t.map(e=>e.id)),s=a?`Fix this comment on ${i}`:`Fix these ${t.length} comments on ${i}`;return r===`ids`?[s,...o].join(`
10
-
11
- `):r===`titles`?[s,t.map((e,t)=>a?T(e):`${t+1}. ${T(e)}`).join(`
12
- `),...o].join(`
13
-
14
- `):a?[s,...C(t[0],r),...o].join(`
15
- `):[s,...t.map((e,t)=>C(e,r).map((e,n)=>n===0?`${t+1}. ${e}`:` ${e}`).join(`
16
- `)),o.join(`
17
- `)].join(`
18
-
19
- `)}function D(e){return E(e,1/0)}function O(e,t){let n=b(t),r=t=>{let r=new URL(_);return r.searchParams.set(`prompt`,E(e,t)),n&&r.searchParams.set(`repo`,n),r.href},i=[1/0];for(let e=2e3;e>=y;e=Math.floor(e/2))i.push(e);for(let t of[...i,`titles`,...e.agent?[`ids`]:[]]){let e=r(t);if(e.length<=8e3)return e}}var k=`modulepreload`,A=function(e,t){return new URL(e,t).href},j={},M=function(e){return e.pathname.endsWith(`.css`)},N=function(e,t,n){if(t in e)return e[t];let r=n();if(!r){e[t]=void 0;return}let i=r.then(()=>{e[t]=void 0},n=>{throw e[t]=void 0,n});return e[t]=i,i},P=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e,i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?new URL(import.meta.resolve(e)):new URL(e,import.meta.url)}r=o(t.map(t=>{t=A(t,n);let r=s(t),i=M(r);return N(j,r.href,()=>{if(e===void 0){e={all:new Set,styles:new Set};let t=document.getElementsByTagName(`link`);for(let n=t.length-1;n>=0;n--){let r=t[n];e.all.add(r.href),r.rel===`stylesheet`&&e.styles.add(r.href)}}if((i?e.styles:e.all).has(r.href))return;let t=document.createElement(`link`);if(t.rel=i?`stylesheet`:k,i||(t.as=`script`),t.crossOrigin=``,t.href=r.href,a&&t.setAttribute(`nonce`,a),document.head.appendChild(t),i)return new Promise((e,n)=>{let i=a=>{t.removeEventListener(`load`,i),t.removeEventListener(`error`,i),a.type===`error`?n(Error(`Unable to preload CSS for ${r}`)):e(a)};t.addEventListener(`load`,i),t.addEventListener(`error`,i)})})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})},F=15e3,I=3e4,L=5e3,R=RegExp(`^#(/?)vhc=([\\w-]+)$`);function z(){let e=R.exec(location.hash);if(!e)return;let[,t,n]=e;return history.replaceState(history.state,``,`${location.pathname}${location.search}${t?`#/`:``}`),n}function B(e){try{return sessionStorage.getItem(e)===`1`}catch{return!1}}function V(e){try{sessionStorage.setItem(e,`1`)}catch{}}function H(i,a){let o=document.createElement(`iframe`);o.src=`${i}${n(a)}`,o.hidden=!0,o.tabIndex=-1,o.title=`ViteHub Comments`,o.setAttribute(`aria-hidden`,`true`),o.setAttribute(`data-comments-ui`,``);let s=new MessageChannel,c=new Map,l=0,u={call:(t,n)=>new Promise((i,a)=>{let o=++l,u=setTimeout(()=>{c.delete(o),a(r(0))},I);c.set(o,t=>{clearTimeout(u),t.ok?i(t):a(e(t.error))}),s.port1.postMessage({id:o,method:t,input:n})})};return new Promise((e,n)=>{let a=setTimeout(()=>n(r(0)),F);s.port1.addEventListener(`message`,({data:t})=>{if(typeof t==`object`&&t){if(Reflect.get(t,`event`)===`ready`)clearTimeout(a),e(u);else{let e=Reflect.get(t,`id`),n=typeof e==`number`?c.get(e):void 0;if(!n||typeof e!=`number`)return;c.delete(e),n(t)}}}),s.port1.start(),o.addEventListener(`load`,()=>o.contentWindow?.postMessage({type:t},i,[s.port2]),{once:!0}),o.addEventListener(`error`,()=>n(r(0)),{once:!0}),document.documentElement.append(o)})}async function U(e,t){return await new Promise(n=>{let r=setTimeout(()=>i(!1),L);function i(t){clearTimeout(r),e.removeEventListener(`message`,a),n(t)}function a({data:e}){e.type===`redeemed`&&e.code===t&&i(!0)}e.addEventListener(`message`,a),e.postMessage({type:`code`,code:t})})}async function W(e,t,n){let r=z(),a=`vitehub-comments:${e}`;if(!r&&!B(a)&&!s(location.search,document.cookie))return;V(a);let o=new BroadcastChannel(i(e)),c=H(t,e),l=async e=>(await(await c).call(`redeem`,e)).value===!0,u=P(()=>import(`./hosted-comments/tools-D8xg-kDW.js`).then(e=>e.t),__vite__mapDeps([0,1,2]),import.meta.url),d={id:e,console:t,...n?{repository:n}:{}};o.addEventListener(`message`,({data:e})=>{e.type===`code`&&l(e.code).then(t=>{t&&(o.postMessage({type:`redeemed`,code:e.code}),u.then(({mountHostedComments:e})=>e(c,d)))},()=>void 0)});let f=r?await l(r).catch(()=>!1):!1;if(r&&!f&&await U(o,r)){window.close();return}let{mountHostedComments:p}=await u;await p(c,d)}var G=document.querySelector(`script[data-vitehub-comments]`),K=G?.dataset.vitehubComments;K&&W(K,new URL(import.meta.url).origin,b(G?.dataset.vitehubRepo));export{f as a,s as c,g as i,d as l,D as n,o,O as r,a as s,P as t,u};
1
+ var e=`vitehub`,t=[`comment`];function n(e,n){let r=new URLSearchParams(e);if(r.has(`vitehub`)||t.some(e=>r.has(e)))return!0;let i=n.split(`;`).map(e=>e.trim());return i.includes(`vitehub-tools=1`)?!0:i.includes(`vitehub_session=1`)&&!i.some(e=>e.startsWith(`vitehub-tools=`))}`${JSON.stringify([e,...t])}`;var r=/^[A-Za-z0-9][A-Za-z0-9-]{0,38}\/(?!\.+$)[A-Za-z0-9._-]{1,100}$/;function i(e){return e&&r.test(e)?e:void 0}function a(e,...t){return typeof e==`function`?e(...t):e}var o=Error.captureStackTrace,s=class e extends Error{get why(){return this.message}constructor(t,n=e){super(t.why,{cause:t.cause}),this.code=this.name=t.code,this.docs=t.docs,this.fix=t.fix,this.sources=t.sources,this.data=t.data,o?.(this,n)}toJSON(){return{name:this.name,why:this.why,fix:this.fix,docs:this.docs,sources:this.sources,cause:this.cause,data:this.data,stack:this.stack}}};function c(e,t){return typeof e==`string`?`${e}/${t.toLowerCase()}`:e?.(t)}var l=e=>t=>t instanceof s&&e in t;function u(e){let t=e.reporters??[],n=Symbol(),r=Object.defineProperty({},"is",{value:l(n)}),{docsBase:i}=e;for(let o of Object.keys(e.codes)){let l=e.codes[o],u=l.docs===!1?void 0:l.docs||c(i,o),d=(e={},r={})=>{let i=new s({code:o,why:a(l.why,e),fix:a(l.fix,e),docs:u,cause:e.cause,sources:e.sources,data:a(l.data,e)},d);i[n]=1;for(let e of t)e(i,r);return i};d.is=e=>r.is(e)&&e.code===o,r[o]=d}return r}var d=u({docsBase:`https://vitehub.dev/docs/comments/diagnostics`,codes:{COMMENTS_HOSTED_CONFLICT:{why:`This page runs the app's own Comments, so the Hosted Comments script does not start its overlay.`,fix:"Remove the Hosted Comments script, or keep it and set `comments: { overlay: false }` to turn off the app's overlay. See https://vitehub.dev/docs/comments/configure#add-hosted-comments"},COMMENTS_OUTBOX_ACCOUNT_CHANGED:{why:`The current author is not the author of this queued comment.`,fix:`Sign in as the original author and retry the outbox.`},COMMENTS_OUTBOX_RESOLVE_BLOCKED:{why:`Queued delivery must resume before the thread can close.`,fix:`Go online, then retry or dismiss any blocked comments and resolve the thread again.`},COMMENTS_OUTBOX_SENDING:{why:`The server may already have this comment, so the draft cannot change.`,fix:`Wait for delivery to finish, then edit or delete the server copy.`},COMMENTS_OVERLAY_ELEMENT_TAKEN:{why:({name:e})=>`Another script defined the <${e}> element, so this Comments overlay cannot start.`,fix:`Load one Comments overlay script on the page. Remove the other script that defines the element.`},COMMENTS_R0001:{why:({target:e})=>`createAnchor() found nothing to anchor to for ${e}.`,fix:`Pass an element, a non-empty selection, or a point that is over an element of the page.`},COMMENTS_R0013:{why:`The comments request did not get an answer from the server.`,fix:`Check the connection and the app URL, then try again.`},COMMENTS_R0015:{why:`The comment list kept changing while its pages were loading.`,fix:`Refresh again. The previous cache is kept until two complete scans agree.`}}});function f(e){let{code:t,details:n,fix:r,retryAfter:i,status:a,why:o}=e,c=t.startsWith(`COMMENTS_`)?`https://vitehub.dev/docs/comments/diagnostics/${t.toLowerCase()}`:void 0;return Object.assign(new s({code:t,why:o,...r?{fix:r}:{},...c?{docs:c}:{}}),{status:a,...n?{details:n}:{},...i===void 0?{}:{retryAfter:i}})}function p(e,t,n){return Object.assign(d.COMMENTS_R0013(t===void 0?{}:{cause:t}),{status:e,...n===void 0?{}:{retryAfter:n}})}var m=`vitehub-comments:connect`;function h(e){return`vitehub-comments:${e}`}function g(e){return`/comments/${encodeURIComponent(e)}/embed`}var _=15e3,v=3e4,y=5e3,b=`vitehub-comments:`,x=RegExp(`^#(/?)vhc=([\\w-]+)$`);function S(e=!1){let t=x.exec(location.hash);if(!t)return;let[,n,r]=t,i=new URL(location.href);return e&&i.searchParams.delete(`vhp`),i.hash=n?`#/`:``,history.replaceState(history.state,``,i),r}function C(e){try{return sessionStorage.getItem(e)===`1`}catch{return!1}}function w(){try{for(let e=0;e<sessionStorage.length;e++)if(sessionStorage.key(e)?.startsWith(b))return!0}catch{}return!1}function T(e){try{sessionStorage.setItem(e,`1`)}catch{}}function E(e,t){let n=document.createElement(`iframe`);n.src=`${e}${g(t)}`,n.hidden=!0,n.tabIndex=-1,n.title=`ViteHub Comments`,n.setAttribute(`aria-hidden`,`true`),n.setAttribute(`data-comments-ui`,``);let r=new MessageChannel,i=new Map,a=new Set,o=0,s={call:(e,t)=>new Promise((n,a)=>{let s=++o,c=setTimeout(()=>{i.delete(s),a(p(0))},v);i.set(s,e=>{clearTimeout(c),e.ok?n(e):a(f(e.error))}),r.port1.postMessage({id:s,method:e,input:t})}),onChange(e){return a.add(e),()=>a.delete(e)}};return new Promise((t,o)=>{let c=setTimeout(()=>o(p(0)),_);r.port1.addEventListener(`message`,({data:e})=>{if(typeof e!=`object`||!e)return;let n=Reflect.get(e,`event`);if(n===`ready`)clearTimeout(c),t(s);else if(n===`changed`)for(let e of a)e();else{let t=Reflect.get(e,`id`),n=typeof t==`number`?i.get(t):void 0;if(!n||typeof t!=`number`)return;i.delete(t),n(e)}}),r.port1.start(),n.addEventListener(`load`,()=>n.contentWindow?.postMessage({type:m},e,[r.port2]),{once:!0}),n.addEventListener(`error`,()=>o(p(0)),{once:!0}),document.documentElement.append(n)})}async function D(e,t){return await new Promise(n=>{let r=setTimeout(()=>i(!1),y);function i(t){clearTimeout(r),e.removeEventListener(`message`,a),n(t)}function a({data:e}){e.type===`redeemed`&&e.code===t&&i(!0)}e.addEventListener(`message`,a),e.postMessage({type:`code`,code:t})})}function O(){return import(new URL(`hosted-comments/tools.js`,``+import.meta.url).href)}async function k(e,t,r,i=n(location.search,document.cookie),a){let o=S(a!==void 0),s=`${b}${e}`;if(!o&&!C(s)&&!i)return;T(s);let c=new BroadcastChannel(h(e)),l=E(t,e),u=async e=>(await(await l).call(`redeem`,e)).value===!0,d=O(),f={id:e,console:t,...r?{repository:r}:{},...a?{consoleUrl:a}:{}};c.addEventListener(`message`,({data:e})=>{e.type===`code`&&u(e.code).then(t=>{t&&(c.postMessage({type:`redeemed`,code:e.code}),d.then(({mountHostedComments:e})=>e(l,f)))},()=>void 0)});let p=o?await u(o).catch(()=>!1):!1;if(o&&!p&&await D(c,o)){window.close();return}let{mountHostedComments:m}=await d;await m(l,f)}function A(e){return typeof e==`object`&&!!e&&typeof Reflect.get(e,`id`)==`string`&&typeof Reflect.get(e,`team`)==`string`}async function j(e,t,r){let i=n(location.search,``)||w(),a=x.test(location.hash);if(!i&&!a)return;let o=new URL(`/comments/project`,t);for(let t of e)o.searchParams.append(`key`,t);o.searchParams.set(`base`,r);let s=await fetch(o,{credentials:`omit`}).then(e=>e.ok?e.json():void 0).catch(()=>void 0),c=typeof s==`object`&&s?Reflect.get(s,`projects`):void 0,l=Array.isArray(c)?c.filter(A):[],u=e=>{let n=new URL(`/open`,t);return n.searchParams.set(`project`,`${location.origin}${r}`),n.searchParams.set(`path`,`/`),e&&n.searchParams.set(`app`,e),n.href},d=e=>k(e,t,void 0,!0,u(e)),f=a?new URLSearchParams(location.search).get(`vhp`):null,p=l.filter(e=>C(`${b}${e.id}`)),m=f?l.find(e=>e.id===f):l.length===1?l[0]:p.length===1?p[0]:void 0;if(m)return await d(m.id);a&&S(!0);let{mountHostedProjectChoice:h}=await O();await h(u(),l.map(e=>({team:e.team,choose:()=>void d(e.id)})))}var M=document.querySelector(`script[data-vitehub-comments], script[data-vitehub-console-key]`),N=new URL(import.meta.url).origin,P=M?.dataset.vitehubComments,F=M?.dataset.vitehubConsoleKey?.split(/\s+/).filter(Boolean)??[];P?k(P,N,i(M?.dataset.vitehubRepo)):F.length&&j(F,N,M?.dataset.vitehubBase??``);
@@ -1,104 +1,6 @@
1
1
  import { D as CommentUser, T as CommentThread, n as CommentActor, s as CommentContext, w as CommentSubject, y as CommentMessage } from "./types-BX3vH18p.js";
2
- import { f as CommentsPolicyGate, g as CommentsUser, t as CommentAction } from "./define-B1jLSPe9.js";
3
- import "./store-DvNTDNgn.js";
4
- import { _ as ListCommentThreadsOptions, g as FindCommentThreadInput, h as EditCommentInput, m as DefineCommentsOptions, o as CommentsErrorCode, p as CreateCommentThreadInput, v as ReplyInput, y as ReplyOptions } from "./types-l6GOb_yc.js";
5
- import { n as commentSends, t as CommentSendState } from "./database-CPua6Q6_.js";
2
+ import { D as CommentsPolicyGate, c as CreateCommentThreadInput, d as FindCommentThreadInput, f as ListCommentThreadsOptions, h as CommentAction, j as CommentsUser, l as DefineCommentsOptions, m as ReplyOptions, p as ReplyInput, t as CommentsErrorCode, u as EditCommentInput } from "./types-qzJKgWYS.js";
6
3
  import { Result } from "@vite-hub/runtime";
7
- type SendRow = typeof commentSends.$inferSelect;
8
- interface EndpointLike {
9
- id: string;
10
- kind: "url" | "inbox";
11
- agent: string | null;
12
- host: string | null;
13
- disabledAt: number | null;
14
- }
15
- interface PairingLike {
16
- state: "waiting" | "paired" | "used" | "refused";
17
- agent: string | null;
18
- host: string | null;
19
- address: string | null;
20
- }
21
- /**
22
- * The parts of `@vite-hub/webhooks` that Send uses: member pairing and member endpoints. The generated plugin imports the
23
- * package only when `send` is on.
24
- */
25
- interface CommentSendWebhooks {
26
- startMemberPairing: (owner: string) => Promise<Result<{
27
- code: string;
28
- secret: string;
29
- expiresAt: number;
30
- }, string>>;
31
- pairMemberEndpoint: (input: unknown, options?: {
32
- hosts?: readonly string[];
33
- }) => Promise<Result<{
34
- status: "paired";
35
- pairing: PairingLike;
36
- } | {
37
- status: "expired" | "used";
38
- } | {
39
- status: "refused";
40
- reason: string;
41
- }, string>>;
42
- refuseMemberPairing: (code: string) => Promise<Result<boolean, string>>;
43
- getMemberPairing: (owner: string, code: string) => Promise<Result<PairingLike | null, string>>;
44
- cancelMemberPairing: (owner: string, code: string) => Promise<Result<void, string>>;
45
- allowMemberPairing: (owner: string, code: string, options: {
46
- name: string | ((pairing: PairingLike) => string);
47
- ownerName?: string;
48
- ownerEmail?: string;
49
- hosts?: readonly string[];
50
- }) => Promise<Result<{
51
- status: "allowed";
52
- endpoint: EndpointLike;
53
- pairing: PairingLike;
54
- } | {
55
- status: "expired" | "not-owner";
56
- }, string>>;
57
- getMemberEndpoint: (owner: string, options?: {
58
- address?: string;
59
- endpointId?: string;
60
- }) => Promise<Result<EndpointLike | null, string>>;
61
- getMemberDelivery: (id: string) => Promise<{
62
- state: "pending" | "sending" | "sent" | "dead" | "cancelled";
63
- inbox: boolean;
64
- } | undefined>;
65
- sendToMemberEndpoint: (owner: string, body: unknown, options: {
66
- event: string;
67
- key: string;
68
- endpointId: string;
69
- deliveryId: string;
70
- sealBody: boolean;
71
- hosts?: readonly string[];
72
- }) => Promise<Result<{
73
- id: string;
74
- status: "sent" | "inbox" | "pending" | "failed";
75
- }, string>>;
76
- }
77
- /** A thread of a send as its reader gets it: the thread, and whether it is the sender's ask or a quote. */
78
- type CommentSendThread = CommentThread & {
79
- role: "ask" | "quote";
80
- };
81
- /** What a read token, or `comments_get_send`, opens: the send and exactly its threads, as the sender may read them. */
82
- interface CommentSendView {
83
- send: {
84
- id: string;
85
- page: string;
86
- subject: CommentSubject;
87
- state: SendRow["state"];
88
- createdAt: number;
89
- };
90
- threads: CommentSendThread[];
91
- }
92
- /** What the server checked before a read, as `comments.can()` takes it. */
93
- interface CommentSendPolicy {
94
- gate?: CommentsPolicyGate;
95
- console?: boolean;
96
- }
97
- /** Which sends `listOwn` returns. Default: the sent and working ones, at most 20. */
98
- interface CommentSendListOptions extends CommentSendPolicy {
99
- states?: readonly Extract<CommentSendState, "sent" | "working" | "done">[];
100
- limit?: number;
101
- }
102
4
  /**
103
5
  * The context of a thread as label and value pairs, in the order a person reads them: page, element, components,
104
6
  * browser, build. The Console and Agent tools show these.
@@ -134,7 +36,7 @@ interface Comments {
134
36
  by: CommentUser;
135
37
  actor?: CommentActor;
136
38
  }): Promise<Result<CommentThread, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND">>>;
137
- /** With `send`, it can restore a done inbox send or make the thread available to send again to a webhook agent. */
39
+ /** Opens a resolved thread again. */
138
40
  reopen(threadId: string): Promise<Result<CommentThread, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND">>>;
139
41
  /** Deletes a thread and all its messages. */
140
42
  remove(threadId: string): Promise<Result<void, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND">>>;
@@ -166,24 +68,14 @@ interface Comments {
166
68
  limit?: number;
167
69
  gate?: CommentsPolicyGate;
168
70
  }): Promise<Result<CommentUser[], Codes<"COMMENTS_NOT_INSTALLED">>>;
169
- /**
170
- * With `send`: the sends of `user`, newest first, with the threads that `user` may still read. Default: the ones that
171
- * reached the agent and that it has not finished, at most 20. As it scans, it marks finished sends as done.
172
- */
173
- listSends(user: CommentsUser, options?: CommentSendListOptions): Promise<Result<CommentSendView[], Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_SEND_OFF">>>;
174
- /**
175
- * With `send`: a send of `user` with the threads that `user` may still read, as `comments_get_send` opens it. A send
176
- * that reached the agent becomes `working`, also while its delivery waits for the receiver's answer.
177
- */
178
- readSend(user: CommentsUser, id: string, policy?: CommentSendPolicy): Promise<Result<CommentSendView, Codes<"COMMENTS_NOT_INSTALLED" | "COMMENTS_NOT_FOUND" | "COMMENTS_SEND_OFF">>>;
179
71
  /**
180
72
  * With `forge`: brings the thread's pull request comments in line with the thread now, and posts what failed
181
73
  * before. Every change starts this on its own; `flush()` waits for it.
182
74
  */
183
75
  sync(threadId: string): Promise<void>;
184
- /** Waits for the pull request syncs and `onMention` calls that earlier changes started. On Cloudflare, pass it to `waitUntil`. */
76
+ /** Waits for the pull request syncs, `onMention` calls, and `onComment` `waitUntil` work that earlier changes started. On Cloudflare, pass it to `waitUntil`. */
185
77
  flush(): Promise<void>;
186
78
  }
187
79
  /** Defines Comments for the app: the access policy, the people, the hooks, and the trusted server API. */
188
80
  declare function defineComments(options?: DefineCommentsOptions): Comments;
189
- export { CommentSendPolicy as a, CommentSendWebhooks as c, CommentSendListOptions as i, defineComments as n, CommentSendThread as o, describeCommentContext as r, CommentSendView as s, Comments as t };
81
+ export { defineComments as n, describeCommentContext as r, Comments as t };
package/dist/index.d.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import { A as ElementAnchor, C as CommentStatusInput, D as CommentUser, E as CommentUploadInput, M as PageAnchor, N as TextAnchor, O as CommentUsersInput, S as CommentStatus, T as CommentThread, _ as CommentListCursor, a as CommentBuild, b as CommentMetadata, c as CommentCreateInput, d as CommentDeliveryError, f as CommentEditInput, g as CommentGetInput, h as CommentForgeLink, i as CommentAttachment, j as ImageAnchor, k as CommentsTransport, l as CommentDeleteInput, m as CommentFiles, n as CommentActor, o as CommentComponent, p as CommentEvent, r as CommentAnchor, s as CommentContext, t as AreaAnchor, u as CommentDelivery, v as CommentListQuery, w as CommentSubject, x as CommentReplyInput, y as CommentMessage } from "./types-BX3vH18p.js";
2
- import { _ as commentsRoleAllows, a as CommentsAttachmentFile, c as CommentsCanMentionContext, d as CommentsPeople, f as CommentsPolicyGate, g as CommentsUser, h as CommentsStoreAttachmentContext, i as CommentSubjectDefinition, l as CommentsDefinition, m as CommentsReadAttachmentContext, n as CommentMentionEvent, o as CommentsAuthorize, p as CommentsRateLimit, r as CommentMessageEvent, s as CommentsAuthorizeContext, t as CommentAction, u as CommentsGitHubAccess, v as defaultPolicy, y as defineCommentSubject } from "./define-B1jLSPe9.js";
3
- import { _ as ListCommentThreadsOptions, a as CommentSendPromptContext, c as CommentsForgeTarget, d as CommentsPageSubject, f as CommentsRequestEvent, g as FindCommentThreadInput, h as EditCommentInput, i as CommentSendPayloadContext, l as CommentsIdentifyContext, m as DefineCommentsOptions, n as CommentSendData, o as CommentsErrorCode, p as CreateCommentThreadInput, r as CommentSendOptions, s as CommentsForgeOptions, t as CommentSendAddressContext, u as CommentsPageContext, v as ReplyInput, y as ReplyOptions } from "./types-l6GOb_yc.js";
4
- import { a as CommentSendPolicy, i as CommentSendListOptions, n as defineComments, o as CommentSendThread, r as describeCommentContext, s as CommentSendView, t as Comments } from "./index-D1T7RJ4R.js";
5
- import { r as normalizeCommentPage, t as commentRoom } from "./page-DE71P_gQ.js";
6
- export { type AreaAnchor, type CommentAction, type CommentActor, type CommentAnchor, type CommentAttachment, type CommentBuild, type CommentComponent, type CommentContext, type CommentCreateInput, type CommentDeleteInput, type CommentDelivery, type CommentDeliveryError, type CommentEditInput, type CommentEvent, type CommentFiles, type CommentForgeLink, type CommentGetInput, type CommentListCursor, type CommentListQuery, type CommentMentionEvent, type CommentMessage, type CommentMessageEvent, type CommentMetadata, type CommentReplyInput, type CommentSendAddressContext, type CommentSendData, type CommentSendListOptions, type CommentSendOptions, type CommentSendPayloadContext, type CommentSendPolicy, type CommentSendPromptContext, type CommentSendThread, type CommentSendView, type CommentStatus, type CommentStatusInput, type CommentSubject, type CommentSubjectDefinition, type CommentThread, type CommentUploadInput, type CommentUser, type CommentUsersInput, Comments, type CommentsAttachmentFile, type CommentsAuthorize, type CommentsAuthorizeContext, type CommentsCanMentionContext, type CommentsDefinition, type CommentsErrorCode, type CommentsForgeOptions, type CommentsForgeTarget, type CommentsGitHubAccess, type CommentsIdentifyContext, type CommentsPageContext, type CommentsPageSubject, type CommentsPeople, type CommentsPolicyGate, type CommentsRateLimit, type CommentsReadAttachmentContext, type CommentsRequestEvent, type CommentsStoreAttachmentContext, type CommentsTransport, type CommentsUser, type CreateCommentThreadInput, type DefineCommentsOptions, type EditCommentInput, type ElementAnchor, type FindCommentThreadInput, type ImageAnchor, type ListCommentThreadsOptions, type PageAnchor, type ReplyInput, type ReplyOptions, type TextAnchor, commentRoom, commentsRoleAllows, defaultPolicy, defineCommentSubject, defineComments, describeCommentContext, normalizeCommentPage };
2
+ import { A as CommentsStoreAttachmentContext, C as CommentsDefinition, D as CommentsPolicyGate, E as CommentsPeopleSearchContext, M as commentsRoleAllows, N as defaultPolicy, O as CommentsRateLimit, P as defineCommentSubject, S as CommentsCanMentionContext, T as CommentsPeople, _ as CommentMessageEvent, a as CommentsPageContext, b as CommentsAuthorize, c as CreateCommentThreadInput, d as FindCommentThreadInput, f as ListCommentThreadsOptions, g as CommentMentionEvent, h as CommentAction, i as CommentsIdentifyContext, j as CommentsUser, k as CommentsReadAttachmentContext, l as DefineCommentsOptions, m as ReplyOptions, n as CommentsForgeOptions, o as CommentsPageSubject, p as ReplyInput, r as CommentsForgeTarget, s as CommentsRequestEvent, t as CommentsErrorCode, u as EditCommentInput, v as CommentSubjectDefinition, w as CommentsGitHubAccess, x as CommentsAuthorizeContext, y as CommentsAttachmentFile } from "./types-qzJKgWYS.js";
3
+ import { n as defineComments, r as describeCommentContext, t as Comments } from "./index-d6NsDxu9.js";
4
+ import { c as normalizeCommentPage, t as commentRoom } from "./page-BgvzzsJb.js";
5
+ export { type AreaAnchor, type CommentAction, type CommentActor, type CommentAnchor, type CommentAttachment, type CommentBuild, type CommentComponent, type CommentContext, type CommentCreateInput, type CommentDeleteInput, type CommentDelivery, type CommentDeliveryError, type CommentEditInput, type CommentEvent, type CommentFiles, type CommentForgeLink, type CommentGetInput, type CommentListCursor, type CommentListQuery, type CommentMentionEvent, type CommentMessage, type CommentMessageEvent, type CommentMetadata, type CommentReplyInput, type CommentStatus, type CommentStatusInput, type CommentSubject, type CommentSubjectDefinition, type CommentThread, type CommentUploadInput, type CommentUser, type CommentUsersInput, Comments, type CommentsAttachmentFile, type CommentsAuthorize, type CommentsAuthorizeContext, type CommentsCanMentionContext, type CommentsDefinition, type CommentsErrorCode, type CommentsForgeOptions, type CommentsForgeTarget, type CommentsGitHubAccess, type CommentsIdentifyContext, type CommentsPageContext, type CommentsPageSubject, type CommentsPeople, type CommentsPeopleSearchContext, type CommentsPolicyGate, type CommentsRateLimit, type CommentsReadAttachmentContext, type CommentsRequestEvent, type CommentsStoreAttachmentContext, type CommentsTransport, type CommentsUser, type CreateCommentThreadInput, type DefineCommentsOptions, type EditCommentInput, type ElementAnchor, type FindCommentThreadInput, type ImageAnchor, type ListCommentThreadsOptions, type PageAnchor, type ReplyInput, type ReplyOptions, type TextAnchor, commentRoom, commentsRoleAllows, defaultPolicy, defineCommentSubject, defineComments, describeCommentContext, normalizeCommentPage };
package/dist/index.js CHANGED
@@ -1,9 +1,9 @@
1
- import { C as threadChanged, S as suggest, T as clientRateLimitIssue, a as createThread, b as scopeOf, c as earlierThread, g as replyToThread, l as editMessage, r as can, s as earlierReply } from "./service-BIGe1Hpo.js";
2
- import { a as defineCommentSubject, i as defaultPolicy, n as commentsRoleAllows, s as markCommentsDefinition } from "./define-C2tnAtBU.js";
3
- import { t as commentsErrorDiagnostics } from "./errors-ByCRdInk.js";
4
- import { t as commentsErrors } from "./errors-C0VwRHiy.js";
5
- import { a as runtimeOf, n as pendingKey, o as runtimes, t as commentSendOf } from "./installed-bPUnazFf.js";
6
- import { c as normalizeCommentPage, n as commentRoom } from "./page-2NzFladc.js";
1
+ import { C as threadChanged, S as suggest, T as clientRateLimitIssue, a as createThread, b as scopeOf, c as earlierThread, g as replyToThread, l as editMessage, r as can, s as earlierReply } from "./service-DaMq8TBw.js";
2
+ import { a as defineCommentSubject, i as defaultPolicy, n as commentsRoleAllows, s as markCommentsDefinition } from "./define-C-LUOouq.js";
3
+ import { t as commentsErrorDiagnostics } from "./errors-DeSEHzRf.js";
4
+ import { t as commentsErrors } from "./errors-C5utwZ5H.js";
5
+ import { a as runtimes, i as runtimeOf, t as pendingKey } from "./installed-BqQKo6WC.js";
6
+ import { n as commentRoom, p as normalizeCommentPage } from "./page-CDhmXO-y.js";
7
7
  import { t as describeCommentContext } from "./context-DbkBjITZ.js";
8
8
  // src/index.ts
9
9
  /** A thread that someone deleted during the change: the store reads it again and finds nothing. */
@@ -157,7 +157,6 @@ function defineComments(options = {}) {
157
157
  const thread = await current.store.setStatus(threadId, "open", { id: "" }, Date.now()).catch(gone);
158
158
  if (!thread) return notFound(threadId);
159
159
  await threadChanged(current, thread);
160
- await current.reopened?.(thread);
161
160
  return [void 0, thread];
162
161
  },
163
162
  async remove(threadId) {
@@ -217,19 +216,6 @@ function defineComments(options = {}) {
217
216
  ...subject ? { subject } : {}
218
217
  })];
219
218
  },
220
- async listSends(user, listOptions) {
221
- if (!await runtime()) return notInstalled();
222
- const service = await commentSendOf(comments);
223
- if (!service) return [commentsErrors.COMMENTS_SEND_OFF(), void 0];
224
- return [void 0, await service.listOwn(user, listOptions)];
225
- },
226
- async readSend(user, id, policy) {
227
- if (!await runtime()) return notInstalled();
228
- const service = await commentSendOf(comments);
229
- if (!service) return [commentsErrors.COMMENTS_SEND_OFF(), void 0];
230
- const opened = await service.readOwn(user, id, policy);
231
- return opened ? [void 0, opened] : notFound(id);
232
- },
233
219
  async sync(threadId) {
234
220
  await runtime();
235
221
  await runtimes.get(comments)?.sync?.(threadId);