Skip to content

Commit

Permalink
Merge branch 'main' into Sparkle27
Browse files Browse the repository at this point in the history
  • Loading branch information
Duncid authored Oct 12, 2023
2 parents 6c84521 + 289a803 commit ce636a7
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 5 deletions.
13 changes: 10 additions & 3 deletions front/components/assistant/conversation/DustAppRunAction.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,16 @@ export default function DustAppRunAction({
<div className="grid-cols-auto grid items-center">
{!dustAppRunAction.output ? (
<div>
<div className="pb-2 text-xs font-bold text-element-600">
Executing {dustAppRunAction.appName}...
</div>
{dustAppRunAction.runningBlock ? (
<div className="pb-2 text-xs font-bold text-element-600">
Executing app {dustAppRunAction.appName}: running block{" "}
{dustAppRunAction.runningBlock.name}...
</div>
) : (
<div className="pb-2 text-xs font-bold text-element-600">
Executing app {dustAppRunAction.appName}...
</div>
)}
<Spinner size="sm" />
</div>
) : (
Expand Down
5 changes: 4 additions & 1 deletion front/lib/api/assistant/actions/dust_app_run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,14 +400,17 @@ export async function* runDustApp(
useLocalInDev: true,
});

// As we run the app (using a system API key here), we do force using the workspace credentials so
// that the app executes in the exact same conditions in which they were developed.
const runRes = await api.runAppStreamed(
{
workspaceId: c.appWorkspaceId,
appId: c.appId,
appHash: "latest",
},
appConfig,
[params]
[params],
{ useWorkspaceCredentials: true }
);

if (runRes.isErr()) {
Expand Down
10 changes: 10 additions & 0 deletions front/lib/models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ export class User extends Model<
declare username: string;
declare email: string;
declare name: string;
declare firstName: string | null;
declare lastName: string | null;

declare isDustSuperUser: CreationOptional<boolean>;
}
Expand Down Expand Up @@ -61,6 +63,14 @@ User.init(
type: DataTypes.STRING,
allowNull: false,
},
firstName: {
type: DataTypes.STRING,
allowNull: true,
},
lastName: {
type: DataTypes.STRING,
allowNull: true,
},
isDustSuperUser: {
type: DataTypes.BOOLEAN,
defaultValue: false,
Expand Down
15 changes: 15 additions & 0 deletions front/lib/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,3 +58,18 @@ export function setUserMetadataFromClient(metadata: UserMetadataType) {
}
})();
}

export const guessFirstandLastNameFromFullName = (
fullName: string
): { firstName: string | null; lastName: string | null } => {
if (!fullName) return { firstName: null, lastName: null };

const nameParts = fullName.split(" ");

if (nameParts.length === 1) return { firstName: fullName, lastName: null };

const firstName = nameParts.shift() || null;
const lastName = nameParts.join(" ");

return { firstName, lastName };
};
16 changes: 16 additions & 0 deletions front/pages/api/login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
User,
Workspace,
} from "@app/lib/models";
import { guessFirstandLastNameFromFullName } from "@app/lib/user";
import { generateModelSId } from "@app/lib/utils";
import { apiError, withLogging } from "@app/logger/withlogging";

Expand Down Expand Up @@ -129,18 +130,33 @@ async function handler(
user.username = session.user.username;
user.email = session.user.email;
user.name = session.user.name;

if (!user.firstName && !user.lastName) {
const { firstName, lastName } = guessFirstandLastNameFromFullName(
session.user.name
);
user.firstName = firstName;
user.lastName = lastName;
}

await user.save();
}

// The user does not exist. We create it and create a personal workspace if there is no invite
// associated with the login request.
if (!user) {
const { firstName, lastName } = guessFirstandLastNameFromFullName(
session.user.name
);

user = await User.create({
provider: session.provider.provider,
providerId: session.provider.id.toString(),
username: session.user.username,
email: session.user.email,
name: session.user.name,
firstName,
lastName,
});

// If there is no invte, we create a personal workspace for the user, otherwise the user
Expand Down
2 changes: 1 addition & 1 deletion front/pages/api/v1/w/[wId]/apps/[aId]/runs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ async function handler(

// This variable is used in the context of the DustAppRun action to use the workspace credentials
// instead of our managed credentials when running an app with a system API key.
const useWorkspaceCredentials = !!req.query.useWorkspaceCredentials;
const useWorkspaceCredentials = !!req.query["use_workspace_credentials"];

switch (req.method) {
case "POST":
Expand Down

0 comments on commit ce636a7

Please sign in to comment.