@lark-apaas/coding-steering 0.1.43-alpha.20260831015213 → 0.1.43

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/package.json CHANGED
@@ -1,14 +1,11 @@
1
1
  {
2
2
  "name": "@lark-apaas/coding-steering",
3
- "version": "0.1.43-alpha.20260831015213",
3
+ "version": "0.1.43",
4
4
  "description": "Stack-specific steering content for miaoda-coding templates",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "steering"
8
8
  ],
9
- "scripts": {
10
- "lint:md": "markdownlint 'steering/**/*.md' --ignore 'steering/**/skills/**' --ignore 'steering/**/skills_common/**' --ignore 'steering/**/skills_local/**'"
11
- },
12
9
  "devDependencies": {
13
10
  "markdownlint-cli": "^0.47.0"
14
11
  },
@@ -20,5 +17,8 @@
20
17
  "miaoda",
21
18
  "coding-steering"
22
19
  ],
23
- "license": "MIT"
24
- }
20
+ "license": "MIT",
21
+ "scripts": {
22
+ "lint:md": "markdownlint 'steering/**/*.md' --ignore 'steering/**/skills/**' --ignore 'steering/**/skills_common/**' --ignore 'steering/**/skills_local/**'"
23
+ }
24
+ }
@@ -130,7 +130,7 @@ Read `<pack_dir>/design.md` first, especially `## Usage`, `## Hard Rules`, color
130
130
  When generating a deck:
131
131
 
132
132
  1. Call `copy_starter_component` with `kind: "deck-stage.js"`.
133
- 2. Build `<deck-stage width="<canvas width>" height="<canvas height>">` using the `canvas` declared in `layouts.md` — source decks are not always 16:9, and a default-sized stage shifts every coordinate on the page. Each slide is one static `<section data-pptx-layout="<chosen archetype>">`.
133
+ 2. Build `<deck-stage width="<canvas width>" height="<canvas height>">` using the `canvas` declared in `layouts.md` — source decks are not always 16:9, and a default-sized stage shifts every coordinate on the page. Each slide is one static `<section data-pptx-layout="<chosen archetype>">`. For a multi-theme pack, choose layouts compatible with `default-theme` by default. When a page intentionally switches theme, add `data-pptx-theme="<theme>"`; the theme must be listed by that layout's `themes`.
134
134
  3. Inline CSS variables from `design.md` into the HTML `<style>` block using a `--ppt-*` prefix.
135
135
  4. **位移动画用独立的 `translate` 属性**:`@keyframes fadeUp { from{opacity:0; translate:0 24px} to{opacity:1; translate:0 0} }`。`transform` 是单一属性,动画里碰它会覆盖掉元素原有的那条(`left:50%; transform:translateX(-50%)` 的居中就此丢失);`translate` / `rotate` / `scale` 各自独立,与已有 `transform` 叠加。
136
136
  5. Map `layouts.md` slots to absolute-positioned elements inside each section: expand `box: [x,y,w,h]` mechanically to `left/top/width/height`, then apply the slot's `css` declaration string unchanged. `box` owns geometry; `css` owns all rendering style, including the template's text padding, typography, alignment, line height, letter spacing, and rotation. Do not reinterpret PPTX fields or replace slot CSS with your own type scale. A slot with `asset` is a fixed image element: use that exact asset at that box on that archetype only; do not omit or replace it. Do not reflow any of this as generic web grids.
@@ -1243,7 +1243,21 @@ def layouts_from_template(d, shapes, cW, cH):
1243
1243
  sample_pages_of_layout = defaultdict(list)
1244
1244
  for slide_part, layout_part in lay_of_slide.items():
1245
1245
  sample_pages_of_layout[layout_part].append(slide_no(slide_part))
1246
+ sampled_theme_counts = Counter(
1247
+ theme_of_master.get(master_of.get(layout_part))
1248
+ for layout_part in lay_of_slide.values()
1249
+ )
1250
+ sampled_theme_counts.pop(None, None)
1246
1251
  default_theme = topo.get('default')
1252
+ if sampled_theme_counts:
1253
+ highest = max(sampled_theme_counts.values())
1254
+ leaders = sorted(
1255
+ theme for theme, count in sampled_theme_counts.items()
1256
+ if count == highest
1257
+ )
1258
+ if default_theme not in leaders:
1259
+ default_theme = leaders[0]
1260
+ topo['default'] = default_theme
1247
1261
  multi = len(topo.get('themes') or []) > 1
1248
1262
 
1249
1263
  rows = []
@@ -2394,7 +2408,9 @@ def emit_manifest(d, assets, vision_groups, ldir, archetypes=()):
2394
2408
  ' TODO: 一句话说清这套模板的视觉性格(底色 / 主色 / 字形 / 版面骨架),给消费模型定调。']
2395
2409
  themes = d['theme_topology'].get('themes') or ['single']
2396
2410
  if themes != ['single'] and len(themes) > 1:
2397
- L += ['themes: [%s]' % ', '.join(themes), 'default-theme: %s' % themes[0]]
2411
+ default_theme = d['theme_topology'].get('default') or themes[0]
2412
+ L += ['themes: [%s]' % ', '.join(themes),
2413
+ 'default-theme: %s' % default_theme]
2398
2414
  if assets:
2399
2415
  L.append('assets:')
2400
2416
  for a in assets:
@@ -2921,6 +2937,8 @@ def emit_layouts(archetypes, ldir, busy_hints=None, facts=None, recipes=None):
2921
2937
  L.append(' %s:' % a['name'])
2922
2938
  if a.get('role'):
2923
2939
  L.append(' role: %s' % a['role'])
2940
+ if a.get('theme'):
2941
+ L.append(' themes: [%s]' % a['theme'])
2924
2942
  if a['bg']:
2925
2943
  L.append(' background: %s' % a['bg'])
2926
2944
  fl = a.get('flow')
@@ -3056,6 +3074,8 @@ def emit_body(d, tokens, fonts, roles, assets, archetypes, exceptions, cusage, l
3056
3074
  '页数多于页型时,挑最接近的一个原样套用它的 slot:用不到的槽删掉,'
3057
3075
  '内容比槽多就按同类槽的间距等距加,**坐标一律沿用该页型给的那套,不要自己另起网格**。'
3058
3076
  '每个生成页面的 `<section>` 都写 `data-pptx-layout="<页型名>"`,'
3077
+ '多主题包默认只选兼容 `default-theme` 的页型;确需切换时,该页同时写 '
3078
+ '`data-pptx-theme="<主题名>"`,且主题必须属于该页型的 `themes`。'
3059
3079
  '交付前据此核验该页型绑定的背景与图片资产均已使用,且没有跨页型误用。' % sidecar,
3060
3080
  '3. **按页型给的形态落元素** —— 页型给 `flow` 就用流式,给 `slots` 就用绝对,'
3061
3081
  '两者只会出现一个。'
@@ -15,6 +15,7 @@ from draft import (asset_vision_contexts, bound_visual_candidates, # noqa: E402
15
15
  cover_background_media,
16
16
  emit_asset_vision_groups, emit_layouts, emit_manifest,
17
17
  fullscreen_overlay_media,
18
+ layouts_from_template,
18
19
  needs_asset_judgment, preserve_image_bearing_groups,
19
20
  select_asset_vision_groups, slide_image_marks, slot_style,
20
21
  visual_slot_candidates)
@@ -24,6 +25,125 @@ from package import (FONTSIZE_RE, Fail, apply_asset_decisions, # noqa: E402
24
25
 
25
26
 
26
27
  class LayoutCssTest(unittest.TestCase):
28
+ def test_template_layouts_use_sampled_theme_as_default_and_keep_theme_scope(self):
29
+ dark_master = 'ppt/slideMasters/slideMaster1.xml'
30
+ light_master = 'ppt/slideMasters/slideMaster2.xml'
31
+ dark_layout = 'ppt/slideLayouts/slideLayout1.xml'
32
+ light_layout = 'ppt/slideLayouts/slideLayout2.xml'
33
+ data = {
34
+ 'layouts': [
35
+ {'part': dark_layout, 'name': 'Dark content', 'used_by_slides': 2},
36
+ {'part': light_layout, 'name': 'Light content', 'used_by_slides': 0},
37
+ ],
38
+ 'slides': [],
39
+ 'theme_topology': {
40
+ 'themes': ['light', 'dark'],
41
+ 'default': 'light',
42
+ 'per_master': [
43
+ {'master': dark_master, 'theme_label': 'dark'},
44
+ {'master': light_master, 'theme_label': 'light'},
45
+ ],
46
+ },
47
+ 'reference_graph': {
48
+ 'master_of_layout': {
49
+ dark_layout: dark_master,
50
+ light_layout: light_master,
51
+ },
52
+ 'layout_of_slide': {
53
+ 'ppt/slides/slide1.xml': dark_layout,
54
+ 'ppt/slides/slide2.xml': dark_layout,
55
+ },
56
+ },
57
+ 'background_composites': {},
58
+ }
59
+ shapes = [
60
+ {
61
+ 'part': part,
62
+ 'layer': 'layout',
63
+ 'kind': 'sp',
64
+ 'box': {'x': 100, 'y': 100, 'w': 800, 'h': 100},
65
+ 'ph': {'type': 'title', 'idx': '1'},
66
+ 'text': {'paragraphs': [{'runs': [{'text': 'Title', 'sz_px': 40}]}]},
67
+ }
68
+ for part in (dark_layout, light_layout)
69
+ ]
70
+
71
+ archetypes = layouts_from_template(data, shapes, 1920, 1080)
72
+
73
+ self.assertEqual('dark', data['theme_topology']['default'])
74
+ self.assertEqual(
75
+ {'content': 'dark', 'content-2': 'light'},
76
+ {item['name']: item['theme'] for item in archetypes},
77
+ )
78
+ with tempfile.TemporaryDirectory() as output_dir:
79
+ emit_layouts(archetypes, output_dir)
80
+ emit_manifest(data, [], [], output_dir, archetypes)
81
+ with open(os.path.join(output_dir, 'layouts.yaml'), encoding='utf-8') as stream:
82
+ layouts = stream.read()
83
+ with open(os.path.join(output_dir, 'manifest.yaml'), encoding='utf-8') as stream:
84
+ manifest = stream.read()
85
+ self.assertIn(' themes: [dark]', layouts)
86
+ self.assertIn(' themes: [light]', layouts)
87
+ self.assertIn('default-theme: dark', manifest)
88
+
89
+ def test_template_twin_layouts_keep_topology_but_scope_retained_layout(self):
90
+ dark_master = 'ppt/slideMasters/slideMaster1.xml'
91
+ light_master = 'ppt/slideMasters/slideMaster2.xml'
92
+ dark_layout = 'ppt/slideLayouts/slideLayout1.xml'
93
+ light_layout = 'ppt/slideLayouts/slideLayout2.xml'
94
+ data = {
95
+ 'layouts': [
96
+ {'part': dark_layout, 'name': 'Content', 'used_by_slides': 2},
97
+ {'part': light_layout, 'name': 'Content', 'used_by_slides': 0},
98
+ ],
99
+ 'slides': [],
100
+ 'theme_topology': {
101
+ 'themes': ['light', 'dark'],
102
+ 'default': 'light',
103
+ 'per_master': [
104
+ {'master': dark_master, 'theme_label': 'dark'},
105
+ {'master': light_master, 'theme_label': 'light'},
106
+ ],
107
+ },
108
+ 'reference_graph': {
109
+ 'master_of_layout': {
110
+ dark_layout: dark_master,
111
+ light_layout: light_master,
112
+ },
113
+ 'layout_of_slide': {
114
+ 'ppt/slides/slide1.xml': dark_layout,
115
+ 'ppt/slides/slide2.xml': dark_layout,
116
+ },
117
+ },
118
+ 'background_composites': {},
119
+ }
120
+ shapes = [
121
+ {
122
+ 'part': part,
123
+ 'layer': 'layout',
124
+ 'kind': 'sp',
125
+ 'box': {'x': 100, 'y': 100, 'w': 800, 'h': 100},
126
+ 'ph': {'type': 'title', 'idx': '1'},
127
+ 'text': {'paragraphs': [{'runs': [{'text': 'Title', 'sz_px': 40}]}]},
128
+ }
129
+ for part in (dark_layout, light_layout)
130
+ ]
131
+
132
+ archetypes = layouts_from_template(data, shapes, 1920, 1080)
133
+
134
+ self.assertEqual(1, len(archetypes))
135
+ self.assertEqual('dark', archetypes[0]['theme'])
136
+ with tempfile.TemporaryDirectory() as output_dir:
137
+ emit_layouts(archetypes, output_dir)
138
+ emit_manifest(data, [], [], output_dir, archetypes)
139
+ with open(os.path.join(output_dir, 'layouts.yaml'), encoding='utf-8') as stream:
140
+ layouts = stream.read()
141
+ with open(os.path.join(output_dir, 'manifest.yaml'), encoding='utf-8') as stream:
142
+ manifest = stream.read()
143
+ self.assertIn(' themes: [dark]', layouts)
144
+ self.assertIn('themes: [light, dark]', manifest)
145
+ self.assertIn('default-theme: dark', manifest)
146
+
27
147
  def test_text_slot_emits_rendering_style_as_css_only(self):
28
148
  shape = {
29
149
  'text': {
@@ -128,6 +128,31 @@ class LayoutAssetContractTest(unittest.TestCase):
128
128
  '---\n'
129
129
  )
130
130
 
131
+ def write_theme_pack(self, root):
132
+ with open(os.path.join(root, 'design.md'), 'w', encoding='utf-8') as stream:
133
+ stream.write(
134
+ '---\n'
135
+ 'themes: [dark, light]\n'
136
+ 'default-theme: dark\n'
137
+ 'layouts: layouts.md\n'
138
+ '---\n'
139
+ )
140
+ with open(os.path.join(root, 'layouts.md'), 'w', encoding='utf-8') as stream:
141
+ stream.write(
142
+ '---\n'
143
+ 'canvas: 1920x1080\n'
144
+ 'layouts:\n'
145
+ ' dark-content:\n'
146
+ ' role: content\n'
147
+ ' themes: [dark]\n'
148
+ ' slots: []\n'
149
+ ' light-content:\n'
150
+ ' role: content\n'
151
+ ' themes: [light]\n'
152
+ ' slots: []\n'
153
+ '---\n'
154
+ )
155
+
131
156
  def test_logo_is_limited_to_every_archetype_with_its_slot(self):
132
157
  with tempfile.TemporaryDirectory() as root:
133
158
  self.write_pack(root)
@@ -200,6 +225,102 @@ class LayoutAssetContractTest(unittest.TestCase):
200
225
  validate_layout_assets(root, html, 'assets/pptx-volcengine'),
201
226
  )
202
227
 
228
+ def test_missing_deck_slides_is_rejected_even_without_fixed_assets(self):
229
+ with tempfile.TemporaryDirectory() as root:
230
+ self.write_theme_pack(root)
231
+ html = self.write_html(root, '<main><section>普通页面</section></main>')
232
+
233
+ self.assertEqual(
234
+ ['没有识别到 deck-stage 的直属 slide section,无法核验模板页型'],
235
+ validate_layout_assets(root, html, 'assets/pptx-theme'),
236
+ )
237
+
238
+ def test_layout_outside_default_theme_requires_explicit_theme(self):
239
+ with tempfile.TemporaryDirectory() as root:
240
+ self.write_theme_pack(root)
241
+ html = self.write_html(
242
+ root,
243
+ '<deck-stage>'
244
+ '<section data-pptx-layout="light-content">正文</section>'
245
+ '</deck-stage>',
246
+ )
247
+
248
+ self.assertEqual(
249
+ ['第 1 页页型 light-content 不支持当前主题 dark;'
250
+ '允许主题: light。若确需切换,显式声明 data-pptx-theme'],
251
+ validate_layout_assets(root, html, 'assets/pptx-theme'),
252
+ )
253
+
254
+ def test_explicit_non_default_theme_must_match_layout(self):
255
+ with tempfile.TemporaryDirectory() as root:
256
+ self.write_theme_pack(root)
257
+ html = self.write_html(
258
+ root,
259
+ '<deck-stage>'
260
+ '<section data-pptx-layout="light-content" '
261
+ 'data-pptx-theme="light">正文</section>'
262
+ '</deck-stage>',
263
+ )
264
+
265
+ self.assertEqual(
266
+ [],
267
+ validate_layout_assets(root, html, 'assets/pptx-theme'),
268
+ )
269
+
270
+ def test_unknown_explicit_theme_is_rejected(self):
271
+ with tempfile.TemporaryDirectory() as root:
272
+ self.write_theme_pack(root)
273
+ html = self.write_html(
274
+ root,
275
+ '<deck-stage>'
276
+ '<section data-pptx-layout="dark-content" '
277
+ 'data-pptx-theme="brand-new">正文</section>'
278
+ '</deck-stage>',
279
+ )
280
+
281
+ self.assertEqual(
282
+ ['第 1 页声明了不存在的模板主题: brand-new'],
283
+ validate_layout_assets(root, html, 'assets/pptx-theme'),
284
+ )
285
+
286
+ def test_pack_without_fixed_assets_still_accepts_valid_layout(self):
287
+ with tempfile.TemporaryDirectory() as root:
288
+ self.write_theme_pack(root)
289
+ html = self.write_html(
290
+ root,
291
+ '<deck-stage>'
292
+ '<section data-pptx-layout="dark-content">正文</section>'
293
+ '</deck-stage>',
294
+ )
295
+
296
+ self.assertEqual(
297
+ [],
298
+ validate_layout_assets(root, html, 'assets/pptx-theme'),
299
+ )
300
+
301
+ def test_non_mapping_layout_entry_does_not_crash_theme_validation(self):
302
+ with tempfile.TemporaryDirectory() as root:
303
+ self.write_theme_pack(root)
304
+ with open(os.path.join(root, 'layouts.md'), 'w', encoding='utf-8') as stream:
305
+ stream.write(
306
+ '---\n'
307
+ 'canvas: 1920x1080\n'
308
+ 'layouts:\n'
309
+ ' malformed: unavailable\n'
310
+ '---\n'
311
+ )
312
+ html = self.write_html(
313
+ root,
314
+ '<deck-stage>'
315
+ '<section data-pptx-layout="malformed">正文</section>'
316
+ '</deck-stage>',
317
+ )
318
+
319
+ self.assertEqual(
320
+ [],
321
+ validate_layout_assets(root, html, 'assets/pptx-theme'),
322
+ )
323
+
203
324
  def test_logo_in_global_css_is_rejected(self):
204
325
  with tempfile.TemporaryDirectory() as root:
205
326
  self.write_pack(root)
@@ -207,6 +207,7 @@ class SlideAssetParser(HTMLParser):
207
207
  tag == 'section' and parent and parent['tag'] == 'deck-stage')
208
208
  slide = ({
209
209
  'layout': attrs_map.get('data-pptx-layout'),
210
+ 'theme': attrs_map.get('data-pptx-theme'),
210
211
  'references': [],
211
212
  } if slide_root else parent_slide)
212
213
  if slide_root:
@@ -270,8 +271,6 @@ def validate_layout_assets(pack_dir, html_path, asset_prefix):
270
271
  pack = Pack(pack_dir)
271
272
  owners = layout_asset_contract(pack)
272
273
  known_urls = asset_urls(pack, asset_prefix, owners)
273
- if not known_urls:
274
- return []
275
274
  asset_urls_by_id = {
276
275
  asset_id: url
277
276
  for url, asset_ids in known_urls.items()
@@ -285,6 +284,10 @@ def validate_layout_assets(pack_dir, html_path, asset_prefix):
285
284
  parser.close()
286
285
 
287
286
  problems = copied_asset_problems(pack, html_path, asset_prefix, owners)
287
+ if not parser.slides:
288
+ problems.append(
289
+ '没有识别到 deck-stage 的直属 slide section,无法核验模板页型')
290
+ return problems
288
291
  for url in parser.outside_urls:
289
292
  for asset_id in sorted(known_urls.get(normalized_path(url), ())):
290
293
  problems.append(
@@ -297,8 +300,26 @@ def validate_layout_assets(pack_dir, html_path, asset_prefix):
297
300
  if layout not in pack.layouts:
298
301
  problems.append('第 %d 页声明了不存在的模板页型: %s' % (number, layout))
299
302
  continue
303
+ layout_entry = pack.layouts[layout][0]
304
+ explicit_theme = slide['theme']
305
+ default_theme = pack.design.data.get('default-theme')
306
+ active_theme = explicit_theme or default_theme
307
+ if explicit_theme and explicit_theme not in pack.themes:
308
+ problems.append(
309
+ '第 %d 页声明了不存在的模板主题: %s' % (number, explicit_theme))
310
+ continue
311
+ layout_themes = (
312
+ (layout_entry.get('themes') or [])
313
+ if isinstance(layout_entry, dict) else []
314
+ )
315
+ if active_theme and layout_themes and active_theme not in layout_themes:
316
+ problems.append(
317
+ '第 %d 页页型 %s 不支持当前主题 %s;允许主题: %s。'
318
+ '若确需切换,显式声明 data-pptx-theme'
319
+ % (number, layout, active_theme, '、'.join(layout_themes)))
320
+ continue
300
321
  expected = layout_asset_instances(
301
- pack.layouts[layout][0], set(pack.assets), pack.canvas)
322
+ layout_entry, set(pack.assets), pack.canvas)
302
323
  actual = []
303
324
  for reference in slide['references']:
304
325
  referenced_ids = set()
@@ -71,6 +71,7 @@ available-agents:
71
71
  | 实时多人编辑、毫秒级协同 | 弱实时刷新、提交后同步 |
72
72
  | 原生 App、桌面端、浏览器插件 | Web 应用、响应式页面 |
73
73
  | 服务端持久写本地文件 | 平台文件服务、数据库、临时 `/tmp` |
74
+ | 服务启动时下载大文件、全量同步或批量迁移 | 采用异步处理,避免阻塞服务启动 |
74
75
  | 无凭证调用受限第三方系统 | 要求用户提供 API、凭证或授权方式 |
75
76
  | 自建账号体系绕过平台登录 | 使用平台内置身份与权限 |
76
77
  | 多语言 i18n、深浅色主题切换(非平台内置) | 需自行实现并计入工作量;规格中先确认是否必要 |
@@ -155,7 +155,7 @@ shared/ # 前后端共享的目录
155
155
 
156
156
  ## 依赖使用规范
157
157
 
158
- 1. **子包完整性检查**:部分库有多个子包(如 `@radix-ui/react-*` 系列每个组件都是独立子包),添加 import 后必须确认 package.json 中包含所有需要的子包
158
+ 1. **子包完整性检查**:部分库有多个子包(如 `@dnd-kit/core` + `@dnd-kit/sortable` + `@dnd-kit/utilities`),添加 import 后必须确认 package.json 中包含所有需要的子包
159
159
  2. 用法不清时查看 readme,可进一步搜索或网页访问获取信息
160
160
 
161
161
  ## 文件命名约定
@@ -232,8 +232,9 @@ shared/ # 前后端共享的目录
232
232
  - **三方集成**:调用第三方 API 需在后端实现,使用 @nestjs/axios
233
233
  - **能力边界**:服务端不支持文件上传(FaaS 限制),前端用 dataloom SDK 上传,服务端仅保存元信息
234
234
  - **环境判断**:`process.env.NODE_ENV === "production"` 表示生产环境
235
- - **文件系统**:**严禁使用 `fs` 写入非 `/tmp` 路径**(无状态 FaaS 容器)
235
+ - **文件系统**:临时文件、下载内容和处理中间产物统一写入 `/tmp` 下的独立目录,用完后清理
236
236
  - **服务端运行时资源文件**(字体 / 证书 / 模板 / wasm 等需在运行时读取的非代码文件,CRITICAL — 发布后静默失效根因):① 必须在 `nest-cli.json` 的 `assets` 中声明(如 `{"include": "assets/<dir>/**/*", "outDir": "dist/server"}`),否则不会进 `dist/` 构建产物;② 路径用 `__dirname` 相对**编译产物**定位(如 `path.join(__dirname, "../assets/...")`),**禁止 `process.cwd()` 相对源码路径**——dev 跑源码能命中、发布跑 `dist/` 会落空;③ 资源缺失或加载失败必须 **fail-loud**(抛错或明确错误日志),禁止 `catch` 后静默返回残缺产物
237
+ - **启动生命周期**:`constructor`、`onModuleInit` 和 `onApplicationBootstrap` 应快速完成,避免在其中下载大文件、全量同步或批量迁移;仅将钩子声明为 `async` 仍会被等待,无法缩短启动时间
237
238
 
238
239
  ## 日志约定
239
240
 
@@ -569,8 +570,6 @@ async createArticle(@Req() req: Request, @Body() dto: CreateArticleDto) {
569
570
  {% if projectMeta['flags']['supportTiptapAndStreamdown'] %}
570
571
  - **富文本**: `business-ui/tiptap-editor`(阅读 README.md)
571
572
  - **Markdown 渲染**: `components/ui/streamdown`(内置 prose 排版)
572
- {% else %}
573
- - **Markdown 渲染**: `components/ui/markdown`(react-markdown + remark-gfm,内置 prose 排版)
574
573
  {% endif %}
575
574
 
576
575
  ## API 请求
@@ -608,8 +607,6 @@ import { axiosForBackend } from '@lark-apaas/client-toolkit/utils/getAxiosForBac
608
607
  {% if projectMeta['flags']['supportTiptapAndStreamdown'] %}
609
608
  | TiptapEditorComplete | `business-ui/tiptap-editor` | 富文本编辑器 |
610
609
  | Streamdown | `components/ui/streamdown` | Markdown/流式渲染 |
611
- {% else %}
612
- | Markdown | `components/ui/markdown` | Markdown 渲染(react-markdown + remark-gfm) |
613
610
  {% endif %}
614
611
 
615
612
  ### 组件 Skill 召回规则(强制执行)
@@ -773,12 +770,15 @@ return <h1>{data?.title || '未知标题'}</h1>;
773
770
  | 验证 | zod |
774
771
  | 工具函数 | lodash |
775
772
  | 样式 | clsx |
776
- | 文件上传 | 原生 `<input type="file">`,用 shadcn 组件封装样式 |
773
+ | Excel | xlsx(**仅前端实现,禁止服务端实现**。解析后将结构化数据传到服务端保存) |
774
+ | PDF 导出 | jspdf + html2canvas(**仅前端实现,禁止服务端实现**) |
775
+ | 文件上传 | react-dropzone |
776
+ | 二维码 | qrcode.react |
777
777
  | 用户反馈 | sonner |
778
- | 数字动画 | `requestAnimationFrame` 手写,或 framer-motion 的 `animate` |
779
- | Base64 | 原生 `atob`/`btoa`(Unicode 内容先经 `TextEncoder`/`TextDecoder`);服务端用 `Buffer` |
780
-
781
- > Excel 解析、PDF 导出、二维码、拖拽、3D 场景等能力已随依赖瘦身不再预装(xlsx、jspdf、html2canvas、qrcode.react、@dnd-kit、react-dropzone、react-countup、js-base64、cobe 已从模板移除)。确有此类需求时,先在 package.json 显式添加所需依赖并安装,再编写代码。
778
+ | 拖拽 | @dnd-kit/core |
779
+ | 数字动画 | react-countup |
780
+ | Base64 | js-base64 — `import { encode, decode } from 'js-base64'` |
781
+ | 3D 场景 | cobe |
782
782
 
783
783
  ## 滚动分页最佳实践
784
784
 
@@ -20,6 +20,7 @@ gate-tools:
20
20
  | 获取运行时投影 | 调用 `get_plugin_ai_json(pluginInstanceId)` |
21
21
  | Client 侧调用 | `capabilityClient.load(id).call(actionKey, input)`(流式用 `callStream`) |
22
22
  | Server 侧调用(仅兜底) | `capabilityService.load(id).call(actionKey, input)` |
23
+ | 长耗时 AI 结果 | 大体量/多字段/多份/多语言/文件或多模态串联等结构信号命中时,优先前端 `callStream` 渐进展示;需保存则流式结束后复用 CRUD 落库;仅在 Client 侧无法满足时使用后端任务记录 + 状态查询 + 结果读取;禁止单个 HTTP 请求等待完整结果后才返回 |
23
24
  | capabilityClient 导入 | `import { capabilityClient } from '@lark-apaas/client-toolkit'` |
24
25
  | CapabilityService 导入 | `import { CapabilityService } from '@lark-apaas/fullstack-nestjs-core';` |
25
26
 
@@ -70,6 +71,7 @@ gate-tools:
70
71
  - 必须先调 `get_plugin_ai_json(pluginInstanceId)`,再产出 **Schema 摘录卡**(格式见 `references/plugin-coding-guide.md`);摘录卡字段缺失禁止编码,`output.fields` 必须完整列出且每个输出字段在代码中被消费(持久化或展示)
71
72
  - 按 `actions[].key` 选 actionKey;严格按 `inputSchema` 构造入参(`type: array` 字段必须传数组)、按 `outputSchema` 解析出参——流式 chunk 是**对象**(按字段解构如 `chunk.content`,禁止当字符串拼接),非流式同理按字段名读取;**务必阅读并遵循 `readme`**
72
73
  - 调用侧:优先 Client(`unary` → `call()`,`stream` → `callStream()`);触发器/定时任务、敏感凭证、强事务、结果需落库 → Server 侧
74
+ - 高耗时 AI capability 闸门:若运行时投影或功能设计显示输出规模大、输出字段多、需要多份结果、多语言/长文本、文件或多模态输入后继续生成、多个 capability 串联、或结果需后续查看/落库,禁止把完整生成放进一个同步 HTTP 请求等待;能由前端承接时优先 `callStream` 渐进展示,需保存则流式结束后复用 CRUD 落库;仅在 Client 侧无法满足时后端创建任务记录后快速返回、由前端短轮询状态/结果,或拆成多个独立小调用
73
75
  4. **代码放置**:Client(默认,用户交互触发)→ `client/` 组件/hooks;Server(兜底)→ `server/` Service。
74
76
  5. **真实调用冒烟(完成前必须)**:至少成功调用一次 `call()` 或 `callStream()`(按 outputSchema 读 chunk);失败日志含最小字段(字段清单见 `references/plugin-coding-guide.md`)。无冒烟结果不得宣告完成。
75
77
 
@@ -136,6 +138,9 @@ const structured = await capabilityClient
136
138
  ├── 输出包含多个独立字段(标题+正文+评分等)
137
139
  │ → 拆成多个独立插件并行调用(⭐ 优先)或用 ai-text-to-json
138
140
  │ → ⛔ 禁止用 ai-text-generate + 正则/split 解析多字段
141
+ ├── 输出规模大(多份结果、多语言、长正文、多章节或批量对象)
142
+ │ → 优先拆分为多个独立生成单元;需要汇总持久化时使用任务状态模型承接
143
+ │ → ⛔ 禁止一个后端 HTTP 请求同步等待所有生成结果后才响应
139
144
  └── 输出为单一文本(仅展示,不需解析)→ ai-text-generate
140
145
  ```
141
146
 
@@ -203,9 +208,9 @@ const structured = await capabilityClient
203
208
 
204
209
  1. **禁止静默吞异常**:每个 `catch` 至少满足其一——向用户展示错误(toast/页面状态),或触发补偿机制(重试/降级/记录待处理列表)
205
210
  2. **异步操作必须有终态**:不阻塞主流程的插件调用须在 DB 维护状态(pending → success/failed),前端必须展示 failed,不能永远 loading
206
- 3. **通知类插件失败必须有补偿**:如 `send-feishu-message` 失败,至少记录"待发送"列表或 UI 提示"通知发送失败,请手动联系"
207
- 4. **配置完整性(load 前必查)**:`load(id)` 前确认实例已创建且 id 与代码完全匹配,否则抛 `CapabilityNotFoundError`(开发态 Top 错误);load/call 失败时停止后续请求避免放大错误;**缓存 load 结果**,同一 id 不重复 load
208
- 5. **线上/客户反馈的插件问题先查 runtime log 取证**:用户反馈「线上 / 已发布」的插件问题(飞书消息发不出 / 插件不生效 / capability 调用「用户收不到」)时,**先查线上 runtime log 再定位代码**——用 `miaoda observability log`(必要时 `trace`)看 CapabilityService 真实错误、plugin_key、action、必填参数/输入校验错误,拿到线上 ERROR/WARN 再读代码修复。**即使你已在代码里读到一个疑似原因,也不得据此直接下根因、跳过取证**——静态代码里的可疑点常不是运行时真正的失败点(线上真错误多为运行时入参为空 / 校验失败 / 授权态问题,代码静态看不出),runtime log 是这类问题下结论前的必经步。沙箱 `read_logs` 只覆盖 dev 态,**不能**作为「线上插件无错误」的证据;纯本地 dev 态插件报错仍用 `read_logs`
211
+ 3. **长耗时 AI 生成不得同步等完**:大体量、多字段、多份、多语言、文件/多模态串联或需要持久化的 AI capability 调用,触发接口必须快速返回任务状态或采用前端流式展示;若 `api_request`、浏览器操作或页面请求出现超时/连接断开,不能只凭服务端最终日志或数据库最终写入宣告成功,必须证明用户侧存在可读取的终态结果
212
+ 4. **通知类插件失败必须有补偿**:如 `send-feishu-message` 失败,至少记录"待发送"列表或 UI 提示"通知发送失败,请手动联系"
213
+ 5. **配置完整性(load 前必查)**:`load(id)` 前确认实例已创建且 id 与代码完全匹配,否则抛 `CapabilityNotFoundError`(开发态 Top 错误);load/call 失败时停止后续请求避免放大错误;**缓存 load 结果**,同一 id 不重复 load
209
214
 
210
215
  ## 缓存与幂等性
211
216
 
@@ -240,7 +245,7 @@ const structured = await capabilityClient
240
245
 
241
246
  ### 通知接收人动态解析
242
247
 
243
- 接收人(`receiverUserList`/`receiverGroupList` 等)按角色/条件变化时,必须实时查询角色成员经 `input` 传入(角色/成员的运行时查询写法见 `authz-guide` 技能),禁止硬编码或凭经验拼装 ID。如引入缓存,必须提供显式失效手段(如角色变更时清缓存)并明示 TTL,禁止无失效手段的常驻缓存导致接收人信息过期。通知发送失败的补偿要求见上文「插件调用错误处理」第 3 条铁律,不重复展开。
248
+ 接收人(`receiverUserList`/`receiverGroupList` 等)按角色/条件变化时,必须实时查询角色成员经 `input` 传入(角色/成员的运行时查询写法见 `authz-guide` 技能),禁止硬编码或凭经验拼装 ID。如引入缓存,必须提供显式失效手段(如角色变更时清缓存)并明示 TTL,禁止无失效手段的常驻缓存导致接收人信息过期。通知发送失败的补偿要求见上文「插件调用错误处理」第 4 条铁律,不重复展开。
244
249
 
245
250
  ## 飞书深链 URL 规范
246
251
 
@@ -2,15 +2,19 @@
2
2
 
3
3
  ### 核心原则:根据场景选择调用侧
4
4
 
5
- **默认优先在 Client 侧调用 capabilityClient;但当插件结果需要持久化到数据库时,应考虑在 Server 侧调用或确保前端调用后及时通过后端接口保存。**
5
+ **默认优先在 Client 侧调用 capabilityClient;流式或高耗时 AI 生成优先 `callStream` 渐进展示。结果需要持久化时,优先在流式结束后通过已有后端接口保存;只有 Client 侧无法满足时才切到 Server 侧。**
6
+
7
+ **高耗时 AI capability 先判调用形态**:只要输出规模大、输出字段多、需要多份结果、多语言/长文本、文件或多模态输入后继续生成、多个 capability 串联、或结果需后续查看/落库,就不得把完整 AI 结果塞进一个同步 HTTP 请求等待。能由前端承接时,优先用前端 `callStream` 渐进展示,并在流式结束后按需复用已有 CRUD 接口保存结果;只有 Client 侧无法满足(触发器/敏感凭证/强事务/必须由后端保证落库一致性等)时,才采用后端任务记录 + 状态/结果查询,避免把后台任务作为默认方案。
8
+
6
9
  **严禁** import { capabilityClient } from '@lark-apaas/client-capability'。
7
10
  **唯一指定**的导入方式是 import { capabilityClient } from '@lark-apaas/client-toolkit';
8
11
 
9
12
  | 优先级 | 场景 | 调用方式 |
10
13
  |-------|------|---------|
11
- | **首选** | 绝大多数场景 | `capabilityClient.load(id).call()` |
12
- | **首选** | 流式输出场景 | `capabilityClient.load(id).callStream()` |
13
- | **兜底** | Client 侧无法满足时 | `CapabilityService.load(id).call()` |
14
+ | **首选** | 绝大多数即时展示场景 | `capabilityClient.load(id).call()` |
15
+ | **首选** | 流式输出,或高耗时但可由前端承接的 AI 生成 | `capabilityClient.load(id).callStream()`(流式结束后按需持久化) |
16
+ | **必要时** | 高耗时且 Client 侧无法满足:触发器、敏感凭证、强事务、必须由后端保证落库一致性 | 后端任务记录 + 后台调用 `CapabilityService.load(id).call()` + 前端短轮询状态/结果 |
17
+ | **兜底** | Client 侧无法满足且单次调用可在交互边界内完成 | `CapabilityService.load(id).call()` |
14
18
 
15
19
  #### 什么情况下应使用 Server 侧?
16
20
 
@@ -19,7 +23,7 @@
19
23
  1. **涉及敏感凭证**:调用需要服务端私密 token/secret,不适合暴露给前端
20
24
  2. **必须后端编排**:多个插件调用之间有强事务依赖,需要后端统一编排
21
25
  3. **触发器/定时任务场景**:没有前端上下文,只能由后端发起
22
- 4. **插件结果需要持久化**:调用结果需要保存到数据库,在 Server 侧可以在同一方法中完成调用+落库,保证数据一致性
26
+ 4. **插件结果需要持久化**:调用结果需要保存到数据库;能由前端承接时,优先前端 `callStream` 渐进展示并在结束后复用已有 CRUD 接口保存;只有 Client 侧无法满足或必须由后端保证落库一致性时,才在 Server 侧调用并落库。若此时输出规模大、字段多、结果多份或需多步能力串联,必须改为任务记录 + 后台执行 + 状态/结果查询,避免一个 HTTP 请求等待完整生成
23
27
 
24
28
  > **提示**:如果插件结果不需要存储、仅用于即时展示(如流式生成文本、发送消息),优先在前端调用。但当结果需要保存到数据库时,不要回避使用 Server 侧。
25
29
 
@@ -42,9 +46,13 @@
42
46
 
43
47
  ```
44
48
  插件结果是否需要持久化到数据库?
45
- ├── 否(一次性即时展示)→ Client 侧调用(默认)
46
- └── 推荐方案 A:Server 侧调用,在 Service 中调用插件并在同一方法中落库
47
- 备选方案 B:Client 侧调用插件 成功后通过已有 CRUD 接口保存结果
49
+ ├── 否(一次性即时展示)
50
+ │ ├── `outputMode=stream` 或内容生成较慢 Client `callStream()` 渐进展示
51
+ │ └── 单次短输出Client `call()`(默认)
52
+ └── 是
53
+ ├── `outputMode=stream` 且前端可承接 → 推荐方案 A:Client 侧 `callStream()` 渐进展示,成功后通过已有 CRUD 接口保存结果
54
+ ├── 输出较小且可在交互边界内完成、且必须由后端保证一致性 → Server 侧调用并在同一方法中落库
55
+ └── Client 侧无法满足且输出规模大/多字段/多份/多语言/多步骤 → 方案 B:Server 侧创建任务记录,快速返回任务状态;后台调用插件并落库;前端短轮询状态/结果
48
56
  ```
49
57
 
50
58
  | 应避免的做法 | 推荐做法 |
@@ -271,10 +279,11 @@ function MultiPluginStreamExample({ recordId }: { recordId: string }) {
271
279
  2. 一个 `stream` action 的真实调用结果(chunk 按 `outputSchema` 字段读取)
272
280
  3. 调用失败时的最小日志字段齐全
273
281
  4. 若无法执行真实调用,必须明确写明阻塞原因,禁止直接标记“开发完成”
282
+ 5. 若用户触发 AI 生成的请求超时、连接断开或工具返回超时,必须判定为验收失败;只有触发请求快速返回、随后能通过页面或接口读到明确完成或失败终态和结果,才允许标记通过
274
283
 
275
284
  ### Server 侧调用方式(仅兜底场景)
276
285
 
277
- > 以下场景适合使用 Server 侧调用,特别是涉及数据持久化时不要回避后端。
286
+ > 以下场景适合使用 Server 侧调用;若前端 `callStream` + 既有 CRUD 保存即可满足展示和持久化,不要优先引入后端后台任务。
278
287
 
279
288
  #### 1. 何时适合用 Server 侧?
280
289
 
@@ -285,6 +294,7 @@ function MultiPluginStreamExample({ recordId }: { recordId: string }) {
285
294
  | 敏感凭证调用 | 凭证不能暴露给前端 | 调用需要 admin token 的 API |
286
295
  | 强事务编排 | 多步骤需要原子性 | 创建记录 → 发通知 → 更新状态必须全成功或全回滚 |
287
296
  | 插件结果需持久化 | 调用结果需保存到数据库 | AI 分类/摘要结果需落库、文档解析的结构化数据需入库、图片识别结果需关联业务记录、语音转文字结果需存档等 |
297
+ | 高耗时 AI 生成需后续查看 | 请求不能长期占用用户交互链路 | 批量、多版本、多语言、长文本、多字段结构化生成,或文件/多模态分析后再生成内容 |
288
298
 
289
299
  #### 2. NestJS 注入方式
290
300
 
@@ -328,6 +338,7 @@ try {
328
338
 
329
339
  - PluginInstance 调用在 Server 侧通常属于 **外部依赖 / side-effect**
330
340
  - 除非业务明确要求强一致性,**默认不应阻塞主业务流程**
341
+ - 已选择 Server 侧承接的高耗时 AI capability 必须有可观测状态:创建任务时记录处理进度、完成终态、失败终态、输入摘要、错误信息和结果引用;触发接口只返回任务标识与当前状态,前端通过短轮询读取进度和最终结果
331
342
 
332
343
  推荐写法:异步触发 + catch 兜底:
333
344
 
@@ -129,7 +129,7 @@ shared/ # 前后端共享的目录
129
129
 
130
130
  1. 优先使用项目已有依赖,仅在无法实现时安装新依赖
131
131
  2. 使用前先查看 `package.json` 确保依赖已存在
132
- 3. **子包完整性检查**:部分库有多个子包(如 `@radix-ui/react-*` 系列每个组件都是独立子包),添加 import 后必须确认 package.json 中包含所有需要的子包
132
+ 3. **子包完整性检查**:部分库有多个子包(如 `@dnd-kit/core` + `@dnd-kit/sortable` + `@dnd-kit/utilities`),添加 import 后必须确认 package.json 中包含所有需要的子包
133
133
  4. 用法不清时查看 readme,可进一步搜索或网页访问获取信息
134
134
 
135
135
  ## 文件命名约定
@@ -443,13 +443,14 @@ NestJS 自己不读 env。直连 NestJS 端口 → header 缺失 → `req.userCo
443
443
 
444
444
  - **框架**: React 19 + TypeScript
445
445
  - **路由**: React Router DOM v6
446
- - **样式**: tailwindcss(语义化 token)为主,复杂 CSS 用 CSS Modules(`*.module.css`),动态计算值用行内 `style`
446
+ - **样式**: styled-jsx + tailwindcss(语义化 token)。styled-jsx 使用前提见下方"样式开发"
447
447
  - **UI 组件库**: shadcn/ui — Use components for functionality, heavily style them
448
448
  - **图表**: ReactECharts,**开发前必须调用 `/charts-skill`**
449
449
  - **图标**: Lucide React(唯一图标库,禁止 Emoji 和其他图标库)
450
450
  - **表格/表单/图表**: 见下方"组件 Skill 召回规则",开发前必须先调用对应 Skill
451
451
  - **用户**: 用户信息展示/选择必须用 `business-ui` 组件(阅读 README.md),禁止直接展示 userId
452
- - **Markdown 渲染**: `components/ui/markdown`(react-markdown + remark-gfm,内置 prose 排版)
452
+ - **富文本**: `business-ui/tiptap-editor`(阅读 README.md)
453
+ - **Markdown 渲染**: `components/ui/streamdown`(内置 prose 排版)
453
454
 
454
455
  ## API 请求
455
456
 
@@ -482,7 +483,8 @@ import { axiosForBackend } from '@lark-apaas/client-toolkit/utils/getAxiosForBac
482
483
  | --------------------------------------------------- | --------------------------------------- | --------------------------------- |
483
484
  | Table | `@lark-apaas/client-toolkit/antd-table` | 数据表格,**先调 `/table-skill`** |
484
485
  | UserSelect/UserDisplay/UserProfile/DepartmentSelect | `business-ui/*` | 用户/部门选择展示 |
485
- | Markdown | `components/ui/markdown` | Markdown 渲染(react-markdown + remark-gfm) |
486
+ | TiptapEditorComplete | `business-ui/tiptap-editor` | 富文本编辑器 |
487
+ | Streamdown | `components/ui/streamdown` | Markdown/流式渲染 |
486
488
 
487
489
  ### 组件 Skill 召回规则(强制执行)
488
490
 
@@ -533,7 +535,7 @@ import { axiosForBackend } from '@lark-apaas/client-toolkit/utils/getAxiosForBac
533
535
  ```
534
536
  需要写样式?
535
537
  ├─ 基础布局/间距/颜色 → Tailwind ✅
536
- ├─ 复杂动画/伪元素/高级CSS → CSS Modules(`*.module.css`)✅
538
+ ├─ 复杂动画/伪元素/高级CSS → styled-jsx
537
539
  └─ JS动态计算值 → 行内 style ✅
538
540
  ```
539
541
 
@@ -546,12 +548,10 @@ import { axiosForBackend } from '@lark-apaas/client-toolkit/utils/getAxiosForBac
546
548
  - **arbitrary values 中空格用下划线**:`from-[hsl(215_60%_18%)]` 非 `from-[hsl(215 60% 18%)]`
547
549
  - `tailwind-theme.css` 自定义属性用 `hsl(H, S%, L%)` 格式(非 `23 10% 23%`)
548
550
 
549
- ### CSS Modules 规范
551
+ ### styled-jsx 规范
550
552
 
551
- - 文件名:`ComponentName.module.css`,与组件同目录
552
- - 导入用 `import styles from './ComponentName.module.css'`,通过 `className={styles.foo}` 引用
553
- - 类名用 camelCase,避免使用连字符(`styles.myClass` 而非 `styles['my-class']`)
554
- - 全局样式(如动画 keyframes、CSS 变量)放在 `client/src/index.css` 或 `tailwind-theme.css`
553
+ - **技术栈一致性**:仅在已配置 styled-jsx 插件的项目中使用。`package.json` 无 `styled-jsx` 依赖则**禁用**,否则运行时 SyntaxError
554
+ - **禁止动态插值**:`<style jsx>` 内禁止 `${...}` 等表达式(会卡死)。动态值放 CSS 变量,用 `var(--xxx)` 引用
555
555
 
556
556
  ### 布局/排版
557
557
 
@@ -635,12 +635,15 @@ return <h1>{data?.title || '未知标题'}</h1>;
635
635
  | 验证 | zod |
636
636
  | 工具函数 | lodash |
637
637
  | 样式 | clsx |
638
- | 文件上传 | 原生 `<input type="file">`,用 shadcn 组件封装样式 |
638
+ | Excel | xlsx(**仅前端实现,禁止服务端实现**。解析后将结构化数据传到服务端保存) |
639
+ | PDF 导出 | jspdf + html2canvas(**仅前端实现,禁止服务端实现**) |
640
+ | 文件上传 | react-dropzone |
641
+ | 二维码 | qrcode.react |
639
642
  | 用户反馈 | sonner |
640
- | 数字动画 | `requestAnimationFrame` 手写,或 framer-motion 的 `animate` |
641
- | Base64 | 原生 `atob`/`btoa`(Unicode 内容先经 `TextEncoder`/`TextDecoder`);服务端用 `Buffer` |
642
-
643
- > Excel 解析、PDF 导出、二维码、拖拽、3D 场景等能力已随依赖瘦身不再预装(xlsx、jspdf、html2canvas、qrcode.react、@dnd-kit、react-dropzone、react-countup、js-base64、cobe 已从模板移除)。确有此类需求时,先在 package.json 显式添加所需依赖并安装,再编写代码。
643
+ | 拖拽 | @dnd-kit/core |
644
+ | 数字动画 | react-countup |
645
+ | Base64 | js-base64 — `import { encode, decode } from 'js-base64'` |
646
+ | 3D 场景 | cobe |
644
647
 
645
648
  ## 滚动分页最佳实践
646
649
 
@@ -35,6 +35,7 @@ lark-cli apps --help 2>&1 | grep -q '+plugin-install' && echo "READY" || echo "M
35
35
  | Client 侧非流式调用 | `capabilityClient.load(id).call(actionKey, input)` |
36
36
  | Client 侧流式调用 | `capabilityClient.load(id).callStream(actionKey, input)` |
37
37
  | Server 侧调用(仅兜底) | `capabilityService.load(id).call(actionKey, input)` |
38
+ | 长耗时 AI 结果 | 大体量/多字段/多份/多语言/文件或多模态串联等结构信号命中时,优先前端 `callStream` 渐进展示;需保存则流式结束后复用 CRUD 落库;仅在 Client 侧无法满足时使用后端任务记录 + 状态查询 + 结果读取;禁止单个 HTTP 请求等待完整结果后才返回 |
38
39
  | capabilityClient 导入 | `import { capabilityClient } from '@lark-apaas/client-toolkit'` |
39
40
  | CapabilityService 导入 | `import { CapabilityService } from '@lark-apaas/fullstack-nestjs-core';` |
40
41
  | CapabilityService 注入 | `@Inject() private readonly capabilityService: CapabilityService` |
@@ -516,7 +517,9 @@ npx @lark-apaas/miaoda-cli plugin list --id <instance_id>
516
517
  2. 结果供后续功能消费
517
518
  3. 用户再次访问时需要看到结果
518
519
 
519
- **推荐**:ServerService 调用插件 + 同一方法落库。**备选**:Client 侧调用 流式结束后调已有 CRUD 接口保存。
520
+ **推荐**:能由前端承接时,Client`callStream` 渐进展示,流式结束后调已有 CRUD 接口保存。**必要时**:敏感凭证、触发器、强事务或必须由后端保证落库一致性时,Server Service 调用插件并落库。
521
+
522
+ **高耗时 AI capability 闸门**:若插件输出定义或功能设计显示输出规模大、输出字段多、需要多份结果、多语言/长文本、文件或多模态输入后继续生成、多个 capability 串联、或结果需后续查看/落库,禁止把完整生成放进一个同步 HTTP 请求等待;能由前端承接时优先 `callStream` 渐进展示,需保存则流式结束后复用 CRUD 落库;仅在 Client 侧无法满足时后端创建任务记录后快速返回、由前端短轮询状态/结果,或拆成多个独立小调用。
520
523
 
521
524
  ### 生成代码
522
525
 
@@ -535,7 +538,8 @@ npx @lark-apaas/miaoda-cli plugin list --id <instance_id>
535
538
 
536
539
  1. **禁止静默吞异常**:每个 `catch` 块必须向用户展示错误或触发补偿
537
540
  2. **异步操作必须有终态**:DB 中维护状态(pending → success / failed)
538
- 3. **插件失败必须有补偿**:至少记录到待处理列表或提示用户重试
541
+ 3. **长耗时 AI 生成不得同步等完**:大体量、多字段、多份、多语言、文件/多模态串联或需要持久化的 AI capability 调用,触发接口必须快速返回任务状态或采用前端流式展示;若接口请求、浏览器操作或页面请求出现超时/连接断开,不能只凭服务端最终日志或数据库最终写入宣告成功,必须证明用户侧存在可读取的终态结果
542
+ 4. **插件失败必须有补偿**:至少记录到待处理列表或提示用户重试
539
543
 
540
544
  ## 缓存与幂等性
541
545
 
@@ -2,15 +2,19 @@
2
2
 
3
3
  ### 核心原则:根据场景选择调用侧
4
4
 
5
- **默认优先在 Client 侧调用 capabilityClient;但当插件结果需要持久化到数据库时,应考虑在 Server 侧调用或确保前端调用后及时通过后端接口保存。**
5
+ **默认优先在 Client 侧调用 capabilityClient;流式或高耗时 AI 生成优先 `callStream` 渐进展示。结果需要持久化时,优先在流式结束后通过已有后端接口保存;只有 Client 侧无法满足时才切到 Server 侧。**
6
+
7
+ **高耗时 AI capability 先判调用形态**:只要输出规模大、输出字段多、需要多份结果、多语言/长文本、文件或多模态输入后继续生成、多个 capability 串联、或结果需后续查看/落库,就不得把完整 AI 结果塞进一个同步 HTTP 请求等待。能由前端承接时,优先用前端 `callStream` 渐进展示,并在流式结束后按需复用已有 CRUD 接口保存结果;只有 Client 侧无法满足(触发器/敏感凭证/强事务/必须由后端保证落库一致性等)时,才采用后端任务记录 + 状态/结果查询,避免把后台任务作为默认方案。
8
+
6
9
  **严禁** import { capabilityClient } from '@lark-apaas/client-capability'。
7
10
  **唯一指定**的导入方式是 import { capabilityClient } from '@lark-apaas/client-toolkit';
8
11
 
9
12
  | 优先级 | 场景 | 调用方式 |
10
13
  |-------|------|---------|
11
- | **首选** | 绝大多数场景 | `capabilityClient.load(id).call()` |
12
- | **首选** | 流式输出场景 | `capabilityClient.load(id).callStream()` |
13
- | **兜底** | Client 侧无法满足时 | `CapabilityService.load(id).call()` |
14
+ | **首选** | 绝大多数即时展示场景 | `capabilityClient.load(id).call()` |
15
+ | **首选** | 流式输出,或高耗时但可由前端承接的 AI 生成 | `capabilityClient.load(id).callStream()`(流式结束后按需持久化) |
16
+ | **必要时** | 高耗时且 Client 侧无法满足:触发器、敏感凭证、强事务、必须由后端保证落库一致性 | 后端任务记录 + 后台调用 `CapabilityService.load(id).call()` + 前端短轮询状态/结果 |
17
+ | **兜底** | Client 侧无法满足且单次调用可在交互边界内完成 | `CapabilityService.load(id).call()` |
14
18
 
15
19
  #### 什么情况下应使用 Server 侧?
16
20
 
@@ -19,7 +23,7 @@
19
23
  1. **涉及敏感凭证**:调用需要服务端私密 token/secret,不适合暴露给前端
20
24
  2. **必须后端编排**:多个插件调用之间有强事务依赖,需要后端统一编排
21
25
  3. **触发器/定时任务场景**:没有前端上下文,只能由后端发起
22
- 4. **插件结果需要持久化**:调用结果需要保存到数据库,在 Server 侧可以在同一方法中完成调用+落库,保证数据一致性
26
+ 4. **插件结果需要持久化**:调用结果需要保存到数据库;能由前端承接时,优先前端 `callStream` 渐进展示并在结束后复用已有 CRUD 接口保存;只有 Client 侧无法满足或必须由后端保证落库一致性时,才在 Server 侧调用并落库。若此时输出规模大、字段多、结果多份或需多步能力串联,必须改为任务记录 + 后台执行 + 状态/结果查询,避免一个 HTTP 请求等待完整生成
23
27
 
24
28
  > **提示**:如果插件结果不需要存储、仅用于即时展示(如流式生成文本、发送消息),优先在前端调用。但当结果需要保存到数据库时,不要回避使用 Server 侧。
25
29
 
@@ -31,9 +35,13 @@
31
35
 
32
36
  ```
33
37
  插件结果是否需要持久化到数据库?
34
- ├── 否 → Client 侧调用(默认)
35
- └── 推荐方案 A:Server 侧调用,在 Service 中调用插件并在同一方法中落库
36
- 备选方案 B:Client 侧调用插件 成功后通过已有 CRUD 接口保存结果
38
+ ├── 否
39
+ │ ├── `outputMode=stream` 或内容生成较慢 Client `callStream()` 渐进展示
40
+ │ └── 单次短输出Client `call()`(默认)
41
+ └── 是
42
+ ├── `outputMode=stream` 且前端可承接 → 推荐方案 A:Client 侧 `callStream()` 渐进展示,成功后通过已有 CRUD 接口保存结果
43
+ ├── 输出较小且可在交互边界内完成、且必须由后端保证一致性 → Server 侧调用并在同一方法中落库
44
+ └── Client 侧无法满足且输出规模大/多字段/多份/多语言/多步骤 → 方案 B:Server 侧创建任务记录,快速返回任务状态;后台调用插件并落库;前端短轮询状态/结果
37
45
  ```
38
46
 
39
47
  | 应避免的做法 | 推荐做法 |
@@ -233,10 +241,11 @@ function MultiPluginStreamExample() {
233
241
  2. 一个 `stream` action 的真实调用结果(chunk 按 `outputSchema` 字段读取)
234
242
  3. 调用失败时的最小日志字段齐全
235
243
  4. 若无法执行真实调用,必须明确写明阻塞原因,禁止直接标记"开发完成"
244
+ 5. 若用户触发 AI 生成的请求超时、连接断开或工具返回超时,必须判定为验收失败;只有触发请求快速返回、随后能通过页面或接口读到明确完成或失败终态和结果,才允许标记通过
236
245
 
237
246
  ### Server 侧调用方式(仅兜底场景)
238
247
 
239
- > 以下场景适合使用 Server 侧调用,特别是涉及数据持久化时不要回避后端。
248
+ > 以下场景适合使用 Server 侧调用;若前端 `callStream` + 既有 CRUD 保存即可满足展示和持久化,不要优先引入后端后台任务。
240
249
 
241
250
  #### 1. 何时适合用 Server 侧?
242
251
 
@@ -247,6 +256,7 @@ function MultiPluginStreamExample() {
247
256
  | 敏感凭证调用 | 凭证不能暴露给前端 | 调用需要 admin token 的 API |
248
257
  | 强事务编排 | 多步骤需要原子性 | 创建记录 → 发通知 → 更新状态必须全成功或全回滚 |
249
258
  | 插件结果需持久化 | 调用结果需保存到数据库 | AI 分类/摘要结果需落库、文档解析的结构化数据需入库、图片识别结果需关联业务记录、语音转文字结果需存档等 |
259
+ | 高耗时 AI 生成需后续查看 | 请求不能长期占用用户交互链路 | 批量、多版本、多语言、长文本、多字段结构化生成,或文件/多模态分析后再生成内容 |
250
260
 
251
261
  #### 2. NestJS 注入方式
252
262
 
@@ -290,6 +300,7 @@ try {
290
300
 
291
301
  - PluginInstance 调用在 Server 侧通常属于 **外部依赖 / side-effect**
292
302
  - 除非业务明确要求强一致性,**默认不应阻塞主业务流程**
303
+ - 已选择 Server 侧承接的高耗时 AI capability 必须有可观测状态:创建任务时记录处理进度、完成终态、失败终态、输入摘要、错误信息和结果引用;触发接口只返回任务标识与当前状态,前端通过短轮询读取进度和最终结果
293
304
 
294
305
  推荐写法:异步触发 + catch 兜底:
295
306