@framers/agentos-ext-tool-social-analytics 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 ADDED
@@ -0,0 +1,98 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
10
+
11
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
12
+
13
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
14
+
15
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
16
+
17
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
18
+
19
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
20
+
21
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
22
+
23
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
24
+
25
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
26
+
27
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
28
+
29
+ 2. Grant of Copyright License.
30
+
31
+ Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
32
+
33
+ 3. Grant of Patent License.
34
+
35
+ Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
36
+
37
+ 4. Redistribution.
38
+
39
+ You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
40
+
41
+ (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
42
+
43
+ (b) You must cause any modified files to carry prominent notices stating that You changed the files; and
44
+
45
+ (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
46
+
47
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
48
+
49
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
50
+
51
+ 5. Submission of Contributions.
52
+
53
+ Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
54
+
55
+ 6. Trademarks.
56
+
57
+ This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
58
+
59
+ 7. Disclaimer of Warranty.
60
+
61
+ Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
62
+
63
+ 8. Limitation of Liability.
64
+
65
+ In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
66
+
67
+ 9. Accepting Warranty or Additional Liability.
68
+
69
+ While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
70
+
71
+ END OF TERMS AND CONDITIONS
72
+
73
+ APPENDIX: How to apply the Apache License to your work.
74
+
75
+ To apply the Apache License to your work, attach the following
76
+ boilerplate notice, with the fields enclosed by brackets "[]"
77
+ replaced with your own identifying information. (Don't include
78
+ the brackets!) The text should be enclosed in the appropriate
79
+ comment syntax for the file format. We also recommend that a
80
+ file or class name and description of purpose be included on the
81
+ same "printed page" as the copyright notice for easier
82
+ identification within third-party archives.
83
+
84
+ Copyright (c) 2025 Framers
85
+
86
+ Licensed under the Apache License, Version 2.0 (the "License");
87
+ you may not use this file except in compliance with the License.
88
+ You may obtain a copy of the License at
89
+
90
+ http://www.apache.org/licenses/LICENSE-2.0
91
+
92
+ Unless required by applicable law or agreed to in writing, software
93
+ distributed under the License is distributed on an "AS IS" BASIS,
94
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
95
+ See the License for the specific language governing permissions and
96
+ limitations under the License.
97
+
98
+
@@ -0,0 +1,92 @@
1
+ /**
2
+ * @fileoverview Cross-Platform Analytics Tool — aggregate engagement metrics from N platforms.
3
+ *
4
+ * This tool acts as an orchestrator that delegates to per-platform analytics tools
5
+ * (twitterAnalytics, instagramAnalytics, etc.) and aggregates the results into a
6
+ * unified view with per-platform breakdowns and overall totals.
7
+ */
8
+ export interface CrossPlatformAnalyticsInput {
9
+ /** Platforms to query analytics from. */
10
+ platforms: string[];
11
+ /** Platform-to-postId mapping (e.g., { twitter: "123", linkedin: "456" }). */
12
+ postIds?: Record<string, string>;
13
+ /** Time range for analytics (default: '7d'). */
14
+ timeRange?: '24h' | '7d' | '30d' | '90d';
15
+ }
16
+ export interface PlatformMetrics {
17
+ likes?: number;
18
+ comments?: number;
19
+ shares?: number;
20
+ impressions?: number;
21
+ engagementRate?: number;
22
+ /** Platform-specific raw data fields. */
23
+ [key: string]: unknown;
24
+ }
25
+ export interface PlatformAnalyticsResult {
26
+ /** Metrics when successful, or an error descriptor on failure. */
27
+ [key: string]: PlatformMetrics | {
28
+ error: string;
29
+ };
30
+ }
31
+ export interface AnalyticsTotals {
32
+ likes: number;
33
+ comments: number;
34
+ shares: number;
35
+ impressions: number;
36
+ /** Overall engagement rate as a percentage (0-100). */
37
+ engagement: number;
38
+ }
39
+ export interface CrossPlatformAnalyticsOutput {
40
+ platforms: PlatformAnalyticsResult;
41
+ totals: AnalyticsTotals;
42
+ timeRange: string;
43
+ }
44
+ export type ToolExecutorFn = (toolName: string, args: Record<string, unknown>) => Promise<{
45
+ success: boolean;
46
+ data?: Record<string, unknown>;
47
+ error?: string;
48
+ }>;
49
+ export declare class CrossPlatformAnalyticsTool {
50
+ readonly id = "crossPlatformAnalytics";
51
+ readonly name = "crossPlatformAnalytics";
52
+ readonly displayName = "Cross-Platform Analytics";
53
+ readonly description: string;
54
+ readonly category = "social";
55
+ readonly version = "0.1.0";
56
+ readonly hasSideEffects = false;
57
+ readonly inputSchema: {
58
+ type: "object";
59
+ properties: {
60
+ platforms: {
61
+ type: string;
62
+ items: {
63
+ type: string;
64
+ };
65
+ description: string;
66
+ };
67
+ postIds: {
68
+ type: string;
69
+ additionalProperties: {
70
+ type: string;
71
+ };
72
+ description: string;
73
+ };
74
+ timeRange: {
75
+ type: string;
76
+ enum: string[];
77
+ description: string;
78
+ };
79
+ };
80
+ required: string[];
81
+ };
82
+ private toolExecutor?;
83
+ setToolExecutor(executor: ToolExecutorFn): void;
84
+ execute(args: CrossPlatformAnalyticsInput): Promise<{
85
+ success: boolean;
86
+ data?: CrossPlatformAnalyticsOutput;
87
+ error?: string;
88
+ }>;
89
+ /** Safely coerce an unknown value to a number, defaulting to 0. */
90
+ private toNumber;
91
+ }
92
+ //# sourceMappingURL=CrossPlatformAnalyticsTool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CrossPlatformAnalyticsTool.d.ts","sourceRoot":"","sources":["../src/CrossPlatformAnalyticsTool.ts"],"names":[],"mappings":"AACA;;;;;;GAMG;AAMH,MAAM,WAAW,2BAA2B;IAC1C,yCAAyC;IACzC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,8EAA8E;IAC9E,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,gDAAgD;IAChD,SAAS,CAAC,EAAE,KAAK,GAAG,IAAI,GAAG,KAAK,GAAG,KAAK,CAAC;CAC1C;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,yCAAyC;IACzC,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,uBAAuB;IACtC,kEAAkE;IAClE,CAAC,GAAG,EAAE,MAAM,GAAG,eAAe,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC;CACpD;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,uDAAuD;IACvD,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,4BAA4B;IAC3C,SAAS,EAAE,uBAAuB,CAAC;IACnC,MAAM,EAAE,eAAe,CAAC;IACxB,SAAS,EAAE,MAAM,CAAC;CACnB;AAMD,MAAM,MAAM,cAAc,GAAG,CAC3B,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC1B,OAAO,CAAC;IAAE,OAAO,EAAE,OAAO,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AAMnF,qBAAa,0BAA0B;IACrC,QAAQ,CAAC,EAAE,4BAA4B;IACvC,QAAQ,CAAC,IAAI,4BAA4B;IACzC,QAAQ,CAAC,WAAW,8BAA8B;IAClD,QAAQ,CAAC,WAAW,SAEkD;IACtE,QAAQ,CAAC,QAAQ,YAAY;IAC7B,QAAQ,CAAC,OAAO,WAAW;IAC3B,QAAQ,CAAC,cAAc,SAAS;IAEhC,QAAQ,CAAC,WAAW;;;;;;;;;;;;;;;;;;;;;;;;MAoBlB;IAMF,OAAO,CAAC,YAAY,CAAC,CAAiB;IAEtC,eAAe,CAAC,QAAQ,EAAE,cAAc,GAAG,IAAI;IAQzC,OAAO,CACX,IAAI,EAAE,2BAA2B,GAChC,OAAO,CAAC;QAAE,OAAO,EAAE,OAAO,CAAC;QAAC,IAAI,CAAC,EAAE,4BAA4B,CAAC;QAAC,KAAK,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAqErF,mEAAmE;IACnE,OAAO,CAAC,QAAQ;CAQjB"}
@@ -0,0 +1,123 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @fileoverview Cross-Platform Analytics Tool — aggregate engagement metrics from N platforms.
4
+ *
5
+ * This tool acts as an orchestrator that delegates to per-platform analytics tools
6
+ * (twitterAnalytics, instagramAnalytics, etc.) and aggregates the results into a
7
+ * unified view with per-platform breakdowns and overall totals.
8
+ */
9
+ /* ------------------------------------------------------------------ */
10
+ /* CrossPlatformAnalyticsTool */
11
+ /* ------------------------------------------------------------------ */
12
+ export class CrossPlatformAnalyticsTool {
13
+ id = 'crossPlatformAnalytics';
14
+ name = 'crossPlatformAnalytics';
15
+ displayName = 'Cross-Platform Analytics';
16
+ description = 'Aggregate engagement metrics across social platforms. Returns likes, comments, ' +
17
+ 'shares, impressions, and engagement rate per platform and totals.';
18
+ category = 'social';
19
+ version = '0.1.0';
20
+ hasSideEffects = false;
21
+ inputSchema = {
22
+ type: 'object',
23
+ properties: {
24
+ platforms: {
25
+ type: 'array',
26
+ items: { type: 'string' },
27
+ description: 'Platforms to query analytics from',
28
+ },
29
+ postIds: {
30
+ type: 'object',
31
+ additionalProperties: { type: 'string' },
32
+ description: 'Platform-to-postId mapping (e.g., { twitter: "123", linkedin: "456" })',
33
+ },
34
+ timeRange: {
35
+ type: 'string',
36
+ enum: ['24h', '7d', '30d', '90d'],
37
+ description: 'Time range for analytics (default: 7d)',
38
+ },
39
+ },
40
+ required: ['platforms'],
41
+ };
42
+ /* -------------------------------------------------------------- */
43
+ /* Tool executor — set by the orchestrator that loads this ext */
44
+ /* -------------------------------------------------------------- */
45
+ toolExecutor;
46
+ setToolExecutor(executor) {
47
+ this.toolExecutor = executor;
48
+ }
49
+ /* -------------------------------------------------------------- */
50
+ /* execute() */
51
+ /* -------------------------------------------------------------- */
52
+ async execute(args) {
53
+ const platformResults = {};
54
+ const totals = {
55
+ likes: 0,
56
+ comments: 0,
57
+ shares: 0,
58
+ impressions: 0,
59
+ engagement: 0,
60
+ };
61
+ for (const platform of args.platforms) {
62
+ const analyticsToolName = `${platform}Analytics`;
63
+ const postId = args.postIds?.[platform];
64
+ try {
65
+ if (this.toolExecutor && postId) {
66
+ const result = await this.toolExecutor(analyticsToolName, {
67
+ postId,
68
+ timeRange: args.timeRange ?? '7d',
69
+ });
70
+ if (result.success && result.data) {
71
+ const data = result.data;
72
+ platformResults[platform] = data;
73
+ // Accumulate totals — normalize platform-specific field names.
74
+ totals.likes += this.toNumber(data.likes ?? data.favouritesCount);
75
+ totals.comments += this.toNumber(data.comments ?? data.repliesCount);
76
+ totals.shares += this.toNumber(data.shares ?? data.retweets ?? data.reblogsCount ?? data.reposts);
77
+ totals.impressions += this.toNumber(data.impressions ?? data.views);
78
+ }
79
+ else {
80
+ platformResults[platform] = { error: result.error ?? 'No data returned' };
81
+ }
82
+ }
83
+ else {
84
+ platformResults[platform] = {
85
+ error: postId
86
+ ? 'No tool executor available'
87
+ : 'No post ID provided for this platform',
88
+ };
89
+ }
90
+ }
91
+ catch (err) {
92
+ const message = err instanceof Error ? err.message : String(err);
93
+ platformResults[platform] = { error: message };
94
+ }
95
+ }
96
+ // Calculate overall engagement rate.
97
+ if (totals.impressions > 0) {
98
+ totals.engagement = Number((((totals.likes + totals.comments + totals.shares) / totals.impressions) * 100).toFixed(2));
99
+ }
100
+ return {
101
+ success: true,
102
+ data: {
103
+ platforms: platformResults,
104
+ totals,
105
+ timeRange: args.timeRange ?? '7d',
106
+ },
107
+ };
108
+ }
109
+ /* -------------------------------------------------------------- */
110
+ /* Helpers */
111
+ /* -------------------------------------------------------------- */
112
+ /** Safely coerce an unknown value to a number, defaulting to 0. */
113
+ toNumber(value) {
114
+ if (typeof value === 'number' && !Number.isNaN(value))
115
+ return value;
116
+ if (typeof value === 'string') {
117
+ const parsed = Number(value);
118
+ return Number.isNaN(parsed) ? 0 : parsed;
119
+ }
120
+ return 0;
121
+ }
122
+ }
123
+ //# sourceMappingURL=CrossPlatformAnalyticsTool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CrossPlatformAnalyticsTool.js","sourceRoot":"","sources":["../src/CrossPlatformAnalyticsTool.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * Cross-Platform Social Analytics Extension Pack — aggregate engagement metrics
3
+ * from multiple social platforms in a single query.
4
+ */
5
+ export interface ExtensionContext {
6
+ options?: Record<string, unknown>;
7
+ secrets?: Record<string, string>;
8
+ getSecret?: (key: string) => string | undefined;
9
+ logger?: {
10
+ info: (msg: string) => void;
11
+ };
12
+ }
13
+ export interface ExtensionPack {
14
+ name: string;
15
+ version: string;
16
+ descriptors: Array<{
17
+ id: string;
18
+ kind: string;
19
+ priority?: number;
20
+ payload: unknown;
21
+ }>;
22
+ onActivate?: () => Promise<void>;
23
+ onDeactivate?: () => Promise<void>;
24
+ }
25
+ export declare function createExtensionPack(context: ExtensionContext): ExtensionPack;
26
+ export { CrossPlatformAnalyticsTool } from './CrossPlatformAnalyticsTool.js';
27
+ export type { CrossPlatformAnalyticsInput, CrossPlatformAnalyticsOutput, PlatformMetrics, PlatformAnalyticsResult, AnalyticsTotals, ToolExecutorFn, } from './CrossPlatformAnalyticsTool.js';
28
+ export default createExtensionPack;
29
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA;;;GAGG;AAQH,MAAM,WAAW,gBAAgB;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAClC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,SAAS,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,MAAM,GAAG,SAAS,CAAC;IAChD,MAAM,CAAC,EAAE;QAAE,IAAI,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAA;KAAE,CAAC;CAC1C;AAED,MAAM,WAAW,aAAa;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,WAAW,EAAE,KAAK,CAAC;QACjB,EAAE,EAAE,MAAM,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,EAAE,OAAO,CAAC;KAClB,CAAC,CAAC;IACH,UAAU,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACjC,YAAY,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC;AAMD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,GAAG,aAAa,CAiB5E;AAMD,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAC7E,YAAY,EACV,2BAA2B,EAC3B,4BAA4B,EAC5B,eAAe,EACf,uBAAuB,EACvB,eAAe,EACf,cAAc,GACf,MAAM,iCAAiC,CAAC;AAEzC,eAAe,mBAAmB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,32 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * Cross-Platform Social Analytics Extension Pack — aggregate engagement metrics
4
+ * from multiple social platforms in a single query.
5
+ */
6
+ import { CrossPlatformAnalyticsTool } from './CrossPlatformAnalyticsTool.js';
7
+ /* ------------------------------------------------------------------ */
8
+ /* Factory */
9
+ /* ------------------------------------------------------------------ */
10
+ export function createExtensionPack(context) {
11
+ const tool = new CrossPlatformAnalyticsTool();
12
+ return {
13
+ name: '@framers/agentos-ext-tool-social-analytics',
14
+ version: '0.1.0',
15
+ descriptors: [
16
+ {
17
+ id: tool.name,
18
+ kind: 'tool',
19
+ priority: 50,
20
+ payload: tool,
21
+ },
22
+ ],
23
+ onActivate: async () => context.logger?.info('Cross-Platform Analytics Extension activated'),
24
+ onDeactivate: async () => context.logger?.info('Cross-Platform Analytics Extension deactivated'),
25
+ };
26
+ }
27
+ /* ------------------------------------------------------------------ */
28
+ /* Re-exports */
29
+ /* ------------------------------------------------------------------ */
30
+ export { CrossPlatformAnalyticsTool } from './CrossPlatformAnalyticsTool.js';
31
+ export default createExtensionPack;
32
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc;AACd;;;GAGG;AAEH,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AA0B7E,wEAAwE;AACxE,yEAAyE;AACzE,wEAAwE;AAExE,MAAM,UAAU,mBAAmB,CAAC,OAAyB;IAC3D,MAAM,IAAI,GAAG,IAAI,0BAA0B,EAAE,CAAC;IAE9C,OAAO;QACL,IAAI,EAAE,4CAA4C;QAClD,OAAO,EAAE,OAAO;QAChB,WAAW,EAAE;YACX;gBACE,EAAE,EAAE,IAAI,CAAC,IAAI;gBACb,IAAI,EAAE,MAAe;gBACrB,QAAQ,EAAE,EAAE;gBACZ,OAAO,EAAE,IAAI;aACd;SACF;QACD,UAAU,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,8CAA8C,CAAC;QAC5F,YAAY,EAAE,KAAK,IAAI,EAAE,CAAC,OAAO,CAAC,MAAM,EAAE,IAAI,CAAC,gDAAgD,CAAC;KACjG,CAAC;AACJ,CAAC;AAED,wEAAwE;AACxE,yEAAyE;AACzE,wEAAwE;AAExE,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC;AAU7E,eAAe,mBAAmB,CAAC"}
package/manifest.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "$schema": "https://agentos.sh/schemas/extension-manifest-v1.json",
3
+ "id": "com.framers.tools.social-analytics",
4
+ "name": "Cross-Platform Social Analytics Tool",
5
+ "version": "0.1.0",
6
+ "description": "Aggregate engagement metrics (likes, comments, shares, impressions, engagement rate) across multiple social platforms in a single query.",
7
+ "author": {
8
+ "name": "Frame.dev",
9
+ "email": "support@frame.dev",
10
+ "url": "https://github.com/framersai"
11
+ },
12
+ "license": "MIT",
13
+ "keywords": ["social", "analytics", "engagement", "cross-platform", "metrics"],
14
+ "agentosVersion": "^2.0.0",
15
+ "categories": ["tool", "social"],
16
+ "platforms": [],
17
+ "sdk": "none",
18
+ "extensions": [
19
+ {
20
+ "kind": "tool",
21
+ "id": "crossPlatformAnalytics",
22
+ "displayName": "Cross-Platform Analytics",
23
+ "description": "Aggregate engagement metrics across social platforms",
24
+ "entry": "./dist/CrossPlatformAnalyticsTool.js"
25
+ }
26
+ ],
27
+ "requiredSecrets": [],
28
+ "features": [
29
+ "Aggregate metrics from multiple platforms",
30
+ "Per-platform engagement breakdown",
31
+ "Total engagement rate calculation",
32
+ "Flexible time range querying",
33
+ "Graceful per-platform error handling"
34
+ ]
35
+ }
package/package.json ADDED
@@ -0,0 +1,67 @@
1
+ {
2
+ "name": "@framers/agentos-ext-tool-social-analytics",
3
+ "version": "0.1.0",
4
+ "description": "Cross-platform social analytics tool — aggregate engagement metrics from multiple platforms in a single query.",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "module",
8
+ "sideEffects": false,
9
+ "exports": {
10
+ ".": {
11
+ "import": "./dist/index.js",
12
+ "types": "./dist/index.d.ts"
13
+ },
14
+ "./manifest.json": "./manifest.json",
15
+ "./package.json": "./package.json"
16
+ },
17
+ "keywords": [
18
+ "agentos",
19
+ "extension",
20
+ "social",
21
+ "analytics",
22
+ "cross-platform",
23
+ "engagement"
24
+ ],
25
+ "author": {
26
+ "name": "Framers AI",
27
+ "email": "team@frame.dev",
28
+ "url": "https://frame.dev"
29
+ },
30
+ "contributors": [
31
+ {
32
+ "name": "Johnny Dunn",
33
+ "email": "johnnyfived@protonmail.com",
34
+ "url": "https://github.com/jddunn"
35
+ }
36
+ ],
37
+ "license": "MIT",
38
+ "repository": {
39
+ "type": "git",
40
+ "url": "https://github.com/framersai/agentos-extensions.git",
41
+ "directory": "registry/curated/tools/social-analytics"
42
+ },
43
+ "publishConfig": {
44
+ "access": "public"
45
+ },
46
+ "peerDependencies": {
47
+ "@framers/agentos": "^0.5.2"
48
+ },
49
+ "devDependencies": {
50
+ "@framers/agentos": "^0.6.6",
51
+ "@types/node": "^20.12.12",
52
+ "@vitest/coverage-v8": "^1.6.0",
53
+ "rimraf": "^5.0.7",
54
+ "typescript": "^5.4.5",
55
+ "vitest": "^1.6.0"
56
+ },
57
+ "scripts": {
58
+ "build": "tsc",
59
+ "dev": "tsc --watch",
60
+ "test": "vitest run",
61
+ "test:watch": "vitest",
62
+ "test:coverage": "vitest run --coverage",
63
+ "lint": "eslint src --ext .ts",
64
+ "typecheck": "tsc --noEmit",
65
+ "clean": "rimraf dist"
66
+ }
67
+ }
@@ -0,0 +1,193 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @fileoverview Cross-Platform Analytics Tool — aggregate engagement metrics from N platforms.
4
+ *
5
+ * This tool acts as an orchestrator that delegates to per-platform analytics tools
6
+ * (twitterAnalytics, instagramAnalytics, etc.) and aggregates the results into a
7
+ * unified view with per-platform breakdowns and overall totals.
8
+ */
9
+
10
+ /* ------------------------------------------------------------------ */
11
+ /* Types */
12
+ /* ------------------------------------------------------------------ */
13
+
14
+ export interface CrossPlatformAnalyticsInput {
15
+ /** Platforms to query analytics from. */
16
+ platforms: string[];
17
+ /** Platform-to-postId mapping (e.g., { twitter: "123", linkedin: "456" }). */
18
+ postIds?: Record<string, string>;
19
+ /** Time range for analytics (default: '7d'). */
20
+ timeRange?: '24h' | '7d' | '30d' | '90d';
21
+ }
22
+
23
+ export interface PlatformMetrics {
24
+ likes?: number;
25
+ comments?: number;
26
+ shares?: number;
27
+ impressions?: number;
28
+ engagementRate?: number;
29
+ /** Platform-specific raw data fields. */
30
+ [key: string]: unknown;
31
+ }
32
+
33
+ export interface PlatformAnalyticsResult {
34
+ /** Metrics when successful, or an error descriptor on failure. */
35
+ [key: string]: PlatformMetrics | { error: string };
36
+ }
37
+
38
+ export interface AnalyticsTotals {
39
+ likes: number;
40
+ comments: number;
41
+ shares: number;
42
+ impressions: number;
43
+ /** Overall engagement rate as a percentage (0-100). */
44
+ engagement: number;
45
+ }
46
+
47
+ export interface CrossPlatformAnalyticsOutput {
48
+ platforms: PlatformAnalyticsResult;
49
+ totals: AnalyticsTotals;
50
+ timeRange: string;
51
+ }
52
+
53
+ /* ------------------------------------------------------------------ */
54
+ /* Tool executor callback type */
55
+ /* ------------------------------------------------------------------ */
56
+
57
+ export type ToolExecutorFn = (
58
+ toolName: string,
59
+ args: Record<string, unknown>,
60
+ ) => Promise<{ success: boolean; data?: Record<string, unknown>; error?: string }>;
61
+
62
+ /* ------------------------------------------------------------------ */
63
+ /* CrossPlatformAnalyticsTool */
64
+ /* ------------------------------------------------------------------ */
65
+
66
+ export class CrossPlatformAnalyticsTool {
67
+ readonly id = 'crossPlatformAnalytics';
68
+ readonly name = 'crossPlatformAnalytics';
69
+ readonly displayName = 'Cross-Platform Analytics';
70
+ readonly description =
71
+ 'Aggregate engagement metrics across social platforms. Returns likes, comments, ' +
72
+ 'shares, impressions, and engagement rate per platform and totals.';
73
+ readonly category = 'social';
74
+ readonly version = '0.1.0';
75
+ readonly hasSideEffects = false;
76
+
77
+ readonly inputSchema = {
78
+ type: 'object' as const,
79
+ properties: {
80
+ platforms: {
81
+ type: 'array',
82
+ items: { type: 'string' },
83
+ description: 'Platforms to query analytics from',
84
+ },
85
+ postIds: {
86
+ type: 'object',
87
+ additionalProperties: { type: 'string' },
88
+ description: 'Platform-to-postId mapping (e.g., { twitter: "123", linkedin: "456" })',
89
+ },
90
+ timeRange: {
91
+ type: 'string',
92
+ enum: ['24h', '7d', '30d', '90d'],
93
+ description: 'Time range for analytics (default: 7d)',
94
+ },
95
+ },
96
+ required: ['platforms'],
97
+ };
98
+
99
+ /* -------------------------------------------------------------- */
100
+ /* Tool executor — set by the orchestrator that loads this ext */
101
+ /* -------------------------------------------------------------- */
102
+
103
+ private toolExecutor?: ToolExecutorFn;
104
+
105
+ setToolExecutor(executor: ToolExecutorFn): void {
106
+ this.toolExecutor = executor;
107
+ }
108
+
109
+ /* -------------------------------------------------------------- */
110
+ /* execute() */
111
+ /* -------------------------------------------------------------- */
112
+
113
+ async execute(
114
+ args: CrossPlatformAnalyticsInput,
115
+ ): Promise<{ success: boolean; data?: CrossPlatformAnalyticsOutput; error?: string }> {
116
+ const platformResults: PlatformAnalyticsResult = {};
117
+ const totals: AnalyticsTotals = {
118
+ likes: 0,
119
+ comments: 0,
120
+ shares: 0,
121
+ impressions: 0,
122
+ engagement: 0,
123
+ };
124
+
125
+ for (const platform of args.platforms) {
126
+ const analyticsToolName = `${platform}Analytics`;
127
+ const postId = args.postIds?.[platform];
128
+
129
+ try {
130
+ if (this.toolExecutor && postId) {
131
+ const result = await this.toolExecutor(analyticsToolName, {
132
+ postId,
133
+ timeRange: args.timeRange ?? '7d',
134
+ });
135
+
136
+ if (result.success && result.data) {
137
+ const data = result.data;
138
+ platformResults[platform] = data as PlatformMetrics;
139
+
140
+ // Accumulate totals — normalize platform-specific field names.
141
+ totals.likes += this.toNumber(data.likes ?? data.favouritesCount);
142
+ totals.comments += this.toNumber(data.comments ?? data.repliesCount);
143
+ totals.shares += this.toNumber(
144
+ data.shares ?? data.retweets ?? data.reblogsCount ?? data.reposts,
145
+ );
146
+ totals.impressions += this.toNumber(data.impressions ?? data.views);
147
+ } else {
148
+ platformResults[platform] = { error: result.error ?? 'No data returned' };
149
+ }
150
+ } else {
151
+ platformResults[platform] = {
152
+ error: postId
153
+ ? 'No tool executor available'
154
+ : 'No post ID provided for this platform',
155
+ };
156
+ }
157
+ } catch (err: unknown) {
158
+ const message = err instanceof Error ? err.message : String(err);
159
+ platformResults[platform] = { error: message };
160
+ }
161
+ }
162
+
163
+ // Calculate overall engagement rate.
164
+ if (totals.impressions > 0) {
165
+ totals.engagement = Number(
166
+ (((totals.likes + totals.comments + totals.shares) / totals.impressions) * 100).toFixed(2),
167
+ );
168
+ }
169
+
170
+ return {
171
+ success: true,
172
+ data: {
173
+ platforms: platformResults,
174
+ totals,
175
+ timeRange: args.timeRange ?? '7d',
176
+ },
177
+ };
178
+ }
179
+
180
+ /* -------------------------------------------------------------- */
181
+ /* Helpers */
182
+ /* -------------------------------------------------------------- */
183
+
184
+ /** Safely coerce an unknown value to a number, defaulting to 0. */
185
+ private toNumber(value: unknown): number {
186
+ if (typeof value === 'number' && !Number.isNaN(value)) return value;
187
+ if (typeof value === 'string') {
188
+ const parsed = Number(value);
189
+ return Number.isNaN(parsed) ? 0 : parsed;
190
+ }
191
+ return 0;
192
+ }
193
+ }
package/src/index.ts ADDED
@@ -0,0 +1,70 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * Cross-Platform Social Analytics Extension Pack — aggregate engagement metrics
4
+ * from multiple social platforms in a single query.
5
+ */
6
+
7
+ import { CrossPlatformAnalyticsTool } from './CrossPlatformAnalyticsTool.js';
8
+
9
+ /* ------------------------------------------------------------------ */
10
+ /* Extension pack types */
11
+ /* ------------------------------------------------------------------ */
12
+
13
+ export interface ExtensionContext {
14
+ options?: Record<string, unknown>;
15
+ secrets?: Record<string, string>;
16
+ getSecret?: (key: string) => string | undefined;
17
+ logger?: { info: (msg: string) => void };
18
+ }
19
+
20
+ export interface ExtensionPack {
21
+ name: string;
22
+ version: string;
23
+ descriptors: Array<{
24
+ id: string;
25
+ kind: string;
26
+ priority?: number;
27
+ payload: unknown;
28
+ }>;
29
+ onActivate?: () => Promise<void>;
30
+ onDeactivate?: () => Promise<void>;
31
+ }
32
+
33
+ /* ------------------------------------------------------------------ */
34
+ /* Factory */
35
+ /* ------------------------------------------------------------------ */
36
+
37
+ export function createExtensionPack(context: ExtensionContext): ExtensionPack {
38
+ const tool = new CrossPlatformAnalyticsTool();
39
+
40
+ return {
41
+ name: '@framers/agentos-ext-tool-social-analytics',
42
+ version: '0.1.0',
43
+ descriptors: [
44
+ {
45
+ id: tool.name,
46
+ kind: 'tool' as const,
47
+ priority: 50,
48
+ payload: tool,
49
+ },
50
+ ],
51
+ onActivate: async () => context.logger?.info('Cross-Platform Analytics Extension activated'),
52
+ onDeactivate: async () => context.logger?.info('Cross-Platform Analytics Extension deactivated'),
53
+ };
54
+ }
55
+
56
+ /* ------------------------------------------------------------------ */
57
+ /* Re-exports */
58
+ /* ------------------------------------------------------------------ */
59
+
60
+ export { CrossPlatformAnalyticsTool } from './CrossPlatformAnalyticsTool.js';
61
+ export type {
62
+ CrossPlatformAnalyticsInput,
63
+ CrossPlatformAnalyticsOutput,
64
+ PlatformMetrics,
65
+ PlatformAnalyticsResult,
66
+ AnalyticsTotals,
67
+ ToolExecutorFn,
68
+ } from './CrossPlatformAnalyticsTool.js';
69
+
70
+ export default createExtensionPack;
@@ -0,0 +1,455 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * @fileoverview Unit tests for CrossPlatformAnalyticsTool.
4
+ *
5
+ * Tests cover: tool metadata, multi-platform metric aggregation,
6
+ * field name normalization (likes/favouritesCount, shares/retweets/reblogsCount),
7
+ * engagement rate calculation, missing post IDs, executor errors,
8
+ * and missing executor handling.
9
+ */
10
+
11
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
12
+ import {
13
+ CrossPlatformAnalyticsTool,
14
+ type ToolExecutorFn,
15
+ type CrossPlatformAnalyticsInput,
16
+ } from '../src/CrossPlatformAnalyticsTool.js';
17
+
18
+ /* ------------------------------------------------------------------ */
19
+ /* Helpers */
20
+ /* ------------------------------------------------------------------ */
21
+
22
+ function createMockExecutor(
23
+ platformData: Record<string, Record<string, unknown>>,
24
+ ): ToolExecutorFn {
25
+ return vi.fn(async (toolName: string, _args: Record<string, unknown>) => {
26
+ // Extract platform name from tool name (e.g. "twitterAnalytics" -> "twitter")
27
+ const platform = toolName.replace('Analytics', '');
28
+ if (platformData[platform]) {
29
+ return { success: true, data: platformData[platform] };
30
+ }
31
+ return { success: false, error: `No data configured for ${toolName}` };
32
+ });
33
+ }
34
+
35
+ /* ------------------------------------------------------------------ */
36
+ /* Tests */
37
+ /* ------------------------------------------------------------------ */
38
+
39
+ describe('CrossPlatformAnalyticsTool', () => {
40
+ let tool: CrossPlatformAnalyticsTool;
41
+
42
+ beforeEach(() => {
43
+ tool = new CrossPlatformAnalyticsTool();
44
+ });
45
+
46
+ /* ── Metadata ─────────────────────────────────────────────────── */
47
+
48
+ describe('metadata', () => {
49
+ it('should expose the correct id and name', () => {
50
+ expect(tool.id).toBe('crossPlatformAnalytics');
51
+ expect(tool.name).toBe('crossPlatformAnalytics');
52
+ });
53
+
54
+ it('should declare hasSideEffects as false', () => {
55
+ expect(tool.hasSideEffects).toBe(false);
56
+ });
57
+
58
+ it('should require platforms in the input schema', () => {
59
+ expect(tool.inputSchema.required).toEqual(['platforms']);
60
+ });
61
+
62
+ it('should define timeRange as an enum with 4 options', () => {
63
+ const timeRange = tool.inputSchema.properties.timeRange as { enum: string[] };
64
+ expect(timeRange.enum).toEqual(['24h', '7d', '30d', '90d']);
65
+ });
66
+ });
67
+
68
+ /* ── Aggregation across platforms ─────────────────────────────── */
69
+
70
+ describe('metric aggregation', () => {
71
+ it('should aggregate likes, comments, shares, and impressions from multiple platforms', async () => {
72
+ const executor = createMockExecutor({
73
+ twitter: { likes: 100, comments: 20, shares: 50, impressions: 5000 },
74
+ linkedin: { likes: 200, comments: 30, shares: 80, impressions: 10000 },
75
+ });
76
+ tool.setToolExecutor(executor);
77
+
78
+ const result = await tool.execute({
79
+ platforms: ['twitter', 'linkedin'],
80
+ postIds: { twitter: 'tw-1', linkedin: 'li-1' },
81
+ });
82
+
83
+ expect(result.success).toBe(true);
84
+ const totals = result.data!.totals;
85
+ expect(totals.likes).toBe(300);
86
+ expect(totals.comments).toBe(50);
87
+ expect(totals.shares).toBe(130);
88
+ expect(totals.impressions).toBe(15000);
89
+ });
90
+
91
+ it('should pass timeRange to the per-platform executor', async () => {
92
+ const executor = createMockExecutor({
93
+ twitter: { likes: 10, comments: 2, shares: 5, impressions: 500 },
94
+ });
95
+ tool.setToolExecutor(executor);
96
+
97
+ await tool.execute({
98
+ platforms: ['twitter'],
99
+ postIds: { twitter: 'tw-1' },
100
+ timeRange: '30d',
101
+ });
102
+
103
+ expect(executor).toHaveBeenCalledWith('twitterAnalytics', {
104
+ postId: 'tw-1',
105
+ timeRange: '30d',
106
+ });
107
+ });
108
+
109
+ it('should default timeRange to 7d', async () => {
110
+ const executor = createMockExecutor({
111
+ twitter: { likes: 10, comments: 2, shares: 5, impressions: 500 },
112
+ });
113
+ tool.setToolExecutor(executor);
114
+
115
+ const result = await tool.execute({
116
+ platforms: ['twitter'],
117
+ postIds: { twitter: 'tw-1' },
118
+ });
119
+
120
+ expect(executor).toHaveBeenCalledWith('twitterAnalytics', {
121
+ postId: 'tw-1',
122
+ timeRange: '7d',
123
+ });
124
+
125
+ expect(result.data!.timeRange).toBe('7d');
126
+ });
127
+
128
+ it('should return the timeRange in the output', async () => {
129
+ const executor = createMockExecutor({
130
+ twitter: { likes: 0, comments: 0, shares: 0, impressions: 0 },
131
+ });
132
+ tool.setToolExecutor(executor);
133
+
134
+ const result = await tool.execute({
135
+ platforms: ['twitter'],
136
+ postIds: { twitter: 'tw-1' },
137
+ timeRange: '90d',
138
+ });
139
+
140
+ expect(result.data!.timeRange).toBe('90d');
141
+ });
142
+ });
143
+
144
+ /* ── Field name normalization ─────────────────────────────────── */
145
+
146
+ describe('field name normalization', () => {
147
+ it('should normalize favouritesCount to likes', async () => {
148
+ const executor = createMockExecutor({
149
+ mastodon: { favouritesCount: 42, repliesCount: 5, reblogsCount: 12, impressions: 800 },
150
+ });
151
+ tool.setToolExecutor(executor);
152
+
153
+ const result = await tool.execute({
154
+ platforms: ['mastodon'],
155
+ postIds: { mastodon: 'masto-1' },
156
+ });
157
+
158
+ expect(result.data!.totals.likes).toBe(42);
159
+ expect(result.data!.totals.comments).toBe(5);
160
+ expect(result.data!.totals.shares).toBe(12);
161
+ });
162
+
163
+ it('should normalize retweets to shares (Twitter)', async () => {
164
+ const executor = createMockExecutor({
165
+ twitter: { likes: 100, comments: 10, retweets: 30, impressions: 2000 },
166
+ });
167
+ tool.setToolExecutor(executor);
168
+
169
+ const result = await tool.execute({
170
+ platforms: ['twitter'],
171
+ postIds: { twitter: 'tw-2' },
172
+ });
173
+
174
+ expect(result.data!.totals.shares).toBe(30);
175
+ });
176
+
177
+ it('should normalize reposts to shares (Bluesky)', async () => {
178
+ const executor = createMockExecutor({
179
+ bluesky: { likes: 50, comments: 3, reposts: 15, views: 1500 },
180
+ });
181
+ tool.setToolExecutor(executor);
182
+
183
+ const result = await tool.execute({
184
+ platforms: ['bluesky'],
185
+ postIds: { bluesky: 'bsky-1' },
186
+ });
187
+
188
+ expect(result.data!.totals.shares).toBe(15);
189
+ });
190
+
191
+ it('should normalize views to impressions', async () => {
192
+ const executor = createMockExecutor({
193
+ bluesky: { likes: 50, comments: 3, reposts: 15, views: 1500 },
194
+ });
195
+ tool.setToolExecutor(executor);
196
+
197
+ const result = await tool.execute({
198
+ platforms: ['bluesky'],
199
+ postIds: { bluesky: 'bsky-1' },
200
+ });
201
+
202
+ expect(result.data!.totals.impressions).toBe(1500);
203
+ });
204
+
205
+ it('should handle mixed normalized and standard field names across platforms', async () => {
206
+ const executor = createMockExecutor({
207
+ twitter: { likes: 100, comments: 10, retweets: 30, impressions: 2000 },
208
+ mastodon: { favouritesCount: 50, repliesCount: 5, reblogsCount: 20, impressions: 1000 },
209
+ });
210
+ tool.setToolExecutor(executor);
211
+
212
+ const result = await tool.execute({
213
+ platforms: ['twitter', 'mastodon'],
214
+ postIds: { twitter: 'tw-1', mastodon: 'masto-1' },
215
+ });
216
+
217
+ expect(result.data!.totals.likes).toBe(150);
218
+ expect(result.data!.totals.comments).toBe(15);
219
+ expect(result.data!.totals.shares).toBe(50);
220
+ expect(result.data!.totals.impressions).toBe(3000);
221
+ });
222
+ });
223
+
224
+ /* ── Engagement rate calculation ──────────────────────────────── */
225
+
226
+ describe('engagement rate', () => {
227
+ it('should calculate engagement rate as (likes+comments+shares)/impressions * 100', async () => {
228
+ const executor = createMockExecutor({
229
+ twitter: { likes: 100, comments: 20, shares: 30, impressions: 5000 },
230
+ });
231
+ tool.setToolExecutor(executor);
232
+
233
+ const result = await tool.execute({
234
+ platforms: ['twitter'],
235
+ postIds: { twitter: 'tw-1' },
236
+ });
237
+
238
+ // (100 + 20 + 30) / 5000 * 100 = 3.00
239
+ expect(result.data!.totals.engagement).toBe(3);
240
+ });
241
+
242
+ it('should return 0 engagement when impressions are 0', async () => {
243
+ const executor = createMockExecutor({
244
+ twitter: { likes: 5, comments: 1, shares: 0, impressions: 0 },
245
+ });
246
+ tool.setToolExecutor(executor);
247
+
248
+ const result = await tool.execute({
249
+ platforms: ['twitter'],
250
+ postIds: { twitter: 'tw-1' },
251
+ });
252
+
253
+ expect(result.data!.totals.engagement).toBe(0);
254
+ });
255
+
256
+ it('should calculate engagement across all platforms combined', async () => {
257
+ const executor = createMockExecutor({
258
+ twitter: { likes: 50, comments: 10, shares: 20, impressions: 2000 },
259
+ linkedin: { likes: 50, comments: 10, shares: 20, impressions: 3000 },
260
+ });
261
+ tool.setToolExecutor(executor);
262
+
263
+ const result = await tool.execute({
264
+ platforms: ['twitter', 'linkedin'],
265
+ postIds: { twitter: 'tw-1', linkedin: 'li-1' },
266
+ });
267
+
268
+ // (100 + 20 + 40) / 5000 * 100 = 3.20
269
+ expect(result.data!.totals.engagement).toBe(3.2);
270
+ });
271
+
272
+ it('should round engagement to 2 decimal places', async () => {
273
+ const executor = createMockExecutor({
274
+ twitter: { likes: 1, comments: 1, shares: 1, impressions: 7 },
275
+ });
276
+ tool.setToolExecutor(executor);
277
+
278
+ const result = await tool.execute({
279
+ platforms: ['twitter'],
280
+ postIds: { twitter: 'tw-1' },
281
+ });
282
+
283
+ // (3 / 7) * 100 = 42.857... -> 42.86
284
+ expect(result.data!.totals.engagement).toBe(42.86);
285
+ });
286
+ });
287
+
288
+ /* ── Missing post IDs ─────────────────────────────────────────── */
289
+
290
+ describe('missing post IDs', () => {
291
+ it('should report error for a platform without a post ID', async () => {
292
+ const executor = createMockExecutor({
293
+ twitter: { likes: 100, comments: 20, shares: 30, impressions: 5000 },
294
+ });
295
+ tool.setToolExecutor(executor);
296
+
297
+ const result = await tool.execute({
298
+ platforms: ['twitter', 'linkedin'],
299
+ postIds: { twitter: 'tw-1' }, // linkedin has no postId
300
+ });
301
+
302
+ expect(result.success).toBe(true);
303
+ const linkedinResult = result.data!.platforms['linkedin'] as { error: string };
304
+ expect(linkedinResult.error).toBe('No post ID provided for this platform');
305
+ });
306
+
307
+ it('should still aggregate metrics from platforms that have post IDs', async () => {
308
+ const executor = createMockExecutor({
309
+ twitter: { likes: 100, comments: 20, shares: 30, impressions: 5000 },
310
+ });
311
+ tool.setToolExecutor(executor);
312
+
313
+ const result = await tool.execute({
314
+ platforms: ['twitter', 'linkedin'],
315
+ postIds: { twitter: 'tw-1' },
316
+ });
317
+
318
+ expect(result.data!.totals.likes).toBe(100);
319
+ });
320
+ });
321
+
322
+ /* ── Executor errors ──────────────────────────────────────────── */
323
+
324
+ describe('executor errors', () => {
325
+ it('should handle executor returning success=false', async () => {
326
+ const executor = vi.fn(async () => ({
327
+ success: false,
328
+ error: 'API rate limited',
329
+ }));
330
+ tool.setToolExecutor(executor);
331
+
332
+ const result = await tool.execute({
333
+ platforms: ['twitter'],
334
+ postIds: { twitter: 'tw-1' },
335
+ });
336
+
337
+ expect(result.success).toBe(true); // tool-level always succeeds
338
+ const twitterResult = result.data!.platforms['twitter'] as { error: string };
339
+ expect(twitterResult.error).toBe('API rate limited');
340
+ });
341
+
342
+ it('should handle executor returning success=false with no error message', async () => {
343
+ const executor = vi.fn(async () => ({
344
+ success: false,
345
+ }));
346
+ tool.setToolExecutor(executor);
347
+
348
+ const result = await tool.execute({
349
+ platforms: ['twitter'],
350
+ postIds: { twitter: 'tw-1' },
351
+ });
352
+
353
+ const twitterResult = result.data!.platforms['twitter'] as { error: string };
354
+ expect(twitterResult.error).toBe('No data returned');
355
+ });
356
+
357
+ it('should handle thrown errors from executor gracefully', async () => {
358
+ const executor = vi.fn(async () => {
359
+ throw new Error('Connection refused');
360
+ });
361
+ tool.setToolExecutor(executor);
362
+
363
+ const result = await tool.execute({
364
+ platforms: ['twitter'],
365
+ postIds: { twitter: 'tw-1' },
366
+ });
367
+
368
+ expect(result.success).toBe(true);
369
+ const twitterResult = result.data!.platforms['twitter'] as { error: string };
370
+ expect(twitterResult.error).toBe('Connection refused');
371
+ });
372
+
373
+ it('should handle non-Error thrown values', async () => {
374
+ const executor = vi.fn(async () => {
375
+ throw 42; // eslint-disable-line no-throw-literal
376
+ });
377
+ tool.setToolExecutor(executor);
378
+
379
+ const result = await tool.execute({
380
+ platforms: ['twitter'],
381
+ postIds: { twitter: 'tw-1' },
382
+ });
383
+
384
+ const twitterResult = result.data!.platforms['twitter'] as { error: string };
385
+ expect(twitterResult.error).toBe('42');
386
+ });
387
+ });
388
+
389
+ /* ── No executor ──────────────────────────────────────────────── */
390
+
391
+ describe('missing tool executor', () => {
392
+ it('should report error when executor is not set and postId is present', async () => {
393
+ const result = await tool.execute({
394
+ platforms: ['twitter'],
395
+ postIds: { twitter: 'tw-1' },
396
+ });
397
+
398
+ const twitterResult = result.data!.platforms['twitter'] as { error: string };
399
+ expect(twitterResult.error).toBe('No tool executor available');
400
+ });
401
+ });
402
+
403
+ /* ── toNumber helper (via output) ─────────────────────────────── */
404
+
405
+ describe('toNumber coercion', () => {
406
+ it('should coerce string numbers in platform metrics', async () => {
407
+ const executor = createMockExecutor({
408
+ twitter: { likes: '50', comments: '10', shares: '20', impressions: '2000' },
409
+ });
410
+ tool.setToolExecutor(executor);
411
+
412
+ const result = await tool.execute({
413
+ platforms: ['twitter'],
414
+ postIds: { twitter: 'tw-1' },
415
+ });
416
+
417
+ expect(result.data!.totals.likes).toBe(50);
418
+ expect(result.data!.totals.comments).toBe(10);
419
+ expect(result.data!.totals.shares).toBe(20);
420
+ expect(result.data!.totals.impressions).toBe(2000);
421
+ });
422
+
423
+ it('should treat undefined/null metrics as 0', async () => {
424
+ const executor = createMockExecutor({
425
+ twitter: { likes: undefined, comments: null, impressions: 1000 },
426
+ });
427
+ tool.setToolExecutor(executor);
428
+
429
+ const result = await tool.execute({
430
+ platforms: ['twitter'],
431
+ postIds: { twitter: 'tw-1' },
432
+ });
433
+
434
+ expect(result.data!.totals.likes).toBe(0);
435
+ expect(result.data!.totals.comments).toBe(0);
436
+ expect(result.data!.totals.shares).toBe(0);
437
+ });
438
+
439
+ it('should treat NaN as 0', async () => {
440
+ const executor = createMockExecutor({
441
+ twitter: { likes: NaN, comments: 'not-a-number', shares: 5, impressions: 100 },
442
+ });
443
+ tool.setToolExecutor(executor);
444
+
445
+ const result = await tool.execute({
446
+ platforms: ['twitter'],
447
+ postIds: { twitter: 'tw-1' },
448
+ });
449
+
450
+ expect(result.data!.totals.likes).toBe(0);
451
+ expect(result.data!.totals.comments).toBe(0);
452
+ expect(result.data!.totals.shares).toBe(5);
453
+ });
454
+ });
455
+ });
package/tsconfig.json ADDED
@@ -0,0 +1,22 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "lib": ["ES2022"],
6
+ "outDir": "./dist",
7
+ "rootDir": "./src",
8
+ "strict": true,
9
+ "esModuleInterop": true,
10
+ "skipLibCheck": true,
11
+ "noEmitOnError": false,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "declaration": true,
14
+ "declarationMap": true,
15
+ "sourceMap": true,
16
+ "resolveJsonModule": true,
17
+ "moduleResolution": "Bundler",
18
+ "types": ["node"]
19
+ },
20
+ "include": ["src/**/*"],
21
+ "exclude": ["node_modules", "dist", "test"]
22
+ }