promptopskit 0.2.6 → 0.3.0

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.
@@ -0,0 +1,147 @@
1
+ import { a as ProviderRequest } from '../types-CQhlfAnR.js';
2
+ import '../schema-DIOA4OiO.js';
3
+ import 'zod';
4
+
5
+ type UsageTapReasoningLevel = 'NONE' | 'LOW' | 'MEDIUM' | 'HIGH';
6
+ type UsageTapEntitlementMode = 'off' | 'apply';
7
+ type UsageTapAllowedCapability = 'standard' | 'premium' | 'audio' | 'image' | 'search';
8
+ interface UsageTapAllowed {
9
+ standard?: boolean;
10
+ premium?: boolean;
11
+ audio?: boolean;
12
+ image?: boolean;
13
+ search?: boolean;
14
+ reasoningLevel?: UsageTapReasoningLevel;
15
+ }
16
+ interface UsageTapBeginRequest {
17
+ customerId: string;
18
+ feature?: string;
19
+ tags?: string[];
20
+ customerName?: string;
21
+ customerEmail?: string;
22
+ stripeCustomerId?: string;
23
+ requested?: Record<string, boolean | string>;
24
+ idempotencyKey?: string;
25
+ batch?: boolean;
26
+ pricingMode?: 'batch' | 'standard';
27
+ }
28
+ interface UsageTapBeginResponse {
29
+ data: {
30
+ callId: string;
31
+ allowed: UsageTapAllowed;
32
+ entitlementHints?: Record<string, unknown>;
33
+ subscription?: Record<string, unknown>;
34
+ plan?: Record<string, unknown>;
35
+ balances?: Record<string, unknown>;
36
+ stripeCustomerId?: string | null;
37
+ [key: string]: unknown;
38
+ };
39
+ [key: string]: unknown;
40
+ }
41
+ interface UsageTapErrorPayload {
42
+ code: string;
43
+ message: string;
44
+ }
45
+ interface UsageTapEndUsage {
46
+ modelUsed?: string;
47
+ inputTokens?: number;
48
+ cachedInputTokens?: number;
49
+ responseTokens?: number;
50
+ reasoningTokens?: number;
51
+ searches?: number;
52
+ audio?: number;
53
+ audioSeconds?: number;
54
+ isPremium?: boolean;
55
+ stripeCustomerId?: string;
56
+ responseStatusCode?: number;
57
+ batch?: boolean;
58
+ pricingMode?: 'batch' | 'standard';
59
+ error?: UsageTapErrorPayload;
60
+ }
61
+ interface UsageTapEndRequest extends UsageTapEndUsage {
62
+ callId: string;
63
+ }
64
+ interface UsageTapEndResponse {
65
+ data?: Record<string, unknown>;
66
+ [key: string]: unknown;
67
+ }
68
+ interface UsageTapClientConfig {
69
+ apiKey: string;
70
+ baseUrl?: string;
71
+ fetch?: typeof globalThis.fetch;
72
+ }
73
+ interface UsageTapRequestInit {
74
+ signal?: AbortSignal;
75
+ }
76
+ interface UsageTapClient {
77
+ request<T>(path: string, body: unknown, init?: UsageTapRequestInit): Promise<T>;
78
+ beginCall(begin: UsageTapBeginRequest, init?: UsageTapRequestInit): Promise<UsageTapBeginResponse>;
79
+ endCall(end: UsageTapEndRequest, init?: UsageTapRequestInit): Promise<UsageTapEndResponse>;
80
+ }
81
+ interface UsageTapInvokeContext {
82
+ begin: UsageTapBeginResponse;
83
+ setUsage: (usage: UsageTapEndUsage) => void;
84
+ signal?: AbortSignal;
85
+ }
86
+ interface UsageTapInvokeResult<TResult> {
87
+ result: TResult;
88
+ usage: UsageTapEndUsage;
89
+ }
90
+ interface UsageTapCallOptions<TResult> {
91
+ begin: UsageTapBeginRequest;
92
+ invoke: (context: UsageTapInvokeContext) => Promise<TResult | UsageTapInvokeResult<TResult>>;
93
+ onError?: (error: unknown) => UsageTapErrorPayload;
94
+ signal?: AbortSignal;
95
+ }
96
+ interface UsageTapCallResult<TResult> {
97
+ result: TResult;
98
+ begin: UsageTapBeginResponse;
99
+ end: UsageTapEndResponse;
100
+ effectiveUsage: UsageTapEndUsage;
101
+ }
102
+ interface UsageTapEntitlementOptions {
103
+ modelTiers?: {
104
+ standard?: string;
105
+ premium?: string;
106
+ };
107
+ toolEntitlements?: Record<string, UsageTapAllowedCapability>;
108
+ }
109
+ interface UsageTapProviderRunOptions<TResult> extends UsageTapEntitlementOptions {
110
+ request: ProviderRequest;
111
+ begin: UsageTapBeginRequest;
112
+ invoke: (request: ProviderRequest) => Promise<TResult | UsageTapInvokeResult<TResult>>;
113
+ extractUsage?: (response: TResult) => UsageTapEndUsage;
114
+ entitlementMode?: UsageTapEntitlementMode;
115
+ signal?: AbortSignal;
116
+ onError?: (error: unknown) => UsageTapErrorPayload;
117
+ }
118
+ interface UsageTapProviderRunResult<TResult> {
119
+ response: TResult;
120
+ begin: UsageTapBeginResponse;
121
+ end: UsageTapEndResponse;
122
+ requestUsed: ProviderRequest;
123
+ effectiveUsage: UsageTapEndUsage;
124
+ allowed: UsageTapAllowed;
125
+ }
126
+
127
+ declare function createUsageTapClient(config: UsageTapClientConfig): UsageTapClient;
128
+
129
+ declare function defaultUsageTapErrorMapper(error: unknown): UsageTapErrorPayload;
130
+ declare function beginUsageTapCall(client: UsageTapClient, begin: Parameters<UsageTapClient['beginCall']>[0], init?: UsageTapRequestInit): Promise<UsageTapBeginResponse>;
131
+ declare function endUsageTapCall(client: UsageTapClient, end: UsageTapEndRequest, init?: UsageTapRequestInit): Promise<UsageTapEndResponse>;
132
+ declare function withUsageTapCall<TResult>(client: UsageTapClient, options: UsageTapCallOptions<TResult>): Promise<UsageTapCallResult<TResult>>;
133
+
134
+ declare function applyUsageTapEntitlements(request: ProviderRequest, begin: UsageTapBeginResponse, options?: UsageTapEntitlementOptions): ProviderRequest;
135
+ interface UsageMeta {
136
+ modelUsed?: string;
137
+ responseStatusCode?: number;
138
+ }
139
+ declare function extractOpenAIUsage(response: unknown, meta?: UsageMeta): UsageTapEndUsage;
140
+ declare function extractAnthropicUsage(response: unknown, meta?: UsageMeta): UsageTapEndUsage;
141
+ declare function extractGeminiUsage(response: unknown, meta?: UsageMeta): UsageTapEndUsage;
142
+ declare function runOpenAIWithUsageTap<TResult>(client: UsageTapClient, options: UsageTapProviderRunOptions<TResult>): Promise<UsageTapProviderRunResult<TResult>>;
143
+ declare function runOpenRouterWithUsageTap<TResult>(client: UsageTapClient, options: UsageTapProviderRunOptions<TResult>): Promise<UsageTapProviderRunResult<TResult>>;
144
+ declare function runAnthropicWithUsageTap<TResult>(client: UsageTapClient, options: UsageTapProviderRunOptions<TResult>): Promise<UsageTapProviderRunResult<TResult>>;
145
+ declare function runGeminiWithUsageTap<TResult>(client: UsageTapClient, options: UsageTapProviderRunOptions<TResult>): Promise<UsageTapProviderRunResult<TResult>>;
146
+
147
+ export { type UsageTapAllowed, type UsageTapAllowedCapability, type UsageTapBeginRequest, type UsageTapBeginResponse, type UsageTapCallOptions, type UsageTapCallResult, type UsageTapClient, type UsageTapClientConfig, type UsageTapEndRequest, type UsageTapEndResponse, type UsageTapEndUsage, type UsageTapEntitlementMode, type UsageTapEntitlementOptions, type UsageTapErrorPayload, type UsageTapInvokeContext, type UsageTapInvokeResult, type UsageTapProviderRunOptions, type UsageTapProviderRunResult, type UsageTapReasoningLevel, applyUsageTapEntitlements, beginUsageTapCall, createUsageTapClient, defaultUsageTapErrorMapper, endUsageTapCall, extractAnthropicUsage, extractGeminiUsage, extractOpenAIUsage, runAnthropicWithUsageTap, runGeminiWithUsageTap, runOpenAIWithUsageTap, runOpenRouterWithUsageTap, withUsageTapCall };
@@ -0,0 +1,31 @@
1
+ import {
2
+ applyUsageTapEntitlements,
3
+ beginUsageTapCall,
4
+ createUsageTapClient,
5
+ defaultUsageTapErrorMapper,
6
+ endUsageTapCall,
7
+ extractAnthropicUsage,
8
+ extractGeminiUsage,
9
+ extractOpenAIUsage,
10
+ runAnthropicWithUsageTap,
11
+ runGeminiWithUsageTap,
12
+ runOpenAIWithUsageTap,
13
+ runOpenRouterWithUsageTap,
14
+ withUsageTapCall
15
+ } from "../chunk-HWEVRBKZ.js";
16
+ export {
17
+ applyUsageTapEntitlements,
18
+ beginUsageTapCall,
19
+ createUsageTapClient,
20
+ defaultUsageTapErrorMapper,
21
+ endUsageTapCall,
22
+ extractAnthropicUsage,
23
+ extractGeminiUsage,
24
+ extractOpenAIUsage,
25
+ runAnthropicWithUsageTap,
26
+ runGeminiWithUsageTap,
27
+ runOpenAIWithUsageTap,
28
+ runOpenRouterWithUsageTap,
29
+ withUsageTapCall
30
+ };
31
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "promptopskit",
3
- "version": "0.2.6",
3
+ "version": "0.3.0",
4
4
  "description": "Manage prompts, system instructions, tools, and model settings as code",
5
5
  "type": "module",
6
6
  "bin": {
@@ -30,6 +30,16 @@
30
30
  "default": "./dist/testing.cjs"
31
31
  }
32
32
  },
33
+ "./usagetap": {
34
+ "import": {
35
+ "types": "./dist/usagetap/index.d.ts",
36
+ "default": "./dist/usagetap/index.js"
37
+ },
38
+ "require": {
39
+ "types": "./dist/usagetap/index.d.cts",
40
+ "default": "./dist/usagetap/index.cjs"
41
+ }
42
+ },
33
43
  "./openai": {
34
44
  "import": {
35
45
  "types": "./dist/providers/openai.d.ts",
@@ -211,21 +211,21 @@ declare const PromptAssetSchema: z.ZodObject<{
211
211
  max_items?: number | undefined;
212
212
  }>>;
213
213
  }, "strip", z.ZodTypeAny, {
214
- history?: {
215
- max_items?: number | undefined;
216
- } | undefined;
217
214
  inputs?: (string | {
218
215
  name: string;
219
216
  max_size?: number | undefined;
220
217
  })[] | undefined;
221
- }, {
222
218
  history?: {
223
219
  max_items?: number | undefined;
224
220
  } | undefined;
221
+ }, {
225
222
  inputs?: (string | {
226
223
  name: string;
227
224
  max_size?: number | undefined;
228
225
  })[] | undefined;
226
+ history?: {
227
+ max_items?: number | undefined;
228
+ } | undefined;
229
229
  }>>;
230
230
  includes: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
231
231
  environments: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
@@ -484,14 +484,9 @@ declare const PromptAssetSchema: z.ZodObject<{
484
484
  }, "strip", z.ZodTypeAny, {
485
485
  id: string;
486
486
  schema_version: number;
487
- source?: {
488
- file_path?: string | undefined;
489
- checksum?: string | undefined;
490
- } | undefined;
491
- provider?: "openai" | "anthropic" | "google" | "gemini" | "openrouter" | "any" | undefined;
492
487
  description?: string | undefined;
493
- model?: string | undefined;
494
488
  includes?: string[] | undefined;
489
+ model?: string | undefined;
495
490
  fallback_models?: string[] | undefined;
496
491
  reasoning?: {
497
492
  effort?: "low" | "medium" | "high" | undefined;
@@ -514,6 +509,18 @@ declare const PromptAssetSchema: z.ZodObject<{
514
509
  description?: string | undefined;
515
510
  input_schema?: Record<string, unknown> | undefined;
516
511
  })[] | undefined;
512
+ provider?: "openai" | "anthropic" | "google" | "gemini" | "openrouter" | "any" | undefined;
513
+ metadata?: {
514
+ owner?: string | undefined;
515
+ tags?: string[] | undefined;
516
+ review_required?: boolean | undefined;
517
+ stable?: boolean | undefined;
518
+ } | undefined;
519
+ sections?: {
520
+ system_instructions?: string | undefined;
521
+ prompt_template?: string | undefined;
522
+ notes?: string | undefined;
523
+ } | undefined;
517
524
  mcp?: {
518
525
  servers?: (string | {
519
526
  name: string;
@@ -521,13 +528,13 @@ declare const PromptAssetSchema: z.ZodObject<{
521
528
  })[] | undefined;
522
529
  } | undefined;
523
530
  context?: {
524
- history?: {
525
- max_items?: number | undefined;
526
- } | undefined;
527
531
  inputs?: (string | {
528
532
  name: string;
529
533
  max_size?: number | undefined;
530
534
  })[] | undefined;
535
+ history?: {
536
+ max_items?: number | undefined;
537
+ } | undefined;
531
538
  } | undefined;
532
539
  environments?: Record<string, {
533
540
  model?: string | undefined;
@@ -579,28 +586,15 @@ declare const PromptAssetSchema: z.ZodObject<{
579
586
  input_schema?: Record<string, unknown> | undefined;
580
587
  })[] | undefined;
581
588
  }> | undefined;
582
- metadata?: {
583
- owner?: string | undefined;
584
- tags?: string[] | undefined;
585
- review_required?: boolean | undefined;
586
- stable?: boolean | undefined;
587
- } | undefined;
588
- sections?: {
589
- system_instructions?: string | undefined;
590
- prompt_template?: string | undefined;
591
- notes?: string | undefined;
592
- } | undefined;
593
- }, {
594
- id: string;
595
589
  source?: {
596
590
  file_path?: string | undefined;
597
591
  checksum?: string | undefined;
598
592
  } | undefined;
599
- provider?: "openai" | "anthropic" | "google" | "gemini" | "openrouter" | "any" | undefined;
600
- schema_version?: number | undefined;
593
+ }, {
594
+ id: string;
601
595
  description?: string | undefined;
602
- model?: string | undefined;
603
596
  includes?: string[] | undefined;
597
+ model?: string | undefined;
604
598
  fallback_models?: string[] | undefined;
605
599
  reasoning?: {
606
600
  effort?: "low" | "medium" | "high" | undefined;
@@ -623,6 +617,19 @@ declare const PromptAssetSchema: z.ZodObject<{
623
617
  description?: string | undefined;
624
618
  input_schema?: Record<string, unknown> | undefined;
625
619
  })[] | undefined;
620
+ provider?: "openai" | "anthropic" | "google" | "gemini" | "openrouter" | "any" | undefined;
621
+ metadata?: {
622
+ owner?: string | undefined;
623
+ tags?: string[] | undefined;
624
+ review_required?: boolean | undefined;
625
+ stable?: boolean | undefined;
626
+ } | undefined;
627
+ sections?: {
628
+ system_instructions?: string | undefined;
629
+ prompt_template?: string | undefined;
630
+ notes?: string | undefined;
631
+ } | undefined;
632
+ schema_version?: number | undefined;
626
633
  mcp?: {
627
634
  servers?: (string | {
628
635
  name: string;
@@ -630,13 +637,13 @@ declare const PromptAssetSchema: z.ZodObject<{
630
637
  })[] | undefined;
631
638
  } | undefined;
632
639
  context?: {
633
- history?: {
634
- max_items?: number | undefined;
635
- } | undefined;
636
640
  inputs?: (string | {
637
641
  name: string;
638
642
  max_size?: number | undefined;
639
643
  })[] | undefined;
644
+ history?: {
645
+ max_items?: number | undefined;
646
+ } | undefined;
640
647
  } | undefined;
641
648
  environments?: Record<string, {
642
649
  model?: string | undefined;
@@ -688,16 +695,9 @@ declare const PromptAssetSchema: z.ZodObject<{
688
695
  input_schema?: Record<string, unknown> | undefined;
689
696
  })[] | undefined;
690
697
  }> | undefined;
691
- metadata?: {
692
- owner?: string | undefined;
693
- tags?: string[] | undefined;
694
- review_required?: boolean | undefined;
695
- stable?: boolean | undefined;
696
- } | undefined;
697
- sections?: {
698
- system_instructions?: string | undefined;
699
- prompt_template?: string | undefined;
700
- notes?: string | undefined;
698
+ source?: {
699
+ file_path?: string | undefined;
700
+ checksum?: string | undefined;
701
701
  } | undefined;
702
702
  }>;
703
703
  type PromptAsset = z.infer<typeof PromptAssetSchema>;
@@ -211,21 +211,21 @@ declare const PromptAssetSchema: z.ZodObject<{
211
211
  max_items?: number | undefined;
212
212
  }>>;
213
213
  }, "strip", z.ZodTypeAny, {
214
- history?: {
215
- max_items?: number | undefined;
216
- } | undefined;
217
214
  inputs?: (string | {
218
215
  name: string;
219
216
  max_size?: number | undefined;
220
217
  })[] | undefined;
221
- }, {
222
218
  history?: {
223
219
  max_items?: number | undefined;
224
220
  } | undefined;
221
+ }, {
225
222
  inputs?: (string | {
226
223
  name: string;
227
224
  max_size?: number | undefined;
228
225
  })[] | undefined;
226
+ history?: {
227
+ max_items?: number | undefined;
228
+ } | undefined;
229
229
  }>>;
230
230
  includes: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
231
231
  environments: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodObject<{
@@ -484,14 +484,9 @@ declare const PromptAssetSchema: z.ZodObject<{
484
484
  }, "strip", z.ZodTypeAny, {
485
485
  id: string;
486
486
  schema_version: number;
487
- source?: {
488
- file_path?: string | undefined;
489
- checksum?: string | undefined;
490
- } | undefined;
491
- provider?: "openai" | "anthropic" | "google" | "gemini" | "openrouter" | "any" | undefined;
492
487
  description?: string | undefined;
493
- model?: string | undefined;
494
488
  includes?: string[] | undefined;
489
+ model?: string | undefined;
495
490
  fallback_models?: string[] | undefined;
496
491
  reasoning?: {
497
492
  effort?: "low" | "medium" | "high" | undefined;
@@ -514,6 +509,18 @@ declare const PromptAssetSchema: z.ZodObject<{
514
509
  description?: string | undefined;
515
510
  input_schema?: Record<string, unknown> | undefined;
516
511
  })[] | undefined;
512
+ provider?: "openai" | "anthropic" | "google" | "gemini" | "openrouter" | "any" | undefined;
513
+ metadata?: {
514
+ owner?: string | undefined;
515
+ tags?: string[] | undefined;
516
+ review_required?: boolean | undefined;
517
+ stable?: boolean | undefined;
518
+ } | undefined;
519
+ sections?: {
520
+ system_instructions?: string | undefined;
521
+ prompt_template?: string | undefined;
522
+ notes?: string | undefined;
523
+ } | undefined;
517
524
  mcp?: {
518
525
  servers?: (string | {
519
526
  name: string;
@@ -521,13 +528,13 @@ declare const PromptAssetSchema: z.ZodObject<{
521
528
  })[] | undefined;
522
529
  } | undefined;
523
530
  context?: {
524
- history?: {
525
- max_items?: number | undefined;
526
- } | undefined;
527
531
  inputs?: (string | {
528
532
  name: string;
529
533
  max_size?: number | undefined;
530
534
  })[] | undefined;
535
+ history?: {
536
+ max_items?: number | undefined;
537
+ } | undefined;
531
538
  } | undefined;
532
539
  environments?: Record<string, {
533
540
  model?: string | undefined;
@@ -579,28 +586,15 @@ declare const PromptAssetSchema: z.ZodObject<{
579
586
  input_schema?: Record<string, unknown> | undefined;
580
587
  })[] | undefined;
581
588
  }> | undefined;
582
- metadata?: {
583
- owner?: string | undefined;
584
- tags?: string[] | undefined;
585
- review_required?: boolean | undefined;
586
- stable?: boolean | undefined;
587
- } | undefined;
588
- sections?: {
589
- system_instructions?: string | undefined;
590
- prompt_template?: string | undefined;
591
- notes?: string | undefined;
592
- } | undefined;
593
- }, {
594
- id: string;
595
589
  source?: {
596
590
  file_path?: string | undefined;
597
591
  checksum?: string | undefined;
598
592
  } | undefined;
599
- provider?: "openai" | "anthropic" | "google" | "gemini" | "openrouter" | "any" | undefined;
600
- schema_version?: number | undefined;
593
+ }, {
594
+ id: string;
601
595
  description?: string | undefined;
602
- model?: string | undefined;
603
596
  includes?: string[] | undefined;
597
+ model?: string | undefined;
604
598
  fallback_models?: string[] | undefined;
605
599
  reasoning?: {
606
600
  effort?: "low" | "medium" | "high" | undefined;
@@ -623,6 +617,19 @@ declare const PromptAssetSchema: z.ZodObject<{
623
617
  description?: string | undefined;
624
618
  input_schema?: Record<string, unknown> | undefined;
625
619
  })[] | undefined;
620
+ provider?: "openai" | "anthropic" | "google" | "gemini" | "openrouter" | "any" | undefined;
621
+ metadata?: {
622
+ owner?: string | undefined;
623
+ tags?: string[] | undefined;
624
+ review_required?: boolean | undefined;
625
+ stable?: boolean | undefined;
626
+ } | undefined;
627
+ sections?: {
628
+ system_instructions?: string | undefined;
629
+ prompt_template?: string | undefined;
630
+ notes?: string | undefined;
631
+ } | undefined;
632
+ schema_version?: number | undefined;
626
633
  mcp?: {
627
634
  servers?: (string | {
628
635
  name: string;
@@ -630,13 +637,13 @@ declare const PromptAssetSchema: z.ZodObject<{
630
637
  })[] | undefined;
631
638
  } | undefined;
632
639
  context?: {
633
- history?: {
634
- max_items?: number | undefined;
635
- } | undefined;
636
640
  inputs?: (string | {
637
641
  name: string;
638
642
  max_size?: number | undefined;
639
643
  })[] | undefined;
644
+ history?: {
645
+ max_items?: number | undefined;
646
+ } | undefined;
640
647
  } | undefined;
641
648
  environments?: Record<string, {
642
649
  model?: string | undefined;
@@ -688,16 +695,9 @@ declare const PromptAssetSchema: z.ZodObject<{
688
695
  input_schema?: Record<string, unknown> | undefined;
689
696
  })[] | undefined;
690
697
  }> | undefined;
691
- metadata?: {
692
- owner?: string | undefined;
693
- tags?: string[] | undefined;
694
- review_required?: boolean | undefined;
695
- stable?: boolean | undefined;
696
- } | undefined;
697
- sections?: {
698
- system_instructions?: string | undefined;
699
- prompt_template?: string | undefined;
700
- notes?: string | undefined;
698
+ source?: {
699
+ file_path?: string | undefined;
700
+ checksum?: string | undefined;
701
701
  } | undefined;
702
702
  }>;
703
703
  type PromptAsset = z.infer<typeof PromptAssetSchema>;