-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Basic versioning (not sticking to figma yet) * Remembering edits on latest version * better button positioning * Re-positioning advanced settings * Now remembering all version edits * New date formatter * Fixed scroll area height -> now dynamic --------- Co-authored-by: Lucas <lucas@dust.tt>
- Loading branch information
Showing
5 changed files
with
269 additions
and
1 deletion.
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
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
87 changes: 87 additions & 0 deletions
87
front/pages/api/w/[wId]/assistant/agent_configurations/[aId]/history/index.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,87 @@ | ||
import type { | ||
LightAgentConfigurationType, | ||
WithAPIErrorResponse, | ||
} from "@dust-tt/types"; | ||
import { GetAgentConfigurationsHistoryQuerySchema } from "@dust-tt/types"; | ||
import { isLeft } from "fp-ts/lib/Either"; | ||
import * as reporter from "io-ts-reporters"; | ||
import type { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
import { getAgentConfigurations } 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"; | ||
|
||
export type GetAgentConfigurationsResponseBody = { | ||
history: LightAgentConfigurationType[]; | ||
}; | ||
|
||
async function handler( | ||
req: NextApiRequest, | ||
res: NextApiResponse< | ||
WithAPIErrorResponse<GetAgentConfigurationsResponseBody | void> | ||
>, | ||
auth: Authenticator | ||
): Promise<void> { | ||
switch (req.method) { | ||
case "GET": | ||
// extract the limit from the query parameters | ||
const queryValidation = GetAgentConfigurationsHistoryQuerySchema.decode({ | ||
...req.query, | ||
limit: | ||
typeof req.query.limit === "string" | ||
? parseInt(req.query.limit, 10) | ||
: undefined, | ||
}); | ||
if (isLeft(queryValidation)) { | ||
const pathError = reporter.formatValidationErrors(queryValidation.left); | ||
return apiError(req, res, { | ||
status_code: 400, | ||
api_error: { | ||
type: "invalid_request_error", | ||
message: `Invalid query parameters: ${pathError}`, | ||
}, | ||
}); | ||
} | ||
|
||
const { limit } = queryValidation.right; | ||
|
||
const agentConfigurations = await getAgentConfigurations({ | ||
auth, | ||
agentsGetView: { | ||
agentIds: [req.query.aId as string], | ||
allVersions: true, | ||
}, | ||
variant: "light", | ||
// Return the latest versions first | ||
sort: "updatedAt", | ||
limit, | ||
}); | ||
|
||
if ( | ||
!agentConfigurations || | ||
(agentConfigurations[0].scope === "private" && | ||
agentConfigurations[0].versionAuthorId !== auth.user()?.id) | ||
) { | ||
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({ history: agentConfigurations }); | ||
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); |
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