"use strict";Object.defineProperty(exports, "__esModule", { value: true });Object.defineProperty(exports, "ADP_UPLOAD_TOOL_MAX_CONCURRENCY", { enumerable: true, get: function () {return _adpUploadTool.ADP_UPLOAD_TOOL_MAX_CONCURRENCY;} });Object.defineProperty(exports, "ADP_UPLOAD_TOOL_MAX_PATHS", { enumerable: true, get: function () {return _adpUploadTool.ADP_UPLOAD_TOOL_MAX_PATHS;} });Object.defineProperty(exports, "ADP_UPLOAD_TOOL_MIN_PATHS", { enumerable: true, get: function () {return _adpUploadTool.ADP_UPLOAD_TOOL_MIN_PATHS;} });Object.defineProperty(exports, "ADP_UPLOAD_TOOL_NAME", { enumerable: true, get: function () {return _adpUploadTool.ADP_UPLOAD_TOOL_NAME;} });Object.defineProperty(exports, "ADP_UPLOAD_TOOL_SCHEMA", { enumerable: true, get: function () {return _adpUploadTool.ADP_UPLOAD_TOOL_SCHEMA;} });Object.defineProperty(exports, "ADP_UPLOAD_VALIDATION_MESSAGE", { enumerable: true, get: function () {return _adpUploadTool.ADP_UPLOAD_VALIDATION_MESSAGE;} });Object.defineProperty(exports, "AdpUploader", { enumerable: true, get: function () {return _adpUploadTool.AdpUploader;} });Object.defineProperty(exports, "adpUploadFile", { enumerable: true, get: function () {return _adpUploadTool.adpUploadFile;} });Object.defineProperty(exports, "adpUploadFileWithConfig", { enumerable: true, get: function () {return _adpUploadTool.adpUploadFileWithConfig;} });Object.defineProperty(exports, "adpUploadFiles", { enumerable: true, get: function () {return _adpUploadTool.adpUploadFiles;} });Object.defineProperty(exports, "adpUploadFilesWithConfig", { enumerable: true, get: function () {return _adpUploadTool.adpUploadFilesWithConfig;} });Object.defineProperty(exports, "buildToolResultSessionContentBlocks", { enumerable: true, get: function () {return _toolResultMessageBlocks.buildToolResultSessionContentBlocks;} });Object.defineProperty(exports, "configureSessionFileReader", { enumerable: true, get: function () {return _sessionHistory.configureSessionFileReader;} });exports.default = void 0;Object.defineProperty(exports, "dispatchToolResultToMessageBlocks", { enumerable: true, get: function () {return _toolResultMessageBlocks.dispatchToolResultToMessageBlocks;} });Object.defineProperty(exports, "executeAdpUploadTool", { enumerable: true, get: function () {return _adpUploadTool.executeAdpUploadTool;} });Object.defineProperty(exports, "formatUploadResultAsMarkdown", { enumerable: true, get: function () {return _toolResultMessageBlocks.formatUploadResultAsMarkdown;} });Object.defineProperty(exports, "formatUploadResultForUser", { enumerable: true, get: function () {return _toolResultMessageBlocks.formatUploadResultForUser;} });Object.defineProperty(exports, "getChatHistory", { enumerable: true, get: function () {return _sessionHistory.getChatHistory;} });Object.defineProperty(exports, "getChatHistoryByConversationId", { enumerable: true, get: function () {return _sessionHistory.getChatHistoryByConversationId;} });Object.defineProperty(exports, "getOpenClawChatHistory", { enumerable: true, get: function () {return _sessionHistory.getOpenClawChatHistory;} });Object.defineProperty(exports, "getOpenClawChatHistoryViaCli", { enumerable: true, get: function () {return _sessionHistory.getOpenClawChatHistoryViaCli;} });Object.defineProperty(exports, "getSessionFileConfig", { enumerable: true, get: function () {return _sessionHistory.getSessionFileConfig;} });Object.defineProperty(exports, "getSessionPreviews", { enumerable: true, get: function () {return _sessionHistory.getSessionPreviews;} });Object.defineProperty(exports, "getStorageCredential", { enumerable: true, get: function () {return _adpUploadTool.getStorageCredential;} });Object.defineProperty(exports, "listOpenClawSessions", { enumerable: true, get: function () {return _sessionHistory.listOpenClawSessions;} });Object.defineProperty(exports, "listOpenClawSessionsViaCli", { enumerable: true, get: function () {return _sessionHistory.listOpenClawSessionsViaCli;} });Object.defineProperty(exports, "listSessions", { enumerable: true, get: function () {return _sessionHistory.listSessions;} });Object.defineProperty(exports, "parseAdpUploadToolParams", { enumerable: true, get: function () {return _adpUploadTool.parseAdpUploadToolParams;} });Object.defineProperty(exports, "resolveClientToken", { enumerable: true, get: function () {return _adpUploadTool.resolveClientToken;} });Object.defineProperty(exports, "resolveSessionKey", { enumerable: true, get: function () {return _sessionHistory.resolveSessionKey;} });Object.defineProperty(exports, "uploadFileToCos", { enumerable: true, get: function () {return _adpUploadTool.uploadFileToCos;} });Object.defineProperty(exports, "uploadFilesToAdpEndpoint", { enumerable: true, get: function () {return _adpUploadTool.uploadFilesToAdpEndpoint;} }); var _pluginSdk = require("openclaw/plugin-sdk"); var _channel = require("./src/channel.js"); var _runtime = require("./src/runtime.js"); var _adpUploadTool = require("./src/adp-upload-tool.js"); var _sessionHistory = require("./src/session-history.js"); var _toolResultMessageBlocks = require("./src/tool-result-message-blocks.js"); // Export session history functions for external use // Export ADP upload tool functions and types // Export tool result message blocks functions // Helper to format tool result as JSON string const formatToolResultJson = (result) => JSON.stringify(result, null, 2) ?? "upload failed"; const plugin = { id: "adp-openclaw", name: "ADP OpenClaw", description: "ADP channel plugin backed by a Go WebSocket server", configSchema: (0, _pluginSdk.emptyPluginConfigSchema)(), register(api) { // Log registration for debugging console.log("[adp-openclaw] register() called - starting plugin registration"); api.logger.info?.("[adp-openclaw] Plugin register() called"); (0, _runtime.setAdpOpenclawRuntime)(api.runtime); // Register the ADP file upload tool as a factory function // Using a factory so the tool is only available when the message originates from the ADP channel. // This prevents other channels (e.g. DingTalk) with multimodal models from picking up this tool. console.log(`[adp-openclaw] Registering tool factory: ${_adpUploadTool.ADP_UPLOAD_TOOL_NAME}`); api.logger.info?.(`[adp-openclaw] Registering tool factory: ${_adpUploadTool.ADP_UPLOAD_TOOL_NAME}`); api.registerTool((ctx) => { // Only expose this tool when the message comes from the adp-openclaw channel const channel = ctx.messageChannel ?? ""; if (channel && channel !== "adp-openclaw") { api.logger.debug?.(`[adp-openclaw] Skipping ${_adpUploadTool.ADP_UPLOAD_TOOL_NAME} for channel: ${channel}`); return null; } return { name: _adpUploadTool.ADP_UPLOAD_TOOL_NAME, description: "If you can see this tool description, you are connected to the ADP server. " + "Use this tool to send 1-10 local files of any type (including images and documents) to the user. " + "A successful call means the files were uploaded and download URLs are returned. " + "IMPORTANT: You MUST include the download URLs in your response to the user, " + "and remind the user that the download links are valid for 24 hours. " + "Parameters must be local filesystem paths only.", parameters: _adpUploadTool.ADP_UPLOAD_TOOL_SCHEMA, async execute(toolCallId, params) { // Get bot token from channel config const getClientToken = () => { try { const cfg = api.runtime?.config?.loadConfig?.(); const channelCfg = cfg?.channels?.["adp-openclaw"]; return channelCfg?.clientToken?.trim() || process.env.ADP_OPENCLAW_CLIENT_TOKEN; } catch { return process.env.ADP_OPENCLAW_CLIENT_TOKEN; } }; // Parse and validate parameters const parsed = (0, _adpUploadTool.parseAdpUploadToolParams)(params); if (!parsed.ok) { const errorResult = { ok: false, error: formatToolResultJson(parsed.error) }; api.logger.debug?.(`[${_adpUploadTool.ADP_UPLOAD_TOOL_NAME}] validation failed toolCallId=${toolCallId} error=${errorResult.error}`); return { output: errorResult, result: errorResult, details: errorResult, content: [{ type: "text", text: formatToolResultJson(parsed.error) }], isError: true }; } // Get bot token const botToken = getClientToken(); if (!botToken) { const errorResult = { ok: false, error: "missing bot token for file upload - please configure clientToken in adp-openclaw channel settings" }; api.logger.debug?.(`[${_adpUploadTool.ADP_UPLOAD_TOOL_NAME}] token missing toolCallId=${toolCallId} paths=${JSON.stringify(parsed.value.paths)}`); return { output: errorResult, result: errorResult, details: errorResult, content: [{ type: "text", text: errorResult.error }], isError: true }; } // Execute upload const uploadResult = await (0, _adpUploadTool.uploadFilesToAdpEndpoint)(parsed.value.paths, { botToken, fileType: parsed.value.fileType }); if (!uploadResult.ok) { const errorResult = { ok: false, error: formatToolResultJson(uploadResult.error) }; api.logger.debug?.(`[${_adpUploadTool.ADP_UPLOAD_TOOL_NAME}] upload failed toolCallId=${toolCallId} paths=${JSON.stringify(parsed.value.paths)} error=${errorResult.error}`); return { output: errorResult, result: errorResult, details: errorResult, content: [{ type: "text", text: formatToolResultJson(uploadResult.error) }], isError: true }; } // Success - format result with download URLs const successResult = { ok: true, files: uploadResult.files }; api.logger.debug?.(`[${_adpUploadTool.ADP_UPLOAD_TOOL_NAME}] upload success toolCallId=${toolCallId} count=${successResult.files?.length ?? 0} paths=${JSON.stringify(parsed.value.paths)}`); // Debug: print full downloadUrl for each file for (const file of successResult.files || []) { api.logger.info?.(`[${_adpUploadTool.ADP_UPLOAD_TOOL_NAME}] file.downloadUrl: ${file.downloadUrl}`); api.logger.info?.(`[${_adpUploadTool.ADP_UPLOAD_TOOL_NAME}] file.uri: ${file.uri}`); } // 发射上传结果事件,让 monitor.ts 能够直接获取完整的下载链接 _adpUploadTool.uploadResultEmitter.emit(_adpUploadTool.UPLOAD_RESULT_EVENT, { toolCallId, result: successResult }); // Build content with resource links and download URLs const content = []; // Add resource links for each file for (const file of successResult.files || []) { content.push({ type: "resource_link", uri: file.downloadUrl || file.uri, // 使用带签名的下载链接 name: file.name, mimeType: file.mimeType, downloadUrl: file.downloadUrl // 也包含 downloadUrl 字段 }); } // Add a text summary with download URLs for AI to include in response // 注意:URL 包含签名参数,必须完整保留,不能截断或修改 const urlSummary = (successResult.files || []). map((f) => { const url = f.downloadUrl || f.uri; // 把完整 URL 作为代码块,防止 AI 截断或修改 return `- **${f.name}**: \`${url}\``; }). join("\n"); api.logger.info?.(`[${_adpUploadTool.ADP_UPLOAD_TOOL_NAME}] urlSummary: ${urlSummary}`); content.push({ type: "text", text: `Files uploaded successfully:\n${urlSummary}\n\n⚠️ IMPORTANT: The URLs above contain authentication signatures. You MUST copy the ENTIRE URL exactly as shown (including all query parameters after the "?"). Do NOT truncate or modify the URLs in any way. The links are valid for 24 hours.` }); return { output: successResult, result: successResult, details: successResult, content, isError: false }; } }; // end of tool object }); // end of factory function passed to registerTool // Log tool registration success console.log(`[adp-openclaw] Tool ${_adpUploadTool.ADP_UPLOAD_TOOL_NAME} registered successfully`); api.logger.info?.(`[adp-openclaw] Tool ${_adpUploadTool.ADP_UPLOAD_TOOL_NAME} registered successfully`); // Register the channel plugin api.registerChannel({ plugin: _channel.adpOpenclawPlugin }); console.log("[adp-openclaw] Plugin registration complete"); api.logger.info?.("[adp-openclaw] Plugin registration complete"); } };var _default = exports.default = plugin; /* v9-05c76e9ffd62f6b5 */