@ycodium-ai/plugin-visualize 0.2.3240 → 0.2.3250
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/assets/ui.js +12 -11
- package/dist/index.js +1 -1
- package/package.json +2 -2
package/assets/ui.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
var
|
|
2
|
-
`,r:"\r",t:" "};function T(e){return
|
|
1
|
+
var J=window.__ycodiumPluginHost.react;var{Activity:he,Children:ye,Component:ve,Fragment:be,Profiler:xe,PureComponent:ze,StrictMode:we,Suspense:ke,__CLIENT_INTERNALS_DO_NOT_USE_OR_WARN_USERS_THEY_CANNOT_UPGRADE:Se,__COMPILER_RUNTIME:Ie,act:Ce,cache:Ee,cacheSignal:Te,captureOwnerStack:Ae,cloneElement:Pe,createContext:Ne,createElement:m,createRef:Re,forwardRef:Ve,isValidElement:_e,lazy:Fe,memo:Me,startTransition:Oe,unstable_useCacheRefresh:De,use:Le,useActionState:Be,useCallback:He,useContext:$e,useDebugValue:Ue,useDeferredValue:je,useEffect:f,useEffectEvent:Ge,useId:Ye,useImperativeHandle:We,useInsertionEffect:Je,useLayoutEffect:Ze,useMemo:g,useOptimistic:Qe,useReducer:qe,useRef:E,useState:y,useSyncExternalStore:Ke,useTransition:Xe,version:et}=J;var Z={'"':'"',"\\":"\\","/":"/",b:"\b",f:"\f",n:`
|
|
2
|
+
`,r:"\r",t:" "};function T(e){return Q(e,!1)}function Q(e,t){let n=/"fragment"\s*:\s*"/u.exec(e);if(!n)return;let r="";for(let i=n.index+n[0].length;i<e.length;i++){let o=e[i];if(o===void 0)break;if(o==='"')return r;if(o!=="\\"){r+=o;continue}let l=e[i+1];if(l===void 0)return t?void 0:r;if(l==="u"){let s=e.slice(i+2,i+6);if(s.length<4||!/^[0-9a-fA-F]{4}$/u.test(s))return t?void 0:r;r+=String.fromCharCode(Number.parseInt(s,16)),i+=5;continue}let d=Z[l];if(d===void 0)return t?void 0:r;r+=d,i+=1}return t?void 0:r}var q=/<script\b[^>]*>?(?![\s\S]*<script\b)/iu;function A(e){let t=q.exec(e);if(!t)return e;let n=e.slice(t.index+t[0].length);return/<\/script\s*>/iu.test(n)?e:e.slice(0,t.index)}var K=/(?:workspace copy at|updated card at) (viz\/[a-z0-9][a-z0-9-]{0,80}-[0-9a-f]{8}\.html)/u;function v(e){return e==null?null:K.exec(e)?.[1]??null}function N(e){if(typeof e!="object"||e===null)return null;let t=e;if(t.kind!=="visualize")return null;let n=t.fragment,r=t.title,i=t.path,o=t.mode,l=t.invocationId,d=t.action,s=t.sizeBytes;return typeof n!="string"||n.trim().length===0||typeof r!="string"||r.trim().length===0||typeof i!="string"||o!=="inline"&&o!=="wide"||d!=="create"&&d!=="update"||typeof l!="string"||typeof s!="number"||!Number.isFinite(s)?null:{kind:"visualize",invocationId:l,fragment:n,title:r,mode:o,path:i,sizeBytes:s,action:d}}function P(e,t){return N(e)??z(t)}function R(e){let t=v(e.confirmation),n=P(e.presentation,e.commandData);if(n!==null&&X(n,e.invocationId,t))return n;if(t===null)return null;let r=P(void 0,e.pathCommandData);return r===null||r.path!==t?null:r}function X(e,t,n){return!(n!==null&&e.path!==n||t.length>0&&e.invocationId!==t&&n===null)}function z(e){return typeof e!="object"||e===null?null:N(e.card)}function V(e){if(typeof e!="object"||e===null)return[];let t=e.cards;if(!Array.isArray(t))return[];let n=[];for(let r of t){if(typeof r!="object"||r===null)continue;let i=r,o=i.mode,l=i.action;typeof i.invocationId!="string"||typeof i.title!="string"||typeof i.path=="string"&&(o!=="inline"&&o!=="wide"||l!=="create"&&l!=="update"||typeof i.sizeBytes=="number"&&n.push({invocationId:i.invocationId,title:i.title,mode:o,path:i.path,sizeBytes:i.sizeBytes,action:l}))}return n}function w(e){return e===void 0?{}:{background:e.surface,foreground:e.foreground,card:e.surface,"muted-foreground":e.muted,border:e.border,primary:e.accent,"primary-foreground":e.surface}}function _(e){return e.querySelector('meta[name="ycodium-plugin-surface"]')!==null}function p(e){return e.i18n.usePluginTranslation()}var F=`
|
|
3
3
|
.ycodium-visualize-ui {
|
|
4
4
|
box-sizing: border-box;
|
|
5
5
|
width: 100%;
|
|
@@ -113,8 +113,9 @@ var W=window.__ycodiumPluginHost.react;var{Activity:he,Children:pe,Component:ye,
|
|
|
113
113
|
width: 100%;
|
|
114
114
|
min-width: 0;
|
|
115
115
|
}
|
|
116
|
-
`;var{jsx:a,jsxs:c,Fragment:dt}=window.__ycodiumPluginHost.jsxRuntime;function
|
|
116
|
+
`;var{jsx:a,jsxs:c,Fragment:dt}=window.__ycodiumPluginHost.jsxRuntime;function h(e){let t=p(e.bridge),[n,r]=y(!1),i=e.bridge.ui;f(()=>{r(!1)},[e.path]);let o={...e.colors===void 0?{}:{"--viz-fg":e.colors.foreground,"--viz-surface":e.colors.surface,"--viz-muted":e.colors.muted,"--viz-border":e.colors.border,"--viz-accent":e.colors.accent},colorScheme:e.colorScheme};return c("div",{className:"ycodium-visualize-ui","data-mode":e.mode,"data-status":e.status,"data-visualize-card":"",style:o,children:[a("style",{children:F}),c("article",{className:"ycodium-visualize-card","data-mode":e.mode,"data-status":e.status,children:[a("div",{className:"ycodium-visualize-accent"}),c("header",{className:"ycodium-visualize-header",children:[a("h3",{className:"ycodium-visualize-title",children:e.title}),c("div",{className:"ycodium-visualize-chips",children:[c("span",{className:"ycodium-visualize-chip",children:[a("span",{className:"ycodium-visualize-dot"}),t(ee(e.status))]}),a("span",{className:"ycodium-visualize-chip",children:e.mode==="wide"?t("card.modeWide"):t("card.modeInline")})]}),e.path.length>0?m(i.Button,{type:"button",size:"xs",variant:"outline",className:"ycodium-visualize-copy","aria-label":t(n?"card.copied":"card.copyPath"),onClick:()=>{e.bridge.writeClipboard(e.path).then(()=>{r(!0)})}},t(n?"card.copied":"card.copyPath")):null]}),e.sizeBytes!==null||e.path.length>0?c("div",{className:"ycodium-visualize-meta",children:[e.sizeBytes!==null?a("span",{children:t("card.bytes",{count:e.sizeBytes})}):null,e.path.length>0?a("span",{className:"ycodium-visualize-path",children:t("card.path",{path:e.path})}):null]}):null,e.children]})]})}function ee(e){switch(e){case"streaming":return"status.streaming";case"ready":return"status.ready";case"loading":return"status.loading";case"missing":return"status.missing";default:return e}}function M(e){return e.className.split(/\s+/u).includes("dark")||e.prefersDark?"dark":"light"}var k="ycodium-visualize:height",b="ycodium-visualize:stream";function O(e,t){if(typeof e!="object"||e===null)return null;let n=e;if(n.type!==k||n.token!==t)return null;let r=n.height;return typeof r!="number"||!Number.isFinite(r)||r<0?null:r}function D(e){return Math.min(960,Math.max(96,Math.round(e)))}var L=`
|
|
117
117
|
:root {
|
|
118
|
+
--control-cursor: var(--ycodium-viz-control-cursor, pointer);
|
|
118
119
|
color-scheme: light dark;
|
|
119
120
|
--background: var(--ycodium-viz-background, transparent);
|
|
120
121
|
--foreground: var(--ycodium-viz-foreground, light-dark(rgb(26 28 31), rgb(240 242 245)));
|
|
@@ -169,7 +170,7 @@ svg text { fill: var(--foreground); font-size: 12px; }
|
|
|
169
170
|
background: transparent;
|
|
170
171
|
color: var(--foreground);
|
|
171
172
|
font: inherit;
|
|
172
|
-
cursor: pointer;
|
|
173
|
+
cursor: var(--control-cursor, pointer);
|
|
173
174
|
}
|
|
174
175
|
.btn:hover { background: color-mix(in oklab, var(--foreground) 6%, transparent); }
|
|
175
176
|
.btn-primary,
|
|
@@ -231,21 +232,21 @@ table { border-collapse: collapse; width: 100%; }
|
|
|
231
232
|
th, td { text-align: left; padding: 5px 10px; border-bottom: 1px solid var(--border); }
|
|
232
233
|
th { font-weight: 500; color: var(--muted-foreground); font-size: 12px; }
|
|
233
234
|
.table-responsive { overflow-x: auto; }
|
|
234
|
-
`;var
|
|
235
|
+
`;var te=["https://cdnjs.cloudflare.com","https://cdn.jsdelivr.net","https://esm.sh","https://fonts.bunny.net","https://fonts.googleapis.com","https://fonts.gstatic.com","https://unpkg.com"],S=["blob:","data:",...te].join(" "),ne="'unsafe-inline' 'unsafe-eval' 'wasm-unsafe-eval' blob: data:",re="'unsafe-inline' blob: data:",ie=["default-src 'none'",`script-src ${ne}`,`style-src ${re}`,`img-src ${S}`,`font-src ${S}`,`media-src ${S}`,"worker-src blob:","connect-src blob: data:","frame-src 'none'","object-src 'none'","base-uri 'none'","form-action 'none'"].join("; ");function oe(e){let t=e.trim();return/[;{}<>]/u.test(t)?"":t}function I(e){let t=Object.entries(e.themeVars).map(([n,r])=>[n,oe(r)]).filter(([,n])=>n.length>0).map(([n,r])=>`--ycodium-viz-${n}: ${r};`).join(" ");return`<!doctype html>
|
|
235
236
|
<html lang="en">
|
|
236
237
|
<head>
|
|
237
238
|
<meta charset="utf-8">
|
|
238
239
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
239
240
|
<meta name="referrer" content="no-referrer">
|
|
240
|
-
<meta http-equiv="Content-Security-Policy" content="${
|
|
241
|
-
<title>${
|
|
241
|
+
<meta http-equiv="Content-Security-Policy" content="${ie}">
|
|
242
|
+
<title>${le(e.title)}</title>
|
|
242
243
|
<style>${L}
|
|
243
244
|
:root { ${t} color-scheme: ${e.colorScheme}; }
|
|
244
245
|
body { padding: 4px 2px; }</style>
|
|
245
246
|
</head>
|
|
246
247
|
<body>
|
|
247
248
|
${e.fragment}
|
|
248
|
-
<script>${
|
|
249
|
+
<script>${ae(e.reportToken)}<\/script>
|
|
249
250
|
</body>
|
|
250
251
|
</html>
|
|
251
252
|
`}function B(e){return I({...e,title:"preview",fragment:`<div id="ycodium-viz-stream-root"></div>
|
|
@@ -254,7 +255,7 @@ ${e.fragment}
|
|
|
254
255
|
@keyframes ycodium-viz-enter { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
|
|
255
256
|
@media (prefers-reduced-motion: reduce) { .ycodium-viz-enter { animation: none; } }
|
|
256
257
|
</style>
|
|
257
|
-
<script>${
|
|
258
|
+
<script>${se(e.reportToken)}<\/script>`})}function ae(e){let t=x(e);return`
|
|
258
259
|
(function () {
|
|
259
260
|
var post = function () {
|
|
260
261
|
parent.postMessage({
|
|
@@ -267,7 +268,7 @@ ${e.fragment}
|
|
|
267
268
|
addEventListener('load', post);
|
|
268
269
|
post();
|
|
269
270
|
})();
|
|
270
|
-
`}function
|
|
271
|
+
`}function se(e){return`
|
|
271
272
|
(function () {
|
|
272
273
|
var root = document.getElementById('ycodium-viz-stream-root');
|
|
273
274
|
var token = ${x(e)};
|
|
@@ -323,4 +324,4 @@ ${e.fragment}
|
|
|
323
324
|
sync(root, next);
|
|
324
325
|
});
|
|
325
326
|
})();
|
|
326
|
-
`}function x(e){return JSON.stringify(e).replaceAll("<","\\u003c")}function
|
|
327
|
+
`}function x(e){return JSON.stringify(e).replaceAll("<","\\u003c")}function le(e){return e.replaceAll("&","&").replaceAll("<","<").replaceAll(">",">")}function H(e){let t=e.colorScheme??j(),n=G(),r=g(()=>I({fragment:e.fragment,title:e.title,themeVars:{...w(e.colors),"control-cursor":n},colorScheme:t,reportToken:e.token}),[e.colors,e.fragment,e.title,e.token,t,n]);return a(U,{srcDoc:r,token:e.token,title:e.frameLabel,fragment:null})}function $(e){let t=j(),n=G(),r=g(()=>B({themeVars:{...w(e.colors),"control-cursor":n},colorScheme:t,reportToken:e.token}),[e.colors,e.token,t,n]);return a(U,{srcDoc:r,token:e.token,title:e.frameLabel,fragment:A(e.fragment)})}function U(e){let t=E(null),[n,r]=y(160);return f(()=>{let i=t.current;if(i===null)return;let o=l=>{if(l.source!==i.contentWindow)return;let d=O(l.data,e.token);d!==null&&r(D(d))};return window.addEventListener("message",o),()=>window.removeEventListener("message",o)},[e.token]),f(()=>{let i=t.current;if(i===null||e.fragment===null)return;let o=()=>{i.contentWindow?.postMessage({type:b,token:e.token,fragment:e.fragment},"*")};return i.addEventListener("load",o),o(),()=>i.removeEventListener("load",o)},[e.fragment,e.token]),a("div",{className:"ycodium-visualize-viewport",children:a("iframe",{ref:t,title:e.title,sandbox:"allow-scripts",srcDoc:e.srcDoc,style:{height:n}})})}function j(){let e=window.matchMedia?.("(prefers-color-scheme: dark)").matches??!1;return M({className:document.documentElement.className,prefersDark:e})}function G(){return window.getComputedStyle?.(document.documentElement).getPropertyValue("--control-cursor").trim()||"pointer"}function C(e){let t=p(e.bridge),n=e.threadRef?.threadId??"",r=e.invocationId??"",i=me(e.entry,e.details),o=v(i),l=e.bridge.commands.useQuery("card",{threadId:n,invocationId:r,path:""},{environmentId:e.environmentId}),d=e.bridge.commands.useQuery("card",{threadId:n,invocationId:o??"",path:o??""},{environmentId:e.environmentId}),s=R({invocationId:r,presentation:e.presentation,commandData:l.data,pathCommandData:d.data,confirmation:i}),u=e.colors;return s===null&&(l.isPending||o!==null&&d.isPending)?a(h,{bridge:e.bridge,title:t("status.loading"),mode:"inline",path:"",sizeBytes:null,status:"loading",...u===void 0?{}:{colors:u},...e.colorScheme===void 0?{}:{colorScheme:e.colorScheme},children:a("p",{className:"ycodium-visualize-note",children:t("card.loading")})}):s===null?a(h,{bridge:e.bridge,title:t("status.missing"),mode:"inline",path:"",sizeBytes:null,status:"missing",...u===void 0?{}:{colors:u},...e.colorScheme===void 0?{}:{colorScheme:e.colorScheme},children:a(ce,{bridge:e.bridge,title:t("status.missing"),description:t("card.missing")})}):a(h,{bridge:e.bridge,title:s.title,mode:s.mode,path:s.path,sizeBytes:s.sizeBytes,status:"ready",...u===void 0?{}:{colors:u},...e.colorScheme===void 0?{}:{colorScheme:e.colorScheme},children:a(H,{fragment:s.fragment,title:s.title,token:s.invocationId.length>0?s.invocationId:r,frameLabel:t("card.frame",{title:s.title}),...u===void 0?{}:{colors:u},...e.colorScheme===void 0?{}:{colorScheme:e.colorScheme}})})}function Y(e){return typeof e.argumentsText!="string"?null:a(de,{...e})}function de(e){let t=p(e.bridge),n=T(e.argumentsText),r=n===void 0?"":n.trim();return a(h,{bridge:e.bridge,title:t("status.streaming"),mode:"inline",path:"",sizeBytes:r.length===0?null:new TextEncoder().encode(r).length,status:"streaming",children:r.length===0?a("p",{className:"ycodium-visualize-note",children:t("dock.waiting")}):a($,{fragment:r,token:e.threadId,frameLabel:t("card.frame",{title:t("status.streaming")})})})}function W(e){return!_(document)||e.environmentId===void 0||e.threadId===void 0||e.threadId.length===0?null:a(ue,{bridge:e.bridge,environmentId:e.environmentId,threadId:e.threadId})}function ue(e){let t=e.bridge.commands.useSubscription("cards",{threadId:e.threadId},{environmentId:e.environmentId}),n=g(()=>V(t.data),[t.data]),r=g(()=>n.map(o=>({environmentId:e.environmentId,payload:{threadId:e.threadId,invocationId:o.invocationId}})),[n,e.environmentId,e.threadId]),i=e.bridge.commands.useQueryEach("card",r);return n.length===0?null:a("div",{className:"ycodium-visualize-stack",children:n.map((o,l)=>{let d=ge(i.rows[l]?.data);return a(C,{bridge:e.bridge,environmentId:e.environmentId,invocationId:o.invocationId,entry:fe(o.invocationId),details:{files:[],inputFields:[]},...d===void 0?{}:{presentation:d},...e.threadId.length>0?{threadRef:{environmentId:e.environmentId,threadId:e.threadId}}:{}},o.invocationId)})})}function ce(e){let t=e.bridge.ui;return m(t.Alert,{variant:"error",layout:"inline"},m(t.AlertTitle,null,e.title),m(t.AlertDescription,null,e.description))}function me(e,t){let n=e.toolIo?.output??t.output?.text??e.detail;return typeof n=="string"&&n.length>0?n:null}function ge(e){return z(e)??void 0}function fe(e){return{id:e,label:"",displayFailed:!1}}function pe(e){return{views:{card(t){return a(C,{bridge:e,...t})}},slots:[{name:"conversation.input.dock",component(t){return a(Y,{bridge:e,...t})}},{name:"conversation.chat.turnTail",component(t){return a(W,{bridge:e,...t})}}]}}export{pe as default};
|
package/dist/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ycodium-ai/plugin-visualize",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.3250",
|
|
4
4
|
"description": "Renders an inline HTML fragment as a sandboxed card in the conversation.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"visualization",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"react": "19.2.6",
|
|
26
26
|
"typescript": "~6.0.3",
|
|
27
27
|
"vite-plus": "0.2.2",
|
|
28
|
-
"@ycodium-ai/plugin-api": "0.2.
|
|
28
|
+
"@ycodium-ai/plugin-api": "0.2.3250"
|
|
29
29
|
},
|
|
30
30
|
"ycodium": {
|
|
31
31
|
"plugin": "./dist/index.js",
|