Skip to content

Commit

Permalink
Merge pull request #1083 from TencentBlueKing/develop
Browse files Browse the repository at this point in the history
v1.1.1 merge develop to master
  • Loading branch information
ielgnaw authored Aug 8, 2023
2 parents 38ca704 + 75071b8 commit b463b41
Show file tree
Hide file tree
Showing 328 changed files with 7,429 additions and 5,505 deletions.
6 changes: 6 additions & 0 deletions .bk.development.env
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,12 @@ BK_USER_MANAGE_HOST =
// lesscode部署时环境区分(prod/stag)
BK_LESSCODE_ENVIRONMENT = stag

// paas 相关url前缀, 如用户管理相关接口
BK_COMPONENT_API_URL =

// cookie domian
BKPAAS_BK_DOMAIN =

// itsm 地址
BK_ITSM_URL =

Expand Down
6 changes: 6 additions & 0 deletions .bk.production.env
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ BK_USER_MANAGE_HOST = ${BK_USER_MANAGE_URL}
// lesscode部署时环境区分(prod/stag)
BK_LESSCODE_ENVIRONMENT = ${BKPAAS_ENVIRONMENT}

/ paas 相关url前缀, 如用户管理相关接口
BK_COMPONENT_API_URL = {{ BK_COMPONENT_API_URL }}

// cookie domian
BKPAAS_BK_DOMAIN = {{ BKPAAS_BK_DOMAIN }}

// apigateway 地址
BK_API_GATEWAY_ORIGIN = ${BK_API_URL_TMPL}

Expand Down
7 changes: 7 additions & 0 deletions bk.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ module.exports = {
{ from: /^\/$/, to: '/index.html' },
{ from: /^\/preview\//, to: '/preview.html' }
]
},
client: {
overlay: false
}
},
optimization: {
Expand Down Expand Up @@ -137,6 +140,10 @@ module.exports = {
.loader(require.resolve('vue-markdown-loader/lib/markdown-compiler'))
.options(mdLoaderOption)

config.module.rule('txt')
.test(/\.txt/)
.set('type', 'asset/source')

config.plugin('Buffer')
.use(
webpack.ProvidePlugin,
Expand Down
2 changes: 2 additions & 0 deletions lib/client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
<script>
var BK_STATIC_URL = '<%= process.env.BK_STATIC_URL %>'
var BKPAAS_ENVIRONMENT = '<%= process.env.BK_PAAS_ENVIRONMENT %>'
var BK_COMPONENT_API_URL = '<%= process.env.BK_COMPONENT_API_URL %>'
var BKPAAS_BK_DOMAIN = '<%= process.env.BKPAAS_BK_DOMAIN %>'
var BK_API_URL_TMPL = '{{ BK_API_URL_TMPL }}'
var BKPAAS_ENGINE_REGION = '<%= process.env.BK_PAAS_ENGINE_REGION %>'
var BK_APP_APIGW_PREFIX = '<%= process.env.BK_API_GATEWAY_ORIGIN.replace('{api_name}', 'bk-lesscode') + '/' + process.env.BK_LESSCODE_ENVIRONMENT || '' %>'
Expand Down
Binary file modified lib/client/src/bk-icon/fonts/iconcool.eot
Binary file not shown.
24 changes: 24 additions & 0 deletions lib/client/src/bk-icon/fonts/iconcool.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified lib/client/src/bk-icon/fonts/iconcool.ttf
Binary file not shown.
Binary file modified lib/client/src/bk-icon/fonts/iconcool.woff
Binary file not shown.
2 changes: 1 addition & 1 deletion lib/client/src/bk-icon/iconcool.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lib/client/src/bk-icon/iconcool.json

Large diffs are not rendered by default.

24 changes: 24 additions & 0 deletions lib/client/src/bk-icon/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ url("fonts/iconcool.eot?#iefix") format("embedded-opentype");
.bk-drag-assembly-line:before {
content: "\e240";
}
.bk-drag-feature-conversion:before {
content: "\e28c";
}
.bk-drag-home:before {
content: "\e15d";
}
Expand Down Expand Up @@ -593,6 +596,12 @@ url("fonts/iconcool.eot?#iefix") format("embedded-opentype");
.bk-drag-drag-small:before {
content: "\e1b1";
}
.bk-drag-dianzan-tianchong:before {
content: "\e28e";
}
.bk-drag-dianzan:before {
content: "\e28d";
}
.bk-drag-select-value:before {
content: "\e1b2";
}
Expand Down Expand Up @@ -1169,3 +1178,18 @@ url("fonts/iconcool.eot?#iefix") format("embedded-opentype");
.bk-drag-shanchu-2:before {
content: "\e286";
}
.bk-drag-tag-3:before {
content: "\e28f";
}
.bk-drag-liaotianchuang:before {
content: "\e290";
}
.bk-drag-yinyongchuangjian:before {
content: "\e291";
}
.bk-drag-yinyong-2:before {
content: "\e292";
}
.bk-drag-saoba:before {
content: "\e294";
}
132 changes: 132 additions & 0 deletions lib/client/src/common/ai.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@

export class Ai {
constructor ({
handlerStart,
handleEnd,
handleCmd,
handleMessage,
handleApiError,
handleCmdError,
systemPrompt
}) {
// event
this.handlerStart = handlerStart
this.handleEnd = handleEnd
this.handleCmd = handleCmd
this.handleMessage = handleMessage
this.handleApiError = handleApiError
this.handleCmdError = handleCmdError

// Prompt
this.systemPrompt = systemPrompt
this.inputs = []

// content
this.content = ''

// init
this.pushPrompt(systemPrompt, 'system')
}

pushPrompt (content, role) {
this.inputs.push({
role,
content
})
}

clearPrompt () {
this.inputs = []
this.pushPrompt(this.systemPrompt, 'system')
}

receiveMessage (message) {
this.content += message
const cmdIndex = this.content.indexOf('``')
const aiMessage = cmdIndex > 0 ? this.content.slice(0, cmdIndex).trim() : this.content
// 触发消息更新
this.handleMessage(aiMessage, this.content)
}

endReceiveMessage () {
this.pushPrompt(this.content, 'assistant')
// 触发指令
const cmdIndex = this.content.indexOf('``')
const cmdMessage = this.content.slice(cmdIndex)
if (cmdIndex > -1 && !/(cmd(?:\d)?): (?:<)?([^>\n]+)(?:>)?/gmi.test(cmdMessage)) {
this.chart('It looks like the command is not formatted correctly, please rethink and issue commands')
return
}
const exp = /(cmd(?:\d)?): (?:<)?([^>\n]+)(?:>)?/gmi
let result
let errorCmd
try {
do {
result = exp.exec(cmdMessage)
if (result) {
this.handleCmd(result[1], result[2])
}
} while (result)
} catch (error) {
errorCmd = result[2]
}
this.content = ''
// trigger end
if (errorCmd) {
this.handleCmdError(errorCmd)
} else {
this.handleEnd()
}
}

chat (message) {
// push user prompt
this.pushPrompt(message, 'user')
// api
return fetch('/api/ai/chat/stream', {
method: 'post',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ inputs: this.inputs })
}).then(async response => {
const reader = response.body
.pipeThrough(new window.TextDecoderStream())
.getReader()

// trigger start
this.handlerStart()

// 临时存储数据
let temp = ''

while (true) {
const { value, done } = await reader.read()
if (done) break
const values = (temp + value.toString()).split(/(?<=})\s*(?={\"errors\")/)
values.forEach((value) => {
const item = value.trim()
if (item.startsWith('{') && item.endsWith('}')) {
const {
data,
message
} = JSON.parse(item)
if (data?.status === 'success') {
const choice = JSON.parse(data?.data?.[0]?.output?.[0]?.output)?.choices[0] || {}
if (!choice?.finish_reason) {
this.receiveMessage(choice?.delta?.content)
} else {
this.endReceiveMessage()
}
} else {
this.handleApiError(message || '调用 aiops 接口失败')
}
temp = ''
} else if (item) {
temp = item
}
})
}
})
}
}
27 changes: 27 additions & 0 deletions lib/client/src/common/constant.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,33 @@ export const PAGE_TEMPLATE_TYPE = [
}
]

export const CUSTOM_COMPS_TYPE = [
{
id: 'INFO',
name: window.i18n.t('信息展示')
},
{
id: 'DATA',
name: window.i18n.t('数据')
},
{
id: 'FORM',
name: window.i18n.t('表单')
},
{
id: 'NAV',
name: window.i18n.t('导航')
},
{
id: 'CHART',
name: window.i18n.t('图表')
},
{
id: 'FEEDBACK',
name: window.i18n.t('反馈')
}
]

export const NOCODE_TYPE_MAP = {
toRouteName: {
FORM: 'editNocode',
Expand Down
2 changes: 0 additions & 2 deletions lib/client/src/common/fully-import.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import bkImage from '@/components/patch/image'
import chart from '@/components/patch/chart'
import widgetElTable from '@/components/patch/widget-el-table'
import widgetBkVision from '@/components/patch/widget-bk-vision'
import widgetDateTimePicker from '@/components/patch/widget-vant-date-time-picker'
import VueAwesomeSwiper from 'vue-awesome-swiper'

// import style
Expand All @@ -38,4 +37,3 @@ Vue.use(bkMagicVue)
Vue.use(bkCharts)
Vue.use(widgetBkVision)
Vue.use(widgetElTable)
Vue.use(widgetDateTimePicker)
2 changes: 1 addition & 1 deletion lib/client/src/components/api/common/scheme-header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ export default ({ props }) => {
<section class="object-layout layout-header">
<span class="layout-icon"></span>
<span class="layout-flex">{window.i18n.t('table_参数名')}</span>
{ props.hideRequired ? '' : <span class="layout-small">{window.i18n.t('是否必填')}</span> }
<span class="layout-middle">{window.i18n.t('类型')}</span>
<span class="layout-item">{props.slotLabel || window.i18n.t('值')}</span>
{ props.showRule === false ? '' : <span class="layout-middle">{window.i18n.t('自定义校验')}</span> }
<span class="layout-middle">{window.i18n.t('备注')}</span>
<span class="layout-icons">{window.i18n.t('操作')}</span>
</section>
Expand Down
Loading

0 comments on commit b463b41

Please sign in to comment.