@ai-sdk/provider-utils
Advanced tools
| import { AISDKError } from '@ai-sdk/provider'; | ||
| const name = 'AI_SerializationError'; | ||
| const marker = `vercel.ai.error.${name}`; | ||
| const symbol = Symbol.for(marker); | ||
| export class SerializationError extends AISDKError { | ||
| private readonly [symbol] = true; // used in isInstance | ||
| constructor({ | ||
| message = 'Failed to serialize value.', | ||
| cause, | ||
| }: { | ||
| message?: string; | ||
| cause?: unknown; | ||
| } = {}) { | ||
| super({ name, message, cause }); | ||
| } | ||
| static isInstance(error: unknown): error is SerializationError { | ||
| return AISDKError.hasMarker(error, marker); | ||
| } | ||
| } |
+1
-1
| { | ||
| "name": "@ai-sdk/provider-utils", | ||
| "version": "5.0.13", | ||
| "version": "5.0.14", | ||
| "type": "module", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
@@ -49,3 +49,7 @@ import { removeUndefinedEntries } from './remove-undefined-entries'; | ||
| onSocketError?: () => void; | ||
| onClose?: () => void; | ||
| /** | ||
| * Receives the close code and reason when the transport provides them | ||
| * (native `CloseEvent` / `ws` close event). | ||
| */ | ||
| onClose?: (info: { code?: number; reason?: string }) => void; | ||
| /** Also called (without opening a socket) when the signal is already aborted. */ | ||
@@ -112,4 +116,16 @@ onAbort?: (reason: unknown) => void; | ||
| }; | ||
| socket.onclose = () => { | ||
| tail = tail.then(() => onClose?.()).catch(onProcessingError); | ||
| socket.onclose = event => { | ||
| // Extract close diagnostics when the transport provides them (native | ||
| // `CloseEvent` and `ws` both carry `code` and `reason`). | ||
| const closeEvent = event as | ||
| | { code?: unknown; reason?: unknown } | ||
| | null | ||
| | undefined; | ||
| const code = | ||
| typeof closeEvent?.code === 'number' ? closeEvent.code : undefined; | ||
| const reason = | ||
| typeof closeEvent?.reason === 'string' ? closeEvent.reason : undefined; | ||
| tail = tail | ||
| .then(() => onClose?.({ code, reason })) | ||
| .catch(onProcessingError); | ||
| }; | ||
@@ -116,0 +132,0 @@ |
+1
-0
@@ -91,2 +91,3 @@ export { asArray } from './as-array'; | ||
| export { serializeModelOptions } from './serialize-model-options'; | ||
| export { SerializationError } from './serialization-error'; | ||
| export { secureJsonParse } from './secure-json-parse'; | ||
@@ -93,0 +94,0 @@ export { |
| import type { JSONObject } from '@ai-sdk/provider'; | ||
| import { isJSONSerializable } from './is-json-serializable'; | ||
| import type { Resolvable } from './resolve'; | ||
| import { SerializationError } from './serialization-error'; | ||
@@ -56,6 +57,6 @@ /** | ||
| // the serialization for workflows currently only supports synchronous values | ||
| // TODO introduce SerializationError | ||
| if (next instanceof Promise) { | ||
| throw new Error('Promise returned from resolveSync'); | ||
| throw new SerializationError({ | ||
| message: 'Cannot serialize asynchronous model options.', | ||
| }); | ||
| } | ||
@@ -62,0 +63,0 @@ |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
857161
0.6%159
0.63%14494
0.54%