@modelrelay/sdk 0.21.0 → 0.22.0
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/index.cjs +23 -3
- package/dist/index.d.cts +17 -1
- package/dist/index.d.ts +17 -1
- package/dist/index.js +19 -3
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -64,6 +64,10 @@ __export(index_exports, {
|
|
|
64
64
|
getRetryableErrors: () => getRetryableErrors,
|
|
65
65
|
hasRetryableErrors: () => hasRetryableErrors,
|
|
66
66
|
hasToolCalls: () => hasToolCalls,
|
|
67
|
+
isEmailRequired: () => isEmailRequired,
|
|
68
|
+
isNoFreeTier: () => isNoFreeTier,
|
|
69
|
+
isNoTiers: () => isNoTiers,
|
|
70
|
+
isProvisioningError: () => isProvisioningError,
|
|
67
71
|
isPublishableKey: () => isPublishableKey,
|
|
68
72
|
mergeMetrics: () => mergeMetrics,
|
|
69
73
|
mergeTrace: () => mergeTrace,
|
|
@@ -202,6 +206,18 @@ var APIError = class extends ModelRelayError {
|
|
|
202
206
|
return this.isNoTiers() || this.isNoFreeTier() || this.isEmailRequired();
|
|
203
207
|
}
|
|
204
208
|
};
|
|
209
|
+
function isEmailRequired(err) {
|
|
210
|
+
return err instanceof APIError && err.isEmailRequired();
|
|
211
|
+
}
|
|
212
|
+
function isNoFreeTier(err) {
|
|
213
|
+
return err instanceof APIError && err.isNoFreeTier();
|
|
214
|
+
}
|
|
215
|
+
function isNoTiers(err) {
|
|
216
|
+
return err instanceof APIError && err.isNoTiers();
|
|
217
|
+
}
|
|
218
|
+
function isProvisioningError(err) {
|
|
219
|
+
return err instanceof APIError && err.isProvisioningError();
|
|
220
|
+
}
|
|
205
221
|
async function parseErrorResponse(response, retries) {
|
|
206
222
|
const requestId = response.headers.get("X-ModelRelay-Chat-Request-Id") || response.headers.get("X-Request-Id") || void 0;
|
|
207
223
|
const fallbackMessage = response.statusText || "Request failed";
|
|
@@ -217,8 +233,8 @@ async function parseErrorResponse(response, retries) {
|
|
|
217
233
|
try {
|
|
218
234
|
const parsed = JSON.parse(bodyText);
|
|
219
235
|
const parsedObj = typeof parsed === "object" && parsed !== null ? parsed : null;
|
|
220
|
-
if (parsedObj?.error) {
|
|
221
|
-
const errPayload =
|
|
236
|
+
if (parsedObj?.error && typeof parsedObj.error === "object") {
|
|
237
|
+
const errPayload = parsedObj.error;
|
|
222
238
|
const message = errPayload?.message || fallbackMessage;
|
|
223
239
|
const code = errPayload?.code || void 0;
|
|
224
240
|
const fields = Array.isArray(errPayload?.fields) ? errPayload?.fields : void 0;
|
|
@@ -418,7 +434,7 @@ function isTokenReusable(token) {
|
|
|
418
434
|
// package.json
|
|
419
435
|
var package_default = {
|
|
420
436
|
name: "@modelrelay/sdk",
|
|
421
|
-
version: "0.
|
|
437
|
+
version: "0.22.0",
|
|
422
438
|
description: "TypeScript SDK for the ModelRelay API",
|
|
423
439
|
type: "module",
|
|
424
440
|
main: "dist/index.cjs",
|
|
@@ -2582,6 +2598,10 @@ function resolveBaseUrl(override) {
|
|
|
2582
2598
|
getRetryableErrors,
|
|
2583
2599
|
hasRetryableErrors,
|
|
2584
2600
|
hasToolCalls,
|
|
2601
|
+
isEmailRequired,
|
|
2602
|
+
isNoFreeTier,
|
|
2603
|
+
isNoTiers,
|
|
2604
|
+
isProvisioningError,
|
|
2585
2605
|
isPublishableKey,
|
|
2586
2606
|
mergeMetrics,
|
|
2587
2607
|
mergeTrace,
|
package/dist/index.d.cts
CHANGED
|
@@ -1102,6 +1102,22 @@ declare class APIError extends ModelRelayError {
|
|
|
1102
1102
|
*/
|
|
1103
1103
|
isProvisioningError(): boolean;
|
|
1104
1104
|
}
|
|
1105
|
+
/**
|
|
1106
|
+
* Returns true if the error indicates email is required for auto-provisioning.
|
|
1107
|
+
*/
|
|
1108
|
+
declare function isEmailRequired(err: unknown): boolean;
|
|
1109
|
+
/**
|
|
1110
|
+
* Returns true if the error indicates no free tier is available.
|
|
1111
|
+
*/
|
|
1112
|
+
declare function isNoFreeTier(err: unknown): boolean;
|
|
1113
|
+
/**
|
|
1114
|
+
* Returns true if the error indicates no tiers are configured.
|
|
1115
|
+
*/
|
|
1116
|
+
declare function isNoTiers(err: unknown): boolean;
|
|
1117
|
+
/**
|
|
1118
|
+
* Returns true if the error is a customer provisioning error.
|
|
1119
|
+
*/
|
|
1120
|
+
declare function isProvisioningError(err: unknown): boolean;
|
|
1105
1121
|
declare function parseErrorResponse(response: Response, retries?: RetryMetadata): Promise<APIError>;
|
|
1106
1122
|
|
|
1107
1123
|
/**
|
|
@@ -1530,4 +1546,4 @@ declare class ModelRelay {
|
|
|
1530
1546
|
constructor(options: ModelRelayOptions);
|
|
1531
1547
|
}
|
|
1532
1548
|
|
|
1533
|
-
export { type APIChatResponse, type APIChatUsage, type APICheckoutSession, type APICustomerRef, APIError, type APIFrontendToken, type APIKey, AuthClient, type AuthHeaders, ChatClient, type ChatCompletionCreateParams, type ChatCompletionEvent, type ChatCompletionResponse, ChatCompletionsStream, type ChatEventType, type ChatMessage, type CheckoutSession, type CheckoutSessionRequest, type CodeExecConfig, ConfigError, type Customer, type CustomerClaimRequest, type CustomerCreateRequest, type CustomerMetadata, type CustomerUpsertRequest, CustomersClient, DEFAULT_BASE_URL, DEFAULT_CLIENT_HEADER, DEFAULT_CONNECT_TIMEOUT_MS, DEFAULT_REQUEST_TIMEOUT_MS, type ErrorCategory, type ErrorCode, ErrorCodes, type FieldError, type FrontendCustomer, type FrontendToken, type FrontendTokenAutoProvisionRequest, type FrontendTokenRequest, type FunctionCall, type FunctionCallDelta, type FunctionTool, type HttpRequestMetrics, type JsonSchemaOptions, type KnownStopReason, type MessageDeltaData, type MessageStartData, type MessageStopData, type MetricsCallbacks, type ModelId, ModelRelay, type ModelRelayBaseOptions, ModelRelayError, type ModelRelayKeyOptions, type ModelRelayOptions, type ModelRelayOptionsLegacy, type ModelRelayTokenOptions, type NonEmptyArray, type PriceInterval, type Project, type ProviderId, type RequestContext, type ResponseFormat, type ResponseFormatType, ResponseFormatTypes, type ResponseJSONSchemaFormat, type RetryConfig, type RetryMetadata, type RetryOptions, SDK_VERSION, type Schema, type StopReason, StopReasons, type StreamFirstTokenMetrics, type StructuredJSONEvent, type StructuredJSONRecordType, StructuredJSONStream, type SubscriptionStatus, type Tier, type TierCheckoutRequest, type TierCheckoutSession, TiersClient, type TokenUsageMetrics, type Tool, ToolArgsError, type ToolCall, ToolCallAccumulator, type ToolCallDelta, type ToolChoice, type ToolChoiceType, ToolChoiceTypes, type ToolExecutionResult, type ToolHandler, ToolRegistry, type ToolType, ToolTypes, type TraceCallbacks, TransportError, type TransportErrorKind, type Usage, type UsageSummary, type WebSearchConfig, type WebToolMode, WebToolModes, type XSearchConfig, type ZodLikeSchema, assistantMessageWithToolCalls, createAccessTokenAuth, createApiKeyAuth, createAssistantMessage, createFunctionCall, createFunctionTool, createFunctionToolFromSchema, createRetryMessages, createSystemMessage, createToolCall, createUsage, createUserMessage, createWebTool, executeWithRetry, firstToolCall, formatToolErrorForModel, getRetryableErrors, hasRetryableErrors, hasToolCalls, isPublishableKey, mergeMetrics, mergeTrace, modelToString, normalizeModelId, normalizeStopReason, parseErrorResponse, parseToolArgs, parseToolArgsRaw, respondToToolCall, stopReasonToString, toolChoiceAuto, toolChoiceNone, toolChoiceRequired, toolResultMessage, tryParseToolArgs, zodToJsonSchema };
|
|
1549
|
+
export { type APIChatResponse, type APIChatUsage, type APICheckoutSession, type APICustomerRef, APIError, type APIFrontendToken, type APIKey, AuthClient, type AuthHeaders, ChatClient, type ChatCompletionCreateParams, type ChatCompletionEvent, type ChatCompletionResponse, ChatCompletionsStream, type ChatEventType, type ChatMessage, type CheckoutSession, type CheckoutSessionRequest, type CodeExecConfig, ConfigError, type Customer, type CustomerClaimRequest, type CustomerCreateRequest, type CustomerMetadata, type CustomerUpsertRequest, CustomersClient, DEFAULT_BASE_URL, DEFAULT_CLIENT_HEADER, DEFAULT_CONNECT_TIMEOUT_MS, DEFAULT_REQUEST_TIMEOUT_MS, type ErrorCategory, type ErrorCode, ErrorCodes, type FieldError, type FrontendCustomer, type FrontendToken, type FrontendTokenAutoProvisionRequest, type FrontendTokenRequest, type FunctionCall, type FunctionCallDelta, type FunctionTool, type HttpRequestMetrics, type JsonSchemaOptions, type KnownStopReason, type MessageDeltaData, type MessageStartData, type MessageStopData, type MetricsCallbacks, type ModelId, ModelRelay, type ModelRelayBaseOptions, ModelRelayError, type ModelRelayKeyOptions, type ModelRelayOptions, type ModelRelayOptionsLegacy, type ModelRelayTokenOptions, type NonEmptyArray, type PriceInterval, type Project, type ProviderId, type RequestContext, type ResponseFormat, type ResponseFormatType, ResponseFormatTypes, type ResponseJSONSchemaFormat, type RetryConfig, type RetryMetadata, type RetryOptions, SDK_VERSION, type Schema, type StopReason, StopReasons, type StreamFirstTokenMetrics, type StructuredJSONEvent, type StructuredJSONRecordType, StructuredJSONStream, type SubscriptionStatus, type Tier, type TierCheckoutRequest, type TierCheckoutSession, TiersClient, type TokenUsageMetrics, type Tool, ToolArgsError, type ToolCall, ToolCallAccumulator, type ToolCallDelta, type ToolChoice, type ToolChoiceType, ToolChoiceTypes, type ToolExecutionResult, type ToolHandler, ToolRegistry, type ToolType, ToolTypes, type TraceCallbacks, TransportError, type TransportErrorKind, type Usage, type UsageSummary, type WebSearchConfig, type WebToolMode, WebToolModes, type XSearchConfig, type ZodLikeSchema, assistantMessageWithToolCalls, createAccessTokenAuth, createApiKeyAuth, createAssistantMessage, createFunctionCall, createFunctionTool, createFunctionToolFromSchema, createRetryMessages, createSystemMessage, createToolCall, createUsage, createUserMessage, createWebTool, executeWithRetry, firstToolCall, formatToolErrorForModel, getRetryableErrors, hasRetryableErrors, hasToolCalls, isEmailRequired, isNoFreeTier, isNoTiers, isProvisioningError, isPublishableKey, mergeMetrics, mergeTrace, modelToString, normalizeModelId, normalizeStopReason, parseErrorResponse, parseToolArgs, parseToolArgsRaw, respondToToolCall, stopReasonToString, toolChoiceAuto, toolChoiceNone, toolChoiceRequired, toolResultMessage, tryParseToolArgs, zodToJsonSchema };
|
package/dist/index.d.ts
CHANGED
|
@@ -1102,6 +1102,22 @@ declare class APIError extends ModelRelayError {
|
|
|
1102
1102
|
*/
|
|
1103
1103
|
isProvisioningError(): boolean;
|
|
1104
1104
|
}
|
|
1105
|
+
/**
|
|
1106
|
+
* Returns true if the error indicates email is required for auto-provisioning.
|
|
1107
|
+
*/
|
|
1108
|
+
declare function isEmailRequired(err: unknown): boolean;
|
|
1109
|
+
/**
|
|
1110
|
+
* Returns true if the error indicates no free tier is available.
|
|
1111
|
+
*/
|
|
1112
|
+
declare function isNoFreeTier(err: unknown): boolean;
|
|
1113
|
+
/**
|
|
1114
|
+
* Returns true if the error indicates no tiers are configured.
|
|
1115
|
+
*/
|
|
1116
|
+
declare function isNoTiers(err: unknown): boolean;
|
|
1117
|
+
/**
|
|
1118
|
+
* Returns true if the error is a customer provisioning error.
|
|
1119
|
+
*/
|
|
1120
|
+
declare function isProvisioningError(err: unknown): boolean;
|
|
1105
1121
|
declare function parseErrorResponse(response: Response, retries?: RetryMetadata): Promise<APIError>;
|
|
1106
1122
|
|
|
1107
1123
|
/**
|
|
@@ -1530,4 +1546,4 @@ declare class ModelRelay {
|
|
|
1530
1546
|
constructor(options: ModelRelayOptions);
|
|
1531
1547
|
}
|
|
1532
1548
|
|
|
1533
|
-
export { type APIChatResponse, type APIChatUsage, type APICheckoutSession, type APICustomerRef, APIError, type APIFrontendToken, type APIKey, AuthClient, type AuthHeaders, ChatClient, type ChatCompletionCreateParams, type ChatCompletionEvent, type ChatCompletionResponse, ChatCompletionsStream, type ChatEventType, type ChatMessage, type CheckoutSession, type CheckoutSessionRequest, type CodeExecConfig, ConfigError, type Customer, type CustomerClaimRequest, type CustomerCreateRequest, type CustomerMetadata, type CustomerUpsertRequest, CustomersClient, DEFAULT_BASE_URL, DEFAULT_CLIENT_HEADER, DEFAULT_CONNECT_TIMEOUT_MS, DEFAULT_REQUEST_TIMEOUT_MS, type ErrorCategory, type ErrorCode, ErrorCodes, type FieldError, type FrontendCustomer, type FrontendToken, type FrontendTokenAutoProvisionRequest, type FrontendTokenRequest, type FunctionCall, type FunctionCallDelta, type FunctionTool, type HttpRequestMetrics, type JsonSchemaOptions, type KnownStopReason, type MessageDeltaData, type MessageStartData, type MessageStopData, type MetricsCallbacks, type ModelId, ModelRelay, type ModelRelayBaseOptions, ModelRelayError, type ModelRelayKeyOptions, type ModelRelayOptions, type ModelRelayOptionsLegacy, type ModelRelayTokenOptions, type NonEmptyArray, type PriceInterval, type Project, type ProviderId, type RequestContext, type ResponseFormat, type ResponseFormatType, ResponseFormatTypes, type ResponseJSONSchemaFormat, type RetryConfig, type RetryMetadata, type RetryOptions, SDK_VERSION, type Schema, type StopReason, StopReasons, type StreamFirstTokenMetrics, type StructuredJSONEvent, type StructuredJSONRecordType, StructuredJSONStream, type SubscriptionStatus, type Tier, type TierCheckoutRequest, type TierCheckoutSession, TiersClient, type TokenUsageMetrics, type Tool, ToolArgsError, type ToolCall, ToolCallAccumulator, type ToolCallDelta, type ToolChoice, type ToolChoiceType, ToolChoiceTypes, type ToolExecutionResult, type ToolHandler, ToolRegistry, type ToolType, ToolTypes, type TraceCallbacks, TransportError, type TransportErrorKind, type Usage, type UsageSummary, type WebSearchConfig, type WebToolMode, WebToolModes, type XSearchConfig, type ZodLikeSchema, assistantMessageWithToolCalls, createAccessTokenAuth, createApiKeyAuth, createAssistantMessage, createFunctionCall, createFunctionTool, createFunctionToolFromSchema, createRetryMessages, createSystemMessage, createToolCall, createUsage, createUserMessage, createWebTool, executeWithRetry, firstToolCall, formatToolErrorForModel, getRetryableErrors, hasRetryableErrors, hasToolCalls, isPublishableKey, mergeMetrics, mergeTrace, modelToString, normalizeModelId, normalizeStopReason, parseErrorResponse, parseToolArgs, parseToolArgsRaw, respondToToolCall, stopReasonToString, toolChoiceAuto, toolChoiceNone, toolChoiceRequired, toolResultMessage, tryParseToolArgs, zodToJsonSchema };
|
|
1549
|
+
export { type APIChatResponse, type APIChatUsage, type APICheckoutSession, type APICustomerRef, APIError, type APIFrontendToken, type APIKey, AuthClient, type AuthHeaders, ChatClient, type ChatCompletionCreateParams, type ChatCompletionEvent, type ChatCompletionResponse, ChatCompletionsStream, type ChatEventType, type ChatMessage, type CheckoutSession, type CheckoutSessionRequest, type CodeExecConfig, ConfigError, type Customer, type CustomerClaimRequest, type CustomerCreateRequest, type CustomerMetadata, type CustomerUpsertRequest, CustomersClient, DEFAULT_BASE_URL, DEFAULT_CLIENT_HEADER, DEFAULT_CONNECT_TIMEOUT_MS, DEFAULT_REQUEST_TIMEOUT_MS, type ErrorCategory, type ErrorCode, ErrorCodes, type FieldError, type FrontendCustomer, type FrontendToken, type FrontendTokenAutoProvisionRequest, type FrontendTokenRequest, type FunctionCall, type FunctionCallDelta, type FunctionTool, type HttpRequestMetrics, type JsonSchemaOptions, type KnownStopReason, type MessageDeltaData, type MessageStartData, type MessageStopData, type MetricsCallbacks, type ModelId, ModelRelay, type ModelRelayBaseOptions, ModelRelayError, type ModelRelayKeyOptions, type ModelRelayOptions, type ModelRelayOptionsLegacy, type ModelRelayTokenOptions, type NonEmptyArray, type PriceInterval, type Project, type ProviderId, type RequestContext, type ResponseFormat, type ResponseFormatType, ResponseFormatTypes, type ResponseJSONSchemaFormat, type RetryConfig, type RetryMetadata, type RetryOptions, SDK_VERSION, type Schema, type StopReason, StopReasons, type StreamFirstTokenMetrics, type StructuredJSONEvent, type StructuredJSONRecordType, StructuredJSONStream, type SubscriptionStatus, type Tier, type TierCheckoutRequest, type TierCheckoutSession, TiersClient, type TokenUsageMetrics, type Tool, ToolArgsError, type ToolCall, ToolCallAccumulator, type ToolCallDelta, type ToolChoice, type ToolChoiceType, ToolChoiceTypes, type ToolExecutionResult, type ToolHandler, ToolRegistry, type ToolType, ToolTypes, type TraceCallbacks, TransportError, type TransportErrorKind, type Usage, type UsageSummary, type WebSearchConfig, type WebToolMode, WebToolModes, type XSearchConfig, type ZodLikeSchema, assistantMessageWithToolCalls, createAccessTokenAuth, createApiKeyAuth, createAssistantMessage, createFunctionCall, createFunctionTool, createFunctionToolFromSchema, createRetryMessages, createSystemMessage, createToolCall, createUsage, createUserMessage, createWebTool, executeWithRetry, firstToolCall, formatToolErrorForModel, getRetryableErrors, hasRetryableErrors, hasToolCalls, isEmailRequired, isNoFreeTier, isNoTiers, isProvisioningError, isPublishableKey, mergeMetrics, mergeTrace, modelToString, normalizeModelId, normalizeStopReason, parseErrorResponse, parseToolArgs, parseToolArgsRaw, respondToToolCall, stopReasonToString, toolChoiceAuto, toolChoiceNone, toolChoiceRequired, toolResultMessage, tryParseToolArgs, zodToJsonSchema };
|
package/dist/index.js
CHANGED
|
@@ -116,6 +116,18 @@ var APIError = class extends ModelRelayError {
|
|
|
116
116
|
return this.isNoTiers() || this.isNoFreeTier() || this.isEmailRequired();
|
|
117
117
|
}
|
|
118
118
|
};
|
|
119
|
+
function isEmailRequired(err) {
|
|
120
|
+
return err instanceof APIError && err.isEmailRequired();
|
|
121
|
+
}
|
|
122
|
+
function isNoFreeTier(err) {
|
|
123
|
+
return err instanceof APIError && err.isNoFreeTier();
|
|
124
|
+
}
|
|
125
|
+
function isNoTiers(err) {
|
|
126
|
+
return err instanceof APIError && err.isNoTiers();
|
|
127
|
+
}
|
|
128
|
+
function isProvisioningError(err) {
|
|
129
|
+
return err instanceof APIError && err.isProvisioningError();
|
|
130
|
+
}
|
|
119
131
|
async function parseErrorResponse(response, retries) {
|
|
120
132
|
const requestId = response.headers.get("X-ModelRelay-Chat-Request-Id") || response.headers.get("X-Request-Id") || void 0;
|
|
121
133
|
const fallbackMessage = response.statusText || "Request failed";
|
|
@@ -131,8 +143,8 @@ async function parseErrorResponse(response, retries) {
|
|
|
131
143
|
try {
|
|
132
144
|
const parsed = JSON.parse(bodyText);
|
|
133
145
|
const parsedObj = typeof parsed === "object" && parsed !== null ? parsed : null;
|
|
134
|
-
if (parsedObj?.error) {
|
|
135
|
-
const errPayload =
|
|
146
|
+
if (parsedObj?.error && typeof parsedObj.error === "object") {
|
|
147
|
+
const errPayload = parsedObj.error;
|
|
136
148
|
const message = errPayload?.message || fallbackMessage;
|
|
137
149
|
const code = errPayload?.code || void 0;
|
|
138
150
|
const fields = Array.isArray(errPayload?.fields) ? errPayload?.fields : void 0;
|
|
@@ -332,7 +344,7 @@ function isTokenReusable(token) {
|
|
|
332
344
|
// package.json
|
|
333
345
|
var package_default = {
|
|
334
346
|
name: "@modelrelay/sdk",
|
|
335
|
-
version: "0.
|
|
347
|
+
version: "0.22.0",
|
|
336
348
|
description: "TypeScript SDK for the ModelRelay API",
|
|
337
349
|
type: "module",
|
|
338
350
|
main: "dist/index.cjs",
|
|
@@ -2495,6 +2507,10 @@ export {
|
|
|
2495
2507
|
getRetryableErrors,
|
|
2496
2508
|
hasRetryableErrors,
|
|
2497
2509
|
hasToolCalls,
|
|
2510
|
+
isEmailRequired,
|
|
2511
|
+
isNoFreeTier,
|
|
2512
|
+
isNoTiers,
|
|
2513
|
+
isProvisioningError,
|
|
2498
2514
|
isPublishableKey,
|
|
2499
2515
|
mergeMetrics,
|
|
2500
2516
|
mergeTrace,
|