@fragola-ai/prompt 1.0.0 → 1.0.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/Prompt.d.ts +85 -0
- package/dist/index.d.ts +3 -0
- package/dist/utils.d.ts +1 -0
- package/package.json +1 -1
package/dist/Prompt.d.ts
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents a record of variables used for string interpolation in prompts.
|
|
3
|
+
* Each key in the record is a variable name to interpolate in the prompt template,
|
|
4
|
+
* and its value can be any type (object, array, number, string, etc.) which will replace the placeholder.
|
|
5
|
+
*/
|
|
6
|
+
export type Variables = Record<string, any>;
|
|
7
|
+
export declare class MissingVariablesError extends Error {
|
|
8
|
+
variables: string[];
|
|
9
|
+
constructor(variables: string[], prompt: string);
|
|
10
|
+
}
|
|
11
|
+
export declare class NamespaceUndefinedError extends Error {
|
|
12
|
+
namespace: string;
|
|
13
|
+
constructor(namespace: string);
|
|
14
|
+
}
|
|
15
|
+
export declare class LoadFileReadError extends Error {
|
|
16
|
+
filePath: string;
|
|
17
|
+
originalError: Error;
|
|
18
|
+
constructor(filePath: string, originalError: Error);
|
|
19
|
+
}
|
|
20
|
+
export type Load = {
|
|
21
|
+
load: true;
|
|
22
|
+
relativePath: string;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Creates a Load object to specify a prompt file location.
|
|
26
|
+
* This function is used when the prompt is located in a file system.
|
|
27
|
+
* The process working directory (PWD) is used as the base path by default.
|
|
28
|
+
* Path aliases can be used to reduce path overhead.
|
|
29
|
+
*
|
|
30
|
+
* @param {string} relativePath - The relative path to the prompt file. Can include path aliases.
|
|
31
|
+
* @returns {Load} An object containing the load flag and the relative path to the prompt file
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* // Using relative path
|
|
35
|
+
* load('./prompts/myPrompt.txt')
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* // Using path alias
|
|
39
|
+
* load('prompts:myPrompt.txt')
|
|
40
|
+
*/
|
|
41
|
+
export declare const load: (relativePath: string) => Load;
|
|
42
|
+
export default class Prompt {
|
|
43
|
+
#private;
|
|
44
|
+
private static defaultVariableRegex;
|
|
45
|
+
/**
|
|
46
|
+
* A map of aliases to file paths for use with the {@link load} function.
|
|
47
|
+
* Allows defining shortcuts for commonly used prompt file paths.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```typescript
|
|
51
|
+
* Prompt.pathAlias = {
|
|
52
|
+
* browse: "prompts", // Maps "@browse" to "prompts/"
|
|
53
|
+
* refund: "prompts/refund" // Maps "@refund" to "prompts/refund/"
|
|
54
|
+
* }
|
|
55
|
+
*
|
|
56
|
+
* // Usage with load():
|
|
57
|
+
* load("@refund/shopRefund.md") // Resolves to "prompts/refund/shopRefund.md"
|
|
58
|
+
* ```
|
|
59
|
+
* @see {@link load}
|
|
60
|
+
*/
|
|
61
|
+
static pathAlias: Record<string, string>;
|
|
62
|
+
constructor(prompt: string | Load, variables?: Variables);
|
|
63
|
+
/**
|
|
64
|
+
* Updates the variables used for string interpolation and re-processes the prompt template.
|
|
65
|
+
*
|
|
66
|
+
* @param variables - Your new variables
|
|
67
|
+
* @throws {MissingVariablesError} When required variables are not provided in the variables object
|
|
68
|
+
*/
|
|
69
|
+
setVariables(variables: Variables): void;
|
|
70
|
+
/**
|
|
71
|
+
* Gets the original prompt string used for this instance. Before any processing
|
|
72
|
+
* @returns {string} The original prompt string
|
|
73
|
+
*/
|
|
74
|
+
get promptString(): string;
|
|
75
|
+
/**
|
|
76
|
+
* Gets the variables currently in use for this prompt.
|
|
77
|
+
* @returns {Map<string, any>} A map containing the prompt variables and their values.
|
|
78
|
+
*/
|
|
79
|
+
get variables(): Variables;
|
|
80
|
+
/**
|
|
81
|
+
* Gets the interpolated value of the prompt.
|
|
82
|
+
* @returns {string} The resulting string after all variable interpolation has been applied.
|
|
83
|
+
*/
|
|
84
|
+
get value(): string;
|
|
85
|
+
}
|
package/dist/index.d.ts
ADDED
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|