Skip to content

Commit

Permalink
Rename ConnectorNode to ContentNode (#4158)
Browse files Browse the repository at this point in the history
  • Loading branch information
PopDaph authored Mar 5, 2024
1 parent 05551e2 commit 7acfce3
Show file tree
Hide file tree
Showing 22 changed files with 124 additions and 134 deletions.
4 changes: 2 additions & 2 deletions connectors/src/api/get_connector_permissions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ import type {
ConnectorPermission,
WithConnectorsAPIErrorReponse,
} from "@dust-tt/types";
import type { ConnectorNode } from "@dust-tt/types";
import type { ContentNode } from "@dust-tt/types";
import type { Request, Response } from "express";

import { RETRIEVE_CONNECTOR_PERMISSIONS_BY_TYPE } from "@connectors/connectors";
import { apiError, withLogging } from "@connectors/logger/withlogging";
import { ConnectorResource } from "@connectors/resources/connector_resource";

type GetConnectorPermissionsRes = WithConnectorsAPIErrorReponse<{
resources: ConnectorNode[];
resources: ContentNode[];
}>;

const _getConnectorPermissions = async (
Expand Down
16 changes: 8 additions & 8 deletions connectors/src/api/get_content_nodes.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type {
ConnectorNode,
ContentNode,
WithConnectorsAPIErrorReponse,
} from "@dust-tt/types";
import type { Request, Response } from "express";
Expand All @@ -20,7 +20,7 @@ type GetContentNodesRequestBody = t.TypeOf<
>;

type GetContentNodesResponseBody = WithConnectorsAPIErrorReponse<{
nodes: ConnectorNode[];
nodes: ContentNode[];
}>;

const _getContentNodes = async (
Expand Down Expand Up @@ -56,27 +56,27 @@ const _getContentNodes = async (

const { internalIds } = bodyValidation.right;

const connectorNodesRes: Result<ConnectorNode[], Error> =
const contentNodesRes: Result<ContentNode[], Error> =
await BATCH_RETRIEVE_CONTENT_NODES_BY_TYPE[connector.type](
connector.id,
internalIds
);

if (connectorNodesRes.isErr()) {
if (contentNodesRes.isErr()) {
return apiError(req, res, {
status_code: 500,
api_error: {
type: "internal_server_error",
message: connectorNodesRes.error.message,
message: contentNodesRes.error.message,
},
});
}

const connectorNodes = connectorNodesRes.value;
const contentNodes = contentNodesRes.value;

return res.status(200).json({
nodes: connectorNodes,
nodes: contentNodes,
});
};

export const getConnectorNodesAPIHandler = withLogging(_getContentNodes);
export const getContentNodesAPIHandler = withLogging(_getContentNodes);
4 changes: 2 additions & 2 deletions connectors/src/api_server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { deleteConnectorAPIHandler } from "@connectors/api/delete_connector";
import { getConnectorAPIHandler } from "@connectors/api/get_connector";
import { getConnectorPermissionsAPIHandler } from "@connectors/api/get_connector_permissions";
import { getContentNodesParentsAPIHandler } from "@connectors/api/get_content_node_parents";
import { getConnectorNodesAPIHandler } from "@connectors/api/get_content_nodes";
import { getContentNodesAPIHandler } from "@connectors/api/get_content_nodes";
import { getResourcesTitlesAPIHandler } from "@connectors/api/get_resources_titles";
import { resumeConnectorAPIHandler } from "@connectors/api/resume_connector";
import { setConnectorPermissionsAPIHandler } from "@connectors/api/set_connector_permissions";
Expand Down Expand Up @@ -110,7 +110,7 @@ export function startServer(port: number) {
app.post(
// must be POST because of body
"/connectors/:connector_id/content_nodes",
getConnectorNodesAPIHandler
getContentNodesAPIHandler
);
app.post(
"/connectors/:connector_id/permissions",
Expand Down
18 changes: 9 additions & 9 deletions connectors/src/connectors/confluence/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type {
ConnectorNode,
ConnectorPermission,
ConnectorsAPIError,
ContentNode,
ModelId,
} from "@dust-tt/types";

Expand All @@ -21,8 +21,8 @@ import {
} from "@connectors/connectors/confluence/lib/internal_ids";
import {
checkPageHasChildren,
createConnectorNodeFromPage,
createConnectorNodeFromSpace,
createContentNodeFromPage,
createContentNodeFromSpace,
retrieveAvailableSpaces,
retrieveHierarchyForParent,
} from "@connectors/connectors/confluence/lib/permissions";
Expand Down Expand Up @@ -254,7 +254,7 @@ export async function retrieveConfluenceConnectorPermissions({
parentInternalId,
filterPermission,
}: Parameters<ConnectorPermissionRetriever>[0]): Promise<
Result<ConnectorNode[], Error>
Result<ContentNode[], Error>
> {
const connector = await ConnectorResource.fetchById(connectorId);
if (!connector) {
Expand Down Expand Up @@ -403,7 +403,7 @@ export async function retrieveConfluenceObjectsTitles(
export async function retrieveConfluenceContentNodes(
connectorId: ModelId,
internalIds: string[]
): Promise<Result<ConnectorNode[], Error>> {
): Promise<Result<ContentNode[], Error>> {
const connectorState = await ConfluenceConfiguration.findOne({
where: {
connectorId,
Expand Down Expand Up @@ -439,13 +439,13 @@ export async function retrieveConfluenceContentNodes(
}),
]);

const spaceContentNodes: ConnectorNode[] = confluenceSpaces.map((space) => {
return createConnectorNodeFromSpace(space, connectorState.url, "read", {
const spaceContentNodes: ContentNode[] = confluenceSpaces.map((space) => {
return createContentNodeFromSpace(space, connectorState.url, "read", {
isExpandable: true,
});
});

const pageContentNodes: ConnectorNode[] = await concurrentExecutor(
const pageContentNodes: ContentNode[] = await concurrentExecutor(
confluencePages,
async (page) => {
let parentId: string;
Expand All @@ -460,7 +460,7 @@ export async function retrieveConfluenceContentNodes(
}
const isExpandable = await checkPageHasChildren(connectorId, page.pageId);

return createConnectorNodeFromPage(
return createContentNodeFromPage(
{ id: parentId, type: parentType },
connectorState.url,
page,
Expand Down
26 changes: 13 additions & 13 deletions connectors/src/connectors/confluence/lib/permissions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {
ConnectorNode,
ConnectorPermission,
ContentNode,
ModelId,
Result,
} from "@dust-tt/types";
Expand Down Expand Up @@ -34,12 +34,12 @@ function isConfluenceSpaceModel(
);
}

export function createConnectorNodeFromSpace(
export function createContentNodeFromSpace(
space: ConfluenceSpace | ConfluenceSpaceType,
baseUrl: string,
permission: ConnectorPermission,
{ isExpandable }: { isExpandable: boolean }
): ConnectorNode {
): ContentNode {
const urlSuffix = isConfluenceSpaceModel(space)
? space.urlSuffix
: space._links.webui;
Expand All @@ -59,12 +59,12 @@ export function createConnectorNodeFromSpace(
};
}

export function createConnectorNodeFromPage(
export function createContentNodeFromPage(
parent: { id: string; type: "page" | "space" },
baseUrl: string,
page: ConfluencePage,
isExpandable = false
): ConnectorNode {
): ContentNode {
return {
provider: "confluence",
internalId: makeConfluenceInternalPageId(page.pageId),
Expand Down Expand Up @@ -101,7 +101,7 @@ async function getSynchronizedSpaces(
connectorId: ModelId,
confluenceConfig: ConfluenceConfiguration,
parentInternalId: string
): Promise<Result<ConnectorNode[], Error>> {
): Promise<Result<ContentNode[], Error>> {
const confluenceId = getIdFromConfluenceInternalId(parentInternalId);

const parentSpace = await ConfluenceSpace.findOne({
Expand All @@ -127,11 +127,11 @@ async function getSynchronizedSpaces(
},
});

const allPages: ConnectorNode[] = [];
const allPages: ContentNode[] = [];
for (const page of pagesWithinSpace) {
const hasChildren = await checkPageHasChildren(connectorId, page.pageId);

const res = createConnectorNodeFromPage(
const res = createContentNodeFromPage(
{ id: parentSpace.spaceId, type: "space" },
confluenceConfig.url,
page,
Expand All @@ -148,7 +148,7 @@ async function getSynchronizedChildrenPages(
connectorId: ModelId,
confluenceConfig: ConfluenceConfiguration,
parentInternalId: string
): Promise<Result<ConnectorNode[], Error>> {
): Promise<Result<ContentNode[], Error>> {
const confluenceId = getIdFromConfluenceInternalId(parentInternalId);

const parentPage = await ConfluencePage.findOne({
Expand All @@ -171,11 +171,11 @@ async function getSynchronizedChildrenPages(
},
});

const allPages: ConnectorNode[] = [];
const allPages: ContentNode[] = [];
for (const page of pagesWithinSpace) {
const hasChildren = await checkPageHasChildren(connectorId, page.pageId);

const res = createConnectorNodeFromPage(
const res = createContentNodeFromPage(
{ id: parentPage.pageId, type: "page" },
confluenceConfig.url,
page,
Expand Down Expand Up @@ -232,7 +232,7 @@ export async function retrieveHierarchyForParent(
});

const allSpaces = syncedSpaces.map((space) =>
createConnectorNodeFromSpace(space, confluenceConfig.url, "read", {
createContentNodeFromSpace(space, confluenceConfig.url, "read", {
isExpandable: true,
})
);
Expand All @@ -257,7 +257,7 @@ export async function retrieveAvailableSpaces(
return spaces.map((space) => {
const isSynced = syncedSpaces.some((ss) => ss.spaceId === space.id);

return createConnectorNodeFromSpace(
return createContentNodeFromSpace(
space,
confluenceConfig.url,
isSynced ? "read" : "none",
Expand Down
18 changes: 7 additions & 11 deletions connectors/src/connectors/github/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import type {
ConnectorNode,
ConnectorsAPIError,
ModelId,
} from "@dust-tt/types";
import type { ConnectorsAPIError, ContentNode, ModelId } from "@dust-tt/types";
import { assertNever } from "@dust-tt/types";

import type { GithubRepo } from "@connectors/connectors/github/lib/github_api";
Expand Down Expand Up @@ -228,7 +224,7 @@ export async function retrieveGithubConnectorPermissions({
connectorId,
parentInternalId,
}: Parameters<ConnectorPermissionRetriever>[0]): Promise<
Result<ConnectorNode[], Error>
Result<ContentNode[], Error>
> {
const c = await ConnectorResource.fetchById(connectorId);
if (!c) {
Expand All @@ -241,7 +237,7 @@ export async function retrieveGithubConnectorPermissions({
if (!parentInternalId) {
// No parentInternalId: we return the repositories.

let nodes: ConnectorNode[] = [];
let nodes: ContentNode[] = [];
let pageNumber = 1; // 1-indexed
for (;;) {
const page = await getReposPage(githubInstallationId, pageNumber);
Expand Down Expand Up @@ -299,7 +295,7 @@ export async function retrieveGithubConnectorPermissions({
return a.dirName.localeCompare(b.dirName);
});

const nodes: ConnectorNode[] = [];
const nodes: ContentNode[] = [];

directories.forEach((directory) => {
nodes.push({
Expand Down Expand Up @@ -375,7 +371,7 @@ export async function retrieveGithubConnectorPermissions({
]
);

const nodes: ConnectorNode[] = [];
const nodes: ContentNode[] = [];

if (latestIssue) {
nodes.push({
Expand Down Expand Up @@ -465,7 +461,7 @@ export async function retrieveGithubReposTitles(
export async function retrieveGithubReposContentNodes(
connectorId: ModelId,
internalIds: string[]
): Promise<Result<ConnectorNode[], Error>> {
): Promise<Result<ContentNode[], Error>> {
const c = await ConnectorResource.fetchById(connectorId);
if (!c) {
logger.error({ connectorId }, "Connector not found");
Expand All @@ -474,7 +470,7 @@ export async function retrieveGithubReposContentNodes(

const githubInstallationId = c.connectionId;
const allReposIdsToFetch: Set<number> = new Set();
const nodes: ConnectorNode[] = [];
const nodes: ContentNode[] = [];

// Users can select:
// A full repo (issues + discussions + code if enabled)
Expand Down
Loading

0 comments on commit 7acfce3

Please sign in to comment.