@tachu/extensions 1.0.0-beta.1 → 1.0.0-rc.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.
Files changed (243) hide show
  1. package/CHANGELOG.md +48 -65
  2. package/README.md +83 -708
  3. package/README_ZH.md +82 -696
  4. package/dist/backends/file.d.ts +6 -6
  5. package/dist/backends/file.d.ts.map +1 -1
  6. package/dist/backends/file.js +27 -11
  7. package/dist/backends/file.js.map +1 -1
  8. package/dist/backends/terminal.d.ts +6 -6
  9. package/dist/backends/terminal.d.ts.map +1 -1
  10. package/dist/backends/terminal.js +31 -7
  11. package/dist/backends/terminal.js.map +1 -1
  12. package/dist/backends/web.d.ts +6 -6
  13. package/dist/backends/web.d.ts.map +1 -1
  14. package/dist/backends/web.js +10 -8
  15. package/dist/backends/web.js.map +1 -1
  16. package/dist/common/net.d.ts +8 -0
  17. package/dist/common/net.d.ts.map +1 -1
  18. package/dist/common/net.js +39 -24
  19. package/dist/common/net.js.map +1 -1
  20. package/dist/common/path.d.ts +38 -5
  21. package/dist/common/path.d.ts.map +1 -1
  22. package/dist/common/path.js +55 -13
  23. package/dist/common/path.js.map +1 -1
  24. package/dist/common/process.js.map +1 -1
  25. package/dist/index.d.ts +7 -3
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +7 -3
  28. package/dist/index.js.map +1 -1
  29. package/dist/mcp/sse-adapter.d.ts +45 -33
  30. package/dist/mcp/sse-adapter.d.ts.map +1 -1
  31. package/dist/mcp/sse-adapter.js +59 -34
  32. package/dist/mcp/sse-adapter.js.map +1 -1
  33. package/dist/mcp/stdio-adapter.d.ts +45 -33
  34. package/dist/mcp/stdio-adapter.d.ts.map +1 -1
  35. package/dist/mcp/stdio-adapter.js +59 -34
  36. package/dist/mcp/stdio-adapter.js.map +1 -1
  37. package/dist/memory/fs-memory-system.d.ts +288 -0
  38. package/dist/memory/fs-memory-system.d.ts.map +1 -0
  39. package/dist/memory/fs-memory-system.js +482 -0
  40. package/dist/memory/fs-memory-system.js.map +1 -0
  41. package/dist/memory/index.d.ts +5 -0
  42. package/dist/memory/index.d.ts.map +1 -0
  43. package/dist/memory/index.js +5 -0
  44. package/dist/memory/index.js.map +1 -0
  45. package/dist/memory/projection-outbox.d.ts +69 -0
  46. package/dist/memory/projection-outbox.d.ts.map +1 -0
  47. package/dist/memory/projection-outbox.js +187 -0
  48. package/dist/memory/projection-outbox.js.map +1 -0
  49. package/dist/memory/projection-projector.d.ts +16 -0
  50. package/dist/memory/projection-projector.d.ts.map +1 -0
  51. package/dist/memory/projection-projector.js +56 -0
  52. package/dist/memory/projection-projector.js.map +1 -0
  53. package/dist/memory/projection-worker.d.ts +28 -0
  54. package/dist/memory/projection-worker.d.ts.map +1 -0
  55. package/dist/memory/projection-worker.js +84 -0
  56. package/dist/memory/projection-worker.js.map +1 -0
  57. package/dist/observability/jsonl-emitter.d.ts +25 -25
  58. package/dist/observability/jsonl-emitter.d.ts.map +1 -1
  59. package/dist/observability/jsonl-emitter.js +25 -25
  60. package/dist/observability/jsonl-emitter.js.map +1 -1
  61. package/dist/observability/otel-emitter.d.ts +23 -23
  62. package/dist/observability/otel-emitter.d.ts.map +1 -1
  63. package/dist/observability/otel-emitter.js +39 -30
  64. package/dist/observability/otel-emitter.js.map +1 -1
  65. package/dist/providers/anthropic.d.ts +51 -32
  66. package/dist/providers/anthropic.d.ts.map +1 -1
  67. package/dist/providers/anthropic.js +293 -58
  68. package/dist/providers/anthropic.js.map +1 -1
  69. package/dist/providers/gemini.d.ts +115 -0
  70. package/dist/providers/gemini.d.ts.map +1 -0
  71. package/dist/providers/gemini.js +901 -0
  72. package/dist/providers/gemini.js.map +1 -0
  73. package/dist/providers/index.d.ts +2 -0
  74. package/dist/providers/index.d.ts.map +1 -1
  75. package/dist/providers/index.js +2 -0
  76. package/dist/providers/index.js.map +1 -1
  77. package/dist/providers/mock.d.ts +67 -24
  78. package/dist/providers/mock.d.ts.map +1 -1
  79. package/dist/providers/mock.js +122 -41
  80. package/dist/providers/mock.js.map +1 -1
  81. package/dist/providers/openai.d.ts +70 -35
  82. package/dist/providers/openai.d.ts.map +1 -1
  83. package/dist/providers/openai.js +330 -50
  84. package/dist/providers/openai.js.map +1 -1
  85. package/dist/providers/qwen.d.ts +146 -0
  86. package/dist/providers/qwen.d.ts.map +1 -0
  87. package/dist/providers/qwen.js +672 -0
  88. package/dist/providers/qwen.js.map +1 -0
  89. package/dist/safety/default-gate.d.ts +112 -0
  90. package/dist/safety/default-gate.d.ts.map +1 -0
  91. package/dist/safety/default-gate.js +188 -0
  92. package/dist/safety/default-gate.js.map +1 -0
  93. package/dist/safety/index.d.ts +2 -0
  94. package/dist/safety/index.d.ts.map +1 -0
  95. package/dist/safety/index.js +2 -0
  96. package/dist/safety/index.js.map +1 -0
  97. package/dist/tools/_shared/web-client.d.ts +18 -0
  98. package/dist/tools/_shared/web-client.d.ts.map +1 -0
  99. package/dist/tools/_shared/web-client.js +46 -0
  100. package/dist/tools/_shared/web-client.js.map +1 -0
  101. package/dist/tools/apply-patch/executor.d.ts.map +1 -1
  102. package/dist/tools/apply-patch/executor.js +54 -4
  103. package/dist/tools/apply-patch/executor.js.map +1 -1
  104. package/dist/tools/edit-file/executor.d.ts +32 -0
  105. package/dist/tools/edit-file/executor.d.ts.map +1 -0
  106. package/dist/tools/edit-file/executor.js +84 -0
  107. package/dist/tools/edit-file/executor.js.map +1 -0
  108. package/dist/tools/fetch-url/descriptor.md +6 -0
  109. package/dist/tools/fetch-url/executor.d.ts +8 -0
  110. package/dist/tools/fetch-url/executor.d.ts.map +1 -1
  111. package/dist/tools/fetch-url/executor.js +83 -2
  112. package/dist/tools/fetch-url/executor.js.map +1 -1
  113. package/dist/tools/git-blame/executor.d.ts +24 -0
  114. package/dist/tools/git-blame/executor.d.ts.map +1 -0
  115. package/dist/tools/git-blame/executor.js +76 -0
  116. package/dist/tools/git-blame/executor.js.map +1 -0
  117. package/dist/tools/git-branch/executor.d.ts +22 -0
  118. package/dist/tools/git-branch/executor.d.ts.map +1 -0
  119. package/dist/tools/git-branch/executor.js +81 -0
  120. package/dist/tools/git-branch/executor.js.map +1 -0
  121. package/dist/tools/git-diff/executor.d.ts +37 -0
  122. package/dist/tools/git-diff/executor.d.ts.map +1 -0
  123. package/dist/tools/git-diff/executor.js +156 -0
  124. package/dist/tools/git-diff/executor.js.map +1 -0
  125. package/dist/tools/git-log/executor.d.ts +31 -0
  126. package/dist/tools/git-log/executor.d.ts.map +1 -0
  127. package/dist/tools/git-log/executor.js +65 -0
  128. package/dist/tools/git-log/executor.js.map +1 -0
  129. package/dist/tools/git-show/executor.d.ts +22 -0
  130. package/dist/tools/git-show/executor.d.ts.map +1 -0
  131. package/dist/tools/git-show/executor.js +74 -0
  132. package/dist/tools/git-show/executor.js.map +1 -0
  133. package/dist/tools/git-status/executor.d.ts +25 -0
  134. package/dist/tools/git-status/executor.d.ts.map +1 -0
  135. package/dist/tools/git-status/executor.js +120 -0
  136. package/dist/tools/git-status/executor.js.map +1 -0
  137. package/dist/tools/glob/executor.d.ts +18 -0
  138. package/dist/tools/glob/executor.d.ts.map +1 -0
  139. package/dist/tools/glob/executor.js +47 -0
  140. package/dist/tools/glob/executor.js.map +1 -0
  141. package/dist/tools/index.d.ts +1 -1
  142. package/dist/tools/index.d.ts.map +1 -1
  143. package/dist/tools/index.js +459 -4
  144. package/dist/tools/index.js.map +1 -1
  145. package/dist/tools/list-dir/executor.d.ts.map +1 -1
  146. package/dist/tools/list-dir/executor.js +5 -3
  147. package/dist/tools/list-dir/executor.js.map +1 -1
  148. package/dist/tools/multi-edit/executor.d.ts +29 -0
  149. package/dist/tools/multi-edit/executor.d.ts.map +1 -0
  150. package/dist/tools/multi-edit/executor.js +37 -0
  151. package/dist/tools/multi-edit/executor.js.map +1 -0
  152. package/dist/tools/read-file/executor.d.ts +5 -0
  153. package/dist/tools/read-file/executor.d.ts.map +1 -1
  154. package/dist/tools/read-file/executor.js +49 -5
  155. package/dist/tools/read-file/executor.js.map +1 -1
  156. package/dist/tools/run-shell/executor.d.ts +12 -1
  157. package/dist/tools/run-shell/executor.d.ts.map +1 -1
  158. package/dist/tools/run-shell/executor.js +105 -9
  159. package/dist/tools/run-shell/executor.js.map +1 -1
  160. package/dist/tools/run-tests/executor.d.ts +28 -0
  161. package/dist/tools/run-tests/executor.d.ts.map +1 -0
  162. package/dist/tools/run-tests/executor.js +161 -0
  163. package/dist/tools/run-tests/executor.js.map +1 -0
  164. package/dist/tools/run-typecheck/executor.d.ts +25 -0
  165. package/dist/tools/run-typecheck/executor.d.ts.map +1 -0
  166. package/dist/tools/run-typecheck/executor.js +83 -0
  167. package/dist/tools/run-typecheck/executor.js.map +1 -0
  168. package/dist/tools/search-code/executor.d.ts.map +1 -1
  169. package/dist/tools/search-code/executor.js +60 -30
  170. package/dist/tools/search-code/executor.js.map +1 -1
  171. package/dist/tools/shared.d.ts +26 -0
  172. package/dist/tools/shared.d.ts.map +1 -1
  173. package/dist/tools/shared.js +15 -0
  174. package/dist/tools/shared.js.map +1 -1
  175. package/dist/tools/todo-read/executor.d.ts +20 -0
  176. package/dist/tools/todo-read/executor.d.ts.map +1 -0
  177. package/dist/tools/todo-read/executor.js +26 -0
  178. package/dist/tools/todo-read/executor.js.map +1 -0
  179. package/dist/tools/todo-write/executor.d.ts +21 -0
  180. package/dist/tools/todo-write/executor.d.ts.map +1 -0
  181. package/dist/tools/todo-write/executor.js +38 -0
  182. package/dist/tools/todo-write/executor.js.map +1 -0
  183. package/dist/tools/web-fetch/descriptor.md +198 -0
  184. package/dist/tools/web-fetch/errors.d.ts +32 -0
  185. package/dist/tools/web-fetch/errors.d.ts.map +1 -0
  186. package/dist/tools/web-fetch/errors.js +91 -0
  187. package/dist/tools/web-fetch/errors.js.map +1 -0
  188. package/dist/tools/web-fetch/executor.d.ts +10 -0
  189. package/dist/tools/web-fetch/executor.d.ts.map +1 -0
  190. package/dist/tools/web-fetch/executor.js +191 -0
  191. package/dist/tools/web-fetch/executor.js.map +1 -0
  192. package/dist/tools/web-fetch/index.d.ts +4 -0
  193. package/dist/tools/web-fetch/index.d.ts.map +1 -0
  194. package/dist/tools/web-fetch/index.js +3 -0
  195. package/dist/tools/web-fetch/index.js.map +1 -0
  196. package/dist/tools/web-fetch/types.d.ts +157 -0
  197. package/dist/tools/web-fetch/types.d.ts.map +1 -0
  198. package/dist/tools/web-fetch/types.js +7 -0
  199. package/dist/tools/web-fetch/types.js.map +1 -0
  200. package/dist/tools/web-search/descriptor.md +89 -0
  201. package/dist/tools/web-search/errors.d.ts +33 -0
  202. package/dist/tools/web-search/errors.d.ts.map +1 -0
  203. package/dist/tools/web-search/errors.js +45 -0
  204. package/dist/tools/web-search/errors.js.map +1 -0
  205. package/dist/tools/web-search/executor.d.ts +10 -0
  206. package/dist/tools/web-search/executor.d.ts.map +1 -0
  207. package/dist/tools/web-search/executor.js +185 -0
  208. package/dist/tools/web-search/executor.js.map +1 -0
  209. package/dist/tools/web-search/index.d.ts +4 -0
  210. package/dist/tools/web-search/index.d.ts.map +1 -0
  211. package/dist/tools/web-search/index.js +3 -0
  212. package/dist/tools/web-search/index.js.map +1 -0
  213. package/dist/tools/web-search/types.d.ts +86 -0
  214. package/dist/tools/web-search/types.d.ts.map +1 -0
  215. package/dist/tools/web-search/types.js +7 -0
  216. package/dist/tools/web-search/types.js.map +1 -0
  217. package/dist/tools/write-file/executor.js +3 -3
  218. package/dist/tools/write-file/executor.js.map +1 -1
  219. package/dist/transformers/document-to-text.d.ts +11 -11
  220. package/dist/transformers/document-to-text.d.ts.map +1 -1
  221. package/dist/transformers/document-to-text.js +11 -11
  222. package/dist/transformers/document-to-text.js.map +1 -1
  223. package/dist/transformers/image-to-text.d.ts +15 -15
  224. package/dist/transformers/image-to-text.d.ts.map +1 -1
  225. package/dist/transformers/image-to-text.js +22 -21
  226. package/dist/transformers/image-to-text.js.map +1 -1
  227. package/dist/vector/index.d.ts +4 -2
  228. package/dist/vector/index.d.ts.map +1 -1
  229. package/dist/vector/index.js +2 -2
  230. package/dist/vector/index.js.map +1 -1
  231. package/dist/vector/local-fs-index.d.ts +59 -0
  232. package/dist/vector/local-fs-index.d.ts.map +1 -0
  233. package/dist/vector/local-fs-index.js +216 -0
  234. package/dist/vector/local-fs-index.js.map +1 -0
  235. package/dist/vector/qdrant.d.ts +11 -52
  236. package/dist/vector/qdrant.d.ts.map +1 -1
  237. package/dist/vector/qdrant.js +39 -105
  238. package/dist/vector/qdrant.js.map +1 -1
  239. package/package.json +27 -6
  240. package/dist/vector/local-fs.d.ts +0 -76
  241. package/dist/vector/local-fs.d.ts.map +0 -1
  242. package/dist/vector/local-fs.js +0 -153
  243. package/dist/vector/local-fs.js.map +0 -1
@@ -0,0 +1,157 @@
1
+ /**
2
+ * Web Fetch 工具与 `/v1/extract` 共享的类型(客户端本地复刻,不依赖 `@tachu/web-fetch-server`)。
3
+ *
4
+ * @see packages/web-fetch-server/src/0003b-web-fetch-types.md
5
+ */
6
+ /**
7
+ * POST /v1/extract 请求体。
8
+ * @see packages/web-fetch-server/src/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 packages/web-fetch-server/src/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 packages/web-fetch-server/src/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 packages/web-fetch-server/src/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 packages/web-fetch-server/src/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 packages/web-fetch-server/src/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
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/tools/web-fetch/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,GAAG,EAAE,MAAM,CAAC;IACZ,UAAU,CAAC,EAAE,UAAU,CAAC;IACxB,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,MAAM,CAAC,EAAE,cAAc,CAAC;IACxB,SAAS,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACtC,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC;IACvB,cAAc,CAAC,EAAE,YAAY,EAAE,CAAC;IAChC,OAAO,CAAC,EAAE,OAAO,GAAG,IAAI,CAAC;IACzB,YAAY,CAAC,EAAE,YAAY,CAAC;IAC5B,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,SAAS,GAAG,MAAM,CAAC;AAEvD,MAAM,MAAM,YAAY,GACpB,MAAM,GACN,kBAAkB,GAClB,aAAa,GACb;IAAE,QAAQ,EAAE,MAAM,CAAA;CAAE,GACpB;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,CAAC;AAEvB,MAAM,MAAM,cAAc,GAAG,KAAK,GAAG,IAAI,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CA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fetch 工具与 `/v1/extract` 共享的类型(客户端本地复刻,不依赖 `@tachu/web-fetch-server`)。
3
+ *
4
+ * @see packages/web-fetch-server/src/0003b-web-fetch-types.md
5
+ */
6
+ export {};
7
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/tools/web-fetch/types.ts"],"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 packages/web-fetch-server/src/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 packages/web-fetch-server/src/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 packages/web-fetch-server/src/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 packages/web-fetch-server/src/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 packages/web-fetch-server/src/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 packages/web-fetch-server/src/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 packages/web-fetch-server/src/0003a-web-fetch-api-contract.md §Endpoint 3
7
+ * @see packages/web-fetch-server/src/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"}
@@ -0,0 +1,185 @@
1
+ import { buildWebFetchJsonHeaders, getWebFetchEndpointBase, readWebFetchClientTimeoutMs, } from "../_shared/web-client";
2
+ import { assertNotAborted } from "../shared";
3
+ import { getMalformedResponseError, getNetworkError } from "../web-fetch/errors";
4
+ import { asWebSearchClientError, getSearchTimeoutError, mapSearchServerErrorToClient, } from "./errors";
5
+ function toSearchRequest(input) {
6
+ const { timeoutMs: _timeoutMs, ...rest } = input;
7
+ return {
8
+ ...rest,
9
+ traceId: null,
10
+ };
11
+ }
12
+ function isRecord(value) {
13
+ return typeof value === "object" && value !== null && !Array.isArray(value);
14
+ }
15
+ function isSearchResultExtract(value) {
16
+ if (!isRecord(value))
17
+ return false;
18
+ if (typeof value.status !== "number")
19
+ return false;
20
+ if (value.renderedWith !== "static" && value.renderedWith !== "browser")
21
+ return false;
22
+ if (typeof value.body !== "string")
23
+ return false;
24
+ if (typeof value.wordCount !== "number")
25
+ return false;
26
+ if (typeof value.truncated !== "boolean")
27
+ return false;
28
+ if (!Array.isArray(value.warnings))
29
+ return false;
30
+ if (value.title !== undefined && typeof value.title !== "string")
31
+ return false;
32
+ return true;
33
+ }
34
+ function isSearchResultItem(value) {
35
+ if (!isRecord(value))
36
+ return false;
37
+ if (typeof value.title !== "string")
38
+ return false;
39
+ if (typeof value.url !== "string")
40
+ return false;
41
+ if (typeof value.snippet !== "string")
42
+ return false;
43
+ if (value.publishedAt !== undefined && value.publishedAt !== null && typeof value.publishedAt !== "string") {
44
+ return false;
45
+ }
46
+ if (value.score !== undefined && value.score !== null && typeof value.score !== "number") {
47
+ return false;
48
+ }
49
+ if (value.extract !== undefined && !isSearchResultExtract(value.extract))
50
+ return false;
51
+ return true;
52
+ }
53
+ function isSearchResponse(value) {
54
+ if (!isRecord(value))
55
+ return false;
56
+ if (typeof value.query !== "string")
57
+ return false;
58
+ if (typeof value.provider !== "string")
59
+ return false;
60
+ if (!Array.isArray(value.results))
61
+ return false;
62
+ for (const item of value.results) {
63
+ if (!isSearchResultItem(item))
64
+ return false;
65
+ }
66
+ if (typeof value.totalResults !== "number")
67
+ return false;
68
+ if (typeof value.searchedAtMs !== "number")
69
+ return false;
70
+ if (!Array.isArray(value.warnings))
71
+ return false;
72
+ if (typeof value.traceId !== "string")
73
+ return false;
74
+ return true;
75
+ }
76
+ function toToolOutput(res) {
77
+ return {
78
+ query: res.query,
79
+ provider: res.provider,
80
+ results: res.results.map((r) => {
81
+ const row = {
82
+ title: r.title,
83
+ url: r.url,
84
+ snippet: r.snippet,
85
+ };
86
+ if (r.publishedAt !== undefined)
87
+ row.publishedAt = r.publishedAt;
88
+ if (r.score !== undefined)
89
+ row.score = r.score;
90
+ if (r.extract !== undefined) {
91
+ row.extract = {
92
+ status: r.extract.status,
93
+ renderedWith: r.extract.renderedWith,
94
+ body: r.extract.body,
95
+ wordCount: r.extract.wordCount,
96
+ truncated: r.extract.truncated,
97
+ warnings: r.extract.warnings,
98
+ };
99
+ if (r.extract.title !== undefined)
100
+ row.extract.title = r.extract.title;
101
+ }
102
+ return row;
103
+ }),
104
+ totalResults: res.totalResults,
105
+ warnings: res.warnings,
106
+ };
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 `POST /v1/search`。
138
+ *
139
+ * @see packages/web-fetch-server/src/0003a-web-fetch-api-contract.md §Endpoint 3
140
+ * @see packages/web-fetch-server/src/0003d-web-fetch-errors.md §2.2
141
+ */
142
+ export async function executeWebSearch(input, ctx) {
143
+ assertNotAborted(ctx.abortSignal);
144
+ const endpoint = getWebFetchEndpointBase();
145
+ const url = `${endpoint}/v1/search`;
146
+ const timeoutMs = readWebFetchClientTimeoutMs(input.timeoutMs);
147
+ const signal = AbortSignal.any([AbortSignal.timeout(timeoutMs), ctx.abortSignal]);
148
+ const headers = buildWebFetchJsonHeaders();
149
+ let response;
150
+ try {
151
+ response = await fetch(url, {
152
+ method: "POST",
153
+ headers,
154
+ body: JSON.stringify(toSearchRequest(input)),
155
+ signal,
156
+ });
157
+ }
158
+ catch (e) {
159
+ if (e instanceof Error && e.name === "AbortError") {
160
+ if (ctx.abortSignal.aborted) {
161
+ throw ctx.abortSignal.reason ?? e;
162
+ }
163
+ throw getSearchTimeoutError(timeoutMs);
164
+ }
165
+ throw asWebSearchClientError(getNetworkError(endpoint, e));
166
+ }
167
+ if (!response.ok) {
168
+ const text = await response.text();
169
+ const parsed = tryParseErrorBody(text);
170
+ throw mapSearchServerErrorToClient(response.status, parsed, { endpoint });
171
+ }
172
+ const text = await response.text();
173
+ let parsedBody;
174
+ try {
175
+ parsedBody = JSON.parse(text);
176
+ }
177
+ catch {
178
+ throw asWebSearchClientError(getMalformedResponseError());
179
+ }
180
+ if (!isSearchResponse(parsedBody)) {
181
+ throw asWebSearchClientError(getMalformedResponseError());
182
+ }
183
+ return toToolOutput(parsedBody);
184
+ }
185
+ //# sourceMappingURL=executor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"executor.js","sourceRoot":"","sources":["../../../src/tools/web-search/executor.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,2BAA2B,GAC5B,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE7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M,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnC,MAAM,MAAM,GAAG,iBAAiB,CAAC,IAAI,CAAC,CAAC;QACvC,MAAM,4BAA4B,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC5E,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,sBAAsB,CAAC,yBAAyB,EAAE,CAAC,CAAC;IAC5D,CAAC;IACD,IAAI,CAAC,gBAAgB,CAAC,UAAU,CAAC,EAAE,CAAC;QAClC,MAAM,sBAAsB,CAAC,yBAAyB,EAAE,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,YAAY,CAAC,UAAU,CAAC,CAAC;AAClC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export { asWebSearchClientError, getSearchTimeoutError, mapSearchServerErrorToClient, WebSearchClientError, } from "./errors";
2
+ export { executeWebSearch } from "./executor";
3
+ export type { SearchRequest, SearchResponse, SearchResultItem, WebSearchToolInput, WebSearchToolOutput, } from "./types";
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tools/web-search/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,4BAA4B,EAC5B,oBAAoB,GACrB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,YAAY,EACV,aAAa,EACb,cAAc,EACd,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,GACpB,MAAM,SAAS,CAAC"}
@@ -0,0 +1,3 @@
1
+ export { asWebSearchClientError, getSearchTimeoutError, mapSearchServerErrorToClient, WebSearchClientError, } from "./errors";
2
+ export { executeWebSearch } from "./executor";
3
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/tools/web-search/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,sBAAsB,EACtB,qBAAqB,EACrB,4BAA4B,EAC5B,oBAAoB,GACrB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}