draftgo-cli 3.0.1 → 3.0.33

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.
Files changed (68) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +73 -124
  3. package/package.json +21 -8
  4. package/resources/skill/SKILL.md +62 -89
  5. package/resources/skill/init/SKILL.md +18 -67
  6. package/resources/skill/manifest.json +27 -0
  7. package/resources/skill/pull/SKILL.md +18 -44
  8. package/resources/skill/push/SKILL.md +30 -247
  9. package/resources/skill/references/aihub.md +86 -0
  10. package/resources/skill/references/api-endpoints.md +178 -0
  11. package/resources/skill/references/api.json +20248 -0
  12. package/resources/skill/{quickref → references}/app-api.md +44 -14
  13. package/resources/skill/{core → references}/architecture.md +6 -26
  14. package/resources/skill/references/chat-sdk.md +201 -0
  15. package/resources/skill/references/custom-services.md +308 -0
  16. package/resources/skill/references/data.md +298 -0
  17. package/resources/skill/references/db-relations.md +227 -0
  18. package/resources/skill/references/frontend.md +788 -0
  19. package/resources/skill/references/modules.md +66 -0
  20. package/resources/skill/references/parallel.md +48 -0
  21. package/resources/skill/{specs → references}/runtime.md +31 -1
  22. package/resources/skill/{specs → references}/security.md +3 -3
  23. package/resources/skill/references/ui-protocol.md +99 -0
  24. package/resources/skill/scripts/draftgo_delete.py +0 -2
  25. package/resources/skill/scripts/draftgo_init.py +15 -3
  26. package/resources/skill/scripts/draftgo_pull.py +154 -87
  27. package/resources/skill/scripts/draftgo_push.py +440 -183
  28. package/resources/skill/story/SKILL.md +13 -23
  29. package/src/cli.js +22 -7
  30. package/src/commandRegistry.js +34 -0
  31. package/src/commands/api.js +204 -0
  32. package/src/commands/autoPush.js +41 -0
  33. package/src/commands/check.js +27 -17
  34. package/src/commands/delete.js +6 -4
  35. package/src/commands/deploy.js +31 -0
  36. package/src/commands/help.js +41 -28
  37. package/src/commands/init.js +34 -20
  38. package/src/commands/local.js +9 -3
  39. package/src/commands/map.js +18 -7
  40. package/src/commands/sync.js +11 -4
  41. package/src/commands/update.js +39 -52
  42. package/src/commands/verifyUi.js +199 -0
  43. package/src/index.js +13 -46
  44. package/src/localdev/compose.js +48 -197
  45. package/src/localdev/index.js +116 -216
  46. package/src/localdev/mysqlClient.js +12 -9
  47. package/src/localdev/services.js +163 -0
  48. package/src/platforms.js +3 -3
  49. package/src/projectConfig.js +12 -2
  50. package/src/projectMap.js +240 -68
  51. package/src/skill.js +113 -29
  52. package/src/updateCheck.js +37 -15
  53. package/resources/skill/core/modules.md +0 -54
  54. package/resources/skill/practices/anti-patterns.md +0 -70
  55. package/resources/skill/practices/best-practices.md +0 -41
  56. package/resources/skill/practices/dev-declaration.md +0 -94
  57. package/resources/skill/quickref/api-endpoints.md +0 -130
  58. package/resources/skill/quickref/api.json +0 -17675
  59. package/resources/skill/quickref/dg-components.md +0 -198
  60. package/resources/skill/rules/dev-workflow.md +0 -652
  61. package/resources/skill/rules/frontend.md +0 -210
  62. package/resources/skill/rules/parallel.md +0 -263
  63. package/resources/skill/specs/data.md +0 -108
  64. package/resources/skill/specs/ui-protocol.md +0 -68
  65. package/src/commands/doctor.js +0 -54
  66. package/src/commands/new.js +0 -183
  67. package/src/commands/projectScript.js +0 -37
  68. /package/resources/skill/{rules → references}/debugging-syntax.md +0 -0
@@ -0,0 +1,178 @@
1
+ ---
2
+ read_when: 需要查具体 API 端点时 · 构造请求时
3
+ ---
4
+
5
+ # 后端 API 速查
6
+
7
+ > 优先运行 `draftgo api <keyword>` 做结构化查询;需要完整 OpenAPI 时见 [api.json]({{SKILL_SHARED}}/references/api.json)。
8
+ > `draftgo api` 仅索引 DraftGo 底座 API。自定义服务的运行时路由由本地 `app.Route` 动态注册,不会出现在该 OpenAPI 中;按 `<METHOD> /api/x/<slug><route-path>` 推导,推送后必须请求无副作用 GET Route 验证。
9
+ > 统一响应信封:`{ code: 200, data: <载荷>, message: "success" }`
10
+ > GET 列表端点通常在不传 `page` / `page_size` 时全量返回;自定义服务执行记录是固定分页特例(默认 20,最大 100)。
11
+ > Go 自定义服务使用 `draftgo.DB.Query(type, sdk.QueryOptions{...})`;返回 `sdk.QueryResult`,筛选和分页见 `references/custom-services.md`。
12
+
13
+ ## 认证
14
+
15
+ ```
16
+ POST /api/auth/login, /register, /logout, /refresh
17
+ POST /api/auth/forgot-password, /reset-password
18
+ POST /api/auth/wechat/mp/oauth, /wechat/mini/login
19
+ POST /api/auth/wechat/mp/qr/create GET /wechat/mp/qr/poll
20
+ ```
21
+
22
+ ## 用户 & 角色
23
+
24
+ ```
25
+ GET/PUT /api/users/me PUT /api/users/me/password
26
+ GET/POST /api/users GET/PUT/DELETE /api/users/{id}
27
+ POST /api/users/{id}/ban, /unban
28
+
29
+ GET/POST /api/roles GET/PUT/DELETE /api/roles/{id}
30
+ POST /api/roles/{id}/assign/{uid} DELETE /api/roles/{id}/revoke/{uid}
31
+ ```
32
+
33
+ ## 页面
34
+
35
+ ```
36
+ GET/POST /api/pages/
37
+ GET/PUT/DELETE /api/pages/{id}
38
+ POST /api/pages/{id}/reset-system
39
+ GET /api/pages/by-route?route=/xxx
40
+ GET /api/pages/{id}/versions
41
+ POST /api/pages/{page_id}/versions/{version_id}/restore, /star
42
+ ```
43
+
44
+ ## 导航栏
45
+
46
+ ```
47
+ GET/POST /api/navigations
48
+ GET /api/navigations/{code}
49
+ PUT/DELETE /api/navigations/{id}
50
+ ```
51
+
52
+ ## 动态 DB
53
+
54
+ ```
55
+ GET /api/db/{type}
56
+ 支持 filters/order_by/order/page/page_size/populate/scope=mine
57
+ scope=mine 仅 admin 用户的列表 GET 生效:非后台业务页用,后台管理页不用
58
+ 📌 filters 语法 → references/data.md#filters-操作符
59
+ 📌 searchable 模式 → references/data.md#searchable-字段标记
60
+ 📌 ref/populate/onDelete → references/data.md#关联关系ref
61
+ POST /api/db/{type} body: { data: {...} } 或数组
62
+ PATCH /api/db/{type}/batch
63
+ GET/PUT/DELETE /api/db/{type}/{id}
64
+ DELETE 会按真实引用字段的 ref.onDelete 处理级联 / 置空 / 阻止 / 解除关联
65
+ ```
66
+
67
+ ## DB Meta ⚠️
68
+
69
+ ```
70
+ GET/POST /api/db-meta
71
+ GET /api/db-meta/{type} ← 必须用 type,不是 id!
72
+ PUT/DELETE /api/db-meta/{id}
73
+ POST /api/db-meta/{type}/reconcile-fields
74
+ ```
75
+
76
+ ## 自定义服务
77
+
78
+ ```
79
+ GET/POST /api/scripts
80
+ GET /api/scripts/options/roles
81
+ GET/PUT/DELETE /api/scripts/{id}
82
+ GET /api/scripts/{id}/routes
83
+ POST /api/scripts/{id}/enable, /disable, /execute
84
+ GET /api/scripts/{id}/versions
85
+ POST /api/scripts/{id}/versions/{version_id}/restore
86
+ GET /api/scripts/{id}/executions
87
+ GET /api/scripts/{id}/executions/{execution_id}
88
+ ANY /api/x/{slug}/{path} ← 脚本运行时端点
89
+ ```
90
+
91
+ 自定义服务要点:
92
+
93
+ - 本地文件:`.draftgo/custom_scripts/index.json` + 每条记录的 `code_file`。
94
+ - 新服务使用 Go `Register(app *sdk.App)`;用 `app.Route` / `app.On` / `app.Schedule` 自动注册。
95
+ - 新服务使用 `mode=mixed`,可同时暴露 HTTP、响应事件和执行 cron。
96
+ - route 注册来自 `app.Route("METHOD", "/path", handler)`;一个服务可声明多个 route,共用同一个 slug 命名空间。
97
+ - event 和 scheduled 分别来自 `app.On(...)` 与 `app.Schedule(...)`;均支持在一个服务内声明多个 handler。
98
+ - 旧 `triggers` 字段不参与注册,CLI 不再创建或推送该字段。
99
+ - route handler 签名:`func handler(draftgo *sdk.Context) (any, error)`;实际字段位于 `draftgo.Input`,用户身份用 `draftgo.Auth.CurrentUser()`。
100
+ - Route 的普通 SDK 调用继承当前调用者资源权限,管理员创建服务不自动提升;需要管理员权限时逐次显式调用 `draftgo.Admin.DB`、`draftgo.Admin.Users` 等。`Admin` 调用以管理员身份执行并自动写入执行审计,但不会向代码暴露 SAT。带 `user_id` / `actor_user_id` 的事件继承该用户,定时任务及无可解析用户的事件才是系统身份。
101
+ - 路径换算:`slug=order` + `app.Route("POST", "/pay", handler)` → `POST /api/x/order/pay`。
102
+ - route 是精确路径匹配,不支持 `/items/{id}` 参数模板;ID 使用 query/body。
103
+ - 动态数据访问使用 `draftgo.DB.Query("order", sdk.QueryOptions{...})`,结果为 `sdk.QueryResult`;筛选与分页见 `references/custom-services.md`。
104
+ - `permission` 控制调用权限;`config.route_security` 控制限流、IP、body 大小和超时。
105
+ - `scripts:*` 控制服务管理权限,和 Route 的调用权限彼此独立;执行列表固定分页,详情日志按单条加载。
106
+ - `config.max_concurrency` / `queue_timeout_ms` 控制服务级退避;Route 饱和返回 429。
107
+ - 完整 SDK、`draftgo`、AIHub、事件、配置与运行限制见 `references/custom-services.md`。
108
+
109
+ ## AIHub & AI推理
110
+
111
+ ```
112
+ GET/POST /api/aihub ← AIHub 资源(模型/Agent 定义)CRUD
113
+ POST /api/aihub/{id}/sync ← 同步供应商模型目录
114
+ GET /api/v1/models
115
+ POST /api/v1/chat/completions ← OpenAI 兼容格式(直连模型)
116
+ POST /api/v1/embeddings ← 向量嵌入(OpenAI 兼容)
117
+ POST /api/v1/images/generations ← 图片生成(OpenAI 兼容)
118
+ ```
119
+
120
+ Agent 调用面(页面/调用方用 agent id 调用,不是直连模型):
121
+ ```
122
+ GET /api/agents ← 列出当前用户可调用的 Agent(拿 id/name/describe)
123
+ GET /api/agents/{id}/selectable-models ← { user_selectable, models }
124
+ POST /api/agents/{id}/chat ← 对话,见下方 body;stream=true 返回 SSE
125
+ POST /api/agents/{id}/images ← 图片模式 Agent(body.prompt 必填)
126
+ POST /api/agents/{id}/preview-chat ← 只解析不执行:回 { model, fallback_models, candidate_provider_ids, messages },用于调试路由
127
+ ```
128
+
129
+ `/api/agents/{id}/chat` 请求体:
130
+ ```
131
+ { messages:[{role,content}] | message:"简写字符串", stream?:bool,
132
+ model?:"覆盖模型", session_id?:"多轮会话键", context?:{} }
133
+ ```
134
+ - `stream:true` → `text/event-stream`,逐帧 `data: {...}`,以 `data: [DONE]` 结束;否则返回 OpenAI 风格完整结果。
135
+ - 传 `session_id` 且 Agent 开启持续对话(checkpoint)时,服务端加载并续写该会话历史;不传即无状态单轮。
136
+
137
+ AI 运行观测(`/admin/ai-runs` 页数据源):
138
+ ```
139
+ GET /api/aihub/runs ← 运行列表,支持 status/model/trace_id/agent_id/event_type/time_start/time_end + 分页
140
+ GET /api/aihub/runs/{trace_id} ← 单次运行详情(含 spans / tokens / ttft_ms / 延迟)
141
+ DELETE /api/aihub/runs ← 按 trace_ids 或时间范围批量清理
142
+ ```
143
+
144
+ ## 文档中心
145
+
146
+ ```
147
+ GET/POST /api/docs/categories
148
+ GET /api/docs/articles, /api/docs/articles/{key}, /api/docs/search
149
+ POST /api/docs/articles PUT/DELETE /api/docs/articles/{id}
150
+ ```
151
+
152
+ ## 系统 & 备份
153
+
154
+ ```
155
+ GET /api/system/config
156
+ GET/PUT/DELETE /api/system/{key}
157
+ GET/POST /api/system/backup
158
+ POST /api/system/restore, /api/system/reset
159
+ POST /api/system/restore/selective?mode=replace|merge|append
160
+ POST /api/upload
161
+ GET /api/system/logs
162
+ ```
163
+
164
+ ## 二次认证(高危操作前必须)
165
+
166
+ restore / reset / undo / cleanup-orphans 需要:
167
+ ```
168
+ POST /api/auth/reauth { password, scope } → 返回 confirm_token
169
+ 请求头加:X-Confirm-Token: <token>
170
+ ```
171
+
172
+ ## 不使用信封的端点
173
+
174
+ | 端点 | 格式 |
175
+ |---|---|
176
+ | `POST /api/v1/chat/completions` | OpenAI SSE / JSON |
177
+ | `GET /api/v1/models` | `{ object:"list", data:[...] }` |
178
+ | `ANY /api/x/{slug}/{path}` | 脚本自定义 |