@auto-ai/agent 2.1.92 → 2.1.94
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/404/index.html +1 -1
- package/dist/404.html +1 -1
- package/dist/_next/static/chunks/24ad0472395a5554.js +1 -0
- package/dist/_next/static/chunks/{ce0cac88dd992956.css → 6a750155591ba201.css} +1 -1
- package/dist/agent-office.html +580 -1
- package/dist/index.html +1 -1
- package/dist/index.txt +6 -6
- package/dist/manage/about/index.html +2 -2
- package/dist/manage/about/index.txt +3 -3
- package/dist/manage/add-account/basic/index.html +2 -2
- package/dist/manage/add-account/basic/index.txt +6 -5
- package/dist/manage/add-account/index.html +2 -2
- package/dist/manage/add-account/index.txt +5 -6
- package/dist/manage/add-account/prompt/index.html +2 -2
- package/dist/manage/add-account/prompt/index.txt +3 -3
- package/dist/manage/agent-teams/index.html +2 -2
- package/dist/manage/agent-teams/index.txt +3 -3
- package/dist/manage/env/index.html +2 -2
- package/dist/manage/env/index.txt +3 -3
- package/dist/manage/general/index.html +2 -2
- package/dist/manage/general/index.txt +3 -3
- package/dist/manage/index.html +1 -1
- package/dist/manage/index.txt +3 -3
- package/dist/manage/mcp/index.html +2 -2
- package/dist/manage/mcp/index.txt +3 -3
- package/dist/manage/permissions/index.html +2 -2
- package/dist/manage/permissions/index.txt +3 -3
- package/dist/manage/skills/index.html +2 -2
- package/dist/manage/skills/index.txt +3 -3
- package/dist/manage/task/index.html +1 -1
- package/dist/manage/task/index.txt +3 -3
- package/dist/manage/teams/index.html +1 -1
- package/dist/manage/teams/index.txt +3 -3
- package/dist/manage/tools/index.html +2 -2
- package/dist/manage/tools/index.txt +3 -3
- package/dist/slash-command-ui-patch.css +49 -0
- package/dist/slash-command-ui-patch.js +101 -0
- package/dist/ws-test.html +111 -2
- package/package.json +6 -6
- package/dist/_next/static/chunks/091dc4a67d911a93.js +0 -1
- package/dist/agent-office/accents.js +0 -28
- package/dist/agent-office/api.js +0 -142
- package/dist/agent-office/list.js +0 -79
- package/dist/agent-office/main.js +0 -38
- package/dist/agent-office/officeController.js +0 -13
- package/dist/agent-office/ui.js +0 -264
- /package/dist/_next/static/{IV9dkeTt0V-ZE8jl01i6B → 8ct8wdwNecCOvJ8dbcAlk}/_buildManifest.js +0 -0
- /package/dist/_next/static/{IV9dkeTt0V-ZE8jl01i6B → 8ct8wdwNecCOvJ8dbcAlk}/_clientMiddlewareManifest.json +0 -0
- /package/dist/_next/static/{IV9dkeTt0V-ZE8jl01i6B → 8ct8wdwNecCOvJ8dbcAlk}/_ssgManifest.js +0 -0
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
/** 选中工位显示器高亮色 */
|
|
2
|
-
export const MONITOR_SELECTED = '#0a84ff'
|
|
3
|
-
|
|
4
|
-
/** Agent 识别色带 */
|
|
5
|
-
export const AGENT_ACCENT_COLORS = [
|
|
6
|
-
'#22d3c5',
|
|
7
|
-
'#4da3ff',
|
|
8
|
-
'#8b5cf6',
|
|
9
|
-
'#e84855',
|
|
10
|
-
'#f5c518',
|
|
11
|
-
'#c5e84c',
|
|
12
|
-
]
|
|
13
|
-
|
|
14
|
-
const KNOWN_ACCENTS = {
|
|
15
|
-
dev: '#22d3c5',
|
|
16
|
-
edr: '#4da3ff',
|
|
17
|
-
qihoo: '#8b5cf6',
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
/** 根据 agent id 分配色带 */
|
|
21
|
-
export function accentColorForId(id) {
|
|
22
|
-
const key = String(id || '').trim().toLowerCase()
|
|
23
|
-
if (KNOWN_ACCENTS[key]) return KNOWN_ACCENTS[key]
|
|
24
|
-
const s = String(id || 'a')
|
|
25
|
-
let h = 0
|
|
26
|
-
for (let i = 0; i < s.length; i++) h = (h + s.charCodeAt(i) * 17) % AGENT_ACCENT_COLORS.length
|
|
27
|
-
return AGENT_ACCENT_COLORS[h]
|
|
28
|
-
}
|
package/dist/agent-office/api.js
DELETED
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
/** Agent CRUD API;列表/写操作上下文固定用已存在的默认 agent */
|
|
2
|
-
export const DEFAULT_CONTEXT_AGENT = 'qihoo'
|
|
3
|
-
|
|
4
|
-
/** 解析 API 基址:与 ws-test 一致,支持 apiBase 输入或当前 origin */
|
|
5
|
-
export function httpOriginForApi() {
|
|
6
|
-
try {
|
|
7
|
-
const params = new URLSearchParams(window.location.search)
|
|
8
|
-
const fromQuery = params.get('apiBase')
|
|
9
|
-
if (fromQuery && String(fromQuery).trim()) {
|
|
10
|
-
return String(fromQuery).trim().replace(/\/$/, '')
|
|
11
|
-
}
|
|
12
|
-
} catch {
|
|
13
|
-
/* ignore */
|
|
14
|
-
}
|
|
15
|
-
return window.location.origin
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** 构建 agent 列表 API 地址 */
|
|
19
|
-
export function buildAgentsListUrl(contextAgent) {
|
|
20
|
-
const u = new URL('/api/agents', httpOriginForApi() + '/')
|
|
21
|
-
u.searchParams.set('agent', contextAgent || DEFAULT_CONTEXT_AGENT)
|
|
22
|
-
return u.toString()
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** 构建单个 agent REST 地址 */
|
|
26
|
-
export function buildAgentItemUrl(id, contextAgent) {
|
|
27
|
-
const u = new URL(
|
|
28
|
-
'/api/agents/' + encodeURIComponent(String(id || '').trim()),
|
|
29
|
-
httpOriginForApi() + '/',
|
|
30
|
-
)
|
|
31
|
-
u.searchParams.set('agent', contextAgent || DEFAULT_CONTEXT_AGENT)
|
|
32
|
-
return u.toString()
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/** 校验 agent id:字母数字下划线中划线,1~64 */
|
|
36
|
-
export function isValidAgentIdInput(id) {
|
|
37
|
-
return /^[a-zA-Z0-9_-]{1,64}$/.test(String(id || '').trim())
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/** 基于已有 agent.json 构造 PATCH config,仅更新 whentouse;effort 为 null 时不写入 */
|
|
41
|
-
export function buildAgentConfigPatch(baseConfig, whentouse) {
|
|
42
|
-
const c = baseConfig && typeof baseConfig === 'object' ? baseConfig : {}
|
|
43
|
-
const env = c.env && typeof c.env === 'object' && !Array.isArray(c.env) ? c.env : {}
|
|
44
|
-
const patch = {
|
|
45
|
-
tools: Array.isArray(c.tools) ? c.tools.map(String) : [],
|
|
46
|
-
disallowedTools: Array.isArray(c.disallowedTools)
|
|
47
|
-
? c.disallowedTools.map(String)
|
|
48
|
-
: [],
|
|
49
|
-
mcpServers: Array.isArray(c.mcpServers) ? c.mcpServers.map(String) : [],
|
|
50
|
-
skills: Array.isArray(c.skills) ? c.skills.map(String) : [],
|
|
51
|
-
agentTeams: Array.isArray(c.agentTeams) ? c.agentTeams.map(String) : [],
|
|
52
|
-
model: typeof c.model === 'string' ? c.model : '',
|
|
53
|
-
background: c.background === true,
|
|
54
|
-
isolation: typeof c.isolation === 'string' ? c.isolation : '',
|
|
55
|
-
whentouse: typeof whentouse === 'string' ? whentouse : '',
|
|
56
|
-
env,
|
|
57
|
-
}
|
|
58
|
-
if (typeof c.effort === 'string' || typeof c.effort === 'number') {
|
|
59
|
-
patch.effort = c.effort
|
|
60
|
-
}
|
|
61
|
-
return patch
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/** 拉取 agent 列表 */
|
|
65
|
-
export async function fetchAgentsList(contextAgent) {
|
|
66
|
-
const r = await fetch(buildAgentsListUrl(contextAgent))
|
|
67
|
-
const body = await r.json().catch(() => ({}))
|
|
68
|
-
if (!r.ok) {
|
|
69
|
-
throw new Error(body.message || body.error || r.statusText)
|
|
70
|
-
}
|
|
71
|
-
return Array.isArray(body.agents) ? body.agents : []
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
/** 拉取单个 agent 详情 */
|
|
75
|
-
export async function fetchAgentDetail(id, contextAgent) {
|
|
76
|
-
const r = await fetch(buildAgentItemUrl(id, contextAgent))
|
|
77
|
-
const body = await r.json().catch(() => ({}))
|
|
78
|
-
if (!r.ok) {
|
|
79
|
-
throw new Error(body.message || body.error || r.statusText)
|
|
80
|
-
}
|
|
81
|
-
return body.agent || { id }
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/** 删除 agent;qihoo 不可删 */
|
|
85
|
-
export async function deleteAgent(id, contextAgent) {
|
|
86
|
-
const agentId = String(id || '').trim()
|
|
87
|
-
if (!agentId) throw new Error('缺少 agent id')
|
|
88
|
-
if (agentId === DEFAULT_CONTEXT_AGENT) {
|
|
89
|
-
throw new Error('默认 Agent(' + DEFAULT_CONTEXT_AGENT + ')不可删除')
|
|
90
|
-
}
|
|
91
|
-
const r = await fetch(buildAgentItemUrl(agentId, contextAgent), { method: 'DELETE' })
|
|
92
|
-
const body = await r.json().catch(() => ({}))
|
|
93
|
-
if (!r.ok) {
|
|
94
|
-
throw new Error(body.message || body.error || r.statusText)
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/** 保存 agent(新建或编辑):whentouse + agent.md */
|
|
99
|
-
export async function saveAgent(params) {
|
|
100
|
-
const { id, whentouse, prompt, isEdit, baseConfig, contextAgent } = params
|
|
101
|
-
if (isEdit) {
|
|
102
|
-
const patchRes = await fetch(buildAgentItemUrl(id, contextAgent), {
|
|
103
|
-
method: 'PATCH',
|
|
104
|
-
headers: { 'content-type': 'application/json; charset=utf-8' },
|
|
105
|
-
body: JSON.stringify({
|
|
106
|
-
prompt,
|
|
107
|
-
config: buildAgentConfigPatch(baseConfig, whentouse),
|
|
108
|
-
}),
|
|
109
|
-
})
|
|
110
|
-
const patchBody = await patchRes.json().catch(() => ({}))
|
|
111
|
-
if (!patchRes.ok) {
|
|
112
|
-
throw new Error(patchBody.message || patchBody.error || patchRes.statusText)
|
|
113
|
-
}
|
|
114
|
-
return id
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
const createRes = await fetch(buildAgentsListUrl(contextAgent), {
|
|
118
|
-
method: 'POST',
|
|
119
|
-
headers: { 'content-type': 'application/json; charset=utf-8' },
|
|
120
|
-
body: JSON.stringify({ name: id, prompt }),
|
|
121
|
-
})
|
|
122
|
-
const createBody = await createRes.json().catch(() => ({}))
|
|
123
|
-
if (!createRes.ok) {
|
|
124
|
-
throw new Error(createBody.message || createBody.error || createRes.statusText)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const cfgBody = await fetchAgentDetail(id, contextAgent)
|
|
128
|
-
const baseCfg =
|
|
129
|
-
cfgBody.config && typeof cfgBody.config === 'object' ? cfgBody.config : null
|
|
130
|
-
const patchRes = await fetch(buildAgentItemUrl(id, contextAgent), {
|
|
131
|
-
method: 'PATCH',
|
|
132
|
-
headers: { 'content-type': 'application/json; charset=utf-8' },
|
|
133
|
-
body: JSON.stringify({
|
|
134
|
-
config: buildAgentConfigPatch(baseCfg, whentouse),
|
|
135
|
-
}),
|
|
136
|
-
})
|
|
137
|
-
const patchBody = await patchRes.json().catch(() => ({}))
|
|
138
|
-
if (!patchRes.ok) {
|
|
139
|
-
throw new Error(patchBody.message || patchBody.error || patchRes.statusText)
|
|
140
|
-
}
|
|
141
|
-
return id
|
|
142
|
-
}
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { accentColorForId } from './accents.js'
|
|
2
|
-
|
|
3
|
-
function truncate(text, max) {
|
|
4
|
-
const s = String(text || '').replace(/\s+/g, ' ').trim()
|
|
5
|
-
if (!s) return '暂无使用说明'
|
|
6
|
-
return s.length <= max ? s : s.slice(0, max - 1) + '…'
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
/** Agent 列表渲染 */
|
|
10
|
-
export class AgentList {
|
|
11
|
-
constructor(container, onPick) {
|
|
12
|
-
this.container = container
|
|
13
|
-
this.onPick = onPick
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
render(agents, selectedId) {
|
|
17
|
-
if (!this.container) return
|
|
18
|
-
this.container.innerHTML = ''
|
|
19
|
-
|
|
20
|
-
if (!agents.length) {
|
|
21
|
-
const empty = document.createElement('div')
|
|
22
|
-
empty.className = 'agent-list-empty'
|
|
23
|
-
empty.textContent = '暂无 Agent,点击右上角「新建 Agent」创建'
|
|
24
|
-
this.container.appendChild(empty)
|
|
25
|
-
return
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const ul = document.createElement('ul')
|
|
29
|
-
ul.className = 'agent-list'
|
|
30
|
-
ul.setAttribute('role', 'list')
|
|
31
|
-
|
|
32
|
-
for (let i = 0; i < agents.length; i++) {
|
|
33
|
-
const row = agents[i]
|
|
34
|
-
const id = String(row.id || '').trim()
|
|
35
|
-
if (!id) continue
|
|
36
|
-
|
|
37
|
-
const li = document.createElement('li')
|
|
38
|
-
const btn = document.createElement('button')
|
|
39
|
-
btn.type = 'button'
|
|
40
|
-
btn.className = 'agent-list-item' + (selectedId === id ? ' is-selected' : '')
|
|
41
|
-
btn.setAttribute('aria-pressed', selectedId === id ? 'true' : 'false')
|
|
42
|
-
|
|
43
|
-
const accent = document.createElement('span')
|
|
44
|
-
accent.className = 'agent-list-accent'
|
|
45
|
-
accent.style.background = accentColorForId(id)
|
|
46
|
-
|
|
47
|
-
const body = document.createElement('span')
|
|
48
|
-
body.className = 'agent-list-body'
|
|
49
|
-
|
|
50
|
-
const title = document.createElement('span')
|
|
51
|
-
title.className = 'agent-list-id'
|
|
52
|
-
title.textContent = id
|
|
53
|
-
|
|
54
|
-
const desc = document.createElement('span')
|
|
55
|
-
desc.className = 'agent-list-desc'
|
|
56
|
-
desc.textContent = truncate(row.whentouse, 80)
|
|
57
|
-
|
|
58
|
-
body.appendChild(title)
|
|
59
|
-
body.appendChild(desc)
|
|
60
|
-
|
|
61
|
-
const arrow = document.createElement('span')
|
|
62
|
-
arrow.className = 'agent-list-arrow'
|
|
63
|
-
arrow.textContent = '›'
|
|
64
|
-
|
|
65
|
-
btn.appendChild(accent)
|
|
66
|
-
btn.appendChild(body)
|
|
67
|
-
btn.appendChild(arrow)
|
|
68
|
-
|
|
69
|
-
btn.addEventListener('click', () => {
|
|
70
|
-
if (this.onPick) this.onPick(id)
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
li.appendChild(btn)
|
|
74
|
-
ul.appendChild(li)
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
this.container.appendChild(ul)
|
|
78
|
-
}
|
|
79
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { OfficeController } from './officeController.js'
|
|
2
|
-
import { AgentList } from './list.js'
|
|
3
|
-
import { OfficeUI } from './ui.js'
|
|
4
|
-
|
|
5
|
-
/** Agent 列表页入口 */
|
|
6
|
-
async function main() {
|
|
7
|
-
const app = document.getElementById('officeApp')
|
|
8
|
-
const listRoot = document.getElementById('agentListRoot')
|
|
9
|
-
if (!app || !listRoot) return
|
|
10
|
-
|
|
11
|
-
const controller = new OfficeController()
|
|
12
|
-
const list = new AgentList(listRoot, (id) => controller.selectAgent(id))
|
|
13
|
-
|
|
14
|
-
const ui = new OfficeUI(app, controller, list, {
|
|
15
|
-
onAgentsLoaded(agents) {
|
|
16
|
-
const subtitle = document.getElementById('officeSubtitle')
|
|
17
|
-
if (subtitle) {
|
|
18
|
-
subtitle.textContent = String(agents.length) + ' 个 Agent · 点击列表项管理'
|
|
19
|
-
}
|
|
20
|
-
list.render(agents, controller.selectedId)
|
|
21
|
-
},
|
|
22
|
-
})
|
|
23
|
-
|
|
24
|
-
controller.onSelect = (id) => ui.onSelect(id)
|
|
25
|
-
|
|
26
|
-
try {
|
|
27
|
-
await ui.refreshAgents()
|
|
28
|
-
await ui.handleUrlAgentParam()
|
|
29
|
-
} catch (e) {
|
|
30
|
-
ui.showToast('加载 Agent 失败: ' + String(e), true)
|
|
31
|
-
const subtitle = document.getElementById('officeSubtitle')
|
|
32
|
-
if (subtitle) subtitle.textContent = '加载失败'
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
main().catch((e) => {
|
|
37
|
-
console.error(e)
|
|
38
|
-
})
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
/** Agent 列表页轻量状态:仅维护当前选中项 */
|
|
2
|
-
export class OfficeController {
|
|
3
|
-
constructor() {
|
|
4
|
-
this.selectedId = null
|
|
5
|
-
this.onSelect = null
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
/** 选中或取消选中 Agent,并通知 UI */
|
|
9
|
-
selectAgent(id) {
|
|
10
|
-
this.selectedId = id || null
|
|
11
|
-
if (this.onSelect) this.onSelect(this.selectedId)
|
|
12
|
-
}
|
|
13
|
-
}
|
package/dist/agent-office/ui.js
DELETED
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DEFAULT_CONTEXT_AGENT,
|
|
3
|
-
fetchAgentsList,
|
|
4
|
-
fetchAgentDetail,
|
|
5
|
-
saveAgent,
|
|
6
|
-
deleteAgent,
|
|
7
|
-
isValidAgentIdInput,
|
|
8
|
-
} from './api.js'
|
|
9
|
-
|
|
10
|
-
/** 列表页 + 侧栏 CRUD */
|
|
11
|
-
export class OfficeUI {
|
|
12
|
-
constructor(root, controller, list, hooks) {
|
|
13
|
-
this.root = root
|
|
14
|
-
this.controller = controller
|
|
15
|
-
this.list = list
|
|
16
|
-
this.hooks = hooks || {}
|
|
17
|
-
this.contextAgent = DEFAULT_CONTEXT_AGENT
|
|
18
|
-
this.agents = []
|
|
19
|
-
this.editingId = null
|
|
20
|
-
this.baseConfig = null
|
|
21
|
-
this.mode = 'idle'
|
|
22
|
-
|
|
23
|
-
this.panelEl = root.querySelector('#officePanel')
|
|
24
|
-
this.panelTitleEl = root.querySelector('#officePanelTitle')
|
|
25
|
-
this.panelMetaEl = root.querySelector('#officePanelMeta')
|
|
26
|
-
this.formEl = root.querySelector('#officeAgentForm')
|
|
27
|
-
this.idInput = root.querySelector('#officeAgentId')
|
|
28
|
-
this.whenInput = root.querySelector('#officeAgentWhen')
|
|
29
|
-
this.promptInput = root.querySelector('#officeAgentPrompt')
|
|
30
|
-
this.btnNew = root.querySelector('#btnOfficeNewAgent')
|
|
31
|
-
this.btnSave = root.querySelector('#btnOfficeSave')
|
|
32
|
-
this.btnDelete = root.querySelector('#btnOfficeDelete')
|
|
33
|
-
this.btnWorkbench = root.querySelector('#btnOfficeWorkbench')
|
|
34
|
-
this.btnClose = root.querySelector('#btnOfficePanelClose')
|
|
35
|
-
this.toastEl = root.querySelector('#officeToast')
|
|
36
|
-
|
|
37
|
-
this.bindEvents()
|
|
38
|
-
this.hidePanel()
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
bindEvents() {
|
|
42
|
-
if (this.btnNew) {
|
|
43
|
-
this.btnNew.addEventListener('click', () => this.showCreateForm())
|
|
44
|
-
}
|
|
45
|
-
if (this.btnClose) {
|
|
46
|
-
this.btnClose.addEventListener('click', () => {
|
|
47
|
-
this.hidePanel()
|
|
48
|
-
this.controller.selectAgent(null)
|
|
49
|
-
this.clearUrlAgentParam()
|
|
50
|
-
})
|
|
51
|
-
}
|
|
52
|
-
if (this.btnSave) {
|
|
53
|
-
this.btnSave.addEventListener('click', () => void this.submitForm())
|
|
54
|
-
}
|
|
55
|
-
if (this.btnDelete) {
|
|
56
|
-
this.btnDelete.addEventListener('click', () => void this.handleDelete())
|
|
57
|
-
}
|
|
58
|
-
if (this.btnWorkbench) {
|
|
59
|
-
this.btnWorkbench.addEventListener('click', () => {
|
|
60
|
-
const id = this.editingId || (this.idInput ? this.idInput.value.trim() : '')
|
|
61
|
-
if (!id) return
|
|
62
|
-
window.location.href = '/ws-test.html?agent=' + encodeURIComponent(id)
|
|
63
|
-
})
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
showToast(msg, isError) {
|
|
68
|
-
if (!this.toastEl) return
|
|
69
|
-
this.toastEl.textContent = msg
|
|
70
|
-
this.toastEl.classList.toggle('is-error', !!isError)
|
|
71
|
-
this.toastEl.classList.add('is-visible')
|
|
72
|
-
clearTimeout(this._toastTimer)
|
|
73
|
-
this._toastTimer = setTimeout(() => {
|
|
74
|
-
this.toastEl.classList.remove('is-visible')
|
|
75
|
-
}, 3200)
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
hidePanel() {
|
|
79
|
-
if (this.panelEl) this.panelEl.classList.remove('is-open')
|
|
80
|
-
this.editingId = null
|
|
81
|
-
this.baseConfig = null
|
|
82
|
-
this.mode = 'idle'
|
|
83
|
-
this.list.render(this.agents, null)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
showPanelForAgent(id) {
|
|
87
|
-
if (!this.panelEl) return
|
|
88
|
-
this.panelEl.classList.add('is-open')
|
|
89
|
-
this.list.render(this.agents, id)
|
|
90
|
-
void this.loadAgentIntoForm(id)
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
showCreateForm() {
|
|
94
|
-
if (!this.panelEl || !this.formEl) return
|
|
95
|
-
this.panelEl.classList.add('is-open')
|
|
96
|
-
this.mode = 'create'
|
|
97
|
-
this.editingId = null
|
|
98
|
-
this.baseConfig = null
|
|
99
|
-
if (this.panelTitleEl) this.panelTitleEl.textContent = '新建 Agent'
|
|
100
|
-
if (this.panelMetaEl) this.panelMetaEl.textContent = '创建后可从列表进入工作台'
|
|
101
|
-
if (this.idInput) {
|
|
102
|
-
this.idInput.value = ''
|
|
103
|
-
this.idInput.readOnly = false
|
|
104
|
-
}
|
|
105
|
-
if (this.whenInput) this.whenInput.value = ''
|
|
106
|
-
if (this.promptInput) this.promptInput.value = ''
|
|
107
|
-
if (this.btnDelete) this.btnDelete.disabled = true
|
|
108
|
-
if (this.btnWorkbench) this.btnWorkbench.disabled = true
|
|
109
|
-
this.list.render(this.agents, null)
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
async loadAgentIntoForm(id) {
|
|
113
|
-
const agentId = String(id || '').trim()
|
|
114
|
-
if (!agentId) return
|
|
115
|
-
this.mode = 'edit'
|
|
116
|
-
this.editingId = agentId
|
|
117
|
-
if (this.panelTitleEl) this.panelTitleEl.textContent = 'Agent · ' + agentId
|
|
118
|
-
if (this.panelMetaEl) this.panelMetaEl.textContent = '加载中…'
|
|
119
|
-
if (this.btnDelete) {
|
|
120
|
-
this.btnDelete.disabled = agentId === DEFAULT_CONTEXT_AGENT
|
|
121
|
-
}
|
|
122
|
-
if (this.btnWorkbench) this.btnWorkbench.disabled = false
|
|
123
|
-
try {
|
|
124
|
-
const agent = await fetchAgentDetail(agentId, this.contextAgent)
|
|
125
|
-
this.baseConfig =
|
|
126
|
-
agent.config && typeof agent.config === 'object' ? agent.config : null
|
|
127
|
-
if (this.idInput) {
|
|
128
|
-
this.idInput.value = agentId
|
|
129
|
-
this.idInput.readOnly = true
|
|
130
|
-
}
|
|
131
|
-
const whentouse =
|
|
132
|
-
agent.config && typeof agent.config.whentouse === 'string'
|
|
133
|
-
? agent.config.whentouse
|
|
134
|
-
: typeof agent.whentouse === 'string'
|
|
135
|
-
? agent.whentouse
|
|
136
|
-
: ''
|
|
137
|
-
if (this.whenInput) this.whenInput.value = whentouse
|
|
138
|
-
if (this.promptInput) {
|
|
139
|
-
this.promptInput.value = typeof agent.prompt === 'string' ? agent.prompt : ''
|
|
140
|
-
}
|
|
141
|
-
if (this.panelMetaEl) {
|
|
142
|
-
this.panelMetaEl.textContent =
|
|
143
|
-
'共 ' + String(this.agents.length) + ' 个 Agent · 上下文:' + this.contextAgent
|
|
144
|
-
}
|
|
145
|
-
} catch (e) {
|
|
146
|
-
if (this.panelMetaEl) this.panelMetaEl.textContent = '加载失败'
|
|
147
|
-
this.showToast('加载 Agent 失败: ' + String(e), true)
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
async refreshAgents() {
|
|
152
|
-
this.agents = await fetchAgentsList(this.contextAgent)
|
|
153
|
-
this.list.render(this.agents, this.controller.selectedId)
|
|
154
|
-
if (this.hooks.onAgentsLoaded) this.hooks.onAgentsLoaded(this.agents)
|
|
155
|
-
return this.agents
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
async submitForm() {
|
|
159
|
-
const isEdit = this.mode === 'edit' && !!this.editingId
|
|
160
|
-
const id = isEdit
|
|
161
|
-
? this.editingId
|
|
162
|
-
: this.idInput
|
|
163
|
-
? this.idInput.value.trim()
|
|
164
|
-
: ''
|
|
165
|
-
const whentouse = this.whenInput ? this.whenInput.value : ''
|
|
166
|
-
const prompt = this.promptInput ? this.promptInput.value : ''
|
|
167
|
-
if (!isEdit && !isValidAgentIdInput(id)) {
|
|
168
|
-
this.showToast('Agent ID 仅支持字母、数字、下划线和中划线,长度 1~64', true)
|
|
169
|
-
return
|
|
170
|
-
}
|
|
171
|
-
try {
|
|
172
|
-
await saveAgent({
|
|
173
|
-
id,
|
|
174
|
-
whentouse,
|
|
175
|
-
prompt,
|
|
176
|
-
isEdit,
|
|
177
|
-
baseConfig: this.baseConfig,
|
|
178
|
-
contextAgent: this.contextAgent,
|
|
179
|
-
})
|
|
180
|
-
await this.refreshAgents()
|
|
181
|
-
this.mode = 'edit'
|
|
182
|
-
this.editingId = id
|
|
183
|
-
if (this.idInput) {
|
|
184
|
-
this.idInput.value = id
|
|
185
|
-
this.idInput.readOnly = true
|
|
186
|
-
}
|
|
187
|
-
if (this.btnDelete) this.btnDelete.disabled = id === DEFAULT_CONTEXT_AGENT
|
|
188
|
-
if (this.btnWorkbench) this.btnWorkbench.disabled = false
|
|
189
|
-
if (this.panelTitleEl) this.panelTitleEl.textContent = 'Agent · ' + id
|
|
190
|
-
this.controller.selectAgent(id)
|
|
191
|
-
this.syncUrlAgentParam(id)
|
|
192
|
-
this.showToast(isEdit ? '已保存' : '已创建')
|
|
193
|
-
} catch (e) {
|
|
194
|
-
this.showToast((isEdit ? '保存失败: ' : '创建失败: ') + String(e), true)
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
async handleDelete() {
|
|
199
|
-
const id = this.editingId
|
|
200
|
-
if (!id || id === DEFAULT_CONTEXT_AGENT) return
|
|
201
|
-
if (!window.confirm('确定删除 Agent「' + id + '」?此操作不可恢复。')) return
|
|
202
|
-
try {
|
|
203
|
-
await deleteAgent(id, this.contextAgent)
|
|
204
|
-
await this.refreshAgents()
|
|
205
|
-
this.hidePanel()
|
|
206
|
-
this.clearUrlAgentParam()
|
|
207
|
-
this.showToast('已删除')
|
|
208
|
-
} catch (e) {
|
|
209
|
-
this.showToast('删除失败: ' + String(e), true)
|
|
210
|
-
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
async handleUrlAgentParam() {
|
|
214
|
-
let param = ''
|
|
215
|
-
try {
|
|
216
|
-
param = new URLSearchParams(window.location.search).get('agent') || ''
|
|
217
|
-
} catch {
|
|
218
|
-
return
|
|
219
|
-
}
|
|
220
|
-
const id = String(param).trim()
|
|
221
|
-
if (!id) return
|
|
222
|
-
|
|
223
|
-
const exists = this.agents.some((a) => String(a.id) === id)
|
|
224
|
-
if (!exists) {
|
|
225
|
-
this.showToast('agent 不存在,请先创建', true)
|
|
226
|
-
this.clearUrlAgentParam()
|
|
227
|
-
return
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
this.controller.selectAgent(id)
|
|
231
|
-
this.showPanelForAgent(id)
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
syncUrlAgentParam(id) {
|
|
235
|
-
try {
|
|
236
|
-
const u = new URL(window.location.href)
|
|
237
|
-
u.searchParams.set('agent', id)
|
|
238
|
-
window.history.replaceState(null, '', u.pathname + u.search)
|
|
239
|
-
} catch {
|
|
240
|
-
/* ignore */
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
clearUrlAgentParam() {
|
|
245
|
-
try {
|
|
246
|
-
const u = new URL(window.location.href)
|
|
247
|
-
u.searchParams.delete('agent')
|
|
248
|
-
const qs = u.searchParams.toString()
|
|
249
|
-
window.history.replaceState(null, '', u.pathname + (qs ? '?' + qs : ''))
|
|
250
|
-
} catch {
|
|
251
|
-
/* ignore */
|
|
252
|
-
}
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
onSelect(id) {
|
|
256
|
-
if (!id) {
|
|
257
|
-
this.hidePanel()
|
|
258
|
-
this.clearUrlAgentParam()
|
|
259
|
-
return
|
|
260
|
-
}
|
|
261
|
-
this.showPanelForAgent(id)
|
|
262
|
-
this.syncUrlAgentParam(id)
|
|
263
|
-
}
|
|
264
|
-
}
|
/package/dist/_next/static/{IV9dkeTt0V-ZE8jl01i6B → 8ct8wdwNecCOvJ8dbcAlk}/_buildManifest.js
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|