@@ -186,7 +186,7 @@ <h4 style="margin: 0 0 10px 0;" data-i18n="uploadedSkills">Uploaded Skills</h4>
186186
187187 // Global version date variable (format: vYear.Month.Day)
188188 const GLOBAL_VERSION_DATE = "v2026.03.26" ;
189- const GLOBAL_VERSION_LAST_MODIFIED = "2026-03-26 21:45:55 " ;
189+ const GLOBAL_VERSION_LAST_MODIFIED = "2026-03-26 22:00:43 " ;
190190
191191 // Set version date
192192 function setVersionDate ( )
@@ -4272,13 +4272,14 @@ <h3 style="color: #4CAF50;">${title}</h3>
42724272 // 全局变量存储操作系统类型,页面加载时初始化一次
42734273 const OPERATING_SYSTEM = detectOperatingSystem ( ) ;
42744274
4275- // AI代码生成服务 - 使用 Pollinations.ai 免费 GET API (无需API Key, CORS友好 )
4276- // text.pollinations.ai GET endpoint: OPTIONS 204, no auth required
4277- // URL pattern: https:// text.pollinations.ai/{prompt}?model={model}&system={system}&seed={seed}
4275+ // AI代码生成服务 - 使用 Pollinations.ai 免费 POST API (无需API Key)
4276+ // POST text.pollinations.ai/openai with Content-Type: text/plain 跳过CORS preflight
4277+ // ( text/plain是"简单"Content-Type,浏览器不会发OPTIONS预检请求)
42784278 const AI_SERVICE_CONFIG = {
4279- baseUrl : "https://text.pollinations.ai" ,
4279+ endpoint : "https://text.pollinations.ai/openai " ,
42804280 model : "openai" ,
4281- maxPromptLength : 7000
4281+ maxTokens : 1500 ,
4282+ temperature : 0.7
42824283 } ;
42834284
42844285 // 加载积木块配置用于AI提示
@@ -4325,19 +4326,37 @@ <h3 style="color: #4CAF50;">${title}</h3>
43254326RULE: ALWAYS use built-in k* skill for named actions. NEVER compose joint movements for actions that have a skill command.` ;
43264327
43274328 const userPrompt = `Generate JavaScript code for: "${ description } "` ;
4328- const fullPrompt = userPrompt ;
4329- const seed = Math . floor ( Math . random ( ) * 1000000 ) ;
43304329
43314330 try {
4332- const url = `${ AI_SERVICE_CONFIG . baseUrl } /${ encodeURIComponent ( fullPrompt ) } ?model=${ encodeURIComponent ( AI_SERVICE_CONFIG . model ) } &system=${ encodeURIComponent ( systemPrompt ) } &seed=${ seed } ` ;
4333-
4334- const response = await fetch ( url ) ;
4331+ const response = await fetch ( AI_SERVICE_CONFIG . endpoint , {
4332+ method : 'POST' ,
4333+ headers : { 'Content-Type' : 'text/plain' } ,
4334+ body : JSON . stringify ( {
4335+ model : AI_SERVICE_CONFIG . model ,
4336+ messages : [
4337+ { role : 'system' , content : systemPrompt } ,
4338+ { role : 'user' , content : userPrompt }
4339+ ] ,
4340+ max_tokens : AI_SERVICE_CONFIG . maxTokens ,
4341+ temperature : AI_SERVICE_CONFIG . temperature ,
4342+ seed : Math . floor ( Math . random ( ) * 1000000 )
4343+ } )
4344+ } ) ;
43354345
43364346 if ( ! response . ok ) {
43374347 throw new Error ( `AI service error: ${ response . status } ${ response . statusText } ` ) ;
43384348 }
43394349
4340- let generatedCode = await response . text ( ) ;
4350+ const data = await response . json ( ) ;
4351+ let generatedCode = '' ;
4352+
4353+ if ( data . choices && data . choices [ 0 ] && data . choices [ 0 ] . message ) {
4354+ generatedCode = data . choices [ 0 ] . message . content ;
4355+ } else if ( data . content ) {
4356+ generatedCode = data . content ;
4357+ } else if ( typeof data === 'string' ) {
4358+ generatedCode = data ;
4359+ }
43414360
43424361 generatedCode = generatedCode
43434362 . replace ( / ` ` ` j a v a s c r i p t \s * / gi, '' )
0 commit comments