diff --git a/.changeset/new-chairs-provide.md b/.changeset/new-chairs-provide.md new file mode 100644 index 00000000..3cfe31f2 --- /dev/null +++ b/.changeset/new-chairs-provide.md @@ -0,0 +1,6 @@ +--- +"@effectai/sdk": patch +--- + +- add symlinks for license and README +- fix createBatch types diff --git a/LICENSE b/LICENSE deleted file mode 100644 index a1594b3e..00000000 --- a/LICENSE +++ /dev/null @@ -1,21 +0,0 @@ -MIT License - -Copyright (c) 2021 Effect Network - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. diff --git a/LICENSE b/LICENSE new file mode 120000 index 00000000..da348fc8 --- /dev/null +++ b/LICENSE @@ -0,0 +1 @@ +src/LICENSE \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 7eddf7fb..00000000 --- a/README.md +++ /dev/null @@ -1,28 +0,0 @@ -# ๐Ÿ”ฅ @effectai/effect-js - -

- -Effect-js is a free and open-source library powered by blockchain technology that enables developers to collect and enrich their data-sets in a transparent way. - -## ๐Ÿ—’๏ธ Documentation -For full documentation, visit https://docs.effect.ai - -## ๐Ÿ™‹ Contributing -If you want to add contributions to this repository, please follow the instructions in [contributing.md](CONTRIBUTING.md). - -## ๐Ÿ  Local Development -Follow the docs to Set Up Your Local Development Environment to contribute to the framework and documentation. - -### Testing - -#### `.env` - -To run the tests locally, you will need to provide an EOS account that can be used to make transactions on your behalf. -Copy the `.env.example` file to `.env.testnet` and fill in the required parameters. - -#### PowerUp - -You might need to power up your account, either by adding some Native Token to your account or EFX tokens. -You can powerup your account at the following link: https://monitor4.jungletestnet.io/ - - diff --git a/README.md b/README.md new file mode 120000 index 00000000..351df1da --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +src/README.md \ No newline at end of file diff --git a/bun.lockb b/bun.lockb index 6d676796..69b420d5 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/docs/package.json b/docs/package.json index b5f98582..4fe4bc40 100644 --- a/docs/package.json +++ b/docs/package.json @@ -9,6 +9,9 @@ }, "dependencies": {}, "devDependencies": { + "@wharfkit/wallet-plugin-anchor": "^1.0.0", + "@wharfkit/web-renderer": "^1.0.3", + "@wharfkit/wallet-plugin-privatekey": "1.1.0", "react": "^18.2.0", "react-dom": "^18.2.0", "vocs": "^1.0.0-alpha.46", diff --git a/docs/pages/docs/authentication.mdx b/docs/pages/docs/authentication.mdx new file mode 100644 index 00000000..3d4cea5b --- /dev/null +++ b/docs/pages/docs/authentication.mdx @@ -0,0 +1,62 @@ +# Authentication +Some functions in the Effect AI SDK require authentication with the EOS blockchain. This is done by passing a session object to the createClient function. +A session can be established by either [private key](https://github.com/wharfkit/wallet-plugin-privatekey) or [wallet plugins](https://wharfkit.com/plugins?tag=wallet-plugin). + +### Private Key +To authenticate using a private key we recommend using the [wallet-plugin-privatekey](https://github.com/wharfkit/wallet-plugin-privatekey) +And passing it through a session to the `createClient` function. + +```ts twoslash +import { + createClient, + eos, + Session +} from "@effectai/sdk"; + +import { WalletPluginPrivateKey } from '@wharfkit/wallet-plugin-privatekey' + +const session = new Session({ + chain: eos, + walletPlugin: new WalletPluginPrivateKey( + '5Jtoxgny5tT7NiNFp1MLogviuPJ9NniWjnU4wKzaX4t7pL4kJ8s', + ), +}) + +const client = await createClient({ session }) +``` + +### Wallet Plugin +It's also possible to authenticate using a wallet plugin, for example using the [wallet-plugin-anchor](https://github.com/wharfkit/wallet-plugin-anchor) +This one is a bit more complicated and requires two additional packages: [`@wharfkit/session`](https://github.com/wharfkit/session) and [`@wharfkit/web-renderer`](https://github.com/wharfkit/web-renderer) + +```ts twoslash +import { + createClient, + eos, +} from "@effectai/sdk"; + +import { SessionKit } from "@wharfkit/session"; +import { WebRenderer } from "@wharfkit/web-renderer"; +import { WalletPluginAnchor } from "@wharfkit/wallet-plugin-anchor"; + +const webRenderer = new WebRenderer(); + +const sessionKit = new SessionKit( + { + appName: "Effect Network", + chains: [eos], + ui: webRenderer, + walletPlugins: [ + new WalletPluginAnchor(), + ], + }, + ) + +const session = await sessionKit.restore(); + +if(!session) { + throw new Error('Session not found') +} + +const client = await createClient({ session }) +``` \ No newline at end of file diff --git a/docs/pages/docs/collecting-data/adding-tasks.mdx b/docs/pages/docs/collecting-data/adding-tasks.mdx index 4c6e43a2..998edd82 100644 --- a/docs/pages/docs/collecting-data/adding-tasks.mdx +++ b/docs/pages/docs/collecting-data/adding-tasks.mdx @@ -1,30 +1,44 @@ ## Adding tasks -Adding tasks to a campaign is done through batches batches are a collection of tasks that are added to a campaign. Each batch can contain multiple tasks. -Let's start by creating a batch with 3 tasks to our newly created image classification campaign. +Adding tasks to a campaign is done through adding batches. -```ts [example.ts] -import { createBatch } from '@effectai/effect-js' +Batches are a collection of tasks that are added to a campaign. Each batch can contain multiple tasks. +Let's start by creating a batch with 3 tasks to our newly created image classification campaign. +```ts twoslash +// [!include ~/snippets/getting-started/getting-started-auth.ts] +if(!client.session) { + throw new Error('No session found') +} const { actor } = client.session +if(!actor) { + throw new Error('No actor found') +} +//---cut--- +import { createBatch } from '@effectai/sdk' + const batch = await createBatch({ client, - batch: { - campaign_id: '<..>', // the id of the campaign - repetitions: 1 // number of times each task should be repeated - payer: actor // the actor that will pay the workers for the tasks - } - data: [ + // The campaign id to which the batch should be added + campaignId : 1, + // The number of times each task in the batch should be repeated + repetitions: 1, + // The reward for each task in the batch + reward: 3, + // The template placeholders for each task in the batch + taskData : [ { - image: 'https://example.com/image.jpg', //task 1 image placeholder + ipfs_url: 'https://example.com/image.jpg', //task 1 image placeholder }, { - image: 'https://example.com/image2.jpg', //task 2 image placeholder + ipfs_url: 'https://example.com/image2.jpg', //task 2 image placeholder }, { - image: 'https://example.com/image3.jpg', // task 3 image placeholder + ipfs_url: 'https://example.com/image3.jpg', // task 3 image placeholder } - ] + ], }) -``` \ No newline at end of file + +``` + diff --git a/docs/pages/docs/collecting-data/collecting-results.mdx b/docs/pages/docs/collecting-data/collecting-results.mdx new file mode 100644 index 00000000..4b86553c --- /dev/null +++ b/docs/pages/docs/collecting-data/collecting-results.mdx @@ -0,0 +1,3 @@ +## Collecting Results + +TODO:: \ No newline at end of file diff --git a/docs/pages/docs/glossary/client-options.mdx b/docs/pages/docs/glossary/client-options.mdx index d42ce0e8..b6752018 100644 --- a/docs/pages/docs/glossary/client-options.mdx +++ b/docs/pages/docs/glossary/client-options.mdx @@ -17,7 +17,7 @@ As we can see, the ClientOpts interface has three optional properties: This property is used to set the cache duration for the IPFS data. The default value is 600_000 milliseconds; 10 minutes. -## `fetchProfider` +## `fetchProvider` This property is used to set the fetch provider. This is needed because of the different runtimes availalbe to Java Script. @@ -45,6 +45,5 @@ const client = createClient({ }) ``` -# TODO: This needs to be changed when the `dev` branch is merged into main. [See Type](https://github.com/effectai/effect-js/blob/main/src/client.ts) diff --git a/docs/pages/index.mdx b/docs/pages/index.mdx index 68ba2a6d..bdbbd247 100644 --- a/docs/pages/index.mdx +++ b/docs/pages/index.mdx @@ -36,15 +36,15 @@ style={{ :::code-group ```bash [npm] - npm i @effectai/effect-js + npm i @effectai/sdk ``` ```bash [pnpm] - pnpm i @effectai/effect-js + pnpm i @effectai/sdk ``` ```bash [bun] - bun i @effectai/effect-js + bun i @effectai/sdk ``` ::: @@ -69,7 +69,7 @@ style={{ coverage
- 0% + 63.34%
diff --git a/docs/public/.nojekyll b/docs/public/.nojekyll new file mode 100644 index 00000000..e69de29b diff --git a/docs/public/CNAME b/docs/public/CNAME new file mode 100644 index 00000000..ac776a72 --- /dev/null +++ b/docs/public/CNAME @@ -0,0 +1 @@ +docs.effect.ai \ No newline at end of file diff --git a/docs/sidebar.ts b/docs/sidebar.ts index b810854f..f0bbbda5 100644 --- a/docs/sidebar.ts +++ b/docs/sidebar.ts @@ -7,6 +7,7 @@ export const sidebar = { items: [ { text: "Why Effect AI", link: "/docs/introduction" }, { text: "Getting Started", link: "/docs/getting-started" }, + { text: "Authentication", link: "/docs/authentication" }, ], }, { @@ -25,6 +26,10 @@ export const sidebar = { text: "Adding Tasks to a Campaign", link: "/docs/collecting-data/adding-tasks", }, + { + text: "Collecting results", + link: "/docs/collecting-data/collecting-results", + }, ], }, { diff --git a/docs/snippets/getting-started/getting-started-auth.ts b/docs/snippets/getting-started/getting-started-auth.ts index da0b77fa..56a7c727 100644 --- a/docs/snippets/getting-started/getting-started-auth.ts +++ b/docs/snippets/getting-started/getting-started-auth.ts @@ -16,9 +16,4 @@ const session = new Session({ }); // Create client to make authenticated transactions -const authClient = await createClient({ session }); - -// Create a new Effect Account -const account = "efxforce1112"; -const response = await createVAccount({ client: authClient, account }); -console.log(response); // => Transaction Details +const client = await createClient({ session }); diff --git a/docs/vocs.config.tsx b/docs/vocs.config.tsx index cf807b5d..39e851ec 100644 --- a/docs/vocs.config.tsx +++ b/docs/vocs.config.tsx @@ -3,8 +3,8 @@ import pkg from "../src/package.json"; import { sidebar } from "./sidebar"; export default defineConfig({ - baseUrl: "https://effect.ai", - title: "Effect JS", + baseUrl: "https://docs.effect.ai", + title: "Effect SDK Docs", titleTemplate: "%s ยท Effect.AI", description: "Effect-js is a free and open-source library powered by blockchain technology that enables developers to collect and enrich their data-sets in a transparent way.", diff --git a/package.json b/package.json index 552f9201..0b3244ca 100644 --- a/package.json +++ b/package.json @@ -16,7 +16,8 @@ "changeset:version": "changeset version && bun install --frozen-lockfile && bun scripts/updateVersion.ts", "docs:dev": "cd docs && bun run dev", "docs:build": "cd docs && bun run build", - "docs:preview": "cd docs && bun run preview" + "docs:preview": "cd docs && bun run preview", + "link": "cd src && bun link" }, "devDependencies": { "@biomejs/biome": "1.7.0", diff --git a/src/LICENSE b/src/LICENSE new file mode 100644 index 00000000..a1594b3e --- /dev/null +++ b/src/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Effect Network + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/src/README.md b/src/README.md index 9cea49a3..7643ab8e 100644 --- a/src/README.md +++ b/src/README.md @@ -1,15 +1,28 @@ -# @effectai/sdk +# ๐Ÿ”ฅ The @effectai/sdk Monorepo -To install dependencies: +

-```bash -bun install -``` +The @effectai/sdk is a free and open source library for training next-gen transparent AI models. Integrate the SDK into your app and tap into a global, decentralized workforce powered by blockchain technology. -To run: +## ๐Ÿ—’๏ธ Documentation +For full documentation, visit https://docs.effect.ai + +## ๐Ÿ™‹ Contributing +If you want to add contributions to this repository, please follow the instructions in [contributing.md](CONTRIBUTING.md). + +## ๐Ÿ  Local Development +Follow the docs to Set Up Your Local Development Environment to contribute to the framework and documentation. + +### Testing + +#### `.env` + +To run the tests locally, you will need to provide an EOS account that can be used to make transactions on your behalf. +Copy the `.env.example` file to `.env.testnet` and fill in the required parameters. + +#### PowerUp + +You might need to power up your account, either by adding some Native Token to your account or EFX tokens. +You can powerup your account at the following link: https://monitor4.jungletestnet.io/ -```bash -bun run dist/exports/index.js -``` -This project was created using `bun init` in bun v1.1.7. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime. diff --git a/src/actions/ipfs/uploadIpfsResource.ts b/src/actions/ipfs/uploadIpfsResource.ts index 3169aef9..46222226 100644 --- a/src/actions/ipfs/uploadIpfsResource.ts +++ b/src/actions/ipfs/uploadIpfsResource.ts @@ -1,9 +1,9 @@ import type { Client } from "../../client"; -import { Bytes } from "@wharfkit/antelope"; +import { Bytes, Base58 } from "@wharfkit/antelope"; export type UploadIpfsResourceArgs = { client: Client; - data: Record; + data: Record | Record[]; }; export const uploadIpfsResource = async ({ @@ -46,10 +46,5 @@ export const uploadIpfsResource = async ({ }; export const ipfsCIDToHex = (cid: string): string => { - const string = atob(cid); - const array = new Uint8Array(string.length); - for (let i = 0; i < string.length; i++) { - array[i] = string.charCodeAt(i); - } - return Bytes.from(array).hexString; + return Base58.decode(cid).hexString; }; diff --git a/src/actions/tasks/batch/createBatch.ts b/src/actions/tasks/batch/createBatch.ts index 4de4b695..9862b622 100644 --- a/src/actions/tasks/batch/createBatch.ts +++ b/src/actions/tasks/batch/createBatch.ts @@ -84,7 +84,7 @@ export type CreateBatchArgs = { campaignId: number; repetitions: number; reward: number; - taskData: Record; + taskData: Record[]; }; export const createBatch = async ({ diff --git a/src/package.json b/src/package.json index 0fdbcf81..c65d9a36 100644 --- a/src/package.json +++ b/src/package.json @@ -8,7 +8,6 @@ "types": "./dist/exports/index.d.ts", "files": ["dist"], "type": "module", - "repository": { "type": "git", "url": "git+https://github.com/effectai/effect-js.git" @@ -27,7 +26,6 @@ "url": "https://github.com/effectai/effect-js/issues" }, "homepage": "https://github.com/effectai/effect-js#readme", - "devDependencies": { "@types/bun": "latest" },