Skip to content

Commit

Permalink
add external endpoint to retrieve available assistant configurations (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
fontanierh authored Oct 5, 2023
1 parent 55d8c37 commit b0fbb24
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/src/components/Navigation.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ export const navigation = [
{ title: "Runs", href: "/runs" },
{ title: "Documents", href: "/documents" },
{ title: "Conversations", href: "/conversations" },
{ title: "Agents", href: "/agents" },
],
},
];
Expand Down
79 changes: 79 additions & 0 deletions docs/src/pages/agents.mdx
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 front/pages/api/v1/w/[wId]/assistant/agent_configurations.ts
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);

0 comments on commit b0fbb24

Please sign in to comment.