@zuplo/runtime 6.59.6 → 6.59.7

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{Z as n,a as t}from"../chunk-SSAQ7DDU.js";function m(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(m,"createMockContext");var l={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;constructor({event:e,route:o=l,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}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 d=t(i=>{try{typeof o=="function"?o(i):o.handleEvent(i)}catch(p){throw this.log.error(`Error invoking event ${e}. See following logs for details.`),p}},"wrapped");super.addEventListener(e,d,r)}};export{s as MockZuploContext,m as createMockContext};
25
+ import{a as p}from"../chunk-7X7Y6YCS.js";import{Z as n,a as t}from"../chunk-SSAQ7DDU.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};
@@ -4,6 +4,32 @@ import { RequestGeneric as RequestGeneric_2 } from "../../request.js";
4
4
  import type { ValidateFunction } from "ajv";
5
5
  import { z } from "zod/v4";
6
6
 
7
+ /**
8
+ * Handler that routes AI/LLM requests through Zuplo's LLM Translation Layer.
9
+ * This handler forwards requests to the translation layer that handles provider-specific
10
+ * API transformations, parameter validation, and response normalization to provide
11
+ * a unified OpenAI-compatible interface across multiple LLM providers.
12
+ *
13
+ * @param request - The incoming ZuploRequest containing AI/LLM API call
14
+ * @param context - The ZuploContext containing route configuration
15
+ * @returns A Response from the AI provider via the translation layer
16
+ *
17
+ * @public
18
+ * @example
19
+ * ```json
20
+ * {
21
+ * "handler": {
22
+ * "export": "aiGatewayHandler",
23
+ * "module": "$import(@zuplo/runtime)"
24
+ * }
25
+ * }
26
+ * ```
27
+ */
28
+ export declare function aiGatewayHandler(
29
+ request: ZuploRequest,
30
+ context: ZuploContext
31
+ ): Promise<Response>;
32
+
7
33
  /**
8
34
  * Entry format for Akamai API Security logger
9
35
  * @public
@@ -2191,6 +2217,12 @@ export declare interface ErrorHandler {
2191
2217
  ): Response | Promise<Response>;
2192
2218
  }
2193
2219
 
2220
+ declare const EventType: {
2221
+ readonly MCP_TOOL_USAGE: "mcp_tool_usage";
2222
+ };
2223
+
2224
+ declare type EventType = (typeof EventType)[keyof typeof EventType];
2225
+
2194
2226
  declare interface FetchOptions<T> {
2195
2227
  method?: HttpMethod_2;
2196
2228
  data?: T;
@@ -4415,6 +4447,26 @@ declare type Iso3166Alpha2Code =
4415
4447
  | "ZM"
4416
4448
  | "ZW";
4417
4449
 
4450
+ declare type JsonArray = JsonValue[] | readonly JsonValue[];
4451
+
4452
+ /**
4453
+ Matches a JSON object.
4454
+ This type can be useful to enforce some input to be JSON-compatible or as a super-type to be extended from. Don't use this as a direct return type as the user would have to double-cast it: `jsonObject as unknown as CustomResponse`. Instead, you could extend your CustomResponse type from it to ensure your type only uses JSON-compatible types: `interface CustomResponse extends JsonObject { … }`.
4455
+ */
4456
+ declare type JsonObject = {
4457
+ [Key in string]: JsonValue;
4458
+ } & {
4459
+ [Key in string]?: JsonValue | undefined;
4460
+ };
4461
+
4462
+ declare type JsonPrimitive = string | number | boolean | null;
4463
+
4464
+ /**
4465
+ Matches any valid JSON value.
4466
+ @see `Jsonify` if you need to transform a type to one that is assignable to `JsonValue`.
4467
+ */
4468
+ declare type JsonValue = JsonPrimitive | JsonObject | JsonArray;
4469
+
4418
4470
  /**
4419
4471
  * Validates that the JWT token includes specific scopes
4420
4472
  *
@@ -9086,6 +9138,29 @@ export declare class ZoneCache<T = any> {
9086
9138
  logDebug(...messages: unknown[]): void;
9087
9139
  }
9088
9140
 
9141
+ declare interface ZuploAnalyticsContext {
9142
+ addAnalyticsEvent(
9143
+ value: number,
9144
+ eventType: EventType,
9145
+ metadata: JsonObject,
9146
+ unit?: string
9147
+ ): void;
9148
+ getAnalyticsEvents(): ZuploAnalyticsEvent[];
9149
+ }
9150
+
9151
+ declare interface ZuploAnalyticsEvent<T extends JsonObject = JsonObject> {
9152
+ eventId: string;
9153
+ requestId: string;
9154
+ timestamp: Date;
9155
+ accountName: string;
9156
+ projectName: string;
9157
+ deploymentName: string;
9158
+ eventType: EventType;
9159
+ metadata: T;
9160
+ unit?: string;
9161
+ value: number;
9162
+ }
9163
+
9089
9164
  /**
9090
9165
  * The ZuploContext provides information about the current request and helper methods.
9091
9166
  * @public
@@ -9117,6 +9192,7 @@ export declare interface ZuploContext extends EventTarget {
9117
9192
  * @beta
9118
9193
  */
9119
9194
  readonly parentContext: ZuploContext | undefined;
9195
+ /* Excluded from this release type: analyticsContext */
9120
9196
  readonly invokeInboundPolicy: (
9121
9197
  policyName: string,
9122
9198
  request: ZuploRequest
@@ -65,6 +65,12 @@ export declare function createMockContext(options?: {
65
65
  invokeResponse: () => Promise<void>;
66
66
  };
67
67
 
68
+ declare const EventType: {
69
+ readonly MCP_TOOL_USAGE: "mcp_tool_usage";
70
+ };
71
+
72
+ declare type EventType = (typeof EventType)[keyof typeof EventType];
73
+
68
74
  /**
69
75
  * @public
70
76
  */
@@ -754,6 +760,26 @@ declare type Iso3166Alpha2Code =
754
760
  | "ZM"
755
761
  | "ZW";
756
762
 
763
+ declare type JsonArray = JsonValue[] | readonly JsonValue[];
764
+
765
+ /**
766
+ Matches a JSON object.
767
+ This type can be useful to enforce some input to be JSON-compatible or as a super-type to be extended from. Don't use this as a direct return type as the user would have to double-cast it: `jsonObject as unknown as CustomResponse`. Instead, you could extend your CustomResponse type from it to ensure your type only uses JSON-compatible types: `interface CustomResponse extends JsonObject { … }`.
768
+ */
769
+ declare type JsonObject = {
770
+ [Key in string]: JsonValue;
771
+ } & {
772
+ [Key in string]?: JsonValue | undefined;
773
+ };
774
+
775
+ declare type JsonPrimitive = string | number | boolean | null;
776
+
777
+ /**
778
+ Matches any valid JSON value.
779
+ @see `Jsonify` if you need to transform a type to one that is assignable to `JsonValue`.
780
+ */
781
+ declare type JsonValue = JsonPrimitive | JsonObject | JsonArray;
782
+
757
783
  /**
758
784
  * @beta
759
785
  */
@@ -781,6 +807,7 @@ export declare class MockZuploContext
781
807
  readonly custom: Record<string, any>;
782
808
  readonly incomingRequestProperties: IncomingRequestProperties;
783
809
  readonly parentContext: ZuploContext | undefined;
810
+ readonly analyticsContext: ZuploAnalyticsContext;
784
811
  constructor({
785
812
  event,
786
813
  route,
@@ -1517,6 +1544,29 @@ declare interface WaitUntilFunc {
1517
1544
  (promise: Promise<any>): void;
1518
1545
  }
1519
1546
 
1547
+ declare interface ZuploAnalyticsContext {
1548
+ addAnalyticsEvent(
1549
+ value: number,
1550
+ eventType: EventType,
1551
+ metadata: JsonObject,
1552
+ unit?: string
1553
+ ): void;
1554
+ getAnalyticsEvents(): ZuploAnalyticsEvent[];
1555
+ }
1556
+
1557
+ declare interface ZuploAnalyticsEvent<T extends JsonObject = JsonObject> {
1558
+ eventId: string;
1559
+ requestId: string;
1560
+ timestamp: Date;
1561
+ accountName: string;
1562
+ projectName: string;
1563
+ deploymentName: string;
1564
+ eventType: EventType;
1565
+ metadata: T;
1566
+ unit?: string;
1567
+ value: number;
1568
+ }
1569
+
1520
1570
  /**
1521
1571
  * The ZuploContext provides information about the current request and helper methods.
1522
1572
  * @public
@@ -1548,6 +1598,7 @@ declare interface ZuploContext extends EventTarget {
1548
1598
  * @beta
1549
1599
  */
1550
1600
  readonly parentContext: ZuploContext | undefined;
1601
+ /* Excluded from this release type: analyticsContext */
1551
1602
  readonly invokeInboundPolicy: (
1552
1603
  policyName: string,
1553
1604
  request: ZuploRequest
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zuplo/runtime",
3
3
  "type": "module",
4
- "version": "6.59.6",
4
+ "version": "6.59.7",
5
5
  "repository": "https://github.com/zuplo/zuplo",
6
6
  "author": "Zuplo, Inc.",
7
7
  "exports": {