Skip to content

Commit

Permalink
review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
tdraier committed Jan 15, 2025
1 parent b4f0a0a commit b60a0ce
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 45 deletions.
4 changes: 2 additions & 2 deletions front/admin/copy_apps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ then
# Get projects matching the current specifications
PROJECTS=$(psql $CORE_DATABASE_URI -c "copy (select distinct(project) from specifications where hash in (${IN_CLAUSE})) to stdout" | sed "s/.*/'&'/" | paste -sd, -)
# Get appIds matching the specifications
LOCAL_APP_IDS=$(psql $FRONT_DATABASE_URI -c "copy (select distinct(\"sId\") from apps where \"dustAPIProjectId\" in (${PROJECTS}) and visibility!='deleted' and \"workspaceId\"=${DUST_APPS_WORKSPACE_NUMERIC_ID} order by \"sId\") to stdout" | paste -sd\ -)
LOCAL_APP_IDS=$(psql $FRONT_DATABASE_URI -c "copy (select distinct(\"sId\") from apps where \"dustAPIProjectId\" in (${PROJECTS}) and \"deletedAt\" is null and \"workspaceId\"=${DUST_APPS_WORKSPACE_NUMERIC_ID} order by \"sId\") to stdout" | paste -sd\ -)

# Check if any app is missing
MISSING=false
Expand Down Expand Up @@ -109,7 +109,7 @@ PRODBOX_POD_NAME=$(kubectl get pods |grep prodbox|grep Running |cut -d \ -f1)

# ---- front
VAULT_ID=$(psql ${FRONT_DATABASE_URI} -c "COPY (SELECT id from vaults where \"workspaceId\"=${DUST_APPS_WORKSPACE_NUMERIC_ID} and name='Public Dust Apps') TO STDOUT")
fetch FRONT apps "id createdAt updatedAt sId name description visibility savedSpecification savedConfig savedRun dustAPIProjectId ${DUST_APPS_WORKSPACE_NUMERIC_ID} ${VAULT_ID}" "\\\"workspaceId\\\"=5069 AND \\\"vaultId\\\"=93077 and visibility='private'"
fetch FRONT apps "id createdAt updatedAt sId name description visibility savedSpecification savedConfig savedRun dustAPIProjectId ${DUST_APPS_WORKSPACE_NUMERIC_ID} ${VAULT_ID}" "\\\"workspaceId\\\"=5069 AND \\\"vaultId\\\"=93077 and \\\"deletedAt\\\" is not null"
PROJECT_IDS=$(cut -f 11 /tmp/dust-apps/FRONT_apps.csv |paste -sd "," -)

fetch FRONT datasets "id createdAt updatedAt name description schema appId ${DUST_APPS_WORKSPACE_NUMERIC_ID}" "\\\"workspaceId\\\"=5069"
Expand Down
40 changes: 27 additions & 13 deletions front/admin/init_dust_apps.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
import { isDevelopment } from "@dust-tt/types";
import _ from "lodash";
import parseArgs from "minimist";

import { Authenticator } from "@app/lib/auth";
import { Workspace } from "@app/lib/models/workspace";
import { internalSubscribeWorkspaceToFreePlan } from "@app/lib/plans/subscription";
Expand All @@ -8,14 +12,22 @@ import { UserModel } from "@app/lib/resources/storage/models/user";
import { generateRandomModelSId } from "@app/lib/resources/string_ids";
import { UserResource } from "@app/lib/resources/user_resource";
import { renderLightWorkspaceType } from "@app/lib/workspace";
import logger from "@app/logger/logger";

async function main() {
let w = await Workspace.findOne({ where: { name: "dust-apps" } });
const argv = parseArgs(process.argv.slice(2));

const where = _.pick(argv, ["name", "sId"]);
if (!where.name && !where.sId) {
where.name = "dust-apps";
}
logger.info("Creating workspace");
let w = await Workspace.findOne({ where });
if (!w) {
console.log("Creating workspace");
w = await Workspace.create({
sId: generateRandomModelSId(),
name: "dust-apps",
sId: argv.sId || generateRandomModelSId(),
name: argv.name || "dust-apps",
});

await internalSubscribeWorkspaceToFreePlan({
Expand Down Expand Up @@ -46,16 +58,18 @@ async function main() {
kind: "regular",
});

const users = await UserModel.findAll();
await Promise.all(
users.map(async (user) =>
MembershipResource.createMembership({
user: new UserResource(UserModel, user.get()),
workspace: lightWorkspace,
role: "admin",
})
)
);
if (isDevelopment()) {
const users = await UserModel.findAll();
await Promise.all(
users.map(async (user) =>
MembershipResource.createMembership({
user: new UserResource(UserModel, user.get()),
workspace: lightWorkspace,
role: "admin",
})
)
);
}

console.log("Creating space");
space = await SpaceResource.makeNew(
Expand Down
12 changes: 5 additions & 7 deletions front/components/spaces/SpaceAppsList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import * as React from "react";
import { useRef, useState } from "react";

import { SpaceCreateAppModal } from "@app/components/spaces/SpaceCreateAppModal";
import type { Action } from "@app/lib/registry";
import type { ActionApp } from "@app/lib/registry";
import { useApps, useSavedRunStatus } from "@app/lib/swr/apps";

type RowData = {
Expand Down Expand Up @@ -54,7 +54,7 @@ const getTableColumns = () => {

const getDustAppsColumns = (
owner: WorkspaceType,
registryApps: Action["app"][]
registryApps: ActionApp[]
) => ({
id: "status",
cell: (info: CellContext<RowData, string>) => {
Expand All @@ -81,7 +81,7 @@ const getDustAppsColumns = (
type AppHashCheckerProps = {
owner: LightWorkspaceType;
app: AppType;
registryApp: Action["app"];
registryApp: ActionApp;
};

const AppHashChecker = ({ owner, app, registryApp }: AppHashCheckerProps) => {
Expand Down Expand Up @@ -135,16 +135,14 @@ interface SpaceAppsListProps {
onSelect: (sId: string) => void;
owner: LightWorkspaceType;
space: SpaceType;
isDustApps: boolean;
registryApps: Action["app"][];
registryApps?: ActionApp[];
}

export const SpaceAppsList = ({
owner,
canWriteInSpace,
space,
onSelect,
isDustApps,
registryApps,
}: SpaceAppsListProps) => {
const router = useRouter();
Expand Down Expand Up @@ -183,7 +181,7 @@ export const SpaceAppsList = ({
}

const columns = getTableColumns();
if (isDustApps) {
if (registryApps) {
columns.push(getDustAppsColumns(owner, registryApps));
}

Expand Down
14 changes: 8 additions & 6 deletions front/lib/registry.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import config from "@app/lib/api/config";

export type ActionApp = {
workspaceId: string;
appId: string;
appHash: string;
appSpaceId: string;
};

export type Action = {
app: {
workspaceId: string;
appId: string;
appHash: string;
appSpaceId: string;
};
app: ActionApp;
config: { [key: string]: unknown };
};

Expand Down
6 changes: 3 additions & 3 deletions front/lib/resources/space_resource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export class SpaceResource extends BaseResource<SpaceModel> {
includeConversationsSpace: true,
});
const systemSpace =
existingSpaces.find((s) => s.kind === "system") ||
existingSpaces.find((s) => s.isSystem()) ||
(await SpaceResource.makeNew(
{
name: "System",
Expand All @@ -104,7 +104,7 @@ export class SpaceResource extends BaseResource<SpaceModel> {
));

const globalSpace =
existingSpaces.find((s) => s.kind === "global") ||
existingSpaces.find((s) => s.isGlobal()) ||
(await SpaceResource.makeNew(
{
name: "Company Data",
Expand All @@ -115,7 +115,7 @@ export class SpaceResource extends BaseResource<SpaceModel> {
));

const conversationsSpace =
existingSpaces.find((s) => s.kind === "conversations") ||
existingSpaces.find((s) => s.isConversations()) ||
(await SpaceResource.makeNew(
{
name: "Conversations",
Expand Down
9 changes: 4 additions & 5 deletions front/migrations/20240906_registry_apps_to_public_vault.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import config from "@app/lib/api/config";
import { Workspace } from "@app/lib/models/workspace";
import { DustProdActionRegistry } from "@app/lib/registry";
import { AppModel } from "@app/lib/resources/storage/models/apps";
import { getResourceIdFromSId } from "@app/lib/resources/string_ids";
import { makeScript } from "@app/scripts/helpers";
import config from "@app/lib/api/config";

const PUBLIC_VAULT_SQID = "vlt_rICtlrSEpWqX";

makeScript({}, async ({ execute }, logger) => {
const vaultId = getResourceIdFromSId(PUBLIC_VAULT_SQID);
const publicVaultSqid = config.getDustAppsSpaceId();
const vaultId = getResourceIdFromSId(publicVaultSqid);
const dustAppsWorkspace = await Workspace.findOne({
where: { sId: config.getDustAppsWorkspaceId() },
});
Expand All @@ -18,7 +17,7 @@ makeScript({}, async ({ execute }, logger) => {
);
}
if (!vaultId) {
throw new Error(`Could not find vault with SQID ${PUBLIC_VAULT_SQID}`);
throw new Error(`Could not find vault with SQID ${publicVaultSqid}`);
}

for (const [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import {
} from "@app/lib/api/data_sources";
import { isManaged } from "@app/lib/data_sources";
import { withDefaultUserAuthRequirements } from "@app/lib/iam/session";
import type { Action } from "@app/lib/registry";
import type { ActionApp } from "@app/lib/registry";
import { DustProdActionRegistry } from "@app/lib/registry";
import { SpaceResource } from "@app/lib/resources/space_resource";
export const getServerSideProps = withDefaultUserAuthRequirements<
Expand All @@ -38,8 +38,7 @@ export const getServerSideProps = withDefaultUserAuthRequirements<
space: SpaceType;
systemSpace: SpaceType;
integrations: DataSourceIntegration[];
isDustApps: boolean;
registryApps: Action["app"][];
registryApps?: ActionApp[];
}
>(async (context, auth) => {
const owner = auth.getNonNullableWorkspace();
Expand Down Expand Up @@ -122,13 +121,13 @@ export const getServerSideProps = withDefaultUserAuthRequirements<
}
}

const isDustApps =
const isDustAppsSpace =
owner.sId === config.getDustAppsWorkspaceId() &&
space.sId === config.getDustAppsSpaceId();

const registryApps = isDustApps
const registryApps = isDustAppsSpace
? Object.values(DustProdActionRegistry).map((action) => action.app)
: [];
: undefined;

return {
props: {
Expand All @@ -142,7 +141,6 @@ export const getServerSideProps = withDefaultUserAuthRequirements<
space: space.toJSON(),
systemSpace: systemSpace.toJSON(),
integrations,
isDustApps,
registryApps,
},
};
Expand All @@ -157,7 +155,6 @@ export default function Space({
space,
systemSpace,
integrations,
isDustApps,
registryApps,
}: InferGetServerSidePropsType<typeof getServerSideProps>) {
const router = useRouter();
Expand Down Expand Up @@ -195,7 +192,6 @@ export default function Space({
onSelect={(sId) => {
void router.push(`/w/${owner.sId}/spaces/${space.sId}/apps/${sId}`);
}}
isDustApps={isDustApps}
registryApps={registryApps}
/>
) : (
Expand Down

0 comments on commit b60a0ce

Please sign in to comment.