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: add Agent Manager to utils package #731

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

AntonioVentilii-DFINITY
Copy link
Contributor

@AntonioVentilii-DFINITY AntonioVentilii-DFINITY commented Oct 11, 2024

Motivation

It is a simple but useful class to manage multiple HTTP agents associated with identities.

Credits

The original scripts were created by @peterpeterparker in the OISY repo. This is just a transposition to a re-usable utility.

Changes

New AgentManager class with:

  • create method: static constructor.
  • createAgent method: as the name suggests, it creates a new HTTP but do not cache it.
  • getAgent method: it fetches the HTTP agent among the cached, and if does note exists, it creates it and cache it.
  • clearAgents method: clean slate.

Tests

I created a few tests for the few usecases.

Todos

  • Maybe add more mocked identity, to check for concurrent multiple agents.

Copy link
Contributor

github-actions bot commented Oct 11, 2024

size-limit report 📦

Path Size
@dfinity/ckbtc 7.99 KB (0%)
@dfinity/cketh 3.53 KB (0%)
@dfinity/cmc 1.36 KB (0%)
@dfinity/ledger-icrc 4.17 KB (0%)
@dfinity/ledger-icp 15.43 KB (0%)
@dfinity/nns 36.23 KB (0%)
@dfinity/nns-proto 140.98 KB (0%)
@dfinity/sns 15.87 KB (0%)
@dfinity/utils 4.64 KB (+3.02% 🔺)
@dfinity/ic-management 3.01 KB (0%)

@AntonioVentilii-DFINITY AntonioVentilii-DFINITY marked this pull request as ready for review October 12, 2024 00:14
Copy link
Member

@peterpeterparker peterpeterparker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool idea!

},
}));

jest.mock("./nullish.utils", () => ({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to mock this?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apparently yes... when i ran the test without, it said that it couldn't find it... I will re-try and let you know

packages/utils/src/utils/agent.utils.ts Show resolved Hide resolved
@@ -42,3 +42,102 @@ export const createAgent = async ({
shouldFetchRootKey: fetchRootKey,
});
};

export interface AgentManagerConfig {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In another PR, we should extract an interface for all the paramters of @dfinity/utils.createAgent and this interface become a subtype of this new interface.

export type AgentManagerConfig = Omit<NewInterface, 'identity'>

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah! right! shall i do it before this one? i think it would be a fast one

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, go for it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

packages/utils/src/utils/agent.utils.ts Outdated Show resolved Hide resolved
packages/utils/src/utils/agent.utils.ts Outdated Show resolved Hide resolved
@peterpeterparker
Copy link
Member

In addition:

  • Can you add an entry in CHANGELOG.md
  • The new module should be exposed in packages/utils/src/index.ts otherwise it cannot be consumed

@AntonioVentilii-DFINITY
Copy link
Contributor Author

@peterpeterparker

  • for the CHANGELOG how do you do it usually? just add on top of the current one?
  • I see that agent.utils is already there, right?

@peterpeterparker
Copy link
Member

for the CHANGELOG how do you do it usually? just add on top of the current one?

Yes at the top, in # Next. You can add a new section ## Features if there are none yet.

I see that agent.utils is already there, right?

Nvm, my bad. Assumed it was a brand new separate module. All good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants