miniprogram-development
npx skills add https://github.com/tencentcloudbase/skills --skill miniprogram-development
Agent 安装分布
Skill 文档
When to use this skill
Use this skill for WeChat Mini Program development when you need to:
- Develop WeChat mini program pages and components
- Integrate CloudBase capabilities (database, cloud functions, storage)
- Deploy and preview mini program projects
- Handle mini program authentication and user identity
- Call AI models in mini programs
- Get WeChat step count data
Do NOT use for:
- Web frontend development (use web-development skill)
- Backend service development (use cloudrun-development skill)
- UI design only (use ui-design skill, but may combine with this skill)
How to use this skill (for a coding agent)
-
Follow project structure conventions
- Mini program code in
miniprogramdirectory - Cloud functions in
cloudfunctionsdirectory - Use latest base library version
- Include page configuration files (e.g., index.json) when generating pages
- Mini program code in
-
Understand authentication characteristics
- Important: Mini programs with CloudBase are naturally login-free
- Never generate login pages or login flows
- Get user identity via
cloud.getWXContext().OPENIDin cloud functions
-
Use WeChat Developer Tools correctly
- Check
project.config.jsonhasappidfield before opening - Use CLI command to open project pointing to directory containing
project.config.json
- Check
-
Handle resources properly
- Icons8 (Recommended): Use Icons8 for icon images (e.g., tabbar iconPath)
- URL format:
https://img.icons8.com/{style}/{size}/{color}/{icon-name}.png - Parameters:
style:ios(outline style) orios-filled(filled style)size:100(recommended 100px, file size < 5KB)color: hex color code without # (e.g.,8E8E93for gray,FF3B30for red)icon-name: icon name (e.g.,checked--v1)
- Examples:
- Unselected (gray outline):
https://img.icons8.com/ios/100/8E8E93/checked--v1.png - Selected (red filled):
https://img.icons8.com/ios-filled/100/FF3B30/checked--v1.png
- Unselected (gray outline):
- Advantages:
- â Very small file size (usually < 3KB)
- â Supports custom colors
- â Clean and professional icons
- URL format:
- Use
downloadRemoteFiletool to download resources - Avoid build errors by ensuring all referenced resources exist
- Icons8 (Recommended): Use Icons8 for icon images (e.g., tabbar iconPath)
WeChat Mini Program Development Rules
Project Structure
-
CloudBase Integration:
- If user needs to develop mini program, you will use various WeChat CloudBase capabilities to develop the project
- Mini program base library should use
latestversion
-
Directory Organization:
- Mini program projects follow WeChat CloudBase best practices
- Mini program code is generally in
miniprogramdirectory - If developing cloud functions, they can be stored in
cloudfunctionsdirectory - Mini program’s
project.config.jsonneeds to specifyminiprogramRootand other configurations
-
Page Generation:
- When generating mini program pages, must include page configuration files such as
index.json - Must comply with specifications to avoid compilation errors
- When generating mini program pages, must include page configuration files such as
Development Tools
WeChat Developer Tools Opening Project Workflow:
- When detecting current project is a mini program project, suggest user to use WeChat Developer Tools for preview, debugging, and publishing
- Before opening, confirm
project.config.jsonhasappidfield configured. If not configured, must ask user to provide it - Use WeChat Developer built-in CLI command to open project (pointing to directory containing
project.config.json):- Windows:
"C:\Program Files (x86)\Tencent\微信webå¼åè å·¥å ·\cli.bat" open --project "é¡¹ç®æ ¹ç®å½è·¯å¾" - macOS:
/Applications/wechatwebdevtools.app/Contents/MacOS/cli open --project "/path/to/project/root"
- Windows:
- Project root directory path is the directory containing
project.config.jsonfile
CloudBase Integration
-
Environment Configuration:
- When using
wx.cloudin mini program, need to specify environment ID - Environment ID can be queried via
envQuerytool
- When using
-
Resource Management:
- When generating mini program code, if material images are needed, such as tabbar’s
iconPathand other places, prefer Icons8 (see section 4 above for details) - Use
downloadRemoteFiletool to download resources - When generating mini program code, if using
iconPathand similar, must simultaneously help user download icons to avoid build errors
- When generating mini program code, if material images are needed, such as tabbar’s
Mini Program Authentication Characteristics
Important: Mini programs with CloudBase are naturally login-free. It is strictly forbidden to generate login pages or login flows!
-
Login-Free Feature: Mini program CloudBase does not require user login, can get user identity in cloud functions via wx-server-sdk
-
User Identity Retrieval: In cloud functions, get user’s unique identifier via
cloud.getWXContext().OPENID -
User Data Management: Manage user data in cloud functions based on openid, no login flow needed
// Example of getting user identity in cloud function
exports.main = async (event, context) => {
const wxContext = cloud.getWXContext();
const openid = wxContext.OPENID;
return { openid: openid };
};
AI Model Invocation
Mini programs with base library version 3.7.1+ already support direct AI model invocation
// Create model instance, here we use DeepSeek AI model
const model = wx.cloud.extend.AI.createModel("deepseek");
// First set AI's system prompt, here using seven-character quatrain generation as example
const systemPrompt =
"è¯·ä¸¥æ ¼æç
§ä¸è¨ç»å¥æä¸è¨å¾è¯çæ ¼å¾è¦æ±åä½ï¼å¹³ä»é符åè§åï¼æ¼éµè¦åè°èªç¶ï¼éµèåéå¨åä¸éµé¨ãåä½å
容å´ç»ç¨æ·ç»å®ç主é¢ï¼ä¸è¨ç»å¥å
±åå¥ï¼æ¯å¥ä¸ä¸ªåï¼ä¸è¨å¾è¯å
±å
«å¥ï¼æ¯å¥ä¸ä¸ªåï¼é¢èåé¢èé对ä»å·¥æ´ãåæ¶ï¼è¦èå
¥çå¨çæè±¡ã丰å¯çæ
æä¸ä¼ç¾çæå¢ï¼å±ç°åºå¤è¯è¯çéµå³ä¸ç¾æã";
// User's natural language input, e.g., '帮æåä¸é¦èµç¾çé¾éªå±±çè¯'
const userInput = "帮æåä¸é¦èµç¾çé¾éªå±±çè¯";
// Pass system prompt and user input to AI model
const res = await model.streamText({
data: {
model: "deepseek-v3", // Specify specific model
messages: [
{ role: "system", content: systemPrompt },
{ role: "user", content: userInput },
],
},
});
// Receive AI model's response
// Since AI model's return result is streaming, we need to loop to receive complete response text
for await (let str of res.textStream) {
console.log(str);
}
WeChat Step Count Retrieval
WeChat step count retrieval must use CloudID method (base library 2.7.0+):
- Frontend:
wx.getWeRunData()to get cloudID, usewx.cloud.CloudID(cloudID)to pass to cloud function - Cloud Function: Directly use
weRunData.datato get decrypted step count data, checkweRunData.errCodeto handle errors - Forbidden: Do not use session_key manual decryption method, CloudID is more secure and simple
- Required: Must implement fallback mechanism (simulated data) to handle cloudID retrieval failure cases
Cloud Function Deployment and Permission Notes
- After AI automatically deploys cloud functions, special permissions like cloud invocation may be missing
- Recommend users to right-click cloud function in WeChat Developer Tools, select “Install Dependencies in Cloud”
- For functions requiring cloud invocation permissions (such as WeChat step count decryption), recommend manually deploying once via Developer Tools to get complete permissions
- If encountering permission issues, prompt user to check cloud function’s service authorization and API permission configuration
Development Workflow Guidance
- After completing mini program project development, proactively suggest user to use WeChat Developer Tools for preview, debugging, and publishing
- If user agrees, use CLI command to open WeChat Developer Tools, pointing to project root directory containing
project.config.json - Remind user to perform real device preview, debugging, and publishing operations in WeChat Developer Tools