recker 1.0.2-0 → 1.0.3

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 (287) hide show
  1. package/LICENSE +0 -2
  2. package/README.md +121 -72
  3. package/dist/cache/memory-storage.d.ts.map +1 -1
  4. package/dist/cache/memory-storage.js +7 -1
  5. package/dist/constants/http-status.d.ts +74 -0
  6. package/dist/constants/http-status.d.ts.map +1 -0
  7. package/dist/constants/http-status.js +156 -0
  8. package/dist/constants.d.ts.map +1 -1
  9. package/dist/constants.js +6 -6
  10. package/dist/cookies/memory-cookie-jar.d.ts +31 -0
  11. package/dist/cookies/memory-cookie-jar.d.ts.map +1 -0
  12. package/dist/cookies/memory-cookie-jar.js +210 -0
  13. package/dist/core/client.d.ts +9 -0
  14. package/dist/core/client.d.ts.map +1 -1
  15. package/dist/core/client.js +252 -53
  16. package/dist/core/errors.d.ts +18 -2
  17. package/dist/core/errors.d.ts.map +1 -1
  18. package/dist/core/errors.js +66 -5
  19. package/dist/core/index.d.ts +6 -0
  20. package/dist/core/index.d.ts.map +1 -0
  21. package/dist/core/index.js +5 -0
  22. package/dist/core/request-promise.d.ts.map +1 -1
  23. package/dist/core/request-promise.js +8 -2
  24. package/dist/core/request.d.ts +7 -1
  25. package/dist/core/request.d.ts.map +1 -1
  26. package/dist/core/request.js +32 -0
  27. package/dist/core/response.d.ts +2 -0
  28. package/dist/core/response.d.ts.map +1 -1
  29. package/dist/core/response.js +44 -19
  30. package/dist/events/request-events.d.ts +48 -0
  31. package/dist/events/request-events.d.ts.map +1 -0
  32. package/dist/events/request-events.js +85 -0
  33. package/dist/index.d.ts +28 -2
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.js +28 -2
  36. package/dist/mcp/client.d.ts.map +1 -1
  37. package/dist/mcp/client.js +16 -5
  38. package/dist/mcp/contract.d.ts +77 -0
  39. package/dist/mcp/contract.d.ts.map +1 -0
  40. package/dist/mcp/contract.js +278 -0
  41. package/dist/mcp/types.d.ts +1 -0
  42. package/dist/mcp/types.d.ts.map +1 -1
  43. package/dist/plugins/auth.d.ts +45 -0
  44. package/dist/plugins/auth.d.ts.map +1 -0
  45. package/dist/plugins/auth.js +268 -0
  46. package/dist/plugins/cache.d.ts +7 -1
  47. package/dist/plugins/cache.d.ts.map +1 -1
  48. package/dist/plugins/cache.js +470 -49
  49. package/dist/plugins/circuit-breaker.js +1 -1
  50. package/dist/plugins/compression.d.ts.map +1 -1
  51. package/dist/plugins/compression.js +3 -3
  52. package/dist/plugins/dedup.d.ts.map +1 -1
  53. package/dist/plugins/dedup.js +2 -1
  54. package/dist/plugins/graphql.d.ts +4 -3
  55. package/dist/plugins/graphql.d.ts.map +1 -1
  56. package/dist/plugins/graphql.js +24 -5
  57. package/dist/plugins/grpc-web.d.ts +80 -0
  58. package/dist/plugins/grpc-web.d.ts.map +1 -0
  59. package/dist/plugins/grpc-web.js +261 -0
  60. package/dist/plugins/har-player.d.ts.map +1 -1
  61. package/dist/plugins/har-player.js +11 -2
  62. package/dist/plugins/hls.d.ts +33 -0
  63. package/dist/plugins/hls.d.ts.map +1 -0
  64. package/dist/plugins/hls.js +225 -0
  65. package/dist/plugins/http2-push.d.ts +64 -0
  66. package/dist/plugins/http2-push.d.ts.map +1 -0
  67. package/dist/plugins/http2-push.js +274 -0
  68. package/dist/plugins/http3.d.ts +76 -0
  69. package/dist/plugins/http3.d.ts.map +1 -0
  70. package/dist/plugins/http3.js +231 -0
  71. package/dist/plugins/interface-rotator.d.ts +10 -0
  72. package/dist/plugins/interface-rotator.d.ts.map +1 -0
  73. package/dist/plugins/interface-rotator.js +57 -0
  74. package/dist/plugins/jsonrpc.d.ts +76 -0
  75. package/dist/plugins/jsonrpc.d.ts.map +1 -0
  76. package/dist/plugins/jsonrpc.js +143 -0
  77. package/dist/plugins/logger.d.ts +8 -5
  78. package/dist/plugins/logger.d.ts.map +1 -1
  79. package/dist/plugins/logger.js +66 -30
  80. package/dist/plugins/odata.d.ts +182 -0
  81. package/dist/plugins/odata.d.ts.map +1 -0
  82. package/dist/plugins/odata.js +561 -0
  83. package/dist/plugins/retry.d.ts +1 -0
  84. package/dist/plugins/retry.d.ts.map +1 -1
  85. package/dist/plugins/retry.js +26 -2
  86. package/dist/plugins/scrape.d.ts +22 -0
  87. package/dist/plugins/scrape.d.ts.map +1 -0
  88. package/dist/plugins/scrape.js +87 -0
  89. package/dist/plugins/soap.d.ts +73 -0
  90. package/dist/plugins/soap.d.ts.map +1 -0
  91. package/dist/plugins/soap.js +347 -0
  92. package/dist/plugins/user-agent.d.ts +8 -0
  93. package/dist/plugins/user-agent.d.ts.map +1 -0
  94. package/dist/plugins/user-agent.js +46 -0
  95. package/dist/plugins/xml.d.ts +10 -0
  96. package/dist/plugins/xml.d.ts.map +1 -0
  97. package/dist/plugins/xml.js +194 -0
  98. package/dist/presets/anthropic.d.ts +7 -0
  99. package/dist/presets/anthropic.d.ts.map +1 -0
  100. package/dist/presets/anthropic.js +17 -0
  101. package/dist/presets/azure-openai.d.ts +9 -0
  102. package/dist/presets/azure-openai.d.ts.map +1 -0
  103. package/dist/presets/azure-openai.js +25 -0
  104. package/dist/presets/cloudflare.d.ts +13 -0
  105. package/dist/presets/cloudflare.d.ts.map +1 -0
  106. package/dist/presets/cloudflare.js +39 -0
  107. package/dist/presets/cohere.d.ts +6 -0
  108. package/dist/presets/cohere.d.ts.map +1 -0
  109. package/dist/presets/cohere.js +16 -0
  110. package/dist/presets/deepseek.d.ts +6 -0
  111. package/dist/presets/deepseek.d.ts.map +1 -0
  112. package/dist/presets/deepseek.js +16 -0
  113. package/dist/presets/digitalocean.d.ts +6 -0
  114. package/dist/presets/digitalocean.d.ts.map +1 -0
  115. package/dist/presets/digitalocean.js +16 -0
  116. package/dist/presets/discord.d.ts +7 -0
  117. package/dist/presets/discord.d.ts.map +1 -0
  118. package/dist/presets/discord.js +17 -0
  119. package/dist/presets/fireworks.d.ts +6 -0
  120. package/dist/presets/fireworks.d.ts.map +1 -0
  121. package/dist/presets/fireworks.js +16 -0
  122. package/dist/presets/gemini.d.ts +6 -0
  123. package/dist/presets/gemini.d.ts.map +1 -0
  124. package/dist/presets/gemini.js +16 -0
  125. package/dist/presets/github.d.ts +7 -0
  126. package/dist/presets/github.d.ts.map +1 -0
  127. package/dist/presets/github.js +17 -0
  128. package/dist/presets/gitlab.d.ts +7 -0
  129. package/dist/presets/gitlab.d.ts.map +1 -0
  130. package/dist/presets/gitlab.js +16 -0
  131. package/dist/presets/groq.d.ts +6 -0
  132. package/dist/presets/groq.d.ts.map +1 -0
  133. package/dist/presets/groq.js +16 -0
  134. package/dist/presets/huggingface.d.ts +6 -0
  135. package/dist/presets/huggingface.d.ts.map +1 -0
  136. package/dist/presets/huggingface.js +16 -0
  137. package/dist/presets/index.d.ts +28 -0
  138. package/dist/presets/index.d.ts.map +1 -0
  139. package/dist/presets/index.js +27 -0
  140. package/dist/presets/linear.d.ts +6 -0
  141. package/dist/presets/linear.d.ts.map +1 -0
  142. package/dist/presets/linear.js +16 -0
  143. package/dist/presets/mistral.d.ts +6 -0
  144. package/dist/presets/mistral.d.ts.map +1 -0
  145. package/dist/presets/mistral.js +16 -0
  146. package/dist/presets/notion.d.ts +7 -0
  147. package/dist/presets/notion.d.ts.map +1 -0
  148. package/dist/presets/notion.js +17 -0
  149. package/dist/presets/openai.d.ts +8 -0
  150. package/dist/presets/openai.d.ts.map +1 -0
  151. package/dist/presets/openai.js +23 -0
  152. package/dist/presets/perplexity.d.ts +6 -0
  153. package/dist/presets/perplexity.d.ts.map +1 -0
  154. package/dist/presets/perplexity.js +16 -0
  155. package/dist/presets/registry.d.ts +20 -0
  156. package/dist/presets/registry.d.ts.map +1 -0
  157. package/dist/presets/registry.js +311 -0
  158. package/dist/presets/replicate.d.ts +6 -0
  159. package/dist/presets/replicate.d.ts.map +1 -0
  160. package/dist/presets/replicate.js +16 -0
  161. package/dist/presets/slack.d.ts +6 -0
  162. package/dist/presets/slack.d.ts.map +1 -0
  163. package/dist/presets/slack.js +16 -0
  164. package/dist/presets/stripe.d.ts +8 -0
  165. package/dist/presets/stripe.d.ts.map +1 -0
  166. package/dist/presets/stripe.js +23 -0
  167. package/dist/presets/supabase.d.ts +7 -0
  168. package/dist/presets/supabase.d.ts.map +1 -0
  169. package/dist/presets/supabase.js +18 -0
  170. package/dist/presets/together.d.ts +6 -0
  171. package/dist/presets/together.d.ts.map +1 -0
  172. package/dist/presets/together.js +16 -0
  173. package/dist/presets/twilio.d.ts +7 -0
  174. package/dist/presets/twilio.d.ts.map +1 -0
  175. package/dist/presets/twilio.js +17 -0
  176. package/dist/presets/vercel.d.ts +7 -0
  177. package/dist/presets/vercel.d.ts.map +1 -0
  178. package/dist/presets/vercel.js +23 -0
  179. package/dist/presets/xai.d.ts +7 -0
  180. package/dist/presets/xai.d.ts.map +1 -0
  181. package/dist/presets/xai.js +17 -0
  182. package/dist/protocols/ftp.d.ts +63 -0
  183. package/dist/protocols/ftp.d.ts.map +1 -0
  184. package/dist/protocols/ftp.js +388 -0
  185. package/dist/protocols/index.d.ts +4 -0
  186. package/dist/protocols/index.d.ts.map +1 -0
  187. package/dist/protocols/index.js +3 -0
  188. package/dist/protocols/sftp.d.ts +65 -0
  189. package/dist/protocols/sftp.d.ts.map +1 -0
  190. package/dist/protocols/sftp.js +346 -0
  191. package/dist/protocols/telnet.d.ts +50 -0
  192. package/dist/protocols/telnet.d.ts.map +1 -0
  193. package/dist/protocols/telnet.js +139 -0
  194. package/dist/runner/request-runner.d.ts.map +1 -1
  195. package/dist/runner/request-runner.js +1 -0
  196. package/dist/scrape/document.d.ts +44 -0
  197. package/dist/scrape/document.d.ts.map +1 -0
  198. package/dist/scrape/document.js +198 -0
  199. package/dist/scrape/element.d.ts +50 -0
  200. package/dist/scrape/element.d.ts.map +1 -0
  201. package/dist/scrape/element.js +176 -0
  202. package/dist/scrape/extractors.d.ts +17 -0
  203. package/dist/scrape/extractors.d.ts.map +1 -0
  204. package/dist/scrape/extractors.js +356 -0
  205. package/dist/scrape/index.d.ts +5 -0
  206. package/dist/scrape/index.d.ts.map +1 -0
  207. package/dist/scrape/index.js +3 -0
  208. package/dist/scrape/types.d.ts +108 -0
  209. package/dist/scrape/types.d.ts.map +1 -0
  210. package/dist/scrape/types.js +1 -0
  211. package/dist/testing/index.d.ts +3 -0
  212. package/dist/testing/index.d.ts.map +1 -0
  213. package/dist/testing/index.js +1 -0
  214. package/dist/testing/mock.d.ts +58 -0
  215. package/dist/testing/mock.d.ts.map +1 -0
  216. package/dist/testing/mock.js +252 -0
  217. package/dist/transport/fetch.d.ts.map +1 -1
  218. package/dist/transport/fetch.js +12 -4
  219. package/dist/transport/undici.d.ts +17 -1
  220. package/dist/transport/undici.d.ts.map +1 -1
  221. package/dist/transport/undici.js +708 -47
  222. package/dist/types/index.d.ts +111 -10
  223. package/dist/types/index.d.ts.map +1 -1
  224. package/dist/types/index.js +1 -1
  225. package/dist/types/logger.d.ts +17 -0
  226. package/dist/types/logger.d.ts.map +1 -0
  227. package/dist/types/logger.js +66 -0
  228. package/dist/utils/agent-manager.d.ts.map +1 -1
  229. package/dist/utils/agent-manager.js +20 -4
  230. package/dist/utils/body.d.ts.map +1 -1
  231. package/dist/utils/body.js +14 -2
  232. package/dist/utils/charset.d.ts +16 -0
  233. package/dist/utils/charset.d.ts.map +1 -0
  234. package/dist/utils/charset.js +169 -0
  235. package/dist/utils/client-pool.d.ts +21 -0
  236. package/dist/utils/client-pool.d.ts.map +1 -0
  237. package/dist/utils/client-pool.js +49 -0
  238. package/dist/utils/concurrency.d.ts.map +1 -1
  239. package/dist/utils/concurrency.js +8 -4
  240. package/dist/utils/dns-toolkit.d.ts +13 -0
  241. package/dist/utils/dns-toolkit.d.ts.map +1 -0
  242. package/dist/utils/dns-toolkit.js +48 -0
  243. package/dist/utils/doh.d.ts.map +1 -1
  244. package/dist/utils/doh.js +16 -3
  245. package/dist/utils/download.d.ts +15 -0
  246. package/dist/utils/download.d.ts.map +1 -0
  247. package/dist/utils/download.js +44 -0
  248. package/dist/utils/env-proxy.d.ts +13 -0
  249. package/dist/utils/env-proxy.d.ts.map +1 -0
  250. package/dist/utils/env-proxy.js +105 -0
  251. package/dist/utils/header-parser.d.ts +15 -1
  252. package/dist/utils/header-parser.d.ts.map +1 -1
  253. package/dist/utils/header-parser.js +161 -1
  254. package/dist/utils/link-header.d.ts +70 -0
  255. package/dist/utils/link-header.d.ts.map +1 -0
  256. package/dist/utils/link-header.js +190 -0
  257. package/dist/utils/progress.d.ts +7 -2
  258. package/dist/utils/progress.d.ts.map +1 -1
  259. package/dist/utils/progress.js +48 -15
  260. package/dist/utils/rdap.d.ts +17 -0
  261. package/dist/utils/rdap.d.ts.map +1 -0
  262. package/dist/utils/rdap.js +32 -0
  263. package/dist/utils/request-pool.d.ts.map +1 -1
  264. package/dist/utils/request-pool.js +4 -3
  265. package/dist/utils/sse.d.ts.map +1 -1
  266. package/dist/utils/sse.js +8 -2
  267. package/dist/utils/status-codes.d.ts +84 -0
  268. package/dist/utils/status-codes.d.ts.map +1 -0
  269. package/dist/utils/status-codes.js +204 -0
  270. package/dist/utils/streaming.d.ts.map +1 -1
  271. package/dist/utils/streaming.js +1 -0
  272. package/dist/utils/tls-inspector.d.ts +21 -0
  273. package/dist/utils/tls-inspector.d.ts.map +1 -0
  274. package/dist/utils/tls-inspector.js +39 -0
  275. package/dist/utils/try-fn.d.ts.map +1 -1
  276. package/dist/utils/try-fn.js +11 -5
  277. package/dist/utils/upload.d.ts +1 -0
  278. package/dist/utils/upload.d.ts.map +1 -1
  279. package/dist/utils/upload.js +20 -3
  280. package/dist/utils/user-agent.d.ts +9 -9
  281. package/dist/utils/user-agent.js +9 -9
  282. package/dist/utils/whois.d.ts.map +1 -1
  283. package/dist/utils/whois.js +11 -2
  284. package/dist/websocket/client.d.ts +29 -1
  285. package/dist/websocket/client.d.ts.map +1 -1
  286. package/dist/websocket/client.js +145 -13
  287. package/package.json +45 -8
@@ -0,0 +1,278 @@
1
+ export class MCPContractError extends Error {
2
+ toolName;
3
+ validationType;
4
+ originalError;
5
+ constructor(toolName, validationType, originalError) {
6
+ super(`MCP Contract Error [${toolName}] ${validationType} validation failed: ${originalError.message}`);
7
+ this.toolName = toolName;
8
+ this.validationType = validationType;
9
+ this.originalError = originalError;
10
+ this.name = 'MCPContractError';
11
+ }
12
+ }
13
+ export function createMCPContract(mcp, contract) {
14
+ const proxy = {};
15
+ for (const [toolName, toolDef] of Object.entries(contract)) {
16
+ if (toolDef.stream) {
17
+ proxy[toolName] = async function* (args = {}) {
18
+ let validatedArgs = args;
19
+ if (toolDef.inputSchema) {
20
+ try {
21
+ validatedArgs = toolDef.inputSchema.parse(args);
22
+ }
23
+ catch (err) {
24
+ throw new MCPContractError(toolName, 'input', err);
25
+ }
26
+ }
27
+ const result = await mcp.tools.call(toolName, validatedArgs);
28
+ for (const content of result.content) {
29
+ if (content.type === 'text' && content.text) {
30
+ yield content.text;
31
+ }
32
+ }
33
+ };
34
+ }
35
+ else {
36
+ proxy[toolName] = async (args = {}) => {
37
+ let validatedArgs = args;
38
+ if (toolDef.inputSchema) {
39
+ try {
40
+ validatedArgs = toolDef.inputSchema.parse(args);
41
+ }
42
+ catch (err) {
43
+ throw new MCPContractError(toolName, 'input', err);
44
+ }
45
+ }
46
+ const result = await mcp.tools.call(toolName, validatedArgs);
47
+ const textContent = result.content
48
+ .filter((c) => c.type === 'text')
49
+ .map((c) => c.text)
50
+ .join('');
51
+ if (toolDef.outputSchema) {
52
+ try {
53
+ const parsed = JSON.parse(textContent);
54
+ return toolDef.outputSchema.parse(parsed);
55
+ }
56
+ catch (err) {
57
+ try {
58
+ return toolDef.outputSchema.parse(textContent);
59
+ }
60
+ catch (validationErr) {
61
+ throw new MCPContractError(toolName, 'output', validationErr);
62
+ }
63
+ }
64
+ }
65
+ return result;
66
+ };
67
+ }
68
+ }
69
+ proxy.raw = async (name, args = {}) => {
70
+ const toolDef = contract[name];
71
+ let validatedArgs = args;
72
+ if (toolDef?.inputSchema) {
73
+ try {
74
+ validatedArgs = toolDef.inputSchema.parse(args);
75
+ }
76
+ catch (err) {
77
+ throw new MCPContractError(name, 'input', err);
78
+ }
79
+ }
80
+ return mcp.tools.call(name, validatedArgs);
81
+ };
82
+ proxy.list = () => {
83
+ return Object.entries(contract).map(([name, def]) => ({
84
+ name,
85
+ description: def.description,
86
+ inputSchema: def.inputSchema,
87
+ }));
88
+ };
89
+ proxy.has = (name) => {
90
+ return name in contract;
91
+ };
92
+ return proxy;
93
+ }
94
+ export function createMCPStream(mcp, toolName, options = {}) {
95
+ const { inputParam = 'prompt', extraParams = {} } = options;
96
+ const streamFn = async function* (input) {
97
+ const args = { [inputParam]: input, ...extraParams };
98
+ const result = await mcp.tools.call(toolName, args);
99
+ for (const content of result.content) {
100
+ if (content.type === 'text' && content.text) {
101
+ yield content.text;
102
+ }
103
+ }
104
+ };
105
+ streamFn.text = async (input) => {
106
+ const chunks = [];
107
+ for await (const chunk of streamFn(input)) {
108
+ chunks.push(chunk);
109
+ }
110
+ return chunks.join('');
111
+ };
112
+ streamFn.json = async (input) => {
113
+ const text = await streamFn.text(input);
114
+ return JSON.parse(text);
115
+ };
116
+ return streamFn;
117
+ }
118
+ export function createMCPBatch(mcp, contract) {
119
+ return async (calls) => {
120
+ const results = await Promise.allSettled(calls.map(async ({ tool, args }) => {
121
+ const toolDef = contract[tool];
122
+ let validatedArgs = (args || {});
123
+ if (toolDef?.inputSchema) {
124
+ validatedArgs = toolDef.inputSchema.parse(args);
125
+ }
126
+ const result = await mcp.tools.call(tool, validatedArgs);
127
+ if (toolDef?.outputSchema) {
128
+ const textContent = result.content
129
+ .filter((c) => c.type === 'text')
130
+ .map((c) => c.text)
131
+ .join('');
132
+ try {
133
+ const parsed = JSON.parse(textContent);
134
+ return toolDef.outputSchema.parse(parsed);
135
+ }
136
+ catch {
137
+ return toolDef.outputSchema.parse(textContent);
138
+ }
139
+ }
140
+ return result;
141
+ }));
142
+ return results.map((r) => {
143
+ if (r.status === 'fulfilled') {
144
+ return { success: true, result: r.value };
145
+ }
146
+ else {
147
+ return { success: false, error: r.reason };
148
+ }
149
+ });
150
+ };
151
+ }
152
+ export function createMCPSSEStream(client, endpoint, options = {}) {
153
+ const { inputParam = 'prompt', extraParams = {}, eventType = 'message', extractData = (event) => event.data, } = options;
154
+ const eventTypes = Array.isArray(eventType) ? eventType : [eventType];
155
+ async function* streamEvents(input, callOptions) {
156
+ const body = { [inputParam]: input, ...extraParams };
157
+ const response = await client.post(endpoint, {
158
+ json: body,
159
+ signal: callOptions?.signal,
160
+ timeout: callOptions?.timeout,
161
+ headers: {
162
+ Accept: 'text/event-stream',
163
+ 'Cache-Control': 'no-cache',
164
+ },
165
+ });
166
+ for await (const event of response.sse()) {
167
+ yield event;
168
+ }
169
+ }
170
+ async function* streamText(input, callOptions) {
171
+ for await (const event of streamEvents(input, callOptions)) {
172
+ const eventName = event.event || 'message';
173
+ if (!eventTypes.includes(eventName))
174
+ continue;
175
+ if (event.data === '[DONE]')
176
+ continue;
177
+ const data = extractData(event);
178
+ if (data !== null && data !== undefined && data !== '') {
179
+ yield data;
180
+ }
181
+ }
182
+ }
183
+ const fn = streamText;
184
+ fn.text = async (input, callOptions) => {
185
+ const chunks = [];
186
+ for await (const chunk of streamText(input, callOptions)) {
187
+ chunks.push(chunk);
188
+ }
189
+ return chunks.join('');
190
+ };
191
+ fn.json = async (input, callOptions) => {
192
+ const text = await fn.text(input, callOptions);
193
+ return JSON.parse(text);
194
+ };
195
+ fn.events = streamEvents;
196
+ return fn;
197
+ }
198
+ export function createValidatedSSEStream(client, endpoint, options) {
199
+ const { inputSchema, extraParams = {}, eventType = 'message', extractData = (event) => event.data, } = options;
200
+ const eventTypes = Array.isArray(eventType) ? eventType : [eventType];
201
+ async function* streamEvents(args, callOptions) {
202
+ const validatedArgs = inputSchema.parse(args);
203
+ const body = { ...validatedArgs, ...extraParams };
204
+ const response = await client.post(endpoint, {
205
+ json: body,
206
+ signal: callOptions?.signal,
207
+ timeout: callOptions?.timeout,
208
+ headers: {
209
+ Accept: 'text/event-stream',
210
+ 'Cache-Control': 'no-cache',
211
+ },
212
+ });
213
+ for await (const event of response.sse()) {
214
+ yield event;
215
+ }
216
+ }
217
+ async function* streamText(args, callOptions) {
218
+ for await (const event of streamEvents(args, callOptions)) {
219
+ const eventName = event.event || 'message';
220
+ if (!eventTypes.includes(eventName))
221
+ continue;
222
+ if (event.data === '[DONE]')
223
+ continue;
224
+ const data = extractData(event);
225
+ if (data !== null && data !== undefined && data !== '') {
226
+ yield data;
227
+ }
228
+ }
229
+ }
230
+ const fn = streamText;
231
+ fn.text = async (args, callOptions) => {
232
+ const chunks = [];
233
+ for await (const chunk of streamText(args, callOptions)) {
234
+ chunks.push(chunk);
235
+ }
236
+ return chunks.join('');
237
+ };
238
+ fn.json = async (args, callOptions) => {
239
+ const text = await fn.text(args, callOptions);
240
+ return JSON.parse(text);
241
+ };
242
+ fn.events = streamEvents;
243
+ return fn;
244
+ }
245
+ export function openAIExtractor(event) {
246
+ if (!event.data || event.data === '[DONE]')
247
+ return null;
248
+ try {
249
+ const json = JSON.parse(event.data);
250
+ if (json.choices?.[0]?.delta?.content) {
251
+ return json.choices[0].delta.content;
252
+ }
253
+ if (json.choices?.[0]?.text) {
254
+ return json.choices[0].text;
255
+ }
256
+ return null;
257
+ }
258
+ catch {
259
+ return null;
260
+ }
261
+ }
262
+ export function anthropicExtractor(event) {
263
+ if (!event.data || event.data === '[DONE]')
264
+ return null;
265
+ try {
266
+ const json = JSON.parse(event.data);
267
+ if (json.delta?.text) {
268
+ return json.delta.text;
269
+ }
270
+ if (json.type === 'message_delta') {
271
+ return null;
272
+ }
273
+ return null;
274
+ }
275
+ catch {
276
+ return null;
277
+ }
278
+ }
@@ -65,6 +65,7 @@ export interface MCPResource {
65
65
  mimeType?: string;
66
66
  }
67
67
  export interface MCPResourceContent {
68
+ type: 'resource';
68
69
  uri: string;
69
70
  mimeType?: string;
70
71
  text?: string;
@@ -1 +1 @@
1
- {"version":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AqB;IACpC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,EAAE,gBAAgB,EAAE,CAAC;CAC9B;AAED,MAAM,MAAM,eAAe,GACvB,2BAA2B,GAC3B,wBAAwB,GACxB,uBAAuB,GACvB,iCAAiC,GACjC,sCAAsC,GACtC,kCAAkC,GAClC,oCAAoC,CAAC;AAEzC,MAAM,WAAW,uBAAuB;IACtC,aAAa,EAAE,MAAM,GAAG,MAAM,CAAC;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,mBAAmB;IAClC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,GAAG,CAAC;CACjB"}
@@ -0,0 +1,45 @@
1
+ import { Middleware, Plugin } from '../types/index.js';
2
+ export interface BasicAuthOptions {
3
+ username: string;
4
+ password: string;
5
+ }
6
+ export declare function basicAuth(options: BasicAuthOptions): Middleware;
7
+ export declare function basicAuthPlugin(options: BasicAuthOptions): Plugin;
8
+ export interface BearerAuthOptions {
9
+ token: string | (() => string | Promise<string>);
10
+ type?: string;
11
+ headerName?: string;
12
+ }
13
+ export declare function bearerAuth(options: BearerAuthOptions): Middleware;
14
+ export declare function bearerAuthPlugin(options: BearerAuthOptions): Plugin;
15
+ export interface ApiKeyAuthOptions {
16
+ key: string | (() => string | Promise<string>);
17
+ in?: 'header' | 'query';
18
+ name?: string;
19
+ }
20
+ export declare function apiKeyAuth(options: ApiKeyAuthOptions): Middleware;
21
+ export declare function apiKeyAuthPlugin(options: ApiKeyAuthOptions): Plugin;
22
+ export interface DigestAuthOptions {
23
+ username: string;
24
+ password: string;
25
+ preemptive?: boolean;
26
+ }
27
+ export declare function digestAuth(options: DigestAuthOptions): Middleware;
28
+ export declare function digestAuthPlugin(options: DigestAuthOptions): Plugin;
29
+ export interface OAuth2Options {
30
+ accessToken: string | (() => string | Promise<string>);
31
+ tokenType?: string;
32
+ onTokenExpired?: () => Promise<string>;
33
+ }
34
+ export declare function oauth2(options: OAuth2Options): Middleware;
35
+ export declare function oauth2Plugin(options: OAuth2Options): Plugin;
36
+ export interface AWSSignatureV4Options {
37
+ accessKeyId: string;
38
+ secretAccessKey: string;
39
+ region: string;
40
+ service: string;
41
+ sessionToken?: string;
42
+ }
43
+ export declare function awsSignatureV4(options: AWSSignatureV4Options): Middleware;
44
+ export declare function awsSignatureV4Plugin(options: AWSSignatureV4Options): Plugin;
45
+ //# sourceMappingURL=auth.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/plugins/auth.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,UAAU,EAAE,MAAM,EAAiB,MAAM,mBAAmB,CAAC;AAOtE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAcD,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,UAAU,CAQ/D;AAKD,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,MAAM,CAIjE;AAMD,MAAM,WAAW,iBAAiB;IAIhC,KAAK,EAAE,MAAM,GAAG,CAAC,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;IAKjD,IAAI,CAAC,EAAE,MAAM,CAAC;IAKd,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAiBD,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,UAAU,CAajE;AAKD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,iBAAiB,GAAG,MAAM,CAInE;AAMD,MAAM,WAAW,iBAAiB;IAIhC,GAAG,EAAE,MAAM,GAAG,C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3E"}
@@ -0,0 +1,268 @@
1
+ import { createHash, randomBytes } from 'node:crypto';
2
+ export function basicAuth(options) {
3
+ const credentials = Buffer.from(`${options.username}:${options.password}`).toString('base64');
4
+ const authHeader = `Basic ${credentials}`;
5
+ return async (req, next) => {
6
+ const newReq = req.withHeader('Authorization', authHeader);
7
+ return next(newReq);
8
+ };
9
+ }
10
+ export function basicAuthPlugin(options) {
11
+ return (client) => {
12
+ client.use(basicAuth(options));
13
+ };
14
+ }
15
+ export function bearerAuth(options) {
16
+ const type = options.type ?? 'Bearer';
17
+ const headerName = options.headerName ?? 'Authorization';
18
+ return async (req, next) => {
19
+ const token = typeof options.token === 'function'
20
+ ? await options.token()
21
+ : options.token;
22
+ const authHeader = `${type} ${token}`;
23
+ const newReq = req.withHeader(headerName, authHeader);
24
+ return next(newReq);
25
+ };
26
+ }
27
+ export function bearerAuthPlugin(options) {
28
+ return (client) => {
29
+ client.use(bearerAuth(options));
30
+ };
31
+ }
32
+ export function apiKeyAuth(options) {
33
+ const location = options.in ?? 'header';
34
+ const name = options.name ?? 'X-API-Key';
35
+ return async (req, next) => {
36
+ const key = typeof options.key === 'function'
37
+ ? await options.key()
38
+ : options.key;
39
+ if (location === 'header') {
40
+ const newReq = req.withHeader(name, key);
41
+ return next(newReq);
42
+ }
43
+ else {
44
+ const url = new URL(req.url);
45
+ url.searchParams.set(name, key);
46
+ const newReq = {
47
+ ...req,
48
+ url: url.toString(),
49
+ };
50
+ return next(newReq);
51
+ }
52
+ };
53
+ }
54
+ export function apiKeyAuthPlugin(options) {
55
+ return (client) => {
56
+ client.use(apiKeyAuth(options));
57
+ };
58
+ }
59
+ function parseDigestChallenge(header) {
60
+ if (!header.toLowerCase().startsWith('digest ')) {
61
+ return null;
62
+ }
63
+ const params = {};
64
+ const regex = /(\w+)=(?:"([^"]+)"|([^\s,]+))/g;
65
+ let match;
66
+ while ((match = regex.exec(header)) !== null) {
67
+ params[match[1].toLowerCase()] = match[2] || match[3];
68
+ }
69
+ if (!params.realm || !params.nonce) {
70
+ return null;
71
+ }
72
+ return {
73
+ realm: params.realm,
74
+ nonce: params.nonce,
75
+ qop: params.qop,
76
+ opaque: params.opaque,
77
+ algorithm: params.algorithm,
78
+ stale: params.stale === 'true',
79
+ };
80
+ }
81
+ function md5(str) {
82
+ return createHash('md5').update(str).digest('hex');
83
+ }
84
+ function sha256(str) {
85
+ return createHash('sha256').update(str).digest('hex');
86
+ }
87
+ function generateDigestHeader(method, uri, username, password, challenge, nc) {
88
+ const algorithm = challenge.algorithm?.toUpperCase() || 'MD5';
89
+ const hashFn = algorithm.includes('SHA-256') ? sha256 : md5;
90
+ const cnonce = randomBytes(8).toString('hex');
91
+ const ncStr = nc.toString(16).padStart(8, '0');
92
+ let ha1 = hashFn(`${username}:${challenge.realm}:${password}`);
93
+ if (algorithm.endsWith('-SESS')) {
94
+ ha1 = hashFn(`${ha1}:${challenge.nonce}:${cnonce}`);
95
+ }
96
+ const ha2 = hashFn(`${method}:${uri}`);
97
+ let response;
98
+ if (challenge.qop) {
99
+ response = hashFn(`${ha1}:${challenge.nonce}:${ncStr}:${cnonce}:${challenge.qop}:${ha2}`);
100
+ }
101
+ else {
102
+ response = hashFn(`${ha1}:${challenge.nonce}:${ha2}`);
103
+ }
104
+ const parts = [
105
+ `username="${username}"`,
106
+ `realm="${challenge.realm}"`,
107
+ `nonce="${challenge.nonce}"`,
108
+ `uri="${uri}"`,
109
+ `response="${response}"`,
110
+ ];
111
+ if (challenge.qop) {
112
+ parts.push(`qop=${challenge.qop.split(',')[0].trim()}`);
113
+ parts.push(`nc=${ncStr}`);
114
+ parts.push(`cnonce="${cnonce}"`);
115
+ }
116
+ if (challenge.opaque) {
117
+ parts.push(`opaque="${challenge.opaque}"`);
118
+ }
119
+ if (algorithm !== 'MD5') {
120
+ parts.push(`algorithm=${algorithm}`);
121
+ }
122
+ return `Digest ${parts.join(', ')}`;
123
+ }
124
+ export function digestAuth(options) {
125
+ let nc = 0;
126
+ let lastChallenge = null;
127
+ return async (req, next) => {
128
+ if (lastChallenge && options.preemptive) {
129
+ nc++;
130
+ const uri = new URL(req.url).pathname + new URL(req.url).search;
131
+ const authHeader = generateDigestHeader(req.method, uri, options.username, options.password, lastChallenge, nc);
132
+ const newReq = req.withHeader('Authorization', authHeader);
133
+ return next(newReq);
134
+ }
135
+ const response = await next(req);
136
+ if (response.status === 401) {
137
+ const wwwAuth = response.headers.get('WWW-Authenticate');
138
+ if (wwwAuth) {
139
+ const challenge = parseDigestChallenge(wwwAuth);
140
+ if (challenge) {
141
+ lastChallenge = challenge;
142
+ nc++;
143
+ const uri = new URL(req.url).pathname + new URL(req.url).search;
144
+ const authHeader = generateDigestHeader(req.method, uri, options.username, options.password, challenge, nc);
145
+ const newReq = req.withHeader('Authorization', authHeader);
146
+ return next(newReq);
147
+ }
148
+ }
149
+ }
150
+ return response;
151
+ };
152
+ }
153
+ export function digestAuthPlugin(options) {
154
+ return (client) => {
155
+ client.use(digestAuth(options));
156
+ };
157
+ }
158
+ export function oauth2(options) {
159
+ const tokenType = options.tokenType ?? 'Bearer';
160
+ return async (req, next) => {
161
+ const token = typeof options.accessToken === 'function'
162
+ ? await options.accessToken()
163
+ : options.accessToken;
164
+ const authReq = req.withHeader('Authorization', `${tokenType} ${token}`);
165
+ const response = await next(authReq);
166
+ if (response.status === 401 && options.onTokenExpired) {
167
+ try {
168
+ const newToken = await options.onTokenExpired();
169
+ const retryReq = req.withHeader('Authorization', `${tokenType} ${newToken}`);
170
+ return next(retryReq);
171
+ }
172
+ catch {
173
+ return response;
174
+ }
175
+ }
176
+ return response;
177
+ };
178
+ }
179
+ export function oauth2Plugin(options) {
180
+ return (client) => {
181
+ client.use(oauth2(options));
182
+ };
183
+ }
184
+ export function awsSignatureV4(options) {
185
+ return async (req, next) => {
186
+ const url = new URL(req.url);
187
+ const host = url.host;
188
+ const pathname = url.pathname;
189
+ const queryString = url.search.slice(1);
190
+ const now = new Date();
191
+ const amzDate = now.toISOString().replace(/[:-]|\.\d{3}/g, '');
192
+ const dateStamp = amzDate.slice(0, 8);
193
+ const method = req.method;
194
+ const canonicalUri = pathname || '/';
195
+ const canonicalQueryString = queryString
196
+ .split('&')
197
+ .filter(Boolean)
198
+ .sort()
199
+ .join('&');
200
+ let payload = '';
201
+ if (req.body) {
202
+ if (typeof req.body === 'string') {
203
+ payload = req.body;
204
+ }
205
+ else if (req.body instanceof ArrayBuffer) {
206
+ payload = Buffer.from(req.body).toString();
207
+ }
208
+ }
209
+ const payloadHash = sha256(payload);
210
+ const headers = {
211
+ host,
212
+ 'x-amz-date': amzDate,
213
+ 'x-amz-content-sha256': payloadHash,
214
+ };
215
+ if (options.sessionToken) {
216
+ headers['x-amz-security-token'] = options.sessionToken;
217
+ }
218
+ req.headers.forEach((value, key) => {
219
+ headers[key.toLowerCase()] = value;
220
+ });
221
+ const signedHeaders = Object.keys(headers).sort().join(';');
222
+ const canonicalHeaders = Object.keys(headers)
223
+ .sort()
224
+ .map(key => `${key}:${headers[key].trim()}\n`)
225
+ .join('');
226
+ const canonicalRequest = [
227
+ method,
228
+ canonicalUri,
229
+ canonicalQueryString,
230
+ canonicalHeaders,
231
+ signedHeaders,
232
+ payloadHash,
233
+ ].join('\n');
234
+ const algorithm = 'AWS4-HMAC-SHA256';
235
+ const credentialScope = `${dateStamp}/${options.region}/${options.service}/aws4_request`;
236
+ const stringToSign = [
237
+ algorithm,
238
+ amzDate,
239
+ credentialScope,
240
+ sha256(canonicalRequest),
241
+ ].join('\n');
242
+ const getSignatureKey = (key, dateStamp, regionName, serviceName) => {
243
+ const kDate = createHash('sha256').update(`AWS4${key}`).update(dateStamp).digest();
244
+ const kRegion = createHash('sha256').update(kDate).update(regionName).digest();
245
+ const kService = createHash('sha256').update(kRegion).update(serviceName).digest();
246
+ const kSigning = createHash('sha256').update(kService).update('aws4_request').digest();
247
+ return kSigning;
248
+ };
249
+ const signingKey = getSignatureKey(options.secretAccessKey, dateStamp, options.region, options.service);
250
+ const signature = createHash('sha256')
251
+ .update(signingKey)
252
+ .update(stringToSign)
253
+ .digest('hex');
254
+ const authorizationHeader = `${algorithm} Credential=${options.accessKeyId}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signature}`;
255
+ let newReq = req.withHeader('Authorization', authorizationHeader);
256
+ newReq = newReq.withHeader('x-amz-date', amzDate);
257
+ newReq = newReq.withHeader('x-amz-content-sha256', payloadHash);
258
+ if (options.sessionToken) {
259
+ newReq = newReq.withHeader('x-amz-security-token', options.sessionToken);
260
+ }
261
+ return next(newReq);
262
+ };
263
+ }
264
+ export function awsSignatureV4Plugin(options) {
265
+ return (client) => {
266
+ client.use(awsSignatureV4(options));
267
+ };
268
+ }
@@ -1,10 +1,16 @@
1
- import { CacheStorage, CacheStrategy, Plugin, ReckerRequest } from '../types/index.js';
1
+ import { CacheStorage, CacheStrategy, Plugin, ReckerRequest, CacheEntry } from '../types/index.js';
2
2
  export interface CacheOptions {
3
3
  storage?: CacheStorage;
4
4
  strategy?: CacheStrategy;
5
5
  ttl?: number;
6
6
  methods?: string[];
7
7
  keyGenerator?: (req: ReckerRequest) => string;
8
+ respectCacheControl?: boolean;
9
+ respectVary?: boolean;
10
+ maxStale?: number;
11
+ forceRevalidate?: boolean;
8
12
  }
13
+ declare function parseCacheControl(header: string | null): Partial<CacheEntry>;
9
14
  export declare function cache(options?: CacheOptions): Plugin;
15
+ export { parseCacheControl };
10
16
  //# sourceMappingURL=cache.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/plugins/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAc,MAAM,EAAE,aAAa,EAAkB,MAAM,mBAAmB,CAAC;AAInH,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,MAAM,CAAC;CAC/C;AAED,wBAAgB,KAAK,CAAC,OAAO,GAAE,YAAiB,GAAG,MAAM,CAgGxD"}
1
+ {"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../src/plugins/cache.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,aAAa,EAAc,MAAM,EAAE,aAAa,EAAkB,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAM/H,MAAM,WAAW,YAAY;IAC3B,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,aAAa,KAAK,MAAM,CAAC;IAU9C,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAM9B,WAAW,CAAC,EAAE,OAAO,CAAC;IAOtB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAOlB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAmDD,iBAAS,iBAAiB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO,CAAC,UAAU,CAAC,CA6BrE;AA0OD,wBAAgB,KAAK,CAAC,OAAO,GAAE,YAAiB,GAAG,MAAM,CAuYxD;AAGD,OAAO,EAAE,iBAAiB,EAAE,CAAC"}