@truefoundry/ai-gateway-sdk 0.0.7 → 0.0.9
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.
- package/dist/autogen/decoders.d.ts +5 -1
- package/dist/autogen/decoders.js +44 -0
- package/dist/autogen/decoders.js.map +1 -1
- package/dist/autogen/meta.d.ts +5 -1
- package/dist/autogen/meta.js +4 -0
- package/dist/autogen/meta.js.map +1 -1
- package/dist/autogen/models.d.ts +169 -4
- package/dist/autogen/schema.json +190 -3
- package/dist/constants.d.ts +10 -0
- package/dist/constants.js +8 -0
- package/dist/constants.js.map +1 -1
- package/dist/handlers/retryHandler.d.ts +4 -0
- package/dist/handlers/retryHandler.js +23 -0
- package/dist/handlers/retryHandler.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/providers/anthropic/api.js +4 -4
- package/dist/providers/anthropic/api.js.map +1 -1
- package/dist/providers/google-vertex-ai/api.js +60 -8
- package/dist/providers/google-vertex-ai/api.js.map +1 -1
- package/dist/providers/google-vertex-ai/types.d.ts +6 -1
- package/dist/providers/google-vertex-ai/types.js +2 -0
- package/dist/providers/google-vertex-ai/types.js.map +1 -1
- package/dist/providers/truefoundry-managed/index.js +7 -4
- package/dist/providers/truefoundry-managed/index.js.map +1 -1
- package/dist/providers/truefoundry-managed/insufficientCredit.d.ts +6 -0
- package/dist/providers/truefoundry-managed/insufficientCredit.js +20 -0
- package/dist/providers/truefoundry-managed/insufficientCredit.js.map +1 -0
- package/dist/providers/utils/finishReasonMap.js +1 -0
- package/dist/providers/utils/finishReasonMap.js.map +1 -1
- package/dist/services/execute.js +30 -2
- package/dist/services/execute.js.map +1 -1
- package/dist/services/handleProviderResponse.d.ts +3 -1
- package/dist/services/handleProviderResponse.js +2 -0
- package/dist/services/handleProviderResponse.js.map +1 -1
- package/dist/types/contracts.d.ts +1 -1
- package/dist/types/executionReport.d.ts +13 -0
- package/dist/types/options.d.ts +2 -0
- package/dist/types/requestBody.d.ts +0 -2
- package/dist/types/requestBody.js.map +1 -1
- package/dist/utils/deriveProviderHeaderOptions.js +2 -0
- package/dist/utils/deriveProviderHeaderOptions.js.map +1 -1
- package/dist/utils/providerFailureLogging.d.ts +36 -0
- package/dist/utils/providerFailureLogging.js +110 -0
- package/dist/utils/providerFailureLogging.js.map +1 -0
- package/dist/utils/vertexApiVersion.d.ts +7 -0
- package/dist/utils/vertexApiVersion.js +16 -0
- package/dist/utils/vertexApiVersion.js.map +1 -0
- package/package.json +1 -1
package/dist/autogen/schema.json
CHANGED
|
@@ -5946,8 +5946,14 @@
|
|
|
5946
5946
|
"provider_accounts": {
|
|
5947
5947
|
"$ref": "#/definitions/BudgetV2InNotInFilter"
|
|
5948
5948
|
},
|
|
5949
|
+
"virtual_models": {
|
|
5950
|
+
"$ref": "#/definitions/BudgetV2InNotInFilter"
|
|
5951
|
+
},
|
|
5952
|
+
"virtual_provider_accounts": {
|
|
5953
|
+
"$ref": "#/definitions/BudgetV2InNotInFilter"
|
|
5954
|
+
},
|
|
5949
5955
|
"metadata": {
|
|
5950
|
-
"description": "+usage=Filter by metadata key-value pairs this budget applies to\n+label=Metadata\n+sort=
|
|
5956
|
+
"description": "+usage=Filter by metadata key-value pairs this budget applies to\n+label=Metadata\n+sort=6",
|
|
5951
5957
|
"type": "object",
|
|
5952
5958
|
"additionalProperties": {
|
|
5953
5959
|
"$ref": "#/definitions/BudgetV2InNotInFilter"
|
|
@@ -5969,8 +5975,14 @@
|
|
|
5969
5975
|
"provider_accounts": {
|
|
5970
5976
|
"$ref": "#/definitions/BudgetV2InNotInFilter"
|
|
5971
5977
|
},
|
|
5978
|
+
"virtual_models": {
|
|
5979
|
+
"$ref": "#/definitions/BudgetV2InNotInFilter"
|
|
5980
|
+
},
|
|
5981
|
+
"virtual_provider_accounts": {
|
|
5982
|
+
"$ref": "#/definitions/BudgetV2InNotInFilter"
|
|
5983
|
+
},
|
|
5972
5984
|
"metadata": {
|
|
5973
|
-
"description": "+usage=Filter by metadata key-value pairs this budget applies to\n+label=Metadata\n+sort=
|
|
5985
|
+
"description": "+usage=Filter by metadata key-value pairs this budget applies to\n+label=Metadata\n+sort=6",
|
|
5974
5986
|
"type": "object",
|
|
5975
5987
|
"additionalProperties": {
|
|
5976
5988
|
"$ref": "#/definitions/BudgetV2InNotInFilter"
|
|
@@ -9899,6 +9911,80 @@
|
|
|
9899
9911
|
},
|
|
9900
9912
|
"$schema": "http://json-schema.org/draft-04/schema#"
|
|
9901
9913
|
},
|
|
9914
|
+
"FireworksApiKeyAuth": {
|
|
9915
|
+
"description": "+label=Fireworks API Key Auth\n+usage=Authentication using a Fireworks API key",
|
|
9916
|
+
"type": "object",
|
|
9917
|
+
"required": ["type", "api_key"],
|
|
9918
|
+
"properties": {
|
|
9919
|
+
"type": {
|
|
9920
|
+
"description": "+value=api-key",
|
|
9921
|
+
"type": "string",
|
|
9922
|
+
"enum": ["api-key"]
|
|
9923
|
+
},
|
|
9924
|
+
"api_key": {
|
|
9925
|
+
"description": "+sort=100\n+usage=Fireworks API key (sent as a Bearer token). Create one in the Fireworks console.\n+message=API key must not be empty\n+uiType=SecretSelect\n+uiProps={\"isPassword\": true, \"enableNew\": true}",
|
|
9926
|
+
"type": "string",
|
|
9927
|
+
"pattern": "^\\S+$"
|
|
9928
|
+
}
|
|
9929
|
+
},
|
|
9930
|
+
"$schema": "http://json-schema.org/draft-04/schema#"
|
|
9931
|
+
},
|
|
9932
|
+
"FireworksGuardrailConfig": {
|
|
9933
|
+
"description": "+label=Fireworks\n+icon=https://assets.production.truefoundry.com/fireworks.svg",
|
|
9934
|
+
"type": "object",
|
|
9935
|
+
"required": ["name", "type", "auth_data", "operation", "enforcing_strategy", "config"],
|
|
9936
|
+
"properties": {
|
|
9937
|
+
"name": {
|
|
9938
|
+
"description": "+label=Name\n+sort=50\n+usage=The name of the Guardrail Config.\n+message=3 to 36 lower case characters long alphanumeric word, may contain - in between, cannot start with a number\n+uiProps={\"disableEdit\":true}",
|
|
9939
|
+
"type": "string",
|
|
9940
|
+
"pattern": "^[a-z][a-z0-9\\-]{1,34}[a-z0-9]$"
|
|
9941
|
+
},
|
|
9942
|
+
"description": {
|
|
9943
|
+
"description": "+label=Description\n+sort=75\n+usage=Optional description for this Guardrail Config.",
|
|
9944
|
+
"type": "string",
|
|
9945
|
+
"default": "Fireworks-hosted safety model (gpt-oss-safeguard or Llama Guard) for policy-based content classification"
|
|
9946
|
+
},
|
|
9947
|
+
"type": {
|
|
9948
|
+
"description": "+uiType=Hidden\n+value=integration/guardrail-config/fireworks",
|
|
9949
|
+
"type": "string",
|
|
9950
|
+
"enum": ["integration/guardrail-config/fireworks"]
|
|
9951
|
+
},
|
|
9952
|
+
"auth_data": {
|
|
9953
|
+
"$ref": "#/definitions/FireworksApiKeyAuth"
|
|
9954
|
+
},
|
|
9955
|
+
"operation": {
|
|
9956
|
+
"description": "+label=Operation\n+usage=Fireworks safety models classify content without modifying it.\n+uiType=MultiSelectPills\n+uiProps={\"hideRadioIcon\": true}\n+sort=100",
|
|
9957
|
+
"type": "string",
|
|
9958
|
+
"enum": ["validate"]
|
|
9959
|
+
},
|
|
9960
|
+
"enforcing_strategy": {
|
|
9961
|
+
"$ref": "#/definitions/EnforcingStrategy"
|
|
9962
|
+
},
|
|
9963
|
+
"config": {
|
|
9964
|
+
"description": "+uiType=Ignore\n+uiProps={\"forwardJsonKey\": true}",
|
|
9965
|
+
"type": "object",
|
|
9966
|
+
"required": ["model", "model_type"],
|
|
9967
|
+
"properties": {
|
|
9968
|
+
"model": {
|
|
9969
|
+
"description": "+label=Model\n+usage=Deployment name from your Fireworks account (accounts/<account>/deployments/<deployment>). Safety models run on dedicated (on-demand) deployments only.\n+message=Model must not be empty\n+sort=50",
|
|
9970
|
+
"type": "string",
|
|
9971
|
+
"pattern": "^\\S+$"
|
|
9972
|
+
},
|
|
9973
|
+
"model_type": {
|
|
9974
|
+
"description": "+label=Model Type\n+usage=gpt-oss-safeguard classifies content against the policy below. llama-guard classifies against Meta's fixed hazard categories (S1 to S14 for Llama Guard 3 8B) and ignores the policy.\n+uiType=Select\n+sort=100",
|
|
9975
|
+
"type": "string",
|
|
9976
|
+
"enum": ["gpt-oss-safeguard", "llama-guard"],
|
|
9977
|
+
"default": "gpt-oss-safeguard"
|
|
9978
|
+
},
|
|
9979
|
+
"policy": {
|
|
9980
|
+
"description": "+label=Policy\n+usage=Safety policy the model applies (required for gpt-oss-safeguard, ignored for llama-guard). Describe what violates and what is safe, with examples. Do not put secrets in the policy.\n+uiType=TextArea\n+uiProps={\"descriptionInline\":true}\n+sort=150",
|
|
9981
|
+
"type": "string"
|
|
9982
|
+
}
|
|
9983
|
+
}
|
|
9984
|
+
}
|
|
9985
|
+
},
|
|
9986
|
+
"$schema": "http://json-schema.org/draft-04/schema#"
|
|
9987
|
+
},
|
|
9902
9988
|
"FlyteLaunchPlan": {
|
|
9903
9989
|
"type": "object",
|
|
9904
9990
|
"required": ["id", "spec", "closure"],
|
|
@@ -12728,6 +12814,12 @@
|
|
|
12728
12814
|
},
|
|
12729
12815
|
{
|
|
12730
12816
|
"$ref": "#/definitions/HiddenLayerGuardrailConfig"
|
|
12817
|
+
},
|
|
12818
|
+
{
|
|
12819
|
+
"$ref": "#/definitions/FireworksGuardrailConfig"
|
|
12820
|
+
},
|
|
12821
|
+
{
|
|
12822
|
+
"$ref": "#/definitions/ZscalerAIGuardGuardrailConfig"
|
|
12731
12823
|
}
|
|
12732
12824
|
],
|
|
12733
12825
|
"$schema": "http://json-schema.org/draft-04/schema#"
|
|
@@ -21336,8 +21428,14 @@
|
|
|
21336
21428
|
"provider_accounts": {
|
|
21337
21429
|
"$ref": "#/definitions/RateLimitV2InNotInFilter"
|
|
21338
21430
|
},
|
|
21431
|
+
"virtual_models": {
|
|
21432
|
+
"$ref": "#/definitions/RateLimitV2InNotInFilter"
|
|
21433
|
+
},
|
|
21434
|
+
"virtual_provider_accounts": {
|
|
21435
|
+
"$ref": "#/definitions/RateLimitV2InNotInFilter"
|
|
21436
|
+
},
|
|
21339
21437
|
"metadata": {
|
|
21340
|
-
"description": "+usage=Filter by metadata key-value pairs this rate limit applies to\n+label=Metadata\n+sort=
|
|
21438
|
+
"description": "+usage=Filter by metadata key-value pairs this rate limit applies to\n+label=Metadata\n+sort=6",
|
|
21341
21439
|
"type": "object",
|
|
21342
21440
|
"additionalProperties": {
|
|
21343
21441
|
"$ref": "#/definitions/RateLimitV2InNotInFilter"
|
|
@@ -28411,6 +28509,83 @@
|
|
|
28411
28509
|
"type": "string",
|
|
28412
28510
|
"enum": ["cloudpickle", "joblib", "pickle", "json"],
|
|
28413
28511
|
"$schema": "http://json-schema.org/draft-04/schema#"
|
|
28512
|
+
},
|
|
28513
|
+
"ZscalerAIGuardApiKeyAuth": {
|
|
28514
|
+
"description": "+label=Zscaler AI Guard API Key Auth",
|
|
28515
|
+
"type": "object",
|
|
28516
|
+
"required": ["type", "api_key"],
|
|
28517
|
+
"properties": {
|
|
28518
|
+
"type": {
|
|
28519
|
+
"description": "+value=api-key",
|
|
28520
|
+
"type": "string",
|
|
28521
|
+
"enum": ["api-key"]
|
|
28522
|
+
},
|
|
28523
|
+
"api_key": {
|
|
28524
|
+
"description": "+sort=100\n+usage=Zscaler AI Guard API key. Sent as a Bearer token against the AI Guard detection API.\n+message=API key must not be empty\n+uiType=SecretSelect\n+uiProps={\"isPassword\": true, \"enableNew\": true}",
|
|
28525
|
+
"type": "string",
|
|
28526
|
+
"pattern": "^\\S+$"
|
|
28527
|
+
}
|
|
28528
|
+
},
|
|
28529
|
+
"$schema": "http://json-schema.org/draft-04/schema#"
|
|
28530
|
+
},
|
|
28531
|
+
"ZscalerAIGuardGuardrailConfig": {
|
|
28532
|
+
"description": "+label=Zscaler AI Guard\n+icon=https://assets.production.truefoundry.com/zscaler.svg",
|
|
28533
|
+
"type": "object",
|
|
28534
|
+
"required": ["name", "type", "auth_data", "operation", "enforcing_strategy", "config"],
|
|
28535
|
+
"properties": {
|
|
28536
|
+
"name": {
|
|
28537
|
+
"description": "+label=Name\n+sort=50\n+usage=The name of the Guardrail Config.\n+message=3 to 36 lower case characters long alphanumeric word, may contain - in between, cannot start with a number\n+uiProps={\"disableEdit\":true}",
|
|
28538
|
+
"type": "string",
|
|
28539
|
+
"pattern": "^[a-z][a-z0-9\\-]{1,34}[a-z0-9]$"
|
|
28540
|
+
},
|
|
28541
|
+
"description": {
|
|
28542
|
+
"description": "+label=Description\n+sort=75\n+usage=Optional description for this Guardrail Config.",
|
|
28543
|
+
"type": "string",
|
|
28544
|
+
"default": "Zscaler AI Guard runtime protection for prompts and model responses"
|
|
28545
|
+
},
|
|
28546
|
+
"type": {
|
|
28547
|
+
"description": "+uiType=Hidden\n+value=integration/guardrail-config/zscaler-ai-guard",
|
|
28548
|
+
"type": "string",
|
|
28549
|
+
"enum": ["integration/guardrail-config/zscaler-ai-guard"]
|
|
28550
|
+
},
|
|
28551
|
+
"auth_data": {
|
|
28552
|
+
"$ref": "#/definitions/ZscalerAIGuardApiKeyAuth"
|
|
28553
|
+
},
|
|
28554
|
+
"operation": {
|
|
28555
|
+
"description": "+label=Operation\n+usage=Validate treats a Zscaler BLOCK action as a violation and leaves the payload unchanged. Mutate also replaces content with Zscaler maskedContent when returned.\nValidate guardrails are run in parallel while mutate guardrails are run sequentially.\n+uiType=MultiSelectPills\n+uiProps={\"hideRadioIcon\": true}\n+sort=100",
|
|
28556
|
+
"type": "string",
|
|
28557
|
+
"enum": ["validate", "mutate"],
|
|
28558
|
+
"default": "validate"
|
|
28559
|
+
},
|
|
28560
|
+
"priority": {
|
|
28561
|
+
"description": "+label=Priority\n+usage=Execution order for mutate guardrails. Lower values run first. Only applicable when operation is mutate.\n+sort=150",
|
|
28562
|
+
"type": "integer",
|
|
28563
|
+
"minimum": 0,
|
|
28564
|
+
"exclusiveMinimum": true,
|
|
28565
|
+
"default": 1
|
|
28566
|
+
},
|
|
28567
|
+
"enforcing_strategy": {
|
|
28568
|
+
"$ref": "#/definitions/EnforcingStrategy"
|
|
28569
|
+
},
|
|
28570
|
+
"config": {
|
|
28571
|
+
"description": "+uiType=Ignore\n+uiProps={\"forwardJsonKey\": true}",
|
|
28572
|
+
"type": "object",
|
|
28573
|
+
"properties": {
|
|
28574
|
+
"base_url": {
|
|
28575
|
+
"description": "+label=Base URL\n+usage=The AI Guard API base URL.\n+sort=100\n+message=Base URL must be an http or https URL",
|
|
28576
|
+
"type": "string",
|
|
28577
|
+
"pattern": "^https?:\\/\\/\\S+$"
|
|
28578
|
+
},
|
|
28579
|
+
"policy_id": {
|
|
28580
|
+
"description": "+label=Policy ID\n+usage=Optional AI Guard policy ID. When set, calls /v1/detection/execute-policy. When omitted, calls /v1/detection/resolve-and-execute-policy for automatic policy resolution.\n+sort=200",
|
|
28581
|
+
"type": "integer",
|
|
28582
|
+
"minimum": 0,
|
|
28583
|
+
"exclusiveMinimum": true
|
|
28584
|
+
}
|
|
28585
|
+
}
|
|
28586
|
+
}
|
|
28587
|
+
},
|
|
28588
|
+
"$schema": "http://json-schema.org/draft-04/schema#"
|
|
28414
28589
|
}
|
|
28415
28590
|
},
|
|
28416
28591
|
"properties": {
|
|
@@ -29338,6 +29513,12 @@
|
|
|
29338
29513
|
"FiddlerKeyAuth": {
|
|
29339
29514
|
"$ref": "#/definitions/FiddlerKeyAuth"
|
|
29340
29515
|
},
|
|
29516
|
+
"FireworksApiKeyAuth": {
|
|
29517
|
+
"$ref": "#/definitions/FireworksApiKeyAuth"
|
|
29518
|
+
},
|
|
29519
|
+
"FireworksGuardrailConfig": {
|
|
29520
|
+
"$ref": "#/definitions/FireworksGuardrailConfig"
|
|
29521
|
+
},
|
|
29341
29522
|
"FlyteLaunchPlan": {
|
|
29342
29523
|
"$ref": "#/definitions/FlyteLaunchPlan"
|
|
29343
29524
|
},
|
|
@@ -31323,6 +31504,12 @@
|
|
|
31323
31504
|
},
|
|
31324
31505
|
"XGBoostSerializationFormat": {
|
|
31325
31506
|
"$ref": "#/definitions/XGBoostSerializationFormat"
|
|
31507
|
+
},
|
|
31508
|
+
"ZscalerAIGuardApiKeyAuth": {
|
|
31509
|
+
"$ref": "#/definitions/ZscalerAIGuardApiKeyAuth"
|
|
31510
|
+
},
|
|
31511
|
+
"ZscalerAIGuardGuardrailConfig": {
|
|
31512
|
+
"$ref": "#/definitions/ZscalerAIGuardGuardrailConfig"
|
|
31326
31513
|
}
|
|
31327
31514
|
}
|
|
31328
31515
|
}
|
package/dist/constants.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export declare const TFY_METADATA_HEADER = "x-tfy-metadata";
|
|
2
2
|
export declare const TFY_RETRY_CONFIG_HEADER = "x-tfy-retry-config";
|
|
3
3
|
export declare const TFY_CONVERSATION_ID_HEADER = "x-tfy-conversation-id";
|
|
4
|
+
/** Optional per-request Vertex API version (default `v1`); mirror of the gateway constant in src/constants.ts. */
|
|
5
|
+
export declare const TFY_VERTEX_API_VERSION_HEADER = "x-tfy-vertex-api-version";
|
|
6
|
+
export declare const VERTEX_API_VERSIONS: readonly ["v1", "v1beta1"];
|
|
4
7
|
export declare const TFY_REQUEST_ID_HEADER = "x-tfy-request-id";
|
|
5
8
|
export declare const TFY_LOGGING_CONFIG_HEADER = "x-tfy-logging-config";
|
|
6
9
|
export declare const TFY_CACHE_CONFIG_HEADER = "x-tfy-cache-config";
|
|
@@ -17,6 +20,11 @@ export declare const TFY_ERROR_TYPES: {
|
|
|
17
20
|
readonly MODEL_NOT_FOUND: "tfy-model-not-found";
|
|
18
21
|
readonly REQUEST_FAILURE: "request-failure";
|
|
19
22
|
readonly REQUEST_TIMEOUT: "request-timeout";
|
|
23
|
+
/** The gateway could not reach the provider (DNS, refused, reset, connect timeout). */
|
|
24
|
+
readonly UPSTREAM_CONNECT_FAILURE: "upstream-connect-failure";
|
|
25
|
+
readonly UPSTREAM_HEADERS_TIMEOUT: "upstream-headers-timeout";
|
|
26
|
+
readonly UPSTREAM_BODY_TIMEOUT: "upstream-body-timeout";
|
|
27
|
+
readonly UPSTREAM_TLS_ERROR: "upstream-tls-error";
|
|
20
28
|
readonly CLIENT_DISCONNECTED: "client-disconnected";
|
|
21
29
|
readonly PROVIDER_STREAMING_TERMINATED: "provider-streaming-terminated";
|
|
22
30
|
/** Provider reported a failure inside an HTTP 200 stream (e.g. a Responses `response.failed` frame). */
|
|
@@ -24,3 +32,5 @@ export declare const TFY_ERROR_TYPES: {
|
|
|
24
32
|
readonly TTFT_TIMEOUT: "ttft-timeout";
|
|
25
33
|
readonly UNKNOWN_ERROR: "unknown-error";
|
|
26
34
|
};
|
|
35
|
+
/** Failures where the gateway never got an HTTP response from the provider. */
|
|
36
|
+
export type GatewayFailureErrorType = typeof TFY_ERROR_TYPES.UPSTREAM_CONNECT_FAILURE | typeof TFY_ERROR_TYPES.UPSTREAM_HEADERS_TIMEOUT | typeof TFY_ERROR_TYPES.UPSTREAM_BODY_TIMEOUT | typeof TFY_ERROR_TYPES.UPSTREAM_TLS_ERROR;
|
package/dist/constants.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export const TFY_METADATA_HEADER = 'x-tfy-metadata';
|
|
2
2
|
export const TFY_RETRY_CONFIG_HEADER = 'x-tfy-retry-config';
|
|
3
3
|
export const TFY_CONVERSATION_ID_HEADER = 'x-tfy-conversation-id';
|
|
4
|
+
/** Optional per-request Vertex API version (default `v1`); mirror of the gateway constant in src/constants.ts. */
|
|
5
|
+
export const TFY_VERTEX_API_VERSION_HEADER = 'x-tfy-vertex-api-version';
|
|
6
|
+
export const VERTEX_API_VERSIONS = ['v1', 'v1beta1'];
|
|
4
7
|
export const TFY_REQUEST_ID_HEADER = 'x-tfy-request-id';
|
|
5
8
|
export const TFY_LOGGING_CONFIG_HEADER = 'x-tfy-logging-config';
|
|
6
9
|
export const TFY_CACHE_CONFIG_HEADER = 'x-tfy-cache-config';
|
|
@@ -17,6 +20,11 @@ export const TFY_ERROR_TYPES = {
|
|
|
17
20
|
MODEL_NOT_FOUND: 'tfy-model-not-found',
|
|
18
21
|
REQUEST_FAILURE: 'request-failure',
|
|
19
22
|
REQUEST_TIMEOUT: 'request-timeout',
|
|
23
|
+
/** The gateway could not reach the provider (DNS, refused, reset, connect timeout). */
|
|
24
|
+
UPSTREAM_CONNECT_FAILURE: 'upstream-connect-failure',
|
|
25
|
+
UPSTREAM_HEADERS_TIMEOUT: 'upstream-headers-timeout',
|
|
26
|
+
UPSTREAM_BODY_TIMEOUT: 'upstream-body-timeout',
|
|
27
|
+
UPSTREAM_TLS_ERROR: 'upstream-tls-error',
|
|
20
28
|
CLIENT_DISCONNECTED: 'client-disconnected',
|
|
21
29
|
PROVIDER_STREAMING_TERMINATED: 'provider-streaming-terminated',
|
|
22
30
|
/** Provider reported a failure inside an HTTP 200 stream (e.g. a Responses `response.failed` frame). */
|
package/dist/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,mBAAmB,GAAG,gBAAgB,CAAC;AACpD,MAAM,CAAC,MAAM,uBAAuB,GAAG,oBAAoB,CAAC;AAC5D,MAAM,CAAC,MAAM,0BAA0B,GAAG,uBAAuB,CAAC;AAClE,MAAM,CAAC,MAAM,qBAAqB,GAAG,kBAAkB,CAAC;AACxD,MAAM,CAAC,MAAM,yBAAyB,GAAG,sBAAsB,CAAC;AAChE,MAAM,CAAC,MAAM,uBAAuB,GAAG,oBAAoB,CAAC;AAC5D,MAAM,CAAC,MAAM,wBAAwB,GAAG,qBAAqB,CAAC;AAC9D,MAAM,CAAC,MAAM,mCAAmC,GAAG,gCAAgC,CAAC;AACpF,MAAM,CAAC,MAAM,6BAA6B,GAAG,0BAA0B,CAAC;AACxE,MAAM,CAAC,MAAM,eAAe,GAAG,UAAU,CAAC;AAC1C,MAAM,CAAC,MAAM,sBAAsB,GAAG,mBAAmB,CAAC;AAE1D,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7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,aAAa,EAAE,eAAe;IAC9B,qGAAqG;IACrG,eAAe,EAAE,qBAAqB;IACtC,eAAe,EAAE,iBAAiB;IAClC,eAAe,EAAE,iBAAiB;IAClC,uFAAuF;IACvF,wBAAwB,EAAE,0BAA0B;IACpD,wBAAwB,EAAE,0BAA0B;IACpD,qBAAqB,EAAE,uBAAuB;IAC9C,kBAAkB,EAAE,oBAAoB;IACxC,mBAAmB,EAAE,qBAAqB;IAC1C,6BAA6B,EAAE,+BAA+B;IAC9D,wGAAwG;IACxG,qBAAqB,EAAE,uBAAuB;IAC9C,YAAY,EAAE,cAAc;IAC5B,aAAa,EAAE,eAAe;CACtB,CAAC"}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
|
+
import { type GatewayFailureErrorType } from '../constants.js';
|
|
1
2
|
import { type SafeFetchInit } from '../http/index.js';
|
|
3
|
+
import { type FailureCauseEntry } from '../utils/providerFailureLogging.js';
|
|
2
4
|
/**
|
|
3
5
|
* Did the client hang up or cancel?
|
|
4
6
|
*
|
|
@@ -17,4 +19,6 @@ export declare const retryRequest: (url: string, options: SafeFetchInit, retryCo
|
|
|
17
19
|
createdAt: Date;
|
|
18
20
|
skip: boolean;
|
|
19
21
|
lastProviderResponseStatusCode: number | undefined;
|
|
22
|
+
gatewayFailureType: GatewayFailureErrorType | undefined;
|
|
23
|
+
gatewayFailureCause: FailureCauseEntry[] | undefined;
|
|
20
24
|
}>;
|
|
@@ -11,10 +11,12 @@
|
|
|
11
11
|
*/
|
|
12
12
|
import retry from 'async-retry';
|
|
13
13
|
import config from '../config.js';
|
|
14
|
+
import { TFY_ERROR_TYPES } from '../constants.js';
|
|
14
15
|
import { TimeoutError } from '../errors.js';
|
|
15
16
|
import { MAX_RETRY_LIMIT_MS, POSSIBLE_RETRY_STATUS_HEADERS, TLS_ERROR_CONFIG } from '../globals.js';
|
|
16
17
|
import { safeFetch } from '../http/index.js';
|
|
17
18
|
import { mergeAbortSignals } from '../utils/abortSignals.js';
|
|
19
|
+
import { describeFailureCause } from '../utils/providerFailureLogging.js';
|
|
18
20
|
// Provider base URLs are tenant-configured and can legitimately be private endpoints.
|
|
19
21
|
const PROVIDER_SSRF_MODE = 'guard';
|
|
20
22
|
function isCertificateError(error) {
|
|
@@ -86,6 +88,8 @@ export const retryRequest = async (url, options, retryCount, statusCodesToRetry,
|
|
|
86
88
|
let lastResponse;
|
|
87
89
|
let lastAttempt;
|
|
88
90
|
let lastProviderResponseStatusCode;
|
|
91
|
+
let gatewayFailureType;
|
|
92
|
+
let gatewayFailureCause;
|
|
89
93
|
const start = new Date();
|
|
90
94
|
let retrySkipped = false;
|
|
91
95
|
let remainingRetryTimeout = MAX_RETRY_LIMIT_MS;
|
|
@@ -177,6 +181,10 @@ export const retryRequest = async (url, options, retryCount, statusCodesToRetry,
|
|
|
177
181
|
else if (error instanceof TypeError &&
|
|
178
182
|
error.cause instanceof Error &&
|
|
179
183
|
error.cause?.name === 'ConnectTimeoutError') {
|
|
184
|
+
gatewayFailureType = TFY_ERROR_TYPES.UPSTREAM_CONNECT_FAILURE;
|
|
185
|
+
gatewayFailureCause = describeFailureCause(error);
|
|
186
|
+
// The last attempt got no HTTP response, so an earlier retried response must not read as the outcome.
|
|
187
|
+
lastProviderResponseStatusCode = undefined;
|
|
180
188
|
lastResponse = new Response(JSON.stringify({
|
|
181
189
|
genericError: {
|
|
182
190
|
message: `Message: ${error.message} Cause: ${error.cause ?? 'NA'} Name: ${error.name ?? 'N/A'}`,
|
|
@@ -186,6 +194,9 @@ export const retryRequest = async (url, options, retryCount, statusCodesToRetry,
|
|
|
186
194
|
});
|
|
187
195
|
}
|
|
188
196
|
else if (!error.status || error instanceof TypeError) {
|
|
197
|
+
gatewayFailureCause = describeFailureCause(error);
|
|
198
|
+
// The last attempt got no HTTP response, so an earlier retried response must not read as the outcome.
|
|
199
|
+
lastProviderResponseStatusCode = undefined;
|
|
189
200
|
if (error.cause?.code === 'UND_ERR_HEADERS_TIMEOUT' || error.cause?.name === 'HeadersTimeoutError') {
|
|
190
201
|
const configuredTimeout = config.UNDICI_HEADERS_TIMEOUT_MS;
|
|
191
202
|
const timeoutMessage = configuredTimeout === 0
|
|
@@ -205,6 +216,8 @@ export const retryRequest = async (url, options, retryCount, statusCodesToRetry,
|
|
|
205
216
|
createdAt: start,
|
|
206
217
|
skip: retrySkipped,
|
|
207
218
|
lastProviderResponseStatusCode: lastProviderResponseStatusCode,
|
|
219
|
+
gatewayFailureType: TFY_ERROR_TYPES.UPSTREAM_HEADERS_TIMEOUT,
|
|
220
|
+
gatewayFailureCause,
|
|
208
221
|
};
|
|
209
222
|
}
|
|
210
223
|
if (error.cause?.code === 'UND_ERR_BODY_TIMEOUT' || error.cause?.name === 'BodyTimeoutError') {
|
|
@@ -226,9 +239,17 @@ export const retryRequest = async (url, options, retryCount, statusCodesToRetry,
|
|
|
226
239
|
createdAt: start,
|
|
227
240
|
skip: retrySkipped,
|
|
228
241
|
lastProviderResponseStatusCode: lastProviderResponseStatusCode,
|
|
242
|
+
gatewayFailureType: TFY_ERROR_TYPES.UPSTREAM_BODY_TIMEOUT,
|
|
243
|
+
gatewayFailureCause,
|
|
229
244
|
};
|
|
230
245
|
}
|
|
231
246
|
const isCertError = isCertificateError(error);
|
|
247
|
+
if (isCertError) {
|
|
248
|
+
gatewayFailureType = TFY_ERROR_TYPES.UPSTREAM_TLS_ERROR;
|
|
249
|
+
}
|
|
250
|
+
else if (error instanceof TypeError) {
|
|
251
|
+
gatewayFailureType = TFY_ERROR_TYPES.UPSTREAM_CONNECT_FAILURE;
|
|
252
|
+
}
|
|
232
253
|
const errorMessageToReturn = isCertError
|
|
233
254
|
? getCertificateErrorMessage(error)
|
|
234
255
|
: `Message: ${error.message ?? 'Request failed'} Cause: ${error.cause ?? 'NA'} Name: ${error.name ?? 'N/A'}`;
|
|
@@ -271,6 +292,8 @@ export const retryRequest = async (url, options, retryCount, statusCodesToRetry,
|
|
|
271
292
|
createdAt: start,
|
|
272
293
|
skip: retrySkipped,
|
|
273
294
|
lastProviderResponseStatusCode: lastProviderResponseStatusCode,
|
|
295
|
+
gatewayFailureType,
|
|
296
|
+
gatewayFailureCause,
|
|
274
297
|
};
|
|
275
298
|
};
|
|
276
299
|
//# sourceMappingURL=retryHandler.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"retryHandler.js","sourceRoot":"","sources":["../../src/handlers/retryHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,MAAM,aAAa,CAAC;AAChC,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACjG,OAAO,EAAE,SAAS,EAAsB,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"retryHandler.js","sourceRoot":"","sources":["../../src/handlers/retryHandler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,KAAK,MAAM,aAAa,CAAC;AAChC,OAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,OAAO,EAAE,eAAe,EAAgC,MAAM,cAAc,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,6BAA6B,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AACjG,OAAO,EAAE,SAAS,EAAsB,MAAM,SAAS,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,OAAO,EAAE,oBAAoB,EAA0B,MAAM,iCAAiC,CAAC;AAE/F,sFAAsF;AACtF,MAAM,kBAAkB,GAAG,OAAgB,CAAC;AAE5C,SAAS,kBAAkB,CAAC,KAAU;IACpC,MAAM,SAAS,GAAG,KAAK,EAAE,KAAK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,SAAS,EAAE,KAAK;QAChB,IAAI,EAAE,YAAY;QAClB,8BAA8B,EAAE,8BAA8B;QAC9D,kBAAkB;QAClB,mBAAmB;KACpB,CAAC;AACJ,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -10,7 +10,7 @@ export { LlmGatewaySdk } from './sdk.js';
|
|
|
10
10
|
export { getStreamModeSplitPattern, pumpProviderAwsEventStream, pumpProviderSseStream, readSseFrames, shouldReadAwsEventStream, } from './stream/index.js';
|
|
11
11
|
export type { GetStreamModeSplitPatternInput, PumpProviderAwsEventStreamOptions, PumpProviderBaseOptions, PumpProviderSseOptions, PumpResult, ReadSseFramesOptions, ReadSseFramesResult, ShouldReadAwsEventStreamInput, SplitPattern, SseCommentMode, StreamTransformFn, } from './stream/index.js';
|
|
12
12
|
export type { CachePort } from './types/cache.js';
|
|
13
|
-
export type { BilledUsageOverlay, EndReason, Endpoint, ExecutionFinishReason, ExecutionModelMetadata, ExecutionReport, ExecutionTimings, ExecutionToolUsage, MidStreamError, MidStreamErrorKind, MidStreamProviderErrorToken, ProviderCallConfig, ProviderOptions, SdkCallInputs, SdkExecuteResult, SdkExecutionConfig, SdkInitConfig, SdkRequest, SdkRequestBody, SessionContext, TokenUsage, TokenUsageIteration, } from './types/contracts.js';
|
|
13
|
+
export type { BilledUsageOverlay, EndReason, Endpoint, ExecutionFinishReason, ExecutionModelMetadata, ExecutionReport, ExecutionTimings, ExecutionToolUsage, GatewayFailure, MidStreamError, MidStreamErrorKind, MidStreamProviderErrorToken, ProviderCallConfig, ProviderOptions, SdkCallInputs, SdkExecuteResult, SdkExecutionConfig, SdkInitConfig, SdkRequest, SdkRequestBody, SessionContext, TokenUsage, TokenUsageIteration, } from './types/contracts.js';
|
|
14
14
|
export type { AnthropicServerToolColumn, AnthropicServerToolMapping, BetaColumn, CatalogProviderConfig, CatalogProviderConfigs, ModelConfigMap, ProviderModelConfigs, } from './types/modelConfig.js';
|
|
15
15
|
export type { AnthropicOptions, AwsOptions, AwsSagemakerOptions, AzureAiInferenceOptions, AzureOptions, CommonHeaderOptions, FireworksAiOptions, HuggingFaceOptions, MistralOptions, OpenAIOptions, ProviderHeaderOptions, SnowflakeCortexOptions, StabilityAiOptions, VertexOptions, WorkersAiOptions, } from './types/options.js';
|
|
16
16
|
export { deriveProviderHeaderOptions } from './utils/deriveProviderHeaderOptions.js';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAU1C,OAAO,EACL,iCAAiC,GAIlC,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,qBAAqB,EACrB,aAAa,EACb,wBAAwB,GACzB,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAU1C,OAAO,EACL,iCAAiC,GAIlC,MAAM,4CAA4C,CAAC;AACpD,OAAO,EAAE,uBAAuB,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AACrF,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AACtC,OAAO,EACL,yBAAyB,EACzB,0BAA0B,EAC1B,qBAAqB,EACrB,aAAa,EACb,wBAAwB,GACzB,MAAM,UAAU,CAAC;AAkElB,OAAO,EAAE,2BAA2B,EAAE,MAAM,qCAAqC,CAAC"}
|
|
@@ -37,10 +37,10 @@ const AnthropicAPIConfig = {
|
|
|
37
37
|
const account = providerOptions.providerAccount.manifest;
|
|
38
38
|
const storedApiKey = account.auth_data?.api_key;
|
|
39
39
|
const apiKey = storedApiKey ?? callConfig.bearerTokenOverride;
|
|
40
|
-
//
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
40
|
+
// Anthropic documents `Authorization: Bearer` as the auth header and `x-api-key` as a legacy
|
|
41
|
+
// fallback. Bearer accepts both Console API keys and the short-lived Workload Identity
|
|
42
|
+
// Federation tokens from `POST /v1/oauth/token`; `x-api-key` rejects the latter outright.
|
|
43
|
+
const headers = { Authorization: `Bearer ${apiKey}` };
|
|
44
44
|
const body = request.body;
|
|
45
45
|
const { betaHeader, version } = resolveAnthropicBetaAndVersion({
|
|
46
46
|
endpoint,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/providers/anthropic/api.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,+BAA+B,EAAoC,MAAM,SAAS,CAAC;AAE5F,MAAM,cAAc,GAAG,CAAC,YAAY,EAAE,WAAW,EAAE,cAAc,EAAE,YAAY,EAAE,qBAAqB,CAAC,CAAC;AAExG,MAAM,CAAC,MAAM,yBAAyB,GAAG,YAAY,CAAC;AACtD,MAAM,CAAC,MAAM,6BAA6B,GAAG,qBAAqB,CAAC;AACnE,MAAM,CAAC,MAAM,qBAAqB,GAAG,sBAAsB,CAAC;AAI5D;;;;GAIG;AACH,MAAM,UAAU,8BAA8B,CAAC,EAC7C,QAAQ,EACR,eAAe,EACf,WAAW,GAKZ;IACC,8CAA8C;IAC9C,IAAI,iBAAiB,GAAG,cAAc,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,6BAA6B,CAAC;IAElH,6FAA6F;IAC7F,IAAI,QAAQ,KAAK,cAAc,IAAI,WAAW,IAAI,mBAAmB,CAAC,WAAW,CAAC,QAAQ,CAAC,EAAE,CAAC;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AE,OAAO,EAAE,EAAE,EAAE;QACrC,MAAM,UAAU,GAAG,CAAC,qBAAqB,CAAC,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QACxE,MAAM,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC;QAEtD,QAAQ,QAAQ,EAAE,CAAC;YACjB,KAAK,UAAU;gBACb,OAAO,WAAW,CAAC;YACrB,KAAK,cAAc;gBACjB,OAAO,WAAW,CAAC;YACrB,KAAK,UAAU;gBACb,OAAO,WAAW,CAAC;YACrB,KAAK,qBAAqB;gBACxB,OAAO,wBAAwB,CAAC;YAClC,KAAK,YAAY;gBACf,OAAO,QAAQ,CAAC;YAClB,KAAK,WAAW;gBACd,OAAO,QAAQ,CAAC;YAClB,KAAK,cAAc;gBACjB,OAAO,UAAU,MAAM,EAAE,CAAC;YAC5B,KAAK,YAAY;gBACf,OAAO,UAAU,MAAM,EAAE,CAAC;YAC5B,KAAK,qBAAqB;gBACxB,OAAO,UAAU,MAAM,UAAU,CAAC;YACpC;gBACE,OAAO,EAAE,CAAC;QACd,CAAC;IACH,CAAC;CACF,CAAC;AAEF,eAAe,kBAAkB,CAAC"}
|
|
@@ -9,9 +9,16 @@ import { isEmbedContentModel } from './embed.js';
|
|
|
9
9
|
import { isGeminiImageModel } from './imageGenerate.js';
|
|
10
10
|
import { getAccessToken, getAccessTokenFromADC, getBucketAndFile, getModelAndProvider } from './utils.js';
|
|
11
11
|
import { getAccessTokenFromExternalAccount } from './wifAuth.js';
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* The Vertex API version for a publisher. `requested` is the optional per-request `x-tfy-vertex-api-version`
|
|
14
|
+
* (Google serves some features, e.g. Gemini 4 Argon long decode, only on `v1beta1`). It only applies to the
|
|
15
|
+
* `google` publisher; `meta` stays on `v1beta1`, and everything else on `v1`. There is no per-model rule.
|
|
16
|
+
*/
|
|
17
|
+
const getApiVersion = (provider, requested) => {
|
|
13
18
|
if (provider === 'meta')
|
|
14
19
|
return 'v1beta1';
|
|
20
|
+
if (provider === 'google' && requested !== undefined)
|
|
21
|
+
return requested;
|
|
15
22
|
return 'v1';
|
|
16
23
|
};
|
|
17
24
|
function parseVertexJsonCredentialField(raw, fieldLabel) {
|
|
@@ -76,9 +83,9 @@ export function resolveVertexFields(providerOptions, headerOptions) {
|
|
|
76
83
|
vertexModelName,
|
|
77
84
|
};
|
|
78
85
|
}
|
|
79
|
-
const getProjectRoute = (vertexProjectId, vertexRegion, inputModel) => {
|
|
86
|
+
const getProjectRoute = (vertexProjectId, vertexRegion, inputModel, requestedApiVersion) => {
|
|
80
87
|
const { provider } = getModelAndProvider(inputModel);
|
|
81
|
-
const routeVersion = getApiVersion(provider,
|
|
88
|
+
const routeVersion = getApiVersion(provider, requestedApiVersion);
|
|
82
89
|
return `/${routeVersion}/projects/${vertexProjectId}/locations/${vertexRegion}`;
|
|
83
90
|
};
|
|
84
91
|
const FILE_ENDPOINTS = ['uploadFile', 'retrieveFileContent', 'deleteFile', 'listFiles', 'retrieveFile'];
|
|
@@ -94,6 +101,27 @@ const BATCH_ENDPOINTS = [
|
|
|
94
101
|
'cancelFinetune',
|
|
95
102
|
];
|
|
96
103
|
const NON_INFERENCE_ENDPOINTS = [...FILE_ENDPOINTS, ...BATCH_ENDPOINTS];
|
|
104
|
+
// Proxied model methods. Resource-management methods (e.g. :setIamPolicy) are deliberately absent.
|
|
105
|
+
const MODEL_ACTIONS = 'generateContent|streamGenerateContent|countTokens|computeTokens|predict|rawPredict|streamRawPredict|embedContent|predictLongRunning|fetchPredictOperation';
|
|
106
|
+
const PROJECT_LOCATION_SEGMENT = /\/projects\/[^/]+\/locations\/[^/]+/;
|
|
107
|
+
const PROJECT_SEGMENT = /\/projects\/[^/]+/;
|
|
108
|
+
// Segments must start alphanumeric so `.`/`..` traversal segments never match.
|
|
109
|
+
const PATH_SEGMENT = '[A-Za-z0-9][\\w.-]*';
|
|
110
|
+
const GOOGLE_API_VERSION = 'v1(?:alpha|beta\\d*)?';
|
|
111
|
+
// Mirrors NATIVE_VEO_ALLOWED_PATHS in the gateway's utils/videoRequestUtils.ts.
|
|
112
|
+
const NATIVE_VEO_ALLOWED_PATHS = [
|
|
113
|
+
new RegExp(`^/${GOOGLE_API_VERSION}/(?:projects/${PATH_SEGMENT}/locations/${PATH_SEGMENT}/)?(?:publishers/${PATH_SEGMENT}/)?models/${PATH_SEGMENT}(?::(?:predictLongRunning|fetchPredictOperation)|/operations/${PATH_SEGMENT})$`),
|
|
114
|
+
new RegExp(`^/${GOOGLE_API_VERSION}/files/${PATH_SEGMENT}(?::download)?$`),
|
|
115
|
+
];
|
|
116
|
+
// The proxy route can't tell TTS/STT/video calls apart from others, so their native paths are
|
|
117
|
+
// matched by shape and forwarded to their own base URLs.
|
|
118
|
+
const NATIVE_TTS_STT_PATH_PATTERNS = [
|
|
119
|
+
/^\/v1(?:beta1)?\/text:synthesize$/,
|
|
120
|
+
/^\/v1(?:p1beta1)?\/speech:(?:recognize|longrunningrecognize)$/,
|
|
121
|
+
];
|
|
122
|
+
// batchRecognize is excluded: a per-file config.model overrides the request-level model, which the
|
|
123
|
+
// STT handler authorizes, so it would bypass model authorization.
|
|
124
|
+
const SPEECH_V2_RECOGNIZE_PATH_PATTERN = new RegExp(`^/v2/projects/${PATH_SEGMENT}/locations/${PATH_SEGMENT}/recognizers/\\w[\\w.-]*:recognize$`);
|
|
97
125
|
// Good reference for using REST: https://cloud.google.com/vertex-ai/generative-ai/docs/start/quickstarts/quickstart-multimodal#gemini-beginner-samples-drest
|
|
98
126
|
// Difference versus Studio AI: https://cloud.google.com/vertex-ai/docs/start/ai-platform-users
|
|
99
127
|
export const GoogleApiConfig = {
|
|
@@ -134,17 +162,17 @@ export const GoogleApiConfig = {
|
|
|
134
162
|
const reqPath = request.path;
|
|
135
163
|
const reqQuery = request.search;
|
|
136
164
|
// Gemini format: /v1beta/models/{model}:{action} — rewrite to full Vertex path
|
|
137
|
-
const geminiPattern =
|
|
165
|
+
const geminiPattern = new RegExp(`^/(v1beta|v1alpha|v1)(?:\\d)*/models/([^:?]+):(${MODEL_ACTIONS})$`);
|
|
138
166
|
const geminiMatch = reqPath.match(geminiPattern);
|
|
139
167
|
if (geminiMatch) {
|
|
140
168
|
const [, , modelName, action] = geminiMatch;
|
|
141
169
|
const { provider } = getModelAndProvider(`google/${modelName}`);
|
|
142
|
-
const routeVersion = getApiVersion(provider,
|
|
170
|
+
const routeVersion = getApiVersion(provider, headerOptions.vertex.vertexApiVersion);
|
|
143
171
|
return `/${routeVersion}/projects/${vertexProjectId}/locations/${vertexRegion}/publishers/${provider}/models/${modelName}:${action}${reqQuery}`;
|
|
144
172
|
}
|
|
145
173
|
// Vertex format (e.g. from Gemini CLI): /v1beta1/publishers/google/models/{model}:{action}
|
|
146
174
|
// Path is missing projects/{id}/locations/{region}; prepend them so Vertex API accepts the request.
|
|
147
|
-
const vertexPathPattern =
|
|
175
|
+
const vertexPathPattern = new RegExp(`^/(v1beta\\d*|v1alpha|v1)(/publishers/[^/]+/models/[^/:]+:(?:${MODEL_ACTIONS}))$`);
|
|
148
176
|
const vertexMatch = reqPath.match(vertexPathPattern);
|
|
149
177
|
if (vertexMatch && vertexProjectId && vertexRegion) {
|
|
150
178
|
const [, version, rest] = vertexMatch;
|
|
@@ -161,7 +189,31 @@ export const GoogleApiConfig = {
|
|
|
161
189
|
const { model: upstreamModel } = getModelAndProvider(resolvedModel);
|
|
162
190
|
return `/${version}/projects/${vertexProjectId}/locations/${vertexRegion}/publishers/${publisher}/models/${encodeURIComponent(upstreamModel)}:${action}${reqQuery}`;
|
|
163
191
|
}
|
|
164
|
-
|
|
192
|
+
// Only model-scoped inference calls (e.g. Anthropic :rawPredict) are proxied, always pinned
|
|
193
|
+
// to the configured project/location. Anything else would run with the gateway's credentials.
|
|
194
|
+
const vertexModelScopedPathPattern = new RegExp(`^/(v1(?:beta\\d*|alpha)?)/projects/[^/]+/locations/[^/]+(/publishers/[^/]+/models/[^/:]+:(?:${MODEL_ACTIONS}))$`);
|
|
195
|
+
const modelScopedMatch = reqPath.match(vertexModelScopedPathPattern);
|
|
196
|
+
if (modelScopedMatch && vertexProjectId && vertexRegion) {
|
|
197
|
+
const [, version, rest] = modelScopedMatch;
|
|
198
|
+
return `/${version}/projects/${vertexProjectId}/locations/${vertexRegion}${rest}${reqQuery}`;
|
|
199
|
+
}
|
|
200
|
+
if (NATIVE_VEO_ALLOWED_PATHS.some(pattern => pattern.test(reqPath))) {
|
|
201
|
+
if (!PROJECT_LOCATION_SEGMENT.test(reqPath)) {
|
|
202
|
+
return `${reqPath}${reqQuery}`;
|
|
203
|
+
}
|
|
204
|
+
if (vertexProjectId && vertexRegion) {
|
|
205
|
+
const pinnedPath = reqPath.replace(PROJECT_LOCATION_SEGMENT, () => `/projects/${vertexProjectId}/locations/${vertexRegion}`);
|
|
206
|
+
return `${pinnedPath}${reqQuery}`;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
// Location stays caller-supplied: Speech v2 locations (e.g. global) differ from the Vertex region.
|
|
210
|
+
if (vertexProjectId && SPEECH_V2_RECOGNIZE_PATH_PATTERN.test(reqPath)) {
|
|
211
|
+
return `${reqPath.replace(PROJECT_SEGMENT, () => `/projects/${vertexProjectId}`)}${reqQuery}`;
|
|
212
|
+
}
|
|
213
|
+
if (NATIVE_TTS_STT_PATH_PATTERNS.some(pattern => pattern.test(reqPath))) {
|
|
214
|
+
return `${reqPath}${reqQuery}`;
|
|
215
|
+
}
|
|
216
|
+
throw new ValidationError('Vertex: unsupported proxy path. Only model inference paths are allowed.');
|
|
165
217
|
},
|
|
166
218
|
headers: async ({ session, providerOptions, headerOptions, callConfig, request }) => {
|
|
167
219
|
const { vertexServiceAccountJson, vertexExternalAccountJson, vertexProviderAccountFqn, vertexProjectId, vertexRegion, } = resolveVertexFields(providerOptions, headerOptions);
|
|
@@ -257,7 +309,7 @@ export const GoogleApiConfig = {
|
|
|
257
309
|
? inputModel
|
|
258
310
|
: 'google/gemini-1.0-pro';
|
|
259
311
|
const { provider, model } = getModelAndProvider(safeInputModel);
|
|
260
|
-
const projectRoute = getProjectRoute(vertexProjectId, vertexRegion, safeInputModel);
|
|
312
|
+
const projectRoute = getProjectRoute(vertexProjectId, vertexRegion, safeInputModel, headerOptions.vertex.vertexApiVersion);
|
|
261
313
|
const googleUrlMap = new Map([
|
|
262
314
|
['chatComplete', `${projectRoute}/publishers/${provider}/models/${model}:generateContent`],
|
|
263
315
|
['stream-chatComplete', `${projectRoute}/publishers/${provider}/models/${model}:streamGenerateContent?alt=sse`],
|