@spteck/react-controls-v2 2.0.9 → 2.0.10
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AIAssistant.d.ts","sourceRoot":"","sources":["../../../src/components/aiAssistant/AIAssistant.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAmBxD,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,
|
|
1
|
+
{"version":3,"file":"AIAssistant.d.ts","sourceRoot":"","sources":["../../../src/components/aiAssistant/AIAssistant.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAmBxD,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAmOnD,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useStreamRequest.d.ts","sourceRoot":"","sources":["../../../src/components/aiAssistant/useStreamRequest.ts"],"names":[],"mappings":"AAEA,UAAU,mBAAmB;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,WAAW,EAAE,CACX,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,GAAG,EACZ,OAAO,CAAC,EAAE,WAAW,EACrB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,KAC9B,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED,wBAAgB,gBAAgB,IAAI,mBAAmB,
|
|
1
|
+
{"version":3,"file":"useStreamRequest.d.ts","sourceRoot":"","sources":["../../../src/components/aiAssistant/useStreamRequest.ts"],"names":[],"mappings":"AAEA,UAAU,mBAAmB;IAC3B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,WAAW,EAAE,CACX,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,GAAG,EACZ,OAAO,CAAC,EAAE,WAAW,EACrB,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,KAC9B,OAAO,CAAC,IAAI,CAAC,CAAC;IACnB,aAAa,EAAE,MAAM,IAAI,CAAC;CAC3B;AAED,wBAAgB,gBAAgB,IAAI,mBAAmB,CAwHtD"}
|
package/dist/index.js
CHANGED
|
@@ -133,7 +133,7 @@ var s=function(){function e(){}return e.generate=function(){var t=4294967295*Mat
|
|
|
133
133
|
`,bottomText:g.css`
|
|
134
134
|
padding-left: 8px;
|
|
135
135
|
padding-right: 8px;
|
|
136
|
-
`,zoomContainer:g.css({display:"flex",flexDirection:"row",alignItems:"center",gap:"6px",width:"100%",boxSizing:"border-box",padding:"8px 0px"})},[s,l]=L.useState(n),[u,d]=L.useState(null),[h,m]=L.useState(!1);L.useEffect(()=>{l(n)},[n]);const f=(e,n)=>{const r={spanCols:n+1,spanRows:e+1};l(r),null==t||t(r),m(!1)},y=(e,t)=>{d({spanCols:t+1,spanRows:e+1})},b=L.useMemo(()=>30*r+4*(r-1)+32,[r]);return c.jsxs(p.Menu,{open:h,onOpenChange:(e,t)=>{m(t.open),d(null)},children:[c.jsx(p.MenuTrigger,{disableButtonEnhancement:!0,children:c.jsx(p.Tooltip,{content:"Configure",relationship:"label",children:c.jsx(p.MenuButton,{icon:c.jsx(i,{}),size:"small",appearance:"transparent"})})}),c.jsxs(p.MenuPopover,{style:{width:`${b}px`,minWidth:"120px",padding:8},children:[c.jsx("div",{className:a.zoomContainer,children:c.jsx(bt,{label:`Span (${s.spanCols} × ${s.spanRows})`})}),c.jsx("div",{className:a.gridContainer,style:{gridTemplateColumns:`repeat(${r}, 30px)`,gridTemplateRows:`repeat(${o}, 30px)`},onMouseLeave:()=>{d(null)},children:(()=>{const e=[];for(let t=0;t<o;t++)for(let n=0;n<r;n++){const r=t<s.spanRows&&n<s.spanCols,o=u&&t<u.spanRows&&n<u.spanCols;e.push(c.jsx("div",{className:`${a.cell} ${o?a.hoveredCell:""} ${r?a.selectedCell:""}`,onMouseEnter:()=>y(t,n),onClick:()=>f(t,n)},`${t}-${n}`))}return e})()}),c.jsx(p.Caption1,{className:a.bottomText,children:"Click to set span"})]})]})};exports.ErrorType=l.ErrorType,exports.LogLevel=l.LogLevel,exports.AIAssistant=e=>{const{instrutions:t,timezone:n,locale:r,onResponse:o,openAIConfig:i,theme:a,placeholder:s,context:l}=e,[d,h]=L.useReducer(uc,{messages:[],inputText:"",isLoading:!0,error:void 0,isRunning:!1}),{messages:m,inputText:f,isLoading:y,error:v,isRunning:b}=d,C=L.useRef([]),w={container:g.css({display:"flex",flexDirection:"column",padding:"10px",width:"100%",height:"600px",borderRadius:"8px",boxShadow:"0 2px 10px rgba(0, 0, 0, 0.1)",overflowY:"auto",overflowX:"hidden",position:"relative",zIndex:1e3}),chatList:g.css({display:"flex",flexDirection:"column",gap:"10px",padding:"10px",overflowY:"auto",overflowX:"hidden",height:"100%",width:"100%","::-webkit-scrollbar":{width:"5px",height:"5px"},"::-webkit-scrollbar-track":{background:p.tokens.colorNeutralBackground4,borderRadius:"10px"},"::-webkit-scrollbar-thumb":{background:p.tokens.colorBrandStroke2Hover,borderRadius:"10px"},"::-webkit-scrollbar-thumb:hover":{background:p.tokens.colorNeutralStroke2}}),chatAIAssistantRoot:g.css({padding:"10px",display:"flex",flexDirection:"column",position:"relative",height:"calc(100% - 20px)"}),inputContainer:g.css({display:"flex",flexDirection:"row",flex:1,marginTop:"10px",gap:"10px",alignItems:"center"}),input:g.css({width:"100%",fontSize:"14px"})},S=L.useRef(null),{sendRequest:k,cancelRequest:P,error:E}=function(){const[e,t]=u.useState(""),[n,r]=u.useState(!1),[o,i]=u.useState(null),a=u.useRef(null);return{data:e,isLoading:n,error:o,sendRequest:u.useCallback(async(e,n,o,s)=>{var l;t(""),i(null),r(!0);const c=new AbortController;a.current=c;try{const r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n),signal:c.signal,...o});if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);const i=null==(l=r.body)?void 0:l.getReader();if(!i)throw new Error("No response body");const a=new TextDecoder("utf-8");let
|
|
136
|
+
`,zoomContainer:g.css({display:"flex",flexDirection:"row",alignItems:"center",gap:"6px",width:"100%",boxSizing:"border-box",padding:"8px 0px"})},[s,l]=L.useState(n),[u,d]=L.useState(null),[h,m]=L.useState(!1);L.useEffect(()=>{l(n)},[n]);const f=(e,n)=>{const r={spanCols:n+1,spanRows:e+1};l(r),null==t||t(r),m(!1)},y=(e,t)=>{d({spanCols:t+1,spanRows:e+1})},b=L.useMemo(()=>30*r+4*(r-1)+32,[r]);return c.jsxs(p.Menu,{open:h,onOpenChange:(e,t)=>{m(t.open),d(null)},children:[c.jsx(p.MenuTrigger,{disableButtonEnhancement:!0,children:c.jsx(p.Tooltip,{content:"Configure",relationship:"label",children:c.jsx(p.MenuButton,{icon:c.jsx(i,{}),size:"small",appearance:"transparent"})})}),c.jsxs(p.MenuPopover,{style:{width:`${b}px`,minWidth:"120px",padding:8},children:[c.jsx("div",{className:a.zoomContainer,children:c.jsx(bt,{label:`Span (${s.spanCols} × ${s.spanRows})`})}),c.jsx("div",{className:a.gridContainer,style:{gridTemplateColumns:`repeat(${r}, 30px)`,gridTemplateRows:`repeat(${o}, 30px)`},onMouseLeave:()=>{d(null)},children:(()=>{const e=[];for(let t=0;t<o;t++)for(let n=0;n<r;n++){const r=t<s.spanRows&&n<s.spanCols,o=u&&t<u.spanRows&&n<u.spanCols;e.push(c.jsx("div",{className:`${a.cell} ${o?a.hoveredCell:""} ${r?a.selectedCell:""}`,onMouseEnter:()=>y(t,n),onClick:()=>f(t,n)},`${t}-${n}`))}return e})()}),c.jsx(p.Caption1,{className:a.bottomText,children:"Click to set span"})]})]})};exports.ErrorType=l.ErrorType,exports.LogLevel=l.LogLevel,exports.AIAssistant=e=>{const{instrutions:t,timezone:n,locale:r,onResponse:o,openAIConfig:i,theme:a,placeholder:s,context:l}=e,[d,h]=L.useReducer(uc,{messages:[],inputText:"",isLoading:!0,error:void 0,isRunning:!1}),{messages:m,inputText:f,isLoading:y,error:v,isRunning:b}=d,C=L.useRef([]),w={container:g.css({display:"flex",flexDirection:"column",padding:"10px",width:"100%",height:"600px",borderRadius:"8px",boxShadow:"0 2px 10px rgba(0, 0, 0, 0.1)",overflowY:"auto",overflowX:"hidden",position:"relative",zIndex:1e3}),chatList:g.css({display:"flex",flexDirection:"column",gap:"10px",padding:"10px",overflowY:"auto",overflowX:"hidden",height:"100%",width:"100%","::-webkit-scrollbar":{width:"5px",height:"5px"},"::-webkit-scrollbar-track":{background:p.tokens.colorNeutralBackground4,borderRadius:"10px"},"::-webkit-scrollbar-thumb":{background:p.tokens.colorBrandStroke2Hover,borderRadius:"10px"},"::-webkit-scrollbar-thumb:hover":{background:p.tokens.colorNeutralStroke2}}),chatAIAssistantRoot:g.css({padding:"10px",display:"flex",flexDirection:"column",position:"relative",height:"calc(100% - 20px)"}),inputContainer:g.css({display:"flex",flexDirection:"row",flex:1,marginTop:"10px",gap:"10px",alignItems:"center"}),input:g.css({width:"100%",fontSize:"14px"})},S=L.useRef(null),{sendRequest:k,cancelRequest:P,error:E}=function(){const[e,t]=u.useState(""),[n,r]=u.useState(!1),[o,i]=u.useState(null),a=u.useRef(null);return{data:e,isLoading:n,error:o,sendRequest:u.useCallback(async(e,n,o,s)=>{var l;t(""),i(null),r(!0);const c=new AbortController;a.current=c;try{const r=await fetch(e,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n),signal:c.signal,...o});if(!r.ok)throw new Error(`HTTP error! status: ${r.status}`);const i=null==(l=r.body)?void 0:l.getReader();if(!i)throw new Error("No response body");const a=new TextDecoder("utf-8");let d=!1,p="",h="";for(;!d;){const{value:e,done:n}=await i.read();if(d=n,e){const n=a.decode(e,{stream:!0});h+=n;const r=h.split("\n");h=r.pop()||"";let o="",i="";for(const e of r)if(e.startsWith("event:"))o=e.substring(6).trim();else if(e.startsWith("data:"))i=e.substring(5).trim();else if(""===e){if("error"===o)try{const e=JSON.parse(i).message||"An error occurred";throw e.includes("429")||e.toLowerCase().includes("rate limit")?new Error("Rate limit exceeded. Please wait a moment and try again."):e.includes("quota")?new Error("API quota exceeded. Please try again later."):new Error(e)}catch(u){if(u instanceof Error&&u.message.includes("Rate limit"))throw u;throw new Error(i||"An error occurred during streaming")}o="",i=""}p+=n,t(p),s&&s(n)}}}catch(d){throw d instanceof Error&&"AbortError"===d.name?(i("Request aborted"),d):(i(d instanceof Error?d.message:"Error occurred"),d)}finally{r(!1)}},[]),cancelRequest:u.useCallback(()=>{a.current&&a.current.abort()},[])}}(),A=L.useCallback(()=>{S.current&&(S.current.scrollTop=S.current.scrollHeight-S.current.clientHeight)},[]);L.useEffect(()=>{var e,t;const r={message:"Welcome to AI Assistant! How can I help you today?",senderName:"Assistant",timeStamp:dc(n,(null==(t=null==(e=null==l?void 0:l.pageContext)?void 0:e.cultureInfo)?void 0:t.currentUICultureName)||"en-US"),status:"received"};h({type:"INIT",welcomeMessage:r})},[]);const I=L.useCallback(async()=>{var e,a,s,u;if(!f.trim())return;const d={message:f,senderName:"User",timeStamp:dc(n,(null==(a=null==(e=null==l?void 0:l.pageContext)?void 0:e.cultureInfo)?void 0:a.currentUICultureName)||"en-US"),status:"received"},p=f;h({type:"ADD_USER_MESSAGE",message:d}),h({type:"CLEAR_INPUT"}),h({type:"SET_IS_RUNNING"});const m={message:c.jsx(cc,{}),senderName:"Assistant",timeStamp:dc(n,(null==(u=null==(s=null==l?void 0:l.pageContext)?void 0:s.cultureInfo)?void 0:u.currentUICultureName)||"en-US"),status:"sending"};h({type:"ADD_ASSISTANT_MESSAGE",message:m}),A();let g="";const y=(null==i?void 0:i.endpoint)||"http://localhost:7071/api/EventAssistant",v={instructions:t,input:p,timezone:n,locale:r,history:C.current,mcpServers:null==i?void 0:i.mcpServers};try{await k(y,v,void 0,e=>{g+=e,null==o||o(g).then(e=>{const{message:t,status:n}=e;h({type:"UPDATE_LAST_ASSISTANT_MESSAGE",message:{...m,message:t||g,status:n||"received"}}),h({type:"SET_IS_RUNNING"})})})}catch(b){console.error("Error during streaming:",b);let e="Error occurred while processing your request.";b instanceof Error&&(e=b.message.includes("Rate limit")||b.message.includes("429")?"⚠️ Rate limit exceeded. Please wait a moment before sending another message.":b.message.includes("quota")?"⚠️ API quota exceeded. Please try again later.":b.message.includes("abort")?"Request was cancelled.":b.message),h({type:"UPDATE_LAST_ASSISTANT_MESSAGE",message:{...m,message:e,status:"failed"}}),h({type:"SET_IS_RUNNING"})}C.current.push(p),C.current.push(g),A()},[f,t,r,o,i,n,k,E]),_=L.useCallback(e=>{h({type:"SET_INPUT",inputText:e})},[]);return y?c.jsx(p.Spinner,{size:"medium"}):v?c.jsx(En,{message:"There was an error processing your request.",messageType:U.INFO}):c.jsxs("div",{id:"aiAssistant",className:w.chatAIAssistantRoot,children:[c.jsx(V.Chat,{className:w.chatList,ref:S,children:m.map((e,t)=>"User"===e.senderName?c.jsx(V.ChatMyMessage,{status:e.status,author:e.senderName,timestamp:e.timeStamp,children:e.message},t):c.jsx(V.ChatMessage,{decoration:"failed"===e.status?"important":void 0,avatar:c.jsx(x.Icon,{icon:"carbon:ibm-consulting-advantage-assistant",width:"32",height:"32",style:{color:p.tokens.colorBrandBackground}}),author:e.senderName,timestamp:e.timeStamp,children:e.message},t))}),c.jsx("div",{className:w.inputContainer,children:c.jsx(lc,{context:l,value:f,onChange:_,placeholder:s,onSend:I,onAbort:P,theme:a,isRunning:b})})]})},exports.AISearchControl=({systemPromptTemplate:e,azureOpenAIConfig:t,placeholder:n="Ask AI to generate search query... (e.g., 'Find engineers in the Seattle office')",onSearchQueryGenerated:r,onSearchStart:o,onSearchError:i,disabled:a=!1,className:s,width:l})=>{const{error:c}=q(),{generateText:d,isConfigured:h}={generateText:async(e,t)=>(console.warn("useAzureOpenAI not implemented - add your Azure OpenAI implementation",{prompt:e,userInput:t}),"Azure OpenAI not configured - please provide configuration"),isConfigured:!1},[m,f]=u.useState(!1),[g,y]=u.useState(""),v=u.useRef(null),{searchBoxStyles:b,iconWrapperStyles:x}={searchBoxStyles:Xl`
|
|
137
137
|
border: 1px solid ${p.tokens.colorNeutralStroke2};
|
|
138
138
|
border-radius: 50px; /* Fully circular/pill shape */
|
|
139
139
|
background-color: ${p.tokens.colorNeutralBackground1};
|