Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Primus zkTLS plugin to fully verify agent activities #2086

Merged
merged 28 commits into from
Jan 11, 2025
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
3b16a4c
add primus plugin
WuEcho Jan 6, 2025
b6eae8d
update primus zktls core sdk invoke
fksyuan Jan 6, 2025
de6b982
fix model name bug and update primus attestation decode
fksyuan Jan 6, 2025
1a098b4
Proof provider and action for twitter-plugin
xudean Jan 7, 2025
b750bfb
update readme log
fksyuan Jan 7, 2025
d8df612
update README in plugin-twitter-primus
xudean Jan 7, 2025
e00f5ea
Merge remote-tracking branch 'origin/develop' into develop
xudean Jan 7, 2025
adb2374
Merge remote-tracking branch 'upstream/develop' into develop
xudean Jan 8, 2025
e2e9063
update npm package 'zktls-core-sdk'
xudean Jan 8, 2025
0563ed5
update README in plugin-primus and plugin-twitter-plugin
xudean Jan 8, 2025
e33cead
get tweet by UserScreenName
xudean Jan 9, 2025
02ef838
refactor plugin-primus
xudean Jan 9, 2025
8266043
refine readme in plugin-primus
xiangxiecrypto Jan 9, 2025
d05c974
fix format
xiangxiecrypto Jan 9, 2025
d8d3ce7
update readme in plugin-primus
xudean Jan 9, 2025
adfd2be
Merge remote-tracking branch 'origin/develop' into develop
xudean Jan 9, 2025
d389b22
Merge remote-tracking branch 'upstream/develop' into develop
xudean Jan 9, 2025
8122abc
fix readme format
xudean Jan 9, 2025
c8500cd
fix code error
xudean Jan 9, 2025
4f08094
update readme in plugin-primus
xudean Jan 9, 2025
14fe671
update import
xudean Jan 9, 2025
ff931a9
update import
xudean Jan 9, 2025
730b929
refine readme
xiangxiecrypto Jan 9, 2025
b6818ec
chore: refine readme
xiangxiecrypto Jan 10, 2025
d55da5f
Merge branch 'develop' into develop
xudean Jan 10, 2025
3a3a9f2
Merge remote-tracking branch 'upstream/develop' into develop
xudean Jan 11, 2025
9bf45e0
Merge remote-tracking branch 'upstream/develop' into develop
xudean Jan 11, 2025
d90f838
resolve conversions problems
xudean Jan 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
273 changes: 20 additions & 253 deletions packages/plugin-twitter-primus/README.md
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
# @elizaos/plugin-twitter-primus

A plugin for Twitter/X integration, providing automated tweet posting capabilities with character-aware content generation.

A plugin for Twitter/X integration that ensures the verifiability of information throughout the process, including the source of information, summary, usage, and more, across the stages of 'model -> provider -> action'.
## Overview

This plugin provides functionality to:
This plugin offers the following functionalities:

- Compose context-aware tweets
- Post tweets to Twitter/X platform
- Handle authentication and session management
- Support premium Twitter features
- Manage tweet length restrictions
- Verifying that the information originated from Twitter/X
- Confirming that the information summary was generated by a large model
- Ensuring that the summary message was successfully sent to Twitter/X

## Installation

> Before using the plugins, make sure to install [plugin-primus](../plugin-primus) and complete the configuration.
```bash
npm install @elizaos/plugin-twitter-primus
pnpm add @elizaos/plugin-twitter-primus
```

## Configuration

The plugin requires the following environment variables:

- .env file

```env
TWITTER_USERNAME=your_username
TWITTER_PASSWORD=your_password
@@ -34,249 +35,15 @@ TWITTER_USER_ID_WANT_TO_GET_TWEET=123456677 # Must: Which user the tweet came fr
```

## Usage

Import and register the plugin in your Eliza configuration:

```typescript
import { twitterPlugin } from "@elizaos/plugin-twitter-primus";

export default {
plugins: [twitterPlugin],
// ... other configuration
};
```

## Features

### Tweet Getting

The plugin uses context-aware templates to generate appropriate tweets:

```typescript
import { postAction } from "@elizaos/plugin-twitter-primus";

// Tweet will be composed based on context and character limits
const result = await postAction.handler(runtime, message, state);
```

### Tweet Summary


### Tweet Posting

```typescript
// Post with automatic content generation
await postAction.handler(runtime, message, state);

// Dry run mode (for testing)
process.env.TWITTER_DRY_RUN = "true";
await postAction.handler(runtime, message, state);
```

## Development

### Building

```bash
npm run build
```

### Testing

```bash
npm run test
```

### Development Mode

```bash
npm run dev
```

## Dependencies

- `@elizaos/core`: Core Eliza functionality
- `agent-twitter-client`: Twitter API client
- `@primuslabs/zktls-core-sdk`: ZK-TLS SDK provided by Primus Labs
- `tsup`: Build tool
- Other standard dependencies listed in package.json

## API Reference

### Core Interfaces

```typescript
interface TweetContent {
text: string;
To use the plugin, add `@elizaos/plugin-twitter-primus` to the plugins field in your character file. Here's an example of how your character file might look after the update:

```json
{
"name": "trump",
"plugins": [
"@elizaos/plugin-twitter-primus"
],
//other fields
.....
}

// Tweet Schema
const TweetSchema = z.object({
text: z.string().describe("The text of the tweet"),
});

// Action Interface
interface Action {
name: "POST_TWEET";
similes: string[];
description: string;
validate: (
runtime: IAgentRuntime,
message: Memory,
state?: State
) => Promise<boolean>;
handler: (
runtime: IAgentRuntime,
message: Memory,
state?: State
) => Promise<boolean>;
examples: Array<Array<any>>;
}
```

### Plugin Methods

- `postAction.handler`: Main method for posting tweets
- `postAction.validate`: Validates Twitter credentials
- `composeTweet`: Internal method for tweet generation
- `postTweet`: Internal method for tweet posting

## Common Issues/Troubleshooting

### Issue: Authentication Failures

- **Cause**: Invalid credentials or 2FA configuration
- **Solution**: Verify credentials and 2FA setup

### Issue: Tweet Length Errors

- **Cause**: Content exceeds Twitter's character limit
- **Solution**: Enable TWITTER_PREMIUM for extended tweets or ensure content is within limits

### Issue: Rate Limiting

- **Cause**: Too many requests in short time
- **Solution**: Implement proper request throttling

## Security Best Practices

- Store credentials securely using environment variables
- Use 2FA when possible
- Implement proper error handling
- Keep dependencies updated
- Use dry run mode for testing
- Monitor Twitter API usage

## Template System

The plug-in uses a complex template system to generate a summary of tweets:

```typescript
export const summarizeTweetTemplate = `
# Context
{{twitterContent}}
# Topics
{{topics}}
# Post Directions
{{postDirections}}
# Recent interactions between {{agentName}} and other users:
{{recentPostInteractions}}
# Task
Generate a tweet that:
1. Summarize the input
2. The content does not contain emoji
3. Must be less than 200 characters (this is a strict requirement)
4. The key information should be retained
5. Is concise and engaging
Generate only the tweet text, no other commentary.`;
```

## Future Enhancements

1. **Content Generation**

- Advanced context awareness
- Multi-language support
- Style customization
- Hashtag optimization
- Media generation
- Thread composition

2. **Engagement Features**

- Auto-reply system
- Engagement analytics
- Follower management
- Interaction scheduling
- Sentiment analysis
- Community management

3. **Tweet Management**

- Thread management
- Tweet scheduling
- Content moderation
- Archive management
- Delete automation
- Edit optimization

4. **Analytics Integration**

- Performance tracking
- Engagement metrics
- Audience insights
- Trend analysis
- ROI measurement
- Custom reporting

5. **Authentication**

- OAuth improvements
- Multi-account support
- Session management
- Rate limit handling
- Security enhancements
- Backup mechanisms

6. **Developer Tools**
- Enhanced debugging
- Testing framework
- Documentation generator
- Integration templates
- Error handling
- Logging system

We welcome community feedback and contributions to help prioritize these enhancements.

## Contributing

Contributions are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) file for more information.

## Credits

This plugin integrates with and builds upon several key technologies:

- [Twitter/X API](https://developer.twitter.com/en/docs): Official Twitter platform API
- [agent-twitter-client](https://www.npmjs.com/package/agent-twitter-client): Twitter API client library
- [Zod](https://github.com/colinhacks/zod): TypeScript-first schema validation

Special thanks to:

- The Twitter/X Developer Platform team
- The agent-twitter-client maintainers for API integration tools
- The Eliza community for their contributions and feedback

For more information about Twitter/X integration capabilities:

- [Twitter API Documentation](https://developer.twitter.com/en/docs)
- [Twitter Developer Portal](https://developer.twitter.com/en/portal/dashboard)
- [Twitter API Best Practices](https://developer.twitter.com/en/docs/twitter-api/rate-limits)

## License

This plugin is part of the Eliza project. See the main project repository for license information.