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

Make ServiceType can be extended without modify package/core #2315

Open
fibonacci998 opened this issue Jan 15, 2025 · 3 comments
Open

Make ServiceType can be extended without modify package/core #2315

fibonacci998 opened this issue Jan 15, 2025 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@fibonacci998
Copy link

Is your feature request related to a problem? Please describe.

Currently, when someone want to create a new service, they must add new type as string to enum ServiceType in packages/core/src/types.

Describe the solution you'd like

I want to add new service type in my new plugin without modify enum ServiceType in package core. In some case they import packages/cores from node-modules, so they can not edit that enum

Describe alternatives you've considered

May be remove that enum, so that getService function in packages/core/src/runtime.ts we can use

getService<T extends Service>(service: string)

instead of

getService<T extends Service>(service: ServiceType)
@fibonacci998 fibonacci998 added the enhancement New feature or request label Jan 15, 2025
@tcm390 tcm390 self-assigned this Jan 15, 2025
@tcm390
Copy link
Collaborator

tcm390 commented Jan 16, 2025

hi @fibonacci998 I'm aware of this issue as well and have outlined my thoughts in #2348. So for custom services (not part of plugin-node), we want to avoid touching the core code or core types. Instead, we can let each custom service register whichever methods it needs, and then external code can invoke those methods through a function in runtime.ts.

For example, if I need to call the web search service from the image plugin, I could do:

const latestNews = await runtime.callServiceMethod(
            "web_search",
            "search",
            "latest news on AI Agents",
            {limit: 5, includeImages: true}
); 

What do you think of this approach?

@fibonacci998
Copy link
Author

That's ok for me, all I need to do is avoiding edit packages/core when create new service @tcm390

@tcm390
Copy link
Collaborator

tcm390 commented Jan 16, 2025

Sorry I pasted the wrong PR: here is the correct one: #2348

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

No branches or pull requests

2 participants