Skip to content

Commit

Permalink
Add Poke Plugin to set connector error and pause. (#10025)
Browse files Browse the repository at this point in the history
* Add Poke Plugin to set connector error and pause.

* 👕
  • Loading branch information
flvndvd authored Jan 16, 2025
1 parent 88c8386 commit 0527010
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 3 deletions.
4 changes: 4 additions & 0 deletions connectors/src/api/admin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ const whitelistedCommands = [
command: "find-url",
},
{ majorCommand: "slack", command: "whitelist-bot" },
{
majorCommand: "connectors",
command: "set-error",
},
];

const _adminAPIHandler = async (
Expand Down
1 change: 1 addition & 0 deletions front/lib/api/poke/plugins/data_sources/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from "./garbage_collect_google_drive_document";
export * from "./mark_connector_as_error";
export * from "./operations";
78 changes: 78 additions & 0 deletions front/lib/api/poke/plugins/data_sources/mark_connector_as_error.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import type { AdminCommandType } from "@dust-tt/types";
import { CONNECTORS_ERROR_TYPES, ConnectorsAPI, Err, Ok } from "@dust-tt/types";

import config from "@app/lib/api/config";
import { createPlugin } from "@app/lib/api/poke/types";
import { isManaged, isWebsite } from "@app/lib/data_sources";
import { DataSourceResource } from "@app/lib/resources/data_source_resource";
import logger from "@app/logger/logger";

export const markConnectorAsErrorPlugin = createPlugin(
{
id: "mark-connector-as-error",
name: "Mark connector as error",
description: "Mark a connector as errored with a specific error type",
resourceTypes: ["data_sources"],
args: {
errorType: {
type: "enum",
label: "Error Type",
description: "Select error type to set",
values: CONNECTORS_ERROR_TYPES,
},
},
},
async (auth, dataSourceId, args) => {
if (!dataSourceId) {
return new Err(new Error("Data source not found."));
}

const dataSource = await DataSourceResource.fetchById(auth, dataSourceId);
if (!dataSource) {
return new Err(new Error("Data source not found."));
}

if (!isManaged(dataSource) && !isWebsite(dataSource)) {
return new Err(new Error("Data source is not managed or website."));
}

const { connectorId } = dataSource;
if (!connectorId) {
return new Err(new Error("No connector on datasource."));
}

const { errorType } = args;
const connectorsAPI = new ConnectorsAPI(
config.getConnectorsAPIConfig(),
logger
);

// First set the error.
const setErrorCommand: AdminCommandType = {
majorCommand: "connectors",
command: "set-error",
args: {
connectorId: connectorId.toString(),
error: errorType,
wId: auth.getNonNullableWorkspace().sId,
dsId: dataSource.sId,
},
};

const setErrorRes = await connectorsAPI.admin(setErrorCommand);
if (setErrorRes.isErr()) {
return new Err(new Error(setErrorRes.error.message));
}

// Then pause it.
const pauseRes = await connectorsAPI.pauseConnector(connectorId.toString());
if (pauseRes.isErr()) {
return new Err(new Error(pauseRes.error.message));
}

return new Ok({
display: "text",
value: `Connector ${connectorId} marked as ${errorType} and paused.`,
});
}
);
2 changes: 0 additions & 2 deletions front/lib/api/poke/plugins/data_sources/operations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,11 @@ export const connectorOperationsPlugin = createPlugin(
}

const dataSource = await DataSourceResource.fetchById(auth, dataSourceId);

if (!dataSource) {
return new Err(new Error("Data source not found."));
}

const { connectorId } = dataSource;

if (!connectorId) {
return new Err(new Error("No connector on datasource."));
}
Expand Down
2 changes: 1 addition & 1 deletion types/src/front/lib/connectors_api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { Err, Ok, Result } from "../../shared/result";

export type ConnectorsAPIResponse<T> = Result<T, ConnectorsAPIError>;
export type ConnectorSyncStatus = "succeeded" | "failed";
const CONNECTORS_ERROR_TYPES = [
export const CONNECTORS_ERROR_TYPES = [
"oauth_token_revoked",
"third_party_internal_error",
"webcrawling_error",
Expand Down

0 comments on commit 0527010

Please sign in to comment.