@ever-works/linkup-plugin 1.0.0 → 1.0.2
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/dist/index.cjs +339 -0
- package/dist/index.d.cts +28 -0
- package/dist/index.d.ts +28 -0
- package/dist/index.js +334 -0
- package/package.json +88 -75
- package/LICENSE +0 -661
- package/src/__tests__/linkup.plugin.spec.ts +0 -297
- package/src/index.ts +0 -2
- package/src/linkup.plugin.ts +0 -369
- package/tsconfig.json +0 -22
- package/tsup.config.ts +0 -12
|
@@ -1,297 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest';
|
|
2
|
-
import { LinkupSearchPlugin } from '../linkup.plugin.js';
|
|
3
|
-
import type { PluginContext, SearchOptions, ContentExtractionOptions } from '@ever-works/plugin';
|
|
4
|
-
|
|
5
|
-
const buildContext = (settings: Record<string, unknown> = {}): PluginContext =>
|
|
6
|
-
({
|
|
7
|
-
pluginId: 'linkup',
|
|
8
|
-
logger: {
|
|
9
|
-
log: vi.fn(),
|
|
10
|
-
debug: vi.fn(),
|
|
11
|
-
warn: vi.fn(),
|
|
12
|
-
error: vi.fn()
|
|
13
|
-
},
|
|
14
|
-
getSettings: vi.fn().mockResolvedValue(settings)
|
|
15
|
-
}) as unknown as PluginContext;
|
|
16
|
-
|
|
17
|
-
const okResponse = (body: unknown): Response =>
|
|
18
|
-
({
|
|
19
|
-
ok: true,
|
|
20
|
-
status: 200,
|
|
21
|
-
json: () => Promise.resolve(body),
|
|
22
|
-
text: () => Promise.resolve(JSON.stringify(body))
|
|
23
|
-
}) as unknown as Response;
|
|
24
|
-
|
|
25
|
-
const errResponse = (status: number, body = 'error'): Response =>
|
|
26
|
-
({
|
|
27
|
-
ok: false,
|
|
28
|
-
status,
|
|
29
|
-
json: () => Promise.resolve({ error: body }),
|
|
30
|
-
text: () => Promise.resolve(body)
|
|
31
|
-
}) as unknown as Response;
|
|
32
|
-
|
|
33
|
-
describe('LinkupSearchPlugin', () => {
|
|
34
|
-
let plugin: LinkupSearchPlugin;
|
|
35
|
-
let fetchMock: ReturnType<typeof vi.fn>;
|
|
36
|
-
const originalFetch = globalThis.fetch;
|
|
37
|
-
|
|
38
|
-
beforeEach(() => {
|
|
39
|
-
plugin = new LinkupSearchPlugin();
|
|
40
|
-
fetchMock = vi.fn();
|
|
41
|
-
globalThis.fetch = fetchMock as unknown as typeof fetch;
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
afterEach(() => {
|
|
45
|
-
globalThis.fetch = originalFetch;
|
|
46
|
-
vi.clearAllMocks();
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
describe('metadata', () => {
|
|
50
|
-
it('exposes stable identity fields', () => {
|
|
51
|
-
expect(plugin.id).toBe('linkup');
|
|
52
|
-
expect(plugin.name).toBe('Linkup');
|
|
53
|
-
expect(plugin.category).toBe('search');
|
|
54
|
-
expect(plugin.providerName).toBe('Linkup');
|
|
55
|
-
expect(plugin.version).toBe('1.0.0');
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
it('declares both search and content-extractor capabilities', () => {
|
|
59
|
-
expect(plugin.capabilities).toEqual(['search', 'content-extractor']);
|
|
60
|
-
});
|
|
61
|
-
|
|
62
|
-
it('uses hybrid configuration mode', () => {
|
|
63
|
-
expect(plugin.configurationMode).toBe('hybrid');
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
describe('settingsSchema', () => {
|
|
68
|
-
it('requires apiKey and marks it as a user-scoped secret', () => {
|
|
69
|
-
expect(plugin.settingsSchema.required).toContain('apiKey');
|
|
70
|
-
const props = plugin.settingsSchema.properties as Record<string, Record<string, unknown>>;
|
|
71
|
-
expect(props.apiKey['x-secret']).toBe(true);
|
|
72
|
-
expect(props.apiKey['x-scope']).toBe('user');
|
|
73
|
-
expect(props.apiKey['x-envVar']).toBe('PLUGIN_LINKUP_API_KEY');
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
describe('search', () => {
|
|
78
|
-
const opts = (overrides: Partial<SearchOptions> = {}): SearchOptions => ({
|
|
79
|
-
query: 'hello',
|
|
80
|
-
settings: { apiKey: 'k' },
|
|
81
|
-
...overrides
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
it('throws when apiKey is missing', async () => {
|
|
85
|
-
await expect(plugin.search({ query: 'hello', settings: {} })).rejects.toThrow(/API key not configured/i);
|
|
86
|
-
expect(fetchMock).not.toHaveBeenCalled();
|
|
87
|
-
});
|
|
88
|
-
|
|
89
|
-
it('returns mapped results from data.results on success', async () => {
|
|
90
|
-
fetchMock.mockResolvedValueOnce(
|
|
91
|
-
okResponse({
|
|
92
|
-
results: [
|
|
93
|
-
{ name: 'Result A', url: 'https://a.example', content: 'snippet a' },
|
|
94
|
-
{ name: 'Result B', url: 'https://b.example', content: 'snippet b' }
|
|
95
|
-
]
|
|
96
|
-
})
|
|
97
|
-
);
|
|
98
|
-
const r = await plugin.search(opts());
|
|
99
|
-
expect(r.results).toHaveLength(2);
|
|
100
|
-
expect(r.results[0]).toMatchObject({
|
|
101
|
-
title: 'Result A',
|
|
102
|
-
url: 'https://a.example',
|
|
103
|
-
snippet: 'snippet a',
|
|
104
|
-
position: 1
|
|
105
|
-
});
|
|
106
|
-
expect(r.totalResults).toBe(2);
|
|
107
|
-
expect(r.hasMore).toBe(false);
|
|
108
|
-
expect(typeof r.duration).toBe('number');
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it('falls back to data.sources when results is missing', async () => {
|
|
112
|
-
fetchMock.mockResolvedValueOnce(
|
|
113
|
-
okResponse({
|
|
114
|
-
sources: [{ name: 'Source A', url: 'https://s.example', snippet: 'src snippet' }]
|
|
115
|
-
})
|
|
116
|
-
);
|
|
117
|
-
const r = await plugin.search(opts());
|
|
118
|
-
expect(r.results).toHaveLength(1);
|
|
119
|
-
expect(r.results[0]).toMatchObject({
|
|
120
|
-
title: 'Source A',
|
|
121
|
-
url: 'https://s.example',
|
|
122
|
-
snippet: 'src snippet'
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('forwards Bearer apiKey and JSON body with includeDomains/excludeDomains', async () => {
|
|
127
|
-
fetchMock.mockResolvedValueOnce(okResponse({ results: [] }));
|
|
128
|
-
await plugin.search(
|
|
129
|
-
opts({
|
|
130
|
-
includeDomains: ['a.com'],
|
|
131
|
-
excludeDomains: ['b.com']
|
|
132
|
-
})
|
|
133
|
-
);
|
|
134
|
-
const [url, init] = fetchMock.mock.calls[0] as [string, RequestInit];
|
|
135
|
-
expect(url).toBe('https://api.linkup.so/v1/search');
|
|
136
|
-
expect(init.method).toBe('POST');
|
|
137
|
-
expect((init.headers as Record<string, string>).Authorization).toBe('Bearer k');
|
|
138
|
-
const body = JSON.parse(init.body as string);
|
|
139
|
-
expect(body.q).toBe('hello');
|
|
140
|
-
expect(body.depth).toBe('deep');
|
|
141
|
-
expect(body.outputType).toBe('searchResults');
|
|
142
|
-
expect(body.includeDomains).toEqual(['a.com']);
|
|
143
|
-
expect(body.excludeDomains).toEqual(['b.com']);
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it('throws and logs when the upstream returns non-OK', async () => {
|
|
147
|
-
await plugin.onLoad(buildContext());
|
|
148
|
-
fetchMock.mockResolvedValueOnce(errResponse(500, 'oops'));
|
|
149
|
-
await expect(plugin.search(opts())).rejects.toThrow(/Linkup search failed with status 500/);
|
|
150
|
-
});
|
|
151
|
-
});
|
|
152
|
-
|
|
153
|
-
describe('isAvailable', () => {
|
|
154
|
-
it('returns false without context', async () => {
|
|
155
|
-
expect(await plugin.isAvailable()).toBe(false);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('reflects whether settings has an apiKey', async () => {
|
|
159
|
-
await plugin.onLoad(buildContext({ apiKey: 'k' }));
|
|
160
|
-
expect(await plugin.isAvailable()).toBe(true);
|
|
161
|
-
|
|
162
|
-
await plugin.onLoad(buildContext({}));
|
|
163
|
-
expect(await plugin.isAvailable()).toBe(false);
|
|
164
|
-
});
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
describe('validateConnection', () => {
|
|
168
|
-
it('fails fast without an apiKey', async () => {
|
|
169
|
-
const r = await plugin.validateConnection({});
|
|
170
|
-
expect(r.success).toBe(false);
|
|
171
|
-
expect(r.message).toMatch(/not configured/i);
|
|
172
|
-
expect(fetchMock).not.toHaveBeenCalled();
|
|
173
|
-
});
|
|
174
|
-
|
|
175
|
-
it('returns success on a 200 response', async () => {
|
|
176
|
-
fetchMock.mockResolvedValueOnce(okResponse({ results: [] }));
|
|
177
|
-
const r = await plugin.validateConnection({ apiKey: 'k' });
|
|
178
|
-
expect(r.success).toBe(true);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
it('returns failure on a non-OK response', async () => {
|
|
182
|
-
fetchMock.mockResolvedValueOnce(errResponse(401, 'unauthorized'));
|
|
183
|
-
const r = await plugin.validateConnection({ apiKey: 'k' });
|
|
184
|
-
expect(r.success).toBe(false);
|
|
185
|
-
expect(r.message).toMatch(/401/);
|
|
186
|
-
});
|
|
187
|
-
|
|
188
|
-
it('returns failure when fetch throws', async () => {
|
|
189
|
-
fetchMock.mockRejectedValueOnce(new Error('network down'));
|
|
190
|
-
const r = await plugin.validateConnection({ apiKey: 'k' });
|
|
191
|
-
expect(r.success).toBe(false);
|
|
192
|
-
expect(r.message).toMatch(/network down/);
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
describe('getRateLimitInfo', () => {
|
|
197
|
-
it('reports the documented Linkup rate limit', async () => {
|
|
198
|
-
const info = await plugin.getRateLimitInfo();
|
|
199
|
-
expect(info.remaining).toBe(-1);
|
|
200
|
-
expect(info.limit).toBe(10);
|
|
201
|
-
expect(info.period).toBe('second');
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
describe('extract', () => {
|
|
206
|
-
const opts = (overrides: Partial<ContentExtractionOptions> = {}): ContentExtractionOptions => ({
|
|
207
|
-
url: 'https://example.com/post',
|
|
208
|
-
settings: { apiKey: 'k' },
|
|
209
|
-
...overrides
|
|
210
|
-
});
|
|
211
|
-
|
|
212
|
-
it('returns success with markdown and word count', async () => {
|
|
213
|
-
fetchMock.mockResolvedValueOnce(okResponse({ markdown: 'one two three' }));
|
|
214
|
-
const r = await plugin.extract(opts());
|
|
215
|
-
expect(r.success).toBe(true);
|
|
216
|
-
expect(r.url).toBe('https://example.com/post');
|
|
217
|
-
expect(r.markdown).toBe('one two three');
|
|
218
|
-
expect(r.wordCount).toBe(3);
|
|
219
|
-
});
|
|
220
|
-
|
|
221
|
-
it('returns failure when markdown is missing', async () => {
|
|
222
|
-
fetchMock.mockResolvedValueOnce(okResponse({}));
|
|
223
|
-
const r = await plugin.extract(opts());
|
|
224
|
-
expect(r.success).toBe(false);
|
|
225
|
-
expect(r.error).toMatch(/No content extracted/);
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
it('returns failure on a non-OK fetch response', async () => {
|
|
229
|
-
fetchMock.mockResolvedValueOnce(errResponse(503, 'unavailable'));
|
|
230
|
-
const r = await plugin.extract(opts());
|
|
231
|
-
expect(r.success).toBe(false);
|
|
232
|
-
expect(r.error).toMatch(/Linkup fetch failed with status 503/);
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
it('returns failure when fetch throws', async () => {
|
|
236
|
-
fetchMock.mockRejectedValueOnce(new Error('boom'));
|
|
237
|
-
const r = await plugin.extract(opts());
|
|
238
|
-
expect(r.success).toBe(false);
|
|
239
|
-
expect(r.error).toMatch(/boom/);
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
describe('extractBatch', () => {
|
|
244
|
-
it('runs each URL through extract', async () => {
|
|
245
|
-
fetchMock
|
|
246
|
-
.mockResolvedValueOnce(okResponse({ markdown: 'a' }))
|
|
247
|
-
.mockResolvedValueOnce(okResponse({ markdown: 'b' }));
|
|
248
|
-
const r = await plugin.extractBatch(['https://a', 'https://b'], { settings: { apiKey: 'k' } });
|
|
249
|
-
expect(r).toHaveLength(2);
|
|
250
|
-
expect(r[0].success).toBe(true);
|
|
251
|
-
expect(r[1].success).toBe(true);
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
describe('canExtract / getSupportedFormats', () => {
|
|
256
|
-
it('accepts http and https URLs', async () => {
|
|
257
|
-
expect(await plugin.canExtract('https://example.com')).toBe(true);
|
|
258
|
-
expect(await plugin.canExtract('http://example.com')).toBe(true);
|
|
259
|
-
});
|
|
260
|
-
|
|
261
|
-
it('rejects non-http schemes and invalid URLs', async () => {
|
|
262
|
-
expect(await plugin.canExtract('ftp://example.com')).toBe(false);
|
|
263
|
-
expect(await plugin.canExtract('not a url')).toBe(false);
|
|
264
|
-
});
|
|
265
|
-
|
|
266
|
-
it('exposes text + markdown formats', () => {
|
|
267
|
-
expect(plugin.getSupportedFormats()).toEqual(['text', 'markdown']);
|
|
268
|
-
});
|
|
269
|
-
});
|
|
270
|
-
|
|
271
|
-
describe('lifecycle', () => {
|
|
272
|
-
it('logs on load and clears context on unload', async () => {
|
|
273
|
-
const ctx = buildContext();
|
|
274
|
-
await plugin.onLoad(ctx);
|
|
275
|
-
expect(ctx.logger.log).toHaveBeenCalledWith('Linkup Plugin loaded');
|
|
276
|
-
await plugin.onUnload();
|
|
277
|
-
expect(await plugin.isAvailable()).toBe(false);
|
|
278
|
-
});
|
|
279
|
-
});
|
|
280
|
-
|
|
281
|
-
describe('healthCheck + manifest', () => {
|
|
282
|
-
it('reports healthy', async () => {
|
|
283
|
-
const h = await plugin.healthCheck();
|
|
284
|
-
expect(h.status).toBe('healthy');
|
|
285
|
-
});
|
|
286
|
-
|
|
287
|
-
it('returns a manifest aligned with plugin metadata', () => {
|
|
288
|
-
const m = plugin.getManifest();
|
|
289
|
-
expect(m.id).toBe('linkup');
|
|
290
|
-
expect(m.category).toBe('search');
|
|
291
|
-
expect(m.capabilities).toEqual(['search', 'content-extractor']);
|
|
292
|
-
expect(m.builtIn).toBe(true);
|
|
293
|
-
expect(m.systemPlugin).toBe(false);
|
|
294
|
-
expect(m.autoEnable).toBe(false);
|
|
295
|
-
});
|
|
296
|
-
});
|
|
297
|
-
});
|
package/src/index.ts
DELETED
package/src/linkup.plugin.ts
DELETED
|
@@ -1,369 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
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
DELETED