draftgo-cli 3.0.56 → 4.0.22
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/README.md +169 -297
- package/package.json +12 -7
- package/resources/custom-service-sdk/ai.go +520 -0
- package/resources/custom-service-sdk/ai_test.go +156 -0
- package/resources/custom-service-sdk/billing.go +596 -0
- package/resources/custom-service-sdk/billing_test.go +150 -0
- package/resources/custom-service-sdk/go.mod +3 -0
- package/resources/custom-service-sdk/manifest.json +72 -0
- package/resources/custom-service-sdk/platform.go +360 -0
- package/resources/custom-service-sdk/platform_logger_test.go +24 -0
- package/resources/custom-service-sdk/registration_test.go +39 -0
- package/resources/custom-service-sdk/resources.go +246 -0
- package/resources/custom-service-sdk/resources_billing_test.go +115 -0
- package/resources/custom-service-sdk/resources_files_test.go +57 -0
- package/resources/custom-service-sdk/resources_scope_test.go +87 -0
- package/resources/custom-service-sdk/sdk.go +208 -0
- package/resources/skill/SKILL.md +36 -87
- package/resources/skill/init/SKILL.md +9 -14
- package/resources/skill/manifest.json +6 -2
- package/resources/skill/references/aihub.md +28 -5
- package/resources/skill/references/app-api.md +56 -6
- package/resources/skill/references/architecture.md +2 -2
- package/resources/skill/references/chat-sdk.md +4 -2
- package/resources/skill/references/checkout.md +21 -7
- package/resources/skill/references/custom-services.md +124 -222
- package/resources/skill/references/data.md +22 -6
- package/resources/skill/references/delivery.md +33 -0
- package/resources/skill/references/diagnostics.md +51 -0
- package/resources/skill/references/frontend.md +93 -499
- package/resources/skill/references/mcp.md +65 -101
- package/resources/skill/references/methods.md +189 -0
- package/resources/skill/references/modules.md +36 -8
- package/resources/skill/references/runtime.md +26 -3
- package/resources/skill/story/SKILL.md +1 -2
- package/src/apiContractCache.js +112 -0
- package/src/cli.js +24 -20
- package/src/commandRegistry.js +15 -12
- package/src/commands/api.js +41 -10
- package/src/commands/apiKey.js +34 -0
- package/src/commands/capabilities.js +93 -0
- package/src/commands/check.js +1 -10
- package/src/commands/checkout.js +1 -1
- package/src/commands/commit.js +1 -1
- package/src/commands/components.js +550 -0
- package/src/commands/conflict.js +1 -1
- package/src/commands/connect.js +18 -8
- package/src/commands/customService.js +22 -8
- package/src/commands/dataRange.js +33 -0
- package/src/commands/delete.js +34 -46
- package/src/commands/deploy.js +1 -1
- package/src/commands/diff.js +18 -2
- package/src/commands/grant.js +29 -0
- package/src/commands/group.js +38 -0
- package/src/commands/help.js +80 -51
- package/src/commands/init.js +6 -12
- package/src/commands/listTargets.js +1 -1
- package/src/commands/local.js +2 -6
- package/src/commands/map.js +145 -28
- package/src/commands/mcp.js +2 -2
- package/src/commands/reconcile.js +1 -1
- package/src/commands/role.js +32 -0
- package/src/commands/space.js +41 -0
- package/src/commands/status.js +111 -8
- package/src/commands/uninstall.js +3 -3
- package/src/commands/update.js +24 -12
- package/src/commands/verify.js +118 -21
- package/src/commands/{verifyUi.js → visualVerify.js} +28 -116
- package/src/commands/worklog.js +90 -0
- package/src/consoleEncoding.js +34 -0
- package/src/contractCompatibility.js +57 -0
- package/src/customServices.js +278 -41
- package/src/diffReport.js +106 -0
- package/src/index.js +2 -0
- package/src/{localdev → localRuntime}/compose.js +14 -17
- package/src/{localdev → localRuntime}/detect.js +1 -1
- package/src/{localdev → localRuntime}/index.js +22 -23
- package/src/{localdev → localRuntime}/mysqlClient.js +1 -1
- package/src/{localdev → localRuntime}/services.js +28 -37
- package/src/mcp/client.js +11 -2
- package/src/mcp/protocol.js +2 -2
- package/src/mcp/tools.js +14 -1
- package/src/platforms.js +9 -0
- package/src/projectConfig.js +8 -4
- package/src/releaseInstall.js +105 -0
- package/src/{installers/index.js → targets.js} +3 -5
- package/src/updateCheck.js +48 -28
- package/src/worklog.js +275 -0
- package/src/workspaceHealth.js +1 -1
- package/src/worktree/backend.js +1 -1
- package/src/worktree/index.js +86 -51
- package/src/changelog.js +0 -276
- package/src/commands/changelog.js +0 -24
- package/src/commands/localDev.js +0 -9
- package/src/commands/sync.js +0 -46
- package/src/commands/task.js +0 -408
- package/src/commands/verifyUiCompat.js +0 -16
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
// Package sdk is the public contract for DraftGo Go custom services.
|
|
2
|
+
//
|
|
3
|
+
// A service implements Register and calls App.Route, App.On and App.Schedule.
|
|
4
|
+
// The isolated script runner invokes Register once at publish time to discover
|
|
5
|
+
// handlers, then invokes the selected Handler for each execution.
|
|
6
|
+
package sdk
|
|
7
|
+
|
|
8
|
+
import (
|
|
9
|
+
"context"
|
|
10
|
+
"fmt"
|
|
11
|
+
"net/http"
|
|
12
|
+
"strings"
|
|
13
|
+
"sync"
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
// Handler is a user supplied custom-service function.
|
|
17
|
+
type Handler func(*Context) (any, error)
|
|
18
|
+
|
|
19
|
+
// Registration is an immutable description of one platform trigger.
|
|
20
|
+
type Registration struct {
|
|
21
|
+
Kind string `json:"kind"`
|
|
22
|
+
Method string `json:"method,omitempty"`
|
|
23
|
+
Path string `json:"path,omitempty"`
|
|
24
|
+
Event string `json:"event,omitempty"`
|
|
25
|
+
Cron string `json:"cron,omitempty"`
|
|
26
|
+
Name string `json:"name,omitempty"`
|
|
27
|
+
Handler Handler `json:"-"`
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// App is supplied to Register. It is safe to inspect registrations after
|
|
31
|
+
// Register returns; registration itself is intentionally limited to startup.
|
|
32
|
+
type App struct {
|
|
33
|
+
mu sync.RWMutex
|
|
34
|
+
registrations []Registration
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// NewApp creates the registration collector used by a script runner.
|
|
38
|
+
func NewApp() *App { return &App{} }
|
|
39
|
+
|
|
40
|
+
// Route registers an HTTP endpoint. Path is relative to the custom-service
|
|
41
|
+
// mount point and must start with '/'.
|
|
42
|
+
func (app *App) Route(method, path string, handler Handler) {
|
|
43
|
+
method, path = strings.ToUpper(strings.TrimSpace(method)), strings.TrimSpace(path)
|
|
44
|
+
if method == "" || path == "" || !strings.HasPrefix(path, "/") || handler == nil {
|
|
45
|
+
panic("sdk.Route requires method, absolute path and handler")
|
|
46
|
+
}
|
|
47
|
+
trimmed := strings.Trim(path, "/")
|
|
48
|
+
if trimmed == "" {
|
|
49
|
+
path = "/"
|
|
50
|
+
} else {
|
|
51
|
+
path = "/" + trimmed
|
|
52
|
+
}
|
|
53
|
+
app.add(Registration{Kind: "route", Method: method, Path: path, Handler: handler})
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// On registers a named DraftGo event handler.
|
|
57
|
+
func (app *App) On(event string, handler Handler) {
|
|
58
|
+
event = strings.TrimSpace(event)
|
|
59
|
+
if event == "" || handler == nil {
|
|
60
|
+
panic("sdk.On requires event and handler")
|
|
61
|
+
}
|
|
62
|
+
app.add(Registration{Kind: "event", Event: event, Handler: handler})
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// Schedule registers a five-field cron expression or a DraftGo interval
|
|
66
|
+
// expression (for example "interval:5m").
|
|
67
|
+
func (app *App) Schedule(cron string, handler Handler) {
|
|
68
|
+
cron = strings.TrimSpace(cron)
|
|
69
|
+
if cron == "" || handler == nil {
|
|
70
|
+
panic("sdk.Schedule requires cron and handler")
|
|
71
|
+
}
|
|
72
|
+
app.add(Registration{Kind: "scheduled", Cron: cron, Handler: handler})
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
func (app *App) add(registration Registration) {
|
|
76
|
+
app.mu.Lock()
|
|
77
|
+
defer app.mu.Unlock()
|
|
78
|
+
for _, existing := range app.registrations {
|
|
79
|
+
if registration.Kind == "route" && existing.Kind == "route" && existing.Method == registration.Method && existing.Path == registration.Path {
|
|
80
|
+
panic(fmt.Sprintf("duplicate route %s %s", registration.Method, registration.Path))
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Function names are not a stable Go runtime API. A deterministic ID based
|
|
84
|
+
// on registration order is therefore persisted in the published manifest.
|
|
85
|
+
registration.Name = fmt.Sprintf("%s-%d", registration.Kind, len(app.registrations)+1)
|
|
86
|
+
app.registrations = append(app.registrations, registration)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// Registrations returns a copy, so callers cannot mutate the published
|
|
90
|
+
// registration set.
|
|
91
|
+
func (app *App) Registrations() []Registration {
|
|
92
|
+
app.mu.RLock()
|
|
93
|
+
defer app.mu.RUnlock()
|
|
94
|
+
result := make([]Registration, len(app.registrations))
|
|
95
|
+
copy(result, app.registrations)
|
|
96
|
+
return result
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// Context is passed to a handler. Input and User are JSON-compatible values
|
|
100
|
+
// supplied by DraftGo; platform resource methods will be added by the runner
|
|
101
|
+
// RPC client rather than by exposing database handles to scripts.
|
|
102
|
+
type Context struct {
|
|
103
|
+
Input map[string]any `json:"input"`
|
|
104
|
+
User map[string]any `json:"user,omitempty"`
|
|
105
|
+
Headers http.Header `json:"headers,omitempty"`
|
|
106
|
+
Platform bool `json:"platform"`
|
|
107
|
+
WorkspaceID int64 `json:"workspace_id,omitempty"`
|
|
108
|
+
SpaceID int64 `json:"space_id,omitempty"`
|
|
109
|
+
Principal ScopePrincipal `json:"principal"`
|
|
110
|
+
|
|
111
|
+
DB Database `json:"-"`
|
|
112
|
+
Users Users `json:"-"`
|
|
113
|
+
Auth Auth `json:"-"`
|
|
114
|
+
Notify Notifier `json:"-"`
|
|
115
|
+
HTTP HTTPClient `json:"-"`
|
|
116
|
+
Cache Cache `json:"-"`
|
|
117
|
+
Config Config `json:"-"`
|
|
118
|
+
AIHub AIHub `json:"-"`
|
|
119
|
+
Knowledge Knowledge `json:"-"`
|
|
120
|
+
Memory Memory `json:"-"`
|
|
121
|
+
Files FileStore `json:"-"`
|
|
122
|
+
Scope ScopeAPI `json:"-"`
|
|
123
|
+
Billing BillingAPI `json:"-"`
|
|
124
|
+
// Admin groups explicitly elevated operations for trusted custom services.
|
|
125
|
+
// Elevation applies to one RPC call, is audited, and never exposes credentials.
|
|
126
|
+
Admin Admin `json:"-"`
|
|
127
|
+
Log *Logger `json:"-"`
|
|
128
|
+
|
|
129
|
+
context context.Context
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// NewContext constructs the platform facade used by the isolated runner. The
|
|
133
|
+
// client is intentionally a narrow RPC interface rather than a database or
|
|
134
|
+
// HTTP-server handle.
|
|
135
|
+
func NewContext(draftgo context.Context, input, user map[string]any, headers http.Header, client Client) *Context {
|
|
136
|
+
return NewContextWithResource(draftgo, input, user, headers, client, ResourceContext{}, ScopePrincipal{})
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
// NewContextWithResource constructs a handler context with persisted resource
|
|
140
|
+
// ownership and the service principal supplied by DraftGo. Custom services
|
|
141
|
+
// cannot override these values through Input or request headers.
|
|
142
|
+
func NewContextWithResource(draftgo context.Context, input, user map[string]any, headers http.Header, client Client, resource ResourceContext, principal ScopePrincipal) *Context {
|
|
143
|
+
if draftgo == nil {
|
|
144
|
+
draftgo = context.Background()
|
|
145
|
+
}
|
|
146
|
+
if input == nil {
|
|
147
|
+
input = map[string]any{}
|
|
148
|
+
}
|
|
149
|
+
platform := platformClient{client: client, context: draftgo}
|
|
150
|
+
adminPlatform := platformClient{client: client, context: draftgo, admin: true}
|
|
151
|
+
return &Context{
|
|
152
|
+
Input: input, User: user, Headers: headers, context: draftgo,
|
|
153
|
+
Platform: resource.ScopeType == ScopePlatform, WorkspaceID: resource.WorkspaceID, SpaceID: resource.SpaceID, Principal: principal,
|
|
154
|
+
DB: dbClient{platform}, Users: usersClient{platform}, Auth: authClient{user: user}, Notify: notifierClient{platform},
|
|
155
|
+
HTTP: httpClient{platform}, Cache: cacheClient{platform}, Config: configClient{platform}, AIHub: aiHubClient{platform},
|
|
156
|
+
Knowledge: knowledgeClient{platform}, Memory: memoryClient{platform}, Files: fileStoreClient{platform}, Scope: scopeClient{platform}, Billing: billingClient{platform},
|
|
157
|
+
Admin: Admin{
|
|
158
|
+
DB: dbClient{adminPlatform}, Users: usersClient{adminPlatform}, Auth: authClient{user: user}, Notify: notifierClient{adminPlatform},
|
|
159
|
+
HTTP: httpClient{adminPlatform}, Cache: cacheClient{adminPlatform}, Config: configClient{adminPlatform}, AIHub: aiHubClient{adminPlatform},
|
|
160
|
+
Knowledge: knowledgeClient{adminPlatform}, Memory: memoryClient{adminPlatform},
|
|
161
|
+
Files: fileStoreClient{adminPlatform}, Scope: scopeClient{adminPlatform}, Billing: billingClient{adminPlatform},
|
|
162
|
+
},
|
|
163
|
+
Log: &Logger{},
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Admin exposes explicitly elevated platform capabilities to trusted custom
|
|
168
|
+
// services. The runtime preserves the service subject, scopes elevation to one
|
|
169
|
+
// audited RPC call, and never exposes platform credentials.
|
|
170
|
+
type Admin struct {
|
|
171
|
+
DB Database
|
|
172
|
+
Users Users
|
|
173
|
+
Auth Auth
|
|
174
|
+
Notify Notifier
|
|
175
|
+
HTTP HTTPClient
|
|
176
|
+
Cache Cache
|
|
177
|
+
Config Config
|
|
178
|
+
AIHub AIHub
|
|
179
|
+
Knowledge Knowledge
|
|
180
|
+
Memory Memory
|
|
181
|
+
Files FileStore
|
|
182
|
+
Scope ScopeAPI
|
|
183
|
+
Billing BillingAPI
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Context returns the invocation deadline/cancellation context supplied by
|
|
187
|
+
// DraftGo. Pass it to SDK calls that accept a context.Context.
|
|
188
|
+
func (draftgo *Context) Context() context.Context {
|
|
189
|
+
if draftgo == nil || draftgo.context == nil {
|
|
190
|
+
return context.Background()
|
|
191
|
+
}
|
|
192
|
+
return draftgo.context
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Response allows handlers to explicitly control an HTTP response.
|
|
196
|
+
type Response struct {
|
|
197
|
+
Body any `json:"body"`
|
|
198
|
+
StatusCode int `json:"status_code"`
|
|
199
|
+
Headers http.Header `json:"headers,omitempty"`
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
// Respond creates a response result. A status of zero defaults to 200.
|
|
203
|
+
func (draftgo *Context) Respond(body any, status int, headers http.Header) Response {
|
|
204
|
+
if status == 0 {
|
|
205
|
+
status = http.StatusOK
|
|
206
|
+
}
|
|
207
|
+
return Response{Body: body, StatusCode: status, Headers: headers}
|
|
208
|
+
}
|
package/resources/skill/SKILL.md
CHANGED
|
@@ -1,106 +1,55 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: draftgo
|
|
3
|
-
description: Use this skill to inspect, develop, debug, or deliver a DraftGo application. Read task-specific references
|
|
3
|
+
description: Use this skill to inspect, develop, debug, or deliver a DraftGo application. Read only the task-specific references, locate long-content resources precisely, and use checkout/commit with a project worklog.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
|
-
## Workflow 2.0 authority
|
|
7
|
-
|
|
8
|
-
- Treat pages, navigations, docs/articles, and custom services as checkout resources. Never save complete MCP responses, duplicate source snapshots, temporary Go modules, SDK stubs, executables, or build directories by hand.
|
|
9
|
-
- The root Skill loads automatically. Before acting, read the smallest relevant Reference set from the task-routing table, then use MCP only for live project evidence.
|
|
10
|
-
- Custom-service flow: read `references/custom-services.md` -> locate the service through MCP -> `checkout custom-services` -> edit four files -> `commit` cloud draft -> `test` in the server Runner -> `check --remote` -> `publish` -> `refresh`. CLI and admin UI edit the same cloud draft.
|
|
11
|
-
- Do not create Task overhead for a small, single-point change. For cross-module, cross-session, or multi-Agent work, create or resume `.draftgo/Task/[YYYY-MM-DD]<slug>/Task.md`. It is the only task state: preserve both the user's original request and the clarified executable requirement, assign one owner per item/resource, and check an item only with verification evidence. Changelog remains the final delivery record, not a task tracker.
|
|
12
|
-
- Normal delivery uses `draftgo verify`; add `--remote` only when remote comparison is required and `--url` only for browser evidence. UI verification is iframe-aware and defaults to one viewport with no screenshot. Only explicit visual acceptance or regression diagnosis may pass `--viewport both` or `--screenshot on-failure|always`.
|
|
13
|
-
- `.draftgo/tmp/` is entirely disposable. CLI data uses `.draftgo/tmp/<command>/<run-id>/`; AI-created scratch files use `.draftgo/tmp/ai/<run-id>/`. User-facing evidence belongs under registered `.draftgo/artifacts/`. Use `draftgo clean --dry-run` before `draftgo clean --yes`.
|
|
14
|
-
|
|
15
6
|
# DraftGo 开发助手
|
|
16
7
|
|
|
17
|
-
##
|
|
8
|
+
## 开始前
|
|
18
9
|
|
|
19
|
-
-
|
|
20
|
-
-
|
|
21
|
-
-
|
|
22
|
-
-
|
|
23
|
-
-
|
|
24
|
-
-
|
|
10
|
+
- 任务开始即运行 `draftgo work start "<事项>"`;记录 CLI 返回的工作项引用。独立事项用 `draftgo work add`,仅在验证和交付成功后运行 `draftgo work complete <ref> --note "<证据>"`。
|
|
11
|
+
- 根 Skill 会在触发时自动加载;先读取下表中最少必要的 Reference,再用 MCP 查询当前项目。不要预先读取所有 Reference,也不要把动态 operation schema 写入 Skill 或聊天上下文。
|
|
12
|
+
- pages、navigations、docs/articles 与 custom services 的完整正文只能通过 `draftgo checkout`、worktree、`draftgo diff`、`draftgo verify` 和 `draftgo commit` 处理;MCP 只用于定位、元数据和结构化资源。不要把完整正文、响应快照、临时 Go 模块、SDK 副本或构建目录写入聊天上下文或手工归档。
|
|
13
|
+
- 已知页面 route 或标题时,用 `draftgo map --type pages --route <path>` 或 `--title <title>` 精确定位;两个筛选条件取交集。只需范围或状态时加 `--summary`;需要浏览时使用 `--limit`(默认 20)和后续 `--cursor`,绝不默认全量枚举。
|
|
14
|
+
- `--output json` 的 stdout 是单一 UTF-8 JSON;诊断和进度走 stderr。不要依赖终端截断来控制上下文。
|
|
15
|
+
- 正常交付只运行 `draftgo verify`。默认跳过 UI;只有用户明确要求视觉验收时才使用截图,要求交互或 DOM 验证时才使用 `--ui always`。
|
|
25
16
|
|
|
26
|
-
|
|
17
|
+
不要用 MCP 摘要代替完整正文,也不要把 Skill 中列出的 `/assets/` 能力声称为当前服务器全部文件。CLI 不提供页面模板;页面根据任务、受众、现有产品语言和可用资源设计。
|
|
27
18
|
|
|
28
|
-
|
|
19
|
+
## 任务路由
|
|
29
20
|
|
|
30
|
-
| 任务 |
|
|
21
|
+
| 任务 | 先读 |
|
|
31
22
|
|---|---|
|
|
32
|
-
| 页面、导航、交互或 UI | `references/frontend.md`;涉及 iframe、路由、认证或全局层加读 `runtime.md` / `app-api.md
|
|
33
|
-
|
|
|
34
|
-
|
|
|
35
|
-
|
|
|
36
|
-
|
|
|
37
|
-
|
|
|
38
|
-
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
页面需求不因出现“页面”二字就默认新建或 checkout。Agent 结合用户意图、现有 route、页面职责和入口自主判断:修改已有页面时定位唯一资源后 checkout;确需独立新页面时先通过 MCP 实时 API 创建并取得 ID,再 checkout 正文。证据足以判断时直接推进;多个候选会导致不同产品结果时再向用户澄清。
|
|
43
|
-
|
|
44
|
-
## 所有权与执行
|
|
45
|
-
|
|
46
|
-
- 同一文件或 DraftGo 资源全程只能由一个 Agent 修改;其他 Agent 只读分析并回传建议。
|
|
47
|
-
- 先确定共享 schema、接口、权限和 route,再并行处理无依赖且 owner 不冲突的工作单元。
|
|
48
|
-
- 单页面、强依赖或仍共享主要资源的任务不强行并行。
|
|
49
|
-
- 主 Agent 负责 Reference/MCP 路由、owner 分配、汇总回读、统一验证、交付和完成日志;子 Agent 不单独写 changelog。
|
|
50
|
-
- 冲突 owner、接口依赖或验证失败会阻塞依赖项,不影响无关分支继续汇总。
|
|
51
|
-
|
|
52
|
-
## 开发与交付
|
|
23
|
+
| 页面、导航、交互或 UI | `references/frontend.md`;涉及 iframe、路由、认证或全局层加读 `runtime.md` / `app-api.md` |
|
|
24
|
+
| pages/nav/docs 正文、版本或冲突 | `references/checkout.md` |
|
|
25
|
+
| 动态 DB、筛选或关系 | `references/data.md`;复杂关系再读 `db-relations.md` |
|
|
26
|
+
| AIHub、知识库、记忆、聊天或图片 | `references/aihub.md`;页面调用再读 `chat-sdk.md` |
|
|
27
|
+
| 自定义服务、权限、外部调用、余额扣款或订阅 | `references/custom-services.md` |
|
|
28
|
+
| MCP 配置、API 契约或故障 | `references/mcp.md`;连接或调用失败时运行 `draftgo mcp test` |
|
|
29
|
+
| 运行失败、日志或请求链路 | `references/diagnostics.md` |
|
|
30
|
+
| 验证、发布或交付验收 | `references/delivery.md` |
|
|
31
|
+
| 跨领域任务且不确定最短链路 | `references/methods.md`,再打开所需领域资料 |
|
|
32
|
+
| 架构、模块选型或陌生项目 | `references/architecture.md`、`references/modules.md`;存在时一并读 `.draftgo/story.yaml` |
|
|
53
33
|
|
|
54
|
-
|
|
34
|
+
业务归属、系统资源或页面类型没有元数据时,报告证据不足,不凭标题、路径或片段猜测。页面需求不因出现“页面”二字就默认新建或 checkout:修改已有资源时先唯一定位,确需独立新页面时先通过 MCP 实时 API 创建并取得 ID,再 checkout 正文;多个候选会导致不同产品结果时再向用户澄清。
|
|
55
35
|
|
|
56
|
-
|
|
57
|
-
2. 对需要完整分析或编辑的目标批量 checkout;在 `.draftgo/worktree/` 按唯一 owner 编辑。
|
|
58
|
-
3. 主 Agent 回读全部修改,编辑过程中统一运行一次快速 `draftgo check`。交付前运行 `draftgo verify <type> <id...>`;需要远端证据时加 `--remote`,页面布局或交互变化时加对应 `--url`。
|
|
59
|
-
4. 用 `draftgo diff <type> <id>` 检查 base/local 差异,再按类型运行 `draftgo commit ...`。commit 后需要验证远端页面时运行 `draftgo verify <type> <id> --remote --url <url>`。
|
|
60
|
-
5. 409/412 时停止自动提交,保留 base/local/remote 冲突材料;不得 force、覆盖或自动合并。
|
|
36
|
+
## 长正文与结构化资源
|
|
61
37
|
|
|
62
|
-
|
|
38
|
+
1. 精确定位目标后再 checkout;对需要完整分析或编辑的目标批量 checkout,并在 `.draftgo/worktree/` 由唯一 owner 编辑。
|
|
39
|
+
2. 先用 `draftgo diff <type> <id> --stat` 或 `--summary` 判断范围;只有需要审查内容时才展开完整 diff。
|
|
40
|
+
3. 运行所需的 `draftgo verify`,再 commit。409/412 时停止,保留 base/local/remote;不得 force、覆盖或自动合并。
|
|
41
|
+
4. 结构化资源不 checkout:未知 operation 才 search,首次使用或 registry revision 变化时 describe,其余使用缓存后 call;describe 不完整就停止,不猜字段、权限或风险。
|
|
63
42
|
|
|
64
|
-
|
|
43
|
+
完整传输、manifest 和冲突规则见 `references/checkout.md`;交付证据见 `references/delivery.md`。
|
|
65
44
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
### 完成日志
|
|
69
|
-
|
|
70
|
-
只有整个任务的检查、UI/API 验证和所有 commit/MCP 写入都成功后,主 Agent 执行一次:
|
|
71
|
-
|
|
72
|
-
```bash
|
|
73
|
-
draftgo changelog add "<完成结果>"
|
|
74
|
-
```
|
|
75
|
-
|
|
76
|
-
任何验证失败、409/412 或交付失败都不得写 changelog。日志只写完成结果,不写排查过程。
|
|
77
|
-
|
|
78
|
-
## 安全规则
|
|
79
|
-
|
|
80
|
-
- SAT 只保存在 `.draftgo/config.json`;不得进入宿主配置、命令行参数、Skill、日志、manifest 或错误消息。宿主只配置 `draftgo mcp serve`。
|
|
81
|
-
- 页面优先使用可信本地资源;禁止境外 CDN。用户输入或不可信 HTML 在渲染前净化,关键状态不能只靠颜色或动效表达。
|
|
82
|
-
- 页面通过 `window.parent.App` 使用认证、权限、反馈和主题;登出调用 `await App.logout()`,路由参数读取运行时注入对象。详细规则见 `frontend.md`、`runtime.md` 与 `app-api.md`。
|
|
83
|
-
- 自定义服务普通 SDK 继承调用者权限;仅显式 `draftgo.Admin.*` 提升单次调用并进入审计。Route 权限、脚本管理权限、定时/事件身份和出站限制见 `custom-services.md`。
|
|
84
|
-
- 高风险 MCP operation 仅在用户意图明确且影响范围已核对时设置 `confirm=true`。不要传 SAT、Authorization、tenant override 或自行实现旧式二次认证。
|
|
85
|
-
- 旧 `.draftgo` 缓存不是事实来源;不自动删除。不要隐式 force、自动重试覆盖或自动合并冲突。
|
|
86
|
-
|
|
87
|
-
## 验证证据
|
|
88
|
-
|
|
89
|
-
| 范围 | 最低证据 |
|
|
90
|
-
|---|---|
|
|
91
|
-
| MCP 连接 | 失败时用 `draftgo mcp test` 核对 initialize、tools/list 和关键工具;输出不含 SAT |
|
|
92
|
-
| 页面、导航、文档 | checkout manifest、`draftgo check`、交付前 `draftgo verify`、diff、commit 返回版本与哈希 |
|
|
93
|
-
| 结构化资源 | search/describe 契约、call 结果与回读的权限、字段、错误和副作用 |
|
|
94
|
-
| 自定义服务 | 动态 Route describe、无副作用健康请求或目标行为结果,以及管理员调用审计 |
|
|
95
|
-
| 冲突 | `.draftgo/conflicts/` 的 base/local/remote;解决后重新 check、必要的 verify 和 commit |
|
|
96
|
-
| 本地底座 | `draftgo local status`、日志和相关 local 测试 |
|
|
45
|
+
## 所有权与安全
|
|
97
46
|
|
|
98
|
-
|
|
47
|
+
- 同一文件或 DraftGo 资源全程只能由一个 Agent 修改;不同资源、operation 和 owner 不冲突的单元可以并发,不设置客户端并发上限;同一资源的依赖步骤保持串行。主 Agent 负责 owner 分配、汇总、验证、交付和 worklog 状态。
|
|
48
|
+
- 用户 API Key 只保存在 `.draftgo/config.json`,不得进入宿主配置、命令参数、Skill、日志、manifest 或错误消息。宿主 MCP 配置只运行 `draftgo mcp serve`。
|
|
49
|
+
- 页面优先使用可信本地资源;禁止境外 CDN。净化不可信 HTML,关键状态不能只靠颜色或动效表达。页面通过 `window.parent.App` 使用认证、权限、反馈和主题;详细规则见前端与运行时 Reference。
|
|
50
|
+
- 普通自定义服务 SDK 调用继承调用者、服务归属和 AccessGrant;`ctx.Admin.*` 是可信服务显式选择的单次管理提升,允许跨用户/空间操作且必须进入审计,不会泄漏到后续调用。高风险 MCP operation 仅在用户意图明确且影响范围已核对时设置 `confirm=true`。
|
|
51
|
+
- `.draftgo/tmp/` 可清理;先运行 `draftgo clean --dry-run`,再在需要时使用 `--yes`。用户可查验的证据放入已注册的 `.draftgo/artifacts/`。
|
|
99
52
|
|
|
100
|
-
##
|
|
53
|
+
## 完成条件
|
|
101
54
|
|
|
102
|
-
|
|
103
|
-
- `.draftgo/worktree/`、`.base/`、`manifest.json`:checkout 正文及基线,必须 gitignore。
|
|
104
|
-
- `.draftgo/conflicts/`:409/412 材料,必须 gitignore。
|
|
105
|
-
- `.draftgo/story.yaml`、`Task/`、`lessons/`:项目决策、任务和经验。
|
|
106
|
-
- `.draftgo/changelog.md`:仅在整个任务验证和交付成功后写入。
|
|
55
|
+
每个目标均有与其类型相符的证据:正文有 checkout、验证、commit 返回的版本/哈希及必要远端回读;结构化资源有 describe、写入结果和回读;自定义服务的 `commit` 会完成 validate/publish,按需补充 test。任何验证失败、409/412 或交付失败都不得标记为完成;任何 verify、写入、回读或要求的视觉验收失败时,工作项保持 active。
|
|
@@ -17,30 +17,25 @@ description: Install or refresh the DraftGo skill, connect a project to a DraftG
|
|
|
17
17
|
- 已有 DraftGo 服务器:运行 draftgo connect。
|
|
18
18
|
- 需要本地 Docker 基座:运行 draftgo local setup。
|
|
19
19
|
6. 连接后运行 draftgo mcp setup(或指定目标),再运行 draftgo mcp test 验证 initialize、tools/list 和关键工具。
|
|
20
|
-
7. 根 Skill 自动加载后,按实际任务读取最少必要的 Reference,并通过 MCP project_overview、resource_search 或 api_search 获取实时信息;需要叠加本地 checkout 状态时运行 `draftgo map`。MCP
|
|
20
|
+
7. 根 Skill 自动加载后,按实际任务读取最少必要的 Reference,并通过 MCP project_overview、resource_search 或 api_search 获取实时信息;需要叠加本地 checkout 状态时运行 `draftgo map`。MCP 不可用时报告原因。
|
|
21
21
|
|
|
22
|
-
draftgo init 只负责 Skill 安装;draftgo connect 负责保存并验证 server/
|
|
22
|
+
draftgo init 只负责 Skill 安装;draftgo connect 负责保存并验证 server/API Key;draftgo mcp setup 负责宿主配置。不要混用职责。
|
|
23
23
|
|
|
24
|
-
初始化后 `.draftgo/` 只保留已经写入的 `config.json`。不要预建
|
|
24
|
+
初始化后 `.draftgo/` 只保留已经写入的 `config.json`。不要预建 worklog、lessons、worktree、conflicts 或其他占位文件和目录;首次实际使用对应能力时再创建。
|
|
25
25
|
|
|
26
|
-
##
|
|
26
|
+
## API Key 与配置
|
|
27
27
|
|
|
28
|
-
-
|
|
28
|
+
- 交互式连接使用当前用户的 DraftGo API Key 和隐藏输入;不要把 API Key 写入宿主配置、Skill 文件、命令行示例或日志。
|
|
29
29
|
- .draftgo/config.json、checkout manifest、base 和冲突目录必须加入项目 .gitignore。
|
|
30
|
-
- bridge 从当前项目配置读取
|
|
31
|
-
- 旧 .draftgo 缓存不自动删除。把它当作 legacy 数据,提示用户使用 MCP 或 checkout 重新建立上下文。
|
|
30
|
+
- bridge 从当前项目配置读取 API Key;宿主配置只引用 draftgo mcp serve。
|
|
32
31
|
|
|
33
32
|
## 后续动作
|
|
34
33
|
|
|
35
34
|
- 宿主配置和诊断:draftgo mcp setup/status/test,详见 ../references/mcp.md。
|
|
36
35
|
- 开发准备:根 Skill 自动加载;按任务路由读取最少必要的 Reference,再按需直接调用 MCP。
|
|
37
36
|
- 远端资源补充定位:MCP project_overview、resource_search、resource_list。
|
|
38
|
-
-
|
|
37
|
+
- 正文编辑:遵循根 Skill 的 checkout/commit 与统一验证策略。
|
|
39
38
|
- 结构化资源:直接使用 MCP 的 api_search、api_describe、api_call;不 checkout、不生成本地镜像。
|
|
40
|
-
-
|
|
41
|
-
- 管理本地基座:draftgo local start|stop|logs|status
|
|
39
|
+
- 工作记录:开发开始时运行 `draftgo work start "<事项>"`;只有统一验证且全部 commit/MCP 交付成功后运行 `draftgo work complete <编号> --note "<结果>"`。验证、冲突或交付失败时不得标记为完成。
|
|
40
|
+
- 管理本地基座:draftgo local setup|start|stop|logs|status。
|
|
42
41
|
- 移除指定目标:draftgo uninstall <target>;完整移除所有目标只在用户明确要求时运行 draftgo uninstall all,--purge 会删除 .draftgo/。
|
|
43
|
-
|
|
44
|
-
## 迁移旧命令
|
|
45
|
-
|
|
46
|
-
draftgo pull 不再执行同步。它只能给出迁移提示并返回非零,指导使用 MCP 定位资源或 checkout 长正文。不要悄悄恢复全量下载。
|
|
@@ -2,17 +2,21 @@
|
|
|
2
2
|
"schema_version": "1.0",
|
|
3
3
|
"id": "draftgo",
|
|
4
4
|
"name": "DraftGo 开发助手",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "4.0.22",
|
|
6
6
|
"entry": "SKILL.md",
|
|
7
7
|
"description": "以 Skill/reference 任务路由、MCP 实时发现、长正文 checkout/commit、统一验证和完成日志为边界的 DraftGo 工作流。",
|
|
8
8
|
"license": "MIT",
|
|
9
9
|
"capabilities": [
|
|
10
10
|
"draftgo-development",
|
|
11
11
|
"reference-routing",
|
|
12
|
-
"
|
|
12
|
+
"worklog-tracking",
|
|
13
13
|
"custom-service-ai-sdk",
|
|
14
|
+
"minimal-method-guides",
|
|
15
|
+
"aihub-knowledge-memory",
|
|
14
16
|
"mcp-bridge",
|
|
15
17
|
"content-checkout-commit",
|
|
18
|
+
"runtime-diagnostics",
|
|
19
|
+
"delivery-acceptance",
|
|
16
20
|
"conflict-safe-delivery",
|
|
17
21
|
"project-validation",
|
|
18
22
|
"skill-installation"
|
|
@@ -4,8 +4,26 @@ read_when: 创建或调优 AI Agent 时 · 需要工具/子智能体/记忆/多
|
|
|
4
4
|
|
|
5
5
|
# AIHub / Agent 资源
|
|
6
6
|
|
|
7
|
+
## 最短管理流程
|
|
8
|
+
|
|
9
|
+
AIHub、知识库与记忆都是结构化远端资源。先按领域搜索实时 operation,再描述契约并调用;`request.json` 只包含 describe 允许的字段:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
draftgo api search "AIHub Agent"
|
|
13
|
+
draftgo api search "knowledge base"
|
|
14
|
+
draftgo api search "agent memory"
|
|
15
|
+
draftgo api describe <operation_id>
|
|
16
|
+
draftgo api call <operation_id> --input request.json --output json
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
已有精确 `operation_id` 时跳过 search。写入后用对应 get/list operation 回读目标 ID;需要验证运行行为时,再查调用 operation 和 AI run 日志,不把配置成功当成推理成功。知识库存放可检索资料,长期记忆存放 Agent 运行时按作用域提炼的用户/Agent 记忆,两者不要互相代替。
|
|
20
|
+
|
|
21
|
+
AIHub 与知识库是独立权限域:Agent、模型和 AI 运行使用 `aihub:*`,知识库、文档、上传、检索和重建使用 `knowledge:*`。配置了 `aihub:*` 不会自动获得知识库权限,反之亦然;具体动作仍以实时 operation 契约为准。
|
|
22
|
+
|
|
23
|
+
完成条件:目标资产可回读,状态与调用权限符合预期;任务涉及调用时,运行成功且日志能按入口 Agent/模型定位。任何文件和输出都不得包含供应商密钥。
|
|
24
|
+
|
|
7
25
|
AIHub 是结构化远端资源,不 checkout,也不生成本地镜像。先使用 MCP `draftgo_resource_search`/`draftgo_resource_list`
|
|
8
|
-
|
|
26
|
+
定位资产;未知 operation 才用 `draftgo_api_search`,首次使用或 registry revision 变化时 `draftgo_api_describe`,然后通过 `draftgo_api_call` 读写。
|
|
9
27
|
更新 AIHub 资产时只发送实时契约允许的字段;常见字段包括
|
|
10
28
|
`type, name, data, priority, version, tags, describe, permission, status`。供应商和模型使用各自的实时接口,
|
|
11
29
|
不要经旧 AIHub 资产接口写入。任何输出、工作区文件或调用参数都不得保存 API Key 或 header 值;只可处理
|
|
@@ -29,7 +47,7 @@ AIHub 是结构化远端资源,不 checkout,也不生成本地镜像。先
|
|
|
29
47
|
|
|
30
48
|
页面对话 UI 使用 `<dg-chat protocol="draftgo-agent" agent-id="AGENT_ID">` 或 `DraftGoChat.create()`;
|
|
31
49
|
旧代码/无 UI 文本调用可用 `DraftGoAI.chat(...)`,图片模式使用 `DraftGoAI.images(...)`。调用前都必须加载
|
|
32
|
-
`/assets/draftgo-chat.js`,完整用法见 `references/chat-sdk.md`。后端 operation 与可调用 Agent 列表通过 MCP
|
|
50
|
+
`/assets/draftgo-chat.js`,完整用法见 `references/chat-sdk.md`。后端 operation 与可调用 Agent 列表通过 MCP 实时确认;已知契约可复用项目缓存。
|
|
33
51
|
|
|
34
52
|
## `data.spec` 字段地图
|
|
35
53
|
|
|
@@ -37,7 +55,7 @@ AIHub 是结构化远端资源,不 checkout,也不生成本地镜像。先
|
|
|
37
55
|
|
|
38
56
|
| 字段 | 类型 / 取值 | 说明 |
|
|
39
57
|
|---|---|---|
|
|
40
|
-
| `mode` | `chat` / `image_generation` |
|
|
58
|
+
| `mode` | `chat` / `image_generation` | 决定主要交互形态;具体 Responses、Embedding、Rerank、TTS、ASR、Video operation 以 MCP 和模型 capability 为准 |
|
|
41
59
|
| `model` | string | 主模型(逻辑模型名,映射到供应商路由) |
|
|
42
60
|
| `fallback_models` | string[] | 主模型失败后按序回退(跨模型 failover) |
|
|
43
61
|
| `model_selection.user_selectable` | bool | 是否允许调用方在请求里覆盖 `model`(配合 `selectable-models`) |
|
|
@@ -57,6 +75,7 @@ AIHub 是结构化远端资源,不 checkout,也不生成本地镜像。先
|
|
|
57
75
|
| `skills` | 见运行时 | 绑定 Skill |
|
|
58
76
|
| `sub_agent_ids` | int[] | 子智能体:为每个 id 生成 `agent_{id}` 委派工具(用法同 `knowledge_base_ids`) |
|
|
59
77
|
| `call_permissions` | 角色配置 | 哪些角色可以调用此 Agent;调用接口与筛选条件以 MCP 实时契约为准 |
|
|
78
|
+
| `billing_mode` | `disabled` / `inherit_model` / `per_call` / `usage` | Agent 零售计费;公开 Agent 强制 `disabled`,订阅/会员额度由业务服务管理 |
|
|
60
79
|
|
|
61
80
|
### `orchestration.*`(编排开关)
|
|
62
81
|
|
|
@@ -86,8 +105,12 @@ AIHub 是结构化远端资源,不 checkout,也不生成本地镜像。先
|
|
|
86
105
|
## 观测
|
|
87
106
|
|
|
88
107
|
每次调用都开一条 AI run,管理台 `/admin/ai-runs` 展示状态、tokens、延迟、`ttft_ms` 与 span 链路。
|
|
89
|
-
运行记录接口通过 MCP
|
|
108
|
+
运行记录接口通过 MCP 实时发现,不维护静态路径表;已知 operation 复用 registry revision 未变化的契约缓存。
|
|
109
|
+
|
|
110
|
+
模型价格使用 `disabled`、`per_call`、`usage`。模型能否调用某项能力必须同时满足模型声明、Provider
|
|
111
|
+
profile、transport readiness 和实际 route;不要只根据供应商名称推断支持音频、视频或其他能力。
|
|
112
|
+
能力名大小写敏感,使用实时 describe 返回的 canonical 值,不使用历史别名。
|
|
90
113
|
|
|
91
114
|
Agent 对外响应(`/api/agents/{id}/chat`、图片接口、Go/Script SDK Agent 调用)不返回内部 `model`、`fallback_models` 或 `upstream_model`;错误也不暴露内部模型名、供应商名称、服务地址或运行时实现名。只有显式启用 `model_selection.user_selectable` 后,`/selectable-models` 才作为授权的模型选择目录返回可选逻辑模型名。运行日志仍在服务端保留真实模型、供应商与链路信息用于定位。
|
|
92
115
|
|
|
93
|
-
> 权威细节以 DraftGo
|
|
116
|
+
> 权威细节以 DraftGo `docs/modules/ai-platform/agent-runtime.md` 和实时 MCP schema 为准;本页是基座开发者视角的字段速查。
|
|
@@ -12,11 +12,11 @@ const App = window.parent?.App;
|
|
|
12
12
|
|
|
13
13
|
| 方法 | 签名 | 说明 |
|
|
14
14
|
|---|---|---|
|
|
15
|
-
| `App.get` | `(path, params?)` | GET,params 为 query 参数 |
|
|
16
|
-
| `App.post` | `(path, body?)` | POST |
|
|
17
|
-
| `App.put` | `(path, body?)` | PUT |
|
|
18
|
-
| `App.patch` | `(path, body?)` | PATCH |
|
|
19
|
-
| `App.delete` | `(path)` | DELETE |
|
|
15
|
+
| `App.get` | `(path, params?, headers?)` | GET,params 为 query 参数 |
|
|
16
|
+
| `App.post` | `(path, body?, headers?)` | POST |
|
|
17
|
+
| `App.put` | `(path, body?, headers?)` | PUT |
|
|
18
|
+
| `App.patch` | `(path, body?, headers?)` | PATCH |
|
|
19
|
+
| `App.delete` | `(path, params?, headers?)` | DELETE |
|
|
20
20
|
| `App.uploadFile` | `(file, onProgress?)` | 文件上传,返回标准信封 |
|
|
21
21
|
|
|
22
22
|
**响应格式**:`{ code: 200, data: <载荷>, message: "success" }`
|
|
@@ -67,11 +67,57 @@ const { patientId, visitId } = routeContext.query;
|
|
|
67
67
|
|---|---|---|
|
|
68
68
|
| `App.currentUser` | object \| null | 当前用户,未登录为 null |
|
|
69
69
|
| `App.isAdmin` | boolean | 是否管理员 |
|
|
70
|
+
| `App.permissions` | string[] | 当前用户有效 permission grant 的展示投影;仅用于页面显隐,不替代服务端授权 |
|
|
70
71
|
| `App.isAuthenticated` | boolean | 是否已认证 |
|
|
71
72
|
| `App.hasToken` | boolean | 是否有 token(含未验证) |
|
|
72
73
|
| `App.config` | object | 系统配置 KV |
|
|
73
74
|
| `App.theme` | `'light'` \| `'dark'` | 当前显示模式 |
|
|
74
75
|
| `App.colorScheme` | string | 当前配色方案 |
|
|
76
|
+
| `App.scopeContext` | object | null | 当前候选范围;`scope_type` 为 `platform` / `space` |
|
|
77
|
+
| `App.availableSpaces` | object[] | 当前用户可选择的工作区与递归空间 |
|
|
78
|
+
|
|
79
|
+
### 空间上下文
|
|
80
|
+
|
|
81
|
+
空间业务请求使用运行时当前上下文。页面先显示加载状态,再等待有效空间;返回 `null` 时呈现紧凑的工作空间状态和重试入口,本轮不发送业务请求。
|
|
82
|
+
|
|
83
|
+
```javascript
|
|
84
|
+
function currentSpace() {
|
|
85
|
+
const scope = App.getScopeContext?.() || App.scopeContext;
|
|
86
|
+
return scope?.scope_type === 'space' && scope.space_id ? scope : null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function waitForSpace(timeout = 4000) {
|
|
90
|
+
if (currentSpace()) return currentSpace();
|
|
91
|
+
return new Promise(resolve => {
|
|
92
|
+
const host = window.parent;
|
|
93
|
+
const done = value => {
|
|
94
|
+
clearTimeout(timer);
|
|
95
|
+
host?.removeEventListener('dg:scope-changed', check);
|
|
96
|
+
host?.removeEventListener('dg:scope-spaces-changed', check);
|
|
97
|
+
resolve(value);
|
|
98
|
+
};
|
|
99
|
+
const check = () => { if (currentSpace()) done(currentSpace()); };
|
|
100
|
+
const timer = setTimeout(() => done(null), timeout);
|
|
101
|
+
host?.addEventListener('dg:scope-changed', check);
|
|
102
|
+
host?.addEventListener('dg:scope-spaces-changed', check);
|
|
103
|
+
check();
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const scope = await waitForSpace();
|
|
108
|
+
if (!scope) {
|
|
109
|
+
renderWorkspaceState();
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
await App.get('business-items', { page: 1 });
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
平台管理接口按接口契约显式传入平台范围:
|
|
116
|
+
|
|
117
|
+
```javascript
|
|
118
|
+
const platformHeaders = { 'X-DraftGo-Scope-Type': 'platform' };
|
|
119
|
+
await App.get('roles', {}, platformHeaders);
|
|
120
|
+
```
|
|
75
121
|
|
|
76
122
|
## 主题
|
|
77
123
|
|
|
@@ -89,7 +135,11 @@ await App.logout(); // 服务端登出、清理状态并跳转
|
|
|
89
135
|
App.setAuthTokens({ access_token, refresh_token }); // 登录后写入 token
|
|
90
136
|
App.reloadGlobalLayer(); // 重载全局层
|
|
91
137
|
App.openGlobalWidget(name); // 触发全局挂件打开
|
|
92
|
-
App.
|
|
138
|
+
App.getScopeContext(); // 读取当前作用域
|
|
139
|
+
App.setScopeContext({ scope_type: 'space', space_id: '120' });
|
|
140
|
+
App.clearScopeContext(); // 清除手工选择,恢复服务端默认
|
|
141
|
+
App.t(key, fallback?, values?); // 页面级国际化文本,values 保留 ICU 占位符
|
|
142
|
+
App.formatDateTime(value, options?); // 按 system_timezone 格式化 API 返回的 UTC 时间
|
|
93
143
|
```
|
|
94
144
|
|
|
95
145
|
Token、刷新、路由上下文和认证事件见 `references/runtime.md`。AI 对话、图片和兼容门面的完整契约见 `references/chat-sdk.md`,Agent 能力见 `references/aihub.md`。
|
|
@@ -40,7 +40,7 @@ DraftGo **不是传统 SPA**,是「数据库驱动的页面资产运行时」
|
|
|
40
40
|
|---|---|
|
|
41
41
|
| 后端 | Go 1.26 · 标准库 `net/http` · `database/sql`(go-sql-driver/mysql)· MySQL · Redis |
|
|
42
42
|
| 壳层前端 | React · Vite |
|
|
43
|
-
| 数据库页面 | HTML 文档运行时 ·
|
|
43
|
+
| 数据库页面 | HTML 文档运行时 · Tailwind CSS 4 · Basecoat UI(默认)· Oat UI(可选)· Font Awesome · GSAP · 内置 SVG 图标库 |
|
|
44
44
|
| CLI | Node.js(draftgo-cli) |
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
数据库页面以完整 HTML 文档运行,直接加载平台提供的本地资源;壳层源码按 React + Vite 工程构建。开发时按目标所属层使用上表对应技术栈。
|
|
@@ -4,7 +4,7 @@ read_when: 页面需要 AI 对话 UI 时 · 使用 dg-chat 或 DraftGoChat 时
|
|
|
4
4
|
|
|
5
5
|
# DraftGo Chat SDK
|
|
6
6
|
|
|
7
|
-
DraftGo
|
|
7
|
+
DraftGo 页面使用完整版 `/assets/draftgo-chat.js` 原生 Web Component。SDK 统一提供消息状态机、流解析、停止、重试和历史逻辑。
|
|
8
8
|
|
|
9
9
|
## 目录
|
|
10
10
|
|
|
@@ -71,7 +71,7 @@ DraftGo 页面只使用完整版 `/assets/draftgo-chat.js`。它是原生 Web Co
|
|
|
71
71
|
|
|
72
72
|
这些 `/api/ai-proxy/*` 是接入方实现的占位路由,不是 DraftGo 自动提供的默认代理。不要将供应商密钥或长期 token 写入页面。
|
|
73
73
|
|
|
74
|
-
内置 transport 支持 SSE、NDJSON 和普通 JSON,并把上游响应归一化为 `text.delta`、`reasoning.delta`、`tool.start`、`tool.delta`、`tool.finish`、`artifact.complete`、`source`、`usage`、`message.finish`、`error`
|
|
74
|
+
内置 transport 支持 SSE、NDJSON 和普通 JSON,并把上游响应归一化为 `text.delta`、`reasoning.delta`、`tool.start`、`tool.delta`、`tool.finish`、`step.finish`、`artifact.complete`、`source`、`usage`、`message.finish`、`error` 等事件。配置 JSON 以 DraftGo 当前 `contracts/chat-sdk.schema.json` 为准;不要猜测字段或把函数、DOM、renderer、plugin、transport 写入 JSON。
|
|
75
75
|
|
|
76
76
|
## 配置与布局
|
|
77
77
|
|
|
@@ -160,6 +160,8 @@ chat.addEventListener('dg-chat:run-finish', event => {
|
|
|
160
160
|
|
|
161
161
|
页面销毁或离开路由时调用 `stop()`,取消上传、plugin 和在途 transport。
|
|
162
162
|
|
|
163
|
+
`requestTimeoutMs` 和 `streamTimeoutMs` 分别控制客户端非流式/流式总时限,默认 120000/610000 毫秒,`0` 表示禁用。两者只处理客户端半开连接,不替代 Agent 的服务端超时。
|
|
164
|
+
|
|
163
165
|
## 历史与会话
|
|
164
166
|
|
|
165
167
|
- `persist` 默认开启,将 UI thread 历史写入 `localStorage`;敏感或临时页面设为 `false`。
|