├── .cursor
└── rules
│ ├── code-practices.mdc
│ ├── flow.mdc
│ └── test-practices.mdc
├── .github
└── workflows
│ ├── myget-publish.yml
│ └── test-with-code-coverage.yml
├── .gitignore
├── CodeCoverage.runsettings
├── Directory.Build.props
├── Directory.Packages.props
├── LICENSE
├── README.md
├── aevatar-framework.sln
├── ai
└── project_tracker.md
├── codecov.yml
├── common.props
├── docs
├── Aevatar.Core.md
├── Aevatar.EventSourcing.Core.md
├── Aevatar.PermissionManagement.md
├── Aevatar.Plugins.md
├── DIRECTORY_STRUCTURE.md
└── MODULE_DOCUMENTATION.md
├── samples
├── ArtifactGAgent
│ ├── ArtifactGAgent.Client
│ │ ├── ArtifactGAgent.Client.csproj
│ │ └── Program.cs
│ └── ArtifactGAgent.Silo
│ │ ├── ArtifactGAgent.Silo.csproj
│ │ ├── Program.cs
│ │ └── appsettings.json
├── BroadCastGAgentDemo
│ ├── BroadCastGAgentDemo.csproj
│ └── Program.cs
├── MessagingGAgent.Client
│ ├── MessagingGAgent.Client.csproj
│ └── Program.cs
├── MessagingGAgent.Grains
│ ├── Agents
│ │ ├── Events
│ │ │ ├── MessagingEvent.cs
│ │ │ └── SendEvent.cs
│ │ ├── Group
│ │ │ ├── GroupAgentState.cs
│ │ │ ├── GroupGAgent.cs
│ │ │ └── GroupStateLogEvent.cs
│ │ └── Messaging
│ │ │ ├── DemoGAgent.cs
│ │ │ ├── MessagingGAgent.cs
│ │ │ ├── MessagingGState.cs
│ │ │ ├── MessagingStateLogEvent.cs
│ │ │ └── SpecializedGrain.cs
│ └── MessagingGAgent.Grains.csproj
├── MessagingGAgent.Silo
│ ├── MessagingGAgent.Silo.csproj
│ └── Program.cs
├── PluginGAgent
│ ├── PluginGAgent.Client
│ │ ├── PluginGAgent.Client.csproj
│ │ ├── Program.cs
│ │ ├── appsettings.json
│ │ └── plugins
│ │ │ ├── Aevatar.dll
│ │ │ ├── PluginGAgent.Grains.dll
│ │ │ ├── PluginGAgent.GrainsDup.dll
│ │ │ └── RestSharp.dll
│ ├── PluginGAgent.Grains
│ │ ├── CommanderGAgent.cs
│ │ ├── PluginGAgent.Grains.csproj
│ │ └── WorkerGAgent.cs
│ ├── PluginGAgent.GrainsDup
│ │ ├── CommanderGAgent.cs
│ │ ├── PluginGAgent.GrainsDup.csproj
│ │ └── WorkerGAgent.cs
│ └── PluginGAgent.Silo
│ │ ├── Extensions
│ │ └── OrleansHostExtension.cs
│ │ ├── PluginGAgent.Silo.csproj
│ │ ├── PluginGAgentTestHostedService.cs
│ │ ├── PluginGAgentTestModule.cs
│ │ ├── Program.cs
│ │ └── appsettings.json
├── PubSubDemoWithoutGroup
│ ├── Program.cs
│ └── PubSubDemoWithoutGroup.csproj
└── SiloNamePatternPlacementExamples
│ ├── Program.cs
│ └── SiloNamePatternPlacementExamples.csproj
├── src
├── Aevatar.Core.Abstractions
│ ├── Aevatar.Core.Abstractions.csproj
│ ├── AevatarCoreConstants.cs
│ ├── AevatarOptions.cs
│ ├── Application
│ │ ├── BroadCastGState.cs
│ │ ├── RequestAllDescriptionsEvent.cs
│ │ └── SubscribedEventListEvent.cs
│ ├── ConfigurationBase.cs
│ ├── EventHandlerExceptionEvent.cs
│ ├── Events
│ │ ├── EventBase.cs
│ │ ├── EventWithResponseBase.cs
│ │ ├── EventWrapper.cs
│ │ └── EventWrapperBase.cs
│ ├── Exceptions
│ │ ├── ArtifactGAgentException.cs
│ │ ├── EventHandlingException.cs
│ │ ├── EventPublishingException.cs
│ │ └── StateTransitionException.cs
│ ├── Extensions
│ │ ├── AssemblyExtensions.cs
│ │ └── StringExtensions.cs
│ ├── IArtifact.cs
│ ├── IArtifactGAgent.cs
│ ├── IEventDispatcher.cs
│ ├── IExtGAgent.cs
│ ├── IGAgentFactory.cs
│ ├── IGAgentManager.cs
│ ├── IPublishingGAgent.cs
│ ├── IStateAgent.cs
│ ├── IStateDispatcher.cs
│ ├── IStateProjector.cs
│ ├── Infrastructure
│ │ ├── AllEventHandlerAttribute.cs
│ │ ├── EventHandlerAttribute.cs
│ │ ├── GAgentAttribute.cs
│ │ ├── StateHandlerAttribute.cs
│ │ └── StateLogEventHandlerAttribute.cs
│ ├── Plugin
│ │ ├── AddExistedPluginDto.cs
│ │ ├── AddPluginDto.cs
│ │ ├── IPluginGAgentManager.cs
│ │ ├── PluginLoadStatus.cs
│ │ ├── PluginsInformation.cs
│ │ ├── RemovePluginDto.cs
│ │ └── UpdatePluginDto.cs
│ ├── Projections
│ │ └── IProjectionGrain.cs
│ ├── StateBase.cs
│ ├── StateLogEventBase.cs
│ ├── StateWrapper.cs
│ ├── StateWrapperBase.cs
│ └── SyncWorker
│ │ └── IAevatarSyncWorker.cs
├── Aevatar.Core
│ ├── Aevatar.Core.csproj
│ ├── AevatarGAgentConstants.cs
│ ├── AevatarGrainActivator.cs
│ ├── AevatarSyncWorker.cs
│ ├── ArtifactGAgent.cs
│ ├── AsyncTaskRunner.cs
│ ├── BroadCastGAgentBase.cs
│ ├── EventWrapperBaseAsyncObserver.cs
│ ├── EventWrapperHelper.cs
│ ├── Extensions
│ │ ├── MethodInfoExtensions.cs
│ │ └── ReflectionExtensions.cs
│ ├── GAgentAsyncObserver.cs
│ ├── GAgentBase.Observers.cs
│ ├── GAgentBase.Publish.cs
│ ├── GAgentBase.Subscribe.cs
│ ├── GAgentBase.SyncWorker.cs
│ ├── GAgentBase.cs
│ ├── GAgentBaseExceptionEvent.cs
│ ├── GAgentFactory.cs
│ ├── GAgentManager.cs
│ ├── Observability
│ │ ├── ActivityHelper.cs
│ │ ├── OpenTelemetryConstants.cs
│ │ └── OpenTelemetryScope.cs
│ ├── Placement
│ │ └── SiloNamePatternPlacement.cs
│ ├── Projections
│ │ └── StateProjectionGrain.cs
│ ├── PublishingGAgent.cs
│ ├── StateBaseAsyncObserver.cs
│ ├── StateDispatcher.cs
│ ├── StateProjectionAsyncObserver.cs
│ └── StateProjectionGAgentBase.cs
├── Aevatar.EventSourcing.Core
│ ├── Aevatar.EventSourcing.Core.csproj
│ ├── AevatarEventSourcingConstants.cs
│ ├── Exceptions
│ │ ├── ReadFromLogStorageFailed.cs
│ │ ├── ReadFromSnapshotStorageFailed.cs
│ │ ├── UpdateLogStorageFailed.cs
│ │ └── UpdateSnapshotStorageFailed.cs
│ ├── Hosting
│ │ ├── InMemoryStorageServiceCollectionExtensions.cs
│ │ └── InMemoryStorageSiloBuilderExtensions.cs
│ ├── InMemoryLogConsistentStorage.cs
│ ├── InMemoryLogConsistentStorageFactory.cs
│ ├── LogConsistency
│ │ └── DefaultProtocolServices.cs
│ ├── Snapshot
│ │ ├── ViewStateSnapshot.cs
│ │ └── ViewStateSnapshotWithMetadata.cs
│ └── Storage
│ │ ├── ILogConsistentStorage.cs
│ │ ├── LogConsistencyProvider.cs
│ │ ├── LogConsistencyProviderFactory.cs
│ │ ├── LogViewAdaptor.EventSourcing.cs
│ │ └── LogViewAdaptor.Notifications.cs
├── Aevatar.EventSourcing.MongoDB
│ ├── Aevatar.EventSourcing.MongoDB.csproj
│ ├── Configuration
│ │ └── MongoDBGrainStorageConfigurator.cs
│ ├── GrainTypeBsonSerializer.cs
│ ├── Hosting
│ │ ├── MongoDbStorageServiceCollectionExtensions.cs
│ │ └── MongoDbStorageSiloBuilderExtensions.cs
│ ├── IdSpanBsonSerializer.cs
│ ├── MongoDbLogConsistentStorage.cs
│ ├── MongoDbLogConsistentStorageFactory.cs
│ ├── MongoDbStorageException.cs
│ ├── Options
│ │ ├── MongoDbStorageOptions.cs
│ │ └── MongoDbStorageOptionsValidator.cs
│ └── Serializers
│ │ └── BsonGrainSerializer.cs
├── Aevatar.PermissionManagement
│ ├── Aevatar.PermissionManagement.csproj
│ ├── AevatarPermissionManagementModule.cs
│ ├── Extensions
│ │ └── OrleansHostExtensions.cs
│ ├── GAgentPermissionHelper.cs
│ ├── IPermissionInfoProvider.cs
│ ├── PermissionAttribute.cs
│ ├── PermissionCheckFilter.cs
│ ├── PermissionGAgentBase.cs
│ ├── PermissionInfo.cs
│ ├── PermissionStateBase.cs
│ └── UserContext.cs
├── Aevatar.Plugins
│ ├── Aevatar.Plugins.csproj
│ ├── AevatarPluginsModule.cs
│ ├── DbContexts
│ │ ├── AevatarMongoDbContextBase.cs
│ │ ├── PluginCodeStorageMongoDbContext.cs
│ │ ├── PluginLoadStatusMongoDbContext.cs
│ │ └── TenantPluginCodeMongoDbContext.cs
│ ├── Entities
│ │ ├── PluginCodeStorage.cs
│ │ ├── PluginLoadStatus.cs
│ │ └── TenantPluginCode.cs
│ ├── Extensions
│ │ └── AbpApplicationExtensions.cs
│ ├── GAgents
│ │ ├── PluginCodeStorageGAgent.cs
│ │ └── TenantPluginCodeGAgent.cs
│ ├── PluginGAgentLoadOptions.cs
│ ├── PluginGAgentManager.cs
│ ├── PluginLoader.cs
│ └── Repositories
│ │ ├── IPluginCodeStorageRepository.cs
│ │ ├── IPluginLoadStatusRepository.cs
│ │ ├── ITenantPluginCodeRepository.cs
│ │ ├── PluginCodeStorageRepository.cs
│ │ ├── PluginLoadStatusRepository.cs
│ │ └── TenantPluginCodeRepository.cs
├── Aevatar.TestKit
│ ├── Aevatar.TestKit.csproj
│ ├── DefaultTestKitBase.cs
│ ├── EventSourcing
│ │ ├── TestCloner.cs
│ │ ├── TestCodec.cs
│ │ ├── TestCodecProvider.cs
│ │ ├── TestLogConsistencyProtocolServices.cs
│ │ ├── TestLogConsistencyProvider.cs
│ │ └── TestLogViewAdaptor.cs
│ ├── Extensions
│ │ ├── GrainProbeExtensions.cs
│ │ ├── TestKitSiloExtensions.GrainContext.cs
│ │ └── TestKitSiloExtensions.GrainCreation.cs
│ ├── GlobalUsing.cs
│ ├── README.md
│ ├── Reminders
│ │ ├── ReminderContextHandler.cs
│ │ ├── ReminderContextHolder.cs
│ │ ├── ReminderExtensions.cs
│ │ ├── TestReminder.cs
│ │ └── TestReminderRegistry.cs
│ ├── Services
│ │ ├── TestServiceProvider.cs
│ │ └── TestServicesExtensions.cs
│ ├── Storage
│ │ ├── IStorageStats.cs
│ │ ├── StorageExtensions.cs
│ │ ├── StorageManager.cs
│ │ ├── TestPersistentStateAttributeToFactoryMapper.cs
│ │ ├── TestStorage.cs
│ │ └── TestStorageStats.cs
│ ├── Streams
│ │ ├── StreamExtensions.cs
│ │ ├── TestStream.cs
│ │ ├── TestStreamProvider.cs
│ │ ├── TestStreamProviderManager.cs
│ │ └── TestStreamSubscriptionHandle.cs
│ ├── TestGrainActivationContext.cs
│ ├── TestGrainContextAccessor.cs
│ ├── TestGrainCreator.cs
│ ├── TestGrainFactory.cs
│ ├── TestGrainLifecycle.cs
│ ├── TestGrainRuntime.cs
│ ├── TestGrainStorage.cs
│ ├── TestKitBase.cs
│ ├── TestKitOptions.cs
│ ├── TestKitSilo.cs
│ ├── Timers
│ │ ├── TestTimer.cs
│ │ ├── TestTimerRegistry.cs
│ │ └── TimerExtensions.cs
│ ├── TypeHelper.cs
│ └── Utilities
│ │ ├── LambdaDisposable.cs
│ │ └── RuntimeContextManager.cs
└── Aevatar
│ ├── Aevatar.csproj
│ ├── AevatarDefaultConventionalRegistrar.cs
│ ├── AevatarModule.cs
│ ├── ConfigureAevatarGrainActivator.cs
│ └── Extensions
│ └── OrleansHostExtensions.cs
└── test
├── Aevatar.Core.Tests
├── Aevatar.Core.Tests.csproj
├── AevatarTestKitSilo.cs
├── ContextPropagationTests.cs
├── EventHandlingTests.cs
├── EventSourcingTests.cs
├── GAgentTestKitBase.cs
├── GroupingTests.cs
├── Placement
│ ├── SiloNamePatternPlacementTests.cs
│ └── SiloNamePatternRegistrationTests.cs
├── PublishingTests.cs
├── TestArtifacts
│ └── MyArtifact.cs
├── TestEvents
│ ├── DevelopTaskTestEvent.cs
│ ├── GroupReloadTestEvent.cs
│ ├── IncorrectTestEvent.cs
│ ├── InvestorFeedbackTestEvent.cs
│ ├── NaiveTestEvent.cs
│ ├── NewDemandTestEvent.cs
│ ├── NewFeatureCompletedTestEvent.cs
│ ├── NotImplEventBaseTestEvent.cs
│ ├── ReceiveMessageTestEvent.cs
│ ├── ResponseTestEvent.cs
│ ├── SendMessageTestEvent.cs
│ ├── SocialTestEvent.cs
│ └── WorkingOnTestEvent.cs
├── TestGAgents
│ ├── BadEventHandlerTestGAgent.cs
│ ├── ConfigurationTestGAgent.cs
│ ├── DeveloperTestGAgent.cs
│ ├── DevelopingLeaderTestGAgent.cs
│ ├── EventHandlerTestGAgent.cs
│ ├── EventHandlerWithResponseTestGAgent.cs
│ ├── ExceptionHandlingTestGAgent.cs
│ ├── FatalEventHandlerTestGAgent.cs
│ ├── GroupGAgent.cs
│ ├── GroupTestGAgent.cs
│ ├── InvestorTestGAgent.cs
│ ├── LogViewAdaptorTestGAgent.cs
│ ├── LongRunTaskTestGAgent.cs
│ ├── MarketingLeaderTestGAgent.cs
│ ├── NaiveTestGAgent.cs
│ ├── PermissionTestGAgent.cs
│ ├── SampleAIGAgent.cs
│ ├── SubscribeTestGAgent.cs
│ ├── TestStateProjectionGAgent.cs
│ └── TokenUsageProjectionGAgent.cs
├── TestHelper.cs
├── TestStateLogEvents
│ ├── MessageStateLogEvent.cs
│ └── ReceiveMessageTestStateLogEvent.cs
└── TestStateProjector.cs
├── Aevatar.EventSourcing.MongoDB.Tests
├── Aevatar.EventSourcing.MongoDB.Tests.csproj
├── AevatarMongoDbFixture.cs
├── BsonGrainSerializerTests.cs
├── GrainTypeBsonSerializer.cs
├── IdSpanBsonSerializer.cs
├── MongoDbLogConsistentStorageMongoTests.cs
├── MongoDbLogConsistentStorageTests.cs
├── MongoDbTestCollection.cs
└── TestSiloLifecycle.cs
├── Aevatar.GAgents.Plugins
├── Aevatar.GAgents.Plugins.csproj
└── PluginTestGAgent.cs
├── Aevatar.GAgents.Tests
├── Aevatar.GAgents.Tests.csproj
├── AevatarGAgentsTestBase.cs
├── AevatarGAgentsTestModule.cs
├── AssemblyInfo.cs
├── EventDispatcherTests.cs
├── GAgentBaseTests.cs
├── GAgentFactoryTests.cs
├── GAgentPermissionTests.cs
├── InMemoryPluginCodeStorageRepository.cs
├── InMemoryPluginLoadStatusRepository.cs
├── InMemoryTenantPluginCodeRepository.cs
├── MockPermissionGrantRepository.cs
├── PermissionGAgentBaseTests.cs
├── PluginGAgentManagerTests.cs
├── PluginTestCollection.cs
├── Plugins
│ └── RestSharp.dll
├── StateProjectionGAgentBaseTests.cs
├── TestPermissionDefinitionProvider.cs
└── appsettings.json
├── Aevatar.TestBase
├── Aevatar.TestBase.csproj
├── AevatarTestBase.cs
├── AevatarTestBaseModule.cs
├── ClusterCollection.cs
├── ClusterFixture.cs
├── InterfaceImplementationsFinder.cs
├── MockLoggerProvider.cs
└── appsettings.json
└── Aevatar.TestKit.Tests
├── Aevatar.TestKit.Tests.csproj
├── GlobalSuppressions.cs
├── GlobalUsing.cs
├── Grains
├── ActivationCountWithReminder.cs
├── BasicGrains.cs
├── ChatMessage.cs
├── Chatty.cs
├── ColorGrain.cs
├── ColorGrainState.cs
├── ColorRankingGrain.cs
├── ContextConstructorGrain.cs
├── DeactivationGrain.cs
├── DependencyGrain.cs
├── DeviceAndroidGrain.cs
├── DeviceIosGrain.cs
├── DeviceManagerGrain.cs
├── GrainContextGrain.cs
├── GreetingArchiveGrain.cs
├── HelloGrain.cs
├── HelloGrainWithServiceDependency.cs
├── HelloReminders.cs
├── HelloTimers.cs
├── IUnknownGrainResolver.cs
├── LifecycleGrain.cs
├── Listener.cs
├── PersistentListenerWithHandleInState.cs
├── PersistentListenerWithoutHandleInState.cs
├── PingGrain.cs
├── StatefulActivationGrain.cs
├── StatefulNonNewActivationGrain.cs
└── UnknownGrainResolver.cs
├── Interfaces
├── Color.cs
├── IBasicGrains.cs
├── IChatty.cs
├── IColorGrain.cs
├── IColorRankingGrain.cs
├── IDateTimeService.cs
├── IDeactivationGrain.cs
├── IDependencyGrain.cs
├── IDevice.cs
├── IDeviceManager.cs
├── IGreetingArchiveGrain.cs
├── IHello.cs
├── ILifecycleGrain.cs
├── IListener.cs
├── IPing.cs
├── IPong.cs
├── IPong2.cs
├── IPongCompound.cs
└── IUnknownGrain.cs
└── Tests
├── ActivationGrainTests.cs
├── BasicGrainTests.cs
├── ContextConstructorGrainTests.cs
├── DeactivationGrainTests.cs
├── DependencyGrainTests.cs
├── GrainContextTests.cs
├── GrainIdTests.cs
├── GrainProbeTests.cs
├── LoggerTests.cs
├── PersistantStreamNotWithinGrainStateTests.cs
├── PersistentStreamWithinGrainStateTests.cs
├── ReminderTests.cs
├── ServiceProbeTests.cs
├── StorageFacetTests.cs
├── StorageTests.cs
├── StreamBatchTests.cs
├── StreamProbeStringTests.cs
├── StreamTests.cs
├── StrictGrainProbeTests.cs
├── StrictStreamTests.cs
└── TimerTests.cs
/.cursor/rules/code-practices.mdc:
--------------------------------------------------------------------------------
1 | ---
2 | description:
3 | globs:
4 | alwaysApply: true
5 | ---
6 |
7 | # Coding Best Practices
8 |
9 | Iterate until the implementation adheres to the following:
10 | - SOLID principles
11 | - Add logging at important checkpoints of the code
12 | - Ensure scalability and performance
13 |
14 | Whenever `dotnet build` or `dotnet run` is executed, fix the compile error if there are any.
15 | When referencing code, make sure that the referenced code exists.
--------------------------------------------------------------------------------
/.cursor/rules/test-practices.mdc:
--------------------------------------------------------------------------------
1 | ---
2 | description: implement unit test
3 | globs:
4 | alwaysApply: false
5 | ---
6 |
7 | # Unit Test Writing Best Practices
8 |
9 | When working on unit tests, do the following:
10 | 1. Output "!!!Implementing Unit Test Cases!!!".
11 | 2. Make sure to cover the following test cases:
12 | 1. Positive Test Cases
13 | 2. Negative Test Cases
14 | 3. Boundary Test Cases
15 | 4. Exception Test Cases
16 | 3. Use Arrange, Act and Assert format.
17 | 4. Implement using SOLID principles.
18 | 5. Only edit test files.
19 |
20 | You MUST iterate implementing and fixing unit tests until all the following criteria are met:
21 | 1. At least 80% code coverage.
22 | 2. All unit test cases passes.
23 | 3. Execute `dotnet test` and it yields no compile error.
--------------------------------------------------------------------------------
/.github/workflows/test-with-code-coverage.yml:
--------------------------------------------------------------------------------
1 | name: Test with code coverage
2 |
3 | on:
4 | push:
5 | branches:
6 | - '**'
7 |
8 | env:
9 | DOTNET_INSTALL_DIR: "./.dotnet"
10 |
11 | jobs:
12 | test:
13 | runs-on: ubuntu-22.04
14 | permissions:
15 | pull-requests: write
16 | contents: write
17 | steps:
18 | - name: Checkout
19 | uses: actions/checkout@v4
20 | - name: Setup dotnet
21 | uses: actions/setup-dotnet@v4
22 | with:
23 | dotnet-version: '9.0.x'
24 | - name: chown
25 | run: |
26 | sudo chown -R $USER:$USER /home/runneradmin
27 | - name: Install dependencies
28 | run: dotnet restore --verbosity quiet
29 |
30 | - name: Build
31 | run: dotnet build --no-restore /clp:ErrorsOnly /p:GeneratePackageOnBuild=false --verbosity quiet
32 |
33 | - name: Test
34 | run: |
35 | dotnet test --no-restore --no-build --logger trx --settings CodeCoverage.runsettings --results-directory coverage --collect:"XPlat Code Coverage"
36 |
37 | - name: Upload coverage reports to Codecov
38 | uses: codecov/codecov-action@v4
39 | with:
40 | fail_ci_if_error: true
41 | files: ./coverage/*/coverage.cobertura.xml
42 | env:
43 | CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
--------------------------------------------------------------------------------
/CodeCoverage.runsettings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 | cobertura
9 | [xunit.*]*,[*Tests]*
10 | **/test/**/*.cs,**/samples/**/*.cs
11 | Obsolete,GeneratedCodeAttribute
12 | false
13 |
14 |
15 |
16 |
17 |
--------------------------------------------------------------------------------
/Directory.Build.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | netstandard2.0
4 | net9.0
5 |
6 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | MIT License
2 |
3 | Copyright (c) 2024 AElfProject
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/codecov.yml:
--------------------------------------------------------------------------------
1 | codecov:
2 | notify:
3 | after_n_builds: 1
4 | coverage:
5 | status:
6 | project:
7 | default:
8 | target: auto
--------------------------------------------------------------------------------
/common.props:
--------------------------------------------------------------------------------
1 |
2 |
3 | latest
4 | 1.0.0
5 | $(NoWarn);CS1591
6 | app
7 |
8 |
9 |
10 |
11 | $(NoWarn);0436
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/docs/MODULE_DOCUMENTATION.md:
--------------------------------------------------------------------------------
1 | # Aevatar Framework Module Documentation
2 |
3 | This directory contains detailed technical documentation for the major modules of the Aevatar Framework.
4 |
5 | ## Available Module Documentation
6 |
7 | - [Aevatar.Core](./Aevatar.Core.md) - Core framework components for Generative Agents
8 | - [Aevatar.EventSourcing.Core](./Aevatar.EventSourcing.Core.md) - Event sourcing implementation
9 | - [Aevatar.Plugins](./Aevatar.Plugins.md) - Plugin system for extending agent capabilities
10 | - [Aevatar.PermissionManagement](./Aevatar.PermissionManagement.md) - Access control system for agents and resources
11 |
12 | ## Documentation Format
13 |
14 | Each module documentation includes:
15 |
16 | 1. **Data Flow Sequence Diagram** - Illustrates the typical flow of data and interactions between components
17 | 2. **Relationship Diagram** - Shows the class relationships and dependencies within the module
18 | 3. **Module Explanation** - Detailed overview of the module's purpose, components, and capabilities
19 |
20 | The diagrams are provided in Mermaid format, which can be rendered in GitHub and other Markdown viewers that support Mermaid syntax.
--------------------------------------------------------------------------------
/samples/ArtifactGAgent/ArtifactGAgent.Client/ArtifactGAgent.Client.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | $(DefaultTargetFramework)
6 | enable
7 | enable
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/samples/ArtifactGAgent/ArtifactGAgent.Client/Program.cs:
--------------------------------------------------------------------------------
1 | using Aevatar.Core.Abstractions;
2 | using Aevatar.Core.Tests.TestArtifacts;
3 | using Aevatar.Extensions;
4 | using Microsoft.Extensions.DependencyInjection;
5 | using Microsoft.Extensions.Logging;
6 | using Microsoft.Extensions.Hosting;
7 |
8 | var builder = Host.CreateDefaultBuilder(args)
9 | .UseOrleansClient(client =>
10 | {
11 | client.UseLocalhostClustering()
12 | .AddMemoryStreams(AevatarCoreConstants.StreamProvider)
13 | .UseAevatar();
14 | })
15 | .ConfigureLogging(logging => logging.AddConsole())
16 | .UseConsoleLifetime();
17 |
18 | using IHost host = builder.Build();
19 | await host.StartAsync();
20 |
21 | var gAgentFactory = host.Services.GetRequiredService();
22 | var gAgentManager = host.Services.GetRequiredService();
23 |
24 | var allGAgents = gAgentManager.GetAvailableGAgentTypes();
25 | Console.WriteLine("All types:");
26 | foreach (var gAgent in allGAgents)
27 | {
28 | Console.WriteLine(gAgent.FullName);
29 | }
30 |
31 | Console.WriteLine();
32 |
33 | {
34 | Console.WriteLine("Get GAgent from Type:");
35 | var myArtifactGAgent =
36 | await gAgentFactory.GetArtifactGAgentAsync();
37 | var description = await myArtifactGAgent.GetDescriptionAsync();
38 | Console.WriteLine(description);
39 | }
40 |
41 | Console.ReadKey();
--------------------------------------------------------------------------------
/samples/ArtifactGAgent/ArtifactGAgent.Silo/ArtifactGAgent.Silo.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | $(DefaultTargetFramework)
6 | enable
7 | enable
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 | Always
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/samples/ArtifactGAgent/ArtifactGAgent.Silo/Program.cs:
--------------------------------------------------------------------------------
1 | using Aevatar.Core.Abstractions;
2 | using Aevatar.Extensions;
3 | using Microsoft.Extensions.Configuration;
4 | using Microsoft.Extensions.Hosting;
5 | using Microsoft.Extensions.Logging;
6 |
7 | var builder = Host.CreateDefaultBuilder(args)
8 | .ConfigureAppConfiguration((_, config) =>
9 | {
10 | config.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
11 | })
12 | .UseOrleans(silo =>
13 | {
14 | silo.AddMemoryGrainStorage("Default")
15 | .AddMemoryStreams(AevatarCoreConstants.StreamProvider)
16 | .AddMemoryGrainStorage("PubSubStore")
17 | .AddLogStorageBasedLogConsistencyProvider("LogStorage")
18 | .UseLocalhostClustering()
19 | .UseAevatar()
20 | .ConfigureLogging(logging => logging.SetMinimumLevel(LogLevel.Information).AddConsole());
21 | })
22 | .UseConsoleLifetime();
23 |
24 | using var host = builder.Build();
25 |
26 | await host.RunAsync();
--------------------------------------------------------------------------------
/samples/ArtifactGAgent/ArtifactGAgent.Silo/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "ConnectionStrings": {
3 | "Default": "mongodb://127.0.0.1:27017/AevatarDb"
4 | }
5 | }
--------------------------------------------------------------------------------
/samples/BroadCastGAgentDemo/BroadCastGAgentDemo.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net9.0
6 | enable
7 | enable
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/samples/MessagingGAgent.Client/MessagingGAgent.Client.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | $(DefaultTargetFramework)
6 | enable
7 | enable
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | PreserveNewest
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/samples/MessagingGAgent.Grains/Agents/Events/MessagingEvent.cs:
--------------------------------------------------------------------------------
1 | using Aevatar.Core.Abstractions;
2 |
3 | namespace MessagingGAgent.Grains.Agents.Events;
4 |
5 | [GenerateSerializer]
6 | public class MessagingEvent : EventBase
7 | {
8 | [Id(0)] public string Message { get; set; } = string.Empty;
9 | }
--------------------------------------------------------------------------------
/samples/MessagingGAgent.Grains/Agents/Events/SendEvent.cs:
--------------------------------------------------------------------------------
1 | using Aevatar.Core.Abstractions;
2 |
3 | namespace MessagingGAgent.Grains.Agents.Events;
4 |
5 | [GenerateSerializer]
6 | public class SendEvent : EventBase
7 | {
8 | [Id(0)] public string Message { get; set; } = string.Empty;
9 | }
--------------------------------------------------------------------------------
/samples/MessagingGAgent.Grains/Agents/Group/GroupAgentState.cs:
--------------------------------------------------------------------------------
1 | using Aevatar.Core.Abstractions;
2 |
3 | namespace MessagingGAgent.Grains.Agents.Group;
4 |
5 | [GenerateSerializer]
6 | public class GroupAgentState : StateBase
7 | {
8 | [Id(0)] public int RegisteredAgents { get; set; } = 0;
9 | }
--------------------------------------------------------------------------------
/samples/MessagingGAgent.Grains/Agents/Group/GroupGAgent.cs:
--------------------------------------------------------------------------------
1 | using Aevatar.Core;
2 | using Aevatar.Core.Abstractions;
3 | using Microsoft.Extensions.Logging;
4 | using Orleans.Providers;
5 |
6 | namespace MessagingGAgent.Grains.Agents.Group;
7 |
8 | public interface IGroupGAgent : IGAgent
9 | {
10 | }
11 | [GrainType("MessagingGroupGAgent")]
12 | [StorageProvider(ProviderName = "PubSubStore")]
13 | [LogConsistencyProvider(ProviderName = "LogStorage")]
14 | public class GroupGAgent : GAgentBase, IGroupGAgent
15 | {
16 | public override Task GetDescriptionAsync()
17 | {
18 | return Task.FromResult("An agent to inform other agents when a social event is published.");
19 | }
20 |
21 | protected override Task OnRegisterAgentAsync(GrainId agentGuid)
22 | {
23 | ++State.RegisteredAgents;
24 | return Task.CompletedTask;
25 | }
26 |
27 | protected override Task OnUnregisterAgentAsync(GrainId agentGuid)
28 | {
29 | --State.RegisteredAgents;
30 | return Task.CompletedTask;
31 | }
32 |
33 | protected override async Task OnGAgentActivateAsync(CancellationToken cancellationToken)
34 | {
35 | State.RegisteredAgents = 0;
36 | }
37 | }
--------------------------------------------------------------------------------
/samples/MessagingGAgent.Grains/Agents/Group/GroupStateLogEvent.cs:
--------------------------------------------------------------------------------
1 | using Aevatar.Core.Abstractions;
2 |
3 | namespace MessagingGAgent.Grains.Agents.Group;
4 |
5 | public class GroupStateLogEvent : StateLogEventBase
6 | {
7 |
8 | }
--------------------------------------------------------------------------------
/samples/MessagingGAgent.Grains/Agents/Messaging/MessagingGAgent.cs:
--------------------------------------------------------------------------------
1 | using Aevatar.Core;
2 | using Aevatar.Core.Abstractions;
3 | using MessagingGAgent.Grains.Agents.Events;
4 | using Microsoft.Extensions.Logging;
5 |
6 | namespace MessagingGAgent.Grains.Agents.Messaging;
7 |
8 | public interface IMessagingGAgent : IGAgent
9 | {
10 | Task GetReceivedMessagesAsync();
11 | }
12 |
13 | public class MessagingGAgent : GAgentBase, IMessagingGAgent
14 | {
15 | public override Task GetDescriptionAsync()
16 | {
17 | return Task.FromResult("Agent for messaging.");
18 | }
19 |
20 | [EventHandler]
21 | public async Task OnSendEvent(SendEvent @event)
22 | {
23 | await Task.Delay(1000);
24 | await PublishAsync(new MessagingEvent()
25 | {
26 | Message = $"{this.GetGrainId().ToString()} sent a message."
27 | });
28 | }
29 |
30 | [EventHandler]
31 | public async Task OnMessagingEvent(MessagingEvent @event)
32 | {
33 | RaiseEvent(new MessagingStateLogEvent());
34 | await ConfirmEvents();
35 | }
36 |
37 | public Task GetReceivedMessagesAsync()
38 | {
39 | return Task.FromResult(State.ReceivedMessages);
40 | }
41 | }
--------------------------------------------------------------------------------
/samples/MessagingGAgent.Grains/Agents/Messaging/MessagingGState.cs:
--------------------------------------------------------------------------------
1 | using Aevatar.Core.Abstractions;
2 |
3 | namespace MessagingGAgent.Grains.Agents.Messaging;
4 |
5 | public class MessagingGState : StateBase
6 | {
7 | public int ReceivedMessages { get; set; } = 0;
8 |
9 | public void Apply(MessagingStateLogEvent message)
10 | {
11 | ReceivedMessages++;
12 | }
13 | }
--------------------------------------------------------------------------------
/samples/MessagingGAgent.Grains/Agents/Messaging/MessagingStateLogEvent.cs:
--------------------------------------------------------------------------------
1 | using Aevatar.Core.Abstractions;
2 |
3 | namespace MessagingGAgent.Grains.Agents.Messaging;
4 |
5 | public class MessagingStateLogEvent : StateLogEventBase
6 | {
7 |
8 | }
--------------------------------------------------------------------------------
/samples/MessagingGAgent.Grains/Agents/Messaging/SpecializedGrain.cs:
--------------------------------------------------------------------------------
1 | using Aevatar.Core.Placement;
2 |
3 | namespace MessagingGAgent.Grains;
4 | ///
5 | /// Example of a grain class that uses the SiloNamePatternPlacement attribute to specify placement.
6 | ///
7 | [SiloNamePatternPlacement("Analytics")]
8 | public class SpecializedGrain : Orleans.Grain, ISpecializedGrain
9 | {
10 | public Task DoSomethingAsync()
11 | {
12 | // This grain will be activated on a silo whose name begins with "Analytics" if available
13 | // For example, it will match "AnalyticsSilo-01", "DataAnalytics", etc.
14 | Console.WriteLine($"Grain activated on silo: {this.RuntimeIdentity}");
15 | return Task.CompletedTask;
16 | }
17 | }
18 |
19 | ///
20 | /// Interface for the specialized grain example.
21 | ///
22 | public interface ISpecializedGrain : Orleans.IGrainWithGuidKey
23 | {
24 | Task DoSomethingAsync();
25 | }
--------------------------------------------------------------------------------
/samples/MessagingGAgent.Grains/MessagingGAgent.Grains.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(DefaultTargetFramework)
5 | enable
6 | enable
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/samples/MessagingGAgent.Silo/MessagingGAgent.Silo.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | $(DefaultTargetFramework)
6 | enable
7 | enable
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | Always
24 |
25 |
26 |
27 |
--------------------------------------------------------------------------------
/samples/MessagingGAgent.Silo/Program.cs:
--------------------------------------------------------------------------------
1 | using Aevatar.Core.Abstractions;
2 | using Orleans.Configuration;
3 | using Microsoft.Extensions.Hosting;
4 | using Microsoft.Extensions.Logging;
5 | using Aevatar.Core.Placement;
6 |
7 | /// Set your Orleans Silo name pattern in the environment variable SILO_NAME_PATTERN.
8 |
9 | var siloNamePattern = "No-Analytics-Silo";
10 | var builder = Host.CreateDefaultBuilder(args)
11 | .UseOrleans(silo =>
12 | {
13 | silo.AddMemoryGrainStorage("Default")
14 | .AddMemoryStreams(AevatarCoreConstants.StreamProvider)
15 | .AddMemoryGrainStorage("PubSubStore")
16 | .AddLogStorageBasedLogConsistencyProvider("LogStorage")
17 | .UseLocalhostClustering()
18 | .Configure(options =>
19 | {
20 | options.SiloName = $"{siloNamePattern}-{Guid.NewGuid().ToString("N").Substring(0, 6)}";
21 | })
22 | .ConfigureLogging(logging => logging.AddConsole());
23 | })
24 | .UseConsoleLifetime();
25 |
26 | builder.ConfigureServices((context, services) =>
27 | {
28 | // Register the SiloNamePatternPlacement director
29 | services.AddPlacementDirector();
30 |
31 | });
32 |
33 | using var host = builder.Build();
34 |
35 | await host.RunAsync();
--------------------------------------------------------------------------------
/samples/PluginGAgent/PluginGAgent.Client/PluginGAgent.Client.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | $(DefaultTargetFramework)
6 | enable
7 | enable
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 | Always
28 |
29 |
30 |
31 |
32 |
33 |
34 | Always
35 |
36 |
37 |
38 |
39 |
--------------------------------------------------------------------------------
/samples/PluginGAgent/PluginGAgent.Client/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Serilog": {
3 | "Properties": {
4 | "Application": "PluginGAgent.Silo",
5 | "Environment": "Development"
6 | },
7 | "MinimumLevel": {
8 | "Default": "Debug",
9 | "Override": {
10 | "Default": "Debug",
11 | "System": "Warning",
12 | "Microsoft": "Warning",
13 | "Orleans": "Warning"
14 | }
15 | },
16 | "WriteTo": [
17 | {
18 | "Name": "Console",
19 | "Args": {
20 | "formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact"
21 | }
22 | },
23 | {
24 | "Name": "RollingFile",
25 | "Args": {
26 | "pathFormat": "Logs/log-{Date}.log",
27 | "outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff}{Offset:zzz}][{Level:u3}] [{SourceContext}] {Message}{NewLine}{Exception}",
28 | "rollOnFileSizeLimit": true,
29 | "rollingInterval": "Day",
30 | "retainedFileCountLimit": 15
31 | }
32 | }
33 | ]
34 | },
35 | "Plugins": {
36 | "TenantId": "cd6b8f09214673d3cade4e832627b4f6"
37 | },
38 | "ConnectionStrings": {
39 | "Default": "mongodb://localhost:27017/Aevatar",
40 | "Orleans": "mongodb://localhost:27017/AevatarDb"
41 | },
42 | "Aevatar": {
43 | "StreamNamespace": "Aevatar"
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/samples/PluginGAgent/PluginGAgent.Client/plugins/Aevatar.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aevatarAI/aevatar-framework/b4e62d20ab438dc664a3026e07af96dcba57965c/samples/PluginGAgent/PluginGAgent.Client/plugins/Aevatar.dll
--------------------------------------------------------------------------------
/samples/PluginGAgent/PluginGAgent.Client/plugins/PluginGAgent.Grains.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aevatarAI/aevatar-framework/b4e62d20ab438dc664a3026e07af96dcba57965c/samples/PluginGAgent/PluginGAgent.Client/plugins/PluginGAgent.Grains.dll
--------------------------------------------------------------------------------
/samples/PluginGAgent/PluginGAgent.Client/plugins/PluginGAgent.GrainsDup.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aevatarAI/aevatar-framework/b4e62d20ab438dc664a3026e07af96dcba57965c/samples/PluginGAgent/PluginGAgent.Client/plugins/PluginGAgent.GrainsDup.dll
--------------------------------------------------------------------------------
/samples/PluginGAgent/PluginGAgent.Client/plugins/RestSharp.dll:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aevatarAI/aevatar-framework/b4e62d20ab438dc664a3026e07af96dcba57965c/samples/PluginGAgent/PluginGAgent.Client/plugins/RestSharp.dll
--------------------------------------------------------------------------------
/samples/PluginGAgent/PluginGAgent.Grains/CommanderGAgent.cs:
--------------------------------------------------------------------------------
1 | using Aevatar.Core;
2 | using Aevatar.Core.Abstractions;
3 |
4 | namespace PluginGAgent.Grains;
5 |
6 | [GenerateSerializer]
7 | public class CommanderGAgentState : StateBase
8 | {
9 |
10 | }
11 |
12 | [GenerateSerializer]
13 | public class CommanderStateLogEvent : StateLogEventBase
14 | {
15 |
16 | }
17 |
18 | [GenerateSerializer]
19 | public class Command : EventBase
20 | {
21 | [Id(0)] public string Content { get; set; }
22 | }
23 |
24 | [GAgent("commander", "pluginTest")]
25 | public class CommanderGAgent : GAgentBase
26 | {
27 | public override Task GetDescriptionAsync()
28 | {
29 | return Task.FromResult("This is a GAgent for");
30 | }
31 | }
--------------------------------------------------------------------------------
/samples/PluginGAgent/PluginGAgent.Grains/PluginGAgent.Grains.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net9.0
5 | enable
6 | enable
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/samples/PluginGAgent/PluginGAgent.Grains/WorkerGAgent.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics;
2 | using System.Reflection;
3 | using Aevatar.Core;
4 | using Aevatar.Core.Abstractions;
5 | using Microsoft.Extensions.Logging;
6 | using RestSharp;
7 |
8 | namespace PluginGAgent.Grains;
9 |
10 | [GenerateSerializer]
11 |
12 | public class WorkerGAgentState : StateBase;
13 |
14 | [GenerateSerializer]
15 | public class WorkerStateLogEvent : StateLogEventBase;
16 |
17 | [GAgent("worker", "pluginTest")]
18 | public class WorkerGAgent : GAgentBase
19 | {
20 | public override Task GetDescriptionAsync()
21 | {
22 | return Task.FromResult("This is a GAgent for");
23 | }
24 |
25 | [EventHandler]
26 | public async Task HandleEventAsync(Command data)
27 | {
28 | Logger.LogInformation("Received command: {0}", data.Content);
29 |
30 | var client = new RestClient("https://www.hao123.com");
31 | var request = new RestRequest("/api/gethitthecity");
32 | var response = await client.GetAsync(request);
33 | Logger.LogInformation($"Response: {response.Content}");
34 | }
35 | }
--------------------------------------------------------------------------------
/samples/PluginGAgent/PluginGAgent.GrainsDup/CommanderGAgent.cs:
--------------------------------------------------------------------------------
1 | using Aevatar.Core;
2 | using Aevatar.Core.Abstractions;
3 |
4 | namespace PluginGAgent.Grains;
5 |
6 | [GenerateSerializer]
7 | public class CommanderGAgentState : StateBase
8 | {
9 |
10 | }
11 |
12 | [GenerateSerializer]
13 | public class CommanderStateLogEvent : StateLogEventBase
14 | {
15 |
16 | }
17 |
18 | [GenerateSerializer]
19 | public class Command : EventBase
20 | {
21 | [Id(0)] public string Content { get; set; }
22 | }
23 |
24 | [GAgent("commander", "pluginTest")]
25 | public class CommanderGAgent : GAgentBase
26 | {
27 | public override Task GetDescriptionAsync()
28 | {
29 | return Task.FromResult("This is a GAgent for");
30 | }
31 | }
--------------------------------------------------------------------------------
/samples/PluginGAgent/PluginGAgent.GrainsDup/PluginGAgent.GrainsDup.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net9.0
5 | enable
6 | enable
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/samples/PluginGAgent/PluginGAgent.GrainsDup/WorkerGAgent.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics;
2 | using System.Reflection;
3 | using Aevatar.Core;
4 | using Aevatar.Core.Abstractions;
5 | using Microsoft.Extensions.Logging;
6 | using RestSharp;
7 |
8 | namespace PluginGAgent.Grains;
9 |
10 | [GenerateSerializer]
11 |
12 | public class WorkerGAgentState : StateBase;
13 |
14 | [GenerateSerializer]
15 | public class WorkerStateLogEvent : StateLogEventBase;
16 |
17 | [GAgent("worker", "pluginTest")]
18 | public class WorkerGAgent : GAgentBase
19 | {
20 | public override Task GetDescriptionAsync()
21 | {
22 | return Task.FromResult("This is a GAgent for");
23 | }
24 |
25 | [EventHandler]
26 | public async Task HandleEventAsync(Command data)
27 | {
28 | Logger.LogInformation("Received command: {0}", data.Content);
29 |
30 | var client = new RestClient("https://www.hao123.com");
31 | var request = new RestRequest("/api/gethitthecity");
32 | var response = await client.GetAsync(request);
33 | Logger.LogInformation($"Response: {response.Content}");
34 | }
35 | }
--------------------------------------------------------------------------------
/samples/PluginGAgent/PluginGAgent.Silo/PluginGAgentTestHostedService.cs:
--------------------------------------------------------------------------------
1 | using Aevatar.Core.Abstractions.Extensions;
2 | using Aevatar.Core.Abstractions.Plugin;
3 | using Aevatar.Plugins.Extensions;
4 | using Microsoft.Extensions.DependencyInjection;
5 | using Microsoft.Extensions.Hosting;
6 | using Volo.Abp;
7 | using Volo.Abp.PermissionManagement;
8 |
9 | namespace PluginGAgent.Silo;
10 |
11 | public class PluginGAgentTestHostedService : IHostedService
12 | {
13 | private readonly IAbpApplicationWithExternalServiceProvider _application;
14 | private readonly IServiceProvider _serviceProvider;
15 |
16 | public PluginGAgentTestHostedService(
17 | IAbpApplicationWithExternalServiceProvider application,
18 | IServiceProvider serviceProvider)
19 | {
20 | _application = application;
21 | _serviceProvider = serviceProvider;
22 | }
23 |
24 | public async Task StartAsync(CancellationToken cancellationToken)
25 | {
26 | await _application.InitializeAsync(_serviceProvider);
27 | }
28 |
29 | public Task StopAsync(CancellationToken cancellationToken)
30 | {
31 | _application.Shutdown();
32 | return Task.CompletedTask;
33 | }
34 | }
--------------------------------------------------------------------------------
/samples/PluginGAgent/PluginGAgent.Silo/PluginGAgentTestModule.cs:
--------------------------------------------------------------------------------
1 | using Aevatar;
2 | using Aevatar.Core.Abstractions;
3 | using Aevatar.PermissionManagement;
4 | using Microsoft.Extensions.DependencyInjection;
5 | using Serilog;
6 | using Volo.Abp.AspNetCore.Serilog;
7 | using Volo.Abp.Autofac;
8 | using Volo.Abp.AutoMapper;
9 | using Volo.Abp.Modularity;
10 | using Volo.Abp.PermissionManagement;
11 |
12 | namespace PluginGAgent.Silo;
13 |
14 | [DependsOn(
15 | typeof(AbpAspNetCoreSerilogModule),
16 | typeof(AbpAutofacModule),
17 | typeof(AbpAutoMapperModule),
18 | // typeof(AevatarPermissionManagementModule),
19 | typeof(AevatarModule)
20 | )]
21 | public class PluginGAgentTestModule : AbpModule
22 | {
23 | public override void ConfigureServices(ServiceConfigurationContext context)
24 | {
25 | Configure(options => { options.AddMaps(); });
26 | context.Services.AddHostedService();
27 | context.Services.AddSerilog(_ => {},
28 | true, writeToProviders: true);
29 | context.Services.AddHttpClient();
30 | context.Services.AddSingleton();
31 | // Configure(options =>
32 | // {
33 | // options.IsDynamicPermissionStoreEnabled = true;
34 | // });
35 | }
36 | }
--------------------------------------------------------------------------------
/samples/PluginGAgent/PluginGAgent.Silo/Program.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.Configuration;
2 | using Microsoft.Extensions.Hosting;
3 | using Microsoft.Extensions.DependencyInjection;
4 | using PluginGAgent.Silo.Extensions;
5 | using Serilog;
6 |
7 | namespace PluginGAgent.Silo;
8 |
9 | public class Program
10 | {
11 | public static async Task Main(string[] args)
12 | {
13 | var configuration = new ConfigurationBuilder()
14 | .AddJsonFile("appsettings.json")
15 | .AddJsonFile("appsettings.secrets.json", optional: true)
16 | .Build();
17 | Log.Logger = new LoggerConfiguration()
18 | .Enrich.FromLogContext()
19 | .ReadFrom.Configuration(configuration)
20 | .CreateLogger();
21 |
22 | try
23 | {
24 | Log.Information("Starting Silo");
25 | await CreateHostBuilder(args).RunConsoleAsync();
26 | return 0;
27 | }
28 | catch (Exception ex)
29 | {
30 | Log.Fatal(ex, "Host terminated unexpectedly!");
31 | return 1;
32 | }
33 | finally
34 | {
35 | Log.CloseAndFlush();
36 | }
37 | }
38 |
39 | internal static IHostBuilder CreateHostBuilder(string[] args) =>
40 | Host.CreateDefaultBuilder(args)
41 | .ConfigureServices((_, services) => { services.AddApplication(); })
42 | .UseOrleansConfiguration()
43 | .UseAutofac()
44 | .UseSerilog();
45 | }
--------------------------------------------------------------------------------
/samples/PluginGAgent/PluginGAgent.Silo/appsettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "Serilog": {
3 | "Properties": {
4 | "Application": "PluginGAgent.Silo",
5 | "Environment": "Development"
6 | },
7 | "MinimumLevel": {
8 | "Default": "Debug",
9 | "Override": {
10 | "Default": "Debug",
11 | "System": "Warning",
12 | "Microsoft": "Warning",
13 | "Orleans": "Warning"
14 | }
15 | },
16 | "WriteTo": [
17 | {
18 | "Name": "Console",
19 | "Args": {
20 | "formatter": "Serilog.Formatting.Compact.RenderedCompactJsonFormatter, Serilog.Formatting.Compact"
21 | }
22 | },
23 | {
24 | "Name": "RollingFile",
25 | "Args": {
26 | "pathFormat": "Logs/log-{Date}.log",
27 | "outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss.fff}{Offset:zzz}][{Level:u3}] [{SourceContext}] {Message}{NewLine}{Exception}",
28 | "rollOnFileSizeLimit": true,
29 | "rollingInterval": "Day",
30 | "retainedFileCountLimit": 15
31 | }
32 | }
33 | ]
34 | },
35 | "Plugins": {
36 | "TenantId": "cd6b8f09214673d3cade4e832627b4f6",
37 | "ConnectionString": "mongodb://localhost:27017/AevatarDb"
38 | },
39 | "ConnectionStrings": {
40 | "Default": "mongodb://localhost:27017/Aevatar",
41 | "Orleans": "mongodb://localhost:27017/AevatarDb"
42 | },
43 | "Aevatar": {
44 | "StreamNamespace": "Aevatar"
45 | }
46 | }
47 |
--------------------------------------------------------------------------------
/samples/PubSubDemoWithoutGroup/PubSubDemoWithoutGroup.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net9.0
6 | enable
7 | enable
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/samples/SiloNamePatternPlacementExamples/SiloNamePatternPlacementExamples.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net9.0
6 | enable
7 | enable
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Aevatar.Core.Abstractions.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(DefaultTargetFramework)
5 | enable
6 | enable
7 | Dependency
8 | Aevatar.Core.Abstractions
9 | aevatar Framework
10 | AElf
11 | The abstraction package to the Aevatar.Core framework.
12 | agent
13 | https://github.com/aevatarAI/aevatar-framework
14 | git
15 | https://github.com/aevatarAI/aevatar-framework
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/AevatarCoreConstants.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions;
2 |
3 | public class AevatarCoreConstants
4 | {
5 | public const int DefaultNumOfProjectorPerAgentType = 8;
6 | public const string StreamProvider = "Aevatar";
7 | public const char GAgentNamespaceSeparator = '.';
8 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/AevatarOptions.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions;
2 |
3 | public class AevatarOptions
4 | {
5 | public string StreamNamespace { get; set; } = "Aevatar";
6 | public string StateProjectionStreamNamespace { get; set; } = "AevatarStateProjection";
7 |
8 | public string BroadCastStreamNamespace { get; set; } = "AevatarBroadCast";
9 | //public int ElasticSearchProcessors { get; set; } = 10;
10 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Application/BroadCastGState.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions;
2 |
3 | using Orleans.Streams;
4 |
5 | [GenerateSerializer]
6 | public class BroadCastGState : StateBase
7 | {
8 | [Id(0)]public Dictionary Subscription = [];
9 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Application/RequestAllDescriptionsEvent.cs:
--------------------------------------------------------------------------------
1 | // ReSharper disable once CheckNamespace
2 | namespace Aevatar.Core.Abstractions;
3 |
4 | [GenerateSerializer]
5 | public class RequestAllSubscriptionsEvent : EventWithResponseBase
6 | {
7 | [Id(0)] public Type? RequestFromGAgentType { get; set; }
8 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Application/SubscribedEventListEvent.cs:
--------------------------------------------------------------------------------
1 | // ReSharper disable once CheckNamespace
2 | namespace Aevatar.Core.Abstractions;
3 |
4 | [GenerateSerializer]
5 | public class SubscribedEventListEvent : EventBase
6 | {
7 | ///
8 | /// Key: GAgent Type.
9 | /// Value: Subscribed Event Types.
10 | ///
11 | [Id(0)] public required Dictionary> Value { get; set; }
12 |
13 | [Id(1)] public required Type GAgentType { get; set; }
14 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/ConfigurationBase.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions;
2 |
3 | [GenerateSerializer]
4 | public abstract class ConfigurationBase : EventBase;
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/EventHandlerExceptionEvent.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions;
2 |
3 | [GenerateSerializer]
4 | public class EventHandlerExceptionEvent : EventBase
5 | {
6 | [Id(0)] public required GrainId GrainId { get; set; }
7 | [Id(1)] public required Type HandleEventType { get; set; }
8 | [Id(2)] public required string ExceptionMessage { get; set; }
9 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Events/EventBase.cs:
--------------------------------------------------------------------------------
1 | // ReSharper disable once CheckNamespace
2 | namespace Aevatar.Core.Abstractions;
3 |
4 | [GenerateSerializer]
5 | public abstract class EventBase
6 | {
7 | [Id(0)] public Guid? CorrelationId { get; set; }
8 | [Id(1)] public GrainId PublisherGrainId { get; set; }
9 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Events/EventWithResponseBase.cs:
--------------------------------------------------------------------------------
1 | // ReSharper disable once CheckNamespace
2 | namespace Aevatar.Core.Abstractions;
3 |
4 | [GenerateSerializer]
5 | public abstract class EventWithResponseBase : EventBase where TResponseEvent : EventBase;
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Events/EventWrapper.cs:
--------------------------------------------------------------------------------
1 | // ReSharper disable once CheckNamespace
2 | namespace Aevatar.Core.Abstractions;
3 |
4 | using System.Diagnostics;
5 |
6 | [GenerateSerializer]
7 | public class EventWrapper : EventWrapperBase where T : EventBase
8 | {
9 | [Id(0)] public T Event { get; private set; }
10 | [Id(1)] public Guid EventId { get; private set; }
11 | [Id(2)] public GrainId GrainId { get; private set; }
12 | [Id(3)] public Guid? CorrelationId { get; set; }
13 | [Id(4)] public GrainId PublisherGrainId { get; set; }
14 |
15 | public EventWrapper(T @event, Guid eventId, GrainId grainId)
16 | {
17 | Event = @event;
18 | EventId = eventId;
19 | GrainId = grainId;
20 | CorrelationId = @event.CorrelationId;
21 | PublisherGrainId = @event.PublisherGrainId;
22 | }
23 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Events/EventWrapperBase.cs:
--------------------------------------------------------------------------------
1 | // ReSharper disable once CheckNamespace
2 |
3 | using System.Diagnostics;
4 |
5 | namespace Aevatar.Core.Abstractions;
6 |
7 | using System.Collections.Generic;
8 |
9 | [GenerateSerializer]
10 | public abstract class EventWrapperBase
11 | {
12 | // Constants for context metadata keys
13 | public const string TraceIdKey = "TraceId";
14 | public const string SpanIdKey = "SpanId";
15 | public const string TraceFlagsKey = "TraceFlags";
16 | public const string BaggagePrefixKey = "Baggage.";
17 |
18 | [Id(0)]
19 | public Dictionary ContextMetadata { get; set; } = new Dictionary();
20 |
21 | protected EventWrapperBase()
22 | {
23 | // Initialize ContextMetadata
24 | ContextMetadata = new Dictionary();
25 |
26 | // Simple context injection - in real implementation, this would be
27 | // enhanced with DistributedContextPropagator usage in GAgentAsyncObserver
28 | var activity = Activity.Current;
29 | if (activity != null)
30 | {
31 | ContextMetadata[TraceIdKey] = activity.TraceId.ToString();
32 | ContextMetadata[SpanIdKey] = activity.SpanId.ToString();
33 | ContextMetadata[TraceFlagsKey] = activity.ActivityTraceFlags.ToString();
34 |
35 | // Add baggage items
36 | foreach (var baggage in activity.Baggage)
37 | {
38 | ContextMetadata[$"{BaggagePrefixKey}{baggage.Key}"] = baggage.Value;
39 | }
40 | }
41 | }
42 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Exceptions/ArtifactGAgentException.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions.Exceptions;
2 |
3 | public class ArtifactGAgentException(string message, Exception inner) : Exception(message, inner);
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Exceptions/EventHandlingException.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions.Exceptions;
2 |
3 | public class EventHandlingException(string message, Exception ex) : Exception(message, ex);
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Exceptions/EventPublishingException.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions.Exceptions;
2 |
3 | public class EventPublishingException(string message, Exception ex) : Exception(message, ex);
4 |
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Exceptions/StateTransitionException.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions.Exceptions;
2 |
3 | public class StateTransitionException(string message, Exception inner) : Exception(message, inner);
4 |
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Extensions/AssemblyExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 |
3 | namespace Aevatar.Core.Abstractions.Extensions;
4 |
5 | public static class AssemblyExtensions
6 | {
7 | public static Type[] GetTypesIgnoringLoadException(this Assembly? assembly)
8 | {
9 | if (assembly is null) return [];
10 | Type[] types;
11 | try
12 | {
13 | types = assembly.GetTypes();
14 | }
15 | catch (ReflectionTypeLoadException ex)
16 | {
17 | types = ex.Types.Where(t => t != null).ToArray()!;
18 | }
19 |
20 | return types;
21 | }
22 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Extensions/StringExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.Security.Cryptography;
2 | using System.Text;
3 |
4 | namespace Aevatar.Core.Abstractions.Extensions;
5 |
6 | public static class StringExtensions
7 | {
8 | public static Guid ToGuid(this string str)
9 | {
10 | var hash = MD5.HashData(Encoding.UTF8.GetBytes(str));
11 | return new Guid(hash);
12 | }
13 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/IArtifact.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions;
2 |
3 | public interface IArtifact
4 | where TState : StateBase
5 | where TStateLogEvent : StateLogEventBase
6 | {
7 | void TransitionState(TState state, StateLogEventBase stateLogEvent);
8 | string GetDescription();
9 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/IArtifactGAgent.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions;
2 |
3 | public interface IArtifactGAgent : IGAgent
4 | where TArtifact : IArtifact
5 | where TState : StateBase
6 | where TStateLogEvent : StateLogEventBase
7 | {
8 | Task GetArtifactAsync();
9 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/IExtGAgent.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions;
2 |
3 | ///
4 | /// Represents an extended GAgent which intends to boosts the performance of the current GAgent.
5 | /// It should be merged back to IGAgent after the performance is improved.
6 | ///
7 | public interface IExtGAgent : IGAgent
8 | {
9 |
10 | ///
11 | /// Register many GAgents as the next level of the current GAgent.
12 | /// To compare with RegisterAsync, this method is more efficient via batch processing.
13 | ///
14 | ///
15 | ///
16 | Task RegisterManyAsync(List gAgents);
17 |
18 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/IGAgentFactory.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions;
2 |
3 | public interface IGAgentFactory
4 | {
5 | Task GetGAgentAsync(GrainId grainId, ConfigurationBase? configuration = null);
6 |
7 | Task GetGAgentAsync(Guid primaryKey, string alias,
8 | string ns, ConfigurationBase? configuration = null);
9 |
10 | Task GetGAgentAsync(string alias, string ns,
11 | ConfigurationBase? configuration = null);
12 |
13 | Task GetGAgentAsync(Guid primaryKey, Type gAgentType, ConfigurationBase? configuration = null);
14 |
15 | Task GetGAgentAsync(Type gAgentType, ConfigurationBase? configuration = null);
16 |
17 | Task GetGAgentAsync(Guid primaryKey,
18 | ConfigurationBase? configuration = null)
19 | where TGrainInterface : IGAgent;
20 |
21 | Task GetGAgentAsync(GrainId grainId,
22 | ConfigurationBase? configuration = null)
23 | where TGrainInterface : IGAgent;
24 |
25 | Task GetGAgentAsync(ConfigurationBase? configuration = null)
26 | where TGrainInterface : IGAgent;
27 |
28 | Task>
29 | GetArtifactGAgentAsync(ConfigurationBase? configuration = null)
30 | where TArtifact : IArtifact, new()
31 | where TState : StateBase, new()
32 | where TStateLogEvent : StateLogEventBase;
33 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/IGAgentManager.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions;
2 |
3 | public interface IGAgentManager
4 | {
5 | List GetAvailableGAgentTypes();
6 | List GetAvailableEventTypes();
7 | List GetAvailableGAgentGrainTypes();
8 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/IPublishingGAgent.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions;
2 |
3 | public interface IPublishingGAgent : IGAgent
4 | {
5 | Task PublishEventAsync(T @event, params IGAgent[] agents) where T : EventBase;
6 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/IStateDispatcher.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions;
2 |
3 | public interface IStateDispatcher
4 | {
5 | Task PublishAsync(GrainId grainId, StateWrapper stateWrapper) where TState : StateBase;
6 | Task PublishSingleAsync(GrainId grainId, StateWrapper stateWrapper) where TState : StateBase;
7 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/IStateProjector.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions;
2 |
3 | public interface IStateProjector
4 | {
5 | Task ProjectAsync(T state) where T : StateWrapperBase;
6 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Infrastructure/AllEventHandlerAttribute.cs:
--------------------------------------------------------------------------------
1 | // ReSharper disable once CheckNamespace
2 | namespace Aevatar.Core.Abstractions;
3 |
4 | [AttributeUsage(AttributeTargets.Method, Inherited = false)]
5 | public class AllEventHandlerAttribute(int priority = 10, bool allowSelfHandling = false) : Attribute
6 | {
7 | public int Priority { get; } = priority;
8 | public bool AllowSelfHandling { get; } = allowSelfHandling;
9 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Infrastructure/EventHandlerAttribute.cs:
--------------------------------------------------------------------------------
1 | // ReSharper disable once CheckNamespace
2 | namespace Aevatar.Core.Abstractions;
3 |
4 | [AttributeUsage(AttributeTargets.Method, Inherited = false)]
5 | public class EventHandlerAttribute(int priority = 100, bool allowSelfHandling = false) : Attribute
6 | {
7 | public int Priority { get; } = priority;
8 | public bool AllowSelfHandling { get; } = allowSelfHandling;
9 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Infrastructure/GAgentAttribute.cs:
--------------------------------------------------------------------------------
1 | using Orleans.Metadata;
2 |
3 | // ReSharper disable once CheckNamespace
4 | namespace Aevatar.Core.Abstractions;
5 |
6 | [AttributeUsage(AttributeTargets.Class, Inherited = true, AllowMultiple = false)]
7 | public sealed class GAgentAttribute : Attribute, IGrainTypeProviderAttribute
8 | {
9 | private readonly string? _ns;
10 | private readonly string? _alias;
11 |
12 | public GAgentAttribute()
13 | {
14 |
15 | }
16 |
17 | public GAgentAttribute(string alias)
18 | {
19 | _alias = alias;
20 | }
21 |
22 | public GAgentAttribute(string alias, string ns)
23 | {
24 | _alias = alias;
25 | _ns = ns;
26 | }
27 |
28 | public GrainType GetGrainType(IServiceProvider services, Type type)
29 | {
30 | if (_alias == null) // Use ctor with 0 parameters.
31 | {
32 | return GrainType.Create($"{type.Namespace}{AevatarCoreConstants.GAgentNamespaceSeparator}{type.Name}");
33 | }
34 |
35 | if (_ns == null)
36 | {
37 | return GrainType.Create($"{type.Namespace}{AevatarCoreConstants.GAgentNamespaceSeparator}{_alias}");
38 | }
39 |
40 | return GrainType.Create($"{_ns}{AevatarCoreConstants.GAgentNamespaceSeparator}{_alias}");
41 | }
42 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Infrastructure/StateHandlerAttribute.cs:
--------------------------------------------------------------------------------
1 | // ReSharper disable once CheckNamespace
2 | namespace Aevatar.Core.Abstractions;
3 |
4 | [AttributeUsage(AttributeTargets.Method, Inherited = false)]
5 | public class StateHandlerAttribute : Attribute;
6 |
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Infrastructure/StateLogEventHandlerAttribute.cs:
--------------------------------------------------------------------------------
1 | // ReSharper disable once CheckNamespace
2 | namespace Aevatar.Core.Abstractions;
3 |
4 | [AttributeUsage(AttributeTargets.Method, Inherited = false)]
5 | public class StateLogEventHandlerAttribute : Attribute;
6 |
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Plugin/AddExistedPluginDto.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions.Plugin;
2 |
3 | [GenerateSerializer]
4 | public class AddExistedPluginDto
5 | {
6 | [Id(0)] public required Guid PluginCodeId { get; set; }
7 | [Id(1)] public required Guid TenantId { get; set; }
8 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Plugin/AddPluginDto.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions.Plugin;
2 |
3 | [GenerateSerializer]
4 | public class AddPluginDto
5 | {
6 | [Id(0)] public required byte[] Code { get; set; } = [];
7 | [Id(1)] public required Guid TenantId { get; set; }
8 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Plugin/IPluginGAgentManager.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 |
3 | namespace Aevatar.Core.Abstractions.Plugin;
4 |
5 | public interface IPluginGAgentManager
6 | {
7 | Task AddPluginAsync(AddPluginDto addPluginDto);
8 | Task> GetPluginsAsync(Guid tenantId);
9 | Task GetPluginsWithDescriptionAsync(Guid tenantId);
10 | Task> GetPluginDescriptions(Guid pluginCodeId);
11 | Task RemovePluginAsync(RemovePluginDto removePluginDto);
12 | Task UpdatePluginAsync(UpdatePluginDto updatePluginDto);
13 | Task AddExistedPluginAsync(AddExistedPluginDto addExistedPluginDto);
14 | Task> GetPluginAssembliesAsync(Guid tenantId);
15 | Task> GetCurrentTenantPluginAssembliesAsync();
16 | ///
17 | /// Query plugin DLL load status for this startup.
18 | ///
19 | /// Tenant ID
20 | /// Dictionary: key is DLL name, value is load status and error reason if failed
21 | Task> GetPluginLoadStatusAsync(Guid? tenantId = null);
22 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Plugin/PluginLoadStatus.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions.Plugin;
2 |
3 | ///
4 | /// Plugin DLL load status information.
5 | ///
6 | public class PluginLoadStatus
7 | {
8 | ///
9 | /// Load status: Success or Failed.
10 | ///
11 | public LoadStatus Status { get; set; }
12 |
13 | ///
14 | /// Failure reason (only set if Status is Failed).
15 | ///
16 | public string? Reason { get; set; }
17 | }
18 |
19 | public enum LoadStatus
20 | {
21 | Unload = -1,
22 | Success = 0,
23 | GAgentDuplicated,
24 | AlreadyLoaded,
25 | Error
26 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Plugin/PluginsInformation.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions.Plugin;
2 |
3 | [GenerateSerializer]
4 | public class PluginsInformation
5 | {
6 | ///
7 | /// PluginCodeId -> Description.
8 | ///
9 | [Id(0)]
10 | public Dictionary> Value { get; set; } = new();
11 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Plugin/RemovePluginDto.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions.Plugin;
2 |
3 | [GenerateSerializer]
4 | public class RemovePluginDto
5 | {
6 | [Id(0)] public required Guid TenantId { get; set; }
7 | [Id(1)] public required Guid PluginCodeId { get; set; }
8 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Plugin/UpdatePluginDto.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions.Plugin;
2 |
3 | [GenerateSerializer]
4 | public class UpdatePluginDto
5 | {
6 | [Id(0)] public required Guid TenantId { get; set; }
7 | [Id(1)] public required Guid PluginCodeId { get; set; }
8 | [Id(2)] public required byte[] Code { get; set; }
9 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/Projections/IProjectionGrain.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions.Projections;
2 |
3 | public interface IProjectionGrain : IGrainWithGuidKey
4 | where TState : StateBase, new()
5 | {
6 | Task ActivateAsync();
7 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/StateBase.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions;
2 |
3 | [GenerateSerializer]
4 | public abstract class StateBase
5 | {
6 | [Id(0)] public List Children { get; set; } = [];
7 | [Id(1)] public GrainId? Parent { get; set; }
8 | [Id(2)] public string? GAgentCreator { get; set; }
9 |
10 | public void Apply(StateLogEventBase @stateLogEvent)
11 | {
12 | // Just to avoid exception on GAgentBase.TransitionState.
13 | }
14 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/StateLogEventBase.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions;
2 |
3 | [GenerateSerializer]
4 | public abstract class StateLogEventBase
5 | {
6 | [Id(0)] public virtual Guid Id { get; set; }
7 | [Id(1)] public DateTime Ctime { get; set; }
8 | }
9 |
10 | [GenerateSerializer]
11 | public abstract class StateLogEventBase : StateLogEventBase
12 | where T:StateLogEventBase;
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/StateWrapper.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions;
2 |
3 | [GenerateSerializer]
4 | public class StateWrapper(GrainId grainId, T state, int version) : StateWrapperBase
5 | where T : StateBase
6 | {
7 | [Id(0)] public GrainId GrainId { get; private set; } = grainId;
8 | [Id(1)] public T State { get; private set; } = state;
9 | [Id(2)] public int Version { get; private set; } = version;
10 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/StateWrapperBase.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core.Abstractions;
2 |
3 | [GenerateSerializer]
4 | public abstract class StateWrapperBase;
--------------------------------------------------------------------------------
/src/Aevatar.Core.Abstractions/SyncWorker/IAevatarSyncWorker.cs:
--------------------------------------------------------------------------------
1 | using Orleans.Streams;
2 | using Orleans.SyncWork;
3 |
4 | namespace Aevatar.Core.Abstractions.SyncWorker;
5 |
6 | public interface IAevatarSyncWorker : ISyncWorker, IGrainWithStringKey
7 | where TRequest : EventBase
8 | where TResponse : EventBase
9 | {
10 | Task SetLongRunTaskAsync(IAsyncStream callbackStream);
11 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core/Aevatar.Core.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | $(DefaultTargetFramework)
5 | enable
6 | enable
7 | Dependency
8 | Aevatar.Core
9 | aevatar Framework
10 | AElf
11 | A distributed AI agent-based framework built on Microsoft Orleans for building scalable event-sourced applications.
12 | agent
13 | https://github.com/aevatarAI/aevatar-framework
14 | git
15 | https://github.com/aevatarAI/aevatar-framework
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
--------------------------------------------------------------------------------
/src/Aevatar.Core/AevatarGAgentConstants.cs:
--------------------------------------------------------------------------------
1 | namespace Aevatar.Core;
2 |
3 | public static class AevatarGAgentConstants
4 | {
5 | public const string EventHandlerDefaultMethodName = "HandleEventAsync";
6 | public const string StateHandlerDefaultMethodName = "HandleStateAsync";
7 | public const string ConfigDefaultMethodName = "PerformConfigAsync";
8 | public const string ForwardEventMethodName = "ForwardEventAsync";
9 | public const int MaxSyncWorkConcurrency = 4;
10 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core/AsyncTaskRunner.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.Logging;
2 |
3 | namespace Aevatar.Core;
4 |
5 | public static class AsyncTaskRunner
6 | {
7 | public static void RunSafely(Func taskFactory, ILogger logger)
8 | {
9 | Task.Run(async () =>
10 | {
11 | try
12 | {
13 | await taskFactory().ConfigureAwait(false);
14 | }
15 | catch (Exception ex)
16 | {
17 | logger.LogCritical(ex, "Unhandled async exception");
18 | }
19 | });
20 | }
21 | }
--------------------------------------------------------------------------------
/src/Aevatar.Core/EventWrapperHelper.cs:
--------------------------------------------------------------------------------
1 | using Aevatar.Core.Abstractions;
2 |
3 | namespace Aevatar.Core;
4 |
5 | ///
6 | /// Utility methods for working with EventWrapper objects
7 | ///
8 | internal static class EventWrapperHelper
9 | {
10 | ///
11 | /// Extracts a property from an EventWrapper using reflection
12 | ///
13 | public static T? GetProperty(EventWrapperBase wrapper, string propertyName) where T : class
14 | {
15 | return wrapper.GetType().GetProperty(propertyName)?.GetValue(wrapper) as T;
16 | }
17 |
18 | ///
19 | /// Extracts common properties from an EventWrapper
20 | ///
21 | public static (EventBase eventType, string? eventId) ExtractProperties(EventWrapperBase wrapper)
22 | {
23 | var eventType = GetProperty(wrapper, nameof(EventWrapper.Event))!;
24 | var eventId = GetProperty