Skip to content

Commit

Permalink
chore (ai): remove toJSON method from AI SDK errors (#3495)
Browse files Browse the repository at this point in the history
  • Loading branch information
lgrammel authored Nov 6, 2024
1 parent 7814c4b commit c0ddc24
Show file tree
Hide file tree
Showing 21 changed files with 10 additions and 262 deletions.
6 changes: 6 additions & 0 deletions .changeset/poor-needles-double.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'@ai-sdk/provider': major
'ai': major
---

chore (ai): remove toJSON method from AI SDK errors
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ Please use the `headers` and `body` parameters instead.

The `name` property from the `Message` type has been removed.

### Removed `toJSON` method from errors

The `toJSON` method has been removed from AI SDK errors.

### Removed `streamMode` from `useChat` and `useCompletion`

The `streamMode` parameter has been removed from the `useChat` and `useCompletion` hooks.
Expand Down
12 changes: 0 additions & 12 deletions packages/ai/core/generate-object/no-object-generated-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,4 @@ export class NoObjectGeneratedError extends AISDKError {
): error is NoObjectGeneratedError {
return error instanceof Error && error.name === name;
}

/**
* @deprecated Do not use this method. It will be removed in the next major version.
*/
toJSON() {
return {
name: this.name,
cause: this.cause,
message: this.message,
stack: this.stack,
};
}
}
13 changes: 0 additions & 13 deletions packages/ai/core/prompt/invalid-data-content-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,4 @@ export class InvalidDataContentError extends AISDKError {
(error as InvalidDataContentError).content != null
);
}

/**
* @deprecated Do not use this method. It will be removed in the next major version.
*/
toJSON() {
return {
name: this.name,
message: this.message,
stack: this.stack,
cause: this.cause,
content: this.content,
};
}
}
13 changes: 0 additions & 13 deletions packages/ai/core/prompt/invalid-message-role-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,4 @@ export class InvalidMessageRoleError extends AISDKError {
typeof (error as InvalidMessageRoleError).role === 'string'
);
}

/**
* @deprecated Do not use this method. It will be removed in the next major version.
*/
toJSON() {
return {
name: this.name,
message: this.message,
stack: this.stack,

role: this.role,
};
}
}
17 changes: 0 additions & 17 deletions packages/ai/core/registry/no-such-provider-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,21 +44,4 @@ export class NoSuchProviderError extends NoSuchModelError {
Array.isArray((error as NoSuchProviderError).availableProviders)
);
}

/**
* @deprecated Do not use this method. It will be removed in the next major version.
*/
toJSON() {
return {
name: this.name,
message: this.message,
stack: this.stack,

modelId: this.modelId,
modelType: this.modelType,

providerId: this.providerId,
availableProviders: this.availableProviders,
};
}
}
11 changes: 0 additions & 11 deletions packages/ai/errors/invalid-argument-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,4 @@ export class InvalidArgumentError extends AISDKError {
typeof (error as InvalidArgumentError).value === 'string'
);
}

toJSON() {
return {
name: this.name,
message: this.message,
stack: this.stack,

parameter: this.parameter,
value: this.value,
};
}
}
15 changes: 0 additions & 15 deletions packages/ai/errors/invalid-tool-arguments-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,4 @@ export class InvalidToolArgumentsError extends AISDKError {
typeof (error as InvalidToolArgumentsError).toolArgs === 'string'
);
}

/**
* @deprecated Do not use this method. It will be removed in the next major version.
*/
toJSON() {
return {
name: this.name,
message: this.message,
cause: this.cause,
stack: this.stack,

toolName: this.toolName,
toolArgs: this.toolArgs,
};
}
}
14 changes: 0 additions & 14 deletions packages/ai/errors/no-such-tool-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,18 +45,4 @@ export class NoSuchToolError extends AISDKError {
typeof error.name === 'string'
);
}

/**
* @deprecated Do not use this method. It will be removed in the next major version.
*/
toJSON() {
return {
name: this.name,
message: this.message,
stack: this.stack,

toolName: this.toolName,
availableTools: this.availableTools,
};
}
}
14 changes: 0 additions & 14 deletions packages/ai/util/download-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,4 @@ export class DownloadError extends AISDKError {
typeof (error as DownloadError).statusText === 'string')
);
}

/**
* @deprecated Do not use this method. It will be removed in the next major version.
*/
toJSON() {
return {
name: this.name,
message: this.message,
url: this.url,
statusCode: this.statusCode,
statusText: this.statusText,
cause: this.cause,
};
}
}
13 changes: 0 additions & 13 deletions packages/ai/util/retry-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,4 @@ export class RetryError extends AISDKError {
Array.isArray((error as RetryError).errors)
);
}

/**
* @deprecated Do not use this method. It will be removed in the next major version.
*/
toJSON() {
return {
name: this.name,
message: this.message,
reason: this.reason,
lastError: this.lastError,
errors: this.errors,
};
}
}
13 changes: 0 additions & 13 deletions packages/provider/src/errors/ai-sdk-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,17 +59,4 @@ export class AISDKError extends Error {
error[markerSymbol] === true
);
}

/**
* Returns a JSON representation of the error.
* @returns {Object} An object containing the error's name, message, and cause.
*
* @deprecated Do not use this method. It will be removed in the next major version.
*/
toJSON() {
return {
name: this.name,
message: this.message,
};
}
}
18 changes: 0 additions & 18 deletions packages/provider/src/errors/api-call-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,4 @@ export class APICallError extends AISDKError {
typeof (error as APICallError).data === 'object')
);
}

/**
* @deprecated Do not use this method. It will be removed in the next major version.
*/
toJSON() {
return {
name: this.name,
message: this.message,
url: this.url,
requestBodyValues: this.requestBodyValues,
statusCode: this.statusCode,
responseHeaders: this.responseHeaders,
responseBody: this.responseBody,
cause: this.cause,
isRetryable: this.isRetryable,
data: this.data,
};
}
}
13 changes: 0 additions & 13 deletions packages/provider/src/errors/invalid-prompt-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,17 +37,4 @@ export class InvalidPromptError extends AISDKError {
static isInvalidPromptError(error: unknown): error is InvalidPromptError {
return error instanceof Error && error.name === name && prompt != null;
}

/**
* @deprecated Do not use this method. It will be removed in the next major version.
*/
toJSON() {
return {
name: this.name,
message: this.message,
stack: this.stack,

prompt: this.prompt,
};
}
}
13 changes: 0 additions & 13 deletions packages/provider/src/errors/invalid-response-data-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,4 @@ export class InvalidResponseDataError extends AISDKError {
(error as InvalidResponseDataError).data != null
);
}

/**
* @deprecated Do not use this method. It will be removed in the next major version.
*/
toJSON() {
return {
name: this.name,
message: this.message,
stack: this.stack,

data: this.data,
};
}
}
14 changes: 0 additions & 14 deletions packages/provider/src/errors/json-parse-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,4 @@ export class JSONParseError extends AISDKError {
typeof error.text === 'string'
);
}

/**
* @deprecated Do not use this method. It will be removed in the next major version.
*/
toJSON() {
return {
name: this.name,
message: this.message,
cause: this.cause,
stack: this.stack,

valueText: this.text,
};
}
}
12 changes: 0 additions & 12 deletions packages/provider/src/errors/no-content-generated-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,4 @@ export class NoContentGeneratedError extends AISDKError {
): error is NoContentGeneratedError {
return error instanceof Error && error.name === name;
}

/**
* @deprecated Do not use this method. It will be removed in the next major version.
*/
toJSON() {
return {
name: this.name,
cause: this.cause,
message: this.message,
stack: this.stack,
};
}
}
14 changes: 0 additions & 14 deletions packages/provider/src/errors/no-such-model-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,4 @@ export class NoSuchModelError extends AISDKError {
typeof (error as NoSuchModelError).modelType === 'string'
);
}

/**
* @deprecated Do not use this method. It will be removed in the next major version.
*/
toJSON() {
return {
name: this.name,
message: this.message,
stack: this.stack,

modelId: this.modelId,
modelType: this.modelType,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,20 +57,4 @@ export class TooManyEmbeddingValuesForCallError extends AISDKError {
Array.isArray(error.values)
);
}

/**
* @deprecated Do not use this method. It will be removed in the next major version.
*/
toJSON() {
return {
name: this.name,
message: this.message,
stack: this.stack,

provider: this.provider,
modelId: this.modelId,
maxEmbeddingsPerCall: this.maxEmbeddingsPerCall,
values: this.values,
};
}
}
14 changes: 0 additions & 14 deletions packages/provider/src/errors/type-validation-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,18 +55,4 @@ export class TypeValidationError extends AISDKError {
static isTypeValidationError(error: unknown): error is TypeValidationError {
return error instanceof Error && error.name === name;
}

/**
* @deprecated Do not use this method. It will be removed in the next major version.
*/
toJSON() {
return {
name: this.name,
message: this.message,
cause: this.cause,
stack: this.stack,

value: this.value,
};
}
}
13 changes: 0 additions & 13 deletions packages/provider/src/errors/unsupported-functionality-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,4 @@ export class UnsupportedFunctionalityError extends AISDKError {
typeof (error as UnsupportedFunctionalityError).functionality === 'string'
);
}

/**
* @deprecated Do not use this method. It will be removed in the next major version.
*/
toJSON() {
return {
name: this.name,
message: this.message,
stack: this.stack,

functionality: this.functionality,
};
}
}

0 comments on commit c0ddc24

Please sign in to comment.