Skip to content

ProviderValues

Namespace: Vercel.AI.ProviderUtils

public static class ProviderValues

Small collection, header, text, and media helpers shared by providers.

Inheritance: object

View source

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>

View source

public static IReadOnlyList<T> AsArray<T>(T? value) where T : class

Returns an empty list for null, or a one-item list.

Type parameters

Name Description
T

Parameters

Name Type Description
value T

Returns: IReadOnlyList<T>

View source

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

View source

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>

View source

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

View source

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

View source

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

View source

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

View source

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

View source

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

View source

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

View source

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>

View source

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>

View source

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

View source

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

View source

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>

View source

public static string? WithoutTrailingSlash(string? url)

Removes one trailing slash.

Parameters

Name Type Description
url string

Returns: string

View source

Apache-2.0 · Copyright 2023 Vercel, Inc. · unofficial community port, not an official Vercel product