@promptlycms/prompts 0.4.0 → 0.4.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 +33 -8
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -86,6 +86,28 @@ var extractTemplateVariables = (text) => {
|
|
|
86
86
|
}
|
|
87
87
|
return [...vars];
|
|
88
88
|
};
|
|
89
|
+
var extractStaticSegmentVariables = (content) => {
|
|
90
|
+
const vars = /* @__PURE__ */ new Set();
|
|
91
|
+
const varRefRegex = /<span[^>]*\sdata-variable-ref(?:="[^"]*")?[^>]*\sdata-field-path="([^"]+)"[^>]*><\/span>/g;
|
|
92
|
+
const varRefAltRegex = /<span[^>]*\sdata-field-path="([^"]+)"[^>]*\sdata-variable-ref(?:="[^"]*")?[^>]*><\/span>/g;
|
|
93
|
+
const mustacheRegex = /\{\{(\w[\w.]*)\}\}/g;
|
|
94
|
+
for (const match of content.matchAll(varRefRegex)) {
|
|
95
|
+
if (match[1]) {
|
|
96
|
+
vars.add(match[1]);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
for (const match of content.matchAll(varRefAltRegex)) {
|
|
100
|
+
if (match[1]) {
|
|
101
|
+
vars.add(match[1]);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
for (const match of content.matchAll(mustacheRegex)) {
|
|
105
|
+
if (match[1]) {
|
|
106
|
+
vars.add(match[1]);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return [...vars];
|
|
110
|
+
};
|
|
89
111
|
var fetchAllPrompts = async (apiKey, baseUrl) => {
|
|
90
112
|
const url = new URL("/prompts", baseUrl ?? DEFAULT_BASE_URL);
|
|
91
113
|
url.searchParams.set("include_versions", "true");
|
|
@@ -115,14 +137,17 @@ var fetchAllComposers = async (apiKey, baseUrl) => {
|
|
|
115
137
|
var extractComposerVariables = (composer) => {
|
|
116
138
|
const vars = /* @__PURE__ */ new Set();
|
|
117
139
|
for (const segment of composer.segments) {
|
|
118
|
-
if (segment.type
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
140
|
+
if (segment.type === "prompt") {
|
|
141
|
+
if (!segment.userMessage) {
|
|
142
|
+
continue;
|
|
143
|
+
}
|
|
144
|
+
for (const v of extractTemplateVariables(segment.userMessage)) {
|
|
145
|
+
vars.add(v);
|
|
146
|
+
}
|
|
147
|
+
} else if (segment.type === "static") {
|
|
148
|
+
for (const v of extractStaticSegmentVariables(segment.content)) {
|
|
149
|
+
vars.add(v);
|
|
150
|
+
}
|
|
126
151
|
}
|
|
127
152
|
}
|
|
128
153
|
return [...vars];
|