Skip to content

Commit

Permalink
feat:add tsup.config.ts file
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaito committed Jan 5, 2025
1 parent 154a85a commit b89d46a
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 14 deletions.
44 changes: 31 additions & 13 deletions packages/plugin-twitter-search/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,34 +1,52 @@
import { Plugin, IAgentRuntime, elizaLogger } from "@elizaos/core";
import { Plugin, IAgentRuntime, elizaLogger, Service, ServiceType } from "@elizaos/core";
import { TwitterApiClient } from "./client";
import { validateTwitterApiConfig } from "./environment";

export * from "./types";
export { TwitterApiClient } from "./client";
export { validateTwitterApiConfig } from "./environment";

export const TwitterApiPlugin: Plugin = {
class TwitterApiService extends Service {
static serviceType = "TWITTER_SEARCH_API" as ServiceType;
public client!: TwitterApiClient;

async initialize(runtime: IAgentRuntime) {
const config = await validateTwitterApiConfig(runtime);
this.client = new TwitterApiClient(config);
elizaLogger.info("Twitter API Service: Initialized successfully");
}

async cleanup() {
// 清理资源的逻辑
elizaLogger.info("Twitter API Service: Cleaning up...");
}

getClient() {
return this.client;
}
}

export const TwitterApiPlugin = {
name: "twitter-api",

description: "Twitter API integration using twitterapi.io service",

async init(runtime: IAgentRuntime) {
try {
const config = await validateTwitterApiConfig(runtime);
const apiClient = new TwitterApiClient(config);

// Register the client to be available for other components
runtime.registerService("twitterApi", apiClient);

elizaLogger.info("Twitter API Plugin: Initialized successfully");

// 使用标准的 Service 类注册方式
const twitterService = new TwitterApiService();
await twitterService.initialize(runtime);
runtime.registerService(twitterService);

return {
async cleanup() {
elizaLogger.info("Twitter API Plugin: Cleaning up...");
await twitterService.cleanup();
}
};
} catch (error) {
elizaLogger.error("Twitter API Plugin: Initialization failed", error);
throw error;
}
}
}
} as Plugin;

export default TwitterApiPlugin;
5 changes: 4 additions & 1 deletion packages/plugin-twitter-search/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
"ES2021",
"DOM"
],
"types": ["jest", "@jest/globals"],
"types": [
"jest",
"@types/jest"
],
"declaration": true,
"outDir": "./dist",
"strict": true,
Expand Down
9 changes: 9 additions & 0 deletions packages/plugin-twitter-search/tsup.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { defineConfig } from 'tsup';

export default defineConfig({
entry: ['src/index.ts'],
format: ['cjs', 'esm'],
dts: true,
clean: true,
sourcemap: true
});

0 comments on commit b89d46a

Please sign in to comment.