@ganglion/weacpx-channel-feishu 0.1.2 → 0.2.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/dist/channel.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ChannelStartInput, CoordinatorMessageInput, CreateChannelDeps, MessageChannelRuntime, OrchestrationDeliveryCallbacks } from "weacpx/plugin-api";
1
+ import type { ChannelStartInput, CoordinatorMessageInput, CreateChannelDeps, ScheduledChannelMessageInput, MessageChannelRuntime, OrchestrationDeliveryCallbacks } from "weacpx/plugin-api";
2
2
  import type { FeishuResolvedAccountConfig } from "./config.js";
3
3
  import { type FeishuLarkClient } from "./lark-client.js";
4
4
  type OrchestrationTaskRecord = Parameters<MessageChannelRuntime["notifyTaskCompletion"]>[0];
@@ -27,6 +27,7 @@ export declare class FeishuChannel implements MessageChannelRuntime {
27
27
  notifyTaskCompletion(task: OrchestrationTaskRecord): Promise<void>;
28
28
  notifyTaskProgress(task: OrchestrationTaskRecord, text: string): Promise<void>;
29
29
  sendCoordinatorMessage(input: CoordinatorMessageInput): Promise<void>;
30
+ sendScheduledMessage(input: ScheduledChannelMessageInput): Promise<void>;
30
31
  private sendRouteText;
31
32
  private handleMessageEvent;
32
33
  /**
package/dist/index.js CHANGED
@@ -80363,6 +80363,58 @@ class FeishuChannel {
80363
80363
  async sendCoordinatorMessage(input) {
80364
80364
  await this.sendRouteText(input.chatKey, input.replyContextToken, input.text);
80365
80365
  }
80366
+ async sendScheduledMessage(input) {
80367
+ if (!this.agent || !this.logger) {
80368
+ throw new Error("FeishuChannel.start() must be called before scheduled message delivery");
80369
+ }
80370
+ const route = parseFeishuConversationId(input.chatKey);
80371
+ if (!route)
80372
+ throw new Error(`cannot deliver Feishu scheduled message to non-Feishu chatKey: ${input.chatKey}`);
80373
+ if (input.accountId && input.accountId !== route.accountId) {
80374
+ throw new Error(`scheduled Feishu accountId "${input.accountId}" does not match chatKey account "${route.accountId}"`);
80375
+ }
80376
+ if (!this.accounts.has(route.accountId)) {
80377
+ throw new Error(`feishu account "${route.accountId}" is not started; check channel.options.accounts and enabled flags`);
80378
+ }
80379
+ const deliverText = async (text) => {
80380
+ if (input.abortSignal?.aborted)
80381
+ return;
80382
+ const trimmed = text?.trim() ?? "";
80383
+ if (trimmed.length === 0)
80384
+ return;
80385
+ await this.sendRouteText(input.chatKey, input.replyContextToken, trimmed);
80386
+ };
80387
+ await this.sendRouteText(input.chatKey, input.replyContextToken, input.noticeText);
80388
+ try {
80389
+ const response = await this.agent.chat({
80390
+ accountId: route.accountId,
80391
+ conversationId: input.chatKey,
80392
+ text: input.promptText,
80393
+ ...input.replyContextToken ? { replyContextToken: input.replyContextToken } : {},
80394
+ ...input.abortSignal ? { abortSignal: input.abortSignal } : {},
80395
+ metadata: { channel: "feishu", scheduledSessionAlias: input.sessionAlias },
80396
+ reply: deliverText
80397
+ });
80398
+ if (input.abortSignal?.aborted)
80399
+ return;
80400
+ const media = normalizeMediaArray(response.media);
80401
+ if (media.length > 0) {
80402
+ await this.logger.error("feishu.scheduled.media_unsupported", "scheduled feishu media responses are not supported", {
80403
+ accountId: route.accountId,
80404
+ chatKey: input.chatKey,
80405
+ taskId: input.taskId,
80406
+ sessionAlias: input.sessionAlias,
80407
+ count: media.length
80408
+ });
80409
+ }
80410
+ await deliverText(response.text);
80411
+ } catch (error) {
80412
+ try {
80413
+ await deliverText(formatScheduledFailureText(input, error));
80414
+ } catch {}
80415
+ throw error;
80416
+ }
80417
+ }
80366
80418
  async sendRouteText(chatKey, replyContextToken, text) {
80367
80419
  const route = parseFeishuConversationId(chatKey);
80368
80420
  if (!route)
@@ -80826,6 +80878,10 @@ class FeishuChannel {
80826
80878
  return true;
80827
80879
  }
80828
80880
  }
80881
+ function formatScheduledFailureText(input, error) {
80882
+ const message = error instanceof Error ? error.message : String(error);
80883
+ return input.taskId ? `⏰ 定时任务 #${input.taskId} 执行失败:${message}` : `⏰ 定时任务执行失败:${message}`;
80884
+ }
80829
80885
  function defaultMimeForKind(kind) {
80830
80886
  if (kind === "image")
80831
80887
  return "image/*";
@@ -81061,7 +81117,7 @@ var feishuCliProvider = {
81061
81117
  var plugin = {
81062
81118
  apiVersion: 1,
81063
81119
  name: "@ganglion/weacpx-channel-feishu",
81064
- minWeacpxVersion: "0.4.0",
81120
+ minWeacpxVersion: "0.5.0",
81065
81121
  channels: [
81066
81122
  {
81067
81123
  type: "feishu",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ganglion/weacpx-channel-feishu",
3
- "version": "0.1.2",
3
+ "version": "0.2.0",
4
4
  "description": "Feishu channel plugin for weacpx.",
5
5
  "license": "MIT",
6
6
  "keywords": ["weacpx", "feishu", "channel", "plugin"],
@@ -20,7 +20,7 @@
20
20
  },
21
21
  "files": ["dist", "README.md"],
22
22
  "peerDependencies": {
23
- "weacpx": ">=0.4.0-0"
23
+ "weacpx": ">=0.5.0-0"
24
24
  },
25
25
  "peerDependenciesMeta": {
26
26
  "weacpx": {