|
| 1 | +import app from "../../linkup.app.mjs"; |
| 2 | + |
| 3 | +export default { |
| 4 | + name: "Linkup Search", |
| 5 | + description: "Search and retrieve insights using the Linkup API. [See the documentation](https://docs.linkup.so/pages/api-reference/endpoint/post-search)", |
| 6 | + key: "linkup-search", |
| 7 | + version: "0.0.1", |
| 8 | + type: "action", |
| 9 | + props: { |
| 10 | + app, |
| 11 | + query: { |
| 12 | + type: "string", |
| 13 | + label: "Query", |
| 14 | + description: "The search query for Linkup.", |
| 15 | + }, |
| 16 | + depth: { |
| 17 | + type: "string", |
| 18 | + label: "Search Depth", |
| 19 | + description: "Defines the precision of the search. `standard` returns results quickly; `deep` takes longer but yields more complete results.", |
| 20 | + options: [ |
| 21 | + "standard", |
| 22 | + "deep", |
| 23 | + ], |
| 24 | + }, |
| 25 | + outputType: { |
| 26 | + type: "string", |
| 27 | + label: "Output Type", |
| 28 | + description: "The type of output you want to get. Use `structured` for a custom-formatted response defined by `structuredOutputSchema`", |
| 29 | + options: [ |
| 30 | + { |
| 31 | + value: "sourcedAnswer", |
| 32 | + label: "Natural language answer and its sources", |
| 33 | + }, |
| 34 | + { |
| 35 | + value: "searchResults", |
| 36 | + label: "Raw context", |
| 37 | + }, |
| 38 | + { |
| 39 | + value: "structured", |
| 40 | + label: "Json format of the response", |
| 41 | + }, |
| 42 | + ], |
| 43 | + reloadProps: true, |
| 44 | + }, |
| 45 | + structuredOutputSchema: { |
| 46 | + type: "string", |
| 47 | + label: "Structured Output Schema", |
| 48 | + description: "Schema for structured output (only applicable if Output Type is 'structured'). Provide a JSON schema (as a string) representing the desired response format.", |
| 49 | + optional: true, |
| 50 | + hidden: true, |
| 51 | + }, |
| 52 | + includeImages: { |
| 53 | + type: "boolean", |
| 54 | + label: "Include Images", |
| 55 | + description: "Defines whether the API should include images in its results", |
| 56 | + optional: true, |
| 57 | + }, |
| 58 | + }, |
| 59 | + additionalProps(props) { |
| 60 | + if (this.outputType === "structured") { |
| 61 | + props.structuredOutputSchema.optional = false; |
| 62 | + props.structuredOutputSchema.hidden = false; |
| 63 | + props.structuredOutputSchema.default = `{ |
| 64 | + "type": "object", |
| 65 | + "properties": { |
| 66 | + "results": { |
| 67 | + "type": "array", |
| 68 | + "items": { |
| 69 | + "type": "object", |
| 70 | + "properties": { |
| 71 | + "name": { |
| 72 | + "type": "string" |
| 73 | + }, |
| 74 | + "year": { |
| 75 | + "type": "number" |
| 76 | + } |
| 77 | + }, |
| 78 | + "required": [ |
| 79 | + "name", |
| 80 | + "year" |
| 81 | + ], |
| 82 | + "additionalProperties": false |
| 83 | + } |
| 84 | + } |
| 85 | + }, |
| 86 | + "required": [ |
| 87 | + "results" |
| 88 | + ], |
| 89 | + "additionalProperties": false |
| 90 | + }`; |
| 91 | + } |
| 92 | + return {}; |
| 93 | + }, |
| 94 | + async run({ $ }) { |
| 95 | + try { |
| 96 | + const response = await this.app.search({ |
| 97 | + query: this.query, |
| 98 | + depth: this.depth, |
| 99 | + outputType: this.outputType, |
| 100 | + structuredOutputSchema: |
| 101 | + this.structuredOutputSchema && JSON.parse(this.structuredOutputSchema), |
| 102 | + includeImages: this.includeImages, |
| 103 | + }); |
| 104 | + $.export("$summary", "Successfully completed search query"); |
| 105 | + return response; |
| 106 | + } catch (error) { |
| 107 | + console.error("Error calling Linkup API:", error); |
| 108 | + throw new Error(`Failed to fetch data from Linkup API: ${error.message}`); |
| 109 | + } |
| 110 | + }, |
| 111 | +}; |
0 commit comments