@alauda/doom 2.11.2 → 2.11.4

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.
@@ -138,6 +138,8 @@ export interface TranslateDocumentOptions {
138
138
  maxAssemblyRounds?: number;
139
139
  contextTail?: number;
140
140
  repairer?: SegmentRepairer;
141
+ /** Maximum number of uncached segments worked on at once. */
142
+ segmentConcurrency?: number;
141
143
  /**
142
144
  * The translation already on disk, for reusing the segments that did not
143
145
  * change. Absent on a first translation, and when `--force` is given.
@@ -159,6 +161,14 @@ export interface TranslateDocumentOptions {
159
161
  */
160
162
  export declare const maskFindingToTranslationFinding: (finding: MaskIntegrityError["findings"][number]) => TranslationFinding;
161
163
  export declare const translateDocument: (options: TranslateDocumentOptions) => Promise<TranslateDocumentResult>;
164
+ /**
165
+ * Run independent segment jobs with a small worker pool.
166
+ *
167
+ * A rejected job stops new work from being scheduled but lets already-started
168
+ * jobs settle. This preserves the document-level error boundary while avoiding
169
+ * dangling promises when one model call fails.
170
+ */
171
+ export declare const runWithConcurrency: <T>(items: readonly T[], concurrency: number, worker: (item: T, index: number) => Promise<unknown>) => Promise<void>;
162
172
  /**
163
173
  * Whether a segment has any text a reviewer could judge.
164
174
  *
@@ -55,7 +55,7 @@ export const maskFindingToTranslationFinding = (finding) => ({
55
55
  placeholder: finding.placeholder,
56
56
  });
57
57
  export const translateDocument = async (options) => {
58
- const { tree, maskedSource, maskEntries, processor, compose, targetPath, sourceLabel, sourceLanguage, targetLanguage, translator, checker, segmentJudge, documentJudge, terms, segmentCap, segmentHardCap, segmentFloor, maxSegmentAttempts = DEFAULT_MAX_SEGMENT_ATTEMPTS, maxAssemblyRounds = DEFAULT_MAX_ASSEMBLY_ROUNDS, contextTail, repairer, previous, onProgress, } = options;
58
+ const { tree, maskedSource, maskEntries, processor, compose, targetPath, sourceLabel, sourceLanguage, targetLanguage, translator, checker, segmentJudge, documentJudge, terms, segmentCap, segmentHardCap, segmentFloor, maxSegmentAttempts = DEFAULT_MAX_SEGMENT_ATTEMPTS, maxAssemblyRounds = DEFAULT_MAX_ASSEMBLY_ROUNDS, contextTail, repairer, segmentConcurrency = 1, previous, onProgress, } = options;
59
59
  let plan;
60
60
  try {
61
61
  plan = planSegments({
@@ -262,7 +262,8 @@ export const translateDocument = async (options) => {
262
262
  }
263
263
  return true;
264
264
  };
265
- // ------------------------------------------------ every segment, in order
265
+ // ------------------------------------------------ cached segments first
266
+ const pending = [];
266
267
  for (const segment of plan.segments) {
267
268
  const reused = reuse.get(segment.index);
268
269
  if (reused != null) {
@@ -270,8 +271,10 @@ export const translateDocument = async (options) => {
270
271
  outcomes[segment.index].status = 'cached';
271
272
  continue;
272
273
  }
273
- await workOn(segment);
274
+ pending.push(segment);
274
275
  }
276
+ // ------------------------------------------------ uncached segments, bounded
277
+ await runWithConcurrency(pending, segmentConcurrency, (segment) => workOn(segment));
275
278
  if (reuse.size > 0) {
276
279
  onProgress?.(`${sourceLabel}: reused ${reuse.size} of ${plan.segments.length} segment(s) from the previous translation`);
277
280
  }
@@ -369,11 +372,51 @@ export const translateDocument = async (options) => {
369
372
  };
370
373
  }
371
374
  assemblyRounds++;
375
+ const rerouted = [];
372
376
  for (const [index, sentBack] of routed) {
373
377
  const segment = plan.segments[index];
374
378
  onProgress?.(`${sourceLabel} [segment ${index + 1}/${plan.segments.length}${describe(segment)}] sent back by the assembled document: ${summarise(sentBack)}${reasons(sentBack)}`);
375
- await workOn(segment, sentBack);
379
+ rerouted.push({ segment, findings: sentBack });
376
380
  }
381
+ await runWithConcurrency(rerouted, segmentConcurrency, ({ segment, findings }) => workOn(segment, findings));
382
+ }
383
+ };
384
+ /**
385
+ * Run independent segment jobs with a small worker pool.
386
+ *
387
+ * A rejected job stops new work from being scheduled but lets already-started
388
+ * jobs settle. This preserves the document-level error boundary while avoiding
389
+ * dangling promises when one model call fails.
390
+ */
391
+ export const runWithConcurrency = async (items, concurrency, worker) => {
392
+ if (!Number.isInteger(concurrency) || concurrency < 1) {
393
+ throw new Error(`segment concurrency must be a positive integer, got ${concurrency}`);
394
+ }
395
+ let next = 0;
396
+ let stopped = false;
397
+ const errors = [];
398
+ const runWorker = async () => {
399
+ while (!stopped) {
400
+ const index = next++;
401
+ const item = items[index];
402
+ if (item === undefined) {
403
+ return;
404
+ }
405
+ try {
406
+ await worker(item, index);
407
+ }
408
+ catch (error) {
409
+ if (errors.length === 0) {
410
+ errors.push(error);
411
+ stopped = true;
412
+ }
413
+ return;
414
+ }
415
+ }
416
+ };
417
+ await Promise.all(Array.from({ length: Math.min(concurrency, items.length) }, () => runWorker()));
418
+ if (errors.length > 0) {
419
+ throw errors[0];
377
420
  }
378
421
  };
379
422
  const describe = (segment) => segment.label.heading ? ` ‹${segment.label.heading}›` : '';
@@ -560,6 +560,7 @@ export const translateCommand = new Command('translate')
560
560
  contextTail: translateOptions.contextTail,
561
561
  repairer,
562
562
  previous,
563
+ segmentConcurrency: concurrency,
563
564
  onProgress: (message) => {
564
565
  logger.info(message);
565
566
  },
@@ -1,6 +1,6 @@
1
1
  import { type RspressPlugin } from '@rspress/core';
2
2
  import { type DoomSite } from '../../shared/index.ts';
3
- import type { ExportItem } from '../../types.ts';
3
+ import type { ExportItem, ProductsOverviewOptions } from '../../types.ts';
4
4
  export interface GlobalPluginOptions {
5
5
  version?: string;
6
6
  download?: boolean;
@@ -8,6 +8,7 @@ export interface GlobalPluginOptions {
8
8
  export interface GlobalVirtual extends GlobalPluginOptions {
9
9
  userBase: string;
10
10
  prefix?: string;
11
+ productsOverview?: ProductsOverviewOptions;
11
12
  sites?: DoomSite[];
12
13
  export?: ExportItem[];
13
14
  sidebarManifestUrl?: string;
@@ -46,6 +46,7 @@ export const globalPlugin = ({ version, download, }) => {
46
46
  'doom-@global-virtual': `export default ${JSON.stringify({
47
47
  userBase: config.userBase,
48
48
  prefix: config.prefix,
49
+ productsOverview: config.productsOverview,
49
50
  version,
50
51
  download,
51
52
  sites: config.sites?.map((site) => ({
@@ -1,9 +1,10 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import { addLeadingSlash, NoSSR, useSite } from '@rspress/core/runtime';
2
+ import { addLeadingSlash, NoSSR, useHead, useSite } from '@rspress/core/runtime';
3
3
  import virtual from 'doom-@global-virtual';
4
4
  import { use } from 'react';
5
5
  import { BuildInfoContext } from "../shared/context.js";
6
6
  import { isUnversioned } from '../shared/helpers.js';
7
+ import { getProductsOverviewCanonical, getProductsOverviewUrl } from "./url.js";
7
8
  import { useIsPrint, useLang, useTranslation } from '@alauda/doom/runtime';
8
9
  import classes from '@alauda/doom/styles/products.module.scss';
9
10
  const Products = () => {
@@ -20,6 +21,14 @@ const Products = () => {
20
21
  item.base }) }, item.base))) })] }, group.id))) }));
21
22
  };
22
23
  export default () => {
24
+ const lang = useLang();
23
25
  const t = useTranslation();
24
- return (_jsxs(_Fragment, { children: [_jsx("h1", { children: t('all_product_documentation') }), _jsx("p", { children: t('explore_doc_all_products') }), _jsx(NoSSR, { children: _jsx(Products, {}) })] }));
26
+ const productsOverviewCanonical = getProductsOverviewCanonical(virtual.productsOverview, virtual.prefix);
27
+ const productsOverviewUrl = getProductsOverviewUrl(virtual.productsOverview, lang, virtual.prefix);
28
+ useHead({
29
+ link: productsOverviewCanonical
30
+ ? [{ rel: 'canonical', href: productsOverviewCanonical }]
31
+ : [],
32
+ });
33
+ return (_jsxs(_Fragment, { children: [_jsx("h1", { children: t('all_product_documentation') }), _jsx("p", { children: t('explore_doc_all_products') }), productsOverviewUrl && (_jsx("p", { children: _jsx("a", { className: "rp-link", href: productsOverviewUrl, children: t('all_product_documentation') }) })), _jsx(NoSSR, { children: _jsx(Products, {}) })] }));
25
34
  };
@@ -0,0 +1,3 @@
1
+ import type { ProductsOverviewOptions } from '../types.ts';
2
+ export declare const getProductsOverviewUrl: (options: ProductsOverviewOptions | undefined, lang: string, prefix?: string) => string;
3
+ export declare const getProductsOverviewCanonical: (options: ProductsOverviewOptions | undefined, prefix?: string) => string;
@@ -0,0 +1,34 @@
1
+ const URL_BASE = 'https://doom.invalid';
2
+ const defaultProductsOverviewUrl = (prefix) => {
3
+ const normalizedPrefix = prefix?.replace(/\/+$/, '') ?? '';
4
+ return `${normalizedPrefix}/products/`;
5
+ };
6
+ const parseOverviewUrl = (options) => {
7
+ const { url } = options;
8
+ const parsed = new URL(url, URL_BASE);
9
+ let isAbsolute = false;
10
+ try {
11
+ isAbsolute = Boolean(new URL(url).protocol);
12
+ }
13
+ catch {
14
+ // The URL is checked as a root-relative path below.
15
+ }
16
+ const isRootRelative = url.startsWith('/') && !url.startsWith('//');
17
+ if (!isAbsolute && !isRootRelative) {
18
+ throw new Error('`productsOverview.url` must be an absolute URL or a root-relative path');
19
+ }
20
+ return parsed;
21
+ };
22
+ const serializeUrl = (url, isRelative) => isRelative ? `${url.pathname}${url.search}${url.hash}` : url.toString();
23
+ export const getProductsOverviewUrl = (options, lang, prefix) => {
24
+ const configuredUrl = options?.url ?? defaultProductsOverviewUrl(prefix);
25
+ const isRelative = configuredUrl.startsWith('/');
26
+ const url = parseOverviewUrl({ url: configuredUrl });
27
+ url.searchParams.set('lang', lang);
28
+ return serializeUrl(url, isRelative);
29
+ };
30
+ export const getProductsOverviewCanonical = (options, prefix) => {
31
+ const configuredUrl = options?.url ?? defaultProductsOverviewUrl(prefix);
32
+ const isRelative = configuredUrl.startsWith('/');
33
+ return serializeUrl(parseOverviewUrl({ url: configuredUrl }), isRelative);
34
+ };
@@ -5,6 +5,7 @@ import virtual from 'doom-@global-virtual';
5
5
  import { use, useEffect, useMemo } from 'react';
6
6
  import { xfetch } from 'x-fetch';
7
7
  import { parse } from 'yaml';
8
+ import { getProductsOverviewUrl } from "../../products/url.js";
8
9
  import { BuildInfoContext } from "../../shared/context.js";
9
10
  import { X } from "../_X.js";
10
11
  import { useLang, useSiteOverrides, useTranslation } from '@alauda/doom/runtime';
@@ -43,6 +44,7 @@ export const BreadCrumb = () => {
43
44
  return walk(sidebar);
44
45
  }, [pathname, sidebar]);
45
46
  const prefix = addTrailingSlash(`/${lang === siteData.lang ? '' : lang}`);
47
+ const productsOverviewUrl = getProductsOverviewUrl(virtual.productsOverview, lang, virtual.prefix);
46
48
  const { groups, setGroups: setBuildInfoGroups } = use(BuildInfoContext);
47
49
  const hasGroups = !!groups.length;
48
50
  useEffect(() => {
@@ -86,6 +88,6 @@ export const BreadCrumb = () => {
86
88
  };
87
89
  void fetchBuildInfo();
88
90
  }, [setBuildInfoGroups]);
89
- return (_jsx("div", { className: "breadcrumb-container", children: _jsxs("ul", { className: "breadcrumb-content", children: [hasGroups && (_jsx("li", { className: "breadcrumb-item rp-doc", children: _jsx(X.a, { href: prefix + 'products', children: t('products') }) })), _jsxs("li", { className: "breadcrumb-item rp-doc", children: [hasGroups && _jsx(SvgWrapper, { icon: IconArrowRight }), _jsx(X.a, { href: prefix, children: site.title || siteData.title })] }), breadcrumbItems?.map((item, index) => (_jsxs("li", { className: "breadcrumb-item rp-doc", children: [_jsx(SvgWrapper, { icon: IconArrowRight }), item.link ? (_jsx(X.a, { href: item.link, children: item.text })) : (_jsx("span", { className: "breadcrumb-item-text", children: item.text }))] }, index)))] }) }));
91
+ return (_jsx("div", { className: "breadcrumb-container", children: _jsxs("ul", { className: "breadcrumb-content", children: [hasGroups && (_jsx("li", { className: "breadcrumb-item rp-doc", children: _jsx("a", { href: productsOverviewUrl, children: t('products') }) })), _jsxs("li", { className: "breadcrumb-item rp-doc", children: [hasGroups && _jsx(SvgWrapper, { icon: IconArrowRight }), _jsx(X.a, { href: prefix, children: site.title || siteData.title })] }), breadcrumbItems?.map((item, index) => (_jsxs("li", { className: "breadcrumb-item rp-doc", children: [_jsx(SvgWrapper, { icon: IconArrowRight }), item.link ? (_jsx(X.a, { href: item.link, children: item.text })) : (_jsx("span", { className: "breadcrumb-item-text", children: item.text }))] }, index)))] }) }));
90
92
  };
91
93
  export default BreadCrumb;
package/lib/types.d.ts CHANGED
@@ -201,6 +201,16 @@ export interface AlgoliaOptions {
201
201
  apiKey: string;
202
202
  indexName: string;
203
203
  }
204
+ export interface ProductsOverviewOptions {
205
+ /**
206
+ * The deployment's outer products overview URL. It may be an absolute URL
207
+ * or a root-relative path such as `/products/` or `/docs/products/`.
208
+ * The value is used as-is for the Products link and canonical URL. If the
209
+ * overview is a directory index, include a trailing slash because the page
210
+ * loads its stylesheets with relative paths.
211
+ */
212
+ url: string;
213
+ }
204
214
  export interface ExportItem {
205
215
  name?: string;
206
216
  scope: string | string[];
@@ -225,6 +235,7 @@ declare module '@rspress/shared' {
225
235
  lint?: LintOptions;
226
236
  algolia?: AlgoliaOptions;
227
237
  siteUrl?: string;
238
+ productsOverview?: ProductsOverviewOptions;
228
239
  export?: ExportItem[];
229
240
  }
230
241
  interface SiteData {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alauda/doom",
3
- "version": "2.11.2",
3
+ "version": "2.11.4",
4
4
  "type": "module",
5
5
  "description": "Doctor Doom making docs.",
6
6
  "repository": {