|
1 | | -import type { |
2 | | - FlexibleSchema, |
3 | | - IdGenerator, |
4 | | - InferSchema, |
| 1 | +import { |
| 2 | + getErrorMessage, |
| 3 | + type FlexibleSchema, |
| 4 | + type IdGenerator, |
| 5 | + type InferSchema, |
5 | 6 | } from "@ai-sdk/provider-utils"; |
6 | 7 | import type { |
7 | 8 | CallSettings, |
@@ -537,7 +538,7 @@ export class Agent< |
537 | 538 | }; |
538 | 539 | return Object.assign(result, metadata); |
539 | 540 | } catch (error) { |
540 | | - await call.fail(errorToString(error)); |
| 541 | + await call.fail(getErrorMessage(error)); |
541 | 542 | throw error; |
542 | 543 | } |
543 | 544 | } |
@@ -642,8 +643,8 @@ export class Agent< |
642 | 643 | ), |
643 | 644 | onError: async (error) => { |
644 | 645 | console.error("onError", error); |
645 | | - await call.fail(errorToString(error.error)); |
646 | | - await streamer?.fail(errorToString(error.error)); |
| 646 | + await call.fail(getErrorMessage(error.error)); |
| 647 | + await streamer?.fail(getErrorMessage(error.error)); |
647 | 648 | return streamTextArgs.onError?.(error); |
648 | 649 | }, |
649 | 650 | prepareStep: async (options) => { |
@@ -743,7 +744,7 @@ export class Agent< |
743 | 744 | }; |
744 | 745 | return Object.assign(result, metadata); |
745 | 746 | } catch (error) { |
746 | | - await fail(errorToString(error)); |
| 747 | + await fail(getErrorMessage(error)); |
747 | 748 | throw error; |
748 | 749 | } |
749 | 750 | } |
@@ -797,7 +798,7 @@ export class Agent< |
797 | 798 | console.error(" streamObject onError", error); |
798 | 799 | // TODO: content that we have so far |
799 | 800 | // content: stream.fullStream. |
800 | | - await fail(errorToString(error.error)); |
| 801 | + await fail(getErrorMessage(error.error)); |
801 | 802 | return args.onError?.(error); |
802 | 803 | }, |
803 | 804 | onFinish: async (result) => { |
@@ -1668,10 +1669,3 @@ async function willContinue( |
1668 | 1669 | } |
1669 | 1670 | return !!stopWhen && !(await stopWhen({ steps })); |
1670 | 1671 | } |
1671 | | - |
1672 | | -function errorToString(error: unknown): string { |
1673 | | - if (error instanceof Error) { |
1674 | | - return error.message; |
1675 | | - } |
1676 | | - return String(error); |
1677 | | -} |
0 commit comments