Skip to content

Commit 0711cc9

Browse files
committed
Merge branch 'main' of github.com:cohere-ai/cohere-toolkit into staging/deploy
2 parents bbd888d + 82ba73f commit 0711cc9

File tree

12 files changed

+80
-106
lines changed

12 files changed

+80
-106
lines changed

CODEOWNERS

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
* @cohere-ai/toolkit @EugeneLightsOn @malexw @scottmx81 @tianjing-li
2-
src/interfaces/coral_web @tomtobac @abimacarmes @knajjars
3-
src/interfaces/assistants_web @tomtobac @abimacarmes @knajjars
2+
src/interfaces/coral_web @tomtobac @abimacarmes @knajjars @BeatrixCohere
3+
src/interfaces/assistants_web @tomtobac @abimacarmes @knajjars @BeatrixCohere

src/backend/services/compass.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,19 +116,19 @@ def invoke(
116116
index_name=parameters["index"]
117117
)
118118
case self.ValidActions.CREATE.value:
119-
self._create(parameters, **kwargs)
119+
return self._create(parameters, **kwargs)
120120
case self.ValidActions.SEARCH.value:
121121
return self._search(parameters, **kwargs)
122122
case self.ValidActions.UPDATE.value:
123-
self._update(parameters, **kwargs)
123+
return self._update(parameters, **kwargs)
124124
case self.ValidActions.DELETE.value:
125-
self._delete(parameters, **kwargs)
125+
return self._delete(parameters, **kwargs)
126126
case self.ValidActions.GET_DOCUMENT.value:
127127
return self._get_document(parameters, **kwargs)
128128
case self.ValidActions.ADD_CONTEXT.value:
129-
self._add_context(parameters, **kwargs)
129+
return self._add_context(parameters, **kwargs)
130130
case self.ValidActions.REFRESH.value:
131-
self._refresh(parameters, **kwargs)
131+
return self._refresh(parameters, **kwargs)
132132
case self.ValidActions.PROCESS_FILE.value:
133133
return self._process_file(parameters, **kwargs)
134134
case _:

src/backend/services/file.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,9 @@ def delete_all_conversation_files(
318318
if self.is_compass_enabled:
319319
compass = get_compass()
320320
try:
321+
logger.info(
322+
event=f"[Compass File Service] Deleting conversation {conversation_id} files from Compass"
323+
)
321324
compass.invoke(
322325
action=Compass.ValidActions.DELETE_INDEX,
323326
parameters={"index": conversation_id},
@@ -377,6 +380,9 @@ def delete_file_in_compass(
377380
compass = get_compass()
378381

379382
try:
383+
logger.info(
384+
event=f"[Compass File Service] Deleting file {file_id} from Compass {index}"
385+
)
380386
compass.invoke(
381387
action=Compass.ValidActions.DELETE,
382388
parameters={"index": index, "file_id": file_id},
@@ -496,9 +502,12 @@ async def consolidate_agent_files_in_compass(
496502
action=Compass.ValidActions.REFRESH,
497503
parameters={"index": agent_id},
498504
)
505+
logger.info(
506+
event=f"[Compass File Service] Delete temporary file index: {file_id}"
507+
)
499508
# Remove the temporary file index entry
500509
compass.invoke(
501-
action=Compass.ValidActions.DELETE_INDEX, parameters={"index": file_id}
510+
action=Compass.ValidActions.DELETE_INDEX, parameters={"index": agent_id}
502511
)
503512
except Exception as e:
504513
logger.error(

src/backend/tools/google_drive/tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class GoogleDrive(BaseTool):
2424

2525
@classmethod
2626
def is_available(cls) -> bool:
27-
return cls.CLIENT_ID is not None and cls.CLIENT_ID is not None
27+
return cls.CLIENT_ID is not None and cls.CLIENT_SECRET is not None
2828

2929
def _handle_tool_specific_errors(cls, error: Exception, **kwargs: Any):
3030
message = "[Google Drive] Tool Error: {}".format(str(error))
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { NextPage } from 'next';
22

33
import { UpdateAgent } from '@/components/Agents/UpdateAgent';
4+
import { getCohereServerClient } from '@/server/cohereServerClient';
45

56
type Props = {
67
params: {
@@ -9,12 +10,11 @@ type Props = {
910
searchParams: Record<string, string>;
1011
};
1112

12-
const Page: NextPage<Props> = ({ params }) => {
13-
return (
14-
<div className="h-full w-full rounded-lg border border-marble-950 bg-marble-980 dark:border-volcanic-150 dark:bg-volcanic-100">
15-
<UpdateAgent agentId={params.agentId} />
16-
</div>
17-
);
13+
const Page: NextPage<Props> = async ({ params }) => {
14+
const cohereServerClient = getCohereServerClient();
15+
const agent = await cohereServerClient.getAgent(params.agentId);
16+
17+
return <UpdateAgent agent={agent} />;
1818
};
1919

2020
export default Page;
Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { Metadata } from 'next';
2-
import { Suspense } from 'react';
32

43
import { CreateAgent } from '@/components/Agents/CreateAgent';
54

@@ -8,13 +7,7 @@ export const metadata: Metadata = {
87
};
98

109
const NewAssistantPage: React.FC = () => {
11-
return (
12-
<Suspense>
13-
<div className="h-full w-full rounded-lg border border-marble-950 bg-marble-980 dark:border-volcanic-150 dark:bg-volcanic-100">
14-
<CreateAgent />
15-
</div>
16-
</Suspense>
17-
);
10+
return <CreateAgent />;
1811
};
1912

2013
export default NewAssistantPage;

src/interfaces/assistants_web/src/components/Agents/AgentSettings/AgentSettingsForm.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export const AgentSettingsForm: React.FC<Props> = (props) => {
158158
};
159159

160160
return (
161-
<div className="flex flex-col space-y-6 p-8">
161+
<div className="flex flex-col space-y-6">
162162
{/* Step 1: Define your assistant - name, description, instruction */}
163163
<CollapsibleSection
164164
title="Define your assistant"

src/interfaces/assistants_web/src/components/Agents/CreateAgent.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export const CreateAgent: React.FC = () => {
102102
};
103103

104104
return (
105-
<div className="relative flex h-full w-full flex-col overflow-y-auto">
105+
<div className="flex h-full w-full flex-col overflow-y-auto">
106106
<header className="flex flex-col gap-y-3 border-b px-4 py-6 dark:border-volcanic-150 lg:px-10 lg:py-10">
107107
<MobileHeader />
108108
<div className="flex items-center space-x-2">
@@ -114,14 +114,16 @@ export const CreateAgent: React.FC = () => {
114114
</div>
115115
<Text styleAs="h4">Create assistant</Text>
116116
</header>
117-
<div className="overflow-y-auto">
118-
<AgentSettingsForm
119-
source="create"
120-
fields={fields}
121-
setFields={setFields}
122-
onSubmit={handleOpenSubmitModal}
123-
savePendingAssistant={() => setPendingAssistant(fields)}
124-
/>
117+
<div className="flex flex-grow flex-col gap-y-8 overflow-y-hidden px-8 pt-8">
118+
<div className="flex-grow overflow-y-auto">
119+
<AgentSettingsForm
120+
source="create"
121+
fields={fields}
122+
setFields={setFields}
123+
onSubmit={handleOpenSubmitModal}
124+
savePendingAssistant={() => setPendingAssistant(fields)}
125+
/>
126+
</div>
125127
</div>
126128
</div>
127129
);

src/interfaces/assistants_web/src/components/Agents/UpdateAgent.tsx

Lines changed: 33 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import { useLocalStorageValue } from '@react-hookz/web';
44
import Link from 'next/link';
5-
import React, { useEffect, useState } from 'react';
5+
import React, { useState } from 'react';
66

7+
import { AgentPublic } from '@/cohere-client';
78
import {
89
AgentSettingsFields,
910
AgentSettingsForm,
@@ -13,22 +14,30 @@ import { MobileHeader } from '@/components/MobileHeader';
1314
import { Button, Icon, Spinner, Text } from '@/components/Shared';
1415
import { DEFAULT_AGENT_MODEL, DEPLOYMENT_COHERE_PLATFORM } from '@/constants';
1516
import { useContextStore } from '@/context';
16-
import { useAgent, useIsAgentNameUnique, useUpdateAgent } from '@/hooks/agents';
17+
import { useIsAgentNameUnique, useUpdateAgent } from '@/hooks/agents';
1718
import { useNotify } from '@/hooks/toast';
1819

1920
type Props = {
20-
agentId: string;
21+
agent: AgentPublic;
2122
};
2223

23-
export const UpdateAgent: React.FC<Props> = ({ agentId }) => {
24+
export const UpdateAgent: React.FC<Props> = ({ agent }) => {
2425
const { error, success } = useNotify();
25-
const { data: agent, isLoading } = useAgent({ agentId });
2626
const { open, close } = useContextStore();
2727

2828
const { mutateAsync: updateAgent } = useUpdateAgent();
2929
const isAgentNameUnique = useIsAgentNameUnique();
3030
const [isSubmitting, setIsSubmitting] = useState(false);
31-
const [fields, setFields] = useState<AgentSettingsFields>();
31+
const [fields, setFields] = useState<AgentSettingsFields>({
32+
name: agent.name,
33+
description: agent.description,
34+
deployment: agent.deployment ?? DEPLOYMENT_COHERE_PLATFORM,
35+
model: agent.model ?? DEFAULT_AGENT_MODEL,
36+
tools: agent.tools,
37+
preamble: agent.preamble,
38+
tools_metadata: agent.tools_metadata,
39+
is_private: agent.is_private,
40+
});
3241

3342
const { set: setPendingAssistant } = useLocalStorageValue<AgentSettingsFields>(
3443
'pending_assistant',
@@ -38,54 +47,24 @@ export const UpdateAgent: React.FC<Props> = ({ agentId }) => {
3847
}
3948
);
4049

41-
useEffect(() => {
42-
if (agent) {
43-
setFields({
44-
name: agent.name,
45-
description: agent.description,
46-
deployment: agent.deployment ?? DEPLOYMENT_COHERE_PLATFORM,
47-
model: agent.model ?? DEFAULT_AGENT_MODEL,
48-
tools: agent.tools,
49-
preamble: agent.preamble,
50-
tools_metadata: agent.tools_metadata,
51-
is_private: agent.is_private,
52-
});
53-
}
54-
}, [agent]);
55-
5650
const handleOpenDeleteModal = () => {
57-
if (!agent || !agent.name || !agentId) return;
5851
open({
5952
title: `Delete ${agent.name}`,
60-
content: <DeleteAgent name={agent.name} agentId={agentId} onClose={close} />,
53+
content: <DeleteAgent name={agent.name} agentId={agent.id} onClose={close} />,
6154
});
6255
};
6356

64-
if (isLoading && !fields) {
65-
return (
66-
<div className="flex h-full w-full items-center justify-center">
67-
<Spinner />
68-
</div>
69-
);
70-
}
71-
72-
if (!agent || !fields) {
73-
return (
74-
<div className="flex h-full w-full items-center justify-center">
75-
<Text className="text-danger-350">Unable to load assistant information</Text>
76-
</div>
77-
);
78-
}
79-
8057
const handleSubmit = async () => {
81-
if (!agentId) return;
8258
const tools_metadata = (fields.tools_metadata ?? []).map((tool) => ({
8359
...tool,
8460
id: agent.tools_metadata?.find((t) => t.tool_name === tool.tool_name)?.id,
8561
}));
8662
try {
8763
setIsSubmitting(true);
88-
const newAgent = await updateAgent({ request: { ...fields, tools_metadata }, agentId });
64+
const newAgent = await updateAgent({
65+
request: { ...fields, tools_metadata },
66+
agentId: agent.id,
67+
});
8968
setIsSubmitting(false);
9069
success(`Updated ${newAgent?.name}`);
9170
} catch (e) {
@@ -96,7 +75,7 @@ export const UpdateAgent: React.FC<Props> = ({ agentId }) => {
9675
};
9776

9877
return (
99-
<div className="relative flex h-full w-full flex-col overflow-y-auto">
78+
<div className="flex h-full w-full flex-col overflow-y-auto">
10079
<header className="flex flex-col gap-y-3 border-b px-4 py-6 dark:border-volcanic-150 lg:px-10 lg:py-10">
10180
<MobileHeader />
10281
<div className="flex items-center space-x-2">
@@ -108,16 +87,18 @@ export const UpdateAgent: React.FC<Props> = ({ agentId }) => {
10887
</div>
10988
<Text styleAs="h4">Edit {agent.name}</Text>
11089
</header>
111-
<div className="flex flex-col overflow-y-auto">
112-
<AgentSettingsForm
113-
source="update"
114-
fields={fields}
115-
setFields={setFields}
116-
onSubmit={handleSubmit}
117-
savePendingAssistant={() => setPendingAssistant(fields)}
118-
agentId={agentId}
119-
/>
120-
<div className="space-y-5 p-8">
90+
<div className="flex flex-grow flex-col gap-y-8 overflow-y-hidden px-8 pt-8">
91+
<div className="flex-grow overflow-y-auto">
92+
<AgentSettingsForm
93+
source="update"
94+
fields={fields}
95+
setFields={setFields}
96+
onSubmit={handleSubmit}
97+
savePendingAssistant={() => setPendingAssistant(fields)}
98+
agentId={agent.id}
99+
/>
100+
</div>
101+
<div className="space-y-5 pb-8">
121102
<div className="flex w-full max-w-screen-md items-center justify-between ">
122103
<Button label="Cancel" kind="secondary" href="/discover" />
123104
<Button

src/interfaces/assistants_web/src/components/CollapsibleSection.tsx

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
'use client';
22

3-
import { ReactNode, useEffect, useRef } from 'react';
3+
import { ReactNode } from 'react';
44

55
import { Icon, Text } from '@/components/Shared';
66
import { cn } from '@/utils';
@@ -21,20 +21,8 @@ export const CollapsibleSection: React.FC<Props> = ({
2121
isExpanded = false,
2222
setIsExpanded,
2323
}) => {
24-
const ref = useRef<HTMLDivElement>(null);
25-
useEffect(() => {
26-
if (isExpanded) {
27-
ref.current?.scrollIntoView({
28-
behavior: 'smooth',
29-
block: 'center',
30-
inline: 'nearest',
31-
});
32-
}
33-
}, [isExpanded]);
34-
3524
return (
3625
<div
37-
ref={ref}
3826
className={cn(
3927
'flex w-full max-w-screen-md flex-col rounded-md',
4028
'space-y-5 border p-6',

src/interfaces/assistants_web/src/constants.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ export const TOOL_CALCULATOR_ID = 'toolkit_calculator';
5858
export const TOOL_WEB_SCRAPE_ID = 'web_scrape';
5959
export const TOOL_GOOGLE_DRIVE_ID = 'google_drive';
6060
export const FILE_UPLOAD_TOOLS = [TOOL_SEARCH_FILE_ID, TOOL_READ_DOCUMENT_ID];
61-
export const AGENT_SETTINGS_TOOLS = [TOOL_WEB_SEARCH_ID, TOOL_PYTHON_INTERPRETER_ID];
61+
export const AGENT_SETTINGS_TOOLS = [
62+
TOOL_WEB_SEARCH_ID,
63+
TOOL_PYTHON_INTERPRETER_ID,
64+
TOOL_WEB_SCRAPE_ID,
65+
];
6266

6367
export const TOOL_FALLBACK_ICON = 'circles-four';
6468
export const TOOL_ID_TO_DISPLAY_INFO: { [id: string]: { icon: IconName } } = {

src/interfaces/assistants_web/src/hooks/brandedColors.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,10 @@ const getAssistantContrastColor = (assistantId: string | undefined): string => {
6161
};
6262

6363
export const getCohereTheme = (assistantId?: string): COHERE_BRANDED_COLORS => {
64-
if (assistantId === undefined) {
65-
return COHERE_THEMES_MAP.default;
66-
} else {
67-
const idNumber = assistantId.split('').reduce((acc, char) => acc + char.charCodeAt(0), 0);
68-
const index = idNumber % COHERE_THEMES_MAP.branded.length;
69-
return COHERE_THEMES_MAP.branded[index];
70-
}
64+
if (!assistantId) return COHERE_THEMES_MAP.default;
65+
const idNumber = assistantId.split('').reduce((acc, char) => acc + char.charCodeAt(0), 0);
66+
const index = idNumber % COHERE_THEMES_MAP.branded.length;
67+
return COHERE_THEMES_MAP.branded[index];
7168
};
7269

7370
const getDarkMode = (color: string) => `dark:${color}`;

0 commit comments

Comments
 (0)