/** * XG-IM 文件发送工具(`xg_cwork_im_send_file`) * * 直接发送当前 Agent workspace 内的文件到**当前 IM 会话**:校验 workspace 路径与文件 → 上传资源中心 → * 发送 FILE 消息。避免 HTML/SVG 等经 `MEDIA:` + OpenClaw 本地媒体安全规则被拦截。 * * 与 `xg_cwork_im_send_group_message`(仅纯文本、需模型给 groupId)不同: * - groupId / accountId 从注入的会话上下文(deliveryContext)获取,模型不可指定; * - 上传或发送失败一律返回 `ok:false`,绝不降级成文本后谎报成功。 */ import type { AnyAgentTool } from "openclaw/plugin-sdk"; import type { XgImConfig } from "./types.js"; /** 由 OpenClaw 工具工厂上下文(`ctx`)节选注入,模型不可见、不可篡改。 */ export type XgImSendFileToolHints = { /** Agent 在宿主机上的 workspace 根目录(ctx.workspaceDir) */ workspaceDir?: string; /** 当前 Agent ID(ctx.agentId),仅用于日志 */ agentId?: string; /** 当前 IM 通道账户(ctx.agentAccountId) */ channelAccountId?: string; /** 当前发送者 userId(ctx.requesterSenderId) */ requesterSenderId?: string; /** 当前投递目标:channel / to(=groupId) / accountId / threadId(ctx.deliveryContext) */ deliveryContext?: { channel?: string | null; to?: string | null; accountId?: string | null; threadId?: string | number | null; } | null; }; export type SendFileErrorCode = "NO_XG_IM_CONTEXT" | "NO_DELIVERY_TARGET" | "NO_WORKSPACE" | "ACCOUNT_MISMATCH" | "ACCOUNT_NOT_FOUND" | "FILE_NOT_FOUND" | "PATH_IS_DIRECTORY" | "PATH_OUTSIDE_WORKSPACE" | "SYMLINK_ESCAPE" | "EMPTY_FILE" | "FILE_TOO_LARGE" | "EXTENSION_NOT_ALLOWED" | "AUTH_FAILED" | "READ_FAILED" | "UPLOAD_FAILED" | "MESSAGE_SEND_FAILED"; export declare class SendFileError extends Error { readonly code: SendFileErrorCode; constructor(code: SendFileErrorCode, message: string); } /** * 将模型传入的 path 解析为 workspace 内的宿主机绝对路径。 * * 校验顺序与 docs/send-file-tool-design.md §3 一致: * 去前缀 → 拒绝绝对/URL/UNC/.. → resolve 后仍在 workspace → realpath 防符号链接逃逸 → * isFile → 存在/非空/不超限 → 拒绝可执行扩展名。 * * @returns 解析后的真实路径、字节数与源文件名。 */ export declare function resolveWorkspaceFile(workspaceDir: string, inputPath: string, maxBytes: number): Promise<{ realPath: string; size: number; sourceName: string; }>; /** * 依据可选的 fileName 生成用户可见文件名: * 去掉路径部分与非法字符,并强制沿用源文件扩展名(不允许模型改扩展名)。 */ export declare function resolveDisplayFileName(sourceName: string, fileNameParam?: string): string; /** * 从两个可信来源(deliveryContext.accountId、agentAccountId)确定账户 ID: * 两者都存在且不一致时视为上下文冲突,拒绝执行(避免用错机器人)。 */ export declare function selectTrustedAccountId(deliveryAccountId?: string | null, channelAccountId?: string): { accountId?: string; } | { conflict: { a: string; b: string; }; }; /** * 严格解析账户配置: * - 单账户模式(无 accounts):直接返回顶层配置。 * - 多账户模式:指定账户必须存在;未指定账户时仅当只有一个非 default 账户才可自动选定, * 否则视为无法确定账户而拒绝。**不会**像 {@link resolveAccountConfig} 那样静默回退到第一个账户。 */ export declare function resolveAccountConfigStrict(base: XgImConfig, accountId?: string): { config: XgImConfig; accountId?: string; } | { error: "ACCOUNT_NOT_FOUND"; message: string; }; export declare function buildSendFileTool(config: XgImConfig, hints?: XgImSendFileToolHints): AnyAgentTool; //# sourceMappingURL=send-file-tool.d.ts.map