@aliou/pi-linkup 0.6.1 → 0.6.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/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/client.ts +27 -15
- package/src/tools/web-answer.ts +2 -1
- package/src/tools/web-fetch.ts +2 -1
- package/src/tools/web-search.ts +2 -1
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/client.ts
CHANGED
|
@@ -28,9 +28,11 @@ export class LinkupClient {
|
|
|
28
28
|
private async request<T>(
|
|
29
29
|
endpoint: string,
|
|
30
30
|
options: RequestInit = {},
|
|
31
|
+
signal?: AbortSignal,
|
|
31
32
|
): Promise<T> {
|
|
32
33
|
const response = await fetch(`${BASE_URL}${endpoint}`, {
|
|
33
34
|
...options,
|
|
35
|
+
signal,
|
|
34
36
|
headers: {
|
|
35
37
|
Authorization: `Bearer ${this.apiKey}`,
|
|
36
38
|
"Content-Type": "application/json",
|
|
@@ -54,28 +56,38 @@ export class LinkupClient {
|
|
|
54
56
|
query: string;
|
|
55
57
|
depth: SearchDepthType;
|
|
56
58
|
outputType: "searchResults" | "sourcedAnswer";
|
|
59
|
+
signal?: AbortSignal;
|
|
57
60
|
}): Promise<LinkupSearchResponse | LinkupSourcedAnswerResponse> {
|
|
58
|
-
return this.request(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
61
|
+
return this.request(
|
|
62
|
+
"/search",
|
|
63
|
+
{
|
|
64
|
+
method: "POST",
|
|
65
|
+
body: JSON.stringify({
|
|
66
|
+
q: params.query,
|
|
67
|
+
depth: params.depth,
|
|
68
|
+
outputType: params.outputType,
|
|
69
|
+
}),
|
|
70
|
+
},
|
|
71
|
+
params.signal,
|
|
72
|
+
);
|
|
66
73
|
}
|
|
67
74
|
|
|
68
75
|
async fetch(params: {
|
|
69
76
|
url: string;
|
|
70
77
|
renderJs?: boolean;
|
|
78
|
+
signal?: AbortSignal;
|
|
71
79
|
}): Promise<LinkupFetchResponse> {
|
|
72
|
-
return this.request(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
80
|
+
return this.request(
|
|
81
|
+
"/fetch",
|
|
82
|
+
{
|
|
83
|
+
method: "POST",
|
|
84
|
+
body: JSON.stringify({
|
|
85
|
+
url: params.url,
|
|
86
|
+
renderJs: params.renderJs ?? true,
|
|
87
|
+
}),
|
|
88
|
+
},
|
|
89
|
+
params.signal,
|
|
90
|
+
);
|
|
79
91
|
}
|
|
80
92
|
|
|
81
93
|
async getBalance(): Promise<LinkupBalanceResponse> {
|
package/src/tools/web-answer.ts
CHANGED
|
@@ -26,7 +26,7 @@ export function registerWebAnswerTool(pi: ExtensionAPI) {
|
|
|
26
26
|
depth: Type.Optional(SearchDepth),
|
|
27
27
|
}),
|
|
28
28
|
|
|
29
|
-
async execute(_toolCallId, params,
|
|
29
|
+
async execute(_toolCallId, params, signal, onUpdate, _ctx) {
|
|
30
30
|
const client = getClient();
|
|
31
31
|
|
|
32
32
|
try {
|
|
@@ -44,6 +44,7 @@ export function registerWebAnswerTool(pi: ExtensionAPI) {
|
|
|
44
44
|
query: params.query,
|
|
45
45
|
depth: (params.depth ?? "standard") as SearchDepthType,
|
|
46
46
|
outputType: "sourcedAnswer",
|
|
47
|
+
signal,
|
|
47
48
|
})) as LinkupSourcedAnswerResponse;
|
|
48
49
|
|
|
49
50
|
let content = `${response.answer}\n\n`;
|
package/src/tools/web-fetch.ts
CHANGED
|
@@ -28,7 +28,7 @@ export function registerWebFetchTool(pi: ExtensionAPI) {
|
|
|
28
28
|
),
|
|
29
29
|
}),
|
|
30
30
|
|
|
31
|
-
async execute(_toolCallId, params,
|
|
31
|
+
async execute(_toolCallId, params, signal, onUpdate, _ctx) {
|
|
32
32
|
const client = getClient();
|
|
33
33
|
|
|
34
34
|
try {
|
|
@@ -45,6 +45,7 @@ export function registerWebFetchTool(pi: ExtensionAPI) {
|
|
|
45
45
|
const response = await client.fetch({
|
|
46
46
|
url: params.url,
|
|
47
47
|
renderJs: params.renderJs,
|
|
48
|
+
signal,
|
|
48
49
|
});
|
|
49
50
|
|
|
50
51
|
return {
|
package/src/tools/web-search.ts
CHANGED
|
@@ -25,7 +25,7 @@ export function registerWebSearchTool(pi: ExtensionAPI) {
|
|
|
25
25
|
depth: Type.Optional(SearchDepth),
|
|
26
26
|
}),
|
|
27
27
|
|
|
28
|
-
async execute(_toolCallId, params,
|
|
28
|
+
async execute(_toolCallId, params, signal, onUpdate, _ctx) {
|
|
29
29
|
const client = getClient();
|
|
30
30
|
|
|
31
31
|
try {
|
|
@@ -43,6 +43,7 @@ export function registerWebSearchTool(pi: ExtensionAPI) {
|
|
|
43
43
|
query: params.query,
|
|
44
44
|
depth: (params.depth ?? "standard") as SearchDepthType,
|
|
45
45
|
outputType: "searchResults",
|
|
46
|
+
signal,
|
|
46
47
|
})) as LinkupSearchResponse;
|
|
47
48
|
|
|
48
49
|
let content = `Found ${response.results.length} result(s):\n\n`;
|