-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add: dropdown to show all assistants used by a datasource and show mo…
…dal on click (#8932) * Add: dropdown to show all assistants used by a datasource and show modal when click * Review fdbk
- Loading branch information
Showing
5 changed files
with
185 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { | ||
Button, | ||
DropdownMenu, | ||
DropdownMenuContent, | ||
DropdownMenuItem, | ||
DropdownMenuTrigger, | ||
RobotIcon, | ||
ScrollArea, | ||
} from "@dust-tt/sparkle"; | ||
import type { DataSourceWithAgentsUsageType } from "@dust-tt/types"; | ||
|
||
export const UsedByButton = ({ | ||
usage, | ||
onItemClick, | ||
}: { | ||
usage: DataSourceWithAgentsUsageType; | ||
onItemClick: (assistantSid: string) => void; | ||
}) => { | ||
return usage.count === 0 ? ( | ||
<Button | ||
icon={RobotIcon} | ||
variant="ghost" | ||
isSelect={false} | ||
size="sm" | ||
label={`${usage.count}`} | ||
disabled | ||
/> | ||
) : ( | ||
<DropdownMenu> | ||
<DropdownMenuTrigger asChild> | ||
<Button | ||
icon={RobotIcon} | ||
variant="ghost" | ||
isSelect={true} | ||
size="sm" | ||
label={`${usage.count}`} | ||
/> | ||
</DropdownMenuTrigger> | ||
<DropdownMenuContent className="max-w-[300px]"> | ||
<ScrollArea className="border-1 h-[130px]"> | ||
{usage.agentNames.map((name) => ( | ||
<DropdownMenuItem | ||
key={`assistant-picker-${name}`} | ||
label={name} | ||
onClick={(e) => { | ||
e.stopPropagation(); | ||
onItemClick(name); | ||
}} | ||
/> | ||
))} | ||
</ScrollArea> | ||
</DropdownMenuContent> | ||
</DropdownMenu> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
front/pages/api/w/[wId]/assistant/agent_configurations/lookup.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import type { WithAPIErrorResponse } from "@dust-tt/types"; | ||
import { isLeft } from "fp-ts/lib/Either"; | ||
import * as t from "io-ts"; | ||
import * as reporter from "io-ts-reporters"; | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
import { getAgentSIdFromName } from "@app/lib/api/assistant/configuration"; | ||
import { withSessionAuthenticationForWorkspace } from "@app/lib/api/auth_wrappers"; | ||
import type { Authenticator } from "@app/lib/auth"; | ||
import { apiError } from "@app/logger/withlogging"; | ||
|
||
const GetLookupRequestSchema = t.type({ | ||
handle: t.string, | ||
}); | ||
|
||
type GetLookupResponseBody = { | ||
sId: string; | ||
}; | ||
|
||
async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse<WithAPIErrorResponse<GetLookupResponseBody | void>>, | ||
auth: Authenticator | ||
): Promise<void> { | ||
switch (req.method) { | ||
case "GET": | ||
const bodyValidation = GetLookupRequestSchema.decode(req.query); | ||
|
||
if (isLeft(bodyValidation)) { | ||
const pathError = reporter.formatValidationErrors(bodyValidation.left); | ||
|
||
return apiError(req, res, { | ||
status_code: 400, | ||
api_error: { | ||
type: "invalid_request_error", | ||
message: `Invalid request body: ${pathError}`, | ||
}, | ||
}); | ||
} | ||
const sId = await getAgentSIdFromName(auth, bodyValidation.right.handle); | ||
if (!sId) { | ||
return apiError(req, res, { | ||
status_code: 404, | ||
api_error: { | ||
type: "agent_configuration_not_found", | ||
message: "The Assistant you're trying to access was not found.", | ||
}, | ||
}); | ||
} | ||
|
||
return res.status(200).json({ sId }); | ||
|
||
default: | ||
return apiError(req, res, { | ||
status_code: 405, | ||
api_error: { | ||
type: "method_not_supported_error", | ||
message: "The method passed is not supported, GET is expected.", | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
export default withSessionAuthenticationForWorkspace(handler); |