larkcc 0.5.0 → 0.6.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/dist/cardkit.d.ts CHANGED
@@ -3,18 +3,19 @@
3
3
  *
4
4
  * 单卡片架构,对齐飞书官方 OpenClaw 方案。
5
5
  * 全程只有一个卡片消息,通过 CardKit API 实现打字机效果。
6
- * 工具调用不可见,thinking 和最终回答在同一卡片内展示。
6
+ * 工具调用状态作为前缀拼接在流式内容中,thinking 和最终回答在同一卡片内展示。
7
7
  *
8
8
  * API 调用链参考飞书官方 openclaw-lark 项目:
9
9
  * https://github.com/larksuite/openclaw-lark
10
10
  *
11
11
  * 状态机:idle → creating → streaming → completed / aborted
12
12
  *
13
- * API 调用链(对齐官方 SDK):
14
- * 1. POST /cardkit/v1/cards → 创建卡片实体
15
- * 2. im.message.reply({ card_id }) → 发送消息引用卡片
16
- * 3. PUT /cardkit/v1/cards/{id}/elements/{eid}/content → 流式打字机
17
- * 4. PUT /cardkit/v1/cards/{id} 最终更新(关闭 streaming_mode
13
+ * API 调用链(使用 SDK CardKit 客户端):
14
+ * 1. client.cardkit.v1.card.create() → 创建卡片实体
15
+ * 2. im.message.reply({ card_id }) → 发送消息引用卡片
16
+ * 3. client.cardkit.v1.cardElement.content() → 流式打字机
17
+ * 4. client.cardkit.v1.card.settings() 关闭 streaming_mode
18
+ * 5. client.cardkit.v1.card.update() → 最终更新卡片内容
18
19
  */
19
20
  import * as lark from "@larksuiteoapi/node-sdk";
20
21
  import type { ReplyContext } from "./feishu.js";
@@ -22,21 +23,18 @@ import type { CompleteOptions } from "./streaming.js";
22
23
  export declare class CardKitController {
23
24
  private phase;
24
25
  private client;
25
- private appId;
26
- private appSecret;
27
26
  private rootMsgId;
28
27
  private cardTitle;
29
28
  private thinkingEnabled;
30
29
  private context;
31
- private token;
32
30
  private cardId;
33
31
  private readonly streamElementId;
34
32
  private sequence;
33
+ private statusText;
34
+ private apiMutex;
35
35
  private flushCtrl;
36
36
  constructor(params: {
37
37
  client: lark.Client;
38
- appId: string;
39
- appSecret: string;
40
38
  rootMsgId: string;
41
39
  cardTitle: string;
42
40
  thinkingEnabled: boolean;
@@ -49,44 +47,79 @@ export declare class CardKitController {
49
47
  */
50
48
  append(text: string): Promise<void>;
51
49
  /**
52
- * 完成:写入最终内容,关闭流式模式
50
+ * 互斥执行 API 调用,防止 sequence 乱序
51
+ */
52
+ private withMutex;
53
+ /**
54
+ * 两步关闭:关闭 streaming_mode → 更新最终卡片内容(对齐 openclaw-lark)
55
+ */
56
+ private closeAndFinalize;
57
+ /**
58
+ * 设置工具状态文本(拼接在流式内容前缀)
59
+ * 传空字符串清除状态
60
+ */
61
+ updateStatus(text: string): Promise<void>;
62
+ /**
63
+ * 清除工具状态
64
+ */
65
+ clearStatus(): Promise<void>;
66
+ /**
67
+ * 完成:关闭 streaming_mode,写入最终内容
53
68
  */
54
69
  complete(finalContent: string, options?: CompleteOptions): Promise<void>;
55
70
  /**
56
- * 中断
71
+ * 中断:保留已有内容,构建完整终态卡片(对齐 openclaw-lark)
57
72
  */
58
- abort(message: string): Promise<void>;
73
+ abort(options?: {
74
+ content?: string;
75
+ thinking?: string;
76
+ reasoningElapsedMs?: number;
77
+ }): Promise<void>;
59
78
  /**
60
79
  * 卡片是否创建失败(用于降级判断)
61
80
  */
62
81
  isDisabled(): boolean;
82
+ /**
83
+ * 在现有 metadata 后追加降级提示
84
+ */
85
+ private appendFallbackHint;
63
86
  private ensureCardCreated;
64
87
  /**
65
- * 创建 CardKit 卡片实体
88
+ * 创建 CardKit 卡片实体(使用 SDK)
66
89
  *
67
- * POST /cardkit/v1/cards
68
- * body: { type: "card_json", data: "<JSON 2.0 string>" }
90
+ * 对齐 openclaw-lark:
91
+ * - config: streaming_mode, wide_screen_mode, update_multi
92
+ * - summary: 对象格式 { content, i18n_content }
93
+ * - 单元素架构:只有 streaming_content,工具状态作为前缀拼接
69
94
  */
70
95
  private createCardEntity;
71
96
  /**
72
97
  * 通过 IM 消息 API 发送卡片到聊天
73
- *
74
- * content: { type: "card", data: { card_id: "..." } }
75
98
  */
76
99
  private sendCardMessage;
77
100
  /**
78
- * 刷新卡片内容(打字机效果)
79
- *
80
- * PUT /cardkit/v1/cards/{id}/elements/{element_id}/content
81
- * body: { content, sequence }
101
+ * 刷新卡片内容(打字机效果,使用 SDK)
102
+ * 工具状态作为前缀拼接在内容前
82
103
  */
83
104
  private performFlush;
84
105
  /**
85
- * 更新整个卡片
86
- *
87
- * PUT /cardkit/v1/cards/{id}
88
- * body: { card: { type: "card_json", data: "<JSON>" }, sequence }
106
+ * 内容溢出时写入云文档,卡片显示文档链接
107
+ */
108
+ private handleOverflow;
109
+ /**
110
+ * 关闭 streaming_mode(对齐 openclaw-lark 两步关闭的第一步)
111
+ */
112
+ private closeStreamingMode;
113
+ /**
114
+ * 更新整个卡片内容(使用 SDK)
89
115
  */
90
116
  private updateCard;
117
+ /**
118
+ * 构建最终卡片 JSON
119
+ */
91
120
  private buildFinalCard;
121
+ /**
122
+ * 构建 thinking 折叠面板(委托共享函数)
123
+ */
124
+ private buildThinkingElements;
92
125
  }