mirror of
https://github.com/zhayujie/chatgpt-on-wechat.git
synced 2026-07-20 05:27:59 +08:00
feat: key management and scheduled task tools
This commit is contained in:
@@ -70,33 +70,27 @@ def should_include_skill(
|
||||
entry: SkillEntry,
|
||||
config: Optional[Dict] = None,
|
||||
current_platform: Optional[str] = None,
|
||||
lenient: bool = True,
|
||||
) -> bool:
|
||||
"""
|
||||
Determine if a skill should be included based on requirements.
|
||||
|
||||
Similar to clawdbot's shouldIncludeSkill logic, but with lenient mode:
|
||||
- In lenient mode (default): Only check explicit disable and platform, ignore missing requirements
|
||||
- In strict mode: Check all requirements (binary, env vars, config)
|
||||
Simple rule: Skills are auto-enabled if their requirements are met.
|
||||
- Has required API keys → enabled
|
||||
- Missing API keys → disabled
|
||||
- Wrong keys → enabled but will fail at runtime (LLM will handle error)
|
||||
|
||||
:param entry: SkillEntry to check
|
||||
:param config: Configuration dictionary
|
||||
:param config: Configuration dictionary (currently unused, reserved for future)
|
||||
:param current_platform: Current platform (default: auto-detect)
|
||||
:param lenient: If True, ignore missing requirements and load all skills (default: True)
|
||||
:return: True if skill should be included
|
||||
"""
|
||||
metadata = entry.metadata
|
||||
skill_name = entry.skill.name
|
||||
skill_config = get_skill_config(config, skill_name)
|
||||
|
||||
# Always check if skill is explicitly disabled in config
|
||||
if skill_config and skill_config.get('enabled') is False:
|
||||
return False
|
||||
|
||||
# No metadata = always include (no requirements)
|
||||
if not metadata:
|
||||
return True
|
||||
|
||||
# Always check platform requirements (can't work on wrong platform)
|
||||
# Check platform requirements (can't work on wrong platform)
|
||||
if metadata.os:
|
||||
platform_name = current_platform or resolve_runtime_platform()
|
||||
# Map common platform names
|
||||
@@ -114,12 +108,7 @@ def should_include_skill(
|
||||
if metadata.always:
|
||||
return True
|
||||
|
||||
# In lenient mode, skip requirement checks and load all skills
|
||||
# Skills will fail gracefully at runtime if requirements are missing
|
||||
if lenient:
|
||||
return True
|
||||
|
||||
# Strict mode: Check all requirements
|
||||
# Check requirements
|
||||
if metadata.requires:
|
||||
# Check required binaries (all must be present)
|
||||
required_bins = metadata.requires.get('bins', [])
|
||||
@@ -133,29 +122,13 @@ def should_include_skill(
|
||||
if not has_any_binary(any_bins):
|
||||
return False
|
||||
|
||||
# Check environment variables (with config fallback)
|
||||
# Check environment variables (API keys)
|
||||
# Simple rule: All required env vars must be set
|
||||
required_env = metadata.requires.get('env', [])
|
||||
if required_env:
|
||||
for env_name in required_env:
|
||||
# Check in order: 1) env var, 2) skill config env, 3) skill config apiKey (if primaryEnv)
|
||||
if has_env_var(env_name):
|
||||
continue
|
||||
if skill_config:
|
||||
# Check skill config env dict
|
||||
skill_env = skill_config.get('env', {})
|
||||
if isinstance(skill_env, dict) and env_name in skill_env:
|
||||
continue
|
||||
# Check skill config apiKey (if this is the primaryEnv)
|
||||
if metadata.primary_env == env_name and skill_config.get('apiKey'):
|
||||
continue
|
||||
# Requirement not satisfied
|
||||
return False
|
||||
|
||||
# Check config paths
|
||||
required_config = metadata.requires.get('config', [])
|
||||
if required_config and config:
|
||||
for config_path in required_config:
|
||||
if not is_config_path_truthy(config, config_path):
|
||||
if not has_env_var(env_name):
|
||||
# Missing required API key → disable skill
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
Reference in New Issue
Block a user