Skip to content

Commit

Permalink
chore(server): gendo IoC #1 - prep/cleanup before getting started
Browse files Browse the repository at this point in the history
  • Loading branch information
fabis94 committed Oct 24, 2024
1 parent 30fc2a5 commit 6d53308
Show file tree
Hide file tree
Showing 11 changed files with 58 additions and 49 deletions.
2 changes: 1 addition & 1 deletion packages/frontend-2/components/viewer/gendo/Panel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ const lodgeRequest = async (screenshot: string) => {
const err = getFirstErrorMessage(res.errors)
triggerNotification({
type: ToastNotificationType.Danger,
title: 'Failed to enque Gendo render',
title: 'Failed to enqueue Gendo render',
description: err
})
} else {
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend-2/lib/common/generated/gql/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ export type FileUpload = {
export type GendoAiRender = {
__typename?: 'GendoAIRender';
camera?: Maybe<Scalars['JSONObject']['output']>;
createdAt: Scalars['String']['output'];
createdAt: Scalars['DateTime']['output'];
gendoGenerationId?: Maybe<Scalars['String']['output']>;
id: Scalars['ID']['output'];
modelId: Scalars['String']['output'];
Expand All @@ -904,7 +904,7 @@ export type GendoAiRender = {
/** This is a blob id. */
responseImage?: Maybe<Scalars['String']['output']>;
status: Scalars['String']['output'];
updatedAt: Scalars['String']['output'];
updatedAt: Scalars['DateTime']['output'];
user?: Maybe<AvatarUser>;
userId: Scalars['String']['output'];
versionId: Scalars['String']['output'];
Expand Down
2 changes: 2 additions & 0 deletions packages/frontend-2/lib/gendo/graphql/queriesAndMutations.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { graphql } from '~~/lib/common/generated/gql'

// TODO: Clean up these operations and make them component fragment based. Also some of the props requested don't seem to even be used

export const requestGendoAIRender = graphql(`
mutation requestGendoAIRender($input: GendoAIRenderInput!) {
versionMutations {
Expand Down
4 changes: 2 additions & 2 deletions packages/server/assets/gendo/typedefs/gendo.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ type GendoAIRender {
versionId: String!
userId: String!
user: AvatarUser
createdAt: String!
updatedAt: String!
createdAt: DateTime!
updatedAt: DateTime!
gendoGenerationId: String
status: String!
prompt: String!
Expand Down
8 changes: 4 additions & 4 deletions packages/server/modules/core/graph/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -914,7 +914,7 @@ export type FileUpload = {
export type GendoAiRender = {
__typename?: 'GendoAIRender';
camera?: Maybe<Scalars['JSONObject']['output']>;
createdAt: Scalars['String']['output'];
createdAt: Scalars['DateTime']['output'];
gendoGenerationId?: Maybe<Scalars['String']['output']>;
id: Scalars['ID']['output'];
modelId: Scalars['String']['output'];
Expand All @@ -923,7 +923,7 @@ export type GendoAiRender = {
/** This is a blob id. */
responseImage?: Maybe<Scalars['String']['output']>;
status: Scalars['String']['output'];
updatedAt: Scalars['String']['output'];
updatedAt: Scalars['DateTime']['output'];
user?: Maybe<AvatarUser>;
userId: Scalars['String']['output'];
versionId: Scalars['String']['output'];
Expand Down Expand Up @@ -5254,15 +5254,15 @@ export type FileUploadResolvers<ContextType = GraphQLContext, ParentType extends

export type GendoAiRenderResolvers<ContextType = GraphQLContext, ParentType extends ResolversParentTypes['GendoAIRender'] = ResolversParentTypes['GendoAIRender']> = {
camera?: Resolver<Maybe<ResolversTypes['JSONObject']>, ParentType, ContextType>;
createdAt?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
createdAt?: Resolver<ResolversTypes['DateTime'], ParentType, ContextType>;
gendoGenerationId?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
id?: Resolver<ResolversTypes['ID'], ParentType, ContextType>;
modelId?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
projectId?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
prompt?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
responseImage?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
status?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
updatedAt?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
updatedAt?: Resolver<ResolversTypes['DateTime'], ParentType, ContextType>;
user?: Resolver<Maybe<ResolversTypes['AvatarUser']>, ParentType, ContextType>;
userId?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
versionId?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -898,7 +898,7 @@ export type FileUpload = {
export type GendoAiRender = {
__typename?: 'GendoAIRender';
camera?: Maybe<Scalars['JSONObject']['output']>;
createdAt: Scalars['String']['output'];
createdAt: Scalars['DateTime']['output'];
gendoGenerationId?: Maybe<Scalars['String']['output']>;
id: Scalars['ID']['output'];
modelId: Scalars['String']['output'];
Expand All @@ -907,7 +907,7 @@ export type GendoAiRender = {
/** This is a blob id. */
responseImage?: Maybe<Scalars['String']['output']>;
status: Scalars['String']['output'];
updatedAt: Scalars['String']['output'];
updatedAt: Scalars['DateTime']['output'];
user?: Maybe<AvatarUser>;
userId: Scalars['String']['output'];
versionId: Scalars['String']['output'];
Expand Down
9 changes: 5 additions & 4 deletions packages/server/modules/gendo/graph/resolvers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
ProjectSubscriptions,
filteredSubscribe
} from '@/modules/shared/utils/subscriptions'
import { GendoAiRender } from '@/test/graphql/generated/graphql'
import {
getRateLimitResult,
isRateLimitBreached
Expand All @@ -39,7 +38,7 @@ export = {
...item,
user: { name: item.userName, avatar: item.userAvatar, id: item.userId }
}
return response as GendoAiRender
return response
}
},
VersionMutations: {
Expand Down Expand Up @@ -92,8 +91,10 @@ export = {
id: crs({ length: 10 })
})
} else {
const body = await response.json().catch(() => '')
throw new GendoRenderRequestError('Failed to enque gendo render. ' + body)
const body = await response.json().catch((e) => ({ error: `${e}` }))
throw new GendoRenderRequestError('Failed to enqueue gendo render.', {
info: { body }
})
}
return true
}
Expand Down
10 changes: 6 additions & 4 deletions packages/server/modules/gendo/helpers/types/index.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { Nullable } from '@speckle/shared'

export type GendoAIRenderRecord = {
id: string
userId: string
projectId: string
modelId: string
versionId: string
createdAt: string
updatedAt: string
gendoGenerationId: string
createdAt: Date
updatedAt: Date
gendoGenerationId: Nullable<string>
status: string
prompt: string
camera: Record<string, unknown>
/** References a blobId, weakly */
baseImage: string
/** References a blobId, weakly */
responseImage: string
responseImage: Nullable<string>
}
32 changes: 4 additions & 28 deletions packages/server/modules/gendo/index.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import { SpeckleModule } from '@/modules/shared/helpers/typeHelper'
import { moduleLogger } from '@/logging/logging'
import { corsMiddleware } from '@/modules/core/configs/cors'
import {
getGendoAIResponseKey,
getFeatureFlags
} from '@/modules/shared/helpers/envHelper'
import { updateGendoAIRenderRequest } from '@/modules/gendo/services'
import { getFeatureFlags } from '@/modules/shared/helpers/envHelper'
import restApi from '@/modules/gendo/rest/index'

const { FF_GENDOAI_MODULE_ENABLED } = getFeatureFlags()

Expand All @@ -14,26 +10,6 @@ export = {
if (!FF_GENDOAI_MODULE_ENABLED) return
moduleLogger.info('🪞 Init Gendo AI render module')

const responseToken = getGendoAIResponseKey()
// Gendo api calls back in here with the result.
app.options('/api/thirdparty/gendo', corsMiddleware())
app.post('/api/thirdparty/gendo', corsMiddleware(), async (req, res) => {
if (req.headers['x-gendo-authorization'] !== responseToken) {
return res.status(401).send('Speckle says you are not authorized 😠')
}

const responseImage = req.body.generated_image
const status = req.body.status
const gendoGenerationId = req.body.generationId

await updateGendoAIRenderRequest({
gendoGenerationId,
status,
responseImage
})

res.status(200).send('Speckle says thank you 💖')
})
},
async shutdown() {}
restApi(app)
}
} as SpeckleModule
28 changes: 28 additions & 0 deletions packages/server/modules/gendo/rest/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { corsMiddleware } from '@/modules/core/configs/cors'
import { getGendoAIResponseKey } from '@/modules/shared/helpers/envHelper'
import { updateGendoAIRenderRequest } from '@/modules/gendo/services'
import type express from 'express'

export default function (app: express.Express) {
const responseToken = getGendoAIResponseKey()

// Gendo api calls hit these endpoints w/ the results
app.options('/api/thirdparty/gendo', corsMiddleware())
app.post('/api/thirdparty/gendo', corsMiddleware(), async (req, res) => {
if (req.headers['x-gendo-authorization'] !== responseToken) {
return res.status(401).send('Speckle says you are not authorized 😠')
}

const responseImage = req.body.generated_image
const status = req.body.status
const gendoGenerationId = req.body.generationId

await updateGendoAIRenderRequest({
gendoGenerationId,
status,
responseImage
})

res.status(200).send('Speckle says thank you 💖')
})
}
4 changes: 2 additions & 2 deletions packages/server/test/graphql/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ export type FileUpload = {
export type GendoAiRender = {
__typename?: 'GendoAIRender';
camera?: Maybe<Scalars['JSONObject']['output']>;
createdAt: Scalars['String']['output'];
createdAt: Scalars['DateTime']['output'];
gendoGenerationId?: Maybe<Scalars['String']['output']>;
id: Scalars['ID']['output'];
modelId: Scalars['String']['output'];
Expand All @@ -908,7 +908,7 @@ export type GendoAiRender = {
/** This is a blob id. */
responseImage?: Maybe<Scalars['String']['output']>;
status: Scalars['String']['output'];
updatedAt: Scalars['String']['output'];
updatedAt: Scalars['DateTime']['output'];
user?: Maybe<AvatarUser>;
userId: Scalars['String']['output'];
versionId: Scalars['String']['output'];
Expand Down

0 comments on commit 6d53308

Please sign in to comment.