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.
Files changed (55) hide show
  1. package/README.md +31 -8
  2. package/SKILL.md +26 -3
  3. package/dist/{chunk-IXPIBZXT.js → chunk-5OYWNRNC.js} +11 -4
  4. package/dist/{chunk-IXPIBZXT.js.map → chunk-5OYWNRNC.js.map} +1 -1
  5. package/dist/{chunk-KFSP5KN4.js → chunk-BBVVA27J.js} +2 -2
  6. package/dist/{chunk-DGLLQ3FR.js → chunk-E2NXJLS6.js} +3 -3
  7. package/dist/{chunk-5TLHYSP7.js → chunk-E6NPZOJL.js} +2 -2
  8. package/dist/{chunk-QPOHKVY5.js → chunk-UJU5XERR.js} +2 -2
  9. package/dist/{chunk-6XKV4YVK.js → chunk-X73VG645.js} +71 -8
  10. package/dist/chunk-X73VG645.js.map +1 -0
  11. package/dist/cli/index.js +25 -6
  12. package/dist/cli/index.js.map +1 -1
  13. package/dist/index.cjs +89 -12
  14. package/dist/index.cjs.map +1 -1
  15. package/dist/index.d.cts +6 -5
  16. package/dist/index.d.ts +6 -5
  17. package/dist/index.js +16 -9
  18. package/dist/index.js.map +1 -1
  19. package/dist/providers/anthropic.cjs +79 -9
  20. package/dist/providers/anthropic.cjs.map +1 -1
  21. package/dist/providers/anthropic.d.cts +2 -2
  22. package/dist/providers/anthropic.d.ts +2 -2
  23. package/dist/providers/anthropic.js +3 -3
  24. package/dist/providers/gemini.cjs +79 -9
  25. package/dist/providers/gemini.cjs.map +1 -1
  26. package/dist/providers/gemini.d.cts +2 -2
  27. package/dist/providers/gemini.d.ts +2 -2
  28. package/dist/providers/gemini.js +3 -3
  29. package/dist/providers/openai.cjs +79 -9
  30. package/dist/providers/openai.cjs.map +1 -1
  31. package/dist/providers/openai.d.cts +2 -2
  32. package/dist/providers/openai.d.ts +2 -2
  33. package/dist/providers/openai.js +3 -3
  34. package/dist/providers/openrouter.cjs +79 -9
  35. package/dist/providers/openrouter.cjs.map +1 -1
  36. package/dist/providers/openrouter.d.cts +2 -2
  37. package/dist/providers/openrouter.d.ts +2 -2
  38. package/dist/providers/openrouter.js +4 -4
  39. package/dist/{schema-Bgoff-CN.d.cts → schema-DwzYbZba.d.cts} +68 -14
  40. package/dist/{schema-Bgoff-CN.d.ts → schema-DwzYbZba.d.ts} +68 -14
  41. package/dist/testing.cjs +10 -3
  42. package/dist/testing.cjs.map +1 -1
  43. package/dist/testing.d.cts +1 -1
  44. package/dist/testing.d.ts +1 -1
  45. package/dist/testing.js +1 -1
  46. package/dist/{types-7U58bgVW.d.cts → types-C6RG0Si0.d.cts} +12 -5
  47. package/dist/{types-HnZ46u5Q.d.ts → types-fBvo_d4k.d.ts} +12 -5
  48. package/dist/usagetap/index.d.cts +2 -2
  49. package/dist/usagetap/index.d.ts +2 -2
  50. package/package.json +1 -1
  51. package/dist/chunk-6XKV4YVK.js.map +0 -1
  52. /package/dist/{chunk-KFSP5KN4.js.map → chunk-BBVVA27J.js.map} +0 -0
  53. /package/dist/{chunk-DGLLQ3FR.js.map → chunk-E2NXJLS6.js.map} +0 -0
  54. /package/dist/{chunk-5TLHYSP7.js.map → chunk-E6NPZOJL.js.map} +0 -0
  55. /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: import_zod.z.boolean().optional(),
268
- reject_secrets: import_zod.z.boolean().optional()
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 variables = sanitizeContextVariables(resolved, runtime.variables, {
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 sanitizedVariables = sanitizeContextVariables(resolved, options.variables, {
1859
+ const sanitization = sanitizeContextVariables(resolved, options.variables, {
1790
1860
  onContextOverflow: options.onContextOverflow
1791
1861
  });
1792
- const contextSizeWarnings = collectContextSizeWarnings(resolved, sanitizedVariables).map(
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: sanitizedVariables,
1879
+ variables: sanitization.variables,
1803
1880
  history: options.history,
1804
1881
  toolRegistry: options.toolRegistry,
1805
1882
  strict: options.strict