@zuplo/runtime 6.58.0 → 6.58.4

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.
@@ -4658,71 +4658,23 @@ declare type LokiTransportVersion = 1 | 2;
4658
4658
 
4659
4659
  /* Excluded from this release type: LookupResult */
4660
4660
 
4661
- /**
4662
- * Plugin for adding MCP (Model Context Protocol) custom tools to Zuplo
4663
- *
4664
- * This plugin allows end users to create custom MCP tools using a simple SDK
4665
- * that can perform complex operations including invoking multiple routes on the gateway or
4666
- * implementing custom logic beyond simple route mapping.
4667
- */
4668
- export declare class McpCustomToolsPlugin extends SystemRuntimePlugin {
4669
- private options;
4670
- private mcpServer;
4671
- private transport;
4672
- constructor(options: McpCustomToolsPluginOptions);
4673
- private validateTools;
4674
- registerRoutes(options: {
4675
- router: Router;
4676
- runtimeSettings: RuntimeSettings;
4677
- }): void;
4678
- private createMcpHandler;
4679
- /**
4680
- * Lazy loads the MCP server, http transport, and tools on first call
4681
- */
4682
- private initializeMcpServer;
4683
- /**
4684
- * Registers individual custom tools from users given a McpToolDefinion
4685
- */
4686
- private registerTool;
4687
- }
4688
-
4689
- /**
4690
- * Configuration options for the MCP Custom Tools Plugin
4691
- */
4692
- export declare interface McpCustomToolsPluginOptions {
4693
- /**
4694
- * Name of the MCP server
4695
- */
4696
- name?: string;
4697
- /**
4698
- * Version of the MCP server
4699
- */
4700
- version?: string;
4701
- /**
4702
- * The endpoint path where the MCP server will be registered on the gateway
4703
- * Default: "/mcp"
4704
- */
4705
- endpoint?: string;
4706
- /**
4707
- * Custom tools to register with the MCP server
4708
- */
4709
- tools: McpToolDefinition[];
4710
- }
4711
-
4712
4661
  /**
4713
4662
  * SDK for creating and managing MCP custom tools
4714
4663
  *
4715
4664
  * Provides a fluent API for defining custom MCP tools that can perform
4716
4665
  * complex operations including calling multiple routes or implementing
4717
4666
  * custom logic beyond simple route mapping.
4667
+ * @beta
4718
4668
  */
4719
4669
  export declare class McpCustomToolsSDK {
4720
4670
  /**
4721
4671
  * Create a new tool builder
4672
+ * @beta
4722
4673
  */
4723
4674
  createTool(): McpToolBuilder;
4724
4675
  /**
4725
4676
  * Define a tool with a configuration object
4677
+ * @beta
4726
4678
  */
4727
4679
  defineTool<TSchema extends z.ZodType>(config: {
4728
4680
  name: string;
@@ -4733,24 +4685,36 @@ export declare class McpCustomToolsSDK {
4733
4685
  }): McpToolDefinition<z.infer<TSchema>>;
4734
4686
  /**
4735
4687
  * Create a text response
4688
+ * @beta
4736
4689
  */
4737
4690
  textResponse(text: string): CallToolResult;
4738
4691
  /**
4739
4692
  * Create a JSON response (automatically stringified and put in structured content)
4693
+ * @beta
4740
4694
  */
4741
4695
  jsonResponse(data: any): CallToolResult;
4742
4696
  /**
4743
4697
  * Create an error response
4698
+ * @beta
4744
4699
  */
4745
4700
  errorResponse(message: string): CallToolResult;
4746
4701
  /**
4747
4702
  * Create an image response
4703
+ * @beta
4748
4704
  */
4749
4705
  imageResponse(data: string, mimeType: string): CallToolResult;
4750
4706
  /**
4751
4707
  * Create a resource response
4708
+ * @beta
4752
4709
  */
4753
4710
  resourceResponse(uri: string, mimeType?: string): CallToolResult;
4711
+ /**
4712
+ * Fetches the original headers used to invoke the MCP server.
4713
+ * This is especially useful for when re-invoking Gateway routes and passing through
4714
+ * all captured headers.
4715
+ * @beta
4716
+ */
4717
+ getInvokeHeaders(): Record<string, string>;
4754
4718
  }
4755
4719
 
4756
4720
  /**
@@ -4769,37 +4733,45 @@ export declare function mcpServerHandler(
4769
4733
 
4770
4734
  /**
4771
4735
  * Builder for creating MCP tools with type safety
4736
+ * @beta
4772
4737
  */
4773
4738
  export declare class McpToolBuilder<TSchema extends z.ZodSchema = z.ZodAny> {
4774
4739
  private config;
4775
4740
  /**
4776
4741
  * Set the tool name
4742
+ * @beta
4777
4743
  */
4778
4744
  name(name: string): this;
4779
4745
  /**
4780
4746
  * Set the tool description
4747
+ * @beta
4781
4748
  */
4782
4749
  description(description: string): this;
4783
4750
  /**
4784
4751
  * Set the input schema for the tool
4752
+ * @beta
4785
4753
  */
4786
4754
  schema<S extends z.ZodSchema>(schema: S): McpToolBuilder<S>;
4787
4755
  /**
4788
4756
  * Set the output schema for the tool
4757
+ * @beta
4789
4758
  */
4790
4759
  outSchema<S extends z.ZodSchema>(schema: S): McpToolBuilder<S>;
4791
4760
  /**
4792
4761
  * Set the handler function for the tool
4762
+ * @beta
4793
4763
  */
4794
4764
  handler(handler: McpToolHandler<z.infer<TSchema>>): this;
4795
4765
  /**
4796
4766
  * Build the tool definition
4767
+ * @beta
4797
4768
  */
4798
4769
  build(): McpToolDefinition<z.infer<TSchema>>;
4799
4770
  }
4800
4771
 
4801
4772
  /**
4802
4773
  * Definition of a custom MCP tool
4774
+ * @beta
4803
4775
  */
4804
4776
  export declare interface McpToolDefinition<TSchema = any> {
4805
4777
  name: string;
@@ -4811,6 +4783,7 @@ export declare interface McpToolDefinition<TSchema = any> {
4811
4783
 
4812
4784
  /**
4813
4785
  * Handler function for MCP tools
4786
+ * @beta
4814
4787
  */
4815
4788
  export declare type McpToolHandler<TArgs = any> = (
4816
4789
  args: TArgs,
@@ -4904,6 +4877,52 @@ export declare class MemoryZoneReadThroughCache<T = unknown> {
4904
4877
  /* Excluded from this release type: delete */
4905
4878
  }
4906
4879
 
4880
+ declare interface Meter {
4881
+ /**
4882
+ * The event type. This is used to match the event to a meter.
4883
+ */
4884
+ type: string;
4885
+ /**
4886
+ * A dictionary of additional data to be sent to OpenMeter (extensible in code).
4887
+ */
4888
+ data?: {
4889
+ [k: string]: unknown;
4890
+ };
4891
+ }
4892
+
4893
+ /**
4894
+ * Represents a meter event that will be sent to OpenMeter.
4895
+ * You can optionally override the CloudEvents fields like id, time, source, and subject.
4896
+ *
4897
+ * @example
4898
+ * ```typescript
4899
+ * const meter: Meter = {
4900
+ * type: "api-call",
4901
+ * data: {
4902
+ * endpoint: "/api/users",
4903
+ * method: "POST",
4904
+ * responseTime: 123
4905
+ * }
4906
+ * };
4907
+ * ```
4908
+ *
4909
+ * @example
4910
+ * ```typescript
4911
+ * // With custom CloudEvents fields
4912
+ * const meter: Meter = {
4913
+ * type: "llm-usage",
4914
+ * id: "custom-event-id-123",
4915
+ * subject: "user-456",
4916
+ * data: {
4917
+ * model: "gpt-4",
4918
+ * tokens: 1500
4919
+ * }
4920
+ * };
4921
+ * ```
4922
+ * @public
4923
+ */
4924
+ declare type Meter_2 = Partial<OpenMeterEvent> & Meter;
4925
+
4907
4926
  /**
4908
4927
  * Base class for determining type of plugin
4909
4928
  * @public
@@ -5089,7 +5108,7 @@ export declare interface MoesifInboundPolicyOptions {
5089
5108
  * The Monetization policy enables you to track & monetize by your API's usage
5090
5109
  *
5091
5110
  * @title Monetization
5092
- * @beta
5111
+ * @deprecated - Zuplo monetization v1 has been deprecated and will be removed in the future.
5093
5112
  * @param request - The ZuploRequest
5094
5113
  * @param context - The ZuploContext
5095
5114
  * @param options - The policy options set in policies.json
@@ -6105,9 +6124,12 @@ export declare interface OpenIdJwtInboundPolicyOptions {
6105
6124
  oAuthResourceMetadataEnabled?: boolean;
6106
6125
  }
6107
6126
 
6127
+ /* Excluded from this release type: OpenMeterEvent */
6128
+
6108
6129
  /**
6109
6130
  * OpenMeter is a usage metering service. This policy allows
6110
6131
  * you to send metering calls for each API to their event ingest endpoint.
6132
+ * It also supports entitlement checking to verify if a subject has access to a feature.
6111
6133
  *
6112
6134
  * @title OpenMeter Metering
6113
6135
  * @public
@@ -6117,73 +6139,105 @@ export declare interface OpenIdJwtInboundPolicyOptions {
6117
6139
  * @param policyName - The name of the policy as set in policies.json
6118
6140
  * @returns A Request or a Response
6119
6141
  */
6120
- export declare function OpenMeterMeteringInboundPolicy(
6121
- request: ZuploRequest,
6122
- context: ZuploContext,
6123
- options: OpenMeterMeteringInboundPolicy_2,
6124
- policyName: string
6125
- ): Promise<ZuploRequest<RequestGeneric_2>>;
6142
+ export declare class OpenMeterInboundPolicy extends InboundPolicy<OpenMeterInboundPolicyOptions> {
6143
+ #private;
6144
+ constructor(options: OpenMeterInboundPolicyOptions, policyName: string);
6145
+ handler(
6146
+ request: ZuploRequest<RequestGeneric>,
6147
+ context: ZuploContext
6148
+ ): Promise<ZuploRequest<RequestGeneric> | Response>;
6149
+ /**
6150
+ * Extracts the subject identifier from the request based on the configured subjectPath.
6151
+ * The subject is used as the customer/user identifier in OpenMeter events.
6152
+ *
6153
+ * @param request - The incoming request
6154
+ * @returns The subject identifier if found, undefined otherwise
6155
+ * @throws RuntimeError if subjectPath is configured but request.user is undefined
6156
+ */
6157
+ private getSubject;
6158
+ /**
6159
+ * Checks if a subject has access to a specific feature by querying the OpenMeter entitlements API.
6160
+ *
6161
+ * @param subject - The subject/customer identifier
6162
+ * @param featureKey - The feature key to check entitlements for
6163
+ * @param context - The Zuplo context for logging
6164
+ * @returns The entitlement result including access status and usage information
6165
+ */
6166
+ private checkEntitlement;
6167
+ /**
6168
+ * Sets up metering to send events to OpenMeter when the response matches the configured status codes.
6169
+ * Events are batched and sent asynchronously after the response is sent.
6170
+ *
6171
+ * @param request - The incoming request
6172
+ * @param context - The Zuplo context
6173
+ */
6174
+ private setupMetering;
6175
+ /**
6176
+ * Sets custom meters for the current request. This allows other policies or handlers
6177
+ * to define specific metering events that should be sent to OpenMeter.
6178
+ *
6179
+ * @param context - The Zuplo context
6180
+ * @param value - Array of meter configurations to use for this request
6181
+ *
6182
+ * @example
6183
+ * ```typescript
6184
+ * // In a custom policy or handler
6185
+ * OpenMeterInboundPolicy.setMeters(context, [
6186
+ * {
6187
+ * type: "api-call",
6188
+ * data: {
6189
+ * endpoint: request.url,
6190
+ * method: request.method,
6191
+ * tokens: 150
6192
+ * }
6193
+ * },
6194
+ * {
6195
+ * type: "llm-usage",
6196
+ * data: {
6197
+ * model: "gpt-4",
6198
+ * prompt_tokens: 100,
6199
+ * completion_tokens: 50
6200
+ * }
6201
+ * }
6202
+ * ]);
6203
+ * ```
6204
+ */
6205
+ static setMeters(context: ZuploContext, value: Meter_2 | Meter_2[]): void;
6206
+ }
6126
6207
 
6127
6208
  /**
6128
6209
  * Send usage metrics to OpenMeter.
6129
6210
  * @public
6130
6211
  */
6131
- declare interface OpenMeterMeteringInboundPolicy_2 {
6212
+ export declare interface OpenMeterInboundPolicyOptions {
6132
6213
  /**
6133
6214
  * The URL of the OpenMeter API endpoint.
6134
6215
  */
6135
- url: string;
6216
+ apiUrl?: string;
6136
6217
  /**
6137
6218
  * The API key to use when sending metering calls to OpenMeter.
6138
6219
  */
6139
- apiKey?: string;
6140
- /**
6141
- * The type of event to use when sending metering calls to OpenMeter (overridable in code).
6142
- */
6143
- eventType?: string;
6144
- /**
6145
- * The value to use when sending metering calls to OpenMeter (overridable in code).
6146
- */
6147
- meterValue?: number;
6220
+ apiKey: string;
6148
6221
  /**
6149
- * The path to the property on `request.user` contains the customer ID. For example `.data.accountNumber` would read the `request.user.data.accountNumber` property.
6222
+ * A single meter configuration or an array of meter configurations for OpenMeter.
6150
6223
  */
6151
- customerIdPropertyPath?: string;
6224
+ meter?: Meter | Meter[];
6152
6225
  /**
6153
- * The default customerId (subject) for all metering calls - overridable in code and by `customerIdPropertyPath`.
6226
+ * A list of successful status codes and ranges "200-299, 304" that should trigger a metering event.
6154
6227
  */
6155
- customerId?: string;
6228
+ meterOnStatusCodes?: string | number[];
6156
6229
  /**
6157
- * The source identifier for the event (e.g. service name).
6230
+ * The event's source (e.g. the service name).
6158
6231
  */
6159
- source?: string;
6232
+ eventSource?: string;
6160
6233
  /**
6161
- * A dictionary of additional data to be sent to OpenMeter (extensible in code).
6234
+ * A list of entitlements (feature keys) required in order for the call to be allowed.
6162
6235
  */
6163
- data?: {
6164
- [k: string]: unknown;
6165
- };
6236
+ requiredEntitlements?: string[];
6166
6237
  /**
6167
- * A list of successful status codes and ranges "200-299, 304" that should trigger a metering call to OpenMeter.
6238
+ * The path to the property on `request.user` that contains the subject used for meters and entitlements. For example `.data.accountId` would read the `request.user.data.accountId` property.
6168
6239
  */
6169
- statusCodes: string | number[];
6170
- }
6171
-
6172
- export declare type OpenMeterMeteringInboundPolicyOptions =
6173
- OpenMeterMeteringInboundPolicy_2;
6174
-
6175
- export declare class OpenMeterMeteringPolicy {
6176
- static setRequestProperties(
6177
- context: ZuploContext,
6178
- properties: OpenMeterMeteringProperties
6179
- ): void;
6180
- }
6181
-
6182
- declare interface OpenMeterMeteringProperties {
6183
- eventType: string;
6184
- customerId: string;
6185
- meterValue?: number;
6186
- data?: Record<string, unknown>;
6240
+ subjectPath?: string;
6187
6241
  }
6188
6242
 
6189
6243
  /**
@@ -8006,7 +8060,7 @@ export declare class StreamingZoneCache {
8006
8060
 
8007
8061
  /**
8008
8062
  * Adds stripe monetization routes and configuration
8009
- * @beta
8063
+ * @deprecated - This plugin is deprecated and will be removed in the future.
8010
8064
  */
8011
8065
  export declare class StripeMonetizationPlugin extends MeteringPlugin {
8012
8066
  private options;
@@ -8015,7 +8069,7 @@ export declare class StripeMonetizationPlugin extends MeteringPlugin {
8015
8069
  }
8016
8070
 
8017
8071
  /**
8018
- * @beta
8072
+ * @deprecated - This plugin is deprecated and will be removed in the future.
8019
8073
  */
8020
8074
  export declare interface StripeMonetizationPluginOptions {
8021
8075
  /**
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zuplo/runtime",
3
3
  "type": "module",
4
- "version": "6.58.0",
4
+ "version": "6.58.4",
5
5
  "repository": "https://github.com/zuplo/zuplo",
6
6
  "author": "Zuplo, Inc.",
7
7
  "exports": {