mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:50:43 +00:00
refactor: trim feishu helper exports
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
const RACE_TIMEOUT = Symbol("race-timeout");
|
||||
const RACE_ABORT = Symbol("race-abort");
|
||||
|
||||
export type RaceWithTimeoutAndAbortResult<T> =
|
||||
type RaceWithTimeoutAndAbortResult<T> =
|
||||
| { status: "resolved"; value: T }
|
||||
| { status: "timeout" }
|
||||
| { status: "aborted" };
|
||||
|
||||
@@ -7,7 +7,7 @@ import { parsePostContent } from "./post.js";
|
||||
import { getFeishuRuntime } from "./runtime.js";
|
||||
import type { FeishuChatType, FeishuMediaInfo } from "./types.js";
|
||||
|
||||
export type FeishuMention = {
|
||||
type FeishuMention = {
|
||||
key: string;
|
||||
id: {
|
||||
open_id?: string;
|
||||
@@ -37,11 +37,11 @@ type FeishuMessageLike = {
|
||||
};
|
||||
};
|
||||
|
||||
export type GroupSessionScope = "group" | "group_sender" | "group_topic" | "group_topic_sender";
|
||||
type GroupSessionScope = "group" | "group_sender" | "group_topic" | "group_topic_sender";
|
||||
|
||||
type FeishuLogger = (...args: unknown[]) => void;
|
||||
|
||||
export type ResolvedFeishuGroupSession = {
|
||||
type ResolvedFeishuGroupSession = {
|
||||
peerId: string;
|
||||
parentPeer: { kind: "group"; id: string } | null;
|
||||
groupSessionScope: GroupSessionScope;
|
||||
@@ -299,7 +299,7 @@ export function normalizeFeishuCommandProbeBody(text: string): string {
|
||||
.trim();
|
||||
}
|
||||
|
||||
export function parseMediaKeys(
|
||||
function parseMediaKeys(
|
||||
content: string,
|
||||
messageType: string,
|
||||
): { imageKey?: string; fileKey?: string; fileName?: string } {
|
||||
|
||||
@@ -2,17 +2,10 @@ import { isRecord } from "./comment-shared.js";
|
||||
|
||||
export const FEISHU_CARD_INTERACTION_VERSION = "ocf1";
|
||||
|
||||
export type FeishuCardInteractionKind = "button" | "quick" | "meta";
|
||||
export type FeishuCardInteractionReason =
|
||||
| "malformed"
|
||||
| "stale"
|
||||
| "wrong_user"
|
||||
| "wrong_conversation";
|
||||
type FeishuCardInteractionKind = "button" | "quick" | "meta";
|
||||
type FeishuCardInteractionReason = "malformed" | "stale" | "wrong_user" | "wrong_conversation";
|
||||
|
||||
export type FeishuCardInteractionMetadata = Record<
|
||||
string,
|
||||
string | number | boolean | null | undefined
|
||||
>;
|
||||
type FeishuCardInteractionMetadata = Record<string, string | number | boolean | null | undefined>;
|
||||
|
||||
export type FeishuCardInteractionEnvelope = {
|
||||
oc: typeof FEISHU_CARD_INTERACTION_VERSION;
|
||||
@@ -29,7 +22,7 @@ export type FeishuCardInteractionEnvelope = {
|
||||
};
|
||||
};
|
||||
|
||||
export type FeishuCardActionEventLike = {
|
||||
type FeishuCardActionEventLike = {
|
||||
operator: {
|
||||
open_id?: string;
|
||||
};
|
||||
@@ -41,7 +34,7 @@ export type FeishuCardActionEventLike = {
|
||||
};
|
||||
};
|
||||
|
||||
export type DecodedFeishuCardAction =
|
||||
type DecodedFeishuCardAction =
|
||||
| {
|
||||
kind: "structured";
|
||||
envelope: FeishuCardInteractionEnvelope;
|
||||
|
||||
@@ -5,7 +5,7 @@ import { FEISHU_APPROVAL_REQUEST_ACTION } from "./card-ux-approval.js";
|
||||
import { buildFeishuCardButton, buildFeishuCardInteractionContext } from "./card-ux-shared.js";
|
||||
import { sendCardFeishu } from "./send.js";
|
||||
|
||||
export const FEISHU_QUICK_ACTION_CARD_TTL_MS = 10 * 60_000;
|
||||
const FEISHU_QUICK_ACTION_CARD_TTL_MS = 10 * 60_000;
|
||||
|
||||
const QUICK_ACTION_MENU_KEYS = new Set(["quick-actions", "quick_actions", "launcher"]);
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ import type { CommentFileType } from "./comment-target.js";
|
||||
import { deliverCommentThreadText } from "./drive.js";
|
||||
import { getFeishuRuntime } from "./runtime.js";
|
||||
|
||||
export type CreateFeishuCommentReplyDispatcherParams = {
|
||||
type CreateFeishuCommentReplyDispatcherParams = {
|
||||
cfg: ClawdbotConfig;
|
||||
agentId: string;
|
||||
runtime: RuntimeEnv;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
hasNonEmptyString as sharedHasNonEmptyString,
|
||||
isRecord as sharedIsRecord,
|
||||
normalizeOptionalString,
|
||||
readStringValue,
|
||||
@@ -24,8 +23,6 @@ export const normalizeString = normalizeOptionalString;
|
||||
|
||||
export const isRecord = sharedIsRecord;
|
||||
|
||||
export const hasNonEmptyString = sharedHasNonEmptyString;
|
||||
|
||||
export function formatFeishuApiError(
|
||||
error: unknown,
|
||||
options: {
|
||||
@@ -64,18 +61,18 @@ export function formatFeishuApiError(
|
||||
});
|
||||
}
|
||||
|
||||
export type ParsedCommentDocumentRef = {
|
||||
type ParsedCommentDocumentRef = {
|
||||
fileType?: CommentFileType;
|
||||
fileToken?: string;
|
||||
};
|
||||
|
||||
export type ParsedCommentMention = {
|
||||
type ParsedCommentMention = {
|
||||
userId: string;
|
||||
displayText: string;
|
||||
isBotMention: boolean;
|
||||
};
|
||||
|
||||
export type ParsedCommentLinkedDocumentKind =
|
||||
type ParsedCommentLinkedDocumentKind =
|
||||
| CommentFileType
|
||||
| "wiki"
|
||||
| "mindnote"
|
||||
@@ -83,7 +80,7 @@ export type ParsedCommentLinkedDocumentKind =
|
||||
| "base"
|
||||
| "unknown";
|
||||
|
||||
export type ParsedCommentResolvedDocumentType = Exclude<
|
||||
type ParsedCommentResolvedDocumentType = Exclude<
|
||||
ParsedCommentLinkedDocumentKind,
|
||||
"wiki" | "unknown"
|
||||
>;
|
||||
|
||||
@@ -9,7 +9,7 @@ export function normalizeCommentFileType(value: unknown): CommentFileType | unde
|
||||
: undefined;
|
||||
}
|
||||
|
||||
export type FeishuCommentTarget = {
|
||||
type FeishuCommentTarget = {
|
||||
fileType: CommentFileType;
|
||||
fileToken: string;
|
||||
commentId: string;
|
||||
|
||||
@@ -59,7 +59,7 @@ type DocxTextElement = NonNullable<
|
||||
* [bold]text[/bold] → bold
|
||||
* [green bold]text[/green] → green + bold
|
||||
*/
|
||||
export function parseColorMarkup(content: string): Segment[] {
|
||||
function parseColorMarkup(content: string): Segment[] {
|
||||
const segments: Segment[] = [];
|
||||
// Only [known_tag]...[/...] pairs are treated as markup. Using an open
|
||||
// pattern like \[([^\]]+)\] would match any bracket token — e.g. [Q1] —
|
||||
|
||||
@@ -61,10 +61,7 @@ function createDescendantTable(
|
||||
};
|
||||
}
|
||||
|
||||
export function calculateAdaptiveColumnWidths(
|
||||
blocks: FeishuDocxBlock[],
|
||||
tableBlockId: string,
|
||||
): number[] {
|
||||
function calculateAdaptiveColumnWidths(blocks: FeishuDocxBlock[], tableBlockId: string): number[] {
|
||||
// Find the table block
|
||||
const tableBlock = blocks.find((b) => b.block_id === tableBlockId && b.block_type === 31);
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export type FeishuBlockText = {
|
||||
type FeishuBlockText = {
|
||||
elements?: Array<{
|
||||
text_run?: {
|
||||
content?: string;
|
||||
@@ -6,7 +6,7 @@ export type FeishuBlockText = {
|
||||
}>;
|
||||
};
|
||||
|
||||
export type FeishuBlockTableProperty = {
|
||||
type FeishuBlockTableProperty = {
|
||||
row_size?: number;
|
||||
column_size?: number;
|
||||
column_width?: number[];
|
||||
|
||||
@@ -4,7 +4,7 @@ import path from "node:path";
|
||||
import type { OpenClawConfig, PluginRuntime } from "../runtime-api.js";
|
||||
import type { DynamicAgentCreationConfig } from "./types.js";
|
||||
|
||||
export type MaybeCreateDynamicAgentResult = {
|
||||
type MaybeCreateDynamicAgentResult = {
|
||||
created: boolean;
|
||||
updatedCfg: OpenClawConfig;
|
||||
agentId?: string;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { FeishuMessageEvent } from "./event-types.js";
|
||||
export type { MentionTarget } from "./mention-target.types.js";
|
||||
import type { MentionTarget } from "./mention-target.types.js";
|
||||
import { isFeishuGroupChatType } from "./types.js";
|
||||
|
||||
@@ -79,14 +78,14 @@ export function isMentionForwardRequest(event: FeishuMessageEvent, botOpenId?: s
|
||||
/**
|
||||
* Format @mention for text message
|
||||
*/
|
||||
export function formatMentionForText(target: MentionTarget): string {
|
||||
function formatMentionForText(target: MentionTarget): string {
|
||||
return `<at user_id="${target.openId}">${target.name}</at>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format @mention for card message (lark_md)
|
||||
*/
|
||||
export function formatMentionForCard(target: MentionTarget): string {
|
||||
function formatMentionForCard(target: MentionTarget): string {
|
||||
return `<at id=${target.openId}></at>`;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { ResolvedFeishuAccount } from "./types.js";
|
||||
|
||||
// Delays must be >= PROBE_ERROR_TTL_MS (60s) so each retry makes a real network request
|
||||
// instead of silently hitting the probe error cache.
|
||||
export const BOT_IDENTITY_RETRY_DELAYS_MS = [60_000, 120_000, 300_000, 600_000, 900_000];
|
||||
const BOT_IDENTITY_RETRY_DELAYS_MS = [60_000, 120_000, 300_000, 600_000, 900_000];
|
||||
|
||||
export function applyBotIdentityState(
|
||||
accountId: string,
|
||||
|
||||
@@ -60,7 +60,7 @@ type ResolveDriveCommentEventParams = {
|
||||
waitMs?: (ms: number) => Promise<void>;
|
||||
};
|
||||
|
||||
export type ResolvedDriveCommentEventTurn = {
|
||||
type ResolvedDriveCommentEventTurn = {
|
||||
eventId: string;
|
||||
messageId: string;
|
||||
commentId: string;
|
||||
|
||||
@@ -20,7 +20,7 @@ function resolveStartupProbeTimeoutMs(): number {
|
||||
return FEISHU_STARTUP_BOT_INFO_TIMEOUT_DEFAULT_MS;
|
||||
}
|
||||
|
||||
export const FEISHU_STARTUP_BOT_INFO_TIMEOUT_MS = resolveStartupProbeTimeoutMs();
|
||||
const FEISHU_STARTUP_BOT_INFO_TIMEOUT_MS = resolveStartupProbeTimeoutMs();
|
||||
|
||||
type FetchBotOpenIdOptions = {
|
||||
runtime?: RuntimeEnv;
|
||||
|
||||
@@ -22,7 +22,7 @@ import {
|
||||
} from "./monitor.state.js";
|
||||
import type { ResolvedFeishuAccount } from "./types.js";
|
||||
|
||||
export type MonitorTransportParams = {
|
||||
type MonitorTransportParams = {
|
||||
account: ResolvedFeishuAccount;
|
||||
accountId: string;
|
||||
runtime?: RuntimeEnv;
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { ClawdbotConfig } from "../runtime-api.js";
|
||||
import { resolveFeishuRuntimeAccount } from "./accounts.js";
|
||||
import { createFeishuClient } from "./client.js";
|
||||
|
||||
export type FeishuPin = {
|
||||
type FeishuPin = {
|
||||
messageId: string;
|
||||
chatId?: string;
|
||||
operatorId?: string;
|
||||
|
||||
@@ -9,7 +9,7 @@ import type { AllowlistMatch, ChannelGroupContext } from "../runtime-api.js";
|
||||
import { detectIdType } from "./targets.js";
|
||||
import type { FeishuConfig } from "./types.js";
|
||||
|
||||
export type FeishuAllowlistMatch = AllowlistMatch<"wildcard" | "id">;
|
||||
type FeishuAllowlistMatch = AllowlistMatch<"wildcard" | "id">;
|
||||
|
||||
const FEISHU_PROVIDER_PREFIX_RE = /^(feishu|lark):/i;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ import type { ClawdbotConfig } from "../runtime-api.js";
|
||||
import { resolveFeishuRuntimeAccount } from "./accounts.js";
|
||||
import { createFeishuClient } from "./client.js";
|
||||
|
||||
export type FeishuReaction = {
|
||||
type FeishuReaction = {
|
||||
reactionId: string;
|
||||
emojiType: string;
|
||||
operatorType: "app" | "user";
|
||||
|
||||
@@ -101,7 +101,7 @@ function resolveCardNote(
|
||||
return parts.join(" | ");
|
||||
}
|
||||
|
||||
export type CreateFeishuReplyDispatcherParams = {
|
||||
type CreateFeishuReplyDispatcherParams = {
|
||||
cfg: ClawdbotConfig;
|
||||
agentId: string;
|
||||
runtime: RuntimeEnv;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
export type FeishuMessageApiResponse = {
|
||||
type FeishuMessageApiResponse = {
|
||||
code?: number;
|
||||
msg?: string;
|
||||
data?: {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { buildFeishuConversationId, parseFeishuConversationId } from "./conversation-id.js";
|
||||
|
||||
export function resolveFeishuParentConversationCandidates(rawId: string): string[] {
|
||||
function resolveFeishuParentConversationCandidates(rawId: string): string[] {
|
||||
const parsed = parseFeishuConversationId({ conversationId: rawId });
|
||||
if (!parsed) {
|
||||
return [];
|
||||
|
||||
@@ -18,7 +18,7 @@ type CardState = {
|
||||
};
|
||||
|
||||
/** Options for customising the initial streaming card appearance. */
|
||||
export type StreamingCardOptions = {
|
||||
type StreamingCardOptions = {
|
||||
/** Optional header with title and color template. */
|
||||
header?: CardHeaderConfig;
|
||||
/** Optional grey note footer text. */
|
||||
@@ -26,7 +26,7 @@ export type StreamingCardOptions = {
|
||||
};
|
||||
|
||||
/** Optional header for streaming cards (title bar with color template) */
|
||||
export type StreamingCardHeader = {
|
||||
type StreamingCardHeader = {
|
||||
title: string;
|
||||
/** Color template: blue, green, red, orange, purple, indigo, wathet, turquoise, yellow, grey, carmine, violet, lime */
|
||||
template?: string;
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { FeishuToolsConfig } from "./types.js";
|
||||
* - doc, chat, wiki, drive, scopes: enabled by default
|
||||
* - perm: disabled by default (sensitive operation)
|
||||
*/
|
||||
export const DEFAULT_TOOLS_CONFIG: Required<FeishuToolsConfig> = {
|
||||
const DEFAULT_TOOLS_CONFIG: Required<FeishuToolsConfig> = {
|
||||
doc: true,
|
||||
chat: true,
|
||||
wiki: true,
|
||||
|
||||
@@ -11,7 +11,7 @@ export type FeishuDefaultAccountSelectionSource =
|
||||
| "explicit-default"
|
||||
| "mapped-default"
|
||||
| "fallback";
|
||||
export type FeishuAccountSelectionSource = "explicit" | FeishuDefaultAccountSelectionSource;
|
||||
type FeishuAccountSelectionSource = "explicit" | FeishuDefaultAccountSelectionSource;
|
||||
|
||||
export type ResolvedFeishuAccount = {
|
||||
accountId: string;
|
||||
|
||||
Reference in New Issue
Block a user