@zuplo/runtime 7.9.13 → 7.9.14

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-2XSPVUOE.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-Q3IDJ2WR.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
@@ -1255,6 +1255,15 @@ export declare interface AIGatewaySmartRouterResult {
1255
1255
  profile: AIGatewaySmartRouterProfile;
1256
1256
  usage: AIGatewaySmartRouterTokenUsage;
1257
1257
  classifierModel: string;
1258
+ /**
1259
+ * Classifier cost in USD, separate from the routed model's cost. An unpriced
1260
+ * zero means unknown, not free. Optional for results written by older code.
1261
+ */
1262
+ cost?: {
1263
+ costUsd: number;
1264
+ source: "provider" | "catalog" | "unpriced";
1265
+ accuracy: "exact" | "estimated" | "unpriced";
1266
+ };
1258
1267
  routing: AIGatewaySmartRouterRoutingDecision;
1259
1268
  durationMs: number;
1260
1269
  promptSource: AIGatewaySmartRouterPromptSource;
@@ -1279,16 +1288,29 @@ export declare interface AIGatewaySmartRouterRoutingDecision {
1279
1288
  }
1280
1289
 
1281
1290
  /**
1282
- * Classifier token usage reported by the classifier call. For Jev,
1283
- * `promptTokens` and `completionTokens` are the input and output tokens that
1284
- * the Jev API reports.
1291
+ * Classifier token usage from gateway accounting for app classifiers. Missing
1292
+ * accounting headers produce zero counts, without a provider-body fallback.
1293
+ * Deprecated direct classifiers retain the provider-reported counts; for Jev,
1294
+ * input and output tokens map directly to these fields.
1285
1295
  *
1286
1296
  * @public
1287
1297
  */
1288
1298
  export declare interface AIGatewaySmartRouterTokenUsage {
1289
- promptTokens: number;
1290
- completionTokens: number;
1299
+ inputTokens: number;
1300
+ outputTokens: number;
1291
1301
  totalTokens: number;
1302
+ /** Disjoint accounting categories already included in the totals above. */
1303
+ breakdown?: {
1304
+ uncachedInputTokens: number;
1305
+ cacheReadInputTokens?: number;
1306
+ /** Cache writes grouped by TTL when accounting reports that detail. */
1307
+ cacheWriteInput?: Array<{
1308
+ tokens: number;
1309
+ cacheTtl?: "5m" | "1h";
1310
+ }>;
1311
+ visibleOutputTokens: number;
1312
+ reasoningOutputTokens?: number;
1313
+ };
1292
1314
  }
1293
1315
 
1294
1316
  /**
@@ -3711,7 +3733,7 @@ declare interface ChatCompletionResponse {
3711
3733
 
3712
3734
  /**
3713
3735
  * @deprecated
3714
- * Deprecated: use classifier.adapter with flat apiKey, model, and baseUrl fields. Classify by calling an OpenAI-compatible Chat Completions API directly, outside the gateway. The model must support structured outputs (`response_format` with a JSON schema).
3736
+ * Deprecated: use `classifier.app` instead. Classify by calling an OpenAI-compatible Chat Completions API directly, outside the gateway. The model must support structured outputs (`response_format` with a JSON schema).
3715
3737
  * @public
3716
3738
  */
3717
3739
  declare interface ChatCompletionsAPI {
@@ -3757,31 +3779,15 @@ declare type Claim = string;
3757
3779
  declare type ClaimCheck = EqualsRule | InRule | StartsWithRule;
3758
3780
 
3759
3781
  /**
3760
- * Where the prompt is classified. For a direct API, set adapter, apiKey, model, and optional baseUrl. Alternatively set app. Legacy chatCompletions and jev sections remain supported; do not mix forms.
3782
+ * Where the prompt is classified. Set exactly one of `app`, `chatCompletions`, or `jev`. `app.adapter` selects the API that classifier app exposes. Setting more than one section is a configuration error.
3761
3783
  * @public
3762
3784
  */
3763
3785
  declare interface Classifier {
3764
3786
  app?: ClassifierApp;
3765
3787
  chatCompletions?: ChatCompletionsAPI;
3766
3788
  jev?: JevTypeSafe;
3767
- adapter?: ClassifierAdapter;
3768
- apiKey?: ClassifierAPIKey;
3769
- model?: ClassifierModel1;
3770
- baseUrl?: ClassifierBaseURL;
3771
3789
  }
3772
3790
 
3773
- /**
3774
- * API contract for direct classification. chatCompletions requires a model supporting JSON-schema structured outputs. systemOne uses the existing Jev typed-question implementation; it does not accept classifierPrompt.
3775
- * @public
3776
- */
3777
- declare type ClassifierAdapter = "chatCompletions" | "systemOne";
3778
-
3779
- /**
3780
- * API key for the direct classifier, sent as Authorization: Bearer.
3781
- * @public
3782
- */
3783
- declare type ClassifierAPIKey = string;
3784
-
3785
3791
  /**
3786
3792
  * Classify with another AI Gateway app in this project. The call runs in-process and never leaves the gateway, so the classifier uses that app's providers, routing, and quotas.
3787
3793
  * @public
@@ -3790,8 +3796,15 @@ declare interface ClassifierApp {
3790
3796
  appId: ClassifierAppID_2;
3791
3797
  model: ClassifierModel_2;
3792
3798
  apiKey?: ClassifierAppAPIKey;
3799
+ adapter?: ClassifierAppAdapter;
3793
3800
  }
3794
3801
 
3802
+ /**
3803
+ * API contract exposed by the classifier app. chatCompletions calls /v1/chat/completions; systemOne calls /v1/systemone for models such as Jev. The app owns provider credentials, pricing, metering and analytics.
3804
+ * @public
3805
+ */
3806
+ declare type ClassifierAppAdapter = "chatCompletions" | "systemOne";
3807
+
3795
3808
  /**
3796
3809
  * API key sent as `Authorization: Bearer` when invoking the classifier app. Omit it when the classifier app runs the Internal Only policy: the classifier call never leaves the gateway, so that policy accepts it and rejects everything arriving over the network, and no credential is sent. Set it only when the classifier app authenticates callers with API keys.
3797
3810
  * @public
@@ -3822,12 +3835,6 @@ declare type ClassifierAppID_2 = string;
3822
3835
  */
3823
3836
  declare type ClassifierAppIDDeprecated = string;
3824
3837
 
3825
- /**
3826
- * HTTP(S) API root. chatCompletions defaults to https://api.openai.com/v1 and appends /chat/completions. systemOne defaults to https://api.typesafe.ai and appends /v1/systemone.
3827
- * @public
3828
- */
3829
- declare type ClassifierBaseURL = string;
3830
-
3831
3838
  /**
3832
3839
  * Tool-calling capable model used to classify prompts. Prefer a small, fast model; the classification runs before every inspected request reaches the upstream model. With `appId` set this must name a model the classifier app routes, written as `provider/model` (for example `openai/gpt-4o-mini`), and has no default.
3833
3840
  * @public
@@ -3835,13 +3842,7 @@ declare type ClassifierBaseURL = string;
3835
3842
  declare type ClassifierModel = string;
3836
3843
 
3837
3844
  /**
3838
- * Model id sent to the direct API. Required for chatCompletions; defaults to jev-latest for systemOne.
3839
- * @public
3840
- */
3841
- declare type ClassifierModel1 = string;
3842
-
3843
- /**
3844
- * The model (`providerName/model`) the classifier app uses to evaluate the user's request. E.g. `openai/gpt-4o-mini`.
3845
+ * The model (`providerName/model`) the classifier app uses to evaluate the user's request. `providerName` is the name of the provider as configured on the classifier app, not a fixed vendor id. E.g. `openai/gpt-4o-mini`, or `jev/jev-latest` when the Jev provider is named `jev`.
3845
3846
  * @public
3846
3847
  */
3847
3848
  declare type ClassifierModel_2 = string;
@@ -3859,7 +3860,7 @@ declare type ClassifierModelDeprecated = string;
3859
3860
  declare type ClassifierPrompt = string | [string, ...string[]];
3860
3861
 
3861
3862
  /**
3862
- * Prompt for classifier.app or the chatCompletions adapter (including its legacy section). Omit to use the built-in prompt. The systemOne adapter and legacy jev section take no prompt; combining them with classifierPrompt is a configuration error.
3863
+ * Prompt for classifier.app (its default or chatCompletions adapter) and classifier.chatCompletions. Omit to use the built-in prompt. classifier.app.adapter systemOne and classifier.jev take no prompt; combining them with classifierPrompt is a configuration error.
3863
3864
  * @public
3864
3865
  */
3865
3866
  declare type ClassifierPrompt_2 = string | [string, ...string[]];
@@ -8257,7 +8258,7 @@ declare type JevModel = string;
8257
8258
 
8258
8259
  /**
8259
8260
  * @deprecated
8260
- * Deprecated: use classifier.adapter with flat apiKey, model, and baseUrl fields. Classify with Jev, TypeSafe's classification model, by calling a System One API directly: TypeSafe's by default, or another host such as OpenRouter through `baseUrl`. Jev answers typed questions instead of generating text, so it takes no `classifierPrompt`.
8261
+ * Deprecated: use `classifier.app` with `adapter` `systemOne` instead. Classify with Jev, TypeSafe's classification model, by calling a System One API directly: TypeSafe's by default, or another host such as OpenRouter through `baseUrl`. Jev answers typed questions instead of generating text, so it takes no `classifierPrompt`.
8261
8262
  * @public
8262
8263
  */
8263
8264
  declare interface JevTypeSafe {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@zuplo/runtime",
3
3
  "type": "module",
4
- "version": "7.9.13",
4
+ "version": "7.9.14",
5
5
  "repository": "https://github.com/zuplo/zuplo",
6
6
  "author": "Zuplo, Inc.",
7
7
  "exports": {