@zuplo/runtime 7.9.17 → 7.9.18

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,5 +22,5 @@
22
22
  * DEALINGS IN THE SOFTWARE.
23
23
  *--------------------------------------------------------------------------------------------*/
24
24
 
25
- import{E as p,J as c,M as u}from"../chunk-UJ56MYSD.js";import"../chunk-VTO3F6DK.js";import{a as d}from"../chunk-QGAJTUPE.js";import"../chunk-A3QGJZO7.js";import"../chunk-YJ2BHVUH.js";import{aa as i}from"../chunk-PBDT4FDO.js";import{a as o}from"../chunk-TYV53J3B.js";function w(l={request:new Request("https://api.example.com")}){let e=[];function t(s){e.push(Promise.resolve(s))}return o(t,"waitUntil"),{context:new a({event:{waitUntil:t},route:l.route,originalRequest:l.request}),invokeResponse:o(async()=>{await Promise.all(e)},"invokeResponse")}}o(w,"createMockContext");var g={path:"/",methods:["GET"],handler:{module:{},export:"default"},raw:o(()=>({}),"raw")},a=class extends EventTarget{static{o(this,"MockZuploContext")}#e;#t;contextId;requestId;log;route;custom;incomingRequestProperties;parentContext;analyticsContext;constructor({event:e,route:t=g,parentContext:n,originalRequest:r}){super(),this.requestId=crypto.randomUUID(),this.contextId=crypto.randomUUID(),this.log={info:i.console.info,log:i.console.log,debug:i.console.debug,warn:i.console.warn,error:i.console.error,setLogProperties:o(()=>{},"setLogProperties")},this.custom={},this.route=t,this.incomingRequestProperties={ip:"203.0.113.7",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,clientCert:void 0,clientMtlsVerificationStatus:void 0,clientMtlsVerificationReason:void 0,clientCertFingerprintSha256:void 0,clientCertNotBefore:void 0,clientCertNotAfter:void 0,clientCertIssuerDn:void 0,clientCertSubjectDn:void 0},this.parentContext=n,this.#e=e,this.#t=r,this.analyticsContext=new c(this.requestId)}waitUntil(e){this.#e.waitUntil(e)}invokeInboundPolicy(e,t){throw new Error("Not implemented")}invokeOutboundPolicy(e,t,n){throw new Error("Not implemented")}invokeRoute(e,t){throw new Error("Not implemented")}addResponseSendingHook(e){throw new Error("Not implemented")}addResponseSendingFinalHook(e){throw new Error("Not implemented")}addPreRequestHandler(e,t){let n;try{n=u.getContextExtensions(this)}catch{n=u.initialize(this,new d(this.#t??new Request("https://api.example.com")))}n.preRequestPhase??="active",p(this,n,e,t)}get preRequestHandlers(){let e;try{e=u.getContextExtensions(this)}catch{return[]}return(e.preRequestState?.entries??[]).map(t=>({policyName:t.policyName,name:t.name}))}addEventListener(e,t,n){let r=o(s=>{try{typeof t=="function"?t(s):t.handleEvent(s)}catch(m){throw this.log.error(`Error invoking event ${e}. See following logs for details.`),m}},"wrapped");super.addEventListener(e,r,n)}};export{a as MockZuploContext,w as createMockContext};
25
+ import{E as p,J as c,M as u}from"../chunk-GYEX3OZM.js";import"../chunk-VTO3F6DK.js";import{a as d}from"../chunk-QGAJTUPE.js";import"../chunk-A3QGJZO7.js";import"../chunk-YJ2BHVUH.js";import{aa as i}from"../chunk-PBDT4FDO.js";import{a as o}from"../chunk-TYV53J3B.js";function w(l={request:new Request("https://api.example.com")}){let e=[];function t(s){e.push(Promise.resolve(s))}return o(t,"waitUntil"),{context:new a({event:{waitUntil:t},route:l.route,originalRequest:l.request}),invokeResponse:o(async()=>{await Promise.all(e)},"invokeResponse")}}o(w,"createMockContext");var g={path:"/",methods:["GET"],handler:{module:{},export:"default"},raw:o(()=>({}),"raw")},a=class extends EventTarget{static{o(this,"MockZuploContext")}#e;#t;contextId;requestId;log;route;custom;incomingRequestProperties;parentContext;analyticsContext;constructor({event:e,route:t=g,parentContext:n,originalRequest:r}){super(),this.requestId=crypto.randomUUID(),this.contextId=crypto.randomUUID(),this.log={info:i.console.info,log:i.console.log,debug:i.console.debug,warn:i.console.warn,error:i.console.error,setLogProperties:o(()=>{},"setLogProperties")},this.custom={},this.route=t,this.incomingRequestProperties={ip:"203.0.113.7",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,clientCert:void 0,clientMtlsVerificationStatus:void 0,clientMtlsVerificationReason:void 0,clientCertFingerprintSha256:void 0,clientCertNotBefore:void 0,clientCertNotAfter:void 0,clientCertIssuerDn:void 0,clientCertSubjectDn:void 0},this.parentContext=n,this.#e=e,this.#t=r,this.analyticsContext=new c(this.requestId)}waitUntil(e){this.#e.waitUntil(e)}invokeInboundPolicy(e,t){throw new Error("Not implemented")}invokeOutboundPolicy(e,t,n){throw new Error("Not implemented")}invokeRoute(e,t){throw new Error("Not implemented")}addResponseSendingHook(e){throw new Error("Not implemented")}addResponseSendingFinalHook(e){throw new Error("Not implemented")}addPreRequestHandler(e,t){let n;try{n=u.getContextExtensions(this)}catch{n=u.initialize(this,new d(this.#t??new Request("https://api.example.com")))}n.preRequestPhase??="active",p(this,n,e,t)}get preRequestHandlers(){let e;try{e=u.getContextExtensions(this)}catch{return[]}return(e.preRequestState?.entries??[]).map(t=>({policyName:t.policyName,name:t.name}))}addEventListener(e,t,n){let r=o(s=>{try{typeof t=="function"?t(s):t.handleEvent(s)}catch(m){throw this.log.error(`Error invoking event ${e}. See following logs for details.`),m}},"wrapped");super.addEventListener(e,r,n)}};export{a as MockZuploContext,w as createMockContext};
26
26
  //# sourceMappingURL=index.js.map
@@ -540,6 +540,61 @@ export declare const AIGatewayInternalOnlyInboundPolicy: typeof InternalOnlyInbo
540
540
  export declare type AIGatewayInternalOnlyInboundPolicyOptions =
541
541
  InternalOnlyInboundPolicyOptions;
542
542
 
543
+ /**
544
+ * Spreads AI requests across a list of models. The policy cycles through the
545
+ * list, or keeps requests that share a key, such as a user or a conversation,
546
+ * on the same model. Most requests also get a retry model from the list. A
547
+ * request moves there when the chosen model stays rate limited. Chat
548
+ * completions and embeddings requests also move there when the model returns a
549
+ * server error, can't be reached, or times out.
550
+ *
551
+ * The policy picks the model for every request it handles and ignores the
552
+ * request's own `model`, so the list also limits which models clients can
553
+ * reach. An earlier policy's model selection is never overwritten.
554
+ *
555
+ * @title Model Load Balancing
556
+ * @product ai-gateway
557
+ * @requiresAI
558
+ * @param request - The ZuploRequest
559
+ * @param context - The ZuploContext
560
+ * @param options - The policy options set in policies.json
561
+ * @param policyName - The name of the policy as set in policies.json
562
+ * @returns The request with model routing stored in context, or a refusal
563
+ * @example
564
+ * ```json
565
+ * {
566
+ * "strategy": "round-robin",
567
+ * "models": {
568
+ * "completions": [
569
+ * "azure-eastus/gpt-5",
570
+ * "azure-westus/gpt-5",
571
+ * "openai/gpt-5"
572
+ * ]
573
+ * }
574
+ * }
575
+ * ```
576
+ */
577
+ export declare class AIGatewayLoadBalancingInboundPolicy extends InboundPolicy<AIGatewayLoadBalancingInboundPolicyOptions> {
578
+ #private;
579
+ static readonly policyType = "ai-gateway-load-balancing";
580
+ handler(
581
+ request: ZuploRequest,
582
+ context: ZuploContext
583
+ ): Promise<ZuploRequest | Response>;
584
+ }
585
+
586
+ /**
587
+ * Options for spreading AI Gateway requests across a list of models.
588
+ * @public
589
+ */
590
+ export declare interface AIGatewayLoadBalancingInboundPolicyOptions {
591
+ strategy?: Strategy;
592
+ stickyBy?: StickyBy;
593
+ expression?: Expression;
594
+ models: Models;
595
+ fallbackTimeoutSeconds?: FallbackTimeoutSeconds_2;
596
+ }
597
+
543
598
  /* Excluded from this release type: AIGatewayMeterIncrements */
544
599
 
545
600
  /**
@@ -721,7 +776,7 @@ export { AIGatewayModelFilteringInboundPolicy as AIGatewayModelFilteringV2Inboun
721
776
  * @public
722
777
  */
723
778
  declare interface AIGatewayModelFilteringInboundPolicyOptions {
724
- models: Models;
779
+ models: Models_2;
725
780
  }
726
781
  export { AIGatewayModelFilteringInboundPolicyOptions };
727
782
  export { AIGatewayModelFilteringInboundPolicyOptions as AIGatewayModelFilteringV2InboundPolicyOptions };
@@ -799,7 +854,7 @@ export declare class AIGatewayModelOverrideInboundPolicy extends InboundPolicy<A
799
854
  * @public
800
855
  */
801
856
  export declare interface AIGatewayModelOverrideInboundPolicyOptions {
802
- models: Models_2;
857
+ models: Models_3;
803
858
  }
804
859
 
805
860
  /**
@@ -1608,13 +1663,13 @@ export declare interface AkamaiFirewallForAiOutboundPolicyOptions {
1608
1663
  * @minItems 1
1609
1664
  * @public
1610
1665
  */
1611
- declare type AllowedModels = [ProviderAndModel, ...ProviderAndModel[]];
1666
+ declare type AllowedModels = [ProviderAndModel_2, ...ProviderAndModel_2[]];
1612
1667
 
1613
1668
  /**
1614
1669
  * @minItems 1
1615
1670
  * @public
1616
1671
  */
1617
- declare type AllowedModels1 = [ProviderAndModel, ...ProviderAndModel[]];
1672
+ declare type AllowedModels1 = [ProviderAndModel_2, ...ProviderAndModel_2[]];
1618
1673
 
1619
1674
  /**
1620
1675
  * Amberflo is a usage metering and billing service. This policy allows
@@ -3203,13 +3258,13 @@ declare interface BatchDispatcherOptions {
3203
3258
  * @minItems 1
3204
3259
  * @public
3205
3260
  */
3206
- declare type BlockedModels = [ProviderAndModel, ...ProviderAndModel[]];
3261
+ declare type BlockedModels = [ProviderAndModel_2, ...ProviderAndModel_2[]];
3207
3262
 
3208
3263
  /**
3209
3264
  * @minItems 1
3210
3265
  * @public
3211
3266
  */
3212
- declare type BlockedModels1 = [ProviderAndModel, ...ProviderAndModel[]];
3267
+ declare type BlockedModels1 = [ProviderAndModel_2, ...ProviderAndModel_2[]];
3213
3268
 
3214
3269
  /**
3215
3270
  * The brownout policy allows performing scheduled downtime on your API
@@ -4179,11 +4234,20 @@ declare interface CompletionsFallbacks {
4179
4234
  quotaFallback?: QuotaFallbackModel;
4180
4235
  }
4181
4236
 
4237
+ /**
4238
+ * Models for chat completions, Responses, Messages, and System One requests, as `providerName/model`. From 1 through 32 models, each listed once. Provider names aren't case-sensitive, so `openai/gpt-5` and `OpenAI/gpt-5` are the same model. Write each model ID exactly as your provider spells it.
4239
+ *
4240
+ * @minItems 1
4241
+ * @maxItems 32
4242
+ * @public
4243
+ */
4244
+ declare type CompletionsModels = [ProviderAndModel, ...ProviderAndModel[]];
4245
+
4182
4246
  /**
4183
4247
  * Rules for chat completions, Responses, and Anthropic Messages requests.
4184
4248
  * @public
4185
4249
  */
4186
- declare type CompletionsModels =
4250
+ declare type CompletionsModels_2 =
4187
4251
  | {
4188
4252
  allowList: AllowedModels;
4189
4253
  }
@@ -5321,11 +5385,20 @@ declare interface EmbeddingsFallbacks {
5321
5385
  quotaFallback?: QuotaFallbackModel;
5322
5386
  }
5323
5387
 
5388
+ /**
5389
+ * Models for embeddings requests, as `providerName/model`. From 1 through 32 models, each listed once. Provider names aren't case-sensitive. Write each model ID exactly as your provider spells it. Every entry must be the same embedding model, such as one model on several accounts.
5390
+ *
5391
+ * @minItems 1
5392
+ * @maxItems 32
5393
+ * @public
5394
+ */
5395
+ declare type EmbeddingsModels = [ProviderAndModel, ...ProviderAndModel[]];
5396
+
5324
5397
  /**
5325
5398
  * Rules for embedding requests.
5326
5399
  * @public
5327
5400
  */
5328
- declare type EmbeddingsModels =
5401
+ declare type EmbeddingsModels_2 =
5329
5402
  | {
5330
5403
  allowList: AllowedModels1;
5331
5404
  }
@@ -5429,6 +5502,12 @@ declare type EventType = (typeof EventType)[keyof typeof EventType];
5429
5502
  */
5430
5503
  declare type Execution = "sequential" | "parallel";
5431
5504
 
5505
+ /**
5506
+ * The value to key on, written like a {@link https://zuplo.com/docs/policies/ai-gateway-metering-inbound#budget-expressions|Metering budget expression}, such as `request.headers.get("x-end-user-id")`. Required when `stickyBy` is `expression`, and not allowed otherwise.
5507
+ * @public
5508
+ */
5509
+ declare type Expression = string;
5510
+
5432
5511
  /**
5433
5512
  * Best-effort flatten of ALL human/assistant text in a request OR response body,
5434
5513
  * across every shape — the one sanctioned cross-shape helper. Intended for
@@ -5492,6 +5571,12 @@ declare interface FallbackModels {
5492
5571
  */
5493
5572
  declare type FallbackTimeoutSeconds = number;
5494
5573
 
5574
+ /**
5575
+ * How long to wait for a model to start responding before retrying the request on another model. Applies to chat completions and embeddings. The timeout ends when the response starts, so it doesn't cut off a long streaming response. A response that doesn't stream starts only when it's complete, so the timeout covers the whole response. From 1 through 300.
5576
+ * @public
5577
+ */
5578
+ declare type FallbackTimeoutSeconds_2 = number;
5579
+
5495
5580
  declare interface FetchOptions<T> {
5496
5581
  method?: HttpMethod_2;
5497
5582
  data?: T;
@@ -10681,7 +10766,7 @@ declare interface ModelConfiguration {
10681
10766
  }
10682
10767
 
10683
10768
  /**
10684
- * Model filtering rules grouped by AI Gateway capability.
10769
+ * The models to spread requests across, by request type. Set at least one list.
10685
10770
  * @public
10686
10771
  */
10687
10772
  declare interface Models {
@@ -10690,10 +10775,19 @@ declare interface Models {
10690
10775
  }
10691
10776
 
10692
10777
  /**
10693
- * Override rules grouped by AI Gateway capability.
10778
+ * Model filtering rules grouped by AI Gateway capability.
10694
10779
  * @public
10695
10780
  */
10696
10781
  declare interface Models_2 {
10782
+ completions?: CompletionsModels_2;
10783
+ embeddings?: EmbeddingsModels_2;
10784
+ }
10785
+
10786
+ /**
10787
+ * Override rules grouped by AI Gateway capability.
10788
+ * @public
10789
+ */
10790
+ declare interface Models_3 {
10697
10791
  completions?: CompletionsOverride;
10698
10792
  embeddings?: EmbeddingsOverride;
10699
10793
  }
@@ -12686,6 +12780,12 @@ export declare interface PropelAuthJwtInboundPolicyOptions {
12686
12780
  */
12687
12781
  declare type ProviderAndModel = string;
12688
12782
 
12783
+ /**
12784
+ * A model reference in providerName/model form, split on the first slash.
12785
+ * @public
12786
+ */
12787
+ declare type ProviderAndModel_2 = string;
12788
+
12689
12789
  /**
12690
12790
  * Extracts a query parameter and sets it as a header in the request.
12691
12791
  *
@@ -14445,6 +14545,18 @@ declare interface StartsWithRule {
14445
14545
  startsWith: string;
14446
14546
  }
14447
14547
 
14548
+ /**
14549
+ * The key that `sticky` uses. `user` uses the authenticated caller, `request.user.sub`. `conversation` uses the conversation's system prompt and its first user message with text. `expression` uses the value that `expression` selects. Required when `strategy` is `sticky`, and not allowed with `round-robin`.
14550
+ * @public
14551
+ */
14552
+ declare type StickyBy = "user" | "conversation" | "expression";
14553
+
14554
+ /**
14555
+ * How the policy picks a model for each request. `round-robin` cycles through the list in order. `sticky` sends every request with the same key to the same model.
14556
+ * @public
14557
+ */
14558
+ declare type Strategy = "round-robin" | "sticky";
14559
+
14448
14560
  /**
14449
14561
  * Configuration for accumulating and validating streaming responses.
14450
14562
  * @public
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zuplo/runtime",
3
3
  "type": "module",
4
- "version": "7.9.17",
4
+ "version": "7.9.18",
5
5
  "repository": "https://github.com/zuplo/zuplo",
6
6
  "author": "Zuplo, Inc.",
7
7
  "exports": {