@orchestraai/agent-tools 0.10.16 → 0.10.17

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 (183) hide show
  1. package/.agents/plugins/marketplace.json +1 -1
  2. package/.claude-plugin/marketplace.json +1 -1
  3. package/.claude-plugin/plugin.json +1 -1
  4. package/.codex-plugin/plugin.json +1 -1
  5. package/.cursor-plugin/plugin.json +1 -1
  6. package/.devin/adapter.json +1 -1
  7. package/.hermes/adapter.json +1 -1
  8. package/.opencode/adapter.json +1 -1
  9. package/dist/commands/claude-setup.d.ts +1 -1
  10. package/dist/runtime/conversation/command-guard.js +1023 -63
  11. package/dist/runtime/conversation/command-guard.js.map +1 -1
  12. package/dist/runtime/conversation/shell-parse.d.ts +42 -0
  13. package/dist/runtime/conversation/shell-parse.js +517 -0
  14. package/dist/runtime/conversation/shell-parse.js.map +1 -0
  15. package/docs/security.md +11 -2
  16. package/node_modules/@hono/node-server/dist/index.cjs +63 -17
  17. package/node_modules/@hono/node-server/dist/index.mjs +63 -17
  18. package/node_modules/@hono/node-server/dist/serve-static.cjs +1 -1
  19. package/node_modules/@hono/node-server/dist/serve-static.mjs +1 -1
  20. package/node_modules/@hono/node-server/package.json +1 -1
  21. package/node_modules/cross-spawn/README.md +19 -3
  22. package/node_modules/cross-spawn/lib/parse.js +38 -10
  23. package/node_modules/cross-spawn/lib/util/escape.js +84 -25
  24. package/node_modules/cross-spawn/lib/util/readShebang.js +8 -2
  25. package/node_modules/cross-spawn/lib/util/resolveCommand.js +8 -1
  26. package/node_modules/cross-spawn/package.json +21 -24
  27. package/node_modules/hono/README.md +2 -3
  28. package/node_modules/hono/dist/adapter/aws-lambda/handler.js +2 -2
  29. package/node_modules/hono/dist/adapter/bun/websocket.js +19 -4
  30. package/node_modules/hono/dist/adapter/lambda-edge/handler.js +5 -1
  31. package/node_modules/hono/dist/cjs/adapter/aws-lambda/handler.js +2 -2
  32. package/node_modules/hono/dist/cjs/adapter/bun/websocket.js +19 -4
  33. package/node_modules/hono/dist/cjs/adapter/lambda-edge/handler.js +5 -1
  34. package/node_modules/hono/dist/cjs/client/fetch-result-please.js +1 -1
  35. package/node_modules/hono/dist/cjs/client/utils.js +9 -5
  36. package/node_modules/hono/dist/cjs/context.js +1 -1
  37. package/node_modules/hono/dist/cjs/helper/accepts/accepts.js +7 -1
  38. package/node_modules/hono/dist/cjs/helper/css/common.js +11 -8
  39. package/node_modules/hono/dist/cjs/helper/css/index.js +1 -1
  40. package/node_modules/hono/dist/cjs/helper/proxy/index.js +2 -0
  41. package/node_modules/hono/dist/cjs/helper/route/index.js +3 -1
  42. package/node_modules/hono/dist/cjs/helper/ssg/ssg.js +5 -3
  43. package/node_modules/hono/dist/cjs/helper/streaming/sse.js +6 -2
  44. package/node_modules/hono/dist/cjs/hono-base.js +9 -10
  45. package/node_modules/hono/dist/cjs/hono.js +0 -1
  46. package/node_modules/hono/dist/cjs/jsx/base.js +51 -32
  47. package/node_modules/hono/dist/cjs/jsx/components.js +2 -2
  48. package/node_modules/hono/dist/cjs/jsx/constants.js +2 -0
  49. package/node_modules/hono/dist/cjs/jsx/context.js +15 -2
  50. package/node_modules/hono/dist/cjs/jsx/dom/components.js +1 -1
  51. package/node_modules/hono/dist/cjs/jsx/dom/hooks/index.js +38 -8
  52. package/node_modules/hono/dist/cjs/jsx/dom/intrinsic-element/components.js +8 -5
  53. package/node_modules/hono/dist/cjs/jsx/dom/render.js +9 -3
  54. package/node_modules/hono/dist/cjs/jsx/jsx-runtime.js +13 -17
  55. package/node_modules/hono/dist/cjs/middleware/basic-auth/index.js +3 -1
  56. package/node_modules/hono/dist/cjs/middleware/bearer-auth/index.js +9 -1
  57. package/node_modules/hono/dist/cjs/middleware/body-limit/index.js +9 -10
  58. package/node_modules/hono/dist/cjs/middleware/combine/index.js +4 -0
  59. package/node_modules/hono/dist/cjs/middleware/compress/index.js +2 -3
  60. package/node_modules/hono/dist/cjs/middleware/csrf/index.js +2 -2
  61. package/node_modules/hono/dist/cjs/middleware/etag/index.js +3 -1
  62. package/node_modules/hono/dist/cjs/middleware/jwk/jwk.js +2 -2
  63. package/node_modules/hono/dist/cjs/middleware/jwt/jwt.js +2 -2
  64. package/node_modules/hono/dist/cjs/middleware/method-not-allowed/index.js +1 -1
  65. package/node_modules/hono/dist/cjs/middleware/method-override/index.js +35 -12
  66. package/node_modules/hono/dist/cjs/middleware/mount/index.js +5 -4
  67. package/node_modules/hono/dist/cjs/middleware/pretty-json/index.js +1 -0
  68. package/node_modules/hono/dist/cjs/middleware/request-id/request-id.js +3 -3
  69. package/node_modules/hono/dist/cjs/middleware/secure-headers/secure-headers.js +6 -3
  70. package/node_modules/hono/dist/cjs/middleware/serve-static/index.js +4 -2
  71. package/node_modules/hono/dist/cjs/middleware/timing/timing.js +4 -3
  72. package/node_modules/hono/dist/cjs/router/reg-exp-router/node.js +13 -11
  73. package/node_modules/hono/dist/cjs/router/reg-exp-router/prepared-router.js +4 -4
  74. package/node_modules/hono/dist/cjs/router/reg-exp-router/router.js +39 -51
  75. package/node_modules/hono/dist/cjs/router/reg-exp-router/trie.js +15 -5
  76. package/node_modules/hono/dist/cjs/router/trie-router/node.js +6 -4
  77. package/node_modules/hono/dist/cjs/utils/body.js +2 -1
  78. package/node_modules/hono/dist/cjs/utils/cookie.js +3 -3
  79. package/node_modules/hono/dist/cjs/utils/html.js +5 -0
  80. package/node_modules/hono/dist/cjs/utils/jwt/jwt.js +8 -5
  81. package/node_modules/hono/dist/cjs/utils/mime.js +3 -2
  82. package/node_modules/hono/dist/cjs/utils/mount.js +59 -0
  83. package/node_modules/hono/dist/cjs/utils/url.js +23 -11
  84. package/node_modules/hono/dist/cjs/validator/validator.js +5 -5
  85. package/node_modules/hono/dist/client/fetch-result-please.js +1 -1
  86. package/node_modules/hono/dist/client/utils.js +9 -5
  87. package/node_modules/hono/dist/context.js +1 -1
  88. package/node_modules/hono/dist/helper/accepts/accepts.js +7 -1
  89. package/node_modules/hono/dist/helper/css/common.js +11 -8
  90. package/node_modules/hono/dist/helper/css/index.js +1 -1
  91. package/node_modules/hono/dist/helper/proxy/index.js +2 -0
  92. package/node_modules/hono/dist/helper/route/index.js +3 -1
  93. package/node_modules/hono/dist/helper/ssg/ssg.js +5 -3
  94. package/node_modules/hono/dist/helper/streaming/sse.js +6 -2
  95. package/node_modules/hono/dist/hono-base.js +9 -10
  96. package/node_modules/hono/dist/hono.js +0 -1
  97. package/node_modules/hono/dist/jsx/base.js +51 -34
  98. package/node_modules/hono/dist/jsx/components.js +2 -2
  99. package/node_modules/hono/dist/jsx/constants.js +2 -1
  100. package/node_modules/hono/dist/jsx/context.js +15 -2
  101. package/node_modules/hono/dist/jsx/dom/components.js +2 -2
  102. package/node_modules/hono/dist/jsx/dom/hooks/index.js +39 -9
  103. package/node_modules/hono/dist/jsx/dom/intrinsic-element/components.js +8 -5
  104. package/node_modules/hono/dist/jsx/dom/render.js +9 -3
  105. package/node_modules/hono/dist/jsx/jsx-runtime.js +15 -19
  106. package/node_modules/hono/dist/middleware/basic-auth/index.js +3 -1
  107. package/node_modules/hono/dist/middleware/bearer-auth/index.js +9 -1
  108. package/node_modules/hono/dist/middleware/body-limit/index.js +9 -10
  109. package/node_modules/hono/dist/middleware/combine/index.js +4 -0
  110. package/node_modules/hono/dist/middleware/compress/index.js +2 -3
  111. package/node_modules/hono/dist/middleware/csrf/index.js +2 -2
  112. package/node_modules/hono/dist/middleware/etag/index.js +3 -1
  113. package/node_modules/hono/dist/middleware/jwk/jwk.js +2 -2
  114. package/node_modules/hono/dist/middleware/jwt/jwt.js +2 -2
  115. package/node_modules/hono/dist/middleware/method-not-allowed/index.js +1 -1
  116. package/node_modules/hono/dist/middleware/method-override/index.js +35 -12
  117. package/node_modules/hono/dist/middleware/mount/index.js +5 -4
  118. package/node_modules/hono/dist/middleware/pretty-json/index.js +1 -0
  119. package/node_modules/hono/dist/middleware/request-id/request-id.js +3 -3
  120. package/node_modules/hono/dist/middleware/secure-headers/secure-headers.js +6 -3
  121. package/node_modules/hono/dist/middleware/serve-static/index.js +4 -2
  122. package/node_modules/hono/dist/middleware/timing/timing.js +4 -3
  123. package/node_modules/hono/dist/router/reg-exp-router/node.js +13 -11
  124. package/node_modules/hono/dist/router/reg-exp-router/prepared-router.js +5 -5
  125. package/node_modules/hono/dist/router/reg-exp-router/router.js +40 -52
  126. package/node_modules/hono/dist/router/reg-exp-router/trie.js +15 -5
  127. package/node_modules/hono/dist/router/trie-router/node.js +6 -4
  128. package/node_modules/hono/dist/types/adapter/aws-lambda/conninfo.d.ts +1 -1
  129. package/node_modules/hono/dist/types/adapter/bun/conninfo.d.ts +1 -1
  130. package/node_modules/hono/dist/types/adapter/bun/ssg.d.ts +1 -1
  131. package/node_modules/hono/dist/types/adapter/cloudflare-pages/conninfo.d.ts +1 -1
  132. package/node_modules/hono/dist/types/adapter/cloudflare-workers/conninfo.d.ts +1 -1
  133. package/node_modules/hono/dist/types/adapter/deno/conninfo.d.ts +1 -1
  134. package/node_modules/hono/dist/types/adapter/deno/ssg.d.ts +1 -1
  135. package/node_modules/hono/dist/types/adapter/lambda-edge/conninfo.d.ts +1 -1
  136. package/node_modules/hono/dist/types/adapter/netlify/conninfo.d.ts +1 -1
  137. package/node_modules/hono/dist/types/adapter/vercel/conninfo.d.ts +1 -1
  138. package/node_modules/hono/dist/types/helper/accepts/accepts.d.ts +5 -0
  139. package/node_modules/hono/dist/types/helper/factory/index.d.ts +1 -1
  140. package/node_modules/hono/dist/types/helper/ssg/ssg.d.ts +6 -1
  141. package/node_modules/hono/dist/types/helper/streaming/sse.d.ts +1 -1
  142. package/node_modules/hono/dist/types/helper/streaming/stream.d.ts +1 -1
  143. package/node_modules/hono/dist/types/helper/streaming/text.d.ts +1 -1
  144. package/node_modules/hono/dist/types/helper/testing/index.d.ts +2 -1
  145. package/node_modules/hono/dist/types/helper/websocket/index.d.ts +13 -3
  146. package/node_modules/hono/dist/types/hono-base.d.ts +23 -9
  147. package/node_modules/hono/dist/types/index.d.ts +1 -1
  148. package/node_modules/hono/dist/types/jsx/base.d.ts +6 -3
  149. package/node_modules/hono/dist/types/jsx/components.d.ts +2 -2
  150. package/node_modules/hono/dist/types/jsx/constants.d.ts +1 -0
  151. package/node_modules/hono/dist/types/jsx/context.d.ts +2 -2
  152. package/node_modules/hono/dist/types/jsx/dom/components.d.ts +2 -2
  153. package/node_modules/hono/dist/types/jsx/dom/css.d.ts +2 -2
  154. package/node_modules/hono/dist/types/jsx/dom/hooks/index.d.ts +5 -3
  155. package/node_modules/hono/dist/types/jsx/dom/index.d.ts +1 -1
  156. package/node_modules/hono/dist/types/jsx/dom/server.d.ts +1 -1
  157. package/node_modules/hono/dist/types/jsx/index.d.ts +1 -1
  158. package/node_modules/hono/dist/types/jsx/jsx-runtime.d.ts +2 -1
  159. package/node_modules/hono/dist/types/jsx/streaming.d.ts +4 -3
  160. package/node_modules/hono/dist/types/middleware/basic-auth/index.d.ts +1 -0
  161. package/node_modules/hono/dist/types/middleware/bearer-auth/index.d.ts +2 -1
  162. package/node_modules/hono/dist/types/middleware/ip-restriction/index.d.ts +3 -3
  163. package/node_modules/hono/dist/types/middleware/jsx-renderer/index.d.ts +3 -3
  164. package/node_modules/hono/dist/types/middleware/mount/index.d.ts +2 -0
  165. package/node_modules/hono/dist/types/middleware/request-id/request-id.d.ts +3 -3
  166. package/node_modules/hono/dist/types/middleware/secure-headers/secure-headers.d.ts +2 -0
  167. package/node_modules/hono/dist/types/router/reg-exp-router/node.d.ts +3 -3
  168. package/node_modules/hono/dist/types/router/reg-exp-router/trie.d.ts +1 -1
  169. package/node_modules/hono/dist/types/utils/cookie.d.ts +1 -1
  170. package/node_modules/hono/dist/types/utils/ipaddr.d.ts +1 -1
  171. package/node_modules/hono/dist/types/utils/jwt/jwt.d.ts +4 -2
  172. package/node_modules/hono/dist/types/utils/mount.d.ts +4 -0
  173. package/node_modules/hono/dist/types/utils/types.d.ts +12 -2
  174. package/node_modules/hono/dist/utils/body.js +2 -1
  175. package/node_modules/hono/dist/utils/cookie.js +3 -3
  176. package/node_modules/hono/dist/utils/html.js +5 -0
  177. package/node_modules/hono/dist/utils/jwt/jwt.js +8 -5
  178. package/node_modules/hono/dist/utils/mime.js +3 -2
  179. package/node_modules/hono/dist/utils/mount.js +58 -0
  180. package/node_modules/hono/dist/utils/url.js +23 -11
  181. package/node_modules/hono/dist/validator/validator.js +5 -5
  182. package/node_modules/hono/package.json +1 -1
  183. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import { DOM_ERROR_HANDLER } from "../constants.js";
2
- import { Fragment } from "./jsx-dev-runtime.js";
2
+ import { Fragment, jsxDEV } from "./jsx-dev-runtime.js";
3
3
  import "./jsx-runtime.js";
4
4
  //#region src/jsx/dom/components.ts
5
5
  const ErrorBoundary = (({ children, fallback, fallbackRender, onError }) => {
@@ -16,7 +16,7 @@ const Suspense = (({ children, fallback }) => {
16
16
  res[DOM_ERROR_HANDLER] = (err, retry) => {
17
17
  if (!(err instanceof Promise)) throw err;
18
18
  err.finally(retry);
19
- return fallback;
19
+ return fallback || jsxDEV(Fragment, { children: fallback });
20
20
  };
21
21
  return res;
22
22
  });
@@ -1,7 +1,7 @@
1
1
  import { PERMALINK } from "../../constants.js";
2
2
  import { createContext } from "../context.js";
3
3
  import { useContext } from "../../context.js";
4
- import { useCallback, useState } from "../../hooks/index.js";
4
+ import { useCallback, useRef, useState } from "../../hooks/index.js";
5
5
  //#region src/jsx/dom/hooks/index.ts
6
6
  /**
7
7
  * Provide hooks used only in jsx/dom
@@ -15,7 +15,10 @@ const FormContext = createContext({
15
15
  const actions = /* @__PURE__ */ new Set();
16
16
  const registerAction = (action) => {
17
17
  actions.add(action);
18
- action.finally(() => actions.delete(action));
18
+ const remove = () => {
19
+ actions.delete(action);
20
+ };
21
+ action.then(remove, remove);
19
22
  };
20
23
  /**
21
24
  * This hook returns the current form status
@@ -33,7 +36,7 @@ const useFormStatus = () => {
33
36
  */
34
37
  const useOptimistic = (state, updateState) => {
35
38
  const [optimisticState, setOptimisticState] = useState(state);
36
- if (actions.size > 0) Promise.all(actions).finally(() => {
39
+ if (actions.size > 0) Promise.allSettled(actions).then(() => {
37
40
  setOptimisticState(state);
38
41
  });
39
42
  else setOptimisticState(state);
@@ -42,19 +45,46 @@ const useOptimistic = (state, updateState) => {
42
45
  }, [])];
43
46
  };
44
47
  /**
45
- * This hook returns the current state and a function to update the state by form action
48
+ * This hook returns the current state, a function to update the state by form action,
49
+ * and whether an action is pending
50
+ * Actions run one at a time, each receiving the state returned by the previous one
46
51
  * @param fn
47
52
  * @param initialState
48
53
  * @param permalink
49
- * @returns [T, (data: FormData) => void]
54
+ * @returns [T, (data: FormData) => Promise<void>, boolean]
50
55
  */
51
56
  const useActionState = (fn, initialState, permalink) => {
52
57
  const [state, setState] = useState(initialState);
53
- const actionState = async (data) => {
54
- setState(await fn(state, data));
55
- };
58
+ const [pendingCount, setPendingCount] = useState(0);
59
+ const ref = useRef({
60
+ fn,
61
+ state: initialState,
62
+ pending: 0,
63
+ queue: Promise.resolve()
64
+ });
65
+ ref.current.fn = fn;
66
+ const actionState = useCallback((data) => {
67
+ const current = ref.current;
68
+ const run = async () => {
69
+ try {
70
+ current.state = await current.fn(current.state, data);
71
+ setState(current.state);
72
+ } finally {
73
+ current.pending--;
74
+ setPendingCount((count) => count - 1);
75
+ }
76
+ };
77
+ const result = current.pending++ ? current.queue.then(run) : run();
78
+ current.queue = result.catch(() => {});
79
+ setPendingCount((count) => count + 1);
80
+ return result;
81
+ }, []);
56
82
  actionState[PERMALINK] = permalink;
57
- return [state, actionState];
83
+ return [
84
+ state,
85
+ actionState,
86
+ pendingCount > 0
87
+ ];
58
88
  };
59
89
  //#endregion
60
90
  export { FormContext, registerAction, useActionState, useFormStatus, useOptimistic };
@@ -217,12 +217,15 @@ const form = (props) => {
217
217
  ev.preventDefault();
218
218
  const formData = new FormData(ev.target);
219
219
  setState([formData, true]);
220
- const actionRes = currentAction(formData);
221
- if (actionRes instanceof Promise) {
222
- registerAction(actionRes);
223
- await actionRes;
220
+ try {
221
+ const actionRes = currentAction(formData);
222
+ if (actionRes instanceof Promise) {
223
+ registerAction(actionRes);
224
+ await actionRes;
225
+ }
226
+ } finally {
227
+ setState([null, true]);
224
228
  }
225
- setState([null, true]);
226
229
  }, []);
227
230
  const ref = composeRef(props.ref, (el) => {
228
231
  el.addEventListener("submit", onSubmit);
@@ -155,7 +155,11 @@ const findInsertBefore = (node) => {
155
155
  };
156
156
  const removeNode = (node) => {
157
157
  if (!isNodeString(node)) {
158
- node[DOM_STASH]?.[1][1]?.forEach((data) => data[2]?.());
158
+ const stash = node[DOM_STASH];
159
+ if (stash?.[1][1]) {
160
+ stash[1][1].forEach((data) => data[2]?.());
161
+ delete stash[1][1];
162
+ }
159
163
  refCleanupMap.get(node.e)?.();
160
164
  if (node.p === 2) node.vC?.forEach((n) => n.p = 2);
161
165
  node.vC?.forEach(removeNode);
@@ -212,8 +216,9 @@ const applyNodeObject = (node, container, isNew) => {
212
216
  child.d = false;
213
217
  el = child.e ||= document.createTextNode(child.t);
214
218
  } else {
219
+ const isCreated = !child.e;
215
220
  el = child.e ||= child.n ? document.createElementNS(child.n, child.tag) : document.createElement(child.tag);
216
- applyProps(el, child.props, child.pP);
221
+ applyProps(el, child.props, isCreated ? void 0 : child.pP);
217
222
  applyNodeObject(child, el, isNewLocal);
218
223
  if (child.tag === "select") applySelectValue(el, child.props);
219
224
  }
@@ -343,6 +348,7 @@ const build = (context, node, children) => {
343
348
  prevNode = child;
344
349
  }
345
350
  }
351
+ if (prevNode && !prevNode.s) for (let p = prevNode; p && !isNodeString(p); p = p.vC?.at(-1)) p.nN = node.nN;
346
352
  oldVChildren = oldChildrenByKey ? [...oldChildrenByKey.values()] : oldVChildren;
347
353
  node.vR = buildWithPreviousChildren ? [...node.vC, ...oldVChildren || []] : oldVChildren || [];
348
354
  node.vC = vChildren;
@@ -377,7 +383,7 @@ const build = (context, node, children) => {
377
383
  if (context[0] === 1) context[1] = true;
378
384
  else {
379
385
  build(context, errorHandlerNode, [fallback]);
380
- if ((errorHandler.length === 1 || context !== errorHandlerContext) && errorHandlerNode.c) {
386
+ if ((errorHandler.length === 1 || context !== errorHandlerContext) && errorHandlerNode.c && !context[5].some(([, , n]) => n === errorHandlerNode)) {
381
387
  apply(errorHandlerNode, errorHandlerNode.c, false);
382
388
  return;
383
389
  }
@@ -1,31 +1,27 @@
1
1
  import { escapeToBuffer, raw, stringBufferToString } from "../utils/html.js";
2
2
  import { html } from "../helper/html/index.js";
3
- import { isValidAttributeName, styleObjectForEach } from "./utils.js";
4
- import { Fragment } from "./base.js";
3
+ import { PERMALINK } from "./constants.js";
4
+ import { isValidAttributeName } from "./utils.js";
5
+ import { Fragment, attributeToBuffer, markRenderedJSX } from "./base.js";
5
6
  import { jsxDEV } from "./jsx-dev-runtime.js";
6
7
  //#region src/jsx/jsx-runtime.ts
8
+ const jsxTemplate = (strings, ...values) => {
9
+ const result = html(strings, ...values);
10
+ return result instanceof Promise ? result.then(markRenderedJSX) : markRenderedJSX(result);
11
+ };
7
12
  const jsxAttr = (key, v) => {
8
13
  if (!isValidAttributeName(key)) return raw("");
9
- const buffer = [`${key}="`];
10
- if (key === "style" && typeof v === "object") {
11
- let styleStr = "";
12
- styleObjectForEach(v, (property, value) => {
13
- if (value != null) styleStr += `${styleStr ? ";" : ""}${property}:${value}`;
14
- });
15
- escapeToBuffer(styleStr, buffer);
16
- buffer[0] += "\"";
17
- } else if (typeof v === "string") {
14
+ if (typeof v === "string") {
15
+ const buffer = [`${key}="`];
18
16
  escapeToBuffer(v, buffer);
19
- buffer[0] += "\"";
20
- } else if (v === null || v === void 0) return raw("");
21
- else if (typeof v === "number" || v.isEscaped) buffer[0] += `${v}"`;
22
- else if (v instanceof Promise) buffer.unshift("\"", v);
23
- else {
24
- escapeToBuffer(v.toString(), buffer);
25
- buffer[0] += "\"";
17
+ return raw(buffer[0] + "\"");
26
18
  }
19
+ let value = v;
20
+ if (typeof value === "function" && (key === "action" || key === "formaction")) value = PERMALINK in value ? value[PERMALINK] : void 0;
21
+ const buffer = [""];
22
+ attributeToBuffer(buffer, "", key, value);
27
23
  return buffer.length === 1 ? raw(buffer[0]) : stringBufferToString(buffer, void 0);
28
24
  };
29
25
  const jsxEscape = (value) => value;
30
26
  //#endregion
31
- export { Fragment, jsxDEV as jsx, jsxAttr, jsxEscape, html as jsxTemplate, jsxDEV as jsxs };
27
+ export { Fragment, jsxDEV as jsx, jsxAttr, jsxEscape, jsxTemplate, jsxDEV as jsxs };
@@ -15,6 +15,7 @@ import { auth } from "../../utils/basic-auth.js";
15
15
  * @param {Function} [options.verifyUser] - The function to verify user credentials.
16
16
  * @param {string | object | MessageFunction} [options.invalidUserMessage="Unauthorized"] - The invalid user message.
17
17
  * @param {Function} [options.onAuthSuccess] - Callback function called on successful authentication.
18
+ * @param {...{ username: string; password: string }} [users] - Additional user credentials.
18
19
  * @returns {MiddlewareHandler} The middleware handler function.
19
20
  * @throws {HTTPException} If neither "username and password" nor "verifyUser" options are provided.
20
21
  *
@@ -61,6 +62,7 @@ const basicAuth = (options, ...users) => {
61
62
  username: options.username,
62
63
  password: options.password
63
64
  });
65
+ for (const user of users) if (typeof user.username !== "string" || typeof user.password !== "string") throw new Error("basic auth middleware requires \"username\" and \"password\" to be strings");
64
66
  return async function basicAuth(ctx, next) {
65
67
  const requestUser = auth(ctx.req.raw);
66
68
  if (requestUser) {
@@ -80,7 +82,7 @@ const basicAuth = (options, ...users) => {
80
82
  }
81
83
  }
82
84
  const status = 401;
83
- const headers = { "WWW-Authenticate": "Basic realm=\"" + options.realm?.replace(/"/g, "\\\"") + "\"" };
85
+ const headers = { "WWW-Authenticate": "Basic realm=\"" + options.realm?.replace(/[\\"]/g, "\\$&") + "\"" };
84
86
  const responseMessage = typeof options.invalidUserMessage === "function" ? await options.invalidUserMessage(ctx) : options.invalidUserMessage;
85
87
  const res = typeof responseMessage === "string" ? new Response(responseMessage, {
86
88
  status,
@@ -44,7 +44,7 @@ const bearerAuth = (options) => {
44
44
  if (!("token" in options || "verifyToken" in options)) throw new Error("bearer auth middleware requires options for \"token\" or \"verifyToken\"");
45
45
  if (!options.realm) options.realm = "";
46
46
  if (options.prefix === void 0) options.prefix = PREFIX;
47
- const realm = options.realm?.replace(/"/g, "\\\"");
47
+ const realm = options.realm?.replace(/[\\"]/g, "\\$&");
48
48
  const prefix = options.prefix;
49
49
  const tokenRegexp = new RegExp(`^${TOKEN_STRINGS}$`);
50
50
  const wwwAuthenticatePrefix = prefix === "" ? "" : `${prefix} `;
@@ -52,6 +52,14 @@ const bearerAuth = (options) => {
52
52
  const wwwAuthenticateHeaderValue = typeof wwwAuthenticateHeader === "function" ? await wwwAuthenticateHeader(c) : wwwAuthenticateHeader;
53
53
  const headers = { "WWW-Authenticate": typeof wwwAuthenticateHeaderValue === "string" ? wwwAuthenticateHeaderValue : `${wwwAuthenticatePrefix}${Object.entries(wwwAuthenticateHeaderValue).map(([key, value]) => `${key}="${value}"`).join(",")}` };
54
54
  const responseMessage = typeof messageOption === "function" ? await messageOption(c) : messageOption;
55
+ if (responseMessage instanceof Response) {
56
+ const resHeaders = new Headers(responseMessage.headers);
57
+ if (!resHeaders.has("WWW-Authenticate")) resHeaders.set("WWW-Authenticate", headers["WWW-Authenticate"]);
58
+ throw new HTTPException(responseMessage.status, { res: new Response(responseMessage.body, {
59
+ status: responseMessage.status,
60
+ headers: resHeaders
61
+ }) });
62
+ }
55
63
  const res = typeof responseMessage === "string" ? new Response(responseMessage, {
56
64
  status,
57
65
  headers
@@ -44,23 +44,22 @@ const bodyLimit = (options) => {
44
44
  const hasTransferEncoding = c.req.raw.headers.has("transfer-encoding");
45
45
  if (c.req.raw.headers.has("content-length") && !hasTransferEncoding) return parseInt(c.req.raw.headers.get("content-length") || "0", 10) > maxSize ? onError(c) : next();
46
46
  let size = 0;
47
- const chunks = [];
47
+ let buffer = /* @__PURE__ */ new Uint8Array(0);
48
48
  const rawReader = c.req.raw.body.getReader();
49
49
  for (;;) {
50
50
  const { done, value } = await rawReader.read();
51
51
  if (done) break;
52
+ const offset = size;
52
53
  size += value.length;
53
54
  if (size > maxSize) return onError(c);
54
- chunks.push(value);
55
+ if (size > buffer.length) {
56
+ const grown = new Uint8Array(Math.min(maxSize, Math.max(size, buffer.length * 2)));
57
+ grown.set(buffer.subarray(0, offset));
58
+ buffer = grown;
59
+ }
60
+ buffer.set(value, offset);
55
61
  }
56
- const requestInit = {
57
- body: new ReadableStream({ start(controller) {
58
- for (const chunk of chunks) controller.enqueue(chunk);
59
- controller.close();
60
- } }),
61
- duplex: "half"
62
- };
63
- c.req.raw = new Request(c.req.raw, requestInit);
62
+ c.req.raw = new Request(c.req.raw, { body: buffer.subarray(0, size) });
64
63
  return next();
65
64
  };
66
65
  };
@@ -92,6 +92,10 @@ const every = (...middleware) => {
92
92
  c.req.routeIndex = currentRouteIndex;
93
93
  const res = await m(c, next);
94
94
  if (res === false) throw new Error("Unmet condition");
95
+ if (res === true) {
96
+ if (!c.finalized) await next();
97
+ return;
98
+ }
95
99
  return res;
96
100
  }]]))(c, next);
97
101
  };
@@ -58,14 +58,13 @@ const compress = (options) => {
58
58
  return async function compress(ctx, next) {
59
59
  await next();
60
60
  const contentLength = ctx.res.headers.get("Content-Length");
61
- if (ctx.res.status === 206 || ctx.res.headers.has("Content-Encoding") || ctx.res.headers.has("Transfer-Encoding") || ctx.req.method === "HEAD" || contentLength && Number(contentLength) < threshold || !shouldCompress(ctx.res) || !shouldTransform(ctx.res)) return;
61
+ if (ctx.res.status === 206 || ctx.res.headers.has("Content-Encoding") || ctx.res.headers.has("Transfer-Encoding") || contentLength && Number(contentLength) < threshold || !shouldCompress(ctx.res) || !shouldTransform(ctx.res)) return;
62
62
  const current = ctx.res.headers.get("Vary");
63
63
  if (current !== "*" && !(current && varyAcceptEncodingRegExp.test(current))) ctx.header("Vary", current ? `${current}, Accept-Encoding` : "Accept-Encoding");
64
64
  const accepted = ctx.req.header("Accept-Encoding");
65
65
  const encoding = selectEncoding(accepted, candidates);
66
66
  if (!encoding || !ctx.res.body) return;
67
- const stream = new CompressionStream(encoding);
68
- ctx.res = new Response(ctx.res.body.pipeThrough(stream), ctx.res);
67
+ ctx.res = ctx.req.method === "HEAD" ? new Response(null, ctx.res) : new Response(ctx.res.body.pipeThrough(new CompressionStream(encoding)), ctx.res);
69
68
  ctx.res.headers.delete("Content-Length");
70
69
  ctx.res.headers.set("Content-Encoding", encoding);
71
70
  const etag = ctx.res.headers.get("ETag");
@@ -8,7 +8,7 @@ const secFetchSiteValues = [
8
8
  ];
9
9
  const isSecFetchSite = (value) => secFetchSiteValues.includes(value);
10
10
  const isSafeMethodRe = /^(GET|HEAD|OPTIONS)$/;
11
- const isRequestedByFormElementRe = /^\b(application\/x-www-form-urlencoded|multipart\/form-data|text\/plain)\b/i;
11
+ const isCsrfContentTypeRe = /^\b(application\/x-www-form-urlencoded|multipart\/form-data|text\/(?:plain|ping))\b/i;
12
12
  /**
13
13
  * CSRF Protection Middleware for Hono.
14
14
  *
@@ -94,7 +94,7 @@ const csrf = (options) => {
94
94
  return await secFetchSiteHandler(secFetchSite, c);
95
95
  };
96
96
  return async function csrf(c, next) {
97
- if (!isSafeMethodRe.test(c.req.method) && isRequestedByFormElementRe.test(c.req.header("content-type") || "text/plain") && !await isAllowedSecFetchSite(c.req.header("sec-fetch-site"), c) && !await isAllowedOrigin(c.req.header("origin"), c)) {
97
+ if (!isSafeMethodRe.test(c.req.method) && isCsrfContentTypeRe.test(c.req.header("content-type") || "text/plain") && !await isAllowedSecFetchSite(c.req.header("sec-fetch-site"), c) && !await isAllowedOrigin(c.req.header("origin"), c)) {
98
98
  const res = new Response("Forbidden", { status: 403 });
99
99
  throw new HTTPException(403, { res });
100
100
  }
@@ -16,7 +16,8 @@ const RETAINED_304_HEADERS = [
16
16
  ];
17
17
  const stripWeak = (tag) => tag.replace(/^W\//, "");
18
18
  function etagMatches(etag, ifNoneMatch) {
19
- return ifNoneMatch != null && ifNoneMatch.split(",").some((t) => stripWeak(t.trim()) === stripWeak(etag));
19
+ const expected = stripWeak(etag);
20
+ return ifNoneMatch?.match(/"[^"]*"/g)?.some((tag) => tag === expected) ?? false;
20
21
  }
21
22
  function initializeGenerator(generator) {
22
23
  if (!generator) {
@@ -64,6 +65,7 @@ const etag = (options) => {
64
65
  etag = weak ? `W/"${hash}"` : `"${hash}"`;
65
66
  }
66
67
  if (ifNoneMatch === "*" || etagMatches(etag, ifNoneMatch)) {
68
+ await res.body?.cancel();
67
69
  c.res = new Response(null, {
68
70
  status: 304,
69
71
  statusText: "Not Modified",
@@ -109,8 +109,8 @@ const jwk = (options, init) => {
109
109
  };
110
110
  };
111
111
  function unauthorizedResponse(opts) {
112
- const realm = (opts.realm ?? opts.ctx.req.url).replace(/"/g, "\\\"");
113
- const errDescription = opts.errDescription.replace(/"/g, "\\\"");
112
+ const realm = (opts.realm ?? opts.ctx.req.url).replace(/[\\"]/g, "\\$&");
113
+ const errDescription = opts.errDescription.replace(/[\\"]/g, "\\$&");
114
114
  return new Response("Unauthorized", {
115
115
  status: 401,
116
116
  statusText: opts.statusText,
@@ -103,8 +103,8 @@ const jwt = (options) => {
103
103
  };
104
104
  };
105
105
  function unauthorizedResponse(opts) {
106
- const realm = (opts.realm ?? opts.ctx.req.url).replace(/"/g, "\\\"");
107
- const errDescription = opts.errDescription.replace(/"/g, "\\\"");
106
+ const realm = (opts.realm ?? opts.ctx.req.url).replace(/[\\"]/g, "\\$&");
107
+ const errDescription = opts.errDescription.replace(/[\\"]/g, "\\$&");
108
108
  return new Response("Unauthorized", {
109
109
  status: 401,
110
110
  statusText: opts.statusText,
@@ -1,7 +1,7 @@
1
+ import { basePath, matchedRoutes } from "../../helper/route/index.js";
1
2
  import "../../router.js";
2
3
  import { TrieRouter } from "../../router/trie-router/router.js";
3
4
  import "../../router/trie-router/index.js";
4
- import { basePath, matchedRoutes } from "../../helper/route/index.js";
5
5
  //#region src/middleware/method-not-allowed/index.ts
6
6
  /**
7
7
  * Method Not Allowed Middleware for Hono.
@@ -1,6 +1,13 @@
1
1
  import { parseBody } from "../../utils/body.js";
2
2
  //#region src/middleware/method-override/index.ts
3
3
  const DEFAULT_METHOD_FORM_NAME = "_method";
4
+ const isBodylessMethod = (method) => /^(?:GET|HEAD)$/i.test(method);
5
+ const withoutBodyHeaders = (headers) => {
6
+ const newHeaders = new Headers(headers);
7
+ newHeaders.delete("content-type");
8
+ newHeaders.delete("content-length");
9
+ return newHeaders;
10
+ };
4
11
  /**
5
12
  * Method Override Middleware for Hono.
6
13
  *
@@ -37,16 +44,21 @@ const methodOverride = (options) => async function methodOverride(c, next) {
37
44
  if (contentType?.startsWith("multipart/form-data")) {
38
45
  const method = (await clonedRequest.formData()).get(methodFormName);
39
46
  if (method) {
40
- const newForm = await newRequest.formData();
41
- newForm.delete(methodFormName);
42
- const newHeaders = new Headers(clonedRequest.headers);
43
- newHeaders.delete("content-type");
44
- newHeaders.delete("content-length");
45
- const request = new Request(c.req.url, {
46
- body: newForm,
47
+ const newHeaders = withoutBodyHeaders(clonedRequest.headers);
48
+ let request;
49
+ if (isBodylessMethod(method)) request = new Request(c.req.url, {
47
50
  headers: newHeaders,
48
51
  method
49
52
  });
53
+ else {
54
+ const newForm = await newRequest.formData();
55
+ newForm.delete(methodFormName);
56
+ request = new Request(c.req.url, {
57
+ body: newForm,
58
+ headers: newHeaders,
59
+ method
60
+ });
61
+ }
50
62
  return app.fetch(request, c.env, getExecutionCtx(c));
51
63
  }
52
64
  }
@@ -55,9 +67,14 @@ const methodOverride = (options) => async function methodOverride(c, next) {
55
67
  const method = params[methodFormName];
56
68
  if (method) {
57
69
  delete params[methodFormName];
58
- const newParams = new URLSearchParams(params);
59
- const request = new Request(newRequest, {
60
- body: newParams,
70
+ const newHeaders = new Headers(newRequest.headers);
71
+ newHeaders.delete("content-length");
72
+ const request = isBodylessMethod(method) ? new Request(c.req.url, {
73
+ headers: withoutBodyHeaders(newHeaders),
74
+ method
75
+ }) : new Request(newRequest, {
76
+ body: new URLSearchParams(params),
77
+ headers: newHeaders,
61
78
  method
62
79
  });
63
80
  return app.fetch(request, c.env, getExecutionCtx(c));
@@ -69,7 +86,10 @@ const methodOverride = (options) => async function methodOverride(c, next) {
69
86
  if (method) {
70
87
  const newHeaders = new Headers(c.req.raw.headers);
71
88
  newHeaders.delete(headerName);
72
- const request = new Request(c.req.raw, {
89
+ const request = isBodylessMethod(method) ? new Request(c.req.url, {
90
+ headers: withoutBodyHeaders(newHeaders),
91
+ method
92
+ }) : new Request(c.req.raw, {
73
93
  headers: newHeaders,
74
94
  method
75
95
  });
@@ -81,7 +101,10 @@ const methodOverride = (options) => async function methodOverride(c, next) {
81
101
  if (method) {
82
102
  const url = new URL(c.req.url);
83
103
  url.searchParams.delete(queryName);
84
- const requestInit = {
104
+ const requestInit = isBodylessMethod(method) ? {
105
+ headers: withoutBodyHeaders(c.req.raw.headers),
106
+ method
107
+ } : {
85
108
  body: c.req.raw.body,
86
109
  headers: c.req.raw.headers,
87
110
  method,
@@ -1,10 +1,9 @@
1
1
  import { routePath } from "../../helper/route/index.js";
2
+ import { createMountedRequest } from "../../utils/mount.js";
2
3
  //#region src/middleware/mount/index.ts
3
4
  const defaultReplaceRequest = (c) => {
4
- const pathPrefix = routePath(c).replace(/\/\*$/, "");
5
- const url = new URL(c.req.raw.url);
6
- url.pathname = c.req.path.slice(pathPrefix.length) || "/";
7
- return new Request(url, c.req.raw);
5
+ const path = routePath(c);
6
+ return createMountedRequest(c, path.replace(/\/?\*$/, ""), path);
8
7
  };
9
8
  const defaultGetOptions = (c) => {
10
9
  let executionContext = void 0;
@@ -21,6 +20,8 @@ const defaultGetOptions = (c) => {
21
20
  * @param {Function} applicationHandler - other Request Handler
22
21
  * @param {MountOptions} [options] - options of `mount()`
23
22
  * @returns {MiddlewareHandler} handler to register with `app.all()`
23
+ * @throws {Error} If the route ends with a wildcard inside a segment (e.g. `/assets*`), or automatic request rewriting encounters duplicate path parameter names or an optional regular expression parameter.
24
+ * @throws {HTTPException} With status 400 if automatic request rewriting cannot safely preserve the routed path.
24
25
  *
25
26
  * @example
26
27
  * ```ts
@@ -31,6 +31,7 @@ const prettyJSON = (options) => {
31
31
  } catch {
32
32
  return;
33
33
  }
34
+ await c.res.body?.cancel();
34
35
  c.res = new Response(JSON.stringify(obj, null, options?.space ?? 2), c.res);
35
36
  c.res.headers.delete("Content-Length");
36
37
  }
@@ -2,10 +2,10 @@
2
2
  /**
3
3
  * Request ID Middleware for Hono.
4
4
  *
5
- * @param {object} options - Options for Request ID middleware.
5
+ * @param {RequestIdOptions} [options] - Options for Request ID middleware.
6
6
  * @param {number} [options.limitLength=255] - The maximum length of request id.
7
- * @param {string} [options.headerName=X-Request-Id] - The header name used in request id.
8
- * @param {generator} [options.generator=() => crypto.randomUUID()] - The request id generation function.
7
+ * @param {string} [options.headerName='X-Request-Id'] - The header name used in request id.
8
+ * @param {(c: Context) => string} [options.generator=() => crypto.randomUUID()] - The request id generation function.
9
9
  *
10
10
  * @returns {MiddlewareHandler} The middleware handler function.
11
11
  *
@@ -28,7 +28,8 @@ const DEFAULT_OPTIONS = {
28
28
  xPermittedCrossDomainPolicies: true,
29
29
  xXssProtection: true,
30
30
  removePoweredBy: true,
31
- permissionsPolicy: {}
31
+ permissionsPolicy: {},
32
+ overwrite: true
32
33
  };
33
34
  const generateNonce = () => {
34
35
  const arrayBuffer = /* @__PURE__ */ new Uint8Array(16);
@@ -66,6 +67,7 @@ const NONCE = (ctx) => {
66
67
  * @param {overridableHeader} [customOptions.xXssProtection=true] - Settings for the X-XSS-Protection header.
67
68
  * @param {boolean} [customOptions.removePoweredBy=true] - Settings for remove X-Powered-By header.
68
69
  * @param {PermissionsPolicyOptions} [customOptions.permissionsPolicy] - Settings for the Permissions-Policy header.
70
+ * @param {boolean} [customOptions.overwrite=true] - Whether to replace a header that the response already has. Set `false` to keep a header that a handler set itself.
69
71
  * @returns {MiddlewareHandler} The middleware handler function.
70
72
  *
71
73
  * @example
@@ -97,7 +99,7 @@ const secureHeaders = (customOptions) => {
97
99
  return async function secureHeaders(ctx, next) {
98
100
  const headersToSetForReq = callbacks.length === 0 ? headersToSet : callbacks.reduce((acc, cb) => cb(ctx, acc), headersToSet);
99
101
  await next();
100
- setHeaders(ctx, headersToSetForReq);
102
+ setHeaders(ctx, headersToSetForReq, options.overwrite !== false);
101
103
  if (options?.removePoweredBy) ctx.res.headers.delete("X-Powered-By");
102
104
  };
103
105
  };
@@ -155,8 +157,9 @@ function getReportingEndpoints(reportingEndpoints = []) {
155
157
  function getReportToOptions(reportTo = []) {
156
158
  return reportTo.map((option) => JSON.stringify(option)).join(", ");
157
159
  }
158
- function setHeaders(ctx, headersToSet) {
160
+ function setHeaders(ctx, headersToSet, overwrite) {
159
161
  headersToSet.forEach(([header, value]) => {
162
+ if (!overwrite && ctx.res.headers.has(header)) return;
160
163
  ctx.res.headers.set(header, value);
161
164
  });
162
165
  }
@@ -1,4 +1,5 @@
1
1
  import { tryDecodeURI } from "../../utils/url.js";
2
+ import { parseAccept } from "../../utils/accept.js";
2
3
  import { COMPRESSIBLE_CONTENT_TYPE_REGEX } from "../../utils/compress.js";
3
4
  import { getMimeType } from "../../utils/mime.js";
4
5
  import { defaultJoin } from "./path.js";
@@ -19,11 +20,12 @@ const serveStatic = (options) => {
19
20
  const join = options.join ?? defaultJoin;
20
21
  return async (c, next) => {
21
22
  if (c.finalized) return next();
23
+ if (c.req.method !== "GET" && c.req.method !== "HEAD") return next();
22
24
  let filename;
23
25
  if (options.path) filename = options.path;
24
26
  else try {
25
- if (!options.allowPercentInPath && c.req.path.includes("%")) throw new Error();
26
27
  filename = tryDecodeURI(c.req.path);
28
+ if (c.req.path.includes("%") && (!options.allowPercentInPath || filename !== c.req.path.replace(/%25/g, "%"))) throw new Error();
27
29
  if (/(?:^|[\/\\])\.{1,2}(?:$|[\/\\])|[\/\\]{2,}|\\/.test(filename)) throw new Error();
28
30
  } catch {
29
31
  await options.onNotFound?.(c.req.path, c);
@@ -38,7 +40,7 @@ const serveStatic = (options) => {
38
40
  const mimeType = options.mimes && getMimeType(path, options.mimes) || getMimeType(path);
39
41
  c.header("Content-Type", mimeType || "application/octet-stream");
40
42
  if (options.precompressed && (!mimeType || COMPRESSIBLE_CONTENT_TYPE_REGEX.test(mimeType))) {
41
- const acceptEncodingSet = new Set(c.req.header("Accept-Encoding")?.split(",").map((encoding) => encoding.trim()));
43
+ const acceptEncodingSet = new Set(parseAccept(c.req.header("Accept-Encoding") ?? "").filter((encoding) => encoding.q > 0).map((encoding) => encoding.type));
42
44
  for (const encoding of ENCODINGS_ORDERED_KEYS) {
43
45
  if (!acceptEncodingSet.has(encoding)) continue;
44
46
  const compressedContent = await getContent(path + ENCODINGS[encoding], c);
@@ -74,6 +74,7 @@ const timing = (config) => {
74
74
  }
75
75
  };
76
76
  };
77
+ const quote = (s) => `"${s.replace(/[\\"]/g, "\\$&")}"`;
77
78
  /**
78
79
  * Set a metric for the timing middleware.
79
80
  *
@@ -96,11 +97,11 @@ const setMetric = (c, name, valueDescription, description, precision) => {
96
97
  return;
97
98
  }
98
99
  if (typeof valueDescription === "number") {
99
- const dur = valueDescription.toFixed(precision || 1);
100
- const metric = description ? `${name};dur=${dur};desc="${description}"` : `${name};dur=${dur}`;
100
+ const dur = valueDescription.toFixed(precision ?? 1);
101
+ const metric = description ? `${name};dur=${dur};desc=${quote(description)}` : `${name};dur=${dur}`;
101
102
  metrics.headers.push(metric);
102
103
  } else {
103
- const metric = valueDescription ? `${name};desc="${valueDescription}"` : `${name}`;
104
+ const metric = valueDescription ? `${name};desc=${quote(valueDescription)}` : `${name}`;
104
105
  metrics.headers.push(metric);
105
106
  }
106
107
  };