needware-cli 1.7.5 → 1.7.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "needware-cli",
3
- "version": "1.7.5",
3
+ "version": "1.7.7",
4
4
  "description": "一个功能强大的 Node.js 命令行工具",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -361,14 +361,6 @@ export async function streamChat({
361
361
 
362
362
  if (!resp.ok) {
363
363
  const errorData = await resp.json().catch(() => ({}));
364
- if (resp.status === 429) {
365
- onError(errorData.error || "Request rate too high, please try again later");
366
- return;
367
- }
368
- if (resp.status === 402) {
369
- onError(errorData.error || "Insufficient quota, please recharge to continue");
370
- return;
371
- }
372
364
  onError(errorData.error || "Connection failed, please retry");
373
365
  return;
374
366
  }
@@ -598,47 +590,26 @@ Requirements:
598
590
  let generatedImageUrl: string | null = null;
599
591
  let textContent: string | null = null;
600
592
 
601
-
602
- const messageContent = result.choices?.[0]?.message?.content;
593
+ // 从正确的路径获取图片 URL
594
+ const images = result.choices?.[0]?.message?.images;
595
+ if (images && images.length > 0 && images[0].image_url?.url) {
596
+ generatedImageUrl = images[0].image_url.url;
597
+ }
603
598
 
604
- // 检查是否有图片内容
605
- if (Array.isArray(messageContent)) {
606
- for (const part of messageContent) {
607
- if (part.type === 'image_url' && part.image_url?.url) {
608
- generatedImageUrl = part.image_url.url;
609
- } else if (part.type === 'text') {
610
- textContent = part.text;
611
- }
612
- }
613
- } else if (typeof messageContent === 'string') {
614
- // 检查是否包含 base64 图片或图片 URL
615
- const base64Match = messageContent.match(/data:image\/[^;]+;base64,[A-Za-z0-9+/=]+/);
616
- const urlMatch = messageContent.match(/https?:\/\/[^\s"']+\.(jpg|jpeg|png|gif|webp)/i);
617
-
618
- if (base64Match) {
619
- generatedImageUrl = base64Match[0];
620
- } else if (urlMatch) {
621
- generatedImageUrl = urlMatch[0];
622
- }
599
+ // 获取文本内容
600
+ const messageContent = result.choices?.[0]?.message?.content;
601
+ if (typeof messageContent === 'string') {
623
602
  textContent = messageContent;
624
603
  }
625
604
 
626
- // 包装响应
605
+ // 包装响应 - 返回简洁的格式
627
606
  const virtualTryOnResponse = {
628
- success: response.ok,
629
- data: {
630
- generatedImageUrl,
631
- textContent,
632
- personImageUrl: body.personImageUrl,
633
- garmentImageUrl: body.garmentImageUrl,
634
- model: body.model || 'google/gemini-3-pro-image-preview',
635
- usage: result.usage || null,
636
- },
637
- rawResponse: result,
607
+ resultImage: generatedImageUrl,
608
+ message: generatedImageUrl ? "换装效果生成成功" : "未能生成图片,请重试",
638
609
  };
639
610
 
640
611
  return new Response(JSON.stringify(virtualTryOnResponse), {
641
- status: response.status,
612
+ status: response.ok ? 200 : response.status,
642
613
  headers: {
643
614
  "Content-Type": "application/json",
644
615
  ...corsHeaders
@@ -898,30 +869,6 @@ pnpm add @supabase/supabase-js
898
869
  - ✅ Implement usage monitoring and alerts
899
870
  - ✅ Consider using batch processing to reduce costs
900
871
 
901
- ## Error Handling Checklist
902
-
903
- ```typescript
904
- // Standard error handling pattern
905
- const handleAIError = (error: any, statusCode: number) => {
906
- const errorMap: Record<number, string> = {
907
- 400: "Invalid request parameters",
908
- 401: "Authentication failed",
909
- 402: "Insufficient account balance or quota exhausted",
910
- 403: "No permission to access this API",
911
- 404: "API endpoint does not exist",
912
- 429: "Too many requests, please try again later",
913
- 500: "AI service internal error",
914
- 503: "AI service temporarily unavailable",
915
- };
916
-
917
- return {
918
- error: errorMap[statusCode] || "Unknown error",
919
- statusCode,
920
- originalError: error?.message,
921
- timestamp: new Date().toISOString(),
922
- };
923
- };
924
- ```
925
872
 
926
873
  ## When NOT to Use This Skill
927
874
 
@@ -930,15 +877,3 @@ const handleAIError = (error: any, statusCode: number) => {
930
877
  - Pure data processing logic (no AI inference needed)
931
878
  - Static content display
932
879
  - User is just asking about AI concepts (just provide explanation)
933
-
934
- ## Final Reminders
935
-
936
- **After completing AI integration, must:**
937
- 1. ✅ Test all error scenarios
938
- 2. ✅ Check response format correctness
939
- 3. ✅ Test edge cases (extra-long input, special characters, etc.)
940
- 4. ✅ Confirm smooth user experience
941
- 5. ✅ Add usage documentation and examples
942
-
943
- **Remember: AI integration is not "set it and forget it", requires continuous monitoring and optimization.**
944
-
File without changes