@aigne/doc-smith 0.8.0 → 0.8.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.8.1](https://github.com/AIGNE-io/aigne-doc-smith/compare/v0.8.0...v0.8.1) (2025-09-03)
4
+
5
+
6
+ ### Features
7
+
8
+ * tune d2 chart generating with comprehensive examples ([#80](https://github.com/AIGNE-io/aigne-doc-smith/issues/80)) ([3423e4c](https://github.com/AIGNE-io/aigne-doc-smith/commit/3423e4cff24335552503916694a3489e5d91bf6c))
9
+
10
+
11
+ ### Miscellaneous Chores
12
+
13
+ * release 0.8.1 ([21f64d4](https://github.com/AIGNE-io/aigne-doc-smith/commit/21f64d450377b1aef00f12613ba3b87aa4ef1d31))
14
+
3
15
  ## [0.8.0](https://github.com/AIGNE-io/aigne-doc-smith/compare/v0.7.2...v0.8.0) (2025-09-03)
4
16
 
5
17
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/doc-smith",
3
- "version": "0.8.0",
3
+ "version": "0.8.1",
4
4
  "description": "",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -1,48 +1,957 @@
1
1
  - 使用 d2 图表解释复杂的概念 (```d2``` format),让页面内容展示形式更丰富
2
- - 使用 d2 展示架构关系、流程与组件交互,节点与连线文案保持简洁
3
- - d2 代码块必须完整且可渲染,避免使用未闭合的语法与奇异字符
4
- - d2 图表使用补充说明:
5
- - 示例:
6
- {% include "diy-examples.md" %}
7
- - 官方示例:
8
- {% include "official-examples.md" %}
9
- - 其他注意事项:
10
- - 图表应简洁明了,节点和连线命名准确。
11
- - 每个 d2 代码块必须完整闭合,避免语法错误。
12
- - 不要添加注释说明,因为生成的图片无法进行交互。
13
- - 不要随意更改节点和连线的颜色,这样会破坏配置好的主题。
14
- - 节点的名称尽量使用 " 进行包裹,避免出现异常。
15
- - bad: `SDK: @blocklet/js-sdk`
16
- - good: `SDK: "@blocklet/js-sdk"`
17
- - d2 中的 `shape` 只有这些值: `rectangle`, `square`, `page`, `parallelogram`, `document`, `cylinder`, `queue`, `package`, `step`, `callout`, `stored_data`, `person`, `diamond`, `oval`, `circle`, `hexagon`, `cloud`, `c4-person`,不要随意创建其他的 shape,会导致图表报错
18
- - 页面的整体布局使用 `direction: down`,这样能确保图表适合在网页中进行阅读;子图中可以根据情况来使用其他的方向布局,需要确保图表的整体效果看起来不会太宽
19
- - 如果一个对象中的元素太多了(超过3个),请使用 `grid-columns` 限制一下单行的列数,`grid-columns` 的值不要超过 3,例如
20
- ```d2
21
- "Instance": {
2
+ - 使用的 d2 的版本是 0.7.x,d2 官方的文档请查看 https://d2lang.com/tour/intro/
3
+ - 图表应简洁明了,节点和连线命名准确,节点与连线文案保持简洁,不要太长
4
+ - bad
5
+ ```d2
6
+ "TokenService": {
7
+ label: "TokenService (Handles token storage & refresh)"
8
+ shape: class
9
+ }
10
+ ```
11
+ - good
12
+ ```d2
13
+ "TokenService": {
14
+ label: "TokenService"
15
+ shape: class
16
+ }
17
+ ```
18
+ - 使用 d2 展示架构关系、流程与组件交互
19
+ - d2 代码块必须完整且可渲染,避免使用未闭合的语法与奇异字符,避免语法错误
20
+ - 不要为节点添加 `tooltip`,保持简单即可
21
+ - bad
22
+ ```d2
23
+ "AuthService": {
24
+ label: "AuthService"
25
+ tooltip: "Manages user profiles, privacy, and authentication actions"
26
+ shape: class
27
+ }
28
+ ```
29
+ - good
30
+ ```d2
31
+ "AuthService": {
32
+ label: "AuthService"
33
+ shape: class
34
+ }
35
+ ```
36
+ - 节点的名称尽量使用 `"` 进行包裹,避免出现渲染异常
37
+ - bad: `SDK: @blocklet/js-sdk`
38
+ - good: `SDK: "@blocklet/js-sdk"`
39
+ - 不要随意给节点填充颜色,除非节点有明确的 yes/no 的状态,此时可以给节点 fill `error`, `warning`, `success` 之类的颜色
40
+ - bad
41
+ ```d2
42
+ "TokenService" {
43
+ shape: class
44
+ style.fill: "#fffbe6"
45
+ }
46
+ ```
47
+ - good
48
+ ```d2
49
+ "TokenService" {
50
+ shape: class
51
+ }
52
+ ```
53
+ - 对于单个节点和连线,可以使用 `animate: true` 可以让图表增加动画效果,看起来效果更好
54
+ - 对于节点 shape 的选择,可以参考
55
+ {% include "shape-rules.md" %}
56
+ - 页面的整体布局使用 `direction: down`,这样能确保图表适合在网页中进行阅读;子图中可以根据情况来使用其他的方向布局,需要确保图表的整体效果看起来不会太宽
57
+ - bad:
58
+ ```d2
59
+ direction: right
60
+
61
+ "online": {
62
+ shape: circle
63
+ style.fill: "#52c41a"
64
+ }
65
+
66
+ "offline": {
67
+ shape: circle
68
+ style.fill: "#faad14"
69
+ }
70
+
71
+ "expired": {
72
+ shape: circle
73
+ style.fill: "#ff4d4f"
74
+ }
75
+
76
+ "New Login" -> "online": "User authenticates"
77
+ "online" -> "offline": "User closes app/browser"
78
+ "online" -> "expired": "Token expires"
79
+ "offline" -> "online": "User returns"
80
+ "offline" -> "expired": "Extended inactivity"
81
+ ```
82
+ - good:
83
+ ```d2
84
+ direction: down
85
+
86
+ "online": {
87
+ shape: circle
88
+ style.fill: "#52c41a"
89
+ }
90
+
91
+ "offline": {
92
+ shape: circle
93
+ style.fill: "#faad14"
94
+ }
95
+
96
+ "expired": {
97
+ shape: circle
98
+ style.fill: "#ff4d4f"
99
+ }
100
+
101
+ "New Login" -> "online": "User authenticates"
102
+ "online" -> "offline": "User closes app/browser"
103
+ "online" -> "expired": "Token expires"
104
+ "offline" -> "online": "User returns"
105
+ "offline" -> "expired": "Extended inactivity"
106
+ ```
107
+ - 如果一个节点中的字节点太多了(超过3个),请使用 `grid-columns` 限制一下单行的列数,`grid-columns` 的值优先使用2,最大不要超过 3,例如
108
+ - good:
109
+ ```d2
110
+ "Instance": {
111
+ grid-columns: 3
112
+ "A": "A"
113
+ "B": "B"
114
+ "C": "C"
115
+ "D": "D"
116
+ "E": "E"
117
+ }
118
+ ```
119
+ ```d2
120
+ "Instance": {
121
+ grid-columns: 2
122
+ "A": "A"
123
+ "B": "B"
124
+ "C": "C"
125
+ "D": "D"
126
+ }
127
+ ```
128
+ - 每一个容器节点中,最好设置 `grid-columns`
129
+ - bad:
130
+ ```d2
131
+ direction: down
132
+
133
+ "SDK": "@blocklet/js-sdk" {
134
+ shape: package
135
+
136
+ "Core Instance": {
137
+ shape: rectangle
138
+ "BlockletSDK": "Main SDK Class"
139
+ }
140
+
141
+ "Services": {
142
+ grid-columns: 3
143
+ "AuthService": "User Authentication" {
144
+ shape: class
145
+ }
146
+ "TokenService": "Token Management" {
147
+ shape: class
148
+ }
149
+ "UserSessionService": "Session Management" {
150
+ shape: class
151
+ }
152
+ "BlockletService": "Blocklet Metadata" {
153
+ shape: class
154
+ }
155
+ "FederatedService": "Federated Login" {
156
+ shape: class
157
+ }
158
+ }
159
+
160
+ "HTTP Clients": {
161
+ grid-columns: 2
162
+ "createAxios": "Axios-based Client" {
163
+ shape: rectangle
164
+ }
165
+ "createFetch": "Fetch-based Client" {
166
+ shape: rectangle
167
+ }
168
+ }
169
+ }
170
+
171
+ "Your App": "Application Code" {
172
+ shape: rectangle
173
+ }
174
+
175
+ "Blocklet Services": "Remote APIs" {
176
+ shape: cylinder
177
+ }
178
+
179
+ "Your App" -> "SDK": "Import & Use"
180
+ "SDK" -> "Blocklet Services": "Authenticated Requests"
181
+ "Blocklet Services" -> "SDK": "Responses & Tokens"
182
+ ```
183
+ - good:
184
+ ```d2
185
+ direction: down
186
+
187
+ "SDK": "@blocklet/js-sdk" {
188
+ shape: package
189
+ grid-columns: 1
190
+
191
+ "Core Instance": {
192
+ shape: rectangle
193
+ "BlockletSDK": "Main SDK Class"
194
+ }
195
+
196
+ "Services": {
197
+ grid-columns: 3
198
+ "AuthService": "User Authentication" {
199
+ shape: class
200
+ }
201
+ "TokenService": "Token Management" {
202
+ shape: class
203
+ }
204
+ "UserSessionService": "Session Management" {
205
+ shape: class
206
+ }
207
+ "BlockletService": "Blocklet Metadata" {
208
+ shape: class
209
+ }
210
+ "FederatedService": "Federated Login" {
211
+ shape: class
212
+ }
213
+ }
214
+
215
+ "HTTP Clients": {
216
+ grid-columns: 2
217
+ "createAxios": "Axios-based Client" {
218
+ shape: rectangle
219
+ }
220
+ "createFetch": "Fetch-based Client" {
221
+ shape: rectangle
222
+ }
223
+ }
224
+ }
225
+
226
+ "Your App": "Application Code" {
227
+ shape: rectangle
228
+ }
229
+
230
+ "Blocklet Services": "Remote APIs" {
231
+ shape: cylinder
232
+ }
233
+
234
+ "Your App" -> "SDK": "Import & Use"
235
+ "SDK" -> "Blocklet Services": "Authenticated Requests"
236
+ "Blocklet Services" -> "SDK": "Responses & Tokens"
237
+ ```
238
+ - 必须保证一个图中,所有的节点都是有关联的,不需要为图表设置 legend,如果就是有节点不存在关联性,则应该移除这些节点,或者拆分成多个独立的图表
239
+ - bad:
240
+ ```d2
241
+ direction: down
242
+
243
+ "Your App": {
244
+ shape: rectangle
245
+ }
246
+
247
+ "SDK Request Helper": {
248
+ label: "@blocklet/js-sdk (createAxios / createFetch)"
249
+ shape: package
250
+ }
251
+
252
+ "Blocklet Service": {
253
+ shape: cylinder
254
+ }
255
+
256
+ "Token Refresh Endpoint": {
257
+ label: "/api/did/refreshSession"
258
+ shape: rectangle
259
+ }
260
+
261
+ "Your App" -> "SDK Request Helper": "1. Make API Call (e.g., /api/profile)"
262
+
263
+ "SDK Request Helper" -> "Blocklet Service": "2. Adds Auth Header & Sends Request" {
264
+ style {
265
+ stroke-dash: 2
266
+ }
267
+ }
268
+
269
+ "Success Path": {
270
+ style.stroke: "#52c41a"
271
+
272
+ "Blocklet Service" -> "SDK Request Helper": "3a. 200 OK (Token Valid)"
273
+ "SDK Request Helper" -> "Your App": "4a. Returns Data"
274
+ }
275
+
276
+
277
+ "Token Renewal Path": {
278
+ style.stroke: "#faad14"
279
+
280
+ "Blocklet Service" -> "SDK Request Helper": "3b. 401 Unauthorized (Token Expired)"
281
+ "SDK Request Helper" -> "Token Refresh Endpoint": "4b. Request New Token"
282
+ "Token Refresh Endpoint" -> "SDK Request Helper": "5b. New Tokens"
283
+ "SDK Request Helper" -> "Blocklet Service": "6b. Retry Original Request"
284
+ "Blocklet Service" -> "SDK Request Helper": "7b. 200 OK" {
285
+ style.stroke: "#52c41a"
286
+ }
287
+ "SDK Request Helper" -> "Your App": "8b. Returns Data Transparently" {
288
+ style.stroke: "#52c41a"
289
+ }
290
+ }
291
+ ```
292
+ - good:
293
+ ```d2
294
+ direction: down
295
+
296
+ "Your App": {
297
+ shape: rectangle
298
+ }
299
+
300
+ "SDK Request Helper": {
301
+ label: "@blocklet/js-sdk (createAxios / createFetch)"
302
+ shape: package
303
+ }
304
+
305
+ "Blocklet Service": {
306
+ shape: cylinder
307
+ }
308
+
309
+ "Token Refresh Endpoint": {
310
+ label: "/api/did/refreshSession"
311
+ shape: rectangle
312
+ }
313
+
314
+ "Your App" -> "SDK Request Helper": "1. Make API Call (e.g., /api/profile)"
315
+
316
+ "SDK Request Helper" -> "Blocklet Service": "2. Adds Auth Header & Sends Request" {
317
+ style {
318
+ stroke-dash: 2
319
+ }
320
+ }
321
+ ```
322
+ ```d2
323
+ "Success Path": {
324
+ style.stroke: "#52c41a"
325
+
326
+ "Blocklet Service" -> "SDK Request Helper": "3a. 200 OK (Token Valid)"
327
+ "SDK Request Helper" -> "Your App": "4a. Returns Data"
328
+ }
329
+ ```
330
+ ```d2
331
+ "Token Renewal Path": {
332
+ style.stroke: "#faad14"
333
+
334
+ "Blocklet Service" -> "SDK Request Helper": "3b. 401 Unauthorized (Token Expired)"
335
+ "SDK Request Helper" -> "Token Refresh Endpoint": "4b. Request New Token"
336
+ "Token Refresh Endpoint" -> "SDK Request Helper": "5b. New Tokens"
337
+ "SDK Request Helper" -> "Blocklet Service": "6b. Retry Original Request"
338
+ "Blocklet Service" -> "SDK Request Helper": "7b. 200 OK" {
339
+ style.stroke: "#52c41a"
340
+ }
341
+ "SDK Request Helper" -> "Your App": "8b. Returns Data Transparently" {
342
+ style.stroke: "#52c41a"
343
+ }
344
+ }
345
+ ```
346
+ - 必须确保每个节点和子节点是有名称的
347
+ - bad:
348
+ ```d2
349
+ "SDK Core Instance": {
350
+ shape: package
351
+ "TokenService": "Manages session and refresh tokens"
352
+ "Services": {
353
+ grid-columns: 2
354
+ "AuthService": ""
355
+ "BlockletService": ""
356
+ }
357
+ }
358
+ ```
359
+ - good:
360
+ ```d2
361
+ "SDK Core Instance": {
362
+ shape: package
363
+ "TokenService": "Manages session and refresh tokens"
364
+ "Services": {
365
+ grid-columns: 2
366
+ "AuthService": "AuthService"
367
+ "BlockletService": "BlockletService"
368
+ }
369
+ }
370
+ ```
371
+ - 当有关联关系的节点,处于一个节点内部时,则它们的关联关系也应该写在节点内部
372
+ - bad
373
+ ```d2
374
+ direction: down
375
+
376
+ "@blocklet/js-sdk": {
377
+ shape: package
378
+
379
+ "Main SDK Instance": {
380
+ shape: rectangle
381
+ "BlockletSDK Class": "Main entry point"
382
+ "getBlockletSDK()": "Singleton factory"
383
+ }
384
+
385
+ "HTTP Clients": {
386
+ shape: rectangle
387
+ grid-columns: 2
388
+ "createAxios()": "Axios-based client"
389
+ "createFetch()": "Fetch-based client"
390
+ }
391
+
392
+ "Core Services": {
393
+ shape: rectangle
394
+ grid-columns: 3
395
+ "AuthService": "User authentication"
396
+ "TokenService": "Token management"
397
+ "BlockletService": "Blocklet metadata"
398
+ "UserSessionService": "Session management"
399
+ "FederatedService": "Federated login"
400
+ "ComponentService": "Component utilities"
401
+ }
402
+ }
403
+
404
+ "Main SDK Instance" -> "HTTP Clients": "Uses for requests"
405
+ "Main SDK Instance" -> "Core Services": "Provides access to"
406
+ "HTTP Clients" -> "Core Services": "Configured with"
407
+ ```
408
+ - good
409
+ ```d2
410
+ direction: down
411
+
412
+ "@blocklet/js-sdk": {
413
+ shape: package
414
+
415
+ "Main SDK Instance": {
416
+ shape: rectangle
417
+ "BlockletSDK Class": "Main entry point"
418
+ "getBlockletSDK()": "Singleton factory"
419
+ }
420
+
421
+ "HTTP Clients": {
422
+ shape: rectangle
423
+ grid-columns: 2
424
+ "createAxios()": "Axios-based client"
425
+ "createFetch()": "Fetch-based client"
426
+ }
427
+
428
+ "Core Services": {
429
+ shape: rectangle
22
430
  grid-columns: 3
23
- "A": "A"
24
- "B": "B"
25
- "C": "C"
26
- "D": "D"
27
- "E": "E"
28
- }
29
- ```
30
- - 尽量保证一个图中,只有一个关联所有元素的图,不要产生多个没有任何连接的子图
31
- - 确保 `style` 中的值都是可用的,错误的字段会导致图片生成失败
32
- - 尽量确保每个子元素是有名称的
33
- - bad:
34
- ```d2
35
- "SDK Core Instance": {
36
- shape: package
37
- "TokenService": "Manages session and refresh tokens"
38
- "Services": {
39
- grid-columns: 2
40
- "AuthService": ""
41
- "BlockletService": ""
42
- "FederatedService": ""
43
- "UserSessionService": ""
44
- }
45
- }
46
- ```
47
- - 使用 animate: true 可以让图表增加动画效果,看起来效果更好
48
- - 针对节点的状态(yes or no),可以给定不同的颜色(error,warning,success)来增强表现力
431
+ "AuthService": "User authentication"
432
+ "TokenService": "Token management"
433
+ "BlockletService": "Blocklet metadata"
434
+ "UserSessionService": "Session management"
435
+ "FederatedService": "Federated login"
436
+ "ComponentService": "Component utilities"
437
+ }
438
+
439
+ "Main SDK Instance" -> "HTTP Clients": "Uses for requests"
440
+ "Main SDK Instance" -> "Core Services": "Provides access to"
441
+ "HTTP Clients" -> "Core Services": "Configured with"
442
+ }
443
+ ```
444
+ - bad:
445
+ ```d2
446
+ direction: down
447
+
448
+ "Your App": {
449
+ shape: rectangle
450
+ }
451
+
452
+ "SDK Request Helper": {
453
+ label: "@blocklet/js-sdk (createAxios / createFetch)"
454
+ shape: package
455
+ }
456
+
457
+ "Blocklet Service": {
458
+ shape: cylinder
459
+ }
460
+
461
+
462
+ "Your App" -> "SDK Request Helper": "1. Make API Call (e.g., /api/profile)"
463
+
464
+ "SDK Request Helper" -> "Blocklet Service": "2. Adds Auth Header & Sends Request" {
465
+ style {
466
+ stroke-dash: 2
467
+ }
468
+ }
469
+
470
+ "Token Renewal Path": {
471
+ style.stroke: "#faad14"
472
+
473
+ "Blocklet Service" -> "SDK Request Helper": "3. 401 Unauthorized (Token Expired)"
474
+ "SDK Request Helper" -> "Token Refresh Endpoint": "4. Request New Token"
475
+ "Token Refresh Endpoint" -> "SDK Request Helper": "5. New Tokens Received"
476
+ "SDK Request Helper" -> "Blocklet Service": "6. Retry Original Request with New Token"
477
+ "Blocklet Service" -> "SDK Request Helper": "7. 200 OK" {
478
+ style.stroke: "#52c41a"
479
+ }
480
+ "SDK Request Helper" -> "Your App": "8. Returns Data Transparently" {
481
+ style.stroke: "#52c41a"
482
+ }
483
+ }
484
+ ```
485
+ - good:
486
+ ```d2
487
+ direction: down
488
+
489
+ "Your App": {
490
+ shape: rectangle
491
+ }
492
+
493
+ "SDK Request Helper": {
494
+ label: "@blocklet/js-sdk (createAxios / createFetch)"
495
+ shape: package
496
+ }
497
+
498
+ "Blocklet Service": {
499
+ shape: cylinder
500
+ }
501
+
502
+
503
+ "Your App" -> "SDK Request Helper": "1. Make API Call (e.g., /api/profile)"
504
+
505
+ "SDK Request Helper" -> "Blocklet Service": "2. Adds Auth Header & Sends Request" {
506
+ style {
507
+ stroke-dash: 2
508
+ }
509
+ }
510
+
511
+ "Blocklet Service" -> "SDK Request Helper": "3. 401 Unauthorized (Token Expired)"
512
+ "SDK Request Helper" -> "Token Refresh Endpoint": "4. Request New Token"
513
+ "Token Refresh Endpoint" -> "SDK Request Helper": "5. New Tokens Received"
514
+ "SDK Request Helper" -> "Blocklet Service": "6. Retry Original Request with New Token"
515
+ "Blocklet Service" -> "SDK Request Helper": "7. 200 OK" {
516
+ style.stroke: "#52c41a"
517
+ }
518
+ "SDK Request Helper" -> "Your App": "8. Returns Data Transparently" {
519
+ style.stroke: "#52c41a"
520
+ }
521
+ ```
522
+ - 如果整个图表只有一个容器节点,就不要增加这个容器节点,直接将内部的节点放在最外层
523
+ - bad:
524
+ ```d2
525
+ direction: down
526
+
527
+ "User Sessions Flow": {
528
+ shape: package
529
+ grid-columns: 1
530
+
531
+ "User Login": {
532
+ shape: person
533
+ style.fill: "#e6f7ff"
534
+ }
535
+
536
+ "Session Creation": {
537
+ shape: rectangle
538
+ style.fill: "#f6ffed"
539
+ }
540
+
541
+ "Session Storage": {
542
+ shape: cylinder
543
+ style.fill: "#fff7e6"
544
+ }
545
+
546
+ "Multi-Device Access": {
547
+ shape: package
548
+ grid-columns: 3
549
+ "Web Browser": {
550
+ shape: rectangle
551
+ }
552
+ "Mobile App": {
553
+ shape: rectangle
554
+ }
555
+ "Desktop App": {
556
+ shape: rectangle
557
+ }
558
+ }
559
+ "User Login" -> "Session Creation": "Authenticate"
560
+ "Session Creation" -> "Session Storage": "Store session"
561
+ "Session Storage" -> "Multi-Device Access": "Access from devices"
562
+ }
563
+ ```
564
+ - good:
565
+ ```d2
566
+ direction: down
567
+
568
+ "User Login": {
569
+ shape: person
570
+ style.fill: "#e6f7ff"
571
+ }
572
+
573
+ "Session Creation": {
574
+ shape: rectangle
575
+ style.fill: "#f6ffed"
576
+ }
577
+
578
+ "Session Storage": {
579
+ shape: cylinder
580
+ style.fill: "#fff7e6"
581
+ }
582
+
583
+ "Multi-Device Access": {
584
+ shape: package
585
+ grid-columns: 3
586
+ "Web Browser": {
587
+ shape: rectangle
588
+ }
589
+ "Mobile App": {
590
+ shape: rectangle
591
+ }
592
+ "Desktop App": {
593
+ shape: rectangle
594
+ }
595
+ }
596
+ "User Login" -> "Session Creation": "Authenticate"
597
+ "Session Creation" -> "Session Storage": "Store session"
598
+ "Session Storage" -> "Multi-Device Access": "Access from devices"
599
+ ```
600
+ - 某些情况下,单纯的设置 `direction: down` 还无法控制图表的整体方向,可以再结合 `grid-columns: 1` 来进行设置
601
+ - bad:
602
+ ```d2
603
+ direction: down
604
+
605
+ "Your Application": {
606
+ shape: rectangle
607
+ }
608
+
609
+ "@blocklet/js-sdk": {
610
+ shape: package
611
+ grid-columns: 1
612
+
613
+ "AuthService": {
614
+ shape: class
615
+ }
616
+ }
617
+
618
+ "Blocklet API Endpoints": {
619
+ shape: cylinder
620
+ grid-columns: 2
621
+ "/api/user/profile": {}
622
+ "/api/user/privacy/config": {}
623
+ "/api/user/notification/config": {}
624
+ "/api/user/logout": {}
625
+ "/api/user/follow/{did}": {}
626
+ "/api/user": {}
627
+ }
628
+
629
+ "Your Application" -> "@blocklet/js-sdk".AuthService: "e.g., sdk.auth.getProfile()"
630
+ "@blocklet/js-sdk".AuthService -> "Blocklet API Endpoints": "Makes authenticated API calls"
631
+ ```
632
+ - good:
633
+ ```d2
634
+ direction: down
635
+ grid-columns: 1
636
+
637
+ "Your Application": {
638
+ shape: rectangle
639
+ }
640
+
641
+ "@blocklet/js-sdk": {
642
+ shape: package
643
+ grid-columns: 1
644
+
645
+ "AuthService": {
646
+ shape: class
647
+ }
648
+ }
649
+
650
+ "Blocklet API Endpoints": {
651
+ shape: cylinder
652
+ grid-columns: 2
653
+ "/api/user/profile": {}
654
+ "/api/user/privacy/config": {}
655
+ "/api/user/notification/config": {}
656
+ "/api/user/logout": {}
657
+ "/api/user/follow/{did}": {}
658
+ "/api/user": {}
659
+ }
660
+
661
+ "Your Application" -> "@blocklet/js-sdk".AuthService: "e.g., sdk.auth.getProfile()"
662
+ "@blocklet/js-sdk".AuthService -> "Blocklet API Endpoints": "Makes authenticated API calls"
663
+ ```
664
+ - 当节点中子节点个数与 `grid-columns` 值相同时,则应该去掉 `grid-columns` 字段
665
+ - bad:
666
+ ```d2
667
+ "@blocklet/js-sdk": {
668
+ shape: package
669
+ grid-columns: 1
670
+
671
+ "AuthService": {
672
+ shape: class
673
+ }
674
+ }
675
+ ```
676
+ - good:
677
+ ```d2
678
+ "@blocklet/js-sdk": {
679
+ shape: package
680
+
681
+ "AuthService": {
682
+ shape: class
683
+ }
684
+ }
685
+ ```
686
+ - bad:
687
+ ```d2
688
+ "Browser Storage": {
689
+ shape: package
690
+ grid-columns: 2
691
+
692
+ "Cookies": {
693
+ shape: document
694
+ "Session Token": {}
695
+ }
696
+
697
+ "LocalStorage": {
698
+ shape: stored_data
699
+ "Refresh Token": {}
700
+ }
701
+ }
702
+ ```
703
+ - good:
704
+ ```d2
705
+ "Browser Storage": {
706
+ shape: package
707
+
708
+ "Cookies": {
709
+ shape: document
710
+ "Session Token": {}
711
+ }
712
+
713
+ "LocalStorage": {
714
+ shape: stored_data
715
+ "Refresh Token": {}
716
+ }
717
+ }
718
+ ```
719
+ - 当一个容器节点外部有节点与当前容器节点内部节点相互关联时,应该将这些节点放在同一层级
720
+ - bad:
721
+ ```d2
722
+ direction: down
723
+
724
+ "Federated Login Group": {
725
+ shape: package
726
+
727
+ "Master App": {
728
+ shape: rectangle
729
+ style.stroke: "#0052cc"
730
+ style.stroke-width: 2
731
+ "Provides central authentication"
732
+ }
733
+
734
+ "Member App 1 (Current App)": {
735
+ shape: rectangle
736
+ "User interacts here"
737
+ }
738
+
739
+ "Member App 2": {
740
+ shape: rectangle
741
+ }
742
+
743
+ "Master App" -> "Member App 1 (Current App)": "Shares user session"
744
+ "Master App" -> "Member App 2": "Shares user session"
745
+ }
746
+
747
+ User: {
748
+ shape: person
749
+ }
750
+
751
+ User -> "Member App 1 (Current App)": "Logs in via Master App"
752
+ ```
753
+ - good:
754
+ ```d2
755
+ direction: down
756
+
757
+ "Federated Login Group": {
758
+ shape: package
759
+
760
+ "Master App": {
761
+ shape: rectangle
762
+ style.stroke: "#0052cc"
763
+ style.stroke-width: 2
764
+ "Provides central authentication"
765
+ }
766
+
767
+ "Member App 1 (Current App)": {
768
+ shape: rectangle
769
+ "User interacts here"
770
+ }
771
+
772
+ "Member App 2": {
773
+ shape: rectangle
774
+ }
775
+
776
+ "Master App" -> "Member App 1 (Current App)": "Shares user session"
777
+ "Master App" -> "Member App 2": "Shares user session"
778
+
779
+ User: {
780
+ shape: person
781
+ }
782
+
783
+ User -> "Member App 1 (Current App)": "Logs in via Master App"
784
+ }
785
+
786
+ ```
787
+ - 当存在多层容器节点嵌套时,外层的容器节点应该使用 `grid-columns: 1`,这一点非常重要
788
+ - bad:
789
+ ```d2
790
+ direction: down
791
+
792
+ "User Account": {
793
+ shape: person
794
+ }
795
+
796
+ "Sessions": {
797
+ shape: package
798
+ grid-columns: 3
799
+
800
+ "Web Browser Session": {
801
+ shape: rectangle
802
+ "IP: 192.168.1.10"
803
+ "UA: Chrome on macOS"
804
+ "Status: online"
805
+ }
806
+
807
+ "iOS App Session": {
808
+ shape: rectangle
809
+ "IP: 10.0.0.5"
810
+ "UA: MyApp/1.2 iOS"
811
+ "Status: online"
812
+ }
813
+
814
+ "Old Laptop Session": {
815
+ shape: rectangle
816
+ "IP: 172.16.0.20"
817
+ "UA: Firefox on Windows"
818
+ "Status: expired"
819
+ }
820
+ }
821
+
822
+ "User Account" -> "Sessions": "Has multiple"
823
+ ```
824
+ - good:
825
+ ```d2
826
+ direction: down
827
+
828
+ "User Account": {
829
+ shape: person
830
+ }
831
+
832
+ "Sessions": {
833
+ shape: package
834
+ grid-columns: 1
835
+
836
+ "Web Browser Session": {
837
+ shape: rectangle
838
+ "IP: 192.168.1.10"
839
+ "UA: Chrome on macOS"
840
+ "Status: online"
841
+ }
842
+
843
+ "iOS App Session": {
844
+ shape: rectangle
845
+ "IP: 10.0.0.5"
846
+ "UA: MyApp/1.2 iOS"
847
+ "Status: online"
848
+ }
849
+
850
+ "Old Laptop Session": {
851
+ shape: rectangle
852
+ "IP: 172.16.0.20"
853
+ "UA: Firefox on Windows"
854
+ "Status: expired"
855
+ }
856
+ }
857
+
858
+ "User Account" -> "Sessions": "Has multiple"
859
+ ```
860
+ - 当一个节点容器中包含了其他的节点容器,建议使用 `grid-gap` 来增加各个节点容器的距离,尽量大于 100
861
+ - bad:
862
+ ```d2
863
+ direction: down
864
+
865
+ "Your Application": {
866
+ shape: rectangle
867
+ }
868
+
869
+ "SDK: @blocklet/js-sdk": {
870
+ shape: package
871
+ grid-columns: 1
872
+
873
+ "HTTP Clients": {
874
+ shape: rectangle
875
+ grid-columns: 2
876
+ "createAxios()": "Axios-based client"
877
+ "createFetch()": "Fetch-based client"
878
+ }
879
+
880
+ "Core Services": {
881
+ shape: rectangle
882
+ grid-columns: 3
883
+ "AuthService": "User & Auth"
884
+ "TokenService": "Token Management"
885
+ "UserSessionService": "Session Data"
886
+ "BlockletService": "Blocklet Metadata"
887
+ "FederatedService": "Federated Login"
888
+ }
889
+
890
+ "HTTP Clients" -> "Core Services".TokenService: "Uses for auth tokens"
891
+ }
892
+
893
+ "Blocklet Services": {
894
+ shape: cylinder
895
+ "Remote APIs"
896
+ }
897
+
898
+ "Your Application" -> "SDK: @blocklet/js-sdk": "Imports & Initializes"
899
+ "SDK: @blocklet/js-sdk" -> "Blocklet Services": "Makes authenticated requests"
900
+ ```
901
+ - bad:
902
+ ```d2
903
+ direction: down
904
+
905
+ "Your Application": {
906
+ shape: rectangle
907
+ }
908
+
909
+ "SDK: @blocklet/js-sdk": {
910
+ shape: package
911
+ grid-columns: 1
912
+ grid-gap: 100
913
+
914
+ "HTTP Clients": {
915
+ shape: rectangle
916
+ grid-columns: 2
917
+ "createAxios()": "Axios-based client"
918
+ "createFetch()": "Fetch-based client"
919
+ }
920
+
921
+ "Core Services": {
922
+ shape: rectangle
923
+ grid-columns: 3
924
+ "AuthService": "User & Auth"
925
+ "TokenService": "Token Management"
926
+ "UserSessionService": "Session Data"
927
+ "BlockletService": "Blocklet Metadata"
928
+ "FederatedService": "Federated Login"
929
+ }
930
+
931
+ "HTTP Clients" -> "Core Services".TokenService: "Uses for auth tokens"
932
+ }
933
+
934
+ "Blocklet Services": {
935
+ shape: cylinder
936
+ "Remote APIs"
937
+ }
938
+
939
+ "Your Application" -> "SDK: @blocklet/js-sdk": "Imports & Initializes"
940
+ "SDK: @blocklet/js-sdk" -> "Blocklet Services": "Makes authenticated requests"
941
+ ```
942
+ - 如果节点的 `shape: person`,则不要加任何其他内部的文字
943
+ - bad:
944
+ ```d2
945
+ "User Account": {
946
+ shape: person
947
+ "did:z... (John Doe)"
948
+ }
949
+ ```
950
+ - good:
951
+ ```d2
952
+ "User Account": {
953
+ shape: person
954
+ }
955
+ ```
956
+ - 示例参考:
957
+ {% include "diy-examples.md" %}
@@ -0,0 +1,182 @@
1
+ # D2 图表绘制 Shape 选择指南与 Prompt 模板
2
+
3
+ ## 一、D2 Shape 类型与使用场景
4
+
5
+ ### 基础 Shape 类型
6
+ - **rectangle** (默认): 通用节点、组件、系统模块
7
+ - **square**: 数据库、存储、配置项
8
+ - **circle**: 用户、角色、状态节点
9
+ - **oval**: 开始/结束节点、事件
10
+ - **diamond**: 决策节点、条件判断
11
+ - **parallelogram**: 输入/输出、数据流
12
+ - **hexagon**: 准备、预处理步骤
13
+ - **cylinder**: 数据库、数据存储
14
+ - **queue**: 消息队列、缓冲区
15
+ - **package**: 模块、包、容器
16
+ - **step**: 流程步骤
17
+ - **callout**: 注释、说明
18
+ - **stored_data**: 存储的数据
19
+ - **person**: 用户、角色
20
+ - **diamond**: 判断、网关
21
+ - **document**: 文档、报告
22
+ - **multiple_document**: 多个文档
23
+ - **class**: 类定义
24
+ - **sql_table**: 数据库表
25
+ - **image**: 图片、媒体
26
+
27
+ ## 二、针对不同图表类型的 Prompt 模板
28
+
29
+ ### 1. 系统架构图 Prompt
30
+ ```
31
+ 请使用 D2 语法绘制系统架构图,遵循以下 shape 选择规则:
32
+ - 用户/角色使用 person 或 circle
33
+ - 前端应用使用 rectangle
34
+ - API/服务使用 rectangle
35
+ - 数据库使用 cylinder 或 sql_table
36
+ - 缓存使用 queue
37
+ - 外部服务使用 package
38
+ - 负载均衡器使用 diamond
39
+
40
+ 示例结构:
41
+ 用户 -> 前端 -> API网关 -> 微服务 -> 数据库
42
+ ```
43
+
44
+ ### 2. 流程图 Prompt
45
+ ```
46
+ 请使用 D2 语法绘制流程图,严格按照以下 shape 约定:
47
+ - 开始/结束节点:oval
48
+ - 处理步骤:rectangle
49
+ - 判断节点:diamond
50
+ - 输入/输出:parallelogram
51
+ - 准备步骤:hexagon
52
+ - 文档生成:document
53
+ - 数据存储:cylinder
54
+
55
+ 连接线使用箭头表示流向,判断节点要标注 yes/no 分支。
56
+ ```
57
+
58
+ ### 3. 数据流图 Prompt
59
+ ```
60
+ 使用 D2 绘制数据流图,shape 选择原则:
61
+ - 外部实体:square
62
+ - 数据处理:circle
63
+ - 数据存储:stored_data 或 cylinder
64
+ - 数据流:带标签的箭头连接
65
+ - 数据文件:document
66
+
67
+ 确保数据流方向清晰,标注数据类型和流向。
68
+ ```
69
+
70
+ ### 4. 组织架构图 Prompt
71
+ ```
72
+ 创建组织架构图,使用以下 D2 shape 规范:
73
+ - 高层管理:person (设置较大尺寸)
74
+ - 部门负责人:person
75
+ - 团队/部门:package
76
+ - 具体角色:circle
77
+ - 外部合作方:rectangle (虚线边框)
78
+
79
+ 使用层次布局,体现汇报关系。
80
+ ```
81
+
82
+ ## 三、通用优化 Prompt 模板
83
+
84
+ ### 基础模板
85
+ ```
86
+ 请使用 D2 语法创建 [图表类型],要求:
87
+
88
+ 1. **Shape 选择原则**:
89
+ - 根据元素功能选择最合适的 shape
90
+ - 保持同类元素使用相同 shape
91
+ - 重要元素可以使用特殊 shape 突出
92
+
93
+ 2. **样式要求**:
94
+ - 使用合适的颜色区分不同类型的元素
95
+ - 重要路径使用加粗或特殊颜色
96
+ - 添加适当的标签和注释
97
+
98
+ 3. **布局优化**:
99
+ - 使用合理的布局算法 (dagre, elk等)
100
+ - 避免连线交叉
101
+ - 保持整体美观和可读性
102
+
103
+ 4. **语法规范**:
104
+ - 使用正确的 D2 语法
105
+ - 节点命名简洁明了
106
+ - 连接关系清晰表达
107
+
108
+ 请提供完整的 D2 代码。
109
+ ```
110
+
111
+ ### 高级定制模板
112
+ ```
113
+ 创建专业级 D2 图表,具体要求:
114
+
115
+ **图表信息**:[描述你要创建的图表]
116
+
117
+ **定制要求**:
118
+ 1. **Shape 策略**:
119
+ - 为每种元素类型指定最佳 shape
120
+ - 列出 shape 选择理由
121
+ - 确保视觉一致性
122
+
123
+ 2. **颜色方案**:
124
+ - 使用企业级配色
125
+ - 不同模块用不同颜色区分
126
+ - 突出关键路径
127
+
128
+ 3. **高级功能**:
129
+ - 添加图标 (如需要)
130
+ - 使用容器分组相关元素
131
+ - 添加交互提示 (tooltip)
132
+
133
+ 4. **性能考虑**:
134
+ - 节点数量控制在合理范围
135
+ - 避免过于复杂的嵌套
136
+
137
+ 输出格式:
138
+ - D2 代码
139
+ - Shape 选择说明
140
+ - 使用建议
141
+ ```
142
+
143
+ ## 四、特定场景 Prompt 示例
144
+
145
+ ### 网络拓扑图
146
+ ```
147
+ 绘制网络拓扑图,shape 使用规范:
148
+ - 路由器:diamond
149
+ - 交换机:rectangle
150
+ - 服务器:rectangle (填充色)
151
+ - 终端设备:circle
152
+ - 防火墙:hexagon
153
+ - 云服务:package
154
+ - 网络连接:实线
155
+ - 无线连接:虚线
156
+ ```
157
+
158
+ ### 微服务架构图
159
+ ```
160
+ 设计微服务架构图:
161
+ - API Gateway:diamond
162
+ - 微服务:rectangle
163
+ - 数据库:cylinder
164
+ - 缓存:queue
165
+ - 消息队列:queue (不同颜色)
166
+ - 负载均衡:parallelogram
167
+ - 监控服务:circle
168
+ - 外部服务:package (虚线边框)
169
+ ```
170
+
171
+ ### 业务流程图
172
+ ```
173
+ 业务流程建模:
174
+ - 开始事件:oval (绿色)
175
+ - 结束事件:oval (红色)
176
+ - 用户任务:rectangle
177
+ - 系统任务:rectangle (不同颜色)
178
+ - 网关决策:diamond
179
+ - 并行网关:diamond (特殊标记)
180
+ - 数据对象:document
181
+ - 消息流:虚线箭头
182
+ ```
@@ -15,7 +15,7 @@
15
15
  - 说明要尽可能的详细,如果存在配置项或参数,需要解释每个配置项或参数的含义,如果参数有多个可选值,每种可选值需要解释其含义,并尽可能配上代码示例
16
16
  - 参数优先使用 markdown 中的 table 来展示,让内容看上去更整齐,容易阅读
17
17
  - 接口/方法调用的说明必须包含 **响应数据示例**
18
- - 更多的使用 table、d2 图表来解释信息,过长的文本描述会让用户阅读有压力
18
+ - 尽可能少的使用 d2 图表,图表中错误的逻辑会导致文档效果更差,绘制 d2 的图表一定要确保可读性和正确性
19
19
  - 概览部分,建议包含 d2 图表展示产品架构图
20
20
  {% include "d2-chart/rules.md" %}
21
21
  - 对输出的 markdown 进行检查,确认输出内容完整,table、d2 信息完整并且格式正确
@@ -513,30 +513,10 @@ export const RESOLUTION_STRATEGIES = {
513
513
  export const D2_CONFIG = `vars: {
514
514
  d2-config: {
515
515
  layout-engine: elk
516
- theme-id: 0
516
+ theme-id: 300
517
517
  theme-overrides: {
518
- N1: "#2AA7A1"
519
- N2: "#73808C"
520
-
521
- N4: "#FFFFFF"
522
- N5: "#FAFBFC"
523
-
524
- N7: "#ffffff"
525
-
526
- B1: "#8EDDD9"
527
- B2: "#C9DCE6"
528
- B3: "#EEF9F9"
529
- B4: "#F7F8FA"
530
- B5: "#FCFDFD"
531
- B6: "#E3E9F0"
532
-
533
-
534
- AA2: "#9EB7C5"
535
- AA4: "#E3EBF2"
536
- AA5: "#F6FAFC"
537
-
538
- AB4: "#B8F1F6"
539
- AB5: "#E3F8FA"
518
+ AA4: "#90EFDF"
519
+ AA5: "#D2FFF7"
540
520
  }
541
521
  }
542
522
  }`;