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/support agent types #708

Merged
merged 4 commits into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2231,7 +2231,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

> 2 May 2022

- add aave service agreement to ddo when creating nft721 asset [`#248`](https://github.com/nevermined-io/sdk-js/pull/248)
- add aave service agreement to ddo when creating nft721 asset [`#248`](https://github.com/nevermined-io/sdk-js/pull/248)
- Adding v0.19.21 Changelog updates [`c93cdc5`](https://github.com/nevermined-io/sdk-js/commit/c93cdc55f139a43db4130ccb0f80924d2645a931)

#### [v0.19.21](https://github.com/nevermined-io/sdk-js/compare/v0.19.20...v0.19.21)
Expand Down Expand Up @@ -2494,7 +2494,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

> 18 January 2022

- Removing not used parameter [`#186`](https://github.com/nevermined-io/sdk-js/pull/186)
- Removing not used parameter [`#186`](https://github.com/nevermined-io/sdk-js/pull/186)
- [wip] Create agreement+pay in one transaction [`#183`](https://github.com/nevermined-io/sdk-js/pull/183)
- Adapting to contracts `v1.3.3` [`#177`](https://github.com/nevermined-io/sdk-js/pull/177)
- Adding v0.17.2 Changelog updates [`5eddda4`](https://github.com/nevermined-io/sdk-js/commit/5eddda43954e013e6e6f7344c9a877d801aacb5c)
Expand Down Expand Up @@ -3000,7 +3000,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Feature/sync develop [`#268`](https://github.com/nevermined-io/sdk-js/pull/268)
- Quick fix for non-eip1559 networks [`#266`](https://github.com/nevermined-io/sdk-js/pull/266)
- integrate Permissions and refactor search query [`#264`](https://github.com/nevermined-io/sdk-js/pull/264)
- add aave service agreement to ddo when creating nft721 asset [`#248`](https://github.com/nevermined-io/sdk-js/pull/248)
- add aave service agreement to ddo when creating nft721 asset [`#248`](https://github.com/nevermined-io/sdk-js/pull/248)
- Get the keeper version from the artifacts instead of package version [`#244`](https://github.com/nevermined-io/sdk-js/pull/244)
- replace `metadata-api` url by `marketplace-api` and sort type [`#243`](https://github.com/nevermined-io/sdk-js/pull/243)
- fixing issues with BigNumbers [`#246`](https://github.com/nevermined-io/sdk-js/pull/246)
Expand Down Expand Up @@ -3039,7 +3039,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- Feature/190 add did to sec markets [`#191`](https://github.com/nevermined-io/sdk-js/pull/191)
- Adding utility methods for getting nft token uri [`#189`](https://github.com/nevermined-io/sdk-js/pull/189)
- Lint ... [`#187`](https://github.com/nevermined-io/sdk-js/pull/187)
- Removing not used parameter [`#186`](https://github.com/nevermined-io/sdk-js/pull/186)
- Removing not used parameter [`#186`](https://github.com/nevermined-io/sdk-js/pull/186)
- [wip] Create agreement+pay in one transaction [`#183`](https://github.com/nevermined-io/sdk-js/pull/183)
- Adapting to contracts `v1.3.3` [`#177`](https://github.com/nevermined-io/sdk-js/pull/177)
- Correct typo in route [`#184`](https://github.com/nevermined-io/sdk-js/pull/184)
Expand Down
17 changes: 17 additions & 0 deletions integration/nevermined/SearchAsset.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,21 @@ describe('Search Asset', () => {
nevermined.search.byDID(ddo.id).then((ddo) => assert.instanceOf(ddo, DDO))
})
})

it('should be able to get assets by type', async () => {
const { results: ddos } = await neverminedOffline.search.byType('dataset')
assert.equal(ddos.length, 5)

const { results: ddosWithTextFilter } = await neverminedOffline.search.byType(
'dataset',
'TestAsset',
)
assert.equal(ddosWithTextFilter.length, 4)

const { results: ddosServices } = await neverminedOffline.search.byType('service')
assert.equal(ddosServices.length, 2)

const { results: agent } = await neverminedOffline.search.byType('agent')
assert.equal(agent.length, 0)
})
})
3 changes: 2 additions & 1 deletion src/nevermined/api/RegistryBaseApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ export abstract class RegistryBaseApi extends Instantiable {

if (
assetAttributes.metadata.main.type === 'service' ||
assetAttributes.metadata.main.type === 'assistant'
assetAttributes.metadata.main.type === 'assistant' ||
assetAttributes.metadata.main.type === 'agent'
) {
const encryptedServiceAttributesResponse = await this.nevermined.services.node.encrypt(
ddo.id,
Expand Down
68 changes: 67 additions & 1 deletion src/nevermined/api/SearchApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Instantiable, InstantiableConfig } from '../../Instantiable.abstract'
import { DDO } from '../../ddo/DDO'
import { NvmAccount } from '../../models/NvmAccount'
import { QueryResult } from '../../services/metadata/MetadataService'
import { ServiceType, Service } from '../../types/DDOTypes'
import { MetaDataMain, Service, ServiceType } from '../../types/DDOTypes'
import { EventOptions } from '../../types/EventTypes'
import { NeverminedNFT1155Type, NeverminedNFT721Type } from '../../types/GeneralTypes'
import { SearchQuery } from '../../types/MetadataTypes'
Expand Down Expand Up @@ -787,4 +787,70 @@ export class SearchApi extends Instantiable {
appId,
)
}

public async byType(
assetType: MetaDataMain['type'] = 'agent',
text?: string,
offset = 100,
page = 1,
appId?: string,
) {
const mustArray: unknown[] = []
mustArray.push(assetTypeFilter(assetType))
if (text) {
mustArray.push(textFilter(text))
}

return this.query({
query: {
bool: {
must: mustArray,
},
},
sort: {
created: 'desc',
},
page: page,
offset: offset,
appId,
})
}
}

export const assetTypeFilter = (assetType: MetaDataMain['type']) => {
const filter: { [field: string]: unknown }[] = [
{
match: { 'service.type': 'metadata' },
},
{
match: {
'service.attributes.main.nftType': 'nft1155-credit',
},
},
]
filter.push({
match: {
'service.attributes.main.type': assetType,
},
})

return {
nested: {
path: ['service'],
query: {
bool: {
filter,
},
},
},
}
}

export const textFilter = (searchInputText = '') => ({
nested: {
path: ['service'],
query: {
query_string: { query: `*${searchInputText}*`, fields: ['service.attributes.main.name'] },
},
},
})
3 changes: 2 additions & 1 deletion src/types/DDOTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ export interface MetaDataMain {

/**
* Type of the Asset. Helps to filter by the type of asset,
* initially ("dataset", "algorithm", "compute", "workflow", "model", "file", "subscription", "other").
* initially ("dataset", "algorithm", "compute", "workflow", "model", "file", "subscription", "other", "agent").
* @example "dataset"
*/
type:
Expand All @@ -264,6 +264,7 @@ export interface MetaDataMain {
| 'file'
| 'other'
| 'assistant'
| 'agent'

/**
* Sub type asssociated to the main type of the asset. This subtype is open so final users are not restricted to use anything they need.
Expand Down
Loading