|
| 1 | +import arxiv from "../../arxiv.app.mjs"; |
| 2 | +import fs from "fs"; |
| 3 | + |
| 4 | +export default { |
| 5 | + key: "arxiv-search-articles", |
| 6 | + name: "Search Articles", |
| 7 | + description: "Search for articles on arXiv. [See the documentation](https://info.arxiv.org/help/api/user-manual.html#2-api-quickstart)", |
| 8 | + version: "0.0.1", |
| 9 | + type: "action", |
| 10 | + annotations: { |
| 11 | + destructiveHint: false, |
| 12 | + openWorldHint: true, |
| 13 | + readOnlyHint: true, |
| 14 | + }, |
| 15 | + props: { |
| 16 | + arxiv, |
| 17 | + searchQuery: { |
| 18 | + type: "string", |
| 19 | + label: "Search Query", |
| 20 | + description: "The search query to use. Example: `all:electron`. [See the documentation](https://info.arxiv.org/help/api/user-manual.html#51-details-of-query-construction) for information on constructing a search query.", |
| 21 | + optional: true, |
| 22 | + }, |
| 23 | + idList: { |
| 24 | + type: "string[]", |
| 25 | + label: "ID List", |
| 26 | + description: "A list of arXiv article IDs to search for. Example ID: `2505.08081v1`", |
| 27 | + optional: true, |
| 28 | + }, |
| 29 | + start: { |
| 30 | + type: "integer", |
| 31 | + label: "Start", |
| 32 | + description: "The index of the first result to return. Defaults to 0.", |
| 33 | + optional: true, |
| 34 | + }, |
| 35 | + maxResults: { |
| 36 | + type: "integer", |
| 37 | + label: "Max Results", |
| 38 | + description: "The maximum number of results to return. Defaults to 10.", |
| 39 | + optional: true, |
| 40 | + }, |
| 41 | + filename: { |
| 42 | + type: "string", |
| 43 | + label: "Filename", |
| 44 | + description: "A filename to save the result as an xml file to the /tmp directory. Example: `arxiv-search-results.xml`", |
| 45 | + optional: true, |
| 46 | + }, |
| 47 | + syncDir: { |
| 48 | + type: "dir", |
| 49 | + accessMode: "write", |
| 50 | + sync: true, |
| 51 | + }, |
| 52 | + }, |
| 53 | + async run({ $ }) { |
| 54 | + const response = await this.arxiv.search({ |
| 55 | + $, |
| 56 | + params: { |
| 57 | + search_query: this.searchQuery, |
| 58 | + id_list: this.idList |
| 59 | + ? this.idList.join(",") |
| 60 | + : undefined, |
| 61 | + start: this.start, |
| 62 | + max_results: this.maxResults, |
| 63 | + }, |
| 64 | + }); |
| 65 | + |
| 66 | + if (!this.filename) { |
| 67 | + $.export("$summary", "Successfully searched for articles"); |
| 68 | + return response; |
| 69 | + } |
| 70 | + |
| 71 | + const filePath = `/tmp/${this.filename}`; |
| 72 | + fs.writeFileSync(filePath, response, "utf8"); |
| 73 | + |
| 74 | + $.export("$summary", `Successfully saved search results to ${filePath}`); |
| 75 | + return { |
| 76 | + filePath, |
| 77 | + fileContent: response, |
| 78 | + }; |
| 79 | + }, |
| 80 | +}; |
0 commit comments