|
| 1 | +import app from "../../exa.app.mjs"; |
| 2 | + |
| 3 | +export default { |
| 4 | + key: "exa-find-similar-links", |
| 5 | + name: "Find Similar Links", |
| 6 | + description: "Identifies and retrieves web pages similar to a provided URL with optional content extraction. [See the documentation](https://docs.exa.ai/reference/find-similar-links)", |
| 7 | + version: "0.0.1", |
| 8 | + type: "action", |
| 9 | + annotations: { |
| 10 | + destructiveHint: false, |
| 11 | + openWorldHint: true, |
| 12 | + readOnlyHint: true, |
| 13 | + }, |
| 14 | + props: { |
| 15 | + app, |
| 16 | + url: { |
| 17 | + propDefinition: [ |
| 18 | + app, |
| 19 | + "url", |
| 20 | + ], |
| 21 | + }, |
| 22 | + numResults: { |
| 23 | + propDefinition: [ |
| 24 | + app, |
| 25 | + "numResults", |
| 26 | + ], |
| 27 | + }, |
| 28 | + includeDomains: { |
| 29 | + propDefinition: [ |
| 30 | + app, |
| 31 | + "includeDomains", |
| 32 | + ], |
| 33 | + }, |
| 34 | + excludeDomains: { |
| 35 | + propDefinition: [ |
| 36 | + app, |
| 37 | + "excludeDomains", |
| 38 | + ], |
| 39 | + }, |
| 40 | + startCrawlDate: { |
| 41 | + propDefinition: [ |
| 42 | + app, |
| 43 | + "startCrawlDate", |
| 44 | + ], |
| 45 | + }, |
| 46 | + endCrawlDate: { |
| 47 | + propDefinition: [ |
| 48 | + app, |
| 49 | + "endCrawlDate", |
| 50 | + ], |
| 51 | + }, |
| 52 | + startPublishedDate: { |
| 53 | + propDefinition: [ |
| 54 | + app, |
| 55 | + "startPublishedDate", |
| 56 | + ], |
| 57 | + }, |
| 58 | + endPublishedDate: { |
| 59 | + propDefinition: [ |
| 60 | + app, |
| 61 | + "endPublishedDate", |
| 62 | + ], |
| 63 | + }, |
| 64 | + includeText: { |
| 65 | + propDefinition: [ |
| 66 | + app, |
| 67 | + "includeText", |
| 68 | + ], |
| 69 | + }, |
| 70 | + excludeText: { |
| 71 | + propDefinition: [ |
| 72 | + app, |
| 73 | + "excludeText", |
| 74 | + ], |
| 75 | + }, |
| 76 | + context: { |
| 77 | + propDefinition: [ |
| 78 | + app, |
| 79 | + "context", |
| 80 | + ], |
| 81 | + }, |
| 82 | + moderation: { |
| 83 | + propDefinition: [ |
| 84 | + app, |
| 85 | + "moderation", |
| 86 | + ], |
| 87 | + }, |
| 88 | + contentsText: { |
| 89 | + label: "Contents - Text", |
| 90 | + propDefinition: [ |
| 91 | + app, |
| 92 | + "text", |
| 93 | + ], |
| 94 | + }, |
| 95 | + contentsHighlightsNumSentences: { |
| 96 | + label: "Contents - Highlights - Number of Sentences", |
| 97 | + propDefinition: [ |
| 98 | + app, |
| 99 | + "highlightsNumSentences", |
| 100 | + ], |
| 101 | + }, |
| 102 | + contentsHighlightsPerUrl: { |
| 103 | + label: "Contents - Highlights - Number of Snippets per URL", |
| 104 | + propDefinition: [ |
| 105 | + app, |
| 106 | + "highlightsPerUrl", |
| 107 | + ], |
| 108 | + }, |
| 109 | + contentsHighlightsQuery: { |
| 110 | + label: "Contents - Highlights - Custom Query", |
| 111 | + propDefinition: [ |
| 112 | + app, |
| 113 | + "highlightsQuery", |
| 114 | + ], |
| 115 | + }, |
| 116 | + contentsSummaryQuery: { |
| 117 | + label: "Contents - Summary - Custom Query", |
| 118 | + propDefinition: [ |
| 119 | + app, |
| 120 | + "summaryQuery", |
| 121 | + ], |
| 122 | + }, |
| 123 | + contentsSummarySchema: { |
| 124 | + label: "Contents - Summary - JSON Schema", |
| 125 | + propDefinition: [ |
| 126 | + app, |
| 127 | + "summarySchema", |
| 128 | + ], |
| 129 | + }, |
| 130 | + contentsLivecrawl: { |
| 131 | + label: "Contents - Live Crawl", |
| 132 | + propDefinition: [ |
| 133 | + app, |
| 134 | + "livecrawl", |
| 135 | + ], |
| 136 | + }, |
| 137 | + contentsLivecrawlTimeout: { |
| 138 | + label: "Contents - Live Crawl Timeout", |
| 139 | + propDefinition: [ |
| 140 | + app, |
| 141 | + "livecrawlTimeout", |
| 142 | + ], |
| 143 | + }, |
| 144 | + contentsSubpages: { |
| 145 | + label: "Contents - Subpages", |
| 146 | + propDefinition: [ |
| 147 | + app, |
| 148 | + "subpages", |
| 149 | + ], |
| 150 | + }, |
| 151 | + contentsSubpageTarget: { |
| 152 | + label: "Contents - Subpage Target", |
| 153 | + propDefinition: [ |
| 154 | + app, |
| 155 | + "subpageTarget", |
| 156 | + ], |
| 157 | + }, |
| 158 | + contentsExtrasLinks: { |
| 159 | + label: "Contents - Extras - Number of Links", |
| 160 | + propDefinition: [ |
| 161 | + app, |
| 162 | + "extrasLinks", |
| 163 | + ], |
| 164 | + }, |
| 165 | + contentsExtrasImageLinks: { |
| 166 | + label: "Contents - Extras - Number of Image Links", |
| 167 | + propDefinition: [ |
| 168 | + app, |
| 169 | + "extrasImageLinks", |
| 170 | + ], |
| 171 | + }, |
| 172 | + contentsContext: { |
| 173 | + label: "Contents - Context", |
| 174 | + propDefinition: [ |
| 175 | + app, |
| 176 | + "context", |
| 177 | + ], |
| 178 | + }, |
| 179 | + }, |
| 180 | + async run({ $ }) { |
| 181 | + const { |
| 182 | + app, |
| 183 | + url, |
| 184 | + numResults, |
| 185 | + includeDomains, |
| 186 | + excludeDomains, |
| 187 | + startCrawlDate, |
| 188 | + endCrawlDate, |
| 189 | + startPublishedDate, |
| 190 | + endPublishedDate, |
| 191 | + includeText, |
| 192 | + excludeText, |
| 193 | + contentsText, |
| 194 | + contentsHighlightsNumSentences, |
| 195 | + contentsHighlightsPerUrl, |
| 196 | + contentsHighlightsQuery, |
| 197 | + contentsSummaryQuery, |
| 198 | + contentsSummarySchema, |
| 199 | + contentsLivecrawl, |
| 200 | + contentsLivecrawlTimeout, |
| 201 | + contentsSubpages, |
| 202 | + contentsSubpageTarget, |
| 203 | + contentsExtrasLinks, |
| 204 | + contentsExtrasImageLinks, |
| 205 | + contentsContext, |
| 206 | + } = this; |
| 207 | + |
| 208 | + const highlights = contentsHighlightsNumSentences |
| 209 | + || contentsHighlightsPerUrl |
| 210 | + || contentsHighlightsQuery |
| 211 | + ? { |
| 212 | + numSentences: contentsHighlightsNumSentences, |
| 213 | + highlightsPerUrl: contentsHighlightsPerUrl, |
| 214 | + query: contentsHighlightsQuery, |
| 215 | + } |
| 216 | + : undefined; |
| 217 | + |
| 218 | + const summary = contentsSummaryQuery |
| 219 | + || contentsSummarySchema |
| 220 | + ? { |
| 221 | + query: contentsSummaryQuery, |
| 222 | + schema: contentsSummarySchema, |
| 223 | + } |
| 224 | + : undefined; |
| 225 | + |
| 226 | + const extras = contentsExtrasLinks |
| 227 | + || contentsExtrasImageLinks |
| 228 | + ? { |
| 229 | + links: contentsExtrasLinks, |
| 230 | + imageLinks: contentsExtrasImageLinks, |
| 231 | + } |
| 232 | + : undefined; |
| 233 | + |
| 234 | + const response = await app.findSimilar({ |
| 235 | + $, |
| 236 | + data: { |
| 237 | + url, |
| 238 | + numResults, |
| 239 | + includeDomains, |
| 240 | + excludeDomains, |
| 241 | + startCrawlDate, |
| 242 | + endCrawlDate, |
| 243 | + startPublishedDate, |
| 244 | + endPublishedDate, |
| 245 | + includeText, |
| 246 | + excludeText, |
| 247 | + ...(contentsText |
| 248 | + || contentsLivecrawl |
| 249 | + || contentsLivecrawlTimeout |
| 250 | + || contentsSubpages |
| 251 | + || contentsSubpageTarget |
| 252 | + || contentsContext |
| 253 | + || highlights |
| 254 | + || summary |
| 255 | + || extras |
| 256 | + ? { |
| 257 | + contents: { |
| 258 | + text: contentsText, |
| 259 | + context: contentsContext, |
| 260 | + highlights, |
| 261 | + summary, |
| 262 | + livecrawl: contentsLivecrawl, |
| 263 | + livecrawlTimeout: contentsLivecrawlTimeout, |
| 264 | + subpages: contentsSubpages, |
| 265 | + subpageTarget: contentsSubpageTarget, |
| 266 | + extras, |
| 267 | + }, |
| 268 | + } |
| 269 | + : undefined |
| 270 | + ), |
| 271 | + }, |
| 272 | + }); |
| 273 | + |
| 274 | + $.export("$summary", `Successfully found similar links with ID \`${response.requestId}\`.`); |
| 275 | + return response; |
| 276 | + }, |
| 277 | +}; |
0 commit comments