data-navigator 2.3.1 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +78 -22
- package/dist/index.d.cts +265 -0
- package/dist/index.d.ts +265 -0
- package/dist/index.js +78 -22
- package/dist/structure.cjs +1 -1
- package/dist/structure.js +1 -1
- package/dist/text-chat.cjs +13 -13
- package/dist/text-chat.js +8 -8
- package/package.json +5 -5
package/dist/text-chat.cjs
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
var
|
|
1
|
+
var q=Object.defineProperty;var ue=Object.getOwnPropertyDescriptor;var he=Object.getOwnPropertyNames;var me=Object.prototype.hasOwnProperty;var pe=(t,e)=>{for(var i in e)q(t,i,{get:e[i],enumerable:!0})},ge=(t,e,i,s)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of he(e))!me.call(t,r)&&r!==i&&q(t,r,{get:()=>e[r],enumerable:!(s=ue(e,r))||s.enumerable});return t};var fe=t=>ge(q({},"__esModule",{value:!0}),t);var B=(t,e,i)=>new Promise((s,r)=>{var n=l=>{try{h(i.next(l))}catch(d){r(d)}},o=l=>{try{h(i.throw(l))}catch(d){r(d)}},h=l=>l.done?s(l.value):Promise.resolve(l.value).then(n,o);h((i=i.apply(t,e)).next())});var Ne={};pe(Ne,{default:()=>xe});module.exports=fe(Ne);var J={ArrowLeft:"left",ArrowRight:"right",ArrowUp:"up",ArrowDown:"down",Period:"forward",Comma:"backward",Escape:"parent",Enter:"child"};var G={left:{key:"ArrowLeft",direction:"source"},right:{key:"ArrowRight",direction:"target"},up:{key:"ArrowUp",direction:"source"},down:{key:"ArrowDown",direction:"target"},child:{key:"Enter",direction:"target"},parent:{key:"Backspace",direction:"source"},backward:{key:"Comma",direction:"source"},forward:{key:"Period",direction:"target"},previous:{key:"Semicolon",direction:"source"},next:{key:"Quote",direction:"target"},exit:{key:"Escape",direction:"target"},help:{key:"KeyY",direction:"target"},undo:{key:"KeyZ",direction:"target"}};var ne=t=>{let e={},i=J,s=G;return e.moveTo=r=>{let n=t.structure.nodes[r];if(n)return n},e.move=(r,n)=>{if(r){let o=t.structure.nodes[r];if(o.edges){let h=null,l=0,d=s[n];if(!d)return;let f=(g,a)=>{if(g!==n)return null;let b={target:typeof a.target=="string"?a.target:a.target(o,r),source:typeof a.source=="string"?a.source:a.source(o,r)};return b[d.direction]!==r?b[d.direction]:null};for(l=0;l<o.edges.length;l++){let g=t.structure.edges[o.edges[l]];if(g.navigationRules.forEach(a=>{h||(h=f(a,g))}),h)break}return h?e.moveTo(h):void 0}}},e.enter=()=>{if(t.entryPoint)return e.moveTo(t.entryPoint);console.error("No entry point was specified in InputOptions, returning undefined")},e.exit=()=>{if(t.exitPoint)return t.exitPoint;console.error("No exit point was specified in InputOptions, returning undefined")},e.keydownValidator=r=>{let n=i[r.code];if(n)return n},e.focus=r=>{let n=document.getElementById(r);n&&n.focus()},e.setNavigationKeyBindings=r=>{r?(i={},s=r,Object.keys(r).forEach(n=>{let o=r[n];i[o.key]=n})):(i=J,s=G)},e.setNavigationKeyBindings(t.navigationRules),e};var ye=t=>{var e,i,s,r,n;if((e=t.semantics)!=null&&e.label){let o=typeof t.semantics.label=="function"?t.semantics.label():t.semantics.label;if(o)return o}if(!t.derivedNode)return t.data?Object.keys(t.data).map(o=>`${o}: ${t.data[o]}`).join(". ")+". Data point.":t.id;if((i=t.data)!=null&&i.dimensionKey){let o=0,h=Object.keys(t.data.divisions||{});h.forEach(d=>{o+=Object.keys(t.data.divisions[d].values||{}).length});let l=`${t.derivedNode}.`;return l+=h.length&&o?` ${h.length} division${h.length>1?"s":""}, ${o} datapoint${o>1?"s":""}.`:" No child data points.",l+=` ${t.data.type} dimension.`,l}return`${t.derivedNode}: ${(s=t.data)==null?void 0:s[t.derivedNode]}. ${Object.keys(((r=t.data)==null?void 0:r.values)||{}).length} child data point${Object.keys(((n=t.data)==null?void 0:n.values)||{}).length>1?"s":""}. Division.`},ve=(t,e,i)=>{let s=new Set,r=i.navigationRules||{};return e.edges&&e.edges.forEach(n=>{let o=i.edges[n];o&&o.navigationRules.forEach(h=>{let l=r[h];if(!l)return;let d=l.direction==="target"?o.target:o.source,f=typeof d=="function"?d(e,t):d;f&&f!==t&&s.add(h)})}),Array.from(s)},re=t=>t.navigationRules?Object.keys(t.navigationRules):[],z=(t,e)=>{let i=t.length,s=e.length,r=Array.from({length:i+1},()=>Array(s+1).fill(0));for(let n=0;n<=i;n++)r[n][0]=n;for(let n=0;n<=s;n++)r[0][n]=n;for(let n=1;n<=i;n++)for(let o=1;o<=s;o++){let h=t[n-1]===e[o-1]?0:1;r[n][o]=Math.min(r[n-1][o]+1,r[n][o-1]+1,r[n-1][o-1]+h),n>1&&o>1&&t[n-1]===e[o-2]&&t[n-2]===e[o-1]&&(r[n][o]=Math.min(r[n][o],r[n-2][o-2]+h))}return r[i][s]},be=t=>t<=4?1:2,we=(t,e,i={})=>{let s=t.toLowerCase().trim(),r=e.find(a=>a.toLowerCase()===s);if(r)return{match:r,ambiguous:[]};let n=e.find(a=>i[a]&&i[a].toLowerCase()===s);if(n)return{match:n,ambiguous:[]};let o=e.filter(a=>a.toLowerCase().startsWith(s));if(o.length===1)return{match:o[0],ambiguous:[]};let h=e.filter(a=>{if(!i[a])return!1;let b=i[a].toLowerCase();return b.startsWith(s)?!0:b.split(/\s+/).some(A=>A.startsWith(s))}),l=new Set([...o,...h]),d=Array.from(l);if(d.length===1)return{match:d[0],ambiguous:[]};if(d.length>1)return{match:null,ambiguous:d};let f=be(s.length),g=[];for(let a=0;a<e.length;a++){let b=e[a],A=z(s,b.toLowerCase());if(A<=f){g.push({candidate:b,dist:A});continue}if(i[b]){let v=i[b].toLowerCase().split(/\s+/);for(let R=0;R<v.length;R++)if(z(s,v[R])<=f){g.push({candidate:b,dist:z(s,v[R])});break}}}return g.length===1?{match:g[0].candidate,ambiguous:[]}:g.length>1?(g.sort((a,b)=>a.dist-b.dist),g[0].dist<g[1].dist?{match:g[0].candidate,ambiguous:[]}:{match:null,ambiguous:g.map(a=>a.candidate)}):{match:null,ambiguous:[]}},V=(t,e)=>e[t]?`${e[t]} (${t})`:t,ke=(t,e,i,s=10)=>{let r=t.toLowerCase(),n=[],o=Object.keys(e.nodes);for(let h=0;h<o.length&&n.length<s;h++){let l=o[h],d=e.nodes[l],f=!1;if(d.data&&!f){let g=Object.keys(d.data);for(let a=0;a<g.length&&!f;a++){let b=d.data[g[a]];b!=null&&typeof b!="object"&&String(b).toLowerCase().includes(r)&&(f=!0)}}!f&&d.derivedNode&&d.derivedNode.toLowerCase().includes(r)&&(f=!0),!f&&l.toLowerCase().includes(r)&&(f=!0),f&&n.push({nodeId:l,description:i(d)})}return n},xe=t=>{var te;let{structure:e,container:i,entryPoint:s,describeNode:r=ye,commandLabels:n={},onNavigate:o,onExit:h,onClick:l,onHover:d,llm:f,data:g}=t,a=typeof i=="string"?document.getElementById(i):i;if(!a)throw new Error(`textChat: container "${i}" not found`);let b=s||(e.dimensions?(te=e.dimensions[Object.keys(e.dimensions)[0]])==null?void 0:te.nodeId:Object.keys(e.nodes)[0]),A=ne({structure:e,navigationRules:e.navigationRules||{},entryPoint:b}),v=null,R=Math.random().toString(36).slice(2,8),L=[],C=-1,O=null,S=[],oe=()=>{let c=`You are a data assistant helping a user explore a dataset through a text-based navigation interface.
|
|
2
2
|
|
|
3
|
-
`;if(
|
|
4
|
-
`);
|
|
5
|
-
- Columns: ${
|
|
6
|
-
- Rows: ${
|
|
3
|
+
`;if(g&&g.length>0){let p=Object.keys(g[0]),m=g.slice(0,3).map(N=>JSON.stringify(N)).join(`
|
|
4
|
+
`);c+=`DATASET SUMMARY:
|
|
5
|
+
- Columns: ${p.join(", ")}
|
|
6
|
+
- Rows: ${g.length}
|
|
7
7
|
- Sample (first 3):
|
|
8
|
-
${
|
|
8
|
+
${m}
|
|
9
9
|
|
|
10
|
-
`,
|
|
11
|
-
`+JSON.stringify(
|
|
10
|
+
`,c+=`FULL DATASET (JSON):
|
|
11
|
+
`+JSON.stringify(g)+`
|
|
12
12
|
|
|
13
|
-
`}if(
|
|
13
|
+
`}if(v){let p=e.nodes[v];c+=`CURRENT POSITION: ${p?r(p):v}
|
|
14
14
|
|
|
15
|
-
`}else
|
|
15
|
+
`}else c+=`CURRENT POSITION: Not yet navigated into the structure.
|
|
16
16
|
|
|
17
|
-
`;return
|
|
17
|
+
`;return c+=`PRIORITY: Always prefer answers that can be verified against the dataset. For any statistical or quantitative claim (averages, comparisons, trends, extremes), briefly describe the method you used. Avoid open-ended or contextual claims that go beyond what the data can support \u2014 if the user asks something that cannot be checked against the dataset, say so and suggest they verify externally.
|
|
18
18
|
|
|
19
|
-
`,
|
|
19
|
+
`,c+=`VERIFICATION: When the user asks you to verify a claim, write a short Python script (using the dataset as a JSON array) that computes the answer, and show the expected output. If the claim is too open-ended to verify with code, explain why and recommend external verification.
|
|
20
20
|
|
|
21
|
-
`,
|
|
21
|
+
`,c+='IMPORTANT: Your responses may contain errors. The user has been told they can ask you to "verify" any answer, and you will attempt to provide a Python script to check it.',c},$=document.createElement("div");$.className="dn-text-chat";let k=document.createElement("div");k.className="dn-text-chat-log",k.setAttribute("role","log"),k.setAttribute("aria-live","polite"),$.appendChild(k);let U=document.createElement("div");U.className="dn-text-chat-controls";let W=document.createElement("label"),P=document.createElement("input");P.type="checkbox",P.checked=!0,P.addEventListener("change",()=>{k.setAttribute("aria-live",P.checked?"polite":"off")}),W.appendChild(P),W.appendChild(document.createTextNode(" Automatically announce to screen readers")),U.appendChild(W),$.appendChild(U);let I=document.createElement("form");I.className="dn-text-chat-form";let M=document.createElement("label");M.setAttribute("for",`dn-text-chat-input-${R}`),M.className="dn-text-chat-sr-only",M.textContent="Navigation command";let x=document.createElement("input");x.type="text",x.id=`dn-text-chat-input-${R}`,x.autocomplete="off",x.setAttribute("placeholder","Type a command...");let F=document.createElement("button");F.type="submit",F.textContent="Send",I.appendChild(M),I.appendChild(x),I.appendChild(F),$.appendChild(I),a.appendChild($);let Q="";x.addEventListener("keydown",c=>{if(c.key==="ArrowUp"){if(c.preventDefault(),L.length===0)return;C===-1?(Q=x.value,C=L.length-1):C>0&&C--,x.value=L[C]}else if(c.key==="ArrowDown"){if(c.preventDefault(),C===-1)return;C<L.length-1?(C++,x.value=L[C]):(C=-1,x.value=Q)}});let Y=(c,p)=>{let m=document.createElement("div");m.className=`dn-text-chat-message ${p}`,m.textContent=c,k.appendChild(m),k.scrollTop=k.scrollHeight},D=c=>Y(c,"dn-text-chat-system"),ie=c=>Y(`> ${c}`,"dn-text-chat-input-echo"),y=c=>Y(c,"dn-text-chat-response"),ae=(c,p)=>{let m=document.createElement("div");m.className="dn-text-chat-message dn-text-chat-response";let N=document.createElement("span");N.textContent=c,m.appendChild(N);let E=document.createElement("ol");E.className="dn-text-chat-choices",p.forEach(H=>{let T=document.createElement("li");T.textContent=H,E.appendChild(T)}),m.appendChild(E),k.appendChild(m),k.scrollTop=k.scrollHeight},Z=c=>B(void 0,null,function*(){let p={role:"system",content:oe()};S.push({role:"user",content:c});let m=document.createElement("div");m.className="dn-text-chat-message dn-text-chat-llm-thinking",m.textContent="Thinking...",k.appendChild(m),k.scrollTop=k.scrollHeight;try{let N=yield f([p,...S]);return k.removeChild(m),N===null?(S.pop(),null):(S.push({role:"assistant",content:N}),y(N),N)}catch(N){return k.removeChild(m),S.pop(),y(`Error: ${N.message||"Could not get a response."}`),""}});f?(D('Text navigation ready. Type "enter" to begin navigating, "help" for commands, or ask a question about the data.'),D('Note: AI-generated answers may be inaccurate. You can ask the model to "verify" any answer \u2014 it will attempt to provide a Python script that checks the claim against the dataset. If a claim cannot be verified with code, it should be verified externally.')):D('Text navigation ready. Type "enter" to begin or "help" for available commands.');let X=["enter","help","more","more help","clear","click","select","hover","inspect"],_=c=>{let p=A.moveTo(c);p?(v=p.id,o&&o(p),y(`Moved to: ${r(p)}`)):y("Could not move to that node.")},ee=c=>B(void 0,null,function*(){let p=c.trim();if(!p)return;ie(p);let m=p.toLowerCase();if(O){let u=parseInt(p,10);if(!isNaN(u)&&u>=1&&u<=O.length){let w=O[u-1];O=null,_(w.nodeId);return}O=null}if(m==="clear"){k.innerHTML="",D('Chat cleared. Type "help" for available commands.');return}if(m==="enter"){if(v){y('Already in the structure. Type "help" to see available commands.');return}let u=A.enter();if(!u){y("Could not enter the structure. No entry point found.");return}v=u.id,o&&o(u),y(`Entered: ${r(u)}`);return}if(m==="help"){let u=f?" You can also type any question about the data.":"",w=[];l&&w.push('"click" or "select"'),d&&w.push('"hover" or "inspect"');let j=w.length?` Interaction: ${w.join(", ")}.`:"";if(!v)y('Not yet in the structure. Type "enter" to begin navigating, or "move to <search>" to jump to a node.'+j+u);else{let ce=e.nodes[v],le=ve(v,ce,e).map(de=>V(de,n));y(`Available: ${le.join(", ")}, move to <search>.`+j+u)}return}if(m==="click"||m==="select"){if(!v){y('Not in the structure. Type "enter" to begin.');return}let u=e.nodes[v];l&&u?(l(u),y(`Clicked: ${r(u)}`)):y(l?"Nothing to click here.":"Click interaction is not enabled for this chart.");return}if(m==="hover"||m==="inspect"){if(!v){y('Not in the structure. Type "enter" to begin.');return}let u=e.nodes[v];d&&u?(d(u),y(`Hovering over: ${r(u)}`)):y(d?"Nothing to hover over here.":"Hover interaction is not enabled for this chart.");return}if(m.startsWith("move to ")){let u=p.slice(8).trim();if(!u){y("Usage: move to <search term>");return}let w=ke(u,e,r);w.length===0?y(`No nodes found matching "${u}".`):w.length===1?_(w[0].nodeId):(O=w,ae(`Found ${w.length} matches. Type a number to move there:`,w.map(j=>j.description)));return}if(m==="more"||m==="more help"){let w=re(e).map(j=>V(j,n));y(`All navigation rules: ${w.join(", ")}.`);return}if(!v){if(f&&(yield Z(p))!==null)return;y('Type "enter" to begin navigating the structure, or "move to <search>" to jump to a node.'+(f?" Enter an API key above to ask questions about the data.":""));return}let N=re(e),{match:E,ambiguous:H}=we(m,[...N,...X],n);if(E&&X.includes(E)){yield ee(E);return}if(!E&&H.length>0){let u=H.map(w=>V(w,n));y(`Did you mean: ${u.join(", ")}?`);return}if(!E){if(f&&(yield Z(p))!==null)return;let u=f?" Enter an API key above to ask questions about the data.":"";y(`Unknown command "${p}". Type "help" for available commands.`+u);return}let T=E,se=n[T]||T;if(T==="exit"){v=null,h&&h(),y('Exited the structure. Type "enter" to re-enter.');return}let K=A.move(v,T);K?(v=K.id,o&&o(K),y(`${se}: ${r(K)}`)):y(`Cannot move "${T}" from here.`)});return I.addEventListener("submit",c=>B(void 0,null,function*(){c.preventDefault();let p=x.value.trim();p&&(L.push(p),C=-1),yield ee(x.value),x.value="",x.focus()})),{destroy(){a.removeChild($)},getCurrentNode(){return v&&e.nodes[v]||null}}};
|
package/dist/text-chat.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import{a as
|
|
1
|
+
import{a as _}from"./chunk-FP25I6TN.js";import"./chunk-MPFBSVCV.js";import{c as q}from"./chunk-RGY6OTGO.js";var ce=e=>{var o,d,u,a,n;if((o=e.semantics)!=null&&o.label){let t=typeof e.semantics.label=="function"?e.semantics.label():e.semantics.label;if(t)return t}if(!e.derivedNode)return e.data?Object.keys(e.data).map(t=>`${t}: ${e.data[t]}`).join(". ")+". Data point.":e.id;if((d=e.data)!=null&&d.dimensionKey){let t=0,v=Object.keys(e.data.divisions||{});v.forEach(p=>{t+=Object.keys(e.data.divisions[p].values||{}).length});let b=`${e.derivedNode}.`;return b+=v.length&&t?` ${v.length} division${v.length>1?"s":""}, ${t} datapoint${t>1?"s":""}.`:" No child data points.",b+=` ${e.data.type} dimension.`,b}return`${e.derivedNode}: ${(u=e.data)==null?void 0:u[e.derivedNode]}. ${Object.keys(((a=e.data)==null?void 0:a.values)||{}).length} child data point${Object.keys(((n=e.data)==null?void 0:n.values)||{}).length>1?"s":""}. Division.`},le=(e,o,d)=>{let u=new Set,a=d.navigationRules||{};return o.edges&&o.edges.forEach(n=>{let t=d.edges[n];t&&t.navigationRules.forEach(v=>{let b=a[v];if(!b)return;let p=b.direction==="target"?t.target:t.source,g=typeof p=="function"?p(o,e):p;g&&g!==e&&u.add(v)})}),Array.from(u)},ee=e=>e.navigationRules?Object.keys(e.navigationRules):[],K=(e,o)=>{let d=e.length,u=o.length,a=Array.from({length:d+1},()=>Array(u+1).fill(0));for(let n=0;n<=d;n++)a[n][0]=n;for(let n=0;n<=u;n++)a[0][n]=n;for(let n=1;n<=d;n++)for(let t=1;t<=u;t++){let v=e[n-1]===o[t-1]?0:1;a[n][t]=Math.min(a[n-1][t]+1,a[n][t-1]+1,a[n-1][t-1]+v),n>1&&t>1&&e[n-1]===o[t-2]&&e[n-2]===o[t-1]&&(a[n][t]=Math.min(a[n][t],a[n-2][t-2]+v))}return a[d][u]},de=e=>e<=4?1:2,ue=(e,o,d={})=>{let u=e.toLowerCase().trim(),a=o.find(l=>l.toLowerCase()===u);if(a)return{match:a,ambiguous:[]};let n=o.find(l=>d[l]&&d[l].toLowerCase()===u);if(n)return{match:n,ambiguous:[]};let t=o.filter(l=>l.toLowerCase().startsWith(u));if(t.length===1)return{match:t[0],ambiguous:[]};let v=o.filter(l=>{if(!d[l])return!1;let x=d[l].toLowerCase();return x.startsWith(u)?!0:x.split(/\s+/).some(T=>T.startsWith(u))}),b=new Set([...t,...v]),p=Array.from(b);if(p.length===1)return{match:p[0],ambiguous:[]};if(p.length>1)return{match:null,ambiguous:p};let g=de(u.length),f=[];for(let l=0;l<o.length;l++){let x=o[l],T=K(u,x.toLowerCase());if(T<=g){f.push({candidate:x,dist:T});continue}if(d[x]){let m=d[x].toLowerCase().split(/\s+/);for(let A=0;A<m.length;A++)if(K(u,m[A])<=g){f.push({candidate:x,dist:K(u,m[A])});break}}}return f.length===1?{match:f[0].candidate,ambiguous:[]}:f.length>1?(f.sort((l,x)=>l.dist-x.dist),f[0].dist<f[1].dist?{match:f[0].candidate,ambiguous:[]}:{match:null,ambiguous:f.map(l=>l.candidate)}):{match:null,ambiguous:[]}},z=(e,o)=>o[e]?`${o[e]} (${e})`:e,he=(e,o,d,u=10)=>{let a=e.toLowerCase(),n=[],t=Object.keys(o.nodes);for(let v=0;v<t.length&&n.length<u;v++){let b=t[v],p=o.nodes[b],g=!1;if(p.data&&!g){let f=Object.keys(p.data);for(let l=0;l<f.length&&!g;l++){let x=p.data[f[l]];x!=null&&typeof x!="object"&&String(x).toLowerCase().includes(a)&&(g=!0)}}!g&&p.derivedNode&&p.derivedNode.toLowerCase().includes(a)&&(g=!0),!g&&b.toLowerCase().includes(a)&&(g=!0),g&&n.push({nodeId:b,description:d(p)})}return n},ge=e=>{var Z;let{structure:o,container:d,entryPoint:u,describeNode:a=ce,commandLabels:n={},onNavigate:t,onExit:v,onClick:b,onHover:p,llm:g,data:f}=e,l=typeof d=="string"?document.getElementById(d):d;if(!l)throw new Error(`textChat: container "${d}" not found`);let x=u||(o.dimensions?(Z=o.dimensions[Object.keys(o.dimensions)[0]])==null?void 0:Z.nodeId:Object.keys(o.nodes)[0]),T=_({structure:o,navigationRules:o.navigationRules||{},entryPoint:x}),m=null,A=Math.random().toString(36).slice(2,8),L=[],E=-1,I=null,M=[],te=()=>{let s=`You are a data assistant helping a user explore a dataset through a text-based navigation interface.
|
|
2
2
|
|
|
3
|
-
`;if(
|
|
3
|
+
`;if(f&&f.length>0){let c=Object.keys(f[0]),i=f.slice(0,3).map(w=>JSON.stringify(w)).join(`
|
|
4
4
|
`);s+=`DATASET SUMMARY:
|
|
5
|
-
- Columns: ${
|
|
6
|
-
- Rows: ${
|
|
5
|
+
- Columns: ${c.join(", ")}
|
|
6
|
+
- Rows: ${f.length}
|
|
7
7
|
- Sample (first 3):
|
|
8
|
-
${
|
|
8
|
+
${i}
|
|
9
9
|
|
|
10
10
|
`,s+=`FULL DATASET (JSON):
|
|
11
|
-
`+JSON.stringify(
|
|
11
|
+
`+JSON.stringify(f)+`
|
|
12
12
|
|
|
13
|
-
`}if(
|
|
13
|
+
`}if(m){let c=o.nodes[m];s+=`CURRENT POSITION: ${c?a(c):m}
|
|
14
14
|
|
|
15
15
|
`}else s+=`CURRENT POSITION: Not yet navigated into the structure.
|
|
16
16
|
|
|
@@ -18,4 +18,4 @@ import{a as X}from"./chunk-FP25I6TN.js";import"./chunk-MPFBSVCV.js";import{c as
|
|
|
18
18
|
|
|
19
19
|
`,s+=`VERIFICATION: When the user asks you to verify a claim, write a short Python script (using the dataset as a JSON array) that computes the answer, and show the expected output. If the claim is too open-ended to verify with code, explain why and recommend external verification.
|
|
20
20
|
|
|
21
|
-
`,s+='IMPORTANT: Your responses may contain errors. The user has been told they can ask you to "verify" any answer, and you will attempt to provide a Python script to check it.',s},
|
|
21
|
+
`,s+='IMPORTANT: Your responses may contain errors. The user has been told they can ask you to "verify" any answer, and you will attempt to provide a Python script to check it.',s},R=document.createElement("div");R.className="dn-text-chat";let C=document.createElement("div");C.className="dn-text-chat-log",C.setAttribute("role","log"),C.setAttribute("aria-live","polite"),R.appendChild(C);let F=document.createElement("div");F.className="dn-text-chat-controls";let W=document.createElement("label"),S=document.createElement("input");S.type="checkbox",S.checked=!0,S.addEventListener("change",()=>{C.setAttribute("aria-live",S.checked?"polite":"off")}),W.appendChild(S),W.appendChild(document.createTextNode(" Automatically announce to screen readers")),F.appendChild(W),R.appendChild(F);let j=document.createElement("form");j.className="dn-text-chat-form";let P=document.createElement("label");P.setAttribute("for",`dn-text-chat-input-${A}`),P.className="dn-text-chat-sr-only",P.textContent="Navigation command";let N=document.createElement("input");N.type="text",N.id=`dn-text-chat-input-${A}`,N.autocomplete="off",N.setAttribute("placeholder","Type a command...");let Y=document.createElement("button");Y.type="submit",Y.textContent="Send",j.appendChild(P),j.appendChild(N),j.appendChild(Y),R.appendChild(j),l.appendChild(R);let B="";N.addEventListener("keydown",s=>{if(s.key==="ArrowUp"){if(s.preventDefault(),L.length===0)return;E===-1?(B=N.value,E=L.length-1):E>0&&E--,N.value=L[E]}else if(s.key==="ArrowDown"){if(s.preventDefault(),E===-1)return;E<L.length-1?(E++,N.value=L[E]):(E=-1,N.value=B)}});let J=(s,c)=>{let i=document.createElement("div");i.className=`dn-text-chat-message ${c}`,i.textContent=s,C.appendChild(i),C.scrollTop=C.scrollHeight},H=s=>J(s,"dn-text-chat-system"),ne=s=>J(`> ${s}`,"dn-text-chat-input-echo"),h=s=>J(s,"dn-text-chat-response"),oe=(s,c)=>{let i=document.createElement("div");i.className="dn-text-chat-message dn-text-chat-response";let w=document.createElement("span");w.textContent=s,i.appendChild(w);let k=document.createElement("ol");k.className="dn-text-chat-choices",c.forEach(D=>{let $=document.createElement("li");$.textContent=D,k.appendChild($)}),i.appendChild(k),C.appendChild(i),C.scrollTop=C.scrollHeight},V=s=>q(void 0,null,function*(){let c={role:"system",content:te()};M.push({role:"user",content:s});let i=document.createElement("div");i.className="dn-text-chat-message dn-text-chat-llm-thinking",i.textContent="Thinking...",C.appendChild(i),C.scrollTop=C.scrollHeight;try{let w=yield g([c,...M]);return C.removeChild(i),w===null?(M.pop(),null):(M.push({role:"assistant",content:w}),h(w),w)}catch(w){return C.removeChild(i),M.pop(),h(`Error: ${w.message||"Could not get a response."}`),""}});g?(H('Text navigation ready. Type "enter" to begin navigating, "help" for commands, or ask a question about the data.'),H('Note: AI-generated answers may be inaccurate. You can ask the model to "verify" any answer \u2014 it will attempt to provide a Python script that checks the claim against the dataset. If a claim cannot be verified with code, it should be verified externally.')):H('Text navigation ready. Type "enter" to begin or "help" for available commands.');let G=["enter","help","more","more help","clear","click","select","hover","inspect"],Q=s=>{let c=T.moveTo(s);c?(m=c.id,t&&t(c),h(`Moved to: ${a(c)}`)):h("Could not move to that node.")},X=s=>q(void 0,null,function*(){let c=s.trim();if(!c)return;ne(c);let i=c.toLowerCase();if(I){let r=parseInt(c,10);if(!isNaN(r)&&r>=1&&r<=I.length){let y=I[r-1];I=null,Q(y.nodeId);return}I=null}if(i==="clear"){C.innerHTML="",H('Chat cleared. Type "help" for available commands.');return}if(i==="enter"){if(m){h('Already in the structure. Type "help" to see available commands.');return}let r=T.enter();if(!r){h("Could not enter the structure. No entry point found.");return}m=r.id,t&&t(r),h(`Entered: ${a(r)}`);return}if(i==="help"){let r=g?" You can also type any question about the data.":"",y=[];b&&y.push('"click" or "select"'),p&&y.push('"hover" or "inspect"');let O=y.length?` Interaction: ${y.join(", ")}.`:"";if(!m)h('Not yet in the structure. Type "enter" to begin navigating, or "move to <search>" to jump to a node.'+O+r);else{let ae=o.nodes[m],re=le(m,ae,o).map(ie=>z(ie,n));h(`Available: ${re.join(", ")}, move to <search>.`+O+r)}return}if(i==="click"||i==="select"){if(!m){h('Not in the structure. Type "enter" to begin.');return}let r=o.nodes[m];b&&r?(b(r),h(`Clicked: ${a(r)}`)):h(b?"Nothing to click here.":"Click interaction is not enabled for this chart.");return}if(i==="hover"||i==="inspect"){if(!m){h('Not in the structure. Type "enter" to begin.');return}let r=o.nodes[m];p&&r?(p(r),h(`Hovering over: ${a(r)}`)):h(p?"Nothing to hover over here.":"Hover interaction is not enabled for this chart.");return}if(i.startsWith("move to ")){let r=c.slice(8).trim();if(!r){h("Usage: move to <search term>");return}let y=he(r,o,a);y.length===0?h(`No nodes found matching "${r}".`):y.length===1?Q(y[0].nodeId):(I=y,oe(`Found ${y.length} matches. Type a number to move there:`,y.map(O=>O.description)));return}if(i==="more"||i==="more help"){let y=ee(o).map(O=>z(O,n));h(`All navigation rules: ${y.join(", ")}.`);return}if(!m){if(g&&(yield V(c))!==null)return;h('Type "enter" to begin navigating the structure, or "move to <search>" to jump to a node.'+(g?" Enter an API key above to ask questions about the data.":""));return}let w=ee(o),{match:k,ambiguous:D}=ue(i,[...w,...G],n);if(k&&G.includes(k)){yield X(k);return}if(!k&&D.length>0){let r=D.map(y=>z(y,n));h(`Did you mean: ${r.join(", ")}?`);return}if(!k){if(g&&(yield V(c))!==null)return;let r=g?" Enter an API key above to ask questions about the data.":"";h(`Unknown command "${c}". Type "help" for available commands.`+r);return}let $=k,se=n[$]||$;if($==="exit"){m=null,v&&v(),h('Exited the structure. Type "enter" to re-enter.');return}let U=T.move(m,$);U?(m=U.id,t&&t(U),h(`${se}: ${a(U)}`)):h(`Cannot move "${$}" from here.`)});return j.addEventListener("submit",s=>q(void 0,null,function*(){s.preventDefault();let c=N.value.trim();c&&(L.push(c),E=-1),yield X(N.value),N.value="",N.focus()})),{destroy(){l.removeChild(R)},getCurrentNode(){return m&&o.nodes[m]||null}}};export{ge as default};
|
package/package.json
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "data-navigator",
|
|
3
3
|
"author": "Frank Elavsky",
|
|
4
|
-
"version": "2.
|
|
4
|
+
"version": "2.4.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
7
7
|
"module": "./dist/index.js",
|
|
8
|
-
"types": "./dist/
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist/**/*",
|
|
11
11
|
"text-chat.css",
|
|
@@ -15,11 +15,11 @@
|
|
|
15
15
|
"exports": {
|
|
16
16
|
".": {
|
|
17
17
|
"import": {
|
|
18
|
-
"types": "./dist/
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
19
|
"default": "./dist/index.js"
|
|
20
20
|
},
|
|
21
21
|
"require": {
|
|
22
|
-
"types": "./dist/
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
23
|
"default": "./dist/index.cjs"
|
|
24
24
|
}
|
|
25
25
|
},
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
"scripts": {
|
|
36
36
|
"clean": "rm -rf ./dist",
|
|
37
37
|
"build": "yarn build:index && yarn build:modules",
|
|
38
|
-
"build:index": "tsup src/index.ts --format cjs,esm",
|
|
38
|
+
"build:index": "tsup src/index.ts --format cjs,esm --dts",
|
|
39
39
|
"build:modules": "tsup src/structure.ts src/input.ts src/rendering.ts src/utilities.ts src/consts.ts src/text-chat.ts --format cjs,esm --minify",
|
|
40
40
|
"prepublishOnly": "cp ../../README.md ../../LICENSE ."
|
|
41
41
|
},
|