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

Add prettier to auto-kol/agent #85

Merged
merged 3 commits into from
Dec 24, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
31 changes: 31 additions & 0 deletions .github/workflows/prettier.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Code Formatting Check

on:
pull_request:
branches: [main]
push:
branches: [main]

jobs:
format-check:
name: Prettier Check
runs-on: ubuntu-latest
defaults:
run:
working-directory: auto-kol/agent

steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'yarn'
cache-dependency-path: 'auto-kol/agent/yarn.lock'

- name: Install Dependencies
run: yarn install --frozen-lockfile

- name: Check Formatting
run: yarn prettier --check "src/**/*.ts"
8 changes: 8 additions & 0 deletions auto-kol/agent/.prettierrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export default {
semi: true,
marc-aurele-besner marked this conversation as resolved.
Show resolved Hide resolved
trailingComma: 'all',
singleQuote: true,
printWidth: 100,
tabWidth: 2,
arrowParens: 'avoid',
};
7 changes: 5 additions & 2 deletions auto-kol/agent/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"scripts": {
"build": "tsc",
"start": "node dist/index.js",
"dev": "tsx watch src/index.ts"
"dev": "tsx watch src/index.ts",
"format": "prettier --write \"src/**/*.ts\"",
"format:check": "prettier --check \"src/**/*.ts\""
},
"dependencies": {
"@autonomys/auto-dag-data": "^1.0.12",
Expand Down Expand Up @@ -37,7 +39,8 @@
"@types/express": "4.17.21",
"@types/node": "22.10.0",
"@types/sqlite3": "^3.1.11",
"@types/uuid": "10.0.0",
"@types/uuid": "10.0.0",
"prettier": "^3.2.2",
"tsx": "^4.7.1",
"typescript": "^5.3.3"
}
Expand Down
142 changes: 71 additions & 71 deletions auto-kol/agent/src/abi/memory.ts
Original file line number Diff line number Diff line change
@@ -1,72 +1,72 @@
export const MEMORY_ABI = [
{
"anonymous": false,
"inputs": [
{
"indexed": true,
"internalType": "address",
"name": "agent",
"type": "address"
},
{
"indexed": false,
"internalType": "bytes32",
"name": "hash",
"type": "bytes32"
}
],
"name": "LastMemoryHashSet",
"type": "event"
},
{
"inputs": [
{
"internalType": "address",
"name": "_agent",
"type": "address"
}
],
"name": "getLastMemoryHash",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "address",
"name": "",
"type": "address"
}
],
"name": "lastMemoryHash",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "view",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "hash",
"type": "bytes32"
}
],
"name": "setLastMemoryHash",
"outputs": [],
"stateMutability": "nonpayable",
"type": "function"
}
] as const
{
anonymous: false,
inputs: [
{
indexed: true,
internalType: 'address',
name: 'agent',
type: 'address',
},
{
indexed: false,
internalType: 'bytes32',
name: 'hash',
type: 'bytes32',
},
],
name: 'LastMemoryHashSet',
type: 'event',
},
{
inputs: [
{
internalType: 'address',
name: '_agent',
type: 'address',
},
],
name: 'getLastMemoryHash',
outputs: [
{
internalType: 'bytes32',
name: '',
type: 'bytes32',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: 'address',
name: '',
type: 'address',
},
],
name: 'lastMemoryHash',
outputs: [
{
internalType: 'bytes32',
name: '',
type: 'bytes32',
},
],
stateMutability: 'view',
type: 'function',
},
{
inputs: [
{
internalType: 'bytes32',
name: 'hash',
type: 'bytes32',
},
],
name: 'setLastMemoryHash',
outputs: [],
stateMutability: 'nonpayable',
type: 'function',
},
] as const;
2 changes: 1 addition & 1 deletion auto-kol/agent/src/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ router.use('/', responseRoutes);
router.use('/', tweetRoutes);
router.use('/', dsnRoutes);

export default router;
export default router;
30 changes: 15 additions & 15 deletions auto-kol/agent/src/api/middleware/cors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import { config } from '../../config/index.js';
const allowedOrigins = config.CORS_ORIGINS?.split(',') || ['http://localhost:3000'];

export const corsMiddleware = cors({
origin: (origin, callback) => {
if (!origin) {
return callback(null, true);
}
origin: (origin, callback) => {
if (!origin) {
return callback(null, true);
}

if (allowedOrigins.indexOf(origin) !== -1 || config.NODE_ENV === 'development') {
callback(null, true);
} else {
callback(new Error('Not allowed by CORS'));
}
},
credentials: true,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization'],
maxAge: 86400 // 24 hours
});
if (allowedOrigins.indexOf(origin) !== -1 || config.NODE_ENV === 'development') {
callback(null, true);
} else {
callback(new Error('Not allowed by CORS'));
}
},
credentials: true,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization'],
maxAge: 86400, // 24 hours
});
91 changes: 46 additions & 45 deletions auto-kol/agent/src/api/routes/dsn.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,56 @@ const router = Router();
const logger = createLogger('dsn-api');

router.get('/memories', async (req, res) => {
try {
const page = parseInt(req.query.page as string) || 1;
const limit = parseInt(req.query.limit as string) || 10;

if (page < 1 || limit < 1 || limit > 100) {
return res.status(400).json({
error: 'Invalid pagination parameters. Page must be >= 1 and limit must be between 1 and 100'
});
}

const dsnRecords = await getAllDsn(page, limit);
res.json(dsnRecords);
} catch (error) {
logger.error('Error fetching DSN records:', error);
res.status(500).json({ error: 'Failed to fetch DSN records' });
try {
const page = parseInt(req.query.page as string) || 1;
const limit = parseInt(req.query.limit as string) || 10;

if (page < 1 || limit < 1 || limit > 100) {
return res.status(400).json({
error:
'Invalid pagination parameters. Page must be >= 1 and limit must be between 1 and 100',
});
}

const dsnRecords = await getAllDsn(page, limit);
res.json(dsnRecords);
} catch (error) {
logger.error('Error fetching DSN records:', error);
res.status(500).json({ error: 'Failed to fetch DSN records' });
}
});

router.get('/memories/:cid', async (req, res) => {
try {
const api = createAutoDriveApi({
apiKey: config.DSN_API_KEY || ''
});

const stream = await downloadObject(api, { cid: req.params.cid });
const reader = stream.getReader();
const chunks: Uint8Array[] = [];

while (true) {
const { done, value } = await reader.read();
if (done) break;
chunks.push(value);
}

const allChunks = new Uint8Array(chunks.reduce((acc, chunk) => acc + chunk.length, 0));
let position = 0;
for (const chunk of chunks) {
allChunks.set(chunk, position);
position += chunk.length;
}

const decompressed = inflate(allChunks);
const jsonString = new TextDecoder().decode(decompressed);
const memoryData = JSON.parse(jsonString);
res.json(memoryData);
} catch (error) {
logger.error('Error fetching memory data:', error);
res.status(500).json({ error: 'Failed to fetch memory data' });
try {
const api = createAutoDriveApi({
apiKey: config.DSN_API_KEY || '',
});

const stream = await downloadObject(api, { cid: req.params.cid });
const reader = stream.getReader();
const chunks: Uint8Array[] = [];

while (true) {
const { done, value } = await reader.read();
if (done) break;
chunks.push(value);
}

const allChunks = new Uint8Array(chunks.reduce((acc, chunk) => acc + chunk.length, 0));
let position = 0;
for (const chunk of chunks) {
allChunks.set(chunk, position);
position += chunk.length;
}

const decompressed = inflate(allChunks);
const jsonString = new TextDecoder().decode(decompressed);
const memoryData = JSON.parse(jsonString);
res.json(memoryData);
} catch (error) {
logger.error('Error fetching memory data:', error);
res.status(500).json({ error: 'Failed to fetch memory data' });
}
});

export default router;
export default router;
4 changes: 2 additions & 2 deletions auto-kol/agent/src/api/routes/health.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { Router } from 'express';
const router = Router();

router.get('/health', (_, res) => {
res.json({ status: 'ok' });
res.json({ status: 'ok' });
});

export default router;
export default router;
23 changes: 11 additions & 12 deletions auto-kol/agent/src/api/routes/responses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,17 @@ const router = Router();
const logger = createLogger('responses-api');

router.get('/responses/:id/workflow', async (req, res) => {
try {
const responses = await getAllPendingResponses();
const response = responses.find(r => r.id === req.params.id);
if (!response) {
return res.status(404).json({ error: 'Response not found' });
}
res.json(response.workflowState);
} catch (error) {
logger.error('Error getting workflow state:', error);
res.status(500).json({ error: 'Failed to get workflow state' });
try {
const responses = await getAllPendingResponses();
const response = responses.find(r => r.id === req.params.id);
if (!response) {
return res.status(404).json({ error: 'Response not found' });
}
res.json(response.workflowState);
} catch (error) {
logger.error('Error getting workflow state:', error);
res.status(500).json({ error: 'Failed to get workflow state' });
}
});


export default router;
export default router;
Loading
Loading