postproxy-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 +21 -0
- package/README.md +635 -0
- package/dist/api/client.d.ts +71 -0
- package/dist/api/client.d.ts.map +1 -0
- package/dist/api/client.js +432 -0
- package/dist/api/client.js.map +1 -0
- package/dist/auth/credentials.d.ts +19 -0
- package/dist/auth/credentials.d.ts.map +1 -0
- package/dist/auth/credentials.js +40 -0
- package/dist/auth/credentials.js.map +1 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +44 -0
- package/dist/index.js.map +1 -0
- package/dist/server.d.ts +162 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +220 -0
- package/dist/server.js.map +1 -0
- package/dist/setup-cli.d.ts +6 -0
- package/dist/setup-cli.d.ts.map +1 -0
- package/dist/setup-cli.js +10 -0
- package/dist/setup-cli.js.map +1 -0
- package/dist/setup.d.ts +8 -0
- package/dist/setup.d.ts.map +1 -0
- package/dist/setup.js +143 -0
- package/dist/setup.js.map +1 -0
- package/dist/tools/accounts.d.ts +11 -0
- package/dist/tools/accounts.d.ts.map +1 -0
- package/dist/tools/accounts.js +53 -0
- package/dist/tools/accounts.js.map +1 -0
- package/dist/tools/auth.d.ts +11 -0
- package/dist/tools/auth.d.ts.map +1 -0
- package/dist/tools/auth.js +35 -0
- package/dist/tools/auth.js.map +1 -0
- package/dist/tools/history.d.ts +13 -0
- package/dist/tools/history.d.ts.map +1 -0
- package/dist/tools/history.js +79 -0
- package/dist/tools/history.js.map +1 -0
- package/dist/tools/post.d.ts +44 -0
- package/dist/tools/post.d.ts.map +1 -0
- package/dist/tools/post.js +251 -0
- package/dist/tools/post.js.map +1 -0
- package/dist/tools/profiles.d.ts +11 -0
- package/dist/tools/profiles.d.ts.map +1 -0
- package/dist/tools/profiles.js +52 -0
- package/dist/tools/profiles.js.map +1 -0
- package/dist/types/index.d.ts +147 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +5 -0
- package/dist/types/index.js.map +1 -0
- package/dist/utils/errors.d.ts +21 -0
- package/dist/utils/errors.d.ts.map +1 -0
- package/dist/utils/errors.js +33 -0
- package/dist/utils/errors.js.map +1 -0
- package/dist/utils/idempotency.d.ts +8 -0
- package/dist/utils/idempotency.d.ts.map +1 -0
- package/dist/utils/idempotency.js +23 -0
- package/dist/utils/idempotency.js.map +1 -0
- package/dist/utils/logger.d.ts +20 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +68 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/validation.d.ts +555 -0
- package/dist/utils/validation.d.ts.map +1 -0
- package/dist/utils/validation.js +145 -0
- package/dist/utils/validation.js.map +1 -0
- package/package.json +39 -0
- package/src/api/client.ts +497 -0
- package/src/auth/credentials.ts +43 -0
- package/src/index.ts +57 -0
- package/src/server.ts +235 -0
- package/src/setup-cli.ts +11 -0
- package/src/setup.ts +187 -0
- package/src/tools/auth.ts +45 -0
- package/src/tools/history.ts +89 -0
- package/src/tools/post.ts +338 -0
- package/src/tools/profiles.ts +69 -0
- package/src/types/index.ts +161 -0
- package/src/utils/errors.ts +38 -0
- package/src/utils/idempotency.ts +31 -0
- package/src/utils/logger.ts +75 -0
- package/src/utils/validation.ts +171 -0
- package/tsconfig.json +19 -0
- package/worker/index.ts +901 -0
- package/wrangler.toml +11 -0
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication tools: auth.status
|
|
3
|
+
*/
|
|
4
|
+
import type { PostProxyClient } from "../api/client.js";
|
|
5
|
+
export declare function handleAuthStatus(client: PostProxyClient): Promise<{
|
|
6
|
+
content: {
|
|
7
|
+
type: string;
|
|
8
|
+
text: string;
|
|
9
|
+
}[];
|
|
10
|
+
}>;
|
|
11
|
+
//# sourceMappingURL=auth.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/tools/auth.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAKxD,wBAAsB,gBAAgB,CAAC,MAAM,EAAE,eAAe;;;;;GAmC7D"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Authentication tools: auth.status
|
|
3
|
+
*/
|
|
4
|
+
import { getApiKey, getBaseUrl } from "../auth/credentials.js";
|
|
5
|
+
import { logError, logToolCall } from "../utils/logger.js";
|
|
6
|
+
export async function handleAuthStatus(client) {
|
|
7
|
+
logToolCall("auth.status", {});
|
|
8
|
+
const apiKey = getApiKey();
|
|
9
|
+
const baseUrl = getBaseUrl();
|
|
10
|
+
const result = {
|
|
11
|
+
authenticated: apiKey !== null,
|
|
12
|
+
base_url: baseUrl,
|
|
13
|
+
};
|
|
14
|
+
// If authenticated, try to get profile groups count
|
|
15
|
+
if (apiKey !== null) {
|
|
16
|
+
try {
|
|
17
|
+
const profileGroups = await client.getProfileGroups();
|
|
18
|
+
result.profile_groups_count = profileGroups.length;
|
|
19
|
+
}
|
|
20
|
+
catch (error) {
|
|
21
|
+
// If we can't get profile groups, just return without the count
|
|
22
|
+
// Don't fail the whole request
|
|
23
|
+
logError(error, "auth.status");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
return {
|
|
27
|
+
content: [
|
|
28
|
+
{
|
|
29
|
+
type: "text",
|
|
30
|
+
text: JSON.stringify(result, null, 2),
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth.js","sourceRoot":"","sources":["../../src/tools/auth.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AAE/D,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE3D,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,MAAuB;IAC5D,WAAW,CAAC,aAAa,EAAE,EAAE,CAAC,CAAC;IAE/B,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAE7B,MAAM,MAAM,GAIR;QACF,aAAa,EAAE,MAAM,KAAK,IAAI;QAC9B,QAAQ,EAAE,OAAO;KAClB,CAAC;IAEF,oDAAoD;IACpD,IAAI,MAAM,KAAK,IAAI,EAAE,CAAC;QACpB,IAAI,CAAC;YACH,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,gBAAgB,EAAE,CAAC;YACtD,MAAM,CAAC,oBAAoB,GAAG,aAAa,CAAC,MAAM,CAAC;QACrD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,gEAAgE;YAChE,+BAA+B;YAC/B,QAAQ,CAAC,KAAc,EAAE,aAAa,CAAC,CAAC;QAC1C,CAAC;IACH,CAAC;IAED,OAAO;QACL,OAAO,EAAE;YACP;gBACE,IAAI,EAAE,MAAM;gBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC;aACtC;SACF;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* History tools: history.list
|
|
3
|
+
*/
|
|
4
|
+
import type { PostProxyClient } from "../api/client.js";
|
|
5
|
+
export declare function handleHistoryList(client: PostProxyClient, args: {
|
|
6
|
+
limit?: number;
|
|
7
|
+
}): Promise<{
|
|
8
|
+
content: {
|
|
9
|
+
type: string;
|
|
10
|
+
text: string;
|
|
11
|
+
}[];
|
|
12
|
+
}>;
|
|
13
|
+
//# sourceMappingURL=history.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../../src/tools/history.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAIxD,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,eAAe,EACvB,IAAI,EAAE;IAAE,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE;;;;;GA8EzB"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* History tools: history.list
|
|
3
|
+
*/
|
|
4
|
+
import { createError, ErrorCodes } from "../utils/errors.js";
|
|
5
|
+
import { logError } from "../utils/logger.js";
|
|
6
|
+
export async function handleHistoryList(client, args) {
|
|
7
|
+
const limit = args.limit || 10;
|
|
8
|
+
try {
|
|
9
|
+
const posts = await client.listPosts(limit);
|
|
10
|
+
const jobs = posts.map((post) => {
|
|
11
|
+
// Get content from either "body" or "content" field (API uses "body")
|
|
12
|
+
const content = post.body || post.content || "";
|
|
13
|
+
// Determine overall status from post status
|
|
14
|
+
let overallStatus = "unknown";
|
|
15
|
+
// Handle draft status first
|
|
16
|
+
if (post.status === "draft" || post.draft === true) {
|
|
17
|
+
overallStatus = "draft";
|
|
18
|
+
}
|
|
19
|
+
else if (post.status === "scheduled") {
|
|
20
|
+
overallStatus = "pending";
|
|
21
|
+
}
|
|
22
|
+
else if (post.status === "processing") {
|
|
23
|
+
overallStatus = "processing";
|
|
24
|
+
}
|
|
25
|
+
else if (post.status === "processed") {
|
|
26
|
+
// Check platform statuses to determine overall status
|
|
27
|
+
if (post.platforms && post.platforms.length > 0) {
|
|
28
|
+
const allPublished = post.platforms.every((p) => p.status === "published");
|
|
29
|
+
const allFailed = post.platforms.every((p) => p.status === "failed");
|
|
30
|
+
const anyPending = post.platforms.some((p) => p.status === "pending" || p.status === "processing");
|
|
31
|
+
if (anyPending) {
|
|
32
|
+
// Only if there are pending/processing platforms - this is truly processing
|
|
33
|
+
overallStatus = "processing";
|
|
34
|
+
}
|
|
35
|
+
else if (allPublished) {
|
|
36
|
+
overallStatus = "complete";
|
|
37
|
+
}
|
|
38
|
+
else if (allFailed) {
|
|
39
|
+
overallStatus = "failed";
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
// Mixed statuses (some published, some failed) - processing is complete
|
|
43
|
+
// Use "complete" since processing is finished, details are in platforms
|
|
44
|
+
overallStatus = "complete";
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
overallStatus = "pending";
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
else if (post.status === "pending") {
|
|
52
|
+
overallStatus = "pending";
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
job_id: post.id,
|
|
56
|
+
content_preview: content.substring(0, 100) + (content.length > 100 ? "..." : ""),
|
|
57
|
+
created_at: post.created_at,
|
|
58
|
+
overall_status: overallStatus,
|
|
59
|
+
draft: post.draft || false,
|
|
60
|
+
platforms_count: post.platforms?.length || 0,
|
|
61
|
+
};
|
|
62
|
+
});
|
|
63
|
+
return {
|
|
64
|
+
content: [
|
|
65
|
+
{
|
|
66
|
+
type: "text",
|
|
67
|
+
text: JSON.stringify({
|
|
68
|
+
jobs,
|
|
69
|
+
}, null, 2),
|
|
70
|
+
},
|
|
71
|
+
],
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
catch (error) {
|
|
75
|
+
logError(error, "history.list");
|
|
76
|
+
throw createError(ErrorCodes.API_ERROR, `Failed to list history: ${error.message}`);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=history.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"history.js","sourceRoot":"","sources":["../../src/tools/history.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAE9C,MA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,CAAC,CACF;iBACF;aACF;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,QAAQ,CAAC,KAAc,EAAE,cAAc,CAAC,CAAC;QACzC,MAAM,WAAW,CACf,UAAU,CAAC,SAAS,EACpB,2BAA4B,KAAe,CAAC,OAAO,EAAE,CACtD,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Post tools: post.publish, post.status, post.delete
|
|
3
|
+
*/
|
|
4
|
+
import type { PostProxyClient } from "../api/client.js";
|
|
5
|
+
export declare function handlePostPublish(client: PostProxyClient, args: {
|
|
6
|
+
content: string;
|
|
7
|
+
targets: string[];
|
|
8
|
+
schedule?: string;
|
|
9
|
+
media?: string[];
|
|
10
|
+
idempotency_key?: string;
|
|
11
|
+
require_confirmation?: boolean;
|
|
12
|
+
draft?: boolean;
|
|
13
|
+
platforms?: Record<string, Record<string, any>>;
|
|
14
|
+
}): Promise<{
|
|
15
|
+
content: {
|
|
16
|
+
type: string;
|
|
17
|
+
text: string;
|
|
18
|
+
}[];
|
|
19
|
+
}>;
|
|
20
|
+
export declare function handlePostStatus(client: PostProxyClient, args: {
|
|
21
|
+
job_id: string;
|
|
22
|
+
}): Promise<{
|
|
23
|
+
content: {
|
|
24
|
+
type: string;
|
|
25
|
+
text: string;
|
|
26
|
+
}[];
|
|
27
|
+
}>;
|
|
28
|
+
export declare function handlePostPublishDraft(client: PostProxyClient, args: {
|
|
29
|
+
job_id: string;
|
|
30
|
+
}): Promise<{
|
|
31
|
+
content: {
|
|
32
|
+
type: string;
|
|
33
|
+
text: string;
|
|
34
|
+
}[];
|
|
35
|
+
}>;
|
|
36
|
+
export declare function handlePostDelete(client: PostProxyClient, args: {
|
|
37
|
+
job_id: string;
|
|
38
|
+
}): Promise<{
|
|
39
|
+
content: {
|
|
40
|
+
type: string;
|
|
41
|
+
text: string;
|
|
42
|
+
}[];
|
|
43
|
+
}>;
|
|
44
|
+
//# sourceMappingURL=post.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"post.d.ts","sourceRoot":"","sources":["../../src/tools/post.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAOxD,wBAAsB,iBAAiB,CACrC,MAAM,EAAE,eAAe,EACvB,IAAI,EAAE;IACJ,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC;CACjD;;;;;GA+HF;AAED,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,eAAe,EACvB,IAAI,EAAE;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE;;;;;GA8FzB;AAED,wBAAsB,sBAAsB,CAC1C,MAAM,EAAE,eAAe,EACvB,IAAI,EAAE;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE;;;;;GAoDzB;AAED,wBAAsB,gBAAgB,CACpC,MAAM,EAAE,eAAe,EACvB,IAAI,EAAE;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE;;;;;GA8BzB"}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Post tools: post.publish, post.status, post.delete
|
|
3
|
+
*/
|
|
4
|
+
import { PostPublishSchema } from "../utils/validation.js";
|
|
5
|
+
import { generateIdempotencyKey } from "../utils/idempotency.js";
|
|
6
|
+
import { createError, ErrorCodes } from "../utils/errors.js";
|
|
7
|
+
import { logError } from "../utils/logger.js";
|
|
8
|
+
import { handleProfilesList } from "./profiles.js";
|
|
9
|
+
export async function handlePostPublish(client, args) {
|
|
10
|
+
// Validate input
|
|
11
|
+
try {
|
|
12
|
+
PostPublishSchema.parse(args);
|
|
13
|
+
}
|
|
14
|
+
catch (error) {
|
|
15
|
+
throw createError(ErrorCodes.VALIDATION_ERROR, `Invalid input: ${error.message}`);
|
|
16
|
+
}
|
|
17
|
+
// If require_confirmation, return summary without publishing
|
|
18
|
+
if (args.require_confirmation) {
|
|
19
|
+
return {
|
|
20
|
+
content: [
|
|
21
|
+
{
|
|
22
|
+
type: "text",
|
|
23
|
+
text: JSON.stringify({
|
|
24
|
+
summary: {
|
|
25
|
+
targets: args.targets,
|
|
26
|
+
content_preview: args.content.substring(0, 100) + (args.content.length > 100 ? "..." : ""),
|
|
27
|
+
media_count: args.media?.length || 0,
|
|
28
|
+
schedule_time: args.schedule,
|
|
29
|
+
draft: args.draft || false,
|
|
30
|
+
platforms: args.platforms || {},
|
|
31
|
+
},
|
|
32
|
+
}, null, 2),
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
// Get profiles to convert target IDs to platform names
|
|
38
|
+
const profilesResult = await handleProfilesList(client);
|
|
39
|
+
const profilesData = JSON.parse(profilesResult.content[0]?.text || "{}");
|
|
40
|
+
const targetsMap = new Map();
|
|
41
|
+
for (const target of profilesData.targets || []) {
|
|
42
|
+
targetsMap.set(target.id, target);
|
|
43
|
+
}
|
|
44
|
+
// Convert target IDs to platform names (API expects platform names, not IDs)
|
|
45
|
+
const platformNames = [];
|
|
46
|
+
for (const targetId of args.targets) {
|
|
47
|
+
const target = targetsMap.get(targetId);
|
|
48
|
+
if (!target) {
|
|
49
|
+
throw createError(ErrorCodes.TARGET_NOT_FOUND, `Target ${targetId} not found`);
|
|
50
|
+
}
|
|
51
|
+
platformNames.push(target.platform); // platform name (e.g., "twitter")
|
|
52
|
+
}
|
|
53
|
+
// Validate that platforms keys match platform names if platforms are provided
|
|
54
|
+
if (args.platforms) {
|
|
55
|
+
const platformKeys = Object.keys(args.platforms);
|
|
56
|
+
const invalidPlatforms = platformKeys.filter((key) => !platformNames.includes(key));
|
|
57
|
+
if (invalidPlatforms.length > 0) {
|
|
58
|
+
throw createError(ErrorCodes.VALIDATION_ERROR, `Platform parameters specified for platforms not in targets: ${invalidPlatforms.join(", ")}. Available platforms: ${platformNames.join(", ")}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
// Generate idempotency key if not provided
|
|
62
|
+
const idempotencyKey = args.idempotency_key || generateIdempotencyKey(args.content, args.targets, args.schedule);
|
|
63
|
+
// Validate draft parameter is correctly passed
|
|
64
|
+
// Ensure draft is explicitly set (true, false, or undefined) and will be handled correctly
|
|
65
|
+
const draftValue = args.draft !== undefined ? args.draft : undefined;
|
|
66
|
+
// Create post
|
|
67
|
+
try {
|
|
68
|
+
const response = await client.createPost({
|
|
69
|
+
content: args.content,
|
|
70
|
+
profiles: platformNames, // API expects platform names, not profile IDs
|
|
71
|
+
schedule: args.schedule,
|
|
72
|
+
media: args.media,
|
|
73
|
+
idempotency_key: idempotencyKey,
|
|
74
|
+
draft: draftValue, // Explicitly pass draft value (true, false, or undefined)
|
|
75
|
+
platforms: args.platforms, // Platform-specific parameters
|
|
76
|
+
});
|
|
77
|
+
// Check if draft was requested but API ignored it
|
|
78
|
+
// Use strict boolean comparison to ensure we catch all cases
|
|
79
|
+
const wasDraftRequested = args.draft === true;
|
|
80
|
+
const isDraftInResponse = Boolean(response.draft) === true;
|
|
81
|
+
const wasProcessedImmediately = response.status === "processed" && wasDraftRequested;
|
|
82
|
+
// Draft is ignored if: it was requested AND (it's not in response OR post was processed immediately)
|
|
83
|
+
const draftIgnored = wasDraftRequested && (!isDraftInResponse || wasProcessedImmediately);
|
|
84
|
+
// Build response object
|
|
85
|
+
const responseData = {
|
|
86
|
+
job_id: response.id,
|
|
87
|
+
status: response.status,
|
|
88
|
+
draft: response.draft,
|
|
89
|
+
scheduled_at: response.scheduled_at,
|
|
90
|
+
created_at: response.created_at,
|
|
91
|
+
};
|
|
92
|
+
// Always include warning field if draft was ignored
|
|
93
|
+
if (draftIgnored) {
|
|
94
|
+
responseData.warning = "Warning: Draft was requested but API returned draft: false. The post may have been processed immediately. This can happen if the API does not support drafts with media or other parameters.";
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
content: [
|
|
98
|
+
{
|
|
99
|
+
type: "text",
|
|
100
|
+
text: JSON.stringify(responseData, null, 2),
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
logError(error, "post.publish");
|
|
107
|
+
throw createError(ErrorCodes.PUBLISH_FAILED, `Failed to publish post: ${error.message}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
export async function handlePostStatus(client, args) {
|
|
111
|
+
if (!args.job_id) {
|
|
112
|
+
throw createError(ErrorCodes.VALIDATION_ERROR, "job_id is required");
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
const postDetails = await client.getPost(args.job_id);
|
|
116
|
+
// Parse platforms into per-platform format
|
|
117
|
+
const platforms = [];
|
|
118
|
+
if (postDetails.platforms) {
|
|
119
|
+
for (const platform of postDetails.platforms) {
|
|
120
|
+
platforms.push({
|
|
121
|
+
platform: platform.platform,
|
|
122
|
+
status: platform.status,
|
|
123
|
+
url: platform.url,
|
|
124
|
+
post_id: platform.post_id,
|
|
125
|
+
error: platform.error || null,
|
|
126
|
+
attempted_at: platform.attempted_at,
|
|
127
|
+
insights: platform.insights,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
// Determine overall status from post status and platform statuses
|
|
132
|
+
let overallStatus = "pending";
|
|
133
|
+
// Handle draft status first
|
|
134
|
+
if (postDetails.status === "draft" || postDetails.draft === true) {
|
|
135
|
+
overallStatus = "draft";
|
|
136
|
+
}
|
|
137
|
+
else if (postDetails.status === "scheduled") {
|
|
138
|
+
overallStatus = "pending";
|
|
139
|
+
}
|
|
140
|
+
else if (postDetails.status === "processing") {
|
|
141
|
+
overallStatus = "processing";
|
|
142
|
+
}
|
|
143
|
+
else if (postDetails.status === "processed") {
|
|
144
|
+
if (platforms.length === 0) {
|
|
145
|
+
overallStatus = "pending";
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
const allPublished = platforms.every((p) => p.status === "published");
|
|
149
|
+
const allFailed = platforms.every((p) => p.status === "failed");
|
|
150
|
+
const anyPending = platforms.some((p) => p.status === "pending" || p.status === "processing");
|
|
151
|
+
if (anyPending) {
|
|
152
|
+
// Only if there are pending/processing platforms - this is truly processing
|
|
153
|
+
overallStatus = "processing";
|
|
154
|
+
}
|
|
155
|
+
else if (allPublished) {
|
|
156
|
+
overallStatus = "complete";
|
|
157
|
+
}
|
|
158
|
+
else if (allFailed) {
|
|
159
|
+
overallStatus = "failed";
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
// Mixed statuses (some published, some failed) - processing is complete
|
|
163
|
+
// Use "complete" since processing is finished, details are in platforms
|
|
164
|
+
overallStatus = "complete";
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
else if (postDetails.status === "pending") {
|
|
169
|
+
overallStatus = "pending";
|
|
170
|
+
}
|
|
171
|
+
return {
|
|
172
|
+
content: [
|
|
173
|
+
{
|
|
174
|
+
type: "text",
|
|
175
|
+
text: JSON.stringify({
|
|
176
|
+
job_id: args.job_id,
|
|
177
|
+
overall_status: overallStatus,
|
|
178
|
+
draft: postDetails.draft || false,
|
|
179
|
+
status: postDetails.status,
|
|
180
|
+
platforms,
|
|
181
|
+
}, null, 2),
|
|
182
|
+
},
|
|
183
|
+
],
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
catch (error) {
|
|
187
|
+
logError(error, "post.status");
|
|
188
|
+
throw createError(ErrorCodes.API_ERROR, `Failed to get post status: ${error.message}`);
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
export async function handlePostPublishDraft(client, args) {
|
|
192
|
+
if (!args.job_id) {
|
|
193
|
+
throw createError(ErrorCodes.VALIDATION_ERROR, "job_id is required");
|
|
194
|
+
}
|
|
195
|
+
try {
|
|
196
|
+
// First check if the post exists and is a draft
|
|
197
|
+
const postDetails = await client.getPost(args.job_id);
|
|
198
|
+
if (!postDetails.draft && postDetails.status !== "draft") {
|
|
199
|
+
throw createError(ErrorCodes.VALIDATION_ERROR, `Post ${args.job_id} is not a draft and cannot be published using this endpoint`);
|
|
200
|
+
}
|
|
201
|
+
// Publish the draft post
|
|
202
|
+
const publishedPost = await client.publishPost(args.job_id);
|
|
203
|
+
return {
|
|
204
|
+
content: [
|
|
205
|
+
{
|
|
206
|
+
type: "text",
|
|
207
|
+
text: JSON.stringify({
|
|
208
|
+
job_id: publishedPost.id,
|
|
209
|
+
status: publishedPost.status,
|
|
210
|
+
draft: publishedPost.draft,
|
|
211
|
+
scheduled_at: publishedPost.scheduled_at,
|
|
212
|
+
created_at: publishedPost.created_at,
|
|
213
|
+
message: "Draft post published successfully",
|
|
214
|
+
}, null, 2),
|
|
215
|
+
},
|
|
216
|
+
],
|
|
217
|
+
};
|
|
218
|
+
}
|
|
219
|
+
catch (error) {
|
|
220
|
+
logError(error, "post.publish_draft");
|
|
221
|
+
// Re-throw validation errors as-is
|
|
222
|
+
if (error instanceof Error && "code" in error && error.code === ErrorCodes.VALIDATION_ERROR) {
|
|
223
|
+
throw error;
|
|
224
|
+
}
|
|
225
|
+
throw createError(ErrorCodes.API_ERROR, `Failed to publish draft post: ${error.message}`);
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
export async function handlePostDelete(client, args) {
|
|
229
|
+
if (!args.job_id) {
|
|
230
|
+
throw createError(ErrorCodes.VALIDATION_ERROR, "job_id is required");
|
|
231
|
+
}
|
|
232
|
+
try {
|
|
233
|
+
await client.deletePost(args.job_id);
|
|
234
|
+
return {
|
|
235
|
+
content: [
|
|
236
|
+
{
|
|
237
|
+
type: "text",
|
|
238
|
+
text: JSON.stringify({
|
|
239
|
+
job_id: args.job_id,
|
|
240
|
+
deleted: true,
|
|
241
|
+
}, null, 2),
|
|
242
|
+
},
|
|
243
|
+
],
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
logError(error, "post.delete");
|
|
248
|
+
throw createError(ErrorCodes.API_ERROR, `Failed to delete post: ${error.message}`);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
//# sourceMappingURL=post.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"post.js","sourceRoot":"","sources":["../../src/tools/post.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAC;AACjE,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAEnD,MAAM,CAAC,KAAK,UAAU,iBAAiB,CACrC,MAAuB,EACvB,IASC;IAED,iBAAiB;IACjB,IAAI,CAAC;QACH,iBAAiB,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IAAC,OAAO,KAAU,EAAE,CAAC;QACpB,MAAM,WAAW,CAAC,UAAU,CAAC,gBAAgB,EAAE,kBAAkB,KAAK,CAAC,OAAO,EAAE,CAAC,CAAC;IACpF,CAAC;IAED,6DAA6D;IAC7D,IAAI,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAC9B,OAAO;YACL,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAClB;wBACE,OAAO,EAAE;4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C;QACnC,IAAI,KAAK,YAAY,KAAK,IAAI,MAAM,IAAI,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,UAAU,CAAC,gBAAgB,EAAE,CAAC;YAC5F,MAAM,KAAK,CAAC;QACd,CAAC;QAED,MAAM,WAAW,CACf,UAAU,CAAC,SAAS,EACpB,iCAAkC,KAAe,CAAC,OAAO,EAAE,CAC5D,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,gBAAgB,CACpC,MAAuB,EACvB,IAAwB;IAExB,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;QACjB,MAAM,WAAW,CAAC,UAAU,CAAC,gBAAgB,EAAE,oBAAoB,CAAC,CAAC;IACvE,CAAC;IAED,IAAI,CAAC;QACH,MAAM,MAAM,CAAC,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QACrC,OAAO;YACL,OAAO,EAAE;gBACP;oBACE,IAAI,EAAE,MAAM;oBACZ,IAAI,EAAE,IAAI,CAAC,SAAS,CAClB;wBACE,MAAM,EAAE,IAAI,CAAC,MAAM;wBACnB,OAAO,EAAE,IAAI;qBACd,EACD,IAAI,EACJ,CAAC,CACF;iBACF;aACF;SACF,CAAC;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,QAAQ,CAAC,KAAc,EAAE,aAAa,CAAC,CAAC;QACxC,MAAM,WAAW,CACf,UAAU,CAAC,SAAS,EACpB,0BAA2B,KAAe,CAAC,OAAO,EAAE,CACrD,CAAC;IACJ,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Profiles tools: profiles.list
|
|
3
|
+
*/
|
|
4
|
+
import type { PostProxyClient } from "../api/client.js";
|
|
5
|
+
export declare function handleProfilesList(client: PostProxyClient): Promise<{
|
|
6
|
+
content: {
|
|
7
|
+
type: string;
|
|
8
|
+
text: string;
|
|
9
|
+
}[];
|
|
10
|
+
}>;
|
|
11
|
+
//# sourceMappingURL=profiles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiles.d.ts","sourceRoot":"","sources":["../../src/tools/profiles.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAKxD,wBAAsB,kBAAkB,CAAC,MAAM,EAAE,eAAe;;;;;GA2D/D"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Profiles tools: profiles.list
|
|
3
|
+
*/
|
|
4
|
+
import { getApiKey } from "../auth/credentials.js";
|
|
5
|
+
import { createError, ErrorCodes } from "../utils/errors.js";
|
|
6
|
+
import { logError, logToolCall } from "../utils/logger.js";
|
|
7
|
+
export async function handleProfilesList(client) {
|
|
8
|
+
logToolCall("profiles.list", {});
|
|
9
|
+
// Check API key
|
|
10
|
+
const apiKey = getApiKey();
|
|
11
|
+
if (!apiKey) {
|
|
12
|
+
throw createError(ErrorCodes.AUTH_MISSING, "API key is not configured");
|
|
13
|
+
}
|
|
14
|
+
try {
|
|
15
|
+
// Get all profile groups
|
|
16
|
+
const profileGroups = await client.getProfileGroups();
|
|
17
|
+
// Get profiles for each group
|
|
18
|
+
const allTargets = [];
|
|
19
|
+
for (const group of profileGroups) {
|
|
20
|
+
try {
|
|
21
|
+
const profiles = await client.getProfiles(group.id);
|
|
22
|
+
for (const profile of profiles) {
|
|
23
|
+
allTargets.push({
|
|
24
|
+
id: profile.id, // Already a string
|
|
25
|
+
name: profile.name,
|
|
26
|
+
platform: profile.platform,
|
|
27
|
+
profile_group_id: profile.profile_group_id, // Already a string
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (error) {
|
|
32
|
+
logError(error, `profiles.list (group ${group.id})`);
|
|
33
|
+
// Continue with other groups even if one fails
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return {
|
|
37
|
+
content: [
|
|
38
|
+
{
|
|
39
|
+
type: "text",
|
|
40
|
+
text: JSON.stringify({
|
|
41
|
+
targets: allTargets,
|
|
42
|
+
}, null, 2),
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
logError(error, "profiles.list");
|
|
49
|
+
throw createError(ErrorCodes.API_ERROR, `Failed to retrieve profiles: ${error.message}`);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
//# sourceMappingURL=profiles.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"profiles.js","sourceRoot":"","sources":["../../src/tools/profiles.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC7D,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAE3D,MAAM,CAAC,KAAK,UAAU,kBAAkB,CAAC,MAAuB;IAC9D,WAAW,CAAC,eAAe,EAAE,EAAE,CAAC,CAAC;IAEjC,gBAAgB;IAChB,MAAM,MAAM,GAAG,SAAS,EAAE,CAAC;IAC3B,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,WAAW,CAAC,UAAU,CAAC,YAAY,EAAE,2BAA2B,CAAC,CAAC;IAC1E,CAAC;IAED,IAAI,CAAC;QACH,yBAAyB;QACzB,MAAM,aAAa,GAAG,MAAM,MAAM,CAAC,gBAAgB,EAAE,CAAC;QAEtD,8BAA8B;QAC9B,MAAM,UAAU,GAKX,EAAE,CAAC;QAER,KAAK,MAAM,KAAK,IAAI,aAAa,EAAE,CAAC;YAClC,IAAI,CAAC;gBACH,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;gBACpD,KAAK,MAAM,OAAO,IAAI,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