@max1874/feishu 0.3.1 → 0.3.2

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/docx.ts +38 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@max1874/feishu",
3
- "version": "0.3.1",
3
+ "version": "0.3.2",
4
4
  "type": "module",
5
5
  "description": "OpenClaw Feishu/Lark channel plugin",
6
6
  "license": "MIT",
package/src/docx.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Type } from "@sinclair/typebox";
2
2
  import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
3
3
  import { createFeishuClient } from "./client.js";
4
+ import { resolveFeishuCredentials, mergeFeishuAccountConfig } from "./accounts.js";
4
5
  import { getConversationContext } from "./runtime.js";
5
6
  import type { FeishuConfig } from "./types.js";
6
7
  import type * as Lark from "@larksuiteoapi/node-sdk";
@@ -887,16 +888,50 @@ const WikiSpaceIdSchema = Type.Object({
887
888
  ),
888
889
  });
889
890
 
891
+ /**
892
+ * Resolve a FeishuConfig that has credentials, checking:
893
+ * 1. Top-level appId/appSecret (legacy / pre-v2026.3.2 layout)
894
+ * 2. The defaultAccount entry under accounts
895
+ * 3. The first account that has valid credentials
896
+ */
897
+ function resolveEffectiveFeishuConfig(cfg: FeishuConfig): FeishuConfig | null {
898
+ // 1. Top-level credentials
899
+ if (resolveFeishuCredentials(cfg)) return cfg;
900
+
901
+ // 2. defaultAccount (e.g. "main")
902
+ const defaultId = (cfg as any).defaultAccount as string | undefined;
903
+ if (defaultId && cfg.accounts?.[defaultId]) {
904
+ const merged = mergeFeishuAccountConfig(cfg, defaultId);
905
+ if (resolveFeishuCredentials(merged)) return merged;
906
+ }
907
+
908
+ // 3. First account with credentials
909
+ for (const id of Object.keys(cfg.accounts ?? {})) {
910
+ const merged = mergeFeishuAccountConfig(cfg, id);
911
+ if (resolveFeishuCredentials(merged)) return merged;
912
+ }
913
+
914
+ return null;
915
+ }
916
+
890
917
  // ============ Tool Registration ============
891
918
 
892
919
  export function registerFeishuDocTools(api: OpenClawPluginApi) {
893
920
  const feishuCfg = api.config?.channels?.feishu as FeishuConfig | undefined;
894
- if (!feishuCfg?.appId || !feishuCfg?.appSecret) {
895
- api.logger.debug?.("feishu_doc: Feishu credentials not configured, skipping doc tools");
921
+ if (!feishuCfg) {
922
+ api.logger.debug?.("feishu_doc: Feishu not configured, skipping doc tools");
923
+ return;
924
+ }
925
+
926
+ // Resolve effective config: try top-level credentials first, then fall back
927
+ // to defaultAccount or the first account that has credentials configured.
928
+ const resolvedCfg = resolveEffectiveFeishuConfig(feishuCfg);
929
+ if (!resolvedCfg) {
930
+ api.logger.debug?.("feishu_doc: Feishu credentials not configured (appId, appSecret required), skipping doc tools");
896
931
  return;
897
932
  }
898
933
 
899
- const getClient = () => createFeishuClient(feishuCfg);
934
+ const getClient = () => createFeishuClient(resolvedCfg);
900
935
 
901
936
  // Tool 1: feishu_doc_read
902
937
  api.registerTool(