@m1heng-clawd/feishu 0.1.10 → 0.1.11

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/src/drive.ts CHANGED
@@ -2,7 +2,7 @@ import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
2
2
  import type * as Lark from "@larksuiteoapi/node-sdk";
3
3
  import { FeishuDriveSchema, type FeishuDriveParams } from "./drive-schema.js";
4
4
  import { hasFeishuToolEnabledForAnyAccount, withFeishuToolClient } from "./tools-common/tool-exec.js";
5
- import { writeDoc } from "./docx.js";
5
+ import { createAndWriteDoc } from "./doc-write-service.js";
6
6
 
7
7
  // ============ Helpers ============
8
8
 
@@ -161,34 +161,7 @@ async function importDocument(
161
161
  folderToken?: string,
162
162
  _docType?: "docx" | "doc",
163
163
  ) {
164
- // Step 1: Create empty document
165
- const createRes = await client.docx.document.create({
166
- data: { title, folder_token: folderToken },
167
- });
168
-
169
- if (createRes.code !== 0) {
170
- throw new Error(`Failed to create document: ${createRes.msg}`);
171
- }
172
-
173
- const docId = createRes.data?.document?.document_id;
174
- if (!docId) {
175
- throw new Error("Document created but no document_id returned");
176
- }
177
-
178
- // Step 2: Write markdown content to the document
179
- // This ensures proper structure preservation using the writeDoc function
180
- const writeResult = await writeDoc(client, docId, content, mediaMaxBytes);
181
-
182
- return {
183
- success: true,
184
- document_id: docId,
185
- title: title,
186
- url: `https://feishu.cn/docx/${docId}`,
187
- import_method: "create_and_write",
188
- blocks_added: writeResult.blocks_added,
189
- images_processed: writeResult.images_processed,
190
- ...("warning" in writeResult && { warning: writeResult.warning }),
191
- };
164
+ return createAndWriteDoc(client, title, content, mediaMaxBytes, folderToken);
192
165
  }
193
166
 
194
167
  // ============ Tool Registration ============
package/src/onboarding.ts CHANGED
@@ -23,6 +23,7 @@ import { probeFeishu } from "./probe.js";
23
23
  import type { FeishuConfig } from "./types.js";
24
24
 
25
25
  const channel = "feishu" as const;
26
+ let onboardingDmPolicyAccountId: string | undefined;
26
27
 
27
28
  function resolveOnboardingAccountId(cfg: ClawdbotConfig, accountId?: string | null): string {
28
29
  const raw = accountId?.trim();
@@ -32,6 +33,10 @@ function resolveOnboardingAccountId(cfg: ClawdbotConfig, accountId?: string | nu
32
33
  return resolveDefaultFeishuAccountId(cfg);
33
34
  }
34
35
 
36
+ function resolveDmPolicyAccountId(cfg: ClawdbotConfig, accountId?: string | null): string {
37
+ return resolveOnboardingAccountId(cfg, accountId ?? onboardingDmPolicyAccountId);
38
+ }
39
+
35
40
  function upsertFeishuAccountConfig(
36
41
  cfg: ClawdbotConfig,
37
42
  accountId: string,
@@ -79,7 +84,7 @@ function setFeishuDmPolicy(
79
84
  dmPolicy: DmPolicy,
80
85
  accountId?: string,
81
86
  ): ClawdbotConfig {
82
- const resolvedAccountId = resolveOnboardingAccountId(cfg, accountId);
87
+ const resolvedAccountId = resolveDmPolicyAccountId(cfg, accountId);
83
88
  const account = resolveFeishuAccount({ cfg, accountId: resolvedAccountId });
84
89
  // Feishu channel config does not support "disabled" as a dmPolicy value.
85
90
  const effectiveDmPolicy = dmPolicy === "disabled" ? "pairing" : dmPolicy;
@@ -110,7 +115,7 @@ async function promptFeishuAllowFrom(params: {
110
115
  prompter: WizardPrompter;
111
116
  accountId?: string;
112
117
  }): Promise<ClawdbotConfig> {
113
- const accountId = resolveOnboardingAccountId(params.cfg, params.accountId);
118
+ const accountId = resolveDmPolicyAccountId(params.cfg, params.accountId);
114
119
  const existing = resolveFeishuAccount({ cfg: params.cfg, accountId }).config.allowFrom ?? [];
115
120
  const accountLabel = accountId === DEFAULT_ACCOUNT_ID ? "default" : accountId;
116
121
  await params.prompter.note(
@@ -189,10 +194,10 @@ const dmPolicy: ChannelOnboardingDmPolicy = {
189
194
  policyKey: "channels.feishu.dmPolicy",
190
195
  allowFromKey: "channels.feishu.allowFrom",
191
196
  getCurrent: (cfg) => {
192
- const accountId = resolveDefaultFeishuAccountId(cfg);
197
+ const accountId = resolveDmPolicyAccountId(cfg);
193
198
  return resolveFeishuAccount({ cfg, accountId }).config.dmPolicy ?? "pairing";
194
199
  },
195
- setPolicy: (cfg, policy, accountId?: string) => setFeishuDmPolicy(cfg, policy, accountId),
200
+ setPolicy: (cfg, policy) => setFeishuDmPolicy(cfg, policy, onboardingDmPolicyAccountId),
196
201
  promptAllowFrom: promptFeishuAllowFrom,
197
202
  };
198
203
 
@@ -260,6 +265,7 @@ export const feishuOnboardingAdapter: ChannelOnboardingAdapter = {
260
265
  defaultAccountId: defaultFeishuAccountId,
261
266
  });
262
267
  }
268
+ onboardingDmPolicyAccountId = feishuAccountId;
263
269
  const accountLabel = feishuAccountId === DEFAULT_ACCOUNT_ID ? "default" : feishuAccountId;
264
270
  const currentAccount = resolveFeishuAccount({ cfg, accountId: feishuAccountId });
265
271
  const resolved = resolveFeishuCredentials(currentAccount.config);
@@ -429,6 +435,10 @@ export const feishuOnboardingAdapter: ChannelOnboardingAdapter = {
429
435
 
430
436
  dmPolicy,
431
437
 
438
+ onAccountRecorded: (accountId) => {
439
+ onboardingDmPolicyAccountId = normalizeAccountId(accountId);
440
+ },
441
+
432
442
  disable: (cfg) => ({
433
443
  ...cfg,
434
444
  channels: {