| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- const fs = require('fs')
- const paths = [
- 'd:/ylrz_saas_new/saas-companyui/src/views/lobster/prompt/index.vue',
- 'd:/ylrz_saas_new/saas-mgnui/src/views/lobster/prompt/index.vue',
- 'd:/ylrz_saas_new/adminui/src/views/lobster/prompt/index.vue'
- ]
- const content = `<template>
- <div class="app-container lobster-prompt-page">
- <el-alert
- :title="pageNotes.title"
- type="info"
- show-icon
- :closable="false"
- class="page-note"
- >
- <ul class="note-list">
- <li v-for="(line, idx) in pageNotes.lines" :key="'intro-' + idx">{{ line }}</li>
- </ul>
- </el-alert>
- <el-alert
- :title="pageNotes.variableTitle"
- type="warning"
- show-icon
- :closable="false"
- class="page-note"
- >
- <ul class="note-list">
- <li v-for="(line, idx) in pageNotes.variableLines" :key="'var-' + idx">{{ line }}</li>
- </ul>
- </el-alert>
- <el-row :gutter="12" class="toolbar-row">
- <el-col :span="5">
- <el-input v-model="search" placeholder="\u641c\u7d22\u540d\u79f0\u6216\u7528\u9014" clearable size="small" @keyup.enter.native="loadList" />
- </el-col>
- <el-col :span="3">
- <el-select v-model="filterCategory" placeholder="\u5206\u7c7b\u7b5b\u9009" clearable size="small" @change="loadList">
- <el-option v-for="c in sceneOptions" :key="c.value" :label="c.label" :value="c.value" />
- </el-select>
- </el-col>
- <el-col :span="16" class="toolbar-actions">
- <el-button size="small" icon="el-icon-refresh" @click="loadList">\u5237\u65b0</el-button>
- <el-button size="small" type="warning" plain :loading="bootstrapping" @click="handleBootstrap(false)">\u540c\u6b65\u9ed8\u8ba4\u63d0\u793a\u8bcd</el-button>
- <el-button size="small" type="danger" plain :loading="bootstrapping" @click="handleBootstrap(true)">\u91cd\u7f6e\u4e3a\u76ee\u5f55\u9ed8\u8ba4</el-button>
- </el-col>
- </el-row>
- <el-table v-loading="loading" :data="promptList" border size="small">
- <el-table-column prop="category_label" label="\u5206\u7c7b" width="100" />
- <el-table-column prop="prompt_name" label="\u573a\u666f\u540d\u79f0" width="160" show-overflow-tooltip />
- <el-table-column prop="prompt_key" label="\u573a\u666f\u7f16\u7801" width="200" show-overflow-tooltip />
- <el-table-column label="\u7528\u9014\u8bf4\u660e" min-width="200" show-overflow-tooltip>
- <template slot-scope="scope">
- {{ scope.row.scene_hint || sceneHintOf(scope.row.prompt_key) || '\u2014' }}
- </template>
- </el-table-column>
- <el-table-column label="\u662f\u5426\u5df2\u4fee\u6539" width="90" align="center">
- <template slot-scope="scope">
- <el-tag :type="scope.row.customized ? 'warning' : 'info'" size="mini">
- {{ scope.row.customized ? '\u5df2\u81ea\u5b9a\u4e49' : '\u9ed8\u8ba4' }}
- </el-tag>
- </template>
- </el-table-column>
- <el-table-column label="\u64cd\u4f5c" width="90" fixed="right">
- <template slot-scope="scope">
- <el-button type="text" size="mini" @click="openEdit(scope.row)">\u7f16\u8f91</el-button>
- </template>
- </el-table-column>
- </el-table>
- <pagination
- v-show="total > 0"
- :total="total"
- :page.sync="page"
- :limit.sync="pageSize"
- @pagination="loadList"
- />
- <el-dialog
- :title="editForm.prompt_name || '\u7f16\u8f91\u63d0\u793a\u8bcd'"
- :visible.sync="editVisible"
- width="820px"
- append-to-body
- custom-class="lobster-prompt-edit-dialog"
- >
- <el-alert
- :title="sceneHintOf(editForm.prompt_key) || '\u6682\u65e0\u573a\u666f\u8bf4\u660e'"
- type="info"
- :closable="false"
- show-icon
- class="dialog-scene-hint"
- />
- <el-form ref="editRef" :model="editForm" label-width="100px">
- <el-form-item label="\u573a\u666f\u7f16\u7801">
- <el-input v-model="editForm.prompt_key" disabled />
- </el-form-item>
- <el-form-item label="\u573a\u666f\u540d\u79f0">
- <el-input v-model="editForm.prompt_name" />
- </el-form-item>
- <el-form-item label="\u7cfb\u7edf\u89d2\u8272" v-if="editForm.system_role !== undefined && editForm.system_role !== null">
- <el-input
- v-model="editForm.system_role"
- type="textarea"
- :rows="2"
- placeholder="\u5b9a\u4e49 AI \u626e\u6f14\u4ec0\u4e48\u89d2\u8272\uff0c\u4f8b\u5982\uff1a\u4f60\u662f\u4f01\u4e1a\u77e5\u8bc6\u5e93\u52a9\u624b\uff0c\u53ea\u57fa\u4e8e\u63d0\u4f9b\u7684\u77e5\u8bc6\u56de\u7b54\u95ee\u9898"
- />
- <div class="field-tip">\u5907\u6ce8\uff1a\u7cfb\u7edf\u89d2\u8272\u662f\u5bf9 AI \u7684\u8eab\u4efd\u7ea6\u675f\uff0c\u4e00\u822c\u4fdd\u6301\u9ed8\u8ba4\u5373\u53ef\uff1b\u5982\u9700\u8c03\u6574\u8bed\u6c14\u6216\u4e13\u4e1a\u9886\u57df\u53ef\u5728\u6b64\u4fee\u6539\u3002</div>
- </el-form-item>
- <el-form-item label="\u63d0\u793a\u8bcd\u5185\u5bb9" prop="prompt_content">
- <prompt-structured-editor
- v-model="editForm.prompt_content"
- :prompt-key="editForm.prompt_key"
- />
- <div class="field-tip">\u5907\u6ce8\uff1a\u53ea\u9700\u6539\u767d\u8272\u6587\u672c\u6846\u91cc\u7684\u4e2d\u6587\u8bf4\u660e\uff1b\u7070\u8272\u300c\u81ea\u52a8\u586b\u5165\u300d\u5757\u8bf7\u52ff\u5220\u9664\u3002\u4fdd\u5b58\u540e\u7acb\u5373\u751f\u6548\u3002</div>
- </el-form-item>
- </el-form>
- <div slot="footer">
- <el-button @click="editVisible = false">\u53d6\u6d88</el-button>
- <el-button type="primary" :loading="saving" @click="handleSave">\u4fdd\u5b58</el-button>
- </div>
- </el-dialog>
- </div>
- </template>
- <script>
- import { listPrompts, updatePrompt, bootstrapPromptDefaults, refreshPromptCache } from '@/api/workflow/lobster'
- import PromptStructuredEditor from '@/views/lobster/components/PromptStructuredEditor.vue'
- import {
- PROMPT_PAGE_NOTES,
- PROMPT_SCENE_OPTIONS,
- sceneHintOf
- } from '@/utils/lobster/promptCatalog'
- export default {
- name: 'LobsterPrompt',
- components: { PromptStructuredEditor },
- data() {
- return {
- search: '',
- filterCategory: '',
- loading: false,
- bootstrapping: false,
- saving: false,
- promptList: [],
- page: 1,
- pageSize: 50,
- total: 0,
- editVisible: false,
- editForm: {},
- sceneOptions: PROMPT_SCENE_OPTIONS,
- pageNotes: PROMPT_PAGE_NOTES
- }
- },
- created() {
- this.initPage()
- },
- methods: {
- initPage() {
- this.loading = true
- bootstrapPromptDefaults(false).catch(() => {}).finally(() => {
- this.loadList()
- })
- },
- loadList() {
- this.loading = true
- listPrompts({
- page: this.page,
- size: this.pageSize,
- scene: this.filterCategory || undefined,
- search: this.search || undefined
- }).then(res => {
- const data = res.data || {}
- this.promptList = data.list || []
- this.total = data.total || 0
- }).finally(() => { this.loading = false })
- },
- openEdit(row) {
- this.editForm = {
- id: row.id,
- prompt_key: row.prompt_key,
- prompt_name: row.prompt_name,
- prompt_category: row.prompt_category,
- category_label: row.category_label || row.prompt_category,
- prompt_content: row.prompt_content || '',
- system_role: row.system_role || ''
- }
- this.editVisible = true
- },
- handleSave() {
- if (!this.editForm.prompt_content || !this.editForm.prompt_content.trim()) {
- this.$message.warning('\u63d0\u793a\u8bcd\u5185\u5bb9\u4e0d\u80fd\u4e3a\u7a7a')
- return
- }
- this.saving = true
- updatePrompt(this.editForm.id, {
- promptName: this.editForm.prompt_name,
- promptCategory: this.editForm.prompt_category,
- promptContent: this.editForm.prompt_content,
- systemRole: this.editForm.system_role
- }).then(() => {
- this.$message.success('\u4fdd\u5b58\u6210\u529f')
- this.editVisible = false
- refreshPromptCache().catch(() => {})
- this.loadList()
- }).finally(() => { this.saving = false })
- },
- handleBootstrap(reset) {
- const tip = reset
- ? '\u5c06\u628a\u6240\u6709\u5f15\u64ce\u63d0\u793a\u8bcd\u8986\u76d6\u4e3a\u76ee\u5f55\u9ed8\u8ba4\u503c\uff0c\u81ea\u5b9a\u4e49\u4fee\u6539\u4f1a\u4e22\u5931\uff0c\u662f\u5426\u7ee7\u7eed\uff1f'
- : '\u5c06\u4e3a\u7f3a\u5931\u7684 Key \u5199\u5165\u76ee\u5f55\u9ed8\u8ba4\u5185\u5bb9\uff0c\u8865\u5168\u7f3a\u5931\u7684\u5206\u7c7b/\u540d\u79f0\uff0c\u5e76\u81ea\u52a8\u5c06\u4ecd\u4e3a\u65e7\u7248\u82f1\u6587\u9ed8\u8ba4\u7684\u5185\u5bb9\u5347\u7ea7\u4e3a\u4e2d\u6587\u7248\uff0c\u662f\u5426\u7ee7\u7eed\uff1f'
- this.$confirm(tip, '\u63d0\u793a', { type: reset ? 'warning' : 'info' }).then(() => {
- this.bootstrapping = true
- bootstrapPromptDefaults(reset).then(res => {
- this.$message.success(res.msg || '\u540c\u6b65\u5b8c\u6210')
- this.loadList()
- }).finally(() => { this.bootstrapping = false })
- }).catch(() => {})
- },
- sceneHintOf
- }
- }
- </script>
- <style scoped lang="scss">
- .lobster-prompt-page {
- .page-note {
- margin-bottom: 16px;
- }
- .note-list {
- margin: 8px 0 0;
- padding-left: 18px;
- line-height: 1.7;
- color: #606266;
- font-size: 13px;
- }
- .toolbar-row {
- margin-bottom: 12px;
- }
- .toolbar-actions {
- text-align: right;
- }
- .dialog-scene-hint {
- margin-bottom: 16px;
- }
- .field-tip {
- margin-top: 6px;
- font-size: 12px;
- line-height: 1.5;
- color: #909399;
- }
- }
- </style>
- `
- paths.forEach(p => {
- fs.writeFileSync(p, content, 'utf8')
- console.log('wrote', p)
- })
|