needware-cli 1.6.12 → 1.6.15

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.6.12",
3
+ "version": "1.6.15",
4
4
  "description": "一个功能强大的 Node.js 命令行工具",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",
@@ -68,7 +68,6 @@ Trigger Conditions (use if any are met):
68
68
  ### 1. Backend API Pattern (Recommended for Production)
69
69
 
70
70
  **Use Cases:**
71
- - Need to protect API keys
72
71
  - Need rate limiting and usage control
73
72
  - Need data preprocessing or postprocessing
74
73
  - Need caching or logging
@@ -82,7 +81,6 @@ Frontend → Backend API → AI Gateway/Service → AI Provider
82
81
 
83
82
  **Use Cases:**
84
83
  - Prototyping or demos
85
- - Using user's own API keys
86
84
  - Scenarios requiring extremely high real-time performance
87
85
 
88
86
  **Architecture:**
@@ -146,19 +144,12 @@ const handler = async (req: Request): Promise<Response> => {
146
144
  );
147
145
  }
148
146
 
149
- // Get API key from environment variables
150
- const AI_API_KEY = Deno.env.get("AI_API_KEY");
151
- if (!AI_API_KEY) {
152
- throw new Error("AI service not configured");
153
- }
154
-
155
147
  console.log("Processing AI request...");
156
148
 
157
149
  // Call AI Gateway API
158
150
  const response = await fetch("https://ai.gateway.needware.dev/v1/chat/completions", {
159
151
  method: "POST",
160
152
  headers: {
161
- "Authorization": `Bearer ${AI_API_KEY}`,
162
153
  "Content-Type": "application/json",
163
154
  },
164
155
  body: JSON.stringify({
@@ -554,19 +545,12 @@ const handler = async (req: Request): Promise<Response> => {
554
545
  );
555
546
  }
556
547
 
557
- // Get AI API key from environment
558
- const AI_API_KEY = Deno.env.get("AI_API_KEY");
559
- if (!AI_API_KEY) {
560
- throw new Error("AI service not configured");
561
- }
562
-
563
548
  console.log("Generating image with prompt:", prompt);
564
549
 
565
550
  // Call AI Gateway API with image generation model
566
551
  const response = await fetch("https://ai.gateway.needware.dev/v1/chat/completions", {
567
552
  method: "POST",
568
553
  headers: {
569
- "Authorization": `Bearer ${AI_API_KEY}`,
570
554
  "Content-Type": "application/json",
571
555
  },
572
556
  body: JSON.stringify({
@@ -724,19 +708,12 @@ const handler = async (req: Request): Promise<Response> => {
724
708
  );
725
709
  }
726
710
 
727
- // Get AI API key from environment
728
- const AI_API_KEY = Deno.env.get("AI_API_KEY");
729
- if (!AI_API_KEY) {
730
- throw new Error("AI service not configured");
731
- }
732
-
733
711
  console.log("Analyzing image...");
734
712
 
735
713
  // Call AI Gateway API
736
714
  const response = await fetch("https://ai.gateway.needware.dev/v1/chat/completions", {
737
715
  method: "POST",
738
716
  headers: {
739
- "Authorization": `Bearer ${AI_API_KEY}`,
740
717
  "Content-Type": "application/json",
741
718
  },
742
719
  body: JSON.stringify({
@@ -858,76 +835,10 @@ pnpm add @supabase/supabase-js
858
835
  - Function names should clearly express functionality
859
836
  - Each feature gets its own independent function directory
860
837
 
861
- ### Step 6: Configure Environment Variables
862
-
863
- **Configure in Supabase Dashboard:**
864
- 1. Go to Project Settings → Edge Functions → Secrets
865
- 2. Add environment variables:
866
- - `AI_API_KEY`: Your AI service API key
867
- - `AI_MODEL`: (Optional) Default model name
868
- - `AI_MAX_TOKENS`: (Optional) Maximum token count
869
-
870
- **Or use Supabase CLI:**
871
- ```bash
872
- # Set secrets
873
- supabase secrets set AI_API_KEY=your_api_key_here
874
- supabase secrets set AI_MODEL=google/gemini-2.5-flash
875
- supabase secrets set AI_MAX_TOKENS=2000
876
- ```
877
-
878
- **Local Development Environment Variables:**
879
- Create `supabase/.env.local` file (for Supabase Functions):
880
- ```bash
881
- AI_API_KEY=your_api_key_here
882
- AI_MODEL=google/gemini-2.5-flash
883
- AI_MAX_TOKENS=2000
884
- ```
885
-
886
- **Frontend Environment Variables:**
887
- Configure in `.env` or `.env.local` file:
888
- ```bash
889
- VITE_SUPABASE_URL=your_supabase_project_url
890
- VITE_SUPABASE_ANON_KEY=your_supabase_anon_key
891
- ```
892
-
893
- ### Step 7: Testing
894
-
895
- **Test Supabase Function Locally:**
896
- ```bash
897
- # Start local Supabase
898
- supabase start
899
-
900
- # Deploy function locally
901
- supabase functions serve <function-name>
902
-
903
- # Test invocation (text example)
904
- curl -i --location --request POST 'http://localhost:54321/functions/v1/<function-name>' \
905
- --header 'Authorization: Bearer YOUR_ANON_KEY' \
906
- --header 'Content-Type: application/json' \
907
- --data '{"text":"test text","options":{"model":"google/gemini-2.5-flash"}}'
908
-
909
- # Test invocation (image example)
910
- curl -i --location --request POST 'http://localhost:54321/functions/v1/<function-name>' \
911
- --header 'Authorization: Bearer YOUR_ANON_KEY' \
912
- --header 'Content-Type: application/json' \
913
- --data '{"image":"data:image/png;base64,...","prompt":"Please analyze this image"}'
914
- ```
915
-
916
- **Deploy to Production:**
917
- ```bash
918
- # Deploy function
919
- supabase functions deploy <function-name>
920
-
921
- # View logs
922
- supabase functions logs <function-name>
923
- ```
924
-
925
838
 
926
839
  ## Best Practices
927
840
 
928
841
  ### Security
929
- - ✅ **Never** expose API keys in the frontend
930
- - ✅ Use environment variables to store sensitive information
931
842
  - ✅ Implement request rate limiting
932
843
  - ✅ Validate and sanitize user input
933
844
  - ✅ Add request size limits
@@ -946,7 +857,7 @@ supabase functions logs <function-name>
946
857
  const handleAIError = (error: any, statusCode: number) => {
947
858
  const errorMap: Record<number, string> = {
948
859
  400: "Invalid request parameters",
949
- 401: "API key invalid or expired",
860
+ 401: "Authentication failed",
950
861
  402: "Insufficient account balance or quota exhausted",
951
862
  403: "No permission to access this API",
952
863
  404: "API endpoint does not exist",
@@ -976,11 +887,10 @@ const handleAIError = (error: any, statusCode: number) => {
976
887
 
977
888
  **After completing AI integration, must:**
978
889
  1. ✅ Test all error scenarios
979
- 2. ✅ Verify API key configuration
980
- 3. ✅ Check response format correctness
981
- 4. ✅ Test edge cases (extra-long input, special characters, etc.)
982
- 5. ✅ Confirm smooth user experience
983
- 6. ✅ Add usage documentation and examples
890
+ 2. ✅ Check response format correctness
891
+ 3. ✅ Test edge cases (extra-long input, special characters, etc.)
892
+ 4. ✅ Confirm smooth user experience
893
+ 5. ✅ Add usage documentation and examples
984
894
 
985
895
  **Remember: AI integration is not "set it and forget it", requires continuous monitoring and optimization.**
986
896