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 {
@@ -842,6 +971,12 @@ var anthropicAdapter = withPromptInputSupport({
842
971
  if (resolvedAsset.reasoning?.effort !== void 0) {
843
972
  warnings.push("Anthropic uses budget_tokens for thinking, not effort. effort will be mapped approximately.");
844
973
  }
974
+ if (resolvedAsset.response?.schema !== void 0) {
975
+ warnings.push("Anthropic does not support response.schema structured output in this adapter. It will be ignored.");
976
+ }
977
+ if (resolvedAsset.provider_options?.anthropic?.top_k !== void 0 && resolvedAsset.provider_options.anthropic.top_k < 0) {
978
+ errors.push("Anthropic provider_options.top_k must be >= 0.");
979
+ }
845
980
  return { valid: errors.length === 0, errors, warnings };
846
981
  },
847
982
  render(asset, runtime) {
@@ -851,20 +986,38 @@ var anthropicAdapter = withPromptInputSupport({
851
986
  strict: runtime.strict
852
987
  });
853
988
  const messages = [];
989
+ const anthropicCacheConfig = resolvedAsset.cache?.anthropic;
990
+ const cacheType = anthropicCacheConfig?.type ?? "ephemeral";
991
+ const cacheControl = anthropicCacheConfig ? {
992
+ type: cacheType,
993
+ ...anthropicCacheConfig.ttl ? { ttl: anthropicCacheConfig.ttl } : {}
994
+ } : void 0;
995
+ const cacheMode = anthropicCacheConfig?.mode ?? "automatic";
854
996
  if (runtime.history) {
855
997
  for (const msg of runtime.history) {
856
998
  messages.push({ role: msg.role, content: msg.content });
857
999
  }
858
1000
  }
859
1001
  if (sections.prompt_template) {
860
- messages.push({ role: "user", content: sections.prompt_template });
1002
+ if (cacheControl && cacheMode === "explicit" && anthropicCacheConfig?.cache_prompt_template) {
1003
+ messages.push({
1004
+ role: "user",
1005
+ content: [{ type: "text", text: sections.prompt_template, cache_control: cacheControl }]
1006
+ });
1007
+ } else {
1008
+ messages.push({ role: "user", content: sections.prompt_template });
1009
+ }
861
1010
  }
862
1011
  const body = {
863
1012
  model: resolvedAsset.model,
864
1013
  messages
865
1014
  };
866
1015
  if (sections.system_instructions) {
867
- body.system = sections.system_instructions;
1016
+ if (cacheControl && cacheMode === "explicit" && anthropicCacheConfig?.cache_system_instructions !== false) {
1017
+ body.system = [{ type: "text", text: sections.system_instructions, cache_control: cacheControl }];
1018
+ } else {
1019
+ body.system = sections.system_instructions;
1020
+ }
868
1021
  }
869
1022
  if (resolvedAsset.sampling?.temperature !== void 0) body.temperature = resolvedAsset.sampling.temperature;
870
1023
  if (resolvedAsset.sampling?.top_p !== void 0) body.top_p = resolvedAsset.sampling.top_p;
@@ -880,23 +1033,41 @@ var anthropicAdapter = withPromptInputSupport({
880
1033
  budget_tokens: resolvedAsset.reasoning.budget_tokens
881
1034
  };
882
1035
  }
1036
+ if (resolvedAsset.provider_options?.anthropic?.top_k !== void 0) {
1037
+ body.top_k = resolvedAsset.provider_options.anthropic.top_k;
1038
+ }
883
1039
  if (resolvedAsset.response?.stream !== void 0) {
884
1040
  body.stream = resolvedAsset.response.stream;
885
1041
  }
1042
+ if (cacheControl && cacheMode === "automatic") {
1043
+ body.cache_control = cacheControl;
1044
+ }
886
1045
  if (resolvedAsset.tools && resolvedAsset.tools.length > 0) {
887
1046
  body.tools = resolvedAsset.tools.map((tool) => {
888
1047
  if (typeof tool === "string") {
889
1048
  const def = runtime.toolRegistry?.[tool];
890
- if (def) return def;
891
- return { name: tool };
1049
+ if (def) {
1050
+ if (cacheControl && cacheMode === "explicit" && anthropicCacheConfig?.cache_tools) {
1051
+ return { ...def, cache_control: cacheControl };
1052
+ }
1053
+ return def;
1054
+ }
1055
+ return {
1056
+ name: tool,
1057
+ ...cacheControl && cacheMode === "explicit" && anthropicCacheConfig?.cache_tools ? { cache_control: cacheControl } : {}
1058
+ };
892
1059
  }
893
1060
  return {
894
1061
  name: tool.name,
895
1062
  description: tool.description,
896
- input_schema: tool.input_schema ?? { type: "object", properties: {} }
1063
+ input_schema: tool.input_schema ?? { type: "object", properties: {} },
1064
+ ...cacheControl && cacheMode === "explicit" && anthropicCacheConfig?.cache_tools ? { cache_control: cacheControl } : {}
897
1065
  };
898
1066
  });
899
1067
  }
1068
+ if (resolvedAsset.provider_options?.anthropic?.tool_choice !== void 0) {
1069
+ body.tool_choice = resolvedAsset.provider_options.anthropic.tool_choice;
1070
+ }
900
1071
  return {
901
1072
  body,
902
1073
  provider: "anthropic",