adp-openclaw 0.0.31 → 0.0.32
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/index.ts +134 -1
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
|
|
2
2
|
import { emptyPluginConfigSchema } from "openclaw/plugin-sdk";
|
|
3
|
-
import { adpOpenclawPlugin } from "./src/channel.js";
|
|
3
|
+
import { adpOpenclawPlugin, type AdpOpenclawChannelConfig } from "./src/channel.js";
|
|
4
4
|
import { setAdpOpenclawRuntime } from "./src/runtime.js";
|
|
5
|
+
import {
|
|
6
|
+
ADP_UPLOAD_TOOL_NAME,
|
|
7
|
+
ADP_UPLOAD_TOOL_SCHEMA,
|
|
8
|
+
parseAdpUploadToolParams,
|
|
9
|
+
uploadFilesToAdpEndpoint,
|
|
10
|
+
type AdpUploadToolResult,
|
|
11
|
+
type UploadedFileInfo,
|
|
12
|
+
} from "./src/adp-upload-tool.js";
|
|
5
13
|
|
|
6
14
|
// Export session history functions for external use
|
|
7
15
|
export {
|
|
@@ -72,6 +80,10 @@ export {
|
|
|
72
80
|
type MessageBlock,
|
|
73
81
|
} from "./src/tool-result-message-blocks.js";
|
|
74
82
|
|
|
83
|
+
// Helper to format tool result as JSON string
|
|
84
|
+
const formatToolResultJson = (result: unknown): string =>
|
|
85
|
+
JSON.stringify(result, null, 2) ?? "upload failed";
|
|
86
|
+
|
|
75
87
|
const plugin = {
|
|
76
88
|
id: "adp-openclaw",
|
|
77
89
|
name: "ADP OpenClaw",
|
|
@@ -80,6 +92,127 @@ const plugin = {
|
|
|
80
92
|
register(api: OpenClawPluginApi) {
|
|
81
93
|
// console.log("[adp-openclaw] register() called");
|
|
82
94
|
setAdpOpenclawRuntime(api.runtime);
|
|
95
|
+
|
|
96
|
+
// Register the ADP file upload tool
|
|
97
|
+
// This allows AI to send files to users via ADP storage
|
|
98
|
+
api.registerTool({
|
|
99
|
+
name: ADP_UPLOAD_TOOL_NAME,
|
|
100
|
+
description:
|
|
101
|
+
"If you can see this tool description, you are connected to the ADP server. " +
|
|
102
|
+
"Use this tool to send 1-10 local files of any type (including images and documents) to the user. " +
|
|
103
|
+
"A successful call means the files were uploaded and download URLs are returned. " +
|
|
104
|
+
"Include these URLs in your response so the user can access the files. " +
|
|
105
|
+
"Parameters must be local filesystem paths only.",
|
|
106
|
+
parameters: ADP_UPLOAD_TOOL_SCHEMA,
|
|
107
|
+
async execute(toolCallId: string, params: unknown) {
|
|
108
|
+
// Get bot token from channel config
|
|
109
|
+
const getClientToken = (): string | undefined => {
|
|
110
|
+
try {
|
|
111
|
+
const cfg = api.runtime?.config?.loadConfig?.();
|
|
112
|
+
const channelCfg = cfg?.channels?.["adp-openclaw"] as AdpOpenclawChannelConfig | undefined;
|
|
113
|
+
return channelCfg?.clientToken?.trim() || process.env.ADP_OPENCLAW_CLIENT_TOKEN;
|
|
114
|
+
} catch {
|
|
115
|
+
return process.env.ADP_OPENCLAW_CLIENT_TOKEN;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
// Parse and validate parameters
|
|
120
|
+
const parsed = parseAdpUploadToolParams(params);
|
|
121
|
+
if (!parsed.ok) {
|
|
122
|
+
const errorResult = {
|
|
123
|
+
ok: false,
|
|
124
|
+
error: formatToolResultJson(parsed.error),
|
|
125
|
+
};
|
|
126
|
+
api.logger.debug?.(`[${ADP_UPLOAD_TOOL_NAME}] validation failed toolCallId=${toolCallId} error=${errorResult.error}`);
|
|
127
|
+
return {
|
|
128
|
+
output: errorResult,
|
|
129
|
+
result: errorResult,
|
|
130
|
+
details: errorResult,
|
|
131
|
+
content: [{ type: "text", text: formatToolResultJson(parsed.error) }],
|
|
132
|
+
isError: true,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// Get bot token
|
|
137
|
+
const botToken = getClientToken();
|
|
138
|
+
if (!botToken) {
|
|
139
|
+
const errorResult = {
|
|
140
|
+
ok: false,
|
|
141
|
+
error: "missing bot token for file upload - please configure clientToken in adp-openclaw channel settings",
|
|
142
|
+
};
|
|
143
|
+
api.logger.debug?.(`[${ADP_UPLOAD_TOOL_NAME}] token missing toolCallId=${toolCallId} paths=${JSON.stringify(parsed.value.paths)}`);
|
|
144
|
+
return {
|
|
145
|
+
output: errorResult,
|
|
146
|
+
result: errorResult,
|
|
147
|
+
details: errorResult,
|
|
148
|
+
content: [{ type: "text", text: errorResult.error }],
|
|
149
|
+
isError: true,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Execute upload
|
|
154
|
+
const uploadResult = await uploadFilesToAdpEndpoint(parsed.value.paths, {
|
|
155
|
+
botToken,
|
|
156
|
+
fileType: parsed.value.fileType,
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
if (!uploadResult.ok) {
|
|
160
|
+
const errorResult = {
|
|
161
|
+
ok: false,
|
|
162
|
+
error: formatToolResultJson(uploadResult.error),
|
|
163
|
+
};
|
|
164
|
+
api.logger.debug?.(`[${ADP_UPLOAD_TOOL_NAME}] upload failed toolCallId=${toolCallId} paths=${JSON.stringify(parsed.value.paths)} error=${errorResult.error}`);
|
|
165
|
+
return {
|
|
166
|
+
output: errorResult,
|
|
167
|
+
result: errorResult,
|
|
168
|
+
details: errorResult,
|
|
169
|
+
content: [{ type: "text", text: formatToolResultJson(uploadResult.error) }],
|
|
170
|
+
isError: true,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Success - format result with download URLs
|
|
175
|
+
const successResult: AdpUploadToolResult = {
|
|
176
|
+
ok: true,
|
|
177
|
+
files: uploadResult.files,
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
api.logger.debug?.(`[${ADP_UPLOAD_TOOL_NAME}] upload success toolCallId=${toolCallId} count=${successResult.files?.length ?? 0} paths=${JSON.stringify(parsed.value.paths)}`);
|
|
181
|
+
|
|
182
|
+
// Build content with resource links and download URLs
|
|
183
|
+
const content: Array<{ type: string; uri?: string; name?: string; mimeType?: string; text?: string }> = [];
|
|
184
|
+
|
|
185
|
+
// Add resource links for each file
|
|
186
|
+
for (const file of (successResult.files || [])) {
|
|
187
|
+
content.push({
|
|
188
|
+
type: "resource_link",
|
|
189
|
+
uri: file.uri,
|
|
190
|
+
name: file.name,
|
|
191
|
+
mimeType: file.mimeType,
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Add a text summary with download URLs for AI to include in response
|
|
196
|
+
const urlSummary = (successResult.files || [])
|
|
197
|
+
.map((f: UploadedFileInfo) => `- [${f.name}](${f.downloadUrl || f.uri})`)
|
|
198
|
+
.join("\n");
|
|
199
|
+
|
|
200
|
+
content.push({
|
|
201
|
+
type: "text",
|
|
202
|
+
text: `Files uploaded successfully:\n${urlSummary}`,
|
|
203
|
+
});
|
|
204
|
+
|
|
205
|
+
return {
|
|
206
|
+
output: successResult,
|
|
207
|
+
result: successResult,
|
|
208
|
+
details: successResult,
|
|
209
|
+
content,
|
|
210
|
+
isError: false,
|
|
211
|
+
};
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// Register the channel plugin
|
|
83
216
|
api.registerChannel({ plugin: adpOpenclawPlugin });
|
|
84
217
|
},
|
|
85
218
|
};
|