@qualcomm-ui/mdx-vite 2.10.1 → 2.11.1

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.
package/dist/cli.js CHANGED
@@ -3570,15 +3570,41 @@ var knowledgeIntegrationSchema = implement().with(
3570
3570
  exclude: z2.array(z2.string()).optional(),
3571
3571
  exports: knowledgeExportsSchema.optional(),
3572
3572
  extraFiles: z2.array(knowledgeExtraFileSchema).optional(),
3573
+ frontmatterFields: z2.union([z2.array(z2.string()), z2.any()]).optional(),
3573
3574
  metadata: z2.record(z2.string(), z2.string()).optional(),
3574
3575
  name: z2.string().optional(),
3575
3576
  outputMode: z2.union([z2.literal("per-page"), z2.literal("aggregated")]).optional(),
3576
3577
  outputPath: z2.string().optional(),
3578
+ pageIdPrefix: z2.string().optional(),
3577
3579
  pageTitlePrefix: z2.string().optional()
3578
3580
  }
3579
3581
  );
3582
+ var knowledgeEnvironmentSchema = implement().with({
3583
+ baseUrl: z2.string().optional(),
3584
+ description: z2.string().optional(),
3585
+ exclude: z2.array(z2.string()).optional(),
3586
+ exports: knowledgeExportsSchema.optional(),
3587
+ extraFiles: z2.array(knowledgeExtraFileSchema).optional(),
3588
+ frontmatterFields: z2.array(z2.string()).optional(),
3589
+ id: z2.string(),
3590
+ metadata: z2.record(z2.string(), z2.string()).optional(),
3591
+ name: z2.string().optional(),
3592
+ outputMode: z2.union([z2.literal("per-page"), z2.literal("aggregated")]).optional(),
3593
+ outputPath: z2.string(),
3594
+ pageIdPrefix: z2.string().optional(),
3595
+ pageTitlePrefix: z2.string().optional()
3596
+ });
3597
+ var openWebUiIntegrationSchema = implement().with({
3598
+ envFile: z2.string().optional(),
3599
+ id: z2.string()
3600
+ });
3601
+ var knowledgeIntegrationsSchema = implement().with({
3602
+ openWebUi: z2.array(openWebUiIntegrationSchema).optional()
3603
+ });
3580
3604
  var knowledgeConfigSchema = implement().with({
3581
- global: knowledgeIntegrationSchema.optional()
3605
+ environments: z2.array(knowledgeEnvironmentSchema).optional(),
3606
+ global: knowledgeIntegrationSchema.optional(),
3607
+ integrations: knowledgeIntegrationsSchema.optional()
3582
3608
  });
3583
3609
  var configSchema = implement().with({
3584
3610
  appDirectory: z2.string().optional(),
@@ -5286,6 +5312,7 @@ function addGeneratePageMapCommand() {
5286
5312
  }
5287
5313
 
5288
5314
  // src/open-web-ui-knowledge/download-knowledge.ts
5315
+ import dotenv from "dotenv";
5289
5316
  import { mkdir, writeFile as writeFile2 } from "node:fs/promises";
5290
5317
  import { resolve as resolve2 } from "node:path";
5291
5318
 
@@ -5602,9 +5629,9 @@ function loadEnv() {
5602
5629
  }
5603
5630
  }
5604
5631
  function getConfigFromEnv() {
5605
- const openWebUiUrl = process.env.WEB_UI_URL;
5606
- const openWebUiKey = process.env.WEB_UI_KEY;
5607
- const knowledgeId = process.env.KNOWLEDGE_ID;
5632
+ const openWebUiUrl = process.env.WEB_UI_URL || process.env.OPEN_WEB_UI_URL;
5633
+ const openWebUiKey = process.env.WEB_UI_KEY || process.env.OPEN_WEB_UI_API_KEY;
5634
+ const knowledgeId = process.env.KNOWLEDGE_ID || process.env.OPEN_WEB_UI_KNOWLEDGE_ID;
5608
5635
  if (!openWebUiUrl || !openWebUiKey || !knowledgeId) {
5609
5636
  throw new Error("WEB_UI_URL, WEB_UI_KEY, and KNOWLEDGE_ID must be set");
5610
5637
  }
@@ -5614,11 +5641,47 @@ function getConfigFromEnv() {
5614
5641
  webUiUrl: openWebUiUrl
5615
5642
  };
5616
5643
  }
5644
+ function loadOpenWebUiEnv(integration, integrationName) {
5645
+ const envFilePath = integration.envFile ?? `.env.${integration.id}`;
5646
+ config({ override: true, path: envFilePath });
5647
+ const url = process.env.OPEN_WEB_UI_URL ?? process.env.WEB_UI_URL;
5648
+ const apiKey = process.env.OPEN_WEB_UI_API_KEY ?? process.env.WEB_UI_KEY;
5649
+ const knowledgeId = process.env.OPEN_WEB_UI_KNOWLEDGE_ID ?? process.env.KNOWLEDGE_ID;
5650
+ if (!url) {
5651
+ throw new Error(
5652
+ `Missing OPEN_WEB_UI_URL for integration "${integrationName}" (env file: ${envFilePath})`
5653
+ );
5654
+ }
5655
+ if (!apiKey) {
5656
+ throw new Error(
5657
+ `Missing OPEN_WEB_UI_API_KEY for integration "${integrationName}" (env file: ${envFilePath})`
5658
+ );
5659
+ }
5660
+ if (!knowledgeId) {
5661
+ throw new Error(
5662
+ `Missing OPEN_WEB_UI_KNOWLEDGE_ID for integration "${integrationName}" (env file: ${envFilePath})`
5663
+ );
5664
+ }
5665
+ return { apiKey, knowledgeId, url };
5666
+ }
5667
+ function resolveOpenWebUiIntegration(name, integration, outputPath) {
5668
+ const credentials = loadOpenWebUiEnv(integration, name);
5669
+ return {
5670
+ apiKey: credentials.apiKey,
5671
+ environment: integration.id,
5672
+ knowledgeId: credentials.knowledgeId,
5673
+ name,
5674
+ outputPath,
5675
+ url: credentials.url
5676
+ };
5677
+ }
5617
5678
 
5618
5679
  // src/open-web-ui-knowledge/download-knowledge.ts
5619
5680
  function addDownloadKnowledgeCommand() {
5620
- program.command("download-knowledge").description("Download files from an Open Web UI knowledge base").requiredOption("-o, --output-dir <outputDir>", "Folder path").action(async (opts) => {
5681
+ program.command("download-knowledge").description("Download files from an Open Web UI knowledge base").requiredOption("-o, --output-dir <outputDir>", "Folder path").requiredOption("-e, --environment <environments>", "environment to load").action(async (opts) => {
5621
5682
  loadEnv();
5683
+ const env = opts.environment;
5684
+ dotenv.config({ path: `.env.${env}` });
5622
5685
  await mkdir(opts.outputDir, { recursive: true }).catch();
5623
5686
  const config2 = getConfigFromEnv();
5624
5687
  const apiConfig = { apiKey: config2.webUiKey, baseUrl: config2.webUiUrl };
@@ -5647,6 +5710,7 @@ function addDownloadKnowledgeCommand() {
5647
5710
  }
5648
5711
 
5649
5712
  // src/open-web-ui-knowledge/generate-knowledge.ts
5713
+ import chalk3 from "chalk";
5650
5714
  import { minimatch } from "minimatch";
5651
5715
  import {
5652
5716
  access,
@@ -5707,6 +5771,100 @@ function loadKnowledgeConfigFromEnv(options) {
5707
5771
  routeDir
5708
5772
  };
5709
5773
  }
5774
+ function mergeEnvironmentConfig(global, environment) {
5775
+ return {
5776
+ ...global,
5777
+ ...environment,
5778
+ extraFiles: environment.extraFiles ?? global?.extraFiles,
5779
+ metadata: global?.metadata || environment.metadata ? { ...global?.metadata, ...environment.metadata } : void 0
5780
+ };
5781
+ }
5782
+ function loadEnvironmentConfigs(options = {}) {
5783
+ const configLoader = new ConfigLoader({});
5784
+ const resolvedConfig = configLoader.loadConfig();
5785
+ const knowledgeConfig = resolvedConfig.knowledge;
5786
+ const globalConfig = knowledgeConfig?.global;
5787
+ const environments = knowledgeConfig?.environments;
5788
+ const routeDir = join2(
5789
+ resolvedConfig.appDirectory,
5790
+ resolvedConfig.pageDirectory
5791
+ );
5792
+ if (!existsSync(resolve3(routeDir))) {
5793
+ throw new Error(`Route directory ${routeDir} does not exist`);
5794
+ }
5795
+ if (!environments || environments.length === 0) {
5796
+ const legacyConfig = loadKnowledgeConfigFromEnv(
5797
+ options.cliOptions ?? { outputMode: "per-page" }
5798
+ );
5799
+ return [legacyConfig];
5800
+ }
5801
+ let filteredEnvironments = environments;
5802
+ if (options.environments?.length) {
5803
+ const filterSet = new Set(options.environments);
5804
+ filteredEnvironments = environments.filter((env) => filterSet.has(env.id));
5805
+ }
5806
+ if (filteredEnvironments.length === 0) {
5807
+ throw new Error(
5808
+ `No matching environments found. Available: ${environments.map((e) => e.id).join(", ")}`
5809
+ );
5810
+ }
5811
+ return filteredEnvironments.map((envConfig) => {
5812
+ const merged = mergeEnvironmentConfig(globalConfig, envConfig);
5813
+ const cliOpts = options.cliOptions;
5814
+ const cliMetadata = parseCliMetadata(cliOpts?.metadata);
5815
+ const mergedMetadata = merged.metadata || cliMetadata ? { ...merged.metadata, ...cliMetadata } : void 0;
5816
+ return {
5817
+ ...merged,
5818
+ ...cliOpts,
5819
+ baseUrl: cliOpts?.baseUrl ?? merged.baseUrl ?? process.env.DOCS_SITE_BASE_URL,
5820
+ docPropsPath: resolvedConfig.typeDocProps,
5821
+ environmentName: envConfig.id,
5822
+ exclude: (cliOpts?.exclude?.length ? cliOpts.exclude : void 0) ?? merged.exclude ?? (process.env.FILE_EXCLUDE_PATTERN ?? "").split(",").filter(Boolean),
5823
+ extraFiles: merged.extraFiles,
5824
+ metadata: mergedMetadata,
5825
+ outputMode: cliOpts?.outputMode ?? merged.outputMode ?? "per-page",
5826
+ outputPath: merged.outputPath,
5827
+ pageTitlePrefix: cliOpts?.pageTitlePrefix ?? merged.pageTitlePrefix ?? process.env.PAGE_TITLE_PREFIX,
5828
+ routeDir
5829
+ };
5830
+ });
5831
+ }
5832
+ function loadOpenWebUiIntegrations(options = {}) {
5833
+ const configLoader = new ConfigLoader({});
5834
+ const resolvedConfig = configLoader.loadConfig();
5835
+ const knowledgeConfig = resolvedConfig.knowledge;
5836
+ const environments = knowledgeConfig?.environments;
5837
+ const integrations = knowledgeConfig?.integrations?.openWebUi;
5838
+ if (!integrations || integrations.length === 0) {
5839
+ return [];
5840
+ }
5841
+ let filteredIntegrations = integrations;
5842
+ if (options.integrations?.length) {
5843
+ const filterSet = new Set(options.integrations);
5844
+ filteredIntegrations = integrations.filter(
5845
+ (integration) => filterSet.has(integration.id)
5846
+ );
5847
+ }
5848
+ if (options.environments?.length) {
5849
+ const filterSet = new Set(options.environments);
5850
+ filteredIntegrations = filteredIntegrations.filter(
5851
+ (integration) => filterSet.has(integration.id)
5852
+ );
5853
+ }
5854
+ return filteredIntegrations.map((integration) => {
5855
+ const envConfig = environments?.find((e) => e.id === integration.id);
5856
+ if (!envConfig) {
5857
+ throw new Error(
5858
+ `Integration "${integration.id}" references unknown environment "${integration.id}". Available environments: ${environments?.map((e) => e.id).join(", ") || "none"}`
5859
+ );
5860
+ }
5861
+ return {
5862
+ integration,
5863
+ name: integration.id,
5864
+ outputPath: envConfig.outputPath
5865
+ };
5866
+ });
5867
+ }
5710
5868
 
5711
5869
  // src/open-web-ui-knowledge/generate-knowledge.ts
5712
5870
  async function exists(dirPath) {
@@ -5880,7 +6038,6 @@ var KnowledgeGenerator = class {
5880
6038
  processedPages,
5881
6039
  extractedMetadata
5882
6040
  );
5883
- await this.generateExtraFiles(extractedMetadata);
5884
6041
  }
5885
6042
  return pages;
5886
6043
  }
@@ -5934,6 +6091,7 @@ var KnowledgeGenerator = class {
5934
6091
  const mdxFiles = entries.filter(
5935
6092
  (f) => f.name.endsWith(".mdx") && !shouldExclude(join3(dirPath, f.name))
5936
6093
  ) ?? [];
6094
+ const pageIdPrefix = this.config.pageIdPrefix ?? "";
5937
6095
  for (const mdxFile of mdxFiles) {
5938
6096
  const demosFolder = entries.find((f) => f.name === "demos");
5939
6097
  const demosFolderPath = demosFolder ? join3(dirPath, demosFolder.name) : void 0;
@@ -5945,7 +6103,7 @@ var KnowledgeGenerator = class {
5945
6103
  components.push({
5946
6104
  demosFolder: demosFolderPath,
5947
6105
  filePath: dirPath,
5948
- id: segments.join("-").trim(),
6106
+ id: `${pageIdPrefix ? `${pageIdPrefix}-` : ""}${segments.join("-").trim()}`,
5949
6107
  mdxFile: join3(dirPath, mdxFile.name),
5950
6108
  name: segments.at(-1),
5951
6109
  pathname: url,
@@ -6480,9 +6638,10 @@ ${propsToDefinitionList(outputs)}`);
6480
6638
  console.log(`File size: ${outputSizeKb} KB`);
6481
6639
  }
6482
6640
  async generateExtraFiles(metadata) {
6641
+ const start = performance.now();
6483
6642
  const extraFiles = this.config.extraFiles ?? [];
6484
6643
  if (extraFiles.length === 0) {
6485
- return;
6644
+ return { count: 0, duration: 0, totalSize: 0 };
6486
6645
  }
6487
6646
  let totalSize = 0;
6488
6647
  await Promise.all(
@@ -6513,11 +6672,14 @@ ${propsToDefinitionList(outputs)}`);
6513
6672
  totalSize += stats.size / 1024;
6514
6673
  })
6515
6674
  );
6516
- console.log(
6517
- `Generated ${extraFiles.length} extra file(s) (${totalSize.toFixed(1)} KB)`
6518
- );
6675
+ return {
6676
+ count: extraFiles.length,
6677
+ duration: performance.now() - start,
6678
+ totalSize
6679
+ };
6519
6680
  }
6520
6681
  async generatePerPageExports(pages, processedPages, metadata) {
6682
+ const start = performance.now();
6521
6683
  await mkdir2(dirname(this.config.outputPath), { recursive: true }).catch(
6522
6684
  () => {
6523
6685
  }
@@ -6528,16 +6690,38 @@ ${propsToDefinitionList(outputs)}`);
6528
6690
  processedPages.map(async (processedPage, index) => {
6529
6691
  const page = pages[index];
6530
6692
  const lines = [];
6531
- if (metadata.length || page.url) {
6532
- lines.push("---");
6533
- if (page.url) {
6534
- lines.push(`url: ${page.url}`);
6535
- }
6536
- if (metadata.length) {
6537
- for (const [key, value] of metadata) {
6538
- lines.push(`${key}: ${value}`);
6693
+ const frontmatterEntries = [];
6694
+ if (page.url) {
6695
+ frontmatterEntries.push(["url", page.url]);
6696
+ }
6697
+ for (const [key, value] of metadata) {
6698
+ frontmatterEntries.push([key, value]);
6699
+ }
6700
+ if (this.config.frontmatterFields) {
6701
+ if (typeof this.config.frontmatterFields === "function") {
6702
+ const transformed = this.config.frontmatterFields(
6703
+ processedPage.frontmatter,
6704
+ page
6705
+ );
6706
+ for (const [key, value] of Object.entries(transformed)) {
6707
+ if (value !== void 0) {
6708
+ frontmatterEntries.push([key, String(value)]);
6709
+ }
6710
+ }
6711
+ } else {
6712
+ for (const field of this.config.frontmatterFields) {
6713
+ const value = processedPage.frontmatter[field];
6714
+ if (value !== void 0) {
6715
+ frontmatterEntries.push([field, String(value)]);
6716
+ }
6539
6717
  }
6540
6718
  }
6719
+ }
6720
+ if (frontmatterEntries.length > 0) {
6721
+ lines.push("---");
6722
+ for (const [key, value] of frontmatterEntries) {
6723
+ lines.push(`${key}: ${value}`);
6724
+ }
6541
6725
  lines.push("---");
6542
6726
  lines.push("");
6543
6727
  }
@@ -6602,8 +6786,10 @@ ${propsToDefinitionList(outputs)}`);
6602
6786
  totalSize += stats.size / 1024;
6603
6787
  })
6604
6788
  );
6605
- console.log(`Generated ${count} files(s) in ${this.config.outputPath}`);
6606
- console.log(`Folder size: ${totalSize.toFixed(1)} KB`);
6789
+ const extraFilesResult = await this.generateExtraFiles(metadata);
6790
+ console.log(
6791
+ `Generated ${count + extraFilesResult.count} files(s) in ${chalk3.magenta.bold(`${Math.round(performance.now() - start + extraFilesResult.duration)}ms`)} at ${chalk3.blue.bold(this.config.outputPath)} - ${(totalSize + extraFilesResult.totalSize).toFixed(1)} KB`
6792
+ );
6607
6793
  }
6608
6794
  };
6609
6795
  async function generate(config2) {
@@ -6618,13 +6804,31 @@ function addGenerateKnowledgeCommand() {
6618
6804
  "--exclude <patterns...>",
6619
6805
  "Glob patterns to exclude (e.g., **/internal/**, guide/drafts/*)",
6620
6806
  []
6621
- ).option("--base-url <url>", "Base URL for component documentation links").option("--metadata <pairs...>", "metadata key-value pairs").option("--clean", "Clean the output path before generating").option("--include-imports", "Include relative import source files", true).action(async (options) => {
6807
+ ).option("--base-url <url>", "Base URL for component documentation links").option("--metadata <pairs...>", "metadata key-value pairs").option("--clean", "Clean the output path before generating").option("--include-imports", "Include relative import source files", true).option(
6808
+ "-e, --environment <environments>",
6809
+ "Comma-separated list of environments to generate (default: all)"
6810
+ ).action(async (options) => {
6622
6811
  loadEnv();
6623
- const knowledgeConfig = loadKnowledgeConfigFromEnv({
6812
+ const cliOptions = {
6624
6813
  ...options,
6625
6814
  outputMode: options.outputMode === "per-page" ? "per-page" : "aggregated"
6815
+ };
6816
+ const environmentFilter = options.environment?.split(",").map((e) => e.trim()).filter(Boolean);
6817
+ const configs = loadEnvironmentConfigs({
6818
+ cliOptions,
6819
+ environments: environmentFilter
6626
6820
  });
6627
- await generate(knowledgeConfig);
6821
+ for (const config2 of configs) {
6822
+ const envLabel = config2.environmentName ? `[${config2.environmentName}] ` : "";
6823
+ console.log(`${envLabel}Generating knowledge to ${config2.outputPath}`);
6824
+ await generate(config2);
6825
+ }
6826
+ if (configs.length > 1) {
6827
+ console.log(
6828
+ `
6829
+ Generated knowledge for ${configs.length} environment(s)`
6830
+ );
6831
+ }
6628
6832
  });
6629
6833
  }
6630
6834
 
@@ -6769,7 +6973,10 @@ var Uploader = class {
6769
6973
  }))
6770
6974
  );
6771
6975
  const knowledge = await this.knowledgeApi.getById(this.config.knowledgeId);
6772
- this.knowledgeFilesCache = (knowledge.files ?? []).map(toKnowledgeFile);
6976
+ const receivedFiles = knowledge.files?.length ? knowledge.files.map(toKnowledgeFile) : await this.filesApi.list().then(
6977
+ (res) => res.filter((file) => file.meta.collection_name === knowledge.id)
6978
+ );
6979
+ this.knowledgeFilesCache = receivedFiles;
6773
6980
  await this.buildHashCache(this.knowledgeFilesCache);
6774
6981
  let skippedCount = 0;
6775
6982
  let successCount = 0;
@@ -6894,9 +7101,56 @@ function addUploadKnowledgeCommand() {
6894
7101
  program.name("upload-knowledge").description("Upload files to OpenWebUI knowledge base").command("upload-knowledge").option("-p, --path <path>", "Path to file or folder relative to script").option(
6895
7102
  "--force",
6896
7103
  "force upload files, even if their contents have not changed"
7104
+ ).option(
7105
+ "-i, --integration <integrations>",
7106
+ "Comma-separated list of integrations to upload to (default: all)"
7107
+ ).option(
7108
+ "-e, --environment <environments>",
7109
+ "Comma-separated list of environments to filter integrations by (default: all)"
6897
7110
  ).action(async (options) => {
6898
7111
  loadEnv();
6899
- return getUploader(options.path, options.force).uploadKnowledge();
7112
+ const integrationFilter = options.integration?.split(",").map((e) => e.trim()).filter(Boolean);
7113
+ const environmentFilter = options.environment?.split(",").map((e) => e.trim()).filter(Boolean);
7114
+ const integrations = loadOpenWebUiIntegrations({
7115
+ environments: environmentFilter,
7116
+ integrations: integrationFilter
7117
+ });
7118
+ if (integrations.length === 0) {
7119
+ console.log("No integrations configured, using legacy env vars");
7120
+ return getUploader(options.path, options.force).uploadKnowledge();
7121
+ }
7122
+ let successCount = 0;
7123
+ let failureCount = 0;
7124
+ for (const { integration, name, outputPath } of integrations) {
7125
+ console.log(`
7126
+ [${name}] Uploading to OpenWebUI...`);
7127
+ try {
7128
+ const resolved = resolveOpenWebUiIntegration(
7129
+ name,
7130
+ integration,
7131
+ outputPath
7132
+ );
7133
+ const uploader = new Uploader({
7134
+ force: options.force,
7135
+ knowledgeFilePath: options.path ?? resolved.outputPath,
7136
+ knowledgeId: resolved.knowledgeId,
7137
+ webUiKey: resolved.apiKey,
7138
+ webUiUrl: resolved.url
7139
+ });
7140
+ await uploader.uploadKnowledge();
7141
+ successCount++;
7142
+ console.log(`[${name}] Upload complete`);
7143
+ } catch (error) {
7144
+ failureCount++;
7145
+ console.error(`[${name}] Upload failed:`, error);
7146
+ }
7147
+ }
7148
+ if (integrations.length > 1) {
7149
+ console.log(
7150
+ `
7151
+ Uploaded to ${successCount} integration(s)${failureCount > 0 ? `, ${failureCount} failed` : ""}`
7152
+ );
7153
+ }
6900
7154
  });
6901
7155
  program.command("get-knowledge-files").description("Get files from OpenWebUI knowledge base").option("-p, --path <path>", "Path to file or folder relative to script").action(async (options) => {
6902
7156
  loadEnv();
@@ -6954,7 +7208,7 @@ import { resolve as resolve7 } from "node:path";
6954
7208
  import { dedent } from "@qualcomm-ui/utils/dedent";
6955
7209
 
6956
7210
  // src/react-demo-plugin/demo-plugin-utils.ts
6957
- import chalk3 from "chalk";
7211
+ import chalk4 from "chalk";
6958
7212
  import { existsSync as existsSync2, readFileSync as readFileSync2 } from "node:fs";
6959
7213
  import { dirname as dirname2, join as join4, relative as relative3, resolve as resolve6, sep } from "node:path";
6960
7214
  import * as ts from "typescript";