Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BigInt for the win - Wave #1 #9164

Merged
merged 5 commits into from
Dec 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions front/admin/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ import {
} from "@app/lib/models/doc_tracker";
import { FeatureFlag } from "@app/lib/models/feature_flag";
import { Plan, Subscription } from "@app/lib/models/plan";
import { User, UserMetadata } from "@app/lib/models/user";
import {
DustAppSecret,
MembershipInvitation,
Expand Down Expand Up @@ -85,15 +84,19 @@ import {
} from "@app/lib/resources/storage/models/runs";
import { SpaceModel } from "@app/lib/resources/storage/models/spaces";
import { TemplateModel } from "@app/lib/resources/storage/models/templates";
import {
UserMetadataModel,
UserModel,
} from "@app/lib/resources/storage/models/user";
import logger from "@app/logger/logger";

async function main() {
await sendInitDbMessage({
service: "front",
logger: logger,
});
await User.sync({ alter: true });
await UserMetadata.sync({ alter: true });
await UserModel.sync({ alter: true });
await UserMetadataModel.sync({ alter: true });
await Workspace.sync({ alter: true });
await WorkspaceHasDomain.sync({ alter: true });
await MembershipModel.sync({ alter: true });
Expand Down
7 changes: 3 additions & 4 deletions front/admin/init_dust_apps.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Authenticator } from "@app/lib/auth";
import { FeatureFlag } from "@app/lib/models/feature_flag";
import { User } from "@app/lib/models/user";
import { Workspace } from "@app/lib/models/workspace";
import { internalSubscribeWorkspaceToFreePlan } from "@app/lib/plans/subscription";
import { GroupResource } from "@app/lib/resources/group_resource";
import { MembershipResource } from "@app/lib/resources/membership_resource";
import { SpaceResource } from "@app/lib/resources/space_resource";
import { UserModel } from "@app/lib/resources/storage/models/user";
import { UserResource } from "@app/lib/resources/user_resource";
import { renderLightWorkspaceType } from "@app/lib/workspace";

Expand Down Expand Up @@ -51,11 +50,11 @@ async function main() {
planCode: "FREE_UPGRADED_PLAN",
});

const users = await User.findAll();
const users = await UserModel.findAll();
await Promise.all(
users.map(async (user) =>
MembershipResource.createMembership({
user: new UserResource(User, user.get()),
user: new UserResource(UserModel, user.get()),
workspace: lightWorkspace,
role: "admin",
})
Expand Down
1 change: 1 addition & 0 deletions front/lib/api/assistant/conversation/destroy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ async function destroyMessageRelatedResources(messageIds: Array<ModelId>) {
await Mention.destroy({
where: { messageId: messageIds },
});
// TODO: We should also destroy the parent message
await Message.destroy({
where: { id: messageIds },
});
Expand Down
6 changes: 3 additions & 3 deletions front/lib/api/assistant/email_trigger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,17 @@ import { postUserMessageWithPubSub } from "@app/lib/api/assistant/pubsub";
import { sendEmail } from "@app/lib/api/email";
import { processAndStoreFile } from "@app/lib/api/files/upload";
import type { Authenticator } from "@app/lib/auth";
import { User } from "@app/lib/models/user";
import { Workspace } from "@app/lib/models/workspace";
import { FileResource } from "@app/lib/resources/file_resource";
import { MembershipModel } from "@app/lib/resources/storage/models/membership";
import { UserModel } from "@app/lib/resources/storage/models/user";
import { filterAndSortAgents } from "@app/lib/utils";
import { renderLightWorkspaceType } from "@app/lib/workspace";
import logger from "@app/logger/logger";

const { PRODUCTION_DUST_WORKSPACE_ID } = process.env;

function renderUserType(user: User): UserType {
function renderUserType(user: UserModel): UserType {
return {
sId: user.sId,
id: user.id,
Expand Down Expand Up @@ -106,7 +106,7 @@ export async function userAndWorkspacesFromEmail({
EmailTriggerError
>
> {
const user = await User.findOne({
const user = await UserModel.findOne({
where: { email },
});

Expand Down
6 changes: 3 additions & 3 deletions front/lib/api/assistant/participants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,21 @@ import {
Message,
UserMessage,
} from "@app/lib/models/assistant/conversation";
import { User } from "@app/lib/models/user";
import { UserModel } from "@app/lib/resources/storage/models/user";

async function fetchAllUsersById(
userIds: ModelId[]
): Promise<UserParticipantType[]> {
const users = (
await User.findAll({
await UserModel.findAll({
attributes: ["firstName", "lastName", "imageUrl", "username"],
where: {
id: {
[Op.in]: userIds,
},
},
})
).filter((u) => u !== null) as User[];
).filter((u) => u !== null) as UserModel[];

return users.map((u) => ({
fullName: formatUserFullName(u),
Expand Down
8 changes: 4 additions & 4 deletions front/lib/api/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import type {
import { Err, Ok } from "@dust-tt/types";

import type { Authenticator } from "@app/lib/auth";
import { UserMetadata } from "@app/lib/models/user";
import { Workspace } from "@app/lib/models/workspace";
import { UserMetadataModel } from "@app/lib/resources/storage/models/user";
import { UserResource } from "@app/lib/resources/user_resource";
import logger from "@app/logger/logger";

Expand Down Expand Up @@ -57,7 +57,7 @@ export async function getUserMetadata(
user: UserType,
key: string
): Promise<UserMetadataType | null> {
const metadata = await UserMetadata.findOne({
const metadata = await UserMetadataModel.findOne({
where: {
userId: user.id,
key,
Expand All @@ -84,15 +84,15 @@ export async function setUserMetadata(
user: UserType,
update: UserMetadataType
): Promise<void> {
const metadata = await UserMetadata.findOne({
const metadata = await UserMetadataModel.findOne({
where: {
userId: user.id,
key: update.key,
},
});

if (!metadata) {
await UserMetadata.create({
await UserMetadataModel.create({
userId: user.id,
key: update.key,
value: update.value,
Expand Down
6 changes: 3 additions & 3 deletions front/lib/document_tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { literal, Op } from "sequelize";

import type { Authenticator } from "@app/lib/auth";
import { TrackedDocument } from "@app/lib/models/doc_tracker";
import { User } from "@app/lib/models/user";
import { Workspace } from "@app/lib/models/workspace";
import { DataSourceResource } from "@app/lib/resources/data_source_resource";
import { MembershipResource } from "@app/lib/resources/membership_resource";
import { UserModel } from "@app/lib/resources/storage/models/user";
import logger from "@app/logger/logger";

import config from "./api/config";
Expand Down Expand Up @@ -91,7 +91,7 @@ export async function updateTrackedDocuments(
// find users with matching emails
const emails = Array.from(allEmails);
let users = emails.length
? await User.findAll({
? await UserModel.findAll({
where: literal(`lower(email) IN (:emails)`),
replacements: {
emails,
Expand All @@ -108,7 +108,7 @@ export async function updateTrackedDocuments(
);
users = users.filter((user) => userIdsInWorkspace.has(user.id));

const userByEmail: Map<string, User> = new Map();
const userByEmail: Map<string, UserModel> = new Map();
for (const user of users) {
userByEmail.set(user.email.toLowerCase(), user);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import {
DocumentTrackerChangeSuggestion,
TrackedDocument,
} from "@app/lib/models/doc_tracker";
import { User } from "@app/lib/models/user";
import { DataSourceResource } from "@app/lib/resources/data_source_resource";
import { UserModel } from "@app/lib/resources/storage/models/user";
import mainLogger from "@app/logger/logger";

import { callDocTrackerRetrievalAction } from "./actions/doc_tracker_retrieval";
Expand Down Expand Up @@ -410,7 +410,7 @@ export async function documentTrackerSuggestChangesOnUpsert({
)
);

const users = await User.findAll({
const users = await UserModel.findAll({
where: {
id: {
[Op.in]: trackedDocuments.map((td) => td.userId),
Expand Down
4 changes: 2 additions & 2 deletions front/lib/iam/users.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { UserProviderType } from "@dust-tt/types";
import { sanitizeString } from "@dust-tt/types";

import type { ExternalUser, SessionWithUser } from "@app/lib/iam/provider";
import { User } from "@app/lib/models/user";
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 { ServerSideTracking } from "@app/lib/tracking/server";
Expand Down Expand Up @@ -74,7 +74,7 @@ export async function maybeUpdateFromExternalUser(
externalUser: ExternalUser
) {
if (externalUser.picture && externalUser.picture !== user.imageUrl) {
void User.update(
void UserModel.update(
{
imageUrl: externalUser.picture,
},
Expand Down
32 changes: 5 additions & 27 deletions front/lib/models/assistant/actions/browse.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,13 @@
import type { BrowseActionOutputType } from "@dust-tt/types";
import type {
CreationOptional,
ForeignKey,
InferAttributes,
InferCreationAttributes,
} from "sequelize";
import { DataTypes, Model } from "sequelize";
import type { CreationOptional, ForeignKey } from "sequelize";
import { DataTypes } from "sequelize";

import { AgentConfiguration } from "@app/lib/models/assistant/agent";
import { AgentMessage } from "@app/lib/models/assistant/conversation";
import { frontSequelize } from "@app/lib/resources/storage";
import { BaseModel } from "@app/lib/resources/storage/wrappers";

export class AgentBrowseConfiguration extends Model<
InferAttributes<AgentBrowseConfiguration>,
InferCreationAttributes<AgentBrowseConfiguration>
> {
declare id: CreationOptional<number>;
export class AgentBrowseConfiguration extends BaseModel<AgentBrowseConfiguration> {
declare createdAt: CreationOptional<Date>;
declare updatedAt: CreationOptional<Date>;

Expand All @@ -29,11 +21,6 @@ export class AgentBrowseConfiguration extends Model<

AgentBrowseConfiguration.init(
{
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
},
createdAt: {
type: DataTypes.DATE,
allowNull: false,
Expand Down Expand Up @@ -80,11 +67,7 @@ AgentBrowseConfiguration.belongsTo(AgentConfiguration, {
foreignKey: { name: "agentConfigurationId", allowNull: false },
});

export class AgentBrowseAction extends Model<
InferAttributes<AgentBrowseAction>,
InferCreationAttributes<AgentBrowseAction>
> {
declare id: CreationOptional<number>;
export class AgentBrowseAction extends BaseModel<AgentBrowseAction> {
declare createdAt: CreationOptional<Date>;
declare updatedAt: CreationOptional<Date>;
declare runId: string | null;
Expand All @@ -102,11 +85,6 @@ export class AgentBrowseAction extends Model<
}
AgentBrowseAction.init(
{
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
},
createdAt: {
type: DataTypes.DATE,
allowNull: false,
Expand Down
21 changes: 4 additions & 17 deletions front/lib/models/assistant/actions/conversation/include_file.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,14 @@
import type {
CreationOptional,
ForeignKey,
InferAttributes,
InferCreationAttributes,
} from "sequelize";
import { DataTypes, Model } from "sequelize";
import type { CreationOptional, ForeignKey } from "sequelize";
import { DataTypes } from "sequelize";

import { AgentMessage } from "@app/lib/models/assistant/conversation";
import { frontSequelize } from "@app/lib/resources/storage";
import { BaseModel } from "@app/lib/resources/storage/wrappers";

/**
* ConversationIncludeFile Action
*/
export class AgentConversationIncludeFileAction extends Model<
InferAttributes<AgentConversationIncludeFileAction>,
InferCreationAttributes<AgentConversationIncludeFileAction>
> {
declare id: CreationOptional<number>;
export class AgentConversationIncludeFileAction extends BaseModel<AgentConversationIncludeFileAction> {
declare createdAt: CreationOptional<Date>;
declare updatedAt: CreationOptional<Date>;

Expand All @@ -31,11 +23,6 @@ export class AgentConversationIncludeFileAction extends Model<
}
AgentConversationIncludeFileAction.init(
{
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
},
createdAt: {
type: DataTypes.DATE,
allowNull: false,
Expand Down
22 changes: 4 additions & 18 deletions front/lib/models/assistant/actions/data_sources.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
import type {
CreationOptional,
ForeignKey,
InferAttributes,
InferCreationAttributes,
NonAttribute,
} from "sequelize";
import { DataTypes, Model } from "sequelize";
import type { CreationOptional, ForeignKey, NonAttribute } from "sequelize";
import { DataTypes } from "sequelize";

import { AgentProcessConfiguration } from "@app/lib/models/assistant/actions/process";
import { AgentRetrievalConfiguration } from "@app/lib/models/assistant/actions/retrieval";
import { frontSequelize } from "@app/lib/resources/storage";
import { DataSourceModel } from "@app/lib/resources/storage/models/data_source";
import { DataSourceViewModel } from "@app/lib/resources/storage/models/data_source_view";
import { BaseModel } from "@app/lib/resources/storage/wrappers";

/**
* Configuration of Datasources used for Retrieval Action.
*/
export class AgentDataSourceConfiguration extends Model<
InferAttributes<AgentDataSourceConfiguration>,
InferCreationAttributes<AgentDataSourceConfiguration>
> {
declare id: CreationOptional<number>;
export class AgentDataSourceConfiguration extends BaseModel<AgentDataSourceConfiguration> {
declare createdAt: CreationOptional<Date>;
declare updatedAt: CreationOptional<Date>;

Expand All @@ -44,11 +35,6 @@ export class AgentDataSourceConfiguration extends Model<
}
AgentDataSourceConfiguration.init(
{
id: {
type: DataTypes.INTEGER,
autoIncrement: true,
primaryKey: true,
},
createdAt: {
type: DataTypes.DATE,
allowNull: false,
Expand Down
Loading
Loading