-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add external endpoint to retrieve available assistant configurations (#…
- Loading branch information
1 parent
55d8c37
commit b0fbb24
Showing
3 changed files
with
133 additions
and
0 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,79 @@ | ||
## Agent Configuration Model | ||
|
||
The Agent Configuration model contains all the information and data related to an agent configuration. | ||
|
||
### Properties | ||
|
||
<Properties> | ||
<Property name="sId" type="string"> | ||
Unique identifier for the agent configuration. | ||
</Property> | ||
<Property name="scope" type="AgentConfigurationScope"> | ||
The scope of the agent configuration. It can be either `global` or | ||
`workspace`. | ||
</Property> | ||
<Property name="status" type="AgentConfigurationStatus"> | ||
Status of the agent configuration. It can be one of the following: `active`, | ||
`archived`, `disabled_by_admin`, `disabled_missing_datasource`, | ||
`disabled_free_workspace`. | ||
</Property> | ||
<Property name="name" type="string"> | ||
The name of the agent. | ||
</Property> | ||
<Property name="description" type="string"> | ||
A description of the agent. | ||
</Property> | ||
<Property name="pictureUrl" type="string"> | ||
The URL of the agent's picture. | ||
</Property> | ||
</Properties> | ||
|
||
--- | ||
|
||
## Retrieve Agent Configurations {{ tag: 'GET', label: '/v1/w/:workspace_id/assistant/agent_configurations' }} | ||
|
||
<Row> | ||
<Col> | ||
|
||
This endpoint allows you to retrieve a list of Agent Configurations. Each Agent Configuration includes details about the agent's scope, status, name, description, and picture URL. | ||
|
||
### URL attributes | ||
|
||
<Properties> | ||
<Property name="workspace_id" type="string"> | ||
The ID of the workspace (can be found in the workspace's URL) | ||
</Property> | ||
</Properties> | ||
|
||
</Col> | ||
<Col sticky> | ||
|
||
<CodeGroup title="Request" tag="GET" label="/v1/w/:workspace_id/assistant/agent_configurations"> | ||
|
||
```bash {{ title: 'cURL' }} | ||
curl https://dust.tt/api/v1/w/workspace1/assistant/agent_configurations \ | ||
-H "Authorization: Bearer sk-..." \ | ||
``` | ||
|
||
</CodeGroup> | ||
|
||
```json {{ title: 'Response' }} | ||
{ | ||
"agentConfigurations": [ | ||
{ | ||
"sId": "dust", | ||
"scope": "global", | ||
"status": "active", | ||
"name": "Dust Assistant", | ||
"description": "An assistant with context on your company data.", | ||
"pictureUrl": "https://dust.tt/static/systemavatar/dust_avatar_full.png" | ||
}, | ||
... | ||
] | ||
} | ||
``` | ||
|
||
</Col> | ||
</Row> | ||
|
||
--- |
53 changes: 53 additions & 0 deletions
53
front/pages/api/v1/w/[wId]/assistant/agent_configurations.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,53 @@ | ||
import { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
import { getAgentConfigurations } from "@app/lib/api/assistant/configuration"; | ||
import { Authenticator, getAPIKey } from "@app/lib/auth"; | ||
import { ReturnedAPIErrorType } from "@app/lib/error"; | ||
import { apiError, withLogging } from "@app/logger/withlogging"; | ||
import { GetAgentConfigurationsResponseBody } from "@app/pages/api/w/[wId]/assistant/agent_configurations"; | ||
|
||
async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse< | ||
GetAgentConfigurationsResponseBody | ReturnedAPIErrorType | void | ||
> | ||
): Promise<void> { | ||
const keyRes = await getAPIKey(req); | ||
if (keyRes.isErr()) { | ||
return apiError(req, res, keyRes.error); | ||
} | ||
|
||
const { auth, keyWorkspaceId } = await Authenticator.fromKey( | ||
keyRes.value, | ||
req.query.wId as string | ||
); | ||
|
||
if (!auth.isBuilder() || keyWorkspaceId !== req.query.wId) { | ||
return apiError(req, res, { | ||
status_code: 400, | ||
api_error: { | ||
type: "invalid_request_error", | ||
message: "The Assistant API is only available on your own workspace.", | ||
}, | ||
}); | ||
} | ||
|
||
switch (req.method) { | ||
case "GET": { | ||
const agentConfigurations = await getAgentConfigurations(auth); | ||
return res.status(200).json({ | ||
agentConfigurations, | ||
}); | ||
} | ||
default: | ||
return apiError(req, res, { | ||
status_code: 405, | ||
api_error: { | ||
type: "method_not_supported_error", | ||
message: "The method passed is not supported, only GET is expected.", | ||
}, | ||
}); | ||
} | ||
} | ||
|
||
export default withLogging(handler); |