@@ -683,7 +683,7 @@ var EmbedDialog = function(editorUi, result, timeout, ignoreSize, previewFn, tit
683683 text . style . wordBreak = 'break-all' ;
684684 text . style . marginTop = '10px' ;
685685 text . style . resize = 'none' ;
686- text . style . height = '150px ' ;
686+ text . style . height = '180px ' ;
687687 text . style . width = '440px' ;
688688 text . style . border = '1px solid gray' ;
689689 text . value = mxResources . get ( 'updatingDocument' ) ;
@@ -723,10 +723,8 @@ var EmbedDialog = function(editorUi, result, timeout, ignoreSize, previewFn, tit
723723
724724 var previewBtn = null ;
725725
726- // Loads forever in IE9
727726 if ( EmbedDialog . showPreviewOption && ! mxIsElectron &&
728- ( ! mxClient . IS_CHROMEAPP || validUrl ) && ! navigator . standalone && ( validUrl ||
729- ( mxClient . IS_SVG && ( document . documentMode == null || document . documentMode > 9 ) ) ) )
727+ ! navigator . standalone && validUrl )
730728 {
731729 previewBtn = mxUtils . button ( ( previewTitle != null ) ? previewTitle :
732730 mxResources . get ( ( result . length < maxSize ) ? 'preview' : 'openInNewWindow' ) , function ( )
@@ -796,17 +794,14 @@ var EmbedDialog = function(editorUi, result, timeout, ignoreSize, previewFn, tit
796794 buttons . appendChild ( previewBtn ) ;
797795 }
798796
799- if ( ! validUrl || result . length > 7500 )
797+ var downloadBtn = mxUtils . button ( mxResources . get ( 'export' ) , function ( )
800798 {
801- var downloadBtn = mxUtils . button ( mxResources . get ( mxIsElectron ? 'save' : 'download' ) , function ( )
802- {
803- editorUi . hideDialog ( ) ;
804- editorUi . saveData ( ( filename != null ) ? filename : 'embed.txt' , 'txt' , result , 'text/plain' ) ;
805- } ) ;
806-
807- downloadBtn . className = 'geBtn' ;
808- buttons . appendChild ( downloadBtn ) ;
809- }
799+ editorUi . hideDialog ( ) ;
800+ editorUi . saveData ( ( filename != null ) ? filename : 'embed.txt' , 'txt' , result , 'text/plain' ) ;
801+ } ) ;
802+
803+ downloadBtn . className = 'geBtn' ;
804+ buttons . appendChild ( downloadBtn ) ;
810805
811806 if ( ! editorUi . isOffline ( ) && result . length < maxSize )
812807 {
@@ -8606,7 +8601,8 @@ var ChatWindow = function(editorUi, x, y, w, h)
86068601 var value = Editor . gptModels [ key ] ;
86078602
86088603 if ( ( value . substring ( 0 , 4 ) == 'gpt-' && Editor . gptApiKey != null ) ||
8609- ( value . substring ( 0 , 7 ) == 'gemini-' && Editor . geminiApiKey != null ) )
8604+ ( value . substring ( 0 , 7 ) == 'gemini-' && Editor . geminiApiKey != null ) ||
8605+ ( value . substring ( 0 , 7 ) == 'claude-' && Editor . claudeApiKey != null ) )
86108606 {
86118607 var modelOption = document . createElement ( 'option' ) ;
86128608 modelOption . setAttribute ( 'value' , value ) ;
@@ -8885,31 +8881,38 @@ var ChatWindow = function(editorUi, x, y, w, h)
88858881 'instruction in your response.' ;
88868882 }
88878883
8888- messages . push ( { 'role' : 'system' , 'content' : systemInstruction } ) ;
8889- messages . push ( { 'role' : 'user' , 'content' : thePrompt } ) ;
8890-
8891- var params = ( theModel . substring ( 0 , 7 ) == 'gemini-' ) ?
8884+ messages . push ( { role : ( theModel . substring ( 0 , 4 ) == 'gpt-' ) ?
8885+ 'system' : 'assistant' , content : systemInstruction } ) ;
8886+ messages . push ( { role : 'user' , content : thePrompt } ) ;
8887+
8888+ var params = null ;
8889+
8890+ if ( theModel . substring ( 0 , 7 ) == 'gemini-' )
88928891 {
8893- "system_instruction" : {
8894- "parts" : [
8895- {
8896- "text" : systemInstruction
8897- }
8898- ]
8899- } ,
8900- "contents" : [
8901- {
8902- "parts" : [
8903- {
8904- "text" : thePrompt
8905- }
8906- ]
8907- }
8908- ]
8909- } : {
8910- model : theModel ,
8911- messages : messages
8912- } ;
8892+ params = {
8893+ system_instruction : {
8894+ parts : [ { text : systemInstruction } ]
8895+ } ,
8896+ contents : [ {
8897+ parts : [ { text : thePrompt }
8898+ ] } ]
8899+ } ;
8900+ }
8901+ else if ( theModel . substring ( 0 , 7 ) == 'claude-' )
8902+ {
8903+ params = {
8904+ max_tokens : 8192 ,
8905+ model : theModel ,
8906+ messages : messages
8907+ } ;
8908+ }
8909+ else
8910+ {
8911+ params = {
8912+ model : theModel ,
8913+ messages : messages
8914+ } ;
8915+ }
89138916
89148917 var processMessage = mxUtils . bind ( this , function ( )
89158918 {
@@ -9068,23 +9071,26 @@ var ChatWindow = function(editorUi, x, y, w, h)
90689071 buttons . appendChild ( btn ) ;
90699072 mxEvent . addListener ( btn , 'click' , processMessage ) ;
90709073
9071- btn = btn . cloneNode ( ) ;
9072- btn . setAttribute ( 'src' , Editor . shareImage ) ;
9073- btn . setAttribute ( 'title' , mxResources . get ( ! editorUi . isStandaloneApp ( ) ?
9074- 'openInNewWindow' : 'export' ) ) ;
9075- buttons . appendChild ( btn ) ;
9076-
9077- mxEvent . addListener ( btn , 'click' , mxUtils . bind ( this , function ( evt )
9074+ if ( editorUi . getServiceName ( ) == 'draw.io' )
90789075 {
9079- if ( ! editorUi . isStandaloneApp ( ) )
9080- {
9081- editorUi . editor . editAsNew ( data [ 1 ] ) ;
9082- }
9083- else
9076+ btn = btn . cloneNode ( ) ;
9077+ btn . setAttribute ( 'src' , Editor . shareImage ) ;
9078+ btn . setAttribute ( 'title' , mxResources . get ( ! editorUi . isStandaloneApp ( ) ?
9079+ 'openInNewWindow' : 'export' ) ) ;
9080+ buttons . appendChild ( btn ) ;
9081+
9082+ mxEvent . addListener ( btn , 'click' , mxUtils . bind ( this , function ( evt )
90849083 {
9085- editorUi . saveData ( 'export.xml' , 'xml' , data [ 1 ] , 'text/xml' ) ;
9086- }
9087- } ) ) ;
9084+ if ( ! editorUi . isStandaloneApp ( ) )
9085+ {
9086+ editorUi . editor . editAsNew ( data [ 1 ] ) ;
9087+ }
9088+ else
9089+ {
9090+ editorUi . saveData ( 'export.xml' , 'xml' , data [ 1 ] , 'text/xml' ) ;
9091+ }
9092+ } ) ) ;
9093+ }
90889094
90899095 btn = btn . cloneNode ( ) ;
90909096 btn . setAttribute ( 'src' , Editor . magnifyImage ) ;
@@ -9168,9 +9174,22 @@ var ChatWindow = function(editorUi, x, y, w, h)
91689174 handleError ( e ) ;
91699175 } ) ;
91709176
9171- var url = theModel . substring ( 0 , 7 ) == 'gemini-' ?
9172- 'https://generativelanguage.googleapis.com/v1beta/models/' + theModel +
9173- ':generateContent' : Editor . gptUrl ;
9177+ var url = null ;
9178+
9179+ if ( theModel . substring ( 0 , 7 ) == 'gemini-' )
9180+ {
9181+ url = 'https://generativelanguage.googleapis.com/v1beta/models/' + theModel +
9182+ ':generateContent'
9183+ }
9184+ else if ( theModel . substring ( 0 , 7 ) == 'claude-' )
9185+ {
9186+ url = 'https://api.anthropic.com/v1/messages' ;
9187+ }
9188+ else
9189+ {
9190+ url = Editor . gptUrl ;
9191+ }
9192+
91749193 var req = new mxXmlRequest ( url , JSON . stringify ( params ) , 'POST' ) ;
91759194
91769195 req . setRequestHeaders = mxUtils . bind ( this , function ( request , params )
@@ -9179,6 +9198,12 @@ var ChatWindow = function(editorUi, x, y, w, h)
91799198 {
91809199 request . setRequestHeader ( 'X-goog-api-key' , Editor . geminiApiKey ) ;
91819200 }
9201+ else if ( theModel . substring ( 0 , 7 ) == 'claude-' )
9202+ {
9203+ request . setRequestHeader ( 'x-api-key' , Editor . claudeApiKey ) ;
9204+ request . setRequestHeader ( 'anthropic-version' , '2023-06-01' ) ;
9205+ request . setRequestHeader ( 'anthropic-dangerous-direct-browser-access' , 'true' ) ;
9206+ }
91829207 else
91839208 {
91849209 request . setRequestHeader ( 'Authorization' , 'Bearer ' + Editor . gptApiKey ) ;
@@ -9198,9 +9223,22 @@ var ChatWindow = function(editorUi, x, y, w, h)
91989223 if ( req . getStatus ( ) >= 200 && req . getStatus ( ) <= 299 )
91999224 {
92009225 var response = JSON . parse ( req . getText ( ) ) ;
9201- var text = theModel . substring ( 0 , 7 ) == 'gemini-' ?
9202- mxUtils . trim ( response . candidates [ 0 ] . content . parts [ 0 ] . text ) :
9203- mxUtils . trim ( response . choices [ 0 ] . message . content ) ;
9226+ var text = null ;
9227+
9228+ if ( theModel . substring ( 0 , 7 ) == 'gemini-' )
9229+ {
9230+ text = response . candidates [ 0 ] . content . parts [ 0 ] . text ;
9231+ }
9232+ else if ( theModel . substring ( 0 , 7 ) == 'claude-' )
9233+ {
9234+ text = response . content [ 0 ] . text ;
9235+ }
9236+ else
9237+ {
9238+ text = response . choices [ 0 ] . message . content ;
9239+ }
9240+
9241+ text = mxUtils . trim ( text ) ;
92049242 var mermaid = editorUi . extractMermaidDeclaration ( text ) ;
92059243 EditorUi . debug ( 'EditorUi.ChatWindow.addMessage' ,
92069244 'params' , params , 'response' , response ,
@@ -11726,7 +11764,8 @@ var EditShapeDialog = function(editorUi, cell, title)
1172611764 contentDiv . appendChild ( textarea ) ;
1172711765
1172811766 var previewDiv = document . createElement ( 'div' ) ;
11729- previewDiv . style . border = '1px solid lightgray' ;
11767+ previewDiv . style . borderWidth = '1px' ;
11768+ previewDiv . style . borderStyle = 'solid' ;
1173011769 previewDiv . style . padding = '20px' ;
1173111770 previewDiv . style . flexGrow = '1' ;
1173211771 previewDiv . style . borderRadius = '4px' ;
0 commit comments