-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathindex.feishu.ts
More file actions
58 lines (51 loc) · 2.18 KB
/
Copy pathindex.feishu.ts
File metadata and controls
58 lines (51 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// index.feishu.ts
import type { Config } from '@opencode-ai/sdk';
import type { BridgeAdapter, FeishuConfig } from './src/types';
import { asRecord, globalState } from './src/utils';
import { AGENT_LARK } from './src/constants';
import { bridgeLogger } from './src/logger';
let feishuAdapter: BridgeAdapter | null = globalState.__bridge_feishu_adapter || null;
export function parseFeishuConfig(cfg: Config | undefined): FeishuConfig {
const node = cfg?.agent?.[AGENT_LARK];
const options = asRecord(node?.options);
const app_id = typeof options.app_id === 'string' ? options.app_id : '';
const app_secret = typeof options.app_secret === 'string' ? options.app_secret : '';
const mode = options.mode === 'webhook' ? 'webhook' : 'ws';
const callbackUrlRaw = options.callback_url;
const fileStoreDirRaw = options.file_store_dir;
const callbackUrl =
typeof callbackUrlRaw === 'string' && callbackUrlRaw.length > 0
? callbackUrlRaw.startsWith('http')
? callbackUrlRaw
: `http://${callbackUrlRaw}`
: undefined;
const file_store_dir =
typeof fileStoreDirRaw === 'string' && fileStoreDirRaw.trim().length > 0
? fileStoreDirRaw.trim()
: undefined;
if (mode === 'webhook' && !callbackUrl) {
bridgeLogger.warn(`[Plugin] Missing callback_url for ${AGENT_LARK} in webhook mode`);
}
if (!app_id || !app_secret) {
throw new Error(`[Plugin] Missing options for ${AGENT_LARK}: app_id/app_secret`);
}
const maxMbRaw = Number(options.auto_send_local_files_max_mb);
const auto_send_local_files =
options.auto_send_local_files === true || options.auto_send_local_files === 'true';
const auto_send_local_files_allow_absolute =
options.auto_send_local_files_allow_absolute === true ||
options.auto_send_local_files_allow_absolute === 'true';
const auto_send_local_files_max_mb =
Number.isFinite(maxMbRaw) && maxMbRaw > 0 ? maxMbRaw : 20;
return {
app_id,
app_secret,
mode,
callback_url: callbackUrl,
file_store_dir,
encrypt_key: typeof options.encrypt_key === 'string' ? options.encrypt_key : undefined,
auto_send_local_files,
auto_send_local_files_allow_absolute,
auto_send_local_files_max_mb,
};
}