@nextclaw/channel-extension-feishu 0.1.3 → 0.1.4

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/index.d.ts CHANGED
@@ -2,5 +2,4 @@ import { FeishuAccountConfig, FeishuChannelConfig, FeishuDomain, FeishuInboundMe
2
2
  import { FeishuRegistrationService } from "./services/feishu-registration.service.js";
3
3
  import { FeishuAuthCapability } from "./services/feishu-auth-capability.service.js";
4
4
  import { FeishuChannelAdapter } from "./services/feishu-channel-adapter.service.js";
5
- import { FeishuExtensionRuntime } from "./services/feishu-extension-runtime.service.js";
6
- export { type FeishuAccountConfig, FeishuAuthCapability, FeishuChannelAdapter, type FeishuChannelConfig, type FeishuDomain, FeishuExtensionRuntime, type FeishuInboundMessage, FeishuRegistrationService, type FeishuRuntimeAccount };
5
+ export { type FeishuAccountConfig, FeishuAuthCapability, FeishuChannelAdapter, type FeishuChannelConfig, type FeishuDomain, type FeishuInboundMessage, FeishuRegistrationService, type FeishuRuntimeAccount };
package/dist/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import { FeishuRegistrationService } from "./services/feishu-registration.service.js";
2
2
  import { FeishuAuthCapability } from "./services/feishu-auth-capability.service.js";
3
3
  import { FeishuChannelAdapter } from "./services/feishu-channel-adapter.service.js";
4
- import { FeishuExtensionRuntime } from "./services/feishu-extension-runtime.service.js";
5
- export { FeishuAuthCapability, FeishuChannelAdapter, FeishuExtensionRuntime, FeishuRegistrationService };
4
+ export { FeishuAuthCapability, FeishuChannelAdapter, FeishuRegistrationService };
package/dist/main.js CHANGED
@@ -1,12 +1,14 @@
1
1
  import { FeishuAuthCapability } from "./services/feishu-auth-capability.service.js";
2
2
  import { FeishuChannelAdapter } from "./services/feishu-channel-adapter.service.js";
3
- import { FeishuExtensionRuntime } from "./services/feishu-extension-runtime.service.js";
4
- import { NextClawExtension } from "@nextclaw/extension-sdk";
3
+ import { toFeishuSubmittedMessage } from "./utils/feishu-submitted-message.utils.js";
4
+ import { startChannelExtension, warnNcpEventError } from "@nextclaw/extension-sdk";
5
5
  //#region src/main.ts
6
- const extension = new NextClawExtension();
7
- const feishu = extension.channels.use("feishu");
8
- const runtime = new FeishuExtensionRuntime(feishu, new FeishuChannelAdapter());
9
- extension.capabilities.provide("channel.auth", new FeishuAuthCapability({ channel: feishu }));
10
- await runtime.start();
6
+ await startChannelExtension({
7
+ channelId: "feishu",
8
+ createAdapter: () => new FeishuChannelAdapter(),
9
+ mapInbound: toFeishuSubmittedMessage,
10
+ createAuthCapability: ({ channel }) => new FeishuAuthCapability({ channel }),
11
+ onNcpEventError: warnNcpEventError("feishu")
12
+ });
11
13
  //#endregion
12
14
  export {};
@@ -41,6 +41,11 @@ declare class FeishuChannelAdapter implements FeishuChannelAdapterContract {
41
41
  private readonly deleteProcessingReaction;
42
42
  private readonly addFailedReaction;
43
43
  private readonly sendText;
44
+ readonly sendOutboundText: (params: {
45
+ to: string;
46
+ text: string;
47
+ accountId?: string | null;
48
+ }) => Promise<void>;
44
49
  }
45
50
  //#endregion
46
51
  export { FeishuChannelAdapter };
@@ -246,6 +246,18 @@ var FeishuChannelAdapter = class {
246
246
  text: params.text
247
247
  });
248
248
  };
249
+ sendOutboundText = async (params) => {
250
+ const { accountId, text, to } = params;
251
+ const account = this.resolveSendAccount({
252
+ conversationId: to,
253
+ ...accountId ? { accountId } : {}
254
+ });
255
+ await this.sendText({
256
+ account,
257
+ conversationId: to,
258
+ text
259
+ });
260
+ };
249
261
  };
250
262
  //#endregion
251
263
  export { FeishuChannelAdapter };
@@ -2,9 +2,11 @@ import { existsSync, mkdirSync, readFileSync, readdirSync, rmSync, writeFileSync
2
2
  import { homedir } from "node:os";
3
3
  import { join, resolve } from "node:path";
4
4
  //#region src/stores/feishu-account.store.ts
5
+ const NEXTCLAW_HOME_ENV_KEY = "NEXTCLAW_HOME";
6
+ const NEXTCLAW_DEFAULT_HOME_DIR = ".nextclaw";
5
7
  function resolveNextclawHome() {
6
- const override = process.env.NEXTCLAW_HOME?.trim();
7
- return resolve(override || join(homedir(), ".nextclaw"));
8
+ const override = process.env[NEXTCLAW_HOME_ENV_KEY]?.trim();
9
+ return resolve(override || join(homedir(), NEXTCLAW_DEFAULT_HOME_DIR));
8
10
  }
9
11
  function resolveAccountsDir() {
10
12
  return join(resolveNextclawHome(), "channels", "feishu", "accounts");
@@ -46,6 +46,11 @@ type FeishuChannelAdapterContract = {
46
46
  stop: () => Promise<void>;
47
47
  onMessage: (handler: (message: FeishuInboundMessage) => void | Promise<void>) => () => void;
48
48
  sendNcpEvent: (event: NcpEndpointEvent) => Promise<void>;
49
+ sendOutboundText: (params: {
50
+ to: string;
51
+ text: string;
52
+ accountId?: string | null;
53
+ }) => Promise<void>;
49
54
  };
50
55
  //#endregion
51
56
  export { FeishuAccountConfig, FeishuChannelAdapterContract, FeishuChannelConfig, FeishuDomain, FeishuInboundMessage, FeishuRuntimeAccount };
@@ -0,0 +1,23 @@
1
+ //#region src/utils/feishu-submitted-message.utils.ts
2
+ function toFeishuSubmittedMessage(message) {
3
+ return {
4
+ conversationId: message.conversationId,
5
+ senderId: message.senderId,
6
+ content: {
7
+ type: "text",
8
+ text: message.text
9
+ },
10
+ metadata: {
11
+ accountId: message.accountId,
12
+ account_id: message.accountId,
13
+ peerId: message.conversationId,
14
+ peer_id: message.conversationId,
15
+ peerKind: message.peerKind,
16
+ peer_kind: message.peerKind,
17
+ ...message.messageId ? { message_id: message.messageId } : {},
18
+ ...message.raw === void 0 ? {} : { raw: message.raw }
19
+ }
20
+ };
21
+ }
22
+ //#endregion
23
+ export { toFeishuSubmittedMessage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nextclaw/channel-extension-feishu",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "private": false,
5
5
  "description": "NextClaw Feishu/Lark lightweight channel extension process.",
6
6
  "type": "module",
@@ -19,9 +19,9 @@
19
19
  ],
20
20
  "dependencies": {
21
21
  "@larksuiteoapi/node-sdk": "^1.59.0",
22
- "@nextclaw/ncp-toolkit": "0.5.17",
23
- "@nextclaw/ncp": "0.5.12",
24
- "@nextclaw/extension-sdk": "0.1.6"
22
+ "@nextclaw/extension-sdk": "0.1.7",
23
+ "@nextclaw/ncp": "0.5.13",
24
+ "@nextclaw/ncp-toolkit": "0.5.18"
25
25
  },
26
26
  "devDependencies": {
27
27
  "@types/node": "^20.17.6",
@@ -1,19 +0,0 @@
1
- import { FeishuChannelAdapterContract } from "../types/feishu-extension.types.js";
2
- import { ExtensionChannel } from "@nextclaw/extension-sdk";
3
-
4
- //#region src/services/feishu-extension-runtime.service.d.ts
5
- declare class FeishuExtensionRuntime {
6
- private readonly channel;
7
- private readonly adapter;
8
- private readonly cleanups;
9
- private started;
10
- constructor(channel: ExtensionChannel, adapter: FeishuChannelAdapterContract);
11
- readonly start: () => Promise<void>;
12
- readonly stop: () => Promise<void>;
13
- private readonly applyConfig;
14
- private readonly submitMessage;
15
- private readonly sendNcpEvent;
16
- private readonly drainCleanups;
17
- }
18
- //#endregion
19
- export { FeishuExtensionRuntime };
@@ -1,67 +0,0 @@
1
- //#region src/services/feishu-extension-runtime.service.ts
2
- var FeishuExtensionRuntime = class {
3
- cleanups = [];
4
- started = false;
5
- constructor(channel, adapter) {
6
- this.channel = channel;
7
- this.adapter = adapter;
8
- }
9
- start = async () => {
10
- if (this.started) return;
11
- this.started = true;
12
- this.cleanups.push(this.adapter.onMessage(this.submitMessage));
13
- this.cleanups.push(this.channel.onNcpEvent(this.sendNcpEvent));
14
- this.cleanups.push(this.channel.config.onChange(async () => {
15
- await this.applyConfig();
16
- }));
17
- await this.applyConfig();
18
- };
19
- stop = async () => {
20
- if (!this.started) return;
21
- this.started = false;
22
- this.drainCleanups();
23
- await this.adapter.stop();
24
- };
25
- applyConfig = async () => {
26
- const config = await this.channel.config.get();
27
- await this.adapter.configure(config);
28
- if (config.enabled === false) {
29
- await this.adapter.stop();
30
- return;
31
- }
32
- await this.adapter.start();
33
- };
34
- submitMessage = async (message) => {
35
- await this.channel.submitMessage({
36
- conversationId: message.conversationId,
37
- senderId: message.senderId,
38
- content: {
39
- type: "text",
40
- text: message.text
41
- },
42
- metadata: {
43
- accountId: message.accountId,
44
- account_id: message.accountId,
45
- peerId: message.conversationId,
46
- peer_id: message.conversationId,
47
- peerKind: message.peerKind,
48
- peer_kind: message.peerKind,
49
- ...message.messageId ? { message_id: message.messageId } : {},
50
- ...message.raw === void 0 ? {} : { raw: message.raw }
51
- }
52
- });
53
- };
54
- sendNcpEvent = async (event) => {
55
- try {
56
- await this.adapter.sendNcpEvent(event);
57
- } catch (error) {
58
- const message = error instanceof Error ? error.message : String(error);
59
- console.warn(`[feishu] failed to send NCP event: ${message}`);
60
- }
61
- };
62
- drainCleanups = () => {
63
- for (const cleanup of this.cleanups.splice(0).reverse()) cleanup();
64
- };
65
- };
66
- //#endregion
67
- export { FeishuExtensionRuntime };