UNPKG

@defikitdotnet/x-ai-combat

Version:

XCombatAI - Social Media Engagement Template for the Agent Framework

154 lines 5.29 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var PostResource_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.PostResource = void 0; const agent_framework_core_1 = require("@defikitdotnet/agent-framework-core"); /** * Post resource model for storing Twitter posts */ let PostResource = PostResource_1 = class PostResource { constructor() { this.stats = { likes: 0, retweets: 0, quotes: 0, replies: 0, total: 0, famePoints: 0 }; } /** * Convert from Tweet to PostResource */ static fromTweet(tweet) { const post = new PostResource_1(); // Use type assertion with any to handle different tweet formats const tweetData = tweet; post.id = tweetData.id || `tweet-${Date.now()}`; // Fallback if ID is missing post.tweetId = tweetData.id || `tweet-${Date.now()}`; post.twitterUserId = tweetData.userId || 'unknown-user'; // Store Twitter user ID // userId will be set separately if user is linked post.content = tweetData.text || tweetData.content || ''; // Handle different API formats post.raw = JSON.stringify(tweet); // Handle missing or invalid dates gracefully try { // Check for all possible date properties using type assertion const tweetDate = tweetData.createdAt || tweetData.created_at || tweetData.timestamp; if (tweetDate) { const createdDate = new Date(tweetDate); // Check if date is valid if (!isNaN(createdDate.getTime())) { post.createdAt = createdDate; } else { post.createdAt = new Date(); // Fallback to current time } } else { post.createdAt = new Date(); // Fallback to current time } } catch (e) { console.warn('Invalid date in tweet, using current time instead:', e); post.createdAt = new Date(); } return post; } /** * Convert to Tweet */ toTweet() { return JSON.parse(this.raw); } }; exports.PostResource = PostResource; __decorate([ (0, agent_framework_core_1.Field)({ type: "string", primary: true, }), __metadata("design:type", String) ], PostResource.prototype, "id", void 0); __decorate([ (0, agent_framework_core_1.Field)({ type: "string", required: true, }), __metadata("design:type", String) ], PostResource.prototype, "tweetId", void 0); __decorate([ (0, agent_framework_core_1.Field)({ type: "string", required: true, }), __metadata("design:type", String) ], PostResource.prototype, "twitterUserId", void 0); __decorate([ (0, agent_framework_core_1.Field)({ type: "string", required: false, }), __metadata("design:type", String) ], PostResource.prototype, "userId", void 0); __decorate([ (0, agent_framework_core_1.Field)({ type: "string", required: true, }), __metadata("design:type", String) ], PostResource.prototype, "content", void 0); __decorate([ (0, agent_framework_core_1.Field)({ type: "string", required: true, }), __metadata("design:type", String) ], PostResource.prototype, "raw", void 0); __decorate([ (0, agent_framework_core_1.Field)({ type: "date", required: true, }), __metadata("design:type", Date) ], PostResource.prototype, "createdAt", void 0); __decorate([ (0, agent_framework_core_1.Field)({ type: "date", }), __metadata("design:type", Date) ], PostResource.prototype, "updatedAt", void 0); __decorate([ (0, agent_framework_core_1.Field)({ type: "object", required: true, }), __metadata("design:type", Object) ], PostResource.prototype, "stats", void 0); __decorate([ (0, agent_framework_core_1.Field)({ type: "date", }), __metadata("design:type", Date) ], PostResource.prototype, "lastInteractionAt", void 0); __decorate([ (0, agent_framework_core_1.Field)({ type: "string", }), __metadata("design:type", String) ], PostResource.prototype, "agentId", void 0); exports.PostResource = PostResource = PostResource_1 = __decorate([ (0, agent_framework_core_1.ResourceDecorator)({ name: "posts", tableName: "posts", }) ], PostResource); //# sourceMappingURL=Post.js.map