atproto-mcp 0.1.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/LICENSE +22 -0
- package/README.md +293 -0
- package/dist/cli.d.ts +10 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +261 -0
- package/dist/cli.js.map +1 -0
- package/dist/health-check.d.ts +7 -0
- package/dist/health-check.d.ts.map +1 -0
- package/dist/health-check.js +57 -0
- package/dist/health-check.js.map +1 -0
- package/dist/index.d.ts +122 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +612 -0
- package/dist/index.js.map +1 -0
- package/dist/prompts/index.d.ts +77 -0
- package/dist/prompts/index.d.ts.map +1 -0
- package/dist/prompts/index.js +186 -0
- package/dist/prompts/index.js.map +1 -0
- package/dist/resources/index.d.ts +75 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +218 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/test/setup.d.ts +78 -0
- package/dist/test/setup.d.ts.map +1 -0
- package/dist/test/setup.js +138 -0
- package/dist/test/setup.js.map +1 -0
- package/dist/tools/implementations/advanced-social-tools.d.ts +250 -0
- package/dist/tools/implementations/advanced-social-tools.d.ts.map +1 -0
- package/dist/tools/implementations/advanced-social-tools.js +380 -0
- package/dist/tools/implementations/advanced-social-tools.js.map +1 -0
- package/dist/tools/implementations/base-tool.d.ts +73 -0
- package/dist/tools/implementations/base-tool.d.ts.map +1 -0
- package/dist/tools/implementations/base-tool.js +225 -0
- package/dist/tools/implementations/base-tool.js.map +1 -0
- package/dist/tools/implementations/content-management-tools.d.ts +81 -0
- package/dist/tools/implementations/content-management-tools.d.ts.map +1 -0
- package/dist/tools/implementations/content-management-tools.js +236 -0
- package/dist/tools/implementations/content-management-tools.js.map +1 -0
- package/dist/tools/implementations/create-post-tool.d.ts +131 -0
- package/dist/tools/implementations/create-post-tool.d.ts.map +1 -0
- package/dist/tools/implementations/create-post-tool.js +182 -0
- package/dist/tools/implementations/create-post-tool.js.map +1 -0
- package/dist/tools/implementations/follow-user-tool.d.ts +69 -0
- package/dist/tools/implementations/follow-user-tool.d.ts.map +1 -0
- package/dist/tools/implementations/follow-user-tool.js +200 -0
- package/dist/tools/implementations/follow-user-tool.js.map +1 -0
- package/dist/tools/implementations/get-user-profile-tool.d.ts +61 -0
- package/dist/tools/implementations/get-user-profile-tool.d.ts.map +1 -0
- package/dist/tools/implementations/get-user-profile-tool.js +139 -0
- package/dist/tools/implementations/get-user-profile-tool.js.map +1 -0
- package/dist/tools/implementations/index.d.ts +22 -0
- package/dist/tools/implementations/index.d.ts.map +1 -0
- package/dist/tools/implementations/index.js +32 -0
- package/dist/tools/implementations/index.js.map +1 -0
- package/dist/tools/implementations/like-post-tool.d.ts +68 -0
- package/dist/tools/implementations/like-post-tool.d.ts.map +1 -0
- package/dist/tools/implementations/like-post-tool.js +184 -0
- package/dist/tools/implementations/like-post-tool.js.map +1 -0
- package/dist/tools/implementations/media-tools.d.ts +360 -0
- package/dist/tools/implementations/media-tools.d.ts.map +1 -0
- package/dist/tools/implementations/media-tools.js +444 -0
- package/dist/tools/implementations/media-tools.js.map +1 -0
- package/dist/tools/implementations/moderation-tools.d.ts +189 -0
- package/dist/tools/implementations/moderation-tools.d.ts.map +1 -0
- package/dist/tools/implementations/moderation-tools.js +289 -0
- package/dist/tools/implementations/moderation-tools.js.map +1 -0
- package/dist/tools/implementations/oauth-tools.d.ts +108 -0
- package/dist/tools/implementations/oauth-tools.d.ts.map +1 -0
- package/dist/tools/implementations/oauth-tools.js +183 -0
- package/dist/tools/implementations/oauth-tools.js.map +1 -0
- package/dist/tools/implementations/reply-to-post-tool.d.ts +52 -0
- package/dist/tools/implementations/reply-to-post-tool.d.ts.map +1 -0
- package/dist/tools/implementations/reply-to-post-tool.js +167 -0
- package/dist/tools/implementations/reply-to-post-tool.js.map +1 -0
- package/dist/tools/implementations/repost-tool.d.ts +76 -0
- package/dist/tools/implementations/repost-tool.d.ts.map +1 -0
- package/dist/tools/implementations/repost-tool.js +181 -0
- package/dist/tools/implementations/repost-tool.js.map +1 -0
- package/dist/tools/implementations/search-posts-tool.d.ts +95 -0
- package/dist/tools/implementations/search-posts-tool.d.ts.map +1 -0
- package/dist/tools/implementations/search-posts-tool.js +208 -0
- package/dist/tools/implementations/search-posts-tool.js.map +1 -0
- package/dist/tools/implementations/social-graph-tools.d.ts +119 -0
- package/dist/tools/implementations/social-graph-tools.d.ts.map +1 -0
- package/dist/tools/implementations/social-graph-tools.js +262 -0
- package/dist/tools/implementations/social-graph-tools.js.map +1 -0
- package/dist/tools/implementations/streaming-tools.d.ts +130 -0
- package/dist/tools/implementations/streaming-tools.d.ts.map +1 -0
- package/dist/tools/implementations/streaming-tools.js +241 -0
- package/dist/tools/implementations/streaming-tools.js.map +1 -0
- package/dist/tools/implementations/timeline-tools.d.ts +69 -0
- package/dist/tools/implementations/timeline-tools.d.ts.map +1 -0
- package/dist/tools/implementations/timeline-tools.js +194 -0
- package/dist/tools/implementations/timeline-tools.js.map +1 -0
- package/dist/tools/index.d.ts +23 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +73 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/types/index.d.ts +242 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +73 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/atp-client.d.ts +109 -0
- package/dist/utils/atp-client.d.ts.map +1 -0
- package/dist/utils/atp-client.js +451 -0
- package/dist/utils/atp-client.js.map +1 -0
- package/dist/utils/config.d.ts +74 -0
- package/dist/utils/config.d.ts.map +1 -0
- package/dist/utils/config.js +311 -0
- package/dist/utils/config.js.map +1 -0
- package/dist/utils/firehose-client.d.ts +96 -0
- package/dist/utils/firehose-client.d.ts.map +1 -0
- package/dist/utils/firehose-client.js +252 -0
- package/dist/utils/firehose-client.js.map +1 -0
- package/dist/utils/logger.d.ts +74 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +142 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/oauth-client.d.ts +61 -0
- package/dist/utils/oauth-client.d.ts.map +1 -0
- package/dist/utils/oauth-client.js +224 -0
- package/dist/utils/oauth-client.js.map +1 -0
- package/dist/utils/performance.d.ts +102 -0
- package/dist/utils/performance.d.ts.map +1 -0
- package/dist/utils/performance.js +302 -0
- package/dist/utils/performance.js.map +1 -0
- package/dist/utils/security.d.ts +154 -0
- package/dist/utils/security.d.ts.map +1 -0
- package/dist/utils/security.js +358 -0
- package/dist/utils/security.js.map +1 -0
- package/package.json +93 -0
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base class for AT Protocol MCP tools
|
|
3
|
+
* Provides common functionality and error handling
|
|
4
|
+
* Supports both authenticated and unauthenticated modes
|
|
5
|
+
*/
|
|
6
|
+
import { z } from 'zod';
|
|
7
|
+
import { Logger } from '../../utils/logger.js';
|
|
8
|
+
import { AtpError, AuthenticationError, ValidationError } from '../../types/index.js';
|
|
9
|
+
/**
|
|
10
|
+
* Tool authentication requirements
|
|
11
|
+
*/
|
|
12
|
+
export var ToolAuthMode;
|
|
13
|
+
(function (ToolAuthMode) {
|
|
14
|
+
ToolAuthMode["PUBLIC"] = "public";
|
|
15
|
+
ToolAuthMode["PRIVATE"] = "private";
|
|
16
|
+
ToolAuthMode["ENHANCED"] = "enhanced";
|
|
17
|
+
})(ToolAuthMode || (ToolAuthMode = {}));
|
|
18
|
+
/**
|
|
19
|
+
* Abstract base class for all AT Protocol MCP tools
|
|
20
|
+
*/
|
|
21
|
+
export class BaseTool {
|
|
22
|
+
atpClient;
|
|
23
|
+
logger;
|
|
24
|
+
authMode;
|
|
25
|
+
constructor(atpClient, toolName, authMode = ToolAuthMode.PRIVATE) {
|
|
26
|
+
this.atpClient = atpClient;
|
|
27
|
+
this.logger = new Logger(`Tool:${toolName}`);
|
|
28
|
+
this.authMode = authMode;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Main handler method that validates input and executes the tool
|
|
32
|
+
*/
|
|
33
|
+
async handler(params) {
|
|
34
|
+
const startTime = Date.now();
|
|
35
|
+
try {
|
|
36
|
+
this.logger.debug('Tool execution started', {
|
|
37
|
+
method: this.schema.method,
|
|
38
|
+
params: this.sanitizeParams(params),
|
|
39
|
+
});
|
|
40
|
+
// Validate parameters if schema is provided
|
|
41
|
+
let validatedParams = params;
|
|
42
|
+
if (this.schema.params) {
|
|
43
|
+
try {
|
|
44
|
+
validatedParams = this.schema.params.parse(params);
|
|
45
|
+
}
|
|
46
|
+
catch (error) {
|
|
47
|
+
if (error instanceof z.ZodError) {
|
|
48
|
+
const issues = error.issues
|
|
49
|
+
.map(issue => `${issue.path.join('.')}: ${issue.message}`)
|
|
50
|
+
.join(', ');
|
|
51
|
+
throw new ValidationError(`Invalid parameters: ${issues}`, undefined, params, {
|
|
52
|
+
method: this.schema.method,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
throw error;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
// Execute the tool implementation
|
|
59
|
+
const result = await this.execute(validatedParams);
|
|
60
|
+
const duration = Date.now() - startTime;
|
|
61
|
+
this.logger.info('Tool execution completed', {
|
|
62
|
+
method: this.schema.method,
|
|
63
|
+
duration,
|
|
64
|
+
success: true,
|
|
65
|
+
});
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
catch (error) {
|
|
69
|
+
const duration = Date.now() - startTime;
|
|
70
|
+
this.logger.error('Tool execution failed', error, {
|
|
71
|
+
method: this.schema.method,
|
|
72
|
+
duration,
|
|
73
|
+
params: this.sanitizeParams(params),
|
|
74
|
+
});
|
|
75
|
+
// Re-throw the error for MCP to handle
|
|
76
|
+
throw error;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Check if this tool is available in the current authentication mode
|
|
81
|
+
*/
|
|
82
|
+
isAvailable() {
|
|
83
|
+
if (this.authMode === ToolAuthMode.PUBLIC || this.authMode === ToolAuthMode.ENHANCED) {
|
|
84
|
+
return true; // Always available
|
|
85
|
+
}
|
|
86
|
+
if (this.authMode === ToolAuthMode.PRIVATE) {
|
|
87
|
+
return this.atpClient.requiresAuthentication() && this.atpClient.isAuthenticated();
|
|
88
|
+
}
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Get availability status message
|
|
93
|
+
*/
|
|
94
|
+
getAvailabilityMessage() {
|
|
95
|
+
if (this.isAvailable()) {
|
|
96
|
+
return 'Available';
|
|
97
|
+
}
|
|
98
|
+
if (this.authMode === ToolAuthMode.PRIVATE) {
|
|
99
|
+
if (!this.atpClient.requiresAuthentication()) {
|
|
100
|
+
return 'Requires authentication - please provide credentials';
|
|
101
|
+
}
|
|
102
|
+
if (!this.atpClient.isAuthenticated()) {
|
|
103
|
+
return 'Authentication required but not authenticated';
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return 'Not available';
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Execute an AT Protocol operation with error handling
|
|
110
|
+
* Automatically handles authentication requirements based on tool mode
|
|
111
|
+
*/
|
|
112
|
+
async executeAtpOperation(operation, operationName, context) {
|
|
113
|
+
// Check if tool is available
|
|
114
|
+
if (!this.isAvailable() && this.authMode === ToolAuthMode.PRIVATE) {
|
|
115
|
+
throw new AuthenticationError(`This operation requires authentication. ${this.getAvailabilityMessage()}`, undefined, { ...context, tool: this.schema.method, operation: operationName, authMode: this.authMode });
|
|
116
|
+
}
|
|
117
|
+
// Choose the appropriate execution method based on auth mode
|
|
118
|
+
let result;
|
|
119
|
+
if (this.authMode === ToolAuthMode.PUBLIC) {
|
|
120
|
+
result = await this.atpClient.executePublicRequest(operation, {
|
|
121
|
+
...context,
|
|
122
|
+
tool: this.schema.method,
|
|
123
|
+
operation: operationName,
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
else if (this.authMode === ToolAuthMode.PRIVATE) {
|
|
127
|
+
result = await this.atpClient.executeAuthenticatedRequest(operation, {
|
|
128
|
+
...context,
|
|
129
|
+
tool: this.schema.method,
|
|
130
|
+
operation: operationName,
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
// ENHANCED mode
|
|
135
|
+
// Try authenticated first, fall back to public
|
|
136
|
+
if (this.atpClient.isAuthenticated()) {
|
|
137
|
+
result = await this.atpClient.executeAuthenticatedRequest(operation, {
|
|
138
|
+
...context,
|
|
139
|
+
tool: this.schema.method,
|
|
140
|
+
operation: operationName,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
result = await this.atpClient.executePublicRequest(operation, {
|
|
145
|
+
...context,
|
|
146
|
+
tool: this.schema.method,
|
|
147
|
+
operation: operationName,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (!result.success) {
|
|
152
|
+
throw result.error;
|
|
153
|
+
}
|
|
154
|
+
return result.data;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Sanitize parameters for logging (remove sensitive data)
|
|
158
|
+
*/
|
|
159
|
+
sanitizeParams(params) {
|
|
160
|
+
if (typeof params !== 'object' || params === null) {
|
|
161
|
+
return params;
|
|
162
|
+
}
|
|
163
|
+
const sanitized = { ...params };
|
|
164
|
+
// Remove potentially sensitive fields
|
|
165
|
+
const sensitiveFields = ['password', 'token', 'secret', 'key'];
|
|
166
|
+
for (const field of sensitiveFields) {
|
|
167
|
+
if (field in sanitized) {
|
|
168
|
+
sanitized[field] = '[REDACTED]';
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
return sanitized;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Validate AT Protocol identifier (DID or handle)
|
|
175
|
+
*/
|
|
176
|
+
validateActor(actor) {
|
|
177
|
+
if (!actor || typeof actor !== 'string') {
|
|
178
|
+
throw new ValidationError('Actor must be a non-empty string');
|
|
179
|
+
}
|
|
180
|
+
// Basic validation for DID or handle format
|
|
181
|
+
const isDid = actor.startsWith('did:');
|
|
182
|
+
const isHandle = actor.includes('.') && !actor.startsWith('http');
|
|
183
|
+
if (!isDid && !isHandle) {
|
|
184
|
+
throw new ValidationError('Actor must be a valid DID (did:...) or handle (user.domain.com)', 'actor', actor);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Validate AT Protocol URI
|
|
189
|
+
*/
|
|
190
|
+
validateAtUri(uri) {
|
|
191
|
+
if (!uri || typeof uri !== 'string') {
|
|
192
|
+
throw new ValidationError('URI must be a non-empty string');
|
|
193
|
+
}
|
|
194
|
+
if (!uri.startsWith('at://')) {
|
|
195
|
+
throw new ValidationError('URI must be a valid AT Protocol URI (at://...)', 'uri', uri);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Validate CID
|
|
200
|
+
*/
|
|
201
|
+
validateCid(cid) {
|
|
202
|
+
if (!cid || typeof cid !== 'string') {
|
|
203
|
+
throw new ValidationError('CID must be a non-empty string');
|
|
204
|
+
}
|
|
205
|
+
// Basic CID validation (should start with 'bafy' for most cases)
|
|
206
|
+
if (!cid.match(/^[a-z0-9]+$/i)) {
|
|
207
|
+
throw new ValidationError('CID must be a valid content identifier', 'cid', cid);
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Format error for MCP response
|
|
212
|
+
*/
|
|
213
|
+
formatError(error) {
|
|
214
|
+
if (error instanceof AtpError || error instanceof ValidationError) {
|
|
215
|
+
throw error;
|
|
216
|
+
}
|
|
217
|
+
if (error instanceof Error) {
|
|
218
|
+
throw new AtpError(error.message, 'TOOL_EXECUTION_ERROR', undefined, error, {
|
|
219
|
+
tool: this.schema.method,
|
|
220
|
+
});
|
|
221
|
+
}
|
|
222
|
+
throw new AtpError('Unknown error occurred during tool execution', 'UNKNOWN_TOOL_ERROR', undefined, error, { tool: this.schema.method });
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
//# sourceMappingURL=base-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-tool.js","sourceRoot":"","sources":["../../../src/tools/implementations/base-tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,OAAO,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;AAC/C,OAAO,EAAE,QAAQ,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEtF;;GAEG;AACH,MAAM,CAAN,IAAY,YAIX;AAJD,WAAY,YAAY;IACtB,iCAAiB,CAAA;IACjB,mCAAmB,CAAA;IACnB,qCAAqB,CAAA;AACvB,CAAC,EAJW,YAAY,KAAZ,YAAY,QAIvB;AAED;;GAEG;AACH,MAAM,OAAgB,QAAQ;IAClB,SAAS,CAAY;IACrB,MAAM,CAAS;IACf,QAAQ,CAAe;IAQjC,YACE,SAAoB,EACpB,QAAgB,EAChB,WAAyB,YAAY,CAAC,OAAO;QAE7C,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,IAAI,MAAM,CAAC,QAAQ,QAAQ,EAAE,CAAC,CAAC;QAC7C,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,OAAO,CAAC,MAAe;QAClC,MAAM,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;QAE7B,IAAI,CAAC;YACH,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,wBAAwB,EAAE;gBAC1C,MAAM,EAAE,IAAI,CAAC,MAAM,CAAC,MAAM;gBAC1B,MAAM,EAAE,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC;aACpC,CAAC,CAAC;YAEH,4CAA4C;YAC5C,IAAI,eAAe,GAAG,MAAM,CAAC;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
|
1
|
+
/**
|
|
2
|
+
* Content Management Tools - Delete posts and update profiles on AT Protocol
|
|
3
|
+
*/
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { BaseTool } from './base-tool.js';
|
|
6
|
+
import type { AtpClient } from '../../utils/atp-client.js';
|
|
7
|
+
import type { ATURI, IDeletePostParams, IUpdateProfileParams } from '../../types/index.js';
|
|
8
|
+
/**
|
|
9
|
+
* Tool for deleting posts on AT Protocol
|
|
10
|
+
*/
|
|
11
|
+
export declare class DeletePostTool extends BaseTool {
|
|
12
|
+
readonly schema: {
|
|
13
|
+
method: string;
|
|
14
|
+
description: string;
|
|
15
|
+
params: z.ZodObject<{
|
|
16
|
+
uri: z.ZodString;
|
|
17
|
+
}, "strip", z.ZodTypeAny, {
|
|
18
|
+
uri: string;
|
|
19
|
+
}, {
|
|
20
|
+
uri: string;
|
|
21
|
+
}>;
|
|
22
|
+
};
|
|
23
|
+
constructor(atpClient: AtpClient);
|
|
24
|
+
protected execute(params: IDeletePostParams): Promise<{
|
|
25
|
+
success: boolean;
|
|
26
|
+
message: string;
|
|
27
|
+
deletedPost: {
|
|
28
|
+
uri: ATURI;
|
|
29
|
+
};
|
|
30
|
+
}>;
|
|
31
|
+
/**
|
|
32
|
+
* Verify that the post exists and belongs to the current user
|
|
33
|
+
*/
|
|
34
|
+
private verifyPostOwnership;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Tool for updating user profiles on AT Protocol
|
|
38
|
+
*/
|
|
39
|
+
export declare class UpdateProfileTool extends BaseTool {
|
|
40
|
+
readonly schema: {
|
|
41
|
+
method: string;
|
|
42
|
+
description: string;
|
|
43
|
+
params: z.ZodObject<{
|
|
44
|
+
displayName: z.ZodOptional<z.ZodString>;
|
|
45
|
+
description: z.ZodOptional<z.ZodString>;
|
|
46
|
+
avatar: z.ZodOptional<z.ZodAny>;
|
|
47
|
+
banner: z.ZodOptional<z.ZodAny>;
|
|
48
|
+
}, "strip", z.ZodTypeAny, {
|
|
49
|
+
description?: string | undefined;
|
|
50
|
+
displayName?: string | undefined;
|
|
51
|
+
avatar?: any;
|
|
52
|
+
banner?: any;
|
|
53
|
+
}, {
|
|
54
|
+
description?: string | undefined;
|
|
55
|
+
displayName?: string | undefined;
|
|
56
|
+
avatar?: any;
|
|
57
|
+
banner?: any;
|
|
58
|
+
}>;
|
|
59
|
+
};
|
|
60
|
+
constructor(atpClient: AtpClient);
|
|
61
|
+
protected execute(params: IUpdateProfileParams): Promise<{
|
|
62
|
+
success: boolean;
|
|
63
|
+
message: string;
|
|
64
|
+
updatedFields: string[];
|
|
65
|
+
profile: {
|
|
66
|
+
displayName?: string;
|
|
67
|
+
description?: string;
|
|
68
|
+
avatar?: string;
|
|
69
|
+
banner?: string;
|
|
70
|
+
};
|
|
71
|
+
}>;
|
|
72
|
+
/**
|
|
73
|
+
* Get current profile record
|
|
74
|
+
*/
|
|
75
|
+
private getCurrentProfile;
|
|
76
|
+
/**
|
|
77
|
+
* Upload a blob to AT Protocol
|
|
78
|
+
*/
|
|
79
|
+
private uploadBlob;
|
|
80
|
+
}
|
|
81
|
+
//# sourceMappingURL=content-management-tools.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-management-tools.d.ts","sourceRoot":"","sources":["../../../src/tools/implementations/content-management-tools.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,KAAK,EAAE,KAAK,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,sBAAsB,CAAC;AAmB3F;;GAEG;AACH,qBAAa,cAAe,SAAQ,QAAQ;IAC1C,SAAgB,MAAM;;;;;;;;;;MAKpB;gBAEU,SAAS,EAAE,SAAS;cAIhB,OAAO,CAAC,MAAM,EAAE,iBAAiB,GAAG,OAAO,CAAC;QAC1D,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,WAAW,EAAE;YACX,GAAG,EAAE,KAAK,CAAC;SACZ,CAAC;KACH,CAAC;IAoDF;;OAEG;YACW,mBAAmB;CAyClC;AAED;;GAEG;AACH,qBAAa,iBAAkB,SAAQ,QAAQ;IAC7C,SAAgB,MAAM;;;;;;;;;;;;;;;;;;;MAKpB;gBAEU,SAAS,EAAE,SAAS;cAIhB,OAAO,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC;QAC7D,OAAO,EAAE,OAAO,CAAC;QACjB,OAAO,EAAE,MAAM,CAAC;QAChB,aAAa,EAAE,MAAM,EAAE,CAAC;QACxB,OAAO,EAAE;YACP,WAAW,CAAC,EAAE,MAAM,CAAC;YACrB,WAAW,CAAC,EAAE,MAAM,CAAC;YACrB,MAAM,CAAC,EAAE,MAAM,CAAC;YAChB,MAAM,CAAC,EAAE,MAAM,CAAC;SACjB,CAAC;KACH,CAAC;IAyFF;;OAEG;YACW,iBAAiB;IA6B/B;;OAEG;YACW,UAAU;CAazB"}
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content Management Tools - Delete posts and update profiles on AT Protocol
|
|
3
|
+
*/
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { BaseTool } from './base-tool.js';
|
|
6
|
+
/**
|
|
7
|
+
* Zod schema for delete post parameters
|
|
8
|
+
*/
|
|
9
|
+
const DeletePostSchema = z.object({
|
|
10
|
+
uri: z.string().min(1, 'Post URI is required'),
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Zod schema for update profile parameters
|
|
14
|
+
*/
|
|
15
|
+
const UpdateProfileSchema = z.object({
|
|
16
|
+
displayName: z.string().max(64, 'Display name cannot exceed 64 characters').optional(),
|
|
17
|
+
description: z.string().max(256, 'Description cannot exceed 256 characters').optional(),
|
|
18
|
+
avatar: z.any().optional(), // Blob type
|
|
19
|
+
banner: z.any().optional(), // Blob type
|
|
20
|
+
});
|
|
21
|
+
/**
|
|
22
|
+
* Tool for deleting posts on AT Protocol
|
|
23
|
+
*/
|
|
24
|
+
export class DeletePostTool extends BaseTool {
|
|
25
|
+
schema = {
|
|
26
|
+
method: 'delete_post',
|
|
27
|
+
description: "Delete a post on AT Protocol. Permanently removes the post from the user's repository.",
|
|
28
|
+
params: DeletePostSchema,
|
|
29
|
+
};
|
|
30
|
+
constructor(atpClient) {
|
|
31
|
+
super(atpClient, 'DeletePost');
|
|
32
|
+
}
|
|
33
|
+
async execute(params) {
|
|
34
|
+
try {
|
|
35
|
+
this.logger.info('Deleting post', {
|
|
36
|
+
uri: params.uri,
|
|
37
|
+
});
|
|
38
|
+
// Validate the post URI
|
|
39
|
+
this.validateAtUri(params.uri);
|
|
40
|
+
// Verify the post exists and belongs to the current user
|
|
41
|
+
await this.verifyPostOwnership(params.uri);
|
|
42
|
+
// Delete the post record
|
|
43
|
+
await this.executeAtpOperation(async () => {
|
|
44
|
+
const agent = this.atpClient.getAgent();
|
|
45
|
+
const uriParts = params.uri.replace('at://', '').split('/');
|
|
46
|
+
const did = uriParts[0];
|
|
47
|
+
const collection = uriParts[1];
|
|
48
|
+
const rkey = uriParts[2];
|
|
49
|
+
if (!did || !collection || !rkey) {
|
|
50
|
+
throw new Error(`Invalid AT URI format: ${params.uri}`);
|
|
51
|
+
}
|
|
52
|
+
return await agent.com.atproto.repo.deleteRecord({
|
|
53
|
+
repo: did,
|
|
54
|
+
collection,
|
|
55
|
+
rkey,
|
|
56
|
+
});
|
|
57
|
+
}, 'deletePost', { uri: params.uri });
|
|
58
|
+
this.logger.info('Post deleted successfully', {
|
|
59
|
+
uri: params.uri,
|
|
60
|
+
});
|
|
61
|
+
return {
|
|
62
|
+
success: true,
|
|
63
|
+
message: 'Post deleted successfully',
|
|
64
|
+
deletedPost: {
|
|
65
|
+
uri: params.uri,
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
catch (error) {
|
|
70
|
+
this.logger.error('Failed to delete post', error);
|
|
71
|
+
this.formatError(error);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Verify that the post exists and belongs to the current user
|
|
76
|
+
*/
|
|
77
|
+
async verifyPostOwnership(uri) {
|
|
78
|
+
try {
|
|
79
|
+
const agent = this.atpClient.getAgent();
|
|
80
|
+
const currentUserDid = agent.session?.did;
|
|
81
|
+
if (!currentUserDid) {
|
|
82
|
+
throw new Error('User session not available');
|
|
83
|
+
}
|
|
84
|
+
// Extract DID from URI
|
|
85
|
+
const uriParts = uri.replace('at://', '').split('/');
|
|
86
|
+
const postOwnerDid = uriParts[0];
|
|
87
|
+
if (postOwnerDid !== currentUserDid) {
|
|
88
|
+
throw new Error('Cannot delete post: post belongs to another user');
|
|
89
|
+
}
|
|
90
|
+
// Verify the post exists
|
|
91
|
+
const collection = uriParts[1];
|
|
92
|
+
const rkey = uriParts[2];
|
|
93
|
+
await this.executeAtpOperation(async () => {
|
|
94
|
+
if (!collection || !rkey) {
|
|
95
|
+
throw new Error(`Invalid AT URI format: ${uri}`);
|
|
96
|
+
}
|
|
97
|
+
return await agent.com.atproto.repo.getRecord({
|
|
98
|
+
repo: postOwnerDid,
|
|
99
|
+
collection,
|
|
100
|
+
rkey,
|
|
101
|
+
});
|
|
102
|
+
}, 'verifyPost', { uri });
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
this.logger.error('Post ownership verification failed', error, { uri });
|
|
106
|
+
throw error;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Tool for updating user profiles on AT Protocol
|
|
112
|
+
*/
|
|
113
|
+
export class UpdateProfileTool extends BaseTool {
|
|
114
|
+
schema = {
|
|
115
|
+
method: 'update_profile',
|
|
116
|
+
description: 'Update user profile on AT Protocol. Can modify display name, description, avatar, and banner.',
|
|
117
|
+
params: UpdateProfileSchema,
|
|
118
|
+
};
|
|
119
|
+
constructor(atpClient) {
|
|
120
|
+
super(atpClient, 'UpdateProfile');
|
|
121
|
+
}
|
|
122
|
+
async execute(params) {
|
|
123
|
+
try {
|
|
124
|
+
this.logger.info('Updating profile', {
|
|
125
|
+
hasDisplayName: !!params.displayName,
|
|
126
|
+
hasDescription: !!params.description,
|
|
127
|
+
hasAvatar: !!params.avatar,
|
|
128
|
+
hasBanner: !!params.banner,
|
|
129
|
+
});
|
|
130
|
+
// Get current profile to merge with updates
|
|
131
|
+
const currentProfile = await this.getCurrentProfile();
|
|
132
|
+
// Build updated profile record
|
|
133
|
+
const updatedProfile = {
|
|
134
|
+
$type: 'app.bsky.actor.profile',
|
|
135
|
+
displayName: params.displayName !== undefined ? params.displayName : currentProfile.displayName,
|
|
136
|
+
description: params.description !== undefined ? params.description : currentProfile.description,
|
|
137
|
+
};
|
|
138
|
+
const updatedFields = [];
|
|
139
|
+
// Handle avatar upload if provided
|
|
140
|
+
if (params.avatar) {
|
|
141
|
+
this.logger.debug('Uploading new avatar');
|
|
142
|
+
const avatarBlob = await this.uploadBlob(params.avatar);
|
|
143
|
+
updatedProfile.avatar = avatarBlob.blob;
|
|
144
|
+
updatedFields.push('avatar');
|
|
145
|
+
}
|
|
146
|
+
else if (currentProfile.avatar) {
|
|
147
|
+
updatedProfile.avatar = currentProfile.avatar;
|
|
148
|
+
}
|
|
149
|
+
// Handle banner upload if provided
|
|
150
|
+
if (params.banner) {
|
|
151
|
+
this.logger.debug('Uploading new banner');
|
|
152
|
+
const bannerBlob = await this.uploadBlob(params.banner);
|
|
153
|
+
updatedProfile.banner = bannerBlob.blob;
|
|
154
|
+
updatedFields.push('banner');
|
|
155
|
+
}
|
|
156
|
+
else if (currentProfile.banner) {
|
|
157
|
+
updatedProfile.banner = currentProfile.banner;
|
|
158
|
+
}
|
|
159
|
+
// Track which fields were updated
|
|
160
|
+
if (params.displayName !== undefined)
|
|
161
|
+
updatedFields.push('displayName');
|
|
162
|
+
if (params.description !== undefined)
|
|
163
|
+
updatedFields.push('description');
|
|
164
|
+
// Update the profile record
|
|
165
|
+
await this.executeAtpOperation(async () => {
|
|
166
|
+
const agent = this.atpClient.getAgent();
|
|
167
|
+
const userDid = agent.session?.did;
|
|
168
|
+
if (!userDid) {
|
|
169
|
+
throw new Error('User session not available');
|
|
170
|
+
}
|
|
171
|
+
return await agent.com.atproto.repo.putRecord({
|
|
172
|
+
repo: userDid,
|
|
173
|
+
collection: 'app.bsky.actor.profile',
|
|
174
|
+
rkey: 'self',
|
|
175
|
+
record: updatedProfile,
|
|
176
|
+
});
|
|
177
|
+
}, 'updateProfile', { updatedFields });
|
|
178
|
+
this.logger.info('Profile updated successfully', {
|
|
179
|
+
updatedFields,
|
|
180
|
+
});
|
|
181
|
+
return {
|
|
182
|
+
success: true,
|
|
183
|
+
message: 'Profile updated successfully',
|
|
184
|
+
updatedFields,
|
|
185
|
+
profile: {
|
|
186
|
+
displayName: updatedProfile.displayName,
|
|
187
|
+
description: updatedProfile.description,
|
|
188
|
+
...(updatedProfile.avatar && { avatar: 'updated' }),
|
|
189
|
+
...(updatedProfile.banner && { banner: 'updated' }),
|
|
190
|
+
},
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
catch (error) {
|
|
194
|
+
this.logger.error('Failed to update profile', error);
|
|
195
|
+
this.formatError(error);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Get current profile record
|
|
200
|
+
*/
|
|
201
|
+
async getCurrentProfile() {
|
|
202
|
+
try {
|
|
203
|
+
const response = await this.executeAtpOperation(async () => {
|
|
204
|
+
const agent = this.atpClient.getAgent();
|
|
205
|
+
const userDid = agent.session?.did;
|
|
206
|
+
if (!userDid) {
|
|
207
|
+
throw new Error('User session not available');
|
|
208
|
+
}
|
|
209
|
+
return await agent.com.atproto.repo.getRecord({
|
|
210
|
+
repo: userDid,
|
|
211
|
+
collection: 'app.bsky.actor.profile',
|
|
212
|
+
rkey: 'self',
|
|
213
|
+
});
|
|
214
|
+
}, 'getCurrentProfile', {});
|
|
215
|
+
return response.data.value || {};
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
// If profile doesn't exist, return empty object
|
|
219
|
+
this.logger.debug('No existing profile found, creating new one');
|
|
220
|
+
return {};
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Upload a blob to AT Protocol
|
|
225
|
+
*/
|
|
226
|
+
async uploadBlob(blob) {
|
|
227
|
+
return await this.executeAtpOperation(async () => {
|
|
228
|
+
const agent = this.atpClient.getAgent();
|
|
229
|
+
const response = await agent.uploadBlob(blob, {
|
|
230
|
+
encoding: blob.type,
|
|
231
|
+
});
|
|
232
|
+
return response.data;
|
|
233
|
+
}, 'uploadBlob', { blobSize: blob.size, blobType: blob.type });
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
//# sourceMappingURL=content-management-tools.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-management-tools.js","sourceRoot":"","sources":["../../../src/tools/implementations/content-management-tools.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAI1C;;GAEG;AACH,MAAM,gBAAgB,GAAG,CAAC,CAAC,MAAM,CAAC;IAChC,GAAG,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,sBAAsB,CAAC;CAC/C,CAAC,CAAC;AAEH;;GAEG;AACH,MAAM,mBAAmB,GAAG,CAAC,CAAC,MAAM,CAAC;IACnC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,EAAE,0CAA0C,CAAC,CAAC,QAAQ,EAAE;IACtF,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,C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