@alwith/module-chat 0.1.19 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/approval/choice-elicitation-form.js +1 -1
- package/dist/approval/permission-options.js +1 -1
- package/dist/codex/assistant-message.js +2 -2
- package/dist/codex/markdown-renderer.js +3 -3
- package/dist/codex/navigation-audio.js +1 -1
- package/dist/codex/navigation-rail.js +1 -1
- package/dist/codex/virtualized-turn-list.js +1 -1
- package/dist/composer/prompt-input-clipboard.js +1 -1
- package/dist/composer/prompt-input-context.js +1 -1
- package/dist/composer/prompt-input-textarea.js +2 -2
- package/dist/composer/prompt-input.js +1 -1
- package/dist/lib/code-highlighter.js +1 -1
- package/dist/lib/fuzzy.js +1 -1
- package/dist/lib/markdown-parser.js +1 -1
- package/dist/lib/markdown-rules.js +1 -1
- package/dist/lib/stream-style.js +1 -1
- package/dist/lib/streaming-markdown.js +2 -2
- package/dist/search/chat-search.js +1 -1
- package/dist/search/literal-matches.js +1 -1
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as s,jsxs as l}from"react/jsx-runtime";import{autoUpdate as D}from"@floating-ui/dom";import{cn as
|
|
1
|
+
import{jsx as s,jsxs as l}from"react/jsx-runtime";import{autoUpdate as D}from"@floating-ui/dom";import{cn as z}from"cn";import{useCallback as y,useEffect as A,useLayoutEffect as B,useMemo as L,useRef as K,useState as U}from"react";import{createPortal as X}from"react-dom";import{Badge as J}from"../ui/badge.js";import{Button as O}from"../ui/button.js";import{Checkbox as q}from"../ui/checkbox.js";import{Input as H}from"../ui/input.js";import{Label as M}from"../ui/label.js";import{RadioGroup as Y,RadioGroupItem as G}from"../ui/radio-group.js";import{Textarea as Z}from"../ui/textarea.js";import{elicitationFields as ee,elicitationLabels as R,elicitationOptions as I,isMultiSelect as S}from"./choice-schema.js";var d="__other__";function he({current:n,total:P,anchorRef:g,t:u,onAccept:F,onDecline:Q}){let x=L(()=>n?ee(n.requestedSchema):[],[n]),[w,p]=U({}),T=K(null);A(()=>{if(n?.elicitationId===void 0)return;let e={};for(let{key:o,property:r}of x)if(!S(r)){let c=I(r)[0];if(c)e[o]={selected:c.value}}p(e)},[n?.elicitationId,x]),A(()=>{if(n?.elicitationId!==void 0&&T.current&&document.activeElement?.tagName!=="INPUT"&&document.activeElement?.tagName!=="TEXTAREA")T.current.focus()},[n?.elicitationId]);let[b,_]=U(null),[C,V]=U(null),N=y(()=>{let e=g.current;if(!e)return;let o=e.getBoundingClientRect();if(o.width===0){let r=Math.min(640,window.innerWidth*0.9);_({left:(window.innerWidth-r)/2,width:r,bottom:24});return}_({left:o.left,width:o.width,bottom:window.innerHeight-o.bottom+20})},[g]);B(()=>{if(!n)return;let e=0,o=()=>{if(g.current){N();return}e=requestAnimationFrame(o)};return o(),()=>cancelAnimationFrame(e)},[n,N,g]),B(()=>{let e=g.current;if(!n||!e||!C)return;return D(e,C,N,{animationFrame:!0})},[n,C,g,N]);let E=L(()=>{if(!n)return!1;for(let{key:e,property:o}of x){let r=w[e];if(!r)return!1;if(S(o)){if(!r.selectedSet||r.selectedSet.size===0)return!1;if(r.selectedSet.has(d)&&!r.otherText?.trim())return!1}else{if(!r.selected)return!1;if(r.selected===d&&!r.otherText?.trim())return!1}}return!0},[n,x,w]),W=y(async()=>{if(!n)return;if(!E)return;let e={},o={};for(let{key:r,property:c}of x){let a=w[r];if(!a)continue;let f;if(S(c))e[r]=[...a.selectedSet??[]].map((m)=>m===d?(a.otherText??"").trim():m).filter(Boolean);else{let m=a.selected??"";if(e[r]=m===d?(a.otherText??"").trim():m,m!==d)f=I(c).find((t)=>t.value===m)?.preview}let h=a.notes?.trim();if(f||h)o[r]={...f&&{preview:f},...h&&{notes:h}}}await F(n.elicitationId,e,o)},[n,x,w,E,F]),j=y(async()=>{if(n)await Q(n.elicitationId)},[n,Q]);if(!n||!b)return null;return X(l("div",{"data-overlay":"ask-user-question",tabIndex:0,onKeyDown:(e)=>{if(e.key==="Escape")e.preventDefault(),j()},className:"bg-card border-border fixed z-50 flex flex-col overflow-hidden rounded-lg border shadow-lg outline-none",style:{left:b.left,width:b.width,bottom:b.bottom,maxHeight:"70vh"},ref:(e)=>{T.current=e,V(e)},children:[l("div",{className:"border-border flex shrink-0 items-center justify-between gap-2 border-b px-3 py-2",children:[s("div",{className:"text-foreground text-sm font-medium",children:u("askUserQuestion.title")}),P>1&&s("span",{className:"text-muted-foreground shrink-0 text-xs",children:`1 / ${P}`})]}),s("div",{className:"min-h-0 flex-1 overflow-y-auto",children:s("div",{className:"space-y-4 px-3 py-3",children:x.map(({key:e,property:o},r)=>{let c=w[e],a=c?.selected,f=c?.selectedSet??new Set,h=I(o),m=S(o);return l("div",{className:"space-y-2",children:[l("div",{className:"flex items-center gap-2",children:[s(J,{variant:"secondary",className:"font-mono text-[10px] tracking-wide uppercase",children:R(o).title??e}),s("div",{className:"text-foreground text-sm font-medium",children:R(o).description})]}),m?l("div",{className:"space-y-1.5 ps-1",children:[h.map((t)=>l("label",{className:"hover:bg-muted/40 flex cursor-pointer items-center gap-2 rounded-sm px-1.5 py-1",children:[s(q,{checked:f.has(t.value),onCheckedChange:(i)=>{p((v)=>{let k=new Set(v[e]?.selectedSet??new Set);if(i)k.add(t.value);else k.delete(t.value);return{...v,[e]:{...v[e],selectedSet:k}}})}}),l("div",{className:"min-w-0 flex-1",children:[s("div",{className:"text-foreground text-sm",children:t.label}),t.description&&s("div",{className:"text-muted-foreground text-xs",children:t.description})]})]},t.value)),l("label",{className:"hover:bg-muted/40 flex cursor-pointer items-center gap-2 rounded-sm px-1.5 py-1",children:[s(q,{checked:f.has(d),onCheckedChange:(t)=>{p((i)=>{let v=new Set(i[e]?.selectedSet??new Set);if(t)v.add(d);else v.delete(d);return{...i,[e]:{...i[e],selectedSet:v}}})}}),s("div",{className:"text-foreground min-w-0 flex-1 text-sm",children:u("askUserQuestion.other")})]}),f.has(d)&&s("div",{className:"ps-7",children:s(H,{placeholder:u("askUserQuestion.otherPlaceholder"),value:c?.otherText??"",onChange:(t)=>p((i)=>({...i,[e]:{...i[e],otherText:t.target.value}}))})})]}):l(Y,{value:a??"",onValueChange:(t)=>p((i)=>({...i,[e]:{...i[e],selected:t}})),className:"space-y-1.5 ps-1",children:[h.map((t)=>{let i=`${r}:${t.value}`;return l("div",{className:z("hover:bg-muted/40 flex cursor-pointer items-center gap-2 rounded-sm px-1.5 py-1",a===t.value&&"bg-muted/60"),children:[s(G,{value:t.value,id:i}),l(M,{htmlFor:i,className:"min-w-0 flex-1 cursor-pointer",children:[s("div",{className:"text-foreground text-sm font-normal",children:t.label}),t.description&&s("div",{className:"text-muted-foreground text-xs font-normal",children:t.description})]})]},t.value)}),l("div",{className:z("hover:bg-muted/40 flex items-center gap-2 rounded-sm px-1.5 py-1",a===d&&"bg-muted/60"),children:[s(G,{value:d,id:`${r}:other`,className:"mt-0.5"}),s(M,{htmlFor:`${r}:other`,className:"text-foreground min-w-0 flex-1 cursor-pointer text-sm font-normal",children:u("askUserQuestion.other")})]}),a===d&&s("div",{className:"ps-7",children:s(H,{placeholder:u("askUserQuestion.otherPlaceholder"),value:c?.otherText??"",onChange:(t)=>p((i)=>({...i,[e]:{...i[e],otherText:t.target.value}}))})})]}),!m&&a&&a!==d&&(()=>{let t=h.find((i)=>i.value===a)?.preview;if(!t)return null;return s("pre",{className:"bg-muted/50 text-muted-foreground ms-1 mt-1 overflow-auto rounded-sm px-2 py-1.5 font-mono text-[11px] whitespace-pre-wrap",children:t})})(),h.some((t)=>t.preview)&&s(Z,{placeholder:u("askUserQuestion.notesPlaceholder"),value:c?.notes??"",onChange:(t)=>p((i)=>({...i,[e]:{...i[e],notes:t.target.value}})),rows:1,className:"min-h-0 resize-none text-xs"})]},e)})})}),l("div",{className:"border-border bg-card flex shrink-0 items-center justify-end gap-2 border-t px-3 py-2",children:[s(O,{variant:"ghost",size:"sm",onClick:()=>void j(),children:u("askUserQuestion.cancel")}),s(O,{size:"sm",disabled:!E,onClick:()=>void W(),children:u("askUserQuestion.submit")})]})]}),document.body)}export{he as ChoiceElicitationForm};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var e={allow_once:0,allow_always:1,reject_once:2,reject_always:3};function n(o){return[...o].toSorted((l,t)=>(e[l.kind]??99)-(e[t.kind]??99))}function a(o){return o==="allow_once"||o==="allow_always"}function r(o){return o==="allow_always"||o==="reject_always"}export{e as PERMISSION_KIND_GROUP_ORDER,a as isAllowKind,r as isAlwaysKind,n as sortPermissionOptions};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as n,jsxs as f}from"react/jsx-runtime";import{cn as B}from"cn";import{ActivityMarkdown as C,useActivityHost as k}from"../activity-host.js";import{groupBlocksForStyle as T}from"../lib/group-blocks.js";import{describeToolUse as j}from"../lib/stream-style.js";import{CodexActivityGroup as E,CodexWorkSection as S}from"./activity-group.js";import{CodexEditedFilesCard as G}from"./edited-files-card.js";import{CodexPlan as O}from"./plan.js";import{CopyAction as
|
|
2
|
-
`),I=!t.streaming&&g.trim().length>0?n(W,{text:g,isMostRecentTurn:i,beforeCopy:s,afterCopy:l,time:o}):null,c=T(t.content,"compact"),u=c.reduce((e,a,d)=>a.kind==="codexActivityGroup"?d:e,-1),h=c.findIndex((e,a)=>a>u&&e.kind==="block"&&e.block.type==="text"),M=[...t.content].
|
|
1
|
+
import{jsx as n,jsxs as f}from"react/jsx-runtime";import{cn as B}from"cn";import{ActivityMarkdown as C,useActivityHost as k}from"../activity-host.js";import{groupBlocksForStyle as T}from"../lib/group-blocks.js";import{describeToolUse as j}from"../lib/stream-style.js";import{CodexActivityGroup as E,CodexWorkSection as S}from"./activity-group.js";import{CodexEditedFilesCard as G}from"./edited-files-card.js";import{CodexPlan as O}from"./plan.js";import{CopyAction as R}from"./user-message.js";var v=new WeakMap,D=1;function A(t){if(t.type==="tool_use"||t.type==="subagent"||t.type==="collab")return`${t.type}:${t.id}`;let i=v.get(t);if(i!==void 0)return`${t.type}:${i}`;let r=D++;return v.set(t,r),`${t.type}:${r}`}function H({block:t,streaming:i,actions:r}){if(t.isApiError)return n("div",{className:"codex-stream-error",children:t.text});return f("div",{className:"codex-assistant-message",children:[n(C,{text:t.text,streaming:i}),r]})}function K({block:t,streaming:i,actions:r,renderText:o}){switch(t.type){case"text":return o===void 0?n(H,{block:t,streaming:i,actions:r}):o({block:t,streaming:i,actions:r});case"thinking":return t.thinking.length>0?n(C,{text:t.thinking,streaming:!t.isComplete}):null;case"plan":return n(O,{entries:t.entries});case"image":return n("img",{src:`data:${t.source.media_type};base64,${t.source.data}`,className:"max-h-64 rounded",alt:""});case"tool_use":case"subagent":case"collab":return null}}var P=new Set;function Y({message:t,isMostRecentTurn:i,hiddenTools:r=P,time:o,beforeCopy:s,afterCopy:l,providerIcon:w,renderText:_,renderEditedFiles:m}){if(t.streaming===!0&&t.content.every((e)=>e.type==="text"?e.text.length===0:e.type==="thinking"?e.thinking.length===0:!1))return n(N,{});let g=t.content.filter((e)=>e.type==="text").map((e)=>e.text).join(`
|
|
2
|
+
`),I=!t.streaming&&g.trim().length>0?n(W,{text:g,isMostRecentTurn:i,beforeCopy:s,afterCopy:l,time:o}):null,c=T(t.content,"compact"),u=c.reduce((e,a,d)=>a.kind==="codexActivityGroup"?d:e,-1),h=c.findIndex((e,a)=>a>u&&e.kind==="block"&&e.block.type==="text"),M=[...t.content].toReversed().find((e)=>e.type==="text"),p=t.content.filter((e)=>e.type==="tool_use"&&j(e).category==="edit"),y=(e)=>{if(e.kind==="codexActivityGroup"){let a=e.blocks.filter((d)=>d.type!=="tool_use"||!r.has(d.name));return a.length===0?null:n(E,{blocks:a},`activity:${A(a[0])}`)}if(e.kind!=="block")throw Error(`Codex received an incompatible grouped entry: ${e.kind}`);return n(K,{block:e.block,streaming:Boolean(t.streaming),actions:e.block===M?I:void 0,renderText:_},A(e.block))},x=u===-1?0:h===-1?c.length:h;return n(F,{stateKey:t.id,active:Boolean(t.streaming),startedAt:t.startedAt,durationMs:t.durationMs,providerId:t.providerId,providerIcon:w,work:c.slice(0,x).map(y),answer:c.length>x?c.slice(x).map(y):null,footer:u!==-1&&p.length>0&&(m===void 0?n(G,{blocks:p}):m(p))})}function W({text:t,isMostRecentTurn:i=!1,beforeCopy:r,afterCopy:o,time:s}){let{t:l}=k();return f("div",{className:B("mt-1.5 flex h-5 w-fit -translate-x-1 items-center justify-start gap-0.5 [&_*]:transition-none",i?"opacity-100":"opacity-0 group-focus-within/am:opacity-100 group-hover/am:opacity-100"),children:[r,n(R,{text:t,label:l("actions.copy")}),o,s&&n("span",{className:"codex-user-time ms-1",title:s.full,children:s.short})]})}function N(){let{t}=k();return n("div",{className:"codex-pending-message py-2",role:"status",children:n("span",{className:"codex-activity-running",children:t("message.thinking")})})}function F({work:t,answer:i,footer:r,loading:o=!1,...s}){if(o)return n(N,{});return f("div",{className:"group/am codex-assistant-turn",children:[t.length>0&&n(S,{...s,children:t}),i!==null&&(t.length===0?i:n("div",{"data-local-conversation-final-assistant":!0,"data-testid":"codex-final-answer",className:"codex-final-answer",children:i})),r]})}export{Y as CodexAssistantMessage,F as CodexAssistantTurn,W as CodexMessageActions};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import{jsx as a,jsxs as h,Fragment as U}from"react/jsx-runtime";import{decodeHTMLAttribute as M,decodeHTMLStrict as L}from"entities";import ae from"katex";import{CheckIcon as H,ChevronLeftIcon as ie,ChevronRightIcon as se,CopyIcon as ce,DownloadIcon as de,FileIcon as le,LinkIcon as ue,MailIcon as me,XIcon as he}from"lucide-react";import"katex/dist/katex.min.css";import{createContext as fe,createElement as B,memo as X,startTransition as pe,useContext as ge,useEffect as g,useLayoutEffect as D,useMemo as G,useRef as w,useState as p}from"react";import{createCodeHighlighter as we}from"../lib/code-highlighter.js";import{cachedMarkdown as ke,createMarkdownParser as xe}from"../lib/markdown-parser.js";import{isSafeMarkdownUrl as V}from"../lib/markdown-rules.js";var Z=fe(null);function v(){let e=ge(Z);if(e===null)throw Error("Markdown host is missing");return e}var be=80,j=/\[([^\]\n]+)\]\(([^)\n]+)$/,Ce=/(^|\n)[^\S\n]*!\[[^\]\n]*(?:\](?:\([^\n]*)?)?\s*$/,Ne=/\uE200[^\uE201]*$/,Me=4,ve=new Set("7zipx.accdb.asarpack.asciidoc.backup.backupdb.bundle.ccproj.cdrdao.code-workspace.config.debugin.deploy.design.docbook.dockerfile.dockerignore.editorconfig.eslintignore.gitattributes.gitignore.gitignore.gitkeep.gradle.graphqls.ignore.ipynb.keychain.keynote.licensee.lockfile.lockfile.markdown.markup.matlab.mkdocs.models.module.msstyle.notebook.npmignore.output.packageinfo.parquet.pickle.plistx.policy.postcssrc.prettierignore.projectfile.python.readme.review.robots.schema.search.series.settingsjson.shader.sqlite.sqlite3.storyboard.styles.system.target.terraform.update.vertex.webapp.webdoc.webpackrc.widget.workspace.xcodeproj.yarnlock".split("."));function E(e,n){let t=0;for(let r=n-1;r>=0&&e[r]==="\\";r-=1)t+=1;return t%2===1}function J(e,n,t){if(t.length!==1)return!1;return e[n-1]===t||e[n+1]===t}function Ee(e,n){let t=0;for(let r=0;r<=e.length-n.length;){if(e.startsWith(n,r)&&!E(e,r)&&!J(e,r,n)){t+=1,r+=n.length;continue}r+=1}return t}function Ie(e,n){for(let t=e.length-n.length;t>=0;t-=1)if(e.startsWith(n,t)&&!E(e,t)&&!J(e,t,n))return t;return-1}function Te(e,n){let t=0;for(let r=0;r<=e.length-n.length;){if(e.startsWith(n,r)&&!E(e,r)){t+=1,r+=n.length;continue}r+=1}return t}function $e(e){return Te(e,"```")%2===1}function Y(e){let n=0;for(let t=0;t<e.length;){if(e.startsWith("```",t)){for(t+=3;t<e.length&&!e.startsWith("```",t);)t+=1;if(t<e.length)t+=3;continue}if(e[t]==="`"&&!E(e,t))n+=1;t+=1}return n%2===1}function ye(e){return e.endsWith(`
|
|
2
2
|
`)?`${e}\`\`\``:`${e}
|
|
3
3
|
\`\`\``}function O(e,n){if(!e.includes(n)||Ee(e,n)%2===0)return e;let t=Ie(e,n);if(t<0)return e;let r=e.slice(t+n.length);if(r.length===0||/^\s/.test(r)||r.includes(`
|
|
4
|
-
`)||Y(r))return e;return`${e}${n}`}function Le(e){return e.startsWith("/")&&!e.startsWith("//")||/^[A-Za-z]:[\\/]/.test(e)||/^\\\\[^\\]+\\[^\\]+/.test(e)||/^\/\/[^/]+\/[^/]+/.test(e)}function Q(e){let n=e.
|
|
5
|
-
`),t.raw=e.slice(n,i).map((s)=>s.raw).join(""),e.splice(n+1,i-n-1)}}function P(e){return{type:"text",raw:e,text:e}}function Oe(e){return{type:"paragraph",raw:e.raw,text:e.text,tokens:e.tokens??[e]}}function y(e){for(let n of e){if(n.type==="list")for(let t of n.items){let r=t.tokens[0];if(r?.type==="heading"){let o=r.raw.trimEnd(),i
|
|
6
|
-
`,1)[0];if(t===void 0)throw Error("Codex Markdown token has no first line");
|
|
4
|
+
`)||Y(r))return e;return`${e}${n}`}function Le(e){return e.startsWith("/")&&!e.startsWith("//")||/^[A-Za-z]:[\\/]/.test(e)||/^\\\\[^\\]+\\[^\\]+/.test(e)||/^\/\/[^/]+\/[^/]+/.test(e)}function Q(e){let n=e.replaceAll("`","").trim(),t=n.match(/^(.*?):(\d+)(?::(\d+))?(?:[-–](\d+)(?::(\d+))?)?$/);if(t!==null){let[,o,i,s,c,d]=t;if(o===void 0||i===void 0)throw Error("Codex file location is incomplete");return{path:o,line:Number.parseInt(i,10),column:s===void 0?void 0:Number.parseInt(s,10),endLine:c===void 0?void 0:Number.parseInt(c,10),endColumn:d===void 0?void 0:Number.parseInt(d,10)}}let r=n.match(/^(.*?)#L(\d+)(?:C(\d+))?(?:-L(\d+)(?:C(\d+))?)?$/);if(r!==null){let[,o,i,s,c,d]=r;if(o===void 0||i===void 0)throw Error("Codex hash file location is incomplete");return{path:o,line:Number.parseInt(i,10),column:s===void 0?void 0:Number.parseInt(s,10),endLine:c===void 0?void 0:Number.parseInt(c,10),endColumn:d===void 0?void 0:Number.parseInt(d,10)}}return{path:n}}function _e(e){let{path:n,line:t,column:r,endLine:o,endColumn:i}=Q(e);if(/^[a-z][a-z0-9+.-]*:\/\//i.test(n)||/^www\./i.test(n)||/^(mailto|tel):/i.test(n))return!1;if(t!==void 0||r!==void 0||o!==void 0||i!==void 0)return!0;if(!/(?:^|[\\/])[^\\/]+\.(?!\d+$)[^\\/.]+$/i.test(n))return!1;let s=/[\\/]/.test(n),c=n.split(/[\\/]/).at(-1);if(c===void 0)throw Error("Codex streaming link target has no file name");let d=c.split(".").at(-1);if(d===void 0||d.length===0)return!1;if(!s&&/[a-z]/.test(d)&&/[A-Z]/.test(d.slice(1)))return!1;if(!s){let u=d.toLowerCase();if(u.length>Me&&!ve.has(u))return!1}return!0}function Se(e){let{path:n}=Q(e);if(Le(n))return!0;try{return new URL(n).protocol==="file:"}catch{return!1}}function Ae(e){let n=e.match(j);if(n===null)return e;let t=n[2];if(t===void 0)throw Error("Codex streaming link target is missing");return _e(t)||Se(t)?e.replace(j,"$1"):`${e})`}function Fe(e){let n=e.replace(Ne,"");if(n.length===0||n.includes("`")&&Y(n))return{isCodeFenceOpen:!1,markdown:n};if(n.includes("```")&&$e(n))return{isCodeFenceOpen:!0,markdown:ye(n)};if(n.includes(")n=Ae(n);return n=O(n,"**"),n=O(n,"*"),{isCodeFenceOpen:!1,markdown:n}}function je(e){return e?.type==="paragraph"&&"tokens"in e&&Array.isArray(e.tokens)}function R(e){return je(e)&&e.tokens.length===1&&e.tokens[0]?.type==="image"}function ee(e){for(let n=0;n<e.length;n+=1){let t=e[n];if(t===void 0)throw Error(`Codex Markdown token is missing at index ${n}`);if("tokens"in t&&Array.isArray(t.tokens))ee(t.tokens);if(!R(t))continue;let r=[...t.tokens],o=n+1,i=o;for(;;){while(e[o]?.type==="space")o+=1;let s=e[o];if(!R(s))break;r.push(...s.tokens),o+=1,i=o}if(i===n+1)continue;t.tokens=r,t.text=r.map((s)=>s.raw).join(`
|
|
5
|
+
`),t.raw=e.slice(n,i).map((s)=>s.raw).join(""),e.splice(n+1,i-n-1)}}function P(e){return{type:"text",raw:e,text:e}}function Oe(e){return{type:"paragraph",raw:e.raw,text:e.text,tokens:e.tokens??[e]}}function y(e){for(let n of e){if(n.type==="list")for(let t of n.items){let r=t.tokens[0];if(r?.type==="heading"){let o=r,i=o.raw.trimEnd(),s=i.match(/^#{1,6}\s+/)?.[0];if(s!==void 0)t.tokens[0]={type:"paragraph",raw:o.raw,text:i,tokens:o.tokens===void 0?[P(i)]:[P(s),...o.tokens]}}if(t.loose)t.tokens=t.tokens.map((o)=>o.type==="text"?Oe(o):o);y(t.tokens)}if("tokens"in n&&Array.isArray(n.tokens))y(n.tokens)}}function Re(e,n,t){e.preventDefault(),e.stopPropagation(),t.openLink(n)}function Pe(e){try{let n=new URL(e);return n.protocol!=="http:"&&n.protocol!=="https:"?null:`${n.origin}/favicon.ico`}catch{return null}}function We(e){let n=Pe(e);return n===null?[]:[n,`https://www.google.com/s2/favicons?domain=${new URL(e).origin}&sz=32`]}function qe({href:e}){let n=G(()=>We(e),[e]),[t,r]=p(),o=n.length===0&&!/^[a-z][a-z0-9+.-]*:/i.test(e),i=e.toLowerCase().startsWith("mailto:")?me:o?le:ue;return h("span",{className:"codex-markdown-favicon",children:[t===void 0?a("span",{className:"codex-markdown-favicon-fallback",children:a(i,{"aria-hidden":!0})}):null,n.map((s)=>a("img",{alt:"",className:t===s?"codex-markdown-favicon-image-loaded":void 0,decoding:"async",draggable:!1,referrerPolicy:"no-referrer",src:s,onLoad:()=>r((c)=>c!==void 0&&n.includes(c)?c:s)},s))]})}function ze({children:e,href:n,title:t}){let r=v();if(r.preview)return a("span",{children:e});return a("a",{className:"codex-markdown-link","data-inline-mention-interactive":"",href:n,title:t,onClick:(o)=>Re(o,n,r),children:h("span",{className:"codex-markdown-link-mention","data-layout":"inline-flow","data-interactive":"","data-underline-on-hover":"",children:[a("span",{className:"codex-markdown-link-icon-container","data-markdown-copy":"exclude",children:a(qe,{href:n})}),a("span",{className:"codex-markdown-link-label",children:e})]})})}function Ke({code:e,language:n}){let{theme:t,copyLabel:r}=v(),o=w(null),[i,s]=p(null),[c,d]=p(null),[u,k]=p(!1);if(g(()=>{let f=we(s,d);return o.current=f,()=>{f.dispose(),o.current=null}},[]),g(()=>{let f=o.current;if(f===null)throw Error("Code highlighter is not mounted");f.update(e,n)},[e,n]),c!==null)throw c;let b=i!==null&&i.code===e&&i.language===n?i.html:null,C=()=>{navigator.clipboard.writeText(e),k(!0),window.setTimeout(()=>k(!1),2000)};return h("div",{className:"codex-markdown-code-block","data-markdown-copy":"code-block","data-markdown-copy-text":e,"data-theme":t==="dark"?"dark":"light",children:[h("div",{className:"codex-markdown-code-header","data-markdown-copy":"exclude",children:[a("div",{className:"codex-markdown-code-title",children:n}),a("div",{className:"codex-markdown-code-actions",children:a("button",{type:"button",className:"codex-markdown-code-copy",title:r,onClick:C,children:u?a(H,{}):a(ce,{})})})]}),a("div",{className:"codex-markdown-code-container",dir:"ltr",children:a("code",{className:"codex-markdown-code-content hljs",...b===null?{children:e}:{dangerouslySetInnerHTML:{__html:b}}})})]})}function Ue({code:e,language:n}){return v().preview?a("span",{children:e}):a(He,{code:e,language:n})}function He({code:e,language:n}){let t=w(null),[r,o]=p(!1);if(g(()=>{if(r)return;let i=t.current;if(i===null)throw Error("Codex code block placeholder is not mounted");if(typeof IntersectionObserver>"u"){let c=window.setTimeout(()=>o(!0),0);return()=>window.clearTimeout(c)}let s=new IntersectionObserver((c)=>{if(!c.some((d)=>d.isIntersecting))return;o(!0),s.disconnect()},{rootMargin:"600px 0px"});return s.observe(i),()=>s.disconnect()},[r]),r)return a(Ke,{code:e,language:n});return a("div",{ref:t,className:"codex-markdown-code-block",children:a("pre",{className:"codex-markdown-code-placeholder",children:a("code",{children:e})})})}function Be(e){let n=[...document.body.querySelectorAll('[data-markdown-image-preview-trigger="true"]')],t=n.map((o)=>{let i=o.querySelector("img");if(i===null)throw Error("Codex image preview trigger has no image");return{src:i.currentSrc||i.src,alt:i.alt}}),r=n.indexOf(e);if(r===-1)throw Error("Codex image preview trigger is outside the document");return{images:t,index:r}}function Xe({preview:e,setPreview:n}){let t=e.images[e.index];if(t===void 0)throw Error(`Codex image preview index is out of range: ${e.index}`);return h("div",{className:"codex-markdown-image-preview",children:[a("img",{src:t.src,alt:t.alt}),h("div",{className:"codex-markdown-image-preview-actions",children:[a("button",{type:"button","aria-label":"Previous image",disabled:e.index===0,onClick:()=>n({...e,index:e.index-1}),children:a(ie,{})}),a("a",{href:t.src,download:!0,"aria-label":"Download image",children:a(de,{})}),a("button",{type:"button","aria-label":"Next image",disabled:e.index===e.images.length-1,onClick:()=>n({...e,index:e.index+1}),children:a(se,{})}),a("button",{type:"button","aria-label":"Close image preview",onClick:()=>n(void 0),children:a(he,{})})]})]})}function De(e){return v().preview?a(U,{children:e.alt}):a(Ge,{...e})}function Ge({src:e,alt:n,title:t,allowWide:r}){let o=w(null),[i,s]=p();g(()=>{let d=o.current;if(d===null)throw Error("Codex image preview dialog is not mounted");if(i===void 0){if(d.open)d.close();return}if(!d.open)d.showModal()},[i]);let c=n.length===0?"Open image preview":n;return h(U,{children:[a("button",{type:"button",className:`codex-markdown-image-trigger${r?"codex-markdown-image-trigger-wide":""}`,"aria-label":c,"data-markdown-image-preview-trigger":"true",onClick:(d)=>s(Be(d.currentTarget)),children:a("img",{className:`codex-markdown-image${r?"codex-markdown-image-wide":""}`,src:e,alt:n,title:t,loading:"lazy"})}),a("dialog",{ref:o,className:"codex-markdown-image-dialog","aria-label":c,onClose:()=>s(void 0),children:i===void 0?null:a(Xe,{preview:i,setPreview:s})})]})}function Ve({value:e,display:n}){let t=w(null);return D(()=>{if(t.current===null)throw Error("Codex math root is not mounted");ae.render(e,t.current,{displayMode:n,throwOnError:!1})},[n,e]),a("span",{ref:t,className:n?"codex-markdown-math-block":"codex-markdown-inline-math"})}var Ze=150,N=null;function W(e,n){let t=N;if(t===null)return e;let r=t.cursor,o=r+e.length;t.cursor=o;let i=[],s=r;for(let c of t.runs){if(c.end<=r)continue;if(c.start>=o)break;let d=Math.max(r,c.start),u=Math.min(o,c.end);if(s<d)i.push(e.slice(s-r,d-r));i.push(a("span",{className:"codex-markdown-fade",children:e.slice(d-r,u-r)},`${n}:${t.generation}:${c.start}`)),s=u}if(s<o)i.push(e.slice(s-r));return i}function ne(e){let n=5381;for(let t=0;t<e.length;t+=1)n=(n*33+e.charCodeAt(t))%4294967296;return n.toString(36)}function q(e){let n=e.trim();if(n.length===0)return"";let t=n.split(`
|
|
6
|
+
`,1)[0];if(t===void 0)throw Error("Codex Markdown token has no first line");return(t.match(/\S+/)?.[0]??t).slice(0,be)}function Je(e){switch(e.type){case"code":return e.raw.trimStart().match(/^(```|~~~)/)?.[1]??"";case"link":return e.href;case"image":{let n=e;return`${n.href}:${q(n.text)}`}case"html":case"space":case"br":case"hr":case"def":return e.raw;case"math":return q(e.text);default:return""}}function te(e){return`${e.type==="math"?`math-${e.display?"block":"inline"}`:e.type}-${ne(Je(e))}`}function m(e,n){let t=new Map;return e.map((r)=>{let o=te(r),i=t.get(o)??0;return t.set(o,i+1),re(r,`${n}-${o}-${i}`)})}function Ye(e,n){let t=e.task?e.tokens.filter((r)=>r.type!=="checkbox"):e.tokens;return h("li",{className:`codex-markdown-list-item${e.task?"codex-markdown-task-list-item":""}`,children:[e.task?h("div",{className:"codex-markdown-task-checkbox",children:[a("input",{type:"checkbox",className:"codex-markdown-checkbox",checked:e.checked,"data-state":e.checked?"checked":"unchecked",readOnly:!0,disabled:!0}),e.checked?a(H,{}):null]}):null,m(t,n)]},n)}function Qe(e,n){let r=`codex-markdown-list ${e.items.some((i)=>i.task)?"codex-markdown-task-list":e.ordered?"codex-markdown-ordered-list":"codex-markdown-unordered-list"}`,o=m(e.items,n);return e.ordered?a("ol",{className:r,start:e.start===""?void 0:e.start,children:o},n):a("ul",{className:r,children:o},n)}function z(e,n,t){let r=t?"th":"td",o=/^\d+$/.test(e.text);return B(r,{key:n,className:`${t?"codex-markdown-table-header":"codex-markdown-table-cell"}${o?" codex-markdown-numeric-table-cell":""}`,align:e.align??void 0},...m(e.tokens,n))}function en(e,n){let t=new Map;return a("div",{className:"codex-markdown-table-container","data-markdown-table":!0,tabIndex:-1,children:a("div",{className:"codex-markdown-table-scroller",children:a("div",{className:"codex-markdown-table-wrapper",children:h("table",{className:"codex-markdown-table",children:[a("thead",{children:a("tr",{className:"codex-markdown-table-row",children:e.header.map((r,o)=>z(r,`${n}-header-${o}`,!0))})}),a("tbody",{className:"codex-markdown-table-body",children:e.rows.map((r)=>{let o=ne(r.map((c)=>c.text).join("\x00")),i=t.get(o)??0;t.set(o,i+1);let s=`${n}-row-${o}-${i}`;return a("tr",{className:"codex-markdown-table-row",children:r.map((c,d)=>z(c,`${s}-cell-${d}`,!1))},s)})})]})})})},n)}function K(e,n,t){let r=M(e.href);if(!V(r))return null;return a(De,{src:r,alt:L(e.text),title:e.title==null?void 0:M(e.title),allowWide:t},n)}function re(e,n){switch(e.type){case"space":case"def":case"internalMessage":return null;case"hr":return a("hr",{className:"codex-markdown-horizontal-rule"},n);case"heading":{let t=e,o={1:"h1",2:"h2",3:"h3",4:"h4",5:"h5",6:"h6"}[t.depth];if(o===void 0)throw Error(`Unsupported Codex Markdown heading depth: ${t.depth}`);return B(o,{key:n,className:`codex-markdown-heading codex-markdown-heading-${t.depth}`},...m(t.tokens,n))}case"paragraph":{let t=e,r=t.tokens.filter((s)=>s.type!=="space"&&s.type!=="br"),o=r.length>0&&r.every((s)=>s.type==="image"),i=o&&r.length>1;return a("p",{className:`codex-markdown-paragraph${o?"codex-markdown-media-paragraph codex-markdown-media-wide-block":""}${i?"codex-markdown-media-grid-paragraph":""}`,"data-markdown-image-grid":i?"true":void 0,"data-wide-markdown-block":o?"true":void 0,"data-wide-markdown-block-kind":o?"image":void 0,children:o?r.map((s,c)=>K(s,`${n}-image-${c}`,!0)):m(t.tokens,n)},n)}case"text":{let t=e;return t.tokens===void 0?W(L(t.text),n):m(t.tokens,n)}case"escape":return W(e.text,n);case"strong":return a("strong",{className:"codex-markdown-strong",children:m(e.tokens,n)},n);case"em":return a("em",{children:m(e.tokens,n)},n);case"del":return a("del",{children:m(e.tokens,n)},n);case"codespan":return a("span",{className:"codex-markdown-inline-code",dir:"ltr","data-markdown-copy":"inline-code",children:e.text},n);case"br":return a("br",{},n);case"link":{let t=e,r=m(t.tokens,n),o=M(t.href);return V(o)?a(ze,{href:o,title:t.title==null?void 0:M(t.title),children:r},n):a("span",{children:r},n)}case"image":return K(e,n,!1);case"code":{let t=e;return a(Ue,{code:t.text,language:t.lang},n)}case"blockquote":return a("blockquote",{className:"codex-markdown-blockquote",children:m(e.tokens,n)},n);case"list":return Qe(e,n);case"list_item":return Ye(e,n);case"table":return en(e,n);case"html":{let t=e;return/^<br\s*\/?>$/i.test(t.raw.trim())?a("br",{},n):t.raw}case"math":{let t=e;return a(Ve,{value:t.text,display:t.display},n)}default:throw Error(`Unsupported Codex Markdown token: ${JSON.stringify(e)}`)}}function x(e){switch(e.type){case"text":{let n=e;return n.tokens===void 0?L(n.text):n.tokens.map(x).join("")}case"escape":return e.text;case"paragraph":case"heading":case"strong":case"em":case"del":case"link":case"blockquote":case"list_item":return e.tokens.map(x).join("");case"list":return e.items.map(x).join("");case"table":{let n=e;return[n.header,...n.rows].map((t)=>t.map((r)=>r.tokens.map(x).join("")).join("")).join("")}default:return""}}function nn({token:e,tokenKey:n,offset:t,runs:r,generation:o}){let i=N;try{return N={cursor:t,runs:r,generation:o},re(e,n)}finally{N=i}}var tn=X(function({result:n}){let{text:t,isStreaming:r}=n,o=G(()=>{let l=n.tokens;if(n.source.includes("!["))ee(l);y(l);let _=new Map,S=0;return l.map((I)=>{let T=te(I),A=_.get(T)??0;_.set(T,A+1);let F=x(I),oe={token:I,tokenKey:`root-${T}-${A}`,offset:S,visibleText:F};return S+=F.length,oe})},[n]),i=o.map((l)=>l.visibleText).join(""),s=w({text:"",visibleText:"",runs:[],generation:0}),c=s.current,d=t.startsWith(c.text)||i.startsWith(c.visibleText),u=d?c.visibleText.length:0,k=performance.now(),b=r&&d?c.runs.filter((l)=>k-l.firstSeenAtMs<Ze):[],C=c.generation+(d?0:1),f={text:t,visibleText:i,runs:b.filter((l)=>l.start<i.length).map((l)=>({...l,end:Math.min(l.end,i.length)})),generation:C};if(r&&i.length>u)f.runs.push({start:u,end:i.length,firstSeenAtMs:k});return D(()=>{s.current=f}),a("div",{dir:"auto",className:"codex-markdown-content codex-markdown-root","data-streaming":r?"true":void 0,children:o.map((l)=>a(nn,{token:l.token,tokenKey:l.tokenKey,offset:l.offset,runs:f.runs,generation:C},l.tokenKey))})}),rn=X(function({text:n,isStreaming:t}){let r=w(null),[o,i]=p(()=>ke(n,t)),[s,c]=p(null);if(g(()=>{let d=xe((u)=>{pe(()=>i(u))},c);return r.current=d,()=>{d.dispose(),r.current=null}},[]),g(()=>{let d=r.current;if(d===null)throw Error("Markdown parser is not mounted");let u=t?Fe(n).markdown:n;d.update({source:u,text:n,isStreaming:t})},[t,n]),s!==null)throw s;return o===null?a("div",{"data-markdown-pending":!0}):a(tn,{result:o})});function fn({text:e,streaming:n,host:t}){let r=n===!0,[o,i]=p(e);return g(()=>{if(o===e)return;if(!r){i(e);return}let s=requestAnimationFrame(()=>i(e));return()=>cancelAnimationFrame(s)},[o,r,e]),a(Z.Provider,{value:t,children:a(rn,{text:r?o:e,isStreaming:r})})}export{fn as CodexMarkdownRenderer};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{CacheStorage as O,Soundfont as y}from"smplr";var
|
|
1
|
+
import{CacheStorage as O,Soundfont as y}from"smplr";var f=4,I=21,d=88,c=[39,41,43,44,46,48,50],h=0.035,S=0.16,w=88,U=50,m="acoustic_grand_piano",C="MusyngKite",D="FluidR3_GM",p=[0,2,4,5,7,9,11],L=2,k=5,l=globalThis;if(l.__alwithThreadUserMessageNavigationAudio?.version!==f)l.__alwithThreadUserMessageNavigationAudio={version:f,context:null,storage:O("alwith-thread-navigation-instruments"),players:new Map,nextNoteTime:0,unlockConsumerCount:0};var i=l.__alwithThreadUserMessageNavigationAudio;function g(){return i.context??=new AudioContext,i.context}function u(){let e=g();if(e.state==="running"){i.nextNoteTime=e.currentTime;return}e.resume().then(()=>{i.nextNoteTime=e.currentTime},(t)=>{if(t instanceof DOMException&&t.name==="NotAllowedError")return;console.error("Failed to unlock thread navigation audio",t)})}function F(e){let t=g();return y(t,{instrument:e,kit:e===m?C:D,storage:i.storage,volume:U})}function T(e){let t=i.players.get(e);if(t!==void 0)return t;let n=F(e),r={player:n,ready:n.ready};return i.players.set(e,r),r}function b(e){T(e).ready.catch((t)=>{console.error(`Failed to load navigation instrument "${e}"`,t)})}function q(){u()}function G(){if(i.unlockConsumerCount===0)window.addEventListener("pointerdown",u,{capture:!0}),window.addEventListener("keydown",u,{capture:!0});return i.unlockConsumerCount++,()=>{if(i.unlockConsumerCount--,i.unlockConsumerCount===0)window.removeEventListener("pointerdown",u,{capture:!0}),window.removeEventListener("keydown",u,{capture:!0})}}function H(e,t,n,r,o){if(o==="none")return;let a=Math.sign(t-e),s=Math.abs(t-e),E=Array.from({length:s},(Y,M)=>{let N=e+a*(M+1),_=n[N];return v(N,n.length,_.inputTokens,_.outputTokens,o)});A(r,E)}function J(e,t,n,r,o,a){if(a==="none")return;A(o,[v(e,t,n,r,a)])}function v(e,t,n,r,o){if(o==="none")throw Error("navigationMidiNote: 声音已关闭,不该求音符");if(o==="auto")return K(n,r);return x(e,t)}function K(e,t){let n=Math.imul(e,5)+Math.imul(t,3)>>>0,r=(Math.imul(e,11)^Math.imul(t,13))>>>0,o=n%p.length;return 12*(L+r%k+1)+p[o]}function x(e,t){return I+R(e,t)}function X(e,t){return V(x(e,t))}function R(e,t){if(t<=d)return P(t)[t-e-1];return Math.round((t-e-1)/(t-1)*(d-1))}function P(e){if(e<=c.length)return c.slice(0,e);let t=new Set(c),n=c[0]-1,r=c.at(-1)+1;while(t.size<e&&(n>=0||r<d)){if(n>=0&&t.size<e)t.add(n--);if(r<d&&t.size<e)t.add(r++)}for(let o=0;t.size<e&&o<d;o++)t.add(o);return[...t].toSorted((o,a)=>o-a)}function V(e){return 440*2**((e-69)/12)}function A(e,t){let n=g();if(n.state!=="running")return;let{player:r,ready:o}=T(e);o.then(()=>{let a=Math.max(n.currentTime,i.nextNoteTime);for(let s=0;s<t.length;s++)r.start({note:t[s],time:a+s*h,duration:S,velocity:w});i.nextNoteTime=a+t.length*h}).catch((a)=>{console.error(`Failed to play navigation instrument "${e}"`,a)})}function j(){return i.context?.state}function B(e){return T(e).ready}export{q as armThreadUserMessageNavigationAudio,K as automaticNavigationMidiNote,j as getNavigationAudioContextState,B as getNavigationInstrumentReady,G as installThreadUserMessageNavigationAudioUnlock,R as itemPianoKeyIndex,v as navigationMidiNote,P as navigationPianoKeyIndexes,X as pianoKeyFrequency,x as pianoKeyMidiNote,J as playThreadUserMessageNavigationNote,H as playThreadUserMessageNavigationSequence,b as preloadThreadUserMessageNavigationInstrument};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as v,Fragment as ve,jsxs as we}from"react/jsx-runtime";import{useCallback as ye,useEffect as q,useLayoutEffect as Se,useMemo as
|
|
1
|
+
import{jsx as v,Fragment as ve,jsxs as we}from"react/jsx-runtime";import{useCallback as ye,useEffect as q,useLayoutEffect as Se,useMemo as Q,useRef as b,useState as M}from"react";import{NavigationPreview as Te}from"./navigation-preview.js";import"./navigation-rail.css";var ke=4,fe=10;function Ce(x,w){let h=new Map(w.flatMap((l)=>l.itemIds.map((S)=>[S,l.key]))),p=Array(x.length),P;for(let l=x.length-1;l>=0;l--)P=h.get(x[l])??P,p[l]=P;let j=Math.max(-1,...w.map((l)=>l.key))+1,E=new Set,n=[];for(let[l,S]of x.entries()){let T=h.get(S),f=n.at(-1);if(!f||T!==void 0&&T!==f.key||T===void 0&&f.itemIds.length>=64&&p[l]!==f.key){let y=T!==void 0&&!E.has(T)?T:j++;f={key:y,startIndex:l,itemIds:[]},n.push(f),E.add(y)}f.itemIds.push(S)}return n}function ge(x,w){if(x.size!==w.size)return!1;for(let h of x)if(!w.has(h))return!1;return!0}function Ee({audio:x,beforeReveal:w,ensureItemMounted:h,items:p,onPreviewItem:P,renderPreview:j,onRevealError:E,scrollRoot:n,targetTopMarginPx:l=16}){let[S,T]=M(()=>{let e=p.at(-1);return new Set(e===void 0?[]:[e.id])}),[f,y]=M(null),[F,K]=M(null),[X,A]=M(!1),[W,me]=M(()=>new Set),[pe,he]=M(!0),[Ie,G]=M(null),{installUnlock:Z,preload:ee,playSequence:te}=x,L=b(null),k=b(null),H=b(!1),B=b(null),O=b(0),C=b(null),U=b(new Set),_=Q(()=>p.map((e)=>e.id).join("\x00"),[p]),D=b(p);D.current=p;let ne=b(W),re=b(S),se=b({itemIdsKey:_,scrollRoot:n});if(se.current.scrollRoot!==n)O.current+=1,se.current={itemIdsKey:_,scrollRoot:n};let g=Q(()=>h===void 0?p.filter((e)=>W.has(e.id)):p,[h,p,W]),ie=Q(()=>g.map((e)=>({inputTokens:e.inputTokens,outputTokens:e.outputTokens})),[g]),z=b({ids:"",groups:[]}),ae=g.map((e)=>e.id).join("\x00");if(z.current.ids!==ae)z.current={ids:ae,groups:Ce(g.map((e)=>e.id),z.current.groups)};q(()=>Z(),[Z]),q(()=>()=>{if(O.current+=1,C.current!==null)clearTimeout(C.current)},[]),q(()=>{y(null),A(!1),K(null),k.current=null,H.current=!1,B.current=null,G(null),U.current.clear()},[n]),q(()=>{ee()},[ee]),q(()=>{if(n===null)return;let e=new Set,t=new Map,r=new Set(D.current.map((o)=>o.id)),s=()=>{let o=new Set(t.values()),d=D.current.filter((m)=>o.has(m.id)).map((m)=>m.id),u=d.findIndex((m)=>e.has(m));if(u===-1)return;let I=u;for(let m=u+1;m<d.length;m++)if(e.has(d[m]))I=m;let N=new Set(d.slice(u,I+1));if(ge(re.current,N))return;re.current=N,T(N)},i=new IntersectionObserver((o)=>{for(let d of o){let u=t.get(d.target);if(d.isIntersecting)e.add(u);else e.delete(u)}s()},{root:n,rootMargin:`-${l}px 0px 0px 0px`}),a=()=>{let o=new Set,d=new Set;for(let u of n.querySelectorAll("[data-content-search-unit-key]")){let I=u.dataset.contentSearchUnitKey;if(I===void 0||!r.has(I)||o.has(I))continue;o.add(I);let N=u.closest("[data-turn-key]"),m=N===null||d.has(N)?u:N;if(d.add(m),t.has(m))continue;t.set(m,I),i.observe(m)}for(let u of t.keys()){if(d.has(u))continue;i.unobserve(u),e.delete(t.get(u)),t.delete(u)}if(s(),ge(ne.current,o))return;ne.current=o,me(o)};a();let c=new MutationObserver((o)=>{if(o.some((u)=>[...u.addedNodes,...u.removedNodes].some((I)=>I instanceof Element&&(I.matches("[data-turn-key], [data-content-search-unit-key]")||I.querySelector("[data-turn-key], [data-content-search-unit-key]")!==null))))a()});return c.observe(n,{childList:!0,subtree:!0}),()=>{c.disconnect(),i.disconnect()}},[_,n,l]);let J=g.find((e)=>S.has(e.id))?.id??g.at(-1)?.id;Se(()=>{let e=L.current;if(e===null||k.current!==null||J===void 0)return;let t=e.querySelector(`[data-thread-user-message-navigation-item-id="${CSS.escape(J)}"]`);if(t===null)return;let r=e.getBoundingClientRect(),s=t.getBoundingClientRect();if(s.top<r.top)e.scrollTop+=s.top-r.top;else if(s.bottom>r.bottom)e.scrollTop+=s.bottom-r.bottom+1},[J,_]),q(()=>{let e=n?.querySelector("[data-thread-user-message-navigation-content]");if(!n||!e)return;let t=()=>{let s=n.getBoundingClientRect(),i=e.getBoundingClientRect();if(s.width===0||i.width===0)return;let a=n.offsetWidth>0?s.width/n.offsetWidth:1;he((i.left-s.left)/a>=48)},r=new ResizeObserver(t);return r.observe(n),r.observe(e),t(),()=>r.disconnect()},[n]);let be=ye(async(e,t="smooth")=>{if(n===null)throw Error("Thread user-message navigation scroll root is missing");let r=O.current+1;O.current=r,w();let s=()=>n.querySelector(`[data-content-search-unit-key="${CSS.escape(e.id)}"]`),i=s(),a=i!==null&&n.clientHeight>0&&i.closest("[data-turn-key]")!==null&&Math.abs(i.getBoundingClientRect().top-n.getBoundingClientRect().top)>n.clientHeight*2;if((i===null||a)&&h!==void 0){if(t==="instant"&&e.isLoaded===!1)return;i=await h(e,()=>O.current===r)??s(),t="instant"}if(O.current!==r)return;if(i===null)return;let c=window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;i.scrollIntoView({behavior:c?"instant":t,block:"start"}),i.querySelector("[data-user-message-bubble], [data-composer-attachment-pill]")?.animate?.([{backgroundColor:"color-mix(in srgb, var(--foreground) 14%, transparent)"},{backgroundColor:"color-mix(in srgb, var(--foreground) 14%, transparent)",offset:0.35},{backgroundColor:"transparent"}],{duration:c?0:1000,easing:"cubic-bezier(0.23, 1, 0.32, 1)"})},[w,h,n]);if(g.length<ke||!pe)return null;let Y=()=>{if(C.current!==null)clearTimeout(C.current);C.current=null},oe=(e,t=!1)=>{if(Y(),P===void 0||e.isLoaded!==!1||U.current.has(e.turnKey))return;let r=()=>{C.current=null,U.current.add(e.turnKey),P(e).catch(()=>U.current.delete(e.turnKey))};if(t)r();else C.current=setTimeout(r,150)},V=f===null?null:g.find((e)=>e.id===f.item.id)??g.find((e)=>e.nativeTurnId!==void 0&&e.nativeTurnId===f.item.nativeTurnId)??f.item,ue=(e,t="smooth")=>{be(e,t).catch((r)=>{if(E)E(r);else throw r})},ce=g.findIndex((e)=>e.id===(F??Ie)),de=L.current,xe=f===null||!de?.contains(f.button)?0:Ne(de,f.button),le=(e)=>{let t=e?.closest("[data-thread-user-message-navigation-item-id]"),r=L.current;if(t===void 0||t===null||!r.contains(t))return null;let s=t.dataset.threadUserMessageNavigationItemId,i=g.findIndex((a)=>a.id===s);return{button:t,item:g[i],index:i}},R=(e)=>{let t=k.current;if(t?.pointerId!==e.pointerId)return;if(k.current=null,K(null),t.captureTarget.hasPointerCapture(e.pointerId))t.captureTarget.releasePointerCapture(e.pointerId)};return v("nav",{"aria-label":"User messages",className:"thread-user-message-navigation absolute start-4 top-1/2 z-20 -translate-y-1/2",children:v(Te,{open:X,onOpenChange:A,side:"inline-end",sideOffset:0,align:"center",alignOffset:xe,trigger:v("div",{ref:L,"data-thread-user-message-navigation-rail-list":!0,"data-scrubbing":F===null?void 0:"",className:"thread-user-message-navigation-rail-list",onPointerEnter:()=>{B.current=null},onPointerDown:(e)=>{if(e.button!==0)return;Y();let t=le(e.target instanceof Element?e.target:null);if(t===null)return;H.current=!1,k.current={pointerId:e.pointerId,itemId:t.item.id,itemIndex:t.index,captureTarget:t.button},t.button.setPointerCapture(e.pointerId),K(t.item.id),y(t),A(!0)},onPointerMove:(e)=>{let t=k.current;if(t===null){let c=le(e.target instanceof Element?e.target:null);if(c!==null){G(c.item.id);let o=B.current;if(o!==null&&o!==c.index)te(o,c.index,ie);B.current=c.index,y((d)=>d?.item.id===c.item.id?d:c),oe(c.item)}return}if(t.pointerId!==e.pointerId)return;if((e.buttons&1)===0){R(e);return}let r=e.currentTarget.getBoundingClientRect(),s=Math.max(0,Math.min(g.length-1,Math.floor((e.clientY-r.top+e.currentTarget.scrollTop)/fe))),a={button:e.currentTarget.querySelectorAll("[data-thread-user-message-navigation-item-id]")[s],item:g[s],index:s};if(a.item.id===t.itemId)return;te(t.itemIndex,a.index,ie),B.current=a.index,k.current={...t,itemId:a.item.id,itemIndex:a.index},H.current=!0,K(a.item.id),y(a),ue(a.item,"instant")},onPointerUp:R,onPointerCancel:R,onLostPointerCapture:R,onPointerLeave:()=>{if(Y(),G(null),B.current=null,k.current===null&&!X)y(null)},children:v("div",{className:"flex flex-col",children:z.current.groups.map((e)=>v("div",{className:"flex w-9 shrink-0 flex-col [content-visibility:auto]",style:{height:e.itemIds.length*fe},children:g.slice(e.startIndex,e.startIndex+e.itemIds.length).map((t,r)=>{let s=e.startIndex+r,i=Math.abs(s-ce),a=ce===-1||i>3?void 0:[1,0.7,0.4,0.2][i];return v("button",{type:"button","data-thread-user-message-navigation-item-id":t.id,"data-scrub-target":F===t.id?"":void 0,"aria-current":S.has(t.id)?"true":void 0,"aria-label":`Jump to user message ${s+1}`,className:"thread-user-message-navigation-row",onClick:(c)=>{if(H.current){H.current=!1;return}let o={button:c.currentTarget,item:t,index:s};y(o),A(!0),ue(t)},onFocus:(c)=>{oe(t,!0),y({button:c.currentTarget,item:t,index:s}),A(!0)},children:v("span",{className:"flex h-0.5 w-[30px] items-center",children:v("span",{className:"thread-user-message-navigation-marker",style:a===void 0?void 0:{"--marker-progress":a}})})},t.id)})},e.key))})}),children:V!==null&&v("div",{className:"bg-popover/95 text-popover-foreground ring-border w-80 max-w-[calc(100vw-1rem)] overflow-hidden rounded-xl p-2 text-sm leading-5 shadow-xl ring-[0.5px] backdrop-blur-sm",children:j?j(V):we(ve,{children:[v("div",{className:"min-w-0 truncate font-medium",children:V.label}),V.response.length>0&&v("div",{className:"text-muted-foreground mt-1 line-clamp-3",children:V.response})]})})})})}function Ne(x,w){let h=x.getBoundingClientRect(),p=w.getBoundingClientRect();return p.top+p.height/2-(h.top+h.height/2)}export{Ee as ThreadUserMessageNavigationRail};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as R,jsxs as ot}from"react/jsx-runtime";import{forwardRef as vt,useCallback as K,useEffect as ht,useImperativeHandle as Rt,useLayoutEffect as T,useMemo as rt,useRef as a,useState as k}from"react";import{calculateCodexThreadVirtualRange as q,calculateCodexTurnCenterDistanceFromBottom as Pt,calculateCodexTurnTargetDistanceFromBottom as Bt,createCodexThreadVirtualLayout as Ht,preserveCodexThreadDistanceFromBottom as bt,preserveCodexThreadRenderedWindow as xt}from"./thread-virtualizer.js";var wt=12,J=2,W=800,ft=new Map;function Kt({turnKey:j,heightPx:m,placeholder:V=!1,deferUntilReady:n=!1,observe:P,onReady:C,children:z}){let h=a(null),[B,U]=k(!1),G=K((x)=>{h.current=x,P(j,x)},[P,j]);return T(()=>{let x=h.current;if(x===null)throw Error("Codex turn element is missing");let H=()=>{C(x),U(!0)};if(x.querySelector("[data-markdown-pending]")===null){H();return}let d=new MutationObserver(()=>{if(x.querySelector("[data-markdown-pending]")!==null)return;d.disconnect(),H()});return d.observe(x,{childList:!0,subtree:!0}),()=>d.disconnect()},[C]),ot("div",{style:B?void 0:{position:"relative",height:m,overflow:"hidden"},children:[R("div",{ref:G,className:"[&_[data-virtualized-turn-content]]:[content-visibility:visible]","data-turn-key":j,"aria-busy":!B||void 0,style:!B&&!V&&n?{visibility:"hidden"}:void 0,"data-turn-ready":B?"":void 0,children:z}),!B&&!V&&n&&R("div",{"aria-hidden":"true",className:"codex-turn-loading",children:ot("div",{className:"codex-turn-loading-lines",children:[R("span",{}),R("span",{}),R("span",{})]})})]})}var Mt=vt(function({entries:m,renderTurn:V,scrollElement:n,sessionKey:P,leadingContent:C,leadingInsetPx:z=0,preserveViewport:h=!1},B){let U=a(null),[G,x]=k(z),H=C!==void 0&&C!==null;T(()=>{let t=U.current;if(t===null)return;let e=()=>x(t.getBoundingClientRect().height);e();let i=new ResizeObserver(e);return i.observe(t),()=>i.disconnect()},[H]);let d=rt(()=>ft.get(P),[P]),[Q,Y]=k(()=>d?.turnHeightsByKey??{}),o=rt(()=>Ht({entries:m,gapPx:wt,measuredHeightsByKey:Q,leadingInsetPx:H?G:z}),[m,Q,H,G,z]),mt=rt(()=>{let t=q({distanceFromBottomPx:d?.distanceFromBottomPx??0,layout:o,overscanCount:J,viewportHeightPx:W}),e=d?.renderedWindow;if(e===void 0||e===null)return t;return xt({anchorKey:e.anchorKey,layout:o,previousRange:{startIndex:0,endIndex:Math.min(e.count,t.endIndex-t.startIndex)}})??t},[d,o]),[I,it]=k(mt),[y,ut]=k(W),[s,ct]=k(null),
|
|
1
|
+
import{jsx as R,jsxs as ot}from"react/jsx-runtime";import{forwardRef as vt,useCallback as K,useEffect as ht,useImperativeHandle as Rt,useLayoutEffect as T,useMemo as rt,useRef as a,useState as k}from"react";import{calculateCodexThreadVirtualRange as q,calculateCodexTurnCenterDistanceFromBottom as Pt,calculateCodexTurnTargetDistanceFromBottom as Bt,createCodexThreadVirtualLayout as Ht,preserveCodexThreadDistanceFromBottom as bt,preserveCodexThreadRenderedWindow as xt}from"./thread-virtualizer.js";var wt=12,J=2,W=800,ft=new Map;function Kt({turnKey:j,heightPx:m,placeholder:V=!1,deferUntilReady:n=!1,observe:P,onReady:C,children:z}){let h=a(null),[B,U]=k(!1),G=K((x)=>{h.current=x,P(j,x)},[P,j]);return T(()=>{let x=h.current;if(x===null)throw Error("Codex turn element is missing");let H=()=>{C(x),U(!0)};if(x.querySelector("[data-markdown-pending]")===null){H();return}let d=new MutationObserver(()=>{if(x.querySelector("[data-markdown-pending]")!==null)return;d.disconnect(),H()});return d.observe(x,{childList:!0,subtree:!0}),()=>d.disconnect()},[C]),ot("div",{style:B?void 0:{position:"relative",height:m,overflow:"hidden"},children:[R("div",{ref:G,className:"[&_[data-virtualized-turn-content]]:[content-visibility:visible]","data-turn-key":j,"aria-busy":!B||void 0,style:!B&&!V&&n?{visibility:"hidden"}:void 0,"data-turn-ready":B?"":void 0,children:z}),!B&&!V&&n&&R("div",{"aria-hidden":"true",className:"codex-turn-loading",children:ot("div",{className:"codex-turn-loading-lines",children:[R("span",{}),R("span",{}),R("span",{})]})})]})}var Mt=vt(function({entries:m,renderTurn:V,scrollElement:n,sessionKey:P,leadingContent:C,leadingInsetPx:z=0,preserveViewport:h=!1},B){let U=a(null),[G,x]=k(z),H=C!==void 0&&C!==null;T(()=>{let t=U.current;if(t===null)return;let e=()=>x(t.getBoundingClientRect().height);e();let i=new ResizeObserver(e);return i.observe(t),()=>i.disconnect()},[H]);let d=rt(()=>ft.get(P),[P]),[Q,Y]=k(()=>d?.turnHeightsByKey??{}),o=rt(()=>Ht({entries:m,gapPx:wt,measuredHeightsByKey:Q,leadingInsetPx:H?G:z}),[m,Q,H,G,z]),mt=rt(()=>{let t=q({distanceFromBottomPx:d?.distanceFromBottomPx??0,layout:o,overscanCount:J,viewportHeightPx:W}),e=d?.renderedWindow;if(e===void 0||e===null)return t;return xt({anchorKey:e.anchorKey,layout:o,previousRange:{startIndex:0,endIndex:Math.min(e.count,t.endIndex-t.startIndex)}})??t},[d,o]),[I,it]=k(mt),[y,ut]=k(W),[s,ct]=k(null),S=a(d?.distanceFromBottomPx??0),L=a(I),at=a(o.turnKeys),l=a(Q),N=a(o),st=a(o),b=a(new Map),p=a(null),F=a(null),O=a(null),D=a(new Map),Z=a(!1),dt=a(()=>{}),A=a(null),lt=K(()=>{if(!h||n===null||p.current!==null||A.current!==null)return;let t=n.getBoundingClientRect();if(t.height<=0)return;let e=[...b.current].filter(([,r])=>r.hasAttribute("data-turn-ready")).map(([r,u])=>{let c=u.getBoundingClientRect(),g=N.current.turnIndexByKey.get(r),w=g===void 0?c.height:N.current.heightsPx[g];return{key:r,element:u,rect:c,bottom:c.top+w}}).filter(({rect:r,bottom:u})=>u>t.top&&r.top<t.bottom).toSorted((r,u)=>r.rect.top-u.rect.top),i=e.flatMap((r)=>[...r.element.querySelectorAll("[data-user-message-bubble], .codex-markdown-root > *")].filter((u)=>!u.closest('[aria-hidden="true"], [inert]')).map((u)=>({key:r.key,element:u,rect:u.getBoundingClientRect()})).filter(({rect:u})=>u.height>0&&u.top>=t.top&&u.top<t.bottom)).toSorted((r,u)=>r.rect.top-u.rect.top)[0]??e[0];if(i)A.current={key:i.key,element:i.element,top:i.rect.top-t.top,scrollTop:n.scrollTop}},[h,n]),E=a(lt);E.current=lt;let v=K((t,e)=>{let i=Math.min(t,o.totalHeightPx),r=q({distanceFromBottomPx:i,layout:o,overscanCount:J,viewportHeightPx:e}),u=L.current,c=u.startIndex<=r.startIndex&&u.endIndex>=r.endIndex?u:r;if(S.current=i,L.current=c,at.current=o.turnKeys,ut(e),c!==u)it(c)},[o]),_=K((t)=>{let e=Math.max(0,t.scrollHeight-o.totalHeightPx);return Math.max(0,t.scrollHeight-t.clientHeight-t.scrollTop-e)},[o.totalHeightPx]),yt=K((t)=>{let e=t.dataset.turnKey;if(e===void 0)throw Error("Codex measured turn is missing its key");let i=Math.max(1,t.getBoundingClientRect().height);if(l.current[e]===i)return;E.current();let r={...l.current,[e]:i};l.current=r,Y(r)},[]),tt=K(()=>{if(F.current!==null)return F.current;return F.current=new ResizeObserver((t)=>{for(let e of t){let i=e.target;if(!("turnReady"in i.dataset)&&i.querySelector("[data-markdown-pending]")!==null)continue;let r=i.dataset.turnKey;if(r===void 0)throw Error("Codex measured turn is missing its key");let u=Math.max(1,e.borderBoxSize[0]?.blockSize??e.contentRect.height);D.current.set(r,u)}if(O.current!==null||D.current.size===0)return;O.current=requestAnimationFrame(()=>{O.current=null;let e=[...D.current].filter(([r,u])=>l.current[r]!==u);if(D.current.clear(),e.length===0)return;E.current();let i={...l.current,...Object.fromEntries(e)};l.current=i,Y(i)})}),F.current},[]),pt=K((t,e)=>{let i=b.current.get(t);if(i!==void 0)tt().unobserve(i),b.current.delete(t);if(e===null)return;if(e.dataset.turnKey!==t)throw Error(`Codex turn key does not match its element: ${t}`);b.current.set(t,e),tt().observe(e)},[tt]);ht(()=>()=>{if(F.current?.disconnect(),O.current!==null)cancelAnimationFrame(O.current);D.current.clear(),F.current=null,b.current.clear()},[]),T(()=>{dt.current=()=>{if(n===null)return;let t=_(n);if(p.current!==null){S.current=t,ut(n.clientHeight||W);return}v(t,n.clientHeight||W)}},[_,n,v]),T(()=>{if(n===null)return;if(!Z.current){Z.current=!0;let i=d?.distanceFromBottomPx??0;n.scrollTo({behavior:"instant",top:Math.max(0,i>0?N.current.totalHeightPx-n.clientHeight-i:n.scrollHeight-n.clientHeight)})}let t=()=>dt.current();t(),n.addEventListener("scroll",t,{passive:!0});let e=new ResizeObserver(t);return e.observe(n),()=>{n.removeEventListener("scroll",t),e.disconnect()}},[d,n]),T(()=>{if(n===null||s===null)return;let t=b.current.get(s.turnKey);if(t?.querySelector("[data-markdown-pending]")!==null)return;let e=t.offsetHeight;if(e<=0)return;if(l.current[s.turnKey]!==e){let g={...l.current,[s.turnKey]:e};l.current=g,Y(g);return}let i=s.getTargetElement(t)??t,r=t.getBoundingClientRect(),u=i.getBoundingClientRect(),c=Bt({align:s.align,layout:o,targetHeightPx:u.height,targetOffsetPx:u.top-r.top,turnKey:s.turnKey,viewportHeightPx:n.clientHeight});if(c===null)throw Error(`Codex virtual turn is missing: ${s.turnKey}`);n.scrollTo({behavior:"instant",top:Math.max(0,o.totalHeightPx-n.clientHeight-c)}),v(c,n.clientHeight||W),queueMicrotask(()=>{if(p.current!==s)return;s.complete(),p.current=null,ct(null)})},[o,s,n,v]),T(()=>{let t=st.current;if(st.current=o,N.current=o,n===null||s!==null){A.current=null;return}let e=A.current;A.current=null;let i=e===null?void 0:n.contains(e.element)?e.element:b.current.get(e.key);if(h&&t!==o&&e!==null&&i!==void 0){let u=i.getBoundingClientRect().top-n.getBoundingClientRect().top,c=n.scrollTop-e.scrollTop;n.scrollTop+=u-e.top+c,v(_(n),n.clientHeight);return}let r=S.current;if(h&&t!==o&&Z.current)r=Math.max(0,t.totalHeightPx-n.clientHeight-n.scrollTop);if((r>24||h)&&t!==o){let u=_(n);if(u<=96&&!h){v(u,y);return}let c=q({distanceFromBottomPx:r,layout:t,overscanCount:0,viewportHeightPx:y}),g=t.turnKeys.slice(c.startIndex,c.endIndex).filter((f)=>o.turnIndexByKey.has(f)),w=g.find((f)=>l.current[f]!==void 0)??g[0];if(w!==void 0){let f=bt({anchorKey:w,distanceFromBottomPx:r,nextLayout:o,previousLayout:t});if(f===null)throw Error(`Codex viewport anchor is missing: ${w}`);r=f,n.scrollTo({behavior:"instant",top:Math.max(0,o.totalHeightPx-n.clientHeight-r)})}}v(r,y)},[o,s,_,n,v,y,h]),T(()=>{L.current=I},[I]),ht(()=>()=>{p.current?.complete(),p.current=null;let t=L.current,i=N.current.turnKeys[t.startIndex];ft.set(P,{distanceFromBottomPx:S.current,renderedWindow:i===void 0?null:{anchorKey:i,count:t.endIndex-t.startIndex},turnHeightsByKey:l.current})},[P]),Rt(B,()=>({scrollToKey(t,e=(r)=>r,i={align:"center"}){p.current?.complete();let r=o.turnIndexByKey.get(t);if(r===void 0)throw Error(`Codex virtual turn is missing: ${t}`);let u=o.turnKeys[r],c=Pt({layout:o,turnKey:t,viewportHeightPx:y});if(c===null)throw Error(`Codex virtual turn is missing: ${t}`);let g=q({distanceFromBottomPx:c,layout:o,overscanCount:J,viewportHeightPx:y});return L.current=g,it(g),new Promise((w)=>{let f={align:i.align,complete:w,getTargetElement:e,turnKey:u};p.current=f,ct(f)})}}),[o,y]);let M=I,X=at.current;if(!(X===o.turnKeys||X.length===o.turnKeys.length&&X.every((t,e)=>t===o.turnKeys[e]))){let t=X[I.startIndex];M=(t===void 0?null:xt({anchorKey:t,layout:o,previousRange:I}))??q({distanceFromBottomPx:S.current,layout:o,overscanCount:J,viewportHeightPx:y})}let et=m.length-1,gt=m[et],nt=m.slice(M.startIndex,Math.min(M.endIndex,et)).map((t,e)=>({entry:t,index:M.startIndex+e}));if(gt!==void 0)nt.push({entry:gt,index:et});return ot("div",{"data-codex-thread":!0,"data-codex-virtualized-pending-key":s?.turnKey,"data-codex-virtualized-range":`${M.startIndex}:${M.endIndex}`,"data-codex-virtualized-total-count":m.length,"data-codex-virtualized-turn-count":nt.length,className:"relative shrink-0",style:{height:o.totalHeightPx},children:[H&&R("div",{ref:U,"data-codex-thread-leading":!0,className:"absolute inset-x-0 top-0",children:C}),nt.map(({entry:t,index:e})=>R("div",{className:"absolute inset-x-0",style:{top:o.topOffsetsPx[e]??0},children:R(Kt,{turnKey:t.turnKey,heightPx:o.heightsPx[e],placeholder:t.placeholder,deferUntilReady:t.deferUntilReady,observe:pt,onReady:yt,children:V(t,e)})},t.turnKey))]})});export{Mt as VirtualizedTurnList};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function c(t,e){if(t.type||!e.type)return t;let o=e.type.split("/")[1],i=o!==void 0&&o!==""?`pasted-${Date.now()}.${o==="jpeg"?"jpg":o}`:"";return new File([t],t.name||i||`pasted-${Date.now()}`,{type:e.type})}function p(t){let e=[],o=!1;for(let i of t){if(i.kind!=="file")continue;let n=i.getAsFile();if(!n)continue;if(!(n.type||i.type).startsWith("image/")){o=!0;continue}e.push(c(n,i))}return{imageFiles:e,sawNonImageFile:o}}function f(t){return
|
|
1
|
+
function c(t,e){if(t.type||!e.type)return t;let o=e.type.split("/")[1],i=o!==void 0&&o!==""?`pasted-${Date.now()}.${o==="jpeg"?"jpg":o}`:"";return new File([t],t.name||i||`pasted-${Date.now()}`,{type:e.type})}function p(t){let e=[],o=!1;for(let i of t){if(i.kind!=="file")continue;let n=i.getAsFile();if(!n)continue;if(!(n.type||i.type).startsWith("image/")){o=!0;continue}e.push(c(n,i))}return{imageFiles:e,sawNonImageFile:o}}function f(t){return[...t].some((e)=>e.kind==="string")}function u(t){let e=t.codePointAt(0);return e<32&&e!==9&&e!==10&&e!==13||e===127}function l(t){return[...t].filter((e)=>!u(e)).join("")}function a(t,e){let o=0;for(let i=0;i<e;i++){let n=t.charCodeAt(i);if(n>=0&&n<=8||n===11||n===12||n>=14&&n<=31||n===127)o++}return o}function d(t){let{value:e,selectionStart:o,selectionEnd:i}=t,n=l(e);if(n===e)return n;if(t.value=n,o!==null&&i!==null){let r=Math.max(0,o-a(e,o)),s=Math.max(0,i-a(e,i));requestAnimationFrame(()=>{t.setSelectionRange(r,s)})}return n}export{f as clipboardHasStringItem,a as countControlCharsBeforeIndex,c as normalizePastedImageFile,d as sanitizeTextareaTargetValue,l as sanitizeTextareaValue,p as scanClipboardForImageFiles};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as z}from"react/jsx-runtime";import{createContext as
|
|
1
|
+
import{jsx as z}from"react/jsx-runtime";import{createContext as a,useCallback as n,useContext as u,useEffect as X,useMemo as D,useRef as v,useState as B}from"react";var R=a(null),Y=a(null);function rt(){return u(Y)}var Z=a(null);function ot(){return u(Z)}var U=a(null);function ut(){let r=u(R);if(!r)throw Error("Wrap your component inside <PromptInputProvider> to use usePromptInputController().");return r}var st=()=>u(R);function it(){let r=u(U);if(!r)throw Error("Wrap your component inside <PromptInputProvider> to use useProviderAttachments().");return r}var V=()=>u(U);function ct({initialInput:r="",revision:c,onSubmittedClear:p,onRemoveAttachment:w,attachmentPolicy:d,value:L,onValueChange:j,attachments:A,onAttachmentsChange:W,children:G}){let C=n((t)=>{if(t.type)return t.type;let e=(t.name||"").toLowerCase();if(e.endsWith(".png"))return"image/png";if(e.endsWith(".jpg")||e.endsWith(".jpeg"))return"image/jpeg";if(e.endsWith(".webp"))return"image/webp";if(e.endsWith(".gif"))return"image/gif";if(e.endsWith(".bmp"))return"image/bmp";if(e.endsWith(".svg"))return"image/svg+xml";return""},[]),T=L!==void 0,[H,J]=B(r),l=L??H,o=v({value:l,external:c,revision:0});if(o.current.value!==l||o.current.external!==c)o.current={value:l,external:c,revision:o.current.revision+1};let y=n(()=>o.current.revision,[]),x=n((t)=>{if(o.current.value=t,o.current.revision++,T)j?.(t);else J(t)},[T,j]),h=n(()=>x(""),[x]),I=A!==void 0,[K,N]=B([]),P=A??K,g=v(P);g.current=P;let s=n((t)=>{let e=typeof t==="function"?t(g.current):t;if(I)W?.(e);else N(e)},[I,W]),O=v(null),k=v(()=>{}),F=n((t)=>{let e=[...t];if(e.length===0)return;s((m)=>{let f=d===void 0?e:d.uniqueFiles(e,m);return[...m,...f.map((i)=>{let q=d?.sourcePath(i);return{id:crypto.randomUUID(),type:"file",url:URL.createObjectURL(i),mediaType:C(i),filename:i.name,size:i.size,lastModified:i.lastModified,...q===void 0?{}:{sourcePath:q}}})]})},[d,C,s]),S=n((t)=>{s((e)=>{let m=e.find((f)=>f.id===t);if(m?.url)URL.revokeObjectURL(m.url);return e.filter((f)=>f.id!==t)}),w?.()},[w,s]),E=n(()=>{s((t)=>{for(let e of t)if(e.url)URL.revokeObjectURL(e.url);return[]})},[s]);X(()=>{if(I)return;return()=>{for(let t of g.current)if(t.url)URL.revokeObjectURL(t.url)}},[I]);let M=n(()=>{k.current?.()},[]),b=D(()=>({files:P,add:F,remove:S,clear:E,openFileDialog:M,fileInputRef:O}),[P,F,S,E,M]),_=n((t,e)=>{O.current=t.current,k.current=e},[]),Q=D(()=>({textInput:{value:l,setInput:x,clear:h,getRevision:y,clearSubmitted:p??h},attachments:b,__registerFileInput:_}),[l,x,h,y,p,b,_]);return z(R.Provider,{value:Q,children:z(U.Provider,{value:b,children:G})})}var tt=a(null);function pt(){let r=V(),c=u(tt),p=r??c;if(!p)throw Error("usePromptInputAttachments must be used within a PromptInput or PromptInputProvider");return p}export{tt as LocalAttachmentsContext,ct as PromptInputProvider,Z as PromptInputSubmissionContext,Y as PromptInputSubmitContext,U as ProviderAttachmentsContext,st as useOptionalPromptInputController,pt as usePromptInputAttachments,ut as usePromptInputController,ot as usePromptInputSubmission,rt as usePromptInputSubmit,it as useProviderAttachments};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import{jsx as D}from"react/jsx-runtime";import{cn as E}from"cn";import{forwardRef as P,useCallback as R,useEffect as F,useImperativeHandle as A,useRef as m}from"react";import{InputGroupTextarea as H}from"../ui/input-group-textarea.js";import{clipboardHasStringItem as j,sanitizeTextareaTargetValue as g,scanClipboardForImageFiles as q}from"./prompt-input-clipboard.js";import{useOptionalPromptInputController as z,usePromptInputAttachments as N}from"./prompt-input-context.js";var B=(o)=>!o.shiftKey,K=()=>!1,V=P(({onChange:o,className:v,placeholder:x,bashMode:y=!1,isSendShortcut:I=B,isNewlineShortcut:b=K,...k},T)=>{let n=z(),i=N(),l=m(!1),u=m(!1),a=m(null),s=R(()=>{let t=a.current;if(!t)return;t.style.height="auto",t.style.height=`${t.scrollHeight}px`},[]);F(()=>{let t=a.current;if(!t)return;let e=new ResizeObserver(()=>{requestAnimationFrame(s)});return e.observe(t),()=>e.disconnect()},[s]);let p=y&&(n?.textInput.value??"").startsWith("!"),C=(t)=>{if(l.current||t.nativeEvent.isComposing||t.nativeEvent.keyCode===229||u.current)return;if(t.key.length===1&&t.key.charCodeAt(0)<32&&t.key!==`
|
|
2
|
-
`&&t.key!=="\r"&&t.key!=="\t"){t.preventDefault();return}if(p&&n){let e=t.currentTarget.selectionStart===0&&t.currentTarget.selectionEnd===0;if(t.key==="Escape"||(t.key==="Backspace"||t.key==="Delete")&&e){t.preventDefault(),n.textInput.setInput(n.textInput.value.slice(1));return}}if(t.key==="Enter"){if(b(t.nativeEvent)){t.preventDefault();let e=t.currentTarget,{selectionStart:r,selectionEnd:f,value:c}=e,h=`${c.
|
|
3
|
-
${c.
|
|
2
|
+
`&&t.key!=="\r"&&t.key!=="\t"){t.preventDefault();return}if(p&&n){let e=t.currentTarget.selectionStart===0&&t.currentTarget.selectionEnd===0;if(t.key==="Escape"||(t.key==="Backspace"||t.key==="Delete")&&e){t.preventDefault(),n.textInput.setInput(n.textInput.value.slice(1));return}}if(t.key==="Enter"){if(b(t.nativeEvent)){t.preventDefault();let e=t.currentTarget,{selectionStart:r,selectionEnd:f,value:c}=e,h=`${c.slice(0,r)}
|
|
3
|
+
${c.slice(f)}`;if(n)n.textInput.setInput(h);else e.value=h;let d=r+1;e.setSelectionRange(d,d),s();return}if(I(t.nativeEvent)){t.preventDefault();let e=t.currentTarget.form;if(!e)return;let r=e.querySelector('button[type="submit"]');if(!r||r.disabled)return;e.requestSubmit(r)}}if(t.key==="Backspace"&&t.currentTarget.value===""&&i.files.length>0){t.preventDefault();let e=i.files.at(-1);if(e)i.remove(e.id)}},S=(t)=>{let e=t.clipboardData?.items;if(!e)return;let{imageFiles:r,sawNonImageFile:f}=q(e),c=j(e);if(r.length>0)t.preventDefault(),i.add(r);else if(f&&!c)t.preventDefault()},w=n?{value:p?n.textInput.value.slice(1):n.textInput.value,onChange:(t)=>{let e=g(t.currentTarget);n.textInput.setInput(p?`!${e}`:e),s(),o?.(t)}}:{onChange:(t)=>{g(t.currentTarget),s(),o?.(t)}};return A(T,()=>({resetHeight:()=>{if(a.current)a.current.style.height="auto"},focus:()=>{a.current?.focus()},getTextarea:()=>a.current}),[]),D(H,{"data-chat-input":!0,ref:a,rows:3,className:E("field-sizing-content max-h-(--chat-input-max-height) min-h-[calc(var(--chat-input-line-height)*3)] min-w-0 flex-1 overflow-x-hidden","leading-(--chat-input-line-height)","placeholder:text-chat-input-placeholder p-0 pe-2.5","bg-chat-input-bg",v),name:"message",onCompositionEnd:()=>{l.current=!1,u.current=!0,requestAnimationFrame(()=>{u.current=!1})},onCompositionStart:()=>{u.current=!1,l.current=!0},onKeyDown:C,onPaste:S,placeholder:x,...k,...w})});V.displayName="PromptInputTextarea";export{V as PromptInputTextarea};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as a,jsxs as pe}from"react/jsx-runtime";import{cn as x}from"cn";import{ArrowUpIcon as ge,Loader2Icon as he,SquareIcon as be,XIcon as ve}from"lucide-react";import{Children as V,useCallback as v,useEffect as z,useMemo as xe,useRef as _,useState as Ie}from"react";import{flushSync as ye}from"react-dom";import{exceedsImageLimit as Le,MAX_TOTAL_IMAGE_MB as we}from"../lib/limits.js";import{preparePromptFiles as Te}from"../lib/prepare-prompt-files.js";import{InputGroup as ze,InputGroupAddon as Z,InputGroupButton as ee}from"../ui/input-group.js";import{LocalAttachmentsContext as _e,PromptInputSubmissionContext as ke,PromptInputSubmitContext as
|
|
1
|
+
import{jsx as a,jsxs as pe}from"react/jsx-runtime";import{cn as x}from"cn";import{ArrowUpIcon as ge,Loader2Icon as he,SquareIcon as be,XIcon as ve}from"lucide-react";import{Children as V,useCallback as v,useEffect as z,useMemo as xe,useRef as _,useState as Ie}from"react";import{flushSync as ye}from"react-dom";import{exceedsImageLimit as Le,MAX_TOTAL_IMAGE_MB as we}from"../lib/limits.js";import{preparePromptFiles as Te}from"../lib/prepare-prompt-files.js";import{InputGroup as ze,InputGroupAddon as Z,InputGroupButton as ee}from"../ui/input-group.js";import{LocalAttachmentsContext as _e,PromptInputSubmissionContext as ke,PromptInputSubmitContext as Pe,ProviderAttachmentsContext as Re,useOptionalPromptInputController as Ae}from"./prompt-input-context.js";import{MAX_TOTAL_IMAGE_MB as Ke}from"../lib/limits.js";function Y(u){let s=new FormData(u).get("message");return typeof s==="string"?s:""}var Fe=({className:u,bashMode:s=!1,attachmentPolicy:I,onCommand:m,onSubmitError:y,canSubmit:p,onSubmitAsync:g,accept:k,multiple:te,globalDrop:P,syncHiddenInput:D,maxFiles:N,maxFileSize:j,onError:h,onSubmit:re,children:ne,...se})=>{let i=Ae(),c=!!i,ie=s&&c&&i.textInput.value.startsWith("!"),L=_(null),R=_(null),U=_(!1),[oe,W]=Ie([]),d=c?i.attachments.files:oe,O=_(d);O.current=d;let ae=v(()=>{L.current?.click()},[]),F=v((e)=>{if(!k||k.trim()==="")return!0;return k.split(",").map((t)=>t.trim()).filter(Boolean).some((t)=>{if(t.endsWith("/*")){let n=t.slice(0,-1);return e.type.startsWith(n)}return e.type===t})},[k]),B=v((e)=>{if(e.type)return e.type;let r=(e.name||"").toLowerCase();if(r.endsWith(".png"))return"image/png";if(r.endsWith(".jpg")||r.endsWith(".jpeg"))return"image/jpeg";if(r.endsWith(".webp"))return"image/webp";if(r.endsWith(".gif"))return"image/gif";if(r.endsWith(".bmp"))return"image/bmp";if(r.endsWith(".svg"))return"image/svg+xml";return""},[]),ue=v((e)=>{let r=[...e],t=r.filter((o)=>F(o));if(r.length&&t.length===0){h?.({code:"accept",message:"No files match the accepted types."});return}let n=(o)=>j?o.size<=j:!0,f=t.filter(n);if(t.length>0&&f.length===0){h?.({code:"max_file_size",message:"All files exceed the maximum size."});return}W((o)=>{let b=I?I.uniqueFiles(f,o):f,l=typeof N==="number"?Math.max(0,N-o.length):void 0,M=typeof l==="number"?b.slice(0,l):b;if(typeof l==="number"&&b.length>l)h?.({code:"max_files",message:"Too many files. Some were not added."});let K=[];for(let T of M){let Q=I?.sourcePath(T);K.push({id:crypto.randomUUID(),type:"file",url:URL.createObjectURL(T),mediaType:B(T),filename:T.name,size:T.size,lastModified:T.lastModified,...Q===void 0?{}:{sourcePath:Q}})}return[...o,...K]})},[I,B,F,N,j,h]),ce=v((e)=>W((r)=>{let t=r.find((n)=>n.id===e);if(t?.url)URL.revokeObjectURL(t.url);return r.filter((n)=>n.id!==e)}),[]),le=v(()=>W((e)=>{for(let r of e)if(r.url)URL.revokeObjectURL(r.url);return[]}),[]),q=c?i.attachments.add:ue,w=v((e)=>{let r=[...e],t=r.filter((f)=>!(f.type??"").toLowerCase().startsWith("image/"));if(t.length>0){h?.({code:"unsupported_type",message:`Only image attachments are supported. ${t.length} non-image file(s) were ignored.`});return}let n=r.reduce((f,o)=>f+o.size,0);if(n>0){let f=d.filter((o)=>(o.mediaType??"").toLowerCase().startsWith("image/")).reduce((o,b)=>o+(b.size??0),0);if(Le(f,n)){h?.({code:"max_total_size",message:`Total image size must not exceed ${we}MB.`});return}}q(r)},[d,q,h]),E=c?i.attachments.remove:ce,S=c?i.attachments.clear:le,G=c?i.attachments.openFileDialog:ae;z(()=>{if(!c)return;i.__registerFileInput(L,()=>L.current?.click())},[c,i]),z(()=>{if(D&&L.current&&d.length===0)L.current.value=""},[d,D]),z(()=>{let e=R.current;if(!e)return;if(P)return;let r=(n)=>{if(n.dataTransfer?.types?.includes("Files"))n.preventDefault()},t=(n)=>{if(n.dataTransfer?.types?.includes("Files"))n.preventDefault();if(n.dataTransfer?.files&&n.dataTransfer.files.length>0)w(n.dataTransfer.files)};return e.addEventListener("dragover",r),e.addEventListener("drop",t),()=>{e.removeEventListener("dragover",r),e.removeEventListener("drop",t)}},[w,P]),z(()=>{if(!P)return;let e=(t)=>{if(t.dataTransfer?.types?.includes("Files"))t.preventDefault()},r=(t)=>{if(t.dataTransfer?.types?.includes("Files"))t.preventDefault();if(t.dataTransfer?.files&&t.dataTransfer.files.length>0)w(t.dataTransfer.files)};return document.addEventListener("dragover",e),document.addEventListener("drop",r),()=>{document.removeEventListener("dragover",e),document.removeEventListener("drop",r)}},[w,P]),z(()=>()=>{if(!c){for(let e of O.current)if(e.url)URL.revokeObjectURL(e.url)}},[c]);let fe=(e)=>{if(e.currentTarget.files)w(e.currentTarget.files);e.currentTarget.value=""},X=xe(()=>({files:d.map((e)=>({...e,id:e.id})),add:w,remove:E,clear:S,openFileDialog:G,fileInputRef:L}),[d,w,E,S,G]),A=_({controller:i,files:d,canSubmit:p});A.current={controller:i,files:d,canSubmit:p};let C=_(!0);z(()=>(C.current=!0,()=>{C.current=!1}),[]);let H=async(e)=>{let r=p===void 0?!0:p();if(r!==!0)return{status:"blocked",reason:r};if(U.current)return{status:"blocked",reason:"submission_pending"};if(e===null&&g===void 0)throw Error("Awaitable submission requires onSubmitAsync");let t=R.current;if(t===null)return{status:"blocked",reason:"form_unmounted"};let n=c?i.textInput.value:Y(t),f=i?.textInput.getRevision?.(),o=d,b=()=>{if(!C.current)return;let l=A.current;if(l.files!==o)return;if(c){if(f===void 0||l.controller===null||l.controller.textInput.getRevision?.()!==f)return;if(l.controller.textInput.clearSubmitted===void 0)l.controller.textInput.clear();else l.controller.textInput.clearSubmitted()}else if(Y(t)===n)t.reset();S()};U.current=!0;try{if(m?.(n.trim()))return b(),{status:"accepted"};let l=await Te(o),M=A.current.canSubmit===void 0?!0:A.current.canSubmit();if(M!==!0)return{status:"blocked",reason:M};if(!C.current)return{status:"blocked",reason:"form_unmounted"};if(l.rejectedCount>0)h?.({code:"accept",message:"One or more images are corrupted and were removed before sending."});if(g!==void 0)await g({text:n,files:l.files});else if(e!==null)await re({text:n,files:l.files},e);return b(),{status:"accepted"}}finally{U.current=!1}},de=(e)=>{e.preventDefault(),H(e).catch(y)},me=v((e)=>{if(!e.trim())return;if(c&&i)ye(()=>{i.textInput.setInput(e)});R.current?.requestSubmit()},[i,c]),J=a(ke.Provider,{value:()=>H(null),children:pe(Pe.Provider,{value:me,children:[a("input",{accept:k,"aria-label":"Upload files",className:"hidden",multiple:te,onChange:fe,ref:L,title:"Upload files",type:"file"}),a("form",{className:x("w-full",u),onSubmit:de,ref:R,"data-tour":"chat-input",...se,children:a(ze,{className:x("codex-composer-surface overflow-y-auto has-[[data-slot=input-group-control]:focus-visible]:ring-0",ie&&"border! border-[rgb(255,0,135)] has-[[data-slot=input-group-control]:focus-visible]:border-[rgb(255,0,135)] dark:border-[rgb(253,93,177)] dark:has-[[data-slot=input-group-control]:focus-visible]:border-[rgb(253,93,177)]"),children:ne})})]})});return c?a(Re.Provider,{value:X,children:J}):a(_e.Provider,{value:X,children:J})};function Be({className:u,...s}){return a("div",{className:x("flex w-full min-w-0 flex-row items-end gap-2",u),...s})}function qe({className:u,...s}){return a(Z,{align:"block-end",className:x("order-first flex-wrap gap-1 p-2 pb-1.5",u),...s})}function Ee({className:u,...s}){return a(Z,{align:"block-end",className:x("mt-3.5 justify-between gap-1 p-0",u),...s})}function Ge({className:u,...s}){return a("div",{className:x("flex items-center gap-1",u),...s})}var Xe=({variant:u="ghost",className:s,size:I,collapsed:m=!1,...y})=>{let p=m||V.count(y.children)<=1?"icon-xs":"xs";return a(ee,{className:x("h-7 rounded-full text-xs font-medium hover:bg-transparent dark:hover:bg-transparent",(m||V.count(y.children)<=1)&&"size-7",s),size:p,type:"button",variant:u,...y})},$e=({className:u,variant:s="ghost",size:I="icon-xs",status:m,children:y,...p})=>{let g=a(ge,{className:"size-4"});if(m==="submitted")g=a(he,{className:"size-4 animate-spin"});else if(m==="streaming")g=a(be,{className:"size-3 fill-current"});else if(m==="error")g=a(ve,{className:"size-4"});return a(ee,{"aria-label":"Submit",className:x("bg-foreground text-background hover:bg-foreground/70 size-7 rounded-full p-0 transition-opacity disabled:opacity-50",u),size:I,type:"submit",variant:s,...p,children:y??g})};export{Ke as MAX_TOTAL_IMAGE_MB,Fe as PromptInput,Be as PromptInputBody,Xe as PromptInputButton,Ee as PromptInputFooter,qe as PromptInputHeader,$e as PromptInputSubmit,Ge as PromptInputTools};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
class s{worker=new Worker(new URL("./code-highlighter.worker.js",import.meta.url),{type:"module"});clients=new Map;pending=new Map;active=null;failure=null;nextClientId=0;constructor(){this.worker.onmessage=(i)=>{let e=this.active,t=i.data;if(
|
|
1
|
+
class s{worker=new Worker(new URL("./code-highlighter.worker.js",import.meta.url),{type:"module"});clients=new Map;pending=new Map;active=null;failure=null;nextClientId=0;constructor(){this.worker.onmessage=(i)=>{let e=this.active,t=i.data;if(t.clientId!==e?.clientId||t.revision!==e.revision){this.fail(Error("Code highlighting worker returned an unexpected request"));return}if(this.active=null,!t.ok){this.fail(Error(t.error));return}let n=this.clients.get(e.clientId);if(n?.revision===e.revision)n.onResult({code:e.code,language:e.language,html:t.html});this.dispatch()},this.worker.onerror=(i)=>this.fail(Error(i.message)),this.worker.onmessageerror=()=>this.fail(Error("Cannot deserialize code highlighting result"))}fail(i){this.failure=i,this.worker.terminate(),this.pending.clear(),this.active=null;for(let e of this.clients.values())e.onError(i)}dispatch(){if(this.active!==null||this.pending.size===0)return;let i=this.pending.values().next().value;this.pending.delete(i.clientId),this.active=i;try{this.worker.postMessage(i)}catch(e){this.fail(e instanceof Error?e:Error(String(e)))}}connect(i,e){if(this.failure!==null)throw this.failure;let t=++this.nextClientId,n={revision:0,onResult:i,onError:e};return this.clients.set(t,n),{update:(l,o)=>{if(this.failure!==null)throw this.failure;n.revision+=1,this.pending.set(t,{clientId:t,revision:n.revision,code:l,language:o}),this.dispatch()},dispose:()=>{if(this.clients.delete(t),this.pending.delete(t),this.clients.size===0)this.worker.terminate(),r=void 0}}}}var r;function h(i,e){return r??=new s,r.connect(i,e)}export{h as createCodeHighlighter};
|
package/dist/lib/fuzzy.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
var
|
|
1
|
+
var h=/[\\/._\- ]/;function p(o,r){if(r===0)return!0;let s=o[r-1];if(h.test(s))return!0;let c=o[r];if(s===s.toLowerCase()&&c!==c.toLowerCase())return!0;return!1}function a(o,r){if(!r)return{score:0,indices:[]};let s=o.toLowerCase(),c=r.toLowerCase(),f=[],e=0,t=0,i=-2;for(let l of c.split("")){let n=-1;while(e<s.length){if(s[e]===l){n=e;break}e++}if(n<0)return null;if(t+=1,n===i+1)t+=4;if(p(o,n))t+=5;let u=o.lastIndexOf("/");if(u!==-1&&n>u)t+=2;f.push(n),i=n,e=n+1}if(t-=Math.floor(o.length/50),o.includes(r))t+=3;return{score:t,indices:f}}function w(o,r,s,c=100){if(!r)return o.slice(0,c).map((e)=>({item:e,score:0,indices:[]}));let f=[];for(let e of o){let t=a(s(e),r);if(!t)continue;f.push({item:e,score:t.score,indices:t.indices})}return f.sort((e,t)=>t.score-e.score),f.slice(0,c)}export{w as fuzzyFilter,a as fuzzyMatch};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
var i=new Map;var l=0;function u(e,n){let t=n?void 0:i.get(e);if(t===void 0)return null;return i.delete(e),i.set(e,t),{...t,tokens:structuredClone(t.tokens)}}function h(e){if(e.isStreaming||e.text.length>1048576)return;if(i.delete(e.text))l-=e.text.length;i.set(e.text,{...e,tokens:structuredClone(e.tokens)}),l+=e.text.length;while(l>2097152||i.size>200){let n=i.keys().next().value;l-=n.length,i.delete(n)}}class a{worker=new Worker(new URL("./markdown-parser.worker.js",import.meta.url),{type:"module"});clients=new Map;pending=new Map;active=null;failure=null;nextClientId=0;constructor(){this.worker.onmessage=(e)=>{let n=e.data,t=this.active;if(
|
|
1
|
+
var i=new Map;var l=0;function u(e,n){let t=n?void 0:i.get(e);if(t===void 0)return null;return i.delete(e),i.set(e,t),{...t,tokens:structuredClone(t.tokens)}}function h(e){if(e.isStreaming||e.text.length>1048576)return;if(i.delete(e.text))l-=e.text.length;i.set(e.text,{...e,tokens:structuredClone(e.tokens)}),l+=e.text.length;while(l>2097152||i.size>200){let n=i.keys().next().value;l-=n.length,i.delete(n)}}class a{worker=new Worker(new URL("./markdown-parser.worker.js",import.meta.url),{type:"module"});clients=new Map;pending=new Map;active=null;failure=null;nextClientId=0;constructor(){this.worker.onmessage=(e)=>{let n=e.data,t=this.active;if(n.clientId!==t?.clientId||n.revision!==t.revision){this.fail(Error("Markdown worker returned an unexpected request"));return}if(this.active=null,!n.ok){this.fail(Error(n.error));return}let r={...t.input,tokens:n.tokens};h(r);let s=this.clients.get(t.clientId),o=this.pending.get(t.clientId),d=o!==void 0&&t.input.isStreaming&&o.input.isStreaming&&o.input.text.startsWith(t.input.text);if(s!==void 0&&(s.revision===t.revision||d))s.onResult(r);this.dispatch()},this.worker.onerror=(e)=>this.fail(Error(e.message)),this.worker.onmessageerror=()=>this.fail(Error("Cannot deserialize Markdown parsing result"))}fail(e){this.failure=e,this.worker.terminate(),this.pending.clear(),this.active=null;for(let n of this.clients.values())n.onError(e)}send(e){try{this.worker.postMessage(e)}catch(n){this.fail(n instanceof Error?n:Error(String(n)))}}dispatch(){if(this.active!==null||this.pending.size===0)return;let e=this.pending.values().next().value;this.pending.delete(e.clientId),this.active=e,this.send({type:"parse",clientId:e.clientId,revision:e.revision,source:e.input.source})}connect(e,n){if(this.failure!==null)throw this.failure;let t=++this.nextClientId,r={revision:0,onResult:e,onError:n};return this.clients.set(t,r),{update:(s)=>{if(this.failure!==null)throw this.failure;r.revision+=1;let o=u(s.text,s.isStreaming);if(o!==null){this.pending.delete(t),r.onResult(o);return}this.pending.set(t,{clientId:t,revision:r.revision,input:s}),this.dispatch()},dispose:()=>{if(!this.clients.delete(t))return;if(this.pending.delete(t),this.clients.size===0)this.worker.terminate(),c=void 0;else if(this.failure===null)this.send({type:"dispose",clientId:t})}}}}var c;function f(e,n){return c??=new a,c.connect(e,n)}export{u as cachedMarkdown,f as createMarkdownParser};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Marked as d}from"marked";import m from"marked-linkify-it";var h=/<(task-notification|system-reminder|antml:[\w-]+)\b[^>]*>/,x=/^<(task-notification|system-reminder|antml:[\w-]+)\b[^>]*>[\s\S]*?(?:<\/\1\s*>|$)/,f=/^(?:\$\$([\s\S]+?)\$\$|\\\[([\s\S]+?)\\\])/,k={extensions:[{name:"math",level:"block",tokenizer(n){let e=f.exec(n);if(e===null)return;return{type:"math",raw:e[0],text:(e[1]??e[2]).trim(),display:!0}}},{name:"math",level:"inline",start(n){return n.search(/\$|\\[([]/)},tokenizer(n){let e=f.exec(n);if(e!==null)return{type:"math",raw:e[0],text:(e[1]??e[2]).trim(),display:!0};let r=/^\\\(([^\n]+?)\\\)/.exec(n);if(r!==null)return{type:"math",raw:r[0],text:r[1].trim(),display:!1};let a=/^\$(?!\$)((?:\\[^\n]|[^\\$\n])+?)\$(?![\d$])/.exec(n);if(a===null||/^\s|\s$/.test(a[1]))return;return{type:"math",raw:a[0],text:a[1],display:!1}}}]};function g(){let n=new d({gfm:!0}),e=m(),r=e.extensions[0],a=r.tokenizer;r.tokenizer=function(
|
|
1
|
+
import{Marked as d}from"marked";import m from"marked-linkify-it";var h=/<(task-notification|system-reminder|antml:[\w-]+)\b[^>]*>/,x=/^<(task-notification|system-reminder|antml:[\w-]+)\b[^>]*>[\s\S]*?(?:<\/\1\s*>|$)/,f=/^(?:\$\$([\s\S]+?)\$\$|\\\[([\s\S]+?)\\\])/,k={extensions:[{name:"math",level:"block",tokenizer(n){let e=f.exec(n);if(e===null)return;return{type:"math",raw:e[0],text:(e[1]??e[2]).trim(),display:!0}}},{name:"math",level:"inline",start(n){return n.search(/\$|\\[([]/)},tokenizer(n){let e=f.exec(n);if(e!==null)return{type:"math",raw:e[0],text:(e[1]??e[2]).trim(),display:!0};let r=/^\\\(([^\n]+?)\\\)/.exec(n);if(r!==null)return{type:"math",raw:r[0],text:r[1].trim(),display:!1};let a=/^\$(?!\$)((?:\\[^\n]|[^\\$\n])+?)\$(?![\d$])/.exec(n);if(a===null||/^\s|\s$/.test(a[1]))return;return{type:"math",raw:a[0],text:a[1],display:!1}}}]};function g(){let n=new d({gfm:!0}),e=m(),r=e.extensions[0],a=r.tokenizer;r.tokenizer=function(l,i){let t=a.call(this,l,i);if(t===void 0)return;if(t.raw.startsWith("<"))return t;let o=/^(?:[a-z][a-z\d+.-]*:\/\/|www\.)[^/?#]+[/?#]/i.exec(t.raw);if(o===null)return t;let c=o[0].length-1,u=t.raw.slice(c).search(/[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}]/u);if(u===-1)return t;let s=t.raw.slice(0,c+u),p=t.href.slice(0,t.href.length-(t.raw.length-s.length));return{...t,raw:s,href:p,text:s,tokens:[{type:"text",raw:s,text:s}]}},n.use(k,e);for(let l of["block","inline"])n.use({extensions:[{name:"internalMessage",level:l,...l==="inline"?{start(i){return h.exec(i)?.index}}:{},tokenizer(i){let t=x.exec(i);if(t===null)return;return{type:"internalMessage",raw:t[0]}},renderer(){return""}}]});return n}function z(n){let e=n.replaceAll(/[\p{Cc}\s]/gu,"");return!/^(?:data|javascript|vbscript):/i.test(e)}export{g as createChatMarkdown,z as isSafeMarkdownUrl};
|
package/dist/lib/stream-style.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var p=["full","compact","codexUI"];function l(e){return e==="compact"||e==="codexUI"}var d=["read","edit","delete","move","search","execute","think","fetch","switch_mode","other"];function a(e){let n=e.split(/[/\\]/);return n
|
|
1
|
+
var p=["full","compact","codexUI"];function l(e){return e==="compact"||e==="codexUI"}var d=["read","edit","delete","move","search","execute","think","fetch","switch_mode","other"];function a(e){let n=e.split(/[/\\]/).at(-1)??"";return n===""?e:n}function f(e){let n=d.includes(e.kind)?e.kind:"other",i=e.rawInput,t=(s)=>{let r=i[s];return typeof r==="string"&&r.length>0?r:void 0},o=e.locations?.[0]?.path??t("file_path")??t("notebook_path"),c=o!==void 0?a(o):t("command")?.split(`
|
|
2
2
|
`)[0]??t("pattern")??t("url")??t("query")??t("description");return{category:n,...c===void 0?{}:{target:c},...o===void 0?{}:{filePath:o}}}function h(e,n){if(n)return"dot-permission";switch(e){case"completed":return"dot-success";case"failed":return"dot-error";case"in_progress":return"dot-in-progress";case"pending":return"dot-pending";case"interrupted":return"dot-interrupted";default:return console.warn("[acp] unknown tool call status:",e),"dot-pending"}}export{p as STREAM_STYLES,d as TOOL_CATEGORIES,f as describeToolUse,l as isCodexLook,h as toolDotClass};
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{createChatMarkdown as w}from"./markdown-rules.js";function g(e,s){let
|
|
2
|
-
`);if(!
|
|
1
|
+
import{createChatMarkdown as w}from"./markdown-rules.js";function g(e,s){let n=Object.keys(e);return n.length===Object.keys(s).length&&n.every((l)=>{let i=s[l];return e[l].href===i?.href&&e[l].title===i.title})}function b(e,s){let n=2,l=0;for(let t=e.length-1;t>=0;t-=1){if(e[t].type==="space")continue;if(n-=1,n===0){l=t;break}}let i=0;for(let t=0;t<l;t+=1){let o=e[t];if(o.type==="def"||/^ {0,3}(?:\[|<|\$\$|\\\[)/.test(o.raw))return i;let f=!1;if(s.walkTokens([e[t]],(a)=>{if(a.type==="html"&&(("inLink"in a)&&a.inLink||("inRawBlock"in a)&&a.inRawBlock))f=!0}),f)return i;if(/\n[\t ]*\n$/.test(e[t].raw))i=t+1}return i}function x(e=w()){let s="",n=[],l={},i={};return{parse(t){let o=t.replaceAll(/\r\n|\r/g,`
|
|
2
|
+
`);if(!o.startsWith(s))s="",n=[],l={},i={};let f=new e.Lexer(e.defaults);f.tokens.links={...l};let a=f.lex(o.slice(s.length)),u=[...n,...a],k=a.links;if(n.length>0&&!g(i,k)){let r=e.lexer(o);u=[...r],k=r.links}i=k;let d=0,h=[];for(let r of u){if(!o.startsWith(r.raw,d))break;h.push(r),d+=r.raw.length}return n=h.slice(0,b(h,e)),s=o.slice(0,n.reduce((r,c)=>r+c.raw.length,0)),l=Object.create(null),e.walkTokens(n,(r)=>{if(r.type!=="def")return;let c=r;if(!Object.hasOwn(l,c.tag))l[c.tag]={href:c.href,title:c.title}}),structuredClone(u)}}}export{x as createStreamingMarkdownLexer};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{jsx as b,jsxs as G,Fragment as Y}from"react/jsx-runtime";import{cn as Z}from"cn";import{SearchIcon as V}from"lucide-react";import{useCallback as N,useEffect as f,useMemo as O,useRef as
|
|
1
|
+
import{jsx as b,jsxs as G,Fragment as Y}from"react/jsx-runtime";import{cn as Z}from"cn";import{SearchIcon as V}from"lucide-react";import{useCallback as N,useEffect as f,useMemo as O,useRef as x,useState as E}from"react";import{Button as tt}from"../ui/button.js";import{FindBar as et}from"./find-bar.js";import{collectMatches as P}from"./dom-matches.js";import{collectMatches as mt}from"./dom-matches.js";var z="chat-search",K="chat-search-current",D=150;function at(n){let e=n??"";return[...document.querySelectorAll("[data-chat-scroll]")].find((c)=>c.dataset.chatScroll===e)??null}var rt=12;function Q(n,e="center"){let c=n.closest("[data-chat-scroll]");if(!c)return;let d=n.getBoundingClientRect(),g=c.getBoundingClientRect(),v=e==="start"?rt:(c.clientHeight-d.height)/2;c.scrollTo({top:c.scrollTop+(d.top-g.top)-v,behavior:"smooth"})}function B(n){let e=n.startContainer.parentElement;if(!e)return;Q(e)}var R=new Map;function U(){if(typeof CSS>"u"||!("highlights"in CSS)||typeof Highlight>"u")return;if(R.size===0){CSS.highlights.delete(z),CSS.highlights.delete(K);return}let n=[...R.values()];CSS.highlights.set(z,new Highlight(...n.flatMap((e)=>e.all))),CSS.highlights.set(K,new Highlight(...n.flatMap((e)=>e.current?[e.current]:[])))}function nt(){let n=Symbol();return{clearHighlights:()=>{R.delete(n),U()},applyHighlights:(e,c)=>{R.set(n,{all:e,current:c}),U()}}}function ft({getViewport:n,findSourceMatches:e,revealTurn:c,subscribeOpen:d,labels:g,placement:v="header"}){let{clearHighlights:i,applyHighlights:m}=O(nt,[]),p=e!==void 0,[s,I]=E(!1),[l,L]=E(""),a=O(()=>s&&l.trim()&&e?e(l.trim()):[],[e,s,l]),[F,T]=E(0),[J,w]=E(0),C=x([]),y=x(0),u=x(null),j=x(null),q=x(null);f(()=>{if(!d)return;return d(()=>{I(!0);let t=q.current;if(t!==null)t.focus(),t.select()})},[d]);let M=N(async(o,t)=>{let r=a[o];if(r===void 0)return;let h=n();if(h===null)throw Error("Chat scroll container is missing");if(c)await c(r.turnKey,t);if(t.aborted)return;let S=h.querySelector(`[data-turn-key="${CSS.escape(r.turnKey)}"]`);if(S===null)throw Error(`Codex turn is missing: ${r.turnKey}`);if(!c)Q(S,"start");if(await new Promise((X)=>requestAnimationFrame(()=>X())),t.aborted)return;let A=P(S,l.trim());C.current=A;let k=A[r.occurrenceInTurn];if(m(A,k??null),k!==void 0)B(k)},[m,a,n,l,c]),_=x(M);f(()=>{_.current=M},[M]);let H=N(()=>{I(!1),L(""),y.current=0,u.current?.abort(),u.current=null,i(),C.current=[]},[i]);f(()=>{if(!s)return;let o=(t)=>{if(t.key==="Escape"&&j.current?.contains(document.activeElement))t.preventDefault(),H()};return window.addEventListener("keydown",o),()=>window.removeEventListener("keydown",o)},[s,H]),f(()=>{if(!s||!l.trim()){i(),C.current=[],T(0),w(0),y.current=0;return}let o=setTimeout(()=>{if(p)return;let t=n();if(!t)return;let r=P(t,l);if(C.current=r,T(r.length),w(0),m(r,r[0]??null),r[0])B(r[0])},D);return()=>{clearTimeout(o),i()}},[m,i,p,s,l,n]),f(()=>{if(!s||!p||!l.trim())return;let o=new AbortController;u.current?.abort(),u.current=o;let t=setTimeout(()=>{C.current=[],y.current=0,T(a.length),w(0),i(),_.current(0,o.signal)},D);return()=>{if(o.abort(),u.current===o)u.current=null;clearTimeout(t),i()}},[i,a.length,p,s,l]),f(()=>()=>{u.current?.abort(),i()},[i]),f(()=>{if(!s)i()},[i,s]);let W=N((o)=>{if(p){if(a.length===0)return;let r=(y.current+(o?-1:1)+a.length)%a.length;y.current=r,w(r),u.current?.abort();let h=new AbortController;u.current=h,_.current(r,h.signal);return}let t=C.current;if(!t.length)return;w((r)=>{let h=(r+(o?-1:1)+t.length)%t.length,S=t[h];return m(t,S),B(S),h})},[m,a.length,p]);return G(Y,{children:[v==="header"&&b(tt,{variant:"ghost",size:"icon-sm",title:g.search,onClick:()=>s?H():I(!0),children:b(V,{})}),s&&G("div",{"data-chat-search":!0,ref:j,className:Z("bg-background border-b",v==="body"?"relative shrink-0":"absolute inset-x-0 top-full z-30"),children:[b(et,{ref:q,value:l,onChange:L,onFind:W,onClose:H,placeholder:g.placeholder,prevTitle:g.previous,nextTitle:g.next}),l.trim()&&b("div",{className:"text-muted-foreground border-border border-t px-3 py-1 text-[11px]",children:F===0?"0 / 0":`${J+1} / ${F}`})]})]})}export{ft as ChatSearch,mt as collectMatches,at as findChatScrollContainer,Q as scrollChatElementIntoView};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
function*
|
|
1
|
+
function*l(r,t){if(t.length===0)return;let n=new RegExp(t.replaceAll(/[.*+?^{}()|[\]\\$]/g,String.raw`\$&`),"giu");for(let e of r.matchAll(n))yield{start:e.index,end:e.index+e[0].length}}function i(r,t){if(t.length===0)return[];let n=[];for(let{turnKey:e,segments:c}of r){let o=0;for(let f of c)for(let s of l(f,t))n.push({turnKey:e,occurrenceInTurn:o}),o+=1}return n}export{i as findTextSourceMatches,l as literalMatches};
|