promptopskit 0.3.7 → 0.3.9

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 (69) hide show
  1. package/README.md +37 -11
  2. package/SKILL.md +26 -3
  3. package/dist/{chunk-IXPIBZXT.js → chunk-4LEPCCSA.js} +60 -8
  4. package/dist/chunk-4LEPCCSA.js.map +1 -0
  5. package/dist/{chunk-5TLHYSP7.js → chunk-AN3OR7YC.js} +26 -3
  6. package/dist/chunk-AN3OR7YC.js.map +1 -0
  7. package/dist/{chunk-QPOHKVY5.js → chunk-LMURMZUA.js} +22 -3
  8. package/dist/chunk-LMURMZUA.js.map +1 -0
  9. package/dist/{chunk-KFSP5KN4.js → chunk-O6RQZYS4.js} +49 -7
  10. package/dist/chunk-O6RQZYS4.js.map +1 -0
  11. package/dist/{chunk-6XKV4YVK.js → chunk-V7QY7MRM.js} +85 -8
  12. package/dist/chunk-V7QY7MRM.js.map +1 -0
  13. package/dist/{chunk-DGLLQ3FR.js → chunk-YAD6COQX.js} +3 -3
  14. package/dist/chunk-YNIAA4ZJ.js +111 -0
  15. package/dist/chunk-YNIAA4ZJ.js.map +1 -0
  16. package/dist/cli/index.js +95 -11
  17. package/dist/cli/index.js.map +1 -1
  18. package/dist/index.cjs +354 -26
  19. package/dist/index.cjs.map +1 -1
  20. package/dist/index.d.cts +9 -5
  21. package/dist/index.d.ts +9 -5
  22. package/dist/index.js +28 -12
  23. package/dist/index.js.map +1 -1
  24. package/dist/providers/anthropic.cjs +189 -18
  25. package/dist/providers/anthropic.cjs.map +1 -1
  26. package/dist/providers/anthropic.d.cts +2 -2
  27. package/dist/providers/anthropic.d.ts +2 -2
  28. package/dist/providers/anthropic.js +3 -3
  29. package/dist/providers/gemini.cjs +166 -14
  30. package/dist/providers/gemini.cjs.map +1 -1
  31. package/dist/providers/gemini.d.cts +2 -2
  32. package/dist/providers/gemini.d.ts +2 -2
  33. package/dist/providers/gemini.js +3 -3
  34. package/dist/providers/openai-responses.cjs +1059 -0
  35. package/dist/providers/openai-responses.cjs.map +1 -0
  36. package/dist/providers/openai-responses.d.cts +11 -0
  37. package/dist/providers/openai-responses.d.ts +11 -0
  38. package/dist/providers/openai-responses.js +9 -0
  39. package/dist/providers/openai-responses.js.map +1 -0
  40. package/dist/providers/openai.cjs +162 -14
  41. package/dist/providers/openai.cjs.map +1 -1
  42. package/dist/providers/openai.d.cts +2 -2
  43. package/dist/providers/openai.d.ts +2 -2
  44. package/dist/providers/openai.js +3 -3
  45. package/dist/providers/openrouter.cjs +162 -14
  46. package/dist/providers/openrouter.cjs.map +1 -1
  47. package/dist/providers/openrouter.d.cts +2 -2
  48. package/dist/providers/openrouter.d.ts +2 -2
  49. package/dist/providers/openrouter.js +4 -4
  50. package/dist/schema-BKkg93rL.d.cts +1923 -0
  51. package/dist/schema-BKkg93rL.d.ts +1923 -0
  52. package/dist/testing.cjs +59 -7
  53. package/dist/testing.cjs.map +1 -1
  54. package/dist/testing.d.cts +1 -1
  55. package/dist/testing.d.ts +1 -1
  56. package/dist/testing.js +1 -1
  57. package/dist/{types-7U58bgVW.d.cts → types-7cC17GWp.d.cts} +24 -5
  58. package/dist/{types-HnZ46u5Q.d.ts → types-CsQ8tON_.d.ts} +24 -5
  59. package/dist/usagetap/index.d.cts +2 -2
  60. package/dist/usagetap/index.d.ts +2 -2
  61. package/package.json +11 -1
  62. package/dist/chunk-5TLHYSP7.js.map +0 -1
  63. package/dist/chunk-6XKV4YVK.js.map +0 -1
  64. package/dist/chunk-IXPIBZXT.js.map +0 -1
  65. package/dist/chunk-KFSP5KN4.js.map +0 -1
  66. package/dist/chunk-QPOHKVY5.js.map +0 -1
  67. package/dist/schema-Bgoff-CN.d.cts +0 -805
  68. package/dist/schema-Bgoff-CN.d.ts +0 -805
  69. /package/dist/{chunk-DGLLQ3FR.js.map → chunk-YAD6COQX.js.map} +0 -0
@@ -103,6 +103,20 @@ function mergeOverride(base, override) {
103
103
  if (override.response !== void 0) {
104
104
  result.response = { ...result.response, ...override.response };
105
105
  }
106
+ if (override.provider_options !== void 0) {
107
+ result.provider_options = {
108
+ ...result.provider_options,
109
+ ...override.provider_options,
110
+ anthropic: {
111
+ ...result.provider_options?.anthropic,
112
+ ...override.provider_options.anthropic
113
+ },
114
+ gemini: {
115
+ ...result.provider_options?.gemini,
116
+ ...override.provider_options.gemini
117
+ }
118
+ };
119
+ }
106
120
  return result;
107
121
  }
108
122
 
@@ -205,7 +219,47 @@ var SamplingSchema = import_zod.z.object({
205
219
  });
206
220
  var ResponseSchema = import_zod.z.object({
207
221
  format: import_zod.z.enum(["text", "json", "markdown"]).optional(),
208
- stream: import_zod.z.boolean().optional()
222
+ stream: import_zod.z.boolean().optional(),
223
+ schema: import_zod.z.record(import_zod.z.unknown()).optional(),
224
+ schema_name: import_zod.z.string().optional(),
225
+ schema_strict: import_zod.z.boolean().optional()
226
+ });
227
+ var AnthropicProviderOptionsSchema = import_zod.z.object({
228
+ top_k: import_zod.z.number().int().min(0).optional(),
229
+ tool_choice: import_zod.z.record(import_zod.z.unknown()).optional()
230
+ });
231
+ var GeminiProviderOptionsSchema = import_zod.z.object({
232
+ candidate_count: import_zod.z.number().int().positive().optional(),
233
+ top_k: import_zod.z.number().int().min(0).optional(),
234
+ seed: import_zod.z.number().int().optional(),
235
+ response_schema: import_zod.z.record(import_zod.z.unknown()).optional(),
236
+ response_modalities: import_zod.z.array(import_zod.z.string()).optional(),
237
+ thinking_budget_tokens: import_zod.z.number().int().positive().optional()
238
+ });
239
+ var ProviderOptionsSchema = import_zod.z.object({
240
+ anthropic: AnthropicProviderOptionsSchema.optional(),
241
+ gemini: GeminiProviderOptionsSchema.optional()
242
+ });
243
+ var OpenAICacheSchema = import_zod.z.object({
244
+ prompt_cache_key: import_zod.z.string().min(1).optional(),
245
+ retention: import_zod.z.enum(["in_memory", "24h"]).optional()
246
+ });
247
+ var AnthropicCacheSchema = import_zod.z.object({
248
+ mode: import_zod.z.enum(["automatic", "explicit"]).optional(),
249
+ type: import_zod.z.literal("ephemeral").optional(),
250
+ ttl: import_zod.z.enum(["5m", "1h"]).optional(),
251
+ cache_system_instructions: import_zod.z.boolean().optional(),
252
+ cache_tools: import_zod.z.boolean().optional(),
253
+ cache_prompt_template: import_zod.z.boolean().optional()
254
+ });
255
+ var GeminiCacheSchema = import_zod.z.object({
256
+ cached_content: import_zod.z.string().min(1).optional()
257
+ });
258
+ var CacheSchema = import_zod.z.object({
259
+ openai: OpenAICacheSchema.optional(),
260
+ anthropic: AnthropicCacheSchema.optional(),
261
+ gemini: GeminiCacheSchema.optional(),
262
+ google: GeminiCacheSchema.optional()
209
263
  });
210
264
  var HistorySchema = import_zod.z.object({
211
265
  max_items: import_zod.z.number().int().positive().optional()
@@ -214,7 +268,14 @@ var ContextRegexSchema = import_zod.z.union([
214
268
  import_zod.z.string(),
215
269
  import_zod.z.object({
216
270
  pattern: import_zod.z.string(),
217
- flags: import_zod.z.string().optional()
271
+ flags: import_zod.z.string().optional(),
272
+ return_message: import_zod.z.string().optional()
273
+ })
274
+ ]);
275
+ var ContextBuiltInValidatorSchema = import_zod.z.union([
276
+ import_zod.z.boolean(),
277
+ import_zod.z.object({
278
+ return_message: import_zod.z.string().optional()
218
279
  })
219
280
  ]);
220
281
  var ContextInputDefinitionObjectSchema = import_zod.z.object({
@@ -223,8 +284,8 @@ var ContextInputDefinitionObjectSchema = import_zod.z.object({
223
284
  trim: import_zod.z.union([import_zod.z.boolean(), import_zod.z.enum(["start", "end", "both"])]).optional(),
224
285
  allow_regex: ContextRegexSchema.optional(),
225
286
  deny_regex: ContextRegexSchema.optional(),
226
- non_empty: import_zod.z.boolean().optional(),
227
- reject_secrets: import_zod.z.boolean().optional()
287
+ non_empty: ContextBuiltInValidatorSchema.optional(),
288
+ reject_secrets: ContextBuiltInValidatorSchema.optional()
228
289
  });
229
290
  var ContextInputDefinitionSchema = import_zod.z.union([
230
291
  import_zod.z.string(),
@@ -249,7 +310,9 @@ var PromptAssetOverridesSchema = import_zod.z.object({
249
310
  reasoning: ReasoningSchema.optional(),
250
311
  sampling: SamplingSchema.optional(),
251
312
  response: ResponseSchema.optional(),
252
- tools: import_zod.z.array(ToolRefSchema).optional()
313
+ cache: CacheSchema.optional(),
314
+ tools: import_zod.z.array(ToolRefSchema).optional(),
315
+ provider_options: ProviderOptionsSchema.optional()
253
316
  });
254
317
  var SourceSchema = import_zod.z.object({
255
318
  file_path: import_zod.z.string().optional(),
@@ -261,8 +324,9 @@ var SectionsSchema = import_zod.z.object({
261
324
  notes: import_zod.z.string().optional()
262
325
  });
263
326
  var PromptDefaultsSchema = import_zod.z.object({
264
- provider: import_zod.z.enum(["openai", "anthropic", "google", "gemini", "openrouter", "any"]).optional(),
327
+ provider: import_zod.z.enum(["openai", "openai-responses", "anthropic", "google", "gemini", "openrouter", "any"]).optional(),
265
328
  model: import_zod.z.string().optional(),
329
+ cache: CacheSchema.optional(),
266
330
  metadata: MetadataSchema.optional(),
267
331
  sections: import_zod.z.object({
268
332
  system_instructions: import_zod.z.string().optional()
@@ -272,13 +336,15 @@ var PromptAssetSchema = import_zod.z.object({
272
336
  id: import_zod.z.string(),
273
337
  schema_version: import_zod.z.number().int().positive().default(1),
274
338
  description: import_zod.z.string().optional(),
275
- provider: import_zod.z.enum(["openai", "anthropic", "google", "gemini", "openrouter", "any"]).optional(),
339
+ provider: import_zod.z.enum(["openai", "openai-responses", "anthropic", "google", "gemini", "openrouter", "any"]).optional(),
276
340
  model: import_zod.z.string().optional(),
277
341
  fallback_models: import_zod.z.array(import_zod.z.string()).optional(),
278
342
  reasoning: ReasoningSchema.optional(),
279
343
  sampling: SamplingSchema.optional(),
280
344
  response: ResponseSchema.optional(),
345
+ cache: CacheSchema.optional(),
281
346
  tools: import_zod.z.array(ToolRefSchema).optional(),
347
+ provider_options: ProviderOptionsSchema.optional(),
282
348
  mcp: MCPSchema.optional(),
283
349
  context: ContextSchema.optional(),
284
350
  includes: import_zod.z.array(import_zod.z.string()).optional(),
@@ -584,8 +650,8 @@ function normalizeContextInput(input) {
584
650
  trim: input.trim,
585
651
  allow_regex: normalizeContextRegex(input.allow_regex),
586
652
  deny_regex: normalizeContextRegex(input.deny_regex),
587
- non_empty: input.non_empty,
588
- reject_secrets: input.reject_secrets
653
+ non_empty: normalizeBuiltInValidator(input.non_empty),
654
+ reject_secrets: normalizeBuiltInValidator(input.reject_secrets)
589
655
  };
590
656
  }
591
657
  function normalizeContextRegex(value) {
@@ -611,7 +677,19 @@ function normalizeContextRegex(value) {
611
677
  return {
612
678
  pattern: value.pattern,
613
679
  flags: value.flags ?? "",
614
- raw: JSON.stringify(value)
680
+ raw: JSON.stringify(value),
681
+ returnMessage: value.return_message
682
+ };
683
+ }
684
+ function normalizeBuiltInValidator(value) {
685
+ if (value === void 0 || value === false) {
686
+ return void 0;
687
+ }
688
+ if (value === true) {
689
+ return {};
690
+ }
691
+ return {
692
+ returnMessage: value.return_message
615
693
  };
616
694
  }
617
695
  function parseRegexLiteral(value) {
@@ -743,6 +821,17 @@ function sanitizeContextVariables(asset, variables = {}, options = {}) {
743
821
  field: "allow_regex"
744
822
  });
745
823
  if (!matcher.test(candidate2)) {
824
+ if (input.allow_regex.returnMessage) {
825
+ return {
826
+ variables: sanitized,
827
+ shortCircuit: {
828
+ returnMessage: input.allow_regex.returnMessage,
829
+ code: "POK031",
830
+ variable: input.name,
831
+ field: "allow_regex"
832
+ }
833
+ };
834
+ }
746
835
  throw new Error(
747
836
  `POK031: Context variable "${input.name}" failed allow_regex validation for prompt "${asset.id}".`
748
837
  );
@@ -756,12 +845,34 @@ function sanitizeContextVariables(asset, variables = {}, options = {}) {
756
845
  field: "deny_regex"
757
846
  });
758
847
  if (matcher.test(candidate2)) {
848
+ if (input.deny_regex.returnMessage) {
849
+ return {
850
+ variables: sanitized,
851
+ shortCircuit: {
852
+ returnMessage: input.deny_regex.returnMessage,
853
+ code: "POK032",
854
+ variable: input.name,
855
+ field: "deny_regex"
856
+ }
857
+ };
858
+ }
759
859
  throw new Error(
760
860
  `POK032: Context variable "${input.name}" matched deny_regex for prompt "${asset.id}".`
761
861
  );
762
862
  }
763
863
  }
764
864
  if (input.non_empty && candidate.trim().length === 0) {
865
+ if (input.non_empty.returnMessage) {
866
+ return {
867
+ variables: sanitized,
868
+ shortCircuit: {
869
+ returnMessage: input.non_empty.returnMessage,
870
+ code: "POK033",
871
+ variable: input.name,
872
+ field: "non_empty"
873
+ }
874
+ };
875
+ }
765
876
  throw new Error(
766
877
  `POK033: Context variable "${input.name}" failed non_empty validation for prompt "${asset.id}".`
767
878
  );
@@ -773,13 +884,24 @@ function sanitizeContextVariables(asset, variables = {}, options = {}) {
773
884
  field: "reject_secrets"
774
885
  });
775
886
  if (matcher.test(candidate)) {
887
+ if (input.reject_secrets.returnMessage) {
888
+ return {
889
+ variables: sanitized,
890
+ shortCircuit: {
891
+ returnMessage: input.reject_secrets.returnMessage,
892
+ code: "POK034",
893
+ variable: input.name,
894
+ field: "reject_secrets"
895
+ }
896
+ };
897
+ }
776
898
  throw new Error(
777
899
  `POK034: Context variable "${input.name}" matched reject_secrets validation for prompt "${asset.id}".`
778
900
  );
779
901
  }
780
902
  }
781
903
  }
782
- return sanitized;
904
+ return { variables: sanitized };
783
905
  }
784
906
  function measureContextValueSize(value) {
785
907
  return textEncoder.encode(value).length;
@@ -808,12 +930,19 @@ function withPromptInputSupport(adapter) {
808
930
  };
809
931
  const renderPrompt = async (input, runtime) => {
810
932
  const resolved = await resolveProviderPromptInput(input, runtime);
811
- const variables = sanitizeContextVariables(resolved, runtime.variables, {
933
+ const sanitization = sanitizeContextVariables(resolved, runtime.variables, {
812
934
  onContextOverflow: runtime.onContextOverflow
813
935
  });
936
+ if (sanitization.shortCircuit) {
937
+ return {
938
+ provider: adapter.name,
939
+ model: resolved.model ?? "",
940
+ returnMessage: sanitization.shortCircuit.returnMessage
941
+ };
942
+ }
814
943
  return adapter.render(resolved, {
815
944
  ...runtime,
816
- variables
945
+ variables: sanitization.variables
817
946
  });
818
947
  };
819
948
  return {
@@ -830,6 +959,8 @@ var geminiAdapter = withPromptInputSupport({
830
959
  const resolvedAsset = resolveAssetForProvider(asset, runtime);
831
960
  const errors = [];
832
961
  const warnings = [];
962
+ const geminiCache = resolvedAsset.cache?.gemini?.cached_content;
963
+ const googleCache = resolvedAsset.cache?.google?.cached_content;
833
964
  if (!resolvedAsset.model) {
834
965
  errors.push("Gemini adapter requires a model to be specified.");
835
966
  }
@@ -839,6 +970,12 @@ var geminiAdapter = withPromptInputSupport({
839
970
  if (resolvedAsset.sampling?.presence_penalty !== void 0) {
840
971
  warnings.push("Gemini does not support presence_penalty. It will be ignored.");
841
972
  }
973
+ if (geminiCache && googleCache && geminiCache !== googleCache) {
974
+ warnings.push("Both cache.gemini.cached_content and cache.google.cached_content are set. Gemini uses cache.gemini.cached_content.");
975
+ }
976
+ if (resolvedAsset.response?.stream !== void 0) {
977
+ warnings.push("Gemini streaming is endpoint-based (streamGenerateContent), not body-based. response.stream will be ignored.");
978
+ }
842
979
  return { valid: errors.length === 0, errors, warnings };
843
980
  },
844
981
  render(asset, runtime) {
@@ -865,20 +1002,32 @@ var geminiAdapter = withPromptInputSupport({
865
1002
  const body = {
866
1003
  contents
867
1004
  };
1005
+ const geminiCacheConfig = resolvedAsset.cache?.gemini ?? resolvedAsset.cache?.google;
868
1006
  if (sections.system_instructions) {
869
1007
  body.systemInstruction = {
870
1008
  parts: [{ text: sections.system_instructions }]
871
1009
  };
872
1010
  }
873
1011
  const generationConfig = {};
1012
+ const geminiOptions = resolvedAsset.provider_options?.gemini;
874
1013
  if (resolvedAsset.sampling?.temperature !== void 0) generationConfig.temperature = resolvedAsset.sampling.temperature;
875
1014
  if (resolvedAsset.sampling?.top_p !== void 0) generationConfig.topP = resolvedAsset.sampling.top_p;
876
1015
  if (resolvedAsset.sampling?.max_output_tokens !== void 0) generationConfig.maxOutputTokens = resolvedAsset.sampling.max_output_tokens;
877
1016
  if (resolvedAsset.sampling?.stop !== void 0) generationConfig.stopSequences = resolvedAsset.sampling.stop;
1017
+ if (geminiOptions?.candidate_count !== void 0) generationConfig.candidateCount = geminiOptions.candidate_count;
1018
+ if (geminiOptions?.top_k !== void 0) generationConfig.topK = geminiOptions.top_k;
1019
+ if (geminiOptions?.seed !== void 0) generationConfig.seed = geminiOptions.seed;
1020
+ if (geminiOptions?.response_schema !== void 0) generationConfig.responseSchema = geminiOptions.response_schema;
1021
+ if (geminiOptions?.response_modalities !== void 0) generationConfig.responseModalities = geminiOptions.response_modalities;
1022
+ if (resolvedAsset.response?.schema !== void 0) generationConfig.responseSchema = resolvedAsset.response.schema;
878
1023
  if (resolvedAsset.response?.format === "json") {
879
1024
  generationConfig.responseMimeType = "application/json";
880
1025
  }
881
- if (resolvedAsset.reasoning?.effort) {
1026
+ if (geminiOptions?.thinking_budget_tokens !== void 0) {
1027
+ body.thinkingConfig = {
1028
+ thinkingBudget: geminiOptions.thinking_budget_tokens
1029
+ };
1030
+ } else if (resolvedAsset.reasoning?.effort) {
882
1031
  body.thinkingConfig = {
883
1032
  thinkingBudget: resolvedAsset.reasoning.effort === "high" ? 8192 : resolvedAsset.reasoning.effort === "medium" ? 4096 : 1024
884
1033
  };
@@ -886,6 +1035,9 @@ var geminiAdapter = withPromptInputSupport({
886
1035
  if (Object.keys(generationConfig).length > 0) {
887
1036
  body.generationConfig = generationConfig;
888
1037
  }
1038
+ if (geminiCacheConfig?.cached_content) {
1039
+ body.cachedContent = geminiCacheConfig.cached_content;
1040
+ }
889
1041
  if (resolvedAsset.tools && resolvedAsset.tools.length > 0) {
890
1042
  const functionDeclarations = resolvedAsset.tools.map((tool) => {
891
1043
  if (typeof tool === "string") {