@tachu/extensions 1.0.0-alpha.1
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 +119 -0
- package/LICENSE +201 -0
- package/README.md +1104 -0
- package/README_ZH.md +1082 -0
- package/dist/backends/file.d.ts +18 -0
- package/dist/backends/file.d.ts.map +1 -0
- package/dist/backends/file.js +85 -0
- package/dist/backends/file.js.map +1 -0
- package/dist/backends/index.d.ts +4 -0
- package/dist/backends/index.d.ts.map +1 -0
- package/dist/backends/index.js +4 -0
- package/dist/backends/index.js.map +1 -0
- package/dist/backends/terminal.d.ts +18 -0
- package/dist/backends/terminal.d.ts.map +1 -0
- package/dist/backends/terminal.js +81 -0
- package/dist/backends/terminal.js.map +1 -0
- package/dist/backends/web.d.ts +18 -0
- package/dist/backends/web.d.ts.map +1 -0
- package/dist/backends/web.js +55 -0
- package/dist/backends/web.js.map +1 -0
- package/dist/common/net.d.ts +39 -0
- package/dist/common/net.d.ts.map +1 -0
- package/dist/common/net.js +177 -0
- package/dist/common/net.js.map +1 -0
- package/dist/common/path.d.ts +51 -0
- package/dist/common/path.d.ts.map +1 -0
- package/dist/common/path.js +76 -0
- package/dist/common/path.js.map +1 -0
- package/dist/common/process.d.ts +19 -0
- package/dist/common/process.d.ts.map +1 -0
- package/dist/common/process.js +67 -0
- package/dist/common/process.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp/index.d.ts +3 -0
- package/dist/mcp/index.d.ts.map +1 -0
- package/dist/mcp/index.js +3 -0
- package/dist/mcp/index.js.map +1 -0
- package/dist/mcp/sse-adapter.d.ts +82 -0
- package/dist/mcp/sse-adapter.d.ts.map +1 -0
- package/dist/mcp/sse-adapter.js +201 -0
- package/dist/mcp/sse-adapter.js.map +1 -0
- package/dist/mcp/stdio-adapter.d.ts +85 -0
- package/dist/mcp/stdio-adapter.d.ts.map +1 -0
- package/dist/mcp/stdio-adapter.js +203 -0
- package/dist/mcp/stdio-adapter.js.map +1 -0
- package/dist/memory/fs-memory-system.d.ts +147 -0
- package/dist/memory/fs-memory-system.d.ts.map +1 -0
- package/dist/memory/fs-memory-system.js +266 -0
- package/dist/memory/fs-memory-system.js.map +1 -0
- package/dist/memory/index.d.ts +2 -0
- package/dist/memory/index.d.ts.map +1 -0
- package/dist/memory/index.js +2 -0
- package/dist/memory/index.js.map +1 -0
- package/dist/observability/index.d.ts +3 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +3 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/observability/jsonl-emitter.d.ts +58 -0
- package/dist/observability/jsonl-emitter.d.ts.map +1 -0
- package/dist/observability/jsonl-emitter.js +96 -0
- package/dist/observability/jsonl-emitter.js.map +1 -0
- package/dist/observability/otel-emitter.d.ts +52 -0
- package/dist/observability/otel-emitter.d.ts.map +1 -0
- package/dist/observability/otel-emitter.js +143 -0
- package/dist/observability/otel-emitter.js.map +1 -0
- package/dist/providers/anthropic.d.ts +73 -0
- package/dist/providers/anthropic.d.ts.map +1 -0
- package/dist/providers/anthropic.js +521 -0
- package/dist/providers/anthropic.js.map +1 -0
- package/dist/providers/index.d.ts +5 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +5 -0
- package/dist/providers/index.js.map +1 -0
- package/dist/providers/mock.d.ts +81 -0
- package/dist/providers/mock.d.ts.map +1 -0
- package/dist/providers/mock.js +160 -0
- package/dist/providers/mock.js.map +1 -0
- package/dist/providers/openai.d.ts +95 -0
- package/dist/providers/openai.d.ts.map +1 -0
- package/dist/providers/openai.js +529 -0
- package/dist/providers/openai.js.map +1 -0
- package/dist/providers/qwen.d.ts +145 -0
- package/dist/providers/qwen.d.ts.map +1 -0
- package/dist/providers/qwen.js +669 -0
- package/dist/providers/qwen.js.map +1 -0
- package/dist/rules/index.d.ts +9 -0
- package/dist/rules/index.d.ts.map +1 -0
- package/dist/rules/index.js +15 -0
- package/dist/rules/index.js.map +1 -0
- package/dist/rules/no-hallucination.md +11 -0
- package/dist/rules/no-sensitive-output.md +11 -0
- package/dist/rules/prefer-concise-response.md +11 -0
- package/dist/rules/require-tool-verification.md +11 -0
- package/dist/safety/default-gate.d.ts +112 -0
- package/dist/safety/default-gate.d.ts.map +1 -0
- package/dist/safety/default-gate.js +188 -0
- package/dist/safety/default-gate.js.map +1 -0
- package/dist/safety/index.d.ts +2 -0
- package/dist/safety/index.d.ts.map +1 -0
- package/dist/safety/index.js +2 -0
- package/dist/safety/index.js.map +1 -0
- package/dist/tools/_shared/web-client.d.ts +18 -0
- package/dist/tools/_shared/web-client.d.ts.map +1 -0
- package/dist/tools/_shared/web-client.js +46 -0
- package/dist/tools/_shared/web-client.js.map +1 -0
- package/dist/tools/apply-patch/descriptor.md +27 -0
- package/dist/tools/apply-patch/executor.d.ts +19 -0
- package/dist/tools/apply-patch/executor.d.ts.map +1 -0
- package/dist/tools/apply-patch/executor.js +193 -0
- package/dist/tools/apply-patch/executor.js.map +1 -0
- package/dist/tools/fetch-url/descriptor.md +44 -0
- package/dist/tools/fetch-url/executor.d.ts +28 -0
- package/dist/tools/fetch-url/executor.d.ts.map +1 -0
- package/dist/tools/fetch-url/executor.js +115 -0
- package/dist/tools/fetch-url/executor.js.map +1 -0
- package/dist/tools/index.d.ts +12 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +286 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/list-dir/descriptor.md +29 -0
- package/dist/tools/list-dir/executor.d.ts +22 -0
- package/dist/tools/list-dir/executor.d.ts.map +1 -0
- package/dist/tools/list-dir/executor.js +48 -0
- package/dist/tools/list-dir/executor.js.map +1 -0
- package/dist/tools/read-file/descriptor.md +28 -0
- package/dist/tools/read-file/executor.d.ts +15 -0
- package/dist/tools/read-file/executor.d.ts.map +1 -0
- package/dist/tools/read-file/executor.js +22 -0
- package/dist/tools/read-file/executor.js.map +1 -0
- package/dist/tools/run-shell/descriptor.md +39 -0
- package/dist/tools/run-shell/executor.d.ts +20 -0
- package/dist/tools/run-shell/executor.d.ts.map +1 -0
- package/dist/tools/run-shell/executor.js +76 -0
- package/dist/tools/run-shell/executor.js.map +1 -0
- package/dist/tools/search-code/descriptor.md +31 -0
- package/dist/tools/search-code/executor.d.ts +23 -0
- package/dist/tools/search-code/executor.d.ts.map +1 -0
- package/dist/tools/search-code/executor.js +122 -0
- package/dist/tools/search-code/executor.js.map +1 -0
- package/dist/tools/shared.d.ts +47 -0
- package/dist/tools/shared.d.ts.map +1 -0
- package/dist/tools/shared.js +27 -0
- package/dist/tools/shared.js.map +1 -0
- package/dist/tools/web-fetch/descriptor.md +198 -0
- package/dist/tools/web-fetch/errors.d.ts +32 -0
- package/dist/tools/web-fetch/errors.d.ts.map +1 -0
- package/dist/tools/web-fetch/errors.js +91 -0
- package/dist/tools/web-fetch/errors.js.map +1 -0
- package/dist/tools/web-fetch/executor.d.ts +10 -0
- package/dist/tools/web-fetch/executor.d.ts.map +1 -0
- package/dist/tools/web-fetch/executor.js +191 -0
- package/dist/tools/web-fetch/executor.js.map +1 -0
- package/dist/tools/web-fetch/index.d.ts +4 -0
- package/dist/tools/web-fetch/index.d.ts.map +1 -0
- package/dist/tools/web-fetch/index.js +3 -0
- package/dist/tools/web-fetch/index.js.map +1 -0
- package/dist/tools/web-fetch/types.d.ts +157 -0
- package/dist/tools/web-fetch/types.d.ts.map +1 -0
- package/dist/tools/web-fetch/types.js +7 -0
- package/dist/tools/web-fetch/types.js.map +1 -0
- package/dist/tools/web-search/descriptor.md +89 -0
- package/dist/tools/web-search/errors.d.ts +33 -0
- package/dist/tools/web-search/errors.d.ts.map +1 -0
- package/dist/tools/web-search/errors.js +45 -0
- package/dist/tools/web-search/errors.js.map +1 -0
- package/dist/tools/web-search/executor.d.ts +10 -0
- package/dist/tools/web-search/executor.d.ts.map +1 -0
- package/dist/tools/web-search/executor.js +185 -0
- package/dist/tools/web-search/executor.js.map +1 -0
- package/dist/tools/web-search/index.d.ts +4 -0
- package/dist/tools/web-search/index.d.ts.map +1 -0
- package/dist/tools/web-search/index.js +3 -0
- package/dist/tools/web-search/index.js.map +1 -0
- package/dist/tools/web-search/types.d.ts +86 -0
- package/dist/tools/web-search/types.d.ts.map +1 -0
- package/dist/tools/web-search/types.js +7 -0
- package/dist/tools/web-search/types.js.map +1 -0
- package/dist/tools/write-file/descriptor.md +30 -0
- package/dist/tools/write-file/executor.d.ts +16 -0
- package/dist/tools/write-file/executor.d.ts.map +1 -0
- package/dist/tools/write-file/executor.js +18 -0
- package/dist/tools/write-file/executor.js.map +1 -0
- package/dist/transformers/document-to-text.d.ts +23 -0
- package/dist/transformers/document-to-text.d.ts.map +1 -0
- package/dist/transformers/document-to-text.js +69 -0
- package/dist/transformers/document-to-text.js.map +1 -0
- package/dist/transformers/image-to-text.d.ts +38 -0
- package/dist/transformers/image-to-text.d.ts.map +1 -0
- package/dist/transformers/image-to-text.js +82 -0
- package/dist/transformers/image-to-text.js.map +1 -0
- package/dist/transformers/index.d.ts +3 -0
- package/dist/transformers/index.d.ts.map +1 -0
- package/dist/transformers/index.js +3 -0
- package/dist/transformers/index.js.map +1 -0
- package/dist/vector/index.d.ts +3 -0
- package/dist/vector/index.d.ts.map +1 -0
- package/dist/vector/index.js +3 -0
- package/dist/vector/index.js.map +1 -0
- package/dist/vector/local-fs.d.ts +76 -0
- package/dist/vector/local-fs.d.ts.map +1 -0
- package/dist/vector/local-fs.js +153 -0
- package/dist/vector/local-fs.js.map +1 -0
- package/dist/vector/qdrant.d.ts +85 -0
- package/dist/vector/qdrant.d.ts.map +1 -0
- package/dist/vector/qdrant.js +208 -0
- package/dist/vector/qdrant.js.map +1 -0
- package/package.json +74 -0
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import { getMalformedResponseError, getNetworkError, getTimeoutError, mapServerErrorToClient, } from "./errors";
|
|
2
|
+
import { assertNotAborted } from "../shared";
|
|
3
|
+
let warnedMissingEndpoint = false;
|
|
4
|
+
function getEndpointBase() {
|
|
5
|
+
const raw = process.env.TACHU_WEB_FETCH_ENDPOINT?.trim();
|
|
6
|
+
if (!raw) {
|
|
7
|
+
if (!warnedMissingEndpoint) {
|
|
8
|
+
warnedMissingEndpoint = true;
|
|
9
|
+
console.warn("[@tachu/extensions/web-fetch] TACHU_WEB_FETCH_ENDPOINT is not set; using default http://127.0.0.1:8787");
|
|
10
|
+
}
|
|
11
|
+
return "http://127.0.0.1:8787";
|
|
12
|
+
}
|
|
13
|
+
return raw.replace(/\/$/, "");
|
|
14
|
+
}
|
|
15
|
+
function readClientTimeoutMs(input) {
|
|
16
|
+
if (input.timeoutMs != null)
|
|
17
|
+
return input.timeoutMs;
|
|
18
|
+
const raw = process.env.TACHU_WEB_FETCH_TIMEOUT_MS?.trim();
|
|
19
|
+
if (!raw)
|
|
20
|
+
return 70000;
|
|
21
|
+
const n = Number(raw);
|
|
22
|
+
return Number.isFinite(n) ? n : 70000;
|
|
23
|
+
}
|
|
24
|
+
function toExtractRequest(input) {
|
|
25
|
+
const { timeoutMs: _timeoutMs, ...rest } = input;
|
|
26
|
+
return {
|
|
27
|
+
...rest,
|
|
28
|
+
traceId: null,
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function isRecord(value) {
|
|
32
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
33
|
+
}
|
|
34
|
+
function isExtractResponse(value) {
|
|
35
|
+
if (!isRecord(value))
|
|
36
|
+
return false;
|
|
37
|
+
const keys = [
|
|
38
|
+
"url",
|
|
39
|
+
"finalUrl",
|
|
40
|
+
"status",
|
|
41
|
+
"renderedWith",
|
|
42
|
+
"renderedAtMs",
|
|
43
|
+
"body",
|
|
44
|
+
"wordCount",
|
|
45
|
+
"truncated",
|
|
46
|
+
"warnings",
|
|
47
|
+
"traceId",
|
|
48
|
+
];
|
|
49
|
+
for (const k of keys) {
|
|
50
|
+
if (!(k in value))
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
if (typeof value.url !== "string")
|
|
54
|
+
return false;
|
|
55
|
+
if (typeof value.finalUrl !== "string")
|
|
56
|
+
return false;
|
|
57
|
+
if (typeof value.status !== "number")
|
|
58
|
+
return false;
|
|
59
|
+
if (value.renderedWith !== "static" && value.renderedWith !== "browser")
|
|
60
|
+
return false;
|
|
61
|
+
if (typeof value.renderedAtMs !== "number")
|
|
62
|
+
return false;
|
|
63
|
+
if (typeof value.body !== "string")
|
|
64
|
+
return false;
|
|
65
|
+
if (typeof value.wordCount !== "number")
|
|
66
|
+
return false;
|
|
67
|
+
if (typeof value.truncated !== "boolean")
|
|
68
|
+
return false;
|
|
69
|
+
if (!Array.isArray(value.warnings))
|
|
70
|
+
return false;
|
|
71
|
+
if (typeof value.traceId !== "string")
|
|
72
|
+
return false;
|
|
73
|
+
return true;
|
|
74
|
+
}
|
|
75
|
+
function toToolOutput(res) {
|
|
76
|
+
const out = {
|
|
77
|
+
url: res.url,
|
|
78
|
+
finalUrl: res.finalUrl,
|
|
79
|
+
status: res.status,
|
|
80
|
+
renderedWith: res.renderedWith,
|
|
81
|
+
body: res.body,
|
|
82
|
+
wordCount: res.wordCount,
|
|
83
|
+
truncated: res.truncated,
|
|
84
|
+
warnings: res.warnings,
|
|
85
|
+
};
|
|
86
|
+
if (res.title !== undefined)
|
|
87
|
+
out.title = res.title;
|
|
88
|
+
if (res.description !== undefined)
|
|
89
|
+
out.description = res.description;
|
|
90
|
+
if (res.siteName !== undefined)
|
|
91
|
+
out.siteName = res.siteName;
|
|
92
|
+
if (res.lang !== undefined)
|
|
93
|
+
out.lang = res.lang;
|
|
94
|
+
if (res.byline !== undefined)
|
|
95
|
+
out.byline = res.byline;
|
|
96
|
+
if (res.publishedTime !== undefined)
|
|
97
|
+
out.publishedTime = res.publishedTime;
|
|
98
|
+
if (res.links !== undefined) {
|
|
99
|
+
out.links = res.links.map((l) => ({ text: l.text, href: l.href }));
|
|
100
|
+
}
|
|
101
|
+
if (res.images !== undefined) {
|
|
102
|
+
out.images = res.images.map((im) => ({ alt: im.alt, src: im.src }));
|
|
103
|
+
}
|
|
104
|
+
if (res.structured !== undefined)
|
|
105
|
+
out.structured = res.structured;
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
function tryParseErrorBody(text) {
|
|
109
|
+
try {
|
|
110
|
+
const parsed = JSON.parse(text);
|
|
111
|
+
if (!isRecord(parsed))
|
|
112
|
+
return null;
|
|
113
|
+
const err = parsed.error;
|
|
114
|
+
if (!isRecord(err))
|
|
115
|
+
return null;
|
|
116
|
+
if (typeof err.code !== "string")
|
|
117
|
+
return null;
|
|
118
|
+
if (typeof err.message !== "string")
|
|
119
|
+
return null;
|
|
120
|
+
if (typeof err.requestId !== "string")
|
|
121
|
+
return null;
|
|
122
|
+
const body = {
|
|
123
|
+
error: {
|
|
124
|
+
code: err.code,
|
|
125
|
+
message: err.message,
|
|
126
|
+
requestId: err.requestId,
|
|
127
|
+
...(isRecord(err.detail) ? { detail: err.detail } : {}),
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
return body;
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
* 调用 Web Fetch Server `/v1/extract`,返回正文与元数据。
|
|
138
|
+
*
|
|
139
|
+
* @see docs/adr/decisions/0003c-web-fetch-config.md §5.1
|
|
140
|
+
* @see docs/adr/decisions/0003d-web-fetch-errors.md §4
|
|
141
|
+
*/
|
|
142
|
+
export async function executeWebFetch(input, ctx) {
|
|
143
|
+
assertNotAborted(ctx.abortSignal);
|
|
144
|
+
const endpoint = getEndpointBase();
|
|
145
|
+
const url = `${endpoint}/v1/extract`;
|
|
146
|
+
const timeoutMs = readClientTimeoutMs(input);
|
|
147
|
+
const signal = AbortSignal.any([AbortSignal.timeout(timeoutMs), ctx.abortSignal]);
|
|
148
|
+
const headers = {
|
|
149
|
+
"Content-Type": "application/json; charset=utf-8",
|
|
150
|
+
};
|
|
151
|
+
const token = process.env.TACHU_WEB_FETCH_TOKEN?.trim();
|
|
152
|
+
if (token) {
|
|
153
|
+
headers.Authorization = `Bearer ${token}`;
|
|
154
|
+
}
|
|
155
|
+
let response;
|
|
156
|
+
try {
|
|
157
|
+
response = await fetch(url, {
|
|
158
|
+
method: "POST",
|
|
159
|
+
headers,
|
|
160
|
+
body: JSON.stringify(toExtractRequest(input)),
|
|
161
|
+
signal,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
catch (e) {
|
|
165
|
+
if (e instanceof Error && e.name === "AbortError") {
|
|
166
|
+
if (ctx.abortSignal.aborted) {
|
|
167
|
+
throw ctx.abortSignal.reason ?? e;
|
|
168
|
+
}
|
|
169
|
+
throw getTimeoutError(timeoutMs);
|
|
170
|
+
}
|
|
171
|
+
throw getNetworkError(endpoint, e);
|
|
172
|
+
}
|
|
173
|
+
if (!response.ok) {
|
|
174
|
+
const text = await response.text();
|
|
175
|
+
const parsed = tryParseErrorBody(text);
|
|
176
|
+
throw mapServerErrorToClient(response.status, parsed, { endpoint });
|
|
177
|
+
}
|
|
178
|
+
const text = await response.text();
|
|
179
|
+
let parsedBody;
|
|
180
|
+
try {
|
|
181
|
+
parsedBody = JSON.parse(text);
|
|
182
|
+
}
|
|
183
|
+
catch {
|
|
184
|
+
throw getMalformedResponseError();
|
|
185
|
+
}
|
|
186
|
+
if (!isExtractResponse(parsedBody)) {
|
|
187
|
+
throw getMalformedResponseError();
|
|
188
|
+
}
|
|
189
|
+
return toToolOutput(parsedBody);
|
|
190
|
+
}
|
|
191
|
+
//# sourceMappingURL=executor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../src/tools/web-fetch/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,eAAe,EACf,eAAe,EACf,sBAAsB,GACvB,MAAM,UAAU,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Ae,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;IACrC,CAAC;IAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE,CAAC;QACjB,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnC,MAAM,MAAM,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;QACvC,MAAM,sBAAsB,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;IACtE,CAAC;IAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;IACnC,IAAI,UAAmB,CAAC;IACxB,IAAI,CAAC;QACH,UAAU,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAY,CAAC;IAC3C,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,yBAAyB,EAAE,CAAC;IACpC,CAAC;IACD,IAAI,CAAC,iBAAiB,CAAC,UAAU,CAAC,EAAE,CAAC;QACnC,MAAM,yBAAyB,EAAE,CAAC;IACpC,CAAC;IACD,OAAO,YAAY,CAAC,UAAU,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { executeWebFetch } from "./executor";
|
|
2
|
+
export { WebFetchClientError, type WebFetchClientErrorCode, type WebFetchClientOnlyErrorCode, } from "./errors";
|
|
3
|
+
export type { CookieInit, ErrorResponseBody, ExtractRequest, ExtractResponse, ImageRef, LinkRef, OutputFormat, RenderMode, ResourceType, ScrollStrategy, WaitStrategy, WebFetchErrorCode, WebFetchToolInput, WebFetchToolOutput, } from "./types";
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/web-fetch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EACL,mBAAmB,EACnB,KAAK,uBAAuB,EAC5B,KAAK,2BAA2B,GACjC,MAAM,UAAU,CAAC;AAClB,YAAY,EACV,UAAU,EACV,iBAAiB,EACjB,cAAc,EACd,eAAe,EACf,QAAQ,EACR,OAAO,EACP,YAAY,EACZ,UAAU,EACV,YAAY,EACZ,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,SAAS,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/web-fetch/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EACL,mBAAmB,GAGpB,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web Fetch 工具与 `/v1/extract` 共享的类型(客户端本地复刻,不依赖 `@tachu/web-fetch-server`)。
|
|
3
|
+
*
|
|
4
|
+
* @see docs/adr/decisions/0003b-web-fetch-types.md
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* POST /v1/extract 请求体。
|
|
8
|
+
* @see docs/adr/decisions/0003a-web-fetch-api-contract.md §Endpoint 2 请求 schema
|
|
9
|
+
*/
|
|
10
|
+
export interface ExtractRequest {
|
|
11
|
+
url: string;
|
|
12
|
+
renderMode?: RenderMode;
|
|
13
|
+
waitFor?: WaitStrategy;
|
|
14
|
+
waitTimeoutMs?: number;
|
|
15
|
+
scroll?: ScrollStrategy;
|
|
16
|
+
userAgent?: string | null;
|
|
17
|
+
extraHeaders?: Record<string, string>;
|
|
18
|
+
cookies?: CookieInit[];
|
|
19
|
+
blockResources?: ResourceType[];
|
|
20
|
+
stealth?: boolean | null;
|
|
21
|
+
outputFormat?: OutputFormat;
|
|
22
|
+
includeLinks?: boolean;
|
|
23
|
+
includeImages?: boolean;
|
|
24
|
+
includeStructured?: boolean;
|
|
25
|
+
maxBodyChars?: number;
|
|
26
|
+
traceId?: string | null;
|
|
27
|
+
}
|
|
28
|
+
export type RenderMode = "static" | "browser" | "auto";
|
|
29
|
+
export type WaitStrategy = "load" | "domcontentloaded" | "networkidle" | {
|
|
30
|
+
selector: string;
|
|
31
|
+
} | {
|
|
32
|
+
timeMs: number;
|
|
33
|
+
};
|
|
34
|
+
export type ScrollStrategy = false | true | {
|
|
35
|
+
steps: number;
|
|
36
|
+
delayMs: number;
|
|
37
|
+
};
|
|
38
|
+
export interface CookieInit {
|
|
39
|
+
name: string;
|
|
40
|
+
value: string;
|
|
41
|
+
domain: string;
|
|
42
|
+
path?: string;
|
|
43
|
+
expires?: number;
|
|
44
|
+
httpOnly?: boolean;
|
|
45
|
+
secure?: boolean;
|
|
46
|
+
sameSite?: "Strict" | "Lax" | "None";
|
|
47
|
+
}
|
|
48
|
+
export type ResourceType = "image" | "font" | "media" | "stylesheet" | "other";
|
|
49
|
+
export type OutputFormat = "markdown" | "text" | "html" | "structured";
|
|
50
|
+
/**
|
|
51
|
+
* POST /v1/extract 成功响应体。
|
|
52
|
+
* @see docs/adr/decisions/0003a-web-fetch-api-contract.md §Endpoint 2 响应 schema
|
|
53
|
+
*/
|
|
54
|
+
export interface ExtractResponse {
|
|
55
|
+
url: string;
|
|
56
|
+
finalUrl: string;
|
|
57
|
+
status: number;
|
|
58
|
+
renderedWith: "static" | "browser";
|
|
59
|
+
renderedAtMs: number;
|
|
60
|
+
title?: string;
|
|
61
|
+
description?: string;
|
|
62
|
+
siteName?: string;
|
|
63
|
+
lang?: string;
|
|
64
|
+
byline?: string;
|
|
65
|
+
publishedTime?: string | null;
|
|
66
|
+
body: string;
|
|
67
|
+
wordCount: number;
|
|
68
|
+
truncated: boolean;
|
|
69
|
+
links?: LinkRef[];
|
|
70
|
+
images?: ImageRef[];
|
|
71
|
+
structured?: Record<string, unknown>;
|
|
72
|
+
warnings: string[];
|
|
73
|
+
traceId: string;
|
|
74
|
+
}
|
|
75
|
+
export interface LinkRef {
|
|
76
|
+
text: string;
|
|
77
|
+
href: string;
|
|
78
|
+
}
|
|
79
|
+
export interface ImageRef {
|
|
80
|
+
alt: string;
|
|
81
|
+
src: string;
|
|
82
|
+
width?: number;
|
|
83
|
+
height?: number;
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* `web-fetch` 工具入参(与 server 侧 {@link ExtractRequest} 字段对齐;`timeoutMs` 仅客户端使用)。
|
|
87
|
+
* @see docs/adr/decisions/0003b-web-fetch-types.md §6.1
|
|
88
|
+
*/
|
|
89
|
+
export interface WebFetchToolInput {
|
|
90
|
+
url: string;
|
|
91
|
+
renderMode?: "static" | "browser" | "auto";
|
|
92
|
+
waitFor?: "load" | "domcontentloaded" | "networkidle" | {
|
|
93
|
+
selector: string;
|
|
94
|
+
} | {
|
|
95
|
+
timeMs: number;
|
|
96
|
+
};
|
|
97
|
+
waitTimeoutMs?: number;
|
|
98
|
+
scroll?: boolean | {
|
|
99
|
+
steps: number;
|
|
100
|
+
delayMs: number;
|
|
101
|
+
};
|
|
102
|
+
outputFormat?: "markdown" | "text" | "html" | "structured";
|
|
103
|
+
includeLinks?: boolean;
|
|
104
|
+
includeImages?: boolean;
|
|
105
|
+
includeStructured?: boolean;
|
|
106
|
+
maxBodyChars?: number;
|
|
107
|
+
stealth?: boolean | null;
|
|
108
|
+
/** client 端整体超时;默认与 `TACHU_WEB_FETCH_TIMEOUT_MS` 或 70000 对齐 */
|
|
109
|
+
timeoutMs?: number;
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* `web-fetch` 工具成功出参(不含服务端追踪字段)。
|
|
113
|
+
* @see docs/adr/decisions/0003b-web-fetch-types.md §6.1
|
|
114
|
+
*/
|
|
115
|
+
export interface WebFetchToolOutput {
|
|
116
|
+
url: string;
|
|
117
|
+
finalUrl: string;
|
|
118
|
+
status: number;
|
|
119
|
+
renderedWith: "static" | "browser";
|
|
120
|
+
title?: string;
|
|
121
|
+
description?: string;
|
|
122
|
+
siteName?: string;
|
|
123
|
+
lang?: string;
|
|
124
|
+
byline?: string;
|
|
125
|
+
publishedTime?: string | null;
|
|
126
|
+
body: string;
|
|
127
|
+
wordCount: number;
|
|
128
|
+
truncated: boolean;
|
|
129
|
+
links?: Array<{
|
|
130
|
+
text: string;
|
|
131
|
+
href: string;
|
|
132
|
+
}>;
|
|
133
|
+
images?: Array<{
|
|
134
|
+
alt: string;
|
|
135
|
+
src: string;
|
|
136
|
+
}>;
|
|
137
|
+
structured?: Record<string, unknown>;
|
|
138
|
+
warnings: string[];
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* 统一错误响应体结构。
|
|
142
|
+
* @see docs/adr/decisions/0003d-web-fetch-errors.md
|
|
143
|
+
*/
|
|
144
|
+
export interface ErrorResponseBody {
|
|
145
|
+
error: {
|
|
146
|
+
code: WebFetchErrorCode;
|
|
147
|
+
message: string;
|
|
148
|
+
detail?: Record<string, unknown>;
|
|
149
|
+
requestId: string;
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* 所有错误码的字面量联合类型。
|
|
154
|
+
* @see docs/adr/decisions/0003b-web-fetch-types.md §4
|
|
155
|
+
*/
|
|
156
|
+
export type WebFetchErrorCode = "INVALID_REQUEST" | "INVALID_URL" | "UNAUTHORIZED" | "FORBIDDEN" | "SSRF_BLOCKED" | "DOMAIN_NOT_ALLOWED" | "REQUEST_TIMEOUT" | "REQUEST_TOO_LARGE" | "RESPONSE_TOO_LARGE" | "RENDER_FAILED" | "RATE_LIMITED" | "INTERNAL_ERROR" | "UPSTREAM_ERROR" | "BROWSER_POOL_EXHAUSTED" | "BROWSER_CRASHED" | "PROVIDER_NOT_CONFIGURED" | "PROVIDER_UPSTREAM_ERROR" | "PROVIDER_TIMEOUT" | "TIMEOUT_WEB_FETCH" | "TIMEOUT_WEB_SEARCH" | "WEB_FETCH_SERVER_UNREACHABLE" | "WEB_FETCH_ENDPOINT_NOT_CONFIGURED";
|
|
157
|
+
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"],"names":[],"mappings":"AAAA;;;;GAIG"}
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
---
|
|
2
|
+
kind: tool
|
|
3
|
+
id: web-search
|
|
4
|
+
name: web-search
|
|
5
|
+
version: "0.1.0"
|
|
6
|
+
category: "web"
|
|
7
|
+
dangerous: false
|
|
8
|
+
description: |
|
|
9
|
+
通过 @tachu/web-fetch-server 调用 POST /v1/search:服务端编排搜索 provider 与可选的 top-N 网页抽取。**v0.1 默认 provider 为 stub**:在未正确配置真实搜索提供方与 API 密钥前,调用将返回 HTTP 503 与错误码 PROVIDER_NOT_CONFIGURED;运维需在服务端设置 WEB_SEARCH_PROVIDER、WEB_SEARCH_PROVIDER_API_KEY 等环境变量后方可获得真实结果。
|
|
10
|
+
sideEffect: readonly
|
|
11
|
+
idempotent: false
|
|
12
|
+
requiresApproval: false
|
|
13
|
+
timeout: 120000
|
|
14
|
+
inputSchema:
|
|
15
|
+
type: object
|
|
16
|
+
properties:
|
|
17
|
+
query:
|
|
18
|
+
type: string
|
|
19
|
+
description: 搜索查询词(必填)
|
|
20
|
+
maxResults:
|
|
21
|
+
type: number
|
|
22
|
+
description: 返回条数;默认 10,上限 30(由服务端校验)
|
|
23
|
+
language:
|
|
24
|
+
type: string
|
|
25
|
+
description: 搜索语言偏好;省略由 provider 决定
|
|
26
|
+
region:
|
|
27
|
+
type: string
|
|
28
|
+
description: 地区偏好;省略由 provider 决定
|
|
29
|
+
timeRange:
|
|
30
|
+
type: string
|
|
31
|
+
enum: [day, week, month, year]
|
|
32
|
+
description: 时间范围过滤
|
|
33
|
+
safeSearch:
|
|
34
|
+
type: string
|
|
35
|
+
enum: [off, moderate, strict]
|
|
36
|
+
description: 安全搜索级别;默认 moderate
|
|
37
|
+
includeDomains:
|
|
38
|
+
type: array
|
|
39
|
+
items:
|
|
40
|
+
type: string
|
|
41
|
+
description: 仅包含这些域名
|
|
42
|
+
excludeDomains:
|
|
43
|
+
type: array
|
|
44
|
+
items:
|
|
45
|
+
type: string
|
|
46
|
+
description: 排除域名
|
|
47
|
+
fetchTopN:
|
|
48
|
+
type: number
|
|
49
|
+
description: 对前 N 条结果执行抽取;0 表示不抽取;上限 5
|
|
50
|
+
fetchOptions:
|
|
51
|
+
type: object
|
|
52
|
+
description: fetchTopN > 0 时透传至抽取管线(如 renderMode、maxBodyChars)
|
|
53
|
+
additionalProperties: true
|
|
54
|
+
timeoutMs:
|
|
55
|
+
type: number
|
|
56
|
+
description: 客户端整体超时毫秒数;默认与 TACHU_WEB_FETCH_TIMEOUT_MS 或 70000 对齐
|
|
57
|
+
required: [query]
|
|
58
|
+
outputSchema:
|
|
59
|
+
type: object
|
|
60
|
+
description: 对应 POST /v1/search 200 响应(省略 searchedAtMs、traceId 等追踪字段)
|
|
61
|
+
properties:
|
|
62
|
+
query:
|
|
63
|
+
type: string
|
|
64
|
+
provider:
|
|
65
|
+
type: string
|
|
66
|
+
results:
|
|
67
|
+
type: array
|
|
68
|
+
totalResults:
|
|
69
|
+
type: number
|
|
70
|
+
warnings:
|
|
71
|
+
type: array
|
|
72
|
+
items:
|
|
73
|
+
type: string
|
|
74
|
+
execute: web-search
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## 行为说明
|
|
78
|
+
|
|
79
|
+
- **Endpoint**:与 `web-fetch` 相同,使用 `TACHU_WEB_FETCH_ENDPOINT`(默认 `http://127.0.0.1:8787`),路径为 `/v1/search`。
|
|
80
|
+
- **鉴权**:可选 `TACHU_WEB_FETCH_TOKEN`,以 `Authorization: Bearer` 发送。
|
|
81
|
+
- **占位行为**:Stage 4 不提供真实第三方搜索;默认 stub 将返回「提供方未配置」,客户端会抛出带中文运维指引的错误。
|
|
82
|
+
|
|
83
|
+
## 与 `web-fetch` 的关系
|
|
84
|
+
|
|
85
|
+
| 维度 | web-search | web-fetch |
|
|
86
|
+
| --- | --- | --- |
|
|
87
|
+
| 能力 | 搜索 + 可选批量抽取 top-N | 单 URL 抽取 / 渲染 |
|
|
88
|
+
| 端点 | `/v1/search` | `/v1/extract` |
|
|
89
|
+
| v0.1 风险 | 默认 PROVIDER_NOT_CONFIGURED | 需可用渲染服务与 SSRF 策略 |
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { WebFetchClientError, type WebFetchClientErrorCode } from "../web-fetch/errors";
|
|
2
|
+
import type { ErrorResponseBody } from "../web-fetch/types";
|
|
3
|
+
/**
|
|
4
|
+
* `web-search` 工具在客户端抛出的错误类型(语义上与 {@link ../web-fetch/errors.WebFetchClientError} 一致)。
|
|
5
|
+
*
|
|
6
|
+
* @see docs/adr/decisions/0003d-web-fetch-errors.md §2.2 / §4
|
|
7
|
+
*/
|
|
8
|
+
export declare class WebSearchClientError extends Error {
|
|
9
|
+
readonly code: WebFetchClientErrorCode;
|
|
10
|
+
readonly userMessage: string;
|
|
11
|
+
readonly detail?: unknown | undefined;
|
|
12
|
+
readonly name = "WebSearchClientError";
|
|
13
|
+
constructor(code: WebFetchClientErrorCode, userMessage: string, detail?: unknown | undefined, options?: {
|
|
14
|
+
cause?: unknown;
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 将 `/v1/search` 的错误响应映射为 {@link WebSearchClientError}。
|
|
19
|
+
* 对 `PROVIDER_NOT_CONFIGURED`(503)提供面向运维的中文指引。
|
|
20
|
+
*
|
|
21
|
+
* @see docs/adr/decisions/0003d-web-fetch-errors.md §2.2
|
|
22
|
+
*/
|
|
23
|
+
export declare function mapSearchServerErrorToClient(httpStatus: number, body: ErrorResponseBody | null, ctx: {
|
|
24
|
+
endpoint: string;
|
|
25
|
+
}): WebSearchClientError;
|
|
26
|
+
/**
|
|
27
|
+
* 客户端整体超时(`TIMEOUT_WEB_SEARCH`)。
|
|
28
|
+
* @see docs/adr/decisions/0003d-web-fetch-errors.md §2.3
|
|
29
|
+
*/
|
|
30
|
+
export declare function getSearchTimeoutError(timeoutMs: number): WebSearchClientError;
|
|
31
|
+
/** 将 {@link WebFetchClientError} 转为本工具统一抛出的错误类型。 */
|
|
32
|
+
export declare function asWebSearchClientError(err: WebFetchClientError): WebSearchClientError;
|
|
33
|
+
//# sourceMappingURL=errors.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/tools/web-search/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,mBAAmB,EACnB,KAAK,uBAAuB,EAC7B,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAE5D;;;;GAIG;AACH,qBAAa,oBAAqB,SAAQ,KAAK;aAI3B,IAAI,EAAE,uBAAuB;aAC7B,WAAW,EAAE,MAAM;aACnB,MAAM,CAAC,EAAE,OAAO;IALlC,QAAQ,CAAC,IAAI,0BAA0B;gBAGrB,IAAI,EAAE,uBAAuB,EAC7B,WAAW,EAAE,MAAM,EACnB,MAAM,CAAC,EAAE,OAAO,YAAA,EAChC,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,OAAO,CAAA;KAAE;CAIhC;AAED;;;;;GAKG;AACH,wBAAgB,4BAA4B,CAC1C,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,iBAAiB,GAAG,IAAI,EAC9B,GAAG,EAAE;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,GACxB,oBAAoB,CAatB;AAED;;;GAGG;AACH,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,MAAM,GAAG,oBAAoB,CAM7E;AAED,oDAAoD;AACpD,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,mBAAmB,GAAG,oBAAoB,CAErF"}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { mapServerErrorToClient, } from "../web-fetch/errors";
|
|
2
|
+
/**
|
|
3
|
+
* `web-search` 工具在客户端抛出的错误类型(语义上与 {@link ../web-fetch/errors.WebFetchClientError} 一致)。
|
|
4
|
+
*
|
|
5
|
+
* @see docs/adr/decisions/0003d-web-fetch-errors.md §2.2 / §4
|
|
6
|
+
*/
|
|
7
|
+
export class WebSearchClientError extends Error {
|
|
8
|
+
code;
|
|
9
|
+
userMessage;
|
|
10
|
+
detail;
|
|
11
|
+
name = "WebSearchClientError";
|
|
12
|
+
constructor(code, userMessage, detail, options) {
|
|
13
|
+
super(userMessage, options);
|
|
14
|
+
this.code = code;
|
|
15
|
+
this.userMessage = userMessage;
|
|
16
|
+
this.detail = detail;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* 将 `/v1/search` 的错误响应映射为 {@link WebSearchClientError}。
|
|
21
|
+
* 对 `PROVIDER_NOT_CONFIGURED`(503)提供面向运维的中文指引。
|
|
22
|
+
*
|
|
23
|
+
* @see docs/adr/decisions/0003d-web-fetch-errors.md §2.2
|
|
24
|
+
*/
|
|
25
|
+
export function mapSearchServerErrorToClient(httpStatus, body, ctx) {
|
|
26
|
+
const mapped = mapServerErrorToClient(httpStatus, body, ctx);
|
|
27
|
+
if (mapped.code === "PROVIDER_NOT_CONFIGURED") {
|
|
28
|
+
return new WebSearchClientError("PROVIDER_NOT_CONFIGURED", "搜索提供方未配置。请在服务器端设置 WEB_SEARCH_PROVIDER、WEB_SEARCH_PROVIDER_API_KEY 等环境变量后重试。", mapped.detail, { cause: mapped.cause });
|
|
29
|
+
}
|
|
30
|
+
return new WebSearchClientError(mapped.code, mapped.userMessage, mapped.detail, {
|
|
31
|
+
cause: mapped.cause,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 客户端整体超时(`TIMEOUT_WEB_SEARCH`)。
|
|
36
|
+
* @see docs/adr/decisions/0003d-web-fetch-errors.md §2.3
|
|
37
|
+
*/
|
|
38
|
+
export function getSearchTimeoutError(timeoutMs) {
|
|
39
|
+
return new WebSearchClientError("TIMEOUT_WEB_SEARCH", "搜索超时。请缩短查询词或减少 fetchTopN 后重试。", { timeoutMs });
|
|
40
|
+
}
|
|
41
|
+
/** 将 {@link WebFetchClientError} 转为本工具统一抛出的错误类型。 */
|
|
42
|
+
export function asWebSearchClientError(err) {
|
|
43
|
+
return new WebSearchClientError(err.code, err.userMessage, err.detail, { cause: err.cause });
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../../src/tools/web-search/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,GAGvB,MAAM,qBAAqB,CAAC;AAG7B;;;;GAIG;AACH,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IAI3B;IACA;IACA;IALT,IAAI,GAAG,sBAAsB,CAAC;IAEvC,YACkB,IAA6B,EAC7B,WAAmB,EACnB,MAAgB,EAChC,OAA6B;QAE7B,KAAK,CAAC,WAAW,EAAE,OAAO,CAAC,CAAC;QALZ,SAAI,GAAJ,IAAI,CAAyB;QAC7B,gBAAW,GAAX,WAAW,CAAQ;QACnB,WAAM,GAAN,MAAM,CAAU;IAIlC,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,UAAU,4BAA4B,CAC1C,UAAkB,EAClB,IAA8B,EAC9B,GAAyB;IAEzB,MAAM,MAAM,GAAG,sBAAsB,CAAC,UAAU,EAAE,IAAI,EAAE,GAAG,CAAC,CAAC;IAC7D,IAAI,MAAM,CAAC,IAAI,KAAK,yBAAyB,EAAE,CAAC;QAC9C,OAAO,IAAI,oBAAoB,CAC7B,yBAAyB,EACzB,6EAA6E,EAC7E,MAAM,CAAC,MAAM,EACb,EAAE,KAAK,EAAE,MAAM,CAAC,KAAK,EAAE,CACxB,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,oBAAoB,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE;QAC9E,KAAK,EAAE,MAAM,CAAC,KAAK;KACpB,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,qBAAqB,CAAC,SAAiB;IACrD,OAAO,IAAI,oBAAoB,CAC7B,oBAAoB,EACpB,+BAA+B,EAC/B,EAAE,SAAS,EAAE,CACd,CAAC;AACJ,CAAC;AAED,oDAAoD;AACpD,MAAM,UAAU,sBAAsB,CAAC,GAAwB;IAC7D,OAAO,IAAI,oBAAoB,CAAC,GAAG,CAAC,IAAI,EAAE,GAAG,CAAC,WAAW,EAAE,GAAG,CAAC,MAAM,EAAE,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,EAAE,CAAC,CAAC;AAC/F,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ToolExecutionContext } from "../shared";
|
|
2
|
+
import type { WebSearchToolInput, WebSearchToolOutput } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* 调用 Web Fetch Server `POST /v1/search`。
|
|
5
|
+
*
|
|
6
|
+
* @see docs/adr/decisions/0003a-web-fetch-api-contract.md §Endpoint 3
|
|
7
|
+
* @see docs/adr/decisions/0003d-web-fetch-errors.md §2.2
|
|
8
|
+
*/
|
|
9
|
+
export declare function executeWebSearch(input: WebSearchToolInput, ctx: ToolExecutionContext): Promise<WebSearchToolOutput>;
|
|
10
|
+
//# sourceMappingURL=executor.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"executor.d.ts","sourceRoot":"","sources":["../../../src/tools/web-search/executor.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAQtD,OAAO,KAAK,EAAiC,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AA+GtG;;;;;GAKG;AACH,wBAAsB,gBAAgB,CACpC,KAAK,EAAE,kBAAkB,EACzB,GAAG,EAAE,oBAAoB,GACxB,OAAO,CAAC,mBAAmB,CAAC,CA6C9B"}
|