Skip to content

Commit

Permalink
Merge pull request #708 from nevermined-io/feat/support-agent-types
Browse files Browse the repository at this point in the history
Feat/support agent types
  • Loading branch information
eruizgar91 authored Aug 27, 2024
2 parents 64997aa + 5331c58 commit 32b98fe
Show file tree
Hide file tree
Showing 9 changed files with 115 additions and 9 deletions.
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
2 changes: 2 additions & 0 deletions integration/external/Zerodev.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,8 @@ describe('Nevermined sdk with zerodev', () => {
contractAddress, // DIDRegistry address
'0x1c52ed414EDd1bCC20Ea670d42289e8bFC03C095', // Sales Template address
'0x75faf114eafb1BDbe2F0316DF893fd58CE46AA4d', // ERC20 address
'0x1bcA156f746C6Eb8b18d61654293e2Fc5b653fF5', // NFT1155 address
'0x1bcA156f746C6Eb8b18d61654293e2Fc5b653fF5',
)
const sessionKey = await createSessionKey(owner, publicClient, permissions)
assert.isDefined(sessionKey)
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)
})
})
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nevermined-io/sdk",
"version": "3.0.27",
"version": "3.0.28",
"description": "Javascript SDK for connecting with Nevermined Data Platform ",
"main": "./dist/node/sdk.js",
"typings": "./dist/node/sdk.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion scripts/download-artifacts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fi

REPO_URL=https://artifacts.nevermined.network
declare -A NETWORKS_MAP
NETWORKS_MAP=( ["mainnet"]="1" ["rinkeby"]="4" ["optimism"]="10" ["kovan"]="42" ["gnosis"]="100" ["matic"]="137" ["base"]="8453" ["mumbai"]="80001" ["celo-alfajores"]="44787" ["celo"]="42220" ["aurora"]="1313161554" ["aurora-testnet"]="1313161555" ["arbitrum-one"]="42161" ["arbitrum-goerli"]="421613" ["arbitrum-sepolia"]="421614" )
NETWORKS_MAP=( ["mainnet"]="1" ["rinkeby"]="4" ["optimism"]="10" ["kovan"]="42" ["gnosis"]="100" ["matic"]="137" ["peaq"]="3338" ["base"]="8453" ["mumbai"]="80001" ["celo-alfajores"]="44787" ["celo"]="42220" ["aurora"]="1313161554" ["aurora-testnet"]="1313161555" ["arbitrum-one"]="42161" ["arbitrum-goerli"]="421613" ["arbitrum-sepolia"]="421614" )

SCRIPT_DIR=$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd)
UNPACK_DIR="$SCRIPT_DIR/../artifacts"
Expand Down
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
19 changes: 19 additions & 0 deletions src/utils/Network.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ export async function getNetworkName(networkId: number): Promise<string> {
return 'geth-localnet'
case 3141:
return 'hyperspace'
case 3338:
return 'peaq'
case 8453:
return 'base'
case 10200:
Expand Down Expand Up @@ -108,6 +110,8 @@ export function isTestnet(networkId: number): boolean {
return true
case 3141:
return true
case 3338:
return false
case 8453:
return false
case 10200:
Expand Down Expand Up @@ -155,6 +159,21 @@ export function getChain(networkId: number | undefined): Chain {
return gnosis
case 137:
return polygon
case 3338:
return defineChain({
id: networkId,
name: 'peaq-network',
nativeCurrency: {
name: 'Peaq',
symbol: 'PEAQ',
decimals: 18,
},
rpcUrls: {
default: {
http: ['https://evm.peaq.network'],
},
},
})
case 8453:
return base as Chain
case 42161:
Expand Down

0 comments on commit 32b98fe

Please sign in to comment.