@zuplo/runtime 6.59.9 → 6.59.11

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.
@@ -22,4 +22,4 @@
22
22
  * DEALINGS IN THE SOFTWARE.
23
23
  *--------------------------------------------------------------------------------------------*/
24
24
 
25
- import{a as p}from"../chunk-QROYR45R.js";import{Z as n,a as t}from"../chunk-B77APQ6Y.js";function g(u={request:new Request("https://api.example.com")}){let e=[];function o(i){e.push(Promise.resolve(i))}return t(o,"waitUntil"),{context:new s({event:{waitUntil:o},route:u.route}),invokeResponse:t(async()=>{await Promise.all(e)},"invokeResponse")}}t(g,"createMockContext");var a={path:"/",methods:["GET"],handler:{module:{},export:"default"},raw:t(()=>({}),"raw")},s=class extends EventTarget{static{t(this,"MockZuploContext")}#e;contextId;requestId;log;route;custom;incomingRequestProperties;parentContext;analyticsContext;constructor({event:e,route:o=a,parentContext:r}){super(),this.requestId=crypto.randomUUID(),this.contextId=crypto.randomUUID(),this.log={info:n.console.info,log:n.console.log,debug:n.console.debug,warn:n.console.warn,error:n.console.error},this.custom={},this.route=o,this.incomingRequestProperties={asn:1234,asOrganization:"ORGANIZATION",city:"Seattle",region:"Washington",regionCode:"WA",colo:"SEA",continent:"NA",country:"US",postalCode:"98004",metroCode:"SEA",latitude:void 0,longitude:void 0,timezone:void 0,httpProtocol:void 0},this.parentContext=r,this.#e=e,this.analyticsContext=new p(this.requestId)}waitUntil(e){this.#e.waitUntil(e)}invokeInboundPolicy(e,o){throw new Error("Not implemented")}invokeOutboundPolicy(e,o,r){throw new Error("Not implemented")}invokeRoute(e,o){throw new Error("Not implemented")}addResponseSendingHook(e){throw new Error("Not implemented")}addResponseSendingFinalHook(e){throw new Error("Not implemented")}addEventListener(e,o,r){let l=t(i=>{try{typeof o=="function"?o(i):o.handleEvent(i)}catch(d){throw this.log.error(`Error invoking event ${e}. See following logs for details.`),d}},"wrapped");super.addEventListener(e,l,r)}};export{s as MockZuploContext,g as createMockContext};
25
+ import{b as p}from"../chunk-I2ALG3UB.js";import{Z as n,a as t}from"../chunk-B77APQ6Y.js";function g(u={request:new Request("https://api.example.com")}){let e=[];function o(i){e.push(Promise.resolve(i))}return t(o,"waitUntil"),{context:new s({event:{waitUntil:o},route:u.route}),invokeResponse:t(async()=>{await Promise.all(e)},"invokeResponse")}}t(g,"createMockContext");var a={path:"/",methods:["GET"],handler:{module:{},export:"default"},raw:t(()=>({}),"raw")},s=class extends EventTarget{static{t(this,"MockZuploContext")}#e;contextId;requestId;log;route;custom;incomingRequestProperties;parentContext;analyticsContext;constructor({event:e,route:o=a,parentContext:r}){super(),this.requestId=crypto.randomUUID(),this.contextId=crypto.randomUUID(),this.log={info:n.console.info,log:n.console.log,debug:n.console.debug,warn:n.console.warn,error:n.console.error},this.custom={},this.route=o,this.incomingRequestProperties={asn:1234,asOrganization:"ORGANIZATION",city:"Seattle",region:"Washington",regionCode:"WA",colo:"SEA",continent:"NA",country:"US",postalCode:"98004",metroCode:"SEA",latitude:void 0,longitude:void 0,timezone:void 0,httpProtocol:void 0},this.parentContext=r,this.#e=e,this.analyticsContext=new p(this.requestId)}waitUntil(e){this.#e.waitUntil(e)}invokeInboundPolicy(e,o){throw new Error("Not implemented")}invokeOutboundPolicy(e,o,r){throw new Error("Not implemented")}invokeRoute(e,o){throw new Error("Not implemented")}addResponseSendingHook(e){throw new Error("Not implemented")}addResponseSendingFinalHook(e){throw new Error("Not implemented")}addEventListener(e,o,r){let l=t(i=>{try{typeof o=="function"?o(i):o.handleEvent(i)}catch(d){throw this.log.error(`Error invoking event ${e}. See following logs for details.`),d}},"wrapped");super.addEventListener(e,l,r)}};export{s as MockZuploContext,g as createMockContext};
@@ -175,6 +175,53 @@ export declare interface AIGatewayMeteringInboundPolicyOptions {
175
175
  throwOnFailure?: boolean;
176
176
  }
177
177
 
178
+ /**
179
+ * The options for this policy.
180
+ * @public
181
+ */
182
+ export declare interface AIGatewayUsageTrackerOptions {}
183
+
184
+ /**
185
+ * Tracks AI Gateway usage including token consumption and costs based on
186
+ * real-time model pricing from the Gateway service.
187
+ *
188
+ * This policy monitors AI model usage by:
189
+ * - Extracting token usage from AI provider responses
190
+ * - Fetching current model pricing from the Gateway service
191
+ * - Calculating costs based on prompt and completion tokens
192
+ * - Recording metrics for billing and monitoring
193
+ * - Adding usage headers to responses for debugging
194
+ * @hidden
195
+ * @title AI Gateway Usage Tracker
196
+ * @param response - The response from the AI provider
197
+ * @param request - The incoming ZuploRequest
198
+ * @param context - The ZuploContext
199
+ * @param options - The policy configuration options
200
+ * @param policyName - The name of the policy instance
201
+ * @returns The response with added usage headers
202
+ *
203
+ * @example
204
+ * ```json
205
+ * // policies.json - Basic usage tracking
206
+ * {
207
+ * "name": "ai-usage-tracker",
208
+ * "policyType": "ai-gateway-usage-tracker",
209
+ * "handler": {
210
+ * "export": "AIGatewayUsageTrackerPolicy",
211
+ * "module": "$import(@zuplo/runtime)",
212
+ * "options": {}
213
+ * }
214
+ * }
215
+ * ```
216
+ */
217
+ export declare function AIGatewayUsageTrackerPolicy(
218
+ response: Response,
219
+ request: ZuploRequest,
220
+ context: ZuploContext,
221
+ _options: AIGatewayUsageTrackerOptions,
222
+ _policyName: string
223
+ ): Promise<Response>;
224
+
178
225
  /**
179
226
  * Entry format for Akamai API Security logger
180
227
  * @public
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zuplo/runtime",
3
3
  "type": "module",
4
- "version": "6.59.9",
4
+ "version": "6.59.11",
5
5
  "repository": "https://github.com/zuplo/zuplo",
6
6
  "author": "Zuplo, Inc.",
7
7
  "exports": {