Skip to content

Commit c066dbc

Browse files
committed
more error messages
1 parent 0add76c commit c066dbc

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"id": "bks-ai-shell",
33
"name": "AI Shell",
4-
"version": "1.1.7",
4+
"version": "1.1.8",
55
"minAppVersion": "5",
66
"description": "Ask AI to analyze your database and generate SQL queries.",
77
"author": {

src/composables/ai.ts

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import {
44
streamText,
55
generateObject,
66
ToolExecutionError,
7+
APICallError,
8+
NoSuchModelError,
9+
NoSuchProviderError,
710
} from "ai";
811
import { useChat } from "@ai-sdk/vue";
912
import { computed, ref, watch } from "vue";
@@ -15,6 +18,7 @@ import {
1518
defaultTemperature,
1619
AvailableProviders,
1720
AvailableModels,
21+
providerConfigs,
1822
} from "@/config";
1923
import { getTools, UserRejectedError } from "@/tools";
2024
import { Message } from "ai";
@@ -71,6 +75,12 @@ export function useAI(options: AIOptions) {
7175
});
7276
return result.toDataStreamResponse({
7377
getErrorMessage: (error) => {
78+
notify("pluginError", {
79+
message: error.message,
80+
name: error.name,
81+
stack: error.stack
82+
})
83+
7484
if (NoSuchToolError.isInstance(error)) {
7585
return "The model tried to call a unknown tool.";
7686
} else if (InvalidToolArgumentsError.isInstance(error)) {
@@ -81,10 +91,22 @@ export function useAI(options: AIOptions) {
8191
} else {
8292
return "An error occurred during tool execution.";
8393
}
84-
} else {
85-
return "An unknown error occurred.";
94+
} else if (APICallError.isInstance(error)) {
95+
if (
96+
error.data?.error?.code === "invalid_api_key" ||
97+
error.data?.error?.message === "invalid x-api-key" ||
98+
error.data?.error?.code === 400
99+
) {
100+
return `The ${providerConfigs[providerId.value!].displayName} API key is invalid.`;
101+
}
102+
return "An error occurred during API call.";
103+
} else if (NoSuchProviderError.isInstance(error)) {
104+
return `Provider ${providerId.value} does not exist.`;
105+
} else if (NoSuchModelError.isInstance(error)) {
106+
return `Model ${modelId.value} does not exist.`;
86107
}
87-
},
108+
return "An unknown error occurred.";
109+
}
88110
});
89111
},
90112
onError: (error) => {

0 commit comments

Comments
 (0)