larkcc 0.4.0 → 0.5.0
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 +26 -12
- package/README.md +177 -23
- package/dist/agent.js +138 -32
- package/dist/agent.js.map +1 -1
- package/dist/app.js.map +1 -1
- package/dist/cardkit.d.ts +92 -0
- package/dist/cardkit.js +407 -0
- package/dist/cardkit.js.map +1 -0
- package/dist/config.d.ts +23 -3
- package/dist/config.js +43 -47
- package/dist/config.js.map +1 -1
- package/dist/feishu.d.ts +34 -4
- package/dist/feishu.js +260 -63
- package/dist/feishu.js.map +1 -1
- package/dist/format/builder.d.ts +126 -37
- package/dist/format/builder.js +276 -116
- package/dist/format/builder.js.map +1 -1
- package/dist/format/card-optimize.d.ts +42 -0
- package/dist/format/card-optimize.js +74 -0
- package/dist/format/card-optimize.js.map +1 -0
- package/dist/format/constants.d.ts +80 -9
- package/dist/format/constants.js +140 -53
- package/dist/format/constants.js.map +1 -1
- package/dist/format/document.d.ts +4 -2
- package/dist/format/document.js +57 -35
- package/dist/format/document.js.map +1 -1
- package/dist/format/guide.d.ts +19 -0
- package/dist/format/guide.js +201 -0
- package/dist/format/guide.js.map +1 -0
- package/dist/format/image-resolver.d.ts +31 -0
- package/dist/format/image-resolver.js +202 -0
- package/dist/format/image-resolver.js.map +1 -0
- package/dist/format/index.d.ts +8 -3
- package/dist/format/index.js +8 -2
- package/dist/format/index.js.map +1 -1
- package/dist/format/parser.d.ts +16 -0
- package/dist/format/parser.js +26 -12
- package/dist/format/parser.js.map +1 -1
- package/dist/format/sanitize.d.ts +3 -0
- package/dist/format/sanitize.js +16 -7
- package/dist/format/sanitize.js.map +1 -1
- package/dist/format/thinking.d.ts +29 -0
- package/dist/format/thinking.js +50 -0
- package/dist/format/thinking.js.map +1 -0
- package/dist/resources/format-guide.md +109 -0
- package/dist/streaming.d.ts +77 -0
- package/dist/streaming.js +293 -0
- package/dist/streaming.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,23 +7,37 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.5.0] - 2026-03-27
|
|
11
|
+
|
|
10
12
|
### Added
|
|
11
13
|
|
|
12
|
-
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
|
|
16
|
-
-
|
|
14
|
+
- Streaming output support with two modes: CardKit (default) and Update
|
|
15
|
+
- **CardKit mode**: single-card architecture with state machine (idle → creating → streaming → completed), aligned with official openclaw-lark approach
|
|
16
|
+
- **Update mode**: message patch API with auto-fallback chain (cardkit → update → none)
|
|
17
|
+
- Image resolver for external images (download and re-upload to Feishu CDN)
|
|
18
|
+
- Internal CDN domain skip list (feishucdn.com, larksuitecdn.com, etc.)
|
|
19
|
+
- Configurable `card_title` for all streaming modes (default: "Claude")
|
|
20
|
+
- Collapsible thinking section in CardKit complete output
|
|
21
|
+
- Per-tool status words for tool cards (replaces random thinking words)
|
|
22
|
+
- `prepublishOnly` script to package.json for safe npm publishing
|
|
23
|
+
- Card footer metadata (model, tokens, duration) in streaming cards
|
|
24
|
+
|
|
25
|
+
### Changed
|
|
26
|
+
|
|
27
|
+
- Default streaming mode changed from `update` to `cardkit`
|
|
28
|
+
- CardKit mode no longer sends separate tool call cards (single-card design)
|
|
29
|
+
|
|
30
|
+
### Removed
|
|
31
|
+
|
|
32
|
+
- `thinking_words` config option (replaced by per-tool status words)
|
|
17
33
|
|
|
18
34
|
### Fixed
|
|
19
35
|
|
|
20
|
-
- Correct
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
- VIEW: 29 → 33
|
|
26
|
-
- Add GRID (24) and GRID_COLUMN (25)
|
|
36
|
+
- Correct CardKit API format (card_json type, IM message reply, sequence counter)
|
|
37
|
+
- CardKit lazy card creation on first `append()` call
|
|
38
|
+
- Image resolver CDN download failures with internal domain blacklist
|
|
39
|
+
- ESM-compatible `__dirname` polyfill in guide.ts
|
|
40
|
+
- Align all docx block structures with Feishu SDK types to resolve 1770024 error
|
|
27
41
|
|
|
28
42
|
## [0.3.0] - 2026-03-26
|
|
29
43
|
|
package/README.md
CHANGED
|
@@ -313,9 +313,15 @@ setup 不需要填 open_id,发第一条消息自动保存。
|
|
|
313
313
|
- 👌 处理中打 reaction,完成换 DONE
|
|
314
314
|
- 💬 回复引用原消息
|
|
315
315
|
- ⚡ 工具调用实时展示
|
|
316
|
-
-
|
|
316
|
+
- 🌊 流式输出(互斥守卫 + 自适应节流 + 长间隔批处理)
|
|
317
|
+
- 📋 Markdown 卡片渲染(自动标题降级适配)
|
|
317
318
|
- 📄 超长消息支持分段发送或写入云文档
|
|
319
|
+
- 🛡️ 文档写入容错(单表/批次失败不影响整篇文档)
|
|
320
|
+
- 🎯 格式指导注入(从源头优化输出质量)
|
|
318
321
|
- 🖼 图片理解(支持富文本多图)
|
|
322
|
+
- 🧠 思考过程分离(可折叠显示 Claude 的推理过程)
|
|
323
|
+
- ⏱ 响应元数据(耗时、token 数实时显示)
|
|
324
|
+
- 🖼 外部图片自动上传(下载 → 飞书 → 渲染,支持卡片和文档)
|
|
319
325
|
- ⌨️ Slash 命令
|
|
320
326
|
- ⏹ `/stop` 中断任务
|
|
321
327
|
- 👥 群聊 @ 触发
|
|
@@ -368,6 +374,93 @@ setup 不需要填 open_id,发第一条消息自动保存。
|
|
|
368
374
|
\<u\> 显示为 <u>
|
|
369
375
|
```
|
|
370
376
|
|
|
377
|
+
## 流式输出
|
|
378
|
+
|
|
379
|
+
回复内容会以打字机效果逐字显示,无需等待完整输出。
|
|
380
|
+
|
|
381
|
+
内部使用 FlushController:
|
|
382
|
+
- **互斥守卫** — 防止并发刷新冲突
|
|
383
|
+
- **自适应节流** — 根据上次刷新时间动态调整间隔
|
|
384
|
+
- **长间隔批处理** — 2 秒无新内容自动 flush 剩余缓冲
|
|
385
|
+
|
|
386
|
+
### 配置
|
|
387
|
+
|
|
388
|
+
```yaml
|
|
389
|
+
streaming:
|
|
390
|
+
enabled: true # 是否启用流式(默认 true)
|
|
391
|
+
mode: cardkit # update(message.patch)| cardkit | none
|
|
392
|
+
flush_interval_ms: 300 # 最小刷新间隔(毫秒)
|
|
393
|
+
thinking_enabled: false # 是否显示 Claude 思考过程
|
|
394
|
+
fallback_on_error: true # 失败时降级为一次性发送
|
|
395
|
+
|
|
396
|
+
# 卡片标题(所有模式生效)
|
|
397
|
+
card_title: Claude # 留空则不显示 header
|
|
398
|
+
|
|
399
|
+
# 图片自动解析(下载外部图片上传到飞书)
|
|
400
|
+
image_resolver:
|
|
401
|
+
enabled: true # 是否启用(默认 true)
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
### 模式说明
|
|
405
|
+
|
|
406
|
+
| 模式 | 说明 | 额外权限 |
|
|
407
|
+
|------|------|---------|
|
|
408
|
+
| `update` | 使用消息 patch API 模拟流式 | 无(默认即可用) |
|
|
409
|
+
| `cardkit` | 使用飞书 CardKit API(真正打字机效果) | `cardkit:card:write` |
|
|
410
|
+
| `none` | 禁用流式,等待完整输出后一次性发送 | 无 |
|
|
411
|
+
|
|
412
|
+
- `cardkit` 模式为默认模式,采用单卡片架构(对齐飞书官方 OpenClaw 方案),全程只有一个消息
|
|
413
|
+
- `cardkit` 模式下工具调用不可见(不打工具卡片),失败时自动降级为 `update`
|
|
414
|
+
- `update` 模式使用消息 patch API 模拟流式,会发送独立的工具调用卡片
|
|
415
|
+
- 流式过程中如果内容超长,最终会自动写入云文档并回复链接
|
|
416
|
+
|
|
417
|
+
### 中断
|
|
418
|
+
|
|
419
|
+
流式输出过程中可以使用 `/stop` 中断,卡片会立即显示中断消息。
|
|
420
|
+
|
|
421
|
+
### 思考过程
|
|
422
|
+
|
|
423
|
+
开启 `streaming.thinking_enabled: true` 后,Claude 的扩展思考过程会以可折叠面板显示在回复上方:
|
|
424
|
+
|
|
425
|
+
- 流式期间显示 "💭 思考中..." 提示
|
|
426
|
+
- 完成后思考内容收起在折叠面板中,点击可展开查看
|
|
427
|
+
- 关闭时完全过滤 `<thinking>` 标签,用户无感
|
|
428
|
+
|
|
429
|
+
### 响应元数据
|
|
430
|
+
|
|
431
|
+
每条回复底部自动显示耗时和 token 用量:
|
|
432
|
+
|
|
433
|
+
```
|
|
434
|
+
⏱ 8.2s · 1,234 tokens
|
|
435
|
+
```
|
|
436
|
+
|
|
437
|
+
仅显示在卡片消息中,云文档不追加。
|
|
438
|
+
|
|
439
|
+
## 格式优化
|
|
440
|
+
|
|
441
|
+
### 卡片自动优化
|
|
442
|
+
|
|
443
|
+
发送到飞书卡片的 Markdown 会自动经过优化管线处理:
|
|
444
|
+
|
|
445
|
+
1. **标题降级** — H1→H4, H2-H6→H5(飞书卡片只支持 H4/H5)
|
|
446
|
+
2. **代码块保护** — 代码块内容不会被其他处理逻辑误解析
|
|
447
|
+
3. **外部图片上传** — 自动下载外部图片并上传到飞书,替换为 `img_xxx` 格式(卡片和文档均支持)
|
|
448
|
+
|
|
449
|
+
### 格式指导(System Prompt)
|
|
450
|
+
|
|
451
|
+
默认启用,通过 Claude Code SDK 的 system prompt 注入飞书格式规范,从源头提升输出质量。整个会话只需注入一次,不重复消耗 token。
|
|
452
|
+
|
|
453
|
+
```yaml
|
|
454
|
+
format_guide:
|
|
455
|
+
enabled: true # 是否启用(默认 true)
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
**自定义格式指导:**
|
|
459
|
+
|
|
460
|
+
编辑 `~/.larkcc/format-guide.md` 即可覆盖默认内容。格式指导内容是纯 Markdown,你可以根据实际需求增减规则。
|
|
461
|
+
|
|
462
|
+
查看默认格式指导:`resources/format-guide.md`(随项目发布)。
|
|
463
|
+
|
|
371
464
|
## 消息类型支持
|
|
372
465
|
|
|
373
466
|
| 类型 | 单聊 | 群聊 |
|
|
@@ -408,6 +501,25 @@ overflow:
|
|
|
408
501
|
threshold: 2800 # 写文档阈值
|
|
409
502
|
title_template: "{cwd} - {session_id} - {datetime}"
|
|
410
503
|
|
|
504
|
+
# 格式指导(从源头优化 Claude 输出质量)
|
|
505
|
+
format_guide:
|
|
506
|
+
enabled: true # 是否注入飞书格式要求到 prompt
|
|
507
|
+
|
|
508
|
+
# 卡片标题
|
|
509
|
+
card_title: Claude # 留空则不显示 header
|
|
510
|
+
|
|
511
|
+
# 流式输出配置
|
|
512
|
+
streaming:
|
|
513
|
+
enabled: true # 是否启用流式(默认 true)
|
|
514
|
+
mode: cardkit # update | cardkit | none
|
|
515
|
+
flush_interval_ms: 300 # 最小刷新间隔(毫秒)
|
|
516
|
+
thinking_enabled: false # 是否显示思考过程
|
|
517
|
+
fallback_on_error: true # 失败时降级
|
|
518
|
+
|
|
519
|
+
# 图片自动解析(下载外部图片上传到飞书)
|
|
520
|
+
image_resolver:
|
|
521
|
+
enabled: true # 是否启用(默认 true)
|
|
522
|
+
|
|
411
523
|
commands:
|
|
412
524
|
deploy: "部署到测试环境"
|
|
413
525
|
|
|
@@ -429,12 +541,8 @@ reaction:
|
|
|
429
541
|
done: DONE # 完成
|
|
430
542
|
error: OnIt # 出错
|
|
431
543
|
|
|
432
|
-
#
|
|
433
|
-
|
|
434
|
-
- "💭 思考中..."
|
|
435
|
-
- "🔍 分析中..."
|
|
436
|
-
- "💻 编码中..."
|
|
437
|
-
# ... 更多状态词
|
|
544
|
+
# 卡片标题
|
|
545
|
+
card_title: Claude
|
|
438
546
|
|
|
439
547
|
profiles:
|
|
440
548
|
mybot:
|
|
@@ -489,9 +597,13 @@ profiles:
|
|
|
489
597
|
|
|
490
598
|
- 支持 Markdown 格式(标题、代码块、列表等)
|
|
491
599
|
|
|
492
|
-
|
|
600
|
+
**图片处理:**
|
|
493
601
|
|
|
494
|
-
|
|
602
|
+
- `blob:` 格式的无效图片 URL 自动过滤
|
|
603
|
+
- 外部图片(`https://`)自动下载并上传到飞书,替换为内部 `img_xxx` 格式
|
|
604
|
+
- 上传失败的图片降级为链接,不影响整体流程
|
|
605
|
+
- 图片大小限制 10MB,下载超时 10 秒
|
|
606
|
+
- 卡片和云文档均支持图片渲染
|
|
495
607
|
|
|
496
608
|
**自动清理:**
|
|
497
609
|
|
|
@@ -536,19 +648,45 @@ overflow:
|
|
|
536
648
|
|
|
537
649
|
### 权限
|
|
538
650
|
|
|
651
|
+
权限按功能分组,建议全部开通:
|
|
652
|
+
|
|
653
|
+
#### 基础消息(必开)
|
|
654
|
+
|
|
539
655
|
| 权限 | 用途 |
|
|
540
656
|
|------|------|
|
|
541
|
-
| `im:message` |
|
|
542
|
-
| `im:message:send_as_bot` |
|
|
543
|
-
| `im:message.p2p_msg:readonly` |
|
|
657
|
+
| `im:message` | 基础消息(含下载消息中的图片、文件) |
|
|
658
|
+
| `im:message:send_as_bot` | 以机器人身份发送消息、回复消息、更新消息(**流式输出也依赖此权限**) |
|
|
659
|
+
| `im:message.p2p_msg:readonly` | 接收私聊消息 |
|
|
544
660
|
| `im:message.group_at_msg:readonly` | 接收群 @ 消息 |
|
|
545
|
-
| `im:message.reactions:write_only` | 打 reaction |
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
661
|
+
| `im:message.reactions:write_only` | 打 reaction 表情(处理中/完成/出错状态) |
|
|
662
|
+
|
|
663
|
+
#### 卡片与富文本
|
|
664
|
+
|
|
665
|
+
| 权限 | 用途 |
|
|
666
|
+
|------|------|
|
|
667
|
+
| `cardkit:card:write` | 发送交互式卡片、CardKit 流式输出 |
|
|
549
668
|
|
|
550
669
|
> 💡 `im:message` 权限已包含下载消息中资源文件(图片、文件)的能力
|
|
551
670
|
|
|
671
|
+
#### 云文档(超长消息写入)
|
|
672
|
+
|
|
673
|
+
| 权限 | 用途 |
|
|
674
|
+
|------|------|
|
|
675
|
+
| `docx:document` | 创建/编辑云文档(`overflow.mode: document` 时需要) |
|
|
676
|
+
| `drive:file` | 删除云空间文件(自动清理旧文档时需要) |
|
|
677
|
+
|
|
678
|
+
> 💡 不使用文档模式时,这两个权限可以不开
|
|
679
|
+
|
|
680
|
+
#### 开通步骤
|
|
681
|
+
|
|
682
|
+
1. 进入 [飞书开发者后台](https://open.feishu.cn/) → 选择你的应用
|
|
683
|
+
2. 左侧菜单 **权限管理** → 搜索并开通上述权限
|
|
684
|
+
3. 点击 **权限管理** 页面上方的 **权限配置** → 批量开通
|
|
685
|
+
4. 创建新版本 → 申请发布(企业自建应用管理员审批即可)
|
|
686
|
+
5. 发布成功后权限生效
|
|
687
|
+
|
|
688
|
+
> ⚠️ 权限变更后需要重新发布应用版本,已运行的 larkcc 需要重启
|
|
689
|
+
|
|
552
690
|
### 事件订阅
|
|
553
691
|
|
|
554
692
|
使用**长连接** → 订阅 `im.message.receive_v1`
|
|
@@ -748,7 +886,7 @@ You: [Error screenshot] How to fix this
|
|
|
748
886
|
You: [Rich text with multiple images] Analyze these images
|
|
749
887
|
```
|
|
750
888
|
|
|
751
|
-
> **Note:** Invalid image URLs (like `blob:` URLs from websearch) are automatically filtered.
|
|
889
|
+
> **Note:** Invalid image URLs (like `blob:` URLs from websearch) are automatically filtered. External images are automatically downloaded and uploaded to Feishu for proper rendering.
|
|
752
890
|
|
|
753
891
|
## File Support
|
|
754
892
|
|
|
@@ -821,21 +959,37 @@ larkcc -p mybot # Use specified bot
|
|
|
821
959
|
|
|
822
960
|
### Permissions
|
|
823
961
|
|
|
962
|
+
#### Basic Messaging (Required)
|
|
963
|
+
|
|
824
964
|
| Permission | Purpose |
|
|
825
965
|
|------------|---------|
|
|
826
|
-
| `im:message` | Basic message (including file download) |
|
|
827
|
-
| `im:message:send_as_bot` | Send messages |
|
|
966
|
+
| `im:message` | Basic message (including image/file download) |
|
|
967
|
+
| `im:message:send_as_bot` | Send/reply/update messages (**streaming also depends on this**) |
|
|
828
968
|
| `im:message.p2p_msg:readonly` | Receive direct messages |
|
|
829
969
|
| `im:message.group_at_msg:readonly` | Receive group @ messages |
|
|
830
|
-
| `im:message.reactions:write_only` | Add reactions |
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
970
|
+
| `im:message.reactions:write_only` | Add reactions (processing/done/error status) |
|
|
971
|
+
|
|
972
|
+
#### Cards
|
|
973
|
+
|
|
974
|
+
| Permission | Purpose |
|
|
975
|
+
|------------|---------|
|
|
976
|
+
| `cardkit:card:write` | Send interactive cards, CardKit streaming |
|
|
977
|
+
|
|
978
|
+
#### Cloud Documents (for overflow mode)
|
|
979
|
+
|
|
980
|
+
| Permission | Purpose |
|
|
981
|
+
|------------|---------|
|
|
982
|
+
| `docx:document` | Create/edit cloud documents (when `overflow.mode: document`) |
|
|
983
|
+
| `drive:file` | Delete cloud files (auto-cleanup of old documents) |
|
|
834
984
|
|
|
835
985
|
### Event Subscription
|
|
836
986
|
|
|
837
987
|
Use **Long Connection** → Subscribe to `im.message.receive_v1`
|
|
838
988
|
|
|
989
|
+
## 致谢
|
|
990
|
+
|
|
991
|
+
CardKit 流式卡片实现参考了飞书官方 [openclaw-lark](https://github.com/larksuite/openclaw-lark) 项目的 API 用法与架构设计。
|
|
992
|
+
|
|
839
993
|
## Contributing
|
|
840
994
|
|
|
841
995
|
See [CONTRIBUTING.md](CONTRIBUTING.md)
|
package/dist/agent.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
import { query } from "@anthropic-ai/claude-agent-sdk";
|
|
2
2
|
import os from "os";
|
|
3
3
|
import { execSync } from "child_process";
|
|
4
|
-
import { replyFinalCard, sendToolCard, updateToolCard, } from "./feishu.js";
|
|
4
|
+
import { replyFinalCard, sendToolCard, updateToolCard, getTenantAccessToken, } from "./feishu.js";
|
|
5
5
|
import { getSession, setSession } from "./session.js";
|
|
6
6
|
import { logger } from "./logger.js";
|
|
7
|
+
import { getFormatGuideContent } from "./format/guide.js";
|
|
8
|
+
import { parseThinking, stripThinking } from "./format/thinking.js";
|
|
9
|
+
import { resolveImages } from "./format/image-resolver.js";
|
|
10
|
+
import { createStreamingCard } from "./streaming.js";
|
|
11
|
+
import { CardKitController } from "./cardkit.js";
|
|
7
12
|
const TOOL_LABELS = {
|
|
8
13
|
Read: "📂 读取文件",
|
|
9
14
|
Write: "✏️ 写入文件",
|
|
@@ -32,12 +37,67 @@ function formatInput(name, input) {
|
|
|
32
37
|
function truncate(str, len) {
|
|
33
38
|
return str.length > len ? str.slice(0, len) + "..." : str;
|
|
34
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* 构建 ReplyContext(多个地方复用)
|
|
42
|
+
*/
|
|
43
|
+
function buildReplyContext(config, profile, cwd, chatId, rootMsgId) {
|
|
44
|
+
return {
|
|
45
|
+
profile: profile ?? "default",
|
|
46
|
+
cwd,
|
|
47
|
+
sessionId: getSession() ?? "",
|
|
48
|
+
overflow: config.overflow,
|
|
49
|
+
chatId,
|
|
50
|
+
rootMsgId,
|
|
51
|
+
appId: config.feishu.app_id,
|
|
52
|
+
appSecret: config.feishu.app_secret,
|
|
53
|
+
card_table: config.card_table,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 构建底部元数据字符串
|
|
58
|
+
* 格式:⏱ 8.2s · Claude Sonnet 4 · 1,234 tokens · ⚠️ 2 张图片上传失败
|
|
59
|
+
*/
|
|
60
|
+
function buildFooterMetadata(elapsedSeconds, model, tokens, imageFailed) {
|
|
61
|
+
const parts = [`⏱ ${elapsedSeconds.toFixed(1)}s`];
|
|
62
|
+
if (model)
|
|
63
|
+
parts.push(model);
|
|
64
|
+
if (tokens)
|
|
65
|
+
parts.push(`${tokens.toLocaleString()} tokens`);
|
|
66
|
+
if (imageFailed && imageFailed > 0)
|
|
67
|
+
parts.push(`⚠️ ${imageFailed} 张图片上传失败`);
|
|
68
|
+
return parts.join(' · ');
|
|
69
|
+
}
|
|
35
70
|
export async function runAgent(prompt, cwd, config, client, chatId, rootMsgId, images, abortSignal, // 可选中断信号
|
|
36
71
|
profile // 机器人配置名
|
|
37
72
|
) {
|
|
38
73
|
const sessionId = getSession();
|
|
74
|
+
const startTime = Date.now();
|
|
39
75
|
let textBuffer = "";
|
|
40
76
|
const toolMsgMap = new Map();
|
|
77
|
+
// 构建 ReplyContext
|
|
78
|
+
const replyContext = buildReplyContext(config, profile, cwd, chatId, rootMsgId);
|
|
79
|
+
// 创建流式控制器
|
|
80
|
+
// CardKit 模式:单卡片架构,不发工具卡片
|
|
81
|
+
// Update 模式:message.patch 模拟流式,保留工具卡片
|
|
82
|
+
const isCardkitMode = config.streaming?.mode === "cardkit";
|
|
83
|
+
let cardkitCtrl = null;
|
|
84
|
+
let streamingCard = createStreamingCard(config.streaming, client, rootMsgId, replyContext, config.card_title);
|
|
85
|
+
if (isCardkitMode && !streamingCard) {
|
|
86
|
+
cardkitCtrl = new CardKitController({
|
|
87
|
+
client,
|
|
88
|
+
appId: replyContext.appId,
|
|
89
|
+
appSecret: replyContext.appSecret,
|
|
90
|
+
rootMsgId,
|
|
91
|
+
cardTitle: config.card_title ?? "Claude",
|
|
92
|
+
thinkingEnabled: config.streaming?.thinking_enabled === true,
|
|
93
|
+
context: replyContext,
|
|
94
|
+
intervalMs: config.streaming?.flush_interval_ms || 300,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
// 构建格式指导 system prompt(追加到 Claude Code 默认 system prompt 后面)
|
|
98
|
+
const systemPrompt = config.format_guide?.enabled !== false
|
|
99
|
+
? getFormatGuideContent()
|
|
100
|
+
: undefined;
|
|
41
101
|
// 构建 prompt content(支持图片)
|
|
42
102
|
const promptContent = [];
|
|
43
103
|
if (images && images.length > 0) {
|
|
@@ -73,21 +133,21 @@ profile // 机器人配置名
|
|
|
73
133
|
permissionMode: config.claude.permission_mode,
|
|
74
134
|
allowedTools: config.claude.allowed_tools,
|
|
75
135
|
abortSignal,
|
|
136
|
+
...(systemPrompt ? { systemPrompt: { type: 'preset', preset: 'claude_code', append: systemPrompt } } : {}),
|
|
76
137
|
},
|
|
77
138
|
})) {
|
|
78
139
|
// 检查是否已中断
|
|
79
140
|
if (abortSignal?.aborted) {
|
|
80
141
|
logger.info("Agent aborted by user");
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
});
|
|
142
|
+
if (cardkitCtrl) {
|
|
143
|
+
await cardkitCtrl.abort("⏹ 任务已中断");
|
|
144
|
+
}
|
|
145
|
+
else if (streamingCard) {
|
|
146
|
+
await streamingCard.abort("⏹ 任务已中断");
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
await replyFinalCard(client, chatId, rootMsgId, "⏹ 任务已中断", replyContext, { cardTitle: config.card_title });
|
|
150
|
+
}
|
|
91
151
|
break;
|
|
92
152
|
}
|
|
93
153
|
if (event.type === "assistant") {
|
|
@@ -95,8 +155,21 @@ profile // 机器人配置名
|
|
|
95
155
|
for (const block of blocks) {
|
|
96
156
|
if (block.type === "text" && block.text) {
|
|
97
157
|
textBuffer += block.text;
|
|
158
|
+
// CardKit 模式:单卡片流式追加
|
|
159
|
+
if (cardkitCtrl)
|
|
160
|
+
await cardkitCtrl.append(block.text);
|
|
161
|
+
// Update 模式:流式追加
|
|
162
|
+
else if (streamingCard)
|
|
163
|
+
await streamingCard.append(block.text);
|
|
98
164
|
}
|
|
99
165
|
if (block.type === "tool_use" && block.id && block.name) {
|
|
166
|
+
// CardKit 模式:不发工具卡片(单卡片架构)
|
|
167
|
+
if (isCardkitMode) {
|
|
168
|
+
if (SILENT_TOOLS.has(block.name))
|
|
169
|
+
break;
|
|
170
|
+
logger.tool(block.name, formatInput(block.name, block.input ?? {}));
|
|
171
|
+
break;
|
|
172
|
+
}
|
|
100
173
|
if (SILENT_TOOLS.has(block.name))
|
|
101
174
|
break;
|
|
102
175
|
const label = TOOL_LABELS[block.name] ?? `🔧 ${block.name}`;
|
|
@@ -104,21 +177,12 @@ profile // 机器人配置名
|
|
|
104
177
|
const input = block.input;
|
|
105
178
|
const questions = input.questions?.map(q => q.question).join("\n") ?? "";
|
|
106
179
|
if (questions)
|
|
107
|
-
await replyFinalCard(client, chatId, rootMsgId, questions, {
|
|
108
|
-
profile: profile ?? "default",
|
|
109
|
-
cwd,
|
|
110
|
-
sessionId: getSession() ?? "",
|
|
111
|
-
overflow: config.overflow,
|
|
112
|
-
chatId,
|
|
113
|
-
rootMsgId,
|
|
114
|
-
appId: config.feishu.app_id,
|
|
115
|
-
appSecret: config.feishu.app_secret,
|
|
116
|
-
});
|
|
180
|
+
await replyFinalCard(client, chatId, rootMsgId, questions, replyContext, { cardTitle: config.card_title });
|
|
117
181
|
break;
|
|
118
182
|
}
|
|
119
183
|
const detail = formatInput(block.name, block.input ?? {});
|
|
120
184
|
logger.tool(block.name, detail);
|
|
121
|
-
const msgId = await sendToolCard(client, chatId, rootMsgId, label, detail, "running",
|
|
185
|
+
const msgId = await sendToolCard(client, chatId, rootMsgId, label, detail, "running", block.name);
|
|
122
186
|
toolMsgMap.set(block.id, { msgId, label, detail });
|
|
123
187
|
}
|
|
124
188
|
}
|
|
@@ -144,16 +208,58 @@ profile // 机器人配置名
|
|
|
144
208
|
logger.dim(`session saved: ${resultEvent.session_id}`);
|
|
145
209
|
}
|
|
146
210
|
if (textBuffer) {
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
211
|
+
// 计算耗时
|
|
212
|
+
const elapsedSeconds = (Date.now() - startTime) / 1000;
|
|
213
|
+
// 尝试从 SDK result 中提取 token 和 model 信息
|
|
214
|
+
const usage = resultEvent.result?.usage;
|
|
215
|
+
const tokens = usage
|
|
216
|
+
? (usage.input_tokens ?? 0) + (usage.output_tokens ?? 0)
|
|
217
|
+
: undefined;
|
|
218
|
+
const model = resultEvent.result?.model;
|
|
219
|
+
// 解析 thinking
|
|
220
|
+
const thinkingEnabled = config.streaming?.thinking_enabled === true;
|
|
221
|
+
let finalContent;
|
|
222
|
+
let thinking;
|
|
223
|
+
if (thinkingEnabled) {
|
|
224
|
+
const parsed = parseThinking(textBuffer);
|
|
225
|
+
finalContent = parsed.content;
|
|
226
|
+
thinking = parsed.thinking || undefined;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
finalContent = stripThinking(textBuffer);
|
|
230
|
+
}
|
|
231
|
+
// 解析图片(下载外部图片上传到飞书)
|
|
232
|
+
let imageFailedCount = 0;
|
|
233
|
+
if (finalContent && config.image_resolver?.enabled !== false) {
|
|
234
|
+
try {
|
|
235
|
+
const token = await getTenantAccessToken(config.feishu.app_id, config.feishu.app_secret);
|
|
236
|
+
const imgResult = await resolveImages(finalContent, token);
|
|
237
|
+
finalContent = imgResult.content;
|
|
238
|
+
imageFailedCount = imgResult.failed;
|
|
239
|
+
}
|
|
240
|
+
catch (error) {
|
|
241
|
+
console.error("[IMAGE] Image resolution failed:", error);
|
|
242
|
+
// 继续发送,不阻断流程
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
// 构建元数据(一次性构建,避免可变拼接)
|
|
246
|
+
const metadata = buildFooterMetadata(elapsedSeconds, model, tokens, imageFailedCount);
|
|
247
|
+
const completeOptions = {
|
|
248
|
+
metadata,
|
|
249
|
+
thinking,
|
|
250
|
+
cardTitle: config.card_title,
|
|
251
|
+
};
|
|
252
|
+
if (cardkitCtrl) {
|
|
253
|
+
// CardKit 模式:单卡片完成
|
|
254
|
+
await cardkitCtrl.complete(finalContent, completeOptions);
|
|
255
|
+
}
|
|
256
|
+
else if (streamingCard) {
|
|
257
|
+
// Update 模式:最终更新卡片(内部处理 overflow)
|
|
258
|
+
await streamingCard.complete(finalContent, completeOptions);
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
await replyFinalCard(client, chatId, rootMsgId, finalContent, replyContext, completeOptions);
|
|
262
|
+
}
|
|
157
263
|
}
|
|
158
264
|
logger.reply(chatId);
|
|
159
265
|
}
|
package/dist/agent.js.map
CH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