promptopskit 0.3.7 → 0.3.8
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 +31 -8
- package/SKILL.md +26 -3
- package/dist/{chunk-IXPIBZXT.js → chunk-5OYWNRNC.js} +11 -4
- package/dist/{chunk-IXPIBZXT.js.map → chunk-5OYWNRNC.js.map} +1 -1
- package/dist/{chunk-KFSP5KN4.js → chunk-BBVVA27J.js} +2 -2
- package/dist/{chunk-DGLLQ3FR.js → chunk-E2NXJLS6.js} +3 -3
- package/dist/{chunk-5TLHYSP7.js → chunk-E6NPZOJL.js} +2 -2
- package/dist/{chunk-QPOHKVY5.js → chunk-UJU5XERR.js} +2 -2
- package/dist/{chunk-6XKV4YVK.js → chunk-X73VG645.js} +71 -8
- package/dist/chunk-X73VG645.js.map +1 -0
- package/dist/cli/index.js +25 -6
- package/dist/cli/index.js.map +1 -1
- package/dist/index.cjs +89 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -5
- package/dist/index.d.ts +6 -5
- package/dist/index.js +16 -9
- package/dist/index.js.map +1 -1
- package/dist/providers/anthropic.cjs +79 -9
- package/dist/providers/anthropic.cjs.map +1 -1
- package/dist/providers/anthropic.d.cts +2 -2
- package/dist/providers/anthropic.d.ts +2 -2
- package/dist/providers/anthropic.js +3 -3
- package/dist/providers/gemini.cjs +79 -9
- package/dist/providers/gemini.cjs.map +1 -1
- package/dist/providers/gemini.d.cts +2 -2
- package/dist/providers/gemini.d.ts +2 -2
- package/dist/providers/gemini.js +3 -3
- package/dist/providers/openai.cjs +79 -9
- package/dist/providers/openai.cjs.map +1 -1
- package/dist/providers/openai.d.cts +2 -2
- package/dist/providers/openai.d.ts +2 -2
- package/dist/providers/openai.js +3 -3
- package/dist/providers/openrouter.cjs +79 -9
- package/dist/providers/openrouter.cjs.map +1 -1
- package/dist/providers/openrouter.d.cts +2 -2
- package/dist/providers/openrouter.d.ts +2 -2
- package/dist/providers/openrouter.js +4 -4
- package/dist/{schema-Bgoff-CN.d.cts → schema-DwzYbZba.d.cts} +68 -14
- package/dist/{schema-Bgoff-CN.d.ts → schema-DwzYbZba.d.ts} +68 -14
- package/dist/testing.cjs +10 -3
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.d.cts +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/dist/{types-7U58bgVW.d.cts → types-C6RG0Si0.d.cts} +12 -5
- package/dist/{types-HnZ46u5Q.d.ts → types-fBvo_d4k.d.ts} +12 -5
- package/dist/usagetap/index.d.cts +2 -2
- package/dist/usagetap/index.d.ts +2 -2
- package/package.json +1 -1
- package/dist/chunk-6XKV4YVK.js.map +0 -1
- /package/dist/{chunk-KFSP5KN4.js.map → chunk-BBVVA27J.js.map} +0 -0
- /package/dist/{chunk-DGLLQ3FR.js.map → chunk-E2NXJLS6.js.map} +0 -0
- /package/dist/{chunk-5TLHYSP7.js.map → chunk-E6NPZOJL.js.map} +0 -0
- /package/dist/{chunk-QPOHKVY5.js.map → chunk-UJU5XERR.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -255,7 +255,14 @@ var ContextRegexSchema = import_zod.z.union([
|
|
|
255
255
|
import_zod.z.string(),
|
|
256
256
|
import_zod.z.object({
|
|
257
257
|
pattern: import_zod.z.string(),
|
|
258
|
-
flags: import_zod.z.string().optional()
|
|
258
|
+
flags: import_zod.z.string().optional(),
|
|
259
|
+
return_message: import_zod.z.string().optional()
|
|
260
|
+
})
|
|
261
|
+
]);
|
|
262
|
+
var ContextBuiltInValidatorSchema = import_zod.z.union([
|
|
263
|
+
import_zod.z.boolean(),
|
|
264
|
+
import_zod.z.object({
|
|
265
|
+
return_message: import_zod.z.string().optional()
|
|
259
266
|
})
|
|
260
267
|
]);
|
|
261
268
|
var ContextInputDefinitionObjectSchema = import_zod.z.object({
|
|
@@ -264,8 +271,8 @@ var ContextInputDefinitionObjectSchema = import_zod.z.object({
|
|
|
264
271
|
trim: import_zod.z.union([import_zod.z.boolean(), import_zod.z.enum(["start", "end", "both"])]).optional(),
|
|
265
272
|
allow_regex: ContextRegexSchema.optional(),
|
|
266
273
|
deny_regex: ContextRegexSchema.optional(),
|
|
267
|
-
non_empty:
|
|
268
|
-
reject_secrets:
|
|
274
|
+
non_empty: ContextBuiltInValidatorSchema.optional(),
|
|
275
|
+
reject_secrets: ContextBuiltInValidatorSchema.optional()
|
|
269
276
|
});
|
|
270
277
|
var ContextInputDefinitionSchema = import_zod.z.union([
|
|
271
278
|
import_zod.z.string(),
|
|
@@ -628,8 +635,8 @@ function normalizeContextInput(input) {
|
|
|
628
635
|
trim: input.trim,
|
|
629
636
|
allow_regex: normalizeContextRegex(input.allow_regex),
|
|
630
637
|
deny_regex: normalizeContextRegex(input.deny_regex),
|
|
631
|
-
non_empty: input.non_empty,
|
|
632
|
-
reject_secrets: input.reject_secrets
|
|
638
|
+
non_empty: normalizeBuiltInValidator(input.non_empty),
|
|
639
|
+
reject_secrets: normalizeBuiltInValidator(input.reject_secrets)
|
|
633
640
|
};
|
|
634
641
|
}
|
|
635
642
|
function normalizeContextRegex(value) {
|
|
@@ -655,7 +662,19 @@ function normalizeContextRegex(value) {
|
|
|
655
662
|
return {
|
|
656
663
|
pattern: value.pattern,
|
|
657
664
|
flags: value.flags ?? "",
|
|
658
|
-
raw: JSON.stringify(value)
|
|
665
|
+
raw: JSON.stringify(value),
|
|
666
|
+
returnMessage: value.return_message
|
|
667
|
+
};
|
|
668
|
+
}
|
|
669
|
+
function normalizeBuiltInValidator(value) {
|
|
670
|
+
if (value === void 0 || value === false) {
|
|
671
|
+
return void 0;
|
|
672
|
+
}
|
|
673
|
+
if (value === true) {
|
|
674
|
+
return {};
|
|
675
|
+
}
|
|
676
|
+
return {
|
|
677
|
+
returnMessage: value.return_message
|
|
659
678
|
};
|
|
660
679
|
}
|
|
661
680
|
function parseRegexLiteral(value) {
|
|
@@ -787,6 +806,17 @@ function sanitizeContextVariables(asset, variables = {}, options = {}) {
|
|
|
787
806
|
field: "allow_regex"
|
|
788
807
|
});
|
|
789
808
|
if (!matcher.test(candidate2)) {
|
|
809
|
+
if (input.allow_regex.returnMessage) {
|
|
810
|
+
return {
|
|
811
|
+
variables: sanitized,
|
|
812
|
+
shortCircuit: {
|
|
813
|
+
returnMessage: input.allow_regex.returnMessage,
|
|
814
|
+
code: "POK031",
|
|
815
|
+
variable: input.name,
|
|
816
|
+
field: "allow_regex"
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
}
|
|
790
820
|
throw new Error(
|
|
791
821
|
`POK031: Context variable "${input.name}" failed allow_regex validation for prompt "${asset.id}".`
|
|
792
822
|
);
|
|
@@ -800,12 +830,34 @@ function sanitizeContextVariables(asset, variables = {}, options = {}) {
|
|
|
800
830
|
field: "deny_regex"
|
|
801
831
|
});
|
|
802
832
|
if (matcher.test(candidate2)) {
|
|
833
|
+
if (input.deny_regex.returnMessage) {
|
|
834
|
+
return {
|
|
835
|
+
variables: sanitized,
|
|
836
|
+
shortCircuit: {
|
|
837
|
+
returnMessage: input.deny_regex.returnMessage,
|
|
838
|
+
code: "POK032",
|
|
839
|
+
variable: input.name,
|
|
840
|
+
field: "deny_regex"
|
|
841
|
+
}
|
|
842
|
+
};
|
|
843
|
+
}
|
|
803
844
|
throw new Error(
|
|
804
845
|
`POK032: Context variable "${input.name}" matched deny_regex for prompt "${asset.id}".`
|
|
805
846
|
);
|
|
806
847
|
}
|
|
807
848
|
}
|
|
808
849
|
if (input.non_empty && candidate.trim().length === 0) {
|
|
850
|
+
if (input.non_empty.returnMessage) {
|
|
851
|
+
return {
|
|
852
|
+
variables: sanitized,
|
|
853
|
+
shortCircuit: {
|
|
854
|
+
returnMessage: input.non_empty.returnMessage,
|
|
855
|
+
code: "POK033",
|
|
856
|
+
variable: input.name,
|
|
857
|
+
field: "non_empty"
|
|
858
|
+
}
|
|
859
|
+
};
|
|
860
|
+
}
|
|
809
861
|
throw new Error(
|
|
810
862
|
`POK033: Context variable "${input.name}" failed non_empty validation for prompt "${asset.id}".`
|
|
811
863
|
);
|
|
@@ -817,13 +869,24 @@ function sanitizeContextVariables(asset, variables = {}, options = {}) {
|
|
|
817
869
|
field: "reject_secrets"
|
|
818
870
|
});
|
|
819
871
|
if (matcher.test(candidate)) {
|
|
872
|
+
if (input.reject_secrets.returnMessage) {
|
|
873
|
+
return {
|
|
874
|
+
variables: sanitized,
|
|
875
|
+
shortCircuit: {
|
|
876
|
+
returnMessage: input.reject_secrets.returnMessage,
|
|
877
|
+
code: "POK034",
|
|
878
|
+
variable: input.name,
|
|
879
|
+
field: "reject_secrets"
|
|
880
|
+
}
|
|
881
|
+
};
|
|
882
|
+
}
|
|
820
883
|
throw new Error(
|
|
821
884
|
`POK034: Context variable "${input.name}" matched reject_secrets validation for prompt "${asset.id}".`
|
|
822
885
|
);
|
|
823
886
|
}
|
|
824
887
|
}
|
|
825
888
|
}
|
|
826
|
-
return sanitized;
|
|
889
|
+
return { variables: sanitized };
|
|
827
890
|
}
|
|
828
891
|
function measureContextValueSize(value) {
|
|
829
892
|
return textEncoder.encode(value).length;
|
|
@@ -873,12 +936,19 @@ function withPromptInputSupport(adapter) {
|
|
|
873
936
|
};
|
|
874
937
|
const renderPrompt2 = async (input, runtime) => {
|
|
875
938
|
const resolved = await resolveProviderPromptInput(input, runtime);
|
|
876
|
-
const
|
|
939
|
+
const sanitization = sanitizeContextVariables(resolved, runtime.variables, {
|
|
877
940
|
onContextOverflow: runtime.onContextOverflow
|
|
878
941
|
});
|
|
942
|
+
if (sanitization.shortCircuit) {
|
|
943
|
+
return {
|
|
944
|
+
provider: adapter.name,
|
|
945
|
+
model: resolved.model ?? "",
|
|
946
|
+
returnMessage: sanitization.shortCircuit.returnMessage
|
|
947
|
+
};
|
|
948
|
+
}
|
|
879
949
|
return adapter.render(resolved, {
|
|
880
950
|
...runtime,
|
|
881
|
-
variables
|
|
951
|
+
variables: sanitization.variables
|
|
882
952
|
});
|
|
883
953
|
};
|
|
884
954
|
return {
|
|
@@ -1786,10 +1856,17 @@ var PromptOpsKit = class {
|
|
|
1786
1856
|
` + validation.errors.map((e) => ` - ${e}`).join("\n")
|
|
1787
1857
|
);
|
|
1788
1858
|
}
|
|
1789
|
-
const
|
|
1859
|
+
const sanitization = sanitizeContextVariables(resolved, options.variables, {
|
|
1790
1860
|
onContextOverflow: options.onContextOverflow
|
|
1791
1861
|
});
|
|
1792
|
-
|
|
1862
|
+
if (sanitization.shortCircuit) {
|
|
1863
|
+
return {
|
|
1864
|
+
resolved,
|
|
1865
|
+
returnMessage: sanitization.shortCircuit.returnMessage,
|
|
1866
|
+
warnings: validation.warnings
|
|
1867
|
+
};
|
|
1868
|
+
}
|
|
1869
|
+
const contextSizeWarnings = collectContextSizeWarnings(resolved, sanitization.variables).map(
|
|
1793
1870
|
(warning) => formatContextSizeWarning(resolved, warning)
|
|
1794
1871
|
);
|
|
1795
1872
|
const contextWarningPolicy = this.config.warnings?.contextSize;
|
|
@@ -1799,7 +1876,7 @@ var PromptOpsKit = class {
|
|
|
1799
1876
|
}
|
|
1800
1877
|
}
|
|
1801
1878
|
const request = adapter.render(resolved, {
|
|
1802
|
-
variables:
|
|
1879
|
+
variables: sanitization.variables,
|
|
1803
1880
|
history: options.history,
|
|
1804
1881
|
toolRegistry: options.toolRegistry,
|
|
1805
1882
|
strict: options.strict
|