Skip to content

Commit 322cf1b

Browse files
authored
fix(agent-tars): old search settings throw error (close: #466) (#468)
1 parent 1fb6504 commit 322cf1b

File tree

8 files changed

+104
-8
lines changed

8 files changed

+104
-8
lines changed

apps/agent-tars/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
"@agent-infra/mcp-server-browser": "workspace:*"
5050
},
5151
"devDependencies": {
52+
"jsonrepair": "3.12.0",
5253
"serialize-javascript": "6.0.2",
5354
"@modelcontextprotocol/sdk": "^1.7.0",
5455
"@electron-toolkit/preload": "^3.0.1",
@@ -115,4 +116,4 @@
115116
"mirror": "https://npmmirror.com/mirrors/electron/"
116117
}
117118
}
118-
}
119+
}

apps/agent-tars/src/main/customTools/search.ts

+4-3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { tavily as tavilyCore } from '@tavily/core';
55
import { SettingStore } from '@main/store/setting';
66
import { logger } from '@main/utils/logger';
77
import { maskSensitiveData } from '@main/utils/maskSensitiveData';
8+
import { jsonrepair } from 'jsonrepair';
89

910
export const tavily = tavilyCore;
1011

@@ -45,11 +46,11 @@ export async function search(
4546
settings?: SearchSettings,
4647
): Promise<MCPToolResult> {
4748
const currentSearchConfig = settings || SettingStore.get('search');
48-
const args = JSON.parse(toolCall.function.arguments) as {
49+
const args = JSON.parse(jsonrepair(toolCall.function.arguments)) as {
4950
query: string;
50-
count: number;
51+
count?: number;
5152
};
52-
const count = args.count ?? currentSearchConfig.providerConfig.count ?? 10;
53+
const count = args?.count ?? currentSearchConfig.providerConfig?.count ?? 10;
5354
try {
5455
logger.info(
5556
'Search provider: ',

apps/agent-tars/src/renderer/src/components/LeftSidebar/Settings/ModelSettingsTab.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Input, Select, SelectItem, Spinner, Switch } from '@nextui-org/react';
33
import { ModelSettings, ModelProvider } from '@agent-infra/shared';
44
import { getProviderLogo, getModelOptions } from './modelUtils';
55
import { useProviders } from './useProviders';
6+
import { PasswordInput } from '@renderer/components/PasswordInput';
67

78
interface ModelSettingsTabProps {
89
settings: ModelSettings;
@@ -145,8 +146,7 @@ export function ModelSettingsTab({
145146
</>
146147
)}
147148

148-
<Input
149-
type="password"
149+
<PasswordInput
150150
label="API Key"
151151
placeholder="Enter your API key"
152152
value={settings.apiKey}

apps/agent-tars/src/renderer/src/components/LeftSidebar/Settings/SearchSettingsTab.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
ModalBody,
2929
ModalFooter,
3030
} from '@nextui-org/react';
31+
import { PasswordInput } from '@renderer/components/PasswordInput';
3132

3233
interface SearchSettingsTabProps {
3334
settings: SearchSettings;
@@ -321,8 +322,7 @@ export function SearchSettingsTab({
321322
{[SearchProvider.Tavily, SearchProvider.BingSearch].includes(
322323
settings.provider,
323324
) && (
324-
<Input
325-
type="password"
325+
<PasswordInput
326326
label="API Key"
327327
placeholder="Enter your API key"
328328
value={settings.apiKey}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import { useState, FC } from 'react';
2+
import { Input, type InputProps } from '@nextui-org/react';
3+
import { EyeSlashFilledIcon } from '@renderer/components/icons/EyeSlashFilledIcon';
4+
import { EyeFilledIcon } from '@renderer/components/icons/EyeFilledIcon';
5+
6+
export const PasswordInput: FC<Omit<InputProps, 'type' | 'endContent'>> = (
7+
props,
8+
) => {
9+
const [isVisible, setIsVisible] = useState(false);
10+
11+
const toggleVisibility = () => setIsVisible(!isVisible);
12+
13+
return (
14+
<Input
15+
type={isVisible ? 'text' : 'password'}
16+
endContent={
17+
<button
18+
aria-label="toggle password visibility"
19+
className="focus:outline-none"
20+
type="button"
21+
onClick={toggleVisibility}
22+
>
23+
{isVisible ? (
24+
<EyeSlashFilledIcon className="text-2xl text-default-400 pointer-events-none" />
25+
) : (
26+
<EyeFilledIcon className="text-2xl text-default-400 pointer-events-none" />
27+
)}
28+
</button>
29+
}
30+
{...props}
31+
/>
32+
);
33+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export const EyeFilledIcon = (props) => {
2+
return (
3+
<svg
4+
aria-hidden="true"
5+
fill="none"
6+
focusable="false"
7+
height="1em"
8+
role="presentation"
9+
viewBox="0 0 24 24"
10+
width="1em"
11+
{...props}
12+
>
13+
<path
14+
d="M21.25 9.14969C18.94 5.51969 15.56 3.42969 12 3.42969C10.22 3.42969 8.49 3.94969 6.91 4.91969C5.33 5.89969 3.91 7.32969 2.75 9.14969C1.75 10.7197 1.75 13.2697 2.75 14.8397C5.06 18.4797 8.44 20.5597 12 20.5597C13.78 20.5597 15.51 20.0397 17.09 19.0697C18.67 18.0897 20.09 16.6597 21.25 14.8397C22.25 13.2797 22.25 10.7197 21.25 9.14969ZM12 16.0397C9.76 16.0397 7.96 14.2297 7.96 11.9997C7.96 9.76969 9.76 7.95969 12 7.95969C14.24 7.95969 16.04 9.76969 16.04 11.9997C16.04 14.2297 14.24 16.0397 12 16.0397Z"
15+
fill="currentColor"
16+
/>
17+
<path
18+
d="M11.9984 9.14062C10.4284 9.14062 9.14844 10.4206 9.14844 12.0006C9.14844 13.5706 10.4284 14.8506 11.9984 14.8506C13.5684 14.8506 14.8584 13.5706 14.8584 12.0006C14.8584 10.4306 13.5684 9.14062 11.9984 9.14062Z"
19+
fill="currentColor"
20+
/>
21+
</svg>
22+
);
23+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
export const EyeSlashFilledIcon = (props) => {
2+
return (
3+
<svg
4+
aria-hidden="true"
5+
fill="none"
6+
focusable="false"
7+
height="1em"
8+
role="presentation"
9+
viewBox="0 0 24 24"
10+
width="1em"
11+
{...props}
12+
>
13+
<path
14+
d="M21.2714 9.17834C20.9814 8.71834 20.6714 8.28834 20.3514 7.88834C19.9814 7.41834 19.2814 7.37834 18.8614 7.79834L15.8614 10.7983C16.0814 11.4583 16.1214 12.2183 15.9214 13.0083C15.5714 14.4183 14.4314 15.5583 13.0214 15.9083C12.2314 16.1083 11.4714 16.0683 10.8114 15.8483C10.8114 15.8483 9.38141 17.2783 8.35141 18.3083C7.85141 18.8083 8.01141 19.6883 8.68141 19.9483C9.75141 20.3583 10.8614 20.5683 12.0014 20.5683C13.7814 20.5683 15.5114 20.0483 17.0914 19.0783C18.7014 18.0783 20.1514 16.6083 21.3214 14.7383C22.2714 13.2283 22.2214 10.6883 21.2714 9.17834Z"
15+
fill="currentColor"
16+
/>
17+
<path
18+
d="M14.0206 9.98062L9.98062 14.0206C9.47062 13.5006 9.14062 12.7806 9.14062 12.0006C9.14062 10.4306 10.4206 9.14062 12.0006 9.14062C12.7806 9.14062 13.5006 9.47062 14.0206 9.98062Z"
19+
fill="currentColor"
20+
/>
21+
<path
22+
d="M18.25 5.74969L14.86 9.13969C14.13 8.39969 13.12 7.95969 12 7.95969C9.76 7.95969 7.96 9.76969 7.96 11.9997C7.96 13.1197 8.41 14.1297 9.14 14.8597L5.76 18.2497H5.75C4.64 17.3497 3.62 16.1997 2.75 14.8397C1.75 13.2697 1.75 10.7197 2.75 9.14969C3.91 7.32969 5.33 5.89969 6.91 4.91969C8.49 3.95969 10.22 3.42969 12 3.42969C14.23 3.42969 16.39 4.24969 18.25 5.74969Z"
23+
fill="currentColor"
24+
/>
25+
<path
26+
d="M14.8581 11.9981C14.8581 13.5681 13.5781 14.8581 11.9981 14.8581C11.9381 14.8581 11.8881 14.8581 11.8281 14.8381L14.8381 11.8281C14.8581 11.8881 14.8581 11.9381 14.8581 11.9981Z"
27+
fill="currentColor"
28+
/>
29+
<path
30+
d="M21.7689 2.22891C21.4689 1.92891 20.9789 1.92891 20.6789 2.22891L2.22891 20.6889C1.92891 20.9889 1.92891 21.4789 2.22891 21.7789C2.37891 21.9189 2.56891 21.9989 2.76891 21.9989C2.96891 21.9989 3.15891 21.9189 3.30891 21.7689L21.7689 3.30891C22.0789 3.00891 22.0789 2.52891 21.7689 2.22891Z"
31+
fill="currentColor"
32+
/>
33+
</svg>
34+
);
35+
};

pnpm-lock.yaml

+3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)