@nudge-ai/core 0.0.1-beta.0 → 0.1.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.
- package/README.md +15 -0
- package/dist/index.cjs +9 -117
- package/dist/index.d.cts +9 -91
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +9 -91
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +7 -114
- package/dist/index.mjs.map +1 -1
- package/dist/internal.cjs +4 -0
- package/dist/internal.d.cts +2 -0
- package/dist/internal.d.mts +2 -0
- package/dist/internal.mjs +3 -0
- package/dist/nudge-B-p-8Izg.d.mts +141 -0
- package/dist/nudge-B-p-8Izg.d.mts.map +1 -0
- package/dist/nudge-D5w_m7nH.d.cts +141 -0
- package/dist/nudge-D5w_m7nH.d.cts.map +1 -0
- package/dist/nudge-R1WAnc_7.mjs +218 -0
- package/dist/nudge-R1WAnc_7.mjs.map +1 -0
- package/dist/nudge-yNScKCNl.cjs +247 -0
- package/package.json +8 -1
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# @nudge-ai/core
|
|
2
|
+
|
|
3
|
+
Type-safe prompt builder for AI applications.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @nudge-ai/core
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Documentation
|
|
12
|
+
|
|
13
|
+
For documentation, examples, and API reference, visit:
|
|
14
|
+
|
|
15
|
+
**[https://nudge-ai.dev](https://nudge-ai.dev)**
|
package/dist/index.cjs
CHANGED
|
@@ -1,121 +1,13 @@
|
|
|
1
|
+
const require_nudge = require('./nudge-yNScKCNl.cjs');
|
|
1
2
|
|
|
2
|
-
//#region src/builder.ts
|
|
3
|
-
function createBuilder(targetState) {
|
|
4
|
-
const state = targetState ?? [];
|
|
5
|
-
const builder = {
|
|
6
|
-
raw: (value) => (state.push({
|
|
7
|
-
type: "raw",
|
|
8
|
-
value
|
|
9
|
-
}), builder),
|
|
10
|
-
persona: (role) => (state.push({
|
|
11
|
-
type: "persona",
|
|
12
|
-
role
|
|
13
|
-
}), builder),
|
|
14
|
-
input: (description) => (state.push({
|
|
15
|
-
type: "input",
|
|
16
|
-
description
|
|
17
|
-
}), builder),
|
|
18
|
-
output: (description) => (state.push({
|
|
19
|
-
type: "output",
|
|
20
|
-
description
|
|
21
|
-
}), builder),
|
|
22
|
-
context: (information) => (state.push({
|
|
23
|
-
type: "context",
|
|
24
|
-
information
|
|
25
|
-
}), builder),
|
|
26
|
-
do: (instruction, options) => (state.push({
|
|
27
|
-
type: "do",
|
|
28
|
-
instruction,
|
|
29
|
-
nudge: options?.nudge
|
|
30
|
-
}), builder),
|
|
31
|
-
dont: (instruction, options) => (state.push({
|
|
32
|
-
type: "dont",
|
|
33
|
-
instruction,
|
|
34
|
-
nudge: options?.nudge
|
|
35
|
-
}), builder),
|
|
36
|
-
constraint: (rule, options) => (state.push({
|
|
37
|
-
type: "constraint",
|
|
38
|
-
rule,
|
|
39
|
-
nudge: options?.nudge
|
|
40
|
-
}), builder),
|
|
41
|
-
example: (input, output) => (state.push({
|
|
42
|
-
type: "example",
|
|
43
|
-
input,
|
|
44
|
-
output
|
|
45
|
-
}), builder),
|
|
46
|
-
use: (source) => (state.push(...source._state), builder),
|
|
47
|
-
optional: (name, builderFn) => {
|
|
48
|
-
const optionalSteps = [];
|
|
49
|
-
const { builder: innerBuilder } = createBuilder(optionalSteps);
|
|
50
|
-
builderFn(innerBuilder);
|
|
51
|
-
state.push({
|
|
52
|
-
type: "optional",
|
|
53
|
-
name,
|
|
54
|
-
steps: optionalSteps
|
|
55
|
-
});
|
|
56
|
-
return builder;
|
|
57
|
-
}
|
|
58
|
-
};
|
|
59
|
-
return {
|
|
60
|
-
builder,
|
|
61
|
-
state
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
//#endregion
|
|
66
|
-
//#region src/steps.ts
|
|
67
|
-
function formatNudge(nudge) {
|
|
68
|
-
if (!nudge || nudge === 3) return "";
|
|
69
|
-
return `\nNudge: ${nudge}`;
|
|
70
|
-
}
|
|
71
|
-
function formatStepForAI(step) {
|
|
72
|
-
switch (step.type) {
|
|
73
|
-
case "raw": return `[Raw Text] (Include this text verbatim in the system prompt.)\nValue: "${step.value}"`;
|
|
74
|
-
case "persona": return `[Persona] (Define the identity and role the AI should assume. Frame this as 'You are...' at the start of the system prompt.)\nValue: "${step.role}"`;
|
|
75
|
-
case "input": return `[Input] (Describe what input the AI will receive from the user. Help the AI understand the context of what it will be working with.)\nValue: "${step.description}"`;
|
|
76
|
-
case "output": return `[Output] (Specify what the AI should produce as output. Be clear about the expected format and content.)\nValue: "${step.description}"`;
|
|
77
|
-
case "context": return `[Context] (Background information or context that helps the AI understand the situation. This is not an instruction, just helpful information.)\nValue: "${step.information}"`;
|
|
78
|
-
case "do": return `[Do] (A positive instruction the AI must follow.)\nValue: "${step.instruction}"${formatNudge(step.nudge)}`;
|
|
79
|
-
case "dont": return `[Don't] (A negative instruction - something the AI must avoid.)\nValue: "${step.instruction}"${formatNudge(step.nudge)}`;
|
|
80
|
-
case "constraint": return `[Constraint] (A rule or limitation the AI must respect.)\nValue: "${step.rule}"${formatNudge(step.nudge)}`;
|
|
81
|
-
case "example": return `[Example] (An input/output example showing the AI how to respond. Use these to demonstrate the expected behavior.)\nInput: "${step.input}"\nExpected output: "${step.output}"`;
|
|
82
|
-
case "optional": {
|
|
83
|
-
const innerSteps = step.steps.map(formatStepForAI).join("\n\n");
|
|
84
|
-
return `[Optional Block Start: "${step.name}"] (The following instructions are OPTIONAL. Wrap the generated content for these in {{#${step.name}}}...{{/${step.name}}} markers so it can be toggled at runtime.)\n\n${innerSteps}\n\n[Optional Block End: "${step.name}"]`;
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
//#endregion
|
|
90
3
|
//#region src/index.ts
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
function processTemplate(text, options = {}) {
|
|
99
|
-
const processOptionals = (str) => str.replace(/\{\{#(\w+)\}\}([\s\S]*?)\{\{\/\1\}\}/g, (_, name, content) => options[name] ? processOptionals(content) : "");
|
|
100
|
-
const processVars = (str) => str.replace(/\{\{(?![#\/])(\w+)\}\}/g, (match, name) => {
|
|
101
|
-
const value = options[name];
|
|
102
|
-
return typeof value === "string" ? value : match;
|
|
103
|
-
});
|
|
104
|
-
return processVars(processOptionals(text)).replace(/\n{3,}/g, "\n\n");
|
|
105
|
-
}
|
|
106
|
-
function prompt(id, promptFunc) {
|
|
107
|
-
const { builder, state } = createBuilder();
|
|
108
|
-
promptFunc(builder);
|
|
109
|
-
return {
|
|
110
|
-
id,
|
|
111
|
-
_state: state,
|
|
112
|
-
toString: ((options) => {
|
|
113
|
-
return processTemplate(promptCache[id]?.text ?? "", options).trim();
|
|
114
|
-
})
|
|
115
|
-
};
|
|
116
|
-
}
|
|
4
|
+
/**
|
|
5
|
+
* Create a prompt using the default builder with all base steps.
|
|
6
|
+
* For custom steps, create your own builder with `createBuilder()`.
|
|
7
|
+
*/
|
|
8
|
+
const prompt = require_nudge.nudge.prompt;
|
|
117
9
|
|
|
118
10
|
//#endregion
|
|
119
|
-
exports.
|
|
120
|
-
exports.
|
|
121
|
-
exports.
|
|
11
|
+
exports.createBuilder = require_nudge.createBuilder;
|
|
12
|
+
exports.createStep = require_nudge.createStep;
|
|
13
|
+
exports.prompt = prompt;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,94 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
type RawStep = {
|
|
4
|
-
type: "raw";
|
|
5
|
-
value: string;
|
|
6
|
-
};
|
|
7
|
-
type PersonaStep = {
|
|
8
|
-
type: "persona";
|
|
9
|
-
role: string;
|
|
10
|
-
};
|
|
11
|
-
type InputStep = {
|
|
12
|
-
type: "input";
|
|
13
|
-
description: string;
|
|
14
|
-
};
|
|
15
|
-
type OutputStep = {
|
|
16
|
-
type: "output";
|
|
17
|
-
description: string;
|
|
18
|
-
};
|
|
19
|
-
type ContextStep = {
|
|
20
|
-
type: "context";
|
|
21
|
-
information: string;
|
|
22
|
-
};
|
|
23
|
-
type DoStep = {
|
|
24
|
-
type: "do";
|
|
25
|
-
instruction: string;
|
|
26
|
-
nudge?: Nudge;
|
|
27
|
-
};
|
|
28
|
-
type DontStep = {
|
|
29
|
-
type: "dont";
|
|
30
|
-
instruction: string;
|
|
31
|
-
nudge?: Nudge;
|
|
32
|
-
};
|
|
33
|
-
type ConstraintStep = {
|
|
34
|
-
type: "constraint";
|
|
35
|
-
rule: string;
|
|
36
|
-
nudge?: Nudge;
|
|
37
|
-
};
|
|
38
|
-
type ExampleStep = {
|
|
39
|
-
type: "example";
|
|
40
|
-
input: string;
|
|
41
|
-
output: string;
|
|
42
|
-
};
|
|
43
|
-
type OptionalStep = {
|
|
44
|
-
type: "optional";
|
|
45
|
-
name: string;
|
|
46
|
-
steps: PromptStep[];
|
|
47
|
-
};
|
|
48
|
-
type PromptStep = RawStep | PersonaStep | InputStep | OutputStep | ContextStep | DoStep | DontStep | ConstraintStep | ExampleStep | OptionalStep;
|
|
49
|
-
type StepType = PromptStep["type"];
|
|
50
|
-
declare function formatStepForAI(step: PromptStep): string;
|
|
51
|
-
//#endregion
|
|
52
|
-
//#region src/types.d.ts
|
|
53
|
-
type PromptBuilderState = PromptStep[];
|
|
54
|
-
type PromptBuilder<Optionals extends string = never> = {
|
|
55
|
-
raw: (value: string) => PromptBuilder<Optionals>;
|
|
56
|
-
persona: (role: string) => PromptBuilder<Optionals>;
|
|
57
|
-
input: (description: string) => PromptBuilder<Optionals>;
|
|
58
|
-
output: (description: string) => PromptBuilder<Optionals>;
|
|
59
|
-
context: (information: string) => PromptBuilder<Optionals>;
|
|
60
|
-
do: (instruction: string, options?: {
|
|
61
|
-
nudge?: Nudge;
|
|
62
|
-
}) => PromptBuilder<Optionals>;
|
|
63
|
-
dont: (instruction: string, options?: {
|
|
64
|
-
nudge?: Nudge;
|
|
65
|
-
}) => PromptBuilder<Optionals>;
|
|
66
|
-
constraint: (rule: string, options?: {
|
|
67
|
-
nudge?: Nudge;
|
|
68
|
-
}) => PromptBuilder<Optionals>;
|
|
69
|
-
example: (input: string, output: string) => PromptBuilder<Optionals>;
|
|
70
|
-
use: (source: {
|
|
71
|
-
_state: PromptBuilderState;
|
|
72
|
-
}) => PromptBuilder<Optionals>;
|
|
73
|
-
optional: <Name extends string, Inner extends string = never>(name: Name, builderFn: (p: PromptBuilder) => PromptBuilder<Inner>) => PromptBuilder<Optionals | Name | Inner>;
|
|
74
|
-
};
|
|
75
|
-
interface PromptRegistry {}
|
|
76
|
-
interface PromptVariables {}
|
|
77
|
-
type PromptId = keyof PromptRegistry;
|
|
78
|
-
type ToStringOptions<Optionals extends string, Variables extends string> = [Variables] extends [never] ? [Optionals] extends [never] ? () => string : (options?: Partial<Record<Optionals, boolean>>) => string : [Optionals] extends [never] ? (options: Record<Variables, string>) => string : (options: Record<Variables, string> & Partial<Record<Optionals, boolean>>) => string;
|
|
79
|
-
type Prompt<Id extends string = string, Optionals extends string = never> = {
|
|
80
|
-
id: Id;
|
|
81
|
-
_state: PromptBuilderState;
|
|
82
|
-
toString: ToStringOptions<Optionals, Id extends keyof PromptVariables ? PromptVariables[Id] : never>;
|
|
83
|
-
};
|
|
84
|
-
type GeneratedPrompt = {
|
|
85
|
-
text: string;
|
|
86
|
-
hash: string;
|
|
87
|
-
};
|
|
88
|
-
//#endregion
|
|
1
|
+
import { c as createBuilder, h as createStep, i as Prompt, m as StepDefinition, n as DefaultPromptFn, t as Builder } from "./nudge-D5w_m7nH.cjs";
|
|
2
|
+
|
|
89
3
|
//#region src/index.d.ts
|
|
90
|
-
|
|
91
|
-
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Create a prompt using the default builder with all base steps.
|
|
7
|
+
* For custom steps, create your own builder with `createBuilder()`.
|
|
8
|
+
*/
|
|
9
|
+
declare const prompt: DefaultPromptFn;
|
|
92
10
|
//#endregion
|
|
93
|
-
export { type
|
|
11
|
+
export { type Builder, type Prompt, type StepDefinition, createBuilder, createStep, prompt };
|
|
94
12
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;AAOA;;cAAa,QAAQ"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,94 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
type RawStep = {
|
|
4
|
-
type: "raw";
|
|
5
|
-
value: string;
|
|
6
|
-
};
|
|
7
|
-
type PersonaStep = {
|
|
8
|
-
type: "persona";
|
|
9
|
-
role: string;
|
|
10
|
-
};
|
|
11
|
-
type InputStep = {
|
|
12
|
-
type: "input";
|
|
13
|
-
description: string;
|
|
14
|
-
};
|
|
15
|
-
type OutputStep = {
|
|
16
|
-
type: "output";
|
|
17
|
-
description: string;
|
|
18
|
-
};
|
|
19
|
-
type ContextStep = {
|
|
20
|
-
type: "context";
|
|
21
|
-
information: string;
|
|
22
|
-
};
|
|
23
|
-
type DoStep = {
|
|
24
|
-
type: "do";
|
|
25
|
-
instruction: string;
|
|
26
|
-
nudge?: Nudge;
|
|
27
|
-
};
|
|
28
|
-
type DontStep = {
|
|
29
|
-
type: "dont";
|
|
30
|
-
instruction: string;
|
|
31
|
-
nudge?: Nudge;
|
|
32
|
-
};
|
|
33
|
-
type ConstraintStep = {
|
|
34
|
-
type: "constraint";
|
|
35
|
-
rule: string;
|
|
36
|
-
nudge?: Nudge;
|
|
37
|
-
};
|
|
38
|
-
type ExampleStep = {
|
|
39
|
-
type: "example";
|
|
40
|
-
input: string;
|
|
41
|
-
output: string;
|
|
42
|
-
};
|
|
43
|
-
type OptionalStep = {
|
|
44
|
-
type: "optional";
|
|
45
|
-
name: string;
|
|
46
|
-
steps: PromptStep[];
|
|
47
|
-
};
|
|
48
|
-
type PromptStep = RawStep | PersonaStep | InputStep | OutputStep | ContextStep | DoStep | DontStep | ConstraintStep | ExampleStep | OptionalStep;
|
|
49
|
-
type StepType = PromptStep["type"];
|
|
50
|
-
declare function formatStepForAI(step: PromptStep): string;
|
|
51
|
-
//#endregion
|
|
52
|
-
//#region src/types.d.ts
|
|
53
|
-
type PromptBuilderState = PromptStep[];
|
|
54
|
-
type PromptBuilder<Optionals extends string = never> = {
|
|
55
|
-
raw: (value: string) => PromptBuilder<Optionals>;
|
|
56
|
-
persona: (role: string) => PromptBuilder<Optionals>;
|
|
57
|
-
input: (description: string) => PromptBuilder<Optionals>;
|
|
58
|
-
output: (description: string) => PromptBuilder<Optionals>;
|
|
59
|
-
context: (information: string) => PromptBuilder<Optionals>;
|
|
60
|
-
do: (instruction: string, options?: {
|
|
61
|
-
nudge?: Nudge;
|
|
62
|
-
}) => PromptBuilder<Optionals>;
|
|
63
|
-
dont: (instruction: string, options?: {
|
|
64
|
-
nudge?: Nudge;
|
|
65
|
-
}) => PromptBuilder<Optionals>;
|
|
66
|
-
constraint: (rule: string, options?: {
|
|
67
|
-
nudge?: Nudge;
|
|
68
|
-
}) => PromptBuilder<Optionals>;
|
|
69
|
-
example: (input: string, output: string) => PromptBuilder<Optionals>;
|
|
70
|
-
use: (source: {
|
|
71
|
-
_state: PromptBuilderState;
|
|
72
|
-
}) => PromptBuilder<Optionals>;
|
|
73
|
-
optional: <Name extends string, Inner extends string = never>(name: Name, builderFn: (p: PromptBuilder) => PromptBuilder<Inner>) => PromptBuilder<Optionals | Name | Inner>;
|
|
74
|
-
};
|
|
75
|
-
interface PromptRegistry {}
|
|
76
|
-
interface PromptVariables {}
|
|
77
|
-
type PromptId = keyof PromptRegistry;
|
|
78
|
-
type ToStringOptions<Optionals extends string, Variables extends string> = [Variables] extends [never] ? [Optionals] extends [never] ? () => string : (options?: Partial<Record<Optionals, boolean>>) => string : [Optionals] extends [never] ? (options: Record<Variables, string>) => string : (options: Record<Variables, string> & Partial<Record<Optionals, boolean>>) => string;
|
|
79
|
-
type Prompt<Id extends string = string, Optionals extends string = never> = {
|
|
80
|
-
id: Id;
|
|
81
|
-
_state: PromptBuilderState;
|
|
82
|
-
toString: ToStringOptions<Optionals, Id extends keyof PromptVariables ? PromptVariables[Id] : never>;
|
|
83
|
-
};
|
|
84
|
-
type GeneratedPrompt = {
|
|
85
|
-
text: string;
|
|
86
|
-
hash: string;
|
|
87
|
-
};
|
|
88
|
-
//#endregion
|
|
1
|
+
import { c as createBuilder, h as createStep, i as Prompt, m as StepDefinition, n as DefaultPromptFn, t as Builder } from "./nudge-B-p-8Izg.mjs";
|
|
2
|
+
|
|
89
3
|
//#region src/index.d.ts
|
|
90
|
-
|
|
91
|
-
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Create a prompt using the default builder with all base steps.
|
|
7
|
+
* For custom steps, create your own builder with `createBuilder()`.
|
|
8
|
+
*/
|
|
9
|
+
declare const prompt: DefaultPromptFn;
|
|
92
10
|
//#endregion
|
|
93
|
-
export { type
|
|
11
|
+
export { type Builder, type Prompt, type StepDefinition, createBuilder, createStep, prompt };
|
|
94
12
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"sourcesContent":[],"mappings":";;;;;;AAOA;;cAAa,QAAQ"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,119 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
function createBuilder(targetState) {
|
|
3
|
-
const state = targetState ?? [];
|
|
4
|
-
const builder = {
|
|
5
|
-
raw: (value) => (state.push({
|
|
6
|
-
type: "raw",
|
|
7
|
-
value
|
|
8
|
-
}), builder),
|
|
9
|
-
persona: (role) => (state.push({
|
|
10
|
-
type: "persona",
|
|
11
|
-
role
|
|
12
|
-
}), builder),
|
|
13
|
-
input: (description) => (state.push({
|
|
14
|
-
type: "input",
|
|
15
|
-
description
|
|
16
|
-
}), builder),
|
|
17
|
-
output: (description) => (state.push({
|
|
18
|
-
type: "output",
|
|
19
|
-
description
|
|
20
|
-
}), builder),
|
|
21
|
-
context: (information) => (state.push({
|
|
22
|
-
type: "context",
|
|
23
|
-
information
|
|
24
|
-
}), builder),
|
|
25
|
-
do: (instruction, options) => (state.push({
|
|
26
|
-
type: "do",
|
|
27
|
-
instruction,
|
|
28
|
-
nudge: options?.nudge
|
|
29
|
-
}), builder),
|
|
30
|
-
dont: (instruction, options) => (state.push({
|
|
31
|
-
type: "dont",
|
|
32
|
-
instruction,
|
|
33
|
-
nudge: options?.nudge
|
|
34
|
-
}), builder),
|
|
35
|
-
constraint: (rule, options) => (state.push({
|
|
36
|
-
type: "constraint",
|
|
37
|
-
rule,
|
|
38
|
-
nudge: options?.nudge
|
|
39
|
-
}), builder),
|
|
40
|
-
example: (input, output) => (state.push({
|
|
41
|
-
type: "example",
|
|
42
|
-
input,
|
|
43
|
-
output
|
|
44
|
-
}), builder),
|
|
45
|
-
use: (source) => (state.push(...source._state), builder),
|
|
46
|
-
optional: (name, builderFn) => {
|
|
47
|
-
const optionalSteps = [];
|
|
48
|
-
const { builder: innerBuilder } = createBuilder(optionalSteps);
|
|
49
|
-
builderFn(innerBuilder);
|
|
50
|
-
state.push({
|
|
51
|
-
type: "optional",
|
|
52
|
-
name,
|
|
53
|
-
steps: optionalSteps
|
|
54
|
-
});
|
|
55
|
-
return builder;
|
|
56
|
-
}
|
|
57
|
-
};
|
|
58
|
-
return {
|
|
59
|
-
builder,
|
|
60
|
-
state
|
|
61
|
-
};
|
|
62
|
-
}
|
|
1
|
+
import { a as createStep, r as nudge, t as createBuilder } from "./nudge-R1WAnc_7.mjs";
|
|
63
2
|
|
|
64
|
-
//#endregion
|
|
65
|
-
//#region src/steps.ts
|
|
66
|
-
function formatNudge(nudge) {
|
|
67
|
-
if (!nudge || nudge === 3) return "";
|
|
68
|
-
return `\nNudge: ${nudge}`;
|
|
69
|
-
}
|
|
70
|
-
function formatStepForAI(step) {
|
|
71
|
-
switch (step.type) {
|
|
72
|
-
case "raw": return `[Raw Text] (Include this text verbatim in the system prompt.)\nValue: "${step.value}"`;
|
|
73
|
-
case "persona": return `[Persona] (Define the identity and role the AI should assume. Frame this as 'You are...' at the start of the system prompt.)\nValue: "${step.role}"`;
|
|
74
|
-
case "input": return `[Input] (Describe what input the AI will receive from the user. Help the AI understand the context of what it will be working with.)\nValue: "${step.description}"`;
|
|
75
|
-
case "output": return `[Output] (Specify what the AI should produce as output. Be clear about the expected format and content.)\nValue: "${step.description}"`;
|
|
76
|
-
case "context": return `[Context] (Background information or context that helps the AI understand the situation. This is not an instruction, just helpful information.)\nValue: "${step.information}"`;
|
|
77
|
-
case "do": return `[Do] (A positive instruction the AI must follow.)\nValue: "${step.instruction}"${formatNudge(step.nudge)}`;
|
|
78
|
-
case "dont": return `[Don't] (A negative instruction - something the AI must avoid.)\nValue: "${step.instruction}"${formatNudge(step.nudge)}`;
|
|
79
|
-
case "constraint": return `[Constraint] (A rule or limitation the AI must respect.)\nValue: "${step.rule}"${formatNudge(step.nudge)}`;
|
|
80
|
-
case "example": return `[Example] (An input/output example showing the AI how to respond. Use these to demonstrate the expected behavior.)\nInput: "${step.input}"\nExpected output: "${step.output}"`;
|
|
81
|
-
case "optional": {
|
|
82
|
-
const innerSteps = step.steps.map(formatStepForAI).join("\n\n");
|
|
83
|
-
return `[Optional Block Start: "${step.name}"] (The following instructions are OPTIONAL. Wrap the generated content for these in {{#${step.name}}}...{{/${step.name}}} markers so it can be toggled at runtime.)\n\n${innerSteps}\n\n[Optional Block End: "${step.name}"]`;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
//#endregion
|
|
89
3
|
//#region src/index.ts
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
function processTemplate(text, options = {}) {
|
|
98
|
-
const processOptionals = (str) => str.replace(/\{\{#(\w+)\}\}([\s\S]*?)\{\{\/\1\}\}/g, (_, name, content) => options[name] ? processOptionals(content) : "");
|
|
99
|
-
const processVars = (str) => str.replace(/\{\{(?![#\/])(\w+)\}\}/g, (match, name) => {
|
|
100
|
-
const value = options[name];
|
|
101
|
-
return typeof value === "string" ? value : match;
|
|
102
|
-
});
|
|
103
|
-
return processVars(processOptionals(text)).replace(/\n{3,}/g, "\n\n");
|
|
104
|
-
}
|
|
105
|
-
function prompt(id, promptFunc) {
|
|
106
|
-
const { builder, state } = createBuilder();
|
|
107
|
-
promptFunc(builder);
|
|
108
|
-
return {
|
|
109
|
-
id,
|
|
110
|
-
_state: state,
|
|
111
|
-
toString: ((options) => {
|
|
112
|
-
return processTemplate(promptCache[id]?.text ?? "", options).trim();
|
|
113
|
-
})
|
|
114
|
-
};
|
|
115
|
-
}
|
|
4
|
+
/**
|
|
5
|
+
* Create a prompt using the default builder with all base steps.
|
|
6
|
+
* For custom steps, create your own builder with `createBuilder()`.
|
|
7
|
+
*/
|
|
8
|
+
const prompt = nudge.prompt;
|
|
116
9
|
|
|
117
10
|
//#endregion
|
|
118
|
-
export {
|
|
11
|
+
export { createBuilder, createStep, prompt };
|
|
119
12
|
//# sourceMappingURL=index.mjs.map
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../src/
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["// Main API - what most users need\nimport { nudge, type DefaultPromptFn } from \"./nudge.js\";\n\n/**\n * Create a prompt using the default builder with all base steps.\n * For custom steps, create your own builder with `createBuilder()`.\n */\nexport const prompt: DefaultPromptFn = nudge.prompt;\n\n// For custom builders\nexport { createStep } from \"./create-step.js\";\nexport { createBuilder } from \"./nudge.js\";\n\n// Types users may need\nexport type { StepDefinition } from \"./create-step.js\";\nexport type { Builder, Prompt } from \"./nudge.js\";\n"],"mappings":";;;;;;;AAOA,MAAa,SAA0B,MAAM"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as PromptRegistry, d as PromptBuilderState, f as PromptTest, l as formatStepForAI, o as PromptVariables, p as BaseStep, r as GeneratedPrompt, s as PromptVariants, u as registerPrompts } from "./nudge-D5w_m7nH.cjs";
|
|
2
|
+
export { type BaseStep, type GeneratedPrompt, type PromptBuilderState, type PromptRegistry, type PromptTest, type PromptVariables, type PromptVariants, formatStepForAI, registerPrompts };
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { a as PromptRegistry, d as PromptBuilderState, f as PromptTest, l as formatStepForAI, o as PromptVariables, p as BaseStep, r as GeneratedPrompt, s as PromptVariants, u as registerPrompts } from "./nudge-B-p-8Izg.mjs";
|
|
2
|
+
export { type BaseStep, type GeneratedPrompt, type PromptBuilderState, type PromptRegistry, type PromptTest, type PromptVariables, type PromptVariants, formatStepForAI, registerPrompts };
|