@strands-agents/sdk 1.16.0 → 1.18.0

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 (192) hide show
  1. package/README.md +1 -1
  2. package/dist/src/agent/agent-metadata.d.ts +12 -0
  3. package/dist/src/agent/agent-metadata.d.ts.map +1 -0
  4. package/dist/src/agent/agent-metadata.js +2 -0
  5. package/dist/src/agent/agent-metadata.js.map +1 -0
  6. package/dist/src/agent/agent.d.ts +11 -28
  7. package/dist/src/agent/agent.d.ts.map +1 -1
  8. package/dist/src/agent/agent.js +21 -54
  9. package/dist/src/agent/agent.js.map +1 -1
  10. package/dist/src/context-manager/context-manager.d.ts +47 -5
  11. package/dist/src/context-manager/context-manager.d.ts.map +1 -1
  12. package/dist/src/context-manager/context-manager.js +114 -16
  13. package/dist/src/context-manager/context-manager.js.map +1 -1
  14. package/dist/src/context-manager/methods/summarize.d.ts +8 -2
  15. package/dist/src/context-manager/methods/summarize.d.ts.map +1 -1
  16. package/dist/src/context-manager/methods/summarize.js +9 -2
  17. package/dist/src/context-manager/methods/summarize.js.map +1 -1
  18. package/dist/src/context-manager/methods/truncate.d.ts +2 -2
  19. package/dist/src/context-manager/methods/truncate.d.ts.map +1 -1
  20. package/dist/src/context-manager/methods/truncate.js +0 -2
  21. package/dist/src/context-manager/methods/truncate.js.map +1 -1
  22. package/dist/src/context-manager/modes/agentic/agentic-context.d.ts +2 -2
  23. package/dist/src/context-manager/presets.d.ts +42 -0
  24. package/dist/src/context-manager/presets.d.ts.map +1 -0
  25. package/dist/src/context-manager/presets.js +71 -0
  26. package/dist/src/context-manager/presets.js.map +1 -0
  27. package/dist/src/context-manager/retrieval-tool.d.ts +29 -0
  28. package/dist/src/context-manager/retrieval-tool.d.ts.map +1 -0
  29. package/dist/src/context-manager/retrieval-tool.js +116 -0
  30. package/dist/src/context-manager/retrieval-tool.js.map +1 -0
  31. package/dist/src/context-manager/stash.d.ts +107 -0
  32. package/dist/src/context-manager/stash.d.ts.map +1 -0
  33. package/dist/src/context-manager/stash.js +189 -0
  34. package/dist/src/context-manager/stash.js.map +1 -0
  35. package/dist/src/context-manager/strategies/offload/base.d.ts +23 -13
  36. package/dist/src/context-manager/strategies/offload/base.d.ts.map +1 -1
  37. package/dist/src/context-manager/strategies/offload/base.js +67 -25
  38. package/dist/src/context-manager/strategies/offload/base.js.map +1 -1
  39. package/dist/src/context-manager/strategies/offload/drop.d.ts +2 -2
  40. package/dist/src/context-manager/strategies/offload/drop.d.ts.map +1 -1
  41. package/dist/src/context-manager/strategies/offload/drop.js +6 -4
  42. package/dist/src/context-manager/strategies/offload/drop.js.map +1 -1
  43. package/dist/src/context-manager/strategies/offload/index.d.ts +1 -1
  44. package/dist/src/context-manager/strategies/offload/index.js +1 -1
  45. package/dist/src/context-manager/strategies/offload/summarize.d.ts +2 -2
  46. package/dist/src/context-manager/strategies/offload/summarize.d.ts.map +1 -1
  47. package/dist/src/context-manager/strategies/offload/summarize.js +22 -25
  48. package/dist/src/context-manager/strategies/offload/summarize.js.map +1 -1
  49. package/dist/src/context-manager/strategies/offload/truncate.d.ts +2 -2
  50. package/dist/src/context-manager/strategies/offload/truncate.d.ts.map +1 -1
  51. package/dist/src/context-manager/strategies/offload/truncate.js +34 -12
  52. package/dist/src/context-manager/strategies/offload/truncate.js.map +1 -1
  53. package/dist/src/context-manager/types.d.ts +46 -2
  54. package/dist/src/context-manager/types.d.ts.map +1 -1
  55. package/dist/src/experimental/index.d.ts +6 -0
  56. package/dist/src/experimental/index.d.ts.map +1 -1
  57. package/dist/src/experimental/index.js +3 -0
  58. package/dist/src/experimental/index.js.map +1 -1
  59. package/dist/src/index.d.ts +11 -3
  60. package/dist/src/index.d.ts.map +1 -1
  61. package/dist/src/index.js +2 -1
  62. package/dist/src/index.js.map +1 -1
  63. package/dist/src/mcp/client.d.ts +3 -2
  64. package/dist/src/mcp/client.d.ts.map +1 -1
  65. package/dist/src/mcp/client.js +3 -2
  66. package/dist/src/mcp/client.js.map +1 -1
  67. package/dist/src/mcp/config.d.ts +11 -1
  68. package/dist/src/mcp/config.d.ts.map +1 -1
  69. package/dist/src/mcp/config.js.map +1 -1
  70. package/dist/src/mcp/config.node.d.ts +3 -2
  71. package/dist/src/mcp/config.node.d.ts.map +1 -1
  72. package/dist/src/mcp/config.node.js +6 -3
  73. package/dist/src/mcp/config.node.js.map +1 -1
  74. package/dist/src/mcp/index.d.ts +1 -1
  75. package/dist/src/mcp/index.d.ts.map +1 -1
  76. package/dist/src/models/defaults.d.ts.map +1 -1
  77. package/dist/src/models/defaults.js +1 -0
  78. package/dist/src/models/defaults.js.map +1 -1
  79. package/dist/src/models/model.d.ts +12 -2
  80. package/dist/src/models/model.d.ts.map +1 -1
  81. package/dist/src/models/model.js.map +1 -1
  82. package/dist/src/models/openai/cache.d.ts +38 -2
  83. package/dist/src/models/openai/cache.d.ts.map +1 -1
  84. package/dist/src/models/openai/cache.js +64 -14
  85. package/dist/src/models/openai/cache.js.map +1 -1
  86. package/dist/src/models/openai/chat-adapter.d.ts.map +1 -1
  87. package/dist/src/models/openai/chat-adapter.js +10 -4
  88. package/dist/src/models/openai/chat-adapter.js.map +1 -1
  89. package/dist/src/models/openai/mantle.js +1 -1
  90. package/dist/src/models/openai/mantle.js.map +1 -1
  91. package/dist/src/models/openai/responses-adapter.js +1 -1
  92. package/dist/src/models/openai/responses-adapter.js.map +1 -1
  93. package/dist/src/models/routing/classifier-strategy.d.ts +87 -0
  94. package/dist/src/models/routing/classifier-strategy.d.ts.map +1 -0
  95. package/dist/src/models/routing/classifier-strategy.js +285 -0
  96. package/dist/src/models/routing/classifier-strategy.js.map +1 -0
  97. package/dist/src/models/routing/index.d.ts +2 -0
  98. package/dist/src/models/routing/index.d.ts.map +1 -1
  99. package/dist/src/models/routing/index.js +1 -0
  100. package/dist/src/models/routing/index.js.map +1 -1
  101. package/dist/src/models/routing/router.d.ts +14 -2
  102. package/dist/src/models/routing/router.d.ts.map +1 -1
  103. package/dist/src/models/routing/router.js +43 -8
  104. package/dist/src/models/routing/router.js.map +1 -1
  105. package/dist/src/models/vercel.d.ts +9 -1
  106. package/dist/src/models/vercel.d.ts.map +1 -1
  107. package/dist/src/models/vercel.js +248 -7
  108. package/dist/src/models/vercel.js.map +1 -1
  109. package/dist/src/plugins/plugin.d.ts +1 -1
  110. package/dist/src/plugins/registry.js +1 -1
  111. package/dist/src/plugins/registry.js.map +1 -1
  112. package/dist/src/sandbox/errors.d.ts +5 -1
  113. package/dist/src/sandbox/errors.d.ts.map +1 -1
  114. package/dist/src/sandbox/errors.js +7 -1
  115. package/dist/src/sandbox/errors.js.map +1 -1
  116. package/dist/src/sandbox/stream-process.js +1 -1
  117. package/dist/src/sandbox/stream-process.js.map +1 -1
  118. package/dist/src/session/session-manager.d.ts +5 -1
  119. package/dist/src/session/session-manager.d.ts.map +1 -1
  120. package/dist/src/session/session-manager.js +51 -1
  121. package/dist/src/session/session-manager.js.map +1 -1
  122. package/dist/src/session/snapshot-storage-adapter.d.ts.map +1 -1
  123. package/dist/src/session/snapshot-storage-adapter.js +1 -0
  124. package/dist/src/session/snapshot-storage-adapter.js.map +1 -1
  125. package/dist/src/storage/in-memory-storage.d.ts +9 -0
  126. package/dist/src/storage/in-memory-storage.d.ts.map +1 -1
  127. package/dist/src/storage/in-memory-storage.js +18 -2
  128. package/dist/src/storage/in-memory-storage.js.map +1 -1
  129. package/dist/src/storage/local-file-storage.d.ts +9 -2
  130. package/dist/src/storage/local-file-storage.d.ts.map +1 -1
  131. package/dist/src/storage/local-file-storage.js +17 -4
  132. package/dist/src/storage/local-file-storage.js.map +1 -1
  133. package/dist/src/storage/s3-storage.d.ts +4 -0
  134. package/dist/src/storage/s3-storage.d.ts.map +1 -1
  135. package/dist/src/storage/s3-storage.js +8 -0
  136. package/dist/src/storage/s3-storage.js.map +1 -1
  137. package/dist/src/storage/search/qmd.d.ts +10 -6
  138. package/dist/src/storage/search/qmd.d.ts.map +1 -1
  139. package/dist/src/storage/search/qmd.js +4 -6
  140. package/dist/src/storage/search/qmd.js.map +1 -1
  141. package/dist/src/storage/search/types.d.ts +14 -2
  142. package/dist/src/storage/search/types.d.ts.map +1 -1
  143. package/dist/src/storage/storage.d.ts +8 -0
  144. package/dist/src/storage/storage.d.ts.map +1 -1
  145. package/dist/src/storage/storage.js +18 -0
  146. package/dist/src/storage/storage.js.map +1 -1
  147. package/dist/src/telemetry/tracer.d.ts.map +1 -1
  148. package/dist/src/telemetry/tracer.js +4 -2
  149. package/dist/src/telemetry/tracer.js.map +1 -1
  150. package/dist/src/tsconfig.tsbuildinfo +1 -1
  151. package/dist/src/types/agent.d.ts +7 -0
  152. package/dist/src/types/agent.d.ts.map +1 -1
  153. package/dist/src/types/agent.js.map +1 -1
  154. package/dist/src/vended-plugins/context-offloader/search.d.ts.map +1 -1
  155. package/dist/src/vended-plugins/context-offloader/search.js +4 -2
  156. package/dist/src/vended-plugins/context-offloader/search.js.map +1 -1
  157. package/dist/src/vended-tools/index.d.ts +5 -3
  158. package/dist/src/vended-tools/index.d.ts.map +1 -1
  159. package/dist/src/vended-tools/index.js +5 -3
  160. package/dist/src/vended-tools/index.js.map +1 -1
  161. package/dist/src/vended-tools/notebook/index.d.ts +2 -1
  162. package/dist/src/vended-tools/notebook/index.d.ts.map +1 -1
  163. package/dist/src/vended-tools/notebook/index.js +1 -1
  164. package/dist/src/vended-tools/notebook/index.js.map +1 -1
  165. package/dist/src/vended-tools/notebook/notebook.d.ts +38 -8
  166. package/dist/src/vended-tools/notebook/notebook.d.ts.map +1 -1
  167. package/dist/src/vended-tools/notebook/notebook.js +130 -79
  168. package/dist/src/vended-tools/notebook/notebook.js.map +1 -1
  169. package/dist/src/vended-tools/shell/make-shell.d.ts.map +1 -1
  170. package/dist/src/vended-tools/shell/make-shell.js +7 -3
  171. package/dist/src/vended-tools/shell/make-shell.js.map +1 -1
  172. package/dist/src/vended-tools/shell/types.d.ts +10 -5
  173. package/dist/src/vended-tools/shell/types.d.ts.map +1 -1
  174. package/dist/src/vended-tools/shell/types.js +7 -2
  175. package/dist/src/vended-tools/shell/types.js.map +1 -1
  176. package/dist/src/vended-tools/web-fetch/extract.d.ts +23 -0
  177. package/dist/src/vended-tools/web-fetch/extract.d.ts.map +1 -0
  178. package/dist/src/vended-tools/web-fetch/extract.js +130 -0
  179. package/dist/src/vended-tools/web-fetch/extract.js.map +1 -0
  180. package/dist/src/vended-tools/web-fetch/index.d.ts +9 -0
  181. package/dist/src/vended-tools/web-fetch/index.d.ts.map +1 -0
  182. package/dist/src/vended-tools/web-fetch/index.js +7 -0
  183. package/dist/src/vended-tools/web-fetch/index.js.map +1 -0
  184. package/dist/src/vended-tools/web-fetch/types.d.ts +40 -0
  185. package/dist/src/vended-tools/web-fetch/types.d.ts.map +1 -0
  186. package/dist/src/vended-tools/web-fetch/types.js +8 -0
  187. package/dist/src/vended-tools/web-fetch/types.js.map +1 -0
  188. package/dist/src/vended-tools/web-fetch/web-fetch.d.ts +14 -0
  189. package/dist/src/vended-tools/web-fetch/web-fetch.d.ts.map +1 -0
  190. package/dist/src/vended-tools/web-fetch/web-fetch.js +175 -0
  191. package/dist/src/vended-tools/web-fetch/web-fetch.js.map +1 -0
  192. package/package.json +18 -5
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/vended-tools/shell/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAErE,eAAO,MAAM,yBAAyB,QAE8C,CAAA;AAEpF;;;;;GAKG;AACH,qBAAa,iBAAkB,SAAQ,gBAAgB;gBACzC,OAAO,EAAE,MAAM;CAI5B;AAED;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ,gBAAgB;gBAC3C,OAAO,EAAE,MAAM;CAI5B;AAED;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IAEd;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAA;IAEb;;OAEG;IACH,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;CACtB"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/vended-tools/shell/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAErE,eAAO,MAAM,yBAAyB,QAG8C,CAAA;AAEpF;;;;;GAKG;AACH,qBAAa,iBAAkB,SAAQ,gBAAgB;IACrD,mFAAmF;IACnF,QAAQ,CAAC,OAAO,CAAC,EAAE,WAAW,CAAA;gBAElB,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,WAAW;CAKnD;AAED;;;;;GAKG;AACH,qBAAa,mBAAoB,SAAQ,gBAAgB;gBAC3C,OAAO,EAAE,MAAM;CAI5B;AAED;;;GAGG;AACH,MAAM,WAAW,WAAW;IAC1B;;OAEG;IACH,MAAM,EAAE,MAAM,CAAA;IAEd;;;OAGG;IACH,KAAK,EAAE,MAAM,CAAA;IAEb;;OAEG;IACH,SAAS,EAAE,MAAM,CAAA;IAEjB;;OAEG;IACH,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;CAC/B"}
@@ -5,7 +5,8 @@
5
5
  * callers who caught the pre-rename error types keep working.
6
6
  */
7
7
  import { BashTimeoutError, BashSessionError } from '../bash/types.js';
8
- export const SANDBOX_SHELL_DESCRIPTION = 'Executes shell commands. Each call runs in a fresh shell; ' +
8
+ export const SANDBOX_SHELL_DESCRIPTION = 'Executes shell commands and returns output (stdout), error (stderr), and exit_code (non-zero means the ' +
9
+ 'command failed). Each call runs in a fresh shell; ' +
9
10
  'state such as variables and the working directory does not persist across calls.';
10
11
  /**
11
12
  * Error thrown when a sandbox-routed shell command exceeds its timeout.
@@ -14,9 +15,13 @@ export const SANDBOX_SHELL_DESCRIPTION = 'Executes shell commands. Each call run
14
15
  * type keep working; new code should catch this instead.
15
16
  */
16
17
  export class ShellTimeoutError extends BashTimeoutError {
17
- constructor(message) {
18
+ /** Output captured before the command was killed, when the sandbox reported it. */
19
+ partial;
20
+ constructor(message, partial) {
18
21
  super(message);
19
22
  this.name = 'ShellTimeoutError';
23
+ if (partial)
24
+ this.partial = partial;
20
25
  }
21
26
  }
22
27
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/vended-tools/shell/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAErE,MAAM,CAAC,MAAM,yBAAyB,GACpC,4DAA4D;IAC5D,kFAAkF,CAAA;AAEpF;;;;;GAKG;AACH,MAAM,OAAO,iBAAkB,SAAQ,gBAAgB;IACrD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAA;IACjC,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,mBAAoB,SAAQ,gBAAgB;IACvD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;IACnC,CAAC;CACF"}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/vended-tools/shell/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAErE,MAAM,CAAC,MAAM,yBAAyB,GACpC,yGAAyG;IACzG,oDAAoD;IACpD,kFAAkF,CAAA;AAEpF;;;;;GAKG;AACH,MAAM,OAAO,iBAAkB,SAAQ,gBAAgB;IACrD,mFAAmF;IAC1E,OAAO,CAAc;IAE9B,YAAY,OAAe,EAAE,OAAqB;QAChD,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,mBAAmB,CAAA;QAC/B,IAAI,OAAO;YAAE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAA;IACrC,CAAC;CACF;AAED;;;;;GAKG;AACH,MAAM,OAAO,mBAAoB,SAAQ,gBAAgB;IACvD,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAA;QACd,IAAI,CAAC,IAAI,GAAG,qBAAqB,CAAA;IACnC,CAAC;CACF"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * HTML → markdown extraction for the web fetch tool.
3
+ *
4
+ * Delegates HTML-to-markdown conversion to turndown with ATX headings and
5
+ * fenced code blocks. Non-content elements (scripts, styles, media, forms,
6
+ * etc.) are dropped entirely. `data:` URI images are replaced with their alt
7
+ * text (or nothing) to avoid enormous blobs in the output. `javascript:`
8
+ * hrefs and src values are stripped silently.
9
+ *
10
+ * Requires `turndown` as an optional peer dependency.
11
+ */
12
+ /**
13
+ * Convert HTML to markdown suitable for a model to read.
14
+ *
15
+ * The page title, if present, is rendered as a top-level ATX heading so the
16
+ * model sees it as part of the document. Returns the original HTML string if
17
+ * conversion fails.
18
+ *
19
+ * @param html - Raw HTML string to convert.
20
+ * @returns The converted markdown string, or the original HTML if conversion failed.
21
+ */
22
+ export declare function htmlToMarkdown(html: string): Promise<string>;
23
+ //# sourceMappingURL=extract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.d.ts","sourceRoot":"","sources":["../../../../src/vended-tools/web-fetch/extract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAyGH;;;;;;;;;GASG;AACH,wBAAsB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAUlE"}
@@ -0,0 +1,130 @@
1
+ /**
2
+ * HTML → markdown extraction for the web fetch tool.
3
+ *
4
+ * Delegates HTML-to-markdown conversion to turndown with ATX headings and
5
+ * fenced code blocks. Non-content elements (scripts, styles, media, forms,
6
+ * etc.) are dropped entirely. `data:` URI images are replaced with their alt
7
+ * text (or nothing) to avoid enormous blobs in the output. `javascript:`
8
+ * hrefs and src values are stripped silently.
9
+ *
10
+ * Requires `turndown` as an optional peer dependency.
11
+ */
12
+ import { logger } from '../../logging/logger.js';
13
+ // Elements whose entire subtree is discarded.
14
+ const DROPPED_ELEMENTS = [
15
+ 'script',
16
+ 'style',
17
+ 'noscript',
18
+ 'template',
19
+ 'svg',
20
+ 'canvas',
21
+ 'iframe',
22
+ 'object',
23
+ 'embed',
24
+ 'video',
25
+ 'audio',
26
+ 'form',
27
+ 'input',
28
+ 'button',
29
+ 'select',
30
+ 'textarea',
31
+ 'nav',
32
+ ];
33
+ // Strip invisible characters before URL scheme detection.
34
+ function _stripInvisible(value) {
35
+ return value.replace(/^[\p{Cc}\p{Cf}\p{Zs}]+/u, '');
36
+ }
37
+ async function loadTurndown() {
38
+ try {
39
+ return (await import('turndown')).default;
40
+ }
41
+ catch (cause) {
42
+ throw new Error("web_fetch requires the 'turndown' package. Install it with: npm install turndown", { cause });
43
+ }
44
+ }
45
+ async function _createTurndownService() {
46
+ const Turndown = await loadTurndown();
47
+ const td = new Turndown({
48
+ headingStyle: 'atx',
49
+ codeBlockStyle: 'fenced',
50
+ bulletListMarker: '-',
51
+ emDelimiter: '*',
52
+ strongDelimiter: '**',
53
+ linkStyle: 'inlined',
54
+ });
55
+ // Cast needed because svg/noscript/template are absent from HTMLElementTagNameMap.
56
+ td.remove(DROPPED_ELEMENTS);
57
+ // Render the <title> as a top-level heading so it appears in the document
58
+ // body rather than being silently dropped (turndown ignores <head> elements).
59
+ td.addRule('title', {
60
+ filter: 'title',
61
+ replacement: (_content, node) => {
62
+ const text = node.textContent?.trim() ?? '';
63
+ return text ? `# ${text}\n\n` : '';
64
+ },
65
+ });
66
+ // Replace data: URI images with alt text only (they can be enormous blobs).
67
+ // Strip javascript: src values entirely.
68
+ td.addRule('safeImage', {
69
+ filter: 'img',
70
+ replacement: (_content, node) => {
71
+ const element = node;
72
+ const src = (element.getAttribute('src') ?? '').trim();
73
+ const alt = element.getAttribute('alt') ?? '';
74
+ if (!src)
75
+ return alt;
76
+ try {
77
+ const scheme = new URL(_stripInvisible(src)).protocol;
78
+ if (scheme === 'javascript:')
79
+ return '';
80
+ if (scheme === 'data:')
81
+ return alt;
82
+ }
83
+ catch {
84
+ // not an absolute URL — pass through as-is
85
+ }
86
+ return `![${alt}](${src})`;
87
+ },
88
+ });
89
+ // Strip javascript: hrefs — render link text only.
90
+ td.addRule('safeLink', {
91
+ filter: (node) => {
92
+ if (node.nodeName !== 'A')
93
+ return false;
94
+ const href = (node.getAttribute('href') ?? '').trim();
95
+ try {
96
+ return new URL(_stripInvisible(href)).protocol === 'javascript:';
97
+ }
98
+ catch {
99
+ return false;
100
+ }
101
+ },
102
+ replacement: (content) => content,
103
+ });
104
+ return td;
105
+ }
106
+ // Cache the configured service so rules are registered once across all calls.
107
+ let _turndownServicePromise = null;
108
+ /**
109
+ * Convert HTML to markdown suitable for a model to read.
110
+ *
111
+ * The page title, if present, is rendered as a top-level ATX heading so the
112
+ * model sees it as part of the document. Returns the original HTML string if
113
+ * conversion fails.
114
+ *
115
+ * @param html - Raw HTML string to convert.
116
+ * @returns The converted markdown string, or the original HTML if conversion failed.
117
+ */
118
+ export async function htmlToMarkdown(html) {
119
+ _turndownServicePromise ??= _createTurndownService();
120
+ const td = await _turndownServicePromise;
121
+ try {
122
+ const markdown = td.turndown(html).trim();
123
+ return markdown ? markdown + '\n' : '';
124
+ }
125
+ catch (error) {
126
+ logger.warn(`error=<${error}> | html_to_markdown failed, returning raw html`);
127
+ return html;
128
+ }
129
+ }
130
+ //# sourceMappingURL=extract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extract.js","sourceRoot":"","sources":["../../../../src/vended-tools/web-fetch/extract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAIH,OAAO,EAAE,MAAM,EAAE,MAAM,yBAAyB,CAAA;AA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AQ,KAAK,aAAa,CAAA;YAClE,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,KAAK,CAAA;YACd,CAAC;QACH,CAAC;QACD,WAAW,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,OAAO;KAClC,CAAC,CAAA;IAEF,OAAO,EAAE,CAAA;AACX,CAAC;AAED,8EAA8E;AAC9E,IAAI,uBAAuB,GAAoC,IAAI,CAAA;AAEnE;;;;;;;;;GASG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,IAAY;IAC/C,uBAAuB,KAAK,sBAAsB,EAAE,CAAA;IACpD,MAAM,EAAE,GAAG,MAAM,uBAAuB,CAAA;IACxC,IAAI,CAAC;QACH,MAAM,QAAQ,GAAG,EAAE,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAA;QACzC,OAAO,QAAQ,CAAC,CAAC,CAAC,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,EAAE,CAAA;IACxC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,CAAC,IAAI,CAAC,UAAU,KAAK,iDAAiD,CAAC,CAAA;QAC7E,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC"}
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Web fetch tool: fetch a URL and return clean markdown suitable for a model to read.
3
+ *
4
+ * Distinct from the http-request tool (raw API calls). See {@link webFetch}.
5
+ */
6
+ export { webFetch, makeWebFetch } from './web-fetch.js';
7
+ export type { MakeWebFetchOptions } from './types.js';
8
+ export type { WebFetchMarkdownInput, WebFetchAgenticInput } from './types.js';
9
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/vended-tools/web-fetch/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AACvD,YAAY,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA;AACrD,YAAY,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,MAAM,YAAY,CAAA"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Web fetch tool: fetch a URL and return clean markdown suitable for a model to read.
3
+ *
4
+ * Distinct from the http-request tool (raw API calls). See {@link webFetch}.
5
+ */
6
+ export { webFetch, makeWebFetch } from './web-fetch.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/vended-tools/web-fetch/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA"}
@@ -0,0 +1,40 @@
1
+ import type { Model } from '../../models/model.js';
2
+ /**
3
+ * Input parameters for the markdown mode web fetch tool.
4
+ */
5
+ export interface WebFetchMarkdownInput {
6
+ /** URL to fetch. Must be http:// or https://. */
7
+ url: string;
8
+ }
9
+ /**
10
+ * Input parameters for the agentic mode web fetch tool.
11
+ */
12
+ export interface WebFetchAgenticInput {
13
+ /** URL to fetch. Must be http:// or https://. */
14
+ url: string;
15
+ /** Question or instruction about the page content. */
16
+ prompt: string;
17
+ }
18
+ export declare const WEB_FETCH_DESCRIPTION_MARKDOWN: string;
19
+ export declare const WEB_FETCH_DESCRIPTION_AGENTIC: string;
20
+ /**
21
+ * Options for {@link makeWebFetch}.
22
+ */
23
+ export interface MakeWebFetchOptions {
24
+ /** Tool name shown to the model. Defaults to `'web_fetch'`. */
25
+ name?: string;
26
+ /** Tool description shown to the model. Defaults to a mode-appropriate description. */
27
+ description?: string;
28
+ /** Maximum response body size in bytes. Defaults to 5 MiB. */
29
+ maxBytes?: number;
30
+ /** Maximum characters of extracted content delivered to the model. Defaults to 50,000. */
31
+ maxContentChars?: number;
32
+ /**
33
+ * Optional model for the analyst agent. Only used when `mode` is `'agentic'`.
34
+ * Falls back to the host agent's model when not provided.
35
+ */
36
+ model?: Model;
37
+ /** Extraction mode. Defaults to `'agentic'`. */
38
+ mode?: 'markdown' | 'agentic';
39
+ }
40
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/vended-tools/web-fetch/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,uBAAuB,CAAA;AAElD;;GAEG;AACH,MAAM,WAAW,qBAAqB;IACpC,iDAAiD;IACjD,GAAG,EAAE,MAAM,CAAA;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC,iDAAiD;IACjD,GAAG,EAAE,MAAM,CAAA;IACX,sDAAsD;IACtD,MAAM,EAAE,MAAM,CAAA;CACf;AAED,eAAO,MAAM,8BAA8B,QAGA,CAAA;AAE3C,eAAO,MAAM,6BAA6B,QAIL,CAAA;AAErC;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,+DAA+D;IAC/D,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,uFAAuF;IACvF,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,8DAA8D;IAC9D,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,0FAA0F;IAC1F,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB;;;OAGG;IACH,KAAK,CAAC,EAAE,KAAK,CAAA;IACb,gDAAgD;IAChD,IAAI,CAAC,EAAE,UAAU,GAAG,SAAS,CAAA;CAC9B"}
@@ -0,0 +1,8 @@
1
+ export const WEB_FETCH_DESCRIPTION_MARKDOWN = 'Fetches an HTTP(S) URL and returns its content as clean markdown. ' +
2
+ 'HTML pages are converted to markdown with scripts, styles, and noise stripped; ' +
3
+ 'other content types are returned as-is.';
4
+ export const WEB_FETCH_DESCRIPTION_AGENTIC = 'Fetches an HTTP(S) URL and answers a prompt about its content. ' +
5
+ 'The analyst processes the page directly so the full content never enters ' +
6
+ "the main agent's context. " +
7
+ 'The prompt parameter is required.';
8
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/vended-tools/web-fetch/types.ts"],"names":[],"mappings":"AAoBA,MAAM,CAAC,MAAM,8BAA8B,GACzC,oEAAoE;IACpE,iFAAiF;IACjF,yCAAyC,CAAA;AAE3C,MAAM,CAAC,MAAM,6BAA6B,GACxC,iEAAiE;IACjE,2EAA2E;IAC3E,4BAA4B;IAC5B,mCAAmC,CAAA"}
@@ -0,0 +1,14 @@
1
+ import { tool } from '../../tools/tool-factory.js';
2
+ import { type MakeWebFetchOptions } from './types.js';
3
+ export declare const DEFAULT_MAX_BYTES: number;
4
+ export declare const DEFAULT_MAX_CONTENT_CHARS = 50000;
5
+ /**
6
+ * Create a web fetch tool. The exported {@link webFetch} is a default instance
7
+ * with conservative limits; use this factory to tune them.
8
+ */
9
+ export declare function makeWebFetch(options?: MakeWebFetchOptions): ReturnType<typeof tool>;
10
+ /**
11
+ * Default web fetch tool (agentic mode). See {@link makeWebFetch} to tune limits or switch modes.
12
+ */
13
+ export declare const webFetch: import("../../index.js").InvokableTool<unknown, import("../../index.js").JSONValue>;
14
+ //# sourceMappingURL=web-fetch.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-fetch.d.ts","sourceRoot":"","sources":["../../../../src/vended-tools/web-fetch/web-fetch.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAA;AAElD,OAAO,EAAE,KAAK,mBAAmB,EAAiE,MAAM,YAAY,CAAA;AAEpH,eAAO,MAAM,iBAAiB,QAAkB,CAAA;AAChD,eAAO,MAAM,yBAAyB,QAAS,CAAA;AA4B/C;;;GAGG;AACH,wBAAgB,YAAY,CAAC,OAAO,GAAE,mBAAwB,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAiFvF;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,qFAAiB,CAAA"}
@@ -0,0 +1,175 @@
1
+ import { z } from 'zod';
2
+ import { Agent } from '../../agent/agent.js';
3
+ import { tool } from '../../tools/tool-factory.js';
4
+ import { htmlToMarkdown } from './extract.js';
5
+ import { WEB_FETCH_DESCRIPTION_MARKDOWN, WEB_FETCH_DESCRIPTION_AGENTIC } from './types.js';
6
+ export const DEFAULT_MAX_BYTES = 5 * 1024 * 1024; // 5 MiB
7
+ export const DEFAULT_MAX_CONTENT_CHARS = 50_000;
8
+ const _HEADERS = {
9
+ 'User-Agent': 'strands-agents-web-fetch/1.0',
10
+ Accept: 'text/html,application/xhtml+xml;q=0.9,*/*;q=0.8',
11
+ };
12
+ const _ANALYST_PROMPT = 'You answer a request about a single fetched web page. Use only the provided ' +
13
+ 'content; if it does not contain the answer, say so plainly. Be concise and ' +
14
+ 'factual, and preserve concrete details (names, numbers, quotes, links) ' +
15
+ 'relevant to the request.';
16
+ /**
17
+ * Zod schema for markdown mode web fetch input validation.
18
+ */
19
+ const webFetchMarkdownInputSchema = z.object({
20
+ url: z.string().describe('URL to fetch. Must be http:// or https://.'),
21
+ });
22
+ /**
23
+ * Zod schema for agentic mode web fetch input validation.
24
+ */
25
+ const webFetchAgenticInputSchema = z.object({
26
+ url: z.string().describe('URL to fetch. Must be http:// or https://.'),
27
+ prompt: z.string().describe('Question or instruction about the page content.'),
28
+ });
29
+ /**
30
+ * Create a web fetch tool. The exported {@link webFetch} is a default instance
31
+ * with conservative limits; use this factory to tune them.
32
+ */
33
+ export function makeWebFetch(options = {}) {
34
+ const { mode = 'agentic', model: analystModel } = options;
35
+ const maxBytes = options.maxBytes ?? DEFAULT_MAX_BYTES;
36
+ const maxContentChars = options.maxContentChars ?? DEFAULT_MAX_CONTENT_CHARS;
37
+ if (maxBytes <= 0) {
38
+ throw new Error(`maxBytes must be a positive number, got ${maxBytes}`);
39
+ }
40
+ if (maxContentChars <= 0) {
41
+ throw new Error(`maxContentChars must be a positive number, got ${maxContentChars}`);
42
+ }
43
+ const name = options.name ?? 'web_fetch';
44
+ const description = options.description ?? (mode === 'markdown' ? WEB_FETCH_DESCRIPTION_MARKDOWN : WEB_FETCH_DESCRIPTION_AGENTIC);
45
+ const markdownTool = tool({
46
+ name,
47
+ description,
48
+ inputSchema: webFetchMarkdownInputSchema,
49
+ callback: async (input, context) => {
50
+ const { url } = input;
51
+ const signal = context?.cancelSignal ?? null;
52
+ const [contentType, raw] = await fetchOnce(url, maxBytes, signal);
53
+ const isMarkup = contentType.toLowerCase().includes('html') || contentType.toLowerCase().includes('xml');
54
+ let content = isMarkup ? await htmlToMarkdown(raw) : raw;
55
+ if (content.length > maxContentChars) {
56
+ content = content.slice(0, maxContentChars) + '\n\n[content truncated]';
57
+ }
58
+ return content;
59
+ },
60
+ });
61
+ const agenticTool = tool({
62
+ name,
63
+ description,
64
+ inputSchema: webFetchAgenticInputSchema,
65
+ callback: async (input, context) => {
66
+ const { url, prompt } = input;
67
+ if (!prompt.trim()) {
68
+ throw new Error('web_fetch: agentic mode requires a non-empty prompt.');
69
+ }
70
+ const effectiveModel = analystModel ?? context?.agent.model;
71
+ if (!effectiveModel) {
72
+ throw new Error('web_fetch: agentic mode requires a model. ' + 'Pass model to makeWebFetch or call the tool from an agent.');
73
+ }
74
+ const signal = context?.cancelSignal ?? null;
75
+ const invokeOptions = context?.cancelSignal ? { cancelSignal: context.cancelSignal } : {};
76
+ const [contentType, raw] = await fetchOnce(url, maxBytes, signal);
77
+ const isMarkup = contentType.toLowerCase().includes('html') || contentType.toLowerCase().includes('xml');
78
+ let content = isMarkup ? await htmlToMarkdown(raw) : raw;
79
+ if (content.length > maxContentChars) {
80
+ content = content.slice(0, maxContentChars) + '\n\n[content truncated]';
81
+ }
82
+ // Fresh agent per call — no history from one fetch bleeds into the next.
83
+ const analyst = new Agent({ model: effectiveModel, systemPrompt: _ANALYST_PROMPT, printer: false });
84
+ const invokePrompt = `URL: ${url}\n\nRequest: ${prompt}\n\n--- Content ---\n${content}`;
85
+ try {
86
+ const result = await analyst.invoke(invokePrompt, invokeOptions);
87
+ return result.lastMessage.content
88
+ .filter((block) => block.type === 'textBlock')
89
+ .map((block) => block.text)
90
+ .join('');
91
+ }
92
+ catch (error) {
93
+ throw new Error(`url=<${url}> | web fetch analyst failed: ${error instanceof Error ? error.message : String(error)}`, { cause: error });
94
+ }
95
+ },
96
+ });
97
+ return mode === 'markdown' ? markdownTool : agenticTool;
98
+ }
99
+ /**
100
+ * Default web fetch tool (agentic mode). See {@link makeWebFetch} to tune limits or switch modes.
101
+ */
102
+ export const webFetch = makeWebFetch();
103
+ // ---- Internals ----
104
+ async function fetchOnce(url, maxBytes, signal) {
105
+ // Validate scheme before hitting the network
106
+ if (!URL.canParse(url)) {
107
+ throw new Error(`url=<${url}> | fetch failed: invalid URL`);
108
+ }
109
+ const { protocol } = new URL(url);
110
+ if (protocol !== 'http:' && protocol !== 'https:') {
111
+ throw new Error(`url=<${url}> | fetch failed: only http and https URLs are supported`);
112
+ }
113
+ let response;
114
+ try {
115
+ response = await globalThis.fetch(url, { method: 'GET', headers: _HEADERS, signal });
116
+ }
117
+ catch (error) {
118
+ if (error instanceof Error && error.name === 'AbortError') {
119
+ throw new Error('Web fetch tool request cancelled', { cause: error });
120
+ }
121
+ throw new Error(`url=<${url}> | fetch failed: ${error instanceof Error ? error.message : String(error)}`, {
122
+ cause: error,
123
+ });
124
+ }
125
+ if (!response.ok) {
126
+ await response.body?.cancel();
127
+ throw new Error(`HTTP ${response.status} ${response.statusText}: GET ${url}`);
128
+ }
129
+ // Stream the body and enforce the size cap on decompressed bytes as they arrive.
130
+ if (!response.body) {
131
+ return [response.headers.get('content-type') ?? '', ''];
132
+ }
133
+ const contentType = response.headers.get('content-type') ?? '';
134
+ const charset = _parseCharset(contentType);
135
+ const reader = response.body.getReader();
136
+ const decoder = new TextDecoder(charset);
137
+ const chunks = [];
138
+ let total = 0;
139
+ try {
140
+ while (true) {
141
+ const { done, value } = await reader.read();
142
+ if (done)
143
+ break;
144
+ total += value.byteLength;
145
+ if (total > maxBytes) {
146
+ throw new Error(`Response body exceeded max_bytes=${maxBytes}. Refusing to buffer more.`);
147
+ }
148
+ chunks.push(decoder.decode(value, { stream: true }));
149
+ }
150
+ chunks.push(decoder.decode());
151
+ }
152
+ catch (error) {
153
+ if (error instanceof Error && error.name === 'AbortError') {
154
+ throw new Error('Web fetch tool request cancelled', { cause: error });
155
+ }
156
+ throw error;
157
+ }
158
+ finally {
159
+ reader.cancel().catch(() => { });
160
+ reader.releaseLock();
161
+ }
162
+ return [contentType, chunks.join('')];
163
+ }
164
+ function _parseCharset(contentType) {
165
+ const match = contentType.match(/charset=(?:"([^"]+)"|'([^']+)'|([^;\s]+))/i);
166
+ const charset = (match?.[1] ?? match?.[2] ?? match?.[3] ?? 'utf-8').toLowerCase();
167
+ try {
168
+ new TextDecoder(charset);
169
+ return charset;
170
+ }
171
+ catch {
172
+ return 'utf-8';
173
+ }
174
+ }
175
+ //# sourceMappingURL=web-fetch.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-fetch.js","sourceRoot":"","sources":["../../../../src/vended-tools/web-fetch/web-fetch.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,OAAO,EAAE,KAAK,EAAE,MAAM,sBAAsB,CAAA;AAC5C,OAAO,EAAE,IAAI,EAAE,MAAM,6BAA6B,CAAA;AAClD,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,EAA4B,8BAA8B,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAA;AAEpH,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAA,CAAC,QAAQ;AACzD,MAAM,CAAC,MAAM,yBAAyB,GAAG,MAAM,CAAA;AAE/C,MAAM,QAAQ,GAAG;IACf,YAAY,EAAE,8BAA8B;IAC5C,MAAM,EAAE,iDAAiD;CAC1D,CAAA;AAED,MAAM,eAAe,GACnB,8EAA8E;IAC9E,6EA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IAChB,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,OAAO,CAAA;IAChB,CAAC;AACH,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@strands-agents/sdk",
3
- "version": "1.16.0",
3
+ "version": "1.18.0",
4
4
  "description": "TypeScript SDK for Strands Agents framework",
5
5
  "main": "dist/src/index.js",
6
6
  "module": "dist/src/index.js",
@@ -84,6 +84,10 @@
84
84
  "types": "./dist/src/experimental/vended-tools/stop/index.d.ts",
85
85
  "default": "./dist/src/experimental/vended-tools/stop/index.js"
86
86
  },
87
+ "./vended-tools/web-fetch": {
88
+ "types": "./dist/src/vended-tools/web-fetch/index.d.ts",
89
+ "default": "./dist/src/vended-tools/web-fetch/index.js"
90
+ },
87
91
  "./a2a": {
88
92
  "types": "./dist/src/a2a/index.d.ts",
89
93
  "default": "./dist/src/a2a/index.js"
@@ -162,6 +166,12 @@
162
166
  "default": "./dist/src/storage/search/qmd.js"
163
167
  }
164
168
  },
169
+ "./storage/search/bm25": {
170
+ "node": {
171
+ "types": "./dist/src/storage/search/qmd.d.ts",
172
+ "default": "./dist/src/storage/search/qmd.js"
173
+ }
174
+ },
165
175
  "./sandbox": {
166
176
  "types": "./dist/src/sandbox/index.d.ts",
167
177
  "default": "./dist/src/sandbox/index.js"
@@ -239,6 +249,7 @@
239
249
  "@smithy/types": "^4.15.1",
240
250
  "@types/express": "^5.0.6",
241
251
  "@types/node": "^25.9.4",
252
+ "@types/turndown": "^5.0.6",
242
253
  "@typescript-eslint/eslint-plugin": "^8.62.1",
243
254
  "@typescript-eslint/parser": "^8.0.0",
244
255
  "@vitest/browser": "^4.1.10",
@@ -250,14 +261,12 @@
250
261
  "openai": "^6.45.0",
251
262
  "playwright": "^1.61.0",
252
263
  "tsx": "^4.22.5",
264
+ "turndown": "^7.2.4",
253
265
  "typescript": "^6.0.3",
254
266
  "vitest": "^4.1.10"
255
267
  },
256
- "optionalDependencies": {
257
- "@tobilu/qmd": "^2.8.0"
258
- },
259
268
  "engines": {
260
- "node": ">=20.0.0"
269
+ "node": ">=22.0.0"
261
270
  },
262
271
  "repository": {
263
272
  "type": "git",
@@ -297,6 +306,7 @@
297
306
  "@tobilu/qmd": "^2.8.0",
298
307
  "express": "^5.1.0",
299
308
  "openai": "^6.45.0",
309
+ "turndown": "^7.2.4",
300
310
  "zod": "^4.1.12"
301
311
  },
302
312
  "peerDependenciesMeta": {
@@ -359,6 +369,9 @@
359
369
  },
360
370
  "@tobilu/qmd": {
361
371
  "optional": true
372
+ },
373
+ "turndown": {
374
+ "optional": true
362
375
  }
363
376
  },
364
377
  "overrides": {