@promptbook/markdown-utils 0.100.1 โ†’ 0.100.3-0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import type { string_agent_name } from '../../types/typeAliases';
2
2
  import type { string_url_image } from '../../types/typeAliases';
3
3
  import type { string_book } from './string_book';
4
- export interface AgentBasicInformation {
4
+ export type AgentBasicInformation = {
5
5
  /**
6
6
  * Name of the agent
7
7
  * This is the first line of the agent source
@@ -17,7 +17,7 @@ export interface AgentBasicInformation {
17
17
  * This is the line starting with "META IMAGE"
18
18
  */
19
19
  profileImageUrl: string_url_image;
20
- }
20
+ };
21
21
  /**
22
22
  * Parses basic information from agent source
23
23
  *
@@ -6,7 +6,7 @@ import type { AgentModelRequirements } from '../_misc/AgentModelRequirements';
6
6
  * - Creating regex patterns for parsing
7
7
  * - Applying its effects to agent model requirements
8
8
  */
9
- export interface CommitmentDefinition {
9
+ export type CommitmentDefinition = {
10
10
  /**
11
11
  * The type/name of this commitment (e.g., 'PERSONA', 'KNOWLEDGE', etc.)
12
12
  */
@@ -45,4 +45,4 @@ export interface CommitmentDefinition {
45
45
  * @returns Updated agent model requirements
46
46
  */
47
47
  applyToAgentModelRequirements(requirements: AgentModelRequirements, content: string): AgentModelRequirements;
48
- }
48
+ };
@@ -4,7 +4,7 @@ import type { TODO_any } from '../../../utils/organization/TODO_any';
4
4
  *
5
5
  * This is like "compiled" version of agent source
6
6
  */
7
- export interface AgentModelRequirements {
7
+ export type AgentModelRequirements = {
8
8
  /**
9
9
  * The system message that defines the agent's behavior and personality
10
10
  */
@@ -34,4 +34,4 @@ export interface AgentModelRequirements {
34
34
  * Each commitment can store its own data here
35
35
  */
36
36
  readonly metadata?: Record<string, TODO_any>;
37
- }
37
+ };
@@ -2,7 +2,7 @@ import type { ParsedCommitment } from './ParsedCommitment';
2
2
  /**
3
3
  * Result of parsing agent source for commitments
4
4
  */
5
- export interface AgentSourceParseResult {
5
+ export type AgentSourceParseResult = {
6
6
  /**
7
7
  * The agent name (first line)
8
8
  */
@@ -15,4 +15,4 @@ export interface AgentSourceParseResult {
15
15
  * Lines that are not commitments (for system message)
16
16
  */
17
17
  nonCommitmentLines: string[];
18
- }
18
+ };
@@ -2,7 +2,7 @@ import type { BookCommitment } from '../_base/BookCommitment';
2
2
  /**
3
3
  * Parsed commitment line from agent source
4
4
  */
5
- export interface ParsedCommitment {
5
+ export type ParsedCommitment = {
6
6
  /**
7
7
  * The commitment type (e.g., 'PERSONA', 'KNOWLEDGE')
8
8
  */
@@ -19,4 +19,4 @@ export interface ParsedCommitment {
19
19
  * Line number in the agent source (1-based)
20
20
  */
21
21
  lineNumber: number;
22
- }
22
+ };
@@ -5,7 +5,7 @@ import type { string_postprocessing_function_name } from '../../types/typeAliase
5
5
  /**
6
6
  * Options for validating a prompt result
7
7
  */
8
- export interface ValidatePromptResultOptions {
8
+ export type ValidatePromptResultOptions = {
9
9
  /**
10
10
  * The result string to validate
11
11
  */
@@ -23,11 +23,11 @@ export interface ValidatePromptResultOptions {
23
23
  * Note: This is for validation purposes only - postprocessing should be done before calling this function
24
24
  */
25
25
  postprocessingFunctionNames?: ReadonlyArray<string_postprocessing_function_name>;
26
- }
26
+ };
27
27
  /**
28
28
  * Result of prompt result validation
29
29
  */
30
- export interface ValidatePromptResultResult {
30
+ export type ValidatePromptResultResult = {
31
31
  /**
32
32
  * Whether the result is valid (passes all expectations and format checks)
33
33
  */
@@ -40,7 +40,7 @@ export interface ValidatePromptResultResult {
40
40
  * Error that occurred during validation, if any
41
41
  */
42
42
  error?: ExpectError;
43
- }
43
+ };
44
44
  /**
45
45
  * Validates a prompt result against expectations and format requirements.
46
46
  * This function provides a common abstraction for result validation that can be used
@@ -6,7 +6,7 @@ import type { Takeable } from './Takeable';
6
6
  * @deprecated [๐Ÿคก] Use some better functional library instead of `TakeChain`
7
7
  */
8
8
  export type WithTake<TValue extends Takeable> = TValue & ITakeChain<TValue>;
9
- export interface ITakeChain<TValue extends Takeable> {
9
+ export type ITakeChain<TValue extends Takeable> = {
10
10
  readonly value: TValue;
11
11
  then<TResultValue extends Takeable>(callback: (value: TValue) => TResultValue): WithTake<TResultValue>;
12
- }
12
+ };
@@ -1,7 +1,7 @@
1
1
  import type { string_filename } from '../../../types/typeAliases';
2
2
  import type { really_unknown } from '../../organization/really_unknown';
3
3
  /**
4
- * Tests if given string is valid URL.
4
+ * Tests if given string is valid file path.
5
5
  *
6
6
  * Note: This does not check if the file exists only if the path is valid
7
7
  * @public exported from `@promptbook/utils`
@@ -15,7 +15,7 @@ export declare const BOOK_LANGUAGE_VERSION: string_semantic_version;
15
15
  export declare const PROMPTBOOK_ENGINE_VERSION: string_promptbook_version;
16
16
  /**
17
17
  * Represents the version string of the Promptbook engine.
18
- * It follows semantic versioning (e.g., `0.100.0`).
18
+ * It follows semantic versioning (e.g., `0.100.2`).
19
19
  *
20
20
  * @generated
21
21
  */
@@ -9,12 +9,12 @@ import type { string_pipeline_url } from '../types/typeAliases';
9
9
  /**
10
10
  * Options for wizard methods
11
11
  */
12
- interface WizardOptions {
12
+ type WizardOptions = {
13
13
  /**
14
14
  * Whether to enable verbose logging
15
15
  */
16
16
  isVerbose?: boolean;
17
- }
17
+ };
18
18
  /**
19
19
  * Wizard for simple usage of the Promptbook
20
20
  * Look at `wizard` for more details
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@promptbook/markdown-utils",
3
- "version": "0.100.1",
3
+ "version": "0.100.3-0",
4
4
  "description": "Promptbook: Run AI apps in plain human language across multiple models and platforms",
5
5
  "private": false,
6
6
  "sideEffects": false,
package/umd/index.umd.js CHANGED
@@ -26,7 +26,7 @@
26
26
  * @generated
27
27
  * @see https://github.com/webgptorg/promptbook
28
28
  */
29
- const PROMPTBOOK_ENGINE_VERSION = '0.100.1';
29
+ const PROMPTBOOK_ENGINE_VERSION = '0.100.3-0';
30
30
  /**
31
31
  * TODO: string_promptbook_version should be constrained to the all versions of Promptbook engine
32
32
  * Note: [๐Ÿ’ž] Ignore a discrepancy between file name and entity name
@@ -584,7 +584,7 @@
584
584
  }
585
585
 
586
586
  /**
587
- * Tests if given string is valid URL.
587
+ * Tests if given string is valid file path.
588
588
  *
589
589
  * Note: This does not check if the file exists only if the path is valid
590
590
  * @public exported from `@promptbook/utils`
@@ -596,18 +596,25 @@
596
596
  if (filename.split('\n').length > 1) {
597
597
  return false;
598
598
  }
599
- if (filename.split(' ').length >
600
- 5 /* <- TODO: [๐Ÿง ][๐Ÿˆท] Make some better non-arbitrary way how to distinct filenames from informational texts */) {
599
+ // Normalize slashes early so heuristics can detect path-like inputs
600
+ const filenameSlashes = filename.replace(/\\/g, '/');
601
+ // Reject strings that look like sentences (informational text)
602
+ // Heuristic: contains multiple spaces and ends with a period, or contains typical sentence punctuation
603
+ // But skip this heuristic if the string looks like a path (contains '/' or starts with a drive letter)
604
+ if (filename.trim().length > 60 && // long enough to be a sentence
605
+ /[.!?]/.test(filename) && // contains sentence punctuation
606
+ filename.split(' ').length > 8 && // has many words
607
+ !/\/|^[A-Z]:/i.test(filenameSlashes) // do NOT treat as sentence if looks like a path
608
+ ) {
601
609
  return false;
602
610
  }
603
- const filenameSlashes = filename.split('\\').join('/');
604
611
  // Absolute Unix path: /hello.txt
605
612
  if (/^(\/)/i.test(filenameSlashes)) {
606
613
  // console.log(filename, 'Absolute Unix path: /hello.txt');
607
614
  return true;
608
615
  }
609
- // Absolute Windows path: /hello.txt
610
- if (/^([A-Z]{1,2}:\/?)\//i.test(filenameSlashes)) {
616
+ // Absolute Windows path: C:/ or C:\ (allow spaces and multiple dots in filename)
617
+ if (/^[A-Z]:\/.+$/i.test(filenameSlashes)) {
611
618
  // console.log(filename, 'Absolute Windows path: /hello.txt');
612
619
  return true;
613
620
  }
@@ -3697,9 +3704,15 @@
3697
3704
  }
3698
3705
  if (isValidUrl(knowledgeSourceContent)) {
3699
3706
  const url = knowledgeSourceContent;
3707
+ if (isVerbose) {
3708
+ console.info(`๐Ÿ“„ [1] "${name}" is available at "${url}"`);
3709
+ }
3700
3710
  const response = await fetch(url); // <- TODO: [๐Ÿง ] Scraping and fetch proxy
3701
3711
  const mimeType = ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.split(';')[0]) || 'text/html';
3702
3712
  if (tools.fs === undefined || !url.endsWith('.pdf' /* <- TODO: [๐Ÿ’ต] */)) {
3713
+ if (isVerbose) {
3714
+ console.info(`๐Ÿ“„ [2] "${name}" tools.fs is not available or URL is not a PDF.`);
3715
+ }
3703
3716
  return {
3704
3717
  source: name,
3705
3718
  filename: null,
@@ -3735,13 +3748,17 @@
3735
3748
  await tools.fs.mkdir(path.dirname(path.join(rootDirname, filepath)), { recursive: true });
3736
3749
  }
3737
3750
  catch (error) {
3751
+ if (isVerbose) {
3752
+ console.info(`๐Ÿ“„ [3] "${name}" error creating cache directory`);
3753
+ }
3738
3754
  // Note: If we can't create cache directory, we'll handle it when trying to write the file
3739
3755
  // This handles read-only filesystems, permission issues, and missing parent directories
3740
- if (error instanceof Error && (error.message.includes('EROFS') ||
3741
- error.message.includes('read-only') ||
3742
- error.message.includes('EACCES') ||
3743
- error.message.includes('EPERM') ||
3744
- error.message.includes('ENOENT'))) ;
3756
+ if (error instanceof Error &&
3757
+ (error.message.includes('EROFS') ||
3758
+ error.message.includes('read-only') ||
3759
+ error.message.includes('EACCES') ||
3760
+ error.message.includes('EPERM') ||
3761
+ error.message.includes('ENOENT'))) ;
3745
3762
  else {
3746
3763
  // Re-throw other unexpected errors
3747
3764
  throw error;
@@ -3756,13 +3773,17 @@
3756
3773
  await tools.fs.writeFile(path.join(rootDirname, filepath), fileContent);
3757
3774
  }
3758
3775
  catch (error) {
3776
+ if (isVerbose) {
3777
+ console.info(`๐Ÿ“„ [4] "${name}" error writing cache file`);
3778
+ }
3759
3779
  // Note: If we can't write to cache, we'll process the file directly from memory
3760
3780
  // This handles read-only filesystems like Vercel
3761
- if (error instanceof Error && (error.message.includes('EROFS') ||
3762
- error.message.includes('read-only') ||
3763
- error.message.includes('EACCES') ||
3764
- error.message.includes('EPERM') ||
3765
- error.message.includes('ENOENT'))) {
3781
+ if (error instanceof Error &&
3782
+ (error.message.includes('EROFS') ||
3783
+ error.message.includes('read-only') ||
3784
+ error.message.includes('EACCES') ||
3785
+ error.message.includes('EPERM') ||
3786
+ error.message.includes('ENOENT'))) {
3766
3787
  // Return a handler that works directly with the downloaded content
3767
3788
  return {
3768
3789
  source: name,
@@ -3784,6 +3805,9 @@
3784
3805
  }
3785
3806
  // TODO: [๐Ÿ’ต] Check the file security
3786
3807
  // TODO: [๐Ÿงน][๐Ÿง ] Delete the file after the scraping is done
3808
+ if (isVerbose) {
3809
+ console.info(`๐Ÿ“„ [5] "${name}" cached at "${path.join(rootDirname, filepath)}"`);
3810
+ }
3787
3811
  return makeKnowledgeSourceHandler({ name, knowledgeSourceContent: filepath }, tools, {
3788
3812
  ...options,
3789
3813
  rootDirname,
@@ -3798,7 +3822,12 @@
3798
3822
  throw new EnvironmentMismatchError('Can not import file knowledge in non-file pipeline');
3799
3823
  // <- TODO: [๐Ÿง ] What is the best error type here`
3800
3824
  }
3801
- const filename = path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
3825
+ const filename = path.isAbsolute(knowledgeSourceContent)
3826
+ ? knowledgeSourceContent
3827
+ : path.join(rootDirname, knowledgeSourceContent).split('\\').join('/');
3828
+ if (isVerbose) {
3829
+ console.info(`๐Ÿ“„ [6] "${name}" is a valid file "${filename}"`);
3830
+ }
3802
3831
  const fileExtension = getFileExtension(filename);
3803
3832
  const mimeType = extensionToMimeType(fileExtension || '');
3804
3833
  if (!(await isFileExisting(filename, tools.fs))) {
@@ -3840,6 +3869,12 @@
3840
3869
  };
3841
3870
  }
3842
3871
  else {
3872
+ if (isVerbose) {
3873
+ console.info(`๐Ÿ“„ [7] "${name}" is just a explicit string text with a knowledge source`);
3874
+ console.info('---');
3875
+ console.info(knowledgeSourceContent);
3876
+ console.info('---');
3877
+ }
3843
3878
  return {
3844
3879
  source: name,
3845
3880
  filename: null,