@@ -49,11 +49,18 @@ function parseMetaData(string) {
4949 / ( (?< k1 > (? ! = ) \S + ) = ( (?< v1 > ( [ " ' ` ] ) ( .* ?) \5) | (?< v2 > \S + ) ) ) | (?< k2 > \S + ) / g;
5050 const io = ( string ?? "" ) . matchAll ( regexp ) ;
5151
52- return new Map (
52+ const resultMap = new Map (
5353 [ ...io ]
5454 . map ( ( item ) => item ?. groups )
5555 . map ( ( { k1, k2, v1, v2 } ) => [ k1 ?? k2 , v1 ?? v2 ] )
5656 ) ;
57+
58+ let props = { } ;
59+ for ( let [ key , value ] of resultMap ) {
60+ props [ key ] = value ;
61+ }
62+
63+ return props ;
5764}
5865
5966const MessageMarkdown = observer ( ( props : MessageMarkdownProps ) => {
@@ -63,9 +70,10 @@ const MessageMarkdown = observer((props: MessageMarkdownProps) => {
6370 const tree = fromMarkdown ( children ) ;
6471 const codes = tree . children . filter ( ( node ) => node . type === "code" ) ;
6572 const lastNode = tree . children [ tree . children . length - 1 ] ;
66- const [ chatmarkValues , setChatmarkValues ] = useSetState ( { } ) ;
73+ const [ chatmarkProps , setChatmarkProps ] = useSetState ( { } ) ;
6774 const { classes } = useStyles ( ) ;
6875 const { i18n, t } = useTranslation ( ) ;
76+ const platform = process . env . platform ;
6977
7078 const handleExplain = ( value : string | undefined ) => {
7179 console . log ( value ) ;
@@ -171,24 +179,41 @@ Generate a professionally written and formatted release note in markdown with th
171179 }
172180 } ;
173181
182+ const openLink = ( link ) => {
183+ messageUtil . sendMessage ( {
184+ command : "openLink" ,
185+ url : link ,
186+ } ) ;
187+ } ;
188+
174189 useEffect ( ( ) => {
175190 let previousNode : any = null ;
176191 let chatmarkCount = 0 ;
177192 visit ( tree , function ( node ) {
178193 if ( node . type === "code" ) {
179194 // set meta data as props
180- const metaData = parseMetaData ( node . meta ) ;
181- let props = { ...metaData } ;
195+ let props = { } ;
182196 if ( node . lang === "chatmark" || node . lang === "ChatMark" ) {
183197 props [ "index" ] = chatmarkCount ;
198+ const metaData = parseMetaData ( node . meta ) ;
199+ setChatmarkProps ( {
200+ [ `chatmark-${ chatmarkCount } ` ] : {
201+ ...metaData ,
202+ } ,
203+ } ) ;
184204 } else if (
185205 ( node . lang === "yaml" || node . lang === "YAML" ) &&
186206 previousNode &&
187207 previousNode . type === "code" &&
188208 previousNode . lang === "chatmark"
189209 ) {
190- setChatmarkValues ( {
191- [ `chatmark-${ previousNode . data . hProperties . index } ` ] : node . value ,
210+ setChatmarkProps ( {
211+ [ `chatmark-${ previousNode . data . hProperties . index } ` ] : {
212+ ...chatmarkProps [
213+ `chatmark-${ previousNode . data . hProperties . index } `
214+ ] ,
215+ value : node . value ,
216+ } ,
192217 } ) ;
193218 }
194219 node . data = {
@@ -218,6 +243,13 @@ Generate a professionally written and formatted release note in markdown with th
218243 ) {
219244 return t ( "devchat.setkey" ) ;
220245 }
246+ if (
247+ children . includes (
248+ "OPENAI_API_KEY is missing from your environment or settings"
249+ )
250+ ) {
251+ return t ( "devchat.setOpenAIkey" ) ;
252+ }
221253 }
222254 }
223255 return children ;
@@ -234,8 +266,7 @@ Generate a professionally written and formatted release note in markdown with th
234266 visit ( tree , function ( node ) {
235267 if ( node . type === "code" ) {
236268 // set meta data as props
237- const metaData = parseMetaData ( node . meta ) ;
238- let props = { ...metaData } ;
269+ let props = { } ;
239270 if ( node . lang === "step" || node . lang === "Step" ) {
240271 props [ "index" ] = stepCount ;
241272 } else if ( node . lang === "chatmark" || node . lang === "ChatMark" ) {
@@ -296,9 +327,9 @@ Generate a professionally written and formatted release note in markdown with th
296327 }
297328
298329 if ( lanugage === "chatmark" || lanugage === "ChatMark" ) {
299- const chatmarkValue = chatmarkValues [ `chatmark-${ index } ` ] ;
330+ const chatmarkValue = chatmarkProps [ `chatmark-${ index } ` ] ;
300331 return (
301- < ChatMark value = { chatmarkValue } messageDone = { messageDone } >
332+ < ChatMark messageDone = { messageDone } { ... chatmarkValue } >
302333 { value }
303334 </ ChatMark >
304335 ) ;
@@ -344,15 +375,20 @@ Generate a professionally written and formatted release note in markdown with th
344375 "&:hover" : {
345376 backgroundColor : "#ED6A45" ,
346377 opacity : 0.8 ,
378+ color : "#fff" ,
347379 } ,
348380 "&:focus" : {
349381 backgroundColor : "#ED6A45" ,
350382 opacity : 0.8 ,
383+ color : "#fff" ,
351384 } ,
352385 } }
353386 onClick = { ( ) => {
354- handleButton ( value ) ;
387+ value === "get_devchat_key" && platform === "idea"
388+ ? openLink ( "https://web.devchat.ai" )
389+ : handleButton ( value ) ;
355390 } }
391+ { ...props }
356392 >
357393 { children }
358394 </ Button >
0 commit comments