ProviderValues
Namespace: Vercel.AI.ProviderUtils
public static class ProviderValuesSmall collection, header, text, and media helpers shared by providers.
Inheritance: object
Methods
Section titled “Methods”AsArray<T>(IReadOnlyList<T>?)
Section titled “AsArray<T>(IReadOnlyList<T>?)”public static IReadOnlyList<T> AsArray<T>(IReadOnlyList<T>? value)Returns an empty list for null, or the same list.
Type parameters
| Name | Description |
|---|---|
T |
Parameters
| Name | Type | Description |
|---|---|---|
value |
IReadOnlyList<T> |
Returns: IReadOnlyList<T>
AsArray<T>(T?)
Section titled “AsArray<T>(T?)”public static IReadOnlyList<T> AsArray<T>(T? value) where T : classReturns an empty list for null, or a one-item list.
Type parameters
| Name | Description |
|---|---|
T |
Parameters
| Name | Type | Description |
|---|---|---|
value |
T |
Returns: IReadOnlyList<T>
ExtractLines(string, int?, int?)
Section titled “ExtractLines(string, int?, int?)”public static string ExtractLines(string text, int? startLine = null, int? endLine = null)Inclusive 1-based line slice. Line endings are detected as \r\n, then \n, then \r.
When both bounds are null the text is returned unchanged.
Parameters
| Name | Type | Description |
|---|---|---|
text |
string | |
startLine |
int? | |
endLine |
int? |
Returns: string
FilterNullable<T>(params T?[])
Section titled “FilterNullable<T>(params T?[])”public static IReadOnlyList<T> FilterNullable<T>(params T?[] values)Drops null entries and keeps other values, including false, zero, and empty strings.
Type parameters
| Name | Description |
|---|---|
T |
Parameters
| Name | Type | Description |
|---|---|---|
values |
T\[\] |
Returns: IReadOnlyList<T>
GetRuntimeEnvironmentUserAgent(RuntimeProbe?)
Section titled “GetRuntimeEnvironmentUserAgent(RuntimeProbe?)”public static string GetRuntimeEnvironmentUserAgent(ProviderValues.RuntimeProbe? probe = null)Describes the runtime the way provider user-agent strings do. Window is checked first, then navigator, then Node, then the Edge runtime. Returns an empty string when the runtime is unknown, so callers can omit it.
Parameters
| Name | Type | Description |
|---|---|---|
probe |
ProviderValues.RuntimeProbe |
Returns: string
IsBrowserRuntime(RuntimeProbe?)
Section titled “IsBrowserRuntime(RuntimeProbe?)”public static bool IsBrowserRuntime(ProviderValues.RuntimeProbe? probe = null)True when the probe reports a browser window. Maps to isBrowserRuntime.
Parameters
| Name | Type | Description |
|---|---|---|
probe |
ProviderValues.RuntimeProbe |
Returns: bool
IsJsonSerializable(object?)
Section titled “IsJsonSerializable(object?)”public static bool IsJsonSerializable(object? value)True when a value can be written as JSON: null, primitives, arrays, and string-keyed dictionaries.
Parameters
| Name | Type | Description |
|---|---|---|
value |
object |
Returns: bool
IsRecord(object?)
Section titled “IsRecord(object?)”public static bool IsRecord(object? value)True for a non-null object that is not a string, primitive, or list.
Parameters
| Name | Type | Description |
|---|---|---|
value |
object |
Returns: bool
IsSameOrigin(string, string)
Section titled “IsSameOrigin(string, string)”public static bool IsSameOrigin(string url, string baseUrl)True when both absolute URLs have the same scheme, host, and port.
Parameters
| Name | Type | Description |
|---|---|---|
url |
string | |
baseUrl |
string |
Returns: bool
MediaTypeToExtension(string)
Section titled “MediaTypeToExtension(string)”public static string MediaTypeToExtension(string mediaType)Maps an audio media type to a file extension. Unknown types use the subtype, or empty text when there is no slash.
Parameters
| Name | Type | Description |
|---|---|---|
mediaType |
string |
Returns: string
NormalizeBatchRequestCounts(double?, double?, double?, double?)
Section titled “NormalizeBatchRequestCounts(double?, double?, double?, double?)”public static ProviderValues.BatchRequestCounts? NormalizeBatchRequestCounts(double? total, double? pending, double? completed, double? failed)Returns counts when every value is a non-negative safe integer and the parts add up to the total.
Parameters
| Name | Type | Description |
|---|---|---|
total |
double? | |
pending |
double? | |
completed |
double? | |
failed |
double? |
Returns: ProviderValues.BatchRequestCounts
NormalizeHeaders(IEnumerable<KeyValuePair<string, string?>>?)
Section titled “NormalizeHeaders(IEnumerable<KeyValuePair<string, string?>>?)”public static Dictionary<string, string> NormalizeHeaders(IEnumerable<KeyValuePair<string, string?>>? headers)Lower-cases header names and drops null values.
Parameters
| Name | Type | Description |
|---|---|---|
headers |
IEnumerable<KeyValuePair<string, string>> |
Returns: Dictionary<string, string>
RemoveUndefinedEntries<T>(IReadOnlyDictionary<string, T?>)
Section titled “RemoveUndefinedEntries<T>(IReadOnlyDictionary<string, T?>)”public static Dictionary<string, T> RemoveUndefinedEntries<T>(IReadOnlyDictionary<string, T?> record)Copies entries whose values are not null.
Type parameters
| Name | Description |
|---|---|
T |
Parameters
| Name | Type | Description |
|---|---|---|
record |
IReadOnlyDictionary<string, T> |
Returns: Dictionary<string, T>
StripFileExtension(string)
Section titled “StripFileExtension(string)”public static string StripFileExtension(string filename)Returns the substring before the first dot. A trailing dot is removed with the empty extension.
Parameters
| Name | Type | Description |
|---|---|---|
filename |
string |
Returns: string
ValidateBaseUrl(string?)
Section titled “ValidateBaseUrl(string?)”public static string? ValidateBaseUrl(string? baseUrl)Returns <code class=“paramref”>baseUrl</code>, or throws when it is empty or whitespace.
Parameters
| Name | Type | Description |
|---|---|---|
baseUrl |
string |
Returns: string
WithUserAgentSuffix(IEnumerable<KeyValuePair<string, string?>>?, params string[])
Section titled “WithUserAgentSuffix(IEnumerable<KeyValuePair<string, string?>>?, params string[])”public static Dictionary<string, string> WithUserAgentSuffix(IEnumerable<KeyValuePair<string, string?>>? headers, params string[] suffixParts)Appends <code class=“paramref”>suffixParts</code> to the user-agent header, creating it when needed.
Parameters
| Name | Type | Description |
|---|---|---|
headers |
IEnumerable<KeyValuePair<string, string>> | |
suffixParts |
string[] |
Returns: Dictionary<string, string>
WithoutTrailingSlash(string?)
Section titled “WithoutTrailingSlash(string?)”public static string? WithoutTrailingSlash(string? url)Removes one trailing slash.
Parameters
| Name | Type | Description |
|---|---|---|
url |
string |
Returns: string
Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product