Skip to content

Commit

Permalink
Update dsn cfg with network id - clean coding
Browse files Browse the repository at this point in the history
  • Loading branch information
Xm0onh committed Feb 3, 2025
1 parent 7820686 commit fa0ebef
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 13 deletions.
1 change: 1 addition & 0 deletions characters/character.example/config/config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ twitter:

auto_drive:
upload: false
network: 'taurus' # or 'mainnet'

llm:
nodes:
Expand Down
7 changes: 7 additions & 0 deletions src/agents/tools/utils/dsn/api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { createAutoDriveApi } from '@autonomys/auto-drive';
import { config } from '../../../../config/index.js';

export const dsnApi = createAutoDriveApi({
apiKey: config.autoDriveConfig.AUTO_DRIVE_API_KEY || '',
network: config.autoDriveConfig.AUTO_DRIVE_NETWORK,
});
11 changes: 3 additions & 8 deletions src/agents/tools/utils/dsn/dsnDownload.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { createAutoDriveApi, downloadFile } from '@autonomys/auto-drive';
import { NetworkId } from '@autonomys/auto-utils';
import { config } from '../../../../config/index.js';
import { downloadFile } from '@autonomys/auto-drive';
import { dsnApi } from './api.js';
import { createLogger } from '../../../../utils/logger.js';
import { withRetry } from './retry.js';

Expand All @@ -16,12 +15,8 @@ interface BaseMemory {
export const download = async (cid: string): Promise<BaseMemory> => {
return withRetry(
async () => {
const api = createAutoDriveApi({
apiKey: config.autoDriveConfig.AUTO_DRIVE_API_KEY || '',
network: NetworkId.TAURUS,
});
logger.info(`Downloading file: ${cid}`);
const stream = await downloadFile(api, cid);
const stream = await downloadFile(dsnApi, cid);

const chunks: Uint8Array[] = [];
for await (const chunk of stream) {
Expand Down
6 changes: 1 addition & 5 deletions src/agents/tools/utils/dsn/dsnUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ import { agentVersion, config } from '../../../../config/index.js';
import { signMessage, wallet } from '../blockchain/agentWallet.js';
import { getLastMemoryCid, setLastMemoryHash } from '../blockchain/agentMemoryContract.js';
import { withRetry } from './retry.js';
import { NetworkId } from '@autonomys/auto-utils';
import { dsnApi } from './api.js';

const logger = createLogger('dsn-upload-tool');
const dsnApi = createAutoDriveApi({
apiKey: config.autoDriveConfig.AUTO_DRIVE_API_KEY || '',
network: NetworkId.TAURUS,
});

let currentNonce = await wallet.getNonce();

Expand Down
1 change: 1 addition & 0 deletions src/config/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ export const config = (() => {
AUTO_DRIVE_API_KEY: process.env.AUTO_DRIVE_API_KEY,
AUTO_DRIVE_ENCRYPTION_PASSWORD: process.env.AUTO_DRIVE_ENCRYPTION_PASSWORD,
AUTO_DRIVE_UPLOAD: yamlConfig.auto_drive.upload ?? false,
AUTO_DRIVE_NETWORK: yamlConfig.auto_drive.network,
},
blockchainConfig: {
RPC_URL: process.env.RPC_URL || undefined,
Expand Down
5 changes: 5 additions & 0 deletions src/config/schema.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { z } from 'zod';
import { LLMProvider } from '../services/llm/types.js';
import { NetworkId } from '@autonomys/auto-utils';

const twitterConfigSchema = z.object({
USERNAME: z.string().min(1, 'Twitter username is required'),
Expand Down Expand Up @@ -98,6 +99,10 @@ const autoDriveConfigSchema = z.object({
AUTO_DRIVE_API_KEY: z.string().optional(),
AUTO_DRIVE_ENCRYPTION_PASSWORD: z.string().optional(),
AUTO_DRIVE_UPLOAD: z.boolean(),
AUTO_DRIVE_NETWORK: z
.enum(['mainnet', 'taurus'])
.transform(val => NetworkId[val.toUpperCase() as 'MAINNET' | 'TAURUS'])
.default('taurus'),
});

const blockchainConfigSchema = z.object({
Expand Down

0 comments on commit fa0ebef

Please sign in to comment.