@ever-works/linkup-plugin 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +661 -0
- package/README.md +75 -0
- package/package.json +76 -0
- package/src/__tests__/linkup.plugin.spec.ts +297 -0
- package/src/index.ts +2 -0
- package/src/linkup.plugin.ts +369 -0
- package/tsconfig.json +22 -0
- package/tsup.config.ts +12 -0
|
@@ -0,0 +1,369 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
IPlugin,
|
|
3
|
+
ISearchPlugin,
|
|
4
|
+
IContentExtractorPlugin,
|
|
5
|
+
PluginContext,
|
|
6
|
+
PluginCategory,
|
|
7
|
+
PluginManifest,
|
|
8
|
+
PluginHealthCheck,
|
|
9
|
+
JsonSchema,
|
|
10
|
+
PluginSettings,
|
|
11
|
+
SearchOptions,
|
|
12
|
+
SearchResponse,
|
|
13
|
+
SearchResult,
|
|
14
|
+
RateLimitInfo,
|
|
15
|
+
ContentExtractionOptions,
|
|
16
|
+
ContentExtractionResult,
|
|
17
|
+
ConnectionValidationResult
|
|
18
|
+
} from '@ever-works/plugin';
|
|
19
|
+
// Security (SSRF): isSafeWebhookUrl rejects non-http(s) schemes and http(s) URLs
|
|
20
|
+
// whose host is private/loopback/link-local/cloud-metadata, before any caller-
|
|
21
|
+
// supplied URL is forwarded to the Linkup /fetch proxy (which fetches it
|
|
22
|
+
// server-side). Imported directly because the ssrf-guard is intentionally not
|
|
23
|
+
// re-exported from the helpers barrel (it pulls in node:net/node:dns).
|
|
24
|
+
import { isSafeWebhookUrl } from '@ever-works/plugin/helpers/ssrf-guard';
|
|
25
|
+
|
|
26
|
+
const LINKUP_API_BASE = 'https://api.linkup.so/v1';
|
|
27
|
+
|
|
28
|
+
interface LinkupSource {
|
|
29
|
+
name: string;
|
|
30
|
+
url: string;
|
|
31
|
+
snippet: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
interface LinkupSearchResult {
|
|
35
|
+
name: string;
|
|
36
|
+
url: string;
|
|
37
|
+
content: string;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
interface LinkupSearchResponse {
|
|
41
|
+
answer?: string;
|
|
42
|
+
results?: LinkupSearchResult[];
|
|
43
|
+
sources?: LinkupSource[];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
interface LinkupFetchResponse {
|
|
47
|
+
markdown: string;
|
|
48
|
+
rawHtml?: string;
|
|
49
|
+
images?: { url: string; alt: string }[];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export class LinkupSearchPlugin implements IPlugin, ISearchPlugin, IContentExtractorPlugin {
|
|
53
|
+
readonly id = 'linkup';
|
|
54
|
+
readonly name = 'Linkup';
|
|
55
|
+
readonly version = '1.0.0';
|
|
56
|
+
readonly category: PluginCategory = 'search';
|
|
57
|
+
readonly capabilities: readonly string[] = ['search', 'content-extractor'];
|
|
58
|
+
readonly providerName = 'Linkup';
|
|
59
|
+
|
|
60
|
+
readonly settingsSchema: JsonSchema = {
|
|
61
|
+
type: 'object',
|
|
62
|
+
properties: {
|
|
63
|
+
apiKey: {
|
|
64
|
+
type: 'string',
|
|
65
|
+
title: 'API Key',
|
|
66
|
+
description: 'Your Linkup API key. Get one at https://linkup.so',
|
|
67
|
+
'x-secret': true,
|
|
68
|
+
'x-envVar': 'PLUGIN_LINKUP_API_KEY',
|
|
69
|
+
'x-scope': 'user'
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
required: ['apiKey']
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
readonly configurationMode: 'admin-only' | 'user-required' | 'hybrid' = 'hybrid';
|
|
76
|
+
|
|
77
|
+
private context?: PluginContext;
|
|
78
|
+
|
|
79
|
+
async search(options: SearchOptions): Promise<SearchResponse> {
|
|
80
|
+
const apiKey = this.getApiKey(options.settings);
|
|
81
|
+
const startTime = Date.now();
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
const body: Record<string, unknown> = {
|
|
85
|
+
q: options.query,
|
|
86
|
+
depth: 'deep',
|
|
87
|
+
outputType: 'searchResults'
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
if (options.includeDomains?.length) {
|
|
91
|
+
body.includeDomains = options.includeDomains;
|
|
92
|
+
}
|
|
93
|
+
if (options.excludeDomains?.length) {
|
|
94
|
+
body.excludeDomains = options.excludeDomains;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const response = await fetch(`${LINKUP_API_BASE}/search`, {
|
|
98
|
+
method: 'POST',
|
|
99
|
+
headers: {
|
|
100
|
+
Authorization: `Bearer ${apiKey}`,
|
|
101
|
+
'Content-Type': 'application/json'
|
|
102
|
+
},
|
|
103
|
+
body: JSON.stringify(body)
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
if (!response.ok) {
|
|
107
|
+
// Security (info-leak): surface only the HTTP status line, not the raw
|
|
108
|
+
// upstream Linkup response body (may carry internal API error detail).
|
|
109
|
+
throw new Error(`Linkup search failed with status ${response.status}: ${response.statusText}`);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const data = (await response.json()) as LinkupSearchResponse;
|
|
113
|
+
|
|
114
|
+
const results: SearchResult[] = (data.results || data.sources || []).map((r, index) => ({
|
|
115
|
+
title: 'name' in r ? r.name : '',
|
|
116
|
+
url: r.url,
|
|
117
|
+
snippet: 'content' in r ? r.content : 'snippet' in r ? (r as LinkupSource).snippet : '',
|
|
118
|
+
position: index + 1,
|
|
119
|
+
metadata: {}
|
|
120
|
+
}));
|
|
121
|
+
|
|
122
|
+
return {
|
|
123
|
+
results,
|
|
124
|
+
query: options.query,
|
|
125
|
+
totalResults: results.length,
|
|
126
|
+
hasMore: false,
|
|
127
|
+
duration: Date.now() - startTime
|
|
128
|
+
};
|
|
129
|
+
} catch (error) {
|
|
130
|
+
this.context?.logger.error(
|
|
131
|
+
`Linkup search failed: ${error instanceof Error ? error.message : String(error)}`
|
|
132
|
+
);
|
|
133
|
+
throw error;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
async isAvailable(): Promise<boolean> {
|
|
138
|
+
if (!this.context) return false;
|
|
139
|
+
const settings = await this.context.getSettings();
|
|
140
|
+
return Boolean(settings?.apiKey);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
async validateConnection(settings: Record<string, unknown>): Promise<ConnectionValidationResult> {
|
|
144
|
+
const apiKey = settings.apiKey as string | undefined;
|
|
145
|
+
if (!apiKey) {
|
|
146
|
+
return { success: false, message: 'Linkup API key is not configured.' };
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
try {
|
|
150
|
+
const response = await fetch(`${LINKUP_API_BASE}/search`, {
|
|
151
|
+
method: 'POST',
|
|
152
|
+
headers: {
|
|
153
|
+
Authorization: `Bearer ${apiKey}`,
|
|
154
|
+
'Content-Type': 'application/json'
|
|
155
|
+
},
|
|
156
|
+
body: JSON.stringify({
|
|
157
|
+
q: 'test',
|
|
158
|
+
depth: 'standard',
|
|
159
|
+
outputType: 'searchResults'
|
|
160
|
+
})
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
if (!response.ok) {
|
|
164
|
+
// Security (info-leak): report only the HTTP status line, not the raw
|
|
165
|
+
// upstream Linkup response body (may carry internal API error detail).
|
|
166
|
+
return {
|
|
167
|
+
success: false,
|
|
168
|
+
message: `Linkup connection failed (${response.status}): ${response.statusText}`
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return { success: true, message: 'Linkup connection verified.' };
|
|
173
|
+
} catch (error) {
|
|
174
|
+
return {
|
|
175
|
+
success: false,
|
|
176
|
+
message: `Linkup connection failed: ${error instanceof Error ? error.message : String(error)}`
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
async getRateLimitInfo(): Promise<RateLimitInfo> {
|
|
182
|
+
return {
|
|
183
|
+
remaining: -1,
|
|
184
|
+
limit: 10,
|
|
185
|
+
period: 'second'
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
async extract(options: ContentExtractionOptions): Promise<ContentExtractionResult> {
|
|
190
|
+
const apiKey = this.getApiKey(options.settings);
|
|
191
|
+
const startTime = Date.now();
|
|
192
|
+
|
|
193
|
+
// Security (SSRF): `options.url` is caller-supplied and forwarded verbatim to
|
|
194
|
+
// the Linkup /fetch endpoint, which fetches it server-side and returns the
|
|
195
|
+
// body to us. `canExtract()` is advisory and `extractBatch()` calls this
|
|
196
|
+
// method directly, so enforce the gate HERE. Reject non-http(s) schemes
|
|
197
|
+
// (file://, ftp://, …) and internal/loopback/link-local/metadata hosts before
|
|
198
|
+
// making the request. Returns the method's existing failed-result shape;
|
|
199
|
+
// legitimate public http(s) URLs are unaffected.
|
|
200
|
+
if (!isSafeWebhookUrl(options.url)) {
|
|
201
|
+
return {
|
|
202
|
+
success: false,
|
|
203
|
+
url: options.url,
|
|
204
|
+
error: `URL host is not safe to fetch (SSRF guard blocked: ${options.url})`,
|
|
205
|
+
duration: Date.now() - startTime
|
|
206
|
+
};
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
try {
|
|
210
|
+
const response = await fetch(`${LINKUP_API_BASE}/fetch`, {
|
|
211
|
+
method: 'POST',
|
|
212
|
+
headers: {
|
|
213
|
+
Authorization: `Bearer ${apiKey}`,
|
|
214
|
+
'Content-Type': 'application/json'
|
|
215
|
+
},
|
|
216
|
+
body: JSON.stringify({
|
|
217
|
+
url: options.url,
|
|
218
|
+
renderJs: true,
|
|
219
|
+
includeRawHtml: false,
|
|
220
|
+
extractImages: false
|
|
221
|
+
})
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
if (!response.ok) {
|
|
225
|
+
// Security (info-leak): do not reflect the raw upstream Linkup response
|
|
226
|
+
// body to the caller — it can carry internal API error detail. Surface
|
|
227
|
+
// only the HTTP status line.
|
|
228
|
+
return {
|
|
229
|
+
success: false,
|
|
230
|
+
url: options.url,
|
|
231
|
+
error: `Linkup fetch failed with status ${response.status}: ${response.statusText}`,
|
|
232
|
+
duration: Date.now() - startTime
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
const data = (await response.json()) as LinkupFetchResponse;
|
|
237
|
+
|
|
238
|
+
if (!data.markdown) {
|
|
239
|
+
return {
|
|
240
|
+
success: false,
|
|
241
|
+
url: options.url,
|
|
242
|
+
error: 'No content extracted',
|
|
243
|
+
duration: Date.now() - startTime
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
return {
|
|
248
|
+
success: true,
|
|
249
|
+
url: options.url,
|
|
250
|
+
content: data.markdown,
|
|
251
|
+
markdown: data.markdown,
|
|
252
|
+
duration: Date.now() - startTime,
|
|
253
|
+
wordCount: data.markdown.split(/\s+/).length
|
|
254
|
+
};
|
|
255
|
+
} catch (error) {
|
|
256
|
+
return {
|
|
257
|
+
success: false,
|
|
258
|
+
url: options.url,
|
|
259
|
+
error: error instanceof Error ? error.message : String(error),
|
|
260
|
+
duration: Date.now() - startTime
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
async extractBatch(
|
|
266
|
+
urls: readonly string[],
|
|
267
|
+
options?: Partial<ContentExtractionOptions>
|
|
268
|
+
): Promise<readonly ContentExtractionResult[]> {
|
|
269
|
+
const results = await Promise.all(
|
|
270
|
+
urls.map((url) =>
|
|
271
|
+
this.extract({
|
|
272
|
+
url,
|
|
273
|
+
...options
|
|
274
|
+
} as ContentExtractionOptions)
|
|
275
|
+
)
|
|
276
|
+
);
|
|
277
|
+
return results;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
async canExtract(url: string): Promise<boolean> {
|
|
281
|
+
try {
|
|
282
|
+
const parsed = new URL(url);
|
|
283
|
+
return parsed.protocol === 'http:' || parsed.protocol === 'https:';
|
|
284
|
+
} catch {
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
getSupportedFormats(): readonly ('text' | 'html' | 'markdown')[] {
|
|
290
|
+
return ['text', 'markdown'];
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
private getApiKey(settings?: PluginSettings): string {
|
|
294
|
+
const apiKey = settings?.apiKey as string;
|
|
295
|
+
|
|
296
|
+
if (!apiKey) {
|
|
297
|
+
throw new Error(
|
|
298
|
+
'Linkup API key not configured. ' +
|
|
299
|
+
'Set it in plugin settings or via PLUGIN_LINKUP_API_KEY environment variable.'
|
|
300
|
+
);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return apiKey;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
async onLoad(context: PluginContext): Promise<void> {
|
|
307
|
+
this.context = context;
|
|
308
|
+
context.logger.log('Linkup Plugin loaded');
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
async onUnload(): Promise<void> {
|
|
312
|
+
this.context = undefined;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
async healthCheck(): Promise<PluginHealthCheck> {
|
|
316
|
+
return {
|
|
317
|
+
status: 'healthy',
|
|
318
|
+
message: 'Linkup plugin is ready (API key required for operations)',
|
|
319
|
+
checkedAt: Date.now()
|
|
320
|
+
};
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
getManifest(): PluginManifest {
|
|
324
|
+
return {
|
|
325
|
+
id: this.id,
|
|
326
|
+
name: this.name,
|
|
327
|
+
version: this.version,
|
|
328
|
+
description: 'Search the web and extract content from websites using Linkup',
|
|
329
|
+
category: this.category,
|
|
330
|
+
capabilities: [...this.capabilities],
|
|
331
|
+
author: { name: 'Ever Works Team' },
|
|
332
|
+
license: 'AGPL-3.0',
|
|
333
|
+
builtIn: true,
|
|
334
|
+
systemPlugin: false,
|
|
335
|
+
autoEnable: false,
|
|
336
|
+
defaultForCapabilities: [],
|
|
337
|
+
homepage: 'https://linkup.so',
|
|
338
|
+
icon: {
|
|
339
|
+
type: 'url',
|
|
340
|
+
value: 'https://framerusercontent.com/images/PuShJA41szIkwbQopIjqoEoOvUc.png'
|
|
341
|
+
},
|
|
342
|
+
readme: [
|
|
343
|
+
'## What does Linkup do?',
|
|
344
|
+
'',
|
|
345
|
+
'Linkup connects AI applications to the internet, providing grounding data to enrich AI output with precision and factuality. It searches the web for relevant content and extracts clean markdown from any URL.',
|
|
346
|
+
'',
|
|
347
|
+
'## Why use it?',
|
|
348
|
+
'',
|
|
349
|
+
'- **High precision search** — optimized for factual grounding of LLM responses',
|
|
350
|
+
'- **Deep search mode** — iterative search for comprehensive results when needed',
|
|
351
|
+
'- **Content extraction** — fetches clean markdown from any webpage via the /fetch endpoint',
|
|
352
|
+
'- **Domain filtering** — include or exclude specific websites from search results',
|
|
353
|
+
'',
|
|
354
|
+
'## How it works in Ever Works',
|
|
355
|
+
'',
|
|
356
|
+
'During work generation, the search facade uses Linkup to find information about each item, discover relevant source URLs, and extract content from web pages. This powers automatic descriptions, source URL resolution, and content enrichment across the generation pipeline.',
|
|
357
|
+
'',
|
|
358
|
+
'## Getting started',
|
|
359
|
+
'',
|
|
360
|
+
'1. Create an account at [linkup.so](https://linkup.so)',
|
|
361
|
+
'2. Copy your API key from the Linkup dashboard',
|
|
362
|
+
'3. Enter the key in the **API Key** field below',
|
|
363
|
+
'4. Linkup will be available for use during work generation'
|
|
364
|
+
].join('\n')
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
export default LinkupSearchPlugin;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"types": ["node"],
|
|
5
|
+
"module": "NodeNext",
|
|
6
|
+
"moduleResolution": "NodeNext",
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"declarationMap": true,
|
|
9
|
+
"sourceMap": true,
|
|
10
|
+
"outDir": "./dist",
|
|
11
|
+
"rootDir": "./src",
|
|
12
|
+
"strict": true,
|
|
13
|
+
"esModuleInterop": true,
|
|
14
|
+
"skipLibCheck": true,
|
|
15
|
+
"forceConsistentCasingInFileNames": true,
|
|
16
|
+
"resolveJsonModule": true,
|
|
17
|
+
"isolatedModules": true,
|
|
18
|
+
"noEmit": true
|
|
19
|
+
},
|
|
20
|
+
"include": ["src/**/*"],
|
|
21
|
+
"exclude": ["node_modules", "dist", "**/*.test.ts", "**/*.spec.ts"]
|
|
22
|
+
}
|
package/tsup.config.ts
ADDED