Skip to content

Commit

Permalink
Merge pull request #46 from meta-d/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
meta-d authored Aug 16, 2024
2 parents 3c13fd2 + 3a1d754 commit de934fb
Show file tree
Hide file tree
Showing 159 changed files with 26,299 additions and 26,925 deletions.
10 changes: 6 additions & 4 deletions .deploy/api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ WORKDIR /srv/pangolin

COPY --chown=node:node packages/store/package.json ./packages/store/
COPY --chown=node:node packages/core/package.json ./packages/core/
COPY --chown=node:node packages/copilot/package.json ./packages/copilot/
COPY --chown=node:node packages/contracts/package.json ./packages/contracts/
COPY --chown=node:node packages/common/package.json ./packages/common/
COPY --chown=node:node packages/config/package.json ./packages/config/
Expand All @@ -36,8 +37,9 @@ COPY --chown=node:node packages/adapter/package.json ./packages/adapter/
COPY --chown=node:node packages/analytics/package.json ./packages/analytics/

COPY --chown=node:node .deploy/api/package.json ./
COPY --chown=node:node ./package-lock.json ./

RUN yarn install && yarn cache clean
RUN npm install --legacy-peer-deps

COPY --chown=node:node nx.json ./
COPY --chown=node:node tsconfig.base.json ./
Expand Down Expand Up @@ -73,11 +75,11 @@ RUN npm install pm2 -g
COPY --chown=node:node --from=build /srv/pangolin/dist/packages ./packages
COPY --chown=node:node --from=build /srv/pangolin/dist/apps/api .
COPY --chown=node:node --from=build /srv/pangolin/tsconfig.base.json ./
COPY --chown=node:node --from=build /srv/pangolin/yarn.lock .
COPY --chown=node:node --from=build /srv/pangolin/package-lock.json .
COPY --chown=node:node .deploy/api/package-prod.json ./package.json

RUN yarn config set network-timeout 300000
RUN yarn install --frozen-lockfile && yarn cache clean && \
# RUN yarn config set network-timeout 300000
RUN npm install --legacy-peer-deps && \
touch ormlogs.log && chown -R node:node /srv/pangolin

USER node:node
Expand Down
7 changes: 7 additions & 0 deletions .deploy/api/package-prod.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@
},
"private": true,
"dependencies": {
"@langchain/community": "0.2.20",
"@langchain/core": "0.2.18",
"@langchain/langgraph": "0.0.31",
"@langchain/ollama": "^0.0.2",
"@langchain/openai": "0.2.4",
"@nestjs/common": "^8.0.0",
"@nestjs/core": "^8.0.0",
"@nestjs/platform-express": "^8.0.0",
"@swc/helpers": "~0.5.0",
"idb-keyval": "^6.0.2",
"immer": "^10.0.1",
"langchain": "0.2.10",
"money-clip": "^3.0.5",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.0.0",
Expand Down
10 changes: 9 additions & 1 deletion .deploy/api/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ocap-server",
"author": "Metad",
"version": "2.5.2",
"version": "2.5.4",
"scripts": {
"start": "nx serve",
"build": "nx build",
Expand All @@ -10,11 +10,18 @@
},
"private": true,
"dependencies": {
"@langchain/community": "0.2.20",
"@langchain/core": "0.2.18",
"@langchain/langgraph": "0.0.31",
"@langchain/ollama": "^0.0.2",
"@langchain/openai": "0.2.4",
"@nestjs/common": "^8.0.0",
"@nestjs/core": "^8.0.0",
"@nestjs/platform-express": "^8.0.0",
"@swc/helpers": "~0.5.0",
"idb-keyval": "^6.0.2",
"immer": "^10.0.1",
"langchain": "0.2.10",
"money-clip": "^3.0.5",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.0.0",
Expand Down Expand Up @@ -42,6 +49,7 @@
"eslint-config-prettier": "8.1.0",
"jest": "29.4.3",
"nx": "17.1.2",
"rimraf": "^5.0.5",
"ts-jest": "29.1.1",
"ts-node": "10.9.1",
"typescript": "5.2.2"
Expand Down
14 changes: 10 additions & 4 deletions .env.compose
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,16 @@ FACEBOOK_CLIENT_SECRET=XXXXXXX
FACEBOOK_CALLBACK_URL=http://localhost:3000/api/auth/facebook/callback
FACEBOOK_GRAPH_VERSION=v3.0

FEISHU_CLIENT_ID=<Feishu Client ID>
FEISHU_CLIENT_SECRET=<Feishu Client Secret>
FEISHU_REDIRECT_URL=http://localhost:3000/api/auth/feishu/callback
FEISHU_APP_TYPE=internal # public 类型的 App 就得提供 appTicket
LARK_APP_ID=
LARK_APP_SECRET=
LARK_VERIFICATION_TOKEN=
LARK_ENCRYPT_KEY=
LARK_APP_OPEN_ID=
LARK_TENANT_ID=
LARK_ORGANIZATION_ID=
LARK_REDIRECT_URL=http://localhost:3000/api/auth/feishu/callback
LARK_APP_TYPE=internal # public 类型的 App 就得提供 appTicket
LARK_ROLE_NAME=VIEWER

GITHUB_CLIENT_ID=<GitHub Client ID>
GITHUB_CLIENT_SECRET=<GitHub Client Secret>
Expand Down
14 changes: 10 additions & 4 deletions .env.local
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,16 @@ FACEBOOK_CLIENT_SECRET=XXXXXXX
FACEBOOK_CALLBACK_URL=http://localhost:3000/api/auth/facebook/callback
FACEBOOK_GRAPH_VERSION=v3.0

FEISHU_CLIENT_ID=<Feishu Client ID>
FEISHU_CLIENT_SECRET=<Feishu Client Secret>
FEISHU_REDIRECT_URL=http://localhost:3000/api/auth/feishu/callback
FEISHU_APP_TYPE=internal # public 类型的 App 就得提供 appTicket
LARK_APP_ID=
LARK_APP_SECRET=
LARK_VERIFICATION_TOKEN=
LARK_ENCRYPT_KEY=
LARK_APP_OPEN_ID=
LARK_TENANT_ID=
LARK_ORGANIZATION_ID=
LARK_REDIRECT_URL=http://localhost:3000/api/auth/feishu/callback
LARK_APP_TYPE=internal # public 类型的 App 就得提供 appTicket
LARK_ROLE_NAME=VIEWER

GITHUB_CLIENT_ID=<GitHub Client ID>
GITHUB_CLIENT_SECRET=<GitHub Client Secret>
Expand Down
27 changes: 20 additions & 7 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Attach NestJS",
"port": 9229,
"request": "attach",
"skipFiles": [
"<node_internals>/**"
],
"type": "node"
},
{
"type": "node",
"request": "attach",
Expand All @@ -12,16 +21,20 @@
"restart": true,
"port": 9229
},

{
"name": "Debug NestJS",
"type": "node",
"request": "launch",
"name": "Debug Nest Framework",
"args": ["${workspaceFolder}/apps/api/src/main.ts"],
"runtimeArgs": ["--nolazy", "-r", "ts-node/register", "-project", "${workspaceFolder}/apps/api/tsconfig.app.json"],
"sourceMaps": true,
"cwd": "${workspaceRoot}",
"protocol": "inspector"
"runtimeExecutable": "nodemon",
"program": "${workspaceFolder}/apps/api/src/main.ts",
"restart": true,
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"env": {
"TS_NODE_PROJECT": "apps/api/tsconfig.app.json"
},
"skipFiles": ["<node_internals>/**"],
"sourceMaps": true
}
]
}
133 changes: 69 additions & 64 deletions apps/api/src/main.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Logger, LogLevel } from '@nestjs/common'
import { NestFactory, Reflector } from '@nestjs/core'
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger'
import { AnalyticsModule, AnalyticsService, prepare, seedModule } from '@metad/analytics'
import { AuthGuard, seedDefault, ServerAppModule, AppService } from '@metad/server-core'
import { AnalyticsModule, AnalyticsService, bootstrap, prepare, seedModule } from '@metad/analytics'
import { AuthGuard, seedDefault, ServerAppModule, AppService, IntegrationLarkModule, LarkService } from '@metad/server-core'
import { getConfig, setConfig, environment as env } from '@metad/server-config'
import { json, urlencoded, text } from 'express'
import * as expressSession from 'express-session';
Expand All @@ -15,68 +15,73 @@ const LoggerIndex = LOGGER_LEVELS.findIndex((value) => value === (process.env.LO

prepare()

async function bootstrap() {
const app = await NestFactory.create(AppModule, {
logger: LOGGER_LEVELS.slice(0, LoggerIndex + 1)
})

// This will lockdown all routes and make them accessible by authenticated users only.
const reflector = app.get(Reflector)
app.useGlobalGuards(new AuthGuard(reflector))

app.use(text({
limit: '50mb',
type: 'text/xml',
}))
app.use(json({ limit: '50mb' }))
app.use(urlencoded({ extended: true, limit: '50mb' }))

const headersForOpenAI = 'x-stainless-os, x-stainless-lang, x-stainless-package-version, x-stainless-runtime, x-stainless-arch, x-stainless-runtime-version'
app.enableCors({
origin: '*',
methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
credentials: true,
allowedHeaders:
'Authorization, Language, Tenant-Id, Organization-Id, X-Requested-With, X-Auth-Token, X-HTTP-Method-Override, Content-Type, Content-Language, Accept, Accept-Language, Observe, ' + headersForOpenAI
})

// Sessions
app.use(
// this runs in memory, so we lose sessions on restart of server/pod
expressSession({
secret: env.EXPRESS_SESSION_SECRET,
resave: true, // we use this because Memory store does not support 'touch' method
saveUninitialized: true,
cookie: { secure: env.production } // TODO
})
)

const globalPrefix = 'api'
app.setGlobalPrefix(globalPrefix)

// Seed default values
const serverService = app.select(ServerAppModule).get(AppService)
await serverService.seedDBIfEmpty()
const analyticsService = app.select(AnalyticsModule).get(AnalyticsService)
await analyticsService.seedDBIfEmpty()

// const subscriptionService = app.select(ServerAppModule).get(SubscriptionService)
// subscriptionService.setupJobs()

// Setup Swagger Module
const options = new DocumentBuilder().setTitle('Metad Cloud API').setVersion('1.0').addBearerAuth().build()

const document = SwaggerModule.createDocument(app, options)
SwaggerModule.setup('swg', app, document)

app.enableShutdownHooks();

// Listen App
const port = process.env.PORT || 3000
await app.listen(port, '0.0.0.0', () => {
Logger.log('Listening at http://localhost:' + port + '/' + globalPrefix)
})
}
// async function bootstrap() {
// const app = await NestFactory.create(AppModule, {
// logger: LOGGER_LEVELS.slice(0, LoggerIndex + 1)
// })

// // This will lockdown all routes and make them accessible by authenticated users only.
// const reflector = app.get(Reflector)
// app.useGlobalGuards(new AuthGuard(reflector))

// app.use(text({
// limit: '50mb',
// type: 'text/xml',
// }))
// app.use(json({ limit: '50mb' }))
// app.use(urlencoded({ extended: true, limit: '50mb' }))

// const headersForOpenAI = 'x-stainless-os, x-stainless-lang, x-stainless-package-version, x-stainless-runtime, x-stainless-arch, x-stainless-runtime-version'
// app.enableCors({
// origin: '*',
// methods: 'GET,HEAD,PUT,PATCH,POST,DELETE,OPTIONS',
// credentials: true,
// allowedHeaders:
// 'Authorization, Language, Tenant-Id, Organization-Id, X-Requested-With, X-Auth-Token, X-HTTP-Method-Override, Content-Type, Content-Language, Accept, Accept-Language, Observe, ' + headersForOpenAI
// })

// // Sessions
// app.use(
// // this runs in memory, so we lose sessions on restart of server/pod
// expressSession({
// secret: env.EXPRESS_SESSION_SECRET,
// resave: true, // we use this because Memory store does not support 'touch' method
// saveUninitialized: true,
// cookie: { secure: env.production } // TODO
// })
// )

// const globalPrefix = 'api'
// app.setGlobalPrefix(globalPrefix)



// // Seed default values
// const serverService = app.select(ServerAppModule).get(AppService)
// await serverService.seedDBIfEmpty()
// const analyticsService = app.select(AnalyticsModule).get(AnalyticsService)
// await analyticsService.seedDBIfEmpty()
// // Webhook for lark
// const larkService = app.select(IntegrationLarkModule).get(LarkService)
// app.use('/api/lark/webhook/event', larkService.webhookEventDispatcher)

// // const subscriptionService = app.select(ServerAppModule).get(SubscriptionService)
// // subscriptionService.setupJobs()

// // Setup Swagger Module
// const options = new DocumentBuilder().setTitle('Metad Cloud API').setVersion('1.0').addBearerAuth().build()

// const document = SwaggerModule.createDocument(app, options)
// SwaggerModule.setup('swg', app, document)

// app.enableShutdownHooks();

// // Listen App
// const port = process.env.PORT || 3000
// await app.listen(port, '0.0.0.0', () => {
// Logger.log('Listening at http://localhost:' + port + '/' + globalPrefix)
// })
// }

const argv: any = yargs(process.argv).argv
const command = argv.command
Expand Down
Loading

0 comments on commit de934fb

Please sign in to comment.