publisher/SKILL.md
yumoqing 6cbc0475af feat: multi-platform content publisher module for Sage
4 tables: publisher_platform/content/task/log
10 platforms: weibo/douyin/bilibili/kuaishou/wechat/xiaohongshu/toutiao/youtube/twitter
Sage-compliant: DSPY no-import delegation, init.py→ServerEnv, scripts/load_path.py
Content types: article/video/audio/image with per-platform format adapters
2026-08-04 08:16:53 +08:00

60 lines
2.0 KiB
Markdown

---
name: publisher-module
description: Multi-platform content publishing module for Sage — articles, videos, audio to 10+ social platforms
category: devops
---
# Publisher Module
Multi-platform content publishing for Sage. When working with the publisher module, load this skill.
## Architecture
- **Repo**: `/Users/ymq/devops/publisher``git@git.opencomputing.cn:yumoqing/publisher.git`
- **Tables** (4): `publisher_platform`, `publisher_content`, `publisher_task`, `publisher_log`
- **Platforms** (10): weibo, douyin, bilibili, kuaishou, wechat, xiaohongshu, toutiao, youtube, twitter
- **Content types**: article, video, audio, image
## Adding a Platform
Edit `publisher/platforms.py`:
```python
from publisher.platforms import register
def publish_newplat(platform, content):
headers = {'Authorization': 'Bearer ' + platform['access_token']}
body = {'text': content.get('title', '')}
return ('POST', 'https://api.newplat.com/publish', headers, body, content['content_type'])
register('newplat', '新平台', publish_newplat, ['article', 'image', 'video'])
```
## DSPY → Python Delegation
All `.dspy` files follow the pattern:
```python
import json
env = request._run_ns
async with get_sor_context(env, 'sage') as sor:
result = await env.run_scheduled(sor)
return json.dumps(result, ensure_ascii=False)
```
## Deployment Checklist
1. `cp -r publisher $SAGE_ROOT/`
2. `cp json/publisher_*.json $SAGE_ROOT/json/`
3. `cp -r wwwroot/publisher $SAGE_ROOT/wwwroot/`
4. Execute `ddl/mysql.sql`
5. Run `scripts/load_path.py`
6. Add `from publisher.init import load_publisher` + `load_publisher()` in sage.py
7. Restart Sage
## Pitfalls
- Platform APIs require real credentials — access_token expires, need refresh flow
- Content format differs per platform (Weibo max 2000 chars, WeChat title max 64 chars)
- Network errors auto-retry 3 times before marking failed
- `sor` parameter allows DSPY context reuse — don't open extra DB connections when sor is provided