@songtonyli/dsh-cli 0.1.58 → 0.1.59

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 (135) hide show
  1. package/README.md +1 -1
  2. package/bin/dsh.mjs +1 -1
  3. package/node_modules/@deepseek-ai/dsh-agent-preset/skills/cordis-composition-reference/references/packages.md +1 -0
  4. package/node_modules/@deepseek-ai/dsh-api-session-controller/lib/client.js +1 -0
  5. package/node_modules/@deepseek-ai/dsh-client-ui-primitives/package.json +1 -1
  6. package/node_modules/@deepseek-ai/dsh-client-ui-sidebar/lib/client.js +1 -1
  7. package/node_modules/@deepseek-ai/dsh-client-ui-slots/package.json +2 -2
  8. package/node_modules/@deepseek-ai/dsh-sandbox/lib/index.js +59 -4
  9. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.i18n.yaml +73 -0
  10. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.md +166 -0
  11. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/README.zh.md +166 -0
  12. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/lib/exec-shim.js +227 -0
  13. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/lib/index.js +704 -0
  14. package/node_modules/@deepseek-ai/dsh-sandbox-apple-container/package.json +62 -0
  15. package/node_modules/@deepseek-ai/dsh-sandbox-policy/README.i18n.yaml +2 -2
  16. package/node_modules/@deepseek-ai/dsh-sandbox-policy/README.md +1 -1
  17. package/node_modules/@deepseek-ai/dsh-sandbox-policy/README.zh.md +1 -1
  18. package/node_modules/@deepseek-ai/dsh-sandbox-policy/lib/index.js +23 -0
  19. package/node_modules/@deepseek-ai/dsh-session/lib/index.js +1 -0
  20. package/node_modules/@deepseek-ai/dsh-session/lib/types/known-event-types.js +1 -0
  21. package/node_modules/@deepseek-ai/dsh-session-persistence-jsonl/lib/worker.cjs +1 -0
  22. package/node_modules/@deepseek-ai/dsh-system-prompt/lib/index.js +1 -0
  23. package/node_modules/@deepseek-ai/dsh-tool-cordis/lib/types/api-catalog.js +22 -0
  24. package/node_modules/@deepseek-ai/dsh-tool-fs/README.i18n.yaml +2 -2
  25. package/node_modules/@deepseek-ai/dsh-tool-fs/README.md +1 -1
  26. package/node_modules/@deepseek-ai/dsh-tool-fs/README.zh.md +1 -1
  27. package/node_modules/@deepseek-ai/dsh-tool-fs/lib/index.js +24 -0
  28. package/node_modules/@deepseek-ai/dsh-tool-fs-search/README.i18n.yaml +4 -4
  29. package/node_modules/@deepseek-ai/dsh-tool-fs-search/README.md +2 -2
  30. package/node_modules/@deepseek-ai/dsh-tool-fs-search/README.zh.md +2 -2
  31. package/node_modules/@deepseek-ai/dsh-tool-fs-search/lib/index.js +28 -3
  32. package/node_modules/@deepseek-ai/dsh-tool-fs-search/package.json +7 -2
  33. package/node_modules/@deepseek-ai/dsh-tool-str-replace-editor/README.i18n.yaml +2 -2
  34. package/node_modules/@deepseek-ai/dsh-tool-str-replace-editor/README.md +1 -1
  35. package/node_modules/@deepseek-ai/dsh-tool-str-replace-editor/README.zh.md +1 -1
  36. package/node_modules/@deepseek-ai/dsh-tool-str-replace-editor/lib/index.js +14 -6
  37. package/node_modules/@deepseek-ai/dsh-tui-app/cordis.patch.yml +20 -0
  38. package/node_modules/@deepseek-ai/dsh-tui-app/package.json +1 -0
  39. package/node_modules/@deepseek-ai/libreoffice-kit/README.md +20 -5
  40. package/node_modules/@deepseek-ai/libreoffice-kit/README.zh.md +21 -6
  41. package/node_modules/@deepseek-ai/libreoffice-kit/lib/cli.js +499 -253
  42. package/node_modules/@deepseek-ai/libreoffice-kit/lib/font-snapshot-worker.js +37 -26
  43. package/node_modules/@deepseek-ai/libreoffice-kit/lib/index.js +498 -252
  44. package/node_modules/@deepseek-ai/libreoffice-kit/lib/worker.js +39 -13
  45. package/node_modules/@deepseek-ai/libreoffice-kit/package.json +5 -3
  46. package/node_modules/@earendil-works/pi-ai/README.md +4 -3
  47. package/node_modules/@earendil-works/pi-ai/dist/api/anthropic-messages.js +117 -18
  48. package/node_modules/@earendil-works/pi-ai/dist/api/bedrock-converse-stream.js +1 -0
  49. package/node_modules/@earendil-works/pi-ai/dist/api/constrained-sampling.js +19 -8
  50. package/node_modules/@earendil-works/pi-ai/dist/api/mistral-conversations.js +1 -0
  51. package/node_modules/@earendil-works/pi-ai/dist/api/openai-completions.js +1 -0
  52. package/node_modules/@earendil-works/pi-ai/dist/api/openai-responses-shared.js +1 -0
  53. package/node_modules/@earendil-works/pi-ai/dist/api/pi-messages.js +2 -0
  54. package/node_modules/@earendil-works/pi-ai/dist/env-api-keys.js +5 -0
  55. package/node_modules/@earendil-works/pi-ai/dist/providers/anthropic.js +24 -2
  56. package/node_modules/@earendil-works/pi-ai/dist/providers/data/.manifest.json +1 -1
  57. package/node_modules/@earendil-works/pi-ai/dist/providers/data/amazon-bedrock.json +1 -1
  58. package/node_modules/@earendil-works/pi-ai/dist/providers/data/azure-openai-responses.json +1 -1
  59. package/node_modules/@earendil-works/pi-ai/dist/providers/data/baseten.json +1 -1
  60. package/node_modules/@earendil-works/pi-ai/dist/providers/data/cerebras.json +1 -1
  61. package/node_modules/@earendil-works/pi-ai/dist/providers/data/github-copilot.json +1 -1
  62. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openai.json +1 -1
  63. package/node_modules/@earendil-works/pi-ai/dist/providers/data/opencode.json +1 -1
  64. package/node_modules/@earendil-works/pi-ai/dist/providers/data/openrouter.json +1 -1
  65. package/node_modules/@earendil-works/pi-ai/dist/providers/data/radius.json +1 -1
  66. package/node_modules/@earendil-works/pi-ai/dist/providers/data/vercel-ai-gateway.json +1 -1
  67. package/node_modules/@earendil-works/pi-ai/dist/utils/overflow.js +2 -1
  68. package/node_modules/@earendil-works/pi-ai/dist/utils/provider-retry.js +3 -2
  69. package/node_modules/@earendil-works/pi-ai/package.json +6 -2
  70. package/node_modules/@earendil-works/pi-telemetry/package.json +1 -1
  71. package/node_modules/@shikijs/core/dist/index.mjs +15 -12
  72. package/node_modules/@shikijs/core/package.json +4 -4
  73. package/node_modules/@shikijs/engine-javascript/dist/engine-compile.mjs +2 -4
  74. package/node_modules/@shikijs/engine-javascript/dist/engine-raw.mjs +2 -4
  75. package/node_modules/@shikijs/engine-javascript/dist/index.mjs +1 -1
  76. package/node_modules/@shikijs/engine-javascript/dist/string-TLTPtCPs.mjs +115 -0
  77. package/node_modules/@shikijs/engine-javascript/package.json +3 -3
  78. package/node_modules/@shikijs/engine-oniguruma/package.json +3 -3
  79. package/node_modules/@shikijs/langs/dist/ada.mjs +1 -1
  80. package/node_modules/@shikijs/langs/dist/ahk.mjs +1 -1
  81. package/node_modules/@shikijs/langs/dist/beancount.mjs +1 -1
  82. package/node_modules/@shikijs/langs/dist/coq.mjs +1 -1
  83. package/node_modules/@shikijs/langs/dist/csharp.mjs +1 -1
  84. package/node_modules/@shikijs/langs/dist/css.mjs +1 -1
  85. package/node_modules/@shikijs/langs/dist/dart.mjs +1 -1
  86. package/node_modules/@shikijs/langs/dist/dotenv.mjs +1 -1
  87. package/node_modules/@shikijs/langs/dist/emacs-lisp.mjs +1 -1
  88. package/node_modules/@shikijs/langs/dist/gn.mjs +1 -1
  89. package/node_modules/@shikijs/langs/dist/handlebars.mjs +1 -1
  90. package/node_modules/@shikijs/langs/dist/julia.mjs +1 -1
  91. package/node_modules/@shikijs/langs/dist/latex.mjs +1 -1
  92. package/node_modules/@shikijs/langs/dist/luau.mjs +1 -1
  93. package/node_modules/@shikijs/langs/dist/marko.mjs +1 -1
  94. package/node_modules/@shikijs/langs/dist/moonbit.mjs +1 -1
  95. package/node_modules/@shikijs/langs/dist/nextflow-groovy.mjs +1 -1
  96. package/node_modules/@shikijs/langs/dist/nextflow.mjs +1 -1
  97. package/node_modules/@shikijs/langs/dist/nushell.mjs +1 -1
  98. package/node_modules/@shikijs/langs/dist/php.mjs +1 -1
  99. package/node_modules/@shikijs/langs/dist/powershell.mjs +1 -1
  100. package/node_modules/@shikijs/langs/dist/ruby.mjs +1 -1
  101. package/node_modules/@shikijs/langs/dist/rust.mjs +1 -1
  102. package/node_modules/@shikijs/langs/dist/sql.mjs +1 -1
  103. package/node_modules/@shikijs/langs/dist/svelte.mjs +1 -1
  104. package/node_modules/@shikijs/langs/dist/twig.mjs +3 -3
  105. package/node_modules/@shikijs/langs/dist/typespec.mjs +1 -1
  106. package/node_modules/@shikijs/langs/package.json +3 -3
  107. package/node_modules/@shikijs/primitive/dist/index.mjs +2 -1
  108. package/node_modules/@shikijs/primitive/package.json +3 -3
  109. package/node_modules/@shikijs/themes/dist/monokai.mjs +1 -1
  110. package/node_modules/@shikijs/themes/dist/one-dark-pro.mjs +1 -1
  111. package/node_modules/@shikijs/themes/dist/red.mjs +1 -1
  112. package/node_modules/@shikijs/themes/dist/solarized-dark.mjs +1 -1
  113. package/node_modules/@shikijs/themes/dist/solarized-light.mjs +1 -1
  114. package/node_modules/@shikijs/themes/package.json +3 -3
  115. package/node_modules/@shikijs/types/package.json +1 -1
  116. package/node_modules/@smithy/core/dist-cjs/submodules/client/index.js +33 -11
  117. package/node_modules/@smithy/core/dist-cjs/submodules/schema/index.js +3 -0
  118. package/node_modules/@smithy/core/dist-es/submodules/client/smithy-client/exceptions.js +33 -11
  119. package/node_modules/@smithy/core/dist-es/submodules/schema/TypeRegistry.js +3 -0
  120. package/node_modules/@smithy/core/package.json +1 -1
  121. package/node_modules/node-addon-native-custom-loader/lib/index.js +23 -10
  122. package/node_modules/node-addon-native-custom-loader/package.json +6 -1
  123. package/node_modules/node-addon-require-builtin/package.json +7 -2
  124. package/node_modules/powershell-utils/index.js +40 -19
  125. package/node_modules/powershell-utils/package.json +1 -1
  126. package/node_modules/powershell-utils/readme.md +69 -13
  127. package/node_modules/shiki/package.json +10 -10
  128. package/node_modules/wsl-utils/index.js +18 -37
  129. package/node_modules/wsl-utils/package.json +2 -2
  130. package/package.json +33 -29
  131. package/node_modules/@shikijs/engine-javascript/dist/scanner-DX8LRFGE.mjs +0 -77
  132. package/node_modules/open/node_modules/powershell-utils/index.js +0 -79
  133. package/node_modules/open/node_modules/powershell-utils/license +0 -9
  134. package/node_modules/open/node_modules/powershell-utils/package.json +0 -47
  135. package/node_modules/open/node_modules/powershell-utils/readme.md +0 -209
@@ -25,7 +25,7 @@
25
25
  * - DS4: "Prompt has X tokens, but the configured context size is Y tokens"
26
26
  * - Cerebras: "400/413 status code (no body)"
27
27
  * - Mistral: "Prompt contains X tokens ... too large for model with Y maximum context length"
28
- * - z.ai: `{"code":"1261","message":"Prompt too long"}` or silent overflow via usage.input > contextWindow
28
+ * - z.ai: `{"code":"1261","message":"Prompt too long"}`, `{"code":"1261","message":"Prompt exceeds max length"}` (CN endpoint), or silent overflow via usage.input > contextWindow
29
29
  * - Xiaomi MiMo: Truncates input to fill contextWindow exactly, then returns finish_reason "length"
30
30
  * with output=0 (no room left to generate). Detected via stopReason "length" + zero output +
31
31
  * input filling the context window.
@@ -34,6 +34,7 @@
34
34
  */
35
35
  const OVERFLOW_PATTERNS = [
36
36
  /prompt (?:is )?too long/i, // Anthropic and z.ai token overflow
37
+ /prompt exceeds max length/i, // z.ai CN endpoint token overflow
37
38
  /request_too_large/i, // Anthropic request byte-size overflow (HTTP 413)
38
39
  /input is too long for requested model/i, // Amazon Bedrock
39
40
  /exceeds the context window/i, // OpenAI (Completions & Responses API)
@@ -30,14 +30,15 @@ function getRetryDelayMs(error, retryIndex, maxRetryDelayMs) {
30
30
  const retryAfterMs = error.headers?.get("retry-after-ms");
31
31
  if (retryAfterMs) {
32
32
  const value = Number.parseFloat(retryAfterMs);
33
- if (!Number.isNaN(value))
33
+ if (Number.isFinite(value))
34
34
  return validateServerRetryDelayMs(value, maxRetryDelayMs, error.message);
35
35
  }
36
36
  const retryAfter = error.headers?.get("retry-after");
37
37
  if (retryAfter) {
38
38
  const seconds = Number.parseFloat(retryAfter);
39
39
  const delayMs = Number.isNaN(seconds) ? Date.parse(retryAfter) - Date.now() : seconds * 1000;
40
- return validateServerRetryDelayMs(delayMs, maxRetryDelayMs, error.message);
40
+ if (Number.isFinite(delayMs))
41
+ return validateServerRetryDelayMs(delayMs, maxRetryDelayMs, error.message);
41
42
  }
42
43
  const exponentialDelay = Math.min(0.5 * 2 ** retryIndex, 8) * 1000;
43
44
  return exponentialDelay * (1 - Math.random() * 0.25);
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@earendil-works/pi-ai",
3
- "version": "0.99.1",
3
+ "version": "0.99.2",
4
4
  "description": "Unified LLM API with automatic model discovery and provider configuration",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -15,6 +15,10 @@
15
15
  "types": "./dist/index.d.ts",
16
16
  "import": "./dist/index.js"
17
17
  },
18
+ "./models": {
19
+ "types": "./dist/models.d.ts",
20
+ "import": "./dist/models.js"
21
+ },
18
22
  "./compat": {
19
23
  "types": "./dist/compat.d.ts",
20
24
  "import": "./dist/compat.js"
@@ -54,7 +58,7 @@
54
58
  "dependencies": {
55
59
  "@anthropic-ai/sdk": "0.124.0",
56
60
  "@aws-sdk/client-bedrock-runtime": "3.1127.0",
57
- "@earendil-works/pi-telemetry": "^0.99.1",
61
+ "@earendil-works/pi-telemetry": "^0.99.2",
58
62
  "@google/genai": "2.21.0",
59
63
  "@smithy/node-http-handler": "4.12.1",
60
64
  "http-proxy-agent": "9.1.0",
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@earendil-works/pi-telemetry",
3
- "version": "0.99.1",
3
+ "version": "0.99.2",
4
4
  "description": "Vendor-neutral telemetry contracts and typed schema utilities for pi",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -177,16 +177,17 @@ function flatTokenVariants(merged, variantsOrder, cssVariablePrefix, defaultColo
177
177
  styles.forEach((cur, idx) => {
178
178
  for (const key of styleKeys) {
179
179
  const value = cur[key] || "inherit";
180
- if (idx === 0 && defaultColor && COLOR_KEYS.includes(key)) if (defaultColor === "light-dark()" && styles.length > 1) {
181
- const lightIndex = variantsOrder.findIndex((t) => t === "light");
182
- const darkIndex = variantsOrder.findIndex((t) => t === "dark");
183
- if (lightIndex === -1 || darkIndex === -1) throw new ShikiError$1("When using `defaultColor: \"light-dark()\"`, you must provide both `light` and `dark` themes");
184
- const lightValue = styles[lightIndex][key] || "inherit";
185
- const darkValue = styles[darkIndex][key] || "inherit";
186
- mergedStyles[key] = `light-dark(${lightValue}, ${darkValue})`;
187
- if (colorsRendering === "css-vars") mergedStyles[varKey(idx, key)] = value;
188
- } else mergedStyles[key] = value;
189
- else if (colorsRendering === "css-vars") mergedStyles[varKey(idx, key)] = value;
180
+ if (idx === 0 && defaultColor && COLOR_KEYS.includes(key)) {
181
+ if (defaultColor === "light-dark()" && styles.length > 1) {
182
+ const lightIndex = variantsOrder.findIndex((t) => t === "light");
183
+ const darkIndex = variantsOrder.findIndex((t) => t === "dark");
184
+ if (lightIndex === -1 || darkIndex === -1) throw new ShikiError$1("When using `defaultColor: \"light-dark()\"`, you must provide both `light` and `dark` themes");
185
+ const lightValue = styles[lightIndex][key] || "inherit";
186
+ const darkValue = styles[darkIndex][key] || "inherit";
187
+ mergedStyles[key] = `light-dark(${lightValue}, ${darkValue})`;
188
+ if (colorsRendering === "css-vars") mergedStyles[varKey(idx, key)] = value;
189
+ } else mergedStyles[key] = value;
190
+ } else if (colorsRendering === "css-vars") mergedStyles[varKey(idx, key)] = value;
190
191
  }
191
192
  });
192
193
  token.htmlStyle = mergedStyles;
@@ -829,8 +830,10 @@ function tokensToHast(tokens, options, transformerContext, grammarState = getLas
829
830
  };
830
831
  const { structure = "classic", tabindex = "0" } = options;
831
832
  const properties = { class: `shiki ${options.themeName || ""}` };
832
- if (options.rootStyle !== false) if (options.rootStyle != null) properties.style = options.rootStyle;
833
- else properties.style = `background-color:${options.bg};color:${options.fg}`;
833
+ if (options.rootStyle !== false) {
834
+ if (options.rootStyle != null) properties.style = options.rootStyle;
835
+ else properties.style = `background-color:${options.bg};color:${options.fg}`;
836
+ }
834
837
  if (tabindex !== false && tabindex != null) properties.tabindex = tabindex.toString();
835
838
  for (const [key, value] of Object.entries(options.meta || {})) if (!key.startsWith("_")) properties[key] = value;
836
839
  let preNode = {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shikijs/core",
3
3
  "type": "module",
4
- "version": "4.4.3",
4
+ "version": "4.5.0",
5
5
  "description": "Core of Shiki",
6
6
  "author": "Pine Wu <octref@gmail.com>; Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -46,10 +46,10 @@
46
46
  "node": ">=20"
47
47
  },
48
48
  "dependencies": {
49
+ "@shikijs/primitive": "4.5.0",
50
+ "@shikijs/types": "4.5.0",
49
51
  "@shikijs/vscode-textmate": "^10.0.2",
50
52
  "@types/hast": "^3.0.5",
51
- "hast-util-to-html": "^9.0.5",
52
- "@shikijs/primitive": "4.4.3",
53
- "@shikijs/types": "4.4.3"
53
+ "hast-util-to-html": "^9.0.5"
54
54
  }
55
55
  }
@@ -1,4 +1,4 @@
1
- import { t as JavaScriptScanner } from "./scanner-DX8LRFGE.mjs";
1
+ import { n as JavaScriptScanner, t as createJavaScriptEngineString } from "./string-TLTPtCPs.mjs";
2
2
  import { toRegExp } from "oniguruma-to-es";
3
3
  //#region src/engine-compile.ts
4
4
  /**
@@ -38,9 +38,7 @@ function createJavaScriptRegexEngine(options = {}) {
38
38
  createScanner(patterns) {
39
39
  return new JavaScriptScanner(patterns, _options);
40
40
  },
41
- createString(s) {
42
- return { content: s };
43
- }
41
+ createString: createJavaScriptEngineString
44
42
  };
45
43
  }
46
44
  //#endregion
@@ -1,4 +1,4 @@
1
- import { t as JavaScriptScanner } from "./scanner-DX8LRFGE.mjs";
1
+ import { n as JavaScriptScanner, t as createJavaScriptEngineString } from "./string-TLTPtCPs.mjs";
2
2
  //#region src/engine-raw.ts
3
3
  /**
4
4
  * Raw JavaScript regex engine that only supports precompiled grammars.
@@ -18,9 +18,7 @@ function createJavaScriptRawEngine() {
18
18
  createScanner(patterns) {
19
19
  return new JavaScriptScanner(patterns, options);
20
20
  },
21
- createString(s) {
22
- return { content: s };
23
- }
21
+ createString: createJavaScriptEngineString
24
22
  };
25
23
  }
26
24
  //#endregion
@@ -1,4 +1,4 @@
1
- import { t as JavaScriptScanner } from "./scanner-DX8LRFGE.mjs";
1
+ import { n as JavaScriptScanner } from "./string-TLTPtCPs.mjs";
2
2
  import { createJavaScriptRegexEngine, defaultJavaScriptRegexConstructor } from "./engine-compile.mjs";
3
3
  import { createJavaScriptRawEngine } from "./engine-raw.mjs";
4
4
  export { JavaScriptScanner, createJavaScriptRawEngine, createJavaScriptRegexEngine, defaultJavaScriptRegexConstructor };
@@ -0,0 +1,115 @@
1
+ //#region src/scanner.ts
2
+ const MAX = 4294967295;
3
+ function isSearchCacheable(regexp) {
4
+ return !regexp.sticky && !regexp.rawOptions?.strategy;
5
+ }
6
+ function toResult(index, indices) {
7
+ return {
8
+ index,
9
+ captureIndices: indices.map((indice) => {
10
+ if (indice == null) return {
11
+ start: MAX,
12
+ end: MAX,
13
+ length: 0
14
+ };
15
+ return {
16
+ start: indice[0],
17
+ end: indice[1],
18
+ length: indice[1] - indice[0]
19
+ };
20
+ })
21
+ };
22
+ }
23
+ var JavaScriptScanner = class {
24
+ patterns;
25
+ options;
26
+ regexps;
27
+ /**
28
+ * Last search of each regexp on the current string, reused the way `vscode-oniguruma` does.
29
+ * `null` for regexps whose searches can't be reused.
30
+ */
31
+ lastSearches;
32
+ constructor(patterns, options = {}) {
33
+ this.patterns = patterns;
34
+ this.options = options;
35
+ const { forgiving = false, cache, regexConstructor } = options;
36
+ if (!regexConstructor) throw new Error("Option `regexConstructor` is not provided");
37
+ this.regexps = patterns.map((p) => {
38
+ if (typeof p !== "string") return p;
39
+ const cached = cache?.get(p);
40
+ if (cached) {
41
+ if (cached instanceof RegExp) return cached;
42
+ if (forgiving) return null;
43
+ throw cached;
44
+ }
45
+ try {
46
+ const regex = regexConstructor(p);
47
+ cache?.set(p, regex);
48
+ return regex;
49
+ } catch (e) {
50
+ cache?.set(p, e);
51
+ if (forgiving) return null;
52
+ throw e;
53
+ }
54
+ });
55
+ this.lastSearches = this.regexps.map((regexp) => regexp && isSearchCacheable(regexp) ? {
56
+ strId: 0,
57
+ searchedFrom: 0,
58
+ matchIndex: -1,
59
+ indices: null
60
+ } : null);
61
+ }
62
+ findNextMatchSync(string, startPosition, _options) {
63
+ const str = typeof string === "string" ? string : string.content;
64
+ const strId = typeof string === "string" ? 0 : string.id || 0;
65
+ let bestIndex = -1;
66
+ let bestMatchIndex = 0;
67
+ let bestIndices = null;
68
+ for (let i = 0; i < this.regexps.length; i++) {
69
+ const regexp = this.regexps[i];
70
+ if (!regexp) continue;
71
+ try {
72
+ const last = strId ? this.lastSearches[i] : null;
73
+ let matchIndex;
74
+ let indices;
75
+ if (last && last.strId === strId && last.searchedFrom <= startPosition && (last.matchIndex === -1 || last.matchIndex >= startPosition)) {
76
+ matchIndex = last.matchIndex;
77
+ indices = last.indices;
78
+ } else {
79
+ regexp.lastIndex = startPosition;
80
+ const match = regexp.exec(str);
81
+ matchIndex = match ? match.index : -1;
82
+ indices = match ? match.indices : null;
83
+ if (last) {
84
+ last.strId = strId;
85
+ last.searchedFrom = startPosition;
86
+ last.matchIndex = matchIndex;
87
+ last.indices = indices;
88
+ }
89
+ }
90
+ if (matchIndex === -1) continue;
91
+ if (matchIndex === startPosition) return toResult(i, indices);
92
+ if (bestIndex === -1 || matchIndex < bestMatchIndex) {
93
+ bestIndex = i;
94
+ bestMatchIndex = matchIndex;
95
+ bestIndices = indices;
96
+ }
97
+ } catch (e) {
98
+ if (this.options.forgiving) continue;
99
+ throw e;
100
+ }
101
+ }
102
+ return bestIndex === -1 ? null : toResult(bestIndex, bestIndices);
103
+ }
104
+ };
105
+ //#endregion
106
+ //#region src/string.ts
107
+ let lastStringId = 0;
108
+ function createJavaScriptEngineString(content) {
109
+ return {
110
+ content,
111
+ id: ++lastStringId
112
+ };
113
+ }
114
+ //#endregion
115
+ export { JavaScriptScanner as n, createJavaScriptEngineString as t };
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shikijs/engine-javascript",
3
3
  "type": "module",
4
- "version": "4.4.3",
4
+ "version": "4.5.0",
5
5
  "description": "Engine for Shiki using JavaScript's native RegExp",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -31,8 +31,8 @@
31
31
  "node": ">=20"
32
32
  },
33
33
  "dependencies": {
34
+ "@shikijs/types": "4.5.0",
34
35
  "@shikijs/vscode-textmate": "^10.0.2",
35
- "oniguruma-to-es": "^4.3.6",
36
- "@shikijs/types": "4.4.3"
36
+ "oniguruma-to-es": "^4.3.6"
37
37
  }
38
38
  }
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@shikijs/engine-oniguruma",
3
3
  "type": "module",
4
- "version": "4.4.3",
4
+ "version": "4.5.0",
5
5
  "description": "Engine for Shiki using Oniguruma RegExp engine in WebAssembly",
6
6
  "author": "Anthony Fu <anthonyfu117@hotmail.com>",
7
7
  "license": "MIT",
@@ -32,8 +32,8 @@
32
32
  "node": ">=20"
33
33
  },
34
34
  "dependencies": {
35
- "@shikijs/vscode-textmate": "^10.0.2",
36
- "@shikijs/types": "4.4.3"
35
+ "@shikijs/types": "4.5.0",
36
+ "@shikijs/vscode-textmate": "^10.0.2"
37
37
  },
38
38
  "devDependencies": {
39
39
  "vscode-oniguruma": "1.7.0"