@zyaochen/weaverbird 0.0.0-stage → 0.1.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/LICENSE +21 -0
- package/README.en.md +418 -0
- package/README.md +418 -2
- package/apps/wb-bot/README.md +118 -0
- package/dist/apps/wb-bot/src/agent-display.js +24 -0
- package/dist/apps/wb-bot/src/agent-registry.js +188 -0
- package/dist/apps/wb-bot/src/approval-gate/audit.js +37 -0
- package/dist/apps/wb-bot/src/approval-gate/cards.js +94 -0
- package/dist/apps/wb-bot/src/approval-gate/hook-env.js +15 -0
- package/dist/apps/wb-bot/src/approval-gate/hook-files.js +311 -0
- package/dist/apps/wb-bot/src/approval-gate/hook-main.js +147 -0
- package/dist/apps/wb-bot/src/approval-gate/notifier.js +29 -0
- package/dist/apps/wb-bot/src/approval-gate/store.js +157 -0
- package/dist/apps/wb-bot/src/binding/migration-runner.js +35 -0
- package/dist/apps/wb-bot/src/binding/migrations/001-add-run-id-agent-id.js +8 -0
- package/dist/apps/wb-bot/src/binding/migrations/002-add-bot-id.js +34 -0
- package/dist/apps/wb-bot/src/binding/migrations/003-inflight-card-agent-id-pk.js +31 -0
- package/dist/apps/wb-bot/src/binding/migrations/004-thread-alias-topic-key.js +31 -0
- package/dist/apps/wb-bot/src/binding/migrations/005-card-entity.js +21 -0
- package/dist/apps/wb-bot/src/binding/migrations/006-group-setting.js +17 -0
- package/dist/apps/wb-bot/src/binding/schema.js +58 -0
- package/dist/apps/wb-bot/src/binding/sleep-sync.js +5 -0
- package/dist/apps/wb-bot/src/binding/store.js +270 -0
- package/dist/apps/wb-bot/src/binding/task-index.js +127 -0
- package/dist/apps/wb-bot/src/boot/entry-path.js +9 -0
- package/dist/apps/wb-bot/src/boot/integrity.js +47 -0
- package/dist/apps/wb-bot/src/boot/logger.js +44 -0
- package/dist/apps/wb-bot/src/captain/bot-discovery.js +42 -0
- package/dist/apps/wb-bot/src/captain/captain-context.js +26 -0
- package/dist/apps/wb-bot/src/captain/captain-gate.js +9 -0
- package/dist/apps/wb-bot/src/captain/captain-status.js +101 -0
- package/dist/apps/wb-bot/src/captain/captain-stop-all.js +72 -0
- package/dist/apps/wb-bot/src/captain/list-bots.js +39 -0
- package/dist/apps/wb-bot/src/cli/doctor.js +105 -0
- package/dist/apps/wb-bot/src/cli/init.js +122 -0
- package/dist/apps/wb-bot/src/cli/parse-args.js +31 -0
- package/dist/apps/wb-bot/src/cli/preflight.js +9 -0
- package/dist/apps/wb-bot/src/cli/setup-checklist.js +10 -0
- package/dist/apps/wb-bot/src/commands/health.js +328 -0
- package/dist/apps/wb-bot/src/commands/history.js +100 -0
- package/dist/apps/wb-bot/src/commands/logs.js +91 -0
- package/dist/apps/wb-bot/src/commands/parser.js +43 -0
- package/dist/apps/wb-bot/src/commands/queue-metrics.js +24 -0
- package/dist/apps/wb-bot/src/commands/resume.js +48 -0
- package/dist/apps/wb-bot/src/commands/router.js +299 -0
- package/dist/apps/wb-bot/src/commands/status.js +77 -0
- package/dist/apps/wb-bot/src/commands/tasks.js +106 -0
- package/dist/apps/wb-bot/src/commands/wb-approval.js +86 -0
- package/dist/apps/wb-bot/src/commands/wb-audit.js +46 -0
- package/dist/apps/wb-bot/src/commands/wb-mute.js +84 -0
- package/dist/apps/wb-bot/src/commands/wb-sync.js +58 -0
- package/dist/apps/wb-bot/src/config/approval-code-owners.js +95 -0
- package/dist/apps/wb-bot/src/config/bot-env.js +80 -0
- package/dist/apps/wb-bot/src/config/config-paths.js +16 -0
- package/dist/apps/wb-bot/src/config/env.js +43 -0
- package/dist/apps/wb-bot/src/config/lark-credentials.js +14 -0
- package/dist/apps/wb-bot/src/e2e/preflight-env.js +147 -0
- package/dist/apps/wb-bot/src/e2e/preflight-main.js +12 -0
- package/dist/apps/wb-bot/src/feishu/admin-alert.js +94 -0
- package/dist/apps/wb-bot/src/feishu/artifacts.js +95 -0
- package/dist/apps/wb-bot/src/feishu/bot-identity.js +38 -0
- package/dist/apps/wb-bot/src/feishu/card-pipeline.js +121 -0
- package/dist/apps/wb-bot/src/feishu/card-renderer.js +360 -0
- package/dist/apps/wb-bot/src/feishu/card-transport.js +294 -0
- package/dist/apps/wb-bot/src/feishu/chat-mode-cache.js +47 -0
- package/dist/apps/wb-bot/src/feishu/completion-push.js +30 -0
- package/dist/apps/wb-bot/src/feishu/doc-comment.js +183 -0
- package/dist/apps/wb-bot/src/feishu/event-handler.js +2634 -0
- package/dist/apps/wb-bot/src/feishu/events-file-reader.js +162 -0
- package/dist/apps/wb-bot/src/feishu/inbound-context.js +53 -0
- package/dist/apps/wb-bot/src/feishu/keepalive.js +85 -0
- package/dist/apps/wb-bot/src/feishu/log-redact.js +20 -0
- package/dist/apps/wb-bot/src/feishu/markdown-style.js +95 -0
- package/dist/apps/wb-bot/src/feishu/media-cache.js +92 -0
- package/dist/apps/wb-bot/src/feishu/message-parser.js +126 -0
- package/dist/apps/wb-bot/src/feishu/pending-queue.js +133 -0
- package/dist/apps/wb-bot/src/feishu/reaction.js +44 -0
- package/dist/apps/wb-bot/src/feishu/reverse-at-im-handler.js +345 -0
- package/dist/apps/wb-bot/src/feishu/run-state.js +30 -0
- package/dist/apps/wb-bot/src/feishu/session-short-id.js +9 -0
- package/dist/apps/wb-bot/src/feishu/stream-state.js +72 -0
- package/dist/apps/wb-bot/src/feishu/topic-key.js +34 -0
- package/dist/apps/wb-bot/src/feishu/transport.js +768 -0
- package/dist/apps/wb-bot/src/feishu/wb-runner-spawner.js +84 -0
- package/dist/apps/wb-bot/src/heartbeat/bot-heartbeat.js +20 -0
- package/dist/apps/wb-bot/src/main.js +144 -0
- package/dist/apps/wb-bot/src/multi/discovery.js +53 -0
- package/dist/apps/wb-bot/src/multi/main.js +57 -0
- package/dist/apps/wb-bot/src/multi/parse-args.js +17 -0
- package/dist/apps/wb-bot/src/multi/supervisor.js +288 -0
- package/dist/apps/wb-bot/src/run-observability/orchestrator.js +61 -0
- package/dist/apps/wb-bot/src/security/bot-id-validator.js +18 -0
- package/dist/apps/wb-bot/src/security/cwd-guard.js +72 -0
- package/dist/apps/wb-bot/src/security/env-whitelist.js +94 -0
- package/dist/apps/wb-bot/src/server/wire-up.js +125 -0
- package/dist/apps/wb-cli/src/commands/approval.js +101 -0
- package/dist/apps/wb-cli/src/commands/attach.js +31 -0
- package/dist/apps/wb-cli/src/commands/audit.js +71 -0
- package/dist/apps/wb-cli/src/commands/captain.js +72 -0
- package/dist/apps/wb-cli/src/commands/debug.js +22 -0
- package/dist/apps/wb-cli/src/commands/history.js +75 -0
- package/dist/apps/wb-cli/src/commands/list.js +24 -0
- package/dist/apps/wb-cli/src/commands/logs.js +122 -0
- package/dist/apps/wb-cli/src/commands/resume.js +50 -0
- package/dist/apps/wb-cli/src/commands/runs.js +75 -0
- package/dist/apps/wb-cli/src/commands/status.js +35 -0
- package/dist/apps/wb-cli/src/commands/watch.js +73 -0
- package/dist/apps/wb-cli/src/main.js +312 -0
- package/dist/packages/core/src/agent/claude-code.js +354 -0
- package/dist/packages/core/src/agent/cli-subprocess.js +244 -0
- package/dist/packages/core/src/agent/codex.js +231 -0
- package/dist/packages/core/src/agent/index.js +5 -0
- package/dist/packages/core/src/agent/registry.js +47 -0
- package/dist/packages/core/src/agent/types.js +1 -0
- package/dist/packages/core/src/approval-gate/audit.js +16 -0
- package/dist/packages/core/src/approval-gate/contracts.js +26 -0
- package/dist/packages/core/src/approval-gate/matcher.js +112 -0
- package/dist/packages/core/src/audit-pipe/audit-pipe-main.js +38 -0
- package/dist/packages/core/src/audit-pipe/bitable-sink.js +156 -0
- package/dist/packages/core/src/audit-pipe/config.js +105 -0
- package/dist/packages/core/src/audit-pipe/contracts.js +33 -0
- package/dist/packages/core/src/audit-pipe/index.js +2 -0
- package/dist/packages/core/src/audit-pipe/mirror-sink.js +21 -0
- package/dist/packages/core/src/audit-pipe/normalizer.js +129 -0
- package/dist/packages/core/src/audit-pipe/orchestrator.js +252 -0
- package/dist/packages/core/src/audit-pipe/parser.js +24 -0
- package/dist/packages/core/src/audit-pipe/tailer.js +46 -0
- package/dist/packages/core/src/audit-pipe/wal.js +71 -0
- package/dist/packages/core/src/calendar-hook/config.js +45 -0
- package/dist/packages/core/src/calendar-hook/contracts.js +66 -0
- package/dist/packages/core/src/calendar-hook/index.js +5 -0
- package/dist/packages/core/src/calendar-hook/scheduler.js +169 -0
- package/dist/packages/core/src/calendar-hook/service.js +189 -0
- package/dist/packages/core/src/calendar-hook/transport.js +66 -0
- package/dist/packages/core/src/captain/captain-service.js +160 -0
- package/dist/packages/core/src/captain/command-catalog.js +41 -0
- package/dist/packages/core/src/captain/concurrency-config.js +10 -0
- package/dist/packages/core/src/captain/concurrency-queue-index.js +94 -0
- package/dist/packages/core/src/captain/concurrency-queue-store.js +43 -0
- package/dist/packages/core/src/captain/contracts.js +102 -0
- package/dist/packages/core/src/captain/cwd-inference.js +29 -0
- package/dist/packages/core/src/captain/enqueue-or-spawn.js +63 -0
- package/dist/packages/core/src/captain/index.js +27 -0
- package/dist/packages/core/src/captain/queue-metrics/aggregator.js +98 -0
- package/dist/packages/core/src/captain/queue-metrics/contracts.js +42 -0
- package/dist/packages/core/src/captain/queue-metrics/event-store.js +26 -0
- package/dist/packages/core/src/captain/session-store.js +429 -0
- package/dist/packages/core/src/captain/toml-loader.js +86 -0
- package/dist/packages/core/src/config/errors.js +15 -0
- package/dist/packages/core/src/config/registry.js +34 -0
- package/dist/packages/core/src/errors/codes.js +98 -0
- package/dist/packages/core/src/group-sync/autodoc.js +166 -0
- package/dist/packages/core/src/group-sync/config.js +45 -0
- package/dist/packages/core/src/group-sync/contracts.js +126 -0
- package/dist/packages/core/src/group-sync/dispatch.js +163 -0
- package/dist/packages/core/src/group-sync/index.js +9 -0
- package/dist/packages/core/src/group-sync/revdiff.js +138 -0
- package/dist/packages/core/src/group-sync/scheduler.js +93 -0
- package/dist/packages/core/src/group-sync/service.js +79 -0
- package/dist/packages/core/src/group-sync/transport.js +97 -0
- package/dist/packages/core/src/group-sync/xref.js +139 -0
- package/dist/packages/core/src/index.js +23 -0
- package/dist/packages/core/src/minutes/adapter.js +187 -0
- package/dist/packages/core/src/minutes/client.js +46 -0
- package/dist/packages/core/src/minutes/contracts.js +36 -0
- package/dist/packages/core/src/minutes/index.js +3 -0
- package/dist/packages/core/src/paths.js +158 -0
- package/dist/packages/core/src/periodic-tasks/config.js +45 -0
- package/dist/packages/core/src/periodic-tasks/contracts.js +75 -0
- package/dist/packages/core/src/periodic-tasks/index.js +4 -0
- package/dist/packages/core/src/periodic-tasks/orchestrator.js +249 -0
- package/dist/packages/core/src/periodic-tasks/state.js +29 -0
- package/dist/packages/core/src/reverse-channel/attach-handler.js +108 -0
- package/dist/packages/core/src/reverse-channel/audit-encoder.js +61 -0
- package/dist/packages/core/src/reverse-channel/contracts.js +136 -0
- package/dist/packages/core/src/reverse-channel/echo-tailer.js +36 -0
- package/dist/packages/core/src/reverse-channel/handoff.js +238 -0
- package/dist/packages/core/src/reverse-channel/index.js +5 -0
- package/dist/packages/core/src/reverse-channel/ipc-client.js +110 -0
- package/dist/packages/core/src/reverse-channel/ipc-control-handler.js +27 -0
- package/dist/packages/core/src/reverse-channel/ipc-server.js +127 -0
- package/dist/packages/core/src/reverse-channel/mute-registry.js +113 -0
- package/dist/packages/core/src/reverse-channel/pid-resolver.js +41 -0
- package/dist/packages/core/src/reverse-channel/reverse-at-handler.js +19 -0
- package/dist/packages/core/src/reverse-channel/sla-tracker.js +51 -0
- package/dist/packages/core/src/run-observability/alert-card-renderer.js +24 -0
- package/dist/packages/core/src/run-observability/alert-pusher.js +47 -0
- package/dist/packages/core/src/run-observability/card-refresher.js +31 -0
- package/dist/packages/core/src/run-observability/card-renderer-progress.js +33 -0
- package/dist/packages/core/src/run-observability/config-loader.js +23 -0
- package/dist/packages/core/src/run-observability/contracts.js +107 -0
- package/dist/packages/core/src/run-observability/exit-code-detector.js +16 -0
- package/dist/packages/core/src/run-observability/finalizer.js +114 -0
- package/dist/packages/core/src/run-observability/index.js +12 -0
- package/dist/packages/core/src/run-observability/obs-toggle-handler.js +29 -0
- package/dist/packages/core/src/run-observability/progress-collector.js +53 -0
- package/dist/packages/core/src/run-observability/progress-store.js +100 -0
- package/dist/packages/core/src/run-observability/silent-timeout-detector.js +12 -0
- package/dist/packages/core/src/run-registry/bitable-writer.js +308 -0
- package/dist/packages/core/src/run-registry/config.js +77 -0
- package/dist/packages/core/src/run-registry/contracts.js +114 -0
- package/dist/packages/core/src/run-registry/doc-sink-classifier.js +0 -0
- package/dist/packages/core/src/run-registry/doc-sink-transport.js +63 -0
- package/dist/packages/core/src/run-registry/doc-sink.js +200 -0
- package/dist/packages/core/src/run-registry/extractor.js +40 -0
- package/dist/packages/core/src/run-registry/index.js +11 -0
- package/dist/packages/core/src/run-registry/inherit.js +11 -0
- package/dist/packages/core/src/run-registry/orchestrator.js +86 -0
- package/dist/packages/core/src/run-registry/run-registry-main.js +38 -0
- package/dist/packages/core/src/run-registry/tailer.js +390 -0
- package/dist/packages/core/src/run-registry/wal.js +106 -0
- package/dist/packages/core/src/runner/event-replay.js +65 -0
- package/dist/packages/core/src/runner/wb-runner-main.js +27 -0
- package/dist/packages/core/src/runner/wb-runner.js +237 -0
- package/dist/packages/core/src/util/entry-module.js +21 -0
- package/dist/packages/core/src/util/ndjson-rotation.js +99 -0
- package/package.json +76 -4
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
import { STREAMING_CONFIG, withoutStreaming } from './card-renderer.js';
|
|
2
|
+
/**
|
|
3
|
+
* 卡片出口. 带 `config.streaming_mode` 的运行卡走 CardKit 卡片实体, 其余卡片照旧走消息接口.
|
|
4
|
+
*
|
|
5
|
+
* 降级链 (每一级失败都记日志再往下走, 不吞错):
|
|
6
|
+
* - L0 元素流式: 结构没变时只把变了的槽位文本推给 `cardElement.content`, 正文是打字机效果
|
|
7
|
+
* - L1 整卡更新: 结构变了 / L0 失败 / 结束时, `card.update` 整卡替换 (结束前先关流式)
|
|
8
|
+
* - L2 消息接口: 创建实体失败、或实体更新出现不可重试错误时, 回到 `im.message.reply/patch`
|
|
9
|
+
*
|
|
10
|
+
* CardKit 的每次写都要带严格递增的 sequence; 先占号落库再调用, 重启后从库里的值往后接.
|
|
11
|
+
*/
|
|
12
|
+
export class FeishuApiError extends Error {
|
|
13
|
+
operation;
|
|
14
|
+
code;
|
|
15
|
+
detail;
|
|
16
|
+
constructor(operation, code, detail) {
|
|
17
|
+
super(`${operation} failed: code=${code} msg=${detail}`);
|
|
18
|
+
this.operation = operation;
|
|
19
|
+
this.code = code;
|
|
20
|
+
this.detail = detail;
|
|
21
|
+
this.name = 'FeishuApiError';
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export function feishuErrorCode(error) {
|
|
25
|
+
if (error instanceof FeishuApiError)
|
|
26
|
+
return error.code;
|
|
27
|
+
if (typeof error !== 'object' || error === null)
|
|
28
|
+
return undefined;
|
|
29
|
+
const record = error;
|
|
30
|
+
const code = record.response?.data?.code ?? record.code;
|
|
31
|
+
return typeof code === 'number' ? code : undefined;
|
|
32
|
+
}
|
|
33
|
+
/** 流式模式超时 (默认 10 分钟自动关闭) / 已关闭: 重开后重试一次. */
|
|
34
|
+
const STREAMING_CLOSED_CODES = new Set([200850, 300309]);
|
|
35
|
+
/** 频控 / 卡片锁: 交给 CardPipeline 退避重试, 不降级. */
|
|
36
|
+
const RETRYABLE_CODES = new Set([230020, 230099, 99991400]);
|
|
37
|
+
const MAX_ELEMENT_FAILURES = 3;
|
|
38
|
+
export function isStreamingCard(card) {
|
|
39
|
+
const config = card['config'];
|
|
40
|
+
return typeof config === 'object' && config !== null && config['streaming_mode'] === true;
|
|
41
|
+
}
|
|
42
|
+
function bodyElements(card) {
|
|
43
|
+
const body = card['body'];
|
|
44
|
+
if (typeof body !== 'object' || body === null)
|
|
45
|
+
return [];
|
|
46
|
+
const elements = body.elements;
|
|
47
|
+
return Array.isArray(elements) ? elements : [];
|
|
48
|
+
}
|
|
49
|
+
function slotContents(card) {
|
|
50
|
+
const slots = new Map();
|
|
51
|
+
for (const element of bodyElements(card)) {
|
|
52
|
+
if (element.tag === 'markdown' && typeof element.element_id === 'string') {
|
|
53
|
+
slots.set(element.element_id, typeof element.content === 'string' ? element.content : '');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return slots;
|
|
57
|
+
}
|
|
58
|
+
/** 去掉槽位文本与 config.summary 之后的骨架; 骨架相同才能只更新槽位. */
|
|
59
|
+
function skeleton(card) {
|
|
60
|
+
return JSON.stringify(card, (key, value) => {
|
|
61
|
+
if (key === 'summary')
|
|
62
|
+
return undefined;
|
|
63
|
+
if (key === 'elements' && Array.isArray(value)) {
|
|
64
|
+
return value.map((element) => (element && element.tag === 'markdown' && typeof element.element_id === 'string' ? { ...element, content: '' } : element));
|
|
65
|
+
}
|
|
66
|
+
return value;
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
export class FeishuCardTransport {
|
|
70
|
+
api;
|
|
71
|
+
store;
|
|
72
|
+
options;
|
|
73
|
+
entries = new Map();
|
|
74
|
+
constructor(api, store, options) {
|
|
75
|
+
this.api = api;
|
|
76
|
+
this.store = store;
|
|
77
|
+
this.options = options;
|
|
78
|
+
}
|
|
79
|
+
/** 该消息是否是 CardKit 流式卡 (调用方据此选更短的刷新间隔). */
|
|
80
|
+
isStreamingCard(messageId) {
|
|
81
|
+
const entry = this.entry(messageId);
|
|
82
|
+
return Boolean(entry && !entry.legacy && entry.streaming);
|
|
83
|
+
}
|
|
84
|
+
async reply(messageId, card, inThread = false) {
|
|
85
|
+
if (!this.options.streaming || !isStreamingCard(card)) {
|
|
86
|
+
return this.api.replyMessageCard(messageId, withoutStreaming(card), inThread);
|
|
87
|
+
}
|
|
88
|
+
let cardId;
|
|
89
|
+
try {
|
|
90
|
+
cardId = await this.api.createCard(JSON.stringify(card));
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
this.options.logger.warn({ messageId, error: describe(error) }, 'cardkit create failed, falling back to message card');
|
|
94
|
+
return this.api.replyMessageCard(messageId, withoutStreaming(card), inThread);
|
|
95
|
+
}
|
|
96
|
+
let replyMessageId;
|
|
97
|
+
try {
|
|
98
|
+
replyMessageId = await this.api.replyWithCardId(messageId, cardId, inThread);
|
|
99
|
+
}
|
|
100
|
+
catch (error) {
|
|
101
|
+
this.options.logger.warn({ messageId, cardId, error: describe(error) }, 'reply with card_id failed, falling back to message card');
|
|
102
|
+
return this.api.replyMessageCard(messageId, withoutStreaming(card), inThread);
|
|
103
|
+
}
|
|
104
|
+
// 创建实体时 sequence 视为 0, 之后的每次写从 1 开始.
|
|
105
|
+
const entry = { cardId, sequence: 0, streaming: true, last: card, lastJson: JSON.stringify(card), elementFailures: 0, legacy: false };
|
|
106
|
+
this.entries.set(replyMessageId, entry);
|
|
107
|
+
this.store.save(replyMessageId, { cardId, sequence: 0, streaming: true });
|
|
108
|
+
this.options.logger.info({ messageId, replyMessageId, cardId }, 'replied with cardkit streaming card');
|
|
109
|
+
return replyMessageId;
|
|
110
|
+
}
|
|
111
|
+
async update(messageId, card) {
|
|
112
|
+
const entry = this.entry(messageId);
|
|
113
|
+
if (!entry || entry.legacy) {
|
|
114
|
+
await this.api.patchMessageCard(messageId, withoutStreaming(card));
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const json = JSON.stringify(card);
|
|
118
|
+
if (json === entry.lastJson)
|
|
119
|
+
return;
|
|
120
|
+
const live = isStreamingCard(card);
|
|
121
|
+
if (live && entry.streaming && entry.last && entry.elementFailures < MAX_ELEMENT_FAILURES && skeleton(entry.last) === skeleton(card)) {
|
|
122
|
+
try {
|
|
123
|
+
await this.streamSlots(messageId, entry, card);
|
|
124
|
+
this.remember(entry, card, json);
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
if (isRetryable(error))
|
|
129
|
+
throw error;
|
|
130
|
+
entry.elementFailures += 1;
|
|
131
|
+
this.options.logger.warn({ messageId, cardId: entry.cardId, failures: entry.elementFailures, error: describe(error) }, 'cardkit element stream failed, using full update');
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
try {
|
|
135
|
+
await this.updateFull(messageId, entry, card, live);
|
|
136
|
+
this.remember(entry, card, json);
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
if (isRetryable(error))
|
|
140
|
+
throw error;
|
|
141
|
+
this.options.logger.error({ messageId, cardId: entry.cardId, error: describe(error) }, 'cardkit full update failed, falling back to message patch');
|
|
142
|
+
try {
|
|
143
|
+
await this.api.patchMessageCard(messageId, withoutStreaming(card));
|
|
144
|
+
}
|
|
145
|
+
catch (patchError) {
|
|
146
|
+
this.options.logger.error({ messageId, error: describe(patchError) }, 'message patch fallback failed');
|
|
147
|
+
throw error;
|
|
148
|
+
}
|
|
149
|
+
entry.legacy = true;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
entry(messageId) {
|
|
153
|
+
const cached = this.entries.get(messageId);
|
|
154
|
+
if (cached)
|
|
155
|
+
return cached;
|
|
156
|
+
const stored = this.store.get(messageId);
|
|
157
|
+
if (!stored)
|
|
158
|
+
return undefined;
|
|
159
|
+
const entry = { ...stored, elementFailures: 0, legacy: false };
|
|
160
|
+
this.entries.set(messageId, entry);
|
|
161
|
+
return entry;
|
|
162
|
+
}
|
|
163
|
+
nextSequence(messageId, entry) {
|
|
164
|
+
entry.sequence += 1;
|
|
165
|
+
this.store.save(messageId, { cardId: entry.cardId, sequence: entry.sequence, streaming: entry.streaming });
|
|
166
|
+
return entry.sequence;
|
|
167
|
+
}
|
|
168
|
+
setStreaming(messageId, entry, streaming) {
|
|
169
|
+
entry.streaming = streaming;
|
|
170
|
+
return this.api.setStreaming(entry.cardId, streaming, this.nextSequence(messageId, entry));
|
|
171
|
+
}
|
|
172
|
+
async streamSlots(messageId, entry, card) {
|
|
173
|
+
const previous = slotContents(entry.last ?? {});
|
|
174
|
+
for (const [elementId, content] of slotContents(card)) {
|
|
175
|
+
if (previous.get(elementId) === content)
|
|
176
|
+
continue;
|
|
177
|
+
try {
|
|
178
|
+
await this.api.setElementContent(entry.cardId, elementId, content, this.nextSequence(messageId, entry));
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
if (!STREAMING_CLOSED_CODES.has(feishuErrorCode(error) ?? -1))
|
|
182
|
+
throw error;
|
|
183
|
+
this.options.logger.info({ messageId, cardId: entry.cardId }, 'cardkit streaming closed, re-enabling');
|
|
184
|
+
await this.setStreaming(messageId, entry, true);
|
|
185
|
+
await this.api.setElementContent(entry.cardId, elementId, content, this.nextSequence(messageId, entry));
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
async updateFull(messageId, entry, card, live) {
|
|
190
|
+
if (!live && entry.streaming) {
|
|
191
|
+
// 按钮等交互元素要在关掉流式之后才能改; 关失败不影响整卡替换, 只记录.
|
|
192
|
+
try {
|
|
193
|
+
await this.setStreaming(messageId, entry, false);
|
|
194
|
+
}
|
|
195
|
+
catch (error) {
|
|
196
|
+
this.options.logger.warn({ messageId, cardId: entry.cardId, error: describe(error) }, 'cardkit disable streaming failed');
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
const payload = JSON.stringify(live ? card : withoutStreaming(card));
|
|
200
|
+
try {
|
|
201
|
+
await this.api.updateCard(entry.cardId, payload, this.nextSequence(messageId, entry));
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
if (!live || !STREAMING_CLOSED_CODES.has(feishuErrorCode(error) ?? -1))
|
|
205
|
+
throw error;
|
|
206
|
+
await this.setStreaming(messageId, entry, true);
|
|
207
|
+
await this.api.updateCard(entry.cardId, payload, this.nextSequence(messageId, entry));
|
|
208
|
+
}
|
|
209
|
+
entry.streaming = live;
|
|
210
|
+
}
|
|
211
|
+
remember(entry, card, json) {
|
|
212
|
+
entry.last = card;
|
|
213
|
+
entry.lastJson = json;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
function isRetryable(error) {
|
|
217
|
+
return RETRYABLE_CODES.has(feishuErrorCode(error) ?? -1);
|
|
218
|
+
}
|
|
219
|
+
function describe(error) {
|
|
220
|
+
return { message: error instanceof Error ? error.message : String(error), code: feishuErrorCode(error) };
|
|
221
|
+
}
|
|
222
|
+
function assertOk(operation, response) {
|
|
223
|
+
if (response && typeof response.code === 'number' && response.code !== 0) {
|
|
224
|
+
throw new FeishuApiError(operation, response.code, response.msg ?? '');
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
/** SDK → CardKitApi. 业务码非 0 统一抛 FeishuApiError, 让上面的降级逻辑按 code 判断. */
|
|
228
|
+
export function createCardKitApi(client) {
|
|
229
|
+
return {
|
|
230
|
+
async createCard(cardJson) {
|
|
231
|
+
const response = await client.cardkit.v1.card.create({ data: { type: 'card_json', data: cardJson } });
|
|
232
|
+
assertOk('cardkit.card.create', response);
|
|
233
|
+
const cardId = response?.data?.card_id;
|
|
234
|
+
if (!cardId)
|
|
235
|
+
throw new FeishuApiError('cardkit.card.create', -1, 'no card_id in response');
|
|
236
|
+
return cardId;
|
|
237
|
+
},
|
|
238
|
+
async updateCard(cardId, cardJson, sequence) {
|
|
239
|
+
const response = await client.cardkit.v1.card.update({
|
|
240
|
+
path: { card_id: cardId },
|
|
241
|
+
data: { card: { type: 'card_json', data: cardJson }, sequence },
|
|
242
|
+
});
|
|
243
|
+
assertOk('cardkit.card.update', response);
|
|
244
|
+
},
|
|
245
|
+
async setStreaming(cardId, streaming, sequence) {
|
|
246
|
+
const config = streaming ? { streaming_mode: true, streaming_config: STREAMING_CONFIG } : { streaming_mode: false };
|
|
247
|
+
const response = await client.cardkit.v1.card.settings({
|
|
248
|
+
path: { card_id: cardId },
|
|
249
|
+
data: { settings: JSON.stringify({ config }), sequence },
|
|
250
|
+
});
|
|
251
|
+
assertOk('cardkit.card.settings', response);
|
|
252
|
+
},
|
|
253
|
+
async setElementContent(cardId, elementId, content, sequence) {
|
|
254
|
+
const response = await client.cardkit.v1.cardElement.content({
|
|
255
|
+
path: { card_id: cardId, element_id: elementId },
|
|
256
|
+
data: { content, sequence },
|
|
257
|
+
});
|
|
258
|
+
assertOk('cardkit.cardElement.content', response);
|
|
259
|
+
},
|
|
260
|
+
async replyWithCardId(messageId, cardId, inThread) {
|
|
261
|
+
const response = await client.im.v1.message.reply({
|
|
262
|
+
path: { message_id: messageId },
|
|
263
|
+
data: {
|
|
264
|
+
msg_type: 'interactive',
|
|
265
|
+
content: JSON.stringify({ type: 'card', data: { card_id: cardId } }),
|
|
266
|
+
...(inThread ? { reply_in_thread: true } : {}),
|
|
267
|
+
},
|
|
268
|
+
});
|
|
269
|
+
assertOk('im.message.reply', response);
|
|
270
|
+
const replyMessageId = response?.data?.message_id;
|
|
271
|
+
if (!replyMessageId)
|
|
272
|
+
throw new FeishuApiError('im.message.reply', -1, 'no message_id in response');
|
|
273
|
+
return replyMessageId;
|
|
274
|
+
},
|
|
275
|
+
async replyMessageCard(messageId, card, inThread) {
|
|
276
|
+
const response = await client.im.v1.message.reply({
|
|
277
|
+
path: { message_id: messageId },
|
|
278
|
+
data: { msg_type: 'interactive', content: JSON.stringify(card), ...(inThread ? { reply_in_thread: true } : {}) },
|
|
279
|
+
});
|
|
280
|
+
assertOk('im.message.reply', response);
|
|
281
|
+
return response?.data?.message_id ?? messageId;
|
|
282
|
+
},
|
|
283
|
+
async patchMessageCard(messageId, card) {
|
|
284
|
+
const response = await client.im.v1.message.patch({
|
|
285
|
+
path: { message_id: messageId },
|
|
286
|
+
data: { content: JSON.stringify(card) },
|
|
287
|
+
});
|
|
288
|
+
assertOk('im.message.patch', response);
|
|
289
|
+
},
|
|
290
|
+
};
|
|
291
|
+
}
|
|
292
|
+
export function cardStreamingEnabled(env = process.env) {
|
|
293
|
+
return env['WB_CARD_STREAMING'] !== '0';
|
|
294
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 话题群判定. 消息事件里不带群模式, 只能 `im.v1.chat.get` 查一次; 群模式在群的生命周期内不变,
|
|
3
|
+
* 按 chat_id 缓存. 查询失败按普通群处理且不写缓存, 下一条消息再试.
|
|
4
|
+
*/
|
|
5
|
+
export class ChatModeCache {
|
|
6
|
+
fetchChat;
|
|
7
|
+
onError;
|
|
8
|
+
cache = new Map();
|
|
9
|
+
constructor(fetchChat, onError = () => { }) {
|
|
10
|
+
this.fetchChat = fetchChat;
|
|
11
|
+
this.onError = onError;
|
|
12
|
+
}
|
|
13
|
+
async resolve(chatId) {
|
|
14
|
+
const hit = this.cache.get(chatId);
|
|
15
|
+
if (hit)
|
|
16
|
+
return hit;
|
|
17
|
+
try {
|
|
18
|
+
const info = await this.fetchChat(chatId);
|
|
19
|
+
// 老话题群 chat_mode=topic; 新版 "话题模式" 群是 chat_mode=group + group_message_type=thread.
|
|
20
|
+
const mode = info?.chat_mode === 'topic' || info?.group_message_type === 'thread' ? 'topic' : 'group';
|
|
21
|
+
this.cache.set(chatId, mode);
|
|
22
|
+
return mode;
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
this.onError(chatId, error);
|
|
26
|
+
return 'group';
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* 回复要挂进话题: 群消息默认都挂 (每条顶层群消息本来就是独立会话, 话题里追问仍落在同一个 root scope);
|
|
32
|
+
* groupDefault=false (WB_GROUP_REPLY_IN_THREAD=0) 时只有话题里的消息和话题群消息才挂. 单聊从不挂.
|
|
33
|
+
*/
|
|
34
|
+
export async function shouldReplyInThread(message, cache, groupDefault = true) {
|
|
35
|
+
if (message.chatType === 'p2p')
|
|
36
|
+
return false;
|
|
37
|
+
if (message.threadId)
|
|
38
|
+
return true;
|
|
39
|
+
if (!message.chatType || !message.chatId)
|
|
40
|
+
return false;
|
|
41
|
+
if (groupDefault)
|
|
42
|
+
return true;
|
|
43
|
+
return (await cache.resolve(message.chatId)) === 'topic';
|
|
44
|
+
}
|
|
45
|
+
export function groupRepliesInThread(env = process.env) {
|
|
46
|
+
return env['WB_GROUP_REPLY_IN_THREAD'] !== '0';
|
|
47
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const DEFAULT_THRESHOLD_MS = 300_000;
|
|
2
|
+
export function shouldPushOnDone(input) {
|
|
3
|
+
return input.durationMs >= input.thresholdMs || input.hasFollow;
|
|
4
|
+
}
|
|
5
|
+
export function parsePushThresholdMs(envValue, defaultMs = DEFAULT_THRESHOLD_MS) {
|
|
6
|
+
if (envValue === undefined)
|
|
7
|
+
return defaultMs;
|
|
8
|
+
const parsed = Number.parseInt(envValue, 10);
|
|
9
|
+
if (Number.isNaN(parsed) || parsed < 0)
|
|
10
|
+
return defaultMs;
|
|
11
|
+
return parsed;
|
|
12
|
+
}
|
|
13
|
+
export function formatDurationHuman(ms) {
|
|
14
|
+
const totalSeconds = Math.floor(ms / 1000);
|
|
15
|
+
if (totalSeconds < 60)
|
|
16
|
+
return `${totalSeconds}s`;
|
|
17
|
+
const totalMinutes = Math.floor(totalSeconds / 60);
|
|
18
|
+
const secs = totalSeconds % 60;
|
|
19
|
+
if (totalMinutes < 60) {
|
|
20
|
+
return secs > 0 ? `${totalMinutes}m${secs}s` : `${totalMinutes}m`;
|
|
21
|
+
}
|
|
22
|
+
const hours = Math.floor(totalMinutes / 60);
|
|
23
|
+
const mins = totalMinutes % 60;
|
|
24
|
+
return mins > 0 ? `${hours}h${mins}m` : `${hours}h`;
|
|
25
|
+
}
|
|
26
|
+
export function formatCompletionMessage(displayName, cwd, durationMs) {
|
|
27
|
+
const home = process.env['HOME'] ?? '';
|
|
28
|
+
const shortCwd = (home && cwd.startsWith(home)) ? `~${cwd.slice(home.length)}` : cwd;
|
|
29
|
+
return `✅ ${displayName} · ${shortCwd} · ${formatDurationHuman(durationMs)} · 任务完成`;
|
|
30
|
+
}
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
import { FeishuApiError, feishuErrorCode } from './card-transport.js';
|
|
2
|
+
/**
|
|
3
|
+
* 云文档评论通道: 用户在文档评论里 @bot, 把评论线程交给 agent, 答案以纯文本回在同一线程.
|
|
4
|
+
*
|
|
5
|
+
* 边界 (product-strategy B3 / B5):
|
|
6
|
+
* - 只读评论线程, 不读写文档正文; agent 需要正文时自己用 lark-cli 等工具
|
|
7
|
+
* - 不给 agent 加文档相关的提示词; 评论框不渲染 markdown, 由这里把常见标记去掉
|
|
8
|
+
* - 过程用评论上的 Typing 表情回执, 没有卡片, 也没有停止按钮 (超时由 runHeadless 兜)
|
|
9
|
+
*/
|
|
10
|
+
const SUPPORTED_FILE_TYPES = new Set(['doc', 'docx', 'sheet', 'file']);
|
|
11
|
+
const REPLY_MAX_CHARS = 2000;
|
|
12
|
+
const THREAD_CONTEXT_REPLIES = 10;
|
|
13
|
+
/** 整篇评论没有线程, 不能回复 (只能另起一条评论). */
|
|
14
|
+
const WHOLE_COMMENT_NO_REPLY = 1069302;
|
|
15
|
+
export function replyText(reply) {
|
|
16
|
+
return (reply.content?.elements ?? []).map((element) => {
|
|
17
|
+
if (element.type === 'text_run')
|
|
18
|
+
return element.text_run?.text ?? '';
|
|
19
|
+
if (element.type === 'docs_link')
|
|
20
|
+
return element.docs_link?.url ?? '';
|
|
21
|
+
return '';
|
|
22
|
+
}).join('').trim();
|
|
23
|
+
}
|
|
24
|
+
/** 评论框是纯文本: 去掉标题 / 粗斜体 / 引用 / 行内代码 / 代码块围栏等标记, 保留文字. */
|
|
25
|
+
export function stripMarkdown(text) {
|
|
26
|
+
return text
|
|
27
|
+
.replace(/^```[^\n]*\n?/gm, '')
|
|
28
|
+
.replace(/^#{1,6}\s+/gm, '')
|
|
29
|
+
.replace(/\*\*([^*]+)\*\*/g, '$1')
|
|
30
|
+
.replace(/__([^_]+)__/g, '$1')
|
|
31
|
+
.replace(/(^|[^*])\*([^*\n]+)\*/g, '$1$2')
|
|
32
|
+
.replace(/`([^`]+)`/g, '$1')
|
|
33
|
+
.replace(/^>\s?/gm, '')
|
|
34
|
+
.replace(/^\s*[-*+]\s+/gm, '• ')
|
|
35
|
+
.replace(/\[([^\]]+)\]\(([^)]+)\)/g, '$1 ($2)')
|
|
36
|
+
.replace(/\n{3,}/g, '\n\n')
|
|
37
|
+
.trim();
|
|
38
|
+
}
|
|
39
|
+
export function buildCommentInput(evt, thread, target) {
|
|
40
|
+
const lines = [`> 云文档评论 · https://feishu.cn/${evt.fileType}/${evt.fileToken}`];
|
|
41
|
+
if (thread.quote)
|
|
42
|
+
lines.push(`> 选中原文: ${thread.quote.replace(/\s*\n\s*/g, ' ')}`);
|
|
43
|
+
const earlier = thread.replies.filter((reply) => reply !== target).slice(-THREAD_CONTEXT_REPLIES).map(replyText).filter(Boolean);
|
|
44
|
+
if (earlier.length > 0) {
|
|
45
|
+
lines.push('> 评论线程:');
|
|
46
|
+
for (const text of earlier)
|
|
47
|
+
lines.push(`> - ${text.replace(/\s*\n\s*/g, ' ')}`);
|
|
48
|
+
}
|
|
49
|
+
return `${lines.join('\n')}\n\n${replyText(target)}`;
|
|
50
|
+
}
|
|
51
|
+
export class DocCommentChannel {
|
|
52
|
+
deps;
|
|
53
|
+
/** 自己发出的评论回复, 用来挡住回推给自己的事件. */
|
|
54
|
+
ownReplyIds = new Set();
|
|
55
|
+
seen = new Set();
|
|
56
|
+
constructor(deps) {
|
|
57
|
+
this.deps = deps;
|
|
58
|
+
}
|
|
59
|
+
async handle(evt) {
|
|
60
|
+
const { api, logger } = this.deps;
|
|
61
|
+
const key = `${evt.fileToken}:${evt.commentId}:${evt.replyId ?? ''}`;
|
|
62
|
+
if (!evt.mentionedBot || this.seen.has(key))
|
|
63
|
+
return;
|
|
64
|
+
if (evt.operator.openId === this.deps.botOpenId || (evt.replyId && this.ownReplyIds.has(evt.replyId)))
|
|
65
|
+
return;
|
|
66
|
+
if (!SUPPORTED_FILE_TYPES.has(evt.fileType)) {
|
|
67
|
+
logger.info({ fileType: evt.fileType }, 'doc comment skipped: unsupported file type');
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
this.remember(this.seen, key);
|
|
71
|
+
const thread = await api.getThread(evt.fileToken, evt.fileType, evt.commentId);
|
|
72
|
+
const target = (evt.replyId ? thread.replies.find((reply) => reply.reply_id === evt.replyId) : undefined) ?? thread.replies.at(-1);
|
|
73
|
+
if (!target || !replyText(target)) {
|
|
74
|
+
logger.info({ commentId: evt.commentId }, 'doc comment skipped: empty question');
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
const typingOn = target.reply_id ? await this.typing(evt, target.reply_id, true) : false;
|
|
78
|
+
try {
|
|
79
|
+
const result = await this.deps.run({
|
|
80
|
+
userOpenId: evt.operator.openId,
|
|
81
|
+
threadId: `doc:${evt.fileToken}`,
|
|
82
|
+
prompt: buildCommentInput(evt, thread, target),
|
|
83
|
+
});
|
|
84
|
+
let answer = result.error ? `⚠️ ${result.error}` : stripMarkdown(result.text) || '(没有输出内容)';
|
|
85
|
+
if (answer.length > REPLY_MAX_CHARS)
|
|
86
|
+
answer = `${answer.slice(0, REPLY_MAX_CHARS - 1)}…`;
|
|
87
|
+
await this.post(evt, thread, answer);
|
|
88
|
+
}
|
|
89
|
+
finally {
|
|
90
|
+
if (typingOn && target.reply_id)
|
|
91
|
+
await this.typing(evt, target.reply_id, false);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
async post(evt, thread, text) {
|
|
95
|
+
const { api } = this.deps;
|
|
96
|
+
if (!thread.isWhole) {
|
|
97
|
+
try {
|
|
98
|
+
const replyId = await api.replyInThread(evt.fileToken, evt.fileType, evt.commentId, text);
|
|
99
|
+
if (replyId)
|
|
100
|
+
this.remember(this.ownReplyIds, replyId);
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
catch (error) {
|
|
104
|
+
if (feishuErrorCode(error) !== WHOLE_COMMENT_NO_REPLY)
|
|
105
|
+
throw error;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
const commentReplyId = await api.createComment(evt.fileToken, evt.fileType, text);
|
|
109
|
+
if (commentReplyId)
|
|
110
|
+
this.remember(this.ownReplyIds, commentReplyId);
|
|
111
|
+
}
|
|
112
|
+
/** 表情回执是装饰性的: 失败只记日志. */
|
|
113
|
+
async typing(evt, replyId, on) {
|
|
114
|
+
try {
|
|
115
|
+
await this.deps.api.setTyping(evt.fileToken, evt.fileType, replyId, on);
|
|
116
|
+
return true;
|
|
117
|
+
}
|
|
118
|
+
catch (error) {
|
|
119
|
+
this.deps.logger.warn({ replyId, on, code: feishuErrorCode(error) }, 'doc comment typing reaction failed');
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
remember(set, value) {
|
|
124
|
+
set.add(value);
|
|
125
|
+
if (set.size > 1000) {
|
|
126
|
+
const oldest = set.values().next().value;
|
|
127
|
+
if (oldest !== undefined)
|
|
128
|
+
set.delete(oldest);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
function assertOk(operation, response) {
|
|
133
|
+
if (response && typeof response.code === 'number' && response.code !== 0) {
|
|
134
|
+
throw new FeishuApiError(operation, response.code, response.msg ?? '');
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
function textContent(text) {
|
|
138
|
+
return { elements: [{ type: 'text_run', text_run: { text } }] };
|
|
139
|
+
}
|
|
140
|
+
export function createDocCommentApi(client) {
|
|
141
|
+
return {
|
|
142
|
+
async getThread(fileToken, fileType, commentId) {
|
|
143
|
+
const response = await client.drive.v1.fileComment.get({
|
|
144
|
+
params: { file_type: fileType },
|
|
145
|
+
path: { file_token: fileToken, comment_id: commentId },
|
|
146
|
+
});
|
|
147
|
+
const data = response?.data;
|
|
148
|
+
return {
|
|
149
|
+
replies: (data?.reply_list?.replies ?? []),
|
|
150
|
+
...(data?.quote ? { quote: data.quote } : {}),
|
|
151
|
+
isWhole: Boolean(data?.is_whole),
|
|
152
|
+
};
|
|
153
|
+
},
|
|
154
|
+
async replyInThread(fileToken, fileType, commentId, text) {
|
|
155
|
+
// SDK 没有封装 fileCommentReply.create, 走通用 request (仍带 tenant token).
|
|
156
|
+
const response = await client.request({
|
|
157
|
+
method: 'POST',
|
|
158
|
+
url: `/open-apis/drive/v1/files/${encodeURIComponent(fileToken)}/comments/${encodeURIComponent(commentId)}/replies`,
|
|
159
|
+
params: { file_type: fileType },
|
|
160
|
+
data: { content: textContent(text) },
|
|
161
|
+
});
|
|
162
|
+
assertOk('drive.fileCommentReply.create', response);
|
|
163
|
+
return response?.data?.reply_id;
|
|
164
|
+
},
|
|
165
|
+
async createComment(fileToken, fileType, text) {
|
|
166
|
+
const response = await client.drive.v1.fileComment.create({
|
|
167
|
+
params: { file_type: fileType },
|
|
168
|
+
path: { file_token: fileToken },
|
|
169
|
+
data: { reply_list: { replies: [{ content: textContent(text) }] } },
|
|
170
|
+
});
|
|
171
|
+
return response?.data?.reply_list?.replies?.[0]?.reply_id;
|
|
172
|
+
},
|
|
173
|
+
async setTyping(fileToken, fileType, replyId, on) {
|
|
174
|
+
const response = await client.request({
|
|
175
|
+
method: 'POST',
|
|
176
|
+
url: `/open-apis/drive/v2/files/${encodeURIComponent(fileToken)}/comments/reaction`,
|
|
177
|
+
params: { file_type: fileType },
|
|
178
|
+
data: { action: on ? 'add' : 'delete', reply_id: replyId, reaction_type: 'Typing' },
|
|
179
|
+
});
|
|
180
|
+
assertOk('drive.comment.reaction', response);
|
|
181
|
+
},
|
|
182
|
+
};
|
|
183
|
+
}
|