-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into direct-client_agent-crud
- Loading branch information
Showing
27 changed files
with
821 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
136 changes: 136 additions & 0 deletions
136
packages/_examples/plugin/src/services/sampleService.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import { | ||
Service, | ||
ServiceType, | ||
IAgentRuntime, | ||
// Memory, | ||
// State, | ||
elizaLogger, | ||
// stringToUuid, | ||
} from "@elizaos/core"; | ||
// import { sampleProvider } from "../providers/sampleProvider"; // TODO: Uncomment this line to use the sampleProvider | ||
|
||
// Add SAMPLE to ServiceType enum in types.ts | ||
declare module "@elizaos/core" { | ||
export enum ServiceType { | ||
SAMPLE = "sample", | ||
} | ||
} | ||
|
||
// The SampleService is a simple service that logs "Hello world" every 15 minutes. | ||
export class SampleService extends Service { | ||
private runtime: IAgentRuntime | null = null; | ||
private intervalId: NodeJS.Timeout | null = null; | ||
private readonly DEFAULT_INTERVAL = 15 * 60 * 1000; // 15 minutes in milliseconds | ||
|
||
static get serviceType(): ServiceType { | ||
return ServiceType.SAMPLE; | ||
} | ||
|
||
private static isInitialized = false; | ||
|
||
async initialize(runtime: IAgentRuntime): Promise<void> { | ||
// Verify if the service is already initialized | ||
if (SampleService.isInitialized) { | ||
return; | ||
} | ||
|
||
this.runtime = runtime; | ||
|
||
// Start the periodic task | ||
this.startPeriodicTask(); | ||
SampleService.isInitialized = true; | ||
elizaLogger.info("SampleService initialized and started periodic task"); | ||
} | ||
|
||
private static activeTaskCount = 0; | ||
|
||
private startPeriodicTask(): void { | ||
// Verify if a task is already active | ||
if (SampleService.activeTaskCount > 0) { | ||
elizaLogger.warn( | ||
"SampleService: Periodic task already running, skipping" | ||
); | ||
return; | ||
} | ||
|
||
// Clear any existing interval | ||
if (this.intervalId) { | ||
clearInterval(this.intervalId); | ||
} | ||
|
||
SampleService.activeTaskCount++; | ||
elizaLogger.info( | ||
`SampleService: Starting periodic task (active tasks: ${SampleService.activeTaskCount})` | ||
); | ||
|
||
// Initial call immediately | ||
this.fetchSample(); | ||
|
||
// Set up periodic calls | ||
this.intervalId = setInterval(() => { | ||
this.fetchSample(); | ||
}, this.DEFAULT_INTERVAL); | ||
} | ||
|
||
private async fetchSample(): Promise<void> { | ||
if (!this.runtime) { | ||
elizaLogger.error("SampleService: Runtime not initialized"); | ||
return; | ||
} | ||
|
||
try { | ||
// Example of using the sampleProvider | ||
// Create dummy memory and state objects for the provider | ||
// const dummyMemory: Memory = { | ||
// id: stringToUuid("sample-service-trigger"), | ||
// userId: this.runtime.agentId, | ||
// agentId: this.runtime.agentId, | ||
// roomId: this.runtime.agentId, | ||
// content: { text: "Periodic sample fetch" }, | ||
// createdAt: Date.now(), | ||
// }; | ||
|
||
// const dummyState: State = { | ||
// userId: this.runtime.agentId, | ||
// bio: "", | ||
// lore: "", | ||
// messageDirections: "", | ||
// postDirections: "", | ||
// roomId: this.runtime.agentId, | ||
// actors: "", | ||
// recentMessages: "", | ||
// recentMessagesData: [], | ||
// }; | ||
// await sampleProvider.get(this.runtime, dummyMemory, dummyState); | ||
|
||
// hello world log example | ||
elizaLogger.info("SampleService: Hello world"); | ||
|
||
elizaLogger.info( | ||
"SampleService: Successfully fetched and processed sample" | ||
); | ||
} catch (error) { | ||
elizaLogger.error("SampleService: Error fetching sample:", error); | ||
} | ||
} | ||
|
||
// Method to stop the service | ||
stop(): void { | ||
if (this.intervalId) { | ||
clearInterval(this.intervalId); | ||
this.intervalId = null; | ||
SampleService.activeTaskCount--; | ||
elizaLogger.info( | ||
`SampleService stopped (active tasks: ${SampleService.activeTaskCount})` | ||
); | ||
} | ||
SampleService.isInitialized = false; | ||
} | ||
|
||
// Method to manually trigger a sample fetch (for testing) | ||
async forceFetch(): Promise<void> { | ||
await this.fetchSample(); | ||
} | ||
} | ||
|
||
export default SampleService; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# `@elizaos/plugin-passport` | ||
|
||
This plugin provides actions for interacting with Gitcoin passport | ||
https://docs.passport.xyz/building-with-passport/passport-api/overview | ||
|
||
--- | ||
|
||
## Installation | ||
|
||
Just add it under your character profile in plugins as | ||
|
||
``` | ||
"plugins": [ | ||
"@elizaos/plugin-gitcoin-passport" | ||
], | ||
``` | ||
|
||
## Configuration | ||
|
||
Getting Your API Key | ||
|
||
1. Log in to the developer portal: Go to developer.passport.xyz and log in to your account by connecting your wallet. | ||
2. Navigate to the API Keys section: After logging in, go to the "API Keys" section. | ||
3. Generate an API key: Click on the "+ Create a Key" button to generate a unique API key for your account. | ||
4. Store your API key securely: Store your API key in a secure place, as it will be used to access the Passport API. | ||
|
||
Getting your Scorer ID | ||
|
||
1. Log in to the Developer Portal: Go to developer.passport.xyz and log in to your account by connecting your wallet. | ||
2. Navigate to the Scorer section: After logging in, go to the "Scorer" section | ||
3. Create a Scorer: Click on the "+ Create a Scorer" button and input a Scorer name and description. Make sure you use the Unique Humanity scorer, and not the Binary scorer. | ||
4. Find your Scorer ID: Click on the newly created Scorer and you will see the Scorer ID in the page URL. | ||
Example: https://developer.passport.xyz/dashboard/scorer/{scorer_id} | ||
|
||
## Usage | ||
|
||
Results are saved as message and agents can retrive it from there for different use cases. | ||
Default passport treshold of 20 is used, but you can pick your own value and match it agains that |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import eslintGlobalConfig from "../../eslint.config.mjs"; | ||
|
||
export default [...eslintGlobalConfig]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"name": "@elizaos/plugin-gitcoin-passport", | ||
"version": "0.1.7-alpha.2", | ||
"main": "dist/index.js", | ||
"type": "module", | ||
"types": "dist/index.d.ts", | ||
"dependencies": { | ||
"@elizaos/core": "workspace:*", | ||
"tsup": "8.3.5" | ||
}, | ||
"scripts": { | ||
"build": "tsup --format esm --dts", | ||
"dev": "tsup --format esm --dts --watch", | ||
"test": "vitest run", | ||
"lint": "eslint --fix --cache ." | ||
}, | ||
"peerDependencies": { | ||
"whatwg-url": "7.1.0" | ||
} | ||
} |
Oops, something went wrong.