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: add news-aggregator tool #137

Closed
wants to merge 1 commit into from
Closed
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
Binary file added tools/news-aggregator/banner.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tools/news-aggregator/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
91 changes: 91 additions & 0 deletions tools/news-aggregator/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import { expect } from '@jest/globals';
import { getToolTestClient } from '../../src/test/utils';
import * as path from 'path';

interface Article {
title: string;
url: string;
source: string;
summary: string;
publish_date: string;
authors: string[];
top_image: string;
text: string;
}

interface NewsAggregatorResult {
total_sources_processed: number;
total_articles_found: number;
failed_sources: string[];
articles: Article[];
processing_time: number;
}

describe('News Aggregator Tool', () => {
const toolPath = path.join(__dirname, 'tool.py');
const client = getToolTestClient();

it('aggregates news from specific providers', async () => {
const result = await client.executeToolFromFile(toolPath, {
providers: ['https://reuters.com', 'https://techcrunch.com'],
articles_per_source: 3
}) as NewsAggregatorResult;
console.log(result);

// Basic checks
expect(result).toHaveProperty('total_sources_processed');
expect(result).toHaveProperty('total_articles_found');
expect(result).toHaveProperty('failed_sources');
expect(result).toHaveProperty('articles');
expect(result).toHaveProperty('processing_time');

// Type checks
expect(Array.isArray(result.articles)).toBe(true);
expect(Array.isArray(result.failed_sources)).toBe(true);
expect(typeof result.total_sources_processed).toBe('number');
expect(typeof result.total_articles_found).toBe('number');
expect(typeof result.processing_time).toBe('number');

// Content checks
if (result.articles.length > 0) {
const article = result.articles[0];
expect(article).toHaveProperty('title');
expect(article).toHaveProperty('url');
expect(article).toHaveProperty('source');
expect(article).toHaveProperty('summary');
expect(article).toHaveProperty('publish_date');
expect(article).toHaveProperty('authors');
expect(article).toHaveProperty('top_image');
expect(article).toHaveProperty('text');
}
}, 60000);

it('aggregates news by categories', async () => {
const result = await client.executeToolFromFile(toolPath, {
providers: [],
categories: ['tech'],
articles_per_source: 2
}) as NewsAggregatorResult;

expect(result.total_sources_processed).toBeGreaterThan(0);
expect(result.articles.length).toBeGreaterThan(0);

// Verify sources are from tech category
const techDomains = ['techcrunch.com', 'theverge.com', 'wired.com'];
const hasTechSource = result.articles.some((article: Article) =>
techDomains.some(domain => article.source.includes(domain))
);
expect(hasTechSource).toBe(true);
}, 60000);

it('handles failed sources gracefully', async () => {
const result = await client.executeToolFromFile(toolPath, {
providers: ['http://invalid-news-source.com'],
articles_per_source: 1
}) as NewsAggregatorResult;

expect(result.failed_sources).toContain('http://invalid-news-source.com');
expect(result.total_sources_processed).toBe(0);
expect(result.articles.length).toBe(0);
}, 30000);
});
107 changes: 107 additions & 0 deletions tools/news-aggregator/metadata.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
{
"id": "news-aggregator",
"name": "News Aggregator",
"version": "1.0.0",
"description": "Aggregates latest news from multiple sources using newspaper3k, supporting parallel processing and category-based filtering",
"author": "Shinkai",
"keywords": [
"news",
"aggregator",
"newspaper3k",
"scraper",
"articles",
"multi-source"
],
"configurations": {
"type": "object",
"properties": {
"language": {
"type": "string",
"description": "The language to use for article processing",
"default": "en"
},
"number_threads": {
"type": "integer",
"description": "Number of threads for article processing",
"default": 10
},
"request_timeout": {
"type": "integer",
"description": "Timeout in seconds for HTTP requests",
"default": 30
},
"max_concurrent_sources": {
"type": "integer",
"description": "Maximum number of sources to process concurrently",
"default": 5
}
},
"required": []
},
"parameters": {
"type": "object",
"properties": {
"providers": {
"type": "array",
"items": {
"type": "string"
},
"description": "List of news provider URLs to aggregate from"
},
"articles_per_source": {
"type": "integer",
"description": "Maximum number of articles to fetch per source",
"default": 5
},
"categories": {
"type": "array",
"items": {
"type": "string",
"enum": ["general", "tech", "business"]
},
"description": "Categories to fetch news from (uses default providers if no specific providers given)"
}
},
"required": ["providers"]
},
"result": {
"type": "object",
"properties": {
"total_sources_processed": {
"type": "integer"
},
"total_articles_found": {
"type": "integer"
},
"failed_sources": {
"type": "array",
"items": {
"type": "string"
}
},
"articles": {
"type": "array",
"items": {
"type": "object",
"properties": {
"title": {"type": "string"},
"url": {"type": "string"},
"source": {"type": "string"},
"summary": {"type": "string"},
"publish_date": {"type": "string"},
"authors": {
"type": "array",
"items": {
"type": "string"
}
},
"top_image": {"type": "string"},
"text": {"type": "string"}
}
}
},
"processing_time": {"type": "number"}
},
"required": ["total_sources_processed", "total_articles_found", "failed_sources", "articles", "processing_time"]
}
}
3 changes: 3 additions & 0 deletions tools/news-aggregator/store.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"categoryId": "e9e36f6d-a0e3-47e9-b782-acb946b0199e"
}
Loading
Loading