-
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.
Move to ConnectorType.configuration (#4557)
* Tmp commit Fix managed/update renderConnectorType() Fully working for websites Clean up Cleaning up the createConnector Interface Clean up typing in connectors Removes unknown from connectorsAPI.updateConfiguration Removing unknown Cleaning up following @spolu's comments. Remvoe console.log() Just removing a comment Make connectionId non optional Make sure only webcrawler configuration can be updated by a user * Fix typing
- Loading branch information
Showing
27 changed files
with
748 additions
and
461 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,111 @@ | ||
import type { | ||
ConnectorType, | ||
Result, | ||
UpdateConnectorConfigurationType, | ||
WithConnectorsAPIErrorReponse, | ||
} from "@dust-tt/types"; | ||
import { | ||
assertNever, | ||
ioTsParsePayload, | ||
WebCrawlerConfigurationTypeSchema, | ||
} from "@dust-tt/types"; | ||
import type { Request, Response } from "express"; | ||
|
||
import { SET_CONNECTOR_CONFIGURATION_BY_TYPE } from "@connectors/connectors"; | ||
import { renderConnectorType } from "@connectors/lib/renderers/connector"; | ||
import { apiError, withLogging } from "@connectors/logger/withlogging"; | ||
import { ConnectorResource } from "@connectors/resources/connector_resource"; | ||
|
||
type PatchConnectorConfigurationResBody = | ||
WithConnectorsAPIErrorReponse<ConnectorType>; | ||
|
||
const _patchConnectorConfiguration = async ( | ||
req: Request< | ||
{ connector_id: string }, | ||
PatchConnectorConfigurationResBody, | ||
UpdateConnectorConfigurationType | ||
>, | ||
res: Response<PatchConnectorConfigurationResBody> | ||
) => { | ||
const connector = await ConnectorResource.fetchById(req.params.connector_id); | ||
if (!connector) { | ||
return apiError(req, res, { | ||
api_error: { | ||
type: "connector_not_found", | ||
message: "Connector not found", | ||
}, | ||
status_code: 404, | ||
}); | ||
} | ||
|
||
let patchRes: Result<void, Error> | null = null; | ||
switch (connector.type) { | ||
case "webcrawler": { | ||
const parseRes = ioTsParsePayload( | ||
req.body.configuration, | ||
WebCrawlerConfigurationTypeSchema | ||
); | ||
if (parseRes.isErr()) { | ||
return apiError(req, res, { | ||
api_error: { | ||
type: "invalid_request_error", | ||
message: `Invalid configuration: ${parseRes.error.join(", ")}`, | ||
}, | ||
status_code: 400, | ||
}); | ||
} | ||
const setConfiguration = | ||
SET_CONNECTOR_CONFIGURATION_BY_TYPE[connector.type]; | ||
patchRes = await setConfiguration(connector.id, parseRes.value); | ||
break; | ||
} | ||
|
||
case "notion": | ||
case "confluence": | ||
case "github": | ||
case "google_drive": | ||
case "intercom": | ||
case "slack": { | ||
throw new Error( | ||
`Connector type ${connector.type} does not support configuration patching` | ||
); | ||
} | ||
|
||
default: { | ||
assertNever(connector.type); | ||
} | ||
} | ||
|
||
if (patchRes.isErr()) { | ||
return apiError( | ||
req, | ||
res, | ||
{ | ||
api_error: { | ||
type: "internal_server_error", | ||
message: patchRes.error.message, | ||
}, | ||
status_code: 500, | ||
}, | ||
patchRes.error | ||
); | ||
} | ||
|
||
const updatedConnector = await ConnectorResource.fetchById( | ||
req.params.connector_id | ||
); | ||
if (!updatedConnector) { | ||
return apiError(req, res, { | ||
api_error: { | ||
type: "connector_not_found", | ||
message: "Connector not found", | ||
}, | ||
status_code: 404, | ||
}); | ||
} | ||
return res.status(200).json(await renderConnectorType(updatedConnector)); | ||
}; | ||
|
||
export const patchConnectorConfigurationAPIHandler = withLogging( | ||
_patchConnectorConfiguration | ||
); |
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
Oops, something went wrong.