@modelrelay/sdk 0.21.0 → 0.23.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 +28 -12
- package/dist/index.d.cts +47 -19
- package/dist/index.d.ts +47 -19
- package/dist/index.js +24 -12
- package/package.json +27 -25
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;
|
|
@@ -338,7 +354,6 @@ var AuthClient = class {
|
|
|
338
354
|
);
|
|
339
355
|
const token = normalizeFrontendToken(response, {
|
|
340
356
|
publishableKey,
|
|
341
|
-
customerId,
|
|
342
357
|
deviceId
|
|
343
358
|
});
|
|
344
359
|
this.cachedFrontend.set(cacheKey, token);
|
|
@@ -390,17 +405,17 @@ function isPublishableKey(value) {
|
|
|
390
405
|
return value.trim().toLowerCase().startsWith("mr_pk_");
|
|
391
406
|
}
|
|
392
407
|
function normalizeFrontendToken(payload, meta) {
|
|
393
|
-
const expiresAt = payload.expires_at;
|
|
394
408
|
return {
|
|
395
409
|
token: payload.token,
|
|
396
|
-
expiresAt:
|
|
410
|
+
expiresAt: new Date(payload.expires_at),
|
|
397
411
|
expiresIn: payload.expires_in,
|
|
398
412
|
tokenType: payload.token_type,
|
|
399
413
|
keyId: payload.key_id,
|
|
400
414
|
sessionId: payload.session_id,
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
415
|
+
projectId: payload.project_id,
|
|
416
|
+
customerId: payload.customer_id,
|
|
417
|
+
customerExternalId: payload.customer_external_id,
|
|
418
|
+
tierCode: payload.tier_code,
|
|
404
419
|
publishableKey: meta.publishableKey,
|
|
405
420
|
deviceId: meta.deviceId
|
|
406
421
|
};
|
|
@@ -409,16 +424,13 @@ function isTokenReusable(token) {
|
|
|
409
424
|
if (!token.token) {
|
|
410
425
|
return false;
|
|
411
426
|
}
|
|
412
|
-
if (!token.expiresAt) {
|
|
413
|
-
return true;
|
|
414
|
-
}
|
|
415
427
|
return token.expiresAt.getTime() - Date.now() > 6e4;
|
|
416
428
|
}
|
|
417
429
|
|
|
418
430
|
// package.json
|
|
419
431
|
var package_default = {
|
|
420
432
|
name: "@modelrelay/sdk",
|
|
421
|
-
version: "0.
|
|
433
|
+
version: "0.22.0",
|
|
422
434
|
description: "TypeScript SDK for the ModelRelay API",
|
|
423
435
|
type: "module",
|
|
424
436
|
main: "dist/index.cjs",
|
|
@@ -2582,6 +2594,10 @@ function resolveBaseUrl(override) {
|
|
|
2582
2594
|
getRetryableErrors,
|
|
2583
2595
|
hasRetryableErrors,
|
|
2584
2596
|
hasToolCalls,
|
|
2597
|
+
isEmailRequired,
|
|
2598
|
+
isNoFreeTier,
|
|
2599
|
+
isNoTiers,
|
|
2600
|
+
isProvisioningError,
|
|
2585
2601
|
isPublishableKey,
|
|
2586
2602
|
mergeMetrics,
|
|
2587
2603
|
mergeTrace,
|
package/dist/index.d.cts
CHANGED
|
@@ -211,19 +211,29 @@ interface FrontendTokenAutoProvisionRequest {
|
|
|
211
211
|
/** Optional TTL in seconds for the issued token. */
|
|
212
212
|
ttlSeconds?: number;
|
|
213
213
|
}
|
|
214
|
+
/** Token type for OAuth2 bearer tokens. */
|
|
215
|
+
type TokenType = "Bearer";
|
|
214
216
|
interface FrontendToken {
|
|
217
|
+
/** The bearer token for authenticating LLM requests. */
|
|
215
218
|
token: string;
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
219
|
+
/** When the token expires. */
|
|
220
|
+
expiresAt: Date;
|
|
221
|
+
/** Seconds until the token expires. */
|
|
222
|
+
expiresIn: number;
|
|
223
|
+
/** Token type, always "Bearer". */
|
|
224
|
+
tokenType: TokenType;
|
|
225
|
+
/** The publishable key ID that issued this token. */
|
|
226
|
+
keyId: string;
|
|
227
|
+
/** Unique session identifier for this token. */
|
|
228
|
+
sessionId: string;
|
|
229
|
+
/** The project ID this token is scoped to. */
|
|
230
|
+
projectId: string;
|
|
231
|
+
/** The internal customer ID (UUID). */
|
|
232
|
+
customerId: string;
|
|
233
|
+
/** The external customer ID provided by the application. */
|
|
234
|
+
customerExternalId: string;
|
|
235
|
+
/** The tier code for the customer (e.g., "free", "pro", "enterprise"). */
|
|
236
|
+
tierCode: string;
|
|
227
237
|
/**
|
|
228
238
|
* Publishable key used for issuance. Added client-side for caching.
|
|
229
239
|
*/
|
|
@@ -514,13 +524,15 @@ interface StructuredJSONEvent<T> {
|
|
|
514
524
|
}
|
|
515
525
|
interface APIFrontendToken {
|
|
516
526
|
token: string;
|
|
517
|
-
expires_at
|
|
518
|
-
expires_in
|
|
519
|
-
token_type
|
|
520
|
-
key_id
|
|
521
|
-
session_id
|
|
522
|
-
|
|
523
|
-
|
|
527
|
+
expires_at: string;
|
|
528
|
+
expires_in: number;
|
|
529
|
+
token_type: TokenType;
|
|
530
|
+
key_id: string;
|
|
531
|
+
session_id: string;
|
|
532
|
+
project_id: string;
|
|
533
|
+
customer_id: string;
|
|
534
|
+
customer_external_id: string;
|
|
535
|
+
tier_code: string;
|
|
524
536
|
}
|
|
525
537
|
interface APICustomerRef {
|
|
526
538
|
id: string;
|
|
@@ -1102,6 +1114,22 @@ declare class APIError extends ModelRelayError {
|
|
|
1102
1114
|
*/
|
|
1103
1115
|
isProvisioningError(): boolean;
|
|
1104
1116
|
}
|
|
1117
|
+
/**
|
|
1118
|
+
* Returns true if the error indicates email is required for auto-provisioning.
|
|
1119
|
+
*/
|
|
1120
|
+
declare function isEmailRequired(err: unknown): boolean;
|
|
1121
|
+
/**
|
|
1122
|
+
* Returns true if the error indicates no free tier is available.
|
|
1123
|
+
*/
|
|
1124
|
+
declare function isNoFreeTier(err: unknown): boolean;
|
|
1125
|
+
/**
|
|
1126
|
+
* Returns true if the error indicates no tiers are configured.
|
|
1127
|
+
*/
|
|
1128
|
+
declare function isNoTiers(err: unknown): boolean;
|
|
1129
|
+
/**
|
|
1130
|
+
* Returns true if the error is a customer provisioning error.
|
|
1131
|
+
*/
|
|
1132
|
+
declare function isProvisioningError(err: unknown): boolean;
|
|
1105
1133
|
declare function parseErrorResponse(response: Response, retries?: RetryMetadata): Promise<APIError>;
|
|
1106
1134
|
|
|
1107
1135
|
/**
|
|
@@ -1530,4 +1558,4 @@ declare class ModelRelay {
|
|
|
1530
1558
|
constructor(options: ModelRelayOptions);
|
|
1531
1559
|
}
|
|
1532
1560
|
|
|
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 };
|
|
1561
|
+
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 TokenType, 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
|
@@ -211,19 +211,29 @@ interface FrontendTokenAutoProvisionRequest {
|
|
|
211
211
|
/** Optional TTL in seconds for the issued token. */
|
|
212
212
|
ttlSeconds?: number;
|
|
213
213
|
}
|
|
214
|
+
/** Token type for OAuth2 bearer tokens. */
|
|
215
|
+
type TokenType = "Bearer";
|
|
214
216
|
interface FrontendToken {
|
|
217
|
+
/** The bearer token for authenticating LLM requests. */
|
|
215
218
|
token: string;
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
219
|
+
/** When the token expires. */
|
|
220
|
+
expiresAt: Date;
|
|
221
|
+
/** Seconds until the token expires. */
|
|
222
|
+
expiresIn: number;
|
|
223
|
+
/** Token type, always "Bearer". */
|
|
224
|
+
tokenType: TokenType;
|
|
225
|
+
/** The publishable key ID that issued this token. */
|
|
226
|
+
keyId: string;
|
|
227
|
+
/** Unique session identifier for this token. */
|
|
228
|
+
sessionId: string;
|
|
229
|
+
/** The project ID this token is scoped to. */
|
|
230
|
+
projectId: string;
|
|
231
|
+
/** The internal customer ID (UUID). */
|
|
232
|
+
customerId: string;
|
|
233
|
+
/** The external customer ID provided by the application. */
|
|
234
|
+
customerExternalId: string;
|
|
235
|
+
/** The tier code for the customer (e.g., "free", "pro", "enterprise"). */
|
|
236
|
+
tierCode: string;
|
|
227
237
|
/**
|
|
228
238
|
* Publishable key used for issuance. Added client-side for caching.
|
|
229
239
|
*/
|
|
@@ -514,13 +524,15 @@ interface StructuredJSONEvent<T> {
|
|
|
514
524
|
}
|
|
515
525
|
interface APIFrontendToken {
|
|
516
526
|
token: string;
|
|
517
|
-
expires_at
|
|
518
|
-
expires_in
|
|
519
|
-
token_type
|
|
520
|
-
key_id
|
|
521
|
-
session_id
|
|
522
|
-
|
|
523
|
-
|
|
527
|
+
expires_at: string;
|
|
528
|
+
expires_in: number;
|
|
529
|
+
token_type: TokenType;
|
|
530
|
+
key_id: string;
|
|
531
|
+
session_id: string;
|
|
532
|
+
project_id: string;
|
|
533
|
+
customer_id: string;
|
|
534
|
+
customer_external_id: string;
|
|
535
|
+
tier_code: string;
|
|
524
536
|
}
|
|
525
537
|
interface APICustomerRef {
|
|
526
538
|
id: string;
|
|
@@ -1102,6 +1114,22 @@ declare class APIError extends ModelRelayError {
|
|
|
1102
1114
|
*/
|
|
1103
1115
|
isProvisioningError(): boolean;
|
|
1104
1116
|
}
|
|
1117
|
+
/**
|
|
1118
|
+
* Returns true if the error indicates email is required for auto-provisioning.
|
|
1119
|
+
*/
|
|
1120
|
+
declare function isEmailRequired(err: unknown): boolean;
|
|
1121
|
+
/**
|
|
1122
|
+
* Returns true if the error indicates no free tier is available.
|
|
1123
|
+
*/
|
|
1124
|
+
declare function isNoFreeTier(err: unknown): boolean;
|
|
1125
|
+
/**
|
|
1126
|
+
* Returns true if the error indicates no tiers are configured.
|
|
1127
|
+
*/
|
|
1128
|
+
declare function isNoTiers(err: unknown): boolean;
|
|
1129
|
+
/**
|
|
1130
|
+
* Returns true if the error is a customer provisioning error.
|
|
1131
|
+
*/
|
|
1132
|
+
declare function isProvisioningError(err: unknown): boolean;
|
|
1105
1133
|
declare function parseErrorResponse(response: Response, retries?: RetryMetadata): Promise<APIError>;
|
|
1106
1134
|
|
|
1107
1135
|
/**
|
|
@@ -1530,4 +1558,4 @@ declare class ModelRelay {
|
|
|
1530
1558
|
constructor(options: ModelRelayOptions);
|
|
1531
1559
|
}
|
|
1532
1560
|
|
|
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 };
|
|
1561
|
+
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 TokenType, 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;
|
|
@@ -252,7 +264,6 @@ var AuthClient = class {
|
|
|
252
264
|
);
|
|
253
265
|
const token = normalizeFrontendToken(response, {
|
|
254
266
|
publishableKey,
|
|
255
|
-
customerId,
|
|
256
267
|
deviceId
|
|
257
268
|
});
|
|
258
269
|
this.cachedFrontend.set(cacheKey, token);
|
|
@@ -304,17 +315,17 @@ function isPublishableKey(value) {
|
|
|
304
315
|
return value.trim().toLowerCase().startsWith("mr_pk_");
|
|
305
316
|
}
|
|
306
317
|
function normalizeFrontendToken(payload, meta) {
|
|
307
|
-
const expiresAt = payload.expires_at;
|
|
308
318
|
return {
|
|
309
319
|
token: payload.token,
|
|
310
|
-
expiresAt:
|
|
320
|
+
expiresAt: new Date(payload.expires_at),
|
|
311
321
|
expiresIn: payload.expires_in,
|
|
312
322
|
tokenType: payload.token_type,
|
|
313
323
|
keyId: payload.key_id,
|
|
314
324
|
sessionId: payload.session_id,
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
325
|
+
projectId: payload.project_id,
|
|
326
|
+
customerId: payload.customer_id,
|
|
327
|
+
customerExternalId: payload.customer_external_id,
|
|
328
|
+
tierCode: payload.tier_code,
|
|
318
329
|
publishableKey: meta.publishableKey,
|
|
319
330
|
deviceId: meta.deviceId
|
|
320
331
|
};
|
|
@@ -323,16 +334,13 @@ function isTokenReusable(token) {
|
|
|
323
334
|
if (!token.token) {
|
|
324
335
|
return false;
|
|
325
336
|
}
|
|
326
|
-
if (!token.expiresAt) {
|
|
327
|
-
return true;
|
|
328
|
-
}
|
|
329
337
|
return token.expiresAt.getTime() - Date.now() > 6e4;
|
|
330
338
|
}
|
|
331
339
|
|
|
332
340
|
// package.json
|
|
333
341
|
var package_default = {
|
|
334
342
|
name: "@modelrelay/sdk",
|
|
335
|
-
version: "0.
|
|
343
|
+
version: "0.22.0",
|
|
336
344
|
description: "TypeScript SDK for the ModelRelay API",
|
|
337
345
|
type: "module",
|
|
338
346
|
main: "dist/index.cjs",
|
|
@@ -2495,6 +2503,10 @@ export {
|
|
|
2495
2503
|
getRetryableErrors,
|
|
2496
2504
|
hasRetryableErrors,
|
|
2497
2505
|
hasToolCalls,
|
|
2506
|
+
isEmailRequired,
|
|
2507
|
+
isNoFreeTier,
|
|
2508
|
+
isNoTiers,
|
|
2509
|
+
isProvisioningError,
|
|
2498
2510
|
isPublishableKey,
|
|
2499
2511
|
mergeMetrics,
|
|
2500
2512
|
mergeTrace,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@modelrelay/sdk",
|
|
3
|
-
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"description": "TypeScript SDK for the ModelRelay API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs",
|
|
@@ -13,28 +13,30 @@
|
|
|
13
13
|
"require": "./dist/index.cjs"
|
|
14
14
|
}
|
|
15
15
|
},
|
|
16
|
-
"publishConfig": {
|
|
17
|
-
"
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
"
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
16
|
+
"publishConfig": {
|
|
17
|
+
"access": "public"
|
|
18
|
+
},
|
|
19
|
+
"files": [
|
|
20
|
+
"dist"
|
|
21
|
+
],
|
|
22
|
+
"scripts": {
|
|
23
|
+
"build": "tsup src/index.ts --format esm,cjs --dts",
|
|
24
|
+
"dev": "tsup src/index.ts --format esm,cjs --dts --watch",
|
|
25
|
+
"lint": "tsc --noEmit",
|
|
26
|
+
"test": "vitest run"
|
|
27
|
+
},
|
|
28
|
+
"keywords": [
|
|
29
|
+
"modelrelay",
|
|
30
|
+
"llm",
|
|
31
|
+
"sdk",
|
|
32
|
+
"typescript"
|
|
33
|
+
],
|
|
34
|
+
"author": "Shane Vitarana",
|
|
35
|
+
"license": "Apache-2.0",
|
|
36
|
+
"devDependencies": {
|
|
37
|
+
"tsup": "^8.2.4",
|
|
38
|
+
"typescript": "^5.6.3",
|
|
39
|
+
"vitest": "^2.1.4",
|
|
40
|
+
"zod": "^3.23.0"
|
|
41
|
+
}
|
|
40
42
|
}
|